
CONTROL FLOW GRAPH SSA
@begin: scope:[]  from
  (byte) x#0 ← (byte/signed byte/word/signed word/dword/signed dword) 12
  to:@1
main: scope:[main]  from @1
  (byte) x#8 ← phi( @1/(byte) x#10 )
  to:main::@1
main::@1: scope:[main]  from main main::@2
  (byte) x#5 ← phi( main/(byte) x#8 main::@2/(byte) x#9 )
  (byte) x#1 ← ++ (byte) x#5
  (bool~) main::$0 ← (byte) x#1 < (byte/signed byte/word/signed word/dword/signed dword) 50
  if((bool~) main::$0) goto main::@2
  to:main::@3
main::@2: scope:[main]  from main::@1
  (byte) x#9 ← phi( main::@1/(byte) x#1 )
  to:main::@1
main::@3: scope:[main]  from main::@1
  (byte) x#2 ← (byte/signed byte/word/signed word/dword/signed dword) 0
  to:main::@return
main::@return: scope:[main]  from main::@3
  (byte) x#6 ← phi( main::@3/(byte) x#2 )
  (byte) x#3 ← (byte) x#6
  return 
  to:@return
@1: scope:[]  from @begin
  (byte) x#10 ← phi( @begin/(byte) x#0 )
  call main 
  to:@2
@2: scope:[]  from @1
  (byte) x#7 ← phi( @1/(byte) x#3 )
  (byte) x#4 ← (byte) x#7
  to:@end
@end: scope:[]  from @2

SYMBOL TABLE SSA
(label) @1
(label) @2
(label) @begin
(label) @end
(void()) main()
(bool~) main::$0
(label) main::@1
(label) main::@2
(label) main::@3
(label) main::@return
(byte) x
(byte) x#0
(byte) x#1
(byte) x#10
(byte) x#2
(byte) x#3
(byte) x#4
(byte) x#5
(byte) x#6
(byte) x#7
(byte) x#8
(byte) x#9

