3v4l.org

run code in 300+ PHP versions simultaneously
<?php function greatest_prime($n) { for($x1 = (int)floor(sqrt($n)); $x1 > 3; $x1--) { if($n % $x1 != 0) continue; $x2 = $n/$x1; if(is_prime($x1)) return $x1; if(is_prime($x2)) return $x2; } } function is_prime($x) { for($y = (int)floor(sqrt($x)); $y > 1; $y--) if($x % $y == 0) return false; return true; } var_dump(greatest_prime(600851475143));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/jXd3E
function name:  (null)
number of ops:  7
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   23     0  E >   INIT_FCALL                                               'var_dump'
          1        INIT_FCALL                                               'greatest_prime'
          2        SEND_VAL                                                 600851475143
          3        DO_FCALL                                      0  $0      
          4        SEND_VAR                                                 $0
          5        DO_ICALL                                                 
   24     6      > RETURN                                                   1

Function greatest_prime:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 27
Branch analysis from position: 27
2 jumps found. (Code = 44) Position 1 = 29, Position 2 = 10
Branch analysis from position: 29
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 10
2 jumps found. (Code = 43) Position 1 = 13, Position 2 = 14
Branch analysis from position: 13
1 jumps found. (Code = 42) Position 1 = 26
Branch analysis from position: 26
2 jumps found. (Code = 44) Position 1 = 29, Position 2 = 10
Branch analysis from position: 29
Branch analysis from position: 10
Branch analysis from position: 14
2 jumps found. (Code = 43) Position 1 = 20, Position 2 = 21
Branch analysis from position: 20
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 21
2 jumps found. (Code = 43) Position 1 = 25, Position 2 = 26
Branch analysis from position: 25
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 26
filename:       /in/jXd3E
function name:  greatest_prime
number of ops:  30
compiled vars:  !0 = $n, !1 = $x1, !2 = $x2
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
    5     1        INIT_FCALL                                               'floor'
          2        INIT_FCALL                                               'sqrt'
          3        SEND_VAR                                                 !0
          4        DO_ICALL                                         $3      
          5        SEND_VAR                                                 $3
          6        DO_ICALL                                         $4      
          7        CAST                                          4  ~5      $4
          8        ASSIGN                                                   !1, ~5
          9      > JMP                                                      ->27
    7    10    >   MOD                                              ~7      !0, !1
         11        IS_NOT_EQUAL                                             ~7, 0
         12      > JMPZ                                                     ~8, ->14
    8    13    > > JMP                                                      ->26
    9    14    >   DIV                                              ~9      !0, !1
         15        ASSIGN                                                   !2, ~9
   10    16        INIT_FCALL_BY_NAME                                       'is_prime'
         17        SEND_VAR_EX                                              !1
         18        DO_FCALL                                      0  $11     
         19      > JMPZ                                                     $11, ->21
   11    20    > > RETURN                                                   !1
   12    21    >   INIT_FCALL_BY_NAME                                       'is_prime'
         22        SEND_VAR_EX                                              !2
         23        DO_FCALL                                      0  $12     
         24      > JMPZ                                                     $12, ->26
   13    25    > > RETURN                                                   !2
    5    26    >   PRE_DEC                                                  !1
         27    >   IS_SMALLER                                               3, !1
         28      > JMPNZ                                                    ~14, ->10
   15    29    > > RETURN                                                   null

End of function greatest_prime

Function is_prime:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 15
Branch analysis from position: 15
2 jumps found. (Code = 44) Position 1 = 17, Position 2 = 10
Branch analysis from position: 17
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 10
2 jumps found. (Code = 43) Position 1 = 13, Position 2 = 14
Branch analysis from position: 13
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 14
2 jumps found. (Code = 44) Position 1 = 17, Position 2 = 10
Branch analysis from position: 17
Branch analysis from position: 10
filename:       /in/jXd3E
function name:  is_prime
number of ops:  19
compiled vars:  !0 = $x, !1 = $y
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   16     0  E >   RECV                                             !0      
   18     1        INIT_FCALL                                               'floor'
          2        INIT_FCALL                                               'sqrt'
          3        SEND_VAR                                                 !0
          4        DO_ICALL                                         $2      
          5        SEND_VAR                                                 $2
          6        DO_ICALL                                         $3      
          7        CAST                                          4  ~4      $3
          8        ASSIGN                                                   !1, ~4
          9      > JMP                                                      ->15
   19    10    >   MOD                                              ~6      !0, !1
         11        IS_EQUAL                                                 ~6, 0
         12      > JMPZ                                                     ~7, ->14
   20    13    > > RETURN                                                   <false>
   18    14    >   PRE_DEC                                                  !1
         15    >   IS_SMALLER                                               1, !1
         16      > JMPNZ                                                    ~9, ->10
   21    17    > > RETURN                                                   <true>
   22    18*     > RETURN                                                   null

End of function is_prime

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
174.26 ms | 1403 KiB | 20 Q