Identified constant variable (byte*) SCREEN
Culled Empty Block (label) @1
Culled Empty Block (label) fillscreen::@2

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

(void()) main()
main: scope:[main]  from @2
  (byte) main::c#0 ← *((const byte*) SCREEN)
  (byte) fillscreen::c#0 ← (byte) main::c#0
  call fillscreen 
  to:main::@1
main::@1: scope:[main]  from main
  to:main::@return
main::@return: scope:[main]  from main::@1
  return 
  to:@return

(void()) fillscreen((byte) fillscreen::c)
fillscreen: scope:[fillscreen]  from main
  (byte) fillscreen::c#2 ← phi( main/(byte) fillscreen::c#0 )
  (byte) fillscreen::j#0 ← (byte) 0
  to:fillscreen::@1
fillscreen::@1: scope:[fillscreen]  from fillscreen fillscreen::@1
  (byte) fillscreen::j#2 ← phi( fillscreen/(byte) fillscreen::j#0 fillscreen::@1/(byte) fillscreen::j#1 )
  (byte) fillscreen::c#1 ← phi( fillscreen/(byte) fillscreen::c#2 fillscreen::@1/(byte) fillscreen::c#1 )
  (byte*~) fillscreen::$0 ← (const byte*) SCREEN + (number) $100
  (byte*) fillscreen::SCREEN2#0 ← (byte*~) fillscreen::$0
  (byte*~) fillscreen::$1 ← (const byte*) SCREEN + (number) $200
  (byte*) fillscreen::SCREEN3#0 ← (byte*~) fillscreen::$1
  (byte*~) fillscreen::$2 ← (const byte*) SCREEN + (number) $3e8
  (byte*) fillscreen::SCREEN4#0 ← (byte*~) fillscreen::$2
  *((const byte*) SCREEN + (byte) fillscreen::j#2) ← (byte) fillscreen::c#1
  *((byte*) fillscreen::SCREEN2#0 + (byte) fillscreen::j#2) ← (byte) fillscreen::c#1
  *((byte*) fillscreen::SCREEN3#0 + (byte) fillscreen::j#2) ← (byte) fillscreen::c#1
  *((byte*) fillscreen::SCREEN4#0 + (byte) fillscreen::j#2) ← (byte) fillscreen::c#1
  (byte) fillscreen::j#1 ← (byte) fillscreen::j#2 + rangenext(0,$ff)
  (bool~) fillscreen::$3 ← (byte) fillscreen::j#1 != rangelast(0,$ff)
  if((bool~) fillscreen::$3) goto fillscreen::@1
  to:fillscreen::@return
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*) SCREEN = (byte*)(number) $400
(void()) fillscreen((byte) fillscreen::c)
(byte*~) fillscreen::$0
(byte*~) fillscreen::$1
(byte*~) fillscreen::$2
(bool~) fillscreen::$3
(label) fillscreen::@1
(label) fillscreen::@return
(byte*) fillscreen::SCREEN2
(byte*) fillscreen::SCREEN2#0
(byte*) fillscreen::SCREEN3
(byte*) fillscreen::SCREEN3#0
(byte*) fillscreen::SCREEN4
(byte*) fillscreen::SCREEN4#0
(byte) fillscreen::c
(byte) fillscreen::c#0
(byte) fillscreen::c#1
(byte) fillscreen::c#2
(byte) fillscreen::j
(byte) fillscreen::j#0
(byte) fillscreen::j#1
(byte) fillscreen::j#2
(void()) main()
(label) main::@1
(label) main::@return
(byte) main::c
(byte) main::c#0

Adding number conversion cast (unumber) $100 in (byte*~) fillscreen::$0 ← (const byte*) SCREEN + (number) $100
Adding number conversion cast (unumber) $200 in (byte*~) fillscreen::$1 ← (const byte*) SCREEN + (number) $200
Adding number conversion cast (unumber) $3e8 in (byte*~) fillscreen::$2 ← (const byte*) SCREEN + (number) $3e8
Successful SSA optimization PassNAddNumberTypeConversions
Simplifying constant pointer cast (byte*) 1024
Simplifying constant integer cast $100
Simplifying constant integer cast $200
Simplifying constant integer cast $3e8
Successful SSA optimization PassNCastSimplification
Finalized unsigned number type (word) $100
Finalized unsigned number type (word) $200
Finalized unsigned number type (word) $3e8
Successful SSA optimization PassNFinalizeNumberTypeConversions
Alias (byte*) fillscreen::SCREEN2#0 = (byte*~) fillscreen::$0 
Alias (byte*) fillscreen::SCREEN3#0 = (byte*~) fillscreen::$1 
Alias (byte*) fillscreen::SCREEN4#0 = (byte*~) fillscreen::$2 
Successful SSA optimization Pass2AliasElimination
Identical Phi Values (byte) fillscreen::c#2 (byte) fillscreen::c#0
Identical Phi Values (byte) fillscreen::c#1 (byte) fillscreen::c#2
Successful SSA optimization Pass2IdenticalPhiElimination
Simple Condition (bool~) fillscreen::$3 [16] if((byte) fillscreen::j#1!=rangelast(0,$ff)) goto fillscreen::@1
Successful SSA optimization Pass2ConditionalJumpSimplification
Constant right-side identified [7] (byte*) fillscreen::SCREEN2#0 ← (const byte*) SCREEN + (word) $100
Constant right-side identified [8] (byte*) fillscreen::SCREEN3#0 ← (const byte*) SCREEN + (word) $200
Constant right-side identified [9] (byte*) fillscreen::SCREEN4#0 ← (const byte*) SCREEN + (word) $3e8
Successful SSA optimization Pass2ConstantRValueConsolidation
Constant (const byte) fillscreen::j#0 = 0
Constant (const byte*) fillscreen::SCREEN2#0 = SCREEN+$100
Constant (const byte*) fillscreen::SCREEN3#0 = SCREEN+$200
Constant (const byte*) fillscreen::SCREEN4#0 = SCREEN+$3e8
Successful SSA optimization Pass2ConstantIdentification
Resolved ranged next value [14] fillscreen::j#1 ← ++ fillscreen::j#2 to ++
Resolved ranged comparison value [16] if(fillscreen::j#1!=rangelast(0,$ff)) goto fillscreen::@1 to (number) 0
Adding number conversion cast (unumber) 0 in if((byte) fillscreen::j#1!=(number) 0) goto fillscreen::@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) fillscreen::j#0
Constant inlined fillscreen::j#0 = (byte) 0
Successful SSA optimization Pass2ConstantInlining
Added new block during phi lifting fillscreen::@3(between fillscreen::@1 and fillscreen::@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::@1
Adding NOP phi() at start of fillscreen
CALL GRAPH
Calls in [] to main:2 
Calls in [main] to fillscreen:7 

Created 1 initial phi equivalence classes
Coalesced [19] fillscreen::j#3 ← fillscreen::j#1
Coalesced down to 1 phi equivalence classes
Culled Empty Block (label) @3
Culled Empty Block (label) main::@1
Culled Empty Block (label) fillscreen::@3
Renumbering block @2 to @1
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 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] (byte) main::c#0 ← *((const byte*) SCREEN)
  [5] (byte) fillscreen::c#0 ← (byte) main::c#0
  [6] call fillscreen 
  to:main::@return
main::@return: scope:[main]  from main
  [7] return 
  to:@return

(void()) fillscreen((byte) fillscreen::c)
fillscreen: scope:[fillscreen]  from main
  [8] phi()
  to:fillscreen::@1
fillscreen::@1: scope:[fillscreen]  from fillscreen fillscreen::@1
  [9] (byte) fillscreen::j#2 ← phi( fillscreen/(byte) 0 fillscreen::@1/(byte) fillscreen::j#1 )
  [10] *((const byte*) SCREEN + (byte) fillscreen::j#2) ← (byte) fillscreen::c#0
  [11] *((const byte*) fillscreen::SCREEN2#0 + (byte) fillscreen::j#2) ← (byte) fillscreen::c#0
  [12] *((const byte*) fillscreen::SCREEN3#0 + (byte) fillscreen::j#2) ← (byte) fillscreen::c#0
  [13] *((const byte*) fillscreen::SCREEN4#0 + (byte) fillscreen::j#2) ← (byte) fillscreen::c#0
  [14] (byte) fillscreen::j#1 ← ++ (byte) fillscreen::j#2
  [15] if((byte) fillscreen::j#1!=(byte) 0) goto fillscreen::@1
  to:fillscreen::@return
fillscreen::@return: scope:[fillscreen]  from fillscreen::@1
  [16] return 
  to:@return


VARIABLE REGISTER WEIGHTS
(void()) fillscreen((byte) fillscreen::c)
(byte*) fillscreen::SCREEN2
(byte*) fillscreen::SCREEN3
(byte*) fillscreen::SCREEN4
(byte) fillscreen::c
(byte) fillscreen::c#0 5.111111111111112
(byte) fillscreen::j
(byte) fillscreen::j#1 16.5
(byte) fillscreen::j#2 13.2
(void()) main()
(byte) main::c
(byte) main::c#0 4.0

Initial phi equivalence classes
[ fillscreen::j#2 fillscreen::j#1 ]
Added variable main::c#0 to live range equivalence class [ main::c#0 ]
Added variable fillscreen::c#0 to live range equivalence class [ fillscreen::c#0 ]
Complete equivalence classes
[ fillscreen::j#2 fillscreen::j#1 ]
[ main::c#0 ]
[ fillscreen::c#0 ]
Allocated zp[1]:2 [ fillscreen::j#2 fillscreen::j#1 ]
Allocated zp[1]:3 [ main::c#0 ]
Allocated zp[1]:4 [ fillscreen::c#0 ]

INITIAL ASM
Target platform is c64basic / MOS6502X
  // File Comments
  // Upstart
.pc = $801 "Basic"
:BasicUpstart(__bbegin)
.pc = $80d "Program"
  // Global Constants & labels
  .label SCREEN = $400
  // @begin
__bbegin:
  // [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: {
    .label c = 3
    // [4] (byte) main::c#0 ← *((const byte*) SCREEN) -- vbuz1=_deref_pbuc1 
    lda SCREEN
    sta.z c
    // [5] (byte) fillscreen::c#0 ← (byte) main::c#0 -- vbuz1=vbuz2 
    lda.z c
    sta.z fillscreen.c
    // [6] call fillscreen 
    // [8] phi from main to fillscreen [phi:main->fillscreen]
  fillscreen_from_main:
    jsr fillscreen
    jmp __breturn
    // main::@return
  __breturn:
    // [7] return 
    rts
}
  // fillscreen
// fillscreen(byte zp(4) c)
fillscreen: {
    .label SCREEN2 = SCREEN+$100
    .label SCREEN3 = SCREEN+$200
    .label SCREEN4 = SCREEN+$3e8
    .label c = 4
    .label j = 2
    // [9] phi from fillscreen to fillscreen::@1 [phi:fillscreen->fillscreen::@1]
  __b1_from_fillscreen:
    // [9] phi (byte) fillscreen::j#2 = (byte) 0 [phi:fillscreen->fillscreen::@1#0] -- vbuz1=vbuc1 
    lda #0
    sta.z j
    jmp __b1
    // [9] phi from fillscreen::@1 to fillscreen::@1 [phi:fillscreen::@1->fillscreen::@1]
  __b1_from___b1:
    // [9] phi (byte) fillscreen::j#2 = (byte) fillscreen::j#1 [phi:fillscreen::@1->fillscreen::@1#0] -- register_copy 
    jmp __b1
    // fillscreen::@1
  __b1:
    // [10] *((const byte*) SCREEN + (byte) fillscreen::j#2) ← (byte) fillscreen::c#0 -- pbuc1_derefidx_vbuz1=vbuz2 
    lda.z c
    ldy.z j
    sta SCREEN,y
    // [11] *((const byte*) fillscreen::SCREEN2#0 + (byte) fillscreen::j#2) ← (byte) fillscreen::c#0 -- pbuc1_derefidx_vbuz1=vbuz2 
    lda.z c
    ldy.z j
    sta SCREEN2,y
    // [12] *((const byte*) fillscreen::SCREEN3#0 + (byte) fillscreen::j#2) ← (byte) fillscreen::c#0 -- pbuc1_derefidx_vbuz1=vbuz2 
    lda.z c
    ldy.z j
    sta SCREEN3,y
    // [13] *((const byte*) fillscreen::SCREEN4#0 + (byte) fillscreen::j#2) ← (byte) fillscreen::c#0 -- pbuc1_derefidx_vbuz1=vbuz2 
    lda.z c
    ldy.z j
    sta SCREEN4,y
    // [14] (byte) fillscreen::j#1 ← ++ (byte) fillscreen::j#2 -- vbuz1=_inc_vbuz1 
    inc.z j
    // [15] if((byte) fillscreen::j#1!=(byte) 0) goto fillscreen::@1 -- vbuz1_neq_0_then_la1 
    lda.z j
    cmp #0
    bne __b1_from___b1
    jmp __breturn
    // fillscreen::@return
  __breturn:
    // [16] return 
    rts
}
  // File Data

REGISTER UPLIFT POTENTIAL REGISTERS
Potential registers zp[1]:2 [ fillscreen::j#2 fillscreen::j#1 ] : zp[1]:2 , reg byte a , reg byte x , reg byte y , 
Potential registers zp[1]:3 [ main::c#0 ] : zp[1]:3 , reg byte a , reg byte x , reg byte y , 
Potential registers zp[1]:4 [ fillscreen::c#0 ] : zp[1]:4 , reg byte a , reg byte x , reg byte y , 

REGISTER UPLIFT SCOPES
Uplift Scope [fillscreen] 29.7: zp[1]:2 [ fillscreen::j#2 fillscreen::j#1 ] 5.11: zp[1]:4 [ fillscreen::c#0 ] 
Uplift Scope [main] 4: zp[1]:3 [ main::c#0 ] 
Uplift Scope [] 

Uplifting [fillscreen] best 418 combination reg byte x [ fillscreen::j#2 fillscreen::j#1 ] reg byte a [ fillscreen::c#0 ] 
Uplifting [main] best 412 combination reg byte a [ main::c#0 ] 
Uplifting [] best 412 combination 

ASSEMBLER BEFORE OPTIMIZATION
  // File Comments
  // Upstart
.pc = $801 "Basic"
:BasicUpstart(__bbegin)
.pc = $80d "Program"
  // Global Constants & labels
  .label SCREEN = $400
  // @begin
__bbegin:
  // [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] (byte) main::c#0 ← *((const byte*) SCREEN) -- vbuaa=_deref_pbuc1 
    lda SCREEN
    // [5] (byte) fillscreen::c#0 ← (byte) main::c#0
    // [6] call fillscreen 
    // [8] phi from main to fillscreen [phi:main->fillscreen]
  fillscreen_from_main:
    jsr fillscreen
    jmp __breturn
    // main::@return
  __breturn:
    // [7] return 
    rts
}
  // fillscreen
// fillscreen(byte register(A) c)
fillscreen: {
    .label SCREEN2 = SCREEN+$100
    .label SCREEN3 = SCREEN+$200
    .label SCREEN4 = SCREEN+$3e8
    // [9] phi from fillscreen to fillscreen::@1 [phi:fillscreen->fillscreen::@1]
  __b1_from_fillscreen:
    // [9] phi (byte) fillscreen::j#2 = (byte) 0 [phi:fillscreen->fillscreen::@1#0] -- vbuxx=vbuc1 
    ldx #0
    jmp __b1
    // [9] phi from fillscreen::@1 to fillscreen::@1 [phi:fillscreen::@1->fillscreen::@1]
  __b1_from___b1:
    // [9] phi (byte) fillscreen::j#2 = (byte) fillscreen::j#1 [phi:fillscreen::@1->fillscreen::@1#0] -- register_copy 
    jmp __b1
    // fillscreen::@1
  __b1:
    // [10] *((const byte*) SCREEN + (byte) fillscreen::j#2) ← (byte) fillscreen::c#0 -- pbuc1_derefidx_vbuxx=vbuaa 
    sta SCREEN,x
    // [11] *((const byte*) fillscreen::SCREEN2#0 + (byte) fillscreen::j#2) ← (byte) fillscreen::c#0 -- pbuc1_derefidx_vbuxx=vbuaa 
    sta SCREEN2,x
    // [12] *((const byte*) fillscreen::SCREEN3#0 + (byte) fillscreen::j#2) ← (byte) fillscreen::c#0 -- pbuc1_derefidx_vbuxx=vbuaa 
    sta SCREEN3,x
    // [13] *((const byte*) fillscreen::SCREEN4#0 + (byte) fillscreen::j#2) ← (byte) fillscreen::c#0 -- pbuc1_derefidx_vbuxx=vbuaa 
    sta SCREEN4,x
    // [14] (byte) fillscreen::j#1 ← ++ (byte) fillscreen::j#2 -- vbuxx=_inc_vbuxx 
    inx
    // [15] if((byte) fillscreen::j#1!=(byte) 0) goto fillscreen::@1 -- vbuxx_neq_0_then_la1 
    cpx #0
    bne __b1_from___b1
    jmp __breturn
    // fillscreen::@return
  __breturn:
    // [16] return 
    rts
}
  // File Data

ASSEMBLER OPTIMIZATIONS
Removing instruction jmp __b1
Removing instruction jmp __bend
Removing instruction jmp __breturn
Removing instruction jmp __b1
Removing instruction jmp __breturn
Succesful ASM optimization Pass5NextJumpElimination
Replacing label __bbegin with __b1
Replacing label __b1_from___b1 with __b1
Removing instruction __bbegin:
Removing instruction __b1_from___bbegin:
Removing instruction __bend_from___b1:
Removing instruction __b1_from___b1:
Succesful ASM optimization Pass5RedundantLabelElimination
Removing instruction __bend:
Removing instruction fillscreen_from_main:
Removing instruction __breturn:
Removing instruction __b1_from_fillscreen:
Removing instruction __breturn:
Succesful ASM optimization Pass5UnusedLabelElimination
Updating BasicUpstart to call main directly
Removing instruction jsr main
Succesful ASM optimization Pass5SkipBegin
Removing instruction jmp __b1
Succesful ASM optimization Pass5NextJumpElimination
Removing instruction __b1:
Succesful ASM optimization Pass5UnusedLabelElimination

FINAL SYMBOL TABLE
(label) @1
(label) @begin
(label) @end
(const byte*) SCREEN = (byte*) 1024
(void()) fillscreen((byte) fillscreen::c)
(label) fillscreen::@1
(label) fillscreen::@return
(byte*) fillscreen::SCREEN2
(const byte*) fillscreen::SCREEN2#0 SCREEN2 = (const byte*) SCREEN+(word) $100
(byte*) fillscreen::SCREEN3
(const byte*) fillscreen::SCREEN3#0 SCREEN3 = (const byte*) SCREEN+(word) $200
(byte*) fillscreen::SCREEN4
(const byte*) fillscreen::SCREEN4#0 SCREEN4 = (const byte*) SCREEN+(word) $3e8
(byte) fillscreen::c
(byte) fillscreen::c#0 reg byte a 5.111111111111112
(byte) fillscreen::j
(byte) fillscreen::j#1 reg byte x 16.5
(byte) fillscreen::j#2 reg byte x 13.2
(void()) main()
(label) main::@return
(byte) main::c
(byte) main::c#0 reg byte a 4.0

reg byte x [ fillscreen::j#2 fillscreen::j#1 ]
reg byte a [ main::c#0 ]
reg byte a [ fillscreen::c#0 ]


FINAL ASSEMBLER
Score: 307

  // File Comments
  // Upstart
.pc = $801 "Basic"
:BasicUpstart(main)
.pc = $80d "Program"
  // Global Constants & labels
  .label SCREEN = $400
  // @begin
  // [1] phi from @begin to @1 [phi:@begin->@1]
  // @1
  // [2] call main 
  // [3] phi from @1 to @end [phi:@1->@end]
  // @end
  // main
main: {
    // c = (*SCREEN)
    // [4] (byte) main::c#0 ← *((const byte*) SCREEN) -- vbuaa=_deref_pbuc1 
    lda SCREEN
    // fillscreen(c)
    // [5] (byte) fillscreen::c#0 ← (byte) main::c#0
    // [6] call fillscreen 
    // [8] phi from main to fillscreen [phi:main->fillscreen]
    jsr fillscreen
    // main::@return
    // }
    // [7] return 
    rts
}
  // fillscreen
// fillscreen(byte register(A) c)
fillscreen: {
    .label SCREEN2 = SCREEN+$100
    .label SCREEN3 = SCREEN+$200
    .label SCREEN4 = SCREEN+$3e8
    // [9] phi from fillscreen to fillscreen::@1 [phi:fillscreen->fillscreen::@1]
    // [9] phi (byte) fillscreen::j#2 = (byte) 0 [phi:fillscreen->fillscreen::@1#0] -- vbuxx=vbuc1 
    ldx #0
    // [9] phi from fillscreen::@1 to fillscreen::@1 [phi:fillscreen::@1->fillscreen::@1]
    // [9] phi (byte) fillscreen::j#2 = (byte) fillscreen::j#1 [phi:fillscreen::@1->fillscreen::@1#0] -- register_copy 
    // fillscreen::@1
  __b1:
    // SCREEN[j] = c
    // [10] *((const byte*) SCREEN + (byte) fillscreen::j#2) ← (byte) fillscreen::c#0 -- pbuc1_derefidx_vbuxx=vbuaa 
    sta SCREEN,x
    // SCREEN2[j] = c
    // [11] *((const byte*) fillscreen::SCREEN2#0 + (byte) fillscreen::j#2) ← (byte) fillscreen::c#0 -- pbuc1_derefidx_vbuxx=vbuaa 
    sta SCREEN2,x
    // SCREEN3[j] = c
    // [12] *((const byte*) fillscreen::SCREEN3#0 + (byte) fillscreen::j#2) ← (byte) fillscreen::c#0 -- pbuc1_derefidx_vbuxx=vbuaa 
    sta SCREEN3,x
    // SCREEN4[j] = c
    // [13] *((const byte*) fillscreen::SCREEN4#0 + (byte) fillscreen::j#2) ← (byte) fillscreen::c#0 -- pbuc1_derefidx_vbuxx=vbuaa 
    sta SCREEN4,x
    // for(byte j : 0..255)
    // [14] (byte) fillscreen::j#1 ← ++ (byte) fillscreen::j#2 -- vbuxx=_inc_vbuxx 
    inx
    // [15] if((byte) fillscreen::j#1!=(byte) 0) goto fillscreen::@1 -- vbuxx_neq_0_then_la1 
    cpx #0
    bne __b1
    // fillscreen::@return
    // }
    // [16] return 
    rts
}
  // File Data

