decompiled_code:
_BOOL8 basic_test()
{
unsigned int i; // ebx
__int64 *v1; // rsi
int v2; // ebx
_DWORD *v3; // rdi
int v4; // ebp
_DWORD *v5; // rdi
int v6; // ebp
int v7; // ebx
_DWORD *v8; // rdi
int v9; // ebp
_DWORD *v10; // rdi
int v11; // ebp
_BOOL8 result; // rax
_QWORD *v13; // [rsp+8h] [rbp-30h] BYREF
void *ptr; // [rsp+10h] [rbp-28h] BYREF
__int64 v15[4]; // [rsp+18h] [rbp-20h] BYREF

sll_init(&v13);
if ( !sll_is_empty(&v13) )
__assert_fail("rc != 0", "test-sll.c", 0x2Au, "basic_test");
for ( i = 0; i != 50000; ++i )
{
v1 = (__int64 *)tst_basic_new(i);
if ( !v1 )
__assert_fail("np != NULL", "test-sll.c", 0x2Eu, "basic_test");
sll_insert_head((__int64 *)&v13, v1);
if ( sll_is_empty(&v13) )
__assert_fail("rc == 0", "test-sll.c", 0x33u, "basic_test");
v15[0] = 0LL;
sll_get_mid(&v13, v15);
if ( !v15[0] )
__assert_fail("midp != NULL", "test-sll.c", 0x37u, "basic_test");
if ( *(_DWORD *)(v15[0] + 8) != i >> 1 )
__assert_fail("np->number == (i >> 1)", "test-sll.c", 0x39u, "basic_test");
}
v2 = 10;
do
{
ptr = (void *)sll_next((__int64)&v13);
v3 = ptr;
if ( ptr )
{
v4 = 49999;
do
{
if ( v3[2] != v4 )
__assert_fail("np->number == i", "test-sll.c", 0x42u, "basic_test");
--v4;
ptr = (void *)sll_next((__int64)v3);
v3 = ptr;
}
while ( ptr );
}
sll_reverse(&v13);
ptr = (void *)sll_next((__int64)&v13);
v5 = ptr;
if ( ptr )
{
v6 = 0;
do
{
if ( v5[2] != v6 )
__assert_fail("np->number == i", "test-sll.c", 0x4Du, "basic_test");
++v6;
ptr = (void *)sll_next((__int64)v5);
v5 = ptr;
}
while ( ptr );
}
sll_reverse_recursive(&v13);
--v2;
}
while ( v2 );
v7 = 10;
do
{
ptr = (void *)sll_next((__int64)&v13);
v8 = ptr;
if ( ptr )
{
v9 = 49999;
do
{
if ( v8[2] != v9 )
__assert_fail("np->number == i", "test-sll.c", 0x5Bu, "basic_test");
--v9;
ptr = (void *)sll_next((__int64)v8);
v8 = ptr;
}
while ( ptr );
}
sll_reverse_recursive(&v13);
ptr = (void *)sll_next((__int64)&v13);
v10 = ptr;
if ( ptr )
{
v11 = 0;
do
{
if ( v10[2] != v11 )
__assert_fail("np->number == i", "test-sll.c", 0x66u, "basic_test");
++v11;
ptr = (void *)sll_next((__int64)v10);
v10 = ptr;
}
while ( ptr );
}
sll_reverse(&v13);
--v7;
}
while ( v7 );
for ( result = sll_is_empty(&v13); !result; result = sll_is_empty(&v13) )
{
ptr = 0LL;
sll_delete_head(&v13, &ptr);
if ( !ptr )
__assert_fail("l != NULL", "test-sll.c", 0x71u, "basic_test");
free(ptr);
}
return result;
}

canonical_decompiled_code:
_BOOL8 func12()
{
unsigned int i; // ebx
__int64 *v1; // rsi
int v2; // ebx
_DWORD *v3; // rdi
int v4; // ebp
_DWORD *v5; // rdi
int v6; // ebp
int v7; // ebx
_DWORD *v8; // rdi
int v9; // ebp
_DWORD *v10; // rdi
int v11; // ebp
_BOOL8 result; // rax
_QWORD *v13; // [rsp+8h] [rbp-30h] BYREF
void *ptr; // [rsp+10h] [rbp-28h] BYREF
__int64 v15[4]; // [rsp+18h] [rbp-20h] BYREF

func8(&v13);
if ( !func9(&v13) )
__assert_fail("rc != 0", "test-sll.c", 0x2Au, "basic_test");
for ( i = 0; i != 50000; ++i )
{
v1 = (__int64 *)tst_basic_new(i);
if ( !v1 )
__assert_fail("np != NULL", "test-sll.c", 0x2Eu, "basic_test");
func10((__int64 *)&v13, v1);
if ( func9(&v13) )
__assert_fail("rc == 0", "test-sll.c", 0x33u, "basic_test");
v15[0] = 0LL;
sll_get_mid(&v13, v15);
if ( !v15[0] )
__assert_fail("midp != NULL", "test-sll.c", 0x37u, "basic_test");
if ( *(_DWORD *)(v15[0] + 8) != i >> 1 )
__assert_fail("np->number == (i >> 1)", "test-sll.c", 0x39u, "basic_test");
}
v2 = 10;
do
{
ptr = (void *)func11((__int64)&v13);
v3 = ptr;
if ( ptr )
{
v4 = 49999;
do
{
if ( v3[2] != v4 )
__assert_fail("np->number == i", "test-sll.c", 0x42u, "basic_test");
--v4;
ptr = (void *)func11((__int64)v3);
v3 = ptr;
}
while ( ptr );
}
sll_reverse(&v13);
ptr = (void *)func11((__int64)&v13);
v5 = ptr;
if ( ptr )
{
v6 = 0;
do
{
if ( v5[2] != v6 )
__assert_fail("np->number == i", "test-sll.c", 0x4Du, "basic_test");
++v6;
ptr = (void *)func11((__int64)v5);
v5 = ptr;
}
while ( ptr );
}
func7(&v13);
--v2;
}
while ( v2 );
v7 = 10;
do
{
ptr = (void *)func11((__int64)&v13);
v8 = ptr;
if ( ptr )
{
v9 = 49999;
do
{
if ( v8[2] != v9 )
__assert_fail("np->number == i", "test-sll.c", 0x5Bu, "basic_test");
--v9;
ptr = (void *)func11((__int64)v8);
v8 = ptr;
}
while ( ptr );
}
func7(&v13);
ptr = (void *)func11((__int64)&v13);
v10 = ptr;
if ( ptr )
{
v11 = 0;
do
{
if ( v10[2] != v11 )
__assert_fail("np->number == i", "test-sll.c", 0x66u, "basic_test");
++v11;
ptr = (void *)func11((__int64)v10);
v10 = ptr;
}
while ( ptr );
}
sll_reverse(&v13);
--v7;
}
while ( v7 );
for ( result = func9(&v13); !result; result = func9(&v13) )
{
ptr = 0LL;
sll_delete_head(&v13, &ptr);
if ( !ptr )
__assert_fail("l != NULL", "test-sll.c", 0x71u, "basic_test");
free(ptr);
}
return result;
}

