
CONTROL FLOW GRAPH SSA

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

void __start()
__start: scope:[__start]  from
  call main
  to:__start::@1
__start::@1: scope:[__start]  from __start
  to:__start::@return
__start::@return: scope:[__start]  from __start::@1
  return 
  to:@return

SYMBOL TABLE SSA
__constant const char MESSAGE[] = "hello brave new world!"
__constant char * const SCREEN = (char *)$400
void __start()
void main()
bool main::$0
bool main::$1
bool main::$2
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
char main::idx
char main::idx#0
char main::idx#1
char main::idx#2
char main::idx#3
char main::idx#4
char main::idx#5

Adding number conversion cast (unumber) 0 in main::$2 = 0 != MESSAGE[main::i#2]
Successful SSA optimization PassNAddNumberTypeConversions
Simplifying constant pointer cast (char *) 1024
Simplifying constant integer cast 0
Successful SSA optimization PassNCastSimplification
Finalized unsigned number type (char) 0
Successful SSA optimization PassNFinalizeNumberTypeConversions
Inversing boolean not [7] main::$1 = MESSAGE[main::i#3] != ' ' from [6] main::$0 = MESSAGE[main::i#3] == ' '
Successful SSA optimization Pass2UnaryNotSimplification
Alias main::i#2 = main::i#3 main::i#4 
Alias main::idx#2 = main::idx#3 main::idx#4 
Successful SSA optimization Pass2AliasElimination
Alias main::i#2 = main::i#5 
Successful SSA optimization Pass2AliasElimination
Simple Condition main::$2 [4] if(0!=MESSAGE[main::i#2]) goto main::@2
Simple Condition main::$1 [6] if(MESSAGE[main::i#2]!=' ') goto main::@3
Successful SSA optimization Pass2ConditionalJumpSimplification
Negating conditional jump and destination [6] if(MESSAGE[main::i#2]==' ') goto main::@4
Successful SSA optimization Pass2ConditionalJumpSequenceImprovement
Constant main::idx#0 = 0
Constant main::i#0 = 0
Successful SSA optimization Pass2ConstantIdentification
Removing unused procedure __start
Removing unused procedure block __start
Removing unused procedure block __start::@1
Removing unused procedure block __start::@return
Successful SSA optimization PassNEliminateEmptyStart
Inlining constant with var siblings main::idx#0
Inlining constant with var siblings main::i#0
Constant inlined main::i#0 = 0
Constant inlined main::idx#0 = 0
Successful SSA optimization Pass2ConstantInlining
Added new block during phi lifting main::@5(between main::@2 and main::@4)
Adding NOP phi() at start of main
CALL GRAPH

Created 3 initial phi equivalence classes
Coalesced [7] main::idx#8 = main::idx#1
Coalesced [10] main::i#6 = main::i#1
Coalesced [11] main::idx#6 = main::idx#5
Coalesced (already) [12] main::idx#7 = main::idx#2
Coalesced down to 2 phi equivalence classes
Culled Empty Block label main::@5
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::@4
  [1] main::idx#2 = phi( main/0, main::@4/main::idx#5 )
  [1] main::i#2 = phi( main/0, main::@4/main::i#1 )
  [2] if(0!=MESSAGE[main::i#2]) goto main::@2
  to:main::@return
main::@return: scope:[main]  from main::@1
  [3] return 
  to:@return
main::@2: scope:[main]  from main::@1
  [4] if(MESSAGE[main::i#2]==' ') goto main::@4
  to:main::@3
main::@3: scope:[main]  from main::@2
  [5] SCREEN[main::idx#2] = MESSAGE[main::i#2]
  [6] main::idx#1 = ++ main::idx#2
  to:main::@4
main::@4: scope:[main]  from main::@2 main::@3
  [7] main::idx#5 = phi( main::@2/main::idx#2, main::@3/main::idx#1 )
  [8] main::i#1 = ++ main::i#2
  to:main::@1


VARIABLE REGISTER WEIGHTS
void main()
char main::i
char main::i#1 // 22.0
char main::i#2 // 9.166666666666666
char main::idx
char main::idx#1 // 22.0
char main::idx#2 // 11.0
char main::idx#5 // 16.5

Initial phi equivalence classes
[ main::i#2 main::i#1 ]
[ main::idx#2 main::idx#5 main::idx#1 ]
Complete equivalence classes
[ main::i#2 main::i#1 ]
[ main::idx#2 main::idx#5 main::idx#1 ]
Allocated zp[1]:2 [ main::idx#2 main::idx#5 main::idx#1 ]
Allocated zp[1]:3 [ main::i#2 main::i#1 ]
REGISTER UPLIFT POTENTIAL REGISTERS
Statement [2] if(0!=MESSAGE[main::i#2]) goto main::@2 [ main::i#2 main::idx#2 ] (  [ main::i#2 main::idx#2 ] { }  ) always clobbers reg byte a 
Removing always clobbered register reg byte a as potential for zp[1]:3 [ main::i#2 main::i#1 ]
Removing always clobbered register reg byte a as potential for zp[1]:2 [ main::idx#2 main::idx#5 main::idx#1 ]
Statement [4] if(MESSAGE[main::i#2]==' ') goto main::@4 [ main::i#2 main::idx#2 ] (  [ main::i#2 main::idx#2 ] { }  ) always clobbers reg byte a 
Statement [5] SCREEN[main::idx#2] = MESSAGE[main::i#2] [ main::i#2 main::idx#2 ] (  [ main::i#2 main::idx#2 ] { }  ) always clobbers reg byte a 
Statement [2] if(0!=MESSAGE[main::i#2]) goto main::@2 [ main::i#2 main::idx#2 ] (  [ main::i#2 main::idx#2 ] { }  ) always clobbers reg byte a 
Statement [4] if(MESSAGE[main::i#2]==' ') goto main::@4 [ main::i#2 main::idx#2 ] (  [ main::i#2 main::idx#2 ] { }  ) always clobbers reg byte a 
Statement [5] SCREEN[main::idx#2] = MESSAGE[main::i#2] [ main::i#2 main::idx#2 ] (  [ main::i#2 main::idx#2 ] { }  ) always clobbers reg byte a 
Potential registers zp[1]:3 [ main::i#2 main::i#1 ] : zp[1]:3 , reg byte x , reg byte y , 
Potential registers zp[1]:2 [ main::idx#2 main::idx#5 main::idx#1 ] : zp[1]:2 , reg byte x , reg byte y , 

REGISTER UPLIFT SCOPES
Uplift Scope [main] 49.5: zp[1]:2 [ main::idx#2 main::idx#5 main::idx#1 ] 31.17: zp[1]:3 [ main::i#2 main::i#1 ] 
Uplift Scope [] 

Uplifting [main] best 511 combination reg byte y [ main::idx#2 main::idx#5 main::idx#1 ] reg byte x [ main::i#2 main::i#1 ] 
Uplifting [] best 511 combination 

ASSEMBLER BEFORE OPTIMIZATION
  // File Comments
// Tests continue statement in a simple for()-loop
  // Upstart
  // Commodore 64 PRG executable file
.file [name="loop-for-continue.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::idx#2 = 0 [phi:main->main::@1#0] -- vbuyy=vbuc1 
    ldy #0
    // [1] phi main::i#2 = 0 [phi:main->main::@1#1] -- vbuxx=vbuc1 
    ldx #0
    jmp __b1
    // main::@1
  __b1:
    // [2] if(0!=MESSAGE[main::i#2]) goto main::@2 -- 0_neq_pbuc1_derefidx_vbuxx_then_la1 
    lda MESSAGE,x
    cmp #0
    bne __b2
    jmp __breturn
    // main::@return
  __breturn:
    // [3] return 
    rts
    // main::@2
  __b2:
    // [4] if(MESSAGE[main::i#2]==' ') goto main::@4 -- pbuc1_derefidx_vbuxx_eq_vbuc2_then_la1 
    lda MESSAGE,x
    cmp #' '
    beq __b4_from___b2
    jmp __b3
    // main::@3
  __b3:
    // [5] SCREEN[main::idx#2] = MESSAGE[main::i#2] -- pbuc1_derefidx_vbuyy=pbuc2_derefidx_vbuxx 
    lda MESSAGE,x
    sta SCREEN,y
    // [6] main::idx#1 = ++ main::idx#2 -- vbuyy=_inc_vbuyy 
    iny
    // [7] phi from main::@2 main::@3 to main::@4 [phi:main::@2/main::@3->main::@4]
  __b4_from___b2:
  __b4_from___b3:
    // [7] phi main::idx#5 = main::idx#2 [phi:main::@2/main::@3->main::@4#0] -- register_copy 
    jmp __b4
    // main::@4
  __b4:
    // [8] main::i#1 = ++ main::i#2 -- vbuxx=_inc_vbuxx 
    inx
    // [1] phi from main::@4 to main::@1 [phi:main::@4->main::@1]
  __b1_from___b4:
    // [1] phi main::idx#2 = main::idx#5 [phi:main::@4->main::@1#0] -- register_copy 
    // [1] phi main::i#2 = main::i#1 [phi:main::@4->main::@1#1] -- register_copy 
    jmp __b1
}
  // File Data
.segment Data
  MESSAGE: .text "hello brave new world!"
  .byte 0

ASSEMBLER OPTIMIZATIONS
Removing instruction jmp __b1
Removing instruction jmp __breturn
Removing instruction jmp __b3
Removing instruction jmp __b4
Succesful ASM optimization Pass5NextJumpElimination
Replacing label __b4_from___b2 with __b4
Removing instruction __b4_from___b2:
Removing instruction __b4_from___b3:
Succesful ASM optimization Pass5RedundantLabelElimination
Removing instruction __b1_from_main:
Removing instruction __breturn:
Removing instruction __b3:
Removing instruction __b1_from___b4:
Succesful ASM optimization Pass5UnusedLabelElimination

FINAL SYMBOL TABLE
__constant const char MESSAGE[] = "hello brave new world!"
__constant char * const SCREEN = (char *) 1024
void main()
char main::i
char main::i#1 // reg byte x 22.0
char main::i#2 // reg byte x 9.166666666666666
char main::idx
char main::idx#1 // reg byte y 22.0
char main::idx#2 // reg byte y 11.0
char main::idx#5 // reg byte y 16.5

reg byte x [ main::i#2 main::i#1 ]
reg byte y [ main::idx#2 main::idx#5 main::idx#1 ]


FINAL ASSEMBLER
Score: 391

  // File Comments
// Tests continue statement in a simple for()-loop
  // Upstart
  // Commodore 64 PRG executable file
.file [name="loop-for-continue.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::idx#2 = 0 [phi:main->main::@1#0] -- vbuyy=vbuc1 
    ldy #0
    // [1] phi main::i#2 = 0 [phi:main->main::@1#1] -- vbuxx=vbuc1 
    ldx #0
    // main::@1
  __b1:
    // for( char i =0; MESSAGE[i]; i++)
    // [2] if(0!=MESSAGE[main::i#2]) goto main::@2 -- 0_neq_pbuc1_derefidx_vbuxx_then_la1 
    lda MESSAGE,x
    cmp #0
    bne __b2
    // main::@return
    // }
    // [3] return 
    rts
    // main::@2
  __b2:
    // if(MESSAGE[i]==' ')
    // [4] if(MESSAGE[main::i#2]==' ') goto main::@4 -- pbuc1_derefidx_vbuxx_eq_vbuc2_then_la1 
    lda MESSAGE,x
    cmp #' '
    beq __b4
    // main::@3
    // SCREEN[idx++] = MESSAGE[i]
    // [5] SCREEN[main::idx#2] = MESSAGE[main::i#2] -- pbuc1_derefidx_vbuyy=pbuc2_derefidx_vbuxx 
    lda MESSAGE,x
    sta SCREEN,y
    // SCREEN[idx++] = MESSAGE[i];
    // [6] main::idx#1 = ++ main::idx#2 -- vbuyy=_inc_vbuyy 
    iny
    // [7] phi from main::@2 main::@3 to main::@4 [phi:main::@2/main::@3->main::@4]
    // [7] phi main::idx#5 = main::idx#2 [phi:main::@2/main::@3->main::@4#0] -- register_copy 
    // main::@4
  __b4:
    // for( char i =0; MESSAGE[i]; i++)
    // [8] main::i#1 = ++ main::i#2 -- vbuxx=_inc_vbuxx 
    inx
    // [1] phi from main::@4 to main::@1 [phi:main::@4->main::@1]
    // [1] phi main::idx#2 = main::idx#5 [phi:main::@4->main::@1#0] -- register_copy 
    // [1] phi main::i#2 = main::i#1 [phi:main::@4->main::@1#1] -- register_copy 
    jmp __b1
}
  // File Data
.segment Data
  MESSAGE: .text "hello brave new world!"
  .byte 0

