decompiled_code:
void __fastcall __noreturn worker_thread_function(void *ptr)
{
pthread_t *v1; // r12
pthread_t *v2; // rax
int v3; // ebx
char v4; // bl
__int64 v5; // rax
__int64 v6; // r12
char *v7; // r12
__int64 v8; // r13
__int64 v9; // r13
_QWORD *v10; // rax
_QWORD *v11; // rbx
__int64 v12; // r12
int v13; // eax
char *v14; // r12
char *v15; // r12
__int64 v16; // r13

pthread_mutex_lock(&connections_lock);
v1 = (pthread_t *)connections;
if ( *(_QWORD *)connections )
{
v2 = (pthread_t *)((char *)connections + 16);
v3 = 0;
do
{
++v3;
v1 = v2;
v2 += 2;
}
while ( *(v2 - 2) );
}
else
{
v3 = 0;
}
*v1 = pthread_self();
v1[1] = *(_QWORD *)ptr;
*((_DWORD *)ptr + 2) = v3;
pthread_mutex_unlock(&connections_lock);
signal(13, (__sighandler_t)qa_pipe_handler);
v4 = 0;
while ( (unsigned int)rtable_connect(*(_QWORD *)ptr) == -1 && !v4 )
{
pthread_mutex_lock(&check_quit);
v4 = quit_and_cleanup;
pthread_mutex_unlock(&check_quit);
}
if ( v4 )
{
LABEL_10:
free(ptr);
pthread_exit(0LL);
}
while ( 1 )
{
v10 = queue_get_task();
v11 = v10;
if ( !v10 )
goto LABEL_10;
*(_DWORD *)(*v10 + 4LL) = *((_DWORD *)ptr + 2);
v12 = *v10;
v13 = *(_DWORD *)(*v10 + 8LL);
if ( v13 == 40 )
{
*(_DWORD *)(v12 + 16) = rtable_size(*(_QWORD *)ptr);
goto LABEL_19;
}
if ( v13 > 40 )
{
if ( v13 == 50 )
{
*(_QWORD *)(v12 + 16) = rtable_get_keys(*(_QWORD *)ptr);
goto LABEL_19;
}
if ( v13 != 60 )
goto LABEL_32;
v7 = strdup(*(const char **)(v12 + 16));
if ( !v7 )
{
fprintf(stderr, "%s : %d : \"strdup\"\n", "worker_thread_function", 311LL);
*(_DWORD *)(*v11 + 8LL) = 99;
*(_DWORD *)(*v11 + 16LL) = -1;
}
v8 = *v11;
*(_QWORD *)(v8 + 16) = rtable_get_ts(*(_QWORD *)ptr, v7);
free(v7);
}
else
{
switch ( v13 )
{
case 20:
v15 = strdup(*(const char **)(v12 + 16));
if ( !v15 )
{
fprintf(stderr, "%s : %d : \"strdup\"\n", "worker_thread_function", 288LL);
*(_DWORD *)(*v11 + 8LL) = 99;
*(_DWORD *)(*v11 + 16LL) = -1;
}
v16 = *v11;
*(_QWORD *)(v16 + 16) = rtable_get(*(_QWORD *)ptr, v15);
free(v15);
break;
case 30:
v14 = strdup(*(const char **)(v12 + 16));
if ( !v14 )
{
fprintf(stderr, "%s : %d : \"strdup\"\n", "worker_thread_function", 276LL);
*(_DWORD *)(*v11 + 8LL) = 99;
*(_DWORD *)(*v11 + 16LL) = -1;
}
v9 = *v11;
*(_DWORD *)(v9 + 16) = rtable_del(*(_QWORD *)ptr, v14);
free(v14);
break;
case 10:
v5 = entry_dup(*(_QWORD *)(v12 + 16));
v6 = *v11;
*(_DWORD *)(v6 + 16) = rtable_put(*(_QWORD *)ptr, v5);
break;
default:
LABEL_32:
fprintf(stderr, "%s : %d : \"bad opcode\"\n", "worker_thread_function", 322LL);
break;
}
}
LABEL_19:
add_completed_task(v11);
}
}

canonical_decompiled_code:
void __fastcall __noreturn func11(void *ptr)
{
pthread_t *v1; // r12
pthread_t *v2; // rax
int v3; // ebx
char v4; // bl
__int64 v5; // rax
__int64 v6; // r12
char *v7; // r12
__int64 v8; // r13
__int64 v9; // r13
_QWORD *v10; // rax
_QWORD *v11; // rbx
__int64 v12; // r12
int v13; // eax
char *v14; // r12
char *v15; // r12
__int64 v16; // r13

pthread_mutex_lock(&connections_lock);
v1 = (pthread_t *)connections;
if ( *(_QWORD *)connections )
{
v2 = (pthread_t *)((char *)connections + 16);
v3 = 0;
do
{
++v3;
v1 = v2;
v2 += 2;
}
while ( *(v2 - 2) );
}
else
{
v3 = 0;
}
*v1 = pthread_self();
v1[1] = *(_QWORD *)ptr;
*((_DWORD *)ptr + 2) = v3;
pthread_mutex_unlock(&connections_lock);
signal(13, (__sighandler_t)qa_pipe_handler);
v4 = 0;
while ( (unsigned int)rtable_connect(*(_QWORD *)ptr) == -1 && !v4 )
{
pthread_mutex_lock(&check_quit);
v4 = quit_and_cleanup;
pthread_mutex_unlock(&check_quit);
}
if ( v4 )
{
LABEL_10:
free(ptr);
pthread_exit(0LL);
}
while ( 1 )
{
v10 = func9();
v11 = v10;
if ( !v10 )
goto LABEL_10;
*(_DWORD *)(*v10 + 4LL) = *((_DWORD *)ptr + 2);
v12 = *v10;
v13 = *(_DWORD *)(*v10 + 8LL);
if ( v13 == 40 )
{
*(_DWORD *)(v12 + 16) = rtable_size(*(_QWORD *)ptr);
goto LABEL_19;
}
if ( v13 > 40 )
{
if ( v13 == 50 )
{
*(_QWORD *)(v12 + 16) = rtable_get_keys(*(_QWORD *)ptr);
goto LABEL_19;
}
if ( v13 != 60 )
goto LABEL_32;
v7 = strdup(*(const char **)(v12 + 16));
if ( !v7 )
{
fprintf(stderr, "%s : %d : \"strdup\"\n", "worker_thread_function", 311LL);
*(_DWORD *)(*v11 + 8LL) = 99;
*(_DWORD *)(*v11 + 16LL) = -1;
}
v8 = *v11;
*(_QWORD *)(v8 + 16) = rtable_get_ts(*(_QWORD *)ptr, v7);
free(v7);
}
else
{
switch ( v13 )
{
case 20:
v15 = strdup(*(const char **)(v12 + 16));
if ( !v15 )
{
fprintf(stderr, "%s : %d : \"strdup\"\n", "worker_thread_function", 288LL);
*(_DWORD *)(*v11 + 8LL) = 99;
*(_DWORD *)(*v11 + 16LL) = -1;
}
v16 = *v11;
*(_QWORD *)(v16 + 16) = rtable_get(*(_QWORD *)ptr, v15);
free(v15);
break;
case 30:
v14 = strdup(*(const char **)(v12 + 16));
if ( !v14 )
{
fprintf(stderr, "%s : %d : \"strdup\"\n", "worker_thread_function", 276LL);
*(_DWORD *)(*v11 + 8LL) = 99;
*(_DWORD *)(*v11 + 16LL) = -1;
}
v9 = *v11;
*(_DWORD *)(v9 + 16) = rtable_del(*(_QWORD *)ptr, v14);
free(v14);
break;
case 10:
v5 = entry_dup(*(_QWORD *)(v12 + 16));
v6 = *v11;
*(_DWORD *)(v6 + 16) = rtable_put(*(_QWORD *)ptr, v5);
break;
default:
LABEL_32:
fprintf(stderr, "%s : %d : \"bad opcode\"\n", "worker_thread_function", 322LL);
break;
}
}
LABEL_19:
func10(v11);
}
}

original_code:
void *worker_thread_function(void *arg) {
 char *key = ((void *)0);
 struct entry_t *entry;
 struct qa_table_t *table = (struct qa_table_t *)arg;
 _Bool quit = 0;
 int i = 0;
 pthread_mutex_lock(&connections_lock);
 while(connections[i].self != 0) {
  i ++;
 }
 connections[i].self = pthread_self();
 connections[i].table = table->table;
 table->id = i;
 pthread_mutex_unlock(&connections_lock);
 signal(13, (__sighandler_t)qa_pipe_handler);
 while(rtable_connect(table->table) == -1 && !quit) {
  pthread_mutex_lock(&check_quit);
  quit = quit_and_cleanup;
  pthread_mutex_unlock(&check_quit);
 }
 while(!quit) {
  struct task_t *task = queue_get_task();
  if(task) {
   task->task->sender = table->id;
   switch(task->task->opcode) {
    case 30:
     key = strdup(task->task->content.key);
     if(!(key)) {
      fprintf( stderr, "%s : %d : ""\"strdup\"""\n", __FUNCTION__, 276);
      task->task->opcode = 99;
      task->task->content.result = -1;
     }
     task->task->content.result = rtable_del(table->table, key);
     free(key);
     key = ((void *)0);
     break;
    case 20:
     key = strdup(task->task->content.key);
     if(!(key)) {
      fprintf( stderr, "%s : %d : ""\"strdup\"""\n", __FUNCTION__, 288);
      task->task->opcode = 99;
      task->task->content.result = -1;
     }
     task->task->content.value = rtable_get(table->table, key);
     free(key);
     key = ((void *)0);
     break;
    case 50:
     task->task->content.keys = rtable_get_keys(table->table);
     break;
    case 10:
     entry = entry_dup(task->task->content.entry);
     task->task->content.result = rtable_put(table->table, entry);
     break;
    case 40:
     task->task->content.result = rtable_size(table->table);
     break;
    case 60:
     key = strdup(task->task->content.key);
     if(!(key)) {
      fprintf( stderr, "%s : %d : ""\"strdup\"""\n", __FUNCTION__, 311);
      task->task->opcode = 99;
      task->task->content.result = -1;
     }
     task->task->content.timestamp = rtable_get_ts(table->table, key);
     free(key);
     key = ((void *)0);
     break;
    default:
     fprintf( stderr, "%s : %d : ""\"bad opcode\"""\n", __FUNCTION__, 322);
     break;
   }
   add_completed_task(task);
  } else {
   quit = 1;
  }
 }
 if(table) {
  free(table);
 }
 pthread_exit(0);
}

canonical_original_code:
void *worker_thread_function(void *arg) {
 char *key = ((void *)0);
 struct entry_t *entry;
 struct qa_table_t *table = (struct qa_table_t *)arg;
 _Bool quit = 0;
 int i = 0;
 pthread_mutex_lock(&connections_lock);
 while(connections[i].self != 0) {
  i ++;
 }
 connections[i].self = pthread_self();
 connections[i].table = table->table;
 table->id = i;
 pthread_mutex_unlock(&connections_lock);
 signal(13, (void (*)(int))qa_pipe_handler);
 while(rtable_connect(table->table) == -1 && !quit) {
  pthread_mutex_lock(&check_quit);
  quit = quit_and_cleanup;
  pthread_mutex_unlock(&check_quit);
 }
 while(!quit) {
  struct task_t *task = queue_get_task();
  if(task) {
   task->task->sender = table->id;
   switch(task->task->opcode) {
    case 30:
     key = strdup(task->task->content.key);
     if(!(key)) {
      fprintf( stderr, "%s : %d : ""\"strdup\"""\n", __FUNCTION__, 276);
      task->task->opcode = 99;
      task->task->content.result = -1;
     }
     task->task->content.result = rtable_del(table->table, key);
     free(key);
     key = ((void *)0);
     break;
    case 20:
     key = strdup(task->task->content.key);
     if(!(key)) {
      fprintf( stderr, "%s : %d : ""\"strdup\"""\n", __FUNCTION__, 288);
      task->task->opcode = 99;
      task->task->content.result = -1;
     }
     task->task->content.value = rtable_get(table->table, key);
     free(key);
     key = ((void *)0);
     break;
    case 50:
     task->task->content.keys = rtable_get_keys(table->table);
     break;
    case 10:
     entry = entry_dup(task->task->content.entry);
     task->task->content.result = rtable_put(table->table, entry);
     break;
    case 40:
     task->task->content.result = rtable_size(table->table);
     break;
    case 60:
     key = strdup(task->task->content.key);
     if(!(key)) {
      fprintf( stderr, "%s : %d : ""\"strdup\"""\n", __FUNCTION__, 311);
      task->task->opcode = 99;
      task->task->content.result = -1;
     }
     task->task->content.timestamp = rtable_get_ts(table->table, key);
     free(key);
     key = ((void *)0);
     break;
    default:
     fprintf( stderr, "%s : %d : ""\"bad opcode\"""\n", __FUNCTION__, 322);
     break;
   }
   add_completed_task(task);
  } else {
   quit = 1;
  }
 }
 if(table) {
  free(table);
 }
 pthread_exit(0);
}

variable_types:
arg
void *

variable_types:
key
char *

user_defined_types: struct rtable_t { int socket; char *ip; char *porto; }


repo: vascoorey/DistributedTable

decompiled_code:
_QWORD *get_completed_task()
{
void *v0; // r12
char v1; // bp
_QWORD *v2; // rbx

pthread_mutex_lock(&done_lock);
v0 = done;
if ( done )
{
v2 = done;
LABEL_5:
done = (void *)v2[1];
pthread_mutex_unlock(&done_lock);
return v2;
}
do
{
pthread_cond_wait(&done_not_empty, &done_lock);
pthread_mutex_lock(&check_quit);
v1 = quit_and_cleanup;
pthread_mutex_unlock(&check_quit);
v2 = done;
}
while ( !done && !v1 );
if ( !v1 )
goto LABEL_5;
return v0;
}

canonical_decompiled_code:
_QWORD *func12()
{
void *v0; // r12
char v1; // bp
_QWORD *v2; // rbx

pthread_mutex_lock(&done_lock);
v0 = done;
if ( done )
{
v2 = done;
LABEL_5:
done = (void *)v2[1];
pthread_mutex_unlock(&done_lock);
return v2;
}
do
{
pthread_cond_wait(&done_not_empty, &done_lock);
pthread_mutex_lock(&check_quit);
v1 = quit_and_cleanup;
pthread_mutex_unlock(&check_quit);
v2 = done;
}
while ( !done && !v1 );
if ( !v1 )
goto LABEL_5;
return v0;
}

original_code:
struct task_t *get_completed_task() {
 _Bool quit = 0;
 struct task_t *done_task = ((void *)0);
 pthread_mutex_lock(&done_lock);
 while(!done && !quit) {
  pthread_cond_wait(&done_not_empty, &done_lock);
  pthread_mutex_lock(&check_quit);
  quit = quit_and_cleanup;
  pthread_mutex_unlock(&check_quit);
 }
 if(!quit) {
  done_task = done;
  done = done->next;
  pthread_mutex_unlock(&done_lock);
 }
 return done_task;
}

