decompiled_code:
char __fastcall ppnfs_mutex_destroy(__int64 a1, const char *a2)
{
char result; // al
__int64 v3; // r12
const char *v4; // rbx
char *v5; // rax
unsigned int errnum; // [rsp+1Ch] [rbp-14h]

errnum = pthread_mutex_destroy((pthread_mutex_t *)a1);
result = errnum != 0;
if ( errnum )
{
v3 = *(_QWORD *)(a1 + 40);
v4 = *(const char **)(a1 + 48);
v5 = strerror(errnum);
fprintf(
stdout,
"ERR|ppnfs_mutex.cc:%d:%s|Could not destroy mutex '%s' : err=%d:%s, locked at %s by %lx\n",
35LL,
"ppnfs_mutex_destroy",
a2,
errnum,
v5,
v4,
v3);
result = fflush(stdout);
}
return result;
}

canonical_decompiled_code:
char __fastcall func1(__int64 a1, const char *a2)
{
char result; // al
__int64 v3; // r12
const char *v4; // rbx
char *v5; // rax
unsigned int errnum; // [rsp+1Ch] [rbp-14h]

errnum = pthread_mutex_destroy((pthread_mutex_t *)a1);
result = errnum != 0;
if ( errnum )
{
v3 = *(_QWORD *)(a1 + 40);
v4 = *(const char **)(a1 + 48);
v5 = strerror(errnum);
fprintf(
stdout,
"ERR|ppnfs_mutex.cc:%d:%s|Could not destroy mutex '%s' : err=%d:%s, locked at %s by %lx\n",
35LL,
"ppnfs_mutex_destroy",
a2,
errnum,
v5,
v4,
v3);
result = fflush(stdout);
}
return result;
}

original_code:
void
ppnfs_mutex_destroy(struct ppnfs_mutex_t* mutex, const char* name)
{
    int res;
    if ((res = pthread_mutex_destroy(&(mutex->mutex))) != 0)
    {
        do { fprintf(stderr, "ERR" "|" "ppnfs_mutex.c" ":%d:%s|" "Could not destroy mutex '%s' : err=%d:%s, locked at %s by %lx\n", 34, __FUNCTION__, name, res, strerror(res), mutex->context, (unsigned long) mutex->owner ); fflush(stderr); } while(0);
    }
}

canonical_original_code:
void ppnfs_mutex_destroy(struct ppnfs_mutex_t *mutex, char *name)
{
    int res;
    if ((res = pthread_mutex_destroy(&(mutex->mutex))) != 0)
    {
        do { fprintf(stderr, "ERR" "|" "ppnfs_mutex.c" ":%d:%s|" "Could not destroy mutex '%s' : err=%d:%s, locked at %s by %lx\n", 34, __FUNCTION__, name, res, strerror(res), mutex->context, (unsigned long) mutex->owner ); fflush(stderr); } while(0);
    }
}

variable_types:
name
char *

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


repo: yubai/PPNFS

decompiled_code:
// write access to const memory has been detected, the output may be wrong!
__int64 __fastcall ppnfs_mutex_lock(__int64 a1, const char *a2, const char *a3)
{
__int64 result; // rax
__int64 v4; // r12
const char *v5; // rbx
char *v6; // rax
unsigned int errnum; // [rsp+24h] [rbp-1Ch]
pthread_t v9; // [rsp+28h] [rbp-18h]

v9 = pthread_self();
errnum = pthread_mutex_lock((pthread_mutex_t *)a1);
if ( errnum )
{
v4 = *(_QWORD *)(a1 + 40);
v5 = *(const char **)(a1 + 48);
v6 = strerror(errnum);
fprintf(
stdout,
"BUG|ppnfs_mutex.cc:%d:%s|Could not lock mutex '%s' at %s by %lx : err=%d:%s, locked at %s by %lx\n",
53LL,
"ppnfs_mutex_lock",
a2,
a3,
v9,
errnum,
v6,
v5,
v4);
fflush(stdout);
result = 0LL;
*(_BYTE *)ppnfs_mutex_init = 0;
}
else
{
*(_QWORD *)(a1 + 40) = v9;
result = a1;
*(_QWORD *)(a1 + 48) = a3;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, const char *a2, const char *a3)
{
__int64 result; // rax
__int64 v4; // r12
const char *v5; // rbx
char *v6; // rax
unsigned int errnum; // [rsp+24h] [rbp-1Ch]
pthread_t v9; // [rsp+28h] [rbp-18h]

v9 = pthread_self();
errnum = pthread_mutex_lock((pthread_mutex_t *)a1);
if ( errnum )
{
v4 = *(_QWORD *)(a1 + 40);
v5 = *(const char **)(a1 + 48);
v6 = strerror(errnum);
fprintf(
stdout,
"BUG|ppnfs_mutex.cc:%d:%s|Could not lock mutex '%s' at %s by %lx : err=%d:%s, locked at %s by %lx\n",
53LL,
"ppnfs_mutex_lock",
a2,
a3,
v9,
errnum,
v6,
v5,
v4);
fflush(stdout);
result = 0LL;
*(_BYTE *)ppnfs_mutex_init = 0;
}
else
{
*(_QWORD *)(a1 + 40) = v9;
result = a1;
*(_QWORD *)(a1 + 48) = a3;
}
return result;
}

original_code:
void
ppnfs_mutex_lock(struct ppnfs_mutex_t* mutex, const char* name,
                 const char* context)
{
    int res;
    pthread_t me = pthread_self();
    res = pthread_mutex_lock(&(mutex->mutex));
    if (res == 0)
    {
        mutex->owner = me;
        mutex->context = context;
        return;
    }
    do { do { fprintf(stderr, "BUG" "|" "ppnfs_mutex.c" ":%d:%s|" "Could not lock mutex '%s' at %s by %lx : err=%d:%s, locked at %s by %lx\n", 52, __FUNCTION__, name, context, (unsigned long) me, res, strerror(res), mutex->context, (unsigned long) mutex->owner ); fflush(stderr); } while(0); ((char*)((void *)0))[0] = 0; } while(0);
}

canonical_original_code:
void ppnfs_mutex_lock(struct ppnfs_mutex_t *mutex, char *name, char *context)
{
    int res;
    unsigned long me = pthread_self();
    res = pthread_mutex_lock(&(mutex->mutex));
    if (res == 0)
    {
        mutex->owner = me;
        mutex->context = context;
        return;
    }
    do { do { fprintf(stderr, "BUG" "|" "ppnfs_mutex.c" ":%d:%s|" "Could not lock mutex '%s' at %s by %lx : err=%d:%s, locked at %s by %lx\n", 52, __FUNCTION__, name, context, (unsigned long) me, res, strerror(res), mutex->context, (unsigned long) mutex->owner ); fflush(stderr); } while(0); ((char *)((void *)0))[0] = 0; } while(0);
}

variable_types: struct ppnfs_mutex_t { 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; } mutex; unsigned long owner; char *context; } *

variable_types:
context
char *

variable_types: res int

variable_types:
me
unsigned long

return_type: void

