main

canonical_name: main

repo: JFreegman/Colour-Keys

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
bool v3; // bp
int v4; // er12
unsigned int i; // ebx
int result; // eax
__int128 v7[5]; // [rsp+0h] [rbp-B8h] BYREF
char s2[16]; // [rsp+50h] [rbp-68h] BYREF
__int128 v9; // [rsp+60h] [rbp-58h]
__int128 v10; // [rsp+70h] [rbp-48h]
__int128 v11; // [rsp+80h] [rbp-38h]
__int128 v12; // [rsp+90h] [rbp-28h]

if ( (unsigned int)(argc - 2) > 1 )
{
puts("Usage: [num tests] (-m to mute)");
result = -1;
}
else
{
v3 = 0;
if ( argc == 3 )
v3 = strcmp(argv[2], "-m") == 0;
v4 = atoi(argv[1]);
if ( v4 > 0 )
{
for ( i = 1; ; ++i )
{
if ( !v3 )
printf("* Test %d\n", i);
v7[0] = 0LL;
v7[1] = 0LL;
v7[2] = 0LL;
v7[3] = 0LL;
v7[4] = 0LL;
random_key((char *)v7);
if ( (unsigned int)make_keyimg(v7, "testkeyimg.tox") )
__assert_fail("make_keyimg(key_in, outpath) == 0", "keyimgtest.c", 0x2Fu, "main");
*(_OWORD *)s2 = 0LL;
v9 = 0LL;
v10 = 0LL;
v11 = 0LL;
v12 = 0LL;
if ( (unsigned int)extract_keyimg(s2, "testkeyimg.tox") )
__assert_fail("extract_keyimg(key_out, outpath) == 0", "keyimgtest.c", 0x34u, "main");
if ( !v3 )
{
printf("IN :%s\n", (const char *)v7);
printf("OUT:%s\n\n", s2);
}
if ( strcmp((const char *)v7, s2) )
__assert_fail("strcmp(key_in, key_out) == 0", "keyimgtest.c", 0x3Cu, "main");
if ( v4 == i )
break;
}
}
puts("Tests passed!");
result = 0;
}
return result;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
bool v3; // bp
int v4; // er12
unsigned int i; // ebx
int result; // eax
__int128 v7[5]; // [rsp+0h] [rbp-B8h] BYREF
char s2[16]; // [rsp+50h] [rbp-68h] BYREF
__int128 v9; // [rsp+60h] [rbp-58h]
__int128 v10; // [rsp+70h] [rbp-48h]
__int128 v11; // [rsp+80h] [rbp-38h]
__int128 v12; // [rsp+90h] [rbp-28h]

if ( (unsigned int)(argc - 2) > 1 )
{
puts("Usage: [num tests] (-m to mute)");
result = -1;
}
else
{
v3 = 0;
if ( argc == 3 )
v3 = strcmp(argv[2], "-m") == 0;
v4 = atoi(argv[1]);
if ( v4 > 0 )
{
for ( i = 1; ; ++i )
{
if ( !v3 )
printf("* Test %d\n", i);
v7[0] = 0LL;
v7[1] = 0LL;
v7[2] = 0LL;
v7[3] = 0LL;
v7[4] = 0LL;
func9((char *)v7);
if ( (unsigned int)func8(v7, "testkeyimg.tox") )
__assert_fail("make_keyimg(key_in, outpath) == 0", "keyimgtest.c", 0x2Fu, "main");
*(_OWORD *)s2 = 0LL;
v9 = 0LL;
v10 = 0LL;
v11 = 0LL;
v12 = 0LL;
if ( (unsigned int)func7(s2, "testkeyimg.tox") )
__assert_fail("extract_keyimg(key_out, outpath) == 0", "keyimgtest.c", 0x34u, "main");
if ( !v3 )
{
printf("IN :%s\n", (const char *)v7);
printf("OUT:%s\n\n", s2);
}
if ( strcmp((const char *)v7, s2) )
__assert_fail("strcmp(key_in, key_out) == 0", "keyimgtest.c", 0x3Cu, "main");
if ( v4 == i )
break;
}
}
puts("Tests passed!");
result = 0;
}
return result;
}

original_code:
int main(int argc, char *argv[])
{
    if (argc < 2 || argc > 3) {
        printf("Usage: [num tests] (-m to mute)\n");
        return -1;
    }
    _Bool mute = 0;
    if (argc == 3 && strcmp(argv[2], "-m") == 0)
        mute = 1;
    int n = atoi(argv[1]);
    int i;
    for (i = 0; i < n; ++i) {
        if (!mute)
            printf("* Test %d\n", i+1);
        const char *outpath = "testkeyimg.tox";
        char key_in[80] = {'\0'};
        random_key(key_in);
        ((void) sizeof ((make_keyimg(key_in, outpath) == 0) ? 1 : 0), __extension__ ({ if (make_keyimg(key_in, outpath) == 0) ; else __assert_fail ("make_keyimg(key_in, outpath) == 0", "keyimgtest.c", 47, __extension__ __PRETTY_FUNCTION__); }));
        char key_out[80] = {'\0'};
        ((void) sizeof ((extract_keyimg(key_out, outpath) == 0) ? 1 : 0), __extension__ ({ if (extract_keyimg(key_out, outpath) == 0) ; else __assert_fail ("extract_keyimg(key_out, outpath) == 0", "keyimgtest.c", 52, __extension__ __PRETTY_FUNCTION__); }));
        if (!mute) {
            printf("IN :%s\n", key_in);
            printf("OUT:%s\n\n", key_out);
        }
        ((void) sizeof ((strcmp(key_in, key_out) == 0) ? 1 : 0), __extension__ ({ if (strcmp(key_in, key_out) == 0) ; else __assert_fail ("strcmp(key_in, key_out) == 0", "keyimgtest.c", 60, __extension__ __PRETTY_FUNCTION__); }));
    }
    printf("Tests passed!\n");
    return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
    if (argc < 2 || argc > 3) {
        printf("Usage: [num tests] (-m to mute)\n");
        return -1;
    }
    _Bool mute = 0;
    if (argc == 3 && strcmp(argv[2], "-m") == 0)
        mute = 1;
    int n = atoi(argv[1]);
    int i;
    for (i = 0; i < n; ++i) {
        if (!mute)
            printf("* Test %d\n", i+1);
        char *outpath = "testkeyimg.tox";
        char key_in[80] = {'\0'};
        random_key(key_in);
        ((void) sizeof ((make_keyimg(key_in, outpath) == 0) ? 1 : 0), __extension__ ({ if (make_keyimg(key_in, outpath) == 0) ; else __assert_fail ("make_keyimg(key_in, outpath) == 0", "keyimgtest.c", 47, __extension__ __PRETTY_FUNCTION__); }));
        char key_out[80] = {'\0'};
        ((void) sizeof ((extract_keyimg(key_out, outpath) == 0) ? 1 : 0), __extension__ ({ if (extract_keyimg(key_out, outpath) == 0) ; else __assert_fail ("extract_keyimg(key_out, outpath) == 0", "keyimgtest.c", 52, __extension__ __PRETTY_FUNCTION__); }));
        if (!mute) {
            printf("IN :%s\n", key_in);
            printf("OUT:%s\n\n", key_out);
        }
        ((void) sizeof ((strcmp(key_in, key_out) == 0) ? 1 : 0), __extension__ ({ if (strcmp(key_in, key_out) == 0) ; else __assert_fail ("strcmp(key_in, key_out) == 0", "keyimgtest.c", 60, __extension__ __PRETTY_FUNCTION__); }));
    }
    printf("Tests passed!\n");
    return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: n int

variable_types:
outpath
char *


decompiled_code:
int __fastcall random_key(char *s)
{
char *v1; // rbp
char *v2; // rbx
int v3; // eax
char *v4; // rdi
int result; // eax

v1 = s;
v2 = s + 76;
do
{
v3 = rand();
v4 = v1++;
result = snprintf(v4, 8uLL, "%x", (unsigned int)(v3 % 16));
}
while ( v1 != v2 );
return result;
}

canonical_decompiled_code:
int __fastcall func9(char *s)
{
char *v1; // rbp
char *v2; // rbx
int v3; // eax
char *v4; // rdi
int result; // eax

v1 = s;
v2 = s + 76;
do
{
v3 = rand();
v4 = v1++;
result = snprintf(v4, 8uLL, "%x", (unsigned int)(v3 % 16));
}
while ( v1 != v2 );
return result;
}

original_code:
static void random_key(char *s)
{
    int i;
    for (i = 0; i < 76; ++i)
        snprintf(s+i, sizeof(s), "%x", rand() % 16);
}

variable_types:
s
char *

variable_types: i int

return_type: void


repo: JLLLinn/System-Programming

decompiled_code:
__int64 __fastcall compare1(_DWORD *a1, _DWORD *a2)
{
return (unsigned int)(*a1 - *a2);
}

canonical_decompiled_code:
__int64 __fastcall func7(_DWORD *a1, _DWORD *a2)
{
return (unsigned int)(*a1 - *a2);
}

original_code:
int compare1(const void * a, const void * b)
{
 return ( *(int*)a - *(int*)b );
}

canonical_original_code:
int compare1(void *a, void *b)
{
 return ( *(int *)a - *(int *)b );
}

variable_types:
a
void *

variable_types:
b
void *

return_type: int


decompiled_code:
__int64 __fastcall compare2(_DWORD *a1, _DWORD *a2)
{
return (unsigned int)(*a2 - *a1);
}

canonical_decompiled_code:
__int64 __fastcall func8(_DWORD *a1, _DWORD *a2)
{
return (unsigned int)(*a2 - *a1);
}

original_code:
int compare2(const void * a, const void * b)
{
 return ( *(int*)b - *(int*)a );
}

canonical_original_code:
int compare2(void *a, void *b)
{
 return ( *(int *)b - *(int *)a );
}


original_code:
int priqueue_offer(priqueue_t *q, void *ptr) {
 if (!q->headMin->data) {
  q->headMin->data = ptr;
  (q->size)++;
  return 0;
 } else {
  int index = 0;
  priqueue_entry_t* cur;
  if (q->comparer(ptr, q->headMin->data) < 0) {
   cur = malloc(sizeof(priqueue_entry_t));
   cur->next = q->headMin;
   q->headMin = cur;
   q->headMin->data = ptr;
   (q->size)++;
   return 0;
  }
  cur = q->headMin;
  priqueue_entry_t* temp;
  int i = 0;
  while (cur->next) {
   i++;
   if (q->comparer(ptr, cur->next->data) < 0) {
    temp = malloc(sizeof(priqueue_entry_t));
    temp->next = cur->next;
    cur->next = temp;
    temp->data = ptr;
    (q->size)++;
    return i;
   }
   cur = cur->next;
  }
  i++;
  cur->next = malloc(sizeof(priqueue_entry_t));
  cur = cur->next;
  cur->next = ((void *)0);
  cur->data = ptr;
  (q->size)++;
  return i;
 }
 return -1;
}

canonical_original_code:
int priqueue_offer(struct _priqueue_t *q, void *ptr) {
 if (!q->headMin->data) {
  q->headMin->data = ptr;
  (q->size)++;
  return 0;
 } else {
  int index = 0;
  struct _priqueue_entry_t *cur;
  if (q->comparer(ptr, q->headMin->data) < 0) {
   cur = malloc(sizeof(priqueue_entry_t));
   cur->next = q->headMin;
   q->headMin = cur;
   q->headMin->data = ptr;
   (q->size)++;
   return 0;
  }
  cur = q->headMin;
  struct _priqueue_entry_t *temp;
  int i = 0;
  while (cur->next) {
   i++;
   if (q->comparer(ptr, cur->next->data) < 0) {
    temp = malloc(sizeof(priqueue_entry_t));
    temp->next = cur->next;
    cur->next = temp;
    temp->data = ptr;
    (q->size)++;
    return i;
   }
   cur = cur->next;
  }
  i++;
  cur->next = malloc(sizeof(priqueue_entry_t));
  cur = cur->next;
  cur->next = ((void *)0);
  cur->data = ptr;
  (q->size)++;
  return i;
 }
 return -1;
}

variable_types: struct _priqueue_t { int (*comparer)(void *, void *); struct _priqueue_entry_t { struct _priqueue_entry_t *next; void *data; } *headMin; int size; } *

variable_types:
ptr
void *

variable_types: index int

user_defined_types: struct _priqueue_t { int (*comparer)(void *, void *); struct _priqueue_entry_t *headMin; int size; }


decompiled_code:
__int64 __fastcall priqueue_peek(__int64 a1)
{
return *(_QWORD *)(*(_QWORD *)(a1 + 8) + 8LL);
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1)
{
return *(_QWORD *)(*(_QWORD *)(a1 + 8) + 8LL);
}

original_code:
void *priqueue_peek(priqueue_t *q) {
 if (q->headMin->data) {
  return q->headMin->data;
 }
 return ((void *)0);
}

canonical_original_code:
void *priqueue_peek(struct _priqueue_t *q) {
 if (q->headMin->data) {
  return q->headMin->data;
 }
 return ((void *)0);
}

return_type: void *

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


original_code:
void *priqueue_poll(priqueue_t *q) {
 if (q->headMin->data) {
  void* ret = q->headMin->data;
  if (q->headMin->next) {
   priqueue_entry_t* temphead = q->headMin;
   q->headMin = q->headMin->next;
   free(temphead);
  } else {
   q->headMin->next = ((void *)0);
   q->headMin->data = ((void *)0);
  }
  (q->size)--;
  return ret;
 }
 return ((void *)0);
}

canonical_original_code:
void *priqueue_poll(struct _priqueue_t *q) {
 if (q->headMin->data) {
  void *ret = q->headMin->data;
  if (q->headMin->next) {
   struct _priqueue_entry_t *temphead = q->headMin;
   q->headMin = q->headMin->next;
   free(temphead);
  } else {
   q->headMin->next = ((void *)0);
   q->headMin->data = ((void *)0);
  }
  (q->size)--;
  return ret;
 }
 return ((void *)0);
}

variable_types:
ret
void *

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


decompiled_code:
__int64 __fastcall priqueue_size(__int64 a1)
{
return *(unsigned int *)(a1 + 16);
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 a1)
{
return *(unsigned int *)(a1 + 16);
}

original_code:
int priqueue_size(priqueue_t *q) {
 return q->size;
}

canonical_original_code:
int priqueue_size(struct _priqueue_t *q) {
 return q->size;
}


decompiled_code:
void __fastcall priqueue_destroy(__int64 a1)
{
_QWORD *v1; // rbx
void *v2; // rdi

v1 = *(_QWORD **)(a1 + 8);
while ( v1 )
{
v2 = v1;
v1 = (_QWORD *)*v1;
free(v2);
}
}

canonical_decompiled_code:
void __fastcall func13(__int64 a1)
{
_QWORD *v1; // rbx
void *v2; // rdi

v1 = *(_QWORD **)(a1 + 8);
while ( v1 )
{
v2 = v1;
v1 = (_QWORD *)*v1;
free(v2);
}
}

original_code:
void priqueue_destroy(priqueue_t *q) {
 priqueue_entry_t* cur = q->headMin;
 priqueue_entry_t* prev = q->headMin;
 while (cur) {
  prev = cur;
  cur = cur->next;
  free(prev);
 }
}

canonical_original_code:
void priqueue_destroy(struct _priqueue_t *q) {
 struct _priqueue_entry_t *cur = q->headMin;
 struct _priqueue_entry_t *prev = q->headMin;
 while (cur) {
  prev = cur;
  cur = cur->next;
  free(prev);
 }
}


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rdx
_DWORD *v4; // rbp
__int64 i; // rax
unsigned int v6; // eax
unsigned int v7; // er12
unsigned int v8; // eax
unsigned int v9; // eax
unsigned int *v10; // rax
unsigned int v11; // eax
unsigned int *v12; // rax
unsigned int v13; // eax
unsigned int *v14; // rax
unsigned int *v15; // rax
_BYTE v17[32]; // [rsp+0h] [rbp-68h] BYREF
char v18[72]; // [rsp+20h] [rbp-48h] BYREF

priqueue_init(v17, compare1, envp);
priqueue_init(v18, compare2, v3);
v4 = malloc(0x190uLL);
for ( i = 0LL; i != 100; ++i )
v4[i] = i;
priqueue_offer(v17, v4 + 12);
priqueue_offer(v17, v4 + 13);
priqueue_offer(v17, v4 + 14);
priqueue_offer(v17, v4 + 12);
priqueue_offer(v17, v4 + 12);
v6 = priqueue_size(v17);
printf("Total elements: %d (expected 5).\n", v6);
v7 = *(_DWORD *)priqueue_poll(v17);
printf("Top element: %d (expected 12).\n", v7);
v8 = priqueue_size(v17);
printf("Total elements: %d (expected 4).\n", v8);
priqueue_peek(v17);
printf("Top element: %d (expected 12).\n", v7);
v9 = priqueue_size(v17);
printf("Total elements: %d (expected 4).\n", v9);
v10 = (unsigned int *)priqueue_poll(v17);
printf("Top element: %d (expected 12).\n", *v10);
v11 = priqueue_size(v17);
printf("Total elements: %d (expected 3).\n", v11);
v12 = (unsigned int *)priqueue_poll(v17);
printf("Top element: %d (expected 12).\n", *v12);
v13 = priqueue_size(v17);
printf("Total elements: %d (expected 2).\n", v13);
priqueue_offer(v17, v4 + 10);
priqueue_offer(v17, v4 + 30);
priqueue_offer(v17, v4 + 20);
priqueue_offer(v17, v4 + 25);
priqueue_offer(v18, v4 + 10);
priqueue_offer(v18, v4 + 30);
priqueue_offer(v18, v4 + 20);
printf("Elements in order queue (expected 10 13 14 20 25 30): ");
while ( (unsigned int)priqueue_size(v17) )
{
v14 = (unsigned int *)priqueue_poll(v17);
printf("%d ", *v14);
}
putchar(10);
printf("Elements in order queue (expected 30 20 10): ");
while ( (unsigned int)priqueue_size(v18) )
{
v15 = (unsigned int *)priqueue_poll(v18);
printf("%d ", *v15);
}
putchar(10);
priqueue_destroy(v18);
priqueue_destroy(v17);
free(v4);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rdx
_DWORD *v4; // rbp
__int64 i; // rax
unsigned int v6; // eax
unsigned int v7; // er12
unsigned int v8; // eax
unsigned int v9; // eax
unsigned int *v10; // rax
unsigned int v11; // eax
unsigned int *v12; // rax
unsigned int v13; // eax
unsigned int *v14; // rax
unsigned int *v15; // rax
_BYTE v17[32]; // [rsp+0h] [rbp-68h] BYREF
char v18[72]; // [rsp+20h] [rbp-48h] BYREF

priqueue_init(v17, compare1, envp);
priqueue_init(v18, compare2, v3);
v4 = malloc(0x190uLL);
for ( i = 0LL; i != 100; ++i )
v4[i] = i;
func9(v17, v4 + 12);
func9(v17, v4 + 13);
func9(v17, v4 + 14);
func9(v17, v4 + 12);
func9(v17, v4 + 12);
v6 = func12(v17);
printf("Total elements: %d (expected 5).\n", v6);
v7 = *(_DWORD *)func11(v17);
printf("Top element: %d (expected 12).\n", v7);
v8 = func12(v17);
printf("Total elements: %d (expected 4).\n", v8);
func10(v17);
printf("Top element: %d (expected 12).\n", v7);
v9 = func12(v17);
printf("Total elements: %d (expected 4).\n", v9);
v10 = (unsigned int *)func11(v17);
printf("Top element: %d (expected 12).\n", *v10);
v11 = func12(v17);
printf("Total elements: %d (expected 3).\n", v11);
v12 = (unsigned int *)func11(v17);
printf("Top element: %d (expected 12).\n", *v12);
v13 = func12(v17);
printf("Total elements: %d (expected 2).\n", v13);
func9(v17, v4 + 10);
func9(v17, v4 + 30);
func9(v17, v4 + 20);
func9(v17, v4 + 25);
func9(v18, v4 + 10);
func9(v18, v4 + 30);
func9(v18, v4 + 20);
printf("Elements in order queue (expected 10 13 14 20 25 30): ");
while ( (unsigned int)func12(v17) )
{
v14 = (unsigned int *)func11(v17);
printf("%d ", *v14);
}
putchar(10);
printf("Elements in order queue (expected 30 20 10): ");
while ( (unsigned int)func12(v18) )
{
v15 = (unsigned int *)func11(v18);
printf("%d ", *v15);
}
putchar(10);
func13(v18);
func13(v17);
free(v4);
return 0;
}

