recursive

decompiled_code:
__int64 __fastcall recursive(__int64 a1, char *a2, __int64 a3, unsigned int a4)
{
__int64 result; // rax
__int64 v9; // rax
char v10; // al
char **v11; // rax
char *v12; // r13

while ( 2 )
{
switch ( *(_DWORD *)a1 )
{
case 1:
v10 = *a2;
if ( *a2 != *(_DWORD *)(a1 + 4) )
return 0LL;
goto LABEL_6;
case 2:
return 1LL;
case 3:
a1 = *(_QWORD *)(a1 + 16);
continue;
case 4:
if ( (unsigned int)recursive(*(_QWORD *)(a1 + 16), a2, a3, a4) )
return 1LL;
a1 = *(_QWORD *)(a1 + 24);
continue;
case 5:
v10 = *a2;
LABEL_6:
if ( !v10 )
return 0LL;
++a2;
a1 += 40LL;
continue;
case 6:
v9 = *(int *)(a1 + 8);
if ( (int)v9 >= (int)a4 )
{
a1 += 40LL;
continue;
}
v11 = (char **)(a3 + 8 * v9);
v12 = *v11;
*v11 = a2;
result = recursive(a1 + 40, a2, a3, a4);
if ( (_DWORD)result )
return 1LL;
*(_QWORD *)(a3 + 8LL * *(int *)(a1 + 8)) = v12;
return result;
default:
fatal("recursive");
return 0xFFFFFFFFLL;
}
}
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, char *a2, __int64 a3, unsigned int a4)
{
__int64 result; // rax
__int64 v9; // rax
char v10; // al
char **v11; // rax
char *v12; // r13

while ( 2 )
{
switch ( *(_DWORD *)a1 )
{
case 1:
v10 = *a2;
if ( *a2 != *(_DWORD *)(a1 + 4) )
return 0LL;
goto LABEL_6;
case 2:
return 1LL;
case 3:
a1 = *(_QWORD *)(a1 + 16);
continue;
case 4:
if ( (unsigned int)func0(*(_QWORD *)(a1 + 16), a2, a3, a4) )
return 1LL;
a1 = *(_QWORD *)(a1 + 24);
continue;
case 5:
v10 = *a2;
LABEL_6:
if ( !v10 )
return 0LL;
++a2;
a1 += 40LL;
continue;
case 6:
v9 = *(int *)(a1 + 8);
if ( (int)v9 >= (int)a4 )
{
a1 += 40LL;
continue;
}
v11 = (char **)(a3 + 8 * v9);
v12 = *v11;
*v11 = a2;
result = func0(a1 + 40, a2, a3, a4);
if ( (_DWORD)result )
return 1LL;
*(_QWORD *)(a3 + 8LL * *(int *)(a1 + 8)) = v12;
return result;
default:
fatal("recursive");
return 0xFFFFFFFFLL;
}
}
}

original_code:
int
recursive(Inst *pc, char *sp, char **subp, int nsubp)
{
 char *old;
 switch(pc->opcode) {
 case Char:
  if(*sp != pc->c)
   return 0;
 case Any:
  if(*sp == '\0')
   return 0;
  return recursive(pc+1, sp+1, subp, nsubp);
 case Match:
  return 1;
 case Jmp:
  return recursive(pc->x, sp, subp, nsubp);
 case Split:
  if(recursive(pc->x, sp, subp, nsubp))
   return 1;
  return recursive(pc->y, sp, subp, nsubp);
 case Save:
  if(pc->n >= nsubp)
   return recursive(pc+1, sp, subp, nsubp);
  old = subp[pc->n];
  subp[pc->n] = sp;
  if(recursive(pc+1, sp, subp, nsubp))
   return 1;
  subp[pc->n] = old;
  return 0;
 }
 fatal("recursive");
 return -1;
}

canonical_original_code:
int recursive(struct Inst *pc, char *sp, char **subp, int nsubp)
{
 char *old;
 switch(pc->opcode) {
 case Char:
  if(*sp != pc->c)
   return 0;
 case Any:
  if(*sp == '\0')
   return 0;
  return recursive(pc+1, sp+1, subp, nsubp);
 case Match:
  return 1;
 case Jmp:
  return recursive(pc->x, sp, subp, nsubp);
 case Split:
  if(recursive(pc->x, sp, subp, nsubp))
   return 1;
  return recursive(pc->y, sp, subp, nsubp);
 case Save:
  if(pc->n >= nsubp)
   return recursive(pc+1, sp, subp, nsubp);
  old = subp[pc->n];
  subp[pc->n] = sp;
  if(recursive(pc+1, sp, subp, nsubp))
   return 1;
  subp[pc->n] = old;
  return 0;
 }
 fatal("recursive");
 return -1;
}

variable_types: struct Inst { int opcode; int c; int n; struct Inst *x; struct Inst *y; int gen; } *

variable_types:
sp
char *

variable_types:
subp
char **

variable_types: nsubp int

variable_types:
old
char *


recursiveprog

decompiled_code:
__int64 __fastcall recursiveprog(__int64 *a1, char *a2, __int64 a3, unsigned int a4)
{
return recursive(*a1, a2, a3, a4);
}

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

original_code:
int
recursiveprog(Prog *prog, char *input, char **subp, int nsubp)
{
 return recursive(prog->start, input, subp, nsubp);
}

canonical_original_code:
int recursiveprog(struct Prog *prog, char *input, char **subp, int nsubp)
{
 return recursive(prog->start, input, subp, nsubp);
}

variable_types: struct Prog { struct Inst { int opcode; int c; int n; struct Inst *x; struct Inst *y; int gen; } *start; int len; } *

variable_types:
input
char *

return_type: int

user_defined_types: struct Prog { struct Inst *start; int len; }


recursiveloop

decompiled_code:
__int64 __fastcall recursiveloop(__int64 a1, char *a2, __int64 a3, unsigned int a4)
{
__int64 result; // rax
__int64 v9; // rax
char **v10; // rax
char *v11; // r13

while ( 2 )
{
switch ( *(_DWORD *)a1 )
{
case 1:
if ( *a2 == *(_DWORD *)(a1 + 4) )
goto LABEL_4;
return 0LL;
case 2:
return 1LL;
case 3:
a1 = *(_QWORD *)(a1 + 16);
continue;
case 4:
if ( (unsigned int)recursiveloop(*(_QWORD *)(a1 + 16), a2, a3, a4) )
return 1LL;
a1 = *(_QWORD *)(a1 + 24);
continue;
case 5:
LABEL_4:
a1 += 40LL;
++a2;
continue;
case 6:
v9 = *(int *)(a1 + 8);
if ( (int)v9 >= (int)a4 )
{
a1 += 40LL;
continue;
}
v10 = (char **)(a3 + 8 * v9);
v11 = *v10;
*v10 = a2;
result = recursiveloop(a1 + 40, a2, a3, a4);
if ( (_DWORD)result )
return 1LL;
*(_QWORD *)(a3 + 8LL * *(int *)(a1 + 8)) = v11;
return result;
default:
fatal("recursiveloop");
continue;
}
}
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, char *a2, __int64 a3, unsigned int a4)
{
__int64 result; // rax
__int64 v9; // rax
char **v10; // rax
char *v11; // r13

while ( 2 )
{
switch ( *(_DWORD *)a1 )
{
case 1:
if ( *a2 == *(_DWORD *)(a1 + 4) )
goto LABEL_4;
return 0LL;
case 2:
return 1LL;
case 3:
a1 = *(_QWORD *)(a1 + 16);
continue;
case 4:
if ( (unsigned int)func2(*(_QWORD *)(a1 + 16), a2, a3, a4) )
return 1LL;
a1 = *(_QWORD *)(a1 + 24);
continue;
case 5:
LABEL_4:
a1 += 40LL;
++a2;
continue;
case 6:
v9 = *(int *)(a1 + 8);
if ( (int)v9 >= (int)a4 )
{
a1 += 40LL;
continue;
}
v10 = (char **)(a3 + 8 * v9);
v11 = *v10;
*v10 = a2;
result = func2(a1 + 40, a2, a3, a4);
if ( (_DWORD)result )
return 1LL;
*(_QWORD *)(a3 + 8LL * *(int *)(a1 + 8)) = v11;
return result;
default:
fatal("recursiveloop");
continue;
}
}
}

original_code:
int
recursiveloop(Inst *pc, char *sp, char **subp, int nsubp)
{
 char *old;
 for(;;) {
  switch(pc->opcode) {
  case Char:
   if(*sp != pc->c)
    return 0;
  case Any:
   pc++;
   sp++;
   continue;
  case Match:
   return 1;
  case Jmp:
   pc = pc->x;
   continue;
  case Split:
   if(recursiveloop(pc->x, sp, subp, nsubp))
    return 1;
   pc = pc->y;
   continue;
  case Save:
   if(pc->n >= nsubp) {
    pc++;
    continue;
   }
   old = subp[pc->n];
   subp[pc->n] = sp;
   if(recursiveloop(pc+1, sp, subp, nsubp))
    return 1;
   subp[pc->n] = old;
   return 0;
  }
  fatal("recursiveloop");
 }
}

canonical_original_code:
int recursiveloop(struct Inst *pc, char *sp, char **subp, int nsubp)
{
 char *old;
 for(;;) {
  switch(pc->opcode) {
  case Char:
   if(*sp != pc->c)
    return 0;
  case Any:
   pc++;
   sp++;
   continue;
  case Match:
   return 1;
  case Jmp:
   pc = pc->x;
   continue;
  case Split:
   if(recursiveloop(pc->x, sp, subp, nsubp))
    return 1;
   pc = pc->y;
   continue;
  case Save:
   if(pc->n >= nsubp) {
    pc++;
    continue;
   }
   old = subp[pc->n];
   subp[pc->n] = sp;
   if(recursiveloop(pc+1, sp, subp, nsubp))
    return 1;
   subp[pc->n] = old;
   return 0;
  }
  fatal("recursiveloop");
 }
}

user_defined_types: struct Inst { int opcode; int c; int n; struct Inst *x; struct Inst *y; int gen; }


recursiveloopprog

decompiled_code:
__int64 __fastcall recursiveloopprog(__int64 *a1, char *a2, __int64 a3, unsigned int a4)
{
return recursiveloop(*a1, a2, a3, a4);
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 *a1, char *a2, __int64 a3, unsigned int a4)
{
return func2(*a1, a2, a3, a4);
}

original_code:
int
recursiveloopprog(Prog *prog, char *input, char **subp, int nsubp)
{
 return recursiveloop(prog->start, input, subp, nsubp);
}

canonical_original_code:
int recursiveloopprog(struct Prog *prog, char *input, char **subp, int nsubp)
{
 return recursiveloop(prog->start, input, subp, nsubp);
}


count

decompiled_code:
__int64 __fastcall count(__int64 a1)
{
int v1; // ebp
int v4; // eax
int v5; // eax

v1 = 0;
while ( 1 )
{
switch ( *(_DWORD *)a1 )
{
case 1:
goto LABEL_7;
case 2:
v5 = count(*(_QWORD *)(a1 + 16));
a1 = *(_QWORD *)(a1 + 24);
v1 += v5;
continue;
case 3:
case 4:
return (unsigned int)(v1 + 1);
case 5:
case 7:
a1 = *(_QWORD *)(a1 + 16);
v1 += 2;
continue;
case 6:
case 8:
a1 = *(_QWORD *)(a1 + 16);
++v1;
continue;
default:
fatal("bad count");
LABEL_7:
v4 = count(*(_QWORD *)(a1 + 16));
a1 = *(_QWORD *)(a1 + 24);
v1 += v4 + 2;
break;
}
}
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
int v1; // ebp
int v4; // eax
int v5; // eax

v1 = 0;
while ( 1 )
{
switch ( *(_DWORD *)a1 )
{
case 1:
goto LABEL_7;
case 2:
v5 = func0(*(_QWORD *)(a1 + 16));
a1 = *(_QWORD *)(a1 + 24);
v1 += v5;
continue;
case 3:
case 4:
return (unsigned int)(v1 + 1);
case 5:
case 7:
a1 = *(_QWORD *)(a1 + 16);
v1 += 2;
continue;
case 6:
case 8:
a1 = *(_QWORD *)(a1 + 16);
++v1;
continue;
default:
fatal("bad count");
LABEL_7:
v4 = func0(*(_QWORD *)(a1 + 16));
a1 = *(_QWORD *)(a1 + 24);
v1 += v4 + 2;
break;
}
}
}

original_code:
static int
count(Regexp *r)
{
 switch(r->type) {
 default:
  fatal("bad count");
 case Alt:
  return 2 + count(r->left) + count(r->right);
 case Cat:
  return count(r->left) + count(r->right);
 case Lit:
 case Dot:
  return 1;
 case Paren:
  return 2 + count(r->left);
 case Quest:
  return 1 + count(r->left);
 case Star:
  return 2 + count(r->left);
 case Plus:
  return 1 + count(r->left);
 }
}

canonical_original_code:
static int count(struct Regexp *r)
{
 switch(r->type) {
 default:
  fatal("bad count");
 case Alt:
  return 2 + count(r->left) + count(r->right);
 case Cat:
  return count(r->left) + count(r->right);
 case Lit:
 case Dot:
  return 1;
 case Paren:
  return 2 + count(r->left);
 case Quest:
  return 1 + count(r->left);
 case Star:
  return 2 + count(r->left);
 case Plus:
  return 1 + count(r->left);
 }
}

variable_types: struct Regexp { int type; int n; int ch; struct Regexp *left; struct Regexp *right; } *


emit

original_code:
static void
emit(Regexp *r)
{
 Inst *p1, *p2, *t;
 switch(r->type) {
 default:
  fatal("bad emit");
 case Alt:
  pc->opcode = Split;
  p1 = pc++;
  p1->x = pc;
  emit(r->left);
  pc->opcode = Jmp;
  p2 = pc++;
  p1->y = pc;
  emit(r->right);
  p2->x = pc;
  break;
 case Cat:
  emit(r->left);
  emit(r->right);
  break;
 case Lit:
  pc->opcode = Char;
  pc->c = r->ch;
  pc++;
  break;
 case Dot:
  pc++->opcode = Any;
  break;
 case Paren:
  pc->opcode = Save;
  pc->n = 2*r->n;
  pc++;
  emit(r->left);
  pc->opcode = Save;
  pc->n = 2*r->n + 1;
  pc++;
  break;
 case Quest:
  pc->opcode = Split;
  p1 = pc++;
  p1->x = pc;
  emit(r->left);
  p1->y = pc;
  if(r->n) {
   t = p1->x;
   p1->x = p1->y;
   p1->y = t;
  }
  break;
 case Star:
  pc->opcode = Split;
  p1 = pc++;
  p1->x = pc;
  emit(r->left);
  pc->opcode = Jmp;
  pc->x = p1;
  pc++;
  p1->y = pc;
  if(r->n) {
   t = p1->x;
   p1->x = p1->y;
   p1->y = t;
  }
  break;
 case Plus:
  p1 = pc;
  emit(r->left);
  pc->opcode = Split;
  pc->x = p1;
  p2 = pc;
  pc++;
  p2->y = pc;
  if(r->n) {
   t = p2->x;
   p2->x = p2->y;
   p2->y = t;
  }
  break;
 }
}

