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 = ($bits % 8) & 0xff; $mask = ~(0xff >> (8 - $offset)) & 0xff; $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; $input = "abc\x00"; $bits = 2; string_shift_left($input, strlen($input) - 1, $bits, $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 = 21
Branch analysis from position: 21
2 jumps found. (Code = 44) Position 1 = 24, Position 2 = 12
Branch analysis from position: 24
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 12
2 jumps found. (Code = 44) Position 1 = 24, Position 2 = 12
Branch analysis from position: 24
Branch analysis from position: 12
filename:       /in/N1J6i
function name:  (null)
number of ops:  25
compiled vars:  !0 = $input, !1 = $bits, !2 = $output, !3 = $i
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   31     0  E >   ASSIGN                                                   !0, 'abc%00'
   32     1        ASSIGN                                                   !1, 2
   34     2        INIT_FCALL                                               'string_shift_left'
          3        SEND_VAR                                                 !0
          4        STRLEN                                           ~6      !0
          5        SUB                                              ~7      ~6, 1
          6        SEND_VAL                                                 ~7
          7        SEND_VAR                                                 !1
          8        SEND_REF                                                 !2
          9        DO_FCALL                                      0          
   36    10        ASSIGN                                                   !3, 0
         11      > JMP                                                      ->21
   37    12    >   INIT_FCALL                                               'printf'
         13        SEND_VAL                                                 '%0A%2502x'
         14        INIT_FCALL                                               'ord'
         15        FETCH_DIM_R                                      ~10     !2, !3
         16        SEND_VAL                                                 ~10
         17        DO_ICALL                                         $11     
         18        SEND_VAR                                                 $11
         19        DO_ICALL                                                 
   36    20        PRE_INC                                                  !3
         21    >   STRLEN                                           ~14     !2
         22        IS_SMALLER                                               !3, ~14
         23      > JMPNZ                                                    ~15, ->12
   38    24    > > RETURN                                                   1

Function string_shift_left:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 36, Position 2 = 46
Branch analysis from position: 36
1 jumps found. (Code = 42) Position 1 = 43
Branch analysis from position: 43
2 jumps found. (Code = 44) Position 1 = 45, Position 2 = 38
Branch analysis from position: 45
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 38
2 jumps found. (Code = 44) Position 1 = 45, Position 2 = 38
Branch analysis from position: 45
Branch analysis from position: 38
Branch analysis from position: 46
1 jumps found. (Code = 42) Position 1 = 76
Branch analysis from position: 76
2 jumps found. (Code = 44) Position 1 = 78, Position 2 = 48
Branch analysis from position: 78
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 48
2 jumps found. (Code = 44) Position 1 = 78, Position 2 = 48
Branch analysis from position: 78
Branch analysis from position: 48
filename:       /in/N1J6i
function name:  string_shift_left
number of ops:  79
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        MOD                                              ~17     !2, 8
         11        BW_AND                                           ~18     ~17, 255
         12        ASSIGN                                                   !6, ~18
    8    13        SUB                                              ~20     8, !6
         14        SR                                               ~21     255, ~20
         15        BW_NOT                                           ~22     ~21
         16        BW_AND                                           ~23     ~22, 255
         17        ASSIGN                                                   !7, ~23
   10    18        INIT_FCALL                                               'str_pad'
         19        SEND_VAL                                                 ''
         20        ADD                                              ~25     !1, 1
         21        SEND_VAL                                                 ~25
         22        SEND_VAL                                                 '%00'
         23        DO_ICALL                                         $26     
         24        ASSIGN                                                   !3, $26
   12    25        ROPE_INIT                                     8  ~29     !4
         26        ROPE_ADD                                      1  ~29     ~29, '+'
         27        ROPE_ADD                                      2  ~29     ~29, !5
         28        ROPE_ADD                                      3  ~29     ~29, '+'
         29        ROPE_ADD                                      4  ~29     ~29, !6
         30        ROPE_ADD                                      5  ~29     ~29, '+'
         31        ROPE_ADD                                      6  ~29     ~29, !7
         32        ROPE_END                                      7  ~28     ~29, '%0A'
         33        ECHO                                                     ~28
   14    34        IS_EQUAL                                                 !6, 0
         35      > JMPZ                                                     ~33, ->46
   16    36    >   ASSIGN                                                   !8, 0
         37      > JMP                                                      ->43
   17    38    >   ADD                                              ~36     !8, !4
         39        FETCH_DIM_R                                      ~37     !0, ~36
         40        ASSIGN_DIM                                               !3, !8
         41        OP_DATA                                                  ~37
   16    42        PRE_INC                                                  !8
         43    >   IS_SMALLER                                               !8, !5
         44      > JMPNZ                                                    ~39, ->38
   19    45    > > RETURN                                                   null
   22    46    >   ASSIGN                                                   !8, 0
         47      > JMP                                                      ->76
   23    48    >   INIT_FCALL                                               'ord'
         49        ADD                                              ~41     !8, !4
         50        FETCH_DIM_R                                      ~42     !0, ~41
         51        SEND_VAL                                                 ~42
         52        DO_ICALL                                         $43     
         53        SL                                               ~44     $43, !6
         54        ASSIGN                                                   !9, ~44
   24    55        INIT_FCALL                                               'ord'
         56        ADD                                              ~46     !8, !4
         57        ADD                                              ~47     ~46, 1
         58        FETCH_DIM_R                                      ~48     !0, ~47
         59        SEND_VAL                                                 ~48
         60        DO_ICALL                                         $49     
         61        BW_AND                                           ~50     !7, $49
         62        SR                                               ~51     ~50, !6
         63        ASSIGN                                                   !10, ~51
   25    64        INIT_FCALL                                               'printf'
         65        SEND_VAL                                                 '%2502x+'
         66        BW_OR                                            ~53     !9, !10
         67        SEND_VAL                                                 ~53
         68        DO_ICALL                                                 
   26    69        INIT_FCALL                                               'chr'
         70        BW_OR                                            ~56     !9, !10
         71        SEND_VAL                                                 ~56
         72        DO_ICALL                                         $57     
         73        ASSIGN_DIM                                               !3, !8
         74        OP_DATA                                                  $57
   22    75        PRE_INC                                                  !8
         76    >   IS_SMALLER                                               !8, !5
         77      > JMPNZ                                                    ~59, ->48
   28    78    > > RETURN                                                   null

End of function string_shift_left

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
148.07 ms | 1398 KiB | 22 Q