
CONTROL FLOW GRAPH SSA
@begin: scope:[]  from
  to:@1
main: scope:[main]  from @1
  (byte*) main::screen#0 ← ((byte*)) (word/signed word/dword/signed dword) 1024
  (byte*) main::colors#0 ← ((byte*)) (word/dword/signed dword) 55296
  (byte) main::color#0 ← (byte/signed byte/word/signed word/dword/signed dword) 1
  (byte) main::row#0 ← (byte/signed byte/word/signed word/dword/signed dword) 0
  to:main::@1
main::@1: scope:[main]  from main main::@3
  (byte) main::row#4 ← phi( main/(byte) main::row#0 main::@3/(byte) main::row#1 )
  (byte*) main::colors#4 ← phi( main/(byte*) main::colors#0 main::@3/(byte*) main::colors#1 )
  (byte) main::color#5 ← phi( main/(byte) main::color#0 main::@3/(byte) main::color#2 )
  (byte*) main::screen#4 ← phi( main/(byte*) main::screen#0 main::@3/(byte*) main::screen#1 )
  (byte) main::column#0 ← (byte/signed byte/word/signed word/dword/signed dword) 0
  to:main::@2
main::@2: scope:[main]  from main::@1 main::@2
  (byte) main::row#3 ← phi( main::@1/(byte) main::row#4 main::@2/(byte) main::row#3 )
  (byte*) main::colors#2 ← phi( main::@1/(byte*) main::colors#4 main::@2/(byte*) main::colors#2 )
  (byte) main::color#3 ← phi( main::@1/(byte) main::color#5 main::@2/(byte) main::color#1 )
  (byte) main::column#2 ← phi( main::@1/(byte) main::column#0 main::@2/(byte) main::column#1 )
  (byte*) main::screen#2 ← phi( main::@1/(byte*) main::screen#4 main::@2/(byte*) main::screen#2 )
  *((byte*) main::screen#2 + (byte) main::column#2) ← (byte/word/signed word/dword/signed dword) 160
  *((byte*) main::colors#2 + (byte) main::column#2) ← (byte) main::color#3
  (byte/word/dword~) main::$0 ← (byte) main::color#3 ^ (byte/signed byte/word/signed word/dword/signed dword) 1
  (byte) main::color#1 ← (byte/word/dword~) main::$0
  (byte) main::column#1 ← (byte) main::column#2 + rangenext(0,7)
  (bool~) main::$1 ← (byte) main::column#1 != rangelast(0,7)
  if((bool~) main::$1) goto main::@2
  to:main::@3
main::@3: scope:[main]  from main::@2
  (byte) main::row#2 ← phi( main::@2/(byte) main::row#3 )
  (byte*) main::colors#3 ← phi( main::@2/(byte*) main::colors#2 )
  (byte*) main::screen#3 ← phi( main::@2/(byte*) main::screen#2 )
  (byte) main::color#4 ← phi( main::@2/(byte) main::color#1 )
  (byte/word/dword~) main::$2 ← (byte) main::color#4 ^ (byte/signed byte/word/signed word/dword/signed dword) 1
  (byte) main::color#2 ← (byte/word/dword~) main::$2
  (byte*~) main::$3 ← (byte*) main::screen#3 + (byte/signed byte/word/signed word/dword/signed dword) 40
  (byte*) main::screen#1 ← (byte*~) main::$3
  (byte*~) main::$4 ← (byte*) main::colors#3 + (byte/signed byte/word/signed word/dword/signed dword) 40
  (byte*) main::colors#1 ← (byte*~) main::$4
  (byte) main::row#1 ← (byte) main::row#2 + rangenext(0,7)
  (bool~) main::$5 ← (byte) main::row#1 != rangelast(0,7)
  if((bool~) main::$5) goto main::@1
  to:main::@return
main::@return: scope:[main]  from main::@3
  return 
  to:@return
@1: scope:[]  from @begin
  call main 
  to:@2
@2: scope:[]  from @1
  to:@end
@end: scope:[]  from @2

SYMBOL TABLE SSA
(label) @1
(label) @2
(label) @begin
(label) @end
(void()) main()
(byte/word/dword~) main::$0
(bool~) main::$1
(byte/word/dword~) main::$2
(byte*~) main::$3
(byte*~) main::$4
(bool~) main::$5
(label) main::@1
(label) main::@2
(label) main::@3
(label) main::@return
(byte) main::color
(byte) main::color#0
(byte) main::color#1
(byte) main::color#2
(byte) main::color#3
(byte) main::color#4
(byte) main::color#5
(byte*) main::colors
(byte*) main::colors#0
(byte*) main::colors#1
(byte*) main::colors#2
(byte*) main::colors#3
(byte*) main::colors#4
(byte) main::column
(byte) main::column#0
(byte) main::column#1
(byte) main::column#2
(byte) main::row
(byte) main::row#0
(byte) main::row#1
(byte) main::row#2
(byte) main::row#3
(byte) main::row#4
(byte*) main::screen
(byte*) main::screen#0
(byte*) main::screen#1
(byte*) main::screen#2
(byte*) main::screen#3
(byte*) main::screen#4

Culled Empty Block (label) @2
Successful SSA optimization Pass2CullEmptyBlocks
Alias (byte) main::color#1 = (byte/word/dword~) main::$0 (byte) main::color#4 
Alias (byte*) main::screen#2 = (byte*) main::screen#3 
Alias (byte*) main::colors#2 = (byte*) main::colors#3 
Alias (byte) main::row#2 = (byte) main::row#3 
Alias (byte) main::color#2 = (byte/word/dword~) main::$2 
Alias (byte*) main::screen#1 = (byte*~) main::$3 
Alias (byte*) main::colors#1 = (byte*~) main::$4 
Successful SSA optimization Pass2AliasElimination
Self Phi Eliminated (byte*) main::screen#2
Self Phi Eliminated (byte*) main::colors#2
Self Phi Eliminated (byte) main::row#2
Successful SSA optimization Pass2SelfPhiElimination
Redundant Phi (byte*) main::screen#2 (byte*) main::screen#4
Redundant Phi (byte*) main::colors#2 (byte*) main::colors#4
Redundant Phi (byte) main::row#2 (byte) main::row#4
Successful SSA optimization Pass2RedundantPhiElimination
Simple Condition (bool~) main::$1 [13] if((byte) main::column#1!=rangelast(0,7)) goto main::@2
Simple Condition (bool~) main::$5 [23] if((byte) main::row#1!=rangelast(0,7)) goto main::@1
Successful SSA optimization Pass2ConditionalJumpSimplification
Constant (const byte*) main::screen#0 = ((byte*))1024
Constant (const byte*) main::colors#0 = ((byte*))55296
Constant (const byte) main::color#0 = 1
Constant (const byte) main::row#0 = 0
Constant (const byte) main::column#0 = 0
Successful SSA optimization Pass2ConstantIdentification
Resolved ranged next value main::column#1 ← ++ main::column#2 to ++
Resolved ranged comparison value if(main::column#1!=rangelast(0,7)) goto main::@2 to (byte/signed byte/word/signed word/dword/signed dword) 8
Resolved ranged next value main::row#1 ← ++ main::row#4 to ++
Resolved ranged comparison value if(main::row#1!=rangelast(0,7)) goto main::@1 to (byte/signed byte/word/signed word/dword/signed dword) 8
Inlining constant with var siblings (const byte*) main::screen#0
Inlining constant with var siblings (const byte*) main::colors#0
Inlining constant with var siblings (const byte) main::color#0
Inlining constant with var siblings (const byte) main::row#0
Inlining constant with var siblings (const byte) main::column#0
Constant inlined main::screen#0 = ((byte*))(word/signed word/dword/signed dword) 1024
Constant inlined main::colors#0 = ((byte*))(word/dword/signed dword) 55296
Constant inlined main::color#0 = (byte/signed byte/word/signed word/dword/signed dword) 1
Constant inlined main::row#0 = (byte/signed byte/word/signed word/dword/signed dword) 0
Constant inlined main::column#0 = (byte/signed byte/word/signed word/dword/signed dword) 0
Successful SSA optimization Pass2ConstantInlining
Added new block during phi lifting main::@5(between main::@3 and main::@1)
Added new block during phi lifting main::@6(between main::@2 and main::@2)
Adding NOP phi() at start of @begin
Adding NOP phi() at start of @1
Adding NOP phi() at start of @end
Adding NOP phi() at start of main
CALL GRAPH
Calls in [] to main:2 

Created 6 initial phi equivalence classes
Coalesced [6] main::color#7 ← main::color#5
Coalesced [19] main::screen#5 ← main::screen#1
Coalesced [20] main::color#6 ← main::color#2
Coalesced [21] main::colors#5 ← main::colors#1
Coalesced [22] main::row#5 ← main::row#1
Coalesced [23] main::column#3 ← main::column#1
Coalesced [24] main::color#8 ← main::color#1
Coalesced down to 5 phi equivalence classes
Culled Empty Block (label) main::@5
Culled Empty Block (label) main::@6
Adding NOP phi() at start of @begin
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] phi()
  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::@3
  [5] (byte) main::row#4 ← phi( main/(byte/signed byte/word/signed word/dword/signed dword) 0 main::@3/(byte) main::row#1 )
  [5] (byte*) main::colors#4 ← phi( main/((byte*))(word/dword/signed dword) 55296 main::@3/(byte*) main::colors#1 )
  [5] (byte) main::color#5 ← phi( main/(byte/signed byte/word/signed word/dword/signed dword) 1 main::@3/(byte) main::color#2 )
  [5] (byte*) main::screen#4 ← phi( main/((byte*))(word/signed word/dword/signed dword) 1024 main::@3/(byte*) main::screen#1 )
  to:main::@2
main::@2: scope:[main]  from main::@1 main::@2
  [6] (byte) main::color#3 ← phi( main::@1/(byte) main::color#5 main::@2/(byte) main::color#1 )
  [6] (byte) main::column#2 ← phi( main::@1/(byte/signed byte/word/signed word/dword/signed dword) 0 main::@2/(byte) main::column#1 )
  [7] *((byte*) main::screen#4 + (byte) main::column#2) ← (byte/word/signed word/dword/signed dword) 160
  [8] *((byte*) main::colors#4 + (byte) main::column#2) ← (byte) main::color#3
  [9] (byte) main::color#1 ← (byte) main::color#3 ^ (byte/signed byte/word/signed word/dword/signed dword) 1
  [10] (byte) main::column#1 ← ++ (byte) main::column#2
  [11] if((byte) main::column#1!=(byte/signed byte/word/signed word/dword/signed dword) 8) goto main::@2
  to:main::@3
main::@3: scope:[main]  from main::@2
  [12] (byte) main::color#2 ← (byte) main::color#1 ^ (byte/signed byte/word/signed word/dword/signed dword) 1
  [13] (byte*) main::screen#1 ← (byte*) main::screen#4 + (byte/signed byte/word/signed word/dword/signed dword) 40
  [14] (byte*) main::colors#1 ← (byte*) main::colors#4 + (byte/signed byte/word/signed word/dword/signed dword) 40
  [15] (byte) main::row#1 ← ++ (byte) main::row#4
  [16] if((byte) main::row#1!=(byte/signed byte/word/signed word/dword/signed dword) 8) goto main::@1
  to:main::@return
main::@return: scope:[main]  from main::@3
  [17] return 
  to:@return


VARIABLE REGISTER WEIGHTS
(void()) main()
(byte) main::color
(byte) main::color#1 71.0
(byte) main::color#2 4.4
(byte) main::color#3 104.66666666666666
(byte) main::color#5 22.0
(byte*) main::colors
(byte*) main::colors#1 7.333333333333333
(byte*) main::colors#4 13.666666666666664
(byte) main::column
(byte) main::column#1 151.5
(byte) main::column#2 101.0
(byte) main::row
(byte) main::row#1 16.5
(byte) main::row#4 2.2
(byte*) main::screen
(byte*) main::screen#1 5.5
(byte*) main::screen#4 15.375

Initial phi equivalence classes
[ main::screen#4 main::screen#1 ]
[ main::colors#4 main::colors#1 ]
[ main::row#4 main::row#1 ]
[ main::column#2 main::column#1 ]
[ main::color#3 main::color#5 main::color#2 main::color#1 ]
Complete equivalence classes
[ main::screen#4 main::screen#1 ]
[ main::colors#4 main::colors#1 ]
[ main::row#4 main::row#1 ]
[ main::column#2 main::column#1 ]
[ main::color#3 main::color#5 main::color#2 main::color#1 ]
Allocated zp ZP_WORD:2 [ main::screen#4 main::screen#1 ]
Allocated zp ZP_WORD:4 [ main::colors#4 main::colors#1 ]
Allocated zp ZP_BYTE:6 [ main::row#4 main::row#1 ]
Allocated zp ZP_BYTE:7 [ main::column#2 main::column#1 ]
Allocated zp ZP_BYTE:8 [ main::color#3 main::color#5 main::color#2 main::color#1 ]

INITIAL ASM
//SEG0 File Comments
// Draws a chess board in the upper left corner of the screen
//SEG1 Basic Upstart
.pc = $801 "Basic"
:BasicUpstart(bbegin)
.pc = $80d "Program"
//SEG2 Global Constants & labels
//SEG3 @begin
bbegin:
//SEG4 [1] phi from @begin to @1 [phi:@begin->@1]
b1_from_bbegin:
  jmp b1
//SEG5 @1
b1:
//SEG6 [2] call main 
//SEG7 [4] phi from @1 to main [phi:@1->main]
main_from_b1:
  jsr main
//SEG8 [3] phi from @1 to @end [phi:@1->@end]
bend_from_b1:
  jmp bend
//SEG9 @end
bend:
//SEG10 main
main: {
    .label color = 8
    .label column = 7
    .label screen = 2
    .label colors = 4
    .label row = 6
  //SEG11 [5] phi from main to main::@1 [phi:main->main::@1]
  b1_from_main:
  //SEG12 [5] phi (byte) main::row#4 = (byte/signed byte/word/signed word/dword/signed dword) 0 [phi:main->main::@1#0] -- vbuz1=vbuc1 
    lda #0
    sta row
  //SEG13 [5] phi (byte*) main::colors#4 = ((byte*))(word/dword/signed dword) 55296 [phi:main->main::@1#1] -- pbuz1=pbuc1 
    lda #<$d800
    sta colors
    lda #>$d800
    sta colors+1
  //SEG14 [5] phi (byte) main::color#5 = (byte/signed byte/word/signed word/dword/signed dword) 1 [phi:main->main::@1#2] -- vbuz1=vbuc1 
    lda #1
    sta color
  //SEG15 [5] phi (byte*) main::screen#4 = ((byte*))(word/signed word/dword/signed dword) 1024 [phi:main->main::@1#3] -- pbuz1=pbuc1 
    lda #<$400
    sta screen
    lda #>$400
    sta screen+1
    jmp b1
  //SEG16 [5] phi from main::@3 to main::@1 [phi:main::@3->main::@1]
  b1_from_b3:
  //SEG17 [5] phi (byte) main::row#4 = (byte) main::row#1 [phi:main::@3->main::@1#0] -- register_copy 
  //SEG18 [5] phi (byte*) main::colors#4 = (byte*) main::colors#1 [phi:main::@3->main::@1#1] -- register_copy 
  //SEG19 [5] phi (byte) main::color#5 = (byte) main::color#2 [phi:main::@3->main::@1#2] -- register_copy 
  //SEG20 [5] phi (byte*) main::screen#4 = (byte*) main::screen#1 [phi:main::@3->main::@1#3] -- register_copy 
    jmp b1
  //SEG21 main::@1
  b1:
  //SEG22 [6] phi from main::@1 to main::@2 [phi:main::@1->main::@2]
  b2_from_b1:
  //SEG23 [6] phi (byte) main::color#3 = (byte) main::color#5 [phi:main::@1->main::@2#0] -- register_copy 
  //SEG24 [6] phi (byte) main::column#2 = (byte/signed byte/word/signed word/dword/signed dword) 0 [phi:main::@1->main::@2#1] -- vbuz1=vbuc1 
    lda #0
    sta column
    jmp b2
  //SEG25 [6] phi from main::@2 to main::@2 [phi:main::@2->main::@2]
  b2_from_b2:
  //SEG26 [6] phi (byte) main::color#3 = (byte) main::color#1 [phi:main::@2->main::@2#0] -- register_copy 
  //SEG27 [6] phi (byte) main::column#2 = (byte) main::column#1 [phi:main::@2->main::@2#1] -- register_copy 
    jmp b2
  //SEG28 main::@2
  b2:
  //SEG29 [7] *((byte*) main::screen#4 + (byte) main::column#2) ← (byte/word/signed word/dword/signed dword) 160 -- pbuz1_derefidx_vbuz2=vbuc1 
    lda #$a0
    ldy column
    sta (screen),y
  //SEG30 [8] *((byte*) main::colors#4 + (byte) main::column#2) ← (byte) main::color#3 -- pbuz1_derefidx_vbuz2=vbuz3 
    lda color
    ldy column
    sta (colors),y
  //SEG31 [9] (byte) main::color#1 ← (byte) main::color#3 ^ (byte/signed byte/word/signed word/dword/signed dword) 1 -- vbuz1=vbuz1_bxor_vbuc1 
    lda color
    eor #1
    sta color
  //SEG32 [10] (byte) main::column#1 ← ++ (byte) main::column#2 -- vbuz1=_inc_vbuz1 
    inc column
  //SEG33 [11] if((byte) main::column#1!=(byte/signed byte/word/signed word/dword/signed dword) 8) goto main::@2 -- vbuz1_neq_vbuc1_then_la1 
    lda column
    cmp #8
    bne b2_from_b2
    jmp b3
  //SEG34 main::@3
  b3:
  //SEG35 [12] (byte) main::color#2 ← (byte) main::color#1 ^ (byte/signed byte/word/signed word/dword/signed dword) 1 -- vbuz1=vbuz1_bxor_vbuc1 
    lda color
    eor #1
    sta color
  //SEG36 [13] (byte*) main::screen#1 ← (byte*) main::screen#4 + (byte/signed byte/word/signed word/dword/signed dword) 40 -- pbuz1=pbuz1_plus_vbuc1 
    lda screen
    clc
    adc #$28
    sta screen
    bcc !+
    inc screen+1
  !:
  //SEG37 [14] (byte*) main::colors#1 ← (byte*) main::colors#4 + (byte/signed byte/word/signed word/dword/signed dword) 40 -- pbuz1=pbuz1_plus_vbuc1 
    lda colors
    clc
    adc #$28
    sta colors
    bcc !+
    inc colors+1
  !:
  //SEG38 [15] (byte) main::row#1 ← ++ (byte) main::row#4 -- vbuz1=_inc_vbuz1 
    inc row
  //SEG39 [16] if((byte) main::row#1!=(byte/signed byte/word/signed word/dword/signed dword) 8) goto main::@1 -- vbuz1_neq_vbuc1_then_la1 
    lda row
    cmp #8
    bne b1_from_b3
    jmp breturn
  //SEG40 main::@return
  breturn:
  //SEG41 [17] return 
    rts
}

REGISTER UPLIFT POTENTIAL REGISTERS
Statement [7] *((byte*) main::screen#4 + (byte) main::column#2) ← (byte/word/signed word/dword/signed dword) 160 [ main::screen#4 main::colors#4 main::row#4 main::column#2 main::color#3 ] ( main:2 [ main::screen#4 main::colors#4 main::row#4 main::column#2 main::color#3 ] ) always clobbers reg byte a 
Removing always clobbered register reg byte a as potential for zp ZP_BYTE:6 [ main::row#4 main::row#1 ]
Removing always clobbered register reg byte a as potential for zp ZP_BYTE:7 [ main::column#2 main::column#1 ]
Removing always clobbered register reg byte a as potential for zp ZP_BYTE:8 [ main::color#3 main::color#5 main::color#2 main::color#1 ]
Statement [8] *((byte*) main::colors#4 + (byte) main::column#2) ← (byte) main::color#3 [ main::screen#4 main::colors#4 main::row#4 main::column#2 main::color#3 ] ( main:2 [ main::screen#4 main::colors#4 main::row#4 main::column#2 main::color#3 ] ) always clobbers reg byte a 
Statement [9] (byte) main::color#1 ← (byte) main::color#3 ^ (byte/signed byte/word/signed word/dword/signed dword) 1 [ main::screen#4 main::colors#4 main::row#4 main::column#2 main::color#1 ] ( main:2 [ main::screen#4 main::colors#4 main::row#4 main::column#2 main::color#1 ] ) always clobbers reg byte a 
Statement [12] (byte) main::color#2 ← (byte) main::color#1 ^ (byte/signed byte/word/signed word/dword/signed dword) 1 [ main::screen#4 main::colors#4 main::row#4 main::color#2 ] ( main:2 [ main::screen#4 main::colors#4 main::row#4 main::color#2 ] ) always clobbers reg byte a 
Statement [13] (byte*) main::screen#1 ← (byte*) main::screen#4 + (byte/signed byte/word/signed word/dword/signed dword) 40 [ main::colors#4 main::row#4 main::screen#1 main::color#2 ] ( main:2 [ main::colors#4 main::row#4 main::screen#1 main::color#2 ] ) always clobbers reg byte a 
Statement [14] (byte*) main::colors#1 ← (byte*) main::colors#4 + (byte/signed byte/word/signed word/dword/signed dword) 40 [ main::row#4 main::screen#1 main::color#2 main::colors#1 ] ( main:2 [ main::row#4 main::screen#1 main::color#2 main::colors#1 ] ) always clobbers reg byte a 
Statement [7] *((byte*) main::screen#4 + (byte) main::column#2) ← (byte/word/signed word/dword/signed dword) 160 [ main::screen#4 main::colors#4 main::row#4 main::column#2 main::color#3 ] ( main:2 [ main::screen#4 main::colors#4 main::row#4 main::column#2 main::color#3 ] ) always clobbers reg byte a 
Statement [8] *((byte*) main::colors#4 + (byte) main::column#2) ← (byte) main::color#3 [ main::screen#4 main::colors#4 main::row#4 main::column#2 main::color#3 ] ( main:2 [ main::screen#4 main::colors#4 main::row#4 main::column#2 main::color#3 ] ) always clobbers reg byte a 
Statement [9] (byte) main::color#1 ← (byte) main::color#3 ^ (byte/signed byte/word/signed word/dword/signed dword) 1 [ main::screen#4 main::colors#4 main::row#4 main::column#2 main::color#1 ] ( main:2 [ main::screen#4 main::colors#4 main::row#4 main::column#2 main::color#1 ] ) always clobbers reg byte a 
Statement [12] (byte) main::color#2 ← (byte) main::color#1 ^ (byte/signed byte/word/signed word/dword/signed dword) 1 [ main::screen#4 main::colors#4 main::row#4 main::color#2 ] ( main:2 [ main::screen#4 main::colors#4 main::row#4 main::color#2 ] ) always clobbers reg byte a 
Statement [13] (byte*) main::screen#1 ← (byte*) main::screen#4 + (byte/signed byte/word/signed word/dword/signed dword) 40 [ main::colors#4 main::row#4 main::screen#1 main::color#2 ] ( main:2 [ main::colors#4 main::row#4 main::screen#1 main::color#2 ] ) always clobbers reg byte a 
Statement [14] (byte*) main::colors#1 ← (byte*) main::colors#4 + (byte/signed byte/word/signed word/dword/signed dword) 40 [ main::row#4 main::screen#1 main::color#2 main::colors#1 ] ( main:2 [ main::row#4 main::screen#1 main::color#2 main::colors#1 ] ) always clobbers reg byte a 
Potential registers zp ZP_WORD:2 [ main::screen#4 main::screen#1 ] : zp ZP_WORD:2 , 
Potential registers zp ZP_WORD:4 [ main::colors#4 main::colors#1 ] : zp ZP_WORD:4 , 
Potential registers zp ZP_BYTE:6 [ main::row#4 main::row#1 ] : zp ZP_BYTE:6 , reg byte x , reg byte y , 
Potential registers zp ZP_BYTE:7 [ main::column#2 main::column#1 ] : zp ZP_BYTE:7 , reg byte x , reg byte y , 
Potential registers zp ZP_BYTE:8 [ main::color#3 main::color#5 main::color#2 main::color#1 ] : zp ZP_BYTE:8 , reg byte x , reg byte y , 

REGISTER UPLIFT SCOPES
Uplift Scope [main] 252.5: zp ZP_BYTE:7 [ main::column#2 main::column#1 ] 202.07: zp ZP_BYTE:8 [ main::color#3 main::color#5 main::color#2 main::color#1 ] 21: zp ZP_WORD:4 [ main::colors#4 main::colors#1 ] 20.88: zp ZP_WORD:2 [ main::screen#4 main::screen#1 ] 18.7: zp ZP_BYTE:6 [ main::row#4 main::row#1 ] 
Uplift Scope [] 

Uplifting [main] best 4863 combination reg byte y [ main::column#2 main::column#1 ] reg byte x [ main::color#3 main::color#5 main::color#2 main::color#1 ] zp ZP_WORD:4 [ main::colors#4 main::colors#1 ] zp ZP_WORD:2 [ main::screen#4 main::screen#1 ] zp ZP_BYTE:6 [ main::row#4 main::row#1 ] 
Uplifting [] best 4863 combination 
Attempting to uplift remaining variables inzp ZP_BYTE:6 [ main::row#4 main::row#1 ]
Uplifting [main] best 4863 combination zp ZP_BYTE:6 [ main::row#4 main::row#1 ] 

ASSEMBLER BEFORE OPTIMIZATION
//SEG0 File Comments
// Draws a chess board in the upper left corner of the screen
//SEG1 Basic Upstart
.pc = $801 "Basic"
:BasicUpstart(bbegin)
.pc = $80d "Program"
//SEG2 Global Constants & labels
//SEG3 @begin
bbegin:
//SEG4 [1] phi from @begin to @1 [phi:@begin->@1]
b1_from_bbegin:
  jmp b1
//SEG5 @1
b1:
//SEG6 [2] call main 
//SEG7 [4] phi from @1 to main [phi:@1->main]
main_from_b1:
  jsr main
//SEG8 [3] phi from @1 to @end [phi:@1->@end]
bend_from_b1:
  jmp bend
//SEG9 @end
bend:
//SEG10 main
main: {
    .label screen = 2
    .label colors = 4
    .label row = 6
  //SEG11 [5] phi from main to main::@1 [phi:main->main::@1]
  b1_from_main:
  //SEG12 [5] phi (byte) main::row#4 = (byte/signed byte/word/signed word/dword/signed dword) 0 [phi:main->main::@1#0] -- vbuz1=vbuc1 
    lda #0
    sta row
  //SEG13 [5] phi (byte*) main::colors#4 = ((byte*))(word/dword/signed dword) 55296 [phi:main->main::@1#1] -- pbuz1=pbuc1 
    lda #<$d800
    sta colors
    lda #>$d800
    sta colors+1
  //SEG14 [5] phi (byte) main::color#5 = (byte/signed byte/word/signed word/dword/signed dword) 1 [phi:main->main::@1#2] -- vbuxx=vbuc1 
    ldx #1
  //SEG15 [5] phi (byte*) main::screen#4 = ((byte*))(word/signed word/dword/signed dword) 1024 [phi:main->main::@1#3] -- pbuz1=pbuc1 
    lda #<$400
    sta screen
    lda #>$400
    sta screen+1
    jmp b1
  //SEG16 [5] phi from main::@3 to main::@1 [phi:main::@3->main::@1]
  b1_from_b3:
  //SEG17 [5] phi (byte) main::row#4 = (byte) main::row#1 [phi:main::@3->main::@1#0] -- register_copy 
  //SEG18 [5] phi (byte*) main::colors#4 = (byte*) main::colors#1 [phi:main::@3->main::@1#1] -- register_copy 
  //SEG19 [5] phi (byte) main::color#5 = (byte) main::color#2 [phi:main::@3->main::@1#2] -- register_copy 
  //SEG20 [5] phi (byte*) main::screen#4 = (byte*) main::screen#1 [phi:main::@3->main::@1#3] -- register_copy 
    jmp b1
  //SEG21 main::@1
  b1:
  //SEG22 [6] phi from main::@1 to main::@2 [phi:main::@1->main::@2]
  b2_from_b1:
  //SEG23 [6] phi (byte) main::color#3 = (byte) main::color#5 [phi:main::@1->main::@2#0] -- register_copy 
  //SEG24 [6] phi (byte) main::column#2 = (byte/signed byte/word/signed word/dword/signed dword) 0 [phi:main::@1->main::@2#1] -- vbuyy=vbuc1 
    ldy #0
    jmp b2
  //SEG25 [6] phi from main::@2 to main::@2 [phi:main::@2->main::@2]
  b2_from_b2:
  //SEG26 [6] phi (byte) main::color#3 = (byte) main::color#1 [phi:main::@2->main::@2#0] -- register_copy 
  //SEG27 [6] phi (byte) main::column#2 = (byte) main::column#1 [phi:main::@2->main::@2#1] -- register_copy 
    jmp b2
  //SEG28 main::@2
  b2:
  //SEG29 [7] *((byte*) main::screen#4 + (byte) main::column#2) ← (byte/word/signed word/dword/signed dword) 160 -- pbuz1_derefidx_vbuyy=vbuc1 
    lda #$a0
    sta (screen),y
  //SEG30 [8] *((byte*) main::colors#4 + (byte) main::column#2) ← (byte) main::color#3 -- pbuz1_derefidx_vbuyy=vbuxx 
    txa
    sta (colors),y
  //SEG31 [9] (byte) main::color#1 ← (byte) main::color#3 ^ (byte/signed byte/word/signed word/dword/signed dword) 1 -- vbuxx=vbuxx_bxor_vbuc1 
    txa
    eor #1
    tax
  //SEG32 [10] (byte) main::column#1 ← ++ (byte) main::column#2 -- vbuyy=_inc_vbuyy 
    iny
  //SEG33 [11] if((byte) main::column#1!=(byte/signed byte/word/signed word/dword/signed dword) 8) goto main::@2 -- vbuyy_neq_vbuc1_then_la1 
    cpy #8
    bne b2_from_b2
    jmp b3
  //SEG34 main::@3
  b3:
  //SEG35 [12] (byte) main::color#2 ← (byte) main::color#1 ^ (byte/signed byte/word/signed word/dword/signed dword) 1 -- vbuxx=vbuxx_bxor_vbuc1 
    txa
    eor #1
    tax
  //SEG36 [13] (byte*) main::screen#1 ← (byte*) main::screen#4 + (byte/signed byte/word/signed word/dword/signed dword) 40 -- pbuz1=pbuz1_plus_vbuc1 
    lda screen
    clc
    adc #$28
    sta screen
    bcc !+
    inc screen+1
  !:
  //SEG37 [14] (byte*) main::colors#1 ← (byte*) main::colors#4 + (byte/signed byte/word/signed word/dword/signed dword) 40 -- pbuz1=pbuz1_plus_vbuc1 
    lda colors
    clc
    adc #$28
    sta colors
    bcc !+
    inc colors+1
  !:
  //SEG38 [15] (byte) main::row#1 ← ++ (byte) main::row#4 -- vbuz1=_inc_vbuz1 
    inc row
  //SEG39 [16] if((byte) main::row#1!=(byte/signed byte/word/signed word/dword/signed dword) 8) goto main::@1 -- vbuz1_neq_vbuc1_then_la1 
    lda row
    cmp #8
    bne b1_from_b3
    jmp breturn
  //SEG40 main::@return
  breturn:
  //SEG41 [17] return 
    rts
}

ASSEMBLER OPTIMIZATIONS
Removing instruction jmp b1
Removing instruction jmp bend
Removing instruction jmp b1
Removing instruction jmp b2
Removing instruction jmp b3
Removing instruction jmp breturn
Succesful ASM optimization Pass5NextJumpElimination
Replacing label b2_from_b2 with b2
Replacing label b1_from_b3 with b1
Removing instruction b1_from_bbegin:
Removing instruction b1:
Removing instruction main_from_b1:
Removing instruction bend_from_b1:
Removing instruction b1_from_b3:
Removing instruction b2_from_b1:
Removing instruction b2_from_b2:
Succesful ASM optimization Pass5RedundantLabelElimination
Removing instruction bend:
Removing instruction b1_from_main:
Removing instruction b3:
Removing instruction breturn:
Succesful ASM optimization Pass5UnusedLabelElimination
Updating BasicUpstart to call main directly
Removing instruction jsr main
Succesful ASM optimization Pass5SkipBegin
Removing instruction jmp b1
Removing instruction jmp b2
Succesful ASM optimization Pass5NextJumpElimination
Removing instruction bbegin:
Succesful ASM optimization Pass5UnusedLabelElimination

FINAL SYMBOL TABLE
(label) @1
(label) @begin
(label) @end
(void()) main()
(label) main::@1
(label) main::@2
(label) main::@3
(label) main::@return
(byte) main::color
(byte) main::color#1 reg byte x 71.0
(byte) main::color#2 reg byte x 4.4
(byte) main::color#3 reg byte x 104.66666666666666
(byte) main::color#5 reg byte x 22.0
(byte*) main::colors
(byte*) main::colors#1 colors zp ZP_WORD:4 7.333333333333333
(byte*) main::colors#4 colors zp ZP_WORD:4 13.666666666666664
(byte) main::column
(byte) main::column#1 reg byte y 151.5
(byte) main::column#2 reg byte y 101.0
(byte) main::row
(byte) main::row#1 row zp ZP_BYTE:6 16.5
(byte) main::row#4 row zp ZP_BYTE:6 2.2
(byte*) main::screen
(byte*) main::screen#1 screen zp ZP_WORD:2 5.5
(byte*) main::screen#4 screen zp ZP_WORD:2 15.375

zp ZP_WORD:2 [ main::screen#4 main::screen#1 ]
zp ZP_WORD:4 [ main::colors#4 main::colors#1 ]
zp ZP_BYTE:6 [ main::row#4 main::row#1 ]
reg byte y [ main::column#2 main::column#1 ]
reg byte x [ main::color#3 main::color#5 main::color#2 main::color#1 ]


FINAL ASSEMBLER
Score: 3861

//SEG0 File Comments
// Draws a chess board in the upper left corner of the screen
//SEG1 Basic Upstart
.pc = $801 "Basic"
:BasicUpstart(main)
.pc = $80d "Program"
//SEG2 Global Constants & labels
//SEG3 @begin
//SEG4 [1] phi from @begin to @1 [phi:@begin->@1]
//SEG5 @1
//SEG6 [2] call main 
//SEG7 [4] phi from @1 to main [phi:@1->main]
//SEG8 [3] phi from @1 to @end [phi:@1->@end]
//SEG9 @end
//SEG10 main
main: {
    .label screen = 2
    .label colors = 4
    .label row = 6
  //SEG11 [5] phi from main to main::@1 [phi:main->main::@1]
  //SEG12 [5] phi (byte) main::row#4 = (byte/signed byte/word/signed word/dword/signed dword) 0 [phi:main->main::@1#0] -- vbuz1=vbuc1 
    lda #0
    sta row
  //SEG13 [5] phi (byte*) main::colors#4 = ((byte*))(word/dword/signed dword) 55296 [phi:main->main::@1#1] -- pbuz1=pbuc1 
    lda #<$d800
    sta colors
    lda #>$d800
    sta colors+1
  //SEG14 [5] phi (byte) main::color#5 = (byte/signed byte/word/signed word/dword/signed dword) 1 [phi:main->main::@1#2] -- vbuxx=vbuc1 
    ldx #1
  //SEG15 [5] phi (byte*) main::screen#4 = ((byte*))(word/signed word/dword/signed dword) 1024 [phi:main->main::@1#3] -- pbuz1=pbuc1 
    lda #<$400
    sta screen
    lda #>$400
    sta screen+1
  //SEG16 [5] phi from main::@3 to main::@1 [phi:main::@3->main::@1]
  //SEG17 [5] phi (byte) main::row#4 = (byte) main::row#1 [phi:main::@3->main::@1#0] -- register_copy 
  //SEG18 [5] phi (byte*) main::colors#4 = (byte*) main::colors#1 [phi:main::@3->main::@1#1] -- register_copy 
  //SEG19 [5] phi (byte) main::color#5 = (byte) main::color#2 [phi:main::@3->main::@1#2] -- register_copy 
  //SEG20 [5] phi (byte*) main::screen#4 = (byte*) main::screen#1 [phi:main::@3->main::@1#3] -- register_copy 
  //SEG21 main::@1
  b1:
  //SEG22 [6] phi from main::@1 to main::@2 [phi:main::@1->main::@2]
  //SEG23 [6] phi (byte) main::color#3 = (byte) main::color#5 [phi:main::@1->main::@2#0] -- register_copy 
  //SEG24 [6] phi (byte) main::column#2 = (byte/signed byte/word/signed word/dword/signed dword) 0 [phi:main::@1->main::@2#1] -- vbuyy=vbuc1 
    ldy #0
  //SEG25 [6] phi from main::@2 to main::@2 [phi:main::@2->main::@2]
  //SEG26 [6] phi (byte) main::color#3 = (byte) main::color#1 [phi:main::@2->main::@2#0] -- register_copy 
  //SEG27 [6] phi (byte) main::column#2 = (byte) main::column#1 [phi:main::@2->main::@2#1] -- register_copy 
  //SEG28 main::@2
  b2:
  //SEG29 [7] *((byte*) main::screen#4 + (byte) main::column#2) ← (byte/word/signed word/dword/signed dword) 160 -- pbuz1_derefidx_vbuyy=vbuc1 
    lda #$a0
    sta (screen),y
  //SEG30 [8] *((byte*) main::colors#4 + (byte) main::column#2) ← (byte) main::color#3 -- pbuz1_derefidx_vbuyy=vbuxx 
    txa
    sta (colors),y
  //SEG31 [9] (byte) main::color#1 ← (byte) main::color#3 ^ (byte/signed byte/word/signed word/dword/signed dword) 1 -- vbuxx=vbuxx_bxor_vbuc1 
    txa
    eor #1
    tax
  //SEG32 [10] (byte) main::column#1 ← ++ (byte) main::column#2 -- vbuyy=_inc_vbuyy 
    iny
  //SEG33 [11] if((byte) main::column#1!=(byte/signed byte/word/signed word/dword/signed dword) 8) goto main::@2 -- vbuyy_neq_vbuc1_then_la1 
    cpy #8
    bne b2
  //SEG34 main::@3
  //SEG35 [12] (byte) main::color#2 ← (byte) main::color#1 ^ (byte/signed byte/word/signed word/dword/signed dword) 1 -- vbuxx=vbuxx_bxor_vbuc1 
    txa
    eor #1
    tax
  //SEG36 [13] (byte*) main::screen#1 ← (byte*) main::screen#4 + (byte/signed byte/word/signed word/dword/signed dword) 40 -- pbuz1=pbuz1_plus_vbuc1 
    lda screen
    clc
    adc #$28
    sta screen
    bcc !+
    inc screen+1
  !:
  //SEG37 [14] (byte*) main::colors#1 ← (byte*) main::colors#4 + (byte/signed byte/word/signed word/dword/signed dword) 40 -- pbuz1=pbuz1_plus_vbuc1 
    lda colors
    clc
    adc #$28
    sta colors
    bcc !+
    inc colors+1
  !:
  //SEG38 [15] (byte) main::row#1 ← ++ (byte) main::row#4 -- vbuz1=_inc_vbuz1 
    inc row
  //SEG39 [16] if((byte) main::row#1!=(byte/signed byte/word/signed word/dword/signed dword) 8) goto main::@1 -- vbuz1_neq_vbuc1_then_la1 
    lda row
    cmp #8
    bne b1
  //SEG40 main::@return
  //SEG41 [17] return 
    rts
}

