
CONTROL FLOW GRAPH SSA

int main()
main: scope:[main]  from __start
  strTemp[2] = 'e'pm
  strTemp[3] = 0
  asm { ldy#0 loop: ldastrTemp,y beqdone jsr$FFD2 iny jmploop done:  }
  main::return#0 = 0
  to:main::@return
main::@return: scope:[main]  from main
  main::return#3 = phi( main/main::return#0 )
  main::return#1 = main::return#3
  return 
  to:@return

void __start()
__start: scope:[__start]  from
  call main
  main::return#2 = main::return#1
  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()
int main()
int main::return
int main::return#0
int main::return#1
int main::return#2
int main::return#3
__constant char strTemp[] = "v=X"pm

Adding number conversion cast (unumber) 2 in strTemp[2] = 'e'pm
Adding number conversion cast (unumber) 0 in strTemp[3] = 0
Adding number conversion cast (unumber) 3 in strTemp[3] = ((unumber)) 0
Adding number conversion cast (snumber) 0 in main::return#0 = 0
Successful SSA optimization PassNAddNumberTypeConversions
Inlining cast strTemp[(unumber)3] = (unumber)0
Inlining cast main::return#0 = (snumber)0
Successful SSA optimization Pass2InlineCast
Simplifying constant integer cast 2
Simplifying constant integer cast 0
Simplifying constant integer cast 3
Simplifying constant integer cast 0
Successful SSA optimization PassNCastSimplification
Finalized unsigned number type (char) 2
Finalized unsigned number type (char) 0
Finalized unsigned number type (char) 3
Finalized signed number type (signed char) 0
Successful SSA optimization PassNFinalizeNumberTypeConversions
Alias main::return#0 = main::return#3 main::return#1 
Successful SSA optimization Pass2AliasElimination
Constant main::return#0 = 0
Successful SSA optimization Pass2ConstantIdentification
Constant main::return#2 = main::return#0
Successful SSA optimization Pass2ConstantIdentification
Eliminating unused constant main::return#2
Successful SSA optimization PassNEliminateUnusedVars
Eliminating unused constant main::return#0
Successful SSA optimization PassNEliminateUnusedVars
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
Consolidated array index constant in *(strTemp+2)
Consolidated array index constant in *(strTemp+3)
Successful SSA optimization Pass2ConstantAdditionElimination
CALL GRAPH

Created 0 initial phi equivalence classes
Coalesced down to 0 phi equivalence classes

FINAL CONTROL FLOW GRAPH

int main()
main: scope:[main]  from
  [0] *(strTemp+2) = 'e'pm
  [1] *(strTemp+3) = 0
  asm { ldy#0 loop: ldastrTemp,y beqdone jsr$FFD2 iny jmploop done:  }
  to:main::@return
main::@return: scope:[main]  from main
  [3] return 
  to:@return


VARIABLE REGISTER WEIGHTS
int main()
int main::return

Initial phi equivalence classes
Complete equivalence classes
REGISTER UPLIFT POTENTIAL REGISTERS
Statement [0] *(strTemp+2) = 'e'pm [ ] (  [ ] { }  ) always clobbers reg byte a 
Statement [1] *(strTemp+3) = 0 [ ] (  [ ] { }  ) always clobbers reg byte a 
Statement asm { ldy#0 loop: ldastrTemp,y beqdone jsr$FFD2 iny jmploop done:  } always clobbers reg byte a reg byte x reg byte y 

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

Uplifting [main] best 41 combination 
Uplifting [] best 41 combination 

ASSEMBLER BEFORE OPTIMIZATION
  // File Comments
  // Upstart
  // Commodore 64 PRG executable file
.file [name="kc-ka-string-encoding.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: {
    // [0] *(strTemp+2) = 'e'pm -- _deref_pbuc1=vbuc2 
  .encoding "petscii_mixed"
    lda #'e'
    sta strTemp+2
    // [1] *(strTemp+3) = 0 -- _deref_pbuc1=vbuc2 
    lda #0
    sta strTemp+3
    // asm { ldy#0 loop: ldastrTemp,y beqdone jsr$FFD2 iny jmploop done:  }
    ldy #0
  loop:
    lda strTemp,y
    beq done
    jsr $ffd2
    iny
    jmp loop
  done:
    jmp __breturn
    // main::@return
  __breturn:
    // [3] return 
    rts
}
  // File Data
.segment Data
  strTemp: .text "v=X"
  .byte 0

ASSEMBLER OPTIMIZATIONS
Removing instruction jmp __breturn
Succesful ASM optimization Pass5NextJumpElimination
Replacing instruction ldy #0 with TAY
Removing instruction __breturn:
Succesful ASM optimization Pass5RedundantLabelElimination

FINAL SYMBOL TABLE
int main()
int main::return
__constant char strTemp[] = "v=X"pm



FINAL ASSEMBLER
Score: 38

  // File Comments
  // Upstart
  // Commodore 64 PRG executable file
.file [name="kc-ka-string-encoding.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: {
    // strTemp[2] = 'e'
    // [0] *(strTemp+2) = 'e'pm -- _deref_pbuc1=vbuc2 
  .encoding "petscii_mixed"
    lda #'e'
    sta strTemp+2
    // strTemp[3] = 0
    // [1] *(strTemp+3) = 0 -- _deref_pbuc1=vbuc2 
    lda #0
    sta strTemp+3
    // asm
    // asm { ldy#0 loop: ldastrTemp,y beqdone jsr$FFD2 iny jmploop done:  }
    tay
  loop:
    lda strTemp,y
    beq done
    jsr $ffd2
    iny
    jmp loop
  done:
    // main::@return
    // }
    // [3] return 
    rts
}
  // File Data
.segment Data
  strTemp: .text "v=X"
  .byte 0