canonical_original_code:
static void emit(struct Regexp *r)
{
 struct Inst *p1; struct Inst *p2; struct Inst *t;
 switch(r->type) {
 default:
  fatal("bad emit");
 case Alt:
  pc->opcode = Split;
  p1 = pc++;
  p1->x = pc;
  emit(r->left);
  pc->opcode = Jmp;
  p2 = pc++;
  p1->y = pc;
  emit(r->right);
  p2->x = pc;
  break;
 case Cat:
  emit(r->left);
  emit(r->right);
  break;
 case Lit:
  pc->opcode = Char;
  pc->c = r->ch;
  pc++;
  break;
 case Dot:
  pc++->opcode = Any;
  break;
 case Paren:
  pc->opcode = Save;
  pc->n = 2*r->n;
  pc++;
  emit(r->left);
  pc->opcode = Save;
  pc->n = 2*r->n + 1;
  pc++;
  break;
 case Quest:
  pc->opcode = Split;
  p1 = pc++;
  p1->x = pc;
  emit(r->left);
  p1->y = pc;
  if(r->n) {
   t = p1->x;
   p1->x = p1->y;
   p1->y = t;
  }
  break;
 case Star:
  pc->opcode = Split;
  p1 = pc++;
  p1->x = pc;
  emit(r->left);
  pc->opcode = Jmp;
  pc->x = p1;
  pc++;
  p1->y = pc;
  if(r->n) {
   t = p1->x;
   p1->x = p1->y;
   p1->y = t;
  }
  break;
 case Plus:
  p1 = pc;
  emit(r->left);
  pc->opcode = Split;
  pc->x = p1;
  p2 = pc;
  pc++;
  p2->y = pc;
  if(r->n) {
   t = p2->x;
   p2->x = p2->y;
   p2->y = t;
  }
  break;
 }
}

return_type: void

user_defined_types: struct Regexp { int type; int n; int ch; struct Regexp *left; struct Regexp *right; }


compile

original_code:
Prog*
compile(Regexp *r)
{
 int n;
 Prog *p;
 n = count(r) + 1;
 p = mal(sizeof *p + n*sizeof p->start[0]);
 p->start = (Inst*)(p+1);
 pc = p->start;
 emit(r);
 pc->opcode = Match;
 pc++;
 p->len = pc - p->start;
 return p;
}

canonical_original_code:
struct Prog *compile(struct Regexp *r)
{
 int n;
 struct Prog *p;
 n = count(r) + 1;
 p = mal(sizeof *p + n*sizeof p->start[0]);
 p->start = (struct Inst *)(p+1);
 pc = p->start;
 emit(r);
 pc->opcode = Match;
 pc++;
 p->len = pc - p->start;
 return p;
}

variable_types: n int

return_type: struct Prog { struct Inst { int opcode; int c; int n; struct Inst *x; struct Inst *y; int gen; } *start; int len; } *


printprog

decompiled_code:
int __fastcall printprog(__int64 a1)
{
unsigned __int64 v1; // rbx
int result; // eax
unsigned __int64 v3; // r13

v1 = *(_QWORD *)a1;
result = 5 * *(_DWORD *)(a1 + 8);
v3 = *(_QWORD *)a1 + 40LL * *(int *)(a1 + 8);
if ( *(_QWORD *)a1 < v3 )
{
do
{
switch ( *(_DWORD *)v1 )
{
case 1:
result = printf(
"%2d. char %c\n",
0xCCCCCCCCCCCCCCCDLL * ((__int64)(v1 - *(_QWORD *)a1) >> 3),
*(unsigned int *)(v1 + 4));
break;
case 2:
result = printf("%2d. match\n", 0xCCCCCCCCCCCCCCCDLL * ((__int64)(v1 - *(_QWORD *)a1) >> 3));
break;
case 3:
result = printf(
"%2d. jmp %d\n",
0xCCCCCCCCCCCCCCCDLL * ((__int64)(v1 - *(_QWORD *)a1) >> 3),
0xCCCCCCCCCCCCCCCDLL * ((__int64)(*(_QWORD *)(v1 + 16) - *(_QWORD *)a1) >> 3));
break;
case 4:
goto LABEL_4;
case 5:
result = printf("%2d. any\n", 0xCCCCCCCCCCCCCCCDLL * ((__int64)(v1 - *(_QWORD *)a1) >> 3));
break;
case 6:
result = printf(
"%2d. save %d\n",
0xCCCCCCCCCCCCCCCDLL * ((__int64)(v1 - *(_QWORD *)a1) >> 3),
*(unsigned int *)(v1 + 8));
break;
default:
fatal("printprog");
LABEL_4:
result = printf(
"%2d. split %d, %d\n",
0xCCCCCCCCCCCCCCCDLL * ((__int64)(v1 - *(_QWORD *)a1) >> 3),
0xCCCCCCCCCCCCCCCDLL * ((__int64)(*(_QWORD *)(v1 + 16) - *(_QWORD *)a1) >> 3),
0xCCCCCCCCCCCCCCCDLL * ((__int64)(*(_QWORD *)(v1 + 24) - *(_QWORD *)a1) >> 3));
break;
}
v1 += 40LL;
}
while ( v3 > v1 );
}
return result;
}

canonical_decompiled_code:
int __fastcall func3(__int64 a1)
{
unsigned __int64 v1; // rbx
int result; // eax
unsigned __int64 v3; // r13

v1 = *(_QWORD *)a1;
result = 5 * *(_DWORD *)(a1 + 8);
v3 = *(_QWORD *)a1 + 40LL * *(int *)(a1 + 8);
if ( *(_QWORD *)a1 < v3 )
{
do
{
switch ( *(_DWORD *)v1 )
{
case 1:
result = printf(
"%2d. char %c\n",
0xCCCCCCCCCCCCCCCDLL * ((__int64)(v1 - *(_QWORD *)a1) >> 3),
*(unsigned int *)(v1 + 4));
break;
case 2:
result = printf("%2d. match\n", 0xCCCCCCCCCCCCCCCDLL * ((__int64)(v1 - *(_QWORD *)a1) >> 3));
break;
case 3:
result = printf(
"%2d. jmp %d\n",
0xCCCCCCCCCCCCCCCDLL * ((__int64)(v1 - *(_QWORD *)a1) >> 3),
0xCCCCCCCCCCCCCCCDLL * ((__int64)(*(_QWORD *)(v1 + 16) - *(_QWORD *)a1) >> 3));
break;
case 4:
goto LABEL_4;
case 5:
result = printf("%2d. any\n", 0xCCCCCCCCCCCCCCCDLL * ((__int64)(v1 - *(_QWORD *)a1) >> 3));
break;
case 6:
result = printf(
"%2d. save %d\n",
0xCCCCCCCCCCCCCCCDLL * ((__int64)(v1 - *(_QWORD *)a1) >> 3),
*(unsigned int *)(v1 + 8));
break;
default:
fatal("printprog");
LABEL_4:
result = printf(
"%2d. split %d, %d\n",
0xCCCCCCCCCCCCCCCDLL * ((__int64)(v1 - *(_QWORD *)a1) >> 3),
0xCCCCCCCCCCCCCCCDLL * ((__int64)(*(_QWORD *)(v1 + 16) - *(_QWORD *)a1) >> 3),
0xCCCCCCCCCCCCCCCDLL * ((__int64)(*(_QWORD *)(v1 + 24) - *(_QWORD *)a1) >> 3));
break;
}
v1 += 40LL;
}
while ( v3 > v1 );
}
return result;
}

original_code:
void
printprog(Prog *p)
{
 Inst *pc, *e;
 pc = p->start;
 e = p->start + p->len;
 for(; pc < e; pc++) {
  switch(pc->opcode) {
  default:
   fatal("printprog");
  case Split:
   printf("%2d. split %d, %d\n", (int)(pc-p->start), (int)(pc->x-p->start), (int)(pc->y-p->start));
   break;
  case Jmp:
   printf("%2d. jmp %d\n", (int)(pc-p->start), (int)(pc->x-p->start));
   break;
  case Char:
   printf("%2d. char %c\n", (int)(pc-p->start), pc->c);
   break;
  case Any:
   printf("%2d. any\n", (int)(pc-p->start));
   break;
  case Match:
   printf("%2d. match\n", (int)(pc-p->start));
   break;
  case Save:
   printf("%2d. save %d\n", (int)(pc-p->start), pc->n);
  }
 }
}

canonical_original_code:
void printprog(struct Prog *p)
{
 struct Inst *pc; struct Inst *e;
 pc = p->start;
 e = p->start + p->len;
 for(; pc < e; pc++) {
  switch(pc->opcode) {
  default:
   fatal("printprog");
  case Split:
   printf("%2d. split %d, %d\n", (int)(pc-p->start), (int)(pc->x-p->start), (int)(pc->y-p->start));
   break;
  case Jmp:
   printf("%2d. jmp %d\n", (int)(pc-p->start), (int)(pc->x-p->start));
   break;
  case Char:
   printf("%2d. char %c\n", (int)(pc-p->start), pc->c);
   break;
  case Any:
   printf("%2d. any\n", (int)(pc-p->start));
   break;
  case Match:
   printf("%2d. match\n", (int)(pc-p->start));
   break;
  case Save:
   printf("%2d. save %d\n", (int)(pc-p->start), pc->n);
  }
 }
}


threadlist

decompiled_code:
__int64 __fastcall threadlist(int a1)
{
return mal((unsigned int)(8 * a1 + 16));
}

canonical_decompiled_code:
__int64 __fastcall func2(int a1)
{
return mal((unsigned int)(8 * a1 + 16));
}

original_code:
static ThreadList*
threadlist(int n)
{
 return mal(sizeof(ThreadList)+n*sizeof(Thread));
}

canonical_original_code:
static struct ThreadList *threadlist(int n)
{
 return mal(sizeof(ThreadList)+n*sizeof(Thread));
}

return_type: struct ThreadList { int n; struct Thread { struct Inst { int opcode; int c; int n; struct Inst *x; struct Inst *y; int gen; } *pc; struct Sub { int ref; int nsub; char *sub[-1]; } *sub; } t[1]; } *

user_defined_types: struct ThreadList { int n; struct Thread t[1]; }

user_defined_types: struct Thread { struct Inst *pc; struct Sub *sub; }


thompsonvm

decompiled_code:
__int64 __fastcall thompsonvm(__int64 a1, _BYTE *a2, _QWORD *a3, int a4)
{
_BYTE *v4; // r13
int v7; // er15
int *v8; // rbx
__int64 v9; // rdi
unsigned int *v10; // rax
int *v11; // r8
unsigned int v12; // er9
int v13; // eax
__int64 v14; // rcx
int *v15; // rdi
int v16; // eax
int *v17; // rdx
unsigned int *v18; // rax
int *v19; // r8

v4 = a2;
v7 = *(_DWORD *)(a1 + 8);
if ( a4 <= 0 )
{
v8 = (int *)threadlist(v7);
threadlist(v7);
}
else
{
memset(a3, 0, 8LL * a4);
v8 = (int *)threadlist(v7);
threadlist(v7);
*a3 = a2;
}
v9 = *(_QWORD *)a1;
++gen;
v10 = (unsigned int *)thread(v9);
addthread(v8, v10);
v13 = *v8;
if ( !*v8 )
return v12;
while ( 2 )
{
++gen;
if ( v13 <= 0 )
goto LABEL_10;
v14 = 0LL;
while ( 1 )
{
v15 = *(int **)&v8[2 * v14 + 2];
v16 = *v15;
if ( *v15 == 2 )
break;
if ( v16 == 5 )
{
if ( !*v4 )
goto LABEL_9;
}
else if ( v16 != 1 || (char)*v4 != v15[1] || !*v4 )
{
goto LABEL_9;
}
v18 = (unsigned int *)thread((__int64)(v15 + 10));
addthread(v19, v18);
LABEL_9:
if ( *v8 <= (int)++v14 )
goto LABEL_10;
}
v12 = 1;
if ( a4 <= 1 )
{
LABEL_10:
*v8 = 0;
if ( *v4 )
goto LABEL_11;
return v12;
}
a3[1] = v4;
*v8 = 0;
if ( !*v4 )
return v12;
LABEL_11:
v13 = *v11;
v17 = v11;
++v4;
v11 = v8;
if ( v13 )
{
v8 = v17;
continue;
}
return v12;
}
}

original_code:
int
thompsonvm(Prog *prog, char *input, char **subp, int nsubp)
{
 int i, len, matched;
 ThreadList *clist, *nlist, *tmp;
 Inst *pc;
 char *sp;
 for(i=0; i<nsubp; i++)
  subp[i] = ((void*)0);
 len = prog->len;
 clist = threadlist(len);
 nlist = threadlist(len);
 if(nsubp >= 1)
  subp[0] = input;
 gen++;
 addthread(clist, thread(prog->start));
 matched = 0;
 for(sp=input;; sp++) {
  if(clist->n == 0)
   break;
  gen++;
  for(i=0; i<clist->n; i++) {
   pc = clist->t[i].pc;
   switch(pc->opcode) {
   case Char:
    if(*sp != pc->c)
     break;
   case Any:
    if(*sp == 0)
     break;
    addthread(nlist, thread(pc+1));
    break;
   case Match:
    if(nsubp >= 2)
     subp[1] = sp;
    matched = 1;
    goto BreakFor;
   }
  }
 BreakFor:
  tmp = clist;
  clist = nlist;
  nlist = tmp;
  nlist->n = 0;
  if(*sp == '\0')
   break;
 }
 return matched;
}

canonical_original_code:
int thompsonvm(struct Prog *prog, char *input, char **subp, int nsubp)
{
 int i; int len; int matched;
 struct ThreadList *clist; struct ThreadList *nlist; struct ThreadList *tmp;
 struct Inst *pc;
 char *sp;
 for(i=0; i<nsubp; i++)
  subp[i] = ((void *)0);
 len = prog->len;
 clist = threadlist(len);
 nlist = threadlist(len);
 if(nsubp >= 1)
  subp[0] = input;
 gen++;
 addthread(clist, thread(prog->start));
 matched = 0;
 for(sp=input;; sp++) {
  if(clist->n == 0)
   break;
  gen++;
  for(i=0; i<clist->n; i++) {
   pc = clist->t[i].pc;
   switch(pc->opcode) {
   case Char:
    if(*sp != pc->c)
     break;
   case Any:
    if(*sp == 0)
     break;
    addthread(nlist, thread(pc+1));
    break;
   case Match:
    if(nsubp >= 2)
     subp[1] = sp;
    matched = 1;
    goto BreakFor;
   }
  }
 BreakFor:
  tmp = clist;
  clist = nlist;
  nlist = tmp;
  nlist->n = 0;
  if(*sp == '\0')
   break;
 }
 return matched;
}

variable_types: i int

variable_types: len int

variable_types: matched int

variable_types: struct ThreadList { int n; struct Thread { struct Inst { int opcode; int c; int n; struct Inst *x; struct Inst *y; int gen; } *pc; } t[1]; } *


update

original_code:
Sub*
update(Sub *s, int i, char *p)
{
 Sub *s1;
 int j;
 if(s->ref > 1) {
  s1 = newsub(s->nsub);
  for(j=0; j<s->nsub; j++)
   s1->sub[j] = s->sub[j];
  s->ref--;
  s = s1;
 }
 s->sub[i] = p;
 return s;
}

canonical_original_code:
struct Sub *update(struct Sub *s, int i, char *p)
{
 struct Sub *s1;
 int j;
 if(s->ref > 1) {
  s1 = newsub(s->nsub);
  for(j=0; j<s->nsub; j++)
   s1->sub[j] = s->sub[j];
  s->ref--;
  s = s1;
 }
 s->sub[i] = p;
 return s;
}

