Loading link script "linking.ld"
Resolved forward reference base to (const byte*) base
Resolved forward reference base to (const byte*) base
Identified constant variable (byte*) BGCOL
Identified constant variable (byte*) SCREEN
Culled Empty Block (label) main::@2
Culled Empty Block (label) main::@6
Culled Empty Block (label) main::@5
Culled Empty Block (label) main::@7
Culled Empty Block (label) main::@8
Culled Empty Block (label) @1
Culled Empty Block (label) fillscreen::@4
Culled Empty Block (label) fillscreen::@3
Culled Empty Block (label) fillscreen::@5
Culled Empty Block (label) fillscreen::@6

CONTROL FLOW GRAPH SSA
@begin: scope:[]  from
  to:@2

(void()) main()
main: scope:[main]  from @2
  (byte) main::i#0 ← (byte) 0
  to:main::@1
main::@1: scope:[main]  from main main::@1
  (byte) main::i#2 ← phi( main/(byte) main::i#0 main::@1/(byte) main::i#1 )
  *((const byte*) base + (byte) main::i#2) ← (byte) main::i#2
  (byte) main::i#1 ← (byte) main::i#2 + rangenext(0,$ff)
  (bool~) main::$0 ← (byte) main::i#1 != rangelast(0,$ff)
  if((bool~) main::$0) goto main::@1
  to:main::@3
main::@3: scope:[main]  from main::@1 main::@9
  if(true) goto main::@4
  to:main::@return
main::@4: scope:[main]  from main::@3
  (byte) fillscreen::c#0 ← *((const byte*) BGCOL)
  call fillscreen 
  to:main::@9
main::@9: scope:[main]  from main::@4
  *((const byte*) BGCOL) ← ++ *((const byte*) BGCOL)
  to:main::@3
main::@return: scope:[main]  from main::@3
  return 
  to:@return

(void()) fillscreen((byte) fillscreen::c)
fillscreen: scope:[fillscreen]  from main::@4
  (byte) fillscreen::c#3 ← phi( main::@4/(byte) fillscreen::c#0 )
  (byte) fillscreen::i#0 ← (byte) 0
  (byte*) fillscreen::screen#0 ← (const byte*) SCREEN
  to:fillscreen::@1
fillscreen::@1: scope:[fillscreen]  from fillscreen fillscreen::@2
  (byte) fillscreen::i#3 ← phi( fillscreen/(byte) fillscreen::i#0 fillscreen::@2/(byte) fillscreen::i#1 )
  (byte) fillscreen::c#2 ← phi( fillscreen/(byte) fillscreen::c#3 fillscreen::@2/(byte) fillscreen::c#1 )
  (byte*) fillscreen::screen#2 ← phi( fillscreen/(byte*) fillscreen::screen#0 fillscreen::@2/(byte*) fillscreen::screen#1 )
  (byte*~) fillscreen::$0 ← (const byte*) SCREEN + (number) $3e8
  (bool~) fillscreen::$1 ← (byte*) fillscreen::screen#2 < (byte*~) fillscreen::$0
  if((bool~) fillscreen::$1) goto fillscreen::@2
  to:fillscreen::@return
fillscreen::@2: scope:[fillscreen]  from fillscreen::@1
  (byte*) fillscreen::screen#3 ← phi( fillscreen::@1/(byte*) fillscreen::screen#2 )
  (byte) fillscreen::i#2 ← phi( fillscreen::@1/(byte) fillscreen::i#3 )
  (byte) fillscreen::c#1 ← phi( fillscreen::@1/(byte) fillscreen::c#2 )
  (byte~) fillscreen::$2 ← (byte) fillscreen::c#1 + *((const byte*) base + (byte) fillscreen::i#2)
  *((byte*) fillscreen::screen#3) ← (byte~) fillscreen::$2
  (byte) fillscreen::i#1 ← ++ (byte) fillscreen::i#2
  (byte*) fillscreen::screen#1 ← ++ (byte*) fillscreen::screen#3
  to:fillscreen::@1
fillscreen::@return: scope:[fillscreen]  from fillscreen::@1
  return 
  to:@return
@2: scope:[]  from @begin
  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
(const byte*) BGCOL = (byte*)(number) $d021
(const byte*) SCREEN = (byte*)(number) $400
(const byte*) base[(number) $100]  = { fill( $100, 0) }
(void()) fillscreen((byte) fillscreen::c)
(byte*~) fillscreen::$0
(bool~) fillscreen::$1
(byte~) fillscreen::$2
(label) fillscreen::@1
(label) fillscreen::@2
(label) fillscreen::@return
(byte) fillscreen::c
(byte) fillscreen::c#0
(byte) fillscreen::c#1
(byte) fillscreen::c#2
(byte) fillscreen::c#3
(byte) fillscreen::i
(byte) fillscreen::i#0
(byte) fillscreen::i#1
(byte) fillscreen::i#2
(byte) fillscreen::i#3
(byte*) fillscreen::screen
(byte*) fillscreen::screen#0
(byte*) fillscreen::screen#1
(byte*) fillscreen::screen#2
(byte*) fillscreen::screen#3
(void()) main()
(bool~) main::$0
(label) main::@1
(label) main::@3
(label) main::@4
(label) main::@9
(label) main::@return
(byte) main::i
(byte) main::i#0
(byte) main::i#1
(byte) main::i#2

Adding number conversion cast (unumber) $3e8 in (byte*~) fillscreen::$0 ← (const byte*) SCREEN + (number) $3e8
Successful SSA optimization PassNAddNumberTypeConversions
Simplifying constant pointer cast (byte*) 53281
Simplifying constant pointer cast (byte*) 1024
Simplifying constant integer cast $3e8
Successful SSA optimization PassNCastSimplification
Finalized unsigned number type (word) $3e8
Successful SSA optimization PassNFinalizeNumberTypeConversions
Alias (byte) fillscreen::c#1 = (byte) fillscreen::c#2 
Alias (byte) fillscreen::i#2 = (byte) fillscreen::i#3 
Alias (byte*) fillscreen::screen#2 = (byte*) fillscreen::screen#3 
Successful SSA optimization Pass2AliasElimination
Identical Phi Values (byte) fillscreen::c#3 (byte) fillscreen::c#0
Identical Phi Values (byte) fillscreen::c#1 (byte) fillscreen::c#3
Successful SSA optimization Pass2IdenticalPhiElimination
Simple Condition (bool~) main::$0 [5] if((byte) main::i#1!=rangelast(0,$ff)) goto main::@1
Simple Condition (bool~) fillscreen::$1 [17] if((byte*) fillscreen::screen#2<(byte*~) fillscreen::$0) goto fillscreen::@2
Successful SSA optimization Pass2ConditionalJumpSimplification
Constant right-side identified [15] (byte*~) fillscreen::$0 ← (const byte*) SCREEN + (word) $3e8
Successful SSA optimization Pass2ConstantRValueConsolidation
Constant (const byte) main::i#0 = 0
Constant (const byte) fillscreen::i#0 = 0
Constant (const byte*) fillscreen::screen#0 = SCREEN
Constant (const byte*) fillscreen::$0 = SCREEN+$3e8
Successful SSA optimization Pass2ConstantIdentification
if() condition always true - replacing block destination [6] if(true) goto main::@4
Successful SSA optimization Pass2ConstantIfs
Resolved ranged next value [3] main::i#1 ← ++ main::i#2 to ++
Resolved ranged comparison value [5] if(main::i#1!=rangelast(0,$ff)) goto main::@1 to (number) 0
Removing unused block main::@return
Successful SSA optimization Pass2EliminateUnusedBlocks
Adding number conversion cast (unumber) 0 in if((byte) main::i#1!=(number) 0) goto main::@1
Successful SSA optimization PassNAddNumberTypeConversions
Simplifying constant integer cast 0
Successful SSA optimization PassNCastSimplification
Finalized unsigned number type (byte) 0
Successful SSA optimization PassNFinalizeNumberTypeConversions
Inlining constant with var siblings (const byte) main::i#0
Inlining constant with var siblings (const byte) fillscreen::i#0
Inlining constant with var siblings (const byte*) fillscreen::screen#0
Constant inlined fillscreen::i#0 = (byte) 0
Constant inlined main::i#0 = (byte) 0
Constant inlined fillscreen::screen#0 = (const byte*) SCREEN
Constant inlined fillscreen::$0 = (const byte*) SCREEN+(word) $3e8
Successful SSA optimization Pass2ConstantInlining
Added new block during phi lifting main::@10(between main::@1 and main::@1)
Adding NOP phi() at start of @begin
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
Adding NOP phi() at start of main::@3
Adding NOP phi() at start of fillscreen
CALL GRAPH
Calls in [] to main:2 
Calls in [main] to fillscreen:12 

Created 3 initial phi equivalence classes
Coalesced [14] main::i#3 ← main::i#1
Coalesced [23] fillscreen::screen#4 ← fillscreen::screen#1
Coalesced [24] fillscreen::i#4 ← fillscreen::i#1
Coalesced down to 3 phi equivalence classes
Culled Empty Block (label) @3
Culled Empty Block (label) main::@3
Culled Empty Block (label) main::@10
Renumbering block @2 to @1
Renumbering block main::@4 to main::@2
Renumbering block main::@9 to main::@3
Adding NOP phi() at start of @begin
Adding NOP phi() at start of @1
Adding NOP phi() at start of @end
Adding NOP phi() at start of main
Adding NOP phi() at start of fillscreen

FINAL CONTROL FLOW GRAPH
@begin: scope:[]  from
  [0] phi()
  to:@1
@1: scope:[]  from @begin
  [1] phi()
  [2] call main 
  to:@end
@end: scope:[]  from @1
  [3] phi()

(void()) main()
main: scope:[main]  from @1
  [4] phi()
  to:main::@1
main::@1: scope:[main]  from main main::@1
  [5] (byte) main::i#2 ← phi( main/(byte) 0 main::@1/(byte) main::i#1 )
  [6] *((const byte*) base + (byte) main::i#2) ← (byte) main::i#2
  [7] (byte) main::i#1 ← ++ (byte) main::i#2
  [8] if((byte) main::i#1!=(byte) 0) goto main::@1
  to:main::@2
main::@2: scope:[main]  from main::@1 main::@3
  [9] (byte) fillscreen::c#0 ← *((const byte*) BGCOL)
  [10] call fillscreen 
  to:main::@3
main::@3: scope:[main]  from main::@2
  [11] *((const byte*) BGCOL) ← ++ *((const byte*) BGCOL)
  to:main::@2

(void()) fillscreen((byte) fillscreen::c)
fillscreen: scope:[fillscreen]  from main::@2
  [12] phi()
  to:fillscreen::@1
fillscreen::@1: scope:[fillscreen]  from fillscreen fillscreen::@2
  [13] (byte) fillscreen::i#2 ← phi( fillscreen/(byte) 0 fillscreen::@2/(byte) fillscreen::i#1 )
  [13] (byte*) fillscreen::screen#2 ← phi( fillscreen/(const byte*) SCREEN fillscreen::@2/(byte*) fillscreen::screen#1 )
  [14] if((byte*) fillscreen::screen#2<(const byte*) SCREEN+(word) $3e8) goto fillscreen::@2
  to:fillscreen::@return
fillscreen::@return: scope:[fillscreen]  from fillscreen::@1
  [15] return 
  to:@return
fillscreen::@2: scope:[fillscreen]  from fillscreen::@1
  [16] (byte~) fillscreen::$2 ← (byte) fillscreen::c#0 + *((const byte*) base + (byte) fillscreen::i#2)
  [17] *((byte*) fillscreen::screen#2) ← (byte~) fillscreen::$2
  [18] (byte) fillscreen::i#1 ← ++ (byte) fillscreen::i#2
  [19] (byte*) fillscreen::screen#1 ← ++ (byte*) fillscreen::screen#2
  to:fillscreen::@1


VARIABLE REGISTER WEIGHTS
(void()) fillscreen((byte) fillscreen::c)
(byte~) fillscreen::$2 202.0
(byte) fillscreen::c
(byte) fillscreen::c#0 14.0
(byte) fillscreen::i
(byte) fillscreen::i#1 101.0
(byte) fillscreen::i#2 75.75
(byte*) fillscreen::screen
(byte*) fillscreen::screen#1 202.0
(byte*) fillscreen::screen#2 80.8
(void()) main()
(byte) main::i
(byte) main::i#1 16.5
(byte) main::i#2 22.0

Initial phi equivalence classes
[ main::i#2 main::i#1 ]
[ fillscreen::screen#2 fillscreen::screen#1 ]
[ fillscreen::i#2 fillscreen::i#1 ]
Added variable fillscreen::c#0 to live range equivalence class [ fillscreen::c#0 ]
Added variable fillscreen::$2 to live range equivalence class [ fillscreen::$2 ]
Complete equivalence classes
[ main::i#2 main::i#1 ]
[ fillscreen::screen#2 fillscreen::screen#1 ]
[ fillscreen::i#2 fillscreen::i#1 ]
[ fillscreen::c#0 ]
[ fillscreen::$2 ]
Allocated zp[1]:2 [ main::i#2 main::i#1 ]
Allocated zp[2]:3 [ fillscreen::screen#2 fillscreen::screen#1 ]
Allocated zp[1]:5 [ fillscreen::i#2 fillscreen::i#1 ]
Allocated zp[1]:6 [ fillscreen::c#0 ]
Allocated zp[1]:7 [ fillscreen::$2 ]

INITIAL ASM
Target platform is custom / MOS6502X
  // File Comments
// Example showing how to perform linking using a linker-file
// The linker file is created using KickAssembler segments.
// See the KickAssembler manual for description of the format http://theweb.dk/KickAssembler/
// Specifying the linker script file is done using the #pragma link(<file>)
// It can also be specified using kickc command line option -T <file>
  // Upstart
  .file [name="linking.prg", type="prg", segments="Program"]
.segmentdef Program [segments="Basic, Code, Data, CodeHigh, DataHigh"]
.segmentdef Basic [start=$0801]
.segmentdef Code [start=$0810]
.segmentdef Data [startAfter="Code"]
.segmentdef CodeHigh [start=$4000]
.segmentdef DataHigh [startAfter="CodeHigh"]
.segment Basic
:BasicUpstart(main)


  // Global Constants & labels
  .label BGCOL = $d021
  .label SCREEN = $400
  // @begin
__bbegin:
  // [1] phi from @begin to @1 [phi:@begin->@1]
__b1_from___bbegin:
  jmp __b1
  // @1
__b1:
  // [2] call main 
  // [4] phi from @1 to main [phi:@1->main]
main_from___b1:
  jsr main
  // [3] phi from @1 to @end [phi:@1->@end]
__bend_from___b1:
  jmp __bend
  // @end
__bend:
.segment Code
  // main
main: {
    .label i = 2
    // [5] phi from main to main::@1 [phi:main->main::@1]
  __b1_from_main:
    // [5] phi (byte) main::i#2 = (byte) 0 [phi:main->main::@1#0] -- vbuz1=vbuc1 
    lda #0
    sta.z i
    jmp __b1
    // [5] phi from main::@1 to main::@1 [phi:main::@1->main::@1]
  __b1_from___b1:
    // [5] phi (byte) main::i#2 = (byte) main::i#1 [phi:main::@1->main::@1#0] -- register_copy 
    jmp __b1
    // main::@1
  __b1:
    // [6] *((const byte*) base + (byte) main::i#2) ← (byte) main::i#2 -- pbuc1_derefidx_vbuz1=vbuz1 
    ldy.z i
    tya
    sta base,y
    // [7] (byte) main::i#1 ← ++ (byte) main::i#2 -- vbuz1=_inc_vbuz1 
    inc.z i
    // [8] if((byte) main::i#1!=(byte) 0) goto main::@1 -- vbuz1_neq_0_then_la1 
    lda.z i
    cmp #0
    bne __b1_from___b1
    jmp __b2
    // main::@2
  __b2:
    // [9] (byte) fillscreen::c#0 ← *((const byte*) BGCOL) -- vbuz1=_deref_pbuc1 
    lda BGCOL
    sta.z fillscreen.c
    // [10] call fillscreen 
    // [12] phi from main::@2 to fillscreen [phi:main::@2->fillscreen]
  fillscreen_from___b2:
    jsr fillscreen
    jmp __b3
    // main::@3
  __b3:
    // [11] *((const byte*) BGCOL) ← ++ *((const byte*) BGCOL) -- _deref_pbuc1=_inc__deref_pbuc1 
    inc BGCOL
    jmp __b2
}
.segment CodeHigh
  // fillscreen
// fillscreen(byte zp(6) c)
fillscreen: {
    .label __2 = 7
    .label c = 6
    .label i = 5
    .label screen = 3
    // [13] phi from fillscreen to fillscreen::@1 [phi:fillscreen->fillscreen::@1]
  __b1_from_fillscreen:
    // [13] phi (byte) fillscreen::i#2 = (byte) 0 [phi:fillscreen->fillscreen::@1#0] -- vbuz1=vbuc1 
    lda #0
    sta.z i
    // [13] phi (byte*) fillscreen::screen#2 = (const byte*) SCREEN [phi:fillscreen->fillscreen::@1#1] -- pbuz1=pbuc1 
    lda #<SCREEN
    sta.z screen
    lda #>SCREEN
    sta.z screen+1
    jmp __b1
    // fillscreen::@1
  __b1:
    // [14] if((byte*) fillscreen::screen#2<(const byte*) SCREEN+(word) $3e8) goto fillscreen::@2 -- pbuz1_lt_pbuc1_then_la1 
    lda.z screen+1
    cmp #>SCREEN+$3e8
    bcc __b2
    bne !+
    lda.z screen
    cmp #<SCREEN+$3e8
    bcc __b2
  !:
    jmp __breturn
    // fillscreen::@return
  __breturn:
    // [15] return 
    rts
    // fillscreen::@2
  __b2:
    // [16] (byte~) fillscreen::$2 ← (byte) fillscreen::c#0 + *((const byte*) base + (byte) fillscreen::i#2) -- vbuz1=vbuz2_plus_pbuc1_derefidx_vbuz3 
    lda.z c
    ldy.z i
    clc
    adc base,y
    sta.z __2
    // [17] *((byte*) fillscreen::screen#2) ← (byte~) fillscreen::$2 -- _deref_pbuz1=vbuz2 
    lda.z __2
    ldy #0
    sta (screen),y
    // [18] (byte) fillscreen::i#1 ← ++ (byte) fillscreen::i#2 -- vbuz1=_inc_vbuz1 
    inc.z i
    // [19] (byte*) fillscreen::screen#1 ← ++ (byte*) fillscreen::screen#2 -- pbuz1=_inc_pbuz1 
    inc.z screen
    bne !+
    inc.z screen+1
  !:
    // [13] phi from fillscreen::@2 to fillscreen::@1 [phi:fillscreen::@2->fillscreen::@1]
  __b1_from___b2:
    // [13] phi (byte) fillscreen::i#2 = (byte) fillscreen::i#1 [phi:fillscreen::@2->fillscreen::@1#0] -- register_copy 
    // [13] phi (byte*) fillscreen::screen#2 = (byte*) fillscreen::screen#1 [phi:fillscreen::@2->fillscreen::@1#1] -- register_copy 
    jmp __b1
}
  // File Data
.segment DataHigh
  base: .fill $100, 0

REGISTER UPLIFT POTENTIAL REGISTERS
Statement [14] if((byte*) fillscreen::screen#2<(const byte*) SCREEN+(word) $3e8) goto fillscreen::@2 [ fillscreen::c#0 fillscreen::screen#2 fillscreen::i#2 ] ( main:2::fillscreen:10 [ fillscreen::c#0 fillscreen::screen#2 fillscreen::i#2 ] ) always clobbers reg byte a 
Removing always clobbered register reg byte a as potential for zp[1]:6 [ fillscreen::c#0 ]
Removing always clobbered register reg byte a as potential for zp[1]:5 [ fillscreen::i#2 fillscreen::i#1 ]
Statement [16] (byte~) fillscreen::$2 ← (byte) fillscreen::c#0 + *((const byte*) base + (byte) fillscreen::i#2) [ fillscreen::c#0 fillscreen::screen#2 fillscreen::i#2 fillscreen::$2 ] ( main:2::fillscreen:10 [ fillscreen::c#0 fillscreen::screen#2 fillscreen::i#2 fillscreen::$2 ] ) always clobbers reg byte a 
Statement [17] *((byte*) fillscreen::screen#2) ← (byte~) fillscreen::$2 [ fillscreen::c#0 fillscreen::screen#2 fillscreen::i#2 ] ( main:2::fillscreen:10 [ fillscreen::c#0 fillscreen::screen#2 fillscreen::i#2 ] ) always clobbers reg byte y 
Removing always clobbered register reg byte y as potential for zp[1]:6 [ fillscreen::c#0 ]
Removing always clobbered register reg byte y as potential for zp[1]:5 [ fillscreen::i#2 fillscreen::i#1 ]
Statement [14] if((byte*) fillscreen::screen#2<(const byte*) SCREEN+(word) $3e8) goto fillscreen::@2 [ fillscreen::c#0 fillscreen::screen#2 fillscreen::i#2 ] ( main:2::fillscreen:10 [ fillscreen::c#0 fillscreen::screen#2 fillscreen::i#2 ] ) always clobbers reg byte a 
Statement [16] (byte~) fillscreen::$2 ← (byte) fillscreen::c#0 + *((const byte*) base + (byte) fillscreen::i#2) [ fillscreen::c#0 fillscreen::screen#2 fillscreen::i#2 fillscreen::$2 ] ( main:2::fillscreen:10 [ fillscreen::c#0 fillscreen::screen#2 fillscreen::i#2 fillscreen::$2 ] ) always clobbers reg byte a 
Statement [17] *((byte*) fillscreen::screen#2) ← (byte~) fillscreen::$2 [ fillscreen::c#0 fillscreen::screen#2 fillscreen::i#2 ] ( main:2::fillscreen:10 [ fillscreen::c#0 fillscreen::screen#2 fillscreen::i#2 ] ) always clobbers reg byte y 
Potential registers zp[1]:2 [ main::i#2 main::i#1 ] : zp[1]:2 , reg byte a , reg byte x , reg byte y , 
Potential registers zp[2]:3 [ fillscreen::screen#2 fillscreen::screen#1 ] : zp[2]:3 , 
Potential registers zp[1]:5 [ fillscreen::i#2 fillscreen::i#1 ] : zp[1]:5 , reg byte x , 
Potential registers zp[1]:6 [ fillscreen::c#0 ] : zp[1]:6 , reg byte x , 
Potential registers zp[1]:7 [ fillscreen::$2 ] : zp[1]:7 , reg byte a , reg byte x , reg byte y , 

REGISTER UPLIFT SCOPES
Uplift Scope [fillscreen] 282.8: zp[2]:3 [ fillscreen::screen#2 fillscreen::screen#1 ] 202: zp[1]:7 [ fillscreen::$2 ] 176.75: zp[1]:5 [ fillscreen::i#2 fillscreen::i#1 ] 14: zp[1]:6 [ fillscreen::c#0 ] 
Uplift Scope [main] 38.5: zp[1]:2 [ main::i#2 main::i#1 ] 
Uplift Scope [] 

Uplifting [fillscreen] best 7602 combination zp[2]:3 [ fillscreen::screen#2 fillscreen::screen#1 ] reg byte a [ fillscreen::$2 ] reg byte x [ fillscreen::i#2 fillscreen::i#1 ] zp[1]:6 [ fillscreen::c#0 ] 
Uplifting [main] best 7482 combination reg byte x [ main::i#2 main::i#1 ] 
Uplifting [] best 7482 combination 
Attempting to uplift remaining variables inzp[1]:6 [ fillscreen::c#0 ]
Uplifting [fillscreen] best 7482 combination zp[1]:6 [ fillscreen::c#0 ] 
Allocated (was zp[2]:3) zp[2]:2 [ fillscreen::screen#2 fillscreen::screen#1 ]
Allocated (was zp[1]:6) zp[1]:4 [ fillscreen::c#0 ]

ASSEMBLER BEFORE OPTIMIZATION
  // File Comments
// Example showing how to perform linking using a linker-file
// The linker file is created using KickAssembler segments.
// See the KickAssembler manual for description of the format http://theweb.dk/KickAssembler/
// Specifying the linker script file is done using the #pragma link(<file>)
// It can also be specified using kickc command line option -T <file>
  // Upstart
  .file [name="linking.prg", type="prg", segments="Program"]
.segmentdef Program [segments="Basic, Code, Data, CodeHigh, DataHigh"]
.segmentdef Basic [start=$0801]
.segmentdef Code [start=$0810]
.segmentdef Data [startAfter="Code"]
.segmentdef CodeHigh [start=$4000]
.segmentdef DataHigh [startAfter="CodeHigh"]
.segment Basic
:BasicUpstart(main)


  // Global Constants & labels
  .label BGCOL = $d021
  .label SCREEN = $400
  // @begin
__bbegin:
  // [1] phi from @begin to @1 [phi:@begin->@1]
__b1_from___bbegin:
  jmp __b1
  // @1
__b1:
  // [2] call main 
  // [4] phi from @1 to main [phi:@1->main]
main_from___b1:
  jsr main
  // [3] phi from @1 to @end [phi:@1->@end]
__bend_from___b1:
  jmp __bend
  // @end
__bend:
.segment Code
  // main
main: {
    // [5] phi from main to main::@1 [phi:main->main::@1]
  __b1_from_main:
    // [5] phi (byte) main::i#2 = (byte) 0 [phi:main->main::@1#0] -- vbuxx=vbuc1 
    ldx #0
    jmp __b1
    // [5] phi from main::@1 to main::@1 [phi:main::@1->main::@1]
  __b1_from___b1:
    // [5] phi (byte) main::i#2 = (byte) main::i#1 [phi:main::@1->main::@1#0] -- register_copy 
    jmp __b1
    // main::@1
  __b1:
    // [6] *((const byte*) base + (byte) main::i#2) ← (byte) main::i#2 -- pbuc1_derefidx_vbuxx=vbuxx 
    txa
    sta base,x
    // [7] (byte) main::i#1 ← ++ (byte) main::i#2 -- vbuxx=_inc_vbuxx 
    inx
    // [8] if((byte) main::i#1!=(byte) 0) goto main::@1 -- vbuxx_neq_0_then_la1 
    cpx #0
    bne __b1_from___b1
    jmp __b2
    // main::@2
  __b2:
    // [9] (byte) fillscreen::c#0 ← *((const byte*) BGCOL) -- vbuz1=_deref_pbuc1 
    lda BGCOL
    sta.z fillscreen.c
    // [10] call fillscreen 
    // [12] phi from main::@2 to fillscreen [phi:main::@2->fillscreen]
  fillscreen_from___b2:
    jsr fillscreen
    jmp __b3
    // main::@3
  __b3:
    // [11] *((const byte*) BGCOL) ← ++ *((const byte*) BGCOL) -- _deref_pbuc1=_inc__deref_pbuc1 
    inc BGCOL
    jmp __b2
}
.segment CodeHigh
  // fillscreen
// fillscreen(byte zp(4) c)
fillscreen: {
    .label c = 4
    .label screen = 2
    // [13] phi from fillscreen to fillscreen::@1 [phi:fillscreen->fillscreen::@1]
  __b1_from_fillscreen:
    // [13] phi (byte) fillscreen::i#2 = (byte) 0 [phi:fillscreen->fillscreen::@1#0] -- vbuxx=vbuc1 
    ldx #0
    // [13] phi (byte*) fillscreen::screen#2 = (const byte*) SCREEN [phi:fillscreen->fillscreen::@1#1] -- pbuz1=pbuc1 
    lda #<SCREEN
    sta.z screen
    lda #>SCREEN
    sta.z screen+1
    jmp __b1
    // fillscreen::@1
  __b1:
    // [14] if((byte*) fillscreen::screen#2<(const byte*) SCREEN+(word) $3e8) goto fillscreen::@2 -- pbuz1_lt_pbuc1_then_la1 
    lda.z screen+1
    cmp #>SCREEN+$3e8
    bcc __b2
    bne !+
    lda.z screen
    cmp #<SCREEN+$3e8
    bcc __b2
  !:
    jmp __breturn
    // fillscreen::@return
  __breturn:
    // [15] return 
    rts
    // fillscreen::@2
  __b2:
    // [16] (byte~) fillscreen::$2 ← (byte) fillscreen::c#0 + *((const byte*) base + (byte) fillscreen::i#2) -- vbuaa=vbuz1_plus_pbuc1_derefidx_vbuxx 
    lda base,x
    clc
    adc.z c
    // [17] *((byte*) fillscreen::screen#2) ← (byte~) fillscreen::$2 -- _deref_pbuz1=vbuaa 
    ldy #0
    sta (screen),y
    // [18] (byte) fillscreen::i#1 ← ++ (byte) fillscreen::i#2 -- vbuxx=_inc_vbuxx 
    inx
    // [19] (byte*) fillscreen::screen#1 ← ++ (byte*) fillscreen::screen#2 -- pbuz1=_inc_pbuz1 
    inc.z screen
    bne !+
    inc.z screen+1
  !:
    // [13] phi from fillscreen::@2 to fillscreen::@1 [phi:fillscreen::@2->fillscreen::@1]
  __b1_from___b2:
    // [13] phi (byte) fillscreen::i#2 = (byte) fillscreen::i#1 [phi:fillscreen::@2->fillscreen::@1#0] -- register_copy 
    // [13] phi (byte*) fillscreen::screen#2 = (byte*) fillscreen::screen#1 [phi:fillscreen::@2->fillscreen::@1#1] -- register_copy 
    jmp __b1
}
  // File Data
.segment DataHigh
  base: .fill $100, 0

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_from___b1 with __b1
Removing instruction __bbegin:
Removing instruction __b1_from___bbegin:
Removing instruction main_from___b1:
Removing instruction __bend_from___b1:
Removing instruction __b1_from___b1:
Succesful ASM optimization Pass5RedundantLabelElimination
Removing instruction __b1:
Removing instruction __bend:
Removing instruction __b1_from_main:
Removing instruction fillscreen_from___b2:
Removing instruction __b3:
Removing instruction __b1_from_fillscreen:
Removing instruction __breturn:
Removing instruction __b1_from___b2:
Succesful ASM optimization Pass5UnusedLabelElimination
Removing instruction jsr main
Succesful ASM optimization Pass5SkipBegin
Removing instruction jmp __b1
Succesful ASM optimization Pass5NextJumpElimination

FINAL SYMBOL TABLE
(label) @1
(label) @begin
(label) @end
(const byte*) BGCOL = (byte*) 53281
(const byte*) SCREEN = (byte*) 1024
(const byte*) base[(number) $100]  = { fill( $100, 0) }
(void()) fillscreen((byte) fillscreen::c)
(byte~) fillscreen::$2 reg byte a 202.0
(label) fillscreen::@1
(label) fillscreen::@2
(label) fillscreen::@return
(byte) fillscreen::c
(byte) fillscreen::c#0 c zp[1]:4 14.0
(byte) fillscreen::i
(byte) fillscreen::i#1 reg byte x 101.0
(byte) fillscreen::i#2 reg byte x 75.75
(byte*) fillscreen::screen
(byte*) fillscreen::screen#1 screen zp[2]:2 202.0
(byte*) fillscreen::screen#2 screen zp[2]:2 80.8
(void()) main()
(label) main::@1
(label) main::@2
(label) main::@3
(byte) main::i
(byte) main::i#1 reg byte x 16.5
(byte) main::i#2 reg byte x 22.0

reg byte x [ main::i#2 main::i#1 ]
zp[2]:2 [ fillscreen::screen#2 fillscreen::screen#1 ]
reg byte x [ fillscreen::i#2 fillscreen::i#1 ]
zp[1]:4 [ fillscreen::c#0 ]
reg byte a [ fillscreen::$2 ]


FINAL ASSEMBLER
Score: 6777

  // File Comments
// Example showing how to perform linking using a linker-file
// The linker file is created using KickAssembler segments.
// See the KickAssembler manual for description of the format http://theweb.dk/KickAssembler/
// Specifying the linker script file is done using the #pragma link(<file>)
// It can also be specified using kickc command line option -T <file>
  // Upstart
  .file [name="linking.prg", type="prg", segments="Program"]
.segmentdef Program [segments="Basic, Code, Data, CodeHigh, DataHigh"]
.segmentdef Basic [start=$0801]
.segmentdef Code [start=$0810]
.segmentdef Data [startAfter="Code"]
.segmentdef CodeHigh [start=$4000]
.segmentdef DataHigh [startAfter="CodeHigh"]
.segment Basic
:BasicUpstart(main)


  // Global Constants & labels
  .label BGCOL = $d021
  .label SCREEN = $400
  // @begin
  // [1] phi from @begin to @1 [phi:@begin->@1]
  // @1
  // [2] call main 
  // [4] phi from @1 to main [phi:@1->main]
  // [3] phi from @1 to @end [phi:@1->@end]
  // @end
.segment Code
  // main
main: {
    // [5] phi from main to main::@1 [phi:main->main::@1]
    // [5] phi (byte) main::i#2 = (byte) 0 [phi:main->main::@1#0] -- vbuxx=vbuc1 
    ldx #0
    // [5] phi from main::@1 to main::@1 [phi:main::@1->main::@1]
    // [5] phi (byte) main::i#2 = (byte) main::i#1 [phi:main::@1->main::@1#0] -- register_copy 
    // main::@1
  __b1:
    // base[i] = i
    // [6] *((const byte*) base + (byte) main::i#2) ← (byte) main::i#2 -- pbuc1_derefidx_vbuxx=vbuxx 
    txa
    sta base,x
    // for(char i:0..255)
    // [7] (byte) main::i#1 ← ++ (byte) main::i#2 -- vbuxx=_inc_vbuxx 
    inx
    // [8] if((byte) main::i#1!=(byte) 0) goto main::@1 -- vbuxx_neq_0_then_la1 
    cpx #0
    bne __b1
    // main::@2
  __b2:
    // fillscreen(*BGCOL)
    // [9] (byte) fillscreen::c#0 ← *((const byte*) BGCOL) -- vbuz1=_deref_pbuc1 
    lda BGCOL
    sta.z fillscreen.c
    // [10] call fillscreen 
    // [12] phi from main::@2 to fillscreen [phi:main::@2->fillscreen]
    jsr fillscreen
    // main::@3
    // (*BGCOL)++;
    // [11] *((const byte*) BGCOL) ← ++ *((const byte*) BGCOL) -- _deref_pbuc1=_inc__deref_pbuc1 
    inc BGCOL
    jmp __b2
}
.segment CodeHigh
  // fillscreen
// fillscreen(byte zp(4) c)
fillscreen: {
    .label c = 4
    .label screen = 2
    // [13] phi from fillscreen to fillscreen::@1 [phi:fillscreen->fillscreen::@1]
    // [13] phi (byte) fillscreen::i#2 = (byte) 0 [phi:fillscreen->fillscreen::@1#0] -- vbuxx=vbuc1 
    ldx #0
    // [13] phi (byte*) fillscreen::screen#2 = (const byte*) SCREEN [phi:fillscreen->fillscreen::@1#1] -- pbuz1=pbuc1 
    lda #<SCREEN
    sta.z screen
    lda #>SCREEN
    sta.z screen+1
    // fillscreen::@1
  __b1:
    // for( char *screen = SCREEN; screen<SCREEN+1000; screen++)
    // [14] if((byte*) fillscreen::screen#2<(const byte*) SCREEN+(word) $3e8) goto fillscreen::@2 -- pbuz1_lt_pbuc1_then_la1 
    lda.z screen+1
    cmp #>SCREEN+$3e8
    bcc __b2
    bne !+
    lda.z screen
    cmp #<SCREEN+$3e8
    bcc __b2
  !:
    // fillscreen::@return
    // }
    // [15] return 
    rts
    // fillscreen::@2
  __b2:
    // c+base[i++]
    // [16] (byte~) fillscreen::$2 ← (byte) fillscreen::c#0 + *((const byte*) base + (byte) fillscreen::i#2) -- vbuaa=vbuz1_plus_pbuc1_derefidx_vbuxx 
    lda base,x
    clc
    adc.z c
    // *screen = c+base[i++]
    // [17] *((byte*) fillscreen::screen#2) ← (byte~) fillscreen::$2 -- _deref_pbuz1=vbuaa 
    ldy #0
    sta (screen),y
    // *screen = c+base[i++];
    // [18] (byte) fillscreen::i#1 ← ++ (byte) fillscreen::i#2 -- vbuxx=_inc_vbuxx 
    inx
    // for( char *screen = SCREEN; screen<SCREEN+1000; screen++)
    // [19] (byte*) fillscreen::screen#1 ← ++ (byte*) fillscreen::screen#2 -- pbuz1=_inc_pbuz1 
    inc.z screen
    bne !+
    inc.z screen+1
  !:
    // [13] phi from fillscreen::@2 to fillscreen::@1 [phi:fillscreen::@2->fillscreen::@1]
    // [13] phi (byte) fillscreen::i#2 = (byte) fillscreen::i#1 [phi:fillscreen::@2->fillscreen::@1#0] -- register_copy 
    // [13] phi (byte*) fillscreen::screen#2 = (byte*) fillscreen::screen#1 [phi:fillscreen::@2->fillscreen::@1#1] -- register_copy 
    jmp __b1
}
  // File Data
.segment DataHigh
  base: .fill $100, 0

