decompiled_code:
__int64 tm2_handler()
{
struct timeval v1; // [rsp+0h] [rbp-18h] BYREF

gettimeofday(&v1, 0LL);
printf("tm2:interval=%u.%u\n", v1.tv_sec - tm2_last.tv_sec, v1.tv_usec - tm2_last.tv_usec);
tm2_last = (struct timeval)_mm_loadu_si128((const __m128i *)&v1);
return 0LL;
}

canonical_decompiled_code:
__int64 func2()
{
struct timeval v1; // [rsp+0h] [rbp-18h] BYREF

gettimeofday(&v1, 0LL);
printf("tm2:interval=%u.%u\n", v1.tv_sec - tm2_last.tv_sec, v1.tv_usec - tm2_last.tv_usec);
tm2_last = (struct timeval)_mm_loadu_si128((const __m128i *)&v1);
return 0LL;
}

original_code:
int32_t tm2_handler(void *args)
{
 struct timeval tm_now;
 gettimeofday(&tm_now, ((void *)0));
 printf("tm2:interval=%u.%u\n",
   tm_now.tv_sec-tm2_last.tv_sec, tm_now.tv_usec-tm2_last.tv_usec);
 tm2_last = tm_now;
 return 0;
}

canonical_original_code:
int tm2_handler(void *args)
{
 struct timeval tm_now;
 gettimeofday(&tm_now, ((void *)0));
 printf("tm2:interval=%u.%u\n",
   tm_now.tv_sec-tm2_last.tv_sec, tm_now.tv_usec-tm2_last.tv_usec);
 tm2_last = tm_now;
 return 0;
}


decompiled_code:
__int64 tm3_handler()
{
struct timeval v1; // [rsp+0h] [rbp-18h] BYREF

gettimeofday(&v1, 0LL);
printf("tm3:interval=%u.%u\n", v1.tv_sec - tm3_last.tv_sec, v1.tv_usec - tm3_last.tv_usec);
tm3_last = (struct timeval)_mm_loadu_si128((const __m128i *)&v1);
return 0LL;
}

canonical_decompiled_code:
__int64 func3()
{
struct timeval v1; // [rsp+0h] [rbp-18h] BYREF

gettimeofday(&v1, 0LL);
printf("tm3:interval=%u.%u\n", v1.tv_sec - tm3_last.tv_sec, v1.tv_usec - tm3_last.tv_usec);
tm3_last = (struct timeval)_mm_loadu_si128((const __m128i *)&v1);
return 0LL;
}

original_code:
int32_t tm3_handler(void *args)
{
 struct timeval tm_now;
 gettimeofday(&tm_now, ((void *)0));
 printf("tm3:interval=%u.%u\n",
   tm_now.tv_sec-tm3_last.tv_sec, tm_now.tv_usec-tm3_last.tv_usec);
 tm3_last = tm_now;
 return 0;
}

canonical_original_code:
int tm3_handler(void *args)
{
 struct timeval tm_now;
 gettimeofday(&tm_now, ((void *)0));
 printf("tm3:interval=%u.%u\n",
   tm_now.tv_sec-tm3_last.tv_sec, tm_now.tv_usec-tm3_last.tv_usec);
 tm3_last = tm_now;
 return 0;
}

variable_types:
args
void *

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

return_type: int


decompiled_code:
int __fastcall timer_thread(unsigned int *a1)
{
printf("thread run, val=%d\n", *a1);
sleep(5u);
return puts("thread finished");
}

canonical_decompiled_code:
int __fastcall func4(unsigned int *a1)
{
printf("thread run, val=%d\n", *a1);
sleep(5u);
return puts("thread finished");
}

original_code:
void timer_thread(sigval_t val)
{
 struct timer_struct *ts = val.sival_ptr;
 printf("thread run, val=%d\n", ts->priv);
 sleep(5);
 printf("thread finished\n");
}

canonical_original_code:
void timer_thread(union sigval val)
{
 struct timer_struct *ts = val.sival_ptr;
 printf("thread run, val=%d\n", ts->priv);
 sleep(5);
 printf("thread finished\n");
}

variable_types: union sigval { int sival_int; void *sival_ptr; }

variable_types: struct timer_struct { int priv; void *timer_id; struct itimerspec { struct timespec { long tv_sec; long tv_nsec; } it_interval; struct timespec it_value; } tick; } *

return_type: void

user_defined_types: struct timer_struct { int priv; void *timer_id; struct itimerspec tick; }

user_defined_types: struct itimerspec { struct timespec it_interval; struct timespec it_value; }


decompiled_code:
int test_timer_create()
{
int v0; // ebx
int *v1; // rbx
char *v2; // rax
struct itimerspec v4; // [rsp+0h] [rbp-68h] BYREF
struct sigevent evp; // [rsp+20h] [rbp-48h] BYREF

signal(14, (__sighandler_t)sig_handler);
evp.sigev_value.sival_ptr = &g_ts;
evp.sigev_signo = 14;
evp.sigev_notify = 2;
evp._sigev_un._sigev_thread._function = (void (*)(sigval_t))timer_thread;
evp._sigev_un._sigev_thread._attribute = 0LL;
if ( !timer_create(0, &evp, (timer_t *)(unsigned int)((_DWORD)&g_ts + 8)) )
{
v0 = 0;
*(&g_ts + 4) = 0LL;
*(&g_ts + 5) = 0LL;
*(&g_ts + 2) = 0LL;
*(&g_ts + 3) = 0LL;
timer_settime(*(&g_ts + 1), 0, (const struct itimerspec *)(unsigned int)((_DWORD)&g_ts + 16), 0LL);
while ( 1 )
{
timer_gettime(*(&g_ts + 1), &v4);
printf(
"still it_value=%d.%d it_interval=%d.%d seconds.\n",
v4.it_value.tv_sec,
v4.it_value.tv_nsec,
v4.it_interval.tv_sec,
v4.it_interval.tv_nsec);
if ( v4.it_value.tv_sec <= 1 && v0 <= 9 )
{
v4.it_value.tv_sec = 4LL;
timer_settime(*(&g_ts + 1), 0, &v4, 0LL);
++v0;
}
sleep(1u);
}
}
v1 = _errno_location();
v2 = strerror(*v1);
return printf("timer_create error:%d(%s)\n", (unsigned int)*v1, v2);
}

canonical_decompiled_code:
int func5()
{
int v0; // ebx
int *v1; // rbx
char *v2; // rax
struct itimerspec v4; // [rsp+0h] [rbp-68h] BYREF
struct sigevent evp; // [rsp+20h] [rbp-48h] BYREF

signal(14, (__sighandler_t)sig_handler);
evp.sigev_value.sival_ptr = &g_ts;
evp.sigev_signo = 14;
evp.sigev_notify = 2;
evp._sigev_un._sigev_thread._function = (void (*)(sigval_t))timer_thread;
evp._sigev_un._sigev_thread._attribute = 0LL;
if ( !timer_create(0, &evp, (timer_t *)(unsigned int)((_DWORD)&g_ts + 8)) )
{
v0 = 0;
*(&g_ts + 4) = 0LL;
*(&g_ts + 5) = 0LL;
*(&g_ts + 2) = 0LL;
*(&g_ts + 3) = 0LL;
timer_settime(*(&g_ts + 1), 0, (const struct itimerspec *)(unsigned int)((_DWORD)&g_ts + 16), 0LL);
while ( 1 )
{
timer_gettime(*(&g_ts + 1), &v4);
printf(
"still it_value=%d.%d it_interval=%d.%d seconds.\n",
v4.it_value.tv_sec,
v4.it_value.tv_nsec,
v4.it_interval.tv_sec,
v4.it_interval.tv_nsec);
if ( v4.it_value.tv_sec <= 1 && v0 <= 9 )
{
v4.it_value.tv_sec = 4LL;
timer_settime(*(&g_ts + 1), 0, &v4, 0LL);
++v0;
}
sleep(1u);
}
}
v1 = _errno_location();
v2 = strerror(*v1);
return printf("timer_create error:%d(%s)\n", (unsigned int)*v1, v2);
}

original_code:
void test_timer_create(void)
{
 struct sigevent sige;
 struct itimerspec tspec;
 long ret;
 int count = 0;
 signal(14, sig_handler);
 sige.sigev_value.sival_ptr = &g_ts;
 sige.sigev_signo = 14;
 sige.sigev_notify = SIGEV_THREAD;
 sige._sigev_un._sigev_thread._function = timer_thread;
 sige._sigev_un._sigev_thread._attribute = ((void *)0);
 ret = timer_create(0, &sige, &g_ts.timer_id);
 if (ret) {
  printf("timer_create error:%d(%s)\n", (*__errno_location ()), strerror((*__errno_location ())));
  return ;
 }
 g_ts.tick.it_value.tv_sec = 0;
 g_ts.tick.it_value.tv_nsec = 0;
 g_ts.tick.it_interval.tv_sec = 0;
 g_ts.tick.it_interval.tv_nsec = 0;
 timer_settime(g_ts.timer_id, 0, &g_ts.tick, ((void *)0));
 while(1) {
  timer_gettime(g_ts.timer_id, &tspec);
  printf("still it_value=%d.%d it_interval=%d.%d seconds.\n",
    tspec.it_value.tv_sec,
    tspec.it_value.tv_nsec,
    tspec.it_interval.tv_sec,
    tspec.it_interval.tv_nsec);
  if (tspec.it_value.tv_sec < 2 && count < 10) {
   tspec.it_value.tv_sec = 4;
   timer_settime(g_ts.timer_id, 0, &tspec, ((void *)0));
   count ++;
  }
  sleep(1);
 }
}

canonical_original_code:
void test_timer_create()
{
 struct sigevent sige;
 struct itimerspec tspec;
 long ret;
 int count = 0;
 signal(14, sig_handler);
 sige.sigev_value.sival_ptr = &g_ts;
 sige.sigev_signo = 14;
 sige.sigev_notify = SIGEV_THREAD;
 sige._sigev_un._sigev_thread._function = timer_thread;
 sige._sigev_un._sigev_thread._attribute = ((void *)0);
 ret = timer_create(0, &sige, &g_ts.timer_id);
 if (ret) {
  printf("timer_create error:%d(%s)\n", (*__errno_location ()), strerror((*__errno_location ())));
  return ;
 }
 g_ts.tick.it_value.tv_sec = 0;
 g_ts.tick.it_value.tv_nsec = 0;
 g_ts.tick.it_interval.tv_sec = 0;
 g_ts.tick.it_interval.tv_nsec = 0;
 timer_settime(g_ts.timer_id, 0, &g_ts.tick, ((void *)0));
 while(1) {
  timer_gettime(g_ts.timer_id, &tspec);
  printf("still it_value=%d.%d it_interval=%d.%d seconds.\n",
    tspec.it_value.tv_sec,
    tspec.it_value.tv_nsec,
    tspec.it_interval.tv_sec,
    tspec.it_interval.tv_nsec);
  if (tspec.it_value.tv_sec < 2 && count < 10) {
   tspec.it_value.tv_sec = 4;
   timer_settime(g_ts.timer_id, 0, &tspec, ((void *)0));
   count ++;
  }
  sleep(1);
 }
}

variable_types: struct sigevent { union sigval { int sival_int; void *sival_ptr; } sigev_value; int sigev_signo; int sigev_notify; union { int _pad[-1]; int _tid; struct { void (*_function)(union sigval); union pthread_attr_t { char __size[56]; long __align; } *_attribute; } _sigev_thread; } _sigev_un; }

variable_types: struct itimerspec { struct timespec { long tv_sec; long tv_nsec; } it_interval; struct timespec it_value; }

variable_types: ret long

variable_types: count int

user_defined_types: struct sigevent { union sigval sigev_value; int sigev_signo; int sigev_notify; union { int _pad[-1]; int _tid; struct { void (*_function)(union sigval); union pthread_attr_t *_attribute; } _sigev_thread; } _sigev_un; }


decompiled_code:
int test_setitimer()
{
struct itimerval v1; // [rsp+0h] [rbp-48h] BYREF
struct itimerval newa; // [rsp+20h] [rbp-28h] BYREF

newa.it_value.tv_sec = 3LL;
newa.it_value.tv_usec = 0LL;
newa.it_interval.tv_sec = 3LL;
newa.it_interval.tv_usec = 0LL;
v1.it_value.tv_sec = 3LL;
v1.it_value.tv_usec = 0LL;
v1.it_interval.tv_sec = 5LL;
v1.it_interval.tv_usec = 0LL;
signal(14, (__sighandler_t)sig_handler);
if ( setitimer(ITIMER_REAL, &newa, 0LL) )
return puts("set timer failed");
if ( !setitimer(ITIMER_REAL, &v1, 0LL) )
{
while ( 1 )
pause();
}
return puts("set timer failed");
}

canonical_decompiled_code:
int func6()
{
struct itimerval v1; // [rsp+0h] [rbp-48h] BYREF
struct itimerval newa; // [rsp+20h] [rbp-28h] BYREF

newa.it_value.tv_sec = 3LL;
newa.it_value.tv_usec = 0LL;
newa.it_interval.tv_sec = 3LL;
newa.it_interval.tv_usec = 0LL;
v1.it_value.tv_sec = 3LL;
v1.it_value.tv_usec = 0LL;
v1.it_interval.tv_sec = 5LL;
v1.it_interval.tv_usec = 0LL;
signal(14, (__sighandler_t)sig_handler);
if ( setitimer(ITIMER_REAL, &newa, 0LL) )
return puts("set timer failed");
if ( !setitimer(ITIMER_REAL, &v1, 0LL) )
{
while ( 1 )
pause();
}
return puts("set timer failed");
}

original_code:
void test_setitimer(void)
{
 int ret;
 struct itimerval tick1;
 struct itimerval tick2;
 tick1.it_value.tv_sec = 3;
 tick1.it_value.tv_usec = 0;
 tick1.it_interval.tv_sec = 3;
 tick1.it_interval.tv_usec = 0;
 tick2.it_value.tv_sec = 3;
 tick2.it_value.tv_usec = 0;
 tick2.it_interval.tv_sec = 5;
 tick2.it_interval.tv_usec = 0;
 signal(14, sig_handler);
 ret = setitimer(ITIMER_REAL, &tick1, ((void *)0));
 if (ret) {
  printf("set timer failed\n");
  return;
 }
 ret = setitimer(ITIMER_REAL, &tick2, ((void *)0));
 if (ret) {
  printf("set timer failed\n");
  return;
 }
 while(1) {
  pause();
 }
}

canonical_original_code:
void test_setitimer()
{
 int ret;
 struct itimerval tick1;
 struct itimerval tick2;
 tick1.it_value.tv_sec = 3;
 tick1.it_value.tv_usec = 0;
 tick1.it_interval.tv_sec = 3;
 tick1.it_interval.tv_usec = 0;
 tick2.it_value.tv_sec = 3;
 tick2.it_value.tv_usec = 0;
 tick2.it_interval.tv_sec = 5;
 tick2.it_interval.tv_usec = 0;
 signal(14, sig_handler);
 ret = setitimer(ITIMER_REAL, &tick1, ((void *)0));
 if (ret) {
  printf("set timer failed\n");
  return;
 }
 ret = setitimer(ITIMER_REAL, &tick2, ((void *)0));
 if (ret) {
  printf("set timer failed\n");
  return;
 }
 while(1) {
  pause();
 }
}

variable_types: ret int

variable_types: struct itimerval { struct timeval { long tv_sec; long tv_usec; } it_interval; struct timeval it_value; }