Alias (byte) x#1 = (byte) x#9 
Alias (byte) x#2 = (byte) x#6 (byte) x#3 
Alias (byte) x#0 = (byte) x#10 
Alias (byte) x#4 = (byte) x#7 
Successful SSA optimization Pass2AliasElimination
Redundant Phi (byte) x#8 (byte) x#0
Redundant Phi (byte) x#4 (byte) x#2
Successful SSA optimization Pass2RedundantPhiElimination
Simple Condition (bool~) main::$0 [5] if((byte) x#1<(byte/signed byte/word/signed word/dword/signed dword) 50) goto main::@2
Successful SSA optimization Pass2ConditionalJumpSimplification
Culled Empty Block (label) main::@2
Culled Empty Block (label) @2
Successful SSA optimization Pass2CullEmptyBlocks
Added new block during phi lifting main::@7(between main::@1 and main::@1)
Adding NOP phi() at start of @1
Adding NOP phi() at start of @end
CALL GRAPH
Calls in [] to main:2 

Created 1 initial phi equivalence classes
Coalesced [4] x#11 ← x#0
Coalesced [10] x#12 ← x#1
Coalesced down to 1 phi equivalence classes
Culled Empty Block (label) main::@7
Adding NOP phi() at start of @1
Adding NOP phi() at start of @end
Adding NOP phi() at start of main

FINAL CONTROL FLOW GRAPH
@begin: scope:[]  from
  [0] (byte) x#0 ← (byte/signed byte/word/signed word/dword/signed dword) 12
  to:@1
@1: scope:[]  from @begin
  [1] phi()
  [2] call main 
  to:@end
@end: scope:[]  from @1
  [3] phi()
main: scope:[main]  from @1
  [4] phi()
  to:main::@1
main::@1: scope:[main]  from main main::@1
  [5] (byte) x#5 ← phi( main/(byte) x#0 main::@1/(byte) x#1 )
  [6] (byte) x#1 ← ++ (byte) x#5
  [7] if((byte) x#1<(byte/signed byte/word/signed word/dword/signed dword) 50) goto main::@1
  to:main::@3
main::@3: scope:[main]  from main::@1
  [8] (byte) x#2 ← (byte/signed byte/word/signed word/dword/signed dword) 0
  to:main::@return
main::@return: scope:[main]  from main::@3
  [9] return 
  to:@return


VARIABLE REGISTER WEIGHTS
(void()) main()
(byte) x
(byte) x#0 1.3333333333333333
(byte) x#1 16.5
(byte) x#2 20.0
(byte) x#5 24.0

Initial phi equivalence classes
[ x#5 x#0 x#1 ]
Added variable x#2 to zero page equivalence class [ x#2 ]
Complete equivalence classes
[ x#5 x#0 x#1 ]
[ x#2 ]
Allocated zp ZP_BYTE:2 [ x#5 x#0 x#1 ]
Allocated zp ZP_BYTE:3 [ x#2 ]

INITIAL ASM
//SEG0 File Comments
// Illustrates a problem where volatiles with initializers are initialized outside the main()-routine
//SEG1 Basic Upstart
.pc = $801 "Basic"
:BasicUpstart(bbegin)
.pc = $80d "Program"
//SEG2 Global Constants & labels
  .label x = 2
  .label x_2 = 3
//SEG3 @begin
bbegin:
//SEG4 [0] (byte) x#0 ← (byte/signed byte/word/signed word/dword/signed dword) 12 -- vbuz1=vbuc1 
  lda #$c
  sta x
//SEG5 [1] phi from @begin to @1 [phi:@begin->@1]
b1_from_bbegin:
  jmp b1
//SEG6 @1
b1:
//SEG7 [2] call main 
//SEG8 [4] phi from @1 to main [phi:@1->main]
main_from_b1:
  jsr main
//SEG9 [3] phi from @1 to @end [phi:@1->@end]
bend_from_b1:
  jmp bend
//SEG10 @end
bend:
//SEG11 main
main: {
  //SEG12 [5] phi from main main::@1 to main::@1 [phi:main/main::@1->main::@1]
  b1_from_main:
  b1_from_b1:
  //SEG13 [5] phi (byte) x#5 = (byte) x#0 [phi:main/main::@1->main::@1#0] -- register_copy 
    jmp b1
  //SEG14 main::@1
  b1:
  //SEG15 [6] (byte) x#1 ← ++ (byte) x#5 -- vbuz1=_inc_vbuz1 
    inc x
  //SEG16 [7] if((byte) x#1<(byte/signed byte/word/signed word/dword/signed dword) 50) goto main::@1 -- vbuz1_lt_vbuc1_then_la1 
    lda x
    cmp #$32
    bcc b1_from_b1
    jmp b3
  //SEG17 main::@3
  b3:
  //SEG18 [8] (byte) x#2 ← (byte/signed byte/word/signed word/dword/signed dword) 0 -- vbuz1=vbuc1 
    lda #0
    sta x_2
    jmp breturn
  //SEG19 main::@return
  breturn:
  //SEG20 [9] return 
    rts
}

REGISTER UPLIFT POTENTIAL REGISTERS
Statement [0] (byte) x#0 ← (byte/signed byte/word/signed word/dword/signed dword) 12 [ x#0 ] ( ) always clobbers reg byte a 
Statement [7] if((byte) x#1<(byte/signed byte/word/signed word/dword/signed dword) 50) goto main::@1 [ x#1 ] ( main:2 [ x#1 ] ) always clobbers reg byte a 
Statement [8] (byte) x#2 ← (byte/signed byte/word/signed word/dword/signed dword) 0 [ ] ( main:2 [ ] ) always clobbers reg byte a 
Potential registers zp ZP_BYTE:2 [ x#5 x#0 x#1 ] : zp ZP_BYTE:2 , 
Potential registers zp ZP_BYTE:3 [ x#2 ] : zp ZP_BYTE:3 , 

REGISTER UPLIFT SCOPES
Uplift Scope [] 41.83: zp ZP_BYTE:2 [ x#5 x#0 x#1 ] 20: zp ZP_BYTE:3 [ x#2 ] 
Uplift Scope [main] 

Uplifting [] best 216 combination zp ZP_BYTE:2 [ x#5 x#0 x#1 ] zp ZP_BYTE:3 [ x#2 ] 
Uplifting [main] best 216 combination 
Attempting to uplift remaining variables inzp ZP_BYTE:2 [ x#5 x#0 x#1 ]
Uplifting [] best 216 combination zp ZP_BYTE:2 [ x#5 x#0 x#1 ] 
Attempting to uplift remaining variables inzp ZP_BYTE:3 [ x#2 ]
Uplifting [] best 216 combination zp ZP_BYTE:3 [ x#2 ] 
Coalescing zero page register [ zp ZP_BYTE:2 [ x#5 x#0 x#1 ] ] with [ zp ZP_BYTE:3 [ x#2 ] ]

ASSEMBLER BEFORE OPTIMIZATION
//SEG0 File Comments
// Illustrates a problem where volatiles with initializers are initialized outside the main()-routine
//SEG1 Basic Upstart
.pc = $801 "Basic"
:BasicUpstart(bbegin)
.pc = $80d "Program"
//SEG2 Global Constants & labels
  .label x = 2
//SEG3 @begin
bbegin:
//SEG4 [0] (byte) x#0 ← (byte/signed byte/word/signed word/dword/signed dword) 12 -- vbuz1=vbuc1 
  lda #$c
  sta x
//SEG5 [1] phi from @begin to @1 [phi:@begin->@1]
b1_from_bbegin:
  jmp b1
//SEG6 @1
b1:
//SEG7 [2] call main 
//SEG8 [4] phi from @1 to main [phi:@1->main]
main_from_b1:
  jsr main
//SEG9 [3] phi from @1 to @end [phi:@1->@end]
bend_from_b1:
  jmp bend
//SEG10 @end
bend:
//SEG11 main
main: {
  //SEG12 [5] phi from main main::@1 to main::@1 [phi:main/main::@1->main::@1]
  b1_from_main:
  b1_from_b1:
  //SEG13 [5] phi (byte) x#5 = (byte) x#0 [phi:main/main::@1->main::@1#0] -- register_copy 
    jmp b1
  //SEG14 main::@1
  b1:
  //SEG15 [6] (byte) x#1 ← ++ (byte) x#5 -- vbuz1=_inc_vbuz1 
    inc x
  //SEG16 [7] if((byte) x#1<(byte/signed byte/word/signed word/dword/signed dword) 50) goto main::@1 -- vbuz1_lt_vbuc1_then_la1 
    lda x
    cmp #$32
    bcc b1_from_b1
    jmp b3
  //SEG17 main::@3
  b3:
  //SEG18 [8] (byte) x#2 ← (byte/signed byte/word/signed word/dword/signed dword) 0 -- vbuz1=vbuc1 
    lda #0
    sta x
    jmp breturn
  //SEG19 main::@return
  breturn:
  //SEG20 [9] return 
    rts
}

ASSEMBLER OPTIMIZATIONS
Removing instruction jmp b1
Removing instruction jmp bend
Removing instruction jmp b1
Removing instruction jmp b3
Removing instruction jmp breturn
Succesful ASM optimization Pass5NextJumpElimination
Replacing label b1_from_b1 with b1
Removing instruction b1_from_bbegin:
Removing instruction main_from_b1:
Removing instruction bend_from_b1:
Removing instruction b1_from_main:
Removing instruction b1_from_b1:
Succesful ASM optimization Pass5RedundantLabelElimination
Removing instruction b1:
Removing instruction bend:
Removing instruction b3:
Removing instruction breturn:
Succesful ASM optimization Pass5UnusedLabelElimination

FINAL SYMBOL TABLE
(label) @1
(label) @begin
(label) @end
(void()) main()
(label) main::@1
(label) main::@3
(label) main::@return
(byte) x
(byte) x#0 x zp ZP_BYTE:2 1.3333333333333333
(byte) x#1 x zp ZP_BYTE:2 16.5
(byte) x#2 x zp ZP_BYTE:2 20.0
(byte) x#5 x zp ZP_BYTE:2 24.0

zp ZP_BYTE:2 [ x#5 x#0 x#1 x#2 ]


FINAL ASSEMBLER
Score: 147

//SEG0 File Comments
// Illustrates a problem where volatiles with initializers are initialized outside the main()-routine
//SEG1 Basic Upstart
.pc = $801 "Basic"
:BasicUpstart(bbegin)
.pc = $80d "Program"
//SEG2 Global Constants & labels
  .label x = 2
//SEG3 @begin
bbegin:
//SEG4 [0] (byte) x#0 ← (byte/signed byte/word/signed word/dword/signed dword) 12 -- vbuz1=vbuc1 
  lda #$c
  sta x
//SEG5 [1] phi from @begin to @1 [phi:@begin->@1]
//SEG6 @1
//SEG7 [2] call main 
//SEG8 [4] phi from @1 to main [phi:@1->main]
  jsr main
//SEG9 [3] phi from @1 to @end [phi:@1->@end]
//SEG10 @end
//SEG11 main
main: {
  //SEG12 [5] phi from main main::@1 to main::@1 [phi:main/main::@1->main::@1]
  //SEG13 [5] phi (byte) x#5 = (byte) x#0 [phi:main/main::@1->main::@1#0] -- register_copy 
  //SEG14 main::@1
  b1:
  //SEG15 [6] (byte) x#1 ← ++ (byte) x#5 -- vbuz1=_inc_vbuz1 
    inc x
  //SEG16 [7] if((byte) x#1<(byte/signed byte/word/signed word/dword/signed dword) 50) goto main::@1 -- vbuz1_lt_vbuc1_then_la1 
    lda x
    cmp #$32
    bcc b1
  //SEG17 main::@3
  //SEG18 [8] (byte) x#2 ← (byte/signed byte/word/signed word/dword/signed dword) 0 -- vbuz1=vbuc1 
    lda #0
    sta x
  //SEG19 main::@return
  //SEG20 [9] return 
    rts
}

