decompiled_code:
void __fastcall teardown_nanokontrol2(void *ptr)
{
teardown_midi();
free(ptr);
}

canonical_decompiled_code:
void __fastcall func4(void *ptr)
{
teardown_midi();
free(ptr);
}

original_code:
void
teardown_nanokontrol2(struct nanokontrol2_context *ctx) {
 teardown_midi(&ctx->midictx);
 free(ctx);
}


repo: villavanschaeck/schaeckeling

decompiled_code:
__int64 __fastcall nanokontrol2_ask_status(__int64 a1)
{
__int64 v2; // [rsp+5h] [rbp-13h] BYREF
__int16 v3; // [rsp+Dh] [rbp-Bh]
char v4; // [rsp+Fh] [rbp-9h]

v2 = 0x1F001301004042F0LL;
v3 = 16;
v4 = -9;
return midi_send_buf(a1, &v2, 11LL);
}

original_code:
void
nanokontrol2_ask_status(struct nanokontrol2_context *ctx) {
 unsigned char buf[] = { 0xf0, 0x42, 0x40, 0x00, 0x01, 0x13, 0x00, 0x1f, 0x10, 0x00, 0xf7 };
 midi_send_buf(&ctx->midictx, buf, 11);
}

variable_types: struct nanokontrol2_context { struct midi_context { int fd; unsigned long thr; int running; int (*eater)(void *ctx, unsigned char *buffer, int len); } midictx; int active_mode; int requested_mode; } *

variable_types:
buf
unsigned char []

return_type: void

user_defined_types: struct nanokontrol2_context { struct midi_context midictx; int active_mode; int requested_mode; }


decompiled_code:
ssize_t __fastcall midi_reader(__int64 a1)
{
int v1; // er12
ssize_t result; // rax
int i; // er13
int v4; // eax
char src[552]; // [rsp+0h] [rbp-228h] BYREF

v1 = 0;
*(_DWORD *)(a1 + 16) = 1;
while ( 1 )
{
result = read(*(_DWORD *)a1, &src[v1], 512LL - v1);
if ( (_DWORD)result == -1 )
break;
v1 += result;
for ( i = 0; ; i = 1 )
{
v4 = (*(__int64 (__fastcall **)(__int64, char *, _QWORD))(a1 + 24))(a1, src, (unsigned int)v1);
if ( v4 < 0 || v1 < v4 )
_assert_fail("eat >= 0 && eat <= bufpos", "mididriver.c", 0x32u, "midi_reader");
if ( !v4 )
break;
v1 -= v4;
memmove(src, &src[v4], v1);
}
if ( i )
midi_input_completed();
result = *(unsigned int *)(a1 + 16);
if ( !(_DWORD)result )
return result;
}
if ( *(_DWORD *)(a1 + 16) )
_assert_fail("ret != -1", "mididriver.c", 0x2Bu, "midi_reader");
return result;
}

canonical_decompiled_code:
ssize_t __fastcall func0(__int64 a1)
{
int v1; // er12
ssize_t result; // rax
int i; // er13
int v4; // eax
char src[552]; // [rsp+0h] [rbp-228h] BYREF

v1 = 0;
*(_DWORD *)(a1 + 16) = 1;
while ( 1 )
{
result = read(*(_DWORD *)a1, &src[v1], 512LL - v1);
if ( (_DWORD)result == -1 )
break;
v1 += result;
for ( i = 0; ; i = 1 )
{
v4 = (*(__int64 (__fastcall **)(__int64, char *, _QWORD))(a1 + 24))(a1, src, (unsigned int)v1);
if ( v4 < 0 || v1 < v4 )
_assert_fail("eat >= 0 && eat <= bufpos", "mididriver.c", 0x32u, "midi_reader");
if ( !v4 )
break;
v1 -= v4;
memmove(src, &src[v4], v1);
}
if ( i )
midi_input_completed();
result = *(unsigned int *)(a1 + 16);
if ( !(_DWORD)result )
return result;
}
if ( *(_DWORD *)(a1 + 16) )
_assert_fail("ret != -1", "mididriver.c", 0x2Bu, "midi_reader");
return result;
}

original_code:
static void
midi_reader(struct midi_context *ctx) {
 unsigned char buffer[512];
 int bufpos = 0;
 ctx->running = 1;
 while(ctx->running) {
  int ret = read(ctx->fd, buffer+bufpos, sizeof(buffer) - bufpos);
  if(ret == -1 && !ctx->running) {
   break;
  }
  ((ret != -1) ? (void) (0) : __assert_fail ("ret != -1", "mididriver.c", 43, __extension__ __PRETTY_FUNCTION__));
  bufpos += ret;
  int eat;
  int did_something = 0;
  do {
   eat = ctx->eater(ctx, buffer, bufpos);
   ((eat >= 0 && eat <= bufpos) ? (void) (0) : __assert_fail ("eat >= 0 && eat <= bufpos", "mididriver.c", 50, __extension__ __PRETTY_FUNCTION__));
   if(eat == 0) {
    break;
   }
   did_something = 1;
   bufpos -= eat;
   memmove(buffer, buffer + eat, bufpos);
  } while(eat > 0);
  if(did_something) {
   midi_input_completed();
  }
 }
}

variable_types: struct midi_context { int fd; unsigned long thr; int running; int (*eater)(void *ctx, unsigned char *buffer, int len); } *

variable_types:
buffer
unsigned char [512]

variable_types: bufpos int

variable_types: ret int

variable_types: eat int


decompiled_code:
void *__fastcall midi_read_thread(void *a1)
{
midi_reader((__int64)a1);
return 0LL;
}

canonical_decompiled_code:
void *__fastcall func1(void *a1)
{
func0((__int64)a1);
return 0LL;
}

original_code:
static void *
midi_read_thread(void *ctx) {
 midi_reader(ctx);
 return ((void *)0);
}

canonical_original_code:
static void *midi_read_thread(void *ctx) {
 midi_reader(ctx);
 return ((void *)0);
}

variable_types:
ctx
void *

return_type: void *


decompiled_code:
int __fastcall midi_print_buf(const char *a1, __int64 a2, int a3)
{
__int64 v3; // r13
int result; // eax
__int64 i; // rbx
__int64 v7; // rdx
__int64 v8; // rsi

v3 = a3;
result = printf("%s", a1);
if ( (int)v3 > 0 )
{
for ( i = 0LL; i != v3; ++i )
{
v7 = 10LL;
v8 = *(unsigned __int8 *)(a2 + i);
if ( (_DWORD)v3 - 1 != (_DWORD)i )
v7 = 32LL;
result = printf("%02x%c", v8, v7);
}
}
return result;
}

canonical_decompiled_code:
int __fastcall func2(const char *a1, __int64 a2, int a3)
{
__int64 v3; // r13
int result; // eax
__int64 i; // rbx
__int64 v7; // rdx
__int64 v8; // rsi

v3 = a3;
result = printf("%s", a1);
if ( (int)v3 > 0 )
{
for ( i = 0LL; i != v3; ++i )
{
v7 = 10LL;
v8 = *(unsigned __int8 *)(a2 + i);
if ( (_DWORD)v3 - 1 != (_DWORD)i )
v7 = 32LL;
result = printf("%02x%c", v8, v7);
}
}
return result;
}

original_code:
void
midi_print_buf(const char *prefix, const unsigned char *buf, int len) {
 int i;
 printf("%s", prefix);
 for(i = 0; len > i; i++) {
  printf("%02x%c", buf[i], i == len-1 ? '\n' : ' ');
 }
}

canonical_original_code:
void midi_print_buf(char *prefix, unsigned char *buf, int len) {
 int i;
 printf("%s", prefix);
 for(i = 0; len > i; i++) {
  printf("%02x%c", buf[i], i == len-1 ? '\n' : ' ');
 }
}

variable_types:
prefix
char *

variable_types:
buf
unsigned char *

variable_types: len int

variable_types: i int


decompiled_code:
__int64 __fastcall midi_send_buf(int *a1, const void *a2, int a3)
{
midi_print_buf("> ", (__int64)a2, a3);
if ( a3 != (unsigned int)write(*a1, a2, a3) )
_assert_fail("ret == len", "mididriver.c", 0x1Bu, "midi_send_buf");
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(int *a1, const void *a2, int a3)
{
func2("> ", (__int64)a2, a3);
if ( a3 != (unsigned int)write(*a1, a2, a3) )
_assert_fail("ret == len", "mididriver.c", 0x1Bu, "midi_send_buf");
return 0LL;
}

original_code:
int
midi_send_buf(struct midi_context *ctx, const unsigned char *buf, const int len) {
 int ret;
 midi_print_buf("> ", buf, len);
 ret = write(ctx->fd, buf, len);
 ((ret == len) ? (void) (0) : __assert_fail ("ret == len", "mididriver.c", 27, __extension__ __PRETTY_FUNCTION__));
 return 0;
}

canonical_original_code:
int midi_send_buf(struct midi_context *ctx, unsigned char *buf, int len) {
 int ret;
 midi_print_buf("> ", buf, len);
 ret = write(ctx->fd, buf, len);
 ((ret == len) ? (void) (0) : __assert_fail ("ret == len", "mididriver.c", 27, __extension__ __PRETTY_FUNCTION__));
 return 0;
}

return_type: int

user_defined_types: struct midi_context { int fd; unsigned long thr; int running; int (*eater)(void *ctx, unsigned char *buffer, int len); }


decompiled_code:
int __fastcall teardown_midi(__int64 a1)
{
*(_DWORD *)(a1 + 16) = 0;
close(*(_DWORD *)a1);
return pthread_join(*(_QWORD *)(a1 + 8), 0LL);
}

canonical_decompiled_code:
int __fastcall func5(__int64 a1)
{
*(_DWORD *)(a1 + 16) = 0;
close(*(_DWORD *)a1);
return pthread_join(*(_QWORD *)(a1 + 8), 0LL);
}

original_code:
void
teardown_midi(struct midi_context *ctx) {
 ctx->running = 0;
 close(ctx->fd);
 pthread_join(ctx->thr, ((void *)0));
}


decompiled_code:
__int64 __fastcall convert_color(unsigned __int8 a1, __int64 a2)
{
__int64 v2; // rax
unsigned __int8 i; // dl
__int16 v5; // dx
__int64 result; // rax

v2 = 28LL;
for ( i = -4; i > a1; i = mapping[4 * v2] )
{
if ( v2-- == 0 )
_assert_fail("!\"reached\"", "colors.c", 0x38u, "convert_color");
}
v5 = word_A1[2 * (int)v2];
result = (unsigned __int8)byte_A3[4 * (int)v2];
*(_WORD *)a2 = v5;
*(_BYTE *)(a2 + 2) = result;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned __int8 a1, __int64 a2)
{
__int64 v2; // rax
unsigned __int8 i; // dl
__int16 v5; // dx
__int64 result; // rax

v2 = 28LL;
for ( i = -4; i > a1; i = mapping[4 * v2] )
{
if ( v2-- == 0 )
_assert_fail("!\"reached\"", "colors.c", 0x38u, "convert_color");
}
v5 = word_A1[2 * (int)v2];
result = (unsigned __int8)byte_A3[4 * (int)v2];
*(_WORD *)a2 = v5;
*(_BYTE *)(a2 + 2) = result;
return result;
}

original_code:
void
convert_color(unsigned char input, unsigned char *output) {
 int i;
 for(i = sizeof(mapping) / sizeof(struct mapping_entry) - 1; i >= 0; i--) {
  if(input >= mapping[i].from) {
   output[0] = mapping[i].red;
   output[1] = mapping[i].green;
   output[2] = mapping[i].blue;
   return;
  }
 }
 ((!"reached") ? (void) (0) : __assert_fail ("!\"reached\"", "colors.c", 56, __extension__ __PRETTY_FUNCTION__));
}

variable_types:
input
unsigned char

variable_types:
output
unsigned char *

user_defined_types: struct mapping_entry { unsigned char from; unsigned char red; unsigned char green; unsigned char blue; }


main

canonical_name: main

repo: vilmart/kfs

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int i; // ebx
__int64 v4; // rdx
int result; // eax

for ( i = 1; i != 33; ++i )
{
while ( signal(i, signal_handler) != (__sighandler_t)-1LL )
{
if ( ++i == 33 )
goto LABEL_5;
}
v4 = i;
fprintf(stderr, "signal32: signal %d could not be registered.\n", v4);
}
LABEL_5:
result = wait;
while ( wait )
;
return result;
}

original_code:
int main ()
{
  int i;
  for (i = 1; i <= 32; i++)
    {
      if (signal (i, signal_handler) == ((__sighandler_t) -1))
        fprintf (stderr, "signal32: signal %d could not be registered.\n", i);
    }
  while (wait);
  return 0;
}

canonical_original_code:
int main()
{
  int i;
  for (i = 1; i <= 32; i++)
    {
      if (signal (i, signal_handler) == ((__sighandler_t) -1))
        fprintf (stderr, "signal32: signal %d could not be registered.\n", i);
    }
  while (wait);
  return 0;
}


decompiled_code:
void __fastcall signal_handler(unsigned int a1)
{
fprintf(stderr, "signal32: signal received: %d\n", a1);
if ( a1 == 2 )
{
fwrite("Finishing...\n", 1uLL, 0xDuLL, stderr);
wait = 0;
}
}

canonical_decompiled_code:
void __fastcall func7(unsigned int a1)
{
fprintf(stderr, "signal32: signal received: %d\n", a1);
if ( a1 == 2 )
{
fwrite("Finishing...\n", 1uLL, 0xDuLL, stderr);
wait = 0;
}
}

original_code:
void signal_handler (int signum)
{
  fprintf (stderr, "signal32: signal received: %d\n", signum);
  if (signum == 2)
    {
      fprintf (stderr, "Finishing...\n");
      wait = 0;
    }
}

canonical_original_code:
void signal_handler(int signum)
{
  fprintf (stderr, "signal32: signal received: %d\n", signum);
  if (signum == 2)
    {
      fprintf (stderr, "Finishing...\n");
      wait = 0;
    }
}

variable_types: signum int


decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
char *v3; // rbp
int v4; // er12
unsigned int v5; // er13
const void *v6; // r15
unsigned __int8 v7; // al
unsigned __int8 v8; // bl
bool v9; // cf
bool v10; // zf
__int64 v11; // rcx
const char *v12; // rsi
const char *v13; // rdi
char *v14; // r13
signed __int64 v15; // rsi
char *v16; // r14
size_t v17; // rax
char *v18; // r14
const char *v19; // rax
size_t v20; // rax
char *v21; // r13
unsigned int v22; // er13
unsigned __int8 *v23; // [rsp+8h] [rbp-80h]
FILE *s; // [rsp+10h] [rbp-78h]
unsigned int v25; // [rsp+18h] [rbp-70h]
unsigned int v26; // [rsp+1Ch] [rbp-6Ch]
const char *v27; // [rsp+20h] [rbp-68h]
struct timeval tv; // [rsp+30h] [rbp-58h] BYREF
struct timeval v29; // [rsp+40h] [rbp-48h] BYREF

