
CONTROL FLOW GRAPH SSA

void main()
main: scope:[main]  from __start
  main::k#0 = 0
  to:main::@1
main::@1: scope:[main]  from main main::@5
  main::k#6 = phi( main/main::k#0, main::@5/main::k#1 )
  main::l#0 = 0
  to:main::@2
main::@2: scope:[main]  from main::@1 main::@4
  main::k#5 = phi( main::@1/main::k#6, main::@4/main::k#3 )
  main::l#4 = phi( main::@1/main::l#0, main::@4/main::l#1 )
  main::m#0 = 0
  to:main::@3
main::@3: scope:[main]  from main::@2 main::@3
  main::k#4 = phi( main::@2/main::k#5, main::@3/main::k#4 )
  main::l#3 = phi( main::@2/main::l#4, main::@3/main::l#3 )
  main::m#2 = phi( main::@2/main::m#0, main::@3/main::m#1 )
  kickasm( uses SCREEN) {{ lda #0
                    ldx #0
                    sta SCREEN,x
                 }}
  main::m#1 = main::m#2 + rangenext(0,$a)
  main::$0 = main::m#1 != rangelast(0,$a)
  if(main::$0) goto main::@3
  to:main::@4
main::@4: scope:[main]  from main::@3
  main::k#3 = phi( main::@3/main::k#4 )
  main::l#2 = phi( main::@3/main::l#3 )
  main::l#1 = main::l#2 + rangenext(0,$a)
  main::$1 = main::l#1 != rangelast(0,$a)
  if(main::$1) goto main::@2
  to:main::@5
main::@5: scope:[main]  from main::@4
  main::k#2 = phi( main::@4/main::k#3 )
  main::k#1 = main::k#2 + rangenext(0,$a)
  main::$2 = main::k#1 != rangelast(0,$a)
  if(main::$2) goto main::@1
  to:main::@return
main::@return: scope:[main]  from main::@5
  return 
  to:@return

void __start()
__start: scope:[__start]  from
  call main
  to:__start::@1
__start::@1: scope:[__start]  from __start
  to:__start::@return
__start::@return: scope:[__start]  from __start::@1
  return 
  to:@return

SYMBOL TABLE SSA
__constant char * const SCREEN = (char *)$400
void __start()
void main()
bool main::$0
bool main::$1
bool main::$2
char main::k
char main::k#0
char main::k#1
char main::k#2
char main::k#3
char main::k#4
char main::k#5
char main::k#6
char main::l
char main::l#0
char main::l#1
char main::l#2
char main::l#3
char main::l#4
char main::m
char main::m#0
char main::m#1
char main::m#2

