
CONTROL FLOW GRAPH SSA

void main()
main: scope:[main]  from __start
  main::screen#0 = (char *)$400
  main::i#0 = 0
  to:main::@1
main::@1: scope:[main]  from main main::@7
  main::screen#9 = phi( main/main::screen#0, main::@7/main::screen#2 )
  main::i#2 = phi( main/main::i#0, main::@7/main::i#1 )
  main::$0 = main::i#2 & 1
  main::$13 = 0 != main::$0
  if(main::$13) goto main::@2
  to:main::@3
main::@2: scope:[main]  from main::@1
  main::screen#5 = phi( main::@1/main::screen#9 )
  main::i#3 = phi( main::@1/main::i#2 )
  main::$3 = main::i#3 + 3
  main::$4 = main::$3
  to:main::@4
main::@3: scope:[main]  from main::@1
  main::screen#6 = phi( main::@1/main::screen#9 )
  main::i#4 = phi( main::@1/main::i#2 )
  main::$1 = main::i#4 * 4
  main::$2 = main::$1
  to:main::@4
main::@4: scope:[main]  from main::@2 main::@3
  main::i#5 = phi( main::@2/main::i#3, main::@3/main::i#4 )
  main::screen#3 = phi( main::@2/main::screen#5, main::@3/main::screen#6 )
  main::$5 = phi( main::@2/main::$4, main::@3/main::$2 )
  *main::screen#3 = main::$5
  main::screen#1 = ++ main::screen#3
  main::$6 = main::i#5 & 1
  main::$14 = 0 != main::$6
  if(main::$14) goto main::@5
  to:main::@6
main::@5: scope:[main]  from main::@4
  main::screen#7 = phi( main::@4/main::screen#1 )
  main::i#6 = phi( main::@4/main::i#5 )
  main::$9 = main::i#6 + 3
  main::$10 = main::$9
  to:main::@7
main::@6: scope:[main]  from main::@4
  main::screen#8 = phi( main::@4/main::screen#1 )
  main::i#7 = phi( main::@4/main::i#5 )
  main::$7 = main::i#7 * 4
  main::$8 = main::$7
  to:main::@7
main::@7: scope:[main]  from main::@5 main::@6
  main::i#8 = phi( main::@5/main::i#6, main::@6/main::i#7 )
  main::screen#4 = phi( main::@5/main::screen#7, main::@6/main::screen#8 )
  main::$11 = phi( main::@5/main::$10, main::@6/main::$8 )
  *main::screen#4 = main::$11
  main::screen#2 = ++ main::screen#4
  main::i#1 = main::i#8 + rangenext(0,2)
  main::$12 = main::i#1 != rangelast(0,2)
  if(main::$12) goto main::@1
  to:main::@return
main::@return: scope:[main]  from main::@7
  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
void __start()
void main()
number main::$0
number main::$1
number main::$10
number main::$11
bool main::$12
bool main::$13
bool main::$14
number main::$2
number main::$3
number main::$4
number main::$5
number main::$6
number main::$7
number main::$8
number main::$9
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::i#6
char main::i#7
char main::i#8
char *main::screen
char *main::screen#0
char *main::screen#1
char *main::screen#2
char *main::screen#3
char *main::screen#4
char *main::screen#5
char *main::screen#6
char *main::screen#7
char *main::screen#8
char *main::screen#9

Adding number conversion cast (unumber) 1 in main::$0 = main::i#2 & 1
Adding number conversion cast (unumber) main::$0 in main::$0 = main::i#2 & (unumber)1
Adding number conversion cast (unumber) 0 in main::$13 = 0 != main::$0
Adding number conversion cast (unumber) 3 in main::$3 = main::i#3 + 3
Adding number conversion cast (unumber) main::$3 in main::$3 = main::i#3 + (unumber)3
Adding number conversion cast (unumber) main::$4 in main::$4 = main::$3
Adding number conversion cast (unumber) 4 in main::$1 = main::i#4 * 4
Adding number conversion cast (unumber) main::$1 in main::$1 = main::i#4 * (unumber)4
Adding number conversion cast (unumber) main::$2 in main::$2 = main::$1
Adding number conversion cast (unumber) main::$5 in main::i#5 = phi( main::@2/main::i#3, main::@3/main::i#4 )
  main::screen#3 = phi( main::@2/main::screen#5, main::@3/main::screen#6 )
  main::$5 = phi( main::@2/main::$4, main::@3/main::$2 )
