Inlined call vicSelectGfxBank::$0 = call toDd00(vicSelectGfxBank::gfx)
Inlined call call __init
Eliminating unused variable with no statement keyboard_matrix_read::$0
Eliminating unused variable with no statement keyboard_key_pressed::$0
Eliminating unused variable with no statement keyboard_key_pressed::$1
Eliminating unused variable with no statement main::$3
Eliminating unused variable with no statement main::$11

CONTROL FLOW GRAPH SSA

void keyboard_init()
keyboard_init: scope:[keyboard_init]  from main::@3
  *((char *)CIA1+OFFSET_STRUCT_MOS6526_CIA_PORT_A_DDR) = $ff
  *((char *)CIA1+OFFSET_STRUCT_MOS6526_CIA_PORT_B_DDR) = 0
  to:keyboard_init::@return
keyboard_init::@return: scope:[keyboard_init]  from keyboard_init
  return 
  to:@return

char keyboard_matrix_read(char rowid)
keyboard_matrix_read: scope:[keyboard_matrix_read]  from keyboard_key_pressed main::@7
  keyboard_matrix_read::rowid#2 = phi( keyboard_key_pressed/keyboard_matrix_read::rowid#0, main::@7/keyboard_matrix_read::rowid#1 )
  *((char *)CIA1+OFFSET_STRUCT_MOS6526_CIA_PORT_A) = keyboard_matrix_row_bitmask[keyboard_matrix_read::rowid#2]
  keyboard_matrix_read::row_pressed_bits#0 = ~ *((char *)CIA1+OFFSET_STRUCT_MOS6526_CIA_PORT_B)
  keyboard_matrix_read::return#0 = keyboard_matrix_read::row_pressed_bits#0
  to:keyboard_matrix_read::@return
keyboard_matrix_read::@return: scope:[keyboard_matrix_read]  from keyboard_matrix_read
  keyboard_matrix_read::return#4 = phi( keyboard_matrix_read/keyboard_matrix_read::return#0 )
  keyboard_matrix_read::return#1 = keyboard_matrix_read::return#4
  return 
  to:@return

char keyboard_key_pressed(char key)
keyboard_key_pressed: scope:[keyboard_key_pressed]  from main::@16
  keyboard_key_pressed::key#1 = phi( main::@16/keyboard_key_pressed::key#0 )
  keyboard_key_pressed::colidx#0 = keyboard_key_pressed::key#1 & 7
  keyboard_key_pressed::rowidx#0 = keyboard_key_pressed::key#1 >> 3
  keyboard_matrix_read::rowid#0 = keyboard_key_pressed::rowidx#0
  call keyboard_matrix_read
  keyboard_matrix_read::return#2 = keyboard_matrix_read::return#1
  to:keyboard_key_pressed::@1
keyboard_key_pressed::@1: scope:[keyboard_key_pressed]  from keyboard_key_pressed
  keyboard_key_pressed::colidx#1 = phi( keyboard_key_pressed/keyboard_key_pressed::colidx#0 )
  keyboard_matrix_read::return#5 = phi( keyboard_key_pressed/keyboard_matrix_read::return#2 )
  keyboard_key_pressed::$2 = keyboard_matrix_read::return#5
  keyboard_key_pressed::$3 = keyboard_key_pressed::$2 & keyboard_matrix_col_bitmask[keyboard_key_pressed::colidx#1]
  keyboard_key_pressed::return#0 = keyboard_key_pressed::$3
  to:keyboard_key_pressed::@return
keyboard_key_pressed::@return: scope:[keyboard_key_pressed]  from keyboard_key_pressed::@1
  keyboard_key_pressed::return#3 = phi( keyboard_key_pressed::@1/keyboard_key_pressed::return#0 )
  keyboard_key_pressed::return#1 = keyboard_key_pressed::return#3
  return 
  to:@return

char keyboard_get_keycode(char ch)
keyboard_get_keycode: scope:[keyboard_get_keycode]  from main::@14
  keyboard_get_keycode::ch#1 = phi( main::@14/keyboard_get_keycode::ch#0 )
  keyboard_get_keycode::return#0 = keyboard_char_keycodes[keyboard_get_keycode::ch#1]
  to:keyboard_get_keycode::@return
keyboard_get_keycode::@return: scope:[keyboard_get_keycode]  from keyboard_get_keycode
  keyboard_get_keycode::return#3 = phi( keyboard_get_keycode/keyboard_get_keycode::return#0 )
  keyboard_get_keycode::return#1 = keyboard_get_keycode::return#3
  return 
  to:@return

void main()
main: scope:[main]  from __start::@1
  main::sc#0 = (char *)$400
  to:main::@1
main::@1: scope:[main]  from main main::@2
  main::sc#2 = phi( main/main::sc#0, main::@2/main::sc#1 )
  main::$1 = main::sc#2 < $400+$3e8
  if(main::$1) goto main::@2
  to:main::@3
main::@2: scope:[main]  from main::@1
  main::sc#3 = phi( main::@1/main::sc#2 )
  *main::sc#3 = ' '
  main::sc#1 = ++ main::sc#3
  to:main::@1
main::@3: scope:[main]  from main::@1
  call keyboard_init
  to:main::@19
main::@19: scope:[main]  from main::@3
  to:main::@4
main::@4: scope:[main]  from main::@18 main::@19
  if(true) goto main::@5
  to:main::@return
main::@5: scope:[main]  from main::@4 main::@5
  main::$2 = *RASTER != $ff
  if(main::$2) goto main::@5
  to:main::@6
main::@6: scope:[main]  from main::@5
  main::screen#0 = (char *)$400
  main::row#0 = 0
  to:main::@7
main::@7: scope:[main]  from main::@12 main::@6
  main::screen#16 = phi( main::@12/main::screen#1, main::@6/main::screen#0 )
  main::row#2 = phi( main::@12/main::row#1, main::@6/main::row#0 )
  keyboard_matrix_read::rowid#1 = main::row#2
  call keyboard_matrix_read
  keyboard_matrix_read::return#3 = keyboard_matrix_read::return#1
  to:main::@20
main::@20: scope:[main]  from main::@7
  main::row#8 = phi( main::@7/main::row#2 )
  main::screen#13 = phi( main::@7/main::screen#16 )
  keyboard_matrix_read::return#6 = phi( main::@7/keyboard_matrix_read::return#3 )
  main::row_pressed_bits#0 = keyboard_matrix_read::return#6
  main::col#0 = 0
  to:main::@8
main::@8: scope:[main]  from main::@10 main::@20
  main::row#7 = phi( main::@10/main::row#4, main::@20/main::row#8 )
  main::col#5 = phi( main::@10/main::col#1, main::@20/main::col#0 )
  main::screen#9 = phi( main::@10/main::screen#10, main::@20/main::screen#13 )
  main::row_pressed_bits#2 = phi( main::@10/main::row_pressed_bits#1, main::@20/main::row_pressed_bits#0 )
  main::$4 = main::row_pressed_bits#2 & $80
  main::$5 = main::$4 != 0
  if(main::$5) goto main::@9
  to:main::@11
main::@9: scope:[main]  from main::@8
  main::row#6 = phi( main::@8/main::row#7 )
  main::row_pressed_bits#5 = phi( main::@8/main::row_pressed_bits#2 )
  main::col#2 = phi( main::@8/main::col#5 )
  main::screen#3 = phi( main::@8/main::screen#9 )
  main::screen#3[main::col#2] = '1'
  to:main::@10
main::@11: scope:[main]  from main::@8
  main::row#5 = phi( main::@8/main::row#7 )
  main::row_pressed_bits#4 = phi( main::@8/main::row_pressed_bits#2 )
  main::col#3 = phi( main::@8/main::col#5 )
  main::screen#4 = phi( main::@8/main::screen#9 )
  main::screen#4[main::col#3] = '0'
  to:main::@10
main::@10: scope:[main]  from main::@11 main::@9
  main::row#4 = phi( main::@11/main::row#5, main::@9/main::row#6 )
  main::screen#10 = phi( main::@11/main::screen#4, main::@9/main::screen#3 )
  main::col#4 = phi( main::@11/main::col#3, main::@9/main::col#2 )
  main::row_pressed_bits#3 = phi( main::@11/main::row_pressed_bits#4, main::@9/main::row_pressed_bits#5 )
  main::$6 = main::row_pressed_bits#3 * 2
  main::row_pressed_bits#1 = main::$6
  main::col#1 = main::col#4 + rangenext(0,7)
  main::$7 = main::col#1 != rangelast(0,7)
  if(main::$7) goto main::@8
  to:main::@12
main::@12: scope:[main]  from main::@10
  main::row#3 = phi( main::@10/main::row#4 )
  main::screen#5 = phi( main::@10/main::screen#10 )
  main::$8 = main::screen#5 + $28
  main::screen#1 = main::$8
  main::row#1 = main::row#3 + rangenext(0,7)
  main::$9 = main::row#1 != rangelast(0,7)
  if(main::$9) goto main::@7
  to:main::@13
main::@13: scope:[main]  from main::@12
  main::screen#6 = phi( main::@12/main::screen#1 )
  main::$10 = main::screen#6 + $28
  main::screen#2 = main::$10
  main::i#0 = 0
  main::ch#0 = 0
  to:main::@14
main::@14: scope:[main]  from main::@13 main::@15
  main::i#9 = phi( main::@13/main::i#0, main::@15/main::i#6 )
  main::screen#17 = phi( main::@13/main::screen#2, main::@15/main::screen#12 )
  main::ch#2 = phi( main::@13/main::ch#0, main::@15/main::ch#1 )
  keyboard_get_keycode::ch#0 = main::ch#2
  call keyboard_get_keycode
  keyboard_get_keycode::return#2 = keyboard_get_keycode::return#1
  to:main::@21
main::@21: scope:[main]  from main::@14
  main::i#7 = phi( main::@14/main::i#9 )
  main::screen#14 = phi( main::@14/main::screen#17 )
  main::ch#5 = phi( main::@14/main::ch#2 )
  keyboard_get_keycode::return#4 = phi( main::@14/keyboard_get_keycode::return#2 )
  main::key#0 = keyboard_get_keycode::return#4
  main::$12 = main::key#0 != $3f
  main::$13 = ! main::$12
  if(main::$13) goto main::@15
  to:main::@16
main::@15: scope:[main]  from main::@17 main::@21 main::@22
  main::i#6 = phi( main::@17/main::i#1, main::@21/main::i#7, main::@22/main::i#5 )
  main::screen#12 = phi( main::@17/main::screen#7, main::@21/main::screen#14, main::@22/main::screen#11 )
  main::ch#3 = phi( main::@17/main::ch#4, main::@21/main::ch#5, main::@22/main::ch#6 )
  main::ch#1 = main::ch#3 + rangenext(0,$3f)
  main::$17 = main::ch#1 != rangelast(0,$3f)
  if(main::$17) goto main::@14
  to:main::@18
main::@16: scope:[main]  from main::@21
  main::i#8 = phi( main::@21/main::i#7 )
  main::screen#15 = phi( main::@21/main::screen#14 )
  main::ch#7 = phi( main::@21/main::ch#5 )
  main::key#1 = phi( main::@21/main::key#0 )
  keyboard_key_pressed::key#0 = main::key#1
  call keyboard_key_pressed
  keyboard_key_pressed::return#2 = keyboard_key_pressed::return#1
  to:main::@22
main::@22: scope:[main]  from main::@16
  main::i#5 = phi( main::@16/main::i#8 )
  main::screen#11 = phi( main::@16/main::screen#15 )
  main::ch#6 = phi( main::@16/main::ch#7 )
  keyboard_key_pressed::return#4 = phi( main::@16/keyboard_key_pressed::return#2 )
  main::$14 = keyboard_key_pressed::return#4
  main::$15 = main::$14 != 0
  main::$16 = ! main::$15
  if(main::$16) goto main::@15
  to:main::@17
main::@17: scope:[main]  from main::@22
  main::i#3 = phi( main::@22/main::i#5 )
  main::screen#7 = phi( main::@22/main::screen#11 )
  main::ch#4 = phi( main::@22/main::ch#6 )
  main::screen#7[main::i#3] = main::ch#4
  main::i#1 = ++ main::i#3
  to:main::@15
main::@18: scope:[main]  from main::@15 main::@18
  main::i#4 = phi( main::@15/main::i#6, main::@18/main::i#2 )
  main::screen#8 = phi( main::@15/main::screen#12, main::@18/main::screen#8 )
  main::screen#8[main::i#4] = ' '
  main::i#2 = ++ main::i#4
  main::$18 = main::i#2 < 5
  if(main::$18) goto main::@18
  to:main::@4
main::@return: scope:[main]  from main::@4
  return 
  to:@return

void __start()
__start: scope:[__start]  from
  to:__start::__init1
__start::__init1: scope:[__start]  from __start
  to:__start::@1
__start::@1: scope:[__start]  from __start::__init1
  call main
  to:__start::@2
__start::@2: scope:[__start]  from __start::@1
  to:__start::@return
__start::@return: scope:[__start]  from __start::@2
  return 
  to:@return

SYMBOL TABLE SSA
__constant struct MOS6526_CIA * const CIA1 = (struct MOS6526_CIA *)$dc00
__constant const char KEY_0 = $23
__constant const char KEY_1 = $38
__constant const char KEY_2 = $3b
__constant const char KEY_3 = 8
__constant const char KEY_4 = $b
__constant const char KEY_5 = $10
__constant const char KEY_6 = $13
__constant const char KEY_7 = $18
__constant const char KEY_8 = $1b
__constant const char KEY_9 = $20
__constant const char KEY_A = $a
__constant const char KEY_ARROW_LEFT = $39
__constant const char KEY_ARROW_UP = $36
__constant const char KEY_ASTERISK = $31
__constant const char KEY_AT = $2e
__constant const char KEY_B = $1c
__constant const char KEY_C = $14
__constant const char KEY_COLON = $2d
__constant const char KEY_COMMA = $2f
__constant const char KEY_D = $12
__constant const char KEY_DOT = $2c
__constant const char KEY_E = $e
__constant const char KEY_EQUALS = $35
__constant const char KEY_F = $15
__constant const char KEY_G = $1a
__constant const char KEY_H = $1d
__constant const char KEY_I = $21
__constant const char KEY_J = $22
__constant const char KEY_K = $25
__constant const char KEY_L = $2a
__constant const char KEY_M = $24
__constant const char KEY_MINUS = $2b
__constant const char KEY_N = $27
__constant const char KEY_O = $26
__constant const char KEY_P = $29
__constant const char KEY_PLUS = $28
__constant const char KEY_POUND = $30
__constant const char KEY_Q = $3e
__constant const char KEY_R = $11
__constant const char KEY_S = $d
__constant const char KEY_SEMICOLON = $32
__constant const char KEY_SLASH = $37
__constant const char KEY_SPACE = $3c
__constant const char KEY_T = $16
__constant const char KEY_U = $1e
__constant const char KEY_V = $1f
__constant const char KEY_W = 9
__constant const char KEY_X = $17
__constant const char KEY_Y = $19
__constant const char KEY_Z = $c
__constant char OFFSET_STRUCT_MOS6526_CIA_PORT_A = 0
__constant char OFFSET_STRUCT_MOS6526_CIA_PORT_A_DDR = 2
__constant char OFFSET_STRUCT_MOS6526_CIA_PORT_B = 1
__constant char OFFSET_STRUCT_MOS6526_CIA_PORT_B_DDR = 3
__constant char * const RASTER = (char *)$d012
void __start()
__constant const char keyboard_char_keycodes[] = { KEY_AT, KEY_A, KEY_B, KEY_C, KEY_D, KEY_E, KEY_F, KEY_G, KEY_H, KEY_I, KEY_J, KEY_K, KEY_L, KEY_M, KEY_N, KEY_O, KEY_P, KEY_Q, KEY_R, KEY_S, KEY_T, KEY_U, KEY_V, KEY_W, KEY_X, KEY_Y, KEY_Z, $3f, KEY_POUND, $3f, KEY_ARROW_UP, KEY_ARROW_LEFT, KEY_SPACE, $3f, $3f, $3f, $3f, $3f, $3f, $3f, $3f, $3f, KEY_ASTERISK, KEY_PLUS, KEY_COMMA, KEY_MINUS, KEY_DOT, KEY_SLASH, KEY_0, KEY_1, KEY_2, KEY_3, KEY_4, KEY_5, KEY_6, KEY_7, KEY_8, KEY_9, KEY_COLON, KEY_SEMICOLON, $3f, KEY_EQUALS, $3f, $3f }
char keyboard_get_keycode(char ch)
char keyboard_get_keycode::ch
char keyboard_get_keycode::ch#0
char keyboard_get_keycode::ch#1
char keyboard_get_keycode::return
char keyboard_get_keycode::return#0
char keyboard_get_keycode::return#1
char keyboard_get_keycode::return#2
char keyboard_get_keycode::return#3
char keyboard_get_keycode::return#4
void keyboard_init()
char keyboard_key_pressed(char key)
char keyboard_key_pressed::$2
char keyboard_key_pressed::$3
char keyboard_key_pressed::colidx
char keyboard_key_pressed::colidx#0
char keyboard_key_pressed::colidx#1
char keyboard_key_pressed::key
char keyboard_key_pressed::key#0
char keyboard_key_pressed::key#1
char keyboard_key_pressed::return
char keyboard_key_pressed::return#0
char keyboard_key_pressed::return#1
char keyboard_key_pressed::return#2
char keyboard_key_pressed::return#3
char keyboard_key_pressed::return#4
char keyboard_key_pressed::rowidx
char keyboard_key_pressed::rowidx#0
__constant char keyboard_matrix_col_bitmask[8] = { 1, 2, 4, 8, $10, $20, $40, $80 }
char keyboard_matrix_read(char rowid)
char keyboard_matrix_read::return
char keyboard_matrix_read::return#0
char keyboard_matrix_read::return#1
char keyboard_matrix_read::return#2
char keyboard_matrix_read::return#3
char keyboard_matrix_read::return#4
char keyboard_matrix_read::return#5
char keyboard_matrix_read::return#6
char keyboard_matrix_read::row_pressed_bits
char keyboard_matrix_read::row_pressed_bits#0
char keyboard_matrix_read::rowid
char keyboard_matrix_read::rowid#0
char keyboard_matrix_read::rowid#1
char keyboard_matrix_read::rowid#2
__constant char keyboard_matrix_row_bitmask[8] = { $fe, $fd, $fb, $f7, $ef, $df, $bf, $7f }
void main()
bool main::$1
char *main::$10
bool main::$12
bool main::$13
char main::$14
bool main::$15
bool main::$16
bool main::$17
bool main::$18
bool main::$2
number main::$4
bool main::$5
number main::$6
bool main::$7
char *main::$8
bool main::$9
char main::ch
char main::ch#0
char main::ch#1
char main::ch#2
char main::ch#3
char main::ch#4
char main::ch#5
char main::ch#6
char main::ch#7
char main::col
char main::col#0
char main::col#1
char main::col#2
char main::col#3
char main::col#4
char main::col#5
char main::i
char main::i#0
char main::i#1
char main::i#2
char main::i#3
char main::i#4
char main::i#5
char main::i#6
char main::i#7
char main::i#8
char main::i#9
char main::key
char main::key#0
char main::key#1
char main::row
char main::row#0
char main::row#1
char main::row#2
char main::row#3
char main::row#4
char main::row#5
char main::row#6
char main::row#7
char main::row#8
char main::row_pressed_bits
char main::row_pressed_bits#0
char main::row_pressed_bits#1
char main::row_pressed_bits#2
char main::row_pressed_bits#3
char main::row_pressed_bits#4
char main::row_pressed_bits#5
char *main::sc
char *main::sc#0
char *main::sc#1
char *main::sc#2
char *main::sc#3
char *main::screen
char *main::screen#0
char *main::screen#1
char *main::screen#10
char *main::screen#11
char *main::screen#12
char *main::screen#13
char *main::screen#14
char *main::screen#15
char *main::screen#16
char *main::screen#17
char *main::screen#2
char *main::screen#3
char *main::screen#4
char *main::screen#5
char *main::screen#6
char *main::screen#7
char *main::screen#8
char *main::screen#9

Adding number conversion cast (unumber) $ff in *((char *)CIA1+OFFSET_STRUCT_MOS6526_CIA_PORT_A_DDR) = $ff
Adding number conversion cast (unumber) 0 in *((char *)CIA1+OFFSET_STRUCT_MOS6526_CIA_PORT_B_DDR) = 0
Adding number conversion cast (unumber) 7 in keyboard_key_pressed::colidx#0 = keyboard_key_pressed::key#1 & 7
Adding number conversion cast (unumber) 3 in keyboard_key_pressed::rowidx#0 = keyboard_key_pressed::key#1 >> 3
Adding number conversion cast (unumber) $400+$3e8 in main::$1 = main::sc#2 < $400+$3e8
Adding number conversion cast (unumber) $ff in main::$2 = *RASTER != $ff
Adding number conversion cast (unumber) $80 in main::$4 = main::row_pressed_bits#2 & $80
Adding number conversion cast (unumber) main::$4 in main::$4 = main::row_pressed_bits#2 & (unumber)$80
Adding number conversion cast (unumber) 0 in main::$5 = main::$4 != 0
Adding number conversion cast (unumber) 2 in main::$6 = main::row_pressed_bits#3 * 2
Adding number conversion cast (unumber) main::$6 in main::$6 = main::row_pressed_bits#3 * (unumber)2
Adding number conversion cast (unumber) $28 in main::$8 = main::screen#5 + $28
Adding number conversion cast (unumber) $28 in main::$10 = main::screen#6 + $28
Adding number conversion cast (unumber) $3f in main::$12 = main::key#0 != $3f
Adding number conversion cast (unumber) 0 in main::$15 = main::$14 != 0
Adding number conversion cast (unumber) 5 in main::$18 = main::i#2 < 5
Successful SSA optimization PassNAddNumberTypeConversions
Inlining cast *((char *)CIA1+OFFSET_STRUCT_MOS6526_CIA_PORT_A_DDR) = (unumber)$ff
Inlining cast *((char *)CIA1+OFFSET_STRUCT_MOS6526_CIA_PORT_B_DDR) = (unumber)0
Successful SSA optimization Pass2InlineCast
Simplifying constant pointer cast (char *) 53266
Simplifying constant pointer cast (struct MOS6526_CIA *) 56320
Simplifying constant integer cast $ff
Simplifying constant integer cast 0
Simplifying constant integer cast 7
Simplifying constant integer cast 3
Simplifying constant pointer cast (char *) 1024
Simplifying constant integer cast $ff
Simplifying constant pointer cast (char *) 1024
Simplifying constant integer cast $80
Simplifying constant integer cast 0
Simplifying constant integer cast 2
Simplifying constant integer cast $28
Simplifying constant integer cast $28
Simplifying constant integer cast $3f
Simplifying constant integer cast 0
Simplifying constant integer cast 5
Successful SSA optimization PassNCastSimplification
Finalized unsigned number type (char) $ff
Finalized unsigned number type (char) 0
Finalized unsigned number type (char) 7
Finalized unsigned number type (char) 3
Finalized unsigned number type (char) $ff
Finalized unsigned number type (char) $80
Finalized unsigned number type (char) 0
Finalized unsigned number type (char) 2
Finalized unsigned number type (char) $28
Finalized unsigned number type (char) $28
Finalized unsigned number type (char) $3f
Finalized unsigned number type (char) 0
Finalized unsigned number type (char) 5
Successful SSA optimization PassNFinalizeNumberTypeConversions
Inferred type updated to char in main::$4 = main::row_pressed_bits#2 & $80
Inferred type updated to char in main::$6 = main::row_pressed_bits#3 * 2
Inversing boolean not [80] main::$13 = main::key#0 == $3f from [79] main::$12 = main::key#0 != $3f
Inversing boolean not [93] main::$16 = main::$14 == 0 from [92] main::$15 = main::$14 != 0
Successful SSA optimization Pass2UnaryNotSimplification
Alias keyboard_matrix_read::return#0 = keyboard_matrix_read::row_pressed_bits#0 keyboard_matrix_read::return#4 keyboard_matrix_read::return#1 
Alias keyboard_matrix_read::return#2 = keyboard_matrix_read::return#5 
Alias keyboard_key_pressed::colidx#0 = keyboard_key_pressed::colidx#1 
Alias keyboard_key_pressed::return#0 = keyboard_key_pressed::$3 keyboard_key_pressed::return#3 keyboard_key_pressed::return#1 
Alias keyboard_get_keycode::return#0 = keyboard_get_keycode::return#3 keyboard_get_keycode::return#1 
Alias main::sc#2 = main::sc#3 
Alias keyboard_matrix_read::return#3 = keyboard_matrix_read::return#6 
Alias main::screen#13 = main::screen#16 
Alias main::row#2 = main::row#8 
Alias main::screen#3 = main::screen#9 main::screen#4 
Alias main::col#2 = main::col#5 main::col#3 
Alias main::row_pressed_bits#2 = main::row_pressed_bits#5 main::row_pressed_bits#4 
Alias main::row#5 = main::row#6 main::row#7 
Alias main::row_pressed_bits#1 = main::$6 
Alias main::screen#10 = main::screen#5 
Alias main::row#3 = main::row#4 
Alias main::screen#1 = main::$8 main::screen#6 
Alias main::screen#2 = main::$10 
Alias keyboard_get_keycode::return#2 = keyboard_get_keycode::return#4 
Alias main::ch#2 = main::ch#5 main::ch#7 main::ch#6 main::ch#4 
Alias main::screen#11 = main::screen#14 main::screen#17 main::screen#15 main::screen#7 
Alias main::i#3 = main::i#7 main::i#9 main::i#8 main::i#5 
Alias main::key#0 = main::key#1 
Alias keyboard_key_pressed::return#2 = keyboard_key_pressed::return#4 
Successful SSA optimization Pass2AliasElimination
Alias main::row_pressed_bits#2 = main::row_pressed_bits#3 
Alias main::col#2 = main::col#4 
Alias main::screen#10 = main::screen#3 
Alias main::row#3 = main::row#5 
Alias main::ch#2 = main::ch#3 
Alias main::screen#11 = main::screen#12 
Successful SSA optimization Pass2AliasElimination
Identical Phi Values keyboard_key_pressed::key#1 keyboard_key_pressed::key#0
Identical Phi Values keyboard_get_keycode::ch#1 keyboard_get_keycode::ch#0
Identical Phi Values main::screen#10 main::screen#13
Identical Phi Values main::row#3 main::row#2
Identical Phi Values main::screen#11 main::screen#2
Identical Phi Values main::screen#8 main::screen#11
Successful SSA optimization Pass2IdenticalPhiElimination
Simple Condition main::$1 [22] if(main::sc#2<(unsigned int)$400+$3e8) goto main::@2
Simple Condition main::$2 [28] if(*RASTER!=$ff) goto main::@5
Simple Condition main::$5 [40] if(main::$4!=0) goto main::@9
Simple Condition main::$7 [46] if(main::col#1!=rangelast(0,7)) goto main::@8
Simple Condition main::$9 [50] if(main::row#1!=rangelast(0,7)) goto main::@7
Simple Condition main::$13 [60] if(main::key#0==$3f) goto main::@15
Simple Condition main::$17 [64] if(main::ch#1!=rangelast(0,$3f)) goto main::@14
Simple Condition main::$16 [70] if(main::$14==0) goto main::@15
Simple Condition main::$18 [77] if(main::i#2<5) goto main::@18
Successful SSA optimization Pass2ConditionalJumpSimplification
Constant main::sc#0 = (char *) 1024
Constant main::screen#0 = (char *) 1024
Constant main::row#0 = 0
Constant main::col#0 = 0
Constant main::i#0 = 0
Constant main::ch#0 = 0
Successful SSA optimization Pass2ConstantIdentification
if() condition always true - replacing block destination [26] if(true) goto main::@5
Successful SSA optimization Pass2ConstantIfs
Resolved ranged next value [44] main::col#1 = ++ main::col#2 to ++
Resolved ranged comparison value [46] if(main::col#1!=rangelast(0,7)) goto main::@8 to 8
Resolved ranged next value [48] main::row#1 = ++ main::row#2 to ++
Resolved ranged comparison value [50] if(main::row#1!=rangelast(0,7)) goto main::@7 to 8
Resolved ranged next value [62] main::ch#1 = ++ main::ch#2 to ++
Resolved ranged comparison value [64] if(main::ch#1!=rangelast(0,$3f)) goto main::@14 to $40
Simplifying expression containing zero (char *)CIA1 in [4] *((char *)CIA1+OFFSET_STRUCT_MOS6526_CIA_PORT_A) = keyboard_matrix_row_bitmask[keyboard_matrix_read::rowid#2]
Successful SSA optimization PassNSimplifyExpressionWithZero
Removing unused block main::@return
Successful SSA optimization Pass2EliminateUnusedBlocks
Eliminating unused constant OFFSET_STRUCT_MOS6526_CIA_PORT_A
Successful SSA optimization PassNEliminateUnusedVars
Removing unused procedure __start
Removing unused procedure block __start
Removing unused procedure block __start::__init1
Removing unused procedure block __start::@1
Removing unused procedure block __start::@2
Removing unused procedure block __start::@return
Successful SSA optimization PassNEliminateEmptyStart
Adding number conversion cast (unumber) 8 in [35] if(main::col#1!=8) goto main::@8
Adding number conversion cast (unumber) 8 in [38] if(main::row#1!=8) goto main::@7
Adding number conversion cast (unumber) $40 in [48] if(main::ch#1!=$40) goto main::@14
Successful SSA optimization PassNAddNumberTypeConversions
Simplifying constant integer cast 8
Simplifying constant integer cast 8
Simplifying constant integer cast $40
Successful SSA optimization PassNCastSimplification
Finalized unsigned number type (char) 8
Finalized unsigned number type (char) 8
Finalized unsigned number type (char) $40
Successful SSA optimization PassNFinalizeNumberTypeConversions
Rewriting multiplication to use shift [33] main::row_pressed_bits#1 = main::row_pressed_bits#2 * 2
Successful SSA optimization Pass2MultiplyToShiftRewriting
Inlining constant with var siblings main::sc#0
Inlining constant with var siblings main::screen#0
Inlining constant with var siblings main::row#0
Inlining constant with var siblings main::col#0
Inlining constant with var siblings main::i#0
Inlining constant with var siblings main::ch#0
Constant inlined main::screen#0 = (char *) 1024
Constant inlined main::col#0 = 0
Constant inlined main::i#0 = 0
Constant inlined main::sc#0 = (char *) 1024
Constant inlined main::row#0 = 0
Constant inlined main::ch#0 = 0
Successful SSA optimization Pass2ConstantInlining
Finalized unsigned number type (char) 8
Finalized unsigned number type (char) 8
Finalized unsigned number type (unsigned int) $400
Finalized unsigned number type (unsigned int) $3e8
Successful SSA optimization PassNFinalizeNumberTypeConversions
Simplifying constant integer cast $400+$3e8
Successful SSA optimization PassNCastSimplification
Added new block during phi lifting main::@23(between main::@12 and main::@7)
Added new block during phi lifting main::@24(between main::@10 and main::@8)
Added new block during phi lifting main::@25(between main::@15 and main::@14)
Added new block during phi lifting main::@26(between main::@21 and main::@15)
Added new block during phi lifting main::@27(between main::@22 and main::@15)
Added new block during phi lifting main::@28(between main::@15 and main::@18)
Added new block during phi lifting main::@29(between main::@18 and main::@18)
Adding NOP phi() at start of main
Adding NOP phi() at start of main::@3
Adding NOP phi() at start of main::@19
Adding NOP phi() at start of main::@4
Adding NOP phi() at start of main::@6
CALL GRAPH
Calls in [main] to keyboard_init:4 keyboard_matrix_read:12 keyboard_get_keycode:29 keyboard_key_pressed:34 
Calls in [keyboard_key_pressed] to keyboard_matrix_read:75 

Created 10 initial phi equivalence classes
Coalesced [11] keyboard_matrix_read::rowid#4 = keyboard_matrix_read::rowid#1
Coalesced [15] main::row_pressed_bits#7 = main::row_pressed_bits#0
Coalesced [40] main::i#11 = main::i#1
Coalesced [44] main::i#14 = main::i#6
Coalesced [49] main::i#15 = main::i#2
Coalesced [50] main::ch#8 = main::ch#1
Coalesced [51] main::i#10 = main::i#6
Coalesced (already) [52] main::i#13 = main::i#3
Coalesced (already) [53] main::i#12 = main::i#3
Coalesced [54] main::row#9 = main::row#1
Coalesced [55] main::screen#18 = main::screen#1
Coalesced [56] main::row_pressed_bits#6 = main::row_pressed_bits#1
Coalesced [57] main::col#6 = main::col#1
Coalesced [61] main::sc#4 = main::sc#1
Coalesced [74] keyboard_matrix_read::rowid#3 = keyboard_matrix_read::rowid#0
Coalesced down to 8 phi equivalence classes
Culled Empty Block label main::@19
Culled Empty Block label main::@4
Culled Empty Block label main::@6
Culled Empty Block label main::@28
Culled Empty Block label main::@29
Culled Empty Block label main::@25
Culled Empty Block label main::@27
Culled Empty Block label main::@26
Culled Empty Block label main::@23
Culled Empty Block label main::@24
Renumbering block main::@5 to main::@4
Renumbering block main::@7 to main::@5
Renumbering block main::@8 to main::@6
Renumbering block main::@9 to main::@7
Renumbering block main::@10 to main::@8
Renumbering block main::@11 to main::@9
Renumbering block main::@12 to main::@10
Renumbering block main::@13 to main::@11
Renumbering block main::@14 to main::@12
Renumbering block main::@15 to main::@13
Renumbering block main::@16 to main::@14
Renumbering block main::@17 to main::@15
Renumbering block main::@18 to main::@16
Renumbering block main::@20 to main::@17
Renumbering block main::@21 to main::@18
Renumbering block main::@22 to main::@19
Adding NOP phi() at start of main
Adding NOP phi() at start of main::@3

FINAL CONTROL FLOW GRAPH

void main()
main: scope:[main]  from
  [0] phi()
  to:main::@1
main::@1: scope:[main]  from main main::@2
  [1] main::sc#2 = phi( main/(char *) 1024, main::@2/main::sc#1 )
  [2] if(main::sc#2<$400+$3e8) goto main::@2
  to:main::@3
main::@3: scope:[main]  from main::@1
  [3] phi()
  [4] call keyboard_init
  to:main::@4
main::@4: scope:[main]  from main::@16 main::@3 main::@4
  [5] if(*RASTER!=$ff) goto main::@4
  to:main::@5
main::@5: scope:[main]  from main::@10 main::@4
  [6] main::screen#13 = phi( main::@10/main::screen#1, main::@4/(char *) 1024 )
  [6] main::row#2 = phi( main::@10/main::row#1, main::@4/0 )
  [7] keyboard_matrix_read::rowid#1 = main::row#2
  [8] call keyboard_matrix_read
  [9] keyboard_matrix_read::return#3 = keyboard_matrix_read::return#0
  to:main::@17
main::@17: scope:[main]  from main::@5
  [10] main::row_pressed_bits#0 = keyboard_matrix_read::return#3
  to:main::@6
main::@6: scope:[main]  from main::@17 main::@8
  [11] main::col#2 = phi( main::@8/main::col#1, main::@17/0 )
  [11] main::row_pressed_bits#2 = phi( main::@8/main::row_pressed_bits#1, main::@17/main::row_pressed_bits#0 )
  [12] main::$4 = main::row_pressed_bits#2 & $80
  [13] if(main::$4!=0) goto main::@7
  to:main::@9
main::@9: scope:[main]  from main::@6
  [14] main::screen#13[main::col#2] = '0'
  to:main::@8
main::@8: scope:[main]  from main::@7 main::@9
  [15] main::row_pressed_bits#1 = main::row_pressed_bits#2 << 1
  [16] main::col#1 = ++ main::col#2
  [17] if(main::col#1!=8) goto main::@6
  to:main::@10
main::@10: scope:[main]  from main::@8
  [18] main::screen#1 = main::screen#13 + $28
  [19] main::row#1 = ++ main::row#2
  [20] if(main::row#1!=8) goto main::@5
  to:main::@11
main::@11: scope:[main]  from main::@10
  [21] main::screen#2 = main::screen#1 + $28
  to:main::@12
main::@12: scope:[main]  from main::@11 main::@13
  [22] main::i#3 = phi( main::@11/0, main::@13/main::i#6 )
  [22] main::ch#2 = phi( main::@11/0, main::@13/main::ch#1 )
  [23] keyboard_get_keycode::ch#0 = main::ch#2
  [24] call keyboard_get_keycode
  [25] keyboard_get_keycode::return#2 = keyboard_get_keycode::return#0
  to:main::@18
main::@18: scope:[main]  from main::@12
  [26] main::key#0 = keyboard_get_keycode::return#2
  [27] if(main::key#0==$3f) goto main::@13
  to:main::@14
main::@14: scope:[main]  from main::@18
  [28] keyboard_key_pressed::key#0 = main::key#0
  [29] call keyboard_key_pressed
  [30] keyboard_key_pressed::return#2 = keyboard_key_pressed::return#0
  to:main::@19
main::@19: scope:[main]  from main::@14
  [31] main::$14 = keyboard_key_pressed::return#2
  [32] if(main::$14==0) goto main::@13
  to:main::@15
main::@15: scope:[main]  from main::@19
  [33] main::screen#2[main::i#3] = main::ch#2
  [34] main::i#1 = ++ main::i#3
  to:main::@13
main::@13: scope:[main]  from main::@15 main::@18 main::@19
  [35] main::i#6 = phi( main::@15/main::i#1, main::@18/main::i#3, main::@19/main::i#3 )
  [36] main::ch#1 = ++ main::ch#2
  [37] if(main::ch#1!=$40) goto main::@12
  to:main::@16
main::@16: scope:[main]  from main::@13 main::@16
  [38] main::i#4 = phi( main::@13/main::i#6, main::@16/main::i#2 )
  [39] main::screen#2[main::i#4] = ' '
  [40] main::i#2 = ++ main::i#4
  [41] if(main::i#2<5) goto main::@16
  to:main::@4
main::@7: scope:[main]  from main::@6
  [42] main::screen#13[main::col#2] = '1'
  to:main::@8
main::@2: scope:[main]  from main::@1
  [43] *main::sc#2 = ' '
  [44] main::sc#1 = ++ main::sc#2
  to:main::@1

void keyboard_init()
keyboard_init: scope:[keyboard_init]  from main::@3
  [45] *((char *)CIA1+OFFSET_STRUCT_MOS6526_CIA_PORT_A_DDR) = $ff
  [46] *((char *)CIA1+OFFSET_STRUCT_MOS6526_CIA_PORT_B_DDR) = 0
  to:keyboard_init::@return
keyboard_init::@return: scope:[keyboard_init]  from keyboard_init
  [47] return 
  to:@return

char keyboard_matrix_read(char rowid)
keyboard_matrix_read: scope:[keyboard_matrix_read]  from keyboard_key_pressed main::@5
  [48] keyboard_matrix_read::rowid#2 = phi( keyboard_key_pressed/keyboard_matrix_read::rowid#0, main::@5/keyboard_matrix_read::rowid#1 )
  [49] *((char *)CIA1) = keyboard_matrix_row_bitmask[keyboard_matrix_read::rowid#2]
  [50] keyboard_matrix_read::return#0 = ~ *((char *)CIA1+OFFSET_STRUCT_MOS6526_CIA_PORT_B)
  to:keyboard_matrix_read::@return
keyboard_matrix_read::@return: scope:[keyboard_matrix_read]  from keyboard_matrix_read
  [51] return 
  to:@return

char keyboard_get_keycode(char ch)
keyboard_get_keycode: scope:[keyboard_get_keycode]  from main::@12
  [52] keyboard_get_keycode::return#0 = keyboard_char_keycodes[keyboard_get_keycode::ch#0]
  to:keyboard_get_keycode::@return
keyboard_get_keycode::@return: scope:[keyboard_get_keycode]  from keyboard_get_keycode
  [53] return 
  to:@return

char keyboard_key_pressed(char key)
keyboard_key_pressed: scope:[keyboard_key_pressed]  from main::@14
  [54] keyboard_key_pressed::colidx#0 = keyboard_key_pressed::key#0 & 7
  [55] keyboard_key_pressed::rowidx#0 = keyboard_key_pressed::key#0 >> 3
  [56] keyboard_matrix_read::rowid#0 = keyboard_key_pressed::rowidx#0
  [57] call keyboard_matrix_read
  [58] keyboard_matrix_read::return#2 = keyboard_matrix_read::return#0
  to:keyboard_key_pressed::@1
keyboard_key_pressed::@1: scope:[keyboard_key_pressed]  from keyboard_key_pressed
  [59] keyboard_key_pressed::$2 = keyboard_matrix_read::return#2
  [60] keyboard_key_pressed::return#0 = keyboard_key_pressed::$2 & keyboard_matrix_col_bitmask[keyboard_key_pressed::colidx#0]
  to:keyboard_key_pressed::@return
keyboard_key_pressed::@return: scope:[keyboard_key_pressed]  from keyboard_key_pressed::@1
  [61] return 
  to:@return


VARIABLE REGISTER WEIGHTS
char keyboard_get_keycode(char ch)
char keyboard_get_keycode::ch
char keyboard_get_keycode::ch#0 // 1102.0
char keyboard_get_keycode::return
char keyboard_get_keycode::return#0 // 367.33333333333337
char keyboard_get_keycode::return#2 // 202.0
void keyboard_init()
char keyboard_key_pressed(char key)
char keyboard_key_pressed::$2 // 2002.0
char keyboard_key_pressed::colidx
char keyboard_key_pressed::colidx#0 // 333.6666666666667
char keyboard_key_pressed::key
char keyboard_key_pressed::key#0 // 1051.5
char keyboard_key_pressed::return
char keyboard_key_pressed::return#0 // 367.33333333333337
char keyboard_key_pressed::return#2 // 202.0
char keyboard_key_pressed::rowidx
char keyboard_key_pressed::rowidx#0 // 2002.0
char keyboard_matrix_read(char rowid)
char keyboard_matrix_read::return
char keyboard_matrix_read::return#0 // 2775.75
char keyboard_matrix_read::return#2 // 2002.0
char keyboard_matrix_read::return#3 // 202.0
char keyboard_matrix_read::row_pressed_bits
char keyboard_matrix_read::rowid
char keyboard_matrix_read::rowid#0 // 2002.0
char keyboard_matrix_read::rowid#1 // 202.0
char keyboard_matrix_read::rowid#2 // 11103.0
void main()
char main::$14 // 202.0
char main::$4 // 2002.0
char main::ch
char main::ch#1 // 151.5
char main::ch#2 // 28.857142857142858
char main::col
char main::col#1 // 1501.5
char main::col#2 // 667.3333333333334
char main::i
char main::i#1 // 202.0
char main::i#2 // 151.5
char main::i#3 // 42.08333333333333
char main::i#4 // 202.0
char main::i#6 // 168.33333333333331
char main::key
char main::key#0 // 151.5
char main::row
char main::row#1 // 151.5
char main::row#2 // 21.642857142857142
char main::row_pressed_bits
char main::row_pressed_bits#0 // 202.0
char main::row_pressed_bits#1 // 667.3333333333334
char main::row_pressed_bits#2 // 620.8
char *main::sc
char *main::sc#1 // 22.0
char *main::sc#2 // 14.666666666666666
char *main::screen
char *main::screen#1 // 71.0
char *main::screen#13 // 169.53846153846155
char *main::screen#2 // 10.142857142857142

Initial phi equivalence classes
[ main::sc#2 main::sc#1 ]
[ main::row#2 main::row#1 ]
[ main::screen#13 main::screen#1 ]
[ main::row_pressed_bits#2 main::row_pressed_bits#1 main::row_pressed_bits#0 ]
[ main::col#2 main::col#1 ]
[ main::ch#2 main::ch#1 ]
[ main::i#4 main::i#3 main::i#6 main::i#1 main::i#2 ]
[ keyboard_matrix_read::rowid#2 keyboard_matrix_read::rowid#0 keyboard_matrix_read::rowid#1 ]
Added variable keyboard_matrix_read::return#3 to live range equivalence class [ keyboard_matrix_read::return#3 ]
Added variable main::$4 to live range equivalence class [ main::$4 ]
Added variable main::screen#2 to live range equivalence class [ main::screen#2 ]
Added variable keyboard_get_keycode::ch#0 to live range equivalence class [ keyboard_get_keycode::ch#0 ]
Added variable keyboard_get_keycode::return#2 to live range equivalence class [ keyboard_get_keycode::return#2 ]
Added variable main::key#0 to live range equivalence class [ main::key#0 ]
Added variable keyboard_key_pressed::key#0 to live range equivalence class [ keyboard_key_pressed::key#0 ]
Added variable keyboard_key_pressed::return#2 to live range equivalence class [ keyboard_key_pressed::return#2 ]
Added variable main::$14 to live range equivalence class [ main::$14 ]
Added variable keyboard_matrix_read::return#0 to live range equivalence class [ keyboard_matrix_read::return#0 ]
Added variable keyboard_get_keycode::return#0 to live range equivalence class [ keyboard_get_keycode::return#0 ]
Added variable keyboard_key_pressed::colidx#0 to live range equivalence class [ keyboard_key_pressed::colidx#0 ]
Added variable keyboard_key_pressed::rowidx#0 to live range equivalence class [ keyboard_key_pressed::rowidx#0 ]
Added variable keyboard_matrix_read::return#2 to live range equivalence class [ keyboard_matrix_read::return#2 ]
Added variable keyboard_key_pressed::$2 to live range equivalence class [ keyboard_key_pressed::$2 ]
Added variable keyboard_key_pressed::return#0 to live range equivalence class [ keyboard_key_pressed::return#0 ]
Complete equivalence classes
[ main::sc#2 main::sc#1 ]
[ main::row#2 main::row#1 ]
[ main::screen#13 main::screen#1 ]
[ main::row_pressed_bits#2 main::row_pressed_bits#1 main::row_pressed_bits#0 ]
[ main::col#2 main::col#1 ]
[ main::ch#2 main::ch#1 ]
[ main::i#4 main::i#3 main::i#6 main::i#1 main::i#2 ]
[ keyboard_matrix_read::rowid#2 keyboard_matrix_read::rowid#0 keyboard_matrix_read::rowid#1 ]
[ keyboard_matrix_read::return#3 ]
[ main::$4 ]
[ main::screen#2 ]
[ keyboard_get_keycode::ch#0 ]
[ keyboard_get_keycode::return#2 ]
[ main::key#0 ]
[ keyboard_key_pressed::key#0 ]
[ keyboard_key_pressed::return#2 ]
[ main::$14 ]
[ keyboard_matrix_read::return#0 ]
[ keyboard_get_keycode::return#0 ]
[ keyboard_key_pressed::colidx#0 ]
[ keyboard_key_pressed::rowidx#0 ]
[ keyboard_matrix_read::return#2 ]
[ keyboard_key_pressed::$2 ]
[ keyboard_key_pressed::return#0 ]
Allocated zp[1]:2 [ keyboard_matrix_read::rowid#2 keyboard_matrix_read::rowid#0 keyboard_matrix_read::rowid#1 ]
Allocated zp[1]:3 [ keyboard_matrix_read::return#0 ]
Allocated zp[1]:4 [ main::col#2 main::col#1 ]
Allocated zp[1]:5 [ main::$4 ]
Allocated zp[1]:6 [ keyboard_key_pressed::rowidx#0 ]
Allocated zp[1]:7 [ keyboard_matrix_read::return#2 ]
Allocated zp[1]:8 [ keyboard_key_pressed::$2 ]
Allocated zp[1]:9 [ main::row_pressed_bits#2 main::row_pressed_bits#1 main::row_pressed_bits#0 ]
Allocated zp[1]:10 [ keyboard_get_keycode::ch#0 ]
Allocated zp[1]:11 [ keyboard_key_pressed::key#0 ]
Allocated zp[1]:12 [ main::i#4 main::i#3 main::i#6 main::i#1 main::i#2 ]
Allocated zp[1]:13 [ keyboard_get_keycode::return#0 ]
Allocated zp[1]:14 [ keyboard_key_pressed::return#0 ]
Allocated zp[1]:15 [ keyboard_key_pressed::colidx#0 ]
Allocated zp[2]:16 [ main::screen#13 main::screen#1 ]
Allocated zp[1]:18 [ keyboard_matrix_read::return#3 ]
Allocated zp[1]:19 [ keyboard_get_keycode::return#2 ]
Allocated zp[1]:20 [ keyboard_key_pressed::return#2 ]
Allocated zp[1]:21 [ main::$14 ]
Allocated zp[1]:22 [ main::ch#2 main::ch#1 ]
Allocated zp[1]:23 [ main::row#2 main::row#1 ]
Allocated zp[1]:24 [ main::key#0 ]
Allocated zp[2]:25 [ main::sc#2 main::sc#1 ]
Allocated zp[2]:27 [ main::screen#2 ]
REGISTER UPLIFT POTENTIAL REGISTERS
Statement [2] if(main::sc#2<$400+$3e8) goto main::@2 [ main::sc#2 ] (  [ main::sc#2 ] { }  ) always clobbers reg byte a 
Statement [5] if(*RASTER!=$ff) goto main::@4 [ ] (  [ ] { }  ) always clobbers reg byte a 
Statement [14] main::screen#13[main::col#2] = '0' [ main::row#2 main::screen#13 main::row_pressed_bits#2 main::col#2 ] (  [ main::row#2 main::screen#13 main::row_pressed_bits#2 main::col#2 ] { }  ) always clobbers reg byte a 
Removing always clobbered register reg byte a as potential for zp[1]:23 [ main::row#2 main::row#1 ]
Removing always clobbered register reg byte a as potential for zp[1]:9 [ main::row_pressed_bits#2 main::row_pressed_bits#1 main::row_pressed_bits#0 ]
Removing always clobbered register reg byte a as potential for zp[1]:4 [ main::col#2 main::col#1 ]
Statement [18] main::screen#1 = main::screen#13 + $28 [ main::row#2 main::screen#1 ] (  [ main::row#2 main::screen#1 ] { }  ) always clobbers reg byte a 
Statement [21] main::screen#2 = main::screen#1 + $28 [ main::screen#2 ] (  [ main::screen#2 ] { }  ) always clobbers reg byte a 
Statement [39] main::screen#2[main::i#4] = ' ' [ main::screen#2 main::i#4 ] (  [ main::screen#2 main::i#4 ] { }  ) always clobbers reg byte a 
Removing always clobbered register reg byte a as potential for zp[1]:12 [ main::i#4 main::i#3 main::i#6 main::i#1 main::i#2 ]
Statement [42] main::screen#13[main::col#2] = '1' [ main::row#2 main::screen#13 main::row_pressed_bits#2 main::col#2 ] (  [ main::row#2 main::screen#13 main::row_pressed_bits#2 main::col#2 ] { }  ) always clobbers reg byte a 
Statement [43] *main::sc#2 = ' ' [ main::sc#2 ] (  [ main::sc#2 ] { }  ) always clobbers reg byte a reg byte y 
Statement [45] *((char *)CIA1+OFFSET_STRUCT_MOS6526_CIA_PORT_A_DDR) = $ff [ ] ( keyboard_init:4 [ ] { }  ) always clobbers reg byte a 
Statement [46] *((char *)CIA1+OFFSET_STRUCT_MOS6526_CIA_PORT_B_DDR) = 0 [ ] ( keyboard_init:4 [ ] { }  ) always clobbers reg byte a 
Statement [49] *((char *)CIA1) = keyboard_matrix_row_bitmask[keyboard_matrix_read::rowid#2] [ ] ( keyboard_matrix_read:8 [ main::row#2 main::screen#13 ] { { keyboard_matrix_read::rowid#1 = keyboard_matrix_read::rowid#2 main::row#2 } { keyboard_matrix_read::return#0 = keyboard_matrix_read::return#3 } }  keyboard_key_pressed:29::keyboard_matrix_read:57 [ main::screen#2 main::ch#2 main::i#3 keyboard_key_pressed::colidx#0 ] { { keyboard_key_pressed::key#0 = main::key#0 } { keyboard_key_pressed::return#0 = keyboard_key_pressed::return#2 } { keyboard_matrix_read::rowid#0 = keyboard_matrix_read::rowid#2 keyboard_key_pressed::rowidx#0 } { keyboard_matrix_read::return#0 = keyboard_matrix_read::return#2 } }  ) always clobbers reg byte a 
Removing always clobbered register reg byte a as potential for zp[1]:22 [ main::ch#2 main::ch#1 ]
Removing always clobbered register reg byte a as potential for zp[1]:15 [ keyboard_key_pressed::colidx#0 ]
Statement [50] keyboard_matrix_read::return#0 = ~ *((char *)CIA1+OFFSET_STRUCT_MOS6526_CIA_PORT_B) [ keyboard_matrix_read::return#0 ] ( keyboard_matrix_read:8 [ main::row#2 main::screen#13 keyboard_matrix_read::return#0 ] { { keyboard_matrix_read::rowid#1 = keyboard_matrix_read::rowid#2 main::row#2 } { keyboard_matrix_read::return#0 = keyboard_matrix_read::return#3 } }  keyboard_key_pressed:29::keyboard_matrix_read:57 [ main::screen#2 main::ch#2 main::i#3 keyboard_key_pressed::colidx#0 keyboard_matrix_read::return#0 ] { { keyboard_key_pressed::key#0 = main::key#0 } { keyboard_key_pressed::return#0 = keyboard_key_pressed::return#2 } { keyboard_matrix_read::rowid#0 = keyboard_matrix_read::rowid#2 keyboard_key_pressed::rowidx#0 } { keyboard_matrix_read::return#0 = keyboard_matrix_read::return#2 } }  ) always clobbers reg byte a 
Statement [55] keyboard_key_pressed::rowidx#0 = keyboard_key_pressed::key#0 >> 3 [ keyboard_key_pressed::colidx#0 keyboard_key_pressed::rowidx#0 ] ( keyboard_key_pressed:29 [ main::screen#2 main::ch#2 main::i#3 keyboard_key_pressed::colidx#0 keyboard_key_pressed::rowidx#0 ] { { keyboard_key_pressed::key#0 = main::key#0 } { keyboard_key_pressed::return#0 = keyboard_key_pressed::return#2 } { keyboard_matrix_read::rowid#0 = keyboard_matrix_read::rowid#2 keyboard_key_pressed::rowidx#0 } { keyboard_matrix_read::return#0 = keyboard_matrix_read::return#2 } }  ) always clobbers reg byte a 
Statement [2] if(main::sc#2<$400+$3e8) goto main::@2 [ main::sc#2 ] (  [ main::sc#2 ] { }  ) always clobbers reg byte a 
Statement [5] if(*RASTER!=$ff) goto main::@4 [ ] (  [ ] { }  ) always clobbers reg byte a 
Statement [12] main::$4 = main::row_pressed_bits#2 & $80 [ main::row#2 main::screen#13 main::row_pressed_bits#2 main::col#2 main::$4 ] (  [ main::row#2 main::screen#13 main::row_pressed_bits#2 main::col#2 main::$4 ] { }  ) always clobbers reg byte a 
Statement [14] main::screen#13[main::col#2] = '0' [ main::row#2 main::screen#13 main::row_pressed_bits#2 main::col#2 ] (  [ main::row#2 main::screen#13 main::row_pressed_bits#2 main::col#2 ] { }  ) always clobbers reg byte a 
Statement [18] main::screen#1 = main::screen#13 + $28 [ main::row#2 main::screen#1 ] (  [ main::row#2 main::screen#1 ] { }  ) always clobbers reg byte a 
Statement [21] main::screen#2 = main::screen#1 + $28 [ main::screen#2 ] (  [ main::screen#2 ] { }  ) always clobbers reg byte a 
Statement [33] main::screen#2[main::i#3] = main::ch#2 [ main::screen#2 main::ch#2 main::i#3 ] (  [ main::screen#2 main::ch#2 main::i#3 ] { }  ) always clobbers reg byte a 
Statement [39] main::screen#2[main::i#4] = ' ' [ main::screen#2 main::i#4 ] (  [ main::screen#2 main::i#4 ] { }  ) always clobbers reg byte a 
Statement [42] main::screen#13[main::col#2] = '1' [ main::row#2 main::screen#13 main::row_pressed_bits#2 main::col#2 ] (  [ main::row#2 main::screen#13 main::row_pressed_bits#2 main::col#2 ] { }  ) always clobbers reg byte a 
Statement [43] *main::sc#2 = ' ' [ main::sc#2 ] (  [ main::sc#2 ] { }  ) always clobbers reg byte a reg byte y 
Statement [45] *((char *)CIA1+OFFSET_STRUCT_MOS6526_CIA_PORT_A_DDR) = $ff [ ] ( keyboard_init:4 [ ] { }  ) always clobbers reg byte a 
Statement [46] *((char *)CIA1+OFFSET_STRUCT_MOS6526_CIA_PORT_B_DDR) = 0 [ ] ( keyboard_init:4 [ ] { }  ) always clobbers reg byte a 
Statement [49] *((char *)CIA1) = keyboard_matrix_row_bitmask[keyboard_matrix_read::rowid#2] [ ] ( keyboard_matrix_read:8 [ main::row#2 main::screen#13 ] { { keyboard_matrix_read::rowid#1 = keyboard_matrix_read::rowid#2 main::row#2 } { keyboard_matrix_read::return#0 = keyboard_matrix_read::return#3 } }  keyboard_key_pressed:29::keyboard_matrix_read:57 [ main::screen#2 main::ch#2 main::i#3 keyboard_key_pressed::colidx#0 ] { { keyboard_key_pressed::key#0 = main::key#0 } { keyboard_key_pressed::return#0 = keyboard_key_pressed::return#2 } { keyboard_matrix_read::rowid#0 = keyboard_matrix_read::rowid#2 keyboard_key_pressed::rowidx#0 } { keyboard_matrix_read::return#0 = keyboard_matrix_read::return#2 } }  ) always clobbers reg byte a 
Statement [50] keyboard_matrix_read::return#0 = ~ *((char *)CIA1+OFFSET_STRUCT_MOS6526_CIA_PORT_B) [ keyboard_matrix_read::return#0 ] ( keyboard_matrix_read:8 [ main::row#2 main::screen#13 keyboard_matrix_read::return#0 ] { { keyboard_matrix_read::rowid#1 = keyboard_matrix_read::rowid#2 main::row#2 } { keyboard_matrix_read::return#0 = keyboard_matrix_read::return#3 } }  keyboard_key_pressed:29::keyboard_matrix_read:57 [ main::screen#2 main::ch#2 main::i#3 keyboard_key_pressed::colidx#0 keyboard_matrix_read::return#0 ] { { keyboard_key_pressed::key#0 = main::key#0 } { keyboard_key_pressed::return#0 = keyboard_key_pressed::return#2 } { keyboard_matrix_read::rowid#0 = keyboard_matrix_read::rowid#2 keyboard_key_pressed::rowidx#0 } { keyboard_matrix_read::return#0 = keyboard_matrix_read::return#2 } }  ) always clobbers reg byte a 
Statement [55] keyboard_key_pressed::rowidx#0 = keyboard_key_pressed::key#0 >> 3 [ keyboard_key_pressed::colidx#0 keyboard_key_pressed::rowidx#0 ] ( keyboard_key_pressed:29 [ main::screen#2 main::ch#2 main::i#3 keyboard_key_pressed::colidx#0 keyboard_key_pressed::rowidx#0 ] { { keyboard_key_pressed::key#0 = main::key#0 } { keyboard_key_pressed::return#0 = keyboard_key_pressed::return#2 } { keyboard_matrix_read::rowid#0 = keyboard_matrix_read::rowid#2 keyboard_key_pressed::rowidx#0 } { keyboard_matrix_read::return#0 = keyboard_matrix_read::return#2 } }  ) always clobbers reg byte a 
Potential registers zp[2]:25 [ main::sc#2 main::sc#1 ] : zp[2]:25 , 
Potential registers zp[1]:23 [ main::row#2 main::row#1 ] : zp[1]:23 , reg byte x , reg byte y , 
Potential registers zp[2]:16 [ main::screen#13 main::screen#1 ] : zp[2]:16 , 
Potential registers zp[1]:9 [ main::row_pressed_bits#2 main::row_pressed_bits#1 main::row_pressed_bits#0 ] : zp[1]:9 , reg byte x , reg byte y , 
Potential registers zp[1]:4 [ main::col#2 main::col#1 ] : zp[1]:4 , reg byte x , reg byte y , 
Potential registers zp[1]:22 [ main::ch#2 main::ch#1 ] : zp[1]:22 , reg byte x , reg byte y , 
Potential registers zp[1]:12 [ main::i#4 main::i#3 main::i#6 main::i#1 main::i#2 ] : zp[1]:12 , reg byte x , reg byte y , 
Potential registers zp[1]:2 [ keyboard_matrix_read::rowid#2 keyboard_matrix_read::rowid#0 keyboard_matrix_read::rowid#1 ] : zp[1]:2 , reg byte a , reg byte x , reg byte y , 
Potential registers zp[1]:18 [ keyboard_matrix_read::return#3 ] : zp[1]:18 , reg byte a , reg byte x , reg byte y , 
Potential registers zp[1]:5 [ main::$4 ] : zp[1]:5 , reg byte a , reg byte x , reg byte y , 
Potential registers zp[2]:27 [ main::screen#2 ] : zp[2]:27 , 
Potential registers zp[1]:10 [ keyboard_get_keycode::ch#0 ] : zp[1]:10 , reg byte a , reg byte x , reg byte y , 
Potential registers zp[1]:19 [ keyboard_get_keycode::return#2 ] : zp[1]:19 , reg byte a , reg byte x , reg byte y , 
Potential registers zp[1]:24 [ main::key#0 ] : zp[1]:24 , reg byte a , reg byte x , reg byte y , 
Potential registers zp[1]:11 [ keyboard_key_pressed::key#0 ] : zp[1]:11 , reg byte a , reg byte x , reg byte y , 
Potential registers zp[1]:20 [ keyboard_key_pressed::return#2 ] : zp[1]:20 , reg byte a , reg byte x , reg byte y , 
Potential registers zp[1]:21 [ main::$14 ] : zp[1]:21 , reg byte a , reg byte x , reg byte y , 
Potential registers zp[1]:3 [ keyboard_matrix_read::return#0 ] : zp[1]:3 , reg byte a , reg byte x , reg byte y , 
Potential registers zp[1]:13 [ keyboard_get_keycode::return#0 ] : zp[1]:13 , reg byte a , reg byte x , reg byte y , 
Potential registers zp[1]:15 [ keyboard_key_pressed::colidx#0 ] : zp[1]:15 , reg byte x , reg byte y , 
Potential registers zp[1]:6 [ keyboard_key_pressed::rowidx#0 ] : zp[1]:6 , reg byte a , reg byte x , reg byte y , 
Potential registers zp[1]:7 [ keyboard_matrix_read::return#2 ] : zp[1]:7 , reg byte a , reg byte x , reg byte y , 
Potential registers zp[1]:8 [ keyboard_key_pressed::$2 ] : zp[1]:8 , reg byte a , reg byte x , reg byte y , 
Potential registers zp[1]:14 [ keyboard_key_pressed::return#0 ] : zp[1]:14 , reg byte a , reg byte x , reg byte y , 

REGISTER UPLIFT SCOPES
Uplift Scope [keyboard_matrix_read] 13,307: zp[1]:2 [ keyboard_matrix_read::rowid#2 keyboard_matrix_read::rowid#0 keyboard_matrix_read::rowid#1 ] 2,775.75: zp[1]:3 [ keyboard_matrix_read::return#0 ] 2,002: zp[1]:7 [ keyboard_matrix_read::return#2 ] 202: zp[1]:18 [ keyboard_matrix_read::return#3 ] 
Uplift Scope [main] 2,168.83: zp[1]:4 [ main::col#2 main::col#1 ] 2,002: zp[1]:5 [ main::$4 ] 1,490.13: zp[1]:9 [ main::row_pressed_bits#2 main::row_pressed_bits#1 main::row_pressed_bits#0 ] 765.92: zp[1]:12 [ main::i#4 main::i#3 main::i#6 main::i#1 main::i#2 ] 240.54: zp[2]:16 [ main::screen#13 main::screen#1 ] 202: zp[1]:21 [ main::$14 ] 180.36: zp[1]:22 [ main::ch#2 main::ch#1 ] 173.14: zp[1]:23 [ main::row#2 main::row#1 ] 151.5: zp[1]:24 [ main::key#0 ] 36.67: zp[2]:25 [ main::sc#2 main::sc#1 ] 10.14: zp[2]:27 [ main::screen#2 ] 
Uplift Scope [keyboard_key_pressed] 2,002: zp[1]:6 [ keyboard_key_pressed::rowidx#0 ] 2,002: zp[1]:8 [ keyboard_key_pressed::$2 ] 1,051.5: zp[1]:11 [ keyboard_key_pressed::key#0 ] 367.33: zp[1]:14 [ keyboard_key_pressed::return#0 ] 333.67: zp[1]:15 [ keyboard_key_pressed::colidx#0 ] 202: zp[1]:20 [ keyboard_key_pressed::return#2 ] 
Uplift Scope [keyboard_get_keycode] 1,102: zp[1]:10 [ keyboard_get_keycode::ch#0 ] 367.33: zp[1]:13 [ keyboard_get_keycode::return#0 ] 202: zp[1]:19 [ keyboard_get_keycode::return#2 ] 
Uplift Scope [keyboard_init] 
Uplift Scope [MOS6526_CIA] 
Uplift Scope [MOS6569_VICII] 
Uplift Scope [MOS6581_SID] 
Uplift Scope [] 

Uplifting [keyboard_matrix_read] best 99128 combination reg byte x [ keyboard_matrix_read::rowid#2 keyboard_matrix_read::rowid#0 keyboard_matrix_read::rowid#1 ] reg byte a [ keyboard_matrix_read::return#0 ] reg byte a [ keyboard_matrix_read::return#2 ] reg byte a [ keyboard_matrix_read::return#3 ] 
Limited combination testing to 100 combinations of 256 possible.
Uplifting [main] best 80028 combination reg byte y [ main::col#2 main::col#1 ] reg byte a [ main::$4 ] reg byte x [ main::row_pressed_bits#2 main::row_pressed_bits#1 main::row_pressed_bits#0 ] zp[1]:12 [ main::i#4 main::i#3 main::i#6 main::i#1 main::i#2 ] zp[2]:16 [ main::screen#13 main::screen#1 ] zp[1]:21 [ main::$14 ] zp[1]:22 [ main::ch#2 main::ch#1 ] zp[1]:23 [ main::row#2 main::row#1 ] zp[1]:24 [ main::key#0 ] zp[2]:25 [ main::sc#2 main::sc#1 ] zp[2]:27 [ main::screen#2 ] 
Limited combination testing to 100 combinations of 15552 possible.
Uplifting [keyboard_key_pressed] best 79417 combination reg byte a [ keyboard_key_pressed::rowidx#0 ] zp[1]:8 [ keyboard_key_pressed::$2 ] reg byte x [ keyboard_key_pressed::key#0 ] reg byte a [ keyboard_key_pressed::return#0 ] zp[1]:15 [ keyboard_key_pressed::colidx#0 ] zp[1]:20 [ keyboard_key_pressed::return#2 ] 
Limited combination testing to 100 combinations of 3072 possible.
Uplifting [keyboard_get_keycode] best 78211 combination reg byte x [ keyboard_get_keycode::ch#0 ] reg byte a [ keyboard_get_keycode::return#0 ] reg byte a [ keyboard_get_keycode::return#2 ] 
Uplifting [keyboard_init] best 78211 combination 
Uplifting [MOS6526_CIA] best 78211 combination 
Uplifting [MOS6569_VICII] best 78211 combination 
Uplifting [MOS6581_SID] best 78211 combination 
Uplifting [] best 78211 combination 
Attempting to uplift remaining variables inzp[1]:8 [ keyboard_key_pressed::$2 ]
Uplifting [keyboard_key_pressed] best 78205 combination reg byte a [ keyboard_key_pressed::$2 ] 
Attempting to uplift remaining variables inzp[1]:12 [ main::i#4 main::i#3 main::i#6 main::i#1 main::i#2 ]
Uplifting [main] best 78205 combination zp[1]:12 [ main::i#4 main::i#3 main::i#6 main::i#1 main::i#2 ] 
Attempting to uplift remaining variables inzp[1]:15 [ keyboard_key_pressed::colidx#0 ]
Uplifting [keyboard_key_pressed] best 78203 combination reg byte y [ keyboard_key_pressed::colidx#0 ] 
Attempting to uplift remaining variables inzp[1]:20 [ keyboard_key_pressed::return#2 ]
Uplifting [keyboard_key_pressed] best 77603 combination reg byte a [ keyboard_key_pressed::return#2 ] 
Attempting to uplift remaining variables inzp[1]:21 [ main::$14 ]
Uplifting [main] best 77203 combination reg byte a [ main::$14 ] 
Attempting to uplift remaining variables inzp[1]:22 [ main::ch#2 main::ch#1 ]
Uplifting [main] best 77203 combination zp[1]:22 [ main::ch#2 main::ch#1 ] 
Attempting to uplift remaining variables inzp[1]:23 [ main::row#2 main::row#1 ]
Uplifting [main] best 77203 combination zp[1]:23 [ main::row#2 main::row#1 ] 
Attempting to uplift remaining variables inzp[1]:24 [ main::key#0 ]
Uplifting [main] best 76503 combination reg byte a [ main::key#0 ] 
Coalescing zero page register [ zp[2]:16 [ main::screen#13 main::screen#1 ] ] with [ zp[2]:27 [ main::screen#2 ] ] - score: 1
Allocated (was zp[1]:12) zp[1]:2 [ main::i#4 main::i#3 main::i#6 main::i#1 main::i#2 ]
Allocated (was zp[2]:16) zp[2]:3 [ main::screen#13 main::screen#1 main::screen#2 ]
Allocated (was zp[1]:22) zp[1]:5 [ main::ch#2 main::ch#1 ]
Allocated (was zp[1]:23) zp[1]:6 [ main::row#2 main::row#1 ]
Allocated (was zp[2]:25) zp[2]:7 [ main::sc#2 main::sc#1 ]

ASSEMBLER BEFORE OPTIMIZATION
  // File Comments
// Test keyboard input - in the keyboard matrix and mapping screen codes to key codes
  // Upstart
  // Commodore 64 PRG executable file
.file [name="test-keyboard.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
  .const KEY_3 = 8
  .const KEY_W = 9
  .const KEY_A = $a
  .const KEY_4 = $b
  .const KEY_Z = $c
  .const KEY_S = $d
  .const KEY_E = $e
  .const KEY_5 = $10
  .const KEY_R = $11
  .const KEY_D = $12
  .const KEY_6 = $13
  .const KEY_C = $14
  .const KEY_F = $15
  .const KEY_T = $16
  .const KEY_X = $17
  .const KEY_7 = $18
  .const KEY_Y = $19
  .const KEY_G = $1a
  .const KEY_8 = $1b
  .const KEY_B = $1c
  .const KEY_H = $1d
  .const KEY_U = $1e
  .const KEY_V = $1f
  .const KEY_9 = $20
  .const KEY_I = $21
  .const KEY_J = $22
  .const KEY_0 = $23
  .const KEY_M = $24
  .const KEY_K = $25
  .const KEY_O = $26
  .const KEY_N = $27
  .const KEY_PLUS = $28
  .const KEY_P = $29
  .const KEY_L = $2a
  .const KEY_MINUS = $2b
  .const KEY_DOT = $2c
  .const KEY_COLON = $2d
  .const KEY_AT = $2e
  .const KEY_COMMA = $2f
  .const KEY_POUND = $30
  .const KEY_ASTERISK = $31
  .const KEY_SEMICOLON = $32
  .const KEY_EQUALS = $35
  .const KEY_ARROW_UP = $36
  .const KEY_SLASH = $37
  .const KEY_1 = $38
  .const KEY_ARROW_LEFT = $39
  .const KEY_2 = $3b
  .const KEY_SPACE = $3c
  .const KEY_Q = $3e
  .const OFFSET_STRUCT_MOS6526_CIA_PORT_A_DDR = 2
  .const OFFSET_STRUCT_MOS6526_CIA_PORT_B_DDR = 3
  .const OFFSET_STRUCT_MOS6526_CIA_PORT_B = 1
  /// $D012 RASTER Raster counter
  .label RASTER = $d012
  /// The CIA#1: keyboard matrix, joystick #1/#2
  .label CIA1 = $dc00
.segment Code
  // main
main: {
    .label sc = 7
    .label screen = 3
    .label row = 6
    .label ch = 5
    // Checks all specific chars $00-$3f
    .label i = 2
    // [1] phi from main to main::@1 [phi:main->main::@1]
  __b1_from_main:
    // [1] phi main::sc#2 = (char *) 1024 [phi:main->main::@1#0] -- pbuz1=pbuc1 
    lda #<$400
    sta.z sc
    lda #>$400
    sta.z sc+1
    jmp __b1
  // Clear screen
    // main::@1
  __b1:
    // [2] if(main::sc#2<$400+$3e8) goto main::@2 -- pbuz1_lt_vwuc1_then_la1 
    lda.z sc+1
    cmp #>$400+$3e8
    bcc __b2
    bne !+
    lda.z sc
    cmp #<$400+$3e8
    bcc __b2
  !:
    // [3] phi from main::@1 to main::@3 [phi:main::@1->main::@3]
  __b3_from___b1:
    jmp __b3
    // main::@3
  __b3:
    // [4] call keyboard_init
    // Init keyboard
    jsr keyboard_init
    jmp __b4
    // main::@4
  __b4:
    // [5] if(*RASTER!=$ff) goto main::@4 -- _deref_pbuc1_neq_vbuc2_then_la1 
    lda #$ff
    cmp RASTER
    bne __b4
    // [6] phi from main::@4 to main::@5 [phi:main::@4->main::@5]
  __b5_from___b4:
    // [6] phi main::screen#13 = (char *) 1024 [phi:main::@4->main::@5#0] -- pbuz1=pbuc1 
    lda #<$400
    sta.z screen
    lda #>$400
    sta.z screen+1
    // [6] phi main::row#2 = 0 [phi:main::@4->main::@5#1] -- vbuz1=vbuc1 
    lda #0
    sta.z row
    jmp __b5
  // Read & print keyboard matrix
    // [6] phi from main::@10 to main::@5 [phi:main::@10->main::@5]
  __b5_from___b10:
    // [6] phi main::screen#13 = main::screen#1 [phi:main::@10->main::@5#0] -- register_copy 
    // [6] phi main::row#2 = main::row#1 [phi:main::@10->main::@5#1] -- register_copy 
    jmp __b5
    // main::@5
  __b5:
    // [7] keyboard_matrix_read::rowid#1 = main::row#2 -- vbuxx=vbuz1 
    ldx.z row
    // [8] call keyboard_matrix_read
    // [48] phi from main::@5 to keyboard_matrix_read [phi:main::@5->keyboard_matrix_read]
  keyboard_matrix_read_from___b5:
    // [48] phi keyboard_matrix_read::rowid#2 = keyboard_matrix_read::rowid#1 [phi:main::@5->keyboard_matrix_read#0] -- register_copy 
    jsr keyboard_matrix_read
    // [9] keyboard_matrix_read::return#3 = keyboard_matrix_read::return#0
    jmp __b17
    // main::@17
  __b17:
    // [10] main::row_pressed_bits#0 = keyboard_matrix_read::return#3 -- vbuxx=vbuaa 
    tax
    // [11] phi from main::@17 to main::@6 [phi:main::@17->main::@6]
  __b6_from___b17:
    // [11] phi main::col#2 = 0 [phi:main::@17->main::@6#0] -- vbuyy=vbuc1 
    ldy #0
    // [11] phi main::row_pressed_bits#2 = main::row_pressed_bits#0 [phi:main::@17->main::@6#1] -- register_copy 
    jmp __b6
    // [11] phi from main::@8 to main::@6 [phi:main::@8->main::@6]
  __b6_from___b8:
    // [11] phi main::col#2 = main::col#1 [phi:main::@8->main::@6#0] -- register_copy 
    // [11] phi main::row_pressed_bits#2 = main::row_pressed_bits#1 [phi:main::@8->main::@6#1] -- register_copy 
    jmp __b6
    // main::@6
  __b6:
    // [12] main::$4 = main::row_pressed_bits#2 & $80 -- vbuaa=vbuxx_band_vbuc1 
    txa
    and #$80
    // [13] if(main::$4!=0) goto main::@7 -- vbuaa_neq_0_then_la1 
    cmp #0
    bne __b7
    jmp __b9
    // main::@9
  __b9:
    // [14] main::screen#13[main::col#2] = '0' -- pbuz1_derefidx_vbuyy=vbuc1 
    lda #'0'
    sta (screen),y
    jmp __b8
    // main::@8
  __b8:
    // [15] main::row_pressed_bits#1 = main::row_pressed_bits#2 << 1 -- vbuxx=vbuxx_rol_1 
    txa
    asl
    tax
    // [16] main::col#1 = ++ main::col#2 -- vbuyy=_inc_vbuyy 
    iny
    // [17] if(main::col#1!=8) goto main::@6 -- vbuyy_neq_vbuc1_then_la1 
    cpy #8
    bne __b6_from___b8
    jmp __b10
    // main::@10
  __b10:
    // [18] main::screen#1 = main::screen#13 + $28 -- pbuz1=pbuz1_plus_vbuc1 
    lda #$28
    clc
    adc.z screen
    sta.z screen
    bcc !+
    inc.z screen+1
  !:
    // [19] main::row#1 = ++ main::row#2 -- vbuz1=_inc_vbuz1 
    inc.z row
    // [20] if(main::row#1!=8) goto main::@5 -- vbuz1_neq_vbuc1_then_la1 
    lda #8
    cmp.z row
    bne __b5_from___b10
    jmp __b11
    // main::@11
  __b11:
    // [21] main::screen#2 = main::screen#1 + $28 -- pbuz1=pbuz1_plus_vbuc1 
    lda #$28
    clc
    adc.z screen
    sta.z screen
    bcc !+
    inc.z screen+1
  !:
    // [22] phi from main::@11 to main::@12 [phi:main::@11->main::@12]
  __b12_from___b11:
    // [22] phi main::i#3 = 0 [phi:main::@11->main::@12#0] -- vbuz1=vbuc1 
    lda #0
    sta.z i
    // [22] phi main::ch#2 = 0 [phi:main::@11->main::@12#1] -- vbuz1=vbuc1 
    lda #0
    sta.z ch
    jmp __b12
    // [22] phi from main::@13 to main::@12 [phi:main::@13->main::@12]
  __b12_from___b13:
    // [22] phi main::i#3 = main::i#6 [phi:main::@13->main::@12#0] -- register_copy 
    // [22] phi main::ch#2 = main::ch#1 [phi:main::@13->main::@12#1] -- register_copy 
    jmp __b12
    // main::@12
  __b12:
    // [23] keyboard_get_keycode::ch#0 = main::ch#2 -- vbuxx=vbuz1 
    ldx.z ch
    // [24] call keyboard_get_keycode
    jsr keyboard_get_keycode
    // [25] keyboard_get_keycode::return#2 = keyboard_get_keycode::return#0
    jmp __b18
    // main::@18
  __b18:
    // [26] main::key#0 = keyboard_get_keycode::return#2
    // [27] if(main::key#0==$3f) goto main::@13 -- vbuaa_eq_vbuc1_then_la1 
    cmp #$3f
    beq __b13_from___b18
    jmp __b14
    // main::@14
  __b14:
    // [28] keyboard_key_pressed::key#0 = main::key#0 -- vbuxx=vbuaa 
    tax
    // [29] call keyboard_key_pressed
    jsr keyboard_key_pressed
    // [30] keyboard_key_pressed::return#2 = keyboard_key_pressed::return#0
    jmp __b19
    // main::@19
  __b19:
    // [31] main::$14 = keyboard_key_pressed::return#2
    // [32] if(main::$14==0) goto main::@13 -- vbuaa_eq_0_then_la1 
    cmp #0
    beq __b13_from___b19
    jmp __b15
    // main::@15
  __b15:
    // [33] main::screen#2[main::i#3] = main::ch#2 -- pbuz1_derefidx_vbuz2=vbuz3 
    lda.z ch
    ldy.z i
    sta (screen),y
    // [34] main::i#1 = ++ main::i#3 -- vbuz1=_inc_vbuz1 
    inc.z i
    // [35] phi from main::@15 main::@18 main::@19 to main::@13 [phi:main::@15/main::@18/main::@19->main::@13]
  __b13_from___b15:
  __b13_from___b18:
  __b13_from___b19:
    // [35] phi main::i#6 = main::i#1 [phi:main::@15/main::@18/main::@19->main::@13#0] -- register_copy 
    jmp __b13
    // main::@13
  __b13:
    // [36] main::ch#1 = ++ main::ch#2 -- vbuz1=_inc_vbuz1 
    inc.z ch
    // [37] if(main::ch#1!=$40) goto main::@12 -- vbuz1_neq_vbuc1_then_la1 
    lda #$40
    cmp.z ch
    bne __b12_from___b13
    // [38] phi from main::@13 main::@16 to main::@16 [phi:main::@13/main::@16->main::@16]
  __b16_from___b13:
  __b16_from___b16:
    // [38] phi main::i#4 = main::i#6 [phi:main::@13/main::@16->main::@16#0] -- register_copy 
    jmp __b16
  // Add some spaces
    // main::@16
  __b16:
    // [39] main::screen#2[main::i#4] = ' ' -- pbuz1_derefidx_vbuz2=vbuc1 
    lda #' '
    ldy.z i
    sta (screen),y
    // [40] main::i#2 = ++ main::i#4 -- vbuz1=_inc_vbuz1 
    inc.z i
    // [41] if(main::i#2<5) goto main::@16 -- vbuz1_lt_vbuc1_then_la1 
    lda.z i
    cmp #5
    bcc __b16_from___b16
    jmp __b4
    // main::@7
  __b7:
    // [42] main::screen#13[main::col#2] = '1' -- pbuz1_derefidx_vbuyy=vbuc1 
    lda #'1'
    sta (screen),y
    jmp __b8
    // main::@2
  __b2:
    // [43] *main::sc#2 = ' ' -- _deref_pbuz1=vbuc1 
    lda #' '
    ldy #0
    sta (sc),y
    // [44] main::sc#1 = ++ main::sc#2 -- pbuz1=_inc_pbuz1 
    inc.z sc
    bne !+
    inc.z sc+1
  !:
    // [1] phi from main::@2 to main::@1 [phi:main::@2->main::@1]
  __b1_from___b2:
    // [1] phi main::sc#2 = main::sc#1 [phi:main::@2->main::@1#0] -- register_copy 
    jmp __b1
}
  // keyboard_init
// Initialize keyboard reading by setting CIA#1 Data Direction Registers
keyboard_init: {
    // [45] *((char *)CIA1+OFFSET_STRUCT_MOS6526_CIA_PORT_A_DDR) = $ff -- _deref_pbuc1=vbuc2 
    // Keyboard Matrix Columns Write Mode
    lda #$ff
    sta CIA1+OFFSET_STRUCT_MOS6526_CIA_PORT_A_DDR
    // [46] *((char *)CIA1+OFFSET_STRUCT_MOS6526_CIA_PORT_B_DDR) = 0 -- _deref_pbuc1=vbuc2 
    // Keyboard Matrix Columns Read Mode
    lda #0
    sta CIA1+OFFSET_STRUCT_MOS6526_CIA_PORT_B_DDR
    jmp __breturn
    // keyboard_init::@return
  __breturn:
    // [47] return 
    rts
}
  // keyboard_matrix_read
// Read a single row of the keyboard matrix
// The row ID (0-7) of the keyboard matrix row to read. See the C64 key matrix for row IDs.
// Returns the keys pressed on the row as bits according to the C64 key matrix.
// Notice: If the C64 normal interrupt is still running it will occasionally interrupt right between the read & write
// leading to erroneous readings. You must disable the normal interrupt or sei/cli around calls to the keyboard matrix reader.
// __register(A) char keyboard_matrix_read(__register(X) char rowid)
keyboard_matrix_read: {
    // [49] *((char *)CIA1) = keyboard_matrix_row_bitmask[keyboard_matrix_read::rowid#2] -- _deref_pbuc1=pbuc2_derefidx_vbuxx 
    lda keyboard_matrix_row_bitmask,x
    sta CIA1
    // [50] keyboard_matrix_read::return#0 = ~ *((char *)CIA1+OFFSET_STRUCT_MOS6526_CIA_PORT_B) -- vbuaa=_bnot__deref_pbuc1 
    lda CIA1+OFFSET_STRUCT_MOS6526_CIA_PORT_B
    eor #$ff
    jmp __breturn
    // keyboard_matrix_read::@return
  __breturn:
    // [51] return 
    rts
}
  // keyboard_get_keycode
// Get the keycode corresponding to a specific screen code character
// ch is the character to get the key code for ($00-$3f)
// Returns the key code corresponding to the passed character. Only characters with a non-shifted key are handled.
// If there is no non-shifted key representing the char $3f is returned (representing RUN/STOP) .
// __register(A) char keyboard_get_keycode(__register(X) char ch)
keyboard_get_keycode: {
    // [52] keyboard_get_keycode::return#0 = keyboard_char_keycodes[keyboard_get_keycode::ch#0] -- vbuaa=pbuc1_derefidx_vbuxx 
    lda keyboard_char_keycodes,x
    jmp __breturn
    // keyboard_get_keycode::@return
  __breturn:
    // [53] return 
    rts
}
  // keyboard_key_pressed
// Determines whether a specific key is currently pressed by accessing the matrix directly
// The key is a keyboard code defined from the keyboard matrix by %00rrrccc, where rrr is the row ID (0-7) and ccc is the column ID (0-7)
// All keys exist as as KEY_XXX constants.
// Returns zero if the key is not pressed and a non-zero value if the key is currently pressed
// __register(A) char keyboard_key_pressed(__register(X) char key)
keyboard_key_pressed: {
    // [54] keyboard_key_pressed::colidx#0 = keyboard_key_pressed::key#0 & 7 -- vbuyy=vbuxx_band_vbuc1 
    txa
    and #7
    tay
    // [55] keyboard_key_pressed::rowidx#0 = keyboard_key_pressed::key#0 >> 3 -- vbuaa=vbuxx_ror_3 
    txa
    lsr
    lsr
    lsr
    // [56] keyboard_matrix_read::rowid#0 = keyboard_key_pressed::rowidx#0 -- vbuxx=vbuaa 
    tax
    // [57] call keyboard_matrix_read
    // [48] phi from keyboard_key_pressed to keyboard_matrix_read [phi:keyboard_key_pressed->keyboard_matrix_read]
  keyboard_matrix_read_from_keyboard_key_pressed:
    // [48] phi keyboard_matrix_read::rowid#2 = keyboard_matrix_read::rowid#0 [phi:keyboard_key_pressed->keyboard_matrix_read#0] -- register_copy 
    jsr keyboard_matrix_read
    // [58] keyboard_matrix_read::return#2 = keyboard_matrix_read::return#0
    jmp __b1
    // keyboard_key_pressed::@1
  __b1:
    // [59] keyboard_key_pressed::$2 = keyboard_matrix_read::return#2
    // [60] keyboard_key_pressed::return#0 = keyboard_key_pressed::$2 & keyboard_matrix_col_bitmask[keyboard_key_pressed::colidx#0] -- vbuaa=vbuaa_band_pbuc1_derefidx_vbuyy 
    and keyboard_matrix_col_bitmask,y
    jmp __breturn
    // keyboard_key_pressed::@return
  __breturn:
    // [61] return 
    rts
}
  // File Data
.segment Data
  // Keycodes for each screen code character from $00-$3f.
  // Chars that do not have an unmodified keycode return $3f (representing RUN/STOP).
  keyboard_char_keycodes: .byte KEY_AT, KEY_A, KEY_B, KEY_C, KEY_D, KEY_E, KEY_F, KEY_G, KEY_H, KEY_I, KEY_J, KEY_K, KEY_L, KEY_M, KEY_N, KEY_O, KEY_P, KEY_Q, KEY_R, KEY_S, KEY_T, KEY_U, KEY_V, KEY_W, KEY_X, KEY_Y, KEY_Z, $3f, KEY_POUND, $3f, KEY_ARROW_UP, KEY_ARROW_LEFT, KEY_SPACE, $3f, $3f, $3f, $3f, $3f, $3f, $3f, $3f, $3f, KEY_ASTERISK, KEY_PLUS, KEY_COMMA, KEY_MINUS, KEY_DOT, KEY_SLASH, KEY_0, KEY_1, KEY_2, KEY_3, KEY_4, KEY_5, KEY_6, KEY_7, KEY_8, KEY_9, KEY_COLON, KEY_SEMICOLON, $3f, KEY_EQUALS, $3f, $3f
  // Keyboard row bitmask as expected by CIA#1 Port A when reading a specific keyboard matrix row (rows are numbered 0-7)
  keyboard_matrix_row_bitmask: .byte $fe, $fd, $fb, $f7, $ef, $df, $bf, $7f
  // Keyboard matrix column bitmasks for a specific keybooard matrix column when reading the keyboard. (columns are numbered 0-7)
  keyboard_matrix_col_bitmask: .byte 1, 2, 4, 8, $10, $20, $40, $80

ASSEMBLER OPTIMIZATIONS
Removing instruction jmp __b1
Removing instruction jmp __b3
Removing instruction jmp __b4
Removing instruction jmp __b5
Removing instruction jmp __b17
Removing instruction jmp __b6
Removing instruction jmp __b9
Removing instruction jmp __b8
Removing instruction jmp __b10
Removing instruction jmp __b11
Removing instruction jmp __b12
Removing instruction jmp __b18
Removing instruction jmp __b14
Removing instruction jmp __b19
Removing instruction jmp __b15
Removing instruction jmp __b13
Removing instruction jmp __b16
Removing instruction jmp __breturn
Removing instruction jmp __breturn
Removing instruction jmp __breturn
Removing instruction jmp __b1
Removing instruction jmp __breturn
Succesful ASM optimization Pass5NextJumpElimination
Removing instruction lda #0
Succesful ASM optimization Pass5UnnecesaryLoadElimination
Replacing label __b6_from___b8 with __b6
Replacing label __b5_from___b10 with __b5
Replacing label __b13_from___b18 with __b13
Replacing label __b13_from___b19 with __b13
Replacing label __b12_from___b13 with __b12
Removing instruction __b3_from___b1:
Removing instruction __b5_from___b10:
Removing instruction __b6_from___b8:
Removing instruction __b12_from___b13:
Removing instruction __b13_from___b15:
Removing instruction __b13_from___b18:
Removing instruction __b13_from___b19:
Removing instruction __b16_from___b13:
Succesful ASM optimization Pass5RedundantLabelElimination
Removing instruction __b1_from_main:
Removing instruction __b3:
Removing instruction __b5_from___b4:
Removing instruction keyboard_matrix_read_from___b5:
Removing instruction __b17:
Removing instruction __b6_from___b17:
Removing instruction __b9:
Removing instruction __b10:
Removing instruction __b11:
Removing instruction __b12_from___b11:
Removing instruction __b18:
Removing instruction __b14:
Removing instruction __b19:
Removing instruction __b15:
Removing instruction __b16:
Removing instruction __b1_from___b2:
Removing instruction __breturn:
Removing instruction __breturn:
Removing instruction __breturn:
Removing instruction keyboard_matrix_read_from_keyboard_key_pressed:
Removing instruction __b1:
Removing instruction __breturn:
Succesful ASM optimization Pass5UnusedLabelElimination
Relabelling long label __b16_from___b16 to __b3
Succesful ASM optimization Pass5RelabelLongLabels
Removing instruction jmp __b5
Removing instruction jmp __b6
Removing instruction jmp __b12
Succesful ASM optimization Pass5NextJumpElimination
Fixing long branch [82] bcc __b2 to bcs
Fixing long branch [88] bcc __b2 to bcs

FINAL SYMBOL TABLE
__constant struct MOS6526_CIA * const CIA1 = (struct MOS6526_CIA *) 56320
__constant const char KEY_0 = $23
__constant const char KEY_1 = $38
__constant const char KEY_2 = $3b
__constant const char KEY_3 = 8
__constant const char KEY_4 = $b
__constant const char KEY_5 = $10
__constant const char KEY_6 = $13
__constant const char KEY_7 = $18
__constant const char KEY_8 = $1b
__constant const char KEY_9 = $20
__constant const char KEY_A = $a
__constant const char KEY_ARROW_LEFT = $39
__constant const char KEY_ARROW_UP = $36
__constant const char KEY_ASTERISK = $31
__constant const char KEY_AT = $2e
__constant const char KEY_B = $1c
__constant const char KEY_C = $14
__constant const char KEY_COLON = $2d
__constant const char KEY_COMMA = $2f
__constant const char KEY_D = $12
__constant const char KEY_DOT = $2c
__constant const char KEY_E = $e
__constant const char KEY_EQUALS = $35
__constant const char KEY_F = $15
__constant const char KEY_G = $1a
__constant const char KEY_H = $1d
__constant const char KEY_I = $21
__constant const char KEY_J = $22
__constant const char KEY_K = $25
__constant const char KEY_L = $2a
__constant const char KEY_M = $24
__constant const char KEY_MINUS = $2b
__constant const char KEY_N = $27
__constant const char KEY_O = $26
__constant const char KEY_P = $29
__constant const char KEY_PLUS = $28
__constant const char KEY_POUND = $30
__constant const char KEY_Q = $3e
__constant const char KEY_R = $11
__constant const char KEY_S = $d
__constant const char KEY_SEMICOLON = $32
__constant const char KEY_SLASH = $37
__constant const char KEY_SPACE = $3c
__constant const char KEY_T = $16
__constant const char KEY_U = $1e
__constant const char KEY_V = $1f
__constant const char KEY_W = 9
__constant const char KEY_X = $17
__constant const char KEY_Y = $19
__constant const char KEY_Z = $c
__constant char OFFSET_STRUCT_MOS6526_CIA_PORT_A_DDR = 2
__constant char OFFSET_STRUCT_MOS6526_CIA_PORT_B = 1
__constant char OFFSET_STRUCT_MOS6526_CIA_PORT_B_DDR = 3
__constant char * const RASTER = (char *) 53266
__constant const char keyboard_char_keycodes[] = { KEY_AT, KEY_A, KEY_B, KEY_C, KEY_D, KEY_E, KEY_F, KEY_G, KEY_H, KEY_I, KEY_J, KEY_K, KEY_L, KEY_M, KEY_N, KEY_O, KEY_P, KEY_Q, KEY_R, KEY_S, KEY_T, KEY_U, KEY_V, KEY_W, KEY_X, KEY_Y, KEY_Z, $3f, KEY_POUND, $3f, KEY_ARROW_UP, KEY_ARROW_LEFT, KEY_SPACE, $3f, $3f, $3f, $3f, $3f, $3f, $3f, $3f, $3f, KEY_ASTERISK, KEY_PLUS, KEY_COMMA, KEY_MINUS, KEY_DOT, KEY_SLASH, KEY_0, KEY_1, KEY_2, KEY_3, KEY_4, KEY_5, KEY_6, KEY_7, KEY_8, KEY_9, KEY_COLON, KEY_SEMICOLON, $3f, KEY_EQUALS, $3f, $3f }
char keyboard_get_keycode(char ch)
char keyboard_get_keycode::ch
char keyboard_get_keycode::ch#0 // reg byte x 1102.0
char keyboard_get_keycode::return
char keyboard_get_keycode::return#0 // reg byte a 367.33333333333337
char keyboard_get_keycode::return#2 // reg byte a 202.0
void keyboard_init()
char keyboard_key_pressed(char key)
char keyboard_key_pressed::$2 // reg byte a 2002.0
char keyboard_key_pressed::colidx
char keyboard_key_pressed::colidx#0 // reg byte y 333.6666666666667
char keyboard_key_pressed::key
char keyboard_key_pressed::key#0 // reg byte x 1051.5
char keyboard_key_pressed::return
char keyboard_key_pressed::return#0 // reg byte a 367.33333333333337
char keyboard_key_pressed::return#2 // reg byte a 202.0
char keyboard_key_pressed::rowidx
char keyboard_key_pressed::rowidx#0 // reg byte a 2002.0
__constant char keyboard_matrix_col_bitmask[8] = { 1, 2, 4, 8, $10, $20, $40, $80 }
char keyboard_matrix_read(char rowid)
char keyboard_matrix_read::return
char keyboard_matrix_read::return#0 // reg byte a 2775.75
char keyboard_matrix_read::return#2 // reg byte a 2002.0
char keyboard_matrix_read::return#3 // reg byte a 202.0
char keyboard_matrix_read::row_pressed_bits
char keyboard_matrix_read::rowid
char keyboard_matrix_read::rowid#0 // reg byte x 2002.0
char keyboard_matrix_read::rowid#1 // reg byte x 202.0
char keyboard_matrix_read::rowid#2 // reg byte x 11103.0
__constant char keyboard_matrix_row_bitmask[8] = { $fe, $fd, $fb, $f7, $ef, $df, $bf, $7f }
void main()
char main::$14 // reg byte a 202.0
char main::$4 // reg byte a 2002.0
char main::ch
char main::ch#1 // ch zp[1]:5 151.5
char main::ch#2 // ch zp[1]:5 28.857142857142858
char main::col
char main::col#1 // reg byte y 1501.5
char main::col#2 // reg byte y 667.3333333333334
char main::i
char main::i#1 // i zp[1]:2 202.0
char main::i#2 // i zp[1]:2 151.5
char main::i#3 // i zp[1]:2 42.08333333333333
char main::i#4 // i zp[1]:2 202.0
char main::i#6 // i zp[1]:2 168.33333333333331
char main::key
char main::key#0 // reg byte a 151.5
char main::row
char main::row#1 // row zp[1]:6 151.5
char main::row#2 // row zp[1]:6 21.642857142857142
char main::row_pressed_bits
char main::row_pressed_bits#0 // reg byte x 202.0
char main::row_pressed_bits#1 // reg byte x 667.3333333333334
char main::row_pressed_bits#2 // reg byte x 620.8
char *main::sc
char *main::sc#1 // sc zp[2]:7 22.0
char *main::sc#2 // sc zp[2]:7 14.666666666666666
char *main::screen
char *main::screen#1 // screen zp[2]:3 71.0
char *main::screen#13 // screen zp[2]:3 169.53846153846155
char *main::screen#2 // screen zp[2]:3 10.142857142857142

zp[2]:7 [ main::sc#2 main::sc#1 ]
zp[1]:6 [ main::row#2 main::row#1 ]
zp[2]:3 [ main::screen#13 main::screen#1 main::screen#2 ]
reg byte x [ main::row_pressed_bits#2 main::row_pressed_bits#1 main::row_pressed_bits#0 ]
reg byte y [ main::col#2 main::col#1 ]
zp[1]:5 [ main::ch#2 main::ch#1 ]
zp[1]:2 [ main::i#4 main::i#3 main::i#6 main::i#1 main::i#2 ]
reg byte x [ keyboard_matrix_read::rowid#2 keyboard_matrix_read::rowid#0 keyboard_matrix_read::rowid#1 ]
reg byte a [ keyboard_matrix_read::return#3 ]
reg byte a [ main::$4 ]
reg byte x [ keyboard_get_keycode::ch#0 ]
reg byte a [ keyboard_get_keycode::return#2 ]
reg byte a [ main::key#0 ]
reg byte x [ keyboard_key_pressed::key#0 ]
reg byte a [ keyboard_key_pressed::return#2 ]
reg byte a [ main::$14 ]
reg byte a [ keyboard_matrix_read::return#0 ]
reg byte a [ keyboard_get_keycode::return#0 ]
reg byte y [ keyboard_key_pressed::colidx#0 ]
reg byte a [ keyboard_key_pressed::rowidx#0 ]
reg byte a [ keyboard_matrix_read::return#2 ]
reg byte a [ keyboard_key_pressed::$2 ]
reg byte a [ keyboard_key_pressed::return#0 ]


FINAL ASSEMBLER
Score: 57707

  // File Comments
// Test keyboard input - in the keyboard matrix and mapping screen codes to key codes
  // Upstart
  // Commodore 64 PRG executable file
.file [name="test-keyboard.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
  .const KEY_3 = 8
  .const KEY_W = 9
  .const KEY_A = $a
  .const KEY_4 = $b
  .const KEY_Z = $c
  .const KEY_S = $d
  .const KEY_E = $e
  .const KEY_5 = $10
  .const KEY_R = $11
  .const KEY_D = $12
  .const KEY_6 = $13
  .const KEY_C = $14
  .const KEY_F = $15
  .const KEY_T = $16
  .const KEY_X = $17
  .const KEY_7 = $18
  .const KEY_Y = $19
  .const KEY_G = $1a
  .const KEY_8 = $1b
  .const KEY_B = $1c
  .const KEY_H = $1d
  .const KEY_U = $1e
  .const KEY_V = $1f
  .const KEY_9 = $20
  .const KEY_I = $21
  .const KEY_J = $22
  .const KEY_0 = $23
  .const KEY_M = $24
  .const KEY_K = $25
  .const KEY_O = $26
  .const KEY_N = $27
  .const KEY_PLUS = $28
  .const KEY_P = $29
  .const KEY_L = $2a
  .const KEY_MINUS = $2b
  .const KEY_DOT = $2c
  .const KEY_COLON = $2d
  .const KEY_AT = $2e
  .const KEY_COMMA = $2f
  .const KEY_POUND = $30
  .const KEY_ASTERISK = $31
  .const KEY_SEMICOLON = $32
  .const KEY_EQUALS = $35
  .const KEY_ARROW_UP = $36
  .const KEY_SLASH = $37
  .const KEY_1 = $38
  .const KEY_ARROW_LEFT = $39
  .const KEY_2 = $3b
  .const KEY_SPACE = $3c
  .const KEY_Q = $3e
  .const OFFSET_STRUCT_MOS6526_CIA_PORT_A_DDR = 2
  .const OFFSET_STRUCT_MOS6526_CIA_PORT_B_DDR = 3
  .const OFFSET_STRUCT_MOS6526_CIA_PORT_B = 1
  /// $D012 RASTER Raster counter
  .label RASTER = $d012
  /// The CIA#1: keyboard matrix, joystick #1/#2
  .label CIA1 = $dc00
.segment Code
  // main
main: {
    .label sc = 7
    .label screen = 3
    .label row = 6
    .label ch = 5
    // Checks all specific chars $00-$3f
    .label i = 2
    // [1] phi from main to main::@1 [phi:main->main::@1]
    // [1] phi main::sc#2 = (char *) 1024 [phi:main->main::@1#0] -- pbuz1=pbuc1 
    lda #<$400
    sta.z sc
    lda #>$400
    sta.z sc+1
  // Clear screen
    // main::@1
  __b1:
    // for(byte* sc = (char*)$400; sc<$400+1000;sc++)
    // [2] if(main::sc#2<$400+$3e8) goto main::@2 -- pbuz1_lt_vwuc1_then_la1 
    lda.z sc+1
    cmp #>$400+$3e8
    bcs !__b2+
    jmp __b2
  !__b2:
    bne !+
    lda.z sc
    cmp #<$400+$3e8
    bcs !__b2+
    jmp __b2
  !__b2:
  !:
    // [3] phi from main::@1 to main::@3 [phi:main::@1->main::@3]
    // main::@3
    // keyboard_init()
    // [4] call keyboard_init
    // Init keyboard
    jsr keyboard_init
    // main::@4
  __b4:
    // while (*RASTER!=$ff)
    // [5] if(*RASTER!=$ff) goto main::@4 -- _deref_pbuc1_neq_vbuc2_then_la1 
    lda #$ff
    cmp RASTER
    bne __b4
    // [6] phi from main::@4 to main::@5 [phi:main::@4->main::@5]
    // [6] phi main::screen#13 = (char *) 1024 [phi:main::@4->main::@5#0] -- pbuz1=pbuc1 
    lda #<$400
    sta.z screen
    lda #>$400
    sta.z screen+1
    // [6] phi main::row#2 = 0 [phi:main::@4->main::@5#1] -- vbuz1=vbuc1 
    lda #0
    sta.z row
  // Read & print keyboard matrix
    // [6] phi from main::@10 to main::@5 [phi:main::@10->main::@5]
    // [6] phi main::screen#13 = main::screen#1 [phi:main::@10->main::@5#0] -- register_copy 
    // [6] phi main::row#2 = main::row#1 [phi:main::@10->main::@5#1] -- register_copy 
    // main::@5
  __b5:
    // byte row_pressed_bits = keyboard_matrix_read(row)
    // [7] keyboard_matrix_read::rowid#1 = main::row#2 -- vbuxx=vbuz1 
    ldx.z row
    // [8] call keyboard_matrix_read
    // [48] phi from main::@5 to keyboard_matrix_read [phi:main::@5->keyboard_matrix_read]
    // [48] phi keyboard_matrix_read::rowid#2 = keyboard_matrix_read::rowid#1 [phi:main::@5->keyboard_matrix_read#0] -- register_copy 
    jsr keyboard_matrix_read
    // byte row_pressed_bits = keyboard_matrix_read(row)
    // [9] keyboard_matrix_read::return#3 = keyboard_matrix_read::return#0
    // main::@17
    // [10] main::row_pressed_bits#0 = keyboard_matrix_read::return#3 -- vbuxx=vbuaa 
    tax
    // [11] phi from main::@17 to main::@6 [phi:main::@17->main::@6]
    // [11] phi main::col#2 = 0 [phi:main::@17->main::@6#0] -- vbuyy=vbuc1 
    ldy #0
    // [11] phi main::row_pressed_bits#2 = main::row_pressed_bits#0 [phi:main::@17->main::@6#1] -- register_copy 
    // [11] phi from main::@8 to main::@6 [phi:main::@8->main::@6]
    // [11] phi main::col#2 = main::col#1 [phi:main::@8->main::@6#0] -- register_copy 
    // [11] phi main::row_pressed_bits#2 = main::row_pressed_bits#1 [phi:main::@8->main::@6#1] -- register_copy 
    // main::@6
  __b6:
    // row_pressed_bits & $80
    // [12] main::$4 = main::row_pressed_bits#2 & $80 -- vbuaa=vbuxx_band_vbuc1 
    txa
    and #$80
    // if( (row_pressed_bits & $80) != 0)
    // [13] if(main::$4!=0) goto main::@7 -- vbuaa_neq_0_then_la1 
    cmp #0
    bne __b7
    // main::@9
    // screen[col] = '0'
    // [14] main::screen#13[main::col#2] = '0' -- pbuz1_derefidx_vbuyy=vbuc1 
    lda #'0'
    sta (screen),y
    // main::@8
  __b8:
    // row_pressed_bits = row_pressed_bits * 2
    // [15] main::row_pressed_bits#1 = main::row_pressed_bits#2 << 1 -- vbuxx=vbuxx_rol_1 
    txa
    asl
    tax
    // for(byte col : 0..7)
    // [16] main::col#1 = ++ main::col#2 -- vbuyy=_inc_vbuyy 
    iny
    // [17] if(main::col#1!=8) goto main::@6 -- vbuyy_neq_vbuc1_then_la1 
    cpy #8
    bne __b6
    // main::@10
    // screen = screen + 40
    // [18] main::screen#1 = main::screen#13 + $28 -- pbuz1=pbuz1_plus_vbuc1 
    lda #$28
    clc
    adc.z screen
    sta.z screen
    bcc !+
    inc.z screen+1
  !:
    // for(byte row : 0..7)
    // [19] main::row#1 = ++ main::row#2 -- vbuz1=_inc_vbuz1 
    inc.z row
    // [20] if(main::row#1!=8) goto main::@5 -- vbuz1_neq_vbuc1_then_la1 
    lda #8
    cmp.z row
    bne __b5
    // main::@11
    // screen = screen + 40
    // [21] main::screen#2 = main::screen#1 + $28 -- pbuz1=pbuz1_plus_vbuc1 
    lda #$28
    clc
    adc.z screen
    sta.z screen
    bcc !+
    inc.z screen+1
  !:
    // [22] phi from main::@11 to main::@12 [phi:main::@11->main::@12]
    // [22] phi main::i#3 = 0 [phi:main::@11->main::@12#0] -- vbuz1=vbuc1 
    lda #0
    sta.z i
    // [22] phi main::ch#2 = 0 [phi:main::@11->main::@12#1] -- vbuz1=vbuc1 
    sta.z ch
    // [22] phi from main::@13 to main::@12 [phi:main::@13->main::@12]
    // [22] phi main::i#3 = main::i#6 [phi:main::@13->main::@12#0] -- register_copy 
    // [22] phi main::ch#2 = main::ch#1 [phi:main::@13->main::@12#1] -- register_copy 
    // main::@12
  __b12:
    // byte key = keyboard_get_keycode(ch)
    // [23] keyboard_get_keycode::ch#0 = main::ch#2 -- vbuxx=vbuz1 
    ldx.z ch
    // [24] call keyboard_get_keycode
    jsr keyboard_get_keycode
    // [25] keyboard_get_keycode::return#2 = keyboard_get_keycode::return#0
    // main::@18
    // [26] main::key#0 = keyboard_get_keycode::return#2
    // if(key!=$3f)
    // [27] if(main::key#0==$3f) goto main::@13 -- vbuaa_eq_vbuc1_then_la1 
    cmp #$3f
    beq __b13
    // main::@14
    // keyboard_key_pressed(key)
    // [28] keyboard_key_pressed::key#0 = main::key#0 -- vbuxx=vbuaa 
    tax
    // [29] call keyboard_key_pressed
    jsr keyboard_key_pressed
    // [30] keyboard_key_pressed::return#2 = keyboard_key_pressed::return#0
    // main::@19
    // [31] main::$14 = keyboard_key_pressed::return#2
    // if(keyboard_key_pressed(key)!=0)
    // [32] if(main::$14==0) goto main::@13 -- vbuaa_eq_0_then_la1 
    cmp #0
    beq __b13
    // main::@15
    // screen[i++] = ch
    // [33] main::screen#2[main::i#3] = main::ch#2 -- pbuz1_derefidx_vbuz2=vbuz3 
    lda.z ch
    ldy.z i
    sta (screen),y
    // screen[i++] = ch;
    // [34] main::i#1 = ++ main::i#3 -- vbuz1=_inc_vbuz1 
    inc.z i
    // [35] phi from main::@15 main::@18 main::@19 to main::@13 [phi:main::@15/main::@18/main::@19->main::@13]
    // [35] phi main::i#6 = main::i#1 [phi:main::@15/main::@18/main::@19->main::@13#0] -- register_copy 
    // main::@13
  __b13:
    // for( byte ch : 0..$3f )
    // [36] main::ch#1 = ++ main::ch#2 -- vbuz1=_inc_vbuz1 
    inc.z ch
    // [37] if(main::ch#1!=$40) goto main::@12 -- vbuz1_neq_vbuc1_then_la1 
    lda #$40
    cmp.z ch
    bne __b12
    // [38] phi from main::@13 main::@16 to main::@16 [phi:main::@13/main::@16->main::@16]
  __b3:
    // [38] phi main::i#4 = main::i#6 [phi:main::@13/main::@16->main::@16#0] -- register_copy 
  // Add some spaces
    // main::@16
    // screen[i++] = ' '
    // [39] main::screen#2[main::i#4] = ' ' -- pbuz1_derefidx_vbuz2=vbuc1 
    lda #' '
    ldy.z i
    sta (screen),y
    // screen[i++] = ' ';
    // [40] main::i#2 = ++ main::i#4 -- vbuz1=_inc_vbuz1 
    inc.z i
    // while (i<5)
    // [41] if(main::i#2<5) goto main::@16 -- vbuz1_lt_vbuc1_then_la1 
    lda.z i
    cmp #5
    bcc __b3
    jmp __b4
    // main::@7
  __b7:
    // screen[col] = '1'
    // [42] main::screen#13[main::col#2] = '1' -- pbuz1_derefidx_vbuyy=vbuc1 
    lda #'1'
    sta (screen),y
    jmp __b8
    // main::@2
  __b2:
    // *sc = ' '
    // [43] *main::sc#2 = ' ' -- _deref_pbuz1=vbuc1 
    lda #' '
    ldy #0
    sta (sc),y
    // for(byte* sc = (char*)$400; sc<$400+1000;sc++)
    // [44] main::sc#1 = ++ main::sc#2 -- pbuz1=_inc_pbuz1 
    inc.z sc
    bne !+
    inc.z sc+1
  !:
    // [1] phi from main::@2 to main::@1 [phi:main::@2->main::@1]
    // [1] phi main::sc#2 = main::sc#1 [phi:main::@2->main::@1#0] -- register_copy 
    jmp __b1
}
  // keyboard_init
// Initialize keyboard reading by setting CIA#1 Data Direction Registers
keyboard_init: {
    // CIA1->PORT_A_DDR = $ff
    // [45] *((char *)CIA1+OFFSET_STRUCT_MOS6526_CIA_PORT_A_DDR) = $ff -- _deref_pbuc1=vbuc2 
    // Keyboard Matrix Columns Write Mode
    lda #$ff
    sta CIA1+OFFSET_STRUCT_MOS6526_CIA_PORT_A_DDR
    // CIA1->PORT_B_DDR = $00
    // [46] *((char *)CIA1+OFFSET_STRUCT_MOS6526_CIA_PORT_B_DDR) = 0 -- _deref_pbuc1=vbuc2 
    // Keyboard Matrix Columns Read Mode
    lda #0
    sta CIA1+OFFSET_STRUCT_MOS6526_CIA_PORT_B_DDR
    // keyboard_init::@return
    // }
    // [47] return 
    rts
}
  // keyboard_matrix_read
// Read a single row of the keyboard matrix
// The row ID (0-7) of the keyboard matrix row to read. See the C64 key matrix for row IDs.
// Returns the keys pressed on the row as bits according to the C64 key matrix.
// Notice: If the C64 normal interrupt is still running it will occasionally interrupt right between the read & write
// leading to erroneous readings. You must disable the normal interrupt or sei/cli around calls to the keyboard matrix reader.
// __register(A) char keyboard_matrix_read(__register(X) char rowid)
keyboard_matrix_read: {
    // CIA1->PORT_A = keyboard_matrix_row_bitmask[rowid]
    // [49] *((char *)CIA1) = keyboard_matrix_row_bitmask[keyboard_matrix_read::rowid#2] -- _deref_pbuc1=pbuc2_derefidx_vbuxx 
    lda keyboard_matrix_row_bitmask,x
    sta CIA1
    // char row_pressed_bits = ~CIA1->PORT_B
    // [50] keyboard_matrix_read::return#0 = ~ *((char *)CIA1+OFFSET_STRUCT_MOS6526_CIA_PORT_B) -- vbuaa=_bnot__deref_pbuc1 
    lda CIA1+OFFSET_STRUCT_MOS6526_CIA_PORT_B
    eor #$ff
    // keyboard_matrix_read::@return
    // }
    // [51] return 
    rts
}
  // keyboard_get_keycode
// Get the keycode corresponding to a specific screen code character
// ch is the character to get the key code for ($00-$3f)
// Returns the key code corresponding to the passed character. Only characters with a non-shifted key are handled.
// If there is no non-shifted key representing the char $3f is returned (representing RUN/STOP) .
// __register(A) char keyboard_get_keycode(__register(X) char ch)
keyboard_get_keycode: {
    // return keyboard_char_keycodes[ch];
    // [52] keyboard_get_keycode::return#0 = keyboard_char_keycodes[keyboard_get_keycode::ch#0] -- vbuaa=pbuc1_derefidx_vbuxx 
    lda keyboard_char_keycodes,x
    // keyboard_get_keycode::@return
    // }
    // [53] return 
    rts
}
  // keyboard_key_pressed
// Determines whether a specific key is currently pressed by accessing the matrix directly
// The key is a keyboard code defined from the keyboard matrix by %00rrrccc, where rrr is the row ID (0-7) and ccc is the column ID (0-7)
// All keys exist as as KEY_XXX constants.
// Returns zero if the key is not pressed and a non-zero value if the key is currently pressed
// __register(A) char keyboard_key_pressed(__register(X) char key)
keyboard_key_pressed: {
    // char colidx = key&7
    // [54] keyboard_key_pressed::colidx#0 = keyboard_key_pressed::key#0 & 7 -- vbuyy=vbuxx_band_vbuc1 
    txa
    and #7
    tay
    // char rowidx = key>>3
    // [55] keyboard_key_pressed::rowidx#0 = keyboard_key_pressed::key#0 >> 3 -- vbuaa=vbuxx_ror_3 
    txa
    lsr
    lsr
    lsr
    // keyboard_matrix_read(rowidx)
    // [56] keyboard_matrix_read::rowid#0 = keyboard_key_pressed::rowidx#0 -- vbuxx=vbuaa 
    tax
    // [57] call keyboard_matrix_read
    // [48] phi from keyboard_key_pressed to keyboard_matrix_read [phi:keyboard_key_pressed->keyboard_matrix_read]
    // [48] phi keyboard_matrix_read::rowid#2 = keyboard_matrix_read::rowid#0 [phi:keyboard_key_pressed->keyboard_matrix_read#0] -- register_copy 
    jsr keyboard_matrix_read
    // keyboard_matrix_read(rowidx)
    // [58] keyboard_matrix_read::return#2 = keyboard_matrix_read::return#0
    // keyboard_key_pressed::@1
    // [59] keyboard_key_pressed::$2 = keyboard_matrix_read::return#2
    // keyboard_matrix_read(rowidx) & keyboard_matrix_col_bitmask[colidx]
    // [60] keyboard_key_pressed::return#0 = keyboard_key_pressed::$2 & keyboard_matrix_col_bitmask[keyboard_key_pressed::colidx#0] -- vbuaa=vbuaa_band_pbuc1_derefidx_vbuyy 
    and keyboard_matrix_col_bitmask,y
    // keyboard_key_pressed::@return
    // }
    // [61] return 
    rts
}
  // File Data
.segment Data
  // Keycodes for each screen code character from $00-$3f.
  // Chars that do not have an unmodified keycode return $3f (representing RUN/STOP).
  keyboard_char_keycodes: .byte KEY_AT, KEY_A, KEY_B, KEY_C, KEY_D, KEY_E, KEY_F, KEY_G, KEY_H, KEY_I, KEY_J, KEY_K, KEY_L, KEY_M, KEY_N, KEY_O, KEY_P, KEY_Q, KEY_R, KEY_S, KEY_T, KEY_U, KEY_V, KEY_W, KEY_X, KEY_Y, KEY_Z, $3f, KEY_POUND, $3f, KEY_ARROW_UP, KEY_ARROW_LEFT, KEY_SPACE, $3f, $3f, $3f, $3f, $3f, $3f, $3f, $3f, $3f, KEY_ASTERISK, KEY_PLUS, KEY_COMMA, KEY_MINUS, KEY_DOT, KEY_SLASH, KEY_0, KEY_1, KEY_2, KEY_3, KEY_4, KEY_5, KEY_6, KEY_7, KEY_8, KEY_9, KEY_COLON, KEY_SEMICOLON, $3f, KEY_EQUALS, $3f, $3f
  // Keyboard row bitmask as expected by CIA#1 Port A when reading a specific keyboard matrix row (rows are numbered 0-7)
  keyboard_matrix_row_bitmask: .byte $fe, $fd, $fb, $f7, $ef, $df, $bf, $7f
  // Keyboard matrix column bitmasks for a specific keybooard matrix column when reading the keyboard. (columns are numbered 0-7)
  keyboard_matrix_col_bitmask: .byte 1, 2, 4, 8, $10, $20, $40, $80

