addToList

decompiled_code:
int *__fastcall addToList(int **a1)
{
int v1; // ebp
char *v3; // rdi
int *v4; // r13
char *v5; // r14
_QWORD *v6; // rax
_QWORD *v7; // r12
_DWORD *v8; // rax
int v9; // edx
int *result; // rax
_QWORD *v11; // rax
_QWORD *v12; // r12
_DWORD *v13; // rax
int v14; // edx

v1 = tailleDeplacement;
v3 = (char *)coupsPossibles;
if ( tailleListe == tailleDeplacement )
{
tailleListe = 2 * tailleDeplacement;
coupsPossibles = realloc(coupsPossibles, 16LL * tailleDeplacement);
v3 = (char *)coupsPossibles;
}
v4 = *a1;
v5 = &v3[8 * v1];
if ( **a1 == 2 )
{
v11 = malloc(0x18uLL);
*(_QWORD *)v5 = v11;
v12 = v11;
v13 = malloc(4uLL);
v14 = *v4;
*v12 = v13;
*v13 = v14;
v12[1] = a1[1];
result = a1[2];
v12[2] = result;
}
else
{
v6 = malloc(0x20uLL);
*(_QWORD *)v5 = v6;
v7 = v6;
v8 = malloc(4uLL);
v9 = *v4;
*v7 = v8;
*v8 = v9;
v7[1] = a1[1];
v7[2] = a1[2];
result = a1[3];
v7[3] = result;
}
tailleDeplacement = v1 + 1;
return result;
}

canonical_decompiled_code:
int *__fastcall func2(int **a1)
{
int v1; // ebp
char *v3; // rdi
int *v4; // r13
char *v5; // r14
_QWORD *v6; // rax
_QWORD *v7; // r12
_DWORD *v8; // rax
int v9; // edx
int *result; // rax
_QWORD *v11; // rax
_QWORD *v12; // r12
_DWORD *v13; // rax
int v14; // edx

v1 = tailleDeplacement;
v3 = (char *)coupsPossibles;
if ( tailleListe == tailleDeplacement )
{
tailleListe = 2 * tailleDeplacement;
coupsPossibles = realloc(coupsPossibles, 16LL * tailleDeplacement);
v3 = (char *)coupsPossibles;
}
v4 = *a1;
v5 = &v3[8 * v1];
if ( **a1 == 2 )
{
v11 = malloc(0x18uLL);
*(_QWORD *)v5 = v11;
v12 = v11;
v13 = malloc(4uLL);
v14 = *v4;
*v12 = v13;
*v13 = v14;
v12[1] = a1[1];
result = a1[2];
v12[2] = result;
}
else
{
v6 = malloc(0x20uLL);
*(_QWORD *)v5 = v6;
v7 = v6;
v8 = malloc(4uLL);
v9 = *v4;
*v7 = v8;
*v8 = v9;
v7[1] = a1[1];
v7[2] = a1[2];
result = a1[3];
v7[3] = result;
}
tailleDeplacement = v1 + 1;
return result;
}

original_code:
void addToList(int ** coor){
 if (tailleListe==tailleDeplacement){
   tailleListe*=2;
  coupsPossibles = realloc(coupsPossibles, sizeof(int**)*tailleListe);
 }
 if( coor[0][0]==2){
  coupsPossibles[tailleDeplacement] = malloc(sizeof(int*) * 3);
  coupsPossibles[tailleDeplacement][0] = malloc(sizeof(int) * 1);
  coupsPossibles[tailleDeplacement][1] = malloc( sizeof(int) * 2);
  coupsPossibles[tailleDeplacement][2] = malloc( sizeof(int) * 2);
  coupsPossibles[tailleDeplacement][0][0] = coor[0][0];
  coupsPossibles[tailleDeplacement][1] = coor[1];
  coupsPossibles[tailleDeplacement][2] = coor[2];
 }
 else{
  coupsPossibles[tailleDeplacement] = malloc(sizeof(int*) * 4);
  coupsPossibles[tailleDeplacement][0] = malloc(sizeof(int) * 1);
  coupsPossibles[tailleDeplacement][1] = malloc( sizeof(int) * 2);
  coupsPossibles[tailleDeplacement][2] = malloc( sizeof(int) * 2);
  coupsPossibles[tailleDeplacement][3] = malloc( sizeof(int) * 2);
  coupsPossibles[tailleDeplacement][0][0] = coor[0][0];
  coupsPossibles[tailleDeplacement][1] = coor[1];
  coupsPossibles[tailleDeplacement][2] = coor[2];
  coupsPossibles[tailleDeplacement][3] = coor[3];
 }
 tailleDeplacement++;
}

canonical_original_code:
void addToList(int **coor){
 if (tailleListe==tailleDeplacement){
   tailleListe*=2;
  coupsPossibles = realloc(coupsPossibles, sizeof(int **)*tailleListe);
 }
 if( coor[0][0]==2){
  coupsPossibles[tailleDeplacement] = malloc(sizeof(int *) * 3);
  coupsPossibles[tailleDeplacement][0] = malloc(sizeof(int) * 1);
  coupsPossibles[tailleDeplacement][1] = malloc( sizeof(int) * 2);
  coupsPossibles[tailleDeplacement][2] = malloc( sizeof(int) * 2);
  coupsPossibles[tailleDeplacement][0][0] = coor[0][0];
  coupsPossibles[tailleDeplacement][1] = coor[1];
  coupsPossibles[tailleDeplacement][2] = coor[2];
 }
 else{
  coupsPossibles[tailleDeplacement] = malloc(sizeof(int *) * 4);
  coupsPossibles[tailleDeplacement][0] = malloc(sizeof(int) * 1);
  coupsPossibles[tailleDeplacement][1] = malloc( sizeof(int) * 2);
  coupsPossibles[tailleDeplacement][2] = malloc( sizeof(int) * 2);
  coupsPossibles[tailleDeplacement][3] = malloc( sizeof(int) * 2);
  coupsPossibles[tailleDeplacement][0][0] = coor[0][0];
  coupsPossibles[tailleDeplacement][1] = coor[1];
  coupsPossibles[tailleDeplacement][2] = coor[2];
  coupsPossibles[tailleDeplacement][3] = coor[3];
 }
 tailleDeplacement++;
}


syntaxeCoups