setbuf(_bss_start, 0LL);
v23 = (unsigned __int8 *)tramp_initialize();
v27 = (const char *)tramp_initialize();
v3 = (char *)malloc(0x50000uLL);
tramp_get();
tramp_subscribe();
printf("%c[%d;%dm", 27LL, 1LL, 34LL);
printf("Waiting for messages from %s...", v27);
printf("%c[%dm\n", 27LL, 0LL);
if ( (unsigned int)createFolder("./downloads") )
puts("Failed to create folder downloads");
v26 = 0;
v4 = -1;
v25 = 1;
v5 = *v23;
v6 = v23 + 1;
v7 = 0;
while ( 1 )
{
do
v8 = v5;
while ( (unsigned __int8)v5 <= v7 && (v7 != 0xFF || (_BYTE)v5 != 1) );
gettimeofday(&tv, 0LL);
memcpy(v3, v6, 0x4FFFFuLL);
printf("Seq: %d\n", v5);
v11 = 5LL;
v12 = v3;
v13 = "file:";
do
{
if ( !v11 )
break;
v9 = *v12 < (unsigned int)*v13;
v10 = *v12++ == *v13++;
--v11;
}
while ( v10 );
if ( (!v9 && !v10) == v9 )
break;
if ( v4 >= 0 )
{
v22 = GetInt32(v3, v12);
printf("size of packet %u\n", v22);
v26 += fwrite(v3 + 4, 1uLL, v22, s);
printf("received so far: %d bytes %d packets \n", v26, v25);
fflush(s);
if ( v4 == v26 )
{
v4 = -1;
fclose(s);
printf("Number of packets received: %d", v25);
v26 = 0;
}
gettimeofday(&v29, 0LL);
printf("processing delay: %f\n", ((double)SLODWORD(v29.tv_usec) - (double)SLODWORD(tv.tv_usec)) * 0.5);
LABEL_12:
v5 = *v23;
v7 = v8;
++v25;
}
else
{
printf("%c[%d;%dm", 27LL, 1LL, 32LL);
printf("[%u] ", v5);
printf("%c[%d;%dm", 27LL, 1LL, 35LL);
printf("<%s> ", v27);
printf("%c[%d;%dm", 27LL, 1LL, 37LL);
printf("%s", (const char *)v6);
printf("%c[%dm\n", 27LL, 0LL);
v5 = *v23;
v7 = v8;
}
}
puts("got file header");
v14 = strchr(v3, 124);
puts(v14);
v15 = v14 - v3;
++v14;
v16 = (char *)substring(5LL, v15, v3);
puts(v16);
v4 = atoi(v16);
free(v16);
v17 = strlen(v14);
v18 = (char *)substring(0LL, v17, v14);
v19 = (const char *)trim(v18);
printf("%s,%d\n", v19, (unsigned int)v4);
v20 = strlen(v18);
v21 = (char *)malloc(v20 + 13);
strcpy(v21, "./downloads/");
strcat(v21, v18);
s = fopen(v21, "wb+");
free(v18);
free(v21);
goto LABEL_12;
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
char *v3; // rbp
int v4; // er12
unsigned int v5; // er13
const void *v6; // r15
unsigned __int8 v7; // al
unsigned __int8 v8; // bl
bool v9; // cf
bool v10; // zf
__int64 v11; // rcx
const char *v12; // rsi
const char *v13; // rdi
char *v14; // r13
signed __int64 v15; // rsi
char *v16; // r14
size_t v17; // rax
char *v18; // r14
const char *v19; // rax
size_t v20; // rax
char *v21; // r13
unsigned int v22; // er13
unsigned __int8 *v23; // [rsp+8h] [rbp-80h]
FILE *s; // [rsp+10h] [rbp-78h]
unsigned int v25; // [rsp+18h] [rbp-70h]
unsigned int v26; // [rsp+1Ch] [rbp-6Ch]
const char *v27; // [rsp+20h] [rbp-68h]
struct timeval tv; // [rsp+30h] [rbp-58h] BYREF
struct timeval v29; // [rsp+40h] [rbp-48h] BYREF

setbuf(_bss_start, 0LL);
v23 = (unsigned __int8 *)tramp_initialize();
v27 = (const char *)tramp_initialize();
v3 = (char *)malloc(0x50000uLL);
tramp_get();
tramp_subscribe();
printf("%c[%d;%dm", 27LL, 1LL, 34LL);
printf("Waiting for messages from %s...", v27);
printf("%c[%dm\n", 27LL, 0LL);
if ( (unsigned int)func11("./downloads") )
puts("Failed to create folder downloads");
v26 = 0;
v4 = -1;
v25 = 1;
v5 = *v23;
v6 = v23 + 1;
v7 = 0;
while ( 1 )
{
do
v8 = v5;
while ( (unsigned __int8)v5 <= v7 && (v7 != 0xFF || (_BYTE)v5 != 1) );
gettimeofday(&tv, 0LL);
memcpy(v3, v6, 0x4FFFFuLL);
printf("Seq: %d\n", v5);
v11 = 5LL;
v12 = v3;
v13 = "file:";
do
{
if ( !v11 )
break;
v9 = *v12 < (unsigned int)*v13;
v10 = *v12++ == *v13++;
--v11;
}
while ( v10 );
if ( (!v9 && !v10) == v9 )
break;
if ( v4 >= 0 )
{
v22 = func8(v3, v12);
printf("size of packet %u\n", v22);
v26 += fwrite(v3 + 4, 1uLL, v22, s);
printf("received so far: %d bytes %d packets \n", v26, v25);
fflush(s);
if ( v4 == v26 )
{
v4 = -1;
fclose(s);
printf("Number of packets received: %d", v25);
v26 = 0;
}
gettimeofday(&v29, 0LL);
printf("processing delay: %f\n", ((double)SLODWORD(v29.tv_usec) - (double)SLODWORD(tv.tv_usec)) * 0.5);
LABEL_12:
v5 = *v23;
v7 = v8;
++v25;
}
else
{
printf("%c[%d;%dm", 27LL, 1LL, 32LL);
printf("[%u] ", v5);
printf("%c[%d;%dm", 27LL, 1LL, 35LL);
printf("<%s> ", v27);
printf("%c[%d;%dm", 27LL, 1LL, 37LL);
printf("%s", (const char *)v6);
printf("%c[%dm\n", 27LL, 0LL);
v5 = *v23;
v7 = v8;
}
}
puts("got file header");
v14 = strchr(v3, 124);
puts(v14);
v15 = v14 - v3;
++v14;
v16 = (char *)func10(5LL, v15, v3);
puts(v16);
v4 = atoi(v16);
free(v16);
v17 = strlen(v14);
v18 = (char *)func10(0LL, v17, v14);
v19 = (const char *)func7(v18);
printf("%s,%d\n", v19, (unsigned int)v4);
v20 = strlen(v18);
v21 = (char *)malloc(v20 + 13);
strcpy(v21, "./downloads/");
strcat(v21, v18);
s = fopen(v21, "wb+");
free(v18);
free(v21);
goto LABEL_12;
}

original_code:
int main(int argc, char *argv[]) {
 daemonize();
 setbuf(stdout, ((void *)0));
 int ret = -1;
 pthread_t dbus_thread;
 ret = pthread_create(&dbus_thread, ((void *)0), dbus_listen, ((void *)0));
 if(ret != 0) {
  fprintf(stderr, "Could not create RPC thread!\n");
  exit(1);
 }
 bootstrap();
 pthread_t server_thread;
 ret = pthread_create(&server_thread, ((void *)0), server_listen, ((void *)0));
 if(ret != 0) {
  fprintf(stderr, "Could not create TRAMP daemon server thread!\n");
  exit(1);
 }
 fprintf(stderr, "READY!\n");
 pthread_join(dbus_thread, ((void *)0));
 pthread_join(server_thread, ((void *)0));
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[]) {
 daemonize();
 setbuf(stdout, ((void *)0));
 int ret = -1;
 unsigned long dbus_thread;
 ret = pthread_create(&dbus_thread, ((void *)0), dbus_listen, ((void *)0));
 if(ret != 0) {
  fprintf(stderr, "Could not create RPC thread!\n");
  exit(1);
 }
 bootstrap();
 unsigned long server_thread;
 ret = pthread_create(&server_thread, ((void *)0), server_listen, ((void *)0));
 if(ret != 0) {
  fprintf(stderr, "Could not create TRAMP daemon server thread!\n");
  exit(1);
 }
 fprintf(stderr, "READY!\n");
 pthread_join(dbus_thread, ((void *)0));
 pthread_join(server_thread, ((void *)0));
 return 0;
}

variable_types: argc int

variable_types:
argv
char *[]


trim

decompiled_code:
const char *__fastcall trim(const char *a1)
{
const char *i; // rbx

if ( a1 && *a1 )
{
for ( i = &a1[strlen(a1) - 1]; a1 <= i; --i )
{
if ( !isspace(*i) )
break;
}
*((_BYTE *)i + 1) = 0;
}
return a1;
}

canonical_decompiled_code:
const char *__fastcall func7(const char *a1)
{
const char *i; // rbx

if ( a1 && *a1 )
{
for ( i = &a1[strlen(a1) - 1]; a1 <= i; --i )
{
if ( !isspace(*i) )
break;
}
*((_BYTE *)i + 1) = 0;
}
return a1;
}

original_code:
char *trim(char *s) {
    char *ptr;
    if (!s)
        return ((void *)0);
    if (!*s)
        return s;
    for (ptr = s + strlen(s) - 1; (ptr >= s) && isspace(*ptr); --ptr);
    ptr[1] = '\0';
    return s;
}

variable_types:
s
char *

variable_types:
ptr
char *

return_type: char *


decompiled_code:
__int64 __fastcall GetInt32(unsigned int *a1)
{
return *a1;
}

canonical_decompiled_code:
__int64 __fastcall func8(unsigned int *a1)
{
return *a1;
}

original_code:
uint32 GetInt32( byte *pBytes )
{
    return (uint32)(*(pBytes + 3) << 24 | *(pBytes + 2) << 16 | *(pBytes + 1) << 8 | *pBytes);
}

canonical_original_code:
unsigned int GetInt32(unsigned char *pBytes)
{
    return (uint32)(*(pBytes + 3) << 24 | *(pBytes + 2) << 16 | *(pBytes + 1) << 8 | *pBytes);
}

variable_types:
pBytes
unsigned char *

return_type: unsigned int


writeFile

decompiled_code:
void __fastcall __noreturn writeFile(__int64 a1)
{
printf("THREAD[%ld]: Hello world from thread: %ld\n", a1, a1);
sleep(5u);
printf("THREAD[%ld]: I'm done\n", a1);
pthread_exit(0LL);
}

canonical_decompiled_code:
void __fastcall __noreturn func9(__int64 a1)
{
printf("THREAD[%ld]: Hello world from thread: %ld\n", a1, a1);
sleep(5u);
printf("THREAD[%ld]: I'm done\n", a1);
pthread_exit(0LL);
}

original_code:
void *writeFile(void *threadid){
    long tid;
    tid = (long)threadid;
    printf("THREAD[%ld]: Hello world from thread: %ld\n", tid, tid);
    sleep(5);
    printf("THREAD[%ld]: I'm done\n", tid);
    pthread_exit(((void *)0));
}

variable_types:
threadid
void *

variable_types: tid long


substring

decompiled_code:
char *__fastcall substring(unsigned int a1, unsigned int a2, const char *a3)
{
char *v4; // r12

v4 = (char *)malloc((int)(a2 - a1 + 1));
printf("%d, %d, %s\n", a1, a2, a3);
sprintf(v4, "%.*s\n", a2 - a1, &a3[a1]);
return v4;
}

canonical_decompiled_code:
char *__fastcall func10(unsigned int a1, unsigned int a2, const char *a3)
{
char *v4; // r12

v4 = (char *)malloc((int)(a2 - a1 + 1));
printf("%d, %d, %s\n", a1, a2, a3);
sprintf(v4, "%.*s\n", a2 - a1, &a3[a1]);
return v4;
}

original_code:
char* substring(int start, int stop, const char *text)
{
    char *substring = (char *)(malloc(stop - start+1));
    printf("%d, %d, %s\n",start, stop, text);
   sprintf(substring, "%.*s\n", stop - start, &text[start]);
   return substring;
}

canonical_original_code:
char *substring(int start, int stop, char *text)
{
    char *substring = (char *)(malloc(stop - start+1));
    printf("%d, %d, %s\n",start, stop, text);
   sprintf(substring, "%.*s\n", stop - start, &text[start]);
   return substring;
}

variable_types: start int

variable_types: stop int

variable_types:
text
char *

variable_types:
substring
char *


createFolder