variable_types:
s
struct Sub *

variable_types:
p
char *

variable_types: struct Sub { int ref; int nsub; char *sub[-1]; } *

variable_types: j int


decref

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

if ( (*(_DWORD *)a1)-- == 1 )
{
result = freesub;
freesub = a1;
*(_QWORD *)(a1 + 8) = result;
}
return result;
}

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

if ( (*(_DWORD *)a1)-- == 1 )
{
result = freesub;
freesub = a1;
*(_QWORD *)(a1 + 8) = result;
}
return result;
}

original_code:
void
decref(Sub *s)
{
 if(--s->ref == 0) {
  s->sub[0] = (char*)freesub;
  freesub = s;
 }
}

canonical_original_code:
void decref(struct Sub *s)
{
 if(--s->ref == 0) {
  s->sub[0] = (char *)freesub;
  freesub = s;
 }
}

user_defined_types: struct Sub { int ref; int nsub; char *sub[-1]; }


threadlist

decompiled_code:
__int64 __fastcall threadlist(int a1)
{
return mal((unsigned int)(16 * a1 + 24));
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1)
{
return mal((unsigned int)(16 * a1 + 24));
}


pikevm

original_code:
int
pikevm(Prog *prog, char *input, char **subp, int nsubp)
{
 int i, len;
 ThreadList *clist, *nlist, *tmp;
 Inst *pc;
 char *sp;
 Sub *sub, *matched;
 matched = ((void*)0);
 for(i=0; i<nsubp; i++)
  subp[i] = ((void*)0);
 sub = newsub(nsubp);
 for(i=0; i<nsubp; i++)
  sub->sub[i] = ((void*)0);
 len = prog->len;
 clist = threadlist(len);
 nlist = threadlist(len);
 gen++;
 addthread(clist, thread(prog->start, sub), input);
 matched = 0;
 for(sp=input;; sp++) {
  if(clist->n == 0)
   break;
  gen++;
  for(i=0; i<clist->n; i++) {
   pc = clist->t[i].pc;
   sub = clist->t[i].sub;
   switch(pc->opcode) {
   case Char:
    if(*sp != pc->c) {
     decref(sub);
     break;
    }
   case Any:
    if(*sp == 0) {
     decref(sub);
     break;
    }
    addthread(nlist, thread(pc+1, sub), sp+1);
    break;
   case Match:
    if(matched)
     decref(matched);
    matched = sub;
    for(i++; i < clist->n; i++)
     decref(clist->t[i].sub);
    goto BreakFor;
   }
  }
 BreakFor:
  tmp = clist;
  clist = nlist;
  nlist = tmp;
  nlist->n = 0;
  if(*sp == '\0')
   break;
 }
 if(matched) {
  for(i=0; i<nsubp; i++)
   subp[i] = matched->sub[i];
  decref(matched);
  return 1;
 }
 return 0;
}

canonical_original_code:
int pikevm(struct Prog *prog, char *input, char **subp, int nsubp)
{
 int i; int len;
 struct ThreadList *clist; struct ThreadList *nlist; struct ThreadList *tmp;
 struct Inst *pc;
 char *sp;
 struct Sub *sub; struct Sub *matched;
 matched = ((void *)0);
 for(i=0; i<nsubp; i++)
  subp[i] = ((void *)0);
 sub = newsub(nsubp);
 for(i=0; i<nsubp; i++)
  sub->sub[i] = ((void *)0);
 len = prog->len;
 clist = threadlist(len);
 nlist = threadlist(len);
 gen++;
 addthread(clist, thread(prog->start, sub), input);
 matched = 0;
 for(sp=input;; sp++) {
  if(clist->n == 0)
   break;
  gen++;
  for(i=0; i<clist->n; i++) {
   pc = clist->t[i].pc;
   sub = clist->t[i].sub;
   switch(pc->opcode) {
   case Char:
    if(*sp != pc->c) {
     decref(sub);
     break;
    }
   case Any:
    if(*sp == 0) {
     decref(sub);
     break;
    }
    addthread(nlist, thread(pc+1, sub), sp+1);
    break;
   case Match:
    if(matched)
     decref(matched);
    matched = sub;
    for(i++; i < clist->n; i++)
     decref(clist->t[i].sub);
    goto BreakFor;
   }
  }
 BreakFor:
  tmp = clist;
  clist = nlist;
  nlist = tmp;
  nlist->n = 0;
  if(*sp == '\0')
   break;
 }
 if(matched) {
  for(i=0; i<nsubp; i++)
   subp[i] = matched->sub[i];
  decref(matched);
  return 1;
 }
 return 0;
}

variable_types: struct ThreadList { int n; struct Thread { struct Inst { int opcode; int c; int n; struct Inst *x; struct Inst *y; int gen; } *pc; struct Sub { int ref; int nsub; char *sub[-1]; } *sub; } t[1]; } *


backtrack

original_code:
int
backtrack(Prog *prog, char *input, char **subp, int nsubp)
{
 enum { MAX = 1000 };
 Thread ready[MAX];
 int i, nready;
 Inst *pc;
 char *sp;
 Sub *sub;
 sub = newsub(nsubp);
 for(i=0; i<nsubp; i++)
  sub->sub[i] = ((void*)0);
 ready[0] = thread(prog->start, input, sub);
 nready = 1;
 while(nready > 0) {
  --nready;
  pc = ready[nready].pc;
  sp = ready[nready].sp;
  sub = ready[nready].sub;
  ((void) sizeof ((sub->ref > 0) ? 1 : 0), __extension__ ({ if (sub->ref > 0) ; else __assert_fail ("sub->ref > 0", "backtrack.c", 45, __extension__ __PRETTY_FUNCTION__); }));
  for(;;) {
   switch(pc->opcode) {
   case Char:
    if(*sp != pc->c)
     goto Dead;
    pc++;
    sp++;
    continue;
   case Any:
    if(*sp == 0)
     goto Dead;
    pc++;
    sp++;
    continue;
   case Match:
    for(i=0; i<nsubp; i++)
     subp[i] = sub->sub[i];
    decref(sub);
    return 1;
   case Jmp:
    pc = pc->x;
    continue;
   case Split:
    if(nready >= MAX)
     fatal("backtrack overflow");
    ready[nready++] = thread(pc->y, sp, incref(sub));
    pc = pc->x;
    continue;
   case Save:
    sub = update(sub, pc->n, sp);
    pc++;
    continue;
   }
  }
 Dead:
  decref(sub);
 }
 return 0;
}

canonical_original_code:
int backtrack(struct Prog *prog, char *input, char **subp, int nsubp)
{
 enum { MAX = 1000 };
 struct Thread ready[-1];
 int i; int nready;
 struct Inst *pc;
 char *sp;
 struct Sub *sub;
 sub = newsub(nsubp);
 for(i=0; i<nsubp; i++)
  sub->sub[i] = ((void *)0);
 ready[0] = thread(prog->start, input, sub);
 nready = 1;
 while(nready > 0) {
  --nready;
  pc = ready[nready].pc;
  sp = ready[nready].sp;
  sub = ready[nready].sub;
  ((void) sizeof ((sub->ref > 0) ? 1 : 0), __extension__ ({ if (sub->ref > 0) ; else __assert_fail ("sub->ref > 0", "backtrack.c", 45, __extension__ __PRETTY_FUNCTION__); }));
  for(;;) {
   switch(pc->opcode) {
   case Char:
    if(*sp != pc->c)
     goto Dead;
    pc++;
    sp++;
    continue;
   case Any:
    if(*sp == 0)
     goto Dead;
    pc++;
    sp++;
    continue;
   case Match:
    for(i=0; i<nsubp; i++)
     subp[i] = sub->sub[i];
    decref(sub);
    return 1;
   case Jmp:
    pc = pc->x;
    continue;
   case Split:
    if(nready >= MAX)
     fatal("backtrack overflow");
    ready[nready++] = thread(pc->y, sp, incref(sub));
    pc = pc->x;
    continue;
   case Save:
    sub = update(sub, pc->n, sp);
    pc++;
    continue;
   }
  }
 Dead:
  decref(sub);
 }
 return 0;
}

variable_types: struct Thread { struct Inst { int opcode; int c; int n; struct Inst *x; struct Inst *y; int gen; } *pc; char *sp; struct Sub { int ref; int nsub; char *sub[-1]; } *sub; } [-1]

variable_types: nready int

variable_types:
sp
char *

user_defined_types: struct Thread { struct Inst *pc; char *sp; struct Sub *sub; }


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
FILE *v3; // rax
FILE *v4; // rbp
FILE *v5; // rax
FILE *v6; // rbp
FILE *v7; // rax
FILE *v8; // rbp
int v9; // er12
int v10; // ebx
__int64 v11; // rbp
__int64 v12; // rax

v3 = fopen("/proc/sysmon_toggle", "w");
if ( !v3 )
goto LABEL_9;
v4 = v3;
fprintf(v3, "1");
fclose(v4);
puts("Kprobe toggled ON");
v5 = fopen("/proc/sysmon_uid", "w");
v6 = v5;
if ( !v5 )
{
puts("sysmon_uid not open");
return 1;
}
fprintf(v5, "396531");
fclose(v6);
puts("Kprobe set uid");
v7 = fopen("/proc/sysmon_toggle", "w");
v8 = v7;
if ( !v7 )
{
LABEL_9:
puts("sysmon_toggle not open");
return 1;
}
v9 = 100;
fprintf(v7, "0");
fclose(v8);
puts("Kprobe toggled off");
puts("access, ");
do
{
v10 = 128;
v11 = rdtsc();
do
{
syscall(21LL, 0LL, 0LL);
--v10;
}
while ( v10 );
v12 = rdtsc();
printf("%llu, \n", v12 - v11);
--v9;
}
while ( v9 );
putchar(10);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
FILE *v3; // rax
FILE *v4; // rbp
FILE *v5; // rax
FILE *v6; // rbp
FILE *v7; // rax
FILE *v8; // rbp
int v9; // er12
int v10; // ebx
__int64 v11; // rbp
__int64 v12; // rax

v3 = fopen("/proc/sysmon_toggle", "w");
if ( !v3 )
goto LABEL_9;
v4 = v3;
fprintf(v3, "1");
fclose(v4);
puts("Kprobe toggled ON");
v5 = fopen("/proc/sysmon_uid", "w");
v6 = v5;
if ( !v5 )
{
puts("sysmon_uid not open");
return 1;
}
fprintf(v5, "396531");
fclose(v6);
puts("Kprobe set uid");
v7 = fopen("/proc/sysmon_toggle", "w");
v8 = v7;
if ( !v7 )
{
LABEL_9:
puts("sysmon_toggle not open");
return 1;
}
v9 = 100;
fprintf(v7, "0");
fclose(v8);
puts("Kprobe toggled off");
puts("access, ");
do
{
v10 = 128;
v11 = func7();
do
{
syscall(21LL, 0LL, 0LL);
--v10;
}
while ( v10 );
v12 = func7();
printf("%llu, \n", v12 - v11);
--v9;
}
while ( v9 );
putchar(10);
return 0;
}

original_code:
int main(void)
{
 unsigned int syscall_number = 1024;
 unsigned int epoch = 100;
 unsigned int index_syscall = 0;
 unsigned int index_epoch = 0;
 unsigned long long start, end, total;
 char buf[40];
 char buf_write[20] = "hello\n";
 printf("getuid, \n");
 for(index_epoch = 0; index_epoch < epoch; index_epoch++){
  start = rdtsc();
  for(index_syscall = 0; index_syscall < syscall_number; index_syscall++){
   syscall(102);
  }
  end = rdtsc();
  total = end - start;
  printf("%llu, \n", total);
 }
 printf("\n");
 return 0;
}

canonical_original_code:
int main()
{
 unsigned int syscall_number = 1024;
 unsigned int epoch = 100;
 unsigned int index_syscall = 0;
 unsigned int index_epoch = 0;
 unsigned long long start; unsigned long long end; unsigned long long total;
 char buf[40];
 char buf_write[20] = "hello\n";
 printf("getuid, \n");
 for(index_epoch = 0; index_epoch < epoch; index_epoch++){
  start = rdtsc();
  for(index_syscall = 0; index_syscall < syscall_number; index_syscall++){
   syscall(102);
  }
  end = rdtsc();
  total = end - start;
  printf("%llu, \n", total);
 }
 printf("\n");
 return 0;
}

variable_types:
epoch
unsigned int

variable_types:
start
unsigned long long

variable_types:
end
unsigned long long

variable_types:
total
unsigned long long

variable_types:
buf
char [40]


rdtsc

decompiled_code:
unsigned __int64 rdtsc()
{
return __rdtsc();
}

canonical_decompiled_code:
unsigned __int64 func7()
{
return __rdtsc();
}

original_code:
static __inline__ unsigned long long rdtsc(void)
{
  unsigned hi, lo;
  __asm__ __volatile__ ("rdtsc" : "=a"(lo), "=d"(hi));
  return ( (unsigned long long)lo)|( ((unsigned long long)hi)<<32 );
}

canonical_original_code:
static __inline__ unsigned long long rdtsc()
{
  unsigned int hi; unsigned int lo;
  __asm__ __volatile__ ("rdtsc" : "=a"(lo), "=d"(hi));
  return ( (unsigned long long)lo)|( ((unsigned long long)hi)<<32 );
}

variable_types:
hi
unsigned int

variable_types:
lo
unsigned int

return_type: unsigned long long


repo: agrimaldi/pmap

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

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

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

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

original_code:
double u_wseconds(void) {
    struct timeval tp;
    gettimeofday(&tp, ((void *)0));
    return (double) tp.tv_sec + (double) tp.tv_usec / 1000000.0;
}

canonical_original_code:
double u_wseconds() {
    struct timeval tp;
    gettimeofday(&tp, ((void *)0));
    return (double) tp.tv_sec + (double) tp.tv_usec / 1000000.0;
}

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

return_type: double


main

repo: agusk/sorting

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rdx
__int64 v4; // rdx
__int64 v5; // rdx
__int64 v6; // rdx
__int64 v7; // rdx
__int64 v8; // rdx
__int64 v9; // rdx
__int64 v10; // rdx
__int64 v11; // rdx
__int64 v12; // rdx

printList("data", argv, envp);
bubbleSort(&list, 10LL);
printList("bubblesort", 10LL, v3);
resetList(&list, 10LL);
insertionSort();
printList("insertionsort", 10LL, v4);
resetList(&list, 10LL);
selectionSort();
printList("selectionsort", 10LL, v5);
resetList(&list, 10LL);
heapSort();
printList("heapsort", 10LL, v6);
resetList("heapsort", 0LL);
quickSort(&list);
printList("quicksort", 0LL, v7);
resetList("quicksort", 0LL);
mergeSort(&list, 0LL, 9LL);
printList("mergesort", 0LL, v8);
resetList(&list, 10LL);
radixSort();
printList("radixsort", 10LL, v9);
resetList(&list, 10LL);
gnomeSort();
printList("gnomesort", 10LL, v10);
resetList(&list, 10LL);
shellSort();
printList("shellsort", 10LL, v11);
resetList(&list, 10LL);
cycleSort();
printList("cyclesort", 10LL, v12);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rdx
__int64 v4; // rdx
__int64 v5; // rdx
__int64 v6; // rdx
__int64 v7; // rdx
__int64 v8; // rdx
__int64 v9; // rdx
__int64 v10; // rdx
__int64 v11; // rdx
__int64 v12; // rdx

