3v4l.org

run code in 300+ PHP versions simultaneously
<?php const INT_SIGNED = 1; const INT_LE = 2; function byteswap($str) { return str_reverse($str); } function unpack_int32($str, $flags = 0) { $length = strlen($str); if ($length < 4) { return false; } else if ($length > 4) { $str = substr($str, 0, 4); } if ($flags & INT_LE) { $str = strrev($str); } $result = current(unpack('N', $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; } function unpack_int64($str, $flags = 0) { $length = strlen($str); if ($length < 8) { return false; } else if ($length > 8) { $str = substr($str, 0, 8); } $is32bit = PHP_INT_MAX < 0x80000000; if ($flags & INT_LE) { $str = strrev($str); } $longs = array_values(unpack('NN', substr($str, 0, 4), substr($str, 4, 4))); $signBit = (bool) ($longs[0] & 0x80000000); if (PHP_INT_MAX > 0x7FFFFFFF) { $result = ($longs[0] << 32) | $longs[1]; if ($signBit) { $result = (($result & 0x7FFFFFFFFFFFFFFF) * 2) + ~$result + 1; } } return $result; } var_dump(unpack_int32("\x81\x00\x00\x80", INT_SIGNED | INT_LE));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Lh7v3
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
   63     2        INIT_FCALL                                               'var_dump'
          3        INIT_FCALL                                               'unpack_int32'
          4        SEND_VAL                                                 '%81%00%00%80'
          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 byteswap:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Lh7v3
function name:  byteswap
number of ops:  6
compiled vars:  !0 = $str
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    6     0  E >   RECV                                             !0      
    7     1        INIT_FCALL_BY_NAME                                       'str_reverse'
          2        SEND_VAR_EX                                              !0
          3        DO_FCALL                                      0  $1      
          4      > RETURN                                                   $1
    8     5*     > RETURN                                                   null

End of function byteswap

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

End of function unpack_int32

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

End of function unpack_int64

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
156.77 ms | 1411 KiB | 26 Q