decompiled_code:
__int64 createFolder()
{
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 func11()
{
return 0xFFFFFFFFLL;
}

original_code:
int createFolder(char* folder_name)
{
    return -1;
}

canonical_original_code:
int createFolder(char *folder_name)
{
    return -1;
}


main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
void *v3; // r13
const char *v4; // rbp
size_t v5; // rax
int v6; // ebp
char *v7; // r15
bool v8; // zf
unsigned int v9; // er12
const char *v10; // rax
FILE *v11; // rax
FILE *v12; // r14
char *v13; // rax
const char *v14; // rcx
char *v15; // rax
unsigned int v16; // ebx
unsigned int v17; // eax
unsigned __int8 *v18; // [rsp+0h] [rbp-88h]
unsigned int v19; // [rsp+8h] [rbp-80h]
unsigned int v20; // [rsp+Ch] [rbp-7Ch]
char *s; // [rsp+18h] [rbp-70h]
char *dest; // [rsp+20h] [rbp-68h]
struct timeval tv; // [rsp+30h] [rbp-58h] BYREF
struct timeval v24; // [rsp+40h] [rbp-48h] BYREF

setbuf(stdout, 0LL);
v18 = (unsigned __int8 *)tramp_initialize();
dest = (char *)tramp_initialize();
puts("finished tramp init");
v3 = malloc(0x50000uLL);
s = (char *)malloc(0x50uLL);
tramp_publish();
tramp_publish();
*((_DWORD *)dest + 4) = 0;
*(_OWORD *)dest = 0LL;
v4 = argv[1];
if ( v4 )
{
v5 = strlen(argv[1]);
strncpy(dest, v4, v5);
}
else
{
strcpy(dest, "Anonymous");
}
v19 = 0;
v6 = *v18;
v7 = (char *)(v18 + 1);
while ( 1 )
{
printf("<%s> ", dest);
fgets((char *)v3, 8000, stdin);
v8 = memcmp(v3, "send", 4uLL) == 0;
v9 = !v8;
if ( !v8 )
break;
puts("inside send");
strcpy(s, (const char *)v3 + 5);
v10 = (const char *)trim(s);
v11 = fopen(v10, "r");
v12 = v11;
if ( v11 )
{
fseek(v11, 0LL, 2);
v20 = ftell(v12);
fseek(v12, 0LL, 0);
puts("file open complete");
v13 = strrchr(s, 47);
v14 = v13 + 1;
if ( !v13 )
v14 = s;
sprintf(v7, "file:%d|%s", v20, v14);
++v6;
++v19;
*v18 = v6;
v15 = strrchr(s, 47);
if ( v15 )
printf("seq: %d file_size: %d file_name: %s\n", (unsigned __int8)v6, v20, v15 + 1);
else
printf("seq: %d file_size: %d file_name: %s\n", (unsigned __int8)v6, v20, s);
sleep(2u);
gettimeofday(&tv, 0LL);
do
{
++v6;
printf("size of chat_msg: %d\n", 8LL);
v16 = fread(v3, 1uLL, 0x4FFFBuLL, v12);
memcpy(v18 + 5, v3, v16);
v9 += v16;
intToBytes(v16, v7);
v17 = GetInt32(v7);
printf("num bytes from the chat_msg: %u\n", v17);
++v19;
*v18 = v6;
printf("seq: %d Bytes read : %u\n", (unsigned __int8)v6, v16);
if ( (int)v20 <= (int)v9 )
{
puts("all bytes sent");
printf("num packets sent: %d, bytes: %d ", v19, v9);
goto LABEL_17;
}
usleep(0x7A120u);
}
while ( v16 );
printf("0 bytes read");
LABEL_17:
gettimeofday(&v24, 0LL);
printf("processing delay: %f\n", ((double)SLODWORD(v24.tv_usec) - (double)SLODWORD(tv.tv_usec)) * 0.5);
LABEL_8:
printf("%d size: ", 80LL);
}
else
{
fprintf(stderr, "can't open file %s", s);
}
}
++v6;
strcpy(v7, (const char *)v3);
++v19;
*v18 = v6;
goto LABEL_8;
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
void *v3; // r13
const char *v4; // rbp
size_t v5; // rax
int v6; // ebp
char *v7; // r15
bool v8; // zf
unsigned int v9; // er12
const char *v10; // rax
FILE *v11; // rax
FILE *v12; // r14
char *v13; // rax
const char *v14; // rcx
char *v15; // rax
unsigned int v16; // ebx
unsigned int v17; // eax
unsigned __int8 *v18; // [rsp+0h] [rbp-88h]
unsigned int v19; // [rsp+8h] [rbp-80h]
unsigned int v20; // [rsp+Ch] [rbp-7Ch]
char *s; // [rsp+18h] [rbp-70h]
char *dest; // [rsp+20h] [rbp-68h]
struct timeval tv; // [rsp+30h] [rbp-58h] BYREF
struct timeval v24; // [rsp+40h] [rbp-48h] BYREF

setbuf(stdout, 0LL);
v18 = (unsigned __int8 *)tramp_initialize();
dest = (char *)tramp_initialize();
puts("finished tramp init");
v3 = malloc(0x50000uLL);
s = (char *)malloc(0x50uLL);
tramp_publish();
tramp_publish();
*((_DWORD *)dest + 4) = 0;
*(_OWORD *)dest = 0LL;
v4 = argv[1];
if ( v4 )
{
v5 = strlen(argv[1]);
strncpy(dest, v4, v5);
}
else
{
strcpy(dest, "Anonymous");
}
v19 = 0;
v6 = *v18;
v7 = (char *)(v18 + 1);
while ( 1 )
{
printf("<%s> ", dest);
fgets((char *)v3, 8000, stdin);
v8 = memcmp(v3, "send", 4uLL) == 0;
v9 = !v8;
if ( !v8 )
break;
puts("inside send");
strcpy(s, (const char *)v3 + 5);
v10 = (const char *)func9(s);
v11 = fopen(v10, "r");
v12 = v11;
if ( v11 )
{
fseek(v11, 0LL, 2);
v20 = ftell(v12);
fseek(v12, 0LL, 0);
puts("file open complete");
v13 = strrchr(s, 47);
v14 = v13 + 1;
if ( !v13 )
v14 = s;
sprintf(v7, "file:%d|%s", v20, v14);
++v6;
++v19;
*v18 = v6;
v15 = strrchr(s, 47);
if ( v15 )
printf("seq: %d file_size: %d file_name: %s\n", (unsigned __int8)v6, v20, v15 + 1);
else
printf("seq: %d file_size: %d file_name: %s\n", (unsigned __int8)v6, v20, s);
sleep(2u);
gettimeofday(&tv, 0LL);
do
{
++v6;
printf("size of chat_msg: %d\n", 8LL);
v16 = fread(v3, 1uLL, 0x4FFFBuLL, v12);
memcpy(v18 + 5, v3, v16);
v9 += v16;
func7(v16, v7);
v17 = func8(v7);
printf("num bytes from the chat_msg: %u\n", v17);
++v19;
*v18 = v6;
printf("seq: %d Bytes read : %u\n", (unsigned __int8)v6, v16);
if ( (int)v20 <= (int)v9 )
{
puts("all bytes sent");
printf("num packets sent: %d, bytes: %d ", v19, v9);
goto LABEL_17;
}
usleep(0x7A120u);
}
while ( v16 );
printf("0 bytes read");
LABEL_17:
gettimeofday(&v24, 0LL);
printf("processing delay: %f\n", ((double)SLODWORD(v24.tv_usec) - (double)SLODWORD(tv.tv_usec)) * 0.5);
LABEL_8:
printf("%d size: ", 80LL);
}
else
{
fprintf(stderr, "can't open file %s", s);
}
}
++v6;
strcpy(v7, (const char *)v3);
++v19;
*v18 = v6;
goto LABEL_8;
}

variable_types: ret int


intToBytes

decompiled_code:
void __fastcall intToBytes(int a1, _DWORD *a2)
{
*a2 = a1;
}

canonical_decompiled_code:
void __fastcall func7(int a1, _DWORD *a2)
{
*a2 = a1;
}

original_code:
void intToBytes( uint32 val, byte *pBytes )
{
    pBytes[0] = (byte)val;
    pBytes[1] = (byte)(val >> 8);
    pBytes[2] = (byte)(val >> 16);
    pBytes[3] = (byte)(val >> 24);
}

canonical_original_code:
void intToBytes(unsigned int val, unsigned char *pBytes)
{
    pBytes[0] = (unsigned char)val;
    pBytes[1] = (byte)(val >> 8);
    pBytes[2] = (byte)(val >> 16);
    pBytes[3] = (byte)(val >> 24);
}

variable_types:
val
unsigned int


trim

canonical_decompiled_code:
const char *__fastcall func9(const char *a1)
{
const char *i; // rbx

if ( a1 && *a1 )
{
for ( i = &a1[strlen(a1) - 1]; a1 <= i; --i )
{
if ( !isspace(*i) )
break;
}
*((_BYTE *)i + 1) = 0;
}
return a1;
}

canonical_original_code:
char *trim(char *s) {
    char *ptr;
    if (!s)
        return ((void *)0);
    if (!*s)
        return s;
    for (ptr = s + strlen(s) - 1; (ptr >= s) && isspace(*ptr); --ptr);
    ptr[1] = '\0';
    return s;
}


decompiled_code:
void *__fastcall tramp_initialize(const char *a1, size_t a2)
{
unsigned int v2; // er13
int v3; // eax
__int64 v4; // r12
void *v5; // rax
void *v6; // r13

v2 = strtol(a1, 0LL, 36);
printf("Initializing label '%s' of size '%lu'. Key is '%x'.\n", a1, a2, v2);
v3 = shmget(v2, a2, 1920);
if ( v3 < 0 )
{
v4 = (unsigned int)shmget(v2, a2, 256);
printf("The segment is already present on this device with id '%d'.\n", v4);
if ( (int)v4 < 0 )
{
fwrite("Could not create data segment!\n", 1uLL, 0x1FuLL, stderr);
exit(1);
}
}
else
{
LODWORD(v4) = v3;
printf("The segment was not present on this device. Created it with id '%d'.\n", (unsigned int)v3);
}
v5 = shmat(v4, 0LL, 0);
v6 = v5;
if ( v5 == (void *)-1LL )
{
fwrite("Could not attach data segment!\n", 1uLL, 0x1FuLL, stderr);
exit(1);
}
printf(
"The segment with label '%s' located at '%p' with id '%d' is attached with flag '%d'.\n",
a1,
v5,
(unsigned int)v4,
0LL);
return v6;
}

canonical_decompiled_code:
void *__fastcall func6(const char *a1, size_t a2)
{
unsigned int v2; // er13
int v3; // eax
__int64 v4; // r12
void *v5; // rax
void *v6; // r13

v2 = strtol(a1, 0LL, 36);
printf("Initializing label '%s' of size '%lu'. Key is '%x'.\n", a1, a2, v2);
v3 = shmget(v2, a2, 1920);
if ( v3 < 0 )
{
v4 = (unsigned int)shmget(v2, a2, 256);
printf("The segment is already present on this device with id '%d'.\n", v4);
if ( (int)v4 < 0 )
{
fwrite("Could not create data segment!\n", 1uLL, 0x1FuLL, stderr);
exit(1);
}
}
else
{
LODWORD(v4) = v3;
printf("The segment was not present on this device. Created it with id '%d'.\n", (unsigned int)v3);
}
v5 = shmat(v4, 0LL, 0);
v6 = v5;
if ( v5 == (void *)-1LL )
{
fwrite("Could not attach data segment!\n", 1uLL, 0x1FuLL, stderr);
exit(1);
}
printf(
"The segment with label '%s' located at '%p' with id '%d' is attached with flag '%d'.\n",
a1,
v5,
(unsigned int)v4,
0LL);
return v6;
}

original_code:
void* tramp_initialize(char *label, size_t size) {
 char *shm = ((void *)0);
 int shmid = -1;
 int shmflg = 0;
 key_t key = strtol(label, ((void *)0), 36);
  printf("Initializing label '%s' of size '%lu'. Key is '%x'.\n", label, size, key);
 shmid = shmget(key, size, 01000 | 02000 | 0400 | 0200);
 if(shmid < 0) {
  shmid = shmget(key, size, 0 | 0400);
   printf("The segment is already present on this device with id '%d'.\n", shmid);
 } else {
   printf("The segment was not present on this device. Created it with id '%d'.\n", shmid);
 }
 if(shmid < 0) {
  fprintf(stderr, "Could not create data segment!\n");
  exit(1);
 }
 shm = (char *) shmat(shmid, ((void *)0), shmflg);
 if(shm == (char *) -1) {
  fprintf(stderr, "Could not attach data segment!\n");
  exit(1);
 }
  printf("The segment with label '%s' located at '%p' with id '%d' is attached with flag '%d'.\n", label, shm, shmid, shmflg);
 return shm;
}

canonical_original_code:
void *tramp_initialize(char *label, unsigned long size) {
 char *shm = ((void *)0);
 int shmid = -1;
 int shmflg = 0;
 int key = strtol(label, ((void *)0), 36);
  printf("Initializing label '%s' of size '%lu'. Key is '%x'.\n", label, size, key);
 shmid = shmget(key, size, 01000 | 02000 | 0400 | 0200);
 if(shmid < 0) {
  shmid = shmget(key, size, 0 | 0400);
   printf("The segment is already present on this device with id '%d'.\n", shmid);
 } else {
   printf("The segment was not present on this device. Created it with id '%d'.\n", shmid);
 }
 if(shmid < 0) {
  fprintf(stderr, "Could not create data segment!\n");
  exit(1);
 }
 shm = (char *) shmat(shmid, ((void *)0), shmflg);
 if(shm == (char *) -1) {
  fprintf(stderr, "Could not attach data segment!\n");
  exit(1);
 }
  printf("The segment with label '%s' located at '%p' with id '%d' is attached with flag '%d'.\n", label, shm, shmid, shmflg);
 return shm;
}

variable_types:
label
char *

variable_types:
size
unsigned long

variable_types:
shm
char *

variable_types: shmid int

variable_types: shmflg int

variable_types: key int


printMatrix

decompiled_code:
int printMatrix()
{
__int64 *v0; // r12
double *v1; // rbp
double *v2; // rbx
double v3; // xmm0_8
double v4; // xmm0_8
int result; // eax

v0 = Y;
v1 = (double *)&unk_40FC00;
do
{
v2 = v1 - 2000;
do
{
v3 = *v2++;
printf("%7.3f ", v3);
}
while ( v2 != v1 );
v4 = *(double *)v0;
v1 = v2 + 2000;
++v0;
result = printf(" | %7.3f \n", v4);
}
while ( v2 + 2000 != (double *)((char *)&unk_1E84800 + (_QWORD)&unk_40FC00) );
return result;
}

canonical_decompiled_code:
int func7()
{
__int64 *v0; // r12
double *v1; // rbp
double *v2; // rbx
double v3; // xmm0_8
double v4; // xmm0_8
int result; // eax

v0 = Y;
v1 = (double *)&unk_40FC00;
do
{
v2 = v1 - 2000;
do
{
v3 = *v2++;
printf("%7.3f ", v3);
}
while ( v2 != v1 );
v4 = *(double *)v0;
v1 = v2 + 2000;
++v0;
result = printf(" | %7.3f \n", v4);
}
while ( v2 + 2000 != (double *)((char *)&unk_1E84800 + (_QWORD)&unk_40FC00) );
return result;
}

variable_types: i int

variable_types: j int


printSol

decompiled_code:
int printSol()
{
__int64 v0; // rbx
double v1; // xmm0_8
__int64 v2; // rsi
int result; // eax

v0 = 0LL;
puts("--- Solution of Y=AX: ");
do
{
v1 = X[v0];
v2 = (unsigned int)v0++;
result = printf(" X%d = %7.3f \n", v2, v1);
}
while ( v0 != 2000 );
return result;
}

canonical_decompiled_code:
int func8()
{
__int64 v0; // rbx
double v1; // xmm0_8
__int64 v2; // rsi
int result; // eax

v0 = 0LL;
puts("--- Solution of Y=AX: ");
do
{
v1 = X[v0];
v2 = (unsigned int)v0++;
result = printf(" X%d = %7.3f \n", v2, v1);
}
while ( v0 != 2000 );
return result;
}

original_code:
void printSol()
{
 int i, j;
 printf("--- Solution of Y=AX: \n");
 for (i=0; i<2000; i++) {
  printf(" X%d = %7.3f \n", i, X[i]);
 }
}

canonical_original_code:
void printSol()
{
 int i; int j;
 printf("--- Solution of Y=AX: \n");
 for (i=0; i<2000; i++) {
  printf(" X%d = %7.3f \n", i, X[i]);
 }
}


decompiled_code:
int __fastcall ArrNode_Print(__int64 a1, __int64 a2)
{
__int64 i; // rbx
__int64 v4; // rdx
__int64 v5; // rsi
int result; // eax

if ( a2 > 0 )
{
for ( i = 0LL; i != a2; ++i )
{
v4 = *(_QWORD *)(a1 + 8 * i);
v5 = (unsigned int)i;
result = printf("ArrNode_Print: element %d points to %d\n", v5, v4);
}
}
return result;
}

