3v4l.org

run code in 300+ PHP versions simultaneously
<?php function gdr_encode($val) { $bin = ''; while ($val > 0) { $bin .= chr($val & 0xFF); $val >>= 8; } return str_replace(array('/', '='), array('_', ''), base64_encode($bin)); } function gdr_decode($str) { $bin = base64_decode(str_replace('_', '/', $str)); $val = 0; for ($i=strlen($bin)-1; $i>=0; $i--) { $val |= ord($bin[$i]) << $i*8; } return $val; } mt_srand(42); // seed rng for semi-consistent values for ($i=0; $i<32; $i++) { $val = 1<<$i; $val += mt_rand(0, $val/2); $enc = gdr_encode($val); $dec = gdr_decode($enc); if ($val === $dec) { echo "$enc $val\n"; } else { echo "$enc $valĀ ERROR: gdr_decode($enc) == $dec\n"; } }
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 39
Branch analysis from position: 39
2 jumps found. (Code = 44) Position 1 = 41, Position 2 = 5
Branch analysis from position: 41
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 5
2 jumps found. (Code = 43) Position 1 = 23, Position 2 = 29
Branch analysis from position: 23
1 jumps found. (Code = 42) Position 1 = 38
Branch analysis from position: 38
2 jumps found. (Code = 44) Position 1 = 41, Position 2 = 5
Branch analysis from position: 41
Branch analysis from position: 5
Branch analysis from position: 29
2 jumps found. (Code = 44) Position 1 = 41, Position 2 = 5
Branch analysis from position: 41
Branch analysis from position: 5
filename:       /in/iZC9n
function name:  (null)
number of ops:  42
compiled vars:  !0 = $i, !1 = $val, !2 = $enc, !3 = $dec, !4 = $valĀ ERROR
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   21     0  E >   INIT_FCALL                                               'mt_srand'
          1        SEND_VAL                                                 42
          2        DO_ICALL                                                 
   22     3        ASSIGN                                                   !0, 0
          4      > JMP                                                      ->39
   23     5    >   SL                                               ~7      1, !0
          6        ASSIGN                                                   !1, ~7
   24     7        INIT_FCALL                                               'mt_rand'
          8        SEND_VAL                                                 0
          9        DIV                                              ~9      !1, 2
         10        SEND_VAL                                                 ~9
         11        DO_ICALL                                         $10     
         12        ASSIGN_OP                                     1          !1, $10
   25    13        INIT_FCALL                                               'gdr_encode'
         14        SEND_VAR                                                 !1
         15        DO_FCALL                                      0  $12     
         16        ASSIGN                                                   !2, $12
   26    17        INIT_FCALL                                               'gdr_decode'
         18        SEND_VAR                                                 !2
         19        DO_FCALL                                      0  $14     
         20        ASSIGN                                                   !3, $14
   27    21        IS_IDENTICAL                                             !1, !3
         22      > JMPZ                                                     ~16, ->29
   28    23    >   ROPE_INIT                                     4  ~18     !2
         24        ROPE_ADD                                      1  ~18     ~18, '+'
         25        ROPE_ADD                                      2  ~18     ~18, !1
         26        ROPE_END                                      3  ~17     ~18, '%0A'
         27        ECHO                                                     ~17
         28      > JMP                                                      ->38
   30    29    >   ROPE_INIT                                     8  ~21     !2
         30        ROPE_ADD                                      1  ~21     ~21, '+'
         31        ROPE_ADD                                      2  ~21     ~21, !4
         32        ROPE_ADD                                      3  ~21     ~21, '%3A+gdr_decode%28'
         33        ROPE_ADD                                      4  ~21     ~21, !2
         34        ROPE_ADD                                      5  ~21     ~21, '%29+%3D%3D+'
         35        ROPE_ADD                                      6  ~21     ~21, !3
         36        ROPE_END                                      7  ~20     ~21, '%0A'
         37        ECHO                                                     ~20
   22    38    >   PRE_INC                                                  !0
         39    >   IS_SMALLER                                               !0, 32
         40      > JMPNZ                                                    ~26, ->5
   32    41    > > RETURN                                                   1

Function gdr_encode:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 9
Branch analysis from position: 9
2 jumps found. (Code = 44) Position 1 = 11, Position 2 = 3
Branch analysis from position: 11
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 3
2 jumps found. (Code = 44) Position 1 = 11, Position 2 = 3
Branch analysis from position: 11
Branch analysis from position: 3
filename:       /in/iZC9n
function name:  gdr_encode
number of ops:  21
compiled vars:  !0 = $val, !1 = $bin
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
    4     1        ASSIGN                                                   !1, ''
    5     2      > JMP                                                      ->9
    6     3    >   INIT_FCALL                                               'chr'
          4        BW_AND                                           ~3      !0, 255
          5        SEND_VAL                                                 ~3
          6        DO_ICALL                                         $4      
          7        ASSIGN_OP                                     8          !1, $4
    7     8        ASSIGN_OP                                     7          !0, 8
    5     9    >   IS_SMALLER                                               0, !0
         10      > JMPNZ                                                    ~7, ->3
    9    11    >   INIT_FCALL                                               'str_replace'
         12        SEND_VAL                                                 <array>
         13        SEND_VAL                                                 <array>
         14        INIT_FCALL                                               'base64_encode'
         15        SEND_VAR                                                 !1
         16        DO_ICALL                                         $8      
         17        SEND_VAR                                                 $8
         18        DO_ICALL                                         $9      
         19      > RETURN                                                   $9
   10    20*     > RETURN                                                   null

End of function gdr_encode

Function gdr_decode:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 23
Branch analysis from position: 23
2 jumps found. (Code = 44) Position 1 = 25, Position 2 = 15
Branch analysis from position: 25
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 15
2 jumps found. (Code = 44) Position 1 = 25, Position 2 = 15
Branch analysis from position: 25
Branch analysis from position: 15
filename:       /in/iZC9n
function name:  gdr_decode
number of ops:  27
compiled vars:  !0 = $str, !1 = $bin, !2 = $val, !3 = $i
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   12     0  E >   RECV                                             !0      
   13     1        INIT_FCALL                                               'base64_decode'
          2        INIT_FCALL                                               'str_replace'
          3        SEND_VAL                                                 '_'
          4        SEND_VAL                                                 '%2F'
          5        SEND_VAR                                                 !0
          6        DO_ICALL                                         $4      
          7        SEND_VAR                                                 $4
          8        DO_ICALL                                         $5      
          9        ASSIGN                                                   !1, $5
   14    10        ASSIGN                                                   !2, 0
   15    11        STRLEN                                           ~8      !1
         12        SUB                                              ~9      ~8, 1
         13        ASSIGN                                                   !3, ~9
         14      > JMP                                                      ->23
   16    15    >   INIT_FCALL                                               'ord'
         16        FETCH_DIM_R                                      ~11     !1, !3
         17        SEND_VAL                                                 ~11
         18        DO_ICALL                                         $12     
         19        MUL                                              ~13     !3, 8
         20        SL                                               ~14     $12, ~13
         21        ASSIGN_OP                                     9          !2, ~14
   15    22        PRE_DEC                                                  !3
         23    >   IS_SMALLER_OR_EQUAL                                      0, !3
         24      > JMPNZ                                                    ~17, ->15
   18    25    > > RETURN                                                   !2
   19    26*     > RETURN                                                   null

End of function gdr_decode

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
152.23 ms | 1407 KiB | 29 Q