Resolved forward reference irq to __interrupt(rom_min_c64) void irq()
Inlined call call __init

CONTROL FLOW GRAPH SSA

void main()
main: scope:[main]  from __start::@1
  *KERNEL_IRQ = &irq
  to:main::@1
main::@1: scope:[main]  from main main::@2 main::@3
  if(true) goto main::@2
  to:main::@return
main::@2: scope:[main]  from main::@1
  main::$0 = col > $a
  main::$1 = ! main::$0
  if(main::$1) goto main::@1
  to:main::@3
main::@3: scope:[main]  from main::@2
  col = 0
  to:main::@1
main::@return: scope:[main]  from main::@1
  return 
  to:@return

__interrupt(rom_min_c64) void irq()
irq: scope:[irq]  from
  asm { lda$dc0d  }
  *BG_COLOR = col
  irq::$0 = col != 0
  irq::$1 = ! irq::$0
  if(irq::$1) goto irq::@return
  to:irq::@1
irq::@1: scope:[irq]  from irq
  col = ++ col
  to:irq::@return
irq::@return: scope:[irq]  from irq irq::@1
  return 
  to:@return

void __start()
__start: scope:[__start]  from
  to:__start::__init1
__start::__init1: scope:[__start]  from __start
  col = 0
  to:__start::@1
__start::@1: scope:[__start]  from __start::__init1
  call main
  to:__start::@2
__start::@2: scope:[__start]  from __start::@1
  to:__start::@return
__start::@return: scope:[__start]  from __start::@2
  return 
  to:@return

SYMBOL TABLE SSA
__constant char * const BG_COLOR = (char *)$d020
__constant void (**KERNEL_IRQ)() = (void (**)())$314
void __start()
__loadstore volatile char col
__interrupt(rom_min_c64) void irq()
bool irq::$0
bool irq::$1
void main()
bool main::$0
bool main::$1

Adding number conversion cast (unumber) $a in main::$0 = col > $a
Adding number conversion cast (unumber) 0 in col = 0
Adding number conversion cast (unumber) 0 in irq::$0 = col != 0
Successful SSA optimization PassNAddNumberTypeConversions
Inlining cast col = (unumber)0
Successful SSA optimization Pass2InlineCast
Simplifying constant pointer cast (char *) 53280
Simplifying constant pointer cast (void (**)()) 788
Simplifying constant integer cast $a
Simplifying constant integer cast 0
Simplifying constant integer cast 0
Successful SSA optimization PassNCastSimplification
Finalized unsigned number type (char) $a
Finalized unsigned number type (char) 0
Finalized unsigned number type (char) 0
Successful SSA optimization PassNFinalizeNumberTypeConversions
Inversing boolean not [3] main::$1 = col <= $a from [2] main::$0 = col > $a
Inversing boolean not [10] irq::$1 = col == 0 from [9] irq::$0 = col != 0
Successful SSA optimization Pass2UnaryNotSimplification
Simple Condition main::$1 [3] if(col<=$a) goto main::@1
Simple Condition irq::$1 [9] if(col==0) goto irq::@return
Successful SSA optimization Pass2ConditionalJumpSimplification
if() condition always true - replacing block destination [1] if(true) goto main::@2
Successful SSA optimization Pass2ConstantIfs
Rewriting conditional comparison [3] if(col<=$a) goto main::@1
Removing unused block main::@return
Successful SSA optimization Pass2EliminateUnusedBlocks
Adding number conversion cast (unumber) $a+1 in if(col<$a+1) goto main::@1
Adding number conversion cast (unumber) 1 in if(col<(unumber)$a+1) goto main::@1
Successful SSA optimization PassNAddNumberTypeConversions
Simplifying constant integer cast $a+(unumber)1
Simplifying constant integer cast 1
Successful SSA optimization PassNCastSimplification
Finalized unsigned number type (char) 1
Successful SSA optimization PassNFinalizeNumberTypeConversions
Adding NOP phi() at start of __start
Adding NOP phi() at start of __start::@1
Adding NOP phi() at start of __start::@2
Adding NOP phi() at start of main::@1
CALL GRAPH
Calls in [__start] to main:3 

Created 0 initial phi equivalence classes
Coalesced down to 0 phi equivalence classes
Culled Empty Block label __start::@2
Culled Empty Block label main::@1
Renumbering block main::@2 to main::@1
Renumbering block main::@3 to main::@2
Adding NOP phi() at start of __start
Adding NOP phi() at start of __start::@1

FINAL CONTROL FLOW GRAPH

void __start()
__start: scope:[__start]  from
  [0] phi()
  to:__start::__init1