canonical_decompiled_code:
int __fastcall func14(__int64 a1, __int64 a2)
{
__int64 i; // rbx
__int64 v4; // rdx
__int64 v5; // rsi
int result; // eax

if ( a2 > 0 )
{
for ( i = 0LL; i != a2; ++i )
{
v4 = *(_QWORD *)(a1 + 8 * i);
v5 = (unsigned int)i;
result = printf("ArrNode_Print: element %d points to %d\n", v5, v4);
}
}
return result;
}

original_code:
void ArrNode_Print(pArrNode an, long num)
{
 int i;
 for (i=0; i<num; i++)
  printf("ArrNode_Print: element %d points to %d\n", i, an->nodes[i]);
}

canonical_original_code:
void ArrNode_Print(struct ArrNode *an, long num)
{
 int i;
 for (i=0; i<num; i++)
  printf("ArrNode_Print: element %d points to %d\n", i, an->nodes[i]);
}

variable_types: struct ArrNode { struct tagIntListNode { int data; struct tagIntListNode *next; struct tagIntListNode *prev; struct omp_lock_t { unsigned char _x[4]; } lock; int deleted; } *nodes[500]; int curPtr; int numElmt; } *

variable_types: num long

user_defined_types: struct ArrNode { struct tagIntListNode *nodes[500]; int curPtr; int numElmt; }

user_defined_types: struct tagIntListNode { int data; struct tagIntListNode *next; struct tagIntListNode *prev; struct omp_lock_t lock; int deleted; }


decompiled_code:
__int64 __fastcall sys_futex(__int64 a1, unsigned int a2, unsigned int a3, __int64 a4)
{
return syscall(202LL, a1, a2, a3, a4, 0LL, 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, unsigned int a2, unsigned int a3, __int64 a4)
{
return syscall(202LL, a1, a2, a3, a4, 0LL, 0LL);
}

original_code:
int sys_futex(int *uaddr, int op, int val, const struct timespec *timeout)
{
  return syscall(202, uaddr, op, val, timeout, ((void *)0), 0);
}

canonical_original_code:
int sys_futex(int *uaddr, int op, int val, struct timespec *timeout)
{
  return syscall(202, uaddr, op, val, timeout, ((void *)0), 0);
}

variable_types:
uaddr
int *

variable_types: op int

variable_types: val int

variable_types: struct timespec { long tv_sec; long tv_nsec; } *


decompiled_code:
__int64 __fastcall futex_await(__int64 a1, unsigned int a2)
{
return sys_futex(a1, 2u, a2, 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, unsigned int a2)
{
return func0(a1, 2u, a2, 0LL);
}

original_code:
int futex_await(struct futex *futx, int signal)
{
 return sys_futex(&futx->count, 2, signal, ((void *)0));
}

variable_types:
futx
struct futex { int count; } *

variable_types: signal int


decompiled_code:
void __fastcall futex_init(_DWORD *a1, int a2)
{
*a1 = a2;
}

canonical_decompiled_code:
void __fastcall func4(_DWORD *a1, int a2)
{
*a1 = a2;
}

original_code:
void futex_init(struct futex *futx, int val)
{
 futx->count = val;
 __futex_commit();
}


decompiled_code:
__int64 __fastcall mythread_q_append(__int64 *a1, __int64 a2)
{
__int64 result; // rax

result = *a1;
*(_QWORD *)(a2 + 16) = *a1;
*(_QWORD *)(result + 24) = a2;
*(_QWORD *)(a2 + 24) = 0LL;
*a1 = a2;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 *a1, __int64 a2)
{
__int64 result; // rax

result = *a1;
*(_QWORD *)(a2 + 16) = *a1;
*(_QWORD *)(result + 24) = a2;
*(_QWORD *)(a2 + 24) = 0LL;
*a1 = a2;
return result;
}

original_code:
void mythread_q_append(mythread_queue_t *queue,mythread_helper_t *newElement)
{
 newElement->prev = queue->head;
 queue->head->next = newElement;
 newElement->next = ((void *)0);
 queue->head = newElement;
}

canonical_original_code:
void mythread_q_append(struct mythread_queue *queue, struct mythread_helper *newElement)
{
 newElement->prev = queue->head;
 queue->head->next = newElement;
 newElement->next = ((void *)0);
 queue->head = newElement;
}

variable_types: struct mythread_queue { struct mythread_helper { int pid; char *threadStack; struct mythread_helper *prev; enum MTHREADSTATE { NEW=0, READY=1, RUNNING=2, WAITING=3, TERMINATED=4 } currState; struct futex { int count; } thread_futex; int joiner_thread; int hasChildren; } *head; struct mythread_helper *currThread; } *

variable_types:
newElement
struct mythread_helper *

user_defined_types: struct mythread_queue { struct mythread_helper *head; struct mythread_helper *currThread; }

user_defined_types: struct mythread_helper { int pid; char *threadStack; struct mythread_helper *prev; enum MTHREADSTATE currState; struct futex thread_futex; int joiner_thread; int hasChildren; }


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

result = *(_QWORD *)(*(_QWORD *)(a1 + 8) + 24LL);
*(_QWORD *)(a1 + 8) = result;
return result;
}

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

result = *(_QWORD *)(*(_QWORD *)(a1 + 8) + 24LL);
*(_QWORD *)(a1 + 8) = result;
return result;
}

original_code:
void mythread_q_remove_end(mythread_queue_t *queue)
{
 queue->tail = queue->tail->next;
}

canonical_original_code:
void mythread_q_remove_end(struct mythread_queue *queue)
{
 queue->tail = queue->tail->next;
}

user_defined_types: enum MTHREADSTATE { NEW=0, READY=1, RUNNING=2, WAITING=3, TERMINATED=4 }


decompiled_code:
__int64 __fastcall mythread_q_find(__int64 a1, int a2)
{
__int64 result; // rax

for ( result = *(_QWORD *)(a1 + 8); result; result = *(_QWORD *)(result + 24) )
{
if ( *(_DWORD *)result == a2 )
break;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, int a2)
{
__int64 result; // rax

for ( result = *(_QWORD *)(a1 + 8); result; result = *(_QWORD *)(result + 24) )
{
if ( *(_DWORD *)result == a2 )
break;
}
return result;
}

original_code:
mythread_helper_t *mythread_q_find(mythread_queue_t *queue,mythread_t tid)
{
 mythread_helper_t *currNode;
 currNode = queue->tail;
 while (currNode != ((void *)0))
 {
  if (currNode->pid == tid)
  {
   break;
  }
  currNode = currNode->next;
 }
 return currNode;
}

canonical_original_code:
struct mythread_helper *mythread_q_find(struct mythread_queue *queue, int tid)
{
 struct mythread_helper *currNode;
 currNode = queue->tail;
 while (currNode != ((void *)0))
 {
  if (currNode->pid == tid)
  {
   break;
  }
  currNode = currNode->next;
 }
 return currNode;
}

variable_types: struct mythread_queue { struct mythread_helper *head; struct mythread_helper *currThread; } *

variable_types: tid int

variable_types: struct mythread_helper { int pid; char *threadStack; struct mythread_helper *prev; enum MTHREADSTATE { NEW=0, READY=1, RUNNING=2, WAITING=3, TERMINATED=4 } currState; struct futex { int count; } thread_futex; int joiner_thread; int hasChildren; } *


original_code:
int mythread_q_remove_specific(mythread_queue_t *queue,mythread_t tid)
{
 mythread_helper_t *nodeToRemove = mythread_q_find(queue,tid);
 if (nodeToRemove != ((void *)0))
 {
  if (nodeToRemove != queue->head)
  {
   nodeToRemove->next->prev = nodeToRemove->prev;
  }
  else
  {
   queue->head = nodeToRemove->prev;
  }
  if (nodeToRemove != queue->tail)
  {
   nodeToRemove->prev->next = nodeToRemove->next;
  }
  else
  {
   queue->tail = nodeToRemove->next;
  }
  nodeToRemove->next = ((void *)0);
  nodeToRemove->prev = ((void *)0);
 }
 else
 {
  return -1;
 }
 return 0;
}

canonical_original_code:
int mythread_q_remove_specific(struct mythread_queue *queue, int tid)
{
 struct mythread_helper *nodeToRemove = mythread_q_find(queue,tid);
 if (nodeToRemove != ((void *)0))
 {
  if (nodeToRemove != queue->head)
  {
   nodeToRemove->next->prev = nodeToRemove->prev;
  }
  else
  {
   queue->head = nodeToRemove->prev;
  }
  if (nodeToRemove != queue->tail)
  {
   nodeToRemove->prev->next = nodeToRemove->next;
  }
  else
  {
   queue->tail = nodeToRemove->next;
  }
  nodeToRemove->next = ((void *)0);
  nodeToRemove->prev = ((void *)0);
 }
 else
 {
  return -1;
 }
 return 0;
}


decompiled_code:
__int64 __fastcall mythread_q_count(__int64 a1)
{
__int64 v1; // rax
__int64 v2; // rax
unsigned int i; // er8

v1 = *(_QWORD *)(a1 + 8);
if ( !v1 )
return 0LL;
v2 = *(_QWORD *)(v1 + 24);
for ( i = 0; v2; ++i )
v2 = *(_QWORD *)(v2 + 24);
return i;
}

original_code:
unsigned int mythread_q_count(mythread_queue_t *queue)
{
 unsigned int count = 0;
 mythread_helper_t *currNode;
 currNode = queue->tail;
 if (currNode == ((void *)0))
 {
  return 0;
 }
 while (currNode->next != ((void *)0))
 {
  currNode = currNode->next;
  count++;
 }
 return count;
}

canonical_original_code:
unsigned int mythread_q_count(struct mythread_queue *queue)
{
 unsigned int count = 0;
 struct mythread_helper *currNode;
 currNode = queue->tail;
 if (currNode == ((void *)0))
 {
  return 0;
 }
 while (currNode->next != ((void *)0))
 {
  currNode = currNode->next;
  count++;
 }
 return count;
}

variable_types:
count
unsigned int


decompiled_code:
__int64 __fastcall mythread_q_get_alive_count(__int64 a1)
{
__int64 v1; // rax
__int64 v2; // rax
unsigned int i; // er8
bool v4; // zf

v1 = *(_QWORD *)(a1 + 8);
if ( !v1 )
return 0LL;
v2 = *(_QWORD *)(v1 + 24);
for ( i = 0; v2; i += !v4 )
{
v4 = *(_DWORD *)(v2 + 32) == 4;
v2 = *(_QWORD *)(v2 + 24);
}
return i;
}

original_code:
unsigned int mythread_q_get_alive_count(mythread_queue_t *queue)
{
 unsigned int count = 0;
 mythread_helper_t *currNode;
 currNode = queue->tail;
 if (currNode == ((void *)0))
 {
  return 0;
 }
 while (currNode->next != ((void *)0))
 {
  currNode = currNode->next;
  if (currNode->currState != TERMINATED)
  {
   count++;
  }
 }
 return count;
}

canonical_original_code:
unsigned int mythread_q_get_alive_count(struct mythread_queue *queue)
{
 unsigned int count = 0;
 struct mythread_helper *currNode;
 currNode = queue->tail;
 if (currNode == ((void *)0))
 {
  return 0;
 }
 while (currNode->next != ((void *)0))
 {
  currNode = currNode->next;
  if (currNode->currState != TERMINATED)
  {
   count++;
  }
 }
 return count;
}


decompiled_code:
__int64 __fastcall mythread_q_get_ready_count(__int64 a1)
{
__int64 v1; // rax
__int64 v2; // rax
unsigned int i; // er8
bool v4; // zf

v1 = *(_QWORD *)(a1 + 8);
if ( !v1 )
return 0LL;
v2 = *(_QWORD *)(v1 + 24);
for ( i = 0; v2; i += v4 )
{
v4 = *(_DWORD *)(v2 + 32) == 1;
v2 = *(_QWORD *)(v2 + 24);
}
return i;
}

original_code:
unsigned int mythread_q_get_ready_count(mythread_queue_t *queue)
{
 unsigned int count = 0;
 mythread_helper_t *currNode;
 currNode = queue->tail;
 if (currNode == ((void *)0))
 {
  return 0;
 }
 while (currNode->next != ((void *)0))
 {
  currNode = currNode->next;
  if (currNode->currState == READY)
  {
   count++;
  }
 }
 return count;
}

canonical_original_code:
unsigned int mythread_q_get_ready_count(struct mythread_queue *queue)
{
 unsigned int count = 0;
 struct mythread_helper *currNode;
 currNode = queue->tail;
 if (currNode == ((void *)0))
 {
  return 0;
 }
 while (currNode->next != ((void *)0))
 {
  currNode = currNode->next;
  if (currNode->currState == READY)
  {
   count++;
  }
 }
 return count;
}


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

for ( result = *(_QWORD *)(a1 + 8); result; result = *(_QWORD *)(result + 24) )
{
if ( *(_DWORD *)(result + 32) == 1 )
break;
}
return result;
}

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

for ( result = *(_QWORD *)(a1 + 8); result; result = *(_QWORD *)(result + 24) )
{
if ( *(_DWORD *)(result + 32) == 1 )
break;
}
return result;
}

original_code:
mythread_helper_t *mythread_q_get_highest_ready_thread(mythread_queue_t *queue)
{
 mythread_helper_t *currNode;
 currNode = queue->tail;
 while (currNode != ((void *)0))
 {
  if (currNode->currState == READY)
  {
   return currNode;
  }
  currNode = currNode->next;
 }
 return currNode;
}

canonical_original_code:
struct mythread_helper *mythread_q_get_highest_ready_thread(struct mythread_queue *queue)
{
 struct mythread_helper *currNode;
 currNode = queue->tail;
 while (currNode != ((void *)0))
 {
  if (currNode->currState == READY)
  {
   return currNode;
  }
  currNode = currNode->next;
 }
 return currNode;
}

return_type: struct mythread_helper { int pid; char *threadStack; struct mythread_helper *prev; enum MTHREADSTATE { NEW=0, READY=1, RUNNING=2, WAITING=3, TERMINATED=4 } currState; struct futex { int count; } thread_futex; int joiner_thread; int hasChildren; } *


original_code:
int mythread_join(mythread_t target_thread, void **status)
{
 char logStr[128] = {'\0'};
 mythread_helper_t *joinee_thread;
 if (target_thread > 0)
 {
  joinee_thread = mythread_q_find(mythread_queue,target_thread);
  if (joinee_thread != ((void *)0) )
  {
   if (joinee_thread->currState == TERMINATED || joinee_thread->joiner_thread != 0)
   {
    sprintf(logStr,"Thread %d has joiner_thread %d",target_thread, joinee_thread->joiner_thread);
    writeLog(__func__,VDEBUG,logStr);
    return MNOERR;
   }
   joinee_thread->joiner_thread = mythread_queue->currThread->pid;
   mythread_queue->currThread->currState = WAITING;
   mythread_swapcontext(mythread_queue->currThread);
   return MNOERR;
  }
  else
  {
   sprintf(logStr,"Couldnt find thread %d in the queue",target_thread);
   writeLog(__func__,VSEVERE,logStr);
   return MERR_INVALIDTID;
  }
 }
 else
 {
  return MERR_INVALIDTID;
 }
}

