3v4l.org

run code in 300+ PHP versions simultaneously
<?php declare(strict_types = 1); function readUnsignedVarLong(string $buffer, int &$offset) : int{ $value = 0; for($i = 0; $i <= 63; $i += 7){ if(!isset($buffer[$offset])){ throw new Exception("No bytes left in buffer"); } $b = ord($buffer[$offset++]); $value |= (($b & 0x7f) << $i); if(($b & 0x80) === 0){ return $value; } } throw new Exception("VarLong did not terminate after 10 bytes!"); } $a = 0; var_dump(readUnsignedVarLong(str_repeat(chr(255), 9) . chr(0x80 << 1), $a), PHP_INT_MAX);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/auLE8
function name:  (null)
number of ops:  18
compiled vars:  !0 = $a
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   19     0  E >   ASSIGN                                                   !0, 0
   20     1        INIT_FCALL                                               'var_dump'
          2        INIT_FCALL                                               'readunsignedvarlong'
          3        INIT_FCALL                                               'str_repeat'
          4        SEND_VAL                                                 '%FF'
          5        SEND_VAL                                                 9
          6        DO_ICALL                                         $2      
          7        INIT_FCALL                                               'chr'
          8        SEND_VAL                                                 256
          9        DO_ICALL                                         $3      
         10        CONCAT                                           ~4      $2, $3
         11        SEND_VAL                                                 ~4
         12        SEND_REF                                                 !0
         13        DO_FCALL                                      0  $5      
         14        SEND_VAR                                                 $5
         15        SEND_VAL                                                 9223372036854775807
         16        DO_ICALL                                                 
         17      > RETURN                                                   1

Function readunsignedvarlong:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 27
Branch analysis from position: 27
2 jumps found. (Code = 44) Position 1 = 29, Position 2 = 5
Branch analysis from position: 29
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 5
2 jumps found. (Code = 43) Position 1 = 8, Position 2 = 12
Branch analysis from position: 8
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 12
2 jumps found. (Code = 43) Position 1 = 24, Position 2 = 26
Branch analysis from position: 24
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 26
2 jumps found. (Code = 44) Position 1 = 29, Position 2 = 5
Branch analysis from position: 29
Branch analysis from position: 5
filename:       /in/auLE8
function name:  readUnsignedVarLong
number of ops:  35
compiled vars:  !0 = $buffer, !1 = $offset, !2 = $value, !3 = $i, !4 = $b
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
          1        RECV                                             !1      
    4     2        ASSIGN                                                   !2, 0
    5     3        ASSIGN                                                   !3, 0
          4      > JMP                                                      ->27
    6     5    >   ISSET_ISEMPTY_DIM_OBJ                         0  ~7      !0, !1
          6        BOOL_NOT                                         ~8      ~7
          7      > JMPZ                                                     ~8, ->12
    7     8    >   NEW                                              $9      'Exception'
          9        SEND_VAL_EX                                              'No+bytes+left+in+buffer'
         10        DO_FCALL                                      0          
         11      > THROW                                         0          $9
    9    12    >   INIT_FCALL                                               'ord'
         13        POST_INC                                         ~11     !1
         14        FETCH_DIM_R                                      ~12     !0, ~11
         15        SEND_VAL                                                 ~12
         16        DO_ICALL                                         $13     
         17        ASSIGN                                                   !4, $13
   10    18        BW_AND                                           ~15     !4, 127
         19        SL                                               ~16     ~15, !3
         20        ASSIGN_OP                                     9          !2, ~16
   12    21        BW_AND                                           ~18     !4, 128
         22        IS_IDENTICAL                                             ~18, 0
         23      > JMPZ                                                     ~19, ->26
   13    24    >   VERIFY_RETURN_TYPE                                       !2
         25      > RETURN                                                   !2
    5    26    >   ASSIGN_OP                                     1          !3, 7
         27    >   IS_SMALLER_OR_EQUAL                                      !3, 63
         28      > JMPNZ                                                    ~21, ->5
   17    29    >   NEW                                              $22     'Exception'
         30        SEND_VAL_EX                                              'VarLong+did+not+terminate+after+10+bytes%21'
         31        DO_FCALL                                      0          
         32      > THROW                                         0          $22
   18    33*       VERIFY_RETURN_TYPE                                       
         34*     > RETURN                                                   null

End of function readunsignedvarlong

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
161.36 ms | 1403 KiB | 22 Q