addEvent

decompiled_code:
__int64 __fastcall addEvent(__int64 a1, __int64 a2)
{
size_t v2; // rbx
_QWORD *v3; // rax
_QWORD *v4; // r13
void *v5; // r14
__int64 result; // rax

v2 = 8LL * (*(_DWORD *)(a1 + 96) + 1);
v3 = malloc(v2);
v4 = v3;
v5 = *(void **)(a1 + 88);
if ( v5 )
{
memcpy(v3, *(const void **)(a1 + 88), v2 - 8);
free(v5);
}
*(_QWORD *)(a1 + 88) = v4;
LODWORD(result) = *(_DWORD *)(a1 + 96);
*(_DWORD *)(a1 + 96) = result + 1;
result = (int)result;
v4[(int)result] = a2;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int64 a2)
{
size_t v2; // rbx
_QWORD *v3; // rax
_QWORD *v4; // r13
void *v5; // r14
__int64 result; // rax

v2 = 8LL * (*(_DWORD *)(a1 + 96) + 1);
v3 = malloc(v2);
v4 = v3;
v5 = *(void **)(a1 + 88);
if ( v5 )
{
memcpy(v3, *(const void **)(a1 + 88), v2 - 8);
free(v5);
}
*(_QWORD *)(a1 + 88) = v4;
LODWORD(result) = *(_DWORD *)(a1 + 96);
*(_DWORD *)(a1 + 96) = result + 1;
result = (int)result;
v4[(int)result] = a2;
return result;
}

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

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

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

variable_types:
event
struct laser_event *

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


repo: TIHan/TFile

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

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

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

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

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

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

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

variable_types: type int

variable_types: ret int

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

return_type: int

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:
int __fastcall mtx_destroy(pthread_mutex_t *a1)
{
return pthread_mutex_destroy(a1);
}

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

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

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

return_type: void

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


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

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

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

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


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

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

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

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

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


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

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

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

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


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

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

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

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


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

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

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

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

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

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


decompiled_code:
int __fastcall cnd_destroy(pthread_cond_t *a1)
{
return pthread_cond_destroy(a1);
}

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

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

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

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


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

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

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

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


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

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

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

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


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

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

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

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


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

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

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

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

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

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

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


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

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

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

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

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

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

variable_types:
thr
unsigned long *

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

variable_types:
arg
void *

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


decompiled_code:
pthread_t thrd_current()
{
return pthread_self();
}

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

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

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

return_type: unsigned long


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

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

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

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

variable_types:
thr
unsigned long


decompiled_code:
int __fastcall thrd_equal(pthread_t a1, pthread_t a2)
{
return pthread_equal(a1, a2);
}

canonical_decompiled_code:
int __fastcall func15(pthread_t a1, pthread_t a2)
{
return pthread_equal(a1, a2);
}

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

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


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

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

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

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

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

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

variable_types: res int

variable_types:
pres
void *


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

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

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

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

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

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

variable_types:
res
int *

variable_types: ires int


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

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

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

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

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

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

variable_types:
remaining
struct timespec *

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

variable_types: delta long


decompiled_code:
int thrd_yield()
{
return sched_yield();
}

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

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

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


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

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

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

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

variable_types:
key
unsigned int *

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


decompiled_code:
int __fastcall tss_delete(pthread_key_t a1)
{
return pthread_key_delete(a1);
}

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

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

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

variable_types:
key
unsigned int


decompiled_code:
void *__fastcall tss_get(pthread_key_t a1)
{
return pthread_getspecific(a1);
}

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

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

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

return_type: void *


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

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

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

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

variable_types:
val
void *


launchStats

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

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

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

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

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

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

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

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


launchStatsFile

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

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

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

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

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

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

variable_types:
log
char *

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

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


launchImport

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

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

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

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

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

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


createDataBase

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

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

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

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

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


dropDataBase

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

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

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


displayHelp

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

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

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


main

canonical_name: main

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

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

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

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

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

variable_types: argc int

variable_types:
argv
char *[]

variable_types: option int

variable_types: opt char


printDataList

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

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


convertUDateToSec

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

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

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

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


compareUDateCell

decompiled_code:
__int64 __fastcall compareUDateCell(_DWORD *a1, _DWORD *a2)
{
int v2; // edx
int v3; // eax
__int64 result; // rax
int v5; // edx
int v6; // eax
int v7; // edx
int v8; // eax
int v9; // ecx
int v10; // edx

v2 = a1[6];
v3 = a2[6];
if ( v2 != v3 )
return 2 * (unsigned int)(v2 > v3) - 1;
v5 = a1[7];
v6 = a2[7];
if ( v5 != v6 )
return 2 * (unsigned int)(v5 > v6) - 1;
v7 = a1[8];
v8 = a2[8];
if ( v7 != v8 )
return 2 * (unsigned int)(v7 > v8) - 1;
v9 = a1[9];
v10 = a2[9];
result = 0LL;
if ( v9 != v10 )
result = 2 * (unsigned int)(v9 > v10) - 1;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(_DWORD *a1, _DWORD *a2)
{
int v2; // edx
int v3; // eax
__int64 result; // rax
int v5; // edx
int v6; // eax
int v7; // edx
int v8; // eax
int v9; // ecx
int v10; // edx

v2 = a1[6];
v3 = a2[6];
if ( v2 != v3 )
return 2 * (unsigned int)(v2 > v3) - 1;
v5 = a1[7];
v6 = a2[7];
if ( v5 != v6 )
return 2 * (unsigned int)(v5 > v6) - 1;
v7 = a1[8];
v8 = a2[8];
if ( v7 != v8 )
return 2 * (unsigned int)(v7 > v8) - 1;
v9 = a1[9];
v10 = a2[9];
result = 0LL;
if ( v9 != v10 )
result = 2 * (unsigned int)(v9 > v10) - 1;
return result;
}

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

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


freeDataList

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

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

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

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

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

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


calcNbDropForCounter

decompiled_code:
__int64 __fastcall calcNbDropForCounter(_QWORD *a1, const char *a2, const char *a3, int a4)
{
_QWORD *v4; // rbx
__int64 v5; // rbp
__int64 v6; // r12
__int64 v7; // r15
__int64 v8; // r13
__int64 v9; // r14

if ( !a1 )
return 0LL;
v4 = a1;
v5 = 0LL;
v6 = 0LL;
v7 = 0LL;
v8 = a4;
do
{
if ( v4[1] && *v4 )
{
if ( !v5 )
{
++v6;
v5 = *v4;
}
if ( (unsigned int)compareUDateCell(*v4, v5) == -1 )
{
v5 = *v4;
++v6;
}
else
{
v5 = *v4;
}
if ( v8 == v6 )
{
v9 = v4[1];
if ( !strcmp((const char *)(v9 + 255), a3) && !strcmp((const char *)v9, a2) )
v7 = *(_QWORD *)(v9 + 512);
}
}
v4 = (_QWORD *)v4[2];
}
while ( v4 );
return v7;
}

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

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

variable_types:
counterName
char *

variable_types:
threadName
char *

variable_types: run int

variable_types: count long

variable_types: numRun long

return_type: long


clacNbRun

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

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

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

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

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

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

variable_types: count int


nbSecondeInRun

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

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


calcNbThread

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

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

variable_types:
threadNames
char ***

variable_types: i int

variable_types: test int


calcNbCounter

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

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

variable_types:
counterName
char ***


stats

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

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

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

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

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

variable_types: j int

variable_types: nbCounter int

variable_types: nbThread int

variable_types: nbRun int

variable_types:
counterNames
char **

variable_types:
threadNames
char **


parseDateLine

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

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

variable_types:
data
char *

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


parseDataLine

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

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

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

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


printDate

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

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


insertToList

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

v3 = (char **)malloc(0x10uLL);
*v3 = (char *)malloc(0xFFuLL);
v4 = (char *)malloc(0xFFuLL);
v3[1] = v4;
strcpy(*v3, "capture.kernel_packets");
strcpy(v4, "capture.kernel_drops");
for ( i = 0LL; i != 2; ++i )
{
LODWORD(v6) = strcmp(v3[i], (const char *)a2);
if ( !(_DWORD)v6 )
{
newDataList(*(_QWORD *)a1 + 16LL);
v7 = *(_QWORD *)(*(_QWORD *)a1 + 16LL);
*(_QWORD *)a1 = v7;
newDataLine(v7 + 8);
strcpy(*(char **)(*(_QWORD *)a1 + 8LL), (const char *)a2);
strcpy((char *)(*(_QWORD *)(*(_QWORD *)a1 + 8LL) + 255LL), (const char *)(a2 + 255));
v6 = *(_QWORD *)(*(_QWORD *)a1 + 8LL);
*(_QWORD *)(v6 + 512) = *(_QWORD *)(a2 + 512);
}
}
return v6;
}

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

