
CONTROL FLOW GRAPH SSA
@begin: scope:[]  from
  to:@1
main: scope:[main]  from @1
  (byte[]) main::STRING#0 ← (const string) main::$5
  (byte*) main::PTR#0 ← ((byte*)) (number) $9ffe
  (byte~) main::$0 ← < (byte[]) main::STRING#0
  *((byte*) main::PTR#0) ← (byte~) main::$0
  (byte*~) main::$1 ← (byte*) main::PTR#0 + (number) 1
  (byte~) main::$2 ← > (byte[]) main::STRING#0
  *((byte*~) main::$1) ← (byte~) main::$2
  (byte*~) main::$3 ← (byte*) main::PTR#0 + (number) 1
  (byte*~) main::$4 ← ((byte*)) { *((byte*~) main::$3), *((byte*) main::PTR#0) }
  (byte*) main::ptr#0 ← (byte*~) main::$4
  (byte*) main::SCREEN#0 ← ((byte*)) (number) $400
  *((byte*) main::SCREEN#0) ← *((byte*) main::ptr#0)
  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
(void()) main()
(byte~) main::$0
(byte*~) main::$1
(byte~) main::$2
(byte*~) main::$3
(byte*~) main::$4
(const string) main::$5 = (string) "camelot"
(label) main::@return
(byte*) main::PTR
(byte*) main::PTR#0
(byte*) main::SCREEN
(byte*) main::SCREEN#0
(byte[]) main::STRING
(byte[]) main::STRING#0
(byte*) main::ptr
(byte*) main::ptr#0

Fixing inline constructor with main::$6 ← (byte)*(main::$3) w= (byte)*(main::PTR#0)
Successful SSA optimization Pass2FixInlineConstructorsNew
Adding number conversion cast (unumber) 1 in (byte*~) main::$1 ← (byte*) main::PTR#0 + (number) 1
Adding number conversion cast (unumber) 1 in (byte*~) main::$3 ← (byte*) main::PTR#0 + (number) 1
Successful SSA optimization PassNAddNumberTypeConversions
Inlining cast (byte*) main::PTR#0 ← (byte*)(number) $9ffe
Inlining cast (byte*) main::SCREEN#0 ← (byte*)(number) $400
Successful SSA optimization Pass2InlineCast
Simplifying constant pointer cast (byte*) 40958
Simplifying constant integer cast 1
Simplifying constant integer cast 1
Simplifying constant integer cast *((byte*~) main::$3)
Simplifying constant integer cast *((byte*) main::PTR#0)
Simplifying constant pointer cast (byte*) 1024
Successful SSA optimization PassNCastSimplification
Finalized unsigned number type (byte) 1
Finalized unsigned number type (byte) 1
Successful SSA optimization PassNFinalizeNumberTypeConversions
Adding pointer type conversion cast (byte*) main::$4 in (byte*~) main::$4 ← (word~) main::$6
Successful SSA optimization PassNAddTypeConversionAssignment
Alias (byte*) main::ptr#0 = (byte*~) main::$4 
Successful SSA optimization Pass2AliasElimination
Constant (const byte[]) main::STRING#0 = main::$5
Constant (const byte*) main::PTR#0 = (byte*) 40958
Constant (const byte*) main::SCREEN#0 = (byte*) 1024
Successful SSA optimization Pass2ConstantIdentification
Converting *(pointer+n) to pointer[n] [6] *((byte*~) main::$1) ← (byte~) main::$2  -- *(main::PTR#0 + 1)
Converting *(pointer+n) to pointer[n] [8] (word~) main::$6 ← *((byte*~) main::$3) w= *((const byte*) main::PTR#0)  -- *(main::PTR#0 + 1)
Successful SSA optimization Pass2InlineDerefIdx
Eliminating unused variable (byte*~) main::$1 and assignment [2] (byte*~) main::$1 ← (const byte*) main::PTR#0 + (byte) 1
Eliminating unused variable (byte*~) main::$3 and assignment [5] (byte*~) main::$3 ← (const byte*) main::PTR#0 + (byte) 1
Successful SSA optimization PassNEliminateUnusedVars
Inlining cast (byte*) main::ptr#0 ← (byte*)(word~) main::$6
Successful SSA optimization Pass2InlineCast
Constant right-side identified [0] (byte~) main::$0 ← < (const byte[]) main::STRING#0
Constant right-side identified [2] (byte~) main::$2 ← > (const byte[]) main::STRING#0
Successful SSA optimization Pass2ConstantRValueConsolidation
Constant (const byte) main::$0 = <main::STRING#0
Constant (const byte) main::$2 = >main::STRING#0
Successful SSA optimization Pass2ConstantIdentification
Inlining Noop Cast [3] (byte*) main::ptr#0 ← (byte*)(word~) main::$6 keeping main::ptr#0
Successful SSA optimization Pass2NopCastInlining
Constant inlined main::$5 = (const byte[]) main::STRING#0
Constant inlined main::$2 = >(const byte[]) main::STRING#0
Constant inlined main::$0 = <(const byte[]) main::STRING#0
Successful SSA optimization Pass2ConstantInlining
Consolidated array index constant in *(main::PTR#0+1)
Consolidated array index constant in *(main::PTR#0+1)
Successful SSA optimization Pass2ConstantAdditionElimination
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()
main: scope:[main]  from @1
  [4] *((const byte*) main::PTR#0) ← <(const byte[]) main::STRING#0
  [5] *((const byte*) main::PTR#0+(byte) 1) ← >(const byte[]) main::STRING#0
  [6] (word) main::ptr#0 ← *((const byte*) main::PTR#0+(byte) 1) w= *((const byte*) main::PTR#0)
  [7] *((const byte*) main::SCREEN#0) ← *((byte*)(word) main::ptr#0)
  to:main::@return
main::@return: scope:[main]  from main
  [8] return 
  to:@return


VARIABLE REGISTER WEIGHTS
(void()) main()
(byte*) main::PTR
(byte*) main::SCREEN
(byte[]) main::STRING
(byte*) main::ptr
(word) main::ptr#0 2.0

Initial phi equivalence classes
Added variable main::ptr#0 to zero page equivalence class [ main::ptr#0 ]
Complete equivalence classes
[ main::ptr#0 ]
Allocated zp ZP_WORD:2 [ main::ptr#0 ]

INITIAL ASM
  // File Comments
// Test assigning address of inline string to pointer
// The result should be an labelled .text in the ASM
// Erroneously tries to inline the string completely leading to a CompileError
  // Basic Upstart
.pc = $801 "Basic"
:BasicUpstart(bbegin)
.pc = $80d "Program"
  // Global Constants & labels
  // @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: {
    .label PTR = $9ffe
    .label SCREEN = $400
    .label ptr = 2
    // [4] *((const byte*) main::PTR#0) ← <(const byte[]) main::STRING#0 -- _deref_pbuc1=vbuc2 
    lda #<STRING
    sta PTR
    // [5] *((const byte*) main::PTR#0+(byte) 1) ← >(const byte[]) main::STRING#0 -- _deref_pbuc1=vbuc2 
    lda #>STRING
    sta PTR+1
    // [6] (word) main::ptr#0 ← *((const byte*) main::PTR#0+(byte) 1) w= *((const byte*) main::PTR#0) -- vwuz1=_deref_pbuc1_word__deref_pbuc2 
    lda PTR
    sta ptr
    lda PTR+1
    sta ptr+1
    // [7] *((const byte*) main::SCREEN#0) ← *((byte*)(word) main::ptr#0) -- _deref_pbuc1=_deref_pbuz1 
    ldy #0
    lda (ptr),y
    sta SCREEN
    jmp breturn
    // main::@return
  breturn:
    // [8] return 
    rts
    STRING: .text "camelot"
}
  // File Data

REGISTER UPLIFT POTENTIAL REGISTERS
Statement [4] *((const byte*) main::PTR#0) ← <(const byte[]) main::STRING#0 [ ] ( main:2 [ ] ) always clobbers reg byte a 
Statement [5] *((const byte*) main::PTR#0+(byte) 1) ← >(const byte[]) main::STRING#0 [ ] ( main:2 [ ] ) always clobbers reg byte a 
Statement [6] (word) main::ptr#0 ← *((const byte*) main::PTR#0+(byte) 1) w= *((const byte*) main::PTR#0) [ main::ptr#0 ] ( main:2 [ main::ptr#0 ] ) always clobbers reg byte a 
Statement [7] *((const byte*) main::SCREEN#0) ← *((byte*)(word) main::ptr#0) [ ] ( main:2 [ ] ) always clobbers reg byte a reg byte y 
Potential registers zp ZP_WORD:2 [ main::ptr#0 ] : zp ZP_WORD:2 , 

REGISTER UPLIFT SCOPES
Uplift Scope [main] 2: zp ZP_WORD:2 [ main::ptr#0 ] 
Uplift Scope [] 

Uplifting [main] best 58 combination zp ZP_WORD:2 [ main::ptr#0 ] 
Uplifting [] best 58 combination 

ASSEMBLER BEFORE OPTIMIZATION
  // File Comments
// Test assigning address of inline string to pointer
// The result should be an labelled .text in the ASM
// Erroneously tries to inline the string completely leading to a CompileError
  // Basic Upstart
.pc = $801 "Basic"
:BasicUpstart(bbegin)
.pc = $80d "Program"
  // Global Constants & labels
  // @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: {
    .label PTR = $9ffe
    .label SCREEN = $400
    .label ptr = 2
    // [4] *((const byte*) main::PTR#0) ← <(const byte[]) main::STRING#0 -- _deref_pbuc1=vbuc2 
    lda #<STRING
    sta PTR
    // [5] *((const byte*) main::PTR#0+(byte) 1) ← >(const byte[]) main::STRING#0 -- _deref_pbuc1=vbuc2 
    lda #>STRING
    sta PTR+1
    // [6] (word) main::ptr#0 ← *((const byte*) main::PTR#0+(byte) 1) w= *((const byte*) main::PTR#0) -- vwuz1=_deref_pbuc1_word__deref_pbuc2 
    lda PTR
    sta ptr
    lda PTR+1
    sta ptr+1
    // [7] *((const byte*) main::SCREEN#0) ← *((byte*)(word) main::ptr#0) -- _deref_pbuc1=_deref_pbuz1 
    ldy #0
    lda (ptr),y
    sta SCREEN
    jmp breturn
    // main::@return
  breturn:
    // [8] return 
    rts
    STRING: .text "camelot"
}
  // File Data

ASSEMBLER OPTIMIZATIONS
Removing instruction jmp b1
Removing instruction jmp bend
Removing instruction jmp breturn
Succesful ASM optimization Pass5NextJumpElimination
Removing instruction b1_from_bbegin:
Removing instruction b1:
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 bbegin:
Succesful ASM optimization Pass5UnusedLabelElimination

FINAL SYMBOL TABLE
(label) @1
(label) @begin
(label) @end
(void()) main()
(label) main::@return
(byte*) main::PTR
(const byte*) main::PTR#0 PTR = (byte*) 40958
(byte*) main::SCREEN
(const byte*) main::SCREEN#0 SCREEN = (byte*) 1024
(byte[]) main::STRING
(const byte[]) main::STRING#0 STRING = (string) "camelot"
(byte*) main::ptr
(word) main::ptr#0 ptr zp ZP_WORD:2 2.0

zp ZP_WORD:2 [ main::ptr#0 ]


FINAL ASSEMBLER
Score: 43

  // File Comments
// Test assigning address of inline string to pointer
// The result should be an labelled .text in the ASM
// Erroneously tries to inline the string completely leading to a CompileError
  // Basic Upstart
.pc = $801 "Basic"
:BasicUpstart(main)
.pc = $80d "Program"
  // Global Constants & labels
  // @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: {
    .label PTR = $9ffe
    .label SCREEN = $400
    .label ptr = 2
    // *PTR = <STRING
    // [4] *((const byte*) main::PTR#0) ← <(const byte[]) main::STRING#0 -- _deref_pbuc1=vbuc2 
    lda #<STRING
    sta PTR
    // *(PTR+1)= >STRING
    // [5] *((const byte*) main::PTR#0+(byte) 1) ← >(const byte[]) main::STRING#0 -- _deref_pbuc1=vbuc2 
    lda #>STRING
    sta PTR+1
    // (byte*) { *(PTR+1), *PTR }
    // [6] (word) main::ptr#0 ← *((const byte*) main::PTR#0+(byte) 1) w= *((const byte*) main::PTR#0) -- vwuz1=_deref_pbuc1_word__deref_pbuc2 
    lda PTR
    sta ptr
    lda PTR+1
    sta ptr+1
    // *SCREEN = *ptr
    // [7] *((const byte*) main::SCREEN#0) ← *((byte*)(word) main::ptr#0) -- _deref_pbuc1=_deref_pbuz1 
    ldy #0
    lda (ptr),y
    sta SCREEN
    // main::@return
    // }
    // [8] return 
    rts
    STRING: .text "camelot"
}
  // File Data

