UDPTrainReceiver

decompiled_code:
__int64 __fastcall UDPTrainReceiver(char *dest, __int64 a2, int a3)
{
int v4; // eax
int v5; // er13
int v6; // ebx
int v7; // er14
__int64 result; // rax
__int64 v9; // rdx
unsigned int v10; // ebp
int v11; // ebx
int v12[500]; // [rsp+0h] [rbp-8C8h] BYREF
char s[112]; // [rsp+7D0h] [rbp-F8h] BYREF
struct timespec v14; // [rsp+840h] [rbp-88h] BYREF
struct timespec tp; // [rsp+850h] [rbp-78h] BYREF
int optval; // [rsp+864h] [rbp-64h] BYREF
struct addrinfo *pai; // [rsp+868h] [rbp-60h] BYREF
struct addrinfo req; // [rsp+870h] [rbp-58h] BYREF

if ( signal(2, (__sighandler_t)handle_shutdown) == (__sighandler_t)-1LL )
printf(format);
*(_QWORD *)&req.ai_socktype = 2LL;
*(_QWORD *)&req.ai_addrlen = 0LL;
req.ai_addr = 0LL;
req.ai_canonname = 0LL;
req.ai_next = 0LL;
req.ai_family = 2;
req.ai_flags = 1;
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, v12, v7, 0, 0LL, 0LL);
v10 = v12[0];
if ( v12[0] - v6 == 1 )
goto LABEL_13;
if ( v12[0] - v6 > 1 )
{
v11 = v6 + 1;
if ( v12[0] > v11 )
{
do
{
strcpy(s, "\t-1\n");
strcat(dest, s);
++v11;
}
while ( v10 != v11 );
}
LABEL_13:
clock_gettime(2, &v14);
diff(tp.tv_sec, tp.tv_nsec, v14.tv_sec, v14.tv_nsec);
sprintf(s, "%d\t%ld\n", v10, v9);
strcat(dest, s);
v6 = v10;
}
}
}
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
__int64 result; // rax
__int64 v9; // rdx
unsigned int v10; // ebp
int v11; // ebx
int v12[500]; // [rsp+0h] [rbp-8C8h] BYREF
char s[112]; // [rsp+7D0h] [rbp-F8h] BYREF
struct timespec v14; // [rsp+840h] [rbp-88h] BYREF
struct timespec tp; // [rsp+850h] [rbp-78h] BYREF
int optval; // [rsp+864h] [rbp-64h] BYREF
struct addrinfo *pai; // [rsp+868h] [rbp-60h] BYREF
struct addrinfo req; // [rsp+870h] [rbp-58h] BYREF

if ( signal(2, (__sighandler_t)handle_shutdown) == (__sighandler_t)-1LL )
printf(format);
*(_QWORD *)&req.ai_socktype = 2LL;
*(_QWORD *)&req.ai_addrlen = 0LL;
req.ai_addr = 0LL;
req.ai_canonname = 0LL;
req.ai_next = 0LL;
req.ai_family = 2;
req.ai_flags = 1;
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, v12, v7, 0, 0LL, 0LL);
v10 = v12[0];
if ( v12[0] - v6 == 1 )
goto LABEL_13;
if ( v12[0] - v6 > 1 )
{
v11 = v6 + 1;
if ( v12[0] > v11 )
{
do
{
strcpy(s, "\t-1\n");
strcat(dest, s);
++v11;
}
while ( v10 != v11 );
}
LABEL_13:
clock_gettime(2, &v14);
func1(tp.tv_sec, tp.tv_nsec, v14.tv_sec, v14.tv_nsec);
sprintf(s, "%d\t%ld\n", v10, v9);
strcat(dest, s);
v6 = v10;
}
}
}
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

repo: vhbsoft/triton

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

variable_types: 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
int v7; // ebx
__int64 result; // rax
struct sockaddr buf; // [rsp+0h] [rbp-48h] BYREF
int v10; // [rsp+10h] [rbp-38h] BYREF
__int64 v11; // [rsp+14h] [rbp-34h]
int v12; // [rsp+1Ch] [rbp-2Ch]
char dest[40]; // [rsp+20h] [rbp-28h] BYREF