user_defined_types: struct itimerval { struct timeval it_interval; struct timeval it_value; }


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rax
__int64 v4; // rbp
__int64 v5; // r13
__int64 v6; // r12
__int64 v7; // r14
int v8; // ebx
int v9; // er15
int v10; // edx
int v11; // eax
int v12; // ebx
int v13; // ebx
int v14; // er12

v3 = bw_timer_create_queue(argc, argv, envp);
if ( v3 )
{
v4 = v3;
v5 = bw_timer_create_timer(5LL, 0LL, 1LL, 0LL, tm1_handler, "hello");
v6 = bw_timer_create_timer(4LL, 0LL, 2LL, 0LL, tm2_handler, "hello");
v7 = bw_timer_create_timer(6LL, 0LL, 3LL, 0LL, tm3_handler, "hello");
if ( v6 == 0 || v5 == 0 || !v7 )
{
puts("Create timer 2 failed.");
}
else
{
gettimeofday(&tm1_last, 0LL);
v8 = bw_timer_queue_timer(v4, v5);
gettimeofday(&tm2_last, 0LL);
v9 = bw_timer_queue_timer(v4, v6);
gettimeofday(&tm3_last, 0LL);
v10 = bw_timer_queue_timer(v4, v7);
v11 = v9 | v8;
v12 = 10;
if ( v10 | v11 )
{
puts("Queue timer failed.");
}
else
{
do
{
sleep(1u);
--v12;
}
while ( v12 );
v13 = bw_timer_unqueue_timer(v4, v5);
v14 = bw_timer_unqueue_timer(v4, v6);
if ( !((unsigned int)bw_timer_unqueue_timer(v4, v7) | v14 | v13) )
{
while ( 1 )
sleep(1u);
}
puts("Unqueue timer failed.");
}
}
}
else
{
puts("Create timer queue failed.");
}
return 0;
}

