Inlined call call __init

CONTROL FLOW GRAPH SSA

void main()
main: scope:[main]  from __start::@1
  main::i#0 = 3
  to:main::@1
main::@1: scope:[main]  from main main::@2
  main::i#2 = phi( main/main::i#0, main::@2/main::i#1 )
  main::$0 = main::i#2 < 7
  if(main::$0) goto main::@2
  to:main::@return
main::@2: scope:[main]  from main::@1
  main::i#3 = phi( main::@1/main::i#2 )
  SCREEN[main::i#3] = ch
  main::i#1 = ++ main::i#3
  to:main::@1
main::@return: scope:[main]  from main::@1
  return 
  to:@return

void __start()
__start: scope:[__start]  from
  to:__start::__init1
__start::__init1: scope:[__start]  from __start
  ch = 3
  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 char * const SCREEN = (char *)$400
void __start()
__loadstore volatile const char ch
void main()
bool main::$0
char main::i
char main::i#0
char main::i#1
char main::i#2
char main::i#3

Adding number conversion cast (unumber) 7 in main::$0 = main::i#2 < 7
Successful SSA optimization PassNAddNumberTypeConversions
Simplifying constant pointer cast (char *) 1024
Simplifying constant integer cast 7
Successful SSA optimization PassNCastSimplification
Finalized unsigned number type (char) 7
Successful SSA optimization PassNFinalizeNumberTypeConversions
Alias main::i#2 = main::i#3 
Successful SSA optimization Pass2AliasElimination
Simple Condition main::$0 [3] if(main::i#2<7) goto main::@2
Successful SSA optimization Pass2ConditionalJumpSimplification
Constant main::i#0 = 3
Successful SSA optimization Pass2ConstantIdentification
Inlining constant with var siblings main::i#0
Constant inlined main::i#0 = 3
Successful SSA optimization Pass2ConstantInlining
Adding NOP phi() at start of __start
Adding NOP phi() at start of __start::@1
Adding NOP phi() at start of __start::@2
Adding NOP phi() at start of main
CALL GRAPH
Calls in [__start] to main:3 

Created 1 initial phi equivalence classes
Coalesced [12] main::i#4 = main::i#1
Coalesced down to 1 phi equivalence classes
Culled Empty Block label __start::@2
Adding NOP phi() at start of __start
Adding NOP phi() at start of __start::@1
Adding NOP phi() at start of main

FINAL CONTROL FLOW GRAPH

void __start()
__start: scope:[__start]  from
  [0] phi()
  to:__start::__init1
__start::__init1: scope:[__start]  from __start
  [1] ch = 3
  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

void main()
main: scope:[main]  from __start::@1
  [5] phi()
  to:main::@1
main::@1: scope:[main]  from main main::@2
  [6] main::i#2 = phi( main/3, main::@2/main::i#1 )
  [7] if(main::i#2<7) goto main::@2
  to:main::@return
main::@return: scope:[main]  from main::@1
  [8] return 
  to:@return
main::@2: scope:[main]  from main::@1
  [9] SCREEN[main::i#2] = ch
  [10] main::i#1 = ++ main::i#2
  to:main::@1


VARIABLE REGISTER WEIGHTS
void __start()
__loadstore volatile const char ch // 14.714285714285715
void main()
char main::i
char main::i#1 // 202.0
char main::i#2 // 134.66666666666666

Initial phi equivalence classes
[ main::i#2 main::i#1 ]
Added variable ch to live range equivalence class [ ch ]
Complete equivalence classes
[ main::i#2 main::i#1 ]
[ ch ]
Allocated zp[1]:2 [ main::i#2 main::i#1 ]
Allocated zp[1]:3 [ ch ]
REGISTER UPLIFT POTENTIAL REGISTERS
Statement [1] ch = 3 [ ch ] (  [ ch ] { }  ) always clobbers reg byte a 
Statement [9] SCREEN[main::i#2] = ch [ ch main::i#2 ] ( main:3 [ ch main::i#2 ] { }  ) always clobbers reg byte a 
Removing always clobbered register reg byte a as potential for zp[1]:2 [ main::i#2 main::i#1 ]
Statement [1] ch = 3 [ ch ] (  [ ch ] { }  ) always clobbers reg byte a 
Statement [9] SCREEN[main::i#2] = ch [ ch main::i#2 ] ( main:3 [ ch main::i#2 ] { }  ) always clobbers reg byte a 
Potential registers zp[1]:2 [ main::i#2 main::i#1 ] : zp[1]:2 , reg byte x , reg byte y , 
Potential registers zp[1]:3 [ ch ] : zp[1]:3 , 

REGISTER UPLIFT SCOPES
Uplift Scope [main] 336.67: zp[1]:2 [ main::i#2 main::i#1 ] 
Uplift Scope [] 14.71: zp[1]:3 [ ch ] 
Uplift Scope [__start] 

Uplifting [main] best 314 combination reg byte x [ main::i#2 main::i#1 ] 
Uplifting [] best 314 combination zp[1]:3 [ ch ] 
Uplifting [__start] best 314 combination 
Attempting to uplift remaining variables inzp[1]:3 [ ch ]
Uplifting [] best 314 combination zp[1]:3 [ ch ] 
Allocated (was zp[1]:3) zp[1]:2 [ ch ]

ASSEMBLER BEFORE OPTIMIZATION
  // File Comments
// Test that volatile const vars are turned into load/store
  // Upstart
  // Commodore 64 PRG executable file
.file [name="volatile-2.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
  .label SCREEN = $400
  .label ch = 2
.segment Code
  // __start
__start: {
    jmp __init1
    // __start::__init1
  __init1:
    // [1] ch = 3 -- vbuz1=vbuc1 
    lda #3
    sta.z ch
    // [2] phi from __start::__init1 to __start::@1 [phi:__start::__init1->__start::@1]
  __b1_from___init1:
    jmp __b1
    // __start::@1
  __b1:
    // [3] call main
    // [5] phi from __start::@1 to main [phi:__start::@1->main]
  main_from___b1:
    jsr main
    jmp __breturn
    // __start::@return
  __breturn:
    // [4] return 
    rts
}
  // main
main: {
    // [6] phi from main to main::@1 [phi:main->main::@1]
  __b1_from_main:
    // [6] phi main::i#2 = 3 [phi:main->main::@1#0] -- vbuxx=vbuc1 
    ldx #3
    jmp __b1
    // main::@1
  __b1:
    // [7] if(main::i#2<7) goto main::@2 -- vbuxx_lt_vbuc1_then_la1 
    cpx #7
    bcc __b2
    jmp __breturn
    // main::@return
  __breturn:
    // [8] return 
    rts
    // main::@2
  __b2:
    // [9] SCREEN[main::i#2] = ch -- pbuc1_derefidx_vbuxx=vbuz1 
    lda.z ch
    sta SCREEN,x
    // [10] main::i#1 = ++ main::i#2 -- vbuxx=_inc_vbuxx 
    inx
    // [6] phi from main::@2 to main::@1 [phi:main::@2->main::@1]
  __b1_from___b2:
    // [6] phi main::i#2 = main::i#1 [phi:main::@2->main::@1#0] -- register_copy 
    jmp __b1
}
  // File Data

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

FINAL SYMBOL TABLE
__constant char * const SCREEN = (char *) 1024
void __start()
__loadstore volatile const char ch // zp[1]:2 14.714285714285715
void main()
char main::i
char main::i#1 // reg byte x 202.0
char main::i#2 // reg byte x 134.66666666666666

reg byte x [ main::i#2 main::i#1 ]
zp[1]:2 [ ch ]


FINAL ASSEMBLER
Score: 218

  // File Comments
// Test that volatile const vars are turned into load/store
  // Upstart
  // Commodore 64 PRG executable file
.file [name="volatile-2.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
  .label SCREEN = $400
  .label ch = 2
.segment Code
  // __start
__start: {
    // __start::__init1
    // const volatile char ch = 3
    // [1] ch = 3 -- vbuz1=vbuc1 
    lda #3
    sta.z ch
    // [2] phi from __start::__init1 to __start::@1 [phi:__start::__init1->__start::@1]
    // __start::@1
    // [3] call main
    // [5] phi from __start::@1 to main [phi:__start::@1->main]
    jsr main
    // __start::@return
    // [4] return 
    rts
}
  // main
main: {
    // [6] phi from main to main::@1 [phi:main->main::@1]
    // [6] phi main::i#2 = 3 [phi:main->main::@1#0] -- vbuxx=vbuc1 
    ldx #3
    // main::@1
  __b1:
    // while(i<7)
    // [7] if(main::i#2<7) goto main::@2 -- vbuxx_lt_vbuc1_then_la1 
    cpx #7
    bcc __b2
    // main::@return
    // }
    // [8] return 
    rts
    // main::@2
  __b2:
    // SCREEN[i++] = ch
    // [9] SCREEN[main::i#2] = ch -- pbuc1_derefidx_vbuxx=vbuz1 
    lda.z ch
    sta SCREEN,x
    // SCREEN[i++] = ch;
    // [10] main::i#1 = ++ main::i#2 -- vbuxx=_inc_vbuxx 
    inx
    // [6] phi from main::@2 to main::@1 [phi:main::@2->main::@1]
    // [6] phi main::i#2 = main::i#1 [phi:main::@2->main::@1#0] -- register_copy 
    jmp __b1
}
  // File Data

