main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
_QWORD *v3; // rax
int result; // eax

v3 = malloc(0x28uLL);
nil_node = (__int64)v3;
if ( v3 )
{
v3[1] = 0LL;
v3[2] = 0LL;
v3[3] = 0LL;
*((_DWORD *)v3 + 8) = 0;
*(_DWORD *)v3 = -559038737;
insert(&root, 10);
insert(&root, 5);
insert(&root, 20);
insert(&root, 8);
insert(&root, 4);
insert(&root, 2);
insert(&root, 3);
insert(&root, 30);
insert(&root, 25);
insert(&root, 1);
print_in_order((unsigned int *)root);
putchar(10);
delete(&root, 3);
print_in_order((unsigned int *)root);
result = 0;
}
else
{
puts("ERROR; can't initialize nil_node. BT creation will fail");
result = -1;
}
return result;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
_QWORD *v3; // rax
int result; // eax

v3 = malloc(0x28uLL);
nil_node = (__int64)v3;
if ( v3 )
{
v3[1] = 0LL;
v3[2] = 0LL;
v3[3] = 0LL;
*((_DWORD *)v3 + 8) = 0;
*(_DWORD *)v3 = -559038737;
func0(&root, 10);
func0(&root, 5);
func0(&root, 20);
func0(&root, 8);
func0(&root, 4);
func0(&root, 2);
func0(&root, 3);
func0(&root, 30);
func0(&root, 25);
func0(&root, 1);
func1((unsigned int *)root);
putchar(10);
func5(&root, 3);
func1((unsigned int *)root);
result = 0;
}
else
{
puts("ERROR; can't initialize nil_node. BT creation will fail");
result = -1;
}
return result;
}

original_code:
int main()
{
 nil_node = malloc(sizeof(struct node));
 if (!nil_node) {
  printf("ERROR; can't initialize nil_node. BT creation will fail\n");
  return -1;
 }
 nil_node->l = ((void *)0);
 nil_node->r = ((void *)0);
 nil_node->p = ((void *)0);
 nil_node->col = BLACK;
 nil_node->val = 0xDEADBEEF;
 insert(&root, 10);
 insert(&root, 5);
 insert(&root, 20);
 insert(&root, 8);
 insert(&root, 4);
 insert(&root, 2);
 insert(&root, 3);
 insert(&root, 30);
 insert(&root, 25);
 insert(&root, 1);
        print_in_order(root);
 printf("\n");
 delete(&root, 3);
        print_in_order(root);
 return 0;
}


original_code:
void rotate_left(struct node *x, struct node **root)
{
 struct node *y = x->p;
 if((y->p->l == y))
  y->p->l = x;
 else
  y->p->r = x;
 x->p = y->p;
 y->r = x->l;
 y->r->p = y;
 x->l = y;
 y->p = x;
 if ((x->p == nil_node))
  *root = x;
}

variable_types: struct node { int val; struct node *l; struct node *r; struct node *p; enum color { BLACK=0, RED=1 } col; } *

variable_types:
root
struct node **

return_type: void

user_defined_types: struct node { int val; struct node *l; struct node *r; struct node *p; enum color col; }


original_code:
void rotate_right(struct node *x, struct node **root)
{
 struct node *y = x->p;
 if((y->p->l == y))
  y->p->l = x;
 else
  y->p->r = x;
 x->p = y->p;
 y->l = x->r;
 y->l->p = y;
 x->r = y;
 y->p = x;
 if ((x->p == nil_node))
  *root = x;
}


decompiled_code:
int __fastcall print_list(unsigned int *a1)
{
unsigned int *v1; // rbx

v1 = a1;
if ( !a1 )
return puts("Empty list");
do
{
printf("%d ", *v1);
v1 = (unsigned int *)*((_QWORD *)v1 + 1);
}
while ( v1 );
return putchar(10);
}

canonical_decompiled_code:
int __fastcall func8(unsigned int *a1)
{
unsigned int *v1; // rbx

v1 = a1;
if ( !a1 )
return puts("Empty list");
do
{
printf("%d ", *v1);
v1 = (unsigned int *)*((_QWORD *)v1 + 1);
}
while ( v1 );
return putchar(10);
}

original_code:
void print_list(struct node *head)
{
 struct node *cur;
 if (!head) {
  printf("Empty list\n");
  return;
 }
 for (cur = head; cur; cur=cur->next)
  printf("%d ", cur->val);
 printf("\n");
}

variable_types: struct node { int val; struct node *next; } *


reverse

decompiled_code:
int __fastcall reverse(__int64 *a1)
{
__int64 v1; // rdx
__int64 v2; // rax
__int64 v3; // rcx
__int64 v4; // rsi

v1 = *a1;
if ( *a1 && (v2 = *(_QWORD *)(v1 + 8), v3 = 0LL, v2) )
{
while ( 1 )
{
*(_QWORD *)(v1 + 8) = v3;
v4 = v2;
v2 = *(_QWORD *)(v2 + 8);
v3 = v1;
if ( !v2 )
break;
v1 = v4;
}
*(_QWORD *)(v4 + 8) = v1;
*a1 = v4;
}
else
{
LODWORD(v2) = puts("No reversing to do, since either empty list or single entry.");
}
return v2;
}

canonical_decompiled_code:
int __fastcall func10(__int64 *a1)
{
__int64 v1; // rdx
__int64 v2; // rax
__int64 v3; // rcx
__int64 v4; // rsi

v1 = *a1;
if ( *a1 && (v2 = *(_QWORD *)(v1 + 8), v3 = 0LL, v2) )
{
while ( 1 )
{
*(_QWORD *)(v1 + 8) = v3;
v4 = v2;
v2 = *(_QWORD *)(v2 + 8);
v3 = v1;
if ( !v2 )
break;
v1 = v4;
}
*(_QWORD *)(v4 + 8) = v1;
*a1 = v4;
}
else
{
LODWORD(v2) = puts("No reversing to do, since either empty list or single entry.");
}
return v2;
}

original_code:
void reverse(struct node **head)
{
 struct node *prev, *cur, *next;
 if (!(*head) || (*head)->next == ((void *)0)) {
  printf("No reversing to do, since either empty list or single entry.\n");
  return;
 }
 prev = ((void *)0);
 cur = *head;
 next = cur->next;
 while (next) {
  cur->next = prev;
  prev = cur;
  cur = next;
  next = next->next;
 }
 cur->next = prev;
 *head = cur;
}

canonical_original_code:
void reverse(struct node **head)
{
 struct node *prev; struct node *cur; struct node *next;
 if (!(*head) || (*head)->next == ((void *)0)) {
  printf("No reversing to do, since either empty list or single entry.\n");
  return;
 }
 prev = ((void *)0);
 cur = *head;
 next = cur->next;
 while (next) {
  cur->next = prev;
  prev = cur;
  cur = next;
  next = next->next;
 }
 cur->next = prev;
 *head = cur;
}

variable_types: struct node { int val; struct node *next; } **


