printUsage

decompiled_code:
size_t printUsage()
{
fwrite(
"daggen [options] [-o <output file>]\n"
"\t -n <number of tasks>\n"
"\t --mindata <minimum data size>\n"
"\t --maxdata <maximum data size>\n"
"\t --minalpha <minimum Amdahl's law parameter value>\n"
"\t --maxalpha <maximum Amdahl's law parameter value>\n",
1uLL,
0xE3uLL,
stderr);
return fwrite(
"\t --fat <dag shape>\n"
"\t\t fat=1.0: fat (maximum parallelism)\n"
"\t\t fat=0.0: thin (minimum parallelism)\n"
"\t --density <density>\n"
"\t density=0.0: minimum number of dependencies\n"
"\t density=1.0: full graph\n"
"\t --regular <regularity for num tasks per level>\n"
"\t regular= 1.0: perfectly regular\n"
"\t regular= 0.0: irregular\n"
"\t --ccr <communication(MBytes) to computation(sec) ratio>\n"
"\t --jump <number of levels spanned by communications>\n"
"\t jump=1: perfectly synchronized levels\n"
"\t --dot: output generated DAG in the DOT format\n"
"\n",
1uLL,
0x204uLL,
stderr);
}

canonical_decompiled_code:
size_t func1()
{
fwrite(
"daggen [options] [-o <output file>]\n"
"\t -n <number of tasks>\n"
"\t --mindata <minimum data size>\n"
"\t --maxdata <maximum data size>\n"
"\t --minalpha <minimum Amdahl's law parameter value>\n"
"\t --maxalpha <maximum Amdahl's law parameter value>\n",
1uLL,
0xE3uLL,
stderr);
return fwrite(
"\t --fat <dag shape>\n"
"\t\t fat=1.0: fat (maximum parallelism)\n"
"\t\t fat=0.0: thin (minimum parallelism)\n"
"\t --density <density>\n"
"\t density=0.0: minimum number of dependencies\n"
"\t density=1.0: full graph\n"
"\t --regular <regularity for num tasks per level>\n"
"\t regular= 1.0: perfectly regular\n"
"\t regular= 0.0: irregular\n"
"\t --ccr <communication(MBytes) to computation(sec) ratio>\n"
"\t --jump <number of levels spanned by communications>\n"
"\t jump=1: perfectly synchronized levels\n"
"\t --dot: output generated DAG in the DOT format\n"
"\n",
1uLL,
0x204uLL,
stderr);
}

original_code:
void printUsage(void)
{
  fprintf(stderr,"daggen [options] [-o <output file>]\n"
      "\t -n <number of tasks>\n"
      "\t --mindata <minimum data size>\n"
      "\t --maxdata <maximum data size>\n"
      "\t --minalpha <minimum Amdahl's law parameter value>\n"
      "\t --maxalpha <maximum Amdahl's law parameter value>\n");
  fprintf(stderr,
      "\t --fat <dag shape>\n"
      "\t	 fat=1.0: fat (maximum parallelism)\n"
      "\t	 fat=0.0: thin (minimum parallelism)\n"
      "\t --density <density>\n"
      "\t    density=0.0: minimum number of dependencies\n"
      "\t    density=1.0: full graph\n"
      "\t --regular <regularity for num tasks per level>\n"
      "\t    regular= 1.0: perfectly regular\n"
      "\t    regular= 0.0: irregular\n"
      "\t --ccr <communication(MBytes) to computation(sec) ratio>\n"
      "\t --jump <number of levels spanned by communications>\n"
      "\t    jump=1: perfectly synchronized levels\n"
      "\t --dot: output generated DAG in the DOT format\n"
      "\n");
  return;
}

canonical_original_code:
void printUsage()
{
  fprintf(stderr,"daggen [options] [-o <output file>]\n"
      "\t -n <number of tasks>\n"
      "\t --mindata <minimum data size>\n"
      "\t --maxdata <maximum data size>\n"
      "\t --minalpha <minimum Amdahl's law parameter value>\n"
      "\t --maxalpha <maximum Amdahl's law parameter value>\n");
  fprintf(stderr,
      "\t --fat <dag shape>\n"
      "\t	 fat=1.0: fat (maximum parallelism)\n"
      "\t	 fat=0.0: thin (minimum parallelism)\n"
      "\t --density <density>\n"
      "\t    density=0.0: minimum number of dependencies\n"
      "\t    density=1.0: full graph\n"
      "\t --regular <regularity for num tasks per level>\n"
      "\t    regular= 1.0: perfectly regular\n"
      "\t    regular= 0.0: irregular\n"
      "\t --ccr <communication(MBytes) to computation(sec) ratio>\n"
      "\t --jump <number of levels spanned by communications>\n"
      "\t    jump=1: perfectly synchronized levels\n"
      "\t --dot: output generated DAG in the DOT format\n"
      "\n");
  return;
}


outputDAG

original_code:
void outputDAG(DAG dag) {
  int i, j, k;
  int node_count=1;
  for (i=0; i<dag->nb_levels; i++) {
    for (j=0; j<dag->nb_tasks_per_level[i]; j++) {
      dag->levels[i][j]->tag = node_count++;
    }
    for (j=0; j<dag->nb_tasks_per_level[i]; j++) {
      for (k=0; k<dag->levels[i][j]->nb_children; k++) {
        dag->levels[i][j]->transfer_tags[k] = node_count++;
      }
    }
  }
  fprintf((global.output_file),"NODE_COUNT %d\n",node_count+1);
  fprintf((global.output_file),"NODE 0 ");
  for (i=0; i<dag->nb_tasks_per_level[0]-1; i++) {
    fprintf((global.output_file),"%d,",dag->levels[0][i]->tag);
  }
  if (dag->nb_tasks_per_level[0])
    fprintf((global.output_file),"%d ROOT 0.0 0.0\n",dag->levels[0][i]->tag);
  else
    fprintf((global.output_file),"%d ROOT 0.0 0.0\n",node_count);
  for (i=0; i<dag->nb_levels-1; i++) {
    for (j=0; j<dag->nb_tasks_per_level[i]; j++) {
      fprintf((global.output_file),"NODE %d ",dag->levels[i][j]->tag);
      for (k=0; k<dag->levels[i][j]->nb_children-1; k++) {
        fprintf((global.output_file),"%d,",dag->levels[i][j]->transfer_tags[k]);
      }
      if (dag->levels[i][j]->nb_children) {
        fprintf((global.output_file),"%d COMPUTATION %.0f %.2f\n",
            dag->levels[i][j]->transfer_tags[k],
            dag->levels[i][j]->cost,
            dag->levels[i][j]->alpha);
      } else {
        fprintf((global.output_file),"%d COMPUTATION %.0f %.2f\n",
            node_count,
            dag->levels[i][j]->cost,
            dag->levels[i][j]->alpha);
      }
      for (k=0; k<dag->levels[i][j]->nb_children; k++) {
        fprintf((global.output_file),"NODE %d ",dag->levels[i][j]->transfer_tags[k]);
        fprintf((global.output_file),"%d TRANSFER %.0f 0.0\n",
            dag->levels[i][j]->children[k]->tag,
            dag->levels[i][j]->comm_costs[k]);
      }
    }
  }
  for (j=0; j<dag->nb_tasks_per_level[dag->nb_levels-1]; j++) {
    fprintf((global.output_file),"NODE %d %d COMPUTATION %.0f %.2f\n",
        dag->levels[dag->nb_levels-1][j]->tag,
        node_count,
        dag->levels[dag->nb_levels-1][j]->cost,
        dag->levels[dag->nb_levels-1][j]->alpha);
  }
  fprintf((global.output_file),"NODE %d - END 0.0 0.0\n",node_count);
}

canonical_original_code:
void outputDAG(struct _DAG *dag) {
  int i; int j; int k;
  int node_count = 1;
  for (i=0; i<dag->nb_levels; i++) {
    for (j=0; j<dag->nb_tasks_per_level[i]; j++) {
      dag->levels[i][j]->tag = node_count++;
    }
    for (j=0; j<dag->nb_tasks_per_level[i]; j++) {
      for (k=0; k<dag->levels[i][j]->nb_children; k++) {
        dag->levels[i][j]->transfer_tags[k] = node_count++;
      }
    }
  }
  fprintf((global.output_file),"NODE_COUNT %d\n",node_count+1);
  fprintf((global.output_file),"NODE 0 ");
  for (i=0; i<dag->nb_tasks_per_level[0]-1; i++) {
    fprintf((global.output_file),"%d,",dag->levels[0][i]->tag);
  }
  if (dag->nb_tasks_per_level[0])
    fprintf((global.output_file),"%d ROOT 0.0 0.0\n",dag->levels[0][i]->tag);
  else
    fprintf((global.output_file),"%d ROOT 0.0 0.0\n",node_count);
  for (i=0; i<dag->nb_levels-1; i++) {
    for (j=0; j<dag->nb_tasks_per_level[i]; j++) {
      fprintf((global.output_file),"NODE %d ",dag->levels[i][j]->tag);
      for (k=0; k<dag->levels[i][j]->nb_children-1; k++) {
        fprintf((global.output_file),"%d,",dag->levels[i][j]->transfer_tags[k]);
      }
      if (dag->levels[i][j]->nb_children) {
        fprintf((global.output_file),"%d COMPUTATION %.0f %.2f\n",
            dag->levels[i][j]->transfer_tags[k],
            dag->levels[i][j]->cost,
            dag->levels[i][j]->alpha);
      } else {
        fprintf((global.output_file),"%d COMPUTATION %.0f %.2f\n",
            node_count,
            dag->levels[i][j]->cost,
            dag->levels[i][j]->alpha);
      }
      for (k=0; k<dag->levels[i][j]->nb_children; k++) {
        fprintf((global.output_file),"NODE %d ",dag->levels[i][j]->transfer_tags[k]);
        fprintf((global.output_file),"%d TRANSFER %.0f 0.0\n",
            dag->levels[i][j]->children[k]->tag,
            dag->levels[i][j]->comm_costs[k]);
      }
    }
  }
  for (j=0; j<dag->nb_tasks_per_level[dag->nb_levels-1]; j++) {
    fprintf((global.output_file),"NODE %d %d COMPUTATION %.0f %.2f\n",
        dag->levels[dag->nb_levels-1][j]->tag,
        node_count,
        dag->levels[dag->nb_levels-1][j]->cost,
        dag->levels[dag->nb_levels-1][j]->alpha);
  }
  fprintf((global.output_file),"NODE %d - END 0.0 0.0\n",node_count);
}

variable_types: struct _DAG { int nb_levels; int *nb_tasks_per_level; struct _Task { int tag; double cost; int data_size; double alpha; int nb_children; struct _Task **children; double *comm_costs; int *transfer_tags; enum complexity_t { MIXED=0, N_2=1, N_LOG_N=2, N_3=3 } complexity; } ***levels; } *

variable_types: i int

variable_types: j int

variable_types: k int

return_type: void

user_defined_types: struct _DAG { int nb_levels; int *nb_tasks_per_level; struct _Task ***levels; }

user_defined_types: struct _Task { int tag; double cost; int data_size; double alpha; int nb_children; struct _Task **children; double *comm_costs; int *transfer_tags; enum complexity_t complexity; }


outputDOT

original_code:
void outputDOT(DAG dag) {
  int i, j, k;
  int node_count=1;
  for (i=0; i<dag->nb_levels; i++) {
    for (j=0; j<dag->nb_tasks_per_level[i]; j++) {
      dag->levels[i][j]->tag = node_count++;
    }
  }
  fprintf((global.output_file),"digraph G {\n");
  for (i=0; i<dag->nb_levels; i++) {
    for (j=0; j<dag->nb_tasks_per_level[i]; j++) {
      fprintf((global.output_file),"  %d [size=\"%.0f\", alpha=\"%.2f\"]\n",
          dag->levels[i][j]->tag,
          dag->levels[i][j]->cost,
          dag->levels[i][j]->alpha);
      for (k=0; k<dag->levels[i][j]->nb_children; k++) {
        fprintf((global.output_file),"  %d -> %d [size =\"%.f\"]\n",
            dag->levels[i][j]->tag,
            dag->levels[i][j]->children[k]->tag,
            dag->levels[i][j]->comm_costs[k]);
      }
    }
  }
  fprintf((global.output_file),"}\n");
}

canonical_original_code:
void outputDOT(struct _DAG *dag) {
  int i; int j; int k;
  int node_count = 1;
  for (i=0; i<dag->nb_levels; i++) {
    for (j=0; j<dag->nb_tasks_per_level[i]; j++) {
      dag->levels[i][j]->tag = node_count++;
    }
  }
  fprintf((global.output_file),"digraph G {\n");
  for (i=0; i<dag->nb_levels; i++) {
    for (j=0; j<dag->nb_tasks_per_level[i]; j++) {
      fprintf((global.output_file),"  %d [size=\"%.0f\", alpha=\"%.2f\"]\n",
          dag->levels[i][j]->tag,
          dag->levels[i][j]->cost,
          dag->levels[i][j]->alpha);
      for (k=0; k<dag->levels[i][j]->nb_children; k++) {
        fprintf((global.output_file),"  %d -> %d [size =\"%.f\"]\n",
            dag->levels[i][j]->tag,
            dag->levels[i][j]->children[k]->tag,
            dag->levels[i][j]->comm_costs[k]);
      }
    }
  }
  fprintf((global.output_file),"}\n");
}

user_defined_types: enum complexity_t { MIXED=0, N_2=1, N_LOG_N=2, N_3=3 }


getIntRandomNumberAround