Adding number conversion cast (unumber) 1 in main::$6 = main::i#5 & 1
Adding number conversion cast (unumber) main::$6 in main::$6 = main::i#5 & (unumber)1
Adding number conversion cast (unumber) 0 in main::$14 = 0 != main::$6
Adding number conversion cast (unumber) 3 in main::$9 = main::i#6 + 3
Adding number conversion cast (unumber) main::$9 in main::$9 = main::i#6 + (unumber)3
Adding number conversion cast (unumber) main::$10 in main::$10 = main::$9
Adding number conversion cast (unumber) 4 in main::$7 = main::i#7 * 4
Adding number conversion cast (unumber) main::$7 in main::$7 = main::i#7 * (unumber)4
Adding number conversion cast (unumber) main::$8 in main::$8 = main::$7
Adding number conversion cast (unumber) main::$11 in main::i#8 = phi( main::@5/main::i#6, main::@6/main::i#7 )
  main::screen#4 = phi( main::@5/main::screen#7, main::@6/main::screen#8 )
  main::$11 = phi( main::@5/main::$10, main::@6/main::$8 )
Successful SSA optimization PassNAddNumberTypeConversions
Simplifying constant pointer cast (char *) 1024
Simplifying constant integer cast 1
Simplifying constant integer cast 0
Simplifying constant integer cast 3
Simplifying constant integer cast 4
Simplifying constant integer cast 1
Simplifying constant integer cast 0
Simplifying constant integer cast 3
Simplifying constant integer cast 4
Successful SSA optimization PassNCastSimplification
Finalized unsigned number type (char) 1
Finalized unsigned number type (char) 0
Finalized unsigned number type (char) 3
Finalized unsigned number type (char) 4
Finalized unsigned number type (char) 1
Finalized unsigned number type (char) 0
Finalized unsigned number type (char) 3
Finalized unsigned number type (char) 4
Successful SSA optimization PassNFinalizeNumberTypeConversions
Inferred type updated to char in main::$0 = main::i#2 & 1
Inferred type updated to char in main::$3 = main::i#3 + 3
Inferred type updated to char in main::$4 = main::$3
Inferred type updated to char in main::$1 = main::i#4 * 4
Inferred type updated to char in main::$2 = main::$1
Inferred type updated to char for main::$5
Inferred type updated to char in main::$6 = main::i#5 & 1
Inferred type updated to char in main::$9 = main::i#6 + 3
Inferred type updated to char in main::$10 = main::$9
Inferred type updated to char in main::$7 = main::i#7 * 4
Inferred type updated to char in main::$8 = main::$7
Inferred type updated to char for main::$11
Alias main::i#2 = main::i#3 main::i#4 
Alias main::screen#5 = main::screen#9 main::screen#6 
Alias main::$4 = main::$3 
Alias main::$2 = main::$1 
Alias main::i#5 = main::i#6 main::i#7 
Alias main::screen#1 = main::screen#7 main::screen#8 
Alias main::$10 = main::$9 
Alias main::$8 = main::$7 
Successful SSA optimization Pass2AliasElimination
Alias main::screen#3 = main::screen#5 
Alias main::i#2 = main::i#5 main::i#8 
Alias main::screen#1 = main::screen#4 
Successful SSA optimization Pass2AliasElimination
Identified duplicate assignment right side [15] main::$6 = main::i#2 & 1
Successful SSA optimization Pass2DuplicateRValueIdentification
Simple Condition main::$13 [5] if(0!=main::$0) goto main::@2
Simple Condition main::$14 [13] if(0!=main::$6) goto main::@5
Simple Condition main::$12 [21] if(main::i#1!=rangelast(0,2)) goto main::@1
Successful SSA optimization Pass2ConditionalJumpSimplification
Constant main::screen#0 = (char *) 1024
Constant main::i#0 = 0
Successful SSA optimization Pass2ConstantIdentification
Resolved ranged next value [19] main::i#1 = ++ main::i#2 to ++
Resolved ranged comparison value [21] if(main::i#1!=rangelast(0,2)) goto main::@1 to 3
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
Adding number conversion cast (unumber) 3 in [16] if(main::i#1!=3) goto main::@1
Successful SSA optimization PassNAddNumberTypeConversions
Simplifying constant integer cast 3
Successful SSA optimization PassNCastSimplification
Finalized unsigned number type (char) 3
Successful SSA optimization PassNFinalizeNumberTypeConversions
Alias main::$6 = main::$0 
Successful SSA optimization Pass2AliasElimination
Rewriting multiplication to use shift [4] main::$2 = main::i#2 * 4
Rewriting multiplication to use shift [10] main::$8 = main::i#2 * 4
Successful SSA optimization Pass2MultiplyToShiftRewriting
Inlining constant with var siblings main::screen#0
Inlining constant with var siblings main::i#0
Constant inlined main::screen#0 = (char *) 1024
Constant inlined main::i#0 = 0
Successful SSA optimization Pass2ConstantInlining
Added new block during phi lifting main::@8(between main::@7 and main::@1)
Adding NOP phi() at start of main
CALL GRAPH

Created 4 initial phi equivalence classes
Coalesced [5] main::$16 = main::$2
Coalesced [11] main::$18 = main::$8
Coalesced [18] main::i#9 = main::i#1
Coalesced [19] main::screen#10 = main::screen#2
Coalesced [21] main::$17 = main::$10
Coalesced [23] main::$15 = main::$4
Coalesced down to 4 phi equivalence classes
Culled Empty Block label main::@8
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::@7
  [1] main::screen#3 = phi( main/(char *) 1024, main::@7/main::screen#2 )
  [1] main::i#2 = phi( main/0, main::@7/main::i#1 )
  [2] main::$6 = main::i#2 & 1
  [3] if(0!=main::$6) goto main::@2
  to:main::@3
main::@3: scope:[main]  from main::@1
  [4] main::$2 = main::i#2 << 2
  to:main::@4
main::@4: scope:[main]  from main::@2 main::@3
  [5] main::$5 = phi( main::@2/main::$4, main::@3/main::$2 )
  [6] *main::screen#3 = main::$5
  [7] main::screen#1 = ++ main::screen#3
  [8] if(0!=main::$6) goto main::@5
  to:main::@6
main::@6: scope:[main]  from main::@4
  [9] main::$8 = main::i#2 << 2
  to:main::@7
main::@7: scope:[main]  from main::@5 main::@6
  [10] main::$11 = phi( main::@5/main::$10, main::@6/main::$8 )
  [11] *main::screen#1 = main::$11
  [12] main::screen#2 = ++ main::screen#1
  [13] main::i#1 = ++ main::i#2
  [14] if(main::i#1!=3) goto main::@1
  to:main::@return
main::@return: scope:[main]  from main::@7
  [15] return 
  to:@return
main::@5: scope:[main]  from main::@4
  [16] main::$10 = main::i#2 + 3
  to:main::@7
main::@2: scope:[main]  from main::@1
  [17] main::$4 = main::i#2 + 3
  to:main::@4


VARIABLE REGISTER WEIGHTS
void main()
char main::$10 // 22.0
char main::$11 // 33.0
char main::$2 // 22.0
char main::$4 // 22.0
char main::$5 // 33.0
char main::$6 // 4.714285714285714
char main::$8 // 22.0
char main::i
char main::i#1 // 16.5
char main::i#2 // 5.5
char *main::screen
char *main::screen#1 // 5.5
char *main::screen#2 // 7.333333333333333
char *main::screen#3 // 4.714285714285714

Initial phi equivalence classes
[ main::i#2 main::i#1 ]
[ main::screen#3 main::screen#2 ]
[ main::$5 main::$4 main::$2 ]
[ main::$11 main::$10 main::$8 ]
Added variable main::$6 to live range equivalence class [ main::$6 ]
Added variable main::screen#1 to live range equivalence class [ main::screen#1 ]
Complete equivalence classes
[ main::i#2 main::i#1 ]
[ main::screen#3 main::screen#2 ]
[ main::$5 main::$4 main::$2 ]
[ main::$11 main::$10 main::$8 ]
[ main::$6 ]
[ main::screen#1 ]
Allocated zp[1]:2 [ main::$5 main::$4 main::$2 ]
Allocated zp[1]:3 [ main::$11 main::$10 main::$8 ]
Allocated zp[1]:4 [ main::i#2 main::i#1 ]
Allocated zp[2]:5 [ main::screen#3 main::screen#2 ]
Allocated zp[2]:7 [ main::screen#1 ]
Allocated zp[1]:9 [ main::$6 ]
REGISTER UPLIFT POTENTIAL REGISTERS
Statement [4] main::$2 = main::i#2 << 2 [ main::i#2 main::screen#3 main::$6 main::$2 ] (  [ main::i#2 main::screen#3 main::$6 main::$2 ] { }  ) always clobbers reg byte a 
Removing always clobbered register reg byte a as potential for zp[1]:4 [ main::i#2 main::i#1 ]
Removing always clobbered register reg byte a as potential for zp[1]:9 [ main::$6 ]
Statement [6] *main::screen#3 = main::$5 [ main::i#2 main::screen#3 main::$6 ] (  [ main::i#2 main::screen#3 main::$6 ] { }  ) always clobbers reg byte y 
Removing always clobbered register reg byte y as potential for zp[1]:4 [ main::i#2 main::i#1 ]
Removing always clobbered register reg byte y as potential for zp[1]:9 [ main::$6 ]
Statement [7] main::screen#1 = ++ main::screen#3 [ main::i#2 main::$6 main::screen#1 ] (  [ main::i#2 main::$6 main::screen#1 ] { }  ) always clobbers reg byte a 
Statement [9] main::$8 = main::i#2 << 2 [ main::i#2 main::screen#1 main::$8 ] (  [ main::i#2 main::screen#1 main::$8 ] { }  ) always clobbers reg byte a 
Statement [11] *main::screen#1 = main::$11 [ main::i#2 main::screen#1 ] (  [ main::i#2 main::screen#1 ] { }  ) always clobbers reg byte y 
Statement [12] main::screen#2 = ++ main::screen#1 [ main::i#2 main::screen#2 ] (  [ main::i#2 main::screen#2 ] { }  ) always clobbers reg byte a 
Statement [16] main::$10 = main::i#2 + 3 [ main::i#2 main::screen#1 main::$10 ] (  [ main::i#2 main::screen#1 main::$10 ] { }  ) always clobbers reg byte a 
Statement [17] main::$4 = main::i#2 + 3 [ main::i#2 main::screen#3 main::$6 main::$4 ] (  [ main::i#2 main::screen#3 main::$6 main::$4 ] { }  ) always clobbers reg byte a 
Statement [2] main::$6 = main::i#2 & 1 [ main::i#2 main::screen#3 main::$6 ] (  [ main::i#2 main::screen#3 main::$6 ] { }  ) always clobbers reg byte a 
Statement [4] main::$2 = main::i#2 << 2 [ main::i#2 main::screen#3 main::$6 main::$2 ] (  [ main::i#2 main::screen#3 main::$6 main::$2 ] { }  ) always clobbers reg byte a 
Statement [6] *main::screen#3 = main::$5 [ main::i#2 main::screen#3 main::$6 ] (  [ main::i#2 main::screen#3 main::$6 ] { }  ) always clobbers reg byte y 
Statement [7] main::screen#1 = ++ main::screen#3 [ main::i#2 main::$6 main::screen#1 ] (  [ main::i#2 main::$6 main::screen#1 ] { }  ) always clobbers reg byte a 
Statement [9] main::$8 = main::i#2 << 2 [ main::i#2 main::screen#1 main::$8 ] (  [ main::i#2 main::screen#1 main::$8 ] { }  ) always clobbers reg byte a 
Statement [11] *main::screen#1 = main::$11 [ main::i#2 main::screen#1 ] (  [ main::i#2 main::screen#1 ] { }  ) always clobbers reg byte y 
Statement [12] main::screen#2 = ++ main::screen#1 [ main::i#2 main::screen#2 ] (  [ main::i#2 main::screen#2 ] { }  ) always clobbers reg byte a 
Statement [16] main::$10 = main::i#2 + 3 [ main::i#2 main::screen#1 main::$10 ] (  [ main::i#2 main::screen#1 main::$10 ] { }  ) always clobbers reg byte a 
Statement [17] main::$4 = main::i#2 + 3 [ main::i#2 main::screen#3 main::$6 main::$4 ] (  [ main::i#2 main::screen#3 main::$6 main::$4 ] { }  ) always clobbers reg byte a 
Potential registers zp[1]:4 [ main::i#2 main::i#1 ] : zp[1]:4 , reg byte x , 
Potential registers zp[2]:5 [ main::screen#3 main::screen#2 ] : zp[2]:5 , 
Potential registers zp[1]:2 [ main::$5 main::$4 main::$2 ] : zp[1]:2 , reg byte a , reg byte x , reg byte y , 
Potential registers zp[1]:3 [ main::$11 main::$10 main::$8 ] : zp[1]:3 , reg byte a , reg byte x , reg byte y , 
Potential registers zp[1]:9 [ main::$6 ] : zp[1]:9 , reg byte x , 
Potential registers zp[2]:7 [ main::screen#1 ] : zp[2]:7 , 

REGISTER UPLIFT SCOPES
Uplift Scope [main] 77: zp[1]:2 [ main::$5 main::$4 main::$2 ] 77: zp[1]:3 [ main::$11 main::$10 main::$8 ] 22: zp[1]:4 [ main::i#2 main::i#1 ] 12.05: zp[2]:5 [ main::screen#3 main::screen#2 ] 5.5: zp[2]:7 [ main::screen#1 ] 4.71: zp[1]:9 [ main::$6 ] 
Uplift Scope [] 

Uplifting [main] best 1381 combination reg byte a [ main::$5 main::$4 main::$2 ] reg byte a [ main::$11 main::$10 main::$8 ] reg byte x [ main::i#2 main::i#1 ] zp[2]:5 [ main::screen#3 main::screen#2 ] zp[2]:7 [ main::screen#1 ] zp[1]:9 [ main::$6 ] 
Uplifting [] best 1381 combination 
Attempting to uplift remaining variables inzp[1]:9 [ main::$6 ]
Uplifting [main] best 1381 combination zp[1]:9 [ main::$6 ] 
Coalescing zero page register [ zp[2]:5 [ main::screen#3 main::screen#2 ] ] with [ zp[2]:7 [ main::screen#1 ] ] - score: 2
Allocated (was zp[2]:5) zp[2]:2 [ main::screen#3 main::screen#2 main::screen#1 ]
Allocated (was zp[1]:9) zp[1]:4 [ main::$6 ]

ASSEMBLER BEFORE OPTIMIZATION
  // File Comments
// Tests optimization of identical sub-expressions
  // Upstart
  // Commodore 64 PRG executable file
.file [name="subexpr-optimize-4.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
.segment Code
  // main
main: {
    .label __6 = 4
    .label screen = 2
    // [1] phi from main to main::@1 [phi:main->main::@1]
  __b1_from_main:
    // [1] phi main::screen#3 = (char *) 1024 [phi:main->main::@1#0] -- pbuz1=pbuc1 
    lda #<$400
    sta.z screen
    lda #>$400
    sta.z screen+1
    // [1] phi main::i#2 = 0 [phi:main->main::@1#1] -- vbuxx=vbuc1 
    ldx #0
    jmp __b1
    // [1] phi from main::@7 to main::@1 [phi:main::@7->main::@1]
  __b1_from___b7:
    // [1] phi main::screen#3 = main::screen#2 [phi:main::@7->main::@1#0] -- register_copy 
    // [1] phi main::i#2 = main::i#1 [phi:main::@7->main::@1#1] -- register_copy 
    jmp __b1
    // main::@1
  __b1:
    // [2] main::$6 = main::i#2 & 1 -- vbuz1=vbuxx_band_vbuc1 
    lda #1
    sax.z __6
    // [3] if(0!=main::$6) goto main::@2 -- 0_neq_vbuz1_then_la1 
    lda.z __6
    bne __b2
    jmp __b3
    // main::@3
  __b3:
    // [4] main::$2 = main::i#2 << 2 -- vbuaa=vbuxx_rol_2 
    txa
    asl
    asl
    // [5] phi from main::@2 main::@3 to main::@4 [phi:main::@2/main::@3->main::@4]
  __b4_from___b2:
  __b4_from___b3:
    // [5] phi main::$5 = main::$4 [phi:main::@2/main::@3->main::@4#0] -- register_copy 
    jmp __b4
    // main::@4
  __b4:
    // [6] *main::screen#3 = main::$5 -- _deref_pbuz1=vbuaa 
    ldy #0
    sta (screen),y
    // [7] main::screen#1 = ++ main::screen#3 -- pbuz1=_inc_pbuz1 
    inc.z screen
    bne !+
    inc.z screen+1
  !:
    // [8] if(0!=main::$6) goto main::@5 -- 0_neq_vbuz1_then_la1 
    lda.z __6
    bne __b5
    jmp __b6
    // main::@6
  __b6:
    // [9] main::$8 = main::i#2 << 2 -- vbuaa=vbuxx_rol_2 
    txa
    asl
    asl
    // [10] phi from main::@5 main::@6 to main::@7 [phi:main::@5/main::@6->main::@7]
  __b7_from___b5:
  __b7_from___b6:
    // [10] phi main::$11 = main::$10 [phi:main::@5/main::@6->main::@7#0] -- register_copy 
    jmp __b7
    // main::@7
  __b7:
    // [11] *main::screen#1 = main::$11 -- _deref_pbuz1=vbuaa 
    ldy #0
    sta (screen),y
    // [12] main::screen#2 = ++ main::screen#1 -- pbuz1=_inc_pbuz1 
    inc.z screen
    bne !+
    inc.z screen+1
  !:
    // [13] main::i#1 = ++ main::i#2 -- vbuxx=_inc_vbuxx 
    inx
    // [14] if(main::i#1!=3) goto main::@1 -- vbuxx_neq_vbuc1_then_la1 
    cpx #3
    bne __b1_from___b7
    jmp __breturn
    // main::@return
  __breturn:
    // [15] return 
    rts
    // main::@5
  __b5:
    // [16] main::$10 = main::i#2 + 3 -- vbuaa=vbuxx_plus_vbuc1 
    txa
    clc
    adc #3
    jmp __b7_from___b5
    // main::@2
  __b2:
    // [17] main::$4 = main::i#2 + 3 -- vbuaa=vbuxx_plus_vbuc1 
    txa
    clc
    adc #3
    jmp __b4_from___b2
}
  // File Data

ASSEMBLER OPTIMIZATIONS
Removing instruction jmp __b1
Removing instruction jmp __b3
Removing instruction jmp __b4
Removing instruction jmp __b6
Removing instruction jmp __b7
Removing instruction jmp __breturn
Succesful ASM optimization Pass5NextJumpElimination
Replacing label __b1_from___b7 with __b1
Replacing label __b7_from___b5 with __b7
Replacing label __b4_from___b2 with __b4
Removing instruction __b1_from___b7:
Removing instruction __b4_from___b2:
Removing instruction __b4_from___b3:
Removing instruction __b7_from___b5:
Removing instruction __b7_from___b6:
Succesful ASM optimization Pass5RedundantLabelElimination
Removing instruction __b1_from_main:
Removing instruction __b3:
Removing instruction __b6:
Removing instruction __breturn:
Succesful ASM optimization Pass5UnusedLabelElimination
Removing instruction jmp __b1
Succesful ASM optimization Pass5NextJumpElimination

FINAL SYMBOL TABLE
void main()
char main::$10 // reg byte a 22.0
char main::$11 // reg byte a 33.0
char main::$2 // reg byte a 22.0
char main::$4 // reg byte a 22.0
char main::$5 // reg byte a 33.0
char main::$6 // zp[1]:4 4.714285714285714
char main::$8 // reg byte a 22.0
char main::i
char main::i#1 // reg byte x 16.5
char main::i#2 // reg byte x 5.5
char *main::screen
char *main::screen#1 // screen zp[2]:2 5.5
char *main::screen#2 // screen zp[2]:2 7.333333333333333
char *main::screen#3 // screen zp[2]:2 4.714285714285714

reg byte x [ main::i#2 main::i#1 ]
zp[2]:2 [ main::screen#3 main::screen#2 main::screen#1 ]
reg byte a [ main::$5 main::$4 main::$2 ]
reg byte a [ main::$11 main::$10 main::$8 ]
zp[1]:4 [ main::$6 ]


FINAL ASSEMBLER
Score: 1061

  // File Comments
// Tests optimization of identical sub-expressions
  // Upstart
  // Commodore 64 PRG executable file
.file [name="subexpr-optimize-4.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
.segment Code
  // main
main: {
    .label __6 = 4
    .label screen = 2
    // [1] phi from main to main::@1 [phi:main->main::@1]
    // [1] phi main::screen#3 = (char *) 1024 [phi:main->main::@1#0] -- pbuz1=pbuc1 
    lda #<$400
    sta.z screen
    lda #>$400
    sta.z screen+1
    // [1] phi main::i#2 = 0 [phi:main->main::@1#1] -- vbuxx=vbuc1 
    ldx #0
    // [1] phi from main::@7 to main::@1 [phi:main::@7->main::@1]
    // [1] phi main::screen#3 = main::screen#2 [phi:main::@7->main::@1#0] -- register_copy 
    // [1] phi main::i#2 = main::i#1 [phi:main::@7->main::@1#1] -- register_copy 
    // main::@1
  __b1:
    // i&1
    // [2] main::$6 = main::i#2 & 1 -- vbuz1=vbuxx_band_vbuc1 
    lda #1
    sax.z __6
    // (i&1)?i+3:i*4
    // [3] if(0!=main::$6) goto main::@2 -- 0_neq_vbuz1_then_la1 
    lda.z __6
    bne __b2
    // main::@3
    // [4] main::$2 = main::i#2 << 2 -- vbuaa=vbuxx_rol_2 
    txa
    asl
    asl
    // [5] phi from main::@2 main::@3 to main::@4 [phi:main::@2/main::@3->main::@4]
    // [5] phi main::$5 = main::$4 [phi:main::@2/main::@3->main::@4#0] -- register_copy 
    // main::@4
  __b4:
    // *screen++ = (i&1)?i+3:i*4
    // [6] *main::screen#3 = main::$5 -- _deref_pbuz1=vbuaa 
    ldy #0
    sta (screen),y
    // *screen++ = (i&1)?i+3:i*4;
    // [7] main::screen#1 = ++ main::screen#3 -- pbuz1=_inc_pbuz1 
    inc.z screen
    bne !+
    inc.z screen+1
  !:
    // (i&1)?i+3:i*4
    // [8] if(0!=main::$6) goto main::@5 -- 0_neq_vbuz1_then_la1 
    lda.z __6
    bne __b5
    // main::@6
    // [9] main::$8 = main::i#2 << 2 -- vbuaa=vbuxx_rol_2 
    txa
    asl
    asl
    // [10] phi from main::@5 main::@6 to main::@7 [phi:main::@5/main::@6->main::@7]
    // [10] phi main::$11 = main::$10 [phi:main::@5/main::@6->main::@7#0] -- register_copy 
    // main::@7
  __b7:
    // *screen++ = (i&1)?i+3:i*4
    // [11] *main::screen#1 = main::$11 -- _deref_pbuz1=vbuaa 
    ldy #0
    sta (screen),y
    // *screen++ = (i&1)?i+3:i*4;
    // [12] main::screen#2 = ++ main::screen#1 -- pbuz1=_inc_pbuz1 
    inc.z screen
    bne !+
    inc.z screen+1
  !:
    // for( byte i: 0..2)
    // [13] main::i#1 = ++ main::i#2 -- vbuxx=_inc_vbuxx 
    inx
    // [14] if(main::i#1!=3) goto main::@1 -- vbuxx_neq_vbuc1_then_la1 
    cpx #3
    bne __b1
    // main::@return
    // }
    // [15] return 
    rts
    // main::@5
  __b5:
    // (i&1)?i+3:i*4
    // [16] main::$10 = main::i#2 + 3 -- vbuaa=vbuxx_plus_vbuc1 
    txa
    clc
    adc #3
    jmp __b7
    // main::@2
  __b2:
    // [17] main::$4 = main::i#2 + 3 -- vbuaa=vbuxx_plus_vbuc1 
    txa
    clc
    adc #3
    jmp __b4
}
  // File Data

