Resolved forward reference irq to interrupt(KERNEL_MIN)(void()) irq()
Culled Empty Block (label) main::@5
Culled Empty Block (label) main::@3
Culled Empty Block (label) main::@6
Culled Empty Block (label) main::@4
Culled Empty Block (label) main::@8
Culled Empty Block (label) @1
Culled Empty Block (label) irq::@1

CONTROL FLOW GRAPH SSA
@begin: scope:[]  from
  (void()**) KERNEL_IRQ#0 ← ((void()**)) (number) $314
  (byte*) BGCOL#0 ← ((byte*)) (number) $d020
  (byte) col#0 ← (number) 0
  to:@2
main: scope:[main]  from @2
  (byte) col#14 ← phi( @2/(byte) col#13 )
  (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::@2 main::@7
  (byte) col#12 ← phi( main/(byte) col#14 main::@2/(byte) col#6 main::@7/(byte) col#1 )
  if(true) goto main::@2
  to:main::@return
main::@2: scope:[main]  from main::@1
  (byte) col#6 ← phi( main::@1/(byte) col#12 )
  (bool~) main::$1 ← (byte) col#6 > (number) $a
  (bool~) main::$2 ← ! (bool~) main::$1
  if((bool~) main::$2) goto main::@1
  to:main::@7
main::@7: scope:[main]  from main::@2
  (byte) col#1 ← (number) 0
  to:main::@1
main::@return: scope:[main]  from main::@1
  (byte) col#7 ← phi( main::@1/(byte) col#12 )
  (byte) col#2 ← (byte) col#7
  return 
  to:@return
irq: scope:[irq]  from
  (byte) col#8 ← phi( @2/(byte) col#13 )
  asm { lda$dc0d  }
  *((byte*) BGCOL#0) ← (byte) col#8
  (bool~) irq::$0 ← (byte) col#8 != (number) 0
  (bool~) irq::$1 ← ! (bool~) irq::$0
  if((bool~) irq::$1) goto irq::@return
  to:irq::@2
irq::@2: scope:[irq]  from irq
  (byte) col#9 ← phi( irq/(byte) col#8 )
  (byte) col#3 ← ++ (byte) col#9
  to:irq::@return
irq::@return: scope:[irq]  from irq irq::@2
  (byte) col#10 ← phi( irq/(byte) col#8 irq::@2/(byte) col#3 )
  (byte) col#4 ← (byte) col#10
  return 
  to:@return
@2: scope:[]  from @begin
  (byte) col#13 ← phi( @begin/(byte) col#0 )
  call main 
  to:@3
@3: scope:[]  from @2
  (byte) col#11 ← phi( @2/(byte) col#2 )
  (byte) col#5 ← (byte) col#11
  to:@end
@end: scope:[]  from @3

SYMBOL TABLE SSA
(label) @2
(label) @3
(label) @begin
(label) @end
(byte*) BGCOL
(byte*) BGCOL#0
(void()**) KERNEL_IRQ
(void()**) KERNEL_IRQ#0
(byte) col
(byte) col#0
(byte) col#1
(byte) col#10
(byte) col#11
(byte) col#12
(byte) col#13
(byte) col#14
(byte) col#2
(byte) col#3
(byte) col#4
(byte) col#5
(byte) col#6
(byte) col#7
(byte) col#8
(byte) col#9
interrupt(KERNEL_MIN)(void()) irq()
(bool~) irq::$0
(bool~) irq::$1
(label) irq::@2
(label) irq::@return
(void()) main()
(void()*~) main::$0
(bool~) main::$1
(bool~) main::$2
(label) main::@1
(label) main::@2
(label) main::@7
(label) main::@return

Adding number conversion cast (unumber) 0 in (byte) col#0 ← (number) 0
Adding number conversion cast (unumber) $a in (bool~) main::$1 ← (byte) col#6 > (number) $a
Adding number conversion cast (unumber) 0 in (byte) col#1 ← (number) 0
Adding number conversion cast (unumber) 0 in (bool~) irq::$0 ← (byte) col#8 != (number) 0
Successful SSA optimization PassNAddNumberTypeConversions
Inlining cast (void()**) KERNEL_IRQ#0 ← (void()**)(number) $314
Inlining cast (byte*) BGCOL#0 ← (byte*)(number) $d020
Inlining cast (byte) col#0 ← (unumber)(number) 0
Inlining cast (byte) col#1 ← (unumber)(number) 0
Successful SSA optimization Pass2InlineCast
Simplifying constant pointer cast (void()**) 788
Simplifying constant pointer cast (byte*) 53280
Simplifying constant integer cast 0
Simplifying constant integer cast $a
Simplifying constant integer cast 0
Simplifying constant integer cast 0
Successful SSA optimization PassNCastSimplification
Finalized unsigned number type (byte) 0
Finalized unsigned number type (byte) $a
Finalized unsigned number type (byte) 0
Finalized unsigned number type (byte) 0
Successful SSA optimization PassNFinalizeNumberTypeConversions
Inversing boolean not [10] (bool~) main::$2 ← (byte) col#6 <= (byte) $a from [9] (bool~) main::$1 ← (byte) col#6 > (byte) $a
Inversing boolean not [20] (bool~) irq::$1 ← (byte) col#8 == (byte) 0 from [19] (bool~) irq::$0 ← (byte) col#8 != (byte) 0
Successful SSA optimization Pass2UnaryNotSimplification
Alias (byte) col#12 = (byte) col#6 (byte) col#7 (byte) col#2 
Alias (byte) col#8 = (byte) col#9 
Alias (byte) col#10 = (byte) col#4 
Alias (byte) col#0 = (byte) col#13 
Alias (byte) col#11 = (byte) col#5 
Successful SSA optimization Pass2AliasElimination
Self Phi Eliminated (byte) col#12
Successful SSA optimization Pass2SelfPhiElimination
Identical Phi Values (byte) col#14 (byte) col#0
Identical Phi Values (byte) col#8 (byte) col#0
Identical Phi Values (byte) col#11 (byte) col#12
Successful SSA optimization Pass2IdenticalPhiElimination
Simple Condition (bool~) main::$2 [11] if((byte) col#12<=(byte) $a) goto main::@1
Simple Condition (bool~) irq::$1 [21] if((byte) col#0==(byte) 0) goto irq::@return
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*) BGCOL#0 = (byte*) 53280
Constant (const void()*) main::$0 = &irq
Successful SSA optimization Pass2ConstantIdentification
if() condition always true - replacing block destination [7] if(true) goto main::@2
Successful SSA optimization Pass2ConstantIfs
Rewriting conditional comparison [11] if((byte) col#12<=(byte) $a) goto main::@1
Removing unused block main::@return
Successful SSA optimization Pass2EliminateUnusedBlocks
Adding number conversion cast (unumber) $a+1 in if((byte) col#12<(byte) $a+(number) 1) goto main::@1
Adding number conversion cast (unumber) 1 in if((byte) col#12<(unumber)(byte) $a+(number) 1) goto main::@1
Successful SSA optimization PassNAddNumberTypeConversions
Simplifying constant integer cast (byte) $a+(unumber)(number) 1
Simplifying constant integer cast 1
Successful SSA optimization PassNCastSimplification
Finalized unsigned number type (byte) 1
Successful SSA optimization PassNFinalizeNumberTypeConversions
Constant inlined main::$0 = &interrupt(KERNEL_MIN)(void()) irq()
Successful SSA optimization Pass2ConstantInlining
Added new block during phi lifting irq::@3(between irq and irq::@return)
Adding NOP phi() at start of @2
Adding NOP phi() at start of @3
Adding NOP phi() at start of @end
CALL GRAPH
Calls in [] to main:2 

Created 2 initial phi equivalence classes
Coalesced [6] col#15 ← col#0
Coalesced [10] col#16 ← col#1
Coalesced [15] col#18 ← col#3
Coalesced [18] col#17 ← col#0
Coalesced down to 1 phi equivalence classes
Culled Empty Block (label) @3
Culled Empty Block (label) irq::@3
Renumbering block @2 to @1
Renumbering block main::@7 to main::@3
Renumbering block irq::@2 to irq::@1
Adding NOP phi() at start of @1
Adding NOP phi() at start of @end

FINAL CONTROL FLOW GRAPH
@begin: scope:[]  from
  [0] (byte) col#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::@2 main::@3
  [5] (byte) col#12 ← phi( main/(byte) col#0 main::@3/(byte) col#1 )
  to:main::@2
main::@2: scope:[main]  from main::@1
  [6] if((byte) col#12<(byte) $a+(byte) 1) goto main::@1
  to:main::@3
main::@3: scope:[main]  from main::@2
  [7] (byte) col#1 ← (byte) 0
  to:main::@1
irq: scope:[irq]  from
  asm { lda$dc0d  }
  [9] *((const byte*) BGCOL#0) ← (byte) col#0
  [10] if((byte) col#0==(byte) 0) goto irq::@return
  to:irq::@1
irq::@1: scope:[irq]  from irq
  [11] (byte) col#3 ← ++ (byte) col#0
  to:irq::@return
irq::@return: scope:[irq]  from irq irq::@1
  [12] (byte) col#10 ← phi( irq/(byte) col#0 irq::@1/(byte) col#3 )
  [13] return 
  to:@return


VARIABLE REGISTER WEIGHTS
(byte*) BGCOL
(void()**) KERNEL_IRQ
(byte) col
(byte) col#0 1.9999999999999998
(byte) col#1 22.0
(byte) col#10 40.0
(byte) col#12 114.0
(byte) col#3 4.0
interrupt(KERNEL_MIN)(void()) irq()
(void()) main()

Initial phi equivalence classes
[ col#10 col#12 col#0 col#1 col#3 ]
Complete equivalence classes
[ col#10 col#12 col#0 col#1 col#3 ]
Allocated zp ZP_BYTE:2 [ col#10 col#12 col#0 col#1 col#3 ]

INITIAL ASM
  // File Comments
// Tests that long branch fixing works with interrupt exits (to $ea81)
  // Basic Upstart
.pc = $801 "Basic"
:BasicUpstart(bbegin)
.pc = $80d "Program"
  // Global Constants & labels
  .label KERNEL_IRQ = $314
  .label BGCOL = $d020
  .label col = 2
  // @begin
bbegin:
  // [0] (byte) col#0 ← (byte) 0 -- vbuz1=vbuc1 
  lda #0
  sta col
  // [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: {
    // [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::@3 to main::@1 [phi:main/main::@3->main::@1]
  b1_from_main:
  b1_from_b3:
    // [5] phi (byte) col#12 = (byte) col#0 [phi:main/main::@3->main::@1#0] -- register_copy 
    jmp b1
    // [5] phi from main::@2 to main::@1 [phi:main::@2->main::@1]
  b1_from_b2:
    jmp b1
    // main::@1
  b1:
    jmp b2
    // main::@2
  b2:
    // [6] if((byte) col#12<(byte) $a+(byte) 1) goto main::@1 -- vbuz1_lt_vbuc1_then_la1 
    lda col
    cmp #$a+1
    bcc b1_from_b2
    jmp b3
    // main::@3
  b3:
    // [7] (byte) col#1 ← (byte) 0 -- vbuz1=vbuc1 
    lda #0
    sta col
    jmp b1_from_b3
}
  // irq
irq: {
    // entry interrupt(KERNEL_MIN)
    // asm { lda$dc0d  }
    lda $dc0d
    // [9] *((const byte*) BGCOL#0) ← (byte) col#0 -- _deref_pbuc1=vbuz1 
    lda col
    sta BGCOL
    // [10] if((byte) col#0==(byte) 0) goto irq::@return -- vbuz1_eq_0_then_la1 
    lda col
    cmp #0
    beq breturn_from_irq
    jmp b1
    // irq::@1
  b1:
    // [11] (byte) col#3 ← ++ (byte) col#0 -- vbuz1=_inc_vbuz1 
    inc col
    // [12] phi from irq irq::@1 to irq::@return [phi:irq/irq::@1->irq::@return]
  breturn_from_irq:
  breturn_from_b1:
    // [12] phi (byte) col#10 = (byte) col#0 [phi:irq/irq::@1->irq::@return#0] -- register_copy 
    jmp breturn
    // irq::@return
  breturn:
    // [13] return  - exit interrupt(KERNEL_MIN)
    jmp $ea81
}
  // File Data

REGISTER UPLIFT POTENTIAL REGISTERS
Statement [0] (byte) col#0 ← (byte) 0 [ col#0 ] (  [ col#0 ] ) always clobbers reg byte a 
Statement [4] *((const void()**) KERNEL_IRQ#0) ← &interrupt(KERNEL_MIN)(void()) irq() [ col#0 ] ( main:2 [ col#0 ] ) always clobbers reg byte a 
Statement [6] if((byte) col#12<(byte) $a+(byte) 1) goto main::@1 [ ] ( main:2 [ ] ) always clobbers reg byte a 
Statement [7] (byte) col#1 ← (byte) 0 [ col#1 ] ( main:2 [ col#1 ] ) always clobbers reg byte a 
Statement asm { lda$dc0d  } always clobbers reg byte a 
Statement [9] *((const byte*) BGCOL#0) ← (byte) col#0 [ col#0 ] (  [ col#0 ] ) always clobbers reg byte a 
Statement [10] if((byte) col#0==(byte) 0) goto irq::@return [ col#0 ] (  [ col#0 ] ) always clobbers reg byte a 
Potential registers zp ZP_BYTE:2 [ col#10 col#12 col#0 col#1 col#3 ] : zp ZP_BYTE:2 , 

REGISTER UPLIFT SCOPES
Uplift Scope [] 182: zp ZP_BYTE:2 [ col#10 col#12 col#0 col#1 col#3 ] 
Uplift Scope [main] 
Uplift Scope [irq] 

Uplifting [] best 1821 combination zp ZP_BYTE:2 [ col#10 col#12 col#0 col#1 col#3 ] 
Uplifting [main] best 1821 combination 
Uplifting [irq] best 1821 combination 
Attempting to uplift remaining variables inzp ZP_BYTE:2 [ col#10 col#12 col#0 col#1 col#3 ]
Uplifting [] best 1821 combination zp ZP_BYTE:2 [ col#10 col#12 col#0 col#1 col#3 ] 

ASSEMBLER BEFORE OPTIMIZATION
  // File Comments
// Tests that long branch fixing works with interrupt exits (to $ea81)
  // Basic Upstart
.pc = $801 "Basic"
:BasicUpstart(bbegin)
.pc = $80d "Program"
  // Global Constants & labels
  .label KERNEL_IRQ = $314
  .label BGCOL = $d020
  .label col = 2
  // @begin
bbegin:
  // [0] (byte) col#0 ← (byte) 0 -- vbuz1=vbuc1 
  lda #0
  sta col
  // [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: {
    // [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::@3 to main::@1 [phi:main/main::@3->main::@1]
  b1_from_main:
  b1_from_b3:
    // [5] phi (byte) col#12 = (byte) col#0 [phi:main/main::@3->main::@1#0] -- register_copy 
    jmp b1
    // [5] phi from main::@2 to main::@1 [phi:main::@2->main::@1]
  b1_from_b2:
    jmp b1
    // main::@1
  b1:
    jmp b2
    // main::@2
  b2:
    // [6] if((byte) col#12<(byte) $a+(byte) 1) goto main::@1 -- vbuz1_lt_vbuc1_then_la1 
    lda col
    cmp #$a+1
    bcc b1_from_b2
    jmp b3
    // main::@3
  b3:
    // [7] (byte) col#1 ← (byte) 0 -- vbuz1=vbuc1 
    lda #0
    sta col
    jmp b1_from_b3
}
  // irq
irq: {
    // entry interrupt(KERNEL_MIN)
    // asm { lda$dc0d  }
    lda $dc0d
    // [9] *((const byte*) BGCOL#0) ← (byte) col#0 -- _deref_pbuc1=vbuz1 
    lda col
    sta BGCOL
    // [10] if((byte) col#0==(byte) 0) goto irq::@return -- vbuz1_eq_0_then_la1 
    lda col
    cmp #0
    beq breturn_from_irq
    jmp b1
    // irq::@1
  b1:
    // [11] (byte) col#3 ← ++ (byte) col#0 -- vbuz1=_inc_vbuz1 
    inc col
    // [12] phi from irq irq::@1 to irq::@return [phi:irq/irq::@1->irq::@return]
  breturn_from_irq:
  breturn_from_b1:
    // [12] phi (byte) col#10 = (byte) col#0 [phi:irq/irq::@1->irq::@return#0] -- register_copy 
    jmp breturn
    // irq::@return
  breturn:
    // [13] 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 b1
Removing instruction jmp breturn
Succesful ASM optimization Pass5NextJumpElimination
Replacing label b1 with b2
Replacing label b1_from_b2 with b2
Replacing label breturn_from_irq with breturn
Removing instruction b1_from_bbegin:
Removing instruction bend_from_b1:
Removing instruction b1_from_main:
Removing instruction b1_from_b2:
Removing instruction b1:
Removing instruction breturn_from_irq:
Removing instruction breturn_from_b1:
Succesful ASM optimization Pass5RedundantLabelElimination
Removing instruction b1:
Removing instruction bend:
Removing instruction b3:
Removing instruction b1:
Succesful ASM optimization Pass5UnusedLabelElimination
Skipping double jump to b2 in jmp b1_from_b3
Skipping double jump to $ea81 in beq breturn
Succesful ASM optimization Pass5DoubleJumpElimination
Relabelling long label b1_from_b3 to b1
Succesful ASM optimization Pass5RelabelLongLabels
Adding RTS to root block 
Succesful ASM optimization Pass5AddMainRts
Removing instruction jmp b2
Succesful ASM optimization Pass5NextJumpElimination
Removing instruction b1:
Succesful ASM optimization Pass5RedundantLabelElimination
Removing instruction breturn:
Succesful ASM optimization Pass5UnusedLabelElimination
Fixing long branch [31] beq $ea81 to bne

FINAL SYMBOL TABLE
(label) @1
(label) @begin
(label) @end
(byte*) BGCOL
(const byte*) BGCOL#0 BGCOL = (byte*) 53280
(void()**) KERNEL_IRQ
(const void()**) KERNEL_IRQ#0 KERNEL_IRQ = (void()**) 788
(byte) col
(byte) col#0 col zp ZP_BYTE:2 1.9999999999999998
(byte) col#1 col zp ZP_BYTE:2 22.0
(byte) col#10 col zp ZP_BYTE:2 40.0
(byte) col#12 col zp ZP_BYTE:2 114.0
(byte) col#3 col zp ZP_BYTE:2 4.0
interrupt(KERNEL_MIN)(void()) irq()
(label) irq::@1
(label) irq::@return
(void()) main()
(label) main::@1
(label) main::@2
(label) main::@3

zp ZP_BYTE:2 [ col#10 col#12 col#0 col#1 col#3 ]


FINAL ASSEMBLER
Score: 888

  // File Comments
// Tests that long branch fixing works with interrupt exits (to $ea81)
  // Basic Upstart
.pc = $801 "Basic"
:BasicUpstart(bbegin)
.pc = $80d "Program"
  // Global Constants & labels
  .label KERNEL_IRQ = $314
  .label BGCOL = $d020
  .label col = 2
  // @begin
bbegin:
  // col = 0
  // [0] (byte) col#0 ← (byte) 0 -- vbuz1=vbuc1 
  lda #0
  sta col
  // [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: {
    // *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::@3 to main::@1 [phi:main/main::@3->main::@1]
    // [5] phi (byte) col#12 = (byte) col#0 [phi:main/main::@3->main::@1#0] -- register_copy 
    // [5] phi from main::@2 to main::@1 [phi:main::@2->main::@1]
    // main::@1
    // main::@2
  b2:
    // if(col>10)
    // [6] if((byte) col#12<(byte) $a+(byte) 1) goto main::@1 -- vbuz1_lt_vbuc1_then_la1 
    lda col
    cmp #$a+1
    bcc b2
    // main::@3
    // col = 0
    // [7] (byte) col#1 ← (byte) 0 -- vbuz1=vbuc1 
    lda #0
    sta col
    jmp b2
}
  // irq
irq: {
    // entry interrupt(KERNEL_MIN)
    // asm
    // asm { lda$dc0d  }
    lda $dc0d
    // *BGCOL = col
    // [9] *((const byte*) BGCOL#0) ← (byte) col#0 -- _deref_pbuc1=vbuz1 
    lda col
    sta BGCOL
    // if(col!=0)
    // [10] if((byte) col#0==(byte) 0) goto irq::@return -- vbuz1_eq_0_then_la1 
    lda col
    cmp #0
    bne !_ea81+
    jmp $ea81
  !_ea81:
    // irq::@1
    // col++;
    // [11] (byte) col#3 ← ++ (byte) col#0 -- vbuz1=_inc_vbuz1 
    inc col
    // [12] phi from irq irq::@1 to irq::@return [phi:irq/irq::@1->irq::@return]
    // [12] phi (byte) col#10 = (byte) col#0 [phi:irq/irq::@1->irq::@return#0] -- register_copy 
    // irq::@return
    // }
    // [13] return  - exit interrupt(KERNEL_MIN)
    jmp $ea81
}
  // File Data