variable_types: struct task_t { struct quorum_op_t { int id; int sender; int opcode; union content_u { struct entry_t { char *key; struct data_t { int datasize; void *data; long timestamp; } *value; } *entry; long timestamp; char *key; char **keys; struct data_t *value; int result; } content; } *task; struct task_t *next; int id; } *

user_defined_types: struct task_t { struct quorum_op_t *task; struct task_t *next; int id; }

user_defined_types: struct quorum_op_t { int id; int sender; int opcode; union content_u content; }

user_defined_types: union content_u { struct entry_t *entry; long timestamp; char *key; char **keys; struct data_t *value; int result; }

user_defined_types: struct entry_t { char *key; struct data_t *value; }


decompiled_code:
int clear_completed_tasks()
{
__int64 *v0; // rbx
__int64 *v2; // rax
__int64 v3; // rax
int v4; // edx

pthread_mutex_lock(&done_lock);
v0 = (__int64 *)done;
if ( done )
{
do
{
v2 = v0;
v0 = (__int64 *)v0[1];
v3 = *v2;
if ( v3 )
{
v4 = *(_DWORD *)(v3 + 8);
if ( v4 == 20 )
{
data_destroy(*(_QWORD *)(v3 + 16));
}
else if ( v4 == 50 )
{
table_free_keys(*(_QWORD *)(v3 + 16));
}
free(*(void **)done);
}
free(done);
done = v0;
}
while ( v0 );
}
done = 0LL;
return pthread_mutex_unlock(&done_lock);
}

canonical_decompiled_code:
int func13()
{
__int64 *v0; // rbx
__int64 *v2; // rax
__int64 v3; // rax
int v4; // edx

pthread_mutex_lock(&done_lock);
v0 = (__int64 *)done;
if ( done )
{
do
{
v2 = v0;
v0 = (__int64 *)v0[1];
v3 = *v2;
if ( v3 )
{
v4 = *(_DWORD *)(v3 + 8);
if ( v4 == 20 )
{
data_destroy(*(_QWORD *)(v3 + 16));
}
else if ( v4 == 50 )
{
table_free_keys(*(_QWORD *)(v3 + 16));
}
free(*(void **)done);
}
free(done);
done = v0;
}
while ( v0 );
}
done = 0LL;
return pthread_mutex_unlock(&done_lock);
}

original_code:
void clear_completed_tasks() {
 struct task_t *task;
 pthread_mutex_lock(&done_lock);
 while(done) {
  task = done->next;
  if(done->task) {
   switch (done->task->opcode) {
    case 20:
     data_destroy(done->task->content.value);
     break;
    case 50:
     table_free_keys(done->task->content.keys);
     break;
    default:
     break;
   }
   free(done->task);
  }
  free(done);
  done = task;
 }
 done = ((void *)0);
 pthread_mutex_unlock(&done_lock);
}

return_type: void

user_defined_types: struct data_t { int datasize; void *data; long timestamp; }


decompiled_code:
int clear_tasks()
{
void **v0; // rbx
void **v1; // rbp

pthread_mutex_lock(&queue_lock);
v0 = (void **)queue_head;
if ( queue_head )
{
do
{
v1 = v0;
v0 = (void **)v0[1];
free(*v1);
free(v1);
queue_head = v0;
}
while ( v0 );
}
queue_head = 0LL;
return pthread_mutex_unlock(&queue_lock);
}

canonical_decompiled_code:
int func14()
{
void **v0; // rbx
void **v1; // rbp

pthread_mutex_lock(&queue_lock);
v0 = (void **)queue_head;
if ( queue_head )
{
do
{
v1 = v0;
v0 = (void **)v0[1];
free(*v1);
free(v1);
queue_head = v0;
}
while ( v0 );
}
queue_head = 0LL;
return pthread_mutex_unlock(&queue_lock);
}

original_code:
void clear_tasks() {
 struct task_t *task;
 pthread_mutex_lock(&queue_lock);
 while (queue_head) {
  task = queue_head->next;
  free(queue_head->task);
  free(queue_head);
  queue_head = task;
 }
 queue_head = ((void *)0);
 pthread_mutex_unlock(&queue_lock);
}


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

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

original_code:
static inline unsigned char
to_uchar (char ch)
{
  return ch;
}

canonical_original_code:
static inline unsigned char to_uchar(char ch)
{
  return ch;
}

variable_types: ch char

return_type: unsigned char


original_code:
void
base64_encode (const char *in, size_t inlen,
        char *out, size_t outlen)
{
  static const char b64str[64] =
    "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
  while (inlen && outlen)
    {
      *out++ = b64str[(to_uchar (in[0]) >> 2) & 0x3f];
      if (!--outlen)
 break;
      *out++ = b64str[((to_uchar (in[0]) << 4)
         + (--inlen ? to_uchar (in[1]) >> 4 : 0))
        & 0x3f];
      if (!--outlen)
 break;
      *out++ =
 (inlen
  ? b64str[((to_uchar (in[1]) << 2)
     + (--inlen ? to_uchar (in[2]) >> 6 : 0))
    & 0x3f]
  : '=');
      if (!--outlen)
 break;
      *out++ = inlen ? b64str[to_uchar (in[2]) & 0x3f] : '=';
      if (!--outlen)
 break;
      if (inlen)
 inlen--;
      if (inlen)
 in += 3;
    }
  if (outlen)
    *out = '\0';
}

canonical_original_code:
void base64_encode(char *in, unsigned long inlen, char *out, unsigned long outlen)
{
  static char b64str[64] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
  while (inlen && outlen)
    {
      *out++ = b64str[(to_uchar (in[0]) >> 2) & 0x3f];
      if (!--outlen)
 break;
      *out++ = b64str[((to_uchar (in[0]) << 4)
         + (--inlen ? to_uchar (in[1]) >> 4 : 0))
        & 0x3f];
      if (!--outlen)
 break;
      *out++ =
 (inlen
  ? b64str[((to_uchar (in[1]) << 2)
     + (--inlen ? to_uchar (in[2]) >> 6 : 0))
    & 0x3f]
  : '=');
      if (!--outlen)
 break;
      *out++ = inlen ? b64str[to_uchar (in[2]) & 0x3f] : '=';
      if (!--outlen)
 break;
      if (inlen)
 inlen--;
      if (inlen)
 in += 3;
    }
  if (outlen)
    *out = '\0';
}

variable_types:
in
char *

variable_types:
inlen
unsigned long

variable_types:
out
char *

variable_types:
outlen
unsigned long