decompiled_code:
__int64 __fastcall syntaxeCoups(__int64 a1)
{
unsigned int v1; // eax
__int64 result; // rax

v1 = strlen((const char *)a1);
if ( v1 == 5 )
return 3 * (unsigned int)(*(_BYTE *)(a1 + 2) == 45) - 1;
if ( v1 == 8 )
{
if ( *(_BYTE *)(a1 + 2) == 45 )
result = 4 * (unsigned int)(*(_BYTE *)(a1 + 5) == 45) - 1;
else
result = 0xFFFFFFFFLL;
}
else
{
printf("%s est un coups non valide de taille : %d\n", (const char *)a1, v1);
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
unsigned int v1; // eax
__int64 result; // rax

v1 = strlen((const char *)a1);
if ( v1 == 5 )
return 3 * (unsigned int)(*(_BYTE *)(a1 + 2) == 45) - 1;
if ( v1 == 8 )
{
if ( *(_BYTE *)(a1 + 2) == 45 )
result = 4 * (unsigned int)(*(_BYTE *)(a1 + 5) == 45) - 1;
else
result = 0xFFFFFFFFLL;
}
else
{
printf("%s est un coups non valide de taille : %d\n", (const char *)a1, v1);
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
int syntaxeCoups(char * coups){
 int taille;
 taille = strlen(coups);
 if (taille == 5){
  if(coups[2]=='-')return 2;
  else return-1;
 }
 else if (taille == 8){
  if(coups[2]=='-' && coups[5]=='-')return 3;
  else return -1;
 }
 else {
  printf ("%s est un coups non valide de taille : %d\n", coups, taille);
  return -1;
 }
 return 0;
}

canonical_original_code:
int syntaxeCoups(char *coups){
 int taille;
 taille = strlen(coups);
 if (taille == 5){
  if(coups[2]=='-')return 2;
  else return-1;
 }
 else if (taille == 8){
  if(coups[2]=='-' && coups[5]=='-')return 3;
  else return -1;
 }
 else {
  printf ("%s est un coups non valide de taille : %d\n", coups, taille);
  return -1;
 }
 return 0;
}

variable_types:
coups
char *

variable_types: taille int

return_type: int


repo: T-bagwell/su

decompiled_code:
__int64 __fastcall bprint_finalize(__int64 a1, _QWORD *a2)
{
const void *v2; // rdx
unsigned int v3; // ebp
const void *v4; // r13
void *v5; // rcx
__int64 result; // rax
void *v7; // rax

v2 = (const void *)(a1 + 20);
v3 = *(_DWORD *)(a1 + 12);
v4 = *(const void **)a1;
if ( *(_DWORD *)(a1 + 8) + 1 <= v3 )
v3 = *(_DWORD *)(a1 + 8) + 1;
if ( a2 )
{
if ( v4 == v2 )
{
v7 = malloc(v3);
v5 = v7;
if ( v7 )
{
v5 = memcpy(v7, v4, v3);
result = 0LL;
}
else
{
result = 4294967284LL;
}
}
else
{
v5 = realloc(*(void **)a1, v3);
if ( !v5 )
v5 = *(void **)a1;
*(_QWORD *)a1 = 0LL;
result = 0LL;
}
*a2 = v5;
goto LABEL_9;
}
result = 0LL;
if ( v4 == v2 )
{
LABEL_9:
*(_DWORD *)(a1 + 12) = v3;
return result;
}
free((void *)a1);
*(_DWORD *)(a1 + 12) = v3;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, _QWORD *a2)
{
const void *v2; // rdx
unsigned int v3; // ebp
const void *v4; // r13
void *v5; // rcx
__int64 result; // rax
void *v7; // rax

v2 = (const void *)(a1 + 20);
v3 = *(_DWORD *)(a1 + 12);
v4 = *(const void **)a1;
if ( *(_DWORD *)(a1 + 8) + 1 <= v3 )
v3 = *(_DWORD *)(a1 + 8) + 1;
if ( a2 )
{
if ( v4 == v2 )
{
v7 = malloc(v3);
v5 = v7;
if ( v7 )
{
v5 = memcpy(v7, v4, v3);
result = 0LL;
}
else
{
result = 4294967284LL;
}
}
else
{
v5 = realloc(*(void **)a1, v3);
if ( !v5 )
v5 = *(void **)a1;
*(_QWORD *)a1 = 0LL;
result = 0LL;
}
*a2 = v5;
goto LABEL_9;
}
result = 0LL;
if ( v4 == v2 )
{
LABEL_9:
*(_DWORD *)(a1 + 12) = v3;
return result;
}
free((void *)a1);
*(_DWORD *)(a1 + 12) = v3;
return 0LL;
}

original_code:
int bprint_finalize(BPrint *buf, char **ret_str)
{
    unsigned real_size = ((buf->len + 1) > (buf->size) ? (buf->size) : (buf->len + 1));
    char *str;
    int ret = 0;
    if (ret_str) {
        if (((buf)->str != (buf)->reserved_internal_buffer)) {
            str = realloc(buf->str, real_size);
            if (!str)
                str = buf->str;
            buf->str = ((void *)0);
        } else {
            str = malloc(real_size);
            if (str)
                memcpy(str, buf->str, real_size);
            else
                ret = -12;
        }
        *ret_str = str;
    } else {
        if (((buf)->str != (buf)->reserved_internal_buffer))
            free(&buf->str);
    }
    buf->size = real_size;
    return ret;
}

canonical_original_code:
int bprint_finalize(struct BPrint *buf, char **ret_str)
{
    unsigned int real_size = ((buf->len + 1) > (buf->size) ? (buf->size) : (buf->len + 1));
    char *str;
    int ret = 0;
    if (ret_str) {
        if (((buf)->str != (buf)->reserved_internal_buffer)) {
            str = realloc(buf->str, real_size);
            if (!str)
                str = buf->str;
            buf->str = ((void *)0);
        } else {
            str = malloc(real_size);
            if (str)
                memcpy(str, buf->str, real_size);
            else
                ret = -12;
        }
        *ret_str = str;
    } else {
        if (((buf)->str != (buf)->reserved_internal_buffer))
            free(&buf->str);
    }
    buf->size = real_size;
    return ret;
}

variable_types: struct BPrint { char *str; unsigned int len; unsigned int size; unsigned int size_max; char reserved_internal_buffer[1]; char reserved_padding[-1]; } *

variable_types:
str
char *

variable_types: ret int


decompiled_code:
_BOOL8 __fastcall bprint_is_complete(__int64 a1)
{
return *(_DWORD *)(a1 + 8) < *(_DWORD *)(a1 + 12);
}

canonical_decompiled_code:
_BOOL8 __fastcall func2(__int64 a1)
{
return *(_DWORD *)(a1 + 8) < *(_DWORD *)(a1 + 12);
}

original_code:
int bprint_is_complete(const BPrint *buf)
{
    return buf->len < buf->size;
}

canonical_original_code:
int bprint_is_complete(struct BPrint *buf)
{
    return buf->len < buf->size;
}

user_defined_types: struct BPrint { char *str; unsigned int len; unsigned int size; unsigned int size_max; char reserved_internal_buffer[1]; char reserved_padding[-1]; }


decompiled_code:
__int64 __fastcall bprint_alloc(__int64 a1, unsigned int a2)
{
unsigned int v2; // ecx
unsigned int v3; // er8
int v4; // eax
unsigned int v6; // ebp
unsigned int v7; // esi
unsigned int v8; // er13
size_t v9; // rsi
void *v10; // r12
void *v11; // rcx
__int64 result; // rax

if ( *(_DWORD *)(a1 + 12) == *(_DWORD *)(a1 + 16) )
return 4294967291LL;
if ( !bprint_is_complete(a1) )
return 4294967274LL;
v4 = *(_DWORD *)(a1 + 8);
v6 = 2 * v3;
v7 = -2 - v4;
v8 = v4 + 1;
if ( -2 - v4 > a2 )
v7 = a2;
LODWORD(v9) = v8 + v7;
if ( v3 > v2 >> 1 )
v6 = v2;
if ( v6 >= (unsigned int)v9 )
{
v10 = *(void **)a1;
v9 = v6;
if ( *(_QWORD *)a1 != a1 + 20 )
goto LABEL_9;
LABEL_16:
v11 = malloc(v9);
if ( v11 )
{
LABEL_17:
v11 = memcpy(v11, v10, v8);
goto LABEL_11;
}
return 4294967284LL;
}
v10 = *(void **)a1;
if ( v2 <= (unsigned int)v9 )
LODWORD(v9) = v2;
v6 = v9;
v9 = (unsigned int)v9;
if ( v10 == (void *)(a1 + 20) )
goto LABEL_16;
LABEL_9:
v11 = realloc(v10, v9);
if ( !v11 )
return 4294967284LL;
if ( !v10 )
{
v10 = *(void **)a1;
v8 = *(_DWORD *)(a1 + 8) + 1;
goto LABEL_17;
}
LABEL_11:
*(_QWORD *)a1 = v11;
result = 0LL;
*(_DWORD *)(a1 + 12) = v6;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, unsigned int a2)
{
unsigned int v2; // ecx
unsigned int v3; // er8
int v4; // eax
unsigned int v6; // ebp
unsigned int v7; // esi
unsigned int v8; // er13
size_t v9; // rsi
void *v10; // r12
void *v11; // rcx
__int64 result; // rax

if ( *(_DWORD *)(a1 + 12) == *(_DWORD *)(a1 + 16) )
return 4294967291LL;
if ( !func2(a1) )
return 4294967274LL;
v4 = *(_DWORD *)(a1 + 8);
v6 = 2 * v3;
v7 = -2 - v4;
v8 = v4 + 1;
if ( -2 - v4 > a2 )
v7 = a2;
LODWORD(v9) = v8 + v7;
if ( v3 > v2 >> 1 )
v6 = v2;
if ( v6 >= (unsigned int)v9 )
{
v10 = *(void **)a1;
v9 = v6;
if ( *(_QWORD *)a1 != a1 + 20 )
goto LABEL_9;
LABEL_16:
v11 = malloc(v9);
if ( v11 )
{
LABEL_17:
v11 = memcpy(v11, v10, v8);
goto LABEL_11;
}
return 4294967284LL;
}
v10 = *(void **)a1;
if ( v2 <= (unsigned int)v9 )
LODWORD(v9) = v2;
v6 = v9;
v9 = (unsigned int)v9;
if ( v10 == (void *)(a1 + 20) )
goto LABEL_16;
LABEL_9:
v11 = realloc(v10, v9);
if ( !v11 )
return 4294967284LL;
if ( !v10 )
{
v10 = *(void **)a1;
v8 = *(_DWORD *)(a1 + 8) + 1;
goto LABEL_17;
}
LABEL_11:
*(_QWORD *)a1 = v11;
result = 0LL;
*(_DWORD *)(a1 + 12) = v6;
return result;
}

original_code:
static int bprint_alloc(BPrint *buf, unsigned room)
{
    char *old, *new;
    unsigned minsz, newsz;
    if (buf->size == buf->size_max) {
        return -5;
    }
    if (!bprint_is_complete(buf)) {
        return -22;
    }
    minsz = buf->len + 1 + (((0x7fffffff * 2U + 1U) - buf->len - 1) > (room) ? (room) : ((0x7fffffff * 2U + 1U) - buf->len - 1));
    newsz = buf->size > buf->size_max / 2 ? buf->size_max : buf->size * 2;
    if (newsz < minsz) {
        newsz = ((buf->size_max) > (minsz) ? (minsz) : (buf->size_max));
    }
    old = ((buf)->str != (buf)->reserved_internal_buffer) ? buf->str : ((void *)0);
    new = realloc(old, newsz);
    if (!new) {
        return -12;
    }
    if (!old) {
        memcpy(new, buf->str, buf->len + 1);
    }
    buf->str = new;
    buf->size = newsz;
    return 0;
}

canonical_original_code:
static int bprint_alloc(struct BPrint *buf, unsigned int room)
{
    char *old; char *new;
    unsigned int minsz; unsigned int newsz;
    if (buf->size == buf->size_max) {
        return -5;
    }
    if (!bprint_is_complete(buf)) {
        return -22;
    }
    minsz = buf->len + 1 + (((0x7fffffff * 2U + 1U) - buf->len - 1) > (room) ? (room) : ((0x7fffffff * 2U + 1U) - buf->len - 1));
    newsz = buf->size > buf->size_max / 2 ? buf->size_max : buf->size * 2;
    if (newsz < minsz) {
        newsz = ((buf->size_max) > (minsz) ? (minsz) : (buf->size_max));
    }
    old = ((buf)->str != (buf)->reserved_internal_buffer) ? buf->str : ((void *)0);
    new = realloc(old, newsz);
    if (!new) {
        return -12;
    }
    if (!old) {
        memcpy(new, buf->str, buf->len + 1);
    }
    buf->str = new;
    buf->size = newsz;
    return 0;
}

variable_types:
room
unsigned int

variable_types:
old
char *

variable_types:
new
char *

variable_types:
minsz
unsigned int

variable_types:
newsz
unsigned int


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

if ( a3 == 1 )
{
result = 1004LL;
a3 = 1004;
}
else
{
result = 1004LL;
if ( a3 <= 0x3EC )
result = a3;
}
*(_DWORD *)(a1 + 8) = 0;
*(_QWORD *)a1 = a1 + 20;
*(_DWORD *)(a1 + 12) = result;
*(_DWORD *)(a1 + 16) = a3;
*(_BYTE *)(a1 + 20) = 0;
if ( a2 > (unsigned int)result )
result = bprint_alloc(a1, a2 - 1);
return result;
}

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

if ( a3 == 1 )
{
result = 1004LL;
a3 = 1004;
}
else
{
result = 1004LL;
if ( a3 <= 0x3EC )
result = a3;
}
*(_DWORD *)(a1 + 8) = 0;
*(_QWORD *)a1 = a1 + 20;
*(_DWORD *)(a1 + 12) = result;
*(_DWORD *)(a1 + 16) = a3;
*(_BYTE *)(a1 + 20) = 0;
if ( a2 > (unsigned int)result )
result = func3(a1, a2 - 1);
return result;
}

original_code:
void bprint_init(BPrint *buf, unsigned size_init, unsigned size_max)
{
    unsigned size_auto = (char *)buf + sizeof(*buf) - buf->reserved_internal_buffer;
    if (size_max == 1) {
        size_max = size_auto;
    }
    buf->str = buf->reserved_internal_buffer;
    buf->len = 0;
    buf->size = ((size_auto) > (size_max) ? (size_max) : (size_auto));
    buf->size_max = size_max;
    *buf->str = 0;
    if (size_init > buf->size) {
        bprint_alloc(buf, size_init - 1);
    }
}

canonical_original_code:
void bprint_init(struct BPrint *buf, unsigned int size_init, unsigned int size_max)
{
    unsigned int size_auto = (char *)buf + sizeof(*buf) - buf->reserved_internal_buffer;
    if (size_max == 1) {
        size_max = size_auto;
    }
    buf->str = buf->reserved_internal_buffer;
    buf->len = 0;
    buf->size = ((size_auto) > (size_max) ? (size_max) : (size_auto));
    buf->size_max = size_max;
    *buf->str = 0;
    if (size_init > buf->size) {
        bprint_alloc(buf, size_init - 1);
    }
}

return_type: void


decompiled_code:
__int64 __fastcall parser_ipaddr_to_int(char *a1, _BYTE *a2, _BYTE *a3, _BYTE *a4, _BYTE *a5)
{
int v5; // er15
char *i; // rbx
char v10; // al
char *v11; // rdx
char nptr[4]; // [rsp+0h] [rbp-3Ch] BYREF

if ( a1 )
{
v5 = 0;
for ( i = a1; ; ++i )
{
v10 = *i;
*(_DWORD *)nptr = 0;
if ( v10 && v10 != 46 )
{
v11 = nptr;
do
{
++i;
*v11++ = v10;
v10 = *i;
}
while ( *i != 46 && v10 );
}
if ( v5 )
{
switch ( v5 )
{
case 1:
*a3 = atoi(nptr);
break;
case 2:
*a4 = atoi(nptr);
break;
case 3:
*a5 = atoi(nptr);
return 0LL;
}
}
else
{
*a2 = atoi(nptr);
}
++v5;
fwrite("yyy\n", 1uLL, 4uLL, _bss_start);
}
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func7(char *a1, _BYTE *a2, _BYTE *a3, _BYTE *a4, _BYTE *a5)
{
int v5; // er15
char *i; // rbx
char v10; // al
char *v11; // rdx
char nptr[4]; // [rsp+0h] [rbp-3Ch] BYREF

if ( a1 )
{
v5 = 0;
for ( i = a1; ; ++i )
{
v10 = *i;
*(_DWORD *)nptr = 0;
if ( v10 && v10 != 46 )
{
v11 = nptr;
do
{
++i;
*v11++ = v10;
v10 = *i;
}
while ( *i != 46 && v10 );
}
if ( v5 )
{
switch ( v5 )
{
case 1:
*a3 = atoi(nptr);
break;
case 2:
*a4 = atoi(nptr);
break;
case 3:
*a5 = atoi(nptr);
return 0LL;
}
}
else
{
*a2 = atoi(nptr);
}
++v5;
fwrite("yyy\n", 1uLL, 4uLL, _bss_start);
}
}
return 0LL;
}

original_code:
int parser_ipaddr_to_int(unsigned char *ipaddr, unsigned char *val1, unsigned char *val2, unsigned char *val3, unsigned char *val4)
{
    unsigned char *p = ipaddr;
    unsigned char tmp_ipaddr[4];
    int i = 0;
    int j = 0;
    while (p) {
        memset(tmp_ipaddr, 0, sizeof(tmp_ipaddr));
        while (*p != '.' && *p != '\0') {
            tmp_ipaddr[i] = *p;
            i++;
            p++;
        }
        if (j == 0) {
            *val1 = atoi(tmp_ipaddr);
        } else if (j == 1) {
            *val2 = atoi(tmp_ipaddr);
        } else if (j == 2) {
            *val3 = atoi(tmp_ipaddr);
        } else if (j == 3) {
            *val4 = atoi(tmp_ipaddr);
            break;
        }
        fprintf(stdout, "yyy\n");
        i = 0;
        j++;
        p++;
    }
    return 0;
}

variable_types:
ipaddr
unsigned char *

variable_types:
p
unsigned char *

variable_types: i int

variable_types: j int


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // rbp
size_t v4; // rax
int v5; // ebp
int v6; // er12
int v7; // er13
__int16 v8; // bx
int v9; // eax
int v10; // er14
char *v11; // r8
char *v12; // r9
int v13; // eax
FILE *v14; // rcx
char *v16; // [rsp+8h] [rbp-A080h]
char *v17; // [rsp+8h] [rbp-A080h]
char *v18; // [rsp+10h] [rbp-A078h]
char *v19; // [rsp+10h] [rbp-A078h]
__int16 v20; // [rsp+1Ch] [rbp-A06Ch]
unsigned int v21; // [rsp+20h] [rbp-A068h] BYREF
unsigned int v22; // [rsp+24h] [rbp-A064h] BYREF
unsigned int v23; // [rsp+28h] [rbp-A060h] BYREF
unsigned int v24; // [rsp+2Ch] [rbp-A05Ch] BYREF
char dest[16]; // [rsp+30h] [rbp-A058h] BYREF
__int128 v26; // [rsp+40h] [rbp-A048h]
char s[41016]; // [rsp+50h] [rbp-A038h] BYREF

v21 = 0;
v22 = 0;
v23 = 0;
v24 = 0;
if ( argc <= 3 )
{
fwrite("./modifypcap_tool <source file> <dest file> <dest ip> <before port> <after port>\n", 1uLL, 0x51uLL, stderr);
exit(1);
}
memset(s, 0, 0xA000uLL);
v3 = argv[3];
*(_OWORD *)dest = 0LL;
v26 = 0LL;
v4 = strlen(v3);
strncpy(dest, v3, v4);
parser_ipaddr_to_int(dest, &v21, &v22, &v23, &v24);
fprintf(_bss_start, "%x, %x, %x, %x\n", v21, v22, v23, v24);
v5 = open(argv[1], 0);
v6 = open(argv[2], 66, 511LL);
v7 = 0;
v8 = atoi(argv[4]);
v20 = atoi(argv[5]);
LABEL_3:
v9 = read(v5, s, 0xA000uLL);
v10 = v9;
if ( v9 )
{
v11 = s;
v12 = &s[v9 - 1 + 1];
while ( 1 )
{
while ( 1 )
{
v13 = (unsigned __int8)*v11;
if ( v13 == v21
&& (unsigned __int8)v11[1] == v22
&& (unsigned __int8)v11[2] == v23
&& (unsigned __int8)v11[3] == v24 )
{
break;
}
if ( v13 == HIBYTE(v8) && v11[1] == (_BYTE)v8 && v7 == 1 )
goto LABEL_13;
LABEL_6:
if ( v12 == ++v11 )
goto LABEL_14;
}
v18 = v11;
v7 = 1;
v16 = v12;
fwrite("xxxxxxxx\n", 1uLL, 9uLL, _bss_start);
v11 = v18;
v12 = v16;
if ( (unsigned __int8)*v18 != HIBYTE(v8) || v18[1] != (_BYTE)v8 )
goto LABEL_6;
LABEL_13:
v14 = _bss_start;
v19 = v12;
v7 = 0;
*v11 = HIBYTE(v20);
v17 = v11;
v11[1] = v20;
fwrite("000\n", 1uLL, 4uLL, v14);
v12 = v19;
v11 = v17 + 1;
if ( v19 == v17 + 1 )
{
LABEL_14:
fwrite("xxx\n", 1uLL, 4uLL, _bss_start);
write(v6, s, v10);
memset(s, 0, 0xA000uLL);
goto LABEL_3;
}
}
}
close(v6);
close(v5);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // rbp
size_t v4; // rax
int v5; // ebp
int v6; // er12
int v7; // er13
__int16 v8; // bx
int v9; // eax
int v10; // er14
char *v11; // r8
char *v12; // r9
int v13; // eax
FILE *v14; // rcx
char *v16; // [rsp+8h] [rbp-A080h]
char *v17; // [rsp+8h] [rbp-A080h]
char *v18; // [rsp+10h] [rbp-A078h]
char *v19; // [rsp+10h] [rbp-A078h]
__int16 v20; // [rsp+1Ch] [rbp-A06Ch]
unsigned int v21; // [rsp+20h] [rbp-A068h] BYREF
unsigned int v22; // [rsp+24h] [rbp-A064h] BYREF
unsigned int v23; // [rsp+28h] [rbp-A060h] BYREF
unsigned int v24; // [rsp+2Ch] [rbp-A05Ch] BYREF
char dest[16]; // [rsp+30h] [rbp-A058h] BYREF
__int128 v26; // [rsp+40h] [rbp-A048h]
char s[41016]; // [rsp+50h] [rbp-A038h] BYREF

v21 = 0;
v22 = 0;
v23 = 0;
v24 = 0;
if ( argc <= 3 )
{
fwrite("./modifypcap_tool <source file> <dest file> <dest ip> <before port> <after port>\n", 1uLL, 0x51uLL, stderr);
exit(1);
}
memset(s, 0, 0xA000uLL);
v3 = argv[3];
*(_OWORD *)dest = 0LL;
v26 = 0LL;
v4 = strlen(v3);
strncpy(dest, v3, v4);
func7(dest, &v21, &v22, &v23, &v24);
fprintf(_bss_start, "%x, %x, %x, %x\n", v21, v22, v23, v24);
v5 = open(argv[1], 0);
v6 = open(argv[2], 66, 511LL);
v7 = 0;
v8 = atoi(argv[4]);
v20 = atoi(argv[5]);
LABEL_3:
v9 = read(v5, s, 0xA000uLL);
v10 = v9;
if ( v9 )
{
v11 = s;
v12 = &s[v9 - 1 + 1];
while ( 1 )
{
while ( 1 )
{
v13 = (unsigned __int8)*v11;
if ( v13 == v21
&& (unsigned __int8)v11[1] == v22
&& (unsigned __int8)v11[2] == v23
&& (unsigned __int8)v11[3] == v24 )
{
break;
}
if ( v13 == HIBYTE(v8) && v11[1] == (_BYTE)v8 && v7 == 1 )
goto LABEL_13;
LABEL_6:
if ( v12 == ++v11 )
goto LABEL_14;
}
v18 = v11;
v7 = 1;
v16 = v12;
fwrite("xxxxxxxx\n", 1uLL, 9uLL, _bss_start);
v11 = v18;
v12 = v16;
if ( (unsigned __int8)*v18 != HIBYTE(v8) || v18[1] != (_BYTE)v8 )
goto LABEL_6;
LABEL_13:
v14 = _bss_start;
v19 = v12;
v7 = 0;
*v11 = HIBYTE(v20);
v17 = v11;
v11[1] = v20;
fwrite("000\n", 1uLL, 4uLL, v14);
v12 = v19;
v11 = v17 + 1;
if ( v19 == v17 + 1 )
{
LABEL_14:
fwrite("xxx\n", 1uLL, 4uLL, _bss_start);
write(v6, s, v10);
memset(s, 0, 0xA000uLL);
goto LABEL_3;
}
}
}
close(v6);
close(v5);
return 0;
}

original_code:
int main(int argc, char *argv[])
{
    int input_fd = 0;
    int output_fd = 0;
    int ret = 0;
    int read_size = 0;
    unsigned char buffer[40960];
    unsigned char *p = ((void *)0);
    unsigned char ipaddr[32];
    unsigned int ipaddr1 = 0;
    unsigned int ipaddr2 = 0;
    unsigned int ipaddr3 = 0;
    unsigned int ipaddr4 = 0;
    int port_in = 0;
    int port_out = 0;
    int modify_flag = 0;
    if (argc < 4) {
        fprintf(stderr, "./modifypcap_tool <source file> <dest file> <dest ip> <before port> <after port>\n");
        exit(1);
    }
    memset(buffer, 0, sizeof(buffer));
    memset(ipaddr, 0, sizeof(ipaddr));
    strncpy(ipaddr, argv[3], strlen(argv[3]));
    parser_ipaddr_to_int(ipaddr, &ipaddr1, &ipaddr2, &ipaddr3, &ipaddr4);
    fprintf(stdout, "%x, %x, %x, %x\n", ipaddr1, ipaddr2, ipaddr3, ipaddr4);
    port_in = atoi(argv[4]);
    port_out = atoi(argv[5]);
    input_fd = open(argv[1], 00);
    output_fd = open(argv[2], 0100 | 02, (0400|0200|0100) | ((0400|0200|0100) >> 3) | (((0400|0200|0100) >> 3) >> 3));
    port_in = atoi(argv[4]);
    port_out = atoi(argv[5]);
    while ((ret = read(input_fd, buffer, sizeof(buffer)))) {
        p = buffer;
        read_size = ret;
        while (read_size != 0) {
            if (p[0] == ipaddr1 && p[1] == ipaddr2 && p[2] == ipaddr3 && p[3] == ipaddr4) {
                fprintf(stdout, "xxxxxxxx\n");
                modify_flag = 1;
            }
            if (((p[0] == ((port_in & 0xFF00) >> 8)) && (p[1] == (port_in & 0xFF))) && modify_flag == 1) {
                p[0] = (port_out & 0xFF00) >> 8;
                p[1] = port_out & 0xFF;
                modify_flag = 0;
                fprintf(stdout, "000\n");
            }
            p++;
            read_size--;
        }
        fprintf(stdout, "xxx\n");
        ret = write(output_fd, buffer, ret);
        memset(buffer, 0, sizeof(buffer));
    }
    close(output_fd);
    close(input_fd);
    return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types:
buffer
unsigned char [40960]

variable_types:
ipaddr
unsigned char [32]


decompiled_code:
__int64 get_local_time()
{
time_t timer; // [rsp+8h] [rbp-10h] BYREF

time(&timer);
fprintf(stderr, "time = [%d]\n", timer);
return (unsigned int)timer;
}

canonical_decompiled_code:
__int64 func0()
{
time_t timer; // [rsp+8h] [rbp-10h] BYREF

time(&timer);
fprintf(stderr, "time = [%d]\n", timer);
return (unsigned int)timer;
}

original_code:
int get_local_time()
{
    time_t time_p;
    time(&time_p);
    fprintf(stderr, "time = [%d]\n", time_p);
    return (int) time_p;
}

canonical_original_code:
int get_local_time()
{
    long time_p;
    time(&time_p);
    fprintf(stderr, "time = [%d]\n", time_p);
    return (int) time_p;
}


decompiled_code:
__int64 __fastcall time_str2int(const char *a1)
{
return (unsigned int)(int)strtod(a1, 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func1(const char *a1)
{
return (unsigned int)(int)strtod(a1, 0LL);
}

original_code:
int time_str2int(unsigned char *str)
{
    return strtod(str, ((void *)0));
}

variable_types:
str
unsigned char *


decompiled_code:
__int64 __fastcall check_time_val(int a1, int a2)
{
return 2 * (unsigned int)((int)abs32(a1 - a2) < 1001) - 1;
}

canonical_decompiled_code:
__int64 __fastcall func2(int a1, int a2)
{
return 2 * (unsigned int)((int)abs32(a1 - a2) < 1001) - 1;
}

original_code:
int check_time_val(int local_time, int remote_time)
{
    if (abs(local_time - remote_time) > 1000) {
        return -1;
    }
    return 1;
}


reduce

repo: TACC/laser

original_code:
void reduce(laser_reduction *reducer, double val) {
  double delta;
  reducer->count++;
  reducer->values[0] += val;
  if(val < reducer->values[2]) reducer->values[2] = val;
  if(val > reducer->values[3]) reducer->values[3] = val;
  delta = val - reducer->values[1];
  reducer->values[1] += delta / reducer->count;
  reducer->values[6] += delta * (val - reducer->values[1]);
  reducer->values[4] = reducer->values[6] / reducer->count;
  if(reducer->custom != ((void *)0)) {
    reducer->values[5] = reducer->custom(reducer->values[5], val, reducer->count);
  }
}

canonical_original_code:
void reduce(struct laser_reduction *reducer, double val) {
  double delta;
  reducer->count++;
  reducer->values[0] += val;
  if(val < reducer->values[2]) reducer->values[2] = val;
  if(val > reducer->values[3]) reducer->values[3] = val;
  delta = val - reducer->values[1];
  reducer->values[1] += delta / reducer->count;
  reducer->values[6] += delta * (val - reducer->values[1]);
  reducer->values[4] = reducer->values[6] / reducer->count;
  if(reducer->custom != ((void *)0)) {
    reducer->values[5] = reducer->custom(reducer->values[5], val, reducer->count);
  }
}

variable_types: struct laser_reduction { short options; unsigned long count; double values[7]; double (*custom)(double, double, unsigned long); } *

variable_types: val double

variable_types: delta double


createReductionEvent

decompiled_code:
__int64 __fastcall createReductionEvent(__int64 a1, char a2, __int64 a3, __int64 a4)
{
__int128 v7; // [rsp+0h] [rbp-428h] BYREF
char v8[1008]; // [rsp+10h] [rbp-418h] BYREF

v7 = 0LL;
memset(v8, 0, sizeof(v8));
if ( (a2 & 1) != 0 )
{
sprintf((char *)&v7, "*Count, %ld;", *(_QWORD *)(a1 + 8));
if ( (a2 & 2) == 0 )
{
LABEL_3:
if ( (a2 & 4) == 0 )
goto LABEL_4;
goto LABEL_11;
}
}
else if ( (a2 & 2) == 0 )
{
goto LABEL_3;
}
sprintf((char *)&v7, "%s *Sum, %lf;", (const char *)&v7, *(double *)(a1 + 16));
if ( (a2 & 4) == 0 )
{
LABEL_4:
if ( (a2 & 8) == 0 )
goto LABEL_5;
goto LABEL_12;
}
LABEL_11:
sprintf((char *)&v7, "%s *Mean, %lf;", (const char *)&v7, *(double *)(a1 + 24));
if ( (a2 & 8) == 0 )
{
LABEL_5:
if ( (a2 & 0x10) == 0 )
goto LABEL_6;
goto LABEL_13;
}
LABEL_12:
sprintf((char *)&v7, "%s *Min, %lf;", (const char *)&v7, *(double *)(a1 + 32));
if ( (a2 & 0x10) == 0 )
{
LABEL_6:
if ( (a2 & 0x20) == 0 )
goto LABEL_7;
LABEL_14:
sprintf((char *)&v7, "%s *Variance, %lf;", (const char *)&v7, *(double *)(a1 + 48));
if ( (a2 & 0x40) == 0 )
return createEvent(a3, a4, 2LL, &v7);
LABEL_15:
sprintf((char *)&v7, "%s *Custom, %lf;", (const char *)&v7, *(double *)(a1 + 56));
return createEvent(a3, a4, 2LL, &v7);
}
LABEL_13:
sprintf((char *)&v7, "%s *Max, %lf;", (const char *)&v7, *(double *)(a1 + 40));
if ( (a2 & 0x20) != 0 )
goto LABEL_14;
LABEL_7:
if ( (a2 & 0x40) != 0 )
goto LABEL_15;
return createEvent(a3, a4, 2LL, &v7);
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, char a2, __int64 a3, __int64 a4)
{
__int128 v7; // [rsp+0h] [rbp-428h] BYREF
char v8[1008]; // [rsp+10h] [rbp-418h] BYREF

v7 = 0LL;
memset(v8, 0, sizeof(v8));
if ( (a2 & 1) != 0 )
{
sprintf((char *)&v7, "*Count, %ld;", *(_QWORD *)(a1 + 8));
if ( (a2 & 2) == 0 )
{
LABEL_3:
if ( (a2 & 4) == 0 )
goto LABEL_4;
goto LABEL_11;
}
}
else if ( (a2 & 2) == 0 )
{
goto LABEL_3;
}
sprintf((char *)&v7, "%s *Sum, %lf;", (const char *)&v7, *(double *)(a1 + 16));
if ( (a2 & 4) == 0 )
{
LABEL_4:
if ( (a2 & 8) == 0 )
goto LABEL_5;
goto LABEL_12;
}
LABEL_11:
sprintf((char *)&v7, "%s *Mean, %lf;", (const char *)&v7, *(double *)(a1 + 24));
if ( (a2 & 8) == 0 )
{
LABEL_5:
if ( (a2 & 0x10) == 0 )
goto LABEL_6;
goto LABEL_13;
}
LABEL_12:
sprintf((char *)&v7, "%s *Min, %lf;", (const char *)&v7, *(double *)(a1 + 32));
if ( (a2 & 0x10) == 0 )
{
LABEL_6:
if ( (a2 & 0x20) == 0 )
goto LABEL_7;
LABEL_14:
sprintf((char *)&v7, "%s *Variance, %lf;", (const char *)&v7, *(double *)(a1 + 48));
if ( (a2 & 0x40) == 0 )
return createEvent(a3, a4, 2LL, &v7);
LABEL_15:
sprintf((char *)&v7, "%s *Custom, %lf;", (const char *)&v7, *(double *)(a1 + 56));
return createEvent(a3, a4, 2LL, &v7);
}
LABEL_13:
sprintf((char *)&v7, "%s *Max, %lf;", (const char *)&v7, *(double *)(a1 + 40));
if ( (a2 & 0x20) != 0 )
goto LABEL_14;
LABEL_7:
if ( (a2 & 0x40) != 0 )
goto LABEL_15;
return createEvent(a3, a4, 2LL, &v7);
}

original_code:
laser_event *createReductionEvent(laser_reduction *reducer, short options, char *title, char *desc) {
  char datastr[1024] = "";
  if(options & 1) sprintf(datastr, "*Count, %ld;", reducer->count);
  if(options & 2) sprintf(datastr, "%s *Sum, %lf;", datastr, reducer->values[0]);
  if(options & 4) sprintf(datastr, "%s *Mean, %lf;", datastr, reducer->values[1]);
  if(options & 8) sprintf(datastr, "%s *Min, %lf;", datastr, reducer->values[2]);
  if(options & 16) sprintf(datastr, "%s *Max, %lf;", datastr, reducer->values[3]);
  if(options & 32) sprintf(datastr, "%s *Variance, %lf;", datastr, reducer->values[4]);
  if(options & 64) sprintf(datastr, "%s *Custom, %lf;", datastr, reducer->values[5]);
  return createEvent(title, desc, 2, datastr);
}

canonical_original_code:
struct laser_event *createReductionEvent(struct laser_reduction *reducer, short options, char *title, char *desc) {
  char datastr[1024] = "";
  if(options & 1) sprintf(datastr, "*Count, %ld;", reducer->count);
  if(options & 2) sprintf(datastr, "%s *Sum, %lf;", datastr, reducer->values[0]);
  if(options & 4) sprintf(datastr, "%s *Mean, %lf;", datastr, reducer->values[1]);
  if(options & 8) sprintf(datastr, "%s *Min, %lf;", datastr, reducer->values[2]);
  if(options & 16) sprintf(datastr, "%s *Max, %lf;", datastr, reducer->values[3]);
  if(options & 32) sprintf(datastr, "%s *Variance, %lf;", datastr, reducer->values[4]);
  if(options & 64) sprintf(datastr, "%s *Custom, %lf;", datastr, reducer->values[5]);
  return createEvent(title, desc, 2, datastr);
}

variable_types: options short

variable_types:
title
char *

variable_types:
desc
char *

variable_types:
datastr
char [1024]

return_type: struct laser_event { char *title; char *desc; long generated; short eventtype; char *data; } *

user_defined_types: struct laser_reduction { short options; unsigned long count; double values[7]; double (*custom)(double, double, unsigned long); }


addEvent

original_code:
void addEvent(laser_report *report, laser_event *event) {
  laser_event **tmp = malloc(sizeof(laser_event*)*(report->numevents+1));
  if(report->events != ((void *)0)) {
    memcpy(tmp, report->events, sizeof(laser_event*)*report->numevents);
    free(report->events);
  }
  report->events = tmp;
  report->events[report->numevents++] = event;
}

canonical_original_code:
void addEvent(struct laser_report *report, struct laser_event *event) {
  struct laser_event **tmp = malloc(sizeof(laser_event*)*(report->numevents+1));
  if(report->events != ((void *)0)) {
    memcpy(tmp, report->events, sizeof(struct laser_event *)*report->numevents);
    free(report->events);
  }
  report->events = tmp;
  report->events[report->numevents++] = event;
}

variable_types: struct laser_report { char *filename; short filetype; char *filetplate; struct { char *title; char **authors; int numauths; char *abstract; unsigned long jobID; char *invocation; unsigned int NP; long walltime; } header; struct laser_event { char *title; char *desc; long generated; short eventtype; char *data; } **events; int numevents; } *

variable_types:
event
struct laser_event *

user_defined_types: struct laser_report { char *filename; short filetype; char *filetplate; struct { char *title; char **authors; int numauths; char *abstract; unsigned long jobID; char *invocation; unsigned int NP; long walltime; } header; struct laser_event **events; int numevents; }


repo: TIHan/TFile

decompiled_code:
_BOOL8 __fastcall mtx_init(pthread_mutex_t *mutex, char a2)
{
int v2; // ebx
pthread_mutexattr_t attr; // [rsp+Ch] [rbp-1Ch] BYREF

pthread_mutexattr_init(&attr);
if ( (a2 & 8) != 0 )
pthread_mutexattr_settype(&attr, 1);
v2 = pthread_mutex_init(mutex, &attr);
pthread_mutexattr_destroy(&attr);
return v2 == 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func0(pthread_mutex_t *mutex, char a2)
{
int v2; // ebx
pthread_mutexattr_t attr; // [rsp+Ch] [rbp-1Ch] BYREF

pthread_mutexattr_init(&attr);
if ( (a2 & 8) != 0 )
pthread_mutexattr_settype(&attr, 1);
v2 = pthread_mutex_init(mutex, &attr);
pthread_mutexattr_destroy(&attr);
return v2 == 0;
}

original_code:
int mtx_init(mtx_t *mtx, int type)
{
  int ret;
  pthread_mutexattr_t attr;
  pthread_mutexattr_init(&attr);
  if (type & 8)
  {
    pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
  }
  ret = pthread_mutex_init(mtx, &attr);
  pthread_mutexattr_destroy(&attr);
  return ret == 0 ? 1 : 0;
}

canonical_original_code:
int mtx_init(union pthread_mutex_t *mtx, int type)
{
  int ret;
  union pthread_mutexattr_t attr;
  pthread_mutexattr_init(&attr);
  if (type & 8)
  {
    pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
  }
  ret = pthread_mutex_init(mtx, &attr);
  pthread_mutexattr_destroy(&attr);
  return ret == 0 ? 1 : 0;
}

variable_types: union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } *

variable_types: type int

variable_types: ret int

variable_types: union pthread_mutexattr_t { char __size[4]; int __align; }

user_defined_types: union pthread_mutex_t { struct __pthread_mutex_s __data; char __size[40]; long __align; }

user_defined_types: struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list __list; }


decompiled_code:
// attributes: thunk
int mtx_destroy(pthread_mutex_t *mutex)
{
return pthread_mutex_destroy(mutex);
}

canonical_decompiled_code:
int func1(pthread_mutex_t *mutex)
{
return pthread_mutex_destroy(mutex);
}

original_code:
void mtx_destroy(mtx_t *mtx)
{
  pthread_mutex_destroy(mtx);
}

canonical_original_code:
void mtx_destroy(union pthread_mutex_t *mtx)
{
  pthread_mutex_destroy(mtx);
}

user_defined_types: struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; }


decompiled_code:
_BOOL8 __fastcall mtx_lock(pthread_mutex_t *a1)
{
return pthread_mutex_lock(a1) == 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func2(pthread_mutex_t *a1)
{
return pthread_mutex_lock(a1) == 0;
}

original_code:
int mtx_lock(mtx_t *mtx)
{
  return pthread_mutex_lock(mtx) == 0 ? 1 : 0;
}

canonical_original_code:
int mtx_lock(union pthread_mutex_t *mtx)
{
  return pthread_mutex_lock(mtx) == 0 ? 1 : 0;
}


decompiled_code:
__int64 mtx_timedlock()
{
return 0LL;
}

canonical_decompiled_code:
__int64 func3()
{
return 0LL;
}

original_code:
int mtx_timedlock(mtx_t *mtx, const struct timespec *ts)
{
  (void)mtx;
  (void)ts;
  return 0;
}

canonical_original_code:
int mtx_timedlock(union pthread_mutex_t *mtx, struct timespec *ts)
{
  (void)mtx;
  (void)ts;
  return 0;
}

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


decompiled_code:
__int64 __fastcall mtx_trylock(pthread_mutex_t *a1)
{
return pthread_mutex_trylock(a1) == 0 ? 1 : 3;
}

canonical_decompiled_code:
__int64 __fastcall func4(pthread_mutex_t *a1)
{
return pthread_mutex_trylock(a1) == 0 ? 1 : 3;
}

original_code:
int mtx_trylock(mtx_t *mtx)
{
  return (pthread_mutex_trylock(mtx) == 0) ? 1 : 3;
}

canonical_original_code:
int mtx_trylock(union pthread_mutex_t *mtx)
{
  return (pthread_mutex_trylock(mtx) == 0) ? 1 : 3;
}


decompiled_code:
_BOOL8 __fastcall mtx_unlock(pthread_mutex_t *a1)
{
return pthread_mutex_unlock(a1) == 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func5(pthread_mutex_t *a1)
{
return pthread_mutex_unlock(a1) == 0;
}

original_code:
int mtx_unlock(mtx_t *mtx)
{
  return pthread_mutex_unlock(mtx) == 0 ? 1 : 0;;
}

canonical_original_code:
int mtx_unlock(union pthread_mutex_t *mtx)
{
  return pthread_mutex_unlock(mtx) == 0 ? 1 : 0;;
}


decompiled_code:
_BOOL8 __fastcall cnd_init(pthread_cond_t *a1)
{
return pthread_cond_init(a1, 0LL) == 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func6(pthread_cond_t *a1)
{
return pthread_cond_init(a1, 0LL) == 0;
}

original_code:
int cnd_init(cnd_t *cond)
{
  return pthread_cond_init(cond, ((void *)0)) == 0 ? 1 : 0;
}

canonical_original_code:
int cnd_init(union pthread_cond_t *cond)
{
  return pthread_cond_init(cond, ((void *)0)) == 0 ? 1 : 0;
}

variable_types: union pthread_cond_t { struct __pthread_cond_s { union { unsigned long long __wseq; struct { unsigned int __low; unsigned int __high; } __wseq32; }; union { unsigned long long __g1_start; struct { unsigned int __low; unsigned int __high; } __g1_start32; }; unsigned int __g_refs[2]; unsigned int __g_size[2]; unsigned int __g1_orig_size; unsigned int __wrefs; unsigned int __g_signals[2]; } __data; char __size[48]; long long __align; } *

user_defined_types: union pthread_cond_t { struct __pthread_cond_s __data; char __size[48]; long long __align; }


decompiled_code:
// attributes: thunk
int cnd_destroy(pthread_cond_t *cond)
{
return pthread_cond_destroy(cond);
}

canonical_decompiled_code:
int func7(pthread_cond_t *cond)
{
return pthread_cond_destroy(cond);
}

original_code:
void cnd_destroy(cnd_t *cond)
{
  pthread_cond_destroy(cond);
}

canonical_original_code:
void cnd_destroy(union pthread_cond_t *cond)
{
  pthread_cond_destroy(cond);
}

user_defined_types: struct __pthread_cond_s { union { unsigned long long __wseq; struct { unsigned int __low; unsigned int __high; } __wseq32; }; union { unsigned long long __g1_start; struct { unsigned int __low; unsigned int __high; } __g1_start32; }; unsigned int __g_refs[2]; unsigned int __g_size[2]; unsigned int __g1_orig_size; unsigned int __wrefs; unsigned int __g_signals[2]; }


decompiled_code:
_BOOL8 __fastcall cnd_signal(pthread_cond_t *a1)
{
return pthread_cond_signal(a1) == 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func8(pthread_cond_t *a1)
{
return pthread_cond_signal(a1) == 0;
}

original_code:
int cnd_signal(cnd_t *cond)
{
  return pthread_cond_signal(cond) == 0 ? 1 : 0;
}

canonical_original_code:
int cnd_signal(union pthread_cond_t *cond)
{
  return pthread_cond_signal(cond) == 0 ? 1 : 0;
}


decompiled_code:
// attributes: thunk
_BOOL8 __fastcall cnd_broadcast(pthread_cond_t *a1)
{
return cnd_signal(a1);
}

canonical_decompiled_code:
_BOOL8 __fastcall func9(pthread_cond_t *a1)
{
return func8(a1);
}

original_code:
int cnd_broadcast(cnd_t *cond)
{
  return pthread_cond_signal(cond) == 0 ? 1 : 0;
}

canonical_original_code:
int cnd_broadcast(union pthread_cond_t *cond)
{
  return pthread_cond_signal(cond) == 0 ? 1 : 0;
}


decompiled_code:
_BOOL8 __fastcall cnd_wait(pthread_cond_t *a1, pthread_mutex_t *a2)
{
return pthread_cond_wait(a1, a2) == 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func10(pthread_cond_t *a1, pthread_mutex_t *a2)
{
return pthread_cond_wait(a1, a2) == 0;
}

original_code:
int cnd_wait(cnd_t *cond, mtx_t *mtx)
{
  return pthread_cond_wait(cond, mtx) == 0 ? 1 : 0;
}

canonical_original_code:
int cnd_wait(union pthread_cond_t *cond, union pthread_mutex_t *mtx)
{
  return pthread_cond_wait(cond, mtx) == 0 ? 1 : 0;
}


decompiled_code:
__int64 __fastcall cnd_timedwait(pthread_cond_t *a1, pthread_mutex_t *a2, const struct timespec *a3)
{
int v3; // eax
__int64 result; // rax

v3 = pthread_cond_timedwait(a1, a2, a3);
if ( v3 == 110 )
result = 2LL;
else
result = v3 == 0;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func11(pthread_cond_t *a1, pthread_mutex_t *a2, const struct timespec *a3)
{
int v3; // eax
__int64 result; // rax

v3 = pthread_cond_timedwait(a1, a2, a3);
if ( v3 == 110 )
result = 2LL;
else
result = v3 == 0;
return result;
}

original_code:
int cnd_timedwait(cnd_t *cond, mtx_t *mtx, const struct timespec *ts)
{
  int ret;
  ret = pthread_cond_timedwait(cond, mtx, ts);
  if (ret == 110)
  {
    return 2;
  }
  return ret == 0 ? 1 : 0;
}

canonical_original_code:
int cnd_timedwait(union pthread_cond_t *cond, union pthread_mutex_t *mtx, struct timespec *ts)
{
  int ret;
  ret = pthread_cond_timedwait(cond, mtx, ts);
  if (ret == 110)
  {
    return 2;
  }
  return ret == 0 ? 1 : 0;
}

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


decompiled_code:
__int64 __fastcall thrd_create(pthread_t *newthread, __int64 a2, __int64 a3)
{
_QWORD *v4; // rax
void *v5; // rbp

v4 = malloc(0x10uLL);
if ( !v4 )
return 4LL;
*v4 = a2;
v4[1] = a3;
v5 = v4;
if ( pthread_create(newthread, 0LL, (void *(*)(void *))thrd_wrapper_function, v4) )
{
*newthread = 0LL;
}
else if ( *newthread )
{
return 1LL;
}
free(v5);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func12(pthread_t *newthread, __int64 a2, __int64 a3)
{
_QWORD *v4; // rax
void *v5; // rbp

v4 = malloc(0x10uLL);
if ( !v4 )
return 4LL;
*v4 = a2;
v4[1] = a3;
v5 = v4;
if ( pthread_create(newthread, 0LL, (void *(*)(void *))thrd_wrapper_function, v4) )
{
*newthread = 0LL;
}
else if ( *newthread )
{
return 1LL;
}
free(v5);
return 0LL;
}

original_code:
int thrd_create(thrd_t *thr, thrd_start_t func, void *arg)
{
  _thread_start_info* ti = (_thread_start_info*)malloc(sizeof(_thread_start_info));
  if (ti == ((void *)0))
  {
    return 4;
  }
  ti->mFunction = func;
  ti->mArg = arg;
  if(pthread_create(thr, ((void *)0), _thrd_wrapper_function, (void *)ti) != 0)
  {
    *thr = 0;
  }
  if(!*thr)
  {
    free(ti);
    return 0;
  }
  return 1;
}

canonical_original_code:
int thrd_create(unsigned long *thr, int (*func)(void *arg), void *arg)
{
  struct _thread_start_info *ti = (_thread_start_info*)malloc(sizeof(_thread_start_info));
  if (ti == ((void *)0))
  {
    return 4;
  }
  ti->mFunction = func;
  ti->mArg = arg;
  if(pthread_create(thr, ((void *)0), _thrd_wrapper_function, (void *)ti) != 0)
  {
    *thr = 0;
  }
  if(!*thr)
  {
    free(ti);
    return 0;
  }
  return 1;
}

variable_types:
thr
unsigned long *

variable_types:
func
int (*)(void *arg)

variable_types:
arg
void *

variable_types: struct _thread_start_info { int (*mFunction)(void *arg); void *mArg; } *


decompiled_code:
// attributes: thunk
pthread_t thrd_current(void)
{
return pthread_self();
}

canonical_decompiled_code:
pthread_t func13(void)
{
return pthread_self();
}

original_code:
thrd_t thrd_current(void)
{
  return pthread_self();
}

canonical_original_code:
unsigned long thrd_current()
{
  return pthread_self();
}

return_type: unsigned long


decompiled_code:
__int64 thrd_detach()
{
return 0LL;
}

canonical_decompiled_code:
__int64 func14()
{
return 0LL;
}

original_code:
int thrd_detach(thrd_t thr)
{
  (void)thr;
  return 0;
}

canonical_original_code:
int thrd_detach(unsigned long thr)
{
  (void)thr;
  return 0;
}

variable_types:
thr
unsigned long


decompiled_code:
// attributes: thunk
int thrd_equal(pthread_t thread1, pthread_t thread2)
{
return pthread_equal(thread1, thread2);
}

canonical_decompiled_code:
int func15(pthread_t thread1, pthread_t thread2)
{
return pthread_equal(thread1, thread2);
}

original_code:
int thrd_equal(thrd_t thr0, thrd_t thr1)
{
  return pthread_equal(thr0, thr1);
}

canonical_original_code:
int thrd_equal(unsigned long thr0, unsigned long thr1)
{
  return pthread_equal(thr0, thr1);
}


decompiled_code:
void __fastcall __noreturn thrd_exit(int a1)
{
_DWORD *v1; // rax

v1 = malloc(4uLL);
if ( v1 )
*v1 = a1;
pthread_exit(v1);
}

canonical_decompiled_code:
void __fastcall __noreturn func16(int a1)
{
_DWORD *v1; // rax

v1 = malloc(4uLL);
if ( v1 )
*v1 = a1;
pthread_exit(v1);
}

original_code:
void thrd_exit(int res)
{
  void *pres = malloc(sizeof(int));
  if (pres != ((void *)0))
  {
    *(int*)pres = res;
  }
  pthread_exit(pres);
}

canonical_original_code:
void thrd_exit(int res)
{
  void *pres = malloc(sizeof(int));
  if (pres != ((void *)0))
  {
    *(int *)pres = res;
  }
  pthread_exit(pres);
}

variable_types: res int

variable_types:
pres
void *


decompiled_code:
__int64 __fastcall thrd_join(pthread_t a1, int *a2)
{
int v2; // ebx
__int64 result; // rax
void *thread_return; // [rsp+8h] [rbp-20h] BYREF

v2 = pthread_join(a1, &thread_return);
result = 0LL;
if ( !v2 )
{
if ( thread_return )
{
v2 = *(_DWORD *)thread_return;
free(thread_return);
}
result = 1LL;
if ( a2 )
*a2 = v2;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func17(pthread_t a1, int *a2)
{
int v2; // ebx
__int64 result; // rax
void *thread_return; // [rsp+8h] [rbp-20h] BYREF

v2 = pthread_join(a1, &thread_return);
result = 0LL;
if ( !v2 )
{
if ( thread_return )
{
v2 = *(_DWORD *)thread_return;
free(thread_return);
}
result = 1LL;
if ( a2 )
*a2 = v2;
}
return result;
}

original_code:
int thrd_join(thrd_t thr, int *res)
{
  void *pres;
  int ires = 0;
  if (pthread_join(thr, &pres) != 0)
  {
    return 0;
  }
  if (pres != ((void *)0))
  {
    ires = *(int*)pres;
    free(pres);
  }
  if (res != ((void *)0))
  {
    *res = ires;
  }
  return 1;
}

canonical_original_code:
int thrd_join(unsigned long thr, int *res)
{
  void *pres;
  int ires = 0;
  if (pthread_join(thr, &pres) != 0)
  {
    return 0;
  }
  if (pres != ((void *)0))
  {
    ires = *(int *)pres;
    free(pres);
  }
  if (res != ((void *)0))
  {
    *res = ires;
  }
  return 1;
}

variable_types:
res
int *

variable_types: ires int


decompiled_code:
__int64 __fastcall thrd_sleep(_QWORD *a1, _QWORD *a2)
{
unsigned int v2; // er12
__syscall_slong_t v3; // rbx
struct timespec v5; // [rsp+0h] [rbp-28h] BYREF

if ( clock_gettime(1, &v5) )
return (unsigned int)-2;
v2 = 0;
v3 = (a1[1] - v5.tv_nsec + 500) / 1000 + 1000000 * (*a1 - v5.tv_sec);
if ( v3 > 999999 )
{
do
{
v3 -= 999999LL;
usleep(0xF423Fu);
}
while ( v3 > 999999 );
goto LABEL_4;
}
if ( v3 > 0 )
LABEL_4:
usleep(v3);
if ( a2 )
{
*a2 = 0LL;
a2[1] = 0LL;
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func18(_QWORD *a1, _QWORD *a2)
{
unsigned int v2; // er12
__syscall_slong_t v3; // rbx
struct timespec v5; // [rsp+0h] [rbp-28h] BYREF

if ( clock_gettime(1, &v5) )
return (unsigned int)-2;
v2 = 0;
v3 = (a1[1] - v5.tv_nsec + 500) / 1000 + 1000000 * (*a1 - v5.tv_sec);
if ( v3 > 999999 )
{
do
{
v3 -= 999999LL;
usleep(0xF423Fu);
}
while ( v3 > 999999 );
goto LABEL_4;
}
if ( v3 > 0 )
LABEL_4:
usleep(v3);
if ( a2 )
{
*a2 = 0LL;
a2[1] = 0LL;
}
return v2;
}

original_code:
int thrd_sleep(const struct timespec *time_point, struct timespec *remaining)
{
  struct timespec now;
  long delta;
  if (clock_gettime(1, &now) != 0)
    return -2;
  delta = (time_point->tv_sec - now.tv_sec) * 1000000L +
          (time_point->tv_nsec - now.tv_nsec + 500L) / 1000L;
  while (delta > 999999L)
  {
    usleep(999999);
    delta -= 999999L;
  }
  if (delta > 0L)
  {
    usleep((useconds_t)delta);
  }
  if (remaining)
  {
    remaining->tv_sec = 0;
    remaining->tv_nsec = 0;
  }
  return 0;
}

canonical_original_code:
int thrd_sleep(struct timespec *time_point, struct timespec *remaining)
{
  struct timespec now;
  long delta;
  if (clock_gettime(1, &now) != 0)
    return -2;
  delta = (time_point->tv_sec - now.tv_sec) * 1000000L +
          (time_point->tv_nsec - now.tv_nsec + 500L) / 1000L;
  while (delta > 999999L)
  {
    usleep(999999);
    delta -= 999999L;
  }
  if (delta > 0L)
  {
    usleep((unsigned int)delta);
  }
  if (remaining)
  {
    remaining->tv_sec = 0;
    remaining->tv_nsec = 0;
  }
  return 0;
}

variable_types:
remaining
struct timespec *

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

variable_types: delta long


decompiled_code:
// attributes: thunk
int thrd_yield(void)
{
return sched_yield();
}

canonical_decompiled_code:
int func19(void)
{
return sched_yield();
}

original_code:
void thrd_yield(void)
{
  sched_yield();
}

canonical_original_code:
void thrd_yield()
{
  sched_yield();
}


decompiled_code:
_BOOL8 __fastcall tss_create(pthread_key_t *a1, void (*a2)(void *))
{
return pthread_key_create(a1, a2) == 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func20(pthread_key_t *a1, void (*a2)(void *))
{
return pthread_key_create(a1, a2) == 0;
}

original_code:
int tss_create(tss_t *key, tss_dtor_t dtor)
{
  if (pthread_key_create(key, dtor) != 0)
  {
    return 0;
  }
  return 1;
}

canonical_original_code:
int tss_create(unsigned int *key, void (*dtor)(void *val))
{
  if (pthread_key_create(key, dtor) != 0)
  {
    return 0;
  }
  return 1;
}

variable_types:
key
unsigned int *

variable_types:
dtor
void (*)(void *val)


decompiled_code:
// attributes: thunk
int tss_delete(pthread_key_t key)
{
return pthread_key_delete(key);
}

canonical_decompiled_code:
int func21(pthread_key_t key)
{
return pthread_key_delete(key);
}

original_code:
void tss_delete(tss_t key)
{
  pthread_key_delete(key);
}

canonical_original_code:
void tss_delete(unsigned int key)
{
  pthread_key_delete(key);
}

variable_types:
key
unsigned int


decompiled_code:
// attributes: thunk
void *tss_get(pthread_key_t key)
{
return pthread_getspecific(key);
}

canonical_decompiled_code:
void *func22(pthread_key_t key)
{
return pthread_getspecific(key);
}

original_code:
void *tss_get(tss_t key)
{
  return pthread_getspecific(key);
}

canonical_original_code:
void *tss_get(unsigned int key)
{
  return pthread_getspecific(key);
}

return_type: void *


decompiled_code:
_BOOL8 __fastcall tss_set(pthread_key_t a1, const void *a2)
{
return pthread_setspecific(a1, a2) == 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func23(pthread_key_t a1, const void *a2)
{
return pthread_setspecific(a1, a2) == 0;
}

original_code:
int tss_set(tss_t key, void *val)
{
  if (pthread_setspecific(key, val) != 0)
  {
    return 0;
  }
  return 1;
}

canonical_original_code:
int tss_set(unsigned int key, void *val)
{
  if (pthread_setspecific(key, val) != 0)
  {
    return 0;
  }
  return 1;
}

variable_types:
val
void *


launchStats

decompiled_code:
__int64 launchStats()
{
__int64 v1; // [rsp+8h] [rbp-10h] BYREF

v1 = 0LL;
readDataBase(&v1);
stats(v1);
return freeDataList(v1);
}

canonical_decompiled_code:
__int64 func0()
{
__int64 v1; // [rsp+8h] [rbp-10h] BYREF

v1 = 0LL;
readDataBase(&v1);
stats(v1);
return freeDataList(v1);
}

original_code:
void launchStats()
{
 dataList *l = ((void *)0);
 readDataBase(&l);
 stats(l);
 freeDataList(l);
}

canonical_original_code:
void launchStats()
{
 struct _dataList *l = ((void *)0);
 readDataBase(&l);
 stats(l);
 freeDataList(l);
}

variable_types: struct _dataList { struct _dateCell { int day; int month; int year; int hours; int min; int sec; int uday; int uhours; int umin; int usec; } *date; struct _dataLine { char counter[255]; char threadName[255]; long value; } *data; struct _dataList *next; } *

user_defined_types: struct _dataList { struct _dateCell *date; struct _dataLine *data; struct _dataList *next; }


launchStatsFile

decompiled_code:
__int64 __fastcall launchStatsFile(__int64 a1)
{
__int64 v2; // [rsp+8h] [rbp-10h] BYREF

v2 = 0LL;
importFile(a1, &v2);
stats(v2);
return freeDataList(v2);
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
__int64 v2; // [rsp+8h] [rbp-10h] BYREF

v2 = 0LL;
importFile(a1, &v2);
stats(v2);
return freeDataList(v2);
}

original_code:
void launchStatsFile(char *log)
{
 dataList *l = ((void *)0);
 importFile(log, &l);
 stats(l);
 freeDataList(l);
}

canonical_original_code:
void launchStatsFile(char *log)
{
 struct _dataList *l = ((void *)0);
 importFile(log, &l);
 stats(l);
 freeDataList(l);
}

variable_types:
log
char *

user_defined_types: struct _dateCell { int day; int month; int year; int hours; int min; int sec; int uday; int uhours; int umin; int usec; }

user_defined_types: struct _dataLine { char counter[255]; char threadName[255]; long value; }


launchImport

decompiled_code:
__int64 __fastcall launchImport(__int64 a1)
{
__int64 v2; // [rsp+8h] [rbp-10h] BYREF

v2 = 0LL;
importFile(a1, &v2);
insertDataList(v2);
return freeDataList(v2);
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
__int64 v2; // [rsp+8h] [rbp-10h] BYREF

v2 = 0LL;
importFile(a1, &v2);
insertDataList(v2);
return freeDataList(v2);
}

original_code:
void launchImport(char *log)
{
 dataList *l = ((void *)0);
 importFile(log, &l);
 insertDataList(l);
 freeDataList(l);
}

canonical_original_code:
void launchImport(char *log)
{
 struct _dataList *l = ((void *)0);
 importFile(log, &l);
 insertDataList(l);
 freeDataList(l);
}


createDataBase

decompiled_code:
__int64 createDataBase()
{
__int64 v0; // rax

v0 = openDb("../test.db");
sqlite3_close(v0);
return createTable("../test.db");
}

canonical_decompiled_code:
__int64 func3()
{
__int64 v0; // rax

v0 = openDb("../test.db");
sqlite3_close(v0);
return createTable("../test.db");
}

original_code:
void createDataBase()
{
 sqlite3_close(openDb("../test.db"));
 createTable("../test.db");
}


dropDataBase

decompiled_code:
int dropDataBase()
{
return remove("../test.db");
}

canonical_decompiled_code:
int func4()
{
return remove("../test.db");
}

original_code:
void dropDataBase()
{
 remove("../test.db");
}


displayHelp

decompiled_code:
int displayHelp()
{
puts("Options de suricastat: \n");
puts(aParDefaultLePr);
puts(" -h: affiche ce menu");
puts(aCCreeLaBaseDeD);
puts(aDSupprimeLaBas);
puts(aFLitLeFichierP);
return puts(aIImporteLePass);
}

canonical_decompiled_code:
int func5()
{
puts("Options de suricastat: \n");
puts(aParDefaultLePr);
puts(" -h: affiche ce menu");
puts(aCCreeLaBaseDeD);
puts(aDSupprimeLaBas);
puts(aFLitLeFichierP);
return puts(aIImporteLePass);
}

original_code:
void displayHelp()
{
 printf("Options de suricastat: \n\n");
 printf("Par default le programme lance les statistiques sur les données importées dans la base\n");
 printf("  -h: affiche ce menu\n");
 printf("  -c: cree la base de données à l'emplacement ../test.db\n");
 printf("  -d: supprime la base de données\n");
 printf("  -f: lit le fichier passé en parametre et affiche les stats\n");
 printf("  -i: importe le passé en parametre dans la base de données\n");
}


main

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

v3 = 0;
while ( 1 )
{
v4 = getopt(argc, (char *const *)argv, "hcdf:i:");
if ( v4 == -1 )
break;
switch ( v4 )
{
case 'c':
v3 = 1;
createDataBase();
break;
case 'd':
v3 = 1;
dropDataBase();
break;
case 'f':
v3 = 1;
launchStatsFile((__int64)optarg);
break;
case 'h':
v3 = 1;
displayHelp();
break;
case 'i':
launchImport((__int64)optarg);
break;
default:
continue;
}
}
if ( !v3 )
launchStats();
return 0;
}

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

v3 = 0;
while ( 1 )
{
v4 = getopt(argc, (char *const *)argv, "hcdf:i:");
if ( v4 == -1 )
break;
switch ( v4 )
{
case 'c':
v3 = 1;
func3();
break;
case 'd':
v3 = 1;
func4();
break;
case 'f':
v3 = 1;
func1((__int64)optarg);
break;
case 'h':
v3 = 1;
func5();
break;
case 'i':
func2((__int64)optarg);
break;
default:
continue;
}
}
if ( !v3 )
func0();
return 0;
}

original_code:
int main(int argc, char *argv[])
{
 int option;
 char opt;
 option = 0;
 while((opt = getopt(argc, argv, "hcdf:i:")) != -1)
 {
  switch(opt)
  {
   case 'h':
    displayHelp();
    option = 1;
    break;
   case 'c':
    createDataBase();
    option = 1;
    break;
   case 'd':
    dropDataBase();
    option = 1;
    break;
   case 'f':
    launchStatsFile(optarg);
    option = 1;
    break;
   case 'i':
    launchImport(optarg);
    break;
  }
 }
 if(option == 0)
  launchStats();
 return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: option int

variable_types: opt char


printDataList

original_code:
void printDataList(dataList *l)
{
 while(l != ((void *)0))
 {
  if(l->data != ((void *)0))
   printf("%s, %s, %lld", l->data->counter, l->data->threadName, l->data->value);
  if(l->date != ((void *)0))
   printf("  %.2d/%.2d/%.4d %.2d:%.2d:%.2d %.2d:%.2d:%.2d:%.2d",
    l->date->day,
    l->date->month,
    l->date->year,
    l->date->hours,
    l->date->min,
    l->date->sec,
    l->date->uday,
    l->date->uhours,
    l->date->umin,
    l->date->usec);
  printf("\n");
  l = l->next;
 }
}

canonical_original_code:
void printDataList(struct _dataList *l)
{
 while(l != ((void *)0))
 {
  if(l->data != ((void *)0))
   printf("%s, %s, %lld", l->data->counter, l->data->threadName, l->data->value);
  if(l->date != ((void *)0))
   printf("  %.2d/%.2d/%.4d %.2d:%.2d:%.2d %.2d:%.2d:%.2d:%.2d",
    l->date->day,
    l->date->month,
    l->date->year,
    l->date->hours,
    l->date->min,
    l->date->sec,
    l->date->uday,
    l->date->uhours,
    l->date->umin,
    l->date->usec);
  printf("\n");
  l = l->next;
 }
}


convertUDateToSec

decompiled_code:
__int64 __fastcall convertUDateToSec(_DWORD *a1)
{
return (unsigned int)(86400 * a1[6] + 3600 * a1[7] + a1[9] + 60 * a1[8]);
}

original_code:
int convertUDateToSec(dateCell *d)
{
 return d->usec + (60 * d->umin) + (3600 * d->uhours) + (86400 * d->uday);
}

canonical_original_code:
int convertUDateToSec(struct _dateCell *d)
{
 return d->usec + (60 * d->umin) + (3600 * d->uhours) + (86400 * d->uday);
}

variable_types: struct _dateCell { int day; int month; int year; int hours; int min; int sec; int uday; int uhours; int umin; int usec; } *


compareUDateCell

original_code:
int compareUDateCell(dateCell *d1, dateCell *d2)
{
 if(d1->uday == d2->uday)
 {
  if(d1->uhours == d2->uhours)
  {
   if(d1->umin == d2->umin)
   {
    if(d1->usec == d2->usec)
     return 0;
    else if(d1->usec > d2->usec)
     return 1;
    else
     return -1;
   }
   else if(d1->umin > d2->umin)
    return 1;
   else
    return -1;
  }
  else if(d1->uhours > d2->uhours)
   return 1;
  else
   return -1;
 }
 else if(d1->uday > d2->uday)
  return 1;
 else
  return -1;
}

canonical_original_code:
int compareUDateCell(struct _dateCell *d1, struct _dateCell *d2)
{
 if(d1->uday == d2->uday)
 {
  if(d1->uhours == d2->uhours)
  {
   if(d1->umin == d2->umin)
   {
    if(d1->usec == d2->usec)
     return 0;
    else if(d1->usec > d2->usec)
     return 1;
    else
     return -1;
   }
   else if(d1->umin > d2->umin)
    return 1;
   else
    return -1;
  }
  else if(d1->uhours > d2->uhours)
   return 1;
  else
   return -1;
 }
 else if(d1->uday > d2->uday)
  return 1;
 else
  return -1;
}


freeDataList

decompiled_code:
void __fastcall freeDataList(void *ptr)
{
void **v1; // rbx
void **v2; // rbp

if ( ptr )
{
v1 = (void **)ptr;
do
{
v2 = v1;
v1 = (void **)v1[2];
free(*v2);
free(v2[1]);
free(v2);
}
while ( v1 );
}
}

canonical_decompiled_code:
void __fastcall func3(void *ptr)
{
void **v1; // rbx
void **v2; // rbp

if ( ptr )
{
v1 = (void **)ptr;
do
{
v2 = v1;
v1 = (void **)v1[2];
free(*v2);
free(v2[1]);
free(v2);
}
while ( v1 );
}
}

original_code:
void freeDataList(dataList *l)
{
 dataList *tmp = ((void *)0);
 while(l != ((void *)0))
 {
  tmp = l;
  l = l->next;
  free(tmp->date);
  free(tmp->data);
  free(tmp);
 }
}

canonical_original_code:
void freeDataList(struct _dataList *l)
{
 struct _dataList *tmp = ((void *)0);
 while(l != ((void *)0))
 {
  tmp = l;
  l = l->next;
  free(tmp->date);
  free(tmp->data);
  free(tmp);
 }
}


calcNbDropForCounter

original_code:
int64_t calcNbDropForCounter(dataList *l, char *counterName, char *threadName, int run)
{
 int64_t count, numRun;
 dateCell *d = ((void *)0);
 count = 0;
 numRun = 0;
 while(l != ((void *)0))
 {
  if(l->data != ((void *)0))
  {
   if(l->date != ((void *)0))
   {
    if(d == ((void *)0))
    {
     d = l->date;
     numRun++;
    }
    if(compareUDateCell(l->date, d) == -1)
    {
     d = l->date;
     numRun ++;
    }
    else
     d = l->date;
    if(run == numRun)
     if(strcmp(l->data->threadName, threadName) == 0)
      if(strcmp(l->data->counter, counterName) == 0)
       count = l->data->value;
   }
  }
  l = l->next;
 }
 return count;
}

canonical_original_code:
long calcNbDropForCounter(struct _dataList *l, char *counterName, char *threadName, int run)
{
 long count; long numRun;
 struct _dateCell *d = ((void *)0);
 count = 0;
 numRun = 0;
 while(l != ((void *)0))
 {
  if(l->data != ((void *)0))
  {
   if(l->date != ((void *)0))
   {
    if(d == ((void *)0))
    {
     d = l->date;
     numRun++;
    }
    if(compareUDateCell(l->date, d) == -1)
    {
     d = l->date;
     numRun ++;
    }
    else
     d = l->date;
    if(run == numRun)
     if(strcmp(l->data->threadName, threadName) == 0)
      if(strcmp(l->data->counter, counterName) == 0)
       count = l->data->value;
   }
  }
  l = l->next;
 }
 return count;
}

variable_types:
counterName
char *

variable_types:
threadName
char *

variable_types: run int

variable_types: count long

variable_types: numRun long

return_type: long


clacNbRun

decompiled_code:
__int64 __fastcall clacNbRun(_QWORD *a1)
{
_QWORD *v1; // rbx
__int64 v2; // rsi
unsigned int v3; // er12
int v4; // eax

if ( !a1 )
return 0;
v1 = a1;
v2 = 0LL;
v3 = 0;
do
{
if ( *v1 )
{
if ( !v2 )
{
++v3;
v2 = *v1;
}
v4 = compareUDateCell(*v1, v2);
v2 = *v1;
if ( v4 == -1 )
++v3;
}
v1 = (_QWORD *)v1[2];
}
while ( v1 );
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func1(_QWORD *a1)
{
_QWORD *v1; // rbx
__int64 v2; // rsi
unsigned int v3; // er12
int v4; // eax

if ( !a1 )
return 0;
v1 = a1;
v2 = 0LL;
v3 = 0;
do
{
if ( *v1 )
{
if ( !v2 )
{
++v3;
v2 = *v1;
}
v4 = compareUDateCell(*v1, v2);
v2 = *v1;
if ( v4 == -1 )
++v3;
}
v1 = (_QWORD *)v1[2];
}
while ( v1 );
return v3;
}

original_code:
int clacNbRun(dataList *l)
{
 int count;
 dateCell *d = ((void *)0);
 count = 0;
 while(l != ((void *)0))
 {
  if(l->date != ((void *)0))
  {
   if(d == ((void *)0))
   {
    d = l->date;
    count ++;
   }
   if(compareUDateCell(l->date, d) == -1)
   {
    d = l->date;
    count ++;
   }
   else
    d = l->date;
  }
  l = l->next;
 }
 return count;
}

canonical_original_code:
int clacNbRun(struct _dataList *l)
{
 int count;
 struct _dateCell *d = ((void *)0);
 count = 0;
 while(l != ((void *)0))
 {
  if(l->date != ((void *)0))
  {
   if(d == ((void *)0))
   {
    d = l->date;
    count ++;
   }
   if(compareUDateCell(l->date, d) == -1)
   {
    d = l->date;
    count ++;
   }
   else
    d = l->date;
  }
  l = l->next;
 }
 return count;
}

variable_types: count int


nbSecondeInRun

decompiled_code:
__int64 __fastcall nbSecondeInRun(_QWORD *a1, int a2)
{
int v2; // er12
_DWORD *v3; // rbp
_QWORD *v4; // rbx

if ( !a1 )
nbSecondeInRun_cold();
v2 = 0;
v3 = 0LL;
v4 = a1;
do
{
while ( 1 )
{
if ( !*v4 )
goto LABEL_4;
if ( !v3 )
{
++v2;
v3 = (_DWORD *)*v4;
}
if ( (unsigned int)compareUDateCell(*v4, v3) == -1 )
break;
v3 = (_DWORD *)*v4;
LABEL_4:
v4 = (_QWORD *)v4[2];
if ( !v4 )
return (unsigned int)(86400 * v3[6] + 3600 * v3[7] + v3[9] + 60 * v3[8]);
}
if ( v2 == a2 )
break;
v3 = (_DWORD *)*v4;
v4 = (_QWORD *)v4[2];
++v2;
}
while ( v4 );
return (unsigned int)(86400 * v3[6] + 3600 * v3[7] + v3[9] + 60 * v3[8]);
}

original_code:
int nbSecondeInRun(dataList *l, int run)
{
 int count;
 dateCell *d = ((void *)0);
 count = 0;
 while(l != ((void *)0))
 {
  if(l->date != ((void *)0))
  {
   if(d == ((void *)0))
   {
    d = l->date;
    count ++;
   }
   if(compareUDateCell(l->date, d) == -1)
   {
    if(count == run)
     break;
    d = l->date;
    count ++;
   }
   else
    d = l->date;
  }
  l = l->next;
 }
 return (d->usec*1)+
  (d->umin*60*1)+
  (d->uhours*60*60*1)+
  (d->uday*24*60*60*1);
}

canonical_original_code:
int nbSecondeInRun(struct _dataList *l, int run)
{
 int count;
 struct _dateCell *d = ((void *)0);
 count = 0;
 while(l != ((void *)0))
 {
  if(l->date != ((void *)0))
  {
   if(d == ((void *)0))
   {
    d = l->date;
    count ++;
   }
   if(compareUDateCell(l->date, d) == -1)
   {
    if(count == run)
     break;
    d = l->date;
    count ++;
   }
   else
    d = l->date;
  }
  l = l->next;
 }
 return (d->usec*1)+
  (d->umin*60*1)+
  (d->uhours*60*60*1)+
  (d->uday*24*60*60*1);
}


calcNbThread

decompiled_code:
__int64 __fastcall calcNbThread(__int64 a1, const char ***a2)
{
__int64 v2; // rbp
__int64 v3; // rbx
const char *v4; // rdi
const char *v5; // rbx
int v6; // er15
const char **i; // r14
const char **v8; // rax
char **v9; // rbx
char *v10; // rdx
char *v12; // rax
char *v13; // rax
unsigned int v14; // [rsp+Ch] [rbp-4Ch]
const char **ptr; // [rsp+10h] [rbp-48h]

if ( !a1 )
return 0;
v14 = 0;
v2 = a1;
do
{
while ( 1 )
{
v3 = *(_QWORD *)(v2 + 8);
if ( v3 )
{
if ( v14 )
{
ptr = *a2;
v4 = **a2;
}
else
{
ptr = (const char **)malloc(8uLL);
*a2 = ptr;
v12 = (char *)calloc(0xFFuLL, 1uLL);
*ptr = v12;
v13 = strcpy(v12, (const char *)(*(_QWORD *)(v2 + 8) + 255LL));
v14 = 1;
v3 = *(_QWORD *)(v2 + 8);
v4 = v13;
}
v5 = (const char *)(v3 + 255);
v6 = 0;
for ( i = ptr + 1; ; ++i )
{
if ( !strcmp(v4, v5) )
v6 = 1;
if ( i == &ptr[v14] )
break;
v4 = *i;
}
if ( !v6 )
break;
}
v2 = *(_QWORD *)(v2 + 16);
if ( !v2 )
return v14;
}
v8 = (const char **)realloc(ptr, 8LL * (int)++v14);
v9 = (char **)&v8[(int)v14 - 1];
*a2 = v8;
v10 = (char *)malloc(0xFFuLL);
*v9 = v10;
memset(v10, 0, 0xF8uLL);
*((_DWORD *)v10 + 62) = 0;
*((_WORD *)v10 + 126) = 0;
v10[254] = 0;
strcpy(*v9, (const char *)(*(_QWORD *)(v2 + 8) + 255LL));
v2 = *(_QWORD *)(v2 + 16);
}
while ( v2 );
return v14;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, const char ***a2)
{
__int64 v2; // rbp
__int64 v3; // rbx
const char *v4; // rdi
const char *v5; // rbx
int v6; // er15
const char **i; // r14
const char **v8; // rax
char **v9; // rbx
char *v10; // rdx
char *v12; // rax
char *v13; // rax
unsigned int v14; // [rsp+Ch] [rbp-4Ch]
const char **ptr; // [rsp+10h] [rbp-48h]

if ( !a1 )
return 0;
v14 = 0;
v2 = a1;
do
{
while ( 1 )
{
v3 = *(_QWORD *)(v2 + 8);
if ( v3 )
{
if ( v14 )
{
ptr = *a2;
v4 = **a2;
}
else
{
ptr = (const char **)malloc(8uLL);
*a2 = ptr;
v12 = (char *)calloc(0xFFuLL, 1uLL);
*ptr = v12;
v13 = strcpy(v12, (const char *)(*(_QWORD *)(v2 + 8) + 255LL));
v14 = 1;
v3 = *(_QWORD *)(v2 + 8);
v4 = v13;
}
v5 = (const char *)(v3 + 255);
v6 = 0;
for ( i = ptr + 1; ; ++i )
{
if ( !strcmp(v4, v5) )
v6 = 1;
if ( i == &ptr[v14] )
break;
v4 = *i;
}
if ( !v6 )
break;
}
v2 = *(_QWORD *)(v2 + 16);
if ( !v2 )
return v14;
}
v8 = (const char **)realloc(ptr, 8LL * (int)++v14);
v9 = (char **)&v8[(int)v14 - 1];
*a2 = v8;
v10 = (char *)malloc(0xFFuLL);
*v9 = v10;
memset(v10, 0, 0xF8uLL);
*((_DWORD *)v10 + 62) = 0;
*((_WORD *)v10 + 126) = 0;
v10[254] = 0;
strcpy(*v9, (const char *)(*(_QWORD *)(v2 + 8) + 255LL));
v2 = *(_QWORD *)(v2 + 16);
}
while ( v2 );
return v14;
}

original_code:
int calcNbThread(dataList *l, char ***threadNames)
{
 int i, count, test;
 count = 0;
 while(l != ((void *)0))
 {
  if(l->data != ((void *)0))
  {
   if(count == 0)
   {
    count++;
    *threadNames = (char**) malloc(sizeof(char*) * count);
    (*threadNames)[count-1] = (char*) malloc(sizeof(char) * 255);
    memset((*threadNames)[count-1], '\0', 255);
    strcpy((*threadNames)[count-1], l->data->threadName);
   }
   for(i=0, test=0; i<count; i++)
    if(strcmp((*threadNames)[i], l->data->threadName) == 0)
     test = 1;
   if(test == 0)
   {
    count++;
    *threadNames = (char**) realloc((*threadNames), sizeof(char*) * count);
    (*threadNames)[count-1] = (char*) malloc(sizeof(char) * 255);
    memset((*threadNames)[count-1], '\0', 255);
    strcpy((*threadNames)[count-1], l->data->threadName);
   }
  }
  l = l->next;
 }
 return count;
}

canonical_original_code:
int calcNbThread(struct _dataList *l, char ***threadNames)
{
 int i; int count; int test;
 count = 0;
 while(l != ((void *)0))
 {
  if(l->data != ((void *)0))
  {
   if(count == 0)
   {
    count++;
    *threadNames = (char **) malloc(sizeof(char *) * count);
    (*threadNames)[count-1] = (char *) malloc(sizeof(char) * 255);
    memset((*threadNames)[count-1], '\0', 255);
    strcpy((*threadNames)[count-1], l->data->threadName);
   }
   for(i=0, test=0; i<count; i++)
    if(strcmp((*threadNames)[i], l->data->threadName) == 0)
     test = 1;
   if(test == 0)
   {
    count++;
    *threadNames = (char **) realloc((*threadNames), sizeof(char *) * count);
    (*threadNames)[count-1] = (char *) malloc(sizeof(char) * 255);
    memset((*threadNames)[count-1], '\0', 255);
    strcpy((*threadNames)[count-1], l->data->threadName);
   }
  }
  l = l->next;
 }
 return count;
}

variable_types:
threadNames
char ***

variable_types: i int

variable_types: test int


calcNbCounter

decompiled_code:
__int64 __fastcall calcNbCounter(__int64 a1, const char ***a2)
{
__int64 v2; // rbx
const char *v3; // r13
const char *v4; // rdi
int v5; // er15
const char **i; // r14
const char **v7; // rax
char **v8; // rbp
char *v9; // rdx
char *v11; // rax
const char *v12; // rsi
char *v13; // rax
unsigned int v14; // [rsp+Ch] [rbp-4Ch]
const char **ptr; // [rsp+10h] [rbp-48h]

if ( !a1 )
return 0;
v14 = 0;
v2 = a1;
do
{
while ( 1 )
{
v3 = *(const char **)(v2 + 8);
if ( v3 )
{
if ( v14 )
{
ptr = *a2;
v4 = **a2;
}
else
{
ptr = (const char **)malloc(8uLL);
*a2 = ptr;
v11 = (char *)calloc(0xFFuLL, 1uLL);
v12 = *(const char **)(v2 + 8);
*ptr = v11;
v13 = strcpy(v11, v12);
v14 = 1;
v3 = *(const char **)(v2 + 8);
v4 = v13;
}
v5 = 0;
for ( i = ptr + 1; ; ++i )
{
if ( !strcmp(v4, v3) )
v5 = 1;
if ( i == &ptr[v14] )
break;
v4 = *i;
}
if ( !v5 )
break;
}
v2 = *(_QWORD *)(v2 + 16);
if ( !v2 )
return v14;
}
v7 = (const char **)realloc(ptr, 8LL * (int)++v14);
v8 = (char **)&v7[(int)v14 - 1];
*a2 = v7;
v9 = (char *)malloc(0xFFuLL);
*v8 = v9;
memset(v9, 0, 0xF8uLL);
*((_DWORD *)v9 + 62) = 0;
*((_WORD *)v9 + 126) = 0;
v9[254] = 0;
strcpy(*v8, *(const char **)(v2 + 8));
v2 = *(_QWORD *)(v2 + 16);
}
while ( v2 );
return v14;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, const char ***a2)
{
__int64 v2; // rbx
const char *v3; // r13
const char *v4; // rdi
int v5; // er15
const char **i; // r14
const char **v7; // rax
char **v8; // rbp
char *v9; // rdx
char *v11; // rax
const char *v12; // rsi
char *v13; // rax
unsigned int v14; // [rsp+Ch] [rbp-4Ch]
const char **ptr; // [rsp+10h] [rbp-48h]

if ( !a1 )
return 0;
v14 = 0;
v2 = a1;
do
{
while ( 1 )
{
v3 = *(const char **)(v2 + 8);
if ( v3 )
{
if ( v14 )
{
ptr = *a2;
v4 = **a2;
}
else
{
ptr = (const char **)malloc(8uLL);
*a2 = ptr;
v11 = (char *)calloc(0xFFuLL, 1uLL);
v12 = *(const char **)(v2 + 8);
*ptr = v11;
v13 = strcpy(v11, v12);
v14 = 1;
v3 = *(const char **)(v2 + 8);
v4 = v13;
}
v5 = 0;
for ( i = ptr + 1; ; ++i )
{
if ( !strcmp(v4, v3) )
v5 = 1;
if ( i == &ptr[v14] )
break;
v4 = *i;
}
if ( !v5 )
break;
}
v2 = *(_QWORD *)(v2 + 16);
if ( !v2 )
return v14;
}
v7 = (const char **)realloc(ptr, 8LL * (int)++v14);
v8 = (char **)&v7[(int)v14 - 1];
*a2 = v7;
v9 = (char *)malloc(0xFFuLL);
*v8 = v9;
memset(v9, 0, 0xF8uLL);
*((_DWORD *)v9 + 62) = 0;
*((_WORD *)v9 + 126) = 0;
v9[254] = 0;
strcpy(*v8, *(const char **)(v2 + 8));
v2 = *(_QWORD *)(v2 + 16);
}
while ( v2 );
return v14;
}

original_code:
int calcNbCounter(dataList *l, char ***counterName)
{
 int i, count, test;
 count = 0;
 while(l != ((void *)0))
 {
  if(l->data != ((void *)0))
  {
   if(count == 0)
   {
    count++;
    *counterName = (char**) malloc(sizeof(char*) * count);
    (*counterName)[count-1] = (char*) malloc(sizeof(char) * 255);
    memset((*counterName)[count-1], '\0', 255);
    strcpy((*counterName)[count-1], l->data->counter);
   }
   for(i=0, test=0; i<count; i++)
    if(strcmp((*counterName)[i], l->data->counter) == 0)
     test = 1;
   if(test == 0)
   {
    count++;
    *counterName = (char**) realloc((*counterName), sizeof(char*) * count);
    (*counterName)[count-1] = (char*) malloc(sizeof(char) * 255);
    memset((*counterName)[count-1], '\0', 255);
    strcpy((*counterName)[count-1], l->data->counter);
   }
  }
  l = l->next;
 }
 return count;
}

canonical_original_code:
int calcNbCounter(struct _dataList *l, char ***counterName)
{
 int i; int count; int test;
 count = 0;
 while(l != ((void *)0))
 {
  if(l->data != ((void *)0))
  {
   if(count == 0)
   {
    count++;
    *counterName = (char **) malloc(sizeof(char *) * count);
    (*counterName)[count-1] = (char *) malloc(sizeof(char) * 255);
    memset((*counterName)[count-1], '\0', 255);
    strcpy((*counterName)[count-1], l->data->counter);
   }
   for(i=0, test=0; i<count; i++)
    if(strcmp((*counterName)[i], l->data->counter) == 0)
     test = 1;
   if(test == 0)
   {
    count++;
    *counterName = (char **) realloc((*counterName), sizeof(char *) * count);
    (*counterName)[count-1] = (char *) malloc(sizeof(char) * 255);
    memset((*counterName)[count-1], '\0', 255);
    strcpy((*counterName)[count-1], l->data->counter);
   }
  }
  l = l->next;
 }
 return count;
}

variable_types:
counterName
char ***


stats

decompiled_code:
int __fastcall stats(_QWORD *a1)
{
unsigned int v1; // ebp
unsigned int v2; // er14
int result; // eax
__int64 v4; // rax
unsigned int v5; // ebp
__int64 v6; // r14
unsigned __int64 v7; // rbx
__int64 v8; // r13
__int64 v9; // r15
const char *v10; // rsi
int v11; // ebx
int v12; // eax
__int64 v13; // [rsp+8h] [rbp-70h]
__int64 v14; // [rsp+10h] [rbp-68h]
int v15; // [rsp+1Ch] [rbp-5Ch]
int v16; // [rsp+28h] [rbp-50h]
int v17; // [rsp+2Ch] [rbp-4Ch]
const char **v18; // [rsp+30h] [rbp-48h] BYREF
const char **v19; // [rsp+38h] [rbp-40h] BYREF

v18 = (const char **)malloc(8uLL);
v19 = (const char **)malloc(8uLL);
v1 = calcNbCounter((__int64)a1, &v18);
v2 = calcNbThread((__int64)a1, &v19);
v16 = v2;
v17 = clacNbRun(a1);
printf("Nombre de run: %d\n", (unsigned int)v17);
printf("Nombre de thread: %d\n", v2);
result = printf("Nombre de compteur: %d\n", v1);
if ( v17 > 0 )
{
v13 = 0LL;
v4 = v2 - 1;
v5 = 0;
v6 = 0LL;
v14 = 8 * v4 + 8;
do
{
printf(" Run %d\n", v5);
v15 = v5++;
if ( v16 > 0 )
{
v7 = 0LL;
do
{
v8 = calcNbDropForCounter(a1, *v18, v19[v7 / 8], v5);
v9 = calcNbDropForCounter(a1, v18[1], v19[v7 / 8], v5);
v6 += v9;
v10 = v19[v7 / 8];
v7 += 8LL;
printf(" %16s: %16lld | %16lld | %f\n", v10, v8, v9, (float)((float)(int)v9 / (float)(int)v8));
v13 += v8;
}
while ( v7 != v14 );
}
puts("_______________________________________________________________________________");
printf(" %18s: %16lld | %16lld | %f\n", "TOTAL", v13, v6, (float)((float)(int)v6 / (float)(int)v13));
v11 = nbSecondeInRun(a1, v15);
v12 = nbSecondeInRun(a1, v15);
result = printf(
" Moyenne paquets/secondes: %10.1f | Moyenne drops/secondes: %10.1f\n\n",
(float)((float)(int)v13 / (float)v12),
(float)((float)(int)v6 / (float)v11));
}
while ( v5 != v17 );
}
return result;
}

original_code:
void stats(dataList *l)
{
 int i, j, nbCounter, nbThread, nbRun;
 int64_t drop1, drop2, nbDrop1Run, nbDrop2Run;
 char **counterNames = ((void *)0);
 char **threadNames = ((void *)0);
 counterNames = (char**) malloc(sizeof(char*));
 threadNames = (char**) malloc(sizeof(char*));
 nbCounter = calcNbCounter(l, &counterNames);
 nbThread = calcNbThread(l, &threadNames);
 nbRun = clacNbRun(l);
 nbDrop1Run = 0;
 nbDrop2Run = 0;
 printf("Nombre de run: %d\n", nbRun);
 printf("Nombre de thread: %d\n", nbThread);
 printf("Nombre de compteur: %d\n", nbCounter);
 for(i=0; i<nbRun; i++)
 {
  printf("  Run %d\n", i);
  for(j=0; j<nbThread; j++)
  {
   drop1 = calcNbDropForCounter(l, counterNames[0], threadNames[j], i+1);
   drop2 = calcNbDropForCounter(l, counterNames[1], threadNames[j], i+1);
   printf("    %16s: %16lld | %16lld | %f\n", threadNames[j], drop1, drop2, (float)drop2/(float)drop1);
   nbDrop1Run += drop1;
   nbDrop2Run += drop2;
  }
  printf("_______________________________________________________________________________\n");
  printf("  %18s: %16lld | %16lld | %f\n", "TOTAL", nbDrop1Run, nbDrop2Run, (float)nbDrop2Run/(float)nbDrop1Run);
  printf("    Moyenne paquets/secondes: %10.1f | Moyenne drops/secondes: %10.1f\n\n",
   (float)nbDrop1Run/(float)nbSecondeInRun(l, i),
   (float)nbDrop2Run/(float)nbSecondeInRun(l, i));
 }
}

canonical_original_code:
void stats(struct _dataList *l)
{
 int i; int j; int nbCounter; int nbThread; int nbRun;
 long drop1; long drop2; long nbDrop1Run; long nbDrop2Run;
 char **counterNames = ((void *)0);
 char **threadNames = ((void *)0);
 counterNames = (char **) malloc(sizeof(char *));
 threadNames = (char **) malloc(sizeof(char *));
 nbCounter = calcNbCounter(l, &counterNames);
 nbThread = calcNbThread(l, &threadNames);
 nbRun = clacNbRun(l);
 nbDrop1Run = 0;
 nbDrop2Run = 0;
 printf("Nombre de run: %d\n", nbRun);
 printf("Nombre de thread: %d\n", nbThread);
 printf("Nombre de compteur: %d\n", nbCounter);
 for(i=0; i<nbRun; i++)
 {
  printf("  Run %d\n", i);
  for(j=0; j<nbThread; j++)
  {
   drop1 = calcNbDropForCounter(l, counterNames[0], threadNames[j], i+1);
   drop2 = calcNbDropForCounter(l, counterNames[1], threadNames[j], i+1);
   printf("    %16s: %16lld | %16lld | %f\n", threadNames[j], drop1, drop2, (float)drop2/(float)drop1);
   nbDrop1Run += drop1;
   nbDrop2Run += drop2;
  }
  printf("_______________________________________________________________________________\n");
  printf("  %18s: %16lld | %16lld | %f\n", "TOTAL", nbDrop1Run, nbDrop2Run, (float)nbDrop2Run/(float)nbDrop1Run);
  printf("    Moyenne paquets/secondes: %10.1f | Moyenne drops/secondes: %10.1f\n\n",
   (float)nbDrop1Run/(float)nbSecondeInRun(l, i),
   (float)nbDrop2Run/(float)nbSecondeInRun(l, i));
 }
}

variable_types: struct _dataList { struct _dateCell { int day; int month; int year; int hours; int min; int sec; int uday; int uhours; int umin; int usec; } *date; struct _dataLine { char counter[255]; char threadName[255]; long value; } *data; struct _dataList *next; } *

variable_types: j int

variable_types: nbCounter int

variable_types: nbThread int

variable_types: nbRun int

variable_types:
counterNames
char **

variable_types:
threadNames
char **


parseDateLine

original_code:
void parseDateLine(char *data, dateCell *actDate)
{
 sscanf(data, "Date: %d/%d/%d -- %d:%d:%d (uptime: %dd, %dh %dm %ds)",
   &(actDate->month),
   &(actDate->day),
   &(actDate->year),
   &(actDate->hours),
   &(actDate->min),
   &(actDate->sec),
   &(actDate->uday),
   &(actDate->uhours),
   &(actDate->umin),
   &(actDate->usec)
       );
}

canonical_original_code:
void parseDateLine(char *data, struct _dateCell *actDate)
{
 sscanf(data, "Date: %d/%d/%d -- %d:%d:%d (uptime: %dd, %dh %dm %ds)",
   &(actDate->month),
   &(actDate->day),
   &(actDate->year),
   &(actDate->hours),
   &(actDate->min),
   &(actDate->sec),
   &(actDate->uday),
   &(actDate->uhours),
   &(actDate->umin),
   &(actDate->usec)
       );
}

variable_types:
data
char *

variable_types: struct _dateCell { int day; int month; int year; int hours; int min; int sec; int uday; int uhours; int umin; int usec; } *


parseDataLine

decompiled_code:
__int64 __fastcall parseDataLine(__int64 a1, __int64 a2)
{
return _isoc99_sscanf(a1, "%s | %s | %lld", a2, a2 + 255, a2 + 512);
}

original_code:
void parseDataLine(char *data, dataLine *actLine)
{
 sscanf(data, "%s | %s | %lld",
   actLine->counter,
   actLine->threadName,
   &(actLine->value)
  );
}

canonical_original_code:
void parseDataLine(char *data, struct _dataLine *actLine)
{
 sscanf(data, "%s | %s | %lld",
   actLine->counter,
   actLine->threadName,
   &(actLine->value)
  );
}

variable_types: struct _dataLine { char counter[255]; char threadName[255]; long value; } *


printDate

original_code:
void printDate(dateCell *date)
{
 printf("%.2d/%.2d/%.2d %.2d:%.2d:%.2d ,%.2d, %.2d %.2d %.2d\n",
   date->day,
   date->month,
   date->year,
   date->hours,
   date->min,
   date->sec,
   date->uday,
   date->uhours,
   date->umin,
   date->usec
       );
}

canonical_original_code:
void printDate(struct _dateCell *date)
{
 printf("%.2d/%.2d/%.2d %.2d:%.2d:%.2d ,%.2d, %.2d %.2d %.2d\n",
   date->day,
   date->month,
   date->year,
   date->hours,
   date->min,
   date->sec,
   date->uday,
   date->uhours,
   date->umin,
   date->usec
       );
}


insertToList

decompiled_code:
int __fastcall insertToList(__int64 a1, __int64 a2)
{
__int64 v3; // rbx
_QWORD *v4; // r14
char *v5; // rbp
__m128i *v6; // rax
__int64 v7; // rax
__int64 v8; // rdi

v3 = 0LL;
v4 = malloc(0x10uLL);
v5 = (char *)malloc(0xFFuLL);
*v4 = v5;
v6 = (__m128i *)malloc(0xFFuLL);
strcpy(v5 + 16, "ackets");
*(__m128i *)v5 = _mm_load_si128((const __m128i *)&LC5);
strcpy(v6[1].m128i_i8, "rops");
*v6 = _mm_load_si128((const __m128i *)&LC6);
v4[1] = v6;
LODWORD(v7) = strcmp(v5, (const char *)a2);
if ( !(_DWORD)v7 )
goto LABEL_4;
while ( ++v3 != 2 )
{
while ( 1 )
{
LODWORD(v7) = strcmp((const char *)v4[v3], (const char *)a2);
if ( (_DWORD)v7 )
break;
LABEL_4:
++v3;
newDataList(*(_QWORD *)a1 + 16LL);
v8 = *(_QWORD *)(*(_QWORD *)a1 + 16LL);
*(_QWORD *)a1 = v8;
newDataLine(v8 + 8);
strcpy(*(char **)(*(_QWORD *)a1 + 8LL), (const char *)a2);
strcpy((char *)(*(_QWORD *)(*(_QWORD *)a1 + 8LL) + 255LL), (const char *)(a2 + 255));
v7 = *(_QWORD *)(*(_QWORD *)a1 + 8LL);
*(_QWORD *)(v7 + 512) = *(_QWORD *)(a2 + 512);
if ( v3 == 2 )
return v7;
}
}
return v7;
}

canonical_decompiled_code:
int __fastcall func4(__int64 a1, __int64 a2)
{
__int64 v3; // rbx
_QWORD *v4; // r14
char *v5; // rbp
__m128i *v6; // rax
__int64 v7; // rax
__int64 v8; // rdi

v3 = 0LL;
v4 = malloc(0x10uLL);
v5 = (char *)malloc(0xFFuLL);
*v4 = v5;
v6 = (__m128i *)malloc(0xFFuLL);
strcpy(v5 + 16, "ackets");
*(__m128i *)v5 = _mm_load_si128((const __m128i *)&LC5);
strcpy(v6[1].m128i_i8, "rops");
*v6 = _mm_load_si128((const __m128i *)&LC6);
v4[1] = v6;
LODWORD(v7) = strcmp(v5, (const char *)a2);
if ( !(_DWORD)v7 )
goto LABEL_4;
while ( ++v3 != 2 )
{
while ( 1 )
{
LODWORD(v7) = strcmp((const char *)v4[v3], (const char *)a2);
if ( (_DWORD)v7 )
break;
LABEL_4:
++v3;
newDataList(*(_QWORD *)a1 + 16LL);
v8 = *(_QWORD *)(*(_QWORD *)a1 + 16LL);
*(_QWORD *)a1 = v8;
newDataLine(v8 + 8);
strcpy(*(char **)(*(_QWORD *)a1 + 8LL), (const char *)a2);
strcpy((char *)(*(_QWORD *)(*(_QWORD *)a1 + 8LL) + 255LL), (const char *)(a2 + 255));
v7 = *(_QWORD *)(*(_QWORD *)a1 + 8LL);
*(_QWORD *)(v7 + 512) = *(_QWORD *)(a2 + 512);
if ( v3 == 2 )
return v7;
}
}
return v7;
}

original_code:
void insertToList(dataList **l, dataLine *actLine)
{
 int i;
 char **toInsert;
 toInsert = malloc(sizeof(char*) * 2);
 for(i=0; i<2; i++)
  toInsert[i] = malloc(sizeof(char)*255);
 sprintf(toInsert[0], "capture.kernel_packets");
 sprintf(toInsert[1], "capture.kernel_drops");
 for(i=0; i<2; i++)
 {
  if(strcmp(toInsert[i], actLine->counter) == 0)
  {
   newDataList(&((*l)->next));
   *l = (*l)->next;
   newDataLine(&((*l)->data));
   strcpy((*l)->data->counter, actLine->counter);
   strcpy((*l)->data->threadName, actLine->threadName);
   (*l)->data->value = actLine->value;
  }
 }
}

canonical_original_code:
void insertToList(struct _dataList **l, struct _dataLine *actLine)
{
 int i;
 char **toInsert;
 toInsert = malloc(sizeof(char *) * 2);
 for(i=0; i<2; i++)
  toInsert[i] = malloc(sizeof(char)*255);
 sprintf(toInsert[0], "capture.kernel_packets");
 sprintf(toInsert[1], "capture.kernel_drops");
 for(i=0; i<2; i++)
 {
  if(strcmp(toInsert[i], actLine->counter) == 0)
  {
   newDataList(&((*l)->next));
   *l = (*l)->next;
   newDataLine(&((*l)->data));
   strcpy((*l)->data->counter, actLine->counter);
   strcpy((*l)->data->threadName, actLine->threadName);
   (*l)->data->value = actLine->value;
  }
 }
}

variable_types: struct _dataList { struct _dateCell { int day; int month; int year; int hours; int min; int sec; int uday; int uhours; int umin; int usec; } *date; struct _dataLine { char counter[255]; char threadName[255]; long value; } *data; struct _dataList *next; } **

variable_types:
actLine
struct _dataLine *

variable_types:
toInsert
char **


decompiled_code:
void free_timeout()
{
if ( timeout )
free(timeout);
}

canonical_decompiled_code:
void func7()
{
if ( timeout )
free(timeout);
}

original_code:
static void free_timeout()
{
    if (timeout)
        free(timeout);
}


decompiled_code:
void check_timeout()
{
__time_t *v0; // rbp
struct timeval v1; // [rsp+0h] [rbp-18h] BYREF

v0 = (__time_t *)timeout;
if ( timeout )
{
gettimeofday(&v1, 0LL);
if ( *v0 == v1.tv_sec )
{
if ( v0[1] >= v1.tv_usec )
return;
}
else if ( *v0 >= v1.tv_sec )
{
return;
}
timeout = 0LL;
((void (__fastcall *)(__time_t))v0[2])(v0[3]);
free(v0);
}
}

canonical_decompiled_code:
void func8()
{
__time_t *v0; // rbp
struct timeval v1; // [rsp+0h] [rbp-18h] BYREF

v0 = (__time_t *)timeout;
if ( timeout )
{
gettimeofday(&v1, 0LL);
if ( *v0 == v1.tv_sec )
{
if ( v0[1] >= v1.tv_usec )
return;
}
else if ( *v0 >= v1.tv_sec )
{
return;
}
timeout = 0LL;
((void (__fastcall *)(__time_t))v0[2])(v0[3]);
free(v0);
}
}

original_code:
static void check_timeout()
{
    if (timeout) {
        struct timeval now;
        gettimeofday(&now, ((void *)0));
        if ((((&timeout->timeout)->tv_sec == (&now)->tv_sec) ? ((&timeout->timeout)->tv_usec < (&now)->tv_usec) : ((&timeout->timeout)->tv_sec < (&now)->tv_sec))) {
            timeout_t *t = timeout;
            timeout = ((void *)0);
            t->callback_func(t->args);
            free(t);
        }
    }
}

canonical_original_code:
static void check_timeout()
{
    if (timeout) {
        struct timeval now;
        gettimeofday(&now, ((void *)0));
        if ((((&timeout->timeout)->tv_sec == (&now)->tv_sec) ? ((&timeout->timeout)->tv_usec < (&now)->tv_usec) : ((&timeout->timeout)->tv_sec < (&now)->tv_sec))) {
            struct timeout_entry *t = timeout;
            timeout = ((void *)0);
            t->callback_func(t->args);
            free(t);
        }
    }
}

variable_types: struct timeout_entry { struct timeval { long tv_sec; long tv_usec; } timeout; void (*callback_func)(void *arg); void *args; } *

user_defined_types: struct timeout_entry { struct timeval timeout; void (*callback_func)(void *arg); void *args; }


decompiled_code:
int handle_keyboard()
{
char *v0; // rbx
size_t v1; // rax
_QWORD v3[3]; // [rsp-8h] [rbp-68h] BYREF
char v4[8]; // [rsp+10h] [rbp-50h] BYREF
char s[16]; // [rsp+18h] [rbp-48h] BYREF
__int128 v6; // [rsp+28h] [rbp-38h]
__int64 v7; // [rsp+38h] [rbp-28h]

*(_OWORD *)s = 0LL;
v6 = 0LL;
v7 = 0LL;
if ( !fgets(s, 40, stdin) )
__assert_fail("fgets(command, MAX_LEN, stdin)", "timeout.c", 0x59u, "handle_keyboard");
v0 = (char *)v3;
v1 = strlen(s);
v3[1] = "quit";
v4[v1 + 7] = 0;
v3[2] = "q";
if ( !strcmp(s, "exit") )
{
LABEL_5:
puts("Goodbye :)");
exit(0);
}
while ( 1 )
{
v0 += 8;
if ( v0 == v4 )
break;
if ( !strcmp(s, *(const char **)v0) )
goto LABEL_5;
}
if ( !strcmp(s, "help") )
{
puts("Thank you, here is some help:\n\texit\tquit the program\n\tquit\tquit the program\n\tq\tquit the program");
has_asked_for_help = 1;
}
printf("yolo >> ");
return fflush(_bss_start);
}

canonical_decompiled_code:
int func9()
{
char *v0; // rbx
size_t v1; // rax
_QWORD v3[3]; // [rsp-8h] [rbp-68h] BYREF
char v4[8]; // [rsp+10h] [rbp-50h] BYREF
char s[16]; // [rsp+18h] [rbp-48h] BYREF
__int128 v6; // [rsp+28h] [rbp-38h]
__int64 v7; // [rsp+38h] [rbp-28h]

*(_OWORD *)s = 0LL;
v6 = 0LL;
v7 = 0LL;
if ( !fgets(s, 40, stdin) )
__assert_fail("fgets(command, MAX_LEN, stdin)", "timeout.c", 0x59u, "handle_keyboard");
v0 = (char *)v3;
v1 = strlen(s);
v3[1] = "quit";
v4[v1 + 7] = 0;
v3[2] = "q";
if ( !strcmp(s, "exit") )
{
LABEL_5:
puts("Goodbye :)");
exit(0);
}
while ( 1 )
{
v0 += 8;
if ( v0 == v4 )
break;
if ( !strcmp(s, *(const char **)v0) )
goto LABEL_5;
}
if ( !strcmp(s, "help") )
{
puts("Thank you, here is some help:\n\texit\tquit the program\n\tquit\tquit the program\n\tq\tquit the program");
has_asked_for_help = 1;
}
printf("yolo >> ");
return fflush(_bss_start);
}

original_code:
static void handle_keyboard()
{
    char command[40] = {'\0'};
    ((void) sizeof ((fgets(command, 40, stdin)) ? 1 : 0), __extension__ ({ if (fgets(command, 40, stdin)) ; else __assert_fail ("fgets(command, MAX_LEN, stdin)", "timeout.c", 89, __extension__ __PRETTY_FUNCTION__); }));
    command[strlen(command)-1] = '\0';
    const char *exit_commands[] = {"exit", "quit", "q"};
    int i;
    for (i = 0; i < 3; ++i)
    {
        if (!strcmp(command, exit_commands[i])) {
            printf("Goodbye :)\n");
            exit(0);
        }
    }
    if (!strcmp(command, "help")) {
        printf("Thank you, here is some help:\n\t"
               "exit\tquit the program\n\t"
               "quit\tquit the program\n\t"
               "q\tquit the program\n");
        has_asked_for_help = 1;
    }
    do { printf("yolo >> "); fflush(stdout); } while (0);
}

canonical_original_code:
static void handle_keyboard()
{
    char command[40] = {'\0'};
    ((void) sizeof ((fgets(command, 40, stdin)) ? 1 : 0), __extension__ ({ if (fgets(command, 40, stdin)) ; else __assert_fail ("fgets(command, MAX_LEN, stdin)", "timeout.c", 89, __extension__ __PRETTY_FUNCTION__); }));
    command[strlen(command)-1] = '\0';
    char *exit_commands[] = {"exit", "quit", "q"};
    int i;
    for (i = 0; i < 3; ++i)
    {
        if (!strcmp(command, exit_commands[i])) {
            printf("Goodbye :)\n");
            exit(0);
        }
    }
    if (!strcmp(command, "help")) {
        printf("Thank you, here is some help:\n\t"
               "exit\tquit the program\n\t"
               "quit\tquit the program\n\t"
               "q\tquit the program\n");
        has_asked_for_help = 1;
    }
    do { printf("yolo >> "); fflush(stdout); } while (0);
}

variable_types:
command
char [40]

variable_types: i int


decompiled_code:
void display_hint()
{
if ( !has_asked_for_help )
{
puts("\nHint: try the command \"help\"");
printf("yolo >> ");
fflush(_bss_start);
register_timeout_constprop_0();
}
}

canonical_decompiled_code:
void func11()
{
if ( !has_asked_for_help )
{
puts("\nHint: try the command \"help\"");
printf("yolo >> ");
fflush(_bss_start);
func10();
}
}

original_code:
static void display_hint()
{
    if (!has_asked_for_help) {
        printf("\nHint: try the command \"help\"\n");
        do { printf("yolo >> "); fflush(stdout); } while (0);
        register_timeout(3000, &display_hint, ((void *)0));
    }
}


main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
__m128i v3; // xmm0
__m128i v4; // xmm1
__m128i v5; // xmm2
__m128i v6; // xmm3
__m128i v7; // xmm4
__m128i v8; // xmm5
__m128i v9; // xmm6
__m128i v10; // xmm7
struct timeval v11; // [rsp+0h] [rbp-118h] BYREF
__m128i v12[8]; // [rsp+10h] [rbp-108h] BYREF
fd_set readfds; // [rsp+90h] [rbp-88h] BYREF

printf("yolo >> ");
fflush(_bss_start);
atexit(free_timeout, argv);
register_timeout_constprop_0();
memset(v12, 0, sizeof(v12));
v12[0].m128i_i64[0] |= 1uLL;
while ( 1 )
{
v3 = _mm_loadu_si128(v12);
v4 = _mm_loadu_si128(&v12[1]);
v5 = _mm_loadu_si128(&v12[2]);
v6 = _mm_loadu_si128(&v12[3]);
v7 = _mm_loadu_si128(&v12[4]);
v8 = _mm_loadu_si128(&v12[5]);
v11.tv_sec = 0LL;
v9 = _mm_loadu_si128(&v12[6]);
*(__m128i *)readfds.fds_bits = v3;
v10 = _mm_loadu_si128(&v12[7]);
v11.tv_usec = 100000LL;
*(__m128i *)&readfds.fds_bits[2] = v4;
*(__m128i *)&readfds.fds_bits[4] = v5;
*(__m128i *)&readfds.fds_bits[6] = v6;
*(__m128i *)&readfds.fds_bits[8] = v7;
*(__m128i *)&readfds.fds_bits[10] = v8;
*(__m128i *)&readfds.fds_bits[12] = v9;
*(__m128i *)&readfds.fds_bits[14] = v10;
if ( select(1, &readfds, 0LL, 0LL, &v11) < 0 )
break;
check_timeout();
if ( (readfds.fds_bits[0] & 1) != 0 )
handle_keyboard();
}
__assert_fail("retval >= 0", "timeout.c", 0x8Fu, "main");
}

original_code:
int main(void)
{
    do { printf("yolo >> "); fflush(stdout); } while (0);
    atexit(&free_timeout);
    register_timeout(3000, &display_hint, ((void *)0));
    fd_set readfds;
    do { int __d0, __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&readfds)->__fds_bits)[0]) : "memory"); } while (0);
    ((void) (((&readfds)->__fds_bits)[((0) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((0) % (8 * (int) sizeof (__fd_mask)))))));
    struct timeval tv;
    tv.tv_sec = 0;
    tv.tv_usec = 100000;
    while (1)
    {
        fd_set readfds_copy = readfds;
        struct timeval tv_copy = tv;
        int retval = select(0 +1, &readfds_copy, ((void *)0), ((void *)0), &tv_copy);
        ((void) sizeof ((retval >= 0) ? 1 : 0), __extension__ ({ if (retval >= 0) ; else __assert_fail ("retval >= 0", "timeout.c", 143, __extension__ __PRETTY_FUNCTION__); }));
        check_timeout();
        if (((((&readfds_copy)->__fds_bits)[((0) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((0) % (8 * (int) sizeof (__fd_mask)))))) != 0))
            handle_keyboard();
    }
}

canonical_original_code:
int main()
{
    do { printf("yolo >> "); fflush(stdout); } while (0);
    atexit(&free_timeout);
    register_timeout(3000, &display_hint, ((void *)0));
    struct fd_set readfds;
    do { int __d0; int __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&readfds)->__fds_bits)[0]) : "memory"); } while (0);
    ((void) (((&readfds)->__fds_bits)[((0) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((0) % (8 * (int) sizeof (__fd_mask)))))));
    struct timeval tv;
    tv.tv_sec = 0;
    tv.tv_usec = 100000;
    while (1)
    {
        struct fd_set readfds_copy = readfds;
        struct timeval tv_copy = tv;
        int retval = select(0 +1, &readfds_copy, ((void *)0), ((void *)0), &tv_copy);
        ((void) sizeof ((retval >= 0) ? 1 : 0), __extension__ ({ if (retval >= 0) ; else __assert_fail ("retval >= 0", "timeout.c", 143, __extension__ __PRETTY_FUNCTION__); }));
        check_timeout();
        if (((((&readfds_copy)->__fds_bits)[((0) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((0) % (8 * (int) sizeof (__fd_mask)))))) != 0))
            handle_keyboard();
    }
}

variable_types:
readfds
struct fd_set { long __fds_bits[-1]; }

variable_types: struct timeval { long tv_sec; long tv_usec; }

variable_types: retval int


repo: TacOS-team/ted

decompiled_code:
__int64 __fastcall line_nb_wraps(__int64 a1, unsigned int a2)
{
return *(_DWORD *)(a1 + 28) / a2;
}

canonical_decompiled_code:
__int64 __fastcall func14(__int64 a1, unsigned int a2)
{
return *(_DWORD *)(a1 + 28) / a2;
}

original_code:
unsigned int line_nb_wraps(line_t* line, unsigned int nb_col) {
    return (line->llen / nb_col);
}

canonical_original_code:
unsigned int line_nb_wraps(struct _line_t *line, unsigned int nb_col) {
    return (line->llen / nb_col);
}

variable_types: struct _line_t { struct _line_t *prev; struct _line_t *next; char *data; unsigned int num; unsigned int llen; unsigned int lalloc; } *

return_type: unsigned int


decompiled_code:
__int64 __fastcall print_line(__int64 a1, int a2, unsigned int a3)
{
int v4; // eax
char *v5; // r14
unsigned int v6; // er12
int v7; // edi
int i; // er12
unsigned int v9; // ebx
__int64 result; // rax

v4 = line_nb_wraps(a1, a3);
v5 = *(char **)(a1 + 16);
v6 = v4 + 1;
if ( v4 + 1 <= a2 )
{
printf("%s", *(const char **)(a1 + 16));
result = v6;
}
else
{
if ( a2 > 0 )
{
v7 = *v5;
for ( i = 0; i != a2; ++i )
{
v9 = 0;
do
{
putchar(v7);
v7 = *++v5;
++v9;
}
while ( (_BYTE)v7 != 10 && v9 < a3 );
}
}
fflush(stdout);
result = (unsigned int)a2;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func15(__int64 a1, int a2, unsigned int a3)
{
int v4; // eax
char *v5; // r14
unsigned int v6; // er12
int v7; // edi
int i; // er12
unsigned int v9; // ebx
__int64 result; // rax

v4 = func14(a1, a3);
v5 = *(char **)(a1 + 16);
v6 = v4 + 1;
if ( v4 + 1 <= a2 )
{
printf("%s", *(const char **)(a1 + 16));
result = v6;
}
else
{
if ( a2 > 0 )
{
v7 = *v5;
for ( i = 0; i != a2; ++i )
{
v9 = 0;
do
{
putchar(v7);
v7 = *++v5;
++v9;
}
while ( (_BYTE)v7 != 10 && v9 < a3 );
}
}
fflush(stdout);
result = (unsigned int)a2;
}
return result;
}

original_code:
int print_line(line_t* line, int nb_lines, unsigned int nb_col) {
    int needed_lines = line_nb_wraps(line, nb_col) + 1;
    int i,j;
    char* aux;
    if(needed_lines <= nb_lines) {
        printf("%s", line->data);
        return needed_lines;
    } else {
        aux = line->data;
        for(i=0; i<nb_lines; i++) {
            j=0;
            do {
                putchar(*aux);
                aux++;
                j++;
            }while(*aux != '\n' && j<nb_col);
        }
        fflush(stdout);
        return nb_lines;
    }
}

canonical_original_code:
int print_line(struct _line_t *line, int nb_lines, unsigned int nb_col) {
    int needed_lines = line_nb_wraps(line, nb_col) + 1;
    int i; int j;
    char *aux;
    if(needed_lines <= nb_lines) {
        printf("%s", line->data);
        return needed_lines;
    } else {
        aux = line->data;
        for(i=0; i<nb_lines; i++) {
            j=0;
            do {
                putchar(*aux);
                aux++;
                j++;
            }while(*aux != '\n' && j<nb_col);
        }
        fflush(stdout);
        return nb_lines;
    }
}

variable_types: j int

variable_types:
aux
char *

user_defined_types: struct _line_t { struct _line_t *prev; struct _line_t *next; char *data; unsigned int num; unsigned int llen; unsigned int lalloc; }