3v4l.org

run code in 300+ PHP versions simultaneously
<?php $competitors = [1, 2, 3, 4, 5 , 6, 7, 8]; $rounds = log( count( $competitors ), 2 ) + 1; // round one for( $i = 0; $i < log( count( $competitors ), 2 ); $i++ ) { $seeded = array( ); foreach( $competitors as $competitor ) { $splice = pow( 2, $i ); $seeded = array_merge( $seeded, array_splice( $competitors, 0, $splice ) ); $seeded = array_merge( $seeded, array_splice( $competitors, -$splice ) ); } $competitors = $seeded; } $events = array_chunk( $seeded, 2 ); if( $rounds > 2 ) { $round_index = count( $events ); // second round for( $i = 0; $i < count( $competitors ) / 2; $i++ ) { array_push( $events, array( array( 'from_event_index' => $i, 'from_event_rank' => 1 ), // rank 1 = winner array( 'from_event_index' => ++$i, 'from_event_rank' => 1 ) ) ); } $round_matchups = array( ); for( $i = 0; $i < count( $competitors ) / 2; $i++ ) { array_push( $round_matchups, array( array( 'from_event_index' => $i, 'from_event_rank' => 2 ), // rank 2 = loser array( 'from_event_index' => ++$i, 'from_event_rank' => 2 ) ) ); } $events = array_merge( $events, $round_matchups ); for( $i = 0; $i < count( $round_matchups ); $i++ ) { array_push( $events, array( array( 'from_event_index' => $i + count( $competitors ) / 2, 'from_event_rank' => 2 ), array( 'from_event_index' => $i + count( $competitors ) / 2 + count( $competitors ) / 2 / 2, 'from_event_rank' => 1 ) ) ); } } if( $rounds > 3 ) { // subsequent rounds for( $i = 0; $i < $rounds - 3; $i++ ) { $round_events = pow( 2, $rounds - 3 - $i ); $total_events = count( $events ); for( $j = 0; $j < $round_events; $j++ ) { array_push( $events, array( array( 'from_event_index' => $j + $round_index, 'from_event_rank' => 1 ), array( 'from_event_index' => ++$j + $round_index, 'from_event_rank' => 1 ) ) ); } for( $j = 0; $j < $round_events; $j++ ) { array_push( $events, array( array( 'from_event_index' => $j + $round_index + $round_events * 2, 'from_event_rank' => 1 ), array( 'from_event_index' => ++$j + $round_index + $round_events * 2, 'from_event_rank' => 1 ) ) ); } for( $j = 0; $j < $round_events / 2; $j++ ) { array_push( $events, array( array( 'from_event_index' => $j + $total_events, 'from_event_rank' => 2 ), array( 'from_event_index' => $j + $total_events + $round_events / 2, 'from_event_rank' => 1 ) ) ); } $round_index = $total_events; } } if( $rounds > 1 ) { // finals array_push( $events, array( array( 'from_event_index' => count( $events ) - 3, 'from_event_rank' => 1 ), array( 'from_event_index' => count( $events ) - 1, 'from_event_rank' => 1 ) ) ); } var_dump($events);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 42
Branch analysis from position: 42
2 jumps found. (Code = 44) Position 1 = 49, Position 2 = 10
Branch analysis from position: 49
2 jumps found. (Code = 43) Position 1 = 56, Position 2 = 126
Branch analysis from position: 56
1 jumps found. (Code = 42) Position 1 = 72
Branch analysis from position: 72
2 jumps found. (Code = 44) Position 1 = 76, Position 2 = 60
Branch analysis from position: 76
1 jumps found. (Code = 42) Position 1 = 91
Branch analysis from position: 91
2 jumps found. (Code = 44) Position 1 = 95, Position 2 = 79
Branch analysis from position: 95
1 jumps found. (Code = 42) Position 1 = 123
Branch analysis from position: 123
2 jumps found. (Code = 44) Position 1 = 126, Position 2 = 102
Branch analysis from position: 126
2 jumps found. (Code = 43) Position 1 = 128, Position 2 = 204
Branch analysis from position: 128
1 jumps found. (Code = 42) Position 1 = 201
Branch analysis from position: 201
2 jumps found. (Code = 44) Position 1 = 204, Position 2 = 130
Branch analysis from position: 204
2 jumps found. (Code = 43) Position 1 = 206, Position 2 = 220
Branch analysis from position: 206
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 220
Branch analysis from position: 130
1 jumps found. (Code = 42) Position 1 = 155
Branch analysis from position: 155
2 jumps found. (Code = 44) Position 1 = 157, Position 2 = 141
Branch analysis from position: 157
1 jumps found. (Code = 42) Position 1 = 177
Branch analysis from position: 177
2 jumps found. (Code = 44) Position 1 = 179, Position 2 = 159
Branch analysis from position: 179
1 jumps found. (Code = 42) Position 1 = 196
Branch analysis from position: 196
2 jumps found. (Code = 44) Position 1 = 199, Position 2 = 181
Branch analysis from position: 199
2 jumps found. (Code = 44) Position 1 = 204, Position 2 = 130
Branch analysis from position: 204
Branch analysis from position: 130
Branch analysis from position: 181
2 jumps found. (Code = 44) Position 1 = 199, Position 2 = 181
Branch analysis from position: 199
Branch analysis from position: 181
Branch analysis from position: 159
2 jumps found. (Code = 44) Position 1 = 179, Position 2 = 159
Branch analysis from position: 179
Branch analysis from position: 159
Branch analysis from position: 141
2 jumps found. (Code = 44) Position 1 = 157, Position 2 = 141
Branch analysis from position: 157
Branch analysis from position: 141
Branch analysis from position: 204
Branch analysis from position: 102
2 jumps found. (Code = 44) Position 1 = 126, Position 2 = 102
Branch analysis from position: 126
Branch analysis from position: 102
Branch analysis from position: 79
2 jumps found. (Code = 44) Position 1 = 95, Position 2 = 79
Branch analysis from position: 95
Branch analysis from position: 79
Branch analysis from position: 60
2 jumps found. (Code = 44) Position 1 = 76, Position 2 = 60
Branch analysis from position: 76
Branch analysis from position: 60
Branch analysis from position: 126
Branch analysis from position: 10
2 jumps found. (Code = 77) Position 1 = 12, Position 2 = 39
Branch analysis from position: 12
2 jumps found. (Code = 78) Position 1 = 13, Position 2 = 39
Branch analysis from position: 13
1 jumps found. (Code = 42) Position 1 = 12
Branch analysis from position: 12
Branch analysis from position: 39
2 jumps found. (Code = 44) Position 1 = 49, Position 2 = 10
Branch analysis from position: 49
Branch analysis from position: 10
Branch analysis from position: 39
filename:       /in/r21LC
function name:  (null)
number of ops:  224
compiled vars:  !0 = $competitors, !1 = $rounds, !2 = $i, !3 = $seeded, !4 = $competitor, !5 = $splice, !6 = $events, !7 = $round_index, !8 = $round_matchups, !9 = $round_events, !10 = $total_events, !11 = $j
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
    4     1        INIT_FCALL                                               'log'
          2        COUNT                                            ~13     !0
          3        SEND_VAL                                                 ~13
          4        SEND_VAL                                                 2
          5        DO_ICALL                                         $14     
          6        ADD                                              ~15     $14, 1
          7        ASSIGN                                                   !1, ~15
    7     8        ASSIGN                                                   !2, 0
          9      > JMP                                                      ->42
    9    10    >   ASSIGN                                                   !3, <array>
   10    11      > FE_RESET_R                                       $19     !0, ->39
         12    > > FE_FETCH_R                                               $19, !4, ->39
   12    13    >   INIT_FCALL                                               'pow'
         14        SEND_VAL                                                 2
         15        SEND_VAR                                                 !2
         16        DO_ICALL                                         $20     
         17        ASSIGN                                                   !5, $20
   14    18        INIT_FCALL                                               'array_merge'
         19        SEND_VAR                                                 !3
         20        INIT_FCALL                                               'array_splice'
         21        SEND_REF                                                 !0
         22        SEND_VAL                                                 0
         23        SEND_VAR                                                 !5
         24        DO_ICALL                                         $22     
         25        SEND_VAR                                                 $22
         26        DO_ICALL                                         $23     
         27        ASSIGN                                                   !3, $23
   15    28        INIT_FCALL                                               'array_merge'
         29        SEND_VAR                                                 !3
         30        INIT_FCALL                                               'array_splice'
         31        SEND_REF                                                 !0
         32        MUL                                              ~25     !5, -1
         33        SEND_VAL                                                 ~25
         34        DO_ICALL                                         $26     
         35        SEND_VAR                                                 $26
         36        DO_ICALL                                         $27     
         37        ASSIGN                                                   !3, $27
   10    38      > JMP                                                      ->12
         39    >   FE_FREE                                                  $19
   17    40        ASSIGN                                                   !0, !3
    7    41        PRE_INC                                                  !2
         42    >   INIT_FCALL                                               'log'
         43        COUNT                                            ~31     !0
         44        SEND_VAL                                                 ~31
         45        SEND_VAL                                                 2
         46        DO_ICALL                                         $32     
         47        IS_SMALLER                                               !2, $32
         48      > JMPNZ                                                    ~33, ->10
   20    49    >   INIT_FCALL                                               'array_chunk'
         50        SEND_VAR                                                 !3
         51        SEND_VAL                                                 2
         52        DO_ICALL                                         $34     
         53        ASSIGN                                                   !6, $34
   22    54        IS_SMALLER                                               2, !1
         55      > JMPZ                                                     ~36, ->126
   24    56    >   COUNT                                            ~37     !6
         57        ASSIGN                                                   !7, ~37
   27    58        ASSIGN                                                   !2, 0
         59      > JMP                                                      ->72
   29    60    >   INIT_FCALL                                               'array_push'
         61        SEND_REF                                                 !6
   30    62        INIT_ARRAY                                       ~40     !2, 'from_event_index'
         63        ADD_ARRAY_ELEMENT                                ~40     1, 'from_event_rank'
         64        INIT_ARRAY                                       ~41     ~40
   31    65        PRE_INC                                          ~42     !2
         66        INIT_ARRAY                                       ~43     ~42, 'from_event_index'
         67        ADD_ARRAY_ELEMENT                                ~43     1, 'from_event_rank'
         68        ADD_ARRAY_ELEMENT                                ~41     ~43
         69        SEND_VAL                                                 ~41
         70        DO_ICALL                                                 
   27    71        PRE_INC                                                  !2
         72    >   COUNT                                            ~46     !0
         73        DIV                                              ~47     ~46, 2
         74        IS_SMALLER                                               !2, ~47
         75      > JMPNZ                                                    ~48, ->60
   35    76    >   ASSIGN                                                   !8, <array>
   36    77        ASSIGN                                                   !2, 0
         78      > JMP                                                      ->91
   38    79    >   INIT_FCALL                                               'array_push'
         80        SEND_REF                                                 !8
   39    81        INIT_ARRAY                                       ~51     !2, 'from_event_index'
         82        ADD_ARRAY_ELEMENT                                ~51     2, 'from_event_rank'
         83        INIT_ARRAY                                       ~52     ~51
   40    84        PRE_INC                                          ~53     !2
         85        INIT_ARRAY                                       ~54     ~53, 'from_event_index'
         86        ADD_ARRAY_ELEMENT                                ~54     2, 'from_event_rank'
         87        ADD_ARRAY_ELEMENT                                ~52     ~54
         88        SEND_VAL                                                 ~52
         89        DO_ICALL                                                 
   36    90        PRE_INC                                                  !2
         91    >   COUNT                                            ~57     !0
         92        DIV                                              ~58     ~57, 2
         93        IS_SMALLER                                               !2, ~58
         94      > JMPNZ                                                    ~59, ->79
   43    95    >   INIT_FCALL                                               'array_merge'
         96        SEND_VAR                                                 !6
         97        SEND_VAR                                                 !8
         98        DO_ICALL                                         $60     
         99        ASSIGN                                                   !6, $60
   45   100        ASSIGN                                                   !2, 0
        101      > JMP                                                      ->123
   47   102    >   INIT_FCALL                                               'array_push'
        103        SEND_REF                                                 !6
   48   104        COUNT                                            ~63     !0
        105        DIV                                              ~64     ~63, 2
        106        ADD                                              ~65     !2, ~64
        107        INIT_ARRAY                                       ~66     ~65, 'from_event_index'
        108        ADD_ARRAY_ELEMENT                                ~66     2, 'from_event_rank'
        109        INIT_ARRAY                                       ~67     ~66
   49   110        COUNT                                            ~68     !0
        111        DIV                                              ~69     ~68, 2
        112        ADD                                              ~70     !2, ~69
        113        COUNT                                            ~71     !0
        114        DIV                                              ~72     ~71, 2
        115        DIV                                              ~73     ~72, 2
        116        ADD                                              ~74     ~70, ~73
        117        INIT_ARRAY                                       ~75     ~74, 'from_event_index'
        118        ADD_ARRAY_ELEMENT                                ~75     1, 'from_event_rank'
        119        ADD_ARRAY_ELEMENT                                ~67     ~75
        120        SEND_VAL                                                 ~67
        121        DO_ICALL                                                 
   45   122        PRE_INC                                                  !2
        123    >   COUNT                                            ~78     !8
        124        IS_SMALLER                                               !2, ~78
        125      > JMPNZ                                                    ~79, ->102
   54   126    >   IS_SMALLER                                               3, !1
        127      > JMPZ                                                     ~80, ->204
   57   128    >   ASSIGN                                                   !2, 0
        129      > JMP                                                      ->201
   59   130    >   INIT_FCALL                                               'pow'
        131        SEND_VAL                                                 2
        132        SUB                                              ~82     !1, 3
        133        SUB                                              ~83     ~82, !2
        134        SEND_VAL                                                 ~83
        135        DO_ICALL                                         $84     
        136        ASSIGN                                                   !9, $84
   60   137        COUNT                                            ~86     !6
        138        ASSIGN                                                   !10, ~86
   62   139        ASSIGN                                                   !11, 0
        140      > JMP                                                      ->155
   64   141    >   INIT_FCALL                                               'array_push'
        142        SEND_REF                                                 !6
   65   143        ADD                                              ~89     !11, !7
        144        INIT_ARRAY                                       ~90     ~89, 'from_event_index'
        145        ADD_ARRAY_ELEMENT                                ~90     1, 'from_event_rank'
        146        INIT_ARRAY                                       ~91     ~90
   66   147        PRE_INC                                          ~92     !11
        148        ADD                                              ~93     ~92, !7
        149        INIT_ARRAY                                       ~94     ~93, 'from_event_index'
        150        ADD_ARRAY_ELEMENT                                ~94     1, 'from_event_rank'
        151        ADD_ARRAY_ELEMENT                                ~91     ~94
        152        SEND_VAL                                                 ~91
        153        DO_ICALL                                                 
   62   154        PRE_INC                                                  !11
        155    >   IS_SMALLER                                               !11, !9
        156      > JMPNZ                                                    ~97, ->141
   70   157    >   ASSIGN                                                   !11, 0
        158      > JMP                                                      ->177
   72   159    >   INIT_FCALL                                               'array_push'
        160        SEND_REF                                                 !6
   73   161        ADD                                              ~99     !11, !7
        162        MUL                                              ~100    !9, 2
        163        ADD                                              ~101    ~99, ~100
        164        INIT_ARRAY                                       ~102    ~101, 'from_event_index'
        165        ADD_ARRAY_ELEMENT                                ~102    1, 'from_event_rank'
        166        INIT_ARRAY                                       ~103    ~102
   74   167        PRE_INC                                          ~104    !11
        168        ADD                                              ~105    ~104, !7
        169        MUL                                              ~106    !9, 2
        170        ADD                                              ~107    ~105, ~106
        171        INIT_ARRAY                                       ~108    ~107, 'from_event_index'
        172        ADD_ARRAY_ELEMENT                                ~108    1, 'from_event_rank'
        173        ADD_ARRAY_ELEMENT                                ~103    ~108
        174        SEND_VAL                                                 ~103
        175        DO_ICALL                                                 
   70   176        PRE_INC                                                  !11
        177    >   IS_SMALLER                                               !11, !9
        178      > JMPNZ                                                    ~111, ->159
   78   179    >   ASSIGN                                                   !11, 0
        180      > JMP                                                      ->196
   80   181    >   INIT_FCALL                                               'array_push'
        182        SEND_REF                                                 !6
   81   183        ADD                                              ~113    !11, !10
        184        INIT_ARRAY                                       ~114    ~113, 'from_event_index'
        185        ADD_ARRAY_ELEMENT                                ~114    2, 'from_event_rank'
        186        INIT_ARRAY                                       ~115    ~114
   82   187        ADD                                              ~116    !11, !10
        188        DIV                                              ~117    !9, 2
        189        ADD                                              ~118    ~116, ~117
        190        INIT_ARRAY                                       ~119    ~118, 'from_event_index'
        191        ADD_ARRAY_ELEMENT                                ~119    1, 'from_event_rank'
        192        ADD_ARRAY_ELEMENT                                ~115    ~119
        193        SEND_VAL                                                 ~115
        194        DO_ICALL                                                 
   78   195        PRE_INC                                                  !11
        196    >   DIV                                              ~122    !9, 2
        197        IS_SMALLER                                               !11, ~122
        198      > JMPNZ                                                    ~123, ->181
   86   199    >   ASSIGN                                                   !7, !10
   57   200        PRE_INC                                                  !2
        201    >   SUB                                              ~126    !1, 3
        202        IS_SMALLER                                               !2, ~126
        203      > JMPNZ                                                    ~127, ->130
   91   204    >   IS_SMALLER                                               1, !1
        205      > JMPZ                                                     ~128, ->220
   94   206    >   INIT_FCALL                                               'array_push'
        207        SEND_REF                                                 !6
   95   208        COUNT                                            ~129    !6
        209        SUB                                              ~130    ~129, 3
        210        INIT_ARRAY                                       ~131    ~130, 'from_event_index'
        211        ADD_ARRAY_ELEMENT                                ~131    1, 'from_event_rank'
        212        INIT_ARRAY                                       ~132    ~131
   96   213        COUNT                                            ~133    !6
        214        SUB                                              ~134    ~133, 1
        215        INIT_ARRAY                                       ~135    ~134, 'from_event_index'
        216        ADD_ARRAY_ELEMENT                                ~135    1, 'from_event_rank'
        217        ADD_ARRAY_ELEMENT                                ~132    ~135
        218        SEND_VAL                                                 ~132
        219        DO_ICALL                                                 
  100   220    >   INIT_FCALL                                               'var_dump'
        221        SEND_VAR                                                 !6
        222        DO_ICALL                                                 
        223      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
159.4 ms | 1416 KiB | 27 Q