3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Tree { public $i; public $l; public $r; public function __construct($item, $depth) { $this->i = $item; if($depth) { $this->l = new Tree($item * 2 - 1, --$depth); $this->r = new Tree($item * 2, $depth); } } public function check() { return $this->i + ($this->l->l === null ? $this->l->check() : $this->l->i) - ($this->r->l === null ? $this->r->check() : $this->r->i); } } $minDepth = 10; $n = $argc == 2 ? $argv[1] : 1; $maxDepth = $minDepth + 2 > $n ? $minDepth + 2 : $n; $stretchDepth = $maxDepth + 1; $stretch = new Tree(0, $stretchDepth); printf("stretch tree of depth %d\t check: %d\n", $stretchDepth, $stretch->check()); unset($stretch); $longLivedTree = new Tree(0, $maxDepth); $iterations = 1 << $maxDepth; do { $check = 0; for($i = 1; $i <= $iterations; ++$i) { $check += (new Tree($i, $minDepth))->check() + (new Tree(-$i, $minDepth))->check(); } printf("%d\t trees of depth %d\t check: %d\n", $iterations<<1, $minDepth, $check); $minDepth += 2; $iterations >>= 2; } while($minDepth <= $maxDepth); printf("long lived tree of depth %d\t check: %d\n", $maxDepth, $longLivedTree->check());
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 3, Position 2 = 6
Branch analysis from position: 3
1 jumps found. (Code = 42) Position 1 = 7
Branch analysis from position: 7
2 jumps found. (Code = 43) Position 1 = 11, Position 2 = 14
Branch analysis from position: 11
1 jumps found. (Code = 42) Position 1 = 15
Branch analysis from position: 15
1 jumps found. (Code = 42) Position 1 = 57
Branch analysis from position: 57
2 jumps found. (Code = 44) Position 1 = 59, Position 2 = 41
Branch analysis from position: 59
2 jumps found. (Code = 44) Position 1 = 70, Position 2 = 38
Branch analysis from position: 70
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 38
Branch analysis from position: 41
2 jumps found. (Code = 44) Position 1 = 59, Position 2 = 41
Branch analysis from position: 59
Branch analysis from position: 41
Branch analysis from position: 14
1 jumps found. (Code = 42) Position 1 = 57
Branch analysis from position: 57
Branch analysis from position: 6
2 jumps found. (Code = 43) Position 1 = 11, Position 2 = 14
Branch analysis from position: 11
Branch analysis from position: 14
filename:       /in/ddVAG
function name:  (null)
number of ops:  78
compiled vars:  !0 = $minDepth, !1 = $n, !2 = $argc, !3 = $argv, !4 = $maxDepth, !5 = $stretchDepth, !6 = $stretch, !7 = $longLivedTree, !8 = $iterations, !9 = $check, !10 = $i
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   23     0  E >   ASSIGN                                                   !0, 10
   25     1        IS_EQUAL                                                 !2, 2
          2      > JMPZ                                                     ~12, ->6
          3    >   FETCH_DIM_R                                      ~13     !3, 1
          4        QM_ASSIGN                                        ~14     ~13
          5      > JMP                                                      ->7
          6    >   QM_ASSIGN                                        ~14     1
          7    >   ASSIGN                                                   !1, ~14
   26     8        ADD                                              ~16     !0, 2
          9        IS_SMALLER                                               !1, ~16
         10      > JMPZ                                                     ~17, ->14
         11    >   ADD                                              ~18     !0, 2
         12        QM_ASSIGN                                        ~19     ~18
         13      > JMP                                                      ->15
         14    >   QM_ASSIGN                                        ~19     !1
         15    >   ASSIGN                                                   !4, ~19
   27    16        ADD                                              ~21     !4, 1
         17        ASSIGN                                                   !5, ~21
   29    18        NEW                                              $23     'Tree'
         19        SEND_VAL_EX                                              0
         20        SEND_VAR_EX                                              !5
         21        DO_FCALL                                      0          
         22        ASSIGN                                                   !6, $23
   30    23        INIT_FCALL                                               'printf'
         24        SEND_VAL                                                 'stretch+tree+of+depth+%25d%09+check%3A+%25d%0A'
   31    25        SEND_VAR                                                 !5
         26        INIT_METHOD_CALL                                         !6, 'check'
         27        DO_FCALL                                      0  $26     
         28        SEND_VAR                                                 $26
         29        DO_ICALL                                                 
   32    30        UNSET_CV                                                 !6
   34    31        NEW                                              $28     'Tree'
         32        SEND_VAL_EX                                              0
         33        SEND_VAR_EX                                              !4
         34        DO_FCALL                                      0          
         35        ASSIGN                                                   !7, $28
   36    36        SL                                               ~31     1, !4
         37        ASSIGN                                                   !8, ~31
   39    38    >   ASSIGN                                                   !9, 0
   40    39        ASSIGN                                                   !10, 1
         40      > JMP                                                      ->57
   42    41    >   NEW                                              $35     'Tree'
         42        SEND_VAR_EX                                              !10
         43        SEND_VAR_EX                                              !0
         44        DO_FCALL                                      0          
         45        INIT_METHOD_CALL                                         $35, 'check'
         46        DO_FCALL                                      0  $37     
   43    47        NEW                                              $38     'Tree'
         48        MUL                                              ~39     !10, -1
         49        SEND_VAL_EX                                              ~39
         50        SEND_VAR_EX                                              !0
         51        DO_FCALL                                      0          
         52        INIT_METHOD_CALL                                         $38, 'check'
         53        DO_FCALL                                      0  $41     
         54        ADD                                              ~42     $37, $41
         55        ASSIGN_OP                                     1          !9, ~42
   40    56        PRE_INC                                                  !10
         57    >   IS_SMALLER_OR_EQUAL                                      !10, !8
         58      > JMPNZ                                                    ~45, ->41
   46    59    >   INIT_FCALL                                               'printf'
         60        SEND_VAL                                                 '%25d%09+trees+of+depth+%25d%09+check%3A+%25d%0A'
   47    61        SL                                               ~46     !8, 1
         62        SEND_VAL                                                 ~46
         63        SEND_VAR                                                 !0
         64        SEND_VAR                                                 !9
         65        DO_ICALL                                                 
   49    66        ASSIGN_OP                                     1          !0, 2
   50    67        ASSIGN_OP                                     7          !8, 2
   52    68        IS_SMALLER_OR_EQUAL                                      !0, !4
         69      > JMPNZ                                                    ~50, ->38
   54    70    >   INIT_FCALL                                               'printf'
         71        SEND_VAL                                                 'long+lived+tree+of+depth+%25d%09+check%3A+%25d%0A'
   55    72        SEND_VAR                                                 !4
         73        INIT_METHOD_CALL                                         !7, 'check'
         74        DO_FCALL                                      0  $51     
         75        SEND_VAR                                                 $51
         76        DO_ICALL                                                 
         77      > RETURN                                                   1

