Converting variable modified inside __stackcall procedure next() to load/store current
Inlined call call __init
Calling convention __stackcall adding prepare/execute/finalize for main::$0 = call next
Calling convention __stackcall adding prepare/execute/finalize for main::$1 = call next
Calling convention STACK_CALL adding stack return stackidx(int,next::OFFSET_STACK_RETURN_0) = next::return
Calling convention STACK_CALL adding stack pull main::$0 = stackpull(int)
Calling convention STACK_CALL adding stack pull main::$1 = stackpull(int)

CONTROL FLOW GRAPH SSA

void main()
main: scope:[main]  from __start::@1
  sideeffect stackpushbytes(2)
  callexecute next 
  main::$0 = stackpull(int)
  main::$2 = 0 * SIZEOF_INT
  SCREEN[main::$2] = main::$0
  sideeffect stackpushbytes(2)
  callexecute next 
  main::$1 = stackpull(int)
  main::$3 = 1 * SIZEOF_INT
  SCREEN[main::$3] = main::$1
  to:main::@return
main::@return: scope:[main]  from main
  return 
  to:@return

__stackcall int next()
next: scope:[next]  from
  next::return#0 = current
  current = ++ current
  to:next::@return
next::@return: scope:[next]  from next
  next::return#1 = phi( next/next::return#0 )
  stackidx(int,next::OFFSET_STACK_RETURN_0) = next::return#1
  return 
  to:@return

void __start()
__start: scope:[__start]  from
  to:__start::__init1
__start::__init1: scope:[__start]  from __start
  current = $30
  to:__start::@1
__start::@1: scope:[__start]  from __start::__init1
  call main
  to:__start::@2
__start::@2: scope:[__start]  from __start::@1
  to:__start::@return
__start::@return: scope:[__start]  from __start::@2
  return 
  to:@return

SYMBOL TABLE SSA
__constant int * const SCREEN = (int *)$400
__constant char SIZEOF_INT = 2
__constant unsigned int STACK_BASE = $103
void __start()
__loadstore int current
void main()
int main::$0
int main::$1
number main::$2
number main::$3
__stackcall int next()
__constant char next::OFFSET_STACK_RETURN_0 = 0
int next::return
int next::return#0
int next::return#1

Adding number conversion cast (unumber) 0 in main::$2 = 0 * SIZEOF_INT
Adding number conversion cast (unumber) main::$2 in main::$2 = (unumber)0 * SIZEOF_INT
Adding number conversion cast (unumber) 1 in main::$3 = 1 * SIZEOF_INT
Adding number conversion cast (unumber) main::$3 in main::$3 = (unumber)1 * SIZEOF_INT
Successful SSA optimization PassNAddNumberTypeConversions
Simplifying constant pointer cast (int *) 1024
Simplifying constant integer cast 0
Simplifying constant integer cast 1
Successful SSA optimization PassNCastSimplification
Finalized unsigned number type (char) 0
Finalized unsigned number type (char) 1
Successful SSA optimization PassNFinalizeNumberTypeConversions
Inferred type updated to char in main::$2 = 0 * SIZEOF_INT
Inferred type updated to char in main::$3 = 1 * SIZEOF_INT
Alias next::return#0 = next::return#1 
Successful SSA optimization Pass2AliasElimination
Constant right-side identified [3] main::$2 = 0 * SIZEOF_INT
Constant right-side identified [8] main::$3 = 1 * SIZEOF_INT
Successful SSA optimization Pass2ConstantRValueConsolidation
Constant main::$2 = 0*SIZEOF_INT
Constant main::$3 = 1*SIZEOF_INT
Successful SSA optimization Pass2ConstantIdentification
Simplifying constant evaluating to zero 0*SIZEOF_INT in 
Successful SSA optimization PassNSimplifyConstantZero
Simplifying expression containing zero SCREEN in [4] SCREEN[main::$2] = main::$0
Successful SSA optimization PassNSimplifyExpressionWithZero
Eliminating unused constant main::$2
Successful SSA optimization PassNEliminateUnusedVars
Constant inlined main::$3 = 1*SIZEOF_INT
Successful SSA optimization Pass2ConstantInlining
Consolidated array index constant in *(SCREEN+1*SIZEOF_INT)
Successful SSA optimization Pass2ConstantAdditionElimination
Finalized unsigned number type (char) 2
Finalized unsigned number type (char) 2
Successful SSA optimization PassNFinalizeNumberTypeConversions
Adding NOP phi() at start of __start
Adding NOP phi() at start of __start::@1
Adding NOP phi() at start of __start::@2
CALL GRAPH
Calls in [__start] to main:3 
Calls in [main] to next:11 next:15 