func19("data", argv, envp);
func7(&list, 10LL);
func19("bubblesort", 10LL, v3);
func18(&list, 10LL);
func8();
func19("insertionsort", 10LL, v4);
func18(&list, 10LL);
func9();
func19("selectionsort", 10LL, v5);
func18(&list, 10LL);
func10();
func19("heapsort", 10LL, v6);
func18("heapsort", 0LL);
func11(&list);
func19("quicksort", 0LL, v7);
func18("quicksort", 0LL);
func13(&list, 0LL, 9LL);
func19("mergesort", 0LL, v8);
func18(&list, 10LL);
func14();
func19("radixsort", 10LL, v9);
func18(&list, 10LL);
func15();
func19("gnomesort", 10LL, v10);
func18(&list, 10LL);
func16();
func19("shellsort", 10LL, v11);
func18(&list, 10LL);
func17();
func19("cyclesort", 10LL, v12);
return 0;
}

original_code:
int main() {
  printList("data");
  bubbleSort(list,10);
  printList("bubblesort");
  resetList();
  insertionSort(list,10);
  printList("insertionsort");
  resetList();
  selectionSort(list,10);
  printList("selectionsort");
  resetList();
  heapSort(list,10);
  printList("heapsort");
  resetList();
  quickSort(list,0,9);
  printList("quicksort");
  resetList();
  mergeSort(list,0,9,10);
  printList("mergesort");
  resetList();
  radixSort(list,10);
  printList("radixsort");
  resetList();
  gnomeSort(list,10);
  printList("gnomesort");
  resetList();
  shellSort(list,10);
  printList("shellsort");
  resetList();
  cycleSort(list,10);
  printList("cyclesort");
}


printList

decompiled_code:
int __fastcall printList(const char *a1)
{
char *v1; // rbx
__int64 v2; // rsi

v1 = (char *)&list;
printf("%s :", a1);
do
{
v2 = *(_QWORD *)v1;
v1 += 8;
printf("%ld ", v2);
}
while ( v1 != &_bss_start );
return putchar(10);
}

canonical_decompiled_code:
int __fastcall func19(const char *a1)
{
char *v1; // rbx
__int64 v2; // rsi

v1 = (char *)&list;
printf("%s :", a1);
do
{
v2 = *(_QWORD *)v1;
v1 += 8;
printf("%ld ", v2);
}
while ( v1 != &_bss_start );
return putchar(10);
}

original_code:
void printList(char* title) {
  int i;
  printf("%s :",title);
  for(i=0;i<10;i++)
    printf("%ld ", list[i]);
  printf("\n");
}

canonical_original_code:
void printList(char *title) {
  int i;
  printf("%s :",title);
  for(i=0;i<10;i++)
    printf("%ld ", list[i]);
  printf("\n");
}

variable_types:
title
char *

variable_types: i int


repo: agustingianni/StreamingProject

decompiled_code:
__int64 socket_error()
{
return (unsigned int)*_errno_location();
}

canonical_decompiled_code:
__int64 func1()
{
return (unsigned int)*_errno_location();
}

original_code:
int
socket_error(void)
{
 return (*__errno_location ());
}

canonical_original_code:
int socket_error()
{
 return (*__errno_location ());
}


decompiled_code:
_BOOL8 __fastcall socket_recoverable(int a1)
{
_BOOL8 result; // rax

if ( a1 > 11 )
{
result = 1LL;
if ( a1 != 85 )
result = a1 == 115;
}
else
{
result = 0LL;
if ( a1 >= 0 )
result = ((1LL << a1) & 0x811) != 0;
}
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func2(int a1)
{
_BOOL8 result; // rax

if ( a1 > 11 )
{
result = 1LL;
if ( a1 != 85 )
result = a1 == 115;
}
else
{
result = 0LL;
if ( a1 >= 0 )
result = ((1LL << a1) & 0x811) != 0;
}
return result;
}

original_code:
int
socket_recoverable(int error)
{
 switch (error)
 {
  case 0:
  case 11:
  case 4:
  case 115:
  case 85:
   return 1;
  default:
   return 0;
 }
}

variable_types: error int


decompiled_code:
__int64 __fastcall socket_stalled(int a1)
{
if ( a1 == 85 )
return 1LL;
if ( a1 > 85 )
return (unsigned int)(a1 - 114) <= 1;
return a1 == 11;
}

canonical_decompiled_code:
__int64 __fastcall func3(int a1)
{
if ( a1 == 85 )
return 1LL;
if ( a1 > 85 )
return (unsigned int)(a1 - 114) <= 1;
return a1 == 11;
}

original_code:
int
socket_stalled(int error)
{
 switch (error)
 {
  case 11:
  case 115:
  case 114:
  case 85:
   return 1;
  default:
   return 0;
 }
}


decompiled_code:
__int64 __fastcall socket_active(int a1)
{
char buf[9]; // [rsp+Fh] [rbp-9h] BYREF

recv(a1, buf, 1uLL, 2);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func4(int a1)
{
char buf[9]; // [rsp+Fh] [rbp-9h] BYREF

recv(a1, buf, 1uLL, 2);
return 0LL;
}

original_code:
int
socket_active(int sock)
{
 char c;
 int l;
 l = recv(sock, &c, 1, MSG_PEEK);
 if (l == 0)
  return 0;
 return 0;
}

variable_types: sock int

variable_types: c char

variable_types: l int


decompiled_code:
int __fastcall socket_set_blocking(int a1)
{
return fcntl(a1, 4, 0LL);
}

canonical_decompiled_code:
int __fastcall func5(int a1)
{
return fcntl(a1, 4, 0LL);
}

original_code:
int
socket_set_blocking(int sock)
{
 return fcntl(sock, 4, 0);
}


decompiled_code:
int __fastcall socket_set_nonblocking(int a1)
{
return fcntl(a1, 4, 2048LL);
}

canonical_decompiled_code:
int __fastcall func6(int a1)
{
return fcntl(a1, 4, 2048LL);
}

original_code:
int
socket_set_nonblocking(int sock)
{
 return fcntl(sock, 4, 04000);
}


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

optval = 0LL;
return setsockopt(a1, 1, 13, &optval, 8u);
}

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

optval = 0LL;
return setsockopt(a1, 1, 13, &optval, 8u);
}

original_code:
int
socket_set_no_linger(int sock)
{
 struct linger lin = { 0, 0 };
 return setsockopt(sock, 1, 13, (void *) &lin,
   sizeof(struct linger));
}

variable_types: struct linger { int l_onoff; int l_linger; }


decompiled_code:
int __fastcall socket_set_nodelay(int a1)
{
int optval[3]; // [rsp+Ch] [rbp-Ch] BYREF

optval[0] = 1;
return setsockopt(a1, 6, 1, optval, 4u);
}

canonical_decompiled_code:
int __fastcall func8(int a1)
{
int optval[3]; // [rsp+Ch] [rbp-Ch] BYREF

optval[0] = 1;
return setsockopt(a1, 6, 1, optval, 4u);
}

original_code:
int
socket_set_nodelay(int sock)
{
 int nodelay = 1;
 return setsockopt(sock, IPPROTO_TCP, 1, (void *) &nodelay,
   sizeof(int));
}

variable_types: nodelay int


decompiled_code:
int __fastcall socket_set_keepalive(int a1)
{
int optval[3]; // [rsp+Ch] [rbp-Ch] BYREF

optval[0] = 1;
return setsockopt(a1, 1, 9, optval, 4u);
}

canonical_decompiled_code:
int __fastcall func9(int a1)
{
int optval[3]; // [rsp+Ch] [rbp-Ch] BYREF

optval[0] = 1;
return setsockopt(a1, 1, 9, optval, 4u);
}

original_code:
int
socket_set_keepalive(int sock)
{
 int keepalive = 1;
 return setsockopt(sock, 1, 9, (void *) &keepalive,
   sizeof(int));
}

variable_types: keepalive int


decompiled_code:
// attributes: thunk
int socket_close(int fd)
{
return close(fd);
}

canonical_decompiled_code:
int func10(int fd)
{
return close(fd);
}

original_code:
int
socket_close(int sock)
{
 return close(sock);
}


decompiled_code:
ssize_t __fastcall socket_write(int a1, const void *a2, size_t a3)
{
return send(a1, a2, a3, 0);
}

canonical_decompiled_code:
ssize_t __fastcall func11(int a1, const void *a2, size_t a3)
{
return send(a1, a2, a3, 0);
}

original_code:
int
socket_write(int sock, const void *buff, size_t len)
{
 return send(sock, buff, len, 0);
}

canonical_original_code:
int socket_write(int sock, void *buff, unsigned long len)
{
 return send(sock, buff, len, 0);
}

variable_types:
buff
void *

variable_types:
len
unsigned long


