3v4l.org

run code in 300+ PHP versions simultaneously
<?php // The magic three sequence is the sum of the previous three values minus 1. // // 0,1,1,1,2,3,5, // // assume $n >= 0 function magicThree($n) { $n--; // To an index; $s = array(0,1,1,1); if ($n > 3) { for ($i = 4; $i < $n; $i++) { $s[$i] = $s[$i-1] + $s[$i-2] + $s[$i-3] - 1; } } else { $result = $s[$n]; } print $result; } magicThree(5); ?>
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/OmgqV
function name:  (null)
number of ops:  4
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   31     0  E >   INIT_FCALL                                               'magicthree'
          1        SEND_VAL                                                 5
          2        DO_FCALL                                      0          
   33     3      > RETURN                                                   1

Function magicthree:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 5, Position 2 = 22
Branch analysis from position: 5
1 jumps found. (Code = 42) Position 1 = 19
Branch analysis from position: 19
2 jumps found. (Code = 44) Position 1 = 21, Position 2 = 7
Branch analysis from position: 21
1 jumps found. (Code = 42) Position 1 = 24
Branch analysis from position: 24
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 7
2 jumps found. (Code = 44) Position 1 = 21, Position 2 = 7
Branch analysis from position: 21
Branch analysis from position: 7
Branch analysis from position: 22
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/OmgqV
function name:  magicThree
number of ops:  26
compiled vars:  !0 = $n, !1 = $s, !2 = $i, !3 = $result
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    9     0  E >   RECV                                             !0      
   11     1        PRE_DEC                                                  !0
   13     2        ASSIGN                                                   !1, <array>
   15     3        IS_SMALLER                                               3, !0
          4      > JMPZ                                                     ~6, ->22
   17     5    >   ASSIGN                                                   !2, 4
          6      > JMP                                                      ->19
   19     7    >   SUB                                              ~9      !2, 1
          8        FETCH_DIM_R                                      ~10     !1, ~9
          9        SUB                                              ~11     !2, 2
         10        FETCH_DIM_R                                      ~12     !1, ~11
         11        ADD                                              ~13     ~10, ~12
         12        SUB                                              ~14     !2, 3
         13        FETCH_DIM_R                                      ~15     !1, ~14
         14        ADD                                              ~16     ~13, ~15
         15        SUB                                              ~17     ~16, 1
         16        ASSIGN_DIM                                               !1, !2
         17        OP_DATA                                                  ~17
   17    18        PRE_INC                                                  !2
         19    >   IS_SMALLER                                               !2, !0
         20      > JMPNZ                                                    ~19, ->7
         21    > > JMP                                                      ->24
   24    22    >   FETCH_DIM_R                                      ~20     !1, !0
         23        ASSIGN                                                   !3, ~20
   27    24    >   ECHO                                                     !3
   29    25      > RETURN                                                   null

End of function magicthree

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
187.56 ms | 1399 KiB | 14 Q