user_defined_types: struct ppnfs_mutex_t { union pthread_mutex_t mutex; unsigned long owner; char *context; }

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:
// write access to const memory has been detected, the output may be wrong!
__int64 __fastcall ppnfs_mutex_check_unlocked(__int64 a1, const char *a2, const char *a3)
{
__int64 result; // rax
pthread_t v5; // [rsp+28h] [rbp-8h]

v5 = pthread_self();
result = *(_QWORD *)(a1 + 40);
if ( v5 == result )
{
fprintf(
stdout,
"BUG|ppnfs_mutex.cc:%d:%s|Mutex '%s' locked by myself %lx at %s : locked by %s at %lx\n",
65LL,
"ppnfs_mutex_check_unlocked",
a2,
v5,
a3,
*(const char **)(a1 + 48),
*(_QWORD *)(a1 + 40));
fflush(stdout);
result = 0LL;
*(_BYTE *)ppnfs_mutex_init = 0;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, const char *a2, const char *a3)
{
__int64 result; // rax
pthread_t v5; // [rsp+28h] [rbp-8h]

v5 = pthread_self();
result = *(_QWORD *)(a1 + 40);
if ( v5 == result )
{
fprintf(
stdout,
"BUG|ppnfs_mutex.cc:%d:%s|Mutex '%s' locked by myself %lx at %s : locked by %s at %lx\n",
65LL,
"ppnfs_mutex_check_unlocked",
a2,
v5,
a3,
*(const char **)(a1 + 48),
*(_QWORD *)(a1 + 40));
fflush(stdout);
result = 0LL;
*(_BYTE *)ppnfs_mutex_init = 0;
}
return result;
}

original_code:
void
ppnfs_mutex_check_unlocked(struct ppnfs_mutex_t* mutex, const char* name,
                           const char* context)
{
    pthread_t me = pthread_self();
    if (mutex->owner == me)
    {
        do { do { fprintf(stderr, "BUG" "|" "ppnfs_mutex.c" ":%d:%s|" "Mutex '%s' locked by myself %lx at %s : locked by %s at %lx\n", 64, __FUNCTION__, name, (unsigned long) me, context, mutex->context, (unsigned long) mutex->owner ); fflush(stderr); } while(0); ((char*)((void *)0))[0] = 0; } while(0);
    }
}

canonical_original_code:
void ppnfs_mutex_check_unlocked(struct ppnfs_mutex_t *mutex, char *name, char *context)
{
    unsigned long me = pthread_self();
    if (mutex->owner == me)
    {
        do { do { fprintf(stderr, "BUG" "|" "ppnfs_mutex.c" ":%d:%s|" "Mutex '%s' locked by myself %lx at %s : locked by %s at %lx\n", 64, __FUNCTION__, name, (unsigned long) me, context, mutex->context, (unsigned long) mutex->owner ); fflush(stderr); } while(0); ((char *)((void *)0))[0] = 0; } while(0);
    }
}


decompiled_code:
// write access to const memory has been detected, the output may be wrong!
__int64 __fastcall ppnfs_mutex_check_locked(__int64 a1, const char *a2, const char *a3)
{
__int64 result; // rax
pthread_t v5; // [rsp+28h] [rbp-8h]

v5 = pthread_self();
result = *(_QWORD *)(a1 + 40);
if ( v5 != result )
{
fprintf(
stdout,
"BUG|ppnfs_mutex.cc:%d:%s|Mutex '%s' not locked by myself %lx at %s : locked by %s at %lx\n",
77LL,
"ppnfs_mutex_check_locked",
a2,
v5,
a3,
*(const char **)(a1 + 48),
*(_QWORD *)(a1 + 40));
fflush(stdout);
result = 0LL;
*(_BYTE *)ppnfs_mutex_init = 0;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, const char *a2, const char *a3)
{
__int64 result; // rax
pthread_t v5; // [rsp+28h] [rbp-8h]

v5 = pthread_self();
result = *(_QWORD *)(a1 + 40);
if ( v5 != result )
{
fprintf(
stdout,
"BUG|ppnfs_mutex.cc:%d:%s|Mutex '%s' not locked by myself %lx at %s : locked by %s at %lx\n",
77LL,
"ppnfs_mutex_check_locked",
a2,
v5,
a3,
*(const char **)(a1 + 48),
*(_QWORD *)(a1 + 40));
fflush(stdout);
result = 0LL;
*(_BYTE *)ppnfs_mutex_init = 0;
}
return result;
}

original_code:
void
ppnfs_mutex_check_locked(struct ppnfs_mutex_t* mutex, const char* name,
                         const char* context)
{
    pthread_t me = pthread_self();
    if (mutex->owner != me)
    {
        do { do { fprintf(stderr, "BUG" "|" "ppnfs_mutex.c" ":%d:%s|" "Mutex '%s' not locked by myself %lx at %s : locked by %s at %lx\n", 76, __FUNCTION__, name, (unsigned long) me, context, mutex->context, (unsigned long) mutex->owner ); fflush(stderr); } while(0); ((char*)((void *)0))[0] = 0; } while(0);
    }
}

canonical_original_code:
void ppnfs_mutex_check_locked(struct ppnfs_mutex_t *mutex, char *name, char *context)
{
    unsigned long me = pthread_self();
    if (mutex->owner != me)
    {
        do { do { fprintf(stderr, "BUG" "|" "ppnfs_mutex.c" ":%d:%s|" "Mutex '%s' not locked by myself %lx at %s : locked by %s at %lx\n", 76, __FUNCTION__, name, (unsigned long) me, context, mutex->context, (unsigned long) mutex->owner ); fflush(stderr); } while(0); ((char *)((void *)0))[0] = 0; } while(0);
    }
}


decompiled_code:
// write access to const memory has been detected, the output may be wrong!
int __fastcall ppnfs_mutex_unlock(__int64 a1, const char *a2, const char *a3)
{
int result; // eax
const char *v4; // r12
__int64 v5; // rbx
char *v6; // rax
unsigned int errnum; // [rsp+24h] [rbp-1Ch]
pthread_t v9; // [rsp+28h] [rbp-18h]

v9 = pthread_self();
if ( v9 != *(_QWORD *)(a1 + 40) )
{
fprintf(
stdout,
"BUG|ppnfs_mutex.cc:%d:%s|Mutex '%s' was not held by myself ! locked by %lx at %s, unlocked by %lx at %s\n",
91LL,
"ppnfs_mutex_unlock",
a2,
*(_QWORD *)(a1 + 40),
*(const char **)(a1 + 48),
v9,
a3);
fflush(stdout);
*(_BYTE *)ppnfs_mutex_init = 0;
}
*(_QWORD *)(a1 + 40) = 0LL;
*(_QWORD *)(a1 + 48) = 0LL;
result = pthread_mutex_unlock((pthread_mutex_t *)a1);
errnum = result;
if ( result )
{
v4 = *(const char **)(a1 + 48);
v5 = *(_QWORD *)(a1 + 40);
v6 = strerror(result);
fprintf(
stdout,
"BUG|ppnfs_mutex.cc:%d:%s|Could not unlock mutex '%s' by %lx at %s : err=%d:%s, locked by %lx at %s\n",
103LL,
"ppnfs_mutex_unlock",
a2,
v9,
a3,
errnum,
v6,
v5,
v4);
fflush(stdout);
result = 0;
*(_BYTE *)ppnfs_mutex_init = 0;
}
return result;
}

canonical_decompiled_code:
int __fastcall func5(__int64 a1, const char *a2, const char *a3)
{
int result; // eax
const char *v4; // r12
__int64 v5; // rbx
char *v6; // rax
unsigned int errnum; // [rsp+24h] [rbp-1Ch]
pthread_t v9; // [rsp+28h] [rbp-18h]

v9 = pthread_self();
if ( v9 != *(_QWORD *)(a1 + 40) )
{
fprintf(
stdout,
"BUG|ppnfs_mutex.cc:%d:%s|Mutex '%s' was not held by myself ! locked by %lx at %s, unlocked by %lx at %s\n",
91LL,
"ppnfs_mutex_unlock",
a2,
*(_QWORD *)(a1 + 40),
*(const char **)(a1 + 48),
v9,
a3);
fflush(stdout);
*(_BYTE *)ppnfs_mutex_init = 0;
}
*(_QWORD *)(a1 + 40) = 0LL;
*(_QWORD *)(a1 + 48) = 0LL;
result = pthread_mutex_unlock((pthread_mutex_t *)a1);
errnum = result;
if ( result )
{
v4 = *(const char **)(a1 + 48);
v5 = *(_QWORD *)(a1 + 40);
v6 = strerror(result);
fprintf(
stdout,
"BUG|ppnfs_mutex.cc:%d:%s|Could not unlock mutex '%s' by %lx at %s : err=%d:%s, locked by %lx at %s\n",
103LL,
"ppnfs_mutex_unlock",
a2,
v9,
a3,
errnum,
v6,
v5,
v4);
fflush(stdout);
result = 0;
*(_BYTE *)ppnfs_mutex_init = 0;
}
return result;
}

original_code:
void
ppnfs_mutex_unlock(struct ppnfs_mutex_t* mutex, const char* name,
                   const char* context)
{
    int res;
    pthread_t me = pthread_self();
    if (mutex->owner != me)
    {
        do { do { fprintf(stderr, "BUG" "|" "ppnfs_mutex.c" ":%d:%s|" "Mutex '%s' was not held by myself ! locked by %lx at %s, unlocked by %lx at %s\n", 90, __FUNCTION__, name, (unsigned long)mutex->owner, mutex->context, (unsigned long)me, context ); fflush(stderr); } while(0); ((char*)((void *)0))[0] = 0; } while(0);
    }
    mutex->owner = 0;
    mutex->context = ((void *)0);
    res = pthread_mutex_unlock(&(mutex->mutex));
    if (res == 0)
    {
        return;
    }
    do { do { fprintf(stderr, "BUG" "|" "ppnfs_mutex.c" ":%d:%s|" "Could not unlock mutex '%s' by %lx at %s : err=%d:%s, locked by %lx at %s\n", 102, __FUNCTION__, name, (unsigned long)me, context, res, strerror(res), (unsigned long)mutex->owner, mutex->context ); fflush(stderr); } while(0); ((char*)((void *)0))[0] = 0; } while(0);
}

canonical_original_code:
void ppnfs_mutex_unlock(struct ppnfs_mutex_t *mutex, char *name, char *context)
{
    int res;
    unsigned long me = pthread_self();
    if (mutex->owner != me)
    {
        do { do { fprintf(stderr, "BUG" "|" "ppnfs_mutex.c" ":%d:%s|" "Mutex '%s' was not held by myself ! locked by %lx at %s, unlocked by %lx at %s\n", 90, __FUNCTION__, name, (unsigned long)mutex->owner, mutex->context, (unsigned long)me, context ); fflush(stderr); } while(0); ((char *)((void *)0))[0] = 0; } while(0);
    }
    mutex->owner = 0;
    mutex->context = ((void *)0);
    res = pthread_mutex_unlock(&(mutex->mutex));
    if (res == 0)
    {
        return;
    }
    do { do { fprintf(stderr, "BUG" "|" "ppnfs_mutex.c" ":%d:%s|" "Could not unlock mutex '%s' by %lx at %s : err=%d:%s, locked by %lx at %s\n", 102, __FUNCTION__, name, (unsigned long)me, context, res, strerror(res), (unsigned long)mutex->owner, mutex->context ); fflush(stderr); } while(0); ((char *)((void *)0))[0] = 0; } while(0);
}


comp

decompiled_code:
__int64 __fastcall comp(const void *a1, const void *a2)
{
return _gmpz_cmp((char *)a1 + 8, (char *)a2 + 8);
}

canonical_decompiled_code:
__int64 __fastcall func0(const void *a1, const void *a2)
{
return _gmpz_cmp((char *)a1 + 8, (char *)a2 + 8);
}

original_code:
int comp(const void * a,const void * b)
{
 const struct tagGpow * a1 = (const struct tagGpow * )a;
 const struct tagGpow * b1 = (const struct tagGpow * )b;
 return __gmpz_cmp(a1->gpow, b1->gpow);
}

canonical_original_code:
int comp(void *a, void *b)
{
 struct tagGpow *a1 = (const struct tagGpow * )a;
 struct tagGpow *b1 = (const struct tagGpow * )b;
 return __gmpz_cmp(a1->gpow, b1->gpow);
}

variable_types:
a
void *

variable_types:
b
void *

variable_types: struct tagGpow { int index; struct __mpz_struct { int _mp_alloc; int _mp_size; unsigned long *_mp_d; } gpow[1]; } *

return_type: int

user_defined_types: struct tagGpow { int index; struct __mpz_struct gpow[1]; }


precompute

decompiled_code:
void __fastcall precompute(__int64 a1, __int64 a2, signed int a3)
{
int v4; // [rsp+28h] [rbp-8h]
int i; // [rsp+2Ch] [rbp-4h]

v4 = (int)std::sqrt<int>((unsigned int)a3);
for ( i = 0; i <= a3 / v4; ++i )
{
arrG[6 * i] = i;
_gmpz_init(&arrG[6 * i + 2]);
_gmpz_powm_ui(&arrG[6 * i + 2], a1, v4 * i, a2);
}
qsort(arrG, a3 / v4 + 1, 0x18uLL, (__compar_fn_t)comp);
}

canonical_decompiled_code:
void __fastcall func1(__int64 a1, __int64 a2, signed int a3)
{
int v4; // [rsp+28h] [rbp-8h]
int i; // [rsp+2Ch] [rbp-4h]

v4 = (int)std::sqrt<int>((unsigned int)a3);
for ( i = 0; i <= a3 / v4; ++i )
{
arrG[6 * i] = i;
_gmpz_init(&arrG[6 * i + 2]);
_gmpz_powm_ui(&arrG[6 * i + 2], a1, v4 * i, a2);
}
qsort(arrG, a3 / v4 + 1, 0x18uLL, (__compar_fn_t)comp);
}

original_code:
void precompute(mpz_t g, mpz_t m, int q)
{
 int i;
 int t = (int)sqrt(q);
 for (i = 0; i <= (int)q/t; i++)
 {
  arrG[i].index = i;
  __gmpz_init(arrG[i].gpow);
  __gmpz_powm_ui(arrG[i].gpow, g, i*t, m);
 }
 qsort(arrG, (int)q/t+1, sizeof(struct tagGpow), comp);
}

canonical_original_code:
void precompute(struct __mpz_struct g[1], struct __mpz_struct m[1], int q)
{
 int i;
 int t = (int)sqrt(q);
 for (i = 0; i <= (int)q/t; i++)
 {
  arrG[i].index = i;
  __gmpz_init(arrG[i].gpow);
  __gmpz_powm_ui(arrG[i].gpow, g, i*t, m);
 }
 qsort(arrG, (int)q/t+1, sizeof(struct tagGpow), comp);
}

variable_types: struct __mpz_struct { int _mp_alloc; int _mp_size; unsigned long *_mp_d; } [1]

variable_types:
m
struct __mpz_struct [1]

variable_types: q int

variable_types: i int

variable_types: t int


Shank

original_code:
int Shank(int* x, mpz_t g, mpz_t y, mpz_t m, int q)
{
 int t = (int)sqrt(q);
 int i;
 mpz_t tmpy;
 if (!bstored)
 {
  precompute(g, m, q);
  bstored = 1;
 }
 __gmpz_init(tmpy);
 for (i = 0; i <= t; i++)
 {
  __gmpz_powm_ui(tmpy, g, i, m);
  __gmpz_mul(tmpy, tmpy, y);
  __gmpz_mod(tmpy, tmpy, m);
  int mid;
  int min = 0, max = (int)q/t;
  while (max >= min)
  {
   mid = (min + max)/2;
   int r = __gmpz_cmp(tmpy, arrG[mid].gpow);
   if (r > 0)
    min = mid + 1;
   else if (r < 0)
    max = mid - 1;
   else
   {
    *x = (arrG[mid].index*t-i)%q;
    if (*x < 0)
     *x += q;
    return 1;
   }
  }
 }
 return 0;
}

canonical_original_code:
int Shank(int *x, struct __mpz_struct g[1], struct __mpz_struct y[1], struct __mpz_struct m[1], int q)
{
 int t = (int)sqrt(q);
 int i;
 struct __mpz_struct tmpy[1];
 if (!bstored)
 {
  precompute(g, m, q);
  bstored = 1;
 }
 __gmpz_init(tmpy);
 for (i = 0; i <= t; i++)
 {
  __gmpz_powm_ui(tmpy, g, i, m);
  __gmpz_mul(tmpy, tmpy, y);
  __gmpz_mod(tmpy, tmpy, m);
  int mid;
  int min = 0; int max = (int)q/t;
  while (max >= min)
  {
   mid = (min + max)/2;
   int r = __gmpz_cmp(tmpy, arrG[mid].gpow);
   if (r > 0)
    min = mid + 1;
   else if (r < 0)
    max = mid - 1;
   else
   {
    *x = (arrG[mid].index*t-i)%q;
    if (*x < 0)
     *x += q;
    return 1;
   }
  }
 }
 return 0;
}

variable_types:
x
int *

variable_types:
y
struct __mpz_struct [1]

variable_types: mid int

variable_types: min int

variable_types: max int

variable_types: r int

user_defined_types: struct __mpz_struct { int _mp_alloc; int _mp_size; unsigned long *_mp_d; }


decompiled_code:
__int64 __fastcall Shank2(int *a1, __int64 a2, __int64 a3, __int64 a4, signed int a5)
{
char v9[24]; // [rsp+30h] [rbp-30h] BYREF
char *v10; // [rsp+48h] [rbp-18h]
int v11; // [rsp+54h] [rbp-Ch]
int j; // [rsp+58h] [rbp-8h]
int i; // [rsp+5Ch] [rbp-4h]

v11 = (int)std::sqrt<int>((unsigned int)a5);
v10 = (char *)malloc(16LL * (a5 / v11 + 1));
for ( i = 0; i <= a5 / v11; ++i )
{
_gmpz_init(&v10[16 * i]);
_gmpz_powm_ui(&v10[16 * i], a2, v11 * i, a4);
}
_gmpz_init(v9);
i = 0;
LABEL_5:
if ( i > v11 )
return 0LL;
_gmpz_powm_ui(v9, a2, i, a4);
_gmpz_mul(v9, v9, a3);
_gmpz_mod(v9, v9, a4);
for ( j = 0; ; ++j )
{
if ( j > a5 / v11 )
{
++i;
goto LABEL_5;
}
if ( !(unsigned int)_gmpz_cmp(v9, &v10[16 * j]) )
break;
}
*a1 = (v11 * j - i) % a5;
if ( *a1 < 0 )
*a1 += a5;
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(int *a1, __int64 a2, __int64 a3, __int64 a4, signed int a5)
{
char v9[24]; // [rsp+30h] [rbp-30h] BYREF
char *v10; // [rsp+48h] [rbp-18h]
int v11; // [rsp+54h] [rbp-Ch]
int j; // [rsp+58h] [rbp-8h]
int i; // [rsp+5Ch] [rbp-4h]

v11 = (int)std::sqrt<int>((unsigned int)a5);
v10 = (char *)malloc(16LL * (a5 / v11 + 1));
for ( i = 0; i <= a5 / v11; ++i )
{
_gmpz_init(&v10[16 * i]);
_gmpz_powm_ui(&v10[16 * i], a2, v11 * i, a4);
}
_gmpz_init(v9);
i = 0;
LABEL_5:
if ( i > v11 )
return 0LL;
_gmpz_powm_ui(v9, a2, i, a4);
_gmpz_mul(v9, v9, a3);
_gmpz_mod(v9, v9, a4);
for ( j = 0; ; ++j )
{
if ( j > a5 / v11 )
{
++i;
goto LABEL_5;
}
if ( !(unsigned int)_gmpz_cmp(v9, &v10[16 * j]) )
break;
}
*a1 = (v11 * j - i) % a5;
if ( *a1 < 0 )
*a1 += a5;
return 1LL;
}

original_code:
int Shank2(int* x, mpz_t g, mpz_t y, mpz_t m, int q)
{
 int t = (int)sqrt(q);
 int i;
 mpz_t * arrG = (mpz_t*)malloc((int)(q/t+1)*sizeof(mpz_t));
 for (i = 0; i <= (int)q/t; i++)
 {
  __gmpz_init(arrG[i]);
  __gmpz_powm_ui(arrG[i], g, i*t, m);
 }
 mpz_t tmpy;
 __gmpz_init(tmpy);
 for (i = 0; i <= t; i++)
 {
  __gmpz_powm_ui(tmpy, g, i, m);
  __gmpz_mul(tmpy, tmpy, y);
  __gmpz_mod(tmpy, tmpy, m);
  int j;
  for (j = 0; j <= (int)q/t; j++)
  {
   if (!__gmpz_cmp(tmpy, arrG[j]))
   {
    *x = (j*t-i)%q;
    if (*x < 0)
     *x += q;
    return 1;
   }
  }
 }
 return 0;
}

canonical_original_code:
int Shank2(int *x, struct __mpz_struct g[1], struct __mpz_struct y[1], struct __mpz_struct m[1], int q)
{
 int t = (int)sqrt(q);
 int i;
 struct __mpz_struct (*arrG)[1] = (mpz_t*)malloc((int)(q/t+1)*sizeof(mpz_t));
 for (i = 0; i <= (int)q/t; i++)
 {
  __gmpz_init(arrG[i]);
  __gmpz_powm_ui(arrG[i], g, i*t, m);
 }
 struct __mpz_struct tmpy[1];
 __gmpz_init(tmpy);
 for (i = 0; i <= t; i++)
 {
  __gmpz_powm_ui(tmpy, g, i, m);
  __gmpz_mul(tmpy, tmpy, y);
  __gmpz_mod(tmpy, tmpy, m);
  int j;
  for (j = 0; j <= (int)q/t; j++)
  {
   if (!__gmpz_cmp(tmpy, arrG[j]))
   {
    *x = (j*t-i)%q;
    if (*x < 0)
     *x += q;
    return 1;
   }
  }
 }
 return 0;
}

variable_types: struct __mpz_struct { int _mp_alloc; int _mp_size; unsigned long *_mp_d; } (*)[1]

variable_types: j int


original_code:
void discrete_log(mpz_t x, mpz_t a, mpz_t b, mpz_t m, int p, int c)
{
    int * arrA = (int*) malloc(c*sizeof(int));
    mpz_t * arrP = (mpz_t*)malloc(c*sizeof(mpz_t));
 int i;
 for (i = 0; i < c; i++)
 {
  __gmpz_init(arrP[i]);
  __gmpz_ui_pow_ui(arrP[i], p, i);
 }
 mpz_t bi[2], abase, tmpy;
 __gmpz_init(bi[0]);
 __gmpz_init(bi[1]);
 __gmpz_init(tmpy);
 __gmpz_init(abase);
 int pos = 1;
 __gmpz_set(bi[0], b);
 __gmpz_powm(abase, a, arrP[c-1], m);
 __gmpz_powm(tmpy, bi[0], arrP[c-1], m);
 precompute(abase, m, p);
 bstored = 1;
 if(!Shank(&arrA[0], abase, tmpy, m, p))
 {
  printf("did not find log for %d\n", i);
 }
 __gmpz_set_ui(x, arrA[0]);
 mpz_t ap;
 __gmpz_init(ap);
 for (i = 1; i < c; i++)
 {
  __gmpz_mul_ui(ap, arrP[i-1], arrA[i-1]);
  __gmpz_invert(bi[pos], a, m);
  __gmpz_powm(bi[pos], bi[pos], ap, m);
  __gmpz_mul(bi[pos], bi[1-pos], bi[pos]);
  __gmpz_powm(tmpy, bi[pos], arrP[c-i-1], m);
  if (!Shank(&arrA[i], abase, tmpy, m, p))
  {
   printf("did not find log for %d\n", i);
  }
  pos = 1-pos;
  __gmpz_mul_ui(tmpy, arrP[i], arrA[i]);
  __gmpz_add(x, x, tmpy);
 }
}

canonical_original_code:
void discrete_log(struct __mpz_struct x[1], struct __mpz_struct a[1], struct __mpz_struct b[1], struct __mpz_struct m[1], int p, int c)
{
    int *arrA = (int*) malloc(c*sizeof(int));
    struct __mpz_struct (*arrP)[1] = (mpz_t*)malloc(c*sizeof(mpz_t));
 int i;
 for (i = 0; i < c; i++)
 {
  __gmpz_init(arrP[i]);
  __gmpz_ui_pow_ui(arrP[i], p, i);
 }
 struct __mpz_struct bi[2][1]; struct __mpz_struct abase[1]; struct __mpz_struct tmpy[1];
 __gmpz_init(bi[0]);
 __gmpz_init(bi[1]);
 __gmpz_init(tmpy);
 __gmpz_init(abase);
 int pos = 1;
 __gmpz_set(bi[0], b);
 __gmpz_powm(abase, a, arrP[c-1], m);
 __gmpz_powm(tmpy, bi[0], arrP[c-1], m);
 precompute(abase, m, p);
 bstored = 1;
 if(!Shank(&arrA[0], abase, tmpy, m, p))
 {
  printf("did not find log for %d\n", i);
 }
 __gmpz_set_ui(x, arrA[0]);
 struct __mpz_struct ap[1];
 __gmpz_init(ap);
 for (i = 1; i < c; i++)
 {
  __gmpz_mul_ui(ap, arrP[i-1], arrA[i-1]);
  __gmpz_invert(bi[pos], a, m);
  __gmpz_powm(bi[pos], bi[pos], ap, m);
  __gmpz_mul(bi[pos], bi[1-pos], bi[pos]);
  __gmpz_powm(tmpy, bi[pos], arrP[c-i-1], m);
  if (!Shank(&arrA[i], abase, tmpy, m, p))
  {
   printf("did not find log for %d\n", i);
  }
  pos = 1-pos;
  __gmpz_mul_ui(tmpy, arrP[i], arrA[i]);
  __gmpz_add(x, x, tmpy);
 }
}

variable_types:
a
struct __mpz_struct [1]

variable_types:
b
struct __mpz_struct [1]

variable_types: p int

variable_types: c int

variable_types:
arrA
int *

variable_types: struct __mpz_struct { int _mp_alloc; int _mp_size; unsigned long *_mp_d; } [2][1]

variable_types: pos int


comp

variable_types:
a
void *

variable_types:
b
void *

variable_types: struct tagGpow { int index; struct __mpz_struct { int _mp_alloc; int _mp_size; unsigned long *_mp_d; } gpow[1]; } *


precompute

variable_types: struct __mpz_struct { int _mp_alloc; int _mp_size; unsigned long *_mp_d; } [1]

variable_types:
m
struct __mpz_struct [1]

variable_types: q int

variable_types: i int

variable_types: t int


Shank

variable_types:
x
int *

variable_types:
y
struct __mpz_struct [1]

variable_types: mid int

variable_types: min int

variable_types: max int

variable_types: r int


variable_types: struct __mpz_struct { int _mp_alloc; int _mp_size; unsigned long *_mp_d; } (*)[1]

variable_types: j int


decompiled_code:
int __fastcall ppnfs_mutex_destroy(__int64 a1, const char *a2)
{
int result; // eax
unsigned int v3; // ebx
__int64 v4; // r14
const char *v5; // r12
char *v6; // rax

result = pthread_mutex_destroy((pthread_mutex_t *)a1);
v3 = result;
if ( result )
{
v4 = *(_QWORD *)(a1 + 40);
v5 = *(const char **)(a1 + 48);
v6 = strerror(result);
fprintf(
stderr,
"ERR|ppnfs_mutex.c:%d:%s|Could not destroy mutex '%s' : err=%d:%s, locked at %s by %lx\n",
34LL,
"ppnfs_mutex_destroy",
a2,
v3,
v6,
v5,
v4);
result = fflush(stderr);
}
return result;
}

canonical_decompiled_code:
int __fastcall func0(__int64 a1, const char *a2)
{
int result; // eax
unsigned int v3; // ebx
__int64 v4; // r14
const char *v5; // r12
char *v6; // rax

result = pthread_mutex_destroy((pthread_mutex_t *)a1);
v3 = result;
if ( result )
{
v4 = *(_QWORD *)(a1 + 40);
v5 = *(const char **)(a1 + 48);
v6 = strerror(result);
fprintf(
stderr,
"ERR|ppnfs_mutex.c:%d:%s|Could not destroy mutex '%s' : err=%d:%s, locked at %s by %lx\n",
34LL,
"ppnfs_mutex_destroy",
a2,
v3,
v6,
v5,
v4);
result = fflush(stderr);
}
return result;
}

variable_types: struct ppnfs_mutex_t { 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; } mutex; unsigned long owner; char *context; } *

variable_types:
name
char *

variable_types: res int


decompiled_code:
// write access to const memory has been detected, the output may be wrong!
unsigned int __fastcall ppnfs_mutex_lock(pthread_mutex_t *mutex, const char *a2, const char *a3)
{
__int64 v4; // r13
unsigned int result; // eax
__int64 v6; // r12
const char *v7; // rbx
char *v8; // rax
__int64 v9; // [rsp+8h] [rbp-38h]

v4 = pthread_self();
result = pthread_mutex_lock(mutex);
v6 = result;
if ( result )
{
v7 = (const char *)*(&mutex[1].__align + 1);
v9 = mutex[1].__align;
v8 = strerror(result);
fprintf(
stderr,
"BUG|ppnfs_mutex.c:%d:%s|Could not lock mutex '%s' at %s by %lx : err=%d:%s, locked at %s by %lx\n",
52LL,
"ppnfs_mutex_lock",
a2,
a3,
v4,
v6,
v8,
v7,
v9);
fflush(stderr);
*(_BYTE *)ppnfs_mutex_init = 0;
BUG();
}
mutex[1].__align = v4;
*(&mutex[1].__align + 1) = (__int64)a3;
return result;
}

canonical_decompiled_code:
unsigned int __fastcall func1(pthread_mutex_t *mutex, const char *a2, const char *a3)
{
__int64 v4; // r13
unsigned int result; // eax
__int64 v6; // r12
const char *v7; // rbx
char *v8; // rax
__int64 v9; // [rsp+8h] [rbp-38h]

v4 = pthread_self();
result = pthread_mutex_lock(mutex);
v6 = result;
if ( result )
{
v7 = (const char *)*(&mutex[1].__align + 1);
v9 = mutex[1].__align;
v8 = strerror(result);
fprintf(
stderr,
"BUG|ppnfs_mutex.c:%d:%s|Could not lock mutex '%s' at %s by %lx : err=%d:%s, locked at %s by %lx\n",
52LL,
"ppnfs_mutex_lock",
a2,
a3,
v4,
v6,
v8,
v7,
v9);
fflush(stderr);
*(_BYTE *)ppnfs_mutex_init = 0;
BUG();
}
mutex[1].__align = v4;
*(&mutex[1].__align + 1) = (__int64)a3;
return result;
}

variable_types:
context
char *

variable_types:
me
unsigned long


decompiled_code:
// write access to const memory has been detected, the output may be wrong!
pthread_t __fastcall ppnfs_mutex_check_unlocked(__int64 a1, const char *a2, const char *a3)
{
pthread_t result; // rax

result = pthread_self();
if ( *(_QWORD *)(a1 + 40) == result )
{
fprintf(
stderr,
"BUG|ppnfs_mutex.c:%d:%s|Mutex '%s' locked by myself %lx at %s : locked by %s at %lx\n",
64LL,
"ppnfs_mutex_check_unlocked",
a2,
result,
a3,
*(const char **)(a1 + 48),
result);
fflush(stderr);
*(_BYTE *)ppnfs_mutex_init = 0;
BUG();
}
return result;
}

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

result = pthread_self();
if ( *(_QWORD *)(a1 + 40) == result )
{
fprintf(
stderr,
"BUG|ppnfs_mutex.c:%d:%s|Mutex '%s' locked by myself %lx at %s : locked by %s at %lx\n",
64LL,
"ppnfs_mutex_check_unlocked",
a2,
result,
a3,
*(const char **)(a1 + 48),
result);
fflush(stderr);
*(_BYTE *)ppnfs_mutex_init = 0;
BUG();
}
return result;
}


decompiled_code:
// write access to const memory has been detected, the output may be wrong!
__int64 __fastcall ppnfs_mutex_check_locked(__int64 a1, const char *a2, const char *a3)
{
pthread_t v4; // r9
__int64 result; // rax

v4 = pthread_self();
result = *(_QWORD *)(a1 + 40);
if ( result != v4 )
{
fprintf(
stderr,
"BUG|ppnfs_mutex.c:%d:%s|Mutex '%s' not locked by myself %lx at %s : locked by %s at %lx\n",
76LL,
"ppnfs_mutex_check_locked",
a2,
v4,
a3,
*(const char **)(a1 + 48),
*(_QWORD *)(a1 + 40));
fflush(stderr);
*(_BYTE *)ppnfs_mutex_init = 0;
BUG();
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, const char *a2, const char *a3)
{
pthread_t v4; // r9
__int64 result; // rax

v4 = pthread_self();
result = *(_QWORD *)(a1 + 40);
if ( result != v4 )
{
fprintf(
stderr,
"BUG|ppnfs_mutex.c:%d:%s|Mutex '%s' not locked by myself %lx at %s : locked by %s at %lx\n",
76LL,
"ppnfs_mutex_check_locked",
a2,
v4,
a3,
*(const char **)(a1 + 48),
*(_QWORD *)(a1 + 40));
fflush(stderr);
*(_BYTE *)ppnfs_mutex_init = 0;
BUG();
}
return result;
}


decompiled_code:
// write access to const memory has been detected, the output may be wrong!
unsigned int __fastcall ppnfs_mutex_unlock(pthread_mutex_t *mutex, const char *a2, const char *a3)
{
pthread_t v4; // rax
__int64 v5; // r15
unsigned int result; // eax
__int64 v7; // r12
__int64 v8; // rbx
char *v9; // rax
const char *v10; // [rsp+8h] [rbp-38h]

v4 = pthread_self();
v5 = mutex[1].__align;
if ( v5 != v4 )
{
fprintf(
stderr,
"BUG|ppnfs_mutex.c:%d:%s|Mutex '%s' was not held by myself ! locked by %lx at %s, unlocked by %lx at %s\n",
90LL,
"ppnfs_mutex_unlock",
a2,
mutex[1].__align,
*((const char **)&mutex[1].__align + 1),
v4,
a3);
fflush(stderr);
*(_BYTE *)ppnfs_mutex_init = 0;
BUG();
}
*(_OWORD *)&mutex[1].__lock = 0uLL;
result = pthread_mutex_unlock(mutex);
v7 = result;
if ( result )
{
v8 = mutex[1].__align;
v10 = (const char *)*(&mutex[1].__align + 1);
v9 = strerror(result);
fprintf(
stderr,
"BUG|ppnfs_mutex.c:%d:%s|Could not unlock mutex '%s' by %lx at %s : err=%d:%s, locked by %lx at %s\n",
102LL,
"ppnfs_mutex_unlock",
a2,
v5,
a3,
v7,
v9,
v8,
v10);
fflush(stderr);
*(_BYTE *)ppnfs_mutex_init = 0;
BUG();
}
return result;
}

canonical_decompiled_code:
unsigned int __fastcall func4(pthread_mutex_t *mutex, const char *a2, const char *a3)
{
pthread_t v4; // rax
__int64 v5; // r15
unsigned int result; // eax
__int64 v7; // r12
__int64 v8; // rbx
char *v9; // rax
const char *v10; // [rsp+8h] [rbp-38h]

v4 = pthread_self();
v5 = mutex[1].__align;
if ( v5 != v4 )
{
fprintf(
stderr,
"BUG|ppnfs_mutex.c:%d:%s|Mutex '%s' was not held by myself ! locked by %lx at %s, unlocked by %lx at %s\n",
90LL,
"ppnfs_mutex_unlock",
a2,
mutex[1].__align,
*((const char **)&mutex[1].__align + 1),
v4,
a3);
fflush(stderr);
*(_BYTE *)ppnfs_mutex_init = 0;
BUG();
}
*(_OWORD *)&mutex[1].__lock = 0uLL;
result = pthread_mutex_unlock(mutex);
v7 = result;
if ( result )
{
v8 = mutex[1].__align;
v10 = (const char *)*(&mutex[1].__align + 1);
v9 = strerror(result);
fprintf(
stderr,
"BUG|ppnfs_mutex.c:%d:%s|Could not unlock mutex '%s' by %lx at %s : err=%d:%s, locked by %lx at %s\n",
102LL,
"ppnfs_mutex_unlock",
a2,
v5,
a3,
v7,
v9,
v8,
v10);
fflush(stderr);
*(_BYTE *)ppnfs_mutex_init = 0;
BUG();
}
return result;
}


decompiled_code:
__int64 __fastcall sdbm_hash(__int64 a1, const char *a2, int a3)
{
int v6; // [rsp+34h] [rbp-4h]

v6 = 0;
while ( *a2 )
{
a1 = (a1 << 6) + *(unsigned __int8 *)a2 + (a1 << 16) - a1;
if ( ++v6 == a3 )
break;
++a2;
}
return a1;
}

original_code:
static hash_t
sdbm_hash( hash_t h, const char* str, int sz )
{
    int cur = 0;
    const char* c;
    unsigned char d;
    for ( c = str ; *c ; c++ ) {
        d = (unsigned char)(*c);
        h = d + (h<<6) + (h<<16) - h;
        cur++;
        if ( cur == sz ) break;
    }
    return h;
}

canonical_original_code:
static unsigned long long sdbm_hash(unsigned long long h, char *str, int sz)
{
    int cur = 0;
    char *c;
    unsigned char d;
    for ( c = str ; *c ; c++ ) {
        d = (unsigned char)(*c);
        h = d + (h<<6) + (h<<16) - h;
        cur++;
        if ( cur == sz ) break;
    }
    return h;
}

variable_types:
h
unsigned long long

variable_types:
str
char *

variable_types: sz int

variable_types: cur int

variable_types:
c
char *

variable_types:
d
unsigned char

return_type: unsigned long long


continueHashPartial

decompiled_code:
__int64 __fastcall continueHashPartial(__int64 a1, const char *a2, int a3)
{
return sdbm_hash(a1, a2, a3);
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, const char *a2, int a3)
{
return func0(a1, a2, a3);
}

original_code:
hash_t continueHashPartial ( hash_t h, const char* str, int sz )
{
    return sdbm_hash( h, str, sz );
}

canonical_original_code:
unsigned long long continueHashPartial(unsigned long long h, char *str, int sz)
{
    return sdbm_hash( h, str, sz );
}


continueHash

decompiled_code:
__int64 __fastcall continueHash(__int64 a1, const char *a2)
{
return continueHashPartial(a1, a2, -1);
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, const char *a2)
{
return func1(a1, a2, -1);
}

original_code:
hash_t continueHash ( hash_t h, const char* str )
{
    return continueHashPartial ( h, str, ~((int)0) );
}

canonical_original_code:
unsigned long long continueHash(unsigned long long h, char *str)
{
    return continueHashPartial ( h, str, ~((int)0) );
}


doHashPartial

decompiled_code:
__int64 __fastcall doHashPartial(const char *a1, int a2)
{
return continueHashPartial(581LL, a1, a2);
}

canonical_decompiled_code:
__int64 __fastcall func3(const char *a1, int a2)
{
return func1(581LL, a1, a2);
}

original_code:
hash_t doHashPartial ( const char* str, int sz )
{
    hash_t h = 0x245;
    return continueHashPartial ( h, str, sz );
}

canonical_original_code:
unsigned long long doHashPartial(char *str, int sz)
{
    unsigned long long h = 0x245;
    return continueHashPartial ( h, str, sz );
}


doHash

decompiled_code:
__int64 __fastcall doHash(const char *a1)
{
return doHashPartial(a1, -1);
}

canonical_decompiled_code:
__int64 __fastcall func4(const char *a1)
{
return func3(a1, -1);
}

original_code:
hash_t doHash ( const char* str )
{
    return doHashPartial ( str, ~((int)0) );
}

canonical_original_code:
unsigned long long doHash(char *str)
{
    return doHashPartial ( str, ~((int)0) );
}


decompiled_code:
__int64 __fastcall reference_dgemm(int a1, __int64 a2, __int64 a3, __int64 a4, double a5)
{
double v6; // [rsp+8h] [rbp-38h] BYREF
int v7; // [rsp+14h] [rbp-2Ch] BYREF
char v8; // [rsp+1Ah] [rbp-26h] BYREF
char v9; // [rsp+1Bh] [rbp-25h] BYREF
int v10; // [rsp+1Ch] [rbp-24h] BYREF
int v11; // [rsp+20h] [rbp-20h] BYREF
int v12; // [rsp+24h] [rbp-1Ch] BYREF
int v13; // [rsp+28h] [rbp-18h] BYREF
int v14; // [rsp+2Ch] [rbp-14h] BYREF
__int64 v15; // [rsp+30h] [rbp-10h] BYREF

v7 = a1;
v10 = a1;
v11 = a1;
v12 = a1;
v13 = a1;
v14 = a1;
v15 = LC0;
v8 = 78;
v9 = 78;
v6 = a5;
return dgemm_(&v8, &v9, &v10, &v7, &v11, &v6, a2, &v12, a3, &v13, &v15, a4, &v14);
}

original_code:
void reference_dgemm (int N, double ALPHA, double* A, double* B, double* C)
{
  char TRANSA = 'N';
  char TRANSB = 'N';
  int M = N;
  int K = N;
  double BETA = 1.;
  int LDA = N;
  int LDB = N;
  int LDC = N;
  dgemm_(&TRANSA, &TRANSB, &M, &N, &K, &ALPHA, A, &LDA, B, &LDB, &BETA, C, &LDC);
}

canonical_original_code:
void reference_dgemm(int N, double ALPHA, double *A, double *B, double *C)
{
  char TRANSA = 'N';
  char TRANSB = 'N';
  int M = N;
  int K = N;
  double BETA = 1.;
  int LDA = N;
  int LDB = N;
  int LDC = N;
  dgemm_(&TRANSA, &TRANSB, &M, &N, &K, &ALPHA, A, &LDA, B, &LDB, &BETA, C, &LDC);
}

variable_types: N int

variable_types: ALPHA double

variable_types:
A
double *

variable_types:
B
double *

variable_types:
C
double *

variable_types: TRANSA char

variable_types: TRANSB char

variable_types: M int

variable_types: K int

variable_types: BETA double

variable_types: LDA int

variable_types: LDB int

variable_types: LDC int


decompiled_code:
double wall_time()
{
struct timespec v1; // [rsp+0h] [rbp-18h] BYREF

clock_gettime(1, &v1);
return (double)SLODWORD(v1.tv_nsec) * 0.000000001 + (double)SLODWORD(v1.tv_sec);
}

canonical_decompiled_code:
double func1()
{
struct timespec v1; // [rsp+0h] [rbp-18h] BYREF

clock_gettime(1, &v1);
return (double)SLODWORD(v1.tv_nsec) * 0.000000001 + (double)SLODWORD(v1.tv_sec);
}

original_code:
double wall_time ()
{
  struct timespec t;
  clock_gettime (1, &t);
  return 1.*t.tv_sec + 1.e-9*t.tv_nsec;
}

canonical_original_code:
double wall_time()
{
  struct timespec t;
  clock_gettime (1, &t);
  return 1.*t.tv_sec + 1.e-9*t.tv_nsec;
}

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

return_type: double


die

decompiled_code:
void __fastcall __noreturn die(const char *a1)
{
perror(a1);
exit(1);
}

canonical_decompiled_code:
void __fastcall __noreturn func2(const char *a1)
{
perror(a1);
exit(1);
}

original_code:
void die (const char* message)
{
  perror (message);
  exit (1);
}

canonical_original_code:
void die(char *message)
{
  perror (message);
  exit (1);
}

variable_types:
message
char *


fill

original_code:
void fill (double* p, int n)
{
  for (int i = 0; i < n; ++i)
    p[i] = 2 * drand48() - 1;
}

canonical_original_code:
void fill(double *p, int n)
{
  for (int i = 0; i < n; ++i)
    p[i] = 2 * drand48() - 1;
}

variable_types:
p
double *

variable_types: n int

variable_types: i int


original_code:
void absolute_value (double *p, int n)
{
  for (int i = 0; i < n; ++i)
    p[i] = fabs (p[i]);
}

canonical_original_code:
void absolute_value(double *p, int n)
{
  for (int i = 0; i < n; ++i)
    p[i] = fabs (p[i]);
}


original_code:
static void do_block(int M, int K, int N, double* A, double* B, double* C) {
    __m128d c0, c1, a0, a1, b0, b1, b2, b3, d0, d1;
    for (int k=0; k<K; k+=2) {
        for (int j=0; j<N; j+=2) {
            b0 = _mm_load1_pd(B+k+j*K);
            b1 = _mm_load1_pd(B+k+1+j*K);
            b2 = _mm_load1_pd(B+k+(j+1)*K);
            b3 = _mm_load1_pd(B+k+1+(j+1)*K);
            for (int i=0; i<M; i+=2) {
                a0 = _mm_load_pd(A+i+k*M);
                a1 = _mm_load_pd(A+i+(k+1)*M);
                c0 = _mm_load_pd(C+i+j*M);
                c1 = _mm_load_pd(C+i+(j+1)*M);
                d0 = _mm_add_pd(c0, _mm_mul_pd(a0,b0));
                d1 = _mm_add_pd(c1, _mm_mul_pd(a0,b2));
                c0 = _mm_add_pd(d0, _mm_mul_pd(a1,b1));
                c1 = _mm_add_pd(d1, _mm_mul_pd(a1,b3));
                _mm_store_pd(C+i+j*M,c0);
                _mm_store_pd(C+i+(j+1)*M,c1);
            }
        }
    }
}

canonical_original_code:
static void do_block(int M, int K, int N, double *A, double *B, double *C) {
    double c0; double c1; double a0; double a1; double b0; double b1; double b2; double b3; double d0; double d1;
    for (int k = 0; k<K; k+=2) {
        for (int j = 0; j<N; j+=2) {
            b0 = _mm_load1_pd(B+k+j*K);
            b1 = _mm_load1_pd(B+k+1+j*K);
            b2 = _mm_load1_pd(B+k+(j+1)*K);
            b3 = _mm_load1_pd(B+k+1+(j+1)*K);
            for (int i = 0; i<M; i+=2) {
                a0 = _mm_load_pd(A+i+k*M);
                a1 = _mm_load_pd(A+i+(k+1)*M);
                c0 = _mm_load_pd(C+i+j*M);
                c1 = _mm_load_pd(C+i+(j+1)*M);
                d0 = _mm_add_pd(c0, _mm_mul_pd(a0,b0));
                d1 = _mm_add_pd(c1, _mm_mul_pd(a0,b2));
                c0 = _mm_add_pd(d0, _mm_mul_pd(a1,b1));
                c1 = _mm_add_pd(d1, _mm_mul_pd(a1,b3));
                _mm_store_pd(C+i+j*M,c0);
                _mm_store_pd(C+i+(j+1)*M,c1);
            }
        }
    }
}

variable_types: N int

variable_types: k int

variable_types: j int


original_code:
static void add_block(double* new_A, double* A, int M, int N, int lda, int M_even) {
    __m128d a;
    int i_step;
    for (int j=0; j<N; j++) {
        for (int i=0; i<M; i+=2) {
            i_step = (((2)<(M-i))?(2):(M-i));
            if (i_step == 1) {
                A[i+j*lda] = new_A[i+j*M_even];
            }
            else {
                a = _mm_load_pd(new_A + i + j*M_even);
                _mm_storeu_pd(A+i+j*lda,a);
            }
        }
    }
}

canonical_original_code:
static void add_block(double *new_A, double *A, int M, int N, int lda, int M_even) {
    double a;
    int i_step;
    for (int j = 0; j<N; j++) {
        for (int i = 0; i<M; i+=2) {
            i_step = (((2)<(M-i))?(2):(M-i));
            if (i_step == 1) {
                A[i+j*lda] = new_A[i+j*M_even];
            }
            else {
                a = _mm_load_pd(new_A + i + j*M_even);
                _mm_storeu_pd(A+i+j*lda,a);
            }
        }
    }
}

variable_types:
A
double *

variable_types: lda int

variable_types: a double


show

repo: yuhongliang/practice

decompiled_code:
int __fastcall show(unsigned int *a1)
{
return printf("%d\n", *a1);
}

canonical_decompiled_code:
int __fastcall func7(unsigned int *a1)
{
return printf("%d\n", *a1);
}

original_code:
void show(void *data)
{
 printf("%d\n",*(int*)data);
}

canonical_original_code:
void show(void *data)
{
 printf("%d\n",*(int *)data);
}

variable_types:
data
void *


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

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

original_code:
void free_d(void *data)
{
 free(data);
}

canonical_original_code:
void free_d(void *data)
{
 free(data);
}


decompiled_code:
__int64 __fastcall stack_destroy(unsigned int *a1)
{
__int64 result; // rax
__int64 *i; // rbp
__int64 v4; // rdx
__int64 v5; // rdi

result = *a1;
for ( i = (__int64 *)*((_QWORD *)a1 + 1); (_DWORD)result; i = (__int64 *)*((_QWORD *)a1 + 1) )
{
v4 = i[1];
v5 = *i;
*a1 = result - 1;
*((_QWORD *)a1 + 1) = v4;
(*((void (__fastcall **)(__int64))a1 + 4))(v5);
free(i);
result = *a1;
}
*((_QWORD *)a1 + 2) = 0LL;
*((_QWORD *)a1 + 1) = 0LL;
return result;
}

original_code:
void stack_destroy(stack_t* stack)
{
 stack_elem_t *top=stack->top;
 while(stack->size)
 {
  stack->top=top->next;
  stack->size--;
  stack->free(top->data);
  free(top);
  top=stack->top;
 }
 stack->top = stack->bottom = ((void *)0);
}

canonical_original_code:
void stack_destroy(struct stack *stack)
{
 struct stack_elem *top = stack->top;
 while(stack->size)
 {
  stack->top=top->next;
  stack->size--;
  stack->free(top->data);
  free(top);
  top=stack->top;
 }
 stack->top = stack->bottom = ((void *)0);
}

variable_types: struct stack { int size; struct stack_elem { void *data; struct stack_elem *next; } *top; struct stack_elem *bottom; int (*cmp)(void *key1, void *key2, unsigned long size); void (*free)(void *data); } *

user_defined_types: struct stack { int size; struct stack_elem *top; struct stack_elem *bottom; int (*cmp)(void *key1, void *key2, unsigned long size); void (*free)(void *data); }


original_code:
void *stack_pop(stack_t* stack)
{
 if(stack->size==0)
  return ((void *)0);
 stack_elem_t *del=stack->top;
 void * data = del->data;
 stack->top=stack->top->next;
 stack->size--;
 if(stack->size==0)
  stack->bottom=((void *)0);
 free(del);
 return data;
}

canonical_original_code:
void *stack_pop(struct stack *stack)
{
 if(stack->size==0)
  return ((void *)0);
 struct stack_elem *del = stack->top;
 void *data = del->data;
 stack->top=stack->top->next;
 stack->size--;
 if(stack->size==0)
  stack->bottom=((void *)0);
 free(del);
 return data;
}

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

return_type: void *


original_code:
int stack_push(stack_t* stack,const void *data)
{
 stack_elem_t *elem;
 elem=(stack_elem_t *)malloc(sizeof(stack_elem_t));
 if(elem==((void *)0))
  return 0;
 elem->data=(void *)data;
 if(stack->size==0)
  stack->bottom=elem;
 elem->next=stack->top;
 stack->top=elem;
 stack->size++;
 return 1;
}

canonical_original_code:
int stack_push(struct stack *stack, void *data)
{
 struct stack_elem *elem;
 elem=(struct stack_elem *)malloc(sizeof(stack_elem_t));
 if(elem==((void *)0))
  return 0;
 elem->data=(void *)data;
 if(stack->size==0)
  stack->bottom=elem;
 elem->next=stack->top;
 stack->top=elem;
 stack->size++;
 return 1;
}

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


decompiled_code:
int __fastcall stack_show(__int64 a1, __int64 (__fastcall *a2)(_QWORD))
{
int result; // eax
_QWORD *i; // rbx

result = *(_DWORD *)a1;
if ( !*(_DWORD *)a1 )
return puts("The stack is empty");
for ( i = *(_QWORD **)(a1 + 8); i; i = (_QWORD *)i[1] )
result = a2(*i);
return result;
}

canonical_decompiled_code:
int __fastcall func13(__int64 a1, __int64 (__fastcall *a2)(_QWORD))
{
int result; // eax
_QWORD *i; // rbx

result = *(_DWORD *)a1;
if ( !*(_DWORD *)a1 )
return puts("The stack is empty");
for ( i = *(_QWORD **)(a1 + 8); i; i = (_QWORD *)i[1] )
result = a2(*i);
return result;
}

original_code:
void stack_show(stack_t *stack, show_t *show)
{
 if(stack->size==0)
 {
  printf("The stack is empty\n");
  return ;
 }
 stack_elem_t* elem=stack->top;
 while(elem!=((void *)0))
 {
  show(elem->data);
  elem=elem->next;
 }
}

canonical_original_code:
void stack_show(struct stack *stack, void (*show)(void *data))
{
 if(stack->size==0)
 {
  printf("The stack is empty\n");
  return ;
 }
 struct stack_elem *elem = stack->top;
 while(elem!=((void *)0))
 {
  show(elem->data);
  elem=elem->next;
 }
}

variable_types:
show
void (*)(void *data)


decompiled_code:
_BOOL8 __fastcall stack_read(_DWORD *a1)
{
return *a1 != 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func14(_DWORD *a1)
{
return *a1 != 0;
}

original_code:
int stack_read(stack_t* stack,void **data)
{
 if(stack->size==0)
  return 0;
 data=&(stack->top->data);
 return 1;
}

canonical_original_code:
int stack_read(struct stack *stack, void **data)
{
 if(stack->size==0)
  return 0;
 data=&(stack->top->data);
 return 1;
}

variable_types:
data
void **


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
_DWORD *v3; // rax
_DWORD *v4; // rbp
_DWORD *v5; // rax
_DWORD *v6; // rax
void *v7; // rax
_BYTE v9[56]; // [rsp+0h] [rbp-38h] BYREF

v3 = malloc(4uLL);
*v3 = 123;
v4 = v3;
stack_init(v9, 0LL, 0LL);
stack_push(v9, v4);
stack_show(v9, show);
v5 = malloc(4uLL);
*v5 = 456;
stack_push(v9, v5);
v6 = malloc(4uLL);
*v6 = 789;
stack_push(v9, v6);
stack_show(v9, show);
v7 = (void *)stack_pop(v9);
free(v7);
stack_show(v9, show);
stack_destroy(v9);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
_DWORD *v3; // rax
_DWORD *v4; // rbp
_DWORD *v5; // rax
_DWORD *v6; // rax
void *v7; // rax
_BYTE v9[56]; // [rsp+0h] [rbp-38h] BYREF

v3 = malloc(4uLL);
*v3 = 123;
v4 = v3;
stack_init(v9, 0LL, 0LL);
func12(v9, v4);
func13(v9, show);
v5 = malloc(4uLL);
*v5 = 456;
func12(v9, v5);
v6 = malloc(4uLL);
*v6 = 789;
func12(v9, v6);
func13(v9, show);
v7 = (void *)func11(v9);
free(v7);
func13(v9, show);
func10(v9);
return 0;
}

original_code:
int main()
{
 stack_t stack1;
 int *p=(int*)malloc(sizeof(int));
 *p=123;
 int *b;
 stack_init(&stack1,((void *)0),((void *)0));
 stack_push(&stack1,(void*)p);
 stack_show(&stack1,show);
 p=(int*)malloc(sizeof(int));
 *p=456;
 stack_push(&stack1,(void*)p);
 p=(int*)malloc(sizeof(int));
 *p=789;
 stack_push(&stack1,(void*)p);
 stack_show(&stack1,show);
 b = (int *)stack_pop(&stack1);
 free(b);
 stack_show(&stack1,show);
 stack_destroy(&stack1);
 return 0;
}

canonical_original_code:
int main()
{
 struct stack stack1;
 int *p = (int*)malloc(sizeof(int));
 *p=123;
 int *b;
 stack_init(&stack1,((void *)0),((void *)0));
 stack_push(&stack1,(void *)p);
 stack_show(&stack1,show);
 p=(int *)malloc(sizeof(int));
 *p=456;
 stack_push(&stack1,(void *)p);
 p=(int *)malloc(sizeof(int));
 *p=789;
 stack_push(&stack1,(void *)p);
 stack_show(&stack1,show);
 b = (int *)stack_pop(&stack1);
 free(b);
 stack_show(&stack1,show);
 stack_destroy(&stack1);
 return 0;
}

variable_types: struct stack { int size; struct stack_elem { void *data; struct stack_elem *next; } *top; struct stack_elem *bottom; int (*cmp)(void *key1, void *key2, unsigned long size); void (*free)(void *data); }

variable_types:
p
int *

variable_types:
b
int *


destroyHashTable

decompiled_code:
void __fastcall destroyHashTable(__int64 a1)
{
free(*(void **)a1);
*(_QWORD *)a1 = 0LL;
*(_QWORD *)(a1 + 8) = 0LL;
}

canonical_decompiled_code:
void __fastcall func7(__int64 a1)
{
free(*(void **)a1);
*(_QWORD *)a1 = 0LL;
*(_QWORD *)(a1 + 8) = 0LL;
}

original_code:
void destroyHashTable(HashTable *H)
{
 free(H->elem);
 H->count=0;
 H->sizeindex=0;
 H->elem=((void *)0);
}

canonical_original_code:
void destroyHashTable(struct HashTable *H)
{
 free(H->elem);
 H->count=0;
 H->sizeindex=0;
 H->elem=((void *)0);
}

variable_types: struct HashTable { struct ElemType { int key; int ord; } *elem; int count; int sizeindex; } *

user_defined_types: struct HashTable { struct ElemType *elem; int count; int sizeindex; }


Hash

decompiled_code:
__int64 __fastcall Hash(int a1)
{
return (unsigned int)(a1 % m);
}

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

original_code:
unsigned Hash(const KeyType key)
{
 return key%m;
}

canonical_original_code:
unsigned int Hash(int key)
{
 return key%m;
}

variable_types: key int

return_type: unsigned int


searchHash

decompiled_code:
_BOOL8 __fastcall searchHash(__int64 a1, int a2, int *a3)
{
_DWORD *v5; // rcx
int v6; // er8
_QWORD *v7; // r9
int v8; // eax

*a3 = Hash(a2);
*v5 = 0;
while ( 1 )
{
v8 = *(_DWORD *)(*v7 + 8LL * *a3);
if ( v8 == -1 )
return v6 == -1;
if ( v6 == v8 )
break;
++*v5;
collision(a3);
}
return 1LL;
}

canonical_decompiled_code:
_BOOL8 __fastcall func10(__int64 a1, int a2, int *a3)
{
_DWORD *v5; // rcx
int v6; // er8
_QWORD *v7; // r9
int v8; // eax

*a3 = func8(a2);
*v5 = 0;
while ( 1 )
{
v8 = *(_DWORD *)(*v7 + 8LL * *a3);
if ( v8 == -1 )
return v6 == -1;
if ( v6 == v8 )
break;
++*v5;
func9(a3);
}
return 1LL;
}

original_code:
Status searchHash(const HashTable *H,KeyType K,int *p,int *c)
{
 *p=Hash(K);
 *c=0;
 while(H->elem[*p].key!=-1&&!((K)==(H->elem[*p].key)))
 {
  (*c)++;
  collision(p);
 }
 if ((K)==(H->elem[*p].key))
  return 1;
 else
   {
  p=((void *)0);
  return 0;
   }
}

canonical_original_code:
int searchHash(struct HashTable *H, int K, int *p, int *c)
{
 *p=Hash(K);
 *c=0;
 while(H->elem[*p].key!=-1&&!((K)==(H->elem[*p].key)))
 {
  (*c)++;
  collision(p);
 }
 if ((K)==(H->elem[*p].key))
  return 1;
 else
   {
  p=((void *)0);
  return 0;
   }
}

variable_types: K int

variable_types:
c
int *


SearchHash

decompiled_code:
_BOOL8 __fastcall SearchHash(__int64 a1, int a2, int *a3)
{
return searchHash(a1, a2, a3);
}

canonical_decompiled_code:
_BOOL8 __fastcall func11(__int64 a1, int a2, int *a3)
{
return func10(a1, a2, a3);
}

original_code:
Status SearchHash(const HashTable *H,KeyType K,int *p)
{
  int c;
  return searchHash(H,K,p,&c);
}

canonical_original_code:
int SearchHash(struct HashTable *H, int K, int *p)
{
  int c;
  return searchHash(H,K,p,&c);
}

variable_types: c int


InsertHash

decompiled_code:
__int64 __fastcall InsertHash(__int64 a1, int a2)
{
unsigned int v2; // er12
__int64 v3; // r10
__int64 v4; // r11
int v6; // [rsp+8h] [rbp-10h]
int v7[3]; // [rsp+Ch] [rbp-Ch] BYREF

v2 = -1;
if ( searchHash(a1, a2, v7) )
return v2;
if ( hashsize[*(int *)(v3 + 12)] / 2 > v6 )
{
v2 = 1;
*(_QWORD *)(*(_QWORD *)v3 + 8LL * v7[0]) = v4;
++*(_DWORD *)(v3 + 8);
return v2;
}
puts(&byte_402090);
return 0LL;
}

original_code:
Status InsertHash(HashTable *H,ElemType e)
{
 int c,p;
 if(searchHash(H,e.key,&p,&c))
  return -1;
 else
  if(c<hashsize[H->sizeindex]/2)
  {
   H->elem[p]=e;
   ++H->count;
   return 1;
  }
  else
  {
   printf("冲突过多需要重新建表！\n");
   return 0;
  }
}

canonical_original_code:
int InsertHash(struct HashTable *H, struct ElemType e)
{
 int c; int p;
 if(searchHash(H,e.key,&p,&c))
  return -1;
 else
  if(c<hashsize[H->sizeindex]/2)
  {
   H->elem[p]=e;
   ++H->count;
   return 1;
  }
  else
  {
   printf("冲突过多需要重新建表！\n");
   return 0;
  }
}

variable_types:
e
struct ElemType

variable_types: p int


DeletHash

decompiled_code:
__int64 __fastcall DeletHash(__int64 a1, int a2)
{
__int64 *v2; // r10
__int64 result; // rax
int v4; // [rsp+Ch] [rbp-4h] BYREF

SearchHash(a1, a2, &v4);
result = *v2;
*(_QWORD *)(*v2 + 8LL * v4) = 0xFFFFFFFFLL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func13(__int64 a1, int a2)
{
__int64 *v2; // r10
__int64 result; // rax
int v4; // [rsp+Ch] [rbp-4h] BYREF

func11(a1, a2, &v4);
result = *v2;
*(_QWORD *)(*v2 + 8LL * v4) = 0xFFFFFFFFLL;
return result;
}

original_code:
Status DeletHash(HashTable *H,KeyType K)
{
     int p;
     SearchHash(H,K,&p);
     H->elem[p].key=-1;
     H->elem[p].ord=0;
}

canonical_original_code:
int DeletHash(struct HashTable *H, int K)
{
     int p;
     SearchHash(H,K,&p);
     H->elem[p].key=-1;
     H->elem[p].ord=0;
}


TraverseHash

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

result = *(int *)(a1 + 12);
if ( hashsize[result] > 0 )
{
v3 = *(int *)(a1 + 12);
v4 = 0LL;
do
{
v5 = (_QWORD *)(*(_QWORD *)a1 + 8 * v4);
if ( *(_DWORD *)v5 != -1 )
{
a2((unsigned int)v4, *v5, v3);
v3 = *(unsigned int *)(a1 + 12);
}
result = (int)v3;
++v4;
}
while ( hashsize[(int)v3] > (int)v4 );
}
return result;
}

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

result = *(int *)(a1 + 12);
if ( hashsize[result] > 0 )
{
v3 = *(int *)(a1 + 12);
v4 = 0LL;
do
{
v5 = (_QWORD *)(*(_QWORD *)a1 + 8 * v4);
if ( *(_DWORD *)v5 != -1 )
{
a2((unsigned int)v4, *v5, v3);
v3 = *(unsigned int *)(a1 + 12);
}
result = (int)v3;
++v4;
}
while ( hashsize[(int)v3] > (int)v4 );
}
return result;
}

original_code:
void TraverseHash(const HashTable *H,void(*Vi)(int,ElemType))
{
 int i;
 for(i=0;i<hashsize[H->sizeindex];i++)
  if(H->elem[i].key!=-1)
    Vi(i,H->elem[i]);
}

canonical_original_code:
void TraverseHash(struct HashTable *H, void (*Vi)(int, struct ElemType))
{
 int i;
 for(i=0;i<hashsize[H->sizeindex];i++)
  if(H->elem[i].key!=-1)
    Vi(i,H->elem[i]);
}

variable_types:
Vi
void (*)(int, struct ElemType)

variable_types: i int


print

decompiled_code:
int __fastcall print(unsigned int a1, __int64 a2)
{
return printf("address=%d (%d,%d) \n", a1, a2, a2 >> 32);
}

canonical_decompiled_code:
int __fastcall func15(unsigned int a1, __int64 a2)
{
return printf("address=%d (%d,%d) \n", a1, a2, a2 >> 32);
}

original_code:
void print(int p,ElemType r)
{
   printf("address=%d (%d,%d) \n",p,r.key,r.ord);
}

canonical_original_code:
void print(int p, struct ElemType r)
{
   printf("address=%d (%d,%d) \n",p,r.key,r.ord);
}

variable_types:
r
struct ElemType { int key; int ord; }


eq

decompiled_code:
_BOOL8 __fastcall eq(_DWORD *a1, _DWORD *a2)
{
return *a1 == *a2;
}

canonical_decompiled_code:
_BOOL8 __fastcall func7(_DWORD *a1, _DWORD *a2)
{
return *a1 == *a2;
}

original_code:
int eq(const void * key1,const void * key2)
{
 if(*(int*)key1 == *(int*)key2)
  return 1;
 return 0;
}

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


destroy

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

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

original_code:
void destroy(void *data)
{
 free(data);
}

variable_types:
data
void *


original_code:
int set_init(set_t *set,int (*eq)(const void *,const void *),void (*destroy)(void *))
{
 set->size=0;
 set->head=((void *)0);
 set->eq=eq;
 set->destroy=destroy;
}

canonical_original_code:
int set_init(struct set *set, int (*eq)(void *, void *), void (*destroy)(void *))
{
 set->size=0;
 set->head=((void *)0);
 set->eq=eq;
 set->destroy=destroy;
}

variable_types: struct set { int size; struct setelem { void *data; struct setelem *next; long updatetime; } *head; struct setelem *tail; int (*eq)(void *key1, void *key2); void (*destroy)(void *data); } *

variable_types:
eq
int (*)(void *, void *)

variable_types:
destroy
void (*)(void *)

user_defined_types: struct set { int size; struct setelem *head; struct setelem *tail; int (*eq)(void *key1, void *key2); void (*destroy)(void *data); }


original_code:
int set_remove(set_t *set,void *data)
{
 if(((set)->size)==0)
  return 1;
 setelem_t *pre;
 setelem_t *del;
 pre=del=set->head;
 while(del != ((void *)0))
 {
  if(!eq(del->data,data))
  {
   pre=del;
   del=del->next;
   continue;
  }
  if(((set)->size)==1)
  {
   set->tail=((void *)0);
   set->head=((void *)0);
  }
  else
   if(del==set->head)
    set->head=del->next;
   else
    pre->next=del->next;
  set->size--;
  set->destroy(del->data);
  free(del);
  return 0;
 }
 return 1;
}

canonical_original_code:
int set_remove(struct set *set, void *data)
{
 if(((set)->size)==0)
  return 1;
 struct setelem *pre;
 struct setelem *del;
 pre=del=set->head;
 while(del != ((void *)0))
 {
  if(!eq(del->data,data))
  {
   pre=del;
   del=del->next;
   continue;
  }
  if(((set)->size)==1)
  {
   set->tail=((void *)0);
   set->head=((void *)0);
  }
  else
   if(del==set->head)
    set->head=del->next;
   else
    pre->next=del->next;
  set->size--;
  set->destroy(del->data);
  free(del);
  return 0;
 }
 return 1;
}

variable_types: struct setelem { void *data; struct setelem *next; long updatetime; } *


original_code:
int set_removeall(set_t *set)
{
 if(((set)->size)==0)
  return 0;
 setelem_t *p=set->head;
 while(p != ((void *)0))
 {
  set->head=p->next;
  set->destroy(p->data);
  free(p);
  p=set->head;
 }
 set->tail=((void *)0);
 return 0;
}

canonical_original_code:
int set_removeall(struct set *set)
{
 if(((set)->size)==0)
  return 0;
 struct setelem *p = set->head;
 while(p != ((void *)0))
 {
  set->head=p->next;
  set->destroy(p->data);
  free(p);
  p=set->head;
 }
 set->tail=((void *)0);
 return 0;
}

user_defined_types: struct setelem { void *data; struct setelem *next; long updatetime; }


decompiled_code:
__int64 __fastcall set_destroy(_QWORD *a1)
{
__int64 result; // rax

result = set_removeall((__int64)a1);
*a1 = 0LL;
return result;
}

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

result = func11((__int64)a1);
*a1 = 0LL;
return result;
}