strcpy(dest, a5);
v10 = a1;
v11 = a2;
v12 = a3;
v6 = socket(2, 1, 6);
if ( v6 < 0 )
{
fprintf(stderr, "ERROR #%d: Socket Setup Error", 102LL);
result = 102LL;
}
else
{
v7 = v6;
*(_QWORD *)&buf.sa_family = 2LL;
*(_QWORD *)&buf.sa_data[6] = 0LL;
inet_pton(2, dest, &buf.sa_data[2]);
*(_WORD *)buf.sa_data = _bswap_16(16400);
if ( connect(v7, &buf, 0x10u) < 0 )
{
fprintf(stderr, "ERROR #%d: Connection Setup Error IP = %s", 103LL, dest);
result = 103LL;
}
else if ( send(v7, &v10, 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
int v7; // ebx
__int64 result; // rax
struct sockaddr buf; // [rsp+0h] [rbp-48h] BYREF
int v10; // [rsp+10h] [rbp-38h] BYREF
__int64 v11; // [rsp+14h] [rbp-34h]
int v12; // [rsp+1Ch] [rbp-2Ch]
char dest[40]; // [rsp+20h] [rbp-28h] BYREF

strcpy(dest, a5);
v10 = a1;
v11 = a2;
v12 = a3;
v6 = socket(2, 1, 6);
if ( v6 < 0 )
{
fprintf(stderr, "ERROR #%d: Socket Setup Error", 102LL);
result = 102LL;
}
else
{
v7 = v6;
*(_QWORD *)&buf.sa_family = 2LL;
*(_QWORD *)&buf.sa_data[6] = 0LL;
inet_pton(2, dest, &buf.sa_data[2]);
*(_WORD *)buf.sa_data = func0(16400);
if ( connect(v7, &buf, 0x10u) < 0 )
{
fprintf(stderr, "ERROR #%d: Connection Setup Error IP = %s", 103LL, dest);
result = 103LL;
}
else if ( send(v7, &v10, 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: struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr sin_addr; unsigned char sin_zero[-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 }

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


PostExperimentTCPReceiver

decompiled_code:
__int64 __fastcall PostExperimentTCPReceiver(void *buf)
{
int v1; // eax
int v2; // ebx
int v3; // er12
ssize_t v4; // rax
__int64 result; // rax
size_t bufa; // [rsp+8h] [rbp-50h] BYREF
int optval; // [rsp+14h] [rbp-44h] BYREF
socklen_t addr_len[2]; // [rsp+18h] [rbp-40h] BYREF
struct sockaddr v9; // [rsp+20h] [rbp-38h] BYREF
struct sockaddr addr; // [rsp+30h] [rbp-28h] BYREF

v1 = socket(2, 1, 6);
if ( v1 < 0 )
{
fprintf(stderr, "ERROR #%d: Socket Setup Error", 102LL);
result = 102LL;
}
else
{
v2 = v1;
*(_DWORD *)&addr.sa_data[10] = 0;
addr.sa_family = 2;
*(_QWORD *)&addr.sa_data[2] = (unsigned int)_bswap_32(0);
*(_WORD *)addr.sa_data = _bswap_16(26400);
optval = 1;
if ( setsockopt(v2, 1, 2, &optval, 4u) == -1 )
printf("Can't set the reuse option on the socket");
if ( bind(v2, &addr, 0x10u) < 0 )
{
fprintf(stderr, "ERROR #%d: Binding Error", 106LL);
result = 106LL;
}
else if ( listen(v2, 5) < 0 )
{
fprintf(stderr, "ERROR #%d: Port Listening Error", 107LL);
result = 107LL;
}
else
{
*(_QWORD *)addr_len = 16LL;
v3 = accept(v2, &v9, addr_len);
if ( v3 < 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(v3, &bufa, 8uLL, 0) == 8 && (v4 = send(v3, buf, bufa, 0), v4 == bufa) )
{
close(v2);
result = 0LL;
}
else
{
fprintf(stderr, "ERROR #%d: Send Data Error", 104LL);
result = 104LL;
}
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(void *buf)
{
int v1; // eax
int v2; // ebx
int v3; // er12
ssize_t v4; // rax
__int64 result; // rax
size_t bufa; // [rsp+8h] [rbp-50h] BYREF
int optval; // [rsp+14h] [rbp-44h] BYREF
socklen_t addr_len[2]; // [rsp+18h] [rbp-40h] BYREF
struct sockaddr v9; // [rsp+20h] [rbp-38h] BYREF
struct sockaddr addr; // [rsp+30h] [rbp-28h] BYREF

v1 = socket(2, 1, 6);
if ( v1 < 0 )
{
fprintf(stderr, "ERROR #%d: Socket Setup Error", 102LL);
result = 102LL;
}
else
{
v2 = v1;
*(_DWORD *)&addr.sa_data[10] = 0;
addr.sa_family = 2;
*(_QWORD *)&addr.sa_data[2] = (unsigned int)func0(0);
*(_WORD *)addr.sa_data = func1(26400);
optval = 1;
if ( setsockopt(v2, 1, 2, &optval, 4u) == -1 )
printf("Can't set the reuse option on the socket");
if ( bind(v2, &addr, 0x10u) < 0 )
{
fprintf(stderr, "ERROR #%d: Binding Error", 106LL);
result = 106LL;
}
else if ( listen(v2, 5) < 0 )
{
fprintf(stderr, "ERROR #%d: Port Listening Error", 107LL);
result = 107LL;
}
else
{
*(_QWORD *)addr_len = 16LL;
v3 = accept(v2, &v9, addr_len);
if ( v3 < 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(v3, &bufa, 8uLL, 0) == 8 && (v4 = send(v3, buf, bufa, 0), v4 == bufa) )
{
close(v2);
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; // ebx
int v7; // edi
__int64 result; // rax
int v9; // [rsp+0h] [rbp-C8h] BYREF
__int64 v10; // [rsp+4h] [rbp-C4h]
int v11; // [rsp+Ch] [rbp-BCh]
int optval; // [rsp+74h] [rbp-54h] BYREF
socklen_t addr_len[2]; // [rsp+78h] [rbp-50h] BYREF
struct sockaddr v14; // [rsp+80h] [rbp-48h] BYREF
struct sockaddr addr; // [rsp+90h] [rbp-38h] BYREF

*(_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;
*(_DWORD *)&addr.sa_data[10] = 0;
addr.sa_family = 2;
*(_QWORD *)&addr.sa_data[2] = (unsigned int)_bswap_32(0);
*(_WORD *)addr.sa_data = _bswap_16(16400);
optval = 1;
if ( setsockopt(v6, 1, 2, &optval, 4u) == -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
{
v7 = accept(v6, &v14, addr_len);
if ( v7 < 0 )
{
fprintf(stderr, "ERROR #%d: Accept Client Error", 108LL);
result = 108LL;
}
else if ( recv(v7, &v9, 0x74uLL, 0) <= 0 )
{
fprintf(stderr, "ERROR #%d: Receive Data Error", 105LL);
result = 105LL;
}
else
{
*a1 = v9;
*a2 = v10;
*a3 = v11;
close(v6);
result = 0LL;
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(_DWORD *a1, _QWORD *a2, _DWORD *a3)
{
int v5; // eax
int v6; // ebx
int v7; // edi
__int64 result; // rax
int v9; // [rsp+0h] [rbp-C8h] BYREF
__int64 v10; // [rsp+4h] [rbp-C4h]
int v11; // [rsp+Ch] [rbp-BCh]
int optval; // [rsp+74h] [rbp-54h] BYREF
socklen_t addr_len[2]; // [rsp+78h] [rbp-50h] BYREF
struct sockaddr v14; // [rsp+80h] [rbp-48h] BYREF
struct sockaddr addr; // [rsp+90h] [rbp-38h] BYREF

*(_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;
*(_DWORD *)&addr.sa_data[10] = 0;
addr.sa_family = 2;
*(_QWORD *)&addr.sa_data[2] = (unsigned int)func0(0);
*(_WORD *)addr.sa_data = func1(16400);
optval = 1;
if ( setsockopt(v6, 1, 2, &optval, 4u) == -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
{
v7 = accept(v6, &v14, addr_len);
if ( v7 < 0 )
{
fprintf(stderr, "ERROR #%d: Accept Client Error", 108LL);
result = 108LL;
}
else if ( recv(v7, &v9, 0x74uLL, 0) <= 0 )
{
fprintf(stderr, "ERROR #%d: Receive Data Error", 105LL);
result = 105LL;
}
else
{
*a1 = v9;
*a2 = v10;
*a3 = v11;
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; // er12
int v1; // ebx
unsigned int v2; // ebp
int v4[11]; // [rsp+Ch] [rbp-2Ch] BYREF

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

canonical_decompiled_code:
__int64 func0()
{
int v0; // er12
int v1; // ebx
unsigned int v2; // ebp
int v4[11]; // [rsp+Ch] [rbp-2Ch] BYREF

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

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

return_type: 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
__int64 v3; // rbx
__int64 result; // rax

v2 = (char *)malloc(0x30uLL);
if ( v2 )
{
v3 = (__int64)v2;
strcpy(v2, a2);
*(_DWORD *)(v3 + 32) = a1;
*(_QWORD *)(v3 + 40) = 0LL;
if ( labels_first )
*(_QWORD *)(labels_last + 40) = v3;
else
labels_first = v3;
labels_last = v3;
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
__int64 v3; // rbx
__int64 result; // rax

v2 = (char *)malloc(0x30uLL);
if ( v2 )
{
v3 = (__int64)v2;
strcpy(v2, a2);
*(_DWORD *)(v3 + 32) = a1;
*(_QWORD *)(v3 + 40) = 0LL;
if ( labels_first )
*(_QWORD *)(labels_last + 40) = v3;
else
labels_first = v3;
labels_last = v3;
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)
{
__int64 result; // rax
int v2; // ecx
_BYTE *v3; // rdx
__int64 v4; // rcx

result = 0LL;
if ( *a1 == 45 )
{
v2 = strlen(a1);
result = 0LL;
if ( v2 != 1 )
{
v3 = a1 + 1;
if ( v2 <= 1 )
{
result = 1LL;
}
else
{
v4 = (__int64)&a1[v2 - 2 + 2];
while ( 2 )
{
switch ( *v3 )
{
case 'a':
arg_address = 0;
goto LABEL_6;
case 'b':
if ( arg_mode )
return 0LL;
arg_mode = 1;
goto LABEL_6;
case 'c':
if ( arg_mode )
return 0LL;
arg_mode = 2;
LABEL_6:
if ( ++v3 != (_BYTE *)v4 )
continue;
result = 1LL;
break;
case 'd':
arg_only_code = 1;
goto LABEL_6;
case 'l':
arg_labels = 1;
goto LABEL_6;
case 's':
arg_strings = 1;
goto LABEL_6;
default:
return 0LL;
}
break;
}
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(const char *a1)
{
__int64 result; // rax
int v2; // ecx
_BYTE *v3; // rdx
__int64 v4; // rcx

result = 0LL;
if ( *a1 == 45 )
{
v2 = strlen(a1);
result = 0LL;
if ( v2 != 1 )
{
v3 = a1 + 1;
if ( v2 <= 1 )
{
result = 1LL;
}
else
{
v4 = (__int64)&a1[v2 - 2 + 2];
while ( 2 )
{
switch ( *v3 )
{
case 'a':
arg_address = 0;
goto LABEL_6;
case 'b':
if ( arg_mode )
return 0LL;
arg_mode = 1;
goto LABEL_6;
case 'c':
if ( arg_mode )
return 0LL;
arg_mode = 2;
LABEL_6:
if ( ++v3 != (_BYTE *)v4 )
continue;
result = 1LL;
break;
case 'd':
arg_only_code = 1;
goto LABEL_6;
case 'l':
arg_labels = 1;
goto LABEL_6;
case 's':
arg_strings = 1;
goto LABEL_6;
default:
return 0LL;
}
break;
}
}
}
}
return result;
}

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

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int result; // eax
int v4; // ebp
int v5; // eax
const char *v6; // rbp
FILE *v7; // rax
FILE *v8; // rbx
unsigned int v9; // er13
size_t v10; // r12
void *v11; // rdi
int v12; // esi
int v13; // eax

if ( argc != 4 || (v4 = 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;
}
v5 = get_value((char *)argv[2], &arg_value);
if ( !v4 || !v5 )
goto LABEL_3;
v6 = argv[3];
v7 = fopen(v6, "rb");
v8 = v7;
if ( v7 )
{
fseek(v7, 0LL, 2);
dword_5C0 = ftell(v8);
fseek(v8, 0LL, 0);
v9 = dword_5C0;
v10 = dword_5C0;
v11 = malloc(dword_5C0);
in = v11;
if ( v11 )
{
fread(v11, 1uLL, v10, v8);
fclose(v8);
if ( arg_mode == 1 )
{
v13 = arg_value << 10;
if ( arg_value << 10 > dword_5C0 )
v13 = dword_5C0;
arg_value = v13;
}
v12 = dword_5C0 / 0x4000;
if ( dword_5C0 != (dword_5C0 / 0x4000) << 14 )
v12 = dword_5C0 / 0x4000 + 1;
output_header(v6, v12);
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", 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; // ebp
int v5; // eax
const char *v6; // rbp
FILE *v7; // rax
FILE *v8; // rbx
unsigned int v9; // er13
size_t v10; // r12
void *v11; // rdi
int v12; // esi
int v13; // eax

if ( argc != 4 || (v4 = 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;
}
v5 = func3((char *)argv[2], &arg_value);
if ( !v4 || !v5 )
goto LABEL_3;
v6 = argv[3];
v7 = fopen(v6, "rb");
v8 = v7;
if ( v7 )
{
fseek(v7, 0LL, 2);
dword_5C0 = ftell(v8);
fseek(v8, 0LL, 0);
v9 = dword_5C0;
v10 = dword_5C0;
v11 = malloc(dword_5C0);
in = v11;
if ( v11 )
{
fread(v11, 1uLL, v10, v8);
fclose(v8);
if ( arg_mode == 1 )
{
v13 = arg_value << 10;
if ( arg_value << 10 > dword_5C0 )
v13 = dword_5C0;
arg_value = v13;
}
v12 = dword_5C0 / 0x4000;
if ( dword_5C0 != (dword_5C0 / 0x4000) << 14 )
v12 = dword_5C0 / 0x4000 + 1;
func2(v6, v12);
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", 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)
{
__int64 result; // rax
unsigned int v3; // [rsp+Ch] [rbp-Ch] BYREF

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

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

v3 = 0;
sscanf(*a1, "%255s%n", a2, &v3);
result = v3;
if ( v3 )
{
*a1 += (int)v3;
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(void *dest, int a2)
{
_BYTE *v2; // r12
const char *v3; // rbp
char *v4; // rax
char *v5; // rbx
char *v6; // r14
char *v7; // rax
int v8; // er14
char *v9; // rax

if ( *(_BYTE *)dest )
{
v2 = dest;
v3 = (const char *)dest;
while ( 1 )
{
v9 = strstr(v3, "; @BT");
if ( !v9 )
break;
v5 = v9 + 5;
v6 = strchr(v9 + 5, 10);
v4 = strstr(v3, "// @BT");
if ( !v4 )
{
v7 = strstr(v3, "/* @BT");
if ( !v7 )
goto LABEL_10;
LABEL_7:
if ( v5 && v5 <= v7 )
goto LABEL_10;
LABEL_9:
v5 = v7 + 6;
v6 = strstr(v7 + 6, "*/");
goto LABEL_10;
}
if ( v5 > v4 )
goto LABEL_5;
LABEL_6:
v7 = strstr(v3, "/* @BT");
if ( v7 )
goto LABEL_7;
LABEL_10:
if ( !v6 )
LODWORD(v6) = (_DWORD)dest + a2;
v8 = (_DWORD)v6 - (_DWORD)v5;
memmove(v2, v5, v8);
v2 += v8;
v3 = &v5[v8];
if ( !*v3 )
goto LABEL_18;
}
v4 = strstr(v3, "// @BT");
if ( !v4 )
{
v7 = strstr(v3, "/* @BT");
if ( !v7 )
goto LABEL_18;
goto LABEL_9;
}
LABEL_5:
v5 = v4 + 6;
v6 = strchr(v4 + 6, 10);
goto LABEL_6;
}
v2 = dest;
LABEL_18:
*v2 = 0;
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(void *dest, int a2)
{
_BYTE *v2; // r12
const char *v3; // rbp
char *v4; // rax
char *v5; // rbx
char *v6; // r14
char *v7; // rax
int v8; // er14
char *v9; // rax

if ( *(_BYTE *)dest )
{
v2 = dest;
v3 = (const char *)dest;
while ( 1 )
{
v9 = strstr(v3, "; @BT");
if ( !v9 )
break;
v5 = v9 + 5;
v6 = strchr(v9 + 5, 10);
v4 = strstr(v3, "// @BT");
if ( !v4 )
{
v7 = strstr(v3, "/* @BT");
if ( !v7 )
goto LABEL_10;
LABEL_7:
if ( v5 && v5 <= v7 )
goto LABEL_10;
LABEL_9:
v5 = v7 + 6;
v6 = strstr(v7 + 6, "*/");
goto LABEL_10;
}
if ( v5 > v4 )
goto LABEL_5;
LABEL_6:
v7 = strstr(v3, "/* @BT");
if ( v7 )
goto LABEL_7;
LABEL_10:
if ( !v6 )
LODWORD(v6) = (_DWORD)dest + a2;
v8 = (_DWORD)v6 - (_DWORD)v5;
memmove(v2, v5, v8);
v2 += v8;
v3 = &v5[v8];
if ( !*v3 )
goto LABEL_18;
}
v4 = strstr(v3, "// @BT");
if ( !v4 )
{
v7 = strstr(v3, "/* @BT");
if ( !v7 )
goto LABEL_18;
goto LABEL_9;
}
LABEL_5:
v5 = v4 + 6;
v6 = strchr(v4 + 6, 10);
goto LABEL_6;
}
v2 = dest;
LABEL_18:
*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 *


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rbx
char *v4; // r13
size_t v6; // rax
const char *v7; // rbp
int v8; // ebx
int i; // er14
size_t v10; // r8
__int64 v11; // r9
__int64 v12; // rax
int v13; // edx
int v14; // er9
unsigned __int8 *v15; // rdi
__int64 v16; // rax
int v17; // edx
__int64 v18; // rbp
__int64 v19; // r13
int v20; // ebx
bool v21; // zf
size_t v22; // rax
signed int v23; // ecx
signed int v24; // er10
unsigned __int8 *v25; // rax
int v26; // er9
char *v27; // rax
__int64 v28; // rcx
__int64 v29; // rbp
__int64 v30; // rbx
unsigned __int8 v31; // r12
size_t v32; // r8
int v33; // [rsp+Ch] [rbp-107Ch]
int v34; // [rsp+Ch] [rbp-107Ch]
FILE *stream; // [rsp+10h] [rbp-1078h]
char *ptr; // [rsp+18h] [rbp-1070h]
int v37; // [rsp+20h] [rbp-1068h]
int v38; // [rsp+24h] [rbp-1064h]
int v39; // [rsp+34h] [rbp-1054h] BYREF
int v40; // [rsp+38h] [rbp-1050h] BYREF
unsigned int v41[259]; // [rsp+3Ch] [rbp-104Ch] BYREF
char *v42; // [rsp+448h] [rbp-C40h] BYREF
char s; // [rsp+450h] [rbp-C38h] BYREF
char v44; // [rsp+451h] [rbp-C37h]
char v45[1024]; // [rsp+850h] [rbp-838h] BYREF
char s1[1080]; // [rsp+C50h] [rbp-438h] BYREF

v42 = 0LL;
v40 = 0;
v39 = 0;
if ( (unsigned int)(argc - 2) > 1 || !argv )
{
fputc(10, stderr);
fwrite("Byte tester 2.1\n", 1uLL, 0x10uLL, stderr);
fputc(10, stderr);
fprintf(stderr, "USAGE: %s [-s] <TESTS FILE / SOURCE FILE>\n", *argv);
fputc(10, stderr);
fwrite(
"If -s is given then we read tests file data from the comments of a source code file.\n",
1uLL,
0x55uLL,
stderr);
fputc(10, stderr);
fwrite("TESTS FILE FORMAT:\n", 1uLL, 0x13uLL, stderr);
fputc(10, stderr);
fwrite("...\n", 1uLL, 4uLL, stderr);
fwrite("<BINARY FILE NAME>\n", 1uLL, 0x13uLL, stderr);
fwrite(
"<TEST ID> <TAG ID> START <BYTE 1> <BYTE 2> ... <BYTE N> END /* Require the bytes to be between the tags */\n",
1uLL,
0x6BuLL,
stderr);
fwrite(
"<TEST ID> -a <INTEGER ADDRESS> START <BYTE 1> <BYTE 2> ... <BYTE N> END /* Require the bytes to be at the address */\n",
1uLL,
0x75uLL,
stderr);
fwrite("<TEST ID> -y <STRING> /* Require that the string is found */\n", 1uLL, 0x3DuLL, stderr);
fwrite("<TEST ID> -n <STRING> /* Require that the string is not found */\n", 1uLL, 0x41uLL, stderr);
fwrite("...\n", 1uLL, 4uLL, stderr);
fputc(10, stderr);
fwrite(
"If <TAG ID> is \"01\", then we test if the bytes between \"01>\" and \"<01\" match with bytes 1...n\n",
1uLL,
0x5EuLL,
stderr);
fputc(10, stderr);
return 1;
}
v3 = 1LL;
v33 = 0;
v4 = 0LL;
do
{
v7 = argv[v3];
if ( !strcmp(v7, "-s") )
{
v33 = 1;
}
else
{
v6 = strlen(argv[v3]);
v4 = (char *)calloc(v6 + 1, 1uLL);
strcpy(v4, v7);
}
++v3;
}
while ( argc > (int)v3 );
stream = fopen(v4, "rb");
if ( !stream )
{
fprintf(stderr, "Error opening file \"%s\".\n", argv[1]);
return 1;
}
fseek(stream, 0LL, 2);
v8 = ftell(stream);
fseek(stream, 0LL, 0);
ptr = (char *)calloc(v8 + 1, 1uLL);
v42 = ptr;
if ( v8 != fread(ptr, 1uLL, v8, stream) )
{
fprintf(stderr, "Could not read all %d bytes of \"%s\"!", (unsigned int)v8, v4);
return 0;
}
free(v4);
if ( v33 )
extract_comments(ptr, v8);
get_token((const char **)&v42, (__int64)s1);
if ( !(unsigned int)read_binary_file(s1, &v39, stream, v41) )
return 1;
v37 = 0;
v34 = 0;
for ( i = 0; ; i = v20 )
{
do
{
if ( i || !(unsigned int)get_token((const char **)&v42, (__int64)v45) )
goto LABEL_19;
if ( !(unsigned int)read_binary_file(v45, &v39, stream, v41) )
return 1;
}
while ( v39 == 1 );
if ( !(unsigned int)get_token((const char **)&v42, (__int64)&s) )
goto LABEL_19;
if ( strlen(&s) != 2 )
{
fprintf(stderr, "Test \"%s\" FAILED - TAG ID must be exactly two characters long. Error in \"%s\".\n", v45, &s);
v34 = 1;
LABEL_19:
fclose(stream);
free(ptr);
free(g_binary_file);
return v34;
}
if ( strcmp(&s, "-a") )
break;
if ( !(unsigned int)get_token((const char **)&v42, (__int64)s1) )
goto LABEL_19;
if ( !(unsigned int)get_next_number(s1, &v40) )
{
fprintf(stderr, "\"%s\" is not a number.\n", s1);
v34 = 1;
goto LABEL_19;
}
if ( !(unsigned int)get_token((const char **)&v42, (__int64)s1) )
goto LABEL_19;
if ( strcmp(s1, "START") )
{
fprintf(stderr, "Test \"%s\" FAILED - START is missing in \"%s\".\n", v45, argv[1]);
v34 = 1;
goto LABEL_19;
}
v37 = 1;
LABEL_43:
v18 = 0LL;
while ( 1 )
{
v19 = (unsigned int)v18;
if ( !(unsigned int)get_token((const char **)&v42, (__int64)s1) )
break;
v21 = strcmp(s1, "END") == 0;
v20 = !v21;
if ( v21 )
goto LABEL_55;
v22 = strlen(s1);
if ( v22 == 1 )
{
*((_BYTE *)&v41[1] + v18) = s1[0];
}
else
{
if ( v22 != 2 )
{
fprintf(
stderr,
"Test \"%s\" FAILED - Unknown data \"%s\" in test \"%s\"! Must either be a character, two character hexadecim"
"al value or END.\n",
v45,
s1,
v45);
v34 = 1;
v20 = 1;
goto LABEL_55;
}
*((_BYTE *)&v41[1] + v18) = strtol(s1, 0LL, 16);
}
if ( ++v18 == 1024 )
{
fprintf(stderr, "Test \"%s\" FAILED - Each test can contain max %d bytes.\n", v45, 1024LL);
v19 = 1024LL;
v34 = 1;
v20 = 1;
goto LABEL_55;
}
}
v20 = 1;
LABEL_55:
v23 = v37;
if ( v37 )
{
v26 = v40;
}
else
{
v24 = v41[0] - 2;
if ( (signed int)(v41[0] - 2) <= 0 )
{
if ( v41[0] == 2 )
goto LABEL_67;
v23 = 0;
v26 = 3;
}
else
{
v25 = (unsigned __int8 *)g_binary_file;
while ( *v25 != s || v25[1] != v44 || v25[2] != 62 )
{
++v23;
++v25;
if ( v23 == v24 )
{
v23 = v41[0] - 2;
break;
}
}
if ( v24 == v23 )
{
LABEL_67:
fprintf(stderr, "Test \"%s\" FAILED - Could not find tag \"%s>\".\n", v45, &s);
v34 = 1;
continue;
}
v26 = v23 + 3;
if ( v24 > v23 )
{
v27 = (char *)g_binary_file + v23;
while ( *v27 != 60 || (unsigned __int8)v27[1] != s || (unsigned __int8)v27[2] != v44 )
{
++v23;
++v27;
if ( v23 == v41[0] - 2 )
{
v23 = v41[0] - 2;
break;
}
}
if ( v24 == v23 )
{
fprintf(stderr, "Test \"%s\" FAILED - Could not find tag \"<%s\".\n", v45, &s);
v34 = 1;
continue;
}
}
}
v28 = (unsigned int)(v23 - v26);
if ( (_DWORD)v28 != (_DWORD)v19 )
{
fprintf(
stderr,
"Test \"%s\" FAILED - There is %d bytes between the tags \"%s\", but the test \"%s\" defines %d bytes.\n",
v45,
v28,
&s,
v45,
v19);
v34 = 1;
continue;
}
}
if ( (int)v19 > 0 )
{
v29 = 1LL;
v38 = v20;
v30 = v26 - 1LL;
do
{
v31 = *((_BYTE *)v41 + v29 + 3);
if ( v31 != *((_BYTE *)g_binary_file + v30 + v29) )
{
if ( i )
fprintf(stderr, ", %d", (unsigned int)v29);
else
fprintf(stderr, "Test \"%s\" FAILED - Bytes that don't match: %d", v45, (unsigned int)v29);
fprintf(stderr, " (GOT: $%.2x EXPECTED: $%.2x)", *((unsigned __int8 *)g_binary_file + v30 + v29), v31);
++i;
}
++v29;
}
while ( v29 != (_DWORD)v19 + 1 );
v20 = v38;
if ( i > 0 )
{
fputc(10, stderr);
v34 = 1;
continue;
}
}
LABEL_106:
fprintf(stderr, "Test \"%s\" SUCCEEDED!\n", v45);
}
v20 = strcmp(&s, "-y");
if ( !v20 )
{
if ( !(unsigned int)get_token((const char **)&v42, (__int64)s1) )
goto LABEL_19;
v10 = strlen(s1);
v11 = 0LL;
while ( (int)v41[0] > (int)v11 )
{
v12 = 0LL;
v13 = v20;
if ( (int)v10 > 0 )
{
do
{
v13 = v12;
if ( *((unsigned __int8 *)g_binary_file + v11 + v12) != s1[v12] )
break;
v13 = ++v12;
}
while ( v10 != v12 );
}
++v11;
if ( (_DWORD)v10 == v13 )
goto LABEL_106;
}
goto LABEL_43;
}
v20 = strcmp(&s, "-n");
if ( v20 )
{
if ( !(unsigned int)get_token((const char **)&v42, (__int64)s1) )
goto LABEL_19;
if ( strcmp(s1, "START") )
{
fprintf(stderr, "Test \"%s\" FAILED - START/-a/-y/-n is missing in \"%s\".\n", v45, argv[1]);
v34 = 1;
goto LABEL_19;
}
goto LABEL_43;
}
if ( !(unsigned int)get_token((const char **)&v42, (__int64)s1) )
goto LABEL_19;
v32 = strlen(s1);
if ( (int)v41[0] <= 0 )
goto LABEL_106;
v15 = (unsigned __int8 *)g_binary_file;
v14 = v20;
while ( 1 )
{
v16 = 0LL;
v17 = v20;
if ( (int)v32 > 0 )
{
do
{
v17 = v16;
if ( v15[v16] != s1[v16] )
break;
v17 = ++v16;
}
while ( v32 != v16 );
}
if ( (_DWORD)v32 == v17 )
return 1;
++v14;
++v15;
if ( v14 == v41[0] )
goto LABEL_106;
}
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rbx
char *v4; // r13
size_t v6; // rax
const char *v7; // rbp
int v8; // ebx
int i; // er14
size_t v10; // r8
__int64 v11; // r9
__int64 v12; // rax
int v13; // edx
int v14; // er9
unsigned __int8 *v15; // rdi
__int64 v16; // rax
int v17; // edx
__int64 v18; // rbp
__int64 v19; // r13
int v20; // ebx
bool v21; // zf
size_t v22; // rax
signed int v23; // ecx
signed int v24; // er10
unsigned __int8 *v25; // rax
int v26; // er9
char *v27; // rax
__int64 v28; // rcx
__int64 v29; // rbp
__int64 v30; // rbx
unsigned __int8 v31; // r12
size_t v32; // r8
int v33; // [rsp+Ch] [rbp-107Ch]
int v34; // [rsp+Ch] [rbp-107Ch]
FILE *stream; // [rsp+10h] [rbp-1078h]
char *ptr; // [rsp+18h] [rbp-1070h]
int v37; // [rsp+20h] [rbp-1068h]
int v38; // [rsp+24h] [rbp-1064h]
int v39; // [rsp+34h] [rbp-1054h] BYREF
int v40; // [rsp+38h] [rbp-1050h] BYREF
unsigned int v41[259]; // [rsp+3Ch] [rbp-104Ch] BYREF
char *v42; // [rsp+448h] [rbp-C40h] BYREF
char s; // [rsp+450h] [rbp-C38h] BYREF
char v44; // [rsp+451h] [rbp-C37h]
char v45[1024]; // [rsp+850h] [rbp-838h] BYREF
char s1[1080]; // [rsp+C50h] [rbp-438h] BYREF

v42 = 0LL;
v40 = 0;
v39 = 0;
if ( (unsigned int)(argc - 2) > 1 || !argv )
{
fputc(10, stderr);
fwrite("Byte tester 2.1\n", 1uLL, 0x10uLL, stderr);
fputc(10, stderr);
fprintf(stderr, "USAGE: %s [-s] <TESTS FILE / SOURCE FILE>\n", *argv);
fputc(10, stderr);
fwrite(
"If -s is given then we read tests file data from the comments of a source code file.\n",
1uLL,
0x55uLL,
stderr);
fputc(10, stderr);
fwrite("TESTS FILE FORMAT:\n", 1uLL, 0x13uLL, stderr);
fputc(10, stderr);
fwrite("...\n", 1uLL, 4uLL, stderr);
fwrite("<BINARY FILE NAME>\n", 1uLL, 0x13uLL, stderr);
fwrite(
"<TEST ID> <TAG ID> START <BYTE 1> <BYTE 2> ... <BYTE N> END /* Require the bytes to be between the tags */\n",
1uLL,
0x6BuLL,
stderr);
fwrite(
"<TEST ID> -a <INTEGER ADDRESS> START <BYTE 1> <BYTE 2> ... <BYTE N> END /* Require the bytes to be at the address */\n",
1uLL,
0x75uLL,
stderr);
fwrite("<TEST ID> -y <STRING> /* Require that the string is found */\n", 1uLL, 0x3DuLL, stderr);
fwrite("<TEST ID> -n <STRING> /* Require that the string is not found */\n", 1uLL, 0x41uLL, stderr);
fwrite("...\n", 1uLL, 4uLL, stderr);
fputc(10, stderr);
fwrite(
"If <TAG ID> is \"01\", then we test if the bytes between \"01>\" and \"<01\" match with bytes 1...n\n",
1uLL,
0x5EuLL,
stderr);
fputc(10, stderr);
return 1;
}
v3 = 1LL;
v33 = 0;
v4 = 0LL;
do
{
v7 = argv[v3];
if ( !strcmp(v7, "-s") )
{
v33 = 1;
}
else
{
v6 = strlen(argv[v3]);
v4 = (char *)calloc(v6 + 1, 1uLL);
strcpy(v4, v7);
}
++v3;
}
while ( argc > (int)v3 );
stream = fopen(v4, "rb");
if ( !stream )
{
fprintf(stderr, "Error opening file \"%s\".\n", argv[1]);
return 1;
}
fseek(stream, 0LL, 2);
v8 = ftell(stream);
fseek(stream, 0LL, 0);
ptr = (char *)calloc(v8 + 1, 1uLL);
v42 = ptr;
if ( v8 != fread(ptr, 1uLL, v8, stream) )
{
fprintf(stderr, "Could not read all %d bytes of \"%s\"!", (unsigned int)v8, v4);
return 0;
}
free(v4);
if ( v33 )
func3(ptr, v8);
func2((const char **)&v42, (__int64)s1);
if ( !(unsigned int)func1(s1, &v39, stream, v41) )
return 1;
v37 = 0;
v34 = 0;
for ( i = 0; ; i = v20 )
{
do
{
if ( i || !(unsigned int)func2((const char **)&v42, (__int64)v45) )
goto LABEL_19;
if ( !(unsigned int)func1(v45, &v39, stream, v41) )
return 1;
}
while ( v39 == 1 );
if ( !(unsigned int)func2((const char **)&v42, (__int64)&s) )
goto LABEL_19;
if ( strlen(&s) != 2 )
{
fprintf(stderr, "Test \"%s\" FAILED - TAG ID must be exactly two characters long. Error in \"%s\".\n", v45, &s);
v34 = 1;
LABEL_19:
fclose(stream);
free(ptr);
free(g_binary_file);
return v34;
}
if ( strcmp(&s, "-a") )
break;
if ( !(unsigned int)func2((const char **)&v42, (__int64)s1) )
goto LABEL_19;
if ( !(unsigned int)func0(s1, &v40) )
{
fprintf(stderr, "\"%s\" is not a number.\n", s1);
v34 = 1;
goto LABEL_19;
}
if ( !(unsigned int)func2((const char **)&v42, (__int64)s1) )
goto LABEL_19;
if ( strcmp(s1, "START") )
{
fprintf(stderr, "Test \"%s\" FAILED - START is missing in \"%s\".\n", v45, argv[1]);
v34 = 1;
goto LABEL_19;
}
v37 = 1;
LABEL_43:
v18 = 0LL;
while ( 1 )
{
v19 = (unsigned int)v18;
if ( !(unsigned int)func2((const char **)&v42, (__int64)s1) )
break;
v21 = strcmp(s1, "END") == 0;
v20 = !v21;
if ( v21 )
goto LABEL_55;
v22 = strlen(s1);
if ( v22 == 1 )
{
*((_BYTE *)&v41[1] + v18) = s1[0];
}
else
{
if ( v22 != 2 )
{
fprintf(
stderr,
"Test \"%s\" FAILED - Unknown data \"%s\" in test \"%s\"! Must either be a character, two character hexadecim"
"al value or END.\n",
v45,
s1,
v45);
v34 = 1;
v20 = 1;
goto LABEL_55;
}
*((_BYTE *)&v41[1] + v18) = strtol(s1, 0LL, 16);
}
if ( ++v18 == 1024 )
{
fprintf(stderr, "Test \"%s\" FAILED - Each test can contain max %d bytes.\n", v45, 1024LL);
v19 = 1024LL;
v34 = 1;
v20 = 1;
goto LABEL_55;
}
}
v20 = 1;
LABEL_55:
v23 = v37;
if ( v37 )
{
v26 = v40;
}
else
{
v24 = v41[0] - 2;
if ( (signed int)(v41[0] - 2) <= 0 )
{
if ( v41[0] == 2 )
goto LABEL_67;
v23 = 0;
v26 = 3;
}
else
{
v25 = (unsigned __int8 *)g_binary_file;
while ( *v25 != s || v25[1] != v44 || v25[2] != 62 )
{
++v23;
++v25;
if ( v23 == v24 )
{
v23 = v41[0] - 2;
break;
}
}
if ( v24 == v23 )
{
LABEL_67:
fprintf(stderr, "Test \"%s\" FAILED - Could not find tag \"%s>\".\n", v45, &s);
v34 = 1;
continue;
}
v26 = v23 + 3;
if ( v24 > v23 )
{
v27 = (char *)g_binary_file + v23;
while ( *v27 != 60 || (unsigned __int8)v27[1] != s || (unsigned __int8)v27[2] != v44 )
{
++v23;
++v27;
if ( v23 == v41[0] - 2 )
{
v23 = v41[0] - 2;
break;
}
}
if ( v24 == v23 )
{
fprintf(stderr, "Test \"%s\" FAILED - Could not find tag \"<%s\".\n", v45, &s);
v34 = 1;
continue;
}
}
}
v28 = (unsigned int)(v23 - v26);
if ( (_DWORD)v28 != (_DWORD)v19 )
{
fprintf(
stderr,
"Test \"%s\" FAILED - There is %d bytes between the tags \"%s\", but the test \"%s\" defines %d bytes.\n",
v45,
v28,
&s,
v45,
v19);
v34 = 1;
continue;
}
}
if ( (int)v19 > 0 )
{
v29 = 1LL;
v38 = v20;
v30 = v26 - 1LL;
do
{
v31 = *((_BYTE *)v41 + v29 + 3);
if ( v31 != *((_BYTE *)g_binary_file + v30 + v29) )
{
if ( i )
fprintf(stderr, ", %d", (unsigned int)v29);
else
fprintf(stderr, "Test \"%s\" FAILED - Bytes that don't match: %d", v45, (unsigned int)v29);
fprintf(stderr, " (GOT: $%.2x EXPECTED: $%.2x)", *((unsigned __int8 *)g_binary_file + v30 + v29), v31);
++i;
}
++v29;
}
while ( v29 != (_DWORD)v19 + 1 );
v20 = v38;
if ( i > 0 )
{
fputc(10, stderr);
v34 = 1;
continue;
}
}
LABEL_106:
fprintf(stderr, "Test \"%s\" SUCCEEDED!\n", v45);
}
v20 = strcmp(&s, "-y");
if ( !v20 )
{
if ( !(unsigned int)func2((const char **)&v42, (__int64)s1) )
goto LABEL_19;
v10 = strlen(s1);
v11 = 0LL;
while ( (int)v41[0] > (int)v11 )
{
v12 = 0LL;
v13 = v20;
if ( (int)v10 > 0 )
{
do
{
v13 = v12;
if ( *((unsigned __int8 *)g_binary_file + v11 + v12) != s1[v12] )
break;
v13 = ++v12;
}
while ( v10 != v12 );
}
++v11;
if ( (_DWORD)v10 == v13 )
goto LABEL_106;
}
goto LABEL_43;
}
v20 = strcmp(&s, "-n");
if ( v20 )
{
if ( !(unsigned int)func2((const char **)&v42, (__int64)s1) )
goto LABEL_19;
if ( strcmp(s1, "START") )
{
fprintf(stderr, "Test \"%s\" FAILED - START/-a/-y/-n is missing in \"%s\".\n", v45, argv[1]);
v34 = 1;
goto LABEL_19;
}
goto LABEL_43;
}
if ( !(unsigned int)func2((const char **)&v42, (__int64)s1) )
goto LABEL_19;
v32 = strlen(s1);
if ( (int)v41[0] <= 0 )
goto LABEL_106;
v15 = (unsigned __int8 *)g_binary_file;
v14 = v20;
while ( 1 )
{
v16 = 0LL;
v17 = v20;
if ( (int)v32 > 0 )
{
do
{
v17 = v16;
if ( v15[v16] != s1[v16] )
break;
v17 = ++v16;
}
while ( v32 != v16 );
}
if ( (_DWORD)v32 == v17 )
return 1;
++v14;
++v15;
if ( v14 == v41[0] )
goto LABEL_106;
}
}

variable_types: i int


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char **i; // rbp
__int64 j; // rax
unsigned __int16 v5; // ax
const char *v6; // rbx
int v7; // eax
int v8; // esi
__int64 v9; // rcx
unsigned __int64 v10; // rax
__int64 v11; // rdx

for ( i = &g_instructions_table; ; i += 2 )
{
v6 = *i;
if ( !strcmp(*i, "E") )
break;
v7 = strlen(*i);
v8 = v7;
if ( v7 <= 0 )
goto LABEL_5;
v9 = (unsigned int)(v7 - 1);
for ( j = 0LL; v6[j] != 46; ++j )
{
if ( v9 == j )
goto LABEL_5;
}
if ( v8 > (int)j )
{
v10 = (unsigned int)(unsigned __int8)v6[(int)j + 1] - 66;
if ( (unsigned __int8)v10 <= 0x15u )
{
v11 = 2098177LL;
if ( _bittest64(&v11, v10) )
continue;
}
}
LABEL_5:
printf("\"%s\" ", v6);
v5 = *((_WORD *)i + 4);
if ( (v5 & 0xFF00) != 0 )
printf("$%.2X%.2X\n", (unsigned __int8)v5, HIBYTE(v5));
else
printf("$%.2X\n", v5);
}
return 0;
}


repo: vhmth/Lego-Box

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

if ( a1 )
{
*(_DWORD *)(a1 + 32) = 0;
((void (*)(void))stack_init)();
result = stack_init(a1 + 16);
}
return result;
}

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

if ( a1 )
{
*(_DWORD *)(a1 + 32) = 0;
((void (*)(void))stack_init)();
result = func16(a1 + 16);
}
return result;
}

original_code:
void queue_init(queue_t *q){
    if (!q)
        return;
    q->size = 0;
    stack_init(&(q->in));
    stack_init(&(q->out));
}

canonical_original_code:
void queue_init(struct _queue_t *q){
    if (!q)
        return;
    q->size = 0;
    stack_init(&(q->in));
    stack_init(&(q->out));
}

variable_types: struct _queue_t { struct _stack { void **items; int size; int capacity; } in; int size; } *

return_type: void

user_defined_types: struct _queue_t { struct _stack in; int size; }


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

if ( a1 )
result = *(_DWORD *)(a1 + 32) == 0;
else
result = 1LL;
return result;
}

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

if ( a1 )
result = *(_DWORD *)(a1 + 32) == 0;
else
result = 1LL;
return result;
}

original_code:
int queue_empty(queue_t *q){
    if (!q)
        return 1;
    return (q->size == 0);
}

canonical_original_code:
int queue_empty(struct _queue_t *q){
    if (!q)
        return 1;
    return (q->size == 0);
}

user_defined_types: struct _stack { void **items; int size; int capacity; }


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

if ( a1 )
result = *(unsigned int *)(a1 + 32);
else
result = 0LL;
return result;
}

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

if ( a1 )
result = *(unsigned int *)(a1 + 32);
else
result = 0LL;
return result;
}

original_code:
int queue_size(queue_t *q){
    if (!q)
        return 0;
    return q->size;
}

canonical_original_code:
int queue_size(struct _queue_t *q){
    if (!q)
        return 0;
    return q->size;
}


decompiled_code:
__int64 __fastcall queue_front(__int64 a1)
{
__int64 result; // rax
__int64 v2; // r12
int v3; // er13
int i; // ebp
__int64 v5; // rax

if ( !a1 )
return 0LL;
result = 0LL;
if ( *(_DWORD *)(a1 + 32) )
{
v2 = a1 + 16;
if ( (int)stack_size(a1 + 16) > 0 )
{
result = stack_peek(v2);
}
else
{
v3 = stack_size(a1);
if ( v3 > 0 )
{
for ( i = 0; i != v3; ++i )
{
v5 = stack_pop(a1);
stack_push(v2, v5);
}
}
result = queue_front(a1);
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1)
{
__int64 result; // rax
__int64 v2; // r12
int v3; // er13
int i; // ebp
__int64 v5; // rax

if ( !a1 )
return 0LL;
result = 0LL;
if ( *(_DWORD *)(a1 + 32) )
{
v2 = a1 + 16;
if ( (int)func21(a1 + 16) > 0 )
{
result = func20(v2);
}
else
{
v3 = func21(a1);
if ( v3 > 0 )
{
for ( i = 0; i != v3; ++i )
{
v5 = func19(a1);
func18(v2, v5);
}
}
result = func10(a1);
}
}
return result;
}

original_code:
void *queue_front(queue_t *q){
    if (!q || (q->size == 0))
        return ((void *)0);
    if (stack_size(&(q->out)) > 0)
        return stack_peek(&(q->out));
    int inSize = stack_size(&(q->in));
    int i;
    for (i = 0; i < inSize; i++)
        stack_push(&(q->out), stack_pop(&(q->in)));
    return queue_front(q);
}

canonical_original_code:
void *queue_front(struct _queue_t *q){
    if (!q || (q->size == 0))
        return ((void *)0);
    if (stack_size(&(q->out)) > 0)
        return stack_peek(&(q->out));
    int inSize = stack_size(&(q->in));
    int i;
    for (i = 0; i < inSize; i++)
        stack_push(&(q->out), stack_pop(&(q->in)));
    return queue_front(q);
}

variable_types: inSize int

return_type: void *


decompiled_code:
__int64 __fastcall queue_back(__int64 a1)
{
__int64 v1; // rbx
int v2; // ebp
int v3; // eax
int v4; // er15
int v5; // ebx
__int64 v6; // rax
int v7; // er14
__int64 v8; // rax
int v9; // eax

if ( !a1 )
return 0LL;
v1 = 0LL;
if ( *(_DWORD *)(a1 + 32) )
{
v2 = stack_size(a1);
if ( v2 )
{
v1 = stack_peek(a1);
}
else
{
v3 = stack_size(a1 + 16);
if ( v3 <= 1 )
{
v1 = stack_peek(a1 + 16);
}
else
{
v4 = v3 - 1;
v5 = 0;
do
{
v6 = stack_pop(a1 + 16);
stack_push(a1, v6);
v7 = v5++;
}
while ( v5 != v4 );
v1 = stack_peek(a1 + 16);
do
{
v8 = stack_pop(a1);
stack_push(a1 + 16, v8);
v9 = v2++;
}
while ( v7 != v9 );
}
}
}
return v1;
}

original_code:
void *queue_back(queue_t *q){
    if (!q || (q->size == 0))
        return ((void *)0);
    if (stack_size(&(q->in)))
        return stack_peek(&(q->in));
    int outSize = stack_size(&(q->out));
    int i;
    for (i = 0; i < (outSize - 1); i++)
        stack_push(&(q->in), stack_pop(&(q->out)));
    void *item = stack_peek(&(q->out));
    for (i = 0; i < (outSize - 1); i++)
        stack_push(&(q->out), stack_pop(&(q->in)));
    return item;
}

canonical_original_code:
void *queue_back(struct _queue_t *q){
    if (!q || (q->size == 0))
        return ((void *)0);
    if (stack_size(&(q->in)))
        return stack_peek(&(q->in));
    int outSize = stack_size(&(q->out));
    int i;
    for (i = 0; i < (outSize - 1); i++)
        stack_push(&(q->in), stack_pop(&(q->out)));
    void *item = stack_peek(&(q->out));
    for (i = 0; i < (outSize - 1); i++)
        stack_push(&(q->out), stack_pop(&(q->in)));
    return item;
}

variable_types: outSize int

variable_types:
item
void *


decompiled_code:
__int64 __fastcall queue_enqueue(__int64 a1, __int64 a2)
{
__int64 result; // rax

if ( a1 )
{
result = stack_push(a1, a2);
++*(_DWORD *)(a1 + 32);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 a1, __int64 a2)
{
__int64 result; // rax

if ( a1 )
{
result = func18(a1, a2);
++*(_DWORD *)(a1 + 32);
}
return result;
}

original_code:
void queue_enqueue(queue_t *q, void *item){
    if (!q)
        return;
    stack_push(&(q->in), item);
    (q->size)++;
}

canonical_original_code:
void queue_enqueue(struct _queue_t *q, void *item){
    if (!q)
        return;
    stack_push(&(q->in), item);
    (q->size)++;
}


decompiled_code:
__int64 __fastcall queue_dequeue(__int64 a1)
{
__int64 result; // rax
__int64 v2; // r12
int v3; // er13
int i; // ebp
__int64 v5; // rax

if ( !a1 )
return 0LL;
result = 0LL;
if ( *(_DWORD *)(a1 + 32) )
{
v2 = a1 + 16;
if ( (int)stack_size(a1 + 16) > 0 )
{
--*(_DWORD *)(a1 + 32);
result = stack_pop(v2);
}
else
{
v3 = stack_size(a1);
if ( v3 > 0 )
{
for ( i = 0; i != v3; ++i )
{
v5 = stack_pop(a1);
stack_push(v2, v5);
}
}
result = queue_dequeue(a1);
}
}
return result;
}

original_code:
void *queue_dequeue(queue_t *q){
    if (!q || (q->size == 0))
        return ((void *)0);
    if (stack_size(&(q->out)) > 0){
        (q->size)--;
        return stack_pop(&(q->out));
    }
    int inSize = stack_size(&(q->in));
    int i;
    for (i = 0; i < inSize; i++)
        stack_push(&(q->out), stack_pop(&(q->in)));
    return queue_dequeue(q);
}

canonical_original_code:
void *queue_dequeue(struct _queue_t *q){
    if (!q || (q->size == 0))
        return ((void *)0);
    if (stack_size(&(q->out)) > 0){
        (q->size)--;
        return stack_pop(&(q->out));
    }
    int inSize = stack_size(&(q->in));
    int i;
    for (i = 0; i < inSize; i++)
        stack_push(&(q->out), stack_pop(&(q->in)));
    return queue_dequeue(q);
}


decompiled_code:
void __fastcall queue_print(__int64 a1)
{
int v1; // er12
const char *v2; // rax
__int64 v3; // rbp

if ( a1 )
{
if ( *(_DWORD *)(a1 + 32) )
{
printf("front--> ");
if ( *(int *)(a1 + 32) > 0 )
{
v1 = 0;
do
{
v2 = (const char *)queue_dequeue(a1);
v3 = (__int64)v2;
if ( *(_DWORD *)(a1 + 32) == v1 )
printf("(%s) <--back\n", v2);
else
printf("(%s), ", v2);
queue_enqueue(a1, v3);
++v1;
}
while ( *(_DWORD *)(a1 + 32) > v1 );
}
}
}
}

original_code:
void queue_print(queue_t *q){
    if (!q || (q->size == 0))
        return;
    printf("front--> ");
    int i;
    for (i = 0; i < q->size; i++){
        void *tmp = queue_dequeue(q);
        if (i == q->size)
            printf("(%s) <--back\n", (char *)tmp);
        else
            printf("(%s), ", (char *)tmp);
        queue_enqueue(q, tmp);
    }
}

canonical_original_code:
void queue_print(struct _queue_t *q){
    if (!q || (q->size == 0))
        return;
    printf("front--> ");
    int i;
    for (i = 0; i < q->size; i++){
        void *tmp = queue_dequeue(q);
        if (i == q->size)
            printf("(%s) <--back\n", (char *)tmp);
        else
            printf("(%s), ", (char *)tmp);
        queue_enqueue(q, tmp);
    }
}

variable_types:
tmp
void *


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

if ( a1 )
{
((void (*)(void))stack_destroy)();
result = stack_destroy(a1 + 16);
}
return result;
}

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

if ( a1 )
{
((void (*)(void))stack_destroy)();
result = func22(a1 + 16);
}
return result;
}

original_code:
void queue_destroy(queue_t *q){
    if (!q)
        return;
    stack_destroy(&(q->in));
    stack_destroy(&(q->out));
}

canonical_original_code:
void queue_destroy(struct _queue_t *q){
    if (!q)
        return;
    stack_destroy(&(q->in));
    stack_destroy(&(q->out));
}


original_code:
void stack_init(stack* s){
    if(s == ((void *)0)) return;
    s->size = 0;
    s->capacity = 16;
    s->items = malloc(s->capacity * sizeof(void*));
}

canonical_original_code:
void stack_init(struct _stack *s){
    if(s == ((void *)0)) return;
    s->size = 0;
    s->capacity = 16;
    s->items = malloc(s->capacity * sizeof(void *));
}

variable_types: struct _stack { void **items; int size; int capacity; } *


decompiled_code:
void *__fastcall stack_resize(__int64 a1)
{
int v1; // eax
void *result; // rax

v1 = *(_DWORD *)(a1 + 12);
*(_DWORD *)(a1 + 12) = 2 * v1;
result = realloc(*(void **)a1, 16LL * v1);
*(_QWORD *)a1 = result;
return result;
}

canonical_decompiled_code:
void *__fastcall func17(__int64 a1)
{
int v1; // eax
void *result; // rax

v1 = *(_DWORD *)(a1 + 12);
*(_DWORD *)(a1 + 12) = 2 * v1;
result = realloc(*(void **)a1, 16LL * v1);
*(_QWORD *)a1 = result;
return result;
}

original_code:
void stack_resize(stack* s){
    s->capacity *= 2;
    s->items = realloc(s->items, s->capacity * sizeof(void*));
}

canonical_original_code:
void stack_resize(struct _stack *s){
    s->capacity *= 2;
    s->items = realloc(s->items, s->capacity * sizeof(void *));
}


decompiled_code:
__int64 __fastcall stack_push(__int64 a1, __int64 a2)
{
__int64 result; // rax

if ( *(_DWORD *)(a1 + 8) == *(_DWORD *)(a1 + 12) )
stack_resize(a1);
result = *(_QWORD *)a1;
*(_QWORD *)(*(_QWORD *)a1 + 8LL * (int)(*(_DWORD *)(a1 + 8))++) = a2;
return result;
}

original_code:
void stack_push(stack* s, void* ptr){
    if(s->size == s->capacity) stack_resize(s);
    int top_index = s->size;
    s->items[top_index] = ptr;
    s->size++;
}

canonical_original_code:
void stack_push(struct _stack *s, void *ptr){
    if(s->size == s->capacity) stack_resize(s);
    int top_index = s->size;
    s->items[top_index] = ptr;
    s->size++;
}

variable_types:
ptr
void *


original_code:
void* stack_pop(stack* s){
    if(s->size == 0) return ((void *)0);
    int top_index = s->size - 1;
    void* top_item = s->items[top_index];
    s->items[top_index] = ((void *)0);
    s->size--;
    return top_item;
}

canonical_original_code:
void *stack_pop(struct _stack *s){
    if(s->size == 0) return ((void *)0);
    int top_index = s->size - 1;
    void *top_item = s->items[top_index];
    s->items[top_index] = ((void *)0);
    s->size--;
    return top_item;
}


decompiled_code:
__int64 __fastcall stack_peek(__int64 a1)
{
int v1; // eax
__int64 result; // rax

v1 = *(_DWORD *)(a1 + 8);
if ( v1 )
result = *(_QWORD *)(*(_QWORD *)a1 + 8LL * (v1 - 1));
else
result = 0LL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func20(__int64 a1)
{
int v1; // eax
__int64 result; // rax

v1 = *(_DWORD *)(a1 + 8);
if ( v1 )
result = *(_QWORD *)(*(_QWORD *)a1 + 8LL * (v1 - 1));
else
result = 0LL;
return result;
}

original_code:
void* stack_peek(stack* s){
    if(s->size == 0) return ((void *)0);
    int top_index = s->size - 1;
    void* top_item = s->items[top_index];
    return top_item;
}

canonical_original_code:
void *stack_peek(struct _stack *s){
    if(s->size == 0) return ((void *)0);
    int top_index = s->size - 1;
    void *top_item = s->items[top_index];
    return top_item;
}


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

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

original_code:
int stack_size(stack* s){
    return s->size;
}

canonical_original_code:
int stack_size(struct _stack *s){
    return s->size;
}


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

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

original_code:
void stack_destroy(stack* s){
    free(s->items);
}

canonical_original_code:
void stack_destroy(struct _stack *s){
    free(s->items);
}


decompiled_code:
void __fastcall dsjsets_init(__int64 a1)
{
if ( a1 )
{
*(_QWORD *)a1 = 0LL;
*(_DWORD *)(a1 + 8) = 0;
}
}

original_code:
void dsjsets_init(dsjsets *d){
    if (!d)
        return;
    d->dsets = ((void *)0);
    d->size = 0;
}

canonical_original_code:
void dsjsets_init(struct _dsjsets *d){
    if (!d)
        return;
    d->dsets = ((void *)0);
    d->size = 0;
}

variable_types: struct _dsjsets { int *dsets; int size; } *


original_code:
void dsjsets_addelems(dsjsets *d, int n){
    if (!d || (n <= 0))
        return;
    if (!(d->dsets)){
        d->dsets = (int *)malloc(n*sizeof(int));
        int i;
        for (i = 0; i < n; i++)
            d->dsets[i] = -1;
        d->size = n;
        return;
    }
    d->dsets = (int *)realloc(d->dsets, (n + d->size)*sizeof(int));
    int i;
    for (i = n; i < (d->size + n); i++)
        d->dsets[i] = -1;
    d->size += n;
}

canonical_original_code:
void dsjsets_addelems(struct _dsjsets *d, int n){
    if (!d || (n <= 0))
        return;
    if (!(d->dsets)){
        d->dsets = (int *)malloc(n*sizeof(int));
        int i;
        for (i = 0; i < n; i++)
            d->dsets[i] = -1;
        d->size = n;
        return;
    }
    d->dsets = (int *)realloc(d->dsets, (n + d->size)*sizeof(int));
    int i;
    for (i = n; i < (d->size + n); i++)
        d->dsets[i] = -1;
    d->size += n;
}

variable_types: n int

user_defined_types: struct _dsjsets { int *dsets; int size; }


decompiled_code:
__int64 __fastcall dsjsets_find(__int64 *a1, int a2)
{
__int64 result; // rax
__int64 v3; // rdx
__int64 v4; // rbp
__int64 v5; // rsi

if ( !a1 )
return 0xFFFFFFFFLL;
result = (unsigned int)a2;
v3 = *a1;
if ( a2 < 0 || !v3 )
return 0xFFFFFFFFLL;
if ( *((_DWORD *)a1 + 2) <= a2 )
return 0xFFFFFFFFLL;
v4 = a2;
v5 = *(unsigned int *)(v3 + 4LL * a2);
if ( (int)v5 >= 0 )
{
result = dsjsets_find(a1, v5);
*(_DWORD *)(*a1 + 4 * v4) = result;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 *a1, int a2)
{
__int64 result; // rax
__int64 v3; // rdx
__int64 v4; // rbp
__int64 v5; // rsi

if ( !a1 )
return 0xFFFFFFFFLL;
result = (unsigned int)a2;
v3 = *a1;
if ( a2 < 0 || !v3 )
return 0xFFFFFFFFLL;
if ( *((_DWORD *)a1 + 2) <= a2 )
return 0xFFFFFFFFLL;
v4 = a2;
v5 = *(unsigned int *)(v3 + 4LL * a2);
if ( (int)v5 >= 0 )
{
result = func9(a1, v5);
*(_DWORD *)(*a1 + 4 * v4) = result;
}
return result;
}

original_code:
int dsjsets_find(dsjsets *d, int n){
    if (!d || !(d->dsets) || n < 0 || n >= d->size)
        return -1;
    if (d->dsets[n] < 0)
        return n;
    int rootSet = dsjsets_find(d, d->dsets[n]);
    d->dsets[n] = rootSet;
    return rootSet;
}

canonical_original_code:
int dsjsets_find(struct _dsjsets *d, int n){
    if (!d || !(d->dsets) || n < 0 || n >= d->size)
        return -1;
    if (d->dsets[n] < 0)
        return n;
    int rootSet = dsjsets_find(d, d->dsets[n]);
    d->dsets[n] = rootSet;
    return rootSet;
}

variable_types: rootSet int


original_code:
void dsjsets_union(dsjsets *d, int a, int b){
    if (!d || !(d->dsets) || a < 0 || a >= d->size
        || b < 0 || b >= d->size)
        return;
    int aRoot = dsjsets_find(d, a);
    int bRoot = dsjsets_find(d, b);
    int aSize = d->dsets[aRoot];
    int bSize = d->dsets[bRoot];
    if (bSize < aSize){
        d->dsets[aRoot] = bRoot;
        d->dsets[bRoot] += aSize;
        return;
    }
    d->dsets[bRoot] = aRoot;
    d->dsets[aRoot] += bSize;
}

canonical_original_code:
void dsjsets_union(struct _dsjsets *d, int a, int b){
    if (!d || !(d->dsets) || a < 0 || a >= d->size
        || b < 0 || b >= d->size)
        return;
    int aRoot = dsjsets_find(d, a);
    int bRoot = dsjsets_find(d, b);
    int aSize = d->dsets[aRoot];
    int bSize = d->dsets[bRoot];
    if (bSize < aSize){
        d->dsets[aRoot] = bRoot;
        d->dsets[bRoot] += aSize;
        return;
    }
    d->dsets[bRoot] = aRoot;
    d->dsets[aRoot] += bSize;
}

variable_types: a int

variable_types: b int

variable_types: aRoot int

variable_types: bRoot int

variable_types: aSize int

variable_types: bSize int


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

if ( a1 )
result = *(unsigned int *)(a1 + 8);
else
result = 0LL;
return result;
}

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

if ( a1 )
result = *(unsigned int *)(a1 + 8);
else
result = 0LL;
return result;
}

original_code:
int dsjsets_size(dsjsets *d){
    if (!d)
        return 0;
    return d->size;
}

canonical_original_code:
int dsjsets_size(struct _dsjsets *d){
    if (!d)
        return 0;
    return d->size;
}


decompiled_code:
void __fastcall dsjsets_print(__int64 a1)
{
int v1; // eax
__int64 v2; // rbx

if ( a1 )
{
if ( *(_QWORD *)a1 )
{
v1 = *(_DWORD *)(a1 + 8);
if ( v1 > 0 )
{
v2 = 0LL;
do
{
if ( v1 - 1 == (_DWORD)v2 )
printf("(set %d: %d)\n", (unsigned int)v2, *(unsigned int *)(*(_QWORD *)a1 + 4 * v2));
else
printf("(set %d: %d) ", (unsigned int)v2, *(unsigned int *)(*(_QWORD *)a1 + 4 * v2));
v1 = *(_DWORD *)(a1 + 8);
++v2;
}
while ( v1 > (int)v2 );
}
}
}
}

canonical_decompiled_code:
void __fastcall func12(__int64 a1)
{
int v1; // eax
__int64 v2; // rbx

if ( a1 )
{
if ( *(_QWORD *)a1 )
{
v1 = *(_DWORD *)(a1 + 8);
if ( v1 > 0 )
{
v2 = 0LL;
do
{
if ( v1 - 1 == (_DWORD)v2 )
printf("(set %d: %d)\n", (unsigned int)v2, *(unsigned int *)(*(_QWORD *)a1 + 4 * v2));
else
printf("(set %d: %d) ", (unsigned int)v2, *(unsigned int *)(*(_QWORD *)a1 + 4 * v2));
v1 = *(_DWORD *)(a1 + 8);
++v2;
}
while ( v1 > (int)v2 );
}
}
}
}

original_code:
void dsjsets_print(dsjsets *d){
    if (!d || !(d->dsets) || !(d->size))
        return;
    int i;
    for (i = 0; i < d->size; i++){
        if (i != (d->size -1))
            printf("(set %d: %d) ", i, d->dsets[i]);
        else
            printf("(set %d: %d)\n", i, d->dsets[i]);
    }
}

canonical_original_code:
void dsjsets_print(struct _dsjsets *d){
    if (!d || !(d->dsets) || !(d->size))
        return;
    int i;
    for (i = 0; i < d->size; i++){
        if (i != (d->size -1))
            printf("(set %d: %d) ", i, d->dsets[i]);
        else
            printf("(set %d: %d)\n", i, d->dsets[i]);
    }
}

variable_types: i int


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

if ( a1 )
{
v2 = *(void **)a1;
if ( v2 )
{
free(v2);
*(_QWORD *)a1 = 0LL;
*(_DWORD *)(a1 + 8) = 0;
}
}
}

original_code:
void dsjsets_destroy(dsjsets *d){
    if (!d || !(d->dsets))
        return;
    free(d->dsets);
    d->dsets = ((void *)0);
    d->size = 0;
}

canonical_original_code:
void dsjsets_destroy(struct _dsjsets *d){
    if (!d || !(d->dsets))
        return;
    free(d->dsets);
    d->dsets = ((void *)0);
    d->size = 0;
}


SuperFastHash

original_code:
uint32_t SuperFastHash (const char * data, int len) {
    uint32_t hash = len, tmp;
    int rem;
    if (len <= 0 || data == ((void *)0)) return 0;
    rem = len & 3;
    len >>= 2;
    for (;len > 0; len--){
        hash += ((((uint32_t)(((const uint8_t *)(data))[1])) << 8) +(uint32_t)(((const uint8_t *)(data))[0]) );
        tmp = (((((uint32_t)(((const uint8_t *)(data+2))[1])) << 8) +(uint32_t)(((const uint8_t *)(data+2))[0]) ) << 11) ^ hash;
        hash = (hash << 16) ^ tmp;
        data += 2*sizeof (uint16_t);
        hash += hash >> 11;
    }
    switch (rem){
        case 3: hash += ((((uint32_t)(((const uint8_t *)(data))[1])) << 8) +(uint32_t)(((const uint8_t *)(data))[0]) );
                hash ^= hash << 16;
                hash ^= ((signed char)data[sizeof (uint16_t)]) << 18;
                hash += hash >> 11;
                break;
        case 2: hash += ((((uint32_t)(((const uint8_t *)(data))[1])) << 8) +(uint32_t)(((const uint8_t *)(data))[0]) );
                hash ^= hash << 11;
                hash += hash >> 17;
                break;
        case 1: hash += (signed char)*data;
                hash ^= hash << 10;
                hash += hash >> 1;
    }
    hash ^= hash << 3;
    hash += hash >> 5;
    hash ^= hash << 4;
    hash += hash >> 17;
    hash ^= hash << 25;
    hash += hash >> 6;
    return hash;
}

canonical_original_code:
unsigned int SuperFastHash(char *data, int len) {
    unsigned int hash = len; unsigned int tmp;
    int rem;
    if (len <= 0 || data == ((void *)0)) return 0;
    rem = len & 3;
    len >>= 2;
    for (;len > 0; len--){
        hash += ((((unsigned int)(((unsigned char *)(data))[1])) << 8) +(unsigned int)(((unsigned char *)(data))[0]) );
        tmp = (((((unsigned int)(((unsigned char *)(data+2))[1])) << 8) +(unsigned int)(((unsigned char *)(data+2))[0]) ) << 11) ^ hash;
        hash = (hash << 16) ^ tmp;
        data += 2*sizeof (unsigned short);
        hash += hash >> 11;
    }
    switch (rem){
        case 3: hash += ((((unsigned int)(((unsigned char *)(data))[1])) << 8) +(unsigned int)(((unsigned char *)(data))[0]) );
                hash ^= hash << 16;
                hash ^= ((char)data[sizeof (unsigned short)]) << 18;
                hash += hash >> 11;
                break;
        case 2: hash += ((((unsigned int)(((unsigned char *)(data))[1])) << 8) +(unsigned int)(((unsigned char *)(data))[0]) );
                hash ^= hash << 11;
                hash += hash >> 17;
                break;
        case 1: hash += (char)*data;
                hash ^= hash << 10;
                hash += hash >> 1;
    }
    hash ^= hash << 3;
    hash += hash >> 5;
    hash ^= hash << 4;
    hash += hash >> 17;
    hash ^= hash << 25;
    hash += hash >> 6;
    return hash;
}

variable_types:
data
char *

variable_types: len int

variable_types:
hash
unsigned int

variable_types:
tmp
unsigned int

variable_types: rem int

return_type: unsigned int


original_code:
void hashtable_init(hashtable_t *h){
    if (!h)
        return;
    h->MAX_ALPHA = .7;
    h->alpha = 0;
    h->capacity = 32;
    h->table = (node_t **)malloc((h->capacity)*sizeof(node_t *));
    int i;
    for (i = 0; i < h->capacity; i++)
        h->table[i] = ((void *)0);
    h->numItems = 0;
}

canonical_original_code:
void hashtable_init(struct _hashtable_t *h){
    if (!h)
        return;
    h->MAX_ALPHA = .7;
    h->alpha = 0;
    h->capacity = 32;
    h->table = (struct _node_t **)malloc((h->capacity)*sizeof(struct _node_t *));
    int i;
    for (i = 0; i < h->capacity; i++)
        h->table[i] = ((void *)0);
    h->numItems = 0;
}

variable_types: struct _hashtable_t { float MAX_ALPHA; float alpha; int capacity; int numItems; struct _node_t { char *key; void *value; struct _node_t *next; } **table; } *

user_defined_types: struct _hashtable_t { float MAX_ALPHA; float alpha; int capacity; int numItems; struct _node_t **table; }


original_code:
void hashtable_insert(hashtable_t *h, char *key, void *value){
    if (!h || !(h->table) || !key || !value)
        return;
    if (h->alpha >= h->MAX_ALPHA){
        int size = h->numItems;
        char *keys[size];
        void *values[size];
        int i;
        int j;
        j = 0;
        for (i = 0; i < h->capacity; i++){
            if (h->table[i]){
                node_t *stepper = h->table[i];
                while (stepper){
                    node_t *tmp = stepper->next;
                    keys[j] = stepper->key;
                    values[j] = stepper->value;
                    j++;
                    free(stepper);
                    stepper = tmp;
                }
                h->table[i] = ((void *)0);
            }
        }
        h->capacity *= 2;
        h->table = realloc(h->table, h->capacity*sizeof(node_t *));
        h->numItems = 0;
        h->alpha = 0;
        for (i = 0; i < h->capacity; i++)
            h->table[i] = ((void *)0);
        for (i = 0; i < size; i++)
            hashtable_insert(h, keys[i], values[i]);
    }
    unsigned int index = SuperFastHash(key, h->capacity) % h->capacity;
    if (!h->table[index]){
        h->table[index] = (node_t *)malloc(sizeof(node_t));
        (h->table[index])->key = key;
        (h->table[index])->value = value;
        (h->table[index])->next = ((void *)0);
    } else {
        node_t *tmp = (node_t *)malloc(sizeof(node_t));
        tmp->value = value;
        tmp->key = key;
        tmp->next = h->table[index];
        h->table[index] = tmp;
    }
    (h->numItems)++;
    h->alpha = (float)h->numItems/(h->capacity);
}

canonical_original_code:
void hashtable_insert(struct _hashtable_t *h, char *key, void *value){
    if (!h || !(h->table) || !key || !value)
        return;
    if (h->alpha >= h->MAX_ALPHA){
        int size = h->numItems;
        char *keys[-1];
        void *values[-1];
        int i;
        int j;
        j = 0;
        for (i = 0; i < h->capacity; i++){
            if (h->table[i]){
                struct _node_t *stepper = h->table[i];
                while (stepper){
                    struct _node_t *tmp = stepper->next;
                    keys[j] = stepper->key;
                    values[j] = stepper->value;
                    j++;
                    free(stepper);
                    stepper = tmp;
                }
                h->table[i] = ((void *)0);
            }
        }
        h->capacity *= 2;
        h->table = realloc(h->table, h->capacity*sizeof(struct _node_t *));
        h->numItems = 0;
        h->alpha = 0;
        for (i = 0; i < h->capacity; i++)
            h->table[i] = ((void *)0);
        for (i = 0; i < size; i++)
            hashtable_insert(h, keys[i], values[i]);
    }
    unsigned int index = SuperFastHash(key, h->capacity) % h->capacity;
    if (!h->table[index]){
        h->table[index] = (struct _node_t *)malloc(sizeof(node_t));
        (h->table[index])->key = key;
        (h->table[index])->value = value;
        (h->table[index])->next = ((void *)0);
    } else {
        struct _node_t *tmp = (node_t *)malloc(sizeof(node_t));
        tmp->value = value;
        tmp->key = key;
        tmp->next = h->table[index];
        h->table[index] = tmp;
    }
    (h->numItems)++;
    h->alpha = (float)h->numItems/(h->capacity);
}

variable_types:
key
char *

variable_types:
value
void *

variable_types: size int

variable_types:
keys
char *[-1]

variable_types:
values
void *[-1]

variable_types: j int

variable_types: struct _node_t { char *key; void *value; struct _node_t *next; } *

variable_types:
index
unsigned int


decompiled_code:
__int64 __fastcall hashtable_find(__int64 a1, unsigned __int8 *a2)
{
__int64 v2; // r12
unsigned int v3; // ebx
__int64 v4; // rbx

if ( !a1 )
return 0LL;
v2 = *(_QWORD *)(a1 + 16);
if ( !v2 || !a2 )
return 0LL;
v3 = *(_DWORD *)(a1 + 8);
v4 = *(_QWORD *)(v2 + 8LL * ((unsigned int)SuperFastHash(a2, v3) % v3));
if ( v4 )
{
while ( strcmp((const char *)a2, *(const char **)v4) )
{
v4 = *(_QWORD *)(v4 + 16);
if ( !v4 )
return v4;
}
v4 = *(_QWORD *)(v4 + 8);
}
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1, unsigned __int8 *a2)
{
__int64 v2; // r12
unsigned int v3; // ebx
__int64 v4; // rbx

if ( !a1 )
return 0LL;
v2 = *(_QWORD *)(a1 + 16);
if ( !v2 || !a2 )
return 0LL;
v3 = *(_DWORD *)(a1 + 8);
v4 = *(_QWORD *)(v2 + 8LL * ((unsigned int)func7(a2, v3) % v3));
if ( v4 )
{
while ( strcmp((const char *)a2, *(const char **)v4) )
{
v4 = *(_QWORD *)(v4 + 16);
if ( !v4 )
return v4;
}
v4 = *(_QWORD *)(v4 + 8);
}
return v4;
}

original_code:
void *hashtable_find(hashtable_t *h, char *key){
    if(!h || !(h->table) | !key)
        return ((void *)0);
    unsigned int index = SuperFastHash(key, h->capacity) % h->capacity;
    node_t *stepper = h->table[index];
    while (stepper){
        if (!strcmp(key, stepper->key))
            return stepper->value;
        stepper = stepper->next;
    }
    return ((void *)0);
}

canonical_original_code:
void *hashtable_find(struct _hashtable_t *h, char *key){
    if(!h || !(h->table) | !key)
        return ((void *)0);
    unsigned int index = SuperFastHash(key, h->capacity) % h->capacity;
    struct _node_t *stepper = h->table[index];
    while (stepper){
        if (!strcmp(key, stepper->key))
            return stepper->value;
        stepper = stepper->next;
    }
    return ((void *)0);
}

user_defined_types: struct _node_t { char *key; void *value; struct _node_t *next; }


decompiled_code:
void __fastcall hashtable_remove(__int64 a1, unsigned __int8 *a2)
{
__int64 v2; // r13
unsigned int v3; // ebx
const char ***v4; // r13
const char **v5; // rbx
const char **v6; // r13

if ( a1 )
{
v2 = *(_QWORD *)(a1 + 16);
if ( a2 )
{
if ( v2 )
{
v3 = *(_DWORD *)(a1 + 8);
v4 = (const char ***)(v2 + 8LL * ((unsigned int)SuperFastHash(a2, v3) % v3));
v5 = *v4;
if ( !strcmp((const char *)a2, **v4) )
{
*v4 = (const char **)v5[2];
free(v5);
--*(_DWORD *)(a1 + 12);
}
else
{
while ( 1 )
{
v6 = v5;
v5 = (const char **)v5[2];
if ( !v5 )
break;
if ( !strcmp(*v5, (const char *)a2) )
{
v6[2] = v5[2];
free(v5);
--*(_DWORD *)(a1 + 12);
break;
}
}
}
*(float *)(a1 + 4) = (float)*(int *)(a1 + 12) / (float)*(int *)(a1 + 8);
}
}
}
}

original_code:
void hashtable_remove(hashtable_t *h, char *key){
    if (!h || !(h->table) || !key)
        return;
    unsigned int index = SuperFastHash(key, h->capacity) % h->capacity;
    node_t *stepper = h->table[index];
    if (!strcmp(key, stepper->key)){
        h->table[index] = stepper->next;
        free(stepper);
        (h->numItems)--;
    } else {
        while(stepper->next){
            if (!strcmp(stepper->next->key, key)){
                node_t *tmp = stepper->next;
                stepper->next = stepper->next->next;
                free(tmp);
                (h->numItems)--;
                break;
            }
            stepper = stepper->next;
        }
    }
    h->alpha = (float)h->numItems/(h->capacity);
}

canonical_original_code:
void hashtable_remove(struct _hashtable_t *h, char *key){
    if (!h || !(h->table) || !key)
        return;
    unsigned int index = SuperFastHash(key, h->capacity) % h->capacity;
    struct _node_t *stepper = h->table[index];
    if (!strcmp(key, stepper->key)){
        h->table[index] = stepper->next;
        free(stepper);
        (h->numItems)--;
    } else {
        while(stepper->next){
            if (!strcmp(stepper->next->key, key)){
                struct _node_t *tmp = stepper->next;
                stepper->next = stepper->next->next;
                free(tmp);
                (h->numItems)--;
                break;
            }
            stepper = stepper->next;
        }
    }
    h->alpha = (float)h->numItems/(h->capacity);
}


original_code:
void hashtable_destroy(hashtable_t *h){
    if (!h || !(h->table))
        return;
    node_t *stepper;
    int i;
    for (i = 0; i < h->capacity; i++){
        stepper = h->table[i];
        while(stepper){
            node_t *tmp = stepper->next;
            free(stepper);
            stepper = tmp;
        }
        h->table[i] = ((void *)0);
    }
    free(h->table);
    h->table = ((void *)0);
    h->alpha = 0;
    h->numItems = 0;
    h->capacity = 0;
}

canonical_original_code:
void hashtable_destroy(struct _hashtable_t *h){
    if (!h || !(h->table))
        return;
    struct _node_t *stepper;
    int i;
    for (i = 0; i < h->capacity; i++){
        stepper = h->table[i];
        while(stepper){
            struct _node_t *tmp = stepper->next;
            free(stepper);
            stepper = tmp;
        }
        h->table[i] = ((void *)0);
    }
    free(h->table);
    h->table = ((void *)0);
    h->alpha = 0;
    h->numItems = 0;
    h->capacity = 0;
}