__start::__init1: scope:[__start]  from __start
  [1] col = 0
  to:__start::@1
__start::@1: scope:[__start]  from __start::__init1
  [2] phi()
  [3] call main
  to:__start::@return
__start::@return: scope:[__start]  from __start::@1
  [4] return 
  to:@return

__interrupt(rom_min_c64) void irq()
irq: scope:[irq]  from
  asm { lda$dc0d  }
  [6] *BG_COLOR = col
  [7] if(col==0) goto irq::@return
  to:irq::@1
irq::@1: scope:[irq]  from irq
  [8] col = ++ col
  to:irq::@return
irq::@return: scope:[irq]  from irq irq::@1
  [9] return 
  to:@return

void main()
main: scope:[main]  from __start::@1
  [10] *KERNEL_IRQ = &irq
  to:main::@1
main::@1: scope:[main]  from main main::@1 main::@2
  [11] if(col<$a+1) goto main::@1
  to:main::@2
main::@2: scope:[main]  from main::@1
  [12] col = 0
  to:main::@1


VARIABLE REGISTER WEIGHTS
void __start()
__loadstore volatile char col // 139.0
__interrupt(rom_min_c64) void irq()
void main()

Initial phi equivalence classes
Added variable col to live range equivalence class [ col ]
Complete equivalence classes
[ col ]
Allocated zp[1]:2 [ col ]
REGISTER UPLIFT POTENTIAL REGISTERS
Statement [1] col = 0 [ col ] (  [ col ] { }  ) always clobbers reg byte a 
Statement asm { lda$dc0d  } always clobbers reg byte a 
Statement [6] *BG_COLOR = col [ col ] (  [ col ] { }  ) always clobbers reg byte a 
Statement [7] if(col==0) goto irq::@return [ col ] (  [ col ] { }  ) always clobbers reg byte a 
Statement [10] *KERNEL_IRQ = &irq [ col ] ( main:3 [ col ] { }  ) always clobbers reg byte a 
Statement [11] if(col<$a+1) goto main::@1 [ col ] ( main:3 [ col ] { }  ) always clobbers reg byte a 
Statement [12] col = 0 [ col ] ( main:3 [ col ] { }  ) always clobbers reg byte a 
Potential registers zp[1]:2 [ col ] : zp[1]:2 , 

REGISTER UPLIFT SCOPES
Uplift Scope [] 139: zp[1]:2 [ col ] 
Uplift Scope [main] 
Uplift Scope [irq] 
Uplift Scope [__start] 

Uplifting [] best 1255 combination zp[1]:2 [ col ] 
Uplifting [main] best 1255 combination 
Uplifting [irq] best 1255 combination 
Uplifting [__start] best 1255 combination 
Attempting to uplift remaining variables inzp[1]:2 [ col ]
Uplifting [] best 1255 combination zp[1]:2 [ col ] 

ASSEMBLER BEFORE OPTIMIZATION
  // File Comments
// Tests that long branch fixing works with interrupt exits (to $ea81)
  // Upstart
  // Commodore 64 PRG executable file
.file [name="longbranch-interrupt-problem.prg", type="prg", segments="Program"]
.segmentdef Program [segments="Basic, Code, Data"]
.segmentdef Basic [start=$0801]
.segmentdef Code [start=$80d]
.segmentdef Data [startAfter="Code"]
.segment Basic
:BasicUpstart(__start)
  // Global Constants & labels
  .label BG_COLOR = $d020
  .label KERNEL_IRQ = $314
  .label col = 2
.segment Code
  // __start
__start: {
    jmp __init1
    // __start::__init1
  __init1:
    // [1] col = 0 -- vbuz1=vbuc1 
    lda #0
    sta.z col
    // [2] phi from __start::__init1 to __start::@1 [phi:__start::__init1->__start::@1]
  __b1_from___init1:
    jmp __b1
    // __start::@1
  __b1:
    // [3] call main
    jsr main
    jmp __breturn
    // __start::@return
  __breturn:
    // [4] return 
    rts
}
  // irq
irq: {
    // interrupt(isr_rom_min_c64_entry) -- isr_rom_min_c64_entry 
    // asm { lda$dc0d  }
    lda $dc0d
    // [6] *BG_COLOR = col -- _deref_pbuc1=vbuz1 
    lda.z col
    sta BG_COLOR
    // [7] if(col==0) goto irq::@return -- vbuz1_eq_0_then_la1 
    lda.z col
    beq __breturn
    jmp __b1
    // irq::@1
  __b1:
    // [8] col = ++ col -- vbuz1=_inc_vbuz1 
    inc.z col
    jmp __breturn
    // irq::@return
  __breturn:
    // [9] return 
    // interrupt(isr_rom_min_c64_exit) -- isr_rom_min_c64_exit 
    jmp $ea81
}
  // main
