Fixing pointer array-indexing *((const signed word*) SCREEN + (number) 0)
Fixing pointer array-indexing *((const signed word*) SCREEN + (number) 1)
Culled Empty Block (label) next::@1

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

(void()) main()
main: scope:[main]  from @2
  (signed word) current#7 ← phi( @2/(signed word) current#8 )
  (signed word~) main::$0 ← call next 
  (number~) main::$2 ← (number) 0 * (const byte) SIZEOF_SIGNED_WORD
  *((const signed word*) SCREEN + (number~) main::$2) ← (signed word~) main::$0
  (signed word~) main::$1 ← call next 
  (number~) main::$3 ← (number) 1 * (const byte) SIZEOF_SIGNED_WORD
  *((const signed word*) SCREEN + (number~) main::$3) ← (signed word~) main::$1
  to:main::@return
main::@return: scope:[main]  from main
  (signed word) current#4 ← phi( main/(signed word) current#7 )
  (signed word) current#0 ← (signed word) current#4
  return 
  to:@return
@1: scope:[]  from @begin
  (signed word) current#1 ← (signed word) $30
  to:@2

__stackcall (signed word()) next()
next: scope:[next]  from
  (signed word) current#5 ← phi( )
  (signed word) next::return#0 ← (signed word) current#5
  (signed word) current#2 ← ++ (signed word) current#5
  to:next::@return
next::@return: scope:[next]  from next
  (signed word) next::return#1 ← phi( next/(signed word) next::return#0 )
  return (signed word) next::return#1
  to:@return
@2: scope:[]  from @1
  (signed word) current#8 ← phi( @1/(signed word) current#1 )
  call main 
  to:@3
@3: scope:[]  from @2
  (signed word) current#6 ← phi( @2/(signed word) current#0 )
  (signed word) current#3 ← (signed word) current#6
  to:@end
@end: scope:[]  from @3

SYMBOL TABLE SSA
(label) @1
(label) @2
(label) @3
(label) @begin
(label) @end
(const signed word*) SCREEN = (signed word*)(number) $400
(const byte) SIZEOF_SIGNED_WORD = (byte) 2
(signed word) current
(signed word) current#0
(signed word) current#1
(signed word) current#2
(signed word) current#3
(signed word) current#4
(signed word) current#5
(signed word) current#6
(signed word) current#7
(signed word) current#8
(void()) main()
(signed word~) main::$0
(signed word~) main::$1
(number~) main::$2
(number~) main::$3
(label) main::@return
__stackcall (signed word()) next()
(label) next::@return
(signed word) next::return
(signed word) next::return#0
(signed word) next::return#1

