Resolved forward reference nmi to interrupt(HARDWARE_ALL)(void()) nmi()
Resolved forward reference nmi2 to interrupt(HARDWARE_ALL)(void()) nmi2()
Inlined call (byte~) vicSelectGfxBank::$0 ← call toDd00 (byte*) vicSelectGfxBank::gfx 
Culled Empty Block (label) @1
Culled Empty Block (label) @2
Culled Empty Block (label) @3
Culled Empty Block (label) @5
Culled Empty Block (label) @6

CONTROL FLOW GRAPH SSA
@begin: scope:[]  from
  to:@4
@4: scope:[]  from @begin
  (byte*) sample ← (const byte*) SAMPLE
  to:@7

(void()) main()
main: scope:[main]  from @7
  asm { lda#$ff sta$d406 sta$d40d sta$d414 lda#$49 sta$d404 sta$d40b sta$d412  }
  asm { sei  }
  *((const byte*) CIA2_INTERRUPT) ← (const byte) CIA_INTERRUPT_CLEAR
  *((const void()**) KERNEL_NMI) ← &interrupt(HARDWARE_ALL)(void()) nmi()
  *((const word*) CIA2_TIMER_A) ← (number) $88
  *((const byte*) CIA2_INTERRUPT) ← (number) $81
  *((const byte*) CIA2_TIMER_A_CONTROL) ← (number) 1
  asm { cli  }
  to:main::@return
main::@return: scope:[main]  from main
  return 
  to:@return

interrupt(HARDWARE_ALL)(void()) nmi()
nmi: scope:[nmi]  from
  *((const byte*) BORDERCOL) ← ++ *((const byte*) BORDERCOL)
  asm { ldaCIA2_INTERRUPT  }
  (number~) nmi::$1 ← *((byte*) sample) & (number) $f
  *((const byte*) SID_VOLUME) ← (number~) nmi::$1
  *((const void()**) KERNEL_NMI) ← &interrupt(HARDWARE_ALL)(void()) nmi2()
  *((const byte*) BORDERCOL) ← -- *((const byte*) BORDERCOL)
  to:nmi::@return
nmi::@return: scope:[nmi]  from nmi
  return 
  to:@return

interrupt(HARDWARE_ALL)(void()) nmi2()
nmi2: scope:[nmi2]  from
  *((const byte*) BORDERCOL) ← ++ *((const byte*) BORDERCOL)
  asm { ldaCIA2_INTERRUPT  }
  (byte~) nmi2::$1 ← *((byte*) sample) >> (number) 4
  *((const byte*) SID_VOLUME) ← (byte~) nmi2::$1
  (byte*) sample ← ++ (byte*) sample
  (byte~) nmi2::$2 ← > (byte*) sample
  (bool~) nmi2::$3 ← (byte~) nmi2::$2 == >(const byte*) SAMPLE+(number) $6100
  (bool~) nmi2::$4 ← ! (bool~) nmi2::$3
  if((bool~) nmi2::$4) goto nmi2::@1
  to:nmi2::@2
nmi2::@1: scope:[nmi2]  from nmi2 nmi2::@2
  *((const void()**) KERNEL_NMI) ← &interrupt(HARDWARE_ALL)(void()) nmi()
  *((const byte*) BORDERCOL) ← -- *((const byte*) BORDERCOL)
  to:nmi2::@return
nmi2::@2: scope:[nmi2]  from nmi2
  (byte*) sample ← (const byte*) SAMPLE
  to:nmi2::@1
nmi2::@return: scope:[nmi2]  from nmi2::@1
  return 
  to:@return
@7: scope:[]  from @4
  call main 
  to:@8
@8: scope:[]  from @7
  to:@end
@end: scope:[]  from @8

SYMBOL TABLE SSA
(label) @4
(label) @7
(label) @8
(label) @begin
(label) @end
(const byte*) BORDERCOL = (byte*)(number) $d020
(const byte*) CIA2_INTERRUPT = (byte*)(number) $dd0d
(const word*) CIA2_TIMER_A = (word*)(number) $dd04
(const byte*) CIA2_TIMER_A_CONTROL = (byte*)(number) $dd0e
(const byte) CIA_INTERRUPT_CLEAR = (byte) $7f
(const void()**) KERNEL_NMI = (void()**)(number) $318
(const byte*) SAMPLE[(const word) SAMPLE_SIZE]  = kickasm {{ .import binary "moments_sample.bin"  }}
(const word) SAMPLE_SIZE = (word) $6100
(const byte*) SID_VOLUME = (byte*)(number) $d418
(void()) main()
(label) main::@return
interrupt(HARDWARE_ALL)(void()) nmi()
(number~) nmi::$1
(label) nmi::@return
interrupt(HARDWARE_ALL)(void()) nmi2()
(byte~) nmi2::$1
(byte~) nmi2::$2
(bool~) nmi2::$3
(bool~) nmi2::$4
(label) nmi2::@1
(label) nmi2::@2
(label) nmi2::@return
(byte*) sample loadstore

Adding number conversion cast (unumber) $88 in *((const word*) CIA2_TIMER_A) ← (number) $88
Adding number conversion cast (unumber) $81 in *((const byte*) CIA2_INTERRUPT) ← (number) $81
Adding number conversion cast (unumber) 1 in *((const byte*) CIA2_TIMER_A_CONTROL) ← (number) 1
Adding number conversion cast (unumber) $f in (number~) nmi::$1 ← *((byte*) sample) & (number) $f
Adding number conversion cast (unumber) nmi::$1 in (number~) nmi::$1 ← *((byte*) sample) & (unumber)(number) $f
Adding number conversion cast (unumber) 4 in (byte~) nmi2::$1 ← *((byte*) sample) >> (number) 4
Adding number conversion cast (unumber) $6100 in (bool~) nmi2::$3 ← (byte~) nmi2::$2 == >(const byte*) SAMPLE+(number) $6100
Successful SSA optimization PassNAddNumberTypeConversions
Inlining cast *((const word*) CIA2_TIMER_A) ← (unumber)(number) $88
Inlining cast *((const byte*) CIA2_INTERRUPT) ← (unumber)(number) $81
Inlining cast *((const byte*) CIA2_TIMER_A_CONTROL) ← (unumber)(number) 1
Successful SSA optimization Pass2InlineCast
Simplifying constant pointer cast (byte*) 53280
Simplifying constant pointer cast (word*) 56580
Simplifying constant pointer cast (byte*) 56589
Simplifying constant pointer cast (byte*) 56590
Simplifying constant pointer cast (void()**) 792
Simplifying constant pointer cast (byte*) 54296
Simplifying constant integer cast $88
Simplifying constant integer cast $81
Simplifying constant integer cast 1
Simplifying constant integer cast $f
Simplifying constant integer cast 4
Simplifying constant integer cast $6100
Successful SSA optimization PassNCastSimplification
Finalized unsigned number type (byte) $88
Finalized unsigned number type (byte) $81
Finalized unsigned number type (byte) 1
Finalized unsigned number type (byte) $f
Finalized unsigned number type (byte) 4
Finalized unsigned number type (word) $6100
Successful SSA optimization PassNFinalizeNumberTypeConversions
Inferred type updated to byte in (unumber~) nmi::$1 ← *((byte*) sample) & (byte) $f
Inversing boolean not [24] (bool~) nmi2::$4 ← (byte~) nmi2::$2 != >(const byte*) SAMPLE+(word) $6100 from [23] (bool~) nmi2::$3 ← (byte~) nmi2::$2 == >(const byte*) SAMPLE+(word) $6100
Successful SSA optimization Pass2UnaryNotSimplification
Simple Condition (bool~) nmi2::$4 [24] if((byte~) nmi2::$2!=>(const byte*) SAMPLE+(word) $6100) goto nmi2::@1
Successful SSA optimization Pass2ConditionalJumpSimplification
Adding NOP phi() at start of @begin
Adding NOP phi() at start of @7
Adding NOP phi() at start of @8
Adding NOP phi() at start of @end
CALL GRAPH
Calls in [] to main:3 

Created 0 initial phi equivalence classes
Coalesced down to 0 phi equivalence classes
Culled Empty Block (label) @8
Renumbering block @4 to @1
Renumbering block @7 to @2
Adding NOP phi() at start of @begin
Adding NOP phi() at start of @2
Adding NOP phi() at start of @end

FINAL CONTROL FLOW GRAPH
@begin: scope:[]  from
  [0] phi()
  to:@1
@1: scope:[]  from @begin
  [1] (byte*) sample ← (const byte*) SAMPLE
  to:@2
@2: scope:[]  from @1
  [2] phi()
  [3] call main 
  to:@end
@end: scope:[]  from @2
  [4] phi()

(void()) main()
main: scope:[main]  from @2
  asm { lda#$ff sta$d406 sta$d40d sta$d414 lda#$49 sta$d404 sta$d40b sta$d412  }
  asm { sei  }
  [7] *((const byte*) CIA2_INTERRUPT) ← (const byte) CIA_INTERRUPT_CLEAR
  [8] *((const void()**) KERNEL_NMI) ← &interrupt(HARDWARE_ALL)(void()) nmi()
  [9] *((const word*) CIA2_TIMER_A) ← (byte) $88
  [10] *((const byte*) CIA2_INTERRUPT) ← (byte) $81
  [11] *((const byte*) CIA2_TIMER_A_CONTROL) ← (byte) 1
  asm { cli  }
  to:main::@return
main::@return: scope:[main]  from main
  [13] return 
  to:@return

interrupt(HARDWARE_ALL)(void()) nmi2()
nmi2: scope:[nmi2]  from
  [14] *((const byte*) BORDERCOL) ← ++ *((const byte*) BORDERCOL)
  asm { ldaCIA2_INTERRUPT  }
  [16] (byte~) nmi2::$1 ← *((byte*) sample) >> (byte) 4
  [17] *((const byte*) SID_VOLUME) ← (byte~) nmi2::$1
  [18] (byte*) sample ← ++ (byte*) sample
  [19] (byte~) nmi2::$2 ← > (byte*) sample
  [20] if((byte~) nmi2::$2!=>(const byte*) SAMPLE+(word) $6100) goto nmi2::@1
  to:nmi2::@2
nmi2::@2: scope:[nmi2]  from nmi2
  [21] (byte*) sample ← (const byte*) SAMPLE
  to:nmi2::@1
nmi2::@1: scope:[nmi2]  from nmi2 nmi2::@2
  [22] *((const void()**) KERNEL_NMI) ← &interrupt(HARDWARE_ALL)(void()) nmi()
  [23] *((const byte*) BORDERCOL) ← -- *((const byte*) BORDERCOL)
  to:nmi2::@return
nmi2::@return: scope:[nmi2]  from nmi2::@1
  [24] return 
  to:@return

interrupt(HARDWARE_ALL)(void()) nmi()
nmi: scope:[nmi]  from
  [25] *((const byte*) BORDERCOL) ← ++ *((const byte*) BORDERCOL)
  asm { ldaCIA2_INTERRUPT  }
  [27] (byte~) nmi::$1 ← *((byte*) sample) & (byte) $f
  [28] *((const byte*) SID_VOLUME) ← (byte~) nmi::$1
  [29] *((const void()**) KERNEL_NMI) ← &interrupt(HARDWARE_ALL)(void()) nmi2()
  [30] *((const byte*) BORDERCOL) ← -- *((const byte*) BORDERCOL)
  to:nmi::@return
nmi::@return: scope:[nmi]  from nmi
  [31] return 
  to:@return


VARIABLE REGISTER WEIGHTS
(void()) main()
interrupt(HARDWARE_ALL)(void()) nmi()
(byte~) nmi::$1 4.0
interrupt(HARDWARE_ALL)(void()) nmi2()
(byte~) nmi2::$1 4.0
(byte~) nmi2::$2 4.0
(byte*) sample loadstore 1.9999999999999996

Initial phi equivalence classes
Added variable sample to live range equivalence class [ sample ]
Added variable nmi2::$1 to live range equivalence class [ nmi2::$1 ]
Added variable nmi2::$2 to live range equivalence class [ nmi2::$2 ]
Added variable nmi::$1 to live range equivalence class [ nmi::$1 ]
Complete equivalence classes
[ sample ]
[ nmi2::$1 ]
[ nmi2::$2 ]
[ nmi::$1 ]
Allocated zp[2]:2 [ sample ]
Allocated zp[1]:4 [ nmi2::$1 ]
Allocated zp[1]:5 [ nmi2::$2 ]
Allocated zp[1]:6 [ nmi::$1 ]

INITIAL ASM
Target platform is c64basic / MOS6502X
  // File Comments
// NMI Sample Player using the SID volume register
// Code by Scan of Desire (Richard-William Loerakker)
// Sample from ART OF NOISE: MOMENTS IN LOVE
  // Upstart
.pc = $801 "Basic"
:BasicUpstart(__bbegin)
.pc = $80d "Program"
  // Global Constants & labels
  .label BORDERCOL = $d020
  // CIA #2 Timer A Value (16-bit)
  .label CIA2_TIMER_A = $dd04
  // CIA #2 Interrupt Status & Control Register
  .label CIA2_INTERRUPT = $dd0d
  // CIA #2 Timer A Control Register
  .label CIA2_TIMER_A_CONTROL = $dd0e
  // Value that disables all CIA interrupts when stored to the CIA Interrupt registers
  .const CIA_INTERRUPT_CLEAR = $7f
  // The vector used when the KERNAL serves NMI interrupts
  .label KERNEL_NMI = $318
  // The SID volume
  .label SID_VOLUME = $d418
  .const SAMPLE_SIZE = $6100
  .label sample = 2
  // @begin
__bbegin:
  jmp __b1
  // @1
__b1:
  // [1] (byte*) sample ← (const byte*) SAMPLE -- pbuz1=pbuc1 
  lda #<SAMPLE
  sta.z sample
  lda #>SAMPLE
  sta.z sample+1
  // [2] phi from @1 to @2 [phi:@1->@2]
__b2_from___b1:
  jmp __b2
  // @2
__b2:
  // [3] call main 
  jsr main
  // [4] phi from @2 to @end [phi:@2->@end]
__bend_from___b2:
  jmp __bend
  // @end
__bend:
  // main
main: {
    // asm { lda#$ff sta$d406 sta$d40d sta$d414 lda#$49 sta$d404 sta$d40b sta$d412  }
    // Boosting 8580 Digis
    // See https://gist.github.com/munshkr/30f35e39905e63876ff7 (line 909)
    lda #$ff
    sta $d406
    sta $d40d
    sta $d414
    lda #$49
    sta $d404
    sta $d40b
    sta $d412
    // asm { sei  }
    sei
    // [7] *((const byte*) CIA2_INTERRUPT) ← (const byte) CIA_INTERRUPT_CLEAR -- _deref_pbuc1=vbuc2 
    lda #CIA_INTERRUPT_CLEAR
    sta CIA2_INTERRUPT
    // [8] *((const void()**) KERNEL_NMI) ← &interrupt(HARDWARE_ALL)(void()) nmi() -- _deref_pptc1=pprc2 
    lda #<nmi
    sta KERNEL_NMI
    lda #>nmi
    sta KERNEL_NMI+1
    // [9] *((const word*) CIA2_TIMER_A) ← (byte) $88 -- _deref_pwuc1=vbuc2 
    lda #0
    sta CIA2_TIMER_A+1
    lda #<$88
    sta CIA2_TIMER_A
    // [10] *((const byte*) CIA2_INTERRUPT) ← (byte) $81 -- _deref_pbuc1=vbuc2 
    // speed
    lda #$81
    sta CIA2_INTERRUPT
    // [11] *((const byte*) CIA2_TIMER_A_CONTROL) ← (byte) 1 -- _deref_pbuc1=vbuc2 
    lda #1
    sta CIA2_TIMER_A_CONTROL
    // asm { cli  }
    cli
    jmp __breturn
    // main::@return
  __breturn:
    // [13] return 
    rts
}
  // nmi2
nmi2: {
    .label __1 = 4
    .label __2 = 5
    // entry interrupt(HARDWARE_ALL)
    sta rega+1
    stx regx+1
    sty regy+1
    // [14] *((const byte*) BORDERCOL) ← ++ *((const byte*) BORDERCOL) -- _deref_pbuc1=_inc__deref_pbuc1 
    inc BORDERCOL
    // asm { ldaCIA2_INTERRUPT  }
    lda CIA2_INTERRUPT
    // [16] (byte~) nmi2::$1 ← *((byte*) sample) >> (byte) 4 -- vbuz1=_deref_pbuz2_ror_4 
    ldy #0
    lda (sample),y
    lsr
    lsr
    lsr
    lsr
    sta.z __1
    // [17] *((const byte*) SID_VOLUME) ← (byte~) nmi2::$1 -- _deref_pbuc1=vbuz1 
    lda.z __1
    sta SID_VOLUME
    // [18] (byte*) sample ← ++ (byte*) sample -- pbuz1=_inc_pbuz1 
    inc.z sample
    bne !+
    inc.z sample+1
  !:
    // [19] (byte~) nmi2::$2 ← > (byte*) sample -- vbuz1=_hi_pbuz2 
    lda.z sample+1
    sta.z __2
    // [20] if((byte~) nmi2::$2!=>(const byte*) SAMPLE+(word) $6100) goto nmi2::@1 -- vbuz1_neq_vbuc1_then_la1 
    lda #>SAMPLE+$6100
    cmp.z __2
    bne __b1
    jmp __b2
    // nmi2::@2
  __b2:
    // [21] (byte*) sample ← (const byte*) SAMPLE -- pbuz1=pbuc1 
    lda #<SAMPLE
    sta.z sample
    lda #>SAMPLE
    sta.z sample+1
    jmp __b1
    // nmi2::@1
  __b1:
    // [22] *((const void()**) KERNEL_NMI) ← &interrupt(HARDWARE_ALL)(void()) nmi() -- _deref_pptc1=pprc2 
    lda #<nmi
    sta KERNEL_NMI
    lda #>nmi
    sta KERNEL_NMI+1
    // [23] *((const byte*) BORDERCOL) ← -- *((const byte*) BORDERCOL) -- _deref_pbuc1=_dec__deref_pbuc1 
    dec BORDERCOL
    jmp __breturn
    // nmi2::@return
  __breturn:
    // [24] return  - exit interrupt(HARDWARE_ALL)
  rega:
    lda #00
  regx:
    ldx #00
  regy:
    ldy #00
    rti
}
  // nmi
nmi: {
    .label __1 = 6
    // entry interrupt(HARDWARE_ALL)
    sta rega+1
    stx regx+1
    sty regy+1
    // [25] *((const byte*) BORDERCOL) ← ++ *((const byte*) BORDERCOL) -- _deref_pbuc1=_inc__deref_pbuc1 
    inc BORDERCOL
    // asm { ldaCIA2_INTERRUPT  }
    lda CIA2_INTERRUPT
    // [27] (byte~) nmi::$1 ← *((byte*) sample) & (byte) $f -- vbuz1=_deref_pbuz2_band_vbuc1 
    lda #$f
    ldy #0
    and (sample),y
    sta.z __1
    // [28] *((const byte*) SID_VOLUME) ← (byte~) nmi::$1 -- _deref_pbuc1=vbuz1 
    lda.z __1
    sta SID_VOLUME
    // [29] *((const void()**) KERNEL_NMI) ← &interrupt(HARDWARE_ALL)(void()) nmi2() -- _deref_pptc1=pprc2 
    lda #<nmi2
    sta KERNEL_NMI
    lda #>nmi2
    sta KERNEL_NMI+1
    // [30] *((const byte*) BORDERCOL) ← -- *((const byte*) BORDERCOL) -- _deref_pbuc1=_dec__deref_pbuc1 
    dec BORDERCOL
    jmp __breturn
    // nmi::@return
  __breturn:
    // [31] return  - exit interrupt(HARDWARE_ALL)
  rega:
    lda #00
  regx:
    ldx #00
  regy:
    ldy #00
    rti
}
  // File Data
SAMPLE:
.import binary "moments_sample.bin" 

REGISTER UPLIFT POTENTIAL REGISTERS
Statement [1] (byte*) sample ← (const byte*) SAMPLE [ ] (  [ ] ) always clobbers reg byte a 
Statement asm { lda#$ff sta$d406 sta$d40d sta$d414 lda#$49 sta$d404 sta$d40b sta$d412  } always clobbers reg byte a 
Statement [7] *((const byte*) CIA2_INTERRUPT) ← (const byte) CIA_INTERRUPT_CLEAR [ ] ( main:3 [ ] ) always clobbers reg byte a 
Statement [8] *((const void()**) KERNEL_NMI) ← &interrupt(HARDWARE_ALL)(void()) nmi() [ ] ( main:3 [ ] ) always clobbers reg byte a 
Statement [9] *((const word*) CIA2_TIMER_A) ← (byte) $88 [ ] ( main:3 [ ] ) always clobbers reg byte a 
Statement [10] *((const byte*) CIA2_INTERRUPT) ← (byte) $81 [ ] ( main:3 [ ] ) always clobbers reg byte a 
Statement [11] *((const byte*) CIA2_TIMER_A_CONTROL) ← (byte) 1 [ ] ( main:3 [ ] ) always clobbers reg byte a 
Statement asm { ldaCIA2_INTERRUPT  } always clobbers reg byte a 
Statement [16] (byte~) nmi2::$1 ← *((byte*) sample) >> (byte) 4 [ sample nmi2::$1 ] (  [ sample nmi2::$1 ] ) always clobbers reg byte a reg byte y 
Statement [21] (byte*) sample ← (const byte*) SAMPLE [ ] (  [ ] ) always clobbers reg byte a 
Statement [22] *((const void()**) KERNEL_NMI) ← &interrupt(HARDWARE_ALL)(void()) nmi() [ ] (  [ ] ) always clobbers reg byte a 
Statement [24] return  [ ] (  [ ] ) always clobbers reg byte a reg byte x reg byte y 
Statement asm { ldaCIA2_INTERRUPT  } always clobbers reg byte a 
Statement [27] (byte~) nmi::$1 ← *((byte*) sample) & (byte) $f [ nmi::$1 ] (  [ nmi::$1 ] ) always clobbers reg byte a reg byte y 
Statement [29] *((const void()**) KERNEL_NMI) ← &interrupt(HARDWARE_ALL)(void()) nmi2() [ ] (  [ ] ) always clobbers reg byte a 
Statement [31] return  [ ] (  [ ] ) always clobbers reg byte a reg byte x reg byte y 
Potential registers zp[2]:2 [ sample ] : zp[2]:2 , 
Potential registers zp[1]:4 [ nmi2::$1 ] : zp[1]:4 , reg byte a , reg byte x , reg byte y , 
Potential registers zp[1]:5 [ nmi2::$2 ] : zp[1]:5 , reg byte a , reg byte x , reg byte y , 
Potential registers zp[1]:6 [ nmi::$1 ] : zp[1]:6 , reg byte a , reg byte x , reg byte y , 

REGISTER UPLIFT SCOPES
Uplift Scope [nmi2] 4: zp[1]:4 [ nmi2::$1 ] 4: zp[1]:5 [ nmi2::$2 ] 
Uplift Scope [nmi] 4: zp[1]:6 [ nmi::$1 ] 
Uplift Scope [] 2: zp[2]:2 [ sample ] 
Uplift Scope [main] 

Uplifting [nmi2] best 534 combination reg byte a [ nmi2::$1 ] reg byte a [ nmi2::$2 ] 
Uplifting [nmi] best 528 combination reg byte a [ nmi::$1 ] 
Uplifting [] best 528 combination zp[2]:2 [ sample ] 
Uplifting [main] best 528 combination 

ASSEMBLER BEFORE OPTIMIZATION
  // File Comments
// NMI Sample Player using the SID volume register
// Code by Scan of Desire (Richard-William Loerakker)
// Sample from ART OF NOISE: MOMENTS IN LOVE
  // Upstart
.pc = $801 "Basic"
:BasicUpstart(__bbegin)
.pc = $80d "Program"
  // Global Constants & labels
  .label BORDERCOL = $d020
  // CIA #2 Timer A Value (16-bit)
  .label CIA2_TIMER_A = $dd04
  // CIA #2 Interrupt Status & Control Register
  .label CIA2_INTERRUPT = $dd0d
  // CIA #2 Timer A Control Register
  .label CIA2_TIMER_A_CONTROL = $dd0e
  // Value that disables all CIA interrupts when stored to the CIA Interrupt registers
  .const CIA_INTERRUPT_CLEAR = $7f
  // The vector used when the KERNAL serves NMI interrupts
  .label KERNEL_NMI = $318
  // The SID volume
  .label SID_VOLUME = $d418
  .const SAMPLE_SIZE = $6100
  .label sample = 2
  // @begin
__bbegin:
  jmp __b1
  // @1
__b1:
  // [1] (byte*) sample ← (const byte*) SAMPLE -- pbuz1=pbuc1 
  lda #<SAMPLE
  sta.z sample
  lda #>SAMPLE
  sta.z sample+1
  // [2] phi from @1 to @2 [phi:@1->@2]
__b2_from___b1:
  jmp __b2
  // @2
__b2:
  // [3] call main 
  jsr main
  // [4] phi from @2 to @end [phi:@2->@end]
__bend_from___b2:
  jmp __bend
  // @end
__bend:
  // main
main: {
    // asm { lda#$ff sta$d406 sta$d40d sta$d414 lda#$49 sta$d404 sta$d40b sta$d412  }
    // Boosting 8580 Digis
    // See https://gist.github.com/munshkr/30f35e39905e63876ff7 (line 909)
    lda #$ff
    sta $d406
    sta $d40d
    sta $d414
    lda #$49
    sta $d404
    sta $d40b
    sta $d412
    // asm { sei  }
    sei
    // [7] *((const byte*) CIA2_INTERRUPT) ← (const byte) CIA_INTERRUPT_CLEAR -- _deref_pbuc1=vbuc2 
    lda #CIA_INTERRUPT_CLEAR
    sta CIA2_INTERRUPT
    // [8] *((const void()**) KERNEL_NMI) ← &interrupt(HARDWARE_ALL)(void()) nmi() -- _deref_pptc1=pprc2 
    lda #<nmi
    sta KERNEL_NMI
    lda #>nmi
    sta KERNEL_NMI+1
    // [9] *((const word*) CIA2_TIMER_A) ← (byte) $88 -- _deref_pwuc1=vbuc2 
    lda #0
    sta CIA2_TIMER_A+1
    lda #<$88
    sta CIA2_TIMER_A
    // [10] *((const byte*) CIA2_INTERRUPT) ← (byte) $81 -- _deref_pbuc1=vbuc2 
    // speed
    lda #$81
    sta CIA2_INTERRUPT
    // [11] *((const byte*) CIA2_TIMER_A_CONTROL) ← (byte) 1 -- _deref_pbuc1=vbuc2 
    lda #1
    sta CIA2_TIMER_A_CONTROL
    // asm { cli  }
    cli
    jmp __breturn
    // main::@return
  __breturn:
    // [13] return 
    rts
}
  // nmi2
nmi2: {
    // entry interrupt(HARDWARE_ALL)
    sta rega+1
    stx regx+1
    sty regy+1
    // [14] *((const byte*) BORDERCOL) ← ++ *((const byte*) BORDERCOL) -- _deref_pbuc1=_inc__deref_pbuc1 
    inc BORDERCOL
    // asm { ldaCIA2_INTERRUPT  }
    lda CIA2_INTERRUPT
    // [16] (byte~) nmi2::$1 ← *((byte*) sample) >> (byte) 4 -- vbuaa=_deref_pbuz1_ror_4 
    ldy #0
    lda (sample),y
    lsr
    lsr
    lsr
    lsr
    // [17] *((const byte*) SID_VOLUME) ← (byte~) nmi2::$1 -- _deref_pbuc1=vbuaa 
    sta SID_VOLUME
    // [18] (byte*) sample ← ++ (byte*) sample -- pbuz1=_inc_pbuz1 
    inc.z sample
    bne !+
    inc.z sample+1
  !:
    // [19] (byte~) nmi2::$2 ← > (byte*) sample -- vbuaa=_hi_pbuz1 
    lda.z sample+1
    // [20] if((byte~) nmi2::$2!=>(const byte*) SAMPLE+(word) $6100) goto nmi2::@1 -- vbuaa_neq_vbuc1_then_la1 
    cmp #>SAMPLE+$6100
    bne __b1
    jmp __b2
    // nmi2::@2
  __b2:
    // [21] (byte*) sample ← (const byte*) SAMPLE -- pbuz1=pbuc1 
    lda #<SAMPLE
    sta.z sample
    lda #>SAMPLE
    sta.z sample+1
    jmp __b1
    // nmi2::@1
  __b1:
    // [22] *((const void()**) KERNEL_NMI) ← &interrupt(HARDWARE_ALL)(void()) nmi() -- _deref_pptc1=pprc2 
    lda #<nmi
    sta KERNEL_NMI
    lda #>nmi
    sta KERNEL_NMI+1
    // [23] *((const byte*) BORDERCOL) ← -- *((const byte*) BORDERCOL) -- _deref_pbuc1=_dec__deref_pbuc1 
    dec BORDERCOL
    jmp __breturn
    // nmi2::@return
  __breturn:
    // [24] return  - exit interrupt(HARDWARE_ALL)
  rega:
    lda #00
  regx:
    ldx #00
  regy:
    ldy #00
    rti
}
  // nmi
nmi: {
    // entry interrupt(HARDWARE_ALL)
    sta rega+1
    stx regx+1
    sty regy+1
    // [25] *((const byte*) BORDERCOL) ← ++ *((const byte*) BORDERCOL) -- _deref_pbuc1=_inc__deref_pbuc1 
    inc BORDERCOL
    // asm { ldaCIA2_INTERRUPT  }
    lda CIA2_INTERRUPT
    // [27] (byte~) nmi::$1 ← *((byte*) sample) & (byte) $f -- vbuaa=_deref_pbuz1_band_vbuc1 
    lda #$f
    ldy #0
    and (sample),y
    // [28] *((const byte*) SID_VOLUME) ← (byte~) nmi::$1 -- _deref_pbuc1=vbuaa 
    sta SID_VOLUME
    // [29] *((const void()**) KERNEL_NMI) ← &interrupt(HARDWARE_ALL)(void()) nmi2() -- _deref_pptc1=pprc2 
    lda #<nmi2
    sta KERNEL_NMI
    lda #>nmi2
    sta KERNEL_NMI+1
    // [30] *((const byte*) BORDERCOL) ← -- *((const byte*) BORDERCOL) -- _deref_pbuc1=_dec__deref_pbuc1 
    dec BORDERCOL
    jmp __breturn
    // nmi::@return
  __breturn:
    // [31] return  - exit interrupt(HARDWARE_ALL)
  rega:
    lda #00
  regx:
    ldx #00
  regy:
    ldy #00
    rti
}
  // File Data
SAMPLE:
.import binary "moments_sample.bin" 

ASSEMBLER OPTIMIZATIONS
Removing instruction jmp __b1
Removing instruction jmp __b2
Removing instruction jmp __bend
Removing instruction jmp __breturn
Removing instruction jmp __b2
Removing instruction jmp __b1
Removing instruction jmp __breturn
Removing instruction jmp __breturn
Succesful ASM optimization Pass5NextJumpElimination
Replacing label __bbegin with __b1
Removing instruction __bbegin:
Removing instruction __b2_from___b1:
Removing instruction __bend_from___b2:
Removing instruction __breturn:
Removing instruction __breturn:
Succesful ASM optimization Pass5RedundantLabelElimination
Removing instruction __b2:
Removing instruction __bend:
Removing instruction __breturn:
Removing instruction __b2:
Succesful ASM optimization Pass5UnusedLabelElimination
Adding RTS to root block 
Succesful ASM optimization Pass5AddMainRts

FINAL SYMBOL TABLE
(label) @1
(label) @2
(label) @begin
(label) @end
(const byte*) BORDERCOL = (byte*) 53280
(const byte*) CIA2_INTERRUPT = (byte*) 56589
(const word*) CIA2_TIMER_A = (word*) 56580
(const byte*) CIA2_TIMER_A_CONTROL = (byte*) 56590
(const byte) CIA_INTERRUPT_CLEAR = (byte) $7f
(const void()**) KERNEL_NMI = (void()**) 792
(const byte*) SAMPLE[(const word) SAMPLE_SIZE]  = kickasm {{ .import binary "moments_sample.bin"  }}
(const word) SAMPLE_SIZE = (word) $6100
(const byte*) SID_VOLUME = (byte*) 54296
(void()) main()
(label) main::@return
interrupt(HARDWARE_ALL)(void()) nmi()
(byte~) nmi::$1 reg byte a 4.0
(label) nmi::@return
interrupt(HARDWARE_ALL)(void()) nmi2()
(byte~) nmi2::$1 reg byte a 4.0
(byte~) nmi2::$2 reg byte a 4.0
(label) nmi2::@1
(label) nmi2::@2
(label) nmi2::@return
(byte*) sample loadstore zp[2]:2 1.9999999999999996

zp[2]:2 [ sample ]
reg byte a [ nmi2::$1 ]
reg byte a [ nmi2::$2 ]
reg byte a [ nmi::$1 ]


FINAL ASSEMBLER
Score: 483

  // File Comments
// NMI Sample Player using the SID volume register
// Code by Scan of Desire (Richard-William Loerakker)
// Sample from ART OF NOISE: MOMENTS IN LOVE
  // Upstart
.pc = $801 "Basic"
:BasicUpstart(__b1)
.pc = $80d "Program"
  // Global Constants & labels
  .label BORDERCOL = $d020
  // CIA #2 Timer A Value (16-bit)
  .label CIA2_TIMER_A = $dd04
  // CIA #2 Interrupt Status & Control Register
  .label CIA2_INTERRUPT = $dd0d
  // CIA #2 Timer A Control Register
  .label CIA2_TIMER_A_CONTROL = $dd0e
  // Value that disables all CIA interrupts when stored to the CIA Interrupt registers
  .const CIA_INTERRUPT_CLEAR = $7f
  // The vector used when the KERNAL serves NMI interrupts
  .label KERNEL_NMI = $318
  // The SID volume
  .label SID_VOLUME = $d418
  .const SAMPLE_SIZE = $6100
  .label sample = 2
  // @begin
  // @1
__b1:
  // sample = SAMPLE
  // [1] (byte*) sample ← (const byte*) SAMPLE -- pbuz1=pbuc1 
  lda #<SAMPLE
  sta.z sample
  lda #>SAMPLE
  sta.z sample+1
  // [2] phi from @1 to @2 [phi:@1->@2]
  // @2
  // [3] call main 
  jsr main
  rts
  // [4] phi from @2 to @end [phi:@2->@end]
  // @end
  // main
main: {
    // asm
    // asm { lda#$ff sta$d406 sta$d40d sta$d414 lda#$49 sta$d404 sta$d40b sta$d412  }
    // Boosting 8580 Digis
    // See https://gist.github.com/munshkr/30f35e39905e63876ff7 (line 909)
    lda #$ff
    sta $d406
    sta $d40d
    sta $d414
    lda #$49
    sta $d404
    sta $d40b
    sta $d412
    // asm { sei  }
    sei
    // *CIA2_INTERRUPT = CIA_INTERRUPT_CLEAR
    // [7] *((const byte*) CIA2_INTERRUPT) ← (const byte) CIA_INTERRUPT_CLEAR -- _deref_pbuc1=vbuc2 
    lda #CIA_INTERRUPT_CLEAR
    sta CIA2_INTERRUPT
    // *KERNEL_NMI = &nmi
    // [8] *((const void()**) KERNEL_NMI) ← &interrupt(HARDWARE_ALL)(void()) nmi() -- _deref_pptc1=pprc2 
    lda #<nmi
    sta KERNEL_NMI
    lda #>nmi
    sta KERNEL_NMI+1
    // *CIA2_TIMER_A = 0x88
    // [9] *((const word*) CIA2_TIMER_A) ← (byte) $88 -- _deref_pwuc1=vbuc2 
    lda #0
    sta CIA2_TIMER_A+1
    lda #<$88
    sta CIA2_TIMER_A
    // *CIA2_INTERRUPT = 0x81
    // [10] *((const byte*) CIA2_INTERRUPT) ← (byte) $81 -- _deref_pbuc1=vbuc2 
    // speed
    lda #$81
    sta CIA2_INTERRUPT
    // *CIA2_TIMER_A_CONTROL = 0x01
    // [11] *((const byte*) CIA2_TIMER_A_CONTROL) ← (byte) 1 -- _deref_pbuc1=vbuc2 
    lda #1
    sta CIA2_TIMER_A_CONTROL
    // asm
    // asm { cli  }
    cli
    // main::@return
    // }
    // [13] return 
    rts
}
  // nmi2
nmi2: {
    // entry interrupt(HARDWARE_ALL)
    sta rega+1
    stx regx+1
    sty regy+1
    // (*BORDERCOL)++;
    // [14] *((const byte*) BORDERCOL) ← ++ *((const byte*) BORDERCOL) -- _deref_pbuc1=_inc__deref_pbuc1 
    inc BORDERCOL
    // asm
    // asm { ldaCIA2_INTERRUPT  }
    lda CIA2_INTERRUPT
    // *sample >> 4
    // [16] (byte~) nmi2::$1 ← *((byte*) sample) >> (byte) 4 -- vbuaa=_deref_pbuz1_ror_4 
    ldy #0
    lda (sample),y
    lsr
    lsr
    lsr
    lsr
    // *SID_VOLUME = *sample >> 4
    // [17] *((const byte*) SID_VOLUME) ← (byte~) nmi2::$1 -- _deref_pbuc1=vbuaa 
    sta SID_VOLUME
    // sample++;
    // [18] (byte*) sample ← ++ (byte*) sample -- pbuz1=_inc_pbuz1 
    inc.z sample
    bne !+
    inc.z sample+1
  !:
    // >sample
    // [19] (byte~) nmi2::$2 ← > (byte*) sample -- vbuaa=_hi_pbuz1 
    lda.z sample+1
    // if (>sample == >(SAMPLE+$6100))
    // [20] if((byte~) nmi2::$2!=>(const byte*) SAMPLE+(word) $6100) goto nmi2::@1 -- vbuaa_neq_vbuc1_then_la1 
    cmp #>SAMPLE+$6100
    bne __b1
    // nmi2::@2
    // sample = SAMPLE
    // [21] (byte*) sample ← (const byte*) SAMPLE -- pbuz1=pbuc1 
    lda #<SAMPLE
    sta.z sample
    lda #>SAMPLE
    sta.z sample+1
    // nmi2::@1
  __b1:
    // *KERNEL_NMI = &nmi
    // [22] *((const void()**) KERNEL_NMI) ← &interrupt(HARDWARE_ALL)(void()) nmi() -- _deref_pptc1=pprc2 
    lda #<nmi
    sta KERNEL_NMI
    lda #>nmi
    sta KERNEL_NMI+1
    // (*BORDERCOL)--;
    // [23] *((const byte*) BORDERCOL) ← -- *((const byte*) BORDERCOL) -- _deref_pbuc1=_dec__deref_pbuc1 
    dec BORDERCOL
    // nmi2::@return
    // }
    // [24] return  - exit interrupt(HARDWARE_ALL)
  rega:
    lda #00
  regx:
    ldx #00
  regy:
    ldy #00
    rti
}
  // nmi
nmi: {
    // entry interrupt(HARDWARE_ALL)
    sta rega+1
    stx regx+1
    sty regy+1
    // (*BORDERCOL)++;
    // [25] *((const byte*) BORDERCOL) ← ++ *((const byte*) BORDERCOL) -- _deref_pbuc1=_inc__deref_pbuc1 
    inc BORDERCOL
    // asm
    // asm { ldaCIA2_INTERRUPT  }
    lda CIA2_INTERRUPT
    // *sample & $0f
    // [27] (byte~) nmi::$1 ← *((byte*) sample) & (byte) $f -- vbuaa=_deref_pbuz1_band_vbuc1 
    lda #$f
    ldy #0
    and (sample),y
    // *SID_VOLUME = *sample & $0f
    // [28] *((const byte*) SID_VOLUME) ← (byte~) nmi::$1 -- _deref_pbuc1=vbuaa 
    sta SID_VOLUME
    // *KERNEL_NMI = &nmi2
    // [29] *((const void()**) KERNEL_NMI) ← &interrupt(HARDWARE_ALL)(void()) nmi2() -- _deref_pptc1=pprc2 
    lda #<nmi2
    sta KERNEL_NMI
    lda #>nmi2
    sta KERNEL_NMI+1
    // (*BORDERCOL)--;
    // [30] *((const byte*) BORDERCOL) ← -- *((const byte*) BORDERCOL) -- _deref_pbuc1=_dec__deref_pbuc1 
    dec BORDERCOL
    // nmi::@return
    // }
    // [31] return  - exit interrupt(HARDWARE_ALL)
  rega:
    lda #00
  regx:
    ldx #00
  regy:
    ldy #00
    rti
}
  // File Data
SAMPLE:
.import binary "moments_sample.bin" 