canonical_original_code:
int mythread_join(int target_thread, void **status)
{
 char logStr[128] = {'\0'};
 struct mythread_helper *joinee_thread;
 if (target_thread > 0)
 {
  joinee_thread = mythread_q_find(mythread_queue,target_thread);
  if (joinee_thread != ((void *)0) )
  {
   if (joinee_thread->currState == TERMINATED || joinee_thread->joiner_thread != 0)
   {
    sprintf(logStr,"Thread %d has joiner_thread %d",target_thread, joinee_thread->joiner_thread);
    writeLog(__func__,VDEBUG,logStr);
    return MNOERR;
   }
   joinee_thread->joiner_thread = mythread_queue->currThread->pid;
   mythread_queue->currThread->currState = WAITING;
   mythread_swapcontext(mythread_queue->currThread);
   return MNOERR;
  }
  else
  {
   sprintf(logStr,"Couldnt find thread %d in the queue",target_thread);
   writeLog(__func__,VSEVERE,logStr);
   return MERR_INVALIDTID;
  }
 }
 else
 {
  return MERR_INVALIDTID;
 }
}

variable_types:
status
void **

variable_types:
logStr
char [128]


decompiled_code:
// write access to const memory has been detected, the output may be wrong!
void mythread_key_helper_init()
{
if ( !mythread_key_helper )
{
*(&mythread_key_helper + 1) = 0LL;
loc_10 = 0LL;
BUG();
}
}

canonical_decompiled_code:
void func0()
{
if ( !mythread_key_helper )
{
*(&mythread_key_helper + 1) = 0LL;
loc_10 = 0LL;
BUG();
}
}

original_code:
void mythread_key_helper_init()
{
 if(mythread_key_helper.headkey == ((void *)0))
 {
  mythread_key_helper.headkey = ((void *)0);
  mythread_key_helper.tailkey = ((void *)0);
  mythread_key_helper.headkey->next = ((void *)0);
  mythread_key_helper.tailkey->prev = ((void *)0);
  mythread_key_helper.currKey = mythread_key_helper.headkey;
 }
}


decompiled_code:
__int64 __fastcall mythread_key_create(__int64 a1)
{
__int64 v1; // rbx
int v2; // eax
_QWORD *v3; // rax
_QWORD *v4; // rax
_QWORD *v5; // rbx
__int64 v6; // rbp
__int64 i; // rdx
_QWORD *v8; // rax
__int64 result; // rax

puts("In set specific ");
mythread_key_helper_init();
puts("In set specific1 ");
v1 = *(&mythread_key_helper + 1);
*(_QWORD *)(*(&mythread_key_helper + 2) + 16) = a1;
*(&mythread_key_helper + 2) = a1;
*(_QWORD *)(a1 + 16) = v1;
*(_QWORD *)(v1 + 24) = a1;
*(_QWORD *)(v1 + 16) = malloc(8uLL);
puts("In set specific3 ");
v2 = numKeys + 1;
*(_DWORD *)a1 = numKeys + 1;
numKeys = v2;
puts("In set specific4 ");
*(_QWORD *)(a1 + 8) = malloc(8uLL);
v3 = malloc(8uLL);
*(_QWORD *)(a1 + 32) = v3;
*v3 = malloc(8uLL);
puts("In set specific5 ");
v4 = *(_QWORD **)(a1 + 32);
v5 = (_QWORD *)*v4;
v6 = *(_QWORD *)(mythread_queue + 8);
v4[1] = *v4;
v5[3] = v6;
puts("In set specific 6");
for ( i = *(_QWORD *)(mythread_queue + 8); v6 != i; v6 = *(_QWORD *)(v6 + 24) )
{
v8 = v5;
v5 = (_QWORD *)v5[1];
v5[2] = v8;
v8[3] = v6;
}
puts("In set specific 7");
result = *(_QWORD *)(a1 + 32);
v5[1] = 0LL;
*(_QWORD *)(result + 8) = v5;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
__int64 v1; // rbx
int v2; // eax
_QWORD *v3; // rax
_QWORD *v4; // rax
_QWORD *v5; // rbx
__int64 v6; // rbp
__int64 i; // rdx
_QWORD *v8; // rax
__int64 result; // rax

puts("In set specific ");
func0();
puts("In set specific1 ");
v1 = *(&mythread_key_helper + 1);
*(_QWORD *)(*(&mythread_key_helper + 2) + 16) = a1;
*(&mythread_key_helper + 2) = a1;
*(_QWORD *)(a1 + 16) = v1;
*(_QWORD *)(v1 + 24) = a1;
*(_QWORD *)(v1 + 16) = malloc(8uLL);
puts("In set specific3 ");
v2 = numKeys + 1;
*(_DWORD *)a1 = numKeys + 1;
numKeys = v2;
puts("In set specific4 ");
*(_QWORD *)(a1 + 8) = malloc(8uLL);
v3 = malloc(8uLL);
*(_QWORD *)(a1 + 32) = v3;
*v3 = malloc(8uLL);
puts("In set specific5 ");
v4 = *(_QWORD **)(a1 + 32);
v5 = (_QWORD *)*v4;
v6 = *(_QWORD *)(mythread_queue + 8);
v4[1] = *v4;
v5[3] = v6;
puts("In set specific 6");
for ( i = *(_QWORD *)(mythread_queue + 8); v6 != i; v6 = *(_QWORD *)(v6 + 24) )
{
v8 = v5;
v5 = (_QWORD *)v5[1];
v5[2] = v8;
v8[3] = v6;
}
puts("In set specific 7");
result = *(_QWORD *)(a1 + 32);
v5[1] = 0LL;
*(_QWORD *)(result + 8) = v5;
return result;
}

original_code:
int mythread_key_create(mythread_key_t *key, void (*destructor)(void*))
{
 printf("In set specific \n");
 mythread_helper_t *currT;
 mythread_keyval_t *currV;
 mythread_key_helper_init();
 printf("In set specific1 \n");
 mythread_key_helper.currKey->next = key;
 mythread_key_helper.currKey = mythread_key_helper.currKey->next;
 mythread_key_helper.tailkey->prev =mythread_key_helper.currKey;
 mythread_key_helper.currKey->next = mythread_key_helper.tailkey;
 mythread_key_helper.tailkey = key->next;
 mythread_key_helper.tailkey->prev = key;
 mythread_key_helper.tailkey->next = (mythread_key_t *)malloc(sizeof(mythread_key_t *));
 printf("In set specific3 \n");
 key->keyID = ++numKeys;
 printf("In set specific4 \n");
 key->keyval = (mythread_keyval_t *)malloc(sizeof(mythread_keyval_t *));
 key->mythread_keyval_helper = (mythread_keyval_helper_t *)malloc(sizeof(mythread_keyval_helper_t *));
 key->mythread_keyval_helper->headkeyval = (mythread_keyval_t *)malloc(sizeof(mythread_keyval_t *));
 printf("In set specific5 \n");
 key->mythread_keyval_helper->headkeyval->thread = mythread_queue->tail;
 key->mythread_keyval_helper->tailkeyval = key->mythread_keyval_helper->headkeyval;
 key->mythread_keyval_helper->tailkeyval->thread = key->mythread_keyval_helper->headkeyval->thread;
 currT = (mythread_helper_t *)malloc(sizeof(mythread_helper_t *));
 currT = key->mythread_keyval_helper->tailkeyval->thread;
 currV = key->mythread_keyval_helper->tailkeyval;
 printf("In set specific 6\n");
 while(currT != mythread_queue->tail)
 {
  currV->next->prev = currV;
  currV->thread = currT;
  currV = currV->next;
  currT = currT->next;
 }
 printf("In set specific 7\n");
 currV->next = ((void *)0);
 key->mythread_keyval_helper->tailkeyval = currV;
}

canonical_original_code:
int mythread_key_create(struct mythread_key_t *key, void (*destructor)(void *))
{
 printf("In set specific \n");
 struct mythread_helper *currT;
 struct mythread_keyval *currV;
 mythread_key_helper_init();
 printf("In set specific1 \n");
 mythread_key_helper.currKey->next = key;
 mythread_key_helper.currKey = mythread_key_helper.currKey->next;
 mythread_key_helper.tailkey->prev =mythread_key_helper.currKey;
 mythread_key_helper.currKey->next = mythread_key_helper.tailkey;
 mythread_key_helper.tailkey = key->next;
 mythread_key_helper.tailkey->prev = key;
 mythread_key_helper.tailkey->next = (struct mythread_key_t *)malloc(sizeof(struct mythread_key_t *));
 printf("In set specific3 \n");
 key->keyID = ++numKeys;
 printf("In set specific4 \n");
 key->keyval = (struct mythread_keyval *)malloc(sizeof(struct mythread_keyval *));
 key->mythread_keyval_helper = (struct mythread_keyval_helper *)malloc(sizeof(struct mythread_keyval_helper *));
 key->mythread_keyval_helper->headkeyval = (struct mythread_keyval *)malloc(sizeof(struct mythread_keyval *));
 printf("In set specific5 \n");
 key->mythread_keyval_helper->headkeyval->thread = mythread_queue->tail;
 key->mythread_keyval_helper->tailkeyval = key->mythread_keyval_helper->headkeyval;
 key->mythread_keyval_helper->tailkeyval->thread = key->mythread_keyval_helper->headkeyval->thread;
 currT = (struct mythread_helper *)malloc(sizeof(struct mythread_helper *));
 currT = key->mythread_keyval_helper->tailkeyval->thread;
 currV = key->mythread_keyval_helper->tailkeyval;
 printf("In set specific 6\n");
 while(currT != mythread_queue->tail)
 {
  currV->next->prev = currV;
  currV->thread = currT;
  currV = currV->next;
  currT = currT->next;
 }
 printf("In set specific 7\n");
 currV->next = ((void *)0);
 key->mythread_keyval_helper->tailkeyval = currV;
}

variable_types: struct mythread_key_t { int keyID; struct mythread_keyval { void *value; struct mythread_keyval *next; struct mythread_keyval *prev; struct mythread_helper { int pid; char *threadStack; struct mythread_helper *prev; enum MTHREADSTATE { NEW=0, READY=1, RUNNING=2, WAITING=3, TERMINATED=4 } currState; struct futex { int count; } thread_futex; int joiner_thread; int hasChildren; } *thread; } *keyval; struct mythread_key_t *next; struct mythread_key_t *prev; struct mythread_keyval_helper { struct mythread_keyval *headkeyval; } *mythread_keyval_helper; } *

variable_types:
destructor
void (*)(void *)

user_defined_types: struct mythread_key_t { int keyID; struct mythread_keyval *keyval; struct mythread_key_t *next; struct mythread_key_t *prev; struct mythread_keyval_helper *mythread_keyval_helper; }

user_defined_types: struct mythread_keyval { void *value; struct mythread_keyval *next; struct mythread_keyval *prev; struct mythread_helper *thread; }


original_code:
void *mythread_getspecific(mythread_key_t key)
{
 int id;
 id = key.keyID;
 mythread_keyval_t *currKeyVal;
 currKeyVal= (mythread_keyval_t *)malloc(sizeof(mythread_keyval_t));
 mythread_key_t *currKey;
 currKey = (mythread_key_t *)malloc(sizeof(mythread_key_t *));
 currKey = mythread_key_helper.headkey;
 while(currKey != mythread_key_helper.tailkey)
 {
  if(currKey->keyID == id)
  {
   break;
  }
  currKey = currKey->next;
 }
 currKeyVal = currKey->mythread_keyval_helper->headkeyval;
 while(currKeyVal->next != currKey->mythread_keyval_helper->tailkeyval)
 {
  if(currKeyVal->thread->pid == mythread_queue->currThread->pid)
  {
   break;
  }
  else
  currKeyVal= currKeyVal->next;
 }
 return(currKeyVal->value);
}

canonical_original_code:
void *mythread_getspecific(struct mythread_key_t key)
{
 int id;
 id = key.keyID;
 struct mythread_keyval *currKeyVal;
 currKeyVal= (struct mythread_keyval *)malloc(sizeof(mythread_keyval_t));
 struct mythread_key_t *currKey;
 currKey = (struct mythread_key_t *)malloc(sizeof(struct mythread_key_t *));
 currKey = mythread_key_helper.headkey;
 while(currKey != mythread_key_helper.tailkey)
 {
  if(currKey->keyID == id)
  {
   break;
  }
  currKey = currKey->next;
 }
 currKeyVal = currKey->mythread_keyval_helper->headkeyval;
 while(currKeyVal->next != currKey->mythread_keyval_helper->tailkeyval)
 {
  if(currKeyVal->thread->pid == mythread_queue->currThread->pid)
  {
   break;
  }
  else
  currKeyVal= currKeyVal->next;
 }
 return(currKeyVal->value);
}

variable_types: struct mythread_key_t { int keyID; struct mythread_keyval { void *value; struct mythread_keyval *next; struct mythread_keyval *prev; struct mythread_helper { int pid; char *threadStack; struct mythread_helper *prev; enum MTHREADSTATE { NEW=0, READY=1, RUNNING=2, WAITING=3, TERMINATED=4 } currState; struct futex { int count; } thread_futex; int joiner_thread; int hasChildren; } *thread; } *keyval; struct mythread_key_t *next; struct mythread_key_t *prev; struct mythread_keyval_helper { struct mythread_keyval *headkeyval; } *mythread_keyval_helper; }

variable_types: id int


writeLog