v3 = (char **)malloc(0x10uLL);
*v3 = (char *)malloc(0xFFuLL);
v4 = (char *)malloc(0xFFuLL);
v3[1] = v4;
strcpy(*v3, "capture.kernel_packets");
strcpy(v4, "capture.kernel_drops");
for ( i = 0LL; i != 2; ++i )
{
LODWORD(v6) = strcmp(v3[i], (const char *)a2);
if ( !(_DWORD)v6 )
{
newDataList(*(_QWORD *)a1 + 16LL);
v7 = *(_QWORD *)(*(_QWORD *)a1 + 16LL);
*(_QWORD *)a1 = v7;
newDataLine(v7 + 8);
strcpy(*(char **)(*(_QWORD *)a1 + 8LL), (const char *)a2);
strcpy((char *)(*(_QWORD *)(*(_QWORD *)a1 + 8LL) + 255LL), (const char *)(a2 + 255));
v6 = *(_QWORD *)(*(_QWORD *)a1 + 8LL);
*(_QWORD *)(v6 + 512) = *(_QWORD *)(a2 + 512);
}
}
return v6;
}

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

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

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

variable_types:
actLine
struct _dataLine *

variable_types:
toInsert
char **


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

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

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


decompiled_code:
void display_hint()
{
if ( !has_asked_for_help )
{
puts("\nHint: try the command \"help\"");
printf("yolo >> ");
fflush(_bss_start);
register_timeout(3000, (__int64)display_hint, 0LL);
}
}

canonical_decompiled_code:
void func9()
{
if ( !has_asked_for_help )
{
puts("\nHint: try the command \"help\"");
printf("yolo >> ");
fflush(_bss_start);
func8(3000, (__int64)display_hint, 0LL);
}
}

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


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

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

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

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

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

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

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

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