original_code:
static void basic_test(void)
{
 const uint32_t NODES = 50000;
 sll_t head;
 int rc;
 struct tst_basic *np;
 sll_t *l;
 sll_t *midp;
 uint32_t n;
 uint32_t i;
 uint32_t j;
 sll_init(&head);
 rc = sll_is_empty(&head);
 ((void) sizeof ((rc != 0) ? 1 : 0), __extension__ ({ if (rc != 0) ; else __assert_fail ("rc != 0", "test-sll.c", 42, __extension__ __PRETTY_FUNCTION__); }));
 for (i = 0; i < NODES; i++) {
  np = tst_basic_new(i);
  ((void) sizeof ((np != ((void *)0)) ? 1 : 0), __extension__ ({ if (np != ((void *)0)) ; else __assert_fail ("np != NULL", "test-sll.c", 46, __extension__ __PRETTY_FUNCTION__); }));
  sll_insert_head(&head, &np->list);
  rc = sll_is_empty(&head);
  ((void) sizeof ((rc == 0) ? 1 : 0), __extension__ ({ if (rc == 0) ; else __assert_fail ("rc == 0", "test-sll.c", 51, __extension__ __PRETTY_FUNCTION__); }));
  midp = ((void *)0);
  sll_get_mid(&head, &midp);
  ((void) sizeof ((midp != ((void *)0)) ? 1 : 0), __extension__ ({ if (midp != ((void *)0)) ; else __assert_fail ("midp != NULL", "test-sll.c", 55, __extension__ __PRETTY_FUNCTION__); }));
  np = ((struct tst_basic *) (((char *) midp) - ((size_t)(&(((struct tst_basic *) 0)->list)))));
  ((void) sizeof ((np->number == (i >> 1)) ? 1 : 0), __extension__ ({ if (np->number == (i >> 1)) ; else __assert_fail ("np->number == (i >> 1)", "test-sll.c", 57, __extension__ __PRETTY_FUNCTION__); }));
 }
 for (j = 0; j < 10; j++) {
  i = NODES - 1;
  l = sll_next(&head);
  while (l != ((void *)0)) {
   np = ((struct tst_basic *) (((char *) l) - ((size_t)(&(((struct tst_basic *) 0)->list)))));
   ((void) sizeof ((np != ((void *)0)) ? 1 : 0), __extension__ ({ if (np != ((void *)0)) ; else __assert_fail ("np != NULL", "test-sll.c", 65, __extension__ __PRETTY_FUNCTION__); }));
   ((void) sizeof ((np->number == i) ? 1 : 0), __extension__ ({ if (np->number == i) ; else __assert_fail ("np->number == i", "test-sll.c", 66, __extension__ __PRETTY_FUNCTION__); }));
   i--;
   l = sll_next(l);
  }
  sll_reverse(&head);
  i = 0;
  l = sll_next(&head);
  while (l != ((void *)0)) {
   np = ((struct tst_basic *) (((char *) l) - ((size_t)(&(((struct tst_basic *) 0)->list)))));
   ((void) sizeof ((np != ((void *)0)) ? 1 : 0), __extension__ ({ if (np != ((void *)0)) ; else __assert_fail ("np != NULL", "test-sll.c", 76, __extension__ __PRETTY_FUNCTION__); }));
   ((void) sizeof ((np->number == i) ? 1 : 0), __extension__ ({ if (np->number == i) ; else __assert_fail ("np->number == i", "test-sll.c", 77, __extension__ __PRETTY_FUNCTION__); }));
   i++;
   l = sll_next(l);
  }
  sll_reverse_recursive(&head);
 }
 for (j = 0; j < 10; j++) {
  i = NODES - 1;
  l = sll_next(&head);
  while (l != ((void *)0)) {
   np = ((struct tst_basic *) (((char *) l) - ((size_t)(&(((struct tst_basic *) 0)->list)))));
   ((void) sizeof ((np != ((void *)0)) ? 1 : 0), __extension__ ({ if (np != ((void *)0)) ; else __assert_fail ("np != NULL", "test-sll.c", 90, __extension__ __PRETTY_FUNCTION__); }));
   ((void) sizeof ((np->number == i) ? 1 : 0), __extension__ ({ if (np->number == i) ; else __assert_fail ("np->number == i", "test-sll.c", 91, __extension__ __PRETTY_FUNCTION__); }));
   i--;
   l = sll_next(l);
  }
  sll_reverse_recursive(&head);
  i = 0;
  l = sll_next(&head);
  while (l != ((void *)0)) {
   np = ((struct tst_basic *) (((char *) l) - ((size_t)(&(((struct tst_basic *) 0)->list)))));
   ((void) sizeof ((np != ((void *)0)) ? 1 : 0), __extension__ ({ if (np != ((void *)0)) ; else __assert_fail ("np != NULL", "test-sll.c", 101, __extension__ __PRETTY_FUNCTION__); }));
   ((void) sizeof ((np->number == i) ? 1 : 0), __extension__ ({ if (np->number == i) ; else __assert_fail ("np->number == i", "test-sll.c", 102, __extension__ __PRETTY_FUNCTION__); }));
   i++;
   l = sll_next(l);
  }
  sll_reverse(&head);
 }
 while (sll_is_empty(&head) == 0) {
  l = ((void *)0);
  sll_delete_head(&head, &l);
  ((void) sizeof ((l != ((void *)0)) ? 1 : 0), __extension__ ({ if (l != ((void *)0)) ; else __assert_fail ("l != NULL", "test-sll.c", 113, __extension__ __PRETTY_FUNCTION__); }));
  np = ((struct tst_basic *) (((char *) l) - ((size_t)(&(((struct tst_basic *) 0)->list)))));
  free(np);
 }
}

canonical_original_code:
static void basic_test()
{
 unsigned int NODES = 50000;
 struct sll head;
 int rc;
 struct tst_basic *np;
 struct sll *l;
 struct sll *midp;
 unsigned int n;
 unsigned int i;
 unsigned int j;
 sll_init(&head);
 rc = sll_is_empty(&head);
 ((void) sizeof ((rc != 0) ? 1 : 0), __extension__ ({ if (rc != 0) ; else __assert_fail ("rc != 0", "test-sll.c", 42, __extension__ __PRETTY_FUNCTION__); }));
 for (i = 0; i < NODES; i++) {
  np = tst_basic_new(i);
  ((void) sizeof ((np != ((void *)0)) ? 1 : 0), __extension__ ({ if (np != ((void *)0)) ; else __assert_fail ("np != NULL", "test-sll.c", 46, __extension__ __PRETTY_FUNCTION__); }));
  sll_insert_head(&head, &np->list);
  rc = sll_is_empty(&head);
  ((void) sizeof ((rc == 0) ? 1 : 0), __extension__ ({ if (rc == 0) ; else __assert_fail ("rc == 0", "test-sll.c", 51, __extension__ __PRETTY_FUNCTION__); }));
  midp = ((void *)0);
  sll_get_mid(&head, &midp);
  ((void) sizeof ((midp != ((void *)0)) ? 1 : 0), __extension__ ({ if (midp != ((void *)0)) ; else __assert_fail ("midp != NULL", "test-sll.c", 55, __extension__ __PRETTY_FUNCTION__); }));
  np = ((struct tst_basic *) (((char *) midp) - ((unsigned long)(&(((struct tst_basic *) 0)->list)))));
  ((void) sizeof ((np->number == (i >> 1)) ? 1 : 0), __extension__ ({ if (np->number == (i >> 1)) ; else __assert_fail ("np->number == (i >> 1)", "test-sll.c", 57, __extension__ __PRETTY_FUNCTION__); }));
 }
 for (j = 0; j < 10; j++) {
  i = NODES - 1;
  l = sll_next(&head);
  while (l != ((void *)0)) {
   np = ((struct tst_basic *) (((char *) l) - ((unsigned long)(&(((struct tst_basic *) 0)->list)))));
   ((void) sizeof ((np != ((void *)0)) ? 1 : 0), __extension__ ({ if (np != ((void *)0)) ; else __assert_fail ("np != NULL", "test-sll.c", 65, __extension__ __PRETTY_FUNCTION__); }));
   ((void) sizeof ((np->number == i) ? 1 : 0), __extension__ ({ if (np->number == i) ; else __assert_fail ("np->number == i", "test-sll.c", 66, __extension__ __PRETTY_FUNCTION__); }));
   i--;
   l = sll_next(l);
  }
  sll_reverse(&head);
  i = 0;
  l = sll_next(&head);
  while (l != ((void *)0)) {
   np = ((struct tst_basic *) (((char *) l) - ((unsigned long)(&(((struct tst_basic *) 0)->list)))));
   ((void) sizeof ((np != ((void *)0)) ? 1 : 0), __extension__ ({ if (np != ((void *)0)) ; else __assert_fail ("np != NULL", "test-sll.c", 76, __extension__ __PRETTY_FUNCTION__); }));
   ((void) sizeof ((np->number == i) ? 1 : 0), __extension__ ({ if (np->number == i) ; else __assert_fail ("np->number == i", "test-sll.c", 77, __extension__ __PRETTY_FUNCTION__); }));
   i++;
   l = sll_next(l);
  }
  sll_reverse_recursive(&head);
 }
 for (j = 0; j < 10; j++) {
  i = NODES - 1;
  l = sll_next(&head);
  while (l != ((void *)0)) {
   np = ((struct tst_basic *) (((char *) l) - ((unsigned long)(&(((struct tst_basic *) 0)->list)))));
   ((void) sizeof ((np != ((void *)0)) ? 1 : 0), __extension__ ({ if (np != ((void *)0)) ; else __assert_fail ("np != NULL", "test-sll.c", 90, __extension__ __PRETTY_FUNCTION__); }));
   ((void) sizeof ((np->number == i) ? 1 : 0), __extension__ ({ if (np->number == i) ; else __assert_fail ("np->number == i", "test-sll.c", 91, __extension__ __PRETTY_FUNCTION__); }));
   i--;
   l = sll_next(l);
  }
  sll_reverse_recursive(&head);
  i = 0;
  l = sll_next(&head);
  while (l != ((void *)0)) {
   np = ((struct tst_basic *) (((char *) l) - ((unsigned long)(&(((struct tst_basic *) 0)->list)))));
   ((void) sizeof ((np != ((void *)0)) ? 1 : 0), __extension__ ({ if (np != ((void *)0)) ; else __assert_fail ("np != NULL", "test-sll.c", 101, __extension__ __PRETTY_FUNCTION__); }));
   ((void) sizeof ((np->number == i) ? 1 : 0), __extension__ ({ if (np->number == i) ; else __assert_fail ("np->number == i", "test-sll.c", 102, __extension__ __PRETTY_FUNCTION__); }));
   i++;
   l = sll_next(l);
  }
  sll_reverse(&head);
 }
 while (sll_is_empty(&head) == 0) {
  l = ((void *)0);
  sll_delete_head(&head, &l);
  ((void) sizeof ((l != ((void *)0)) ? 1 : 0), __extension__ ({ if (l != ((void *)0)) ; else __assert_fail ("l != NULL", "test-sll.c", 113, __extension__ __PRETTY_FUNCTION__); }));
  np = ((struct tst_basic *) (((char *) l) - ((unsigned long)(&(((struct tst_basic *) 0)->list)))));
  free(np);
 }
}

variable_types:
NODES
unsigned int

variable_types:
head
struct sll { struct sll *next; }

variable_types: rc int

variable_types: struct tst_basic { struct sll { struct sll *next; } list; unsigned int number; } *

variable_types:
l
struct sll { struct sll *next; } *

variable_types:
midp
struct sll { struct sll *next; } *

variable_types:
n
unsigned int

variable_types:
i
unsigned int

variable_types:
j
unsigned int

user_defined_types: struct tst_basic { struct sll list; unsigned int number; }


main

canonical_name: main

repo: prasad-joshi/skiena

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
basic_test(argc, argv, envp);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
func12(argc, argv, envp);
return 0;
}

original_code:
int main(void)
{
 basic_test();
 return 0;
}

canonical_original_code:
int main()
{
 basic_test();
 return 0;
}

return_type: int


