3v4l.org

run code in 300+ PHP versions simultaneously
<?php function mask(int $bits, int $ones): string { $m = ""; for ($i = 0; $i < $bits/8; $i++) { if ($ones >= 8) { $m .= chr(0xff); $ones -= 8; } else { $m .= chr(~(0xff>>$ones)); $ones = 0; } } return $m; } $addr = inet_pton("d7a:5949:11d0:bd9e:b2c1:6268:d889:de9b"); $mask = mask(128, 48); $start = ""; for ($i = 0; $i < strlen($addr); $i++) { $start .= $addr[$i] & $mask[$i]; } echo inet_ntop($start), "\n";
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 = 12
Branch analysis from position: 20
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 12
2 jumps found. (Code = 44) Position 1 = 20, Position 2 = 12
Branch analysis from position: 20
Branch analysis from position: 12
filename:       /in/hrD6a
function name:  (null)
number of ops:  26
compiled vars:  !0 = $addr, !1 = $mask, !2 = $start, !3 = $i
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   20     0  E >   INIT_FCALL                                               'inet_pton'
          1        SEND_VAL                                                 'd7a%3A5949%3A11d0%3Abd9e%3Ab2c1%3A6268%3Ad889%3Ade9b'
          2        DO_ICALL                                         $4      
          3        ASSIGN                                                   !0, $4
   21     4        INIT_FCALL                                               'mask'
          5        SEND_VAL                                                 128
          6        SEND_VAL                                                 48
          7        DO_FCALL                                      0  $6      
          8        ASSIGN                                                   !1, $6
   23     9        ASSIGN                                                   !2, ''
   24    10        ASSIGN                                                   !3, 0
         11      > JMP                                                      ->17
   25    12    >   FETCH_DIM_R                                      ~10     !0, !3
         13        FETCH_DIM_R                                      ~11     !1, !3
         14        BW_AND                                           ~12     ~10, ~11
         15        ASSIGN_OP                                     8          !2, ~12
   24    16        PRE_INC                                                  !3
         17    >   STRLEN                                           ~15     !0
         18        IS_SMALLER                                               !3, ~15
         19      > JMPNZ                                                    ~16, ->12
   29    20    >   INIT_FCALL                                               'inet_ntop'
         21        SEND_VAR                                                 !2
         22        DO_ICALL                                         $17     
         23        ECHO                                                     $17
         24        ECHO                                                     '%0A'
         25      > RETURN                                                   1

Function mask:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 18
Branch analysis from position: 18
2 jumps found. (Code = 44) Position 1 = 21, Position 2 = 5
Branch analysis from position: 21
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 5
2 jumps found. (Code = 43) Position 1 = 7, Position 2 = 10
Branch analysis from position: 7
1 jumps found. (Code = 42) Position 1 = 17
Branch analysis from position: 17
2 jumps found. (Code = 44) Position 1 = 21, Position 2 = 5
Branch analysis from position: 21
Branch analysis from position: 5
Branch analysis from position: 10
2 jumps found. (Code = 44) Position 1 = 21, Position 2 = 5
Branch analysis from position: 21
Branch analysis from position: 5
filename:       /in/hrD6a
function name:  mask
number of ops:  25
compiled vars:  !0 = $bits, !1 = $ones, !2 = $m, !3 = $i
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
          1        RECV                                             !1      
    5     2        ASSIGN                                                   !2, ''
    7     3        ASSIGN                                                   !3, 0
          4      > JMP                                                      ->18
    8     5    >   IS_SMALLER_OR_EQUAL                                      8, !1
          6      > JMPZ                                                     ~6, ->10
    9     7    >   ASSIGN_OP                                     8          !2, '%FF'
   10     8        ASSIGN_OP                                     2          !1, 8
    8     9      > JMP                                                      ->17
   12    10    >   INIT_FCALL                                               'chr'
         11        SR                                               ~9      255, !1
         12        BW_NOT                                           ~10     ~9
         13        SEND_VAL                                                 ~10
         14        DO_ICALL                                         $11     
         15        ASSIGN_OP                                     8          !2, $11
   13    16        ASSIGN                                                   !1, 0
    7    17    >   PRE_INC                                                  !3
         18    >   DIV                                              ~15     !0, 8
         19        IS_SMALLER                                               !3, ~15
         20      > JMPNZ                                                    ~16, ->5
   17    21    >   VERIFY_RETURN_TYPE                                       !2
         22      > RETURN                                                   !2
   18    23*       VERIFY_RETURN_TYPE                                       
         24*     > RETURN                                                   null

End of function mask

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
153.09 ms | 1020 KiB | 17 Q