original_code:
int main()
{
 priqueue_t q, q2;
 priqueue_init(&q, compare1);
 priqueue_init(&q2, compare2);
 int *values = malloc(100 * sizeof(int));
 int i;
 for (i = 0; i < 100; i++)
  values[i] = i;
 priqueue_offer(&q, &values[12]);
 priqueue_offer(&q, &values[13]);
 priqueue_offer(&q, &values[14]);
 priqueue_offer(&q, &values[12]);
 priqueue_offer(&q, &values[12]);
 printf("Total elements: %d (expected 5).\n", priqueue_size(&q));
 int val = *((int *)priqueue_poll(&q));
 printf("Top element: %d (expected 12).\n", val);
 printf("Total elements: %d (expected 4).\n", priqueue_size(&q));
 int val4 = *((int *)priqueue_peek(&q));
 printf("Top element: %d (expected 12).\n", val);
 printf("Total elements: %d (expected 4).\n", priqueue_size(&q));
 int val2 = *((int *)priqueue_poll(&q));
 printf("Top element: %d (expected 12).\n", val2);
 printf("Total elements: %d (expected 3).\n", priqueue_size(&q));
 int val3 = *((int *)priqueue_poll(&q));
 printf("Top element: %d (expected 12).\n", val3);
 printf("Total elements: %d (expected 2).\n", priqueue_size(&q));
 priqueue_offer(&q, &values[10]);
 priqueue_offer(&q, &values[30]);
 priqueue_offer(&q, &values[20]);
 priqueue_offer(&q, &values[25]);
 priqueue_offer(&q2, &values[10]);
 priqueue_offer(&q2, &values[30]);
 priqueue_offer(&q2, &values[20]);
 printf("Elements in order queue (expected 10 13 14 20 25 30): ");
 while ( priqueue_size(&q) )
  printf("%d ", *((int *)priqueue_poll(&q)) );
 printf("\n");
 printf("Elements in order queue (expected 30 20 10): ");
 while ( priqueue_size(&q2) )
  printf("%d ", *((int *)priqueue_poll(&q2)) );
 printf("\n");
 priqueue_destroy(&q2);
 priqueue_destroy(&q);
 free(values);
 return 0;
}

canonical_original_code:
int main()
{
 struct _priqueue_t q; struct _priqueue_t q2;
 priqueue_init(&q, compare1);
 priqueue_init(&q2, compare2);
 int *values = malloc(100 * sizeof(int));
 int i;
 for (i = 0; i < 100; i++)
  values[i] = i;
 priqueue_offer(&q, &values[12]);
 priqueue_offer(&q, &values[13]);
 priqueue_offer(&q, &values[14]);
 priqueue_offer(&q, &values[12]);
 priqueue_offer(&q, &values[12]);
 printf("Total elements: %d (expected 5).\n", priqueue_size(&q));
 int val = *((int *)priqueue_poll(&q));
 printf("Top element: %d (expected 12).\n", val);
 printf("Total elements: %d (expected 4).\n", priqueue_size(&q));
 int val4 = *((int *)priqueue_peek(&q));
 printf("Top element: %d (expected 12).\n", val);
 printf("Total elements: %d (expected 4).\n", priqueue_size(&q));
 int val2 = *((int *)priqueue_poll(&q));
 printf("Top element: %d (expected 12).\n", val2);
 printf("Total elements: %d (expected 3).\n", priqueue_size(&q));
 int val3 = *((int *)priqueue_poll(&q));
 printf("Top element: %d (expected 12).\n", val3);
 printf("Total elements: %d (expected 2).\n", priqueue_size(&q));
 priqueue_offer(&q, &values[10]);
 priqueue_offer(&q, &values[30]);
 priqueue_offer(&q, &values[20]);
 priqueue_offer(&q, &values[25]);
 priqueue_offer(&q2, &values[10]);
 priqueue_offer(&q2, &values[30]);
 priqueue_offer(&q2, &values[20]);
 printf("Elements in order queue (expected 10 13 14 20 25 30): ");
 while ( priqueue_size(&q) )
  printf("%d ", *((int *)priqueue_poll(&q)) );
 printf("\n");
 printf("Elements in order queue (expected 30 20 10): ");
 while ( priqueue_size(&q2) )
  printf("%d ", *((int *)priqueue_poll(&q2)) );
 printf("\n");
 priqueue_destroy(&q2);
 priqueue_destroy(&q);
 free(values);
 return 0;
}

variable_types: struct _priqueue_t { int (*comparer)(void *, void *); struct _priqueue_entry_t { struct _priqueue_entry_t *next; void *data; } *headMin; int size; }

variable_types:
values
int *

variable_types: val int


verify

decompiled_code:
void __fastcall verify(_BYTE *a1, char a2, __int64 a3)
{
_BYTE *v3; // rdx

v3 = &a1[a3];
while ( a1 != v3 )
{
if ( *a1++ != a2 )
{
puts("Memeory failed to contain correct value!");
exit(1);
}
}
}

canonical_decompiled_code:
void __fastcall func7(_BYTE *a1, char a2, __int64 a3)
{
_BYTE *v3; // rdx

v3 = &a1[a3];
while ( a1 != v3 )
{
if ( *a1++ != a2 )
{
puts("Memeory failed to contain correct value!");
exit(1);
}
}
}

original_code:
void verify(void *region, int c, size_t len)
{
  char *r = region;
  while (len--) if (*(r++) != (char)c) {
    printf("Memeory failed to contain correct value!\n");
    exit(1);
  }
}

canonical_original_code:
void verify(void *region, int c, unsigned long len)
{
  char *r = region;
  while (len--) if (*(r++) != (char)c) {
    printf("Memeory failed to contain correct value!\n");
    exit(1);
  }
}

variable_types:
region
void *

variable_types: c int

variable_types:
len
unsigned long

variable_types:
r
char *


overlap

