3v4l.org

run code in 300+ PHP versions simultaneously
<?php $A = [-9, -2, 1, 5, 9]; 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); if ($A[$m] === $X) return $m; if ($A[$m] > $X) { $r = $m; } else { $l = $m; } } if ($A[$l] == $X) { return $l; } else return -1; } var_dump(solution($A, -9)); var_dump(solution($A, -2)); var_dump(solution($A, 5)); //var_dump(solution($A, 42));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/tYd0W
function name:  (null)
number of ops:  23
compiled vars:  !0 = $A
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
   28     1        INIT_FCALL                                               'var_dump'
          2        INIT_FCALL                                               'solution'
          3        SEND_REF                                                 !0
          4        SEND_VAL                                                 -9
          5        DO_FCALL                                      0  $2      
          6        SEND_VAR                                                 $2
          7        DO_ICALL                                                 
   29     8        INIT_FCALL                                               'var_dump'
          9        INIT_FCALL                                               'solution'
         10        SEND_REF                                                 !0
         11        SEND_VAL                                                 -2
         12        DO_FCALL                                      0  $4      
         13        SEND_VAR                                                 $4
         14        DO_ICALL                                                 
   30    15        INIT_FCALL                                               'var_dump'
         16        INIT_FCALL                                               'solution'
         17        SEND_REF                                                 !0
         18        SEND_VAL                                                 5
         19        DO_FCALL                                      0  $6      
         20        SEND_VAR                                                 $6
         21        DO_ICALL                                                 
   31    22      > 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 = 25
Branch analysis from position: 25
2 jumps found. (Code = 44) Position 1 = 27, Position 2 = 11
Branch analysis from position: 27
2 jumps found. (Code = 43) Position 1 = 30, Position 2 = 32
Branch analysis from position: 30
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 32
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 11
2 jumps found. (Code = 43) Position 1 = 18, Position 2 = 19
Branch analysis from position: 18
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 19
2 jumps found. (Code = 43) Position 1 = 22, Position 2 = 24
Branch analysis from position: 22
1 jumps found. (Code = 42) Position 1 = 25
Branch analysis from position: 25
Branch analysis from position: 24
2 jumps found. (Code = 44) Position 1 = 27, Position 2 = 11
Branch analysis from position: 27
Branch analysis from position: 11
filename:       /in/tYd0W
function name:  solution
number of ops:  34
compiled vars:  !0 = $A, !1 = $X, !2 = $N, !3 = $l, !4 = $r, !5 = $m
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    5     0  E >   RECV                                             !0      
          1        RECV                                             !1      
    6     2        COUNT                                            ~6      !0
          3        ASSIGN                                                   !2, ~6
    7     4        IS_EQUAL                                                 !2, 0
          5      > JMPZ                                                     ~8, ->7
    8     6    > > RETURN                                                   -1
   10     7    >   ASSIGN                                                   !3, 0
   11     8        SUB                                              ~10     !2, 1
          9        ASSIGN                                                   !4, ~10
   12    10      > JMP                                                      ->25
   13    11    >   ADD                                              ~12     !3, !4
         12        DIV                                              ~13     ~12, 2
         13        CAST                                          4  ~14     ~13
         14        ASSIGN                                                   !5, ~14
   14    15        FETCH_DIM_R                                      ~16     !0, !5
         16        IS_IDENTICAL                                             !1, ~16
         17      > JMPZ                                                     ~17, ->19
   15    18    > > RETURN                                                   !5
   16    19    >   FETCH_DIM_R                                      ~18     !0, !5
         20        IS_SMALLER                                               !1, ~18
         21      > JMPZ                                                     ~19, ->24
   17    22    >   ASSIGN                                                   !4, !5
         23      > JMP                                                      ->25
   19    24    >   ASSIGN                                                   !3, !5
   12    25    >   IS_SMALLER                                               !3, !4
         26      > JMPNZ                                                    ~22, ->11
   22    27    >   FETCH_DIM_R                                      ~23     !0, !3
         28        IS_EQUAL                                                 !1, ~23
         29      > JMPZ                                                     ~24, ->32
   23    30    > > RETURN                                                   !3
         31*       JMP                                                      ->33
   25    32    > > RETURN                                                   -1
   26    33*     > RETURN                                                   null

End of function solution

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
164.64 ms | 1402 KiB | 18 Q