Culled Empty Block (label) @1
Culled Empty Block (label) first::@1

CONTROL FLOW GRAPH SSA
@begin: scope:[]  from
  (byte[]) msg1#0 ← (const string) $0
  (byte[]) msg2#0 ← (const string) $1
  to:@2
main: scope:[main]  from @2
  (byte*) main::SCREEN#0 ← ((byte*)) (number) $400
  (byte*) first::msg#0 ← (byte[]) msg1#0
  call first 
  (byte*) first::return#0 ← (byte*) first::return#3
  to:main::@1
main::@1: scope:[main]  from main
  (byte*) first::return#4 ← phi( main/(byte*) first::return#0 )
  (byte*~) main::$0 ← (byte*) first::return#4
  (byte*~) main::$1 ← (byte*~) main::$0 + (number) 0
  *((byte*) main::SCREEN#0 + (number) 0) ← *((byte*~) main::$1)
  (byte*) first::msg#1 ← (byte[]) msg2#0
  call first 
  (byte*) first::return#1 ← (byte*) first::return#3
  to:main::@2
main::@2: scope:[main]  from main::@1
  (byte*) first::return#5 ← phi( main::@1/(byte*) first::return#1 )
  (byte*~) main::$2 ← (byte*) first::return#5
  (byte*~) main::$3 ← (byte*~) main::$2 + (number) 0
  *((byte*) main::SCREEN#0 + (number) 1) ← *((byte*~) main::$3)
  to:main::@return
main::@return: scope:[main]  from main::@2
  return 
  to:@return
first: scope:[first]  from main main::@1
  (byte*) first::msg#2 ← phi( main/(byte*) first::msg#0 main::@1/(byte*) first::msg#1 )
  (byte*~) first::$0 ← (byte*) first::msg#2 + (number) 0
  (byte*~) first::$1 ← ((byte*)) (byte*~) first::$0
  (byte*) first::return#2 ← (byte*~) first::$1
  to:first::@return
first::@return: scope:[first]  from first
  (byte*) first::return#6 ← phi( first/(byte*) first::return#2 )
  (byte*) first::return#3 ← (byte*) first::return#6
  return 
  to:@return
@2: scope:[]  from @begin
  call main 
  to:@3
@3: scope:[]  from @2
  to:@end
@end: scope:[]  from @3

SYMBOL TABLE SSA
(const string) $0 = (string) "hello world!"
(const string) $1 = (string) "goodbye sky?"
(label) @2
(label) @3
(label) @begin
(label) @end
(byte*()) first((byte*) first::msg)
(byte*~) first::$0
(byte*~) first::$1
(label) first::@return
(byte*) first::msg
(byte*) first::msg#0
(byte*) first::msg#1
(byte*) first::msg#2
(byte*) first::return
(byte*) first::return#0
(byte*) first::return#1
(byte*) first::return#2
(byte*) first::return#3
(byte*) first::return#4
(byte*) first::return#5
(byte*) first::return#6
(void()) main()
(byte*~) main::$0
(byte*~) main::$1
(byte*~) main::$2
(byte*~) main::$3
(label) main::@1
(label) main::@2
(label) main::@return
(byte*) main::SCREEN
(byte*) main::SCREEN#0
(byte[]) msg1
(byte[]) msg1#0
(byte[]) msg2
(byte[]) msg2#0

Adding number conversion cast (unumber) 0 in (byte*~) main::$1 ← (byte*~) main::$0 + (number) 0
Adding number conversion cast (unumber) 0 in *((byte*) main::SCREEN#0 + (number) 0) ← *((byte*~) main::$1)
Adding number conversion cast (unumber) 0 in (byte*~) main::$3 ← (byte*~) main::$2 + (number) 0
Adding number conversion cast (unumber) 1 in *((byte*) main::SCREEN#0 + (number) 1) ← *((byte*~) main::$3)
Adding number conversion cast (unumber) 0 in (byte*~) first::$0 ← (byte*) first::msg#2 + (number) 0
Successful SSA optimization PassNAddNumberTypeConversions
Inlining cast (byte*) main::SCREEN#0 ← (byte*)(number) $400
Inlining cast (byte*~) first::$1 ← (byte*)(byte*~) first::$0
Successful SSA optimization Pass2InlineCast
Simplifying constant pointer cast (byte*) 1024
Simplifying constant integer cast 0
Simplifying constant integer cast 0
Simplifying constant integer cast 0
Simplifying constant integer cast 1
Simplifying constant integer cast 0
Simplifying constant integer cast (byte*~) first::$0
Successful SSA optimization PassNCastSimplification
Finalized unsigned number type (byte) 0
Finalized unsigned number type (byte) 0
Finalized unsigned number type (byte) 0
Finalized unsigned number type (byte) 1
Finalized unsigned number type (byte) 0
Successful SSA optimization PassNFinalizeNumberTypeConversions
Alias (byte*) first::return#0 = (byte*) first::return#4 
Alias (byte*) first::return#1 = (byte*) first::return#5 
Alias (byte*) first::return#2 = (byte*~) first::$1 (byte*~) first::$0 (byte*) first::return#6 (byte*) first::return#3 
Successful SSA optimization Pass2AliasElimination
Constant (const byte[]) msg1#0 = $0
Constant (const byte[]) msg2#0 = $1
Constant (const byte*) main::SCREEN#0 = (byte*) 1024
Successful SSA optimization Pass2ConstantIdentification
Constant (const byte*) first::msg#0 = msg1#0
Constant (const byte*) first::msg#1 = msg2#0
Successful SSA optimization Pass2ConstantIdentification
Converting *(pointer+n) to pointer[n] [9] *((const byte*) main::SCREEN#0 + (byte) 0) ← *((byte*~) main::$1)  -- *(main::$0 + 0)
Converting *(pointer+n) to pointer[n] [16] *((const byte*) main::SCREEN#0 + (byte) 1) ← *((byte*~) main::$3)  -- *(main::$2 + 0)
Successful SSA optimization Pass2InlineDerefIdx
Simplifying expression containing zero main::$0 in [8] (byte*~) main::$1 ← (byte*~) main::$0 + (byte) 0
Simplifying expression containing zero main::$0 in [9] *((const byte*) main::SCREEN#0 + (byte) 0) ← *((byte*~) main::$0 + (byte) 0)
Simplifying expression containing zero main::SCREEN#0 in [9] *((const byte*) main::SCREEN#0 + (byte) 0) ← *((byte*~) main::$0)
Simplifying expression containing zero main::$2 in [15] (byte*~) main::$3 ← (byte*~) main::$2 + (byte) 0
Simplifying expression containing zero main::$2 in [16] *((const byte*) main::SCREEN#0 + (byte) 1) ← *((byte*~) main::$2 + (byte) 0)
Simplifying expression containing zero first::msg#2 in [19] (byte*) first::return#2 ← (byte*) first::msg#2 + (byte) 0
Successful SSA optimization PassNSimplifyExpressionWithZero
Eliminating unused variable (byte*~) main::$1 and assignment [3] (byte*~) main::$1 ← (byte*~) main::$0
Eliminating unused variable (byte*~) main::$3 and assignment [8] (byte*~) main::$3 ← (byte*~) main::$2
Successful SSA optimization PassNEliminateUnusedVars
Alias (byte*) first::return#2 = (byte*) first::msg#2 
Successful SSA optimization Pass2AliasElimination
Constant inlined $0 = (const byte[]) msg1#0
Constant inlined $1 = (const byte[]) msg2#0
Constant inlined first::msg#0 = (const byte[]) msg1#0
Constant inlined first::msg#1 = (const byte[]) msg2#0
Successful SSA optimization Pass2ConstantInlining
Consolidated array index constant in *(main::SCREEN#0+1)
Successful SSA optimization Pass2ConstantAdditionElimination
Adding NOP phi() at start of @begin
Adding NOP phi() at start of @2
Adding NOP phi() at start of @3
Adding NOP phi() at start of @end
Adding NOP phi() at start of main
CALL GRAPH
Calls in [] to main:2 
Calls in [main] to first:6 first:10 

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

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] phi()
  [5] call first 
  [6] (byte*) first::return#0 ← (byte*) first::return#2
  to:main::@1
main::@1: scope:[main]  from main
  [7] (byte*~) main::$0 ← (byte*) first::return#0
  [8] *((const byte*) main::SCREEN#0) ← *((byte*~) main::$0)
  [9] call first 
  [10] (byte*) first::return#1 ← (byte*) first::return#2
  to:main::@2
main::@2: scope:[main]  from main::@1
  [11] (byte*~) main::$2 ← (byte*) first::return#1
  [12] *((const byte*) main::SCREEN#0+(byte) 1) ← *((byte*~) main::$2)
  to:main::@return
main::@return: scope:[main]  from main::@2
  [13] return 
  to:@return
first: scope:[first]  from main main::@1
  [14] (byte*) first::return#2 ← phi( main/(const byte[]) msg1#0 main::@1/(const byte[]) msg2#0 )
  to:first::@return
first::@return: scope:[first]  from first
  [15] return 
  to:@return


VARIABLE REGISTER WEIGHTS
(byte*()) first((byte*) first::msg)
(byte*) first::msg
(byte*) first::return
(byte*) first::return#0 4.0
(byte*) first::return#1 4.0
(byte*) first::return#2 1.0
(void()) main()
(byte*~) main::$0 4.0
(byte*~) main::$2 4.0
(byte*) main::SCREEN
(byte[]) msg1
(byte[]) msg2

Initial phi equivalence classes
[ first::return#2 ]
Added variable first::return#0 to zero page equivalence class [ first::return#0 ]
Added variable main::$0 to zero page equivalence class [ main::$0 ]
Added variable first::return#1 to zero page equivalence class [ first::return#1 ]
Added variable main::$2 to zero page equivalence class [ main::$2 ]
Complete equivalence classes
[ first::return#2 ]
[ first::return#0 ]
[ main::$0 ]
[ first::return#1 ]
[ main::$2 ]
Allocated zp ZP_WORD:2 [ first::return#2 ]
Allocated zp ZP_WORD:4 [ first::return#0 ]
Allocated zp ZP_WORD:6 [ main::$0 ]
Allocated zp ZP_WORD:8 [ first::return#1 ]
Allocated zp ZP_WORD:10 [ main::$2 ]

INITIAL ASM
Target platform is c64basic
  // File Comments
// Tests pointer plus 0 elimination
  // 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 
  // [4] phi from @1 to main [phi:@1->main]
main_from_b1:
  jsr main
  // [3] phi from @1 to @end [phi:@1->@end]
bend_from_b1:
  jmp bend
  // @end
bend:
  // main
main: {
    .label SCREEN = $400
    .label _0 = 6
    .label _2 = $a
    // [5] call first 
    // [14] phi from main to first [phi:main->first]
  first_from_main:
    // [14] phi (byte*) first::return#2 = (const byte[]) msg1#0 [phi:main->first#0] -- pbuz1=pbuc1 
    lda #<msg1
    sta.z first.return_2
    lda #>msg1
    sta.z first.return_2+1
    jsr first
    // [6] (byte*) first::return#0 ← (byte*) first::return#2 -- pbuz1=pbuz2 
    lda.z first.return_2
    sta.z first.return
    lda.z first.return_2+1
    sta.z first.return+1
    jmp b1
    // main::@1
  b1:
    // [7] (byte*~) main::$0 ← (byte*) first::return#0 -- pbuz1=pbuz2 
    lda.z first.return
    sta.z _0
    lda.z first.return+1
    sta.z _0+1
    // [8] *((const byte*) main::SCREEN#0) ← *((byte*~) main::$0) -- _deref_pbuc1=_deref_pbuz1 
    ldy #0
    lda (_0),y
    sta SCREEN
    // [9] call first 
    // [14] phi from main::@1 to first [phi:main::@1->first]
  first_from_b1:
    // [14] phi (byte*) first::return#2 = (const byte[]) msg2#0 [phi:main::@1->first#0] -- pbuz1=pbuc1 
    lda #<msg2
    sta.z first.return_2
    lda #>msg2
    sta.z first.return_2+1
    jsr first
    // [10] (byte*) first::return#1 ← (byte*) first::return#2 -- pbuz1=pbuz2 
    lda.z first.return_2
    sta.z first.return_1
    lda.z first.return_2+1
    sta.z first.return_1+1
    jmp b2
    // main::@2
  b2:
    // [11] (byte*~) main::$2 ← (byte*) first::return#1 -- pbuz1=pbuz2 
    lda.z first.return_1
    sta.z _2
    lda.z first.return_1+1
    sta.z _2+1
    // [12] *((const byte*) main::SCREEN#0+(byte) 1) ← *((byte*~) main::$2) -- _deref_pbuc1=_deref_pbuz1 
    ldy #0
    lda (_2),y
    sta SCREEN+1
    jmp breturn
    // main::@return
  breturn:
    // [13] return 
    rts
}
  // first
first: {
    .label return = 4
    .label return_1 = 8
    .label return_2 = 2
    jmp breturn
    // first::@return
  breturn:
    // [15] return 
    rts
}
  // File Data
  msg1: .text "hello world!"
  .byte 0
  msg2: .text "goodbye sky?"
  .byte 0

REGISTER UPLIFT POTENTIAL REGISTERS
Statement [6] (byte*) first::return#0 ← (byte*) first::return#2 [ first::return#0 ] ( main:2 [ first::return#0 ] ) always clobbers reg byte a 
Statement [7] (byte*~) main::$0 ← (byte*) first::return#0 [ main::$0 ] ( main:2 [ main::$0 ] ) always clobbers reg byte a 
Statement [8] *((const byte*) main::SCREEN#0) ← *((byte*~) main::$0) [ ] ( main:2 [ ] ) always clobbers reg byte a reg byte y 
Statement [10] (byte*) first::return#1 ← (byte*) first::return#2 [ first::return#1 ] ( main:2 [ first::return#1 ] ) always clobbers reg byte a 
Statement [11] (byte*~) main::$2 ← (byte*) first::return#1 [ main::$2 ] ( main:2 [ main::$2 ] ) always clobbers reg byte a 
Statement [12] *((const byte*) main::SCREEN#0+(byte) 1) ← *((byte*~) main::$2) [ ] ( main:2 [ ] ) always clobbers reg byte a reg byte y 
Potential registers zp ZP_WORD:2 [ first::return#2 ] : zp ZP_WORD:2 , 
Potential registers zp ZP_WORD:4 [ first::return#0 ] : zp ZP_WORD:4 , 
Potential registers zp ZP_WORD:6 [ main::$0 ] : zp ZP_WORD:6 , 
Potential registers zp ZP_WORD:8 [ first::return#1 ] : zp ZP_WORD:8 , 
Potential registers zp ZP_WORD:10 [ main::$2 ] : zp ZP_WORD:10 , 

REGISTER UPLIFT SCOPES
Uplift Scope [first] 4: zp ZP_WORD:4 [ first::return#0 ] 4: zp ZP_WORD:8 [ first::return#1 ] 1: zp ZP_WORD:2 [ first::return#2 ] 
Uplift Scope [main] 4: zp ZP_WORD:6 [ main::$0 ] 4: zp ZP_WORD:10 [ main::$2 ] 
Uplift Scope [] 

Uplifting [first] best 165 combination zp ZP_WORD:4 [ first::return#0 ] zp ZP_WORD:8 [ first::return#1 ] zp ZP_WORD:2 [ first::return#2 ] 
Uplifting [main] best 165 combination zp ZP_WORD:6 [ main::$0 ] zp ZP_WORD:10 [ main::$2 ] 
Uplifting [] best 165 combination 
Coalescing zero page register [ zp ZP_WORD:2 [ first::return#2 ] ] with [ zp ZP_WORD:4 [ first::return#0 ] ] - score: 1
Coalescing zero page register [ zp ZP_WORD:2 [ first::return#2 first::return#0 ] ] with [ zp ZP_WORD:8 [ first::return#1 ] ] - score: 1
Coalescing zero page register [ zp ZP_WORD:2 [ first::return#2 first::return#0 first::return#1 ] ] with [ zp ZP_WORD:6 [ main::$0 ] ] - score: 1
Coalescing zero page register [ zp ZP_WORD:2 [ first::return#2 first::return#0 first::return#1 main::$0 ] ] with [ zp ZP_WORD:10 [ main::$2 ] ] - score: 1

ASSEMBLER BEFORE OPTIMIZATION
  // File Comments
// Tests pointer plus 0 elimination
  // 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 
  // [4] phi from @1 to main [phi:@1->main]
main_from_b1:
  jsr main
  // [3] phi from @1 to @end [phi:@1->@end]
bend_from_b1:
  jmp bend
  // @end
bend:
  // main
main: {
    .label SCREEN = $400
    .label _0 = 2
    .label _2 = 2
    // [5] call first 
    // [14] phi from main to first [phi:main->first]
  first_from_main:
    // [14] phi (byte*) first::return#2 = (const byte[]) msg1#0 [phi:main->first#0] -- pbuz1=pbuc1 
    lda #<msg1
    sta.z first.return
    lda #>msg1
    sta.z first.return+1
    jsr first
    // [6] (byte*) first::return#0 ← (byte*) first::return#2
    jmp b1
    // main::@1
  b1:
    // [7] (byte*~) main::$0 ← (byte*) first::return#0
    // [8] *((const byte*) main::SCREEN#0) ← *((byte*~) main::$0) -- _deref_pbuc1=_deref_pbuz1 
    ldy #0
    lda (_0),y
    sta SCREEN
    // [9] call first 
    // [14] phi from main::@1 to first [phi:main::@1->first]
  first_from_b1:
    // [14] phi (byte*) first::return#2 = (const byte[]) msg2#0 [phi:main::@1->first#0] -- pbuz1=pbuc1 
    lda #<msg2
    sta.z first.return
    lda #>msg2
    sta.z first.return+1
    jsr first
    // [10] (byte*) first::return#1 ← (byte*) first::return#2
    jmp b2
    // main::@2
  b2:
    // [11] (byte*~) main::$2 ← (byte*) first::return#1
    // [12] *((const byte*) main::SCREEN#0+(byte) 1) ← *((byte*~) main::$2) -- _deref_pbuc1=_deref_pbuz1 
    ldy #0
    lda (_2),y
    sta SCREEN+1
    jmp breturn
    // main::@return
  breturn:
    // [13] return 
    rts
}
  // first
first: {
    .label return = 2
    jmp breturn
    // first::@return
  breturn:
    // [15] return 
    rts
}
  // File Data
  msg1: .text "hello world!"
  .byte 0
  msg2: .text "goodbye sky?"
  .byte 0

ASSEMBLER OPTIMIZATIONS
Removing instruction jmp b1
Removing instruction jmp bend
Removing instruction jmp b1
Removing instruction jmp b2
Removing instruction jmp breturn
Removing instruction jmp breturn
Succesful ASM optimization Pass5NextJumpElimination
Removing instruction b1_from_bbegin:
Removing instruction b1:
Removing instruction main_from_b1:
Removing instruction bend_from_b1:
Succesful ASM optimization Pass5RedundantLabelElimination
Removing instruction bend:
Removing instruction first_from_main:
Removing instruction b1:
Removing instruction first_from_b1:
Removing instruction b2:
Removing instruction breturn:
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
(byte*()) first((byte*) first::msg)
(label) first::@return
(byte*) first::msg
(byte*) first::return
(byte*) first::return#0 return zp ZP_WORD:2 4.0
(byte*) first::return#1 return zp ZP_WORD:2 4.0
(byte*) first::return#2 return zp ZP_WORD:2 1.0
(void()) main()
(byte*~) main::$0 $0 zp ZP_WORD:2 4.0
(byte*~) main::$2 $2 zp ZP_WORD:2 4.0
(label) main::@1
(label) main::@2
(label) main::@return
(byte*) main::SCREEN
(const byte*) main::SCREEN#0 SCREEN = (byte*) 1024
(byte[]) msg1
(const byte[]) msg1#0 msg1 = (string) "hello world!"
(byte[]) msg2
(const byte[]) msg2#0 msg2 = (string) "goodbye sky?"

zp ZP_WORD:2 [ first::return#2 first::return#0 first::return#1 main::$0 main::$2 ]


FINAL ASSEMBLER
Score: 66

  // File Comments
// Tests pointer plus 0 elimination
  // 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 
  // [4] phi from @1 to main [phi:@1->main]
  // [3] phi from @1 to @end [phi:@1->@end]
  // @end
  // main
main: {
    .label SCREEN = $400
    .label _0 = 2
    .label _2 = 2
    // first(msg1)
    // [5] call first 
    // [14] phi from main to first [phi:main->first]
    // [14] phi (byte*) first::return#2 = (const byte[]) msg1#0 [phi:main->first#0] -- pbuz1=pbuc1 
    lda #<msg1
    sta.z first.return
    lda #>msg1
    sta.z first.return+1
    jsr first
    // first(msg1)
    // [6] (byte*) first::return#0 ← (byte*) first::return#2
    // main::@1
    // [7] (byte*~) main::$0 ← (byte*) first::return#0
    // SCREEN[0] = *(first(msg1)+0)
    // [8] *((const byte*) main::SCREEN#0) ← *((byte*~) main::$0) -- _deref_pbuc1=_deref_pbuz1 
    ldy #0
    lda (_0),y
    sta SCREEN
    // first(msg2)
    // [9] call first 
    // [14] phi from main::@1 to first [phi:main::@1->first]
    // [14] phi (byte*) first::return#2 = (const byte[]) msg2#0 [phi:main::@1->first#0] -- pbuz1=pbuc1 
    lda #<msg2
    sta.z first.return
    lda #>msg2
    sta.z first.return+1
    jsr first
    // first(msg2)
    // [10] (byte*) first::return#1 ← (byte*) first::return#2
    // main::@2
    // [11] (byte*~) main::$2 ← (byte*) first::return#1
    // SCREEN[1] = *(first(msg2)+0)
    // [12] *((const byte*) main::SCREEN#0+(byte) 1) ← *((byte*~) main::$2) -- _deref_pbuc1=_deref_pbuz1 
    ldy #0
    lda (_2),y
    sta SCREEN+1
    // main::@return
    // }
    // [13] return 
    rts
}
  // first
first: {
    .label return = 2
    // first::@return
    // [15] return 
    rts
}
  // File Data
  msg1: .text "hello world!"
  .byte 0
  msg2: .text "goodbye sky?"
  .byte 0