decompiled_code:
__int64 __fastcall writeLog(char *src, int a2, const char *a3)
{
struct tm *v5; // rax
char *v6; // rax
size_t v7; // rax
char *v8; // rax
char *v9; // rax
time_t timer; // [rsp+0h] [rbp-270h] BYREF
char s[64]; // [rsp+8h] [rbp-268h] BYREF
char dest[552]; // [rsp+48h] [rbp-228h] BYREF

if ( !system_log_level )
return 0LL;
timer = time(0LL);
v5 = localtime(&timer);
strftime(s, 0x40uLL, "%Y%m%d %H:%M:%S|", v5);
v6 = stpcpy(dest, s);
switch ( a2 )
{
case 4:
strcpy(v6, "ERROR|");
break;
case 2:
strcpy(v6, "WARNING|");
break;
case 8:
*(_QWORD *)v6 = 0x7C455245564553LL;
break;
case 1:
strcpy(v6, "INFO|");
break;
case 16:
strcpy(v6, "DEBUG|");
break;
}
v7 = strlen(dest);
v8 = stpcpy(&dest[v7], src);
*v8 = 124;
v9 = stpcpy(v8 + 1, a3);
*(_WORD *)v9 = 10;
if ( a2 == (a2 & system_log_level) )
write(1, dest, v9 - dest + 1);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(char *src, int a2, const char *a3)
{
struct tm *v5; // rax
char *v6; // rax
size_t v7; // rax
char *v8; // rax
char *v9; // rax
time_t timer; // [rsp+0h] [rbp-270h] BYREF
char s[64]; // [rsp+8h] [rbp-268h] BYREF
char dest[552]; // [rsp+48h] [rbp-228h] BYREF

if ( !system_log_level )
return 0LL;
timer = time(0LL);
v5 = localtime(&timer);
strftime(s, 0x40uLL, "%Y%m%d %H:%M:%S|", v5);
v6 = stpcpy(dest, s);
switch ( a2 )
{
case 4:
strcpy(v6, "ERROR|");
break;
case 2:
strcpy(v6, "WARNING|");
break;
case 8:
*(_QWORD *)v6 = 0x7C455245564553LL;
break;
case 1:
strcpy(v6, "INFO|");
break;
case 16:
strcpy(v6, "DEBUG|");
break;
}
v7 = strlen(dest);
v8 = stpcpy(&dest[v7], src);
*v8 = 124;
v9 = stpcpy(v8 + 1, a3);
*(_WORD *)v9 = 10;
if ( a2 == (a2 & system_log_level) )
write(1, dest, v9 - dest + 1);
return 0LL;
}

original_code:
int writeLog(const char *sourceFunction,enum VLOGLEVEL loglevel,char *logStr)
{
 if (_system_log_level != NONE)
 {
  char text[512];
  struct tm *timeVal;
  time_t currTime;
  char timeBuff[64];
  currTime = time(((void *)0));
  timeVal = localtime(&currTime);
  strftime(timeBuff,64,"%Y%m%d %H:%M:%S|",timeVal);
  strcpy(text,timeBuff);
  if (loglevel == VERROR)
  {
   strcat(text,"ERROR|");
  }
  else if (loglevel == VWARNING)
  {
   strcat(text,"WARNING|");
  }
  else if (loglevel == VSEVERE)
  {
   strcat(text,"SEVERE|");
  }
  else if (loglevel == VINFO)
  {
   strcat(text,"INFO|");
  }
  else if (loglevel == VDEBUG)
  {
   strcat(text,"DEBUG|");
  }
  strcat(text,sourceFunction);
  strcat(text,"|");
  strcat(text,logStr);
  strcat(text,"\n");
  if ( (_system_log_level & (int) loglevel) == (int) loglevel)
  {
   write(1,text,strlen(text));
  }
 }
 return 0;
}

canonical_original_code:
int writeLog(char *sourceFunction, enum VLOGLEVEL loglevel, char *logStr)
{
 if (_system_log_level != NONE)
 {
  char text[512];
  struct tm *timeVal;
  long currTime;
  char timeBuff[64];
  currTime = time(((void *)0));
  timeVal = localtime(&currTime);
  strftime(timeBuff,64,"%Y%m%d %H:%M:%S|",timeVal);
  strcpy(text,timeBuff);
  if (loglevel == VERROR)
  {
   strcat(text,"ERROR|");
  }
  else if (loglevel == VWARNING)
  {
   strcat(text,"WARNING|");
  }
  else if (loglevel == VSEVERE)
  {
   strcat(text,"SEVERE|");
  }
  else if (loglevel == VINFO)
  {
   strcat(text,"INFO|");
  }
  else if (loglevel == VDEBUG)
  {
   strcat(text,"DEBUG|");
  }
  strcat(text,sourceFunction);
  strcat(text,"|");
  strcat(text,logStr);
  strcat(text,"\n");
  if ( (_system_log_level & (int) loglevel) == (int) loglevel)
  {
   write(1,text,strlen(text));
  }
 }
 return 0;
}

variable_types:
sourceFunction
char *

variable_types: enum VLOGLEVEL { NONE=0, VINFO=1, VWARNING=2, VERROR=4, VSEVERE=8, VDEBUG=16 }

variable_types:
logStr
char *

variable_types:
text
char [512]

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; } *

variable_types: currTime long

variable_types:
timeBuff
char [64]


decompiled_code:
__int64 __fastcall mythread_helper_init(_DWORD *a1)
{
_DWORD *v1; // rdi

if ( !a1 )
return 1LL;
*a1 = -1;
v1 = a1 + 9;
*(v1 - 1) = 0;
*(_QWORD *)(v1 - 3) = 0LL;
*(_QWORD *)(v1 - 5) = 0LL;
v1[1] = 0;
futex_init(v1, 0LL);
return 0LL;
}

original_code:
enum MERRORSTATE mythread_helper_init(mythread_helper_t *helper)
{
 if ( helper == ((void *)0))
 {
  return MERR_MALLOC;
 }
 else
 {
  helper->currState = NEW;
  helper->next = ((void *)0);
  helper->prev = ((void *)0);
  helper->pid = -1;
  helper->joiner_thread = 0;
  futex_init(&helper->thread_futex,0);
 }
 return MNOERR;
}

canonical_original_code:
enum MERRORSTATE mythread_helper_init(struct mythread_helper *helper)
{
 if ( helper == ((void *)0))
 {
  return MERR_MALLOC;
 }
 else
 {
  helper->currState = NEW;
  helper->next = ((void *)0);
  helper->prev = ((void *)0);
  helper->pid = -1;
  helper->joiner_thread = 0;
  futex_init(&helper->thread_futex,0);
 }
 return MNOERR;
}

return_type: enum MERRORSTATE { MNOERR=0, MERR_MALLOC=1, MERR_LOG=2, MERR_CLONE=3, MERR_THREADINIT=4, MERR_QUEUECREATE=5, MERR_INVALIDTID=6, MERR_QUEUENOITEM=7, MERR_GENERIC=8 }


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

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

original_code:
void mythread_helper_destroy(mythread_helper_t *helper)
{
 helper->currState = TERMINATED;
 helper->next = ((void *)0);
 helper->prev = ((void *)0);
 helper->pid = -1;
 helper->threadStack = ((void *)0);
 free(helper);
}

canonical_original_code:
void mythread_helper_destroy(struct mythread_helper *helper)
{
 helper->currState = TERMINATED;
 helper->next = ((void *)0);
 helper->prev = ((void *)0);
 helper->pid = -1;
 helper->threadStack = ((void *)0);
 free(helper);
}


decompiled_code:
__int64 mythread_self()
{
return **(unsigned int **)(mythread_queue + 16);
}

canonical_decompiled_code:
__int64 func0()
{
return **(unsigned int **)(mythread_queue + 16);
}

original_code:
mythread_t mythread_self(void)
{
 mythread_helper_t *currNode = mythread_queue->currThread;
 return currNode->pid;
}

canonical_original_code:
int mythread_self()
{
 struct mythread_helper *currNode = mythread_queue->currThread;
 return currNode->pid;
}


decompiled_code:
void mythread_exit()
{
;
}

canonical_decompiled_code:
void func0()
{
;
}

original_code:
void mythread_exit(void *retval)
{
 return;
}

variable_types:
retval
void *


original_code:
int mythread_setspecific(mythread_key_t key, const void *val)
{
 int id;
 id = key.keyID;
 mythread_keyval_t *currKeyVal;
 currKeyVal = (mythread_keyval_t *) malloc(sizeof(mythread_keyval_t));
 mythread_key_t *currKey;
 currKey = (mythread_key_t *)malloc(sizeof(mythread_key_t *));
 currKey = mythread_key_helper.headkey;
 while(currKey != mythread_key_helper.tailkey)
 {
  if(currKey->keyID == id)
  {
   break;
  }
  currKey = currKey->next;
 }
 currKeyVal = currKey->mythread_keyval_helper->headkeyval;
 while(currKeyVal->next != currKey->mythread_keyval_helper->tailkeyval)
 {
  if(currKeyVal->thread->pid == mythread_queue->currThread->pid)
   {
   break;
  }
  else
  currKeyVal= currKeyVal->next;
 }
 currKeyVal->value = val;
 }

canonical_original_code:
int mythread_setspecific(struct mythread_key_t key, void *val)
{
 int id;
 id = key.keyID;
 struct mythread_keyval *currKeyVal;
 currKeyVal = (struct mythread_keyval *) malloc(sizeof(mythread_keyval_t));
 struct mythread_key_t *currKey;
 currKey = (struct mythread_key_t *)malloc(sizeof(struct mythread_key_t *));
 currKey = mythread_key_helper.headkey;
 while(currKey != mythread_key_helper.tailkey)
 {
  if(currKey->keyID == id)
  {
   break;
  }
  currKey = currKey->next;
 }
 currKeyVal = currKey->mythread_keyval_helper->headkeyval;
 while(currKeyVal->next != currKey->mythread_keyval_helper->tailkeyval)
 {
  if(currKeyVal->thread->pid == mythread_queue->currThread->pid)
   {
   break;
  }
  else
  currKeyVal= currKeyVal->next;
 }
 currKeyVal->value = val;
 }

variable_types:
val
void *

variable_types: struct mythread_keyval { void *value; struct mythread_keyval *next; struct mythread_keyval *prev; struct mythread_helper { int pid; char *threadStack; struct mythread_helper *prev; enum MTHREADSTATE { NEW=0, READY=1, RUNNING=2, WAITING=3, TERMINATED=4 } currState; struct futex { int count; } thread_futex; int joiner_thread; int hasChildren; } *thread; } *

user_defined_types: struct mythread_keyval_helper { struct mythread_keyval *headkeyval; }


decompiled_code:
void *mythread_key_init()
{
void *result; // rax

result = malloc(8uLL);
key_helper = (__int64)result;
*(&key_helper + 1) = (__int64)result;
return result;
}

canonical_decompiled_code:
void *func0()
{
void *result; // rax

result = malloc(8uLL);
key_helper = (__int64)result;
*(&key_helper + 1) = (__int64)result;
return result;
}

original_code:
void mythread_key_init(mythread_key_t *key)
{
 key = (mythread_key_t *)malloc(sizeof(mythread_key_t *));
 key_helper.headkey = key;
 key_helper.tailkey = key;
}

canonical_original_code:
void mythread_key_init(struct mythread_key_t *key)
{
 key = (struct mythread_key_t *)malloc(sizeof(struct mythread_key_t *));
 key_helper.headkey = key;
 key_helper.tailkey = key;
}


decompiled_code:
__int64 mythread_yield()
{
*(_DWORD *)(*(_QWORD *)(mythread_queue + 16) + 32LL) = 1;
mythread_swapcontext();
return 0LL;
}

canonical_decompiled_code:
__int64 func0()
{
*(_DWORD *)(*(_QWORD *)(mythread_queue + 16) + 32LL) = 1;
mythread_swapcontext();
return 0LL;
}

original_code:
int mythread_yield(void)
{
    mythread_helper_t *currNode = mythread_queue->currThread;
    currNode->currState = READY;
    mythread_swapcontext(currNode);
    return 0;
}

canonical_original_code:
int mythread_yield()
{
    struct mythread_helper *currNode = mythread_queue->currThread;
    currNode->currState = READY;
    mythread_swapcontext(currNode);
    return 0;
}

variable_types: struct mythread_helper { int pid; char *threadStack; struct mythread_helper *prev; enum MTHREADSTATE { NEW=0, READY=1, RUNNING=2, WAITING=3, TERMINATED=4 } currState; struct futex { int count; } thread_futex; int joiner_thread; int hasChildren; } *


getConflict

decompiled_code:
__int64 *getConflict()
{
return &conflict;
}

canonical_decompiled_code:
__int64 *func0()
{
return &conflict;
}

original_code:
Item **getConflict() {
    return &conflict;
}

canonical_original_code:
struct palavra **getConflict() {
    return &conflict;
}

return_type: struct palavra { char *literal; struct palavra *lema; struct palavra *prox; struct sentence { struct _G_fpos_t { long __pos; struct __mbstate_t { int __count; union { unsigned int __wch; char __wchb[4]; } __value; } __state; } position; struct sentence *prox; struct sentence *ant; } *list; } **

user_defined_types: struct palavra { char *literal; struct palavra *lema; struct palavra *prox; struct sentence *list; }

user_defined_types: struct sentence { struct _G_fpos_t position; struct sentence *prox; struct sentence *ant; }

user_defined_types: struct _G_fpos_t { long __pos; struct __mbstate_t __state; }


initTree

decompiled_code:
__int64 initTree()
{
return z;
}

canonical_decompiled_code:
__int64 func1()
{
return z;
}

original_code:
link initTree() {
    link head = z;
    return head;
}

canonical_original_code:
struct STnode *initTree() {
    struct STnode *head = z;
    return head;
}

variable_types: struct STnode { struct palavra { char *literal; struct palavra *lema; struct palavra *prox; struct sentence { struct _G_fpos_t { long __pos; struct __mbstate_t { int __count; union { unsigned int __wch; char __wchb[4]; } __value; } __state; } position; struct sentence *prox; struct sentence *ant; } *list; } *item; struct STnode *l; int N; int red; } *

user_defined_types: struct STnode { struct palavra *item; struct STnode *l; int N; int red; }


STinit

decompiled_code:
_QWORD *STinit()
{
__int64 v0; // rax
_QWORD *result; // rax

v0 = getNULLitem();
result = NEW(v0, 0LL, 0LL, 0, 0);
conflict = 0LL;
z = (__int64)result;
return result;
}

canonical_decompiled_code:
_QWORD *func2()
{
__int64 v0; // rax
_QWORD *result; // rax

v0 = getNULLitem();
result = NEW(v0, 0LL, 0LL, 0, 0);
conflict = 0LL;
z = (__int64)result;
return result;
}

original_code:
void STinit() {
    z = NEW(getNULLitem(), 0, 0, 0, 0);
    conflict = ((void *)0);
}


STcount

decompiled_code:
__int64 __fastcall STcount(__int64 a1)
{
return *(unsigned int *)(a1 + 24);
}

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

original_code:
int STcount(link head) {
    return head->N;
}

canonical_original_code:
int STcount(struct STnode *head) {
    return head->N;
}

user_defined_types: struct __mbstate_t { int __count; union { unsigned int __wch; char __wchb[4]; } __value; }


searchR

decompiled_code:
__int64 __fastcall searchR(_QWORD *a1, __int64 a2)
{
int v3; // eax
_QWORD *v4; // rdx
__int64 v5; // rax
__int64 v6; // rbp

while ( 1 )
{
v5 = key(*a1);
v6 = v5;
if ( (_QWORD *)z == a1 )
return getNULLitem();
if ( (unsigned int)eq(a2, v5) )
break;
v3 = less(a2, v6);
v4 = (_QWORD *)a1[1];
if ( !v3 )
v4 = (_QWORD *)a1[2];
a1 = v4;
}
return *a1;
}

canonical_decompiled_code:
__int64 __fastcall func4(_QWORD *a1, __int64 a2)
{
int v3; // eax
_QWORD *v4; // rdx
__int64 v5; // rax
__int64 v6; // rbp

while ( 1 )
{
v5 = key(*a1);
v6 = v5;
if ( (_QWORD *)z == a1 )
return getNULLitem();
if ( (unsigned int)eq(a2, v5) )
break;
v3 = less(a2, v6);
v4 = (_QWORD *)a1[1];
if ( !v3 )
v4 = (_QWORD *)a1[2];
a1 = v4;
}
return *a1;
}

original_code:
Item *searchR(link h, Key v) {
    Key t = key(h->item);
    if (h == z) return getNULLitem();
    if (eq(v, t)) return (h->item);
    if (less(v, t)) return searchR((h->l), v);
    else return searchR((h->r), v);
}

