decompiled_code:
int __fastcall tt_wait(unsigned int a1)
{
unsigned int v1; // ebx

v1 = a1;
rote_vt_draw(rt, term_win, 1LL, 1LL, 0LL);
if ( a1 > 0x3E8 )
{
do
{
usleep(0xF4240u);
v1 -= 1000;
rote_vt_draw(rt, term_win, 1LL, 1LL, 0LL);
wrefresh(term_win);
}
while ( v1 > 0x3E8 );
}
usleep(1000 * v1);
rote_vt_draw(rt, term_win, 1LL, 1LL, 0LL);
return wrefresh(term_win);
}

canonical_decompiled_code:
int __fastcall func1(unsigned int a1)
{
unsigned int v1; // ebx

v1 = a1;
rote_vt_draw(rt, term_win, 1LL, 1LL, 0LL);
if ( a1 > 0x3E8 )
{
do
{
usleep(0xF4240u);
v1 -= 1000;
rote_vt_draw(rt, term_win, 1LL, 1LL, 0LL);
wrefresh(term_win);
}
while ( v1 > 0x3E8 );
}
usleep(1000 * v1);
rote_vt_draw(rt, term_win, 1LL, 1LL, 0LL);
return wrefresh(term_win);
}

original_code:
void tt_wait(unsigned int msec) {
 rote_vt_draw(rt, term_win, 1, 1, ((void *)0));
 while (msec > 1000) {
  usleep(1000000);
  msec -= 1000;
  rote_vt_draw(rt, term_win, 1, 1, ((void *)0));
  wrefresh(term_win);
 }
 usleep(msec * 1000);
 rote_vt_draw(rt, term_win, 1, 1, ((void *)0));
 wrefresh(term_win);
}


repo: akrennmair/tuitest

decompiled_code:
char *__fastcall tt_getrow(unsigned int a1)
{
char *result; // rax
__int64 v2; // rcx
__int64 i; // rax
char v4[104]; // [rsp+0h] [rbp-68h] BYREF

result = 0LL;
if ( a1 <= 0x18 )
{
v2 = *(_QWORD *)(*(_QWORD *)(rt + 8LL) + 8LL * a1);
for ( i = 0LL; i != 80; ++i )
v4[i] = *(_BYTE *)(v2 + 2 * i);
v4[80] = 0;
result = strdup(v4);
}
return result;
}

canonical_decompiled_code:
char *__fastcall func2(unsigned int a1)
{
char *result; // rax
__int64 v2; // rcx
__int64 i; // rax
char v4[104]; // [rsp+0h] [rbp-68h] BYREF

result = 0LL;
if ( a1 <= 0x18 )
{
v2 = *(_QWORD *)(*(_QWORD *)(rt + 8LL) + 8LL * a1);
for ( i = 0LL; i != 80; ++i )
v4[i] = *(_BYTE *)(v2 + 2 * i);
v4[80] = 0;
result = strdup(v4);
}
return result;
}

original_code:
char * tt_getrow(unsigned int row) {
 if (row < 25) {
  char buf[81];
  unsigned int i;
  RoteCell* p = rt->cells[row];
  for (i=0;i<80;i++) {
   buf[i] = p[i].ch;
  }
  buf[80] = '\0';
  return strdup(buf);
 }
 return ((void *)0);
}

canonical_original_code:
char *tt_getrow(unsigned int row) {
 if (row < 25) {
  char buf[81];
  unsigned int i;
  struct RoteCell_ *p = rt->cells[row];
  for (i=0;i<80;i++) {
   buf[i] = p[i].ch;
  }
  buf[80] = '\0';
  return strdup(buf);
 }
 return ((void *)0);
}

variable_types:
row
unsigned int

variable_types:
buf
char [81]

variable_types:
i
unsigned int

variable_types: struct RoteCell_ { unsigned char ch; unsigned char attr; } *

return_type: char *


decompiled_code:
bool __fastcall is_valid_csi_ender(char a1)
{
return (unsigned __int8)((a1 & 0xDF) - 64) <= 0x1Au;
}

canonical_decompiled_code:
bool __fastcall func2(char a1)
{
return (unsigned __int8)((a1 & 0xDF) - 64) <= 0x1Au;
}

original_code:
static inline _Bool is_valid_csi_ender(char c) {
   return (c >= 'a' && c <= 'z') ||
          (c >= 'A' && c <= 'Z') ||
          c == '@' || c == '`';
}

variable_types: c char


original_code:
static inline void put_normal_char(RoteTerm *rt, char c) {
   if (rt->ccol >= rt->cols) {
      rt->ccol = 0;
      cursor_line_down(rt);
   }
   rt->cells[rt->crow][rt->ccol].ch = c;
   rt->cells[rt->crow][rt->ccol].attr = rt->curattr;
   rt->ccol++;
   rt->line_dirty[rt->crow] = 1;
   rt->curpos_dirty = 1;
}

canonical_original_code:
static inline void put_normal_char(struct RoteTerm_ *rt, char c) {
   if (rt->ccol >= rt->cols) {
      rt->ccol = 0;
      cursor_line_down(rt);
   }
   rt->cells[rt->crow][rt->ccol].ch = c;
   rt->cells[rt->crow][rt->ccol].attr = rt->curattr;
   rt->ccol++;
   rt->line_dirty[rt->crow] = 1;
   rt->curpos_dirty = 1;
}

variable_types: struct RoteTerm_ { int rows; struct RoteCell_ { unsigned char ch; unsigned char attr; } **cells; int crow; unsigned char curattr; int childpid; struct RoteTermPrivate_ { _Bool escaped; _Bool graphmode; int scrolltop; int saved_x; char esbuf[128]; int esbuf_len; int pty; int (*handler)(struct RoteTerm_ *rt, char *es); } *pd; _Bool curpos_dirty; _Bool *line_dirty; } *

return_type: void

user_defined_types: struct RoteTerm_ { int rows; struct RoteCell_ **cells; int crow; unsigned char curattr; int childpid; struct RoteTermPrivate_ *pd; _Bool curpos_dirty; _Bool *line_dirty; }


decompiled_code:
__int64 __fastcall put_graphmode_char(__int64 a1, char a2)
{
bool v2; // zf
char v3; // si

if ( a2 <= 119 )
{
if ( a2 > 115 )
v3 = 43;
else
v3 = (unsigned __int8)(a2 - 106) < 5u ? 43 : 37;
}
else
{
v2 = a2 == 120;
v3 = 37;
if ( v2 )
v3 = 124;
}
return put_normal_char(a1, v3);
}

original_code:
static inline void put_graphmode_char(RoteTerm *rt, char c) {
   char nc;
   switch (c) {
      case 'j': case 'k': case 'l': case 'm': case 'n': case 't':
                                    case 'u': case 'v': case 'w':
         nc = '+'; break;
      case 'x':
         nc = '|'; break;
      default:
         nc = '%';
   }
   put_normal_char(rt, nc);
}

canonical_original_code:
static inline void put_graphmode_char(struct RoteTerm_ *rt, char c) {
   char nc;
   switch (c) {
      case 'j': case 'k': case 'l': case 'm': case 'n': case 't':
                                    case 'u': case 'v': case 'w':
         nc = '+'; break;
      case 'x':
         nc = '|'; break;
      default:
         nc = '%';
   }
   put_normal_char(rt, nc);
}

variable_types: nc char

user_defined_types: struct RoteTermPrivate_ { _Bool escaped; _Bool graphmode; int scrolltop; int saved_x; char esbuf[128]; int esbuf_len; int pty; int (*handler)(struct RoteTerm_ *rt, char *es); }

user_defined_types: struct RoteCell_ { unsigned char ch; unsigned char attr; }


decompiled_code:
__int64 __fastcall handle_control_char(__int64 a1, int a2)
{
__int64 result; // rax
__int64 v3; // rdx

if ( (_BYTE)a2 != 0x9B )
return (unsigned int)(a2 - 8);
new_escape_sequence(a1);
v3 = *(_QWORD *)(a1 + 32);
LODWORD(result) = *(_DWORD *)(v3 + 148);
*(_DWORD *)(v3 + 148) = result + 1;
result = (int)result;
*(_BYTE *)(v3 + (int)result + 20) = 91;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, int a2)
{
__int64 result; // rax
__int64 v3; // rdx

if ( (_BYTE)a2 != 0x9B )
return (unsigned int)(a2 - 8);
func0(a1);
v3 = *(_QWORD *)(a1 + 32);
LODWORD(result) = *(_DWORD *)(v3 + 148);
*(_DWORD *)(v3 + 148) = result + 1;
result = (int)result;
*(_BYTE *)(v3 + (int)result + 20) = 91;
return result;
}

original_code:
static void handle_control_char(RoteTerm *rt, char c) {
   switch (c) {
      case '\r': rt->ccol = 0; break;
      case '\n':
         rt->ccol = 0; cursor_line_down(rt);
         rt->curpos_dirty = 1;
         break;
      case '\b':
         if (rt->ccol > 0) rt->ccol--;
         rt->curpos_dirty = 1;
         break;
      case '\t':
         while (rt->ccol % 8) put_normal_char(rt, ' ');
         break;
      case '\x1B':
         new_escape_sequence(rt);
         break;
      case '\x0E':
         rt->pd->graphmode = 1;
         break;
      case '\x0F':
         rt->pd->graphmode = 0;
         break;
      case '\x9B':
         new_escape_sequence(rt);
         rt->pd->esbuf[rt->pd->esbuf_len++] = '[';
         break;
      case '\x18': case '\x1A':
         cancel_escape_sequence(rt);
         break;
      case '\a':
         break;
   }
}

canonical_original_code:
static void handle_control_char(struct RoteTerm_ *rt, char c) {
   switch (c) {
      case '\r': rt->ccol = 0; break;
      case '\n':
         rt->ccol = 0; cursor_line_down(rt);
         rt->curpos_dirty = 1;
         break;
      case '\b':
         if (rt->ccol > 0) rt->ccol--;
         rt->curpos_dirty = 1;
         break;
      case '\t':
         while (rt->ccol % 8) put_normal_char(rt, ' ');
         break;
      case '\x1B':
         new_escape_sequence(rt);
         break;
      case '\x0E':
         rt->pd->graphmode = 1;
         break;
      case '\x0F':
         rt->pd->graphmode = 0;
         break;
      case '\x9B':
         new_escape_sequence(rt);
         rt->pd->esbuf[rt->pd->esbuf_len++] = '[';
         break;
      case '\x18': case '\x1A':
         cancel_escape_sequence(rt);
         break;
      case '\a':
         break;
   }
}


decompiled_code:
void __fastcall try_interpret_escape_seq(__int64 a1)
{
__int64 v1; // rsi
char v2; // bp
char v3; // r12
__int64 (__fastcall *v4)(__int64, __int64); // rax
int v5; // eax

v1 = *(_QWORD *)(a1 + 32);
v2 = *(_BYTE *)(v1 + 20);
if ( !v2 )
return;
v3 = *(_BYTE *)(v1 + *(_DWORD *)(v1 + 148) - 1 + 20);
v4 = *(__int64 (__fastcall **)(__int64, __int64))(v1 + 160);
if ( v4 )
{
v5 = v4(a1, v1 + 20);
if ( !v5 )
{
LABEL_18:
cancel_escape_sequence(a1);
return;
}
if ( v5 == 1 )
return;
}
if ( v2 == 77 )
{
cursor_line_up(a1);
cancel_escape_sequence(a1);
return;
}
if ( ((v2 - 91) & 0xFD) != 0 )
goto LABEL_18;
if ( v2 == 91 )
{
if ( is_valid_csi_ender(v3) )
{
rote_es_interpret_csi(a1);
cancel_escape_sequence(a1);
}
}
else if ( v2 == 93 && v3 == 7 )
{
cancel_escape_sequence(a1);
}
if ( *(int *)(*(_QWORD *)(a1 + 32) + 148LL) > 126 )
goto LABEL_18;
}

original_code:
static void try_interpret_escape_seq(RoteTerm *rt) {
   char firstchar = rt->pd->esbuf[0];
   char lastchar = rt->pd->esbuf[rt->pd->esbuf_len-1];
   if (!firstchar) return;
   if (rt->pd->handler) {
      int answer = (*(rt->pd->handler))(rt, rt->pd->esbuf);
      if (answer == 0) {
         cancel_escape_sequence(rt);
         return;
      }
      else if (answer == 1) {
         return;
      }
   }
   if (firstchar == 'M') {
      cursor_line_up(rt);
      cancel_escape_sequence(rt);
      return;
   }
   if (firstchar != '[' && firstchar != ']') {
      cancel_escape_sequence(rt);
      return;
   }
   if (firstchar == '[' && is_valid_csi_ender(lastchar)) {
      rote_es_interpret_csi(rt);
      cancel_escape_sequence(rt);
   }
   else if (firstchar == ']' && lastchar == '\a') {
      cancel_escape_sequence(rt);
   }
   if (rt->pd->esbuf_len + 1 >= 128) cancel_escape_sequence(rt);
}

canonical_original_code:
static void try_interpret_escape_seq(struct RoteTerm_ *rt) {
   char firstchar = rt->pd->esbuf[0];
   char lastchar = rt->pd->esbuf[rt->pd->esbuf_len-1];
   if (!firstchar) return;
   if (rt->pd->handler) {
      int answer = (*(rt->pd->handler))(rt, rt->pd->esbuf);
      if (answer == 0) {
         cancel_escape_sequence(rt);
         return;
      }
      else if (answer == 1) {
         return;
      }
   }
   if (firstchar == 'M') {
      cursor_line_up(rt);
      cancel_escape_sequence(rt);
      return;
   }
   if (firstchar != '[' && firstchar != ']') {
      cancel_escape_sequence(rt);
      return;
   }
   if (firstchar == '[' && is_valid_csi_ender(lastchar)) {
      rote_es_interpret_csi(rt);
      cancel_escape_sequence(rt);
   }
   else if (firstchar == ']' && lastchar == '\a') {
      cancel_escape_sequence(rt);
   }
   if (rt->pd->esbuf_len + 1 >= 128) cancel_escape_sequence(rt);
}

variable_types: firstchar char

variable_types: lastchar char

variable_types: answer int


original_code:
void rote_vt_inject(RoteTerm *rt, const char *data, int len) {
   int i;
   for (i = 0; i < len; i++, data++) {
      if (*data == 0) continue;
      if (*data >= 1 && *data <= 31) {
         handle_control_char(rt, *data);
         continue;
      }
      if (rt->pd->escaped && rt->pd->esbuf_len < 128) {
         rt->pd->esbuf[rt->pd->esbuf_len] = *data;
         rt->pd->esbuf[++rt->pd->esbuf_len] = 0;
         try_interpret_escape_seq(rt);
      }
      else if (rt->pd->graphmode)
         put_graphmode_char(rt, *data);
      else
         put_normal_char(rt, *data);
   }
}