decompiled_code:
__int64 __fastcall base64_encode_alloc(char *a1, unsigned __int64 a2, _QWORD *a3)
{
unsigned __int64 v4; // rdx
__int64 v5; // rbx
unsigned __int64 v6; // r14
_BYTE *v8; // rdx

v4 = (a2 + 2) / 3;
v5 = 4 * v4;
v6 = 4 * v4 + 1;
if ( a2 <= v6 )
{
v8 = malloc(4 * v4 + 1);
*a3 = v8;
if ( v8 )
base64_encode(a1, a2, v8, v6);
else
v5 = v6;
}
else
{
*a3 = 0LL;
v5 = 0LL;
}
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func2(char *a1, unsigned __int64 a2, _QWORD *a3)
{
unsigned __int64 v4; // rdx
__int64 v5; // rbx
unsigned __int64 v6; // r14
_BYTE *v8; // rdx

v4 = (a2 + 2) / 3;
v5 = 4 * v4;
v6 = 4 * v4 + 1;
if ( a2 <= v6 )
{
v8 = malloc(4 * v4 + 1);
*a3 = v8;
if ( v8 )
func1(a1, a2, v8, v6);
else
v5 = v6;
}
else
{
*a3 = 0LL;
v5 = 0LL;
}
return v5;
}

original_code:
size_t
base64_encode_alloc (const char *in, size_t inlen, char **out)
{
  size_t outlen = 1 + ((((inlen) + 2) / 3) * 4);
  if (inlen > outlen)
    {
      *out = ((void *)0);
      return 0;
    }
  *out = malloc (outlen);
  if (!*out)
    return outlen;
  base64_encode (in, inlen, *out, outlen);
  return outlen - 1;
}

canonical_original_code:
unsigned long base64_encode_alloc(char *in, unsigned long inlen, char **out)
{
  unsigned long outlen = 1 + ((((inlen) + 2) / 3) * 4);
  if (inlen > outlen)
    {
      *out = ((void *)0);
      return 0;
    }
  *out = malloc (outlen);
  if (!*out)
    return outlen;
  base64_encode (in, inlen, *out, outlen);
  return outlen - 1;
}

variable_types:
out
char **

return_type: unsigned long


decompiled_code:
__int64 __fastcall isbase64(char a1)
{
return (unsigned int)~(unsigned __int8)b64[(unsigned __int8)to_uchar(a1)] >> 7;
}

canonical_decompiled_code:
__int64 __fastcall func3(char a1)
{
return (unsigned int)~(unsigned __int8)b64[(unsigned __int8)func0(a1)] >> 7;
}

original_code:
_Bool
isbase64 (char ch)
{
  return 1 && 0 <= b64[to_uchar (ch)];
}

canonical_original_code:
_Bool isbase64(char ch)
{
  return 1 && 0 <= b64[to_uchar (ch)];
}


original_code:
_Bool
base64_decode (const char *in, size_t inlen,
        char *out, size_t *outlen)
{
  size_t outleft = *outlen;
  while (inlen >= 2)
    {
      if (!isbase64 (in[0]) || !isbase64 (in[1]))
 break;
      if (outleft)
 {
   *out++ = ((b64[to_uchar (in[0])] << 2)
      | (b64[to_uchar (in[1])] >> 4));
   outleft--;
 }
      if (inlen == 2)
 break;
      if (in[2] == '=')
 {
   if (inlen != 4)
     break;
   if (in[3] != '=')
     break;
 }
      else
 {
   if (!isbase64 (in[2]))
     break;
   if (outleft)
     {
       *out++ = (((b64[to_uchar (in[1])] << 4) & 0xf0)
   | (b64[to_uchar (in[2])] >> 2));
       outleft--;
     }
   if (inlen == 3)
     break;
   if (in[3] == '=')
     {
       if (inlen != 4)
  break;
     }
   else
     {
       if (!isbase64 (in[3]))
  break;
       if (outleft)
  {
    *out++ = (((b64[to_uchar (in[2])] << 6) & 0xc0)
       | b64[to_uchar (in[3])]);
    outleft--;
  }
     }
 }
      in += 4;
      inlen -= 4;
    }
  *outlen -= outleft;
  if (inlen != 0)
    return 0;
  return 1;
}

canonical_original_code:
_Bool base64_decode(char *in, unsigned long inlen, char *out, unsigned long *outlen)
{
  unsigned long outleft = *outlen;
  while (inlen >= 2)
    {
      if (!isbase64 (in[0]) || !isbase64 (in[1]))
 break;
      if (outleft)
 {
   *out++ = ((b64[to_uchar (in[0])] << 2)
      | (b64[to_uchar (in[1])] >> 4));
   outleft--;
 }
      if (inlen == 2)
 break;
      if (in[2] == '=')
 {
   if (inlen != 4)
     break;
   if (in[3] != '=')
     break;
 }
      else
 {
   if (!isbase64 (in[2]))
     break;
   if (outleft)
     {
       *out++ = (((b64[to_uchar (in[1])] << 4) & 0xf0)
   | (b64[to_uchar (in[2])] >> 2));
       outleft--;
     }
   if (inlen == 3)
     break;
   if (in[3] == '=')
     {
       if (inlen != 4)
  break;
     }
   else
     {
       if (!isbase64 (in[3]))
  break;
       if (outleft)
  {
    *out++ = (((b64[to_uchar (in[2])] << 6) & 0xc0)
       | b64[to_uchar (in[3])]);
    outleft--;
  }
     }
 }
      in += 4;
      inlen -= 4;
    }
  *outlen -= outleft;
  if (inlen != 0)
    return 0;
  return 1;
}

variable_types:
outlen
unsigned long *

variable_types:
outleft
unsigned long


decompiled_code:
__int64 __fastcall base64_decode_alloc(char *a1, unsigned __int64 a2, void **a3, size_t *a4)
{
_BYTE *v6; // rax
unsigned int v7; // eax
unsigned int v8; // ebx
size_t v10[6]; // [rsp+8h] [rbp-30h] BYREF

v10[0] = 3 * (a2 >> 2) + 2;
v6 = malloc(v10[0]);
*a3 = v6;
if ( !v6 )
return 1;
LOBYTE(v7) = base64_decode(a1, a2, v6, (__int64 *)v10);
v8 = v7;
if ( (_BYTE)v7 )
{
if ( a4 )
*a4 = v10[0];
}
else
{
free(*a3);
*a3 = 0LL;
}
return v8;
}

canonical_decompiled_code:
__int64 __fastcall func5(char *a1, unsigned __int64 a2, void **a3, size_t *a4)
{
_BYTE *v6; // rax
unsigned int v7; // eax
unsigned int v8; // ebx
size_t v10[6]; // [rsp+8h] [rbp-30h] BYREF

v10[0] = 3 * (a2 >> 2) + 2;
v6 = malloc(v10[0]);
*a3 = v6;
if ( !v6 )
return 1;
LOBYTE(v7) = func4(a1, a2, v6, (__int64 *)v10);
v8 = v7;
if ( (_BYTE)v7 )
{
if ( a4 )
*a4 = v10[0];
}
else
{
free(*a3);
*a3 = 0LL;
}
return v8;
}

original_code:
_Bool
base64_decode_alloc (const char *in, size_t inlen, char **out,
       size_t *outlen)
{
  size_t needlen = 3 * (inlen / 4) + 2;
  *out = malloc (needlen);
  if (!*out)
    return 1;
  if (!base64_decode (in, inlen, *out, &needlen))
    {
      free (*out);
      *out = ((void *)0);
      return 0;
    }
  if (outlen)
    *outlen = needlen;
  return 1;
}

canonical_original_code:
_Bool base64_decode_alloc(char *in, unsigned long inlen, char **out, unsigned long *outlen)
{
  unsigned long needlen = 3 * (inlen / 4) + 2;
  *out = malloc (needlen);
  if (!*out)
    return 1;
  if (!base64_decode (in, inlen, *out, &needlen))
    {
      free (*out);
      *out = ((void *)0);
      return 0;
    }
  if (outlen)
    *outlen = needlen;
  return 1;
}

variable_types:
needlen
unsigned long


decompiled_code:
__int64 __fastcall table_skel_init(int a1, __int64 a2)
{
__int64 result; // rax
__int64 v3; // rbp
__int64 v4; // rax
__int64 v5; // rbx
__int64 v6; // rdi

if ( a1 > 0 && a2 )
{
result = 0LL;
if ( !sharedPtable )
{
v3 = table_create();
if ( v3 )
{
v4 = pmanager_create(a2, 10000LL, 2LL);
v5 = v4;
if ( v4 )
{
v6 = ptable_open(v3, v4);
sharedPtable = v6;
if ( v6 )
{
ptable_collect_garbage(v6);
result = 0LL;
}
else
{
fprintf(stderr, "%s : %d : \"table_skel: ptable_open\"\n", "table_skel_init", 58LL);
table_destroy(v3);
pmanager_destroy(v5);
result = 0xFFFFFFFFLL;
}
}
else
{
fprintf(stderr, "%s : %d : \"table_skel: pmanager_create\"\n", "table_skel_init", 51LL);
table_destroy(v3);
result = 0xFFFFFFFFLL;
}
}
else
{
fprintf(stderr, "%s : %d : \"table_skel: table_create\"\n", "table_skel_init", 44LL);
result = 0xFFFFFFFFLL;
}
}
}
else
{
fprintf(stderr, "%s : %d : \"table_skel: NULL filename or invalid nlists\"\n", "table_skel_init", 36LL);
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1, __int64 a2)
{
__int64 result; // rax
__int64 v3; // rbp
__int64 v4; // rax
__int64 v5; // rbx
__int64 v6; // rdi

if ( a1 > 0 && a2 )
{
result = 0LL;
if ( !sharedPtable )
{
v3 = table_create();
if ( v3 )
{
v4 = pmanager_create(a2, 10000LL, 2LL);
v5 = v4;
if ( v4 )
{
v6 = ptable_open(v3, v4);
sharedPtable = v6;
if ( v6 )
{
ptable_collect_garbage(v6);
result = 0LL;
}
else
{
fprintf(stderr, "%s : %d : \"table_skel: ptable_open\"\n", "table_skel_init", 58LL);
table_destroy(v3);
pmanager_destroy(v5);
result = 0xFFFFFFFFLL;
}
}
else
{
fprintf(stderr, "%s : %d : \"table_skel: pmanager_create\"\n", "table_skel_init", 51LL);
table_destroy(v3);
result = 0xFFFFFFFFLL;
}
}
else
{
fprintf(stderr, "%s : %d : \"table_skel: table_create\"\n", "table_skel_init", 44LL);
result = 0xFFFFFFFFLL;
}
}
}
else
{
fprintf(stderr, "%s : %d : \"table_skel: NULL filename or invalid nlists\"\n", "table_skel_init", 36LL);
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
int table_skel_init(int n_lists, char *filename) {
    if(n_lists <= 0 || filename == ((void *)0)) {
        fprintf( stderr, "%s : %d : ""\"table_skel: NULL filename or invalid nlists\"""\n", __FUNCTION__, 36);
        return -1;
    }
    if(!sharedPtable) {
        struct table_t *sharedTable;
        if((sharedTable = table_create(n_lists)) == ((void *)0)) {
            fprintf( stderr, "%s : %d : ""\"table_skel: table_create\"""\n", __FUNCTION__, 44);
            return -1;
        }
        struct pmanager_t *sharedPmanager;
        if((sharedPmanager = pmanager_create(filename, 10000, 2)) == ((void *)0)) {
            fprintf( stderr, "%s : %d : ""\"table_skel: pmanager_create\"""\n", __FUNCTION__, 51);
            table_destroy(sharedTable);
            return -1;
        }
        if((sharedPtable = ptable_open(sharedTable, sharedPmanager)) == ((void *)0)) {
            fprintf( stderr, "%s : %d : ""\"table_skel: ptable_open\"""\n", __FUNCTION__, 58);
            table_destroy(sharedTable);
            pmanager_destroy(sharedPmanager);
            return -1;
        }
  ptable_collect_garbage(sharedPtable);
    }
    return 0;
}

variable_types:
filename
char *

variable_types: struct table_t { int hashSize; int numElems; int numUpdates; struct list_t { struct node_t { struct node_t *prev; struct node_t *next; struct entry_t { char *key; struct data_t { int datasize; void *data; long timestamp; } *value; } *entry; } *head; struct node_t *tail; int elements; } **table; } *

variable_types: struct pmanager_t { char *ckp_name; int ckp_fd; char *stt_name; int stt_fd; char *log_name; int log_fd; int create_flags; int max_log_size; int current_log_size; } *

return_type: int

user_defined_types: struct table_t { int hashSize; int numElems; int numUpdates; struct list_t **table; }

user_defined_types: struct list_t { struct node_t *head; struct node_t *tail; int elements; }

user_defined_types: struct node_t { struct node_t *prev; struct node_t *next; struct entry_t *entry; }


decompiled_code:
__int64 table_skel_destroy()
{
if ( sharedPtable )
ptable_close();
return 0LL;
}

canonical_decompiled_code:
__int64 func1()
{
if ( sharedPtable )
ptable_close();
return 0LL;
}

original_code:
int table_skel_destroy() {
    if(sharedPtable) {
        ptable_close(sharedPtable);
    }
    return 0;
}


invoke

original_code:
int invoke(struct message_t *msg) {
    int retVal = 0;
    char *key;
    struct entry_t *entry;
    if(sharedPtable && msg) {
        switch (msg->opcode) {
            case 20:
                if(msg->content.key) {
                    key = msg->content.key;
                    if(!(msg->content.value = ptable_get(sharedPtable, key))) {
                        if(!(msg->content.value = data_create(0))) {
                            msg->opcode = 99;
                            msg->c_type = 50;
                            msg->content.result = -1;
                        }
                    }
                    if(msg->content.value) {
                        msg->opcode ++;
                        msg->c_type = 40;
                        free(key);
                    }
                }
                else {
                    msg->opcode = 99;
                    msg->c_type = 50;
                    msg->content.result = -1;
                }
            break;
            case 10:
                if(msg->content.entry) {
                    entry = msg->content.entry;
                    if((retVal = ptable_put(sharedPtable, entry->key, entry->value)) != -1) {
                        msg->content.result = retVal;
                        msg->opcode ++;
                        msg->c_type = 50;
                    }
                    else {
      if(pmanager_store_table(sharedPtable->pmanager, sharedPtable->table) < 0) {
       fprintf( stderr, "%s : %d : ""\"persistent_table: pmanager_store_table\"""\n", __FUNCTION__, 137);
       msg->opcode = 99;
       msg->c_type = 50;
       msg->content.result = -1;
      }
      if(pmanager_rotate_log(sharedPtable->pmanager) != 0) {
       fprintf( stderr, "%s : %d : ""\"persistent_table: pmanager_rotate_log\"""\n", __FUNCTION__, 145);
       msg->opcode = 99;
       msg->c_type = 50;
       msg->content.result = -1;
      }
      if((retVal = ptable_put(sharedPtable, entry->key, entry->value)) != -1) {
       msg->content.result = retVal;
       msg->opcode ++;
       msg->c_type = 50;
      } else {
       msg->opcode = 99;
       msg->c_type = 50;
       msg->content.result = -1;
      }
                    }
                    entry_destroy(entry);
                }
                else {
                    msg->opcode = 99;
                    msg->c_type = 50;
                    msg->content.result = -1;
                }
            break;
            case 40:
                msg->content.result = ptable_size(sharedPtable);
                msg->opcode ++;
                msg->c_type = 50;
            break;
            case 30:
                if(msg->content.key) {
                    key = msg->content.key;
                    msg->content.key = ((void *)0);
                    retVal = ptable_del(sharedPtable, key);
                    msg->content.result = retVal;
                    msg->opcode ++;
                    msg->c_type = 50;
                    free(key);
                }
                else {
                    msg->opcode = 99;
                    msg->c_type = 50;
                    msg->content.result = -1;
                }
            break;
            case 50:
                if((msg->content.keys = ptable_get_keys(sharedPtable))) {
                    msg->opcode ++;
                    msg->c_type = 30;
                }
                else {
                    msg->opcode = 99;
                    msg->c_type = 50;
                    msg->content.result = -1;
                }
            break;
            case 60:
                if(msg->content.key) {
                    key = strdup(msg->content.key);
     free(msg->content.key);
                    if((msg->content.timestamp = ptable_get_ts(sharedPtable, key)) < 0) {
                            msg->opcode = 99;
       msg->c_type = 50;
                            msg->content.result = -1;
                    } else if(msg->content.timestamp >= 0) {
                        msg->opcode ++;
                        msg->c_type = 60;
                    }
                }
                else {
                    msg->opcode = 99;
                    msg->c_type = 50;
                    msg->content.result = -1;
                }
    free(key);
            break;
            default:
                fprintf( stderr, "%s : %d : ""\"opcode\"""\n", __FUNCTION__, 234);
                msg->opcode = 99;
                msg->c_type = 50;
                msg->content.result = -1;
            break;
        }
    }
    else {
        fprintf( stderr, "%s : %d : ""\"NULL sharedPtable\"""\n", __FUNCTION__, 242);
        retVal = -1;
    }
    return retVal;
}

variable_types: struct message_t { short opcode; short c_type; union content_u { struct entry_t { char *key; struct data_t { int datasize; void *data; long timestamp; } *value; } *entry; char *key; char **keys; struct data_t *value; int result; long timestamp; } content; } *

variable_types: retVal int

user_defined_types: struct message_t { short opcode; short c_type; union content_u content; }

user_defined_types: union content_u { struct entry_t *entry; char *key; char **keys; struct data_t *value; int result; long timestamp; }


decompiled_code:
__int64 table_skel_collect()
{
return ptable_collect_garbage(sharedPtable);
}

canonical_decompiled_code:
__int64 func3()
{
return ptable_collect_garbage(sharedPtable);
}

original_code:
void table_skel_collect() {
 ptable_collect_garbage(sharedPtable);
}


decompiled_code:
_DWORD *list_create()
{
_DWORD *v0; // rax
_DWORD *v1; // rbx

v0 = malloc(0x18uLL);
v1 = v0;
if ( v0 )
{
v0[4] = 0;
*(_QWORD *)v0 = 0LL;
*((_QWORD *)v0 + 1) = 0LL;
}
else
{
fprintf(stderr, "%s : %d : \"Malloc newList\"\n", "list_create", 24LL);
}
return v1;
}

canonical_decompiled_code:
_DWORD *func0()
{
_DWORD *v0; // rax
_DWORD *v1; // rbx

v0 = malloc(0x18uLL);
v1 = v0;
if ( v0 )
{
v0[4] = 0;
*(_QWORD *)v0 = 0LL;
*((_QWORD *)v0 + 1) = 0LL;
}
else
{
fprintf(stderr, "%s : %d : \"Malloc newList\"\n", "list_create", 24LL);
}
return v1;
}

original_code:
struct list_t *list_create() {
    struct list_t *newList = ((void *)0);
    if((newList = (struct list_t*)malloc(sizeof(struct list_t)))) {
        newList->elements = 0;
        newList->head = ((void *)0);
        newList->tail = ((void *)0);
    }
    else {
        fprintf( stderr, "%s : %d : ""\"Malloc newList\"""\n", __FUNCTION__, 24);
    }
    return newList;
}

canonical_original_code:
struct list_t *list_create() {
    struct list_t *newList = ((void *)0);
    if((newList = (struct list_t *)malloc(sizeof(struct list_t)))) {
        newList->elements = 0;
        newList->head = ((void *)0);
        newList->tail = ((void *)0);
    }
    else {
        fprintf( stderr, "%s : %d : ""\"Malloc newList\"""\n", __FUNCTION__, 24);
    }
    return newList;
}

variable_types: struct list_t { struct node_t { struct node_t *prev; struct node_t *next; struct entry_t { char *key; struct data_t { int datasize; void *data; long timestamp; } *value; } *entry; } *head; struct node_t *tail; int elements; } *


decompiled_code:
const char **__fastcall list_get(__int64 *a1, const char *a2)
{
__int64 v2; // rbp
const char **v3; // r13
int v4; // eax
const char **v5; // rbx
int v6; // edx

if ( a1 && a2 )
{
v2 = *a1;
v3 = 0LL;
LABEL_4:
v4 = 0;
while ( !v4 )
{
if ( !v2 )
break;
v5 = *(const char ***)(v2 + 16);
if ( !v5 || !*v5 )
break;
v6 = strcmp(*v5, a2);
v4 = 1;
if ( v6 )
{
v2 = *(_QWORD *)(v2 + 8);
goto LABEL_4;
}
v3 = v5;
}
}
else
{
fprintf(stderr, "%s : %d : \"Lista ou key NULL\"\n", "list_get", 163LL);
v3 = 0LL;
}
return v3;
}

canonical_decompiled_code:
const char **__fastcall func1(__int64 *a1, const char *a2)
{
__int64 v2; // rbp
const char **v3; // r13
int v4; // eax
const char **v5; // rbx
int v6; // edx

if ( a1 && a2 )
{
v2 = *a1;
v3 = 0LL;
LABEL_4:
v4 = 0;
while ( !v4 )
{
if ( !v2 )
break;
v5 = *(const char ***)(v2 + 16);
if ( !v5 || !*v5 )
break;
v6 = strcmp(*v5, a2);
v4 = 1;
if ( v6 )
{
v2 = *(_QWORD *)(v2 + 8);
goto LABEL_4;
}
v3 = v5;
}
}
else
{
fprintf(stderr, "%s : %d : \"Lista ou key NULL\"\n", "list_get", 163LL);
v3 = 0LL;
}
return v3;
}

original_code:
struct entry_t *list_get(struct list_t *list, char *key) {
    struct node_t *tempNode;
    struct entry_t *tempEntry = ((void *)0);
    int found = 0;
    if(list && key) {
        tempNode = list->head;
        while(!found && tempNode && tempNode->entry && tempNode->entry->key) {
            if(tempNode->entry->key && strcmp(tempNode->entry->key, key) == 0) {
                found = 1;
                tempEntry = tempNode->entry;
            }
            else {
                tempNode = tempNode->next;
            }
        }
    }
    else {
        fprintf( stderr, "%s : %d : ""\"Lista ou key NULL\"""\n", __FUNCTION__, 163);
    }
    return tempEntry;
}

variable_types: struct list_t { struct node_t { struct node_t *prev; struct node_t *next; struct entry_t *entry; } *head; struct node_t *tail; int elements; } *

variable_types:
key
char *

variable_types: struct node_t { struct node_t *prev; struct node_t *next; struct entry_t { char *key; struct data_t { int datasize; void *data; long timestamp; } *value; } *entry; } *

variable_types: found int


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

if ( !a1 )
return 0xFFFFFFFFLL;
result = 0xFFFFFFFFLL;
if ( *(int *)(a1 + 16) >= 0 )
result = *(unsigned int *)(a1 + 16);
return result;
}

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

if ( !a1 )
return 0xFFFFFFFFLL;
result = 0xFFFFFFFFLL;
if ( *(int *)(a1 + 16) >= 0 )
result = *(unsigned int *)(a1 + 16);
return result;
}

original_code:
int list_size(struct list_t *list) {
    return (list && list->elements >= 0 ? list->elements : -1);
}


decompiled_code:
void *__fastcall list_get_keys(__int64 *a1)
{
__int64 v1; // rbp
void *v2; // rax
void *v3; // r15
char **v4; // r12
int v5; // er13
char *v6; // rbx
__int64 v8; // rbp
void **v9; // [rsp+8h] [rbp-40h]

if ( a1 )
{
v1 = *a1;
v2 = malloc(8LL * (*((_DWORD *)a1 + 4) + 1));
v3 = v2;
if ( v2 )
{
if ( v1 )
{
v9 = (void **)v2;
v4 = (char **)v2;
v5 = 0;
while ( 1 )
{
v6 = strdup(**(const char ***)(v1 + 16));
*v4 = v6;
if ( !v6 )
break;
++v5;
v1 = *(_QWORD *)(v1 + 8);
++v4;
if ( !v1 )
goto LABEL_7;
}
fprintf(stderr, "%s : %d : \"Malloc\"\n", "list_get_keys", 204LL);
if ( v5 > 0 )
{
v8 = (__int64)&v9[(unsigned int)(v5 - 1) + 1];
do
free(*v9++);
while ( v9 != (void **)v8 );
}
free(v3);
v3 = 0LL;
}
else
{
v5 = 0;
LABEL_7:
if ( *((_DWORD *)a1 + 4) == v5 )
*((_QWORD *)v3 + v5) = 0LL;
}
}
else
{
fprintf(stderr, "%s : %d : \"Malloc keys\"\n", "list_get_keys", 221LL);
}
}
else
{
fprintf(stderr, "%s : %d : \"NULL Lista\"\n", "list_get_keys", 226LL);
v3 = 0LL;
}
return v3;
}

canonical_decompiled_code:
void *__fastcall func3(__int64 *a1)
{
__int64 v1; // rbp
void *v2; // rax
void *v3; // r15
char **v4; // r12
int v5; // er13
char *v6; // rbx
__int64 v8; // rbp
void **v9; // [rsp+8h] [rbp-40h]

if ( a1 )
{
v1 = *a1;
v2 = malloc(8LL * (*((_DWORD *)a1 + 4) + 1));
v3 = v2;
if ( v2 )
{
if ( v1 )
{
v9 = (void **)v2;
v4 = (char **)v2;
v5 = 0;
while ( 1 )
{
v6 = strdup(**(const char ***)(v1 + 16));
*v4 = v6;
if ( !v6 )
break;
++v5;
v1 = *(_QWORD *)(v1 + 8);
++v4;
if ( !v1 )
goto LABEL_7;
}
fprintf(stderr, "%s : %d : \"Malloc\"\n", "list_get_keys", 204LL);
if ( v5 > 0 )
{
v8 = (__int64)&v9[(unsigned int)(v5 - 1) + 1];
do
free(*v9++);
while ( v9 != (void **)v8 );
}
free(v3);
v3 = 0LL;
}
else
{
v5 = 0;
LABEL_7:
if ( *((_DWORD *)a1 + 4) == v5 )
*((_QWORD *)v3 + v5) = 0LL;
}
}
else
{
fprintf(stderr, "%s : %d : \"Malloc keys\"\n", "list_get_keys", 221LL);
}
}
else
{
fprintf(stderr, "%s : %d : \"NULL Lista\"\n", "list_get_keys", 226LL);
v3 = 0LL;
}
return v3;
}

original_code:
char **list_get_keys(struct list_t *list) {
    char **keys = ((void *)0);
    struct node_t *tempNode;
    int numMallocs = 0, counter = 0;
    if(list) {
        tempNode = list->head;
        if((keys = (char**)malloc((list->elements + 1)*sizeof(char*)))) {
            while(tempNode) {
                if((keys[numMallocs] = strdup(tempNode->entry->key))) {
                    numMallocs ++;
                    tempNode = tempNode->next;
                }
                else {
                    fprintf( stderr, "%s : %d : ""\"Malloc\"""\n", __FUNCTION__, 204);
                    tempNode = ((void *)0);
                    for(counter = 0; counter < numMallocs; counter ++) {
                        free(keys[counter]);
                    }
                    free(keys);
                    keys = ((void *)0);
                    numMallocs = 0;
                }
            }
            if(keys && numMallocs == list->elements) {
                keys[numMallocs] = ((void *)0);
            }
        }
        else {
            fprintf( stderr, "%s : %d : ""\"Malloc keys\"""\n", __FUNCTION__, 221);
            keys = ((void *)0);
        }
    }
    else {
        fprintf( stderr, "%s : %d : ""\"NULL Lista\"""\n", __FUNCTION__, 226);
    }
    return keys;
}

canonical_original_code:
char **list_get_keys(struct list_t *list) {
    char **keys = ((void *)0);
    struct node_t *tempNode;
    int numMallocs = 0; int counter = 0;
    if(list) {
        tempNode = list->head;
        if((keys = (char **)malloc((list->elements + 1)*sizeof(char *)))) {
            while(tempNode) {
                if((keys[numMallocs] = strdup(tempNode->entry->key))) {
                    numMallocs ++;
                    tempNode = tempNode->next;
                }
                else {
                    fprintf( stderr, "%s : %d : ""\"Malloc\"""\n", __FUNCTION__, 204);
                    tempNode = ((void *)0);
                    for(counter = 0; counter < numMallocs; counter ++) {
                        free(keys[counter]);
                    }
                    free(keys);
                    keys = ((void *)0);
                    numMallocs = 0;
                }
            }
            if(keys && numMallocs == list->elements) {
                keys[numMallocs] = ((void *)0);
            }
        }
        else {
            fprintf( stderr, "%s : %d : ""\"Malloc keys\"""\n", __FUNCTION__, 221);
            keys = ((void *)0);
        }
    }
    else {
        fprintf( stderr, "%s : %d : ""\"NULL Lista\"""\n", __FUNCTION__, 226);
    }
    return keys;
}

variable_types:
keys
char **

variable_types: numMallocs int

variable_types: counter int

return_type: char **


decompiled_code:
void __fastcall list_free_keys(void *ptr)
{
void *v2; // rdi
char *v3; // rbx

v2 = *(void **)ptr;
if ( v2 )
{
v3 = (char *)ptr + 8;
do
{
free(v2);
v3 += 8;
v2 = (void *)*((_QWORD *)v3 - 1);
}
while ( v2 );
}
free(ptr);
}

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

v2 = *(void **)ptr;
if ( v2 )
{
v3 = (char *)ptr + 8;
do
{
free(v2);
v3 += 8;
v2 = (void *)*((_QWORD *)v3 - 1);
}
while ( v2 );
}
free(ptr);
}

original_code:
void list_free_keys(char **keys) {
    int counter = 0;
    while(keys[counter]) {
        free(keys[counter]);
        counter++;
    }
    free(keys);
}


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

if ( a1 )
{
v2 = node_create(a2);
if ( v2 )
{
if ( *(_DWORD *)(a1 + 16) )
{
*(_QWORD *)(*(_QWORD *)(a1 + 8) + 8LL) = v2;
*v2 = *(_QWORD *)(a1 + 8);
}
else
{
*(_QWORD *)a1 = v2;
}
*(_QWORD *)(a1 + 8) = v2;
*(_QWORD *)(*(_QWORD *)(a1 + 8) + 8LL) = 0LL;
++*(_DWORD *)(a1 + 16);
result = 0LL;
}
else
{
fprintf(stderr, "%s : %d : \"node_create\"\n", "list_add", 79LL);
result = 0xFFFFFFFFLL;
}
}
else
{
fprintf(stderr, "%s : %d : \"NULL list\"\n", "list_add", 83LL);
result = 0xFFFFFFFFLL;
}
return result;
}

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

