
CONTROL FLOW GRAPH SSA

void main()
main: scope:[main]  from __start
  main::b#0 = 0
  to:main::@1
main::@1: scope:[main]  from main main::@2
  main::b#2 = phi( main/main::b#0, main::@2/main::b#1 )
  main::$1 = str[main::b#2] != 0
  if(main::$1) goto main::@2
  to:main::@3
main::@2: scope:[main]  from main::@1
  main::b#3 = phi( main::@1/main::b#2 )
  main::b#1 = ++ main::b#3
  to:main::@1
main::@3: scope:[main]  from main::@1
  main::b#4 = phi( main::@1/main::b#2 )
  main::$0 = '0' + main::b#4
  SCREEN[0] = main::$0
  to:main::@return
main::@return: scope:[main]  from main::@3
  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 char * const SCREEN = (char *)$400
void __start()
void main()
char main::$0
bool main::$1
char main::b
char main::b#0
char main::b#1
char main::b#2
char main::b#3
char main::b#4
__constant char str[] = "Hello!"

Adding number conversion cast (unumber) 0 in main::$1 = str[main::b#2] != 0
Adding number conversion cast (unumber) 0 in SCREEN[0] = main::$0
Successful SSA optimization PassNAddNumberTypeConversions
Simplifying constant pointer cast (char *) 1024
Simplifying constant integer cast 0
Simplifying constant integer cast 0
Successful SSA optimization PassNCastSimplification
Finalized unsigned number type (char) 0
Finalized unsigned number type (char) 0
Successful SSA optimization PassNFinalizeNumberTypeConversions
Alias main::b#2 = main::b#3 main::b#4 
Successful SSA optimization Pass2AliasElimination
Simple Condition main::$1 [3] if(str[main::b#2]!=0) goto main::@2
Successful SSA optimization Pass2ConditionalJumpSimplification
Constant main::b#0 = 0
Successful SSA optimization Pass2ConstantIdentification
Simplifying expression containing zero SCREEN in [6] SCREEN[0] = main::$0
Successful SSA optimization PassNSimplifyExpressionWithZero
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::b#0
Constant inlined main::b#0 = 0
Successful SSA optimization Pass2ConstantInlining
Adding NOP phi() at start of main
CALL GRAPH

Created 1 initial phi equivalence classes
Coalesced [7] main::b#5 = main::b#1
Coalesced down to 1 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::b#2 = phi( main/0, main::@2/main::b#1 )
  [2] if(str[main::b#2]!=0) goto main::@2
  to:main::@3
main::@3: scope:[main]  from main::@1
  [3] main::$0 = '0' + main::b#2
  [4] *SCREEN = main::$0
  to:main::@return
main::@return: scope:[main]  from main::@3
  [5] return 
  to:@return
main::@2: scope:[main]  from main::@1
  [6] main::b#1 = ++ main::b#2
  to:main::@1


VARIABLE REGISTER WEIGHTS
void main()
char main::$0 // 4.0
char main::b
char main::b#1 // 22.0
char main::b#2 // 17.5

Initial phi equivalence classes
[ main::b#2 main::b#1 ]
Added variable main::$0 to live range equivalence class [ main::$0 ]
Complete equivalence classes
[ main::b#2 main::b#1 ]
[ main::$0 ]
Allocated zp[1]:2 [ main::b#2 main::b#1 ]
Allocated zp[1]:3 [ main::$0 ]
REGISTER UPLIFT POTENTIAL REGISTERS
Statement [2] if(str[main::b#2]!=0) goto main::@2 [ main::b#2 ] (  [ main::b#2 ] { }  ) always clobbers reg byte a 
Removing always clobbered register reg byte a as potential for zp[1]:2 [ main::b#2 main::b#1 ]
Statement [3] main::$0 = '0' + main::b#2 [ main::$0 ] (  [ main::$0 ] { }  ) always clobbers reg byte a 
Statement [2] if(str[main::b#2]!=0) goto main::@2 [ main::b#2 ] (  [ main::b#2 ] { }  ) always clobbers reg byte a 
Statement [3] main::$0 = '0' + main::b#2 [ main::$0 ] (  [ main::$0 ] { }  ) always clobbers reg byte a 
Potential registers zp[1]:2 [ main::b#2 main::b#1 ] : zp[1]:2 , reg byte x , reg byte y , 
Potential registers zp[1]:3 [ main::$0 ] : zp[1]:3 , reg byte a , reg byte x , reg byte y , 

REGISTER UPLIFT SCOPES
Uplift Scope [main] 39.5: zp[1]:2 [ main::b#2 main::b#1 ] 4: zp[1]:3 [ main::$0 ] 
Uplift Scope [] 

Uplifting [main] best 237 combination reg byte x [ main::b#2 main::b#1 ] reg byte x [ main::$0 ] 
Uplifting [] best 237 combination 

ASSEMBLER BEFORE OPTIMIZATION
  // File Comments
// Test an empty statement ';'
  // Upstart
  // Commodore 64 PRG executable file
.file [name="stmt-empty-1.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::b#2 = 0 [phi:main->main::@1#0] -- vbuxx=vbuc1 
    ldx #0
    jmp __b1
    // main::@1
  __b1:
    // [2] if(str[main::b#2]!=0) goto main::@2 -- pbuc1_derefidx_vbuxx_neq_0_then_la1 
    lda str,x
    cmp #0
    bne __b2
    jmp __b3
    // main::@3
  __b3:
    // [3] main::$0 = '0' + main::b#2 -- vbuxx=vbuc1_plus_vbuxx 
    txa
    axs #-['0']
    // [4] *SCREEN = main::$0 -- _deref_pbuc1=vbuxx 
    // Empty body
    stx SCREEN
    jmp __breturn
    // main::@return
  __breturn:
    // [5] return 
    rts
    // main::@2
  __b2:
    // [6] main::b#1 = ++ main::b#2 -- vbuxx=_inc_vbuxx 
    inx
    // [1] phi from main::@2 to main::@1 [phi:main::@2->main::@1]
  __b1_from___b2:
    // [1] phi main::b#2 = main::b#1 [phi:main::@2->main::@1#0] -- register_copy 
    jmp __b1
}
  // File Data
.segment Data
  str: .text "Hello!"
  .byte 0

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 * const SCREEN = (char *) 1024
void main()
char main::$0 // reg byte x 4.0
char main::b
char main::b#1 // reg byte x 22.0
char main::b#2 // reg byte x 17.5
__constant char str[] = "Hello!"

reg byte x [ main::b#2 main::b#1 ]
reg byte x [ main::$0 ]


FINAL ASSEMBLER
Score: 174

  // File Comments
// Test an empty statement ';'
  // Upstart
  // Commodore 64 PRG executable file
.file [name="stmt-empty-1.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::b#2 = 0 [phi:main->main::@1#0] -- vbuxx=vbuc1 
    ldx #0
    // main::@1
  __b1:
    // for (; str[b] != 0; ++b)
    // [2] if(str[main::b#2]!=0) goto main::@2 -- pbuc1_derefidx_vbuxx_neq_0_then_la1 
    lda str,x
    cmp #0
    bne __b2
    // main::@3
    // '0'+b
    // [3] main::$0 = '0' + main::b#2 -- vbuxx=vbuc1_plus_vbuxx 
    txa
    axs #-['0']
    // SCREEN[0] = '0'+b
    // [4] *SCREEN = main::$0 -- _deref_pbuc1=vbuxx 
    // Empty body
    stx SCREEN
    // main::@return
    // }
    // [5] return 
    rts
    // main::@2
  __b2:
    // for (; str[b] != 0; ++b)
    // [6] main::b#1 = ++ main::b#2 -- vbuxx=_inc_vbuxx 
    inx
    // [1] phi from main::@2 to main::@1 [phi:main::@2->main::@1]
    // [1] phi main::b#2 = main::b#1 [phi:main::@2->main::@1#0] -- register_copy 
    jmp __b1
}
  // File Data
.segment Data
  str: .text "Hello!"
  .byte 0