canonical_original_code:
void rote_vt_inject(struct RoteTerm_ *rt, char *data, int len) {
   int i;
   for (i = 0; i < len; i++, data++) {
      if (*data == 0) continue;
      if (*data >= 1 && *data <= 31) {
         handle_control_char(rt, *data);
         continue;
      }
      if (rt->pd->escaped && rt->pd->esbuf_len < 128) {
         rt->pd->esbuf[rt->pd->esbuf_len] = *data;
         rt->pd->esbuf[++rt->pd->esbuf_len] = 0;
         try_interpret_escape_seq(rt);
      }
      else if (rt->pd->graphmode)
         put_graphmode_char(rt, *data);
      else
         put_normal_char(rt, *data);
   }
}

variable_types:
data
char *

variable_types: len int

variable_types: i int


getElapsedTime

repo: akshatarao/AOS

decompiled_code:
double __fastcall getElapsedTime(_QWORD *a1, _QWORD *a2)
{
__int64 v2; // rax
double result; // xmm0_8

v2 = a2[1] + 1000000LL * *a2 - (a1[1] + 1000000LL * *a1);
if ( v2 < 0 )
result = (double)(int)(v2 & 1 | ((unsigned __int64)v2 >> 1)) + (double)(int)(v2 & 1 | ((unsigned __int64)v2 >> 1));
else
result = (double)(int)v2;
return result;
}

canonical_decompiled_code:
double __fastcall func7(_QWORD *a1, _QWORD *a2)
{
__int64 v2; // rax
double result; // xmm0_8

v2 = a2[1] + 1000000LL * *a2 - (a1[1] + 1000000LL * *a1);
if ( v2 < 0 )
result = (double)(int)(v2 & 1 | ((unsigned __int64)v2 >> 1)) + (double)(int)(v2 & 1 | ((unsigned __int64)v2 >> 1));
else
result = (double)(int)v2;
return result;
}

original_code:
double getElapsedTime(struct timeval *start_t, struct timeval *finish_t){
        unsigned long start,finish,final_usec,final_sec;
        start=(start_t->tv_sec*1000000 + start_t->tv_usec);
        finish=(finish_t->tv_sec*1000000 + finish_t->tv_usec);
        final_sec =(finish-start)/1000000;
        final_usec = (finish-start)%1000000;
        return (finish-start);
        }

canonical_original_code:
double getElapsedTime(struct timeval *start_t, struct timeval *finish_t){
        unsigned long start; unsigned long finish; unsigned long final_usec; unsigned long final_sec;
        start=(start_t->tv_sec*1000000 + start_t->tv_usec);
        finish=(finish_t->tv_sec*1000000 + finish_t->tv_usec);
        final_sec =(finish-start)/1000000;
        final_usec = (finish-start)%1000000;
        return (finish-start);
        }

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

variable_types:
start
unsigned long

variable_types:
finish
unsigned long

return_type: double


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // ebx
int v4; // eax
void *v5; // rsp
int v6; // er12
_QWORD *v7; // r13
__int64 i; // rbx
_DWORD *v9; // rax
__int64 *v10; // rax
__int64 *v11; // rdx
__int64 v13[6]; // [rsp+0h] [rbp-30h] BYREF

if ( argc <= 2 )
{
printf("\nSyntax: %s numberOfThreads numberOfBarriers", *argv);
fflush(_bss_start);
exit(1);
}
v3 = atoi(argv[1]);
numberOfThreads = v3;
v4 = atoi(argv[2]);
numberOfBarriers = v4;
if ( v4 <= 0 || v3 <= 0 )
{
printf("\nERROR: Number of threads/barriers cannot be negative!");
exit(1);
}
v5 = alloca(4LL * v4);
omp_set_num_threads();
if ( (double)numberOfThreads <= 0.0 )
log((double)numberOfThreads);
v6 = numberOfThreads;
v7 = malloc(8LL * numberOfThreads);
if ( v6 > 0 )
{
for ( i = 0LL; i != v6; v7[i++] = v9 )
{
v9 = malloc(0xCuLL);
*v9 = 0;
v9[1] = 0;
v9[2] = i;
}
}
if ( numberOfBarriers > 0 )
{
v10 = v13;
v11 = (__int64 *)((char *)v13 + 4 * (unsigned int)numberOfBarriers);
do
{
*(_DWORD *)v10 = 0;
v10 = (__int64 *)((char *)v10 + 4);
}
while ( v10 != v11 );
}
v13[1] = (__int64)v13;
v13[0] = (__int64)v7;
GOMP_parallel();
return 0;
}

original_code:
int main(int argc, char** argv)
{
   if(argc < 3)
   {
 printf("\nSyntax: %s numberOfThreads numberOfBarriers", argv[0]);
 fflush(stdout);
 exit(1);
   }
    numberOfThreads = atoi(argv[1]);
    numberOfBarriers = atoi(argv[2]);
    if(numberOfThreads <=0 || numberOfBarriers <= 0) {
      printf("\nERROR: Number of threads/barriers cannot be negative!");
      exit(1);
    }
    int k,l;
    int barrierArray[numberOfBarriers];
    omp_set_num_threads(numberOfThreads);
    int rounds = ceil(log(numberOfThreads)/log(2));
    Thread** threadList = malloc(numberOfThreads*sizeof(Thread*));
    for(k = 0; k < numberOfThreads; k++){
        Thread* thread;
        thread = (Thread*) malloc(sizeof(Thread));
        thread->receivingCount = 0;
        thread->sentCount = 0;
        thread->threadID = k;
        *(threadList + k) = thread;
    }
    for(l = 0;l < numberOfBarriers; l++)
        barrierArray[l] = 0;

#pragma omp parallel shared(numberOfThreads,rounds)
    {
        int i = 0,j;
        struct timeval startTime,endTime;
        double totalTime = 0.00;
        numberOfThreads = omp_get_num_threads();
        int threadId = omp_get_thread_num();
        Thread* thread = *(threadList + threadId);
        for(i = 0; i <numberOfBarriers; i++) {
            j = 0;
            while(j < 9999){
                j++;
            }
            printf("Entered thread %d of %d threads at barrier %d\n", thread->threadID, numberOfThreads-1, i);
           gettimeofday(&startTime, ((void *)0));
           disseminationBarrier(thread,threadList,threadId);
           printf("Completed thread %d of %d threads at barrier %d\n", thread->threadID, numberOfThreads-1, i);

#pragma omp critical
           {
                barrierArray[i] = barrierArray[i] + 1;
           }
           while(barrierArray[i]!= numberOfThreads);
           gettimeofday(&endTime, ((void *)0));
           totalTime = totalTime + getElapsedTime(&startTime,&endTime);
           }
           printf("Time spent in barrier by thread %d is %f\n",thread->threadID,(totalTime/numberOfBarriers));
    }
return 0;
}

canonical_original_code:
int main(int argc, char **argv)
{
   if(argc < 3)
   {
 printf("\nSyntax: %s numberOfThreads numberOfBarriers", argv[0]);
 fflush(stdout);
 exit(1);
   }
    numberOfThreads = atoi(argv[1]);
    numberOfBarriers = atoi(argv[2]);
    if(numberOfThreads <=0 || numberOfBarriers <= 0) {
      printf("\nERROR: Number of threads/barriers cannot be negative!");
      exit(1);
    }
    int k; int l;
    int barrierArray[-1];
    omp_set_num_threads(numberOfThreads);
    int rounds = ceil(log(numberOfThreads)/log(2));
    struct thread_struct **threadList = malloc(numberOfThreads*sizeof(Thread*));
    for(k = 0; k < numberOfThreads; k++){
        struct thread_struct *thread;
        thread = (struct thread_struct *) malloc(sizeof(Thread));
        thread->receivingCount = 0;
        thread->sentCount = 0;
        thread->threadID = k;
        *(threadList + k) = thread;
    }
    for(l = 0;l < numberOfBarriers; l++)
        barrierArray[l] = 0;

#pragma omp parallel shared(numberOfThreads,rounds)
    {
        int i = 0; int j;
        struct timeval startTime; struct timeval endTime;
        double totalTime = 0.00;
        numberOfThreads = omp_get_num_threads();
        int threadId = omp_get_thread_num();
        struct thread_struct *thread = *(threadList + threadId);
        for(i = 0; i <numberOfBarriers; i++) {
            j = 0;
            while(j < 9999){
                j++;
            }
            printf("Entered thread %d of %d threads at barrier %d\n", thread->threadID, numberOfThreads-1, i);
           gettimeofday(&startTime, ((void *)0));
           disseminationBarrier(thread,threadList,threadId);
           printf("Completed thread %d of %d threads at barrier %d\n", thread->threadID, numberOfThreads-1, i);

#pragma omp critical
           {
                barrierArray[i] = barrierArray[i] + 1;
           }
           while(barrierArray[i]!= numberOfThreads);
           gettimeofday(&endTime, ((void *)0));
           totalTime = totalTime + getElapsedTime(&startTime,&endTime);
           }
           printf("Time spent in barrier by thread %d is %f\n",thread->threadID,(totalTime/numberOfBarriers));
    }
return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types: k int

variable_types: l int

variable_types:
barrierArray
int [-1]

variable_types: rounds int

variable_types: struct thread_struct { int receivingCount; int sentCount; int threadID; } **

variable_types: j int

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

variable_types: totalTime double

variable_types: threadId int

return_type: int


centralizedThreadBarrierLogic

decompiled_code:
__int64 __fastcall centralizedThreadBarrierLogic(__int64 a1, _DWORD *a2, _DWORD *a3)
{
int v4; // eax
__int64 result; // rax

v4 = 9999;
do
--v4;
while ( v4 );
*(_DWORD *)(*(_QWORD *)a1 + 4LL) = *(_DWORD *)(*(_QWORD *)a1 + 4LL) == 0;
GOMP_critical_start();
if ( (*a2)-- == 1 )
{
printf("\nSwitching Global Sense to %d", *(unsigned int *)(*(_QWORD *)a1 + 4LL));
*a2 = numberOfThreads;
*a3 = *(_DWORD *)(*(_QWORD *)a1 + 4LL);
}
GOMP_critical_end();
result = (unsigned int)*a3;
while ( *(_DWORD *)(*(_QWORD *)a1 + 4LL) != (_DWORD)result )
;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, _DWORD *a2, _DWORD *a3)
{
int v4; // eax
__int64 result; // rax

v4 = 9999;
do
--v4;
while ( v4 );
*(_DWORD *)(*(_QWORD *)a1 + 4LL) = *(_DWORD *)(*(_QWORD *)a1 + 4LL) == 0;
GOMP_critical_start();
if ( (*a2)-- == 1 )
{
printf("\nSwitching Global Sense to %d", *(unsigned int *)(*(_QWORD *)a1 + 4LL));
*a2 = numberOfThreads;
*a3 = *(_DWORD *)(*(_QWORD *)a1 + 4LL);
}
GOMP_critical_end();
result = (unsigned int)*a3;
while ( *(_DWORD *)(*(_QWORD *)a1 + 4LL) != (_DWORD)result )
;
return result;
}

original_code:
void centralizedThreadBarrierLogic(Thread **thread, int* countOfThreads, int* globalSense)
{
  int i = 0;
  while(i < 9999)
      i++;
  (*thread)->sense = !(*thread)->sense;

#pragma omp critical
  {
      *countOfThreads = *countOfThreads - 1;
    if(*countOfThreads == 0)
    {
       printf("\nSwitching Global Sense to %d", (*thread)->sense);
        *countOfThreads = numberOfThreads;
        *globalSense = (*thread)->sense;
    }
  }
  i = 0;
  while((*thread)->sense != *globalSense)
  {
 i++;
  }
}

canonical_original_code:
void centralizedThreadBarrierLogic(struct thread_struct **thread, int *countOfThreads, int *globalSense)
{
  int i = 0;
  while(i < 9999)
      i++;
  (*thread)->sense = !(*thread)->sense;

#pragma omp critical
  {
      *countOfThreads = *countOfThreads - 1;
    if(*countOfThreads == 0)
    {
       printf("\nSwitching Global Sense to %d", (*thread)->sense);
        *countOfThreads = numberOfThreads;
        *globalSense = (*thread)->sense;
    }
  }
  i = 0;
  while((*thread)->sense != *globalSense)
  {
 i++;
  }
}

variable_types: struct thread_struct { int count; int sense; int localBarrierCounter; } **

variable_types:
countOfThreads
int *

variable_types:
globalSense
int *


centralizedOMP

decompiled_code:
int __fastcall centralizedOMP(int a1, int a2)
{
__int64 v2; // rax
int i; // er12
__int64 v4; // rax
float v5; // xmm0_4

if ( a1 <= 0 || a2 <= 0 )
{
printf("\nERROR: Number of threads/barriers cannot be negative!");
exit(1);
}
v2 = 0LL;
do
barrierTimeCounter[v2++] = 0.0;
while ( a2 > (int)v2 );
omp_set_num_threads();
globalThreadSense = 1;
for ( i = 0; i < a2; ++i )
{
threadCounter = a1;
GOMP_parallel();
}
v4 = 0LL;
v5 = 0.0;
do
v5 = v5 + barrierTimeCounter[v4++];
while ( a2 > (int)v4 );
return printf("\nAverage time taken at Barriers is %f\n", (float)(v5 / (float)a2));
}

canonical_decompiled_code:
int __fastcall func9(int a1, int a2)
{
__int64 v2; // rax
int i; // er12
__int64 v4; // rax
float v5; // xmm0_4

if ( a1 <= 0 || a2 <= 0 )
{
printf("\nERROR: Number of threads/barriers cannot be negative!");
exit(1);
}
v2 = 0LL;
do
barrierTimeCounter[v2++] = 0.0;
while ( a2 > (int)v2 );
omp_set_num_threads();
globalThreadSense = 1;
for ( i = 0; i < a2; ++i )
{
threadCounter = a1;
GOMP_parallel();
}
v4 = 0LL;
v5 = 0.0;
do
v5 = v5 + barrierTimeCounter[v4++];
while ( a2 > (int)v4 );
return printf("\nAverage time taken at Barriers is %f\n", (float)(v5 / (float)a2));
}

original_code:
void centralizedOMP(int numberOfThreads, int numberOfBarriers)
{
  if(numberOfThreads <=0 || numberOfBarriers <= 0)
  {
      printf("\nERROR: Number of threads/barriers cannot be negative!");
      exit(1);
  }
  int i = 0;
  for(i = 0; i < numberOfBarriers; i++)
  {
       barrierTimeCounter[i] = 0.0;
  }
  omp_set_num_threads(numberOfThreads);
  globalThreadSense = 1;
  for(i = 0; i < numberOfBarriers; i++)
  {
    threadCounter = numberOfThreads;

#pragma omp parallel shared(globalThreadSense, numberOfThreads)
       {
      struct timeval startTime, endTime;
     double totalTime;
      numberOfThreads = omp_get_num_threads();
      Thread* thread;
      thread = (Thread*)malloc(sizeof(Thread));
      thread->sense = 1;
      int i = 0, j =0, threadID;
      threadID = omp_get_thread_num();
          j = 0;
          while(j < 9999)
          {
              j++;
          }
          printf("\nEntered thread %d  of %d threads at barrier %d", threadID, numberOfThreads, i);
   gettimeofday(&startTime, ((void *)0));
          centralizedThreadBarrierLogic(&thread, &threadCounter, &globalThreadSense);
   gettimeofday(&endTime, ((void *)0));
   totalTime = (endTime.tv_sec * 1000000 + endTime.tv_usec)- (startTime.tv_sec * 1000000 + startTime.tv_usec);
   printf("\nTotal time at barrier %d by thread %d is %f", i, threadID, totalTime);

#pragma omp critical
   {
  barrierTimeCounter[i] += (float)totalTime;
   }
          j = 0;
          while(j < 9999)
          {
              j++;
          }
          printf("\nCompleted thread %d of %d threads at barrier %d %d", threadID, numberOfThreads, i, thread->sense, globalThreadSense);
   }
  }
  float totalBarrierTime = 0.0;
  for(i = 0; i < numberOfBarriers; i++)
  {
        totalBarrierTime += barrierTimeCounter[i];
  }
  printf("\nAverage time taken at Barriers is %f\n", (float)totalBarrierTime/numberOfBarriers);
}

canonical_original_code:
void centralizedOMP(int numberOfThreads, int numberOfBarriers)
{
  if(numberOfThreads <=0 || numberOfBarriers <= 0)
  {
      printf("\nERROR: Number of threads/barriers cannot be negative!");
      exit(1);
  }
  int i = 0;
  for(i = 0; i < numberOfBarriers; i++)
  {
       barrierTimeCounter[i] = 0.0;
  }
  omp_set_num_threads(numberOfThreads);
  globalThreadSense = 1;
  for(i = 0; i < numberOfBarriers; i++)
  {
    threadCounter = numberOfThreads;

#pragma omp parallel shared(globalThreadSense, numberOfThreads)
       {
      struct timeval startTime; struct timeval endTime;
     double totalTime;
      numberOfThreads = omp_get_num_threads();
      struct thread_struct *thread;
      thread = (struct thread_struct *)malloc(sizeof(Thread));
      thread->sense = 1;
      int i = 0; int j = 0; int threadID;
      threadID = omp_get_thread_num();
          j = 0;
          while(j < 9999)
          {
              j++;
          }
          printf("\nEntered thread %d  of %d threads at barrier %d", threadID, numberOfThreads, i);
   gettimeofday(&startTime, ((void *)0));
          centralizedThreadBarrierLogic(&thread, &threadCounter, &globalThreadSense);
   gettimeofday(&endTime, ((void *)0));
   totalTime = (endTime.tv_sec * 1000000 + endTime.tv_usec)- (startTime.tv_sec * 1000000 + startTime.tv_usec);
   printf("\nTotal time at barrier %d by thread %d is %f", i, threadID, totalTime);

#pragma omp critical
   {
  barrierTimeCounter[i] += (float)totalTime;
   }
          j = 0;
          while(j < 9999)
          {
              j++;
          }
          printf("\nCompleted thread %d of %d threads at barrier %d %d", threadID, numberOfThreads, i, thread->sense, globalThreadSense);
   }
  }
  float totalBarrierTime = 0.0;
  for(i = 0; i < numberOfBarriers; i++)
  {
        totalBarrierTime += barrierTimeCounter[i];
  }
  printf("\nAverage time taken at Barriers is %f\n", (float)totalBarrierTime/numberOfBarriers);
}

variable_types: numberOfThreads int

variable_types: numberOfBarriers int

variable_types: i int

variable_types: struct thread_struct { int count; int sense; int localBarrierCounter; } *

variable_types: threadID int

variable_types: totalBarrierTime float

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


main

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

if ( argc <= 2 )
{
printf("\nSyntax: <executable> numberOfThreads numberOfBarriers");
exit(1);
}
v3 = atoi(argv[1]);
v4 = atoi(argv[2]);
if ( v3 <= 0 || v4 <= 0 )
{
printf("\nInvalid Inputs!");
exit(1);
}
centralizedOMP(v3, v4);
return 0;
}

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

