3v4l.org

run code in 300+ PHP versions simultaneously
<?php const INT_SIGNED = 1; const INT_LE = 2; function unpack_int32($str, $flags = 0) { $length = strlen($str); if ($length < 4) { return false; } else if ($length > 4) { $str = substr($str, 0, 4); } $format = ($flags & INT_LE) ? 'V' : 'N'; $result = current(unpack($format, $str)); $signBit = (bool) ($result & 0x80000000); $isSigned = (bool) ($flags & INT_SIGNED); $is32bit = PHP_INT_MAX < 0x80000000; if ($signBit && $isSigned && !$is32bit) { $result = 0xFFFFFFFF00000000 | $result; } else if ($signBit && !$isSigned && $is32bit) { $result = (($result & 0x7FFFFFFF) * 2) + ~$result + 1; } return $result; } var_dump(unpack_int32("\x81\x00\x00\x00", INT_SIGNED | INT_LE));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/DZIAX
function name:  (null)
number of ops:  13
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   DECLARE_CONST                                            'INT_SIGNED', 1
    4     1        DECLARE_CONST                                            'INT_LE', 2
   30     2        INIT_FCALL                                               'var_dump'
          3        INIT_FCALL                                               'unpack_int32'
          4        SEND_VAL                                                 '%81%00%00%00'
          5        FETCH_CONSTANT                                   ~0      'INT_SIGNED'
          6        FETCH_CONSTANT                                   ~1      'INT_LE'
          7        BW_OR                                            ~2      ~0, ~1
          8        SEND_VAL                                                 ~2
          9        DO_FCALL                                      0  $3      
         10        SEND_VAR                                                 $3
         11        DO_ICALL                                                 
         12      > RETURN                                                   1

Function unpack_int32:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 6, Position 2 = 8
Branch analysis from position: 6
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 8
2 jumps found. (Code = 43) Position 1 = 10, Position 2 = 16
Branch analysis from position: 10
2 jumps found. (Code = 43) Position 1 = 19, Position 2 = 21
Branch analysis from position: 19
1 jumps found. (Code = 42) Position 1 = 22
Branch analysis from position: 22
2 jumps found. (Code = 46) Position 1 = 40, Position 2 = 41
Branch analysis from position: 40
2 jumps found. (Code = 46) Position 1 = 42, Position 2 = 44
Branch analysis from position: 42
2 jumps found. (Code = 43) Position 1 = 45, Position 2 = 48
Branch analysis from position: 45
1 jumps found. (Code = 42) Position 1 = 60
Branch analysis from position: 60
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 48
2 jumps found. (Code = 46) Position 1 = 49, Position 2 = 51
Branch analysis from position: 49
2 jumps found. (Code = 46) Position 1 = 52, Position 2 = 53
Branch analysis from position: 52
2 jumps found. (Code = 43) Position 1 = 54, Position 2 = 60
Branch analysis from position: 54
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 60
Branch analysis from position: 53
Branch analysis from position: 51
Branch analysis from position: 44
Branch analysis from position: 41
Branch analysis from position: 21
2 jumps found. (Code = 46) Position 1 = 40, Position 2 = 41
Branch analysis from position: 40
Branch analysis from position: 41
Branch analysis from position: 16
filename:       /in/DZIAX
function name:  unpack_int32
number of ops:  62
compiled vars:  !0 = $str, !1 = $flags, !2 = $length, !3 = $format, !4 = $result, !5 = $signBit, !6 = $isSigned, !7 = $is32bit
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    6     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      0
    7     2        STRLEN                                           ~8      !0
          3        ASSIGN                                                   !2, ~8
    8     4        IS_SMALLER                                               !2, 4
          5      > JMPZ                                                     ~10, ->8
    9     6    > > RETURN                                                   <false>
          7*       JMP                                                      ->16
   10     8    >   IS_SMALLER                                               4, !2
          9      > JMPZ                                                     ~11, ->16
   11    10    >   INIT_FCALL                                               'substr'
         11        SEND_VAR                                                 !0
         12        SEND_VAL                                                 0
         13        SEND_VAL                                                 4
         14        DO_ICALL                                         $12     
         15        ASSIGN                                                   !0, $12
   14    16    >   FETCH_CONSTANT                                   ~14     'INT_LE'
         17        BW_AND                                           ~15     !1, ~14
         18      > JMPZ                                                     ~15, ->21
         19    >   QM_ASSIGN                                        ~16     'V'
         20      > JMP                                                      ->22
         21    >   QM_ASSIGN                                        ~16     'N'
         22    >   ASSIGN                                                   !3, ~16
   15    23        INIT_FCALL                                               'current'
         24        INIT_FCALL                                               'unpack'
         25        SEND_VAR                                                 !3
         26        SEND_VAR                                                 !0
         27        DO_ICALL                                         $18     
         28        SEND_VAR                                                 $18
         29        DO_ICALL                                         $19     
         30        ASSIGN                                                   !4, $19
   17    31        BW_AND                                           ~21     !4, 2147483648
         32        BOOL                                             ~22     ~21
         33        ASSIGN                                                   !5, ~22
   18    34        FETCH_CONSTANT                                   ~24     'INT_SIGNED'
         35        BW_AND                                           ~25     !1, ~24
         36        BOOL                                             ~26     ~25
         37        ASSIGN                                                   !6, ~26
   19    38        ASSIGN                                                   !7, <false>
   21    39      > JMPZ_EX                                          ~29     !5, ->41
         40    >   BOOL                                             ~29     !6
         41    > > JMPZ_EX                                          ~29     ~29, ->44
         42    >   BOOL_NOT                                         ~30     !7
         43        BOOL                                             ~29     ~30
         44    > > JMPZ                                                     ~29, ->48
   22    45    >   BW_OR                                            ~31     !4, 1.84467e+19
         46        ASSIGN                                                   !4, ~31
         47      > JMP                                                      ->60
   23    48    > > JMPZ_EX                                          ~33     !5, ->51
         49    >   BOOL_NOT                                         ~34     !6
         50        BOOL                                             ~33     ~34
         51    > > JMPZ_EX                                          ~33     ~33, ->53
         52    >   BOOL                                             ~33     !7
         53    > > JMPZ                                                     ~33, ->60
   24    54    >   BW_AND                                           ~35     !4, 2147483647
         55        MUL                                              ~36     ~35, 2
         56        BW_NOT                                           ~37     !4
         57        ADD                                              ~38     ~36, ~37
         58        ADD                                              ~39     ~38, 1
         59        ASSIGN                                                   !4, ~39
   27    60    > > RETURN                                                   !4
   28    61*     > RETURN                                                   null

End of function unpack_int32

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
157.67 ms | 1407 KiB | 22 Q