Culled Empty Block (label) main::@1
Culled Empty Block (label) main::@4

CONTROL FLOW GRAPH SSA
@begin: scope:[]  from
  (byte) key#0 ← (byte) 0
  to:@1

(void()) main()
main: scope:[main]  from @1
  to:main::@2
main::@2: scope:[main]  from main main::@2 main::@3
  (byte) key#1 ← *((const byte*) DC00)
  (bool~) main::$0 ← (byte) key#1 == (number) 0
  (number~) main::$1 ← (byte) key#1 & (number) $1f
  (bool~) main::$2 ← (number~) main::$1 == (number) $1f
  (bool~) main::$3 ← (bool~) main::$0 && (bool~) main::$2
  if((bool~) main::$3) goto main::@2
  to:main::@3
main::@3: scope:[main]  from main::@2
  (byte) key#6 ← phi( main::@2/(byte) key#1 )
  if(true) goto main::@2
  to:main::@return
main::@return: scope:[main]  from main::@3
  (byte) key#4 ← phi( main::@3/(byte) key#6 )
  (byte) key#2 ← (byte) key#4
  return 
  to:@return
@1: scope:[]  from @begin
  (byte) key#7 ← phi( @begin/(byte) key#0 )
  call main 
  to:@2
@2: scope:[]  from @1
  (byte) key#5 ← phi( @1/(byte) key#2 )
  (byte) key#3 ← (byte) key#5
  to:@end
@end: scope:[]  from @2

SYMBOL TABLE SSA
(label) @1
(label) @2
(label) @begin
(label) @end
(const byte*) DC00 = (byte*)(number) $dc00
(byte) key
(byte) key#0
(byte) key#1
(byte) key#2
(byte) key#3
(byte) key#4
(byte) key#5
(byte) key#6
(byte) key#7
(void()) main()
(bool~) main::$0
(number~) main::$1
(bool~) main::$2
(bool~) main::$3
(label) main::@2
(label) main::@3
(label) main::@return