Class Tree:
Function __construct:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 5, Position 2 = 21
Branch analysis from position: 5
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 21
filename:       /in/ddVAG
function name:  __construct
number of ops:  22
compiled vars:  !0 = $item, !1 = $depth
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    8     0  E >   RECV                                             !0      
          1        RECV                                             !1      
    9     2        ASSIGN_OBJ                                               'i'
          3        OP_DATA                                                  !0
   10     4      > JMPZ                                                     !1, ->21
   11     5    >   NEW                                              $4      'Tree'
          6        MUL                                              ~5      !0, 2
          7        SUB                                              ~6      ~5, 1
          8        SEND_VAL_EX                                              ~6
          9        PRE_DEC                                          ~7      !1
         10        SEND_VAL_EX                                              ~7
         11        DO_FCALL                                      0          
         12        ASSIGN_OBJ                                               'l'
         13        OP_DATA                                                  $4
   12    14        NEW                                              $10     'Tree'
         15        MUL                                              ~11     !0, 2
         16        SEND_VAL_EX                                              ~11
         17        SEND_VAR_EX                                              !1
         18        DO_FCALL                                      0          
         19        ASSIGN_OBJ                                               'r'
         20        OP_DATA                                                  $10
   14    21    > > RETURN                                                   null

End of function __construct

Function check:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 5, Position 2 = 10
Branch analysis from position: 5
1 jumps found. (Code = 42) Position 1 = 13
Branch analysis from position: 13
2 jumps found. (Code = 43) Position 1 = 18, Position 2 = 23
Branch analysis from position: 18
1 jumps found. (Code = 42) Position 1 = 26
Branch analysis from position: 26
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 23
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 10
2 jumps found. (Code = 43) Position 1 = 18, Position 2 = 23
Branch analysis from position: 18
Branch analysis from position: 23
filename:       /in/ddVAG
function name:  check
number of ops:  29
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   17     0  E >   FETCH_OBJ_R                                      ~0      'i'
   18     1        FETCH_OBJ_R                                      ~1      'l'
          2        FETCH_OBJ_R                                      ~2      ~1, 'l'
          3        TYPE_CHECK                                    2          ~2
          4      > JMPZ                                                     ~3, ->10
          5    >   FETCH_OBJ_R                                      ~4      'l'
          6        INIT_METHOD_CALL                                         ~4, 'check'
          7        DO_FCALL                                      0  $5      
          8        QM_ASSIGN                                        ~6      $5
          9      > JMP                                                      ->13
         10    >   FETCH_OBJ_R                                      ~7      'l'
         11        FETCH_OBJ_R                                      ~8      ~7, 'i'
         12        QM_ASSIGN                                        ~6      ~8
         13    >   ADD                                              ~9      ~0, ~6
   19    14        FETCH_OBJ_R                                      ~10     'r'
         15        FETCH_OBJ_R                                      ~11     ~10, 'l'
         16        TYPE_CHECK                                    2          ~11
         17      > JMPZ                                                     ~12, ->23
         18    >   FETCH_OBJ_R                                      ~13     'r'
         19        INIT_METHOD_CALL                                         ~13, 'check'
         20        DO_FCALL                                      0  $14     
         21        QM_ASSIGN                                        ~15     $14
         22      > JMP                                                      ->26
         23    >   FETCH_OBJ_R                                      ~16     'r'
         24        FETCH_OBJ_R                                      ~17     ~16, 'i'
         25        QM_ASSIGN                                        ~15     ~17
         26    >   SUB                                              ~18     ~9, ~15
         27      > RETURN                                                   ~18
   20    28*     > RETURN                                                   null

End of function check

End of class Tree.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
161.79 ms | 1408 KiB | 15 Q