Created 0 initial phi equivalence classes
Coalesced down to 0 phi equivalence classes
Culled Empty Block label __start::@2
Adding NOP phi() at start of __start
Adding NOP phi() at start of __start::@1

FINAL CONTROL FLOW GRAPH

void __start()
__start: scope:[__start]  from
  [0] phi()
  to:__start::__init1
__start::__init1: scope:[__start]  from __start
  [1] current = $30
  to:__start::@1
__start::@1: scope:[__start]  from __start::__init1
  [2] phi()
  [3] call main
  to:__start::@return
__start::@return: scope:[__start]  from __start::@1
  [4] return 
  to:@return

__stackcall int next()
next: scope:[next]  from
  [5] next::return#0 = current
  [6] current = ++ current
  to:next::@return
next::@return: scope:[next]  from next
  [7] stackidx(int,next::OFFSET_STACK_RETURN_0) = next::return#0
  [8] return 
  to:@return

void main()
main: scope:[main]  from __start::@1
  sideeffect stackpushbytes(2)
  [10] callexecute next 
  [11] main::$0 = stackpull(int)
  [12] *SCREEN = main::$0
  sideeffect stackpushbytes(2)
  [14] callexecute next 
  [15] main::$1 = stackpull(int)
  [16] *(SCREEN+1*SIZEOF_INT) = main::$1
  to:main::@return
main::@return: scope:[main]  from main
  [17] return 
  to:@return


VARIABLE REGISTER WEIGHTS
void __start()
__loadstore int current // 27.727272727272727
void main()
int main::$0 // 22.0
int main::$1 // 22.0
__stackcall int next()
int next::return
int next::return#0 // 101.0

