isatomchar

repo: zenhack/skilisp

original_code:
int isatomchar(int c) {
 return
  ((*__ctype_b_loc ())[(int) ((c))] & (unsigned short int) _ISprint) &&
  !((*__ctype_b_loc ())[(int) ((c))] & (unsigned short int) _ISspace) &&
  c != ';' &&
  c != '(' &&
  c != ')' &&
  c != (-1);
}

canonical_original_code:
int isatomchar(int c) {
 return
  ((*__ctype_b_loc ())[(int) ((c))] & (unsigned short) _ISprint) &&
  !((*__ctype_b_loc ())[(int) ((c))] & (unsigned short) _ISspace) &&
  c != ';' &&
  c != '(' &&
  c != ')' &&
  c != (-1);
}

variable_types: c int


decompiled_code:
__int64 __fastcall skil_string_buffer_init(_QWORD *a1)
{
_BYTE *v1; // rax

a1[1] = 16LL;
v1 = malloc(0x10uLL);
*a1 = v1;
if ( !v1 )
return 0xFFFFFFFFLL;
*v1 = 0;
a1[2] = 0LL;
return 0LL;
}

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

a1[1] = 16LL;
v1 = malloc(0x10uLL);
*a1 = v1;
if ( !v1 )
return 0xFFFFFFFFLL;
*v1 = 0;
a1[2] = 0LL;
return 0LL;
}

original_code:
int skil_string_buffer_init(skil_string_buffer_t *buf) {
 buf->cap = 16;
 buf->buf = malloc(sizeof(char) * buf->cap);
 if(!buf->buf) {
  return -1;
 }
 buf->buf[0] = '\0';
 buf->len = 0;
 return 0;
}

canonical_original_code:
int skil_string_buffer_init(struct skil_string_buffer_t *buf) {
 buf->cap = 16;
 buf->buf = malloc(sizeof(char) * buf->cap);
 if(!buf->buf) {
  return -1;
 }
 buf->buf[0] = '\0';
 buf->len = 0;
 return 0;
}

variable_types: struct skil_string_buffer_t { char *buf; unsigned long cap; } *

return_type: int


decompiled_code:
__int64 __fastcall skil_string_buffer_putc(__int64 a1, char a2)
{
unsigned __int64 v3; // rsi
void *v5; // rax

v3 = *(_QWORD *)(a1 + 8);
if ( *(_QWORD *)(a1 + 16) + 1LL < v3 )
goto LABEL_2;
v5 = realloc(*(void **)a1, 2 * v3);
if ( v5 )
{
*(_QWORD *)a1 = v5;
*(_QWORD *)(a1 + 8) *= 2LL;
LABEL_2:
*(_BYTE *)(*(_QWORD *)a1 + *(_QWORD *)(a1 + 16)) = a2;
*(_BYTE *)(*(_QWORD *)a1 + (*(_QWORD *)(a1 + 16))++ + 1LL) = 0;
return 0LL;
}
return 0xFFFFFFFFLL;
}

original_code:
int skil_string_buffer_putc(skil_string_buffer_t *buf, char c) {
 if(buf->len + 1 >= buf->cap) {
  char *newbuf = realloc(buf->buf, buf->cap * 2);
  if(!newbuf) {
   return -1;
  }
  buf->buf = newbuf;
  buf->cap *= 2;
 }
 buf->buf[buf->len] = c;
 buf->buf[buf->len+1] = '\0';
 buf->len++;
 return 0;
}

canonical_original_code:
int skil_string_buffer_putc(struct skil_string_buffer_t *buf, char c) {
 if(buf->len + 1 >= buf->cap) {
  char *newbuf = realloc(buf->buf, buf->cap * 2);
  if(!newbuf) {
   return -1;
  }
  buf->buf = newbuf;
  buf->cap *= 2;
 }
 buf->buf[buf->len] = c;
 buf->buf[buf->len+1] = '\0';
 buf->len++;
 return 0;
}

variable_types: c char

variable_types:
newbuf
char *

user_defined_types: struct skil_string_buffer_t { char *buf; unsigned long cap; }


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // eax
__int64 v4; // rsi
int v5; // eax
int result; // eax
const char *v7; // rdx
void *ptr[2]; // [rsp+8h] [rbp-10h] BYREF

v3 = skil_token(_bss_start, ptr);
v4 = (unsigned int)v3;
if ( v3 < 0 )
return 0;
while ( 1 )
{
if ( (_DWORD)v4 == 256 )
{
printf("ATOM: %s\n", (const char *)ptr[0]);
free(ptr[0]);
goto LABEL_6;
}
if ( (int)v4 > 256 )
break;
if ( (unsigned int)(v4 - 40) > 1 )
goto LABEL_11;
printf("%c\n", v4);
LABEL_6:
v5 = skil_token(_bss_start, ptr);
v4 = (unsigned int)v5;
if ( v5 < 0 )
return 0;
}
result = 0;
if ( (_DWORD)v4 == 257 )
return result;
LABEL_11:
v7 = (const char *)ptr[0];
if ( !ptr[0] )
v7 = "NULL";
printf("Unknown token type %d with value %s!\n", v4, v7);
return 1;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // eax
__int64 v4; // rsi
int v5; // eax
int result; // eax
const char *v7; // rdx
void *ptr[2]; // [rsp+8h] [rbp-10h] BYREF

v3 = func11(_bss_start, ptr);
v4 = (unsigned int)v3;
if ( v3 < 0 )
return 0;
while ( 1 )
{
if ( (_DWORD)v4 == 256 )
{
printf("ATOM: %s\n", (const char *)ptr[0]);
free(ptr[0]);
goto LABEL_6;
}
if ( (int)v4 > 256 )
break;
if ( (unsigned int)(v4 - 40) > 1 )
goto LABEL_11;
printf("%c\n", v4);
LABEL_6:
v5 = func11(_bss_start, ptr);
v4 = (unsigned int)v5;
if ( v5 < 0 )
return 0;
}
result = 0;
if ( (_DWORD)v4 == 257 )
return result;
LABEL_11:
v7 = (const char *)ptr[0];
if ( !ptr[0] )
v7 = "NULL";
printf("Unknown token type %d with value %s!\n", v4, v7);
return 1;
}

original_code:
int main(void) {
 char *img;
 int token_type;
 token_type = skil_token(stdin, &img);
 while(token_type >= 0) {
  switch(token_type) {
  case '(':
  case ')':
   printf("%c\n", token_type);
   break;
  case 256:
   printf("ATOM: %s\n", img);
   free(img);
   break;
  case 257:
   return 0;
   break;
  default:
   printf("Unknown token type %d with value %s!\n",
    token_type, (img)? img :"NULL");
   return 1;
   break;
  }
  token_type = skil_token(stdin, &img);
 }
 return 0;
}

canonical_original_code:
int main() {
 char *img;
 int token_type;
 token_type = skil_token(stdin, &img);
 while(token_type >= 0) {
  switch(token_type) {
  case '(':
  case ')':
   printf("%c\n", token_type);
   break;
  case 256:
   printf("ATOM: %s\n", img);
   free(img);
   break;
  case 257:
   return 0;
   break;
  default:
   printf("Unknown token type %d with value %s!\n",
    token_type, (img)? img :"NULL");
   return 1;
   break;
  }
  token_type = skil_token(stdin, &img);
 }
 return 0;
}

variable_types:
img
char *


search

repo: zenkj/lp

original_code:
static int search(lp_strpool *sp, const char* str) {
    int i = 0;
    int j = sp->idxcount - 1;
    char *pool = sp->pool;
    int *indexes = sp->indexes;
    while (i <= j) {
        int m = (i + j) / 2;
        char *b = &pool[indexes[m]];
        int r = strcmp(b, str);
        if (r == 0) {
            return indexes[m];
        } else if (r < 0) {
            i = m + 1;
        } else {
            j = m - 1;
        }
    }
    return -((i+j+1)/2) - 1;
}

canonical_original_code:
static int search(struct lp_strpool *sp, char *str) {
    int i = 0;
    int j = sp->idxcount - 1;
    char *pool = sp->pool;
    int *indexes = sp->indexes;
    while (i <= j) {
        int m = (i + j) / 2;
        char *b = &pool[indexes[m]];
        int r = strcmp(b, str);
        if (r == 0) {
            return indexes[m];
        } else if (r < 0) {
            i = m + 1;
        } else {
            j = m - 1;
        }
    }
    return -((i+j+1)/2) - 1;
}

variable_types: struct lp_strpool { int charcount; int charsize; char *pool; int idxcount; int idxsize; int *indexes; } *

variable_types:
str
char *

variable_types: i int

variable_types: j int

variable_types:
pool
char *

variable_types:
indexes
int *

variable_types: m int

variable_types:
b
char *

variable_types: r int


decompiled_code:
_DWORD *strpool_init()
{
void *v0; // rbp
void *v1; // r12
_DWORD *v2; // rax
_DWORD *v3; // rbx

v0 = malloc(0x1000uLL);
if ( v0 )
{
v1 = malloc(0x400uLL);
if ( v1 )
{
v2 = malloc(0x20uLL);
v3 = v2;
if ( v2 )
{
*v2 = 0;
v2[1] = 4096;
*((_QWORD *)v2 + 1) = v0;
v2[4] = 0;
v2[5] = 256;
*((_QWORD *)v2 + 3) = v1;
}
else
{
free(v0);
free(v1);
fwrite("no enough memory", 1uLL, 0x10uLL, stderr);
}
}
else
{
free(v0);
fwrite("no enough memory", 1uLL, 0x10uLL, stderr);
v3 = 0LL;
}
}
else
{
fwrite("no enough memory", 1uLL, 0x10uLL, stderr);
v3 = 0LL;
}
return v3;
}

canonical_decompiled_code:
_DWORD *func1()
{
void *v0; // rbp
void *v1; // r12
_DWORD *v2; // rax
_DWORD *v3; // rbx

v0 = malloc(0x1000uLL);
if ( v0 )
{
v1 = malloc(0x400uLL);
if ( v1 )
{
v2 = malloc(0x20uLL);
v3 = v2;
if ( v2 )
{
*v2 = 0;
v2[1] = 4096;
*((_QWORD *)v2 + 1) = v0;
v2[4] = 0;
v2[5] = 256;
*((_QWORD *)v2 + 3) = v1;
}
else
{
free(v0);
free(v1);
fwrite("no enough memory", 1uLL, 0x10uLL, stderr);
}
}
else
{
free(v0);
fwrite("no enough memory", 1uLL, 0x10uLL, stderr);
v3 = 0LL;
}
}
else
{
fwrite("no enough memory", 1uLL, 0x10uLL, stderr);
v3 = 0LL;
}
return v3;
}

original_code:
lp_strpool *strpool_init() {
    char *pool;
    int *indexes;
    lp_strpool *sp;
    pool = (char*)malloc(4096);
    if (pool == ((void *)0)) {
        fprintf(stderr, "no enough memory");
        return ((void *)0);
    }
    indexes = (int*)malloc(256 * sizeof(int));
    if (indexes == ((void *)0)) {
        free(pool);
        fprintf(stderr, "no enough memory");
        return ((void *)0);
    }
    sp = (lp_strpool*)malloc(sizeof(lp_strpool));
    if (sp == ((void *)0)) {
        free(pool);
        free(indexes);
        fprintf(stderr, "no enough memory");
        return ((void *)0);
    }
    sp->charcount = 0;
    sp->charsize = 4096;
    sp->pool = pool;
    sp->idxcount = 0;
    sp->idxsize = 256;
    sp->indexes = indexes;
    return sp;
}

canonical_original_code:
struct lp_strpool *strpool_init() {
    char *pool;
    int *indexes;
    struct lp_strpool *sp;
    pool = (char *)malloc(4096);
    if (pool == ((void *)0)) {
        fprintf(stderr, "no enough memory");
        return ((void *)0);
    }
    indexes = (int *)malloc(256 * sizeof(int));
    if (indexes == ((void *)0)) {
        free(pool);
        fprintf(stderr, "no enough memory");
        return ((void *)0);
    }
    sp = (struct lp_strpool *)malloc(sizeof(lp_strpool));
    if (sp == ((void *)0)) {
        free(pool);
        free(indexes);
        fprintf(stderr, "no enough memory");
        return ((void *)0);
    }
    sp->charcount = 0;
    sp->charsize = 4096;
    sp->pool = pool;
    sp->idxcount = 0;
    sp->idxsize = 256;
    sp->indexes = indexes;
    return sp;
}

return_type: struct lp_strpool { int charcount; int charsize; char *pool; int idxcount; int idxsize; int *indexes; } *


decompiled_code:
void __fastcall strpool_destroy(void *ptr)
{
if ( ptr )
{
free(*((void **)ptr + 3));
free(*((void **)ptr + 1));
free(ptr);
}
}

canonical_decompiled_code:
void __fastcall func2(void *ptr)
{
if ( ptr )
{
free(*((void **)ptr + 3));
free(*((void **)ptr + 1));
free(ptr);
}
}

original_code:
void strpool_destroy(lp_strpool* sp) {
    if (sp == ((void *)0))
        return;
    free(sp->indexes);
    free(sp->pool);
    free(sp);
}

canonical_original_code:
void strpool_destroy(struct lp_strpool *sp) {
    if (sp == ((void *)0))
        return;
    free(sp->indexes);
    free(sp->pool);
    free(sp);
}

return_type: void

user_defined_types: struct lp_strpool { int charcount; int charsize; char *pool; int idxcount; int idxsize; int *indexes; }