original_code:
int main(int argc, char *argv[])
{
 struct timeval tm1_begin = {.tv_sec=5, .tv_usec=0,},
         tm1_tick = {.tv_sec=1, .tv_usec=0,},
         tm2_begin = {.tv_sec=4, .tv_usec=0,},
         tm2_tick = {.tv_sec=2, .tv_usec=0,},
         tm3_begin = {.tv_sec=6, .tv_usec=0,},
         tm3_tick = {.tv_sec=3, .tv_usec=0,};
 char *args = "hello";
 int ret1, ret2, ret3, i;
 bw_timer_queue_t *queue;
 bw_timer_timer_t *tm1, *tm2, *tm3;
 queue = bw_timer_create_queue();
 if (!queue) {
  printf("Create timer queue failed.\n");
  goto out;
 }
 tm1 = bw_timer_create_timer(tm1_begin, tm1_tick, tm1_handler, args);
 tm2 = bw_timer_create_timer(tm2_begin, tm2_tick, tm2_handler, args);
 tm3 = bw_timer_create_timer(tm3_begin, tm3_tick, tm3_handler, args);
 if (!tm1 || !tm2 || !tm3) {
  printf("Create timer 2 failed.\n");
  goto out;
 }
 gettimeofday(&tm1_last, ((void *)0));
 ret1 = bw_timer_queue_timer(queue, tm1);
 gettimeofday(&tm2_last, ((void *)0));
 ret2 = bw_timer_queue_timer(queue, tm2);
 gettimeofday(&tm3_last, ((void *)0));
 ret3 = bw_timer_queue_timer(queue, tm3);
 if (ret1 || ret2 || ret3) {
  printf("Queue timer failed.\n");
  goto out;
 }
 for (i=0; i<10; i++)
  sleep(1);
 ret1 = bw_timer_unqueue_timer(queue, tm1);
 ret2 = bw_timer_unqueue_timer(queue, tm2);
 ret3 = bw_timer_unqueue_timer(queue, tm3);
 if (ret1 || ret2 || ret3) {
  printf("Unqueue timer failed.\n");
  goto out;
 }
 while (1)
  sleep(1);
out:
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
 struct timeval tm1_begin = {.tv_sec=5, .tv_usec=0,}; struct timeval tm1_tick = {.tv_sec=1, .tv_usec=0,}; struct timeval tm2_begin = {.tv_sec=4, .tv_usec=0,}; struct timeval tm2_tick = {.tv_sec=2, .tv_usec=0,}; struct timeval tm3_begin = {.tv_sec=6, .tv_usec=0,}; struct timeval tm3_tick = {.tv_sec=3, .tv_usec=0,};
 char *args = "hello";
 int ret1; int ret2; int ret3; int i;
 struct _bw_timer_queue *queue;
 struct _bw_timer_timer *tm1; struct _bw_timer_timer *tm2; struct _bw_timer_timer *tm3;
 queue = bw_timer_create_queue();
 if (!queue) {
  printf("Create timer queue failed.\n");
  goto out;
 }
 tm1 = bw_timer_create_timer(tm1_begin, tm1_tick, tm1_handler, args);
 tm2 = bw_timer_create_timer(tm2_begin, tm2_tick, tm2_handler, args);
 tm3 = bw_timer_create_timer(tm3_begin, tm3_tick, tm3_handler, args);
 if (!tm1 || !tm2 || !tm3) {
  printf("Create timer 2 failed.\n");
  goto out;
 }
 gettimeofday(&tm1_last, ((void *)0));
 ret1 = bw_timer_queue_timer(queue, tm1);
 gettimeofday(&tm2_last, ((void *)0));
 ret2 = bw_timer_queue_timer(queue, tm2);
 gettimeofday(&tm3_last, ((void *)0));
 ret3 = bw_timer_queue_timer(queue, tm3);
 if (ret1 || ret2 || ret3) {
  printf("Queue timer failed.\n");
  goto out;
 }
 for (i=0; i<10; i++)
  sleep(1);
 ret1 = bw_timer_unqueue_timer(queue, tm1);
 ret2 = bw_timer_unqueue_timer(queue, tm2);
 ret3 = bw_timer_unqueue_timer(queue, tm3);
 if (ret1 || ret2 || ret3) {
  printf("Unqueue timer failed.\n");
  goto out;
 }
 while (1)
  sleep(1);
out:
 return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types:
args
char *

variable_types: i int

variable_types: struct _bw_timer_queue { struct bw_list_head { struct bw_list_head *next; } tmq_list; struct sigevent { union sigval { int sival_int; void *sival_ptr; } sigev_value; int sigev_signo; int sigev_notify; union { int _pad[-1]; int _tid; struct { void (*_function)(union sigval); union pthread_attr_t { char __size[56]; long __align; } *_attribute; } _sigev_thread; } _sigev_un; } tmq_sige; void *tmq_id; struct itimerspec { struct timespec { long tv_sec; long tv_nsec; } it_interval; struct timespec it_value; } tmq_timeo; int tmq_count; } *

variable_types: struct _bw_timer_timer { struct bw_list_head { struct bw_list_head *next; } tm_node; int (*tm_handler)(void *); void *tm_args; struct timeval { long tv_sec; long tv_usec; } tm_begin; struct timeval tm_tick; struct timeval tm_timeo; } *

user_defined_types: struct _bw_timer_queue { struct bw_list_head tmq_list; struct sigevent tmq_sige; void *tmq_id; struct itimerspec tmq_timeo; int tmq_count; }

user_defined_types: struct _bw_timer_timer { struct bw_list_head tm_node; int (*tm_handler)(void *); void *tm_args; struct timeval tm_begin; struct timeval tm_tick; struct timeval tm_timeo; }


decompiled_code:
int __fastcall alloc_keep(int a1, off_t a2, off_t a3)
{
return posix_fallocate(a1, a2, a3);
}

canonical_decompiled_code:
int __fastcall func7(int a1, off_t a2, off_t a3)
{
return posix_fallocate(a1, a2, a3);
}

original_code:
int alloc_keep(int fd, loff_t off, loff_t len)
{
 return posix_fallocate(fd, off, len);
}

canonical_original_code:
int alloc_keep(int fd, long off, long len)
{
 return posix_fallocate(fd, off, len);
}

variable_types: fd int

variable_types: off long

variable_types: len long


decompiled_code:
int __fastcall alloc_unkeep(int a1, off_t a2, off_t a3)
{
return posix_fallocate(a1, a2, a3);
}

canonical_decompiled_code:
int __fastcall func8(int a1, off_t a2, off_t a3)
{
return posix_fallocate(a1, a2, a3);
}

original_code:
int alloc_unkeep(int fd, loff_t off, loff_t len)
{
 return posix_fallocate(fd, off, len);
}

canonical_original_code:
int alloc_unkeep(int fd, long off, long len)
{
 return posix_fallocate(fd, off, len);
}


test

decompiled_code:
int __fastcall test(__int64 a1)
{
int v2; // edi
unsigned int v3; // ebx
int *v5; // rbx
char *v6; // rax
int *v7; // rbp
char *v8; // rax

if ( calloc(1uLL, *(_QWORD *)(a1 + 24)) )
{
v2 = open(*(const char **)a1, 66, 420LL);
if ( v2 < 0 )
{
v5 = __errno_location();
v6 = strerror(*v5);
printf("Can not open file.(%d)%s\n", (unsigned int)*v5, v6);
}
else
{
if ( *(_DWORD *)(a1 + 8) )
v3 = alloc_keep(v2, *(_QWORD *)(a1 + 16), *(_QWORD *)(a1 + 24));
else
v3 = alloc_unkeep(v2, *(_QWORD *)(a1 + 16), *(_QWORD *)(a1 + 24));
if ( !v3 )
return puts("test succeed.");
v7 = __errno_location();
v8 = strerror(*v7);
printf("Can not fallocate file.ret = %d (%d)%s\n", v3, (unsigned int)*v7, v8);
}
}
else
{
puts("Can not alloc mem.");
}
return puts("test failed.");
}

canonical_decompiled_code:
int __fastcall func9(__int64 a1)
{
int v2; // edi
unsigned int v3; // ebx
int *v5; // rbx
char *v6; // rax
int *v7; // rbp
char *v8; // rax

if ( calloc(1uLL, *(_QWORD *)(a1 + 24)) )
{
v2 = open(*(const char **)a1, 66, 420LL);
if ( v2 < 0 )
{
v5 = __errno_location();
v6 = strerror(*v5);
printf("Can not open file.(%d)%s\n", (unsigned int)*v5, v6);
}
else
{
if ( *(_DWORD *)(a1 + 8) )
v3 = func7(v2, *(_QWORD *)(a1 + 16), *(_QWORD *)(a1 + 24));
else
v3 = func8(v2, *(_QWORD *)(a1 + 16), *(_QWORD *)(a1 + 24));
if ( !v3 )
return puts("test succeed.");
v7 = __errno_location();
v8 = strerror(*v7);
printf("Can not fallocate file.ret = %d (%d)%s\n", v3, (unsigned int)*v7, v8);
}
}
else
{
puts("Can not alloc mem.");
}
return puts("test failed.");
}

original_code:
void test(const struct options *opts)
{
 int fd = 0, ret = 0;
 loff_t off_now = 0;
 char *buf = ((void *)0);
 ssize_t write_bytes = 0;
 buf = calloc(1, opts->len);
 if (!buf) {
  printf("Can not alloc mem.\n");
  goto failed;
 }
 fd = open(opts->file_path, (02|0100), 0644);
 if (fd < 0) {
  printf("Can not open file.(%d)%s\n", (*__errno_location ()), strerror((*__errno_location ())));
  goto failed;
 }
 if (opts->keep)
  ret = alloc_keep(fd, opts->off, opts->len);
 else
  ret = alloc_unkeep(fd, opts->off, opts->len);
 if (ret) {
  printf("Can not fallocate file.ret = %d (%d)%s\n", ret, (*__errno_location ()), strerror((*__errno_location ())));
  goto failed;
 }
 printf("test succeed.\n");
 return ;
failed:
 printf("test failed.\n");
 return ;
}

canonical_original_code:
void test(struct options *opts)
{
 int fd = 0; int ret = 0;
 long off_now = 0;
 char *buf = ((void *)0);
 long write_bytes = 0;
 buf = calloc(1, opts->len);
 if (!buf) {
  printf("Can not alloc mem.\n");
  goto failed;
 }
 fd = open(opts->file_path, (02|0100), 0644);
 if (fd < 0) {
  printf("Can not open file.(%d)%s\n", (*__errno_location ()), strerror((*__errno_location ())));
  goto failed;
 }
 if (opts->keep)
  ret = alloc_keep(fd, opts->off, opts->len);
 else
  ret = alloc_unkeep(fd, opts->off, opts->len);
 if (ret) {
  printf("Can not fallocate file.ret = %d (%d)%s\n", ret, (*__errno_location ()), strerror((*__errno_location ())));
  goto failed;
 }
 printf("test succeed.\n");
 return ;
failed:
 printf("test failed.\n");
 return ;
}

variable_types: struct options { char *file_path; int keep; long off; long len; } *

variable_types:
buf
char *


decompiled_code:
__int64 __fastcall parse_args(int a1, __int64 a2, __int64 a3)
{
int v6; // ebx
int v7; // er14
__int64 result; // rax
__int64 v9; // r8

*(_DWORD *)(a3 + 8) = 1;
*(_QWORD *)(a3 + 16) = 1024LL;
*(_QWORD *)(a3 + 24) = 4096LL;
if ( a1 > 1 )
{
v6 = 1;
v7 = a1 - 1;
do
{
v9 = 8LL * v6;
if ( !memcmp(*(const void **)(a2 + v9), "-o", 3uLL) )
{
if ( v7 == v6 )
{
puts("missing args for -o");
return 1LL;
}
++v6;
*(_QWORD *)(a3 + 16) = atoll(*(const char **)(a2 + v9 + 8));
}
else if ( !strcmp(*(const char **)(a2 + 8LL * v6), "-l") )
{
if ( v7 == v6 )
goto LABEL_11;
++v6;
*(_QWORD *)(a3 + 24) = atoll(*(const char **)(a2 + v9 + 8));
}
else if ( !strcmp(*(const char **)(a2 + 8LL * v6), "-m") )
{
if ( v7 == v6 )
{
LABEL_11:
puts("missing args for -l");
return 1LL;
}
++v6;
if ( !strcmp(*(const char **)(a2 + v9 + 8), "keep_size") )
{
*(_DWORD *)(a3 + 8) = 1;
}
else
{
if ( strcmp(*(const char **)(a2 + v9 + 8), "unkeep_size") )
{
printf("Unkown args %s for -m\n", *(const char **)(a2 + v9 + 8));
return 1LL;
}
*(_DWORD *)(a3 + 8) = 0;
}
}
else
{
if ( *(_QWORD *)a3 )
{
printf("invalid option %s.\n", *(const char **)(a2 + 8LL * v6));
return 1LL;
}
*(_QWORD *)a3 = strdup(*(const char **)(a2 + 8LL * v6));
}
++v6;
}
while ( a1 > v6 );
}
result = 0LL;
if ( !*(_QWORD *)a3 )
{
puts("provide a file path");
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func10(int a1, __int64 a2, __int64 a3)
{
int v6; // ebx
int v7; // er14
__int64 result; // rax
__int64 v9; // r8

*(_DWORD *)(a3 + 8) = 1;
*(_QWORD *)(a3 + 16) = 1024LL;
*(_QWORD *)(a3 + 24) = 4096LL;
if ( a1 > 1 )
{
v6 = 1;
v7 = a1 - 1;
do
{
v9 = 8LL * v6;
if ( !memcmp(*(const void **)(a2 + v9), "-o", 3uLL) )
{
if ( v7 == v6 )
{
puts("missing args for -o");
return 1LL;
}
++v6;
*(_QWORD *)(a3 + 16) = atoll(*(const char **)(a2 + v9 + 8));
}
else if ( !strcmp(*(const char **)(a2 + 8LL * v6), "-l") )
{
if ( v7 == v6 )
goto LABEL_11;
++v6;
*(_QWORD *)(a3 + 24) = atoll(*(const char **)(a2 + v9 + 8));
}
else if ( !strcmp(*(const char **)(a2 + 8LL * v6), "-m") )
{
if ( v7 == v6 )
{
LABEL_11:
puts("missing args for -l");
return 1LL;
}
++v6;
if ( !strcmp(*(const char **)(a2 + v9 + 8), "keep_size") )
{
*(_DWORD *)(a3 + 8) = 1;
}
else
{
if ( strcmp(*(const char **)(a2 + v9 + 8), "unkeep_size") )
{
printf("Unkown args %s for -m\n", *(const char **)(a2 + v9 + 8));
return 1LL;
}
*(_DWORD *)(a3 + 8) = 0;
}
}
else
{
if ( *(_QWORD *)a3 )
{
printf("invalid option %s.\n", *(const char **)(a2 + 8LL * v6));
return 1LL;
}
*(_QWORD *)a3 = strdup(*(const char **)(a2 + 8LL * v6));
}
++v6;
}
while ( a1 > v6 );
}
result = 0LL;
if ( !*(_QWORD *)a3 )
{
puts("provide a file path");
result = 1LL;
}
return result;
}

original_code:
int parse_args(int argc, char *argv[], struct options *opts)
{
 int i;
 opts->keep = 1;
 opts->off = 1024;
 opts->len = 4096;
 for (i=1; i<argc; i++) {
  if (strcmp(argv[i], "-o") == 0) {
   if (i == argc-1) {
    printf("missing args for -o\n");
    goto failed;
   }
   opts->off = atoll(argv[++i]);
  } else if (strcmp(argv[i], "-l") == 0) {
   if (i == argc-1) {
    printf("missing args for -l\n");
    goto failed;
   }
   opts->len = atoll(argv[++i]);
  } else if (strcmp(argv[i], "-m") == 0) {
   if (i == argc-1) {
    printf("missing args for -l\n");
    goto failed;
   }
   i++;
   if (strcmp(argv[i], "keep_size") == 0) {
    opts->keep = 1;
   } else if (strcmp(argv[i], "unkeep_size") == 0) {
    opts->keep = 0;
   } else {
    printf("Unkown args %s for -m\n", argv[i]);
    goto failed;
   }
  } else {
   if (!opts->file_path) {
    opts->file_path = strdup(argv[i]);
   } else {
    printf("invalid option %s.\n", argv[i]);
    goto failed;
   }
  }
 }
 if (!opts->file_path) {
  printf("provide a file path\n");
  goto failed;
 }
 return 0;
failed:
 return 1;
}

user_defined_types: struct options { char *file_path; int keep; long off; long len; }


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // ebx
const char *v5; // [rsp+0h] [rbp-28h] BYREF
__int64 v6; // [rsp+8h] [rbp-20h]
__int64 v7; // [rsp+10h] [rbp-18h]
__int64 v8; // [rsp+18h] [rbp-10h]

v5 = 0LL;
v6 = 0LL;
v7 = 0LL;
v8 = 0LL;
if ( (unsigned int)parse_args(argc, (__int64)argv, (__int64)&v5) )
return -1;
v3 = 0;
puts("test info:");
printf("\tfile_path=%s\n", v5);
printf("\tkeep=%d\n", (unsigned int)v6);
printf("\toffset=%lld\n", v7);
printf("\tlength=%lld\n", v8);
test((__int64)&v5);
return v3;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // ebx
const char *v5; // [rsp+0h] [rbp-28h] BYREF
__int64 v6; // [rsp+8h] [rbp-20h]
__int64 v7; // [rsp+10h] [rbp-18h]
__int64 v8; // [rsp+18h] [rbp-10h]

v5 = 0LL;
v6 = 0LL;
v7 = 0LL;
v8 = 0LL;
if ( (unsigned int)func10(argc, (__int64)argv, (__int64)&v5) )
return -1;
v3 = 0;
puts("test info:");
printf("\tfile_path=%s\n", v5);
printf("\tkeep=%d\n", (unsigned int)v6);
printf("\toffset=%lld\n", v7);
printf("\tlength=%lld\n", v8);
func9((__int64)&v5);
return v3;
}

original_code:
int main(int argc, char *argv[])
{
 struct options opts = {0};
 if (parse_args(argc, argv, &opts))
  return -1;
 printf("test info:\n");
 printf("\tfile_path=%s\n", opts.file_path);
 printf("\tkeep=%d\n", opts.keep);
 printf("\toffset=%lld\n", opts.off);
 printf("\tlength=%lld\n", opts.len);
 test(&opts);
 return 0;
}

variable_types: struct options { char *file_path; int keep; long off; long len; }


decompiled_code:
int test_string_array()
{
printf("%s\t", "sd");
printf("%s\t", "ssd");
printf("%s\t", "hd");
putchar(10);
printf("%s\t", "md");
printf("%s\t", "dm");
putchar(10);
return printf("%llu\n", -1LL);
}

canonical_decompiled_code:
int func7()
{
printf("%s\t", "sd");
printf("%s\t", "ssd");
printf("%s\t", "hd");
putchar(10);
printf("%s\t", "md");
printf("%s\t", "dm");
putchar(10);
return printf("%llu\n", -1LL);
}

original_code:
void test_string_array(void)
{
 int i, j;
 for (i=0; i<2; i++) {
  for (j=0; j<3; j++) {
   if (bwlc_scan_keyword[i][j] != ((void *)0))
    printf("%s\t", bwlc_scan_keyword[i][j]);
  }
  printf("\n");
 }
 printf("%llu\n", (uint64_t)-1);
 return ;
}

canonical_original_code:
void test_string_array()
{
 int i; int j;
 for (i=0; i<2; i++) {
  for (j=0; j<3; j++) {
   if (bwlc_scan_keyword[i][j] != ((void *)0))
    printf("%s\t", bwlc_scan_keyword[i][j]);
  }
  printf("\n");
 }
 printf("%llu\n", (unsigned long)-1);
 return ;
}

variable_types: j int


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
printf("block:%s\n", "block/sda");
printf("first '/:'%s\n", "/sda");
printf("last '/':%s\n", "/sda");
printf("find device:%s\n", "sda");
test_string_array();
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
printf("block:%s\n", "block/sda");
printf("first '/:'%s\n", "/sda");
printf("last '/':%s\n", "/sda");
printf("find device:%s\n", "sda");
func7();
return 0;
}

original_code:
int main(int argc, char *argv[])
{
 char *source = "/sys/devices/pci0000:00/0000:00:07.1/host0/target0:0:0/0:0:0:0/block/sda";
 char *block = ((void *)0);
 char *first = ((void *)0);
 char *last = ((void *)0);
 block = strstr(source, "block");
 if (!block)
  goto out;
 printf("block:%s\n", block);
 first = index(block, '/');
 if (!first)
  goto out;
 printf("first '/:'%s\n", first);
 last = rindex(block, '/');
 if (!last)
  goto out;
 printf("last '/':%s\n", last);
 if (first != last)
  goto out;
 printf("find device:%s\n", last+1);
 test_string_array();
out:
 return 0;
}

variable_types:
source
char *

variable_types:
block
char *

variable_types:
first
char *

variable_types:
last
char *


decompiled_code:
__int64 __fastcall bwlc_handle_dev_msg(const char **a1)
{
printf("recieve msg:type=%d,devpath=%s\n", *(unsigned int *)a1, a1[1]);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func7(const char **a1)
{
printf("recieve msg:type=%d,devpath=%s\n", *(unsigned int *)a1, a1[1]);
return 0LL;
}

original_code:
int32_t bwlc_handle_dev_msg(bwlc_devent_msg_t *devent)
{
 printf("recieve msg:type=%d,devpath=%s\n", devent->event_type, devent->dev_path);
 return 0;
}

canonical_original_code:
int bwlc_handle_dev_msg(struct _bwlc_devent_msg *devent)
{
 printf("recieve msg:type=%d,devpath=%s\n", devent->event_type, devent->dev_path);
 return 0;
}

variable_types: struct _bwlc_devent_msg { enum _bwlc_devent_type { BWLC_DEV_ARRIVE=1, BWLC_DEV_REMOVE=2 } event_type; char *dev_path; } *

user_defined_types: struct _bwlc_devent_msg { enum _bwlc_devent_type event_type; char *dev_path; }


decompiled_code:
__int64 __fastcall bwlc_netlink_init(struct sockaddr **a1, int a2)
{
int v2; // eax
unsigned int v3; // ebx
struct sockaddr *v4; // rax
struct sockaddr *v5; // rbp
int *v7; // rbp
char *v8; // rax
int *v9; // rbp
char *v10; // rax
int *v11; // rbp
char *v12; // rax
int *v13; // r12
char *v14; // rax
int optval[7]; // [rsp+Ch] [rbp-1Ch] BYREF

optval[0] = 4096;
v2 = socket(16, 2, a2);
v3 = v2;
if ( v2 == -1 )
{
v7 = __errno_location();
v8 = strerror(*v7);
printf("BWLC_NETLINK:Create socket fail. %d(%s)\n", (unsigned int)*v7, v8);
LABEL_8:
close(v3);
return (unsigned int)-1;
}
if ( setsockopt(v2, 1, 8, optval, 4u) < 0 )
{
v9 = __errno_location();
v10 = strerror(*v9);
printf("BWLC_NETLINK:Set socket opt fail. %d(%s)\n", (unsigned int)*v9, v10);
goto LABEL_10;
}
v4 = (struct sockaddr *)calloc(1uLL, 0xCuLL);
v5 = v4;
if ( !v4 )
{
v11 = __errno_location();
v12 = strerror(*v11);
printf("BWLC_NETLINK:Alloc mem for sockaddr fail. %d(%s)\n", (unsigned int)*v11, v12);
goto LABEL_10;
}
v4->sa_family = 16;
*(_DWORD *)&v4->sa_data[2] = getpid();
*(_DWORD *)&v5->sa_data[6] = 1;
if ( bind(v3, v5, 0xCu) )
{
v13 = __errno_location();
v14 = strerror(*v13);
printf("BWLC_NETLINK:Bind socket fail. %d(%s)\n", (unsigned int)*v13, v14);
free(v5);
LABEL_10:
if ( !v3 )
return (unsigned int)-1;
goto LABEL_8;
}
*a1 = v5;
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func8(struct sockaddr **a1, int a2)
{
int v2; // eax
unsigned int v3; // ebx
struct sockaddr *v4; // rax
struct sockaddr *v5; // rbp
int *v7; // rbp
char *v8; // rax
int *v9; // rbp
char *v10; // rax
int *v11; // rbp
char *v12; // rax
int *v13; // r12
char *v14; // rax
int optval[7]; // [rsp+Ch] [rbp-1Ch] BYREF

optval[0] = 4096;
v2 = socket(16, 2, a2);
v3 = v2;
if ( v2 == -1 )
{
v7 = __errno_location();
v8 = strerror(*v7);
printf("BWLC_NETLINK:Create socket fail. %d(%s)\n", (unsigned int)*v7, v8);
LABEL_8:
close(v3);
return (unsigned int)-1;
}
if ( setsockopt(v2, 1, 8, optval, 4u) < 0 )
{
v9 = __errno_location();
v10 = strerror(*v9);
printf("BWLC_NETLINK:Set socket opt fail. %d(%s)\n", (unsigned int)*v9, v10);
goto LABEL_10;
}
v4 = (struct sockaddr *)calloc(1uLL, 0xCuLL);
v5 = v4;
if ( !v4 )
{
v11 = __errno_location();
v12 = strerror(*v11);
printf("BWLC_NETLINK:Alloc mem for sockaddr fail. %d(%s)\n", (unsigned int)*v11, v12);
goto LABEL_10;
}
v4->sa_family = 16;
*(_DWORD *)&v4->sa_data[2] = getpid();
*(_DWORD *)&v5->sa_data[6] = 1;
if ( bind(v3, v5, 0xCu) )
{
v13 = __errno_location();
v14 = strerror(*v13);
printf("BWLC_NETLINK:Bind socket fail. %d(%s)\n", (unsigned int)*v13, v14);
free(v5);
LABEL_10:
if ( !v3 )
return (unsigned int)-1;
goto LABEL_8;
}
*a1 = v5;
return v3;
}

original_code:
int bwlc_netlink_init(struct sockaddr_nl **nl_saddr, int nl)
{
 int sock = -1, ret;
 int rcvbufsz = 4096;
 struct sockaddr_nl *saddr = ((void *)0);
 sock = socket(16, SOCK_DGRAM, nl);
 if (sock == -1) {
  printf("BWLC_NETLINK:Create socket fail. %d(%s)\n",
     (*__errno_location ()), strerror((*__errno_location ())));
  goto failed;
 }
 ret = setsockopt(sock, 1, 8, &rcvbufsz,
       sizeof(rcvbufsz));
 if (ret < 0) {
  printf("BWLC_NETLINK:Set socket opt fail. %d(%s)\n",
     (*__errno_location ()), strerror((*__errno_location ())));
  goto failed;
 }
 saddr = calloc(1, sizeof(struct sockaddr_nl));
 if (!saddr){
  printf("BWLC_NETLINK:Alloc mem for sockaddr fail. %d(%s)\n",
     (*__errno_location ()), strerror((*__errno_location ())));
  goto failed;
 }
 saddr->nl_family = 16;
 saddr->nl_pid = getpid();
 if (nl == 0)
  saddr->nl_groups = RTNLGRP_LINK;
 else
  saddr->nl_groups = 0x1;
 ret = bind(sock, (struct sockaddr *)saddr, sizeof(struct sockaddr_nl));
 if (ret) {
  printf("BWLC_NETLINK:Bind socket fail. %d(%s)\n",
     (*__errno_location ()), strerror((*__errno_location ())));
  goto failed;
 }
 *nl_saddr = saddr;
 return sock;
failed:
 if (saddr)
  free(saddr);
 if (sock)
  close(sock);
 return -1;
}

canonical_original_code:
int bwlc_netlink_init(struct sockaddr_nl **nl_saddr, int nl)
{
 int sock = -1; int ret;
 int rcvbufsz = 4096;
 struct sockaddr_nl *saddr = ((void *)0);
 sock = socket(16, SOCK_DGRAM, nl);
 if (sock == -1) {
  printf("BWLC_NETLINK:Create socket fail. %d(%s)\n",
     (*__errno_location ()), strerror((*__errno_location ())));
  goto failed;
 }
 ret = setsockopt(sock, 1, 8, &rcvbufsz,
       sizeof(rcvbufsz));
 if (ret < 0) {
  printf("BWLC_NETLINK:Set socket opt fail. %d(%s)\n",
     (*__errno_location ()), strerror((*__errno_location ())));
  goto failed;
 }
 saddr = calloc(1, sizeof(struct sockaddr_nl));
 if (!saddr){
  printf("BWLC_NETLINK:Alloc mem for sockaddr fail. %d(%s)\n",
     (*__errno_location ()), strerror((*__errno_location ())));
  goto failed;
 }
 saddr->nl_family = 16;
 saddr->nl_pid = getpid();
 if (nl == 0)
  saddr->nl_groups = RTNLGRP_LINK;
 else
  saddr->nl_groups = 0x1;
 ret = bind(sock, (struct sockaddr *)saddr, sizeof(struct sockaddr_nl));
 if (ret) {
  printf("BWLC_NETLINK:Bind socket fail. %d(%s)\n",
     (*__errno_location ()), strerror((*__errno_location ())));
  goto failed;
 }
 *nl_saddr = saddr;
 return sock;
failed:
 if (saddr)
  free(saddr);
 if (sock)
  close(sock);
 return -1;
}

variable_types: struct sockaddr_nl { unsigned short nl_family; unsigned short nl_pad; unsigned int nl_pid; unsigned int nl_groups; } **

variable_types: nl int

variable_types: sock int

variable_types: ret int

variable_types: rcvbufsz int

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


decompiled_code:
__int64 __fastcall bwlc_netlink_recv(int a1, void *a2, size_t a3)
{
ssize_t v3; // rax
__int64 result; // rax
int *v5; // rbx
char *v6; // rax

v3 = recv(a1, a2, a3, 0);
if ( v3 )
{
if ( v3 < 0 )
{
v5 = __errno_location();
v6 = strerror(*v5);
printf("BWLC_NETLINK:Recv error. %d(%s)\n", (unsigned int)*v5, v6);
result = 0xFFFFFFFFLL;
}
else
{
result = 0LL;
}
}
else
{
puts("BWLC_NETLINK:Peer shutdown while recv.");
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(int a1, void *a2, size_t a3)
{
ssize_t v3; // rax
__int64 result; // rax
int *v5; // rbx
char *v6; // rax

v3 = recv(a1, a2, a3, 0);
if ( v3 )
{
if ( v3 < 0 )
{
v5 = __errno_location();
v6 = strerror(*v5);
printf("BWLC_NETLINK:Recv error. %d(%s)\n", (unsigned int)*v5, v6);
result = 0xFFFFFFFFLL;
}
else
{
result = 0LL;
}
}
else
{
puts("BWLC_NETLINK:Peer shutdown while recv.");
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
int bwlc_netlink_recv(int sock, char *buf, size_t len)
{
 ssize_t ret;
 ret = recv(sock, buf, len, 0);
 if (ret == 0) {
  printf("BWLC_NETLINK:Peer shutdown while recv.\n");
  goto failed;
 } else if (ret < 0) {
  printf("BWLC_NETLINK:Recv error. %d(%s)\n", (*__errno_location ()), strerror((*__errno_location ())));
  goto failed;
 }
 return 0;
failed:
 return -1;
}

canonical_original_code:
int bwlc_netlink_recv(int sock, char *buf, unsigned long len)
{
 long ret;
 ret = recv(sock, buf, len, 0);
 if (ret == 0) {
  printf("BWLC_NETLINK:Peer shutdown while recv.\n");
  goto failed;
 } else if (ret < 0) {
  printf("BWLC_NETLINK:Recv error. %d(%s)\n", (*__errno_location ()), strerror((*__errno_location ())));
  goto failed;
 }
 return 0;
failed:
 return -1;
}

variable_types:
len
unsigned long

variable_types: ret long


decompiled_code:
__int64 __fastcall bwlc_uevent_handler(int a1, const char *a2)
{
const char *v2; // rbx
size_t v3; // rax
unsigned int v4; // er12
_DWORD *v5; // rax
_DWORD *v6; // rbx
size_t v7; // rax
char *v8; // rdi

v2 = (&bwlc_scan_keyword)[g_scan_set];
v3 = strlen(v2);
if ( !strncmp(a2, v2, v3) )
{
v4 = 0;
v5 = calloc(1uLL, 0x10uLL);
v6 = v5;
if ( v5 )
{
*v5 = a1;
v7 = strlen(a2);
v8 = (char *)calloc(1uLL, v7 + 10);
*((_QWORD *)v6 + 1) = v8;
if ( v8 )
{
sprintf(v8, "/dev/%s", a2);
bwlc_handle_dev_msg((const char **)v6);
}
else
{
puts("BWLC_UEVENT:Can not alloc mem for dev_path.");
free(v6);
v4 = -1;
}
}
else
{
puts("BWLC_UEVENT:Can not alloc mem for event msg.");
v4 = -1;
}
}
else
{
printf("BWLC_UEVENT: %s is not in scan set.\n", a2);
v4 = -1;
}
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func11(int a1, const char *a2)
{
const char *v2; // rbx
size_t v3; // rax
unsigned int v4; // er12
_DWORD *v5; // rax
_DWORD *v6; // rbx
size_t v7; // rax
char *v8; // rdi

v2 = (&bwlc_scan_keyword)[g_scan_set];
v3 = strlen(v2);
if ( !strncmp(a2, v2, v3) )
{
v4 = 0;
v5 = calloc(1uLL, 0x10uLL);
v6 = v5;
if ( v5 )
{
*v5 = a1;
v7 = strlen(a2);
v8 = (char *)calloc(1uLL, v7 + 10);
*((_QWORD *)v6 + 1) = v8;
if ( v8 )
{
sprintf(v8, "/dev/%s", a2);
func7((const char **)v6);
}
else
{
puts("BWLC_UEVENT:Can not alloc mem for dev_path.");
free(v6);
v4 = -1;
}
}
else
{
puts("BWLC_UEVENT:Can not alloc mem for event msg.");
v4 = -1;
}
}
else
{
printf("BWLC_UEVENT: %s is not in scan set.\n", a2);
v4 = -1;
}
return v4;
}

original_code:
int32_t bwlc_uevent_handler(bwlc_devent_type_t event_type, char *dev_name)
{
 int32_t ret = 0;
 bwlc_devent_msg_t *devent = ((void *)0);
 if (strncmp(dev_name, bwlc_scan_keyword[g_scan_set],
   strlen(bwlc_scan_keyword[g_scan_set])) != 0) {
  printf("BWLC_UEVENT: %s is not in scan set.\n", dev_name);
  goto failed;
 }
 devent = calloc(1, sizeof(bwlc_devent_msg_t));
 if (!devent) {
  printf("BWLC_UEVENT:Can not alloc mem for event msg.\n");
  goto failed;
 }
 devent->event_type = event_type;
 devent->dev_path = calloc(1, strlen(dev_name)+10);
 if (!devent->dev_path) {
  printf("BWLC_UEVENT:Can not alloc mem for dev_path.\n");
  goto failed;
 }
 sprintf(devent->dev_path, "/dev/%s", dev_name);
 bwlc_handle_dev_msg(devent);
 return ret;
failed:
 if (devent)
  free(devent);
 return -1;
}

canonical_original_code:
int bwlc_uevent_handler(enum _bwlc_devent_type event_type, char *dev_name)
{
 int ret = 0;
 struct _bwlc_devent_msg *devent = ((void *)0);
 if (strncmp(dev_name, bwlc_scan_keyword[g_scan_set],
   strlen(bwlc_scan_keyword[g_scan_set])) != 0) {
  printf("BWLC_UEVENT: %s is not in scan set.\n", dev_name);
  goto failed;
 }
 devent = calloc(1, sizeof(bwlc_devent_msg_t));
 if (!devent) {
  printf("BWLC_UEVENT:Can not alloc mem for event msg.\n");
  goto failed;
 }
 devent->event_type = event_type;
 devent->dev_path = calloc(1, strlen(dev_name)+10);
 if (!devent->dev_path) {
  printf("BWLC_UEVENT:Can not alloc mem for dev_path.\n");
  goto failed;
 }
 sprintf(devent->dev_path, "/dev/%s", dev_name);
 bwlc_handle_dev_msg(devent);
 return ret;
failed:
 if (devent)
  free(devent);
 return -1;
}

variable_types: enum _bwlc_devent_type { BWLC_DEV_ARRIVE=1, BWLC_DEV_REMOVE=2 }


decompiled_code:
void __fastcall __noreturn bwlc_uevent_reciever(void *a1)
{
void *v1; // rbp
int v2; // ebx
char *v3; // [rsp+8h] [rbp-30h] BYREF
int v4; // [rsp+14h] [rbp-24h] BYREF
struct sockaddr *v5; // [rsp+18h] [rbp-20h] BYREF

v1 = calloc(1uLL, 0x1000uLL);
v2 = -1;
while ( 1 )
{
if ( v2 == -1 )
{
LABEL_3:
puts("BWLC_UEVENT:Init netlink.");
v2 = bwlc_netlink_init(&v5, 15);
if ( v2 != -1 )
goto LABEL_6;
puts("BWLC_UEVENT:Init netlink failed, sleep & retry.");
sleep(1u);
}
else
{
LABEL_6:
memset(v1, 0, 0x1000uLL);
if ( (int)bwlc_netlink_recv(v2, v1, 0x1000uLL) < 0 )
{
puts("BWLC_UEVENT:Recv error reinitial usock.");
goto LABEL_3;
}
if ( (unsigned int)_bwlc_uevent_parse((char *)v1, &v3, &v4) )
{
printf("BWLC_UEVENT:DEBUG:uevent msg:%s\n", (const char *)v1);
bwlc_uevent_handler(v4, v3);
}
}
}
}

canonical_decompiled_code:
void __fastcall __noreturn func12(void *a1)
{
void *v1; // rbp
int v2; // ebx
char *v3; // [rsp+8h] [rbp-30h] BYREF
int v4; // [rsp+14h] [rbp-24h] BYREF
struct sockaddr *v5; // [rsp+18h] [rbp-20h] BYREF

v1 = calloc(1uLL, 0x1000uLL);
v2 = -1;
while ( 1 )
{
if ( v2 == -1 )
{
LABEL_3:
puts("BWLC_UEVENT:Init netlink.");
v2 = func8(&v5, 15);
if ( v2 != -1 )
goto LABEL_6;
puts("BWLC_UEVENT:Init netlink failed, sleep & retry.");
sleep(1u);
}
else
{
LABEL_6:
memset(v1, 0, 0x1000uLL);
if ( (int)func9(v2, v1, 0x1000uLL) < 0 )
{
puts("BWLC_UEVENT:Recv error reinitial usock.");
goto LABEL_3;
}
if ( (unsigned int)func10((char *)v1, &v3, &v4) )
{
printf("BWLC_UEVENT:DEBUG:uevent msg:%s\n", (const char *)v1);
func11(v4, v3);
}
}
}
}

original_code:
void *bwlc_uevent_reciever(void *unused)
{
 int usock = -1, ret;
 struct sockaddr_nl *nl_addr;
 bwlc_devent_type_t event_type;
 char *dev_name;
 char *uevent_buf = ((void *)0);
 uevent_buf = calloc(1, 4096);
 while (1) {
  if (usock == -1) {
   printf("BWLC_UEVENT:Init netlink.\n");
   usock = bwlc_netlink_init(&nl_addr, 15);
  }
  if (usock == -1) {
   printf("BWLC_UEVENT:Init netlink failed, sleep & retry.\n");
   sleep(1);
   continue;
  }
  memset(uevent_buf, 0, 4096);
  ret = bwlc_netlink_recv(usock, uevent_buf, 4096);
  if (ret < 0) {
   printf("BWLC_UEVENT:Recv error reinitial usock.\n");
   usock = -1;
   continue;
  }
  if (!__bwlc_uevent_parse(uevent_buf, &dev_name, &event_type))
   continue;
  printf("BWLC_UEVENT:DEBUG:uevent msg:%s\n", uevent_buf);
  bwlc_uevent_handler(event_type, dev_name);
 }
}

canonical_original_code:
void *bwlc_uevent_reciever(void *unused)
{
 int usock = -1; int ret;
 struct sockaddr_nl *nl_addr;
 enum _bwlc_devent_type event_type;
 char *dev_name;
 char *uevent_buf = ((void *)0);
 uevent_buf = calloc(1, 4096);
 while (1) {
  if (usock == -1) {
   printf("BWLC_UEVENT:Init netlink.\n");
   usock = bwlc_netlink_init(&nl_addr, 15);
  }
  if (usock == -1) {
   printf("BWLC_UEVENT:Init netlink failed, sleep & retry.\n");
   sleep(1);
   continue;
  }
  memset(uevent_buf, 0, 4096);
  ret = bwlc_netlink_recv(usock, uevent_buf, 4096);
  if (ret < 0) {
   printf("BWLC_UEVENT:Recv error reinitial usock.\n");
   usock = -1;
   continue;
  }
  if (!__bwlc_uevent_parse(uevent_buf, &dev_name, &event_type))
   continue;
  printf("BWLC_UEVENT:DEBUG:uevent msg:%s\n", uevent_buf);
  bwlc_uevent_handler(event_type, dev_name);
 }
}

variable_types:
unused
void *

variable_types: usock int

variable_types: struct sockaddr_nl { unsigned short nl_family; unsigned short nl_pad; unsigned int nl_pid; unsigned int nl_groups; } *

return_type: void *

user_defined_types: enum _bwlc_devent_type { BWLC_DEV_ARRIVE=1, BWLC_DEV_REMOVE=2 }


decompiled_code:
__int64 __fastcall bwlc_uevent_init(unsigned int a1)
{
int v1; // eax
unsigned int v2; // ebx
char *v4; // rax
pthread_t newthread[2]; // [rsp+8h] [rbp-10h] BYREF

if ( a1 > 1 )
{
printf("BWLC_UEVENT:Unkown scan set %d\n", a1);
v2 = 0;
}
else
{
g_scan_set = a1;
v1 = pthread_create(newthread, 0LL, (void *(*)(void *))bwlc_uevent_reciever, 0LL);
v2 = v1;
if ( v1 )
{
v4 = strerror(v1);
printf("BWLC_UEVENT:Create thread error.%d(%s)\n", v2, v4);
v2 = -1;
}
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func13(unsigned int a1)
{
int v1; // eax
unsigned int v2; // ebx
char *v4; // rax
pthread_t newthread[2]; // [rsp+8h] [rbp-10h] BYREF

if ( a1 > 1 )
{
printf("BWLC_UEVENT:Unkown scan set %d\n", a1);
v2 = 0;
}
else
{
g_scan_set = a1;
v1 = pthread_create(newthread, 0LL, (void *(*)(void *))bwlc_uevent_reciever, 0LL);
v2 = v1;
if ( v1 )
{
v4 = strerror(v1);
printf("BWLC_UEVENT:Create thread error.%d(%s)\n", v2, v4);
v2 = -1;
}
}
return v2;
}

original_code:
int32_t bwlc_uevent_init(bwlc_scan_set_t scan_set)
{
 pthread_t pd;
 int32_t bwret = 0;
 int ret;
 if (scan_set < 0 || scan_set >= BWLC_SCAN_MAX) {
  printf("BWLC_UEVENT:Unkown scan set %d\n", scan_set);
  goto failed;
 }
 g_scan_set = scan_set;
 ret = pthread_create(&pd, ((void *)0), bwlc_uevent_reciever, ((void *)0));
 if (ret) {
  printf("BWLC_UEVENT:Create thread error.%d(%s)\n",
    ret, strerror(ret));
  bwret = -1;
  goto failed;
 }
failed:
 return bwret;
}

canonical_original_code:
int bwlc_uevent_init(enum _bwlc_scan_set scan_set)
{
 unsigned long pd;
 int bwret = 0;
 int ret;
 if (scan_set < 0 || scan_set >= BWLC_SCAN_MAX) {
  printf("BWLC_UEVENT:Unkown scan set %d\n", scan_set);
  goto failed;
 }
 g_scan_set = scan_set;
 ret = pthread_create(&pd, ((void *)0), bwlc_uevent_reciever, ((void *)0));
 if (ret) {
  printf("BWLC_UEVENT:Create thread error.%d(%s)\n",
    ret, strerror(ret));
  bwret = -1;
  goto failed;
 }
failed:
 return bwret;
}

variable_types: enum _bwlc_scan_set { BWLC_SCAN_NORMAL=0, BWLC_SCAN_MULTIPATH=1, BWLC_SCAN_MAX=2 }

variable_types:
pd
unsigned long

variable_types: bwret int


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
if ( !(unsigned int)bwlc_uevent_init(0LL, argv, envp) )
{
while ( 1 )
sleep(1u);
}
puts("init bwlc_event failed.");
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
if ( !(unsigned int)func13(0LL, argv, envp) )
{
while ( 1 )
sleep(1u);
}
puts("init bwlc_event failed.");
return 0;
}

original_code:
int main(int argc, char *argv[])
{
 int32_t ret;
 ret = bwlc_uevent_init(BWLC_SCAN_NORMAL);
 if (ret) {
  printf("init bwlc_event failed.\n");
  goto failed;
 }
 while (1)
  sleep(1);
failed:
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
 int ret;
 ret = bwlc_uevent_init(BWLC_SCAN_NORMAL);
 if (ret) {
  printf("init bwlc_event failed.\n");
  goto failed;
 }
 while (1)
  sleep(1);
failed:
 return 0;
}

variable_types: argc int

variable_types:
argv
char *[]


func

decompiled_code:
int __fastcall func(const void **a1)
{
return printf("p=%p\n", *a1);
}

canonical_decompiled_code:
int __fastcall func8(const void **a1)
{
return printf("p=%p\n", *a1);
}

original_code:
void func(int **pp)
{
 int *p = *pp;
 printf("p=%p\n", p);
 p++;
}

variable_types:
pp
int **

variable_types:
p
int *


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const void *v4[2]; // [rsp+8h] [rbp-10h] BYREF

v4[0] = calloc(0xAuLL, 4uLL);
printf("p=%p address of p %p\n", v4[0], v4);
func(v4);
printf("p=%p address of p %p\n", v4[0], v4);
printf("i=%d\n", 0LL);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const void *v4[2]; // [rsp+8h] [rbp-10h] BYREF

v4[0] = calloc(0xAuLL, 4uLL);
printf("p=%p address of p %p\n", v4[0], v4);
func8(v4);
printf("p=%p address of p %p\n", v4[0], v4);
printf("i=%d\n", 0LL);
return 0;
}

original_code:
int main(int argc, char* argv[])
{
 int *p = ((void *)0);
 int i;
 p = calloc(10, sizeof(int));
 printf("p=%p address of p %p\n", p, &p);
 func(&p);
 printf("p=%p address of p %p\n", p, &p);
 for (i = 0; i != 1; i++)
  printf("i=%d\n", i);
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
 int *p = ((void *)0);
 int i;
 p = calloc(10, sizeof(int));
 printf("p=%p address of p %p\n", p, &p);
 func(&p);
 printf("p=%p address of p %p\n", p, &p);
 for (i = 0; i != 1; i++)
  printf("i=%d\n", i);
 return 0;
}

variable_types: i int


decompiled_code:
__int64 __fastcall getsockopt_sndbuf(int fd)
{
unsigned int *v1; // rax
unsigned int *v2; // rbx
__int64 result; // rax
int *v4; // rbx
char *v5; // rax
int *v6; // rbx
char *v7; // rax
socklen_t optlen[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v1 = (unsigned int *)calloc(1uLL, 0x80uLL);
optlen[0] = 128;
if ( v1 )
{
v2 = v1;
if ( getsockopt(fd, 1, 7, v1, optlen) < 0 )
{
printf("can't get sockopt!");
v6 = __errno_location();
v7 = strerror(*v6);
printf(" errno:%d(%s)\n", (unsigned int)*v6, v7);
result = 0xFFFFFFFFLL;
}
else
{
printf("SNDBUF:%d\n", *v2);
free(v2);
result = 0LL;
}
}
else
{
printf("can't alloc sockopt buffer!");
v4 = __errno_location();
v5 = strerror(*v4);
printf(" errno:%d(%s)\n", (unsigned int)*v4, v5);
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(int fd)
{
unsigned int *v1; // rax
unsigned int *v2; // rbx
__int64 result; // rax
int *v4; // rbx
char *v5; // rax
int *v6; // rbx
char *v7; // rax
socklen_t optlen[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v1 = (unsigned int *)calloc(1uLL, 0x80uLL);
optlen[0] = 128;
if ( v1 )
{
v2 = v1;
if ( getsockopt(fd, 1, 7, v1, optlen) < 0 )
{
printf("can't get sockopt!");
v6 = __errno_location();
v7 = strerror(*v6);
printf(" errno:%d(%s)\n", (unsigned int)*v6, v7);
result = 0xFFFFFFFFLL;
}
else
{
printf("SNDBUF:%d\n", *v2);
free(v2);
result = 0LL;
}
}
else
{
printf("can't alloc sockopt buffer!");
v4 = __errno_location();
v5 = strerror(*v4);
printf(" errno:%d(%s)\n", (unsigned int)*v4, v5);
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
int getsockopt_sndbuf(int fd, int package_id)
{
 char *buf;
 int *sockopt_buflen;
 socklen_t buf_len;
 buf = calloc (1, 128);
 buf_len = 128;
 if (!buf)
  do { do { printf("can't alloc sockopt buffer!"); printf(" errno:%d(%s)\n", (*__errno_location ()), strerror((*__errno_location ()))); } while(0); return -1;} while (0);
 if (getsockopt(fd, 1, 7, buf, &buf_len) < 0)
  do { do { printf("can't get sockopt!"); printf(" errno:%d(%s)\n", (*__errno_location ()), strerror((*__errno_location ()))); } while(0); return -1;} while (0);
 sockopt_buflen = (int *)buf;
 printf("SNDBUF:%d\n", (*sockopt_buflen));
 free(buf);
 return 0;
}

canonical_original_code:
int getsockopt_sndbuf(int fd, int package_id)
{
 char *buf;
 int *sockopt_buflen;
 unsigned int buf_len;
 buf = calloc (1, 128);
 buf_len = 128;
 if (!buf)
  do { do { printf("can't alloc sockopt buffer!"); printf(" errno:%d(%s)\n", (*__errno_location ()), strerror((*__errno_location ()))); } while(0); return -1;} while (0);
 if (getsockopt(fd, 1, 7, buf, &buf_len) < 0)
  do { do { printf("can't get sockopt!"); printf(" errno:%d(%s)\n", (*__errno_location ()), strerror((*__errno_location ()))); } while(0); return -1;} while (0);
 sockopt_buflen = (int *)buf;
 printf("SNDBUF:%d\n", (*sockopt_buflen));
 free(buf);
 return 0;
}

variable_types: fd int

variable_types:
buf
char *


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
void *v3; // r12
int v4; // eax
int v5; // ebp
int i; // ebx
size_t v7; // rax
int result; // eax
int *v9; // rbx
char *v10; // rax
int *v11; // rbx
char *v12; // rax
int *v13; // rbx
char *v14; // rax
int *v15; // rbx
char *v16; // rax
int *v17; // rbx
char *v18; // rax
char s[8]; // [rsp+6h] [rbp-32h] BYREF
__int16 v20; // [rsp+Eh] [rbp-2Ah]
struct sockaddr inp[2]; // [rsp+10h] [rbp-28h] BYREF

*(_QWORD *)s = 0x6F6C6C6568LL;
v20 = 0;
if ( argc <= 1 )
{
puts("please input ip ");
exit(1);
}
v3 = calloc(1uLL, 0xA000uLL);
if ( v3 )
{
v4 = socket(2, 1, 0);
v5 = v4;
if ( v4 < 0 )
{
printf("socket create error!");
v11 = __errno_location();
v12 = strerror(*v11);
printf(" errno:%d(%s)\n", (unsigned int)*v11, v12);
result = -1;
}
else
{
getsockopt_sndbuf(v4);
*(_QWORD *)&inp[0].sa_family = 0LL;
*(_QWORD *)&inp[0].sa_data[6] = 0LL;
inet_aton(argv[1], (struct in_addr *)&inp[0].sa_data[2]);
inp[0].sa_family = 2;
*(_WORD *)inp[0].sa_data = _bswap_16(30001);
if ( connect(v5, inp, 0x10u) < 0 )
{
printf("can't connect to server!");
v13 = __errno_location();
v14 = strerror(*v13);
printf(" errno:%d(%s)\n", (unsigned int)*v13, v14);
result = -1;
}
else
{
getsockopt_sndbuf(v5);
for ( i = 0; i != 10; ++i )
{
if ( send(v5, v3, 0xA000uLL, 64) < 0 )
{
printf("can't send msg!");
v15 = __errno_location();
v16 = strerror(*v15);
printf(" errno:%d(%s)\n", (unsigned int)*v15, v16);
return -1;
}
getsockopt_sndbuf(v5);
}
v7 = strlen(s);
if ( send(v5, s, v7, 0) < 0 )
{
printf("can't send msg!");
v17 = __errno_location();
v18 = strerror(*v17);
printf(" errno:%d(%s)\n", (unsigned int)*v17, v18);
result = -1;
}
else
{
getsockopt_sndbuf(v5);
close(v5);
result = 0;
}
}
}
}
else
{
printf("can't alloc send buffer!");
v9 = __errno_location();
v10 = strerror(*v9);
printf(" errno:%d(%s)\n", (unsigned int)*v9, v10);
result = -1;
}
return result;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
void *v3; // r12
int v4; // eax
int v5; // ebp
int i; // ebx
size_t v7; // rax
int result; // eax
int *v9; // rbx
char *v10; // rax
int *v11; // rbx
char *v12; // rax
int *v13; // rbx
char *v14; // rax
int *v15; // rbx
char *v16; // rax
int *v17; // rbx
char *v18; // rax
char s[8]; // [rsp+6h] [rbp-32h] BYREF
__int16 v20; // [rsp+Eh] [rbp-2Ah]
struct sockaddr inp[2]; // [rsp+10h] [rbp-28h] BYREF

*(_QWORD *)s = 0x6F6C6C6568LL;
v20 = 0;
if ( argc <= 1 )
{
puts("please input ip ");
exit(1);
}
v3 = calloc(1uLL, 0xA000uLL);
if ( v3 )
{
v4 = socket(2, 1, 0);
v5 = v4;
if ( v4 < 0 )
{
printf("socket create error!");
v11 = __errno_location();
v12 = strerror(*v11);
printf(" errno:%d(%s)\n", (unsigned int)*v11, v12);
result = -1;
}
else
{
func8(v4);
*(_QWORD *)&inp[0].sa_family = 0LL;
*(_QWORD *)&inp[0].sa_data[6] = 0LL;
inet_aton(argv[1], (struct in_addr *)&inp[0].sa_data[2]);
inp[0].sa_family = 2;
*(_WORD *)inp[0].sa_data = func7(30001);
if ( connect(v5, inp, 0x10u) < 0 )
{
printf("can't connect to server!");
v13 = __errno_location();
v14 = strerror(*v13);
printf(" errno:%d(%s)\n", (unsigned int)*v13, v14);
result = -1;
}
else
{
func8(v5);
for ( i = 0; i != 10; ++i )
{
if ( send(v5, v3, 0xA000uLL, 64) < 0 )
{
printf("can't send msg!");
v15 = __errno_location();
v16 = strerror(*v15);
printf(" errno:%d(%s)\n", (unsigned int)*v15, v16);
return -1;
}
func8(v5);
}
v7 = strlen(s);
if ( send(v5, s, v7, 0) < 0 )
{
printf("can't send msg!");
v17 = __errno_location();
v18 = strerror(*v17);
printf(" errno:%d(%s)\n", (unsigned int)*v17, v18);
result = -1;
}
else
{
func8(v5);
close(v5);
result = 0;
}
}
}
}
else
{
printf("can't alloc send buffer!");
v9 = __errno_location();
v10 = strerror(*v9);
printf(" errno:%d(%s)\n", (unsigned int)*v9, v10);
result = -1;
}
return result;
}

original_code:
int main(int argc, char **argv)
{
 int servfd,ret = 1;
 struct sockaddr_in servaddr;
 socklen_t socklen = sizeof(servaddr);
 char *buf;
 char hello[10] = "hello";
 int i = -1;
 if (argc < 2)
 {
  printf ("please input ip \n");
  exit(1);
 }
 buf = calloc (1, 40960);
 if (!buf)
  do { do { printf("can't alloc send buffer!"); printf(" errno:%d(%s)\n", (*__errno_location ()), strerror((*__errno_location ()))); } while(0); return -1;} while (0);
 if ((servfd = socket(2,SOCK_STREAM,0)) < 0)
  do { do { printf("socket create error!"); printf(" errno:%d(%s)\n", (*__errno_location ()), strerror((*__errno_location ()))); } while(0); return -1;} while (0);
 getsockopt_sndbuf(servfd, i);
 bzero(&servaddr,sizeof(servaddr));
 inet_aton(argv[1],&servaddr.sin_addr);
 servaddr.sin_family = 2;
 servaddr.sin_port = htons(30001);
 if (connect(servfd,(struct sockaddr*)&servaddr, socklen) < 0)
  do { do { printf("can't connect to server!"); printf(" errno:%d(%s)\n", (*__errno_location ()), strerror((*__errno_location ()))); } while(0); return -1;} while (0);
 getsockopt_sndbuf(servfd, i);
 for (i = 0; i < 10; i++) {
  if (send(servfd, buf, 40960, MSG_DONTWAIT) < 0)
   do { do { printf("can't send msg!"); printf(" errno:%d(%s)\n", (*__errno_location ()), strerror((*__errno_location ()))); } while(0); return -1;} while (0);
  getsockopt_sndbuf(servfd, i);
 }
 if (send(servfd, hello, strlen(hello), 0) < 0)
  do { do { printf("can't send msg!"); printf(" errno:%d(%s)\n", (*__errno_location ()), strerror((*__errno_location ()))); } while(0); return -1;} while (0);
 getsockopt_sndbuf(servfd, i);
 close(servfd);
 return 0;
}

canonical_original_code:
int main(int argc, char **argv)
{
 int servfd; int ret = 1;
 struct sockaddr_in servaddr;
 unsigned int socklen = sizeof(servaddr);
 char *buf;
 char hello[10] = "hello";
 int i = -1;
 if (argc < 2)
 {
  printf ("please input ip \n");
  exit(1);
 }
 buf = calloc (1, 40960);
 if (!buf)
  do { do { printf("can't alloc send buffer!"); printf(" errno:%d(%s)\n", (*__errno_location ()), strerror((*__errno_location ()))); } while(0); return -1;} while (0);
 if ((servfd = socket(2,SOCK_STREAM,0)) < 0)
  do { do { printf("socket create error!"); printf(" errno:%d(%s)\n", (*__errno_location ()), strerror((*__errno_location ()))); } while(0); return -1;} while (0);
 getsockopt_sndbuf(servfd, i);
 bzero(&servaddr,sizeof(servaddr));
 inet_aton(argv[1],&servaddr.sin_addr);
 servaddr.sin_family = 2;
 servaddr.sin_port = htons(30001);
 if (connect(servfd,(struct sockaddr *)&servaddr, socklen) < 0)
  do { do { printf("can't connect to server!"); printf(" errno:%d(%s)\n", (*__errno_location ()), strerror((*__errno_location ()))); } while(0); return -1;} while (0);
 getsockopt_sndbuf(servfd, i);
 for (i = 0; i < 10; i++) {
  if (send(servfd, buf, 40960, MSG_DONTWAIT) < 0)
   do { do { printf("can't send msg!"); printf(" errno:%d(%s)\n", (*__errno_location ()), strerror((*__errno_location ()))); } while(0); return -1;} while (0);
  getsockopt_sndbuf(servfd, i);
 }
 if (send(servfd, hello, strlen(hello), 0) < 0)
  do { do { printf("can't send msg!"); printf(" errno:%d(%s)\n", (*__errno_location ()), strerror((*__errno_location ()))); } while(0); return -1;} while (0);
 getsockopt_sndbuf(servfd, i);
 close(servfd);
 return 0;
}

variable_types:
argv
char **

variable_types: servfd int

variable_types: ret int

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

variable_types:
socklen
unsigned int

variable_types:
hello
char [10]

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


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

v1 = *(_QWORD *)(a1 + 56);
if ( v1 )
result = 4 * (unsigned int)(*(_BYTE *)(v1 + 12) >> 4);
else
result = 0LL;
return result;
}

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

v1 = *(_QWORD *)(a1 + 56);
if ( v1 )
result = 4 * (unsigned int)(*(_BYTE *)(v1 + 12) >> 4);
else
result = 0LL;
return result;
}

original_code:
int
utcp_header_len(struct usk_buff *uskb)
{
 struct tcphdr *tcph;
 tcph = ((struct tcphdr *)(((uskb))->transport_header));
 if (!tcph)
  return 0;
 return (tcph->doff * 4);
}

variable_types: struct usk_buff { struct usk_buff *prev; struct usk_buff *next; unsigned char direct; void *header; void *payload; unsigned short header_len; void *network_header; void *transport_header; struct btqueue_node { struct btqueue_node *next; } q_send; struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr { unsigned int s_addr; } sin_addr; unsigned char sin_zero[-1]; } sin; struct uprotocol { void (*close)(struct usock { int usk_mode; struct usk_buff_head { struct usk_buff *prev; struct usk_buff *next; unsigned short qlen; 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; } loc; } *usk_write_queue; struct usk_buff_head *usk_receive_queue; } *sk, long timeout); int (*connect)(struct usock *sk, struct sockaddr_in *uaddr, int addr_len); int (*disconnect)(struct usock *sk, int flags); struct usock *(*accept)(struct usock *sk, int flags, int *err); int (*ioctl)(struct usock *sk, int cmd, unsigned long arg); int (*init)(struct usock *sk); void (*destroy)(struct usock *sk); void (*shutdown)(struct usock *sk, int how); int (*setsockopt)(struct usock *sk, int level, int optname, char *optval, int optlen); int (*getsockopt)(struct usock *sk, int level, int optname, char *optval, int *option); int (*bind)(struct usock *sk, struct sockaddr_in *uaddr, int addr_len); char name[32]; int proto_num; struct list_head { struct list_head *next; } node; int (*header_len)(struct usk_buff *uskb); int (*handler)(struct usk_buff *uskb); } *proto; } *

variable_types: struct tcphdr { union { struct { unsigned short th_sport; unsigned short th_dport; unsigned int th_seq; unsigned int th_ack; unsigned char th_x2; unsigned char th_off; unsigned char th_flags; unsigned short th_win; unsigned short th_sum; unsigned short th_urp; }; struct { unsigned short source; unsigned short dest; unsigned int seq; unsigned int ack_seq; unsigned short res1; unsigned short doff; unsigned short fin; unsigned short syn; unsigned short rst; unsigned short psh; unsigned short ack; unsigned short urg; unsigned short res2; unsigned short window; unsigned short check; unsigned short urg_ptr; }; }; } *

user_defined_types: struct usk_buff { struct usk_buff *prev; struct usk_buff *next; unsigned char direct; void *header; void *payload; unsigned short header_len; void *network_header; void *transport_header; struct btqueue_node q_send; struct sockaddr_in sin; struct uprotocol *proto; }

user_defined_types: struct uprotocol { void (*close)(struct usock *sk, long timeout); int (*connect)(struct usock *sk, struct sockaddr_in *uaddr, int addr_len); int (*disconnect)(struct usock *sk, int flags); struct usock *(*accept)(struct usock *sk, int flags, int *err); int (*ioctl)(struct usock *sk, int cmd, unsigned long arg); int (*init)(struct usock *sk); void (*destroy)(struct usock *sk); void (*shutdown)(struct usock *sk, int how); int (*setsockopt)(struct usock *sk, int level, int optname, char *optval, int optlen); int (*getsockopt)(struct usock *sk, int level, int optname, char *optval, int *option); int (*bind)(struct usock *sk, struct sockaddr_in *uaddr, int addr_len); char name[32]; int proto_num; struct list_head node; int (*header_len)(struct usk_buff *uskb); int (*handler)(struct usk_buff *uskb); }

user_defined_types: struct usock { int usk_mode; struct usk_buff_head *usk_write_queue; struct usk_buff_head *usk_receive_queue; }

user_defined_types: struct usk_buff_head { struct usk_buff *prev; struct usk_buff *next; unsigned short qlen; union pthread_mutex_t loc; }

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:
__int64 __fastcall utcp_handler(__int64 a1)
{
tcphdr_dump(*(_QWORD *)(a1 + 56));
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
tcphdr_dump(*(_QWORD *)(a1 + 56));
return 0LL;
}

original_code:
int
utcp_handler(struct usk_buff *uskb)
{
 struct tcphdr *tcph;
 tcph = ((struct tcphdr *)(((uskb))->transport_header));
 tcphdr_dump(tcph);
 return 0;
}

user_defined_types: struct tcphdr { union { struct { unsigned short th_sport; unsigned short th_dport; unsigned int th_seq; unsigned int th_ack; unsigned char th_x2; unsigned char th_off; unsigned char th_flags; unsigned short th_win; unsigned short th_sum; unsigned short th_urp; }; struct { unsigned short source; unsigned short dest; unsigned int seq; unsigned int ack_seq; unsigned short res1; unsigned short doff; unsigned short fin; unsigned short syn; unsigned short rst; unsigned short psh; unsigned short ack; unsigned short urg; unsigned short res2; unsigned short window; unsigned short check; unsigned short urg_ptr; }; }; }

user_defined_types: struct btqueue_node { struct btqueue_node *next; }

user_defined_types: struct list_head { struct list_head *next; }

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


decompiled_code:
__int64 utcp_init()
{
uprotocol_register(&utcp);
return 0LL;
}

canonical_decompiled_code:
__int64 func2()
{
uprotocol_register(&utcp);
return 0LL;
}

original_code:
int
utcp_init(void)
{
 uprotocol_register(&utcp);
 return 0;
}

canonical_original_code:
int utcp_init()
{
 uprotocol_register(&utcp);
 return 0;
}


decompiled_code:
int __fastcall iphdr_dump(__int64 a1)
{
puts("iphdr dump:");
printf("version:%u\n", *(_BYTE *)a1 >> 4);
printf("ihl:%u\n", *(_BYTE *)a1 & 0xF);
printf("tos:%u\n", *(unsigned __int8 *)(a1 + 1));
printf("tot_len:%u\n", *(unsigned __int16 *)(a1 + 2));
printf("id:%u\n", *(unsigned __int16 *)(a1 + 4));
printf("frag_off:%u\n", *(unsigned __int16 *)(a1 + 6));
printf("ttl:%u\n", *(unsigned __int8 *)(a1 + 8));
printf("protocol:%u\n", *(unsigned __int8 *)(a1 + 9));
printf("check:%u\n", *(unsigned __int16 *)(a1 + 10));
printf("saddr:%x\n", *(unsigned int *)(a1 + 12));
return printf("daddr:%x\n\n", *(unsigned int *)(a1 + 16));
}

canonical_decompiled_code:
int __fastcall func1(__int64 a1)
{
puts("iphdr dump:");
printf("version:%u\n", *(_BYTE *)a1 >> 4);
printf("ihl:%u\n", *(_BYTE *)a1 & 0xF);
printf("tos:%u\n", *(unsigned __int8 *)(a1 + 1));
printf("tot_len:%u\n", *(unsigned __int16 *)(a1 + 2));
printf("id:%u\n", *(unsigned __int16 *)(a1 + 4));
printf("frag_off:%u\n", *(unsigned __int16 *)(a1 + 6));
printf("ttl:%u\n", *(unsigned __int8 *)(a1 + 8));
printf("protocol:%u\n", *(unsigned __int8 *)(a1 + 9));
printf("check:%u\n", *(unsigned __int16 *)(a1 + 10));
printf("saddr:%x\n", *(unsigned int *)(a1 + 12));
return printf("daddr:%x\n\n", *(unsigned int *)(a1 + 16));
}

original_code:
void
iphdr_dump(struct iphdr *iph)
{
 printf("iphdr dump:\n");
 printf("version:%u\n", iph->version);
 printf("ihl:%u\n", iph->ihl);
 printf("tos:%u\n", iph->tos);
 printf("tot_len:%u\n", iph->tot_len);
 printf("id:%u\n", iph->id);
 printf("frag_off:%u\n", iph->frag_off);
 printf("ttl:%u\n", iph->ttl);
 printf("protocol:%u\n", iph->protocol);
 printf("check:%u\n", iph->check);
 printf("saddr:%x\n", iph->saddr);
 printf("daddr:%x\n\n", iph->daddr);
}

variable_types: struct iphdr { unsigned int ihl; unsigned int version; unsigned char tos; unsigned short tot_len; unsigned short id; unsigned short frag_off; unsigned char ttl; unsigned char protocol; unsigned short check; unsigned int saddr; unsigned int daddr; } *


original_code:
void
tcphdr_dump(struct tcphdr *tcph)
{
 printf("tcphdr dump\n");
 printf("source:%u\n", ntohs(tcph->source));
 printf("dest:%u\n", ntohs(tcph->dest));
 printf("seq:%u\n", tcph->seq);
 printf("ack_seq:%u\n", tcph->ack_seq);
 printf("doff:%u\n", tcph->doff);
 printf("fin:%u\n", tcph->fin);
 printf("syn:%u\n", tcph->syn);
 printf("rst:%u\n", tcph->rst);
 printf("psh:%u\n", tcph->psh);
 printf("ack:%u\n", tcph->ack);
 printf("urg:%u\n\n\n\n", tcph->urg);
}


decompiled_code:
_BOOL8 __fastcall is_zero(unsigned int a1)
{
printf("get %d\n", a1);
return a1 == 0;
}

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

original_code:
int is_zero(int i)
{
 printf("get %d\n", i);
 return i == 0;
}


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
puts("hello");
return 0;
}

original_code:
int main(int argc, char *argv[])
{
 if (0 == 0 || is_zero(1))
  printf("hello\n");
 return 0;
}


decompiled_code:
int test_long()
{
printf("ul=%lx\n", -1000LL);
return printf("p=%p\n", (const void *)0xFFFFFFFFFFFFFC18LL);
}

canonical_decompiled_code:
int func7()
{
printf("ul=%lx\n", -1000LL);
return printf("p=%p\n", (const void *)0xFFFFFFFFFFFFFC18LL);
}

original_code:
void test_long(void)
{
 long l;
 void *p;
 unsigned long ul;
 l = -1000;
 ul = l;
 printf("ul=%lx\n", ul);
 p = (void *)ul;
 printf("p=%p\n", p);
}

canonical_original_code:
void test_long()
{
 long l;
 void *p;
 unsigned long ul;
 l = -1000;
 ul = l;
 printf("ul=%lx\n", ul);
 p = (void *)ul;
 printf("p=%p\n", p);
}

variable_types: l long

variable_types:
p
void *

variable_types:
ul
unsigned long


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char s[10]; // [rsp+0h] [rbp-28h] BYREF
char v5[8]; // [rsp+Ah] [rbp-1Eh] BYREF

strcpy(s, "123456");
strcpy(v5, "abcdef");
puts(s);
puts(&s[1]);
test_long();
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char s[10]; // [rsp+0h] [rbp-28h] BYREF
char v5[8]; // [rsp+Ah] [rbp-1Eh] BYREF

strcpy(s, "123456");
strcpy(v5, "abcdef");
puts(s);
puts(&s[1]);
func7();
return 0;
}

original_code:
int
main(void)
{
 char *hello;
 int *i;
 struct node n[2];
 void *p;
 strcpy(n[0].hello, "123456");
 strcpy(n[1].hello, "abcdef");
 p = n;
 printf("%s\n", p);
 p +=1;
 printf("%s\n", p);
 i = p;
 test_long();
 return 0;
}

canonical_original_code:
int main()
{
 char *hello;
 int *i;
 struct node n[2];
 void *p;
 strcpy(n[0].hello, "123456");
 strcpy(n[1].hello, "abcdef");
 p = n;
 printf("%s\n", p);
 p +=1;
 printf("%s\n", p);
 i = p;
 test_long();
 return 0;
}

variable_types:
hello
char *

variable_types:
i
int *

variable_types:
n
struct node { char hello[10]; } [2]


decompiled_code:
int test_snprintf()
{
__int64 v1; // [rsp+6h] [rbp-12h] BYREF
__int16 v2; // [rsp+Eh] [rbp-Ah]

v1 = 0LL;
v2 = 0;
return printf("snprintf p_len=%d gen=%s\n", 0LL, (const char *)&v1);
}

canonical_decompiled_code:
int func7()
{
__int64 v1; // [rsp+6h] [rbp-12h] BYREF
__int16 v2; // [rsp+Eh] [rbp-Ah]

v1 = 0LL;
v2 = 0;
return printf("snprintf p_len=%d gen=%s\n", 0LL, (const char *)&v1);
}

original_code:
void test_snprintf(void)
{
 char buffer[10] = {0}, *p = ((void *)0);
 int tatal = 10, p_len;
 int i;
 p = buffer;
 p_len = snprintf(buffer, 2, "");
out:
 printf("snprintf p_len=%d gen=%s\n", p_len, buffer);
}

canonical_original_code:
void test_snprintf()
{
 char buffer[10] = {0}; char *p = ((void *)0);
 int tatal = 10; int p_len;
 int i;
 p = buffer;
 p_len = snprintf(buffer, 2, "");
out:
 printf("snprintf p_len=%d gen=%s\n", p_len, buffer);
}

variable_types:
buffer
char [10]

variable_types:
p
char *

variable_types: tatal int

variable_types: i int


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rcx

printf("%u, %u, %u\n", 1LL, 2LL, v3);
printf("%u, %u\n", 4LL, 8LL);
printf("a=%llu\n", 4LL);
printf("%04d\n", 123LL);
test_snprintf();
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rcx

printf("%u, %u, %u\n", 1LL, 2LL, v3);
printf("%u, %u\n", 4LL, 8LL);
printf("a=%llu\n", 4LL);
printf("%04d\n", 123LL);
func7();
return 0;
}

original_code:
int main(int argc, char *argv[])
{
 __u64 a = 0x1;
 __u32 b = 2;
 printf("%u, %u, %u\n", a, b);
 printf("%u, %u\n", sizeof(__u32), sizeof(__u64));
 a <<= 2;
 printf("a=%llu\n", a);
 printf("%04d\n", 123);
 test_snprintf();
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
 unsigned long long a = 0x1;
 unsigned int b = 2;
 printf("%u, %u, %u\n", a, b);
 printf("%u, %u\n", sizeof(__u32), sizeof(__u64));
 a <<= 2;
 printf("a=%llu\n", a);
 printf("%04d\n", 123);
 test_snprintf();
 return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types:
a
unsigned long long

variable_types:
b
unsigned int


Abort

decompiled_code:
void __noreturn Abort()
{
abort();
}

canonical_decompiled_code:
void __noreturn func7()
{
abort();
}

original_code:
int Abort()
{
 abort();
}

canonical_original_code:
int Abort()
{
 abort();
}


main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
struct rlimit v3; // [rsp+0h] [rbp-18h] BYREF

getrlimit(RLIMIT_CORE, &v3);
printf("For core size, cur limit is:%d, hard limit is:%d\n", v3.rlim_cur, v3.rlim_max);
v3.rlim_cur = -1LL;
setrlimit(RLIMIT_CORE, &v3);
getrlimit(RLIMIT_CORE, &v3);
printf("After setrlimit, cur limit is:%d, hard limit is:%d\n", v3.rlim_cur, v3.rlim_max);
Abort();
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
struct rlimit v3; // [rsp+0h] [rbp-18h] BYREF

getrlimit(RLIMIT_CORE, &v3);
printf("For core size, cur limit is:%d, hard limit is:%d\n", v3.rlim_cur, v3.rlim_max);
v3.rlim_cur = -1LL;
setrlimit(RLIMIT_CORE, &v3);
getrlimit(RLIMIT_CORE, &v3);
printf("After setrlimit, cur limit is:%d, hard limit is:%d\n", v3.rlim_cur, v3.rlim_max);
func7();
}

original_code:
int main(int argc, char *argv[])
{
 struct rlimit lim;
 getrlimit(RLIMIT_CORE, &lim);
 printf("For core size, cur limit is:%d, hard limit is:%d\n", lim.rlim_cur, lim.rlim_max);
 lim.rlim_cur = -1;
 setrlimit(RLIMIT_CORE, &lim);
 getrlimit(RLIMIT_CORE, &lim);
 printf("After setrlimit, cur limit is:%d, hard limit is:%d\n", lim.rlim_cur, lim.rlim_max);
 Abort();
}

variable_types: struct rlimit { unsigned long rlim_cur; unsigned long rlim_max; }


decompiled_code:
int __fastcall open_write(const char *a1)
{
int v1; // eax
int result; // eax
int *v3; // rbp
char *v4; // rax
int *v5; // rbx
char *v6; // rax

v1 = open(a1, 0);
if ( v1 < 0 )
{
v3 = __errno_location();
v4 = strerror(*v3);
printf("Can not open file:%s, (%d)%s\n", a1, (unsigned int)*v3, v4);
result = 1;
}
else
{
result = close(v1);
if ( result < 0 )
{
printf("can not close file");
v5 = __errno_location();
v6 = strerror(*v5);
printf(" errno:%d(%s)\n", (unsigned int)*v5, v6);
result = -1;
}
}
return result;
}

canonical_decompiled_code:
int __fastcall func7(const char *a1)
{
int v1; // eax
int result; // eax
int *v3; // rbp
char *v4; // rax
int *v5; // rbx
char *v6; // rax

v1 = open(a1, 0);
if ( v1 < 0 )
{
v3 = __errno_location();
v4 = strerror(*v3);
printf("Can not open file:%s, (%d)%s\n", a1, (unsigned int)*v3, v4);
result = 1;
}
else
{
result = close(v1);
if ( result < 0 )
{
printf("can not close file");
v5 = __errno_location();
v6 = strerror(*v5);
printf(" errno:%d(%s)\n", (unsigned int)*v5, v6);
result = -1;
}
}
return result;
}

original_code:
int open_write(char *file_path)
{
 int fd, ret;
 fd = open(file_path, (00));
 if (fd < 0) {
  printf("Can not open file:%s, (%d)%s\n", file_path, (*__errno_location ()), strerror((*__errno_location ())));
  return 1;
 }
 ret = close(fd);
 do {if (ret < 0) { do { printf("can not close file"); printf(" errno:%d(%s)\n", (*__errno_location ()), strerror((*__errno_location ()))); } while(0); return -1;}} while (0);
 return ret;
}

canonical_original_code:
int open_write(char *file_path)
{
 int fd; int ret;
 fd = open(file_path, (00));
 if (fd < 0) {
  printf("Can not open file:%s, (%d)%s\n", file_path, (*__errno_location ()), strerror((*__errno_location ())));
  return 1;
 }
 ret = close(fd);
 do {if (ret < 0) { do { printf("can not close file"); printf(" errno:%d(%s)\n", (*__errno_location ()), strerror((*__errno_location ()))); } while(0); return -1;}} while (0);
 return ret;
}

variable_types: fd int

variable_types: ret int


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
_QWORD *v3; // rbp
int result; // eax
struct timezone *v5; // rsi
__int64 v6; // rbx

v3 = parse_args(argc, (__int64)argv);
result = 1;
if ( v3 )
{
read_flist((__int64)v3);
v5 = (struct timezone *)v3[2];
printf((const char *)&tv, v5);
gettimeofday((struct timeval *)&tv, v5);
if ( (__int64)v3[2] <= 0 )
{
result = 0;
}
else
{
v6 = 0LL;
do
open_write(*(const char **)(v3[1] + 8 * v6++));
while ( v3[2] > v6 );
result = 0;
}
}
return result;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
_QWORD *v3; // rbp
int result; // eax
struct timezone *v5; // rsi
__int64 v6; // rbx

v3 = parse_args(argc, (__int64)argv);
result = 1;
if ( v3 )
{
func8((__int64)v3);
v5 = (struct timezone *)v3[2];
printf((const char *)&tv, v5);
gettimeofday((struct timeval *)&tv, v5);
if ( (__int64)v3[2] <= 0 )
{
result = 0;
}
else
{
v6 = 0LL;
do
func7(*(const char **)(v3[1] + 8 * v6++));
while ( v3[2] > v6 );
result = 0;
}
}
return result;
}

original_code:
int main(int argc, char *argv[])
{
 struct options *opts;
 int i;
 opts = parse_args(argc, argv);
 if (opts == ((void *)0))
  goto failed;
 read_flist(opts);
 printf("open %ld files\n", opts->flist_count);
 gettimeofday();
 for (i=0; i<opts->flist_count; i++) {
  open_write(opts->flist[i]);
 }
 return 0;
failed:
 return 1;
}

variable_types: struct options { char *flist_path; char **flist; long flist_count; } *


interval

decompiled_code:
float interval()
{
struct timeval v1; // [rsp+0h] [rbp-18h] BYREF

gettimeofday(&v1, 0LL);
return (double)(LODWORD(v1.tv_usec) - LODWORD(start.tv_usec)) / 1000000.0
+ (double)(LODWORD(v1.tv_sec) - LODWORD(start.tv_sec));
}

canonical_decompiled_code:
float func7()
{
struct timeval v1; // [rsp+0h] [rbp-18h] BYREF

gettimeofday(&v1, 0LL);
return (double)(LODWORD(v1.tv_usec) - LODWORD(start.tv_usec)) / 1000000.0
+ (double)(LODWORD(v1.tv_sec) - LODWORD(start.tv_sec));
}

original_code:
float interval()
{
 struct timeval curTime;
 gettimeofday(&curTime, ((void *)0));
 float interval = (curTime.tv_sec - start.tv_sec)+((curTime.tv_usec - start.tv_usec)/1000000.0);
 return interval;
}

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

variable_types: interval float

return_type: float


nextQueue

decompiled_code:
__int64 nextQueue()
{
unsigned int v0; // esi
__int64 v1; // rax
int v2; // edx

v0 = *(_DWORD *)queue;
if ( size_queue > 0 )
{
v1 = 16LL;
v2 = 0;
do
{
*(__m128i *)(queue + v1 - 16) = _mm_loadu_si128((const __m128i *)(queue + v1));
++v2;
v1 += 16LL;
}
while ( size_queue > v2 );
}
return v0;
}

canonical_decompiled_code:
__int64 func8()
{
unsigned int v0; // esi
__int64 v1; // rax
int v2; // edx

v0 = *(_DWORD *)queue;
if ( size_queue > 0 )
{
v1 = 16LL;
v2 = 0;
do
{
*(__m128i *)(queue + v1 - 16) = _mm_loadu_si128((const __m128i *)(queue + v1));
++v2;
v1 += 16LL;
}
while ( size_queue > v2 );
}
return v0;
}

original_code:
int nextQueue()
{
 int next = queue[0].id;
 int i = 0;
 while(i<size_queue)
 {
  queue[i]=queue[i+1];
  i++;
 }
 return next;
}

variable_types: next int


yourFlow

decompiled_code:
void __fastcall __noreturn yourFlow(void *a1)
{
__int64 v1; // r14
__int64 v2; // rbx
unsigned int v3; // ebp
int v4; // er12
unsigned int v5; // er13
float v6; // xmm0_4
int i; // eax
int v8; // ebx
float v9; // xmm0_4
float v10; // xmm0_4

v1 = *(_QWORD *)a1;
v2 = *((_QWORD *)a1 + 1);
v3 = *(_DWORD *)a1;
v4 = *((_DWORD *)a1 + 2);
v5 = *((_DWORD *)a1 + 3);
usleep((int)(float)((float)*((int *)a1 + 1) * 100000.0));
v6 = interval();
printf(
"Flow %2d arrives: arrival time (%.2f), transmission time (%.1f), priority (%2d). \n",
v3,
v6,
(double)v4 / 10.0,
v5);
if ( trans_thread )
{
pthread_mutex_lock(&queue_mutex);
addtoQueue(v1, v2);
pthread_mutex_unlock(&queue_mutex);
printf("Flow %2d waits for the finish of flow %2d. \n", v3, (unsigned int)trans_thread);
for ( i = trans_thread; ; i = v8 )
{
v8 = trans_thread;
do
{
if ( trans_thread == v3 )
goto LABEL_7;
}
while ( i == trans_thread );
printf("Flow %2d waits for the finish of flow %2d. \n", v3, (unsigned int)trans_thread);
}
}
LABEL_7:
pthread_mutex_lock(&transmit);
trans_thread = v3;
pthread_mutex_unlock(&transmit);
v9 = interval();
printf("Flow %2d starts its transmission at time %.2f. \n", v3, v9);
usleep((int)(float)((float)v4 * 100000.0));
v10 = interval();
printf("Flow %2d finishes its transmission at time %.2f. \n", v3, v10);
pthread_mutex_lock(&transmit);
if ( size_queue )
{
pthread_mutex_lock(&queue_mutex);
trans_thread = nextQueue();
pthread_mutex_unlock(&queue_mutex);
}
else
{
trans_thread = 0;
}
pthread_mutex_unlock(&transmit);
pthread_exit(0LL);
}

canonical_decompiled_code:
void __fastcall __noreturn func9(void *a1)
{
__int64 v1; // r14
__int64 v2; // rbx
unsigned int v3; // ebp
int v4; // er12
unsigned int v5; // er13
float v6; // xmm0_4
int i; // eax
int v8; // ebx
float v9; // xmm0_4
float v10; // xmm0_4

v1 = *(_QWORD *)a1;
v2 = *((_QWORD *)a1 + 1);
v3 = *(_DWORD *)a1;
v4 = *((_DWORD *)a1 + 2);
v5 = *((_DWORD *)a1 + 3);
usleep((int)(float)((float)*((int *)a1 + 1) * 100000.0));
v6 = func7();
printf(
"Flow %2d arrives: arrival time (%.2f), transmission time (%.1f), priority (%2d). \n",
v3,
v6,
(double)v4 / 10.0,
v5);
if ( trans_thread )
{
pthread_mutex_lock(&queue_mutex);
addtoQueue(v1, v2);
pthread_mutex_unlock(&queue_mutex);
printf("Flow %2d waits for the finish of flow %2d. \n", v3, (unsigned int)trans_thread);
for ( i = trans_thread; ; i = v8 )
{
v8 = trans_thread;
do
{
if ( trans_thread == v3 )
goto LABEL_7;
}
while ( i == trans_thread );
printf("Flow %2d waits for the finish of flow %2d. \n", v3, (unsigned int)trans_thread);
}
}
LABEL_7:
pthread_mutex_lock(&transmit);
trans_thread = v3;
pthread_mutex_unlock(&transmit);
v9 = func7();
printf("Flow %2d starts its transmission at time %.2f. \n", v3, v9);
usleep((int)(float)((float)v4 * 100000.0));
v10 = func7();
printf("Flow %2d finishes its transmission at time %.2f. \n", v3, v10);
pthread_mutex_lock(&transmit);
if ( size_queue )
{
pthread_mutex_lock(&queue_mutex);
trans_thread = func8();
pthread_mutex_unlock(&queue_mutex);
}
else
{
trans_thread = 0;
}
pthread_mutex_unlock(&transmit);
pthread_exit(0LL);
}

original_code:
void *yourFlow(void* arg)
{
 struct flow curFlow = *(struct flow *)arg;
 double arv = (double)curFlow.arrival_time/10;
 double trans = (double)curFlow.trans_time/10;
 usleep(curFlow.arrival_time * 1E5F);
 printf("Flow %2d arrives: arrival time (%.2f), transmission time (%.1f), priority (%2d). \n",curFlow.id, interval(), trans, curFlow.priority);
 if(!trans_thread)
 {
  pthread_mutex_lock(&transmit);
  trans_thread = curFlow.id;
  pthread_mutex_unlock(&transmit);
  printf("Flow %2d starts its transmission at time %.2f. \n", curFlow.id, interval());
  usleep(curFlow.trans_time* 1E5F);
  printf("Flow %2d finishes its transmission at time %.2f. \n", curFlow.id, interval());
 }
 else
 {
  pthread_mutex_lock(&queue_mutex);
  addtoQueue(curFlow);
  pthread_mutex_unlock(&queue_mutex);
  printf("Flow %2d waits for the finish of flow %2d. \n", curFlow.id, trans_thread);
  int tmp = trans_thread;
  while(trans_thread != curFlow.id)
  {
   if(tmp != trans_thread && trans_thread != curFlow.id)
   {
    tmp = trans_thread;
    printf("Flow %2d waits for the finish of flow %2d. \n", curFlow.id, trans_thread);
   }
  }
  pthread_mutex_lock(&transmit);
  trans_thread = curFlow.id;
  pthread_mutex_unlock(&transmit);
  printf("Flow %2d starts its transmission at time %.2f. \n", curFlow.id, interval());
  usleep(curFlow.trans_time* 1E5F);
  printf("Flow %2d finishes its transmission at time %.2f. \n", curFlow.id, interval());
 }
 pthread_mutex_lock(&transmit);
 if(!size_queue)
 {
  trans_thread = 0;
 }
 else
 {
  pthread_mutex_lock(&queue_mutex);
  trans_thread = nextQueue();
  pthread_mutex_unlock(&queue_mutex);
 }
 pthread_mutex_unlock(&transmit);
 pthread_exit(((void *)0));
}

canonical_original_code:
void *yourFlow(void *arg)
{
 struct flow curFlow = *(struct flow *)arg;
 double arv = (double)curFlow.arrival_time/10;
 double trans = (double)curFlow.trans_time/10;
 usleep(curFlow.arrival_time * 1E5F);
 printf("Flow %2d arrives: arrival time (%.2f), transmission time (%.1f), priority (%2d). \n",curFlow.id, interval(), trans, curFlow.priority);
 if(!trans_thread)
 {
  pthread_mutex_lock(&transmit);
  trans_thread = curFlow.id;
  pthread_mutex_unlock(&transmit);
  printf("Flow %2d starts its transmission at time %.2f. \n", curFlow.id, interval());
  usleep(curFlow.trans_time* 1E5F);
  printf("Flow %2d finishes its transmission at time %.2f. \n", curFlow.id, interval());
 }
 else
 {
  pthread_mutex_lock(&queue_mutex);
  addtoQueue(curFlow);
  pthread_mutex_unlock(&queue_mutex);
  printf("Flow %2d waits for the finish of flow %2d. \n", curFlow.id, trans_thread);
  int tmp = trans_thread;
  while(trans_thread != curFlow.id)
  {
   if(tmp != trans_thread && trans_thread != curFlow.id)
   {
    tmp = trans_thread;
    printf("Flow %2d waits for the finish of flow %2d. \n", curFlow.id, trans_thread);
   }
  }
  pthread_mutex_lock(&transmit);
  trans_thread = curFlow.id;
  pthread_mutex_unlock(&transmit);
  printf("Flow %2d starts its transmission at time %.2f. \n", curFlow.id, interval());
  usleep(curFlow.trans_time* 1E5F);
  printf("Flow %2d finishes its transmission at time %.2f. \n", curFlow.id, interval());
 }
 pthread_mutex_lock(&transmit);
 if(!size_queue)
 {
  trans_thread = 0;
 }
 else
 {
  pthread_mutex_lock(&queue_mutex);
  trans_thread = nextQueue();
  pthread_mutex_unlock(&queue_mutex);
 }
 pthread_mutex_unlock(&transmit);
 pthread_exit(((void *)0));
}

variable_types:
arg
void *

variable_types: struct flow { int id; int arrival_time; int trans_time; int priority; }

variable_types: arv double

variable_types: trans double

variable_types: tmp int


stringtoflow

decompiled_code:
__int64 __fastcall stringtoflow(char *s)
{
char *v1; // rax
char *v2; // rdi
__int64 *v3; // rbx
char v5[128]; // [rsp+0h] [rbp-98h] BYREF
__int64 v6; // [rsp+80h] [rbp-18h] BYREF

strcpy(v5, s);
v1 = strtok(s, delim);
if ( v1 )
{
v2 = v1;
v3 = &v6;
do
{
*(_DWORD *)v3 = atoi(v2);
v2 = strtok(0LL, &delim[2]);
v3 = (__int64 *)((char *)v3 + 4);
}
while ( v2 );
}
return v6;
}

canonical_decompiled_code:
__int64 __fastcall func10(char *s)
{
char *v1; // rax
char *v2; // rdi
__int64 *v3; // rbx
char v5[128]; // [rsp+0h] [rbp-98h] BYREF
__int64 v6; // [rsp+80h] [rbp-18h] BYREF

strcpy(v5, s);
v1 = strtok(s, delim);
if ( v1 )
{
v2 = v1;
v3 = &v6;
do
{
*(_DWORD *)v3 = atoi(v2);
v2 = strtok(0LL, &delim[2]);
v3 = (__int64 *)((char *)v3 + 4);
}
while ( v2 );
}
return v6;
}

original_code:
struct flow stringtoflow(char* text)
{
 struct flow hold;
 int flow_array[4];
 char buffer[128];
 int i = 0;
 strcpy(buffer, text);
 char* token = strtok(text, ":");
 while (token)
        {
  flow_array[i++] = atoi(token);
             token = strtok(((void *)0), ",");
        }
 hold.id = flow_array[0];
 hold.arrival_time = flow_array[1];
 hold.trans_time = flow_array[2];
 hold.priority = flow_array[3];
 return hold;
}

canonical_original_code:
struct flow stringtoflow(char *text)
{
 struct flow hold;
 int flow_array[4];
 char buffer[128];
 int i = 0;
 strcpy(buffer, text);
 char *token = strtok(text, ":");
 while (token)
        {
  flow_array[i++] = atoi(token);
             token = strtok(((void *)0), ",");
        }
 hold.id = flow_array[0];
 hold.arrival_time = flow_array[1];
 hold.trans_time = flow_array[2];
 hold.priority = flow_array[3];
 return hold;
}

variable_types:
text
char *

variable_types:
buffer
char [128]

variable_types: i int

variable_types:
token
char *

return_type: struct flow { int id; int arrival_time; int trans_time; int priority; }


repo: beckharry/loadtune

decompiled_code:
int print_help()
{
puts("Usage:");
puts(" loadtune-daemon target-value");
puts("Options:");
puts(" For single core machine, target-value is between 0 and 1;");
puts(" For multiple[N] core machine, target-value is between 0 and N.");
printf(" (N is %d on this machine)\n", (unsigned int)nrcpus);
puts("Example:");
return puts(" loadtune-daemon 0.4");
}

canonical_decompiled_code:
int func7()
{
puts("Usage:");
puts(" loadtune-daemon target-value");
puts("Options:");
puts(" For single core machine, target-value is between 0 and 1;");
puts(" For multiple[N] core machine, target-value is between 0 and N.");
printf(" (N is %d on this machine)\n", (unsigned int)nrcpus);
puts("Example:");
return puts(" loadtune-daemon 0.4");
}

original_code:
static void print_help(void)
{
 printf("Usage:\n");
 printf("    loadtune-daemon target-value\n");
 printf("Options:\n");
 printf("    For single core machine, target-value is between 0 and 1;\n");
 printf("    For multiple[N] core machine, target-value is between 0 and N.\n");
 printf("    (N is %d on this machine)\n", nrcpus);
 printf("Example:\n");
 printf("    loadtune-daemon 0.4\n");
}

canonical_original_code:
static void print_help()
{
 printf("Usage:\n");
 printf("    loadtune-daemon target-value\n");
 printf("Options:\n");
 printf("    For single core machine, target-value is between 0 and 1;\n");
 printf("    For multiple[N] core machine, target-value is between 0 and N.\n");
 printf("    (N is %d on this machine)\n", nrcpus);
 printf("Example:\n");
 printf("    loadtune-daemon 0.4\n");
}


decompiled_code:
int tune_proc_start()
{
pthread_t newthread[2]; // [rsp+8h] [rbp-10h] BYREF

++affinity;
pthread_create(newthread, 0LL, tune_proc, 0LL);
return pthread_join(newthread[0], 0LL);
}

canonical_decompiled_code:
int func9()
{
pthread_t newthread[2]; // [rsp+8h] [rbp-10h] BYREF

++affinity;
pthread_create(newthread, 0LL, tune_proc, 0LL);
return pthread_join(newthread[0], 0LL);
}

original_code:
static void tune_proc_start(void)
{
 pthread_t thread;
 affinity++;
 pthread_create(&thread, ((void *)0), (void *)tune_proc, ((void *)0));
 pthread_join(thread, ((void *)0));
 return;
}

canonical_original_code:
static void tune_proc_start()
{
 unsigned long thread;
 affinity++;
 pthread_create(&thread, ((void *)0), (void *)tune_proc, ((void *)0));
 pthread_join(thread, ((void *)0));
 return;
}

variable_types:
thread
unsigned long


decompiled_code:
__m128i __fastcall tune_proc(void *a1)
{
pthread_t v1; // r8
unsigned __int64 v2; // rax
__m128i result; // xmm0
cpu_set_t v4; // [rsp+0h] [rbp-88h] BYREF

v1 = pthread_self();
memset(&v4, 0, sizeof(v4));
v2 = affinity % nrcpus;
if ( v2 <= 0x3FF )
v4.__bits[v2 >> 6] |= 1LL << (affinity % nrcpus);
pthread_setaffinity_np(v1, 0x80uLL, &v4);
while ( 1 )
{
result = get_loadavg();
if ( *(float *)&loadtune <= *(float *)result.m128i_i32 )
break;
get_loadavg();
}
return result;
}

canonical_decompiled_code:
__m128i __fastcall func10(void *a1)
{
pthread_t v1; // r8
unsigned __int64 v2; // rax
__m128i result; // xmm0
cpu_set_t v4; // [rsp+0h] [rbp-88h] BYREF

v1 = pthread_self();
memset(&v4, 0, sizeof(v4));
v2 = affinity % nrcpus;
if ( v2 <= 0x3FF )
v4.__bits[v2 >> 6] |= 1LL << (affinity % nrcpus);
pthread_setaffinity_np(v1, 0x80uLL, &v4);
while ( 1 )
{
result = func8();
if ( *(float *)&loadtune <= *(float *)result.m128i_i32 )
break;
func8();
}
return result;
}

original_code:
static void tune_proc(void * arg)
{
 pthread_t thread;
 cpu_set_t cpuset;
 ("affinity: %d.\n", affinity);
 thread = pthread_self();
 ("pthread: %d.\n", thread);
 do __builtin_memset (&cpuset, '\0', sizeof (cpu_set_t)); while (0);
 (__extension__ ({ size_t __cpu = (affinity % nrcpus); __cpu / 8 < (sizeof (cpu_set_t)) ? (((__cpu_mask *) ((&cpuset)->__bits))[((__cpu) / (8 * sizeof (__cpu_mask)))] |= ((__cpu_mask) 1 << ((__cpu) % (8 * sizeof (__cpu_mask))))) : 0; }));
 pthread_setaffinity_np(thread, sizeof(cpu_set_t), &cpuset);
 while (get_loadavg() < loadtune){
  ("pthread: %d.\n", thread);
  ("current load average: %f.\n", get_loadavg());
  ("target load average: %f.\n", loadtune);
 }
 ("end of tune_proc.\n");
 return;
}

canonical_original_code:
static void tune_proc(void *arg)
{
 unsigned long thread;
 struct cpu_set_t cpuset;
 ("affinity: %d.\n", affinity);
 thread = pthread_self();
 ("pthread: %d.\n", thread);
 do __builtin_memset (&cpuset, '\0', sizeof (cpu_set_t)); while (0);
 (__extension__ ({ unsigned long __cpu = (affinity % nrcpus); __cpu / 8 < (sizeof (cpu_set_t)) ? (((unsigned long *) ((&cpuset)->__bits))[((__cpu) / (8 * sizeof (__cpu_mask)))] |= ((unsigned long) 1 << ((__cpu) % (8 * sizeof (__cpu_mask))))) : 0; }));
 pthread_setaffinity_np(thread, sizeof(cpu_set_t), &cpuset);
 while (get_loadavg() < loadtune){
  ("pthread: %d.\n", thread);
  ("current load average: %f.\n", get_loadavg());
  ("target load average: %f.\n", loadtune);
 }
 ("end of tune_proc.\n");
 return;
}

variable_types: struct cpu_set_t { unsigned long __bits[-1]; }


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // ebx
const char *v4; // r12
char v5; // bp
const unsigned __int16 *v6; // rcx
char *v7; // rax
int result; // eax
float v9; // xmm0_4

v3 = sysconf(84);
nrcpus = v3;
getpid();
if ( argc == 2 )
{
v4 = argv[1];
if ( strcmp(v4, "--help") && strcmp(v4, "-h") )
{
v5 = *v4;
if ( !*v4 )
{
LABEL_11:
v9 = atof(v4);
loadtune = LODWORD(v9);
if ( v9 > (float)v3 )
{
puts("Invalid target-value, it MUST be lower than nrcpus.");
print_help();
}
while ( 1 )
{
get_loadavg();
tune_proc_start();
}
}
v6 = *__ctype_b_loc();
v7 = (char *)(v4 + 1);
while ( (v6[v5] & 0x800) != 0 || v5 == 46 )
{
v5 = *v7++;
if ( !v5 )
goto LABEL_11;
}
}
result = print_help();
}
else
{
puts("Invalid parameter count.");
result = print_help();
}
return result;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // ebx
const char *v4; // r12
char v5; // bp
const unsigned __int16 *v6; // rcx
char *v7; // rax
int result; // eax
float v9; // xmm0_4

v3 = sysconf(84);
nrcpus = v3;
getpid();
if ( argc == 2 )
{
v4 = argv[1];
if ( strcmp(v4, "--help") && strcmp(v4, "-h") )
{
v5 = *v4;
if ( !*v4 )
{
LABEL_11:
v9 = atof(v4);
loadtune = LODWORD(v9);
if ( v9 > (float)v3 )
{
puts("Invalid target-value, it MUST be lower than nrcpus.");
func7();
}
while ( 1 )
{
func8();
func9();
}
}
v6 = *__ctype_b_loc();
v7 = (char *)(v4 + 1);
while ( (v6[v5] & 0x800) != 0 || v5 == 46 )
{
v5 = *v7++;
if ( !v5 )
goto LABEL_11;
}
}
result = func7();
}
else
{
puts("Invalid parameter count.");
result = func7();
}
return result;
}

original_code:
void main(int argc, char ** argv)
{
 float current_load = 0;
 int proc_index = 0;
 nrcpus = sysconf(_SC_NPROCESSORS_ONLN);
 ("nrcpus: %d.\n", nrcpus);
 ("pid: %d.\n", getpid());
 if (argc == 2) {
  int i = 0;
  if ((strcmp(argv[1], "--help") == 0)
    || ((strcmp(argv[1], "-h") == 0))) {
   print_help();
   return;
  }
  for (; argv[1][i] != '\0'; i++) {
   if (((*__ctype_b_loc ())[(int) ((argv[1][i]))] & (unsigned short int) _ISdigit) || (argv[1][i] == '.')) {
    continue;
   }
   else {
    print_help();
    return;
   }
  }
  loadtune = atof(argv[1]);
 }
 else {
  printf("Invalid parameter count.\n");
  print_help();
  return;
 }
 ("loadtune: %f.\n", loadtune);
 if (loadtune > (float)(nrcpus)) {
  printf("Invalid target-value, it MUST be lower than nrcpus.\n");
  print_help();
 }
 while(1) {
  ("current load average: %f.\n", get_loadavg());
  ("target load average: %f.\n", loadtune);
  tune_proc_start();
 }
 return;
}

canonical_original_code:
void main(int argc, char **argv)
{
 float current_load = 0;
 int proc_index = 0;
 nrcpus = sysconf(_SC_NPROCESSORS_ONLN);
 ("nrcpus: %d.\n", nrcpus);
 ("pid: %d.\n", getpid());
 if (argc == 2) {
  int i = 0;
  if ((strcmp(argv[1], "--help") == 0)
    || ((strcmp(argv[1], "-h") == 0))) {
   print_help();
   return;
  }
  for (; argv[1][i] != '\0'; i++) {
   if (((*__ctype_b_loc ())[(int) ((argv[1][i]))] & (unsigned short) _ISdigit) || (argv[1][i] == '.')) {
    continue;
   }
   else {
    print_help();
    return;
   }
  }
  loadtune = atof(argv[1]);
 }
 else {
  printf("Invalid parameter count.\n");
  print_help();
  return;
 }
 ("loadtune: %f.\n", loadtune);
 if (loadtune > (float)(nrcpus)) {
  printf("Invalid target-value, it MUST be lower than nrcpus.\n");
  print_help();
 }
 while(1) {
  ("current load average: %f.\n", get_loadavg());
  ("target load average: %f.\n", loadtune);
  tune_proc_start();
 }
 return;
}

variable_types: argc int

variable_types:
argv
char **