Inlined call (byte~) vicSelectGfxBank::$0 ← call toDd00 (byte*) vicSelectGfxBank::gfx 
Culled Empty Block (label) @1
Culled Empty Block (label) @2
Culled Empty Block (label) @3
Culled Empty Block (label) @4

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

(void()) main()
main: scope:[main]  from @5
  *((const byte*) CIA2_PORT_B) ← *((const byte*) CIA2_PORT_B) & (number) $7f
  asm { lda#0  }
  (byte) main::port4Value#0 ← *((const byte*) CIA2_PORT_B)
  *((const byte*) SCREEN) ← (byte) main::port4Value#0
  to:main::@return
main::@return: scope:[main]  from main
  return 
  to:@return
@5: scope:[]  from @begin
  call main 
  to:@6
@6: scope:[]  from @5
  to:@end
@end: scope:[]  from @6

SYMBOL TABLE SSA
(label) @5
(label) @6
(label) @begin
(label) @end
(const byte*) CIA2_PORT_B = (byte*)(number) $dd01
(const byte*) SCREEN = (byte*)(number) $400
(void()) main()
(label) main::@return
(byte) main::port4Value
(byte) main::port4Value#0

Adding number conversion cast (unumber) $7f in *((const byte*) CIA2_PORT_B) ← *((const byte*) CIA2_PORT_B) & (number) $7f
Successful SSA optimization PassNAddNumberTypeConversions
Simplifying constant pointer cast (byte*) 56577
Simplifying constant pointer cast (byte*) 1024
Simplifying constant integer cast $7f
Successful SSA optimization PassNCastSimplification
Finalized unsigned number type (byte) $7f
Successful SSA optimization PassNFinalizeNumberTypeConversions
Adding NOP phi() at start of @begin
Adding NOP phi() at start of @5
Adding NOP phi() at start of @6
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) @6
Renumbering block @5 to @1
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*) CIA2_PORT_B) ← *((const byte*) CIA2_PORT_B) & (byte) $7f
  asm { lda#0  }
  [6] (byte) main::port4Value#0 ← *((const byte*) CIA2_PORT_B)
  [7] *((const byte*) SCREEN) ← (byte) main::port4Value#0
  to:main::@return
main::@return: scope:[main]  from main
  [8] return 
  to:@return


VARIABLE REGISTER WEIGHTS
(void()) main()
(byte) main::port4Value
(byte) main::port4Value#0 4.0

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

INITIAL ASM
Target platform is c64basic / MOS6502X
  // File Comments
// Tests problem writing/reading joystick encountered by Danny Spijksma
// https://www.protovision.games/hardw/build4player.php?language=en&fbclid=IwAR1MJLgQjOU0zVa0ax2aNeGa-xVbE9IGY9zC6b6eInTV4HQzoUAoCPoXu14
  // Upstart
.pc = $801 "Basic"
:BasicUpstart(__bbegin)
.pc = $80d "Program"
  // Global Constants & labels
  // CIA#2 Port B: RS-232
  .label CIA2_PORT_B = $dd01
  .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: {
    .label port4Value = 2
    // [4] *((const byte*) CIA2_PORT_B) ← *((const byte*) CIA2_PORT_B) & (byte) $7f -- _deref_pbuc1=_deref_pbuc1_band_vbuc2 
    lda #$7f
    and CIA2_PORT_B
    sta CIA2_PORT_B
    // asm { lda#0  }
    lda #0
    // [6] (byte) main::port4Value#0 ← *((const byte*) CIA2_PORT_B) -- vbuz1=_deref_pbuc1 
    lda CIA2_PORT_B
    sta.z port4Value
    // [7] *((const byte*) SCREEN) ← (byte) main::port4Value#0 -- _deref_pbuc1=vbuz1 
    lda.z port4Value
    sta SCREEN
    jmp __breturn
    // main::@return
  __breturn:
    // [8] return 
    rts
}
  // File Data

REGISTER UPLIFT POTENTIAL REGISTERS
Statement [4] *((const byte*) CIA2_PORT_B) ← *((const byte*) CIA2_PORT_B) & (byte) $7f [ ] ( main:2 [ ] ) always clobbers reg byte a 
Statement asm { lda#0  } always clobbers reg byte a 
Potential registers zp[1]:2 [ main::port4Value#0 ] : zp[1]:2 , reg byte a , reg byte x , reg byte y , 

REGISTER UPLIFT SCOPES
Uplift Scope [main] 4: zp[1]:2 [ main::port4Value#0 ] 
Uplift Scope [] 

Uplifting [main] best 41 combination reg byte a [ main::port4Value#0 ] 
Uplifting [] best 41 combination 

ASSEMBLER BEFORE OPTIMIZATION
  // File Comments
// Tests problem writing/reading joystick encountered by Danny Spijksma
// https://www.protovision.games/hardw/build4player.php?language=en&fbclid=IwAR1MJLgQjOU0zVa0ax2aNeGa-xVbE9IGY9zC6b6eInTV4HQzoUAoCPoXu14
  // Upstart
.pc = $801 "Basic"
:BasicUpstart(__bbegin)
.pc = $80d "Program"
  // Global Constants & labels
  // CIA#2 Port B: RS-232
  .label CIA2_PORT_B = $dd01
  .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*) CIA2_PORT_B) ← *((const byte*) CIA2_PORT_B) & (byte) $7f -- _deref_pbuc1=_deref_pbuc1_band_vbuc2 
    lda #$7f
    and CIA2_PORT_B
    sta CIA2_PORT_B
    // asm { lda#0  }
    lda #0
    // [6] (byte) main::port4Value#0 ← *((const byte*) CIA2_PORT_B) -- vbuaa=_deref_pbuc1 
    lda CIA2_PORT_B
    // [7] *((const byte*) SCREEN) ← (byte) main::port4Value#0 -- _deref_pbuc1=vbuaa 
    sta SCREEN
    jmp __breturn
    // main::@return
  __breturn:
    // [8] return 
    rts
}
  // File Data

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*) CIA2_PORT_B = (byte*) 56577
(const byte*) SCREEN = (byte*) 1024
(void()) main()
(label) main::@return
(byte) main::port4Value
(byte) main::port4Value#0 reg byte a 4.0

reg byte a [ main::port4Value#0 ]


FINAL ASSEMBLER
Score: 26

  // File Comments
// Tests problem writing/reading joystick encountered by Danny Spijksma
// https://www.protovision.games/hardw/build4player.php?language=en&fbclid=IwAR1MJLgQjOU0zVa0ax2aNeGa-xVbE9IGY9zC6b6eInTV4HQzoUAoCPoXu14
  // Upstart
.pc = $801 "Basic"
:BasicUpstart(main)
.pc = $80d "Program"
  // Global Constants & labels
  // CIA#2 Port B: RS-232
  .label CIA2_PORT_B = $dd01
  .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: {
    // (*CIA2_PORT_B) &= 0x7f
    // [4] *((const byte*) CIA2_PORT_B) ← *((const byte*) CIA2_PORT_B) & (byte) $7f -- _deref_pbuc1=_deref_pbuc1_band_vbuc2 
    lda #$7f
    and CIA2_PORT_B
    sta CIA2_PORT_B
    // asm
    // asm { lda#0  }
    lda #0
    // port4Value = *CIA2_PORT_B
    // [6] (byte) main::port4Value#0 ← *((const byte*) CIA2_PORT_B) -- vbuaa=_deref_pbuc1 
    lda CIA2_PORT_B
    // *SCREEN = port4Value
    // [7] *((const byte*) SCREEN) ← (byte) main::port4Value#0 -- _deref_pbuc1=vbuaa 
    sta SCREEN
    // main::@return
    // }
    // [8] return 
    rts
}
  // File Data