canonical_original_code:
struct palavra *searchR(struct STnode *h, char *v) {
    char *t = key(h->item);
    if (h == z) return getNULLitem();
    if (eq(v, t)) return (h->item);
    if (less(v, t)) return searchR((h->l), v);
    else return searchR((h->r), v);
}

variable_types: struct STnode { struct palavra *item; struct STnode *l; int N; int red; } *

variable_types:
v
char *

variable_types:
t
char *

return_type: struct palavra { char *literal; struct palavra *lema; struct palavra *prox; struct sentence { struct _G_fpos_t { long __pos; struct __mbstate_t { int __count; union { unsigned int __wch; char __wchb[4]; } __value; } __state; } position; struct sentence *prox; struct sentence *ant; } *list; } *


STsearch

decompiled_code:
__int64 __fastcall STsearch(__int64 a1, _QWORD *a2)
{
return searchR(a2, a1);
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, _QWORD *a2)
{
return func4(a2, a1);
}

original_code:
Item *STsearch(Key v, link head) {
    return searchR(head, v);
}

canonical_original_code:
struct palavra *STsearch(char *v, struct STnode *head) {
    return searchR(head, v);
}


fixNr

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

result = a1;
*(_DWORD *)(a1 + 24) = *(_DWORD *)(*(_QWORD *)(a1 + 8) + 24LL) + *(_DWORD *)(*(_QWORD *)(a1 + 16) + 24LL) + 1;
return result;
}

original_code:
link fixNr(link h) {
    h->N = (h->l)->N + (h->r)->N +1;
    return h;
}

canonical_original_code:
struct STnode *fixNr(struct STnode *h) {
    h->N = (h->l)->N + (h->r)->N +1;
    return h;
}

variable_types:
h
struct STnode *

return_type: struct STnode { struct palavra { char *literal; struct palavra *lema; struct palavra *prox; struct sentence { struct _G_fpos_t { long __pos; struct __mbstate_t { int __count; union { unsigned int __wch; char __wchb[4]; } __value; } __state; } position; struct sentence *prox; struct sentence *ant; } *list; } *item; struct STnode *l; int N; int red; } *


rotL

original_code:
link rotL(link h) {
    link x = (h->r); (h->r) = x->l; x->l = fixNr(h);
    x->red = x->l->red; x->l->red = 1;
    return fixNr(x);
}

canonical_original_code:
struct STnode *rotL(struct STnode *h) {
    struct STnode *x = (h->r); (h->r) = x->l; x->l = fixNr(h);
    x->red = x->l->red; x->l->red = 1;
    return fixNr(x);
}


rotR

original_code:
link rotR(link h) {
    link x = (h->l); (h->l) = x->r; x->r = fixNr(h);
    x->red = x->r->red; x->r->red = 1;
    return fixNr(x);
}

canonical_original_code:
struct STnode *rotR(struct STnode *h) {
    struct STnode *x = (h->l); (h->l) = x->r; x->r = fixNr(h);
    x->red = x->r->red; x->r->red = 1;
    return fixNr(x);
}


colorFlip

original_code:
void colorFlip(link h) {
    h->red = 1 - h->red;
    (h->l)->red = 1 - (h->l)->red;
    (h->r)->red = 1 - (h->r)->red;
}

canonical_original_code:
void colorFlip(struct STnode *h) {
    h->red = 1 - h->red;
    (h->l)->red = 1 - (h->l)->red;
    (h->r)->red = 1 - (h->r)->red;
}


mvRedL

original_code:
link mvRedL(link h) {
    colorFlip(h);
    if ((h->r->l)->red) { (h->r) = rotR((h->r)); h = rotL(h); }
    return h;
}

canonical_original_code:
struct STnode *mvRedL(struct STnode *h) {
    colorFlip(h);
    if ((h->r->l)->red) { (h->r) = rotR((h->r)); h = rotL(h); }
    return h;
}


mvRedR

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

colorFlip(a1);
if ( *(_DWORD *)(*(_QWORD *)(*(_QWORD *)(a1 + 8) + 8LL) + 28LL) )
result = rotR(a1);
else
result = a1;
return result;
}

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

func9(a1);
if ( *(_DWORD *)(*(_QWORD *)(*(_QWORD *)(a1 + 8) + 8LL) + 28LL) )
result = func8(a1);
else
result = a1;
return result;
}

original_code:
link mvRedR(link h) {
    colorFlip(h);
    if ((h->l->l)->red) { h = rotR(h); }
    return h;
}

canonical_original_code:
struct STnode *mvRedR(struct STnode *h) {
    colorFlip(h);
    if ((h->l->l)->red) { h = rotR(h); }
    return h;
}


balance

original_code:
link balance(link h) {
    if ((h->r)->red) h = rotL(h);
    if ((h->l)->red && (h->l->l)->red) h = rotR(h);
    if ((h->l)->red && (h->r)->red) colorFlip(h);
    return fixNr(h);
}

canonical_original_code:
struct STnode *balance(struct STnode *h) {
    if ((h->r)->red) h = rotL(h);
    if ((h->l)->red && (h->l->l)->red) h = rotR(h);
    if ((h->l)->red && (h->r)->red) colorFlip(h);
    return fixNr(h);
}


sortR

original_code:
void sortR(link h, void(*visit)(Item)) {
    if (h!=z) {
        sortR((h->l), visit);
        visit(*(h->item));
        sortR((h->r), visit);
    }
}

canonical_original_code:
void sortR(struct STnode *h, void (*visit)(struct palavra)) {
    if (h!=z) {
        sortR((h->l), visit);
        visit(*(h->item));
        sortR((h->r), visit);
    }
}

variable_types:
visit
void (*)(struct palavra)


STsort

decompiled_code:
// attributes: thunk
__int64 __fastcall STsort(__int64 a1, __int64 (__fastcall *a2)(__int64, _QWORD, __int64, __int64))
{
return sortR(a1, a2);
}

canonical_decompiled_code:
__int64 __fastcall func14(__int64 a1, __int64 (__fastcall *a2)(__int64, _QWORD, __int64, __int64))
{
return func13(a1, a2);
}

original_code:
void STsort(link head, void(*visit)(Item)) {
    sortR(head, visit);
}

canonical_original_code:
void STsort(struct STnode *head, void (*visit)(struct palavra)) {
    sortR(head, visit);
}


decompiled_code:
void __fastcall print_rangeR(_QWORD *a1, __int64 a2, __int64 a3)
{
_QWORD *v5; // rbx
__int64 v6; // rax
__int64 v7; // rax
__int64 v8; // rax
__int64 v9; // rsi
__int64 v10; // rdi
__int64 v11; // rdx
__int64 v12; // rcx
__int64 v13; // rax

if ( a1 != (_QWORD *)z )
{
v5 = a1;
do
{
v6 = key(*v5);
if ( (unsigned int)less(a2, v6) )
print_rangeR(v5[1], a2, a3);
v7 = key(*v5);
if ( (unsigned int)less(a2, v7) || (v8 = key(*v5), (unsigned int)eq(a2, v8)) )
{
v9 = a3;
v10 = key(*v5);
if ( (unsigned int)less(v10, a3) || (v9 = a3, v10 = key(*v5), (unsigned int)eq(v10, a3)) )
ITEMshow(v10, v9, v11, v12);
}
v13 = key(*v5);
if ( !(unsigned int)less(v13, a3) )
break;
v5 = (_QWORD *)v5[2];
}
while ( (_QWORD *)z != v5 );
}
}

canonical_decompiled_code:
void __fastcall func15(_QWORD *a1, __int64 a2, __int64 a3)
{
_QWORD *v5; // rbx
__int64 v6; // rax
__int64 v7; // rax
__int64 v8; // rax
__int64 v9; // rsi
__int64 v10; // rdi
__int64 v11; // rdx
__int64 v12; // rcx
__int64 v13; // rax

if ( a1 != (_QWORD *)z )
{
v5 = a1;
do
{
v6 = key(*v5);
if ( (unsigned int)less(a2, v6) )
func15(v5[1], a2, a3);
v7 = key(*v5);
if ( (unsigned int)less(a2, v7) || (v8 = key(*v5), (unsigned int)eq(a2, v8)) )
{
v9 = a3;
v10 = key(*v5);
if ( (unsigned int)less(v10, a3) || (v9 = a3, v10 = key(*v5), (unsigned int)eq(v10, a3)) )
ITEMshow(v10, v9, v11, v12);
}
v13 = key(*v5);
if ( !(unsigned int)less(v13, a3) )
break;
v5 = (_QWORD *)v5[2];
}
while ( (_QWORD *)z != v5 );
}
}

original_code:
void print_rangeR(link h, Key lo, Key hi) {
    if (h == z) return;
    if (less(lo, key(h->item)))
        print_rangeR((h->l), lo, hi);
    if ((less(lo, key(h->item)) || eq(lo, key(h->item)))
        && (less(key(h->item), hi) || eq(key(h->item), hi)))
        ITEMshow(*(h->item));
    if (less(key(h->item), hi))
        print_rangeR((h->r), lo, hi);
}

canonical_original_code:
void print_rangeR(struct STnode *h, char *lo, char *hi) {
    if (h == z) return;
    if (less(lo, key(h->item)))
        print_rangeR((h->l), lo, hi);
    if ((less(lo, key(h->item)) || eq(lo, key(h->item)))
        && (less(key(h->item), hi) || eq(key(h->item), hi)))
        ITEMshow(*(h->item));
    if (less(key(h->item), hi))
        print_rangeR((h->r), lo, hi);
}

variable_types:
lo
char *

variable_types:
hi
char *


decompiled_code:
// attributes: thunk
void __fastcall STprint_range(_QWORD *a1, __int64 a2, __int64 a3)
{
print_rangeR(a1, a2, a3);
}

canonical_decompiled_code:
void __fastcall func16(_QWORD *a1, __int64 a2, __int64 a3)
{
func15(a1, a2, a3);
}

original_code:
void STprint_range(link head, Key lo, Key hi) {
    print_rangeR(head, lo, hi);
}

canonical_original_code:
void STprint_range(struct STnode *head, char *lo, char *hi) {
    print_rangeR(head, lo, hi);
}


getMin

decompiled_code:
__int64 __fastcall getMin(__int64 a1)
{
__int64 v1; // rax

do
{
v1 = a1;
a1 = *(_QWORD *)(a1 + 8);
}
while ( a1 != z );
return *(_QWORD *)v1;
}

original_code:
Item *getMin(link h) {
    if ((h->l) == z) return h->item;
    else return getMin((h->l));
}

canonical_original_code:
struct palavra *getMin(struct STnode *h) {
    if ((h->l) == z) return h->item;
    else return getMin((h->l));
}


deleteMin

original_code:
link deleteMin(link h) {
    if ((h->l) == z) { free(h); return z; }
    if (!(h->l)->red && !(h->l->l)->red) h = mvRedL(h);
    (h->l) = deleteMin((h->l));
    return balance(h);
}

canonical_original_code:
struct STnode *deleteMin(struct STnode *h) {
    if ((h->l) == z) { free(h); return z; }
    if (!(h->l)->red && !(h->l->l)->red) h = mvRedL(h);
    (h->l) = deleteMin((h->l));
    return balance(h);
}


STdeleteMin

decompiled_code:
__int64 __fastcall STdeleteMin(__int64 a1)
{
__int64 v1; // rax
__int64 result; // rax
__int64 v3; // rdx

if ( !(unsigned int)STcount(a1) )
{
printf("Underflow");
exit(1);
}
if ( !*(_DWORD *)(*(_QWORD *)(a1 + 8) + 28LL) && !*(_DWORD *)(*(_QWORD *)(a1 + 16) + 28LL) )
*(_DWORD *)(a1 + 28) = 1;
v1 = deleteMin((_QWORD *)a1);
result = STcount(v1);
if ( (int)result > 0 )
*(_DWORD *)(v3 + 28) = 0;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func19(__int64 a1)
{
__int64 v1; // rax
__int64 result; // rax
__int64 v3; // rdx

if ( !(unsigned int)func3(a1) )
{
printf("Underflow");
exit(1);
}
if ( !*(_DWORD *)(*(_QWORD *)(a1 + 8) + 28LL) && !*(_DWORD *)(*(_QWORD *)(a1 + 16) + 28LL) )
*(_DWORD *)(a1 + 28) = 1;
v1 = func18((_QWORD *)a1);
result = func3(v1);
if ( (int)result > 0 )
*(_DWORD *)(v3 + 28) = 0;
return result;
}

original_code:
void STdeleteMin(link head) {
    if (STcount(head) == 0)
    { printf("Underflow"); exit(1); }
    if (!head->l->red && !head->r->red) head->red = 1;
    head = deleteMin(head);
    if (STcount(head) > 0) head->red = 0;
}

canonical_original_code:
void STdeleteMin(struct STnode *head) {
    if (STcount(head) == 0)
    { printf("Underflow"); exit(1); }
    if (!head->l->red && !head->r->red) head->red = 1;
    head = deleteMin(head);
    if (STcount(head) > 0) head->red = 0;
}


deleteMax

original_code:
link deleteMax(link h) {
    if ((h->l)->red) h = rotR(h);
    if ((h->r) == z) { free(h); return z; }
    if (!(h->r)->red && !(h->r->l)->red) h = mvRedR(h);
    (h->r) = deleteMax((h->r));
    return balance(h);
}

canonical_original_code:
struct STnode *deleteMax(struct STnode *h) {
    if ((h->l)->red) h = rotR(h);
    if ((h->r) == z) { free(h); return z; }
    if (!(h->r)->red && !(h->r->l)->red) h = mvRedR(h);
    (h->r) = deleteMax((h->r));
    return balance(h);
}


STdeleteMax

decompiled_code:
void __fastcall __noreturn STdeleteMax(__int64 a1)
{
if ( !(unsigned int)STcount(a1) )
printf("Underflow");
exit(1);
}

canonical_decompiled_code:
void __fastcall __noreturn func21(__int64 a1)
{
if ( !(unsigned int)func3(a1) )
printf("Underflow");
exit(1);
}

original_code:
void STdeleteMax(link head) {
    if (STcount(head) == 0)
        printf("Underflow"); exit(1);
    if (!head->l->red && !head->r->red) head->red = 1;
    head = deleteMax(head);
    if (STcount(head) > 0) head->red = 0;
}

canonical_original_code:
void STdeleteMax(struct STnode *head) {
    if (STcount(head) == 0)
        printf("Underflow"); exit(1);
    if (!head->l->red && !head->r->red) head->red = 1;
    head = deleteMax(head);
    if (STcount(head) > 0) head->red = 0;
}


deleteR

original_code:
link deleteR(link h, Key v) {
    Key t = key(h->item);
    if (less(v,t)) {
        if (!(h->l)->red && !(h->l->l)->red) h = mvRedL(h);
        (h->l) = deleteR((h->l), v);
    }
    else {
        if ((h->l)->red) h = rotR(h);
        if (eq(v,key(h->item)) && (h->r) == z)
            free(h); return z;
        if (!(h->r)->red && !(h->r->l)->red) h = mvRedR(h);
        if (eq(v,key(h->item))) {
            h->item = getMin((h->r));
            (h->r) = deleteMin((h->r));
        }
        else (h->r) = deleteR((h->r), v);
    }
    return balance(h);
}

canonical_original_code:
struct STnode *deleteR(struct STnode *h, char *v) {
    char *t = key(h->item);
    if (less(v,t)) {
        if (!(h->l)->red && !(h->l->l)->red) h = mvRedL(h);
        (h->l) = deleteR((h->l), v);
    }
    else {
        if ((h->l)->red) h = rotR(h);
        if (eq(v,key(h->item)) && (h->r) == z)
            free(h); return z;
        if (!(h->r)->red && !(h->r->l)->red) h = mvRedR(h);
        if (eq(v,key(h->item))) {
            h->item = getMin((h->r));
            (h->r) = deleteMin((h->r));
        }
        else (h->r) = deleteR((h->r), v);
    }
    return balance(h);
}


STdelete

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

if ( !*(_DWORD *)(*(_QWORD *)(a1 + 8) + 28LL) && !*(_DWORD *)(*(_QWORD *)(a1 + 16) + 28LL) )
*(_DWORD *)(a1 + 28) = 1;
v2 = deleteR((_QWORD *)a1, a2);
result = STcount(v2);
if ( (int)result > 0 )
*(_DWORD *)(v4 + 28) = 0;
return result;
}