original_code:
void set_destroy(set_t *set)
{
 set_removeall(set);
 memset(set,0,sizeof(set));
}

canonical_original_code:
void set_destroy(struct set *set)
{
 set_removeall(set);
 memset(set,0,sizeof(set));
}


decompiled_code:
time_t __fastcall set_update(__int64 a1)
{
__int64 v1; // rbx
time_t result; // rax
time_t timer; // [rsp+8h] [rbp-20h] BYREF

v1 = *(_QWORD *)(a1 + 8);
for ( result = time(&timer); v1; v1 = *(_QWORD *)(v1 + 8) )
{
while ( 1 )
{
result = timer - *(_QWORD *)(v1 + 16);
if ( result > 10 )
break;
v1 = *(_QWORD *)(v1 + 8);
if ( !v1 )
return result;
}
result = set_remove((int *)a1, *(_DWORD **)v1);
}
return result;
}

canonical_decompiled_code:
time_t __fastcall func13(__int64 a1)
{
__int64 v1; // rbx
time_t result; // rax
time_t timer; // [rsp+8h] [rbp-20h] BYREF

v1 = *(_QWORD *)(a1 + 8);
for ( result = time(&timer); v1; v1 = *(_QWORD *)(v1 + 8) )
{
while ( 1 )
{
result = timer - *(_QWORD *)(v1 + 16);
if ( result > 10 )
break;
v1 = *(_QWORD *)(v1 + 8);
if ( !v1 )
return result;
}
result = func10((int *)a1, *(_DWORD **)v1);
}
return result;
}

