PARSING src/test/java/dk/camelot64/kickc/test/kc/asm-clobber.kc
// Tests that inline ASM clobbering is taken into account when assigning registers
byte* SCREEN = $0400;
void main() {
    // First loop with no clobber
    for(byte i : 0..100) {
        for(byte j: 0..100) {
            SCREEN[i] = j;
        }
    }
    // Then loop with clobbering A&X
    for(byte k : 0..100) {
        for(byte l: 0..100) {
            asm {
                // Clobber all registers
                eor #$55
                tax
            }
            SCREEN[k] = l;
        }
    }
}


STATEMENTS
  (byte*) SCREEN ← (word/signed word/dword/signed dword) 1024
proc (void()) main()
  (byte) main::i ← (byte/signed byte/word/signed word/dword/signed dword) 0
main::@1:
  (byte) main::j ← (byte/signed byte/word/signed word/dword/signed dword) 0
main::@2:
  *((byte*) SCREEN + (byte) main::i) ← (byte) main::j
  (byte) main::j ← ++ (byte) main::j
  (boolean~) main::$0 ← (byte) main::j != (byte/signed byte/word/signed word/dword/signed dword) 101
  if((boolean~) main::$0) goto main::@2
  (byte) main::i ← ++ (byte) main::i
  (boolean~) main::$1 ← (byte) main::i != (byte/signed byte/word/signed word/dword/signed dword) 101
  if((boolean~) main::$1) goto main::@1
  (byte) main::k ← (byte/signed byte/word/signed word/dword/signed dword) 0
main::@3:
  (byte) main::l ← (byte/signed byte/word/signed word/dword/signed dword) 0
