3v4l.org

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

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

End of function solution

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
144.01 ms | 1400 KiB | 19 Q