parallelize

decompiled_code:
int __fastcall parallelize(__int64 a1, int a2, int a3)
{
int v5; // ebx
pthread_t *v6; // r13
struct _IO_FILE *v7; // rdi
int v8; // er12
int v9; // er15
pthread_t *v10; // rbp
int v11; // er15
unsigned int v12; // eax
__int64 v13; // rdx
__int64 v14; // rcx
int v15; // eax
__int64 v16; // r8
__int64 v17; // rbp
pthread_t v18; // rdi
int v20; // [rsp+8h] [rbp-90h]
int v21; // [rsp+Ch] [rbp-8Ch]
struct sched_param param; // [rsp+1Ch] [rbp-7Ch] BYREF
pthread_attr_t attr; // [rsp+20h] [rbp-78h] BYREF

pthread_attr_init(&attr);
pthread_attr_setdetachstate(&attr, 0);
pthread_attr_setstacksize(&attr, 0x8000uLL);
param.__sched_priority = 0;
if ( a3 <= 0 )
{
v5 = 1;
v6 = (pthread_t *)malloc(8uLL);
v7 = 0LL;
v21 = sched_get_priority_min(0);
v8 = sched_get_priority_max(0);
LABEL_3:
v9 = 0;
v10 = v6;
if ( v21 >= 0 )
v9 = v21;
v20 = v9;
v11 = 0;
do
{
while ( 1 )
{
if ( v20 < v8 )
{
param.__sched_priority = v21 + (int)randint(v7) % v8;
pthread_attr_setschedparam(&attr, &param);
}
v7 = (struct _IO_FILE *)v10;
v12 = pthread_create(v10, &attr, (void *(*)(void *))threaded_task, (void *)(a1 + ((__int64)(v11 % a2) << 6)));
v15 = test_debug(v10, &attr, v13, v14, v12);
if ( (_DWORD)v16 )
{
if ( v15 )
break;
}
++v11;
++v10;
if ( v11 >= v5 )
goto LABEL_12;
}
++v11;
v7 = stderr;
++v10;
fprintf(stderr, "%s_%d pthread_create failed %d\n", "test.c", 99LL, v16);
}
while ( v11 < v5 );
LABEL_12:
if ( (unsigned int)proto_debug() )
fprintf(stderr, "%s_%d main thread suspending\n", "test.c", 102LL);
v17 = 0LL;
do
{
v18 = v6[v17++];
pthread_join(v18, 0LL);
}
while ( v5 > (int)v17 );
goto LABEL_16;
}
v5 = a2 * a3;
v6 = (pthread_t *)malloc(8LL * v5);
v7 = 0LL;
v21 = sched_get_priority_min(0);
v8 = sched_get_priority_max(0);
if ( v5 > 0 )
goto LABEL_3;
if ( !(unsigned int)proto_debug() )
goto LABEL_18;
fprintf(stderr, "%s_%d main thread suspending\n", "test.c", 102LL);
LABEL_16:
if ( (unsigned int)proto_debug() )
fprintf(stderr, "%s_%d main thread resuming\n", "test.c", 109LL);
LABEL_18:
free(v6);
return pthread_attr_destroy(&attr);
}

canonical_decompiled_code:
int __fastcall func9(__int64 a1, int a2, int a3)
{
int v5; // ebx
pthread_t *v6; // r13
struct _IO_FILE *v7; // rdi
int v8; // er12
int v9; // er15
pthread_t *v10; // rbp
int v11; // er15
unsigned int v12; // eax
__int64 v13; // rdx
__int64 v14; // rcx
int v15; // eax
__int64 v16; // r8
__int64 v17; // rbp
pthread_t v18; // rdi
int v20; // [rsp+8h] [rbp-90h]
int v21; // [rsp+Ch] [rbp-8Ch]
struct sched_param param; // [rsp+1Ch] [rbp-7Ch] BYREF
pthread_attr_t attr; // [rsp+20h] [rbp-78h] BYREF

pthread_attr_init(&attr);
pthread_attr_setdetachstate(&attr, 0);
pthread_attr_setstacksize(&attr, 0x8000uLL);
param.__sched_priority = 0;
if ( a3 <= 0 )
{
v5 = 1;
v6 = (pthread_t *)malloc(8uLL);
v7 = 0LL;
v21 = sched_get_priority_min(0);
v8 = sched_get_priority_max(0);
LABEL_3:
v9 = 0;
v10 = v6;
if ( v21 >= 0 )
v9 = v21;
v20 = v9;
v11 = 0;
do
{
while ( 1 )
{
if ( v20 < v8 )
{
param.__sched_priority = v21 + (int)randint(v7) % v8;
pthread_attr_setschedparam(&attr, &param);
}
v7 = (struct _IO_FILE *)v10;
v12 = pthread_create(v10, &attr, (void *(*)(void *))threaded_task, (void *)(a1 + ((__int64)(v11 % a2) << 6)));
v15 = func8(v10, &attr, v13, v14, v12);
if ( (_DWORD)v16 )
{
if ( v15 )
break;
}
++v11;
++v10;
if ( v11 >= v5 )
goto LABEL_12;
}
++v11;
v7 = stderr;
++v10;
fprintf(stderr, "%s_%d pthread_create failed %d\n", "test.c", 99LL, v16);
}
while ( v11 < v5 );
LABEL_12:
if ( (unsigned int)func1() )
fprintf(stderr, "%s_%d main thread suspending\n", "test.c", 102LL);
v17 = 0LL;
do
{
v18 = v6[v17++];
pthread_join(v18, 0LL);
}
while ( v5 > (int)v17 );
goto LABEL_16;
}
v5 = a2 * a3;
v6 = (pthread_t *)malloc(8LL * v5);
v7 = 0LL;
v21 = sched_get_priority_min(0);
v8 = sched_get_priority_max(0);
if ( v5 > 0 )
goto LABEL_3;
if ( !(unsigned int)func1() )
goto LABEL_18;
fprintf(stderr, "%s_%d main thread suspending\n", "test.c", 102LL);
LABEL_16:
if ( (unsigned int)func1() )
fprintf(stderr, "%s_%d main thread resuming\n", "test.c", 109LL);
LABEL_18:
free(v6);
return pthread_attr_destroy(&attr);
}

original_code:
extern void parallelize(Task tasks[], int num_tasks, int threads_per_task)
{
  int ii, thread_count;
  pthread_attr_t attr;
  pthread_attr_init(&attr);
  pthread_attr_setdetachstate(&attr,PTHREAD_CREATE_JOINABLE);
  pthread_attr_setstacksize(&attr,16384*2);
  struct sched_param param;
  bzero(&param,sizeof(struct sched_param));
  thread_count = (threads_per_task < 1 ? 1 : threads_per_task*num_tasks);
  pthread_t * threads;
  threads = (pthread_t *) malloc(sizeof(pthread_t)*thread_count);
  int min = sched_get_priority_min(0);
  int max = sched_get_priority_max(0);
  for (ii=0;ii < thread_count ;ii++)
  {
    if (max > min && max > 0)
    {
      param.sched_priority = (randint()%max)+min;
      pthread_attr_setschedparam(&attr, &param);
    }
    int rc;
    rc = pthread_create(&threads[ii], &attr, threaded_task, (void*) &tasks[ii%num_tasks] );
    if (test_debug() && rc!=0 )
      fprintf(stderr,"%s_%d pthread_create failed %d\n","test.c",99,rc);
  }
  if (proto_debug() ) fprintf(stderr,"%s_%d main thread suspending\n", "test.c", 102 );
  for (ii=0;ii < thread_count ;ii++)
  {
    pthread_join(threads[ii],((void *)0));
  }
  if (proto_debug() ) fprintf(stderr,"%s_%d main thread resuming\n", "test.c", 109 );
  free(threads);
  pthread_attr_destroy(&attr);
}

canonical_original_code:
extern void parallelize(struct Task tasks[], int num_tasks, int threads_per_task)
{
  int ii; int thread_count;
  union pthread_attr_t attr;
  pthread_attr_init(&attr);
  pthread_attr_setdetachstate(&attr,PTHREAD_CREATE_JOINABLE);
  pthread_attr_setstacksize(&attr,16384*2);
  struct sched_param param;
  bzero(&param,sizeof(struct sched_param));
  thread_count = (threads_per_task < 1 ? 1 : threads_per_task*num_tasks);
  unsigned long *threads;
  threads = (unsigned long *) malloc(sizeof(pthread_t)*thread_count);
  int min = sched_get_priority_min(0);
  int max = sched_get_priority_max(0);
  for (ii=0;ii < thread_count ;ii++)
  {
    if (max > min && max > 0)
    {
      param.sched_priority = (randint()%max)+min;
      pthread_attr_setschedparam(&attr, &param);
    }
    int rc;
    rc = pthread_create(&threads[ii], &attr, threaded_task, (void *) &tasks[ii%num_tasks] );
    if (test_debug() && rc!=0 )
      fprintf(stderr,"%s_%d pthread_create failed %d\n","test.c",99,rc);
  }
  if (proto_debug() ) fprintf(stderr,"%s_%d main thread suspending\n", "test.c", 102 );
  for (ii=0;ii < thread_count ;ii++)
  {
    pthread_join(threads[ii],((void *)0));
  }
  if (proto_debug() ) fprintf(stderr,"%s_%d main thread resuming\n", "test.c", 109 );
  free(threads);
  pthread_attr_destroy(&attr);
}

variable_types: struct Task { void *arg0; void *arg1; void *arg2; void *arg3; void *arg4; void *arg5; void (*func)(void *); int reps; } []

variable_types: ii int

variable_types: struct sched_param { int sched_priority; }

variable_types:
threads
unsigned long *

variable_types: min int

variable_types: max int

user_defined_types: union pthread_attr_t { char __size[56]; long __align; }


repo: samirahmed/bogosort

decompiled_code:
int __fastcall test_summary(unsigned int *a1)
{
time_t v2; // rax
FILE *v3; // rdi
unsigned int v4; // edx
int v5; // er12
__int64 v6; // rdx
__int64 v7; // rdx
int result; // eax

v2 = time(0LL);
v3 = stderr;
v4 = a1[1];
*((_QWORD *)a1 + 11) = v2;
v5 = v2 - a1[20];
fprintf(v3, "\x1B[94m%d\x1B[0m test run", *a1 + v4);
if ( v5 > 0 )
fprintf(stderr, " in %d seconds", (unsigned int)v5);
fputc(10, stderr);
v6 = *a1;
if ( (int)v6 > 0 )
fprintf(stderr, "\x1B[92m%d\x1B[0m passed, ", v6);
v7 = a1[1];
if ( (int)v7 <= 0 )
result = fwrite("no failed tests\n", 1uLL, 0x10uLL, stderr);
else
result = fprintf(stderr, "\x1B[91m%d\x1B[0m failed.", v7);
return result;
}

canonical_decompiled_code:
int __fastcall func10(unsigned int *a1)
{
time_t v2; // rax
FILE *v3; // rdi
unsigned int v4; // edx
int v5; // er12
__int64 v6; // rdx
__int64 v7; // rdx
int result; // eax

v2 = time(0LL);
v3 = stderr;
v4 = a1[1];
*((_QWORD *)a1 + 11) = v2;
v5 = v2 - a1[20];
fprintf(v3, "\x1B[94m%d\x1B[0m test run", *a1 + v4);
if ( v5 > 0 )
fprintf(stderr, " in %d seconds", (unsigned int)v5);
fputc(10, stderr);
v6 = *a1;
if ( (int)v6 > 0 )
fprintf(stderr, "\x1B[92m%d\x1B[0m passed, ", v6);
v7 = a1[1];
if ( (int)v7 <= 0 )
result = fwrite("no failed tests\n", 1uLL, 0x10uLL, stderr);
else
result = fprintf(stderr, "\x1B[91m%d\x1B[0m failed.", v7);
return result;
}

original_code:
extern void test_summary(TestContext *tc)
{
    int seconds;
    tc->stop_time = time(((void *)0));
    seconds = tc->stop_time - tc->start_time;
    fprintf(stderr, "\033[94m" "%d" "\033[0m" " test run", tc->pass+tc->fail);
    if (seconds>0) fprintf(stderr, " in %d seconds", seconds);
    fprintf(stderr,"\n");
    if (tc->pass > 0) fprintf(stderr, "\033[92m" "%d" "\033[0m" " passed, ", tc->pass );
    if (tc->fail > 0) fprintf(stderr, "\033[91m" "%d" "\033[0m" " failed.", tc->fail );
    else fprintf(stderr, "no failed tests\n");
}

canonical_original_code:
extern void test_summary(struct TestContext *tc)
{
    int seconds;
    tc->stop_time = time(((void *)0));
    seconds = tc->stop_time - tc->start_time;
    fprintf(stderr, "\033[94m" "%d" "\033[0m" " test run", tc->pass+tc->fail);
    if (seconds>0) fprintf(stderr, " in %d seconds", seconds);
    fprintf(stderr,"\n");
    if (tc->pass > 0) fprintf(stderr, "\033[92m" "%d" "\033[0m" " passed, ", tc->pass );
    if (tc->fail > 0) fprintf(stderr, "\033[91m" "%d" "\033[0m" " failed.", tc->fail );
    else fprintf(stderr, "no failed tests\n");
}

variable_types: struct TestContext { int pass; int fail; int num; int verbose; char *current; int current_test_status; int blocking; void (*test_function)(void *); 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; } lock; long start_time; long stop_time; int single_test; } *

variable_types: seconds int

return_type: void

user_defined_types: struct TestContext { int pass; int fail; int num; int verbose; char *current; int current_test_status; int blocking; void (*test_function)(void *); union pthread_mutex_t lock; long start_time; long stop_time; int single_test; }

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; }


original_code:
extern void test_init(int argc, char** argv, TestContext *tc)
{
  bzero(tc,sizeof(TestContext));
  if (argc > 1)
  {
    int argument;
    for (argument = 1; argument<argc; argument++)
    {
      if (strncmp(argv[argument],"-v",sizeof("-v")-1) == 0) tc->verbose = 1 ;
      if (strncmp(argv[argument],"--verbose",sizeof("--verbose")-1) == 0) tc->verbose = 1 ;
      if (strncmp(argv[argument],"-d",sizeof("-d")-1) == 0) { proto_debug_on() ; tc->verbose=1; }
      if (strncmp(argv[argument],"--debug",sizeof("--debug")-1) == 0){ proto_debug_on() ; tc->verbose=1;}
      if (strncmp(argv[argument],"--only",sizeof("--only")-1) == 0)
      {
        if (argument+1<argc)
        {
          int only;
          if ( (only = atoi(argv[argument+1]) ) >0 )
          {
            tc->single_test = only;
          }
        }
      }
    }
  }
  tc->pass=0;
  tc->fail=0;
  tc->num =0;
  tc->start_time = time(((void *)0));
  fprintf(stderr,"\n" "\033[95m" "%s---------------------\n" "\033[0m" "\n",argv[0]);
}

canonical_original_code:
extern void test_init(int argc, char **argv, struct TestContext *tc)
{
  bzero(tc,sizeof(TestContext));
  if (argc > 1)
  {
    int argument;
    for (argument = 1; argument<argc; argument++)
    {
      if (strncmp(argv[argument],"-v",sizeof("-v")-1) == 0) tc->verbose = 1 ;
      if (strncmp(argv[argument],"--verbose",sizeof("--verbose")-1) == 0) tc->verbose = 1 ;
      if (strncmp(argv[argument],"-d",sizeof("-d")-1) == 0) { proto_debug_on() ; tc->verbose=1; }
      if (strncmp(argv[argument],"--debug",sizeof("--debug")-1) == 0){ proto_debug_on() ; tc->verbose=1;}
      if (strncmp(argv[argument],"--only",sizeof("--only")-1) == 0)
      {
        if (argument+1<argc)
        {
          int only;
          if ( (only = atoi(argv[argument+1]) ) >0 )
          {
            tc->single_test = only;
          }
        }
      }
    }
  }
  tc->pass=0;
  tc->fail=0;
  tc->num =0;
  tc->start_time = time(((void *)0));
  fprintf(stderr,"\n" "\033[95m" "%s---------------------\n" "\033[0m" "\n",argv[0]);
}