if ( argc <= 2 )
{
printf("\nSyntax: <executable> numberOfThreads numberOfBarriers");
exit(1);
}
v3 = atoi(argv[1]);
v4 = atoi(argv[2]);
if ( v3 <= 0 || v4 <= 0 )
{
printf("\nInvalid Inputs!");
exit(1);
}
func9(v3, v4);
return 0;
}

original_code:
int main(int argc, char* argv[])
{
    if(argc < 3)
    {
        printf("\nSyntax: <executable> numberOfThreads numberOfBarriers");
        exit(1);
    }
    int numberOfThreads = atoi(argv[1]);
    int numberOfBarriers = atoi(argv[2]);
    if(numberOfThreads <= 0 || numberOfBarriers <= 0)
    {
        printf("\nInvalid Inputs!");
        exit(1);
    }
    centralizedOMP(numberOfThreads,numberOfBarriers);
}

canonical_original_code:
int main(int argc, char *argv[])
{
    if(argc < 3)
    {
        printf("\nSyntax: <executable> numberOfThreads numberOfBarriers");
        exit(1);
    }
    int numberOfThreads = atoi(argv[1]);
    int numberOfBarriers = atoi(argv[2]);
    if(numberOfThreads <= 0 || numberOfBarriers <= 0)
    {
        printf("\nInvalid Inputs!");
        exit(1);
    }
    centralizedOMP(numberOfThreads,numberOfBarriers);
}

variable_types: argc int

variable_types:
argv
char *[]


baselineOMP

decompiled_code:
int __fastcall baselineOMP(int a1, int a2)
{
float *v2; // rax
__int64 v3; // rbx
unsigned int v4; // ebp
__m128i v5; // xmm2

if ( a1 <= 0 || a2 <= 0 )
{
printf("\nERROR: Number of threads/barriers cannot be negative!");
exit(1);
}
v2 = barrierTimeCounter;
do
*v2++ = 0.0;
while ( v2 != (float *)&end );
omp_set_num_threads();
GOMP_parallel();
v3 = 0LL;
v4 = 0;
do
{
printf("\nTime taken at Barrier %d is %f", (unsigned int)v3, barrierTimeCounter[v3]);
v5 = _mm_cvtsi32_si128(v4);
*(float *)v5.m128i_i32 = *(float *)v5.m128i_i32 + barrierTimeCounter[v3];
v4 = _mm_cvtsi128_si32(v5);
++v3;
}
while ( a2 > (int)v3 );
return printf("\nAverage time taken at Barriers is %f\n", (float)(*(float *)v5.m128i_i32 / (float)a2));
}

canonical_decompiled_code:
int __fastcall func8(int a1, int a2)
{
float *v2; // rax
__int64 v3; // rbx
unsigned int v4; // ebp
__m128i v5; // xmm2

if ( a1 <= 0 || a2 <= 0 )
{
printf("\nERROR: Number of threads/barriers cannot be negative!");
exit(1);
}
v2 = barrierTimeCounter;
do
*v2++ = 0.0;
while ( v2 != (float *)&end );
omp_set_num_threads();
GOMP_parallel();
v3 = 0LL;
v4 = 0;
do
{
printf("\nTime taken at Barrier %d is %f", (unsigned int)v3, barrierTimeCounter[v3]);
v5 = _mm_cvtsi32_si128(v4);
*(float *)v5.m128i_i32 = *(float *)v5.m128i_i32 + barrierTimeCounter[v3];
v4 = _mm_cvtsi128_si32(v5);
++v3;
}
while ( a2 > (int)v3 );
return printf("\nAverage time taken at Barriers is %f\n", (float)(*(float *)v5.m128i_i32 / (float)a2));
}

original_code:
void baselineOMP(int numberOfThreads, int numberOfBarriers)
{
  if(numberOfThreads <=0 || numberOfBarriers <= 0)
  {
      printf("\nERROR: Number of threads/barriers cannot be negative!");
      exit(1);
  }
  int i = 0;
  for(i = 0; i < 100000; i++)
  {
       barrierTimeCounter[i] = 0.0;
  }
  omp_set_num_threads(numberOfThreads);

#pragma omp parallel shared(numberOfThreads)
  {
     struct timeval startTime, endTime;
     double totalTime;
       numberOfThreads = omp_get_num_threads();
      int i = 0, j =0, threadID;
      threadID = omp_get_thread_num();
      for(i = 0; i <numberOfBarriers; i++)
      {
          j = 0;
          while(j < 9999)
          {
              j++;
          }
          printf("\nEntered thread %d  of %d threads at barrier %d", threadID, numberOfThreads, i);
          gettimeofday(&startTime, ((void *)0));

#pragma omp barrier
   {
          }
          gettimeofday(&endTime, ((void *)0));
          totalTime = (endTime.tv_sec * 1000000 + endTime.tv_usec)- (startTime.tv_sec * 1000000 + startTime.tv_usec);
          printf("\nTotal time at barrier %d by thread %d is %f", i, threadID, totalTime);

#pragma omp critical
          {
                barrierTimeCounter[i] += (float)totalTime;
          }
          j = 0;
          while(j < 9999)
          {
              j++;
          }
          printf("\nCompleted thread %d of %d threads at barrier %d", threadID, numberOfThreads, i);
      }
  }
  float totalBarrierTime = 0.0;
  for(i = 0; i < numberOfBarriers; i++)
  {
        printf("\nTime taken at Barrier %d is %f", i, barrierTimeCounter[i]);
        totalBarrierTime += barrierTimeCounter[i];
  }
  printf("\nAverage time taken at Barriers is %f\n", (float)totalBarrierTime/numberOfBarriers);
}

canonical_original_code:
void baselineOMP(int numberOfThreads, int numberOfBarriers)
{
  if(numberOfThreads <=0 || numberOfBarriers <= 0)
  {
      printf("\nERROR: Number of threads/barriers cannot be negative!");
      exit(1);
  }
  int i = 0;
  for(i = 0; i < 100000; i++)
  {
       barrierTimeCounter[i] = 0.0;
  }
  omp_set_num_threads(numberOfThreads);

#pragma omp parallel shared(numberOfThreads)
  {
     struct timeval startTime; struct timeval endTime;
     double totalTime;
       numberOfThreads = omp_get_num_threads();
      int i = 0; int j = 0; int threadID;
      threadID = omp_get_thread_num();
      for(i = 0; i <numberOfBarriers; i++)
      {
          j = 0;
          while(j < 9999)
          {
              j++;
          }
          printf("\nEntered thread %d  of %d threads at barrier %d", threadID, numberOfThreads, i);
          gettimeofday(&startTime, ((void *)0));

#pragma omp barrier
   {
          }
          gettimeofday(&endTime, ((void *)0));
          totalTime = (endTime.tv_sec * 1000000 + endTime.tv_usec)- (startTime.tv_sec * 1000000 + startTime.tv_usec);
          printf("\nTotal time at barrier %d by thread %d is %f", i, threadID, totalTime);

#pragma omp critical
          {
                barrierTimeCounter[i] += (float)totalTime;
          }
          j = 0;
          while(j < 9999)
          {
              j++;
          }
          printf("\nCompleted thread %d of %d threads at barrier %d", threadID, numberOfThreads, i);
      }
  }
  float totalBarrierTime = 0.0;
  for(i = 0; i < numberOfBarriers; i++)
  {
        printf("\nTime taken at Barrier %d is %f", i, barrierTimeCounter[i]);
        totalBarrierTime += barrierTimeCounter[i];
  }
  printf("\nAverage time taken at Barriers is %f\n", (float)totalBarrierTime/numberOfBarriers);
}


main

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

if ( argc <= 2 )
{
printf("\nSyntax: %s numberOfThreads numberOfBarriers\n", *argv);
exit(1);
}
v3 = atoi(argv[1]);
v4 = atoi(argv[2]);
if ( v4 > 100000 )
{
printf("\nNumber of Barriers exceeded");
exit(1);
}
baselineOMP(v3, v4);
return 0;
}

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

if ( argc <= 2 )
{
printf("\nSyntax: %s numberOfThreads numberOfBarriers\n", *argv);
exit(1);
}
v3 = atoi(argv[1]);
v4 = atoi(argv[2]);
if ( v4 > 100000 )
{
printf("\nNumber of Barriers exceeded");
exit(1);
}
func8(v3, v4);
return 0;
}

original_code:
int main(int argc, char** argv)
{
  int numberOfThreads, numberOfBarriers;
  if(argc < 3)
  {
 printf("\nSyntax: %s numberOfThreads numberOfBarriers\n", argv[0]);
 exit(1);
  }
  numberOfThreads = atoi(argv[1]);
  numberOfBarriers = atoi(argv[2]);
  if(numberOfBarriers > 100000)
  {
 printf("\nNumber of Barriers exceeded");
 exit(1);
  }
  baselineOMP(numberOfThreads, numberOfBarriers);
  return 0;
}

canonical_original_code:
int main(int argc, char **argv)
{
  int numberOfThreads; int numberOfBarriers;
  if(argc < 3)
  {
 printf("\nSyntax: %s numberOfThreads numberOfBarriers\n", argv[0]);
 exit(1);
  }
  numberOfThreads = atoi(argv[1]);
  numberOfBarriers = atoi(argv[2]);
  if(numberOfBarriers > 100000)
  {
 printf("\nNumber of Barriers exceeded");
 exit(1);
  }
  baselineOMP(numberOfThreads, numberOfBarriers);
  return 0;
}

variable_types:
argv
char **


signalHandler

repo: aktau/hhpc

decompiled_code:
void signalHandler()
{
working = 0;
}

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

original_code:
static void signalHandler(int signo) {
    working = 0;
}

variable_types: signo int


parseOptions

