3v4l.org

run code in 300+ PHP versions simultaneously
<?php function string_shift_left($input, $inputlen, $bits, &$output = null) { $skip = (int) ($bits / 8); $copylen = (int) ($inputlen - $skip); $offset = ord(chr($bits % 8)); $mask = (0xff >> $offset) << (8 - $offset); $output = str_pad('', $inputlen + 1, "\x00"); echo "$skip $copylen $offset $mask\n"; if ($offset == 0) { /* Shifting multiples of 8 allows us to simply copy the relevant bytes */ for ($i = 0; $i < $copylen; $i++) { $output[$i] = $input[$i + $skip]; } return; } for ($i = 0; $i < $copylen; $i++) { $left = (ord($input[$i + $skip]) << $offset); $right = (ord($input[$i + $skip + 1]) & $mask) >> $offset; printf("%02x ", $left | $right); $output[$i] = chr($left | $right); } } //0b000100010001000100000000; string_shift_left("abc\x00", 3, 2, $output); for ($i = 0; $i < strlen($output); $i++) { printf("\n%02x", ord($output[$i])); }
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 17
Branch analysis from position: 17
2 jumps found. (Code = 44) Position 1 = 20, Position 2 = 8
Branch analysis from position: 20
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 8
2 jumps found. (Code = 44) Position 1 = 20, Position 2 = 8
Branch analysis from position: 20
Branch analysis from position: 8
filename:       /in/e2Tf8
function name:  (null)
number of ops:  21
compiled vars:  !0 = $output, !1 = $i
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   31     0  E >   INIT_FCALL                                               'string_shift_left'
          1        SEND_VAL                                                 'abc%00'
          2        SEND_VAL                                                 3
          3        SEND_VAL                                                 2
          4        SEND_REF                                                 !0
          5        DO_FCALL                                      0          
   33     6        ASSIGN                                                   !1, 0
          7      > JMP                                                      ->17
   34     8    >   INIT_FCALL                                               'printf'
          9        SEND_VAL                                                 '%0A%2502x'
         10        INIT_FCALL                                               'ord'
         11        FETCH_DIM_R                                      ~4      !0, !1
         12        SEND_VAL                                                 ~4
         13        DO_ICALL                                         $5      
         14        SEND_VAR                                                 $5
         15        DO_ICALL                                                 
   33    16        PRE_INC                                                  !1
         17    >   STRLEN                                           ~8      !0
         18        IS_SMALLER                                               !1, ~8
         19      > JMPNZ                                                    ~9, ->8
   35    20    > > RETURN                                                   1

