main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // er12
int v4; // eax
const char *v5; // rdi
int v6; // ebp
__int64 v7; // rdx
__int64 v8; // rcx
unsigned int i; // ebx
const struct sockaddr *v10; // r8
socklen_t v11; // er9
ssize_t v12; // rax
unsigned int v13; // eax
int v14; // edi
int v16; // [rsp+0h] [rbp-2028h] BYREF
struct in_addr inp; // [rsp+4h] [rbp-2024h] BYREF
__int16 buf; // [rsp+10h] [rbp-2018h] BYREF
__int16 v19; // [rsp+12h] [rbp-2016h]
__int16 v20; // [rsp+14h] [rbp-2014h]
__int16 v21; // [rsp+16h] [rbp-2012h]
char v22[4120]; // [rsp+1010h] [rbp-1018h] BYREF

if ( argc == 3 )
{
v3 = socket(2, 3, 1);
if ( v3 == -1 )
{
fwrite(&unk_402198, 1uLL, 0x34uLL, _bss_start);
}
else
{
v4 = atoi(argv[2]);
v5 = argv[1];
buf = 8;
v6 = v4;
v20 = -11646;
v16 = 2;
inet_aton(v5, &inp);
putchar(10);
if ( (unsigned int)(v6 + 1) > 1 )
{
for ( i = 1; ; i = v13 )
{
v21 = (_WORD)i << 8;
v19 = 0;
v19 = ((__int64 (__fastcall *)(__int16 *, __int64, __int64, __int64, int *, __int64))checksum)(
&buf,
8LL,
v7,
v8,
&v16,
16LL);
sendto(v3, &buf, 0x6CuLL, 0, v10, v11);
printf(&format, i);
do
{
sleep(1u);
v12 = recv(v3, v22, 0x1000uLL, 64);
}
while ( v12 < 0 );
if ( v12 && !v22[160] )
{
puts(&s);
v13 = i + 1;
if ( i == v6 )
break;
}
else
{
v13 = i + 1;
if ( i == v6 )
break;
}
}
}
putchar(10);
v14 = v3;
v3 = 0;
close(v14);
}
}
else
{
v3 = -1;
fwrite(&unk_402008, 1uLL, 0x18EuLL, _bss_start);
}
return v3;
}

original_code:
int main(const int argc, const char *argv[])
{
 if(argc != 3)
 {
  fprintf(stderr, "\nПрограмме передано недостаточное количество аргументов\n\nФормат вызова: ./program IP NUM\n\nЗдесь:\n\n\tIP\t-\tIPv4-адрес сетевого узла - получателя пакетов типа ECHO протокола ICMP;\n\tNUM\t-\tколичество отправляемых пакетов типа ECHO протокола ICMP.\n\n");
  return -1;
 }
 int sock = socket(2, SOCK_RAW, IPPROTO_ICMP);
 if(sock == -1)
 {
  fprintf(stderr, "\nОшибка при создании сокета\n\n");
  return -1;
 }
 unsigned u, max_u = atoi(argv[2]) + 1;
 ssize_t size;
 uint8_t echo_buf[4096], echo_reply_buf[4096];
 struct sockaddr_in addr;
 struct icmphdr *echo_hdr = (struct icmphdr *) echo_buf, *echo_reply_hdr = (struct icmphdr *) echo_reply_buf + sizeof(struct iphdr);
 echo_hdr->type = 8;
 echo_hdr->code = 0;
 echo_hdr->un.echo.id = 53890;
 addr.sin_family = 2;
 addr.sin_port = 0;
 inet_aton(argv[1], & addr.sin_addr);
 printf("\n");
 for(u = 1; u < max_u; u++)
 {
  echo_hdr->un.echo.sequence = u << 8;
  echo_hdr->checksum = 0;
  echo_hdr->checksum = checksum((uint16_t *) echo_hdr, sizeof(struct icmphdr));
  sendto(sock, echo_buf, sizeof(struct icmphdr) + 100, 0, (struct sockaddr *) & addr, sizeof(struct sockaddr_in));
  printf("Пакет %u отправлен -> ", u);
  do
  {
   sleep(1);
   size = recv(sock, echo_reply_buf, 4096, MSG_DONTWAIT);
  }
  while (size < 0);
  if(size > 0)
   if(echo_reply_hdr->type == 0)
    printf("ответ получен\n");
 }
 printf("\n");
 close(sock);
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
 if(argc != 3)
 {
  fprintf(stderr, "\nПрограмме передано недостаточное количество аргументов\n\nФормат вызова: ./program IP NUM\n\nЗдесь:\n\n\tIP\t-\tIPv4-адрес сетевого узла - получателя пакетов типа ECHO протокола ICMP;\n\tNUM\t-\tколичество отправляемых пакетов типа ECHO протокола ICMP.\n\n");
  return -1;
 }
 int sock = socket(2, SOCK_RAW, IPPROTO_ICMP);
 if(sock == -1)
 {
  fprintf(stderr, "\nОшибка при создании сокета\n\n");
  return -1;
 }
 unsigned int u; unsigned int max_u = atoi(argv[2]) + 1;
 long size;
 unsigned char echo_buf[4096]; unsigned char echo_reply_buf[4096];
 struct sockaddr_in addr;
 struct icmphdr *echo_hdr = (struct icmphdr *) echo_buf; struct icmphdr *echo_reply_hdr = (struct icmphdr *) echo_reply_buf + sizeof(struct iphdr);
 echo_hdr->type = 8;
 echo_hdr->code = 0;
 echo_hdr->un.echo.id = 53890;
 addr.sin_family = 2;
 addr.sin_port = 0;
 inet_aton(argv[1], & addr.sin_addr);
 printf("\n");
 for(u = 1; u < max_u; u++)
 {
  echo_hdr->un.echo.sequence = u << 8;
  echo_hdr->checksum = 0;
  echo_hdr->checksum = checksum((unsigned short *) echo_hdr, sizeof(struct icmphdr));
  sendto(sock, echo_buf, sizeof(struct icmphdr) + 100, 0, (struct sockaddr *) & addr, sizeof(struct sockaddr_in));
  printf("Пакет %u отправлен -> ", u);
  do
  {
   sleep(1);
   size = recv(sock, echo_reply_buf, 4096, MSG_DONTWAIT);
  }
  while (size < 0);
  if(size > 0)
   if(echo_reply_hdr->type == 0)
    printf("ответ получен\n");
 }
 printf("\n");
 close(sock);
 return 0;
}

variable_types:
argv
char *[]

variable_types: sock int

variable_types: size long

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

variable_types: struct icmphdr { unsigned char type; unsigned char code; unsigned short checksum; union { struct { unsigned short id; unsigned short sequence; } echo; unsigned int gateway; struct { unsigned short __unused; unsigned short mtu; } frag; unsigned char reserved[4]; } un; } *

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

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