Initial phi equivalence classes
Added variable current to live range equivalence class [ current ]
Added variable next::return#0 to live range equivalence class [ next::return#0 ]
Added variable main::$0 to live range equivalence class [ main::$0 ]
Added variable main::$1 to live range equivalence class [ main::$1 ]
Complete equivalence classes
[ current ]
[ next::return#0 ]
[ main::$0 ]
[ main::$1 ]
Allocated zp[2]:2 [ next::return#0 ]
Allocated zp[2]:4 [ current ]
Allocated zp[2]:6 [ main::$0 ]
Allocated zp[2]:8 [ main::$1 ]
REGISTER UPLIFT POTENTIAL REGISTERS
Statement [1] current = $30 [ current ] (  [ current ] { }  ) always clobbers reg byte a 
Statement [5] next::return#0 = current [ current next::return#0 ] ( main:3::next:10 [ current next::return#0 ] { }  main:3::next:14 [ current next::return#0 ] { }  ) always clobbers reg byte a 
Statement [7] stackidx(int,next::OFFSET_STACK_RETURN_0) = next::return#0 [ current ] ( main:3::next:10 [ current ] { }  main:3::next:14 [ current ] { }  ) always clobbers reg byte a reg byte x 
Statement [11] main::$0 = stackpull(int) [ current main::$0 ] ( main:3 [ current main::$0 ] { }  ) always clobbers reg byte a 
Statement [12] *SCREEN = main::$0 [ current ] ( main:3 [ current ] { }  ) always clobbers reg byte a 
Statement [15] main::$1 = stackpull(int) [ main::$1 ] ( main:3 [ main::$1 ] { }  ) always clobbers reg byte a 
Statement [16] *(SCREEN+1*SIZEOF_INT) = main::$1 [ ] ( main:3 [ ] { }  ) always clobbers reg byte a 
Potential registers zp[2]:4 [ current ] : zp[2]:4 , 
Potential registers zp[2]:2 [ next::return#0 ] : zp[2]:2 , 
Potential registers zp[2]:6 [ main::$0 ] : zp[2]:6 , 
Potential registers zp[2]:8 [ main::$1 ] : zp[2]:8 , 

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

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

ASSEMBLER BEFORE OPTIMIZATION
  // File Comments
// Test a procedure with calling convention stack
// Return value larger than parameter
  // Upstart
  // Commodore 64 PRG executable file
.file [name="procedure-callingconvention-stack-5.prg", type="prg", segments="Program"]
.segmentdef Program [segments="Basic, Code, Data"]
.segmentdef Basic [start=$0801]
.segmentdef Code [start=$80d]
.segmentdef Data [startAfter="Code"]
.segment Basic
:BasicUpstart(__start)
  // Global Constants & labels
  .const SIZEOF_INT = 2
  .const STACK_BASE = $103
  .label SCREEN = $400
  .label current = 4
.segment Code
  // __start
__start: {
    jmp __init1
    // __start::__init1
  __init1:
    // [1] current = $30 -- vwsz1=vwsc1 
    lda #<$30
    sta.z current
    lda #>$30
    sta.z current+1
    // [2] phi from __start::__init1 to __start::@1 [phi:__start::__init1->__start::@1]
  __b1_from___init1:
    jmp __b1
    // __start::@1
  __b1:
    // [3] call main
    jsr main
    jmp __breturn
    // __start::@return
  __breturn:
    // [4] return 
    rts
}
  // next
next: {
    .const OFFSET_STACK_RETURN_0 = 0
    .label return = 2
    // [5] next::return#0 = current -- vwsz1=vwsz2 
    lda.z current
    sta.z return
    lda.z current+1
    sta.z return+1
    // [6] current = ++ current -- vwsz1=_inc_vwsz1 
    inc.z current
    bne !+
    inc.z current+1
  !:
    jmp __breturn
    // next::@return
  __breturn:
    // [7] stackidx(int,next::OFFSET_STACK_RETURN_0) = next::return#0 -- _stackidxsword_vbuc1=vwsz1 
    tsx
    lda.z return
    sta STACK_BASE+OFFSET_STACK_RETURN_0,x
    lda.z return+1
    sta STACK_BASE+OFFSET_STACK_RETURN_0+1,x
    // [8] return 
    rts
}
  // main
main: {
    .label __0 = 2
    .label __1 = 4
    // sideeffect stackpushbytes(2) -- _stackpushbyte_2 
    pha
    pha
    // [10] callexecute next  -- call_vprc1 
    jsr next
    // [11] main::$0 = stackpull(int) -- vwsz1=_stackpullsword_ 
    pla
    sta.z __0
    pla
    sta.z __0+1
    // [12] *SCREEN = main::$0 -- _deref_pwsc1=vwsz1 
    lda.z __0
    sta SCREEN
    lda.z __0+1
    sta SCREEN+1
    // sideeffect stackpushbytes(2) -- _stackpushbyte_2 
    pha
    pha
    // [14] callexecute next  -- call_vprc1 
    jsr next
    // [15] main::$1 = stackpull(int) -- vwsz1=_stackpullsword_ 
    pla
    sta.z __1
    pla
    sta.z __1+1
    // [16] *(SCREEN+1*SIZEOF_INT) = main::$1 -- _deref_pwsc1=vwsz1 
    lda.z __1
    sta SCREEN+1*SIZEOF_INT
    lda.z __1+1
    sta SCREEN+1*SIZEOF_INT+1
    jmp __breturn
    // main::@return
  __breturn:
    // [17] return 
    rts
}
  // File Data

ASSEMBLER OPTIMIZATIONS
Removing instruction jmp __init1
Removing instruction jmp __b1
Removing instruction jmp __breturn
Removing instruction jmp __breturn
Removing instruction jmp __breturn
Succesful ASM optimization Pass5NextJumpElimination
Removing instruction __b1_from___init1:
Succesful ASM optimization Pass5RedundantLabelElimination
Removing instruction __init1:
Removing instruction __b1:
Removing instruction __breturn:
Removing instruction __breturn:
Removing instruction __breturn:
Succesful ASM optimization Pass5UnusedLabelElimination

FINAL SYMBOL TABLE
__constant int * const SCREEN = (int *) 1024
__constant char SIZEOF_INT = 2
__constant unsigned int STACK_BASE = $103
void __start()
__loadstore int current // zp[2]:4 27.727272727272727
void main()
int main::$0 // zp[2]:2 22.0
int main::$1 // zp[2]:4 22.0
__stackcall int next()
__constant char next::OFFSET_STACK_RETURN_0 = 0
int next::return
int next::return#0 // return zp[2]:2 101.0

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


FINAL ASSEMBLER
Score: 156

  // File Comments
// Test a procedure with calling convention stack
// Return value larger than parameter
  // Upstart
  // Commodore 64 PRG executable file
.file [name="procedure-callingconvention-stack-5.prg", type="prg", segments="Program"]
.segmentdef Program [segments="Basic, Code, Data"]
.segmentdef Basic [start=$0801]
.segmentdef Code [start=$80d]
.segmentdef Data [startAfter="Code"]
.segment Basic
:BasicUpstart(__start)
  // Global Constants & labels
  .const SIZEOF_INT = 2
  .const STACK_BASE = $103
  .label SCREEN = $400
  .label current = 4
.segment Code
  // __start
__start: {
    // __start::__init1
    // int  current = 48
    // [1] current = $30 -- vwsz1=vwsc1 
    lda #<$30
    sta.z current
    lda #>$30
    sta.z current+1
    // [2] phi from __start::__init1 to __start::@1 [phi:__start::__init1->__start::@1]
    // __start::@1
    // [3] call main
    jsr main
    // __start::@return
    // [4] return 
    rts
}
  // next
next: {
    .const OFFSET_STACK_RETURN_0 = 0
    .label return = 2
    // return current++;
    // [5] next::return#0 = current -- vwsz1=vwsz2 
    lda.z current
    sta.z return
    lda.z current+1
    sta.z return+1
    // [6] current = ++ current -- vwsz1=_inc_vwsz1 
    inc.z current
    bne !+
    inc.z current+1
  !:
    // next::@return
    // }
    // [7] stackidx(int,next::OFFSET_STACK_RETURN_0) = next::return#0 -- _stackidxsword_vbuc1=vwsz1 
    tsx
    lda.z return
    sta STACK_BASE+OFFSET_STACK_RETURN_0,x
    lda.z return+1
    sta STACK_BASE+OFFSET_STACK_RETURN_0+1,x
    // [8] return 
    rts
}
  // main
main: {
    .label __0 = 2
    .label __1 = 4
    // next()
    // sideeffect stackpushbytes(2) -- _stackpushbyte_2 
    pha
    pha
    // [10] callexecute next  -- call_vprc1 
    jsr next
    // [11] main::$0 = stackpull(int) -- vwsz1=_stackpullsword_ 
    pla
    sta.z __0
    pla
    sta.z __0+1
    // SCREEN[0] = next()
    // [12] *SCREEN = main::$0 -- _deref_pwsc1=vwsz1 
    lda.z __0
    sta SCREEN
    lda.z __0+1
    sta SCREEN+1
    // next()
    // sideeffect stackpushbytes(2) -- _stackpushbyte_2 
    pha
    pha
    // [14] callexecute next  -- call_vprc1 
    jsr next
    // [15] main::$1 = stackpull(int) -- vwsz1=_stackpullsword_ 
    pla
    sta.z __1
    pla
    sta.z __1+1
    // SCREEN[1] = next()
    // [16] *(SCREEN+1*SIZEOF_INT) = main::$1 -- _deref_pwsc1=vwsz1 
    lda.z __1
    sta SCREEN+1*SIZEOF_INT
    lda.z __1+1
    sta SCREEN+1*SIZEOF_INT+1
    // main::@return
    // }
    // [17] return 
    rts
}
  // File Data

