
CONTROL FLOW GRAPH SSA
@begin: scope:[]  from
  to:@1

(void()) main()
main: scope:[main]  from @1
  (byte) main::idx#0 ← (byte) 0
  *((const byte*) screen + (byte) main::idx#0) ← (const byte) cpm
  (byte) main::idx#1 ← ++ (byte) main::idx#0
  *((const byte*) screen + (byte) main::idx#1) ← (const byte) ccpu
  (byte) main::idx#2 ← ++ (byte) main::idx#1
  *((const byte*) screen + (byte) main::idx#2) ← (const byte) csm
  (byte) main::idx#3 ← ++ (byte) main::idx#2
  *((const byte*) screen + (byte) main::idx#3) ← (const byte) csu
  (byte) main::idx#4 ← ++ (byte) main::idx#3
  (byte) main::idx#5 ← (number) $28
  *((const byte*) screen + (byte) main::idx#5) ← *((const byte*) spm + (number) 0)
  (byte) main::idx#6 ← ++ (byte) main::idx#5
  *((const byte*) screen + (byte) main::idx#6) ← *((const byte*) spu + (number) 0)
  (byte) main::idx#7 ← ++ (byte) main::idx#6
  *((const byte*) screen + (byte) main::idx#7) ← *((const byte*) ssm + (number) 0)
  (byte) main::idx#8 ← ++ (byte) main::idx#7
  *((const byte*) screen + (byte) main::idx#8) ← *((const byte*) ssu + (number) 0)
  (byte) main::idx#9 ← ++ (byte) main::idx#8
  to:main::@return
main::@return: scope:[main]  from main
  return 
  to:@return
@1: scope:[]  from @begin
  call main 
  to:@2
@2: scope:[]  from @1
  to:@end
@end: scope:[]  from @2

SYMBOL TABLE SSA
(label) @1
(label) @2
(label) @begin
(label) @end
(const byte) ccpu = (byte) 'A'pu
(const byte) cpm = (byte) 'A'pm
(const byte) csm = (byte) 'A'
(const byte) csu = (byte) 'A'su
(void()) main()
(label) main::@return
(byte) main::idx
(byte) main::idx#0
(byte) main::idx#1
(byte) main::idx#2
(byte) main::idx#3
(byte) main::idx#4
(byte) main::idx#5
(byte) main::idx#6
(byte) main::idx#7
(byte) main::idx#8
(byte) main::idx#9
(const byte*) screen = (byte*)(number) $400
(const byte*) spm[]  = (string) "A"pm
(const byte*) spu[]  = (string) "A"pu
(const byte*) ssm[]  = (string) "A"
(const byte*) ssu[]  = (string) "A"su

Adding number conversion cast (unumber) $28 in (byte) main::idx#5 ← (number) $28
Adding number conversion cast (unumber) 0 in *((const byte*) screen + (byte) main::idx#5) ← *((const byte*) spm + (number) 0)
Adding number conversion cast (unumber) 0 in *((const byte*) screen + (byte) main::idx#6) ← *((const byte*) spu + (number) 0)
Adding number conversion cast (unumber) 0 in *((const byte*) screen + (byte) main::idx#7) ← *((const byte*) ssm + (number) 0)
Adding number conversion cast (unumber) 0 in *((const byte*) screen + (byte) main::idx#8) ← *((const byte*) ssu + (number) 0)
Successful SSA optimization PassNAddNumberTypeConversions
Inlining cast (byte) main::idx#5 ← (unumber)(number) $28
Successful SSA optimization Pass2InlineCast
Simplifying constant pointer cast (byte*) 1024
Simplifying constant integer cast $28
Simplifying constant integer cast 0
Simplifying constant integer cast 0
Simplifying constant integer cast 0
Simplifying constant integer cast 0
Successful SSA optimization PassNCastSimplification
Finalized unsigned number type (byte) $28
Finalized unsigned number type (byte) 0
Finalized unsigned number type (byte) 0
Finalized unsigned number type (byte) 0
Finalized unsigned number type (byte) 0
Successful SSA optimization PassNFinalizeNumberTypeConversions
Constant (const byte) main::idx#0 = 0
Constant (const byte) main::idx#5 = $28
Successful SSA optimization Pass2ConstantIdentification
Simplifying expression containing zero screen in [1] *((const byte*) screen + (const byte) main::idx#0) ← (const byte) cpm
Simplifying expression containing zero spm in [10] *((const byte*) screen + (const byte) main::idx#5) ← *((const byte*) spm + (byte) 0)
Simplifying expression containing zero spu in [12] *((const byte*) screen + (byte) main::idx#6) ← *((const byte*) spu + (byte) 0)
Simplifying expression containing zero ssm in [14] *((const byte*) screen + (byte) main::idx#7) ← *((const byte*) ssm + (byte) 0)
Simplifying expression containing zero ssu in [16] *((const byte*) screen + (byte) main::idx#8) ← *((const byte*) ssu + (byte) 0)
Successful SSA optimization PassNSimplifyExpressionWithZero
Eliminating unused variable (byte) main::idx#4 and assignment [7] (byte) main::idx#4 ← ++ (byte) main::idx#3
Eliminating unused variable (byte) main::idx#9 and assignment [15] (byte) main::idx#9 ← ++ (byte) main::idx#8
Successful SSA optimization PassNEliminateUnusedVars
Constant right-side identified [1] (byte) main::idx#1 ← ++ (const byte) main::idx#0
Constant right-side identified [8] (byte) main::idx#6 ← ++ (const byte) main::idx#5
Successful SSA optimization Pass2ConstantRValueConsolidation
Constant (const byte) main::idx#1 = ++main::idx#0
Constant (const byte) main::idx#6 = ++main::idx#5
Successful SSA optimization Pass2ConstantIdentification
Constant right-side identified [2] (byte) main::idx#2 ← ++ (const byte) main::idx#1
Constant right-side identified [8] (byte) main::idx#7 ← ++ (const byte) main::idx#6
Successful SSA optimization Pass2ConstantRValueConsolidation
Constant (const byte) main::idx#2 = ++main::idx#1
Constant (const byte) main::idx#7 = ++main::idx#6
Successful SSA optimization Pass2ConstantIdentification
Constant right-side identified [3] (byte) main::idx#3 ← ++ (const byte) main::idx#2
Constant right-side identified [8] (byte) main::idx#8 ← ++ (const byte) main::idx#7
Successful SSA optimization Pass2ConstantRValueConsolidation
Constant (const byte) main::idx#3 = ++main::idx#2
Constant (const byte) main::idx#8 = ++main::idx#7
Successful SSA optimization Pass2ConstantIdentification
Inlining constant with different constant siblings (const byte) main::idx#0
Inlining constant with different constant siblings (const byte) main::idx#5
Inlining constant with different constant siblings (const byte) main::idx#1
Inlining constant with different constant siblings (const byte) main::idx#6
Inlining constant with different constant siblings (const byte) main::idx#2
Inlining constant with different constant siblings (const byte) main::idx#7
Inlining constant with different constant siblings (const byte) main::idx#3
Inlining constant with different constant siblings (const byte) main::idx#8
Constant inlined main::idx#0 = (byte) 0
Constant inlined main::idx#1 = ++(byte) 0
Constant inlined main::idx#2 = ++++(byte) 0
Constant inlined main::idx#3 = ++++++(byte) 0
Constant inlined main::idx#5 = (byte) $28
Constant inlined main::idx#6 = ++(byte) $28
Constant inlined main::idx#7 = ++++(byte) $28
Constant inlined main::idx#8 = ++++++(byte) $28
Successful SSA optimization Pass2ConstantInlining
Consolidated array index constant in *(screen+++0)
Consolidated array index constant in *(screen+++++0)
Consolidated array index constant in *(screen+++++++0)
Consolidated array index constant in *(screen+$28)
Consolidated array index constant in *(screen+++$28)
Consolidated array index constant in *(screen+++++$28)
Consolidated array index constant in *(screen+++++++$28)
Successful SSA optimization Pass2ConstantAdditionElimination
Simplifying constant integer increment ++0
Simplifying constant integer increment ++0
Simplifying constant integer increment ++1
Simplifying constant integer increment ++$28
Simplifying constant integer increment ++$28
Simplifying constant integer increment ++$29
Successful SSA optimization Pass2ConstantSimplification
Simplifying constant integer increment ++1
Simplifying constant integer increment ++2
Simplifying constant integer increment ++$29
Simplifying constant integer increment ++$2a
Successful SSA optimization Pass2ConstantSimplification
Adding NOP phi() at start of @begin
Adding NOP phi() at start of @1
Adding NOP phi() at start of @2
Adding NOP phi() at start of @end
CALL GRAPH
Calls in [] to main:2 

Created 0 initial phi equivalence classes
Coalesced down to 0 phi equivalence classes
Culled Empty Block (label) @2
Adding NOP phi() at start of @begin
Adding NOP phi() at start of @1
Adding NOP phi() at start of @end

FINAL CONTROL FLOW GRAPH
@begin: scope:[]  from
  [0] phi()
  to:@1
@1: scope:[]  from @begin
  [1] phi()
  [2] call main 
  to:@end
@end: scope:[]  from @1
  [3] phi()

(void()) main()
main: scope:[main]  from @1
  [4] *((const byte*) screen) ← (const byte) cpm
  [5] *((const byte*) screen+(byte) 1) ← (const byte) ccpu
  [6] *((const byte*) screen+(byte) 2) ← (const byte) csm
  [7] *((const byte*) screen+(byte) 3) ← (const byte) csu
  [8] *((const byte*) screen+(byte) $28) ← *((const byte*) spm)
  [9] *((const byte*) screen+(byte) $29) ← *((const byte*) spu)
  [10] *((const byte*) screen+(byte) $2a) ← *((const byte*) ssm)
  [11] *((const byte*) screen+(byte) $2b) ← *((const byte*) ssu)
  to:main::@return
main::@return: scope:[main]  from main
  [12] return 
  to:@return


VARIABLE REGISTER WEIGHTS
(void()) main()
(byte) main::idx

Initial phi equivalence classes
Complete equivalence classes

INITIAL ASM
Target platform is c64basic / MOS6502X
  // File Comments
// Tests encoding of literal chars
  // Upstart
.pc = $801 "Basic"
:BasicUpstart(__bbegin)
.pc = $80d "Program"
  // Global Constants & labels
.encoding "petscii_mixed"
  .const cpm = 'A'
.encoding "petscii_upper"
  .const ccpu = 'A'
.encoding "screencode_mixed"
  .const csm = 'A'
.encoding "screencode_upper"
  .const csu = 'A'
  .label screen = $400
  // @begin
__bbegin:
  // [1] phi from @begin to @1 [phi:@begin->@1]
__b1_from___bbegin:
  jmp __b1
  // @1
__b1:
  // [2] call main 
  jsr main
  // [3] phi from @1 to @end [phi:@1->@end]
__bend_from___b1:
  jmp __bend
  // @end
__bend:
  // main
main: {
    // [4] *((const byte*) screen) ← (const byte) cpm -- _deref_pbuc1=vbuc2 
    lda #cpm
    sta screen
    // [5] *((const byte*) screen+(byte) 1) ← (const byte) ccpu -- _deref_pbuc1=vbuc2 
    lda #ccpu
    sta screen+1
    // [6] *((const byte*) screen+(byte) 2) ← (const byte) csm -- _deref_pbuc1=vbuc2 
    lda #csm
    sta screen+2
    // [7] *((const byte*) screen+(byte) 3) ← (const byte) csu -- _deref_pbuc1=vbuc2 
    lda #csu
    sta screen+3
    // [8] *((const byte*) screen+(byte) $28) ← *((const byte*) spm) -- _deref_pbuc1=_deref_pbuc2 
    lda spm
    sta screen+$28
    // [9] *((const byte*) screen+(byte) $29) ← *((const byte*) spu) -- _deref_pbuc1=_deref_pbuc2 
    lda spu
    sta screen+$29
    // [10] *((const byte*) screen+(byte) $2a) ← *((const byte*) ssm) -- _deref_pbuc1=_deref_pbuc2 
    lda ssm
    sta screen+$2a
    // [11] *((const byte*) screen+(byte) $2b) ← *((const byte*) ssu) -- _deref_pbuc1=_deref_pbuc2 
    lda ssu
    sta screen+$2b
    jmp __breturn
    // main::@return
  __breturn:
    // [12] return 
    rts
}
  // File Data
.encoding "petscii_mixed"
  spm: .text "A"
  .byte 0
.encoding "petscii_upper"
  spu: .text "A"
  .byte 0
.encoding "screencode_mixed"
  ssm: .text "A"
  .byte 0
.encoding "screencode_upper"
  ssu: .text "A"
  .byte 0

REGISTER UPLIFT POTENTIAL REGISTERS
Statement [4] *((const byte*) screen) ← (const byte) cpm [ ] ( main:2 [ ] ) always clobbers reg byte a 
Statement [5] *((const byte*) screen+(byte) 1) ← (const byte) ccpu [ ] ( main:2 [ ] ) always clobbers reg byte a 
Statement [6] *((const byte*) screen+(byte) 2) ← (const byte) csm [ ] ( main:2 [ ] ) always clobbers reg byte a 
Statement [7] *((const byte*) screen+(byte) 3) ← (const byte) csu [ ] ( main:2 [ ] ) always clobbers reg byte a 
Statement [8] *((const byte*) screen+(byte) $28) ← *((const byte*) spm) [ ] ( main:2 [ ] ) always clobbers reg byte a 
Statement [9] *((const byte*) screen+(byte) $29) ← *((const byte*) spu) [ ] ( main:2 [ ] ) always clobbers reg byte a 
Statement [10] *((const byte*) screen+(byte) $2a) ← *((const byte*) ssm) [ ] ( main:2 [ ] ) always clobbers reg byte a 
Statement [11] *((const byte*) screen+(byte) $2b) ← *((const byte*) ssu) [ ] ( main:2 [ ] ) always clobbers reg byte a 

REGISTER UPLIFT SCOPES
Uplift Scope [main] 
Uplift Scope [] 

Uplifting [main] best 77 combination 
Uplifting [] best 77 combination 

ASSEMBLER BEFORE OPTIMIZATION
  // File Comments
// Tests encoding of literal chars
  // Upstart
.pc = $801 "Basic"
:BasicUpstart(__bbegin)
.pc = $80d "Program"
  // Global Constants & labels
.encoding "petscii_mixed"
  .const cpm = 'A'
.encoding "petscii_upper"
  .const ccpu = 'A'
.encoding "screencode_mixed"
  .const csm = 'A'
.encoding "screencode_upper"
  .const csu = 'A'
  .label screen = $400
  // @begin
__bbegin:
  // [1] phi from @begin to @1 [phi:@begin->@1]
__b1_from___bbegin:
  jmp __b1
  // @1
__b1:
  // [2] call main 
  jsr main
  // [3] phi from @1 to @end [phi:@1->@end]
__bend_from___b1:
  jmp __bend
  // @end
__bend:
  // main
main: {
    // [4] *((const byte*) screen) ← (const byte) cpm -- _deref_pbuc1=vbuc2 
    lda #cpm
    sta screen
    // [5] *((const byte*) screen+(byte) 1) ← (const byte) ccpu -- _deref_pbuc1=vbuc2 
    lda #ccpu
    sta screen+1
    // [6] *((const byte*) screen+(byte) 2) ← (const byte) csm -- _deref_pbuc1=vbuc2 
    lda #csm
    sta screen+2
    // [7] *((const byte*) screen+(byte) 3) ← (const byte) csu -- _deref_pbuc1=vbuc2 
    lda #csu
    sta screen+3
    // [8] *((const byte*) screen+(byte) $28) ← *((const byte*) spm) -- _deref_pbuc1=_deref_pbuc2 
    lda spm
    sta screen+$28
    // [9] *((const byte*) screen+(byte) $29) ← *((const byte*) spu) -- _deref_pbuc1=_deref_pbuc2 
    lda spu
    sta screen+$29
    // [10] *((const byte*) screen+(byte) $2a) ← *((const byte*) ssm) -- _deref_pbuc1=_deref_pbuc2 
    lda ssm
    sta screen+$2a
    // [11] *((const byte*) screen+(byte) $2b) ← *((const byte*) ssu) -- _deref_pbuc1=_deref_pbuc2 
    lda ssu
    sta screen+$2b
    jmp __breturn
    // main::@return
  __breturn:
    // [12] return 
    rts
}
  // File Data
.encoding "petscii_mixed"
  spm: .text "A"
  .byte 0
.encoding "petscii_upper"
  spu: .text "A"
  .byte 0
.encoding "screencode_mixed"
  ssm: .text "A"
  .byte 0
.encoding "screencode_upper"
  ssu: .text "A"
  .byte 0

ASSEMBLER OPTIMIZATIONS
Removing instruction jmp __b1
Removing instruction jmp __bend
Removing instruction jmp __breturn
Succesful ASM optimization Pass5NextJumpElimination
Replacing label __bbegin with __b1
Removing instruction __bbegin:
Removing instruction __b1_from___bbegin:
Removing instruction __bend_from___b1:
Succesful ASM optimization Pass5RedundantLabelElimination
Removing instruction __bend:
Removing instruction __breturn:
Succesful ASM optimization Pass5UnusedLabelElimination
Updating BasicUpstart to call main directly
Removing instruction jsr main
Succesful ASM optimization Pass5SkipBegin
Removing instruction __b1:
Succesful ASM optimization Pass5UnusedLabelElimination

FINAL SYMBOL TABLE
(label) @1
(label) @begin
(label) @end
(const byte) ccpu = (byte) 'A'pu
(const byte) cpm = (byte) 'A'pm
(const byte) csm = (byte) 'A'
(const byte) csu = (byte) 'A'su
(void()) main()
(label) main::@return
(byte) main::idx
(const byte*) screen = (byte*) 1024
(const byte*) spm[]  = (string) "A"pm
(const byte*) spu[]  = (string) "A"pu
(const byte*) ssm[]  = (string) "A"
(const byte*) ssu[]  = (string) "A"su



FINAL ASSEMBLER
Score: 62

  // File Comments
// Tests encoding of literal chars
  // Upstart
.pc = $801 "Basic"
:BasicUpstart(main)
.pc = $80d "Program"
  // Global Constants & labels
.encoding "petscii_mixed"
  .const cpm = 'A'
.encoding "petscii_upper"
  .const ccpu = 'A'
.encoding "screencode_mixed"
  .const csm = 'A'
.encoding "screencode_upper"
  .const csu = 'A'
  .label screen = $400
  // @begin
  // [1] phi from @begin to @1 [phi:@begin->@1]
  // @1
  // [2] call main 
  // [3] phi from @1 to @end [phi:@1->@end]
  // @end
  // main
main: {
    // screen[idx++] = cpm
    // [4] *((const byte*) screen) ← (const byte) cpm -- _deref_pbuc1=vbuc2 
    lda #cpm
    sta screen
    // screen[idx++] = ccpu
    // [5] *((const byte*) screen+(byte) 1) ← (const byte) ccpu -- _deref_pbuc1=vbuc2 
    lda #ccpu
    sta screen+1
    // screen[idx++] = csm
    // [6] *((const byte*) screen+(byte) 2) ← (const byte) csm -- _deref_pbuc1=vbuc2 
    lda #csm
    sta screen+2
    // screen[idx++] = csu
    // [7] *((const byte*) screen+(byte) 3) ← (const byte) csu -- _deref_pbuc1=vbuc2 
    lda #csu
    sta screen+3
    // screen[idx++] = spm[0]
    // [8] *((const byte*) screen+(byte) $28) ← *((const byte*) spm) -- _deref_pbuc1=_deref_pbuc2 
    lda spm
    sta screen+$28
    // screen[idx++] = spu[0]
    // [9] *((const byte*) screen+(byte) $29) ← *((const byte*) spu) -- _deref_pbuc1=_deref_pbuc2 
    lda spu
    sta screen+$29
    // screen[idx++] = ssm[0]
    // [10] *((const byte*) screen+(byte) $2a) ← *((const byte*) ssm) -- _deref_pbuc1=_deref_pbuc2 
    lda ssm
    sta screen+$2a
    // screen[idx++] = ssu[0]
    // [11] *((const byte*) screen+(byte) $2b) ← *((const byte*) ssu) -- _deref_pbuc1=_deref_pbuc2 
    lda ssu
    sta screen+$2b
    // main::@return
    // }
    // [12] return 
    rts
}
  // File Data
.encoding "petscii_mixed"
  spm: .text "A"
  .byte 0
.encoding "petscii_upper"
  spu: .text "A"
  .byte 0
.encoding "screencode_mixed"
  ssm: .text "A"
  .byte 0
.encoding "screencode_upper"
  ssu: .text "A"
  .byte 0

