Fixing pointer array-indexing *((signed word*) main::screen + (byte) main::i)
Identified constant variable (signed word*) main::screen
Culled Empty Block (label) main::@2

CONTROL FLOW GRAPH SSA
@begin: scope:[]  from
  to:@1
main: scope:[main]  from @1
  (signed word) main::w1#0 ← (number) $4d2
  (signed word*) main::screen#0 ← ((signed word*)) (number) $400
  (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 )
  (signed word) main::w1#2 ← phi( main/(signed word) main::w1#0 main::@1/(signed word) main::w1#1 )
  (number~) main::$0 ← (signed word) main::w1#2 - (number) $29
  (signed word) main::w1#1 ← (number~) main::$0
  (byte~) main::$2 ← (byte) main::i#2 * (const byte) SIZEOF_SIGNED_WORD
  *((signed word*) main::screen#0 + (byte~) main::$2) ← (signed word) main::w1#1
  (byte) main::i#1 ← (byte) main::i#2 + rangenext(0,$a)
  (bool~) main::$1 ← (byte) main::i#1 != rangelast(0,$a)
  if((bool~) main::$1) goto main::@1
  to:main::@return
main::@return: scope:[main]  from main::@1
  return 
  to:@return
@1: scope:[]  from @begin
  call main 
  to:@2
@2: scope:[]  from @1
  to:@end
@end: scope:[]  from @2

SYMBOL TABLE SSA
(label) @1
(label) @2
(label) @begin
(label) @end
(const byte) SIZEOF_SIGNED_WORD = (byte) 2
(void()) main()
(number~) main::$0
(bool~) main::$1
(byte~) main::$2
(label) main::@1
(label) main::@return
(byte) main::i
(byte) main::i#0
(byte) main::i#1
(byte) main::i#2
(signed word*) main::screen
(signed word*) main::screen#0
(signed word) main::w1
(signed word) main::w1#0
(signed word) main::w1#1
(signed word) main::w1#2

Adding number conversion cast (snumber) $4d2 in (signed word) main::w1#0 ← (number) $4d2
Adding number conversion cast (snumber) $29 in (number~) main::$0 ← (signed word) main::w1#2 - (number) $29
Adding number conversion cast (snumber) main::$0 in (number~) main::$0 ← (signed word) main::w1#2 - (snumber)(number) $29
Successful SSA optimization PassNAddNumberTypeConversions
Inlining cast (signed word) main::w1#0 ← (snumber)(number) $4d2
Inlining cast (signed word*) main::screen#0 ← (signed word*)(number) $400
Successful SSA optimization Pass2InlineCast
Simplifying constant integer cast $4d2
Simplifying constant pointer cast (signed word*) 1024
Simplifying constant integer cast $29
Successful SSA optimization PassNCastSimplification
Finalized signed number type (signed word) $4d2
Finalized signed number type (signed byte) $29
Successful SSA optimization PassNFinalizeNumberTypeConversions
Inferred type updated to signed word in (snumber~) main::$0 ← (signed word) main::w1#2 - (signed byte) $29
Alias (signed word) main::w1#1 = (signed word~) main::$0 
Successful SSA optimization Pass2AliasElimination
Simple Condition (bool~) main::$1 [10] if((byte) main::i#1!=rangelast(0,$a)) goto main::@1
Successful SSA optimization Pass2ConditionalJumpSimplification
Constant (const signed word) main::w1#0 = $4d2
Constant (const signed word*) main::screen#0 = (signed word*) 1024
Constant (const byte) main::i#0 = 0
Successful SSA optimization Pass2ConstantIdentification
Resolved ranged next value [8] main::i#1 ← ++ main::i#2 to ++
Resolved ranged comparison value [10] if(main::i#1!=rangelast(0,$a)) goto main::@1 to (number) $b
Adding number conversion cast (unumber) $b in if((byte) main::i#1!=(number) $b) goto main::@1
Successful SSA optimization PassNAddNumberTypeConversions
Simplifying constant integer cast $b
Successful SSA optimization PassNCastSimplification
Finalized unsigned number type (byte) $b
Successful SSA optimization PassNFinalizeNumberTypeConversions
Rewriting multiplication to use shift [2] (byte~) main::$2 ← (byte) main::i#2 * (const byte) SIZEOF_SIGNED_WORD
Successful SSA optimization Pass2MultiplyToShiftRewriting
Inlining constant with var siblings (const signed word) main::w1#0
Inlining constant with var siblings (const byte) main::i#0
Constant inlined main::i#0 = (byte) 0
Constant inlined main::w1#0 = (signed word) $4d2
Successful SSA optimization Pass2ConstantInlining
Eliminating unused constant (const byte) SIZEOF_SIGNED_WORD
Successful SSA optimization PassNEliminateUnusedVars
Added new block during phi lifting main::@3(between main::@1 and main::@1)
Adding NOP phi() at start of @begin
Adding NOP phi() at start of @1
Adding NOP phi() at start of @2
Adding NOP phi() at start of @end
Adding NOP phi() at start of main
CALL GRAPH
Calls in [] to main:2 

Created 2 initial phi equivalence classes
Coalesced [13] main::w1#3 ← main::w1#1
Coalesced [14] main::i#3 ← main::i#1
Coalesced down to 2 phi equivalence classes
Culled Empty Block (label) @2
Culled Empty Block (label) 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

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()
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 )
  [5] (signed word) main::w1#2 ← phi( main/(signed word) $4d2 main::@1/(signed word) main::w1#1 )
  [6] (signed word) main::w1#1 ← (signed word) main::w1#2 - (signed byte) $29
  [7] (byte~) main::$2 ← (byte) main::i#2 << (byte) 1
  [8] *((const signed word*) main::screen#0 + (byte~) main::$2) ← (signed word) main::w1#1
  [9] (byte) main::i#1 ← ++ (byte) main::i#2
  [10] if((byte) main::i#1!=(byte) $b) goto main::@1
  to:main::@return
main::@return: scope:[main]  from main::@1
  [11] return 
  to:@return


VARIABLE REGISTER WEIGHTS
(void()) main()
(byte~) main::$2 22.0
(byte) main::i
(byte) main::i#1 16.5
(byte) main::i#2 8.25
(signed word*) main::screen
(signed word) main::w1
(signed word) main::w1#1 6.6000000000000005
(signed word) main::w1#2 22.0

Initial phi equivalence classes
[ main::w1#2 main::w1#1 ]
[ main::i#2 main::i#1 ]
Added variable main::$2 to zero page equivalence class [ main::$2 ]
Complete equivalence classes
[ main::w1#2 main::w1#1 ]
[ main::i#2 main::i#1 ]
[ main::$2 ]
Allocated zp ZP_WORD:2 [ main::w1#2 main::w1#1 ]
Allocated zp ZP_BYTE:4 [ main::i#2 main::i#1 ]
Allocated zp ZP_BYTE:5 [ main::$2 ]

INITIAL ASM
Target platform is c64basic
  // File Comments
// Tests subtracting bytes from signed words
  // Upstart
.pc = $801 "Basic"
:BasicUpstart(bbegin)
.pc = $80d "Program"
  // Global Constants & labels
  // @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:
  // main
main: {
    .label screen = $400
    .label _2 = 5
    .label w1 = 2
    .label i = 4
    // [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
    // [5] phi (signed word) main::w1#2 = (signed word) $4d2 [phi:main->main::@1#1] -- vwsz1=vwsc1 
    lda #<$4d2
    sta.z w1
    lda #>$4d2
    sta.z w1+1
    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 
    // [5] phi (signed word) main::w1#2 = (signed word) main::w1#1 [phi:main::@1->main::@1#1] -- register_copy 
    jmp b1
    // main::@1
  b1:
    // [6] (signed word) main::w1#1 ← (signed word) main::w1#2 - (signed byte) $29 -- vwsz1=vwsz1_minus_vbsc1 
    lda.z w1
    sec
    sbc #$29
    sta.z w1
    lda.z w1+1
    sbc #>$29
    sta.z w1+1
    // [7] (byte~) main::$2 ← (byte) main::i#2 << (byte) 1 -- vbuz1=vbuz2_rol_1 
    lda.z i
    asl
    sta.z _2
    // [8] *((const signed word*) main::screen#0 + (byte~) main::$2) ← (signed word) main::w1#1 -- pwsc1_derefidx_vbuz1=vwsz2 
    ldy.z _2
    lda.z w1
    sta screen,y
    lda.z w1+1
    sta screen+1,y
    // [9] (byte) main::i#1 ← ++ (byte) main::i#2 -- vbuz1=_inc_vbuz1 
    inc.z i
    // [10] if((byte) main::i#1!=(byte) $b) goto main::@1 -- vbuz1_neq_vbuc1_then_la1 
    lda #$b
    cmp.z i
    bne b1_from_b1
    jmp breturn
    // main::@return
  breturn:
    // [11] return 
    rts
}
  // File Data

REGISTER UPLIFT POTENTIAL REGISTERS
Statement [6] (signed word) main::w1#1 ← (signed word) main::w1#2 - (signed byte) $29 [ main::i#2 main::w1#1 ] ( main:2 [ main::i#2 main::w1#1 ] ) always clobbers reg byte a 
Removing always clobbered register reg byte a as potential for zp ZP_BYTE:4 [ main::i#2 main::i#1 ]
Statement [7] (byte~) main::$2 ← (byte) main::i#2 << (byte) 1 [ main::i#2 main::w1#1 main::$2 ] ( main:2 [ main::i#2 main::w1#1 main::$2 ] ) always clobbers reg byte a 
Statement [8] *((const signed word*) main::screen#0 + (byte~) main::$2) ← (signed word) main::w1#1 [ main::i#2 main::w1#1 ] ( main:2 [ main::i#2 main::w1#1 ] ) always clobbers reg byte a 
Statement [6] (signed word) main::w1#1 ← (signed word) main::w1#2 - (signed byte) $29 [ main::i#2 main::w1#1 ] ( main:2 [ main::i#2 main::w1#1 ] ) always clobbers reg byte a 
Statement [7] (byte~) main::$2 ← (byte) main::i#2 << (byte) 1 [ main::i#2 main::w1#1 main::$2 ] ( main:2 [ main::i#2 main::w1#1 main::$2 ] ) always clobbers reg byte a 
Statement [8] *((const signed word*) main::screen#0 + (byte~) main::$2) ← (signed word) main::w1#1 [ main::i#2 main::w1#1 ] ( main:2 [ main::i#2 main::w1#1 ] ) always clobbers reg byte a 
Potential registers zp ZP_WORD:2 [ main::w1#2 main::w1#1 ] : zp ZP_WORD:2 , 
Potential registers zp ZP_BYTE:4 [ main::i#2 main::i#1 ] : zp ZP_BYTE:4 , reg byte x , reg byte y , 
Potential registers zp ZP_BYTE:5 [ main::$2 ] : zp ZP_BYTE:5 , reg byte a , reg byte x , reg byte y , 

REGISTER UPLIFT SCOPES
Uplift Scope [main] 28.6: zp ZP_WORD:2 [ main::w1#2 main::w1#1 ] 24.75: zp ZP_BYTE:4 [ main::i#2 main::i#1 ] 22: zp ZP_BYTE:5 [ main::$2 ] 
Uplift Scope [] 

Uplifting [main] best 693 combination zp ZP_WORD:2 [ main::w1#2 main::w1#1 ] reg byte x [ main::i#2 main::i#1 ] reg byte a [ main::$2 ] 
Uplifting [] best 693 combination 

ASSEMBLER BEFORE OPTIMIZATION
  // File Comments
// Tests subtracting bytes from signed words
  // Upstart
.pc = $801 "Basic"
:BasicUpstart(bbegin)
.pc = $80d "Program"
  // Global Constants & labels
  // @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:
  // main
main: {
    .label screen = $400
    .label w1 = 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] -- vbuxx=vbuc1 
    ldx #0
    // [5] phi (signed word) main::w1#2 = (signed word) $4d2 [phi:main->main::@1#1] -- vwsz1=vwsc1 
    lda #<$4d2
    sta.z w1
    lda #>$4d2
    sta.z w1+1
    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 
    // [5] phi (signed word) main::w1#2 = (signed word) main::w1#1 [phi:main::@1->main::@1#1] -- register_copy 
    jmp b1
    // main::@1
  b1:
    // [6] (signed word) main::w1#1 ← (signed word) main::w1#2 - (signed byte) $29 -- vwsz1=vwsz1_minus_vbsc1 
    lda.z w1
    sec
    sbc #$29
    sta.z w1
    lda.z w1+1
    sbc #>$29
    sta.z w1+1
    // [7] (byte~) main::$2 ← (byte) main::i#2 << (byte) 1 -- vbuaa=vbuxx_rol_1 
    txa
    asl
    // [8] *((const signed word*) main::screen#0 + (byte~) main::$2) ← (signed word) main::w1#1 -- pwsc1_derefidx_vbuaa=vwsz1 
    tay
    lda.z w1
    sta screen,y
    lda.z w1+1
    sta screen+1,y
    // [9] (byte) main::i#1 ← ++ (byte) main::i#2 -- vbuxx=_inc_vbuxx 
    inx
    // [10] if((byte) main::i#1!=(byte) $b) goto main::@1 -- vbuxx_neq_vbuc1_then_la1 
    cpx #$b
    bne b1_from_b1
    jmp breturn
    // main::@return
  breturn:
    // [11] return 
    rts
}
  // File Data

ASSEMBLER OPTIMIZATIONS
Removing instruction jmp b1
Removing instruction jmp bend
Removing instruction jmp b1
Removing instruction jmp breturn
Succesful ASM optimization Pass5NextJumpElimination
Replacing label b1_from_b1 with b1
Removing instruction b1_from_bbegin:
Removing instruction b1:
Removing instruction main_from_b1:
Removing instruction bend_from_b1:
Removing instruction b1_from_b1:
Succesful ASM optimization Pass5RedundantLabelElimination
Removing instruction bend:
Removing instruction b1_from_main:
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 bbegin:
Succesful ASM optimization Pass5UnusedLabelElimination

FINAL SYMBOL TABLE
(label) @1
(label) @begin
(label) @end
(void()) main()
(byte~) main::$2 reg byte a 22.0
(label) main::@1
(label) main::@return
(byte) main::i
(byte) main::i#1 reg byte x 16.5
(byte) main::i#2 reg byte x 8.25
(signed word*) main::screen
(const signed word*) main::screen#0 screen = (signed word*) 1024
(signed word) main::w1
(signed word) main::w1#1 w1 zp ZP_WORD:2 6.6000000000000005
(signed word) main::w1#2 w1 zp ZP_WORD:2 22.0

zp ZP_WORD:2 [ main::w1#2 main::w1#1 ]
reg byte x [ main::i#2 main::i#1 ]
reg byte a [ main::$2 ]


FINAL ASSEMBLER
Score: 591

  // File Comments
// Tests subtracting bytes from signed words
  // Upstart
.pc = $801 "Basic"
:BasicUpstart(main)
.pc = $80d "Program"
  // Global Constants & labels
  // @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
  // main
main: {
    .label screen = $400
    .label w1 = 2
    // [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 (signed word) main::w1#2 = (signed word) $4d2 [phi:main->main::@1#1] -- vwsz1=vwsc1 
    lda #<$4d2
    sta.z w1
    lda #>$4d2
    sta.z w1+1
    // [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 
    // [5] phi (signed word) main::w1#2 = (signed word) main::w1#1 [phi:main::@1->main::@1#1] -- register_copy 
    // main::@1
  b1:
    // w1 = w1 - 41
    // [6] (signed word) main::w1#1 ← (signed word) main::w1#2 - (signed byte) $29 -- vwsz1=vwsz1_minus_vbsc1 
    lda.z w1
    sec
    sbc #$29
    sta.z w1
    lda.z w1+1
    sbc #>$29
    sta.z w1+1
    // screen[i] = w1
    // [7] (byte~) main::$2 ← (byte) main::i#2 << (byte) 1 -- vbuaa=vbuxx_rol_1 
    txa
    asl
    // [8] *((const signed word*) main::screen#0 + (byte~) main::$2) ← (signed word) main::w1#1 -- pwsc1_derefidx_vbuaa=vwsz1 
    tay
    lda.z w1
    sta screen,y
    lda.z w1+1
    sta screen+1,y
    // for( byte i: 0..10 )
    // [9] (byte) main::i#1 ← ++ (byte) main::i#2 -- vbuxx=_inc_vbuxx 
    inx
    // [10] if((byte) main::i#1!=(byte) $b) goto main::@1 -- vbuxx_neq_vbuc1_then_la1 
    cpx #$b
    bne b1
    // main::@return
    // }
    // [11] return 
    rts
}
  // File Data