decompiled_code:
__int64 __fastcall socket_write_all(int a1, char *a2, size_t a3)
{
unsigned int v3; // er13
size_t v5; // rbx
int v6; // eax

v3 = a3;
v5 = a3;
if ( !a3 )
return v3;
do
{
while ( 1 )
{
v6 = socket_write(a1, a2, v5);
if ( v6 <= 0 )
break;
a2 += v6;
v5 -= v6;
if ( !v5 )
return v3;
}
}
while ( v6 && *_errno_location() == 4 );
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func12(int a1, char *a2, size_t a3)
{
unsigned int v3; // er13
size_t v5; // rbx
int v6; // eax

v3 = a3;
v5 = a3;
if ( !a3 )
return v3;
do
{
while ( 1 )
{
v6 = func11(a1, a2, v5);
if ( v6 <= 0 )
break;
a2 += v6;
v5 -= v6;
if ( !v5 )
return v3;
}
}
while ( v6 && *_errno_location() == 4 );
return 0xFFFFFFFFLL;
}

original_code:
int
socket_write_all(int sock, const void *buff, size_t len)
{
 size_t nleft;
 ssize_t nwritten;
 const char *ptr;
 ptr = buff;
 nleft = len;
 while (nleft > 0)
 {
  if ( (nwritten = socket_write(sock, ptr, nleft)) <= 0)
  {
   if (nwritten < 0 && (*__errno_location ()) == 4)
    nwritten = 0;
   else
    return (-1);
  }
  nleft -= nwritten;
  ptr += nwritten;
 }
 return len;
}

canonical_original_code:
int socket_write_all(int sock, void *buff, unsigned long len)
{
 unsigned long nleft;
 long nwritten;
 char *ptr;
 ptr = buff;
 nleft = len;
 while (nleft > 0)
 {
  if ( (nwritten = socket_write(sock, ptr, nleft)) <= 0)
  {
   if (nwritten < 0 && (*__errno_location ()) == 4)
    nwritten = 0;
   else
    return (-1);
  }
  nleft -= nwritten;
  ptr += nwritten;
 }
 return len;
}

variable_types:
nleft
unsigned long

variable_types: nwritten long

variable_types:
ptr
char *


decompiled_code:
ssize_t __fastcall socket_read(int a1, void *a2, size_t a3)
{
ssize_t result; // rax

if ( a2 )
result = recv(a1, a2, a3, 0);
else
result = 0LL;
return result;
}

canonical_decompiled_code:
ssize_t __fastcall func13(int a1, void *a2, size_t a3)
{
ssize_t result; // rax

if ( a2 )
result = recv(a1, a2, a3, 0);
else
result = 0LL;
return result;
}

original_code:
int
socket_read(int sock, char *buff, size_t len)
{
 if (!buff)
  return 0;
 return recv(sock, buff, len, 0);
}

canonical_original_code:
int socket_read(int sock, char *buff, unsigned long len)
{
 if (!buff)
  return 0;
 return recv(sock, buff, len, 0);
}

variable_types:
buff
char *


decompiled_code:
__int64 __fastcall socket_read_string(int a1, void *a2, __int64 a3)
{
__int64 result; // rax

if ( !a2 )
return 0LL;
LODWORD(result) = recv(a1, a2, a3 - 1, 0);
if ( (_DWORD)result != -1 )
*((_BYTE *)a2 + (int)result) = 0;
return (unsigned int)result;
}

canonical_decompiled_code:
__int64 __fastcall func14(int a1, void *a2, __int64 a3)
{
__int64 result; // rax

if ( !a2 )
return 0LL;
LODWORD(result) = recv(a1, a2, a3 - 1, 0);
if ( (_DWORD)result != -1 )
*((_BYTE *)a2 + (int)result) = 0;
return (unsigned int)result;
}

original_code:
int
socket_read_string(int sock, char *string_buffer, size_t len)
{
 if (!string_buffer)
  return 0;
 int ret = recv(sock, string_buffer, len-1, 0);
 if(ret != -1)
  string_buffer[ret] = '\0';
 return ret;
}

canonical_original_code:
int socket_read_string(int sock, char *string_buffer, unsigned long len)
{
 if (!string_buffer)
  return 0;
 int ret = recv(sock, string_buffer, len-1, 0);
 if(ret != -1)
  string_buffer[ret] = '\0';
 return ret;
}

variable_types: ret int


decompiled_code:
__int64 __fastcall socket_tcp_server(int a1)
{
int v1; // edx
int v2; // eax
unsigned int v3; // er12
int optval; // [rsp+Ch] [rbp-1Ch] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-18h] BYREF

if ( a1 < 0
|| (addr = 0LL, addr.sa_family = 2, *(_WORD *)addr.sa_data = _bswap_16(a1), v2 = socket(2, 1, v1), v3 = v2, v2 == -1)
|| (optval = 1, setsockopt(v2, 1, 2, &optval, 4u), bind(v3, &addr, 0x10u) == -1) )
{
v3 = -1;
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func15(int a1)
{
int v1; // edx
int v2; // eax
unsigned int v3; // er12
int optval; // [rsp+Ch] [rbp-1Ch] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-18h] BYREF

if ( a1 < 0
|| (addr = 0LL, addr.sa_family = 2, *(_WORD *)addr.sa_data = func0(a1), v2 = socket(2, 1, v1), v3 = v2, v2 == -1)
|| (optval = 1, setsockopt(v2, 1, 2, &optval, 4u), bind(v3, &addr, 0x10u) == -1) )
{
v3 = -1;
}
return v3;
}

original_code:
int
socket_tcp_server(int port)
{
 struct sockaddr_in sa;
 int opt;
 int sock;
 if (port < 0)
  return -1;
 memset(&sa, 0, sizeof(sa));
 sa.sin_addr.s_addr = ((in_addr_t) 0x00000000);
 sa.sin_family = 2;
 sa.sin_port = htons(port);
 if ((sock = socket(2, SOCK_STREAM,
   IPPROTO_TCP)) == -1)
  return -1;
 opt = 1;
 setsockopt(sock, 1, 2,
   (const void *) &opt, sizeof(int));
 if(bind(sock, (struct sockaddr *) &sa,
   sizeof(struct sockaddr_in)) == -1)
  return -1;
 return sock;
}

canonical_original_code:
int socket_tcp_server(int port)
{
 struct sockaddr_in sa;
 int opt;
 int sock;
 if (port < 0)
  return -1;
 memset(&sa, 0, sizeof(sa));
 sa.sin_addr.s_addr = ((unsigned int) 0x00000000);
 sa.sin_family = 2;
 sa.sin_port = htons(port);
 if ((sock = socket(2, SOCK_STREAM,
   IPPROTO_TCP)) == -1)
  return -1;
 opt = 1;
 setsockopt(sock, 1, 2,
   (void *) &opt, sizeof(int));
 if(bind(sock, (struct sockaddr *) &sa,
   sizeof(struct sockaddr_in)) == -1)
  return -1;
 return sock;
}

variable_types: port int

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

variable_types: opt 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 socket_udp_server(int a1)
{
int v1; // edx
int v2; // eax
unsigned int v3; // er12
int optval; // [rsp+Ch] [rbp-1Ch] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-18h] BYREF

if ( a1 < 0
|| (addr = 0LL, addr.sa_family = 2, *(_WORD *)addr.sa_data = _bswap_16(a1), v2 = socket(2, 2, v1), v3 = v2, v2 == -1)
|| (optval = 1, setsockopt(v2, 1, 2, &optval, 4u), bind(v3, &addr, 0x10u) == -1) )
{
v3 = -1;
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func16(int a1)
{
int v1; // edx
int v2; // eax
unsigned int v3; // er12
int optval; // [rsp+Ch] [rbp-1Ch] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-18h] BYREF

if ( a1 < 0
|| (addr = 0LL, addr.sa_family = 2, *(_WORD *)addr.sa_data = func0(a1), v2 = socket(2, 2, v1), v3 = v2, v2 == -1)
|| (optval = 1, setsockopt(v2, 1, 2, &optval, 4u), bind(v3, &addr, 0x10u) == -1) )
{
v3 = -1;
}
return v3;
}

original_code:
int
socket_udp_server(int port)
{
 struct sockaddr_in sa;
 int opt;
 int sock;
 if (port < 0)
  return -1;
 memset(&sa, 0, sizeof(sa));
 sa.sin_addr.s_addr = ((in_addr_t) 0x00000000);
 sa.sin_family = 2;
 sa.sin_port = htons(port);
 if ((sock = socket(2, SOCK_DGRAM,
   IPPROTO_UDP)) == -1)
  return -1;
 opt = 1;
 setsockopt(sock, 1, 2,
   (const void *) &opt, sizeof(int));
 if(bind(sock, (struct sockaddr *) &sa,
   sizeof(struct sockaddr_in)) == -1)
  return -1;
 return sock;
}

canonical_original_code:
int socket_udp_server(int port)
{
 struct sockaddr_in sa;
 int opt;
 int sock;
 if (port < 0)
  return -1;
 memset(&sa, 0, sizeof(sa));
 sa.sin_addr.s_addr = ((unsigned int) 0x00000000);
 sa.sin_family = 2;
 sa.sin_port = htons(port);
 if ((sock = socket(2, SOCK_DGRAM,
   IPPROTO_UDP)) == -1)
  return -1;
 opt = 1;
 setsockopt(sock, 1, 2,
   (void *) &opt, sizeof(int));
 if(bind(sock, (struct sockaddr *) &sa,
   sizeof(struct sockaddr_in)) == -1)
  return -1;
 return sock;
}


decompiled_code:
int __fastcall socket_listen(int a1)
{
return listen(a1, 128);
}

canonical_decompiled_code:
int __fastcall func17(int a1)
{
return listen(a1, 128);
}

original_code:
int
socket_listen(int serversock)
{
 return listen(serversock, 128);
}

variable_types: serversock int


decompiled_code:
__int64 __fastcall socket_accept(int a1)
{
unsigned int v1; // er12
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);
socket_set_no_linger(v1);
socket_set_keepalive(v1);
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func18(int a1)
{
unsigned int v1; // er12
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);
func7(v1);
func9(v1);
return v1;
}

original_code:
int
socket_accept(int serversock)
{
 int ret;
 struct sockaddr sa;
 socklen_t slen = sizeof(struct sockaddr);
 ret = accept(serversock, (struct sockaddr *) &sa, &slen);
 socket_set_no_linger(ret);
 socket_set_keepalive(ret);
 return ret;
}

canonical_original_code:
int socket_accept(int serversock)
{
 int ret;
 struct sockaddr sa;
 unsigned int slen = sizeof(struct sockaddr);
 ret = accept(serversock, (struct sockaddr *) &sa, &slen);
 socket_set_no_linger(ret);
 socket_set_keepalive(ret);
 return ret;
}

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

variable_types:
slen
unsigned int


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

server = (__int64)"KENNY Streaming Server";
*(&server + 107) = 0x40000000080LL;
result = 1LL;
*((_DWORD *)&server + 2) = 2;
*((_DWORD *)&server + 3) = 0;
*((_DWORD *)&server + 216) = -1;
config = 1000;
*((_WORD *)&config + 2) = 1;
*((_QWORD *)&config + 1) = "test.mp3";
*(&config + 8) = 1;
*((_WORD *)&config + 8) = 1337;
*((_QWORD *)&config + 3) = "lo";
return result;
}

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

server = (__int64)"KENNY Streaming Server";
*(&server + 107) = 0x40000000080LL;
result = 1LL;
*((_DWORD *)&server + 2) = 2;
*((_DWORD *)&server + 3) = 0;
*((_DWORD *)&server + 216) = -1;
config = 1000;
*((_WORD *)&config + 2) = 1;
*((_QWORD *)&config + 1) = "test.mp3";
*(&config + 8) = 1;
*((_WORD *)&config + 8) = 1337;
*((_QWORD *)&config + 3) = "lo";
return result;
}

original_code:
static void
main_initialize(void)
{
 server.name = "KENNY Streaming Server";
 server.status = 2;
 server.clients = 0;
 server.bitrate = 128;
 server.buffer_size = 1024;
 server.timeout = -1;
 config.max_clients = 1024 - 24;
 config.sockets_number = 1;
 config.streaming_file = "test.mp3";
 config.mode = 1;
 config.port = 1337;
 config.interface = "lo";
}

canonical_original_code:
static void main_initialize()
{
 server.name = "KENNY Streaming Server";
 server.status = 2;
 server.clients = 0;
 server.bitrate = 128;
 server.buffer_size = 1024;
 server.timeout = -1;
 config.max_clients = 1024 - 24;
 config.sockets_number = 1;
 config.streaming_file = "test.mp3";
 config.mode = 1;
 config.port = 1337;
 config.interface = "lo";
}


decompiled_code:
__int64 __fastcall parse_arguments(int argc, char **argv)
{
int v3; // eax
FILE *v4; // rcx
unsigned __int16 v5; // ax
FILE *v6; // rdi
char *v7; // rax
FILE *v8; // rdi

while ( 1 )
{
v3 = getopt(argc, argv, "hf:dp:");
if ( v3 == -1 )
break;
if ( v3 == 102 )
{
v7 = strdup(optarg);
v8 = stdout;
*((_QWORD *)&config + 1) = v7;
fprintf(v8, "[*] Archivo a servir: %s\n", v7);
}
else if ( v3 > 102 )
{
if ( v3 == 104 )
show_help_isra_0(*argv);
if ( v3 == 112 )
{
v5 = atoi(optarg);
v6 = stdout;
*((_WORD *)&config + 8) = v5;
fprintf(v6, "[*] Escuchando en el puerto %d\n", v5);
}
}
else
{
if ( v3 == 63 )
{
fwrite("[!] Opcion invalida\n", 1uLL, 0x14uLL, stderr);
return 0xFFFFFFFFLL;
}
if ( v3 == 100 )
{
v4 = stdout;
*(&config + 8) = 0;
fwrite("[*] Corriendo en modo daemon\n", 1uLL, 0x1DuLL, v4);
}
}
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(int argc, char **argv)
{
int v3; // eax
FILE *v4; // rcx
unsigned __int16 v5; // ax
FILE *v6; // rdi
char *v7; // rax
FILE *v8; // rdi

while ( 1 )
{
v3 = getopt(argc, argv, "hf:dp:");
if ( v3 == -1 )
break;
if ( v3 == 102 )
{
v7 = strdup(optarg);
v8 = stdout;
*((_QWORD *)&config + 1) = v7;
fprintf(v8, "[*] Archivo a servir: %s\n", v7);
}
else if ( v3 > 102 )
{
if ( v3 == 104 )
func1(*argv);
if ( v3 == 112 )
{
v5 = atoi(optarg);
v6 = stdout;
*((_WORD *)&config + 8) = v5;
fprintf(v6, "[*] Escuchando en el puerto %d\n", v5);
}
}
else
{
if ( v3 == 63 )
{
fwrite("[!] Opcion invalida\n", 1uLL, 0x14uLL, stderr);
return 0xFFFFFFFFLL;
}
if ( v3 == 100 )
{
v4 = stdout;
*(&config + 8) = 0;
fwrite("[*] Corriendo en modo daemon\n", 1uLL, 0x1DuLL, v4);
}
}
}
return 0LL;
}

original_code:
static int
parse_arguments(int argc, char **argv)
{
 int c;
 while((c = getopt(argc, argv, "hf:dp:")) != -1)
 {
  switch(c)
  {
   case 'h':
    show_help(argv);
    break;
   case 'f':
    config.streaming_file = strdup(optarg);
    fprintf(stdout, "[*] Archivo a servir: %s\n", config.streaming_file);
    break;
   case 'd':
    config.mode = 0;
    fprintf(stdout, "[*] Corriendo en modo daemon\n");
    break;
   case 'p':
    config.port = (unsigned short) atoi(optarg);
    fprintf(stdout, "[*] Escuchando en el puerto %d\n", config.port);
    break;
   case '?':
    fprintf(stderr, "[!] Opcion invalida\n");
    return -1;
   default:
    break;
  }
 }
 return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types: c int


decompiled_code:
__int64 main_daemonize()
{
__pid_t v0; // eax
unsigned int v1; // er12
int v2; // ebp
int i; // ebx
int v4; // edi

v0 = fork();
if ( v0 == -1 )
goto LABEL_10;
v1 = v0;
if ( v0 )
exit(0);
if ( setsid() == -1 )
{
LABEL_10:
v1 = -1;
perror("main_daemonize():");
}
else
{
chdir("/");
v2 = sysconf(4);
if ( v2 > 0 )
{
for ( i = 0; i != v2; ++i )
{
v4 = i;
close(v4);
}
}
umask(0x3Fu);
open("/dev/null", 0);
open("/dev/null", 2);
open("/dev/null", 2);
}
return v1;
}

canonical_decompiled_code:
__int64 func3()
{
__pid_t v0; // eax
unsigned int v1; // er12
int v2; // ebp
int i; // ebx
int v4; // edi

v0 = fork();
if ( v0 == -1 )
goto LABEL_10;
v1 = v0;
if ( v0 )
exit(0);
if ( setsid() == -1 )
{
LABEL_10:
v1 = -1;
perror("main_daemonize():");
}
else
{
chdir("/");
v2 = sysconf(4);
if ( v2 > 0 )
{
for ( i = 0; i != v2; ++i )
{
v4 = i;
close(v4);
}
}
umask(0x3Fu);
open("/dev/null", 0);
open("/dev/null", 2);
open("/dev/null", 2);
}
return v1;
}

original_code:
int
main_daemonize(void)
{
 pid_t pid;
 int i;
 pid = fork();
 if(pid == -1)
 {
  perror("main_daemonize():");
  return -1;
 }
 else if(pid)
 {
  _exit(0);
 }
 if(setsid() == -1)
 {
  perror("main_daemonize():");
  return -1;
 }
 chdir("/");
 int maxfd = sysconf(_SC_OPEN_MAX);
 for (i = 0; i < maxfd; i++)
   close(i);
 umask(077);
 open("/dev/null", 00);
 open("/dev/null", 02);
 open("/dev/null", 02);
 return 0;
}

canonical_original_code:
int main_daemonize()
{
 int pid;
 int i;
 pid = fork();
 if(pid == -1)
 {
  perror("main_daemonize():");
  return -1;
 }
 else if(pid)
 {
  _exit(0);
 }
 if(setsid() == -1)
 {
  perror("main_daemonize():");
  return -1;
 }
 chdir("/");
 int maxfd = sysconf(_SC_OPEN_MAX);
 for (i = 0; i < maxfd; i++)
   close(i);
 umask(077);
 open("/dev/null", 00);
 open("/dev/null", 02);
 open("/dev/null", 02);
 return 0;
}

variable_types: pid int

variable_types: i int

variable_types: maxfd int


main

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

main_initialize(argc, argv, envp);
if ( (unsigned int)parse_arguments(argc, (char **)argv) == -1 )
{
v3 = -1;
fwrite("[!] Error parseando argumentos.\n", 1uLL, 0x20uLL, stderr);
}
else if ( *(&config + 8) || (v3 = main_daemonize(), v3 != -1) )
{
v3 = signal_initialize();
if ( v3 == -1 )
{
fwrite("[!] Error seteando manejadores de seniales\n", 1uLL, 0x2BuLL, stderr);
}
else
{
fwrite("[*] Inicializando el servidor\n", 1uLL, 0x1EuLL, stdout);
v3 = stream_create((unsigned int)((_DWORD)server + 24), *((_QWORD *)&config + 1));
if ( v3 == -1 )
{
fwrite("[!] Error inicializando el stream de bytes\n", 1uLL, 0x2BuLL, stderr);
}
else
{
v3 = server_initialize();
if ( v3 == -1 )
{
fwrite("[!] No se pudo inicializar el servidor.\n", 1uLL, 0x28uLL, stderr);
stream_destroy(server[3]);
}
else
{
v3 = client_initialize((unsigned int)config);
if ( v3 == -1 )
{
fwrite("[!] No se pudo inicializar el subsistema de clientes.\n", 1uLL, 0x36uLL, stderr);
stream_destroy(server[3]);
server_shutdown();
}
else
{
fwrite("[*] Entrando en el loop de eventos\n", 1uLL, 0x23uLL, stdout);
v3 = server_enter_event_loop();
if ( v3 == -1 )
{
fwrite("[!] No se pudo entrar en el loop de eventos.\n", 1uLL, 0x2DuLL, stderr);
stream_destroy(server[3]);
server_shutdown();
}
else
{
fwrite("[*] Cerrando el servidor\n", 1uLL, 0x19uLL, stdout);
stream_destroy(server[3]);
v3 = server_shutdown();
if ( v3 == -1 )
fwrite("[!] Cierre inconcluso del servidor, verifique los logs.\n", 1uLL, 0x38uLL, stderr);
else
v3 = 0;
}
}
}
}
}
}
else
{
fwrite("[!] No se pudo inicializar el servidor como demonio\n", 1uLL, 0x34uLL, stderr);
}
return v3;
}

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

func0(argc, argv, envp);
if ( (unsigned int)func2(argc, (char **)argv) == -1 )
{
v3 = -1;
fwrite("[!] Error parseando argumentos.\n", 1uLL, 0x20uLL, stderr);
}
else if ( *(&config + 8) || (v3 = func3(), v3 != -1) )
{
v3 = signal_initialize();
if ( v3 == -1 )
{
fwrite("[!] Error seteando manejadores de seniales\n", 1uLL, 0x2BuLL, stderr);
}
else
{
fwrite("[*] Inicializando el servidor\n", 1uLL, 0x1EuLL, stdout);
v3 = stream_create((unsigned int)((_DWORD)server + 24), *((_QWORD *)&config + 1));
if ( v3 == -1 )
{
fwrite("[!] Error inicializando el stream de bytes\n", 1uLL, 0x2BuLL, stderr);
}
else
{
v3 = server_initialize();
if ( v3 == -1 )
{
fwrite("[!] No se pudo inicializar el servidor.\n", 1uLL, 0x28uLL, stderr);
stream_destroy(server[3]);
}
else
{
v3 = client_initialize((unsigned int)config);
if ( v3 == -1 )
{
fwrite("[!] No se pudo inicializar el subsistema de clientes.\n", 1uLL, 0x36uLL, stderr);
stream_destroy(server[3]);
server_shutdown();
}
else
{
fwrite("[*] Entrando en el loop de eventos\n", 1uLL, 0x23uLL, stdout);
v3 = server_enter_event_loop();
if ( v3 == -1 )
{
fwrite("[!] No se pudo entrar en el loop de eventos.\n", 1uLL, 0x2DuLL, stderr);
stream_destroy(server[3]);
server_shutdown();
}
else
{
fwrite("[*] Cerrando el servidor\n", 1uLL, 0x19uLL, stdout);
stream_destroy(server[3]);
v3 = server_shutdown();
if ( v3 == -1 )
fwrite("[!] Cierre inconcluso del servidor, verifique los logs.\n", 1uLL, 0x38uLL, stderr);
else
v3 = 0;
}
}
}
}
}
}
else
{
fwrite("[!] No se pudo inicializar el servidor como demonio\n", 1uLL, 0x34uLL, stderr);
}
return v3;
}

original_code:
int
main(int argc, char **argv)
{
 main_initialize();
 if(parse_arguments(argc, argv) == -1)
 {
  fprintf(stderr, "[!] Error parseando argumentos.\n");
  return -1;
 }
 if(config.mode == 0)
 {
  if(main_daemonize() == -1)
  {
   fprintf(stderr, "[!] No se pudo inicializar el servidor como demonio\n");
   return -1;
  }
 }
 if(signal_initialize() == -1)
 {
  fprintf(stderr, "[!] Error seteando manejadores de seniales\n");
  return -1;
 }
 fprintf(stdout, "[*] Inicializando el servidor\n");
 if(stream_create(&server.stream, config.streaming_file) == -1)
 {
  fprintf(stderr, "[!] Error inicializando el stream de bytes\n");
  return -1;
 }
 if(server_initialize() == -1)
 {
  fprintf(stderr, "[!] No se pudo inicializar el servidor.\n");
  stream_destroy(server.stream);
  return -1;
 }
 if(client_initialize(config.max_clients) == -1)
 {
  fprintf(stderr, "[!] No se pudo inicializar el subsistema de clientes.\n");
  stream_destroy(server.stream);
  server_shutdown();
  return -1;
 }
 fprintf(stdout, "[*] Entrando en el loop de eventos\n");
 if(server_enter_event_loop() == -1)
 {
  fprintf(stderr, "[!] No se pudo entrar en el loop de eventos.\n");
  stream_destroy(server.stream);
  server_shutdown();
  return -1;
 }
 fprintf(stdout, "[*] Cerrando el servidor\n");
 stream_destroy(server.stream);
 if(server_shutdown() == -1)
 {
  fprintf(stderr, "[!] Cierre inconcluso del servidor, verifique los logs.\n");
  return -1;
 }
 return 0;
}


decompiled_code:
// attributes: thunk
__int64 signal_handler()
{
return server_leave_event_loop();
}

canonical_decompiled_code:
__int64 func0()
{
return server_leave_event_loop();
}

original_code:
void
signal_handler(__attribute__ ((__unused__)) int sig)
{
 server_leave_event_loop();
}

canonical_original_code:
void signal_handler(int sig)
{
 server_leave_event_loop();
}

variable_types: sig int


decompiled_code:
__int64 signal_initialize()
{
bool v0; // zf
void (*v1)(int); // rax
struct sigaction v3; // [rsp+0h] [rbp-A8h] BYREF

sigemptyset(&v3.sa_mask);
v0 = config[8] == 1;
v1 = (void (*)(int))signal_handler;
v3.sa_flags = 0;
if ( !v0 )
v1 = (void (*)(int))(signal_handler + 1);
v3.sa_handler = v1;
if ( sigaction(2, &v3, 0LL) != -1 )
{
v3.sa_handler = (__sighandler_t)signal_handler;
if ( sigaction(15, &v3, 0LL) != -1 )
{
v3.sa_handler = (__sighandler_t)(signal_handler + 1);
if ( sigaction(1, &v3, 0LL) != -1 && sigaction(3, &v3, 0LL) != -1 )
return 0LL;
}
}
perror("signal_initialize():");
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 func1()
{
bool v0; // zf
void (*v1)(int); // rax
struct sigaction v3; // [rsp+0h] [rbp-A8h] BYREF

sigemptyset(&v3.sa_mask);
v0 = config[8] == 1;
v1 = (void (*)(int))signal_handler;
v3.sa_flags = 0;
if ( !v0 )
v1 = (void (*)(int))(signal_handler + 1);
v3.sa_handler = v1;
if ( sigaction(2, &v3, 0LL) != -1 )
{
v3.sa_handler = (__sighandler_t)signal_handler;
if ( sigaction(15, &v3, 0LL) != -1 )
{
v3.sa_handler = (__sighandler_t)(signal_handler + 1);
if ( sigaction(1, &v3, 0LL) != -1 && sigaction(3, &v3, 0LL) != -1 )
return 0LL;
}
}
perror("signal_initialize():");
return 0xFFFFFFFFLL;
}

original_code:
int
signal_initialize(void)
{
 struct sigaction action;
 sigemptyset (&action.sa_mask);
 action.sa_flags = 0;
 action.__sigaction_handler.sa_handler = (config.mode == 1) ? &signal_handler : ((__sighandler_t) 1);
 if(sigaction (2, &action, ((void *)0)) == -1)
 {
  perror("signal_initialize():");
  return -1;
 }
 action.__sigaction_handler.sa_handler = &signal_handler;
 if(sigaction (15, &action, ((void *)0)) == -1)
 {
  perror("signal_initialize():");
  return -1;
 }
 action.__sigaction_handler.sa_handler = ((__sighandler_t) 1);
 if(sigaction (1, &action, ((void *)0)) == -1)
 {
  perror("signal_initialize():");
  return -1;
 }
 if(sigaction (3, &action, ((void *)0)) == -1)
 {
  perror("signal_initialize():");
  return -1;
 }
 return 0;
}

canonical_original_code:
int signal_initialize()
{
 struct sigaction action;
 sigemptyset (&action.sa_mask);
 action.sa_flags = 0;
 action.__sigaction_handler.sa_handler = (config.mode == 1) ? &signal_handler : ((void (*)(int)) 1);
 if(sigaction (2, &action, ((void *)0)) == -1)
 {
  perror("signal_initialize():");
  return -1;
 }
 action.__sigaction_handler.sa_handler = &signal_handler;
 if(sigaction (15, &action, ((void *)0)) == -1)
 {
  perror("signal_initialize():");
  return -1;
 }
 action.__sigaction_handler.sa_handler = ((void (*)(int)) 1);
 if(sigaction (1, &action, ((void *)0)) == -1)
 {
  perror("signal_initialize():");
  return -1;
 }
 if(sigaction (3, &action, ((void *)0)) == -1)
 {
  perror("signal_initialize():");
  return -1;
 }
 return 0;
}

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


decompiled_code:
_BOOL8 server_running()
{
return server[2] == 1;
}

canonical_decompiled_code:
_BOOL8 func0()
{
return server[2] == 1;
}

original_code:
static int
server_running(void)
{
 return server.status == 1;
}

canonical_original_code:
static int server_running()
{
 return server.status == 1;
}


decompiled_code:
__int64 __fastcall connection_accept_handler(__int64 a1, unsigned int *a2)
{
unsigned int v2; // eax
unsigned int v3; // ebp
unsigned int v4; // er12
__int64 v6[4]; // [rsp+8h] [rbp-20h] BYREF

v2 = socket_accept(*a2);
if ( v2 == -1 )
{
v4 = -1;
perror("connection_accept_handler():");
return v4;
}
v3 = v2;
if ( server[3] != config )
{
v4 = client_create(v6, v2);
if ( v4 == -1 )
{
fwrite("connection_accept_handler(): Error creando cliente\n", 1uLL, 0x33uLL, stderr);
socket_close(v3);
}
else
{
v4 = event_add(a1, v3, connection_client_handler, 3LL);
if ( v4 == -1 )
{
fwrite("connection_accept_handler(): Error seteando el event handler\n", 1uLL, 0x3DuLL, stderr);
client_destroy(v6[0]);
socket_close(v3);
--server[3];
}
else
{
++server[3];
v4 = 0;
}
}
return v4;
}
fwrite("connection_accept_handler(): Guarda! Se llego al limite de clientes\n", 1uLL, 0x44uLL, stdout);
socket_close(v3);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, unsigned int *a2)
{
unsigned int v2; // eax
unsigned int v3; // ebp
unsigned int v4; // er12
__int64 v6[4]; // [rsp+8h] [rbp-20h] BYREF

v2 = socket_accept(*a2);
if ( v2 == -1 )
{
v4 = -1;
perror("connection_accept_handler():");
return v4;
}
v3 = v2;
if ( server[3] != config )
{
v4 = client_create(v6, v2);
if ( v4 == -1 )
{
fwrite("connection_accept_handler(): Error creando cliente\n", 1uLL, 0x33uLL, stderr);
socket_close(v3);
}
else
{
v4 = event_add(a1, v3, connection_client_handler, 3LL);
if ( v4 == -1 )
{
fwrite("connection_accept_handler(): Error seteando el event handler\n", 1uLL, 0x3DuLL, stderr);
client_destroy(v6[0]);
socket_close(v3);
--server[3];
}
else
{
++server[3];
v4 = 0;
}
}
return v4;
}
fwrite("connection_accept_handler(): Guarda! Se llego al limite de clientes\n", 1uLL, 0x44uLL, stdout);
socket_close(v3);
return 0LL;
}

original_code:
int
connection_accept_handler(events_t *ev, event_t *event)
{
 int client_fd;
 client_t *c;
 if((client_fd = socket_accept(event->fd)) == -1)
 {
  perror("connection_accept_handler():");
  return -1;
 }
 if(server.clients == config.max_clients)
 {
  fprintf(stdout, "connection_accept_handler(): Guarda! Se llego al limite de clientes\n");
  socket_close(client_fd);
  return 0;
 }
 if(client_create(&c, client_fd) == -1)
 {
  fprintf(stderr, "connection_accept_handler(): Error creando cliente\n");
  socket_close(client_fd);
  return -1;
 }
 if(event_add(ev, client_fd, &connection_client_handler,
   1 | 2) == -1)
 {
  fprintf(stderr, "connection_accept_handler(): Error seteando el event handler\n");
  client_destroy(c);
  socket_close(client_fd);
  server.clients--;
  return -1;
 }
 server.clients++;
 return 0;
}

canonical_original_code:
int connection_accept_handler(struct events *ev, struct event *event)
{
 int client_fd;
 struct client_t *c;
 if((client_fd = socket_accept(event->fd)) == -1)
 {
  perror("connection_accept_handler():");
  return -1;
 }
 if(server.clients == config.max_clients)
 {
  fprintf(stdout, "connection_accept_handler(): Guarda! Se llego al limite de clientes\n");
  socket_close(client_fd);
  return 0;
 }
 if(client_create(&c, client_fd) == -1)
 {
  fprintf(stderr, "connection_accept_handler(): Error creando cliente\n");
  socket_close(client_fd);
  return -1;
 }
 if(event_add(ev, client_fd, &connection_client_handler,
   1 | 2) == -1)
 {
  fprintf(stderr, "connection_accept_handler(): Error seteando el event handler\n");
  client_destroy(c);
  socket_close(client_fd);
  server.clients--;
  return -1;
 }
 server.clients++;
 return 0;
}

variable_types: struct events { int (**handlers)(struct events *ev, struct event { int fd; int (*handler)(struct events *ev, struct event *event); int event_mask; } *event); unsigned long maxfds; int currfd; struct fd_set { long fds_bits[-1]; } set_read_copy; struct fd_set set_write_copy; struct fd_set set_error_copy; struct fd_set set_read; struct fd_set set_write; struct fd_set set_error; int max_fd; int nevents; int has_timeout; struct timeval { long tv_sec; long tv_usec; } tv; } *

variable_types:
event
struct event *

variable_types: struct client_t { int connection_fd; char *name; unsigned int id; unsigned int offset; int state; } *

user_defined_types: struct events { int (**handlers)(struct events *ev, struct event *event); unsigned long maxfds; int currfd; struct fd_set set_read_copy; struct fd_set set_write_copy; struct fd_set set_error_copy; struct fd_set set_read; struct fd_set set_write; struct fd_set set_error; int max_fd; int nevents; int has_timeout; struct timeval tv; }


decompiled_code:
__int64 server_enter_event_loop()
{
unsigned int v0; // er12
int v1; // ebx
_QWORD v3[7]; // [rsp+0h] [rbp-38h] BYREF

server[2] = 1;
if ( (unsigned int)event_initialize((unsigned int)((_DWORD)server + 32)) == -1 )
{
v0 = -1;
fwrite("server_enter_event_loop(): Error inicializando el monitor de eventos\n", 1uLL, 0x45uLL, stderr);
}
else
{
v0 = event_add((unsigned int)((_DWORD)server + 32), (unsigned int)server[4], connection_accept_handler, 1LL);
if ( v0 == -1 )
{
fwrite("server_enter_event_loop(): Error seteando el event handler\n", 1uLL, 0x3BuLL, stderr);
event_shutdown((unsigned int)((_DWORD)server + 32));
}
else
{
if ( server_running() )
{
while ( 1 )
{
v1 = event_wait((unsigned int)((_DWORD)server + 32), (unsigned int)server[216]);
if ( v1 == -1 )
break;
while ( v1 > 0 )
{
v1 -= event_next((unsigned int)((_DWORD)server + 32), v3);
((void (__fastcall *)(_QWORD, _QWORD *))v3[1])((unsigned int)((_DWORD)server + 32), v3);
}
fprintf(stdout, "\r[*] Numero de clientes = %d", (unsigned int)server[3]);
if ( !server_running() )
goto LABEL_9;
}
fwrite("server_enter_event_loop(): Error esperando por eventos\n", 1uLL, 0x37uLL, stderr);
}
LABEL_9:
v0 = 0;
putchar(10);
event_shutdown((unsigned int)((_DWORD)server + 32));
}
}
return v0;
}

canonical_decompiled_code:
__int64 func3()
{
unsigned int v0; // er12
int v1; // ebx
_QWORD v3[7]; // [rsp+0h] [rbp-38h] BYREF

server[2] = 1;
if ( (unsigned int)event_initialize((unsigned int)((_DWORD)server + 32)) == -1 )
{
v0 = -1;
fwrite("server_enter_event_loop(): Error inicializando el monitor de eventos\n", 1uLL, 0x45uLL, stderr);
}
else
{
v0 = event_add((unsigned int)((_DWORD)server + 32), (unsigned int)server[4], connection_accept_handler, 1LL);
if ( v0 == -1 )
{
fwrite("server_enter_event_loop(): Error seteando el event handler\n", 1uLL, 0x3BuLL, stderr);
event_shutdown((unsigned int)((_DWORD)server + 32));
}
else
{
if ( func0() )
{
while ( 1 )
{
v1 = event_wait((unsigned int)((_DWORD)server + 32), (unsigned int)server[216]);
if ( v1 == -1 )
break;
while ( v1 > 0 )
{
v1 -= event_next((unsigned int)((_DWORD)server + 32), v3);
((void (__fastcall *)(_QWORD, _QWORD *))v3[1])((unsigned int)((_DWORD)server + 32), v3);
}
fprintf(stdout, "\r[*] Numero de clientes = %d", (unsigned int)server[3]);
if ( !func0() )
goto LABEL_9;
}
fwrite("server_enter_event_loop(): Error esperando por eventos\n", 1uLL, 0x37uLL, stderr);
}
LABEL_9:
v0 = 0;
putchar(10);
event_shutdown((unsigned int)((_DWORD)server + 32));
}
}
return v0;
}

original_code:
int
server_enter_event_loop(void)
{
 int nevents;
 event_t event;
 server.status = 1;
 if(event_initialize(&server.ev) == -1)
 {
  fprintf(stderr, "server_enter_event_loop(): Error inicializando el monitor de eventos\n");
  return -1;
 }
 if(event_add(&server.ev, server.server_fd,
   &connection_accept_handler, 1) == -1)
 {
  fprintf(stderr, "server_enter_event_loop(): Error seteando el event handler\n");
  event_shutdown(&server.ev);
  return -1;
 }
 while(server_running())
 {
     nevents = event_wait(&server.ev, server.timeout);
     if(nevents == -1)
     {
      fprintf(stderr, "server_enter_event_loop(): Error esperando por eventos\n");
      break;
     }
     while(nevents > 0)
     {
      nevents -= event_next(&server.ev, &event);
      event.handler(&server.ev, &event);
     }
     fprintf(stdout, "\r[*] Numero de clientes = %d", server.clients);
 }
 printf("\n");
 event_shutdown(&server.ev);
 return 0;
}

canonical_original_code:
int server_enter_event_loop()
{
 int nevents;
 struct event event;
 server.status = 1;
 if(event_initialize(&server.ev) == -1)
 {
  fprintf(stderr, "server_enter_event_loop(): Error inicializando el monitor de eventos\n");
  return -1;
 }
 if(event_add(&server.ev, server.server_fd,
   &connection_accept_handler, 1) == -1)
 {
  fprintf(stderr, "server_enter_event_loop(): Error seteando el event handler\n");
  event_shutdown(&server.ev);
  return -1;
 }
 while(server_running())
 {
     nevents = event_wait(&server.ev, server.timeout);
     if(nevents == -1)
     {
      fprintf(stderr, "server_enter_event_loop(): Error esperando por eventos\n");
      break;
     }
     while(nevents > 0)
     {
      nevents -= event_next(&server.ev, &event);
      event.handler(&server.ev, &event);
     }
     fprintf(stdout, "\r[*] Numero de clientes = %d", server.clients);
 }
 printf("\n");
 event_shutdown(&server.ev);
 return 0;
}

variable_types: nevents int

variable_types: struct event { int fd; int (*handler)(struct events { int (**handlers)(struct events *ev, struct event *event); unsigned long maxfds; int currfd; struct fd_set { long fds_bits[-1]; } set_read_copy; struct fd_set set_write_copy; struct fd_set set_error_copy; struct fd_set set_read; struct fd_set set_write; struct fd_set set_error; int max_fd; int nevents; int has_timeout; struct timeval { long tv_sec; long tv_usec; } tv; } *ev, struct event *event); int event_mask; }

user_defined_types: struct event { int fd; int (*handler)(struct events *ev, struct event *event); int event_mask; }


decompiled_code:
__int64 server_leave_event_loop()
{
server[2] = 0;
return 0LL;
}

canonical_decompiled_code:
__int64 func4()
{
server[2] = 0;
return 0LL;
}

original_code:
int
server_leave_event_loop(void)
{
 server.status = 0;
 return 0;
}

canonical_original_code:
int server_leave_event_loop()
{
 server.status = 0;
 return 0;
}


decompiled_code:
__int64 server_initialize()
{
unsigned int v0; // eax
unsigned int v1; // er12
__int64 v3; // rdi

v0 = socket_tcp_server(config[8]);
v1 = v0;
if ( v0 == -1 )
{
perror("server_initialize():");
}
else
{
if ( (unsigned int)socket_set_nonblocking(v0) )
perror("server_initialize():");
if ( (unsigned int)socket_listen(v1) == -1 )
{
perror("server_initialize():");
v3 = v1;
v1 = -1;
socket_close(v3);
}
else
{
server[4] = v1;
v1 = 0;
}
}
return v1;
}

canonical_decompiled_code:
__int64 func5()
{
unsigned int v0; // eax
unsigned int v1; // er12
__int64 v3; // rdi

v0 = socket_tcp_server(config[8]);
v1 = v0;
if ( v0 == -1 )
{
perror("server_initialize():");
}
else
{
if ( (unsigned int)socket_set_nonblocking(v0) )
perror("server_initialize():");
if ( (unsigned int)socket_listen(v1) == -1 )
{
perror("server_initialize():");
v3 = v1;
v1 = -1;
socket_close(v3);
}
else
{
server[4] = v1;
v1 = 0;
}
}
return v1;
}

original_code:
int
server_initialize(void)
{
 int server_fd;
 server_fd = socket_tcp_server(config.port);
 if(server_fd == -1)
 {
  perror("server_initialize():");
  return -1;
 }
 if(socket_set_nonblocking(server_fd))
 {
  perror("server_initialize():");
 }
 if(socket_listen(server_fd) == -1)
 {
  perror("server_initialize():");
  socket_close(server_fd);
  return -1;
 }
 server.server_fd = server_fd;
 return 0;
}

canonical_original_code:
int server_initialize()
{
 int server_fd;
 server_fd = socket_tcp_server(config.port);
 if(server_fd == -1)
 {
  perror("server_initialize():");
  return -1;
 }
 if(socket_set_nonblocking(server_fd))
 {
  perror("server_initialize():");
 }
 if(socket_listen(server_fd) == -1)
 {
  perror("server_initialize():");
  socket_close(server_fd);
  return -1;
 }
 server.server_fd = server_fd;
 return 0;
}


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

socket_close((unsigned int)server[4]);
result = 0LL;
server[4] = -1;
return result;
}

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

socket_close((unsigned int)server[4]);
result = 0LL;
server[4] = -1;
return result;
}

original_code:
int
server_shutdown(void)
{
 socket_close(server.server_fd);
 server.server_fd = -1;
 return 0;
}

canonical_original_code:
int server_shutdown()
{
 socket_close(server.server_fd);
 server.server_fd = -1;
 return 0;
}


decompiled_code:
__int64 __fastcall event_reset(_DWORD *a1)
{
__int64 result; // rax

result = 0LL;
memset(a1 + 102, 0, 0x80uLL);
memset(a1 + 134, 0, 0x80uLL);
memset(a1 + 166, 0, 0x80uLL);
a1[198] = -1;
return result;
}

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

result = 0LL;
memset(a1 + 102, 0, 0x80uLL);
memset(a1 + 134, 0, 0x80uLL);
memset(a1 + 166, 0, 0x80uLL);
a1[198] = -1;
return result;
}

variable_types: struct events { int (**handlers)(struct events *ev, struct event { int fd; int (*handler)(struct events *ev, struct event *event); int event_mask; } *event); unsigned long maxfds; int currfd; struct fd_set { long __fds_bits[-1]; } set_read_copy; struct fd_set set_write_copy; struct fd_set set_error_copy; struct fd_set set_read; struct fd_set set_write; struct fd_set set_error; int max_fd; int nevents; int has_timeout; struct timeval { long tv_sec; long tv_usec; } tv; } *


decompiled_code:
__int64 __fastcall event_initialize(__int64 a1)
{
void *v1; // rax
__int64 result; // rax

*(_DWORD *)(a1 + 16) = -1;
*(_QWORD *)(a1 + 8) = 1000LL;
*(_QWORD *)(a1 + 792) = 0xFFFFFFFFLL;
v1 = calloc(0x3E8uLL, 8uLL);
*(_QWORD *)a1 = v1;
if ( v1 )
{
event_reset((_DWORD *)a1);
result = 0LL;
}
else
{
perror("event_initialize():");
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
void *v1; // rax
__int64 result; // rax

*(_DWORD *)(a1 + 16) = -1;
*(_QWORD *)(a1 + 8) = 1000LL;
*(_QWORD *)(a1 + 792) = 0xFFFFFFFFLL;
v1 = calloc(0x3E8uLL, 8uLL);
*(_QWORD *)a1 = v1;
if ( v1 )
{
func0((_DWORD *)a1);
result = 0LL;
}
else
{
perror("event_initialize():");
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
int
event_initialize(events_t *ev)
{
 ev->currfd = -1;
 ev->maxfds = 1024 - 24;
 ev->max_fd = -1;
 ev->nevents = 0;
 ev->handlers = (handler_t *) calloc(ev->maxfds, sizeof(handler_t));
 if(ev->handlers == ((void *)0))
 {
  perror("event_initialize():");
  return -1;
 }
 event_reset(ev);
 return 0;
}

canonical_original_code:
int event_initialize(struct events *ev)
{
 ev->currfd = -1;
 ev->maxfds = 1024 - 24;
 ev->max_fd = -1;
 ev->nevents = 0;
 ev->handlers = (int (**)(struct events *ev, struct event *event)) calloc(ev->maxfds, sizeof(handler_t));
 if(ev->handlers == ((void *)0))
 {
  perror("event_initialize():");
  return -1;
 }
 event_reset(ev);
 return 0;
}

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


decompiled_code:
__int64 __fastcall event_shutdown(__int64 a1)
{
void *v2; // rdi

v2 = *(void **)a1;
if ( v2 )
free(v2);
event_reset((_DWORD *)a1);
*(_DWORD *)(a1 + 16) = -1;
*(_QWORD *)(a1 + 792) = 0xFFFFFFFFLL;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
void *v2; // rdi

v2 = *(void **)a1;
if ( v2 )
free(v2);
func0((_DWORD *)a1);
*(_DWORD *)(a1 + 16) = -1;
*(_QWORD *)(a1 + 792) = 0xFFFFFFFFLL;
return 0LL;
}

original_code:
int
event_shutdown(events_t *ev)
{
 if(ev->handlers)
  free(ev->handlers);
 event_reset(ev);
 ev->currfd = -1;
 ev->max_fd = -1;
 ev->nevents = 0;
 return 0;
}

canonical_original_code:
int event_shutdown(struct events *ev)
{
 if(ev->handlers)
  free(ev->handlers);
 event_reset(ev);
 ev->currfd = -1;
 ev->max_fd = -1;
 ev->nevents = 0;
 return 0;
}


original_code:
void
event_set_mask(events_t *ev, int fd, int event_mask)
{
 ((void) (((&(ev->set_read))->__fds_bits)[((fd) / (8 * (int) sizeof (__fd_mask)))] &= ~((__fd_mask) (1UL << ((fd) % (8 * (int) sizeof (__fd_mask)))))));
 if (event_mask & 1)
  ((void) (((&(ev->set_read))->__fds_bits)[((fd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((fd) % (8 * (int) sizeof (__fd_mask)))))));
 ((void) (((&(ev->set_write))->__fds_bits)[((fd) / (8 * (int) sizeof (__fd_mask)))] &= ~((__fd_mask) (1UL << ((fd) % (8 * (int) sizeof (__fd_mask)))))));
 if (event_mask & 2)
  ((void) (((&(ev->set_write))->__fds_bits)[((fd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((fd) % (8 * (int) sizeof (__fd_mask)))))));
 ((void) (((&(ev->set_error))->__fds_bits)[((fd) / (8 * (int) sizeof (__fd_mask)))] &= ~((__fd_mask) (1UL << ((fd) % (8 * (int) sizeof (__fd_mask)))))));
 if (event_mask & 4)
  ((void) (((&(ev->set_error))->__fds_bits)[((fd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((fd) % (8 * (int) sizeof (__fd_mask)))))));
}

canonical_original_code:
void event_set_mask(struct events *ev, int fd, int event_mask)
{
 ((void) (((&(ev->set_read))->__fds_bits)[((fd) / (8 * (int) sizeof (__fd_mask)))] &= ~((__fd_mask) (1UL << ((fd) % (8 * (int) sizeof (__fd_mask)))))));
 if (event_mask & 1)
  ((void) (((&(ev->set_read))->__fds_bits)[((fd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((fd) % (8 * (int) sizeof (__fd_mask)))))));
 ((void) (((&(ev->set_write))->__fds_bits)[((fd) / (8 * (int) sizeof (__fd_mask)))] &= ~((__fd_mask) (1UL << ((fd) % (8 * (int) sizeof (__fd_mask)))))));
 if (event_mask & 2)
  ((void) (((&(ev->set_write))->__fds_bits)[((fd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((fd) % (8 * (int) sizeof (__fd_mask)))))));
 ((void) (((&(ev->set_error))->__fds_bits)[((fd) / (8 * (int) sizeof (__fd_mask)))] &= ~((__fd_mask) (1UL << ((fd) % (8 * (int) sizeof (__fd_mask)))))));
 if (event_mask & 4)
  ((void) (((&(ev->set_error))->__fds_bits)[((fd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((fd) % (8 * (int) sizeof (__fd_mask)))))));
}

variable_types: fd int


decompiled_code:
__int64 __fastcall event_del(_QWORD *a1, int a2)
{
__int64 *v2; // r9
int v3; // er10
__int64 *v4; // rdx
__int64 v5; // rax
int v6; // ecx
__int64 v7; // rdx
__int64 v8; // r11
__int64 v9; // rax
__int64 result; // rax

if ( a2 < 0 || (unsigned __int64)a2 >= a1[1] )
{
fprintf(stderr, "event_del(fd=%d): fd out of range\n", (unsigned int)a2);
result = 0xFFFFFFFFLL;
}
else if ( *(_QWORD *)(*a1 + 8LL * a2) )
{
event_set_mask((__int64)a1, a2, 0);
v4 = &v2[v3 >> 6];
v5 = ~(1LL << v3);
v4[3] &= v5;
v4[19] &= v5;
v4[35] &= v5;
v6 = *((_DWORD *)v2 + 198);
v7 = *v2;
*(_QWORD *)(*v2 + 8 * v8) = 0LL;
v9 = v6 - 1;
if ( v6 >= 0 )
{
do
{
if ( *(_QWORD *)(v7 + 8 * v9 + 8) )
break;
*((_DWORD *)v2 + 198) = v9--;
}
while ( v9 != -2 );
}
result = 0LL;
}
else
{
fprintf(stderr, "event_del(fd=%d): not monitoring that fd!\n", (unsigned int)a2);
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(_QWORD *a1, int a2)
{
__int64 *v2; // r9
int v3; // er10
__int64 *v4; // rdx
__int64 v5; // rax
int v6; // ecx
__int64 v7; // rdx
__int64 v8; // r11
__int64 v9; // rax
__int64 result; // rax

if ( a2 < 0 || (unsigned __int64)a2 >= a1[1] )
{
fprintf(stderr, "event_del(fd=%d): fd out of range\n", (unsigned int)a2);
result = 0xFFFFFFFFLL;
}
else if ( *(_QWORD *)(*a1 + 8LL * a2) )
{
func3((__int64)a1, a2, 0);
v4 = &v2[v3 >> 6];
v5 = ~(1LL << v3);
v4[3] &= v5;
v4[19] &= v5;
v4[35] &= v5;
v6 = *((_DWORD *)v2 + 198);
v7 = *v2;
*(_QWORD *)(*v2 + 8 * v8) = 0LL;
v9 = v6 - 1;
if ( v6 >= 0 )
{
do
{
if ( *(_QWORD *)(v7 + 8 * v9 + 8) )
break;
*((_DWORD *)v2 + 198) = v9--;
}
while ( v9 != -2 );
}
result = 0LL;
}
else
{
fprintf(stderr, "event_del(fd=%d): not monitoring that fd!\n", (unsigned int)a2);
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
int
event_del(events_t *ev, int fd)
{
 if ((fd < 0) || ((unsigned) fd >= ev->maxfds))
 {
  fprintf(stderr, "event_del(fd=%d): fd out of range\n", fd);
  return -1;
 }
 if (ev->handlers[fd] == ((void *)0))
 {
  fprintf(stderr, "event_del(fd=%d): not monitoring that fd!\n", fd);
  return -1;
 }
 event_set_mask(ev, fd, 0);
 ((void) (((&(ev->set_read_copy))->__fds_bits)[((fd) / (8 * (int) sizeof (__fd_mask)))] &= ~((__fd_mask) (1UL << ((fd) % (8 * (int) sizeof (__fd_mask)))))));
 ((void) (((&(ev->set_write_copy))->__fds_bits)[((fd) / (8 * (int) sizeof (__fd_mask)))] &= ~((__fd_mask) (1UL << ((fd) % (8 * (int) sizeof (__fd_mask)))))));
 ((void) (((&(ev->set_error_copy))->__fds_bits)[((fd) / (8 * (int) sizeof (__fd_mask)))] &= ~((__fd_mask) (1UL << ((fd) % (8 * (int) sizeof (__fd_mask)))))));
 ev->handlers[fd] = ((void *)0);
 while ((ev->max_fd >= 0) && (ev->handlers[ev->max_fd] == ((void *)0)))
  ev->max_fd--;
 return 0;
}

canonical_original_code:
int event_del(struct events *ev, int fd)
{
 if ((fd < 0) || ((unsigned int) fd >= ev->maxfds))
 {
  fprintf(stderr, "event_del(fd=%d): fd out of range\n", fd);
  return -1;
 }
 if (ev->handlers[fd] == ((void *)0))
 {
  fprintf(stderr, "event_del(fd=%d): not monitoring that fd!\n", fd);
  return -1;
 }
 event_set_mask(ev, fd, 0);
 ((void) (((&(ev->set_read_copy))->__fds_bits)[((fd) / (8 * (int) sizeof (__fd_mask)))] &= ~((__fd_mask) (1UL << ((fd) % (8 * (int) sizeof (__fd_mask)))))));
 ((void) (((&(ev->set_write_copy))->__fds_bits)[((fd) / (8 * (int) sizeof (__fd_mask)))] &= ~((__fd_mask) (1UL << ((fd) % (8 * (int) sizeof (__fd_mask)))))));
 ((void) (((&(ev->set_error_copy))->__fds_bits)[((fd) / (8 * (int) sizeof (__fd_mask)))] &= ~((__fd_mask) (1UL << ((fd) % (8 * (int) sizeof (__fd_mask)))))));
 ev->handlers[fd] = ((void *)0);
 while ((ev->max_fd >= 0) && (ev->handlers[ev->max_fd] == ((void *)0)))
  ev->max_fd--;
 return 0;
}


decompiled_code:
__int64 __fastcall event_add(__int64 a1, int a2, __int64 a3, char a4)
{
_QWORD *v6; // rcx
__int64 result; // rax

if ( a2 < 0 || (unsigned __int64)a2 >= *(_QWORD *)(a1 + 8) )
{
fprintf(stderr, "event_add(fd=%d): fd out of range\n", (unsigned int)a2);
result = 0xFFFFFFFFLL;
}
else
{
v6 = (_QWORD *)(*(_QWORD *)a1 + 8LL * a2);
if ( *v6 )
{
fprintf(stderr, "event_add(fd=%d): already monitoring that fd!\n", (unsigned int)a2);
result = 0xFFFFFFFFLL;
}
else
{
if ( *(_DWORD *)(a1 + 792) < a2 )
*(_DWORD *)(a1 + 792) = a2;
*v6 = a3;
event_set_mask(a1, a2, a4);
result = 0LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, int a2, __int64 a3, char a4)
{
_QWORD *v6; // rcx
__int64 result; // rax

if ( a2 < 0 || (unsigned __int64)a2 >= *(_QWORD *)(a1 + 8) )
{
fprintf(stderr, "event_add(fd=%d): fd out of range\n", (unsigned int)a2);
result = 0xFFFFFFFFLL;
}
else
{
v6 = (_QWORD *)(*(_QWORD *)a1 + 8LL * a2);
if ( *v6 )
{
fprintf(stderr, "event_add(fd=%d): already monitoring that fd!\n", (unsigned int)a2);
result = 0xFFFFFFFFLL;
}
else
{
if ( *(_DWORD *)(a1 + 792) < a2 )
*(_DWORD *)(a1 + 792) = a2;
*v6 = a3;
func3(a1, a2, a4);
result = 0LL;
}
}
return result;
}

original_code:
int
event_add(events_t *ev, int fd, handler_t handler, int event_mask)
{
 if ((fd < 0) || ((unsigned) fd >= ev->maxfds))
 {
  fprintf(stderr, "event_add(fd=%d): fd out of range\n", fd);
  return -1;
 }
 if (ev->handlers[fd])
 {
  fprintf(stderr, "event_add(fd=%d): already monitoring that fd!\n", fd);
  return -1;
 }
 if (fd > ev->max_fd)
  ev->max_fd = fd;
 ev->handlers[fd] = handler;
 event_set_mask(ev, fd, event_mask);
 return 0;
}

canonical_original_code:
int event_add(struct events *ev, int fd, int (*handler)(struct events *ev, struct event *event), int event_mask)
{
 if ((fd < 0) || ((unsigned int) fd >= ev->maxfds))
 {
  fprintf(stderr, "event_add(fd=%d): fd out of range\n", fd);
  return -1;
 }
 if (ev->handlers[fd])
 {
  fprintf(stderr, "event_add(fd=%d): already monitoring that fd!\n", fd);
  return -1;
 }
 if (fd > ev->max_fd)
  ev->max_fd = fd;
 ev->handlers[fd] = handler;
 event_set_mask(ev, fd, event_mask);
 return 0;
}

variable_types: int (*)(struct events *ev, struct event *event)


original_code:
int
event_wait(events_t *ev, int microseconds)
{
 struct timeval *t = ((void *)0);
 if(microseconds != -1)
 {
  t = &ev->tv;
  t->tv_sec = 0;
  t->tv_usec = microseconds;
 }
 ev->set_read_copy = ev->set_read;
 ev->set_write_copy = ev->set_write;
 ev->set_error_copy = ev->set_error;
 ev->currfd = -1;
 ev->nevents = select(ev->max_fd + 1, &(ev->set_read_copy),
   &(ev->set_write_copy), &(ev->set_error_copy), t);
 if(ev->nevents == -1)
 {
  if((*__errno_location ()) == 4)
   return 0;
  perror("event_wait():");
  return -1;
 }
 return ev->nevents;
}

canonical_original_code:
int event_wait(struct events *ev, int microseconds)
{
 struct timeval *t = ((void *)0);
 if(microseconds != -1)
 {
  t = &ev->tv;
  t->tv_sec = 0;
  t->tv_usec = microseconds;
 }
 ev->set_read_copy = ev->set_read;
 ev->set_write_copy = ev->set_write;
 ev->set_error_copy = ev->set_error;
 ev->currfd = -1;
 ev->nevents = select(ev->max_fd + 1, &(ev->set_read_copy),
   &(ev->set_write_copy), &(ev->set_error_copy), t);
 if(ev->nevents == -1)
 {
  if((*__errno_location ()) == 4)
   return 0;
  perror("event_wait():");
  return -1;
 }
 return ev->nevents;
}

variable_types: microseconds int

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


original_code:
int
event_next(events_t *ev, event_t *event)
{
 ((void) sizeof ((event != ((void *)0)) ? 1 : 0), __extension__ ({ if (event != ((void *)0)) ; else __assert_fail ("event != NULL", "./event/event.c", 179, __extension__ __PRETTY_FUNCTION__); }));
 int ret =0;
 event->event_mask = 0;
 for (; ev->currfd++ < ev->max_fd;)
 {
  if (((((&(ev->set_read_copy))->__fds_bits)[((ev->currfd) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((ev->currfd) % (8 * (int) sizeof (__fd_mask)))))) != 0))
  {
   event->event_mask |= 1;
   ev->nevents--;
   ret++;
  }
  if (((((&(ev->set_write_copy))->__fds_bits)[((ev->currfd) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((ev->currfd) % (8 * (int) sizeof (__fd_mask)))))) != 0))
  {
   event->event_mask |= 2;
   ev->nevents--;
   ret++;
  }
  if (((((&(ev->set_error_copy))->__fds_bits)[((ev->currfd) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((ev->currfd) % (8 * (int) sizeof (__fd_mask)))))) != 0))
  {
   event->event_mask |= 4;
   ev->nevents--;
   ret++;
  }
  if(event->event_mask)
   break;
 }
 event->fd = ev->currfd;
 event->handler = ev->handlers[ev->currfd];
 ((void) sizeof ((event->handler != ((void *)0)) ? 1 : 0), __extension__ ({ if (event->handler != ((void *)0)) ; else __assert_fail ("event->handler != NULL", "./event/event.c", 214, __extension__ __PRETTY_FUNCTION__); }));
 return ret;
}

canonical_original_code:
int event_next(struct events *ev, struct event *event)
{
 ((void) sizeof ((event != ((void *)0)) ? 1 : 0), __extension__ ({ if (event != ((void *)0)) ; else __assert_fail ("event != NULL", "./event/event.c", 179, __extension__ __PRETTY_FUNCTION__); }));
 int ret = 0;
 event->event_mask = 0;
 for (; ev->currfd++ < ev->max_fd;)
 {
  if (((((&(ev->set_read_copy))->__fds_bits)[((ev->currfd) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((ev->currfd) % (8 * (int) sizeof (__fd_mask)))))) != 0))
  {
   event->event_mask |= 1;
   ev->nevents--;
   ret++;
  }
  if (((((&(ev->set_write_copy))->__fds_bits)[((ev->currfd) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((ev->currfd) % (8 * (int) sizeof (__fd_mask)))))) != 0))
  {
   event->event_mask |= 2;
   ev->nevents--;
   ret++;
  }
  if (((((&(ev->set_error_copy))->__fds_bits)[((ev->currfd) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((ev->currfd) % (8 * (int) sizeof (__fd_mask)))))) != 0))
  {
   event->event_mask |= 4;
   ev->nevents--;
   ret++;
  }
  if(event->event_mask)
   break;
 }
 event->fd = ev->currfd;
 event->handler = ev->handlers[ev->currfd];
 ((void) sizeof ((event->handler != ((void *)0)) ? 1 : 0), __extension__ ({ if (event->handler != ((void *)0)) ; else __assert_fail ("event->handler != NULL", "./event/event.c", 214, __extension__ __PRETTY_FUNCTION__); }));
 return ret;
}

variable_types: ret int


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

clients = (__int64)calloc(a1, 8uLL);
if ( clients )
{
client_limit = a1;
result = 0LL;
}
else
{
perror("client_initialize():");
result = 0xFFFFFFFFLL;
}
return result;
}

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

clients = (__int64)calloc(a1, 8uLL);
if ( clients )
{
client_limit = a1;
result = 0LL;
}
else
{
perror("client_initialize():");
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
int
client_initialize(size_t max_clients)
{
 clients = (client_t **) calloc(max_clients, sizeof(client_t *));
 if(clients == ((void *)0))
 {
  perror("client_initialize():");
  return -1;
 }
 client_limit = max_clients;
 return 0;
}

canonical_original_code:
int client_initialize(unsigned long max_clients)
{
 clients = (struct client_t **) calloc(max_clients, sizeof(struct client_t *));
 if(clients == ((void *)0))
 {
  perror("client_initialize():");
  return -1;
 }
 client_limit = max_clients;
 return 0;
}

user_defined_types: struct client_t { int connection_fd; char *name; unsigned int id; unsigned int offset; int state; }


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

result = 0LL;
if ( a1 <= (unsigned __int64)client_limit )
result = *(_QWORD *)(clients + 8LL * a1);
return result;
}

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

result = 0LL;
if ( a1 <= (unsigned __int64)client_limit )
result = *(_QWORD *)(clients + 8LL * a1);
return result;
}

original_code:
client_t *
client_get(int fd)
{
 return ((size_t) fd > client_limit) ? ((void *)0) : clients[fd];
}

canonical_original_code:
struct client_t *client_get(int fd)
{
 return ((unsigned long) fd > client_limit) ? ((void *)0) : clients[fd];
}

return_type: struct client_t { int connection_fd; char *name; unsigned int id; unsigned int offset; int state; } *


decompiled_code:
__int64 __fastcall client_create(_QWORD *a1, int a2)
{
char *v2; // rax

if ( current_clients == client_limit )
{
fwrite("client_create(): Se llego al limite de clientes\n", 1uLL, 0x30uLL, stderr);
}
else
{
++current_clients;
v2 = (char *)malloc(0x20uLL);
if ( v2 )
{
*(_DWORD *)v2 = a2;
*((_DWORD *)v2 + 4) = a2;
*((_QWORD *)v2 + 1) = "1337 Client";
*(_QWORD *)(v2 + 20) = 0LL;
*a1 = v2;
return client_add_constprop_0((int *)v2);
}
perror("client_create():");
}
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func4(_QWORD *a1, int a2)
{
char *v2; // rax

if ( current_clients == client_limit )
{
fwrite("client_create(): Se llego al limite de clientes\n", 1uLL, 0x30uLL, stderr);
}
else
{
++current_clients;
v2 = (char *)malloc(0x20uLL);
if ( v2 )
{
*(_DWORD *)v2 = a2;
*((_DWORD *)v2 + 4) = a2;
*((_QWORD *)v2 + 1) = "1337 Client";
*(_QWORD *)(v2 + 20) = 0LL;
*a1 = v2;
return func0((int *)v2);
}
perror("client_create():");
}
return 0xFFFFFFFFLL;
}

original_code:
int
client_create(client_t **client, int connection)
{
 if(current_clients == client_limit)
 {
  fprintf(stderr, "client_create(): Se llego al limite de clientes\n");
  return -1;
 }
 current_clients++;
 client_t *tmp = (client_t *) malloc(sizeof(client_t));
 if(!tmp)
 {
  perror("client_create():");
  return -1;
 }
 tmp->connection_fd = connection;
 tmp->id = connection;
 tmp->name = "1337 Client";
 tmp->offset = 0;
 tmp->state = 0;
 *client = tmp;
 return client_add(*client);
}

canonical_original_code:
int client_create(struct client_t **client, int connection)
{
 if(current_clients == client_limit)
 {
  fprintf(stderr, "client_create(): Se llego al limite de clientes\n");
  return -1;
 }
 current_clients++;
 struct client_t *tmp = (client_t *) malloc(sizeof(client_t));
 if(!tmp)
 {
  perror("client_create():");
  return -1;
 }
 tmp->connection_fd = connection;
 tmp->id = connection;
 tmp->name = "1337 Client";
 tmp->offset = 0;
 tmp->state = 0;
 *client = tmp;
 return client_add(*client);
}

variable_types: struct client_t { int connection_fd; char *name; unsigned int id; unsigned int offset; int state; } **

variable_types: connection int