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,9,16, function magicThree($n) { if ($n < 1) return; $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; } } print $s[$n]; } magicThree(9); ?>
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/82fEv
function name:  (null)
number of ops:  4
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   26     0  E >   INIT_FCALL                                               'magicthree'
          1        SEND_VAL                                                 9
          2        DO_FCALL                                      0          
   28     3      > RETURN                                                   1

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

End of function magicthree

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
153.91 ms | 1390 KiB | 14 Q