decompiled_code:
__int64 __fastcall parseOptions(int argc, char **argv)
{
int v2; // eax
__int64 result; // rax
unsigned __int64 i; // r12

while ( 1 )
{
v2 = getopt(argc, argv, "i:hv");
if ( v2 == -1 )
break;
switch ( v2 )
{
case 'i':
gIdleTimeout = atoi(optarg);
break;
case 'v':
gVerbose = 1;
break;
case 'h':
gDisplayHelp = 1;
break;
default:
return 0LL;
}
}
result = 1LL;
if ( optind != argc )
{
fprintf(stderr, "%s: wrong number of arguments -- expected none, found:", *argv);
for ( i = optind; i < argc; ++i )
fprintf(stderr, " '%s'", argv[i]);
fputc(10, stderr);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(int argc, char **argv)
{
int v2; // eax
__int64 result; // rax
unsigned __int64 i; // r12

while ( 1 )
{
v2 = getopt(argc, argv, "i:hv");
if ( v2 == -1 )
break;
switch ( v2 )
{
case 'i':
gIdleTimeout = atoi(optarg);
break;
case 'v':
gVerbose = 1;
break;
case 'h':
gDisplayHelp = 1;
break;
default:
return 0LL;
}
}
result = 1LL;
if ( optind != argc )
{
fprintf(stderr, "%s: wrong number of arguments -- expected none, found:", *argv);
for ( i = optind; i < argc; ++i )
fprintf(stderr, " '%s'", argv[i]);
fputc(10, stderr);
result = 0LL;
}
return result;
}

original_code:
static int parseOptions(int argc, char *argv[]) {
    int option = 0;
    while ((option = getopt(argc, argv, "i:hv")) != -1) {
        switch (option) {
            case 'i': gIdleTimeout = atoi(optarg); break;
            case 'h': gDisplayHelp = 1; break;
            case 'v': gVerbose = 1; break;
            default: return 0;
        }
    }
    if (optind == argc) {
        return 1;
    }
    else {
        fprintf(stderr, "%s: wrong number of arguments -- expected none, found:", argv[0]);
        for (size_t i = optind; i < argc; ++i) {
            fprintf(stderr, " '%s'", argv[i]);
        }
        fprintf(stderr, "\n");
        return 0;
    }
}

canonical_original_code:
static int parseOptions(int argc, char *argv[]) {
    int option = 0;
    while ((option = getopt(argc, argv, "i:hv")) != -1) {
        switch (option) {
            case 'i': gIdleTimeout = atoi(optarg); break;
            case 'h': gDisplayHelp = 1; break;
            case 'v': gVerbose = 1; break;
            default: return 0;
        }
    }
    if (optind == argc) {
        return 1;
    }
    else {
        fprintf(stderr, "%s: wrong number of arguments -- expected none, found:", argv[0]);
        for (unsigned long i = optind; i < argc; ++i) {
            fprintf(stderr, " '%s'", argv[i]);
        }
        fprintf(stderr, "\n");
        return 0;
    }
}

variable_types: option int

variable_types:
i
unsigned long


usage

decompiled_code:
int __fastcall usage(const char *a1)
{
int v1; // ebp
int result; // eax
const char *v3; // rdx
char **v4; // rbx

v1 = maxStrlen((const char **)optionDescs_0);
result = printf("usage: %s [-hv] [-i seconds]\n", a1);
v3 = optionDescs_0[0];
if ( *optionDescs_0[0] )
{
v4 = optionDescs_0;
do
{
result = printf(" %-*s %s\n", v1, v3, v4[1]);
v3 = v4[2];
v4 += 2;
}
while ( *v3 );
}
return result;
}

canonical_decompiled_code:
int __fastcall func3(const char *a1)
{
int v1; // ebp
int result; // eax
const char *v3; // rdx
char **v4; // rbx

v1 = func2((const char **)optionDescs_0);
result = printf("usage: %s [-hv] [-i seconds]\n", a1);
v3 = optionDescs_0[0];
if ( *optionDescs_0[0] )
{
v4 = optionDescs_0;
do
{
result = printf(" %-*s %s\n", v1, v3, v4[1]);
v3 = v4[2];
v4 += 2;
}
while ( *v3 );
}
return result;
}

original_code:
static void usage(char *progName) {
    static char *optionDescs[] = {
        "-i seconds", "amount of time to wait before hiding the cursor",
        "-h", "display this help message",
        "-v", "be verbose",
        ""
    };
    size_t maxLen = maxStrlen(optionDescs);
    printf("usage: %s [-hv] [-i seconds]\n", progName);
    for (size_t i = 0; *optionDescs[i] != '\0'; i += 2) {
        printf("    %-*s    %s\n", maxLen, optionDescs[i], optionDescs[i+1]);
    }
}

canonical_original_code:
static void usage(char *progName) {
    static char *optionDescs[] = {
        "-i seconds", "amount of time to wait before hiding the cursor",
        "-h", "display this help message",
        "-v", "be verbose",
        ""
    };
    unsigned long maxLen = maxStrlen(optionDescs);
    printf("usage: %s [-hv] [-i seconds]\n", progName);
    for (unsigned long i = 0; *optionDescs[i] != '\0'; i += 2) {
        printf("    %-*s    %s\n", maxLen, optionDescs[i], optionDescs[i+1]);
    }
}

variable_types:
progName
char *

variable_types:
optionDescs
char *[]

variable_types:
maxLen
unsigned long


setupSignals

decompiled_code:
__int64 setupSignals()
{
int v0; // edx
__int64 result; // rax
struct sigaction v2; // [rsp+0h] [rbp-A8h] BYREF

memset(&v2.sa_mask, 0, 0x90uLL);
v2.sa_handler = (__sighandler_t)signalHandler;
sigemptyset(&v2.sa_mask);
if ( sigaction(15, &v2, 0LL) == -1 )
{
perror("hhpc: could not register SIGTERM");
result = 0LL;
}
else if ( sigaction(1, &v2, 0LL) == -1 )
{
perror("hhpc: could not register SIGHUP");
result = 0LL;
}
else if ( sigaction(2, &v2, 0LL) == -1 )
{
perror("hhpc: could not register SIGINT");
result = 0LL;
}
else
{
v0 = sigaction(3, &v2, 0LL);
result = 1LL;
if ( v0 == -1 )
{
perror("hhpc: could not register SIGQUIT");
result = 0LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 func5()
{
int v0; // edx
__int64 result; // rax
struct sigaction v2; // [rsp+0h] [rbp-A8h] BYREF

memset(&v2.sa_mask, 0, 0x90uLL);
v2.sa_handler = (__sighandler_t)signalHandler;
sigemptyset(&v2.sa_mask);
if ( sigaction(15, &v2, 0LL) == -1 )
{
perror("hhpc: could not register SIGTERM");
result = 0LL;
}
else if ( sigaction(1, &v2, 0LL) == -1 )
{
perror("hhpc: could not register SIGHUP");
result = 0LL;
}
else if ( sigaction(2, &v2, 0LL) == -1 )
{
perror("hhpc: could not register SIGINT");
result = 0LL;
}
else
{
v0 = sigaction(3, &v2, 0LL);
result = 1LL;
if ( v0 == -1 )
{
perror("hhpc: could not register SIGQUIT");
result = 0LL;
}
}
return result;
}

original_code:
static int setupSignals() {
    struct sigaction act;
    memset(&act, 0, sizeof(act));
    act.__sigaction_handler.sa_handler = signalHandler;
    act.sa_flags = 0;
    sigemptyset(&act.sa_mask);
    if (sigaction(15, &act, ((void *)0)) == -1) {
        perror("hhpc: could not register SIGTERM");
        return 0;
    }
    if (sigaction(1, &act, ((void *)0)) == -1) {
        perror("hhpc: could not register SIGHUP");
        return 0;
    }
    if (sigaction(2, &act, ((void *)0)) == -1) {
        perror("hhpc: could not register SIGINT");
        return 0;
    }
    if (sigaction(3, &act, ((void *)0)) == -1) {
        perror("hhpc: could not register SIGQUIT");
        return 0;
    }
    return 1;
}

variable_types: struct sigaction { union { void (*sa_handler)(int); void (*sa_sigaction)(int, struct siginfo_t { int si_signo; int si_errno; int si_code; int __pad0; union { int _pad[-1]; struct { int si_pid; unsigned int si_uid; } _kill; struct { int si_tid; int si_overrun; union sigval { int sival_int; void *sival_ptr; } si_sigval; } _timer; struct { int si_pid; unsigned int si_uid; union sigval si_sigval; } _rt; struct { int si_pid; unsigned int si_uid; int si_status; long si_utime; long si_stime; } _sigchld; struct { void *si_addr; short si_addr_lsb; union { struct { void *_lower; void *_upper; } _addr_bnd; unsigned int _pkey; } _bounds; } _sigfault; struct { long si_band; int si_fd; } _sigpoll; struct { void *_call_addr; int _syscall; unsigned int _arch; } _sigsys; } _sifields; } *, void *); } __sigaction_handler; struct __sigset_t { unsigned long __val[-1]; } sa_mask; int sa_flags; void (*sa_restorer)(); }

user_defined_types: struct sigaction { union { void (*sa_handler)(int); void (*sa_sigaction)(int, struct siginfo_t *, void *); } __sigaction_handler; struct __sigset_t sa_mask; int sa_flags; void (*sa_restorer)(); }

user_defined_types: struct siginfo_t { int si_signo; int si_errno; int si_code; int __pad0; union { int _pad[-1]; struct { int si_pid; unsigned int si_uid; } _kill; struct { int si_tid; int si_overrun; union sigval si_sigval; } _timer; struct { int si_pid; unsigned int si_uid; union sigval si_sigval; } _rt; struct { int si_pid; unsigned int si_uid; int si_status; long si_utime; long si_stime; } _sigchld; struct { void *si_addr; short si_addr_lsb; union { struct { void *_lower; void *_upper; } _addr_bnd; unsigned int _pkey; } _bounds; } _sigfault; struct { long si_band; int si_fd; } _sigpoll; struct { void *_call_addr; int _syscall; unsigned int _arch; } _sigsys; } _sifields; }


delay

decompiled_code:
void __fastcall delay(__time_t a1, __int64 a2)
{
struct timespec v2; // [rsp+0h] [rbp-18h] BYREF

v2.tv_sec = a1;
v2.tv_nsec = 1000000 * (a2 % 1000);
if ( nanosleep(&v2, 0LL) == -1 )
signalHandler();
}

canonical_decompiled_code:
void __fastcall func6(__time_t a1, __int64 a2)
{
struct timespec v2; // [rsp+0h] [rbp-18h] BYREF

v2.tv_sec = a1;
v2.tv_nsec = 1000000 * (a2 % 1000);
if ( nanosleep(&v2, 0LL) == -1 )
func0();
}

original_code:
static void delay(time_t sec, long msec) {
    struct timespec sleep;
    sleep.tv_sec = sec;
    sleep.tv_nsec = (msec % 1000) * 1000 * 1000;
    if (nanosleep(&sleep, ((void *)0)) == -1) {
        signalHandler(0);
    }
}

canonical_original_code:
static void delay(long sec, long msec) {
    struct timespec sleep;
    sleep.tv_sec = sec;
    sleep.tv_nsec = (msec % 1000) * 1000 * 1000;
    if (nanosleep(&sleep, ((void *)0)) == -1) {
        signalHandler(0);
    }
}

variable_types: sec long

variable_types: msec long

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


initializeList

decompiled_code:
_QWORD *initializeList()
{
_QWORD *result; // rax

result = malloc(8uLL);
*result = 0LL;
return result;
}

canonical_decompiled_code:
_QWORD *func0()
{
_QWORD *result; // rax

result = malloc(8uLL);
*result = 0LL;
return result;
}

original_code:
List* initializeList(){
  List *list = (List*)malloc(sizeof(List));
  list->head = ((void *)0);
  return list;
}

canonical_original_code:
struct __LinkedList *initializeList(){
  struct __LinkedList *list = (List*)malloc(sizeof(List));
  list->head = ((void *)0);
  return list;
}

variable_types: struct __LinkedList { struct __Value { int type; union { int boolValue; int intValue; double dblValue; char *stringValue; char *symbolValue; char open; char close; struct __ConsCell { struct __Value *car; struct __Value *cdr; } *cons; }; } *head; } *

user_defined_types: struct __LinkedList { struct __Value *head; }

user_defined_types: struct __Value { int type; union { int boolValue; int intValue; double dblValue; char *stringValue; char *symbolValue; char open; char close; struct __ConsCell *cons; }; }


insertCell

decompiled_code:
__int64 __fastcall insertCell(_QWORD *a1, __int64 a2)
{
__int64 result; // rax
_QWORD *v3; // r12
_QWORD *v4; // rax

if ( !a2 )
return 0LL;
result = 0LL;
if ( a1 )
{
v3 = malloc(0x10uLL);
v4 = malloc(0x10uLL);
*(_DWORD *)v3 = 0;
v3[1] = v4;
*v4 = a2;
v4[1] = *a1;
*a1 = v3;
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(_QWORD *a1, __int64 a2)
{
__int64 result; // rax
_QWORD *v3; // r12
_QWORD *v4; // rax

if ( !a2 )
return 0LL;
result = 0LL;
if ( a1 )
{
v3 = malloc(0x10uLL);
v4 = malloc(0x10uLL);
*(_DWORD *)v3 = 0;
v3[1] = v4;
*v4 = a2;
v4[1] = *a1;
*a1 = v3;
result = 1LL;
}
return result;
}

original_code:
int insertCell(List *list, Value *value){
  if (value==((void *)0) || list==((void *)0)){
    return 0;
  }
  Value *newValue = (Value *)malloc(sizeof(Value));
  ConsCell *newCell = (ConsCell *)malloc(sizeof(ConsCell));
  newValue->type = cellType;
  newValue->cons = newCell;
  newCell->car = value;
  newCell->cdr = list->head;
  list->head = newValue;
  return 1;
}

canonical_original_code:
int insertCell(struct __LinkedList *list, struct __Value *value){
  if (value==((void *)0) || list==((void *)0)){
    return 0;
  }
  struct __Value *newValue = (Value *)malloc(sizeof(Value));
  struct __ConsCell *newCell = (ConsCell *)malloc(sizeof(ConsCell));
  newValue->type = cellType;
  newValue->cons = newCell;
  newCell->car = value;
  newCell->cdr = list->head;
  list->head = newValue;
  return 1;
}

variable_types:
value
struct __Value *

variable_types: struct __Value { int type; union { int boolValue; int intValue; double dblValue; char *stringValue; char *symbolValue; char open; char close; struct __ConsCell { struct __Value *car; struct __Value *cdr; } *cons; }; } *

variable_types: struct __ConsCell { struct __Value { int type; union { int boolValue; int intValue; double dblValue; char *stringValue; char *symbolValue; char open; char close; struct __ConsCell *cons; }; } *car; struct __Value *cdr; } *


push

decompiled_code:
__int64 __fastcall push(_QWORD *a1, __int64 a2)
{
return insertCell(a1, a2);
}

canonical_decompiled_code:
__int64 __fastcall func2(_QWORD *a1, __int64 a2)
{
return func1(a1, a2);
}

original_code:
int push(List *list, Value *value){
  return insertCell(list, value);
}

canonical_original_code:
int push(struct __LinkedList *list, struct __Value *value){
  return insertCell(list, value);
}

user_defined_types: struct __ConsCell { struct __Value *car; struct __Value *cdr; }


pop

original_code:
Value* pop(List *list){
  if (!list){
    return ((void *)0);
  }
  Value *returnValue = ((void *)0);
  Value *prevHead = list->head;
  if(list->head){
    returnValue = prevHead->cons->car;
    list->head = prevHead->cons->cdr;
    free(prevHead->cons);
    free(prevHead);
  }
  return returnValue;
}

canonical_original_code:
struct __Value *pop(struct __LinkedList *list){
  if (!list){
    return ((void *)0);
  }
  struct __Value *returnValue = ((void *)0);
  struct __Value *prevHead = list->head;
  if(list->head){
    returnValue = prevHead->cons->car;
    list->head = prevHead->cons->cdr;
    free(prevHead->cons);
    free(prevHead);
  }
  return returnValue;
}

variable_types: struct __LinkedList { struct __Value *head; } *

return_type: struct __Value { int type; union { int boolValue; int intValue; double dblValue; char *stringValue; char *symbolValue; char open; char close; struct __ConsCell { struct __Value *car; struct __Value *cdr; } *cons; }; } *


destroy

decompiled_code:
void __fastcall destroy(void *ptr)
{
if ( ptr )
{
cleanup(*(void ***)ptr);
free(ptr);
}
}

canonical_decompiled_code:
void __fastcall func7(void *ptr)
{
if ( ptr )
{
func6(*(void ***)ptr);
free(ptr);
}
}

original_code:
void destroy(List* list){
  if (list){
    cleanup(list->head);
    free(list);
  }
}

canonical_original_code:
void destroy(struct __LinkedList *list){
  if (list){
    cleanup(list->head);
    free(list);
  }
}


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
_QWORD *v3; // rbx
_QWORD *v4; // r12
char *v5; // rbp
__int64 v6; // rax
__int64 v7; // rax
_QWORD *v8; // rax
int result; // eax
int v10[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v4 = (_QWORD *)initializeList(argc, argv, envp);
v10[0] = 0;
v5 = (char *)malloc(0x100uLL);
while ( fgets(v5, 256, stdin) )
{
v6 = tokenize(v5);
v7 = append(v4, v6);
v3 = (_QWORD *)v7;
if ( v7 )
{
v8 = (_QWORD *)parse(v7, v10);
if ( v10[0] < 0 )
{
puts("syntax error. Too many close parentheses.");
return 0;
}
if ( v10[0] <= 0 )
{
if ( v8 )
{
if ( *v8 )
{
printValue();
putchar(10);
cleanup(*v4);
}
}
}
else
{
*v4 = *v3;
}
}
else
{
*v4 = 0LL;
}
}
if ( *v4 )
{
puts("syntax error. Too few close parentheses");
destroy(v4);
free(v3);
result = 1;
}
else
{
destroy(v4);
free(v3);
free(v5);
result = -1;
}
return result;
}

original_code:
int main(int argc, char *argv[]) {
  List *tokens, *parseTree, *leftoverTokens = ((void *)0);
  leftoverTokens = initializeList();
  int depth = 0;
  char *expression = (char *)malloc(256 * sizeof(char));
  while (fgets(expression, 256, stdin)) {
     tokens = append(leftoverTokens, tokenize(expression));
     if (!tokens) {
       leftoverTokens->head = ((void *)0);
       continue;
       }
     parseTree = parse(tokens,&depth);
     if (depth < 0) {
       printf("syntax error. Too many close parentheses.\n");
       return SYNTAX_ERROR_TOO_MANY_CLOSE_PARENS;
     } else if (depth > 0) {
       leftoverTokens->head = tokens->head;
      } else {
       if (parseTree && parseTree->head){
  printValue(parseTree->head);
  printf("\n");
  cleanup(leftoverTokens->head);
       }
      }
  }
  if (leftoverTokens->head) {
    printf("syntax error. Too few close parentheses\n");
    destroy(leftoverTokens);
    free(tokens);
    return SYNTAX_ERROR_UNTERMINATED_INPUT;
  }
  destroy(leftoverTokens);
  free(tokens);
  free(expression);
  return -1;
}

canonical_original_code:
int main(int argc, char *argv[]) {
  struct __LinkedList *tokens; struct __LinkedList *parseTree; struct __LinkedList *leftoverTokens = ((void *)0);
  leftoverTokens = initializeList();
  int depth = 0;
  char *expression = (char *)malloc(256 * sizeof(char));
  while (fgets(expression, 256, stdin)) {
     tokens = append(leftoverTokens, tokenize(expression));
     if (!tokens) {
       leftoverTokens->head = ((void *)0);
       continue;
       }
     parseTree = parse(tokens,&depth);
     if (depth < 0) {
       printf("syntax error. Too many close parentheses.\n");
       return SYNTAX_ERROR_TOO_MANY_CLOSE_PARENS;
     } else if (depth > 0) {
       leftoverTokens->head = tokens->head;
      } else {
       if (parseTree && parseTree->head){
  printValue(parseTree->head);
  printf("\n");
  cleanup(leftoverTokens->head);
       }
      }
  }
  if (leftoverTokens->head) {
    printf("syntax error. Too few close parentheses\n");
    destroy(leftoverTokens);
    free(tokens);
    return SYNTAX_ERROR_UNTERMINATED_INPUT;
  }
  destroy(leftoverTokens);
  free(tokens);
  free(expression);
  return -1;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: depth int

variable_types:
expression
char *


repo: alannice/learn

decompiled_code:
void __fastcall xyz_buf_destroy(void *ptr)
{
if ( ptr )
{
free(*((void **)ptr + 5));
free(ptr);
}
}

canonical_decompiled_code:
void __fastcall func1(void *ptr)
{
if ( ptr )
{
free(*((void **)ptr + 5));
free(ptr);
}
}

original_code:
void xyz_buf_destroy(struct xyz_buf_t *buf)
{
    if (buf == ((void *)0)) {
        return;
    }
    free(buf->data);
    free(buf);
    return;
}

variable_types: struct xyz_buf_t { char label[32]; int size; char *data; int len; } *


decompiled_code:
__int64 __fastcall xyz_buf_append(__int64 a1, const void *a2, int a3)
{
int v5; // edi
int v6; // ebx

if ( a3 <= 0 || a2 == 0LL || !a1 )
return 0xFFFFFFFFLL;
v5 = *(_DWORD *)(a1 + 48);
if ( v5 + a3 > *(_DWORD *)(a1 + 32) )
return 0xFFFFFFFFLL;
memcpy((void *)(*(_QWORD *)(a1 + 40) + v5), a2, a3);
v6 = *(_DWORD *)(a1 + 48) + a3;
*(_DWORD *)(a1 + 48) = v6;
*(_BYTE *)(*(_QWORD *)(a1 + 40) + v6) = 0;
return 0LL;
}

original_code:
int xyz_buf_append(struct xyz_buf_t *buf, char *data, int len)
{
    if (buf == ((void *)0) || data == ((void *)0) || len <= 0) {
        return -1;
    }
    if (buf->len + len > buf->size) {
        return -1;
    }
    memcpy(buf->data+buf->len, data, len);
    buf->len+=len;
    *(buf->data+buf->len) = '\0';
    return 0;
}

variable_types:
data
char *

variable_types: len int

user_defined_types: struct xyz_buf_t { char label[32]; int size; char *data; int len; }


original_code:
int xyz_buf_get(struct xyz_buf_t *buf, char *data, int len)
{
    if (buf == ((void *)0) || data == ((void *)0) || len <= 0) {
        return -1;
    }
    int l = buf->len >= len ? len : buf->len;
    memcpy(data, buf->data, l);
    buf->len -= l;
    if (buf->len) {
        memmove(buf->data, buf->data+l, buf->len);
    }
    *(buf->data+buf->len) = '\0';
    return l;
}

variable_types: l int


decompiled_code:
__int64 __fastcall xyz_buf_peek(__int64 a1, void *a2, int a3)
{
int v3; // ebx

if ( a3 <= 0 || a2 == 0LL || !a1 )
{
v3 = -1;
}
else
{
v3 = a3;
if ( *(_DWORD *)(a1 + 48) <= a3 )
v3 = *(_DWORD *)(a1 + 48);
memcpy(a2, *(const void **)(a1 + 40), v3);
}
return (unsigned int)v3;
}

original_code:
int xyz_buf_peek(struct xyz_buf_t *buf, char *data, int len)
{
    if (buf == ((void *)0) || data == ((void *)0) || len <= 0) {
        return -1;
    }
    int l = buf->len >= len ? len : buf->len;
    memcpy(data, buf->data, l);
    return l;
}


original_code:
int xyz_buf_read(struct xyz_buf_t *buf, int fd)
{
    int n;
    if (buf == ((void *)0) || fd < 0) {
        return -1;
    }
    if (buf->len == buf->size) {
        return 0;
    }
    n = read(fd, buf->data+buf->len, buf->size-buf->len);
    if (n < 0) {
        if ((*__errno_location ()) == 4) {
            return 0;
        } else {
            return -1;
        }
    } else if (n == 0) {
        return -1;
    }
    buf->len += n;
    *(buf->data+buf->len) = '\0';
    return n;
}

variable_types: fd int

variable_types: n int


decompiled_code:
__int64 __fastcall xyz_buf_write(__int64 a1, int a2)
{
int v2; // eax
int v3; // ebp
unsigned int v4; // er12
int v5; // eax

if ( !a1 || a2 < 0 )
return (unsigned int)-1;
v2 = write(a2, *(const void **)(a1 + 40), *(int *)(a1 + 48));
v3 = v2;
v4 = v2;
if ( v2 < 0 )
return (unsigned int)-(*_errno_location() != 4);
if ( !v2 )
return (unsigned int)-1;
memmove(*(void **)(a1 + 40), (const void *)(*(_QWORD *)(a1 + 40) + v2), *(_DWORD *)(a1 + 48) - v2);
v5 = *(_DWORD *)(a1 + 48) - v3;
*(_DWORD *)(a1 + 48) = v5;
*(_BYTE *)(*(_QWORD *)(a1 + 40) + v5) = 0;
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, int a2)
{
int v2; // eax
int v3; // ebp
unsigned int v4; // er12
int v5; // eax

if ( !a1 || a2 < 0 )
return (unsigned int)-1;
v2 = write(a2, *(const void **)(a1 + 40), *(int *)(a1 + 48));
v3 = v2;
v4 = v2;
if ( v2 < 0 )
return (unsigned int)-(*_errno_location() != 4);
if ( !v2 )
return (unsigned int)-1;
memmove(*(void **)(a1 + 40), (const void *)(*(_QWORD *)(a1 + 40) + v2), *(_DWORD *)(a1 + 48) - v2);
v5 = *(_DWORD *)(a1 + 48) - v3;
*(_DWORD *)(a1 + 48) = v5;
*(_BYTE *)(*(_QWORD *)(a1 + 40) + v5) = 0;
return v4;
}

original_code:
int xyz_buf_write(struct xyz_buf_t *buf, int fd)
{
    int n;
    if (buf == ((void *)0) || fd < 0) {
        return -1;
    }
    n = write(fd, buf->data, buf->len);
    if (n < 0) {
        if ((*__errno_location ()) == 4) {
            return 0;
        }
        return -1;
    } else if (n == 0) {
        return -1;
    }
    memmove(buf->data, buf->data+n, buf->len-n);
    buf->len -= n;
    *(buf->data+buf->len) = '\0';
    return n;
}


decompiled_code:
__int64 __fastcall xyz_buf_drop(__int64 a1, int a2)
{
__int64 result; // rax
int v3; // eax

if ( !a1 )
return 0xFFFFFFFFLL;
if ( !a2 )
return 0xFFFFFFFFLL;
result = *(unsigned int *)(a1 + 48);
if ( (int)result >= a2 )
{
memmove(*(void **)(a1 + 40), (const void *)(*(_QWORD *)(a1 + 40) + a2), (int)result - a2);
v3 = *(_DWORD *)(a1 + 48) - a2;
*(_DWORD *)(a1 + 48) = v3;
*(_BYTE *)(*(_QWORD *)(a1 + 40) + v3) = 0;
result = (unsigned int)a2;
}
else
{
*(_DWORD *)(a1 + 48) = 0;
**(_BYTE **)(a1 + 40) = 0;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, int a2)
{
__int64 result; // rax
int v3; // eax

if ( !a1 )
return 0xFFFFFFFFLL;
if ( !a2 )
return 0xFFFFFFFFLL;
result = *(unsigned int *)(a1 + 48);
if ( (int)result >= a2 )
{
memmove(*(void **)(a1 + 40), (const void *)(*(_QWORD *)(a1 + 40) + a2), (int)result - a2);
v3 = *(_DWORD *)(a1 + 48) - a2;
*(_DWORD *)(a1 + 48) = v3;
*(_BYTE *)(*(_QWORD *)(a1 + 40) + v3) = 0;
result = (unsigned int)a2;
}
else
{
*(_DWORD *)(a1 + 48) = 0;
**(_BYTE **)(a1 + 40) = 0;
}
return result;
}

original_code:
int xyz_buf_drop(struct xyz_buf_t *buf, int len)
{
    if (buf == ((void *)0) || len == 0) {
        return -1;
    }
    if (len > buf->len) {
        int l = buf->len;
        buf->len = 0;
        *(buf->data) = '\0';
        return l;
    }
    memmove(buf->data, buf->data+len, buf->len-len);
    buf->len -= len;
    *(buf->data+buf->len) = '\0';
    return len;
}


decompiled_code:
__int64 xyz_buf_sprintf(__int64 a1, const char *a2, ...)
{
int v2; // eax
unsigned int v3; // edx
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

if ( !a1 || !a2 )
return (unsigned int)-1;
va_start(arg, a2);
v2 = vsnprintf(
(char *)(*(_QWORD *)(a1 + 40) + *(int *)(a1 + 48)),
*(_DWORD *)(a1 + 32) - *(_DWORD *)(a1 + 48),
a2,
arg);
v3 = 0;
if ( v2 > 0 )
*(_DWORD *)(a1 + 48) += v2;
return v3;
}

canonical_decompiled_code:
__int64 func8(__int64 a1, const char *a2, ...)
{
int v2; // eax
unsigned int v3; // edx
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

if ( !a1 || !a2 )
return (unsigned int)-1;
va_start(arg, a2);
v2 = vsnprintf(
(char *)(*(_QWORD *)(a1 + 40) + *(int *)(a1 + 48)),
*(_DWORD *)(a1 + 32) - *(_DWORD *)(a1 + 48),
a2,
arg);
v3 = 0;
if ( v2 > 0 )
*(_DWORD *)(a1 + 48) += v2;
return v3;
}

original_code:
int xyz_buf_sprintf(struct xyz_buf_t *buf, char *fmt, ...)
{
    va_list vl;
    int rv;
    if (buf == ((void *)0) || fmt == ((void *)0)) {
        return -1;
    }
    __builtin_va_start(vl,fmt);
    rv = vsnprintf(buf->data+buf->len, buf->size-buf->len, fmt, vl);
    __builtin_va_end(vl);
    if (rv > 0) {
        buf->len+=rv;
    }
    return 0;
}

canonical_original_code:
int xyz_buf_sprintf(struct xyz_buf_t *buf, char *fmt, ...)
{
    __builtin_va_list vl;
    int rv;
    if (buf == ((void *)0) || fmt == ((void *)0)) {
        return -1;
    }
    __builtin_va_start(vl,fmt);
    rv = vsnprintf(buf->data+buf->len, buf->size-buf->len, fmt, vl);
    __builtin_va_end(vl);
    if (rv > 0) {
        buf->len+=rv;
    }
    return 0;
}

variable_types:
fmt
char *

variable_types: rv int


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

if ( a1 )
result = *(_QWORD *)(a1 + 40);
else
result = 0LL;
return result;
}

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

if ( a1 )
result = *(_QWORD *)(a1 + 40);
else
result = 0LL;
return result;
}

original_code:
char *xyz_buf_data(struct xyz_buf_t *buf)
{
    if (buf == ((void *)0)) {
        return ((void *)0);
    }
    return buf->data;
}


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

if ( a1 )
result = *(unsigned int *)(a1 + 48);
else
result = 0xFFFFFFFFLL;
return result;
}

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

if ( a1 )
result = *(unsigned int *)(a1 + 48);
else
result = 0xFFFFFFFFLL;
return result;
}

original_code:
int xyz_buf_length(struct xyz_buf_t *buf)
{
    if (buf == ((void *)0)) {
        return -1;
    }
    return buf->len;
}


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

if ( a1 )
result = (unsigned int)(*(_DWORD *)(a1 + 32) - *(_DWORD *)(a1 + 48));
else
result = 0xFFFFFFFFLL;
return result;
}

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

if ( a1 )
result = (unsigned int)(*(_DWORD *)(a1 + 32) - *(_DWORD *)(a1 + 48));
else
result = 0xFFFFFFFFLL;
return result;
}

original_code:
int xyz_buf_space(struct xyz_buf_t *buf)
{
    if (buf == ((void *)0)) {
        return -1;
    }
    return buf->size - buf->len;
}


decompiled_code:
int __fastcall xyz_buf_stat(__int64 a1)
{
int result; // eax

if ( a1 )
{
puts("------ buf stat ------");
printf("*** %s ***\n", (const char *)a1);
printf("size : %d\n", *(unsigned int *)(a1 + 32));
result = printf("len : %d\n", *(unsigned int *)(a1 + 48));
}
return result;
}

canonical_decompiled_code:
int __fastcall func12(__int64 a1)
{
int result; // eax

if ( a1 )
{
puts("------ buf stat ------");
printf("*** %s ***\n", (const char *)a1);
printf("size : %d\n", *(unsigned int *)(a1 + 32));
result = printf("len : %d\n", *(unsigned int *)(a1 + 48));
}
return result;
}

original_code:
void xyz_buf_stat(struct xyz_buf_t *buf)
{
    if (buf == ((void *)0)) {
        return;
    }
    printf("------ buf stat ------\n");
    printf("*** %s ***\n", buf->label);
    printf("size : %d\n", buf->size);
    printf("len : %d\n", buf->len);
    return;
}


decompiled_code:
__int64 __fastcall xyz_conf_trim(_BYTE *a1)
{
unsigned __int64 v1; // rax
unsigned __int8 *v2; // rdx
_BYTE *v3; // rcx
__int64 v4; // rsi
unsigned __int8 *v5; // rax

if ( !a1 )
return 0xFFFFFFFFLL;
v1 = (unsigned __int8)*a1;
if ( !(_BYTE)v1 )
return 0xFFFFFFFFLL;
v2 = a1 + 1;
v3 = a1;
v4 = 0x100002600LL;
do
{
if ( (unsigned __int8)v1 <= 0x20u && _bittest64(&v4, v1) )
{
v5 = v2;
}
else
{
*v3 = v1;
v5 = v2;
++v3;
}
v1 = *v5;
++v2;
}
while ( (_BYTE)v1 );
*v3 = 0;
return (unsigned int)-(*a1 == 0);
}

canonical_decompiled_code:
__int64 __fastcall func0(_BYTE *a1)
{
unsigned __int64 v1; // rax
unsigned __int8 *v2; // rdx
_BYTE *v3; // rcx
__int64 v4; // rsi
unsigned __int8 *v5; // rax

if ( !a1 )
return 0xFFFFFFFFLL;
v1 = (unsigned __int8)*a1;
if ( !(_BYTE)v1 )
return 0xFFFFFFFFLL;
v2 = a1 + 1;
v3 = a1;
v4 = 0x100002600LL;
do
{
if ( (unsigned __int8)v1 <= 0x20u && _bittest64(&v4, v1) )
{
v5 = v2;
}
else
{
*v3 = v1;
v5 = v2;
++v3;
}
v1 = *v5;
++v2;
}
while ( (_BYTE)v1 );
*v3 = 0;
return (unsigned int)-(*a1 == 0);
}

original_code:
static int xyz_conf_trim(char *line)
{
 char *d,*s;
 if(line == ((void *)0) || strlen(line) == 0) {
  return -1;
 }
 d = s = line;
 while(*s) {
  if(*s == ' ' || *s == '\t' || *s == '\r' || *s == '\n') {
   s++;
   continue;
  }
  *d = *s;
  s++;
  d++;
 }
 *(d++) = '\0';
 if(strlen(line) == 0) {
  return -1;
 }
 return 0;
}

canonical_original_code:
static int xyz_conf_trim(char *line)
{
 char *d; char *s;
 if(line == ((void *)0) || strlen(line) == 0) {
  return -1;
 }
 d = s = line;
 while(*s) {
  if(*s == ' ' || *s == '\t' || *s == '\r' || *s == '\n') {
   s++;
   continue;
  }
  *d = *s;
  s++;
  d++;
 }
 *(d++) = '\0';
 if(strlen(line) == 0) {
  return -1;
 }
 return 0;
}

variable_types:
line
char *

variable_types:
d
char *

variable_types:
s
char *


decompiled_code:
char *__fastcall xyz_conf_parse(char *s)
{
char *v1; // rax
char *v2; // rax
char *v3; // rbp

if ( !s )
return 0LL;
if ( !*s )
return 0LL;
v1 = strchr(s, 35);
if ( v1 )
*v1 = 0;
v2 = strchr(s, 61);
v3 = v2;
if ( v2 )
{
*v2 = 0;
if ( strlen(s) <= 2 && strlen(v3 + 1) <= 2 )
v3 = 0LL;
else
++v3;
}
return v3;
}

canonical_decompiled_code:
char *__fastcall func1(char *s)
{
char *v1; // rax
char *v2; // rax
char *v3; // rbp

if ( !s )
return 0LL;
if ( !*s )
return 0LL;
v1 = strchr(s, 35);
if ( v1 )
*v1 = 0;
v2 = strchr(s, 61);
v3 = v2;
if ( v2 )
{
*v2 = 0;
if ( strlen(s) <= 2 && strlen(v3 + 1) <= 2 )
v3 = 0LL;
else
++v3;
}
return v3;
}

original_code:
static char *xyz_conf_parse(char *line)
{
 char *p;
 if(line == ((void *)0) || strlen(line) == 0) {
  return ((void *)0);
 }
 p = strchr(line, '#');
 if(p) {
  *p = '\0';
 }
 p = strchr(line, '=');
 if(p == ((void *)0)) {
  return ((void *)0);
 }
 *p = '\0';
 if(strlen(line) < 3 && strlen(p+1) < 3) {
  return ((void *)0);
 }
 return p+1;
}

variable_types:
p
char *


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

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

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

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

original_code:
void xyz_conf_destroy(struct xyz_conf_t *conf)
{
 struct xyz_conf_t *tmpconf;
    if(conf == ((void *)0)) {
        return;
    }
 while(conf) {
  tmpconf = conf;
  conf = conf->next;
  free(tmpconf->key);
  free(tmpconf->value);
  free(tmpconf);
 }
 return;
}

variable_types: struct xyz_conf_t { char *key; char *value; struct xyz_conf_t *next; } *


decompiled_code:
__int64 __fastcall xyz_conf_string(__int64 a1, const char *a2)
{
__int64 v2; // rbx

if ( !a1 )
return 0LL;
v2 = a1;
if ( !a2 )
return 0LL;
while ( strcmp(*(const char **)v2, a2) )
{
v2 = *(_QWORD *)(v2 + 16);
if ( !v2 )
return 0LL;
}
return *(_QWORD *)(v2 + 8);
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, const char *a2)
{
__int64 v2; // rbx

if ( !a1 )
return 0LL;
v2 = a1;
if ( !a2 )
return 0LL;
while ( strcmp(*(const char **)v2, a2) )
{
v2 = *(_QWORD *)(v2 + 16);
if ( !v2 )
return 0LL;
}
return *(_QWORD *)(v2 + 8);
}

original_code:
const char *xyz_conf_string(struct xyz_conf_t *conf, char *key)
{
    if(conf == ((void *)0) || key == ((void *)0)) {
        return ((void *)0);
    }
 while(conf) {
  if(strcmp(conf->key, key) == 0) {
   return conf->value;
  }
  conf = conf->next;
 }
 return ((void *)0);
}

variable_types:
key
char *

user_defined_types: struct xyz_conf_t { char *key; char *value; struct xyz_conf_t *next; }


decompiled_code:
int __fastcall xyz_conf_stat(__int64 a1)
{
__int64 v1; // rbx
int result; // eax

v1 = a1;
for ( result = puts("------ conf stat ------"); v1; v1 = *(_QWORD *)(v1 + 16) )
result = printf("key: %-16s , value: %-16s\n", *(const char **)v1, *(const char **)(v1 + 8));
return result;
}

canonical_decompiled_code:
int __fastcall func4(__int64 a1)
{
__int64 v1; // rbx
int result; // eax

v1 = a1;
for ( result = puts("------ conf stat ------"); v1; v1 = *(_QWORD *)(v1 + 16) )
result = printf("key: %-16s , value: %-16s\n", *(const char **)v1, *(const char **)(v1 + 8));
return result;
}

original_code:
void xyz_conf_stat(struct xyz_conf_t *conf)
{
 printf("------ conf stat ------\n");
 while(conf) {
  printf("key: %-16s , value: %-16s\n", conf->key, conf->value);
  conf = conf->next;
 }
 return;
}


decompiled_code:
int __fastcall xyz_sock_noblock(int fd)
{
unsigned int v1; // eax

v1 = fcntl(fd, 3);
BYTE1(v1) |= 8u;
return fcntl(fd, 4, v1);
}

canonical_decompiled_code:
int __fastcall func1(int fd)
{
unsigned int v1; // eax

v1 = fcntl(fd, 3);
BYTE1(v1) |= 8u;
return fcntl(fd, 4, v1);
}

original_code:
int xyz_sock_noblock(int sockfd)
{
 int flag;
 flag = fcntl(sockfd,3);
 return fcntl(sockfd, 4, flag|04000);
}

variable_types: sockfd int

variable_types: flag int


decompiled_code:
int __fastcall xyz_sock_closeonexec(int a1)
{
return fcntl(a1, 2, 1LL);
}

canonical_decompiled_code:
int __fastcall func2(int a1)
{
return fcntl(a1, 2, 1LL);
}

original_code:
int xyz_sock_closeonexec(int sockfd)
{
 return fcntl(sockfd, 2, 1);
}


decompiled_code:
__int64 __fastcall xyz_sock_listen(const char *a1, __int16 a2, int a3)
{
struct hostent *v4; // rax
unsigned int v5; // ebx
int optval; // [rsp+Ch] [rbp-2Ch] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-28h] BYREF

*(_QWORD *)&addr.sa_family = 0LL;
*(_QWORD *)&addr.sa_data[6] = 0LL;
if ( a1 )
{
v4 = gethostbyname(a1);
if ( !v4 )
{
perror("gethostbyname() error");
return (unsigned int)-1;
}
*(_DWORD *)&addr.sa_data[2] = **(_DWORD **)v4->h_addr_list;
}
*(_WORD *)addr.sa_data = _bswap_16(a2);
addr.sa_family = 2;
if ( a3 == 2 )
{
v5 = socket(2, 2, 17);
}
else if ( a3 == 3 )
{
v5 = socket(2, 5, 132);
}
else
{
v5 = -1;
if ( a3 != 1 )
return v5;
v5 = socket(2, 1, 6);
}
if ( v5 == -1 )
{
perror("socket() error");
}
else
{
optval = 1;
setsockopt(v5, 1, 2, &optval, 4u);
if ( bind(v5, &addr, 0x10u) == -1 )
{
perror("bind() error");
v5 = -1;
}
else if ( listen(v5, 128) == -1 )
{
perror("listen() error");
v5 = -1;
}
}
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func3(const char *a1, __int16 a2, int a3)
{
struct hostent *v4; // rax
unsigned int v5; // ebx
int optval; // [rsp+Ch] [rbp-2Ch] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-28h] BYREF

*(_QWORD *)&addr.sa_family = 0LL;
*(_QWORD *)&addr.sa_data[6] = 0LL;
if ( a1 )
{
v4 = gethostbyname(a1);
if ( !v4 )
{
perror("gethostbyname() error");
return (unsigned int)-1;
}
*(_DWORD *)&addr.sa_data[2] = **(_DWORD **)v4->h_addr_list;
}
*(_WORD *)addr.sa_data = func0(a2);
addr.sa_family = 2;
if ( a3 == 2 )
{
v5 = socket(2, 2, 17);
}
else if ( a3 == 3 )
{
v5 = socket(2, 5, 132);
}
else
{
v5 = -1;
if ( a3 != 1 )
return v5;
v5 = socket(2, 1, 6);
}
if ( v5 == -1 )
{
perror("socket() error");
}
else
{
optval = 1;
setsockopt(v5, 1, 2, &optval, 4u);
if ( bind(v5, &addr, 0x10u) == -1 )
{
perror("bind() error");
v5 = -1;
}
else if ( listen(v5, 128) == -1 )
{
perror("listen() error");
v5 = -1;
}
}
return v5;
}

original_code:
int xyz_sock_listen(char *addr, int port, int type)
{
 struct sockaddr_in sin;
 int sockfd;
 struct hostent *ht;
 memset (&sin, 0, sizeof (sin));
 if(addr != ((void *)0)) {
  memset (&sin, 0, sizeof (sin));
  ht = gethostbyname(addr);
  if(ht == ((void *)0)) {
   perror ("gethostbyname() error");
   return -1;
  }
  sin.sin_addr.s_addr = *((in_addr_t *)(ht->h_addr_list[0]));
 } else {
  sin.sin_addr.s_addr = ((in_addr_t) 0x00000000);
 }
    sin.sin_port = htons (port);
    sin.sin_family = 2;
    switch(type) {
        case 1:
            sockfd = socket (2, SOCK_STREAM, IPPROTO_TCP);
            break;
        case 2:
            sockfd = socket (2, SOCK_DGRAM, IPPROTO_UDP);
            break;
        case 3:
            sockfd = socket (2, SOCK_SEQPACKET, IPPROTO_SCTP);
            break;
        default:
            return -1;
    }
    if(sockfd == -1) {
  perror ("socket() error");
  return -1;
    }
 int i=1;
 setsockopt(sockfd, 1, 2, &i, sizeof(i));
    if (bind (sockfd, (struct sockaddr *) &sin, sizeof (sin)) == -1)
    {
  perror ("bind() error");
  return -1;
    }
    if (listen (sockfd, 128) == -1)
    {
  perror ("listen() error");
  return -1;
    }
 return sockfd;
}

canonical_original_code:
int xyz_sock_listen(char *addr, int port, int type)
{
 struct sockaddr_in sin;
 int sockfd;
 struct hostent *ht;
 memset (&sin, 0, sizeof (sin));
 if(addr != ((void *)0)) {
  memset (&sin, 0, sizeof (sin));
  ht = gethostbyname(addr);
  if(ht == ((void *)0)) {
   perror ("gethostbyname() error");
   return -1;
  }
  sin.sin_addr.s_addr = *((unsigned int *)(ht->h_addr_list[0]));
 } else {
  sin.sin_addr.s_addr = ((unsigned int) 0x00000000);
 }
    sin.sin_port = htons (port);
    sin.sin_family = 2;
    switch(type) {
        case 1:
            sockfd = socket (2, SOCK_STREAM, IPPROTO_TCP);
            break;
        case 2:
            sockfd = socket (2, SOCK_DGRAM, IPPROTO_UDP);
            break;
        case 3:
            sockfd = socket (2, SOCK_SEQPACKET, IPPROTO_SCTP);
            break;
        default:
            return -1;
    }
    if(sockfd == -1) {
  perror ("socket() error");
  return -1;
    }
 int i = 1;
 setsockopt(sockfd, 1, 2, &i, sizeof(i));
    if (bind (sockfd, (struct sockaddr *) &sin, sizeof (sin)) == -1)
    {
  perror ("bind() error");
  return -1;
    }
    if (listen (sockfd, 128) == -1)
    {
  perror ("listen() error");
  return -1;
    }
 return sockfd;
}

variable_types:
addr
char *

variable_types: port int

variable_types: type 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: struct hostent { char *h_name; char **h_aliases; int h_addrtype; int h_length; char **h_addr_list; } *

variable_types: i 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 xyz_sock_accept(int a1)
{
unsigned int v1; // ebx
socklen_t addr_len; // [rsp+Ch] [rbp-1Ch] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-18h] BYREF

addr_len = 16;
v1 = accept(a1, &addr, &addr_len);
if ( v1 == -1 )
perror("accept() error");
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func4(int a1)
{
unsigned int v1; // ebx
socklen_t addr_len; // [rsp+Ch] [rbp-1Ch] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-18h] BYREF

addr_len = 16;
v1 = accept(a1, &addr, &addr_len);
if ( v1 == -1 )
perror("accept() error");
return v1;
}

original_code:
int xyz_sock_accept(int sockfd)
{
 struct sockaddr sa;
 socklen_t len;
 int conn;
 len = sizeof(sa);
 conn = accept(sockfd, &sa, &len);
 if(conn == -1) {
  perror("accept() error");
 }
 return conn;
}

canonical_original_code:
int xyz_sock_accept(int sockfd)
{
 struct sockaddr sa;
 unsigned int len;
 int conn;
 len = sizeof(sa);
 conn = accept(sockfd, &sa, &len);
 if(conn == -1) {
  perror("accept() error");
 }
 return conn;
}

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

variable_types:
len
unsigned int

variable_types: conn int


decompiled_code:
__int64 __fastcall xyz_sock_connect(char *name, __int16 a2, int a3)
{
unsigned int v3; // ebx
struct hostent *v4; // rax
struct sockaddr v6; // [rsp+0h] [rbp-28h] BYREF

if ( !name )
return (unsigned int)-1;
if ( a3 == 2 )
{
v3 = socket(2, 2, 17);
}
else if ( a3 == 3 )
{
v3 = socket(2, 5, 132);
}
else
{
v3 = -1;
if ( a3 != 1 )
return v3;
v3 = socket(2, 1, 6);
}
if ( v3 == -1 )
{
perror("socket() error");
}
else
{
v4 = gethostbyname(name);
if ( v4 )
{
*(_QWORD *)&v6.sa_family = 0LL;
*(_QWORD *)&v6.sa_data[6] = 0LL;
*(_QWORD *)&v6.sa_data[2] = **(unsigned int **)v4->h_addr_list;
*(_WORD *)v6.sa_data = _bswap_16(a2);
v6.sa_family = 2;
if ( connect(v3, &v6, 0x10u) == -1 )
{
perror("connect() error");
v3 = -1;
}
}
else
{
perror("gethostbyname() error");
v3 = -1;
}
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func5(char *name, __int16 a2, int a3)
{
unsigned int v3; // ebx
struct hostent *v4; // rax
struct sockaddr v6; // [rsp+0h] [rbp-28h] BYREF

if ( !name )
return (unsigned int)-1;
if ( a3 == 2 )
{
v3 = socket(2, 2, 17);
}
else if ( a3 == 3 )
{
v3 = socket(2, 5, 132);
}
else
{
v3 = -1;
if ( a3 != 1 )
return v3;
v3 = socket(2, 1, 6);
}
if ( v3 == -1 )
{
perror("socket() error");
}
else
{
v4 = gethostbyname(name);
if ( v4 )
{
*(_QWORD *)&v6.sa_family = 0LL;
*(_QWORD *)&v6.sa_data[6] = 0LL;
*(_QWORD *)&v6.sa_data[2] = **(unsigned int **)v4->h_addr_list;
*(_WORD *)v6.sa_data = func0(a2);
v6.sa_family = 2;
if ( connect(v3, &v6, 0x10u) == -1 )
{
perror("connect() error");
v3 = -1;
}
}
else
{
perror("gethostbyname() error");
v3 = -1;
}
}
return v3;
}

original_code:
int xyz_sock_connect(char *addr, int port, int type)
{
 struct sockaddr_in sin;
 int sockfd;
 struct hostent *ht;
 if(addr == ((void *)0)) {
  return -1;
 }
    switch(type) {
        case 1:
            sockfd = socket (2, SOCK_STREAM, IPPROTO_TCP);
            break;
        case 2:
            sockfd = socket (2, SOCK_DGRAM, IPPROTO_UDP);
            break;
        case 3:
            sockfd = socket (2, SOCK_SEQPACKET, IPPROTO_SCTP);
            break;
        default:
            return -1;
    }
    if(sockfd == -1) {
  perror ("socket() error");
  return -1;
    }
 ht = gethostbyname(addr);
 if(ht == ((void *)0)) {
  perror ("gethostbyname() error");
  return -1;
 }
 memset (&sin, 0, sizeof (sin));
 sin.sin_addr.s_addr = *((in_addr_t *)(ht->h_addr_list[0]));
    sin.sin_port = htons(port);
    sin.sin_family = 2;
 if(connect(sockfd, (struct sockaddr *)&sin, sizeof(struct sockaddr)) == -1) {
  perror ("connect() error");
  return -1;
 }
 return sockfd;
}

canonical_original_code:
int xyz_sock_connect(char *addr, int port, int type)
{
 struct sockaddr_in sin;
 int sockfd;
 struct hostent *ht;
 if(addr == ((void *)0)) {
  return -1;
 }
    switch(type) {
        case 1:
            sockfd = socket (2, SOCK_STREAM, IPPROTO_TCP);
            break;
        case 2:
            sockfd = socket (2, SOCK_DGRAM, IPPROTO_UDP);
            break;
        case 3:
            sockfd = socket (2, SOCK_SEQPACKET, IPPROTO_SCTP);
            break;
        default:
            return -1;
    }
    if(sockfd == -1) {
  perror ("socket() error");
  return -1;
    }
 ht = gethostbyname(addr);
 if(ht == ((void *)0)) {
  perror ("gethostbyname() error");
  return -1;
 }
 memset (&sin, 0, sizeof (sin));
 sin.sin_addr.s_addr = *((unsigned int *)(ht->h_addr_list[0]));
    sin.sin_port = htons(port);
    sin.sin_family = 2;
 if(connect(sockfd, (struct sockaddr *)&sin, sizeof(struct sockaddr)) == -1) {
  perror ("connect() error");
  return -1;
 }
 return sockfd;
}

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


decompiled_code:
__int64 __fastcall xyz_sock_peeraddr(int a1, char *a2, int a3)
{
char *v5; // rsi
socklen_t len; // [rsp+0h] [rbp-2Ch] BYREF
struct sockaddr addr; // [rsp+4h] [rbp-28h] BYREF

if ( !a2 )
return 0xFFFFFFFFLL;
if ( a3 <= 14 )
return 0xFFFFFFFFLL;
len = 16;
*(_QWORD *)&addr.sa_family = 0LL;
*(_QWORD *)&addr.sa_data[6] = 0LL;
if ( getpeername(a1, &addr, &len) < 0 )
return 0xFFFFFFFFLL;
v5 = inet_ntoa(*(struct in_addr *)&addr.sa_data[2]);
if ( !v5 )
return 0xFFFFFFFFLL;
strncpy(a2, v5, a3);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func6(int a1, char *a2, int a3)
{
char *v5; // rsi
socklen_t len; // [rsp+0h] [rbp-2Ch] BYREF
struct sockaddr addr; // [rsp+4h] [rbp-28h] BYREF

if ( !a2 )
return 0xFFFFFFFFLL;
if ( a3 <= 14 )
return 0xFFFFFFFFLL;
len = 16;
*(_QWORD *)&addr.sa_family = 0LL;
*(_QWORD *)&addr.sa_data[6] = 0LL;
if ( getpeername(a1, &addr, &len) < 0 )
return 0xFFFFFFFFLL;
v5 = inet_ntoa(*(struct in_addr *)&addr.sa_data[2]);
if ( !v5 )
return 0xFFFFFFFFLL;
strncpy(a2, v5, a3);
return 0LL;
}

original_code:
int xyz_sock_peeraddr(int sockfd, char *addr, int len)
{
    struct sockaddr_in sa_in;
    socklen_t sa_len;
    char *paddr;
    int pport;
    if(addr == ((void *)0) || len < 15) {
        return -1;
    }
    sa_len = sizeof(struct sockaddr);
    bzero(&sa_in, sizeof(struct sockaddr_in));
    if(getpeername(sockfd, (struct sockaddr *)&sa_in, &sa_len ) < 0)
    {
        return -1;
    }
    paddr = inet_ntoa(sa_in.sin_addr);
    pport = ntohs(sa_in.sin_port);
    if(paddr == ((void *)0)) {
        return -1;
    }
    strncpy(addr, paddr, len);
    return 0;
}

canonical_original_code:
int xyz_sock_peeraddr(int sockfd, char *addr, int len)
{
    struct sockaddr_in sa_in;
    unsigned int sa_len;
    char *paddr;
    int pport;
    if(addr == ((void *)0) || len < 15) {
        return -1;
    }
    sa_len = sizeof(struct sockaddr);
    bzero(&sa_in, sizeof(struct sockaddr_in));
    if(getpeername(sockfd, (struct sockaddr *)&sa_in, &sa_len ) < 0)
    {
        return -1;
    }
    paddr = inet_ntoa(sa_in.sin_addr);
    pport = ntohs(sa_in.sin_port);
    if(paddr == ((void *)0)) {
        return -1;
    }
    strncpy(addr, paddr, len);
    return 0;
}

variable_types: len int

variable_types:
paddr
char *

variable_types: pport int


decompiled_code:
int __fastcall xyz_sock_read_to(int fd, void *buf, int a3, int a4)
{
int result; // eax
struct timeval v6; // [rsp+0h] [rbp-A8h] BYREF
fd_set readfds; // [rsp+10h] [rbp-98h] BYREF

memset(&readfds, 0, sizeof(readfds));
readfds.fds_bits[fd / 64] |= 1LL << (fd % 64);
v6.tv_sec = a4 / 1000000;
v6.tv_usec = a4 % 1000000;
if ( fd > 1023 )
return read(fd, buf, a3);
result = select(fd + 1, &readfds, 0LL, 0LL, &v6);
if ( result )
{
if ( result == 1 )
{
result = read(fd, buf, a3);
}
else if ( result == -1 )
{
result = -(*_errno_location() != 4);
}
else
{
result = 0;
}
}
return result;
}

canonical_decompiled_code:
int __fastcall func7(int fd, void *buf, int a3, int a4)
{
int result; // eax
struct timeval v6; // [rsp+0h] [rbp-A8h] BYREF
fd_set readfds; // [rsp+10h] [rbp-98h] BYREF

memset(&readfds, 0, sizeof(readfds));
readfds.fds_bits[fd / 64] |= 1LL << (fd % 64);
v6.tv_sec = a4 / 1000000;
v6.tv_usec = a4 % 1000000;
if ( fd > 1023 )
return read(fd, buf, a3);
result = select(fd + 1, &readfds, 0LL, 0LL, &v6);
if ( result )
{
if ( result == 1 )
{
result = read(fd, buf, a3);
}
else if ( result == -1 )
{
result = -(*_errno_location() != 4);
}
else
{
result = 0;
}
}
return result;
}

original_code:
int xyz_sock_read_to(int sockfd, char *data, int len, int usec)
{
    fd_set rdset;
    do { int __d0, __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&rdset)->__fds_bits)[0]) : "memory"); } while (0);
    ((void) (((&rdset)->__fds_bits)[((sockfd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((sockfd) % (8 * (int) sizeof (__fd_mask)))))));
    struct timeval tv;
    tv.tv_sec = usec/1000000;
    tv.tv_usec = usec%1000000;
    if(sockfd >= 1024) {
        return read(sockfd, data, len);
    }
    int n = select(sockfd+1, &rdset, ((void *)0), ((void *)0), &tv);
    if(n == 0) {
        return 0;
    }
    if(n == 1) {
        return read(sockfd, data, len);
    }
    if(n == -1) {
        if((*__errno_location ()) == 4) {
            return 0;
        } else {
            return -1;
        }
    }
    return 0;
}

canonical_original_code:
int xyz_sock_read_to(int sockfd, char *data, int len, int usec)
{
    struct fd_set rdset;
    do { int __d0; int __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&rdset)->__fds_bits)[0]) : "memory"); } while (0);
    ((void) (((&rdset)->__fds_bits)[((sockfd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((sockfd) % (8 * (int) sizeof (__fd_mask)))))));
    struct timeval tv;
    tv.tv_sec = usec/1000000;
    tv.tv_usec = usec%1000000;
    if(sockfd >= 1024) {
        return read(sockfd, data, len);
    }
    int n = select(sockfd+1, &rdset, ((void *)0), ((void *)0), &tv);
    if(n == 0) {
        return 0;
    }
    if(n == 1) {
        return read(sockfd, data, len);
    }
    if(n == -1) {
        if((*__errno_location ()) == 4) {
            return 0;
        } else {
            return -1;
        }
    }
    return 0;
}

variable_types:
data
char *

variable_types: usec int

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

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

variable_types: n int


decompiled_code:
int __fastcall xyz_sock_write_to(int fd, void *buf, int a3, int a4)
{
int result; // eax
struct timeval v6; // [rsp+0h] [rbp-A8h] BYREF
fd_set writefds; // [rsp+10h] [rbp-98h] BYREF

memset(&writefds, 0, sizeof(writefds));
writefds.fds_bits[fd / 64] |= 1LL << (fd % 64);
v6.tv_sec = a4 / 1000000;
v6.tv_usec = a4 % 1000000;
if ( fd > 1023 )
return write(fd, buf, a3);
result = select(fd + 1, 0LL, &writefds, 0LL, &v6);
if ( result )
{
if ( result == 1 )
{
result = write(fd, buf, a3);
}
else if ( result == -1 )
{
result = -(*_errno_location() != 4);
}
else
{
result = 0;
}
}
return result;
}

canonical_decompiled_code:
int __fastcall func8(int fd, void *buf, int a3, int a4)
{
int result; // eax
struct timeval v6; // [rsp+0h] [rbp-A8h] BYREF
fd_set writefds; // [rsp+10h] [rbp-98h] BYREF

memset(&writefds, 0, sizeof(writefds));
writefds.fds_bits[fd / 64] |= 1LL << (fd % 64);
v6.tv_sec = a4 / 1000000;
v6.tv_usec = a4 % 1000000;
if ( fd > 1023 )
return write(fd, buf, a3);
result = select(fd + 1, 0LL, &writefds, 0LL, &v6);
if ( result )
{
if ( result == 1 )
{
result = write(fd, buf, a3);
}
else if ( result == -1 )
{
result = -(*_errno_location() != 4);
}
else
{
result = 0;
}
}
return result;
}

original_code:
int xyz_sock_write_to(int sockfd, char *data, int len, int usec)
{
    fd_set wtset;
    do { int __d0, __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&wtset)->__fds_bits)[0]) : "memory"); } while (0);
    ((void) (((&wtset)->__fds_bits)[((sockfd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((sockfd) % (8 * (int) sizeof (__fd_mask)))))));
    struct timeval tv;
    tv.tv_sec = usec/1000000;
    tv.tv_usec = usec%1000000;
    if(sockfd >= 1024) {
        return write(sockfd, data, len);
    }
    int n = select(sockfd+1, ((void *)0), &wtset, ((void *)0), &tv);
    if(n == 0) {
        return 0;
    }
    if(n == 1) {
        return write(sockfd, data, len);
    }
    if(n == -1) {
        if((*__errno_location ()) == 4) {
            return 0;
        } else {
            return -1;
        }
    }
    return 0;
}