original_code:
void STdelete(link head, Key v) {
    if (!head->l->red && !head->r->red) head->red = 1;
    head = deleteR(head, v);
    if (STcount(head) > 0) head->red = 0;
}

canonical_original_code:
void STdelete(struct STnode *head, char *v) {
    if (!head->l->red && !head->r->red) head->red = 1;
    head = deleteR(head, v);
    if (STcount(head) > 0) head->red = 0;
}


decompiled_code:
__int64 __fastcall faz_desenho(__int64 a1, int a2)
{
int v2; // er13
int v3; // ebx
__int64 result; // rax

if ( *(_DWORD *)(a1 + 24) )
{
if ( a2 )
printf("\\pstree{%s}{\n", "\\Tc*{3pt}");
else
printf("\\pstree[levelsep=%s, treesep=%s]{%s}{\n", "5mm", "3mm", "\\Tc*{3pt}");
v2 = faz_desenho(*(_QWORD *)(a1 + 8), (unsigned int)(a2 + 1));
v3 = faz_desenho(*(_QWORD *)(a1 + 16), (unsigned int)(a2 + 1));
puts("}");
result = (unsigned int)(v2 + v3 + 1);
}
else
{
puts("\\Tn");
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func24(__int64 a1, int a2)
{
int v2; // er13
int v3; // ebx
__int64 result; // rax

if ( *(_DWORD *)(a1 + 24) )
{
if ( a2 )
printf("\\pstree{%s}{\n", "\\Tc*{3pt}");
else
printf("\\pstree[levelsep=%s, treesep=%s]{%s}{\n", "5mm", "3mm", "\\Tc*{3pt}");
v2 = func24(*(_QWORD *)(a1 + 8), (unsigned int)(a2 + 1));
v3 = func24(*(_QWORD *)(a1 + 16), (unsigned int)(a2 + 1));
puts("}");
result = (unsigned int)(v2 + v3 + 1);
}
else
{
puts("\\Tn");
result = 1LL;
}
return result;
}

original_code:
int faz_desenho(link h, int nivel) {
    int d1, d2;
    if (h->N == 0) {
        printf("%s\n", no_externo);
        return 1;
    }
    if (nivel == 0)
        printf("\\pstree[levelsep=%s, treesep=%s]{%s}{\n", level_sep,
               tree_sep, no_interno);
    else
        printf("\\pstree{%s}{\n", no_interno);
    d1 = faz_desenho(h->l, nivel+1);
    d2 = faz_desenho(h->r, nivel+1);
    printf("}\n");
    return d1 + d2 + 1;
}

canonical_original_code:
int faz_desenho(struct STnode *h, int nivel) {
    int d1; int d2;
    if (h->N == 0) {
        printf("%s\n", no_externo);
        return 1;
    }
    if (nivel == 0)
        printf("\\pstree[levelsep=%s, treesep=%s]{%s}{\n", level_sep,
               tree_sep, no_interno);
    else
        printf("\\pstree{%s}{\n", no_interno);
    d1 = faz_desenho(h->l, nivel+1);
    d2 = faz_desenho(h->r, nivel+1);
    printf("}\n");
    return d1 + d2 + 1;
}

variable_types: nivel int


STdraw

decompiled_code:
int __fastcall STdraw(__int64 a1)
{
printf("\\rput{90}{");
faz_desenho(a1, 0);
return puts("}");
}

canonical_decompiled_code:
int __fastcall func25(__int64 a1)
{
printf("\\rput{90}{");
func24(a1, 0);
return puts("}");
}

original_code:
void STdraw(link head) {
    printf("\\rput{90}{");
    faz_desenho(head, 0);
    printf("}\n");
}

canonical_original_code:
void STdraw(struct STnode *head) {
    printf("\\rput{90}{");
    faz_desenho(head, 0);
    printf("}\n");
}


printR

original_code:
void printR(link h, int ind) {
    int i;
    if (h != z) {
        for (i=0; i<ind; i++) putchar(' ');
        printf("%s%c\n", key(h->item), h->red?'*':' ');
        printR((h->l), ind+2);
        printR((h->r), ind+2);
    }
}

canonical_original_code:
void printR(struct STnode *h, int ind) {
    int i;
    if (h != z) {
        for (i=0; i<ind; i++) putchar(' ');
        printf("%s%c\n", key(h->item), h->red?'*':' ');
        printR((h->l), ind+2);
        printR((h->r), ind+2);
    }
}

variable_types: ind int

variable_types: i int


STprint

decompiled_code:
int __fastcall STprint(__int64 a1)
{
printf("\n**** %d keys ****\n", *(unsigned int *)(a1 + 24));
printR(a1, 0);
return puts("**** ****** ****");
}

original_code:
void STprint(link head) {
    printf("\n**** %d keys ****\n", head->N);
    printR(head, 0);
    printf("**** ****** ****\n");
}

canonical_original_code:
void STprint(struct STnode *head) {
    printf("\n**** %d keys ****\n", head->N);
    printR(head, 0);
    printf("**** ****** ****\n");
}


ITEMscan

decompiled_code:
_QWORD *ITEMscan()
{
void *v0; // rbx
_QWORD *v1; // r12
_QWORD *result; // rax

v0 = malloc(0x32uLL);
v1 = malloc(0x20uLL);
_isoc99_scanf(&unk_128, v0);
*v1 = v0;
result = v1;
v1[1] = 0LL;
v1[2] = 0LL;
v1[3] = 0LL;
return result;
}

canonical_decompiled_code:
_QWORD *func0()
{
void *v0; // rbx
_QWORD *v1; // r12
_QWORD *result; // rax

v0 = malloc(0x32uLL);
v1 = malloc(0x20uLL);
_isoc99_scanf(&unk_128, v0);
*v1 = v0;
result = v1;
v1[1] = 0LL;
v1[2] = 0LL;
v1[3] = 0LL;
return result;
}

original_code:
Item *ITEMscan(Item *x) {
    char *t = malloc(50*sizeof(char));
    Item *palavra = malloc(sizeof(Item));
    scanf("%s", t);
    palavra->literal = t;
    palavra->prox = palavra->lema = ((void *)0);
    palavra->list = ((void *)0);
    return palavra;
}

canonical_original_code:
struct palavra *ITEMscan(struct palavra *x) {
    char *t = malloc(50*sizeof(char));
    struct palavra *palavra = malloc(sizeof(Item));
    scanf("%s", t);
    palavra->literal = t;
    palavra->prox = palavra->lema = ((void *)0);
    palavra->list = ((void *)0);
    return palavra;
}

variable_types:
x
struct palavra *

variable_types: struct palavra { char *literal; struct palavra *lema; struct palavra *prox; struct sentence { struct _G_fpos_t { long __pos; struct __mbstate_t { int __count; union { unsigned int __wch; char __wchb[4]; } __value; } __state; } position; struct sentence *prox; struct sentence *ant; } *list; } *


ITEMshow

decompiled_code:
int __fastcall ITEMshow(int a1, int a2, int a3, int a4, int a5, int a6, char *s)
{
return puts(s);
}

canonical_decompiled_code:
int __fastcall func1(int a1, int a2, int a3, int a4, int a5, int a6, char *s)
{
return puts(s);
}

original_code:
void ITEMshow(Item x) {
    printf("%s\n", x.literal);
}

canonical_original_code:
void ITEMshow(struct palavra x) {
    printf("%s\n", x.literal);
}

variable_types: struct palavra { char *literal; struct palavra *lema; struct palavra *prox; struct sentence { struct _G_fpos_t { long __pos; struct __mbstate_t { int __count; union { unsigned int __wch; char __wchb[4]; } __value; } __state; } position; struct sentence *prox; struct sentence *ant; } *list; }


key

decompiled_code:
__int64 __fastcall key(__int64 a1)
{
return *(_QWORD *)a1;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
return *(_QWORD *)a1;
}

original_code:
Key key(Item *item) {
    return item->literal;
}

canonical_original_code:
char *key(struct palavra *item) {
    return item->literal;
}


eq

decompiled_code:
_BOOL8 __fastcall eq(const char *a1, const char *a2)
{
return strcmp(a1, a2) == 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func3(const char *a1, const char *a2)
{
return strcmp(a1, a2) == 0;
}

original_code:
int eq(Key key1, Key key2) {
    if (strcmp(key1, key2) == 0) return 1;
    return 0;
}

canonical_original_code:
int eq(char *key1, char *key2) {
    if (strcmp(key1, key2) == 0) return 1;
    return 0;
}


less

decompiled_code:
__int64 __fastcall less(const char *a1, const char *a2)
{
return (unsigned int)strcmp(a1, a2) >> 31;
}

canonical_decompiled_code:
__int64 __fastcall func4(const char *a1, const char *a2)
{
return (unsigned int)strcmp(a1, a2) >> 31;
}

original_code:
int less(Key key1, Key key2) {
    if (strcmp(key1, key2) < 0) return 1;
    return 0;
}

canonical_original_code:
int less(char *key1, char *key2) {
    if (strcmp(key1, key2) < 0) return 1;
    return 0;
}


initItem

decompiled_code:
_QWORD *initItem()
{
_QWORD *result; // rax

result = malloc(0x20uLL);
NULLitem = (__int64)result;
*result = 0LL;
result[2] = 0LL;
result[1] = 0LL;
result[3] = 0LL;
return result;
}

canonical_decompiled_code:
_QWORD *func5()
{
_QWORD *result; // rax

result = malloc(0x20uLL);
NULLitem = (__int64)result;
*result = 0LL;
result[2] = 0LL;
result[1] = 0LL;
result[3] = 0LL;
return result;
}

original_code:
void initItem () {
    NULLitem = malloc(sizeof(Item));
    NULLitem->literal = ((void *)0);
    NULLitem->lema = NULLitem->prox = ((void *)0);
    NULLitem->list = ((void *)0);
}

canonical_original_code:
void initItem() {
    NULLitem = malloc(sizeof(Item));
    NULLitem->literal = ((void *)0);
    NULLitem->lema = NULLitem->prox = ((void *)0);
    NULLitem->list = ((void *)0);
}


getNULLitem

decompiled_code:
__int64 getNULLitem()
{
return NULLitem;
}

canonical_decompiled_code:
__int64 func6()
{
return NULLitem;
}

original_code:
Item *getNULLitem () {
    return NULLitem;
}

canonical_original_code:
struct palavra *getNULLitem() {
    return NULLitem;
}


isNULLitem

decompiled_code:
_BOOL8 __fastcall isNULLitem(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, __int64 a7)
{
return a7 == 0;
}

original_code:
int isNULLitem (Item item) {
    if (item.literal == ((void *)0)) return 1;
    else return 0;
}

canonical_original_code:
int isNULLitem(struct palavra item) {
    if (item.literal == ((void *)0)) return 1;
    else return 0;
}


main

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

v3 = 0LL;
for ( i = 1; i != 1000; ++i )
{
if ( (unsigned int)(-1431655765 * i) <= 0x55555555 || (unsigned int)(-858993459 * i) <= 0x33333333 )
v3 = (unsigned int)(i + v3);
}
printf("Sum = %d\n", v3);
return 0;
}

variable_types: sum int


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

if ( !getenv("dm3xx_boot_rec") && !getenv("dm3xx_boot_data") )
{
puts("please define env var 'dm3xx_boot_rec' or 'dm3xx_boot_data'");
exit(1);
}
if ( getenv("dm3xx_boot_rec") )
{
v3 = getenv2("dm3xx_boot_rec", argv);
dm3xx_boot_rec_make(v3);
}
if ( getenv("dm3xx_boot_data") )
{
v4 = (char *)getenv2("dm3xx_boot_data", argv);
sdcard_build_data(v4);
}
return 0;
}

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

if ( !getenv("dm3xx_boot_rec") && !getenv("dm3xx_boot_data") )
{
puts("please define env var 'dm3xx_boot_rec' or 'dm3xx_boot_data'");
exit(1);
}
if ( getenv("dm3xx_boot_rec") )
{
v3 = func7("dm3xx_boot_rec", argv);
func9(v3);
}
if ( getenv("dm3xx_boot_data") )
{
v4 = (char *)func7("dm3xx_boot_data", argv);
func12(v4);
}
return 0;
}

original_code:
int main()
{
 if (! getenv("dm3xx_boot_rec") && ! getenv("dm3xx_boot_data") ) {
  printf("please define env var 'dm3xx_boot_rec' or 'dm3xx_boot_data'\n");
  exit(1);
 }
 if ( getenv("dm3xx_boot_rec") )
  dm3xx_boot_rec_make(getenv2("dm3xx_boot_rec"));
 if ( getenv("dm3xx_boot_data") )
  sdcard_build_data(getenv2("dm3xx_boot_data"));
 return 0;
}


decompiled_code:
char *__fastcall getenv2(const char *a1)
{
char *result; // rax

result = getenv(a1);
if ( !result )
{
printf("please define environment variable \"%s\"\n", a1);
exit(1);
}
return result;
}

canonical_decompiled_code:
char *__fastcall func7(const char *a1)
{
char *result; // rax

result = getenv(a1);
if ( !result )
{
printf("please define environment variable \"%s\"\n", a1);
exit(1);
}
return result;
}

original_code:
char * getenv2(char * name)
{
 char * e = getenv(name);
 if (!e) {
  printf("please define environment variable \"%s\"\n",name);
  exit(1);
 }
 return e;
}

canonical_original_code:
char *getenv2(char *name)
{
 char *e = getenv(name);
 if (!e) {
  printf("please define environment variable \"%s\"\n",name);
  exit(1);
 }
 return e;
}

variable_types:
name
char *

variable_types:
e
char *