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) @4
Culled Empty Block (label) main::@2
Culled Empty Block (label) @5
Culled Empty Block (label) position_sprite::@2
Culled Empty Block (label) position_sprite::@4

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

(void()) main()
main: scope:[main]  from @6
  (word) main::xpos#0 ← (word) $c8
  (byte) main::s#0 ← (byte) 0
  to:main::@1
main::@1: scope:[main]  from main main::@3
  (word) main::xpos#2 ← phi( main/(word) main::xpos#0 main::@3/(word) main::xpos#1 )
  (byte) main::s#2 ← phi( main/(byte) main::s#0 main::@3/(byte) main::s#1 )
  (byte) position_sprite::spriteno#0 ← (byte) main::s#2
  (word) position_sprite::x#0 ← (word) main::xpos#2
  (byte) position_sprite::y#0 ← (number) $32
  call position_sprite 
  to:main::@3
main::@3: scope:[main]  from main::@1
  (byte) main::s#3 ← phi( main::@1/(byte) main::s#2 )
  (word) main::xpos#3 ← phi( main::@1/(word) main::xpos#2 )
  (word) main::xpos#1 ← (word) main::xpos#3 + (number) $a
  (byte) main::s#1 ← (byte) main::s#3 + rangenext(0,7)
  (bool~) main::$1 ← (byte) main::s#1 != rangelast(0,7)
  if((bool~) main::$1) goto main::@1
  to:main::@return
main::@return: scope:[main]  from main::@3
  return 
  to:@return

(void()) position_sprite((byte) position_sprite::spriteno , (word) position_sprite::x , (byte) position_sprite::y)
position_sprite: scope:[position_sprite]  from main::@1
  (word) position_sprite::x#1 ← phi( main::@1/(word) position_sprite::x#0 )
  (byte) position_sprite::y#1 ← phi( main::@1/(byte) position_sprite::y#0 )
  (byte) position_sprite::spriteno#1 ← phi( main::@1/(byte) position_sprite::spriteno#0 )
  (number~) position_sprite::$0 ← (byte) position_sprite::spriteno#1 * (number) 2
  *((const byte*) SPRITES_YPOS + (number~) position_sprite::$0) ← (byte) position_sprite::y#1
  (number~) position_sprite::$1 ← (byte) position_sprite::spriteno#1 * (number) 2
  (byte~) position_sprite::$2 ← < (word) position_sprite::x#1
  *((const byte*) SPRITES_XPOS + (number~) position_sprite::$1) ← (byte~) position_sprite::$2
  (bool~) position_sprite::$3 ← (word) position_sprite::x#1 > (number) $ff
  if((bool~) position_sprite::$3) goto position_sprite::@1
  to:position_sprite::@3
position_sprite::@1: scope:[position_sprite]  from position_sprite
  (byte) position_sprite::spriteno#2 ← phi( position_sprite/(byte) position_sprite::spriteno#1 )
  (number~) position_sprite::$6 ← (number) 1 << (byte) position_sprite::spriteno#2
  *((const byte*) SPRITES_XMSB) ← *((const byte*) SPRITES_XMSB) | (number~) position_sprite::$6
  to:position_sprite::@return
position_sprite::@3: scope:[position_sprite]  from position_sprite
  (byte) position_sprite::spriteno#3 ← phi( position_sprite/(byte) position_sprite::spriteno#1 )
  (number~) position_sprite::$4 ← (number) 1 << (byte) position_sprite::spriteno#3
  (number~) position_sprite::$5 ← (number~) position_sprite::$4 ^ (number) $ff
  *((const byte*) SPRITES_XMSB) ← *((const byte*) SPRITES_XMSB) & (number~) position_sprite::$5
  to:position_sprite::@return
position_sprite::@return: scope:[position_sprite]  from position_sprite::@1 position_sprite::@3
  return 
  to:@return
@6: scope:[]  from @begin
  call main 
  to:@7
@7: scope:[]  from @6
  to:@end
@end: scope:[]  from @7

SYMBOL TABLE SSA
(label) @6
(label) @7
(label) @begin
(label) @end
(const byte*) SPRITES_XMSB = (byte*)(number) $d010
(const byte*) SPRITES_XPOS = (byte*)(number) $d000
(const byte*) SPRITES_YPOS = (byte*)(number) $d001
(void()) main()
(bool~) main::$1
(label) main::@1
(label) main::@3
(label) main::@return
(byte) main::s
(byte) main::s#0
(byte) main::s#1
(byte) main::s#2
(byte) main::s#3
(word) main::xpos
(word) main::xpos#0
(word) main::xpos#1
(word) main::xpos#2
(word) main::xpos#3
(void()) position_sprite((byte) position_sprite::spriteno , (word) position_sprite::x , (byte) position_sprite::y)
(number~) position_sprite::$0
(number~) position_sprite::$1
(byte~) position_sprite::$2
(bool~) position_sprite::$3
(number~) position_sprite::$4
(number~) position_sprite::$5
(number~) position_sprite::$6
(label) position_sprite::@1
(label) position_sprite::@3
(label) position_sprite::@return
(byte) position_sprite::spriteno
(byte) position_sprite::spriteno#0
(byte) position_sprite::spriteno#1
(byte) position_sprite::spriteno#2
(byte) position_sprite::spriteno#3
(word) position_sprite::x
(word) position_sprite::x#0
(word) position_sprite::x#1
(byte) position_sprite::y
(byte) position_sprite::y#0
(byte) position_sprite::y#1