decompiled_code:
__int64 __fastcall getIntRandomNumberAround(int a1, double a2)
{
__int64 result; // rax

result = (unsigned int)(int)((((a2 + a2) * (double)rand() * 4.656612873077393e-10 - a2) / 100.0 + 1.0) * (double)a1);
if ( (int)result <= 0 )
result = 1LL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(int a1, double a2)
{
__int64 result; // rax

result = (unsigned int)(int)((((a2 + a2) * (double)rand() * 4.656612873077393e-10 - a2) / 100.0 + 1.0) * (double)a1);
if ( (int)result <= 0 )
result = 1LL;
return result;
}

original_code:
int getIntRandomNumberAround(int x, double perc) {
  double r;
  int new_int;
  r = -perc + (2*perc*rand()/(2147483647 +1.0));
  new_int = ((1) > ((int)((double)x * (1.0 + r/100.00))) ? (1) : ((int)((double)x * (1.0 + r/100.00))));
  return new_int;
}

variable_types: x int

variable_types: perc double

variable_types: r double

return_type: int


getRandomNumberBetween

decompiled_code:
double __fastcall getRandomNumberBetween(double a1, double a2)
{
return (double)rand() * (a2 - a1) * 4.656612873077393e-10 + a1;
}

canonical_decompiled_code:
double __fastcall func5(double a1, double a2)
{
return (double)rand() * (a2 - a1) * 4.656612873077393e-10 + a1;
}

original_code:
double getRandomNumberBetween(double x, double y) {
  double r;
  r = x + (y-x)*rand()/(2147483647 +1.0);
  return r;
}

variable_types: x double

variable_types: y double

return_type: double


repo: frsyuki/pxe-pdhcp

original_code:
int check_dhcp_packet(struct dhcp_packet *p)
{
 u_char *op;
 if (memcmp(p->options, "\143\202\123\143", 4))
  return -1;
 if (p->op != 1)
  return -1;
 op = p->options + 4;
 while (*op != 255) {
  if (op - p->options >= (1500 - (236 + (20 + 8))))
   return -1;
  else if (*op == 0)
   ++op;
  else
   op += op[1] + 2;
 }
 return 0;
}

canonical_original_code:
int check_dhcp_packet(struct dhcp_packet *p)
{
 unsigned char *op;
 if (memcmp(p->options, "\143\202\123\143", 4))
  return -1;
 if (p->op != 1)
  return -1;
 op = p->options + 4;
 while (*op != 255) {
  if (op - p->options >= (1500 - (236 + (20 + 8))))
   return -1;
  else if (*op == 0)
   ++op;
  else
   op += op[1] + 2;
 }
 return 0;
}

variable_types: struct dhcp_packet { unsigned int op; unsigned int htype; unsigned int hlen; unsigned int hops; unsigned int xid; unsigned int secs; unsigned int flags; struct in_addr { unsigned int s_addr; } ciaddr; struct in_addr yiaddr; struct in_addr siaddr; struct in_addr giaddr; unsigned char chaddr[16]; char sname[64]; char file[128]; unsigned char options[-1]; } *

variable_types:
op
unsigned char *

user_defined_types: struct dhcp_packet { unsigned int op; unsigned int htype; unsigned int hlen; unsigned int hops; unsigned int xid; unsigned int secs; unsigned int flags; struct in_addr ciaddr; struct in_addr yiaddr; struct in_addr siaddr; struct in_addr giaddr; unsigned char chaddr[16]; char sname[64]; char file[128]; unsigned char options[-1]; }


decompiled_code:
__int64 __fastcall get_dhcp_option(__int64 a1, char a2, _QWORD *a3, _BYTE *a4)
{
char v4; // al
char *v6; // rdx

v4 = *(_BYTE *)(a1 + 240);
v6 = (char *)(a1 + 240);
if ( v4 == -1 )
return 0xFFFFFFFFLL;
while ( a2 != v4 )
{
if ( v4 )
{
v6 += (unsigned __int8)v6[1] + 2;
v4 = *v6;
if ( *v6 == -1 )
return 0xFFFFFFFFLL;
}
else
{
v4 = *++v6;
if ( v4 == -1 )
return 0xFFFFFFFFLL;
}
}
*a3 = v6 + 2;
*a4 = v6[1];
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, char a2, _QWORD *a3, _BYTE *a4)
{
char v4; // al
char *v6; // rdx

v4 = *(_BYTE *)(a1 + 240);
v6 = (char *)(a1 + 240);
if ( v4 == -1 )
return 0xFFFFFFFFLL;
while ( a2 != v4 )
{
if ( v4 )
{
v6 += (unsigned __int8)v6[1] + 2;
v4 = *v6;
if ( *v6 == -1 )
return 0xFFFFFFFFLL;
}
else
{
v4 = *++v6;
if ( v4 == -1 )
return 0xFFFFFFFFLL;
}
}
*a3 = v6 + 2;
*a4 = v6[1];
return 0LL;
}

original_code:
int get_dhcp_option(struct dhcp_packet *p, u_char type, u_char **opt, u_char *optlen)
{
 u_char *opos = p->options + 4;
 while (*opos != 255) {
  if (*opos == type) {
   *opt = &opos[2];
   *optlen = opos[1];
   return 0;
  }
  if (*opos == 0)
   opos++;
  else
   opos += opos[1] + 2;
 }
 return -1;
}

canonical_original_code:
int get_dhcp_option(struct dhcp_packet *p, unsigned char type, unsigned char **opt, unsigned char *optlen)
{
 unsigned char *opos = p->options + 4;
 while (*opos != 255) {
  if (*opos == type) {
   *opt = &opos[2];
   *optlen = opos[1];
   return 0;
  }
  if (*opos == 0)
   opos++;
  else
   opos += opos[1] + 2;
 }
 return -1;
}

variable_types:
type
unsigned char

variable_types:
opt
unsigned char **

variable_types:
optlen
unsigned char *

variable_types:
opos
unsigned char *


decompiled_code:
__int64 __fastcall get_dhcp_message_type(__int64 a1)
{
__int64 result; // rax
char v2; // [rsp+7h] [rbp-9h] BYREF
unsigned __int8 *v3; // [rsp+8h] [rbp-8h] BYREF

result = get_dhcp_option(a1, 53, &v3, &v2);
if ( (_DWORD)result != -1 )
result = *v3;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
__int64 result; // rax
char v2; // [rsp+7h] [rbp-9h] BYREF
unsigned __int8 *v3; // [rsp+8h] [rbp-8h] BYREF

result = func1(a1, 53, &v3, &v2);
if ( (_DWORD)result != -1 )
result = *v3;
return result;
}

original_code:
int get_dhcp_message_type(struct dhcp_packet *p)
{
 u_char *opt, optlen;
 if (get_dhcp_option(p, 53, &opt, &optlen) == -1) {
  return -1;
 }
 return *opt;
}

canonical_original_code:
int get_dhcp_message_type(struct dhcp_packet *p)
{
 unsigned char *opt; unsigned char optlen;
 if (get_dhcp_option(p, 53, &opt, &optlen) == -1) {
  return -1;
 }
 return *opt;
}

variable_types:
opt
unsigned char *

variable_types:
optlen
unsigned char


decompiled_code:
__int64 __fastcall get_dhcp_packet_len(__int64 a1)
{
char v1; // dl
char *v2; // rax

v1 = *(_BYTE *)(a1 + 240);
v2 = (char *)(a1 + 240);
if ( v1 != -1 )
{
do
{
while ( !v1 )
{
v1 = *++v2;
if ( v1 == -1 )
return (unsigned int)((_DWORD)v2 - a1 + 1);
}
v2 += (unsigned __int8)v2[1] + 2;
v1 = *v2;
}
while ( *v2 != -1 );
}
return (unsigned int)((_DWORD)v2 - a1 + 1);
}

original_code:
int get_dhcp_packet_len(struct dhcp_packet *p)
{
 u_char *op = p->options;
 op += 4;
 while (*op != 255) {
  if (*op == 0)
   op++;
  else
   op += op[1] + 2;
 }
 return (op - (u_char*)p) + 1;
}

canonical_original_code:
int get_dhcp_packet_len(struct dhcp_packet *p)
{
 unsigned char *op = p->options;
 op += 4;
 while (*op != 255) {
  if (*op == 0)
   op++;
  else
   op += op[1] + 2;
 }
 return (op - (unsigned char *)p) + 1;
}


decompiled_code:
__int64 __fastcall add_dhcp_option(__int64 a1, __int64 a2, _QWORD *a3)
{
__int64 result; // rax
unsigned __int8 v5; // r8
char v6; // r9
__int64 v7; // rax
__int64 v8; // r9

result = get_dhcp_packet_len(a1);
if ( (_DWORD)result != -1 )
{
if ( v5 + (unsigned int)result + 3 > 0x5C0 )
{
result = 0xFFFFFFFFLL;
}
else
{
v7 = a1 + (int)result - 1;
*(_BYTE *)v7 = v6;
v8 = v7 + 2;
*(_BYTE *)(v7 + 1) = v5;
if ( v5 >= 8u )
{
*(_QWORD *)(v7 + 2) = *a3;
*(_QWORD *)(v8 + v5 - 8) = *(_QWORD *)((char *)a3 + v5 - 8);
qmemcpy(
(void *)((v7 + 10) & 0xFFFFFFFFFFFFFFF8LL),
(char *)a3 - (v8 - ((v7 + 10) & 0xFFFFFFFFFFFFFFF8LL)),
8LL * (((unsigned int)v8 - (((_DWORD)v7 + 10) & 0xFFFFFFF8) + v5) >> 3));
}
else if ( (v5 & 4) != 0 )
{
*(_DWORD *)(v7 + 2) = *(_DWORD *)a3;
*(_DWORD *)(v8 + v5 - 4) = *(_DWORD *)((char *)a3 + v5 - 4);
}
else if ( v5 )
{
*(_BYTE *)(v7 + 2) = *(_BYTE *)a3;
if ( (v5 & 2) != 0 )
*(_WORD *)(v7 + v5) = *(_WORD *)((char *)a3 + v5 - 2);
}
*(_BYTE *)(v7 + v5 + 2) = -1;
result = 0LL;
}
}
return result;
}

original_code:
int add_dhcp_option(struct dhcp_packet *p, u_char type,
  u_char *opt, u_char optlen)
{
 u_char *op;
 int len = get_dhcp_packet_len(p);
 if (len == -1) return -1;
 if (len + optlen + 3 > sizeof(struct dhcp_packet))
  return -1;
 op = (u_char*)p + len - 1;
 op[0] = type;
 op[1] = optlen;
 memcpy(&op[2], opt, optlen);
 op[2+optlen] = 255;
 return 0;
}

canonical_original_code:
int add_dhcp_option(struct dhcp_packet *p, unsigned char type, unsigned char *opt, unsigned char optlen)
{
 unsigned char *op;
 int len = get_dhcp_packet_len(p);
 if (len == -1) return -1;
 if (len + optlen + 3 > sizeof(struct dhcp_packet))
  return -1;
 op = (unsigned char *)p + len - 1;
 op[0] = type;
 op[1] = optlen;
 memcpy(&op[2], opt, optlen);
 op[2+optlen] = 255;
 return 0;
}

variable_types: len int


decompiled_code:
int __fastcall signal_handler(unsigned int a1)
{
time_t timer; // [rsp+8h] [rbp-70h] BYREF
char s[16]; // [rsp+10h] [rbp-68h] BYREF
int v4; // [rsp+20h] [rbp-58h]
struct tm tp; // [rsp+30h] [rbp-48h] BYREF

if ( a1 == 15 || a1 - 2 <= 1 )
stopflag = 1;
v4 = 0;
*(_OWORD *)s = 0LL;
time(&timer);
localtime_r(&timer, &tp);
strftime(s, 0x13uLL, "%b %d %H:%M:%S", &tp);
printf("%s: DEBUG: pxe-pdhcp.c: ", s);
printf("got signal %d", a1);
return putchar(10);
}

canonical_decompiled_code:
int __fastcall func0(unsigned int a1)
{
time_t timer; // [rsp+8h] [rbp-70h] BYREF
char s[16]; // [rsp+10h] [rbp-68h] BYREF
int v4; // [rsp+20h] [rbp-58h]
struct tm tp; // [rsp+30h] [rbp-48h] BYREF

if ( a1 == 15 || a1 - 2 <= 1 )
stopflag = 1;
v4 = 0;
*(_OWORD *)s = 0LL;
time(&timer);
localtime_r(&timer, &tp);
strftime(s, 0x13uLL, "%b %d %H:%M:%S", &tp);
printf("%s: DEBUG: pxe-pdhcp.c: ", s);
printf("got signal %d", a1);
return putchar(10);
}

original_code:
void signal_handler(int sig)
{
 if (sig == 15) stopflag = 1;
 if (sig == 3) stopflag = 1;
 if (sig == 2) stopflag = 1;
 { char _ts[20] = {0}; time_t _t; struct tm _tm; time(&_t); localtime_r(&_t, &_tm); strftime(_ts, 19, "%b %d %H:%M:%S", &_tm); printf("%s: DEBUG: " "pxe-pdhcp.c" ": ", _ts); printf("got signal %d", sig); printf("\n"); };
}

canonical_original_code:
void signal_handler(int sig)
{
 if (sig == 15) stopflag = 1;
 if (sig == 3) stopflag = 1;
 if (sig == 2) stopflag = 1;
 { char _ts[20] = {0}; long _t; struct tm _tm; time(&_t); localtime_r(&_t, &_tm); strftime(_ts, 19, "%b %d %H:%M:%S", &_tm); printf("%s: DEBUG: " "pxe-pdhcp.c" ": ", _ts); printf("got signal %d", sig); printf("\n"); };
}

variable_types: sig int

variable_types: struct tm { int tm_sec; int tm_min; int tm_hour; int tm_mday; int tm_mon; int tm_year; int tm_wday; int tm_yday; int tm_isdst; long tm_gmtoff; char *tm_zone; }


decompiled_code:
int __fastcall dhcp_reply(__int64 a1)
{
__m128i v3; // xmm5
size_t v4; // rbx
int *v5; // rax
char *v6; // rax
char v7; // [rsp+0h] [rbp-63Ch] BYREF
__int16 v8; // [rsp+1h] [rbp-63Bh] BYREF
char v9; // [rsp+3h] [rbp-639h]
const void *v10; // [rsp+4h] [rbp-638h] BYREF
time_t v11; // [rsp+Ch] [rbp-630h] BYREF
time_t timer[2]; // [rsp+14h] [rbp-628h] BYREF
int v13; // [rsp+24h] [rbp-618h]
struct tm s; // [rsp+34h] [rbp-608h] BYREF
struct tm tp; // [rsp+74h] [rbp-5C8h] BYREF
char dest[1372]; // [rsp+E0h] [rbp-55Ch] BYREF

*(_OWORD *)&s.tm_sec = 0LL;
s.tm_mon = 0;
time(timer);
localtime_r(timer, &tp);
strftime((char *)&s, 0x13uLL, "%b %d %H:%M:%S", &tp);
printf("%s: DEBUG: pxe-pdhcp.c: ", (const char *)&s);
printf("dhcp_reply start");
putchar(10);
if ( (unsigned int)check_dhcp_packet(a1) == -1 )
{
s.tm_mon = 0;
*(_OWORD *)&s.tm_sec = 0LL;
time(timer);
localtime_r(timer, &tp);
strftime((char *)&s, 0x13uLL, "%b %d %H:%M:%S", &tp);
printf("%s: DEBUG: pxe-pdhcp.c: ", (const char *)&s);
printf("got a invalid dhcp packet");
return putchar(10);
}
if ( (unsigned int)get_dhcp_message_type(a1) != 1 )
{
s.tm_mon = 0;
*(_OWORD *)&s.tm_sec = 0LL;
time(timer);
localtime_r(timer, &tp);
strftime((char *)&s, 0x13uLL, "%b %d %H:%M:%S", &tp);
printf("%s: DEBUG: pxe-pdhcp.c: ", (const char *)&s);
printf("got a non-DHCPDISCOVER dhcp packet");
return putchar(10);
}
s.tm_mon = 0;
*(_OWORD *)&s.tm_sec = 0LL;
time(timer);
localtime_r(timer, &tp);
strftime((char *)&s, 0x13uLL, "%b %d %H:%M:%S", &tp);
printf("%s: DEBUG: pxe-pdhcp.c: ", (const char *)&s);
printf("got a DHCPDISCOVER on dhcp");
putchar(10);
if ( (unsigned int)get_dhcp_option(a1, 60LL, &v10, &v7) == -1 || memcmp(v10, "PXEClient", 9uLL) )
{
s.tm_mon = 0;
*(_OWORD *)&s.tm_sec = 0LL;
time(timer);
localtime_r(timer, &tp);
strftime((char *)&s, 0x13uLL, "%b %d %H:%M:%S", &tp);
printf("%s: pxe-pdhcp.c: ", (const char *)&s);
printf("got a non-PXE dhcp packet");
return putchar(10);
}
init_packet((__int64)&tp, a1, 2);
v3 = _mm_loadu_si128((const __m128i *)(a1 + 28));
tp.tm_year = tftp_ip.s_addr;
*(__m128i *)&tp.tm_yday = v3;
strcpy(dest, nbp_name);
if ( (unsigned int)add_dhcp_option(&tp, 60LL, "PXEClient", 9LL) == -1 )
{
*(_OWORD *)timer = 0LL;
LABEL_15:
v13 = 0;
time(&v11);
localtime_r(&v11, &s);
strftime((char *)timer, 0x13uLL, "%b %d %H:%M:%S", &s);
printf("%s: DEBUG: pxe-pdhcp.c: ", (const char *)timer);
printf("add_dhcp_option() failed");
return putchar(10);
}
v8 = 262;
v9 = 8;
if ( (unsigned int)add_dhcp_option(&tp, 43LL, &v8, 3LL) == -1 )
{
*(_OWORD *)timer = 0LL;
goto LABEL_15;
}
v4 = (int)get_dhcp_packet_len(&tp);
if ( (_DWORD)v4 == (unsigned int)sendto(server_socket, &tp, v4, 0, &bcast_address, 0x10u) )
{
v13 = 0;
*(_OWORD *)timer = 0LL;
time(&v11);
localtime_r(&v11, &s);
strftime((char *)timer, 0x13uLL, "%b %d %H:%M:%S", &s);
printf("%s: DEBUG: pxe-pdhcp.c: ", (const char *)timer);
printf("dhcp_reply end");
}
else
{
v13 = 0;
*(_OWORD *)timer = 0LL;
time(&v11);
localtime_r(&v11, &s);
strftime((char *)timer, 0x13uLL, "%b %d %H:%M:%S", &s);
printf("%s: pxe-pdhcp.c: ", (const char *)timer);
v5 = _errno_location();
v6 = strerror(*v5);
printf("sendto() failed or was not complete: %s", v6);
}
return putchar(10);
}

canonical_decompiled_code:
int __fastcall func3(__int64 a1)
{
__m128i v3; // xmm5
size_t v4; // rbx
int *v5; // rax
char *v6; // rax
char v7; // [rsp+0h] [rbp-63Ch] BYREF
__int16 v8; // [rsp+1h] [rbp-63Bh] BYREF
char v9; // [rsp+3h] [rbp-639h]
const void *v10; // [rsp+4h] [rbp-638h] BYREF
time_t v11; // [rsp+Ch] [rbp-630h] BYREF
time_t timer[2]; // [rsp+14h] [rbp-628h] BYREF
int v13; // [rsp+24h] [rbp-618h]
struct tm s; // [rsp+34h] [rbp-608h] BYREF
struct tm tp; // [rsp+74h] [rbp-5C8h] BYREF
char dest[1372]; // [rsp+E0h] [rbp-55Ch] BYREF

*(_OWORD *)&s.tm_sec = 0LL;
s.tm_mon = 0;
time(timer);
localtime_r(timer, &tp);
strftime((char *)&s, 0x13uLL, "%b %d %H:%M:%S", &tp);
printf("%s: DEBUG: pxe-pdhcp.c: ", (const char *)&s);
printf("dhcp_reply start");
putchar(10);
if ( (unsigned int)check_dhcp_packet(a1) == -1 )
{
s.tm_mon = 0;
*(_OWORD *)&s.tm_sec = 0LL;
time(timer);
localtime_r(timer, &tp);
strftime((char *)&s, 0x13uLL, "%b %d %H:%M:%S", &tp);
printf("%s: DEBUG: pxe-pdhcp.c: ", (const char *)&s);
printf("got a invalid dhcp packet");
return putchar(10);
}
if ( (unsigned int)get_dhcp_message_type(a1) != 1 )
{
s.tm_mon = 0;
*(_OWORD *)&s.tm_sec = 0LL;
time(timer);
localtime_r(timer, &tp);
strftime((char *)&s, 0x13uLL, "%b %d %H:%M:%S", &tp);
printf("%s: DEBUG: pxe-pdhcp.c: ", (const char *)&s);
printf("got a non-DHCPDISCOVER dhcp packet");
return putchar(10);
}
s.tm_mon = 0;
*(_OWORD *)&s.tm_sec = 0LL;
time(timer);
localtime_r(timer, &tp);
strftime((char *)&s, 0x13uLL, "%b %d %H:%M:%S", &tp);
printf("%s: DEBUG: pxe-pdhcp.c: ", (const char *)&s);
printf("got a DHCPDISCOVER on dhcp");
putchar(10);
if ( (unsigned int)get_dhcp_option(a1, 60LL, &v10, &v7) == -1 || memcmp(v10, "PXEClient", 9uLL) )
{
s.tm_mon = 0;
*(_OWORD *)&s.tm_sec = 0LL;
time(timer);
localtime_r(timer, &tp);
strftime((char *)&s, 0x13uLL, "%b %d %H:%M:%S", &tp);
printf("%s: pxe-pdhcp.c: ", (const char *)&s);
printf("got a non-PXE dhcp packet");
return putchar(10);
}
func2((__int64)&tp, a1, 2);
v3 = _mm_loadu_si128((const __m128i *)(a1 + 28));
tp.tm_year = tftp_ip.s_addr;
*(__m128i *)&tp.tm_yday = v3;
strcpy(dest, nbp_name);
if ( (unsigned int)add_dhcp_option(&tp, 60LL, "PXEClient", 9LL) == -1 )
{
*(_OWORD *)timer = 0LL;
LABEL_15:
v13 = 0;
time(&v11);
localtime_r(&v11, &s);
strftime((char *)timer, 0x13uLL, "%b %d %H:%M:%S", &s);
printf("%s: DEBUG: pxe-pdhcp.c: ", (const char *)timer);
printf("add_dhcp_option() failed");
return putchar(10);
}
v8 = 262;
v9 = 8;
if ( (unsigned int)add_dhcp_option(&tp, 43LL, &v8, 3LL) == -1 )
{
*(_OWORD *)timer = 0LL;
goto LABEL_15;
}
v4 = (int)get_dhcp_packet_len(&tp);
if ( (_DWORD)v4 == (unsigned int)sendto(server_socket, &tp, v4, 0, &bcast_address, 0x10u) )
{
v13 = 0;
*(_OWORD *)timer = 0LL;
time(&v11);
localtime_r(&v11, &s);
strftime((char *)timer, 0x13uLL, "%b %d %H:%M:%S", &s);
printf("%s: DEBUG: pxe-pdhcp.c: ", (const char *)timer);
printf("dhcp_reply end");
}
else
{
v13 = 0;
*(_OWORD *)timer = 0LL;
time(&v11);
localtime_r(&v11, &s);
strftime((char *)timer, 0x13uLL, "%b %d %H:%M:%S", &s);
printf("%s: pxe-pdhcp.c: ", (const char *)timer);
v5 = _errno_location();
v6 = strerror(*v5);
printf("sendto() failed or was not complete: %s", v6);
}
return putchar(10);
}

original_code:
void dhcp_reply(struct dhcp_packet *p, struct sockaddr* client_address, socklen_t client_addrlen)
{
 int packet_len;
 u_char *opt;
 u_char optlen;
 struct dhcp_packet re;
 int res;
 { char _ts[20] = {0}; time_t _t; struct tm _tm; time(&_t); localtime_r(&_t, &_tm); strftime(_ts, 19, "%b %d %H:%M:%S", &_tm); printf("%s: DEBUG: " "pxe-pdhcp.c" ": ", _ts); printf("dhcp_reply start"); printf("\n"); };
 if (check_dhcp_packet(p) == -1) {
  { char _ts[20] = {0}; time_t _t; struct tm _tm; time(&_t); localtime_r(&_t, &_tm); strftime(_ts, 19, "%b %d %H:%M:%S", &_tm); printf("%s: DEBUG: " "pxe-pdhcp.c" ": ", _ts); printf("got a invalid dhcp packet"); printf("\n"); };
  return;
 }
 if (get_dhcp_message_type(p) == 1) {
  { char _ts[20] = {0}; time_t _t; struct tm _tm; time(&_t); localtime_r(&_t, &_tm); strftime(_ts, 19, "%b %d %H:%M:%S", &_tm); printf("%s: DEBUG: " "pxe-pdhcp.c" ": ", _ts); printf("got a DHCPDISCOVER on dhcp"); printf("\n"); };
 } else {
  { char _ts[20] = {0}; time_t _t; struct tm _tm; time(&_t); localtime_r(&_t, &_tm); strftime(_ts, 19, "%b %d %H:%M:%S", &_tm); printf("%s: DEBUG: " "pxe-pdhcp.c" ": ", _ts); printf("got a non-DHCPDISCOVER dhcp packet"); printf("\n"); };
  return;
 }
 res = get_dhcp_option(p, 60, &opt, &optlen);
 if (res == -1 || strncmp((char*)opt, "PXEClient", strlen("PXEClient")) != 0) {
  { char _ts[20] = {0}; time_t _t; struct tm _tm; time(&_t); localtime_r(&_t, &_tm); strftime(_ts, 19, "%b %d %H:%M:%S", &_tm); printf("%s: " "pxe-pdhcp.c" ": ", _ts); printf("got a non-PXE dhcp packet"); printf("\n"); };
  return;
 }
 init_packet(&re, p, 2);
 re.siaddr = tftp_ip;
 memcpy(re.chaddr, p->chaddr, sizeof(re.chaddr));
 strcpy(re.file, nbp_name);
 res = add_dhcp_option(&re, 60,
  (u_char*)"PXEClient",
  strlen("PXEClient"));
 if (res == -1) {
  { char _ts[20] = {0}; time_t _t; struct tm _tm; time(&_t); localtime_r(&_t, &_tm); strftime(_ts, 19, "%b %d %H:%M:%S", &_tm); printf("%s: DEBUG: " "pxe-pdhcp.c" ": ", _ts); printf("add_dhcp_option() failed"); printf("\n"); };
  return;
 }
 {
  u_char vop[3];
  vop[0] = 6;
  vop[1] = 1;
  vop[2] = 0x08;
  if (add_dhcp_option(&re, 43, vop, 3) == -1) {
   { char _ts[20] = {0}; time_t _t; struct tm _tm; time(&_t); localtime_r(&_t, &_tm); strftime(_ts, 19, "%b %d %H:%M:%S", &_tm); printf("%s: DEBUG: " "pxe-pdhcp.c" ": ", _ts); printf("add_dhcp_option() failed"); printf("\n"); };
   return;
  }
 }
 packet_len = get_dhcp_packet_len(&re);
 res = sendto(server_socket, &re, packet_len, 0,
  (struct sockaddr*)&bcast_address, sizeof(bcast_address));
 if (res != packet_len) {
  { char _ts[20] = {0}; time_t _t; struct tm _tm; time(&_t); localtime_r(&_t, &_tm); strftime(_ts, 19, "%b %d %H:%M:%S", &_tm); printf("%s: " "pxe-pdhcp.c" ": ", _ts); printf("sendto() failed or was not complete: %s", strerror((*__errno_location ()))); printf("\n"); };
  return;
 }
 { char _ts[20] = {0}; time_t _t; struct tm _tm; time(&_t); localtime_r(&_t, &_tm); strftime(_ts, 19, "%b %d %H:%M:%S", &_tm); printf("%s: DEBUG: " "pxe-pdhcp.c" ": ", _ts); printf("dhcp_reply end"); printf("\n"); };
}

canonical_original_code:
void dhcp_reply(struct dhcp_packet *p, struct sockaddr *client_address, unsigned int client_addrlen)
{
 int packet_len;
 unsigned char *opt;
 unsigned char optlen;
 struct dhcp_packet re;
 int res;
 { char _ts[20] = {0}; long _t; struct tm _tm; time(&_t); localtime_r(&_t, &_tm); strftime(_ts, 19, "%b %d %H:%M:%S", &_tm); printf("%s: DEBUG: " "pxe-pdhcp.c" ": ", _ts); printf("dhcp_reply start"); printf("\n"); };
 if (check_dhcp_packet(p) == -1) {
  { char _ts[20] = {0}; long _t; struct tm _tm; time(&_t); localtime_r(&_t, &_tm); strftime(_ts, 19, "%b %d %H:%M:%S", &_tm); printf("%s: DEBUG: " "pxe-pdhcp.c" ": ", _ts); printf("got a invalid dhcp packet"); printf("\n"); };
  return;
 }
 if (get_dhcp_message_type(p) == 1) {
  { char _ts[20] = {0}; long _t; struct tm _tm; time(&_t); localtime_r(&_t, &_tm); strftime(_ts, 19, "%b %d %H:%M:%S", &_tm); printf("%s: DEBUG: " "pxe-pdhcp.c" ": ", _ts); printf("got a DHCPDISCOVER on dhcp"); printf("\n"); };
 } else {
  { char _ts[20] = {0}; long _t; struct tm _tm; time(&_t); localtime_r(&_t, &_tm); strftime(_ts, 19, "%b %d %H:%M:%S", &_tm); printf("%s: DEBUG: " "pxe-pdhcp.c" ": ", _ts); printf("got a non-DHCPDISCOVER dhcp packet"); printf("\n"); };
  return;
 }
 res = get_dhcp_option(p, 60, &opt, &optlen);
 if (res == -1 || strncmp((char *)opt, "PXEClient", strlen("PXEClient")) != 0) {
  { char _ts[20] = {0}; long _t; struct tm _tm; time(&_t); localtime_r(&_t, &_tm); strftime(_ts, 19, "%b %d %H:%M:%S", &_tm); printf("%s: " "pxe-pdhcp.c" ": ", _ts); printf("got a non-PXE dhcp packet"); printf("\n"); };
  return;
 }
 init_packet(&re, p, 2);
 re.siaddr = tftp_ip;
 memcpy(re.chaddr, p->chaddr, sizeof(re.chaddr));
 strcpy(re.file, nbp_name);
 res = add_dhcp_option(&re, 60,
  (unsigned char *)"PXEClient",
  strlen("PXEClient"));
 if (res == -1) {
  { char _ts[20] = {0}; long _t; struct tm _tm; time(&_t); localtime_r(&_t, &_tm); strftime(_ts, 19, "%b %d %H:%M:%S", &_tm); printf("%s: DEBUG: " "pxe-pdhcp.c" ": ", _ts); printf("add_dhcp_option() failed"); printf("\n"); };
  return;
 }
 {
  unsigned char vop[3];
  vop[0] = 6;
  vop[1] = 1;
  vop[2] = 0x08;
  if (add_dhcp_option(&re, 43, vop, 3) == -1) {
   { char _ts[20] = {0}; long _t; struct tm _tm; time(&_t); localtime_r(&_t, &_tm); strftime(_ts, 19, "%b %d %H:%M:%S", &_tm); printf("%s: DEBUG: " "pxe-pdhcp.c" ": ", _ts); printf("add_dhcp_option() failed"); printf("\n"); };
   return;
  }
 }
 packet_len = get_dhcp_packet_len(&re);
 res = sendto(server_socket, &re, packet_len, 0,
  (struct sockaddr *)&bcast_address, sizeof(bcast_address));
 if (res != packet_len) {
  { char _ts[20] = {0}; long _t; struct tm _tm; time(&_t); localtime_r(&_t, &_tm); strftime(_ts, 19, "%b %d %H:%M:%S", &_tm); printf("%s: " "pxe-pdhcp.c" ": ", _ts); printf("sendto() failed or was not complete: %s", strerror((*__errno_location ()))); printf("\n"); };
  return;
 }
 { char _ts[20] = {0}; long _t; struct tm _tm; time(&_t); localtime_r(&_t, &_tm); strftime(_ts, 19, "%b %d %H:%M:%S", &_tm); printf("%s: DEBUG: " "pxe-pdhcp.c" ": ", _ts); printf("dhcp_reply end"); printf("\n"); };
}

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

variable_types: struct dhcp_packet { unsigned int op; unsigned int htype; unsigned int hlen; unsigned int hops; unsigned int xid; unsigned int secs; unsigned int flags; struct in_addr { unsigned int s_addr; } ciaddr; struct in_addr yiaddr; struct in_addr siaddr; struct in_addr giaddr; unsigned char chaddr[16]; char sname[64]; char file[128]; unsigned char options[-1]; }

variable_types: res int

variable_types:
vop
unsigned char [3]

user_defined_types: struct tm { int tm_sec; int tm_min; int tm_hour; int tm_mday; int tm_mon; int tm_year; int tm_wday; int tm_yday; int tm_isdst; long tm_gmtoff; char *tm_zone; }


pdhcp

decompiled_code:
void pdhcp()
{
int *v0; // rax
char *v1; // rax
socklen_t addr_len; // [rsp+0h] [rbp-654h] BYREF
time_t timer; // [rsp+4h] [rbp-650h] BYREF
struct sockaddr addr; // [rsp+Ch] [rbp-648h] BYREF
char s[16]; // [rsp+1Ch] [rbp-638h] BYREF
int v6; // [rsp+2Ch] [rbp-628h]
struct tm tp; // [rsp+3Ch] [rbp-618h] BYREF
char buf[1496]; // [rsp+7Ch] [rbp-5D8h] BYREF

while ( !stopflag )
{
while ( 1 )
{
memset(buf, 0, 0x5C0uLL);
addr_len = 16;
if ( (unsigned int)recvfrom(server_socket, buf, 0x5C0uLL, 0, &addr, &addr_len) == -1 )
break;
dhcp_reply((__int64)buf);
if ( stopflag )
return;
}
v6 = 0;
*(_OWORD *)s = 0LL;
time(&timer);
localtime_r(&timer, &tp);
strftime(s, 0x13uLL, "%b %d %H:%M:%S", &tp);
printf("%s: pxe-pdhcp.c: ", s);
v0 = _errno_location();
v1 = strerror(*v0);
printf("recvfrom() failed: %s", v1);
putchar(10);
}
}

canonical_decompiled_code:
void func4()
{
int *v0; // rax
char *v1; // rax
socklen_t addr_len; // [rsp+0h] [rbp-654h] BYREF
time_t timer; // [rsp+4h] [rbp-650h] BYREF
struct sockaddr addr; // [rsp+Ch] [rbp-648h] BYREF
char s[16]; // [rsp+1Ch] [rbp-638h] BYREF
int v6; // [rsp+2Ch] [rbp-628h]
struct tm tp; // [rsp+3Ch] [rbp-618h] BYREF
char buf[1496]; // [rsp+7Ch] [rbp-5D8h] BYREF

while ( !stopflag )
{
while ( 1 )
{
memset(buf, 0, 0x5C0uLL);
addr_len = 16;
if ( (unsigned int)recvfrom(server_socket, buf, 0x5C0uLL, 0, &addr, &addr_len) == -1 )
break;
func3((__int64)buf);
if ( stopflag )
return;
}
v6 = 0;
*(_OWORD *)s = 0LL;
time(&timer);
localtime_r(&timer, &tp);
strftime(s, 0x13uLL, "%b %d %H:%M:%S", &tp);
printf("%s: pxe-pdhcp.c: ", s);
v0 = _errno_location();
v1 = strerror(*v0);
printf("recvfrom() failed: %s", v1);
putchar(10);
}
}

original_code:
void pdhcp(void)
{
 struct dhcp_packet dhcp_p;
 struct sockaddr_in client_address;
 socklen_t client_addrlen;
 int res;
 while(!stopflag) {
  memset(&dhcp_p, 0, sizeof(dhcp_p));
  client_addrlen = sizeof(client_address);
  res = recvfrom(server_socket, &dhcp_p, sizeof(dhcp_p), 0,
   (struct sockaddr*)&client_address, &client_addrlen);
  if (res == -1) {
   { char _ts[20] = {0}; time_t _t; struct tm _tm; time(&_t); localtime_r(&_t, &_tm); strftime(_ts, 19, "%b %d %H:%M:%S", &_tm); printf("%s: " "pxe-pdhcp.c" ": ", _ts); printf("recvfrom() failed: %s", strerror((*__errno_location ()))); printf("\n"); };
   continue;
  }
  dhcp_reply(&dhcp_p, (struct sockaddr*)&client_address,
   client_addrlen);
 }
}

canonical_original_code:
void pdhcp()
{
 struct dhcp_packet dhcp_p;
 struct sockaddr_in client_address;
 unsigned int client_addrlen;
 int res;
 while(!stopflag) {
  memset(&dhcp_p, 0, sizeof(dhcp_p));
  client_addrlen = sizeof(client_address);
  res = recvfrom(server_socket, &dhcp_p, sizeof(dhcp_p), 0,
   (struct sockaddr *)&client_address, &client_addrlen);
  if (res == -1) {
   { char _ts[20] = {0}; long _t; struct tm _tm; time(&_t); localtime_r(&_t, &_tm); strftime(_ts, 19, "%b %d %H:%M:%S", &_tm); printf("%s: " "pxe-pdhcp.c" ": ", _ts); printf("recvfrom() failed: %s", strerror((*__errno_location ()))); printf("\n"); };
   continue;
  }
  dhcp_reply(&dhcp_p, (struct sockaddr *)&client_address,
   client_addrlen);
 }
}

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

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 init_socket()
{
int v0; // eax
__int64 result; // rax
int optval[3]; // [rsp+Ch] [rbp-Ch] BYREF

v0 = socket(2, 2, 0);
server_socket = v0;
if ( v0 == -1 || (optval[0] = 1, setsockopt(v0, 1, 6, optval, 4u) == -1) )
result = 0xFFFFFFFFLL;
else
result = (unsigned int)-(bind(server_socket, &server_address, 0x10u) == -1);
return result;
}

canonical_decompiled_code:
__int64 func5()
{
int v0; // eax
__int64 result; // rax
int optval[3]; // [rsp+Ch] [rbp-Ch] BYREF

v0 = socket(2, 2, 0);
server_socket = v0;
if ( v0 == -1 || (optval[0] = 1, setsockopt(v0, 1, 6, optval, 4u) == -1) )
result = 0xFFFFFFFFLL;
else
result = (unsigned int)-(bind(server_socket, &server_address, 0x10u) == -1);
return result;
}

original_code:
int init_socket(void)
{
 int res;
 int on;
 server_socket = socket(2, SOCK_DGRAM, 0);
 if (server_socket == -1) return -1;
 on = 1;
 res = setsockopt(server_socket, 1, 6, &on, sizeof(on));
 if (res == -1) return -1;
 res = bind(server_socket, (struct sockaddr*)&server_address,
   sizeof(server_address));
 if (res == -1) return -1;
 return 0;
}

canonical_original_code:
int init_socket()
{
 int res;
 int on;
 server_socket = socket(2, SOCK_DGRAM, 0);
 if (server_socket == -1) return -1;
 on = 1;
 res = setsockopt(server_socket, 1, 6, &on, sizeof(on));
 if (res == -1) return -1;
 res = bind(server_socket, (struct sockaddr *)&server_address,
   sizeof(server_address));
 if (res == -1) return -1;
 return 0;
}

variable_types: on int


decompiled_code:
int release_all()
{
return close(server_socket);
}

canonical_decompiled_code:
int func6()
{
return close(server_socket);
}

original_code:
void release_all(void)
{
 close(server_socket);
}

canonical_original_code:
void release_all()
{
 close(server_socket);
}


decompiled_code:
__int64 install_signal_handler()
{
struct sigaction v1; // [rsp+0h] [rbp-A8h] BYREF

v1.sa_handler = (__sighandler_t)signal_handler;
sigemptyset(&v1.sa_mask);
v1.sa_flags = 0;
if ( sigaction(15, &v1, 0LL) == -1 )
return 0xFFFFFFFFLL;
v1.sa_handler = (__sighandler_t)signal_handler;
sigemptyset(&v1.sa_mask);
v1.sa_flags = 0;
if ( sigaction(3, &v1, 0LL) == -1 )
return 0xFFFFFFFFLL;
v1.sa_handler = (__sighandler_t)signal_handler;
sigemptyset(&v1.sa_mask);
v1.sa_flags = 0;
return (unsigned int)-(sigaction(2, &v1, 0LL) == -1);
}

canonical_decompiled_code:
__int64 func7()
{
struct sigaction v1; // [rsp+0h] [rbp-A8h] BYREF

v1.sa_handler = (__sighandler_t)signal_handler;
sigemptyset(&v1.sa_mask);
v1.sa_flags = 0;
if ( sigaction(15, &v1, 0LL) == -1 )
return 0xFFFFFFFFLL;
v1.sa_handler = (__sighandler_t)signal_handler;
sigemptyset(&v1.sa_mask);
v1.sa_flags = 0;
if ( sigaction(3, &v1, 0LL) == -1 )
return 0xFFFFFFFFLL;
v1.sa_handler = (__sighandler_t)signal_handler;
sigemptyset(&v1.sa_mask);
v1.sa_flags = 0;
return (unsigned int)-(sigaction(2, &v1, 0LL) == -1);
}

original_code:
int install_signal_handler(void)
{
 struct sigaction action;
 action.__sigaction_handler.sa_handler = signal_handler;
 sigemptyset(&action.sa_mask);
 action.sa_flags = 0;
 if (sigaction(15, &action, ((void *)0)) == -1)
  return -1;
 action.__sigaction_handler.sa_handler = signal_handler;
 sigemptyset(&action.sa_mask);
 action.sa_flags = 0;
 if (sigaction(3, &action, ((void *)0)) == -1)
  return -1;
 action.__sigaction_handler.sa_handler = signal_handler;
 sigemptyset(&action.sa_mask);
 action.sa_flags = 0;
 if (sigaction(2, &action, ((void *)0)) == -1)
  return -1;
 return 0;
}

canonical_original_code:
int install_signal_handler()
{
 struct sigaction action;
 action.__sigaction_handler.sa_handler = signal_handler;
 sigemptyset(&action.sa_mask);
 action.sa_flags = 0;
 if (sigaction(15, &action, ((void *)0)) == -1)
  return -1;
 action.__sigaction_handler.sa_handler = signal_handler;
 sigemptyset(&action.sa_mask);
 action.sa_flags = 0;
 if (sigaction(3, &action, ((void *)0)) == -1)
  return -1;
 action.__sigaction_handler.sa_handler = signal_handler;
 sigemptyset(&action.sa_mask);
 action.sa_flags = 0;
 if (sigaction(2, &action, ((void *)0)) == -1)
  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; }


usage

decompiled_code:
size_t __fastcall usage(const char *a1)
{
fprintf(
stderr,
"usage: %s [-d] [-i interface] [-l listen address] [-t tftp address] [-b broadcast address] <nbp name>\n",
a1);
return fwrite("-i or (-l, -t and -b), and <nbp name> options are needed.\n", 1uLL, 0x3AuLL, stderr);
}

canonical_decompiled_code:
size_t __fastcall func8(const char *a1)
{
fprintf(
stderr,
"usage: %s [-d] [-i interface] [-l listen address] [-t tftp address] [-b broadcast address] <nbp name>\n",
a1);
return fwrite("-i or (-l, -t and -b), and <nbp name> options are needed.\n", 1uLL, 0x3AuLL, stderr);
}

original_code:
void usage(const char* prog)
{
 fprintf(stderr, "usage: %s  [-d] [-i interface] [-l listen address] [-t tftp address] [-b broadcast address] <nbp name>\n", prog);
 fprintf(stderr, "-i or (-l, -t and -b), and <nbp name> options are needed.\n");
}

canonical_original_code:
void usage(char *prog)
{
 fprintf(stderr, "usage: %s  [-d] [-i interface] [-l listen address] [-t tftp address] [-b broadcast address] <nbp name>\n", prog);
 fprintf(stderr, "-i or (-l, -t and -b), and <nbp name> options are needed.\n");
}

variable_types:
prog
char *


decompiled_code:
__int16 __fastcall parse_argv(int argc, char **argv)
{
int v2; // er15
int v3; // er14
char *v4; // r13
char v5; // r12
int v6; // eax
char v7; // al
char v8; // r12
int v9; // ebx
__int16 result; // ax
sa_family_t v11; // dx
const char *v12; // rdi
char v13[16]; // [rsp-Eh] [rbp-68h] BYREF
__int16 v14; // [rsp+2h] [rbp-58h]
in_addr_t v15; // [rsp+6h] [rbp-54h]

v2 = 0;
v3 = 0;
v4 = 0LL;
v5 = 0;
server_address = 0LL;
tftp_ip.s_addr = 0;
nbp_name = 0LL;
bcast_address = 0LL;
while ( 2 )
{
v6 = getopt(argc, argv, "i:l:b:t:d");
if ( v6 != -1 )
{
switch ( v6 )
{
case 'b':
if ( !inet_aton(optarg, (struct in_addr *)(unsigned int)((_DWORD)&bcast_address + 4)) )
goto LABEL_29;
v5 = 1;
continue;
case 'd':
foreground = 1;
continue;
case 'i':
v4 = optarg;
continue;
case 'l':
if ( !inet_aton(optarg, (struct in_addr *)(unsigned int)((_DWORD)&server_address + 4)) )
goto LABEL_29;
v2 = 1;
continue;
case 't':
if ( !inet_aton(optarg, &tftp_ip) )
{
LABEL_29:
perror(optarg);
exit(1);
}
v3 = 1;
continue;
default:
goto LABEL_28;
}
}
break;
}
if ( optind >= argc )
goto LABEL_28;
nbp_name = argv[optind];
v7 = v5;
v8 = v5 ^ 1;
if ( (unsigned __int8)v3 ^ 1 | (unsigned __int8)v2 ^ 1 | (unsigned __int8)v7 ^ 1 )
{
if ( v4 )
{
v9 = socket(2, 2, 0);
if ( v9 == -1 )
{
perror("socket() failed");
exit(1);
}
v14 = 2;
strncpy(v13, v4, 0xFuLL);
v13[15] = 0;
if ( v3 ^ 1 | v2 ^ 1 )
{
if ( ioctl(v9, 0x8915uLL, v13) == -1 )
{
v12 = "cannot get ip address of listen interface";
goto LABEL_32;
}
if ( !v2 )
*(_DWORD *)&server_address.sa_data[2] = v15;
if ( !v3 )
tftp_ip.s_addr = v15;
if ( !v8 )
goto LABEL_19;
}
if ( ioctl(v9, 0x8919uLL, v13) != -1 )
{
*(_DWORD *)&bcast_address.sa_data[2] = v15;
LABEL_19:
close(v9);
goto LABEL_20;
}
v12 = "cannot get broadcast address of listen interface";
LABEL_32:
perror(v12);
close(v9);
exit(1);
}
LABEL_28:
usage(*argv);
exit(1);
}
LABEL_20:
*(_WORD *)server_address.sa_data = _bswap_16(67);
server_address.sa_family = 2;
result = _bswap_16(68);
bcast_address.sa_family = v11;
*(_WORD *)bcast_address.sa_data = result;
return result;
}

canonical_decompiled_code:
__int16 __fastcall func9(int argc, char **argv)
{
int v2; // er15
int v3; // er14
char *v4; // r13
char v5; // r12
int v6; // eax
char v7; // al
char v8; // r12
int v9; // ebx
__int16 result; // ax
sa_family_t v11; // dx
const char *v12; // rdi
char v13[16]; // [rsp-Eh] [rbp-68h] BYREF
__int16 v14; // [rsp+2h] [rbp-58h]
in_addr_t v15; // [rsp+6h] [rbp-54h]

v2 = 0;
v3 = 0;
v4 = 0LL;
v5 = 0;
server_address = 0LL;
tftp_ip.s_addr = 0;
nbp_name = 0LL;
bcast_address = 0LL;
while ( 2 )
{
v6 = getopt(argc, argv, "i:l:b:t:d");
if ( v6 != -1 )
{
switch ( v6 )
{
case 'b':
if ( !inet_aton(optarg, (struct in_addr *)(unsigned int)((_DWORD)&bcast_address + 4)) )
goto LABEL_29;
v5 = 1;
continue;
case 'd':
foreground = 1;
continue;
case 'i':
v4 = optarg;
continue;
case 'l':
if ( !inet_aton(optarg, (struct in_addr *)(unsigned int)((_DWORD)&server_address + 4)) )
goto LABEL_29;
v2 = 1;
continue;
case 't':
if ( !inet_aton(optarg, &tftp_ip) )
{
LABEL_29:
perror(optarg);
exit(1);
}
v3 = 1;
continue;
default:
goto LABEL_28;
}
}
break;
}
if ( optind >= argc )
goto LABEL_28;
nbp_name = argv[optind];
v7 = v5;
v8 = v5 ^ 1;
if ( (unsigned __int8)v3 ^ 1 | (unsigned __int8)v2 ^ 1 | (unsigned __int8)v7 ^ 1 )
{
if ( v4 )
{
v9 = socket(2, 2, 0);
if ( v9 == -1 )
{
perror("socket() failed");
exit(1);
}
v14 = 2;
strncpy(v13, v4, 0xFuLL);
v13[15] = 0;
if ( v3 ^ 1 | v2 ^ 1 )
{
if ( ioctl(v9, 0x8915uLL, v13) == -1 )
{
v12 = "cannot get ip address of listen interface";
goto LABEL_32;
}
if ( !v2 )
*(_DWORD *)&server_address.sa_data[2] = v15;
if ( !v3 )
tftp_ip.s_addr = v15;
if ( !v8 )
goto LABEL_19;
}
if ( ioctl(v9, 0x8919uLL, v13) != -1 )
{
*(_DWORD *)&bcast_address.sa_data[2] = v15;
LABEL_19:
close(v9);
goto LABEL_20;
}
v12 = "cannot get broadcast address of listen interface";
LABEL_32:
perror(v12);
close(v9);
exit(1);
}
LABEL_28:
func8(*argv);
exit(1);
}
LABEL_20:
*(_WORD *)server_address.sa_data = func1(67);
server_address.sa_family = 2;
result = func1(68);
bcast_address.sa_family = v11;
*(_WORD *)bcast_address.sa_data = result;
return result;
}

original_code:
void parse_argv(int argc, char* argv[])
{
 int opt;
 char* listen_dev;
 int set_server_address = 0;
 int set_bcast_address = 0;
 int set_tftp_ip = 0;
 memset(&server_address, 0, sizeof(server_address));
 memset(&bcast_address, 0, sizeof(bcast_address));
 memset(&tftp_ip, 0, sizeof(tftp_ip));
 listen_dev = ((void *)0);
 nbp_name = ((void *)0);
 while ((opt = getopt(argc, argv, "i:l:b:t:d")) != -1) {
  switch(opt) {
  case 'i':
   listen_dev = optarg;
   break;
  case 'l':
   if (!inet_aton(optarg, &server_address.sin_addr)) {
    perror(optarg);
    exit(1);
   }
   set_server_address = 1;
   break;
  case 'b':
   if (!inet_aton(optarg, &bcast_address.sin_addr)) {
    perror(optarg);
    exit(1);
   }
   set_bcast_address = 1;
   break;
  case 't':
   if (!inet_aton(optarg, &tftp_ip)) {
    perror(optarg);
    exit(1);
   }
   set_tftp_ip = 1;
   break;
  case 'd':
   foreground = 1;
   break;
  default:
   usage(argv[0]);
   exit(1);
  }
 }
 if (optind >= argc) {
  usage(argv[0]);
  exit(1);
 }
 nbp_name = argv[optind];
 if (!set_server_address || !set_tftp_ip || !set_bcast_address) {
  struct ifreq ifr;
  int s;
  if (!listen_dev) {
   usage(argv[0]);
   exit(1);
  }
  s = socket(2, SOCK_DGRAM, 0);
  if (s == -1) {
   perror("socket() failed");
   exit(1);
  }
  ifr.ifr_ifru.ifru_addr.sa_family = 2;
  strncpy(ifr.ifr_ifrn.ifrn_name, listen_dev, 16 -1);
  ifr.ifr_ifrn.ifrn_name[16 -1] = '\0';
  if (!set_server_address || !set_tftp_ip) {
   if (ioctl(s, 0x8915, &ifr) == -1) {
    perror("cannot get ip address of listen interface");
    close(s);
    exit(1);
   }
   if (!set_server_address)
    server_address.sin_addr = ((struct sockaddr_in*)&ifr.ifr_ifru.ifru_addr)->sin_addr;
   if (!set_tftp_ip)
    tftp_ip = ((struct sockaddr_in*)&ifr.ifr_ifru.ifru_addr)->sin_addr;
  }
  if (!set_bcast_address) {
   if (ioctl(s, 0x8919, &ifr) == -1) {
    perror("cannot get broadcast address of listen interface");
    close(s);
    exit(1);
   }
   bcast_address.sin_addr =
    ((struct sockaddr_in*)&ifr.ifr_ifru.ifru_broadaddr)->sin_addr;
  }
  close(s);
 }
 server_address.sin_port = ntohs(67);
 server_address.sin_family = 2;
 bcast_address.sin_port = ntohs(68);
 bcast_address.sin_family = 2;
}

canonical_original_code:
void parse_argv(int argc, char *argv[])
{
 int opt;
 char *listen_dev;
 int set_server_address = 0;
 int set_bcast_address = 0;
 int set_tftp_ip = 0;
 memset(&server_address, 0, sizeof(server_address));
 memset(&bcast_address, 0, sizeof(bcast_address));
 memset(&tftp_ip, 0, sizeof(tftp_ip));
 listen_dev = ((void *)0);
 nbp_name = ((void *)0);
 while ((opt = getopt(argc, argv, "i:l:b:t:d")) != -1) {
  switch(opt) {
  case 'i':
   listen_dev = optarg;
   break;
  case 'l':
   if (!inet_aton(optarg, &server_address.sin_addr)) {
    perror(optarg);
    exit(1);
   }
   set_server_address = 1;
   break;
  case 'b':
   if (!inet_aton(optarg, &bcast_address.sin_addr)) {
    perror(optarg);
    exit(1);
   }
   set_bcast_address = 1;
   break;
  case 't':
   if (!inet_aton(optarg, &tftp_ip)) {
    perror(optarg);
    exit(1);
   }
   set_tftp_ip = 1;
   break;
  case 'd':
   foreground = 1;
   break;
  default:
   usage(argv[0]);
   exit(1);
  }
 }
 if (optind >= argc) {
  usage(argv[0]);
  exit(1);
 }
 nbp_name = argv[optind];
 if (!set_server_address || !set_tftp_ip || !set_bcast_address) {
  struct ifreq ifr;
  int s;
  if (!listen_dev) {
   usage(argv[0]);
   exit(1);
  }
  s = socket(2, SOCK_DGRAM, 0);
  if (s == -1) {
   perror("socket() failed");
   exit(1);
  }
  ifr.ifr_ifru.ifru_addr.sa_family = 2;
  strncpy(ifr.ifr_ifrn.ifrn_name, listen_dev, 16 -1);
  ifr.ifr_ifrn.ifrn_name[16 -1] = '\0';
  if (!set_server_address || !set_tftp_ip) {
   if (ioctl(s, 0x8915, &ifr) == -1) {
    perror("cannot get ip address of listen interface");
    close(s);
    exit(1);
   }
   if (!set_server_address)
    server_address.sin_addr = ((struct sockaddr_in *)&ifr.ifr_ifru.ifru_addr)->sin_addr;
   if (!set_tftp_ip)
    tftp_ip = ((struct sockaddr_in *)&ifr.ifr_ifru.ifru_addr)->sin_addr;
  }
  if (!set_bcast_address) {
   if (ioctl(s, 0x8919, &ifr) == -1) {
    perror("cannot get broadcast address of listen interface");
    close(s);
    exit(1);
   }
   bcast_address.sin_addr =
    ((struct sockaddr_in *)&ifr.ifr_ifru.ifru_broadaddr)->sin_addr;
  }
  close(s);
 }
 server_address.sin_port = ntohs(67);
 server_address.sin_family = 2;
 bcast_address.sin_port = ntohs(68);
 bcast_address.sin_family = 2;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: opt int

variable_types: struct ifreq { union { char ifrn_name[16]; } ifr_ifrn; union { struct sockaddr { unsigned short sa_family; char sa_data[14]; } ifru_addr; struct sockaddr ifru_dstaddr; struct sockaddr ifru_broadaddr; struct sockaddr ifru_netmask; struct sockaddr ifru_hwaddr; short ifru_flags; int ifru_ivalue; int ifru_mtu; struct ifmap { unsigned long mem_start; unsigned long mem_end; unsigned short base_addr; unsigned char irq; unsigned char dma; unsigned char port; } ifru_map; char ifru_slave[16]; char ifru_newname[16]; char *ifru_data; } ifr_ifru; }

variable_types: s int

user_defined_types: struct ifreq { union { char ifrn_name[16]; } ifr_ifrn; union { struct sockaddr ifru_addr; struct sockaddr ifru_dstaddr; struct sockaddr ifru_broadaddr; struct sockaddr ifru_netmask; struct sockaddr ifru_hwaddr; short ifru_flags; int ifru_ivalue; int ifru_mtu; struct ifmap ifru_map; char ifru_slave[16]; char ifru_newname[16]; char *ifru_data; } ifr_ifru; }


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned __int16 v3; // bx
char *v4; // rax
unsigned __int16 v5; // bx
char *v6; // rax
char *v7; // rax

parse_argv(argc, (char **)argv);
v3 = _bswap_16(*(_WORD *)server_address.sa_data);
v4 = inet_ntoa(*(struct in_addr *)&server_address.sa_data[2]);
printf("listen address: %s:%d\n", v4, v3);
v5 = _bswap_16(*(_WORD *)bcast_address.sa_data);
v6 = inet_ntoa(*(struct in_addr *)&bcast_address.sa_data[2]);
printf("broadcast address %s:%d\n", v6, v5);
v7 = inet_ntoa(tftp_ip);
printf("tftp address: %s\n", v7);
printf("nbp name: %s\n", nbp_name);
if ( (unsigned int)install_signal_handler() == -1 )
{
perror("sigaction() failed");
exit(-1);
}
if ( (unsigned int)init_socket() == -1 )
{
perror("init_socket()");
release_all();
exit(1);
}
if ( !foreground )
daemon(0, 0);
pdhcp();
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned __int16 v3; // bx
char *v4; // rax
unsigned __int16 v5; // bx
char *v6; // rax
char *v7; // rax

func9(argc, (char **)argv);
v3 = func1(*(_WORD *)server_address.sa_data);
v4 = inet_ntoa(*(struct in_addr *)&server_address.sa_data[2]);
printf("listen address: %s:%d\n", v4, v3);
v5 = func1(*(_WORD *)bcast_address.sa_data);
v6 = inet_ntoa(*(struct in_addr *)&bcast_address.sa_data[2]);
printf("broadcast address %s:%d\n", v6, v5);
v7 = inet_ntoa(tftp_ip);
printf("tftp address: %s\n", v7);
printf("nbp name: %s\n", nbp_name);
if ( (unsigned int)func7() == -1 )
{
perror("sigaction() failed");
exit(-1);
}
if ( (unsigned int)func5() == -1 )
{
perror("init_socket()");
func6();
exit(1);
}
if ( !foreground )
daemon(0, 0);
func4();
return 0;
}

original_code:
int main(int argc, char* argv[])
{
 parse_argv(argc, argv);
 printf("listen address:     %s:%d\n", inet_ntoa(server_address.sin_addr),
  ntohs(server_address.sin_port));
 printf("broadcast address   %s:%d\n", inet_ntoa(bcast_address.sin_addr),
  ntohs(bcast_address.sin_port));
 printf("tftp address:       %s\n", inet_ntoa(tftp_ip));
 printf("nbp name:           %s\n", nbp_name);
 if (install_signal_handler() == -1) {
  perror("sigaction() failed");
  exit(-1);
 }
 if (init_socket() == -1) {
  perror("init_socket()");
  release_all();
  exit(1);
 }
 if (foreground) {
  pdhcp();
 } else {
  daemon(0,0);
  pdhcp();
 }
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
 parse_argv(argc, argv);
 printf("listen address:     %s:%d\n", inet_ntoa(server_address.sin_addr),
  ntohs(server_address.sin_port));
 printf("broadcast address   %s:%d\n", inet_ntoa(bcast_address.sin_addr),
  ntohs(bcast_address.sin_port));
 printf("tftp address:       %s\n", inet_ntoa(tftp_ip));
 printf("nbp name:           %s\n", nbp_name);
 if (install_signal_handler() == -1) {
  perror("sigaction() failed");
  exit(-1);
 }
 if (init_socket() == -1) {
  perror("init_socket()");
  release_all();
  exit(1);
 }
 if (foreground) {
  pdhcp();
 } else {
  daemon(0,0);
  pdhcp();
 }
 return 0;
}


privatemsg

decompiled_code:
__int64 __fastcall privatemsg(char *src, __int64 a2, unsigned int a3)
{
__int64 result; // rax
int v5; // eax
size_t v6; // rax
size_t v7; // rax
size_t v8; // rax
size_t v9; // rbx
char vars0[1024]; // [rsp+0h] [rbp+0h] BYREF
char dest[1064]; // [rsp+400h] [rbp+400h] BYREF

result = 0LL;
memset(vars0, 0, sizeof(vars0));
memset(dest, 0, 0x400uLL);
if ( !mute )
{
v5 = usernamecount(a2);
strncpy(dest, (const char *)(a2 + 1), v5);
strcpy(vars0, "PRIVMSG ");
v6 = strnlen(vars0, 0x400uLL);
strncat(vars0, dest, 1023 - v6);
v7 = strnlen(vars0, 0x400uLL);
strncat(vars0, " :", 1023 - v7);
v8 = strnlen(vars0, 0x400uLL);
strncat(vars0, src, 1023 - v8);
v9 = 1023 - strnlen(vars0, 0x400uLL);
strncat(vars0, "\r\n", v9);
if ( logFlag )
msglogprint(vars0);
result = (unsigned int)-((unsigned int)writeserver(vars0, a3) == -1);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(char *src, __int64 a2, unsigned int a3)
{
__int64 result; // rax
int v5; // eax
size_t v6; // rax
size_t v7; // rax
size_t v8; // rax
size_t v9; // rbx
char vars0[1024]; // [rsp+0h] [rbp+0h] BYREF
char dest[1064]; // [rsp+400h] [rbp+400h] BYREF

result = 0LL;
memset(vars0, 0, sizeof(vars0));
memset(dest, 0, 0x400uLL);
if ( !mute )
{
v5 = usernamecount(a2);
strncpy(dest, (const char *)(a2 + 1), v5);
strcpy(vars0, "PRIVMSG ");
v6 = strnlen(vars0, 0x400uLL);
strncat(vars0, dest, 1023 - v6);
v7 = strnlen(vars0, 0x400uLL);
strncat(vars0, " :", 1023 - v7);
v8 = strnlen(vars0, 0x400uLL);
strncat(vars0, src, 1023 - v8);
v9 = 1023 - strnlen(vars0, 0x400uLL);
strncat(vars0, "\r\n", v9);
if ( logFlag )
msglogprint(vars0);
result = (unsigned int)-((unsigned int)writeserver(vars0, a3) == -1);
}
return result;
}

original_code:
int privatemsg(char *msg, char *serverline, int sckt)
{
    char send[1024];
    char user[1024];
    memset(send, 0, 1024);
    memset(user, 0, 1024);
    if (!mute) {
        strncpy(user, serverline+1, (size_t)usernamecount(serverline));
        snprintf(send, 1024, "%s", "PRIVMSG ");
        strncat(send, user, 1024 -strnlen(send, 1024)-1);
        strncat(send, " :", 1024 -strnlen(send, 1024)-1);
        strncat(send, msg, 1024 -strnlen(send, 1024)-1);
        strncat(send, "\r\n", 1024 -strnlen(send, 1024)-1);
        if (logFlag) {
            msglogprint(send);
        }
        if (writeserver(send, sckt) == -1) {
            return -1;
        }
    } else {
    }
    return 0;
}

canonical_original_code:
int privatemsg(char *msg, char *serverline, int sckt)
{
    char send[1024];
    char user[1024];
    memset(send, 0, 1024);
    memset(user, 0, 1024);
    if (!mute) {
        strncpy(user, serverline+1, (unsigned long)usernamecount(serverline));
        snprintf(send, 1024, "%s", "PRIVMSG ");
        strncat(send, user, 1024 -strnlen(send, 1024)-1);
        strncat(send, " :", 1024 -strnlen(send, 1024)-1);
        strncat(send, msg, 1024 -strnlen(send, 1024)-1);
        strncat(send, "\r\n", 1024 -strnlen(send, 1024)-1);
        if (logFlag) {
            msglogprint(send);
        }
        if (writeserver(send, sckt) == -1) {
            return -1;
        }
    } else {
    }
    return 0;
}

variable_types:
msg
char *

variable_types:
serverline
char *

variable_types: sckt int

variable_types:
send
char [1024]

variable_types:
user
char [1024]


sendcommand

decompiled_code:
__int64 __fastcall sendcommand(__int64 a1, unsigned int a2)
{
__int64 result; // rax
_BYTE savedregs[1048]; // [rsp+0h] [rbp+0h] BYREF

memset(savedregs, 0, 0x400uLL);
snprintf(savedregs, 0x400uLL, "%s", a1);
result = getmsg(savedregs, "!send ");
if ( (_DWORD)result != -1 )
result = (unsigned int)-((unsigned int)writeserver(savedregs, a2) == -1);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, unsigned int a2)
{
__int64 result; // rax
_BYTE savedregs[1048]; // [rsp+0h] [rbp+0h] BYREF

memset(savedregs, 0, 0x400uLL);
snprintf(savedregs, 0x400uLL, "%s", a1);
result = getmsg(savedregs, "!send ");
if ( (_DWORD)result != -1 )
result = (unsigned int)-((unsigned int)writeserver(savedregs, a2) == -1);
return result;
}

original_code:
int sendcommand(char *s, int sckt)
{
    char send[1024];
    memset(send, 0, 1024);
    snprintf(send, 1024, "%s", s);
    if (getmsg(send, "!send ") == -1) {
        return -1;
    }
    if (writeserver(send, sckt) == -1) {
        return -1;
    }
    return 0;
}

variable_types:
s
char *


getIP

decompiled_code:
__int64 __fastcall getIP(_QWORD *a1, const char *a2, unsigned int a3)
{
size_t v4; // rax
size_t v5; // rax
int v7[266]; // [rsp+0h] [rbp-428h] BYREF

memset(v7, 0, 0x400uLL);
qmemcpy(v7, "WHOIS ", 6);
v4 = strnlen((const char *)v7, 0x400uLL);
strncat((char *)v7, a2, 1023 - v4);
v5 = strnlen((const char *)v7, 0x400uLL);
strncat((char *)v7, "\r\n", 1023 - v5);
if ( (unsigned int)writeserver(v7, a3) != -1 )
{
while ( 1 )
{
*a1 = 0LL;
a1[127] = 0LL;
memset(
(void *)((unsigned __int64)(a1 + 1) & 0xFFFFFFFFFFFFFFF8LL),
0,
8LL * (((unsigned int)a1 - (((_DWORD)a1 + 8) & 0xFFFFFFF8) + 1024) >> 3));
if ( (unsigned int)readserver(a1, a3) == -1 )
break;
if ( (unsigned int)strfind(a1, "is connecting from") )
return 0LL;
}
}
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func2(_QWORD *a1, const char *a2, unsigned int a3)
{
size_t v4; // rax
size_t v5; // rax
int v7[266]; // [rsp+0h] [rbp-428h] BYREF

memset(v7, 0, 0x400uLL);
qmemcpy(v7, "WHOIS ", 6);
v4 = strnlen((const char *)v7, 0x400uLL);
strncat((char *)v7, a2, 1023 - v4);
v5 = strnlen((const char *)v7, 0x400uLL);
strncat((char *)v7, "\r\n", 1023 - v5);
if ( (unsigned int)writeserver(v7, a3) != -1 )
{
while ( 1 )
{
*a1 = 0LL;
a1[127] = 0LL;
memset(
(void *)((unsigned __int64)(a1 + 1) & 0xFFFFFFFFFFFFFFF8LL),
0,
8LL * (((unsigned int)a1 - (((_DWORD)a1 + 8) & 0xFFFFFFF8) + 1024) >> 3));
if ( (unsigned int)readserver(a1, a3) == -1 )
break;
if ( (unsigned int)strfind(a1, "is connecting from") )
return 0LL;
}
}
return 0xFFFFFFFFLL;
}

original_code:
int getIP(char *ip, char *nick, int sckt)
{
    char send[1024];
    memset(send, 0, 1024);
    snprintf(send, 1024, "%s", "WHOIS ");
    strncat(send, nick, 1024 -strnlen(send, 1024)-1);
    strncat(send, "\r\n", 1024 -strnlen(send, 1024)-1);
    if (writeserver(send, sckt) == -1) {
        return -1;
    }
    while (1 == 1) {
        memset(ip, 0, 1024);
        if (readserver(ip, sckt) == -1) {
            return -1;
        }
        if (strfind(ip, "is connecting from")) {
            break;
        }
    }
    return 0;
}

variable_types:
ip
char *

variable_types:
nick
char *


react

decompiled_code:
__int64 __fastcall react(unsigned int a1, const char *a2, __int64 a3, __int64 a4)
{
size_t v5; // rax
unsigned int v6; // er13
unsigned int v8; // edx
int v9; // eax
unsigned int v10; // eax
__int64 v11[128]; // [rsp+0h] [rbp-838h] BYREF
char s[1080]; // [rsp+400h] [rbp-438h] BYREF

memset(v11, 0, sizeof(v11));
memset(s, 0, 0x400uLL);
v11[0] = 0x2047534D56495250LL;
v5 = strnlen((const char *)v11, 0x400uLL);
strncat((char *)v11, a2, 1023 - v5);
if ( (unsigned int)strfind(a4, "PING :") )
{
v6 = sendpong(a1, a4);
}
else
{
v6 = logFlag;
if ( logFlag )
{
v6 = 0;
msglogprint(a4);
if ( !(unsigned int)strfind(a4, v11) )
return v6;
goto LABEL_6;
}
}
if ( !(unsigned int)strfind(a4, v11) )
return v6;
LABEL_6:
if ( (unsigned int)strfind(a4, ":!disconnect") )
{
if ( (unsigned int)checkPass(a4) )
{
v6 = 1;
disconnectirc(a1);
return v6;
}
goto LABEL_9;
}
if ( (unsigned int)strfind(a4, ":!reconnect") )
{
if ( (unsigned int)checkPass(a4) )
{
v6 = -1;
disconnectirc(a1);
return v6;
}
goto LABEL_9;
}
if ( (unsigned int)strfind(a4, ":!ip") )
{
v9 = checkPass(a4);
v8 = a1;
if ( !v9 )
return (unsigned int)privatemsg("No!", a4, v8);
v6 = getIP(s, a2, a1);
if ( v6 == -1 )
{
errprint("getIP()");
return v6;
}
return (unsigned int)privatemsg(s, a4, a1);
}
if ( (unsigned int)strfind(a4, "!mute") )
{
if ( (unsigned int)checkPass(a4) )
{
mute = 1;
return (unsigned int)privatemsg("Muted.", a4, a1);
}
goto LABEL_9;
}
if ( (unsigned int)strfind(a4, "!unmute") )
{
if ( (unsigned int)checkPass(a4) )
{
mute = 0;
return (unsigned int)privatemsg("Unmuted.", a4, a1);
}
goto LABEL_9;
}
if ( (unsigned int)strfind(a4, ":!os") )
{
memset(s, 0, 0x400uLL);
osinfo(s);
return (unsigned int)privatemsg(s, a4, a1);
}
if ( (unsigned int)strfind(a4, ":!version") )
{
memset(s, 0, 0x400uLL);
snprintf(s, 0x400uLL, "Version: %s", "1.2.3");
return (unsigned int)privatemsg(s, a4, a1);
}
if ( (unsigned int)strfind(a4, "!log") )
{
if ( (unsigned int)checkPass(a4) )
{
if ( logFlag )
return (unsigned int)privatemsg("Already logging.", a4, a1);
logFlag = 1;
msglogprint("--- Log opened ---\n");
return (unsigned int)privatemsg("Logging all messages.", a4, a1);
}
LABEL_9:
v8 = a1;
return (unsigned int)privatemsg("No!", a4, v8);
}
if ( !(unsigned int)strfind(a4, "!dontlog") || !(unsigned int)checkPass(a4) )
goto LABEL_9;
if ( !logFlag )
return (unsigned int)privatemsg("I'm not logging.", a4, a1);
v10 = privatemsg("Not logging anymore.", a4, a1);
logFlag = 0;
v6 = v10;
msglogprint("--- Log closed ---\n");
return v6;
}

canonical_decompiled_code:
__int64 __fastcall func3(unsigned int a1, const char *a2, __int64 a3, __int64 a4)
{
size_t v5; // rax
unsigned int v6; // er13
unsigned int v8; // edx
int v9; // eax
unsigned int v10; // eax
__int64 v11[128]; // [rsp+0h] [rbp-838h] BYREF
char s[1080]; // [rsp+400h] [rbp-438h] BYREF

memset(v11, 0, sizeof(v11));
memset(s, 0, 0x400uLL);
v11[0] = 0x2047534D56495250LL;
v5 = strnlen((const char *)v11, 0x400uLL);
strncat((char *)v11, a2, 1023 - v5);
if ( (unsigned int)strfind(a4, "PING :") )
{
v6 = sendpong(a1, a4);
}
else
{
v6 = logFlag;
if ( logFlag )
{
v6 = 0;
msglogprint(a4);
if ( !(unsigned int)strfind(a4, v11) )
return v6;
goto LABEL_6;
}
}
if ( !(unsigned int)strfind(a4, v11) )
return v6;
LABEL_6:
if ( (unsigned int)strfind(a4, ":!disconnect") )
{
if ( (unsigned int)checkPass(a4) )
{
v6 = 1;
disconnectirc(a1);
return v6;
}
goto LABEL_9;
}
if ( (unsigned int)strfind(a4, ":!reconnect") )
{
if ( (unsigned int)checkPass(a4) )
{
v6 = -1;
disconnectirc(a1);
return v6;
}
goto LABEL_9;
}
if ( (unsigned int)strfind(a4, ":!ip") )
{
v9 = checkPass(a4);
v8 = a1;
if ( !v9 )
return (unsigned int)func0("No!", a4, v8);
v6 = func2(s, a2, a1);
if ( v6 == -1 )
{
errprint("getIP()");
return v6;
}
return (unsigned int)func0(s, a4, a1);
}
if ( (unsigned int)strfind(a4, "!mute") )
{
if ( (unsigned int)checkPass(a4) )
{
mute = 1;
return (unsigned int)func0("Muted.", a4, a1);
}
goto LABEL_9;
}
if ( (unsigned int)strfind(a4, "!unmute") )
{
if ( (unsigned int)checkPass(a4) )
{
mute = 0;
return (unsigned int)func0("Unmuted.", a4, a1);
}
goto LABEL_9;
}
if ( (unsigned int)strfind(a4, ":!os") )
{
memset(s, 0, 0x400uLL);
osinfo(s);
return (unsigned int)func0(s, a4, a1);
}
if ( (unsigned int)strfind(a4, ":!version") )
{
memset(s, 0, 0x400uLL);
snprintf(s, 0x400uLL, "Version: %s", "1.2.3");
return (unsigned int)func0(s, a4, a1);
}
if ( (unsigned int)strfind(a4, "!log") )
{
if ( (unsigned int)checkPass(a4) )
{
if ( logFlag )
return (unsigned int)func0("Already logging.", a4, a1);
logFlag = 1;
msglogprint("--- Log opened ---\n");
return (unsigned int)func0("Logging all messages.", a4, a1);
}
LABEL_9:
v8 = a1;
return (unsigned int)func0("No!", a4, v8);
}
if ( !(unsigned int)strfind(a4, "!dontlog") || !(unsigned int)checkPass(a4) )
goto LABEL_9;
if ( !logFlag )
return (unsigned int)func0("I'm not logging.", a4, a1);
v10 = func0("Not logging anymore.", a4, a1);
logFlag = 0;
v6 = v10;
msglogprint("--- Log closed ---\n");
return v6;
}

original_code:
int react (int sckt, char *nick, char *channel, char *serverline)
{
    char privmsg[1024];
    char tmp[1024];
    int ret = 0;
    memset(privmsg, 0, 1024);
    memset(tmp, 0, 1024);
    snprintf(privmsg, 1024, "%s", "PRIVMSG ");
    strncat(privmsg, nick, 1024 -strnlen(privmsg, 1024)-1);
    if (strfind(serverline, "PING :")) {
        ret = sendpong(sckt, serverline);
    } else if (logFlag) {
        msglogprint(serverline);
    }
    if (strfind(serverline, privmsg)) {
        if (strfind(serverline, ":!disconnect")) {
            if (checkPass(serverline)) {
                disconnectirc(sckt);
                ret = 1;
            } else {
                ret = privatemsg("No!", serverline, sckt);
            }
        } else if (strfind(serverline, ":!reconnect")) {
            if (checkPass(serverline)) {
                disconnectirc(sckt);
                ret = -1;
            } else {
                ret = privatemsg("No!", serverline, sckt);
            }
        } else if (strfind(serverline, ":!ip")) {
            if (checkPass(serverline)) {
                if (getIP(tmp, nick, sckt) == -1) {
                    errprint("getIP()");
                    ret = -1;
                } else {
                    ret = privatemsg(tmp, serverline, sckt);
                }
            } else {
                ret = privatemsg("No!", serverline, sckt);
            }
        } else if (strfind(serverline, "!mute")) {
            if (checkPass(serverline)) {
                mute = 1;
                ret = privatemsg("Muted.", serverline, sckt);
            } else {
                ret = privatemsg("No!", serverline, sckt);
            }
        } else if (strfind(serverline, "!unmute")) {
            if (checkPass(serverline)) {
                mute = 0;
                ret = privatemsg("Unmuted.", serverline, sckt);
            } else {
                ret = privatemsg("No!", serverline, sckt);
            }
        } else if (strfind(serverline, ":!os")) {
            memset(tmp, 0, 1024);
            osinfo(tmp);
            ret = privatemsg(tmp, serverline, sckt);
        } else if (strfind(serverline, ":!version")) {
            memset(tmp, 0, 1024);
            snprintf(tmp, 1024, "Version: %s", "1.2.3");
            ret = privatemsg(tmp, serverline, sckt);
        } else if (strfind(serverline, "!log")) {
            if (checkPass(serverline)) {
                if (logFlag) {
                    ret = privatemsg("Already logging.", serverline, sckt);
                } else {
                    logFlag = 1;
                    msglogprint("--- Log opened ---\n");
                    ret = privatemsg("Logging all messages.", serverline, sckt);
                }
            } else {
                ret = privatemsg("No!", serverline, sckt);
            }
        } else if (strfind(serverline, "!dontlog")) {
            if (checkPass(serverline)) {
                if (logFlag) {
                    ret = privatemsg("Not logging anymore.", serverline, sckt);
                    logFlag = 0;
                    msglogprint("--- Log closed ---\n");
                } else {
                    ret = privatemsg("I'm not logging.", serverline, sckt);
                }
            } else {
                ret = privatemsg("No!", serverline, sckt);
            }
        } else {
            ret = privatemsg("No!", serverline, sckt);
        }
    }
    return ret;
}

canonical_original_code:
int react(int sckt, char *nick, char *channel, char *serverline)
{
    char privmsg[1024];
    char tmp[1024];
    int ret = 0;
    memset(privmsg, 0, 1024);
    memset(tmp, 0, 1024);
    snprintf(privmsg, 1024, "%s", "PRIVMSG ");
    strncat(privmsg, nick, 1024 -strnlen(privmsg, 1024)-1);
    if (strfind(serverline, "PING :")) {
        ret = sendpong(sckt, serverline);
    } else if (logFlag) {
        msglogprint(serverline);
    }
    if (strfind(serverline, privmsg)) {
        if (strfind(serverline, ":!disconnect")) {
            if (checkPass(serverline)) {
                disconnectirc(sckt);
                ret = 1;
            } else {
                ret = privatemsg("No!", serverline, sckt);
            }
        } else if (strfind(serverline, ":!reconnect")) {
            if (checkPass(serverline)) {
                disconnectirc(sckt);
                ret = -1;
            } else {
                ret = privatemsg("No!", serverline, sckt);
            }
        } else if (strfind(serverline, ":!ip")) {
            if (checkPass(serverline)) {
                if (getIP(tmp, nick, sckt) == -1) {
                    errprint("getIP()");
                    ret = -1;
                } else {
                    ret = privatemsg(tmp, serverline, sckt);
                }
            } else {
                ret = privatemsg("No!", serverline, sckt);
            }
        } else if (strfind(serverline, "!mute")) {
            if (checkPass(serverline)) {
                mute = 1;
                ret = privatemsg("Muted.", serverline, sckt);
            } else {
                ret = privatemsg("No!", serverline, sckt);
            }
        } else if (strfind(serverline, "!unmute")) {
            if (checkPass(serverline)) {
                mute = 0;
                ret = privatemsg("Unmuted.", serverline, sckt);
            } else {
                ret = privatemsg("No!", serverline, sckt);
            }
        } else if (strfind(serverline, ":!os")) {
            memset(tmp, 0, 1024);
            osinfo(tmp);
            ret = privatemsg(tmp, serverline, sckt);
        } else if (strfind(serverline, ":!version")) {
            memset(tmp, 0, 1024);
            snprintf(tmp, 1024, "Version: %s", "1.2.3");
            ret = privatemsg(tmp, serverline, sckt);
        } else if (strfind(serverline, "!log")) {
            if (checkPass(serverline)) {
                if (logFlag) {
                    ret = privatemsg("Already logging.", serverline, sckt);
                } else {
                    logFlag = 1;
                    msglogprint("--- Log opened ---\n");
                    ret = privatemsg("Logging all messages.", serverline, sckt);
                }
            } else {
                ret = privatemsg("No!", serverline, sckt);
            }
        } else if (strfind(serverline, "!dontlog")) {
            if (checkPass(serverline)) {
                if (logFlag) {
                    ret = privatemsg("Not logging anymore.", serverline, sckt);
                    logFlag = 0;
                    msglogprint("--- Log closed ---\n");
                } else {
                    ret = privatemsg("I'm not logging.", serverline, sckt);
                }
            } else {
                ret = privatemsg("No!", serverline, sckt);
            }
        } else {
            ret = privatemsg("No!", serverline, sckt);
        }
    }
    return ret;
}

variable_types:
channel
char *

variable_types:
privmsg
char [1024]

variable_types:
tmp
char [1024]

variable_types: ret int


loop

decompiled_code:
__int64 __fastcall loop(unsigned int a1, const char *a2, __int64 a3)
{
__int64 result; // rax
char v5[1064]; // [rsp+10h] [rbp-428h] BYREF

while ( 1 )
{
memset(v5, 0, 0x400uLL);
if ( (unsigned int)readserver(v5, a1) == -1 )
break;
result = react(a1, a2, a3, (__int64)v5);
if ( (_DWORD)result == -1 )
break;
if ( (_DWORD)result == 1 )
{
if ( logFlag )
{
msglogprint("--- Log closed ---\n");
result = 1LL;
}
return result;
}
}
if ( logFlag )
msglogprint("--- Log closed ---\n");
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func4(unsigned int a1, const char *a2, __int64 a3)
{
__int64 result; // rax
char v5[1064]; // [rsp+10h] [rbp-428h] BYREF

while ( 1 )
{
memset(v5, 0, 0x400uLL);
if ( (unsigned int)readserver(v5, a1) == -1 )
break;
result = func3(a1, a2, a3, (__int64)v5);
if ( (_DWORD)result == -1 )
break;
if ( (_DWORD)result == 1 )
{
if ( logFlag )
{
msglogprint("--- Log closed ---\n");
result = 1LL;
}
return result;
}
}
if ( logFlag )
msglogprint("--- Log closed ---\n");
return 0xFFFFFFFFLL;
}

original_code:
int loop(int sckt, char *nick, char *channel)
{
    char serverline[1024];
    int ret = 0;
    while (1==1) {
        memset(serverline, 0, 1024);
        if ( (ret = readserver(serverline, sckt)) != -1) {
            ret = react(sckt, nick, channel, serverline);
        }
        if (ret == -1) {
            if (logFlag) {
                msglogprint("--- Log closed ---\n");
            }
            break;
        } else if (ret == 1) {
            if (logFlag) {
                msglogprint("--- Log closed ---\n");
            }
            break;
        }
    }
    return ret;
}

variable_types:
serverline
char [1024]


init

decompiled_code:
__int64 __fastcall init(int fd, const char *a2, __int64 a3, __int64 a4, __int64 a5)
{
if ( (unsigned int)loginpass() != -1
&& (unsigned int)setnick(a2, (unsigned int)fd) != -1
&& (unsigned int)setuser(a3, a4, (unsigned int)fd) != -1
&& (unsigned int)waitForResponse((unsigned int)fd) != -1
&& (unsigned int)joinchannel(a5, (unsigned int)fd) != -1
&& (unsigned int)setmode(a2, "+B", (unsigned int)fd) != -1
&& (unsigned int)loop(fd, a2, a5) != -1 )
{
return 0LL;
}
if ( close(fd) == -1 )
errprint("close(sckt)");
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func5(int fd, const char *a2, __int64 a3, __int64 a4, __int64 a5)
{
if ( (unsigned int)loginpass() != -1
&& (unsigned int)setnick(a2, (unsigned int)fd) != -1
&& (unsigned int)setuser(a3, a4, (unsigned int)fd) != -1
&& (unsigned int)waitForResponse((unsigned int)fd) != -1
&& (unsigned int)joinchannel(a5, (unsigned int)fd) != -1
&& (unsigned int)setmode(a2, "+B", (unsigned int)fd) != -1
&& (unsigned int)func4(fd, a2, a5) != -1 )
{
return 0LL;
}
if ( close(fd) == -1 )
errprint("close(sckt)");
return 0xFFFFFFFFLL;
}

original_code:
int init(int sckt, char *nick, char *username, char *realname, char *channel)
{
    int ret = 0;
    if (loginpass(sckt) == -1) ret = -1;
    else if (setnick(nick, sckt) == -1) ret = -1;
    else if (setuser(username, realname, sckt) == -1) ret = -1;
    else if (waitForResponse(sckt) == -1) ret = -1;
    else if (joinchannel(channel, sckt) == -1) ret = -1;
    else if (setmode(nick, "+B", sckt) == -1) ret = -1;
    else if (loop(sckt, nick, channel) == -1) ret = -1;
    if (ret == -1) {
        if (close(sckt) == -1) {
            errprint("close(sckt)");
        }
        return -1;
    }
    return 0;
}

variable_types:
username
char *

variable_types:
realname
char *


main

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

if ( argc <= 7 )
{
putchar(10);
puts(" parameters: <server> <port> <nick> <realname> <channel> <mute> <log>");
putchar(10);
puts(" server: freenode server rotation is chat.freenode.net");
puts(" port: usually 6667");
puts(" nick: nickname");
puts(" realname: preferably your own nick (in case of problems with the bot)");
puts(" channel: channelname (put a \\ before the #)");
puts(" mute: set this to non-zero to mute the bot");
puts(" log: set this to non-zero to log all messages");
putchar(10);
}
else
{
v3 = atoi(argv[6]);
v4 = argv[7];
mute = v3;
logFlag = atoi(v4);
while ( 1 )
{
v5 = connectirc(argv[1], argv[2]);
if ( v5 != -1 )
{
if ( logFlag )
msglogprint("--- Log opened ---\n");
if ( (unsigned int)init(v5, argv[3], argv[3], argv[4], argv[5]) != -1 )
break;
}
sleep(0x78u);
}
}
return 0;
}

original_code:
int main(int argc, char *argv[])
{
    int sckt, ret;
    if (argc < 8) {
        printf("\n");
        printf("  parameters: <server> <port> <nick> <realname> <channel> <mute> <log>\n");
        printf("\n");
        printf("  server:   freenode server rotation is chat.freenode.net\n");
        printf("  port:     usually 6667\n");
        printf("  nick:     nickname\n");
        printf("  realname: preferably your own nick (in case of problems with the bot)\n");
        printf("  channel:  channelname (put a \\ before the #)\n");
        printf("  mute:     set this to non-zero to mute the bot\n");
        printf("  log:      set this to non-zero to log all messages\n");
        printf("\n");
        return 0;
    }
    mute = atoi(argv[6]);
    logFlag = atoi(argv[7]);
    do {
        sckt = connectirc(argv[1], argv[2]);
        if (sckt == -1) {
            ret = -1;
        } else {
            if (logFlag) {
                msglogprint("--- Log opened ---\n");
            }
            ret = init(sckt, argv[3], argv[3], argv[4], argv[5]);
        }
        if (ret == -1) {
            sleep(120);
        }
    } while (ret == -1);
    return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
    int sckt; int ret;
    if (argc < 8) {
        printf("\n");
        printf("  parameters: <server> <port> <nick> <realname> <channel> <mute> <log>\n");
        printf("\n");
        printf("  server:   freenode server rotation is chat.freenode.net\n");
        printf("  port:     usually 6667\n");
        printf("  nick:     nickname\n");
        printf("  realname: preferably your own nick (in case of problems with the bot)\n");
        printf("  channel:  channelname (put a \\ before the #)\n");
        printf("  mute:     set this to non-zero to mute the bot\n");
        printf("  log:      set this to non-zero to log all messages\n");
        printf("\n");
        return 0;
    }
    mute = atoi(argv[6]);
    logFlag = atoi(argv[7]);
    do {
        sckt = connectirc(argv[1], argv[2]);
        if (sckt == -1) {
            ret = -1;
        } else {
            if (logFlag) {
                msglogprint("--- Log opened ---\n");
            }
            ret = init(sckt, argv[3], argv[3], argv[4], argv[5]);
        }
        if (ret == -1) {
            sleep(120);
        }
    } while (ret == -1);
    return 0;
}

variable_types: argc int

variable_types:
argv
char *[]


connectirc

decompiled_code:
__int64 __fastcall connectirc(const char *a1, const char *a2)
{
struct addrinfo *v2; // rbx
int v3; // eax
unsigned int v4; // ebp
int v6; // edi
struct addrinfo *pai; // [rsp+0h] [rbp-60h] BYREF
__int64 optval[2]; // [rsp+8h] [rbp-58h] BYREF
struct addrinfo req; // [rsp+18h] [rbp-48h] BYREF

*(_OWORD *)&req.ai_flags = 0LL;
*(_OWORD *)&req.ai_addrlen = 0LL;
*(_QWORD *)&req.ai_family = 0x100000002LL;
*(_OWORD *)&req.ai_canonname = 0LL;
if ( getaddrinfo(a1, a2, &req, &pai) )
{
v4 = -1;
errprint("getaddrinfo()");
return v4;
}
v2 = pai;
if ( !pai )
{
LABEL_7:
v4 = -1;
errprint("failed to connect");
freeaddrinfo(pai);
return v4;
}
while ( 1 )
{
v3 = socket(v2->ai_family, v2->ai_socktype, v2->ai_protocol);
v4 = v3;
if ( v3 != -1 )
break;
LABEL_6:
v2 = v2->ai_next;
if ( !v2 )
goto LABEL_7;
}
if ( connect(v3, v2->ai_addr, v2->ai_addrlen) == -1 )
{
close(v4);
goto LABEL_6;
}
freeaddrinfo(pai);
optval[0] = 180LL;
optval[1] = 0LL;
if ( setsockopt(v4, 1, 20, optval, 0x10u) == -1 )
{
errprint("setsockopt()");
v6 = v4;
v4 = -1;
close(v6);
}
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func0(const char *a1, const char *a2)
{
struct addrinfo *v2; // rbx
int v3; // eax
unsigned int v4; // ebp
int v6; // edi
struct addrinfo *pai; // [rsp+0h] [rbp-60h] BYREF
__int64 optval[2]; // [rsp+8h] [rbp-58h] BYREF
struct addrinfo req; // [rsp+18h] [rbp-48h] BYREF

*(_OWORD *)&req.ai_flags = 0LL;
*(_OWORD *)&req.ai_addrlen = 0LL;
*(_QWORD *)&req.ai_family = 0x100000002LL;
*(_OWORD *)&req.ai_canonname = 0LL;
if ( getaddrinfo(a1, a2, &req, &pai) )
{
v4 = -1;
errprint("getaddrinfo()");
return v4;
}
v2 = pai;
if ( !pai )
{
LABEL_7:
v4 = -1;
errprint("failed to connect");
freeaddrinfo(pai);
return v4;
}
while ( 1 )
{
v3 = socket(v2->ai_family, v2->ai_socktype, v2->ai_protocol);
v4 = v3;
if ( v3 != -1 )
break;
LABEL_6:
v2 = v2->ai_next;
if ( !v2 )
goto LABEL_7;
}
if ( connect(v3, v2->ai_addr, v2->ai_addrlen) == -1 )
{
close(v4);
goto LABEL_6;
}
freeaddrinfo(pai);
optval[0] = 180LL;
optval[1] = 0LL;
if ( setsockopt(v4, 1, 20, optval, 0x10u) == -1 )
{
errprint("setsockopt()");
v6 = v4;
v4 = -1;
close(v6);
}
return v4;
}

original_code:
int connectirc(char *server, char *port)
{
    int sckt;
    struct addrinfo hints;
    struct addrinfo *result, *rp;
    struct timeval tv;
    memset(&hints, 0, sizeof(struct addrinfo));
    hints.ai_family = 2;
    hints.ai_socktype = SOCK_STREAM;
    hints.ai_flags = 0;
    hints.ai_protocol = 0;
    if (getaddrinfo(server, port, &hints, &result) != 0) {
        errprint("getaddrinfo()");
        return -1;
    }
    for (rp = result; rp != ((void *)0); rp = rp->ai_next) {
        if ((sckt = socket(rp->ai_family, rp->ai_socktype, rp->ai_protocol)) == -1) {
            continue;
        }
        if ((connect(sckt, rp->ai_addr, rp->ai_addrlen)) != -1) {
            break;
        }
        close(sckt);
    }
    if (rp == ((void *)0)) {
        errprint("failed to connect");
        freeaddrinfo(result);
        return -1;
    }
    freeaddrinfo(result);
    tv.tv_sec = 180;
    tv.tv_usec = 0;
    if (setsockopt(sckt, 1, 20, (char *)&tv, (socklen_t)sizeof(struct timeval)) == -1) {
        errprint("setsockopt()");
        close(sckt);
        return -1;
    }
    return sckt;
}

canonical_original_code:
int connectirc(char *server, char *port)
{
    int sckt;
    struct addrinfo hints;
    struct addrinfo *result; struct addrinfo *rp;
    struct timeval tv;
    memset(&hints, 0, sizeof(struct addrinfo));
    hints.ai_family = 2;
    hints.ai_socktype = SOCK_STREAM;
    hints.ai_flags = 0;
    hints.ai_protocol = 0;
    if (getaddrinfo(server, port, &hints, &result) != 0) {
        errprint("getaddrinfo()");
        return -1;
    }
    for (rp = result; rp != ((void *)0); rp = rp->ai_next) {
        if ((sckt = socket(rp->ai_family, rp->ai_socktype, rp->ai_protocol)) == -1) {
            continue;
        }
        if ((connect(sckt, rp->ai_addr, rp->ai_addrlen)) != -1) {
            break;
        }
        close(sckt);
    }
    if (rp == ((void *)0)) {
        errprint("failed to connect");
        freeaddrinfo(result);
        return -1;
    }
    freeaddrinfo(result);
    tv.tv_sec = 180;
    tv.tv_usec = 0;
    if (setsockopt(sckt, 1, 20, (char *)&tv, (unsigned int)sizeof(struct timeval)) == -1) {
        errprint("setsockopt()");
        close(sckt);
        return -1;
    }
    return sckt;
}

variable_types:
server
char *

variable_types:
port
char *

variable_types: struct addrinfo { int ai_flags; int ai_family; int ai_socktype; int ai_protocol; unsigned int ai_addrlen; struct sockaddr { unsigned short sa_family; char sa_data[14]; } *ai_addr; char *ai_canonname; struct addrinfo *ai_next; } *

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

user_defined_types: struct addrinfo { int ai_flags; int ai_family; int ai_socktype; int ai_protocol; unsigned int ai_addrlen; struct sockaddr *ai_addr; char *ai_canonname; struct addrinfo *ai_next; }


readserver

decompiled_code:
__int64 __fastcall readserver(char *s, unsigned int a2)
{
unsigned int v2; // er12
char v4[1048]; // [rsp+0h] [rbp-418h] BYREF

if ( readline(a2, v4, 1024LL) == -1 )
{
v2 = -1;
errprint("readserver()");
}
else
{
v2 = strfind(v4, "Closing Link");
if ( v2 )
{
v2 = -1;
errprint("Closing Link");
}
else
{
snprintf(s, 0x400uLL, "%s", v4);
}
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func1(char *s, unsigned int a2)
{
unsigned int v2; // er12
char v4[1048]; // [rsp+0h] [rbp-418h] BYREF

if ( readline(a2, v4, 1024LL) == -1 )
{
v2 = -1;
errprint("readserver()");
}
else
{
v2 = strfind(v4, "Closing Link");
if ( v2 )
{
v2 = -1;
errprint("Closing Link");
}
else
{
snprintf(s, 0x400uLL, "%s", v4);
}
}
return v2;
}

original_code:
int readserver(char *s, int sckt)
{
    char tmp[1024];
    if (readline(sckt, tmp, sizeof(tmp)) == -1) {
        errprint("readserver()");
        return -1;
    }
    if (strfind(tmp, "Closing Link")) {
        errprint("Closing Link");
        return -1;
    }
    snprintf(s, 1024, "%s", tmp);
    return 0;
}

variable_types: sckt int


writeserver

decompiled_code:
__int64 __fastcall writeserver(void *buf, int fd)
{
size_t v2; // rax

v2 = strnlen((const char *)buf, 0x400uLL);
if ( write(fd, buf, v2) != -1 )
return 0LL;
errprint("writeserver()");
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func2(void *buf, int fd)
{
size_t v2; // rax

v2 = strnlen((const char *)buf, 0x400uLL);
if ( write(fd, buf, v2) != -1 )
return 0LL;
errprint("writeserver()");
return 0xFFFFFFFFLL;
}

original_code:
int writeserver(char *s, int sckt)
{
    if (write(sckt, s, strnlen(s, 1024)) == -1) {
        errprint("writeserver()");
        return -1;
    }
    return 0;
}

variable_types:
s
char *


loginpass

decompiled_code:
__int64 __fastcall loginpass(int fd)
{
__m128i v2[64]; // [rsp+0h] [rbp-408h] BYREF

v2[0] = _mm_load_si128((const __m128i *)&LC7);
return (unsigned int)-((unsigned int)writeserver(v2, fd) == -1);
}

canonical_decompiled_code:
__int64 __fastcall func3(int fd)
{
__m128i v2[64]; // [rsp+0h] [rbp-408h] BYREF

v2[0] = _mm_load_si128((const __m128i *)&LC7);
return (unsigned int)-((unsigned int)func2(v2, fd) == -1);
}

original_code:
int loginpass(int sckt)
{
    char tmp[1024];
    snprintf(tmp, 1024, "%s", "PASS drowssap\r\n");
    if (writeserver(tmp, sckt) == -1) {
        return -1;
    }
    return 0;
}


setnick

decompiled_code:
__int64 __fastcall setnick(char *src, int fd)
{
size_t v2; // rax
size_t v3; // rax
char v5[1048]; // [rsp+0h] [rbp-418h] BYREF

strcpy(v5, "NICK ");
v2 = strnlen(v5, 0x400uLL);
strncat(v5, src, 1023 - v2);
v3 = strnlen(v5, 0x400uLL);
strncat(v5, "\r\n", 1023 - v3);
return (unsigned int)-((unsigned int)writeserver(v5, fd) == -1);
}

canonical_decompiled_code:
__int64 __fastcall func4(char *src, int fd)
{
size_t v2; // rax
size_t v3; // rax
char v5[1048]; // [rsp+0h] [rbp-418h] BYREF

strcpy(v5, "NICK ");
v2 = strnlen(v5, 0x400uLL);
strncat(v5, src, 1023 - v2);
v3 = strnlen(v5, 0x400uLL);
strncat(v5, "\r\n", 1023 - v3);
return (unsigned int)-((unsigned int)func2(v5, fd) == -1);
}

original_code:
int setnick(char *nick, int sckt)
{
    char tmp[1024];
    snprintf(tmp, 1024, "%s", "NICK ");
    strncat(tmp, nick, 1024 -strnlen(tmp, 1024)-1);
    strncat(tmp, "\r\n", 1024 -strnlen(tmp, 1024)-1);
    if (writeserver(tmp, sckt) == -1) {
        return -1;
    }
    return 0;
}


setuser

decompiled_code:
__int64 __fastcall setuser(char *src, char *a2, int fd)
{
size_t v4; // rax
size_t v5; // rax
size_t v6; // rax
size_t v7; // rax
char v9[1064]; // [rsp+0h] [rbp-428h] BYREF

strcpy(v9, "USER ");
v4 = strnlen(v9, 0x400uLL);
strncat(v9, src, 1023 - v4);
v5 = strnlen(v9, 0x400uLL);
strncat(v9, " 0 * :", 1023 - v5);
v6 = strnlen(v9, 0x400uLL);
strncat(v9, a2, 1023 - v6);
v7 = strnlen(v9, 0x400uLL);
strncat(v9, "\r\n", 1023 - v7);
return (unsigned int)-((unsigned int)writeserver(v9, fd) == -1);
}

canonical_decompiled_code:
__int64 __fastcall func5(char *src, char *a2, int fd)
{
size_t v4; // rax
size_t v5; // rax
size_t v6; // rax
size_t v7; // rax
char v9[1064]; // [rsp+0h] [rbp-428h] BYREF

strcpy(v9, "USER ");
v4 = strnlen(v9, 0x400uLL);
strncat(v9, src, 1023 - v4);
v5 = strnlen(v9, 0x400uLL);
strncat(v9, " 0 * :", 1023 - v5);
v6 = strnlen(v9, 0x400uLL);
strncat(v9, a2, 1023 - v6);
v7 = strnlen(v9, 0x400uLL);
strncat(v9, "\r\n", 1023 - v7);
return (unsigned int)-((unsigned int)func2(v9, fd) == -1);
}

original_code:
int setuser(char *username, char *realname, int sckt)
{
    char tmp[1024];
    snprintf(tmp, 1024, "%s", "USER ");
    strncat(tmp, username, 1024 -strnlen(tmp, 1024)-1);
    strncat(tmp, " 0 * :", 1024 -strnlen(tmp, 1024)-1);
    strncat(tmp, realname, 1024 -strnlen(tmp, 1024)-1);
    strncat(tmp, "\r\n", 1024 -strnlen(tmp, 1024)-1);
    if (writeserver(tmp, sckt) == -1 ) {
        return -1;
    }
    return 0;
}


setmode

decompiled_code:
__int64 __fastcall setmode(char *src, char *a2, int fd)
{
size_t v4; // rax
size_t v5; // rax
size_t v6; // rax
size_t v7; // rax
size_t v8; // rax
char v10[1064]; // [rsp+0h] [rbp-428h] BYREF

strcpy(v10, "MODE ");
v4 = strnlen(v10, 0x400uLL);
strncat(v10, src, 1023 - v4);
v5 = strnlen(v10, 0x400uLL);
strncat(v10, " ", 1023 - v5);
v6 = strnlen(v10, 0x400uLL);
strncat(v10, a2, 1023 - v6);
v7 = strnlen(v10, 0x400uLL);
strncat(v10, " ", 1023 - v7);
v8 = strnlen(v10, 0x400uLL);
strncat(v10, "\r\n", 1023 - v8);
return (unsigned int)-((unsigned int)writeserver(v10, fd) == -1);
}

canonical_decompiled_code:
__int64 __fastcall func6(char *src, char *a2, int fd)
{
size_t v4; // rax
size_t v5; // rax
size_t v6; // rax
size_t v7; // rax
size_t v8; // rax
char v10[1064]; // [rsp+0h] [rbp-428h] BYREF

strcpy(v10, "MODE ");
v4 = strnlen(v10, 0x400uLL);
strncat(v10, src, 1023 - v4);
v5 = strnlen(v10, 0x400uLL);
strncat(v10, " ", 1023 - v5);
v6 = strnlen(v10, 0x400uLL);
strncat(v10, a2, 1023 - v6);
v7 = strnlen(v10, 0x400uLL);
strncat(v10, " ", 1023 - v7);
v8 = strnlen(v10, 0x400uLL);
strncat(v10, "\r\n", 1023 - v8);
return (unsigned int)-((unsigned int)func2(v10, fd) == -1);
}

original_code:
int setmode(char *nick, char *mode, int sckt)
{
    char tmp[1024];
    snprintf(tmp, 1024, "%s", "MODE ");
    strncat(tmp, nick, 1024 -strnlen(tmp, 1024)-1);
    strncat(tmp, " ", 1024 -strnlen(tmp, 1024)-1);
    strncat(tmp, mode, 1024 -strnlen(tmp, 1024)-1);
    strncat(tmp, " ", 1024 -strnlen(tmp, 1024)-1);
    strncat(tmp, "\r\n", 1024 -strnlen(tmp, 1024)-1);
    if (writeserver(tmp, sckt) == -1 ) {
        return -1;
    }
    return 0;
}

variable_types:
mode
char *


joinchannel

decompiled_code:
__int64 __fastcall joinchannel(char *src, int fd)
{
size_t v2; // rax
size_t v3; // rax
char v5[1048]; // [rsp+0h] [rbp-418h] BYREF

strcpy(v5, "JOIN ");
v2 = strnlen(v5, 0x400uLL);
strncat(v5, src, 1023 - v2);
v3 = strnlen(v5, 0x400uLL);
strncat(v5, "\r\n", 1023 - v3);
return (unsigned int)-((unsigned int)writeserver(v5, fd) == -1);
}

canonical_decompiled_code:
__int64 __fastcall func7(char *src, int fd)
{
size_t v2; // rax
size_t v3; // rax
char v5[1048]; // [rsp+0h] [rbp-418h] BYREF

strcpy(v5, "JOIN ");
v2 = strnlen(v5, 0x400uLL);
strncat(v5, src, 1023 - v2);
v3 = strnlen(v5, 0x400uLL);
strncat(v5, "\r\n", 1023 - v3);
return (unsigned int)-((unsigned int)func2(v5, fd) == -1);
}

original_code:
int joinchannel(char *channel, int sckt)
{
    char tmp[1024];
    snprintf(tmp, 1024, "%s", "JOIN ");
    strncat(tmp, channel, 1024 -strnlen(tmp, 1024)-1);
    strncat(tmp, "\r\n", 1024 -strnlen(tmp, 1024)-1);
    if (writeserver(tmp, sckt) == -1) {
        return -1;
    }
    return 0;
}


sendpong

decompiled_code:
__int64 __fastcall sendpong(int fd, const char *a2)
{
size_t v2; // rax
char v4[1024]; // [rsp+0h] [rbp-818h] BYREF
char string[1048]; // [rsp+400h] [rbp-418h] BYREF

snprintf(v4, 0x400uLL, "%s", a2);
if ( (unsigned int)getmsg(v4, "PING :") )
{
strcpy(string, "PONG");
}
else
{
strcpy(string, "PONG :");
v2 = strnlen(string, 0x400uLL);
strncat(string, v4, 1023 - v2);
}
return (unsigned int)-((unsigned int)writeserver(string, fd) == -1);
}

canonical_decompiled_code:
__int64 __fastcall func8(int fd, const char *a2)
{
size_t v2; // rax
char v4[1024]; // [rsp+0h] [rbp-818h] BYREF
char string[1048]; // [rsp+400h] [rbp-418h] BYREF

snprintf(v4, 0x400uLL, "%s", a2);
if ( (unsigned int)getmsg(v4, "PING :") )
{
strcpy(string, "PONG");
}
else
{
strcpy(string, "PONG :");
v2 = strnlen(string, 0x400uLL);
strncat(string, v4, 1023 - v2);
}
return (unsigned int)-((unsigned int)func2(string, fd) == -1);
}

original_code:
int sendpong(int sckt, char *s)
{
    char tmp[1024];
    char tmp2[1024];
    snprintf(tmp, 1024, "%s", s);
    if (getmsg(tmp, "PING :") == 0) {
        snprintf(tmp2, 1024, "%s", "PONG :");
        strncat(tmp2, tmp, 1024 -strnlen(tmp2, 1024)-1);
    } else {
        snprintf(tmp2, 1024, "%s", "PONG");
    }
    if (writeserver(tmp2, sckt) == -1) {
        return -1;
    }
    return 0;
}


waitForResponse

decompiled_code:
__int64 __fastcall waitForResponse(int fd)
{
_BYTE savedregs[1048]; // [rsp+0h] [rbp+0h] BYREF

while ( 1 )
{
memset(savedregs, 0, 0x400uLL);
if ( (unsigned int)readserver(savedregs, fd) == -1 )
return 0xFFFFFFFFLL;
if ( (unsigned int)strfind(savedregs, ":End of /MOTD") )
break;
if ( (unsigned int)strfind(savedregs, "PING :") && (unsigned int)sendpong(fd, savedregs) == -1 )
return 0xFFFFFFFFLL;
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func9(int fd)
{
_BYTE savedregs[1048]; // [rsp+0h] [rbp+0h] BYREF

while ( 1 )
{
memset(savedregs, 0, 0x400uLL);
if ( (unsigned int)func1(savedregs, fd) == -1 )
return 0xFFFFFFFFLL;
if ( (unsigned int)strfind(savedregs, ":End of /MOTD") )
break;
if ( (unsigned int)strfind(savedregs, "PING :") && (unsigned int)func8(fd, savedregs) == -1 )
return 0xFFFFFFFFLL;
}
return 0LL;
}

original_code:
int waitForResponse(int sckt)
{
    char serverline[1024];
    while (1==1) {
        memset(serverline, 0, 1024);
        if (readserver(serverline, sckt) == -1) {
            return -1;
        }
        if (strfind(serverline, ":End of /MOTD")) {
            return 0;
        } else if (strfind(serverline, "PING :")) {
            if (sendpong(sckt, serverline) == -1) {
                return -1;
            }
        }
    }
    return 0;
}


quit

decompiled_code:
__int64 __fastcall quit(char *src, int fd)
{
size_t v2; // rax
size_t v3; // rax
char v5[1048]; // [rsp+0h] [rbp-418h] BYREF

strcpy(v5, "QUIT ");
v2 = strnlen(v5, 0x400uLL);
strncat(v5, src, 1023 - v2);
v3 = strnlen(v5, 0x400uLL);
strncat(v5, "\r\n", 1023 - v3);
return (unsigned int)-((unsigned int)writeserver(v5, fd) == -1);
}

canonical_decompiled_code:
__int64 __fastcall func10(char *src, int fd)
{
size_t v2; // rax
size_t v3; // rax
char v5[1048]; // [rsp+0h] [rbp-418h] BYREF

strcpy(v5, "QUIT ");
v2 = strnlen(v5, 0x400uLL);
strncat(v5, src, 1023 - v2);
v3 = strnlen(v5, 0x400uLL);
strncat(v5, "\r\n", 1023 - v3);
return (unsigned int)-((unsigned int)func2(v5, fd) == -1);
}

original_code:
int quit(char *msg, int sckt)
{
    char tmp[1024];
    snprintf(tmp, 1024, "%s", "QUIT ");
    strncat(tmp, msg, 1024 -strnlen(tmp, 1024)-1);
    strncat(tmp, "\r\n", 1024 -strnlen(tmp, 1024)-1);
    if (writeserver(tmp, sckt) == -1) {
        return -1;
    }
    return 0;
}

variable_types:
msg
char *