3v4l.org

run code in 300+ PHP versions simultaneously
<?php $A = [-9, -2, 1, 5, 9]; $X = 5; function solution(&$A, $X) { $N = sizeof($A); if ($N == 0) { return -1; } $l = 0; $r = $N - 1; while ($l < $r) { $m = (int)(($l + $r) / 2); echo $m; if ($A[$m] > $X) { $r = $m - 1; } else { $l = $m; } $m = (int)(($l + $r) / 2); echo $m; exit; } if ($A[$l] == $X) { return $l; } else return -1; } var_dump(solution($A, $X));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/nKn6t
function name:  (null)
number of ops:  10
compiled vars:  !0 = $A, !1 = $X
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
    4     1        ASSIGN                                                   !1, 5
   31     2        INIT_FCALL                                               'var_dump'
          3        INIT_FCALL                                               'solution'
          4        SEND_REF                                                 !0
          5        SEND_VAR                                                 !1
          6        DO_FCALL                                      0  $4      
          7        SEND_VAR                                                 $4
          8        DO_ICALL                                                 
          9      > RETURN                                                   1

Function solution:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 6, Position 2 = 7
Branch analysis from position: 6
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 7
1 jumps found. (Code = 42) Position 1 = 29
Branch analysis from position: 29
2 jumps found. (Code = 44) Position 1 = 31, Position 2 = 11
Branch analysis from position: 31
2 jumps found. (Code = 43) Position 1 = 34, Position 2 = 36
Branch analysis from position: 34
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 36
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 11
2 jumps found. (Code = 43) Position 1 = 19, Position 2 = 22
Branch analysis from position: 19
1 jumps found. (Code = 42) Position 1 = 23
Branch analysis from position: 23
1 jumps found. (Code = 79) Position 1 = -2
Branch analysis from position: 22
1 jumps found. (Code = 79) Position 1 = -2
filename:       /in/nKn6t
function name:  solution
number of ops:  38
compiled vars:  !0 = $A, !1 = $X, !2 = $N, !3 = $l, !4 = $r, !5 = $m
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    6     0  E >   RECV                                             !0      
          1        RECV                                             !1      
    7     2        COUNT                                            ~6      !0
          3        ASSIGN                                                   !2, ~6
    8     4        IS_EQUAL                                                 !2, 0
          5      > JMPZ                                                     ~8, ->7
    9     6    > > RETURN                                                   -1
   11     7    >   ASSIGN                                                   !3, 0
   12     8        SUB                                              ~10     !2, 1
          9        ASSIGN                                                   !4, ~10
   13    10      > JMP                                                      ->29
   14    11    >   ADD                                              ~12     !3, !4
         12        DIV                                              ~13     ~12, 2
         13        CAST                                          4  ~14     ~13
         14        ASSIGN                                                   !5, ~14
   15    15        ECHO                                                     !5
   16    16        FETCH_DIM_R                                      ~16     !0, !5
         17        IS_SMALLER                                               !1, ~16
         18      > JMPZ                                                     ~17, ->22
   17    19    >   SUB                                              ~18     !5, 1
         20        ASSIGN                                                   !4, ~18
         21      > JMP                                                      ->23
   19    22    >   ASSIGN                                                   !3, !5
   21    23    >   ADD                                              ~21     !3, !4
         24        DIV                                              ~22     ~21, 2
         25        CAST                                          4  ~23     ~22
         26        ASSIGN                                                   !5, ~23
   22    27        ECHO                                                     !5
   23    28      > EXIT                                                     
   13    29    >   IS_SMALLER                                               !3, !4
         30      > JMPNZ                                                    ~25, ->11
   25    31    >   FETCH_DIM_R                                      ~26     !0, !3
         32        IS_EQUAL                                                 !1, ~26
         33      > JMPZ                                                     ~27, ->36
   26    34    > > RETURN                                                   !3
         35*       JMP                                                      ->37
   28    36    > > RETURN                                                   -1
   29    37*     > RETURN                                                   null

End of function solution

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
143.86 ms | 1403 KiB | 16 Q