decompiled_code:
_BOOL8 __fastcall overlap(unsigned __int64 a1, unsigned __int64 a2, __int64 a3)
{
_BOOL8 result; // rax

result = 0LL;
if ( a1 <= a2 )
result = a2 < a3 + a1;
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func8(unsigned __int64 a1, unsigned __int64 a2, __int64 a3)
{
_BOOL8 result; // rax

result = 0LL;
if ( a1 <= a2 )
result = a2 < a3 + a1;
return result;
}

original_code:
int overlap(void *r1, void *r2, size_t len)
{
  return (size_t)r1 <= (size_t)r2 && (size_t)r2 < (size_t)(r1 + len);
}

canonical_original_code:
int overlap(void *r1, void *r2, unsigned long len)
{
  return (unsigned long)r1 <= (unsigned long)r2 && (unsigned long)r2 < (unsigned long)(r1 + len);
}


decompiled_code:
_BOOL8 __fastcall verify_overlap2(unsigned __int64 a1, unsigned __int64 a2, __int64 a3)
{
_BOOL8 result; // rax

result = overlap(a1, a2, a3);
if ( result )
{
puts("Memory regions overlap!");
exit(1);
}
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func9(unsigned __int64 a1, unsigned __int64 a2, __int64 a3)
{
_BOOL8 result; // rax

result = func8(a1, a2, a3);
if ( result )
{
puts("Memory regions overlap!");
exit(1);
}
return result;
}

original_code:
void verify_overlap2(void *r1, void *r2, size_t len)
{
  if (overlap(r1, r2, len)) {
    printf("Memory regions overlap!\n");
    exit(1);
  }
}

canonical_original_code:
void verify_overlap2(void *r1, void *r2, unsigned long len)
{
  if (overlap(r1, r2, len)) {
    printf("Memory regions overlap!\n");
    exit(1);
  }
}


decompiled_code:
_BOOL8 __fastcall verify_overlap3(unsigned __int64 a1, unsigned __int64 a2, __int64 a3, __int64 a4)
{
__int64 v4; // rdx
unsigned __int64 v5; // r9
unsigned __int64 v6; // r10
unsigned __int64 v7; // rsi
__int64 v8; // rdx
unsigned __int64 v9; // r8
_BOOL8 result; // rax

if ( overlap(a1, a2, a4) || (v7 = v6, overlap(v5, v6, v4)) || (result = overlap(v9, v7, v8)) )
{
puts("Memory regions overlap!");
exit(1);
}
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func10(unsigned __int64 a1, unsigned __int64 a2, __int64 a3, __int64 a4)
{
__int64 v4; // rdx
unsigned __int64 v5; // r9
unsigned __int64 v6; // r10
unsigned __int64 v7; // rsi
__int64 v8; // rdx
unsigned __int64 v9; // r8
_BOOL8 result; // rax

if ( func8(a1, a2, a4) || (v7 = v6, func8(v5, v6, v4)) || (result = func8(v9, v7, v8)) )
{
puts("Memory regions overlap!");
exit(1);
}
return result;
}

original_code:
void verify_overlap3(void *r1, void *r2, void *r3, size_t len)
{
  if (overlap(r1, r2, len) || overlap(r1, r3, len) || overlap(r2, r3, len)) {
    printf("Memory regions overlap!\n");
    exit(1);
  }
}

canonical_original_code:
void verify_overlap3(void *r1, void *r2, void *r3, unsigned long len)
{
  if (overlap(r1, r2, len) || overlap(r1, r3, len) || overlap(r2, r3, len)) {
    printf("Memory regions overlap!\n");
    exit(1);
  }
}


original_code:
void queue_init(queue_t *q) {
 q->head = ((void *)0);
 q->tail = ((void *)0);
 q->size = 0;
}

canonical_original_code:
void queue_init(struct queue_t *q) {
 q->head = ((void *)0);
 q->tail = ((void *)0);
 q->size = 0;
}

variable_types: struct queue_t { struct queue_node { void *item; struct queue_node *next; } *head; struct queue_node *tail; unsigned int size; } *

user_defined_types: struct queue_t { struct queue_node *head; struct queue_node *tail; unsigned int size; }


original_code:
void *queue_remove_at(queue_t *q, int pos){
 if( pos < 0 || q->size-1 < pos)
  return ((void *)0);
 q->size--;
 struct queue_node *cur = q->head;
 struct queue_node *prev = ((void *)0);
 while(pos--){
  prev = cur;
  cur = cur->next;
 }
 if(cur == q->head){
  q->head = cur->next;
  if(q->head == ((void *)0))
   q->tail = ((void *)0);
  void *item = cur->item;
  free(cur);
  return item;
 }else if(cur == q->tail){
  q->tail = prev;
  prev->next = ((void *)0);
  void *item = cur->item;
  free(cur);
  return item;
 }else{
  prev->next = cur->next;
  void *item = cur->item;
  free(cur);
  return item;
 }
}

canonical_original_code:
void *queue_remove_at(struct queue_t *q, int pos){
 if( pos < 0 || q->size-1 < pos)
  return ((void *)0);
 q->size--;
 struct queue_node *cur = q->head;
 struct queue_node *prev = ((void *)0);
 while(pos--){
  prev = cur;
  cur = cur->next;
 }
 if(cur == q->head){
  q->head = cur->next;
  if(q->head == ((void *)0))
   q->tail = ((void *)0);
  void *item = cur->item;
  free(cur);
  return item;
 }else if(cur == q->tail){
  q->tail = prev;
  prev->next = ((void *)0);
  void *item = cur->item;
  free(cur);
  return item;
 }else{
  prev->next = cur->next;
  void *item = cur->item;
  free(cur);
  return item;
 }
}

variable_types: pos int

variable_types: struct queue_node { void *item; struct queue_node *next; } *

variable_types:
item
void *


decompiled_code:
__int64 __fastcall queue_size(__int64 a1)
{
return *(unsigned int *)(a1 + 16);
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
return *(unsigned int *)(a1 + 16);
}

original_code:
unsigned int queue_size(queue_t *q) {
 return q->size;
}

canonical_original_code:
unsigned int queue_size(struct queue_t *q) {
 return q->size;
}

return_type: unsigned int

user_defined_types: struct queue_node { void *item; struct queue_node *next; }


decompiled_code:
__int64 __fastcall queue_dequeue(__int64 a1)
{
__int64 v1; // r12
__int64 *v3; // rdi
__int64 v4; // rax

v1 = 0LL;
if ( (unsigned int)queue_size(a1) )
{
v3 = *(__int64 **)a1;
v4 = v3[1];
--*(_DWORD *)(a1 + 16);
v1 = *v3;
*(_QWORD *)a1 = v4;
free(v3);
if ( !(unsigned int)queue_size(a1) )
{
*(_QWORD *)a1 = 0LL;
*(_QWORD *)(a1 + 8) = 0LL;
}
}
return v1;
}

original_code:
void *queue_dequeue(queue_t *q) {
 struct queue_node *front;
 void *item;
 if(queue_size(q) == 0) {
  return ((void *)0);
 }
 front = q->head;
 q->head = q->head->next;
 q->size--;
 item = front->item;
 free(front);
 if(queue_size(q) == 0) {
  q->head = ((void *)0);
  q->tail = ((void *)0);
 }
 return item;
}

canonical_original_code:
void *queue_dequeue(struct queue_t *q) {
 struct queue_node *front;
 void *item;
 if(queue_size(q) == 0) {
  return ((void *)0);
 }
 front = q->head;
 q->head = q->head->next;
 q->size--;
 item = front->item;
 free(front);
 if(queue_size(q) == 0) {
  q->head = ((void *)0);
  q->tail = ((void *)0);
 }
 return item;
}


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

while ( 1 )
{
result = queue_size(a1);
if ( !(_DWORD)result )
break;
queue_dequeue(a1);
}
return result;
}

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

while ( 1 )
{
result = func3(a1);
if ( !(_DWORD)result )
break;
func4(a1);
}
return result;
}

original_code:
void queue_destroy(queue_t *q) {
 while(queue_size(q) > 0) {
  queue_dequeue(q);
 }
}

canonical_original_code:
void queue_destroy(struct queue_t *q) {
 while(queue_size(q) > 0) {
  queue_dequeue(q);
 }
}


decompiled_code:
__int64 __fastcall queue_enqueue(__int64 a1, __int64 a2)
{
_QWORD *v2; // rax
__int64 result; // rax
__int64 v4; // rdx

v2 = malloc(0x10uLL);
*v2 = a2;
v2[1] = 0LL;
result = queue_size(a1);
if ( (_DWORD)result )
{
result = *(_QWORD *)(a1 + 8);
*(_QWORD *)(result + 8) = v4;
++*(_DWORD *)(a1 + 16);
}
else
{
++*(_DWORD *)(a1 + 16);
*(_QWORD *)a1 = v4;
}
*(_QWORD *)(a1 + 8) = v4;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, __int64 a2)
{
_QWORD *v2; // rax
__int64 result; // rax
__int64 v4; // rdx

v2 = malloc(0x10uLL);
*v2 = a2;
v2[1] = 0LL;
result = func3(a1);
if ( (_DWORD)result )
{
result = *(_QWORD *)(a1 + 8);
*(_QWORD *)(result + 8) = v4;
++*(_DWORD *)(a1 + 16);
}
else
{
++*(_DWORD *)(a1 + 16);
*(_QWORD *)a1 = v4;
}
*(_QWORD *)(a1 + 8) = v4;
return result;
}

original_code:
void queue_enqueue(queue_t *q, void *item) {
 struct queue_node *back = malloc(sizeof(struct queue_node));
 back->item = item;
 back->next = ((void *)0);
 if(queue_size(q) == 0) {
  q->head = back;
 } else {
  q->tail->next = back;
 }
 q->tail = back;
 q->size++;
}

canonical_original_code:
void queue_enqueue(struct queue_t *q, void *item) {
 struct queue_node *back = malloc(sizeof(struct queue_node));
 back->item = item;
 back->next = ((void *)0);
 if(queue_size(q) == 0) {
  q->head = back;
 } else {
  q->tail->next = back;
 }
 q->tail = back;
 q->size++;
}


decompiled_code:
__int64 __fastcall queue_iterate(_QWORD *a1, __int64 (__fastcall *a2)(_QWORD, __int64))
{
__int64 result; // rax
__int64 v3; // rdx
_QWORD *v4; // rbx
__int64 v5; // r12

result = queue_size((__int64)a1);
if ( (_DWORD)result )
{
v4 = (_QWORD *)*a1;
v5 = v3;
if ( *a1 )
{
do
{
result = a2(*v4, v5);
v4 = (_QWORD *)v4[1];
}
while ( v4 );
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(_QWORD *a1, __int64 (__fastcall *a2)(_QWORD, __int64))
{
__int64 result; // rax
__int64 v3; // rdx
_QWORD *v4; // rbx
__int64 v5; // r12

result = func3((__int64)a1);
if ( (_DWORD)result )
{
v4 = (_QWORD *)*a1;
v5 = v3;
if ( *a1 )
{
do
{
result = a2(*v4, v5);
v4 = (_QWORD *)v4[1];
}
while ( v4 );
}
}
return result;
}

original_code:
void queue_iterate(queue_t *q, void (*iter_func)(void *, void *), void *arg) {
 struct queue_node *node;
 if(queue_size(q) == 0) {
  return;
 }
 node = q->head;
 while(node != ((void *)0)) {
  iter_func(node->item, arg);
  node = node->next;
 }
}

canonical_original_code:
void queue_iterate(struct queue_t *q, void (*iter_func)(void *, void *), void *arg) {
 struct queue_node *node;
 if(queue_size(q) == 0) {
  return;
 }
 node = q->head;
 while(node != ((void *)0)) {
  iter_func(node->item, arg);
  node = node->next;
 }
}

variable_types:
arg
void *


decompiled_code:
// attributes: thunk
void free_adapter(void *ptr)
{
free(ptr);
}

canonical_decompiled_code:
void func1(void *ptr)
{
free(ptr);
}

original_code:
static void free_adapter(void *arg, void *trash){
 free(arg);
}

variable_types:
trash
void *


decompiled_code:
__int64 __fastcall rule_finished(char *s1)
{
unsigned int v1; // ebx
const char *v2; // rax

v1 = 0;
pthread_mutex_lock(&finish_q_mutex);
while ( 1 )
{
if ( (unsigned int)queue_size(finished_rule_q) <= v1 )
{
pthread_mutex_unlock(&finish_q_mutex);
return 0LL;
}
v2 = (const char *)queue_at(finished_rule_q, v1);
if ( !strcmp(s1, v2) )
break;
++v1;
}
pthread_mutex_unlock(&finish_q_mutex);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(char *s1)
{
unsigned int v1; // ebx
const char *v2; // rax

v1 = 0;
pthread_mutex_lock(&finish_q_mutex);
while ( 1 )
{
if ( (unsigned int)queue_size(finished_rule_q) <= v1 )
{
pthread_mutex_unlock(&finish_q_mutex);
return 0LL;
}
v2 = (const char *)queue_at(finished_rule_q, v1);
if ( !strcmp(s1, v2) )
break;
++v1;
}
pthread_mutex_unlock(&finish_q_mutex);
return 1LL;
}

original_code:
int rule_finished(char* rule_char_p) {
 int i = 0;
 pthread_mutex_lock(&finish_q_mutex);
 for (i = 0; i < queue_size(finished_rule_q); i++) {
  if (strcmp(rule_char_p, (char*) queue_at(finished_rule_q, i)) == 0) {
   pthread_mutex_unlock(&finish_q_mutex);
   return 1;
  }
 }
 pthread_mutex_unlock(&finish_q_mutex);
 return 0;
}

canonical_original_code:
int rule_finished(char *rule_char_p) {
 int i = 0;
 pthread_mutex_lock(&finish_q_mutex);
 for (i = 0; i < queue_size(finished_rule_q); i++) {
  if (strcmp(rule_char_p, (char *) queue_at(finished_rule_q, i)) == 0) {
   pthread_mutex_unlock(&finish_q_mutex);
   return 1;
  }
 }
 pthread_mutex_unlock(&finish_q_mutex);
 return 0;
}

variable_types: i int


main

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

OpenErrorFile(argc, argv, envp);
while ( 1 )
{
v3 = yylex();
if ( !v3 )
break;
PrintToken_constprop_0(v3, yylval);
}
CloseErrorFile(0LL);
return 0;
}

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

OpenErrorFile(argc, argv, envp);
while ( 1 )
{
v3 = yylex();
if ( !v3 )
break;
func0(v3, yylval);
}
CloseErrorFile(0LL);
return 0;
}

original_code:
int main()
{
    TokenType token;
    OpenErrorFile();
    while ((token = (TokenType)yylex()) != 0)
        PrintToken(token, yytext, yylval);
    CloseErrorFile();
    return 0;
}

canonical_original_code:
int main()
{
    enum TokenType token;
    OpenErrorFile();
    while ((token = (enum TokenType)yylex()) != 0)
        PrintToken(token, yytext, yylval);
    CloseErrorFile();
    return 0;
}

variable_types: enum TokenType { T_OpenSign=256, T_CloseSign=257, T_Elements=258, T_Atributtes=259, T_Values=260, T_Text=261, T_Minus=262, T_Equal=263, T_Colon=264, T_Slash=265, T_QuestionMark=266, T_ExclamationMark=267, T_XML=268, T_PublicIdentifier=269, T_DOCTYPE=270, T_NumTokenTypes=271 }


agregarListaAtributos

decompiled_code:
void __fastcall agregarListaAtributos(__int64 a1, __int64 a2)
{
*(_QWORD *)(a1 + 8) = a2;
}

canonical_decompiled_code:
void __fastcall func2(__int64 a1, __int64 a2)
{
*(_QWORD *)(a1 + 8) = a2;
}

original_code:
void agregarListaAtributos(Nodo_t* nodo, ListaAtributos_t* listaAtributos){
 nodo->listaAtributos= listaAtributos;
}

canonical_original_code:
void agregarListaAtributos(struct Nodo *nodo, struct ListaAtributos *listaAtributos){
 nodo->listaAtributos= listaAtributos;
}

variable_types: struct Nodo { char *nombreNodo; struct ListaAtributos { struct Atributo { char *nombreAtributo; char *valorAtributo; struct Atributo *siguiente; int filaAtributo; int columnaAtributo; int filaValor; int columnaValor; } *primerAtributo; } *listaAtributos; struct ListaTextos { struct Texto { char *texto; struct Texto *siguiente; int fila; int columna; } *primerTexto; } *listaTextos; struct Nodo *padre; struct Nodo *siguiente; struct ListaHijos { struct Nodo *primerHijo; } *listaHijos; } *

variable_types:
listaAtributos
struct ListaAtributos *

user_defined_types: struct Nodo { char *nombreNodo; struct ListaAtributos *listaAtributos; struct ListaTextos *listaTextos; struct Nodo *padre; struct Nodo *siguiente; struct ListaHijos *listaHijos; }

user_defined_types: struct ListaAtributos { struct Atributo *primerAtributo; }

user_defined_types: struct ListaTextos { struct Texto *primerTexto; }


crearListaAtributos

decompiled_code:
void *crearListaAtributos()
{
return malloc(8uLL);
}

canonical_decompiled_code:
void *func3()
{
return malloc(8uLL);
}

original_code:
ListaAtributos_t* crearListaAtributos(){
 ListaAtributos_t* listaAtributos = malloc(sizeof(ListaAtributos_t));
 return listaAtributos;
}

canonical_original_code:
struct ListaAtributos *crearListaAtributos(){
 struct ListaAtributos *listaAtributos = malloc(sizeof(ListaAtributos_t));
 return listaAtributos;
}

variable_types: struct ListaAtributos { struct Atributo { char *nombreAtributo; char *valorAtributo; struct Atributo *siguiente; int filaAtributo; int columnaAtributo; int filaValor; int columnaValor; } *primerAtributo; } *


agregarListaTextos

decompiled_code:
__int64 __fastcall agregarListaTextos(__int64 a1, __int64 *a2)
{
__int64 result; // rax
__int64 v3; // rdx

result = **(_QWORD **)(a1 + 16);
if ( result )
{
do
{
v3 = result;
result = *(_QWORD *)(result + 8);
}
while ( result );
result = *a2;
*(_QWORD *)(v3 + 8) = *a2;
}
else
{
*(_QWORD *)(a1 + 16) = a2;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, __int64 *a2)
{
__int64 result; // rax
__int64 v3; // rdx

result = **(_QWORD **)(a1 + 16);
if ( result )
{
do
{
v3 = result;
result = *(_QWORD *)(result + 8);
}
while ( result );
result = *a2;
*(_QWORD *)(v3 + 8) = *a2;
}
else
{
*(_QWORD *)(a1 + 16) = a2;
}
return result;
}

original_code:
void agregarListaTextos(Nodo_t* nodo, ListaTextos_t* listaTextos){
 Texto_t* tmpTexto = nodo->listaTextos->primerTexto;
 if(tmpTexto!=((void *)0)){
  while(tmpTexto->siguiente!=((void *)0)){
   tmpTexto= tmpTexto->siguiente;
  }
  tmpTexto->siguiente= listaTextos->primerTexto;
 }
 else{
  nodo->listaTextos= listaTextos;
 }
}

canonical_original_code:
void agregarListaTextos(struct Nodo *nodo, struct ListaTextos *listaTextos){
 struct Texto *tmpTexto = nodo->listaTextos->primerTexto;
 if(tmpTexto!=((void *)0)){
  while(tmpTexto->siguiente!=((void *)0)){
   tmpTexto= tmpTexto->siguiente;
  }
  tmpTexto->siguiente= listaTextos->primerTexto;
 }
 else{
  nodo->listaTextos= listaTextos;
 }
}

variable_types:
listaTextos
struct ListaTextos *

variable_types: struct Texto { char *texto; struct Texto *siguiente; int fila; int columna; } *

user_defined_types: struct ListaHijos { struct Nodo *primerHijo; }

user_defined_types: struct Atributo { char *nombreAtributo; char *valorAtributo; struct Atributo *siguiente; int filaAtributo; int columnaAtributo; int filaValor; int columnaValor; }


crearListaTextos

decompiled_code:
void *crearListaTextos()
{
return crearListaAtributos();
}

canonical_decompiled_code:
void *func6()
{
return func3();
}

original_code:
ListaTextos_t* crearListaTextos(){
 ListaTextos_t* listaTextos = malloc(sizeof(ListaTextos_t));
 return listaTextos;
}

canonical_original_code:
struct ListaTextos *crearListaTextos(){
 struct ListaTextos *listaTextos = malloc(sizeof(ListaTextos_t));
 return listaTextos;
}

variable_types: struct ListaTextos { struct Texto { char *texto; struct Texto *siguiente; int fila; int columna; } *primerTexto; } *


printArregloEntero

decompiled_code:
int __fastcall printArregloEntero(unsigned int *a1, int a2)
{
__int64 v2; // rbp
unsigned int *v3; // rbx
__int64 v4; // rsi
int result; // eax

if ( a2 )
{
v2 = (__int64)&a1[a2 - 1 + 1];
v3 = a1;
do
{
v4 = *v3++;
result = printf("\x1B[34m%i.\x1B[m", v4);
}
while ( v3 != (unsigned int *)v2 );
}
return result;
}

canonical_decompiled_code:
int __fastcall func7(unsigned int *a1, int a2)
{
__int64 v2; // rbp
unsigned int *v3; // rbx
__int64 v4; // rsi
int result; // eax

if ( a2 )
{
v2 = (__int64)&a1[a2 - 1 + 1];
v3 = a1;
do
{
v4 = *v3++;
result = printf("\x1B[34m%i.\x1B[m", v4);
}
while ( v3 != (unsigned int *)v2 );
}
return result;
}

original_code:
void printArregloEntero(int numero[30], int profundidad ){
 int i=0;
 while(profundidad--){
  printf("\e[34m" "%i.""\e[m",numero[i]);
  i++;
 }
}

canonical_original_code:
void printArregloEntero(int numero[30], int profundidad){
 int i = 0;
 while(profundidad--){
  printf("\e[34m" "%i.""\e[m",numero[i]);
  i++;
 }
}

variable_types:
numero
int [30]

variable_types: profundidad int


printTabs

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

if ( a1 )
{
v1 = a1;
do
{
result = printf(" ");
--v1;
}
while ( v1 );
}
return result;
}

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

if ( a1 )
{
v1 = a1;
do
{
result = printf(" ");
--v1;
}
while ( v1 );
}
return result;
}

original_code:
void printTabs(int cantidad){
 while(cantidad--){
  printf("    ");
 }
}

variable_types: cantidad int


imprimirDoctype

decompiled_code:
int __fastcall imprimirDoctype(const char **a1)
{
return printf(
" \x1B[34m1.\x1B[31m Doctype\x1B[32m valor 1=\x1B[33m%s \x1B[32mvalor 2 =\x1B[33m %s\n ",
*a1,
a1[1]);
}

canonical_decompiled_code:
int __fastcall func9(const char **a1)
{
return printf(
" \x1B[34m1.\x1B[31m Doctype\x1B[32m valor 1=\x1B[33m%s \x1B[32mvalor 2 =\x1B[33m %s\n ",
*a1,
a1[1]);
}

original_code:
void imprimirDoctype(DocType_t* doctype){
 printf("     ""\e[34m""1." "\e[31m"" Doctype""\e[32m" " valor 1=""\e[33m" "%s ""\e[32m""valor 2 =""\e[33m" " %s\n ",doctype->valor1, doctype->valor2);
}

canonical_original_code:
void imprimirDoctype(struct DocType *doctype){
 printf("     ""\e[34m""1." "\e[31m"" Doctype""\e[32m" " valor 1=""\e[33m" "%s ""\e[32m""valor 2 =""\e[33m" " %s\n ",doctype->valor1, doctype->valor2);
}

variable_types: struct DocType { char *valor1; char *valor2; } *


main

repo: JacksonZhangkun/coding

decompiled_code:
// local variable allocation has failed, the output may be wrong!
int __cdecl main(int argc, const char **argv, const char **envp)
{
FILE *v3; // rbx
const char **v5; // rbp
_BYTE v6[1048]; // [rsp+0h] [rbp-418h] BYREF

v3 = (FILE *)stdin;
if ( argc != 1 )
{
*(_QWORD *)&argc = argv[1];
v5 = argv;
argv = (const char **)"r";
v3 = fopen(*(const char **)&argc, "r");
if ( !v3 )
{
fprintf(stderr, "%s:%s cannot open.\n", *v5, v5[1]);
exit(1);
}
}
word_initialize(*(_QWORD *)&argc, argv, envp);
while ( (unsigned int)get_word(v6, 1024LL, v3) != -1 )
add_word(v6);
dump_word(stdout);
word_finalize();
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
FILE *v3; // rbx
const char **v5; // rbp
_BYTE v6[1048]; // [rsp+0h] [rbp-418h] BYREF

v3 = (FILE *)stdin;
if ( argc != 1 )
{
*(_QWORD *)&argc = argv[1];
v5 = argv;
argv = (const char **)"r";
v3 = fopen(*(const char **)&argc, "r");
if ( !v3 )
{
fprintf(stderr, "%s:%s cannot open.\n", *v5, v5[1]);
exit(1);
}
}
func10(*(_QWORD *)&argc, argv, envp);
while ( (unsigned int)func13(v6, 1024LL, v3) != -1 )
func9(v6);
func11(stdout);
func12();
return 0;
}

original_code:
int main()
{
    char **line;
    ReadLineStatus status = READ_LINE_SUCCESS;
    status = read_line(stdin, line);
    printf("%s", *line);
    return 0;
}

canonical_original_code:
int main()
{
    char **line;
    enum ReadLineStatus status = READ_LINE_SUCCESS;
    status = read_line(stdin, line);
    printf("%s", *line);
    return 0;
}

variable_types:
line
char **

variable_types: enum ReadLineStatus { READ_LINE_SUCCESS=0, READ_LINE_EOF=1, READ_LINE_OUT_OF_MEMORY=2 }


decompiled_code:
unsigned __int64 __fastcall shift_array(int a1)
{
int v1; // ebx
unsigned __int64 result; // rax

v1 = num_of_word;
result = (unsigned int)(num_of_word - 1);
if ( (int)result > a1 )
result = (unsigned __int64)memmove(
(char *)&word_array + 16LL * num_of_word - 16LL * (unsigned int)(num_of_word - a1 - 2),
(char *)&unk_4040D0 + 16LL * num_of_word - 16LL * (unsigned int)(num_of_word - a1 - 2),
16 * ((unsigned int)(num_of_word - a1 - 2) + 1LL));
num_of_word = v1 + 1;
return result;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func7(int a1)
{
int v1; // ebx
unsigned __int64 result; // rax

v1 = num_of_word;
result = (unsigned int)(num_of_word - 1);
if ( (int)result > a1 )
result = (unsigned __int64)memmove(
(char *)&word_array + 16LL * num_of_word - 16LL * (unsigned int)(num_of_word - a1 - 2),
(char *)&unk_4040D0 + 16LL * num_of_word - 16LL * (unsigned int)(num_of_word - a1 - 2),
16 * ((unsigned int)(num_of_word - a1 - 2) + 1LL));
num_of_word = v1 + 1;
return result;
}

original_code:
static void shift_array(int index){
    int src;
    for (src = num_of_word - 1; src > index; src--)
    {
 word_array[src + 1] = word_array[src];
    }
    num_of_word++;
}

variable_types: index int

variable_types: src int


decompiled_code:
void *__fastcall my_strdup(void *src)
{
size_t v1; // r12
void *v2; // rax

v1 = strlen((const char *)src) + 1;
v2 = malloc(v1);
return memcpy(v2, src, v1);
}

canonical_decompiled_code:
void *__fastcall func8(void *src)
{
size_t v1; // r12
void *v2; // rax

v1 = strlen((const char *)src) + 1;
v2 = malloc(v1);
return memcpy(v2, src, v1);
}

original_code:
static char *my_strdup(char *src)
{
    char *dest;
    dest = malloc(sizeof(char) * (strlen(src) + 1));
    strcpy(dest, src);
    return dest;
}

variable_types:
src
char *

variable_types:
dest
char *

return_type: char *


decompiled_code:
int __fastcall add_word(void *src)
{
__int64 v1; // r12
__int64 v2; // rbx
int v3; // ebp
void *v4; // rax
unsigned __int64 v5; // rbp

v1 = num_of_word;
if ( num_of_word <= 0 )
{
v3 = 0;
LABEL_8:
shift_array(v3);
v5 = 16LL * v3;
v4 = my_strdup(src);
dword_4040E8[v5 / 4] = 1;
word_array[v5 / 8] = (__int64)v4;
return (int)v4;
}
v2 = 0LL;
while ( 1 )
{
v3 = v2;
LODWORD(v4) = strcmp((const char *)word_array[2 * v2], (const char *)src);
if ( (int)v4 >= 0 )
break;
v3 = ++v2;
if ( v1 == v2 )
goto LABEL_8;
}
if ( (_DWORD)v4 )
goto LABEL_8;
++dword_4040E8[4 * (int)v2];
return (int)v4;
}

canonical_decompiled_code:
int __fastcall func9(void *src)
{
__int64 v1; // r12
__int64 v2; // rbx
int v3; // ebp
void *v4; // rax
unsigned __int64 v5; // rbp

v1 = num_of_word;
if ( num_of_word <= 0 )
{
v3 = 0;
LABEL_8:
func7(v3);
v5 = 16LL * v3;
v4 = func8(src);
dword_4040E8[v5 / 4] = 1;
word_array[v5 / 8] = (__int64)v4;
return (int)v4;
}
v2 = 0LL;
while ( 1 )
{
v3 = v2;
LODWORD(v4) = strcmp((const char *)word_array[2 * v2], (const char *)src);
if ( (int)v4 >= 0 )
break;
v3 = ++v2;
if ( v1 == v2 )
goto LABEL_8;
}
if ( (_DWORD)v4 )
goto LABEL_8;
++dword_4040E8[4 * (int)v2];
return (int)v4;
}

original_code:
void add_word(char *word)
{
    int i;
    int result;
    for (i = 0; i < num_of_word; i++){
 result = strcmp(word_array[i].name, word);
 if (result >= 0)
     break;
    }
    if (num_of_word != 0 && result == 0)
 word_array[i].count++;
    else
    {
 shift_array(i);
 word_array[i].name = my_strdup(word);
 word_array[i].count = 1;
    }
}

variable_types:
word
char *

variable_types: i int

variable_types: result int


decompiled_code:
void word_initialize()
{
num_of_word = 0;
}

canonical_decompiled_code:
void func10()
{
num_of_word = 0;
}

original_code:
void word_initialize(void){
    num_of_word = 0;
}

canonical_original_code:
void word_initialize(){
    num_of_word = 0;
}


decompiled_code:
void word_finalize()
{
__int64 v0; // rbx
__int64 v1; // rax

if ( num_of_word <= 0 )
{
num_of_word = 0;
}
else
{
v0 = 0LL;
do
{
v1 = v0++;
free((void *)word_array[2 * v1]);
}
while ( num_of_word > (int)v0 );
num_of_word = 0;
}
}

canonical_decompiled_code:
void func12()
{
__int64 v0; // rbx
__int64 v1; // rax

if ( num_of_word <= 0 )
{
num_of_word = 0;
}
else
{
v0 = 0LL;
do
{
v1 = v0++;
free((void *)word_array[2 * v1]);
}
while ( num_of_word > (int)v0 );
num_of_word = 0;
}
}

original_code:
void word_finalize(void)
{
    int i;
    for (i = 0; i < num_of_word; i++)
    {
 free(word_array[i].name);
    }
    num_of_word = 0;
}

canonical_original_code:
void word_finalize()
{
    int i;
    for (i = 0; i < num_of_word; i++)
    {
 free(word_array[i].name);
    }
    num_of_word = 0;
}


decompiled_code:
__int64 __fastcall get_word_count(char *s1)
{
int v1; // er12
int v2; // er13
int v3; // ebx
__int64 *v4; // r14
int v5; // eax

v1 = num_of_word - 1;
if ( num_of_word - 1 > 0 )
return 0LL;
v2 = 0;
while ( 1 )
{
while ( 1 )
{
v3 = (v1 + v2) / 2;
v4 = &word_array[2 * v3];
v5 = strcmp(s1, (const char *)*v4);
if ( v5 <= 0 )
break;
v2 = v3 + 1;
if ( v1 > v3 + 1 )
return 0LL;
}
if ( !v5 )
break;
v1 = v3 - 1;
if ( v3 - 1 > v2 )
return 0LL;
}
return *((unsigned int *)v4 + 2);
}

canonical_decompiled_code:
__int64 __fastcall func14(char *s1)
{
int v1; // er12
int v2; // er13
int v3; // ebx
__int64 *v4; // r14
int v5; // eax

v1 = num_of_word - 1;
if ( num_of_word - 1 > 0 )
return 0LL;
v2 = 0;
while ( 1 )
{
while ( 1 )
{
v3 = (v1 + v2) / 2;
v4 = &word_array[2 * v3];
v5 = strcmp(s1, (const char *)*v4);
if ( v5 <= 0 )
break;
v2 = v3 + 1;
if ( v1 > v3 + 1 )
return 0LL;
}
if ( !v5 )
break;
v1 = v3 - 1;
if ( v3 - 1 > v2 )
return 0LL;
}
return *((unsigned int *)v4 + 2);
}

original_code:
int get_word_count(char *word)
{
    int left = 0;
    int right = num_of_word - 1;
    int mid;
    int result;
    while (left >= right)
    {
 mid = (left + right) / 2;
 result = strcmp(word, word_array[mid].name);
 if (result > 0)
     left = mid + 1;
 else if (result < 0)
     right = mid - 1;
 else
     return word_array[mid].count;
    }
    return 0;
}

variable_types: left int

variable_types: right int

variable_types: mid int


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
read_line(_bss_start);
printf("%s", MEMORY[0]);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
func9(_bss_start);
printf("%s", MEMORY[0]);
return 0;
}

user_defined_types: enum ReadLineStatus { READ_LINE_SUCCESS=0, READ_LINE_EOF=1, READ_LINE_OUT_OF_MEMORY=2 }


decompiled_code:
__int64 __fastcall add_character(char a1)
{
int v1; // ebx
char *v3; // rdi
int v5; // er12
char *v6; // rax

v1 = st_current_used_size;
if ( st_current_buffer_size < st_current_used_size )
__assert_fail("st_current_buffer_size >= st_current_used_size", "read_line.c", 0x12u, "add_character");
v3 = st_line_buffer;
if ( st_current_buffer_size != st_current_used_size )
goto LABEL_3;
v5 = st_current_used_size + 256;
v6 = (char *)realloc(st_line_buffer, st_current_used_size + 256);
v3 = v6;
if ( v6 )
{
st_line_buffer = v6;
st_current_buffer_size = v5;
LABEL_3:
st_current_used_size = v1 + 1;
v3[v1] = a1;
return 0LL;
}
return 2LL;
}

canonical_decompiled_code:
__int64 __fastcall func7(char a1)
{
int v1; // ebx
char *v3; // rdi
int v5; // er12
char *v6; // rax

v1 = st_current_used_size;
if ( st_current_buffer_size < st_current_used_size )
__assert_fail("st_current_buffer_size >= st_current_used_size", "read_line.c", 0x12u, "add_character");
v3 = st_line_buffer;
if ( st_current_buffer_size != st_current_used_size )
goto LABEL_3;
v5 = st_current_used_size + 256;
v6 = (char *)realloc(st_line_buffer, st_current_used_size + 256);
v3 = v6;
if ( v6 )
{
st_line_buffer = v6;
st_current_buffer_size = v5;
LABEL_3:
st_current_used_size = v1 + 1;
v3[v1] = a1;
return 0LL;
}
return 2LL;
}

original_code:
static ReadLineStatus
add_character(int ch)
{
    ((void) sizeof ((st_current_buffer_size >= st_current_used_size) ? 1 : 0), __extension__ ({ if (st_current_buffer_size >= st_current_used_size) ; else __assert_fail ("st_current_buffer_size >= st_current_used_size", "read_line.c", 18, __extension__ __PRETTY_FUNCTION__); }));
    if (st_current_buffer_size == st_current_used_size)
    {
 char *temp;
 temp = realloc(st_line_buffer, (st_current_buffer_size + (256)) * sizeof(char));
 if (temp == ((void *)0))
 {
     return READ_LINE_OUT_OF_MEMORY;
 }
 st_line_buffer = temp;
 st_current_buffer_size += (256);
    }
    st_line_buffer[st_current_used_size] = ch;
    st_current_used_size++;
    return READ_LINE_SUCCESS;
}

canonical_original_code:
static enum ReadLineStatus add_character(int ch)
{
    ((void) sizeof ((st_current_buffer_size >= st_current_used_size) ? 1 : 0), __extension__ ({ if (st_current_buffer_size >= st_current_used_size) ; else __assert_fail ("st_current_buffer_size >= st_current_used_size", "read_line.c", 18, __extension__ __PRETTY_FUNCTION__); }));
    if (st_current_buffer_size == st_current_used_size)
    {
 char *temp;
 temp = realloc(st_line_buffer, (st_current_buffer_size + (256)) * sizeof(char));
 if (temp == ((void *)0))
 {
     return READ_LINE_OUT_OF_MEMORY;
 }
 st_line_buffer = temp;
 st_current_buffer_size += (256);
    }
    st_line_buffer[st_current_used_size] = ch;
    st_current_used_size++;
    return READ_LINE_SUCCESS;
}

variable_types: ch int

variable_types:
temp
char *

return_type: enum ReadLineStatus { READ_LINE_SUCCESS=0, READ_LINE_EOF=1, READ_LINE_OUT_OF_MEMORY=2 }


decompiled_code:
void free_buffer()
{
free(st_line_buffer);
st_line_buffer = 0LL;
st_current_buffer_size = 0;
st_current_used_size = 0;
}

canonical_decompiled_code:
void func8()
{
free(st_line_buffer);
st_line_buffer = 0LL;
st_current_buffer_size = 0;
st_current_used_size = 0;
}

original_code:
void free_buffer(void)
{
    free(st_line_buffer);
    st_line_buffer = ((void *)0);
    st_current_buffer_size = 0;
    st_current_used_size = 0;
}

canonical_original_code:
void free_buffer()
{
    free(st_line_buffer);
    st_line_buffer = ((void *)0);
    st_current_buffer_size = 0;
    st_current_used_size = 0;
}


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
_BYTE v4[88]; // [rsp+0h] [rbp-58h] BYREF

init_database(v4, 10LL, envp);
print_database(v4, 10LL);
sort(v4, 10LL, comp_employee, swap_employee);
print_database(v4, 10LL);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
_BYTE v4[88]; // [rsp+0h] [rbp-58h] BYREF

func8(v4, 10LL, envp);
func9(v4, 10LL);
func10(v4, 10LL, comp_employee, swap_employee);
func9(v4, 10LL);
return 0;
}

original_code:
int main(int argc, char *argv[]) {
    const int no_employees = 10;
    Database people;
    init_database (people, no_employees);
    print_database(people, no_employees);
    sort((int**)people, no_employees, comp_employee, swap_employee);
    print_database(people, no_employees);
    return 0;
}

canonical_original_code:
int main(int argc, char *argv[]) {
    int no_employees = 10;
    struct emp_struct *people[10];
    init_database (people, no_employees);
    print_database(people, no_employees);
    sort((int **)people, no_employees, comp_employee, swap_employee);
    print_database(people, no_employees);
    return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: struct emp_struct { char name[100]; int employee_no; float salary; } *[10]


repo: Jahaja/cityslicker

decompiled_code:
__int64 __fastcall compare_populations(const void *a1, const void *a2)
{
__int64 v2; // rax
bool v3; // cc
__int64 result; // rax

v2 = *(_QWORD *)(*(_QWORD *)a2 + 32LL);
v3 = *(_QWORD *)(*(_QWORD *)a1 + 32LL) <= v2;
result = *(_QWORD *)(*(_QWORD *)a1 + 32LL) < v2;
if ( !v3 )
result = 0xFFFFFFFFLL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(const void *a1, const void *a2)
{
__int64 v2; // rax
bool v3; // cc
__int64 result; // rax

v2 = *(_QWORD *)(*(_QWORD *)a2 + 32LL);
v3 = *(_QWORD *)(*(_QWORD *)a1 + 32LL) <= v2;
result = *(_QWORD *)(*(_QWORD *)a1 + 32LL) < v2;
if ( !v3 )
result = 0xFFFFFFFFLL;
return result;
}

original_code:
static int compare_populations(const void *p1, const void *p2) {
    const city *c1 = *(city * const *) p1;
    const city *c2 = *(city * const *) p2;
    if(c1->population > c2->population) {
        return -1;
    } else if (c1->population < c2->population) {
        return 1;
    } else {
        return 0;
    }
}

canonical_original_code:
static int compare_populations(void *p1, void *p2) {
    struct city *c1 = *(city * const *) p1;
    struct city *c2 = *(city * const *) p2;
    if(c1->population > c2->population) {
        return -1;
    } else if (c1->population < c2->population) {
        return 1;
    } else {
        return 0;
    }
}

variable_types: struct city { int id; char *name; double latitude; double longitude; long long population; char feature_code[-1]; } *


decompiled_code:
void *city_create()
{
return calloc(0x38uLL, 1uLL);
}

canonical_decompiled_code:
void *func1()
{
return calloc(0x38uLL, 1uLL);
}

original_code:
city *city_create(void) {
    city *c = malloc(sizeof *c);
    if(!c) return ((void *)0);
    memset(c, 0, sizeof(city));
    return c;
}

canonical_original_code:
struct city *city_create() {
    struct city *c = malloc(sizeof *c);
    if(!c) return ((void *)0);
    memset(c, 0, sizeof(city));
    return c;
}

return_type: struct city { int id; char *name; double latitude; double longitude; long long population; char feature_code[-1]; } *


decompiled_code:
__int64 __fastcall city_destroy(void *ptr)
{
if ( !ptr )
return 0xFFFFFFFFLL;
free(*((void **)ptr + 1));
free(ptr);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(void *ptr)
{
if ( !ptr )
return 0xFFFFFFFFLL;
free(*((void **)ptr + 1));
free(ptr);
return 0LL;
}

original_code:
int city_destroy(city *c) {
    if(!c) return -1;
    free(c->name);
    free(c);
    return 0;
}

canonical_original_code:
int city_destroy(struct city *c) {
    if(!c) return -1;
    free(c->name);
    free(c);
    return 0;
}

user_defined_types: struct city { int id; char *name; double latitude; double longitude; long long population; char feature_code[-1]; }


decompiled_code:
_QWORD *world_create()
{
_QWORD *v0; // r12
void *v1; // rax
void *v3; // rdi

v0 = malloc(0x10uLL);
if ( v0 )
{
v1 = malloc(0x13880uLL);
v0[1] = v1;
if ( v1 )
{
*v0 = 0x271000000000LL;
}
else
{
v3 = v0;
v0 = 0LL;
free(v3);
}
}
return v0;
}

original_code:
world *world_create(void) {
    world *w = malloc(sizeof *w);
    if(!w) goto err;
    w->cities = malloc((sizeof w->cities) * 10000);
    if(!w->cities) goto err;
    w->size = 10000;
    w->length = 0;
    return w;
err:
    if(w) free(w);
    return ((void *)0);
}

canonical_original_code:
struct world *world_create() {
    struct world *w = malloc(sizeof *w);
    if(!w) goto err;
    w->cities = malloc((sizeof w->cities) * 10000);
    if(!w->cities) goto err;
    w->size = 10000;
    w->length = 0;
    return w;
err:
    if(w) free(w);
    return ((void *)0);
}

variable_types: struct world { int length; int size; struct city { int id; char *name; double latitude; double longitude; long long population; char feature_code[-1]; } **cities; } *

user_defined_types: struct world { int length; int size; struct city **cities; }


decompiled_code:
__int64 __fastcall world_destroy(void *ptr)
{
__int64 v2; // rbx
void *v3; // rdi

if ( !ptr )
return 0xFFFFFFFFLL;
if ( *(int *)ptr > 0 )
{
v2 = 0LL;
do
{
v3 = *(void **)(*((_QWORD *)ptr + 1) + 8 * v2++);
city_destroy(v3);
}
while ( *(_DWORD *)ptr > (int)v2 );
}
free(*((void **)ptr + 1));
free(ptr);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func4(void *ptr)
{
__int64 v2; // rbx
void *v3; // rdi

if ( !ptr )
return 0xFFFFFFFFLL;
if ( *(int *)ptr > 0 )
{
v2 = 0LL;
do
{
v3 = *(void **)(*((_QWORD *)ptr + 1) + 8 * v2++);
func2(v3);
}
while ( *(_DWORD *)ptr > (int)v2 );
}
free(*((void **)ptr + 1));
free(ptr);
return 0LL;
}

original_code:
int world_destroy(world *w) {
    if(!w) return -1;
    int i;
    for (i = 0; i < w->length; i++) {
        city_destroy(w->cities[i]);
    }
    free(w->cities);
    free(w);
    return 0;
}

canonical_original_code:
int world_destroy(struct world *w) {
    if(!w) return -1;
    int i;
    for (i = 0; i < w->length; i++) {
        city_destroy(w->cities[i]);
    }
    free(w->cities);
    free(w);
    return 0;
}


decompiled_code:
__int64 __fastcall world_add_city(int *a1, __int64 a2)
{
__int64 v2; // rax
int v3; // edx
_QWORD *v5; // rdi
unsigned int v6; // er8
_QWORD *v8; // rax

if ( a1 )
{
if ( a2 )
{
v2 = *a1;
v3 = a1[1];
v5 = (_QWORD *)*((_QWORD *)a1 + 1);
if ( (int)v2 < v3 )
{
LABEL_4:
v6 = v2 + 1;
*a1 = v2 + 1;
v5[v2] = a2;
return v6;
}
v8 = realloc(v5, 8LL * (int)((double)v3 * 1.5));
v5 = v8;
if ( v8 )
{
*((_QWORD *)a1 + 1) = v8;
a1[1] = (int)((double)a1[1] * 1.5);
v2 = *a1;
goto LABEL_4;
}
}
return (unsigned int)-1;
}
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func5(int *a1, __int64 a2)
{
__int64 v2; // rax
int v3; // edx
_QWORD *v5; // rdi
unsigned int v6; // er8
_QWORD *v8; // rax

if ( a1 )
{
if ( a2 )
{
v2 = *a1;
v3 = a1[1];
v5 = (_QWORD *)*((_QWORD *)a1 + 1);
if ( (int)v2 < v3 )
{
LABEL_4:
v6 = v2 + 1;
*a1 = v2 + 1;
v5[v2] = a2;
return v6;
}
v8 = realloc(v5, 8LL * (int)((double)v3 * 1.5));
v5 = v8;
if ( v8 )
{
*((_QWORD *)a1 + 1) = v8;
a1[1] = (int)((double)a1[1] * 1.5);
v2 = *a1;
goto LABEL_4;
}
}
return (unsigned int)-1;
}
return 0xFFFFFFFFLL;
}

original_code:
int world_add_city(world *w, city *c) {
    if(!w || !c) return -1;
    if(w->length >= w->size) {
        int newsize = (int) (w->size * 1.5);
        city **tc = realloc(w->cities, sizeof(city *) * newsize);
        if(!tc) return -1;
        w->cities = tc;
        w->size *= 1.5;
    }
    w->cities[w->length++] = c;
    return w->length;
}

canonical_original_code:
int world_add_city(struct world *w, struct city *c) {
    if(!w || !c) return -1;
    if(w->length >= w->size) {
        int newsize = (int) (w->size * 1.5);
        struct city **tc = realloc(w->cities, sizeof(city *) * newsize);
        if(!tc) return -1;
        w->cities = tc;
        w->size *= 1.5;
    }
    w->cities[w->length++] = c;
    return w->length;
}

variable_types:
c
struct city *

variable_types: newsize int

variable_types: struct city { int id; char *name; double latitude; double longitude; long long population; char feature_code[-1]; } **


decompiled_code:
__int64 __fastcall world_get_city_index_by_latitude(__int64 a1, double a2)
{
int v3; // ecx
__int64 v4; // rdi
int v5; // edx
__int64 result; // rax
double v7; // xmm0_8

v3 = *(_DWORD *)a1 - 1;
if ( v3 < 0 )
return 0xFFFFFFFFLL;
v4 = *(_QWORD *)(a1 + 8);
v5 = 0;
do
{
while ( 1 )
{
result = (unsigned int)(v5 + ((v3 - v5) >> 1));
v7 = *(double *)(*(_QWORD *)(v4 + 8LL * (int)result) + 16LL);
if ( a2 <= v7 )
break;
v5 = result + 1;
if ( (int)result + 1 > v3 )
return result;
}
if ( v7 <= a2 )
break;
v3 = result - 1;
}
while ( v5 <= (int)result - 1 );
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, double a2)
{
int v3; // ecx
__int64 v4; // rdi
int v5; // edx
__int64 result; // rax
double v7; // xmm0_8

v3 = *(_DWORD *)a1 - 1;
if ( v3 < 0 )
return 0xFFFFFFFFLL;
v4 = *(_QWORD *)(a1 + 8);
v5 = 0;
do
{
while ( 1 )
{
result = (unsigned int)(v5 + ((v3 - v5) >> 1));
v7 = *(double *)(*(_QWORD *)(v4 + 8LL * (int)result) + 16LL);
if ( a2 <= v7 )
break;
v5 = result + 1;
if ( (int)result + 1 > v3 )
return result;
}
if ( v7 <= a2 )
break;
v3 = result - 1;
}
while ( v5 <= (int)result - 1 );
return result;
}

original_code:
int world_get_city_index_by_latitude(world *w, double latitude) {
    int mid = -1, min = 0;
    int max = w->length - 1;
    while(max >= min) {
        mid = min + ((max - min) / 2);
        city *c = w->cities[mid];
        if(c->latitude < latitude) {
            min = mid + 1;
        } else if (c->latitude > latitude) {
            max = mid - 1;
        } else {
            return mid;
        }
    }
    return mid;
}

canonical_original_code:
int world_get_city_index_by_latitude(struct world *w, double latitude) {
    int mid = -1; int min = 0;
    int max = w->length - 1;
    while(max >= min) {
        mid = min + ((max - min) / 2);
        struct city *c = w->cities[mid];
        if(c->latitude < latitude) {
            min = mid + 1;
        } else if (c->latitude > latitude) {
            max = mid - 1;
        } else {
            return mid;
        }
    }
    return mid;
}

variable_types: latitude double

variable_types: min int

variable_types: max int


decompiled_code:
int *__fastcall world_get_cities_in_bounding_box(__int64 a1, double a2, double a3, double a4, double a5)
{
int v5; // ebx
double v6; // xmm4_8
int v7; // er13
int *v8; // r14
__int64 v9; // rbp
__int64 v10; // rsi
double v11; // xmm0_8

v5 = world_get_city_index_by_latitude(a1, a2);
v7 = world_get_city_index_by_latitude(a1, v6);
v8 = (int *)world_create();
if ( v5 <= v7 )
{
v9 = 8LL * v5;
do
{
while ( 1 )
{
v10 = *(_QWORD *)(*(_QWORD *)(a1 + 8) + v9);
v11 = *(double *)(v10 + 24);
if ( v11 >= a4 && a5 >= v11 )
break;
++v5;
v9 += 8LL;
if ( v7 < v5 )
goto LABEL_7;
}
++v5;
v9 += 8LL;
world_add_city(v8, v10);
}
while ( v7 >= v5 );
}
LABEL_7:
qsort(*((void **)v8 + 1), *v8, 8uLL, (__compar_fn_t)compare_populations);
return v8;
}

canonical_decompiled_code:
int *__fastcall func7(__int64 a1, double a2, double a3, double a4, double a5)
{
int v5; // ebx
double v6; // xmm4_8
int v7; // er13
int *v8; // r14
__int64 v9; // rbp
__int64 v10; // rsi
double v11; // xmm0_8

v5 = func6(a1, a2);
v7 = func6(a1, v6);
v8 = (int *)func3();
if ( v5 <= v7 )
{
v9 = 8LL * v5;
do
{
while ( 1 )
{
v10 = *(_QWORD *)(*(_QWORD *)(a1 + 8) + v9);
v11 = *(double *)(v10 + 24);
if ( v11 >= a4 && a5 >= v11 )
break;
++v5;
v9 += 8LL;
if ( v7 < v5 )
goto LABEL_7;
}
++v5;
v9 += 8LL;
func5(v8, v10);
}
while ( v7 >= v5 );
}
LABEL_7:
qsort(*((void **)v8 + 1), *v8, 8uLL, (__compar_fn_t)compare_populations);
return v8;
}

original_code:
world *world_get_cities_in_bounding_box(world *w, double minlat, double maxlat, double minlng, double maxlng) {
    int minindex, maxindex, i, j;
    city *c;
    world *bbw;
    minindex = world_get_city_index_by_latitude(w, minlat);
    maxindex = world_get_city_index_by_latitude(w, maxlat);
    bbw = world_create();
    for(i = minindex, j = 0; i <= maxindex; i++) {
        c = w->cities[i];
        if(c->longitude >= minlng && c->longitude <= maxlng) {
            world_add_city(bbw, c);
            j++;
        }
    }
    qsort(bbw->cities, bbw->length, sizeof(city *), compare_populations);
    return bbw;
}

canonical_original_code:
struct world *world_get_cities_in_bounding_box(struct world *w, double minlat, double maxlat, double minlng, double maxlng) {
    int minindex; int maxindex; int i; int j;
    struct city *c;
    struct world *bbw;
    minindex = world_get_city_index_by_latitude(w, minlat);
    maxindex = world_get_city_index_by_latitude(w, maxlat);
    bbw = world_create();
    for(i = minindex, j = 0; i <= maxindex; i++) {
        c = w->cities[i];
        if(c->longitude >= minlng && c->longitude <= maxlng) {
            world_add_city(bbw, c);
            j++;
        }
    }
    qsort(bbw->cities, bbw->length, sizeof(struct city *), compare_populations);
    return bbw;
}

variable_types:
w
struct world *

variable_types: minlat double

variable_types: maxlat double

variable_types: minlng double

variable_types: maxlng double

variable_types: minindex int

variable_types: maxindex int

variable_types: i int

variable_types: j int

return_type: struct world { int length; int size; struct city { int id; char *name; double latitude; double longitude; long long population; char feature_code[-1]; } **cities; } *


decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rdx
const char *v4; // r13
unsigned int v5; // ebp
char *v6; // r12
int v7; // ebx
int v8; // eax
__int64 v9; // rbx
int *v10; // rax
char *v11; // rax
int *v12; // rax
char *v13; // rax

log_info("City Slicker version: 0.1.0\n", argv, envp);
if ( argc <= 1 )
{
v5 = 8082;
log_fatal("Invalid number of arguments, database file must be specified.\n");
v4 = argv[1];
}
else
{
v4 = argv[1];
v5 = 8082;
if ( argc != 2 )
{
v6 = (char *)argv[2];
v5 = atoi(v6);
if ( v5 - 1 > 0xFFFE )
{
argv = (const char **)v6;
log_fatal("Invalid port number: %s\n", v6);
}
}
}
log_info("Loading geonames file...\n", argv, v3);
v7 = mstime();
loaded_world = geonames_load_file(v4);
if ( !loaded_world )
{
v10 = _errno_location();
v11 = strerror(*v10);
log_fatal("Could not load geonames database (%s).\n", v11);
}
v8 = mstime();
log_info("Geonames file loaded in %.2f seconds.\n", (double)(v8 - v7) / 1000.0);
log_info(
"Cities loaded: %d (%d slots allocated)\n",
*(unsigned int *)loaded_world,
*(unsigned int *)(loaded_world + 4));
log_info("Starting TCP server on port %d\n", v5);
v9 = net_server_start(v5);
if ( !v9 )
{
v12 = _errno_location();
v13 = strerror(*v12);
log_fatal("Failed to start TCP server: %s\n", v13);
}
while ( 1 )
net_poll(v9);
}

original_code:
int main(const int argc, const char *argv[]) {
    log_info("City Slicker version: 0.1.0\n");
    if(argc < 2) {
        log_fatal("Invalid number of arguments, database file must be specified.\n");
    }
    const char *db = argv[1];
    int port;
    if(argc > 2) {
        port = atoi(argv[2]);
        if(port < 1 || port > (0x7fff * 2 + 1)) {
            log_fatal("Invalid port number: %s\n", argv[2]);
        }
    } else {
        port = 8082;
    }
    log_info("Loading geonames file...\n");
    int start = mstime();
    loaded_world = geonames_load_file(db);
    if(!loaded_world) {
        log_fatal("Could not load geonames database (%s).\n", strerror((*__errno_location ())));
    }
    int elapsed = mstime() - start;
    log_info("Geonames file loaded in %.2f seconds.\n", elapsed / 1000.0);
    log_info("Cities loaded: %d (%d slots allocated)\n", loaded_world->length, loaded_world->size);
    log_info("Starting TCP server on port %d\n", port);
    net_server *s = net_server_start(port);
    if(!s) {
        log_fatal("Failed to start TCP server: %s\n", strerror((*__errno_location ())));
    }
    for (;;) {
        net_poll(s);
    }
    return 0;
}

canonical_original_code:
int main(int argc, char *argv[]) {
    log_info("City Slicker version: 0.1.0\n");
    if(argc < 2) {
        log_fatal("Invalid number of arguments, database file must be specified.\n");
    }
    char *db = argv[1];
    int port;
    if(argc > 2) {
        port = atoi(argv[2]);
        if(port < 1 || port > (0x7fff * 2 + 1)) {
            log_fatal("Invalid port number: %s\n", argv[2]);
        }
    } else {
        port = 8082;
    }
    log_info("Loading geonames file...\n");
    int start = mstime();
    loaded_world = geonames_load_file(db);
    if(!loaded_world) {
        log_fatal("Could not load geonames database (%s).\n", strerror((*__errno_location ())));
    }
    int elapsed = mstime() - start;
    log_info("Geonames file loaded in %.2f seconds.\n", elapsed / 1000.0);
    log_info("Cities loaded: %d (%d slots allocated)\n", loaded_world->length, loaded_world->size);
    log_info("Starting TCP server on port %d\n", port);
    struct net_server *s = net_server_start(port);
    if(!s) {
        log_fatal("Failed to start TCP server: %s\n", strerror((*__errno_location ())));
    }
    for (;;) {
        net_poll(s);
    }
    return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types:
db
char *

variable_types: port int

variable_types: start int

variable_types: elapsed int

variable_types: struct net_server { int fd; int epfd; int num_clients; struct epoll_event { unsigned int events; union epoll_data { void *ptr; int fd; unsigned int u32; unsigned long u64; } data; } *events; int max_events; } *

user_defined_types: struct net_server { int fd; int epfd; int num_clients; struct epoll_event *events; int max_events; }

user_defined_types: struct epoll_event { unsigned int events; union epoll_data data; }


decompiled_code:
_QWORD *net_server_create()
{
_QWORD *v0; // r12
void *v1; // rax
void *v3; // rdi

v0 = malloc(0x20uLL);
if ( v0 )
{
v1 = malloc(0x3000uLL);
v0[2] = v1;
if ( v1 )
{
*((_DWORD *)v0 + 6) = 1024;
}
else
{
v3 = v0;
v0 = 0LL;
free(v3);
}
}
return v0;
}

original_code:
static net_server *net_server_create(void) {
    net_server *s = malloc(sizeof *s);
    if(!s) return ((void *)0);
    s->events = malloc(sizeof(struct epoll_event) * 1024);
    if(!s->events) {
        free(s);
        return ((void *)0);
    }
    s->max_events = 1024;
    return s;
}

canonical_original_code:
static struct net_server *net_server_create() {
    struct net_server *s = malloc(sizeof *s);
    if(!s) return ((void *)0);
    s->events = malloc(sizeof(struct epoll_event) * 1024);
    if(!s->events) {
        free(s);
        return ((void *)0);
    }
    s->max_events = 1024;
    return s;
}

return_type: struct net_server { int fd; int epfd; int num_clients; struct epoll_event { unsigned int events; union epoll_data { void *ptr; int fd; unsigned int u32; unsigned long u64; } data; } *events; int max_events; } *


decompiled_code:
// attributes: thunk
void net_file_event_destroy(void *ptr)
{
free(ptr);
}

canonical_decompiled_code:
void func2(void *ptr)
{
free(ptr);
}

original_code:
static void net_file_event_destroy(net_file_event *fe) {
    free(fe);
}

canonical_original_code:
static void net_file_event_destroy(struct net_file_event *fe) {
    free(fe);
}

variable_types: struct net_file_event { void *ptr; int mask; enum net_file_event_type_t { net_file_event_type_client=0, net_file_event_type_server=1 } type; } *

user_defined_types: struct net_file_event { void *ptr; int mask; enum net_file_event_type_t type; }


decompiled_code:
void __fastcall net_server_destroy(void *ptr)
{
int v2; // edi
int v3; // edi

if ( ptr )
{
free(*((void **)ptr + 2));
v2 = *(_DWORD *)ptr;
if ( v2 )
{
close(v2);
v3 = *((_DWORD *)ptr + 1);
if ( !v3 )
goto LABEL_4;
}
else
{
v3 = *((_DWORD *)ptr + 1);
if ( !v3 )
{
LABEL_4:
free(ptr);
return;
}
}
close(v3);
free(ptr);
}
}

canonical_decompiled_code:
void __fastcall func3(void *ptr)
{
int v2; // edi
int v3; // edi

if ( ptr )
{
free(*((void **)ptr + 2));
v2 = *(_DWORD *)ptr;
if ( v2 )
{
close(v2);
v3 = *((_DWORD *)ptr + 1);
if ( !v3 )
goto LABEL_4;
}
else
{
v3 = *((_DWORD *)ptr + 1);
if ( !v3 )
{
LABEL_4:
free(ptr);
return;
}
}
close(v3);
free(ptr);
}
}

original_code:
static void net_server_destroy(net_server *s) {
    if(!s) return;
    free(s->events);
    if(s->fd) close(s->fd);
    if(s->epfd) close(s->epfd);
    free(s);
}

canonical_original_code:
static void net_server_destroy(struct net_server *s) {
    if(!s) return;
    free(s->events);
    if(s->fd) close(s->fd);
    if(s->epfd) close(s->epfd);
    free(s);
}

user_defined_types: union epoll_data { void *ptr; int fd; unsigned int u32; unsigned long u64; }


decompiled_code:
void __fastcall net_client_close(__int64 a1, __int64 a2)
{
log_info("Client %s:%d disconnected.\n", (const char *)(a2 + 4), *(unsigned int *)(a2 + 20));
epoll_ctl(*(_DWORD *)(a1 + 4), 2, *(_DWORD *)a2, 0LL);
close(*(_DWORD *)a2);
free((void *)a2);
}

canonical_decompiled_code:
void __fastcall func4(__int64 a1, __int64 a2)
{
log_info("Client %s:%d disconnected.\n", (const char *)(a2 + 4), *(unsigned int *)(a2 + 20));
epoll_ctl(*(_DWORD *)(a1 + 4), 2, *(_DWORD *)a2, 0LL);
close(*(_DWORD *)a2);
free((void *)a2);
}

original_code:
static void net_client_close(net_server *s, net_client *c) {
    log_info("Client %s:%d disconnected.\n", c->ip, c->port);
    epoll_ctl(s->epfd, 2, c->fd, ((void *)0));
    close(c->fd);
    free(c);
}

canonical_original_code:
static void net_client_close(struct net_server *s, struct net_client *c) {
    log_info("Client %s:%d disconnected.\n", c->ip, c->port);
    epoll_ctl(s->epfd, 2, c->fd, ((void *)0));
    close(c->fd);
    free(c);
}

variable_types: struct net_client { int fd; char ip[16]; int port; char buf[-1]; int buflen; } *


decompiled_code:
__int64 __fastcall net_client_read(int *a1)
{
unsigned int v1; // eax
unsigned int v2; // er12
__int64 v3; // rax
int v4; // edx
int *v5; // rcx
__int64 v6; // rsi
__int64 v7; // rax
int v9[10]; // [rsp+0h] [rbp-28h] BYREF

v1 = read(*a1, v9, 0x10uLL);
v2 = v1;
if ( v1 )
{
if ( v1 == 16 )
{
v3 = world_get_cities_in_bounding_box(
loaded_world,
*(float *)v9,
*(float *)&v9[1],
*(float *)&v9[2],
*(float *)&v9[3]);
v4 = *(_DWORD *)v3;
v5 = (int *)v3;
if ( *(int *)v3 > 0 )
{
v6 = *(_QWORD *)(v3 + 8);
v7 = 0LL;
do
{
a1[v7 + 6] = **(_DWORD **)(v6 + 8 * v7);
v4 = *v5;
++v7;
}
while ( *v5 > (int)v7 );
}
a1[2566] = 4 * v4;
}
else
{
v2 = -1;
log_info("Got some strange input, need 16 bytes!\n");
}
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func5(int *a1)
{
unsigned int v1; // eax
unsigned int v2; // er12
__int64 v3; // rax
int v4; // edx
int *v5; // rcx
__int64 v6; // rsi
__int64 v7; // rax
int v9[10]; // [rsp+0h] [rbp-28h] BYREF

v1 = read(*a1, v9, 0x10uLL);
v2 = v1;
if ( v1 )
{
if ( v1 == 16 )
{
v3 = world_get_cities_in_bounding_box(
loaded_world,
*(float *)v9,
*(float *)&v9[1],
*(float *)&v9[2],
*(float *)&v9[3]);
v4 = *(_DWORD *)v3;
v5 = (int *)v3;
if ( *(int *)v3 > 0 )
{
v6 = *(_QWORD *)(v3 + 8);
v7 = 0LL;
do
{
a1[v7 + 6] = **(_DWORD **)(v6 + 8 * v7);
v4 = *v5;
++v7;
}
while ( *v5 > (int)v7 );
}
a1[2566] = 4 * v4;
}
else
{
v2 = -1;
log_info("Got some strange input, need 16 bytes!\n");
}
}
return v2;
}

original_code:
static int net_client_read(net_client *c) {
    int num_read;
    int datalen = 16;
    char data[datalen];
    num_read = read(c->fd, data, datalen);
    if(num_read == 0) {
        return 0;
    }
    if(num_read != datalen) {
        log_info("Got some strange input, need 16 bytes!\n");
        return -1;
    }
    float *coords = (float *) &data;
    world *res = world_get_cities_in_bounding_box(
        loaded_world,
        (double) coords[0], (double) coords[1], (double) coords[2], (double) coords[3]
    );
    int i;
    int *ids = (int *) &c->buf;
    for(i = 0; i < res->length; i++) {
        *(ids++) = res->cities[i]->id;
    }
    c->buflen = sizeof(int) * res->length;
    return num_read;
}

canonical_original_code:
static int net_client_read(struct net_client *c) {
    int num_read;
    int datalen = 16;
    char data[-1];
    num_read = read(c->fd, data, datalen);
    if(num_read == 0) {
        return 0;
    }
    if(num_read != datalen) {
        log_info("Got some strange input, need 16 bytes!\n");
        return -1;
    }
    float *coords = (float *) &data;
    struct world *res = world_get_cities_in_bounding_box(
        loaded_world,
        (double) coords[0], (double) coords[1], (double) coords[2], (double) coords[3]
    );
    int i;
    int *ids = (int *) &c->buf;
    for(i = 0; i < res->length; i++) {
        *(ids++) = res->cities[i]->id;
    }
    c->buflen = sizeof(int) * res->length;
    return num_read;
}

variable_types: datalen int

variable_types:
data
char [-1]

variable_types:
coords
float *

variable_types: struct world { int length; int size; struct city { int id; char *name; double latitude; double longitude; long long population; char feature_code[-1]; } **cities; } *

variable_types:
ids
int *

user_defined_types: struct net_client { int fd; char ip[16]; int port; char buf[-1]; int buflen; }


decompiled_code:
ssize_t __fastcall net_client_write(__int64 a1)
{
ssize_t result; // rax

result = *(unsigned int *)(a1 + 10264);
if ( (_DWORD)result )
{
result = write(*(_DWORD *)a1, (const void *)(a1 + 24), (int)result);
if ( (_DWORD)result != -1 )
*(_DWORD *)(a1 + 10264) = 0;
}
return result;
}

canonical_decompiled_code:
ssize_t __fastcall func6(__int64 a1)
{
ssize_t result; // rax

result = *(unsigned int *)(a1 + 10264);
if ( (_DWORD)result )
{
result = write(*(_DWORD *)a1, (const void *)(a1 + 24), (int)result);
if ( (_DWORD)result != -1 )
*(_DWORD *)(a1 + 10264) = 0;
}
return result;
}

original_code:
static int net_client_write(net_client *c) {
    if(c->buflen) {
        int n = write(c->fd, c->buf, c->buflen);
        if(n == -1)
            return -1;
        c->buflen = 0;
        return n;
    }
    return 0;
}

canonical_original_code:
static int net_client_write(struct net_client *c) {
    if(c->buflen) {
        int n = write(c->fd, c->buf, c->buflen);
        if(n == -1)
            return -1;
        c->buflen = 0;
        return n;
    }
    return 0;
}

variable_types: n int


decompiled_code:
__int64 __fastcall net_server_accept(int *a1)
{
int v2; // edi
int v3; // eax
int v4; // ebp
__int64 v5; // r13
char *v7; // rax
_DWORD *v8; // rax
void *v9; // r14
int v10; // edi
socklen_t v11; // [rsp+0h] [rbp-48h] BYREF
struct epoll_event event; // [rsp+4h] [rbp-44h] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-38h] BYREF

v2 = *a1;
v11 = 16;
v3 = accept(v2, &addr, &v11);
v4 = v3;
if ( v3 != -1 )
{
if ( !fcntl(v3, 4, 2048LL) )
{
v7 = net_client_create_isra_0(v4, *(__int16 *)addr.sa_data, *(struct in_addr *)&addr.sa_data[2]);
v5 = (__int64)v7;
if ( v7 )
{
v8 = net_file_event_create((__int64)v7, 0);
v9 = v8;
if ( v8 )
{
v10 = a1[1];
event.events = 5;
event.data.u64 = (uint64_t)v8;
if ( epoll_ctl(v10, 1, v4, &event) )
{
net_client_close((__int64)a1, v5);
net_file_event_destroy(v9);
return 0LL;
}
return v5;
}
net_client_close((__int64)a1, v5);
return 0LL;
}
}
if ( !v4 )
return 0LL;
}
close(v4);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func9(int *a1)
{
int v2; // edi
int v3; // eax
int v4; // ebp
__int64 v5; // r13
char *v7; // rax
_DWORD *v8; // rax
void *v9; // r14
int v10; // edi
socklen_t v11; // [rsp+0h] [rbp-48h] BYREF
struct epoll_event event; // [rsp+4h] [rbp-44h] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-38h] BYREF

v2 = *a1;
v11 = 16;
v3 = accept(v2, &addr, &v11);
v4 = v3;
if ( v3 != -1 )
{
if ( !fcntl(v3, 4, 2048LL) )
{
v7 = func8(v4, *(__int16 *)addr.sa_data, *(struct in_addr *)&addr.sa_data[2]);
v5 = (__int64)v7;
if ( v7 )
{
v8 = net_file_event_create((__int64)v7, 0);
v9 = v8;
if ( v8 )
{
v10 = a1[1];
event.events = 5;
event.data.u64 = (uint64_t)v8;
if ( epoll_ctl(v10, 1, v4, &event) )
{
func4((__int64)a1, v5);
func2(v9);
return 0LL;
}
return v5;
}
func4((__int64)a1, v5);
return 0LL;
}
}
if ( !v4 )
return 0LL;
}
close(v4);
return 0LL;
}

original_code:
static net_client *net_server_accept(net_server *s) {
    struct sockaddr_in addr;
    socklen_t addrlen = sizeof(struct sockaddr_in);
    int fd;
    net_client *c = ((void *)0);
    net_file_event *fe = ((void *)0);
    if((fd = accept(s->fd, (struct sockaddr *) &addr, &addrlen)) == -1)
        goto err;
    if(fcntl(fd, 4, 04000) != 0)
        goto err;
    if((c = net_client_create(fd, addr)) == ((void *)0))
        goto err;
    if((fe = net_file_event_create((void *) c, net_file_event_type_client)) == ((void *)0))
        goto err;
    struct epoll_event ee;
    memset(&ee, 0, sizeof(struct epoll_event));
    ee.events |= EPOLLIN;
    ee.events |= EPOLLOUT;
    ee.data.u64 = 0;
    ee.data.ptr = (void *) fe;
    if(epoll_ctl(s->epfd, 1, fd, &ee) != 0)
        goto err;
    return c;
err:
    if(c)
        net_client_close(s, c);
    else if(fd)
        close(fd);
    if(fe)
        net_file_event_destroy(fe);
    return ((void *)0);
}

canonical_original_code:
static struct net_client *net_server_accept(struct net_server *s) {
    struct sockaddr_in addr;
    unsigned int addrlen = sizeof(struct sockaddr_in);
    int fd;
    struct net_client *c = ((void *)0);
    struct net_file_event *fe = ((void *)0);
    if((fd = accept(s->fd, (struct sockaddr *) &addr, &addrlen)) == -1)
        goto err;
    if(fcntl(fd, 4, 04000) != 0)
        goto err;
    if((c = net_client_create(fd, addr)) == ((void *)0))
        goto err;
    if((fe = net_file_event_create((void *) c, net_file_event_type_client)) == ((void *)0))
        goto err;
    struct epoll_event ee;
    memset(&ee, 0, sizeof(struct epoll_event));
    ee.events |= EPOLLIN;
    ee.events |= EPOLLOUT;
    ee.data.u64 = 0;
    ee.data.ptr = (void *) fe;
    if(epoll_ctl(s->epfd, 1, fd, &ee) != 0)
        goto err;
    return c;
err:
    if(c)
        net_client_close(s, c);
    else if(fd)
        close(fd);
    if(fe)
        net_file_event_destroy(fe);
    return ((void *)0);
}

variable_types: struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr { unsigned int s_addr; } sin_addr; unsigned char sin_zero[-1]; }

variable_types:
addrlen
unsigned int

variable_types: fd int

variable_types: struct epoll_event { unsigned int events; union epoll_data { void *ptr; int fd; unsigned int u32; unsigned long u64; } data; }

return_type: struct net_client { int fd; char ip[16]; int port; char buf[-1]; int buflen; } *

user_defined_types: struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr sin_addr; unsigned char sin_zero[-1]; }

user_defined_types: struct sockaddr { unsigned short sa_family; char sa_data[14]; }

user_defined_types: enum net_file_event_type_t { net_file_event_type_client=0, net_file_event_type_server=1 }


decompiled_code:
int *__fastcall net_server_start(unsigned __int16 a1)
{
int *v1; // rbp
int v2; // eax
int *v3; // rax
char *v4; // rax
int *v5; // rdi
int *v7; // rax
char *v8; // rax
int v9; // eax
int v10; // er13
_DWORD *v11; // rax
void *v12; // r12
int v13; // edx
int *v14; // rax
char *v15; // rax
int v16; // [rsp+0h] [rbp-38h] BYREF
struct epoll_event event; // [rsp+4h] [rbp-34h] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-28h] BYREF

v16 = 1;
*(_DWORD *)&addr.sa_data[10] = 0;
addr.sa_family = 2;
*(_QWORD *)&addr.sa_data[2] = (unsigned int)_bswap_32_constprop_0(a1, (char *)_bswap_16 + 1);
*(_WORD *)addr.sa_data = _bswap_16(a1);
_sysv_signal(13, (__sighandler_t)((char *)_bswap_16 + 1));
v1 = (int *)net_server_create();
if ( !v1 )
{
v7 = _errno_location();
v8 = strerror(*v7);
log_error("Failed to start server: %s\n", v8);
return 0LL;
}
v2 = socket(2, 1, 0);
*v1 = v2;
if ( v2 == -1
|| (setsockopt(v2, 1, 2, &v16, 4u), bind(*v1, &addr, 0x10u))
|| listen(*v1, 50)
|| (v9 = epoll_create(1024), v10 = v9, v9 == -1)
|| (v1[1] = v9, v11 = net_file_event_create((__int64)v1, 1), (v12 = v11) == 0LL) )
{
v3 = _errno_location();
v4 = strerror(*v3);
log_error("Failed to start server: %s\n", v4);
v5 = v1;
v1 = 0LL;
net_server_destroy(v5);
return v1;
}
v13 = *v1;
event.events = 1;
event.data.u64 = (uint64_t)v11;
if ( epoll_ctl(v10, 1, v13, &event) != -1 )
return v1;
v14 = _errno_location();
v15 = strerror(*v14);
log_error("Failed to start server: %s\n", v15);
net_server_destroy(v1);
net_file_event_destroy(v12);
return 0LL;
}

canonical_decompiled_code:
int *__fastcall func10(unsigned __int16 a1)
{
int *v1; // rbp
int v2; // eax
int *v3; // rax
char *v4; // rax
int *v5; // rdi
int *v7; // rax
char *v8; // rax
int v9; // eax
int v10; // er13
_DWORD *v11; // rax
void *v12; // r12
int v13; // edx
int *v14; // rax
char *v15; // rax
int v16; // [rsp+0h] [rbp-38h] BYREF
struct epoll_event event; // [rsp+4h] [rbp-34h] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-28h] BYREF

v16 = 1;
*(_DWORD *)&addr.sa_data[10] = 0;
addr.sa_family = 2;
*(_QWORD *)&addr.sa_data[2] = (unsigned int)func7(a1, (char *)_bswap_16 + 1);
*(_WORD *)addr.sa_data = func0(a1);
_sysv_signal(13, (__sighandler_t)((char *)_bswap_16 + 1));
v1 = (int *)func1();
if ( !v1 )
{
v7 = _errno_location();
v8 = strerror(*v7);
log_error("Failed to start server: %s\n", v8);
return 0LL;
}
v2 = socket(2, 1, 0);
*v1 = v2;
if ( v2 == -1
|| (setsockopt(v2, 1, 2, &v16, 4u), bind(*v1, &addr, 0x10u))
|| listen(*v1, 50)
|| (v9 = epoll_create(1024), v10 = v9, v9 == -1)
|| (v1[1] = v9, v11 = net_file_event_create((__int64)v1, 1), (v12 = v11) == 0LL) )
{
v3 = _errno_location();
v4 = strerror(*v3);
log_error("Failed to start server: %s\n", v4);
v5 = v1;
v1 = 0LL;
func3(v5);
return v1;
}
v13 = *v1;
event.events = 1;
event.data.u64 = (uint64_t)v11;
if ( epoll_ctl(v10, 1, v13, &event) != -1 )
return v1;
v14 = _errno_location();
v15 = strerror(*v14);
log_error("Failed to start server: %s\n", v15);
func3(v1);
func2(v12);
return 0LL;
}

original_code:
net_server *net_server_start(int port) {
    int optval = 1, res;
    net_file_event *fe = ((void *)0);
    struct sockaddr_in addr;
    memset(&addr, 0, sizeof(struct sockaddr_in));
    addr.sin_family = 2;
    addr.sin_addr.s_addr = htonl(((in_addr_t) 0x00000000));
    addr.sin_port = htons(port);
    signal(13, ((__sighandler_t) 1));
    net_server *s = net_server_create();
    if(!s) goto err;
    s->fd = socket(2, SOCK_STREAM, 0);
    if(s->fd == -1) goto err;
    setsockopt(s->fd, 1, 2, &optval, sizeof(optval));
    res = bind(s->fd, (const struct sockaddr *) &addr, sizeof(struct sockaddr_in));
    if(res != 0) goto err;
    res = listen(s->fd, 50);
    if(res != 0) goto err;
    int epfd = epoll_create(1024);
    if(epfd == -1) goto err;
    s->epfd = epfd;
    fe = net_file_event_create((void *) s, net_file_event_type_server);
    if(!fe) goto err;
    struct epoll_event ee;
    memset(&ee, 0, sizeof(struct epoll_event));
    ee.events |= EPOLLIN;
    ee.data.u64 = 0;
    ee.data.ptr = (void *) fe;
    res = epoll_ctl(epfd, 1, s->fd, &ee);
    if(res == -1) goto err;
    return s;
err:
    log_error("Failed to start server: %s\n", strerror((*__errno_location ())));
    if(s) net_server_destroy(s);
    if(fe) net_file_event_destroy(fe);
    return ((void *)0);
}

canonical_original_code:
struct net_server *net_server_start(int port) {
    int optval = 1; int res;
    struct net_file_event *fe = ((void *)0);
    struct sockaddr_in addr;
    memset(&addr, 0, sizeof(struct sockaddr_in));
    addr.sin_family = 2;
    addr.sin_addr.s_addr = htonl(((unsigned int) 0x00000000));
    addr.sin_port = htons(port);
    signal(13, ((void (*)(int)) 1));
    struct net_server *s = net_server_create();
    if(!s) goto err;
    s->fd = socket(2, SOCK_STREAM, 0);
    if(s->fd == -1) goto err;
    setsockopt(s->fd, 1, 2, &optval, sizeof(optval));
    res = bind(s->fd, (struct sockaddr *) &addr, sizeof(struct sockaddr_in));
    if(res != 0) goto err;
    res = listen(s->fd, 50);
    if(res != 0) goto err;
    int epfd = epoll_create(1024);
    if(epfd == -1) goto err;
    s->epfd = epfd;
    fe = net_file_event_create((void *) s, net_file_event_type_server);
    if(!fe) goto err;
    struct epoll_event ee;
    memset(&ee, 0, sizeof(struct epoll_event));
    ee.events |= EPOLLIN;
    ee.data.u64 = 0;
    ee.data.ptr = (void *) fe;
    res = epoll_ctl(epfd, 1, s->fd, &ee);
    if(res == -1) goto err;
    return s;
err:
    log_error("Failed to start server: %s\n", strerror((*__errno_location ())));
    if(s) net_server_destroy(s);
    if(fe) net_file_event_destroy(fe);
    return ((void *)0);
}

variable_types: optval int

variable_types: res int

variable_types: epfd int


decompiled_code:
__int64 __fastcall net_poll(__int64 a1)
{
int v1; // eax
unsigned int v2; // er13
__int64 v3; // rbx
__int64 v4; // r12
int v5; // eax
int *v6; // rax
__int64 v7; // rbp
int v8; // edx
__int64 v9; // rax
int v11; // eax
int v12; // edi
char *v13; // rax
int *v14; // rax
char *v15; // rax

v1 = epoll_wait(*(_DWORD *)(a1 + 4), *(struct epoll_event **)(a1 + 16), *(_DWORD *)(a1 + 24), -1);
v2 = v1;
if ( v1 != -1 )
{
if ( v1 > 0 )
{
v3 = 0LL;
v4 = 12LL * v1;
while ( 1 )
{
while ( 1 )
{
v6 = (int *)(v3 + *(_QWORD *)(a1 + 16));
v7 = *(_QWORD *)(v6 + 1);
v8 = *(_DWORD *)(v7 + 12);
if ( !v8 )
break;
if ( v8 != 1 || (*(_BYTE *)v6 & 1) == 0 )
goto LABEL_8;
v9 = net_server_accept(*(int **)v7);
if ( !v9 )
{
v14 = _errno_location();
v15 = strerror(*v14);
log_info("Failed to accept client connection: %s\n", v15);
goto LABEL_8;
}
v3 += 12LL;
log_info("Client %s:%d connected\n", (const char *)(v9 + 4), *(unsigned int *)(v9 + 20));
if ( v4 == v3 )
return v2;
}
v5 = *v6;
if ( (v5 & 1) == 0 )
break;
v11 = net_client_read(*(int **)v7);
if ( v11 <= 0 )
{
if ( v11 == -1 )
log_error("Failed to read data from client. Closing client.\n");
goto LABEL_7;
}
v5 = *(_DWORD *)(*(_QWORD *)(a1 + 16) + v3);
if ( (v5 & 4) != 0 )
goto LABEL_17;
LABEL_6:
if ( (v5 & 0x18) != 0 )
goto LABEL_7;
LABEL_8:
v3 += 12LL;
if ( v4 == v3 )
return v2;
}
if ( (v5 & 4) == 0 )
goto LABEL_6;
LABEL_17:
if ( (unsigned int)net_client_write(*(_QWORD *)v7) == -1 )
{
log_error("Failed to write data from client. Closing client.\n");
LABEL_7:
net_client_close(a1, *(_QWORD *)v7);
net_file_event_destroy((void *)v7);
goto LABEL_8;
}
v5 = *(_DWORD *)(*(_QWORD *)(a1 + 16) + v3);
goto LABEL_6;
}
return v2;
}
v12 = *_errno_location();
if ( v12 == 4 )
return v2;
v13 = strerror(v12);
log_fatal("An error occured while waiting for fd events: %s.", v13);
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1)
{
int v1; // eax
unsigned int v2; // er13
__int64 v3; // rbx
__int64 v4; // r12
int v5; // eax
int *v6; // rax
__int64 v7; // rbp
int v8; // edx
__int64 v9; // rax
int v11; // eax
int v12; // edi
char *v13; // rax
int *v14; // rax
char *v15; // rax

v1 = epoll_wait(*(_DWORD *)(a1 + 4), *(struct epoll_event **)(a1 + 16), *(_DWORD *)(a1 + 24), -1);
v2 = v1;
if ( v1 != -1 )
{
if ( v1 > 0 )
{
v3 = 0LL;
v4 = 12LL * v1;
while ( 1 )
{
while ( 1 )
{
v6 = (int *)(v3 + *(_QWORD *)(a1 + 16));
v7 = *(_QWORD *)(v6 + 1);
v8 = *(_DWORD *)(v7 + 12);
if ( !v8 )
break;
if ( v8 != 1 || (*(_BYTE *)v6 & 1) == 0 )
goto LABEL_8;
v9 = func9(*(int **)v7);
if ( !v9 )
{
v14 = _errno_location();
v15 = strerror(*v14);
log_info("Failed to accept client connection: %s\n", v15);
goto LABEL_8;
}
v3 += 12LL;
log_info("Client %s:%d connected\n", (const char *)(v9 + 4), *(unsigned int *)(v9 + 20));
if ( v4 == v3 )
return v2;
}
v5 = *v6;
if ( (v5 & 1) == 0 )
break;
v11 = func5(*(int **)v7);
if ( v11 <= 0 )
{
if ( v11 == -1 )
log_error("Failed to read data from client. Closing client.\n");
goto LABEL_7;
}
v5 = *(_DWORD *)(*(_QWORD *)(a1 + 16) + v3);
if ( (v5 & 4) != 0 )
goto LABEL_17;
LABEL_6:
if ( (v5 & 0x18) != 0 )
goto LABEL_7;
LABEL_8:
v3 += 12LL;
if ( v4 == v3 )
return v2;
}
if ( (v5 & 4) == 0 )
goto LABEL_6;
LABEL_17:
if ( (unsigned int)func6(*(_QWORD *)v7) == -1 )
{
log_error("Failed to write data from client. Closing client.\n");
LABEL_7:
func4(a1, *(_QWORD *)v7);
func2((void *)v7);
goto LABEL_8;
}
v5 = *(_DWORD *)(*(_QWORD *)(a1 + 16) + v3);
goto LABEL_6;
}
return v2;
}
v12 = *_errno_location();
if ( v12 == 4 )
return v2;
v13 = strerror(v12);
log_fatal("An error occured while waiting for fd events: %s.", v13);
return v2;
}

original_code:
int net_poll(net_server *s) {
    int num_events = epoll_wait(s->epfd, s->events, s->max_events, -1);
    if(num_events == -1 && (*__errno_location ()) != 4) {
        log_fatal("An error occured while waiting for fd events: %s.", strerror((*__errno_location ())));
    }
    int i, num_read;
    for(i = 0; i < num_events; i++) {
        net_file_event *fe = (net_file_event *) s->events[i].data.ptr;
        if(fe->type == net_file_event_type_client) {
            if(s->events[i].events & EPOLLIN) {
                if((num_read = net_client_read((net_client *)fe->ptr)) <= 0) {
                    if(num_read == -1)
                        log_error("Failed to read data from client. Closing client.\n");
                    net_client_close(s, (net_client *)fe->ptr);
                    net_file_event_destroy(fe);
                    continue;
                }
            }
            if (s->events[i].events & EPOLLOUT) {
                if(net_client_write((net_client *)fe->ptr) == -1) {
                    log_error("Failed to write data from client. Closing client.\n");
                    net_client_close(s, (net_client *)fe->ptr);
                    net_file_event_destroy(fe);
                    continue;
                }
            }
            if (s->events[i].events & EPOLLHUP || s->events[i].events & EPOLLERR) {
                net_client_close(s, (net_client *)fe->ptr);
                net_file_event_destroy(fe);
            }
        }
        else if(fe->type == net_file_event_type_server && s->events[i].events & EPOLLIN) {
            net_client *c = net_server_accept((net_server *)fe->ptr);
            if(!c) {
                log_info("Failed to accept client connection: %s\n", strerror((*__errno_location ())));
            } else {
                log_info("Client %s:%d connected\n", c->ip, c->port);
            }
        }
    }
    return num_events;
}

canonical_original_code:
int net_poll(struct net_server *s) {
    int num_events = epoll_wait(s->epfd, s->events, s->max_events, -1);
    if(num_events == -1 && (*__errno_location ()) != 4) {
        log_fatal("An error occured while waiting for fd events: %s.", strerror((*__errno_location ())));
    }
    int i; int num_read;
    for(i = 0; i < num_events; i++) {
        struct net_file_event *fe = (net_file_event *) s->events[i].data.ptr;
        if(fe->type == net_file_event_type_client) {
            if(s->events[i].events & EPOLLIN) {
                if((num_read = net_client_read((struct net_client *)fe->ptr)) <= 0) {
                    if(num_read == -1)
                        log_error("Failed to read data from client. Closing client.\n");
                    net_client_close(s, (struct net_client *)fe->ptr);
                    net_file_event_destroy(fe);
                    continue;
                }
            }
            if (s->events[i].events & EPOLLOUT) {
                if(net_client_write((struct net_client *)fe->ptr) == -1) {
                    log_error("Failed to write data from client. Closing client.\n");
                    net_client_close(s, (struct net_client *)fe->ptr);
                    net_file_event_destroy(fe);
                    continue;
                }
            }
            if (s->events[i].events & EPOLLHUP || s->events[i].events & EPOLLERR) {
                net_client_close(s, (struct net_client *)fe->ptr);
                net_file_event_destroy(fe);
            }
        }
        else if(fe->type == net_file_event_type_server && s->events[i].events & EPOLLIN) {
            struct net_client *c = net_server_accept((net_server *)fe->ptr);
            if(!c) {
                log_info("Failed to accept client connection: %s\n", strerror((*__errno_location ())));
            } else {
                log_info("Client %s:%d connected\n", c->ip, c->port);
            }
        }
    }
    return num_events;
}

variable_types: i int


decompiled_code:
char *get_current_datetime()
{
struct tm *v0; // rax
time_t timer; // [rsp+8h] [rbp-10h] BYREF

timer = time(0LL);
v0 = localtime(&timer);
strftime(buf_0, 0x32uLL, "%Y-%m-%d %H:%M:%S", v0);
return buf_0;
}

canonical_decompiled_code:
char *func0()
{
struct tm *v0; // rax
time_t timer; // [rsp+8h] [rbp-10h] BYREF

timer = time(0LL);
v0 = localtime(&timer);
strftime(buf_0, 0x32uLL, "%Y-%m-%d %H:%M:%S", v0);
return buf_0;
}

original_code:
static const char *get_current_datetime(void) {
    static char buf[50];
    time_t t = time(((void *)0));
    const struct tm *loctime = (const struct tm *) localtime(&t);
    strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M:%S", loctime);
    return buf;
}

canonical_original_code:
static char *get_current_datetime() {
    static char buf[50];
    long t = time(((void *)0));
    struct tm *loctime = (const struct tm *) localtime(&t);
    strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M:%S", loctime);
    return buf;
}

variable_types:
buf
char [50]

variable_types: t long

variable_types: struct tm { int tm_sec; int tm_min; int tm_hour; int tm_mday; int tm_mon; int tm_year; int tm_wday; int tm_yday; int tm_isdst; long __tm_gmtoff; char *__tm_zone; } *


decompiled_code:
int log_info(const char *a1, ...)
{
gcc_va_list va; // [rsp+8h] [rbp-D0h] BYREF

va_start(va, a1);
return output_log_msg("INFO", stdout, a1, va);
}

canonical_decompiled_code:
int func2(const char *a1, ...)
{
gcc_va_list va; // [rsp+8h] [rbp-D0h] BYREF

va_start(va, a1);
return func1("INFO", stdout, a1, va);
}

original_code:
void log_info(const char *format, ...) {
    va_list ap;
    __builtin_va_start(ap,format);
    output_log_msg("INFO", stdout, format, ap);
    __builtin_va_end(ap);
}

canonical_original_code:
void log_info(char *format, ...) {
    __builtin_va_list ap;
    __builtin_va_start(ap,format);
    output_log_msg("INFO", stdout, format, ap);
    __builtin_va_end(ap);
}

variable_types:
format
char *


decompiled_code:
int log_error(const char *a1, ...)
{
gcc_va_list va; // [rsp+8h] [rbp-D0h] BYREF

va_start(va, a1);
return output_log_msg("ERROR", stderr, a1, va);
}

canonical_decompiled_code:
int func3(const char *a1, ...)
{
gcc_va_list va; // [rsp+8h] [rbp-D0h] BYREF

va_start(va, a1);
return func1("ERROR", stderr, a1, va);
}

original_code:
void log_error(const char *format, ...) {
    va_list ap;
    __builtin_va_start(ap,format);
    output_log_msg("ERROR", stderr, format, ap);
    __builtin_va_end(ap);
}

canonical_original_code:
void log_error(char *format, ...) {
    __builtin_va_list ap;
    __builtin_va_start(ap,format);
    output_log_msg("ERROR", stderr, format, ap);
    __builtin_va_end(ap);
}