Inlined call call __init

CONTROL FLOW GRAPH SSA

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

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

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

Created 1 initial phi equivalence classes
Not coalescing [7] main::i#6 = main::i#2
Coalesced down to 2 phi equivalence classes
Adding NOP phi() at start of main

FINAL CONTROL FLOW GRAPH

void main()
main: scope:[main]  from
  [0] phi()
  to:main::@1
main::@1: scope:[main]  from main main::@2
  [1] main::i#3 = phi( main/7, main::@2/main::i#6 )
  [2] main::i#2 = ++ main::i#3
  [3] if(main::i#3<7) goto main::@2
  to:main::@3
main::@3: scope:[main]  from main::@1
  [4] SCREEN[main::i#2] = 'x'
  to:main::@return
main::@return: scope:[main]  from main::@3
  [5] return 
  to:@return
main::@2: scope:[main]  from main::@1
  [6] SCREEN[main::i#2] = main::i#2
  [7] main::i#6 = main::i#2
  to:main::@1


VARIABLE REGISTER WEIGHTS
void main()
char main::i
char main::i#2 // 15.333333333333332
char main::i#3 // 16.5
char main::i#6 // 22.0

Initial phi equivalence classes
[ main::i#3 main::i#6 ]
Added variable main::i#2 to live range equivalence class [ main::i#2 ]
Complete equivalence classes
[ main::i#3 main::i#6 ]
[ main::i#2 ]
Allocated zp[1]:2 [ main::i#3 main::i#6 ]
Allocated zp[1]:3 [ main::i#2 ]
REGISTER UPLIFT POTENTIAL REGISTERS
Statement [4] SCREEN[main::i#2] = 'x' [ ] (  [ ] { }  ) always clobbers reg byte a 
Potential registers zp[1]:2 [ main::i#3 main::i#6 ] : zp[1]:2 , reg byte a , reg byte x , reg byte y , 
Potential registers zp[1]:3 [ main::i#2 ] : zp[1]:3 , reg byte a , reg byte x , reg byte y , 

REGISTER UPLIFT SCOPES
Uplift Scope [main] 38.5: zp[1]:2 [ main::i#3 main::i#6 ] 15.33: zp[1]:3 [ main::i#2 ] 
Uplift Scope [] 

Uplifting [main] best 301 combination reg byte a [ main::i#3 main::i#6 ] reg byte x [ main::i#2 ] 
Uplifting [] best 301 combination 

ASSEMBLER BEFORE OPTIMIZATION
  // File Comments
// Test a for()-loop where the condition has a side-effect
// Currently not standard C compliant (since the condition is not evaluated before the body)
  // Upstart
  // Commodore 64 PRG executable file
.file [name="loop-for-sideeffect.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(main)
  // Global Constants & labels
  .label SCREEN = $400
.segment Code
  // main
main: {
    // [1] phi from main to main::@1 [phi:main->main::@1]
  __b1_from_main:
    // [1] phi main::i#3 = 7 [phi:main->main::@1#0] -- vbuaa=vbuc1 
    lda #7
    jmp __b1
    // main::@1
  __b1:
    // [2] main::i#2 = ++ main::i#3 -- vbuxx=_inc_vbuaa 
    tax
    inx
    // [3] if(main::i#3<7) goto main::@2 -- vbuaa_lt_vbuc1_then_la1 
    cmp #7
    bcc __b2
    jmp __b3
    // main::@3
  __b3:
    // [4] SCREEN[main::i#2] = 'x' -- pbuc1_derefidx_vbuxx=vbuc2 
    // The condition-evaluation should increment i - even if when it is not met - x should end up in 0x0408
    lda #'x'
    sta SCREEN,x
    jmp __breturn
    // main::@return
  __breturn:
    // [5] return 
    rts
    // main::@2
  __b2:
    // [6] SCREEN[main::i#2] = main::i#2 -- pbuc1_derefidx_vbuxx=vbuxx 
    txa
    sta SCREEN,x
    // [7] main::i#6 = main::i#2 -- vbuaa=vbuxx 
    txa
    // [1] phi from main::@2 to main::@1 [phi:main::@2->main::@1]
  __b1_from___b2:
    // [1] phi main::i#3 = main::i#6 [phi:main::@2->main::@1#0] -- register_copy 
    jmp __b1
}
  // File Data

ASSEMBLER OPTIMIZATIONS
Removing instruction jmp __b1
Removing instruction jmp __b3
Removing instruction jmp __breturn
Succesful ASM optimization Pass5NextJumpElimination
Removing instruction __b1_from_main:
Removing instruction __b3:
Removing instruction __breturn:
Removing instruction __b1_from___b2:
Succesful ASM optimization Pass5UnusedLabelElimination

FINAL SYMBOL TABLE
__constant char *SCREEN = (char *) 1024
void main()
char main::i
char main::i#2 // reg byte x 15.333333333333332
char main::i#3 // reg byte a 16.5
char main::i#6 // reg byte a 22.0

reg byte a [ main::i#3 main::i#6 ]
reg byte x [ main::i#2 ]


FINAL ASSEMBLER
Score: 238

  // File Comments
// Test a for()-loop where the condition has a side-effect
// Currently not standard C compliant (since the condition is not evaluated before the body)
  // Upstart
  // Commodore 64 PRG executable file
.file [name="loop-for-sideeffect.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(main)
  // Global Constants & labels
  .label SCREEN = $400
.segment Code
  // main
main: {
    // [1] phi from main to main::@1 [phi:main->main::@1]
    // [1] phi main::i#3 = 7 [phi:main->main::@1#0] -- vbuaa=vbuc1 
    lda #7
    // main::@1
  __b1:
    // for(i=7;i++<7;)
    // [2] main::i#2 = ++ main::i#3 -- vbuxx=_inc_vbuaa 
    tax
    inx
    // [3] if(main::i#3<7) goto main::@2 -- vbuaa_lt_vbuc1_then_la1 
    cmp #7
    bcc __b2
    // main::@3
    // (SCREEN)[i] = 'x'
    // [4] SCREEN[main::i#2] = 'x' -- pbuc1_derefidx_vbuxx=vbuc2 
    // The condition-evaluation should increment i - even if when it is not met - x should end up in 0x0408
    lda #'x'
    sta SCREEN,x
    // main::@return
    // }
    // [5] return 
    rts
    // main::@2
  __b2:
    // SCREEN[i] = i
    // [6] SCREEN[main::i#2] = main::i#2 -- pbuc1_derefidx_vbuxx=vbuxx 
    txa
    sta SCREEN,x
    // [7] main::i#6 = main::i#2 -- vbuaa=vbuxx 
    txa
    // [1] phi from main::@2 to main::@1 [phi:main::@2->main::@1]
    // [1] phi main::i#3 = main::i#6 [phi:main::@2->main::@1#0] -- register_copy 
    jmp __b1
}
  // File Data

