3v4l.org

run code in 300+ PHP versions simultaneously
<?php function sieve($limit) { if ($limit < 3) { if ($limit < 2) { return []; } return array_slice([2, 3], 0, $limit - 1); } $nums = range(3, $limit - !($limit % 2), 2); for ($p = current($nums); $p; next($nums)) { for ($n = $p; $n < $limit; $n += $p) { unset($nums[$n]); } } return $nums; } var_dump(sieve(20));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/YErJ4
function name:  (null)
number of ops:  7
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   23     0  E >   INIT_FCALL                                               'var_dump'
          1        INIT_FCALL                                               'sieve'
          2        SEND_VAL                                                 20
          3        DO_FCALL                                      0  $0      
          4        SEND_VAR                                                 $0
          5        DO_ICALL                                                 
          6      > RETURN                                                   1

Function sieve:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 3, Position 2 = 13
Branch analysis from position: 3
2 jumps found. (Code = 43) Position 1 = 5, Position 2 = 6
Branch analysis from position: 5
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 6
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 13
1 jumps found. (Code = 42) Position 1 = 36
Branch analysis from position: 36
2 jumps found. (Code = 44) Position 1 = 37, Position 2 = 27
Branch analysis from position: 37
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 27
1 jumps found. (Code = 42) Position 1 = 31
Branch analysis from position: 31
2 jumps found. (Code = 44) Position 1 = 33, Position 2 = 29
Branch analysis from position: 33
2 jumps found. (Code = 44) Position 1 = 37, Position 2 = 27
Branch analysis from position: 37
Branch analysis from position: 27
Branch analysis from position: 29
2 jumps found. (Code = 44) Position 1 = 33, Position 2 = 29
Branch analysis from position: 33
Branch analysis from position: 29
filename:       /in/YErJ4
function name:  sieve
number of ops:  39
compiled vars:  !0 = $limit, !1 = $nums, !2 = $p, !3 = $n
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
    4     1        IS_SMALLER                                               !0, 3
          2      > JMPZ                                                     ~4, ->13
    5     3    >   IS_SMALLER                                               !0, 2
          4      > JMPZ                                                     ~5, ->6
    6     5    > > RETURN                                                   <array>
    9     6    >   INIT_FCALL                                               'array_slice'
          7        SEND_VAL                                                 <array>
          8        SEND_VAL                                                 0
          9        SUB                                              ~6      !0, 1
         10        SEND_VAL                                                 ~6
         11        DO_ICALL                                         $7      
         12      > RETURN                                                   $7
   12    13    >   INIT_FCALL                                               'range'
         14        SEND_VAL                                                 3
         15        MOD                                              ~8      !0, 2
         16        BOOL_NOT                                         ~9      ~8
         17        SUB                                              ~10     !0, ~9
         18        SEND_VAL                                                 ~10
         19        SEND_VAL                                                 2
         20        DO_ICALL                                         $11     
         21        ASSIGN                                                   !1, $11
   14    22        INIT_FCALL                                               'current'
         23        SEND_VAR                                                 !1
         24        DO_ICALL                                         $13     
         25        ASSIGN                                                   !2, $13
         26      > JMP                                                      ->36
   15    27    >   ASSIGN                                                   !3, !2
         28      > JMP                                                      ->31
   16    29    >   UNSET_DIM                                                !1, !3
   15    30        ASSIGN_OP                                     1          !3, !2
         31    >   IS_SMALLER                                               !3, !0
         32      > JMPNZ                                                    ~17, ->29
   14    33    >   INIT_FCALL                                               'next'
         34        SEND_REF                                                 !1
         35        DO_ICALL                                                 
         36    > > JMPNZ                                                    !2, ->27
   20    37    > > RETURN                                                   !1
   21    38*     > RETURN                                                   null

End of function sieve

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
149.26 ms | 1403 KiB | 24 Q