Adding number conversion cast (unumber) 0 in (number~) main::$2 ← (number) 0 * (const byte) SIZEOF_SIGNED_WORD
Adding number conversion cast (unumber) main::$2 in (number~) main::$2 ← (unumber)(number) 0 * (const byte) SIZEOF_SIGNED_WORD
Adding number conversion cast (unumber) 1 in (number~) main::$3 ← (number) 1 * (const byte) SIZEOF_SIGNED_WORD
Adding number conversion cast (unumber) main::$3 in (number~) main::$3 ← (unumber)(number) 1 * (const byte) SIZEOF_SIGNED_WORD
Successful SSA optimization PassNAddNumberTypeConversions
Simplifying constant pointer cast (signed word*) 1024
Simplifying constant integer cast 0
Simplifying constant integer cast 1
Successful SSA optimization PassNCastSimplification
Finalized unsigned number type (byte) 0
Finalized unsigned number type (byte) 1
Successful SSA optimization PassNFinalizeNumberTypeConversions
Inferred type updated to byte in (unumber~) main::$2 ← (byte) 0 * (const byte) SIZEOF_SIGNED_WORD
Inferred type updated to byte in (unumber~) main::$3 ← (byte) 1 * (const byte) SIZEOF_SIGNED_WORD
Alias (signed word) current#0 = (signed word) current#4 (signed word) current#7 
Alias (signed word) next::return#0 = (signed word) next::return#1 
Alias (signed word) current#1 = (signed word) current#8 
Alias (signed word) current#3 = (signed word) current#6 
Successful SSA optimization Pass2AliasElimination
Identical Phi Values (signed word) current#0 (signed word) current#1
Identical Phi Values (signed word) current#3 (signed word) current#0
Successful SSA optimization Pass2IdenticalPhiElimination
Constant right-side identified [2] (byte~) main::$2 ← (byte) 0 * (const byte) SIZEOF_SIGNED_WORD
Constant right-side identified [5] (byte~) main::$3 ← (byte) 1 * (const byte) SIZEOF_SIGNED_WORD
Successful SSA optimization Pass2ConstantRValueConsolidation
Constant (const byte) main::$2 = 0*SIZEOF_SIGNED_WORD
Constant (const byte) main::$3 = 1*SIZEOF_SIGNED_WORD
Constant (const signed word) current#1 = $30
Successful SSA optimization Pass2ConstantIdentification
Simplifying constant evaluating to zero (byte) 0*(const byte) SIZEOF_SIGNED_WORD in 
Successful SSA optimization PassNSimplifyConstantZero
Simplifying expression containing zero SCREEN in [3] *((const signed word*) SCREEN + (const byte) main::$2) ← (signed word~) main::$0
Successful SSA optimization PassNSimplifyExpressionWithZero
Eliminating unused variable (signed word) current#2 and assignment [7] (signed word) current#2 ← ++ (signed word) current#5
Eliminating unused constant (const byte) main::$2
Eliminating unused constant (const signed word) current#1
Successful SSA optimization PassNEliminateUnusedVars
Constant inlined main::$3 = (byte) 1*(const byte) SIZEOF_SIGNED_WORD
Successful SSA optimization Pass2ConstantInlining
Consolidated array index constant in *(SCREEN+1*SIZEOF_SIGNED_WORD)
Successful SSA optimization Pass2ConstantAdditionElimination
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 @3
Adding NOP phi() at start of @end
Adding NOP phi() at start of main
CALL GRAPH
Calls in [] to main:3 
Calls in [main] to next:7 next:9 

Created 1 initial phi equivalence classes
Coalesced down to 1 phi equivalence classes
Culled Empty Block (label) @1
Culled Empty Block (label) @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 main
Calling convention STACK_CALL adding prepare/execute/finalize for [5] (signed word~) main::$0 ← call next 
Calling convention STACK_CALL adding prepare/execute/finalize for [7] (signed word~) main::$1 ← call next 

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()
  [5] callprepare next 
  [6] callexecute next 
  [7] (signed word~) main::$0 ← callfinalize next 
  [8] *((const signed word*) SCREEN) ← (signed word~) main::$0
  [9] callprepare next 
  [10] callexecute next 
  [11] (signed word~) main::$1 ← callfinalize next 
  [12] *((const signed word*) SCREEN+(byte) 1*(const byte) SIZEOF_SIGNED_WORD) ← (signed word~) main::$1
  to:main::@return
main::@return: scope:[main]  from main
  [13] return 
  to:@return

__stackcall (signed word()) next()
next: scope:[next]  from
  [14] (signed word) current#5 ← phi( )
  [15] (signed word) next::return#0 ← (signed word) current#5
  to:next::@return
next::@return: scope:[next]  from next
  [16] return (signed word) next::return#0
  to:@return


VARIABLE REGISTER WEIGHTS
(signed word) current
(signed word) current#5 2.0
(void()) main()
(signed word~) main::$0 2.0
(signed word~) main::$1 2.0
__stackcall (signed word()) next()
(signed word) next::return
(signed word) next::return#0 2.0