Simplifying constant pointer cast (char *) 1024
Successful SSA optimization PassNCastSimplification
Alias main::l#2 = main::l#3 
Alias main::k#2 = main::k#3 main::k#4 
Successful SSA optimization Pass2AliasElimination
Identical Phi Values main::l#2 main::l#4
Identical Phi Values main::k#2 main::k#5
Successful SSA optimization Pass2IdenticalPhiElimination
Identical Phi Values main::k#5 main::k#6
Successful SSA optimization Pass2IdenticalPhiElimination
Simple Condition main::$0 [9] if(main::m#1!=rangelast(0,$a)) goto main::@3
Simple Condition main::$1 [12] if(main::l#1!=rangelast(0,$a)) goto main::@2
Simple Condition main::$2 [15] if(main::k#1!=rangelast(0,$a)) goto main::@1
Successful SSA optimization Pass2ConditionalJumpSimplification
Constant main::k#0 = 0
Constant main::l#0 = 0
Constant main::m#0 = 0
Successful SSA optimization Pass2ConstantIdentification
Resolved ranged next value [7] main::m#1 = ++ main::m#2 to ++
Resolved ranged comparison value [9] if(main::m#1!=rangelast(0,$a)) goto main::@3 to $b
Resolved ranged next value [10] main::l#1 = ++ main::l#4 to ++
Resolved ranged comparison value [12] if(main::l#1!=rangelast(0,$a)) goto main::@2 to $b
Resolved ranged next value [13] main::k#1 = ++ main::k#6 to ++
Resolved ranged comparison value [15] if(main::k#1!=rangelast(0,$a)) goto main::@1 to $b
Removing unused procedure __start
Removing unused procedure block __start
Removing unused procedure block __start::@1
Removing unused procedure block __start::@return
Successful SSA optimization PassNEliminateEmptyStart
Adding number conversion cast (unumber) $b in [5] if(main::m#1!=$b) goto main::@3
Adding number conversion cast (unumber) $b in [7] if(main::l#1!=$b) goto main::@2
Adding number conversion cast (unumber) $b in [9] if(main::k#1!=$b) goto main::@1
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 (char) $b
Finalized unsigned number type (char) $b
Finalized unsigned number type (char) $b
Successful SSA optimization PassNFinalizeNumberTypeConversions
Inlining constant with var siblings main::k#0
Inlining constant with var siblings main::l#0
Inlining constant with var siblings main::m#0
Constant inlined main::k#0 = 0
Constant inlined main::m#0 = 0
Constant inlined main::l#0 = 0
Successful SSA optimization Pass2ConstantInlining
Added new block during phi lifting main::@6(between main::@5 and main::@1)
Added new block during phi lifting main::@7(between main::@4 and main::@2)
Added new block during phi lifting main::@8(between main::@3 and main::@3)
Adding NOP phi() at start of main
CALL GRAPH

Created 3 initial phi equivalence classes
Coalesced [12] main::k#7 = main::k#1
Coalesced [13] main::l#5 = main::l#1
Coalesced [14] main::m#3 = main::m#1
Coalesced down to 3 phi equivalence classes
Culled Empty Block label main::@6
Culled Empty Block label main::@7
Culled Empty Block label main::@8
Adding NOP phi() at start of main

FINAL CONTROL FLOW GRAPH

void main()
main: scope:[main]  from
  [0] phi()
  to:main::@1
main::@1: scope:[main]  from main main::@5
  [1] main::k#6 = phi( main/0, main::@5/main::k#1 )
  to:main::@2
main::@2: scope:[main]  from main::@1 main::@4
  [2] main::l#4 = phi( main::@1/0, main::@4/main::l#1 )
  to:main::@3
main::@3: scope:[main]  from main::@2 main::@3
  [3] main::m#2 = phi( main::@2/0, main::@3/main::m#1 )
  kickasm( uses SCREEN) {{ lda #0
                    ldx #0
                    sta SCREEN,x
                 }}
  [5] main::m#1 = ++ main::m#2
  [6] if(main::m#1!=$b) goto main::@3
  to:main::@4
main::@4: scope:[main]  from main::@3
  [7] main::l#1 = ++ main::l#4
  [8] if(main::l#1!=$b) goto main::@2
  to:main::@5
main::@5: scope:[main]  from main::@4
  [9] main::k#1 = ++ main::k#6
  [10] if(main::k#1!=$b) goto main::@1
  to:main::@return
main::@return: scope:[main]  from main::@5
  [11] return 
  to:@return


VARIABLE REGISTER WEIGHTS
void main()
char main::k
char main::k#1 // 16.5
char main::k#6 // 2.75
char main::l
char main::l#1 // 151.5
char main::l#4 // 40.4
char main::m
char main::m#1 // 1501.5
char main::m#2 // 1001.0

Initial phi equivalence classes
[ main::k#6 main::k#1 ]
[ main::l#4 main::l#1 ]
[ main::m#2 main::m#1 ]
Complete equivalence classes
[ main::k#6 main::k#1 ]
[ main::l#4 main::l#1 ]
[ main::m#2 main::m#1 ]
Allocated zp[1]:2 [ main::m#2 main::m#1 ]
Allocated zp[1]:3 [ main::l#4 main::l#1 ]
Allocated zp[1]:4 [ main::k#6 main::k#1 ]
REGISTER UPLIFT POTENTIAL REGISTERS
Statement kickasm( uses SCREEN) {{ lda #0
                    ldx #0
                    sta SCREEN,x
                 }} always clobbers reg byte a reg byte x 
Removing always clobbered register reg byte a as potential for zp[1]:4 [ main::k#6 main::k#1 ]
Removing always clobbered register reg byte x as potential for zp[1]:4 [ main::k#6 main::k#1 ]
Removing always clobbered register reg byte a as potential for zp[1]:3 [ main::l#4 main::l#1 ]
Removing always clobbered register reg byte x as potential for zp[1]:3 [ main::l#4 main::l#1 ]
Removing always clobbered register reg byte a as potential for zp[1]:2 [ main::m#2 main::m#1 ]
Removing always clobbered register reg byte x as potential for zp[1]:2 [ main::m#2 main::m#1 ]
Statement kickasm( uses SCREEN) {{ lda #0
                    ldx #0
                    sta SCREEN,x
                 }} always clobbers reg byte a reg byte x 
Potential registers zp[1]:4 [ main::k#6 main::k#1 ] : zp[1]:4 , reg byte y , 
Potential registers zp[1]:3 [ main::l#4 main::l#1 ] : zp[1]:3 , reg byte y , 
Potential registers zp[1]:2 [ main::m#2 main::m#1 ] : zp[1]:2 , reg byte y , 

REGISTER UPLIFT SCOPES
Uplift Scope [main] 2,502.5: zp[1]:2 [ main::m#2 main::m#1 ] 191.9: zp[1]:3 [ main::l#4 main::l#1 ] 19.25: zp[1]:4 [ main::k#6 main::k#1 ] 
Uplift Scope [] 

Uplifting [main] best 276421 combination reg byte y [ main::m#2 main::m#1 ] zp[1]:3 [ main::l#4 main::l#1 ] zp[1]:4 [ main::k#6 main::k#1 ] 
Uplifting [] best 276421 combination 
Attempting to uplift remaining variables inzp[1]:3 [ main::l#4 main::l#1 ]
Uplifting [main] best 276421 combination zp[1]:3 [ main::l#4 main::l#1 ] 
Attempting to uplift remaining variables inzp[1]:4 [ main::k#6 main::k#1 ]
Uplifting [main] best 276421 combination zp[1]:4 [ main::k#6 main::k#1 ] 
Allocated (was zp[1]:3) zp[1]:2 [ main::l#4 main::l#1 ]
Allocated (was zp[1]:4) zp[1]:3 [ main::k#6 main::k#1 ]

ASSEMBLER BEFORE OPTIMIZATION
  // File Comments
// Tests that inline kickasm supports the clobbering directive
  // Upstart
  // Commodore 64 PRG executable file
.file [name="inline-kasm-clobber.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(main)
  // Global Constants & labels
  .label SCREEN = $400
.segment Code
  // main
main: {
    .label l = 2
    .label k = 3
    // [1] phi from main to main::@1 [phi:main->main::@1]
  __b1_from_main:
    // [1] phi main::k#6 = 0 [phi:main->main::@1#0] -- vbuz1=vbuc1 
    lda #0
    sta.z k
    jmp __b1
    // [1] phi from main::@5 to main::@1 [phi:main::@5->main::@1]
  __b1_from___b5:
    // [1] phi main::k#6 = main::k#1 [phi:main::@5->main::@1#0] -- register_copy 
    jmp __b1
    // main::@1
  __b1:
    // [2] phi from main::@1 to main::@2 [phi:main::@1->main::@2]
  __b2_from___b1:
    // [2] phi main::l#4 = 0 [phi:main::@1->main::@2#0] -- vbuz1=vbuc1 
    lda #0
    sta.z l
    jmp __b2
    // [2] phi from main::@4 to main::@2 [phi:main::@4->main::@2]
  __b2_from___b4:
    // [2] phi main::l#4 = main::l#1 [phi:main::@4->main::@2#0] -- register_copy 
    jmp __b2
    // main::@2
  __b2:
    // [3] phi from main::@2 to main::@3 [phi:main::@2->main::@3]
  __b3_from___b2:
    // [3] phi main::m#2 = 0 [phi:main::@2->main::@3#0] -- vbuyy=vbuc1 
    ldy #0
    jmp __b3
    // [3] phi from main::@3 to main::@3 [phi:main::@3->main::@3]
  __b3_from___b3:
    // [3] phi main::m#2 = main::m#1 [phi:main::@3->main::@3#0] -- register_copy 
    jmp __b3
    // main::@3
  __b3:
    // kickasm( uses SCREEN) {{ lda #0                     ldx #0                     sta SCREEN,x                  }}
    lda #0
                    ldx #0
                    sta SCREEN,x
                
    // [5] main::m#1 = ++ main::m#2 -- vbuyy=_inc_vbuyy 
    iny
    // [6] if(main::m#1!=$b) goto main::@3 -- vbuyy_neq_vbuc1_then_la1 
    cpy #$b
    bne __b3_from___b3
    jmp __b4
    // main::@4
  __b4:
    // [7] main::l#1 = ++ main::l#4 -- vbuz1=_inc_vbuz1 
    inc.z l
    // [8] if(main::l#1!=$b) goto main::@2 -- vbuz1_neq_vbuc1_then_la1 
    lda #$b
    cmp.z l
    bne __b2_from___b4
    jmp __b5
    // main::@5
  __b5:
    // [9] main::k#1 = ++ main::k#6 -- vbuz1=_inc_vbuz1 
    inc.z k
    // [10] if(main::k#1!=$b) goto main::@1 -- vbuz1_neq_vbuc1_then_la1 
    lda #$b
    cmp.z k
    bne __b1_from___b5
    jmp __breturn
    // main::@return
  __breturn:
    // [11] return 
    rts
}
  // File Data

ASSEMBLER OPTIMIZATIONS
Removing instruction jmp __b1
Removing instruction jmp __b2
Removing instruction jmp __b3
Removing instruction jmp __b4
Removing instruction jmp __b5
Removing instruction jmp __breturn
Succesful ASM optimization Pass5NextJumpElimination
Replacing label __b3_from___b3 with __b3
Replacing label __b2_from___b4 with __b2
Replacing label __b1_from___b5 with __b1
Removing instruction __b1_from___b5:
Removing instruction __b2_from___b1:
Removing instruction __b2_from___b4:
Removing instruction __b3_from___b2:
Removing instruction __b3_from___b3:
Succesful ASM optimization Pass5RedundantLabelElimination
Removing instruction __b1_from_main:
Removing instruction __b4:
Removing instruction __b5:
Removing instruction __breturn:
Succesful ASM optimization Pass5UnusedLabelElimination
Removing instruction jmp __b1
Removing instruction jmp __b2
Removing instruction jmp __b3
Succesful ASM optimization Pass5NextJumpElimination
Removing instruction lda #$b
Succesful ASM optimization Pass5UnnecesaryLoadElimination

FINAL SYMBOL TABLE
__constant char * const SCREEN = (char *) 1024
void main()
char main::k
char main::k#1 // k zp[1]:3 16.5
char main::k#6 // k zp[1]:3 2.75
char main::l
char main::l#1 // l zp[1]:2 151.5
char main::l#4 // l zp[1]:2 40.4
char main::m
char main::m#1 // reg byte y 1501.5
char main::m#2 // reg byte y 1001.0

zp[1]:3 [ main::k#6 main::k#1 ]
zp[1]:2 [ main::l#4 main::l#1 ]
reg byte y [ main::m#2 main::m#1 ]


FINAL ASSEMBLER
Score: 266411

  // File Comments
// Tests that inline kickasm supports the clobbering directive
  // Upstart
  // Commodore 64 PRG executable file
.file [name="inline-kasm-clobber.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(main)
  // Global Constants & labels
  .label SCREEN = $400
.segment Code
  // main
main: {
    .label l = 2
    .label k = 3
    // [1] phi from main to main::@1 [phi:main->main::@1]
    // [1] phi main::k#6 = 0 [phi:main->main::@1#0] -- vbuz1=vbuc1 
    lda #0
    sta.z k
    // [1] phi from main::@5 to main::@1 [phi:main::@5->main::@1]
    // [1] phi main::k#6 = main::k#1 [phi:main::@5->main::@1#0] -- register_copy 
    // main::@1
  __b1:
    // [2] phi from main::@1 to main::@2 [phi:main::@1->main::@2]
    // [2] phi main::l#4 = 0 [phi:main::@1->main::@2#0] -- vbuz1=vbuc1 
    lda #0
    sta.z l
    // [2] phi from main::@4 to main::@2 [phi:main::@4->main::@2]
    // [2] phi main::l#4 = main::l#1 [phi:main::@4->main::@2#0] -- register_copy 
    // main::@2
  __b2:
    // [3] phi from main::@2 to main::@3 [phi:main::@2->main::@3]
    // [3] phi main::m#2 = 0 [phi:main::@2->main::@3#0] -- vbuyy=vbuc1 
    ldy #0
    // [3] phi from main::@3 to main::@3 [phi:main::@3->main::@3]
    // [3] phi main::m#2 = main::m#1 [phi:main::@3->main::@3#0] -- register_copy 
    // main::@3
  __b3:
    // kickasm
    // kickasm( uses SCREEN) {{ lda #0                     ldx #0                     sta SCREEN,x                  }}
    lda #0
                    ldx #0
                    sta SCREEN,x
                
    // for(byte m: 0..10)
    // [5] main::m#1 = ++ main::m#2 -- vbuyy=_inc_vbuyy 
    iny
    // [6] if(main::m#1!=$b) goto main::@3 -- vbuyy_neq_vbuc1_then_la1 
    cpy #$b
    bne __b3
    // main::@4
    // for(byte l: 0..10)
    // [7] main::l#1 = ++ main::l#4 -- vbuz1=_inc_vbuz1 
    inc.z l
    // [8] if(main::l#1!=$b) goto main::@2 -- vbuz1_neq_vbuc1_then_la1 
    lda #$b
    cmp.z l
    bne __b2
    // main::@5
    // for(byte k : 0..10)
    // [9] main::k#1 = ++ main::k#6 -- vbuz1=_inc_vbuz1 
    inc.z k
    // [10] if(main::k#1!=$b) goto main::@1 -- vbuz1_neq_vbuc1_then_la1 
    cmp.z k
    bne __b1
    // main::@return
    // }
    // [11] return 
    rts
}
  // File Data