original_code:
void set_update(set_t *set)
{
 setelem_t *p=set->head;
 time_t nowtime;
 time(&nowtime);
 while(p != ((void *)0))
 {
  if((nowtime - p->updatetime) > 10)
   set_remove(set,p->data);
  p=p->next;
 }
}

canonical_original_code:
void set_update(struct set *set)
{
 struct setelem *p = set->head;
 long nowtime;
 time(&nowtime);
 while(p != ((void *)0))
 {
  if((nowtime - p->updatetime) > 10)
   set_remove(set,p->data);
  p=p->next;
 }
}

variable_types: nowtime long


decompiled_code:
__int64 __fastcall set_is_member(_DWORD *a1, _DWORD *a2)
{
_DWORD *v2; // rbx

v2 = a1;
set_update((__int64)a1);
if ( *a1 )
{
while ( 1 )
{
v2 = (_DWORD *)*((_QWORD *)v2 + 1);
if ( !v2 )
break;
if ( eq(*(_DWORD **)v2, a2) )
return 1LL;
}
}
return 0LL;
}

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

v2 = a1;
func13((__int64)a1);
if ( *a1 )
{
while ( 1 )
{
v2 = (_DWORD *)*((_QWORD *)v2 + 1);
if ( !v2 )
break;
if ( func7(*(_DWORD **)v2, a2) )
return 1LL;
}
}
return 0LL;
}