main::@4:
  asm { eor#$55 tax  }
  *((byte*) SCREEN + (byte) main::k) ← (byte) main::l
  (byte) main::l ← ++ (byte) main::l
  (boolean~) main::$2 ← (byte) main::l != (byte/signed byte/word/signed word/dword/signed dword) 101
  if((boolean~) main::$2) goto main::@4
  (byte) main::k ← ++ (byte) main::k
  (boolean~) main::$3 ← (byte) main::k != (byte/signed byte/word/signed word/dword/signed dword) 101
  if((boolean~) main::$3) goto main::@3
main::@return:
  return 
endproc // main()
  call main 

SYMBOLS
(byte*) SCREEN
(void()) main()
(boolean~) main::$0
(boolean~) main::$1
(boolean~) main::$2
(boolean~) main::$3
(label) main::@1
(label) main::@2
(label) main::@3
(label) main::@4
(label) main::@return
(byte) main::i
(byte) main::j
(byte) main::k
(byte) main::l

Promoting word/signed word/dword/signed dword to byte* in SCREEN ← ((byte*)) 1024
INITIAL CONTROL FLOW GRAPH
@begin: scope:[]  from
  (byte*) SCREEN ← ((byte*)) (word/signed word/dword/signed dword) 1024
  to:@1
main: scope:[main]  from
  (byte) main::i ← (byte/signed byte/word/signed word/dword/signed dword) 0
  to:main::@1
main::@1: scope:[main]  from main main::@5
  (byte) main::j ← (byte/signed byte/word/signed word/dword/signed dword) 0
  to:main::@2
main::@2: scope:[main]  from main::@1 main::@2
  *((byte*) SCREEN + (byte) main::i) ← (byte) main::j
  (byte) main::j ← ++ (byte) main::j
  (boolean~) main::$0 ← (byte) main::j != (byte/signed byte/word/signed word/dword/signed dword) 101
  if((boolean~) main::$0) goto main::@2
  to:main::@5
main::@5: scope:[main]  from main::@2
  (byte) main::i ← ++ (byte) main::i
  (boolean~) main::$1 ← (byte) main::i != (byte/signed byte/word/signed word/dword/signed dword) 101
  if((boolean~) main::$1) goto main::@1
  to:main::@6
main::@6: scope:[main]  from main::@5
  (byte) main::k ← (byte/signed byte/word/signed word/dword/signed dword) 0
  to:main::@3
main::@3: scope:[main]  from main::@6 main::@7
  (byte) main::l ← (byte/signed byte/word/signed word/dword/signed dword) 0
  to:main::@4
main::@4: scope:[main]  from main::@3 main::@4
  asm { eor#$55 tax  }
  *((byte*) SCREEN + (byte) main::k) ← (byte) main::l
  (byte) main::l ← ++ (byte) main::l
  (boolean~) main::$2 ← (byte) main::l != (byte/signed byte/word/signed word/dword/signed dword) 101
  if((boolean~) main::$2) goto main::@4
  to:main::@7
main::@7: scope:[main]  from main::@4
  (byte) main::k ← ++ (byte) main::k
  (boolean~) main::$3 ← (byte) main::k != (byte/signed byte/word/signed word/dword/signed dword) 101
  if((boolean~) main::$3) goto main::@3
  to:main::@8
main::@8: scope:[main]  from main::@7
  to:main::@return
main::@return: scope:[main]  from main::@8
  return 
  to:@return
@1: scope:[]  from @begin
  call main 
  to:@end
@end: scope:[]  from @1

Removing empty block main::@8
PROCEDURE MODIFY VARIABLE ANALYSIS

Completing Phi functions...
Completing Phi functions...
Completing Phi functions...
Completing Phi functions...

CONTROL FLOW GRAPH SSA WITH ASSIGNMENT CALL & RETURN
@begin: scope:[]  from
  (byte*) SCREEN#0 ← ((byte*)) (word/signed word/dword/signed dword) 1024
  to:@1
main: scope:[main]  from @1
  (byte*) SCREEN#5 ← phi( @1/(byte*) SCREEN#9 )
  (byte) main::i#0 ← (byte/signed byte/word/signed word/dword/signed dword) 0
  to:main::@1
main::@1: scope:[main]  from main main::@5
  (byte) main::i#4 ← phi( main/(byte) main::i#0 main::@5/(byte) main::i#1 )
  (byte*) SCREEN#3 ← phi( main/(byte*) SCREEN#5 main::@5/(byte*) SCREEN#6 )
  (byte) main::j#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::i#2 ← phi( main::@1/(byte) main::i#4 main::@2/(byte) main::i#2 )
  (byte*) SCREEN#1 ← phi( main::@1/(byte*) SCREEN#3 main::@2/(byte*) SCREEN#1 )
  (byte) main::j#2 ← phi( main::@1/(byte) main::j#0 main::@2/(byte) main::j#1 )
  *((byte*) SCREEN#1 + (byte) main::i#2) ← (byte) main::j#2
  (byte) main::j#1 ← ++ (byte) main::j#2
  (boolean~) main::$0 ← (byte) main::j#1 != (byte/signed byte/word/signed word/dword/signed dword) 101
  if((boolean~) main::$0) goto main::@2
  to:main::@5
main::@5: scope:[main]  from main::@2
  (byte*) SCREEN#6 ← phi( main::@2/(byte*) SCREEN#1 )
  (byte) main::i#3 ← phi( main::@2/(byte) main::i#2 )
  (byte) main::i#1 ← ++ (byte) main::i#3
  (boolean~) main::$1 ← (byte) main::i#1 != (byte/signed byte/word/signed word/dword/signed dword) 101
  if((boolean~) main::$1) goto main::@1
  to:main::@6
main::@6: scope:[main]  from main::@5
  (byte*) SCREEN#7 ← phi( main::@5/(byte*) SCREEN#6 )
  (byte) main::k#0 ← (byte/signed byte/word/signed word/dword/signed dword) 0
  to:main::@3
main::@3: scope:[main]  from main::@6 main::@7
  (byte) main::k#4 ← phi( main::@6/(byte) main::k#0 main::@7/(byte) main::k#1 )
  (byte*) SCREEN#4 ← phi( main::@6/(byte*) SCREEN#7 main::@7/(byte*) SCREEN#8 )
  (byte) main::l#0 ← (byte/signed byte/word/signed word/dword/signed dword) 0
  to:main::@4
main::@4: scope:[main]  from main::@3 main::@4
  (byte) main::k#2 ← phi( main::@3/(byte) main::k#4 main::@4/(byte) main::k#2 )
  (byte*) SCREEN#2 ← phi( main::@3/(byte*) SCREEN#4 main::@4/(byte*) SCREEN#2 )
  (byte) main::l#2 ← phi( main::@3/(byte) main::l#0 main::@4/(byte) main::l#1 )
  asm { eor#$55 tax  }
  *((byte*) SCREEN#2 + (byte) main::k#2) ← (byte) main::l#2
  (byte) main::l#1 ← ++ (byte) main::l#2
  (boolean~) main::$2 ← (byte) main::l#1 != (byte/signed byte/word/signed word/dword/signed dword) 101
  if((boolean~) main::$2) goto main::@4
  to:main::@7
main::@7: scope:[main]  from main::@4
  (byte*) SCREEN#8 ← phi( main::@4/(byte*) SCREEN#2 )
  (byte) main::k#3 ← phi( main::@4/(byte) main::k#2 )
  (byte) main::k#1 ← ++ (byte) main::k#3
  (boolean~) main::$3 ← (byte) main::k#1 != (byte/signed byte/word/signed word/dword/signed dword) 101
  if((boolean~) main::$3) goto main::@3
  to:main::@return
main::@return: scope:[main]  from main::@7
  return 
  to:@return
@1: scope:[]  from @begin
  (byte*) SCREEN#9 ← phi( @begin/(byte*) SCREEN#0 )
  call main param-assignment
  to:@2
@2: scope:[]  from @1
  to:@end
@end: scope:[]  from @2

SYMBOL TABLE SSA
(label) @1
(label) @2
(label) @begin
(label) @end
(byte*) SCREEN
(byte*) SCREEN#0
(byte*) SCREEN#1
(byte*) SCREEN#2
(byte*) SCREEN#3
(byte*) SCREEN#4
(byte*) SCREEN#5
(byte*) SCREEN#6
(byte*) SCREEN#7
(byte*) SCREEN#8
(byte*) SCREEN#9
(void()) main()
(boolean~) main::$0
(boolean~) main::$1
(boolean~) main::$2
(boolean~) main::$3
(label) main::@1
(label) main::@2
(label) main::@3
(label) main::@4
(label) main::@5
(label) main::@6
(label) main::@7
(label) main::@return
(byte) main::i
(byte) main::i#0
(byte) main::i#1
(byte) main::i#2
(byte) main::i#3
(byte) main::i#4
(byte) main::j
(byte) main::j#0
(byte) main::j#1
(byte) main::j#2
(byte) main::k
(byte) main::k#0
(byte) main::k#1
(byte) main::k#2
(byte) main::k#3
(byte) main::k#4
(byte) main::l
(byte) main::l#0
(byte) main::l#1
(byte) main::l#2

OPTIMIZING CONTROL FLOW GRAPH
Culled Empty Block (label) @2
Succesful SSA optimization Pass2CullEmptyBlocks
Not aliassing across scopes: SCREEN#5 SCREEN#9
Alias (byte) main::i#2 = (byte) main::i#3 
Alias (byte*) SCREEN#1 = (byte*) SCREEN#6 (byte*) SCREEN#7 
Alias (byte) main::k#2 = (byte) main::k#3 
Alias (byte*) SCREEN#2 = (byte*) SCREEN#8 
Alias (byte*) SCREEN#0 = (byte*) SCREEN#9 
Succesful SSA optimization Pass2AliasElimination
Not aliassing across scopes: SCREEN#5 SCREEN#0
Self Phi Eliminated (byte*) SCREEN#1
Self Phi Eliminated (byte) main::i#2
Self Phi Eliminated (byte*) SCREEN#2
Self Phi Eliminated (byte) main::k#2
Succesful SSA optimization Pass2SelfPhiElimination
Redundant Phi (byte*) SCREEN#5 (byte*) SCREEN#0
Redundant Phi (byte*) SCREEN#1 (byte*) SCREEN#3
Redundant Phi (byte) main::i#2 (byte) main::i#4
Redundant Phi (byte*) SCREEN#2 (byte*) SCREEN#4
Redundant Phi (byte) main::k#2 (byte) main::k#4
Succesful SSA optimization Pass2RedundantPhiElimination
Simple Condition (boolean~) main::$0 if((byte) main::j#1!=(byte/signed byte/word/signed word/dword/signed dword) 101) goto main::@2
Simple Condition (boolean~) main::$1 if((byte) main::i#1!=(byte/signed byte/word/signed word/dword/signed dword) 101) goto main::@1
Simple Condition (boolean~) main::$2 if((byte) main::l#1!=(byte/signed byte/word/signed word/dword/signed dword) 101) goto main::@4
Simple Condition (boolean~) main::$3 if((byte) main::k#1!=(byte/signed byte/word/signed word/dword/signed dword) 101) goto main::@3
Succesful SSA optimization Pass2ConditionalJumpSimplification
Constant (const byte*) SCREEN#0 = ((byte*))1024
Constant (const byte) main::i#0 = 0
Constant (const byte) main::j#0 = 0
Constant (const byte) main::k#0 = 0
Constant (const byte) main::l#0 = 0
Succesful SSA optimization Pass2ConstantIdentification
Culled Empty Block (label) main::@6
Succesful SSA optimization Pass2CullEmptyBlocks
Self Phi Eliminated (byte*) SCREEN#3
Self Phi Eliminated (byte*) SCREEN#4
Succesful SSA optimization Pass2SelfPhiElimination
Redundant Phi (byte*) SCREEN#3 (const byte*) SCREEN#0
Redundant Phi (byte*) SCREEN#4 (byte*) SCREEN#3
Succesful SSA optimization Pass2RedundantPhiElimination
OPTIMIZING CONTROL FLOW GRAPH
Inlining constant with var siblings (const byte) main::i#0
Inlining constant with var siblings (const byte) main::i#0
Inlining constant with var siblings (const byte) main::j#0
Inlining constant with var siblings (const byte) main::j#0
Inlining constant with var siblings (const byte) main::k#0
Inlining constant with var siblings (const byte) main::k#0
Inlining constant with var siblings (const byte) main::l#0
Inlining constant with var siblings (const byte) main::l#0
Constant inlined main::i#0 = (byte/signed byte/word/signed word/dword/signed dword) 0
Constant inlined main::k#0 = (byte/signed byte/word/signed word/dword/signed dword) 0
Constant inlined main::j#0 = (byte/signed byte/word/signed word/dword/signed dword) 0
Constant inlined main::l#0 = (byte/signed byte/word/signed word/dword/signed dword) 0
Succesful SSA optimization Pass2ConstantInlining
Block Sequence Planned @begin @1 @end main main::@1 main::@2 main::@5 main::@3 main::@4 main::@7 main::@return 
Added new block during phi lifting main::@9(between main::@5 and main::@1)
Added new block during phi lifting main::@10(between main::@2 and main::@2)
Added new block during phi lifting main::@11(between main::@7 and main::@3)
Added new block during phi lifting main::@12(between main::@4 and main::@4)
Block Sequence Planned @begin @1 @end main main::@1 main::@2 main::@5 main::@3 main::@4 main::@7 main::@return main::@11 main::@12 main::@9 main::@10 
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 

Propagating live ranges...
Propagating live ranges...
Propagating live ranges...
Propagating live ranges...
Created 4 initial phi equivalence classes
Coalesced [21] main::k#5 ← main::k#1
Coalesced [22] main::l#3 ← main::l#1
Coalesced [23] main::i#5 ← main::i#1
Coalesced [24] main::j#3 ← main::j#1
Coalesced down to 4 phi equivalence classes
Culled Empty Block (label) main::@11
Culled Empty Block (label) main::@12
Culled Empty Block (label) main::@9
Culled Empty Block (label) main::@10
Block Sequence Planned @begin @1 @end main main::@1 main::@2 main::@5 main::@3 main::@4 main::@7 main::@return 
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
Propagating live ranges...
Propagating live ranges...
Propagating live ranges...
Propagating live ranges...

FINAL CONTROL FLOW GRAPH
@begin: scope:[]  from
  [0] phi() [ ] ( )
  to:@1
@1: scope:[]  from @begin
  [1] phi() [ ] ( )
  [2] call main param-assignment [ ] ( )
  to:@end
@end: scope:[]  from @1
  [3] phi() [ ] ( )
main: scope:[main]  from @1
  [4] phi() [ ] ( main:2 [ ] )
  to:main::@1
main::@1: scope:[main]  from main main::@5
  [5] (byte) main::i#4 ← phi( main/(byte/signed byte/word/signed word/dword/signed dword) 0 main::@5/(byte) main::i#1 ) [ main::i#4 ] ( main:2 [ main::i#4 ] )
  to:main::@2
main::@2: scope:[main]  from main::@1 main::@2
  [6] (byte) main::j#2 ← phi( main::@1/(byte/signed byte/word/signed word/dword/signed dword) 0 main::@2/(byte) main::j#1 ) [ main::i#4 main::j#2 ] ( main:2 [ main::i#4 main::j#2 ] )
  [7] *((const byte*) SCREEN#0 + (byte) main::i#4) ← (byte) main::j#2 [ main::i#4 main::j#2 ] ( main:2 [ main::i#4 main::j#2 ] )
  [8] (byte) main::j#1 ← ++ (byte) main::j#2 [ main::i#4 main::j#1 ] ( main:2 [ main::i#4 main::j#1 ] )
  [9] if((byte) main::j#1!=(byte/signed byte/word/signed word/dword/signed dword) 101) goto main::@2 [ main::i#4 main::j#1 ] ( main:2 [ main::i#4 main::j#1 ] )
  to:main::@5
main::@5: scope:[main]  from main::@2
  [10] (byte) main::i#1 ← ++ (byte) main::i#4 [ main::i#1 ] ( main:2 [ main::i#1 ] )
  [11] if((byte) main::i#1!=(byte/signed byte/word/signed word/dword/signed dword) 101) goto main::@1 [ main::i#1 ] ( main:2 [ main::i#1 ] )
  to:main::@3
main::@3: scope:[main]  from main::@5 main::@7
  [12] (byte) main::k#4 ← phi( main::@5/(byte/signed byte/word/signed word/dword/signed dword) 0 main::@7/(byte) main::k#1 ) [ main::k#4 ] ( main:2 [ main::k#4 ] )
  to:main::@4
main::@4: scope:[main]  from main::@3 main::@4
  [13] (byte) main::l#2 ← phi( main::@3/(byte/signed byte/word/signed word/dword/signed dword) 0 main::@4/(byte) main::l#1 ) [ main::k#4 main::l#2 ] ( main:2 [ main::k#4 main::l#2 ] )
  asm { eor#$55 tax  }
  [15] *((const byte*) SCREEN#0 + (byte) main::k#4) ← (byte) main::l#2 [ main::k#4 main::l#2 ] ( main:2 [ main::k#4 main::l#2 ] )
  [16] (byte) main::l#1 ← ++ (byte) main::l#2 [ main::k#4 main::l#1 ] ( main:2 [ main::k#4 main::l#1 ] )
  [17] if((byte) main::l#1!=(byte/signed byte/word/signed word/dword/signed dword) 101) goto main::@4 [ main::k#4 main::l#1 ] ( main:2 [ main::k#4 main::l#1 ] )
  to:main::@7
main::@7: scope:[main]  from main::@4
  [18] (byte) main::k#1 ← ++ (byte) main::k#4 [ main::k#1 ] ( main:2 [ main::k#1 ] )
  [19] if((byte) main::k#1!=(byte/signed byte/word/signed word/dword/signed dword) 101) goto main::@3 [ main::k#1 ] ( main:2 [ main::k#1 ] )
  to:main::@return
main::@return: scope:[main]  from main::@7
  [20] return  [ ] ( main:2 [ ] )
  to:@return

DOMINATORS
@begin dominated by  @begin 
@1 dominated by  @1 @begin 
@end dominated by  @1 @begin @end 
main dominated by  @1 @begin main 
main::@1 dominated by  @1 @begin main::@1 main 
main::@2 dominated by  @1 @begin main::@1 main::@2 main 
main::@5 dominated by  @1 @begin main::@1 main::@2 main main::@5 
main::@3 dominated by  @1 @begin main::@1 main::@2 main main::@5 main::@3 
main::@4 dominated by  @1 @begin main::@1 main::@2 main main::@5 main::@3 main::@4 
main::@7 dominated by  @1 main::@7 @begin main::@1 main::@2 main main::@5 main::@3 main::@4 
main::@return dominated by  main::@return @1 main::@7 @begin main::@1 main::@2 main main::@5 main::@3 main::@4 

NATURAL LOOPS
Found back edge: Loop head: main::@2 tails: main::@2 blocks: null
Found back edge: Loop head: main::@1 tails: main::@5 blocks: null
Found back edge: Loop head: main::@4 tails: main::@4 blocks: null
Found back edge: Loop head: main::@3 tails: main::@7 blocks: null
Populated: Loop head: main::@2 tails: main::@2 blocks: main::@2 
Populated: Loop head: main::@1 tails: main::@5 blocks: main::@5 main::@2 main::@1 
Populated: Loop head: main::@4 tails: main::@4 blocks: main::@4 
Populated: Loop head: main::@3 tails: main::@7 blocks: main::@7 main::@4 main::@3 
Loop head: main::@2 tails: main::@2 blocks: main::@2 
Loop head: main::@1 tails: main::@5 blocks: main::@5 main::@2 main::@1 
Loop head: main::@4 tails: main::@4 blocks: main::@4 
Loop head: main::@3 tails: main::@7 blocks: main::@7 main::@4 main::@3 

NATURAL LOOPS WITH DEPTH
Found 0 loops in scope []
Found 4 loops in scope [main]
  Loop head: main::@2 tails: main::@2 blocks: main::@2 
  Loop head: main::@1 tails: main::@5 blocks: main::@5 main::@2 main::@1 
  Loop head: main::@4 tails: main::@4 blocks: main::@4 
  Loop head: main::@3 tails: main::@7 blocks: main::@7 main::@4 main::@3 
Loop head: main::@2 tails: main::@2 blocks: main::@2  depth: 2
Loop head: main::@1 tails: main::@5 blocks: main::@5 main::@2 main::@1  depth: 1
Loop head: main::@4 tails: main::@4 blocks: main::@4  depth: 2
Loop head: main::@3 tails: main::@7 blocks: main::@7 main::@4 main::@3  depth: 1


VARIABLE REGISTER WEIGHTS
(byte*) SCREEN
(void()) main()
(byte) main::i
(byte) main::i#1 16.5
(byte) main::i#4 24.599999999999998
(byte) main::j
(byte) main::j#1 151.5
(byte) main::j#2 151.5
(byte) main::k
(byte) main::k#1 16.5
(byte) main::k#4 20.499999999999996
(byte) main::l
(byte) main::l#1 151.5
(byte) main::l#2 101.0

Initial phi equivalence classes
[ main::i#4 main::i#1 ]
[ main::j#2 main::j#1 ]
[ main::k#4 main::k#1 ]
[ main::l#2 main::l#1 ]
Complete equivalence classes
[ main::i#4 main::i#1 ]
[ main::j#2 main::j#1 ]
[ main::k#4 main::k#1 ]
[ main::l#2 main::l#1 ]
Allocated zp ZP_BYTE:2 [ main::i#4 main::i#1 ]
Allocated zp ZP_BYTE:3 [ main::j#2 main::j#1 ]
Allocated zp ZP_BYTE:4 [ main::k#4 main::k#1 ]
Allocated zp ZP_BYTE:5 [ main::l#2 main::l#1 ]

INITIAL ASM
//SEG0 Basic Upstart
.pc = $801 "Basic"
:BasicUpstart(main)
.pc = $80d "Program"
//SEG1 Global Constants & labels
  .label SCREEN = $400
//SEG2 @begin
bbegin:
//SEG3 [1] phi from @begin to @1 [phi:@begin->@1]
b1_from_bbegin:
  jmp b1
//SEG4 @1
b1:
//SEG5 [2] call main param-assignment [ ] ( )
//SEG6 [4] phi from @1 to main [phi:@1->main]
main_from_b1:
  jsr main
//SEG7 [3] phi from @1 to @end [phi:@1->@end]
bend_from_b1:
  jmp bend
//SEG8 @end
bend:
//SEG9 main
main: {
    .label j = 3
    .label i = 2
    .label l = 5
    .label k = 4
  //SEG10 [5] phi from main to main::@1 [phi:main->main::@1]
  b1_from_main:
  //SEG11 [5] phi (byte) main::i#4 = (byte/signed byte/word/signed word/dword/signed dword) 0 [phi:main->main::@1#0] -- vbuz1=vbuc1 
    lda #0
    sta i
    jmp b1
  //SEG12 [5] phi from main::@5 to main::@1 [phi:main::@5->main::@1]
  b1_from_b5:
  //SEG13 [5] phi (byte) main::i#4 = (byte) main::i#1 [phi:main::@5->main::@1#0] -- register_copy 
    jmp b1
  //SEG14 main::@1
  b1:
  //SEG15 [6] phi from main::@1 to main::@2 [phi:main::@1->main::@2]
  b2_from_b1:
  //SEG16 [6] phi (byte) main::j#2 = (byte/signed byte/word/signed word/dword/signed dword) 0 [phi:main::@1->main::@2#0] -- vbuz1=vbuc1 
    lda #0
    sta j
    jmp b2
  //SEG17 [6] phi from main::@2 to main::@2 [phi:main::@2->main::@2]
  b2_from_b2:
  //SEG18 [6] phi (byte) main::j#2 = (byte) main::j#1 [phi:main::@2->main::@2#0] -- register_copy 
    jmp b2
  //SEG19 main::@2
  b2:
  //SEG20 [7] *((const byte*) SCREEN#0 + (byte) main::i#4) ← (byte) main::j#2 [ main::i#4 main::j#2 ] ( main:2 [ main::i#4 main::j#2 ] ) -- pbuc1_derefidx_vbuz1=vbuz2 
    lda j
    ldy i
    sta SCREEN,y
  //SEG21 [8] (byte) main::j#1 ← ++ (byte) main::j#2 [ main::i#4 main::j#1 ] ( main:2 [ main::i#4 main::j#1 ] ) -- vbuz1=_inc_vbuz1 
    inc j
  //SEG22 [9] if((byte) main::j#1!=(byte/signed byte/word/signed word/dword/signed dword) 101) goto main::@2 [ main::i#4 main::j#1 ] ( main:2 [ main::i#4 main::j#1 ] ) -- vbuz1_neq_vbuc1_then_la1 
    lda j
    cmp #$65
    bne b2_from_b2
    jmp b5
  //SEG23 main::@5
  b5:
  //SEG24 [10] (byte) main::i#1 ← ++ (byte) main::i#4 [ main::i#1 ] ( main:2 [ main::i#1 ] ) -- vbuz1=_inc_vbuz1 
    inc i
  //SEG25 [11] if((byte) main::i#1!=(byte/signed byte/word/signed word/dword/signed dword) 101) goto main::@1 [ main::i#1 ] ( main:2 [ main::i#1 ] ) -- vbuz1_neq_vbuc1_then_la1 
    lda i
    cmp #$65
    bne b1_from_b5
  //SEG26 [12] phi from main::@5 to main::@3 [phi:main::@5->main::@3]
  b3_from_b5:
  //SEG27 [12] phi (byte) main::k#4 = (byte/signed byte/word/signed word/dword/signed dword) 0 [phi:main::@5->main::@3#0] -- vbuz1=vbuc1 
    lda #0
    sta k
    jmp b3
  //SEG28 [12] phi from main::@7 to main::@3 [phi:main::@7->main::@3]
  b3_from_b7:
  //SEG29 [12] phi (byte) main::k#4 = (byte) main::k#1 [phi:main::@7->main::@3#0] -- register_copy 
    jmp b3
  //SEG30 main::@3
  b3:
  //SEG31 [13] phi from main::@3 to main::@4 [phi:main::@3->main::@4]
  b4_from_b3:
  //SEG32 [13] phi (byte) main::l#2 = (byte/signed byte/word/signed word/dword/signed dword) 0 [phi:main::@3->main::@4#0] -- vbuz1=vbuc1 
    lda #0
    sta l
    jmp b4
  //SEG33 [13] phi from main::@4 to main::@4 [phi:main::@4->main::@4]
  b4_from_b4:
  //SEG34 [13] phi (byte) main::l#2 = (byte) main::l#1 [phi:main::@4->main::@4#0] -- register_copy 
    jmp b4
  //SEG35 main::@4
  b4:
  //SEG36 asm { eor#$55 tax  }
    eor #$55
    tax
  //SEG37 [15] *((const byte*) SCREEN#0 + (byte) main::k#4) ← (byte) main::l#2 [ main::k#4 main::l#2 ] ( main:2 [ main::k#4 main::l#2 ] ) -- pbuc1_derefidx_vbuz1=vbuz2 
    lda l
    ldy k
    sta SCREEN,y
  //SEG38 [16] (byte) main::l#1 ← ++ (byte) main::l#2 [ main::k#4 main::l#1 ] ( main:2 [ main::k#4 main::l#1 ] ) -- vbuz1=_inc_vbuz1 
    inc l
  //SEG39 [17] if((byte) main::l#1!=(byte/signed byte/word/signed word/dword/signed dword) 101) goto main::@4 [ main::k#4 main::l#1 ] ( main:2 [ main::k#4 main::l#1 ] ) -- vbuz1_neq_vbuc1_then_la1 
    lda l
    cmp #$65
    bne b4_from_b4
    jmp b7
  //SEG40 main::@7
  b7:
  //SEG41 [18] (byte) main::k#1 ← ++ (byte) main::k#4 [ main::k#1 ] ( main:2 [ main::k#1 ] ) -- vbuz1=_inc_vbuz1 
    inc k
  //SEG42 [19] if((byte) main::k#1!=(byte/signed byte/word/signed word/dword/signed dword) 101) goto main::@3 [ main::k#1 ] ( main:2 [ main::k#1 ] ) -- vbuz1_neq_vbuc1_then_la1 
    lda k
    cmp #$65
    bne b3_from_b7
    jmp breturn
  //SEG43 main::@return
  breturn:
  //SEG44 [20] return  [ ] ( main:2 [ ] )
    rts
}

REGISTER UPLIFT POTENTIAL REGISTERS
Statement asm { eor#$55 tax  } always clobbers reg byte a reg byte x 
Removing always clobbered register reg byte a as potential for zp ZP_BYTE:4 [ main::k#4 main::k#1 ]
Removing always clobbered register reg byte x as potential for zp ZP_BYTE:4 [ main::k#4 main::k#1 ]
Removing always clobbered register reg byte a as potential for zp ZP_BYTE:5 [ main::l#2 main::l#1 ]
Removing always clobbered register reg byte x as potential for zp ZP_BYTE:5 [ main::l#2 main::l#1 ]
Statement [15] *((const byte*) SCREEN#0 + (byte) main::k#4) ← (byte) main::l#2 [ main::k#4 main::l#2 ] ( main:2 [ main::k#4 main::l#2 ] ) always clobbers reg byte a 
Statement asm { eor#$55 tax  } always clobbers reg byte a reg byte x 
Statement [15] *((const byte*) SCREEN#0 + (byte) main::k#4) ← (byte) main::l#2 [ main::k#4 main::l#2 ] ( main:2 [ main::k#4 main::l#2 ] ) always clobbers reg byte a 
Potential registers zp ZP_BYTE:2 [ main::i#4 main::i#1 ] : zp ZP_BYTE:2 , reg byte a , reg byte x , reg byte y , 
Potential registers zp ZP_BYTE:3 [ main::j#2 main::j#1 ] : zp ZP_BYTE:3 , reg byte a , reg byte x , reg byte y , 
Potential registers zp ZP_BYTE:4 [ main::k#4 main::k#1 ] : zp ZP_BYTE:4 , reg byte y , 
Potential registers zp ZP_BYTE:5 [ main::l#2 main::l#1 ] : zp ZP_BYTE:5 , reg byte y , 

REGISTER UPLIFT SCOPES
Uplift Scope [main] 303: zp ZP_BYTE:3 [ main::j#2 main::j#1 ] 252.5: zp ZP_BYTE:5 [ main::l#2 main::l#1 ] 41.1: zp ZP_BYTE:2 [ main::i#4 main::i#1 ] 37: zp ZP_BYTE:4 [ main::k#4 main::k#1 ] 
Uplift Scope [] 

Uplifting [main] best 6638 combination reg byte a [ main::j#2 main::j#1 ] zp ZP_BYTE:5 [ main::l#2 main::l#1 ] reg byte x [ main::i#4 main::i#1 ] reg byte y [ main::k#4 main::k#1 ] 
Uplifting [] best 6638 combination 
Attempting to uplift remaining variables inzp ZP_BYTE:5 [ main::l#2 main::l#1 ]
Uplifting [main] best 6638 combination zp ZP_BYTE:5 [ main::l#2 main::l#1 ] 
Allocated (was zp ZP_BYTE:5) zp ZP_BYTE:2 [ main::l#2 main::l#1 ]

ASSEMBLER BEFORE OPTIMIZATION
//SEG0 Basic Upstart
.pc = $801 "Basic"
:BasicUpstart(main)
.pc = $80d "Program"
//SEG1 Global Constants & labels
  .label SCREEN = $400
//SEG2 @begin
bbegin:
//SEG3 [1] phi from @begin to @1 [phi:@begin->@1]
b1_from_bbegin:
  jmp b1
//SEG4 @1
b1:
//SEG5 [2] call main param-assignment [ ] ( )
//SEG6 [4] phi from @1 to main [phi:@1->main]
main_from_b1:
  jsr main
//SEG7 [3] phi from @1 to @end [phi:@1->@end]
bend_from_b1:
  jmp bend
//SEG8 @end
bend:
//SEG9 main
main: {
    .label l = 2
  //SEG10 [5] phi from main to main::@1 [phi:main->main::@1]
  b1_from_main:
  //SEG11 [5] phi (byte) main::i#4 = (byte/signed byte/word/signed word/dword/signed dword) 0 [phi:main->main::@1#0] -- vbuxx=vbuc1 
    ldx #0
    jmp b1
  //SEG12 [5] phi from main::@5 to main::@1 [phi:main::@5->main::@1]
  b1_from_b5:
  //SEG13 [5] phi (byte) main::i#4 = (byte) main::i#1 [phi:main::@5->main::@1#0] -- register_copy 
    jmp b1
  //SEG14 main::@1
  b1:
  //SEG15 [6] phi from main::@1 to main::@2 [phi:main::@1->main::@2]
  b2_from_b1:
  //SEG16 [6] phi (byte) main::j#2 = (byte/signed byte/word/signed word/dword/signed dword) 0 [phi:main::@1->main::@2#0] -- vbuaa=vbuc1 
    lda #0
    jmp b2
  //SEG17 [6] phi from main::@2 to main::@2 [phi:main::@2->main::@2]
  b2_from_b2:
  //SEG18 [6] phi (byte) main::j#2 = (byte) main::j#1 [phi:main::@2->main::@2#0] -- register_copy 
    jmp b2
  //SEG19 main::@2
  b2:
  //SEG20 [7] *((const byte*) SCREEN#0 + (byte) main::i#4) ← (byte) main::j#2 [ main::i#4 main::j#2 ] ( main:2 [ main::i#4 main::j#2 ] ) -- pbuc1_derefidx_vbuxx=vbuaa 
    sta SCREEN,x
  //SEG21 [8] (byte) main::j#1 ← ++ (byte) main::j#2 [ main::i#4 main::j#1 ] ( main:2 [ main::i#4 main::j#1 ] ) -- vbuaa=_inc_vbuaa 
    clc
    adc #1
  //SEG22 [9] if((byte) main::j#1!=(byte/signed byte/word/signed word/dword/signed dword) 101) goto main::@2 [ main::i#4 main::j#1 ] ( main:2 [ main::i#4 main::j#1 ] ) -- vbuaa_neq_vbuc1_then_la1 
    cmp #$65
    bne b2_from_b2
    jmp b5
  //SEG23 main::@5
  b5:
  //SEG24 [10] (byte) main::i#1 ← ++ (byte) main::i#4 [ main::i#1 ] ( main:2 [ main::i#1 ] ) -- vbuxx=_inc_vbuxx 
    inx
  //SEG25 [11] if((byte) main::i#1!=(byte/signed byte/word/signed word/dword/signed dword) 101) goto main::@1 [ main::i#1 ] ( main:2 [ main::i#1 ] ) -- vbuxx_neq_vbuc1_then_la1 
    cpx #$65
    bne b1_from_b5
  //SEG26 [12] phi from main::@5 to main::@3 [phi:main::@5->main::@3]
  b3_from_b5:
  //SEG27 [12] phi (byte) main::k#4 = (byte/signed byte/word/signed word/dword/signed dword) 0 [phi:main::@5->main::@3#0] -- vbuyy=vbuc1 
    ldy #0
    jmp b3
  //SEG28 [12] phi from main::@7 to main::@3 [phi:main::@7->main::@3]
  b3_from_b7:
  //SEG29 [12] phi (byte) main::k#4 = (byte) main::k#1 [phi:main::@7->main::@3#0] -- register_copy 
    jmp b3
  //SEG30 main::@3
  b3:
  //SEG31 [13] phi from main::@3 to main::@4 [phi:main::@3->main::@4]
  b4_from_b3:
  //SEG32 [13] phi (byte) main::l#2 = (byte/signed byte/word/signed word/dword/signed dword) 0 [phi:main::@3->main::@4#0] -- vbuz1=vbuc1 
    lda #0
    sta l
    jmp b4
  //SEG33 [13] phi from main::@4 to main::@4 [phi:main::@4->main::@4]
  b4_from_b4:
  //SEG34 [13] phi (byte) main::l#2 = (byte) main::l#1 [phi:main::@4->main::@4#0] -- register_copy 
    jmp b4
  //SEG35 main::@4
  b4:
  //SEG36 asm { eor#$55 tax  }
    eor #$55
    tax
  //SEG37 [15] *((const byte*) SCREEN#0 + (byte) main::k#4) ← (byte) main::l#2 [ main::k#4 main::l#2 ] ( main:2 [ main::k#4 main::l#2 ] ) -- pbuc1_derefidx_vbuyy=vbuz1 
    lda l
    sta SCREEN,y
  //SEG38 [16] (byte) main::l#1 ← ++ (byte) main::l#2 [ main::k#4 main::l#1 ] ( main:2 [ main::k#4 main::l#1 ] ) -- vbuz1=_inc_vbuz1 
    inc l
  //SEG39 [17] if((byte) main::l#1!=(byte/signed byte/word/signed word/dword/signed dword) 101) goto main::@4 [ main::k#4 main::l#1 ] ( main:2 [ main::k#4 main::l#1 ] ) -- vbuz1_neq_vbuc1_then_la1 
    lda l
    cmp #$65
    bne b4_from_b4
    jmp b7
  //SEG40 main::@7
  b7:
  //SEG41 [18] (byte) main::k#1 ← ++ (byte) main::k#4 [ main::k#1 ] ( main:2 [ main::k#1 ] ) -- vbuyy=_inc_vbuyy 
    iny
  //SEG42 [19] if((byte) main::k#1!=(byte/signed byte/word/signed word/dword/signed dword) 101) goto main::@3 [ main::k#1 ] ( main:2 [ main::k#1 ] ) -- vbuyy_neq_vbuc1_then_la1 
    cpy #$65
    bne b3_from_b7
    jmp breturn
  //SEG43 main::@return
  breturn:
  //SEG44 [20] return  [ ] ( main:2 [ ] )
    rts
}

ASSEMBLER OPTIMIZATIONS
Removing instruction jmp b1
Removing instruction jmp bend
Removing instruction jmp b1
Removing instruction jmp b2
Removing instruction jmp b5
Removing instruction jmp b3
Removing instruction jmp b4
Removing instruction jmp b7
Removing instruction jmp breturn
Succesful ASM optimization Pass5NextJumpElimination
Replacing label b2_from_b2 with b2
Replacing label b1_from_b5 with b1
Replacing label b4_from_b4 with b4
Replacing label b3_from_b7 with b3
Removing instruction bbegin:
Removing instruction b1_from_bbegin:
Removing instruction main_from_b1:
Removing instruction bend_from_b1:
Removing instruction b1_from_b5:
Removing instruction b2_from_b1:
Removing instruction b2_from_b2:
Removing instruction b3_from_b7:
Removing instruction b4_from_b3:
Removing instruction b4_from_b4:
Succesful ASM optimization Pass5RedundantLabelElimination
Removing instruction b1:
Removing instruction bend:
Removing instruction b1_from_main:
Removing instruction b5:
Removing instruction b3_from_b5:
Removing instruction b7:
Removing instruction breturn:
Succesful ASM optimization Pass5UnusedLabelElimination
Removing instruction jmp b1
Removing instruction jmp b2
Removing instruction jmp b3
Removing instruction jmp b4
Succesful ASM optimization Pass5NextJumpElimination

FINAL SYMBOL TABLE
(label) @1
(label) @begin
(label) @end
(byte*) SCREEN
(const byte*) SCREEN#0 SCREEN = ((byte*))(word/signed word/dword/signed dword) 1024
(void()) main()
(label) main::@1
(label) main::@2
(label) main::@3
(label) main::@4
(label) main::@5
(label) main::@7
(label) main::@return
(byte) main::i
(byte) main::i#1 reg byte x 16.5
(byte) main::i#4 reg byte x 24.599999999999998
(byte) main::j
(byte) main::j#1 reg byte a 151.5
(byte) main::j#2 reg byte a 151.5
(byte) main::k
(byte) main::k#1 reg byte y 16.5
(byte) main::k#4 reg byte y 20.499999999999996
(byte) main::l
(byte) main::l#1 l zp ZP_BYTE:2 151.5
(byte) main::l#2 l zp ZP_BYTE:2 101.0

reg byte x [ main::i#4 main::i#1 ]
reg byte a [ main::j#2 main::j#1 ]
reg byte y [ main::k#4 main::k#1 ]
zp ZP_BYTE:2 [ main::l#2 main::l#1 ]


FINAL ASSEMBLER
Score: 4682

//SEG0 Basic Upstart
.pc = $801 "Basic"
:BasicUpstart(main)
.pc = $80d "Program"
//SEG1 Global Constants & labels
  .label SCREEN = $400
//SEG2 @begin
//SEG3 [1] phi from @begin to @1 [phi:@begin->@1]
//SEG4 @1
//SEG5 [2] call main param-assignment [ ] ( )
//SEG6 [4] phi from @1 to main [phi:@1->main]
  jsr main
//SEG7 [3] phi from @1 to @end [phi:@1->@end]
//SEG8 @end
//SEG9 main
main: {
    .label l = 2
  //SEG10 [5] phi from main to main::@1 [phi:main->main::@1]
  //SEG11 [5] phi (byte) main::i#4 = (byte/signed byte/word/signed word/dword/signed dword) 0 [phi:main->main::@1#0] -- vbuxx=vbuc1 
    ldx #0
  //SEG12 [5] phi from main::@5 to main::@1 [phi:main::@5->main::@1]
  //SEG13 [5] phi (byte) main::i#4 = (byte) main::i#1 [phi:main::@5->main::@1#0] -- register_copy 
  //SEG14 main::@1
  b1:
  //SEG15 [6] phi from main::@1 to main::@2 [phi:main::@1->main::@2]
  //SEG16 [6] phi (byte) main::j#2 = (byte/signed byte/word/signed word/dword/signed dword) 0 [phi:main::@1->main::@2#0] -- vbuaa=vbuc1 
    lda #0
  //SEG17 [6] phi from main::@2 to main::@2 [phi:main::@2->main::@2]
  //SEG18 [6] phi (byte) main::j#2 = (byte) main::j#1 [phi:main::@2->main::@2#0] -- register_copy 
  //SEG19 main::@2
  b2:
  //SEG20 [7] *((const byte*) SCREEN#0 + (byte) main::i#4) ← (byte) main::j#2 [ main::i#4 main::j#2 ] ( main:2 [ main::i#4 main::j#2 ] ) -- pbuc1_derefidx_vbuxx=vbuaa 
    sta SCREEN,x
  //SEG21 [8] (byte) main::j#1 ← ++ (byte) main::j#2 [ main::i#4 main::j#1 ] ( main:2 [ main::i#4 main::j#1 ] ) -- vbuaa=_inc_vbuaa 
    clc
    adc #1
  //SEG22 [9] if((byte) main::j#1!=(byte/signed byte/word/signed word/dword/signed dword) 101) goto main::@2 [ main::i#4 main::j#1 ] ( main:2 [ main::i#4 main::j#1 ] ) -- vbuaa_neq_vbuc1_then_la1 
    cmp #$65
    bne b2
  //SEG23 main::@5
  //SEG24 [10] (byte) main::i#1 ← ++ (byte) main::i#4 [ main::i#1 ] ( main:2 [ main::i#1 ] ) -- vbuxx=_inc_vbuxx 
    inx
  //SEG25 [11] if((byte) main::i#1!=(byte/signed byte/word/signed word/dword/signed dword) 101) goto main::@1 [ main::i#1 ] ( main:2 [ main::i#1 ] ) -- vbuxx_neq_vbuc1_then_la1 
    cpx #$65
    bne b1
  //SEG26 [12] phi from main::@5 to main::@3 [phi:main::@5->main::@3]
  //SEG27 [12] phi (byte) main::k#4 = (byte/signed byte/word/signed word/dword/signed dword) 0 [phi:main::@5->main::@3#0] -- vbuyy=vbuc1 
    ldy #0
  //SEG28 [12] phi from main::@7 to main::@3 [phi:main::@7->main::@3]
  //SEG29 [12] phi (byte) main::k#4 = (byte) main::k#1 [phi:main::@7->main::@3#0] -- register_copy 
  //SEG30 main::@3
  b3:
  //SEG31 [13] phi from main::@3 to main::@4 [phi:main::@3->main::@4]
  //SEG32 [13] phi (byte) main::l#2 = (byte/signed byte/word/signed word/dword/signed dword) 0 [phi:main::@3->main::@4#0] -- vbuz1=vbuc1 
    lda #0
    sta l
  //SEG33 [13] phi from main::@4 to main::@4 [phi:main::@4->main::@4]
  //SEG34 [13] phi (byte) main::l#2 = (byte) main::l#1 [phi:main::@4->main::@4#0] -- register_copy 
  //SEG35 main::@4
  b4:
  //SEG36 asm { eor#$55 tax  }
    eor #$55
    tax
  //SEG37 [15] *((const byte*) SCREEN#0 + (byte) main::k#4) ← (byte) main::l#2 [ main::k#4 main::l#2 ] ( main:2 [ main::k#4 main::l#2 ] ) -- pbuc1_derefidx_vbuyy=vbuz1 
    lda l
    sta SCREEN,y
  //SEG38 [16] (byte) main::l#1 ← ++ (byte) main::l#2 [ main::k#4 main::l#1 ] ( main:2 [ main::k#4 main::l#1 ] ) -- vbuz1=_inc_vbuz1 
    inc l
  //SEG39 [17] if((byte) main::l#1!=(byte/signed byte/word/signed word/dword/signed dword) 101) goto main::@4 [ main::k#4 main::l#1 ] ( main:2 [ main::k#4 main::l#1 ] ) -- vbuz1_neq_vbuc1_then_la1 
    lda l
    cmp #$65
    bne b4
  //SEG40 main::@7
  //SEG41 [18] (byte) main::k#1 ← ++ (byte) main::k#4 [ main::k#1 ] ( main:2 [ main::k#1 ] ) -- vbuyy=_inc_vbuyy 
    iny
  //SEG42 [19] if((byte) main::k#1!=(byte/signed byte/word/signed word/dword/signed dword) 101) goto main::@3 [ main::k#1 ] ( main:2 [ main::k#1 ] ) -- vbuyy_neq_vbuc1_then_la1 
    cpy #$65
    bne b3
  //SEG43 main::@return
  //SEG44 [20] return  [ ] ( main:2 [ ] )
    rts
}