main: {
    // [10] *KERNEL_IRQ = &irq -- _deref_qprc1=pprc2 
    lda #<irq
    sta KERNEL_IRQ
    lda #>irq
    sta KERNEL_IRQ+1
    jmp __b1
    // main::@1
  __b1:
    // [11] if(col<$a+1) goto main::@1 -- vbuz1_lt_vbuc1_then_la1 
    lda.z col
    cmp #$a+1
    bcc __b1
    jmp __b2
    // main::@2
  __b2:
    // [12] col = 0 -- vbuz1=vbuc1 
    lda #0
    sta.z col
    jmp __b1
}
  // File Data

ASSEMBLER OPTIMIZATIONS
Removing instruction jmp __init1
Removing instruction jmp __b1
Removing instruction jmp __breturn
Removing instruction jmp __b1
Removing instruction jmp __breturn
Removing instruction jmp __b1
Removing instruction jmp __b2
Succesful ASM optimization Pass5NextJumpElimination
Removing instruction __b1_from___init1:
Succesful ASM optimization Pass5RedundantLabelElimination
Removing instruction __init1:
Removing instruction __b1:
Removing instruction __breturn:
Removing instruction __b1:
Removing instruction __b2:
Succesful ASM optimization Pass5UnusedLabelElimination
Skipping double jump to $ea81 in beq __breturn
Succesful ASM optimization Pass5DoubleJumpElimination
Removing instruction __breturn:
Succesful ASM optimization Pass5UnusedLabelElimination
Fixing long branch [24] beq $ea81 to bne

FINAL SYMBOL TABLE
__constant char * const BG_COLOR = (char *) 53280
__constant void (**KERNEL_IRQ)() = (void (**)()) 788
void __start()
__loadstore volatile char col // zp[1]:2 139.0
__interrupt(rom_min_c64) void irq()
void main()

zp[1]:2 [ col ]


FINAL ASSEMBLER
Score: 913

  // File Comments
// Tests that long branch fixing works with interrupt exits (to $ea81)
  // Upstart
  // Commodore 64 PRG executable file
.file [name="longbranch-interrupt-problem.prg", type="prg", segments="Program"]
.segmentdef Program [segments="Basic, Code, Data"]
.segmentdef Basic [start=$0801]
.segmentdef Code [start=$80d]
.segmentdef Data [startAfter="Code"]
.segment Basic
:BasicUpstart(__start)
  // Global Constants & labels
  .label BG_COLOR = $d020
  .label KERNEL_IRQ = $314
  .label col = 2
.segment Code
  // __start
__start: {
    // __start::__init1
    // volatile byte col = 0
    // [1] col = 0 -- vbuz1=vbuc1 
    lda #0
    sta.z col
    // [2] phi from __start::__init1 to __start::@1 [phi:__start::__init1->__start::@1]
    // __start::@1
    // [3] call main
    jsr main
    // __start::@return
    // [4] return 
    rts
}
  // irq
irq: {
    // interrupt(isr_rom_min_c64_entry) -- isr_rom_min_c64_entry 
    // asm
    // asm { lda$dc0d  }
    lda $dc0d
    // *BG_COLOR = col
    // [6] *BG_COLOR = col -- _deref_pbuc1=vbuz1 
    lda.z col
    sta BG_COLOR
    // if(col!=0)
    // [7] if(col==0) goto irq::@return -- vbuz1_eq_0_then_la1 
    lda.z col
    bne !__ea81+
    jmp $ea81
  !__ea81:
    // irq::@1
    // col++;
    // [8] col = ++ col -- vbuz1=_inc_vbuz1 
    inc.z col
    // irq::@return
    // }
    // [9] return 
    // interrupt(isr_rom_min_c64_exit) -- isr_rom_min_c64_exit 
    jmp $ea81
}
  // main
main: {
    // *KERNEL_IRQ = &irq
    // [10] *KERNEL_IRQ = &irq -- _deref_qprc1=pprc2 
    lda #<irq
    sta KERNEL_IRQ
    lda #>irq
    sta KERNEL_IRQ+1
    // main::@1
  __b1:
    // if(col>10)
    // [11] if(col<$a+1) goto main::@1 -- vbuz1_lt_vbuc1_then_la1 
    lda.z col
    cmp #$a+1
    bcc __b1
    // main::@2
    // col = 0
    // [12] col = 0 -- vbuz1=vbuc1 
    lda #0
    sta.z col
    jmp __b1
}
  // File Data