original_code:
int set_is_member(set_t* set,const void *key)
{
 set_update(set);
 if(0==((set)->size))
  return 0;
 setelem_t* p=set->head;
 while(p != ((void *)0))
 {
  if(eq(p->data,key))
   return 1;
  p=p->next;
 }
 return 0;
}

canonical_original_code:
int set_is_member(struct set *set, void *key)
{
 set_update(set);
 if(0==((set)->size))
  return 0;
 struct setelem *p = set->head;
 while(p != ((void *)0))
 {
  if(eq(p->data,key))
   return 1;
  p=p->next;
 }
 return 0;
}

variable_types:
key
void *


decompiled_code:
__int64 __fastcall set_insert(__int64 a1, _DWORD *a2)
{
__int64 result; // rax
_QWORD *v3; // rax
_QWORD *v4; // r13
int v5; // eax
__int64 v6; // rdx

set_update(a1);
if ( (unsigned int)set_is_member((_DWORD *)a1, a2) )
return 1LL;
v3 = malloc(0x18uLL);
v4 = v3;
if ( !v3 )
return 1LL;
*v3 = a2;
time(v3 + 2);
v5 = *(_DWORD *)a1;
if ( !*(_DWORD *)a1 )
*(_QWORD *)(a1 + 16) = v4;
v6 = *(_QWORD *)(a1 + 8);
*(_QWORD *)(a1 + 8) = v4;
*(_DWORD *)a1 = v5 + 1;
result = 0LL;
v4[1] = v6;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func15(__int64 a1, _DWORD *a2)
{
__int64 result; // rax
_QWORD *v3; // rax
_QWORD *v4; // r13
int v5; // eax
__int64 v6; // rdx

func13(a1);
if ( (unsigned int)func14((_DWORD *)a1, a2) )
return 1LL;
v3 = malloc(0x18uLL);
v4 = v3;
if ( !v3 )
return 1LL;
*v3 = a2;
time(v3 + 2);
v5 = *(_DWORD *)a1;
if ( !*(_DWORD *)a1 )
*(_QWORD *)(a1 + 16) = v4;
v6 = *(_QWORD *)(a1 + 8);
*(_QWORD *)(a1 + 8) = v4;
*(_DWORD *)a1 = v5 + 1;
result = 0LL;
v4[1] = v6;
return result;
}

original_code:
int set_insert(set_t *set,const void *data)
{
 set_update(set);
 if(set_is_member(set,data))
  return 1;
 setelem_t *new_elem;
 new_elem=(setelem_t*)malloc(sizeof(setelem_t));
 if(new_elem==((void *)0))
  return 1;
 new_elem->data=(void *)data;
 time(&(new_elem->updatetime));
 if(((set)->size)==0)
  set->tail=new_elem;
 new_elem->next=set->head;
 set->head=new_elem;
 set->size++;
 return 0;
}

canonical_original_code:
int set_insert(struct set *set, void *data)
{
 set_update(set);
 if(set_is_member(set,data))
  return 1;
 struct setelem *new_elem;
 new_elem=(struct setelem *)malloc(sizeof(setelem_t));
 if(new_elem==((void *)0))
  return 1;
 new_elem->data=(void *)data;
 time(&(new_elem->updatetime));
 if(((set)->size)==0)
  set->tail=new_elem;
 new_elem->next=set->head;
 set->head=new_elem;
 set->size++;
 return 0;
}


decompiled_code:
__int64 __fastcall set_is_subset(_DWORD *a1, _DWORD *a2)
{
_DWORD *v2; // rbx

v2 = a1;
set_update((__int64)a1);
set_update((__int64)a2);
if ( *a1 )
{
if ( *a1 > *a2 )
return 0LL;
while ( 1 )
{
v2 = (_DWORD *)*((_QWORD *)v2 + 1);
if ( !v2 )
break;
if ( !(unsigned int)set_is_member(a2, *(_DWORD **)v2) )
return 0LL;
}
}
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func16(_DWORD *a1, _DWORD *a2)
{
_DWORD *v2; // rbx

v2 = a1;
func13((__int64)a1);
func13((__int64)a2);
if ( *a1 )
{
if ( *a1 > *a2 )
return 0LL;
while ( 1 )
{
v2 = (_DWORD *)*((_QWORD *)v2 + 1);
if ( !v2 )
break;
if ( !(unsigned int)func14(a2, *(_DWORD **)v2) )
return 0LL;
}
}
return 1LL;
}

original_code:
int set_is_subset(set_t* set1,set_t* set2)
{
 set_update(set1);
 set_update(set2);
 if(((set1)->size)==0)
  return 1;
 if(((set1)->size) > ((set2)->size))
  return 0;
 setelem_t *set1elem=set1->head;
 setelem_t *set2elem;
 while(set1elem != ((void *)0))
 {
  if(!set_is_member(set2,set1elem->data))
   return 0;
  set1elem=set1elem->next;
 }
 return 1;
}

canonical_original_code:
int set_is_subset(struct set *set1, struct set *set2)
{
 set_update(set1);
 set_update(set2);
 if(((set1)->size)==0)
  return 1;
 if(((set1)->size) > ((set2)->size))
  return 0;
 struct setelem *set1elem = set1->head;
 struct setelem *set2elem;
 while(set1elem != ((void *)0))
 {
  if(!set_is_member(set2,set1elem->data))
   return 0;
  set1elem=set1elem->next;
 }
 return 1;
}


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

set_update((__int64)a1);
set_update((__int64)a2);
result = 0LL;
if ( *a1 == *a2 )
{
set_is_subset(a1, a2);
result = 1LL;
}
return result;
}

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

func13((__int64)a1);
func13((__int64)a2);
result = 0LL;
if ( *a1 == *a2 )
{
func16(a1, a2);
result = 1LL;
}
return result;
}