Adding number conversion cast (unumber) 0 in (bool~) main::$0 ← (byte) key#1 == (number) 0
Adding number conversion cast (unumber) $1f in (number~) main::$1 ← (byte) key#1 & (number) $1f
Adding number conversion cast (unumber) main::$1 in (number~) main::$1 ← (byte) key#1 & (unumber)(number) $1f
Adding number conversion cast (unumber) $1f in (bool~) main::$2 ← (unumber~) main::$1 == (number) $1f
Successful SSA optimization PassNAddNumberTypeConversions
Simplifying constant pointer cast (byte*) 56320
Simplifying constant integer cast 0
Simplifying constant integer cast $1f
Simplifying constant integer cast $1f
Successful SSA optimization PassNCastSimplification
Finalized unsigned number type (byte) 0
Finalized unsigned number type (byte) $1f
Finalized unsigned number type (byte) $1f
Successful SSA optimization PassNFinalizeNumberTypeConversions
Inferred type updated to byte in (unumber~) main::$1 ← (byte) key#1 & (byte) $1f
Alias (byte) key#1 = (byte) key#6 (byte) key#4 (byte) key#2 
Alias (byte) key#0 = (byte) key#7 
Alias (byte) key#3 = (byte) key#5 
Successful SSA optimization Pass2AliasElimination
Identical Phi Values (byte) key#3 (byte) key#1
Successful SSA optimization Pass2IdenticalPhiElimination
Rewriting && if()-condition to two if()s [5] (bool~) main::$3 ← (bool~) main::$0 && (bool~) main::$2
Successful SSA optimization Pass2ConditionalAndOrRewriting
Constant (const byte) key#0 = 0
Successful SSA optimization Pass2ConstantIdentification
if() condition always true - replacing block destination [8] if(true) goto main::@2
Successful SSA optimization Pass2ConstantIfs
Eliminating unused constant (const byte) key#0
Successful SSA optimization PassNEliminateUnusedVars
Removing unused block main::@return
Successful SSA optimization Pass2EliminateUnusedBlocks
Simple Condition (bool~) main::$0 [4] if((byte) key#1==(byte) 0) goto main::@5
Simple Condition (bool~) main::$2 [6] if((byte~) main::$1==(byte) $1f) goto main::@2
Successful SSA optimization Pass2ConditionalJumpSimplification
Negating conditional jump and destination [4] if((byte) key#1!=(byte) 0) goto main::@3
Successful SSA optimization Pass2ConditionalJumpSequenceImprovement
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
Adding NOP phi() at start of main
Adding NOP phi() at start of main::@3
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
Renumbering block main::@2 to main::@1
Renumbering block main::@3 to main::@2
Renumbering block main::@5 to main::@3
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
Adding NOP phi() at start of main::@2

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] phi()
  to:main::@1
main::@1: scope:[main]  from main main::@2 main::@3
  [5] (byte) key#1 ← *((const byte*) DC00)
  [6] (byte~) main::$1 ← (byte) key#1 & (byte) $1f
  [7] if((byte) key#1!=(byte) 0) goto main::@2
  to:main::@3
main::@3: scope:[main]  from main::@1
  [8] if((byte~) main::$1==(byte) $1f) goto main::@1
  to:main::@2
main::@2: scope:[main]  from main::@1 main::@3
  [9] phi()
  to:main::@1


VARIABLE REGISTER WEIGHTS
(byte) key
(byte) key#1 151.5
(void()) main()
(byte~) main::$1 101.0

Initial phi equivalence classes
Added variable key#1 to live range equivalence class [ key#1 ]
Added variable main::$1 to live range equivalence class [ main::$1 ]
Complete equivalence classes
[ key#1 ]
[ main::$1 ]
Allocated zp[1]:2 [ key#1 ]
Allocated zp[1]:3 [ main::$1 ]

INITIAL ASM
Target platform is c64basic / MOS6502X
  // File Comments
// Duplicate Loop Problem from Richard-William Loerakker
// Resulted in infinite loop in loop depth analysis
  // Upstart
.pc = $801 "Basic"
:BasicUpstart(__bbegin)
.pc = $80d "Program"
  // Global Constants & labels
  .label DC00 = $dc00
  .label key = 2
  // @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 __1 = 3
    jmp __b1
    // main::@1
  __b1:
    // [5] (byte) key#1 ← *((const byte*) DC00) -- vbuz1=_deref_pbuc1 
    lda DC00
    sta.z key
    // [6] (byte~) main::$1 ← (byte) key#1 & (byte) $1f -- vbuz1=vbuz2_band_vbuc1 
    lda #$1f
    and.z key
    sta.z __1
    // [7] if((byte) key#1!=(byte) 0) goto main::@2 -- vbuz1_neq_0_then_la1 
    lda.z key
    cmp #0
    bne __b2_from___b1
    jmp __b3
    // main::@3
  __b3:
    // [8] if((byte~) main::$1==(byte) $1f) goto main::@1 -- vbuz1_eq_vbuc1_then_la1 
    lda #$1f
    cmp.z __1
    beq __b1
    // [9] phi from main::@1 main::@3 to main::@2 [phi:main::@1/main::@3->main::@2]
  __b2_from___b1:
  __b2_from___b3:
    jmp __b2
    // main::@2
  __b2:
    jmp __b1
}
  // File Data

REGISTER UPLIFT POTENTIAL REGISTERS
Potential registers zp[1]:2 [ key#1 ] : zp[1]:2 , reg byte a , reg byte x , reg byte y , 
Potential registers zp[1]:3 [ main::$1 ] : zp[1]:3 , reg byte a , reg byte x , reg byte y , 

REGISTER UPLIFT SCOPES
Uplift Scope [] 151.5: zp[1]:2 [ key#1 ] 
Uplift Scope [main] 101: zp[1]:3 [ main::$1 ] 

Uplifting [] best 2502 combination reg byte x [ key#1 ] 
Uplifting [main] best 2102 combination reg byte a [ main::$1 ] 

ASSEMBLER BEFORE OPTIMIZATION
  // File Comments
// Duplicate Loop Problem from Richard-William Loerakker
// Resulted in infinite loop in loop depth analysis
  // Upstart
.pc = $801 "Basic"
:BasicUpstart(__bbegin)
.pc = $80d "Program"
  // Global Constants & labels
  .label DC00 = $dc00
  // @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: {
    jmp __b1
    // main::@1
  __b1:
    // [5] (byte) key#1 ← *((const byte*) DC00) -- vbuxx=_deref_pbuc1 
    ldx DC00
    // [6] (byte~) main::$1 ← (byte) key#1 & (byte) $1f -- vbuaa=vbuxx_band_vbuc1 
    txa
    and #$1f
    // [7] if((byte) key#1!=(byte) 0) goto main::@2 -- vbuxx_neq_0_then_la1 
    cpx #0
    bne __b2_from___b1
    jmp __b3
    // main::@3
  __b3:
    // [8] if((byte~) main::$1==(byte) $1f) goto main::@1 -- vbuaa_eq_vbuc1_then_la1 
    cmp #$1f
    beq __b1
    // [9] phi from main::@1 main::@3 to main::@2 [phi:main::@1/main::@3->main::@2]
  __b2_from___b1:
  __b2_from___b3:
    jmp __b2
    // main::@2
  __b2:
    jmp __b1
}
  // File Data

ASSEMBLER OPTIMIZATIONS
Removing instruction jmp __b1
Removing instruction jmp __bend
Removing instruction jmp __b1
Removing instruction jmp __b3
Removing instruction jmp __b2
Succesful ASM optimization Pass5NextJumpElimination
Replacing label __bbegin with __b1
Replacing label __b2_from___b1 with __b2
Removing instruction __bbegin:
Removing instruction __b1_from___bbegin:
Removing instruction main_from___b1:
Removing instruction __bend_from___b1:
Removing instruction __b2_from___b1:
Removing instruction __b2_from___b3:
Succesful ASM optimization Pass5RedundantLabelElimination
Removing instruction __bend:
Removing instruction __b3:
Succesful ASM optimization Pass5UnusedLabelElimination
Updating BasicUpstart to call main directly
Removing instruction jsr main
Succesful ASM optimization Pass5SkipBegin
Skipping double jump to __b1 in bne __b2
Succesful ASM optimization Pass5DoubleJumpElimination
Removing instruction __b1:
Removing instruction __b2:
Succesful ASM optimization Pass5UnusedLabelElimination

FINAL SYMBOL TABLE
(label) @1
(label) @begin
(label) @end
(const byte*) DC00 = (byte*) 56320
(byte) key
(byte) key#1 reg byte x 151.5
(void()) main()
(byte~) main::$1 reg byte a 101.0
(label) main::@1
(label) main::@2
(label) main::@3

reg byte x [ key#1 ]
reg byte a [ main::$1 ]


FINAL ASSEMBLER
Score: 1730

  // File Comments
// Duplicate Loop Problem from Richard-William Loerakker
// Resulted in infinite loop in loop depth analysis
  // Upstart
.pc = $801 "Basic"
:BasicUpstart(main)
.pc = $80d "Program"
  // Global Constants & labels
  .label DC00 = $dc00
  // @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: {
    // main::@1
  __b1:
    // key = *DC00
    // [5] (byte) key#1 ← *((const byte*) DC00) -- vbuxx=_deref_pbuc1 
    ldx DC00
    // key & %00011111
    // [6] (byte~) main::$1 ← (byte) key#1 & (byte) $1f -- vbuaa=vbuxx_band_vbuc1 
    txa
    and #$1f
    // while(key == 0 && ((key & %00011111) == %00011111))
    // [7] if((byte) key#1!=(byte) 0) goto main::@2 -- vbuxx_neq_0_then_la1 
    cpx #0
    bne __b1
    // main::@3
    // [8] if((byte~) main::$1==(byte) $1f) goto main::@1 -- vbuaa_eq_vbuc1_then_la1 
    cmp #$1f
    beq __b1
    // [9] phi from main::@1 main::@3 to main::@2 [phi:main::@1/main::@3->main::@2]
    // main::@2
    jmp __b1
}
  // File Data