Adding number conversion cast (unumber) $32 in (byte) position_sprite::y#0 ← (number) $32
Adding number conversion cast (unumber) $a in (word) main::xpos#1 ← (word) main::xpos#3 + (number) $a
Adding number conversion cast (unumber) 2 in (number~) position_sprite::$0 ← (byte) position_sprite::spriteno#1 * (number) 2
Adding number conversion cast (unumber) position_sprite::$0 in (number~) position_sprite::$0 ← (byte) position_sprite::spriteno#1 * (unumber)(number) 2
Adding number conversion cast (unumber) 2 in (number~) position_sprite::$1 ← (byte) position_sprite::spriteno#1 * (number) 2
Adding number conversion cast (unumber) position_sprite::$1 in (number~) position_sprite::$1 ← (byte) position_sprite::spriteno#1 * (unumber)(number) 2
Adding number conversion cast (unumber) $ff in (bool~) position_sprite::$3 ← (word) position_sprite::x#1 > (number) $ff
Adding number conversion cast (unumber) 1 in (number~) position_sprite::$6 ← (number) 1 << (byte) position_sprite::spriteno#2
Adding number conversion cast (unumber) position_sprite::$6 in (number~) position_sprite::$6 ← (unumber)(number) 1 << (byte) position_sprite::spriteno#2
Adding number conversion cast (unumber) 1 in (number~) position_sprite::$4 ← (number) 1 << (byte) position_sprite::spriteno#3
Adding number conversion cast (unumber) position_sprite::$4 in (number~) position_sprite::$4 ← (unumber)(number) 1 << (byte) position_sprite::spriteno#3
Adding number conversion cast (unumber) $ff in (number~) position_sprite::$5 ← (unumber~) position_sprite::$4 ^ (number) $ff
Adding number conversion cast (unumber) position_sprite::$5 in (number~) position_sprite::$5 ← (unumber~) position_sprite::$4 ^ (unumber)(number) $ff
Successful SSA optimization PassNAddNumberTypeConversions
Inlining cast (byte) position_sprite::y#0 ← (unumber)(number) $32
Successful SSA optimization Pass2InlineCast
Simplifying constant pointer cast (byte*) 53248
Simplifying constant pointer cast (byte*) 53249
Simplifying constant pointer cast (byte*) 53264
Simplifying constant integer cast $32
Simplifying constant integer cast $a
Simplifying constant integer cast 2
Simplifying constant integer cast 2
Simplifying constant integer cast $ff
Simplifying constant integer cast 1
Simplifying constant integer cast 1
Simplifying constant integer cast $ff
Successful SSA optimization PassNCastSimplification
Finalized unsigned number type (byte) $32
Finalized unsigned number type (byte) $a
Finalized unsigned number type (byte) 2
Finalized unsigned number type (byte) 2
Finalized unsigned number type (byte) $ff
Finalized unsigned number type (byte) 1
Finalized unsigned number type (byte) 1
Finalized unsigned number type (byte) $ff
Successful SSA optimization PassNFinalizeNumberTypeConversions
Inferred type updated to byte in (unumber~) position_sprite::$0 ← (byte) position_sprite::spriteno#1 * (byte) 2
Inferred type updated to byte in (unumber~) position_sprite::$1 ← (byte) position_sprite::spriteno#1 * (byte) 2
Inferred type updated to byte in (unumber~) position_sprite::$6 ← (byte) 1 << (byte) position_sprite::spriteno#2
Inferred type updated to byte in (unumber~) position_sprite::$4 ← (byte) 1 << (byte) position_sprite::spriteno#3
Inferred type updated to byte in (unumber~) position_sprite::$5 ← (byte~) position_sprite::$4 ^ (byte) $ff
Alias (word) main::xpos#2 = (word) main::xpos#3 
Alias (byte) main::s#2 = (byte) main::s#3 
Alias (byte) position_sprite::spriteno#1 = (byte) position_sprite::spriteno#2 (byte) position_sprite::spriteno#3 
Successful SSA optimization Pass2AliasElimination
Identical Phi Values (byte) position_sprite::spriteno#1 (byte) position_sprite::spriteno#0
Identical Phi Values (byte) position_sprite::y#1 (byte) position_sprite::y#0
Identical Phi Values (word) position_sprite::x#1 (word) position_sprite::x#0
Successful SSA optimization Pass2IdenticalPhiElimination
Identified duplicate assignment right side [16] (byte~) position_sprite::$1 ← (byte) position_sprite::spriteno#0 * (byte) 2
Successful SSA optimization Pass2DuplicateRValueIdentification
Simple Condition (bool~) main::$1 [10] if((byte) main::s#1!=rangelast(0,7)) goto main::@1
Simple Condition (bool~) position_sprite::$3 [19] if((word) position_sprite::x#0>(byte) $ff) goto position_sprite::@1
Successful SSA optimization Pass2ConditionalJumpSimplification
Constant (const word) main::xpos#0 = $c8
Constant (const byte) main::s#0 = 0
Constant (const byte) position_sprite::y#0 = $32
Successful SSA optimization Pass2ConstantIdentification
Resolved ranged next value [8] main::s#1 ← ++ main::s#2 to ++
Resolved ranged comparison value [10] if(main::s#1!=rangelast(0,7)) goto main::@1 to (number) 8
Adding number conversion cast (unumber) 8 in if((byte) main::s#1!=(number) 8) goto main::@1
Successful SSA optimization PassNAddNumberTypeConversions
Simplifying constant integer cast 8
Successful SSA optimization PassNCastSimplification
Finalized unsigned number type (byte) 8
Successful SSA optimization PassNFinalizeNumberTypeConversions
Alias (byte~) position_sprite::$1 = (byte~) position_sprite::$0 
Successful SSA optimization Pass2AliasElimination
Rewriting multiplication to use shift [8] (byte~) position_sprite::$1 ← (byte) position_sprite::spriteno#0 * (byte) 2
Successful SSA optimization Pass2MultiplyToShiftRewriting
Inlining constant with var siblings (const word) main::xpos#0
Inlining constant with var siblings (const byte) main::s#0
Constant inlined main::xpos#0 = (word) $c8
Constant inlined main::s#0 = (byte) 0
Successful SSA optimization Pass2ConstantInlining
Added new block during phi lifting main::@4(between main::@3 and main::@1)
Adding NOP phi() at start of @begin
Adding NOP phi() at start of @6
Adding NOP phi() at start of @7
Adding NOP phi() at start of @end
Adding NOP phi() at start of main
CALL GRAPH
Calls in [] to main:2 
Calls in [main] to position_sprite:9 

Created 2 initial phi equivalence classes
Coalesced [14] main::s#4 ← main::s#1
Coalesced [15] main::xpos#4 ← main::xpos#1
Coalesced down to 2 phi equivalence classes
Culled Empty Block (label) @7
Culled Empty Block (label) main::@4
Renumbering block @6 to @1
Renumbering block main::@3 to main::@2
Renumbering block position_sprite::@3 to position_sprite::@2
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()

(void()) main()
main: scope:[main]  from @1
  [4] phi()
  to:main::@1
main::@1: scope:[main]  from main main::@2
  [5] (word) main::xpos#2 ← phi( main/(word) $c8 main::@2/(word) main::xpos#1 )
  [5] (byte) main::s#2 ← phi( main/(byte) 0 main::@2/(byte) main::s#1 )
  [6] (byte) position_sprite::spriteno#0 ← (byte) main::s#2
  [7] (word) position_sprite::x#0 ← (word) main::xpos#2
  [8] call position_sprite 
  to:main::@2
main::@2: scope:[main]  from main::@1
  [9] (word) main::xpos#1 ← (word) main::xpos#2 + (byte) $a
  [10] (byte) main::s#1 ← ++ (byte) main::s#2
  [11] if((byte) main::s#1!=(byte) 8) goto main::@1
  to:main::@return
main::@return: scope:[main]  from main::@2
  [12] return 
  to:@return

(void()) position_sprite((byte) position_sprite::spriteno , (word) position_sprite::x , (byte) position_sprite::y)
position_sprite: scope:[position_sprite]  from main::@1
  [13] (byte~) position_sprite::$1 ← (byte) position_sprite::spriteno#0 << (byte) 1
  [14] *((const byte*) SPRITES_YPOS + (byte~) position_sprite::$1) ← (const byte) position_sprite::y#0
  [15] (byte~) position_sprite::$2 ← < (word) position_sprite::x#0
  [16] *((const byte*) SPRITES_XPOS + (byte~) position_sprite::$1) ← (byte~) position_sprite::$2
  [17] if((word) position_sprite::x#0>(byte) $ff) goto position_sprite::@1
  to:position_sprite::@2
position_sprite::@2: scope:[position_sprite]  from position_sprite
  [18] (byte~) position_sprite::$4 ← (byte) 1 << (byte) position_sprite::spriteno#0
  [19] (byte~) position_sprite::$5 ← (byte~) position_sprite::$4 ^ (byte) $ff
  [20] *((const byte*) SPRITES_XMSB) ← *((const byte*) SPRITES_XMSB) & (byte~) position_sprite::$5
  to:position_sprite::@return
position_sprite::@return: scope:[position_sprite]  from position_sprite::@1 position_sprite::@2
  [21] return 
  to:@return
position_sprite::@1: scope:[position_sprite]  from position_sprite
  [22] (byte~) position_sprite::$6 ← (byte) 1 << (byte) position_sprite::spriteno#0
  [23] *((const byte*) SPRITES_XMSB) ← *((const byte*) SPRITES_XMSB) | (byte~) position_sprite::$6
  to:position_sprite::@return


VARIABLE REGISTER WEIGHTS
(void()) main()
(byte) main::s
(byte) main::s#1 16.5
(byte) main::s#2 6.6000000000000005
(word) main::xpos
(word) main::xpos#1 7.333333333333333
(word) main::xpos#2 8.25
(void()) position_sprite((byte) position_sprite::spriteno , (word) position_sprite::x , (byte) position_sprite::y)
(byte~) position_sprite::$1 2.0
(byte~) position_sprite::$2 4.0
(byte~) position_sprite::$4 4.0
(byte~) position_sprite::$5 4.0
(byte~) position_sprite::$6 4.0
(byte) position_sprite::spriteno
(byte) position_sprite::spriteno#0 2.4285714285714284
(word) position_sprite::x
(word) position_sprite::x#0 3.0
(byte) position_sprite::y

Initial phi equivalence classes
[ main::s#2 main::s#1 ]
[ main::xpos#2 main::xpos#1 ]
Added variable position_sprite::spriteno#0 to live range equivalence class [ position_sprite::spriteno#0 ]
Added variable position_sprite::x#0 to live range equivalence class [ position_sprite::x#0 ]
Added variable position_sprite::$1 to live range equivalence class [ position_sprite::$1 ]
Added variable position_sprite::$2 to live range equivalence class [ position_sprite::$2 ]
Added variable position_sprite::$4 to live range equivalence class [ position_sprite::$4 ]
Added variable position_sprite::$5 to live range equivalence class [ position_sprite::$5 ]
Added variable position_sprite::$6 to live range equivalence class [ position_sprite::$6 ]
Complete equivalence classes
[ main::s#2 main::s#1 ]
[ main::xpos#2 main::xpos#1 ]
[ position_sprite::spriteno#0 ]
[ position_sprite::x#0 ]
[ position_sprite::$1 ]
[ position_sprite::$2 ]
[ position_sprite::$4 ]
[ position_sprite::$5 ]
[ position_sprite::$6 ]
Allocated zp[1]:2 [ main::s#2 main::s#1 ]
Allocated zp[2]:3 [ main::xpos#2 main::xpos#1 ]
Allocated zp[1]:5 [ position_sprite::spriteno#0 ]
Allocated zp[2]:6 [ position_sprite::x#0 ]
Allocated zp[1]:8 [ position_sprite::$1 ]
Allocated zp[1]:9 [ position_sprite::$2 ]
Allocated zp[1]:10 [ position_sprite::$4 ]
Allocated zp[1]:11 [ position_sprite::$5 ]
Allocated zp[1]:12 [ position_sprite::$6 ]

INITIAL ASM
Target platform is c64basic / MOS6502X
  // File Comments
// Tests rolling sprite MSB by variable amount
  // Upstart
.pc = $801 "Basic"
:BasicUpstart(__bbegin)
.pc = $80d "Program"
  // Global Constants & labels
  .label SPRITES_XPOS = $d000
  .label SPRITES_YPOS = $d001
  .label SPRITES_XMSB = $d010
  // @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 xpos = 3
    .label s = 2
    // [5] phi from main to main::@1 [phi:main->main::@1]
  __b1_from_main:
    // [5] phi (word) main::xpos#2 = (word) $c8 [phi:main->main::@1#0] -- vwuz1=vwuc1 
    lda #<$c8
    sta.z xpos
    lda #>$c8
    sta.z xpos+1
    // [5] phi (byte) main::s#2 = (byte) 0 [phi:main->main::@1#1] -- vbuz1=vbuc1 
    lda #0
    sta.z s
    jmp __b1
    // [5] phi from main::@2 to main::@1 [phi:main::@2->main::@1]
  __b1_from___b2:
    // [5] phi (word) main::xpos#2 = (word) main::xpos#1 [phi:main::@2->main::@1#0] -- register_copy 
    // [5] phi (byte) main::s#2 = (byte) main::s#1 [phi:main::@2->main::@1#1] -- register_copy 
    jmp __b1
    // main::@1
  __b1:
    // [6] (byte) position_sprite::spriteno#0 ← (byte) main::s#2 -- vbuz1=vbuz2 
    lda.z s
    sta.z position_sprite.spriteno
    // [7] (word) position_sprite::x#0 ← (word) main::xpos#2 -- vwuz1=vwuz2 
    lda.z xpos
    sta.z position_sprite.x
    lda.z xpos+1
    sta.z position_sprite.x+1
    // [8] call position_sprite 
    jsr position_sprite
    jmp __b2
    // main::@2
  __b2:
    // [9] (word) main::xpos#1 ← (word) main::xpos#2 + (byte) $a -- vwuz1=vwuz1_plus_vbuc1 
    lda #$a
    clc
    adc.z xpos
    sta.z xpos
    bcc !+
    inc.z xpos+1
  !:
    // [10] (byte) main::s#1 ← ++ (byte) main::s#2 -- vbuz1=_inc_vbuz1 
    inc.z s
    // [11] if((byte) main::s#1!=(byte) 8) goto main::@1 -- vbuz1_neq_vbuc1_then_la1 
    lda #8
    cmp.z s
    bne __b1_from___b2
    jmp __breturn
    // main::@return
  __breturn:
    // [12] return 
    rts
}
  // position_sprite
// position_sprite(byte zp(5) spriteno, word zp(6) x)
position_sprite: {
    .const y = $32
    .label __1 = 8
    .label __2 = 9
    .label __4 = $a
    .label __5 = $b
    .label __6 = $c
    .label spriteno = 5
    .label x = 6
    // [13] (byte~) position_sprite::$1 ← (byte) position_sprite::spriteno#0 << (byte) 1 -- vbuz1=vbuz2_rol_1 
    lda.z spriteno
    asl
    sta.z __1
    // [14] *((const byte*) SPRITES_YPOS + (byte~) position_sprite::$1) ← (const byte) position_sprite::y#0 -- pbuc1_derefidx_vbuz1=vbuc2 
    lda #y
    ldy.z __1
    sta SPRITES_YPOS,y
    // [15] (byte~) position_sprite::$2 ← < (word) position_sprite::x#0 -- vbuz1=_lo_vwuz2 
    lda.z x
    sta.z __2
    // [16] *((const byte*) SPRITES_XPOS + (byte~) position_sprite::$1) ← (byte~) position_sprite::$2 -- pbuc1_derefidx_vbuz1=vbuz2 
    lda.z __2
    ldy.z __1
    sta SPRITES_XPOS,y
    // [17] if((word) position_sprite::x#0>(byte) $ff) goto position_sprite::@1 -- vwuz1_gt_vbuc1_then_la1 
    lda.z x+1
    bne __b1
    lda.z x
    cmp #$ff
    beq !+
    bcs __b1
  !:
    jmp __b2
    // position_sprite::@2
  __b2:
    // [18] (byte~) position_sprite::$4 ← (byte) 1 << (byte) position_sprite::spriteno#0 -- vbuz1=vbuc1_rol_vbuz2 
    lda #1
    ldy.z spriteno
    cpy #0
    beq !e+
  !:
    asl
    dey
    bne !-
  !e:
    sta.z __4
    // [19] (byte~) position_sprite::$5 ← (byte~) position_sprite::$4 ^ (byte) $ff -- vbuz1=vbuz2_bxor_vbuc1 
    lda #$ff
    eor.z __4
    sta.z __5
    // [20] *((const byte*) SPRITES_XMSB) ← *((const byte*) SPRITES_XMSB) & (byte~) position_sprite::$5 -- _deref_pbuc1=_deref_pbuc1_band_vbuz1 
    lda SPRITES_XMSB
    and.z __5
    sta SPRITES_XMSB
    jmp __breturn
    // position_sprite::@return
  __breturn:
    // [21] return 
    rts
    // position_sprite::@1
  __b1:
    // [22] (byte~) position_sprite::$6 ← (byte) 1 << (byte) position_sprite::spriteno#0 -- vbuz1=vbuc1_rol_vbuz2 
    lda #1
    ldy.z spriteno
    cpy #0
    beq !e+
  !:
    asl
    dey
    bne !-
  !e:
    sta.z __6
    // [23] *((const byte*) SPRITES_XMSB) ← *((const byte*) SPRITES_XMSB) | (byte~) position_sprite::$6 -- _deref_pbuc1=_deref_pbuc1_bor_vbuz1 
    lda SPRITES_XMSB
    ora.z __6
    sta SPRITES_XMSB
    jmp __breturn
}
  // File Data

REGISTER UPLIFT POTENTIAL REGISTERS
Statement [7] (word) position_sprite::x#0 ← (word) main::xpos#2 [ main::s#2 main::xpos#2 position_sprite::spriteno#0 position_sprite::x#0 ] ( main:2 [ main::s#2 main::xpos#2 position_sprite::spriteno#0 position_sprite::x#0 ] ) always clobbers reg byte a 
Removing always clobbered register reg byte a as potential for zp[1]:2 [ main::s#2 main::s#1 ]
Removing always clobbered register reg byte a as potential for zp[1]:5 [ position_sprite::spriteno#0 ]
Statement [9] (word) main::xpos#1 ← (word) main::xpos#2 + (byte) $a [ main::s#2 main::xpos#1 ] ( main:2 [ main::s#2 main::xpos#1 ] ) always clobbers reg byte a 
Statement [13] (byte~) position_sprite::$1 ← (byte) position_sprite::spriteno#0 << (byte) 1 [ position_sprite::spriteno#0 position_sprite::x#0 position_sprite::$1 ] ( main:2::position_sprite:8 [ main::s#2 main::xpos#2 position_sprite::spriteno#0 position_sprite::x#0 position_sprite::$1 ] ) always clobbers reg byte a 
Statement [14] *((const byte*) SPRITES_YPOS + (byte~) position_sprite::$1) ← (const byte) position_sprite::y#0 [ position_sprite::spriteno#0 position_sprite::x#0 position_sprite::$1 ] ( main:2::position_sprite:8 [ main::s#2 main::xpos#2 position_sprite::spriteno#0 position_sprite::x#0 position_sprite::$1 ] ) always clobbers reg byte a 
Removing always clobbered register reg byte a as potential for zp[1]:8 [ position_sprite::$1 ]
Statement [15] (byte~) position_sprite::$2 ← < (word) position_sprite::x#0 [ position_sprite::spriteno#0 position_sprite::x#0 position_sprite::$1 position_sprite::$2 ] ( main:2::position_sprite:8 [ main::s#2 main::xpos#2 position_sprite::spriteno#0 position_sprite::x#0 position_sprite::$1 position_sprite::$2 ] ) always clobbers reg byte a 
Statement [17] if((word) position_sprite::x#0>(byte) $ff) goto position_sprite::@1 [ position_sprite::spriteno#0 ] ( main:2::position_sprite:8 [ main::s#2 main::xpos#2 position_sprite::spriteno#0 ] ) always clobbers reg byte a 
Statement [18] (byte~) position_sprite::$4 ← (byte) 1 << (byte) position_sprite::spriteno#0 [ position_sprite::$4 ] ( main:2::position_sprite:8 [ main::s#2 main::xpos#2 position_sprite::$4 ] ) always clobbers reg byte a 
Statement [19] (byte~) position_sprite::$5 ← (byte~) position_sprite::$4 ^ (byte) $ff [ position_sprite::$5 ] ( main:2::position_sprite:8 [ main::s#2 main::xpos#2 position_sprite::$5 ] ) always clobbers reg byte a 
Statement [20] *((const byte*) SPRITES_XMSB) ← *((const byte*) SPRITES_XMSB) & (byte~) position_sprite::$5 [ ] ( main:2::position_sprite:8 [ main::s#2 main::xpos#2 ] ) always clobbers reg byte a 
Statement [22] (byte~) position_sprite::$6 ← (byte) 1 << (byte) position_sprite::spriteno#0 [ position_sprite::$6 ] ( main:2::position_sprite:8 [ main::s#2 main::xpos#2 position_sprite::$6 ] ) always clobbers reg byte a 
Statement [23] *((const byte*) SPRITES_XMSB) ← *((const byte*) SPRITES_XMSB) | (byte~) position_sprite::$6 [ ] ( main:2::position_sprite:8 [ main::s#2 main::xpos#2 ] ) always clobbers reg byte a 
Statement [7] (word) position_sprite::x#0 ← (word) main::xpos#2 [ main::s#2 main::xpos#2 position_sprite::spriteno#0 position_sprite::x#0 ] ( main:2 [ main::s#2 main::xpos#2 position_sprite::spriteno#0 position_sprite::x#0 ] ) always clobbers reg byte a 
Statement [9] (word) main::xpos#1 ← (word) main::xpos#2 + (byte) $a [ main::s#2 main::xpos#1 ] ( main:2 [ main::s#2 main::xpos#1 ] ) always clobbers reg byte a 
Statement [13] (byte~) position_sprite::$1 ← (byte) position_sprite::spriteno#0 << (byte) 1 [ position_sprite::spriteno#0 position_sprite::x#0 position_sprite::$1 ] ( main:2::position_sprite:8 [ main::s#2 main::xpos#2 position_sprite::spriteno#0 position_sprite::x#0 position_sprite::$1 ] ) always clobbers reg byte a 
Statement [14] *((const byte*) SPRITES_YPOS + (byte~) position_sprite::$1) ← (const byte) position_sprite::y#0 [ position_sprite::spriteno#0 position_sprite::x#0 position_sprite::$1 ] ( main:2::position_sprite:8 [ main::s#2 main::xpos#2 position_sprite::spriteno#0 position_sprite::x#0 position_sprite::$1 ] ) always clobbers reg byte a 
Statement [15] (byte~) position_sprite::$2 ← < (word) position_sprite::x#0 [ position_sprite::spriteno#0 position_sprite::x#0 position_sprite::$1 position_sprite::$2 ] ( main:2::position_sprite:8 [ main::s#2 main::xpos#2 position_sprite::spriteno#0 position_sprite::x#0 position_sprite::$1 position_sprite::$2 ] ) always clobbers reg byte a 
Statement [17] if((word) position_sprite::x#0>(byte) $ff) goto position_sprite::@1 [ position_sprite::spriteno#0 ] ( main:2::position_sprite:8 [ main::s#2 main::xpos#2 position_sprite::spriteno#0 ] ) always clobbers reg byte a 
Statement [18] (byte~) position_sprite::$4 ← (byte) 1 << (byte) position_sprite::spriteno#0 [ position_sprite::$4 ] ( main:2::position_sprite:8 [ main::s#2 main::xpos#2 position_sprite::$4 ] ) always clobbers reg byte a 
Statement [19] (byte~) position_sprite::$5 ← (byte~) position_sprite::$4 ^ (byte) $ff [ position_sprite::$5 ] ( main:2::position_sprite:8 [ main::s#2 main::xpos#2 position_sprite::$5 ] ) always clobbers reg byte a 
Statement [20] *((const byte*) SPRITES_XMSB) ← *((const byte*) SPRITES_XMSB) & (byte~) position_sprite::$5 [ ] ( main:2::position_sprite:8 [ main::s#2 main::xpos#2 ] ) always clobbers reg byte a 
Statement [22] (byte~) position_sprite::$6 ← (byte) 1 << (byte) position_sprite::spriteno#0 [ position_sprite::$6 ] ( main:2::position_sprite:8 [ main::s#2 main::xpos#2 position_sprite::$6 ] ) always clobbers reg byte a 
Statement [23] *((const byte*) SPRITES_XMSB) ← *((const byte*) SPRITES_XMSB) | (byte~) position_sprite::$6 [ ] ( main:2::position_sprite:8 [ main::s#2 main::xpos#2 ] ) always clobbers reg byte a 
Potential registers zp[1]:2 [ main::s#2 main::s#1 ] : zp[1]:2 , reg byte x , reg byte y , 
Potential registers zp[2]:3 [ main::xpos#2 main::xpos#1 ] : zp[2]:3 , 
Potential registers zp[1]:5 [ position_sprite::spriteno#0 ] : zp[1]:5 , reg byte x , reg byte y , 
Potential registers zp[2]:6 [ position_sprite::x#0 ] : zp[2]:6 , 
Potential registers zp[1]:8 [ position_sprite::$1 ] : zp[1]:8 , reg byte x , reg byte y , 
Potential registers zp[1]:9 [ position_sprite::$2 ] : zp[1]:9 , reg byte a , reg byte x , reg byte y , 
Potential registers zp[1]:10 [ position_sprite::$4 ] : zp[1]:10 , reg byte a , reg byte x , reg byte y , 
Potential registers zp[1]:11 [ position_sprite::$5 ] : zp[1]:11 , reg byte a , reg byte x , reg byte y , 
Potential registers zp[1]:12 [ position_sprite::$6 ] : zp[1]:12 , reg byte a , reg byte x , reg byte y , 

REGISTER UPLIFT SCOPES
Uplift Scope [main] 23.1: zp[1]:2 [ main::s#2 main::s#1 ] 15.58: zp[2]:3 [ main::xpos#2 main::xpos#1 ] 
Uplift Scope [position_sprite] 4: zp[1]:9 [ position_sprite::$2 ] 4: zp[1]:10 [ position_sprite::$4 ] 4: zp[1]:11 [ position_sprite::$5 ] 4: zp[1]:12 [ position_sprite::$6 ] 3: zp[2]:6 [ position_sprite::x#0 ] 2.43: zp[1]:5 [ position_sprite::spriteno#0 ] 2: zp[1]:8 [ position_sprite::$1 ] 
Uplift Scope [] 

Uplifting [main] best 841 combination reg byte x [ main::s#2 main::s#1 ] zp[2]:3 [ main::xpos#2 main::xpos#1 ] 
Uplifting [position_sprite] best 817 combination reg byte a [ position_sprite::$2 ] reg byte a [ position_sprite::$4 ] reg byte a [ position_sprite::$5 ] reg byte a [ position_sprite::$6 ] zp[2]:6 [ position_sprite::x#0 ] zp[1]:5 [ position_sprite::spriteno#0 ] zp[1]:8 [ position_sprite::$1 ] 
Limited combination testing to 100 combinations of 2304 possible.
Uplifting [] best 817 combination 
Attempting to uplift remaining variables inzp[1]:5 [ position_sprite::spriteno#0 ]
Uplifting [position_sprite] best 817 combination zp[1]:5 [ position_sprite::spriteno#0 ] 
Attempting to uplift remaining variables inzp[1]:8 [ position_sprite::$1 ]
Uplifting [position_sprite] best 810 combination reg byte y [ position_sprite::$1 ] 
Coalescing zero page register [ zp[2]:3 [ main::xpos#2 main::xpos#1 ] ] with [ zp[2]:6 [ position_sprite::x#0 ] ] - score: 1
Allocated (was zp[2]:3) zp[2]:2 [ main::xpos#2 main::xpos#1 position_sprite::x#0 ]
Allocated (was zp[1]:5) zp[1]:4 [ position_sprite::spriteno#0 ]

ASSEMBLER BEFORE OPTIMIZATION
  // File Comments
// Tests rolling sprite MSB by variable amount
  // Upstart
.pc = $801 "Basic"
:BasicUpstart(__bbegin)
.pc = $80d "Program"
  // Global Constants & labels
  .label SPRITES_XPOS = $d000
  .label SPRITES_YPOS = $d001
  .label SPRITES_XMSB = $d010
  // @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 xpos = 2
    // [5] phi from main to main::@1 [phi:main->main::@1]
  __b1_from_main:
    // [5] phi (word) main::xpos#2 = (word) $c8 [phi:main->main::@1#0] -- vwuz1=vwuc1 
    lda #<$c8
    sta.z xpos
    lda #>$c8
    sta.z xpos+1
    // [5] phi (byte) main::s#2 = (byte) 0 [phi:main->main::@1#1] -- vbuxx=vbuc1 
    ldx #0
    jmp __b1
    // [5] phi from main::@2 to main::@1 [phi:main::@2->main::@1]
  __b1_from___b2:
    // [5] phi (word) main::xpos#2 = (word) main::xpos#1 [phi:main::@2->main::@1#0] -- register_copy 
    // [5] phi (byte) main::s#2 = (byte) main::s#1 [phi:main::@2->main::@1#1] -- register_copy 
    jmp __b1
    // main::@1
  __b1:
    // [6] (byte) position_sprite::spriteno#0 ← (byte) main::s#2 -- vbuz1=vbuxx 
    stx.z position_sprite.spriteno
    // [7] (word) position_sprite::x#0 ← (word) main::xpos#2
    // [8] call position_sprite 
    jsr position_sprite
    jmp __b2
    // main::@2
  __b2:
    // [9] (word) main::xpos#1 ← (word) main::xpos#2 + (byte) $a -- vwuz1=vwuz1_plus_vbuc1 
    lda #$a
    clc
    adc.z xpos
    sta.z xpos
    bcc !+
    inc.z xpos+1
  !:
    // [10] (byte) main::s#1 ← ++ (byte) main::s#2 -- vbuxx=_inc_vbuxx 
    inx
    // [11] if((byte) main::s#1!=(byte) 8) goto main::@1 -- vbuxx_neq_vbuc1_then_la1 
    cpx #8
    bne __b1_from___b2
    jmp __breturn
    // main::@return
  __breturn:
    // [12] return 
    rts
}
  // position_sprite
// position_sprite(byte zp(4) spriteno, word zp(2) x)
position_sprite: {
    .const y = $32
    .label spriteno = 4
    .label x = 2
    // [13] (byte~) position_sprite::$1 ← (byte) position_sprite::spriteno#0 << (byte) 1 -- vbuyy=vbuz1_rol_1 
    lda.z spriteno
    asl
    tay
    // [14] *((const byte*) SPRITES_YPOS + (byte~) position_sprite::$1) ← (const byte) position_sprite::y#0 -- pbuc1_derefidx_vbuyy=vbuc2 
    lda #y
    sta SPRITES_YPOS,y
    // [15] (byte~) position_sprite::$2 ← < (word) position_sprite::x#0 -- vbuaa=_lo_vwuz1 
    lda.z x
    // [16] *((const byte*) SPRITES_XPOS + (byte~) position_sprite::$1) ← (byte~) position_sprite::$2 -- pbuc1_derefidx_vbuyy=vbuaa 
    sta SPRITES_XPOS,y
    // [17] if((word) position_sprite::x#0>(byte) $ff) goto position_sprite::@1 -- vwuz1_gt_vbuc1_then_la1 
    lda.z x+1
    bne __b1
    lda.z x
    cmp #$ff
    beq !+
    bcs __b1
  !:
    jmp __b2
    // position_sprite::@2
  __b2:
    // [18] (byte~) position_sprite::$4 ← (byte) 1 << (byte) position_sprite::spriteno#0 -- vbuaa=vbuc1_rol_vbuz1 
    lda #1
    ldy.z spriteno
    cpy #0
    beq !e+
  !:
    asl
    dey
    bne !-
  !e:
    // [19] (byte~) position_sprite::$5 ← (byte~) position_sprite::$4 ^ (byte) $ff -- vbuaa=vbuaa_bxor_vbuc1 
    eor #$ff
    // [20] *((const byte*) SPRITES_XMSB) ← *((const byte*) SPRITES_XMSB) & (byte~) position_sprite::$5 -- _deref_pbuc1=_deref_pbuc1_band_vbuaa 
    and SPRITES_XMSB
    sta SPRITES_XMSB
    jmp __breturn
    // position_sprite::@return
  __breturn:
    // [21] return 
    rts
    // position_sprite::@1
  __b1:
    // [22] (byte~) position_sprite::$6 ← (byte) 1 << (byte) position_sprite::spriteno#0 -- vbuaa=vbuc1_rol_vbuz1 
    lda #1
    ldy.z spriteno
    cpy #0
    beq !e+
  !:
    asl
    dey
    bne !-
  !e:
    // [23] *((const byte*) SPRITES_XMSB) ← *((const byte*) SPRITES_XMSB) | (byte~) position_sprite::$6 -- _deref_pbuc1=_deref_pbuc1_bor_vbuaa 
    ora SPRITES_XMSB
    sta SPRITES_XMSB
    jmp __breturn
}
  // File Data

ASSEMBLER OPTIMIZATIONS
Removing instruction jmp __b1
Removing instruction jmp __bend
Removing instruction jmp __b1
Removing instruction jmp __b2
Removing instruction jmp __breturn
Removing instruction jmp __b2
Removing instruction jmp __breturn
Succesful ASM optimization Pass5NextJumpElimination
Replacing label __bbegin with __b1
Replacing label __b1_from___b2 with __b1
Removing instruction __bbegin:
Removing instruction __b1_from___bbegin:
Removing instruction main_from___b1:
Removing instruction __bend_from___b1:
Removing instruction __b1_from___b2:
Succesful ASM optimization Pass5RedundantLabelElimination
Removing instruction __bend:
Removing instruction __b1_from_main:
Removing instruction __b2:
Removing instruction __breturn:
Removing instruction __b2:
Succesful ASM optimization Pass5UnusedLabelElimination
Updating BasicUpstart to call main directly
Removing instruction jsr main
Succesful ASM optimization Pass5SkipBegin
Replacing jump to rts with rts in jmp __breturn
Succesful ASM optimization Pass5DoubleJumpElimination
Removing instruction jmp __b1
Succesful ASM optimization Pass5NextJumpElimination
Removing instruction __b1:
Removing instruction __breturn:
Succesful ASM optimization Pass5UnusedLabelElimination

FINAL SYMBOL TABLE
(label) @1
(label) @begin
(label) @end
(const byte*) SPRITES_XMSB = (byte*) 53264
(const byte*) SPRITES_XPOS = (byte*) 53248
(const byte*) SPRITES_YPOS = (byte*) 53249
(void()) main()
(label) main::@1
(label) main::@2
(label) main::@return
(byte) main::s
(byte) main::s#1 reg byte x 16.5
(byte) main::s#2 reg byte x 6.6000000000000005
(word) main::xpos
(word) main::xpos#1 xpos zp[2]:2 7.333333333333333
(word) main::xpos#2 xpos zp[2]:2 8.25
(void()) position_sprite((byte) position_sprite::spriteno , (word) position_sprite::x , (byte) position_sprite::y)
(byte~) position_sprite::$1 reg byte y 2.0
(byte~) position_sprite::$2 reg byte a 4.0
(byte~) position_sprite::$4 reg byte a 4.0
(byte~) position_sprite::$5 reg byte a 4.0
(byte~) position_sprite::$6 reg byte a 4.0
(label) position_sprite::@1
(label) position_sprite::@2
(label) position_sprite::@return
(byte) position_sprite::spriteno
(byte) position_sprite::spriteno#0 spriteno zp[1]:4 2.4285714285714284
(word) position_sprite::x
(word) position_sprite::x#0 x zp[2]:2 3.0
(byte) position_sprite::y
(const byte) position_sprite::y#0 y = (byte) $32

reg byte x [ main::s#2 main::s#1 ]
zp[2]:2 [ main::xpos#2 main::xpos#1 position_sprite::x#0 ]
zp[1]:4 [ position_sprite::spriteno#0 ]
reg byte y [ position_sprite::$1 ]
reg byte a [ position_sprite::$2 ]
reg byte a [ position_sprite::$4 ]
reg byte a [ position_sprite::$5 ]
reg byte a [ position_sprite::$6 ]


FINAL ASSEMBLER
Score: 555

  // File Comments
// Tests rolling sprite MSB by variable amount
  // Upstart
.pc = $801 "Basic"
:BasicUpstart(main)
.pc = $80d "Program"
  // Global Constants & labels
  .label SPRITES_XPOS = $d000
  .label SPRITES_YPOS = $d001
  .label SPRITES_XMSB = $d010
  // @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 xpos = 2
    // [5] phi from main to main::@1 [phi:main->main::@1]
    // [5] phi (word) main::xpos#2 = (word) $c8 [phi:main->main::@1#0] -- vwuz1=vwuc1 
    lda #<$c8
    sta.z xpos
    lda #>$c8
    sta.z xpos+1
    // [5] phi (byte) main::s#2 = (byte) 0 [phi:main->main::@1#1] -- vbuxx=vbuc1 
    ldx #0
    // [5] phi from main::@2 to main::@1 [phi:main::@2->main::@1]
    // [5] phi (word) main::xpos#2 = (word) main::xpos#1 [phi:main::@2->main::@1#0] -- register_copy 
    // [5] phi (byte) main::s#2 = (byte) main::s#1 [phi:main::@2->main::@1#1] -- register_copy 
    // main::@1
  __b1:
    // position_sprite(s, xpos, 50)
    // [6] (byte) position_sprite::spriteno#0 ← (byte) main::s#2 -- vbuz1=vbuxx 
    stx.z position_sprite.spriteno
    // [7] (word) position_sprite::x#0 ← (word) main::xpos#2
    // [8] call position_sprite 
    jsr position_sprite
    // main::@2
    // xpos += 10
    // [9] (word) main::xpos#1 ← (word) main::xpos#2 + (byte) $a -- vwuz1=vwuz1_plus_vbuc1 
    lda #$a
    clc
    adc.z xpos
    sta.z xpos
    bcc !+
    inc.z xpos+1
  !:
    // for(byte s: 0..7)
    // [10] (byte) main::s#1 ← ++ (byte) main::s#2 -- vbuxx=_inc_vbuxx 
    inx
    // [11] if((byte) main::s#1!=(byte) 8) goto main::@1 -- vbuxx_neq_vbuc1_then_la1 
    cpx #8
    bne __b1
    // main::@return
    // }
    // [12] return 
    rts
}
  // position_sprite
// position_sprite(byte zp(4) spriteno, word zp(2) x)
position_sprite: {
    .const y = $32
    .label spriteno = 4
    .label x = 2
    // spriteno * 2
    // [13] (byte~) position_sprite::$1 ← (byte) position_sprite::spriteno#0 << (byte) 1 -- vbuyy=vbuz1_rol_1 
    lda.z spriteno
    asl
    tay
    // SPRITES_YPOS[spriteno * 2] = y
    // [14] *((const byte*) SPRITES_YPOS + (byte~) position_sprite::$1) ← (const byte) position_sprite::y#0 -- pbuc1_derefidx_vbuyy=vbuc2 
    lda #y
    sta SPRITES_YPOS,y
    // <x
    // [15] (byte~) position_sprite::$2 ← < (word) position_sprite::x#0 -- vbuaa=_lo_vwuz1 
    lda.z x
    // SPRITES_XPOS[spriteno * 2] = <x
    // [16] *((const byte*) SPRITES_XPOS + (byte~) position_sprite::$1) ← (byte~) position_sprite::$2 -- pbuc1_derefidx_vbuyy=vbuaa 
    sta SPRITES_XPOS,y
    // if (x > 255)
    // [17] if((word) position_sprite::x#0>(byte) $ff) goto position_sprite::@1 -- vwuz1_gt_vbuc1_then_la1 
    lda.z x+1
    bne __b1
    lda.z x
    cmp #$ff
    beq !+
    bcs __b1
  !:
    // position_sprite::@2
    // 1 << spriteno
    // [18] (byte~) position_sprite::$4 ← (byte) 1 << (byte) position_sprite::spriteno#0 -- vbuaa=vbuc1_rol_vbuz1 
    lda #1
    ldy.z spriteno
    cpy #0
    beq !e+
  !:
    asl
    dey
    bne !-
  !e:
    // (1 << spriteno) ^ $ff
    // [19] (byte~) position_sprite::$5 ← (byte~) position_sprite::$4 ^ (byte) $ff -- vbuaa=vbuaa_bxor_vbuc1 
    eor #$ff
    // *SPRITES_XMSB &= (1 << spriteno) ^ $ff
    // [20] *((const byte*) SPRITES_XMSB) ← *((const byte*) SPRITES_XMSB) & (byte~) position_sprite::$5 -- _deref_pbuc1=_deref_pbuc1_band_vbuaa 
    and SPRITES_XMSB
    sta SPRITES_XMSB
    // position_sprite::@return
    // }
    // [21] return 
    rts
    // position_sprite::@1
  __b1:
    // 1 << spriteno
    // [22] (byte~) position_sprite::$6 ← (byte) 1 << (byte) position_sprite::spriteno#0 -- vbuaa=vbuc1_rol_vbuz1 
    lda #1
    ldy.z spriteno
    cpy #0
    beq !e+
  !:
    asl
    dey
    bne !-
  !e:
    // *SPRITES_XMSB |= 1 << spriteno
    // [23] *((const byte*) SPRITES_XMSB) ← *((const byte*) SPRITES_XMSB) | (byte~) position_sprite::$6 -- _deref_pbuc1=_deref_pbuc1_bor_vbuaa 
    ora SPRITES_XMSB
    sta SPRITES_XMSB
    rts
}
  // File Data