decompiled_code:
__int64 __fastcall add_tail(_QWORD *a1, _QWORD **a2, __int64 a3)
{
_QWORD *v3; // r14
_QWORD *v4; // r13
_QWORD *v6; // rax

if ( !a1 )
return 0xFFFFFFFFLL;
v3 = (_QWORD *)*a1;
v4 = *a2;
v6 = get_new();
if ( !v6 )
return 0xFFFFFFFFLL;
v6[1] = a3;
if ( v3 )
*v4 = v6;
else
v3 = v6;
*a1 = v3;
*a2 = v6;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func8(_QWORD *a1, _QWORD **a2, __int64 a3)
{
_QWORD *v3; // r14
_QWORD *v4; // r13
_QWORD *v6; // rax

if ( !a1 )
return 0xFFFFFFFFLL;
v3 = (_QWORD *)*a1;
v4 = *a2;
v6 = func7();
if ( !v6 )
return 0xFFFFFFFFLL;
v6[1] = a3;
if ( v3 )
*v4 = v6;
else
v3 = v6;
*a1 = v3;
*a2 = v6;
return 0LL;
}

original_code:
static int add_tail(struct list **head, struct list **tail, void *data)
{
 struct list *h;
 struct list *t;
 struct list *n;
 if (head == ((void *)0) || tail == ((void *)0)) {
  return (-1);
 }
 h = *head;
 t = *tail;
 n = get_new();
 if (n == ((void *)0)) {
  return (-1);
 }
 n->data = data;
 if (h == ((void *)0)) {
  t = h = n;
 } else {
  t->next = n;
  t = n;
 }
 *head = h;
 *tail = t;
 return (0);
}

variable_types: struct list { struct list *next; void *data; } **

variable_types:
tail
struct list **

variable_types:
data
void *


decompiled_code:
__int64 __fastcall is_empty(_QWORD *a1)
{
__int64 v1; // rax
__int64 result; // rax

v1 = a1[1];
if ( *a1 )
{
if ( !v1 )
__assert_fail("queue->rear != NULL", "queue.c", 0x57u, "is_empty");
result = 0LL;
}
else
{
if ( v1 )
__assert_fail("queue->rear == NULL", "queue.c", 0x53u, "is_empty");
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(_QWORD *a1)
{
__int64 v1; // rax
__int64 result; // rax

v1 = a1[1];
if ( *a1 )
{
if ( !v1 )
__assert_fail("queue->rear != NULL", "queue.c", 0x57u, "is_empty");
result = 0LL;
}
else
{
if ( v1 )
__assert_fail("queue->rear == NULL", "queue.c", 0x53u, "is_empty");
result = 1LL;
}
return result;
}

original_code:
int is_empty(struct queue *queue)
{
 if (queue->front == ((void *)0)) {
  ((void) sizeof ((queue->rear == ((void *)0)) ? 1 : 0), __extension__ ({ if (queue->rear == ((void *)0)) ; else __assert_fail ("queue->rear == NULL", "queue.c", 83, __extension__ __PRETTY_FUNCTION__); }));
  return (1);
 }
 ((void) sizeof ((queue->rear != ((void *)0)) ? 1 : 0), __extension__ ({ if (queue->rear != ((void *)0)) ; else __assert_fail ("queue->rear != NULL", "queue.c", 87, __extension__ __PRETTY_FUNCTION__); }));
 return (0);
}

variable_types: struct queue { struct list { struct list *next; void *data; } *front; struct list *rear; } *

user_defined_types: struct queue { struct list *front; struct list *rear; }


enqueue

decompiled_code:
__int64 __fastcall enqueue(__int64 a1, __int64 a2)
{
return add_tail((_QWORD *)a1, (_QWORD **)(a1 + 8), a2);
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1, __int64 a2)
{
return func8((_QWORD *)a1, (_QWORD **)(a1 + 8), a2);
}

original_code:
int enqueue(struct queue *queue, void *data)
{
 return (add_tail(&queue->front, &queue->rear, data));
}

user_defined_types: struct list { struct list *next; void *data; }


dequeue

decompiled_code:
__int64 __fastcall dequeue(__int64 a1)
{
_QWORD *v1; // rax
__int64 v2; // r12

v1 = remove_head((_QWORD **)a1, (__int64 *)(a1 + 8));
if ( !v1 )
return 0LL;
v2 = v1[1];
free(v1);
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 a1)
{
_QWORD *v1; // rax
__int64 v2; // r12

v1 = remove_head((_QWORD **)a1, (__int64 *)(a1 + 8));
if ( !v1 )
return 0LL;
v2 = v1[1];
free(v1);
return v2;
}

original_code:
void *dequeue(struct queue *queue)
{
 struct list *l = remove_head(&queue->front, &queue->rear);
 void *data = ((void *)0);
 if (l == ((void *)0)) {
  return (((void *)0));
 }
 data = l->data;
 free(l);
 return (data);
}

variable_types: struct list { struct list *next; void *data; } *

return_type: void *


decompiled_code:
__int64 __fastcall next_direction(int a1)
{
__int64 result; // rax

result = (unsigned int)(a1 + 1);
if ( a1 == 4 )
result = 4LL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func13(int a1)
{
__int64 result; // rax

result = (unsigned int)(a1 + 1);
if ( a1 == 4 )
result = 4LL;
return result;
}

original_code:
DIRECTION next_direction(DIRECTION d)
{
 return ((d == INVAL) ? INVAL : ++d);
}

canonical_original_code:
enum DIRECTION next_direction(enum DIRECTION d)
{
 return ((d == INVAL) ? INVAL : ++d);
}

variable_types: enum DIRECTION { START=0, ULD=1, ULU=2, URU=3, URD=4, DLU=5, DLD=6, DRD=7, DRU=8, INVAL=9 }


print

decompiled_code:
int __fastcall print(__int64 a1, int a2, int a3)
{
__int64 v4; // r12
__int64 v5; // rdx
__int64 v6; // rbp
__int64 v7; // r12
__int64 v8; // r14
_BYTE *v9; // rbx
__int64 v10; // rsi
int result; // eax

if ( a2 > 0 )
{
v4 = (unsigned int)(a3 - 1);
v5 = a1 + v4 + 11;
v6 = a1 + v4 + 1;
v7 = ~v4;
v8 = v5 + 10LL * (unsigned int)(a2 - 1);
do
{
v9 = (_BYTE *)(v7 + v6);
if ( a3 > 0 )
{
do
{
while ( 1 )
{
v10 = (unsigned int)(char)*v9;
if ( *v9 == 80 )
break;
++v9;
printf(" *%c* ", v10);
if ( v9 == (_BYTE *)v6 )
goto LABEL_8;
}
++v9;
printf(" %c ", 80LL);
}
while ( v9 != (_BYTE *)v6 );
}
LABEL_8:
v6 += 10LL;
result = putchar(10);
}
while ( v6 != v8 );
}
return result;
}

original_code:
void print(char arr[][10], int nrow, int ncol)
{
 int i;
 int j;
 for (i = 0; i < nrow; i++) {
  for (j = 0; j < ncol; j++) {
   if (arr[i][j] == 'P') {
   printf("  %c  ", arr[i][j]);
   } else {
   printf(" *%c* ", arr[i][j]);
   }
  }
  printf("\n");
 }
}

variable_types:
arr
char [][10]

variable_types: nrow int

variable_types: ncol int

variable_types: i int

variable_types: j int

return_type: void


decompiled_code:
__int64 __fastcall Mem_Init(int a1, int a2)
{
int v3; // edi
float v4; // xmm0_4
int v5; // eax
__int64 result; // rax

globalDebug = a2;
v3 = getpagesize();
v4 = (float)(a1 % v3);
if ( v4 != 0.0 )
a1 = (int)(float)((float)(a1 + v3) - v4);
v5 = open("/dev/zero", 2);
result = (__int64)mmap(0LL, a1, 3, 2, v5, 0LL);
if ( result == -1 )
{
perror("mmap");
result = 0xFFFFFFFFLL;
}
else
{
*(_DWORD *)result = a1;
*(_QWORD *)(result + 4) = 0LL;
Head = result;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(int a1, int a2)
{
int v3; // edi
float v4; // xmm0_4
int v5; // eax
__int64 result; // rax

globalDebug = a2;
v3 = getpagesize();
v4 = (float)(a1 % v3);
if ( v4 != 0.0 )
a1 = (int)(float)((float)(a1 + v3) - v4);
v5 = open("/dev/zero", 2);
result = (__int64)mmap(0LL, a1, 3, 2, v5, 0LL);
if ( result == -1 )
{
perror("mmap");
result = 0xFFFFFFFFLL;
}
else
{
*(_DWORD *)result = a1;
*(_QWORD *)(result + 4) = 0LL;
Head = result;
}
return result;
}

original_code:
int Mem_Init(int sizeOfRegion,int debug)
{
globalDebug=debug;
int size;
float remainder;
int multiple=getpagesize();
remainder=sizeOfRegion % multiple;
 if ( remainder==0.0f )
   {size=sizeOfRegion;}
 else
    {size=sizeOfRegion+multiple-remainder;}
int fd =open("/dev/zero",02);
list *ptr =mmap(((void *)0),size, 0x1 | 0x2,0x02,fd,0);
 if(ptr == ((void *) -1))
 {
  perror("mmap");
  return -1;
 }
ptr->size=size;
ptr->next=((void *)0);
Head = ptr;
}

canonical_original_code:
int Mem_Init(int sizeOfRegion, int debug)
{
globalDebug=debug;
int size;
float remainder;
int multiple = getpagesize();
remainder=sizeOfRegion % multiple;
 if ( remainder==0.0f )
   {size=sizeOfRegion;}
 else
    {size=sizeOfRegion+multiple-remainder;}
int fd = open("/dev/zero",02);
struct freelist *ptr = mmap(((void *)0),size, 0x1 | 0x2,0x02,fd,0);
 if(ptr == ((void *) -1))
 {
  perror("mmap");
  return -1;
 }
ptr->size=size;
ptr->next=((void *)0);
Head = ptr;
}

variable_types: sizeOfRegion int

variable_types: debug int

variable_types: size int

variable_types: remainder float

variable_types: multiple int

variable_types: fd int

variable_types: struct freelist { int size; struct freelist *next; } *


original_code:
int Mem_Free(void *ptr)
{
list * header = (void *) ptr - sizeof(list);
list * traverse=Head;
list * trav_alloc=allocHead;
while(trav_alloc!=((void *)0))
{
 if(header == allocHead)
 {
  allocHead=allocHead->next;
  header->next=((void *)0);
  break;
 }
        else if((trav_alloc->next) == header)
 {
  trav_alloc->next=header->next;
  header->next=((void *)0);
  break;
 }
trav_alloc=trav_alloc->next;
}
int size_to_free= header->size;
int k=0;
while( (traverse!=((void *)0)) )
{
list * traverse_next= traverse->next;
  if(k==0)
  {
   if ( size_to_free < (traverse->size))
   {
    header->next=Head;
    Head=header;
   }
   else if(((size_to_free) > (traverse->size)) && ( (size_to_free) <= (traverse_next->size) ))
   {
    traverse->next= header;
    header->next=traverse_next;
   }
  }
  else
  {
   if(((size_to_free) > (traverse->size)) && ( (size_to_free) <= (traverse_next->size) ))
   {
    traverse->next= header;
    header->next=traverse_next;
   }
  }
traverse=traverse->next;
k++;
}
list * lhead=Head;
list *prev_lhead=Head;
int i=0;
int service=0;
list* saveList;
list* savePrev;
while(lhead!=((void *)0))
{
int isHead=0;
int isGreater=0;
list * trav=Head;
list * prev_trav=Head;
int sizetemp = lhead->size;
 int j=0;
 while(trav!=((void *)0))
 { list * temp =lhead;
  if( ( ((void*)temp+sizeof(list)+ sizetemp) == ((void*)trav)) )
  {
      if(i>j)
      {
     if( trav == prev_trav)
     {
       Head=Head->next;
       trav->next=((void *)0);
       lhead->size= lhead->size + trav->size + sizeof(list);
       service=1;
     }
     else
     {
       prev_trav->next= trav->next;
       trav->next=((void *)0);
       lhead->size= lhead->size + trav->size + sizeof(list);
       service=1;
     }
    }
      else if(i<j)
      {
    if (((lhead)->next) == trav )
    {
     lhead->next=trav->next;
     trav->next=((void *)0);
     lhead->size= lhead->size + trav->size + sizeof(list);
     service=1;
    }
    else
    {
     prev_trav->next= trav->next;
     trav->next=((void *)0);
     lhead->size= trav->size + lhead->size + sizeof(list);
     service=1;
    }
     }
   if(lhead==Head)
   {isHead=1;}
  if((lhead->next)!=((void *)0))
   {if( (lhead->size)> (lhead->next->size))
    {isGreater=1;}
    saveList=lhead;
    savePrev=prev_lhead;}
  }
  if(j!=0)
  {prev_trav = prev_trav->next;}
  trav=trav->next;
  j++;
 }
if(i!=0)
{ prev_lhead =prev_lhead->next; }
lhead= lhead-> next;
i++;
if(service ==1)
{
int complete=0;
list* tra=saveList;
list* tra_prev=saveList;
int sizecomp= saveList->size;
int count=0;
while((tra!=((void *)0)) && (complete==0))
{
 if((isHead==1) && (isGreater==1))
 {
  if(sizecomp < (tra->size) )
  {
   Head=Head->next;
   tra_prev->next=saveList;
   saveList->next=tra;
  }
 }
 else if((isHead==0) && (isGreater==1))
 {
  if(sizecomp < (tra->size))
  {
   savePrev->next=saveList->next;
   tra_prev->next=saveList;
   saveList->next=tra;
  }
 }
tra=tra->next;
if(count!=0)
{tra_prev=tra_prev->next;}
count++;
}
lhead=Head;
prev_lhead=Head;
i=0;
}
service=0;
}
}

canonical_original_code:
int Mem_Free(void *ptr)
{
struct freelist *header = (void *) ptr - sizeof(list);
struct freelist *traverse = Head;
struct freelist *trav_alloc = allocHead;
while(trav_alloc!=((void *)0))
{
 if(header == allocHead)
 {
  allocHead=allocHead->next;
  header->next=((void *)0);
  break;
 }
        else if((trav_alloc->next) == header)
 {
  trav_alloc->next=header->next;
  header->next=((void *)0);
  break;
 }
trav_alloc=trav_alloc->next;
}
int size_to_free = header->size;
int k = 0;
while( (traverse!=((void *)0)) )
{
struct freelist *traverse_next = traverse->next;
  if(k==0)
  {
   if ( size_to_free < (traverse->size))
   {
    header->next=Head;
    Head=header;
   }
   else if(((size_to_free) > (traverse->size)) && ( (size_to_free) <= (traverse_next->size) ))
   {
    traverse->next= header;
    header->next=traverse_next;
   }
  }
  else
  {
   if(((size_to_free) > (traverse->size)) && ( (size_to_free) <= (traverse_next->size) ))
   {
    traverse->next= header;
    header->next=traverse_next;
   }
  }
traverse=traverse->next;
k++;
}
struct freelist *lhead = Head;
struct freelist *prev_lhead = Head;
int i = 0;
int service = 0;
struct freelist *saveList;
struct freelist *savePrev;
while(lhead!=((void *)0))
{
int isHead = 0;
int isGreater = 0;
struct freelist *trav = Head;
struct freelist *prev_trav = Head;
int sizetemp = lhead->size;
 int j = 0;
 while(trav!=((void *)0))
 { struct freelist *temp = lhead;
  if( ( ((void *)temp+sizeof(list)+ sizetemp) == ((void *)trav)) )
  {
      if(i>j)
      {
     if( trav == prev_trav)
     {
       Head=Head->next;
       trav->next=((void *)0);
       lhead->size= lhead->size + trav->size + sizeof(list);
       service=1;
     }
     else
     {
       prev_trav->next= trav->next;
       trav->next=((void *)0);
       lhead->size= lhead->size + trav->size + sizeof(list);
       service=1;
     }
    }
      else if(i<j)
      {
    if (((lhead)->next) == trav )
    {
     lhead->next=trav->next;
     trav->next=((void *)0);
     lhead->size= lhead->size + trav->size + sizeof(list);
     service=1;
    }
    else
    {
     prev_trav->next= trav->next;
     trav->next=((void *)0);
     lhead->size= trav->size + lhead->size + sizeof(list);
     service=1;
    }
     }
   if(lhead==Head)
   {isHead=1;}
  if((lhead->next)!=((void *)0))
   {if( (lhead->size)> (lhead->next->size))
    {isGreater=1;}
    saveList=lhead;
    savePrev=prev_lhead;}
  }
  if(j!=0)
  {prev_trav = prev_trav->next;}
  trav=trav->next;
  j++;
 }
if(i!=0)
{ prev_lhead =prev_lhead->next; }
lhead= lhead-> next;
i++;
if(service ==1)
{
int complete = 0;
struct freelist *tra = saveList;
struct freelist *tra_prev = saveList;
int sizecomp = saveList->size;
int count = 0;
while((tra!=((void *)0)) && (complete==0))
{
 if((isHead==1) && (isGreater==1))
 {
  if(sizecomp < (tra->size) )
  {
   Head=Head->next;
   tra_prev->next=saveList;
   saveList->next=tra;
  }
 }
 else if((isHead==0) && (isGreater==1))
 {
  if(sizecomp < (tra->size))
  {
   savePrev->next=saveList->next;
   tra_prev->next=saveList;
   saveList->next=tra;
  }
 }
tra=tra->next;
if(count!=0)
{tra_prev=tra_prev->next;}
count++;
}
lhead=Head;
prev_lhead=Head;
i=0;
}
service=0;
}
}

variable_types:
ptr
void *

variable_types: k int

variable_types: service int

variable_types: isHead int

variable_types: isGreater int

variable_types: sizetemp int

variable_types: complete int

variable_types: sizecomp int

variable_types: count int

user_defined_types: struct freelist { int size; struct freelist *next; }


decompiled_code:
int Mem_Dump()
{
_DWORD **v0; // rax
unsigned int *i; // rbx

v0 = &Head;
for ( i = Head; i; i = *(unsigned int **)(i + 1) )
LODWORD(v0) = printf(" FREE LIST ;size if -> %d , address -> %p\n", *i, i);
return (int)v0;
}

canonical_decompiled_code:
int func9()
{
_DWORD **v0; // rax
unsigned int *i; // rbx

v0 = &Head;
for ( i = Head; i; i = *(unsigned int **)(i + 1) )
LODWORD(v0) = printf(" FREE LIST ;size if -> %d , address -> %p\n", *i, i);
return (int)v0;
}

original_code:
void Mem_Dump()
{
list * traverse=Head;
 while(traverse!=((void *)0))
 {
  printf(" FREE LIST ;size if -> %d , address -> %p\n",traverse->size, (void*)traverse);
  traverse = traverse->next;
 }
}

canonical_original_code:
void Mem_Dump()
{
struct freelist *traverse = Head;
 while(traverse!=((void *)0))
 {
  printf(" FREE LIST ;size if -> %d , address -> %p\n",traverse->size, (void *)traverse);
  traverse = traverse->next;
 }
}


main

variable_types: argc int

variable_types:
argv
char *[]

variable_types: a int

variable_types: b int

variable_types: c int

variable_types: d int

variable_types: e int

variable_types: f int

variable_types: m int

variable_types: p int


decompiled_code:
__int64 init_edges()
{
add_edge(5LL, 4LL, &list);
add_edge(0LL, 2LL, &unk_404088);
add_edge(6LL, 2LL, &unk_404088);
add_edge(1LL, 3LL, &unk_404090);
add_edge(4LL, 1LL, &unk_404098);
add_edge(2LL, 2LL, &unk_404098);
add_edge(5LL, 3LL, &unk_4040A0);
add_edge(6LL, 2LL, &unk_4040A0);
add_edge(6LL, 1LL, &unk_4040A8);
add_edge(0LL, 1LL, &unk_4040B0);
add_edge(5LL, 1LL, &unk_4040B0);
add_edge(3LL, 3LL, &unk_4040B0);
return add_edge(2LL, 4LL, &unk_4040B0);
}

canonical_decompiled_code:
__int64 func7()
{
add_edge(5LL, 4LL, &list);
add_edge(0LL, 2LL, &unk_404088);
add_edge(6LL, 2LL, &unk_404088);
add_edge(1LL, 3LL, &unk_404090);
add_edge(4LL, 1LL, &unk_404098);
add_edge(2LL, 2LL, &unk_404098);
add_edge(5LL, 3LL, &unk_4040A0);
add_edge(6LL, 2LL, &unk_4040A0);
add_edge(6LL, 1LL, &unk_4040A8);
add_edge(0LL, 1LL, &unk_4040B0);
add_edge(5LL, 1LL, &unk_4040B0);
add_edge(3LL, 3LL, &unk_4040B0);
return add_edge(2LL, 4LL, &unk_4040B0);
}


decompiled_code:
__int64 __fastcall initialize_data_structures(unsigned int a1)
{
init_edges();
init_heap(a1, &heap, (unsigned int)len_heap);
return init_weight_array(a1, &weights, (unsigned int)len_heap);
}

canonical_decompiled_code:
__int64 __fastcall func8(unsigned int a1)
{
func7();
func11(a1, &heap, (unsigned int)len_heap);
return func12(a1, &weights, (unsigned int)len_heap);
}

original_code:
void initialize_data_structures(int source)
{
 init_edges();
 init_heap(source, heap, len_heap);
 init_weight_array(source, weights, len_heap);
}

variable_types: source int


decompiled_code:
void do_dijkstra()
{
__int64 v0; // rax
int v1; // ebp
int *v2; // rbx
int v3; // ecx
__int64 i; // r12
__int64 v5; // rax
int v6; // ecx
__int64 v7; // rdx

while ( len_heap > 0 )
{
v0 = extract_min(&heap, &len_heap);
v1 = v0;
v2 = (int *)list[(int)v0];
weights[2 * (int)v0] = HIDWORD(v0);
v3 = HIDWORD(v0);
if ( v2 )
{
for ( i = (int)v0; ; v3 = weights[2 * i] )
{
v5 = *v2;
v6 = v2[1] + v3;
if ( weights[2 * v5] <= v6 )
{
v2 = (int *)*((_QWORD *)v2 + 1);
if ( !v2 )
break;
}
else
{
v7 = (unsigned int)len_heap;
dword_4040C4[2 * v5] = v1;
weights[2 * v5] = v6;
decrease_key(v5, &heap, v7);
v2 = (int *)*((_QWORD *)v2 + 1);
if ( !v2 )
break;
}
}
}
}
}

canonical_decompiled_code:
void func9()
{
__int64 v0; // rax
int v1; // ebp
int *v2; // rbx
int v3; // ecx
__int64 i; // r12
__int64 v5; // rax
int v6; // ecx
__int64 v7; // rdx

while ( len_heap > 0 )
{
v0 = func14(&heap, &len_heap);
v1 = v0;
v2 = (int *)list[(int)v0];
weights[2 * (int)v0] = HIDWORD(v0);
v3 = HIDWORD(v0);
if ( v2 )
{
for ( i = (int)v0; ; v3 = weights[2 * i] )
{
v5 = *v2;
v6 = v2[1] + v3;
if ( weights[2 * v5] <= v6 )
{
v2 = (int *)*((_QWORD *)v2 + 1);
if ( !v2 )
break;
}
else
{
v7 = (unsigned int)len_heap;
dword_4040C4[2 * v5] = v1;
weights[2 * v5] = v6;
func15(v5, &heap, v7);
v2 = (int *)*((_QWORD *)v2 + 1);
if ( !v2 )
break;
}
}
}
}
}

original_code:
void do_dijkstra(int source)
{
 struct heap_t cur_min;
 struct adj_t *cur_ver;
 int index, new_weight;
 while (len_heap > 0) {
  cur_min = extract_min(heap, &len_heap);
  index = cur_min.index;
  weights[index].dist = cur_min.dist;
  for (cur_ver = list[index]; cur_ver != ((void *)0); cur_ver= cur_ver->next) {
   new_weight = weights[index].dist +
    cur_ver->edge;
   if (new_weight < weights[cur_ver->index].dist) {
    weights[cur_ver->index].parent = index;
    weights[cur_ver->index].dist = new_weight;
    decrease_key(cur_ver->index, heap, len_heap, new_weight);
   }
  }
 }
}

canonical_original_code:
void do_dijkstra(int source)
{
 struct heap_t cur_min;
 struct adj_t *cur_ver;
 int index; int new_weight;
 while (len_heap > 0) {
  cur_min = extract_min(heap, &len_heap);
  index = cur_min.index;
  weights[index].dist = cur_min.dist;
  for (cur_ver = list[index]; cur_ver != ((void *)0); cur_ver= cur_ver->next) {
   new_weight = weights[index].dist +
    cur_ver->edge;
   if (new_weight < weights[cur_ver->index].dist) {
    weights[cur_ver->index].parent = index;
    weights[cur_ver->index].dist = new_weight;
    decrease_key(cur_ver->index, heap, len_heap, new_weight);
   }
  }
 }
}

variable_types: struct adj_t { int index; int edge; struct adj_t *next; } *

variable_types: index int


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

if ( a1 )
{
v1 = a1;
do
{
printf("ind = %d, edge = %d \t", *v1, v1[1]);
v1 = (unsigned int *)*((_QWORD *)v1 + 1);
}
while ( v1 );
}
return putchar(10);
}

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

if ( a1 )
{
v1 = a1;
do
{
printf("ind = %d, edge = %d \t", *v1, v1[1]);
v1 = (unsigned int *)*((_QWORD *)v1 + 1);
}
while ( v1 );
}
return putchar(10);
}

original_code:
void print_adj_list(struct adj_t *head)
{
 struct adj_t *cur;
 for (cur = head; cur != ((void *)0); cur=cur->next)
  printf("ind = %d, edge = %d \t", cur->index, cur->edge);
 printf("\n");
}

user_defined_types: struct adj_t { int index; int edge; struct adj_t *next; }


original_code:
void init_heap(int index_src, struct heap_t heap[], int len)
{
 int i;
 int ind = 0;
 heap[ind].index = index_src;
 heap[ind].dist = 0;
 ind++;
 for (i = 0; i < len; i++) {
  if (i != index_src) {
   heap[ind].index = i;
   heap[ind].dist = 0x7fffffff;
   ind++;
  }
 }
}

variable_types: struct heap_t { int index; int dist; } []

variable_types: len int

variable_types: i int

variable_types: ind int


decompiled_code:
__int64 __fastcall min_heapify(int a1, __int64 a2, int a3)
{
__int64 v4; // rdx
__int64 result; // rax
__int64 *v6; // rcx
__int64 *v7; // rdx
__int64 v8; // rdi
int v9; // ecx

while ( 1 )
{
v9 = 2 * a1 + 1;
result = (unsigned int)(2 * a1 + 2);
if ( v9 >= a3 )
break;
v4 = a1;
if ( *(_DWORD *)(a2 + 8LL * v9 + 4) >= *(_DWORD *)(a2 + 8LL * a1 + 4) )
break;
if ( (int)result < a3 )
{
if ( *(_DWORD *)(a2 + 8LL * (int)result + 4) >= *(_DWORD *)(a2 + 8LL * v9 + 4) )
result = (unsigned int)v9;
}
else
{
result = (unsigned int)v9;
}
LABEL_5:
if ( (_DWORD)result == a1 )
return result;
v6 = (__int64 *)(a2 + 8 * v4);
v7 = (__int64 *)(a2 + 8LL * (int)result);
v8 = *v6;
*v6 = *v7;
*v7 = v8;
a1 = result;
}
if ( (int)result < a3 )
{
v4 = a1;
if ( *(_DWORD *)(a2 + 8LL * (int)result + 4) < *(_DWORD *)(a2 + 8LL * a1 + 4) )
goto LABEL_5;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func13(int a1, __int64 a2, int a3)
{
__int64 v4; // rdx
__int64 result; // rax
__int64 *v6; // rcx
__int64 *v7; // rdx
__int64 v8; // rdi
int v9; // ecx

while ( 1 )
{
v9 = 2 * a1 + 1;
result = (unsigned int)(2 * a1 + 2);
if ( v9 >= a3 )
break;
v4 = a1;
if ( *(_DWORD *)(a2 + 8LL * v9 + 4) >= *(_DWORD *)(a2 + 8LL * a1 + 4) )
break;
if ( (int)result < a3 )
{
if ( *(_DWORD *)(a2 + 8LL * (int)result + 4) >= *(_DWORD *)(a2 + 8LL * v9 + 4) )
result = (unsigned int)v9;
}
else
{
result = (unsigned int)v9;
}
LABEL_5:
if ( (_DWORD)result == a1 )
return result;
v6 = (__int64 *)(a2 + 8 * v4);
v7 = (__int64 *)(a2 + 8LL * (int)result);
v8 = *v6;
*v6 = *v7;
*v7 = v8;
a1 = result;
}
if ( (int)result < a3 )
{
v4 = a1;
if ( *(_DWORD *)(a2 + 8LL * (int)result + 4) < *(_DWORD *)(a2 + 8LL * a1 + 4) )
goto LABEL_5;
}
return result;
}

original_code:
void min_heapify(int ind, struct heap_t heap[], int len)
{
 int l = 2 * ind + 1;
 int r = 2 * ind + 2;
 int ind_min = ind;
 if (l < len && heap[l].dist < heap[ind_min].dist)
  ind_min = l;
 if (r < len && heap[r].dist < heap[ind_min].dist)
  ind_min = r;
 if (ind_min != ind) {
  struct heap_t temp = heap[ind];
  heap[ind] = heap[ind_min];
  heap[ind_min] = temp;
  min_heapify(ind_min, heap, len);
 }
}

variable_types: l int

variable_types: r int

variable_types:
temp
struct heap_t { int index; int dist; }


original_code:
struct heap_t extract_min(struct heap_t heap[], int *len)
{
 struct heap_t ret = heap[0];
 heap[0] = heap[*len-1];
 (*len)--;
 min_heapify(0, heap, *len);
 return ret;
}

variable_types:
heap
struct heap_t []

variable_types:
len
int *

variable_types:
ret
struct heap_t { int index; int dist; }

return_type: struct heap_t { int index; int dist; }


original_code:
void decrease_key(int index, struct heap_t heap[], int len, int new_val)
{
 int i = 0;
 int parent;
 struct heap_t temp;
 for (i; i < len && (heap[i].index != index); i++);
 heap[i].dist = new_val;
 while (i > 0) {
  parent = i / 2;
  if (heap[parent].dist > heap[i].dist) {
   temp = heap[parent];
   heap[parent] = heap[i];
   heap[i] = temp;
   i = parent;
  } else {
   break;
  }
 }
}

variable_types: parent int


decompiled_code:
int __fastcall print_fin_array(__int64 a1, int a2)
{
__int64 v2; // r12
__int64 i; // rbx
__int64 v4; // rcx
__int64 v5; // rdx
__int64 v6; // rsi
int result; // eax

if ( a2 > 0 )
{
v2 = a2;
for ( i = 0LL; i != v2; ++i )
{
v4 = *(unsigned int *)(a1 + 8 * i + 4);
v5 = *(unsigned int *)(a1 + 8 * i);
v6 = (unsigned int)i;
result = printf("Index = %d, Weight = %d, Parent = %d\n", v6, v5, v4);
}
}
return result;
}

canonical_decompiled_code:
int __fastcall func16(__int64 a1, int a2)
{
__int64 v2; // r12
__int64 i; // rbx
__int64 v4; // rcx
__int64 v5; // rdx
__int64 v6; // rsi
int result; // eax

if ( a2 > 0 )
{
v2 = a2;
for ( i = 0LL; i != v2; ++i )
{
v4 = *(unsigned int *)(a1 + 8 * i + 4);
v5 = *(unsigned int *)(a1 + 8 * i);
v6 = (unsigned int)i;
result = printf("Index = %d, Weight = %d, Parent = %d\n", v6, v5, v4);
}
}
return result;
}

original_code:
void print_fin_array(struct final_t final[], int len)
{
 int i;
 for (i = 0; i < len; i++)
  printf("Index = %d, Weight = %d, Parent = %d\n", i, final[i].dist, final[i].parent);
}

variable_types: struct final_t { int dist; int parent; } []


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
initialize_data_structures(3LL, argv, envp);
do_dijkstra(3LL);
print_fin_array(&weights, 7LL);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
func8(3LL, argv, envp);
func9(3LL);
func16(&weights, 7LL);
return 0;
}

original_code:
int main()
{
 struct heap_t min;
 initialize_data_structures(3);
 do_dijkstra(3);
 print_fin_array(weights, 7);
 return 0;
}

variable_types:
min
struct heap_t { int index; int dist; }


decompiled_code:
int __fastcall print_in_order(unsigned int *a1)
{
unsigned int *v1; // rbx
const char *v2; // rdx
int result; // eax

if ( a1 != (unsigned int *)nil_node )
{
v1 = a1;
do
{
print_in_order(*((_QWORD *)v1 + 1));
v2 = (const char *)&unk_612;
if ( v1[8] == 1 )
v2 = (const char *)&unk_610;
result = printf("%d(%s) ", *v1, v2);
v1 = (unsigned int *)*((_QWORD *)v1 + 2);
}
while ( (unsigned int *)nil_node != v1 );
}
return result;
}

canonical_decompiled_code:
int __fastcall func0(unsigned int *a1)
{
unsigned int *v1; // rbx
const char *v2; // rdx
int result; // eax

if ( a1 != (unsigned int *)nil_node )
{
v1 = a1;
do
{
func0(*((_QWORD *)v1 + 1));
v2 = (const char *)&unk_612;
if ( v1[8] == 1 )
v2 = (const char *)&unk_610;
result = printf("%d(%s) ", *v1, v2);
v1 = (unsigned int *)*((_QWORD *)v1 + 2);
}
while ( (unsigned int *)nil_node != v1 );
}
return result;
}

original_code:
void print_in_order(struct node *node)
{
 if ((node == nil_node))
  return;
 print_in_order(node->l);
 printf("%d(%s) ", node->val,(node->col == RED) ? "R" : "B");
 print_in_order(node->r);
}

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

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


successor

decompiled_code:
__int64 __fastcall successor(__int64 a1)
{
__int64 v1; // rax
__int64 v2; // r8

v1 = *(_QWORD *)(a1 + 16);
if ( nil_node == v1 )
return nil_node;
do
{
v2 = v1;
v1 = *(_QWORD *)(v1 + 8);
}
while ( nil_node != v1 );
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
__int64 v1; // rax
__int64 v2; // r8

v1 = *(_QWORD *)(a1 + 16);
if ( nil_node == v1 )
return nil_node;
do
{
v2 = v1;
v1 = *(_QWORD *)(v1 + 8);
}
while ( nil_node != v1 );
return v2;
}

original_code:
struct node *successor(struct node *s)
{
 struct node *next = s->r;
 if ((next == nil_node))
  return next;
 while (!(next->l == nil_node)) {
  next = next->l;
 }
 return next;
}

variable_types:
s
struct node *

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


search

decompiled_code:
int *__fastcall search(int *a1, int a2)
{
int i; // eax

for ( i = *a1; *a1 != a2; i = *a1 )
{
if ( a2 < i )
{
a1 = (int *)*((_QWORD *)a1 + 1);
if ( a1 == (int *)nil_node )
goto LABEL_8;
}
else if ( a2 <= i || (a1 = (int *)*((_QWORD *)a1 + 2), a1 == (int *)nil_node) )
{
LABEL_8:
puts("Element not found");
return 0LL;
}
}
return a1;
}

canonical_decompiled_code:
int *__fastcall func2(int *a1, int a2)
{
int i; // eax

for ( i = *a1; *a1 != a2; i = *a1 )
{
if ( a2 < i )
{
a1 = (int *)*((_QWORD *)a1 + 1);
if ( a1 == (int *)nil_node )
goto LABEL_8;
}
else if ( a2 <= i || (a1 = (int *)*((_QWORD *)a1 + 2), a1 == (int *)nil_node) )
{
LABEL_8:
puts("Element not found");
return 0LL;
}
}
return a1;
}

original_code:
struct node *search(struct node *cur, int val)
{
 if (cur->val == val)
  return cur;
 if (val < cur->val && !(cur->l == nil_node))
  return search(cur->l, val);
 else if (val > cur->val && !(cur->r == nil_node))
  return search(cur->r, val);
 else {
  printf("Element not found\n");
  return ((void *)0);
 }
}

variable_types:
cur
struct node *

variable_types: val int


original_code:
void rb_delete_fixup(struct node **root, struct node *x)
{
 struct node *w;
 while (!(x->p == nil_node) && !(x->col == RED)) {
  if ((x->p->l == x)) {
   printf("Not here\n");
   w = x->p->r;
   if ((w->col == RED)) {
    x->p->col = RED;
    w->col = BLACK;
    rotate_left(x->p, root);
    w = x->p->r;
   }
   if (!(w->l->col == RED) && !(w->r->col == RED)) {
    w->col = RED;
    x = x->p;
   } else {
    if ((w->l->col == RED)) {
     w->l->col = BLACK;
     w->col = RED;
     rotate_right(w, root);
     w = x->p->r;
    }
    w->col = x->p->col;
    x->p->col = BLACK;
    w->r->col = BLACK;
    rotate_left(x->p, root);
    break;
   }
  } else {
   w = x->p->l;
   if ((w->col == RED)) {
    x->p->col = RED;
    w->col = BLACK;
    rotate_right(x->p, root);
    w = x->p->l;
   }
   if (!(w->l->col == RED) && !(w->r->col == RED)) {
    w->col = RED;
    x = x->p;
   } else {
    if ((w->r->col == RED)) {
     w->r->col = BLACK;
     w->col = RED;
     rotate_left(w, root);
     w = x->p->l;
    }
    w->col = x->p->col;
    x->p->col = BLACK;
    w->l->col = BLACK;
    rotate_right(x->p, root);
    break;
   }
  }
 }
 if ((x->p == nil_node)) {
  *root = x;
  x->col = BLACK;
 }
}

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

variable_types:
x
struct node *


delete

original_code:
void delete(struct node **root, int val)
{
 struct node *del = search(*root, val);
 struct node *splice;
 struct node *child_splice;
 if (!del) {
  printf("No element to delete\n");
  return;
 }
 if ((del->l == nil_node) && (del->r == nil_node)) {
  if ((del->p->l == del))
   del->p->l = nil_node;
  else
   del->p->r = nil_node;
  if (del == *root)
   *root = ((void *)0);
  free(del);
  return;
 }
 if ((del->l == nil_node) || (del->r == nil_node)) {
  splice = del;
 } else {
  splice = successor(del);
 }
 if (!(splice->l == nil_node))
  child_splice = splice->l;
 else
  child_splice = splice->r;
 child_splice->p = splice->p;
 if ((splice->p == nil_node)) {
  *root = child_splice;
 } else if ((splice->p->l == splice)){
  splice->p->l = child_splice;
 } else {
  splice->p->r = child_splice;
 }
 if (splice != del)
  del->val = splice->val;
 if (!(splice->col == RED)) {
  rb_delete_fixup(root, child_splice);
 }
 free(splice);
 return;
}


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((int **)&root, 10);
insert((int **)&root, 5);
insert((int **)&root, 20);
insert((int **)&root, 8);
insert((int **)&root, 4);
insert((int **)&root, 2);
insert((int **)&root, 3);
insert((int **)&root, 30);
insert((int **)&root, 25);
insert((int **)&root, 1);
print_in_order((unsigned int *)root);
putchar(10);
delete((int **)&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;
insert((int **)&root, 10);
insert((int **)&root, 5);
insert((int **)&root, 20);
insert((int **)&root, 8);
insert((int **)&root, 4);
insert((int **)&root, 2);
insert((int **)&root, 3);
insert((int **)&root, 30);
insert((int **)&root, 25);
insert((int **)&root, 1);
func0((unsigned int *)root);
putchar(10);
func4((int **)&root, 3);
func0((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:
root
struct node **


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

if ( !a1 )
return puts("Empty list");
v1 = a1;
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

if ( !a1 )
return puts("Empty list");
v1 = a1;
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; } **


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rdx
__int64 v4; // rdx
__int64 v5; // rdx
__int64 v6; // rdx
__int64 v7; // rdx

create_node(&head, 3LL, envp);
create_node(&head, 4LL, v3);
create_node(&head, 5LL, v4);
create_node(&head, 6LL, v5);
create_node(&head, 7LL, v6);
create_node(&head, 8LL, v7);
print_list(head);
reverse(&head);
print_list(head);
delete(&head, 4294967286LL);
print_list(head);
delete(&head, 5LL);
print_list(head);
delete(&head, 3LL);
print_list(head);
delete(&head, 8LL);
print_list(head);
reverse(&head);
print_list(head);
delete(&head, 4LL);
print_list(head);
reverse(&head);
print_list(head);
delete(&head, 6LL);
print_list(head);
reverse(&head);
print_list(head);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rdx
__int64 v4; // rdx
__int64 v5; // rdx
__int64 v6; // rdx
__int64 v7; // rdx

func7(&head, 3LL, envp);
func7(&head, 4LL, v3);
func7(&head, 5LL, v4);
func7(&head, 6LL, v5);
func7(&head, 7LL, v6);
func7(&head, 8LL, v7);
func8(head);
func10(&head);
func8(head);
func9(&head, 4294967286LL);
func8(head);
func9(&head, 5LL);
func8(head);
func9(&head, 3LL);
func8(head);
func9(&head, 8LL);
func8(head);
func10(&head);
func8(head);
func9(&head, 4LL);
func8(head);
func10(&head);
func8(head);
func9(&head, 6LL);
func8(head);
func10(&head);
func8(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;
}


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

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

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

v2 = malloc(0x10uLL);
if ( !v2 )
return 0xFFFFFFFFLL;
v3 = *a1;
*(_DWORD *)v2 = a2;
*a1 = (__int64)v2;
v2[1] = v3;
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;
}

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


delete

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

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

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

v3 = *a1;
v4 = 0LL;
if ( v3 )
{
while ( 1 )
{
v5 = (void *)v3[1];
if ( *(_DWORD *)v3 == a2 )
break;
v4 = v3;
if ( !v5 )
goto LABEL_10;
v3 = (_QWORD *)v3[1];
}
if ( v4 )
v4[1] = v5;
else
*a1 = v5;
free(v3);
result = 0LL;
}
else
{
LABEL_10:
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;
}


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

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

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

if ( (_BYTE)a1 )
{
v1 = a1 - 1;
do
{
--v1;
result = fputc(32, stdout);
}
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

v4 = a2;
print(a1);
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

v4 = a2;
func0(a1);
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; // edx
int i; // ebx

print(a1);
if ( a3 > a4 )
{
v6 = a3;
for ( i = a3 - 1; ; --i )
{
print_bit(0LL, a2, v6);
v6 = i;
if ( i == a3 - 1 - (unsigned __int8)(a3 - a4 - 1) )
break;
}
}
return print_bit((const char *)&unk_6CD, a2, a4);
}

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

func0(a1);
if ( a3 > a4 )
{
v6 = a3;
for ( i = a3 - 1; ; --i )
{
func12(0LL, a2, v6);
v6 = i;
if ( i == a3 - 1 - (unsigned __int8)(a3 - a4 - 1) )
break;
}
}
return func12((const char *)&unk_6CD, 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)
{
FILE *v3; // rsi
char v4; // di
char v5; // bl
int v6; // ebp
int result; // eax

print(a1);
if ( !a2 )
return fputc(48, stdout);
v3 = stdout;
v4 = (unsigned __int8)((unsigned __int16)(103 * (a2 / 0xAu)) >> 8) >> 2;
v5 = a2 / 0xAu - 10 * v4;
v6 = (unsigned __int8)(a2 % 0xAu + 48);
if ( a2 > 0x63u )
{
fputc((unsigned __int8)(v4 + 48), stdout);
fputc((unsigned __int8)(v5 + 48), stdout);
result = fputc(v6, stdout);
}
else
{
if ( v5 )
{
fputc((unsigned __int8)(v5 + 48), stdout);
v3 = stdout;
}
result = fputc(v6, v3);
}
return result;
}

canonical_decompiled_code:
int __fastcall func17(const char *a1, unsigned __int8 a2)
{
FILE *v3; // rsi
char v4; // di
char v5; // bl
int v6; // ebp
int result; // eax

func0(a1);
if ( !a2 )
return fputc(48, stdout);
v3 = stdout;
v4 = (unsigned __int8)((unsigned __int16)(103 * (a2 / 0xAu)) >> 8) >> 2;
v5 = a2 / 0xAu - 10 * v4;
v6 = (unsigned __int8)(a2 % 0xAu + 48);
if ( a2 > 0x63u )
{
fputc((unsigned __int8)(v4 + 48), stdout);
fputc((unsigned __int8)(v5 + 48), stdout);
result = fputc(v6, stdout);
}
else
{
if ( v5 )
{
fputc((unsigned __int8)(v5 + 48), stdout);
v3 = stdout;
}
result = fputc(v6, v3);
}
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)
{
FILE *v3; // rsi
int v4; // edi
unsigned int v5; // ebp
unsigned int v6; // ebx
unsigned int v7; // edx
__int16 v8; // bp
unsigned int v9; // edi
__int16 v10; // dx
__int16 v11; // r12
int v13; // edi

print(a1);
v3 = stdout;
v4 = 48;
if ( a2 )
{
v5 = a2 / 0xAu / 0xA;
v6 = a2 / 0xAu - 10 * v5;
v7 = (unsigned __int16)v5 / 0xAu;
v3 = stdout;
v8 = (unsigned __int16)v5 % 0xAu;
v9 = (52429 * v7) >> 19;
v10 = (unsigned __int16)v7 % 0xAu;
v11 = v10;
if ( a2 > 0x270Fu )
{
fputc((unsigned __int16)(v9 + 48), stdout);
fputc((unsigned __int16)(v11 + 48), stdout);
v3 = stdout;
v13 = (unsigned __int16)(v8 + 48);
}
else if ( v10 )
{
fputc((unsigned __int16)(v10 + 48), stdout);
v3 = stdout;
v13 = (unsigned __int16)(v8 + 48);
}
else
{
if ( !v8 )
{
if ( (_WORD)v6 )
{
fputc((unsigned __int16)(v6 + 48), stdout);
v3 = stdout;
}
v4 = (unsigned __int16)(a2 % 0xAu + 48);
return fputc(v4, v3);
}
v13 = (unsigned __int16)(v8 + 48);
}
fputc(v13, v3);
fputc((unsigned __int16)(v6 + 48), stdout);
return fputc((unsigned __int16)(a2 % 0xAu + 48), stdout);
}
return fputc(v4, v3);
}

canonical_decompiled_code:
int __fastcall func18(const char *a1, unsigned __int16 a2)
{
FILE *v3; // rsi
int v4; // edi
unsigned int v5; // ebp
unsigned int v6; // ebx
unsigned int v7; // edx
__int16 v8; // bp
unsigned int v9; // edi
__int16 v10; // dx
__int16 v11; // r12
int v13; // edi

func0(a1);
v3 = stdout;
v4 = 48;
if ( a2 )
{
v5 = a2 / 0xAu / 0xA;
v6 = a2 / 0xAu - 10 * v5;
v7 = (unsigned __int16)v5 / 0xAu;
v3 = stdout;
v8 = (unsigned __int16)v5 % 0xAu;
v9 = (52429 * v7) >> 19;
v10 = (unsigned __int16)v7 % 0xAu;
v11 = v10;
if ( a2 > 0x270Fu )
{
fputc((unsigned __int16)(v9 + 48), stdout);
fputc((unsigned __int16)(v11 + 48), stdout);
v3 = stdout;
v13 = (unsigned __int16)(v8 + 48);
}
else if ( v10 )
{
fputc((unsigned __int16)(v10 + 48), stdout);
v3 = stdout;
v13 = (unsigned __int16)(v8 + 48);
}
else
{
if ( !v8 )
{
if ( (_WORD)v6 )
{
fputc((unsigned __int16)(v6 + 48), stdout);
v3 = stdout;
}
v4 = (unsigned __int16)(a2 % 0xAu + 48);
return fputc(v4, v3);
}
v13 = (unsigned __int16)(v8 + 48);
}
fputc(v13, v3);
fputc((unsigned __int16)(v6 + 48), stdout);
return fputc((unsigned __int16)(a2 % 0xAu + 48), stdout);
}
return fputc(v4, v3);
}

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:
__int16 cc_calibrate()
{
__int16 result; // ax

result = word_54A - cc_data;
word_550 = word_54A - cc_data;
return result;
}

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

result = word_54A - cc_data;
word_550 = word_54A - 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 func1()
{
;
}

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


decompiled_code:
void cc_store_0()
{
;
}

canonical_decompiled_code:
void func2()
{
;
}

original_code: void cc_store_0(){}

canonical_original_code: void cc_store_0(){}


decompiled_code:
void cc_store_1()
{
;
}

canonical_decompiled_code:
void func3()
{
;
}

original_code: void cc_store_1(){}

canonical_original_code: void cc_store_1(){}


decompiled_code:
void cc_store_2()
{
;
}

canonical_decompiled_code:
void func4()
{
;
}

original_code: void cc_store_2(){}

canonical_original_code: void cc_store_2(){}


decompiled_code:
void cc_store_3()
{
;
}

canonical_decompiled_code:
void func5()
{
;
}

original_code: void cc_store_3(){}

canonical_original_code: void cc_store_3(){}


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

v0 = word_54E - (word_54C + word_550);
v1 = word_54A - (word_550 + cc_data);
print("cc_values:");
print_hw(" ", (unsigned __int16)cc_data);
print_hw(" ", (unsigned __int16)word_54A);
print_hw(" ", (unsigned __int16)word_54C);
print_hw(" ", (unsigned __int16)word_54E);
print_dw(" A = ", v1);
print_dw(" B = ", v0);
return print_nl();
}

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

v0 = word_54E - (word_54C + word_550);
v1 = word_54A - (word_550 + cc_data);
print("cc_values:");
print_hw(" ", (unsigned __int16)cc_data);
print_hw(" ", (unsigned __int16)word_54A);
print_hw(" ", (unsigned __int16)word_54C);
print_hw(" ", (unsigned __int16)word_54E);
print_dw(" A = ", v1);
print_dw(" B = ", v0);
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_54A - (unsigned int)(unsigned __int16)(cc_data + word_550);
}

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

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_54E - (unsigned int)(unsigned __int16)(word_54C + word_550);
}

canonical_decompiled_code:
__int64 func8()
{
return (unsigned __int16)word_54E - (unsigned int)(unsigned __int16)(word_54C + word_550);
}

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_slot_len = 1;
t_msec = 0;
t_sec = 0;
return cc_calibrate();
}

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

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

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

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

result = (unsigned __int8)t_slot_len;
t_slot = a1;
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()
{
unsigned __int16 v1; // ax
unsigned __int16 v2; // ax
unsigned __int16 v3; // ax
__int64 v4; // rsi
char v5; // al
char v6; // al
int v7; // eax
int v8; // ebx
unsigned __int8 v9; // al
__int64 v10; // [rsp+0h] [rbp-28h] BYREF
int v11; // [rsp+8h] [rbp-20h]
char v12; // [rsp+Ch] [rbp-1Ch]

scan_key(&v10, 17LL);
if ( (_DWORD)v10 != 2003789939 || BYTE4(v10) )
{
if ( (_DWORD)v10 == 1634036835 && WORD2(v10) == 114 )
{
timer_clear();
return 1LL;
}
if ( (_DWORD)v10 != 1953459315 || BYTE4(v10) )
{
if ( v10 != 0x7465675F746F6C73LL )
goto LABEL_5;
}
else
{
print_hb("top = ", (unsigned __int8)t_slot_top);
print_hb(", val = ", (unsigned __int8)t_slot);
print_nl();
if ( v10 != 0x7465675F746F6C73LL )
goto LABEL_5;
}
if ( !(_BYTE)v11 )
{
v7 = scan_uint16();
v8 = v7 - 1;
if ( (_WORD)v7 )
{
do
{
--v8;
v9 = cc_slot_get("slot get = ");
print_hb("slot get = ", v9);
print_nl();
}
while ( (_WORD)v8 != 0xFFFF );
if ( v10 == 0x7465735F746F6C73LL )
{
LABEL_16:
if ( v11 == 1886352479 && !v12 )
{
v6 = scan_uint8();
cc_slot_set_top(v6);
}
}
LABEL_6:
if ( v10 == 0x6961775F746F6C73LL && (_WORD)v11 == 116 )
{
v5 = scan_uint8();
cc_slot_wait(v5);
}
if ( v10 == 0x7365745F746F6C73LL && (_WORD)v11 == 116 )
{
cc_slot_wait(20);
cc_slot_wait(0);
cc_slot_wait(1);
v1 = cc_get_a("a = ");
print_dw("a = ", v1);
v2 = cc_get_b(", b = ");
print_dw(", b = ", v2);
cc_slot_wait(19);
cc_slot_wait(20);
cc_slot_wait(0);
v3 = cc_get_a("a = ");
print_dw("a = ", v3);
v4 = (unsigned __int16)cc_get_b(", b = ");
print_dw(", b = ", v4);
print_nl();
}
return 1LL;
}
}
LABEL_5:
if ( v10 == 0x7465735F746F6C73LL )
goto LABEL_16;
goto LABEL_6;
}
timer_show();
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)
{
int v1; // ebp

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

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

v1 = func1(a1);
return (v1 << 8) + (unsigned int)(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 v0; // ebx
unsigned __int16 v1; // di
unsigned __int8 v2; // al

v0 = 0;
print(&unk_B6);
do
{
v1 = v0++;
v2 = eerd_b(v1);
print_hb(&unk_BA, v2);
}
while ( v0 != 32 );
return print_nl();
}

canonical_decompiled_code:
__int64 func4()
{
int v0; // ebx
unsigned __int16 v1; // di
unsigned __int8 v2; // al

v0 = 0;
print(&unk_B6);
do
{
v1 = v0++;
v2 = func1(v1);
print_hb(&unk_BA, v2);
}
while ( v0 != 32 );
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)
{
char v1; // dl
int v2; // ecx
char v3; // dl

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

canonical_decompiled_code:
bool __fastcall func10(char a1)
{
char v1; // dl
int v2; // ecx
char v3; // dl

func8();
do
{
func5(v1 & a1);
func7();
func8();
}
while ( v2 != 1 );
func5(1);
func7();
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 i2c_start()
{
char v0; // dl

i2c_sclLo();
i2c_sclHi();
i2c_sdaOut(0);
return i2c_write(v0);
}

canonical_decompiled_code:
bool func11()
{
char v0; // dl

func8();
func7();
func5(0);
return func10(v0);
}

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(__int64 a1)
{
int v1; // ecx
unsigned int v2; // er8

do
{
i2c_sclHi();
i2c_sdaIn(a1, (unsigned int)a1);
i2c_sclLo();
}
while ( v1 != 1 );
i2c_sdaOut(a1);
i2c_sclHi();
i2c_sclLo();
if ( (_BYTE)a1 )
i2c_stop();
i2c_sdaOut(1);
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func13(__int64 a1)
{
int v1; // ecx
unsigned int v2; // er8

do
{
func7();
func6(a1, (unsigned int)a1);
func8();
}
while ( v1 != 1 );
func5(a1);
func7();
func8();
if ( (_BYTE)a1 )
func12();
func5(1);
return v2;
}

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; // dl

do
{
led_y_on();
led_y_off();
led_g_on();
led_g_off();
}
while ( v0 != 1 );
}

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

do
{
func0();
func2();
func1();
func3();
}
while ( v0 != 1 );
}

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; // er8

i2c_start();
i2c_stop();
return v0;
}

canonical_decompiled_code:
__int64 func16()
{
unsigned int v0; // er8

func11();
func12();
return v0;
}

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 pad_write()
{
char v0; // r9
unsigned int v1; // er8
char v2; // r9

if ( i2c_start() )
{
i2c_write(v0);
i2c_stop();
pad_last_write_data = v2;
}
else
{
i2c_stop();
}
return v1;
}

canonical_decompiled_code:
__int64 func17()
{
char v0; // r9
unsigned int v1; // er8
char v2; // r9

if ( func11() )
{
func10(v0);
func12();
pad_last_write_data = v2;
}
else
{
func12();
}
return v1;
}

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();
return i2c_read(1LL);
}

canonical_decompiled_code:
__int64 func18()
{
func11();
return func13(1LL);
}

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; // r8
__int64 result; // rax

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

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

v0 = func11();
result = 0xFFFFFFFFLL;
if ( v0 )
result = func13(1LL) & 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)
{
unsigned __int8 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)
{
unsigned __int8 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)
{
unsigned __int8 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)
{
unsigned __int8 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()
{
__int64 result; // rax
char v1; // r10

do
{
pad_remote_led_y(1);
pad_remote_led_y(0);
pad_remote_led_g(1);
result = pad_remote_led_g(0);
}
while ( v1 != 1 );
return result;
}

canonical_decompiled_code:
__int64 func22()
{
__int64 result; // rax
char v1; // r10

do
{
func20(1);
func20(0);
func21(1);
result = func21(0);
}
while ( v1 != 1 );
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(255LL);
}

canonical_decompiled_code:
__int64 func23()
{
func9();
func14();
return func17(255LL);
}

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


decompiled_code:
void __noreturn pad_autoread()
{
unsigned __int8 v0; // al
char v1; // r10
char v2; // r10

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

canonical_decompiled_code:
void __noreturn func24()
{
unsigned __int8 v0; // al
char v1; // r10
char v2; // r10

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

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