Function string_shift_left:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 40, Position 2 = 50
Branch analysis from position: 40
1 jumps found. (Code = 42) Position 1 = 47
Branch analysis from position: 47
2 jumps found. (Code = 44) Position 1 = 49, Position 2 = 42
Branch analysis from position: 49
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 42
2 jumps found. (Code = 44) Position 1 = 49, Position 2 = 42
Branch analysis from position: 49
Branch analysis from position: 42
Branch analysis from position: 50
1 jumps found. (Code = 42) Position 1 = 80
Branch analysis from position: 80
2 jumps found. (Code = 44) Position 1 = 82, Position 2 = 52
Branch analysis from position: 82
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 52
2 jumps found. (Code = 44) Position 1 = 82, Position 2 = 52
Branch analysis from position: 82
Branch analysis from position: 52
filename:       /in/e2Tf8
function name:  string_shift_left
number of ops:  83
compiled vars:  !0 = $input, !1 = $inputlen, !2 = $bits, !3 = $output, !4 = $skip, !5 = $copylen, !6 = $offset, !7 = $mask, !8 = $i, !9 = $left, !10 = $right
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV                                             !2      
          3        RECV_INIT                                        !3      null
    5     4        DIV                                              ~11     !2, 8
          5        CAST                                          4  ~12     ~11
          6        ASSIGN                                                   !4, ~12
    6     7        SUB                                              ~14     !1, !4
          8        CAST                                          4  ~15     ~14
          9        ASSIGN                                                   !5, ~15
    7    10        INIT_FCALL                                               'ord'
         11        INIT_FCALL                                               'chr'
         12        MOD                                              ~17     !2, 8
         13        SEND_VAL                                                 ~17
         14        DO_ICALL                                         $18     
         15        SEND_VAR                                                 $18
         16        DO_ICALL                                         $19     
         17        ASSIGN                                                   !6, $19
    8    18        SR                                               ~21     255, !6
         19        SUB                                              ~22     8, !6
         20        SL                                               ~23     ~21, ~22
         21        ASSIGN                                                   !7, ~23
   10    22        INIT_FCALL                                               'str_pad'
         23        SEND_VAL                                                 ''
         24        ADD                                              ~25     !1, 1
         25        SEND_VAL                                                 ~25
         26        SEND_VAL                                                 '%00'
         27        DO_ICALL                                         $26     
         28        ASSIGN                                                   !3, $26
   12    29        ROPE_INIT                                     8  ~29     !4
         30        ROPE_ADD                                      1  ~29     ~29, '+'
         31        ROPE_ADD                                      2  ~29     ~29, !5
         32        ROPE_ADD                                      3  ~29     ~29, '+'
         33        ROPE_ADD                                      4  ~29     ~29, !6
         34        ROPE_ADD                                      5  ~29     ~29, '+'
         35        ROPE_ADD                                      6  ~29     ~29, !7
         36        ROPE_END                                      7  ~28     ~29, '%0A'
         37        ECHO                                                     ~28
   14    38        IS_EQUAL                                                 !6, 0
         39      > JMPZ                                                     ~33, ->50
   16    40    >   ASSIGN                                                   !8, 0
         41      > JMP                                                      ->47
   17    42    >   ADD                                              ~36     !8, !4
         43        FETCH_DIM_R                                      ~37     !0, ~36
         44        ASSIGN_DIM                                               !3, !8
         45        OP_DATA                                                  ~37
   16    46        PRE_INC                                                  !8
         47    >   IS_SMALLER                                               !8, !5
         48      > JMPNZ                                                    ~39, ->42
   19    49    > > RETURN                                                   null
   22    50    >   ASSIGN                                                   !8, 0
         51      > JMP                                                      ->80
   23    52    >   INIT_FCALL                                               'ord'
         53        ADD                                              ~41     !8, !4
         54        FETCH_DIM_R                                      ~42     !0, ~41
         55        SEND_VAL                                                 ~42
         56        DO_ICALL                                         $43     
         57        SL                                               ~44     $43, !6
         58        ASSIGN                                                   !9, ~44
   24    59        INIT_FCALL                                               'ord'
         60        ADD                                              ~46     !8, !4
         61        ADD                                              ~47     ~46, 1
         62        FETCH_DIM_R                                      ~48     !0, ~47
         63        SEND_VAL                                                 ~48
         64        DO_ICALL                                         $49     
         65        BW_AND                                           ~50     !7, $49
         66        SR                                               ~51     ~50, !6
         67        ASSIGN                                                   !10, ~51
   25    68        INIT_FCALL                                               'printf'
         69        SEND_VAL                                                 '%2502x+'
         70        BW_OR                                            ~53     !9, !10
         71        SEND_VAL                                                 ~53
         72        DO_ICALL                                                 
   26    73        INIT_FCALL                                               'chr'
         74        BW_OR                                            ~56     !9, !10
         75        SEND_VAL                                                 ~56
         76        DO_ICALL                                         $57     
         77        ASSIGN_DIM                                               !3, !8
         78        OP_DATA                                                  $57
   22    79        PRE_INC                                                  !8
         80    >   IS_SMALLER                                               !8, !5
         81      > JMPNZ                                                    ~59, ->52
   28    82    > > RETURN                                                   null

End of function string_shift_left

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
172.99 ms | 1407 KiB | 22 Q