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 - 1; } 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/iaeSD
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 = 25
Branch analysis from position: 25
2 jumps found. (Code = 46) Position 1 = 27, Position 2 = 30
Branch analysis from position: 27
2 jumps found. (Code = 44) Position 1 = 31, Position 2 = 14
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: 14
2 jumps found. (Code = 43) Position 1 = 21, Position 2 = 24
Branch analysis from position: 21
1 jumps found. (Code = 42) Position 1 = 25
Branch analysis from position: 25
Branch analysis from position: 24
2 jumps found. (Code = 46) Position 1 = 27, Position 2 = 30
Branch analysis from position: 27
Branch analysis from position: 30
Branch analysis from position: 30
filename:       /in/iaeSD
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
-------------------------------------------------------------------------------------
   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                                                      ->25
   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, ->24
   21    21    >   SUB                                              ~19     !5, 1
         22        ASSIGN                                                   !4, ~19
         23      > JMP                                                      ->25
   23    24    >   ASSIGN                                                   !3, !5
   18    25    >   IS_SMALLER                                       ~22     !3, !4
         26      > JMPZ_EX                                          ~22     ~22, ->30
         27    >   FETCH_DIM_R                                      ~23     !0, !3
         28        IS_NOT_IDENTICAL                                 ~24     !1, ~23
         29        BOOL                                             ~22     ~24
         30    > > JMPNZ                                                    ~22, ->14
   26    31    >   FETCH_DIM_R                                      ~25     !0, !3
         32        IS_EQUAL                                                 !1, ~25
         33      > JMPZ                                                     ~26, ->36
   27    34    > > RETURN                                                   !3
         35*       JMP                                                      ->37
   29    36    > > RETURN                                                   -1
   30    37*     > RETURN                                                   null

End of function solution

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
149.59 ms | 1400 KiB | 19 Q