decompiled_code:
__int64 __fastcall create_node(_QWORD *a1, int a2)
{
_QWORD *v2; // rax

v2 = malloc(0x10uLL);
if ( !v2 )
return 0xFFFFFFFFLL;
*(_DWORD *)v2 = a2;
v2[1] = *a1;
*a1 = v2;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func7(_QWORD *a1, int a2)
{
_QWORD *v2; // rax

v2 = malloc(0x10uLL);
if ( !v2 )
return 0xFFFFFFFFLL;
*(_DWORD *)v2 = a2;
v2[1] = *a1;
*a1 = v2;
return 0LL;
}

original_code:
int create_node(struct node **head, int val)
{
 struct node *new_node = malloc(sizeof(struct node));
 if (!new_node)
  return -1;
 new_node->val = val;
 new_node->next = *head;
 *head = new_node;
 return 0;
}

variable_types: val int

return_type: int

user_defined_types: struct node { int val; struct node *next; }


delete

decompiled_code:
__int64 __fastcall delete(void **a1, int a2)
{
void **v3; // rdi
void **v4; // rdx
__int64 result; // rax

v3 = (void **)*a1;
v4 = 0LL;
if ( v3 )
{
while ( *(_DWORD *)v3 != a2 )
{
v4 = v3;
if ( !v3[1] )
goto LABEL_9;
v3 = (void **)v3[1];
}
if ( v4 )
v4[1] = v3[1];
else
*a1 = v3[1];
free(v3);
result = 0LL;
}
else
{
LABEL_9:
puts("ERROR: Element doesn't exist");
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(void **a1, int a2)
{
void **v3; // rdi
void **v4; // rdx
__int64 result; // rax

v3 = (void **)*a1;
v4 = 0LL;
if ( v3 )
{
while ( *(_DWORD *)v3 != a2 )
{
v4 = v3;
if ( !v3[1] )
goto LABEL_9;
v3 = (void **)v3[1];
}
if ( v4 )
v4[1] = v3[1];
else
*a1 = v3[1];
free(v3);
result = 0LL;
}
else
{
LABEL_9:
puts("ERROR: Element doesn't exist");
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
int delete(struct node **head, int val)
{
 struct node *cur, *prev;
 cur = *head;
 prev = ((void *)0);
 while (cur != ((void *)0) && cur->val != val) {
  prev = cur;
  cur =cur->next;
 }
 if (cur == ((void *)0)) {
  printf("ERROR: Element doesn't exist\n");
  return -1;
 }
   if (prev == ((void *)0)) {
    *head = cur->next;
    free(cur);
   } else {
    prev->next = cur->next;
    free(cur);
   }
 return 0;
}

canonical_original_code:
int delete(struct node **head, int val)
{
 struct node *cur; struct node *prev;
 cur = *head;
 prev = ((void *)0);
 while (cur != ((void *)0) && cur->val != val) {
  prev = cur;
  cur =cur->next;
 }
 if (cur == ((void *)0)) {
  printf("ERROR: Element doesn't exist\n");
  return -1;
 }
   if (prev == ((void *)0)) {
    *head = cur->next;
    free(cur);
   } else {
    prev->next = cur->next;
    free(cur);
   }
 return 0;
}


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
create_node(&head, 3);
create_node(&head, 4);
create_node(&head, 5);
create_node(&head, 6);
create_node(&head, 7);
create_node(&head, 8);
print_list((unsigned int *)head);
reverse(&head);
print_list((unsigned int *)head);
delete((void **)&head, -10);
print_list((unsigned int *)head);
delete((void **)&head, 5);
print_list((unsigned int *)head);
delete((void **)&head, 3);
print_list((unsigned int *)head);
delete((void **)&head, 8);
print_list((unsigned int *)head);
reverse(&head);
print_list((unsigned int *)head);
delete((void **)&head, 4);
print_list((unsigned int *)head);
reverse(&head);
print_list((unsigned int *)head);
delete((void **)&head, 6);
print_list((unsigned int *)head);
reverse(&head);
print_list((unsigned int *)head);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
func7(&head, 3);
func7(&head, 4);
func7(&head, 5);
func7(&head, 6);
func7(&head, 7);
func7(&head, 8);
func8((unsigned int *)head);
func10(&head);
func8((unsigned int *)head);
func9((void **)&head, -10);
func8((unsigned int *)head);
func9((void **)&head, 5);
func8((unsigned int *)head);
func9((void **)&head, 3);
func8((unsigned int *)head);
func9((void **)&head, 8);
func8((unsigned int *)head);
func10(&head);
func8((unsigned int *)head);
func9((void **)&head, 4);
func8((unsigned int *)head);
func10(&head);
func8((unsigned int *)head);
func9((void **)&head, 6);
func8((unsigned int *)head);
func10(&head);
func8((unsigned int *)head);
return 0;
}

original_code:
int main()
{
 create_node(&head, 3);
 create_node(&head, 4);
 create_node(&head, 5);
 create_node(&head, 6);
 create_node(&head, 7);
 create_node(&head, 8);
 print_list(head);
 reverse(&head);
 print_list(head);
 delete(&head, -10);
 print_list(head);
 delete(&head, 5);
 print_list(head);
 delete(&head, 3);
 print_list(head);
 delete(&head, 8);
 print_list(head);
 reverse(&head);
 print_list(head);
 delete(&head, 4);
 print_list(head);
 reverse(&head);
 print_list(head);
 delete(&head, 6);
 print_list(head);
 reverse(&head);
 print_list(head);
 return 0;
}


print

repo: prcek/RFPad

decompiled_code:
int __fastcall print(const char *a1)
{
int result; // eax

if ( a1 )
result = fputs(a1, stdout);
return result;
}

canonical_decompiled_code:
int __fastcall func0(const char *a1)
{
int result; // eax

if ( a1 )
result = fputs(a1, stdout);
return result;
}

original_code:
void print(const char *str) {
 if (str==0) {
  return ;
 }
 fputs(str,stdout);
}

canonical_original_code:
void print(char *str) {
 if (str==0) {
  return ;
 }
 fputs(str,stdout);
}

variable_types:
str
char *


decompiled_code:
int print_nl()
{
fputc(10, stdout);
return fputc(13, stdout);
}

canonical_decompiled_code:
int func1()
{
fputc(10, stdout);
return fputc(13, stdout);
}

original_code:
void print_nl() {
 fputc('\n',stdout);
 fputc('\r',stdout);
}


decompiled_code:
int print_ok_nl()
{
fputc(79, stdout);
fputc(75, stdout);
fputc(10, stdout);
return fputc(13, stdout);
}

canonical_decompiled_code:
int func2()
{
fputc(79, stdout);
fputc(75, stdout);
fputc(10, stdout);
return fputc(13, stdout);
}

original_code:
void print_ok_nl() {
 fputc('O',stdout);
 fputc('K',stdout);
 fputc('\n',stdout);
 fputc('\r',stdout);
}


decompiled_code:
int print_err_nl()
{
fputc(69, stdout);
fputc(82, stdout);
fputc(82, stdout);
fputc(10, stdout);
return fputc(13, stdout);
}

canonical_decompiled_code:
int func3()
{
fputc(69, stdout);
fputc(82, stdout);
fputc(82, stdout);
fputc(10, stdout);
return fputc(13, stdout);
}

original_code:
void print_err_nl() {
 fputc('E',stdout);
 fputc('R',stdout);
 fputc('R',stdout);
 fputc('\n',stdout);
 fputc('\r',stdout);
}


decompiled_code:
int print_space()
{
return fputc(32, stdout);
}

canonical_decompiled_code:
int func4()
{
return fputc(32, stdout);
}

original_code:
void print_space() {
 fputc(' ',stdout);
}


decompiled_code:
int __fastcall print_spaces(int a1)
{
int v1; // ebx
int result; // eax

v1 = a1 - 1;
if ( (_BYTE)a1 )
{
do
{
result = fputc(32, stdout);
--v1;
}
while ( (_BYTE)v1 != 0xFF );
}
return result;
}

canonical_decompiled_code:
int __fastcall func5(int a1)
{
int v1; // ebx
int result; // eax

v1 = a1 - 1;
if ( (_BYTE)a1 )
{
do
{
result = fputc(32, stdout);
--v1;
}
while ( (_BYTE)v1 != 0xFF );
}
return result;
}

original_code:
void print_spaces(uint8_t c) {
 while(c--) {
  fputc(' ',stdout);
 }
}

canonical_original_code:
void print_spaces(unsigned char c) {
 while(c--) {
  fputc(' ',stdout);
 }
}

variable_types:
c
unsigned char


decompiled_code:
int __fastcall print_char(unsigned __int8 a1)
{
return fputc(a1, stdout);
}

canonical_decompiled_code:
int __fastcall func6(unsigned __int8 a1)
{
return fputc(a1, stdout);
}

original_code:
void print_char(uint8_t c) {
 fputc(c,stdout);
}

canonical_original_code:
void print_char(unsigned char c) {
 fputc(c,stdout);
}


decompiled_code:
int print_hex_prefix()
{
fputc(48, stdout);
return fputc(120, stdout);
}

canonical_decompiled_code:
int func7()
{
fputc(48, stdout);
return fputc(120, stdout);
}

original_code:
void print_hex_prefix() {
 fputc('0',stdout);
 fputc('x',stdout);
}


decompiled_code:
int __fastcall print_hb_internal(unsigned __int8 a1)
{
fputc((unsigned __int8)(((unsigned __int8)(a1 >> 4) < 0xAu ? 0xF9 : 0) + (a1 >> 4) + 55), stdout);
return fputc((unsigned __int8)(((a1 & 0xFu) < 0xA ? 0xF9 : 0) + (a1 & 0xF) + 55), stdout);
}

canonical_decompiled_code:
int __fastcall func8(unsigned __int8 a1)
{
fputc((unsigned __int8)(((unsigned __int8)(a1 >> 4) < 0xAu ? 0xF9 : 0) + (a1 >> 4) + 55), stdout);
return fputc((unsigned __int8)(((a1 & 0xFu) < 0xA ? 0xF9 : 0) + (a1 & 0xF) + 55), stdout);
}

original_code:
void print_hb_internal(uint8_t v) {
 uint8_t c;
 c = (v & 0xf0)>>4;
 c += c<10?'0':'A'-10;
 fputc(c,stdout);
 c=(v&0x0f);
 c += c<10?'0':'A'-10;
 fputc(c,stdout);
}

canonical_original_code:
void print_hb_internal(unsigned char v) {
 unsigned char c;
 c = (v & 0xf0)>>4;
 c += c<10?'0':'A'-10;
 fputc(c,stdout);
 c=(v&0x0f);
 c += c<10?'0':'A'-10;
 fputc(c,stdout);
}

variable_types:
v
unsigned char


decompiled_code:
int __fastcall print_hex(unsigned __int8 a1)
{
return print_hb_internal(a1);
}

canonical_decompiled_code:
int __fastcall func9(unsigned __int8 a1)
{
return func8(a1);
}

original_code:
void print_hex(uint8_t v) {
 print_hb_internal(v);
}

canonical_original_code:
void print_hex(unsigned char v) {
 print_hb_internal(v);
}


decompiled_code:
int __fastcall print_hb(const char *a1, unsigned __int8 a2)
{
print(a1);
print_hex_prefix();
return print_hb_internal(a2);
}

canonical_decompiled_code:
int __fastcall func10(const char *a1, unsigned __int8 a2)
{
func0(a1);
func7();
return func8(a2);
}

original_code:
void print_hb(const char *str, uint8_t v) {
 print(str);
 print_hex_prefix();
 print_hb_internal(v);
}

canonical_original_code:
void print_hb(char *str, unsigned char v) {
 print(str);
 print_hex_prefix();
 print_hb_internal(v);
}


decompiled_code:
int __fastcall print_hw(const char *a1, __int16 a2)
{
print(a1);
print_hex_prefix();
print_hb_internal(HIBYTE(a2));
return print_hb_internal(a2);
}

canonical_decompiled_code:
int __fastcall func11(const char *a1, __int16 a2)
{
func0(a1);
func7();
func8(HIBYTE(a2));
return func8(a2);
}

original_code:
void print_hw(const char *str, uint16_t v) {
 print(str);
 print_hex_prefix();
 print_hb_internal((uint8_t)(v >> 8));
 print_hb_internal((uint8_t)(v));
}

canonical_original_code:
void print_hw(char *str, unsigned short v) {
 print(str);
 print_hex_prefix();
 print_hb_internal((unsigned char)(v >> 8));
 print_hb_internal((unsigned char)(v));
}

variable_types:
v
unsigned short


decompiled_code:
int __fastcall print_bit(const char *a1, unsigned __int16 a2, unsigned int a3)
{
int v4; // ebx
int result; // eax

print(a1);
v4 = a2;
if ( _bittest(&v4, a3) )
result = fputc(49, stdout);
else
result = fputc(48, stdout);
return result;
}

canonical_decompiled_code:
int __fastcall func12(const char *a1, unsigned __int16 a2, unsigned int a3)
{
int v4; // ebx
int result; // eax

func0(a1);
v4 = a2;
if ( _bittest(&v4, a3) )
result = fputc(49, stdout);
else
result = fputc(48, stdout);
return result;
}

original_code:
void print_bit(const char *str, uint16_t v, uint8_t b) {
 print(str);
 if (v&(1<<b)) {
  fputc('1',stdout);
 } else {
  fputc('0',stdout);
 }
}

canonical_original_code:
void print_bit(char *str, unsigned short v, unsigned char b) {
 print(str);
 if (v&(1<<b)) {
  fputc('1',stdout);
 } else {
  fputc('0',stdout);
 }
}

variable_types:
b
unsigned char


decompiled_code:
int __fastcall print_bits(const char *a1, unsigned __int16 a2, unsigned __int8 a3, unsigned __int8 a4)
{
unsigned int v6; // ebx

print(a1);
if ( a3 > a4 )
{
v6 = a3;
do
print_bit(0LL, a2, v6--);
while ( v6 != a3 - 1 - (unsigned __int8)(a3 - a4 - 1) );
}
return print_bit((const char *)&unk_76E, a2, a4);
}

canonical_decompiled_code:
int __fastcall func13(const char *a1, unsigned __int16 a2, unsigned __int8 a3, unsigned __int8 a4)
{
unsigned int v6; // ebx

func0(a1);
if ( a3 > a4 )
{
v6 = a3;
do
func12(0LL, a2, v6--);
while ( v6 != a3 - 1 - (unsigned __int8)(a3 - a4 - 1) );
}
return func12((const char *)&unk_76E, a2, a4);
}

original_code:
void print_bits(const char *str, uint16_t v, uint8_t bh, uint8_t bl) {
 print(str);
 while(bh>bl) {
  print_bit(0,v,bh);
  bh--;
 }
 print_bit("",v,bl);
}

canonical_original_code:
void print_bits(char *str, unsigned short v, unsigned char bh, unsigned char bl) {
 print(str);
 while(bh>bl) {
  print_bit(0,v,bh);
  bh--;
 }
 print_bit("",v,bl);
}

variable_types:
bh
unsigned char

variable_types:
bl
unsigned char


decompiled_code:
int __fastcall print_hbits(const char *a1, __int16 a2, unsigned __int8 a3, unsigned __int8 a4)
{
int v4; // esi
int result; // eax

v4 = (int)(unsigned __int16)(a2 & ((2 << a3) - 1)) >> a4;
if ( a3 - a4 <= 7 )
result = print_hb(a1, v4);
else
result = print_hw(a1, v4);
return result;
}

canonical_decompiled_code:
int __fastcall func14(const char *a1, __int16 a2, unsigned __int8 a3, unsigned __int8 a4)
{
int v4; // esi
int result; // eax

v4 = (int)(unsigned __int16)(a2 & ((2 << a3) - 1)) >> a4;
if ( a3 - a4 <= 7 )
result = func10(a1, v4);
else
result = func11(a1, v4);
return result;
}

original_code:
void print_hbits(const char *str, uint16_t v, uint8_t bh, uint8_t bl) {
 v = v & ((2U<<bh)-1U);
 v = v>>bl;
 if ((bh-bl)>7) {
  print_hw(str,v);
 } else {
  print_hb(str,v);
 }
}

canonical_original_code:
void print_hbits(char *str, unsigned short v, unsigned char bh, unsigned char bl) {
 v = v & ((2U<<bh)-1U);
 v = v>>bl;
 if ((bh-bl)>7) {
  print_hw(str,v);
 } else {
  print_hb(str,v);
 }
}


decompiled_code:
int __fastcall print_bb(const char *a1, unsigned __int8 a2)
{
return print_bits(a1, a2, 7u, 0);
}

canonical_decompiled_code:
int __fastcall func15(const char *a1, unsigned __int8 a2)
{
return func13(a1, a2, 7u, 0);
}

original_code:
void print_bb(const char *str, uint8_t v) {
 print_bits(str,(uint16_t)v, 7,0);
}

canonical_original_code:
void print_bb(char *str, unsigned char v) {
 print_bits(str,(unsigned short)v, 7,0);
}


decompiled_code:
int __fastcall print_bw(const char *a1, unsigned __int16 a2)
{
return print_bits(a1, a2, 0xFu, 0);
}

canonical_decompiled_code:
int __fastcall func16(const char *a1, unsigned __int16 a2)
{
return func13(a1, a2, 0xFu, 0);
}

original_code:
void print_bw(const char *str, uint16_t v) {
 print_bits(str,v, 15,0);
}

canonical_original_code:
void print_bw(char *str, unsigned short v) {
 print_bits(str,v, 15,0);
}


decompiled_code:
int __fastcall print_db(const char *a1, unsigned __int8 a2)
{
char v2; // bl
char v3; // bp
int result; // eax

print(a1);
if ( !a2 )
return fputc(48, stdout);
v2 = a2 % 0xAu;
v3 = a2 / 0xAu % 0xA;
if ( a2 > 0x63u )
{
fputc((unsigned __int8)(a2 / 0xAu / 0xA + 48), stdout);
fputc((unsigned __int8)(v3 + 48), stdout);
result = fputc((unsigned __int8)(v2 + 48), stdout);
}
else
{
if ( v3 )
fputc((unsigned __int8)(a2 / 0xAu % 0xA + 48), stdout);
result = fputc((unsigned __int8)(v2 + 48), stdout);
}
return result;
}

canonical_decompiled_code:
int __fastcall func17(const char *a1, unsigned __int8 a2)
{
char v2; // bl
char v3; // bp
int result; // eax

func0(a1);
if ( !a2 )
return fputc(48, stdout);
v2 = a2 % 0xAu;
v3 = a2 / 0xAu % 0xA;
if ( a2 > 0x63u )
{
fputc((unsigned __int8)(a2 / 0xAu / 0xA + 48), stdout);
fputc((unsigned __int8)(v3 + 48), stdout);
result = fputc((unsigned __int8)(v2 + 48), stdout);
}
else
{
if ( v3 )
fputc((unsigned __int8)(a2 / 0xAu % 0xA + 48), stdout);
result = fputc((unsigned __int8)(v2 + 48), stdout);
}
return result;
}

original_code:
void print_db(const char *str, uint8_t v) {
 uint8_t n1,n0;
 print(str);
 if (v==0) {
  fputc('0',stdout);
  return;
 }
 n0 = v % 10;
 v = v / 10;
 n1 = v % 10;
 v = v / 10;
 if (v!=0) {
  fputc('0'+v,stdout);
  fputc('0'+n1,stdout);
  fputc('0'+n0,stdout);
 } else if (n1 != 0) {
  fputc('0'+n1,stdout);
  fputc('0'+n0,stdout);
 } else {
  fputc('0'+n0,stdout);
 }
}

canonical_original_code:
void print_db(char *str, unsigned char v) {
 unsigned char n1; unsigned char n0;
 print(str);
 if (v==0) {
  fputc('0',stdout);
  return;
 }
 n0 = v % 10;
 v = v / 10;
 n1 = v % 10;
 v = v / 10;
 if (v!=0) {
  fputc('0'+v,stdout);
  fputc('0'+n1,stdout);
  fputc('0'+n0,stdout);
 } else if (n1 != 0) {
  fputc('0'+n1,stdout);
  fputc('0'+n0,stdout);
 } else {
  fputc('0'+n0,stdout);
 }
}


decompiled_code:
int __fastcall print_dw(const char *a1, unsigned __int16 a2)
{
unsigned int v2; // ebx
char v3; // r13
unsigned int v4; // ebp
unsigned int v5; // ebx
unsigned int v6; // eax
unsigned int v7; // ebp
unsigned int v8; // er14
int result; // eax

print(a1);
if ( !a2 )
return fputc(48, stdout);
v2 = a2 / 0xAu;
v3 = a2 % 0xAu;
v4 = (unsigned __int16)v2 / 0xAu;
v5 = v2 % 0xA;
v6 = (unsigned __int16)v4 / 0xAu;
v7 = v4 % 0xA;
v8 = v6 % 0xA;
if ( a2 > 0x270Fu )
{
fputc((unsigned __int16)v6 / 0xAu + 48, stdout);
fputc((unsigned __int8)(v8 + 48), stdout);
fputc((unsigned __int8)(v7 + 48), stdout);
fputc((unsigned __int8)(v5 + 48), stdout);
result = fputc((unsigned __int8)(v3 + 48), stdout);
}
else if ( (_BYTE)v8 )
{
fputc((unsigned __int8)(v8 + 48), stdout);
fputc((unsigned __int8)(v7 + 48), stdout);
fputc((unsigned __int8)(v5 + 48), stdout);
result = fputc((unsigned __int8)(v3 + 48), stdout);
}
else if ( (_BYTE)v7 )
{
fputc((unsigned __int8)(v7 + 48), stdout);
fputc((unsigned __int8)(v5 + 48), stdout);
result = fputc((unsigned __int8)(v3 + 48), stdout);
}
else
{
if ( (_BYTE)v5 )
fputc((unsigned __int8)(v5 + 48), stdout);
result = fputc((unsigned __int8)(v3 + 48), stdout);
}
return result;
}

canonical_decompiled_code:
int __fastcall func18(const char *a1, unsigned __int16 a2)
{
unsigned int v2; // ebx
char v3; // r13
unsigned int v4; // ebp
unsigned int v5; // ebx
unsigned int v6; // eax
unsigned int v7; // ebp
unsigned int v8; // er14
int result; // eax

func0(a1);
if ( !a2 )
return fputc(48, stdout);
v2 = a2 / 0xAu;
v3 = a2 % 0xAu;
v4 = (unsigned __int16)v2 / 0xAu;
v5 = v2 % 0xA;
v6 = (unsigned __int16)v4 / 0xAu;
v7 = v4 % 0xA;
v8 = v6 % 0xA;
if ( a2 > 0x270Fu )
{
fputc((unsigned __int16)v6 / 0xAu + 48, stdout);
fputc((unsigned __int8)(v8 + 48), stdout);
fputc((unsigned __int8)(v7 + 48), stdout);
fputc((unsigned __int8)(v5 + 48), stdout);
result = fputc((unsigned __int8)(v3 + 48), stdout);
}
else if ( (_BYTE)v8 )
{
fputc((unsigned __int8)(v8 + 48), stdout);
fputc((unsigned __int8)(v7 + 48), stdout);
fputc((unsigned __int8)(v5 + 48), stdout);
result = fputc((unsigned __int8)(v3 + 48), stdout);
}
else if ( (_BYTE)v7 )
{
fputc((unsigned __int8)(v7 + 48), stdout);
fputc((unsigned __int8)(v5 + 48), stdout);
result = fputc((unsigned __int8)(v3 + 48), stdout);
}
else
{
if ( (_BYTE)v5 )
fputc((unsigned __int8)(v5 + 48), stdout);
result = fputc((unsigned __int8)(v3 + 48), stdout);
}
return result;
}

original_code:
void print_dw(const char *str, uint16_t v) {
 print(str);
 uint8_t n3,n2,n1,n0;
 if (v==0) {
  fputc('0',stdout);
  return;
 }
 n0 = v % 10;
 v = v / 10;
 n1 = v % 10;
 v = v / 10;
 n2 = v % 10;
 v = v / 10;
 n3 = v % 10;
 v = v / 10;
 if (v!=0) {
  fputc('0'+v,stdout);
  fputc('0'+n3,stdout);
  fputc('0'+n2,stdout);
  fputc('0'+n1,stdout);
  fputc('0'+n0,stdout);
 } else if (n3 != 0) {
  fputc('0'+n3,stdout);
  fputc('0'+n2,stdout);
  fputc('0'+n1,stdout);
  fputc('0'+n0,stdout);
 } else if (n2 != 0) {
  fputc('0'+n2,stdout);
  fputc('0'+n1,stdout);
  fputc('0'+n0,stdout);
 } else if (n1 != 0) {
  fputc('0'+n1,stdout);
  fputc('0'+n0,stdout);
 } else {
  fputc('0'+n0,stdout);
 }
}

canonical_original_code:
void print_dw(char *str, unsigned short v) {
 print(str);
 unsigned char n3; unsigned char n2; unsigned char n1; unsigned char n0;
 if (v==0) {
  fputc('0',stdout);
  return;
 }
 n0 = v % 10;
 v = v / 10;
 n1 = v % 10;
 v = v / 10;
 n2 = v % 10;
 v = v / 10;
 n3 = v % 10;
 v = v / 10;
 if (v!=0) {
  fputc('0'+v,stdout);
  fputc('0'+n3,stdout);
  fputc('0'+n2,stdout);
  fputc('0'+n1,stdout);
  fputc('0'+n0,stdout);
 } else if (n3 != 0) {
  fputc('0'+n3,stdout);
  fputc('0'+n2,stdout);
  fputc('0'+n1,stdout);
  fputc('0'+n0,stdout);
 } else if (n2 != 0) {
  fputc('0'+n2,stdout);
  fputc('0'+n1,stdout);
  fputc('0'+n0,stdout);
 } else if (n1 != 0) {
  fputc('0'+n1,stdout);
  fputc('0'+n0,stdout);
 } else {
  fputc('0'+n0,stdout);
 }
}


decompiled_code:
void cc_store_0()
{
;
}

canonical_decompiled_code:
void func0()
{
;
}

original_code: void cc_store_0(){}

canonical_original_code: void cc_store_0(){}


decompiled_code:
void cc_store_1()
{
;
}

canonical_decompiled_code:
void func1()
{
;
}

original_code: void cc_store_1(){}

canonical_original_code: void cc_store_1(){}


decompiled_code:
void cc_store_2()
{
;
}

canonical_decompiled_code:
void func2()
{
;
}

original_code: void cc_store_2(){}

canonical_original_code: void cc_store_2(){}


decompiled_code:
void cc_store_3()
{
;
}

canonical_decompiled_code:
void func3()
{
;
}

original_code: void cc_store_3(){}

canonical_original_code: void cc_store_3(){}


decompiled_code:
__int16 cc_calibrate()
{
__int16 result; // ax

result = word_47A - cc_data;
word_480 = word_47A - cc_data;
return result;
}

canonical_decompiled_code:
__int16 func4()
{
__int16 result; // ax

result = word_47A - cc_data;
word_480 = word_47A - cc_data;
return result;
}

original_code:
void cc_calibrate() {
 cc_data.calibrate = cc_data.v1 - cc_data.v0;
}


decompiled_code:
void cc_clear()
{
;
}

canonical_decompiled_code:
void func5()
{
;
}

original_code:
void cc_clear() {
 cc_store_0();
 cc_store_1();
 cc_store_2();
 cc_store_3();
}


decompiled_code:
__int64 cc_dump()
{
unsigned __int16 v0; // bp
unsigned __int16 v1; // bx

v0 = word_47A - (cc_data + word_480);
v1 = word_47E - (word_47C + word_480);
print("cc_values:");
print_hw(" ", (unsigned __int16)cc_data);
print_hw(" ", (unsigned __int16)word_47A);
print_hw(" ", (unsigned __int16)word_47C);
print_hw(" ", (unsigned __int16)word_47E);
print_dw(" A = ", v0);
print_dw(" B = ", v1);
return print_nl();
}

canonical_decompiled_code:
__int64 func6()
{
unsigned __int16 v0; // bp
unsigned __int16 v1; // bx

v0 = word_47A - (cc_data + word_480);
v1 = word_47E - (word_47C + word_480);
print("cc_values:");
print_hw(" ", (unsigned __int16)cc_data);
print_hw(" ", (unsigned __int16)word_47A);
print_hw(" ", (unsigned __int16)word_47C);
print_hw(" ", (unsigned __int16)word_47E);
print_dw(" A = ", v0);
print_dw(" B = ", v1);
return print_nl();
}

original_code:
void cc_dump() {
 uint16_t a;
 uint16_t b;
 a = cc_data.v1 - cc_data.v0;
 b = cc_data.v3 - cc_data.v2;
 a-=cc_data.calibrate;
 b-=cc_data.calibrate;
 print("cc_values:");
 print_hw(" ",cc_data.v0);
 print_hw(" ",cc_data.v1);
 print_hw(" ",cc_data.v2);
 print_hw(" ",cc_data.v3);
 print_dw(" A = ",a);
 print_dw(" B = ",b);
 print_nl();
}

canonical_original_code:
void cc_dump() {
 unsigned short a;
 unsigned short b;
 a = cc_data.v1 - cc_data.v0;
 b = cc_data.v3 - cc_data.v2;
 a-=cc_data.calibrate;
 b-=cc_data.calibrate;
 print("cc_values:");
 print_hw(" ",cc_data.v0);
 print_hw(" ",cc_data.v1);
 print_hw(" ",cc_data.v2);
 print_hw(" ",cc_data.v3);
 print_dw(" A = ",a);
 print_dw(" B = ",b);
 print_nl();
}

variable_types:
a
unsigned short

variable_types:
b
unsigned short


decompiled_code:
__int64 cc_get_a()
{
return (unsigned __int16)word_47A - (unsigned int)(unsigned __int16)(cc_data + word_480);
}

canonical_decompiled_code:
__int64 func7()
{
return (unsigned __int16)word_47A - (unsigned int)(unsigned __int16)(cc_data + word_480);
}

original_code:
uint16_t cc_get_a() {
 uint16_t a;
 a = cc_data.v1 - cc_data.v0;
 a-=cc_data.calibrate;
 return a;
}

canonical_original_code:
unsigned short cc_get_a() {
 unsigned short a;
 a = cc_data.v1 - cc_data.v0;
 a-=cc_data.calibrate;
 return a;
}

return_type: unsigned short


decompiled_code:
__int64 cc_get_b()
{
return (unsigned __int16)word_47E - (unsigned int)(unsigned __int16)(word_47C + word_480);
}

canonical_decompiled_code:
__int64 func8()
{
return (unsigned __int16)word_47E - (unsigned int)(unsigned __int16)(word_47C + word_480);
}

original_code:
uint16_t cc_get_b() {
 uint16_t b;
 b = cc_data.v3 - cc_data.v2;
 b-=cc_data.calibrate;
 return b;
}

canonical_original_code:
unsigned short cc_get_b() {
 unsigned short b;
 b = cc_data.v3 - cc_data.v2;
 b-=cc_data.calibrate;
 return b;
}


decompiled_code:
__int16 cc_init()
{
t_msec = 0;
t_sec = 0;
t_slot_len = 1;
return cc_calibrate();
}

canonical_decompiled_code:
__int16 func10()
{
t_msec = 0;
t_sec = 0;
t_slot_len = 1;
return func4();
}

original_code:
void cc_init() {
 t_msec = 0;
 t_sec = 0;
 t_slot_len = 1;
 cc_store_0();
 cc_store_1();
 cc_store_2();
 cc_store_3();
 cc_calibrate();
 cc_store_0();
 cc_store_1();
 cc_store_2();
 cc_store_3();
}


decompiled_code:
__int64 timer_get_sec()
{
return (unsigned __int16)t_sec;
}

canonical_decompiled_code:
__int64 func11()
{
return (unsigned __int16)t_sec;
}

original_code:
uint16_t timer_get_sec() {
 return t_sec;
}

canonical_original_code:
unsigned short timer_get_sec() {
 return t_sec;
}


decompiled_code:
__int64 timer_show()
{
print("timer show: ");
print_hw(" sec: ", (unsigned __int16)t_sec);
print_hw(" msec: ", (unsigned __int16)t_msec);
return print_nl();
}

canonical_decompiled_code:
__int64 func12()
{
print("timer show: ");
print_hw(" sec: ", (unsigned __int16)t_sec);
print_hw(" msec: ", (unsigned __int16)t_msec);
return print_nl();
}

original_code:
void timer_show() {
 print("timer show: ");
 print_hw(" sec: ", t_sec);
 print_hw(" msec: ", t_msec);
 print_nl();
}


decompiled_code:
__int64 timer_clear()
{
t_sec = 0;
t_msec = 0;
return timer_show();
}

canonical_decompiled_code:
__int64 func13()
{
t_sec = 0;
t_msec = 0;
return func12();
}

original_code:
void timer_clear() {
 ;
 t_sec = 0;
 t_msec = 0;
 ;
 timer_show();
}


decompiled_code:
void __fastcall cc_slot_set_top(char a1)
{
t_slot_top = a1;
}

canonical_decompiled_code:
void __fastcall func14(char a1)
{
t_slot_top = a1;
}

original_code:
void cc_slot_set_top(uint8_t t) {
 t_slot_top = t;
}

canonical_original_code:
void cc_slot_set_top(unsigned char t) {
 t_slot_top = t;
}

variable_types:
t
unsigned char


decompiled_code:
__int64 __fastcall cc_slot_set(char a1)
{
__int64 result; // rax

t_slot = a1;
result = (unsigned __int8)t_slot_len;
t_slot_lec = t_slot_len;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func15(char a1)
{
__int64 result; // rax

t_slot = a1;
result = (unsigned __int8)t_slot_len;
t_slot_lec = t_slot_len;
return result;
}

original_code:
void cc_slot_set(uint8_t s) {
 ;
 t_slot = s;
 t_slot_lec = t_slot_len;
 ;
}

canonical_original_code:
void cc_slot_set(unsigned char s) {
 ;
 t_slot = s;
 t_slot_lec = t_slot_len;
 ;
}

variable_types:
s
unsigned char


decompiled_code:
__int64 cc_slot_get()
{
return (unsigned __int8)t_slot;
}

canonical_decompiled_code:
__int64 func16()
{
return (unsigned __int8)t_slot;
}

original_code:
uint8_t cc_slot_get() {
 uint8_t s;
 ;
 s = t_slot;
 ;
 return s;
}

canonical_original_code:
unsigned char cc_slot_get() {
 unsigned char s;
 ;
 s = t_slot;
 ;
 return s;
}

return_type: unsigned char


decompiled_code:
__int64 __fastcall cc_slot_wait(char a1)
{
__int64 result; // rax

do
result = cc_slot_get();
while ( (_BYTE)result != a1 );
return result;
}

canonical_decompiled_code:
__int64 __fastcall func17(char a1)
{
__int64 result; // rax

do
result = func16();
while ( (_BYTE)result != a1 );
return result;
}

original_code:
void cc_slot_wait(uint8_t s) {
 while(s!=cc_slot_get());
}

canonical_original_code:
void cc_slot_wait(unsigned char s) {
 while(s!=cc_slot_get());
}


decompiled_code:
void __fastcall cc_slot_set_len(char a1)
{
t_slot_len = a1;
}

canonical_decompiled_code:
void __fastcall func18(char a1)
{
t_slot_len = a1;
}

original_code:
void cc_slot_set_len(uint8_t sl) {
 t_slot_len = sl;
}

canonical_original_code:
void cc_slot_set_len(unsigned char sl) {
 t_slot_len = sl;
}

variable_types:
sl
unsigned char


decompiled_code:
__int64 timer_do_prompt()
{
bool v0; // cf
bool v1; // zf
const char *v2; // rdi
__int64 v3; // rcx
char *v4; // rsi
char v5; // al
bool v6; // cf
bool v7; // zf
char *v8; // rsi
const char *v9; // rdi
__int64 v10; // rcx
bool v11; // al
bool v12; // cf
bool v13; // zf
char *v14; // rsi
const char *v15; // rdi
__int64 v16; // rcx
char v17; // al
bool v18; // cf
bool v19; // zf
char *v20; // rsi
const char *v21; // rdi
__int64 v22; // rcx
char v23; // al
bool v24; // cf
bool v25; // zf
char *v26; // rsi
const char *v27; // rdi
__int64 v28; // rcx
char v29; // al
bool v30; // cf
bool v31; // zf
char *v32; // rsi
const char *v33; // rdi
__int64 v34; // rcx
int v36; // eax
int v37; // ebx
unsigned __int8 v38; // al
char v39; // al
char v40; // al
unsigned __int16 v41; // ax
__int64 v42; // rsi
unsigned __int16 v43; // ax
__int64 v44; // rsi
char v45[40]; // [rsp+0h] [rbp-28h] BYREF

scan_key(v45, 17LL);
v2 = "show";
v3 = 5LL;
v4 = v45;
do
{
if ( !v3 )
break;
v0 = (unsigned __int8)*v4 < (unsigned int)*v2;
v1 = *v4++ == *v2++;
--v3;
}
while ( v1 );
v5 = (!v0 && !v1) - v0;
v6 = 0;
v7 = v5 == 0;
if ( v5 )
{
v8 = v45;
v9 = "clear";
v10 = 6LL;
do
{
if ( !v10 )
break;
v6 = (unsigned __int8)*v8 < (unsigned int)*v9;
v7 = *v8++ == *v9++;
--v10;
}
while ( v7 );
if ( (!v6 && !v7) == v6 )
{
timer_clear(v9, v8);
}
else
{
v11 = strcmp(v45, "slot") != 0;
v12 = 0;
v13 = !v11;
if ( !v11 )
{
print_hb("top = ", (unsigned __int8)t_slot_top);
print_hb(", val = ", (unsigned __int8)t_slot);
print_nl();
}
v14 = v45;
v15 = "slot_get";
v16 = 9LL;
do
{
if ( !v16 )
break;
v12 = (unsigned __int8)*v14 < (unsigned int)*v15;
v13 = *v14++ == *v15++;
--v16;
}
while ( v13 );
v17 = (!v12 && !v13) - v12;
v18 = 0;
v19 = v17 == 0;
if ( !v17 )
{
v36 = scan_uint16(v15, v14);
v37 = v36 - 1;
v18 = 0;
v19 = (_WORD)v36 == 0;
if ( (_WORD)v36 )
{
do
{
v38 = cc_slot_get();
print_hb("slot get = ", v38);
print_nl();
v18 = (_WORD)--v37 != 0xFFFF;
v19 = (_WORD)v37 == 0xFFFF;
}
while ( (_WORD)v37 != 0xFFFF );
}
}
v20 = v45;
v21 = "slot_set_top";
v22 = 13LL;
do
{
if ( !v22 )
break;
v18 = (unsigned __int8)*v20 < (unsigned int)*v21;
v19 = *v20++ == *v21++;
--v22;
}
while ( v19 );
v23 = (!v18 && !v19) - v18;
v24 = 0;
v25 = v23 == 0;
if ( !v23 )
{
v39 = scan_uint8(v21, v20);
cc_slot_set_top(v39);
}
v26 = v45;
v27 = "slot_wait";
v28 = 10LL;
do
{
if ( !v28 )
break;
v24 = (unsigned __int8)*v26 < (unsigned int)*v27;
v25 = *v26++ == *v27++;
--v28;
}
while ( v25 );
v29 = (!v24 && !v25) - v24;
v30 = 0;
v31 = v29 == 0;
if ( !v29 )
{
v40 = scan_uint8(v27, v26);
cc_slot_wait(v40);
}
v32 = v45;
v33 = "slot_test";
v34 = 10LL;
do
{
if ( !v34 )
break;
v30 = (unsigned __int8)*v32 < (unsigned int)*v33;
v31 = *v32++ == *v33++;
--v34;
}
while ( v31 );
if ( (!v30 && !v31) == v30 )
{
cc_slot_wait(20);
cc_slot_wait(0);
cc_slot_wait(1);
v41 = cc_get_a(1LL, v32);
print_dw("a = ", v41);
v42 = (unsigned __int16)cc_get_b();
print_dw(", b = ", v42);
cc_slot_wait(19);
cc_slot_wait(20);
cc_slot_wait(0);
v43 = cc_get_a(0LL, v42);
print_dw("a = ", v43);
v44 = (unsigned __int16)cc_get_b();
print_dw(", b = ", v44);
print_nl();
}
}
}
else
{
timer_show(v2, v4);
}
return 1LL;
}

canonical_decompiled_code:
__int64 func19()
{
bool v0; // cf
bool v1; // zf
const char *v2; // rdi
__int64 v3; // rcx
char *v4; // rsi
char v5; // al
bool v6; // cf
bool v7; // zf
char *v8; // rsi
const char *v9; // rdi
__int64 v10; // rcx
bool v11; // al
bool v12; // cf
bool v13; // zf
char *v14; // rsi
const char *v15; // rdi
__int64 v16; // rcx
char v17; // al
bool v18; // cf
bool v19; // zf
char *v20; // rsi
const char *v21; // rdi
__int64 v22; // rcx
char v23; // al
bool v24; // cf
bool v25; // zf
char *v26; // rsi
const char *v27; // rdi
__int64 v28; // rcx
char v29; // al
bool v30; // cf
bool v31; // zf
char *v32; // rsi
const char *v33; // rdi
__int64 v34; // rcx
int v36; // eax
int v37; // ebx
unsigned __int8 v38; // al
char v39; // al
char v40; // al
unsigned __int16 v41; // ax
__int64 v42; // rsi
unsigned __int16 v43; // ax
__int64 v44; // rsi
char v45[40]; // [rsp+0h] [rbp-28h] BYREF

scan_key(v45, 17LL);
v2 = "show";
v3 = 5LL;
v4 = v45;
do
{
if ( !v3 )
break;
v0 = (unsigned __int8)*v4 < (unsigned int)*v2;
v1 = *v4++ == *v2++;
--v3;
}
while ( v1 );
v5 = (!v0 && !v1) - v0;
v6 = 0;
v7 = v5 == 0;
if ( v5 )
{
v8 = v45;
v9 = "clear";
v10 = 6LL;
do
{
if ( !v10 )
break;
v6 = (unsigned __int8)*v8 < (unsigned int)*v9;
v7 = *v8++ == *v9++;
--v10;
}
while ( v7 );
if ( (!v6 && !v7) == v6 )
{
func13(v9, v8);
}
else
{
v11 = strcmp(v45, "slot") != 0;
v12 = 0;
v13 = !v11;
if ( !v11 )
{
print_hb("top = ", (unsigned __int8)t_slot_top);
print_hb(", val = ", (unsigned __int8)t_slot);
print_nl();
}
v14 = v45;
v15 = "slot_get";
v16 = 9LL;
do
{
if ( !v16 )
break;
v12 = (unsigned __int8)*v14 < (unsigned int)*v15;
v13 = *v14++ == *v15++;
--v16;
}
while ( v13 );
v17 = (!v12 && !v13) - v12;
v18 = 0;
v19 = v17 == 0;
if ( !v17 )
{
v36 = scan_uint16(v15, v14);
v37 = v36 - 1;
v18 = 0;
v19 = (_WORD)v36 == 0;
if ( (_WORD)v36 )
{
do
{
v38 = func16();
print_hb("slot get = ", v38);
print_nl();
v18 = (_WORD)--v37 != 0xFFFF;
v19 = (_WORD)v37 == 0xFFFF;
}
while ( (_WORD)v37 != 0xFFFF );
}
}
v20 = v45;
v21 = "slot_set_top";
v22 = 13LL;
do
{
if ( !v22 )
break;
v18 = (unsigned __int8)*v20 < (unsigned int)*v21;
v19 = *v20++ == *v21++;
--v22;
}
while ( v19 );
v23 = (!v18 && !v19) - v18;
v24 = 0;
v25 = v23 == 0;
if ( !v23 )
{
v39 = scan_uint8(v21, v20);
func14(v39);
}
v26 = v45;
v27 = "slot_wait";
v28 = 10LL;
do
{
if ( !v28 )
break;
v24 = (unsigned __int8)*v26 < (unsigned int)*v27;
v25 = *v26++ == *v27++;
--v28;
}
while ( v25 );
v29 = (!v24 && !v25) - v24;
v30 = 0;
v31 = v29 == 0;
if ( !v29 )
{
v40 = scan_uint8(v27, v26);
func17(v40);
}
v32 = v45;
v33 = "slot_test";
v34 = 10LL;
do
{
if ( !v34 )
break;
v30 = (unsigned __int8)*v32 < (unsigned int)*v33;
v31 = *v32++ == *v33++;
--v34;
}
while ( v31 );
if ( (!v30 && !v31) == v30 )
{
func17(20);
func17(0);
func17(1);
v41 = func7(1LL, v32);
print_dw("a = ", v41);
v42 = (unsigned __int16)func8();
print_dw(", b = ", v42);
func17(19);
func17(20);
func17(0);
v43 = func7(0LL, v42);
print_dw("a = ", v43);
v44 = (unsigned __int16)func8();
print_dw(", b = ", v44);
print_nl();
}
}
}
else
{
func12(v2, v4);
}
return 1LL;
}

original_code:
int timer_do_prompt() {
        char cmd[17];
        scan_key(cmd,17);
        if (strcmp(cmd,"show")==0) {
   timer_show();
                        return 1;
        }
        if (strcmp(cmd,"clear")==0) {
   timer_clear();
                        return 1;
        }
 if (strcmp(cmd,"slot")==0) {
  print_hb("top = ", t_slot_top);
  print_hb(", val = ", t_slot);
  print_nl();
 }
 if (strcmp(cmd,"slot_get")==0) {
  uint16_t c = scan_uint16();
  while(c--) {
  print_hb("slot get = ",cc_slot_get()); print_nl();
  }
 }
 if (strcmp(cmd,"slot_set_top")==0) {
  uint8_t t = scan_uint8();
  cc_slot_set_top(t);
 }
 if (strcmp(cmd,"slot_wait")==0) {
  uint8_t t = scan_uint8();
  cc_slot_wait(t);
 }
 if (strcmp(cmd,"slot_test")==0) {
  cc_slot_wait(20);
  cc_store_0();
  cc_slot_wait(0);
  cc_store_2();
  cc_slot_wait(1);
  cc_store_1();
  cc_store_3();
  print_dw("a = ",cc_get_a());
  print_dw(", b = ",cc_get_b());
  cc_slot_wait(19);
  cc_store_0();
  cc_slot_wait(20);
  cc_store_2();
  cc_slot_wait(0);
  cc_store_1();
  cc_store_3();
  print_dw("a = ",cc_get_a());
  print_dw(", b = ",cc_get_b());
  print_nl();
 }
        return 1;
}

canonical_original_code:
int timer_do_prompt() {
        char cmd[17];
        scan_key(cmd,17);
        if (strcmp(cmd,"show")==0) {
   timer_show();
                        return 1;
        }
        if (strcmp(cmd,"clear")==0) {
   timer_clear();
                        return 1;
        }
 if (strcmp(cmd,"slot")==0) {
  print_hb("top = ", t_slot_top);
  print_hb(", val = ", t_slot);
  print_nl();
 }
 if (strcmp(cmd,"slot_get")==0) {
  unsigned short c = scan_uint16();
  while(c--) {
  print_hb("slot get = ",cc_slot_get()); print_nl();
  }
 }
 if (strcmp(cmd,"slot_set_top")==0) {
  unsigned char t = scan_uint8();
  cc_slot_set_top(t);
 }
 if (strcmp(cmd,"slot_wait")==0) {
  unsigned char t = scan_uint8();
  cc_slot_wait(t);
 }
 if (strcmp(cmd,"slot_test")==0) {
  cc_slot_wait(20);
  cc_store_0();
  cc_slot_wait(0);
  cc_store_2();
  cc_slot_wait(1);
  cc_store_1();
  cc_store_3();
  print_dw("a = ",cc_get_a());
  print_dw(", b = ",cc_get_b());
  cc_slot_wait(19);
  cc_store_0();
  cc_slot_wait(20);
  cc_store_2();
  cc_slot_wait(0);
  cc_store_1();
  cc_store_3();
  print_dw("a = ",cc_get_a());
  print_dw(", b = ",cc_get_b());
  print_nl();
 }
        return 1;
}

variable_types:
cmd
char [17]

variable_types:
c
unsigned short


decompiled_code:
__int64 __fastcall eewr_b(unsigned __int16 a1, unsigned __int8 a2)
{
return eeprom_write_byte(a1, a2);
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned __int16 a1, unsigned __int8 a2)
{
return eeprom_write_byte(a1, a2);
}

original_code:
void eewr_b(uint16_t a, uint8_t v) {
 uint8_t *ee_base = 0;
 eeprom_write_byte(ee_base+a,v);
}

canonical_original_code:
void eewr_b(unsigned short a, unsigned char v) {
 unsigned char *ee_base = 0;
 eeprom_write_byte(ee_base+a,v);
}


decompiled_code:
__int64 __fastcall eerd_b(unsigned __int16 a1)
{
return eeprom_read_byte(a1);
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned __int16 a1)
{
return eeprom_read_byte(a1);
}

original_code:
uint8_t eerd_b(uint16_t a) {
 const uint8_t *ee_base = 0;
 return eeprom_read_byte(ee_base+a);
}

canonical_original_code:
unsigned char eerd_b(unsigned short a) {
 unsigned char *ee_base = 0;
 return eeprom_read_byte(ee_base+a);
}


decompiled_code:
__int64 __fastcall eewr_w(unsigned __int16 a1, __int16 a2)
{
eewr_b(a1, HIBYTE(a2));
return eewr_b(a1 + 1, a2);
}

canonical_decompiled_code:
__int64 __fastcall func2(unsigned __int16 a1, __int16 a2)
{
func0(a1, HIBYTE(a2));
return func0(a1 + 1, a2);
}

original_code:
void eewr_w(uint16_t a, uint16_t v) {
        eewr_b(a,(v&0xff00)>>8);
        eewr_b(a+1,(v&0xff));
}

canonical_original_code:
void eewr_w(unsigned short a, unsigned short v) {
        eewr_b(a,(v&0xff00)>>8);
        eewr_b(a+1,(v&0xff));
}


decompiled_code:
__int64 __fastcall eerd_w(unsigned __int16 a1)
{
unsigned int v1; // ebp

v1 = (unsigned int)eerd_b(a1) << 8;
return v1 + (unsigned __int8)eerd_b(a1 + 1);
}

canonical_decompiled_code:
__int64 __fastcall func3(unsigned __int16 a1)
{
unsigned int v1; // ebp

v1 = (unsigned int)func1(a1) << 8;
return v1 + (unsigned __int8)func1(a1 + 1);
}

original_code:
uint16_t eerd_w(uint16_t a) {
        uint16_t r = eerd_b(a) << 8;
        r+=eerd_b(a+1);
        return r;
}

canonical_original_code:
unsigned short eerd_w(unsigned short a) {
        unsigned short r = eerd_b(a) << 8;
        r+=eerd_b(a+1);
        return r;
}

variable_types:
r
unsigned short


decompiled_code:
__int64 ee_dump()
{
int i; // ebx
unsigned __int8 v1; // al

print(&unk_B9);
for ( i = 0; i != 32; ++i )
{
v1 = eerd_b(i);
print_hb(&unk_BD, v1);
}
return print_nl();
}

canonical_decompiled_code:
__int64 func4()
{
int i; // ebx
unsigned __int8 v1; // al

print(&unk_B9);
for ( i = 0; i != 32; ++i )
{
v1 = func1(i);
print_hb(&unk_BD, v1);
}
return print_nl();
}

original_code:
void ee_dump(){
        uint16_t a;
        print("ee:");
        for(a=0; a<32; a++) {
                print_hb(" ", eerd_b(a));
        }
        print_nl();
}

canonical_original_code:
void ee_dump(){
        unsigned short a;
        print("ee:");
        for(a=0; a<32; a++) {
                print_hb(" ", eerd_b(a));
        }
        print_nl();
}


decompiled_code:
void led_y_on()
{
PORTD |= 0x20u;
}

canonical_decompiled_code:
void func0()
{
PORTD |= 0x20u;
}


decompiled_code:
void led_g_on()
{
PORTC |= 2u;
}

canonical_decompiled_code:
void func1()
{
PORTC |= 2u;
}


decompiled_code:
void led_y_off()
{
PORTD &= 0xDFu;
}

canonical_decompiled_code:
void func2()
{
PORTD &= 0xDFu;
}


decompiled_code:
void led_g_off()
{
PORTC &= 0xFDu;
}

canonical_decompiled_code:
void func3()
{
PORTC &= 0xFDu;
}


decompiled_code:
void i2c_hold()
{
;
}

canonical_decompiled_code:
void func4()
{
;
}

original_code:
void i2c_hold() {
    ;
}

canonical_original_code:
void i2c_hold() {
    ;
}


decompiled_code:
void __fastcall i2c_sdaOut(char a1)
{
if ( a1 )
{
DDRC &= 0xFEu;
led_g_on();
PORTC |= 1u;
}
else
{
DDRC |= 1u;
led_g_off();
PORTC &= 0xFEu;
}
}

canonical_decompiled_code:
void __fastcall func5(char a1)
{
if ( a1 )
{
DDRC &= 0xFEu;
func1();
PORTC |= 1u;
}
else
{
DDRC |= 1u;
func3();
PORTC &= 0xFEu;
}
}

variable_types:
value
unsigned char


decompiled_code:
__int64 i2c_sdaIn()
{
return PINC & 1;
}

canonical_decompiled_code:
__int64 func6()
{
return PINC & 1;
}

original_code:
uint8_t i2c_sdaIn() {
    if (( PINC & (1<<(0)))) {
        return 1;
    }
    return 0;
}

canonical_original_code:
unsigned char i2c_sdaIn() {
    if (( PINC & (1<<(0)))) {
        return 1;
    }
    return 0;
}


decompiled_code:
void i2c_sclHi()
{
led_y_on();
PORTD |= 0x10u;
}

canonical_decompiled_code:
void func7()
{
func0();
PORTD |= 0x10u;
}


decompiled_code:
void i2c_sclLo()
{
led_y_off();
PORTD &= 0xEFu;
}

canonical_decompiled_code:
void func8()
{
func2();
PORTD &= 0xEFu;
}


decompiled_code:
void i2c_init()
{
i2c_sdaOut(1);
DDRD |= 0x10u;
i2c_sclHi();
}

canonical_decompiled_code:
void func9()
{
func5(1);
DDRD |= 0x10u;
func7();
}


decompiled_code:
bool __fastcall i2c_write(char a1)
{
int v1; // ebp
unsigned __int8 v2; // bl
char v3; // bl

i2c_sclLo();
v1 = 8;
v2 = 0x80;
do
{
i2c_sdaOut(v2 & a1);
i2c_sclHi();
i2c_sclLo();
v2 >>= 1;
--v1;
}
while ( v1 );
i2c_sdaOut(1);
i2c_sclHi();
v3 = i2c_sdaIn();
i2c_sclLo();
return v3 == 0;
}

canonical_decompiled_code:
bool __fastcall func10(char a1)
{
int v1; // ebp
unsigned __int8 v2; // bl
char v3; // bl

func8();
v1 = 8;
v2 = 0x80;
do
{
func5(v2 & a1);
func7();
func8();
v2 >>= 1;
--v1;
}
while ( v1 );
func5(1);
func7();
v3 = func6();
func8();
return v3 == 0;
}

original_code:
uint8_t i2c_write(uint8_t data) {
    i2c_sclLo();
    uint8_t mask;
    for (mask = 0x80; mask != 0; mask >>=1) {
        i2c_sdaOut(data & mask);
        i2c_sclHi();
        i2c_sclLo();
    }
    i2c_sdaOut(1);
    i2c_sclHi();
    uint8_t ack = ! i2c_sdaIn();
    i2c_sclLo();
    return ack;
}

canonical_original_code:
unsigned char i2c_write(unsigned char data) {
    i2c_sclLo();
    unsigned char mask;
    for (mask = 0x80; mask != 0; mask >>=1) {
        i2c_sdaOut(data & mask);
        i2c_sclHi();
        i2c_sclLo();
    }
    i2c_sdaOut(1);
    i2c_sclHi();
    unsigned char ack = ! i2c_sdaIn();
    i2c_sclLo();
    return ack;
}

variable_types:
data
unsigned char

variable_types:
mask
unsigned char

variable_types:
ack
unsigned char


decompiled_code:
bool __fastcall i2c_start(char a1)
{
i2c_sclLo();
i2c_sclHi();
i2c_sdaOut(0);
return i2c_write(a1);
}

canonical_decompiled_code:
bool __fastcall func11(char a1)
{
func8();
func7();
func5(0);
return func10(a1);
}

original_code:
uint8_t i2c_start(uint8_t addr) {
    i2c_sclLo();
    i2c_sclHi();
    i2c_sdaOut(0);
    return i2c_write(addr);
}

canonical_original_code:
unsigned char i2c_start(unsigned char addr) {
    i2c_sclLo();
    i2c_sclHi();
    i2c_sdaOut(0);
    return i2c_write(addr);
}

variable_types:
addr
unsigned char


decompiled_code:
void i2c_stop()
{
i2c_sdaOut(0);
i2c_sclHi();
i2c_sdaOut(1);
}

canonical_decompiled_code:
void func12()
{
func5(0);
func7();
func5(1);
}


decompiled_code:
__int64 __fastcall i2c_read(char a1)
{
int v1; // er12
int v2; // ebp
unsigned int v3; // ebx

v1 = 8;
v2 = -128;
v3 = 0;
do
{
i2c_sclHi();
if ( (unsigned __int8)i2c_sdaIn() )
v3 |= v2;
i2c_sclLo();
LOBYTE(v2) = (unsigned __int8)v2 >> 1;
--v1;
}
while ( v1 );
i2c_sdaOut(a1);
i2c_sclHi();
i2c_sclLo();
if ( a1 )
i2c_stop();
i2c_sdaOut(1);
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func13(char a1)
{
int v1; // er12
int v2; // ebp
unsigned int v3; // ebx

v1 = 8;
v2 = -128;
v3 = 0;
do
{
func7();
if ( (unsigned __int8)func6() )
v3 |= v2;
func8();
LOBYTE(v2) = (unsigned __int8)v2 >> 1;
--v1;
}
while ( v1 );
func5(a1);
func7();
func8();
if ( a1 )
func12();
func5(1);
return v3;
}

original_code:
uint8_t i2c_read(uint8_t last) {
    uint8_t data = 0;
    uint8_t mask;
    for (mask = 0x80; mask !=0; mask >>=1) {
        i2c_sclHi();
        if (i2c_sdaIn()) {
            data |= mask;
        }
        i2c_sclLo();
    }
    i2c_sdaOut(last);
    i2c_sclHi();
    i2c_sclLo();
    if (last) {
        i2c_stop();
    }
    i2c_sdaOut(1);
    return data;
}

canonical_original_code:
unsigned char i2c_read(unsigned char last) {
    unsigned char data = 0;
    unsigned char mask;
    for (mask = 0x80; mask !=0; mask >>=1) {
        i2c_sclHi();
        if (i2c_sdaIn()) {
            data |= mask;
        }
        i2c_sclLo();
    }
    i2c_sdaOut(last);
    i2c_sclHi();
    i2c_sclLo();
    if (last) {
        i2c_stop();
    }
    i2c_sdaOut(1);
    return data;
}

variable_types:
last
unsigned char


decompiled_code:
void led_init()
{
DDRD |= 0x20u;
PORTD &= 0xDFu;
DDRC |= 2u;
PORTC &= 0xFDu;
}

canonical_decompiled_code:
void func14()
{
DDRD |= 0x20u;
PORTD &= 0xDFu;
DDRC |= 2u;
PORTC &= 0xFDu;
}


decompiled_code:
void pad_led()
{
char v0; // bl

v0 = 10;
do
{
led_y_on();
led_y_off();
led_g_on();
led_g_off();
--v0;
}
while ( v0 );
}

canonical_decompiled_code:
void func15()
{
char v0; // bl

v0 = 10;
do
{
func0();
func2();
func1();
func3();
--v0;
}
while ( v0 );
}

original_code:
void pad_led() {
    uint8_t l;
    for (l=0; l<10; l++) {
     led_y_on();
        ;
     led_y_off();
     led_g_on();
        ;
     led_g_off();
    }
}

canonical_original_code:
void pad_led() {
    unsigned char l;
    for (l=0; l<10; l++) {
     led_y_on();
        ;
     led_y_off();
     led_g_on();
        ;
     led_g_off();
    }
}

variable_types:
l
unsigned char


decompiled_code:
__int64 pad_ping()
{
unsigned int v0; // eax
unsigned int v1; // ebx

LOBYTE(v0) = i2c_start(64);
v1 = v0;
i2c_stop();
return v1;
}

canonical_decompiled_code:
__int64 func16()
{
unsigned int v0; // eax
unsigned int v1; // ebx

LOBYTE(v0) = func11(64);
v1 = v0;
func12();
return v1;
}

original_code:
uint8_t pad_ping() {
    uint8_t ok = i2c_start(0x40);
    i2c_stop();
    return ok;
}

canonical_original_code:
unsigned char pad_ping() {
    unsigned char ok = i2c_start(0x40);
    i2c_stop();
    return ok;
}

variable_types:
ok
unsigned char


decompiled_code:
__int64 __fastcall pad_write(char a1)
{
unsigned int v1; // eax
unsigned int v2; // eax
unsigned int v3; // ebx

LOBYTE(v1) = i2c_start(64);
if ( (_BYTE)v1 )
{
LOBYTE(v2) = i2c_write(a1);
v3 = v2;
i2c_stop();
pad_last_write_data = a1;
}
else
{
v3 = v1;
i2c_stop();
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func17(char a1)
{
unsigned int v1; // eax
unsigned int v2; // eax
unsigned int v3; // ebx

LOBYTE(v1) = func11(64);
if ( (_BYTE)v1 )
{
LOBYTE(v2) = func10(a1);
v3 = v2;
func12();
pad_last_write_data = a1;
}
else
{
v3 = v1;
func12();
}
return v3;
}

original_code:
uint8_t pad_write(uint8_t data) {
    uint8_t ok;
    ok = i2c_start(0x40 );
    if (!ok) {
        i2c_stop();
        return 0;
    }
    ok = i2c_write(data);
    i2c_stop();
    pad_last_write_data = data;
    return ok;
}

canonical_original_code:
unsigned char pad_write(unsigned char data) {
    unsigned char ok;
    ok = i2c_start(0x40 );
    if (!ok) {
        i2c_stop();
        return 0;
    }
    ok = i2c_write(data);
    i2c_stop();
    pad_last_write_data = data;
    return ok;
}


decompiled_code:
__int64 pad_read()
{
i2c_start(65);
return i2c_read(1);
}

original_code:
uint8_t pad_read() {
    uint8_t ok = i2c_start(0x40 | 1);
    if (!ok) {
    }
    uint8_t data = i2c_read(1);
    return data;
}

canonical_original_code:
unsigned char pad_read() {
    unsigned char ok = i2c_start(0x40 | 1);
    if (!ok) {
    }
    unsigned char data = i2c_read(1);
    return data;
}


decompiled_code:
__int64 pad_state()
{
bool v0; // dl
__int64 result; // rax

v0 = i2c_start(65);
result = 0xFFFFFFFFLL;
if ( v0 )
result = i2c_read(1) & 0x3F;
return result;
}

canonical_decompiled_code:
__int64 func19()
{
bool v0; // dl
__int64 result; // rax

v0 = func11(65);
result = 0xFFFFFFFFLL;
if ( v0 )
result = func13(1) & 0x3F;
return result;
}

original_code:
uint8_t pad_state() {
    uint8_t ok = i2c_start(0x40 | 1);
    if (!ok) {
        return 0xff;
    }
    uint8_t data = i2c_read(1);
    return data & (~((1<<7) | (1<<6)));
}

canonical_original_code:
unsigned char pad_state() {
    unsigned char ok = i2c_start(0x40 | 1);
    if (!ok) {
        return 0xff;
    }
    unsigned char data = i2c_read(1);
    return data & (~((1<<7) | (1<<6)));
}


decompiled_code:
__int64 __fastcall pad_remote_led_y(char a1)
{
char v2; // di

v2 = pad_last_write_data | 0x80;
if ( a1 )
v2 = pad_last_write_data & 0x7F;
return pad_write(v2);
}

canonical_decompiled_code:
__int64 __fastcall func20(char a1)
{
char v2; // di

v2 = pad_last_write_data | 0x80;
if ( a1 )
v2 = pad_last_write_data & 0x7F;
return func17(v2);
}

original_code:
uint8_t pad_remote_led_y(uint8_t on) {
    uint8_t d = pad_last_write_data;
    if (on) {
        d &= ~(1 << 7);
    } else {
        d |= (1 << 7);
    }
    return pad_write(d);
}

canonical_original_code:
unsigned char pad_remote_led_y(unsigned char on) {
    unsigned char d = pad_last_write_data;
    if (on) {
        d &= ~(1 << 7);
    } else {
        d |= (1 << 7);
    }
    return pad_write(d);
}

variable_types:
on
unsigned char

variable_types:
d
unsigned char


decompiled_code:
__int64 __fastcall pad_remote_led_g(char a1)
{
char v2; // di

v2 = pad_last_write_data | 0x40;
if ( a1 )
v2 = pad_last_write_data & 0xBF;
return pad_write(v2);
}

canonical_decompiled_code:
__int64 __fastcall func21(char a1)
{
char v2; // di

v2 = pad_last_write_data | 0x40;
if ( a1 )
v2 = pad_last_write_data & 0xBF;
return func17(v2);
}

original_code:
uint8_t pad_remote_led_g(uint8_t on) {
    uint8_t d = pad_last_write_data;
    if (on) {
        d &= ~(1 << 6);
    } else {
        d |= (1 << 6);
    }
    return pad_write(d);
}

canonical_original_code:
unsigned char pad_remote_led_g(unsigned char on) {
    unsigned char d = pad_last_write_data;
    if (on) {
        d &= ~(1 << 6);
    } else {
        d |= (1 << 6);
    }
    return pad_write(d);
}


decompiled_code:
__int64 pad_remote_led()
{
char v0; // bl
__int64 result; // rax

v0 = 10;
do
{
pad_remote_led_y(1);
pad_remote_led_y(0);
pad_remote_led_g(1);
result = pad_remote_led_g(0);
--v0;
}
while ( v0 );
return result;
}

canonical_decompiled_code:
__int64 func22()
{
char v0; // bl
__int64 result; // rax

v0 = 10;
do
{
func20(1);
func20(0);
func21(1);
result = func21(0);
--v0;
}
while ( v0 );
return result;
}

original_code:
void pad_remote_led() {
    uint8_t l;
    for (l=0; l<10; l++) {
        pad_remote_led_y(1);
        ;
        pad_remote_led_y(0);
        pad_remote_led_g(1);
        ;
        pad_remote_led_g(0);
    }
}

canonical_original_code:
void pad_remote_led() {
    unsigned char l;
    for (l=0; l<10; l++) {
        pad_remote_led_y(1);
        ;
        pad_remote_led_y(0);
        pad_remote_led_g(1);
        ;
        pad_remote_led_g(0);
    }
}


decompiled_code:
__int64 pad_init()
{
i2c_init();
led_init();
return pad_write(255);
}

original_code:
void pad_init() {
    i2c_init();
    led_init();
    pad_write(0xff);
}


decompiled_code:
void __noreturn pad_autoread()
{
unsigned __int8 i; // bp
unsigned __int8 v1; // al
unsigned __int8 v2; // bl

print("pad autoread\n\r");
pad_init();
for ( i = 0; ; i = v2 )
{
do
{
v1 = pad_read();
v2 = v1;
}
while ( i == v1 );
print_hb(0LL, v1);
}
}

canonical_decompiled_code:
void __noreturn func24()
{
unsigned __int8 i; // bp
unsigned __int8 v1; // al
unsigned __int8 v2; // bl

print("pad autoread\n\r");
func23();
for ( i = 0; ; i = v2 )
{
do
{
v1 = func18();
v2 = v1;
}
while ( i == v1 );
print_hb(0LL, v1);
}
}

original_code:
void pad_autoread() {
 print("pad autoread\n\r");
 pad_init();
 uint8_t ld =0;
 while(!0) {
        uint8_t d = pad_read();
     if (ld!=d) {
      print_hb(0,d);
      ld=d;
  }
    }
}

canonical_original_code:
void pad_autoread() {
 print("pad autoread\n\r");
 pad_init();
 unsigned char ld = 0;
 while(!0) {
        unsigned char d = pad_read();
     if (ld!=d) {
      print_hb(0,d);
      ld=d;
  }
    }
}

variable_types:
ld
unsigned char


decompiled_code:
__int64 pad_do_prompt()
{
bool v0; // cf
bool v1; // zf
const char *v2; // rdi
__int64 v3; // rcx
char *v4; // rsi
char v5; // al
bool v6; // cf
bool v7; // zf
char *v8; // rsi
const char *v9; // rdi
__int64 v10; // rcx
char v11; // al
bool v12; // cf
bool v13; // zf
__int64 v14; // rcx
char v15; // al
bool v16; // cf
bool v17; // zf
char *v18; // rsi
const char *v19; // rdi
__int64 v20; // rcx
bool v21; // al
bool v22; // cf
bool v23; // zf
char *v24; // rsi
const char *v25; // rdi
__int64 v26; // rcx
char v27; // al
bool v28; // cf
bool v29; // zf
char *v30; // rsi
const char *v31; // rdi
__int64 v32; // rcx
char v33; // al
bool v34; // cf
bool v35; // zf
char *v36; // rsi
const char *v37; // rdi
__int64 v38; // rcx
char v39; // al
bool v40; // cf
bool v41; // zf
char *v42; // rsi
const char *v43; // rdi
__int64 v44; // rcx
unsigned __int8 v46; // al
__int64 v47; // rsi
char v48; // al
char v49[40]; // [rsp+0h] [rbp-28h] BYREF

scan_key(v49, 17LL);
v2 = "init";
v3 = 5LL;
v4 = v49;
do
{
if ( !v3 )
break;
v0 = (unsigned __int8)*v4 < (unsigned int)*v2;
v1 = *v4++ == *v2++;
--v3;
}
while ( v1 );
v5 = (!v0 && !v1) - v0;
v6 = 0;
v7 = v5 == 0;
if ( !v5 )
{
pad_init(v2, v4);
return 1LL;
}
v8 = v49;
v9 = "test";
v10 = 5LL;
do
{
if ( !v10 )
break;
v6 = (unsigned __int8)*v8 < (unsigned int)*v9;
v7 = *v8++ == *v9++;
--v10;
}
while ( v7 );
v11 = (!v6 && !v7) - v6;
v12 = 0;
v13 = v11 == 0;
if ( !v11 )
goto LABEL_37;
v8 = v49;
v9 = "ping";
v14 = 5LL;
do
{
if ( !v14 )
break;
v12 = (unsigned __int8)*v8 < (unsigned int)*v9;
v13 = *v8++ == *v9++;
--v14;
}
while ( v13 );
v15 = (!v12 && !v13) - v12;
v16 = 0;
v17 = v15 == 0;
if ( !v15 )
{
LABEL_37:
if ( !(unsigned __int8)pad_ping(v9, v8) )
goto LABEL_47;
goto LABEL_38;
}
v18 = v49;
v19 = "state";
v20 = 6LL;
do
{
if ( !v20 )
break;
v16 = (unsigned __int8)*v18 < (unsigned int)*v19;
v17 = *v18++ == *v19++;
--v20;
}
while ( v17 );
if ( (!v16 && !v17) == v16 )
{
v46 = pad_state(v19, v18);
if ( v46 != 0xFF )
{
print_hb(0LL, v46);
print_nl();
return 1LL;
}
LABEL_47:
print_err_nl();
return 1LL;
}
v21 = strcmp(v49, "led") != 0;
v22 = 0;
v23 = !v21;
if ( !v21 )
{
pad_led();
return 1LL;
}
v24 = v49;
v25 = "rled";
v26 = 5LL;
do
{
if ( !v26 )
break;
v22 = (unsigned __int8)*v24 < (unsigned int)*v25;
v23 = *v24++ == *v25++;
--v26;
}
while ( v23 );
v27 = (!v22 && !v23) - v22;
v28 = 0;
v29 = v27 == 0;
if ( !v27 )
{
pad_remote_led(v25, v24);
return 1LL;
}
v30 = v49;
v31 = "read";
v32 = 5LL;
do
{
if ( !v32 )
break;
v28 = (unsigned __int8)*v30 < (unsigned int)*v31;
v29 = *v30++ == *v31++;
--v32;
}
while ( v29 );
v33 = (!v28 && !v29) - v28;
v34 = 0;
v35 = v33 == 0;
if ( !v33 )
{
v47 = (unsigned __int8)pad_read(v31, v30);
print_hb(0LL, v47);
print_nl();
return 1LL;
}
v36 = v49;
v37 = "write";
v38 = 6LL;
do
{
if ( !v38 )
break;
v34 = (unsigned __int8)*v36 < (unsigned int)*v37;
v35 = *v36++ == *v37++;
--v38;
}
while ( v35 );
v39 = (!v34 && !v35) - v34;
v40 = 0;
v41 = v39 == 0;
if ( !v39 )
{
v48 = scan_uint8(v37, v36);
if ( !(unsigned __int8)pad_write(v48) )
goto LABEL_47;
LABEL_38:
print_ok_nl();
return 1LL;
}
v42 = v49;
v43 = "autoread";
v44 = 9LL;
do
{
if ( !v44 )
break;
v40 = (unsigned __int8)*v42 < (unsigned int)*v43;
v41 = *v42++ == *v43++;
--v44;
}
while ( v41 );
if ( (!v40 && !v41) == v40 )
pad_autoread(v43, v42);
return 1LL;
}

canonical_decompiled_code:
__int64 func25()
{
bool v0; // cf
bool v1; // zf
const char *v2; // rdi
__int64 v3; // rcx
char *v4; // rsi
char v5; // al
bool v6; // cf
bool v7; // zf
char *v8; // rsi
const char *v9; // rdi
__int64 v10; // rcx
char v11; // al
bool v12; // cf
bool v13; // zf
__int64 v14; // rcx
char v15; // al
bool v16; // cf
bool v17; // zf
char *v18; // rsi
const char *v19; // rdi
__int64 v20; // rcx
bool v21; // al
bool v22; // cf
bool v23; // zf
char *v24; // rsi
const char *v25; // rdi
__int64 v26; // rcx
char v27; // al
bool v28; // cf
bool v29; // zf
char *v30; // rsi
const char *v31; // rdi
__int64 v32; // rcx
char v33; // al
bool v34; // cf
bool v35; // zf
char *v36; // rsi
const char *v37; // rdi
__int64 v38; // rcx
char v39; // al
bool v40; // cf
bool v41; // zf
char *v42; // rsi
const char *v43; // rdi
__int64 v44; // rcx
unsigned __int8 v46; // al
__int64 v47; // rsi
char v48; // al
char v49[40]; // [rsp+0h] [rbp-28h] BYREF

scan_key(v49, 17LL);
v2 = "init";
v3 = 5LL;
v4 = v49;
do
{
if ( !v3 )
break;
v0 = (unsigned __int8)*v4 < (unsigned int)*v2;
v1 = *v4++ == *v2++;
--v3;
}
while ( v1 );
v5 = (!v0 && !v1) - v0;
v6 = 0;
v7 = v5 == 0;
if ( !v5 )
{
func23(v2, v4);
return 1LL;
}
v8 = v49;
v9 = "test";
v10 = 5LL;
do
{
if ( !v10 )
break;
v6 = (unsigned __int8)*v8 < (unsigned int)*v9;
v7 = *v8++ == *v9++;
--v10;
}
while ( v7 );
v11 = (!v6 && !v7) - v6;
v12 = 0;
v13 = v11 == 0;
if ( !v11 )
goto LABEL_37;
v8 = v49;
v9 = "ping";
v14 = 5LL;
do
{
if ( !v14 )
break;
v12 = (unsigned __int8)*v8 < (unsigned int)*v9;
v13 = *v8++ == *v9++;
--v14;
}
while ( v13 );
v15 = (!v12 && !v13) - v12;
v16 = 0;
v17 = v15 == 0;
if ( !v15 )
{
LABEL_37:
if ( !(unsigned __int8)func16(v9, v8) )
goto LABEL_47;
goto LABEL_38;
}
v18 = v49;
v19 = "state";
v20 = 6LL;
do
{
if ( !v20 )
break;
v16 = (unsigned __int8)*v18 < (unsigned int)*v19;
v17 = *v18++ == *v19++;
--v20;
}
while ( v17 );
if ( (!v16 && !v17) == v16 )
{
v46 = func19(v19, v18);
if ( v46 != 0xFF )
{
print_hb(0LL, v46);
print_nl();
return 1LL;
}
LABEL_47:
print_err_nl();
return 1LL;
}
v21 = strcmp(v49, "led") != 0;
v22 = 0;
v23 = !v21;
if ( !v21 )
{
func15();
return 1LL;
}
v24 = v49;
v25 = "rled";
v26 = 5LL;
do
{
if ( !v26 )
break;
v22 = (unsigned __int8)*v24 < (unsigned int)*v25;
v23 = *v24++ == *v25++;
--v26;
}
while ( v23 );
v27 = (!v22 && !v23) - v22;
v28 = 0;
v29 = v27 == 0;
if ( !v27 )
{
func22(v25, v24);
return 1LL;
}
v30 = v49;
v31 = "read";
v32 = 5LL;
do
{
if ( !v32 )
break;
v28 = (unsigned __int8)*v30 < (unsigned int)*v31;
v29 = *v30++ == *v31++;
--v32;
}
while ( v29 );
v33 = (!v28 && !v29) - v28;
v34 = 0;
v35 = v33 == 0;
if ( !v33 )
{
v47 = (unsigned __int8)func18(v31, v30);
print_hb(0LL, v47);
print_nl();
return 1LL;
}
v36 = v49;
v37 = "write";
v38 = 6LL;
do
{
if ( !v38 )
break;
v34 = (unsigned __int8)*v36 < (unsigned int)*v37;
v35 = *v36++ == *v37++;
--v38;
}
while ( v35 );
v39 = (!v34 && !v35) - v34;
v40 = 0;
v41 = v39 == 0;
if ( !v39 )
{
v48 = scan_uint8(v37, v36);
if ( !(unsigned __int8)func17(v48) )
goto LABEL_47;
LABEL_38:
print_ok_nl();
return 1LL;
}
v42 = v49;
v43 = "autoread";
v44 = 9LL;
do
{
if ( !v44 )
break;
v40 = (unsigned __int8)*v42 < (unsigned int)*v43;
v41 = *v42++ == *v43++;
--v44;
}
while ( v41 );
if ( (!v40 && !v41) == v40 )
func24(v43, v42);
return 1LL;
}

original_code:
uint8_t pad_do_prompt() {
        char cmd[17];
        scan_key(cmd,17);
        if (strcmp(cmd,"init")==0) {
            pad_init();
            return 1;
        }
        if ((strcmp(cmd,"test")==0) || (strcmp(cmd,"ping")==0)) {
            if (pad_ping()) {
                print_ok_nl();
            } else {
                print_err_nl();
            }
            return 1;
        }
        if (strcmp(cmd,"state")==0) {
            uint8_t d = pad_state();
            if (d == 0xff) {
                print_err_nl();
            } else {
          print_hb(0,d);
                print_nl();
            }
            return 1;
        }
        if (strcmp(cmd,"led")==0) {
            pad_led();
            return 1;
        }
        if (strcmp(cmd,"rled")==0) {
            pad_remote_led();
            return 1;
        }
        if (strcmp(cmd,"read")==0) {
            uint8_t d = pad_read();
      print_hb(0,d);
            print_nl();
            return 1;
        }
        if (strcmp(cmd,"write")==0) {
      uint8_t v0 = scan_uint8();
            if (pad_write(v0)) {
                print_ok_nl();
            } else {
                print_err_nl();
            }
            return 1;
        }
        if (strcmp(cmd,"autoread")==0) {
            pad_autoread();
            return 1;
        }
        return 1;
}

canonical_original_code:
unsigned char pad_do_prompt() {
        char cmd[17];
        scan_key(cmd,17);
        if (strcmp(cmd,"init")==0) {
            pad_init();
            return 1;
        }
        if ((strcmp(cmd,"test")==0) || (strcmp(cmd,"ping")==0)) {
            if (pad_ping()) {
                print_ok_nl();
            } else {
                print_err_nl();
            }
            return 1;
        }
        if (strcmp(cmd,"state")==0) {
            unsigned char d = pad_state();
            if (d == 0xff) {
                print_err_nl();
            } else {
          print_hb(0,d);
                print_nl();
            }
            return 1;
        }
        if (strcmp(cmd,"led")==0) {
            pad_led();
            return 1;
        }
        if (strcmp(cmd,"rled")==0) {
            pad_remote_led();
            return 1;
        }
        if (strcmp(cmd,"read")==0) {
            unsigned char d = pad_read();
      print_hb(0,d);
            print_nl();
            return 1;
        }
        if (strcmp(cmd,"write")==0) {
      unsigned char v0 = scan_uint8();
            if (pad_write(v0)) {
                print_ok_nl();
            } else {
                print_err_nl();
            }
            return 1;
        }
        if (strcmp(cmd,"autoread")==0) {
            pad_autoread();
            return 1;
        }
        return 1;
}


decompiled_code:
__int64 scan_get_last_error()
{
return 0LL;
}

canonical_decompiled_code:
__int64 func0()
{
return 0LL;
}

original_code:
uint8_t scan_get_last_error() {
 return last_error;
}

canonical_original_code:
unsigned char scan_get_last_error() {
 return last_error;
}


decompiled_code:
int scan_gc()
{
int result; // eax

result = fgetc(stdin);
last_char = result;
return result;
}

canonical_decompiled_code:
int func1()
{
int result; // eax

result = fgetc(stdin);
last_char = result;
return result;
}

original_code:
uint8_t scan_gc() {
 last_char = fgetc(stdin);
 return last_char;
}

canonical_original_code:
unsigned char scan_gc() {
 last_char = fgetc(stdin);
 return last_char;
}


decompiled_code:
int scan_ungc()
{
return ungetc((unsigned __int8)last_char, stdin);
}

canonical_decompiled_code:
int func2()
{
return ungetc((unsigned __int8)last_char, stdin);
}

original_code:
void scan_ungc() {
 ungetc(last_char,stdin);
}


decompiled_code:
__int64 __fastcall scan_key(unsigned __int8 *a1, int a2)
{
unsigned __int8 v3; // bl
const unsigned __int16 **v4; // rbp
unsigned int v5; // er14
unsigned int v6; // er13

do
{
v3 = scan_gc();
v4 = _ctype_b_loc();
}
while ( ((*v4)[v3] & 0x2000) != 0 );
v5 = a2 - 1;
v6 = 0;
while ( (_BYTE)v6 != (_BYTE)v5 )
{
++v6;
*a1++ = v3;
v3 = scan_gc();
if ( ((*v4)[v3] & 0x2000) != 0 )
{
scan_ungc();
v5 = v6;
break;
}
}
*a1 = 0;
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func3(unsigned __int8 *a1, int a2)
{
unsigned __int8 v3; // bl
const unsigned __int16 **v4; // rbp
unsigned int v5; // er14
unsigned int v6; // er13

do
{
v3 = func1();
v4 = _ctype_b_loc();
}
while ( ((*v4)[v3] & 0x2000) != 0 );
v5 = a2 - 1;
v6 = 0;
while ( (_BYTE)v6 != (_BYTE)v5 )
{
++v6;
*a1++ = v3;
v3 = func1();
if ( ((*v4)[v3] & 0x2000) != 0 )
{
func2();
v5 = v6;
break;
}
}
*a1 = 0;
return v5;
}

original_code:
uint8_t scan_key(char *str, uint8_t max_len) {
 uint8_t c;
 uint8_t r = 0;
 do {
  c = scan_gc();
 } while(((*__ctype_b_loc ())[(int) ((c))] & (unsigned short int) _ISspace));
 while(--max_len) {
  r++;
  *str = c;
  str++;
  c = scan_gc();
  if (((*__ctype_b_loc ())[(int) ((c))] & (unsigned short int) _ISspace)) {
   scan_ungc();
   break;
  }
 }
 *str = 0;
 return r;
}

canonical_original_code:
unsigned char scan_key(char *str, unsigned char max_len) {
 unsigned char c;
 unsigned char r = 0;
 do {
  c = scan_gc();
 } while(((*__ctype_b_loc ())[(int) ((c))] & (unsigned short) _ISspace));
 while(--max_len) {
  r++;
  *str = c;
  str++;
  c = scan_gc();
  if (((*__ctype_b_loc ())[(int) ((c))] & (unsigned short) _ISspace)) {
   scan_ungc();
   break;
  }
 }
 *str = 0;
 return r;
}

variable_types:
str
char *

variable_types:
c
unsigned char

variable_types:
r
unsigned char


decompiled_code:
__int64 __fastcall is_hexdigit(int a1)
{
__int64 result; // rax
unsigned __int8 v2; // al
unsigned int v3; // edi
bool v4; // cf

result = (unsigned int)(a1 - 48);
if ( (unsigned __int8)(a1 - 48) > 9u )
{
if ( (unsigned __int8)(a1 - 97) <= 5u )
{
result = (unsigned int)(a1 - 87);
}
else
{
v2 = a1 - 65;
v3 = a1 - 55;
v4 = v2 < 6u;
result = 0xFFFFFFFFLL;
if ( v4 )
result = v3;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(int a1)
{
__int64 result; // rax
unsigned __int8 v2; // al
unsigned int v3; // edi
bool v4; // cf

result = (unsigned int)(a1 - 48);
if ( (unsigned __int8)(a1 - 48) > 9u )
{
if ( (unsigned __int8)(a1 - 97) <= 5u )
{
result = (unsigned int)(a1 - 87);
}
else
{
v2 = a1 - 65;
v3 = a1 - 55;
v4 = v2 < 6u;
result = 0xFFFFFFFFLL;
if ( v4 )
result = v3;
}
}
return result;
}


decompiled_code:
__int64 scan_uint8()
{
int v0; // ebx
const unsigned __int16 **v1; // r12
unsigned __int16 v2; // ax
unsigned int v3; // ebp
unsigned __int8 i; // al
int v6; // eax

do
{
v0 = scan_gc();
v1 = _ctype_b_loc();
v2 = (*v1)[(unsigned __int8)v0];
}
while ( (v2 & 0x2000) != 0 );
if ( (v2 & 0x800) != 0 )
{
v3 = 0;
do
{
v3 = v0 + 10 * v3 - 48;
v0 = scan_gc();
}
while ( ((*v1)[(unsigned __int8)v0] & 0x800) != 0 );
}
else
{
v3 = 0;
}
if ( (_BYTE)v0 == 120 && !(_BYTE)v3 )
{
for ( i = scan_gc(); ; i = scan_gc() )
{
v6 = is_hexdigit(i);
if ( (_BYTE)v6 == 0xFF )
break;
v3 = v6 + 16 * v3;
}
}
scan_ungc();
return v3;
}

original_code:
uint8_t scan_uint8() {
 uint8_t c;
 uint8_t r = 0;
 do {
  c = scan_gc();
 } while(((*__ctype_b_loc ())[(int) ((c))] & (unsigned short int) _ISspace));
 while(((*__ctype_b_loc ())[(int) ((c))] & (unsigned short int) _ISdigit)) {
  r = r*10+(c - '0');
  c = scan_gc();
 }
 if ((c=='x') && (r == 0)) {
  c = scan_gc();
  while( (c=is_hexdigit(c))!=255 ) {
   r = r*16+c;
   c = scan_gc();
  }
 }
 scan_ungc();
 return r;
}

canonical_original_code:
unsigned char scan_uint8() {
 unsigned char c;
 unsigned char r = 0;
 do {
  c = scan_gc();
 } while(((*__ctype_b_loc ())[(int) ((c))] & (unsigned short) _ISspace));
 while(((*__ctype_b_loc ())[(int) ((c))] & (unsigned short) _ISdigit)) {
  r = r*10+(c - '0');
  c = scan_gc();
 }
 if ((c=='x') && (r == 0)) {
  c = scan_gc();
  while( (c=is_hexdigit(c))!=255 ) {
   r = r*16+c;
   c = scan_gc();
  }
 }
 scan_ungc();
 return r;
}


decompiled_code:
__int64 scan_uint16()
{
unsigned __int8 v0; // bl
const unsigned __int16 **v1; // r12
unsigned int v2; // ebp
unsigned int v3; // er13
unsigned __int8 v5; // al
unsigned __int8 v6; // al

do
{
v0 = scan_gc();
v1 = _ctype_b_loc();
v2 = (*v1)[v0];
v3 = v2 & 0xFFFF2000;
}
while ( (v2 & 0x2000) != 0 );
LOWORD(v2) = v2 & 0x800;
if ( (_WORD)v2 )
{
v2 = v3;
do
{
v2 = v0 + 10 * v2 - 48;
v0 = scan_gc();
}
while ( ((*v1)[v0] & 0x800) != 0 );
}
if ( v0 == 120 && !(_WORD)v2 )
{
v5 = scan_gc();
v2 = v3;
while ( 1 )
{
v6 = is_hexdigit(v5);
if ( v6 == 0xFF )
break;
v2 = v6 + 16 * v2;
v5 = scan_gc();
}
}
scan_ungc();
return v2;
}

original_code:
uint16_t scan_uint16() {
 uint8_t c;
 uint16_t r = 0;
 do {
  c = scan_gc();
 } while(((*__ctype_b_loc ())[(int) ((c))] & (unsigned short int) _ISspace));
 while(((*__ctype_b_loc ())[(int) ((c))] & (unsigned short int) _ISdigit)) {
  r = r*10+(c - '0');
  c = scan_gc();
 }
 if ((c=='x') && (r == 0)) {
  c = scan_gc();
  while( (c=is_hexdigit(c))!=255 ) {
   r = r*16+c;
   c = scan_gc();
  }
 }
 scan_ungc();
 return r;
}

canonical_original_code:
unsigned short scan_uint16() {
 unsigned char c;
 unsigned short r = 0;
 do {
  c = scan_gc();
 } while(((*__ctype_b_loc ())[(int) ((c))] & (unsigned short) _ISspace));
 while(((*__ctype_b_loc ())[(int) ((c))] & (unsigned short) _ISdigit)) {
  r = r*10+(c - '0');
  c = scan_gc();
 }
 if ((c=='x') && (r == 0)) {
  c = scan_gc();
  while( (c=is_hexdigit(c))!=255 ) {
   r = r*16+c;
   c = scan_gc();
  }
 }
 scan_ungc();
 return r;
}


decompiled_code:
__int64 scan_test()
{
unsigned __int8 v0; // al
unsigned __int8 v1; // al
unsigned __int16 v2; // ax
unsigned __int16 v3; // ax

print("scan test, type 123: ");
v0 = scan_uint8();
print_db("value = ", v0);
print_nl();
print("type 0xff: ");
v1 = scan_uint8();
print_hb("value = ", v1);
print_nl();
print("type 12345: ");
v2 = scan_uint16();
print_dw("value = ", v2);
print_nl();
print("type 0x55AA: ");
v3 = scan_uint16();
print_hw("value = ", v3);
print_nl();
return print("ok, end of scan test\r\n");
}

canonical_decompiled_code:
__int64 func7()
{
unsigned __int8 v0; // al
unsigned __int8 v1; // al
unsigned __int16 v2; // ax
unsigned __int16 v3; // ax

print("scan test, type 123: ");
v0 = func5();
print_db("value = ", v0);
print_nl();
print("type 0xff: ");
v1 = func5();
print_hb("value = ", v1);
print_nl();
print("type 12345: ");
v2 = func6();
print_dw("value = ", v2);
print_nl();
print("type 0x55AA: ");
v3 = func6();
print_hw("value = ", v3);
print_nl();
return print("ok, end of scan test\r\n");
}

original_code:
void scan_test() {
 print("scan test, type 123: ");
 uint8_t v0 = scan_uint8();
 print_db("value = ", v0);
 print_nl();
 print("type 0xff: ");
 v0 = scan_uint8();
 print_hb("value = ", v0);
 print_nl();
 print("type 12345: ");
 uint16_t v1 = scan_uint16();
 print_dw("value = ", v1);
 print_nl();
 print("type 0x55AA: ");
 v1 = scan_uint16();
 print_hw("value = ", v1);
 print_nl();
 print("ok, end of scan test\r\n");
}

canonical_original_code:
void scan_test() {
 print("scan test, type 123: ");
 unsigned char v0 = scan_uint8();
 print_db("value = ", v0);
 print_nl();
 print("type 0xff: ");
 v0 = scan_uint8();
 print_hb("value = ", v0);
 print_nl();
 print("type 12345: ");
 unsigned short v1 = scan_uint16();
 print_dw("value = ", v1);
 print_nl();
 print("type 0x55AA: ");
 v1 = scan_uint16();
 print_hw("value = ", v1);
 print_nl();
 print("ok, end of scan test\r\n");
}


decompiled_code:
__int64 client_init()
{
unsigned __int8 v0; // al

dbg_mode = 1;
cfg_client_id = eerd_b(21LL);
cfg_slot_rest_delay = eerd_b(24LL);
cfg_slot_rf_timeout = eerd_b(25LL);
DDRC &= 0xC0u;
v0 = eerd_b(22LL);
cc_slot_set_len(v0);
cc_slot_set_top(18LL);
return cc_slot_set(0LL);
}

canonical_decompiled_code:
__int64 func0()
{
unsigned __int8 v0; // al

dbg_mode = 1;
cfg_client_id = eerd_b(21LL);
cfg_slot_rest_delay = eerd_b(24LL);
cfg_slot_rf_timeout = eerd_b(25LL);
DDRC &= 0xC0u;
v0 = eerd_b(22LL);
cc_slot_set_len(v0);
cc_slot_set_top(18LL);
return cc_slot_set(0LL);
}

original_code:
void client_init() {
 dbg_mode = 1;
 cfg_client_id = eerd_b(21);
 cfg_slot_rest_delay = eerd_b(24);
 cfg_slot_rf_timeout = eerd_b(25);
 DDRC &=~0x3f;
 cc_slot_set_len(eerd_b(22));
 cc_slot_set_top((2u+16u +1u)-1);
        cc_slot_set(0);
}


decompiled_code:
__int64 client_read_pad()
{
return PINC & 0x3F;
}

canonical_decompiled_code:
__int64 func1()
{
return PINC & 0x3F;
}

original_code:
uint8_t client_read_pad() {
 return PINC &0x3f;
}

canonical_original_code:
unsigned char client_read_pad() {
 return PINC &0x3f;
}


decompiled_code:
__int64 client_loop()
{
__int64 result; // rax
char v1; // bl
int v2; // eax
char v3; // bl
unsigned __int8 v4; // al
unsigned __int8 v5; // si
int v6; // eax

rf_prepare_for_recv();
if ( connected_2 )
{
if ( dbg_mode )
print_char(91LL);
cc_slot_wait(0LL);
result = rf_recv_packet((unsigned __int8)cfg_slot_rf_timeout);
v3 = result;
if ( dbg_mode )
result = print_char((unsigned __int8)(result + 48));
if ( v3 == 1 )
{
result = rf_get_packet_v0();
if ( (_BYTE)result )
{
if ( !dbg_mode )
return result;
goto LABEL_38;
}
if ( dbg_mode )
print_char(115LL);
connected_2 = 1;
rf_get_packet_v1();
connected_2 = 1;
v6 = (unsigned __int8)cfg_slot_rest_delay;
do
--v6;
while ( (_BYTE)v6 != 0xFF );
result = cc_slot_set(1LL);
}
else
{
connected_2 = 0;
if ( !dbg_mode )
return result;
result = print_char(100LL);
}
if ( !connected_2 )
return result;
goto LABEL_24;
}
if ( dbg_mode )
print_char(63LL);
result = rf_recv_packet((unsigned __int16)(19 * (unsigned __int8)cfg_slot_rf_timeout));
v1 = result;
if ( dbg_mode )
result = print_char((unsigned __int8)(result + 48));
if ( v1 == 1 )
{
result = rf_get_packet_v0();
if ( !(_BYTE)result )
{
if ( dbg_mode )
print_char(115LL);
connected_2 = 1;
rf_get_packet_v1();
connected_2 = 1;
v2 = (unsigned __int8)cfg_slot_rest_delay;
do
--v2;
while ( (_BYTE)v2 != 0xFF );
cc_slot_set(1LL);
LABEL_24:
if ( dbg_mode )
print_char(58LL);
rf_prepare_for_send();
cc_slot_wait((unsigned __int8)(cfg_client_id + 2));
v4 = client_read_pad();
v5 = client_seq_0++;
rf_send_packet((unsigned __int8)(cfg_client_id + 0x80), v5, v4, (unsigned __int8)~v4);
if ( (unsigned __int8)cc_slot_get() != (unsigned __int8)cfg_client_id + 2 && dbg_mode )
print_char(94LL);
result = cc_slot_wait(18LL);
if ( dbg_mode )
result = print_char(93LL);
return result;
}
if ( !dbg_mode )
return result;
LABEL_38:
result = print_char(110LL);
}
return result;
}

canonical_decompiled_code:
__int64 func2()
{
__int64 result; // rax
char v1; // bl
int v2; // eax
char v3; // bl
unsigned __int8 v4; // al
unsigned __int8 v5; // si
int v6; // eax

rf_prepare_for_recv();
if ( connected_2 )
{
if ( dbg_mode )
print_char(91LL);
cc_slot_wait(0LL);
result = rf_recv_packet((unsigned __int8)cfg_slot_rf_timeout);
v3 = result;
if ( dbg_mode )
result = print_char((unsigned __int8)(result + 48));
if ( v3 == 1 )
{
result = rf_get_packet_v0();
if ( (_BYTE)result )
{
if ( !dbg_mode )
return result;
goto LABEL_38;
}
if ( dbg_mode )
print_char(115LL);
connected_2 = 1;
rf_get_packet_v1();
connected_2 = 1;
v6 = (unsigned __int8)cfg_slot_rest_delay;
do
--v6;
while ( (_BYTE)v6 != 0xFF );
result = cc_slot_set(1LL);
}
else
{
connected_2 = 0;
if ( !dbg_mode )
return result;
result = print_char(100LL);
}
if ( !connected_2 )
return result;
goto LABEL_24;
}
if ( dbg_mode )
print_char(63LL);
result = rf_recv_packet((unsigned __int16)(19 * (unsigned __int8)cfg_slot_rf_timeout));
v1 = result;
if ( dbg_mode )
result = print_char((unsigned __int8)(result + 48));
if ( v1 == 1 )
{
result = rf_get_packet_v0();
if ( !(_BYTE)result )
{
if ( dbg_mode )
print_char(115LL);
connected_2 = 1;
rf_get_packet_v1();
connected_2 = 1;
v2 = (unsigned __int8)cfg_slot_rest_delay;
do
--v2;
while ( (_BYTE)v2 != 0xFF );
cc_slot_set(1LL);
LABEL_24:
if ( dbg_mode )
print_char(58LL);
rf_prepare_for_send();
cc_slot_wait((unsigned __int8)(cfg_client_id + 2));
v4 = func1();
v5 = client_seq_0++;
rf_send_packet((unsigned __int8)(cfg_client_id + 0x80), v5, v4, (unsigned __int8)~v4);
if ( (unsigned __int8)cc_slot_get() != (unsigned __int8)cfg_client_id + 2 && dbg_mode )
print_char(94LL);
result = cc_slot_wait(18LL);
if ( dbg_mode )
result = print_char(93LL);
return result;
}
if ( !dbg_mode )
return result;
LABEL_38:
result = print_char(110LL);
}
return result;
}

original_code:
void client_loop() {
 static uint8_t connected = 0;
 static uint8_t last_seq = 0;
 static uint8_t client_seq = 0;
 rf_prepare_for_recv();
 if (!connected) {
  if (dbg_mode) { print_char('?');};
  uint8_t rc = rf_recv_packet((2u+16u +1u)*cfg_slot_rf_timeout);
  if (dbg_mode) { print_char('0'+rc);};
  if (rc == 1) {
   if (rf_get_packet_v0()!=0) {
    if (dbg_mode) { print_char('n');};
    return;
   }
   if (dbg_mode) { print_char('s');};
   connected = 1;
   last_seq = rf_get_packet_v1();
   connected = 1;
   uint8_t srd = cfg_slot_rest_delay;
   while(srd--) {
   ;
   }
   cc_slot_set(1);
  } else {
   return;
  }
 } else {
  if (dbg_mode) { print_char('[');};
  cc_slot_wait(0);
  uint8_t rc = rf_recv_packet(cfg_slot_rf_timeout);
  if (dbg_mode) { print_char('0'+rc);};
  if (rc == 1) {
   if (rf_get_packet_v0()!=0) {
    if (dbg_mode) { print_char('n');};
    return;
   }
   if (dbg_mode) { print_char('s');};
   connected = 1;
   last_seq = rf_get_packet_v1();
   connected = 1;
   uint8_t srd = cfg_slot_rest_delay;
   while(srd--) {
   ;
   }
   cc_slot_set(1);
  } else {
   connected = 0;
   if (dbg_mode) { print_char('d');};
  }
  if (!connected) return;
 }
 if (dbg_mode) { print_char(':');};
 rf_prepare_for_send();
 cc_slot_wait(2u +cfg_client_id);
 uint8_t client_data0 = client_read_pad();
 uint8_t client_data1 = ~client_data0;
 rf_send_packet(0x80+cfg_client_id,client_seq++, client_data0, client_data1);
 if (cc_slot_get()!=(2u +cfg_client_id)) {
  if (dbg_mode) { print_char('^');};
 }
 cc_slot_wait(2u +16u);
 if (dbg_mode) { print_char(']');};
}

canonical_original_code:
void client_loop() {
 static unsigned char connected = 0;
 static unsigned char last_seq = 0;
 static unsigned char client_seq = 0;
 rf_prepare_for_recv();
 if (!connected) {
  if (dbg_mode) { print_char('?');};
  unsigned char rc = rf_recv_packet((2u+16u +1u)*cfg_slot_rf_timeout);
  if (dbg_mode) { print_char('0'+rc);};
  if (rc == 1) {
   if (rf_get_packet_v0()!=0) {
    if (dbg_mode) { print_char('n');};
    return;
   }
   if (dbg_mode) { print_char('s');};
   connected = 1;
   last_seq = rf_get_packet_v1();
   connected = 1;
   unsigned char srd = cfg_slot_rest_delay;
   while(srd--) {
   ;
   }
   cc_slot_set(1);
  } else {
   return;
  }
 } else {
  if (dbg_mode) { print_char('[');};
  cc_slot_wait(0);
  unsigned char rc = rf_recv_packet(cfg_slot_rf_timeout);
  if (dbg_mode) { print_char('0'+rc);};
  if (rc == 1) {
   if (rf_get_packet_v0()!=0) {
    if (dbg_mode) { print_char('n');};
    return;
   }
   if (dbg_mode) { print_char('s');};
   connected = 1;
   last_seq = rf_get_packet_v1();
   connected = 1;
   unsigned char srd = cfg_slot_rest_delay;
   while(srd--) {
   ;
   }
   cc_slot_set(1);
  } else {
   connected = 0;
   if (dbg_mode) { print_char('d');};
  }
  if (!connected) return;
 }
 if (dbg_mode) { print_char(':');};
 rf_prepare_for_send();
 cc_slot_wait(2u +cfg_client_id);
 unsigned char client_data0 = client_read_pad();
 unsigned char client_data1 = ~client_data0;
 rf_send_packet(0x80+cfg_client_id,client_seq++, client_data0, client_data1);
 if (cc_slot_get()!=(2u +cfg_client_id)) {
  if (dbg_mode) { print_char('^');};
 }
 cc_slot_wait(2u +16u);
 if (dbg_mode) { print_char(']');};
}

variable_types:
connected
unsigned char

variable_types:
rc
unsigned char

variable_types:
srd
unsigned char


decompiled_code:
__int64 __fastcall client_check_for_server(unsigned __int8 a1)
{
char v1; // r12
int v2; // ebp
unsigned int v3; // ebx
char v5; // al

rf_tune_channel(a1);
v1 = 0;
v2 = 0;
while ( 1 )
{
while ( 1 )
{
v3 = rf_recv_packet(30LL);
if ( (_BYTE)v3 != 1 )
return 0;
v5 = rf_get_packet_v2();
if ( (_BYTE)v2 )
break;
++v2;
v1 = v5 + 1;
}
if ( v5 != v1 )
break;
++v2;
v1 = v5 + 1;
if ( (_BYTE)v2 == 100 )
return v3;
}
return 0;
}

canonical_decompiled_code:
__int64 __fastcall func3(unsigned __int8 a1)
{
char v1; // r12
int v2; // ebp
unsigned int v3; // ebx
char v5; // al

rf_tune_channel(a1);
v1 = 0;
v2 = 0;
while ( 1 )
{
while ( 1 )
{
v3 = rf_recv_packet(30LL);
if ( (_BYTE)v3 != 1 )
return 0;
v5 = rf_get_packet_v2();
if ( (_BYTE)v2 )
break;
++v2;
v1 = v5 + 1;
}
if ( v5 != v1 )
break;
++v2;
v1 = v5 + 1;
if ( (_BYTE)v2 == 100 )
return v3;
}
return 0;
}

original_code:
uint8_t client_check_for_server(uint8_t c) {
 rf_tune_channel(c);
 uint8_t it = 100;
 uint8_t ok = 0;
 uint8_t next_seq = 0;
 while(it--) {
  uint8_t rc = rf_recv_packet(30);
  if (rc == 1) {
   uint8_t seq = rf_get_packet_v2();
   if (ok==0) {
    next_seq = seq;
   } else if (next_seq!=seq) {
    return 0;
   }
   ok++;
   next_seq++;
  } else {
   return 0;
  }
 }
 return 1;
}

canonical_original_code:
unsigned char client_check_for_server(unsigned char c) {
 rf_tune_channel(c);
 unsigned char it = 100;
 unsigned char ok = 0;
 unsigned char next_seq = 0;
 while(it--) {
  unsigned char rc = rf_recv_packet(30);
  if (rc == 1) {
   unsigned char seq = rf_get_packet_v2();
   if (ok==0) {
    next_seq = seq;
   } else if (next_seq!=seq) {
    return 0;
   }
   ok++;
   next_seq++;
  } else {
   return 0;
  }
 }
 return 1;
}

variable_types:
it
unsigned char

variable_types:
seq
unsigned char


decompiled_code:
__int64 client_autotune()
{
unsigned __int8 v0; // r12
__int64 v1; // r13
unsigned int v2; // ebx
unsigned __int16 v3; // bp
unsigned __int16 v4; // ax

v0 = rf_cfg_get_channel_count();
print_hw("autotune channels=", v0);
v1 = (unsigned __int8)rf_cfg_get_channel_bw();
print_hb(", bw = ", v1);
print_nl();
rf_scan_start();
if ( v0 )
{
v2 = 0;
do
{
v3 = rf_scan_get_signal_level_at_channel(v2);
print_hb("channel ", v2);
v4 = rf_cfg_get_channel_f0(v2, (unsigned int)v1);
print_hw(", freq ", v4);
print_hw(" - sig_level ", v3);
if ( v3 )
{
rf_scan_stop();
if ( (unsigned __int8)client_check_for_server(v2) )
print(" server detected");
else
print(" no server");
rf_scan_start();
}
print_nl();
++v2;
}
while ( v0 > (unsigned __int8)v2 );
}
return rf_scan_stop();
}

canonical_decompiled_code:
__int64 func4()
{
unsigned __int8 v0; // r12
__int64 v1; // r13
unsigned int v2; // ebx
unsigned __int16 v3; // bp
unsigned __int16 v4; // ax

v0 = rf_cfg_get_channel_count();
print_hw("autotune channels=", v0);
v1 = (unsigned __int8)rf_cfg_get_channel_bw();
print_hb(", bw = ", v1);
print_nl();
rf_scan_start();
if ( v0 )
{
v2 = 0;
do
{
v3 = rf_scan_get_signal_level_at_channel(v2);
print_hb("channel ", v2);
v4 = rf_cfg_get_channel_f0(v2, (unsigned int)v1);
print_hw(", freq ", v4);
print_hw(" - sig_level ", v3);
if ( v3 )
{
rf_scan_stop();
if ( (unsigned __int8)func3(v2) )
print(" server detected");
else
print(" no server");
rf_scan_start();
}
print_nl();
++v2;
}
while ( v0 > (unsigned __int8)v2 );
}
return rf_scan_stop();
}

original_code:
void client_autotune() {
 uint8_t channels = rf_cfg_get_channel_count();
 print_hw("autotune channels=", channels);
 uint8_t bw = rf_cfg_get_channel_bw();
 print_hb(", bw = ", bw);
 print_nl();
 rf_scan_start();
 uint8_t c;
 for(c=0; c<channels; c++) {
  uint16_t v = rf_scan_get_signal_level_at_channel(c);
  print_hb("channel ",c);
  uint16_t f = rf_cfg_get_channel_f0(c, bw);
  print_hw(", freq ",f);
  print_hw(" - sig_level ",v);
  if (v > 0) {
   rf_scan_stop();
   if (client_check_for_server(c)) {
    print(" server detected");
   } else {
    print(" no server");
   }
   rf_scan_start();
  }
  print_nl();
 }
 rf_scan_stop();
}

canonical_original_code:
void client_autotune() {
 unsigned char channels = rf_cfg_get_channel_count();
 print_hw("autotune channels=", channels);
 unsigned char bw = rf_cfg_get_channel_bw();
 print_hb(", bw = ", bw);
 print_nl();
 rf_scan_start();
 unsigned char c;
 for(c=0; c<channels; c++) {
  unsigned short v = rf_scan_get_signal_level_at_channel(c);
  print_hb("channel ",c);
  unsigned short f = rf_cfg_get_channel_f0(c, bw);
  print_hw(", freq ",f);
  print_hw(" - sig_level ",v);
  if (v > 0) {
   rf_scan_stop();
   if (client_check_for_server(c)) {
    print(" server detected");
   } else {
    print(" no server");
   }
   rf_scan_start();
  }
  print_nl();
 }
 rf_scan_stop();
}

variable_types:
channels
unsigned char

variable_types:
bw
unsigned char

variable_types:
v
unsigned short

variable_types:
f
unsigned short


decompiled_code:
__int64 __fastcall client_select_channel(unsigned __int8 a1)
{
char v1; // bp
unsigned __int8 v2; // r12
char v3; // bl
unsigned __int8 v4; // al
unsigned __int8 v5; // al
unsigned __int8 v6; // al
__int64 v7; // rsi

print_hb("setting channel ", a1);
rf_tune_channel(a1);
print_nl();
print("listening for server packet...");
v1 = 10;
v2 = 0;
do
{
v3 = rf_recv_packet(50LL);
print_char((unsigned __int8)(v3 + 48));
v4 = rf_get_packet_v0();
print_hb(" v0:", v4);
v5 = rf_get_packet_v1();
print_hb(" v1:", v5);
v6 = rf_get_packet_v2();
print_hb(" v2:", v6);
v7 = (unsigned __int8)rf_get_packet_v3();
print_hb(" v3:", v7);
print_nl();
v2 += v3 == 1;
--v1;
}
while ( v1 );
print_nl();
print_hb("result = ", v2);
return print_nl();
}

canonical_decompiled_code:
__int64 __fastcall func5(unsigned __int8 a1)
{
char v1; // bp
unsigned __int8 v2; // r12
char v3; // bl
unsigned __int8 v4; // al
unsigned __int8 v5; // al
unsigned __int8 v6; // al
__int64 v7; // rsi

print_hb("setting channel ", a1);
rf_tune_channel(a1);
print_nl();
print("listening for server packet...");
v1 = 10;
v2 = 0;
do
{
v3 = rf_recv_packet(50LL);
print_char((unsigned __int8)(v3 + 48));
v4 = rf_get_packet_v0();
print_hb(" v0:", v4);
v5 = rf_get_packet_v1();
print_hb(" v1:", v5);
v6 = rf_get_packet_v2();
print_hb(" v2:", v6);
v7 = (unsigned __int8)rf_get_packet_v3();
print_hb(" v3:", v7);
print_nl();
v2 += v3 == 1;
--v1;
}
while ( v1 );
print_nl();
print_hb("result = ", v2);
return print_nl();
}

original_code:
void client_select_channel(uint8_t c) {
 print_hb("setting channel ", c);
 rf_tune_channel(c);
 print_nl();
 print("listening for server packet...");
 uint8_t it = 10;
 uint8_t ok = 0;
 while(it--) {
  uint8_t rc = rf_recv_packet(50);
  print_char('0'+rc);
  print_hb(" v0:", rf_get_packet_v0());
  print_hb(" v1:", rf_get_packet_v1());
  print_hb(" v2:", rf_get_packet_v2());
  print_hb(" v3:", rf_get_packet_v3());
  print_nl();
  if (rc == 1) {
   ok++;
  }
 }
 print_nl();
 print_hb("result = ",ok);
 print_nl();
}

canonical_original_code:
void client_select_channel(unsigned char c) {
 print_hb("setting channel ", c);
 rf_tune_channel(c);
 print_nl();
 print("listening for server packet...");
 unsigned char it = 10;
 unsigned char ok = 0;
 while(it--) {
  unsigned char rc = rf_recv_packet(50);
  print_char('0'+rc);
  print_hb(" v0:", rf_get_packet_v0());
  print_hb(" v1:", rf_get_packet_v1());
  print_hb(" v2:", rf_get_packet_v2());
  print_hb(" v3:", rf_get_packet_v3());
  print_nl();
  if (rc == 1) {
   ok++;
  }
 }
 print_nl();
 print_hb("result = ",ok);
 print_nl();
}


decompiled_code:
void __noreturn client_autorun()
{
print("client autorun\n\r");
rf_client_hack();
client_init();
while ( 1 )
client_loop();
}

canonical_decompiled_code:
void __noreturn func6()
{
print("client autorun\n\r");
rf_client_hack();
func0();
while ( 1 )
func2();
}

original_code:
void client_autorun() {
 print("client autorun\n\r");
 rf_client_hack();
 client_init();
 while(!0) {
         client_loop();
        }
}


original_code:
uint8_t client_do_prompt() {
        char cmd[17];
        scan_key(cmd,17);
        if (strcmp(cmd,"init")==0) {
                        client_init();
   print_ok_nl();
                        return 1;
        }
        if (strcmp(cmd,"loop")==0) {
                        uint16_t count = scan_uint16();
                        if (count == 0) {
                                print("client loop....");
                                while(!0) {
                                        client_loop();
                                }
                                print("   end\n\r");
                        } else {
                                while(count--) {
                                        print_char('.');
                                        client_loop();
                                }
                        }
                        return 1;
        }
 if (strcmp(cmd,"autotune")==0) {
   client_autotune();
   return 1;
 }
 if (strcmp(cmd,"channel")==0) {
   uint8_t c = scan_uint8();
   client_select_channel(c);
   return 1;
 }
 if (strcmp(cmd,"check")==0) {
   uint8_t c = scan_uint8();
   if (client_check_for_server(c)) {
    print("ok\r\n");
   } else {
    print("fail\r\n");
   }
   return 1;
 }
 if (strcmp(cmd,"pad")==0) {
  uint8_t l = client_read_pad();
  print_hb(0,l);
  while(!0) {
   uint8_t d = client_read_pad();
   if (d!=l) {
    l = d;
    print_hb(" ", d);
   }
  }
  return 1;
 }
 if (strcmp(cmd,"reset_stats")==0) {
  stats_ok = 0;
  stats_inv_seq = 0;
  stats_bad_crc = 0;
  stats_timeout = 0;
  print("stat reset ok");
  return 1;
 }
 if (strcmp(cmd,"stats")==0) {
  print_dw("ok: ", stats_ok);
  print_dw(" inv_seq: ", stats_inv_seq);
  print_dw(" bad_crc: ", stats_bad_crc);
  print_dw(" timeout: ", stats_timeout);
  print_nl();
  return 1;
 }
        return 1;
}

canonical_original_code:
unsigned char client_do_prompt() {
        char cmd[17];
        scan_key(cmd,17);
        if (strcmp(cmd,"init")==0) {
                        client_init();
   print_ok_nl();
                        return 1;
        }
        if (strcmp(cmd,"loop")==0) {
                        unsigned short count = scan_uint16();
                        if (count == 0) {
                                print("client loop....");
                                while(!0) {
                                        client_loop();
                                }
                                print("   end\n\r");
                        } else {
                                while(count--) {
                                        print_char('.');
                                        client_loop();
                                }
                        }
                        return 1;
        }
 if (strcmp(cmd,"autotune")==0) {
   client_autotune();
   return 1;
 }
 if (strcmp(cmd,"channel")==0) {
   unsigned char c = scan_uint8();
   client_select_channel(c);
   return 1;
 }
 if (strcmp(cmd,"check")==0) {
   unsigned char c = scan_uint8();
   if (client_check_for_server(c)) {
    print("ok\r\n");
   } else {
    print("fail\r\n");
   }
   return 1;
 }
 if (strcmp(cmd,"pad")==0) {
  unsigned char l = client_read_pad();
  print_hb(0,l);
  while(!0) {
   unsigned char d = client_read_pad();
   if (d!=l) {
    l = d;
    print_hb(" ", d);
   }
  }
  return 1;
 }
 if (strcmp(cmd,"reset_stats")==0) {
  stats_ok = 0;
  stats_inv_seq = 0;
  stats_bad_crc = 0;
  stats_timeout = 0;
  print("stat reset ok");
  return 1;
 }
 if (strcmp(cmd,"stats")==0) {
  print_dw("ok: ", stats_ok);
  print_dw(" inv_seq: ", stats_inv_seq);
  print_dw(" bad_crc: ", stats_bad_crc);
  print_dw(" timeout: ", stats_timeout);
  print_nl();
  return 1;
 }
        return 1;
}

variable_types:
cmd
char [17]

variable_types:
count
unsigned short

variable_types:
l
unsigned char


decompiled_code:
__int64 set_print_info()
{
unsigned __int8 v0; // al
unsigned __int8 v1; // al
unsigned __int8 v2; // al
unsigned __int8 v3; // al
unsigned __int8 v4; // al
unsigned __int8 v5; // al

v0 = eerd_b(20LL);
print_hb("auto mode (0:client, 1:server) = ", v0);
print_nl();
v1 = eerd_b(22LL);
print_hb("slot_size (in ms) = ", v1);
print_nl();
v2 = eerd_b(23LL);
print_hb("slot_count (clients = slots-3) = ", v2);
print_nl();
v3 = eerd_b(24LL);
print_hb("slot_rest_delay (in 50us) = ", v3);
print_nl();
v4 = eerd_b(25LL);
print_hb("slot_rf_timeout (in 20us) = ", v4);
print_nl();
v5 = eerd_b(21LL);
print_hb("client_id = ", v5);
return print_nl();
}

canonical_decompiled_code:
__int64 func0()
{
unsigned __int8 v0; // al
unsigned __int8 v1; // al
unsigned __int8 v2; // al
unsigned __int8 v3; // al
unsigned __int8 v4; // al
unsigned __int8 v5; // al

v0 = eerd_b(20LL);
print_hb("auto mode (0:client, 1:server) = ", v0);
print_nl();
v1 = eerd_b(22LL);
print_hb("slot_size (in ms) = ", v1);
print_nl();
v2 = eerd_b(23LL);
print_hb("slot_count (clients = slots-3) = ", v2);
print_nl();
v3 = eerd_b(24LL);
print_hb("slot_rest_delay (in 50us) = ", v3);
print_nl();
v4 = eerd_b(25LL);
print_hb("slot_rf_timeout (in 20us) = ", v4);
print_nl();
v5 = eerd_b(21LL);
print_hb("client_id = ", v5);
return print_nl();
}

original_code:
void set_print_info() {
 uint8_t mode = eerd_b(20);
 print_hb("auto mode (0:client, 1:server) = ",mode);
 print_nl();
 uint8_t slot_size = eerd_b(22);
 print_hb("slot_size (in ms) = ",slot_size);
 print_nl();
 uint8_t slot_count = eerd_b(23);
 print_hb("slot_count (clients = slots-3) = ",slot_count);
 print_nl();
 uint8_t slot_rest_delay = eerd_b(24);
 print_hb("slot_rest_delay (in 50us) = ",slot_rest_delay);
 print_nl();
 uint8_t slot_rf_timeout = eerd_b(25);
 print_hb("slot_rf_timeout (in 20us) = ",slot_rf_timeout);
 print_nl();
 uint8_t cid = eerd_b(21);
 print_hb("client_id = ",cid);
 print_nl();
}

canonical_original_code:
void set_print_info() {
 unsigned char mode = eerd_b(20);
 print_hb("auto mode (0:client, 1:server) = ",mode);
 print_nl();
 unsigned char slot_size = eerd_b(22);
 print_hb("slot_size (in ms) = ",slot_size);
 print_nl();
 unsigned char slot_count = eerd_b(23);
 print_hb("slot_count (clients = slots-3) = ",slot_count);
 print_nl();
 unsigned char slot_rest_delay = eerd_b(24);
 print_hb("slot_rest_delay (in 50us) = ",slot_rest_delay);
 print_nl();
 unsigned char slot_rf_timeout = eerd_b(25);
 print_hb("slot_rf_timeout (in 20us) = ",slot_rf_timeout);
 print_nl();
 unsigned char cid = eerd_b(21);
 print_hb("client_id = ",cid);
 print_nl();
}

variable_types:
mode
unsigned char

variable_types:
cid
unsigned char