if ( a1 )
{
v2 = node_create(a2);
if ( v2 )
{
if ( *(_DWORD *)(a1 + 16) )
{
*(_QWORD *)(*(_QWORD *)(a1 + 8) + 8LL) = v2;
*v2 = *(_QWORD *)(a1 + 8);
}
else
{
*(_QWORD *)a1 = v2;
}
*(_QWORD *)(a1 + 8) = v2;
*(_QWORD *)(*(_QWORD *)(a1 + 8) + 8LL) = 0LL;
++*(_DWORD *)(a1 + 16);
result = 0LL;
}
else
{
fprintf(stderr, "%s : %d : \"node_create\"\n", "list_add", 79LL);
result = 0xFFFFFFFFLL;
}
}
else
{
fprintf(stderr, "%s : %d : \"NULL list\"\n", "list_add", 83LL);
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
int list_add(struct list_t *list, struct entry_t *entry) {
    int retVal = -1;
    struct node_t *newNode;
    if(list) {
        newNode = node_create(entry);
        if(newNode) {
            if(list->elements == 0) {
                list->head = newNode;
                list->tail = newNode;
            }
            else {
                list->tail->next = newNode;
                newNode->prev = list->tail;
                list->tail = newNode;
            }
            list->tail->next = ((void *)0);
            list->elements ++;
            retVal = 0;
        }
        else {
            fprintf( stderr, "%s : %d : ""\"node_create\"""\n", __FUNCTION__, 79);
        }
    }
    else {
        fprintf( stderr, "%s : %d : ""\"NULL list\"""\n", __FUNCTION__, 83);
    }
    return retVal;
}

variable_types:
entry
struct entry_t *


decompiled_code:
void __fastcall node_destroy(void *ptr)
{
if ( ptr )
{
if ( *((_QWORD *)ptr + 2) )
entry_destroy();
free(ptr);
}
}

canonical_decompiled_code:
void __fastcall func7(void *ptr)
{
if ( ptr )
{
if ( *((_QWORD *)ptr + 2) )
entry_destroy();
free(ptr);
}
}

original_code:
void node_destroy(struct node_t *node) {
    if(node) {
        if(node->entry) {
            entry_destroy(node->entry);
        }
        free(node);
    }
}


decompiled_code:
void __fastcall list_destroy(void *ptr)
{
_QWORD *v2; // rdi

if ( ptr )
{
v2 = *(_QWORD **)ptr;
if ( v2 )
{
do
{
*(_QWORD *)ptr = v2[1];
node_destroy(v2);
v2 = *(_QWORD **)ptr;
}
while ( *(_QWORD *)ptr );
}
free(ptr);
}
else
{
fprintf(stderr, "%s : %d : \"Lista NULL\"\n", "list_destroy", 48LL);
}
}

canonical_decompiled_code:
void __fastcall func8(void *ptr)
{
_QWORD *v2; // rdi

if ( ptr )
{
v2 = *(_QWORD **)ptr;
if ( v2 )
{
do
{
*(_QWORD *)ptr = v2[1];
func7(v2);
v2 = *(_QWORD **)ptr;
}
while ( *(_QWORD *)ptr );
}
free(ptr);
}
else
{
fprintf(stderr, "%s : %d : \"Lista NULL\"\n", "list_destroy", 48LL);
}
}

original_code:
void list_destroy(struct list_t *list) {
    struct node_t *tempNode;
    if(list) {
        while(list->head) {
            tempNode = list->head;
            list->head = list->head->next;
            node_destroy(tempNode);
        }
        free(list);
    }
    else {
        fprintf( stderr, "%s : %d : ""\"Lista NULL\"""\n", __FUNCTION__, 48);
    }
}


decompiled_code:
__int64 __fastcall list_remove(__int64 a1, const char *a2)
{
const char ***v2; // r15
const char ***v3; // rbp
int v4; // eax
bool v5; // bl
int v6; // edx
const char ***v7; // rax
const char **v9; // rax

if ( !a1 )
return 0xFFFFFFFFLL;
v2 = *(const char ****)a1;
v3 = *(const char ****)a1;
LABEL_3:
v4 = 0;
while ( 1 )
{
v5 = v4 == 0;
if ( !v3 || v4 )
break;
v6 = strcmp(*v3[2], a2);
v4 = 1;
if ( v6 )
{
v3 = (const char ***)v3[1];
goto LABEL_3;
}
}
if ( v4 )
{
if ( v3 == v2 )
{
*(_QWORD *)a1 = v3[1];
}
else if ( *(const char ****)(a1 + 8) == v3 )
{
v9 = *v3;
*(_QWORD *)(a1 + 8) = *v3;
v9[1] = 0LL;
}
else
{
v7 = (const char ***)v3[1];
(*v3)[1] = (const char *)v7;
if ( v7 )
*v7 = *v3;
}
node_destroy(v3);
--*(_DWORD *)(a1 + 16);
}
return (unsigned int)-v5;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1, const char *a2)
{
const char ***v2; // r15
const char ***v3; // rbp
int v4; // eax
bool v5; // bl
int v6; // edx
const char ***v7; // rax
const char **v9; // rax

if ( !a1 )
return 0xFFFFFFFFLL;
v2 = *(const char ****)a1;
v3 = *(const char ****)a1;
LABEL_3:
v4 = 0;
while ( 1 )
{
v5 = v4 == 0;
if ( !v3 || v4 )
break;
v6 = strcmp(*v3[2], a2);
v4 = 1;
if ( v6 )
{
v3 = (const char ***)v3[1];
goto LABEL_3;
}
}
if ( v4 )
{
if ( v3 == v2 )
{
*(_QWORD *)a1 = v3[1];
}
else if ( *(const char ****)(a1 + 8) == v3 )
{
v9 = *v3;
*(_QWORD *)(a1 + 8) = *v3;
v9[1] = 0LL;
}
else
{
v7 = (const char ***)v3[1];
(*v3)[1] = (const char *)v7;
if ( v7 )
*v7 = *v3;
}
func7(v3);
--*(_DWORD *)(a1 + 16);
}
return (unsigned int)-v5;
}

original_code:
int list_remove(struct list_t *list, char *key) {
    struct node_t *tempNode;
    int found = 0;
    if(list) {
        tempNode = list->head;
        while(!found && tempNode) {
            if(strcmp(tempNode->entry->key, key) == 0) {
                found = 1;
            }
            else {
                tempNode = tempNode->next;
            }
        }
        if(found) {
            if(tempNode == list->head) {
                list->head = tempNode->next;
            }
            else if(tempNode == list->tail) {
                list->tail = tempNode->prev;
                tempNode->prev->next = ((void *)0);
            }
            else {
                tempNode->prev->next = tempNode->next;
                if(tempNode->next) {
                    tempNode->next->prev = tempNode->prev;
                }
            }
            node_destroy(tempNode);
            list->elements --;
        }
    }
    return (found ? 0 : -1);
}


decompiled_code:
void __fastcall data_destroy(void *ptr)
{
void *v2; // rdi

if ( ptr )
{
v2 = (void *)*((_QWORD *)ptr + 1);
if ( v2 )
free(v2);
free(ptr);
}
}

canonical_decompiled_code:
void __fastcall func0(void *ptr)
{
void *v2; // rdi

if ( ptr )
{
v2 = (void *)*((_QWORD *)ptr + 1);
if ( v2 )
free(v2);
free(ptr);
}
}

original_code:
void data_destroy(struct data_t *data) {
 if(data) {
  if(data->data)
   free(data->data);
  free(data);
  data = ((void *)0);
    }
}

variable_types: struct data_t { int datasize; void *data; long timestamp; } *


decompiled_code:
void **__fastcall entry_dup(__int64 a1)
{
void **v1; // rbx
char *v2; // r12
__int64 v3; // rbp

if ( a1 )
{
v1 = (void **)malloc(0x10uLL);
if ( v1 )
{
v2 = strdup(*(const char **)a1);
*v1 = v2;
if ( v2 )
{
v3 = data_dup(*(_QWORD *)(a1 + 8));
v1[1] = (void *)v3;
if ( !v3 )
{
fprintf(stderr, "%s : %d : \"data_dup\"\n", "entry_dup", 45LL);
free(*v1);
free(v1);
v1 = 0LL;
}
}
else
{
fprintf(stderr, "%s : %d : \"strdup key\"\n", "entry_dup", 52LL);
free(v1);
v1 = 0LL;
}
}
else
{
fprintf(stderr, "%s : %d : \"malloc newEntry\"\n", "entry_dup", 58LL);
}
}
else
{
fprintf(stderr, "%s : %d : \"NULL entry\"\n", "entry_dup", 62LL);
v1 = 0LL;
}
return v1;
}

canonical_decompiled_code:
void **__fastcall func0(__int64 a1)
{
void **v1; // rbx
char *v2; // r12
__int64 v3; // rbp

if ( a1 )
{
v1 = (void **)malloc(0x10uLL);
if ( v1 )
{
v2 = strdup(*(const char **)a1);
*v1 = v2;
if ( v2 )
{
v3 = data_dup(*(_QWORD *)(a1 + 8));
v1[1] = (void *)v3;
if ( !v3 )
{
fprintf(stderr, "%s : %d : \"data_dup\"\n", "entry_dup", 45LL);
free(*v1);
free(v1);
v1 = 0LL;
}
}
else
{
fprintf(stderr, "%s : %d : \"strdup key\"\n", "entry_dup", 52LL);
free(v1);
v1 = 0LL;
}
}
else
{
fprintf(stderr, "%s : %d : \"malloc newEntry\"\n", "entry_dup", 58LL);
}
}
else
{
fprintf(stderr, "%s : %d : \"NULL entry\"\n", "entry_dup", 62LL);
v1 = 0LL;
}
return v1;
}

original_code:
struct entry_t *entry_dup(struct entry_t *entry) {
    struct entry_t *newEntry = ((void *)0);
    if (entry) {
        if ((newEntry = (struct entry_t*) malloc(sizeof (struct entry_t)))) {
            if ((newEntry->key = strdup(entry->key))) {
                if (!(newEntry->value = data_dup(entry->value))) {
                    fprintf( stderr, "%s : %d : ""\"data_dup\"""\n", __FUNCTION__, 45);
                    free(newEntry->key);
                    free(newEntry);
                    newEntry = ((void *)0);
                }
            }
            else {
                fprintf( stderr, "%s : %d : ""\"strdup key\"""\n", __FUNCTION__, 52);
                free(newEntry);
                newEntry = ((void *)0);
            }
        }
        else {
            fprintf( stderr, "%s : %d : ""\"malloc newEntry\"""\n", __FUNCTION__, 58);
        }
    }
    else {
        fprintf( stderr, "%s : %d : ""\"NULL entry\"""\n", __FUNCTION__, 62);
    }
    return newEntry;
}

canonical_original_code:
struct entry_t *entry_dup(struct entry_t *entry) {
    struct entry_t *newEntry = ((void *)0);
    if (entry) {
        if ((newEntry = (struct entry_t *) malloc(sizeof (struct entry_t)))) {
            if ((newEntry->key = strdup(entry->key))) {
                if (!(newEntry->value = data_dup(entry->value))) {
                    fprintf( stderr, "%s : %d : ""\"data_dup\"""\n", __FUNCTION__, 45);
                    free(newEntry->key);
                    free(newEntry);
                    newEntry = ((void *)0);
                }
            }
            else {
                fprintf( stderr, "%s : %d : ""\"strdup key\"""\n", __FUNCTION__, 52);
                free(newEntry);
                newEntry = ((void *)0);
            }
        }
        else {
            fprintf( stderr, "%s : %d : ""\"malloc newEntry\"""\n", __FUNCTION__, 58);
        }
    }
    else {
        fprintf( stderr, "%s : %d : ""\"NULL entry\"""\n", __FUNCTION__, 62);
    }
    return newEntry;
}

variable_types: struct entry_t { char *key; struct data_t { int datasize; void *data; long timestamp; } *value; } *


decompiled_code:
void __fastcall entry_destroy(void *ptr)
{
void *v2; // rdi

if ( ptr )
{
if ( *((_QWORD *)ptr + 1) )
data_destroy();
v2 = *(void **)ptr;
if ( *(_QWORD *)ptr )
free(v2);
free(ptr);
}
}

canonical_decompiled_code:
void __fastcall func1(void *ptr)
{
void *v2; // rdi

if ( ptr )
{
if ( *((_QWORD *)ptr + 1) )
data_destroy();
v2 = *(void **)ptr;
if ( *(_QWORD *)ptr )
free(v2);
free(ptr);
}
}

original_code:
void entry_destroy(struct entry_t *entry) {
    if (entry) {
        if (entry->value) {
            data_destroy(entry->value);
        }
        if (entry->key) {
            free(entry->key);
        }
        free(entry);
    }
}


child

repo: vasi/fuse-misc

decompiled_code:
__int64 __fastcall child(__int64 a1, int a2)
{
return (a1 << 6) + a2 + 1;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, int a2)
{
return (a1 << 6) + a2 + 1;
}

original_code:
static int64_t child(int64_t dnum, int fnum) {
 return branch * dnum + 1 + fnum;
}

canonical_original_code:
static long child(long dnum, int fnum) {
 return branch * dnum + 1 + fnum;
}

variable_types: dnum long

variable_types: fnum int

return_type: long


children

decompiled_code:
__int64 __fastcall children(__int64 a1)
{
unsigned __int64 v1; // rax
unsigned int v2; // edx

v1 = child(a1, 0);
v2 = 0;
if ( v1 <= 0x4C4B3F )
{
v2 = 5000000 - v1;
if ( v1 + 64 <= 0x4C4B40 )
v2 = 64;
}
return v2;
}

original_code:
static int children(int64_t n) {
 int64_t first = child(n, 0);
 if (first >= total)
  return 0;
 if (first + branch <= total)
  return branch;
 return total - first;
}

canonical_original_code:
static int children(long n) {
 long first = child(n, 0);
 if (first >= total)
  return 0;
 if (first + branch <= total)
  return branch;
 return total - first;
}

variable_types: n long

variable_types: first long


decompiled_code:
__int64 __fastcall num_parse(char *nptr)
{
signed int v1; // eax
unsigned int v2; // edx
char *endptr; // [rsp+0h] [rbp-10h] BYREF

if ( !nptr )
return 0xFFFFFFFFLL;
if ( strlen(nptr) != 3 )
return (unsigned int)-1;
endptr = 0LL;
v1 = strtol(nptr, &endptr, 10);
v2 = v1;
if ( *endptr )
return (unsigned int)-1;
if ( (unsigned __int64)v1 >= 0x40 )
v2 = -1;
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func10(char *nptr)
{
signed int v1; // eax
unsigned int v2; // edx
char *endptr; // [rsp+0h] [rbp-10h] BYREF

if ( !nptr )
return 0xFFFFFFFFLL;
if ( strlen(nptr) != 3 )
return (unsigned int)-1;
endptr = 0LL;
v1 = strtol(nptr, &endptr, 10);
v2 = v1;
if ( *endptr )
return (unsigned int)-1;
if ( (unsigned __int64)v1 >= 0x40 )
v2 = -1;
return v2;
}

original_code:
static int num_parse(char *name) {
 if (!name)
  return -1;
 if (strlen(name) != name_size)
  return -1;
 char *end = ((void *)0);
 int ret = strtol(name, &end, 10);
 if (*end)
  return -1;
 if (ret >= branch)
  return -1;
 return ret;
}

variable_types:
name
char *

variable_types:
end
char *

variable_types: ret int


inum

decompiled_code:
__int64 __fastcall inum(char *src)
{
__int64 v1; // rax

strcpy(s_0, src);
v1 = strlen(s_0);
return inum_inner(s_0, v1);
}

canonical_decompiled_code:
__int64 __fastcall func12(char *src)
{
__int64 v1; // rax

strcpy(s_0, src);
v1 = strlen(s_0);
return func11(s_0, v1);
}

original_code:
static int64_t inum(const char *path) {
 static char s[4096];
 strcpy(s, path);
 return inum_inner(s, strlen(s));
}

canonical_original_code:
static long inum(char *path) {
 static char s[4096];
 strcpy(s, path);
 return inum_inner(s, strlen(s));
}

variable_types:
path
char *


decompiled_code:
__int64 __fastcall many_readdir(char *a1, __int64 a2, void (__fastcall *a3)(__int64, char *, _QWORD, _QWORD))
{
__int64 v4; // rax
int v5; // eax
int v6; // ebp
unsigned int v7; // ebx

v4 = inum(a1);
if ( v4 == -1 )
return 4294967294LL;
v5 = children(v4);
v6 = v5;
if ( !v5 )
return 4294967276LL;
if ( v5 <= 0 )
return 0LL;
v7 = 0;
do
{
sprintf(s_1, "%0*d", 3, v7);
a3(a2, s_1, 0LL, 0LL);
++v7;
}
while ( v6 != v7 );
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func13(char *a1, __int64 a2, void (__fastcall *a3)(__int64, char *, _QWORD, _QWORD))
{
__int64 v4; // rax
int v5; // eax
int v6; // ebp
unsigned int v7; // ebx

v4 = func12(a1);
if ( v4 == -1 )
return 4294967294LL;
v5 = func9(v4);
v6 = v5;
if ( !v5 )
return 4294967276LL;
if ( v5 <= 0 )
return 0LL;
v7 = 0;
do
{
sprintf(s_1, "%0*d", 3, v7);
a3(a2, s_1, 0LL, 0LL);
++v7;
}
while ( v6 != v7 );
return 0LL;
}

original_code:
static int many_readdir(const char *path, void *buf,
  fuse_fill_dir_t filler, off_t offset,
  struct fuse_file_info *fi) {
 int64_t n = inum(path);
 if (n == -1)
  return -2;
 int c = children(n);
 if (!c)
  return -20;
 int i;
 static char s[4096];
 for (i = 0; i < c; ++i) {
  sprintf(s, "%0*d", (int)name_size, i);
  filler(buf, s, ((void *)0), 0);
 }
 return 0;
}

canonical_original_code:
static int many_readdir(char *path, void *buf, int (*filler)(void *buf, char *name, struct stat *stbuf, long off), long offset, struct fuse_file_info *fi) {
 long n = inum(path);
 if (n == -1)
  return -2;
 int c = children(n);
 if (!c)
  return -20;
 int i;
 static char s[4096];
 for (i = 0; i < c; ++i) {
  sprintf(s, "%0*d", (int)name_size, i);
  filler(buf, s, ((void *)0), 0);
 }
 return 0;
}

variable_types:
buf
void *

variable_types: int (*)(void *buf, char *name, struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; struct timespec { long tv_sec; long tv_nsec; } st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; } *stbuf, long off)

variable_types: offset long

variable_types: struct fuse_file_info { int flags; unsigned long fh_old; int writepage; unsigned int direct_io; unsigned int keep_cache; unsigned int flush; unsigned int nonseekable; unsigned int flock_release; unsigned int padding; unsigned long fh; unsigned long lock_owner; } *

variable_types: c int

variable_types: i int

user_defined_types: struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; struct timespec st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; }


decompiled_code:
__int64 __fastcall many_open(char *a1, _DWORD *a2)
{
__int64 v2; // rax
__int64 result; // rax

v2 = inum(a1);
if ( v2 == -1 )
return 4294967294LL;
if ( (unsigned int)children(v2) )
return 4294967275LL;
result = *a2 & 3;
if ( (*a2 & 3) != 0 )
result = 4294967283LL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func14(char *a1, _DWORD *a2)
{
__int64 v2; // rax
__int64 result; // rax

v2 = func12(a1);
if ( v2 == -1 )
return 4294967294LL;
if ( (unsigned int)func9(v2) )
return 4294967275LL;
result = *a2 & 3;
if ( (*a2 & 3) != 0 )
result = 4294967283LL;
return result;
}

original_code:
static int many_open(const char *path, struct fuse_file_info *fi) {
 int64_t n = inum(path);
 if (n == -1)
  return -2;
 if (children(n))
  return -21;
 if ((fi->flags & 0003) != 00)
  return -13;
 return 0;
}

canonical_original_code:
static int many_open(char *path, struct fuse_file_info *fi) {
 long n = inum(path);
 if (n == -1)
  return -2;
 if (children(n))
  return -21;
 if ((fi->flags & 0003) != 00)
  return -13;
 return 0;
}

user_defined_types: struct fuse_file_info { int flags; unsigned long fh_old; int writepage; unsigned int direct_io; unsigned int keep_cache; unsigned int flush; unsigned int nonseekable; unsigned int flock_release; unsigned int padding; unsigned long fh; unsigned long lock_owner; }


decompiled_code:
__int64 __fastcall many_getattr(char *a1, __int64 a2)
{
__int64 v2; // rax
__int64 result; // rax

v2 = inum(a1);
if ( v2 == -1 )
return 4294967294LL;
result = children(v2);
if ( (_DWORD)result )
{
*(_DWORD *)(a2 + 24) = 16749;
result = 0LL;
}
else
{
*(_DWORD *)(a2 + 24) = 33060;
*(_QWORD *)(a2 + 48) = 13LL;
}
return result;
}

original_code:
static int many_getattr(const char *path, struct stat *stbuf) {
 int64_t n = inum(path);
 if (n == -1)
  return -2;
 if (children(n)) {
  stbuf->st_mode = 0040000 | 0555;
 } else {
  stbuf->st_mode = 0100000 | 0444;
  stbuf->st_size = file_size;
 }
 return 0;
}

canonical_original_code:
static int many_getattr(char *path, struct stat *stbuf) {
 long n = inum(path);
 if (n == -1)
  return -2;
 if (children(n)) {
  stbuf->st_mode = 0040000 | 0555;
 } else {
  stbuf->st_mode = 0100000 | 0444;
  stbuf->st_size = file_size;
 }
 return 0;
}

variable_types: struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; struct timespec { long tv_sec; long tv_nsec; } st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; } *


decompiled_code:
__int64 __fastcall many_read(__int64 a1, void *a2, size_t a3, unsigned __int64 a4)
{
__int64 result; // rax
size_t v5; // rbx

result = 0LL;
if ( a4 <= 0xC )
{
v5 = a3;
if ( a4 + a3 > 0xD )
v5 = 13 - a4;
memcpy(a2, &file_content[a4], v5);
result = (unsigned int)v5;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func16(__int64 a1, void *a2, size_t a3, unsigned __int64 a4)
{
__int64 result; // rax
size_t v5; // rbx

result = 0LL;
if ( a4 <= 0xC )
{
v5 = a3;
if ( a4 + a3 > 0xD )
v5 = 13 - a4;
memcpy(a2, &file_content[a4], v5);
result = (unsigned int)v5;
}
return result;
}

original_code:
static int many_read(const char *path, char *buf, size_t size,
  off_t offset, struct fuse_file_info *fi) {
 if (offset >= file_size)
  return 0;
 if (offset + size > file_size)
  size = file_size - offset;
 memcpy(buf, file_content + offset, size);
 return size;
}

canonical_original_code:
static int many_read(char *path, char *buf, unsigned long size, long offset, struct fuse_file_info *fi) {
 if (offset >= file_size)
  return 0;
 if (offset + size > file_size)
  size = file_size - offset;
 memcpy(buf, file_content + offset, size);
 return size;
}

variable_types:
buf
char *

variable_types:
size
unsigned long


main

canonical_name: main

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

original_code:
int main(int argc, char **argv) {
 return fuse_main_real(argc, argv, &many_fsops, sizeof(*(&many_fsops)), ((void *)0));
}

variable_types: argc int

variable_types:
argv
char **


decompiled_code:
__int64 __fastcall hello_readdir(const char *a1, __int64 a2, void (__fastcall *a3)(__int64, void *, _QWORD, _QWORD))
{
bool v3; // zf
unsigned int v4; // ebx

v3 = strcmp(a1, "/") == 0;
v4 = !v3;
if ( !v3 )
return (unsigned int)-2;
a3(a2, &unk_402007, 0LL, 0LL);
a3(a2, &unk_402006, 0LL, 0LL);
a3(a2, "hello.txt", 0LL, 0LL);
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func7(const char *a1, __int64 a2, void (__fastcall *a3)(__int64, void *, _QWORD, _QWORD))
{
bool v3; // zf
unsigned int v4; // ebx

v3 = strcmp(a1, "/") == 0;
v4 = !v3;
if ( !v3 )
return (unsigned int)-2;
a3(a2, &unk_402007, 0LL, 0LL);
a3(a2, &unk_402006, 0LL, 0LL);
a3(a2, "hello.txt", 0LL, 0LL);
return v4;
}

original_code:
static int
hello_readdir(const char *path, void *buf, fuse_fill_dir_t filler,
              off_t offset, struct fuse_file_info *fi)
{
    if (strcmp(path, "/") != 0)
        return -2;
    filler(buf, ".", ((void *)0), 0);
    filler(buf, "..", ((void *)0), 0);
    filler(buf, file_path + 1, ((void *)0), 0);
    return 0;
}

canonical_original_code:
static int hello_readdir(char *path, void *buf, int (*filler)(void *buf, char *name, struct stat *stbuf, long off), long offset, struct fuse_file_info *fi)
{
    if (strcmp(path, "/") != 0)
        return -2;
    filler(buf, ".", ((void *)0), 0);
    filler(buf, "..", ((void *)0), 0);
    filler(buf, file_path + 1, ((void *)0), 0);
    return 0;
}

user_defined_types: struct timespec { long tv_sec; long tv_nsec; }


decompiled_code:
__int64 __fastcall hello_open(const char *a1, _DWORD *a2)
{
__int64 result; // rax

if ( strcmp(a1, "/hello.txt") )
return 4294967294LL;
result = *a2 & 3;
if ( (*a2 & 3) != 0 )
result = 4294967283LL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(const char *a1, _DWORD *a2)
{
__int64 result; // rax

if ( strcmp(a1, "/hello.txt") )
return 4294967294LL;
result = *a2 & 3;
if ( (*a2 & 3) != 0 )
result = 4294967283LL;
return result;
}

original_code:
static int
hello_open(const char *path, struct fuse_file_info *fi)
{
    if (strcmp(path, file_path) != 0)
        return -2;
    if ((fi->flags & 0003) != 00)
        return -13;
    return 0;
}

canonical_original_code:
static int hello_open(char *path, struct fuse_file_info *fi)
{
    if (strcmp(path, file_path) != 0)
        return -2;
    if ((fi->flags & 0003) != 00)
        return -13;
    return 0;
}


decompiled_code:
__int64 __fastcall hello_read(const char *a1, void *a2, size_t a3, unsigned __int64 a4)
{
size_t v4; // rbx
bool v5; // zf
__int64 result; // rax

v4 = a3;
v5 = strcmp(a1, "/hello.txt") == 0;
result = !v5;
if ( !v5 )
return 4294967294LL;
if ( a4 <= 0xC )
{
if ( a4 + a3 > 0xD )
v4 = 13 - a4;
memcpy(a2, &file_content[a4], v4);
result = (unsigned int)v4;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(const char *a1, void *a2, size_t a3, unsigned __int64 a4)
{
size_t v4; // rbx
bool v5; // zf
__int64 result; // rax

v4 = a3;
v5 = strcmp(a1, "/hello.txt") == 0;
result = !v5;
if ( !v5 )
return 4294967294LL;
if ( a4 <= 0xC )
{
if ( a4 + a3 > 0xD )
v4 = 13 - a4;
memcpy(a2, &file_content[a4], v4);
result = (unsigned int)v4;
}
return result;
}

original_code:
static int
hello_read(const char *path, char *buf, size_t size, off_t offset,
           struct fuse_file_info *fi)
{
    if (strcmp(path, file_path) != 0)
        return -2;
    if (offset >= file_size)
        return 0;
    if (offset + size > file_size)
        size = file_size - offset;
    memcpy(buf, file_content + offset, size);
    return size;
}

canonical_original_code:
static int hello_read(char *path, char *buf, unsigned long size, long offset, struct fuse_file_info *fi)
{
    if (strcmp(path, file_path) != 0)
        return -2;
    if (offset >= file_size)
        return 0;
    if (offset + size > file_size)
        size = file_size - offset;
    memcpy(buf, file_content + offset, size);
    return size;
}


original_code:
static int
hello_getattr(const char *path, struct stat *stbuf)
{
    memset(stbuf, 0, sizeof(struct stat));
    if (strcmp(path, "/") == 0) {
        stbuf->st_mode = 0040000 | 0755;
        stbuf->st_nlink = 3;
    } else if (strcmp(path, file_path) == 0) {
        stbuf->st_mode = 0100000 | 0444;
        stbuf->st_nlink = 1;
        stbuf->st_size = file_size;
    } else
        return -2;
    return 0;
}

canonical_original_code:
static int hello_getattr(char *path, struct stat *stbuf)
{
    memset(stbuf, 0, sizeof(struct stat));
    if (strcmp(path, "/") == 0) {
        stbuf->st_mode = 0040000 | 0755;
        stbuf->st_nlink = 3;
    } else if (strcmp(path, file_path) == 0) {
        stbuf->st_mode = 0100000 | 0444;
        stbuf->st_nlink = 1;
        stbuf->st_size = file_size;
    } else
        return -2;
    return 0;
}


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

original_code:
int
main(int argc, char **argv)
{
    return fuse_main_real(argc, argv, &hello_filesystem_operations, sizeof(*(&hello_filesystem_operations)), ((void *)0));
}


repo: vasi/fuse-uzip

decompiled_code:
__int64 __fastcall uzip_opt_proc(char **a1, const char *a2, int a3)
{
__int64 result; // rax

result = 1LL;
if ( a3 == -2 && !*a1 )
{
*a1 = strdup(a2);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(char **a1, const char *a2, int a3)
{
__int64 result; // rax

result = 1LL;
if ( a3 == -2 && !*a1 )
{
*a1 = strdup(a2);
result = 0LL;
}
return result;
}

original_code:
static int uzip_opt_proc(void *data, const char *arg, int key,
  struct fuse_args *outargs) {
 char **file = (char**)data;
 if (key == -2) {
  if (*file)
   return 1;
  *file = strdup(arg);
  return 0;
 }
 return 1;
}

canonical_original_code:
static int uzip_opt_proc(void *data, char *arg, int key, struct fuse_args *outargs) {
 char **file = (char**)data;
 if (key == -2) {
  if (*file)
   return 1;
  *file = strdup(arg);
  return 0;
 }
 return 1;
}

variable_types:
data
void *

variable_types:
arg
char *

variable_types: key int

variable_types: struct fuse_args { int argc; char **argv; int allocated; } *

variable_types:
file
char **


decompiled_code:
void __fastcall uzip_destroy(__int64 a1)
{
close(*(_DWORD *)a1);
free(*(void **)(a1 + 8));
free(*(void **)(a1 + 24));
}

canonical_decompiled_code:
void __fastcall func8(__int64 a1)
{
close(*(_DWORD *)a1);
free(*(void **)(a1 + 8));
free(*(void **)(a1 + 24));
}

original_code:
static void uzip_destroy(void *data) {
 uzip *u = data;
 close(u->fd);
 free(u->name);
 free(u->offsets);
}

canonical_original_code:
static void uzip_destroy(void *data) {
 struct uzip *u = data;
 close(u->fd);
 free(u->name);
 free(u->offsets);
}

variable_types: struct uzip { int fd; char *name; struct uzip_header { unsigned int blocksize; unsigned int blocks; } header; unsigned long *offsets; int (*decomp)(char *in, int ilen, char *out, int olen); } *

user_defined_types: struct uzip { int fd; char *name; struct uzip_header header; unsigned long *offsets; int (*decomp)(char *in, int ilen, char *out, int olen); }


decompiled_code:
__int64 uzip_init()
{
return *(_QWORD *)(fuse_get_context() + 24);
}

canonical_decompiled_code:
__int64 func9()
{
return *(_QWORD *)(fuse_get_context() + 24);
}

original_code:
static void *uzip_init(struct fuse_conn_info *conn) {
 return fuse_get_context()->private_data;
}

variable_types: struct fuse_conn_info { unsigned int proto_major; unsigned int proto_minor; unsigned int async_read; unsigned int max_write; unsigned int max_readahead; unsigned int capable; unsigned int want; unsigned int max_background; unsigned int congestion_threshold; unsigned int reserved[23]; } *

return_type: void *


decompiled_code:
__int64 __fastcall uzip_readdir(const char *a1, __int64 a2, void (__fastcall *a3)(__int64, void *, _QWORD, _QWORD))
{
bool v3; // zf
unsigned int v4; // ebx
__int64 v6; // r13

v3 = strcmp(a1, "/") == 0;
v4 = !v3;
if ( !v3 )
return (unsigned int)-2;
v6 = *(_QWORD *)(fuse_get_context() + 24);
a3(a2, &unk_402007, 0LL, 0LL);
a3(a2, &unk_402006, 0LL, 0LL);
a3(a2, *(void **)(v6 + 8), 0LL, 0LL);
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func10(const char *a1, __int64 a2, void (__fastcall *a3)(__int64, void *, _QWORD, _QWORD))
{
bool v3; // zf
unsigned int v4; // ebx
__int64 v6; // r13

v3 = strcmp(a1, "/") == 0;
v4 = !v3;
if ( !v3 )
return (unsigned int)-2;
v6 = *(_QWORD *)(fuse_get_context() + 24);
a3(a2, &unk_402007, 0LL, 0LL);
a3(a2, &unk_402006, 0LL, 0LL);
a3(a2, *(void **)(v6 + 8), 0LL, 0LL);
return v4;
}

original_code:
static int uzip_readdir(const char *path, void *buf, fuse_fill_dir_t filler,
  off_t offset, struct fuse_file_info *fi) {
 if (strcmp(path, "/") != 0)
  return -2;
 uzip *u = fuse_get_context()->private_data;
 filler(buf, ".", ((void *)0), 0);
 filler(buf, "..", ((void *)0), 0);
 filler(buf, u->name, ((void *)0), 0);
 return 0;
}

canonical_original_code:
static int uzip_readdir(char *path, void *buf, int (*filler)(void *buf, char *name, struct stat *stbuf, long off), long offset, struct fuse_file_info *fi) {
 if (strcmp(path, "/") != 0)
  return -2;
 struct uzip *u = fuse_get_context()->private_data;
 filler(buf, ".", ((void *)0), 0);
 filler(buf, "..", ((void *)0), 0);
 filler(buf, u->name, ((void *)0), 0);
 return 0;
}

variable_types:
path
char *

variable_types:
buf
void *

variable_types: int (*)(void *buf, char *name, struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; struct timespec { long tv_sec; long tv_nsec; } st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; } *stbuf, long off)

user_defined_types: struct uzip_header { unsigned int blocksize; unsigned int blocks; }


decompiled_code:
int __fastcall uzip_open(__int64 a1, _BYTE *a2)
{
__int64 v2; // rax
int result; // eax

v2 = *(_QWORD *)(fuse_get_context() + 24);
if ( *(_BYTE *)a1 != 47 )
return -2;
result = strcmp((const char *)(a1 + 1), *(const char **)(v2 + 8));
if ( result )
return -2;
if ( (*a2 & 3) != 0 )
result = -13;
return result;
}

canonical_decompiled_code:
int __fastcall func11(__int64 a1, _BYTE *a2)
{
__int64 v2; // rax
int result; // eax

v2 = *(_QWORD *)(fuse_get_context() + 24);
if ( *(_BYTE *)a1 != 47 )
return -2;
result = strcmp((const char *)(a1 + 1), *(const char **)(v2 + 8));
if ( result )
return -2;
if ( (*a2 & 3) != 0 )
result = -13;
return result;
}

original_code:
static int uzip_open(const char *path, struct fuse_file_info *fi) {
 uzip *u = fuse_get_context()->private_data;
 if (path[0] != '/' || strcmp(path + 1, u->name) != 0)
  return -2;
 if ((fi->flags & 02) || (fi->flags & 01))
  return -13;
 return 0;
}

canonical_original_code:
static int uzip_open(char *path, struct fuse_file_info *fi) {
 struct uzip *u = fuse_get_context()->private_data;
 if (path[0] != '/' || strcmp(path + 1, u->name) != 0)
  return -2;
 if ((fi->flags & 02) || (fi->flags & 01))
  return -13;
 return 0;
}

variable_types: struct fuse_file_info { int flags; unsigned long fh_old; int writepage; unsigned int direct_io; unsigned int keep_cache; unsigned int flush; unsigned int nonseekable; unsigned int flock_release; unsigned int padding; unsigned long fh; unsigned long lock_owner; } *


decompiled_code:
void *__fastcall uzip_block(__int64 a1, unsigned __int64 a2)
{
__int64 v2; // rax
unsigned __int64 v3; // rsi
__off64_t v4; // r14
size_t v5; // r12
void *v6; // rbp
void *v8; // r13
void *v9; // rax
unsigned int v10; // [rsp+Ch] [rbp-3Ch]

if ( *(unsigned int *)(a1 + 20) < a2 )
{
fwrite("Invalid block\n", 1uLL, 0xEuLL, stderr);
return 0LL;
}
v2 = *(_QWORD *)(a1 + 24);
v3 = a2 + 1;
v4 = *(_QWORD *)(v2 + 8 * v3 - 8);
v5 = *(_QWORD *)(v2 + 8 * v3) - v4;
v10 = *(_DWORD *)(a1 + 16);
v6 = calloc(1uLL, v10);
if ( !v6 )
{
fwrite("Can't allocate block memory\n", 1uLL, 0x1CuLL, stderr);
v8 = 0LL;
goto LABEL_14;
}
if ( v5 )
{
v9 = malloc(v5);
v8 = v9;
if ( v9 )
{
if ( pread64(*(_DWORD *)a1, v9, v5, v4) == v5 )
{
if ( (*(int (__fastcall **)(void *, _QWORD, void *, _QWORD))(a1 + 32))(v8, (unsigned int)v5, v6, v10) == (unsigned __int64)v10 )
{
free(v8);
return v6;
}
fwrite("Decompression error\n", 1uLL, 0x14uLL, stderr);
}
else
{
perror("Reading block");
}
}
else
{
fwrite("Can't allocate block data\n", 1uLL, 0x1AuLL, stderr);
}
LABEL_14:
free(v8);
free(v6);
v6 = 0LL;
}
return v6;
}

canonical_decompiled_code:
void *__fastcall func12(__int64 a1, unsigned __int64 a2)
{
__int64 v2; // rax
unsigned __int64 v3; // rsi
__off64_t v4; // r14
size_t v5; // r12
void *v6; // rbp
void *v8; // r13
void *v9; // rax
unsigned int v10; // [rsp+Ch] [rbp-3Ch]

if ( *(unsigned int *)(a1 + 20) < a2 )
{
fwrite("Invalid block\n", 1uLL, 0xEuLL, stderr);
return 0LL;
}
v2 = *(_QWORD *)(a1 + 24);
v3 = a2 + 1;
v4 = *(_QWORD *)(v2 + 8 * v3 - 8);
v5 = *(_QWORD *)(v2 + 8 * v3) - v4;
v10 = *(_DWORD *)(a1 + 16);
v6 = calloc(1uLL, v10);
if ( !v6 )
{
fwrite("Can't allocate block memory\n", 1uLL, 0x1CuLL, stderr);
v8 = 0LL;
goto LABEL_14;
}
if ( v5 )
{
v9 = malloc(v5);
v8 = v9;
if ( v9 )
{
if ( pread64(*(_DWORD *)a1, v9, v5, v4) == v5 )
{
if ( (*(int (__fastcall **)(void *, _QWORD, void *, _QWORD))(a1 + 32))(v8, (unsigned int)v5, v6, v10) == (unsigned __int64)v10 )
{
free(v8);
return v6;
}
fwrite("Decompression error\n", 1uLL, 0x14uLL, stderr);
}
else
{
perror("Reading block");
}
}
else
{
fwrite("Can't allocate block data\n", 1uLL, 0x1AuLL, stderr);
}
LABEL_14:
free(v8);
free(v6);
v6 = 0LL;
}
return v6;
}

original_code:
static char *uzip_block(uzip *u, size_t n) {
 if (n > u->header.blocks) {
  fprintf(stderr, "Invalid block\n");
  return ((void *)0);
 }
 size_t size = u->offsets[n+1] - u->offsets[n];
 size_t osize = u->header.blocksize;
 char *comp = ((void *)0), *ucomp = ((void *)0);
 if (!(ucomp = calloc(1, osize))) {
  fprintf(stderr, "Can't allocate block memory\n");
  goto error;
 }
 if (size == 0)
  return ucomp;
 if (!(comp = malloc(size))) {
  fprintf(stderr, "Can't allocate block data\n");
  goto error;
 }
 if (pread(u->fd, comp, size, u->offsets[n]) != size) {
  perror("Reading block");
  goto error;
 }
 if (u->decomp(comp, size, ucomp, osize) != osize) {
  fprintf(stderr, "Decompression error\n");
  goto error;
 }
 free(comp);
 return ucomp;
error:
 free(comp);
 free(ucomp);
 return ((void *)0);
}

canonical_original_code:
static char *uzip_block(struct uzip *u, unsigned long n) {
 if (n > u->header.blocks) {
  fprintf(stderr, "Invalid block\n");
  return ((void *)0);
 }
 unsigned long size = u->offsets[n+1] - u->offsets[n];
 unsigned long osize = u->header.blocksize;
 char *comp = ((void *)0); char *ucomp = ((void *)0);
 if (!(ucomp = calloc(1, osize))) {
  fprintf(stderr, "Can't allocate block memory\n");
  goto error;
 }
 if (size == 0)
  return ucomp;
 if (!(comp = malloc(size))) {
  fprintf(stderr, "Can't allocate block data\n");
  goto error;
 }
 if (pread(u->fd, comp, size, u->offsets[n]) != size) {
  perror("Reading block");
  goto error;
 }
 if (u->decomp(comp, size, ucomp, osize) != osize) {
  fprintf(stderr, "Decompression error\n");
  goto error;
 }
 free(comp);
 return ucomp;
error:
 free(comp);
 free(ucomp);
 return ((void *)0);
}

variable_types:
n
unsigned long

variable_types:
osize
unsigned long

variable_types:
comp
char *

variable_types:
ucomp
char *

return_type: char *


original_code:
static int uzip_read(const char *path, char *buf, size_t size, off_t offset,
  struct fuse_file_info *fi) {
 uzip *u = fuse_get_context()->private_data;
 if (path[0] != '/' || strcmp(path + 1, u->name) != 0)
  return -2;
 size_t read = 0;
 while (size > 0) {
  size_t block = offset / u->header.blocksize;
  if (block >= u->header.blocks)
   break;
  size_t off = offset % u->header.blocksize;
  size_t to_read = u->header.blocksize - off;
  if (size < to_read)
   to_read = size;
  size_t csize = u->offsets[block+1] - u->offsets[block];
  if (csize > 0) {
   char *data = uzip_block(u, block);
   if (!data)
    return -5;
   memcpy(buf + read, data + off, to_read);
  }
  read += to_read;
  offset += to_read;
  size -= to_read;
 }
 return read;
}

canonical_original_code:
static int uzip_read(char *path, char *buf, unsigned long size, long offset, struct fuse_file_info *fi) {
 struct uzip *u = fuse_get_context()->private_data;
 if (path[0] != '/' || strcmp(path + 1, u->name) != 0)
  return -2;
 unsigned long read = 0;
 while (size > 0) {
  unsigned long block = offset / u->header.blocksize;
  if (block >= u->header.blocks)
   break;
  unsigned long off = offset % u->header.blocksize;
  unsigned long to_read = u->header.blocksize - off;
  if (size < to_read)
   to_read = size;
  unsigned long csize = u->offsets[block+1] - u->offsets[block];
  if (csize > 0) {
   char *data = uzip_block(u, block);
   if (!data)
    return -5;
   memcpy(buf + read, data + off, to_read);
  }
  read += to_read;
  offset += to_read;
  size -= to_read;
 }
 return read;
}

variable_types:
buf
char *

variable_types:
size
unsigned long

variable_types: offset long

variable_types:
read
unsigned long

variable_types:
block
unsigned long

variable_types:
off
unsigned long

variable_types:
csize
unsigned long

variable_types:
data
char *


decompiled_code:
__int64 __fastcall uzip_getattr(const char *a1, struct stat64 *a2)
{
__int64 v2; // r12
bool v3; // zf
__int64 result; // rax

v2 = *(_QWORD *)(fuse_get_context() + 24);
a2->st_dev = 0LL;
a2->__unused[2] = 0LL;
memset(
(void *)((unsigned __int64)&a2->st_ino & 0xFFFFFFFFFFFFFFF8LL),
0,
8LL * (((unsigned int)a2 - (((_DWORD)a2 + 8) & 0xFFFFFFF8) + 144) >> 3));
v3 = strcmp(a1, "/") == 0;
result = !v3;
if ( v3 )
{
a2->st_mode = 16877;
a2->st_nlink = 2LL;
}
else if ( *a1 == 47 )
{
if ( !strcmp(a1 + 1, *(const char **)(v2 + 8)) )
{
result = fstat64(*(_DWORD *)v2, a2);
a2->st_size = (unsigned int)(*(_DWORD *)(v2 + 16) * *(_DWORD *)(v2 + 20));
a2->st_blksize = *(unsigned int *)(v2 + 16);
}
else
{
result = 4294967294LL;
}
}
else
{
result = 4294967294LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func14(const char *a1, struct stat64 *a2)
{
__int64 v2; // r12
bool v3; // zf
__int64 result; // rax

v2 = *(_QWORD *)(fuse_get_context() + 24);
a2->st_dev = 0LL;
a2->__unused[2] = 0LL;
memset(
(void *)((unsigned __int64)&a2->st_ino & 0xFFFFFFFFFFFFFFF8LL),
0,
8LL * (((unsigned int)a2 - (((_DWORD)a2 + 8) & 0xFFFFFFF8) + 144) >> 3));
v3 = strcmp(a1, "/") == 0;
result = !v3;
if ( v3 )
{
a2->st_mode = 16877;
a2->st_nlink = 2LL;
}
else if ( *a1 == 47 )
{
if ( !strcmp(a1 + 1, *(const char **)(v2 + 8)) )
{
result = func21(*(_DWORD *)v2, a2);
a2->st_size = (unsigned int)(*(_DWORD *)(v2 + 16) * *(_DWORD *)(v2 + 20));
a2->st_blksize = *(unsigned int *)(v2 + 16);
}
else
{
result = 4294967294LL;
}
}
else
{
result = 4294967294LL;
}
return result;
}

original_code:
static int uzip_getattr(const char *path, struct stat *st) {
 uzip *u = fuse_get_context()->private_data;
 memset(st, 0, sizeof(*st));
 if (strcmp(path, "/") == 0) {
  st->st_mode = 0040000 | 0755;
  st->st_nlink = 2;
 } else if (path[0] == '/' && strcmp(path + 1, u->name) == 0) {
  int err = fstat(u->fd, st);
  st->st_size = u->header.blocks * u->header.blocksize;
  st->st_blksize = u->header.blocksize;
  return err;
 } else {
  return -2;
 }
 return 0;
}

canonical_original_code:
static int uzip_getattr(char *path, struct stat *st) {
 struct uzip *u = fuse_get_context()->private_data;
 memset(st, 0, sizeof(*st));
 if (strcmp(path, "/") == 0) {
  st->st_mode = 0040000 | 0755;
  st->st_nlink = 2;
 } else if (path[0] == '/' && strcmp(path + 1, u->name) == 0) {
  int err = fstat(u->fd, st);
  st->st_size = u->header.blocks * u->header.blocksize;
  st->st_blksize = u->header.blocksize;
  return err;
 } else {
  return -2;
 }
 return 0;
}

variable_types: struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; struct timespec { long tv_sec; long tv_nsec; } st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; } *

variable_types: struct uzip { int fd; char *name; struct uzip_header { unsigned int blocksize; unsigned int blocks; } header; unsigned long *offsets; int (*decomp)(char *in, int ilen, char *out, int olen); } *

variable_types: err int


decompiled_code:
__int64 __fastcall lzma_decomp(__int64 a1, int a2)
{
int v2; // edx
__int64 result; // rax

v2 = lzma_stream_buffer_decode();
result = 0LL;
if ( !v2 && !a2 )
result = 0LL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func15(__int64 a1, int a2)
{
int v2; // edx
__int64 result; // rax

v2 = lzma_stream_buffer_decode();
result = 0LL;
if ( !v2 && !a2 )
result = 0LL;
return result;
}

original_code:
static int lzma_decomp(char *in, int ilen, char *out, int olen) {
 uint64_t memlimit = (18446744073709551615UL);
 size_t ipos = 0, opos = 0;
 lzma_ret err = lzma_stream_buffer_decode(&memlimit, 0, ((void *)0),
  (uint8_t*)in, &ipos, ilen, (uint8_t*)out, &opos, olen);
 if (err != LZMA_OK || ipos != ilen)
  return 0;
 return opos;
}

canonical_original_code:
static int lzma_decomp(char *in, int ilen, char *out, int olen) {
 unsigned long memlimit = (18446744073709551615UL);
 unsigned long ipos = 0; unsigned long opos = 0;
 enum lzma_ret err = lzma_stream_buffer_decode(&memlimit, 0, ((void *)0),
  (uint8_t*)in, &ipos, ilen, (uint8_t*)out, &opos, olen);
 if (err != LZMA_OK || ipos != ilen)
  return 0;
 return opos;
}

variable_types:
in
char *

variable_types: ilen int

variable_types:
out
char *

variable_types: olen int

variable_types:
memlimit
unsigned long

variable_types:
ipos
unsigned long

variable_types:
opos
unsigned long

variable_types: enum lzma_ret { LZMA_OK=0, LZMA_STREAM_END=1, LZMA_NO_CHECK=2, LZMA_UNSUPPORTED_CHECK=3, LZMA_GET_CHECK=4, LZMA_MEM_ERROR=5, LZMA_MEMLIMIT_ERROR=6, LZMA_FORMAT_ERROR=7, LZMA_OPTIONS_ERROR=8, LZMA_DATA_ERROR=9, LZMA_BUF_ERROR=10, LZMA_PROG_ERROR=11 }


decompiled_code:
__int64 __fastcall zlib_decomp(__int64 a1, __int64 a2, __int64 a3, unsigned int a4)
{
bool v4; // zf
__int64 result; // rax

v4 = (unsigned int)uncompress() == 0;
result = 0LL;
if ( v4 )
result = a4;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func16(__int64 a1, __int64 a2, __int64 a3, unsigned int a4)
{
bool v4; // zf
__int64 result; // rax

v4 = (unsigned int)uncompress() == 0;
result = 0LL;
if ( v4 )
result = a4;
return result;
}

original_code:
static int zlib_decomp(char *in, int ilen, char *out, int olen) {
 uLongf dlen = olen;
 int err = uncompress((Bytef*)out, &dlen, (Bytef*)in, ilen);
 if (err != 0)
  return 0;
 return (int)dlen;
}

canonical_original_code:
static int zlib_decomp(char *in, int ilen, char *out, int olen) {
 unsigned long dlen = olen;
 int err = uncompress((Bytef*)out, &dlen, (Bytef*)in, ilen);
 if (err != 0)
  return 0;
 return (int)dlen;
}

variable_types:
dlen
unsigned long


decompiled_code:
__int64 __fastcall uzip_ntohll(__int64 a1)
{
__int64 v1; // rbx

v1 = (unsigned int)_bswap_32(a1);
return (v1 << 32) | (unsigned int)_bswap_32(HIDWORD(a1));
}

canonical_decompiled_code:
__int64 __fastcall func18(__int64 a1)
{
__int64 v1; // rbx

v1 = (unsigned int)func17(a1);
return (v1 << 32) | (unsigned int)func17(HIDWORD(a1));
}

original_code:
static uint64_t uzip_ntohll(uint64_t n) {
 return ((uint64_t)ntohl(n) << 32) | (uint32_t)ntohl(n >> 32);
}

canonical_original_code:
static unsigned long uzip_ntohll(unsigned long n) {
 return ((unsigned long)ntohl(n) << 32) | (unsigned int)ntohl(n >> 32);
}

variable_types:
n
unsigned long


getUserPath

repo: vatriani/weather-cli

decompiled_code:
void *__fastcall getUserPath(_QWORD *a1)
{
__uid_t v1; // eax
struct passwd *v2; // rbp
int v3; // ebx
void *v4; // rax

v1 = getuid();
v2 = getpwuid(v1);
v3 = strmlen(v2->pw_dir);
v4 = malloc(v3 + 1);
*a1 = v4;
return memcpy(v4, v2->pw_dir, v3 + 2);
}

canonical_decompiled_code:
void *__fastcall func0(_QWORD *a1)
{
__uid_t v1; // eax
struct passwd *v2; // rbp
int v3; // ebx
void *v4; // rax

v1 = getuid();
v2 = getpwuid(v1);
v3 = strmlen(v2->pw_dir);
v4 = malloc(v3 + 1);
*a1 = v4;
return memcpy(v4, v2->pw_dir, v3 + 2);
}

original_code:
void getUserPath(char **path) {
 struct passwd *userInformations;
 int len;
 userInformations = getpwuid(getuid());
 len = strmlen(userInformations->pw_dir);
 *path = malloc(++len);
 memcpy(*path, userInformations->pw_dir, len+1);
}

variable_types:
path
char **

variable_types: struct passwd { char *pw_name; char *pw_passwd; unsigned int pw_uid; unsigned int pw_gid; char *pw_gecos; char *pw_dir; char *pw_shell; } *

variable_types: len int


getConfigHome

decompiled_code:
__int64 __fastcall getConfigHome(_QWORD *a1)
{
char *v1; // rax

v1 = getenv("XDG_CONFIG_HOME");
if ( v1 )
return strmcat(a1, v1);
getUserPath(a1);
return strmcat(a1, "/.config");
}

canonical_decompiled_code:
__int64 __fastcall func2(_QWORD *a1)
{
char *v1; // rax

v1 = getenv("XDG_CONFIG_HOME");
if ( v1 )
return strmcat(a1, v1);
func0(a1);
return strmcat(a1, "/.config");
}

original_code:
void getConfigHome(char **path) {
 char *configHome = getenv("XDG_CONFIG_HOME");
 if(configHome)
  strmcat(path,configHome);
 else {
  getUserPath(path);
  strmcat(path,"/.config");
 }
}

variable_types:
configHome
char *


getConfigApp

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

result = getConfigHome(a1);
if ( *a1 )
{
strmcat(a1, "/");
result = strmcat(a1, a2);
}
return result;
}

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

result = func2(a1);
if ( *a1 )
{
strmcat(a1, "/");
result = strmcat(a1, a2);
}
return result;
}

original_code:
void getConfigApp(char **path, char *app_name) {
 getConfigHome(path);
 if(*path) {
  strmcat(path, "/");
  strmcat(path, app_name);
 }
}


getCacheHome

decompiled_code:
__int64 __fastcall getCacheHome(_QWORD *a1)
{
char *v1; // rax

v1 = getenv("XDG_CACHE_HOME");
if ( v1 )
return strmcat(a1, v1);
getUserPath(a1);
return strmcat(a1, "/.cache");
}

canonical_decompiled_code:
__int64 __fastcall func4(_QWORD *a1)
{
char *v1; // rax

v1 = getenv("XDG_CACHE_HOME");
if ( v1 )
return strmcat(a1, v1);
func0(a1);
return strmcat(a1, "/.cache");
}

original_code:
void getCacheHome(char **path) {
 char *cacheHome = getenv("XDG_CACHE_HOME");
 if(cacheHome)
  strmcat(path,cacheHome);
 else {
  getUserPath(path);
  strmcat(path,"/.cache");
 }
}

variable_types:
cacheHome
char *


getCacheApp

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

result = getCacheHome(a1);
if ( *a1 )
{
strmcat(a1, "/");
result = strmcat(a1, a2);
}
return result;
}

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

result = func4(a1);
if ( *a1 )
{
strmcat(a1, "/");
result = strmcat(a1, a2);
}
return result;
}

original_code:
void getCacheApp(char **path, char *app_name) {
 getCacheHome(path);
 if(*path) {
  strmcat(path,"/");
  strmcat(path,app_name);
 }
}


getCachePath

decompiled_code:
int __fastcall getCachePath(const char **a1, __int64 a2)
{
int result; // eax

result = getCacheApp(a1, a2);
if ( *a1 )
result = createPathIfNotExists(a1);
return result;
}

canonical_decompiled_code:
int __fastcall func6(const char **a1, __int64 a2)
{
int result; // eax

result = func5(a1, a2);
if ( *a1 )
result = func1(a1);
return result;
}

original_code:
void getCachePath(char **path, char *app_name) {
 getCacheApp(path,app_name);
 if(*path) {
  createPathIfNotExists(path);
 }
}


openFileForWrite

decompiled_code:
int __fastcall openFileForWrite(int *a1, const char *a2)
{
int result; // eax

result = open(a2, 577, 384LL);
*a1 = result;
if ( !result )
result = outerr("error by opening file");
return result;
}

canonical_decompiled_code:
int __fastcall func7(int *a1, const char *a2)
{
int result; // eax

result = open(a2, 577, 384LL);
*a1 = result;
if ( !result )
result = outerr("error by opening file");
return result;
}

original_code:
void openFileForWrite(FILEHANDLER *file, char* name) {
 *file = open(name,0100|01|01000,0400|0200);
 if(*file == 0)
  outerr("error by opening file");
}

canonical_original_code:
void openFileForWrite(int *file, char *name) {
 *file = open(name,0100|01|01000,0400|0200);
 if(*file == 0)
  outerr("error by opening file");
}

variable_types:
file
int *

variable_types:
name
char *


openFileForRead

decompiled_code:
__int64 __fastcall openFileForRead(int *a1, const char *a2)
{
int v2; // eax
unsigned int v3; // ebx

v2 = open(a2, 0);
*a1 = v2;
v3 = 1;
if ( !v2 )
{
v3 = 0;
outerr("error by opening file");
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func8(int *a1, const char *a2)
{
int v2; // eax
unsigned int v3; // ebx

v2 = open(a2, 0);
*a1 = v2;
v3 = 1;
if ( !v2 )
{
v3 = 0;
outerr("error by opening file");
}
return v3;
}

original_code:
int openFileForRead(FILEHANDLER *file, char* name) {
 *file = open(name, 00);
 if(*file == 0) {
  outerr("error by opening file");
  return 0;
 }
 return 1;
}

canonical_original_code:
int openFileForRead(int *file, char *name) {
 *file = open(name, 00);
 if(*file == 0) {
  outerr("error by opening file");
  return 0;
 }
 return 1;
}


closeFile

decompiled_code:
int __fastcall closeFile(int *a1)
{
int result; // eax

result = close(*a1);
if ( result )
result = outerr("error by file closing\n");
return result;
}

canonical_decompiled_code:
int __fastcall func9(int *a1)
{
int result; // eax

result = close(*a1);
if ( result )
result = outerr("error by file closing\n");
return result;
}

original_code:
void closeFile(FILEHANDLER *file) {
 if(close(*file) != 0)
  outerr("error by file closing\n");
}

canonical_original_code:
void closeFile(int *file) {
 if(close(*file) != 0)
  outerr("error by file closing\n");
}


writeToFile

decompiled_code:
ssize_t __fastcall writeToFile(int *a1, const void *a2)
{
int v2; // eax
ssize_t result; // rax

v2 = strmlen(a2);
result = write(*a1, a2, v2);
if ( !result )
result = outerr("error by file writing\n");
return result;
}

canonical_decompiled_code:
ssize_t __fastcall func10(int *a1, const void *a2)
{
int v2; // eax
ssize_t result; // rax

v2 = strmlen(a2);
result = write(*a1, a2, v2);
if ( !result )
result = outerr("error by file writing\n");
return result;
}

original_code:
void writeToFile(FILEHANDLER *file, char* bytes) {
 if(write(*file,bytes,strmlen(bytes)) <= 0)
  outerr("error by file writing\n");
}

canonical_original_code:
void writeToFile(int *file, char *bytes) {
 if(write(*file,bytes,strmlen(bytes)) <= 0)
  outerr("error by file writing\n");
}

variable_types:
bytes
char *


writeNToFile

decompiled_code:
ssize_t __fastcall writeNToFile(int *a1, const void *a2, unsigned int a3)
{
ssize_t result; // rax

result = write(*a1, a2, a3);
if ( !result )
result = outerr("error by file writing\n");
return result;
}

canonical_decompiled_code:
ssize_t __fastcall func11(int *a1, const void *a2, unsigned int a3)
{
ssize_t result; // rax

result = write(*a1, a2, a3);
if ( !result )
result = outerr("error by file writing\n");
return result;
}

original_code:
void writeNToFile(FILEHANDLER *file, char* bytes, unsigned int len) {
 if(write(*file,bytes,len) <= 0)
  outerr("error by file writing\n");
}

canonical_original_code:
void writeNToFile(int *file, char *bytes, unsigned int len) {
 if(write(*file,bytes,len) <= 0)
  outerr("error by file writing\n");
}

variable_types:
len
unsigned int


readFromFile

decompiled_code:
__int64 __fastcall readFromFile(int *a1)
{
int v1; // eax
char v3[8200]; // [rsp+0h] [rbp-2018h] BYREF
__int64 i; // [rsp+2008h] [rbp-10h] BYREF

for ( i = 0LL; ; strmcat(&i, v3) )
{
v1 = read(*a1, v3, 0x2000uLL);
if ( !v1 )
break;
if ( v1 == -1 )
{
outerr("couldn't read from file\n");
return 0LL;
}
v3[v1] = 0;
}
return i;
}

canonical_decompiled_code:
__int64 __fastcall func12(int *a1)
{
int v1; // eax
char v3[8200]; // [rsp+0h] [rbp-2018h] BYREF
__int64 i; // [rsp+2008h] [rbp-10h] BYREF

for ( i = 0LL; ; strmcat(&i, v3) )
{
v1 = read(*a1, v3, 0x2000uLL);
if ( !v1 )
break;
if ( v1 == -1 )
{
outerr("couldn't read from file\n");
return 0LL;
}
v3[v1] = 0;
}
return i;
}

original_code:
char* readFromFile(FILEHANDLER *file) {
 char* returnString = ((void *)0);
 char buffer[8192 +1];
 int actualSize;
 while((actualSize = read(*file, (void*)buffer, 8192))) {
  if(actualSize==-1) {
   outerr("couldn't read from file\n");
   return ((void *)0);
  }
  buffer[actualSize]=0;
  strmcat(&returnString, buffer);
 }
 return returnString;
}

canonical_original_code:
char *readFromFile(int *file) {
 char *returnString = ((void *)0);
 char buffer[-1];
 int actualSize;
 while((actualSize = read(*file, (void *)buffer, 8192))) {
  if(actualSize==-1) {
   outerr("couldn't read from file\n");
   return ((void *)0);
  }
  buffer[actualSize]=0;
  strmcat(&returnString, buffer);
 }
 return returnString;
}

variable_types:
returnString
char *

variable_types:
buffer
char [-1]

variable_types: actualSize int


getHostByName

decompiled_code:
struct hostent *__fastcall getHostByName(char *name)
{
void *v1; // rbx
size_t i; // rbp
struct hostent *v3; // rbp
int h_errnop; // [rsp+4h] [rbp-44h] BYREF
struct hostent *result; // [rsp+8h] [rbp-40h] BYREF
struct hostent result_buf; // [rsp+10h] [rbp-38h] BYREF

v1 = malloc(0x400uLL);
for ( i = 1024LL; gethostbyname_r(name, &result_buf, (char *)v1, i, &result, &h_errnop); v1 = realloc(v1, i) )
i *= 2LL;
v3 = result;
if ( result )
free(v1);
return v3;
}

canonical_decompiled_code:
struct hostent *__fastcall func1(char *name)
{
void *v1; // rbx
size_t i; // rbp
struct hostent *v3; // rbp
int h_errnop; // [rsp+4h] [rbp-44h] BYREF
struct hostent *result; // [rsp+8h] [rbp-40h] BYREF
struct hostent result_buf; // [rsp+10h] [rbp-38h] BYREF

v1 = malloc(0x400uLL);
for ( i = 1024LL; gethostbyname_r(name, &result_buf, (char *)v1, i, &result, &h_errnop); v1 = realloc(v1, i) )
i *= 2LL;
v3 = result;
if ( result )
free(v1);
return v3;
}

original_code:
struct hostent *getHostByName(char *host){
 struct hostent hostbuf;
 struct hostent *hp;
 size_t hstbuflen;
 char *tmphstbuf;
 int res;
 int herr;
 hstbuflen=1024;
 tmphstbuf=malloc(hstbuflen);
 while((res=gethostbyname_r(host,&hostbuf,tmphstbuf,hstbuflen,&hp,&herr))!=0) {
  hstbuflen*=2;
  tmphstbuf=realloc(tmphstbuf,hstbuflen);
 }
 if(res||hp==((void *)0)) return ((void *)0);
 free(tmphstbuf);
 return hp;
}

canonical_original_code:
struct hostent *getHostByName(char *host){
 struct hostent hostbuf;
 struct hostent *hp;
 unsigned long hstbuflen;
 char *tmphstbuf;
 int res;
 int herr;
 hstbuflen=1024;
 tmphstbuf=malloc(hstbuflen);
 while((res=gethostbyname_r(host,&hostbuf,tmphstbuf,hstbuflen,&hp,&herr))!=0) {
  hstbuflen*=2;
  tmphstbuf=realloc(tmphstbuf,hstbuflen);
 }
 if(res||hp==((void *)0)) return ((void *)0);
 free(tmphstbuf);
 return hp;
}

variable_types:
host
char *

variable_types: struct hostent { char *h_name; char **h_aliases; int h_addrtype; int h_length; char **h_addr_list; } *

variable_types:
hstbuflen
unsigned long

variable_types:
tmphstbuf
char *

variable_types: res int

variable_types: herr int