decompiled_code:
int handle_keyboard()
{
const char **v0; // rbx
__int64 v2[3]; // [rsp+0h] [rbp-68h] BYREF
char v3[8]; // [rsp+18h] [rbp-50h] BYREF
char s[8]; // [rsp+20h] [rbp-48h] BYREF
__int64 v5; // [rsp+28h] [rbp-40h]
__int64 v6; // [rsp+30h] [rbp-38h]
__int64 v7; // [rsp+38h] [rbp-30h]
__int64 v8; // [rsp+40h] [rbp-28h]

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

canonical_decompiled_code:
int func11()
{
const char **v0; // rbx
__int64 v2[3]; // [rsp+0h] [rbp-68h] BYREF
char v3[8]; // [rsp+18h] [rbp-50h] BYREF
char s[8]; // [rsp+20h] [rbp-48h] BYREF
__int64 v5; // [rsp+28h] [rbp-40h]
__int64 v6; // [rsp+30h] [rbp-38h]
__int64 v7; // [rsp+38h] [rbp-30h]
__int64 v8; // [rsp+40h] [rbp-28h]

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

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

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

variable_types:
command
char [40]

variable_types: i int


main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
struct timeval v3; // [rsp+0h] [rbp-118h] BYREF
fd_set readfds; // [rsp+10h] [rbp-108h] BYREF
__m128i v5[8]; // [rsp+90h] [rbp-88h] BYREF

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

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
struct timeval v3; // [rsp+0h] [rbp-118h] BYREF
fd_set readfds; // [rsp+10h] [rbp-108h] BYREF
__m128i v5[8]; // [rsp+90h] [rbp-88h] BYREF

printf("yolo >> ");
fflush(_bss_start);
func14(free_timeout, argv);
func8(3000, (__int64)display_hint, 0LL);
memset(v5, 0, sizeof(v5));
v5[0].m128i_i64[0] |= 1uLL;
while ( 1 )
{
*(__m128i *)readfds.fds_bits = _mm_loadu_si128(v5);
*(__m128i *)&readfds.fds_bits[2] = _mm_loadu_si128(&v5[1]);
*(__m128i *)&readfds.fds_bits[4] = _mm_loadu_si128(&v5[2]);
*(__m128i *)&readfds.fds_bits[6] = _mm_loadu_si128(&v5[3]);
*(__m128i *)&readfds.fds_bits[8] = _mm_loadu_si128(&v5[4]);
*(__m128i *)&readfds.fds_bits[10] = _mm_loadu_si128(&v5[5]);
*(__m128i *)&readfds.fds_bits[12] = _mm_loadu_si128(&v5[6]);
*(__m128i *)&readfds.fds_bits[14] = _mm_loadu_si128(&v5[7]);
v3.tv_sec = 0LL;
v3.tv_usec = 100000LL;
if ( select(1, &readfds, 0LL, 0LL, &v3) < 0 )
break;
func10();
if ( (readfds.fds_bits[0] & 1) != 0 )
func11();
}
__assert_fail("retval >= 0", "timeout.c", 0x8Fu, "main");
}

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

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

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

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

variable_types: retval int


repo: TacOS-team/ted

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

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

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

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

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

return_type: unsigned int


decompiled_code:
__int64 __fastcall print_line(__int64 a1, int a2, unsigned int a3)
{
int v4; // ebx
_BYTE *v5; // rbx
int i; // er13
unsigned int v7; // ebp

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

canonical_decompiled_code:
__int64 __fastcall func15(__int64 a1, int a2, unsigned int a3)
{
int v4; // ebx
_BYTE *v5; // rbx
int i; // er13
unsigned int v7; // ebp

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

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

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

variable_types: j int

variable_types:
aux
char *

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


decompiled_code:
int tty_raw()
{
struct termios v1; // [rsp+0h] [rbp-48h] BYREF

tcgetattr(0, &v1);
v1.c_lflag &= 0xFFFFFFF5;
return tcsetattr(0, 0, &v1);
}

canonical_decompiled_code:
int func16()
{
struct termios v1; // [rsp+0h] [rbp-48h] BYREF

tcgetattr(0, &v1);
v1.c_lflag &= 0xFFFFFFF5;
return tcsetattr(0, 0, &v1);
}

original_code:
void tty_raw() {
    struct termios newt;
    tcgetattr(0, &newt);
    newt.c_lflag &= ~(0000002 | 0000010);
    tcsetattr(0, 0, &newt);
}

variable_types: struct termios { unsigned int c_iflag; unsigned int c_oflag; unsigned int c_cflag; unsigned int c_lflag; unsigned char c_line; unsigned char c_cc[32]; unsigned int c_ispeed; unsigned int c_ospeed; }


decompiled_code:
int tty_update_winsize()
{
return ioctl(1, 0x5413uLL, &ws);
}

canonical_decompiled_code:
int func17()
{
return ioctl(1, 0x5413uLL, &ws);
}

original_code:
void tty_update_winsize() {
 ioctl(1, 0x5413, &ws);
}


decompiled_code:
__int64 tty_col()
{
return (unsigned __int16)word_4040C2;
}

canonical_decompiled_code:
__int64 func18()
{
return (unsigned __int16)word_4040C2;
}

original_code:
unsigned int tty_col() {
 return ws.ws_col;
}


decompiled_code:
__int64 tty_row()
{
return (unsigned __int16)ws;
}

canonical_decompiled_code:
__int64 func19()
{
return (unsigned __int16)ws;
}

original_code:
unsigned int tty_row() {
 return ws.ws_row;
}


decompiled_code:
int clear_screen()
{
printf("\x1B[2J");
return fflush(stdout);
}

canonical_decompiled_code:
int func20()
{
printf("\x1B[2J");
return fflush(stdout);
}

original_code:
void clear_screen() {
    printf("\033[2J");
    fflush(stdout);
}


clientServerInteraction

repo: TarasDumin/ServerHttp

decompiled_code:
__int64 __fastcall clientServerInteraction(unsigned int a1)
{
int v2; // eax
unsigned int v3; // ebx
int v5; // er14
_QWORD *v6; // rax
void *v7; // rdi
__int64 v8; // rbp
__int64 v9; // r13
char v10[256]; // [rsp+0h] [rbp-2928h] BYREF
__int64 v11[2]; // [rsp+100h] [rbp-2828h] BYREF
char s[10224]; // [rsp+110h] [rbp-2818h] BYREF

v11[0] = 0LL;
v11[1] = 0LL;
memset(s, 0, sizeof(s));
sprintf(v10, "start | Deskription: %d\n", a1);
writeLog("Server.c", "clientServerInteraction", 21LL, v10);
while ( 1 )
{
v8 = createRequestObject();
v9 = getTimeS();
while ( 1 )
{
v2 = readWithTimeOut(a1, v11, 10240LL, *(unsigned int *)(v8 + 16));
v3 = v2;
if ( v2 <= 0 )
break;
if ( *(_DWORD *)(v8 + 56) != 200 || !(unsigned int)parseParameters(v8, v11, (unsigned int)v2) || v3 != 10239 )
goto LABEL_9;
}
if ( v2 == -1 || v2 != -2 )
LABEL_9:
(*(void (__fastcall **)(__int64, _QWORD))(v8 + 72))(v8, a1);
if ( (unsigned int)isUseInLog("HTTPStatus:") )
{
v5 = *(_DWORD *)(v8 + 56);
*(_DWORD *)(getLogeW3CLog() + 88) = v5;
}
if ( (unsigned int)isUseInLog("Date:") )
{
v6 = (_QWORD *)getLogeW3CLog();
if ( !(unsigned int)isEmptyLogDate(*v6) )
{
v7 = *(void **)getLogeW3CLog();
free(v7);
}
*(_QWORD *)getLogeW3CLog() = v9;
}
deleteRequest(v8);
if ( v3 == -2 )
break;
writeInLogFile();
clearW3CLog();
if ( !*(_DWORD *)(v8 + 12) )
goto LABEL_15;
}
clearW3CLog();
LABEL_15:
close(a1);
sprintf(v10, "End | Deskription: %d | result: %d\n", a1, v3);
writeLog("Server.c", "clientServerInteraction", 78LL, v10);
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned int a1)
{
int v2; // eax
unsigned int v3; // ebx
int v5; // er14
_QWORD *v6; // rax
void *v7; // rdi
__int64 v8; // rbp
__int64 v9; // r13
char v10[256]; // [rsp+0h] [rbp-2928h] BYREF
__int64 v11[2]; // [rsp+100h] [rbp-2828h] BYREF
char s[10224]; // [rsp+110h] [rbp-2818h] BYREF

v11[0] = 0LL;
v11[1] = 0LL;
memset(s, 0, sizeof(s));
sprintf(v10, "start | Deskription: %d\n", a1);
writeLog("Server.c", "clientServerInteraction", 21LL, v10);
while ( 1 )
{
v8 = createRequestObject();
v9 = getTimeS();
while ( 1 )
{
v2 = readWithTimeOut(a1, v11, 10240LL, *(unsigned int *)(v8 + 16));
v3 = v2;
if ( v2 <= 0 )
break;
if ( *(_DWORD *)(v8 + 56) != 200 || !(unsigned int)parseParameters(v8, v11, (unsigned int)v2) || v3 != 10239 )
goto LABEL_9;
}
if ( v2 == -1 || v2 != -2 )
LABEL_9:
(*(void (__fastcall **)(__int64, _QWORD))(v8 + 72))(v8, a1);
if ( (unsigned int)isUseInLog("HTTPStatus:") )
{
v5 = *(_DWORD *)(v8 + 56);
*(_DWORD *)(getLogeW3CLog() + 88) = v5;
}
if ( (unsigned int)isUseInLog("Date:") )
{
v6 = (_QWORD *)getLogeW3CLog();
if ( !(unsigned int)isEmptyLogDate(*v6) )
{
v7 = *(void **)getLogeW3CLog();
free(v7);
}
*(_QWORD *)getLogeW3CLog() = v9;
}
deleteRequest(v8);
if ( v3 == -2 )
break;
writeInLogFile();
clearW3CLog();
if ( !*(_DWORD *)(v8 + 12) )
goto LABEL_15;
}
clearW3CLog();
LABEL_15:
close(a1);
sprintf(v10, "End | Deskription: %d | result: %d\n", a1, v3);
writeLog("Server.c", "clientServerInteraction", 78LL, v10);
return v3;
}

original_code:
int clientServerInteraction(int deskription)
{
    HTTP_REQUEST *currentReq;
    char message[(10240)] = {0};
    char* time = ((void *)0);
    int result;
    { char buffer[256]; sprintf(buffer, "start | Deskription: %d\n", deskription); writeLog("Server.c", __func__, 21, buffer); };
    do
    {
        currentReq = createRequestObject();
        time = getTimeS();
        do
        {
            result = readWithTimeOut(deskription, message, (10240), currentReq->timeOfKeapAlive);
            if(result > 0)
            {
                if((HTTP_200_OK != currentReq->status) ||
                   (!parseParameters(currentReq, message, result)))
                {
                    break;
                }
            }
            else if(result == (-1))
            {
                break;
            }
        }while(result == (10240) - 1 &&
               result != (-2));
        if(result != (-2))
        {
            currentReq->MethodHTTP(currentReq, deskription);
        }
        if(isUseInLog("HTTPStatus:"))
        {
            getLogeW3CLog()->HTTPStatus = currentReq->status;
        }
        if(isUseInLog("Date:"))
        {
            if(!isEmptyLogDate(getLogeW3CLog()->Date))
            {
                free(getLogeW3CLog()->Date);
            }
            getLogeW3CLog()->Date = time;
        }
        deleteRequest(currentReq);
        if(result != (-2))
        {
            writeInLogFile();
        }
        clearW3CLog();
    }while(result != (-2) &&
           currentReq->isKeapAliveUsing);
    close(deskription);
    { char buffer[256]; sprintf(buffer, "End | Deskription: %d | result: %d\n", deskription, result); writeLog("Server.c", __func__, 78, buffer); };
    return result;
}

canonical_original_code:
int clientServerInteraction(int deskription)
{
    struct _REQUEST *currentReq;
    char message[-1] = {0};
    char *time = ((void *)0);
    int result;
    { char buffer[256]; sprintf(buffer, "start | Deskription: %d\n", deskription); writeLog("Server.c", __func__, 21, buffer); };
    do
    {
        currentReq = createRequestObject();
        time = getTimeS();
        do
        {
            result = readWithTimeOut(deskription, message, (10240), currentReq->timeOfKeapAlive);
            if(result > 0)
            {
                if((HTTP_200_OK != currentReq->status) ||
                   (!parseParameters(currentReq, message, result)))
                {
                    break;
                }
            }
            else if(result == (-1))
            {
                break;
            }
        }while(result == (10240) - 1 &&
               result != (-2));
        if(result != (-2))
        {
            currentReq->MethodHTTP(currentReq, deskription);
        }
        if(isUseInLog("HTTPStatus:"))
        {
            getLogeW3CLog()->HTTPStatus = currentReq->status;
        }
        if(isUseInLog("Date:"))
        {
            if(!isEmptyLogDate(getLogeW3CLog()->Date))
            {
                free(getLogeW3CLog()->Date);
            }
            getLogeW3CLog()->Date = time;
        }
        deleteRequest(currentReq);
        if(result != (-2))
        {
            writeInLogFile();
        }
        clearW3CLog();
    }while(result != (-2) &&
           currentReq->isKeapAliveUsing);
    close(deskription);
    { char buffer[256]; sprintf(buffer, "End | Deskription: %d | result: %d\n", deskription, result); writeLog("Server.c", __func__, 78, buffer); };
    return result;
}

variable_types: deskription int

variable_types: struct _REQUEST { enum _HTTP_METHOD_ { HTTP_GET=0, HTTP_HEAD=1, HTTP_POST=2, HTTP_PUT=3, HTTP_DELETE=4, HTTP_OPTIONS=5, HTTP_TRACE=6, HTTP_CONNECT=7, HTTP_PATCH=8, HTTP_EXTENSION_METHOD=9 } method; enum VERSION { HTTP_1_0=0, HTTP_1_1=1, UNDEFINED_HTTP=2 } version; enum _YES_NO_QUESTION_ { NO_Q=0, YES_Q=1 } isChunkUsing; enum _YES_NO_QUESTION_ { NO_Q=0, YES_Q=1 } isKeapAliveUsing; int timeOfKeapAlive; int lenResponse; int lenURI; int lenBodyResponse; char *header; char *URI; char *body; enum STATUS { HTTP_100_CONTINUE=100, HTTP_101_SWITCHING=101, HTTP_102_PROCESSING=102, HTTP_200_OK=200, HTTP_201_Created=201, HTTP_202_Accepted=202, HTTP_203_NON_AUTHORITATIVE_INFORMATION=203, HTTP_204_NO_CONTENT=204, HTTP_206_PARTUAL_CONTENT=206, HTTP_207_MULTY_STATUS=207, HTTP_208_ALREADY_REPORTED=208, HTTP_300_MULTIPLE_CHOICES=300, HTTP_301_MOVED_PERMANENTLY=301, HTTP_302_FOUND=302, HTTP_303_SEE_OTHER=303, HTTP_304_NOT_MODIFFED=304, HTTP_305_USE_PROXY=305, HTTP_307_TEMPORARY_REDIRECT=306, HTTP_400_BAD_REQUEST=400, HTTP_401_UNAUTHORIZED=401, HTTP_402_PAYMENT_REQUIRED=402, HTTP_403_FORBIDDEN=403, HTTP_404_NOT_FOUND=404, HTTP_405_METHOD_NOT_ALLOWED=405, HTTP_406_NOT_ACCEPTABLE=406, HTTP_407_PROXY_AUTHENTICATION_REQUIRED=407, HTTP_408_REQUEST_TIMEOUT=408, HTTP_409_CONICT=409, HTTP_410_GONE=410, HTTP_411_LENGTH_REQUIRED=411, HTTP_412_PRECONDITION_FAILED=412, HTTP_413_REQUEST_ENTITY_TOO_LARGE=413, HTTP_414_REQUEST_URI_TOO_LONG=414, HTTP_415_UNSUPPORTED_MEDIA_TYPE=415, HTTP_416_REQUESTED_RANGE_NOT_SATISFIABLE=416, HTTP_417_EXPECTATION_FAILED=417, HTTP_418_IM_TEAPOT=418, HTTP_420_ENHANCE_YOUR_CALM=420, HTTP_422_UNPROCESSABLE_ENTITY=422, HTTP_423_LOCKED=423, HTTP_424_FAILED_DEPENDENCY=424, HTTP_429_TOO_MANY_REQUESTS=429, HTTP_431_REQUEST_HEADER_FIELDS_TOO_LARGE=431, HTTP_444_NO_RESPONSE=444, HTTP_449_RETRY_WITH=449, HTTP_450_BLOCKED_BY_WINDOWS=450, HTTP_451_UNAVAILABLE_FOR_LEGAL_REASONS=451, HTTP_500_INTERNAL_SERVER_ERROR=500, HTTP_501_NOT_IMPLEMENTED=501, HTTP_502_BAD_GATEWAY=502, HTTP_503_SERVICE_UNAVAILABLE=503, HTTP_504_GATEWAY_TIMEOUT=504, HTTP_505_HTTP_VERSION_NOT_SUPPORTED=505, HTTP_507_INSUFFCIENT_STORAGE=507, HTTP_508_LOOP_DETECTED=508, HTTP_509_BANDWIDTH_LIMIT_EXCEEDED=509 } status; void (*getMethodHTTP)(struct _REQUEST *, char *); void (*MethodHTTP)(struct _REQUEST *, int); } *

variable_types:
message
char [-1]

variable_types:
time
char *

variable_types: result int

variable_types:
buffer
char [256]

user_defined_types: struct _REQUEST { enum _HTTP_METHOD_ method; enum VERSION version; enum _YES_NO_QUESTION_ isChunkUsing; enum _YES_NO_QUESTION_ isKeapAliveUsing; int timeOfKeapAlive; int lenResponse; int lenURI; int lenBodyResponse; char *header; char *URI; char *body; enum STATUS status; void (*getMethodHTTP)(struct _REQUEST *, char *); void (*MethodHTTP)(struct _REQUEST *, int); }


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // ebp
unsigned int v4; // eax
unsigned int v5; // ebx
__pid_t v6; // eax
char v8[280]; // [rsp+0h] [rbp-118h] BYREF

initW3CLog(argc, argv, envp);
startDebug();
puts("Server is working now");
sprintf(v8, "Server is working now %s", (const char *)&unk_3B0);
writeLog("Server.c", "main", 93LL, v8);
v3 = connectToSocket();
if ( v3 == -1 )
exit(1);
while ( 1 )
{
if ( !(unsigned int)checkExit() )
{
LABEL_17:
puts("Server is stopped");
close(v3);
endDebug();
sprintf(v8, "Server is stoped%s", (const char *)&unk_3B0);
writeLog("Server.c", "main", 146LL, v8);
return 0;
}
v4 = acceptWithLogger(v3);
v5 = v4;
if ( v4 != -2 )
break;
LABEL_7:
if ( signal(2, (__sighandler_t)&sig_handler) == (__sighandler_t)-1LL )
{
sprintf(v8, "Error. can't catch SIGINT%s\n", " ");
writeLog("Server.c", "main", 129LL, v8);
}
if ( (int)doesServerHaveToWorkCommand() > 0 || (int)doesServerHaveToWorkConfig() > 0 )
goto LABEL_17;
}
if ( v4 == -1 )
exit(1);
v6 = fork();
if ( v6 < 0 )
{
sprintf(v8, "Error. Fork was failed%s\n", " ");
writeLog("Server.c", "main", 113LL, v8);
exit(1);
}
if ( !v6 )
{
close(v5);
goto LABEL_7;
}
close(v3);
if ( (unsigned int)clientServerInteraction(v5) == -1 )
exit(1);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // ebp
unsigned int v4; // eax
unsigned int v5; // ebx
__pid_t v6; // eax
char v8[280]; // [rsp+0h] [rbp-118h] BYREF

initW3CLog(argc, argv, envp);
startDebug();
puts("Server is working now");
sprintf(v8, "Server is working now %s", (const char *)&unk_3B0);
writeLog("Server.c", "main", 93LL, v8);
v3 = connectToSocket();
if ( v3 == -1 )
exit(1);
while ( 1 )
{
if ( !(unsigned int)checkExit() )
{
LABEL_17:
puts("Server is stopped");
close(v3);
endDebug();
sprintf(v8, "Server is stoped%s", (const char *)&unk_3B0);
writeLog("Server.c", "main", 146LL, v8);
return 0;
}
v4 = acceptWithLogger(v3);
v5 = v4;
if ( v4 != -2 )
break;
LABEL_7:
if ( signal(2, (__sighandler_t)&sig_handler) == (__sighandler_t)-1LL )
{
sprintf(v8, "Error. can't catch SIGINT%s\n", " ");
writeLog("Server.c", "main", 129LL, v8);
}
if ( (int)doesServerHaveToWorkCommand() > 0 || (int)doesServerHaveToWorkConfig() > 0 )
goto LABEL_17;
}
if ( v4 == -1 )
exit(1);
v6 = fork();
if ( v6 < 0 )
{
sprintf(v8, "Error. Fork was failed%s\n", " ");
writeLog("Server.c", "main", 113LL, v8);
exit(1);
}
if ( !v6 )
{
close(v5);
goto LABEL_7;
}
close(v3);
if ( (unsigned int)func0(v5) == -1 )
exit(1);
return 0;
}

original_code:
int main(void)
{
    int deskriptionS = 0, deskriptionC = 0;
    int pid = 0;
    initW3CLog();
    startDebug();
    printf("Server is working now\n");
    { char buffer[256]; sprintf(buffer, "Server is working now %s", ""); writeLog("Server.c", __func__, 93, buffer); };
    deskriptionS = connectToSocket();
    if(deskriptionS == (-1))
    {
        exit(1);
    }
    while(checkExit())
    {
        deskriptionC = acceptWithLogger(deskriptionS);
        if(deskriptionC != (-2))
        {
            if(deskriptionC == (-1))
            {
                exit(1);
            }
            pid = fork();
            if (pid < 0)
            {
                { char buffer[256]; sprintf(buffer, "Error. Fork was failed%s\n", " "); writeLog("Server.c", __func__, 113, buffer); };
         exit(1);
            }
            if(pid != 0)
            {
                close(deskriptionS);
                if(clientServerInteraction(deskriptionC) == (-1))
                {
                    exit(1);
                }
                return (0);
            }
            close(deskriptionC);
        }
        if (signal(2, sig_handler) == ((__sighandler_t) -1))
        {
            { char buffer[256]; sprintf(buffer, "Error. can't catch SIGINT%s\n", " "); writeLog("Server.c", __func__, 129, buffer); };
        }
        if(doesServerHaveToWorkCommand() > 0)
        {
            break;
        }
        if(doesServerHaveToWorkConfig() > 0)
 {
            break;
 }
    }
    if(pid == 0)
    {
        printf("Server is stopped\n");
        close(deskriptionS);
        endDebug();
        { char buffer[256]; sprintf(buffer, "Server is stoped%s", ""); writeLog("Server.c", __func__, 146, buffer); };
    }
    return (0);
}

canonical_original_code:
int main()
{
    int deskriptionS = 0; int deskriptionC = 0;
    int pid = 0;
    initW3CLog();
    startDebug();
    printf("Server is working now\n");
    { char buffer[256]; sprintf(buffer, "Server is working now %s", ""); writeLog("Server.c", __func__, 93, buffer); };
    deskriptionS = connectToSocket();
    if(deskriptionS == (-1))
    {
        exit(1);
    }
    while(checkExit())
    {
        deskriptionC = acceptWithLogger(deskriptionS);
        if(deskriptionC != (-2))
        {
            if(deskriptionC == (-1))
            {
                exit(1);
            }
            pid = fork();
            if (pid < 0)
            {
                { char buffer[256]; sprintf(buffer, "Error. Fork was failed%s\n", " "); writeLog("Server.c", __func__, 113, buffer); };
         exit(1);
            }
            if(pid != 0)
            {
                close(deskriptionS);
                if(clientServerInteraction(deskriptionC) == (-1))
                {
                    exit(1);
                }
                return (0);
            }
            close(deskriptionC);
        }
        if (signal(2, sig_handler) == ((__sighandler_t) -1))
        {
            { char buffer[256]; sprintf(buffer, "Error. can't catch SIGINT%s\n", " "); writeLog("Server.c", __func__, 129, buffer); };
        }
        if(doesServerHaveToWorkCommand() > 0)
        {
            break;
        }
        if(doesServerHaveToWorkConfig() > 0)
 {
            break;
 }
    }
    if(pid == 0)
    {
        printf("Server is stopped\n");
        close(deskriptionS);
        endDebug();
        { char buffer[256]; sprintf(buffer, "Server is stoped%s", ""); writeLog("Server.c", __func__, 146, buffer); };
    }
    return (0);
}

variable_types: deskriptionS int

variable_types: deskriptionC int

variable_types: pid int


checkExistenceSpecifiedAddr

decompiled_code:
__int64 __fastcall checkExistenceSpecifiedAddr(void *s2)
{
unsigned int v2; // er12
struct ifaddrs *v3; // rbx
struct sockaddr *v4; // rsi
sa_family_t v5; // di
char *v6; // rax
char *v7; // rsi
size_t v8; // rax
char v10[256]; // [rsp+0h] [rbp-158h] BYREF
char buf[56]; // [rsp+100h] [rbp-58h] BYREF
struct ifaddrs *ifap; // [rsp+138h] [rbp-20h] BYREF

ifap = 0LL;
sprintf(v10, "Start | IPadd: %p\n", s2);
writeLog("workWithSockets.c", "checkExistenceSpecifiedAddr", 32LL, v10);
if ( getifaddrs(&ifap) )
{
sprintf(v10, "Error. getifaddrs was failed%s\n", (const char *)&unk_8D5);
writeLog("workWithSockets.c", "checkExistenceSpecifiedAddr", 62LL, v10);
v2 = -1;
}
else
{
v2 = 0;
v3 = ifap;
if ( ifap )
{
while ( 1 )
{
v4 = v3->ifa_addr;
v5 = v4->sa_family;
v6 = &v4->sa_data[2];
v7 = &v4->sa_data[6];
if ( v5 == 2 )
v7 = v6;
if ( inet_ntop(v5, v7, buf, 0x2Eu) )
{
v8 = strlen(buf);
if ( !memcmp(buf, s2, v8) )
break;
}
v3 = v3->ifa_next;
if ( !v3 )
goto LABEL_10;
}
v2 = 1;
}
LABEL_10:
freeifaddrs(ifap);
ifap = 0LL;
}
sprintf(v10, "End | result: %d\n", v2);
writeLog("workWithSockets.c", "checkExistenceSpecifiedAddr", 66LL, v10);
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func1(void *s2)
{
unsigned int v2; // er12
struct ifaddrs *v3; // rbx
struct sockaddr *v4; // rsi
sa_family_t v5; // di
char *v6; // rax
char *v7; // rsi
size_t v8; // rax
char v10[256]; // [rsp+0h] [rbp-158h] BYREF
char buf[56]; // [rsp+100h] [rbp-58h] BYREF
struct ifaddrs *ifap; // [rsp+138h] [rbp-20h] BYREF

ifap = 0LL;
sprintf(v10, "Start | IPadd: %p\n", s2);
writeLog("workWithSockets.c", "checkExistenceSpecifiedAddr", 32LL, v10);
if ( getifaddrs(&ifap) )
{
sprintf(v10, "Error. getifaddrs was failed%s\n", (const char *)&unk_8D5);
writeLog("workWithSockets.c", "checkExistenceSpecifiedAddr", 62LL, v10);
v2 = -1;
}
else
{
v2 = 0;
v3 = ifap;
if ( ifap )
{
while ( 1 )
{
v4 = v3->ifa_addr;
v5 = v4->sa_family;
v6 = &v4->sa_data[2];
v7 = &v4->sa_data[6];
if ( v5 == 2 )
v7 = v6;
if ( inet_ntop(v5, v7, buf, 0x2Eu) )
{
v8 = strlen(buf);
if ( !memcmp(buf, s2, v8) )
break;
}
v3 = v3->ifa_next;
if ( !v3 )
goto LABEL_10;
}
v2 = 1;
}
LABEL_10:
freeifaddrs(ifap);
ifap = 0LL;
}
sprintf(v10, "End | result: %d\n", v2);
writeLog("workWithSockets.c", "checkExistenceSpecifiedAddr", 66LL, v10);
return v2;
}

original_code:
int checkExistenceSpecifiedAddr(char *IPadd)
{
    struct ifaddrs *interfaceArray = ((void *)0), *tempIfAddr = ((void *)0);
    void *tempAddrPtr = ((void *)0);
    char addressOutputBuffer[46];
    int result;
    { char buffer[256]; sprintf(buffer, "Start | IPadd: %p\n", IPadd); writeLog("workWithSockets.c", __func__, 32, buffer); };
    if (!getifaddrs(&interfaceArray))
    {
        for(tempIfAddr = interfaceArray; tempIfAddr != ((void *)0); tempIfAddr = tempIfAddr->ifa_next)
        {
            if(tempIfAddr->ifa_addr->sa_family == 2)
            {
                tempAddrPtr = &((struct sockaddr_in *)tempIfAddr->ifa_addr)->sin_addr;
            }
            else
            {
                tempAddrPtr = &((struct sockaddr_in6 *)tempIfAddr->ifa_addr)->sin6_addr;
            }
            if(inet_ntop(tempIfAddr->ifa_addr->sa_family, tempAddrPtr, addressOutputBuffer, sizeof(addressOutputBuffer)))
            {
                if(!memcmp(addressOutputBuffer, IPadd, strlen(addressOutputBuffer)))
                {
                     result = (1);
                     break;
                }
            }
            result = (0);
        }
        freeifaddrs(interfaceArray);
        interfaceArray = ((void *)0);
    }
    else
    {
        { char buffer[256]; sprintf(buffer, "Error.  getifaddrs was failed%s\n", ""); writeLog("workWithSockets.c", __func__, 62, buffer); };
        result = (-1);
    }
    { char buffer[256]; sprintf(buffer, "End | result: %d\n", result); writeLog("workWithSockets.c", __func__, 66, buffer); };
    return result;
}

canonical_original_code:
int checkExistenceSpecifiedAddr(char *IPadd)
{
    struct ifaddrs *interfaceArray = ((void *)0); struct ifaddrs *tempIfAddr = ((void *)0);
    void *tempAddrPtr = ((void *)0);
    char addressOutputBuffer[46];
    int result;
    { char buffer[256]; sprintf(buffer, "Start | IPadd: %p\n", IPadd); writeLog("workWithSockets.c", __func__, 32, buffer); };
    if (!getifaddrs(&interfaceArray))
    {
        for(tempIfAddr = interfaceArray; tempIfAddr != ((void *)0); tempIfAddr = tempIfAddr->ifa_next)
        {
            if(tempIfAddr->ifa_addr->sa_family == 2)
            {
                tempAddrPtr = &((struct sockaddr_in *)tempIfAddr->ifa_addr)->sin_addr;
            }
            else
            {
                tempAddrPtr = &((struct sockaddr_in6 *)tempIfAddr->ifa_addr)->sin6_addr;
            }
            if(inet_ntop(tempIfAddr->ifa_addr->sa_family, tempAddrPtr, addressOutputBuffer, sizeof(addressOutputBuffer)))
            {
                if(!memcmp(addressOutputBuffer, IPadd, strlen(addressOutputBuffer)))
                {
                     result = (1);
                     break;
                }
            }
            result = (0);
        }
        freeifaddrs(interfaceArray);
        interfaceArray = ((void *)0);
    }
    else
    {
        { char buffer[256]; sprintf(buffer, "Error.  getifaddrs was failed%s\n", ""); writeLog("workWithSockets.c", __func__, 62, buffer); };
        result = (-1);
    }
    { char buffer[256]; sprintf(buffer, "End | result: %d\n", result); writeLog("workWithSockets.c", __func__, 66, buffer); };
    return result;
}

variable_types:
IPadd
char *

variable_types: struct ifaddrs { struct ifaddrs *ifa_next; char *ifa_name; unsigned int ifa_flags; struct sockaddr { unsigned short sa_family; char sa_data[14]; } *ifa_addr; struct sockaddr *ifa_netmask; union { struct sockaddr *ifu_broadaddr; struct sockaddr *ifu_dstaddr; } ifa_ifu; void *ifa_data; } *

variable_types:
tempAddrPtr
void *

variable_types:
addressOutputBuffer
char [46]

user_defined_types: struct ifaddrs { struct ifaddrs *ifa_next; char *ifa_name; unsigned int ifa_flags; struct sockaddr *ifa_addr; struct sockaddr *ifa_netmask; union { struct sockaddr *ifu_broadaddr; struct sockaddr *ifu_dstaddr; } ifa_ifu; void *ifa_data; }

user_defined_types: struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr sin_addr; unsigned char sin_zero[-1]; }

user_defined_types: struct sockaddr_in6 { unsigned short sin6_family; unsigned short sin6_port; unsigned int sin6_flowinfo; struct in6_addr sin6_addr; unsigned int sin6_scope_id; }

user_defined_types: struct in6_addr { union { unsigned char __u6_addr8[16]; unsigned short __u6_addr16[8]; unsigned int __u6_addr32[4]; } __in6_u; }


connectToSocket

decompiled_code:
__int64 connectToSocket()
{
unsigned int v0; // ebx
char v2[256]; // [rsp+0h] [rbp-158h] BYREF
char cp[52]; // [rsp+100h] [rbp-58h] BYREF
int n; // [rsp+134h] [rbp-24h] BYREF
int v5; // [rsp+138h] [rbp-20h] BYREF
int optval[7]; // [rsp+13Ch] [rbp-1Ch] BYREF

optval[0] = 1;
v5 = 80;
n = 5;
sprintf(v2, "Start | %s\n", (const char *)&unk_8D5);
writeLog("workWithSockets.c", "connectToSocket", 81LL, v2);
getValueForKeyNumber("config.txt", "Port to listen:", &v5);
v0 = socket(2, 1, 0);
*(_QWORD *)&socketADD.sa_family = 0LL;
*(_QWORD *)&socketADD.sa_data[6] = 0LL;
socketADD.sa_family = 2;
if ( (unsigned int)getValueForKeyString("config.txt", "Is used IP address:", cp) == 1
&& (unsigned int)checkExistenceSpecifiedAddr(cp) == 1 )
{
*(_DWORD *)&socketADD.sa_data[2] = inet_addr(cp);
}
else
{
*(_DWORD *)&socketADD.sa_data[2] = 0;
}
*(_WORD *)socketADD.sa_data = _bswap_16(v5);
if ( setsockopt(v0, 1, 2, optval, 4u) == -1 )
{
sprintf(v2, "Error. Setsockopt was failing. | result: %d\n", 0xFFFFFFFFLL);
writeLog("workWithSockets.c", "connectToSocket", 103LL, v2);
v0 = -1;
}
else if ( bind(v0, &socketADD, 0x10u) == -1 )
{
sprintf(v2, "Error. Bind was failing. | result: %d\n", 0xFFFFFFFFLL);
writeLog("workWithSockets.c", "connectToSocket", 110LL, v2);
v0 = -1;
}
else
{
getValueForKeyNumber("config.txt", "Max number of connect:", &n);
if ( listen(v0, n) == -1 )
{
sprintf(v2, "Error. listen was failing. | result: %d\n", 0xFFFFFFFFLL);
writeLog("workWithSockets.c", "connectToSocket", 119LL, v2);
v0 = -1;
}
else
{
sprintf(v2, "End | Server is working now. | deskription: %d\n", v0);
writeLog("workWithSockets.c", "connectToSocket", 123LL, v2);
}
}
return v0;
}

canonical_decompiled_code:
__int64 func2()
{
unsigned int v0; // ebx
char v2[256]; // [rsp+0h] [rbp-158h] BYREF
char cp[52]; // [rsp+100h] [rbp-58h] BYREF
int n; // [rsp+134h] [rbp-24h] BYREF
int v5; // [rsp+138h] [rbp-20h] BYREF
int optval[7]; // [rsp+13Ch] [rbp-1Ch] BYREF

optval[0] = 1;
v5 = 80;
n = 5;
sprintf(v2, "Start | %s\n", (const char *)&unk_8D5);
writeLog("workWithSockets.c", "connectToSocket", 81LL, v2);
getValueForKeyNumber("config.txt", "Port to listen:", &v5);
v0 = socket(2, 1, 0);
*(_QWORD *)&socketADD.sa_family = 0LL;
*(_QWORD *)&socketADD.sa_data[6] = 0LL;
socketADD.sa_family = 2;
if ( (unsigned int)getValueForKeyString("config.txt", "Is used IP address:", cp) == 1
&& (unsigned int)func1(cp) == 1 )
{
*(_DWORD *)&socketADD.sa_data[2] = inet_addr(cp);
}
else
{
*(_DWORD *)&socketADD.sa_data[2] = 0;
}
*(_WORD *)socketADD.sa_data = func0(v5);
if ( setsockopt(v0, 1, 2, optval, 4u) == -1 )
{
sprintf(v2, "Error. Setsockopt was failing. | result: %d\n", 0xFFFFFFFFLL);
writeLog("workWithSockets.c", "connectToSocket", 103LL, v2);
v0 = -1;
}
else if ( bind(v0, &socketADD, 0x10u) == -1 )
{
sprintf(v2, "Error. Bind was failing. | result: %d\n", 0xFFFFFFFFLL);
writeLog("workWithSockets.c", "connectToSocket", 110LL, v2);
v0 = -1;
}
else
{
getValueForKeyNumber("config.txt", "Max number of connect:", &n);
if ( listen(v0, n) == -1 )
{
sprintf(v2, "Error. listen was failing. | result: %d\n", 0xFFFFFFFFLL);
writeLog("workWithSockets.c", "connectToSocket", 119LL, v2);
v0 = -1;
}
else
{
sprintf(v2, "End | Server is working now. | deskription: %d\n", v0);
writeLog("workWithSockets.c", "connectToSocket", 123LL, v2);
}
}
return v0;
}

original_code:
int connectToSocket(void)
{
    int yes = 1;
    int deskription = 0;
    int result;
    int port = (80);
    int maxConnect = (5);
    char IPaddress[46];
    { char buffer[256]; sprintf(buffer, "Start | %s\n", ""); writeLog("workWithSockets.c", __func__, 81, buffer); };
    getValueForKeyNumber("config.txt", "Port to listen:", &port);
    deskription = socket(2, SOCK_STREAM, 0);
    memset(&socketADD, 0, sizeof(socketADD));
    socketADD.sin_family = 2;
    if((1) == getValueForKeyString("config.txt", "Is used IP address:", IPaddress) && (1) == checkExistenceSpecifiedAddr(IPaddress))
    {
        socketADD.sin_addr.s_addr = inet_addr(IPaddress);
    }
    else
    {
        socketADD.sin_addr.s_addr = ((in_addr_t) 0x00000000);
    }
    socketADD.sin_port = htons((unsigned short)port);
    if (setsockopt(deskription, 1, 2, &yes, sizeof(int)) == (-1))
    {
        result = (-1);
        { char buffer[256]; sprintf(buffer, "Error. Setsockopt was failing. | result: %d\n", result); writeLog("workWithSockets.c", __func__, 103, buffer); };
        return result;
    }
    if(bind(deskription,(struct sockaddr*)&socketADD, sizeof(socketADD)) == (-1))
    {
        result = (-1);
        { char buffer[256]; sprintf(buffer, "Error. Bind was failing. | result: %d\n", result); writeLog("workWithSockets.c", __func__, 110, buffer); };
        return result;
    }
    getValueForKeyNumber("config.txt", "Max number of connect:", &maxConnect);
    if(listen(deskription, maxConnect) == (-1))
    {
        result = (-1);
        { char buffer[256]; sprintf(buffer, "Error. listen was failing. | result: %d\n", result); writeLog("workWithSockets.c", __func__, 119, buffer); };
        return result;
    }
    result = deskription;
    { char buffer[256]; sprintf(buffer, "End | Server is working now. | deskription: %d\n", result); writeLog("workWithSockets.c", __func__, 123, buffer); };
    return result;
}

canonical_original_code:
int connectToSocket()
{
    int yes = 1;
    int deskription = 0;
    int result;
    int port = (80);
    int maxConnect = (5);
    char IPaddress[46];
    { char buffer[256]; sprintf(buffer, "Start | %s\n", ""); writeLog("workWithSockets.c", __func__, 81, buffer); };
    getValueForKeyNumber("config.txt", "Port to listen:", &port);
    deskription = socket(2, SOCK_STREAM, 0);
    memset(&socketADD, 0, sizeof(socketADD));
    socketADD.sin_family = 2;
    if((1) == getValueForKeyString("config.txt", "Is used IP address:", IPaddress) && (1) == checkExistenceSpecifiedAddr(IPaddress))
    {
        socketADD.sin_addr.s_addr = inet_addr(IPaddress);
    }
    else
    {
        socketADD.sin_addr.s_addr = ((unsigned int) 0x00000000);
    }
    socketADD.sin_port = htons((unsigned short)port);
    if (setsockopt(deskription, 1, 2, &yes, sizeof(int)) == (-1))
    {
        result = (-1);
        { char buffer[256]; sprintf(buffer, "Error. Setsockopt was failing. | result: %d\n", result); writeLog("workWithSockets.c", __func__, 103, buffer); };
        return result;
    }
    if(bind(deskription,(struct sockaddr *)&socketADD, sizeof(socketADD)) == (-1))
    {
        result = (-1);
        { char buffer[256]; sprintf(buffer, "Error. Bind was failing. | result: %d\n", result); writeLog("workWithSockets.c", __func__, 110, buffer); };
        return result;
    }
    getValueForKeyNumber("config.txt", "Max number of connect:", &maxConnect);
    if(listen(deskription, maxConnect) == (-1))
    {
        result = (-1);
        { char buffer[256]; sprintf(buffer, "Error. listen was failing. | result: %d\n", result); writeLog("workWithSockets.c", __func__, 119, buffer); };
        return result;
    }
    result = deskription;
    { char buffer[256]; sprintf(buffer, "End | Server is working now. | deskription: %d\n", result); writeLog("workWithSockets.c", __func__, 123, buffer); };
    return result;
}

variable_types: yes int

variable_types: port int

variable_types: maxConnect int

variable_types:
IPaddress
char [46]

user_defined_types: struct sockaddr { unsigned short sa_family; char sa_data[14]; }