variable_types: argc int

variable_types:
argv
char **

variable_types: argument int

variable_types: only int

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


decompiled_code:
__int64 __fastcall net_listen(int a1)
{
int v1; // er8
__int64 result; // rax
int *v3; // rax

v1 = listen(a1, 1024);
result = 1LL;
if ( v1 < 0 )
{
v3 = _errno_location();
fprintf(stderr, "Error: EventListen listen failed (%d)\n", (unsigned int)*v3);
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(int a1)
{
int v1; // er8
__int64 result; // rax
int *v3; // rax

v1 = listen(a1, 1024);
result = 1LL;
if ( v1 < 0 )
{
v3 = _errno_location();
fprintf(stderr, "Error: EventListen listen failed (%d)\n", (unsigned int)*v3);
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
extern int
net_listen(FDType fd)
{
  if (listen(fd, 1024) < 0) {
    fprintf(stderr, "Error: EventListen listen failed (%d)\n", (*__errno_location ()));
    return -1;
  }
  return 1;
}

canonical_original_code:
extern int net_listen(int fd)
{
  if (listen(fd, 1024) < 0) {
    fprintf(stderr, "Error: EventListen listen failed (%d)\n", (*__errno_location ()));
    return -1;
  }
  return 1;
}

variable_types: fd int

return_type: int


decompiled_code:
int __fastcall net_accept(int a1)
{
return accept(a1, 0LL, 0LL);
}

canonical_decompiled_code:
int __fastcall func3(int a1)
{
return accept(a1, 0LL, 0LL);
}

original_code:
extern FDType
net_accept(FDType fd)
{
  FDType nfd;
  nfd=accept(fd, ((void *)0), ((void *)0));
  return nfd;
}

canonical_original_code:
extern int net_accept(int fd)
{
  int nfd;
  nfd=accept(fd, ((void *)0), ((void *)0));
  return nfd;
}

variable_types: nfd int


decompiled_code:
__int64 __fastcall net_setup_listen_socket(int *a1, int *a2)
{
int v3; // eax
int v4; // ebp
int v5; // eax
int v6; // edi
__int64 v8; // rdx
int *v9; // rax
char *v10; // rax
int *v11; // rax
__int64 v12; // rdx
int optval; // [rsp+8h] [rbp-30h] BYREF
socklen_t len; // [rsp+Ch] [rbp-2Ch] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-28h] BYREF

optval = 1;
len = 16;
v3 = socket(2, 1, 6);
if ( v3 < 0 )
{
v11 = _errno_location();
fprintf(stderr, "Error: server socket create failed (%d)\n", (unsigned int)*v11);
exit(1);
}
v4 = v3;
if ( setsockopt(v3, 1, 2, &optval, 4u) )
{
v9 = _errno_location();
v10 = strerror(*v9);
fprintf(stderr, "setsockopt(SO_REUSEADDR): %s\n", v10);
exit(1);
}
addr = 0LL;
addr.sa_family = 2;
v5 = _bswap_32_constprop_0();
v6 = *a2;
*(_DWORD *)&addr.sa_data[2] = v5;
if ( v6 )
*(_WORD *)addr.sa_data = _bswap_16(v6);
if ( bind(v4, &addr, len) < 0 )
{
v8 = (unsigned int)*_errno_location();
fprintf(stderr, "Error: server bind failed (%d)\n", v8);
goto LABEL_11;
}
if ( !*a2 )
{
if ( getsockname(v4, &addr, &len) >= 0 )
{
*a2 = (unsigned __int16)_bswap_16(*(__int16 *)addr.sa_data);
goto LABEL_7;
}
v12 = (unsigned int)*_errno_location();
fprintf(stderr, "Error server getsocketname failed (%d)\n", v12);
LABEL_11:
close(v4);
exit(1);
}
LABEL_7:
*a1 = v4;
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func4(int *a1, int *a2)
{
int v3; // eax
int v4; // ebp
int v5; // eax
int v6; // edi
__int64 v8; // rdx
int *v9; // rax
char *v10; // rax
int *v11; // rax
__int64 v12; // rdx
int optval; // [rsp+8h] [rbp-30h] BYREF
socklen_t len; // [rsp+Ch] [rbp-2Ch] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-28h] BYREF

optval = 1;
len = 16;
v3 = socket(2, 1, 6);
if ( v3 < 0 )
{
v11 = _errno_location();
fprintf(stderr, "Error: server socket create failed (%d)\n", (unsigned int)*v11);
exit(1);
}
v4 = v3;
if ( setsockopt(v3, 1, 2, &optval, 4u) )
{
v9 = _errno_location();
v10 = strerror(*v9);
fprintf(stderr, "setsockopt(SO_REUSEADDR): %s\n", v10);
exit(1);
}
addr = 0LL;
addr.sa_family = 2;
v5 = func1();
v6 = *a2;
*(_DWORD *)&addr.sa_data[2] = v5;
if ( v6 )
*(_WORD *)addr.sa_data = func0(v6);
if ( bind(v4, &addr, len) < 0 )
{
v8 = (unsigned int)*_errno_location();
fprintf(stderr, "Error: server bind failed (%d)\n", v8);
goto LABEL_11;
}
if ( !*a2 )
{
if ( getsockname(v4, &addr, &len) >= 0 )
{
*a2 = (unsigned __int16)func0(*(__int16 *)addr.sa_data);
goto LABEL_7;
}
v12 = (unsigned int)*_errno_location();
fprintf(stderr, "Error server getsocketname failed (%d)\n", v12);
LABEL_11:
close(v4);
exit(1);
}
LABEL_7:
*a1 = v4;
return 1LL;
}

original_code:
extern int
net_setup_listen_socket(FDType *fd, PortType *port)
{
    struct sockaddr_in name;
    int one = 1;
    FDType fd_listen;
    socklen_t addrLen = sizeof(struct sockaddr);
    int rc;
    fd_listen = socket(2, SOCK_STREAM, IPPROTO_TCP);
    if (fd_listen < 0) {
        fprintf(stderr, "Error: server socket create failed (%d)\n", (*__errno_location ()));
        exit(1);
    }
    rc = setsockopt(fd_listen, 1, 2, &one, sizeof(one));
    if (rc != 0) {
        fprintf(stderr, "setsockopt(SO_REUSEADDR): %s\n", strerror((*__errno_location ())));
        exit(1);
    }
    bzero(&name, sizeof(name));
    name.sin_family = 2;
    name.sin_addr.s_addr = htonl(((in_addr_t) 0x00000000));
    if (*port) name.sin_port = htons(*port);
    else name.sin_port = 0;
    rc = bind(fd_listen, (struct sockaddr *)&name, addrLen);
    if (rc < 0) {
        fprintf(stderr, "Error: server bind failed (%d)\n", (*__errno_location ()));
        close (fd_listen);
        exit(1);
    }
    if (*port == 0) {
        rc = getsockname(fd_listen, (struct sockaddr *)&name, &addrLen);
        if (rc < 0) {
            fprintf(stderr, "Error server getsocketname failed (%d)\n", (*__errno_location ()));
            close(fd_listen);
            exit(1);
        }
        *port = ntohs(name.sin_port);
    }
    *fd = fd_listen;
    return 1;
}

canonical_original_code:
extern int net_setup_listen_socket(int *fd, int *port)
{
    struct sockaddr_in name;
    int one = 1;
    int fd_listen;
    unsigned int addrLen = sizeof(struct sockaddr);
    int rc;
    fd_listen = socket(2, SOCK_STREAM, IPPROTO_TCP);
    if (fd_listen < 0) {
        fprintf(stderr, "Error: server socket create failed (%d)\n", (*__errno_location ()));
        exit(1);
    }
    rc = setsockopt(fd_listen, 1, 2, &one, sizeof(one));
    if (rc != 0) {
        fprintf(stderr, "setsockopt(SO_REUSEADDR): %s\n", strerror((*__errno_location ())));
        exit(1);
    }
    bzero(&name, sizeof(name));
    name.sin_family = 2;
    name.sin_addr.s_addr = htonl(((unsigned int) 0x00000000));
    if (*port) name.sin_port = htons(*port);
    else name.sin_port = 0;
    rc = bind(fd_listen, (struct sockaddr *)&name, addrLen);
    if (rc < 0) {
        fprintf(stderr, "Error: server bind failed (%d)\n", (*__errno_location ()));
        close (fd_listen);
        exit(1);
    }
    if (*port == 0) {
        rc = getsockname(fd_listen, (struct sockaddr *)&name, &addrLen);
        if (rc < 0) {
            fprintf(stderr, "Error server getsocketname failed (%d)\n", (*__errno_location ()));
            close(fd_listen);
            exit(1);
        }
        *port = ntohs(name.sin_port);
    }
    *fd = fd_listen;
    return 1;
}

variable_types:
fd
int *

variable_types:
port
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: one int

variable_types:
addrLen
unsigned int

variable_types: rc int

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

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


decompiled_code:
__int64 __fastcall net_setup_connection(int *a1, const char *a2, unsigned int a3)
{
struct hostent *v4; // rax
int v5; // edx
int v6; // eax
__int64 v7; // rcx
socklen_t v8; // edx
int v9; // er8
int v10; // er8
__int64 result; // rax
struct sockaddr v12; // [rsp+0h] [rbp-38h] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-28h] BYREF

v4 = gethostbyname(a2);
if ( v4 )
{
addr.sa_family = v4->h_addrtype;
memcpy(&addr.sa_data[2], *(const void **)v4->h_addr_list, v4->h_length);
*(_WORD *)addr.sa_data = _bswap_16(a3);
v6 = socket(2, 1, v5);
*a1 = v6;
if ( v6 < 0 )
{
fwrite("unable to create socket", 1uLL, 0x17uLL, stderr);
perror("oops ");
result = 0xFFFFFFFFLL;
}
else
{
v12.sa_family = 2;
*(_DWORD *)&v12.sa_data[2] = _bswap_32_constprop_0(0LL, &v12, 16LL, v7, (unsigned int)v6);
*(_WORD *)v12.sa_data = _bswap_16(0);
if ( bind(v9, &v12, v8) < 0 )
{
fprintf(stderr, "cannot bind port TCP %u\n", a3);
perror("oops ");
result = 0xFFFFFFFFLL;
}
else
{
v10 = connect(*a1, &addr, 0x10u);
result = 1LL;
if ( v10 < 0 )
{
perror("cannot connect ");
result = 0xFFFFFFFFLL;
}
}
}
}
else
{
fprintf(stderr, "unknown host '%s'\n", a2);
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(int *a1, const char *a2, unsigned int a3)
{
struct hostent *v4; // rax
int v5; // edx
int v6; // eax
__int64 v7; // rcx
socklen_t v8; // edx
int v9; // er8
int v10; // er8
__int64 result; // rax
struct sockaddr v12; // [rsp+0h] [rbp-38h] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-28h] BYREF

v4 = gethostbyname(a2);
if ( v4 )
{
addr.sa_family = v4->h_addrtype;
memcpy(&addr.sa_data[2], *(const void **)v4->h_addr_list, v4->h_length);
*(_WORD *)addr.sa_data = func0(a3);
v6 = socket(2, 1, v5);
*a1 = v6;
if ( v6 < 0 )
{
fwrite("unable to create socket", 1uLL, 0x17uLL, stderr);
perror("oops ");
result = 0xFFFFFFFFLL;
}
else
{
v12.sa_family = 2;
*(_DWORD *)&v12.sa_data[2] = func1(0LL, &v12, 16LL, v7, (unsigned int)v6);
*(_WORD *)v12.sa_data = func0(0);
if ( bind(v9, &v12, v8) < 0 )
{
fprintf(stderr, "cannot bind port TCP %u\n", a3);
perror("oops ");
result = 0xFFFFFFFFLL;
}
else
{
v10 = connect(*a1, &addr, 0x10u);
result = 1LL;
if ( v10 < 0 )
{
perror("cannot connect ");
result = 0xFFFFFFFFLL;
}
}
}
}
else
{
fprintf(stderr, "unknown host '%s'\n", a2);
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
extern int
net_setup_connection(FDType *fd, char *host, PortType port)
{
    int rc;
    struct sockaddr_in localAddr, servAddr;
    struct hostent *h;
    h = gethostbyname(host);
    if (h == ((void *)0)) {
        fprintf(stderr, "unknown host '%s'\n", host);
        return -1;
    }
    servAddr.sin_family = h->h_addrtype;
    memcpy((char *) &servAddr.sin_addr.s_addr, h->h_addr_list[0], h->h_length);
    servAddr.sin_port = htons(port);
    *fd = socket(2, SOCK_STREAM, 0);
    if (*fd<0) {
        fprintf(stderr, "unable to create socket");
        perror("oops ");
        return -1;
    }
    localAddr.sin_family = 2;
    localAddr.sin_addr.s_addr = htonl(((in_addr_t) 0x00000000));
    localAddr.sin_port = htons(0);
    rc = bind(*fd, (struct sockaddr *)&localAddr, sizeof(localAddr));
    if (rc<0) {
        fprintf(stderr, "cannot bind port TCP %u\n", port);
        perror("oops ");
        return -1;
    }
    rc = connect(*fd, (struct sockaddr *) &servAddr, sizeof(servAddr));
    if (rc<0) {
        perror("cannot connect ");
        return -1;
    }
    return 1;
}

canonical_original_code:
extern int net_setup_connection(int *fd, char *host, int port)
{
    int rc;
    struct sockaddr_in localAddr; struct sockaddr_in servAddr;
    struct hostent *h;
    h = gethostbyname(host);
    if (h == ((void *)0)) {
        fprintf(stderr, "unknown host '%s'\n", host);
        return -1;
    }
    servAddr.sin_family = h->h_addrtype;
    memcpy((char *) &servAddr.sin_addr.s_addr, h->h_addr_list[0], h->h_length);
    servAddr.sin_port = htons(port);
    *fd = socket(2, SOCK_STREAM, 0);
    if (*fd<0) {
        fprintf(stderr, "unable to create socket");
        perror("oops ");
        return -1;
    }
    localAddr.sin_family = 2;
    localAddr.sin_addr.s_addr = htonl(((unsigned int) 0x00000000));
    localAddr.sin_port = htons(0);
    rc = bind(*fd, (struct sockaddr *)&localAddr, sizeof(localAddr));
    if (rc<0) {
        fprintf(stderr, "cannot bind port TCP %u\n", port);
        perror("oops ");
        return -1;
    }
    rc = connect(*fd, (struct sockaddr *) &servAddr, sizeof(servAddr));
    if (rc<0) {
        perror("cannot connect ");
        return -1;
    }
    return 1;
}

variable_types:
host
char *

variable_types: port int

variable_types: struct hostent { char *h_name; char **h_aliases; int h_addrtype; int h_length; char **h_addr_list; } *


decompiled_code:
size_t __fastcall net_writen(int fd, void *buf, size_t n)
{
size_t v3; // r13
size_t v5; // rbx
ssize_t v6; // rax

v3 = n;
v5 = n;
if ( !n )
return v3;
do
{
while ( 1 )
{
v6 = send(fd, buf, v5, 0x4000);
if ( v6 <= 0 )
break;
buf = (char *)buf + v6;
v5 -= v6;
if ( !v5 )
return v3;
}
}
while ( v6 && *_errno_location() == 4 );
return -1LL;
}

canonical_decompiled_code:
size_t __fastcall func6(int fd, void *buf, size_t n)
{
size_t v3; // r13
size_t v5; // rbx
ssize_t v6; // rax

v3 = n;
v5 = n;
if ( !n )
return v3;
do
{
while ( 1 )
{
v6 = send(fd, buf, v5, 0x4000);
if ( v6 <= 0 )
break;
buf = (char *)buf + v6;
v5 -= v6;
if ( !v5 )
return v3;
}
}
while ( v6 && *_errno_location() == 4 );
return -1LL;
}

original_code:
extern ssize_t
net_writen(FDType fd, const void *vptr, size_t n)
{
  size_t nleft;
  ssize_t nwritten;
  const char *ptr;
  ptr = vptr;
  nleft = n;
  while (nleft > 0) {
    if ( (nwritten = send(fd, ptr, nleft, MSG_NOSIGNAL)) <= 0) {
      if (nwritten < 0 && (*__errno_location ()) == 4)
  nwritten = 0;
      else
  return(-1);
    }
    nleft -= nwritten;
    ptr += nwritten;
  }
  return(n);
}

canonical_original_code:
extern long net_writen(int fd, void *vptr, unsigned long n)
{
  unsigned long nleft;
  long nwritten;
  char *ptr;
  ptr = vptr;
  nleft = n;
  while (nleft > 0) {
    if ( (nwritten = send(fd, ptr, nleft, MSG_NOSIGNAL)) <= 0) {
      if (nwritten < 0 && (*__errno_location ()) == 4)
  nwritten = 0;
      else
  return(-1);
    }
    nleft -= nwritten;
    ptr += nwritten;
  }
  return(n);
}

variable_types:
vptr
void *

variable_types:
n
unsigned long

variable_types:
nleft
unsigned long

variable_types: nwritten long

variable_types:
ptr
char *

return_type: long


decompiled_code:
size_t __fastcall net_readn(int fd, void *buf, size_t n)
{
size_t v3; // r13
size_t v5; // rbx
ssize_t v6; // rax

v3 = n;
v5 = n;
if ( n )
{
while ( 1 )
{
while ( 1 )
{
v6 = recv(fd, buf, v5, 0x4000);
if ( v6 >= 0 )
break;
if ( *_errno_location() != 4 )
return -1LL;
}
if ( !v6 )
break;
buf = (char *)buf + v6;
v5 -= v6;
if ( !v5 )
return v3;
}
v3 -= v5;
}
return v3;
}

canonical_decompiled_code:
size_t __fastcall func7(int fd, void *buf, size_t n)
{
size_t v3; // r13
size_t v5; // rbx
ssize_t v6; // rax

v3 = n;
v5 = n;
if ( n )
{
while ( 1 )
{
while ( 1 )
{
v6 = recv(fd, buf, v5, 0x4000);
if ( v6 >= 0 )
break;
if ( *_errno_location() != 4 )
return -1LL;
}
if ( !v6 )
break;
buf = (char *)buf + v6;
v5 -= v6;
if ( !v5 )
return v3;
}
v3 -= v5;
}
return v3;
}

original_code:
extern ssize_t
net_readn(FDType fd, void *vptr, size_t n)
{
  size_t nleft;
  ssize_t nread;
  char *ptr;
  ptr = vptr;
  nleft = n;
  while (nleft > 0) {
    if ( (nread = recv(fd, ptr, nleft, MSG_NOSIGNAL)) < 0) {
      if ((*__errno_location ()) == 4)
 nread = 0;
      else
 return(-1);
    } else if (nread == 0)
      break;
    nleft -= nread;
    ptr += nread;
  }
  return(n - nleft);
}

canonical_original_code:
extern long net_readn(int fd, void *vptr, unsigned long n)
{
  unsigned long nleft;
  long nread;
  char *ptr;
  ptr = vptr;
  nleft = n;
  while (nleft > 0) {
    if ( (nread = recv(fd, ptr, nleft, MSG_NOSIGNAL)) < 0) {
      if ((*__errno_location ()) == 4)
 nread = 0;
      else
 return(-1);
    } else if (nread == 0)
      break;
    nleft -= nread;
    ptr += nread;
  }
  return(n - nleft);
}

variable_types: nread long


engineInit

repo: samirotiv/Tron

decompiled_code:
int engineInit()
{
__int16 v0; // bx
__int16 v1; // bp

initscr();
if ( !stdscr )
{
start_color();
goto LABEL_6;
}
v0 = stdscr->_maxx;
v1 = stdscr->_maxy;
start_color();
if ( v0 <= 78 || v1 <= 22 )
{
LABEL_6:
endwin();
printf(
"Your console screen is smaller than %d x %d\n"
"Please resize your window and try again\n"
"Please note, the set SCREENWIDTH and SCREENHEIGHT in engine.h must be greater than 24x80\n",
80LL,
24LL);
exit(0);
}
raw();
noecho();
keypad(stdscr, 1);
curs_set(0);
nodelay(stdscr, 1);
return wrefresh(stdscr);
}

canonical_decompiled_code:
int func0()
{
__int16 v0; // bx
__int16 v1; // bp

initscr();
if ( !stdscr )
{
start_color();
goto LABEL_6;
}
v0 = stdscr->_maxx;
v1 = stdscr->_maxy;
start_color();
if ( v0 <= 78 || v1 <= 22 )
{
LABEL_6:
endwin();
printf(
"Your console screen is smaller than %d x %d\n"
"Please resize your window and try again\n"
"Please note, the set SCREENWIDTH and SCREENHEIGHT in engine.h must be greater than 24x80\n",
80LL,
24LL);
exit(0);
}
raw();
noecho();
keypad(stdscr, 1);
curs_set(0);
nodelay(stdscr, 1);
return wrefresh(stdscr);
}

original_code:
void engineInit(){
    (void) initscr();
    int current_height, current_width;
 (current_height = ((0 != (const void *)((stdscr))) ? ((stdscr)->_maxy + 1) : (-1)), current_width = ((0 != (const void *)((stdscr))) ? ((stdscr)->_maxx + 1) : (-1)));
 start_color();
 if ((current_width < 80) || (current_height < 24) || (24 < 24) || (80 < 80)){
        endwin();
        printf ("Your console screen is smaller than %d x %d\nPlease resize your window and try again\nPlease note, the set SCREENWIDTH and SCREENHEIGHT in engine.h must be greater than 24x80\n", 80, 24);
        exit(0);
    }
    raw();
    noecho();
    keypad(stdscr, 1);
    curs_set(0);
    nodelay(stdscr, 1);
    wrefresh(stdscr);
}

canonical_original_code:
void engineInit(){
    (void) initscr();
    int current_height; int current_width;
 (current_height = ((0 != (void *)((stdscr))) ? ((stdscr)->_maxy + 1) : (-1)), current_width = ((0 != (void *)((stdscr))) ? ((stdscr)->_maxx + 1) : (-1)));
 start_color();
 if ((current_width < 80) || (current_height < 24) || (24 < 24) || (80 < 80)){
        endwin();
        printf ("Your console screen is smaller than %d x %d\nPlease resize your window and try again\nPlease note, the set SCREENWIDTH and SCREENHEIGHT in engine.h must be greater than 24x80\n", 80, 24);
        exit(0);
    }
    raw();
    noecho();
    keypad(stdscr, 1);
    curs_set(0);
    nodelay(stdscr, 1);
    wrefresh(stdscr);
}


engineStartMenuEnvironment

decompiled_code:
int engineStartMenuEnvironment()
{
nodelay(stdscr, 0);
werase(stdscr);
wrefresh(stdscr);
return flushinp();
}

canonical_decompiled_code:
int func1()
{
nodelay(stdscr, 0);
werase(stdscr);
wrefresh(stdscr);
return flushinp();
}

original_code:
void engineStartMenuEnvironment(){
    nodelay(stdscr, 0);
    werase(stdscr);
    wrefresh(stdscr);
    flushinp();
    return;
}


engineDrawWalls

decompiled_code:
int engineDrawWalls()
{
__int64 v0; // rbx
WINDOW *v1; // rdi
unsigned __int64 v2; // rbp
int i; // ebx
int result; // eax

v0 = 0LL;
wattrset(stdscr, 1024);
werase(stdscr);
wbkgd(stdscr, 0x400uLL);
wattrset(stdscr, 768);
do
{
if ( wmove(stdscr, v0, 0) != -1 )
waddch(stdscr, 0x20uLL);
v1 = stdscr;
game[v0 + 13] = 87;
if ( wmove(v1, v0, 79) != -1 )
waddch(stdscr, 0x20uLL);
game[v0++ + 1909] = 87;
}
while ( v0 != 24 );
v2 = (unsigned int)((_DWORD)game + 13);
for ( i = 0; i != 80; ++i )
{
if ( wmove(stdscr, 0, i) != -1 )
waddch(stdscr, 0x20uLL);
*(_BYTE *)v2 = 87;
result = wmove(stdscr, 23, i);
if ( result != -1 )
result = waddch(stdscr, 0x20uLL);
*(_BYTE *)(v2 + 23) = 87;
v2 += 24LL;
}
return result;
}

canonical_decompiled_code:
int func2()
{
__int64 v0; // rbx
WINDOW *v1; // rdi
unsigned __int64 v2; // rbp
int i; // ebx
int result; // eax

v0 = 0LL;
wattrset(stdscr, 1024);
werase(stdscr);
wbkgd(stdscr, 0x400uLL);
wattrset(stdscr, 768);
do
{
if ( wmove(stdscr, v0, 0) != -1 )
waddch(stdscr, 0x20uLL);
v1 = stdscr;
game[v0 + 13] = 87;
if ( wmove(v1, v0, 79) != -1 )
waddch(stdscr, 0x20uLL);
game[v0++ + 1909] = 87;
}
while ( v0 != 24 );
v2 = (unsigned int)((_DWORD)game + 13);
for ( i = 0; i != 80; ++i )
{
if ( wmove(stdscr, 0, i) != -1 )
waddch(stdscr, 0x20uLL);
*(_BYTE *)v2 = 87;
result = wmove(stdscr, 23, i);
if ( result != -1 )
result = waddch(stdscr, 0x20uLL);
*(_BYTE *)(v2 + 23) = 87;
v2 += 24LL;
}
return result;
}

variable_types: y int

variable_types: x int


engineClearMap

decompiled_code:
__int64 engineClearMap()
{
__int64 result; // rax

result = 0LL;
*(_QWORD *)&game[13] = 0LL;
*(_QWORD *)&game[1925] = 0LL;
memset(
(void *)(((_DWORD)game + 21) & 0xFFFFFFF8),
0,
8LL * (((_DWORD)game + 13 - (((_DWORD)game + 21) & 0xFFFFFFF8) + 1920) >> 3));
return result;
}

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

result = 0LL;
*(_QWORD *)&game[13] = 0LL;
*(_QWORD *)&game[1925] = 0LL;
memset(
(void *)(((_DWORD)game + 21) & 0xFFFFFFF8),
0,
8LL * (((_DWORD)game + 13 - (((_DWORD)game + 21) & 0xFFFFFFF8) + 1920) >> 3));
return result;
}

original_code:
void engineClearMap(){
    int i, j;
    for (i=0; i<80; i++){
        for (j=0; j<24; j++){
            game.map[i][j] = 0;
        }
    }
}

canonical_original_code:
void engineClearMap(){
    int i; int j;
    for (i=0; i<80; i++){
        for (j=0; j<24; j++){
            game.map[i][j] = 0;
        }
    }
}

variable_types: i int

variable_types: j int


engineStartGameEnvironment

decompiled_code:
int engineStartGameEnvironment()
{
nodelay(stdscr, 1);
engineClearMap();
engineDrawWalls();
snakeInit();
*(_DWORD *)&game[8] = *(_DWORD *)&game[4];
init_pair(1, 4, 4);
init_pair(2, 1, 1);
init_pair(5, 0, 0);
init_pair(6, 0, 0);
init_pair(3, 0, 0);
init_pair(4, 0, 7);
wrefresh(stdscr);
return flushinp();
}

canonical_decompiled_code:
int func4()
{
nodelay(stdscr, 1);
func3();
func2();
snakeInit();
*(_DWORD *)&game[8] = *(_DWORD *)&game[4];
init_pair(1, 4, 4);
init_pair(2, 1, 1);
init_pair(5, 0, 0);
init_pair(6, 0, 0);
init_pair(3, 0, 0);
init_pair(4, 0, 7);
wrefresh(stdscr);
return flushinp();
}

original_code:
void engineStartGameEnvironment(){
    nodelay(stdscr, 1);
    engineClearMap();
    engineDrawWalls();
    snakeInit();
    game.depth = game.difficulty;
    init_pair(1, 4, 4);
    init_pair(2, 1, 1);
    init_pair(5, 0, 0);
    init_pair(6, 0, 0);
    init_pair(3, 0, 0);
    init_pair(4, 0, 7);
    wrefresh(stdscr);
    flushinp();
    return;
}


engineProcessGameWinner

decompiled_code:
__int64 engineProcessGameWinner()
{
__int64 result; // rax

result = *((unsigned int *)&snake2 + 1);
if ( *((_DWORD *)&snake1 + 1) == (_DWORD)result
&& (result = *((unsigned int *)&snake2 + 2), *((_DWORD *)&snake1 + 2) == (_DWORD)result) )
{
snake2 = 0;
snake1 = 0;
}
else
{
if ( snake1 )
{
game[12] = 1;
return result;
}
if ( snake2 )
{
game[12] = 2;
return result;
}
}
game[12] = 0;
return result;
}

canonical_decompiled_code:
__int64 func5()
{
__int64 result; // rax

result = *((unsigned int *)&snake2 + 1);
if ( *((_DWORD *)&snake1 + 1) == (_DWORD)result
&& (result = *((unsigned int *)&snake2 + 2), *((_DWORD *)&snake1 + 2) == (_DWORD)result) )
{
snake2 = 0;
snake1 = 0;
}
else
{
if ( snake1 )
{
game[12] = 1;
return result;
}
if ( snake2 )
{
game[12] = 2;
return result;
}
}
game[12] = 0;
return result;
}

original_code:
void engineProcessGameWinner(){
    if ((snake1.head.x == snake2.head.x) && (snake1.head.y == snake2.head.y)) snake1.alive = snake2.alive = 0;
    if (snake1.alive != 0) game.winner = 1;
    else if (snake2.alive != 0) game.winner = 2;
    else game.winner = 0;
}


engineSleepAndCallBot

decompiled_code:
__int64 __fastcall engineSleepAndCallBot(__int64 a1, __int64 a2, __useconds_t a3)
{
int v4; // eax
__int64 result; // rax
pthread_t th; // [rsp+0h] [rbp-28h] BYREF
void *thread_return; // [rsp+8h] [rbp-20h] BYREF
__int64 arg[3]; // [rsp+10h] [rbp-18h] BYREF

v4 = *(_DWORD *)(a1 + 12);
doneflag = 0;
arg[0] = a1;
*(_DWORD *)(a1 + 24) = v4;
arg[1] = a2;
pthread_create(&th, 0LL, (void *(*)(void *))&aiProcessGame, arg);
usleep(a3);
pthread_cancel(th);
pthread_join(th, &thread_return);
result = doneflag;
if ( doneflag == 1 )
{
if ( counter_0 <= 0 )
{
result = game[2];
if ( (int)result < (int)game[1] )
{
result = (unsigned int)(result + 1);
game[2] = result;
}
}
else
{
result = (unsigned int)--counter_0;
}
}
else if ( !doneflag )
{
--game[2];
counter_0 = 30;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, __int64 a2, __useconds_t a3)
{
int v4; // eax
__int64 result; // rax
pthread_t th; // [rsp+0h] [rbp-28h] BYREF
void *thread_return; // [rsp+8h] [rbp-20h] BYREF
__int64 arg[3]; // [rsp+10h] [rbp-18h] BYREF

v4 = *(_DWORD *)(a1 + 12);
doneflag = 0;
arg[0] = a1;
*(_DWORD *)(a1 + 24) = v4;
arg[1] = a2;
pthread_create(&th, 0LL, (void *(*)(void *))&aiProcessGame, arg);
usleep(a3);
pthread_cancel(th);
pthread_join(th, &thread_return);
result = doneflag;
if ( doneflag == 1 )
{
if ( counter_0 <= 0 )
{
result = game[2];
if ( (int)result < (int)game[1] )
{
result = (unsigned int)(result + 1);
game[2] = result;
}
}
else
{
result = (unsigned int)--counter_0;
}
}
else if ( !doneflag )
{
--game[2];
counter_0 = 30;
}
return result;
}

original_code:
void engineSleepAndCallBot(struct snakestructure* botsnakepointer, struct snakestructure* usrsnakepointer, long int usleeptime){
    struct timespec timeout;
    pthread_t aithread;
    int error = 0;
    void *exitstatus;
    static int counter;
    botsnakepointer->bot_newdirection = botsnakepointer->direction;
    struct snakestructure* snakes[] = {botsnakepointer, usrsnakepointer};
    doneflag = 0;
    pthread_create(&aithread, ((void *)0), aiProcessGame, snakes);
    usleep(usleeptime);
    error = pthread_cancel(aithread);
    error = pthread_join(aithread, &exitstatus);
    if (doneflag == 1) {
        if (counter > 0) counter--;
        else if (game.depth < game.difficulty) game.depth++;
    }
    if (doneflag == 0) {
        counter = 30;
        game.depth--;
    }
    return;
}

canonical_original_code:
void engineSleepAndCallBot(struct snakestructure *botsnakepointer, struct snakestructure *usrsnakepointer, long usleeptime){
    struct timespec timeout;
    unsigned long aithread;
    int error = 0;
    void *exitstatus;
    static int counter;
    botsnakepointer->bot_newdirection = botsnakepointer->direction;
    struct snakestructure *snakes[] = {botsnakepointer, usrsnakepointer};
    doneflag = 0;
    pthread_create(&aithread, ((void *)0), aiProcessGame, snakes);
    usleep(usleeptime);
    error = pthread_cancel(aithread);
    error = pthread_join(aithread, &exitstatus);
    if (doneflag == 1) {
        if (counter > 0) counter--;
        else if (game.depth < game.difficulty) game.depth++;
    }
    if (doneflag == 0) {
        counter = 30;
        game.depth--;
    }
    return;
}

variable_types:
usrsnakepointer
struct snakestructure *

variable_types: usleeptime long

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

variable_types:
aithread
unsigned long

variable_types: error int

variable_types:
exitstatus
void *

variable_types: counter int

variable_types: struct snakestructure { char alive; struct point { int x; int y; } head; int direction; int size; char marker; char colorcode; char headcolorcode; int bot_newdirection; } *[]

user_defined_types: struct snakestructure { char alive; struct point head; int direction; int size; char marker; char colorcode; char headcolorcode; int bot_newdirection; }


InitQueue

original_code:
void InitQueue (queue* q, int* array, int arraysize){
    q->size = q->front = q->behindback = 0;
    q->maxqueuesize = arraysize;
    if (array != ((void *)0)){
        q->data = array;
    }
    else{
        q->data = (int*) malloc ((q->maxqueuesize + 1) * sizeof(int));
    }
}

canonical_original_code:
void InitQueue(struct queue_ *q, int *array, int arraysize){
    q->size = q->front = q->behindback = 0;
    q->maxqueuesize = arraysize;
    if (array != ((void *)0)){
        q->data = array;
    }
    else{
        q->data = (int *) malloc ((q->maxqueuesize + 1) * sizeof(int));
    }
}

variable_types: struct queue_ { int *data; int maxqueuesize; int front; int behindback; int lastenqueued; int size; } *

variable_types:
array
int *

variable_types: arraysize int


enqueue

original_code:
void enqueue (queue* q, int val){
    if ((q->size == 0) || (q->behindback != q->front)){
        q->size++;
        q->data[q->behindback] = val;
        q->lastenqueued = val;
        q->behindback = (q->behindback + 1) % q->maxqueuesize;
    }
}

canonical_original_code:
void enqueue(struct queue_ *q, int val){
    if ((q->size == 0) || (q->behindback != q->front)){
        q->size++;
        q->data[q->behindback] = val;
        q->lastenqueued = val;
        q->behindback = (q->behindback + 1) % q->maxqueuesize;
    }
}

variable_types: val int

user_defined_types: struct queue_ { int *data; int maxqueuesize; int front; int behindback; int lastenqueued; int size; }


dequeue

original_code:
int dequeue (queue* q){
    if (q->size > 0){
        q->size--;
        int returnvalue = q->data[q->front];
        q->front = (q->front + 1) % q->maxqueuesize;
        return returnvalue;
    }
    else return 0;
}

canonical_original_code:
int dequeue(struct queue_ *q){
    if (q->size > 0){
        q->size--;
        int returnvalue = q->data[q->front];
        q->front = (q->front + 1) % q->maxqueuesize;
        return returnvalue;
    }
    else return 0;
}

variable_types: returnvalue int


FreeQueue

decompiled_code:
void __fastcall FreeQueue(void **a1)
{
free(*a1);
}

canonical_decompiled_code:
void __fastcall func10(void **a1)
{
free(*a1);
}

original_code:
void FreeQueue (queue* q){
    free(q->data);
}

canonical_original_code:
void FreeQueue(struct queue_ *q){
    free(q->data);
}


menuGetInput

decompiled_code:
__int64 __fastcall menuGetInput(_DWORD *a1, int *a2)
{
int v2; // eax
_BOOL4 v3; // er8

nodelay(stdscr, 0);
v2 = wgetch(stdscr);
if ( v2 == 258 )
{
gamemode = 2;
return 1;
}
if ( v2 <= 258 )
{
if ( v2 <= 52 )
{
if ( v2 <= 48 )
{
v3 = 0;
if ( v2 != 10 )
v3 = v2 != 32;
return v3;
}
*a1 = v2 - 48;
return 1LL;
}
if ( (v2 & 0xFFFFFFDF) != 81 )
return 1LL;
ExitGame();
return 1;
}
if ( v2 == 260 )
{
v3 = 1;
if ( *a2 > 1 )
--*a2;
return v3;
}
if ( v2 == 261 )
{
v3 = 1;
if ( *a2 <= 3 )
++*a2;
return v3;
}
if ( v2 != 259 )
return 1LL;
gamemode = 1;
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(_DWORD *a1, int *a2)
{
int v2; // eax
_BOOL4 v3; // er8

nodelay(stdscr, 0);
v2 = wgetch(stdscr);
if ( v2 == 258 )
{
gamemode = 2;
return 1;
}
if ( v2 <= 258 )
{
if ( v2 <= 52 )
{
if ( v2 <= 48 )
{
v3 = 0;
if ( v2 != 10 )
v3 = v2 != 32;
return v3;
}
*a1 = v2 - 48;
return 1LL;
}
if ( (v2 & 0xFFFFFFDF) != 81 )
return 1LL;
ExitGame();
return 1;
}
if ( v2 == 260 )
{
v3 = 1;
if ( *a2 > 1 )
--*a2;
return v3;
}
if ( v2 == 261 )
{
v3 = 1;
if ( *a2 <= 3 )
++*a2;
return v3;
}
if ( v2 != 259 )
return 1LL;
gamemode = 1;
return 1LL;
}

original_code:
int menuGetInput(int* speed_cur_option, int* diff_cur_option)
{
 nodelay (stdscr, 0);
 int input = wgetch(stdscr);
 switch (input)
 {
 case 10: case ' ':
  return 0;
  break;
 case 'q': case 'Q':
  ExitGame();
  break;
 case 0403:
   gamemode = 1;
  break;
 case 0402:
   gamemode = 2;
  break;
 case 0404:
  if (*diff_cur_option > 1)
   (*diff_cur_option)--;
  break;
 case 0405:
  if (*diff_cur_option < 4)
   (*diff_cur_option)++;
  break;
 case '1': case '2': case '3': case '4':
  *speed_cur_option = (input - '0');
  break;
 default:
  break;
 }
 return 1;
}

canonical_original_code:
int menuGetInput(int *speed_cur_option, int *diff_cur_option)
{
 nodelay (stdscr, 0);
 int input = wgetch(stdscr);
 switch (input)
 {
 case 10: case ' ':
  return 0;
  break;
 case 'q': case 'Q':
  ExitGame();
  break;
 case 0403:
   gamemode = 1;
  break;
 case 0402:
   gamemode = 2;
  break;
 case 0404:
  if (*diff_cur_option > 1)
   (*diff_cur_option)--;
  break;
 case 0405:
  if (*diff_cur_option < 4)
   (*diff_cur_option)++;
  break;
 case '1': case '2': case '3': case '4':
  *speed_cur_option = (input - '0');
  break;
 default:
  break;
 }
 return 1;
}

variable_types: input int


menuMainMenu

variable_types:
difficultyoptionsarray
int []

variable_types: wait int

variable_types: y int

variable_types: x int


menuEndPrint

decompiled_code:
int __fastcall menuEndPrint(int a1)
{
int i; // ebx
__int64 v2; // r13
int v3; // edx
int v4; // er14
int v5; // ebp
char v6; // al
_BYTE v8[4]; // [rsp+8h] [rbp-40h]
int v9; // [rsp+Ch] [rbp-3Ch]
const char *v10; // [rsp+10h] [rbp-38h]
const char *v11; // [rsp+18h] [rbp-30h]

v10 = "PLAY AGAIN.!";
v11 = "BACK TO MENU";
v9 = 12;
if ( wmove(stdscr, 6, 25) != -1 )
waddnstr(stdscr, " ____________________________ ", -1);
for ( i = 7; i != 17; ++i )
{
if ( wmove(stdscr, i, 25) != -1 )
waddch(stdscr, 0x7CuLL);
if ( wmove(stdscr, i, 54) != -1 )
waddch(stdscr, 0x7CuLL);
}
if ( wmove(stdscr, 16, 25) != -1 )
waddnstr(stdscr, "|____________________________|", -1);
v2 = 1LL;
v3 = 12;
while ( 1 )
{
v4 = v2 + 9;
v5 = (30 - v3) / 2 + 25;
if ( a1 == (_DWORD)v2 )
{
wattr_on(stdscr, 0x10000uLL, 0LL);
wattr_on(stdscr, 0x200000uLL, 0LL);
mvprintw(v4, v5, "%s", *(const char **)&v8[8 * v2]);
wattr_off(stdscr, 0x10000uLL, 0LL);
}
else
{
wattr_on(stdscr, 0x200000uLL, 0LL);
mvprintw(v4, v5, "%s", *(const char **)&v8[8 * v2]);
}
if ( v2 == 2 )
break;
v3 = v9;
v2 = 2LL;
}
wattr_on(stdscr, 0x200000uLL, 0LL);
v6 = game[12];
if ( v6 == 1 )
{
if ( game[0] == 2 )
{
mvprintw(15, 31, "BLUE SNAKE WINS!!!");
}
else if ( game[0] == 1 )
{
mvprintw(15, 35, "YOU WON!!!");
}
}
else if ( v6 == 2 )
{
if ( game[0] == 2 )
{
mvprintw(15, 31, "RED SNAKE WINS!!!");
}
else if ( game[0] == 1 )
{
mvprintw(15, 34, "YOU LOST :D");
}
}
else
{
mvprintw(15, 35, "DRAW GAME");
}
wattr_off(stdscr, 0x200000uLL, 0LL);
return wrefresh(stdscr);
}

canonical_decompiled_code:
int __fastcall func2(int a1)
{
int i; // ebx
__int64 v2; // r13
int v3; // edx
int v4; // er14
int v5; // ebp
char v6; // al
_BYTE v8[4]; // [rsp+8h] [rbp-40h]
int v9; // [rsp+Ch] [rbp-3Ch]
const char *v10; // [rsp+10h] [rbp-38h]
const char *v11; // [rsp+18h] [rbp-30h]

v10 = "PLAY AGAIN.!";
v11 = "BACK TO MENU";
v9 = 12;
if ( wmove(stdscr, 6, 25) != -1 )
waddnstr(stdscr, " ____________________________ ", -1);
for ( i = 7; i != 17; ++i )
{
if ( wmove(stdscr, i, 25) != -1 )
waddch(stdscr, 0x7CuLL);
if ( wmove(stdscr, i, 54) != -1 )
waddch(stdscr, 0x7CuLL);
}
if ( wmove(stdscr, 16, 25) != -1 )
waddnstr(stdscr, "|____________________________|", -1);
v2 = 1LL;
v3 = 12;
while ( 1 )
{
v4 = v2 + 9;
v5 = (30 - v3) / 2 + 25;
if ( a1 == (_DWORD)v2 )
{
wattr_on(stdscr, 0x10000uLL, 0LL);
wattr_on(stdscr, 0x200000uLL, 0LL);
mvprintw(v4, v5, "%s", *(const char **)&v8[8 * v2]);
wattr_off(stdscr, 0x10000uLL, 0LL);
}
else
{
wattr_on(stdscr, 0x200000uLL, 0LL);
mvprintw(v4, v5, "%s", *(const char **)&v8[8 * v2]);
}
if ( v2 == 2 )
break;
v3 = v9;
v2 = 2LL;
}
wattr_on(stdscr, 0x200000uLL, 0LL);
v6 = game[12];
if ( v6 == 1 )
{
if ( game[0] == 2 )
{
mvprintw(15, 31, "BLUE SNAKE WINS!!!");
}
else if ( game[0] == 1 )
{
mvprintw(15, 35, "YOU WON!!!");
}
}
else if ( v6 == 2 )
{
if ( game[0] == 2 )
{
mvprintw(15, 31, "RED SNAKE WINS!!!");
}
else if ( game[0] == 1 )
{
mvprintw(15, 34, "YOU LOST :D");
}
}
else
{
mvprintw(15, 35, "DRAW GAME");
}
wattr_off(stdscr, 0x200000uLL, 0LL);
return wrefresh(stdscr);
}

variable_types: highlight int

variable_types: i int

variable_types:
choices
char *[]


menuEndGame

decompiled_code:
int menuEndGame()
{
int v0; // ebp
int v1; // ebx
int v2; // eax

v0 = 0;
v1 = 1;
engineStartMenuEnvironment();
menuEndPrint(1);
do
{
wrefresh(stdscr);
v2 = wgetch(stdscr);
if ( v2 == 258 )
{
v1 = 2;
}
else if ( v2 > 258 )
{
if ( v2 == 259 )
v1 = 1;
}
else
{
if ( v2 == 81 )
goto LABEL_12;
if ( v2 <= 81 )
{
if ( v2 == 10 )
{
v0 = v1;
}
else if ( v2 == 32 )
{
v0 = v1;
}
}
else if ( v2 == 113 )
{
LABEL_12:
ExitGame();
menuEndPrint(v1);
continue;
}
}
menuEndPrint(v1);
if ( v0 == 1 )
goto LABEL_13;
}
while ( v0 != 2 );
game[0] = 4;
LABEL_13:
wattrset(stdscr, 0);
return wrefresh(stdscr);
}

canonical_decompiled_code:
int func3()
{
int v0; // ebp
int v1; // ebx
int v2; // eax

v0 = 0;
v1 = 1;
engineStartMenuEnvironment();
func2(1);
do
{
wrefresh(stdscr);
v2 = wgetch(stdscr);
if ( v2 == 258 )
{
v1 = 2;
}
else if ( v2 > 258 )
{
if ( v2 == 259 )
v1 = 1;
}
else
{
if ( v2 == 81 )
goto LABEL_12;
if ( v2 <= 81 )
{
if ( v2 == 10 )
{
v0 = v1;
}
else if ( v2 == 32 )
{
v0 = v1;
}
}
else if ( v2 == 113 )
{
LABEL_12:
ExitGame();
func2(v1);
continue;
}
}
func2(v1);
if ( v0 == 1 )
goto LABEL_13;
}
while ( v0 != 2 );
game[0] = 4;
LABEL_13:
wattrset(stdscr, 0);
return wrefresh(stdscr);
}

original_code:
void menuEndGame()
{
 int highlight = 1;
 int choice = 0;
 int c;
 engineStartMenuEnvironment();
 menuEndPrint(highlight);
 while(1)
 {
     wrefresh(stdscr);
     c = wgetch(stdscr);
  switch(c)
  {
      case 0403:
    if(highlight == 2)
     highlight = 1;
    break;
   case 0402:
    if(highlight == 1)
     highlight = 2;
    break;
   case 10: case ' ':
    choice = highlight;
    break;
   case 'q': case 'Q':
                    ExitGame();
                    break;
  }
  menuEndPrint(highlight);
  if(choice == 1){
   (wattrset(stdscr,(1U - 1U)));
   break;
     }
     else if(choice == 2){
         game.state = 4;
   (wattrset(stdscr,(1U - 1U)));
         break;
     }
 }
 wrefresh(stdscr);
 return;
}

variable_types: choice int

variable_types: c int


menuPrintWinner

decompiled_code:
int menuPrintWinner()
{
char v0; // al

init_pair(6, 1, 0);
init_pair(3, 4, 0);
v0 = game[12];
if ( v0 == 1 )
{
wattrset(stdscr, 768);
wattr_on(stdscr, 0x200000uLL, 0LL);
if ( game[0] == 2 )
{
mvprintw(15, 31, "BLUE SNAKE WINS!!!");
}
else if ( game[0] == 1 )
{
mvprintw(15, 35, "YOU WON!!!");
}
}
else if ( v0 == 2 )
{
wattrset(stdscr, 1536);
wattr_on(stdscr, 0x200000uLL, 0LL);
if ( game[0] == 2 )
{
mvprintw(15, 31, "RED SNAKE WINS!!!");
}
else if ( game[0] == 1 )
{
mvprintw(15, 34, "YOU LOST :D");
}
}
return wrefresh(stdscr);
}

canonical_decompiled_code:
int func4()
{
char v0; // al

init_pair(6, 1, 0);
init_pair(3, 4, 0);
v0 = game[12];
if ( v0 == 1 )
{
wattrset(stdscr, 768);
wattr_on(stdscr, 0x200000uLL, 0LL);
if ( game[0] == 2 )
{
mvprintw(15, 31, "BLUE SNAKE WINS!!!");
}
else if ( game[0] == 1 )
{
mvprintw(15, 35, "YOU WON!!!");
}
}
else if ( v0 == 2 )
{
wattrset(stdscr, 1536);
wattr_on(stdscr, 0x200000uLL, 0LL);
if ( game[0] == 2 )
{
mvprintw(15, 31, "RED SNAKE WINS!!!");
}
else if ( game[0] == 1 )
{
mvprintw(15, 34, "YOU LOST :D");
}
}
return wrefresh(stdscr);
}


menuPauseGame

decompiled_code:
int menuPauseGame()
{
nodelay(stdscr, 0);
wgetch(stdscr);
return nodelay(stdscr, 1);
}

canonical_decompiled_code:
int func5()
{
nodelay(stdscr, 0);
wgetch(stdscr);
return nodelay(stdscr, 1);
}

original_code:
void menuPauseGame(){
    nodelay(stdscr, 0);
    wgetch(stdscr);
    nodelay(stdscr, 1);
}


snakeInit

decompiled_code:
int snakeInit()
{
WINDOW *v0; // rdi
int result; // eax

v0 = stdscr;
*(_QWORD *)(&snake1 + 4) = 0xC00000004LL;
*(_QWORD *)(&snake1 + 12) = 0x100000001LL;
*((_WORD *)&snake1 + 10) = 257;
*(_QWORD *)(&snake2 + 4) = 0xC0000004BLL;
*((_WORD *)&snake2 + 10) = 514;
snake2 = 1;
snake1 = 1;
game[121] = 1;
game[1825] = 2;
*((_DWORD *)&snake1 + 6) = 1;
*(&snake1 + 22) = 5;
*((_DWORD *)&snake2 + 6) = -1;
*(_QWORD *)(&snake2 + 12) = 0x1FFFFFFFFLL;
*(&snake2 + 22) = 6;
if ( wmove(v0, 12, 4) != -1 )
waddch(stdscr, 0x20uLL);
result = wmove(stdscr, *((_DWORD *)&snake2 + 2), *((_DWORD *)&snake2 + 1));
if ( result != -1 )
result = waddch(stdscr, 0x20uLL);
return result;
}

original_code:
void snakeInit(){
    snake1.size = snake1.alive = snake2.size = snake2.alive = 1;
    snake1.head.x = 4; snake1.head.y = (24/2);
    snake2.head.x = (80 - 5); snake2.head.y = (24/2);
    snake1.marker = 1;
    snake2.marker = 2;
    snake1.colorcode = 1;
    snake2.colorcode = 2;
    snake1.headcolorcode = 5;
    snake2.headcolorcode = 6;
    game.map[snake1.head.x][snake1.head.y] = snake1.marker;
    game.map[snake2.head.x][snake2.head.y] = snake2.marker;
    snake1.direction = snake1.bot_newdirection = 1;
    snake2.direction = snake2.bot_newdirection = -1;
    (wmove((stdscr),((snake1.head.y)),((snake1.head.x))) == (-1) ? (-1) : waddch((stdscr),((' '))));
    (wmove((stdscr),((snake2.head.y)),((snake2.head.x))) == (-1) ? (-1) : waddch((stdscr),((' '))));
}


repo: samm-git/atop-freebsd

decompiled_code:
int netatop_ipopen()
{
int result; // eax

result = socket(2, 3, 255);
netsock = result;
return result;
}

canonical_decompiled_code:
int func1()
{
int result; // eax

result = socket(2, 3, 255);
netsock = result;
return result;
}

original_code:
void
netatop_ipopen(void)
{
 netsock = socket(2, SOCK_RAW, IPPROTO_RAW);
}

canonical_original_code:
void netatop_ipopen()
{
 netsock = socket(2, SOCK_RAW, IPPROTO_RAW);
}


decompiled_code:
unsigned int netatop_probe()
{
unsigned int result; // eax
int v1; // ebp
int v2; // ebp
int v3; // er12
_DWORD *v4; // rbp
socklen_t optlen; // [rsp+4h] [rbp-B4h] BYREF
struct sembuf sops; // [rsp+Ah] [rbp-AEh] BYREF
struct stat buf; // [rsp+10h] [rbp-A8h] BYREF

result = 4096;
*(_DWORD *)&sops.sem_num = -65535;
sops.sem_flg = 4096;
optlen = 0;
if ( netsock != -1 )
{
result = getsockopt(netsock, 0, 15661, 0LL, &optlen);
if ( result )
{
supportflags &= 0xFFFFFFCF;
return result;
}
v1 = semid;
supportflags |= 0x10u;
if ( semid != -1
|| (result = semget(1541961, 0, 0), semid = result, v1 = result, result != -1)
&& (result = semop(result, &sops, 1uLL), result != -1) )
{
result = semctl(v1, 0, 12, 0LL);
if ( result == 1 )
{
v2 = netexitfd;
if ( netexitfd != -1 )
{
result = fstat(netexitfd, &buf);
if ( !result && buf.st_nlink )
goto LABEL_9;
close(v2);
if ( nahp )
munmap(nahp, 0x10uLL);
netexitfd = -1;
nahp = 0LL;
}
result = open("/var/run/netatop.log", 0, 0LL);
netexitfd = result;
v3 = result;
if ( result != -1 )
{
nahp = mmap(0LL, 0x10uLL, 1, 1, result, 0LL);
v4 = nahp;
if ( nahp != (void *)-1LL )
{
lseek(v3, 0LL, 2);
result = v4[1];
lastseq = result;
LABEL_9:
supportflags |= 0x20u;
return result;
}
result = close(v3);
netexitfd = -1;
nahp = 0LL;
}
}
}
supportflags &= 0xFFFFFFDF;
}
return result;
}

canonical_decompiled_code:
unsigned int func2()
{
unsigned int result; // eax
int v1; // ebp
int v2; // ebp
int v3; // er12
_DWORD *v4; // rbp
socklen_t optlen; // [rsp+4h] [rbp-B4h] BYREF
struct sembuf sops; // [rsp+Ah] [rbp-AEh] BYREF
struct stat buf; // [rsp+10h] [rbp-A8h] BYREF

result = 4096;
*(_DWORD *)&sops.sem_num = -65535;
sops.sem_flg = 4096;
optlen = 0;
if ( netsock != -1 )
{
result = getsockopt(netsock, 0, 15661, 0LL, &optlen);
if ( result )
{
supportflags &= 0xFFFFFFCF;
return result;
}
v1 = semid;
supportflags |= 0x10u;
if ( semid != -1
|| (result = semget(1541961, 0, 0), semid = result, v1 = result, result != -1)
&& (result = semop(result, &sops, 1uLL), result != -1) )
{
result = semctl(v1, 0, 12, 0LL);
if ( result == 1 )
{
v2 = netexitfd;
if ( netexitfd != -1 )
{
result = fstat(netexitfd, &buf);
if ( !result && buf.st_nlink )
goto LABEL_9;
close(v2);
if ( nahp )
munmap(nahp, 0x10uLL);
netexitfd = -1;
nahp = 0LL;
}
result = open("/var/run/netatop.log", 0, 0LL);
netexitfd = result;
v3 = result;
if ( result != -1 )
{
nahp = mmap(0LL, 0x10uLL, 1, 1, result, 0LL);
v4 = nahp;
if ( nahp != (void *)-1LL )
{
lseek(v3, 0LL, 2);
result = v4[1];
lastseq = result;
LABEL_9:
supportflags |= 0x20u;
return result;
}
result = close(v3);
netexitfd = -1;
nahp = 0LL;
}
}
}
supportflags &= 0xFFFFFFDF;
}
return result;
}

original_code:
void
netatop_probe(void)
{
 struct sembuf semdecr = {1, -1, 0x1000};
 socklen_t sl = 0;
 struct stat exstat;
 if (netsock == -1)
  return;
 if ( getsockopt(netsock, 0, (15661), ((void *)0), &sl) != 0)
 {
  supportflags &= ~0x00000010;
  supportflags &= ~0x00000020;
  return;
 }
 supportflags |= 0x00000010;
 if (semid == -1)
 {
  if ( (semid = semget(1541961, 0, 0)) == -1 ||
                       semop(semid, &semdecr, 1) == -1 )
  {
   supportflags &= ~0x00000020;
   return;
  }
 }
 if (semctl(semid, 0, 12, 0) != 1)
 {
  supportflags &= ~0x00000020;
  return;
 }
 if (netexitfd != -1)
 {
  if ( fstat(netexitfd, &exstat) == 0 &&
       exstat.st_nlink > 0 )
  {
   supportflags |= 0x00000020;
   return;
  }
  else
  {
   (void) close(netexitfd);
   if (nahp)
    munmap(nahp, sizeof *nahp);
   netexitfd = -1;
   nahp = ((void *)0);
  }
 }
 if (netexitfd == -1)
 {
  if ( (netexitfd = open("/var/run/netatop.log", 00, 0)) == -1)
  {
   supportflags &= ~0x00000020;
                 return;
  }
 }
 if ( (nahp = mmap((void *)0, sizeof *nahp, 0x1, 0x01,
      netexitfd, 0)) == (void *) -1)
 {
         (void) close(netexitfd);
  netexitfd = -1;
  nahp = ((void *)0);
  supportflags &= ~0x00000020;
  return;
 }
 (void) lseek(netexitfd, 0, 2);
 lastseq = nahp->curseq;
 supportflags |= 0x00000020;
}

canonical_original_code:
void netatop_probe()
{
 struct sembuf semdecr = {1, -1, 0x1000};
 unsigned int sl = 0;
 struct stat exstat;
 if (netsock == -1)
  return;
 if ( getsockopt(netsock, 0, (15661), ((void *)0), &sl) != 0)
 {
  supportflags &= ~0x00000010;
  supportflags &= ~0x00000020;
  return;
 }
 supportflags |= 0x00000010;
 if (semid == -1)
 {
  if ( (semid = semget(1541961, 0, 0)) == -1 ||
                       semop(semid, &semdecr, 1) == -1 )
  {
   supportflags &= ~0x00000020;
   return;
  }
 }
 if (semctl(semid, 0, 12, 0) != 1)
 {
  supportflags &= ~0x00000020;
  return;
 }
 if (netexitfd != -1)
 {
  if ( fstat(netexitfd, &exstat) == 0 &&
       exstat.st_nlink > 0 )
  {
   supportflags |= 0x00000020;
   return;
  }
  else
  {
   (void) close(netexitfd);
   if (nahp)
    munmap(nahp, sizeof *nahp);
   netexitfd = -1;
   nahp = ((void *)0);
  }
 }
 if (netexitfd == -1)
 {
  if ( (netexitfd = open("/var/run/netatop.log", 00, 0)) == -1)
  {
   supportflags &= ~0x00000020;
                 return;
  }
 }
 if ( (nahp = mmap((void *)0, sizeof *nahp, 0x1, 0x01,
      netexitfd, 0)) == (void *) -1)
 {
         (void) close(netexitfd);
  netexitfd = -1;
  nahp = ((void *)0);
  supportflags &= ~0x00000020;
  return;
 }
 (void) lseek(netexitfd, 0, 2);
 lastseq = nahp->curseq;
 supportflags |= 0x00000020;
}

variable_types: struct sembuf { unsigned short sem_num; short sem_op; short sem_flg; }

variable_types:
sl
unsigned int

variable_types: struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; struct timespec { long tv_sec; long tv_nsec; } st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; }

user_defined_types: struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; struct timespec st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; }


decompiled_code:
int netatop_signoff()
{
int result; // eax
struct sembuf sops; // [rsp+Ah] [rbp-Eh] BYREF

result = 4096;
*(_DWORD *)&sops.sem_num = 65537;
sops.sem_flg = 4096;
if ( netsock != -1 && nahp && (supportflags & 0x20) != 0 )
{
regainrootprivs();
semop(semid, &sops, 1uLL);
kill(*((_DWORD *)nahp + 3), 1);
if ( !(unsigned int)droprootprivs() )
cleanstop(42LL);
munmap(nahp, 0x10uLL);
result = close(netexitfd);
}
return result;
}

canonical_decompiled_code:
int func3()
{
int result; // eax
struct sembuf sops; // [rsp+Ah] [rbp-Eh] BYREF

result = 4096;
*(_DWORD *)&sops.sem_num = 65537;
sops.sem_flg = 4096;
if ( netsock != -1 && nahp && (supportflags & 0x20) != 0 )
{
regainrootprivs();
semop(semid, &sops, 1uLL);
kill(*((_DWORD *)nahp + 3), 1);
if ( !(unsigned int)droprootprivs() )
cleanstop(42LL);
munmap(nahp, 0x10uLL);
result = close(netexitfd);
}
return result;
}

original_code:
void
netatop_signoff(void)
{
 struct sembuf semincr = {1, +1, 0x1000};
 if (netsock == -1 || nahp == ((void *)0))
  return;
 if (supportflags & 0x00000020)
 {
         regainrootprivs();
         (void) semop(semid, &semincr, 1);
  kill(nahp->mypid, 1);
         if (! droprootprivs())
          cleanstop(42);
  (void) munmap(nahp, sizeof *nahp);
  (void) close(netexitfd);
 }
}

canonical_original_code:
void netatop_signoff()
{
 struct sembuf semincr = {1, +1, 0x1000};
 if (netsock == -1 || nahp == ((void *)0))
  return;
 if (supportflags & 0x00000020)
 {
         regainrootprivs();
         (void) semop(semid, &semincr, 1);
  kill(nahp->mypid, 1);
         if (! droprootprivs())
          cleanstop(42);
  (void) munmap(nahp, sizeof *nahp);
  (void) close(netexitfd);
 }
}

user_defined_types: struct sembuf { unsigned short sem_num; short sem_op; short sem_flg; }


decompiled_code:
int __fastcall netatop_gettask(int a1, char a2, _QWORD *a3)
{
int result; // eax
socklen_t optlen; // [rsp+Ch] [rbp-7Ch] BYREF
int optval[8]; // [rsp+10h] [rbp-78h] BYREF
__int64 v7; // [rsp+30h] [rbp-58h]
__int64 v8; // [rsp+38h] [rbp-50h]
__int64 v9; // [rsp+40h] [rbp-48h]
__int64 v10; // [rsp+48h] [rbp-40h]
__int64 v11; // [rsp+50h] [rbp-38h]
__int64 v12; // [rsp+58h] [rbp-30h]
__int64 v13; // [rsp+60h] [rbp-28h]
__int64 v14; // [rsp+68h] [rbp-20h]

optlen = 96;
if ( (supportflags & 0x10) != 0 )
{
optval[0] = a1;
regainrootprivs();
if ( getsockopt(netsock, 0, (a2 != 103) + 15665, optval, &optlen) )
{
a3[78] = 0LL;
a3[91] = 0LL;
memset(
(void *)((unsigned __int64)(a3 + 79) & 0xFFFFFFFFFFFFFFF8LL),
0,
8LL * (((unsigned int)a3 - (((_DWORD)a3 + 632) & 0xFFFFFFF8) + 736) >> 3));
if ( !(unsigned int)droprootprivs() )
cleanstop(42LL);
result = *_errno_location();
if ( result == 92 || result == 1 )
{
supportflags &= 0xFFFFFFCF;
result = close(netsock);
netsock = -1;
}
}
else
{
if ( !(unsigned int)droprootprivs() )
cleanstop(42LL);
a3[78] = v7;
a3[80] = v9;
a3[79] = v8;
a3[81] = v10;
a3[82] = v11;
a3[84] = v13;
a3[83] = v12;
result = v14;
a3[85] = v14;
}
}
else
{
result = 0;
a3[78] = 0LL;
a3[91] = 0LL;
memset(
(void *)((unsigned __int64)(a3 + 79) & 0xFFFFFFFFFFFFFFF8LL),
0,
8LL * (((unsigned int)a3 - (((_DWORD)a3 + 632) & 0xFFFFFFF8) + 736) >> 3));
}
return result;
}

canonical_decompiled_code:
int __fastcall func4(int a1, char a2, _QWORD *a3)
{
int result; // eax
socklen_t optlen; // [rsp+Ch] [rbp-7Ch] BYREF
int optval[8]; // [rsp+10h] [rbp-78h] BYREF
__int64 v7; // [rsp+30h] [rbp-58h]
__int64 v8; // [rsp+38h] [rbp-50h]
__int64 v9; // [rsp+40h] [rbp-48h]
__int64 v10; // [rsp+48h] [rbp-40h]
__int64 v11; // [rsp+50h] [rbp-38h]
__int64 v12; // [rsp+58h] [rbp-30h]
__int64 v13; // [rsp+60h] [rbp-28h]
__int64 v14; // [rsp+68h] [rbp-20h]

optlen = 96;
if ( (supportflags & 0x10) != 0 )
{
optval[0] = a1;
regainrootprivs();
if ( getsockopt(netsock, 0, (a2 != 103) + 15665, optval, &optlen) )
{
a3[78] = 0LL;
a3[91] = 0LL;
memset(
(void *)((unsigned __int64)(a3 + 79) & 0xFFFFFFFFFFFFFFF8LL),
0,
8LL * (((unsigned int)a3 - (((_DWORD)a3 + 632) & 0xFFFFFFF8) + 736) >> 3));
if ( !(unsigned int)droprootprivs() )
cleanstop(42LL);
result = *_errno_location();
if ( result == 92 || result == 1 )
{
supportflags &= 0xFFFFFFCF;
result = close(netsock);
netsock = -1;
}
}
else
{
if ( !(unsigned int)droprootprivs() )
cleanstop(42LL);
a3[78] = v7;
a3[80] = v9;
a3[79] = v8;
a3[81] = v10;
a3[82] = v11;
a3[84] = v13;
a3[83] = v12;
result = v14;
a3[85] = v14;
}
}
else
{
result = 0;
a3[78] = 0LL;
a3[91] = 0LL;
memset(
(void *)((unsigned __int64)(a3 + 79) & 0xFFFFFFFFFFFFFFF8LL),
0,
8LL * (((unsigned int)a3 - (((_DWORD)a3 + 632) & 0xFFFFFFF8) + 736) >> 3));
}
return result;
}

original_code:
void
netatop_gettask(pid_t id, char type, struct tstat *tp)
{
 struct netpertask npt;
 socklen_t socklen = sizeof npt;
 int cmd = (type == 'g' ?
        (15661 +4) : (15661 +5));
 if (!(supportflags & 0x00000010) ) {
  memset(&tp->net, 0, sizeof tp->net);
  return;
 }
 npt.id = id;
        regainrootprivs();
 if (getsockopt(netsock, 0, cmd, &npt, &socklen) != 0) {
  memset(&tp->net, 0, sizeof tp->net);
         if (! droprootprivs())
          cleanstop(42);
  if ((*__errno_location ()) == 92 || (*__errno_location ()) == 1)
  {
   supportflags &= ~0x00000010;
   supportflags &= ~0x00000020;
   close(netsock);
   netsock = -1;
  }
  return;
 }
        if (! droprootprivs())
         cleanstop(42);
 tp->net.tcpsnd = npt.tc.tcpsndpacks;
 tp->net.tcprcv = npt.tc.tcprcvpacks;
 tp->net.tcpssz = npt.tc.tcpsndbytes;
 tp->net.tcprsz = npt.tc.tcprcvbytes;
 tp->net.udpsnd = npt.tc.udpsndpacks;
 tp->net.udprcv = npt.tc.udprcvpacks;
 tp->net.udpssz = npt.tc.udpsndbytes;
 tp->net.udprsz = npt.tc.udprcvbytes;
}

canonical_original_code:
void netatop_gettask(int id, char type, struct tstat *tp)
{
 struct netpertask npt;
 unsigned int socklen = sizeof npt;
 int cmd = (type == 'g' ?
        (15661 +4) : (15661 +5));
 if (!(supportflags & 0x00000010) ) {
  memset(&tp->net, 0, sizeof tp->net);
  return;
 }
 npt.id = id;
        regainrootprivs();
 if (getsockopt(netsock, 0, cmd, &npt, &socklen) != 0) {
  memset(&tp->net, 0, sizeof tp->net);
         if (! droprootprivs())
          cleanstop(42);
  if ((*__errno_location ()) == 92 || (*__errno_location ()) == 1)
  {
   supportflags &= ~0x00000010;
   supportflags &= ~0x00000020;
   close(netsock);
   netsock = -1;
  }
  return;
 }
        if (! droprootprivs())
         cleanstop(42);
 tp->net.tcpsnd = npt.tc.tcpsndpacks;
 tp->net.tcprcv = npt.tc.tcprcvpacks;
 tp->net.tcpssz = npt.tc.tcpsndbytes;
 tp->net.tcprsz = npt.tc.tcprcvbytes;
 tp->net.udpsnd = npt.tc.udpsndpacks;
 tp->net.udprcv = npt.tc.udprcvpacks;
 tp->net.udpssz = npt.tc.udpsndbytes;
 tp->net.udprsz = npt.tc.udprcvbytes;
}

variable_types: id int

variable_types: type char

variable_types: struct tstat { struct gen { int tgid; int pid; int ppid; int ruid; int euid; int suid; int fsuid; int rgid; int egid; int sgid; int fsgid; int nthr; char name[-1]; char isproc; char state; int excode; long btime; long elaps; char cmdline[-1]; int nthrslpi; int nthrslpu; int nthrrun; int ifuture[4]; } gen; struct cpu { long long utime; long long stime; int nice; int prio; int rtprio; int policy; int curcpu; int sleepavg; int ifuture[4]; long long cfuture[4]; } cpu; struct dsk { long long rio; long long rsz; long long wio; long long wsz; long long cwsz; long long cfuture[4]; } dsk; struct mem { long long minflt; long long majflt; long long vexec; long long vmem; long long rmem; long long vgrow; long long rgrow; long long vdata; long long vstack; long long vlibs; long long vswap; } mem; struct net { long long tcpsnd; long long tcpssz; long long tcprcv; long long tcprsz; long long udpsnd; long long udpssz; long long udprcv; long long udprsz; long long avail1; long long avail2; long long cfuture[4]; } net; } *

variable_types: struct netpertask { int id; unsigned long btime; char command[16]; struct taskcount { unsigned long long tcpsndpacks; unsigned long long tcpsndbytes; unsigned long long tcprcvpacks; unsigned long long tcprcvbytes; unsigned long long udpsndpacks; unsigned long long udpsndbytes; unsigned long long udprcvpacks; unsigned long long udprcvbytes; } tc; }

variable_types:
socklen
unsigned int

variable_types: cmd int

user_defined_types: struct netpertask { int id; unsigned long btime; char command[16]; struct taskcount tc; }

user_defined_types: struct tstat { struct gen gen; struct cpu cpu; struct dsk dsk; struct mem mem; struct net net; }


decompiled_code:
__int64 netatop_exitstore()
{
int v0; // eax
void *v1; // rsp
void *v2; // rsp
int v3; // er12
unsigned __int32 v4; // ebx
__m128i *v5; // r15
__int64 v6; // rax
__m128i *v7; // r15
unsigned int v8; // er12
unsigned int v9; // ebx
int v10; // eax
__m128i v12; // [rsp+0h] [rbp-50h] BYREF
__m128i v13; // [rsp+10h] [rbp-40h] BYREF
__m128i v14; // [rsp+20h] [rbp-30h] BYREF
__m128i v15; // [rsp+30h] [rbp-20h] BYREF
__m128i v16; // [rsp+40h] [rbp-10h] BYREF
__int64 savedregs; // [rsp+50h] [rbp+0h] BYREF

v13.m128i_i32[1] = 0;
v0 = *((unsigned __int16 *)nahp + 5);
v1 = alloca((v0 + 115) & 0x1FFF0);
v2 = alloca((v0 + 15) & 0x1FFF0);
regainrootprivs();
v3 = netsock;
if ( getsockopt(netsock, 0, 15662, 0LL, &v13.m128i_u32[1]) || getsockopt(v3, 0, 15663, 0LL, &v13.m128i_u32[1]) )
{
if ( (unsigned int)droprootprivs() )
{
v10 = *_errno_location();
if ( v10 == 92 )
goto LABEL_23;
}
else
{
cleanstop(42LL);
v10 = *_errno_location();
if ( v10 == 92 )
goto LABEL_23;
}
if ( v10 != 1 )
return 0;
LABEL_23:
supportflags &= 0xFFFFFFCF;
close(netsock);
netsock = -1;
return 0;
}
if ( !(unsigned int)droprootprivs() )
cleanstop(42LL);
v4 = *((_DWORD *)nahp + 1) - lastseq;
lastseq = *((unsigned int *)nahp + 1);
v12.m128i_i32[3] = v4;
exitall = malloc(112LL * v4);
ptrverify(exitall, "Malloc failed for %d exited netprocs\n", v4);
v5 = (__m128i *)exitall;
memset(exitall, 0, 112LL * v4);
if ( read(netexitfd, (char *)v13.m128i_i32 + 3, 1uLL) != 1 )
return 0;
v6 = v13.m128i_u8[3];
v7 = v5 + 1;
v8 = 0;
while ( 1 )
{
v12.m128i_i32[2] = read(netexitfd, &v12, v6 + 1);
v9 = v12.m128i_u32[2];
if ( (unsigned int)v13.m128i_u8[3] > v12.m128i_i32[2] )
break;
v13.m128i_i64[1] = *((unsigned __int16 *)nahp + 5);
if ( v13.m128i_i16[4] <= 0x60u )
{
uncompress(v7, &v13.m128i_u64[1], &v12);
}
else
{
uncompress(&v12, &v13.m128i_u64[1], &v12);
*v7 = _mm_loadu_si128(&v12);
v7[1] = _mm_loadu_si128(&v13);
v7[2] = _mm_loadu_si128(&v14);
v7[3] = _mm_loadu_si128(&v15);
v7[4] = _mm_loadu_si128(&v16);
v7[5] = _mm_loadu_si128((const __m128i *)&savedregs);
}
if ( v12.m128i_i32[3] == ++v8 )
{
if ( v12.m128i_i32[2] > (unsigned int)v13.m128i_u8[3] )
lseek(netexitfd, -1LL, 1);
break;
}
v7 += 7;
if ( v9 <= v13.m128i_u8[3] )
break;
v6 = v12.m128i_u8[v13.m128i_u8[3]];
v13.m128i_i8[3] = v12.m128i_i8[v13.m128i_u8[3]];
}
exitnum = v8;
return v8;
}

canonical_decompiled_code:
__int64 func5()
{
int v0; // eax
void *v1; // rsp
void *v2; // rsp
int v3; // er12
unsigned __int32 v4; // ebx
__m128i *v5; // r15
__int64 v6; // rax
__m128i *v7; // r15
unsigned int v8; // er12
unsigned int v9; // ebx
int v10; // eax
__m128i v12; // [rsp+0h] [rbp-50h] BYREF
__m128i v13; // [rsp+10h] [rbp-40h] BYREF
__m128i v14; // [rsp+20h] [rbp-30h] BYREF
__m128i v15; // [rsp+30h] [rbp-20h] BYREF
__m128i v16; // [rsp+40h] [rbp-10h] BYREF
__int64 savedregs; // [rsp+50h] [rbp+0h] BYREF

v13.m128i_i32[1] = 0;
v0 = *((unsigned __int16 *)nahp + 5);
v1 = alloca((v0 + 115) & 0x1FFF0);
v2 = alloca((v0 + 15) & 0x1FFF0);
regainrootprivs();
v3 = netsock;
if ( getsockopt(netsock, 0, 15662, 0LL, &v13.m128i_u32[1]) || getsockopt(v3, 0, 15663, 0LL, &v13.m128i_u32[1]) )
{
if ( (unsigned int)droprootprivs() )
{
v10 = *_errno_location();
if ( v10 == 92 )
goto LABEL_23;
}
else
{
cleanstop(42LL);
v10 = *_errno_location();
if ( v10 == 92 )
goto LABEL_23;
}
if ( v10 != 1 )
return 0;
LABEL_23:
supportflags &= 0xFFFFFFCF;
close(netsock);
netsock = -1;
return 0;
}
if ( !(unsigned int)droprootprivs() )
cleanstop(42LL);
v4 = *((_DWORD *)nahp + 1) - lastseq;
lastseq = *((unsigned int *)nahp + 1);
v12.m128i_i32[3] = v4;
exitall = malloc(112LL * v4);
ptrverify(exitall, "Malloc failed for %d exited netprocs\n", v4);
v5 = (__m128i *)exitall;
memset(exitall, 0, 112LL * v4);
if ( read(netexitfd, (char *)v13.m128i_i32 + 3, 1uLL) != 1 )
return 0;
v6 = v13.m128i_u8[3];
v7 = v5 + 1;
v8 = 0;
while ( 1 )
{
v12.m128i_i32[2] = read(netexitfd, &v12, v6 + 1);
v9 = v12.m128i_u32[2];
if ( (unsigned int)v13.m128i_u8[3] > v12.m128i_i32[2] )
break;
v13.m128i_i64[1] = *((unsigned __int16 *)nahp + 5);
if ( v13.m128i_i16[4] <= 0x60u )
{
uncompress(v7, &v13.m128i_u64[1], &v12);
}
else
{
uncompress(&v12, &v13.m128i_u64[1], &v12);
*v7 = _mm_loadu_si128(&v12);
v7[1] = _mm_loadu_si128(&v13);
v7[2] = _mm_loadu_si128(&v14);
v7[3] = _mm_loadu_si128(&v15);
v7[4] = _mm_loadu_si128(&v16);
v7[5] = _mm_loadu_si128((const __m128i *)&savedregs);
}
if ( v12.m128i_i32[3] == ++v8 )
{
if ( v12.m128i_i32[2] > (unsigned int)v13.m128i_u8[3] )
lseek(netexitfd, -1LL, 1);
break;
}
v7 += 7;
if ( v9 <= v13.m128i_u8[3] )
break;
v6 = v12.m128i_u8[v13.m128i_u8[3]];
v13.m128i_i8[3] = v12.m128i_i8[v13.m128i_u8[3]];
}
exitnum = v8;
return v8;
}

original_code:
unsigned int
netatop_exitstore(void)
{
 socklen_t socklen = 0, nexitnet, sz, nr=0;
 unsigned long uncomplen;
 unsigned char nextsize;
 unsigned char readbuf[nahp->ntplen+100];
 unsigned char databuf[nahp->ntplen];
 struct netpertask *tmp = (struct netpertask *)databuf;
 struct exitstore *esp;
        regainrootprivs();
 if (getsockopt(netsock, 0, (15661 +1), ((void *)0), &socklen)!=0) {
         if (! droprootprivs())
          cleanstop(42);
  if ((*__errno_location ()) == 92 || (*__errno_location ()) == 1)
  {
   supportflags &= ~0x00000010;
   supportflags &= ~0x00000020;
   close(netsock);
   netsock = -1;
  }
  return 0;
 }
 if (getsockopt(netsock, 0, (15661 +2), 0, &socklen) !=0) {
         if (! droprootprivs())
          cleanstop(42);
  if ((*__errno_location ()) == 92 || (*__errno_location ()) == 1)
  {
   supportflags &= ~0x00000010;
   supportflags &= ~0x00000020;
   close(netsock);
   netsock = -1;
  }
  return 0;
 }
        if (! droprootprivs())
         cleanstop(42);
 nexitnet = nahp->curseq - lastseq;
 lastseq = nahp->curseq;
 exitall = malloc(nexitnet * sizeof(struct exitstore));
 ptrverify(exitall, "Malloc failed for %d exited netprocs\n", nexitnet);
 memset(exitall, 0, nexitnet * sizeof(struct exitstore));
 esp = exitall;
 if ( read(netexitfd, &nextsize, 1) != 1)
  return 0;
 while ( (sz = read(netexitfd, readbuf, nextsize+1)) >= nextsize)
 {
         uncomplen = nahp->ntplen;
  if (nahp->ntplen <= sizeof(struct netpertask))
  {
   (void) uncompress((Byte *)&(esp->npt), &uncomplen,
       readbuf, nextsize);
  }
  else
  {
   (void) uncompress((Byte *)databuf, &uncomplen,
       readbuf, nextsize);
   esp->npt = *tmp;
  }
  esp++;
  nr++;
  if (nr == nexitnet)
  {
   if (sz > nextsize)
    (void) lseek(netexitfd, -1, 1);
   break;
  }
  if (sz > nextsize)
   nextsize = readbuf[nextsize];
  else
   break;
 }
 exitnum = nr;
 return nr;
}

canonical_original_code:
unsigned int netatop_exitstore()
{
 unsigned int socklen = 0; unsigned int nexitnet; unsigned int sz; unsigned int nr = 0;
 unsigned long uncomplen;
 unsigned char nextsize;
 unsigned char readbuf[-1];
 unsigned char databuf[-1];
 struct netpertask *tmp = (struct netpertask *)databuf;
 struct exitstore *esp;
        regainrootprivs();
 if (getsockopt(netsock, 0, (15661 +1), ((void *)0), &socklen)!=0) {
         if (! droprootprivs())
          cleanstop(42);
  if ((*__errno_location ()) == 92 || (*__errno_location ()) == 1)
  {
   supportflags &= ~0x00000010;
   supportflags &= ~0x00000020;
   close(netsock);
   netsock = -1;
  }
  return 0;
 }
 if (getsockopt(netsock, 0, (15661 +2), 0, &socklen) !=0) {
         if (! droprootprivs())
          cleanstop(42);
  if ((*__errno_location ()) == 92 || (*__errno_location ()) == 1)
  {
   supportflags &= ~0x00000010;
   supportflags &= ~0x00000020;
   close(netsock);
   netsock = -1;
  }
  return 0;
 }
        if (! droprootprivs())
         cleanstop(42);
 nexitnet = nahp->curseq - lastseq;
 lastseq = nahp->curseq;
 exitall = malloc(nexitnet * sizeof(struct exitstore));
 ptrverify(exitall, "Malloc failed for %d exited netprocs\n", nexitnet);
 memset(exitall, 0, nexitnet * sizeof(struct exitstore));
 esp = exitall;
 if ( read(netexitfd, &nextsize, 1) != 1)
  return 0;
 while ( (sz = read(netexitfd, readbuf, nextsize+1)) >= nextsize)
 {
         uncomplen = nahp->ntplen;
  if (nahp->ntplen <= sizeof(struct netpertask))
  {
   (void) uncompress((unsigned char *)&(esp->npt), &uncomplen,
       readbuf, nextsize);
  }
  else
  {
   (void) uncompress((unsigned char *)databuf, &uncomplen,
       readbuf, nextsize);
   esp->npt = *tmp;
  }
  esp++;
  nr++;
  if (nr == nexitnet)
  {
   if (sz > nextsize)
    (void) lseek(netexitfd, -1, 1);
   break;
  }
  if (sz > nextsize)
   nextsize = readbuf[nextsize];
  else
   break;
 }
 exitnum = nr;
 return nr;
}

variable_types:
nexitnet
unsigned int

variable_types:
sz
unsigned int

variable_types:
nr
unsigned int

variable_types:
uncomplen
unsigned long

variable_types:
nextsize
unsigned char

variable_types:
readbuf
unsigned char [-1]

variable_types:
databuf
unsigned char [-1]

variable_types: struct netpertask { int id; unsigned long btime; char command[16]; struct taskcount { unsigned long long tcpsndpacks; unsigned long long tcpsndbytes; unsigned long long tcprcvpacks; unsigned long long tcprcvbytes; unsigned long long udpsndpacks; unsigned long long udpsndbytes; unsigned long long udprcvpacks; unsigned long long udprcvbytes; } tc; } *

variable_types: struct exitstore { struct exitstore *next; unsigned char isused; struct netpertask { int id; unsigned long btime; char command[16]; struct taskcount { unsigned long long tcpsndpacks; unsigned long long tcpsndbytes; unsigned long long tcprcvpacks; unsigned long long tcprcvbytes; unsigned long long udpsndpacks; unsigned long long udpsndbytes; unsigned long long udprcvpacks; unsigned long long udprcvbytes; } tc; } npt; } *

return_type: unsigned int

user_defined_types: struct exitstore { struct exitstore *next; unsigned char isused; struct netpertask npt; }


decompiled_code:
__int64 netatop_exiterase()
{
__int64 result; // rax

free(exitall);
result = 0LL;
exitnum = 0;
memset(&esbucket, 0, 0x2000uLL);
return result;
}

canonical_decompiled_code:
__int64 func6()
{
__int64 result; // rax

free(exitall);
result = 0LL;
exitnum = 0;
memset(&esbucket, 0, 0x2000uLL);
return result;
}

original_code:
void
netatop_exiterase(void)
{
 free(exitall);
 memset(esbucket, 0, sizeof esbucket);
 exitnum = 0;
}

canonical_original_code:
void netatop_exiterase()
{
 free(exitall);
 memset(esbucket, 0, sizeof esbucket);
 exitnum = 0;
}


decompiled_code:
__int64 __fastcall netatop_exithash(char a1)
{
__int64 result; // rax
char *v2; // rdx
char *v3; // rsi

result = exitnum;
v2 = (char *)exitall;
if ( exitnum > 0 )
{
v3 = (char *)exitall + 112 * exitnum;
do
{
if ( a1 == 112 )
LODWORD(result) = *((_DWORD *)v2 + 4) & 0x3FF;
else
LODWORD(result) = *((_DWORD *)v2 + 6) & 0x3FF;
result = (int)result;
*(_QWORD *)v2 = esbucket[(int)result];
esbucket[(int)result] = (__int64)v2;
v2 += 112;
}
while ( v2 != v3 );
}
exithash = a1;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(char a1)
{
__int64 result; // rax
char *v2; // rdx
char *v3; // rsi

result = exitnum;
v2 = (char *)exitall;
if ( exitnum > 0 )
{
v3 = (char *)exitall + 112 * exitnum;
do
{
if ( a1 == 112 )
LODWORD(result) = *((_DWORD *)v2 + 4) & 0x3FF;
else
LODWORD(result) = *((_DWORD *)v2 + 6) & 0x3FF;
result = (int)result;
*(_QWORD *)v2 = esbucket[(int)result];
esbucket[(int)result] = (__int64)v2;
v2 += 112;
}
while ( v2 != v3 );
}
exithash = a1;
return result;
}

original_code:
void
netatop_exithash(char hashtype)
{
 int i, h;
 struct exitstore *esp;
 for (i=0, esp=exitall; i < exitnum; i++, esp++)
 {
  if (hashtype == 'p')
   h = ((esp->npt.id)&(1024 -1));
  else
   h = ((esp->npt.btime)&(1024 -1));
  esp->next = esbucket[h];
  esbucket[h] = esp;
 }
 exithash = hashtype;
}

canonical_original_code:
void netatop_exithash(char hashtype)
{
 int i; int h;
 struct exitstore *esp;
 for (i=0, esp=exitall; i < exitnum; i++, esp++)
 {
  if (hashtype == 'p')
   h = ((esp->npt.id)&(1024 -1));
  else
   h = ((esp->npt.btime)&(1024 -1));
  esp->next = esbucket[h];
  esbucket[h] = esp;
 }
 exithash = hashtype;
}

variable_types: hashtype char

variable_types: i int

variable_types: h int

user_defined_types: struct taskcount { unsigned long long tcpsndpacks; unsigned long long tcpsndbytes; unsigned long long tcprcvpacks; unsigned long long tcprcvbytes; unsigned long long udpsndpacks; unsigned long long udpsndbytes; unsigned long long udprcvpacks; unsigned long long udprcvbytes; }


decompiled_code:
int __fastcall netatop_exitfind(__int64 a1, _QWORD *a2, _QWORD *a3)
{
unsigned __int64 v3; // rax
__int64 v4; // rbx
char v5; // bp
const char *v6; // r15

v3 = a1 & 0x3FF;
v4 = esbucket[v3];
v5 = exithash;
if ( v4 )
{
v6 = (const char *)(a3 + 6);
do
{
while ( v5 != 98 )
{
if ( v5 == 112 )
{
v3 = *(int *)(v4 + 16);
if ( v3 == a1 )
goto LABEL_19;
}
LABEL_5:
v4 = *(_QWORD *)v4;
if ( !v4 )
return v3;
}
if ( *(_BYTE *)(v4 + 8) )
goto LABEL_5;
if ( *(_QWORD *)(v4 + 24) != a1 )
goto LABEL_5;
LODWORD(v3) = strcmp((const char *)(v4 + 32), v6);
if ( (_DWORD)v3 )
goto LABEL_5;
v3 = a3[78];
if ( *(_QWORD *)(v4 + 48) < v3 )
goto LABEL_5;
v3 = a3[79];
if ( *(_QWORD *)(v4 + 56) < v3 )
goto LABEL_5;
v3 = a3[80];
if ( *(_QWORD *)(v4 + 64) < v3 )
goto LABEL_5;
v3 = a3[81];
if ( *(_QWORD *)(v4 + 72) < v3 )
goto LABEL_5;
v3 = a3[82];
if ( *(_QWORD *)(v4 + 80) < v3 )
goto LABEL_5;
v3 = a3[83];
if ( *(_QWORD *)(v4 + 88) < v3 )
goto LABEL_5;
v3 = a3[84];
if ( *(_QWORD *)(v4 + 96) < v3 )
goto LABEL_5;
v3 = a3[85];
if ( *(_QWORD *)(v4 + 104) < v3 )
goto LABEL_5;
*(_BYTE *)(v4 + 8) = 1;
LABEL_19:
LODWORD(v3) = fill_networkcnt(a2, a3, (_QWORD *)v4);
v4 = *(_QWORD *)v4;
}
while ( v4 );
}
return v3;
}

original_code:
void
netatop_exitfind(unsigned long key, struct tstat *dev, struct tstat *pre)
{
 int h = ((key)&(1024 -1));
 struct exitstore *esp;
 if ( (esp = esbucket[h]) == ((void *)0))
  return;
 for (; esp; esp=esp->next)
 {
  switch (exithash)
  {
     case 'p':
   if (key != esp->npt.id)
    continue;
   fill_networkcnt(dev, pre, esp);
   break;
     case 'b':
   if (esp->isused)
    continue;
   if (key != esp->npt.btime)
    continue;
   if ( strcmp(esp->npt.command, pre->gen.name) != 0)
    continue;
   if (esp->npt.tc.tcpsndpacks < pre->net.tcpsnd ||
       esp->npt.tc.tcpsndbytes < pre->net.tcpssz ||
       esp->npt.tc.tcprcvpacks < pre->net.tcprcv ||
       esp->npt.tc.tcprcvbytes < pre->net.tcprsz ||
       esp->npt.tc.udpsndpacks < pre->net.udpsnd ||
       esp->npt.tc.udpsndbytes < pre->net.udpssz ||
       esp->npt.tc.udprcvpacks < pre->net.udprcv ||
       esp->npt.tc.udprcvbytes < pre->net.udprsz )
    continue;
   esp->isused = 1;
   fill_networkcnt(dev, pre, esp);
   break;
  }
 }
}

variable_types:
key
unsigned long

variable_types:
pre
struct tstat *

user_defined_types: struct gen { int tgid; int pid; int ppid; int ruid; int euid; int suid; int fsuid; int rgid; int egid; int sgid; int fsgid; int nthr; char name[-1]; char isproc; char state; int excode; long btime; long elaps; char cmdline[-1]; int nthrslpi; int nthrslpu; int nthrrun; int ifuture[4]; }

user_defined_types: struct cpu { long long utime; long long stime; int nice; int prio; int rtprio; int policy; int curcpu; int sleepavg; int ifuture[4]; long long cfuture[4]; }

user_defined_types: struct dsk { long long rio; long long rsz; long long wio; long long wsz; long long cwsz; long long cfuture[4]; }

user_defined_types: struct mem { long long minflt; long long majflt; long long vexec; long long vmem; long long rmem; long long vgrow; long long rgrow; long long vdata; long long vstack; long long vlibs; long long vswap; }

user_defined_types: struct net { long long tcpsnd; long long tcpssz; long long tcprcv; long long tcprsz; long long udpsnd; long long udpssz; long long udprcv; long long udprsz; long long avail1; long long avail2; long long cfuture[4]; }


decompiled_code:
void getusr1()
{
awaittrigger = 0;
}

canonical_decompiled_code:
void func0()
{
awaittrigger = 0;
}

original_code:
void
getusr1(int sig)
{
 awaittrigger=0;
}

variable_types: sig int


decompiled_code:
__int64 getusr2()
{
__int64 result; // rax

result = sampcnt;
awaittrigger = 0;
nsamples = sampcnt;
return result;
}

canonical_decompiled_code:
__int64 func1()
{
__int64 result; // rax

result = sampcnt;
awaittrigger = 0;
nsamples = sampcnt;
return result;
}

original_code:
void
getusr2(int sig)
{
 awaittrigger=0;
 nsamples = sampcnt;
}


getalarm

decompiled_code:
unsigned int getalarm()
{
unsigned int result; // eax

awaittrigger = 0;
if ( *(_QWORD *)&interval )
result = alarm(interval);
return result;
}

canonical_decompiled_code:
unsigned int func3()
{
unsigned int result; // eax

awaittrigger = 0;
if ( *(_QWORD *)&interval )
result = alarm(interval);
return result;
}

original_code:
void
getalarm(int sig)
{
 awaittrigger=0;
 if (interval > 0)
  alarm(interval);
}


decompiled_code:
__int64 do_interval()
{
__int64 result; // rax

result = (int)get_posval();
*(_QWORD *)&interval = (int)result;
return result;
}

canonical_decompiled_code:
__int64 func5()
{
__int64 result; // rax

result = (int)get_posval();
*(_QWORD *)&interval = (int)result;
return result;
}

original_code:
void
do_interval(char *name, char *val)
{
 interval = get_posval(name, val);
}

variable_types:
name
char *

variable_types:
val
char *


decompiled_code:
__int64 do_linelength()
{
__int64 result; // rax

result = get_posval();
linelen = result;
return result;
}

canonical_decompiled_code:
__int64 func6()
{
__int64 result; // rax

result = get_posval();
linelen = result;
return result;
}

original_code:
void
do_linelength(char *name, char *val)
{
 linelen = get_posval(name, val);
}


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char *v4; // rcx
const char *v5; // rbx
char *v6; // rax
int v7; // ebx
int v8; // eax
char *v9; // rax
__int64 v10; // rdx
__int64 v12; // rdx
const char *v13; // rsi
const char *v14; // rsi
const char *v15; // rax
__int64 v16; // r13
int v17; // ebx
int v18; // eax
struct rlimit v19[66]; // [rsp+0h] [rbp-428h] BYREF

if ( !(unsigned int)droprootprivs(argc, argv, envp) )
{
fwrite("not possible to drop root privs\n", 1uLL, 0x20uLL, stderr);
exit(42);
}
argvp = (__int64)argv;
readrc("/etc/atoprc");
v4 = getenv("HOME");
if ( v4 )
{
snprintf((char *)v19, 0x400uLL, "%s/.atoprc", v4);
readrc((char *)v19);
}
v5 = *argv;
v6 = strrchr(*argv, 47);
if ( v6 )
v5 = v6 + 1;
if ( *(_DWORD *)v5 == 1886352481 && *((_WORD *)v5 + 2) == 24947 && v5[6] == 114 )
return atopsar((unsigned int)argc, argv);
v7 = 0;
if ( argc > 1 )
{
do
{
v8 = getopt(argc, (char *const *)argv, "ab:cde:fghijklmnopqrstuvwxyz1ABCDEFGHIJKL:MNOP:QRSTUVWXYZ");
if ( v8 == -1 )
break;
switch ( v8 )
{
case '?':
goto LABEL_11;
case 'L':
if ( !(unsigned int)numeric(optarg) )
prusage(*argv);
linelen = atoi(optarg);
break;
case 'P':
if ( !(unsigned int)parsedef(optarg) )
prusage(*argv);
vis = (__int64 (__fastcall *)(_QWORD, _QWORD, _QWORD, _QWORD, _QWORD))&parseout;
break;
case 'S':
++midnightflag;
break;
case 'V':
v15 = (const char *)getstrvers();
puts(v15);
exit(0);
case 'a':
deviatonly = 0;
break;
case 'b':
if ( !(unsigned int)hhmm2secs(optarg, &begintime) )
goto LABEL_11;
break;
case 'e':
if ( !(unsigned int)hhmm2secs(optarg, &endtime) )
LABEL_11:
prusage(*argv);
break;
case 'r':
if ( optind < argc )
{
v14 = argv[optind];
if ( *v14 != 45 )
{
++optind;
strncpy(rawname, v14, 0xFFuLL);
}
}
++rawreadflag;
break;
case 'w':
if ( optind >= argc )
prusage(*argv);
v13 = argv[optind++];
strncpy(rawname, v13, 0xFFuLL);
vis = (__int64 (__fastcall *)(_QWORD, _QWORD, _QWORD, _QWORD, _QWORD))&rawwrite;
break;
default:
v12 = v7++;
flaglist[v12] = v8;
break;
}
}
while ( v7 != 63 );
if ( optind <= 63 && optind < argc )
{
if ( !(unsigned int)numeric(argv[optind]) )
prusage(*argv);
v16 = optind;
v17 = optind + 1;
v18 = atoi(argv[v16]);
optind = v17;
*(_QWORD *)&interval = v18;
if ( v17 < argc )
{
if ( !(unsigned int)numeric(argv[v16 + 1]) )
prusage(*argv);
nsamples = atoi(argv[optind]);
if ( !nsamples )
prusage(*argv);
}
}
}
uname(&utsname);
v9 = strchr((const char *)(unsigned int)((_DWORD)&utsname + 65), 46);
if ( v9 )
*v9 = 0;
utsnodenamelen = strlen((const char *)(unsigned int)((_DWORD)&utsname + 65));
_isoc99_sscanf((unsigned int)((_DWORD)&utsname + 130), "%d.%d.%d", &osrel, &osvers, &ossub);
hertz = sysconf(2);
pagesize = sysconf(30);
if ( rawreadflag )
{
rawread();
cleanstop(0);
}
curtime = getboot() / (unsigned __int64)(unsigned __int16)hertz;
signal(1, (__sighandler_t)&cleanstop);
signal(15, (__sighandler_t)&cleanstop);
regainrootprivs();
v19[0].rlim_cur = -1LL;
v19[0].rlim_max = -1LL;
setrlimit(__RLIMIT_MEMLOCK, v19);
mlockall(3);
nice(-20);
acctreason = acctswon();
initifprop();
netatop_ipopen();
if ( !(unsigned int)droprootprivs(4294967276LL, v19, v10) )
cleanstop(42);
engine();
cleanstop(0);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char *v4; // rcx
const char *v5; // rbx
char *v6; // rax
int v7; // ebx
int v8; // eax
char *v9; // rax
__int64 v10; // rdx
__int64 v12; // rdx
const char *v13; // rsi
const char *v14; // rsi
const char *v15; // rax
__int64 v16; // r13
int v17; // ebx
int v18; // eax
struct rlimit v19[66]; // [rsp+0h] [rbp-428h] BYREF

if ( !(unsigned int)droprootprivs(argc, argv, envp) )
{
fwrite("not possible to drop root privs\n", 1uLL, 0x20uLL, stderr);
exit(42);
}
argvp = (__int64)argv;
func2("/etc/atoprc");
v4 = getenv("HOME");
if ( v4 )
{
snprintf((char *)v19, 0x400uLL, "%s/.atoprc", v4);
func2((char *)v19);
}
v5 = *argv;
v6 = strrchr(*argv, 47);
if ( v6 )
v5 = v6 + 1;
if ( *(_DWORD *)v5 == 1886352481 && *((_WORD *)v5 + 2) == 24947 && v5[6] == 114 )
return atopsar((unsigned int)argc, argv);
v7 = 0;
if ( argc > 1 )
{
do
{
v8 = getopt(argc, (char *const *)argv, "ab:cde:fghijklmnopqrstuvwxyz1ABCDEFGHIJKL:MNOP:QRSTUVWXYZ");
if ( v8 == -1 )
break;
switch ( v8 )
{
case '?':
goto LABEL_11;
case 'L':
if ( !(unsigned int)numeric(optarg) )
prusage(*argv);
linelen = atoi(optarg);
break;
case 'P':
if ( !(unsigned int)parsedef(optarg) )
prusage(*argv);
vis = (__int64 (__fastcall *)(_QWORD, _QWORD, _QWORD, _QWORD, _QWORD))&parseout;
break;
case 'S':
++midnightflag;
break;
case 'V':
v15 = (const char *)getstrvers();
puts(v15);
exit(0);
case 'a':
deviatonly = 0;
break;
case 'b':
if ( !(unsigned int)hhmm2secs(optarg, &begintime) )
goto LABEL_11;
break;
case 'e':
if ( !(unsigned int)hhmm2secs(optarg, &endtime) )
LABEL_11:
prusage(*argv);
break;
case 'r':
if ( optind < argc )
{
v14 = argv[optind];
if ( *v14 != 45 )
{
++optind;
strncpy(rawname, v14, 0xFFuLL);
}
}
++rawreadflag;
break;
case 'w':
if ( optind >= argc )
prusage(*argv);
v13 = argv[optind++];
strncpy(rawname, v13, 0xFFuLL);
vis = (__int64 (__fastcall *)(_QWORD, _QWORD, _QWORD, _QWORD, _QWORD))&rawwrite;
break;
default:
v12 = v7++;
flaglist[v12] = v8;
break;
}
}
while ( v7 != 63 );
if ( optind <= 63 && optind < argc )
{
if ( !(unsigned int)numeric(argv[optind]) )
prusage(*argv);
v16 = optind;
v17 = optind + 1;
v18 = atoi(argv[v16]);
optind = v17;
*(_QWORD *)&interval = v18;
if ( v17 < argc )
{
if ( !(unsigned int)numeric(argv[v16 + 1]) )
prusage(*argv);
nsamples = atoi(argv[optind]);
if ( !nsamples )
prusage(*argv);
}
}
}
uname(&utsname);
v9 = strchr((const char *)(unsigned int)((_DWORD)&utsname + 65), 46);
if ( v9 )
*v9 = 0;
utsnodenamelen = strlen((const char *)(unsigned int)((_DWORD)&utsname + 65));
_isoc99_sscanf((unsigned int)((_DWORD)&utsname + 130), "%d.%d.%d", &osrel, &osvers, &ossub);
hertz = sysconf(2);
pagesize = sysconf(30);
if ( rawreadflag )
{
rawread();
cleanstop(0);
}
curtime = getboot() / (unsigned __int64)(unsigned __int16)hertz;
signal(1, (__sighandler_t)&cleanstop);
signal(15, (__sighandler_t)&cleanstop);
regainrootprivs();
v19[0].rlim_cur = -1LL;
v19[0].rlim_max = -1LL;
setrlimit(__RLIMIT_MEMLOCK, v19);
mlockall(3);
nice(-20);
acctreason = acctswon();
initifprop();
netatop_ipopen();
if ( !(unsigned int)droprootprivs(4294967276LL, v19, v10) )
cleanstop(42);
func4();
cleanstop(0);
return 0;
}

original_code:
int
main(int argc, char *argv[])
{
 register int i;
 int c;
 char *p;
 struct rlimit rlim;
        if (! droprootprivs() )
 {
  fprintf(stderr, "not possible to drop root privs\n");
                exit(42);
 }
 argvp = argv;
 readrc("/etc/atoprc");
 if ( (p = getenv("HOME")) )
 {
  char path[1024];
  snprintf(path, sizeof path, "%s/.atoprc", p);
  readrc(path);
 }
 if ( (p = strrchr(argv[0], '/')))
  p++;
 else
  p = argv[0];
 if ( memcmp(p, "atopsar", 7) == 0)
  return atopsar(argc, argv);
 if (argc > 1)
 {
  i = 0;
  while (i < 64 -1 && (c=getopt(argc, argv, "ab:cde:fghijklmnopqrstuvwxyz1ABCDEFGHIJKL:MNOP:QRSTUVWXYZ")) != (-1))
  {
   switch (c)
   {
      case '?':
    prusage(argv[0]);
    break;
      case 'V':
    printf("%s\n", getstrvers());
    exit(0);
      case 'w':
    if (optind >= argc)
     prusage(argv[0]);
    strncpy(rawname, argv[optind++], 256 -1);
    vis.show_samp = rawwrite;
    break;
      case 'r':
    if (optind < argc && *(argv[optind]) != '-')
     strncpy(rawname, argv[optind++],
       256 -1);
    rawreadflag++;
    break;
      case 'S':
    midnightflag++;
    break;
                           case 'a':
    deviatonly=0;
    break;
                           case 'b':
    if ( !hhmm2secs(optarg, &begintime) )
     prusage(argv[0]);
    break;
                           case 'e':
    if ( !hhmm2secs(optarg, &endtime) )
     prusage(argv[0]);
    break;
                           case 'P':
    if ( !parsedef(optarg) )
     prusage(argv[0]);
    vis.show_samp = parseout;
    break;
                           case 'L':
    if ( !numeric(optarg) )
     prusage(argv[0]);
    linelen = atoi(optarg);
    break;
      default:
    flaglist[i++] = c;
   }
  }
   if (optind < argc && optind < 64)
  {
   if (!numeric(argv[optind]))
    prusage(argv[0]);
   interval = atoi(argv[optind]);
   optind++;
   if (optind < argc)
   {
    if (!numeric(argv[optind]) )
     prusage(argv[0]);
    if ( (nsamples = atoi(argv[optind])) < 1)
     prusage(argv[0]);
   }
  }
 }
 (void) uname(&utsname);
 if ( (p = strchr(utsname.nodename, '.')) )
  *p = '\0';
 utsnodenamelen = strlen(utsname.nodename);
 sscanf(utsname.release, "%d.%d.%d", &osrel, &osvers, &ossub);
 hertz = sysconf(_SC_CLK_TCK);
 pagesize = sysconf(_SC_PAGESIZE);
 if (rawreadflag)
 {
  rawread();
  cleanstop(0);
 }
 curtime = getboot() / hertz;
 signal(1, cleanstop);
 signal(15, cleanstop);
 regainrootprivs();
 rlim.rlim_cur = ((__rlim_t) -1);
 rlim.rlim_max = ((__rlim_t) -1);
 (void) setrlimit(__RLIMIT_MEMLOCK, &rlim);
 (void) mlockall(1|2);
 if ( nice(-20) == -1)
  ;
 acctreason = acctswon();
 initifprop();
 netatop_ipopen();
        if (! droprootprivs() )
  cleanstop(42);
 engine();
 cleanstop(0);
 return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: c int

variable_types:
p
char *

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

variable_types:
path
char [1024]