Resolved forward reference irq to interrupt(KERNEL_MIN)(void()) irq()
Culled Empty Block (label) main::@11
Culled Empty Block (label) main::@3
Culled Empty Block (label) main::@12
Culled Empty Block (label) main::@9
Culled Empty Block (label) main::@10
Culled Empty Block (label) @1

CONTROL FLOW GRAPH SSA
@begin: scope:[]  from
  (void()**) KERNEL_IRQ#0 ← ((void()**)) (number) $314
  (byte*) IRQ_STATUS#0 ← ((byte*)) (number) $d019
  (byte*) SCREEN#0 ← ((byte*)) (number) $400
  (byte) col1#0 ← (number) 0
  to:@2
main: scope:[main]  from @2
  (void()*~) main::$0 ← & interrupt(KERNEL_MIN)(void()) irq()
  *((void()**) KERNEL_IRQ#0) ← (void()*~) main::$0
  to:main::@1
main::@1: scope:[main]  from main main::@8
  if(true) goto main::@2
  to:main::@return
main::@2: scope:[main]  from main::@1
  (byte) main::x#0 ← (byte) 0
  to:main::@4
main::@4: scope:[main]  from main::@2 main::@8
  (byte) main::x#6 ← phi( main::@2/(byte) main::x#0 main::@8/(byte) main::x#1 )
  (byte) main::y#0 ← (byte) 0
  to:main::@5
main::@5: scope:[main]  from main::@4 main::@7
  (byte) main::x#4 ← phi( main::@4/(byte) main::x#6 main::@7/(byte) main::x#5 )
  (byte) main::y#4 ← phi( main::@4/(byte) main::y#0 main::@7/(byte) main::y#1 )
  (byte) main::a#0 ← (byte) 0
  to:main::@6
main::@6: scope:[main]  from main::@5 main::@6
  (byte) main::x#2 ← phi( main::@5/(byte) main::x#4 main::@6/(byte) main::x#2 )
  (byte) main::y#2 ← phi( main::@5/(byte) main::y#4 main::@6/(byte) main::y#2 )
  (byte) main::a#2 ← phi( main::@5/(byte) main::a#0 main::@6/(byte) main::a#1 )
  (byte~) main::$1 ← (byte) main::a#2 + (byte) main::y#2
  *((byte*) SCREEN#0 + (byte) main::x#2) ← (byte~) main::$1
  (byte) main::a#1 ← (byte) main::a#2 + rangenext(0,$a)
  (bool~) main::$2 ← (byte) main::a#1 != rangelast(0,$a)
  if((bool~) main::$2) goto main::@6
  to:main::@7
main::@7: scope:[main]  from main::@6
  (byte) main::x#5 ← phi( main::@6/(byte) main::x#2 )
  (byte) main::y#3 ← phi( main::@6/(byte) main::y#2 )
  (byte) main::y#1 ← (byte) main::y#3 + rangenext(0,$a)
  (bool~) main::$3 ← (byte) main::y#1 != rangelast(0,$a)
  if((bool~) main::$3) goto main::@5
  to:main::@8
main::@8: scope:[main]  from main::@7
  (byte) main::x#3 ← phi( main::@7/(byte) main::x#5 )
  (byte) main::x#1 ← (byte) main::x#3 + rangenext(0,$a)
  (bool~) main::$4 ← (byte) main::x#1 != rangelast(0,$a)
  if((bool~) main::$4) goto main::@4
  to:main::@1
main::@return: scope:[main]  from main::@1
  return 
  to:@return
irq: scope:[irq]  from
  (byte) col1#3 ← phi( @2/(byte) col1#5 )
  *((byte*) IRQ_STATUS#0) ← (number) 1
  asm { lda$dc0d  }
  *((byte*) SCREEN#0 + (number) $28) ← (byte) col1#3
  (byte) col1#1 ← ++ (byte) col1#3
  to:irq::@return
irq::@return: scope:[irq]  from irq
  (byte) col1#4 ← phi( irq/(byte) col1#1 )
  (byte) col1#2 ← (byte) col1#4
  return 
  to:@return
@2: scope:[]  from @begin
  (byte) col1#5 ← phi( @begin/(byte) col1#0 )
  call main 
  to:@3
@3: scope:[]  from @2
  to:@end
@end: scope:[]  from @3

SYMBOL TABLE SSA
(label) @2
(label) @3
(label) @begin
(label) @end
(byte*) IRQ_STATUS
(byte*) IRQ_STATUS#0
(void()**) KERNEL_IRQ
(void()**) KERNEL_IRQ#0
(byte*) SCREEN
(byte*) SCREEN#0
(byte) col1
(byte) col1#0
(byte) col1#1
(byte) col1#2
(byte) col1#3
(byte) col1#4
(byte) col1#5
interrupt(KERNEL_MIN)(void()) irq()
(label) irq::@return
(void()) main()
(void()*~) main::$0
(byte~) main::$1
(bool~) main::$2
(bool~) main::$3
(bool~) main::$4
(label) main::@1
(label) main::@2
(label) main::@4
(label) main::@5
(label) main::@6
(label) main::@7
(label) main::@8
(label) main::@return
(byte) main::a
(byte) main::a#0
(byte) main::a#1
(byte) main::a#2
(byte) main::x
(byte) main::x#0
(byte) main::x#1
(byte) main::x#2
(byte) main::x#3
(byte) main::x#4
(byte) main::x#5
(byte) main::x#6
(byte) main::y
(byte) main::y#0
(byte) main::y#1
(byte) main::y#2
(byte) main::y#3
(byte) main::y#4

Adding number conversion cast (unumber) 0 in (byte) col1#0 ← (number) 0
Adding number conversion cast (unumber) 1 in *((byte*) IRQ_STATUS#0) ← (number) 1
Adding number conversion cast (unumber) $28 in *((byte*) SCREEN#0 + (number) $28) ← (byte) col1#3
Successful SSA optimization PassNAddNumberTypeConversions
Inlining cast (void()**) KERNEL_IRQ#0 ← (void()**)(number) $314
Inlining cast (byte*) IRQ_STATUS#0 ← (byte*)(number) $d019
Inlining cast (byte*) SCREEN#0 ← (byte*)(number) $400
Inlining cast (byte) col1#0 ← (unumber)(number) 0
Inlining cast *((byte*) IRQ_STATUS#0) ← (unumber)(number) 1
Successful SSA optimization Pass2InlineCast
Simplifying constant pointer cast (void()**) 788
Simplifying constant pointer cast (byte*) 53273
Simplifying constant pointer cast (byte*) 1024
Simplifying constant integer cast 0
Simplifying constant integer cast 1
Simplifying constant integer cast $28
Successful SSA optimization PassNCastSimplification
Finalized unsigned number type (byte) 0
Finalized unsigned number type (byte) 1
Finalized unsigned number type (byte) $28
Successful SSA optimization PassNFinalizeNumberTypeConversions
Alias (byte) main::y#2 = (byte) main::y#3 
Alias (byte) main::x#2 = (byte) main::x#5 (byte) main::x#3 
Alias (byte) col1#1 = (byte) col1#4 (byte) col1#2 
Alias (byte) col1#0 = (byte) col1#5 
Successful SSA optimization Pass2AliasElimination
Self Phi Eliminated (byte) main::y#2
Self Phi Eliminated (byte) main::x#2
Successful SSA optimization Pass2SelfPhiElimination
Identical Phi Values (byte) main::y#2 (byte) main::y#4
Identical Phi Values (byte) main::x#2 (byte) main::x#4
Identical Phi Values (byte) col1#3 (byte) col1#0
Successful SSA optimization Pass2IdenticalPhiElimination
Simple Condition (bool~) main::$2 [17] if((byte) main::a#1!=rangelast(0,$a)) goto main::@6
Simple Condition (bool~) main::$3 [21] if((byte) main::y#1!=rangelast(0,$a)) goto main::@5
Simple Condition (bool~) main::$4 [25] if((byte) main::x#1!=rangelast(0,$a)) goto main::@4
Successful SSA optimization Pass2ConditionalJumpSimplification
Constant right-side identified [4] (void()*~) main::$0 ← & interrupt(KERNEL_MIN)(void()) irq()
Successful SSA optimization Pass2ConstantRValueConsolidation
Constant (const void()**) KERNEL_IRQ#0 = (void()**) 788
Constant (const byte*) IRQ_STATUS#0 = (byte*) 53273
Constant (const byte*) SCREEN#0 = (byte*) 1024
Constant (const void()*) main::$0 = &irq
Constant (const byte) main::x#0 = 0
Constant (const byte) main::y#0 = 0
Constant (const byte) main::a#0 = 0
Successful SSA optimization Pass2ConstantIdentification
if() condition always true - replacing block destination [6] if(true) goto main::@2
Successful SSA optimization Pass2ConstantIfs
Resolved ranged next value [15] main::a#1 ← ++ main::a#2 to ++
Resolved ranged comparison value [17] if(main::a#1!=rangelast(0,$a)) goto main::@6 to (number) $b
Resolved ranged next value [19] main::y#1 ← ++ main::y#4 to ++
Resolved ranged comparison value [21] if(main::y#1!=rangelast(0,$a)) goto main::@5 to (number) $b
Resolved ranged next value [23] main::x#1 ← ++ main::x#4 to ++
Resolved ranged comparison value [25] if(main::x#1!=rangelast(0,$a)) goto main::@4 to (number) $b
Removing unused block main::@return
Successful SSA optimization Pass2EliminateUnusedBlocks
Adding number conversion cast (unumber) $b in if((byte) main::a#1!=(number) $b) goto main::@6
Adding number conversion cast (unumber) $b in if((byte) main::y#1!=(number) $b) goto main::@5
Adding number conversion cast (unumber) $b in if((byte) main::x#1!=(number) $b) goto main::@4
Successful SSA optimization PassNAddNumberTypeConversions
Simplifying constant integer cast $b
Simplifying constant integer cast $b
Simplifying constant integer cast $b
Successful SSA optimization PassNCastSimplification
Finalized unsigned number type (byte) $b
Finalized unsigned number type (byte) $b
Finalized unsigned number type (byte) $b
Successful SSA optimization PassNFinalizeNumberTypeConversions
Self Phi Eliminated (byte) main::x#4
Successful SSA optimization Pass2SelfPhiElimination
Identical Phi Values (byte) main::x#4 (byte) main::x#6
Successful SSA optimization Pass2IdenticalPhiElimination
Inlining constant with var siblings (const byte) main::x#0
Inlining constant with var siblings (const byte) main::y#0
Inlining constant with var siblings (const byte) main::a#0
Constant inlined main::a#0 = (byte) 0
Constant inlined main::x#0 = (byte) 0
Constant inlined main::y#0 = (byte) 0
Constant inlined main::$0 = &interrupt(KERNEL_MIN)(void()) irq()
Successful SSA optimization Pass2ConstantInlining
Consolidated array index constant in *(SCREEN#0+$28)
Successful SSA optimization Pass2ConstantAdditionElimination
Added new block during phi lifting main::@13(between main::@8 and main::@4)
Added new block during phi lifting main::@14(between main::@7 and main::@5)
Added new block during phi lifting main::@15(between main::@6 and main::@6)
Adding NOP phi() at start of @2
Adding NOP phi() at start of @3
Adding NOP phi() at start of @end
Adding NOP phi() at start of main::@1
Adding NOP phi() at start of main::@2
CALL GRAPH
Calls in [] to main:2 

Created 3 initial phi equivalence classes
Coalesced [19] main::x#7 ← main::x#1
Coalesced [20] main::y#5 ← main::y#1
Coalesced [21] main::a#3 ← main::a#1
Coalesced down to 3 phi equivalence classes
Culled Empty Block (label) @3
Culled Empty Block (label) main::@1
Culled Empty Block (label) main::@2
Culled Empty Block (label) main::@14
Culled Empty Block (label) main::@15
Renumbering block @2 to @1
Renumbering block main::@4 to main::@1
Renumbering block main::@5 to main::@2
Renumbering block main::@6 to main::@3
Renumbering block main::@7 to main::@4
Renumbering block main::@8 to main::@5
Renumbering block main::@13 to main::@6
Adding NOP phi() at start of @1
Adding NOP phi() at start of @end
Adding NOP phi() at start of main::@6

FINAL CONTROL FLOW GRAPH
@begin: scope:[]  from
  [0] (byte) col1#0 ← (byte) 0
  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] *((const void()**) KERNEL_IRQ#0) ← &interrupt(KERNEL_MIN)(void()) irq()
  to:main::@1
main::@1: scope:[main]  from main main::@5 main::@6
  [5] (byte) main::x#6 ← phi( main/(byte) 0 main::@6/(byte) main::x#1 main::@5/(byte) 0 )
  to:main::@2
main::@2: scope:[main]  from main::@1 main::@4
  [6] (byte) main::y#4 ← phi( main::@1/(byte) 0 main::@4/(byte) main::y#1 )
  to:main::@3
main::@3: scope:[main]  from main::@2 main::@3
  [7] (byte) main::a#2 ← phi( main::@2/(byte) 0 main::@3/(byte) main::a#1 )
  [8] (byte~) main::$1 ← (byte) main::a#2 + (byte) main::y#4
  [9] *((const byte*) SCREEN#0 + (byte) main::x#6) ← (byte~) main::$1
  [10] (byte) main::a#1 ← ++ (byte) main::a#2
  [11] if((byte) main::a#1!=(byte) $b) goto main::@3
  to:main::@4
main::@4: scope:[main]  from main::@3
  [12] (byte) main::y#1 ← ++ (byte) main::y#4
  [13] if((byte) main::y#1!=(byte) $b) goto main::@2
  to:main::@5
main::@5: scope:[main]  from main::@4
  [14] (byte) main::x#1 ← ++ (byte) main::x#6
  [15] if((byte) main::x#1!=(byte) $b) goto main::@6
  to:main::@1
main::@6: scope:[main]  from main::@5
  [16] phi()
  to:main::@1
irq: scope:[irq]  from
  [17] *((const byte*) IRQ_STATUS#0) ← (byte) 1
  asm { lda$dc0d  }
  [19] *((const byte*) SCREEN#0+(byte) $28) ← (byte) col1#0
  [20] (byte) col1#1 ← ++ (byte) col1#0
  to:irq::@return
irq::@return: scope:[irq]  from irq
  [21] return 
  to:@return


VARIABLE REGISTER WEIGHTS
(byte*) IRQ_STATUS
(void()**) KERNEL_IRQ
(byte*) SCREEN
(byte) col1
(byte) col1#0 2.0
(byte) col1#1 20.0
interrupt(KERNEL_MIN)(void()) irq()
(void()) main()
(byte~) main::$1 20002.0
(byte) main::a
(byte) main::a#1 15001.5
(byte) main::a#2 10001.0
(byte) main::x
(byte) main::x#1 71.0
(byte) main::x#6 1123.6666666666665
(byte) main::y
(byte) main::y#1 1501.5
(byte) main::y#4 2000.4999999999998

Initial phi equivalence classes
[ main::x#6 main::x#1 ]
[ main::y#4 main::y#1 ]
[ main::a#2 main::a#1 ]
Coalescing volatile variable equivalence classes [ col1#0 ] and [ col1#1 ]
Added variable main::$1 to zero page equivalence class [ main::$1 ]
Complete equivalence classes
[ main::x#6 main::x#1 ]
[ main::y#4 main::y#1 ]
[ main::a#2 main::a#1 ]
[ col1#0 col1#1 ]
[ main::$1 ]
Allocated zp ZP_BYTE:2 [ main::x#6 main::x#1 ]
Allocated zp ZP_BYTE:3 [ main::y#4 main::y#1 ]
Allocated zp ZP_BYTE:4 [ main::a#2 main::a#1 ]
Allocated zp ZP_BYTE:5 [ col1#0 col1#1 ]
Allocated zp ZP_BYTE:6 [ main::$1 ]

INITIAL ASM
  // File Comments
// Illustrates problem where volatiles reuse ZP addresses of other variables
  // Basic Upstart
.pc = $801 "Basic"
:BasicUpstart(bbegin)
.pc = $80d "Program"
  // Global Constants & labels
  .label KERNEL_IRQ = $314
  .label IRQ_STATUS = $d019
  .label SCREEN = $400
  .label col1 = 5
  // @begin
bbegin:
  // [0] (byte) col1#0 ← (byte) 0 -- vbuz1=vbuc1 
  lda #0
  sta col1
  // [1] phi from @begin to @1 [phi:@begin->@1]
b1_from_bbegin:
  jmp b1
  // @1
b1:
  // [2] call main 
  jsr main
  // [3] phi from @1 to @end [phi:@1->@end]
bend_from_b1:
  jmp bend
  // @end
bend:
  // main
main: {
    .label _1 = 6
    .label a = 4
    .label y = 3
    .label x = 2
    // [4] *((const void()**) KERNEL_IRQ#0) ← &interrupt(KERNEL_MIN)(void()) irq() -- _deref_pptc1=pprc2 
    lda #<irq
    sta KERNEL_IRQ
    lda #>irq
    sta KERNEL_IRQ+1
    // [5] phi from main main::@5 to main::@1 [phi:main/main::@5->main::@1]
  b1_from_main:
  b1_from_b5:
    // [5] phi (byte) main::x#6 = (byte) 0 [phi:main/main::@5->main::@1#0] -- vbuz1=vbuc1 
    lda #0
    sta x
    jmp b1
    // main::@1
  b1:
    // [6] phi from main::@1 to main::@2 [phi:main::@1->main::@2]
  b2_from_b1:
    // [6] phi (byte) main::y#4 = (byte) 0 [phi:main::@1->main::@2#0] -- vbuz1=vbuc1 
    lda #0
    sta y
    jmp b2
    // [6] phi from main::@4 to main::@2 [phi:main::@4->main::@2]
  b2_from_b4:
    // [6] phi (byte) main::y#4 = (byte) main::y#1 [phi:main::@4->main::@2#0] -- register_copy 
    jmp b2
    // main::@2
  b2:
    // [7] phi from main::@2 to main::@3 [phi:main::@2->main::@3]
  b3_from_b2:
    // [7] phi (byte) main::a#2 = (byte) 0 [phi:main::@2->main::@3#0] -- vbuz1=vbuc1 
    lda #0
    sta a
    jmp b3
    // [7] phi from main::@3 to main::@3 [phi:main::@3->main::@3]
  b3_from_b3:
    // [7] phi (byte) main::a#2 = (byte) main::a#1 [phi:main::@3->main::@3#0] -- register_copy 
    jmp b3
    // main::@3
  b3:
    // [8] (byte~) main::$1 ← (byte) main::a#2 + (byte) main::y#4 -- vbuz1=vbuz2_plus_vbuz3 
    lda a
    clc
    adc y
    sta _1
    // [9] *((const byte*) SCREEN#0 + (byte) main::x#6) ← (byte~) main::$1 -- pbuc1_derefidx_vbuz1=vbuz2 
    lda _1
    ldy x
    sta SCREEN,y
    // [10] (byte) main::a#1 ← ++ (byte) main::a#2 -- vbuz1=_inc_vbuz1 
    inc a
    // [11] if((byte) main::a#1!=(byte) $b) goto main::@3 -- vbuz1_neq_vbuc1_then_la1 
    lda #$b
    cmp a
    bne b3_from_b3
    jmp b4
    // main::@4
  b4:
    // [12] (byte) main::y#1 ← ++ (byte) main::y#4 -- vbuz1=_inc_vbuz1 
    inc y
    // [13] if((byte) main::y#1!=(byte) $b) goto main::@2 -- vbuz1_neq_vbuc1_then_la1 
    lda #$b
    cmp y
    bne b2_from_b4
    jmp b5
    // main::@5
  b5:
    // [14] (byte) main::x#1 ← ++ (byte) main::x#6 -- vbuz1=_inc_vbuz1 
    inc x
    // [15] if((byte) main::x#1!=(byte) $b) goto main::@6 -- vbuz1_neq_vbuc1_then_la1 
    lda #$b
    cmp x
    bne b6_from_b5
    jmp b1_from_b5
    // [16] phi from main::@5 to main::@6 [phi:main::@5->main::@6]
  b6_from_b5:
    jmp b6
    // main::@6
  b6:
    // [5] phi from main::@6 to main::@1 [phi:main::@6->main::@1]
  b1_from_b6:
    // [5] phi (byte) main::x#6 = (byte) main::x#1 [phi:main::@6->main::@1#0] -- register_copy 
    jmp b1
}
  // irq
irq: {
    // entry interrupt(KERNEL_MIN)
    // [17] *((const byte*) IRQ_STATUS#0) ← (byte) 1 -- _deref_pbuc1=vbuc2 
    // Acknowledge the IRQ
    lda #1
    sta IRQ_STATUS
    // asm { lda$dc0d  }
    lda $dc0d
    // [19] *((const byte*) SCREEN#0+(byte) $28) ← (byte) col1#0 -- _deref_pbuc1=vbuz1 
    lda col1
    sta SCREEN+$28
    // [20] (byte) col1#1 ← ++ (byte) col1#0 -- vbuz1=_inc_vbuz1 
    inc col1
    jmp breturn
    // irq::@return
  breturn:
    // [21] return  - exit interrupt(KERNEL_MIN)
    jmp $ea81
}
  // File Data

REGISTER UPLIFT POTENTIAL REGISTERS
Statement [0] (byte) col1#0 ← (byte) 0 [ ] (  [ ] ) always clobbers reg byte a 
Statement [4] *((const void()**) KERNEL_IRQ#0) ← &interrupt(KERNEL_MIN)(void()) irq() [ ] ( main:2 [ ] ) always clobbers reg byte a 
Statement [8] (byte~) main::$1 ← (byte) main::a#2 + (byte) main::y#4 [ main::x#6 main::y#4 main::a#2 main::$1 ] ( main:2 [ main::x#6 main::y#4 main::a#2 main::$1 ] ) always clobbers reg byte a 
Removing always clobbered register reg byte a as potential for zp ZP_BYTE:2 [ main::x#6 main::x#1 ]
Removing always clobbered register reg byte a as potential for zp ZP_BYTE:3 [ main::y#4 main::y#1 ]
Removing always clobbered register reg byte a as potential for zp ZP_BYTE:4 [ main::a#2 main::a#1 ]
Statement [17] *((const byte*) IRQ_STATUS#0) ← (byte) 1 [ col1#0 ] (  [ col1#0 ] ) always clobbers reg byte a 
Statement asm { lda$dc0d  } always clobbers reg byte a 
Statement [19] *((const byte*) SCREEN#0+(byte) $28) ← (byte) col1#0 [ col1#0 ] (  [ col1#0 ] ) always clobbers reg byte a 
Statement [0] (byte) col1#0 ← (byte) 0 [ ] (  [ ] ) always clobbers reg byte a 
Statement [4] *((const void()**) KERNEL_IRQ#0) ← &interrupt(KERNEL_MIN)(void()) irq() [ ] ( main:2 [ ] ) always clobbers reg byte a 
Statement [8] (byte~) main::$1 ← (byte) main::a#2 + (byte) main::y#4 [ main::x#6 main::y#4 main::a#2 main::$1 ] ( main:2 [ main::x#6 main::y#4 main::a#2 main::$1 ] ) always clobbers reg byte a 
Statement [17] *((const byte*) IRQ_STATUS#0) ← (byte) 1 [ col1#0 ] (  [ col1#0 ] ) always clobbers reg byte a 
Statement asm { lda$dc0d  } always clobbers reg byte a 
Statement [19] *((const byte*) SCREEN#0+(byte) $28) ← (byte) col1#0 [ col1#0 ] (  [ col1#0 ] ) always clobbers reg byte a 
Potential registers zp ZP_BYTE:2 [ main::x#6 main::x#1 ] : zp ZP_BYTE:2 , reg byte x , reg byte y , 
Potential registers zp ZP_BYTE:3 [ main::y#4 main::y#1 ] : zp ZP_BYTE:3 , reg byte x , reg byte y , 
Potential registers zp ZP_BYTE:4 [ main::a#2 main::a#1 ] : zp ZP_BYTE:4 , reg byte x , reg byte y , 
Potential registers zp ZP_BYTE:5 [ col1#0 col1#1 ] : zp ZP_BYTE:5 , 
Potential registers zp ZP_BYTE:6 [ main::$1 ] : zp ZP_BYTE:6 , reg byte a , reg byte x , reg byte y , 

REGISTER UPLIFT SCOPES
Uplift Scope [main] 25,002.5: zp ZP_BYTE:4 [ main::a#2 main::a#1 ] 20,002: zp ZP_BYTE:6 [ main::$1 ] 3,502: zp ZP_BYTE:3 [ main::y#4 main::y#1 ] 1,194.67: zp ZP_BYTE:2 [ main::x#6 main::x#1 ] 
Uplift Scope [] 22: zp ZP_BYTE:5 [ col1#0 col1#1 ] 
Uplift Scope [irq] 

Uplifting [main] best 323337 combination reg byte y [ main::a#2 main::a#1 ] reg byte a [ main::$1 ] zp ZP_BYTE:3 [ main::y#4 main::y#1 ] reg byte x [ main::x#6 main::x#1 ] 
Limited combination testing to 100 combinations of 108 possible.
Uplifting [] best 323337 combination zp ZP_BYTE:5 [ col1#0 col1#1 ] 
Uplifting [irq] best 323337 combination 
Attempting to uplift remaining variables inzp ZP_BYTE:3 [ main::y#4 main::y#1 ]
Uplifting [main] best 323337 combination zp ZP_BYTE:3 [ main::y#4 main::y#1 ] 
Attempting to uplift remaining variables inzp ZP_BYTE:5 [ col1#0 col1#1 ]
Uplifting [] best 323337 combination zp ZP_BYTE:5 [ col1#0 col1#1 ] 
Allocated (was zp ZP_BYTE:3) zp ZP_BYTE:2 [ main::y#4 main::y#1 ]
Allocated (was zp ZP_BYTE:5) zp ZP_BYTE:3 [ col1#0 col1#1 ]

ASSEMBLER BEFORE OPTIMIZATION
  // File Comments
// Illustrates problem where volatiles reuse ZP addresses of other variables
  // Basic Upstart
.pc = $801 "Basic"
:BasicUpstart(bbegin)
.pc = $80d "Program"
  // Global Constants & labels
  .label KERNEL_IRQ = $314
  .label IRQ_STATUS = $d019
  .label SCREEN = $400
  .label col1 = 3
  // @begin
bbegin:
  // [0] (byte) col1#0 ← (byte) 0 -- vbuz1=vbuc1 
  lda #0
  sta col1
  // [1] phi from @begin to @1 [phi:@begin->@1]
b1_from_bbegin:
  jmp b1
  // @1
b1:
  // [2] call main 
  jsr main
  // [3] phi from @1 to @end [phi:@1->@end]
bend_from_b1:
  jmp bend
  // @end
bend:
  // main
main: {
    .label y = 2
    // [4] *((const void()**) KERNEL_IRQ#0) ← &interrupt(KERNEL_MIN)(void()) irq() -- _deref_pptc1=pprc2 
    lda #<irq
    sta KERNEL_IRQ
    lda #>irq
    sta KERNEL_IRQ+1
    // [5] phi from main main::@5 to main::@1 [phi:main/main::@5->main::@1]
  b1_from_main:
  b1_from_b5:
    // [5] phi (byte) main::x#6 = (byte) 0 [phi:main/main::@5->main::@1#0] -- vbuxx=vbuc1 
    ldx #0
    jmp b1
    // main::@1
  b1:
    // [6] phi from main::@1 to main::@2 [phi:main::@1->main::@2]
  b2_from_b1:
    // [6] phi (byte) main::y#4 = (byte) 0 [phi:main::@1->main::@2#0] -- vbuz1=vbuc1 
    lda #0
    sta y
    jmp b2
    // [6] phi from main::@4 to main::@2 [phi:main::@4->main::@2]
  b2_from_b4:
    // [6] phi (byte) main::y#4 = (byte) main::y#1 [phi:main::@4->main::@2#0] -- register_copy 
    jmp b2
    // main::@2
  b2:
    // [7] phi from main::@2 to main::@3 [phi:main::@2->main::@3]
  b3_from_b2:
    // [7] phi (byte) main::a#2 = (byte) 0 [phi:main::@2->main::@3#0] -- vbuyy=vbuc1 
    ldy #0
    jmp b3
    // [7] phi from main::@3 to main::@3 [phi:main::@3->main::@3]
  b3_from_b3:
    // [7] phi (byte) main::a#2 = (byte) main::a#1 [phi:main::@3->main::@3#0] -- register_copy 
    jmp b3
    // main::@3
  b3:
    // [8] (byte~) main::$1 ← (byte) main::a#2 + (byte) main::y#4 -- vbuaa=vbuyy_plus_vbuz1 
    tya
    clc
    adc y
    // [9] *((const byte*) SCREEN#0 + (byte) main::x#6) ← (byte~) main::$1 -- pbuc1_derefidx_vbuxx=vbuaa 
    sta SCREEN,x
    // [10] (byte) main::a#1 ← ++ (byte) main::a#2 -- vbuyy=_inc_vbuyy 
    iny
    // [11] if((byte) main::a#1!=(byte) $b) goto main::@3 -- vbuyy_neq_vbuc1_then_la1 
    cpy #$b
    bne b3_from_b3
    jmp b4
    // main::@4
  b4:
    // [12] (byte) main::y#1 ← ++ (byte) main::y#4 -- vbuz1=_inc_vbuz1 
    inc y
    // [13] if((byte) main::y#1!=(byte) $b) goto main::@2 -- vbuz1_neq_vbuc1_then_la1 
    lda #$b
    cmp y
    bne b2_from_b4
    jmp b5
    // main::@5
  b5:
    // [14] (byte) main::x#1 ← ++ (byte) main::x#6 -- vbuxx=_inc_vbuxx 
    inx
    // [15] if((byte) main::x#1!=(byte) $b) goto main::@6 -- vbuxx_neq_vbuc1_then_la1 
    cpx #$b
    bne b6_from_b5
    jmp b1_from_b5
    // [16] phi from main::@5 to main::@6 [phi:main::@5->main::@6]
  b6_from_b5:
    jmp b6
    // main::@6
  b6:
    // [5] phi from main::@6 to main::@1 [phi:main::@6->main::@1]
  b1_from_b6:
    // [5] phi (byte) main::x#6 = (byte) main::x#1 [phi:main::@6->main::@1#0] -- register_copy 
    jmp b1
}
  // irq
irq: {
    // entry interrupt(KERNEL_MIN)
    // [17] *((const byte*) IRQ_STATUS#0) ← (byte) 1 -- _deref_pbuc1=vbuc2 
    // Acknowledge the IRQ
    lda #1
    sta IRQ_STATUS
    // asm { lda$dc0d  }
    lda $dc0d
    // [19] *((const byte*) SCREEN#0+(byte) $28) ← (byte) col1#0 -- _deref_pbuc1=vbuz1 
    lda col1
    sta SCREEN+$28
    // [20] (byte) col1#1 ← ++ (byte) col1#0 -- vbuz1=_inc_vbuz1 
    inc col1
    jmp breturn
    // irq::@return
  breturn:
    // [21] return  - exit interrupt(KERNEL_MIN)
    jmp $ea81
}
  // File Data

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 b4
Removing instruction jmp b5
Removing instruction jmp b6
Removing instruction jmp breturn
Succesful ASM optimization Pass5NextJumpElimination
Replacing label b3_from_b3 with b3
Replacing label b2_from_b4 with b2
Replacing label b6_from_b5 with b6
Removing instruction b1_from_bbegin:
Removing instruction bend_from_b1:
Removing instruction b1_from_main:
Removing instruction b2_from_b1:
Removing instruction b2_from_b4:
Removing instruction b3_from_b2:
Removing instruction b3_from_b3:
Removing instruction b6_from_b5:
Removing instruction b1_from_b6:
Succesful ASM optimization Pass5RedundantLabelElimination
Removing instruction b1:
Removing instruction bend:
Removing instruction b4:
Removing instruction b5:
Removing instruction breturn:
Succesful ASM optimization Pass5UnusedLabelElimination
Skipping double jump to b1 in bne b6
Succesful ASM optimization Pass5DoubleJumpElimination
Relabelling long label b1_from_b5 to b4
Succesful ASM optimization Pass5RelabelLongLabels
Adding RTS to root block 
Succesful ASM optimization Pass5AddMainRts
Removing instruction jmp b2
Removing instruction jmp b3
Succesful ASM optimization Pass5NextJumpElimination
Removing instruction b6:
Succesful ASM optimization Pass5UnusedLabelElimination
Removing unreachable instruction jmp b1
Succesful ASM optimization Pass5UnreachableCodeElimination

FINAL SYMBOL TABLE
(label) @1
(label) @begin
(label) @end
(byte*) IRQ_STATUS
(const byte*) IRQ_STATUS#0 IRQ_STATUS = (byte*) 53273
(void()**) KERNEL_IRQ
(const void()**) KERNEL_IRQ#0 KERNEL_IRQ = (void()**) 788
(byte*) SCREEN
(const byte*) SCREEN#0 SCREEN = (byte*) 1024
(byte) col1
(byte) col1#0 col1 zp ZP_BYTE:3 2.0
(byte) col1#1 col1 zp ZP_BYTE:3 20.0
interrupt(KERNEL_MIN)(void()) irq()
(label) irq::@return
(void()) main()
(byte~) main::$1 reg byte a 20002.0
(label) main::@1
(label) main::@2
(label) main::@3
(label) main::@4
(label) main::@5
(label) main::@6
(byte) main::a
(byte) main::a#1 reg byte y 15001.5
(byte) main::a#2 reg byte y 10001.0
(byte) main::x
(byte) main::x#1 reg byte x 71.0
(byte) main::x#6 reg byte x 1123.6666666666665
(byte) main::y
(byte) main::y#1 y zp ZP_BYTE:2 1501.5
(byte) main::y#4 y zp ZP_BYTE:2 2000.4999999999998

reg byte x [ main::x#6 main::x#1 ]
zp ZP_BYTE:2 [ main::y#4 main::y#1 ]
reg byte y [ main::a#2 main::a#1 ]
zp ZP_BYTE:3 [ col1#0 col1#1 ]
reg byte a [ main::$1 ]


FINAL ASSEMBLER
Score: 223704

  // File Comments
// Illustrates problem where volatiles reuse ZP addresses of other variables
  // Basic Upstart
.pc = $801 "Basic"
:BasicUpstart(bbegin)
.pc = $80d "Program"
  // Global Constants & labels
  .label KERNEL_IRQ = $314
  .label IRQ_STATUS = $d019
  .label SCREEN = $400
  .label col1 = 3
  // @begin
bbegin:
  // col1 = 0
  // [0] (byte) col1#0 ← (byte) 0 -- vbuz1=vbuc1 
  lda #0
  sta col1
  // [1] phi from @begin to @1 [phi:@begin->@1]
  // @1
  // [2] call main 
  jsr main
  rts
  // [3] phi from @1 to @end [phi:@1->@end]
  // @end
  // main
main: {
    .label y = 2
    // *KERNEL_IRQ = &irq
    // [4] *((const void()**) KERNEL_IRQ#0) ← &interrupt(KERNEL_MIN)(void()) irq() -- _deref_pptc1=pprc2 
    lda #<irq
    sta KERNEL_IRQ
    lda #>irq
    sta KERNEL_IRQ+1
    // [5] phi from main main::@5 to main::@1 [phi:main/main::@5->main::@1]
  b4:
    // [5] phi (byte) main::x#6 = (byte) 0 [phi:main/main::@5->main::@1#0] -- vbuxx=vbuc1 
    ldx #0
    // main::@1
  b1:
    // [6] phi from main::@1 to main::@2 [phi:main::@1->main::@2]
    // [6] phi (byte) main::y#4 = (byte) 0 [phi:main::@1->main::@2#0] -- vbuz1=vbuc1 
    lda #0
    sta y
    // [6] phi from main::@4 to main::@2 [phi:main::@4->main::@2]
    // [6] phi (byte) main::y#4 = (byte) main::y#1 [phi:main::@4->main::@2#0] -- register_copy 
    // main::@2
  b2:
    // [7] phi from main::@2 to main::@3 [phi:main::@2->main::@3]
    // [7] phi (byte) main::a#2 = (byte) 0 [phi:main::@2->main::@3#0] -- vbuyy=vbuc1 
    ldy #0
    // [7] phi from main::@3 to main::@3 [phi:main::@3->main::@3]
    // [7] phi (byte) main::a#2 = (byte) main::a#1 [phi:main::@3->main::@3#0] -- register_copy 
    // main::@3
  b3:
    // a+y
    // [8] (byte~) main::$1 ← (byte) main::a#2 + (byte) main::y#4 -- vbuaa=vbuyy_plus_vbuz1 
    tya
    clc
    adc y
    // SCREEN[x] = a+y
    // [9] *((const byte*) SCREEN#0 + (byte) main::x#6) ← (byte~) main::$1 -- pbuc1_derefidx_vbuxx=vbuaa 
    sta SCREEN,x
    // for (byte a:0..10)
    // [10] (byte) main::a#1 ← ++ (byte) main::a#2 -- vbuyy=_inc_vbuyy 
    iny
    // [11] if((byte) main::a#1!=(byte) $b) goto main::@3 -- vbuyy_neq_vbuc1_then_la1 
    cpy #$b
    bne b3
    // main::@4
    // for(byte y: 0..10)
    // [12] (byte) main::y#1 ← ++ (byte) main::y#4 -- vbuz1=_inc_vbuz1 
    inc y
    // [13] if((byte) main::y#1!=(byte) $b) goto main::@2 -- vbuz1_neq_vbuc1_then_la1 
    lda #$b
    cmp y
    bne b2
    // main::@5
    // for(byte x: 0..10)
    // [14] (byte) main::x#1 ← ++ (byte) main::x#6 -- vbuxx=_inc_vbuxx 
    inx
    // [15] if((byte) main::x#1!=(byte) $b) goto main::@6 -- vbuxx_neq_vbuc1_then_la1 
    cpx #$b
    bne b1
    jmp b4
    // [16] phi from main::@5 to main::@6 [phi:main::@5->main::@6]
    // main::@6
    // [5] phi from main::@6 to main::@1 [phi:main::@6->main::@1]
    // [5] phi (byte) main::x#6 = (byte) main::x#1 [phi:main::@6->main::@1#0] -- register_copy 
}
  // irq
irq: {
    // entry interrupt(KERNEL_MIN)
    // *IRQ_STATUS = 1
    // [17] *((const byte*) IRQ_STATUS#0) ← (byte) 1 -- _deref_pbuc1=vbuc2 
    // Acknowledge the IRQ
    lda #1
    sta IRQ_STATUS
    // asm
    // asm { lda$dc0d  }
    lda $dc0d
    // SCREEN[40] = col1++
    // [19] *((const byte*) SCREEN#0+(byte) $28) ← (byte) col1#0 -- _deref_pbuc1=vbuz1 
    lda col1
    sta SCREEN+$28
    // SCREEN[40] = col1++;
    // [20] (byte) col1#1 ← ++ (byte) col1#0 -- vbuz1=_inc_vbuz1 
    inc col1
    // irq::@return
    // }
    // [21] return  - exit interrupt(KERNEL_MIN)
    jmp $ea81
}
  // File Data