canonical_original_code:
int xyz_sock_write_to(int sockfd, char *data, int len, int usec)
{
    struct fd_set wtset;
    do { int __d0; int __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&wtset)->__fds_bits)[0]) : "memory"); } while (0);
    ((void) (((&wtset)->__fds_bits)[((sockfd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((sockfd) % (8 * (int) sizeof (__fd_mask)))))));
    struct timeval tv;
    tv.tv_sec = usec/1000000;
    tv.tv_usec = usec%1000000;
    if(sockfd >= 1024) {
        return write(sockfd, data, len);
    }
    int n = select(sockfd+1, ((void *)0), &wtset, ((void *)0), &tv);
    if(n == 0) {
        return 0;
    }
    if(n == 1) {
        return write(sockfd, data, len);
    }
    if(n == -1) {
        if((*__errno_location ()) == 4) {
            return 0;
        } else {
            return -1;
        }
    }
    return 0;
}

variable_types: sockfd int

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


decompiled_code:
__int64 __fastcall xyz_domain_listen(char *name)
{
int v1; // eax
unsigned int v2; // ebx
struct sockaddr v4[8]; // [rsp+0h] [rbp-88h] BYREF

v1 = socket(1, 1, 6);
if ( v1 < 0 )
{
perror("socket() error");
v2 = -1;
}
else
{
v2 = v1;
strncpy(v4[0].sa_data, name, 0x6BuLL);
if ( bind(v2, v4, 0x6Eu) == -1 )
{
perror("bind() error");
close(v2);
unlink(name);
v2 = -1;
}
else if ( listen(v2, 1) == -1 )
{
perror("listen() error");
close(v2);
unlink(name);
v2 = -1;
}
else
{
unlink(name);
}
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func9(char *name)
{
int v1; // eax
unsigned int v2; // ebx
struct sockaddr v4[8]; // [rsp+0h] [rbp-88h] BYREF

v1 = socket(1, 1, 6);
if ( v1 < 0 )
{
perror("socket() error");
v2 = -1;
}
else
{
v2 = v1;
strncpy(v4[0].sa_data, name, 0x6BuLL);
if ( bind(v2, v4, 0x6Eu) == -1 )
{
perror("bind() error");
close(v2);
unlink(name);
v2 = -1;
}
else if ( listen(v2, 1) == -1 )
{
perror("listen() error");
close(v2);
unlink(name);
v2 = -1;
}
else
{
unlink(name);
}
}
return v2;
}

original_code:
int xyz_domain_listen(char *addr)
{
    int listen_fd;
    int ret;
    struct sockaddr_un srv_addr;
    listen_fd=socket(1, SOCK_STREAM, IPPROTO_TCP);
    if(listen_fd < 0) {
        perror("socket() error");
        return -1;
    }
    strncpy(srv_addr.sun_path, addr, sizeof(srv_addr.sun_path)-1);
    ret=bind(listen_fd, (struct sockaddr*)&srv_addr, sizeof(srv_addr));
    if(ret == -1)
    {
        perror("bind() error");
        close(listen_fd);
        unlink(addr);
        return -1;
    }
    ret=listen(listen_fd,1);
    if(ret == -1) {
        perror("listen() error");
        close(listen_fd);
        unlink(addr);
        return -1;
    }
    unlink(addr);
    return listen_fd;
}

canonical_original_code:
int xyz_domain_listen(char *addr)
{
    int listen_fd;
    int ret;
    struct sockaddr_un srv_addr;
    listen_fd=socket(1, SOCK_STREAM, IPPROTO_TCP);
    if(listen_fd < 0) {
        perror("socket() error");
        return -1;
    }
    strncpy(srv_addr.sun_path, addr, sizeof(srv_addr.sun_path)-1);
    ret=bind(listen_fd, (struct sockaddr *)&srv_addr, sizeof(srv_addr));
    if(ret == -1)
    {
        perror("bind() error");
        close(listen_fd);
        unlink(addr);
        return -1;
    }
    ret=listen(listen_fd,1);
    if(ret == -1) {
        perror("listen() error");
        close(listen_fd);
        unlink(addr);
        return -1;
    }
    unlink(addr);
    return listen_fd;
}

variable_types:
addr
char *

variable_types: ret int

variable_types: struct sockaddr_un { unsigned short sun_family; char sun_path[108]; }


decompiled_code:
__int64 __fastcall xyz_domain_connect(char *src)
{
int v1; // eax
unsigned int v2; // ebx
struct sockaddr v4[8]; // [rsp+0h] [rbp-88h] BYREF

v1 = socket(1, 1, 6);
if ( v1 < 0 )
{
perror("socket() error");
v2 = -1;
}
else
{
v2 = v1;
v4[0].sa_family = 1;
strncpy(v4[0].sa_data, src, 0x6BuLL);
if ( connect(v2, v4, 0x6Eu) == -1 )
{
printf("connect() error");
close(v2);
v2 = -1;
}
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func10(char *src)
{
int v1; // eax
unsigned int v2; // ebx
struct sockaddr v4[8]; // [rsp+0h] [rbp-88h] BYREF

v1 = socket(1, 1, 6);
if ( v1 < 0 )
{
perror("socket() error");
v2 = -1;
}
else
{
v2 = v1;
v4[0].sa_family = 1;
strncpy(v4[0].sa_data, src, 0x6BuLL);
if ( connect(v2, v4, 0x6Eu) == -1 )
{
printf("connect() error");
close(v2);
v2 = -1;
}
}
return v2;
}

original_code:
int xyz_domain_connect(char *addr)
{
    int connect_fd;
    struct sockaddr_un srv_addr;
    int ret;
    connect_fd = socket(1, SOCK_STREAM, IPPROTO_TCP);
    if(connect_fd < 0)
    {
        perror("socket() error");
        return -1;
    }
    srv_addr.sun_family=1;
    strncpy(srv_addr.sun_path, addr, sizeof(srv_addr.sun_path)-1);
    ret=connect(connect_fd, (struct sockaddr*)&srv_addr, sizeof(srv_addr));
    if(ret == -1)
    {
        printf("connect() error");
        close(connect_fd);
        return -1;
    }
    return connect_fd;
}

canonical_original_code:
int xyz_domain_connect(char *addr)
{
    int connect_fd;
    struct sockaddr_un srv_addr;
    int ret;
    connect_fd = socket(1, SOCK_STREAM, IPPROTO_TCP);
    if(connect_fd < 0)
    {
        perror("socket() error");
        return -1;
    }
    srv_addr.sun_family=1;
    strncpy(srv_addr.sun_path, addr, sizeof(srv_addr.sun_path)-1);
    ret=connect(connect_fd, (struct sockaddr *)&srv_addr, sizeof(srv_addr));
    if(ret == -1)
    {
        printf("connect() error");
        close(connect_fd);
        return -1;
    }
    return connect_fd;
}

user_defined_types: struct sockaddr_un { unsigned short sun_family; char sun_path[108]; }


decompiled_code:
__int64 __fastcall xyz_sock_sendfile(int out_fd, char *file)
{
unsigned int v2; // ebx
int v3; // eax
__off_t v4; // rbp
struct stat v6; // [rsp+0h] [rbp-A8h] BYREF

v2 = stat(file, &v6);
if ( v2 != -1 )
{
v3 = open(file, 0);
v2 = v3;
if ( v3 != -1 )
{
v4 = v6.st_size;
if ( v4 == sendfile(out_fd, v3, 0LL, v6.st_size) )
{
close(v2);
v2 = 0;
}
else
{
close(v2);
v2 = -1;
}
}
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func11(int out_fd, char *file)
{
unsigned int v2; // ebx
int v3; // eax
__off_t v4; // rbp
struct stat v6; // [rsp+0h] [rbp-A8h] BYREF

v2 = stat(file, &v6);
if ( v2 != -1 )
{
v3 = open(file, 0);
v2 = v3;
if ( v3 != -1 )
{
v4 = v6.st_size;
if ( v4 == sendfile(out_fd, v3, 0LL, v6.st_size) )
{
close(v2);
v2 = 0;
}
else
{
close(v2);
v2 = -1;
}
}
}
return v2;
}

original_code:
int xyz_sock_sendfile(int sockfd, char *file)
{
    int fd;
    struct stat statbuf;
    if(stat(file, &statbuf) == -1) {
        return -1;
    }
    fd = open(file, 00);
    if(fd == -1) {
        return -1;
    }
    if(statbuf.st_size != sendfile(sockfd, fd, 0, statbuf.st_size)) {
        close(fd);
        return -1;
    }
    close(fd);
    return 0;
}

variable_types:
file
char *

variable_types: fd 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:
__int64 __fastcall xyz_plugin_init(const char *a1, const char *a2)
{
char *v2; // rax
__int64 v3; // rbx

v2 = (char *)malloc(0xB0uLL);
v3 = (__int64)v2;
if ( v2 )
{
if ( a1 )
snprintf(v2, 0x1FuLL, "%s", a1);
else
strcpy(v2, "None");
if ( a2 )
snprintf((char *)(v3 + 36), 0x7FuLL, "%s", a2);
else
strcpy((char *)(v3 + 36), "./plugin");
*(_QWORD *)(v3 + 168) = 0LL;
xyz_plugin_scan(v3);
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func2(const char *a1, const char *a2)
{
char *v2; // rax
__int64 v3; // rbx

v2 = (char *)malloc(0xB0uLL);
v3 = (__int64)v2;
if ( v2 )
{
if ( a1 )
snprintf(v2, 0x1FuLL, "%s", a1);
else
strcpy(v2, "None");
if ( a2 )
snprintf((char *)(v3 + 36), 0x7FuLL, "%s", a2);
else
strcpy((char *)(v3 + 36), "./plugin");
*(_QWORD *)(v3 + 168) = 0LL;
func1(v3);
}
return v3;
}

original_code:
struct xyz_plugin_t *xyz_plugin_init(char *label, char *path)
{
    struct xyz_plugin_t *plugin;
    plugin = malloc(sizeof(struct xyz_plugin_t));
    if(plugin == ((void *)0)) {
        return ((void *)0);
    }
    if(label) {
        snprintf(plugin->label, sizeof(plugin->label)-1, "%s", label);
    } else {
        snprintf(plugin->label, sizeof(plugin->label)-1, "%s", "None");
    }
    if(path) {
        snprintf(plugin->path, sizeof(plugin->path)-1, "%s", path);
    } else {
        snprintf(plugin->path, sizeof(plugin->path)-1, "%s", "./plugin");
    }
    plugin->list = ((void *)0);
    xyz_plugin_scan(plugin);
    return plugin;
}

variable_types:
label
char *

variable_types:
path
char *

variable_types: struct xyz_plugin_t { char label[32]; int state; char path[128]; struct xyz_plugin_node_t { char name[32]; int state; void *handle; int (*plugin_init)(); int (*plugin_proc)(void *data, void *args); int (*plugin_destroy)(); struct xyz_plugin_node_t *next; } *list; } *

user_defined_types: struct xyz_plugin_t { char label[32]; int state; char path[128]; struct xyz_plugin_node_t *list; }


decompiled_code:
__int64 __fastcall xyz_plugin_proc(__int64 a1, __int64 a2, __int64 a3)
{
__int64 v4; // r12
int v5; // eax

if ( !a1 )
return 0LL;
v4 = *(_QWORD *)(a1 + 168);
if ( !v4 )
return 0LL;
while ( 1 )
{
v5 = (*(__int64 (__fastcall **)(__int64, __int64))(v4 + 56))(a2, a3);
if ( v5 >= -4 )
{
if ( v5 == -3 )
return 0LL;
goto LABEL_6;
}
if ( v5 >= -6 )
return 0xFFFFFFFFLL;
if ( v5 == -7 )
return 0LL;
LABEL_6:
v4 = *(_QWORD *)(v4 + 72);
if ( !v4 )
return 0LL;
}
}

original_code:
int xyz_plugin_proc(struct xyz_plugin_t *plugin, void *data, void *args)
{
    int retval = 0;
    if(plugin == ((void *)0)) {
        return 0;
    }
    struct xyz_plugin_node_t *tmp = plugin->list;
    while(tmp) {
        retval = tmp->plugin_proc(data, args);
        switch(retval) {
            case (-5):
            case (-6):
                return -1;
            case (-3):
            case (-7):
                return 0;
            default:
                break;
        }
        tmp = tmp->next;
    }
    return 0;
}

variable_types:
data
void *

variable_types:
args
void *

variable_types: retval int

variable_types: struct xyz_plugin_node_t { char name[32]; int state; void *handle; int (*plugin_init)(); int (*plugin_proc)(void *data, void *args); int (*plugin_destroy)(); struct xyz_plugin_node_t *next; } *