original_code:
int strpool_add(lp_strpool *sp, const char* str) {
    int len;
    int pos;
    int idxpos;
    int newcharcount;
    int newidxcount;
    ((void) sizeof ((sp != ((void *)0)) ? 1 : 0), __extension__ ({ if (sp != ((void *)0)) ; else __assert_fail ("sp != NULL", "strpool.c", 84, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((str != ((void *)0)) ? 1 : 0), __extension__ ({ if (str != ((void *)0)) ; else __assert_fail ("str != NULL", "strpool.c", 85, __extension__ __PRETTY_FUNCTION__); }));
    pos = search(sp, str);
    if (pos >= 0) {
        return pos;
    }
    idxpos = -(pos + 1);
    len = strlen(str);
    pos = sp->charcount;
    newcharcount = pos + len + 1;
    if (newcharcount >= sp->charsize) {
        int newsize = newcharcount * 2;
        char *pool = (char*)realloc(sp->pool, newsize);
        if (pool == ((void *)0)) {
            fprintf(stderr, "no enough memory");
            return -1;
        }
        sp->pool = pool;
        sp->charsize = newsize;
    }
    newidxcount = sp->idxcount + 1;
    if (newidxcount >= sp->idxsize) {
        int newsize = newidxcount * 2;
        int *indexes = (int*)realloc(sp->indexes, newsize*sizeof(int));
        if (indexes == ((void *)0)) {
            fprintf(stderr, "no enough memory");
            return -1;
        }
        sp->indexes = indexes;
        sp->idxsize = newsize;
    }
    strcpy(sp->pool + sp->charcount, str);
    sp->charcount = newcharcount;
    if (idxpos < sp->idxcount) {
        memmove((void*)(sp->indexes+idxpos+1), (void*)(sp->indexes+idxpos), sizeof(int));
    }
    sp->indexes[idxpos] = pos;
    sp->idxcount = newidxcount;
    return pos;
}

canonical_original_code:
int strpool_add(struct lp_strpool *sp, char *str) {
    int len;
    int pos;
    int idxpos;
    int newcharcount;
    int newidxcount;
    ((void) sizeof ((sp != ((void *)0)) ? 1 : 0), __extension__ ({ if (sp != ((void *)0)) ; else __assert_fail ("sp != NULL", "strpool.c", 84, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((str != ((void *)0)) ? 1 : 0), __extension__ ({ if (str != ((void *)0)) ; else __assert_fail ("str != NULL", "strpool.c", 85, __extension__ __PRETTY_FUNCTION__); }));
    pos = search(sp, str);
    if (pos >= 0) {
        return pos;
    }
    idxpos = -(pos + 1);
    len = strlen(str);
    pos = sp->charcount;
    newcharcount = pos + len + 1;
    if (newcharcount >= sp->charsize) {
        int newsize = newcharcount * 2;
        char *pool = (char*)realloc(sp->pool, newsize);
        if (pool == ((void *)0)) {
            fprintf(stderr, "no enough memory");
            return -1;
        }
        sp->pool = pool;
        sp->charsize = newsize;
    }
    newidxcount = sp->idxcount + 1;
    if (newidxcount >= sp->idxsize) {
        int newsize = newidxcount * 2;
        int *indexes = (int*)realloc(sp->indexes, newsize*sizeof(int));
        if (indexes == ((void *)0)) {
            fprintf(stderr, "no enough memory");
            return -1;
        }
        sp->indexes = indexes;
        sp->idxsize = newsize;
    }
    strcpy(sp->pool + sp->charcount, str);
    sp->charcount = newcharcount;
    if (idxpos < sp->idxcount) {
        memmove((void *)(sp->indexes+idxpos+1), (void *)(sp->indexes+idxpos), sizeof(int));
    }
    sp->indexes[idxpos] = pos;
    sp->idxcount = newidxcount;
    return pos;
}

variable_types: len int

variable_types: pos int

variable_types: idxpos int

variable_types: newcharcount int

variable_types: newidxcount int

variable_types: newsize int


decompiled_code:
int __fastcall strpool_print(__int64 a1)
{
__int64 v1; // rbx
int result; // eax

if ( *(int *)(a1 + 16) > 0 )
{
v1 = 0LL;
do
result = puts((const char *)(*(_QWORD *)(a1 + 8) + *(int *)(*(_QWORD *)(a1 + 24) + 4 * v1++)));
while ( *(_DWORD *)(a1 + 16) > (int)v1 );
}
return result;
}

canonical_decompiled_code:
int __fastcall func4(__int64 a1)
{
__int64 v1; // rbx
int result; // eax

if ( *(int *)(a1 + 16) > 0 )
{
v1 = 0LL;
do
result = puts((const char *)(*(_QWORD *)(a1 + 8) + *(int *)(*(_QWORD *)(a1 + 24) + 4 * v1++)));
while ( *(_DWORD *)(a1 + 16) > (int)v1 );
}
return result;
}

original_code:
void strpool_print(lp_strpool *sp) {
    int i;
    for (i=0; i<sp->idxcount; i++) {
        printf("%s\n", sp->pool + sp->indexes[i]);
    }
}

canonical_original_code:
void strpool_print(struct lp_strpool *sp) {
    int i;
    for (i=0; i<sp->idxcount; i++) {
        printf("%s\n", sp->pool + sp->indexes[i]);
    }
}


main

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

v3 = strpool_init();
strpool_add(v3, "cadsfeasfd");
strpool_add(v3, "afsadf");
strpool_add(v3, "f1111");
strpool_add(v3, "dr222");
strpool_add(v3, "iddd");
strpool_add(v3, "eaa");
v4 = search((__int64)v3, argv[1]);
printf("%d\n", v4);
strpool_print((__int64)v3);
strpool_destroy(v3);
return 0;
}

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

v3 = func1();
func3(v3, "cadsfeasfd");
func3(v3, "afsadf");
func3(v3, "f1111");
func3(v3, "dr222");
func3(v3, "iddd");
func3(v3, "eaa");
v4 = func0((__int64)v3, argv[1]);
printf("%d\n", v4);
func4((__int64)v3);
func2(v3);
return 0;
}

original_code:
int main(int argc, char*argv[]) {
    lp_strpool *sp = strpool_init();
    strpool_add(sp, "cadsfeasfd");
    strpool_add(sp, "afsadf");
    strpool_add(sp, "f1111");
    strpool_add(sp, "dr222");
    strpool_add(sp, "iddd");
    strpool_add(sp, "eaa");
    printf("%d\n", search(sp, argv[1]));
    strpool_print(sp);
    strpool_destroy(sp);
    return 0;
}

canonical_original_code:
int main(int argc, char *argv[]) {
    struct lp_strpool *sp = strpool_init();
    strpool_add(sp, "cadsfeasfd");
    strpool_add(sp, "afsadf");
    strpool_add(sp, "f1111");
    strpool_add(sp, "dr222");
    strpool_add(sp, "iddd");
    strpool_add(sp, "eaa");
    printf("%d\n", search(sp, argv[1]));
    strpool_print(sp);
    strpool_destroy(sp);
    return 0;
}

variable_types: argc int

variable_types:
argv
char *[]


decompiled_code:
char *init_item()
{
char *v0; // rax
char *v1; // rbx
void *v2; // rax

v0 = (char *)calloc(1uLL, 0x58uLL);
if ( !v0 )
{
fwrite("Dynamic memory allocation failed\n", 1uLL, 0x21uLL, stderr);
exit(1);
}
v1 = v0;
v2 = calloc(0x14uLL, 1uLL);
*((_QWORD *)v1 + 5) = v2;
if ( !v2 )
{
fwrite("Dynamic memory allocation failed\n", 1uLL, 0x21uLL, stderr);
exit(1);
}
*((_QWORD *)v1 + 5) = 0LL;
*((_QWORD *)v1 + 6) = 0LL;
sem_init((sem_t *)(v1 + 56), 0, 0);
*((_DWORD *)v1 + 4) = -1;
return v1;
}

canonical_decompiled_code:
char *func0()
{
char *v0; // rax
char *v1; // rbx
void *v2; // rax

v0 = (char *)calloc(1uLL, 0x58uLL);
if ( !v0 )
{
fwrite("Dynamic memory allocation failed\n", 1uLL, 0x21uLL, stderr);
exit(1);
}
v1 = v0;
v2 = calloc(0x14uLL, 1uLL);
*((_QWORD *)v1 + 5) = v2;
if ( !v2 )
{
fwrite("Dynamic memory allocation failed\n", 1uLL, 0x21uLL, stderr);
exit(1);
}
*((_QWORD *)v1 + 5) = 0LL;
*((_QWORD *)v1 + 6) = 0LL;
sem_init((sem_t *)(v1 + 56), 0, 0);
*((_DWORD *)v1 + 4) = -1;
return v1;
}

original_code:
item* init_item()
{
    item* i = ((void *)0);
    i = calloc(1, sizeof(item));
    if(i==((void *)0)) {
        fprintf(stderr, "Dynamic memory allocation failed\n");
        exit(1);
    }
    i->value = calloc(20, sizeof(char));
    if(i->value==((void *)0)) {
        fprintf(stderr, "Dynamic memory allocation failed\n");
        exit(1);
    }
    i->value = ((void *)0);
    i->pair = ((void *)0);
    sem_init(&(i->waiting), 0, 0);
    i->file_position = -1;
    return i;
}

canonical_original_code:
struct _item *init_item()
{
    struct _item *i = ((void *)0);
    i = calloc(1, sizeof(item));
    if(i==((void *)0)) {
        fprintf(stderr, "Dynamic memory allocation failed\n");
        exit(1);
    }
    i->value = calloc(20, sizeof(char));
    if(i->value==((void *)0)) {
        fprintf(stderr, "Dynamic memory allocation failed\n");
        exit(1);
    }
    i->value = ((void *)0);
    i->pair = ((void *)0);
    sem_init(&(i->waiting), 0, 0);
    i->file_position = -1;
    return i;
}

variable_types: struct _item { int clientID; int shardID; int dimension; int op; int file_position; char key[20]; char *value; struct KV_t { char key[20]; char value[20]; } *pair; union sem_t { char __size[32]; long __align; } waiting; } *

user_defined_types: struct _item { int clientID; int shardID; int dimension; int op; int file_position; char key[20]; char *value; struct KV_t *pair; union sem_t waiting; }


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

if ( ptr )
{
sem_destroy((sem_t *)((char *)ptr + 56));
v2 = (void *)*((_QWORD *)ptr + 6);
if ( v2 )
free(v2);
v3 = (void *)*((_QWORD *)ptr + 5);
if ( v3 )
free(v3);
free(ptr);
}
}

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

if ( ptr )
{
sem_destroy((sem_t *)((char *)ptr + 56));
v2 = (void *)*((_QWORD *)ptr + 6);
if ( v2 )
free(v2);
v3 = (void *)*((_QWORD *)ptr + 5);
if ( v3 )
free(v3);
free(ptr);
}
}

original_code:
void destroy_item(item *i)
{
    if(i != ((void *)0)){
        sem_destroy(&(i->waiting));
        if(i->pair != ((void *)0)){
            free(i->pair);
        }
        if(i->value != ((void *)0)){
            free(i->value);
        }
        free(i);
    }
}

canonical_original_code:
void destroy_item(struct _item *i)
{
    if(i != ((void *)0)){
        sem_destroy(&(i->waiting));
        if(i->pair != ((void *)0)){
            free(i->pair);
        }
        if(i->value != ((void *)0)){
            free(i->value);
        }
        free(i);
    }
}

user_defined_types: union sem_t { char __size[32]; long __align; }

user_defined_types: struct KV_t { char key[20]; char value[20]; }


decompiled_code:
void __fastcall destroy_buffer(void *ptr)
{
__int64 v1; // rbx

if ( *(int *)ptr > 0 )
{
v1 = 0LL;
do
free(*(void **)(*((_QWORD *)ptr + 1) + 8 * v1++));
while ( *(_DWORD *)ptr > (int)v1 );
}
free(ptr);
}

canonical_decompiled_code:
void __fastcall func2(void *ptr)
{
__int64 v1; // rbx

if ( *(int *)ptr > 0 )
{
v1 = 0LL;
do
free(*(void **)(*((_QWORD *)ptr + 1) + 8 * v1++));
while ( *(_DWORD *)ptr > (int)v1 );
}
free(ptr);
}

original_code:
void destroy_buffer(buffer *b)
{
    int ix;
    for(ix = 0; ix < b->size; ix += 1) {
        free(b->items[ix]);
    }
    free(b);
}

canonical_original_code:
void destroy_buffer(struct _buffer *b)
{
    int ix;
    for(ix = 0; ix < b->size; ix += 1) {
        free(b->items[ix]);
    }
    free(b);
}

variable_types: struct _buffer { int size; struct _item { int clientID; int shardID; int dimension; int op; int file_position; char key[20]; char *value; struct KV_t { char key[20]; char value[20]; } *pair; union sem_t { char __size[32]; long __align; } waiting; } **items; } *

variable_types: ix int

user_defined_types: struct _buffer { int size; struct _item **items; }


original_code:
void write_item(item *i, int clientID, int shardID, int op, char *key, char *value, KV_t *pair, int file_position)
{
    if(i != ((void *)0)){
        if(clientID != -1){
            i->clientID = clientID;
        }
        if(shardID != -1){
            i->shardID = shardID;
        }
        if(op != -1){
            i->op = op;
        }
        if(file_position != -1) {
            i->file_position = file_position;
        }
        if(key != ((void *)0)){
            strncpy(i->key, key, 20);
        }
        if(value != ((void *)0)){
            if(i->value == ((void *)0)) {
                i->value = calloc(20, sizeof(char));
                if(i->value==((void *)0)) {
                    fprintf(stderr, "Dynamic memory allocation failed\n");
                    exit(1);
                }
            }
            strncpy(i->value, value, 20);
        }
        else {
            if(i->value != ((void *)0)){
                free(i->value);
                i->value = ((void *)0);
            }
        }
        if(pair != ((void *)0)){
            i->pair = pair;
        }
    }
}

canonical_original_code:
void write_item(struct _item *i, int clientID, int shardID, int op, char *key, char *value, struct KV_t *pair, int file_position)
{
    if(i != ((void *)0)){
        if(clientID != -1){
            i->clientID = clientID;
        }
        if(shardID != -1){
            i->shardID = shardID;
        }
        if(op != -1){
            i->op = op;
        }
        if(file_position != -1) {
            i->file_position = file_position;
        }
        if(key != ((void *)0)){
            strncpy(i->key, key, 20);
        }
        if(value != ((void *)0)){
            if(i->value == ((void *)0)) {
                i->value = calloc(20, sizeof(char));
                if(i->value==((void *)0)) {
                    fprintf(stderr, "Dynamic memory allocation failed\n");
                    exit(1);
                }
            }
            strncpy(i->value, value, 20);
        }
        else {
            if(i->value != ((void *)0)){
                free(i->value);
                i->value = ((void *)0);
            }
        }
        if(pair != ((void *)0)){
            i->pair = pair;
        }
    }
}

variable_types: clientID int

variable_types: shardID int

variable_types: op int

variable_types:
key
char *

variable_types:
value
char *

variable_types:
pair
struct KV_t *


populate

decompiled_code:
__int64 __fastcall populate(int a1)
{
++*(_DWORD *)(file_pos + 4LL * a1);
return add(*(_QWORD *)(shards + 8LL * a1));
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1)
{
++*(_DWORD *)(file_pos + 4LL * a1);
return add(*(_QWORD *)(shards + 8LL * a1));
}

original_code:
void populate(int shardId, char* key, char* value)
{
    int file_position = -1;
    file_position = file_pos[shardId];
    file_pos[shardId] += 1;
    add(shards[shardId], key, value, file_position);
}

canonical_original_code:
void populate(int shardId, char *key, char *value)
{
    int file_position = -1;
    file_position = file_pos[shardId];
    file_pos[shardId] += 1;
    add(shards[shardId], key, value, file_position);
}

variable_types: shardId int


writeToFile

decompiled_code:
int __fastcall writeToFile(unsigned int a1, const char *a2, const char *a3, int a4)
{
int v6; // eax
int v7; // esi
__int64 v8; // rdx
char *v9; // rax
char *v10; // rdx
int v11; // eax
int v12; // esi
__int64 v13; // rdx
char *v14; // rax
char *v15; // rdx
char v17[32]; // [rsp+0h] [rbp-88h] BYREF
char dest[32]; // [rsp+20h] [rbp-68h] BYREF
char s[72]; // [rsp+40h] [rbp-48h] BYREF

snprintf(s, 0x14uLL, "fshard%d", a1);
strncpy(dest, a2, 0x14uLL);
strncpy(v17, a3, 0x14uLL);
v6 = strlen(a2);
if ( v6 <= 18 )
{
v7 = v6;
v8 = v6;
v9 = &dest[v6];
v10 = &dest[v8 + 1 + (unsigned int)(18 - v7)];
do
*v9++ = 32;
while ( v9 != v10 );
v6 = 19;
}
dest[v6] = 0;
v11 = strlen(a3);
v12 = v11;
if ( v11 <= 18 )
{
v13 = v11;
v14 = &v17[v11];
v15 = &v17[v13 + 1 + (unsigned int)(18 - v12)];
do
*v14++ = 32;
while ( v14 != v15 );
v11 = 19;
}
v17[v11] = 0;
pthread_mutex_lock((pthread_mutex_t *)(mutexFiles + 40LL * (int)a1));
if ( a4 != -1 )
fseek(*(FILE **)(files + 8LL * (int)a1), 40LL * a4, 0);
fprintf(*(FILE **)(files + 8LL * (int)a1), "%s %s\n", dest, v17);
fflush(*(FILE **)(files + 8LL * (int)a1));
return pthread_mutex_unlock((pthread_mutex_t *)(mutexFiles + 40LL * (int)a1));
}

canonical_decompiled_code:
int __fastcall func2(unsigned int a1, const char *a2, const char *a3, int a4)
{
int v6; // eax
int v7; // esi
__int64 v8; // rdx
char *v9; // rax
char *v10; // rdx
int v11; // eax
int v12; // esi
__int64 v13; // rdx
char *v14; // rax
char *v15; // rdx
char v17[32]; // [rsp+0h] [rbp-88h] BYREF
char dest[32]; // [rsp+20h] [rbp-68h] BYREF
char s[72]; // [rsp+40h] [rbp-48h] BYREF

snprintf(s, 0x14uLL, "fshard%d", a1);
strncpy(dest, a2, 0x14uLL);
strncpy(v17, a3, 0x14uLL);
v6 = strlen(a2);
if ( v6 <= 18 )
{
v7 = v6;
v8 = v6;
v9 = &dest[v6];
v10 = &dest[v8 + 1 + (unsigned int)(18 - v7)];
do
*v9++ = 32;
while ( v9 != v10 );
v6 = 19;
}
dest[v6] = 0;
v11 = strlen(a3);
v12 = v11;
if ( v11 <= 18 )
{
v13 = v11;
v14 = &v17[v11];
v15 = &v17[v13 + 1 + (unsigned int)(18 - v12)];
do
*v14++ = 32;
while ( v14 != v15 );
v11 = 19;
}
v17[v11] = 0;
pthread_mutex_lock((pthread_mutex_t *)(mutexFiles + 40LL * (int)a1));
if ( a4 != -1 )
fseek(*(FILE **)(files + 8LL * (int)a1), 40LL * a4, 0);
fprintf(*(FILE **)(files + 8LL * (int)a1), "%s %s\n", dest, v17);
fflush(*(FILE **)(files + 8LL * (int)a1));
return pthread_mutex_unlock((pthread_mutex_t *)(mutexFiles + 40LL * (int)a1));
}

original_code:
void writeToFile(int shardId, char* key, char* value, int position)
{
    char name[20], key_copy[20], value_copy[20];
    int ix, spaces;
    snprintf(name, 20, "fshard%d", shardId);
    strncpy(key_copy, key, 20);
    strncpy(value_copy, value, 20);
    spaces = 20 - 1;
    for(ix = strlen(key); ix < spaces; ++ix) {
        key_copy[ix] = ' ';
    }
    key_copy[ix] = '\0';
    for(ix = strlen(value); ix < spaces; ++ix) {
        value_copy[ix] = ' ';
    }
    value_copy[ix] = '\0';
    pthread_mutex_lock(&mutexFiles[shardId]);
    if(position != -1) {
        fseek(files[shardId], 40 * sizeof(char) * position, 0);
    }
    fprintf(files[shardId], "%s %s\n", key_copy, value_copy);
    fflush(files[shardId]);
    pthread_mutex_unlock(&mutexFiles[shardId]);
}

canonical_original_code:
void writeToFile(int shardId, char *key, char *value, int position)
{
    char name[20]; char key_copy[20]; char value_copy[20];
    int ix; int spaces;
    snprintf(name, 20, "fshard%d", shardId);
    strncpy(key_copy, key, 20);
    strncpy(value_copy, value, 20);
    spaces = 20 - 1;
    for(ix = strlen(key); ix < spaces; ++ix) {
        key_copy[ix] = ' ';
    }
    key_copy[ix] = '\0';
    for(ix = strlen(value); ix < spaces; ++ix) {
        value_copy[ix] = ' ';
    }
    value_copy[ix] = '\0';
    pthread_mutex_lock(&mutexFiles[shardId]);
    if(position != -1) {
        fseek(files[shardId], 40 * sizeof(char) * position, 0);
    }
    fprintf(files[shardId], "%s %s\n", key_copy, value_copy);
    fflush(files[shardId]);
    pthread_mutex_unlock(&mutexFiles[shardId]);
}

variable_types: position int

variable_types:
name
char [20]

variable_types: spaces int


producer

decompiled_code:
int __fastcall producer(__int64 a1)
{
int v1; // ecx

sem_wait(&semCanProd);
pthread_mutex_lock(&mutex);
v1 = index_producer++;
index_producer %= *(_DWORD *)b;
*(_QWORD *)(*(_QWORD *)(b + 8) + 8LL * v1) = a1;
pthread_mutex_unlock(&mutex);
sem_post(&semCanCons);
return sem_wait((sem_t *)(a1 + 56));
}

canonical_decompiled_code:
int __fastcall func3(__int64 a1)
{
int v1; // ecx

sem_wait(&semCanProd);
pthread_mutex_lock(&mutex);
v1 = index_producer++;
index_producer %= *(_DWORD *)b;
*(_QWORD *)(*(_QWORD *)(b + 8) + 8LL * v1) = a1;
pthread_mutex_unlock(&mutex);
sem_post(&semCanCons);
return sem_wait((sem_t *)(a1 + 56));
}

original_code:
void producer(item *ip)
{
    int pos;
    sem_wait(&semCanProd);
    pthread_mutex_lock(&mutex);
    pos = index_producer++;
    index_producer %= b->size;
    b->items[pos] = ip;
    pthread_mutex_unlock(&mutex);
    sem_post(&semCanCons);
    sem_wait(&(ip->waiting));
}

canonical_original_code:
void producer(struct _item *ip)
{
    int pos;
    sem_wait(&semCanProd);
    pthread_mutex_lock(&mutex);
    pos = index_producer++;
    index_producer %= b->size;
    b->items[pos] = ip;
    pthread_mutex_unlock(&mutex);
    sem_post(&semCanCons);
    sem_wait(&(ip->waiting));
}

variable_types: pos int


decompiled_code:
char *__fastcall kos_get(unsigned int a1, unsigned int a2, __int64 a3)
{
__int64 v4; // rbx
const char *v5; // r12
char *v6; // rax
char *v7; // rbp

v4 = init_item();
write_item(v4, a1, a2, 2LL, a3, 0LL, 0LL, -1LL);
producer(v4);
v5 = *(const char **)(v4 + 40);
if ( v5 )
{
v6 = (char *)calloc(0x14uLL, 1uLL);
v7 = v6;
if ( !v6 )
{
fwrite("Dynamic memory allocation failed\n", 1uLL, 0x21uLL, stderr);
exit(1);
}
strncpy(v6, v5, 0x14uLL);
}
else
{
v7 = 0LL;
}
destroy_item(v4);
return v7;
}

canonical_decompiled_code:
char *__fastcall func4(unsigned int a1, unsigned int a2, __int64 a3)
{
__int64 v4; // rbx
const char *v5; // r12
char *v6; // rax
char *v7; // rbp

v4 = init_item();
write_item(v4, a1, a2, 2LL, a3, 0LL, 0LL, -1LL);
func3(v4);
v5 = *(const char **)(v4 + 40);
if ( v5 )
{
v6 = (char *)calloc(0x14uLL, 1uLL);
v7 = v6;
if ( !v6 )
{
fwrite("Dynamic memory allocation failed\n", 1uLL, 0x21uLL, stderr);
exit(1);
}
strncpy(v6, v5, 0x14uLL);
}
else
{
v7 = 0LL;
}
destroy_item(v4);
return v7;
}

original_code:
char* kos_get(int clientid, int shardId, char* key)
{
    char *ret = ((void *)0);
    item *i = ((void *)0);
    i = init_item();
    write_item(i, clientid, shardId, 2, key, ((void *)0), ((void *)0), -1);
    producer(i);
    if(i->value != ((void *)0)) {
        ret = calloc(20, sizeof(char));
        if(ret==((void *)0)) {
            fprintf(stderr, "Dynamic memory allocation failed\n");
            exit(1);
        }
        strncpy(ret, i->value, 20);
    }
    destroy_item(i);
    return ret;
}

canonical_original_code:
char *kos_get(int clientid, int shardId, char *key)
{
    char *ret = ((void *)0);
    struct _item *i = ((void *)0);
    i = init_item();
    write_item(i, clientid, shardId, 2, key, ((void *)0), ((void *)0), -1);
    producer(i);
    if(i->value != ((void *)0)) {
        ret = calloc(20, sizeof(char));
        if(ret==((void *)0)) {
            fprintf(stderr, "Dynamic memory allocation failed\n");
            exit(1);
        }
        strncpy(ret, i->value, 20);
    }
    destroy_item(i);
    return ret;
}

variable_types: clientid int

variable_types:
ret
char *

return_type: char *


decompiled_code:
char *__fastcall kos_put(unsigned int a1, signed int a2, const char *a3, const char *a4)
{
__int64 v4; // rbx
_DWORD *v5; // rax
__int64 v6; // r13
const char *v7; // r15
char *v8; // rax
char *v9; // r12

v4 = init_item();
pthread_mutex_lock(&mutex_filepos);
if ( (unsigned int)lst_size(*(_QWORD *)(invalids + 8LL * a2)) )
{
v6 = (unsigned int)lst_remove_pos(*(_QWORD *)(invalids + 8LL * a2));
}
else
{
v5 = (_DWORD *)(file_pos + 4LL * a2);
v6 = (unsigned int)*v5;
*v5 = v6 + 1;
}
pthread_mutex_unlock(&mutex_filepos);
write_item(v4, a1, (unsigned int)a2, 1LL, a3, a4, 0LL, v6);
producer(v4);
v7 = *(const char **)(v4 + 40);
if ( v7 )
{
v8 = (char *)calloc(0x14uLL, 1uLL);
v9 = v8;
if ( !v8 )
{
fwrite("Dynamic memory allocation failed\n", 1uLL, 0x21uLL, stderr);
exit(1);
}
strncpy(v8, v7, 0x14uLL);
writeToFile(a2, a3, a4, *(_DWORD *)(v4 + 16));
lst_insert_pos(*(_QWORD *)(invalids + 8LL * a2), (unsigned int)v6);
}
else
{
writeToFile(a2, a3, a4, v6);
v9 = 0LL;
}
destroy_item(v4);
return v9;
}

canonical_decompiled_code:
char *__fastcall func5(unsigned int a1, signed int a2, const char *a3, const char *a4)
{
__int64 v4; // rbx
_DWORD *v5; // rax
__int64 v6; // r13
const char *v7; // r15
char *v8; // rax
char *v9; // r12

v4 = init_item();
pthread_mutex_lock(&mutex_filepos);
if ( (unsigned int)lst_size(*(_QWORD *)(invalids + 8LL * a2)) )
{
v6 = (unsigned int)lst_remove_pos(*(_QWORD *)(invalids + 8LL * a2));
}
else
{
v5 = (_DWORD *)(file_pos + 4LL * a2);
v6 = (unsigned int)*v5;
*v5 = v6 + 1;
}
pthread_mutex_unlock(&mutex_filepos);
write_item(v4, a1, (unsigned int)a2, 1LL, a3, a4, 0LL, v6);
func3(v4);
v7 = *(const char **)(v4 + 40);
if ( v7 )
{
v8 = (char *)calloc(0x14uLL, 1uLL);
v9 = v8;
if ( !v8 )
{
fwrite("Dynamic memory allocation failed\n", 1uLL, 0x21uLL, stderr);
exit(1);
}
strncpy(v8, v7, 0x14uLL);
func2(a2, a3, a4, *(_DWORD *)(v4 + 16));
lst_insert_pos(*(_QWORD *)(invalids + 8LL * a2), (unsigned int)v6);
}
else
{
func2(a2, a3, a4, v6);
v9 = 0LL;
}
destroy_item(v4);
return v9;
}

original_code:
char* kos_put(int clientid, int shardId, char* key, char* value)
{
    int file_position = -1;
    char *ret = ((void *)0);
    item *i = ((void *)0);
    i = init_item();
    pthread_mutex_lock(&mutex_filepos);
    if(lst_size(invalids[shardId]) == 0) {
        file_position = file_pos[shardId];
        file_pos[shardId] += 1;
    }
    else {
        file_position = lst_remove_pos(invalids[shardId]);
    }
    pthread_mutex_unlock(&mutex_filepos);
    write_item(i, clientid, shardId, 1, key, value, ((void *)0), file_position);
    producer(i);
    if(i->value != ((void *)0)) {
        ret = calloc(20, sizeof(char));
        if(ret==((void *)0)) {
            fprintf(stderr, "Dynamic memory allocation failed\n");
            exit(1);
        }
        strncpy(ret, i->value, 20);
    }
    if(ret != ((void *)0)) {
        writeToFile(shardId, key, value, i->file_position);
        lst_insert_pos(invalids[shardId], file_position);
    }
    else {
        writeToFile(shardId, key, value, file_position);
    }
    destroy_item(i);
    return ret;
}

canonical_original_code:
char *kos_put(int clientid, int shardId, char *key, char *value)
{
    int file_position = -1;
    char *ret = ((void *)0);
    struct _item *i = ((void *)0);
    i = init_item();
    pthread_mutex_lock(&mutex_filepos);
    if(lst_size(invalids[shardId]) == 0) {
        file_position = file_pos[shardId];
        file_pos[shardId] += 1;
    }
    else {
        file_position = lst_remove_pos(invalids[shardId]);
    }
    pthread_mutex_unlock(&mutex_filepos);
    write_item(i, clientid, shardId, 1, key, value, ((void *)0), file_position);
    producer(i);
    if(i->value != ((void *)0)) {
        ret = calloc(20, sizeof(char));
        if(ret==((void *)0)) {
            fprintf(stderr, "Dynamic memory allocation failed\n");
            exit(1);
        }
        strncpy(ret, i->value, 20);
    }
    if(ret != ((void *)0)) {
        writeToFile(shardId, key, value, i->file_position);
        lst_insert_pos(invalids[shardId], file_position);
    }
    else {
        writeToFile(shardId, key, value, file_position);
    }
    destroy_item(i);
    return ret;
}


decompiled_code:
__int64 __fastcall kos_remove(unsigned int a1, unsigned int a2, __int64 a3)
{
__int64 v4; // rbx
__int64 v5; // r12

v4 = init_item();
write_item(v4, a1, a2, 3LL, a3, 0LL, 0LL, -1LL);
producer(v4);
v5 = *(_QWORD *)(v4 + 40);
*(_QWORD *)(v4 + 40) = 0LL;
lst_insert_pos(*(_QWORD *)(invalids + 8LL * (int)a2), *(unsigned int *)(v4 + 16));
destroy_item(v4);
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func6(unsigned int a1, unsigned int a2, __int64 a3)
{
__int64 v4; // rbx
__int64 v5; // r12

v4 = init_item();
write_item(v4, a1, a2, 3LL, a3, 0LL, 0LL, -1LL);
func3(v4);
v5 = *(_QWORD *)(v4 + 40);
*(_QWORD *)(v4 + 40) = 0LL;
lst_insert_pos(*(_QWORD *)(invalids + 8LL * (int)a2), *(unsigned int *)(v4 + 16));
destroy_item(v4);
return v5;
}

original_code:
char* kos_remove(int clientid, int shardId, char* key)
{
    char *ret = ((void *)0);
    item *i = ((void *)0);
    i = init_item();
    write_item(i, clientid, shardId, 3, key, ((void *)0), ((void *)0), -1);
    producer(i);
    ret = i->value;
    i->value = ((void *)0);
    lst_insert_pos(invalids[shardId], i->file_position);
    destroy_item(i);
    return ret;
}

canonical_original_code:
char *kos_remove(int clientid, int shardId, char *key)
{
    char *ret = ((void *)0);
    struct _item *i = ((void *)0);
    i = init_item();
    write_item(i, clientid, shardId, 3, key, ((void *)0), ((void *)0), -1);
    producer(i);
    ret = i->value;
    i->value = ((void *)0);
    lst_insert_pos(invalids[shardId], i->file_position);
    destroy_item(i);
    return ret;
}


decompiled_code:
__int64 __fastcall kos_getAllKeys(unsigned int a1, unsigned int a2, _DWORD *a3)
{
__int64 v4; // rbx
__int64 v5; // rbp

v4 = init_item();
write_item(v4, a1, a2, 4LL, 0LL, 0LL, 0LL, -1LL);
producer(v4);
*a3 = *(_DWORD *)(v4 + 8);
v5 = *(_QWORD *)(v4 + 48);
*(_QWORD *)(v4 + 48) = 0LL;
destroy_item(v4);
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func7(unsigned int a1, unsigned int a2, _DWORD *a3)
{
__int64 v4; // rbx
__int64 v5; // rbp

v4 = init_item();
write_item(v4, a1, a2, 4LL, 0LL, 0LL, 0LL, -1LL);
func3(v4);
*a3 = *(_DWORD *)(v4 + 8);
v5 = *(_QWORD *)(v4 + 48);
*(_QWORD *)(v4 + 48) = 0LL;
destroy_item(v4);
return v5;
}

original_code:
KV_t* kos_getAllKeys(int clientid, int shardId, int* dim)
{
    item *i = ((void *)0);
    KV_t *pair;
    i = init_item();
    write_item(i, clientid, shardId, 4, ((void *)0), ((void *)0), ((void *)0), -1);
    producer(i);
    *dim = i->dimension;
    pair = i->pair;
    i->pair = ((void *)0);
    destroy_item(i);
    return pair;
}

canonical_original_code:
struct KV_t *kos_getAllKeys(int clientid, int shardId, int *dim)
{
    struct _item *i = ((void *)0);
    struct KV_t *pair;
    i = init_item();
    write_item(i, clientid, shardId, 4, ((void *)0), ((void *)0), ((void *)0), -1);
    producer(i);
    *dim = i->dimension;
    pair = i->pair;
    i->pair = ((void *)0);
    destroy_item(i);
    return pair;
}

variable_types:
dim
int *

variable_types: struct KV_t { char key[20]; char value[20]; } *


decompiled_code:
__int64 __fastcall op_handler(__int64 a1)
{
__int64 result; // rax
__int64 v2; // rax
__int64 v3; // rax
__int64 v4; // rax

result = *(unsigned int *)(a1 + 12);
if ( (_DWORD)result == 3 )
{
v2 = ht_remove(*(_QWORD *)(shards + 8LL * *(int *)(a1 + 4)), a1 + 20);
if ( v2 )
return write_item(
a1,
0xFFFFFFFFLL,
0xFFFFFFFFLL,
0xFFFFFFFFLL,
0LL,
*(_QWORD *)v2,
0LL,
*(unsigned int *)(v2 + 8));
return write_item(a1, 0xFFFFFFFFLL, 0xFFFFFFFFLL, 0xFFFFFFFFLL, 0LL, 0LL, 0LL, -1LL);
}
if ( (int)result > 3 )
{
if ( (_DWORD)result == 4 )
{
v3 = getAllKeys(*(_QWORD *)(shards + 8LL * *(int *)(a1 + 4)), a1 + 8);
result = write_item(a1, 0xFFFFFFFFLL, 0xFFFFFFFFLL, 0xFFFFFFFFLL, 0LL, 0LL, v3, -1LL);
}
}
else if ( (_DWORD)result == 1 )
{
v4 = add(*(_QWORD *)(shards + 8LL * *(int *)(a1 + 4)));
result = write_item(
a1,
0xFFFFFFFFLL,
0xFFFFFFFFLL,
0xFFFFFFFFLL,
0LL,
*(_QWORD *)v4,
0LL,
*(unsigned int *)(v4 + 8));
}
else if ( (_DWORD)result == 2 )
{
v2 = get(*(_QWORD *)(shards + 8LL * *(int *)(a1 + 4)), a1 + 20);
if ( v2 )
return write_item(
a1,
0xFFFFFFFFLL,
0xFFFFFFFFLL,
0xFFFFFFFFLL,
0LL,
*(_QWORD *)v2,
0LL,
*(unsigned int *)(v2 + 8));
return write_item(a1, 0xFFFFFFFFLL, 0xFFFFFFFFLL, 0xFFFFFFFFLL, 0LL, 0LL, 0LL, -1LL);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1)
{
__int64 result; // rax
__int64 v2; // rax
__int64 v3; // rax
__int64 v4; // rax

result = *(unsigned int *)(a1 + 12);
if ( (_DWORD)result == 3 )
{
v2 = ht_remove(*(_QWORD *)(shards + 8LL * *(int *)(a1 + 4)), a1 + 20);
if ( v2 )
return write_item(
a1,
0xFFFFFFFFLL,
0xFFFFFFFFLL,
0xFFFFFFFFLL,
0LL,
*(_QWORD *)v2,
0LL,
*(unsigned int *)(v2 + 8));
return write_item(a1, 0xFFFFFFFFLL, 0xFFFFFFFFLL, 0xFFFFFFFFLL, 0LL, 0LL, 0LL, -1LL);
}
if ( (int)result > 3 )
{
if ( (_DWORD)result == 4 )
{
v3 = getAllKeys(*(_QWORD *)(shards + 8LL * *(int *)(a1 + 4)), a1 + 8);
result = write_item(a1, 0xFFFFFFFFLL, 0xFFFFFFFFLL, 0xFFFFFFFFLL, 0LL, 0LL, v3, -1LL);
}
}
else if ( (_DWORD)result == 1 )
{
v4 = add(*(_QWORD *)(shards + 8LL * *(int *)(a1 + 4)));
result = write_item(
a1,
0xFFFFFFFFLL,
0xFFFFFFFFLL,
0xFFFFFFFFLL,
0LL,
*(_QWORD *)v4,
0LL,
*(unsigned int *)(v4 + 8));
}
else if ( (_DWORD)result == 2 )
{
v2 = get(*(_QWORD *)(shards + 8LL * *(int *)(a1 + 4)), a1 + 20);
if ( v2 )
return write_item(
a1,
0xFFFFFFFFLL,
0xFFFFFFFFLL,
0xFFFFFFFFLL,
0LL,
*(_QWORD *)v2,
0LL,
*(unsigned int *)(v2 + 8));
return write_item(a1, 0xFFFFFFFFLL, 0xFFFFFFFFLL, 0xFFFFFFFFLL, 0LL, 0LL, 0LL, -1LL);
}
return result;
}

original_code:
void op_handler(item *i)
{
    lst_ret_t *oldvalue = ((void *)0);
    KV_t *pair = ((void *)0);
        switch(i->op) {
            case 1:
                oldvalue = add(shards[i->shardID], i->key, i->value, i->file_position);
                write_item(i, -1, -1, -1, ((void *)0), oldvalue->value, ((void *)0), oldvalue->position);
                break;
            case 3:
                oldvalue = ht_remove(shards[i->shardID], i->key);
                if(oldvalue == ((void *)0)) {
                    write_item(i, -1, -1, -1, ((void *)0), ((void *)0), ((void *)0), -1);
                }
                else {
                    write_item(i, -1, -1, -1, ((void *)0), oldvalue->value, ((void *)0), oldvalue->position);
                }
                break;
            case 2:
                oldvalue = get(shards[i->shardID], i->key);
                if(oldvalue == ((void *)0)) {
                    write_item(i, -1, -1, -1, ((void *)0), ((void *)0), ((void *)0), -1);
                }
                else {
                    write_item(i, -1, -1, -1, ((void *)0), oldvalue->value, ((void *)0), oldvalue->position);
                }
                break;
            case 4:
                pair = getAllKeys(shards[i->shardID], &(i->dimension));
                write_item(i, -1, -1, -1, ((void *)0), ((void *)0), pair, -1);
                break;
            default:
                break;
        }
}

canonical_original_code:
void op_handler(struct _item *i)
{
    struct lst_ret_t *oldvalue = ((void *)0);
    struct KV_t *pair = ((void *)0);
        switch(i->op) {
            case 1:
                oldvalue = add(shards[i->shardID], i->key, i->value, i->file_position);
                write_item(i, -1, -1, -1, ((void *)0), oldvalue->value, ((void *)0), oldvalue->position);
                break;
            case 3:
                oldvalue = ht_remove(shards[i->shardID], i->key);
                if(oldvalue == ((void *)0)) {
                    write_item(i, -1, -1, -1, ((void *)0), ((void *)0), ((void *)0), -1);
                }
                else {
                    write_item(i, -1, -1, -1, ((void *)0), oldvalue->value, ((void *)0), oldvalue->position);
                }
                break;
            case 2:
                oldvalue = get(shards[i->shardID], i->key);
                if(oldvalue == ((void *)0)) {
                    write_item(i, -1, -1, -1, ((void *)0), ((void *)0), ((void *)0), -1);
                }
                else {
                    write_item(i, -1, -1, -1, ((void *)0), oldvalue->value, ((void *)0), oldvalue->position);
                }
                break;
            case 4:
                pair = getAllKeys(shards[i->shardID], &(i->dimension));
                write_item(i, -1, -1, -1, ((void *)0), ((void *)0), pair, -1);
                break;
            default:
                break;
        }
}

variable_types: struct _item { int clientID; int shardID; int dimension; int op; int file_position; char key[20]; char *value; struct KV_t { char key[20]; char value[20]; } *pair; union sem_t { char __size[32]; long __align; } waiting; } *

variable_types: struct lst_ret_t { char *value; int position; } *


consumer

decompiled_code:
int consumer()
{
int v0; // ecx
__int64 *v1; // rax
__int64 v2; // rbx

sem_wait(&semCanCons);
pthread_mutex_lock(&mutex);
v0 = index_consumer++;
index_consumer %= *(_DWORD *)b;
v1 = (__int64 *)(*(_QWORD *)(b + 8) + 8LL * v0);
v2 = *v1;
*v1 = 0LL;
pthread_mutex_unlock(&mutex);
sem_post(&semCanProd);
op_handler(v2);
return sem_post((sem_t *)(v2 + 56));
}

canonical_decompiled_code:
int func9()
{
int v0; // ecx
__int64 *v1; // rax
__int64 v2; // rbx

sem_wait(&semCanCons);
pthread_mutex_lock(&mutex);
v0 = index_consumer++;
index_consumer %= *(_DWORD *)b;
v1 = (__int64 *)(*(_QWORD *)(b + 8) + 8LL * v0);
v2 = *v1;
*v1 = 0LL;
pthread_mutex_unlock(&mutex);
sem_post(&semCanProd);
func8(v2);
return sem_post((sem_t *)(v2 + 56));
}

original_code:
void consumer()
{
    int pos;
    item *i = ((void *)0);
    sem_wait(&semCanCons);
    pthread_mutex_lock(&mutex);
    pos = index_consumer++;
    index_consumer %= b->size;
    i = b->items[pos];
    b->items[pos] = ((void *)0);
    pthread_mutex_unlock(&mutex);
    sem_post(&semCanProd);
    op_handler(i);
    sem_post(&(i->waiting));
}

canonical_original_code:
void consumer()
{
    int pos;
    struct _item *i = ((void *)0);
    sem_wait(&semCanCons);
    pthread_mutex_lock(&mutex);
    pos = index_consumer++;
    index_consumer %= b->size;
    i = b->items[pos];
    b->items[pos] = ((void *)0);
    pthread_mutex_unlock(&mutex);
    sem_post(&semCanProd);
    op_handler(i);
    sem_post(&(i->waiting));
}


decompiled_code:
void __fastcall __noreturn server_thread(void *a1)
{
while ( 1 )
consumer();
}

canonical_decompiled_code:
void __fastcall __noreturn func10(void *a1)
{
while ( 1 )
func9();
}

original_code:
void *server_thread(void *arg)
{
    while(1) {
        consumer();
    }
}

variable_types:
arg
void *

return_type: void *


decompiled_code:
_DWORD *lst_new()
{
_DWORD *result; // rax

result = malloc(0x10uLL);
*(_QWORD *)result = 0LL;
result[2] = 0;
return result;
}

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

result = malloc(0x10uLL);
*(_QWORD *)result = 0LL;
result[2] = 0;
return result;
}

original_code:
list_t* lst_new()
{
   list_t *list;
   list = (list_t*) malloc(sizeof(list_t));
   list->first = ((void *)0);
   list->size = 0;
   return list;
}

canonical_original_code:
struct list_t *lst_new()
{
   struct list_t *list;
   list = (struct list_t *) malloc(sizeof(list_t));
   list->first = ((void *)0);
   list->size = 0;
   return list;
}

variable_types: struct list_t { struct lst_iitem { struct KV_t { char key[20]; char value[20]; } *item; int file_position; struct lst_iitem *next; } *first; int size; } *

user_defined_types: struct list_t { struct lst_iitem *first; int size; }

user_defined_types: struct lst_iitem { struct KV_t *item; int file_position; struct lst_iitem *next; }


decompiled_code:
void __fastcall lst_destroy(void *ptr)
{
void **v1; // rax
void **i; // rbx

v1 = *(void ***)ptr;
if ( *(_QWORD *)ptr )
{
for ( i = (void **)v1[2]; ; i = (void **)i[2] )
{
free(*v1);
free(*(void **)ptr);
*(_QWORD *)ptr = i;
if ( !i )
break;
v1 = i;
}
}
free(ptr);
}

canonical_decompiled_code:
void __fastcall func1(void *ptr)
{
void **v1; // rax
void **i; // rbx

v1 = *(void ***)ptr;
if ( *(_QWORD *)ptr )
{
for ( i = (void **)v1[2]; ; i = (void **)i[2] )
{
free(*v1);
free(*(void **)ptr);
*(_QWORD *)ptr = i;
if ( !i )
break;
v1 = i;
}
}
free(ptr);
}

original_code:
void lst_destroy(list_t *list)
{
    if(list->first != ((void *)0)) {
        lst_iitem_t *tempA;
        tempA = list->first->next;
        while(list->first != ((void *)0)) {
            free(list->first->item);
            free(list->first);
            list->first = tempA;
            if(tempA != ((void *)0)) {
                tempA = list->first->next;
            }
        }
    }
    free(list);
}

canonical_original_code:
void lst_destroy(struct list_t *list)
{
    if(list->first != ((void *)0)) {
        struct lst_iitem *tempA;
        tempA = list->first->next;
        while(list->first != ((void *)0)) {
            free(list->first->item);
            free(list->first);
            list->first = tempA;
            if(tempA != ((void *)0)) {
                tempA = list->first->next;
            }
        }
    }
    free(list);
}

variable_types: struct lst_iitem { struct KV_t { char key[20]; char value[20]; } *item; int file_position; struct lst_iitem *next; } *


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

if ( !a1 )
return 0LL;
v2 = calloc(1uLL, 0x18uLL);
if ( !v2 )
{
fwrite("\ndynamic memory allocation failed\n", 1uLL, 0x22uLL, stderr);
exit(1);
}
v2[2] = a2;
*((_QWORD *)v2 + 2) = *(_QWORD *)a1;
*(_QWORD *)a1 = v2;
++*(_DWORD *)(a1 + 8);
return 0LL;
}

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

if ( !a1 )
return 0LL;
v2 = calloc(1uLL, 0x18uLL);
if ( !v2 )
{
fwrite("\ndynamic memory allocation failed\n", 1uLL, 0x22uLL, stderr);
exit(1);
}
v2[2] = a2;
*((_QWORD *)v2 + 2) = *(_QWORD *)a1;
*(_QWORD *)a1 = v2;
++*(_DWORD *)(a1 + 8);
return 0LL;
}

original_code:
int lst_insert_pos(list_t *list, int file_position)
{
    if(list != ((void *)0)) {
        lst_iitem_t* item = ((void *)0);
        item = calloc(1, sizeof(lst_iitem_t));
        if(item==((void *)0)) {
            fprintf(stderr, "\ndynamic memory allocation failed\n");
            exit(1);
        }
        item->item = ((void *)0);
        item->file_position = file_position;
        item->next = list->first;
        list->first = item;
        list->size += 1;
    }
    return 0;
}

canonical_original_code:
int lst_insert_pos(struct list_t *list, int file_position)
{
    if(list != ((void *)0)) {
        struct lst_iitem *item = ((void *)0);
        item = calloc(1, sizeof(lst_iitem_t));
        if(item==((void *)0)) {
            fprintf(stderr, "\ndynamic memory allocation failed\n");
            exit(1);
        }
        item->item = ((void *)0);
        item->file_position = file_position;
        item->next = list->first;
        list->first = item;
        list->size += 1;
    }
    return 0;
}


decompiled_code:
__int64 __fastcall lst_remove_pos(__int64 *a1)
{
unsigned int v1; // ebp
__int64 v3; // rdi

if ( !a1 )
return v1;
v3 = *a1;
if ( v3 )
{
v1 = *(_DWORD *)(v3 + 8);
*a1 = *(_QWORD *)(v3 + 16);
free((void *)v3);
--*((_DWORD *)a1 + 2);
}
return v1;
}

original_code:
int lst_remove_pos(list_t *list)
{
    int ret;
    lst_iitem_t *iterA = ((void *)0), *iterB = ((void *)0);
    if(list != ((void *)0)) {
        iterA = list->first;
        if(iterA != ((void *)0)) {
            ret = iterA->file_position;
            iterB = iterA->next;
            list->first = iterB;
            free(iterA);
            list->size -= 1;
        }
    }
    return ret;
}

canonical_original_code:
int lst_remove_pos(struct list_t *list)
{
    int ret;
    struct lst_iitem *iterA = ((void *)0); struct lst_iitem *iterB = ((void *)0);
    if(list != ((void *)0)) {
        iterA = list->first;
        if(iterA != ((void *)0)) {
            ret = iterA->file_position;
            iterB = iterA->next;
            list->first = iterB;
            free(iterA);
            list->size -= 1;
        }
    }
    return ret;
}

variable_types: ret int


decompiled_code:
int __fastcall lst_print(__int64 *a1)
{
__int64 i; // rbx
int result; // eax

for ( i = *a1; i; i = *(_QWORD *)(i + 16) )
result = printf("key: %s, value: %s\n", *(const char **)i, (const char *)(*(_QWORD *)i + 20LL));
return result;
}

canonical_decompiled_code:
int __fastcall func4(__int64 *a1)
{
__int64 i; // rbx
int result; // eax

for ( i = *a1; i; i = *(_QWORD *)(i + 16) )
result = printf("key: %s, value: %s\n", *(const char **)i, (const char *)(*(_QWORD *)i + 20LL));
return result;
}

original_code:
void lst_print(list_t *list)
{
    lst_iitem_t *temp;
    for(temp = list->first; temp != ((void *)0); temp = temp->next) {
        printf("key: %s, value: %s\n", temp->item->key, temp->item->value);
    }
}

canonical_original_code:
void lst_print(struct list_t *list)
{
    struct lst_iitem *temp;
    for(temp = list->first; temp != ((void *)0); temp = temp->next) {
        printf("key: %s, value: %s\n", temp->item->key, temp->item->value);
    }
}


decompiled_code:
__int64 __fastcall lst_size(__int64 a1)
{
return *(unsigned int *)(a1 + 8);
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1)
{
return *(unsigned int *)(a1 + 8);
}

original_code:
int lst_size(list_t *list)
{
    return list->size;
}

canonical_original_code:
int lst_size(struct list_t *list)
{
    return list->size;
}


decompiled_code:
__int64 __fastcall delete_hashtable(void *ptr)
{
int v1; // er13
int v2; // er14
pthread_rwlock_t *v3; // r12
int v4; // ebx
__int64 v5; // rbx

if ( !ptr )
return 0LL;
v1 = *(_DWORD *)ptr;
v2 = *(_DWORD *)ptr - 1;
if ( *(int *)ptr > 0 )
{
v3 = (pthread_rwlock_t *)((char *)ptr + 16);
v4 = 0;
do
{
pthread_rwlock_destroy(v3);
++v4;
++v3;
}
while ( *(_DWORD *)ptr > v4 );
}
v5 = 8LL * v2;
do
{
lst_destroy(*(_QWORD *)(*((_QWORD *)ptr + 1) + v5));
v5 -= 8LL;
}
while ( v5 != 8 * (v1 - (unsigned __int64)(unsigned int)(v1 - 1)) - 16 );
free(*((void **)ptr + 1));
free(ptr);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(void *ptr)
{
int v1; // er13
int v2; // er14
pthread_rwlock_t *v3; // r12
int v4; // ebx
__int64 v5; // rbx

if ( !ptr )
return 0LL;
v1 = *(_DWORD *)ptr;
v2 = *(_DWORD *)ptr - 1;
if ( *(int *)ptr > 0 )
{
v3 = (pthread_rwlock_t *)((char *)ptr + 16);
v4 = 0;
do
{
pthread_rwlock_destroy(v3);
++v4;
++v3;
}
while ( *(_DWORD *)ptr > v4 );
}
v5 = 8LL * v2;
do
{
lst_destroy(*(_QWORD *)(*((_QWORD *)ptr + 1) + v5));
v5 -= 8LL;
}
while ( v5 != 8 * (v1 - (unsigned __int64)(unsigned int)(v1 - 1)) - 16 );
free(*((void **)ptr + 1));
free(ptr);
return 0LL;
}

original_code:
int delete_hashtable(hashtable *h)
{
    if(h != ((void *)0)) {
        int size = h->size, ix;
        --size;
        for(ix = 0; ix < h->size; ix += 1) {
            pthread_rwlock_destroy(&(h->rwlock[ix]));
        }
        do {
            lst_destroy(h->lists[size]);
        } while(size--);
        free(h->lists);
        h->lists = ((void *)0);
        free(h);
        h = ((void *)0);
    }
    return 0;
}

canonical_original_code:
int delete_hashtable(struct hashtable *h)
{
    if(h != ((void *)0)) {
        int size = h->size; int ix;
        --size;
        for(ix = 0; ix < h->size; ix += 1) {
            pthread_rwlock_destroy(&(h->rwlock[ix]));
        }
        do {
            lst_destroy(h->lists[size]);
        } while(size--);
        free(h->lists);
        h->lists = ((void *)0);
        free(h);
        h = ((void *)0);
    }
    return 0;
}

variable_types: struct hashtable { int size; struct list_t { struct lst_iitem { struct KV_t { char key[20]; char value[20]; } *item; int file_position; struct lst_iitem *next; } *first; int size; } **lists; union pthread_rwlock_t { struct __pthread_rwlock_arch_t { unsigned int __readers; unsigned int __writers; unsigned int __wrphase_futex; unsigned int __writers_futex; unsigned int __pad3; unsigned int __pad4; int __cur_writer; int __shared; char __rwelision; unsigned char __pad1[7]; unsigned long __pad2; unsigned int __flags; } __data; char __size[56]; long __align; } rwlock[10]; } *

variable_types: size int

variable_types: ix int

user_defined_types: struct hashtable { int size; struct list_t **lists; union pthread_rwlock_t rwlock[10]; }

user_defined_types: union pthread_rwlock_t { struct __pthread_rwlock_arch_t __data; char __size[56]; long __align; }


hash

decompiled_code:
__int64 __fastcall hash(char *a1)
{
char v1; // al
int v2; // edx

if ( !a1 )
return 0xFFFFFFFFLL;
v1 = *a1;
if ( *a1 )
{
v2 = 0;
do
{
v2 += v1;
v1 = *++a1;
}
while ( *a1 );
}
else
{
v2 = 0;
}
return (unsigned int)(v2 % 10);
}

canonical_decompiled_code:
__int64 __fastcall func1(char *a1)
{
char v1; // al
int v2; // edx

if ( !a1 )
return 0xFFFFFFFFLL;
v1 = *a1;
if ( *a1 )
{
v2 = 0;
do
{
v2 += v1;
v1 = *++a1;
}
while ( *a1 );
}
else
{
v2 = 0;
}
return (unsigned int)(v2 % 10);
}

original_code:
int hash(char* key) {
    int i=0;
    if (key == ((void *)0))
        return -1;
    while (*key != '\0') {
        i+=(int) *key;
        key++;
    }
    i=i % 10;
    return i;
}

canonical_original_code:
int hash(char *key) {
    int i = 0;
    if (key == ((void *)0))
        return -1;
    while (*key != '\0') {
        i+=(int) *key;
        key++;
    }
    i=i % 10;
    return i;
}

variable_types:
key
char *

variable_types: i int


get

decompiled_code:
__int64 __fastcall get(__int64 a1, char *a2)
{
__int64 v2; // r12
__int64 v3; // rbx

if ( a1 && a2 )
{
v2 = (int)hash(a2);
pthread_rwlock_rdlock((pthread_rwlock_t *)(a1 + 56 * v2 + 16));
v3 = lst_get(*(_QWORD *)(*(_QWORD *)(a1 + 8) + 8 * v2), a2);
pthread_rwlock_unlock((pthread_rwlock_t *)(a1 + 56 * v2 + 16));
}
else
{
puts("error: received NULL pointer");
v3 = 0LL;
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, char *a2)
{
__int64 v2; // r12
__int64 v3; // rbx

if ( a1 && a2 )
{
v2 = (int)func1(a2);
pthread_rwlock_rdlock((pthread_rwlock_t *)(a1 + 56 * v2 + 16));
v3 = lst_get(*(_QWORD *)(*(_QWORD *)(a1 + 8) + 8 * v2), a2);
pthread_rwlock_unlock((pthread_rwlock_t *)(a1 + 56 * v2 + 16));
}
else
{
puts("error: received NULL pointer");
v3 = 0LL;
}
return v3;
}

original_code:
lst_ret_t *get(hashtable *h, char *key)
{
    int bucket;
    lst_ret_t* value = ((void *)0);
    if((h != ((void *)0)) && (key != ((void *)0))) {
        bucket = hash(key);
        pthread_rwlock_rdlock(&h->rwlock[bucket]);
        value = lst_get(h->lists[bucket], key);
        pthread_rwlock_unlock(&h->rwlock[bucket]);
    }
    else {
        puts("error: received NULL pointer");
    }
    return value;
}

canonical_original_code:
struct lst_ret_t *get(struct hashtable *h, char *key)
{
    int bucket;
    struct lst_ret_t *value = ((void *)0);
    if((h != ((void *)0)) && (key != ((void *)0))) {
        bucket = hash(key);
        pthread_rwlock_rdlock(&h->rwlock[bucket]);
        value = lst_get(h->lists[bucket], key);
        pthread_rwlock_unlock(&h->rwlock[bucket]);
    }
    else {
        puts("error: received NULL pointer");
    }
    return value;
}

variable_types: bucket int

return_type: struct lst_ret_t { char *value; int position; } *

user_defined_types: struct __pthread_rwlock_arch_t { unsigned int __readers; unsigned int __writers; unsigned int __wrphase_futex; unsigned int __writers_futex; unsigned int __pad3; unsigned int __pad4; int __cur_writer; int __shared; char __rwelision; unsigned char __pad1[7]; unsigned long __pad2; unsigned int __flags; }


decompiled_code:
__int64 __fastcall ht_remove(__int64 a1, char *a2)
{
__int64 v2; // r12
__int64 v3; // rbx

if ( a1 && a2 )
{
v2 = (int)hash(a2);
pthread_rwlock_wrlock((pthread_rwlock_t *)(a1 + 56 * v2 + 16));
v3 = lst_remove(*(_QWORD *)(*(_QWORD *)(a1 + 8) + 8 * v2), a2);
pthread_rwlock_unlock((pthread_rwlock_t *)(a1 + 56 * v2 + 16));
}
else
{
puts("error: received NULL pointer");
v3 = 0LL;
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, char *a2)
{
__int64 v2; // r12
__int64 v3; // rbx

if ( a1 && a2 )
{
v2 = (int)func1(a2);
pthread_rwlock_wrlock((pthread_rwlock_t *)(a1 + 56 * v2 + 16));
v3 = lst_remove(*(_QWORD *)(*(_QWORD *)(a1 + 8) + 8 * v2), a2);
pthread_rwlock_unlock((pthread_rwlock_t *)(a1 + 56 * v2 + 16));
}
else
{
puts("error: received NULL pointer");
v3 = 0LL;
}
return v3;
}

original_code:
lst_ret_t *ht_remove(hashtable *h, char *key)
{
    int bucket;
    lst_ret_t *ret = ((void *)0);
    if((h != ((void *)0)) && (key != ((void *)0))) {
        bucket = hash(key);
        pthread_rwlock_wrlock(&h->rwlock[bucket]);
        ret = lst_remove(h->lists[bucket], key);
        pthread_rwlock_unlock(&h->rwlock[bucket]);
    }
    else {
        puts("error: received NULL pointer");
    }
    return ret;
}

canonical_original_code:
struct lst_ret_t *ht_remove(struct hashtable *h, char *key)
{
    int bucket;
    struct lst_ret_t *ret = ((void *)0);
    if((h != ((void *)0)) && (key != ((void *)0))) {
        bucket = hash(key);
        pthread_rwlock_wrlock(&h->rwlock[bucket]);
        ret = lst_remove(h->lists[bucket], key);
        pthread_rwlock_unlock(&h->rwlock[bucket]);
    }
    else {
        puts("error: received NULL pointer");
    }
    return ret;
}

user_defined_types: struct lst_ret_t { char *value; int position; }


add

decompiled_code:
__int64 __fastcall add(__int64 a1, char *a2, __int64 a3, unsigned int a4)
{
__int64 v6; // r12
__int64 v7; // rbx

if ( a1 && a2 )
{
v6 = (int)hash(a2);
pthread_rwlock_wrlock((pthread_rwlock_t *)(a1 + 56 * v6 + 16));
v7 = lst_insert(*(_QWORD *)(*(_QWORD *)(a1 + 8) + 8 * v6), a2, a3, a4);
pthread_rwlock_unlock((pthread_rwlock_t *)(a1 + 56 * v6 + 16));
}
else
{
puts("error: received NULL pointer");
v7 = 0LL;
}
return v7;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, char *a2, __int64 a3, unsigned int a4)
{
__int64 v6; // r12
__int64 v7; // rbx

if ( a1 && a2 )
{
v6 = (int)func1(a2);
pthread_rwlock_wrlock((pthread_rwlock_t *)(a1 + 56 * v6 + 16));
v7 = lst_insert(*(_QWORD *)(*(_QWORD *)(a1 + 8) + 8 * v6), a2, a3, a4);
pthread_rwlock_unlock((pthread_rwlock_t *)(a1 + 56 * v6 + 16));
}
else
{
puts("error: received NULL pointer");
v7 = 0LL;
}
return v7;
}

original_code:
lst_ret_t *add(hashtable *h, char *key, char *value, int file_position)
{
    int bucket;
    lst_ret_t *ret = ((void *)0);
    if((h != ((void *)0)) && (key != ((void *)0))) {
        bucket = hash(key);
        pthread_rwlock_wrlock(&h->rwlock[bucket]);
        ret = lst_insert(h->lists[bucket], key, value, file_position);
        pthread_rwlock_unlock(&h->rwlock[bucket]);
    }
    else {
        puts("error: received NULL pointer");
    }
    return ret;
}

canonical_original_code:
struct lst_ret_t *add(struct hashtable *h, char *key, char *value, int file_position)
{
    int bucket;
    struct lst_ret_t *ret = ((void *)0);
    if((h != ((void *)0)) && (key != ((void *)0))) {
        bucket = hash(key);
        pthread_rwlock_wrlock(&h->rwlock[bucket]);
        ret = lst_insert(h->lists[bucket], key, value, file_position);
        pthread_rwlock_unlock(&h->rwlock[bucket]);
    }
    else {
        puts("error: received NULL pointer");
    }
    return ret;
}

variable_types:
value
char *


getAllKeys

decompiled_code:
char *__fastcall getAllKeys(__int64 a1, _DWORD *a2)
{
pthread_rwlock_t *v2; // rbp
__int64 v3; // rbx
__int64 v4; // r15
int i; // er12
__int64 v7; // rbx
char *v8; // rbp
pthread_rwlock_t *rwlock; // [rsp+0h] [rbp-58h]
int v10; // [rsp+Ch] [rbp-4Ch]
char *v11; // [rsp+10h] [rbp-48h]

if ( !a1 )
return 0LL;
if ( *(int *)a1 <= 0 )
{
v10 = 0;
}
else
{
v2 = (pthread_rwlock_t *)(a1 + 16);
v3 = 0LL;
v10 = 0;
do
{
pthread_rwlock_rdlock(v2);
v10 += lst_size(*(_QWORD *)(*(_QWORD *)(a1 + 8) + 8 * v3));
pthread_rwlock_unlock(v2);
++v3;
++v2;
}
while ( *(_DWORD *)a1 > (int)v3 );
}
v11 = (char *)calloc(v10, 0x28uLL);
if ( !v11 )
{
fwrite("Dynamic memory allocation failed\n", 1uLL, 0x21uLL, stderr);
exit(1);
}
rwlock = (pthread_rwlock_t *)(a1 + 16);
v4 = 0LL;
for ( i = 0; *(_DWORD *)a1 > (int)v4; ++rwlock )
{
v7 = **(_QWORD **)(*(_QWORD *)(a1 + 8) + 8 * v4);
if ( v7 )
{
v8 = &v11[40 * i];
do
{
pthread_rwlock_rdlock(rwlock);
strncpy(v8, *(const char **)v7, 0x14uLL);
strncpy(v8 + 20, (const char *)(*(_QWORD *)v7 + 20LL), 0x14uLL);
pthread_rwlock_unlock(rwlock);
++i;
v7 = *(_QWORD *)(v7 + 16);
v8 += 40;
}
while ( v7 );
}
++v4;
}
*a2 = v10;
return v11;
}

canonical_decompiled_code:
char *__fastcall func5(__int64 a1, _DWORD *a2)
{
pthread_rwlock_t *v2; // rbp
__int64 v3; // rbx
__int64 v4; // r15
int i; // er12
__int64 v7; // rbx
char *v8; // rbp
pthread_rwlock_t *rwlock; // [rsp+0h] [rbp-58h]
int v10; // [rsp+Ch] [rbp-4Ch]
char *v11; // [rsp+10h] [rbp-48h]

if ( !a1 )
return 0LL;
if ( *(int *)a1 <= 0 )
{
v10 = 0;
}
else
{
v2 = (pthread_rwlock_t *)(a1 + 16);
v3 = 0LL;
v10 = 0;
do
{
pthread_rwlock_rdlock(v2);
v10 += lst_size(*(_QWORD *)(*(_QWORD *)(a1 + 8) + 8 * v3));
pthread_rwlock_unlock(v2);
++v3;
++v2;
}
while ( *(_DWORD *)a1 > (int)v3 );
}
v11 = (char *)calloc(v10, 0x28uLL);
if ( !v11 )
{
fwrite("Dynamic memory allocation failed\n", 1uLL, 0x21uLL, stderr);
exit(1);
}
rwlock = (pthread_rwlock_t *)(a1 + 16);
v4 = 0LL;
for ( i = 0; *(_DWORD *)a1 > (int)v4; ++rwlock )
{
v7 = **(_QWORD **)(*(_QWORD *)(a1 + 8) + 8 * v4);
if ( v7 )
{
v8 = &v11[40 * i];
do
{
pthread_rwlock_rdlock(rwlock);
strncpy(v8, *(const char **)v7, 0x14uLL);
strncpy(v8 + 20, (const char *)(*(_QWORD *)v7 + 20LL), 0x14uLL);
pthread_rwlock_unlock(rwlock);
++i;
v7 = *(_QWORD *)(v7 + 16);
v8 += 40;
}
while ( v7 );
}
++v4;
}
*a2 = v10;
return v11;
}

original_code:
KV_t* getAllKeys(hashtable *h, int* dim)
{
    if(h != ((void *)0)) {
        KV_t* pairs = ((void *)0);
        lst_iitem_t *lst_it = ((void *)0);
        int counter = 0, ix, jx;
        for(ix = 0; ix < h->size; ix += 1) {
            pthread_rwlock_rdlock(&h->rwlock[ix]);
            counter += lst_size(h->lists[ix]);
            pthread_rwlock_unlock(&h->rwlock[ix]);
        }
        pairs = calloc((size_t) counter, sizeof(KV_t));
        if(pairs==((void *)0)) {
            fprintf(stderr, "Dynamic memory allocation failed\n");
            exit(1);
        }
        for(ix = 0, jx = 0; ix < h->size; ix += 1) {
            for(lst_it = h->lists[ix]->first; lst_it != ((void *)0); ++jx, lst_it = lst_it->next) {
                pthread_rwlock_rdlock(&h->rwlock[ix]);
                strncpy(pairs[jx].key, lst_it->item->key, 20);
                strncpy(pairs[jx].value, lst_it->item->value, 20);
                pthread_rwlock_unlock(&h->rwlock[ix]);
            }
        }
        *dim = counter;
        return pairs;
    }
    return ((void *)0);
}

canonical_original_code:
struct KV_t *getAllKeys(struct hashtable *h, int *dim)
{
    if(h != ((void *)0)) {
        struct KV_t *pairs = ((void *)0);
        struct lst_iitem *lst_it = ((void *)0);
        int counter = 0; int ix; int jx;
        for(ix = 0; ix < h->size; ix += 1) {
            pthread_rwlock_rdlock(&h->rwlock[ix]);
            counter += lst_size(h->lists[ix]);
            pthread_rwlock_unlock(&h->rwlock[ix]);
        }
        pairs = calloc((unsigned long) counter, sizeof(KV_t));
        if(pairs==((void *)0)) {
            fprintf(stderr, "Dynamic memory allocation failed\n");
            exit(1);
        }
        for(ix = 0, jx = 0; ix < h->size; ix += 1) {
            for(lst_it = h->lists[ix]->first; lst_it != ((void *)0); ++jx, lst_it = lst_it->next) {
                pthread_rwlock_rdlock(&h->rwlock[ix]);
                strncpy(pairs[jx].key, lst_it->item->key, 20);
                strncpy(pairs[jx].value, lst_it->item->value, 20);
                pthread_rwlock_unlock(&h->rwlock[ix]);
            }
        }
        *dim = counter;
        return pairs;
    }
    return ((void *)0);
}

variable_types: struct hashtable { int size; struct list_t { struct lst_iitem { struct KV_t *item; int file_position; struct lst_iitem *next; } *first; int size; } **lists; union pthread_rwlock_t { struct __pthread_rwlock_arch_t { unsigned int __readers; unsigned int __writers; unsigned int __wrphase_futex; unsigned int __writers_futex; unsigned int __pad3; unsigned int __pad4; int __cur_writer; int __shared; char __rwelision; unsigned char __pad1[7]; unsigned long __pad2; unsigned int __flags; } __data; char __size[56]; long __align; } rwlock[10]; } *

variable_types: counter int

variable_types: jx int

return_type: struct KV_t { char key[20]; char value[20]; } *


delay

decompiled_code:
unsigned int delay()
{
return sleep(1u);
}

canonical_decompiled_code:
unsigned int func0()
{
return sleep(1u);
}

original_code:
void delay() {
  sleep(1);
}

canonical_original_code:
void delay() {
  sleep(1);
}


crearColaP

repo: zeroscarface/Simulacion-Con-Sockets

decompiled_code:
_DWORD *crearColaP()
{
_DWORD *result; // rax

result = malloc(0x10uLL);
*(_QWORD *)result = 0LL;
result[2] = 0;
return result;
}

original_code:
ColaP* crearColaP(){
 ColaP* cp;
 if((cp = (ColaP*)malloc(sizeof(ColaP))) < 0){
  perror("error al pedir memoria");
  exit(1);
 }
 cp->pri = ((void *)0);
 cp->tam = 0;
 return cp;
}

canonical_original_code:
struct colaP *crearColaP(){
 struct colaP *cp;
 if((cp = (struct colaP *)malloc(sizeof(ColaP))) < 0){
  perror("error al pedir memoria");
  exit(1);
 }
 cp->pri = ((void *)0);
 cp->tam = 0;
 return cp;
}

variable_types: struct colaP { struct nodo { struct nodo *sig; struct nodo *ant; int prior; char *info; } *pri; int tam; } *

user_defined_types: struct colaP { struct nodo *pri; int tam; }


agregarElemP

decompiled_code:
unsigned __int64 __fastcall agregarElemP(__int64 a1, __int64 a2, int a3)
{
unsigned __int64 result; // rax
_QWORD *v6; // rsi
int v7; // ecx
_QWORD *v8; // rdi
int v9; // edx
_QWORD *v10; // rdx
_QWORD *v11; // rdx

result = (unsigned __int64)crearNodo(a2, a3);
v6 = (_QWORD *)result;
v7 = *(_DWORD *)(a1 + 8);
if ( !v7 )
{
*(_QWORD *)a1 = result;
*(_DWORD *)(a1 + 8) = 1;
return result;
}
v8 = *(_QWORD **)a1;
result = *(_QWORD *)a1;
v9 = 0;
if ( v7 > 0 )
{
while ( *(_DWORD *)(result + 16) < a3 )
{
result = *(_QWORD *)result;
if ( v7 == ++v9 )
{
if ( result )
goto LABEL_6;
result = 0LL;
while ( 1 )
{
v11 = v8;
v8 = (_QWORD *)*v8;
if ( !v8 )
goto LABEL_14;
result = (unsigned int)(result + 1);
if ( v7 == (_DWORD)result )
{
v11 = v8;
goto LABEL_14;
}
}
}
}
goto LABEL_6;
}
if ( v8 )
{
LABEL_6:
v10 = *(_QWORD **)(result + 8);
if ( v10 )
*v10 = v6;
else
*(_QWORD *)a1 = v6;
*v6 = result;
v6[1] = *(_QWORD *)(result + 8);
*(_QWORD *)(result + 8) = v6;
++*(_DWORD *)(a1 + 8);
return result;
}
v11 = 0LL;
LABEL_14:
*v11 = v6;
v6[1] = v11;
++*(_DWORD *)(a1 + 8);
return result;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func1(__int64 a1, __int64 a2, int a3)
{
unsigned __int64 result; // rax
_QWORD *v6; // rsi
int v7; // ecx
_QWORD *v8; // rdi
int v9; // edx
_QWORD *v10; // rdx
_QWORD *v11; // rdx

result = (unsigned __int64)crearNodo(a2, a3);
v6 = (_QWORD *)result;
v7 = *(_DWORD *)(a1 + 8);
if ( !v7 )
{
*(_QWORD *)a1 = result;
*(_DWORD *)(a1 + 8) = 1;
return result;
}
v8 = *(_QWORD **)a1;
result = *(_QWORD *)a1;
v9 = 0;
if ( v7 > 0 )
{
while ( *(_DWORD *)(result + 16) < a3 )
{
result = *(_QWORD *)result;
if ( v7 == ++v9 )
{
if ( result )
goto LABEL_6;
result = 0LL;
while ( 1 )
{
v11 = v8;
v8 = (_QWORD *)*v8;
if ( !v8 )
goto LABEL_14;
result = (unsigned int)(result + 1);
if ( v7 == (_DWORD)result )
{
v11 = v8;
goto LABEL_14;
}
}
}
}
goto LABEL_6;
}
if ( v8 )
{
LABEL_6:
v10 = *(_QWORD **)(result + 8);
if ( v10 )
*v10 = v6;
else
*(_QWORD *)a1 = v6;
*v6 = result;
v6[1] = *(_QWORD *)(result + 8);
*(_QWORD *)(result + 8) = v6;
++*(_DWORD *)(a1 + 8);
return result;
}
v11 = 0LL;
LABEL_14:
*v11 = v6;
v6[1] = v11;
++*(_DWORD *)(a1 + 8);
return result;
}

original_code:
void agregarElemP(ColaP* cp, char* info, int prior){
 Nodo* np = crearNodo(info,prior);
 if (cp->tam == 0){
  cp->pri = np;
  cp->tam = 1;
  return;
 }
 Nodo* aux = cp->pri;
 int i = 0;
 for (i = 0; i < cp->tam && aux->prior < prior; i++)
  aux = aux->sig;
 if (aux == ((void *)0)){
  aux = cp->pri;
  for (i=0; i < cp->tam && aux->sig != ((void *)0); i++)
   aux = aux->sig;
  aux->sig = np;
  np->ant = aux;
  cp->tam += 1;
  return;
 }
 if (aux->ant == ((void *)0)){
  cp->pri = np;
 } else {
  aux->ant->sig = np;
 }
 np->sig = aux;
 np->ant = aux->ant;
 aux->ant = np;
 cp->tam += 1;
}

canonical_original_code:
void agregarElemP(struct colaP *cp, char *info, int prior){
 struct nodo *np = crearNodo(info,prior);
 if (cp->tam == 0){
  cp->pri = np;
  cp->tam = 1;
  return;
 }
 struct nodo *aux = cp->pri;
 int i = 0;
 for (i = 0; i < cp->tam && aux->prior < prior; i++)
  aux = aux->sig;
 if (aux == ((void *)0)){
  aux = cp->pri;
  for (i=0; i < cp->tam && aux->sig != ((void *)0); i++)
   aux = aux->sig;
  aux->sig = np;
  np->ant = aux;
  cp->tam += 1;
  return;
 }
 if (aux->ant == ((void *)0)){
  cp->pri = np;
 } else {
  aux->ant->sig = np;
 }
 np->sig = aux;
 np->ant = aux->ant;
 aux->ant = np;
 cp->tam += 1;
}

variable_types:
info
char *

variable_types: prior int

variable_types: struct nodo { struct nodo *sig; struct nodo *ant; int prior; char *info; } *


darElemP

decompiled_code:
__int64 __fastcall darElemP(__int64 a1, int a2)
{
_QWORD *v2; // rdx
int i; // eax

v2 = *(_QWORD **)a1;
if ( a2 > 0 )
{
for ( i = 0; i != a2; ++i )
{
if ( *(_DWORD *)(a1 + 8) <= i )
break;
v2 = (_QWORD *)*v2;
}
}
return v2[3];
}

original_code:
char* darElemP(ColaP* cp, int pos){
 Nodo* aux = cp->pri;
 int i;
 for (i=0; i < pos && i < cp->tam; i++)
  aux = aux->sig;
 return aux->info;
}

canonical_original_code:
char *darElemP(struct colaP *cp, int pos){
 struct nodo *aux = cp->pri;
 int i;
 for (i=0; i < pos && i < cp->tam; i++)
  aux = aux->sig;
 return aux->info;
}

variable_types: pos int

user_defined_types: struct nodo { struct nodo *sig; struct nodo *ant; int prior; char *info; }


sboxPrint

decompiled_code:
int __fastcall sboxPrint(__int64 a1)
{
unsigned __int8 *v1; // rbp
unsigned __int8 *v2; // rbx
int result; // eax

v1 = (unsigned __int8 *)(a1 + 16);
do
{
v2 = v1 - 16;
do
printf("0x%02x, ", *v2++);
while ( v2 != v1 );
putchar(10);
result = putchar(10);
v1 += 16;
}
while ( v1 != (unsigned __int8 *)(a1 + 272) );
return result;
}

canonical_decompiled_code:
int __fastcall func0(__int64 a1)
{
unsigned __int8 *v1; // rbp
unsigned __int8 *v2; // rbx
int result; // eax

v1 = (unsigned __int8 *)(a1 + 16);
do
{
v2 = v1 - 16;
do
printf("0x%02x, ", *v2++);
while ( v2 != v1 );
putchar(10);
result = putchar(10);
v1 += 16;
}
while ( v1 != (unsigned __int8 *)(a1 + 272) );
return result;
}

original_code:
void sboxPrint(byte_t * s)
{
 int i,j;
 for(i=0;i<16;i++){
  for(j=0;j<16;j++)
   printf("0x%02x, ",s[i*16+j]);
  putchar('\n');
  putchar('\n');
 }
}

canonical_original_code:
void sboxPrint(unsigned char *s)
{
 int i; int j;
 for(i=0;i<16;i++){
  for(j=0;j<16;j++)
   printf("0x%02x, ",s[i*16+j]);
  putchar('\n');
  putchar('\n');
 }
}

variable_types:
s
unsigned char *

variable_types: j int


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

v1 = a1;
do
printf("%02x", *v1++);
while ( v1 != a1 + 16 );
putchar(10);
return putchar(10);
}

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

v1 = a1;
do
printf("%02x", *v1++);
while ( v1 != a1 + 16 );
putchar(10);
return putchar(10);
}

original_code:
void print4x(byte_t * box)
{
 int i;
 for(i=0;i<16;i++)
 {
  printf("%02x",box[i]);
 }
 putchar('\n');
 putchar('\n');
}

canonical_original_code:
void print4x(unsigned char *box)
{
 int i;
 for(i=0;i<16;i++)
 {
  printf("%02x",box[i]);
 }
 putchar('\n');
 putchar('\n');
}

variable_types:
box
unsigned char *


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned __int8 *v3; // rbx
unsigned __int8 *v4; // rbp
unsigned int v6; // [rsp+Ch] [rbp-3Ch] BYREF
__int64 v7[2]; // [rsp+10h] [rbp-38h] BYREF
__int64 v8[5]; // [rsp+20h] [rbp-28h] BYREF

v8[0] = 0x8D305A88A8F64332LL;
v8[1] = 0x340737E0A2983131LL;
v7[0] = 0xA6D2AE2816157E2BLL;
v7[1] = 0x3C4FCF098815F7ABLL;
v3 = (unsigned __int8 *)calloc(0x11uLL, 1uLL);
Aes128cbc_Pkcs7_Enc(v8, 16LL, v7, 16LL, v3, &IV);
if ( v3 )
print4x(v3);
v4 = (unsigned __int8 *)calloc(0x11uLL, 1uLL);
v6 = 0;
Aes128cbc_Pkcs7_Dec(v3, 16LL, v7, 16LL, v4, &v6, &IV);
print4x(v4);
printf("ptlen=%d\n", v6);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned __int8 *v3; // rbx
unsigned __int8 *v4; // rbp
unsigned int v6; // [rsp+Ch] [rbp-3Ch] BYREF
__int64 v7[2]; // [rsp+10h] [rbp-38h] BYREF
__int64 v8[5]; // [rsp+20h] [rbp-28h] BYREF

v8[0] = 0x8D305A88A8F64332LL;
v8[1] = 0x340737E0A2983131LL;
v7[0] = 0xA6D2AE2816157E2BLL;
v7[1] = 0x3C4FCF098815F7ABLL;
v3 = (unsigned __int8 *)calloc(0x11uLL, 1uLL);
Aes128cbc_Pkcs7_Enc(v8, 16LL, v7, 16LL, v3, &IV);
if ( v3 )
func1(v3);
v4 = (unsigned __int8 *)calloc(0x11uLL, 1uLL);
v6 = 0;
Aes128cbc_Pkcs7_Dec(v3, 16LL, v7, 16LL, v4, &v6, &IV);
func1(v4);
printf("ptlen=%d\n", v6);
return 0;
}

original_code:
int main(void)
{
 int i;
 byte_t input[16]={0x32,0x43,0xf6,0xa8,0x88,0x5a,0x30,0x8d,0x31,0x31,0x98,0xa2,0xe0,0x37,0x07,0x34};
 byte_t k[16]={0x2b,0x7e,0x15,0x16,0x28,0xae,0xd2,0xa6,0xab,0xf7,0x15,0x88,0x09,0xcf,0x4f,0x3c};
 byte_t * S=calloc(16+1,sizeof(byte_t));
 Aes128cbc_Pkcs7_Enc(input,sizeof(input),k,16,S,IV);
 if(S){
  print4x(S);
 }
 byte_t * plain=calloc(16+1,sizeof(byte_t));
 int ptlen=0;
 Aes128cbc_Pkcs7_Dec(S,16,k,16,plain,&ptlen,IV);
 print4x(plain);
 printf("ptlen=%d\n",ptlen);
 return 0;
}

canonical_original_code:
int main()
{
 int i;
 unsigned char input[16] = {0x32,0x43,0xf6,0xa8,0x88,0x5a,0x30,0x8d,0x31,0x31,0x98,0xa2,0xe0,0x37,0x07,0x34};
 unsigned char k[16] = {0x2b,0x7e,0x15,0x16,0x28,0xae,0xd2,0xa6,0xab,0xf7,0x15,0x88,0x09,0xcf,0x4f,0x3c};
 unsigned char *S = calloc(16+1,sizeof(byte_t));
 Aes128cbc_Pkcs7_Enc(input,sizeof(input),k,16,S,IV);
 if(S){
  print4x(S);
 }
 unsigned char *plain = calloc(16+1,sizeof(byte_t));
 int ptlen = 0;
 Aes128cbc_Pkcs7_Dec(S,16,k,16,plain,&ptlen,IV);
 print4x(plain);
 printf("ptlen=%d\n",ptlen);
 return 0;
}

variable_types:
input
unsigned char [16]

variable_types:
k
unsigned char [16]

variable_types:
S
unsigned char *

variable_types:
plain
unsigned char *

variable_types: ptlen int


decompiled_code:
__int64 __fastcall state_mix_columns(unsigned __int8 *a1)
{
unsigned __int8 *v1; // r12
__int64 i; // rbp
int v3; // ebx
int v4; // ebx
int v5; // ebx
__int64 result; // rax
char v7[3]; // [rsp+Ch] [rbp-2Ch]
unsigned __int8 v8; // [rsp+Fh] [rbp-29h]

v1 = a1;
do
{
for ( i = 0LL; i != 4; ++i )
{
v3 = GF2sup8_mul8((unsigned __int8)MixC[4 * i], *v1);
v4 = GF2sup8_mul8((unsigned __int8)byte_631[4 * i], v1[4]) ^ v3;
v5 = GF2sup8_mul8((unsigned __int8)byte_632[4 * i], v1[8]) ^ v4;
v7[i] = GF2sup8_mul8((unsigned __int8)byte_633[4 * i], v1[12]) ^ v5;
}
*v1 = v7[0];
v1[4] = v7[1];
v1[8] = v7[2];
result = v8;
v1[12] = v8;
++v1;
}
while ( v1 != a1 + 4 );
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned __int8 *a1)
{
unsigned __int8 *v1; // r12
__int64 i; // rbp
int v3; // ebx
int v4; // ebx
int v5; // ebx
__int64 result; // rax
char v7[3]; // [rsp+Ch] [rbp-2Ch]
unsigned __int8 v8; // [rsp+Fh] [rbp-29h]

v1 = a1;
do
{
for ( i = 0LL; i != 4; ++i )
{
v3 = GF2sup8_mul8((unsigned __int8)MixC[4 * i], *v1);
v4 = GF2sup8_mul8((unsigned __int8)byte_631[4 * i], v1[4]) ^ v3;
v5 = GF2sup8_mul8((unsigned __int8)byte_632[4 * i], v1[8]) ^ v4;
v7[i] = GF2sup8_mul8((unsigned __int8)byte_633[4 * i], v1[12]) ^ v5;
}
*v1 = v7[0];
v1[4] = v7[1];
v1[8] = v7[2];
result = v8;
v1[12] = v8;
++v1;
}
while ( v1 != a1 + 4 );
return result;
}

original_code:
static void state_mix_columns(byte_t * state)
{
 int i,j,ret;
 byte_t tr[4];
 for(i=0;i<4;i++){
  for(j=0;j<4;j++){
   tr[j]=GF2sup8_mul8(MixC[j][0],state[0*4+i])^
    GF2sup8_mul8(MixC[j][1],state[1*4+i])^
    GF2sup8_mul8(MixC[j][2],state[2*4+i])^
    GF2sup8_mul8(MixC[j][3],state[3*4+i]);
  }
  state[0*4+i]=tr[0];
  state[1*4+i]=tr[1];
  state[2*4+i]=tr[2];
  state[3*4+i]=tr[3];
 }
}

canonical_original_code:
static void state_mix_columns(unsigned char *state)
{
 int i; int j; int ret;
 unsigned char tr[4];
 for(i=0;i<4;i++){
  for(j=0;j<4;j++){
   tr[j]=GF2sup8_mul8(MixC[j][0],state[0*4+i])^
    GF2sup8_mul8(MixC[j][1],state[1*4+i])^
    GF2sup8_mul8(MixC[j][2],state[2*4+i])^
    GF2sup8_mul8(MixC[j][3],state[3*4+i]);
  }
  state[0*4+i]=tr[0];
  state[1*4+i]=tr[1];
  state[2*4+i]=tr[2];
  state[3*4+i]=tr[3];
 }
}

variable_types:
state
unsigned char *

variable_types: i int

variable_types: ret int

variable_types:
tr
unsigned char [4]


decompiled_code:
__int64 __fastcall state_shift_row_left(int *a1, unsigned int a2)
{
unsigned int v2; // ebx
unsigned int v4; // er12

if ( a2 > 3 )
return (unsigned int)-1;
v2 = a2;
if ( !a1 )
return (unsigned int)-1;
if ( a2 )
{
v4 = *a1;
if ( (unsigned int)is_big_endian() )
*a1 = (v4 << (8 * a2)) | (v4 >> (8 * (4 - a2)));
else
*a1 = (v4 << (8 * (4 - a2))) | (v4 >> (8 * a2));
v2 = 0;
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func1(int *a1, unsigned int a2)
{
unsigned int v2; // ebx
unsigned int v4; // er12

if ( a2 > 3 )
return (unsigned int)-1;
v2 = a2;
if ( !a1 )
return (unsigned int)-1;
if ( a2 )
{
v4 = *a1;
if ( (unsigned int)is_big_endian() )
*a1 = (v4 << (8 * a2)) | (v4 >> (8 * (4 - a2)));
else
*a1 = (v4 << (8 * (4 - a2))) | (v4 >> (8 * a2));
v2 = 0;
}
return v2;
}

original_code:
static int state_shift_row_left(byte_t * state,int n)
{
 if(n>3 || n<0 || !state)
  return -1;
 if(n==0) return 0;
 word_t * swt = (word_t*)state;
 word_t sw=*swt;
 if(is_big_endian()){
  *swt=((sw) << (n*8))|((sw) >> ((32) - (n*8)));
 }else{
  *swt=((sw) >> (n*8))|((sw) << ((32) - (n*8)));
 }
 return 0;
}

canonical_original_code:
static int state_shift_row_left(unsigned char *state, int n)
{
 if(n>3 || n<0 || !state)
  return -1;
 if(n==0) return 0;
 unsigned int *swt = (word_t*)state;
 unsigned int sw = *swt;
 if(is_big_endian()){
  *swt=((sw) << (n*8))|((sw) >> ((32) - (n*8)));
 }else{
  *swt=((sw) >> (n*8))|((sw) << ((32) - (n*8)));
 }
 return 0;
}

variable_types: n int

variable_types:
swt
unsigned int *

variable_types:
sw
unsigned int


decompiled_code:
__int64 __fastcall state_bvary_lshift(__int64 a1)
{
__int64 v1; // rbp
unsigned int v2; // er12
__int64 v3; // rbx
__int64 result; // rax

v1 = a1 + 4;
v2 = 0;
while ( 1 )
{
v3 = v1 - 4;
do
subbyte(v3++, &sbox);
while ( v3 != v1 );
result = state_shift_row_left((int *)(v1 - 4), v2);
if ( (int)result < 0 )
break;
++v2;
v1 += 4LL;
if ( v2 == 4 )
return 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
__int64 v1; // rbp
unsigned int v2; // er12
__int64 v3; // rbx
__int64 result; // rax

v1 = a1 + 4;
v2 = 0;
while ( 1 )
{
v3 = v1 - 4;
do
subbyte(v3++, &sbox);
while ( v3 != v1 );
result = func1((int *)(v1 - 4), v2);
if ( (int)result < 0 )
break;
++v2;
v1 += 4LL;
if ( v2 == 4 )
return 0LL;
}
return result;
}

original_code:
static int state_bvary_lshift(byte_t * state)
{
 int i,j,ret;
 for(i=0;i<4;i++)
 {
  for(j=0;j<4;j++)
  {
   subbyte(&state[i*4+j],sbox);
  }
  ret = state_shift_row_left(&state[i*4],i);
  if(ret < 0)
   return ret;
 }
 return 0;
}

canonical_original_code:
static int state_bvary_lshift(unsigned char *state)
{
 int i; int j; int ret;
 for(i=0;i<4;i++)
 {
  for(j=0;j<4;j++)
  {
   subbyte(&state[i*4+j],sbox);
  }
  ret = state_shift_row_left(&state[i*4],i);
  if(ret < 0)
   return ret;
 }
 return 0;
}


decompiled_code:
__int64 __fastcall Aes128_Enc(__int64 a1, int a2, __int64 a3, int a4, unsigned __int8 *a5)
{
__int64 v7; // rbp
int i; // er12
__int64 result; // rax

if ( !a1 )
return 0xFFFFFFFFLL;
if ( a2 != 16 )
return 0xFFFFFFFFLL;
if ( a4 != 16 || a3 == 0 || !a5 )
return 0xFFFFFFFFLL;
state_put(a1, a5);
key_expansion(a3, &W);
state_add_rou_key(a5, &W);
v7 = (unsigned int)((_DWORD)&W + 16);
for ( i = 1; i != 10; ++i )
{
if ( (int)state_bvary_lshift((__int64)a5) < 0 )
return 0xFFFFFFFFLL;
state_mix_columns(a5);
if ( (int)state_add_rou_key(a5, v7) < 0 )
return 0xFFFFFFFFLL;
v7 += 16LL;
}
if ( (int)state_bvary_lshift((__int64)a5) < 0 )
result = 0xFFFFFFFFLL;
else
result = (unsigned int)((int)state_add_rou_key(a5, (unsigned int)((_DWORD)&W + 160)) >> 31);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, int a2, __int64 a3, int a4, unsigned __int8 *a5)
{
__int64 v7; // rbp
int i; // er12
__int64 result; // rax

if ( !a1 )
return 0xFFFFFFFFLL;
if ( a2 != 16 )
return 0xFFFFFFFFLL;
if ( a4 != 16 || a3 == 0 || !a5 )
return 0xFFFFFFFFLL;
state_put(a1, a5);
key_expansion(a3, &W);
state_add_rou_key(a5, &W);
v7 = (unsigned int)((_DWORD)&W + 16);
for ( i = 1; i != 10; ++i )
{
if ( (int)func2((__int64)a5) < 0 )
return 0xFFFFFFFFLL;
func0(a5);
if ( (int)state_add_rou_key(a5, v7) < 0 )
return 0xFFFFFFFFLL;
v7 += 16LL;
}
if ( (int)func2((__int64)a5) < 0 )
result = 0xFFFFFFFFLL;
else
result = (unsigned int)((int)state_add_rou_key(a5, (unsigned int)((_DWORD)&W + 160)) >> 31);
return result;
}

original_code:
int Aes128_Enc(byte_t * input,int inlen,byte_t * key,int keylen,byte_t * output)
{
 if(!input || inlen!=16 || !key || keylen!=16 || !output)
  return -1;
 int i=0,ret=0;
 state_put(input,output);
 key_expansion(key,W);
 i=0;
 state_add_rou_key(output,W+i*4);
 i++;
 while(i<10){
  if(state_bvary_lshift(output)<0)
   return -1;
  state_mix_columns(output);
  if(state_add_rou_key(output,W+i*4)<0)
   return -1;
  i++;
 }
 if(state_bvary_lshift(output)<0)
  return -1;
 if(state_add_rou_key(output,W+i*4)<0)
  return -1;
 return 0;
}

canonical_original_code:
int Aes128_Enc(unsigned char *input, int inlen, unsigned char *key, int keylen, unsigned char *output)
{
 if(!input || inlen!=16 || !key || keylen!=16 || !output)
  return -1;
 int i = 0; int ret = 0;
 state_put(input,output);
 key_expansion(key,W);
 i=0;
 state_add_rou_key(output,W+i*4);
 i++;
 while(i<10){
  if(state_bvary_lshift(output)<0)
   return -1;
  state_mix_columns(output);
  if(state_add_rou_key(output,W+i*4)<0)
   return -1;
  i++;
 }
 if(state_bvary_lshift(output)<0)
  return -1;
 if(state_add_rou_key(output,W+i*4)<0)
  return -1;
 return 0;
}

variable_types:
input
unsigned char *

variable_types: inlen int

variable_types:
key
unsigned char *

variable_types: keylen int

variable_types:
output
unsigned char *


decompiled_code:
__int64 __fastcall Aes128cbc_Enc(unsigned __int8 *a1, int a2, __int64 a3, int a4)
{
__int64 v5; // r12
int i; // ebp

if ( !a1 )
return 0xFFFFFFFFLL;
if ( a2 != 16 )
return 0xFFFFFFFFLL;
if ( !a3 || a4 != 16 )
return 0xFFFFFFFFLL;
((void (*)(void))reverse4x)();
key_expansion(a3, &W);
state_add_rou_key(a1, &W);
v5 = (unsigned int)((_DWORD)&W + 16);
for ( i = 1; i != 10; ++i )
{
if ( (int)state_bvary_lshift((__int64)a1) < 0 )
return 0xFFFFFFFFLL;
state_mix_columns(a1);
state_add_rou_key(a1, v5);
v5 += 16LL;
}
if ( (int)state_bvary_lshift((__int64)a1) < 0 )
return 0xFFFFFFFFLL;
state_add_rou_key(a1, (unsigned int)((_DWORD)&W + 160));
reverse4x(a1);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func4(unsigned __int8 *a1, int a2, __int64 a3, int a4)
{
__int64 v5; // r12
int i; // ebp

if ( !a1 )
return 0xFFFFFFFFLL;
if ( a2 != 16 )
return 0xFFFFFFFFLL;
if ( !a3 || a4 != 16 )
return 0xFFFFFFFFLL;
((void (*)(void))reverse4x)();
key_expansion(a3, &W);
state_add_rou_key(a1, &W);
v5 = (unsigned int)((_DWORD)&W + 16);
for ( i = 1; i != 10; ++i )
{
if ( (int)func2((__int64)a1) < 0 )
return 0xFFFFFFFFLL;
func0(a1);
state_add_rou_key(a1, v5);
v5 += 16LL;
}
if ( (int)func2((__int64)a1) < 0 )
return 0xFFFFFFFFLL;
state_add_rou_key(a1, (unsigned int)((_DWORD)&W + 160));
reverse4x(a1);
return 0LL;
}

original_code:
int Aes128cbc_Enc(byte_t * state,int slen,byte_t * key,int keylen,const byte_t * iv)
{
 if(!state || slen!=16 || !key || keylen!=16 )
  return -1;
 int i=0;
 reverse4x(state);
 key_expansion(key,W);
 i=0;
 state_add_rou_key(state,W+i*4);
 i++;
 while(i<10){
  if(state_bvary_lshift(state)<0)
   return -1;
  state_mix_columns(state);
  state_add_rou_key(state,W+i*4);
  i++;
 }
 if(state_bvary_lshift(state)<0)
  return -1;
 state_add_rou_key(state,W+i*4);
 reverse4x(state);
 return 0;
}

canonical_original_code:
int Aes128cbc_Enc(unsigned char *state, int slen, unsigned char *key, int keylen, unsigned char *iv)
{
 if(!state || slen!=16 || !key || keylen!=16 )
  return -1;
 int i = 0;
 reverse4x(state);
 key_expansion(key,W);
 i=0;
 state_add_rou_key(state,W+i*4);
 i++;
 while(i<10){
  if(state_bvary_lshift(state)<0)
   return -1;
  state_mix_columns(state);
  state_add_rou_key(state,W+i*4);
  i++;
 }
 if(state_bvary_lshift(state)<0)
  return -1;
 state_add_rou_key(state,W+i*4);
 reverse4x(state);
 return 0;
}

variable_types: slen int

variable_types:
iv
unsigned char *


decompiled_code:
__int64 __fastcall Aes128cbc_Pkcs7_Enc(__int64 a1, __int64 a2, __int64 a3, int a4, unsigned __int8 *a5, __int64 a6)
{
__int64 v9; // rax
__int64 v10; // r12
int j; // ebp
__int64 i; // rax

if ( !a1 )
return 0xFFFFFFFFLL;
if ( (int)a2 <= 0 )
return 0xFFFFFFFFLL;
if ( a4 != 16 || a3 == 0 || !a5 )
return 0xFFFFFFFFLL;
v9 = 0LL;
if ( (int)a2 <= 15 )
{
PKCS7_Pad(a1, a2, 16LL, a5);
for ( i = 0LL; i != 16; ++i )
a5[i] ^= *(_BYTE *)(a6 + i);
}
else
{
do
{
a5[v9] = *(_BYTE *)(a6 + v9) ^ *(_BYTE *)(a1 + v9);
++v9;
}
while ( v9 != 16 );
}
reverse4x(a5);
key_expansion(a3, &W);
state_add_rou_key(a5, &W);
v10 = (unsigned int)((_DWORD)&W + 16);
for ( j = 1; j != 10; ++j )
{
if ( (int)state_bvary_lshift((__int64)a5) < 0 )
return 0xFFFFFFFFLL;
state_mix_columns(a5);
state_add_rou_key(a5, v10);
v10 += 16LL;
}
if ( (int)state_bvary_lshift((__int64)a5) < 0 )
return 0xFFFFFFFFLL;
state_add_rou_key(a5, (unsigned int)((_DWORD)&W + 160));
reverse4x(a5);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, __int64 a2, __int64 a3, int a4, unsigned __int8 *a5, __int64 a6)
{
__int64 v9; // rax
__int64 v10; // r12
int j; // ebp
__int64 i; // rax

if ( !a1 )
return 0xFFFFFFFFLL;
if ( (int)a2 <= 0 )
return 0xFFFFFFFFLL;
if ( a4 != 16 || a3 == 0 || !a5 )
return 0xFFFFFFFFLL;
v9 = 0LL;
if ( (int)a2 <= 15 )
{
PKCS7_Pad(a1, a2, 16LL, a5);
for ( i = 0LL; i != 16; ++i )
a5[i] ^= *(_BYTE *)(a6 + i);
}
else
{
do
{
a5[v9] = *(_BYTE *)(a6 + v9) ^ *(_BYTE *)(a1 + v9);
++v9;
}
while ( v9 != 16 );
}
reverse4x(a5);
key_expansion(a3, &W);
state_add_rou_key(a5, &W);
v10 = (unsigned int)((_DWORD)&W + 16);
for ( j = 1; j != 10; ++j )
{
if ( (int)func2((__int64)a5) < 0 )
return 0xFFFFFFFFLL;
func0(a5);
state_add_rou_key(a5, v10);
v10 += 16LL;
}
if ( (int)func2((__int64)a5) < 0 )
return 0xFFFFFFFFLL;
state_add_rou_key(a5, (unsigned int)((_DWORD)&W + 160));
reverse4x(a5);
return 0LL;
}

original_code:
int Aes128cbc_Pkcs7_Enc(byte_t * input,int inlen,byte_t * key,int keylen,byte_t * output,const byte_t * iv)
{
 if(!input || inlen<=0 || !key || keylen!=16 || !output)
  return -1;
 int i=0,ret=0;
 if(inlen<16){
  PKCS7_Pad(input,inlen,16,output);
  for(i=0;i<16;i++) output[i]^=iv[i];
 }else{
  for(i=0;i<16;i++) output[i]=input[i]^iv[i];
 }
 reverse4x(output);
 key_expansion(key,W);
 i=0;
 state_add_rou_key(output,W+i*4);
 i++;
 while(i<10){
  if(state_bvary_lshift(output)<0)
   return -1;
  state_mix_columns(output);
  state_add_rou_key(output,W+i*4);
  i++;
 }
 if(state_bvary_lshift(output)<0)
  return -1;
 state_add_rou_key(output,W+i*4);
 reverse4x(output);
 return 0;
}

canonical_original_code:
int Aes128cbc_Pkcs7_Enc(unsigned char *input, int inlen, unsigned char *key, int keylen, unsigned char *output, unsigned char *iv)
{
 if(!input || inlen<=0 || !key || keylen!=16 || !output)
  return -1;
 int i = 0; int ret = 0;
 if(inlen<16){
  PKCS7_Pad(input,inlen,16,output);
  for(i=0;i<16;i++) output[i]^=iv[i];
 }else{
  for(i=0;i<16;i++) output[i]=input[i]^iv[i];
 }
 reverse4x(output);
 key_expansion(key,W);
 i=0;
 state_add_rou_key(output,W+i*4);
 i++;
 while(i<10){
  if(state_bvary_lshift(output)<0)
   return -1;
  state_mix_columns(output);
  state_add_rou_key(output,W+i*4);
  i++;
 }
 if(state_bvary_lshift(output)<0)
  return -1;
 state_add_rou_key(output,W+i*4);
 reverse4x(output);
 return 0;
}


decompiled_code:
__int64 __fastcall move_left_by(int a1, int a2)
{
__int64 v3; // rax
int v4; // esi
int v5; // edx
int v6; // ecx

if ( a1 > a2 || a1 <= 0 )
return 0xFFFFFFFFLL;
v3 = 0LL;
v4 = -1;
v5 = -1;
do
{
v6 = bit_vector[v3];
if ( (a1 & v6) != 0 && v5 == -1 )
v5 = v3;
if ( (a2 & v6) != 0 && v4 == -1 )
v4 = v3;
if ( v5 > 0 && v4 > 0 )
break;
++v3;
}
while ( v3 != 16 );
return (unsigned int)(v5 - v4);
}

original_code:
static int move_left_by(const int s,const int b)
{
 if(s>b || s<=0)
  return -1;
 int i,si=-1,bi=-1;
 for(i=0;i<16;i++)
 {
  if(s&bit_vector[i] && si==-1)
   si=i;
  if(b&bit_vector[i] && bi==-1)
   bi=i;
  if(si>0&&bi>0)
   break;
 }
 int m_n=si-bi;
 return m_n;
}

canonical_original_code:
static int move_left_by(int s, int b)
{
 if(s>b || s<=0)
  return -1;
 int i; int si = -1; int bi = -1;
 for(i=0;i<16;i++)
 {
  if(s&bit_vector[i] && si==-1)
   si=i;
  if(b&bit_vector[i] && bi==-1)
   bi=i;
  if(si>0&&bi>0)
   break;
 }
 int m_n = si-bi;
 return m_n;
}

variable_types: s int

variable_types: b int

variable_types: si int

variable_types: bi int


original_code:
int GF2sup8_mul8(const int a,const int b)
{
 if(!a || !b) return 0;
 int BX[8];
 BX[0]=a;
 int i;
 for(i=1;i<8;i++){
  if(BX[i-1] & 0x80){
   BX[i]=BX[i-1]<<1;
   BX[i]^=0x001B;
  }else
   BX[i]=BX[i-1]<<1;
 }
 i=0;
 int n=1;
 int ret=0;
 while(n){
  if(n&b) ret^=BX[i];
  i++;
  n<<=1;
 }
 return ret;
}

canonical_original_code:
int GF2sup8_mul8(int a, int b)
{
 if(!a || !b) return 0;
 int BX[8];
 BX[0]=a;
 int i;
 for(i=1;i<8;i++){
  if(BX[i-1] & 0x80){
   BX[i]=BX[i-1]<<1;
   BX[i]^=0x001B;
  }else
   BX[i]=BX[i-1]<<1;
 }
 i=0;
 int n = 1;
 int ret = 0;
 while(n){
  if(n&b) ret^=BX[i];
  i++;
  n<<=1;
 }
 return ret;
}

variable_types: a int

variable_types:
BX
int [8]

variable_types: i int


decompiled_code:
__int64 __fastcall GF2sup8_mul16(int a1, int a2)
{
unsigned int v3; // edx
int v4; // esi
int i; // ecx

if ( !a1 || !a2 )
return 0;
v3 = 0;
v4 = 1;
for ( i = 0; i != 32; ++i )
{
if ( (v4 & a2) != 0 )
v3 ^= a1 << i;
v4 *= 2;
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func2(int a1, int a2)
{
unsigned int v3; // edx
int v4; // esi
int i; // ecx

if ( !a1 || !a2 )
return 0;
v3 = 0;
v4 = 1;
for ( i = 0; i != 32; ++i )
{
if ( (v4 & a2) != 0 )
v3 ^= a1 << i;
v4 *= 2;
}
return v3;
}

original_code:
int GF2sup8_mul16(const int a,const int b)
{
 int i=0;
 int n=1;
 if(!a || !b) return 0;
 int ret=0;
 while(n){
  if(n&b) ret^=(a<<i);
  i++;
  n<<=1;
 }
 return ret;
}

canonical_original_code:
int GF2sup8_mul16(int a, int b)
{
 int i = 0;
 int n = 1;
 if(!a || !b) return 0;
 int ret = 0;
 while(n){
  if(n&b) ret^=(a<<i);
  i++;
  n<<=1;
 }
 return ret;
}

variable_types: n int

variable_types: ret int


decompiled_code:
__int64 __fastcall GF2sup8_divid(int a1, int a2, int *a3)
{
int v3; // ebx
int v5; // eax
unsigned int v7[9]; // [rsp+Ch] [rbp-24h]

v3 = a1;
for ( v7[0] = 0; a2 < v3; v3 ^= a2 << v5 )
{
v5 = move_left_by(a2, v3);
if ( v5 < 0 )
break;
v7[v5 >> 3] |= 1 << (v5 % 8);
}
if ( a3 )
*a3 = v3;
return v7[0];
}

original_code:
int GF2sup8_divid(const int a,const int b,int * mod)
{
 int ret = 0;
 int c=0;
 int A=a;
 while(A>b){
  c=move_left_by(b,A);
  if(c<0) break;
  ((&ret)[(c)/8] |= 1<<((c)%8));
  A=(b<<c)^A;
 }
 if(mod)
  *mod=A;
 return ret;
}

canonical_original_code:
int GF2sup8_divid(int a, int b, int *mod)
{
 int ret = 0;
 int c = 0;
 int A = a;
 while(A>b){
  c=move_left_by(b,A);
  if(c<0) break;
  ((&ret)[(c)/8] |= 1<<((c)%8));
  A=(b<<c)^A;
 }
 if(mod)
  *mod=A;
 return ret;
}

variable_types:
mod
int *

variable_types: c int

variable_types: A int


decompiled_code:
__int64 __fastcall GF2sup8_mod(int a1, int a2)
{
unsigned int v2; // ebx
int v3; // eax

v2 = a1;
if ( a1 <= a2 )
return (unsigned int)a1;
while ( 1 )
{
v3 = move_left_by(a2, v2);
if ( v3 < 0 )
break;
v2 ^= a2 << v3;
if ( a2 >= (int)v2 )
return v2;
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func4(int a1, int a2)
{
unsigned int v2; // ebx
int v3; // eax

v2 = a1;
if ( a1 <= a2 )
return (unsigned int)a1;
while ( 1 )
{
v3 = func0(a2, v2);
if ( v3 < 0 )
break;
v2 ^= a2 << v3;
if ( a2 >= (int)v2 )
return v2;
}
return v2;
}

original_code:
int GF2sup8_mod(const int a,const int b)
{
 int c=0;
 int A=a;
 while(A>b)
 {
  c=move_left_by(b,A);
  if(c<0) break;
  A=(b<<c)^A;
 }
 return A;
}

canonical_original_code:
int GF2sup8_mod(int a, int b)
{
 int c = 0;
 int A = a;
 while(A>b)
 {
  c=move_left_by(b,A);
  if(c<0) break;
  A=(b<<c)^A;
 }
 return A;
}


decompiled_code:
__int64 __fastcall euclid_gcb(int a1, int a2)
{
signed int v2; // eax
int v3; // esi
int v4; // edx
unsigned int v5; // ecx

v2 = abs32(a1);
v3 = abs32(a2);
if ( v2 <= v3 )
{
v4 = v2;
v2 = v3;
v3 = v4;
}
if ( !v3 )
return (unsigned int)v2;
do
{
v5 = v3;
v3 = v2 % v3;
v2 = v5;
}
while ( v3 );
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1, int a2)
{
signed int v2; // eax
int v3; // esi
int v4; // edx
unsigned int v5; // ecx

v2 = abs32(a1);
v3 = abs32(a2);
if ( v2 <= v3 )
{
v4 = v2;
v2 = v3;
v3 = v4;
}
if ( !v3 )
return (unsigned int)v2;
do
{
v5 = v3;
v3 = v2 % v3;
v2 = v5;
}
while ( v3 );
return v5;
}

original_code:
int euclid_gcb(int a,int b)
{
    int A,B,R;
    if(a<0) a=-a;
    if(b<0) b=-b;
    if(a>b) A=a,B=b;
    else A=b,B=a;
    while(B){
        R=A%B;
        A=B;
        B=R;
    }
    return A;
}

canonical_original_code:
int euclid_gcb(int a, int b)
{
    int A; int B; int R;
    if(a<0) a=-a;
    if(b<0) b=-b;
    if(a>b) A=a,B=b;
    else A=b,B=a;
    while(B){
        R=A%B;
        A=B;
        B=R;
    }
    return A;
}

variable_types: B int

variable_types: R int


decompiled_code:
__int64 __fastcall euclid_gcb_ext(int a1, int a2)
{
int v2; // eax
int v3; // ecx
int v4; // er8
int v5; // er9
unsigned int v6; // edi

v2 = a1;
if ( a1 <= a2 )
{
v2 = a2;
a2 = a1;
}
if ( (unsigned int)a2 <= 1 )
{
v6 = v2;
v3 = 1;
}
else
{
v3 = 1;
v4 = 0;
do
{
v5 = v3;
v3 = v4 - v3 * (v2 / a2);
v6 = a2;
a2 = v2 % a2;
v4 = v5;
v2 = v6;
}
while ( (unsigned int)a2 > 1 );
}
if ( a2 )
v6 = v3;
return v6;
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1, int a2)
{
int v2; // eax
int v3; // ecx
int v4; // er8
int v5; // er9
unsigned int v6; // edi

v2 = a1;
if ( a1 <= a2 )
{
v2 = a2;
a2 = a1;
}
if ( (unsigned int)a2 <= 1 )
{
v6 = v2;
v3 = 1;
}
else
{
v3 = 1;
v4 = 0;
do
{
v5 = v3;
v3 = v4 - v3 * (v2 / a2);
v6 = a2;
a2 = v2 % a2;
v4 = v5;
v2 = v6;
}
while ( (unsigned int)a2 > 1 );
}
if ( a2 )
v6 = v3;
return v6;
}

canonical_original_code:
int euclid_gcb_ext(int a, int b)
{
    int A; int B;
    int A1; int A2; int A3; int B1; int B2; int B3;
    if(a>b)A=a,B=b;
    else A=b,B=a;
    A1=1,A2=0,A3=A;
    B1=0,B2=1,B3=B;
    int Q; int T1; int T2; int T3;
    while(B3!=1 && B3!=0){
        Q=A3/B3;
        T1=A1-Q*B1;
        T2=A2-Q*B2;
        T3=A3-Q*B3;
        A1=B1,A2=B2,A3=B3;
        B1=T1,B2=T2,B3=T3;
    }
    if(B3==0) return A3;
    if(B3==1) return B2;
}

variable_types: Q int