decompiled_code:
__int64 __fastcall get_iface_id(int fd, const char *a2)
{
__int64 result; // rax
char v3[16]; // [rsp+0h] [rbp-38h] BYREF
unsigned int v4; // [rsp+10h] [rbp-28h]

strcpy(v3, a2);
if ( ioctl(fd, 0x8933uLL, v3) )
result = 0xFFFFFFFFLL;
else
result = v4;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(int fd, const char *a2)
{
__int64 result; // rax
char v3[16]; // [rsp+0h] [rbp-38h] BYREF
unsigned int v4; // [rsp+10h] [rbp-28h]

strcpy(v3, a2);
if ( ioctl(fd, 0x8933uLL, v3) )
result = 0xFFFFFFFFLL;
else
result = v4;
return result;
}

original_code:
int get_iface_id(int sock, const char* device_name)
{
 struct ifreq req;
 strcpy(req.ifr_ifrn.ifrn_name, device_name);
 if(ioctl(sock, 0x8933, & req))
  return -1;
 return req.ifr_ifru.ifru_ivalue;
}

canonical_original_code:
int get_iface_id(int sock, char *device_name)
{
 struct ifreq req;
 strcpy(req.ifr_ifrn.ifrn_name, device_name);
 if(ioctl(sock, 0x8933, & req))
  return -1;
 return req.ifr_ifru.ifru_ivalue;
}

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

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


original_code:
int set_mac(uint8_t *buf, const char *mac)
{
 if(strlen(mac) != 17)
  return -1;
 unsigned u, v;
 char temp[18];
 strcpy(temp, mac);
 for(u = 0, v = 0; u < 17; u += 3, v ++)
 {
  temp[u + 2] = '\0';
  buf[v] = strtoul(temp + u, ((void *)0), 16);
 }
 return 0;
}

canonical_original_code:
int set_mac(unsigned char *buf, char *mac)
{
 if(strlen(mac) != 17)
  return -1;
 unsigned int u; unsigned int v;
 char temp[18];
 strcpy(temp, mac);
 for(u = 0, v = 0; u < 17; u += 3, v ++)
 {
  temp[u + 2] = '\0';
  buf[v] = strtoul(temp + u, ((void *)0), 16);
 }
 return 0;
}

variable_types:
buf
unsigned char *

variable_types:
mac
char *

variable_types:
u
unsigned int

variable_types:
v
unsigned int

variable_types:
temp
char [18]


decompiled_code:
__int64 __fastcall set_ip(__int64 a1, const char *a2)
{
in_addr_t v3; // eax
unsigned int v4; // esi
in_addr_t v5; // edi
__int64 v6; // rax
unsigned int v7; // edx

v3 = inet_addr(a2);
v4 = -16777216;
v5 = v3;
v6 = 3LL;
do
{
v7 = v4 & v5;
v4 >>= 8;
*(_BYTE *)(a1 + v6) = v7 >> (8 * v6);
}
while ( v6-- != 0 );
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1, const char *a2)
{
in_addr_t v3; // eax
unsigned int v4; // esi
in_addr_t v5; // edi
__int64 v6; // rax
unsigned int v7; // edx

v3 = inet_addr(a2);
v4 = -16777216;
v5 = v3;
v6 = 3LL;
do
{
v7 = v4 & v5;
v4 >>= 8;
*(_BYTE *)(a1 + v6) = v7 >> (8 * v6);
}
while ( v6-- != 0 );
return 0LL;
}

original_code:
int set_ip(uint8_t *buf, const char *ip)
{
 int v;
 unsigned mask = 0xFF000000;
 in_addr_t addr = inet_addr(ip);
 for(v = 3; v >= 0; v--, mask >>= 8)
  buf[v] = (addr & mask) >> (v << 3);
 return 0;
}

canonical_original_code:
int set_ip(unsigned char *buf, char *ip)
{
 int v;
 unsigned int mask = 0xFF000000;
 unsigned int addr = inet_addr(ip);
 for(v = 3; v >= 0; v--, mask >>= 8)
  buf[v] = (addr & mask) >> (v << 3);
 return 0;
}

variable_types:
ip
char *

variable_types: v int

variable_types:
mask
unsigned int

variable_types:
addr
unsigned int


original_code:
char *mac_to_str(const uint8_t *mac)
{
 char *temp = malloc(18 * sizeof(char));
 if(temp == ((void *)0))
  return ((void *)0);
 sprintf(temp, "%.2X:%.2X:%.2X:%.2X:%.2X:%.2X", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
 return temp;
}

canonical_original_code:
char *mac_to_str(unsigned char *mac)
{
 char *temp = malloc(18 * sizeof(char));
 if(temp == ((void *)0))
  return ((void *)0);
 sprintf(temp, "%.2X:%.2X:%.2X:%.2X:%.2X:%.2X", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
 return temp;
}

variable_types:
mac
unsigned char *

variable_types:
temp
char *

return_type: char *


canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v4; // er13
__int64 v5; // rdx
int v6; // ebp
unsigned int v7; // eax
__int16 v8; // ax
const char *v9; // rsi
__int16 v10; // cx
unsigned __int16 v11; // dx
const char *v12; // rsi
int v13; // er12
ssize_t v14; // rax
__int64 v15; // rdx
__int64 v16; // rax
void *v17; // r13
__int16 v19[2]; // [rsp+0h] [rbp-1048h] BYREF
int v20; // [rsp+4h] [rbp-1044h]
int v21; // [rsp+8h] [rbp-1040h]
__int64 v22; // [rsp+Ch] [rbp-103Ch]
__int16 buf[3]; // [rsp+20h] [rbp-1028h] BYREF
unsigned __int16 v24; // [rsp+26h] [rbp-1022h]
char v25[6]; // [rsp+28h] [rbp-1020h] BYREF
char v26[4]; // [rsp+2Eh] [rbp-101Ah] BYREF
int v27; // [rsp+32h] [rbp-1016h] BYREF
__int16 v28; // [rsp+36h] [rbp-1012h]
char v29[4112]; // [rsp+38h] [rbp-1010h] BYREF

if ( argc == 5 )
{
v4 = (unsigned __int16)_bswap_16(2054LL, 2LL, envp);
v6 = socket(17, 2, v4);
if ( v6 == -1 )
{
v13 = -1;
fwrite(&unk_4022A8, 1uLL, 0x3EuLL, stderr);
}
else
{
v7 = _bswap_16(1LL, 2LL, v5);
buf[0] = v7;
v8 = _bswap_16(2048LL, 2LL, v7);
v9 = argv[2];
buf[2] = v10;
buf[1] = v8;
v24 = v11;
if ( (unsigned int)set_mac(v25, v9) )
{
v13 = -1;
fwrite(&unk_4022E8, 1uLL, 0xA1uLL, stderr);
close(v6);
}
else if ( (unsigned int)set_ip(v26, argv[3]) )
{
v13 = -1;
fwrite(&unk_402390, 1uLL, 0x7EuLL, stderr);
close(v6);
}
else
{
v12 = argv[4];
v27 = 0;
v28 = 0;
v13 = set_ip(v29, v12);
if ( v13 )
{
v13 = -1;
fwrite(&unk_402410, 1uLL, 0x7CuLL, stderr);
close(v6);
}
else
{
v19[0] = 17;
v19[1] = v4;
v21 = 100728833;
v22 = -1LL;
v20 = get_iface_id(v6);
if ( v20 == -1 )
{
v13 = -1;
fwrite(&unk_402490, 1uLL, 0x6CuLL, stderr);
close(v6);
}
else if ( sendto(v6, buf, 0x1CuLL, 0, (const struct sockaddr *)v19, 0x14u) <= 0 )
{
v13 = -1;
fwrite(&unk_402570, 1uLL, 0x40uLL, stderr);
close(v6);
}
else
{
do
v14 = recv(v6, buf, 0x1000uLL, 0);
while ( (unsigned __int16)_bswap_16(v24, buf, v14) != 2 );
if ( v15 > 0 && (v16 = mac_to_str(&v27), (v17 = (void *)v16) != 0LL) )
{
printf(format, argv[4], v16);
free(v17);
close(v6);
}
else
{
v13 = -1;
fwrite(&unk_402530, 1uLL, 0x3AuLL, stderr);
close(v6);
}
}
}
}
}
}
else
{
v13 = -1;
fwrite(&unk_402028, 1uLL, 0x27FuLL, stderr);
}
return v13;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v4; // er13
__int64 v5; // rdx
int v6; // ebp
unsigned int v7; // eax
__int16 v8; // ax
const char *v9; // rsi
__int16 v10; // cx
unsigned __int16 v11; // dx
const char *v12; // rsi
int v13; // er12
ssize_t v14; // rax
__int64 v15; // rdx
__int64 v16; // rax
void *v17; // r13
__int16 v19[2]; // [rsp+0h] [rbp-1048h] BYREF
int v20; // [rsp+4h] [rbp-1044h]
int v21; // [rsp+8h] [rbp-1040h]
__int64 v22; // [rsp+Ch] [rbp-103Ch]
__int16 buf[3]; // [rsp+20h] [rbp-1028h] BYREF
unsigned __int16 v24; // [rsp+26h] [rbp-1022h]
char v25[6]; // [rsp+28h] [rbp-1020h] BYREF
char v26[4]; // [rsp+2Eh] [rbp-101Ah] BYREF
int v27; // [rsp+32h] [rbp-1016h] BYREF
__int16 v28; // [rsp+36h] [rbp-1012h]
char v29[4112]; // [rsp+38h] [rbp-1010h] BYREF

if ( argc == 5 )
{
v4 = (unsigned __int16)func7(2054LL, 2LL, envp);
v6 = socket(17, 2, v4);
if ( v6 == -1 )
{
v13 = -1;
fwrite(&unk_4022A8, 1uLL, 0x3EuLL, stderr);
}
else
{
v7 = func7(1LL, 2LL, v5);
buf[0] = v7;
v8 = func7(2048LL, 2LL, v7);
v9 = argv[2];
buf[2] = v10;
buf[1] = v8;
v24 = v11;
if ( (unsigned int)func9(v25, v9) )
{
v13 = -1;
fwrite(&unk_4022E8, 1uLL, 0xA1uLL, stderr);
close(v6);
}
else if ( (unsigned int)func10(v26, argv[3]) )
{
v13 = -1;
fwrite(&unk_402390, 1uLL, 0x7EuLL, stderr);
close(v6);
}
else
{
v12 = argv[4];
v27 = 0;
v28 = 0;
v13 = func10(v29, v12);
if ( v13 )
{
v13 = -1;
fwrite(&unk_402410, 1uLL, 0x7CuLL, stderr);
close(v6);
}
else
{
v19[0] = 17;
v19[1] = v4;
v21 = 100728833;
v22 = -1LL;
v20 = func8(v6);
if ( v20 == -1 )
{
v13 = -1;
fwrite(&unk_402490, 1uLL, 0x6CuLL, stderr);
close(v6);
}
else if ( sendto(v6, buf, 0x1CuLL, 0, (const struct sockaddr *)v19, 0x14u) <= 0 )
{
v13 = -1;
fwrite(&unk_402570, 1uLL, 0x40uLL, stderr);
close(v6);
}
else
{
do
v14 = recv(v6, buf, 0x1000uLL, 0);
while ( (unsigned __int16)func7(v24, buf, v14) != 2 );
if ( v15 > 0 && (v16 = func11(&v27), (v17 = (void *)v16) != 0LL) )
{
printf(format, argv[4], v16);
free(v17);
close(v6);
}
else
{
v13 = -1;
fwrite(&unk_402530, 1uLL, 0x3AuLL, stderr);
close(v6);
}
}
}
}
}
}
else
{
v13 = -1;
fwrite(&unk_402028, 1uLL, 0x27FuLL, stderr);
}
return v13;
}

original_code:
int main(const int argc, const char *argv[])
{
 if(argc != 5)
 {
  fprintf(stderr, "\nПрограмме передано недостаточное количество аргументов\n\nФормат вызова: ./program IFACE IMAC IIP OIP\n\nЗдесь:\n\n\tIFACE\t-\tимя сетевого интерфейса сетевого адаптера сетевого узла - отправителя;\n\tIMAC\t-\tMAC-адрес сетевого адаптера сетевого узла - отправителя;\n\tIIP\t-\tIPv4-адрес сетевого узла - отправителя;\n\tOIP\t-\tIPv4-адрес, соответствующий MAC-адрес для которого необходимо определить.\n\n");
  return -1;
 }
 int sock = socket(17, SOCK_DGRAM, htons(0x0806));
 if(sock == -1)
 {
  fprintf(stderr, "\nОшибка: создать сокет не удалось\n\n");
  return -1;
 }
 uint8_t buf[4096];
 struct arphdr *hdr = (struct arphdr *) buf;
 size_t aoff = sizeof(struct arphdr);
 hdr->ar_hrd = htons(1);
 hdr->ar_pro = htons(0x0800);
 hdr->ar_hln = 6;
 hdr->ar_pln = 4;
 hdr->ar_op = htons(1);
 if(set_mac(buf + aoff, argv[2]))
 {
  fprintf(stderr, "\nОшибка при копировании MAC-адреса сетевого адаптера сетевого узла - отправителя в буфер\n\n");
  close(sock);
  return -1;
 }
 if(set_ip(buf + aoff + 6, argv[3]))
 {
  fprintf(stderr, "\nОшибка при копировании IP-адреса сетевого узла - отправителя в буфер\n\n");
  close(sock);
  return -1;
 }
 buf[aoff + 10] = 0;
 buf[aoff + 11] = 0;
 buf[aoff + 12] = 0;
 buf[aoff + 13] = 0;
 buf[aoff + 14] = 0;
 buf[aoff + 15] = 0;
 if(set_ip(buf + aoff + 16, argv[4]))
 {
  fprintf(stderr, "\nОшибка при копировании IP-адреса сетевого узла - получателя в буфер\n\n");
  close(sock);
  return -1;
 }
 struct sockaddr_ll addr;
 memset(& addr, 0, sizeof(struct sockaddr_ll));
 addr.sll_family = 17;
 addr.sll_protocol = htons(0x0806);
 addr.sll_hatype = 1;
 addr.sll_pkttype = 1;
 addr.sll_halen = 6;
 memset(addr.sll_addr, 0xFF, 8);
 if(
  (addr.sll_ifindex = get_iface_id(sock, argv[1])) == -1
   )
 {
  fprintf(stderr, "\nОшибка при получении идентификатора сетевого интерфейса\n\n");
  close(sock);
  return -1;
 }
 ssize_t size = sendto(sock, buf, aoff + 20, 0, (struct sockaddr *) & addr, sizeof(struct sockaddr_ll));
 if(size > 0)
 {
  char *temp;
  do
   size = recv(sock, buf, 4096, 0);
  while(ntohs(hdr->ar_op) != 2);
  if(
   (size > 0)
   &&
   (temp = mac_to_str(buf + aoff + 10)) != ((void *)0)
    )
  {
   printf("\nПолучен ARP-ответ: %s -> %s\n\n", argv[4], temp);
   free(temp);
  }
  else
  {
   fprintf(stderr, "\nОшибка при получении ARP-ответа\n\n");
   close(sock);
   return -1;
  }
 }
 else
 {
  fprintf(stderr, "\nОшибка при отправлении ARP-запроса\n\n");
  close(sock);
  return -1;
 }
 close(sock);
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
 if(argc != 5)
 {
  fprintf(stderr, "\nПрограмме передано недостаточное количество аргументов\n\nФормат вызова: ./program IFACE IMAC IIP OIP\n\nЗдесь:\n\n\tIFACE\t-\tимя сетевого интерфейса сетевого адаптера сетевого узла - отправителя;\n\tIMAC\t-\tMAC-адрес сетевого адаптера сетевого узла - отправителя;\n\tIIP\t-\tIPv4-адрес сетевого узла - отправителя;\n\tOIP\t-\tIPv4-адрес, соответствующий MAC-адрес для которого необходимо определить.\n\n");
  return -1;
 }
 int sock = socket(17, SOCK_DGRAM, htons(0x0806));
 if(sock == -1)
 {
  fprintf(stderr, "\nОшибка: создать сокет не удалось\n\n");
  return -1;
 }
 unsigned char buf[4096];
 struct arphdr *hdr = (struct arphdr *) buf;
 unsigned long aoff = sizeof(struct arphdr);
 hdr->ar_hrd = htons(1);
 hdr->ar_pro = htons(0x0800);
 hdr->ar_hln = 6;
 hdr->ar_pln = 4;
 hdr->ar_op = htons(1);
 if(set_mac(buf + aoff, argv[2]))
 {
  fprintf(stderr, "\nОшибка при копировании MAC-адреса сетевого адаптера сетевого узла - отправителя в буфер\n\n");
  close(sock);
  return -1;
 }
 if(set_ip(buf + aoff + 6, argv[3]))
 {
  fprintf(stderr, "\nОшибка при копировании IP-адреса сетевого узла - отправителя в буфер\n\n");
  close(sock);
  return -1;
 }
 buf[aoff + 10] = 0;
 buf[aoff + 11] = 0;
 buf[aoff + 12] = 0;
 buf[aoff + 13] = 0;
 buf[aoff + 14] = 0;
 buf[aoff + 15] = 0;
 if(set_ip(buf + aoff + 16, argv[4]))
 {
  fprintf(stderr, "\nОшибка при копировании IP-адреса сетевого узла - получателя в буфер\n\n");
  close(sock);
  return -1;
 }
 struct sockaddr_ll addr;
 memset(& addr, 0, sizeof(struct sockaddr_ll));
 addr.sll_family = 17;
 addr.sll_protocol = htons(0x0806);
 addr.sll_hatype = 1;
 addr.sll_pkttype = 1;
 addr.sll_halen = 6;
 memset(addr.sll_addr, 0xFF, 8);
 if(
  (addr.sll_ifindex = get_iface_id(sock, argv[1])) == -1
   )
 {
  fprintf(stderr, "\nОшибка при получении идентификатора сетевого интерфейса\n\n");
  close(sock);
  return -1;
 }
 long size = sendto(sock, buf, aoff + 20, 0, (struct sockaddr *) & addr, sizeof(struct sockaddr_ll));
 if(size > 0)
 {
  char *temp;
  do
   size = recv(sock, buf, 4096, 0);
  while(ntohs(hdr->ar_op) != 2);
  if(
   (size > 0)
   &&
   (temp = mac_to_str(buf + aoff + 10)) != ((void *)0)
    )
  {
   printf("\nПолучен ARP-ответ: %s -> %s\n\n", argv[4], temp);
   free(temp);
  }
  else
  {
   fprintf(stderr, "\nОшибка при получении ARP-ответа\n\n");
   close(sock);
   return -1;
  }
 }
 else
 {
  fprintf(stderr, "\nОшибка при отправлении ARP-запроса\n\n");
  close(sock);
  return -1;
 }
 close(sock);
 return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types:
buf
unsigned char [4096]

variable_types: struct arphdr { unsigned short ar_hrd; unsigned short ar_pro; unsigned char ar_hln; unsigned char ar_pln; unsigned short ar_op; } *

variable_types:
aoff
unsigned long

variable_types: struct sockaddr_ll { unsigned short sll_family; unsigned short sll_protocol; int sll_ifindex; unsigned short sll_hatype; unsigned char sll_pkttype; unsigned char sll_halen; unsigned char sll_addr[8]; }


decompiled_code:
void __noreturn SIGINT_handler()
{
if ( sock != -1 )
{
if ( is_promisc )
{
word_4040D0 ^= 0x100u;
ioctl(sock, 0x8914uLL, req);
}
close(sock);
}
puts(asc_402008);
exit(0);
}

canonical_decompiled_code:
void __noreturn func7()
{
if ( sock != -1 )
{
if ( is_promisc )
{
word_4040D0 ^= 0x100u;
ioctl(sock, 0x8914uLL, req);
}
close(sock);
}
puts(asc_402008);
exit(0);
}

original_code:
void SIGINT_handler(int notused)
{
 if(sock != -1)
 {
  if(is_promisc)
  {
   req.ifr_ifru.ifru_flags ^= IFF_PROMISC;
   ioctl(sock, 0x8914, & req);
  }
  close(sock);
 }
 printf("\n-----> Останов прослушивания <-----\n\n");
 exit(0);
}

variable_types: notused int

return_type: void


original_code:
int main(const int argc, const char *argv[])
{
 printf("\n");
 if(argc != 2)
  return error("Программе передано недостаточное количество аргументов\n\nФормат вызова: ./program ИМЯ_ПРОСЛУШИВАЕМОГО_СЕТЕВОГО_ИНТЕРФЕЙСА");
 if(signal(2, & SIGINT_handler) == ((__sighandler_t) -1))
  return error("Невозможно установить обработчик сигнала SIGINT");
 sock = socket(17, SOCK_RAW, htons(0x0800));
 if (sock == -1)
  return error("Невозможно создать сокет");
 strcpy(req.ifr_ifrn.ifrn_name, argv[1]);
 if(ioctl(sock, 0x8913, & req))
  return error("Невозможно получить набор параметров сетевого адаптера\n");
 req.ifr_ifru.ifru_flags |= IFF_PROMISC;
 if(ioctl(sock, 0x8914, & req))
  return error("Невозможно перевести сетевой адаптер в неразборчивый режим\n");
 is_promisc = 1;
 char buf[4096 + 1];
 unsigned tcp_data_offset;
 ssize_t get_bytes;
 struct in_addr saddr, daddr;
 struct ethhdr *eth_header = (struct ethhdr *) buf;
 struct iphdr *ip_header = (struct iphdr *) (buf + sizeof(struct ethhdr));
 struct tcphdr *tcp_header = (struct tcphdr *) (buf + (sizeof(struct ethhdr) + sizeof(struct iphdr)));
 printf("-----> Запуск прослушивания <-----\n\n");
 while(1)
 {
  if(
   (get_bytes = recv(sock, buf, 4096, 0)) > 0
   &&
   (eth_header->h_proto == htons(0x0800))
   &&
   (ip_header->protocol == IPPROTO_TCP)
    )
  {
   saddr.s_addr = ip_header->saddr;
   daddr.s_addr = ip_header->daddr;
   tcp_data_offset = (sizeof(struct ethhdr) + sizeof(struct iphdr)) + tcp_header->doff * 4;
   printf("[ %s:%u -> ", inet_ntoa(saddr), ntohs(tcp_header->source));
   printf("%s:%u ] [ %d байт, %d байт данных ] [ ", inet_ntoa(daddr), ntohs(tcp_header->dest), get_bytes, get_bytes - tcp_data_offset);
   if(tcp_header->fin)
    printf("FIN ");
   if(tcp_header->syn)
    printf("SYN ");
   if(tcp_header->rst)
    printf("RST ");
   if(tcp_header->psh)
    printf("PUSH ");
   if(tcp_header->ack)
    printf("ACK ");
   if(tcp_header->urg)
    printf("URG ");
   printf("] ");
   if(tcp_data_offset != get_bytes)
   {
    if(buf[get_bytes - 1] == 0x0A)
     buf[get_bytes - 1] = '\0';
    printf("[ %s ]\n", buf + tcp_data_offset);
   }
   else
    printf("\n");
  }
 }
}

canonical_original_code:
int main(int argc, char *argv[])
{
 printf("\n");
 if(argc != 2)
  return error("Программе передано недостаточное количество аргументов\n\nФормат вызова: ./program ИМЯ_ПРОСЛУШИВАЕМОГО_СЕТЕВОГО_ИНТЕРФЕЙСА");
 if(signal(2, & SIGINT_handler) == ((__sighandler_t) -1))
  return error("Невозможно установить обработчик сигнала SIGINT");
 sock = socket(17, SOCK_RAW, htons(0x0800));
 if (sock == -1)
  return error("Невозможно создать сокет");
 strcpy(req.ifr_ifrn.ifrn_name, argv[1]);
 if(ioctl(sock, 0x8913, & req))
  return error("Невозможно получить набор параметров сетевого адаптера\n");
 req.ifr_ifru.ifru_flags |= IFF_PROMISC;
 if(ioctl(sock, 0x8914, & req))
  return error("Невозможно перевести сетевой адаптер в неразборчивый режим\n");
 is_promisc = 1;
 char buf[-1];
 unsigned int tcp_data_offset;
 long get_bytes;
 struct in_addr saddr; struct in_addr daddr;
 struct ethhdr *eth_header = (struct ethhdr *) buf;
 struct iphdr *ip_header = (struct iphdr *) (buf + sizeof(struct ethhdr));
 struct tcphdr *tcp_header = (struct tcphdr *) (buf + (sizeof(struct ethhdr) + sizeof(struct iphdr)));
 printf("-----> Запуск прослушивания <-----\n\n");
 while(1)
 {
  if(
   (get_bytes = recv(sock, buf, 4096, 0)) > 0
   &&
   (eth_header->h_proto == htons(0x0800))
   &&
   (ip_header->protocol == IPPROTO_TCP)
    )
  {
   saddr.s_addr = ip_header->saddr;
   daddr.s_addr = ip_header->daddr;
   tcp_data_offset = (sizeof(struct ethhdr) + sizeof(struct iphdr)) + tcp_header->doff * 4;
   printf("[ %s:%u -> ", inet_ntoa(saddr), ntohs(tcp_header->source));
   printf("%s:%u ] [ %d байт, %d байт данных ] [ ", inet_ntoa(daddr), ntohs(tcp_header->dest), get_bytes, get_bytes - tcp_data_offset);
   if(tcp_header->fin)
    printf("FIN ");
   if(tcp_header->syn)
    printf("SYN ");
   if(tcp_header->rst)
    printf("RST ");
   if(tcp_header->psh)
    printf("PUSH ");
   if(tcp_header->ack)
    printf("ACK ");
   if(tcp_header->urg)
    printf("URG ");
   printf("] ");
   if(tcp_data_offset != get_bytes)
   {
    if(buf[get_bytes - 1] == 0x0A)
     buf[get_bytes - 1] = '\0';
    printf("[ %s ]\n", buf + tcp_data_offset);
   }
   else
    printf("\n");
  }
 }
}

variable_types:
buf
char [-1]

variable_types:
saddr
struct in_addr { unsigned int s_addr; }

variable_types:
daddr
struct in_addr { unsigned int s_addr; }

variable_types: struct ethhdr { unsigned char h_dest[6]; unsigned char h_source[6]; unsigned short h_proto; } *

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

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


error

decompiled_code:
__int64 __fastcall error(__int64 a1)
{
fprintf(stderr, asc_402300, a1);
if ( sock != -1 )
close(sock);
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1)
{
fprintf(stderr, asc_402300, a1);
if ( sock != -1 )
close(sock);
return 0xFFFFFFFFLL;
}

original_code:
int error(const char *mes)
{
 fprintf(stderr, "[Ошибка] %s\n\n", mes);
 if(sock != -1)
  close(sock);
 return -1;
}

canonical_original_code:
int error(char *mes)
{
 fprintf(stderr, "[Ошибка] %s\n\n", mes);
 if(sock != -1)
  close(sock);
 return -1;
}

variable_types:
mes
char *


decompiled_code:
double normal_distrib()
{
int v0; // ebx
double v1; // xmm0_8
double v3; // [rsp+0h] [rbp-10h]

v0 = 12;
v3 = 0.0;
do
{
v1 = drand48() + v3;
v3 = v1;
--v0;
}
while ( v0 );
return (v1 - 6.0) / 6.0;
}

original_code:
double normal_distrib()
{
 unsigned k;
 double epsilon;
 for(k = 0, epsilon = 0; k < 12; k++)
  epsilon += drand48();
 return (epsilon - 6) / 6;
}

canonical_original_code:
double normal_distrib()
{
 unsigned int k;
 double epsilon;
 for(k = 0, epsilon = 0; k < 12; k++)
  epsilon += drand48();
 return (epsilon - 6) / 6;
}

variable_types:
k
unsigned int

variable_types: epsilon double

return_type: double


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // ebx
unsigned int v4; // eax
int v5; // er13
int v6; // er14
void *v7; // r12
__int64 v8; // rax
unsigned int v9; // ebp
int result; // eax
double v11; // [rsp+0h] [rbp-78h]
double v12; // [rsp+8h] [rbp-70h]
struct timespec tp; // [rsp+10h] [rbp-68h] BYREF
struct timespec v14; // [rsp+20h] [rbp-58h] BYREF
void *v15; // [rsp+30h] [rbp-48h]
unsigned int v16; // [rsp+38h] [rbp-40h]
int v17; // [rsp+3Ch] [rbp-3Ch]
int v18; // [rsp+40h] [rbp-38h]

if ( argc == 4 )
{
v3 = atoi(argv[2]);
v4 = atoi(argv[3]);
v5 = v4;
if ( (unsigned int)v3 <= 2 )
{
fwrite(&unk_402050, 1uLL, 0x88uLL, stderr);
result = -1;
}
else
{
v6 = v4;
v7 = calloc(v4, 8uLL);
v8 = lrand48();
srand48(v8);
atoi(argv[1]);
omp_set_num_threads();
v9 = omp_get_max_threads();
clock_gettime(0, &tp);
v15 = v7;
v18 = v5;
v17 = v3;
v16 = v9;
v14.tv_sec = 0LL;
v14.tv_nsec = 0LL;
GOMP_parallel();
v12 = *(double *)&v14.tv_sec;
v11 = *(double *)&v14.tv_nsec / (double)v6;
clock_gettime(0, &v14);
printf(
format,
v9,
v12,
v11,
(double)v3 / (double)(v3 - 2),
(double)(LODWORD(v14.tv_sec) - LODWORD(tp.tv_sec) + 1)
+ (double)(LODWORD(v14.tv_nsec) - LODWORD(tp.tv_nsec)) / 1000000000.0);
free(v7);
result = 0;
}
}
else
{
fwrite(&unk_402008, 1uLL, 0x46uLL, stderr);
result = -1;
}
return result;
}

original_code:
int main(const int argc, const char * argv[])
{
 if(argc != 4)
 {
  fprintf(stderr, "\nНедостаточно или избыток аргументов\n\n");
  return -1;
 }
 unsigned u, v, t_ind, t_num, n = atoi(argv[2]), N = atoi(argv[3]);
 if(n < 3)
 {
  fprintf(stderr, "\nЧисло степеней свободы распределения Стьюдента должно быть больше двух)\n\n");
  return -1;
 }
 double tx, su, m = 0, d = 0, * x = calloc(N, sizeof(double));
 struct timespec ts_before, ts_after;
 srand48(lrand48());
 omp_set_num_threads(atoi(argv[1]));
 t_num = omp_get_max_threads();
 clock_gettime(0, & ts_before);

#pragma omp parallel private(t_ind, u, v, tx, su)
 {
  t_ind = omp_get_thread_num();
  for(u = t_ind; u < N; u += t_num)
  {
   for(v = 0, tx = 0; v < n; v++)
   {
    su = normal_distrib();
    tx += su * su;
   }
   x[u] = tx = normal_distrib() / sqrt(tx / n);

#pragma omp critical
   {
    m += tx;
   }
  }

#pragma omp barrier

#pragma omp single
  {
   m /= (double) N;
  }

#pragma omp barrier
  for(u = t_ind; u < N; u += t_num)
  {
   tx = x[u] - m;

#pragma omp critical
   {
    d += tx * tx;
   }
  }
 }
 d /= (double) N;
 clock_gettime(0, & ts_after);
 printf("\nМатематическое ожидание:\n\n\tЭмпирическое = %lf\n\tТеоретическое = 0\n\nДисперсия:\n\n\tЭмпирическая = %lf\n\tТеоретическая = %lf\n\nРасчет выполнили %d поток(а; ов) за %lf секунд(ы)\n\n", m, d, n / (double) (n - 2), t_num, ts_after.tv_sec - ts_before.tv_sec + 1 + (ts_after.tv_nsec - ts_before.tv_nsec) / 1000000000.0);
 free(x);
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
 if(argc != 4)
 {
  fprintf(stderr, "\nНедостаточно или избыток аргументов\n\n");
  return -1;
 }
 unsigned int u; unsigned int v; unsigned int t_ind; unsigned int t_num; unsigned int n = atoi(argv[2]); unsigned int N = atoi(argv[3]);
 if(n < 3)
 {
  fprintf(stderr, "\nЧисло степеней свободы распределения Стьюдента должно быть больше двух)\n\n");
  return -1;
 }
 double tx; double su; double m = 0; double d = 0; double *x = calloc(N, sizeof(double));
 struct timespec ts_before; struct timespec ts_after;
 srand48(lrand48());
 omp_set_num_threads(atoi(argv[1]));
 t_num = omp_get_max_threads();
 clock_gettime(0, & ts_before);

#pragma omp parallel private(t_ind, u, v, tx, su)
 {
  t_ind = omp_get_thread_num();
  for(u = t_ind; u < N; u += t_num)
  {
   for(v = 0, tx = 0; v < n; v++)
   {
    su = normal_distrib();
    tx += su * su;
   }
   x[u] = tx = normal_distrib() / sqrt(tx / n);

#pragma omp critical
   {
    m += tx;
   }
  }

#pragma omp barrier

#pragma omp single
  {
   m /= (double) N;
  }

#pragma omp barrier
  for(u = t_ind; u < N; u += t_num)
  {
   tx = x[u] - m;

#pragma omp critical
   {
    d += tx * tx;
   }
  }
 }
 d /= (double) N;
 clock_gettime(0, & ts_after);
 printf("\nМатематическое ожидание:\n\n\tЭмпирическое = %lf\n\tТеоретическое = 0\n\nДисперсия:\n\n\tЭмпирическая = %lf\n\tТеоретическая = %lf\n\nРасчет выполнили %d поток(а; ов) за %lf секунд(ы)\n\n", m, d, n / (double) (n - 2), t_num, ts_after.tv_sec - ts_before.tv_sec + 1 + (ts_after.tv_nsec - ts_before.tv_nsec) / 1000000000.0);
 free(x);
 return 0;
}

variable_types:
u
unsigned int

variable_types:
v
unsigned int

variable_types:
n
unsigned int

variable_types:
N
unsigned int

variable_types: tx double

variable_types: su double

variable_types: m double

variable_types: d double

variable_types:
x
double *

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


printIndentation

repo: vgramer/TP-compil

decompiled_code:
int printIndentation()
{
int result; // eax
int v1; // ebx

result = indent;
if ( indent > 0 )
{
v1 = 0;
do
{
++v1;
result = printf(" ");
}
while ( indent > v1 );
}
return result;
}

canonical_decompiled_code:
int func0()
{
int result; // eax
int v1; // ebx

result = indent;
if ( indent > 0 )
{
v1 = 0;
do
{
++v1;
result = printf(" ");
}
while ( indent > v1 );
}
return result;
}

original_code:
void printIndentation(){
 int i=0;
 for(i=0;i<indent;i++){
   printf("    ");
 }
}

canonical_original_code:
void printIndentation(){
 int i = 0;
 for(i=0;i<indent;i++){
   printf("    ");
 }
}

variable_types: i int


pprintGet

decompiled_code:
int pprintGet()
{
return printf("LIRE()");
}

canonical_decompiled_code:
int func1()
{
return printf("LIRE()");
}

original_code:
void pprintGet() {
  printf("LIRE()");
}

canonical_original_code:
void pprintGet() {
  printf("LIRE()");
}


concate

decompiled_code:
char *__fastcall concate(const char **a1, const char *a2)
{
char *v2; // r13
size_t v3; // r12
size_t v4; // rax
char *v5; // rax
char *result; // rax

v2 = (char *)*a1;
v3 = strlen(*a1);
v4 = strlen(a2);
v5 = (char *)realloc(v2, v3 + v4 + 1);
*a1 = v5;
if ( !v5 )
{
printf("\n\n------------------------\n ERROR CAN NOT REALOCC MEMORY !!!! \n------------------------");
exit(1);
}
result = strcat(v5, a2);
*a1 = result;
return result;
}

canonical_decompiled_code:
char *__fastcall func0(const char **a1, const char *a2)
{
char *v2; // r13
size_t v3; // r12
size_t v4; // rax
char *v5; // rax
char *result; // rax

v2 = (char *)*a1;
v3 = strlen(*a1);
v4 = strlen(a2);
v5 = (char *)realloc(v2, v3 + v4 + 1);
*a1 = v5;
if ( !v5 )
{
printf("\n\n------------------------\n ERROR CAN NOT REALOCC MEMORY !!!! \n------------------------");
exit(1);
}
result = strcat(v5, a2);
*a1 = result;
return result;
}

original_code:
void concate(char** source, const char* stringToConcate)
{
 *source = (char*)realloc(*source, sizeof(char) * (strlen(*source) + strlen(stringToConcate) +1) );
 if(*source == 0)
 {
  printf("\n\n------------------------\n ERROR CAN NOT REALOCC MEMORY !!!! \n------------------------");
  exit(1);
 }
 *source =strcat(*source, stringToConcate);
}

canonical_original_code:
void concate(char **source, char *stringToConcate)
{
 *source = (char *)realloc(*source, sizeof(char) * (strlen(*source) + strlen(stringToConcate) +1) );
 if(*source == 0)
 {
  printf("\n\n------------------------\n ERROR CAN NOT REALOCC MEMORY !!!! \n------------------------");
  exit(1);
 }
 *source =strcat(*source, stringToConcate);
}

variable_types:
source
char **

variable_types:
stringToConcate
char *


genIndentation

decompiled_code:
char *__fastcall genIndentation(const char **a1)
{
char *result; // rax
int v2; // ebx

result = (char *)(unsigned int)indentation;
if ( indentation > 0 )
{
v2 = 0;
do
{
++v2;
result = concate(a1, " ");
}
while ( indentation > v2 );
}
return result;
}

canonical_decompiled_code:
char *__fastcall func1(const char **a1)
{
char *result; // rax
int v2; // ebx

result = (char *)(unsigned int)indentation;
if ( indentation > 0 )
{
v2 = 0;
do
{
++v2;
result = func0(a1, " ");
}
while ( indentation > v2 );
}
return result;
}

original_code:
void genIndentation(char** generated_code){
 int i=0;
 for(i=0;i<indentation;i++){
   concate(generated_code, "    ");
 }
}

canonical_original_code:
void genIndentation(char **generated_code){
 int i = 0;
 for(i=0;i<indentation;i++){
   concate(generated_code, "    ");
 }
}


genGet

decompiled_code:
char *__fastcall genGet(const char **a1)
{
return concate(a1, "__ask_int_value()");
}

canonical_decompiled_code:
char *__fastcall func4(const char **a1)
{
return func0(a1, "__ask_int_value()");
}

original_code:
void genGet(char** generated_code) {
  concate(generated_code, "__ask_int_value()");
}

canonical_original_code:
void genGet(char **generated_code) {
  concate(generated_code, "__ask_int_value()");
}


repo: vhbsoft/triton

decompiled_code:
int __fastcall w_UDPTrainGenerator(void *a1)
{
int result; // eax

result = UDPTrainReceiver(*((_QWORD *)a1 + 1), (char *)a1 + 16, *(unsigned int *)a1);
if ( result )
result = fprintf(stderr, "ERROR #%d: UDP Train Receiver Error", 7LL);
return result;
}

canonical_decompiled_code:
int __fastcall func0(void *a1)
{
int result; // eax

result = UDPTrainReceiver(*((_QWORD *)a1 + 1), (char *)a1 + 16, *(unsigned int *)a1);
if ( result )
result = fprintf(stderr, "ERROR #%d: UDP Train Receiver Error", 7LL);
return result;
}

original_code:
void w_UDPTrainGenerator(struct thread_data* td)
{
 if(UDPTrainReceiver(td->send_buffer, &(td->send_buffer_length), td->probe_packet_length) != 0)
 {
  fprintf(stderr, "ERROR #%d: UDP Train Receiver Error", UDP_TRAIN_RECEIVER_FAILED);
      return;
 }
}

canonical_original_code:
void w_UDPTrainGenerator(struct thread_data *td)
{
 if(UDPTrainReceiver(td->send_buffer, &(td->send_buffer_length), td->probe_packet_length) != 0)
 {
  fprintf(stderr, "ERROR #%d: UDP Train Receiver Error", UDP_TRAIN_RECEIVER_FAILED);
      return;
 }
}

variable_types: struct thread_data { int probe_packet_length; char *send_buffer; unsigned long send_buffer_length; } *


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int result; // eax
char v4[4]; // [rsp+8h] [rbp-40h] BYREF
int v5; // [rsp+Ch] [rbp-3Ch] BYREF
char v6[8]; // [rsp+10h] [rbp-38h] BYREF
pthread_t newthread; // [rsp+18h] [rbp-30h] BYREF
int arg; // [rsp+20h] [rbp-28h] BYREF
void *v9; // [rsp+28h] [rbp-20h]
__int64 v10; // [rsp+30h] [rbp-18h]

while ( 1 )
{
memset(&send_buffer, 0, (size_t)&unk_249F0);
send_buffer_length = 0LL;
if ( (unsigned int)PreExperimentTCPReceiver(v4, v6, &v5) )
{
fprintf(stderr, "ERROR #%d: PreExperiment TCP Receiver Error", 3LL);
return 3;
}
puts("Pre is done");
v9 = &send_buffer;
arg = v5;
v10 = send_buffer_length;
result = pthread_create(&newthread, 0LL, (void *(*)(void *))w_UDPTrainGenerator, &arg);
if ( result == -1 )
return result;
puts("UDP is done");
if ( (unsigned int)PostExperimentTCPReceiver(&send_buffer, &unk_249F0) )
break;
puts("Post is done");
pthread_kill(newthread, 2);
pthread_join(newthread, 0LL);
}
fprintf(stderr, "ERROR #%d: PostExperiment TCP Receiver Error", 5LL);
return 5;
}

original_code:
int main(int argc, char *argv[])
{
  int num_of_packets;
  unsigned long inter_packet_departure_spacing;
  int probe_packet_length;
  while(1)
  {
  int i;
  for(i=0; i<150000;i++){
    send_buffer[i] = 0;
  }
  send_buffer_length = 0;
  if(PreExperimentTCPReceiver(&num_of_packets, &inter_packet_departure_spacing,
                              &probe_packet_length) != 0)
  {
    fprintf(stderr, "ERROR #%d: PreExperiment TCP Receiver Error", PRE_EXPERIMENT_TCP_RECEIVER_FAILED);
    return PRE_EXPERIMENT_TCP_RECEIVER_FAILED;
  }
 printf("Pre is done\n");
 pthread_t t0;
 struct thread_data td;
 td.probe_packet_length = probe_packet_length;
 td.send_buffer = send_buffer;
 td.send_buffer_length = send_buffer_length;
 if (pthread_create(&t0, ((void *)0), (void*)w_UDPTrainGenerator, (void*) &td) == -1)
  return -1;
 printf("UDP is done\n");
  if(PostExperimentTCPReceiver( send_buffer, 150000) != 0)
  {
    fprintf(stderr, "ERROR #%d: PostExperiment TCP Receiver Error", POST_EXPERIMENT_TCP_RECEIVER_FAILED);
    return POST_EXPERIMENT_TCP_RECEIVER_FAILED;
  }
 printf("Post is done\n");
 pthread_kill(t0,2);
 pthread_join(t0, ((void *)0));
  }
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
  int num_of_packets;
  unsigned long inter_packet_departure_spacing;
  int probe_packet_length;
  while(1)
  {
  int i;
  for(i=0; i<150000;i++){
    send_buffer[i] = 0;
  }
  send_buffer_length = 0;
  if(PreExperimentTCPReceiver(&num_of_packets, &inter_packet_departure_spacing,
                              &probe_packet_length) != 0)
  {
    fprintf(stderr, "ERROR #%d: PreExperiment TCP Receiver Error", PRE_EXPERIMENT_TCP_RECEIVER_FAILED);
    return PRE_EXPERIMENT_TCP_RECEIVER_FAILED;
  }
 printf("Pre is done\n");
 unsigned long t0;
 struct thread_data td;
 td.probe_packet_length = probe_packet_length;
 td.send_buffer = send_buffer;
 td.send_buffer_length = send_buffer_length;
 if (pthread_create(&t0, ((void *)0), (void *)w_UDPTrainGenerator, (void *) &td) == -1)
  return -1;
 printf("UDP is done\n");
  if(PostExperimentTCPReceiver( send_buffer, 150000) != 0)
  {
    fprintf(stderr, "ERROR #%d: PostExperiment TCP Receiver Error", POST_EXPERIMENT_TCP_RECEIVER_FAILED);
    return POST_EXPERIMENT_TCP_RECEIVER_FAILED;
  }
 printf("Post is done\n");
 pthread_kill(t0,2);
 pthread_join(t0, ((void *)0));
  }
 return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: struct thread_data { int probe_packet_length; char *send_buffer; unsigned long send_buffer_length; }


decompiled_code:
void __noreturn handle_shutdown()
{
if ( recv_socket )
close(recv_socket);
pthread_exit(0LL);
}

canonical_decompiled_code:
void __noreturn func0()
{
if ( recv_socket )
close(recv_socket);
pthread_exit(0LL);
}

original_code:
void handle_shutdown(int sig)
{
        if (recv_socket)
         close(recv_socket);
        pthread_exit(((void *)0));
}

variable_types: sig int


UDPTrainReceiver

decompiled_code:
__int64 __fastcall UDPTrainReceiver(char *dest, __int64 a2, int a3)
{
int v4; // eax
int v5; // er13
int v6; // ebx
int v7; // er14
unsigned int v8; // ebp
int v9; // ebx
__int64 v10; // rdx
__int64 result; // rax
int optval; // [rsp+4h] [rbp-8C4h] BYREF
struct addrinfo *pai; // [rsp+8h] [rbp-8C0h] BYREF
struct timespec tp; // [rsp+10h] [rbp-8B8h] BYREF
struct timespec v15; // [rsp+20h] [rbp-8A8h] BYREF
struct addrinfo req; // [rsp+30h] [rbp-898h] BYREF
char src[112]; // [rsp+60h] [rbp-868h] BYREF
int buf[510]; // [rsp+D0h] [rbp-7F8h] BYREF

if ( signal(2, (__sighandler_t)handle_shutdown) == (__sighandler_t)-1LL )
printf(aCan);
*(_OWORD *)&req.ai_socktype = 0LL;
req.ai_next = 0LL;
*(_QWORD *)&req.ai_flags = 0x200000001LL;
req.ai_socktype = 2;
*(_OWORD *)&req.ai_addr = 0LL;
if ( getaddrinfo(0LL, "9876", &req, &pai) )
{
fprintf(stderr, "ERROR #%d: Address Information Error", 109LL);
result = 109LL;
}
else
{
v4 = socket(pai->ai_family, pai->ai_socktype, pai->ai_protocol);
v5 = v4;
if ( v4 == -1 )
{
fprintf(stderr, "ERROR #%d: Socket Setup Error", 102LL);
result = 102LL;
}
else
{
optval = 1;
if ( setsockopt(v4, 1, 2, &optval, 4u) == -1 )
printf("Can't set the reuse option on the socket");
if ( bind(v5, pai->ai_addr, pai->ai_addrlen) == -1 )
{
fprintf(stderr, "ERROR #%d: Binding Error", 106LL);
close(v5);
result = 106LL;
}
else
{
freeaddrinfo(pai);
clock_gettime(2, &tp);
if ( v5 )
{
v6 = -1;
v7 = a3 - 1;
while ( 1 )
{
recvfrom(v5, buf, v7, 0, 0LL, 0LL);
v8 = buf[0];
if ( buf[0] - v6 == 1 )
goto LABEL_14;
if ( buf[0] - v6 > 1 )
{
v9 = v6 + 1;
if ( buf[0] > v9 )
{
do
{
++v9;
strcpy(src, "\t-1\n");
strcat(dest, src);
}
while ( v8 != v9 );
}
LABEL_14:
v6 = v8;
clock_gettime(2, &v15);
diff(tp.tv_sec, tp.tv_nsec, v15.tv_sec, v15.tv_nsec);
sprintf(src, "%d\t%ld\n", v8, v10);
strcat(dest, src);
}
}
}
result = 0LL;
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(char *dest, __int64 a2, int a3)
{
int v4; // eax
int v5; // er13
int v6; // ebx
int v7; // er14
unsigned int v8; // ebp
int v9; // ebx
__int64 v10; // rdx
__int64 result; // rax
int optval; // [rsp+4h] [rbp-8C4h] BYREF
struct addrinfo *pai; // [rsp+8h] [rbp-8C0h] BYREF
struct timespec tp; // [rsp+10h] [rbp-8B8h] BYREF
struct timespec v15; // [rsp+20h] [rbp-8A8h] BYREF
struct addrinfo req; // [rsp+30h] [rbp-898h] BYREF
char src[112]; // [rsp+60h] [rbp-868h] BYREF
int buf[510]; // [rsp+D0h] [rbp-7F8h] BYREF

if ( signal(2, (__sighandler_t)handle_shutdown) == (__sighandler_t)-1LL )
printf(aCan);
*(_OWORD *)&req.ai_socktype = 0LL;
req.ai_next = 0LL;
*(_QWORD *)&req.ai_flags = 0x200000001LL;
req.ai_socktype = 2;
*(_OWORD *)&req.ai_addr = 0LL;
if ( getaddrinfo(0LL, "9876", &req, &pai) )
{
fprintf(stderr, "ERROR #%d: Address Information Error", 109LL);
result = 109LL;
}
else
{
v4 = socket(pai->ai_family, pai->ai_socktype, pai->ai_protocol);
v5 = v4;
if ( v4 == -1 )
{
fprintf(stderr, "ERROR #%d: Socket Setup Error", 102LL);
result = 102LL;
}
else
{
optval = 1;
if ( setsockopt(v4, 1, 2, &optval, 4u) == -1 )
printf("Can't set the reuse option on the socket");
if ( bind(v5, pai->ai_addr, pai->ai_addrlen) == -1 )
{
fprintf(stderr, "ERROR #%d: Binding Error", 106LL);
close(v5);
result = 106LL;
}
else
{
freeaddrinfo(pai);
clock_gettime(2, &tp);
if ( v5 )
{
v6 = -1;
v7 = a3 - 1;
while ( 1 )
{
recvfrom(v5, buf, v7, 0, 0LL, 0LL);
v8 = buf[0];
if ( buf[0] - v6 == 1 )
goto LABEL_14;
if ( buf[0] - v6 > 1 )
{
v9 = v6 + 1;
if ( buf[0] > v9 )
{
do
{
++v9;
strcpy(src, "\t-1\n");
strcat(dest, src);
}
while ( v8 != v9 );
}
LABEL_14:
v6 = v8;
clock_gettime(2, &v15);
func1(tp.tv_sec, tp.tv_nsec, v15.tv_sec, v15.tv_nsec);
sprintf(src, "%d\t%ld\n", v8, v10);
strcat(dest, src);
}
}
}
result = 0LL;
}
}
}
return result;
}

original_code:
enum error_t UDPTrainReceiver (char* buffer, unsigned long* buffer_length, int probe_packet_length)
{
  if (signal(2, handle_shutdown) == ((__sighandler_t) -1))
                printf("Can’t set the interrupt handler");
  struct addrinfo hints;
  memset(&hints, 0, sizeof hints);
  hints.ai_family = 2;
  hints.ai_socktype = SOCK_DGRAM;
  hints.ai_flags = 0x0001;
  struct addrinfo* my_addr_info;
  int status = getaddrinfo(((void *)0), "9876", &hints, &my_addr_info);
  if (status != 0)
    {
 fprintf(stderr, "ERROR #%d: Address Information Error", ADDRINFO_ERROR);
 return ADDRINFO_ERROR;
    }
  int recv_socket = socket(my_addr_info->ai_family, my_addr_info->ai_socktype, my_addr_info->ai_protocol);
  if (recv_socket == -1)
    {
 fprintf(stderr, "ERROR #%d: Socket Setup Error", SOCKET_SETUP_ERROR);
 return SOCKET_SETUP_ERROR;
    }
 int reuse = 1;
        if (setsockopt(recv_socket, 1, 2, (char *)&reuse, sizeof(int)) == -1)
                printf("Can't set the reuse option on the socket");
  status = bind(recv_socket, my_addr_info->ai_addr, my_addr_info->ai_addrlen);
  if (status == -1)
    {
 fprintf(stderr, "ERROR #%d: Binding Error", BIND_ERROR);
 close (recv_socket);
 return BIND_ERROR;
    }
  freeaddrinfo(my_addr_info);
  int current_seq_id;
  int last_seq_id = -1;
  struct timespec startTime, endTime;
  clock_gettime(2, &startTime);
  char temp[100];
  char packet_buffer[2000];
  int log_size;
  int i;
  while (1)
    {
 if(!recv_socket){
  return SUCCESS;
 }
 recvfrom(recv_socket, packet_buffer, probe_packet_length-1, 0, ((void *)0), ((void *)0));
 current_seq_id = *((int*) packet_buffer);
 if (current_seq_id - last_seq_id == 1)
     {
  clock_gettime(2, &endTime);
                log_size = sprintf(temp, "%d\t%ld\n",current_seq_id, diff(startTime, endTime).tv_nsec);
  strcat(buffer,temp);
  buffer_length += log_size;
  last_seq_id = current_seq_id;
     }
     else if (current_seq_id - last_seq_id > 1)
     {
  for (i=last_seq_id+1; i<current_seq_id; i++)
         {
   log_size = sprintf(temp, "\t-1\n");
                 strcat(buffer,temp);
          buffer_length += log_size;
         }
                clock_gettime(2, &endTime);
                log_size = sprintf(temp, "%d\t%ld\n",current_seq_id, diff(startTime, endTime).tv_nsec);
                strcat(buffer,temp);
  buffer_length += log_size;
  last_seq_id = current_seq_id;
     }
    }
  close (recv_socket);
  return SUCCESS;
}

canonical_original_code:
enum error_t UDPTrainReceiver(char *buffer, unsigned long *buffer_length, int probe_packet_length)
{
  if (signal(2, handle_shutdown) == ((__sighandler_t) -1))
                printf("Can’t set the interrupt handler");
  struct addrinfo hints;
  memset(&hints, 0, sizeof hints);
  hints.ai_family = 2;
  hints.ai_socktype = SOCK_DGRAM;
  hints.ai_flags = 0x0001;
  struct addrinfo *my_addr_info;
  int status = getaddrinfo(((void *)0), "9876", &hints, &my_addr_info);
  if (status != 0)
    {
 fprintf(stderr, "ERROR #%d: Address Information Error", ADDRINFO_ERROR);
 return ADDRINFO_ERROR;
    }
  int recv_socket = socket(my_addr_info->ai_family, my_addr_info->ai_socktype, my_addr_info->ai_protocol);
  if (recv_socket == -1)
    {
 fprintf(stderr, "ERROR #%d: Socket Setup Error", SOCKET_SETUP_ERROR);
 return SOCKET_SETUP_ERROR;
    }
 int reuse = 1;
        if (setsockopt(recv_socket, 1, 2, (char *)&reuse, sizeof(int)) == -1)
                printf("Can't set the reuse option on the socket");
  status = bind(recv_socket, my_addr_info->ai_addr, my_addr_info->ai_addrlen);
  if (status == -1)
    {
 fprintf(stderr, "ERROR #%d: Binding Error", BIND_ERROR);
 close (recv_socket);
 return BIND_ERROR;
    }
  freeaddrinfo(my_addr_info);
  int current_seq_id;
  int last_seq_id = -1;
  struct timespec startTime; struct timespec endTime;
  clock_gettime(2, &startTime);
  char temp[100];
  char packet_buffer[2000];
  int log_size;
  int i;
  while (1)
    {
 if(!recv_socket){
  return SUCCESS;
 }
 recvfrom(recv_socket, packet_buffer, probe_packet_length-1, 0, ((void *)0), ((void *)0));
 current_seq_id = *((int *) packet_buffer);
 if (current_seq_id - last_seq_id == 1)
     {
  clock_gettime(2, &endTime);
                log_size = sprintf(temp, "%d\t%ld\n",current_seq_id, diff(startTime, endTime).tv_nsec);
  strcat(buffer,temp);
  buffer_length += log_size;
  last_seq_id = current_seq_id;
     }
     else if (current_seq_id - last_seq_id > 1)
     {
  for (i=last_seq_id+1; i<current_seq_id; i++)
         {
   log_size = sprintf(temp, "\t-1\n");
                 strcat(buffer,temp);
          buffer_length += log_size;
         }
                clock_gettime(2, &endTime);
                log_size = sprintf(temp, "%d\t%ld\n",current_seq_id, diff(startTime, endTime).tv_nsec);
                strcat(buffer,temp);
  buffer_length += log_size;
  last_seq_id = current_seq_id;
     }
    }
  close (recv_socket);
  return SUCCESS;
}

variable_types:
buffer
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: status int

variable_types: reuse int

variable_types:
temp
char [100]

return_type: enum error_t { SUCCESS=0, FAIL=1, PRE_EXPERIMENT_TCP_SENDER_FAILED=2, PRE_EXPERIMENT_TCP_RECEIVER_FAILED=3, POST_EXPERIMENT_TCP_SENDER_FAILED=4, POST_EXPERIMENT_TCP_RECEIVER_FAILED=5, UDP_TRAIN_GENERATOR_FAILED=6, UDP_TRAIN_RECEIVER_FAILED=7, SOCKET_SETUP_ERROR=102, CONNECT_ERROR=103, SEND_ERROR=104, RECEIVE_ERROR=105, BIND_ERROR=106, LISTEN_ERROR=107, ACCEPT_CLIENT_ERROR=108, ADDRINFO_ERROR=109, DEVRANDOM_ERROR=110, ENTROPY_PARAM_ERROR=111, COMPRESSION_ERROR=112, DECOMPRESSION_ERROR=113, FREAD_ERROR=114 }

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

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


diff

decompiled_code:
__int64 __fastcall diff(__int64 a1, __int64 a2, __int64 a3, __int64 a4)
{
__int64 result; // rax

result = a3 - a1;
if ( a4 - a2 < 0 )
--result;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 a2, __int64 a3, __int64 a4)
{
__int64 result; // rax

result = a3 - a1;
if ( a4 - a2 < 0 )
--result;
return result;
}

original_code:
struct timespec diff(struct timespec start, struct timespec end)
{
        struct timespec temp;
        if ((end.tv_nsec-start.tv_nsec)<0) {
                temp.tv_sec = end.tv_sec-start.tv_sec-1;
                temp.tv_nsec = 1000000000+end.tv_nsec-start.tv_nsec;
        } else {
                temp.tv_sec = end.tv_sec-start.tv_sec;
                temp.tv_nsec = end.tv_nsec-start.tv_nsec;
        }
        return temp;
}

variable_types:
start
struct timespec

variable_types:
end
struct timespec

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


PreExperimentTCPConnection

decompiled_code:
__int64 __fastcall PreExperimentTCPConnection(int a1, __int64 a2, int a3, __int64 a4, const char *a5)
{
int v6; // eax
unsigned int v7; // ebp
socklen_t v8; // edx
__int64 result; // rax
struct sockaddr v10; // [rsp+0h] [rbp-48h] BYREF
int v11; // [rsp+10h] [rbp-38h] BYREF
__int64 v12; // [rsp+14h] [rbp-34h]
int v13; // [rsp+1Ch] [rbp-2Ch]
char dest[40]; // [rsp+20h] [rbp-28h] BYREF

strcpy(dest, a5);
v11 = a1;
v12 = a2;
v13 = a3;
v6 = socket(2, 1, 6);
if ( v6 < 0 )
{
fprintf(stderr, "ERROR #%d: Socket Setup Error", 102LL);
result = 102LL;
}
else
{
v7 = v6;
v10 = 0LL;
v10.sa_family = 2;
inet_pton(2, dest, &v10.sa_data[2]);
*(_WORD *)v10.sa_data = _bswap_16_constprop_0(v7, &v10, 16LL);
if ( connect(v7, &v10, v8) < 0 )
{
fprintf(stderr, "ERROR #%d: Connection Setup Error IP = %s", 103LL, dest);
result = 103LL;
}
else if ( send(v7, &v11, 0x10uLL, 0) == 16 )
{
close(v7);
result = 0LL;
}
else
{
fprintf(stderr, "ERROR #%d: Send Data Error", 104LL);
result = 104LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1, __int64 a2, int a3, __int64 a4, const char *a5)
{
int v6; // eax
unsigned int v7; // ebp
socklen_t v8; // edx
__int64 result; // rax
struct sockaddr v10; // [rsp+0h] [rbp-48h] BYREF
int v11; // [rsp+10h] [rbp-38h] BYREF
__int64 v12; // [rsp+14h] [rbp-34h]
int v13; // [rsp+1Ch] [rbp-2Ch]
char dest[40]; // [rsp+20h] [rbp-28h] BYREF

strcpy(dest, a5);
v11 = a1;
v12 = a2;
v13 = a3;
v6 = socket(2, 1, 6);
if ( v6 < 0 )
{
fprintf(stderr, "ERROR #%d: Socket Setup Error", 102LL);
result = 102LL;
}
else
{
v7 = v6;
v10 = 0LL;
v10.sa_family = 2;
inet_pton(2, dest, &v10.sa_data[2]);
*(_WORD *)v10.sa_data = func0(v7, &v10, 16LL);
if ( connect(v7, &v10, v8) < 0 )
{
fprintf(stderr, "ERROR #%d: Connection Setup Error IP = %s", 103LL, dest);
result = 103LL;
}
else if ( send(v7, &v11, 0x10uLL, 0) == 16 )
{
close(v7);
result = 0LL;
}
else
{
fprintf(stderr, "ERROR #%d: Send Data Error", 104LL);
result = 104LL;
}
}
return result;
}

original_code:
enum error_t PreExperimentTCPConnection(int num_of_packets,
                      unsigned long inter_packet_departure_spacing,
                      int probe_packet_length,
                      int* timeout_estimation,
                      char* dest_addr){
  const size_t INTEGER_SIZE=sizeof(int);
  const size_t LONG_SIZE=sizeof(unsigned long);
  const unsigned int BUFFER_SEND_LENGTH=INTEGER_SIZE*2+LONG_SIZE;
  const int IP_ADDRESS_BUFFER_LENGTH = 16;
  int sock;
  struct sockaddr_in servAddr;
  char sendBuffer[BUFFER_SEND_LENGTH];
  char servIP[IP_ADDRESS_BUFFER_LENGTH];
  strcpy( servIP, dest_addr);
  memcpy((sendBuffer), &num_of_packets, INTEGER_SIZE);
  memcpy((sendBuffer+INTEGER_SIZE), &inter_packet_departure_spacing, LONG_SIZE);
  memcpy((sendBuffer+INTEGER_SIZE+LONG_SIZE), &probe_packet_length, INTEGER_SIZE);
  if ((sock = socket(2, SOCK_STREAM, IPPROTO_TCP)) < 0)
  {
    fprintf(stderr, "ERROR #%d: Socket Setup Error", SOCKET_SETUP_ERROR);
    return SOCKET_SETUP_ERROR;
  }
  memset(&servAddr, 0, sizeof(servAddr));
  servAddr.sin_family = 2;
   inet_pton(2, servIP, &servAddr.sin_addr);
 servAddr.sin_port = htons(16400);
  if (connect(sock, (struct sockaddr *) &servAddr, sizeof(servAddr)) < 0)
  {
    fprintf(stderr, "ERROR #%d: Connection Setup Error IP = %s", CONNECT_ERROR,servIP);
    return CONNECT_ERROR;
  }
  if (send(sock, sendBuffer, BUFFER_SEND_LENGTH, 0) != BUFFER_SEND_LENGTH){
    fprintf(stderr, "ERROR #%d: Send Data Error", SEND_ERROR);
    return SEND_ERROR;
  }
  close(sock);
 return 0;
}

canonical_original_code:
enum error_t PreExperimentTCPConnection(int num_of_packets, unsigned long inter_packet_departure_spacing, int probe_packet_length, int *timeout_estimation, char *dest_addr){
  unsigned long INTEGER_SIZE = sizeof(int);
  unsigned long LONG_SIZE = sizeof(unsigned long);
  unsigned int BUFFER_SEND_LENGTH = INTEGER_SIZE*2+LONG_SIZE;
  int IP_ADDRESS_BUFFER_LENGTH = 16;
  int sock;
  struct sockaddr_in servAddr;
  char sendBuffer[-1];
  char servIP[-1];
  strcpy( servIP, dest_addr);
  memcpy((sendBuffer), &num_of_packets, INTEGER_SIZE);
  memcpy((sendBuffer+INTEGER_SIZE), &inter_packet_departure_spacing, LONG_SIZE);
  memcpy((sendBuffer+INTEGER_SIZE+LONG_SIZE), &probe_packet_length, INTEGER_SIZE);
  if ((sock = socket(2, SOCK_STREAM, IPPROTO_TCP)) < 0)
  {
    fprintf(stderr, "ERROR #%d: Socket Setup Error", SOCKET_SETUP_ERROR);
    return SOCKET_SETUP_ERROR;
  }
  memset(&servAddr, 0, sizeof(servAddr));
  servAddr.sin_family = 2;
   inet_pton(2, servIP, &servAddr.sin_addr);
 servAddr.sin_port = htons(16400);
  if (connect(sock, (struct sockaddr *) &servAddr, sizeof(servAddr)) < 0)
  {
    fprintf(stderr, "ERROR #%d: Connection Setup Error IP = %s", CONNECT_ERROR,servIP);
    return CONNECT_ERROR;
  }
  if (send(sock, sendBuffer, BUFFER_SEND_LENGTH, 0) != BUFFER_SEND_LENGTH){
    fprintf(stderr, "ERROR #%d: Send Data Error", SEND_ERROR);
    return SEND_ERROR;
  }
  close(sock);
 return 0;
}

variable_types: sock int

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

variable_types:
sendBuffer
char [-1]

variable_types:
servIP
char [-1]

user_defined_types: enum error_t { SUCCESS=0, FAIL=1, PRE_EXPERIMENT_TCP_SENDER_FAILED=2, PRE_EXPERIMENT_TCP_RECEIVER_FAILED=3, POST_EXPERIMENT_TCP_SENDER_FAILED=4, POST_EXPERIMENT_TCP_RECEIVER_FAILED=5, UDP_TRAIN_GENERATOR_FAILED=6, UDP_TRAIN_RECEIVER_FAILED=7, SOCKET_SETUP_ERROR=102, CONNECT_ERROR=103, SEND_ERROR=104, RECEIVE_ERROR=105, BIND_ERROR=106, LISTEN_ERROR=107, ACCEPT_CLIENT_ERROR=108, ADDRINFO_ERROR=109, DEVRANDOM_ERROR=110, ENTROPY_PARAM_ERROR=111, COMPRESSION_ERROR=112, DECOMPRESSION_ERROR=113, FREAD_ERROR=114 }


PostExperimentTCPReceiver

decompiled_code:
__int64 __fastcall PostExperimentTCPReceiver(void *buf)
{
int v2; // eax
int v3; // ebp
__int64 v4; // rdi
__int16 v5; // ax
int v6; // edx
const void *v7; // rcx
socklen_t v8; // er8
int v9; // er13
ssize_t v10; // rax
__int64 result; // rax
int v12; // [rsp+Ch] [rbp-4Ch] BYREF
socklen_t addr_len[2]; // [rsp+10h] [rbp-48h] BYREF
size_t bufa; // [rsp+18h] [rbp-40h] BYREF
struct sockaddr addr; // [rsp+20h] [rbp-38h] BYREF
struct sockaddr v16; // [rsp+30h] [rbp-28h] BYREF

v2 = socket(2, 1, 6);
if ( v2 < 0 )
{
fprintf(stderr, "ERROR #%d: Socket Setup Error", 102LL);
result = 102LL;
}
else
{
v3 = v2;
*(_QWORD *)&addr.sa_data[6] = 0LL;
addr.sa_family = 2;
v4 = (unsigned int)v2;
*(_QWORD *)&addr.sa_data[2] = (unsigned int)_bswap_32_constprop_0((unsigned int)v2, 1LL, 2LL, &v12, 4LL);
v5 = _bswap_16_constprop_0(v4, 1LL);
v12 = 1;
*(_WORD *)addr.sa_data = v5;
if ( setsockopt(v4, 1, v6, v7, v8) == -1 )
printf("Can't set the reuse option on the socket");
if ( bind(v3, &addr, 0x10u) < 0 )
{
fprintf(stderr, "ERROR #%d: Binding Error", 106LL);
result = 106LL;
}
else if ( listen(v3, 5) < 0 )
{
fprintf(stderr, "ERROR #%d: Port Listening Error", 107LL);
result = 107LL;
}
else
{
*(_QWORD *)addr_len = 16LL;
v9 = accept(v3, &v16, addr_len);
if ( v9 < 0 )
{
fprintf(stderr, "ERROR #%d: Accept Client Error", 108LL);
result = 108LL;
}
else
{
bufa = strlen((const char *)buf);
printf("%lu %s \n", bufa, (const char *)buf);
if ( send(v9, &bufa, 8uLL, 0) == 8 && (v10 = send(v9, buf, bufa, 0), v10 == bufa) )
{
close(v3);
result = 0LL;
}
else
{
fprintf(stderr, "ERROR #%d: Send Data Error", 104LL);
result = 104LL;
}
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(void *buf)
{
int v2; // eax
int v3; // ebp
__int64 v4; // rdi
__int16 v5; // ax
int v6; // edx
const void *v7; // rcx
socklen_t v8; // er8
int v9; // er13
ssize_t v10; // rax
__int64 result; // rax
int v12; // [rsp+Ch] [rbp-4Ch] BYREF
socklen_t addr_len[2]; // [rsp+10h] [rbp-48h] BYREF
size_t bufa; // [rsp+18h] [rbp-40h] BYREF
struct sockaddr addr; // [rsp+20h] [rbp-38h] BYREF
struct sockaddr v16; // [rsp+30h] [rbp-28h] BYREF

v2 = socket(2, 1, 6);
if ( v2 < 0 )
{
fprintf(stderr, "ERROR #%d: Socket Setup Error", 102LL);
result = 102LL;
}
else
{
v3 = v2;
*(_QWORD *)&addr.sa_data[6] = 0LL;
addr.sa_family = 2;
v4 = (unsigned int)v2;
*(_QWORD *)&addr.sa_data[2] = (unsigned int)func0((unsigned int)v2, 1LL, 2LL, &v12, 4LL);
v5 = func1(v4, 1LL);
v12 = 1;
*(_WORD *)addr.sa_data = v5;
if ( setsockopt(v4, 1, v6, v7, v8) == -1 )
printf("Can't set the reuse option on the socket");
if ( bind(v3, &addr, 0x10u) < 0 )
{
fprintf(stderr, "ERROR #%d: Binding Error", 106LL);
result = 106LL;
}
else if ( listen(v3, 5) < 0 )
{
fprintf(stderr, "ERROR #%d: Port Listening Error", 107LL);
result = 107LL;
}
else
{
*(_QWORD *)addr_len = 16LL;
v9 = accept(v3, &v16, addr_len);
if ( v9 < 0 )
{
fprintf(stderr, "ERROR #%d: Accept Client Error", 108LL);
result = 108LL;
}
else
{
bufa = strlen((const char *)buf);
printf("%lu %s \n", bufa, (const char *)buf);
if ( send(v9, &bufa, 8uLL, 0) == 8 && (v10 = send(v9, buf, bufa, 0), v10 == bufa) )
{
close(v3);
result = 0LL;
}
else
{
fprintf(stderr, "ERROR #%d: Send Data Error", 104LL);
result = 104LL;
}
}
}
}
return result;
}

original_code:
enum error_t PostExperimentTCPReceiver(char* send_buffer, unsigned long send_buffer_length)
{
  const size_t LONG_SIZE=sizeof(unsigned long);
  int servSock;
  int clntSock;
  struct sockaddr_in servAddr;
  struct sockaddr_in clntAddr;
  char* sendBuffer = send_buffer;
  size_t clntLen;
  if ((servSock = socket(2, SOCK_STREAM, IPPROTO_TCP)) < 0)
  {
    fprintf(stderr, "ERROR #%d: Socket Setup Error", SOCKET_SETUP_ERROR);
    return SOCKET_SETUP_ERROR;
  }
  memset(&servAddr, 0, sizeof(servAddr));
  servAddr.sin_family = 2;
  servAddr.sin_addr.s_addr = htonl(((in_addr_t) 0x00000000));
  servAddr.sin_port = htons(26400);
 int reuse = 1;
        if (setsockopt(servSock, 1, 2, (char *)&reuse, sizeof(int)) == -1)
                printf("Can't set the reuse option on the socket");
  if (bind(servSock,(struct sockaddr *)&servAddr,sizeof(servAddr)) < 0)
  {
    fprintf(stderr, "ERROR #%d: Binding Error", BIND_ERROR);
    return BIND_ERROR;
  }
  if (listen(servSock, 5) < 0)
  {
    fprintf(stderr, "ERROR #%d: Port Listening Error", LISTEN_ERROR);
    return LISTEN_ERROR;
  }
  clntLen = sizeof(clntAddr);
  if ((clntSock = accept(servSock,(struct sockaddr*)&clntAddr,&clntLen)) < 0)
  {
    fprintf(stderr, "ERROR #%d: Accept Client Error", ACCEPT_CLIENT_ERROR);
    return ACCEPT_CLIENT_ERROR;
  }
  unsigned long size_of_buffer = strlen(sendBuffer);
  printf("%lu %s \n", size_of_buffer, sendBuffer);
  if (send(clntSock, &size_of_buffer, LONG_SIZE, 0) != LONG_SIZE)
  {
    fprintf(stderr, "ERROR #%d: Send Data Error", SEND_ERROR);
    return SEND_ERROR;
  }
  if (send(clntSock, sendBuffer, size_of_buffer, 0) != size_of_buffer)
  {
    fprintf(stderr, "ERROR #%d: Send Data Error", SEND_ERROR);
    return SEND_ERROR;
  }
  close(servSock);
  return 0;
}

canonical_original_code:
enum error_t PostExperimentTCPReceiver(char *send_buffer, unsigned long send_buffer_length)
{
  unsigned long LONG_SIZE = sizeof(unsigned long);
  int servSock;
  int clntSock;
  struct sockaddr_in servAddr;
  struct sockaddr_in clntAddr;
  char *sendBuffer = send_buffer;
  unsigned long clntLen;
  if ((servSock = socket(2, SOCK_STREAM, IPPROTO_TCP)) < 0)
  {
    fprintf(stderr, "ERROR #%d: Socket Setup Error", SOCKET_SETUP_ERROR);
    return SOCKET_SETUP_ERROR;
  }
  memset(&servAddr, 0, sizeof(servAddr));
  servAddr.sin_family = 2;
  servAddr.sin_addr.s_addr = htonl(((unsigned int) 0x00000000));
  servAddr.sin_port = htons(26400);
 int reuse = 1;
        if (setsockopt(servSock, 1, 2, (char *)&reuse, sizeof(int)) == -1)
                printf("Can't set the reuse option on the socket");
  if (bind(servSock,(struct sockaddr *)&servAddr,sizeof(servAddr)) < 0)
  {
    fprintf(stderr, "ERROR #%d: Binding Error", BIND_ERROR);
    return BIND_ERROR;
  }
  if (listen(servSock, 5) < 0)
  {
    fprintf(stderr, "ERROR #%d: Port Listening Error", LISTEN_ERROR);
    return LISTEN_ERROR;
  }
  clntLen = sizeof(clntAddr);
  if ((clntSock = accept(servSock,(struct sockaddr *)&clntAddr,&clntLen)) < 0)
  {
    fprintf(stderr, "ERROR #%d: Accept Client Error", ACCEPT_CLIENT_ERROR);
    return ACCEPT_CLIENT_ERROR;
  }
  unsigned long size_of_buffer = strlen(sendBuffer);
  printf("%lu %s \n", size_of_buffer, sendBuffer);
  if (send(clntSock, &size_of_buffer, LONG_SIZE, 0) != LONG_SIZE)
  {
    fprintf(stderr, "ERROR #%d: Send Data Error", SEND_ERROR);
    return SEND_ERROR;
  }
  if (send(clntSock, sendBuffer, size_of_buffer, 0) != size_of_buffer)
  {
    fprintf(stderr, "ERROR #%d: Send Data Error", SEND_ERROR);
    return SEND_ERROR;
  }
  close(servSock);
  return 0;
}

variable_types: servSock int

variable_types: clntSock int

variable_types:
sendBuffer
char *

variable_types:
clntLen
unsigned long


PreExperimentTCPReceiver

decompiled_code:
__int64 __fastcall PreExperimentTCPReceiver(_DWORD *a1, _QWORD *a2, _DWORD *a3)
{
int v5; // eax
int v6; // ebp
__int64 v7; // rdi
__int16 v8; // ax
int v9; // edx
const void *v10; // rcx
socklen_t v11; // er8
int v12; // edi
__int64 result; // rax
int v14; // [rsp+4h] [rbp-D4h] BYREF
socklen_t addr_len[2]; // [rsp+8h] [rbp-D0h] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-C8h] BYREF
struct sockaddr v17; // [rsp+20h] [rbp-B8h] BYREF
int buf; // [rsp+30h] [rbp-A8h] BYREF
__int64 v19; // [rsp+34h] [rbp-A4h]
int v20; // [rsp+3Ch] [rbp-9Ch]

*(_QWORD *)addr_len = 16LL;
v5 = socket(2, 1, 6);
if ( v5 < 0 )
{
fprintf(stderr, "ERROR #%d: Socket Setup Error", 102LL);
result = 102LL;
}
else
{
v6 = v5;
*(_QWORD *)&addr.sa_data[6] = 0LL;
addr.sa_family = 2;
v7 = (unsigned int)v5;
*(_QWORD *)&addr.sa_data[2] = (unsigned int)_bswap_32_constprop_0((unsigned int)v5, 1LL, 2LL, &v14, 4LL);
v8 = _bswap_16_constprop_0(v7, 1LL);
v14 = 1;
*(_WORD *)addr.sa_data = v8;
if ( setsockopt(v7, 1, v9, v10, v11) == -1 )
printf("Can't set the reuse option on the socket");
if ( bind(v6, &addr, 0x10u) < 0 )
{
fprintf(stderr, "ERROR #%d: Binding Error", 106LL);
result = 106LL;
}
else if ( listen(v6, 500) < 0 )
{
fprintf(stderr, "ERROR #%d: Port Listening Error", 107LL);
result = 107LL;
}
else
{
v12 = accept(v6, &v17, addr_len);
if ( v12 < 0 )
{
fprintf(stderr, "ERROR #%d: Accept Client Error", 108LL);
result = 108LL;
}
else if ( recv(v12, &buf, 0x74uLL, 0) <= 0 )
{
fprintf(stderr, "ERROR #%d: Receive Data Error", 105LL);
result = 105LL;
}
else
{
*a1 = buf;
*a2 = v19;
*a3 = v20;
close(v6);
result = 0LL;
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(_DWORD *a1, _QWORD *a2, _DWORD *a3)
{
int v5; // eax
int v6; // ebp
__int64 v7; // rdi
__int16 v8; // ax
int v9; // edx
const void *v10; // rcx
socklen_t v11; // er8
int v12; // edi
__int64 result; // rax
int v14; // [rsp+4h] [rbp-D4h] BYREF
socklen_t addr_len[2]; // [rsp+8h] [rbp-D0h] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-C8h] BYREF
struct sockaddr v17; // [rsp+20h] [rbp-B8h] BYREF
int buf; // [rsp+30h] [rbp-A8h] BYREF
__int64 v19; // [rsp+34h] [rbp-A4h]
int v20; // [rsp+3Ch] [rbp-9Ch]

*(_QWORD *)addr_len = 16LL;
v5 = socket(2, 1, 6);
if ( v5 < 0 )
{
fprintf(stderr, "ERROR #%d: Socket Setup Error", 102LL);
result = 102LL;
}
else
{
v6 = v5;
*(_QWORD *)&addr.sa_data[6] = 0LL;
addr.sa_family = 2;
v7 = (unsigned int)v5;
*(_QWORD *)&addr.sa_data[2] = (unsigned int)func0((unsigned int)v5, 1LL, 2LL, &v14, 4LL);
v8 = func1(v7, 1LL);
v14 = 1;
*(_WORD *)addr.sa_data = v8;
if ( setsockopt(v7, 1, v9, v10, v11) == -1 )
printf("Can't set the reuse option on the socket");
if ( bind(v6, &addr, 0x10u) < 0 )
{
fprintf(stderr, "ERROR #%d: Binding Error", 106LL);
result = 106LL;
}
else if ( listen(v6, 500) < 0 )
{
fprintf(stderr, "ERROR #%d: Port Listening Error", 107LL);
result = 107LL;
}
else
{
v12 = accept(v6, &v17, addr_len);
if ( v12 < 0 )
{
fprintf(stderr, "ERROR #%d: Accept Client Error", 108LL);
result = 108LL;
}
else if ( recv(v12, &buf, 0x74uLL, 0) <= 0 )
{
fprintf(stderr, "ERROR #%d: Receive Data Error", 105LL);
result = 105LL;
}
else
{
*a1 = buf;
*a2 = v19;
*a3 = v20;
close(v6);
result = 0LL;
}
}
}
return result;
}

original_code:
enum error_t PreExperimentTCPReceiver(int* num_of_packets,
                      unsigned long* inter_packet_departure_spacing,
                      int* probe_packet_length){
  const size_t INTEGER_SIZE=sizeof(int);
  const size_t LONG_SIZE=sizeof(unsigned long);
  const unsigned int BUFFER_REC_LENGTH=INTEGER_SIZE*2+LONG_SIZE+100;
  int servSock;
  int clntSock;
  struct sockaddr_in servAddr;
  struct sockaddr_in clntAddr;
  char recBuffer[BUFFER_REC_LENGTH];
  size_t clntLen = sizeof(clntAddr);
  if ((servSock = socket(2, SOCK_STREAM, IPPROTO_TCP)) < 0)
  {
    fprintf(stderr, "ERROR #%d: Socket Setup Error", SOCKET_SETUP_ERROR);
    return SOCKET_SETUP_ERROR;
  }
  memset(&servAddr, 0, sizeof(servAddr));
  servAddr.sin_family = 2;
  servAddr.sin_addr.s_addr = htonl(((in_addr_t) 0x00000000));
  servAddr.sin_port = htons(16400);
 int reuse = 1;
        if (setsockopt(servSock, 1, 2, (char *)&reuse, sizeof(int)) == -1)
                printf("Can't set the reuse option on the socket");
  if (bind(servSock,(struct sockaddr *)&servAddr,sizeof(servAddr)) < 0)
  {
    fprintf(stderr, "ERROR #%d: Binding Error", BIND_ERROR);
    return BIND_ERROR;
  }
  if (listen(servSock, 500) < 0)
  {
    fprintf(stderr, "ERROR #%d: Port Listening Error", LISTEN_ERROR);
    return LISTEN_ERROR;
  }
  if ((clntSock = accept(servSock,(struct sockaddr*)&clntAddr,&clntLen)) < 0)
  {
    fprintf(stderr, "ERROR #%d: Accept Client Error", ACCEPT_CLIENT_ERROR);
    return ACCEPT_CLIENT_ERROR;
  }
  if (recv(clntSock, recBuffer, BUFFER_REC_LENGTH , 0) <= 0)
  {
    fprintf(stderr, "ERROR #%d: Receive Data Error", RECEIVE_ERROR);
    return RECEIVE_ERROR;
  }
  memcpy(num_of_packets, (recBuffer), INTEGER_SIZE);
  memcpy(inter_packet_departure_spacing, (recBuffer+INTEGER_SIZE), LONG_SIZE);
  memcpy(probe_packet_length, (recBuffer+INTEGER_SIZE+LONG_SIZE), INTEGER_SIZE);
  close(servSock);
  return 0;
}

canonical_original_code:
enum error_t PreExperimentTCPReceiver(int *num_of_packets, unsigned long *inter_packet_departure_spacing, int *probe_packet_length){
  unsigned long INTEGER_SIZE = sizeof(int);
  unsigned long LONG_SIZE = sizeof(unsigned long);
  unsigned int BUFFER_REC_LENGTH = INTEGER_SIZE*2+LONG_SIZE+100;
  int servSock;
  int clntSock;
  struct sockaddr_in servAddr;
  struct sockaddr_in clntAddr;
  char recBuffer[-1];
  unsigned long clntLen = sizeof(clntAddr);
  if ((servSock = socket(2, SOCK_STREAM, IPPROTO_TCP)) < 0)
  {
    fprintf(stderr, "ERROR #%d: Socket Setup Error", SOCKET_SETUP_ERROR);
    return SOCKET_SETUP_ERROR;
  }
  memset(&servAddr, 0, sizeof(servAddr));
  servAddr.sin_family = 2;
  servAddr.sin_addr.s_addr = htonl(((unsigned int) 0x00000000));
  servAddr.sin_port = htons(16400);
 int reuse = 1;
        if (setsockopt(servSock, 1, 2, (char *)&reuse, sizeof(int)) == -1)
                printf("Can't set the reuse option on the socket");
  if (bind(servSock,(struct sockaddr *)&servAddr,sizeof(servAddr)) < 0)
  {
    fprintf(stderr, "ERROR #%d: Binding Error", BIND_ERROR);
    return BIND_ERROR;
  }
  if (listen(servSock, 500) < 0)
  {
    fprintf(stderr, "ERROR #%d: Port Listening Error", LISTEN_ERROR);
    return LISTEN_ERROR;
  }
  if ((clntSock = accept(servSock,(struct sockaddr *)&clntAddr,&clntLen)) < 0)
  {
    fprintf(stderr, "ERROR #%d: Accept Client Error", ACCEPT_CLIENT_ERROR);
    return ACCEPT_CLIENT_ERROR;
  }
  if (recv(clntSock, recBuffer, BUFFER_REC_LENGTH , 0) <= 0)
  {
    fprintf(stderr, "ERROR #%d: Receive Data Error", RECEIVE_ERROR);
    return RECEIVE_ERROR;
  }
  memcpy(num_of_packets, (recBuffer), INTEGER_SIZE);
  memcpy(inter_packet_departure_spacing, (recBuffer+INTEGER_SIZE), LONG_SIZE);
  memcpy(probe_packet_length, (recBuffer+INTEGER_SIZE+LONG_SIZE), INTEGER_SIZE);
  close(servSock);
  return 0;
}

variable_types:
recBuffer
char [-1]


repo: vhelin/wla-dx

decompiled_code:
__int64 collect_labels_brutal()
{
int v0; // er13
int v2[7]; // [rsp+Ch] [rbp-1Ch] BYREF

if ( arg_value <= 0 )
return 1LL;
v0 = 0;
while ( (unsigned int)get_mnemonic_type(*(unsigned __int8 *)(in + v0), v2) )
{
if ( v2[0] == 2 )
{
v0 += 3;
goto LABEL_6;
}
if ( v2[0] <= 2 )
{
if ( v2[0] )
{
if ( v2[0] == 1 )
v0 += 2;
goto LABEL_6;
}
LABEL_11:
if ( arg_value <= ++v0 )
return 1LL;
}
else
{
if ( v2[0] == 7 )
goto LABEL_11;
LABEL_6:
if ( arg_value <= v0 )
return 1LL;
}
}
fprintf(
stderr,
"COLLECT_LABELS_BRUTAL: Unknown opcode $%x at $%x.\n",
*(unsigned __int8 *)(in + v0),
(unsigned int)v0);
return 0LL;
}

canonical_decompiled_code:
__int64 func0()
{
int v0; // er13
int v2[7]; // [rsp+Ch] [rbp-1Ch] BYREF

if ( arg_value <= 0 )
return 1LL;
v0 = 0;
while ( (unsigned int)get_mnemonic_type(*(unsigned __int8 *)(in + v0), v2) )
{
if ( v2[0] == 2 )
{
v0 += 3;
goto LABEL_6;
}
if ( v2[0] <= 2 )
{
if ( v2[0] )
{
if ( v2[0] == 1 )
v0 += 2;
goto LABEL_6;
}
LABEL_11:
if ( arg_value <= ++v0 )
return 1LL;
}
else
{
if ( v2[0] == 7 )
goto LABEL_11;
LABEL_6:
if ( arg_value <= v0 )
return 1LL;
}
}
fprintf(
stderr,
"COLLECT_LABELS_BRUTAL: Unknown opcode $%x at $%x.\n",
*(unsigned __int8 *)(in + v0),
(unsigned int)v0);
return 0LL;
}

original_code:
int collect_labels_brutal(void) {
  int i, b, a, s, t;
  b = 0;
  a = 0;
  s = 0;
  i = 0;
  while (a < arg_value) {
    if (i >= 0x4000) {
      i -= 0x4000;
      s = 1;
      b++;
    }
    if (get_mnemonic_type(*(in + a), &t) == 0) {
      fprintf(stderr, "COLLECT_LABELS_BRUTAL: Unknown opcode $%x at $%x.\n", *(in + a), a);
      return 0;
    }
    switch (t) {
    case 0:
    case 7:
      a++;
      i++;
      break;
    case 1:
      a += 2;
      i += 2;
      break;
    case 2:
      a += 3;
      i += 3;
      break;
    }
  }
  return 1;
}

canonical_original_code:
int collect_labels_brutal() {
  int i; int b; int a; int s; int t;
  b = 0;
  a = 0;
  s = 0;
  i = 0;
  while (a < arg_value) {
    if (i >= 0x4000) {
      i -= 0x4000;
      s = 1;
      b++;
    }
    if (get_mnemonic_type(*(in + a), &t) == 0) {
      fprintf(stderr, "COLLECT_LABELS_BRUTAL: Unknown opcode $%x at $%x.\n", *(in + a), a);
      return 0;
    }
    switch (t) {
    case 0:
    case 7:
      a++;
      i++;
      break;
    case 1:
      a += 2;
      i += 2;
      break;
    case 2:
      a += 3;
      i += 3;
      break;
    }
  }
  return 1;
}

variable_types: i int

variable_types: b int

variable_types: a int

variable_types: s int

variable_types: t int


decompiled_code:
__int64 dasm_brutal()
{
if ( arg_labels == 1 )
collect_labels_brutal();
if ( arg_value > 0 )
{
printf(".BANK %d SLOT %d\n\n", 0LL, 0LL);
while ( arg_value > 0 )
;
}
return 1LL;
}

canonical_decompiled_code:
__int64 func1()
{
if ( arg_labels == 1 )
func0();
if ( arg_value > 0 )
{
printf(".BANK %d SLOT %d\n\n", 0LL, 0LL);
while ( arg_value > 0 )
;
}
return 1LL;
}

original_code:
int dasm_brutal(void) {
  int i, b, a, s;
  if (arg_labels == 1)
    collect_labels_brutal();
  b = 0;
  a = 0;
  s = 0;
  while (a < arg_value) {
    printf(".BANK %d SLOT %d\n\n", b, s);
    s = 1;
    b++;
    i = 0;
    while (a < arg_value && i < 0x4000) {
    }
  }
  return 1;
}

canonical_original_code:
int dasm_brutal() {
  int i; int b; int a; int s;
  if (arg_labels == 1)
    collect_labels_brutal();
  b = 0;
  a = 0;
  s = 0;
  while (a < arg_value) {
    printf(".BANK %d SLOT %d\n\n", b, s);
    s = 1;
    b++;
    i = 0;
    while (a < arg_value && i < 0x4000) {
    }
  }
  return 1;
}


decompiled_code:
__int64 dasm_analyzer()
{
return 1LL;
}

canonical_decompiled_code:
__int64 func0()
{
return 1LL;
}

original_code:
int dasm_analyzer(void) {
  return 1;
}

canonical_original_code:
int dasm_analyzer() {
  return 1;
}


decompiled_code:
__int64 __fastcall add_a_new_label(int a1, const char *a2)
{
char *v2; // rax
char *v3; // rax
bool v4; // zf
__int64 v5; // rdx
__int64 v6; // rax
__int64 result; // rax

v2 = (char *)malloc(0x30uLL);
if ( v2 )
{
v3 = strcpy(v2, a2);
v4 = labels_first == 0;
*((_DWORD *)v3 + 8) = a1;
v5 = (__int64)v3;
*((_QWORD *)v3 + 5) = 0LL;
if ( v4 )
{
labels_first = (__int64)v3;
labels_last = (__int64)v3;
}
else
{
v6 = labels_last;
labels_last = v5;
*(_QWORD *)(v6 + 40) = v5;
}
result = 1LL;
}
else
{
fwrite("ADD_A_NEW_LABEL: Out of memory error.\n", 1uLL, 0x26uLL, stderr);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1, const char *a2)
{
char *v2; // rax
char *v3; // rax
bool v4; // zf
__int64 v5; // rdx
__int64 v6; // rax
__int64 result; // rax

v2 = (char *)malloc(0x30uLL);
if ( v2 )
{
v3 = strcpy(v2, a2);
v4 = labels_first == 0;
*((_DWORD *)v3 + 8) = a1;
v5 = (__int64)v3;
*((_QWORD *)v3 + 5) = 0LL;
if ( v4 )
{
labels_first = (__int64)v3;
labels_last = (__int64)v3;
}
else
{
v6 = labels_last;
labels_last = v5;
*(_QWORD *)(v6 + 40) = v5;
}
result = 1LL;
}
else
{
fwrite("ADD_A_NEW_LABEL: Out of memory error.\n", 1uLL, 0x26uLL, stderr);
result = 0LL;
}
return result;
}

original_code:
int add_a_new_label(int address, char *label) {
  struct label *l;
  l = malloc(sizeof(struct label));
  if (l == ((void *)0)) {
    fprintf(stderr, "ADD_A_NEW_LABEL: Out of memory error.\n");
    return 0;
  }
  strcpy(l->label, label);
  l->address = address;
  l->next = ((void *)0);
  if (labels_first == ((void *)0)) {
    labels_first = l;
    labels_last = l;
  }
  else {
    labels_last->next = l;
    labels_last = l;
  }
  return 1;
}

variable_types: address int

variable_types:
label
char *

variable_types: struct label { char label[32]; int address; struct label *next; } *


decompiled_code:
__int64 get_mnemonic_type()
{
return 1LL;
}

canonical_decompiled_code:
__int64 func1()
{
return 1LL;
}

original_code:
int get_mnemonic_type(int m, int *o) {
  return 1;
}

variable_types: m int

variable_types:
o
int *


decompiled_code:
__int64 __fastcall parse_flags(const char *a1)
{
int v2; // eax
const char *v3; // rdx

if ( *a1 != 45 )
return 0LL;
v2 = strlen(a1);
if ( v2 == 1 )
return 0LL;
v3 = a1 + 1;
if ( v2 > 1 )
{
do
{
switch ( *v3 )
{
case 'a':
arg_address = 0;
break;
case 'b':
if ( arg_mode )
return 0LL;
arg_mode = 1;
break;
case 'c':
if ( arg_mode )
return 0LL;
arg_mode = 2;
break;
case 'd':
arg_only_code = 1;
break;
case 'l':
arg_labels = 1;
break;
case 's':
arg_strings = 1;
break;
default:
return 0LL;
}
++v3;
}
while ( v3 != &a1[v2 - 2 + 2] );
}
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(const char *a1)
{
int v2; // eax
const char *v3; // rdx

if ( *a1 != 45 )
return 0LL;
v2 = strlen(a1);
if ( v2 == 1 )
return 0LL;
v3 = a1 + 1;
if ( v2 > 1 )
{
do
{
switch ( *v3 )
{
case 'a':
arg_address = 0;
break;
case 'b':
if ( arg_mode )
return 0LL;
arg_mode = 1;
break;
case 'c':
if ( arg_mode )
return 0LL;
arg_mode = 2;
break;
case 'd':
arg_only_code = 1;
break;
case 'l':
arg_labels = 1;
break;
case 's':
arg_strings = 1;
break;
default:
return 0LL;
}
++v3;
}
while ( v3 != &a1[v2 - 2 + 2] );
}
return 1LL;
}

original_code:
int parse_flags(char *f) {
  int l;
  if (*f != '-') {
    return 0;
  }
  l = strlen(f);
  if (l == 1)
    return 0;
  for (f++, l--; l > 0; l--, f++) {
    switch (*f) {
    case 'd':
      arg_only_code = 1;
      continue;
    case 's':
      arg_strings = 1;
      continue;
    case 'a':
      arg_address = 0;
      continue;
    case 'l':
      arg_labels = 1;
      continue;
    case 'b':
      if (arg_mode != 0)
 return 0;
      arg_mode = 1;
      continue;
    case 'c':
      if (arg_mode != 0)
 return 0;
      arg_mode = 2;
      continue;
    default:
      return 0;
    }
  }
  return 1;
}

variable_types:
f
char *

variable_types: l int


decompiled_code:
__int64 __fastcall output_header(const char *a1, unsigned int a2)
{
fwrite("; this file was created with wlad ", 1uLL, 0x22uLL, stdout);
fwrite("; disassembler by ville helin <vhelin@cc.hut.fi>.\n", 1uLL, 0x32uLL, stdout);
fprintf(stdout, "; disassembly of \"%s\".\n\n", a1);
fwrite(".MEMORYMAP\n", 1uLL, 0xBuLL, stdout);
fwrite("SLOTSIZE $4000\n", 1uLL, 0xFuLL, stdout);
fwrite("DEFAULTSLOT 1\n", 1uLL, 0xEuLL, stdout);
fwrite("SLOT 0 $0000\n", 1uLL, 0xDuLL, stdout);
fwrite("SLOT 1 $4000\n", 1uLL, 0xDuLL, stdout);
fwrite(".ENDME\n\n", 1uLL, 8uLL, stdout);
fwrite(".BANKSIZE $4000\n", 1uLL, 0x10uLL, stdout);
fprintf(stdout, ".ROMBANKS %d\n", a2);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(const char *a1, unsigned int a2)
{
fwrite("; this file was created with wlad ", 1uLL, 0x22uLL, stdout);
fwrite("; disassembler by ville helin <vhelin@cc.hut.fi>.\n", 1uLL, 0x32uLL, stdout);
fprintf(stdout, "; disassembly of \"%s\".\n\n", a1);
fwrite(".MEMORYMAP\n", 1uLL, 0xBuLL, stdout);
fwrite("SLOTSIZE $4000\n", 1uLL, 0xFuLL, stdout);
fwrite("DEFAULTSLOT 1\n", 1uLL, 0xEuLL, stdout);
fwrite("SLOT 0 $0000\n", 1uLL, 0xDuLL, stdout);
fwrite("SLOT 1 $4000\n", 1uLL, 0xDuLL, stdout);
fwrite(".ENDME\n\n", 1uLL, 8uLL, stdout);
fwrite(".BANKSIZE $4000\n", 1uLL, 0x10uLL, stdout);
fprintf(stdout, ".ROMBANKS %d\n", a2);
return 1LL;
}

original_code:
int output_header(char *name, int r) {
  fprintf(stdout, "; this file was created with wlad ");
  fprintf(stdout, "; disassembler by ville helin <vhelin@cc.hut.fi>.\n");
  fprintf(stdout, "; disassembly of \"%s\".\n\n", name);
  fprintf(stdout, ".MEMORYMAP\n");
  fprintf(stdout, "SLOTSIZE $4000\n");
  fprintf(stdout, "DEFAULTSLOT 1\n");
  fprintf(stdout, "SLOT 0 $0000\n");
  fprintf(stdout, "SLOT 1 $4000\n");
  fprintf(stdout, ".ENDME\n\n");
  fprintf(stdout, ".BANKSIZE $4000\n");
  fprintf(stdout, ".ROMBANKS %d\n", r);
  return 1;
}

variable_types:
name
char *

variable_types: r int


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int result; // eax
int v4; // eax
int v5; // er8
const char *v6; // r12
FILE *v7; // rax
FILE *v8; // rbp
size_t v9; // r13
int v10; // ecx
int v11; // esi
int v12; // eax

if ( argc != 4 || (parse_flags(argv[1]), !arg_mode) )
{
get_value((char *)argv[2], &arg_value);
LABEL_3:
fwrite("Copyright 2000-2001 Ville Helin\n", 1uLL, 0x20uLL, stderr);
fprintf(stderr, "USAGE: %s -[adls]{bc} <CODE SIZE KB / START ADDRESS> <BIN FILE>\n", *argv);
fwrite("Commands: Options:\n", 1uLL, 0x21uLL, stderr);
fwrite("b Brutal disassembly a Disable address printing\n", 1uLL, 0x34uLL, stderr);
fwrite("c Code analyzer d Don't disassemble the remaining data\n", 1uLL, 0x40uLL, stderr);
fwrite(" l Create labels\n", 1uLL, 0x29uLL, stderr);
fwrite(" s Detect strings\n\n", 1uLL, 0x2BuLL, stderr);
return 1;
}
v4 = get_value((char *)argv[2], &arg_value);
if ( !v5 || !v4 )
goto LABEL_3;
v6 = argv[3];
v7 = fopen(v6, "rb");
v8 = v7;
if ( v7 )
{
fseek(v7, 0LL, 2);
dword_330 = ftell(v8);
fseek(v8, 0LL, 0);
v9 = dword_330;
in = malloc(dword_330);
if ( in )
{
fread(in, 1uLL, v9, v8);
fclose(v8);
if ( arg_mode == 1 )
{
v10 = dword_330;
v12 = arg_value << 10;
if ( arg_value << 10 > dword_330 )
v12 = dword_330;
arg_value = v12;
}
else
{
v10 = dword_330;
}
v11 = v10 / 0x4000;
if ( v10 != (v10 / 0x4000) << 14 )
++v11;
output_header(v6, v11);
if ( arg_mode == 1 )
dasm_brutal();
else
dasm_analyzer();
free(in);
result = 0;
}
else
{
fprintf(stderr, "Out of memory. Could not allocate %d bytes.\n", (unsigned int)v9);
fclose(v8);
result = 1;
}
}
else
{
fprintf(stderr, "Could not open file \"%s\".\n", v6);
result = 1;
}
return result;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int result; // eax
int v4; // eax
int v5; // er8
const char *v6; // r12
FILE *v7; // rax
FILE *v8; // rbp
size_t v9; // r13
int v10; // ecx
int v11; // esi
int v12; // eax

if ( argc != 4 || (func1(argv[1]), !arg_mode) )
{
func3((char *)argv[2], &arg_value);
LABEL_3:
fwrite("Copyright 2000-2001 Ville Helin\n", 1uLL, 0x20uLL, stderr);
fprintf(stderr, "USAGE: %s -[adls]{bc} <CODE SIZE KB / START ADDRESS> <BIN FILE>\n", *argv);
fwrite("Commands: Options:\n", 1uLL, 0x21uLL, stderr);
fwrite("b Brutal disassembly a Disable address printing\n", 1uLL, 0x34uLL, stderr);
fwrite("c Code analyzer d Don't disassemble the remaining data\n", 1uLL, 0x40uLL, stderr);
fwrite(" l Create labels\n", 1uLL, 0x29uLL, stderr);
fwrite(" s Detect strings\n\n", 1uLL, 0x2BuLL, stderr);
return 1;
}
v4 = func3((char *)argv[2], &arg_value);
if ( !v5 || !v4 )
goto LABEL_3;
v6 = argv[3];
v7 = fopen(v6, "rb");
v8 = v7;
if ( v7 )
{
fseek(v7, 0LL, 2);
dword_330 = ftell(v8);
fseek(v8, 0LL, 0);
v9 = dword_330;
in = malloc(dword_330);
if ( in )
{
fread(in, 1uLL, v9, v8);
fclose(v8);
if ( arg_mode == 1 )
{
v10 = dword_330;
v12 = arg_value << 10;
if ( arg_value << 10 > dword_330 )
v12 = dword_330;
arg_value = v12;
}
else
{
v10 = dword_330;
}
v11 = v10 / 0x4000;
if ( v10 != (v10 / 0x4000) << 14 )
++v11;
func2(v6, v11);
if ( arg_mode == 1 )
dasm_brutal();
else
dasm_analyzer();
free(in);
result = 0;
}
else
{
fprintf(stderr, "Out of memory. Could not allocate %d bytes.\n", (unsigned int)v9);
fclose(v8);
result = 1;
}
}
else
{
fprintf(stderr, "Could not open file \"%s\".\n", v6);
result = 1;
}
return result;
}

original_code:
int main(int argc, char *argv[]) {
  int i, l, n;
  i = 0;
  while (1) {
    if (strcmp(g_instructions_table[i].string, "E") == 0)
      break;
    l = strlen(g_instructions_table[i].string);
    for (n = 0; n < l; n++) {
      if (g_instructions_table[i].string[n] == '.')
        break;
    }
    if (n < l && (g_instructions_table[i].string[n+1] == 'B' || g_instructions_table[i].string[n+1] == 'W' || g_instructions_table[i].string[n+1] == 'L')) {
      i++;
      continue;
    }
    printf("\"%s\" ", g_instructions_table[i].string);
    if (g_instructions_table[i].hex & 0xFF00)
      printf("$%.2X%.2X\n", g_instructions_table[i].hex & 0xFF, (g_instructions_table[i].hex >> 8) & 0xFF);
    else
      printf("$%.2X\n", g_instructions_table[i].hex);
    i++;
  }
  return 0;
}

canonical_original_code:
int main(int argc, char *argv[]) {
  int i; int l; int n;
  i = 0;
  while (1) {
    if (strcmp(g_instructions_table[i].string, "E") == 0)
      break;
    l = strlen(g_instructions_table[i].string);
    for (n = 0; n < l; n++) {
      if (g_instructions_table[i].string[n] == '.')
        break;
    }
    if (n < l && (g_instructions_table[i].string[n+1] == 'B' || g_instructions_table[i].string[n+1] == 'W' || g_instructions_table[i].string[n+1] == 'L')) {
      i++;
      continue;
    }
    printf("\"%s\" ", g_instructions_table[i].string);
    if (g_instructions_table[i].hex & 0xFF00)
      printf("$%.2X%.2X\n", g_instructions_table[i].hex & 0xFF, (g_instructions_table[i].hex >> 8) & 0xFF);
    else
      printf("$%.2X\n", g_instructions_table[i].hex);
    i++;
  }
  return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: n int


decompiled_code:
__int64 __fastcall get_token(const char **a1, __int64 a2)
{
const char *v3; // rdi
__int64 result; // rax
int v5; // [rsp+Ch] [rbp-Ch] BYREF

v3 = *a1;
v5 = 0;
sscanf(v3, "%255s%n", a2, &v5);
result = v5;
if ( v5 )
{
*a1 += v5;
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(const char **a1, __int64 a2)
{
const char *v3; // rdi
__int64 result; // rax
int v5; // [rsp+Ch] [rbp-Ch] BYREF

v3 = *a1;
v5 = 0;
sscanf(v3, "%255s%n", a2, &v5);
result = v5;
if ( v5 )
{
*a1 += v5;
result = 1LL;
}
return result;
}

original_code:
int get_token(char **input, char *result) {
  int n = 0;
  sscanf(*input, "%255s%n", result, &n);
  if (!n) {
    return 0;
  }
  *input += n;
  return 1;
}

variable_types:
input
char **

variable_types:
result
char *


decompiled_code:
__int64 __fastcall extract_comments(char *haystack, int a2)
{
char *v2; // rbp
char *v3; // r15
int v4; // er12
char *v5; // r15
char *v6; // rax
char *v7; // rsi
char *v8; // rdi
size_t v9; // rbx
char *v10; // r14
char *v11; // r13
char *v12; // rax
char *v13; // rbx

v2 = haystack;
if ( *haystack )
{
v3 = haystack;
v4 = (_DWORD)haystack + a2;
do
{
v10 = strstr(v3, "; @BT");
v11 = strstr(v3, "/* @BT");
v12 = strstr(v3, "// @BT");
v13 = v12;
if ( v10 )
{
v5 = v10 + 5;
v6 = strchr(v10 + 5, 10);
if ( v13 && v13 < v5 )
{
LABEL_12:
v5 = v13 + 6;
v6 = strchr(v13 + 6, 10);
if ( !v11 || v11 >= v5 )
goto LABEL_7;
goto LABEL_14;
}
if ( !v11 || v11 >= v5 )
goto LABEL_7;
}
else
{
if ( v12 )
goto LABEL_12;
if ( !v11 )
break;
}
LABEL_14:
v5 = v11 + 6;
v6 = strstr(v11 + 6, "*/");
LABEL_7:
v7 = v5;
v8 = v2;
if ( !v6 )
LODWORD(v6) = v4;
v9 = (int)v6 - (int)v5;
v3 = &v5[v9];
v2 += v9;
memmove(v8, v7, v9);
}
while ( *v3 );
}
*v2 = 0;
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(char *haystack, int a2)
{
char *v2; // rbp
char *v3; // r15
int v4; // er12
char *v5; // r15
char *v6; // rax
char *v7; // rsi
char *v8; // rdi
size_t v9; // rbx
char *v10; // r14
char *v11; // r13
char *v12; // rax
char *v13; // rbx

v2 = haystack;
if ( *haystack )
{
v3 = haystack;
v4 = (_DWORD)haystack + a2;
do
{
v10 = strstr(v3, "; @BT");
v11 = strstr(v3, "/* @BT");
v12 = strstr(v3, "// @BT");
v13 = v12;
if ( v10 )
{
v5 = v10 + 5;
v6 = strchr(v10 + 5, 10);
if ( v13 && v13 < v5 )
{
LABEL_12:
v5 = v13 + 6;
v6 = strchr(v13 + 6, 10);
if ( !v11 || v11 >= v5 )
goto LABEL_7;
goto LABEL_14;
}
if ( !v11 || v11 >= v5 )
goto LABEL_7;
}
else
{
if ( v12 )
goto LABEL_12;
if ( !v11 )
break;
}
LABEL_14:
v5 = v11 + 6;
v6 = strstr(v11 + 6, "*/");
LABEL_7:
v7 = v5;
v8 = v2;
if ( !v6 )
LODWORD(v6) = v4;
v9 = (int)v6 - (int)v5;
v3 = &v5[v9];
v2 += v9;
memmove(v8, v7, v9);
}
while ( *v3 );
}
*v2 = 0;
return 1LL;
}

original_code:
int extract_comments(char *input, size_t size) {
  char *current = input, *output = input, *end = ((void *)0);
  while (*current) {
    int comment_length;
    char *comment = ((void *)0), *result;
    result = strstr(current, "; @BT");
    if (result) {
      comment = result + 5;
      end = strchr(comment, '\n');
    }
    result = strstr(current, "// @BT");
    if (result && (!comment || result < comment)) {
      comment = result + 6;
      end = strchr(comment, '\n');
    }
    result = strstr(current, "/* @BT");
    if (result && (!comment || result < comment)) {
      comment = result + 6;
      end = strstr(comment, "*/");
    }
    if (!comment) {
      break;
    }
    if (!end) {
      end = input + size;
    }
    current = comment;
    comment_length = (int)(end - current);
    memmove(output, current, comment_length);
    output += comment_length;
    current += comment_length;
  }
  *output = '\0';
  return 1;
}

canonical_original_code:
int extract_comments(char *input, unsigned long size) {
  char *current = input; char *output = input; char *end = ((void *)0);
  while (*current) {
    int comment_length;
    char *comment = ((void *)0); char *result;
    result = strstr(current, "; @BT");
    if (result) {
      comment = result + 5;
      end = strchr(comment, '\n');
    }
    result = strstr(current, "// @BT");
    if (result && (!comment || result < comment)) {
      comment = result + 6;
      end = strchr(comment, '\n');
    }
    result = strstr(current, "/* @BT");
    if (result && (!comment || result < comment)) {
      comment = result + 6;
      end = strstr(comment, "*/");
    }
    if (!comment) {
      break;
    }
    if (!end) {
      end = input + size;
    }
    current = comment;
    comment_length = (int)(end - current);
    memmove(output, current, comment_length);
    output += comment_length;
    current += comment_length;
  }
  *output = '\0';
  return 1;
}

variable_types:
input
char *

variable_types:
size
unsigned long

variable_types:
current
char *

variable_types:
output
char *

variable_types:
end
char *

variable_types:
comment
char *