Initial phi equivalence classes
[ current#5 ]
Added variable main::$0 to live range equivalence class [ main::$0 ]
Added variable main::$1 to live range equivalence class [ main::$1 ]
Added variable next::return#0 to live range equivalence class [ next::return#0 ]
Complete equivalence classes
[ current#5 ]
[ main::$0 ]
[ main::$1 ]
[ next::return#0 ]
Allocated zp[2]:2 [ current#5 ]
Allocated zp[2]:4 [ main::$0 ]
Allocated zp[2]:6 [ main::$1 ]
Allocated zp[2]:8 [ next::return#0 ]

INITIAL ASM
Target platform is c64basic / MOS6502X
  // File Comments
// Test a procedure with calling convention stack
// Return value larger than parameter
  // Upstart
.pc = $801 "Basic"
:BasicUpstart(__bbegin)
.pc = $80d "Program"
  // Global Constants & labels
  .label SCREEN = $400
  .const SIZEOF_SIGNED_WORD = 2
  .const STACK_BASE = $103
  .label current = 2
  // @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 __0 = 4
    .label __1 = 6
    // [5] callprepare next 
    // [5] callprepare next  -- _stackpushbyte_2 
    pha
    pha
    // [5] callprepare next 
    // [6] callexecute next  -- jsr 
    jsr next
    // [7] (signed word~) main::$0 ← callfinalize next 
    // [7] (signed word~) main::$0 ← callfinalize next  -- vwsz1=_stackpullsword_ 
    pla
    sta.z __0
    pla
    sta.z __0+1
    // [8] *((const signed word*) SCREEN) ← (signed word~) main::$0 -- _deref_pwsc1=vwsz1 
    lda.z __0
    sta SCREEN
    lda.z __0+1
    sta SCREEN+1
    // [9] callprepare next 
    // [9] callprepare next  -- _stackpushbyte_2 
    pha
    pha
    // [9] callprepare next 
    // [10] callexecute next  -- jsr 
    jsr next
    // [11] (signed word~) main::$1 ← callfinalize next 
    // [11] (signed word~) main::$1 ← callfinalize next  -- vwsz1=_stackpullsword_ 
    pla
    sta.z __1
    pla
    sta.z __1+1
    // [12] *((const signed word*) SCREEN+(byte) 1*(const byte) SIZEOF_SIGNED_WORD) ← (signed word~) main::$1 -- _deref_pwsc1=vwsz1 
    lda.z __1
    sta SCREEN+1*SIZEOF_SIGNED_WORD
    lda.z __1+1
    sta SCREEN+1*SIZEOF_SIGNED_WORD+1
    jmp __breturn
    // main::@return
  __breturn:
    // [13] return 
    rts
}
  // next
next: {
    .const OFFSET_STACK_RETURN = 0
    .label return = 8
    // [15] (signed word) next::return#0 ← (signed word) current#5 -- vwsz1=vwsz2 
    lda.z current
    sta.z return
    lda.z current+1
    sta.z return+1
    jmp __breturn
    // next::@return
  __breturn:
    // [16] return (signed word) next::return#0
    // [16] return (signed word) next::return#0 -- _stackidxsword_vbuc1=vwsz1 
    tsx
    lda.z return
    sta STACK_BASE+OFFSET_STACK_RETURN,x
    lda.z return+1
    sta STACK_BASE+OFFSET_STACK_RETURN+1,x
    rts
}
  // File Data

REGISTER UPLIFT POTENTIAL REGISTERS
Statement [7] (signed word~) main::$0 ← callfinalize next  [ main::$0 ] ( main:2 [ main::$0 ] ) always clobbers reg byte a 
Statement [8] *((const signed word*) SCREEN) ← (signed word~) main::$0 [ ] ( main:2 [ ] ) always clobbers reg byte a 
Statement [11] (signed word~) main::$1 ← callfinalize next  [ main::$1 ] ( main:2 [ main::$1 ] ) always clobbers reg byte a 
Statement [12] *((const signed word*) SCREEN+(byte) 1*(const byte) SIZEOF_SIGNED_WORD) ← (signed word~) main::$1 [ ] ( main:2 [ ] ) always clobbers reg byte a 
Statement [15] (signed word) next::return#0 ← (signed word) current#5 [ next::return#0 ] ( main:2::next:6 [ next::return#0 ] main:2::next:10 [ next::return#0 ] ) always clobbers reg byte a 
Statement [16] return (signed word) next::return#0 [ ] ( main:2::next:6 [ ] main:2::next:10 [ ] ) always clobbers reg byte a reg byte x 
Potential registers zp[2]:2 [ current#5 ] : zp[2]:2 , 
Potential registers zp[2]:4 [ main::$0 ] : zp[2]:4 , 
Potential registers zp[2]:6 [ main::$1 ] : zp[2]:6 , 
Potential registers zp[2]:8 [ next::return#0 ] : zp[2]:8 , 

REGISTER UPLIFT SCOPES
Uplift Scope [main] 2: zp[2]:4 [ main::$0 ] 2: zp[2]:6 [ main::$1 ] 
Uplift Scope [next] 2: zp[2]:8 [ next::return#0 ] 
Uplift Scope [] 2: zp[2]:2 [ current#5 ] 

Uplifting [main] best 140 combination zp[2]:4 [ main::$0 ] zp[2]:6 [ main::$1 ] 
Uplifting [next] best 140 combination zp[2]:8 [ next::return#0 ] 
Uplifting [] best 140 combination zp[2]:2 [ current#5 ] 
Coalescing zero page register [ zp[2]:2 [ current#5 ] ] with [ zp[2]:8 [ next::return#0 ] ] - score: 1
Coalescing zero page register [ zp[2]:4 [ main::$0 ] ] with [ zp[2]:2 [ current#5 next::return#0 ] ]
Allocated (was zp[2]:4) zp[2]:2 [ main::$0 current#5 next::return#0 ]
Allocated (was zp[2]:6) zp[2]:4 [ main::$1 ]

ASSEMBLER BEFORE OPTIMIZATION
  // File Comments
// Test a procedure with calling convention stack
// Return value larger than parameter
  // Upstart
.pc = $801 "Basic"
:BasicUpstart(__bbegin)
.pc = $80d "Program"
  // Global Constants & labels
  .label SCREEN = $400
  .const SIZEOF_SIGNED_WORD = 2
  .const STACK_BASE = $103
  .label current = 2
  // @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 __0 = 2
    .label __1 = 4
    // [5] callprepare next 
    // [5] callprepare next  -- _stackpushbyte_2 
    pha
    pha
    // [5] callprepare next 
    // [6] callexecute next  -- jsr 
    jsr next
    // [7] (signed word~) main::$0 ← callfinalize next 
    // [7] (signed word~) main::$0 ← callfinalize next  -- vwsz1=_stackpullsword_ 
    pla
    sta.z __0
    pla
    sta.z __0+1
    // [8] *((const signed word*) SCREEN) ← (signed word~) main::$0 -- _deref_pwsc1=vwsz1 
    lda.z __0
    sta SCREEN
    lda.z __0+1
    sta SCREEN+1
    // [9] callprepare next 
    // [9] callprepare next  -- _stackpushbyte_2 
    pha
    pha
    // [9] callprepare next 
    // [10] callexecute next  -- jsr 
    jsr next
    // [11] (signed word~) main::$1 ← callfinalize next 
    // [11] (signed word~) main::$1 ← callfinalize next  -- vwsz1=_stackpullsword_ 
    pla
    sta.z __1
    pla
    sta.z __1+1
    // [12] *((const signed word*) SCREEN+(byte) 1*(const byte) SIZEOF_SIGNED_WORD) ← (signed word~) main::$1 -- _deref_pwsc1=vwsz1 
    lda.z __1
    sta SCREEN+1*SIZEOF_SIGNED_WORD
    lda.z __1+1
    sta SCREEN+1*SIZEOF_SIGNED_WORD+1
    jmp __breturn
    // main::@return
  __breturn:
    // [13] return 
    rts
}
  // next
next: {
    .const OFFSET_STACK_RETURN = 0
    .label return = 2
    // [15] (signed word) next::return#0 ← (signed word) current#5
    jmp __breturn
    // next::@return
  __breturn:
    // [16] return (signed word) next::return#0
    // [16] return (signed word) next::return#0 -- _stackidxsword_vbuc1=vwsz1 
    tsx
    lda.z return
    sta STACK_BASE+OFFSET_STACK_RETURN,x
    lda.z return+1
    sta STACK_BASE+OFFSET_STACK_RETURN+1,x
    rts
}
  // File Data

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

FINAL SYMBOL TABLE
(label) @1
(label) @begin
(label) @end
(const signed word*) SCREEN = (signed word*) 1024
(const byte) SIZEOF_SIGNED_WORD = (byte) 2
(const word) STACK_BASE = (word) $103
(signed word) current
(signed word) current#5 current zp[2]:2 2.0
(void()) main()
(signed word~) main::$0 zp[2]:2 2.0
(signed word~) main::$1 zp[2]:4 2.0
(label) main::@return
__stackcall (signed word()) next()
(label) next::@return
(const byte) next::OFFSET_STACK_RETURN = (byte) 0
(signed word) next::return
(signed word) next::return#0 return zp[2]:2 2.0

zp[2]:2 [ main::$0 current#5 next::return#0 ]
zp[2]:4 [ main::$1 ]


FINAL ASSEMBLER
Score: 110

  // File Comments
// Test a procedure with calling convention stack
// Return value larger than parameter
  // Upstart
.pc = $801 "Basic"
:BasicUpstart(main)
.pc = $80d "Program"
  // Global Constants & labels
  .label SCREEN = $400
  .const SIZEOF_SIGNED_WORD = 2
  .const STACK_BASE = $103
  .label current = 2
  // @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 __0 = 2
    .label __1 = 4
    // next()
    // [5] callprepare next 
    // [5] callprepare next  -- _stackpushbyte_2 
    pha
    pha
    // [5] callprepare next 
    // [6] callexecute next  -- jsr 
    jsr next
    // [7] (signed word~) main::$0 ← callfinalize next 
    // [7] (signed word~) main::$0 ← callfinalize next  -- vwsz1=_stackpullsword_ 
    pla
    sta.z __0
    pla
    sta.z __0+1
    // SCREEN[0] = next()
    // [8] *((const signed word*) SCREEN) ← (signed word~) main::$0 -- _deref_pwsc1=vwsz1 
    lda.z __0
    sta SCREEN
    lda.z __0+1
    sta SCREEN+1
    // next()
    // [9] callprepare next 
    // [9] callprepare next  -- _stackpushbyte_2 
    pha
    pha
    // [9] callprepare next 
    // [10] callexecute next  -- jsr 
    jsr next
    // [11] (signed word~) main::$1 ← callfinalize next 
    // [11] (signed word~) main::$1 ← callfinalize next  -- vwsz1=_stackpullsword_ 
    pla
    sta.z __1
    pla
    sta.z __1+1
    // SCREEN[1] = next()
    // [12] *((const signed word*) SCREEN+(byte) 1*(const byte) SIZEOF_SIGNED_WORD) ← (signed word~) main::$1 -- _deref_pwsc1=vwsz1 
    lda.z __1
    sta SCREEN+1*SIZEOF_SIGNED_WORD
    lda.z __1+1
    sta SCREEN+1*SIZEOF_SIGNED_WORD+1
    // main::@return
    // }
    // [13] return 
    rts
}
  // next
next: {
    .const OFFSET_STACK_RETURN = 0
    .label return = 2
    // return current++;
    // [15] (signed word) next::return#0 ← (signed word) current#5
    // next::@return
    // }
    // [16] return (signed word) next::return#0
    // [16] return (signed word) next::return#0 -- _stackidxsword_vbuc1=vwsz1 
    tsx
    lda.z return
    sta STACK_BASE+OFFSET_STACK_RETURN,x
    lda.z return+1
    sta STACK_BASE+OFFSET_STACK_RETURN+1,x
    rts
}
  // File Data