original_code:
int set_is_equal(set_t *set1,set_t *set2)
{
 set_update(set1);
 set_update(set2);
 if(((set1)->size) != ((set2)->size))
  return 0;
 if(set_is_subset(set1,set2))
  return 1;
}

canonical_original_code:
int set_is_equal(struct set *set1, struct set *set2)
{
 set_update(set1);
 set_update(set2);
 if(((set1)->size) != ((set2)->size))
  return 0;
 if(set_is_subset(set1,set2))
  return 1;
}


decompiled_code:
__int64 __fastcall set_union(_QWORD *a1, __int64 a2, __int64 a3)
{
__int64 v4; // rbx
_DWORD **v6; // rbx

set_update(a2);
set_update(a3);
v4 = *(_QWORD *)(a2 + 8);
if ( v4 )
{
while ( !(unsigned int)set_insert((__int64)a1, *(_DWORD **)v4) )
{
v4 = *(_QWORD *)(v4 + 8);
if ( !v4 )
goto LABEL_6;
}
goto LABEL_5;
}
LABEL_6:
v6 = *(_DWORD ***)(a3 + 8);
if ( v6 )
{
while ( (unsigned int)set_is_member((_DWORD *)a2, *v6) || !(unsigned int)set_insert((__int64)a1, *v6) )
{
v6 = (_DWORD **)v6[1];
if ( !v6 )
return 0LL;
}
LABEL_5:
set_destroy(a1);
return 1LL;
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func18(_QWORD *a1, __int64 a2, __int64 a3)
{
__int64 v4; // rbx
_DWORD **v6; // rbx

func13(a2);
func13(a3);
v4 = *(_QWORD *)(a2 + 8);
if ( v4 )
{
while ( !(unsigned int)func15((__int64)a1, *(_DWORD **)v4) )
{
v4 = *(_QWORD *)(v4 + 8);
if ( !v4 )
goto LABEL_6;
}
goto LABEL_5;
}
LABEL_6:
v6 = *(_DWORD ***)(a3 + 8);
if ( v6 )
{
while ( (unsigned int)func14((_DWORD *)a2, *v6) || !(unsigned int)func15((__int64)a1, *v6) )
{
v6 = (_DWORD **)v6[1];
if ( !v6 )
return 0LL;
}
LABEL_5:
func12(a1);
return 1LL;
}
return 0LL;
}

original_code:
int set_union(set_t *set,set_t *set1,set_t *set2)
{
 set_update(set1);
 set_update(set2);
 setelem_t *p=set1->head;
 while(p != ((void *)0))
 {
  if(set_insert(set,p->data)==0)
   p=p->next;
  else
  {
   set_destroy(set);
   return 1;
  }
 }
 p=set2->head;
 while(p != ((void *)0))
 {
  if(!set_is_member(set1,p->data))
   if(set_insert(set,p->data)!=0)
   {
    set_destroy(set);
    return 1;
   }
  p=p->next;
 }
 return 0;
}

canonical_original_code:
int set_union(struct set *set, struct set *set1, struct set *set2)
{
 set_update(set1);
 set_update(set2);
 struct setelem *p = set1->head;
 while(p != ((void *)0))
 {
  if(set_insert(set,p->data)==0)
   p=p->next;
  else
  {
   set_destroy(set);
   return 1;
  }
 }
 p=set2->head;
 while(p != ((void *)0))
 {
  if(!set_is_member(set1,p->data))
   if(set_insert(set,p->data)!=0)
   {
    set_destroy(set);
    return 1;
   }
  p=p->next;
 }
 return 0;
}


decompiled_code:
__int64 __fastcall set_intersection(_QWORD *a1, __int64 a2, _DWORD *a3)
{
_DWORD **v4; // rbx

v4 = (_DWORD **)a2;
set_update(a2);
set_update((__int64)a3);
while ( 1 )
{
v4 = (_DWORD **)v4[1];
if ( !v4 )
break;
if ( (unsigned int)set_is_member(a3, *v4) && (unsigned int)set_insert((__int64)a1, *v4) )
{
set_destroy(a1);
return 1LL;
}
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func19(_QWORD *a1, __int64 a2, _DWORD *a3)
{
_DWORD **v4; // rbx

v4 = (_DWORD **)a2;
func13(a2);
func13((__int64)a3);
while ( 1 )
{
v4 = (_DWORD **)v4[1];
if ( !v4 )
break;
if ( (unsigned int)func14(a3, *v4) && (unsigned int)func15((__int64)a1, *v4) )
{
func12(a1);
return 1LL;
}
}
return 0LL;
}

original_code:
int set_intersection(set_t* set,set_t* set1,set_t* set2)
{
 set_update(set1);
 set_update(set2);
 setelem_t * p=set1->head;
 while(p != ((void *)0))
 {
  if(set_is_member(set2,p->data))
   if(set_insert(set,p->data)!=0)
   {
    set_destroy(set);
    return 1;
   }
  p=p->next;
 }
 return 0;
}

canonical_original_code:
int set_intersection(struct set *set, struct set *set1, struct set *set2)
{
 set_update(set1);
 set_update(set2);
 struct setelem *p = set1->head;
 while(p != ((void *)0))
 {
  if(set_is_member(set2,p->data))
   if(set_insert(set,p->data)!=0)
   {
    set_destroy(set);
    return 1;
   }
  p=p->next;
 }
 return 0;
}


decompiled_code:
__int64 __fastcall set_difference(_QWORD *a1, __int64 a2, _DWORD *a3)
{
_DWORD **v4; // rbx

v4 = (_DWORD **)a2;
set_update(a2);
set_update((__int64)a3);
while ( 1 )
{
v4 = (_DWORD **)v4[1];
if ( !v4 )
break;
if ( !(unsigned int)set_is_member(a3, *v4) && (unsigned int)set_insert((__int64)a1, *v4) )
{
set_destroy(a1);
return 1LL;
}
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func20(_QWORD *a1, __int64 a2, _DWORD *a3)
{
_DWORD **v4; // rbx

v4 = (_DWORD **)a2;
func13(a2);
func13((__int64)a3);
while ( 1 )
{
v4 = (_DWORD **)v4[1];
if ( !v4 )
break;
if ( !(unsigned int)func14(a3, *v4) && (unsigned int)func15((__int64)a1, *v4) )
{
func12(a1);
return 1LL;
}
}
return 0LL;
}

original_code:
int set_difference(set_t *set,set_t *set1,set_t * set2)
{
 set_update(set1);
 set_update(set2);
 setelem_t * p=set1->head;
 while(p != ((void *)0))
 {
  if(!set_is_member(set2,p->data))
   if(set_insert(set,p->data)!=0)
   {
    set_destroy(set);
    return 1;
   }
  p=p->next;
 }
 return 0;
}

canonical_original_code:
int set_difference(struct set *set, struct set *set1, struct set *set2)
{
 set_update(set1);
 set_update(set2);
 struct setelem *p = set1->head;
 while(p != ((void *)0))
 {
  if(!set_is_member(set2,p->data))
   if(set_insert(set,p->data)!=0)
   {
    set_destroy(set);
    return 1;
   }
  p=p->next;
 }
 return 0;
}


decompiled_code:
int __fastcall set_show(__int64 a1)
{
unsigned int **v1; // rbx

set_update(a1);
v1 = *(unsigned int ***)(a1 + 8);
if ( !v1 )
return puts("The set is empty");
do
{
printf("%d\t", **v1);
v1 = (unsigned int **)v1[1];
}
while ( v1 );
return puts("\n");
}

canonical_decompiled_code:
int __fastcall func21(__int64 a1)
{
unsigned int **v1; // rbx

func13(a1);
v1 = *(unsigned int ***)(a1 + 8);
if ( !v1 )
return puts("The set is empty");
do
{
printf("%d\t", **v1);
v1 = (unsigned int **)v1[1];
}
while ( v1 );
return puts("\n");
}

original_code:
void set_show(set_t *set)
{
 set_update(set);
 if(set->head==((void *)0))
 {
  printf("The set is empty\n");
  return ;
 }
 setelem_t * p;
 p=set->head;
 while(p!=((void *)0))
 {
  printf("%d\t",*(int *)(p->data));
  p=p->next;
 }
 printf("\n\n");
}

canonical_original_code:
void set_show(struct set *set)
{
 set_update(set);
 if(set->head==((void *)0))
 {
  printf("The set is empty\n");
  return ;
 }
 struct setelem *p;
 p=set->head;
 while(p!=((void *)0))
 {
  printf("%d\t",*(int *)(p->data));
  p=p->next;
 }
 printf("\n\n");
}


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // ebx
unsigned int *v4; // rax
unsigned int *v5; // rbp
int v6; // ebx
_DWORD *v7; // rax
_DWORD *v8; // rax
unsigned int i; // [rsp+Ch] [rbp-13Ch] BYREF
char v11[48]; // [rsp+10h] [rbp-138h] BYREF
char v12[48]; // [rsp+40h] [rbp-108h] BYREF
__int64 v13; // [rsp+70h] [rbp-D8h]
__int64 v14; // [rsp+78h] [rbp-D0h]
__int64 v15[4]; // [rsp+80h] [rbp-C8h] BYREF
char v16[48]; // [rsp+A0h] [rbp-A8h] BYREF
char v17[48]; // [rsp+D0h] [rbp-78h] BYREF
char v18[72]; // [rsp+100h] [rbp-48h] BYREF

v3 = 0;
set_init(v11, eq, destroy);
set_init(v12, eq, destroy);
i = 0;
v13 = 0x100000000LL;
v14 = 0x300000002LL;
v15[0] = 0x500000004LL;
v15[1] = 0x700000006LL;
v15[2] = 0x900000008LL;
do
{
v4 = (unsigned int *)malloc(4uLL);
*v4 = v3;
v5 = v4;
set_insert(v11, v4);
printf("Insert %d into set1\n", *v5);
puts("wait for 2s...");
sleep(2u);
v3 = i + 1;
i = v3;
}
while ( v3 <= 4 );
v6 = 0;
printf("set1:");
set_show(v11);
set_remove(v11, v15);
printf("set1:");
set_show(v11);
v7 = malloc(4uLL);
*v7 = 15;
set_insert(v11, v7);
printf("set1:");
set_show(v11);
puts("\n");
i = 0;
do
{
v8 = malloc(4uLL);
*v8 = v6;
set_insert(v12, v8);
v6 = i + 1;
i = v6;
}
while ( v6 <= 9 );
printf("set2:");
set_show(v12);
for ( i = 0; (int)i <= 6; ++i )
{
while ( (unsigned int)set_is_member(v11, &i) )
{
printf("%d is in set1\n", i++);
if ( (int)i > 6 )
goto LABEL_9;
}
printf("%d is not in set1\n", i);
}
LABEL_9:
set_init(v16, eq, destroy);
set_union(v16, v11, v12);
printf("setu:");
set_show(v16);
set_init(v17, eq, destroy);
set_intersection(v17, v11, v12);
printf("seti:");
set_show(v17);
puts("Testing set_is_equal");
printf("set1:");
set_show(v11);
printf("set:");
set_show(v11);
if ( (unsigned int)set_is_equal(v11) )
puts("set1 eq set3");
puts("Testing set_is_subset");
printf("set1:");
set_show(v11);
printf("set3:");
set_show(v11);
if ( (unsigned int)set_is_subset(v11) )
puts("set1 is set3's subset");
puts("Testint difference");
printf("set1:");
set_show(v11);
printf("set2:");
set_show(v12);
set_init(v18, eq, destroy);
set_difference(v18, v12, v11);
printf("setd:");
set_show(v18);
sleep(0xFu);
set_show(v11);
set_destroy(v16);
set_destroy(v11);
set_destroy(v12);
set_destroy(v18);
set_destroy(v17);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // ebx
unsigned int *v4; // rax
unsigned int *v5; // rbp
int v6; // ebx
_DWORD *v7; // rax
_DWORD *v8; // rax
unsigned int i; // [rsp+Ch] [rbp-13Ch] BYREF
char v11[48]; // [rsp+10h] [rbp-138h] BYREF
char v12[48]; // [rsp+40h] [rbp-108h] BYREF
__int64 v13; // [rsp+70h] [rbp-D8h]
__int64 v14; // [rsp+78h] [rbp-D0h]
__int64 v15[4]; // [rsp+80h] [rbp-C8h] BYREF
char v16[48]; // [rsp+A0h] [rbp-A8h] BYREF
char v17[48]; // [rsp+D0h] [rbp-78h] BYREF
char v18[72]; // [rsp+100h] [rbp-48h] BYREF

v3 = 0;
func9(v11, eq, destroy);
func9(v12, eq, destroy);
i = 0;
v13 = 0x100000000LL;
v14 = 0x300000002LL;
v15[0] = 0x500000004LL;
v15[1] = 0x700000006LL;
v15[2] = 0x900000008LL;
do
{
v4 = (unsigned int *)malloc(4uLL);
*v4 = v3;
v5 = v4;
func15(v11, v4);
printf("Insert %d into set1\n", *v5);
puts("wait for 2s...");
sleep(2u);
v3 = i + 1;
i = v3;
}
while ( v3 <= 4 );
v6 = 0;
printf("set1:");
func21(v11);
func10(v11, v15);
printf("set1:");
func21(v11);
v7 = malloc(4uLL);
*v7 = 15;
func15(v11, v7);
printf("set1:");
func21(v11);
puts("\n");
i = 0;
do
{
v8 = malloc(4uLL);
*v8 = v6;
func15(v12, v8);
v6 = i + 1;
i = v6;
}
while ( v6 <= 9 );
printf("set2:");
func21(v12);
for ( i = 0; (int)i <= 6; ++i )
{
while ( (unsigned int)func14(v11, &i) )
{
printf("%d is in set1\n", i++);
if ( (int)i > 6 )
goto LABEL_9;
}
printf("%d is not in set1\n", i);
}
LABEL_9:
func9(v16, eq, destroy);
func18(v16, v11, v12);
printf("setu:");
func21(v16);
func9(v17, eq, destroy);
func19(v17, v11, v12);
printf("seti:");
func21(v17);
puts("Testing set_is_equal");
printf("set1:");
func21(v11);
printf("set:");
func21(v11);
if ( (unsigned int)func17(v11) )
puts("set1 eq set3");
puts("Testing set_is_subset");
printf("set1:");
func21(v11);
printf("set3:");
func21(v11);
if ( (unsigned int)func16(v11) )
puts("set1 is set3's subset");
puts("Testint difference");
printf("set1:");
func21(v11);
printf("set2:");
func21(v12);
func9(v18, eq, destroy);
func20(v18, v12, v11);
printf("setd:");
func21(v18);
sleep(0xFu);
func21(v11);
func12(v16);
func12(v11);
func12(v12);
func12(v18);
func12(v17);
return 0;
}

original_code:
int main()
{
 set_t set1,set2;
 set_init(&set1,eq,destroy);
 set_init(&set2,eq,destroy);
 int i;
 int a[10]={0,1,2,3,4,5,6,7,8,9};
 int *data;
 for(i=0;i<5;i++)
 {
  data=(int *)malloc(sizeof(int));
  *data=i;
  set_insert(&set1,(void *)data);
  printf("Insert %d into set1\n",*data);
  printf("wait for 2s...\n");
  sleep(2);
 }
 printf("set1:");
 set_show(&set1);
 data=a;
 set_remove(&set1,(void*)(data+4));
 printf("set1:");
 set_show(&set1);
 data=(int*)malloc(sizeof(int));
 *data=15;
 set_insert(&set1,(void*)data);
 printf("set1:");
 set_show(&set1);
 printf("\n\n");
 for(i=0;i<10;i++)
 {
  data=(int *)malloc(sizeof(int));
  *data=i;
  set_insert(&set2,(void *)data);
 }
 printf("set2:");
 set_show(&set2);
 for(i=0;i<7;i++)
 {
  if(set_is_member(&set1,(void *)&i))
  {
   printf("%d is in set1\n",i);
  }
  else
   printf("%d is not in set1\n",i);
 }
 set_t setu;
 set_init(&setu,eq,destroy);
 set_union(&setu,&set1,&set2);
 printf("setu:");
 set_show(&setu);
 set_t seti;
 set_init(&seti,eq,destroy);
 set_intersection(&seti,&set1,&set2);
 printf("seti:");
 set_show(&seti);
 printf("Testing set_is_equal\n");
 printf("set1:");
 set_show(&set1);
 printf("set:");
 set_show(&set1);
 if(set_is_equal(&set1,&set1))
  printf("set1 eq set3\n");
 printf("Testing set_is_subset\n");
 printf("set1:");
 set_show(&set1);
 printf("set3:");
 set_show(&set1);
 if(set_is_subset(&set1,&set1))
  printf("set1 is set3's subset\n");
 printf("Testint difference\n");
 printf("set1:");
 set_show(&set1);
 printf("set2:");
 set_show(&set2);
 set_t setd;
 set_init(&setd,eq,destroy);
 set_difference(&setd,&set2,&set1);
 printf("setd:");
 set_show(&setd);
 sleep(15);
 set_show(&set1);
 set_destroy(&setu);
 set_destroy(&set1);
 set_destroy(&set2);
 set_destroy(&setd);
 set_destroy(&seti);
 return 0;
}

canonical_original_code:
int main()
{
 struct set set1; struct set set2;
 set_init(&set1,eq,destroy);
 set_init(&set2,eq,destroy);
 int i;
 int a[10] = {0,1,2,3,4,5,6,7,8,9};
 int *data;
 for(i=0;i<5;i++)
 {
  data=(int *)malloc(sizeof(int));
  *data=i;
  set_insert(&set1,(void *)data);
  printf("Insert %d into set1\n",*data);
  printf("wait for 2s...\n");
  sleep(2);
 }
 printf("set1:");
 set_show(&set1);
 data=a;
 set_remove(&set1,(void *)(data+4));
 printf("set1:");
 set_show(&set1);
 data=(int *)malloc(sizeof(int));
 *data=15;
 set_insert(&set1,(void *)data);
 printf("set1:");
 set_show(&set1);
 printf("\n\n");
 for(i=0;i<10;i++)
 {
  data=(int *)malloc(sizeof(int));
  *data=i;
  set_insert(&set2,(void *)data);
 }
 printf("set2:");
 set_show(&set2);
 for(i=0;i<7;i++)
 {
  if(set_is_member(&set1,(void *)&i))
  {
   printf("%d is in set1\n",i);
  }
  else
   printf("%d is not in set1\n",i);
 }
 struct set setu;
 set_init(&setu,eq,destroy);
 set_union(&setu,&set1,&set2);
 printf("setu:");
 set_show(&setu);
 struct set seti;
 set_init(&seti,eq,destroy);
 set_intersection(&seti,&set1,&set2);
 printf("seti:");
 set_show(&seti);
 printf("Testing set_is_equal\n");
 printf("set1:");
 set_show(&set1);
 printf("set:");
 set_show(&set1);
 if(set_is_equal(&set1,&set1))
  printf("set1 eq set3\n");
 printf("Testing set_is_subset\n");
 printf("set1:");
 set_show(&set1);
 printf("set3:");
 set_show(&set1);
 if(set_is_subset(&set1,&set1))
  printf("set1 is set3's subset\n");
 printf("Testint difference\n");
 printf("set1:");
 set_show(&set1);
 printf("set2:");
 set_show(&set2);
 struct set setd;
 set_init(&setd,eq,destroy);
 set_difference(&setd,&set2,&set1);
 printf("setd:");
 set_show(&setd);
 sleep(15);
 set_show(&set1);
 set_destroy(&setu);
 set_destroy(&set1);
 set_destroy(&set2);
 set_destroy(&setd);
 set_destroy(&seti);
 return 0;
}

variable_types: struct set { int size; struct setelem { void *data; struct setelem *next; long updatetime; } *head; struct setelem *tail; int (*eq)(void *key1, void *key2); void (*destroy)(void *data); }

variable_types:
a
int [10]

variable_types:
data
int *


repo: yuikns/callback

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

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

original_code:
int main(int argc,char *argv[])
{
 get_magic_num(use_magic_num);
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
 get_magic_num(use_magic_num);
 return 0;
}

variable_types: argc int

variable_types:
argv
char *[]


decompiled_code:
int __fastcall use_magic_num(unsigned int a1)
{
return printf("bar.c : magic number is %d \n", a1);
}

canonical_decompiled_code:
int __fastcall func7(unsigned int a1)
{
return printf("bar.c : magic number is %d \n", a1);
}

original_code:
void use_magic_num(int magic_num)
{
 printf("bar.c : magic number is %d \n", magic_num);
}


decompiled_code:
__int64 nv50_graph_reset()
{
__int64 result; // rax
int v1; // edx
int v2; // ecx

result = regs;
v1 = *(_DWORD *)(regs + 512);
v2 = v1;
BYTE1(v1) |= 0x10u;
BYTE1(v2) &= 0xEFu;
*(_DWORD *)(regs + 512) = v2;
*(_DWORD *)(result + 512) = v1;
*(int *)((char *)&dword_400040 + result) = -1;
*(int *)((char *)&dword_400040 + result) = 0;
return result;
}

canonical_decompiled_code:
__int64 func15()
{
__int64 result; // rax
int v1; // edx
int v2; // ecx

result = regs;
v1 = *(_DWORD *)(regs + 512);
v2 = v1;
BYTE1(v1) |= 0x10u;
BYTE1(v2) &= 0xEFu;
*(_DWORD *)(regs + 512) = v2;
*(_DWORD *)(result + 512) = v1;
*(int *)((char *)&dword_400040 + result) = -1;
*(int *)((char *)&dword_400040 + result) = 0;
return result;
}

variable_types:
enable
unsigned int


repo: yunccll/fat

decompiled_code:
void fat_time_fat2unix()
{
;
}

canonical_decompiled_code:
void func0()
{
;
}

original_code:
void fat_time_fat2unix(struct fat_sb *fsb, struct timespec64 *ts,
  __le16 __time, __le16 __date, u8 time_cs)
{
}

canonical_original_code:
void fat_time_fat2unix(struct fat_sb *fsb, struct timespec64 *ts, unsigned short __time, unsigned short __date, unsigned char time_cs)
{
}

variable_types: struct fat_sb { unsigned short sector_size; unsigned char fat_bits; unsigned int fsinfo_sector; unsigned short fat_sector_start; unsigned int fat_length; unsigned char fats; unsigned int root_dir_sector_start; unsigned short root_dir_entries; unsigned int data_sector_start; unsigned int max_sectors; unsigned short sec_per_clus; unsigned int root_cluster; unsigned int max_cluster; unsigned int cluster_size; unsigned short cluster_bits; int dir_per_block; int dir_per_block_bits; } *

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


decompiled_code:
__int64 __fastcall mode_from_fat_attr(char a1, unsigned int a2)
{
unsigned int v2; // eax
char v3; // di
int v4; // esi

v2 = a2;
LOBYTE(v2) = a2 & 0x6D;
if ( (a1 & 1) == 0 )
v2 = a2;
v3 = a1 & 0x10;
v4 = -(v3 == 0);
LOWORD(v4) = v3 == 0 ? 0x8000 : 0x4000;
return v4 | v2;
}

canonical_decompiled_code:
__int64 __fastcall func1(char a1, unsigned int a2)
{
unsigned int v2; // eax
char v3; // di
int v4; // esi

v2 = a2;
LOBYTE(v2) = a2 & 0x6D;
if ( (a1 & 1) == 0 )
v2 = a2;
v3 = a1 & 0x10;
v4 = -(v3 == 0);
LOWORD(v4) = v3 == 0 ? 0x8000 : 0x4000;
return v4 | v2;
}

original_code:
u8 mode_from_fat_attr(const u8 fat_attr, const umode_t mode)
{
    umode_t ret_mode = mode;
    if(fat_attr & 1){
        ret_mode &= ~(00200|00020|00002);
    }
    ret_mode |= ((fat_attr & 16) ? 0040000 : 0100000);
    return ret_mode;
}

canonical_original_code:
unsigned char mode_from_fat_attr(unsigned char fat_attr, unsigned short mode)
{
    unsigned short ret_mode = mode;
    if(fat_attr & 1){
        ret_mode &= ~(00200|00020|00002);
    }
    ret_mode |= ((fat_attr & 16) ? 0040000 : 0100000);
    return ret_mode;
}

variable_types:
mode
unsigned short

return_type: unsigned char


decompiled_code:
__int64 __fastcall fat_attr_make_from_mode(char a1, _BYTE *a2)
{
char v2; // al

v2 = *a2 | 1;
if ( (a1 & 0x92) != 0 )
v2 = *a2 & 0xFE;
*a2 = v2;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(char a1, _BYTE *a2)
{
char v2; // al

v2 = *a2 | 1;
if ( (a1 & 0x92) != 0 )
v2 = *a2 & 0xFE;
*a2 = v2;
return 0LL;
}

canonical_original_code:
int fat_attr_make_from_mode(unsigned char mode, unsigned char *fat_attr)
{
    if((((mode) & 00170000) == 0040000))
        *fat_attr |= 16;
    if( mode&(00200|00020|00002)){
        *fat_attr &= ~1;
    }
    else{
        *fat_attr |= 1;
    }
    return 0;
}

variable_types:
mode
unsigned char


decompiled_code:
void __fastcall fat_dev_destroy(void *ptr)
{
int *v1; // rax
char *v2; // rax

if ( ptr )
{
if ( close(*((_DWORD *)ptr + 2)) )
{
v1 = _errno_location();
v2 = strerror(*v1);
printf("close file [%s] error, error:%s\n", *(const char **)ptr, v2);
}
free(ptr);
}
}

canonical_decompiled_code:
void __fastcall func0(void *ptr)
{
int *v1; // rax
char *v2; // rax

if ( ptr )
{
if ( close(*((_DWORD *)ptr + 2)) )
{
v1 = _errno_location();
v2 = strerror(*v1);
printf("close file [%s] error, error:%s\n", *(const char **)ptr, v2);
}
free(ptr);
}
}

original_code:
void fat_dev_destroy(fat_dev_t * ptr){
    if(ptr){
        if(0 != close(ptr->_fd)){
            printf("close file [%s] error, error:%s\n", ptr->_fname, strerror((*__errno_location ())));
        }
        ptr->_is_connected = 0;
        ptr->_fname = ((void *)0);
        ptr->_fd = (-1);
        free(ptr);
    }
}

canonical_original_code:
void fat_dev_destroy(struct fat_dev_s *ptr){
    if(ptr){
        if(0 != close(ptr->_fd)){
            printf("close file [%s] error, error:%s\n", ptr->_fname, strerror((*__errno_location ())));
        }
        ptr->_is_connected = 0;
        ptr->_fname = ((void *)0);
        ptr->_fd = (-1);
        free(ptr);
    }
}

variable_types: struct fat_dev_s { char *_fname; int _fd; int _is_connected; } *


decompiled_code:
__off_t __fastcall fat_dev_write(__int64 a1, __off_t a2, const void *a3, size_t a4)
{
int v5; // edi
__off_t v8; // r12
ssize_t v9; // r12
__off_t result; // rax
int *v11; // rax
char *v12; // rax
int *v13; // rax
char *v14; // rax

v5 = *(_DWORD *)(a1 + 8);
if ( v5 == -1 )
{
v9 = -1LL;
puts("open device first");
return v9;
}
v8 = lseek(v5, a2, 0);
if ( v8 < 0 )
{
v11 = _errno_location();
v12 = strerror(*v11);
printf("lseek file failed! err:%s\n", v12);
result = v8;
}
else
{
v9 = write(*(_DWORD *)(a1 + 8), a3, a4);
if ( v9 >= 0 )
return v9;
v13 = _errno_location();
v14 = strerror(*v13);
printf("write file failed! err:%s\n", v14);
result = v9;
}
return result;
}

canonical_decompiled_code:
__off_t __fastcall func1(__int64 a1, __off_t a2, const void *a3, size_t a4)
{
int v5; // edi
__off_t v8; // r12
ssize_t v9; // r12
__off_t result; // rax
int *v11; // rax
char *v12; // rax
int *v13; // rax
char *v14; // rax

v5 = *(_DWORD *)(a1 + 8);
if ( v5 == -1 )
{
v9 = -1LL;
puts("open device first");
return v9;
}
v8 = lseek(v5, a2, 0);
if ( v8 < 0 )
{
v11 = _errno_location();
v12 = strerror(*v11);
printf("lseek file failed! err:%s\n", v12);
result = v8;
}
else
{
v9 = write(*(_DWORD *)(a1 + 8), a3, a4);
if ( v9 >= 0 )
return v9;
v13 = _errno_location();
v14 = strerror(*v13);
printf("write file failed! err:%s\n", v14);
result = v9;
}
return result;
}

original_code:
long long fat_dev_write(fat_dev_t * ptr, fat_offset_t offset,const char * block, long long bytes){
    do { if((ptr->_fd == (-1))) { printf("open device first\n"); return -1; } } while (0);
    long long ret = lseek(ptr->_fd, offset, 0);
    do { if((ret < 0)) { printf("lseek file failed! err:%s\n", strerror((*__errno_location ()))); return ret; } } while (0);
    ret = write(ptr->_fd, block, bytes);
    do { if((ret < 0)) { printf("write file failed! err:%s\n", strerror((*__errno_location ()))); return ret; } } while (0);
    return ret;
}

canonical_original_code:
long long fat_dev_write(struct fat_dev_s *ptr, long long offset, char *block, long long bytes){
    do { if((ptr->_fd == (-1))) { printf("open device first\n"); return -1; } } while (0);
    long long ret = lseek(ptr->_fd, offset, 0);
    do { if((ret < 0)) { printf("lseek file failed! err:%s\n", strerror((*__errno_location ()))); return ret; } } while (0);
    ret = write(ptr->_fd, block, bytes);
    do { if((ret < 0)) { printf("write file failed! err:%s\n", strerror((*__errno_location ()))); return ret; } } while (0);
    return ret;
}

variable_types:
offset
long long

variable_types:
block
char *

variable_types:
bytes
long long

variable_types:
ret
long long

return_type: long long

user_defined_types: struct fat_dev_s { char *_fname; int _fd; int _is_connected; }


decompiled_code:
__off_t __fastcall fat_dev_read(__int64 a1, __off_t a2, void *a3, size_t a4)
{
int v5; // edi
__off_t v8; // r12
ssize_t v9; // r12
__off_t result; // rax
int *v11; // rax
char *v12; // rax
int *v13; // rax
char *v14; // rax

v5 = *(_DWORD *)(a1 + 8);
if ( v5 == -1 )
{
v9 = -1LL;
puts("open device first");
return v9;
}
v8 = lseek(v5, a2, 0);
if ( v8 < 0 )
{
v11 = _errno_location();
v12 = strerror(*v11);
printf("lseek file failed! err:%s\n", v12);
result = v8;
}
else
{
v9 = read(*(_DWORD *)(a1 + 8), a3, a4);
if ( v9 >= 0 )
return v9;
v13 = _errno_location();
v14 = strerror(*v13);
printf("read file failed! err:%s\n", v14);
result = v9;
}
return result;
}

canonical_decompiled_code:
__off_t __fastcall func2(__int64 a1, __off_t a2, void *a3, size_t a4)
{
int v5; // edi
__off_t v8; // r12
ssize_t v9; // r12
__off_t result; // rax
int *v11; // rax
char *v12; // rax
int *v13; // rax
char *v14; // rax

v5 = *(_DWORD *)(a1 + 8);
if ( v5 == -1 )
{
v9 = -1LL;
puts("open device first");
return v9;
}
v8 = lseek(v5, a2, 0);
if ( v8 < 0 )
{
v11 = _errno_location();
v12 = strerror(*v11);
printf("lseek file failed! err:%s\n", v12);
result = v8;
}
else
{
v9 = read(*(_DWORD *)(a1 + 8), a3, a4);
if ( v9 >= 0 )
return v9;
v13 = _errno_location();
v14 = strerror(*v13);
printf("read file failed! err:%s\n", v14);
result = v9;
}
return result;
}

original_code:
long long fat_dev_read(fat_dev_t * ptr, fat_offset_t offset, char * block, long long bytes){
    do { if((ptr->_fd == (-1))) { printf("open device first\n"); return -1; } } while (0);
    long long ret = lseek(ptr->_fd, offset, 0);
    do { if((ret < 0)) { printf("lseek file failed! err:%s\n", strerror((*__errno_location ()))); return ret; } } while (0);
    ret = read(ptr->_fd, block, bytes);
    do { if((ret < 0)) { printf("read file failed! err:%s\n", strerror((*__errno_location ()))); return ret; } } while (0);
    return ret;
}

canonical_original_code:
long long fat_dev_read(struct fat_dev_s *ptr, long long offset, char *block, long long bytes){
    do { if((ptr->_fd == (-1))) { printf("open device first\n"); return -1; } } while (0);
    long long ret = lseek(ptr->_fd, offset, 0);
    do { if((ret < 0)) { printf("lseek file failed! err:%s\n", strerror((*__errno_location ()))); return ret; } } while (0);
    ret = read(ptr->_fd, block, bytes);
    do { if((ret < 0)) { printf("read file failed! err:%s\n", strerror((*__errno_location ()))); return ret; } } while (0);
    return ret;
}


decompiled_code:
_BOOL8 __fastcall fat_dev_is_open(__int64 a1)
{
return *(_DWORD *)(a1 + 12) == 1;
}

canonical_decompiled_code:
_BOOL8 __fastcall func3(__int64 a1)
{
return *(_DWORD *)(a1 + 12) == 1;
}

original_code:
int fat_dev_is_open(fat_dev_t * ptr){
    return ptr->_is_connected == 1;
}

canonical_original_code:
int fat_dev_is_open(struct fat_dev_s *ptr){
    return ptr->_is_connected == 1;
}


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

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

original_code:
const char * fat_dev_fname(fat_dev_t * ptr){
    return ptr->_fname;
}

canonical_original_code:
char *fat_dev_fname(struct fat_dev_s *ptr){
    return ptr->_fname;
}

return_type: char *


decompiled_code:
int __fastcall fat_dev_print(__int64 a1)
{
return printf(
"fd:%d, is_connected:%d, name:%s\n",
*(unsigned int *)(a1 + 8),
*(unsigned int *)(a1 + 12),
*(const char **)a1);
}

canonical_decompiled_code:
int __fastcall func5(__int64 a1)
{
return printf(
"fd:%d, is_connected:%d, name:%s\n",
*(unsigned int *)(a1 + 8),
*(unsigned int *)(a1 + 12),
*(const char **)a1);
}

original_code:
void fat_dev_print(fat_dev_t * ptr){
    printf("fd:%d, is_connected:%d, name:%s\n", ptr->_fd, ptr->_is_connected, ptr->_fname);
}

canonical_original_code:
void fat_dev_print(struct fat_dev_s *ptr){
    printf("fd:%d, is_connected:%d, name:%s\n", ptr->_fd, ptr->_is_connected, ptr->_fname);
}


decompiled_code:
__int64 current_uid()
{
return 100LL;
}

canonical_decompiled_code:
__int64 func0()
{
return 100LL;
}

original_code:
static inline kuid_t current_uid()
{
    return (kuid_t){ 100 };
}

canonical_original_code:
static inline struct kuid_t current_uid()
{
    return (struct kuid_t){ 100 };
}

return_type: struct kuid_t { unsigned int val; }


decompiled_code:
__int64 current_gid()
{
return 100LL;
}

canonical_decompiled_code:
__int64 func1()
{
return 100LL;
}

original_code:
static inline kgid_t current_gid()
{
    return (kgid_t){ 100 };
}

canonical_original_code:
static inline struct kgid_t current_gid()
{
    return (struct kgid_t){ 100 };
}

return_type: struct kgid_t { unsigned int val; }


decompiled_code:
__int64 fat_exit()
{
return unregister_filesystem(&fat_fs_type);
}

canonical_decompiled_code:
__int64 func11()
{
return unregister_filesystem(&fat_fs_type);
}

original_code:
static void fat_exit(){
 unregister_filesystem(&fat_fs_type);
}


decompiled_code:
// attributes: thunk
__int64 __fastcall atomic64_cmpxchg(__int64 *a1)
{
return arch_atomic64_cmpxchg(a1);
}

canonical_decompiled_code:
__int64 __fastcall func16(__int64 *a1)
{
return func15(a1);
}

original_code:
static inline s64
atomic64_cmpxchg(atomic64_t *v, s64 old, s64 new)
{
    return arch_atomic64_cmpxchg(v, old, new);
}

canonical_original_code:
static inline long long atomic64_cmpxchg(struct atomic64_t *v, long long old, long long new)
{
    return arch_atomic64_cmpxchg(v, old, new);
}

variable_types: struct atomic64_t { long long counter; } *

variable_types:
old
long long

variable_types:
new
long long


decompiled_code:
void ListTest_use()
{
;
}

canonical_decompiled_code:
void func26()
{
;
}

original_code:
void ListTest_use(void){
    struct list_head head = { &(head), &(head) };
}

canonical_original_code:
void ListTest_use(){
    struct list_head head = { &(head), &(head) };
}

variable_types: struct list_head { struct list_head *next; }


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

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

original_code:
int main(int argc, char * argv[]){
    FileSystemTypeTest_use();
    ListTest_use();
}

canonical_original_code:
int main(int argc, char *argv[]){
    FileSystemTypeTest_use();
    ListTest_use();
}


decompiled_code:
void __fastcall mcfs_dev_destroy(void *ptr)
{
int *v1; // rax
char *v2; // rax

if ( ptr )
{
if ( close(*((_DWORD *)ptr + 2)) )
{
v1 = _errno_location();
v2 = strerror(*v1);
printf("close file [%s] error, error:%s\n", *(const char **)ptr, v2);
}
free(ptr);
}
}

original_code:
void mcfs_dev_destroy(mcfs_dev_t * ptr){
    if(ptr){
        if(0 != close(ptr->_fd)){
            printf("close file [%s] error, error:%s\n", ptr->_fname, strerror((*__errno_location ())));
        }
        ptr->_is_connected = 0;
        ptr->_fname = ((void *)0);
        ptr->_fd = (-1);
        free(ptr);
    }
}

canonical_original_code:
void mcfs_dev_destroy(struct mcfs_dev *ptr){
    if(ptr){
        if(0 != close(ptr->_fd)){
            printf("close file [%s] error, error:%s\n", ptr->_fname, strerror((*__errno_location ())));
        }
        ptr->_is_connected = 0;
        ptr->_fname = ((void *)0);
        ptr->_fd = (-1);
        free(ptr);
    }
}

variable_types: struct mcfs_dev { char *_fname; int _fd; int _is_connected; } *


decompiled_code:
__off_t __fastcall mcfs_dev_write(__int64 a1, __off_t a2, const void *a3, size_t a4)
{
int v5; // edi
__off_t v8; // r12
ssize_t v9; // r12
__off_t result; // rax
int *v11; // rax
char *v12; // rax
int *v13; // rax
char *v14; // rax

v5 = *(_DWORD *)(a1 + 8);
if ( v5 == -1 )
{
v9 = -1LL;
puts("open device first");
return v9;
}
v8 = lseek(v5, a2, 0);
if ( v8 < 0 )
{
v11 = _errno_location();
v12 = strerror(*v11);
printf("lseek file failed! err:%s\n", v12);
result = v8;
}
else
{
v9 = write(*(_DWORD *)(a1 + 8), a3, a4);
if ( v9 >= 0 )
return v9;
v13 = _errno_location();
v14 = strerror(*v13);
printf("write file failed! err:%s\n", v14);
result = v9;
}
return result;
}

original_code:
long long mcfs_dev_write(mcfs_dev_t * ptr, loff_t offset,const char * block, long long bytes){
    loff_t ret;
    do { if((ptr->_fd == (-1))) { printf("open device first\n"); return -1; } } while (0);
    ret = lseek(ptr->_fd, offset, 0);
    do { if((ret < 0)) { printf("lseek file failed! err:%s\n", strerror((*__errno_location ()))); return ret; } } while (0);
    ret = write(ptr->_fd, block, bytes);
    do { if((ret < 0)) { printf("write file failed! err:%s\n", strerror((*__errno_location ()))); return ret; } } while (0);
    return ret;
}

canonical_original_code:
long long mcfs_dev_write(struct mcfs_dev *ptr, long offset, char *block, long long bytes){
    long ret;
    do { if((ptr->_fd == (-1))) { printf("open device first\n"); return -1; } } while (0);
    ret = lseek(ptr->_fd, offset, 0);
    do { if((ret < 0)) { printf("lseek file failed! err:%s\n", strerror((*__errno_location ()))); return ret; } } while (0);
    ret = write(ptr->_fd, block, bytes);
    do { if((ret < 0)) { printf("write file failed! err:%s\n", strerror((*__errno_location ()))); return ret; } } while (0);
    return ret;
}

variable_types: offset long

variable_types: ret long

user_defined_types: struct mcfs_dev { char *_fname; int _fd; int _is_connected; }