main

canonical_name: main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
const char *v3; // rdx
int v4; // eax
__int64 i; // r13
_BYTE v6[328]; // [rsp-150h] [rbp-318h] BYREF
_BYTE v7[336]; // [rsp+0h] [rbp-1C8h] BYREF
__m128i v8; // [rsp+150h] [rbp-78h] BYREF
__int64 v9; // [rsp+160h] [rbp-68h]
__int64 v10; // [rsp+168h] [rbp-60h]
__int128 v11; // [rsp+170h] [rbp-58h]
__int128 v12; // [rsp+180h] [rbp-48h]
unsigned __int64 v13; // [rsp+198h] [rbp-30h]

v3 = *argv;
v13 = __readfsqword(0x28u);
v9 = 102LL;
v10 = 0LL;
system_argv = v3;
v8 = _mm_load_si128((const __m128i *)&LC4);
v11 = 0LL;
v12 = 0LL;
while ( 1 )
{
v4 = _posix_getopt((unsigned int)argc, argv, "c:");
if ( v4 == -1 )
break;
if ( v4 == 63 )
{
fprintf(stderr, "Usage: %s [-c config]\n", *argv);
exit(1);
}
if ( v4 == 99 )
strncpyz(&v8, optarg, 64LL);
}
init();
load_config(&v8);
now = time(0LL);
net_connect();
now = time(0LL);
for ( i = now; ; i = now )
{
now = time(0LL);
if ( now != i )
{
pack_empty(v7);
qmemcpy(v6, v7, sizeof(v6));
hook_call("ontick");
}
net_read();
}
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
const char *v3; // rdx
int v4; // eax
__int64 i; // r13
_BYTE v6[328]; // [rsp-150h] [rbp-318h] BYREF
_BYTE v7[336]; // [rsp+0h] [rbp-1C8h] BYREF
__m128i v8; // [rsp+150h] [rbp-78h] BYREF
__int64 v9; // [rsp+160h] [rbp-68h]
__int64 v10; // [rsp+168h] [rbp-60h]
__int128 v11; // [rsp+170h] [rbp-58h]
__int128 v12; // [rsp+180h] [rbp-48h]
unsigned __int64 v13; // [rsp+198h] [rbp-30h]

v3 = *argv;
v13 = __readfsqword(0x28u);
v9 = 102LL;
v10 = 0LL;
system_argv = v3;
v8 = _mm_load_si128((const __m128i *)&LC4);
v11 = 0LL;
v12 = 0LL;
while ( 1 )
{
v4 = _posix_getopt((unsigned int)argc, argv, "c:");
if ( v4 == -1 )
break;
if ( v4 == 63 )
{
fprintf(stderr, "Usage: %s [-c config]\n", *argv);
exit(1);
}
if ( v4 == 99 )
strncpyz(&v8, optarg, 64LL);
}
func0();
load_config(&v8);
now = time(0LL);
net_connect();
now = time(0LL);
for ( i = now; ; i = now )
{
now = time(0LL);
if ( now != i )
{
pack_empty(v7);
qmemcpy(v6, v7, sizeof(v6));
hook_call("ontick");
}
net_read();
}
}

original_code:
int main(int argc, char **argv) {
 char configfile[64] = "./plservices.conf";
 time_t last;
 int opt;
 system_argv = argv[0];
 while ((opt = getopt(argc, argv, "c:")) != -1) {
  switch (opt) {
   case 'c':
    strncpyz((configfile), (optarg), sizeof(configfile));
    break;
   case '?':
    fprintf(stderr, "Usage: %s [-c config]\n", argv[0]);
    exit(1);
  }
 }
 init();
 load_config(configfile);
 now = time(((void *)0));
 net_connect();
 last = now = time(((void *)0));
 while (1) {
  now = time(((void *)0));
  if (last != now) {
   hook_call("ontick", pack_empty());
  }
  net_read();
  last = now;
 }
 return 0;
}

canonical_original_code:
int main(int argc, char **argv) {
 char configfile[64] = "./plservices.conf";
 long last;
 int opt;
 system_argv = argv[0];
 while ((opt = getopt(argc, argv, "c:")) != -1) {
  switch (opt) {
   case 'c':
    strncpyz((configfile), (optarg), sizeof(configfile));
    break;
   case '?':
    fprintf(stderr, "Usage: %s [-c config]\n", argv[0]);
    exit(1);
  }
 }
 init();
 load_config(configfile);
 now = time(((void *)0));
 net_connect();
 last = now = time(((void *)0));
 while (1) {
  now = time(((void *)0));
  if (last != now) {
   hook_call("ontick", pack_empty());
  }
  net_read();
  last = now;
 }
 return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types:
configfile
char [64]

variable_types: last long

variable_types: opt int


repo: thommey/plservices

decompiled_code:
unsigned __int64 __fastcall send_raw(void *buf)
{
size_t v1; // rbx
ssize_t v2; // rax
int *v4; // rax
char *v5; // rax
_BYTE v6[520]; // [rsp+0h] [rbp-228h] BYREF
unsigned __int64 v7; // [rsp+208h] [rbp-20h]

v7 = __readfsqword(0x28u);
v1 = strlen((const char *)buf);
logfmt(1024LL, "-> %s", (const char *)buf);
strncpyz(v6, buf, 513LL);
for ( ; v1; v1 -= v2 )
{
v2 = send(conn, buf, v1, 0);
if ( v2 < 0 )
{
v4 = _errno_location();
v5 = strerror(*v4);
logfmt(1LL, "POSIX error: %s", v5);
logfmt(1LL, "Fatal error at %s (line %d): %s\n", "src/net.c", 103LL, "Error in sending data");
exit(1);
}
}
handle_input(v6);
return v7 - __readfsqword(0x28u);
}

canonical_decompiled_code:
unsigned __int64 __fastcall func1(void *buf)
{
size_t v1; // rbx
ssize_t v2; // rax
int *v4; // rax
char *v5; // rax
_BYTE v6[520]; // [rsp+0h] [rbp-228h] BYREF
unsigned __int64 v7; // [rsp+208h] [rbp-20h]

v7 = __readfsqword(0x28u);
v1 = strlen((const char *)buf);
logfmt(1024LL, "-> %s", (const char *)buf);
strncpyz(v6, buf, 513LL);
for ( ; v1; v1 -= v2 )
{
v2 = send(conn, buf, v1, 0);
if ( v2 < 0 )
{
v4 = _errno_location();
v5 = strerror(*v4);
logfmt(1LL, "POSIX error: %s", v5);
logfmt(1LL, "Fatal error at %s (line %d): %s\n", "src/net.c", 103LL, "Error in sending data");
exit(1);
}
}
handle_input(v6);
return v7 - __readfsqword(0x28u);
}

original_code:
void send_raw(char *str) {
 char buf[513];
 ssize_t tosend, sent;
 tosend = strlen(str);
 logfmt(0x0400, "-> %s", str);
 strncpyz((buf), (str), sizeof(buf));
 while (tosend) {
  sent = send(conn, str, tosend, 0);
  if (sent < 0)
   do { logfmt(0x0001, "POSIX error: %s", strerror((*__errno_location ()))); do { logfmt(0x0001, "Fatal error at %s (line %d): %s\n", "src/net.c", 103, "Error in sending data"); exit(1); } while (0); } while(0);
  tosend -= sent;
 }
 handle_input(buf);
}

canonical_original_code:
void send_raw(char *str) {
 char buf[513];
 long tosend; long sent;
 tosend = strlen(str);
 logfmt(0x0400, "-> %s", str);
 strncpyz((buf), (str), sizeof(buf));
 while (tosend) {
  sent = send(conn, str, tosend, 0);
  if (sent < 0)
   do { logfmt(0x0001, "POSIX error: %s", strerror((*__errno_location ()))); do { logfmt(0x0001, "Fatal error at %s (line %d): %s\n", "src/net.c", 103, "Error in sending data"); exit(1); } while (0); } while(0);
  tosend -= sent;
 }
 handle_input(buf);
}

variable_types:
str
char *

variable_types:
buf
char [513]

variable_types: tosend long

variable_types: sent long

return_type: void


decompiled_code:
unsigned __int64 send_format(char *format, ...)
{
gcc_va_list va; // [rsp+0h] [rbp-D8h] BYREF
unsigned __int64 v3; // [rsp+18h] [rbp-C0h]

va_start(va, format);
v3 = __readfsqword(0x28u);
if ( vsnprintf(buf_1, 0x200uLL, format, va) == 512 )
byte_11560 = 0;
send_raw(buf_1);
return v3 - __readfsqword(0x28u);
}

canonical_decompiled_code:
unsigned __int64 func3(char *format, ...)
{
gcc_va_list va; // [rsp+0h] [rbp-D8h] BYREF
unsigned __int64 v3; // [rsp+18h] [rbp-C0h]

va_start(va, format);
v3 = __readfsqword(0x28u);
if ( vsnprintf(buf_1, 0x200uLL, format, va) == 512 )
byte_11560 = 0;
func1(buf_1);
return v3 - __readfsqword(0x28u);
}

original_code:
void send_format(const char *fmt, ...) {
 static char buf[513];
 va_list ap;
 __builtin_va_start(ap,fmt);
 if (vsnprintf(buf, sizeof(buf)-1, fmt, ap) == sizeof(buf)-1)
  buf[sizeof(buf)-1] = '\0';
 __builtin_va_end(ap);
 send_raw(buf);
}

canonical_original_code:
void send_format(char *fmt, ...) {
 static char buf[513];
 __builtin_va_list ap;
 __builtin_va_start(ap,fmt);
 if (vsnprintf(buf, sizeof(buf)-1, fmt, ap) == sizeof(buf)-1)
  buf[sizeof(buf)-1] = '\0';
 __builtin_va_end(ap);
 send_raw(buf);
}

variable_types:
fmt
char *


decompiled_code:
unsigned __int64 __fastcall net_greet(const char *a1, const char *a2, __int64 a3, const char *a4)
{
char v6[3]; // [rsp+5h] [rbp-33h] BYREF
unsigned __int64 v7; // [rsp+8h] [rbp-30h]

v7 = __readfsqword(0x28u);
base64_encode_padded(v6, 3LL);
send_format("PASS :%s\r\n", a1);
send_format("SERVER %s 1 %ld %ld J10 %s]]] +hsn :%s\r\n", a2, now, now, v6, a4);
return v7 - __readfsqword(0x28u);
}

canonical_decompiled_code:
unsigned __int64 __fastcall func4(const char *a1, const char *a2, __int64 a3, const char *a4)
{
char v6[3]; // [rsp+5h] [rbp-33h] BYREF
unsigned __int64 v7; // [rsp+8h] [rbp-30h]

v7 = __readfsqword(0x28u);
base64_encode_padded(v6, 3LL);
func3("PASS :%s\r\n", a1);
func3("SERVER %s 1 %ld %ld J10 %s]]] +hsn :%s\r\n", a2, now, now, v6, a4);
return v7 - __readfsqword(0x28u);
}

original_code:
static void net_greet(const char *pass, const char *name, unsigned long numeric, const char *descr) {
 char numericstr[2 +1];
 base64_encode_padded(numericstr, sizeof(numericstr), numeric);
 send_format("PASS :%s\r\n", pass);
 send_format("SERVER %s 1 %ld %ld J10 %s]]] +hsn :%s\r\n", name, now, now, numericstr, descr);
}

canonical_original_code:
static void net_greet(char *pass, char *name, unsigned long numeric, char *descr) {
 char numericstr[-1];
 base64_encode_padded(numericstr, sizeof(numericstr), numeric);
 send_format("PASS :%s\r\n", pass);
 send_format("SERVER %s 1 %ld %ld J10 %s]]] +hsn :%s\r\n", name, now, now, numericstr, descr);
}

variable_types:
pass
char *

variable_types:
name
char *

variable_types:
numeric
unsigned long

variable_types:
descr
char *

variable_types:
numericstr
char [-1]


decompiled_code:
unsigned __int64 net_connect()
{
const char *v0; // rbp
const char *v1; // r12
const char *v2; // r13
const char *v3; // rbx
const char *v4; // r14
const char *v5; // r15
__int64 v6; // rbx
struct hostent *v7; // rax
int v8; // ebp
char *v9; // rax
__int16 v10; // ax
const char *v12; // r8
__int64 v13; // rcx
int *v14; // rax
char *v15; // rax
int *v16; // rax
char *v17; // rax
int *v18; // rax
char *v19; // rax
struct in_addr in; // [rsp+Ch] [rbp-6Ch]
int optval; // [rsp+1Ch] [rbp-5Ch] BYREF
struct sockaddr v22; // [rsp+20h] [rbp-58h] BYREF
unsigned __int64 v23; // [rsp+38h] [rbp-40h]

v23 = __readfsqword(0x28u);
v0 = (const char *)config_get("core.uplink", "host");
v1 = (const char *)config_get("core.uplink", "port");
v2 = (const char *)config_get("core.uplink", "pass");
v3 = (const char *)config_get("core.server", "numeric");
v4 = (const char *)config_get("core.server", "name");
optval = 1;
v5 = (const char *)config_get("core.server", "description");
v6 = strtol(v3, 0LL, 10);
if ( v1 == 0LL || v0 == 0LL || !v2 )
{
v12 = "Invalid uplink specified in configfile. Need [core.uplink] host, port, pass";
v13 = 70LL;
goto LABEL_10;
}
if ( v5 == 0LL || v4 == 0LL || !v6 )
{
v12 = "Invalid uplink specified in configfile. Need [core.server] numeric (1-4096), servername, descr";
v13 = 73LL;
goto LABEL_10;
}
conn = socket(2, 1, 6);
if ( conn < 0 )
{
v14 = _errno_location();
v15 = strerror(*v14);
logfmt(1LL, "POSIX error: %s", v15);
v12 = "Could not create socket";
v13 = 76LL;
goto LABEL_10;
}
v7 = gethostbyname(v0);
if ( !v7 )
{
v16 = _errno_location();
v17 = strerror(*v16);
logfmt(1LL, "POSIX error: %s", v17);
v12 = "Could not resolve hostname.";
v13 = 80LL;
goto LABEL_10;
}
v8 = conn;
in.s_addr = **(_DWORD **)v7->h_addr_list;
setsockopt(conn, 6, 1, &optval, 4u);
v22 = 0LL;
v22.sa_family = 2;
v9 = inet_ntoa(in);
*(_DWORD *)&v22.sa_data[2] = inet_addr(v9);
v10 = atoi(v1);
*(_WORD *)v22.sa_data = _bswap_16(v10);
if ( connect(v8, &v22, 0x10u) < 0 )
{
v18 = _errno_location();
v19 = strerror(*v18);
logfmt(1LL, "POSIX error: %s", v19);
v12 = "Failed to connect to server";
v13 = 89LL;
LABEL_10:
logfmt(1LL, "Fatal error at %s (line %d): %s\n", "src/net.c", v13, v12);
exit(1);
}
net_greet(v2, v4, v6, v5);
return v23 - __readfsqword(0x28u);
}

canonical_decompiled_code:
unsigned __int64 func5()
{
const char *v0; // rbp
const char *v1; // r12
const char *v2; // r13
const char *v3; // rbx
const char *v4; // r14
const char *v5; // r15
__int64 v6; // rbx
struct hostent *v7; // rax
int v8; // ebp
char *v9; // rax
__int16 v10; // ax
const char *v12; // r8
__int64 v13; // rcx
int *v14; // rax
char *v15; // rax
int *v16; // rax
char *v17; // rax
int *v18; // rax
char *v19; // rax
struct in_addr in; // [rsp+Ch] [rbp-6Ch]
int optval; // [rsp+1Ch] [rbp-5Ch] BYREF
struct sockaddr v22; // [rsp+20h] [rbp-58h] BYREF
unsigned __int64 v23; // [rsp+38h] [rbp-40h]

v23 = __readfsqword(0x28u);
v0 = (const char *)config_get("core.uplink", "host");
v1 = (const char *)config_get("core.uplink", "port");
v2 = (const char *)config_get("core.uplink", "pass");
v3 = (const char *)config_get("core.server", "numeric");
v4 = (const char *)config_get("core.server", "name");
optval = 1;
v5 = (const char *)config_get("core.server", "description");
v6 = strtol(v3, 0LL, 10);
if ( v1 == 0LL || v0 == 0LL || !v2 )
{
v12 = "Invalid uplink specified in configfile. Need [core.uplink] host, port, pass";
v13 = 70LL;
goto LABEL_10;
}
if ( v5 == 0LL || v4 == 0LL || !v6 )
{
v12 = "Invalid uplink specified in configfile. Need [core.server] numeric (1-4096), servername, descr";
v13 = 73LL;
goto LABEL_10;
}
conn = socket(2, 1, 6);
if ( conn < 0 )
{
v14 = _errno_location();
v15 = strerror(*v14);
logfmt(1LL, "POSIX error: %s", v15);
v12 = "Could not create socket";
v13 = 76LL;
goto LABEL_10;
}
v7 = gethostbyname(v0);
if ( !v7 )
{
v16 = _errno_location();
v17 = strerror(*v16);
logfmt(1LL, "POSIX error: %s", v17);
v12 = "Could not resolve hostname.";
v13 = 80LL;
goto LABEL_10;
}
v8 = conn;
in.s_addr = **(_DWORD **)v7->h_addr_list;
setsockopt(conn, 6, 1, &optval, 4u);
v22 = 0LL;
v22.sa_family = 2;
v9 = inet_ntoa(in);
*(_DWORD *)&v22.sa_data[2] = inet_addr(v9);
v10 = atoi(v1);
*(_WORD *)v22.sa_data = func0(v10);
if ( connect(v8, &v22, 0x10u) < 0 )
{
v18 = _errno_location();
v19 = strerror(*v18);
logfmt(1LL, "POSIX error: %s", v19);
v12 = "Failed to connect to server";
v13 = 89LL;
LABEL_10:
logfmt(1LL, "Fatal error at %s (line %d): %s\n", "src/net.c", v13, v12);
exit(1);
}
func4(v2, v4, v6, v5);
return v23 - __readfsqword(0x28u);
}

original_code:
void net_connect(void) {
 char *uplink = config_get("core.uplink", "host");
 const char *port = config_get("core.uplink", "port");
 const char *pass = config_get("core.uplink", "pass");
 const char *numericstr = config_get("core.server", "numeric");
 const char *servername= config_get("core.server", "name");
 const char *descr = config_get("core.server", "description");
 unsigned long numeric;
 struct sockaddr_in server;
 struct hostent *hostname;
 struct in_addr ip_addr;
 int flag_set = 1;
 numeric = strtol(numericstr, ((void *)0), 10);
 if (!uplink || !port || !pass)
  do { logfmt(0x0001, "Fatal error at %s (line %d): %s\n", "src/net.c", 70, "Invalid uplink specified in configfile. Need [core.uplink] host, port, pass"); exit(1); } while (0);
 if (!servername || !descr || !numeric || !numeric)
  do { logfmt(0x0001, "Fatal error at %s (line %d): %s\n", "src/net.c", 73, "Invalid uplink specified in configfile. Need [core.server] numeric (1-4096), servername, descr"); exit(1); } while (0);
 if ((conn = socket(2, SOCK_STREAM, IPPROTO_TCP)) < 0)
  do { logfmt(0x0001, "POSIX error: %s", strerror((*__errno_location ()))); do { logfmt(0x0001, "Fatal error at %s (line %d): %s\n", "src/net.c", 76, "Could not create socket"); exit(1); } while (0); } while(0);
 hostname = gethostbyname(uplink);
 if (!hostname)
  do { logfmt(0x0001, "POSIX error: %s", strerror((*__errno_location ()))); do { logfmt(0x0001, "Fatal error at %s (line %d): %s\n", "src/net.c", 80, "Could not resolve hostname."); exit(1); } while (0); } while(0);
 ip_addr = *(struct in_addr *)(hostname->h_addr_list[0]);
 setsockopt(conn, IPPROTO_TCP, 1, &flag_set, sizeof(flag_set));
 memset(&server, 0, sizeof(server));
 server.sin_family = 2;
 server.sin_addr.s_addr = inet_addr(inet_ntoa(ip_addr));
 server.sin_port = htons(atoi(port));
 if (connect(conn, (struct sockaddr *) &server, sizeof(server)) < 0)
  do { logfmt(0x0001, "POSIX error: %s", strerror((*__errno_location ()))); do { logfmt(0x0001, "Fatal error at %s (line %d): %s\n", "src/net.c", 89, "Failed to connect to server"); exit(1); } while (0); } while(0);
 net_greet(pass, servername, numeric, descr);
}

canonical_original_code:
void net_connect() {
 char *uplink = config_get("core.uplink", "host");
 char *port = config_get("core.uplink", "port");
 char *pass = config_get("core.uplink", "pass");
 char *numericstr = config_get("core.server", "numeric");
 char *servername = config_get("core.server", "name");
 char *descr = config_get("core.server", "description");
 unsigned long numeric;
 struct sockaddr_in server;
 struct hostent *hostname;
 struct in_addr ip_addr;
 int flag_set = 1;
 numeric = strtol(numericstr, ((void *)0), 10);
 if (!uplink || !port || !pass)
  do { logfmt(0x0001, "Fatal error at %s (line %d): %s\n", "src/net.c", 70, "Invalid uplink specified in configfile. Need [core.uplink] host, port, pass"); exit(1); } while (0);
 if (!servername || !descr || !numeric || !numeric)
  do { logfmt(0x0001, "Fatal error at %s (line %d): %s\n", "src/net.c", 73, "Invalid uplink specified in configfile. Need [core.server] numeric (1-4096), servername, descr"); exit(1); } while (0);
 if ((conn = socket(2, SOCK_STREAM, IPPROTO_TCP)) < 0)
  do { logfmt(0x0001, "POSIX error: %s", strerror((*__errno_location ()))); do { logfmt(0x0001, "Fatal error at %s (line %d): %s\n", "src/net.c", 76, "Could not create socket"); exit(1); } while (0); } while(0);
 hostname = gethostbyname(uplink);
 if (!hostname)
  do { logfmt(0x0001, "POSIX error: %s", strerror((*__errno_location ()))); do { logfmt(0x0001, "Fatal error at %s (line %d): %s\n", "src/net.c", 80, "Could not resolve hostname."); exit(1); } while (0); } while(0);
 ip_addr = *(struct in_addr *)(hostname->h_addr_list[0]);
 setsockopt(conn, IPPROTO_TCP, 1, &flag_set, sizeof(flag_set));
 memset(&server, 0, sizeof(server));
 server.sin_family = 2;
 server.sin_addr.s_addr = inet_addr(inet_ntoa(ip_addr));
 server.sin_port = htons(atoi(port));
 if (connect(conn, (struct sockaddr *) &server, sizeof(server)) < 0)
  do { logfmt(0x0001, "POSIX error: %s", strerror((*__errno_location ()))); do { logfmt(0x0001, "Fatal error at %s (line %d): %s\n", "src/net.c", 89, "Failed to connect to server"); exit(1); } while (0); } while(0);
 net_greet(pass, servername, numeric, descr);
}

variable_types:
uplink
char *

variable_types:
port
char *

variable_types:
numericstr
char *

variable_types:
servername
char *

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

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

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

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


decompiled_code:
void *net_read()
{
size_t v0; // rbx
int v1; // eax
ssize_t v3; // r12
size_t v4; // rcx
ssize_t v5; // rdx
const char *v6; // r12
char *v7; // rax
const char *v8; // rbx
char v9; // al
char v10; // al
const char *v11; // rdx
size_t v12; // rax
size_t v13; // rax
const char *v14; // r8
__int64 v15; // rcx
int *v16; // rax
char *v17; // rax
struct timeval v18; // [rsp+0h] [rbp-C8h] BYREF
fd_set readfds; // [rsp+10h] [rbp-B8h] BYREF
unsigned __int64 v20; // [rsp+98h] [rbp-30h]

v20 = __readfsqword(0x28u);
v18.tv_sec = 1LL;
v18.tv_usec = 0LL;
memset(&readfds, 0, sizeof(readfds));
readfds.fds_bits[conn / 64] |= 1LL << (conn % 64);
v0 = strlen(buf_0);
logfmt(0x2000LL, "---- Old (%d): '%s' ----\n", v0, buf_0);
logtxt(0x2000LL, "Reading/Waiting...");
v1 = select(conn + 1, &readfds, 0LL, 0LL, &v18);
if ( v1 <= 0 )
{
if ( !v1 )
return (void *)(v20 - __readfsqword(0x28u));
v16 = _errno_location();
v17 = strerror(*v16);
logfmt(1LL, "POSIX error: %s", v17);
v14 = "select() error";
v15 = 159LL;
LABEL_14:
logfmt(1LL, "Fatal error at %s (line %d): %s\n", "src/net.c", v15, v14);
exit(1);
}
v3 = read(conn, &buf_0[v0], 0xFFFF - v0);
logfmt(0x2000LL, "%d bytes...\n", v3);
if ( !v3 )
{
v14 = "EOF";
v15 = 165LL;
goto LABEL_14;
}
v4 = v0 + v3;
v5 = v3;
buf_0[v4] = 0;
v6 = buf_0;
logfmt(0x2000LL, "---- New (%d) buf[%d] ----\n", v5, v4);
logfmt(0x2000LL, "%s\n", &buf_0[v0]);
logtxt(0x2000LL, "------------------\n");
if ( buf_0[0] )
{
do
{
v7 = strpbrk(v6, "\r\n");
v8 = v7;
if ( !v7 )
break;
v9 = *v7;
if ( v9 == 10 || v9 == 13 )
{
do
{
do
{
v10 = *++v8;
*((_BYTE *)v8 - 1) = 0;
}
while ( v10 == 13 );
}
while ( v10 == 10 );
}
logfmt(1024LL, "<- %s\n", v6);
handle_input(v6);
logfmt(0x2000LL, "line = buf[%td], lineend = buf[%td]\n", v6 - buf_0, v8 - buf_0);
v11 = v6;
v6 = v8;
logfmt(0x2000LL, "line = '%s', lineend = '%s'\n", v11, v8);
}
while ( *v8 );
}
v12 = strlen(v6);
logfmt(
0x2000LL,
"---- NewOld (%zd): '%s' '%2X %2X %2X'----\n",
v12,
v6,
(unsigned __int8)v6[v12 - 3],
(unsigned __int8)v6[v12 - 2],
(unsigned __int8)v6[v12 - 1]);
v13 = strlen(v6);
return memmove(buf_0, v6, v13 + 1);
}

canonical_decompiled_code:
void *func6()
{
size_t v0; // rbx
int v1; // eax
ssize_t v3; // r12
size_t v4; // rcx
ssize_t v5; // rdx
const char *v6; // r12
char *v7; // rax
const char *v8; // rbx
char v9; // al
char v10; // al
const char *v11; // rdx
size_t v12; // rax
size_t v13; // rax
const char *v14; // r8
__int64 v15; // rcx
int *v16; // rax
char *v17; // rax
struct timeval v18; // [rsp+0h] [rbp-C8h] BYREF
fd_set readfds; // [rsp+10h] [rbp-B8h] BYREF
unsigned __int64 v20; // [rsp+98h] [rbp-30h]

v20 = __readfsqword(0x28u);
v18.tv_sec = 1LL;
v18.tv_usec = 0LL;
memset(&readfds, 0, sizeof(readfds));
readfds.fds_bits[conn / 64] |= 1LL << (conn % 64);
v0 = strlen(buf_0);
logfmt(0x2000LL, "---- Old (%d): '%s' ----\n", v0, buf_0);
logtxt(0x2000LL, "Reading/Waiting...");
v1 = select(conn + 1, &readfds, 0LL, 0LL, &v18);
if ( v1 <= 0 )
{
if ( !v1 )
return (void *)(v20 - __readfsqword(0x28u));
v16 = _errno_location();
v17 = strerror(*v16);
logfmt(1LL, "POSIX error: %s", v17);
v14 = "select() error";
v15 = 159LL;
LABEL_14:
logfmt(1LL, "Fatal error at %s (line %d): %s\n", "src/net.c", v15, v14);
exit(1);
}
v3 = read(conn, &buf_0[v0], 0xFFFF - v0);
logfmt(0x2000LL, "%d bytes...\n", v3);
if ( !v3 )
{
v14 = "EOF";
v15 = 165LL;
goto LABEL_14;
}
v4 = v0 + v3;
v5 = v3;
buf_0[v4] = 0;
v6 = buf_0;
logfmt(0x2000LL, "---- New (%d) buf[%d] ----\n", v5, v4);
logfmt(0x2000LL, "%s\n", &buf_0[v0]);
logtxt(0x2000LL, "------------------\n");
if ( buf_0[0] )
{
do
{
v7 = strpbrk(v6, "\r\n");
v8 = v7;
if ( !v7 )
break;
v9 = *v7;
if ( v9 == 10 || v9 == 13 )
{
do
{
do
{
v10 = *++v8;
*((_BYTE *)v8 - 1) = 0;
}
while ( v10 == 13 );
}
while ( v10 == 10 );
}
logfmt(1024LL, "<- %s\n", v6);
handle_input(v6);
logfmt(0x2000LL, "line = buf[%td], lineend = buf[%td]\n", v6 - buf_0, v8 - buf_0);
v11 = v6;
v6 = v8;
logfmt(0x2000LL, "line = '%s', lineend = '%s'\n", v11, v8);
}
while ( *v8 );
}
v12 = strlen(v6);
logfmt(
0x2000LL,
"---- NewOld (%zd): '%s' '%2X %2X %2X'----\n",
v12,
v6,
(unsigned __int8)v6[v12 - 3],
(unsigned __int8)v6[v12 - 2],
(unsigned __int8)v6[v12 - 1]);
v13 = strlen(v6);
return memmove(buf_0, v6, v13 + 1);
}

original_code:
void net_read(void) {
 static char buf[65536] = { 0 };
 ssize_t oldlen, r;
 char *line, *lineend;
 struct timeval tv = { 1, 0 };
 fd_set fds;
 do { int __d0, __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&fds)->__fds_bits)[0]) : "memory"); } while (0);
 ((void) (((&fds)->__fds_bits)[((conn) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((conn) % (8 * (int) sizeof (__fd_mask)))))));
 oldlen = strlen(buf);
 logfmt(0x2000, "---- Old (%d): '%s' ----\n", oldlen, buf);
 logtxt(0x2000, "Reading/Waiting...");
 r = select(conn+1, &fds, ((void *)0), ((void *)0), &tv);
 if (r <= 0) {
  if (r < 0)
   do { logfmt(0x0001, "POSIX error: %s", strerror((*__errno_location ()))); do { logfmt(0x0001, "Fatal error at %s (line %d): %s\n", "src/net.c", 159, "select() error"); exit(1); } while (0); } while(0);
  return;
 }
 r = read(conn, buf+oldlen, sizeof(buf)-oldlen-1);
 logfmt(0x2000, "%d bytes...\n", r);
 if (r == 0) {
  do { logfmt(0x0001, "Fatal error at %s (line %d): %s\n", "src/net.c", 165, "EOF"); exit(1); } while (0);
  return;
 }
 buf[oldlen+r] = '\0';
 logfmt(0x2000, "---- New (%d) buf[%d] ----\n", r, oldlen+r);
 logfmt(0x2000, "%s\n", buf+oldlen);
 logtxt(0x2000, "------------------\n");
 line = buf;
 while (*line && (lineend = strpbrk(line, "\r\n"))) {
  while (*lineend == '\r' || *lineend == '\n')
   *lineend++ = '\0';
  logfmt(0x0400, "<- %s\n", line);
  handle_input(line);
  logfmt(0x2000, "line = buf[%td], lineend = buf[%td]\n", line-buf, lineend-buf);
  logfmt(0x2000, "line = '%s', lineend = '%s'\n", line, lineend);
  line = lineend;
 }
 logfmt(0x2000, "---- NewOld (%zd): '%s' '%2X %2X %2X'----\n", strlen(line), line,
     (unsigned char)line[strlen(line)-3], (unsigned char)line[strlen(line)-2], (unsigned char)line[strlen(line)-1]);
 memmove(buf, line, strlen(line)+1);
}

canonical_original_code:
void net_read() {
 static char buf[65536] = { 0 };
 long oldlen; long r;
 char *line; char *lineend;
 struct timeval tv = { 1, 0 };
 struct fd_set fds;
 do { int __d0; int __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&fds)->__fds_bits)[0]) : "memory"); } while (0);
 ((void) (((&fds)->__fds_bits)[((conn) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((conn) % (8 * (int) sizeof (__fd_mask)))))));
 oldlen = strlen(buf);
 logfmt(0x2000, "---- Old (%d): '%s' ----\n", oldlen, buf);
 logtxt(0x2000, "Reading/Waiting...");
 r = select(conn+1, &fds, ((void *)0), ((void *)0), &tv);
 if (r <= 0) {
  if (r < 0)
   do { logfmt(0x0001, "POSIX error: %s", strerror((*__errno_location ()))); do { logfmt(0x0001, "Fatal error at %s (line %d): %s\n", "src/net.c", 159, "select() error"); exit(1); } while (0); } while(0);
  return;
 }
 r = read(conn, buf+oldlen, sizeof(buf)-oldlen-1);
 logfmt(0x2000, "%d bytes...\n", r);
 if (r == 0) {
  do { logfmt(0x0001, "Fatal error at %s (line %d): %s\n", "src/net.c", 165, "EOF"); exit(1); } while (0);
  return;
 }
 buf[oldlen+r] = '\0';
 logfmt(0x2000, "---- New (%d) buf[%d] ----\n", r, oldlen+r);
 logfmt(0x2000, "%s\n", buf+oldlen);
 logtxt(0x2000, "------------------\n");
 line = buf;
 while (*line && (lineend = strpbrk(line, "\r\n"))) {
  while (*lineend == '\r' || *lineend == '\n')
   *lineend++ = '\0';
  logfmt(0x0400, "<- %s\n", line);
  handle_input(line);
  logfmt(0x2000, "line = buf[%td], lineend = buf[%td]\n", line-buf, lineend-buf);
  logfmt(0x2000, "line = '%s', lineend = '%s'\n", line, lineend);
  line = lineend;
 }
 logfmt(0x2000, "---- NewOld (%zd): '%s' '%2X %2X %2X'----\n", strlen(line), line,
     (unsigned char)line[strlen(line)-3], (unsigned char)line[strlen(line)-2], (unsigned char)line[strlen(line)-1]);
 memmove(buf, line, strlen(line)+1);
}

variable_types:
buf
char [65536]

variable_types: oldlen long

variable_types: r long

variable_types:
line
char *

variable_types:
lineend
char *

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

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


decompiled_code:
__int64 __fastcall command_help(__int64 a1, __int64 a2, __int64 a3)
{
__int64 v3; // r12
const char **v4; // rbp
int i; // ebx
const char *v7; // r13
const char *v8; // rax
const char **v9; // rbx

v3 = a1 + 16;
if ( *(_BYTE *)a3 == 1 )
{
module_notice(bot, a1 + 16, "Usage: HELP <command>");
module_notice(bot, v3, "Shows help such as syntax and descriptions for commands.");
}
else
{
v4 = (const char **)&commands;
for ( i = 0; i != 32; ++i )
{
if ( *v4 )
{
v7 = *(const char **)(a3 + 16);
if ( !strcasecmp(*v4, v7) )
{
v8 = (const char *)strconv(&toupper, 0LL, 0LL, v7);
module_notice(bot, v3, "Showing help for command %s", v8);
v9 = (const char **)((char *)&commands + 32 * i);
module_notice(bot, v3, "Usage: %s", v9[1]);
module_notice(bot, v3, "%s", v9[2]);
return 0LL;
}
}
v4 += 4;
}
module_notice(bot, v3, "No help available for %s.", *(const char **)(a3 + 8));
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 a2, __int64 a3)
{
__int64 v3; // r12
const char **v4; // rbp
int i; // ebx
const char *v7; // r13
const char *v8; // rax
const char **v9; // rbx

v3 = a1 + 16;
if ( *(_BYTE *)a3 == 1 )
{
module_notice(bot, a1 + 16, "Usage: HELP <command>");
module_notice(bot, v3, "Shows help such as syntax and descriptions for commands.");
}
else
{
v4 = (const char **)&commands;
for ( i = 0; i != 32; ++i )
{
if ( *v4 )
{
v7 = *(const char **)(a3 + 16);
if ( !strcasecmp(*v4, v7) )
{
v8 = (const char *)strconv(&toupper, 0LL, 0LL, v7);
module_notice(bot, v3, "Showing help for command %s", v8);
v9 = (const char **)((char *)&commands + 32 * i);
module_notice(bot, v3, "Usage: %s", v9[1]);
module_notice(bot, v3, "%s", v9[2]);
return 0LL;
}
}
v4 += 4;
}
module_notice(bot, v3, "No help available for %s.", *(const char **)(a3 + 8));
}
return 0LL;
}

original_code:
int command_help (struct user *from, struct user *to, struct manyargs *args) {
 if (args->c == 1) {
  module_notice(bot, from->numericstr, "Usage: HELP <command>");
  module_notice(bot, from->numericstr, "Shows help such as syntax and descriptions for commands.");
  return 0;
 }
 for (int x = 0; x<32; x++) {
  if (commands[x].trigger != ((void *)0) && !strcasecmp(commands[x].trigger, args->v[1])) {
   module_notice(bot, from->numericstr, "Showing help for command %s", strconv(toupper, ((void *)0), 0, args->v[1]));
   module_notice(bot, from->numericstr, "Usage: %s", commands[x].syntax);
   module_notice(bot, from->numericstr, "%s", commands[x].description);
   return 0;
  }
 }
 module_notice(bot, from->numericstr, "No help available for %s.", args->v[0]);
 return 0;
}

canonical_original_code:
int command_help(struct user *from, struct user *to, struct manyargs *args) {
 if (args->c == 1) {
  module_notice(bot, from->numericstr, "Usage: HELP <command>");
  module_notice(bot, from->numericstr, "Shows help such as syntax and descriptions for commands.");
  return 0;
 }
 for (int x = 0; x<32; x++) {
  if (commands[x].trigger != ((void *)0) && !strcasecmp(commands[x].trigger, args->v[1])) {
   module_notice(bot, from->numericstr, "Showing help for command %s", strconv(toupper, ((void *)0), 0, args->v[1]));
   module_notice(bot, from->numericstr, "Usage: %s", commands[x].syntax);
   module_notice(bot, from->numericstr, "%s", commands[x].description);
   return 0;
  }
 }
 module_notice(bot, from->numericstr, "No help available for %s.", args->v[0]);
 return 0;
}

variable_types: struct user { unsigned int magic; unsigned long numeric; char numericstr[-1]; char nick[-1]; char user[-1]; char host[-1]; char fakehost[-1]; char opername[-1]; char account[-1]; long acctime; long accid; char realname[-1]; int hops; unsigned int accountid; char awaymsg[-1]; unsigned long mode; int channelcount; struct jtableP { void *t; } channels; struct server { unsigned int magic; unsigned long numeric; unsigned long lastnumeric; char numericstr[-1]; char name[-1]; unsigned long maxusers; int hops; long boot; long link; char protocol[4]; char description[-1]; struct jtableP users; unsigned long mode; } *server; } *

variable_types:
to
struct user *

variable_types: struct manyargs { unsigned char c; char *v[256]; } *

variable_types: x int

return_type: int

user_defined_types: struct user { unsigned int magic; unsigned long numeric; char numericstr[-1]; char nick[-1]; char user[-1]; char host[-1]; char fakehost[-1]; char opername[-1]; char account[-1]; long acctime; long accid; char realname[-1]; int hops; unsigned int accountid; char awaymsg[-1]; unsigned long mode; int channelcount; struct jtableP channels; struct server *server; }


child

decompiled_code:
__int64 __fastcall child(int a1)
{
return (unsigned int)(2 * a1);
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1)
{
return (unsigned int)(2 * a1);
}

original_code:
uint16_t child(uint16_t p) {
 return p << 1;
}

canonical_original_code:
unsigned short child(unsigned short p) {
 return p << 1;
}

variable_types:
p
unsigned short

return_type: unsigned short


pop

original_code:
void pop(struct heap *heap, struct tbl *tbl, struct maze *maze) {
 heap->h[0] = heap->h[1];
 uint16_t p = 1;
 uint16_t c = 2;
 uint16_t c_min = 1;
 while (c + 1 <= heap->n_heap) {
  c_min = ((heap->h[c])->time < (heap->h[c + 1])->time) ? c : c + 1;
  heap->h[p] = heap->h[c_min];
  p = c_min;
  c = child(p);
 }
 heap->h[c_min] = heap->h[heap->n_heap--];
 return;
}

canonical_original_code:
void pop(struct heap *heap, struct tbl *tbl, struct maze *maze) {
 heap->h[0] = heap->h[1];
 unsigned short p = 1;
 unsigned short c = 2;
 unsigned short c_min = 1;
 while (c + 1 <= heap->n_heap) {
  c_min = ((heap->h[c])->time < (heap->h[c + 1])->time) ? c : c + 1;
  heap->h[p] = heap->h[c_min];
  p = c_min;
  c = child(p);
 }
 heap->h[c_min] = heap->h[heap->n_heap--];
 return;
}

variable_types: struct heap { struct node { unsigned short time; unsigned short id; unsigned short pre; struct node *nxt_in_tbl; } *h[258]; unsigned short n_heap; } *

variable_types: struct tbl { struct node *t[-1]; unsigned short n_tbl; } *

variable_types: struct maze { unsigned short start_id; unsigned short end_id; struct square { _Bool w[4]; } *m; } *

variable_types:
c
unsigned short

user_defined_types: struct heap { struct node *h[258]; unsigned short n_heap; }

user_defined_types: struct maze { unsigned short start_id; unsigned short end_id; struct square *m; }


decompiled_code:
__int64 __fastcall time_straight(int a1)
{
return (unsigned int)(2 * a1 + 1);
}

canonical_decompiled_code:
__int64 __fastcall func2(int a1)
{
return (unsigned int)(2 * a1 + 1);
}

original_code:
uint16_t time_straight(uint16_t n, struct node *p, struct node nb) {
 return (1 + (2 * n));
}

canonical_original_code:
unsigned short time_straight(unsigned short n, struct node *p, struct node nb) {
 return (1 + (2 * n));
}

variable_types:
n
unsigned short

variable_types: struct node { unsigned short time; unsigned short id; unsigned short pre; struct node *nxt_in_tbl; } *

variable_types:
nb
struct node


decompiled_code:
__int64 __fastcall just_ahead(unsigned int a1, char a2)
{
__int64 result; // rax

result = a1;
if ( (unsigned __int16)a1 <= 0x18u )
{
switch ( a2 )
{
case 0:
case 6:
result = a1 - 3;
break;
case 1:
result = a1 - 12;
if ( (unsigned __int16)a1 <= 0xCu )
result = a1 + 14;
break;
case 2:
case 4:
result = a1 + 3;
break;
case 3:
result = a1 - 9;
if ( (unsigned __int16)a1 <= 0xCu )
result = a1 + 15;
break;
case 5:
result = a1 - 10;
if ( (unsigned __int16)a1 <= 0xCu )
result = a1 + 12;
break;
case 7:
result = a1 - 13;
if ( (unsigned __int16)a1 <= 0xCu )
result = a1 + 9;
break;
default:
JUMPOUT(0x71BLL);
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(unsigned int a1, char a2)
{
__int64 result; // rax

result = a1;
if ( (unsigned __int16)a1 <= 0x18u )
{
switch ( a2 )
{
case 0:
case 6:
result = a1 - 3;
break;
case 1:
result = a1 - 12;
if ( (unsigned __int16)a1 <= 0xCu )
result = a1 + 14;
break;
case 2:
case 4:
result = a1 + 3;
break;
case 3:
result = a1 - 9;
if ( (unsigned __int16)a1 <= 0xCu )
result = a1 + 15;
break;
case 5:
result = a1 - 10;
if ( (unsigned __int16)a1 <= 0xCu )
result = a1 + 12;
break;
case 7:
result = a1 - 13;
if ( (unsigned __int16)a1 <= 0xCu )
result = a1 + 9;
break;
default:
JUMPOUT(0x71BLL);
}
}
return result;
}

original_code:
uint16_t just_ahead(uint16_t id, uint8_t dir) {
 if (id > 2*4*(4 -1))
  return id;
 _Bool vertical = (id <= 4*(4 -1));
 switch (dir) {
  case 0:
   return (id - (4 -1));
  case 4:
   return (id + 4 -1);
  case 2:
   return (id + 4 -1);
  case 6:
   return (id - (4 -1));
  case 1:
   if (vertical)
    return ((id + 4*(4 -1)) + 4 -2);
   else
    return (id - 4*(4 -1));
  case 3:
   if (vertical)
    return ((id + 4*(4 -1)) + 4 -1);
   else
    return ((id - 4*(4 -1)) + 4 -1);
  case 5:
   if (vertical)
    return (id + 4*(4 -1));
   else
    return ((id - 4*(4 -1)) + 4 -2);
  case 7:
   if (vertical)
    return ((id + 4*(4 -1)) - (4 -1));
   else
    return ((id - 4*(4 -1)) - 1);
  default:
   return 0xffff;
 }
}

canonical_original_code:
unsigned short just_ahead(unsigned short id, unsigned char dir) {
 if (id > 2*4*(4 -1))
  return id;
 _Bool vertical = (id <= 4*(4 -1));
 switch (dir) {
  case 0:
   return (id - (4 -1));
  case 4:
   return (id + 4 -1);
  case 2:
   return (id + 4 -1);
  case 6:
   return (id - (4 -1));
  case 1:
   if (vertical)
    return ((id + 4*(4 -1)) + 4 -2);
   else
    return (id - 4*(4 -1));
  case 3:
   if (vertical)
    return ((id + 4*(4 -1)) + 4 -1);
   else
    return ((id - 4*(4 -1)) + 4 -1);
  case 5:
   if (vertical)
    return (id + 4*(4 -1));
   else
    return ((id - 4*(4 -1)) + 4 -2);
  case 7:
   if (vertical)
    return ((id + 4*(4 -1)) - (4 -1));
   else
    return ((id - 4*(4 -1)) - 1);
  default:
   return 0xffff;
 }
}

variable_types:
id
unsigned short

variable_types:
dir
unsigned char


decompiled_code:
__int64 __fastcall node_at(unsigned __int16 a1, __int64 a2)
{
__int64 result; // rax
int v3; // edx
int v4; // eax

result = 0LL;
if ( a1 <= 0x18u )
{
v3 = a1 & 3;
v4 = a1 >> 2;
if ( a1 <= 0xCu )
result = *(unsigned __int8 *)(a2 + 4LL * (v3 + 4 * v4) + 1);
else
result = *(unsigned __int8 *)(a2 + 4LL * (v4 + 4 * v3) + 2);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(unsigned __int16 a1, __int64 a2)
{
__int64 result; // rax
int v3; // edx
int v4; // eax

result = 0LL;
if ( a1 <= 0x18u )
{
v3 = a1 & 3;
v4 = a1 >> 2;
if ( a1 <= 0xCu )
result = *(unsigned __int8 *)(a2 + 4LL * (v3 + 4 * v4) + 1);
else
result = *(unsigned __int8 *)(a2 + 4LL * (v4 + 4 * v3) + 2);
}
return result;
}

original_code:
_Bool node_at(uint16_t id, struct square *m) {
 if (id > 2*4*(4 -1))
  return 0;
 uint8_t i,j;
 if (id <= 4*(4 -1)) {
  i = id / 4;
  j = id % 4;
  return m[ 4 * i + j].w[1];
 }
 j = id / 4;
 i = id % 4;
 return m[ 4 * i + j].w[2];
}

canonical_original_code:
_Bool node_at(unsigned short id, struct square *m) {
 if (id > 2*4*(4 -1))
  return 0;
 unsigned char i; unsigned char j;
 if (id <= 4*(4 -1)) {
  i = id / 4;
  j = id % 4;
  return m[ 4 * i + j].w[1];
 }
 j = id / 4;
 i = id % 4;
 return m[ 4 * i + j].w[2];
}

variable_types:
m
struct square { _Bool w[4]; } *

variable_types:
i
unsigned char

variable_types:
j
unsigned char


hash

decompiled_code:
__int64 __fastcall hash(__int64 a1, __int64 a2)
{
__int64 v2; // r12
__int64 v3; // rsi

printf("hash: nd->id=%u\n", *(_WORD *)(a1 + 2) % 6u);
v2 = *(_QWORD *)(a2 + 8LL * (*(_WORD *)(a1 + 2) % 6u));
printf("nxt_in_tbl=NULL? %d\n", *(_QWORD *)(v2 + 8) == 0LL);
v3 = *(unsigned __int16 *)(a1 + 2);
while ( *(_WORD *)(v2 + 2) != (_WORD)v3 )
{
v2 = *(_QWORD *)(v2 + 8);
if ( !v2 )
{
puts("hash: returning NULL");
return 0LL;
}
}
printf("hash: returned p->id= %u\n", v3);
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, __int64 a2)
{
__int64 v2; // r12
__int64 v3; // rsi

printf("hash: nd->id=%u\n", *(_WORD *)(a1 + 2) % 6u);
v2 = *(_QWORD *)(a2 + 8LL * (*(_WORD *)(a1 + 2) % 6u));
printf("nxt_in_tbl=NULL? %d\n", *(_QWORD *)(v2 + 8) == 0LL);
v3 = *(unsigned __int16 *)(a1 + 2);
while ( *(_WORD *)(v2 + 2) != (_WORD)v3 )
{
v2 = *(_QWORD *)(v2 + 8);
if ( !v2 )
{
puts("hash: returning NULL");
return 0LL;
}
}
printf("hash: returned p->id= %u\n", v3);
return v2;
}

original_code:
struct node* hash(struct node *nd, struct tbl *tbl) {
 struct node *p;
 printf("hash: nd->id=%u\n",nd->id % (4 * (4 - 1) / 2));
    p = tbl->t[nd->id % (4 * (4 - 1) / 2)];
 printf("nxt_in_tbl=NULL? %d\n",(p->nxt_in_tbl==((void *)0)) ? 1:0);
 while (p != ((void *)0)) {
  if (p->id == nd->id) break;
  else p = p->nxt_in_tbl;
 }
 if (p != ((void *)0))
  printf("hash: returned p->id= %u\n",p->id);
 else
  printf("hash: returning NULL\n");
 return p;
}

canonical_original_code:
struct node *hash(struct node *nd, struct tbl *tbl) {
 struct node *p;
 printf("hash: nd->id=%u\n",nd->id % (4 * (4 - 1) / 2));
    p = tbl->t[nd->id % (4 * (4 - 1) / 2)];
 printf("nxt_in_tbl=NULL? %d\n",(p->nxt_in_tbl==((void *)0)) ? 1:0);
 while (p != ((void *)0)) {
  if (p->id == nd->id) break;
  else p = p->nxt_in_tbl;
 }
 if (p != ((void *)0))
  printf("hash: returned p->id= %u\n",p->id);
 else
  printf("hash: returning NULL\n");
 return p;
}

variable_types:
nd
struct node *

return_type: struct node { unsigned short time; unsigned short id; unsigned short pre; struct node *nxt_in_tbl; } *

user_defined_types: struct tbl { struct node *t[-1]; unsigned short n_tbl; }


original_code:
void update_tbl(struct nbhs *nbhs, struct tbl *tbl) {
 uint16_t k;
 struct node *c;
 _Bool added = 0;
 for (uint8_t i = 1; i <= nbhs->n_nbhs; ++i) {
  k = nbhs->n[i].id % (4 * (4 - 1) / 2);
  printf("update_tbl: index = %u\n",k);
  c = tbl->t[k];
  if (c == ((void *)0)) {
   c = malloc(sizeof(struct node));
   c->id = nbhs->n[i].id;
   c->time = nbhs->n[i].time;
   c->pre = nbhs->n[0].id;
   c->nxt_in_tbl = ((void *)0);
   tbl->t[k] = c;
  }
  while (c != ((void *)0)) {
   if (c->id == nbhs->n[i].id) {
    if (nbhs->n[i].time < c->time) {
     c->time = nbhs->n[i].time;
     c->pre = nbhs->n[0].id;
    }
    added = 1;
    break;
   }
   if (c->nxt_in_tbl == ((void *)0)) break;
   else c = c->nxt_in_tbl;
  }
  if (!added && c->nxt_in_tbl == ((void *)0)) {
   c->nxt_in_tbl = malloc(sizeof(struct node));
   c = c->nxt_in_tbl;
   c->id = nbhs->n[i].id;
   c->time = nbhs->n[i].time;
   c->pre = nbhs->n[0].id;
   c->nxt_in_tbl = ((void *)0);
  }
 }
 return;
}

canonical_original_code:
void update_tbl(struct nbhs *nbhs, struct tbl *tbl) {
 unsigned short k;
 struct node *c;
 _Bool added = 0;
 for (unsigned char i = 1; i <= nbhs->n_nbhs; ++i) {
  k = nbhs->n[i].id % (4 * (4 - 1) / 2);
  printf("update_tbl: index = %u\n",k);
  c = tbl->t[k];
  if (c == ((void *)0)) {
   c = malloc(sizeof(struct node));
   c->id = nbhs->n[i].id;
   c->time = nbhs->n[i].time;
   c->pre = nbhs->n[0].id;
   c->nxt_in_tbl = ((void *)0);
   tbl->t[k] = c;
  }
  while (c != ((void *)0)) {
   if (c->id == nbhs->n[i].id) {
    if (nbhs->n[i].time < c->time) {
     c->time = nbhs->n[i].time;
     c->pre = nbhs->n[0].id;
    }
    added = 1;
    break;
   }
   if (c->nxt_in_tbl == ((void *)0)) break;
   else c = c->nxt_in_tbl;
  }
  if (!added && c->nxt_in_tbl == ((void *)0)) {
   c->nxt_in_tbl = malloc(sizeof(struct node));
   c = c->nxt_in_tbl;
   c->id = nbhs->n[i].id;
   c->time = nbhs->n[i].time;
   c->pre = nbhs->n[0].id;
   c->nxt_in_tbl = ((void *)0);
  }
 }
 return;
}

variable_types: struct nbhs { struct node { unsigned short time; unsigned short id; unsigned short pre; struct node *nxt_in_tbl; } n[-1]; unsigned short n_nbhs; } *

variable_types:
k
unsigned short

user_defined_types: struct nbhs { struct node n[-1]; unsigned short n_nbhs; }


parent

decompiled_code:
__int16 __fastcall parent(unsigned __int16 a1)
{
__int16 result; // ax

result = a1 >> 1;
if ( a1 == 1 )
result = 1;
return result;
}

canonical_decompiled_code:
__int16 __fastcall func8(unsigned __int16 a1)
{
__int16 result; // ax

result = a1 >> 1;
if ( a1 == 1 )
result = 1;
return result;
}

canonical_original_code:
unsigned short parent(unsigned short c) {
 return ((c == 1) ? 1 : (c >> 1));
}


original_code:
void update_heap(struct nbhs *nbhs, struct heap *heap, struct maze *maze, struct tbl *tbl) {
 uint16_t nc, np;
 struct node *temp;
 for (int8_t i = 1; i <= nbhs->n_nbhs; ++i) {
  nc = ++heap->n_heap;
  heap->h[nc] = hash(&(nbhs->n[i]),tbl);
  if (heap->h[nc] != ((void *)0))
   printf("hash: returned p->id= %u\n",heap->h[nc]->id);
  else
   printf("hash: returning NULL\n");
  np = parent(nc);
  while (heap->h[np]->time > heap->h[nc]->time) {
   temp = heap->h[np];
   heap->h[np] = heap->h[nc];
   heap->h[nc] = temp;
   nc = np;
   np = parent(nc);
  }
  if (heap->n_heap == 258)
   --heap->n_heap;
 }
 return;
}

canonical_original_code:
void update_heap(struct nbhs *nbhs, struct heap *heap, struct maze *maze, struct tbl *tbl) {
 unsigned short nc; unsigned short np;
 struct node *temp;
 for (char i = 1; i <= nbhs->n_nbhs; ++i) {
  nc = ++heap->n_heap;
  heap->h[nc] = hash(&(nbhs->n[i]),tbl);
  if (heap->h[nc] != ((void *)0))
   printf("hash: returned p->id= %u\n",heap->h[nc]->id);
  else
   printf("hash: returning NULL\n");
  np = parent(nc);
  while (heap->h[np]->time > heap->h[nc]->time) {
   temp = heap->h[np];
   heap->h[np] = heap->h[nc];
   heap->h[nc] = temp;
   nc = np;
   np = parent(nc);
  }
  if (heap->n_heap == 258)
   --heap->n_heap;
 }
 return;
}

variable_types: struct heap { struct node *h[258]; unsigned short n_heap; } *

variable_types:
nc
unsigned short

variable_types:
np
unsigned short

variable_types: i char

user_defined_types: struct node { unsigned short time; unsigned short id; unsigned short pre; struct node *nxt_in_tbl; }


original_code:
void fastest_path(struct maze *maze, struct tbl *tbl) {
 tbl->n_tbl = 0;
 for (uint16_t i = 0; i < (4 * (4 - 1) / 2); ++i)
  tbl->t[i] = ((void *)0);
 struct heap *heap = malloc(sizeof(struct heap));
 struct nbhs *nbhs = malloc(sizeof(struct nbhs));
 nbhs->n_nbhs = 1;
 nbhs->n[0].id = 0xffff;
 nbhs->n[0].time = 87;
 nbhs->n[1].id = maze->start_id;
 nbhs->n[1].time = 0;
 update_tbl(nbhs,tbl);
 heap->h[1] = hash(&(nbhs->n[1]),tbl);
 heap->n_heap = 1;
 do {
  pop(heap,tbl,maze);
  get_nbhs(heap->h[0],nbhs,maze);
  printf("nnb=%u\n",nbhs->n_nbhs);
  update_tbl(nbhs,tbl);
  update_heap(nbhs,heap,maze,tbl);
  printf("nhp=%u\n",heap->n_heap);
 } while (heap->h[0]->id != maze->end_id);
 free(heap);
 free(nbhs);
 return;
}

canonical_original_code:
void fastest_path(struct maze *maze, struct tbl *tbl) {
 tbl->n_tbl = 0;
 for (unsigned short i = 0; i < (4 * (4 - 1) / 2); ++i)
  tbl->t[i] = ((void *)0);
 struct heap *heap = malloc(sizeof(struct heap));
 struct nbhs *nbhs = malloc(sizeof(struct nbhs));
 nbhs->n_nbhs = 1;
 nbhs->n[0].id = 0xffff;
 nbhs->n[0].time = 87;
 nbhs->n[1].id = maze->start_id;
 nbhs->n[1].time = 0;
 update_tbl(nbhs,tbl);
 heap->h[1] = hash(&(nbhs->n[1]),tbl);
 heap->n_heap = 1;
 do {
  pop(heap,tbl,maze);
  get_nbhs(heap->h[0],nbhs,maze);
  printf("nnb=%u\n",nbhs->n_nbhs);
  update_tbl(nbhs,tbl);
  update_heap(nbhs,heap,maze,tbl);
  printf("nhp=%u\n",heap->n_heap);
 } while (heap->h[0]->id != maze->end_id);
 free(heap);
 free(nbhs);
 return;
}

variable_types: struct maze { unsigned short start_id; unsigned short end_id; struct square { _Bool w[4]; } *m; } *

variable_types: struct tbl { struct node { unsigned short time; unsigned short id; unsigned short pre; struct node *nxt_in_tbl; } *t[-1]; unsigned short n_tbl; } *

variable_types:
i
unsigned short

variable_types: struct heap { struct node { unsigned short time; unsigned short id; unsigned short pre; struct node *nxt_in_tbl; } *h[258]; unsigned short n_heap; } *


decompiled_code:
__int64 __fastcall id_to_draw_pos(unsigned __int16 a1)
{
unsigned __int8 v1; // cl

if ( a1 > 0xCu )
v1 = 2 * (a1 % 3u);
else
v1 = 2 * (a1 / 3u) + 1;
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned __int16 a1)
{
unsigned __int8 v1; // cl

if ( a1 > 0xCu )
v1 = 2 * (a1 % 3u);
else
v1 = 2 * (a1 / 3u) + 1;
return v1;
}

original_code:
struct pos id_to_draw_pos(uint16_t id) {
 struct pos ij;
 uint8_t row,col;
 if (id <= 4 * (4 - 1)) {
  row = id / (4 - 1);
  col = id % (4 - 1);
  ij.i = 2 * row + 1;
  ij.j = 3 * col;
 } else {
  col = id / (4 - 1);
  row = id % (4 - 1);
  ij.i = 2 * row;
  ij.j = 3 * col + 1;
 }
 return ij;
}

canonical_original_code:
struct pos id_to_draw_pos(unsigned short id) {
 struct pos ij;
 unsigned char row; unsigned char col;
 if (id <= 4 * (4 - 1)) {
  row = id / (4 - 1);
  col = id % (4 - 1);
  ij.i = 2 * row + 1;
  ij.j = 3 * col;
 } else {
  col = id / (4 - 1);
  row = id % (4 - 1);
  ij.i = 2 * row;
  ij.j = 3 * col + 1;
 }
 return ij;
}

variable_types: struct pos { unsigned char i; unsigned char j; }

variable_types:
row
unsigned char

variable_types:
col
unsigned char


draw

original_code:
void draw(struct square *m, struct tbl *tbl, struct maze *maze)
{
 initscr();
 int i = 0, j = 0;
 int row = 0, col = 0;
 while(row < 4) {
  while(col < 4) {
   mvprintw(i,j++,"%s","+");
   if (m[row * 4 + col].w[0]) {
    mvprintw(i,j,"%s","--");
    j += 2;
   } else {
    mvprintw(i,j,"%s","  ");
    j += 2;
   }
   ++col;
  }
  mvprintw(i,j++,"%s","+");
  col = 0;
  ++i;
  j = 0;
  while(col < 4) {
   if (m[row * 4 + col].w[3])
    mvprintw(i,j++,"%s","|");
   else
    mvprintw(i,j++,"%s"," ");
   mvprintw(i,j,"%s","  ");
   j += 2;
   ++col;
  }
  if (col == 4)
   mvprintw(i,j++,"%s","|");
  col = 0;
  ++i;
  j = 0;
  ++row;
 }
 while (col < 4) {
  mvprintw(i,j++,"%s","+");
  mvprintw(i,j,"%s","--");
  j += 2;
  ++col;
 }
 mvprintw(i,j,"%s","+");
 struct pos ij;
 struct node *nb = malloc(sizeof(struct node));
 nb->pre = maze->end_id;
 do {
  nb->id = nb->pre;
  nb = hash(nb, tbl);
  ij = id_to_draw_pos(nb->id);
  if (nb->id > 4*(4 -1))
   mvprintw(ij.i,ij.j,"%s","* ");
  else
   mvprintw(ij.i,ij.j,"%s","*");
 } while (nb->id != maze->start_id);
 wrefresh(stdscr);
 char c = wgetch(stdscr);
 if (c == 'q')
  endwin();
 free(nb);
 return;
}

canonical_original_code:
void draw(struct square *m, struct tbl *tbl, struct maze *maze)
{
 initscr();
 int i = 0; int j = 0;
 int row = 0; int col = 0;
 while(row < 4) {
  while(col < 4) {
   mvprintw(i,j++,"%s","+");
   if (m[row * 4 + col].w[0]) {
    mvprintw(i,j,"%s","--");
    j += 2;
   } else {
    mvprintw(i,j,"%s","  ");
    j += 2;
   }
   ++col;
  }
  mvprintw(i,j++,"%s","+");
  col = 0;
  ++i;
  j = 0;
  while(col < 4) {
   if (m[row * 4 + col].w[3])
    mvprintw(i,j++,"%s","|");
   else
    mvprintw(i,j++,"%s"," ");
   mvprintw(i,j,"%s","  ");
   j += 2;
   ++col;
  }
  if (col == 4)
   mvprintw(i,j++,"%s","|");
  col = 0;
  ++i;
  j = 0;
  ++row;
 }
 while (col < 4) {
  mvprintw(i,j++,"%s","+");
  mvprintw(i,j,"%s","--");
  j += 2;
  ++col;
 }
 mvprintw(i,j,"%s","+");
 struct pos ij;
 struct node *nb = malloc(sizeof(struct node));
 nb->pre = maze->end_id;
 do {
  nb->id = nb->pre;
  nb = hash(nb, tbl);
  ij = id_to_draw_pos(nb->id);
  if (nb->id > 4*(4 -1))
   mvprintw(ij.i,ij.j,"%s","* ");
  else
   mvprintw(ij.i,ij.j,"%s","*");
 } while (nb->id != maze->start_id);
 wrefresh(stdscr);
 char c = wgetch(stdscr);
 if (c == 'q')
  endwin();
 free(nb);
 return;
}

variable_types:
m
struct square { _Bool w[4]; } *

variable_types: struct maze { unsigned short start_id; unsigned short end_id; struct square *m; } *

variable_types: i int

variable_types: j int

variable_types: row int

variable_types: col int

variable_types: struct node { unsigned short time; unsigned short id; unsigned short pre; struct node *nxt_in_tbl; } *

variable_types: c char

user_defined_types: struct pos { unsigned char i; unsigned char j; }


decompiled_code:
__int64 __fastcall set_top_wall(__int64 *a1, char a2, unsigned __int8 a3, unsigned __int8 a4)
{
__int64 v5; // rsi
int v6; // edx
_BYTE *v7; // rdi
__int64 result; // rax

v5 = *a1;
v6 = 4 * a3;
v7 = (_BYTE *)(*a1 + 4LL * (v6 + a4));
result = v5 + 4LL * (v6 + a4 - 4);
if ( a2 )
{
*v7 = 1;
*(_BYTE *)(result + 2) = 1;
}
else
{
*v7 = 0;
*(_BYTE *)(result + 2) = 0;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 *a1, char a2, unsigned __int8 a3, unsigned __int8 a4)
{
__int64 v5; // rsi
int v6; // edx
_BYTE *v7; // rdi
__int64 result; // rax

v5 = *a1;
v6 = 4 * a3;
v7 = (_BYTE *)(*a1 + 4LL * (v6 + a4));
result = v5 + 4LL * (v6 + a4 - 4);
if ( a2 )
{
*v7 = 1;
*(_BYTE *)(result + 2) = 1;
}
else
{
*v7 = 0;
*(_BYTE *)(result + 2) = 0;
}
return result;
}

original_code:
void set_top_wall(struct submaze *s, uint8_t build, uint8_t row, uint8_t col)
{
 if (build) {
  s->m[row * 4 + col].w[0] = 1;
  s->m[(row-1) * 4 + col].w[2] = 1;
 } else {
  s->m[row * 4 + col].w[0] = 0;
  s->m[(row - 1) * 4 + col].w[2] = 0;
 }
}

canonical_original_code:
void set_top_wall(struct submaze *s, unsigned char build, unsigned char row, unsigned char col)
{
 if (build) {
  s->m[row * 4 + col].w[0] = 1;
  s->m[(row-1) * 4 + col].w[2] = 1;
 } else {
  s->m[row * 4 + col].w[0] = 0;
  s->m[(row - 1) * 4 + col].w[2] = 0;
 }
}

variable_types: struct submaze { struct square { _Bool w[4]; } *m; unsigned char i; unsigned char j; unsigned char r; unsigned char c; } *

variable_types:
build
unsigned char

user_defined_types: struct submaze { struct square *m; unsigned char i; unsigned char j; unsigned char r; unsigned char c; }


decompiled_code:
__int64 __fastcall set_left_wall(__int64 *a1, char a2, unsigned __int8 a3, unsigned __int8 a4)
{
__int64 v5; // rsi
int v6; // edx
__int64 v7; // rdi
__int64 result; // rax

v5 = *a1;
v6 = 4 * a3;
v7 = *a1 + 4LL * (v6 + a4);
result = v5 + 4LL * (v6 + a4 - 1);
if ( a2 )
{
*(_BYTE *)(v7 + 3) = 1;
*(_BYTE *)(result + 1) = 1;
}
else
{
*(_BYTE *)(v7 + 3) = 0;
*(_BYTE *)(result + 1) = 0;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 *a1, char a2, unsigned __int8 a3, unsigned __int8 a4)
{
__int64 v5; // rsi
int v6; // edx
__int64 v7; // rdi
__int64 result; // rax

v5 = *a1;
v6 = 4 * a3;
v7 = *a1 + 4LL * (v6 + a4);
result = v5 + 4LL * (v6 + a4 - 1);
if ( a2 )
{
*(_BYTE *)(v7 + 3) = 1;
*(_BYTE *)(result + 1) = 1;
}
else
{
*(_BYTE *)(v7 + 3) = 0;
*(_BYTE *)(result + 1) = 0;
}
return result;
}

original_code:
void set_left_wall(struct submaze *s, uint8_t build, uint8_t row, uint8_t col)
{
 if (build) {
  s->m[row * 4 + col].w[3] = 1;
  s->m[row * 4 + (col - 1)].w[1] = 1;
 } else {
  s->m[row * 4 + col].w[3] = 0;
  s->m[row * 4 + (col - 1)].w[1] = 0;
 }
}

canonical_original_code:
void set_left_wall(struct submaze *s, unsigned char build, unsigned char row, unsigned char col)
{
 if (build) {
  s->m[row * 4 + col].w[3] = 1;
  s->m[row * 4 + (col - 1)].w[1] = 1;
 } else {
  s->m[row * 4 + col].w[3] = 0;
  s->m[row * 4 + (col - 1)].w[1] = 0;
 }
}


original_code:
void new_submaze(struct submaze *t, struct submaze *s, uint8_t vcut, uint8_t hcut)
{
 for (int i = 0; i < 4; ++i)
  t[i] = *s;
 t[0].c = vcut - s->j - 1;
 t[0].r = hcut - s->i - 1;
 t[1].j = vcut;
 t[1].c = s->j + s->c - vcut;
 t[1].r = hcut - s->i - 1;
 t[2].i = hcut;
 t[2].c = vcut - s->j - 1;
 t[2].r = s->i + s->r - hcut;
 t[3].i = hcut;
 t[3].j = vcut;
 t[3].r = s->i + s->r - hcut;
 t[3].c = s->j + s->c - vcut;
}

canonical_original_code:
void new_submaze(struct submaze *t, struct submaze *s, unsigned char vcut, unsigned char hcut)
{
 for (int i = 0; i < 4; ++i)
  t[i] = *s;
 t[0].c = vcut - s->j - 1;
 t[0].r = hcut - s->i - 1;
 t[1].j = vcut;
 t[1].c = s->j + s->c - vcut;
 t[1].r = hcut - s->i - 1;
 t[2].i = hcut;
 t[2].c = vcut - s->j - 1;
 t[2].r = s->i + s->r - hcut;
 t[3].i = hcut;
 t[3].j = vcut;
 t[3].r = s->i + s->r - hcut;
 t[3].c = s->j + s->c - vcut;
}

variable_types:
s
struct submaze *

variable_types:
vcut
unsigned char

variable_types:
hcut
unsigned char


original_code:
void gen_maze(struct submaze *s)
{
 if ( s->r == 0 || s->c == 0)
  return;
 for (int k = 0; k < 4; ++k) {
  s->m[k].w[0] = 1;
  s->m[(4 - 1) * 4 + k].w[2] = 1;
  s->m[k * 4].w[3] = 1;
  s->m[k * 4 + 4 - 1].w[1] = 1;
 }
 uint8_t hcut = 1 + (rand() % s->r) + s->i;
 uint8_t vcut = 1 + (rand() % s->c) + s->j;
 for (int k = s->j; k <= s->j + s->c; ++k)
  set_top_wall(s,1,hcut,k);
 for (int k = s->i; k <= s->i + s->r; ++k)
  set_left_wall(s,1,k,vcut);
 int no_hole = rand() % 4;
 int hole;
 if (no_hole != 0) {
  hole = s->i + (rand() % (hcut - s->i));
  set_left_wall(s,0,hole,vcut);
 }
 if (no_hole != 1) {
  hole = hcut + (rand() % (s->i + s->r - hcut + 1));
  set_left_wall(s,0,hole,vcut);
 }
 if (no_hole != 2) {
  hole = vcut + (rand() % (s->j + s->c - vcut + 1));
  set_top_wall(s,0,hcut,hole);
 }
 if (no_hole != 3) {
  hole = s->j + (rand() % (vcut - s->j));
  set_top_wall(s,0,hcut,hole);
 }
 struct submaze t[4];
 new_submaze(t,s,vcut,hcut);
 for (int i = 0; i < 4; ++i)
  gen_maze(&t[i]);
}

canonical_original_code:
void gen_maze(struct submaze *s)
{
 if ( s->r == 0 || s->c == 0)
  return;
 for (int k = 0; k < 4; ++k) {
  s->m[k].w[0] = 1;
  s->m[(4 - 1) * 4 + k].w[2] = 1;
  s->m[k * 4].w[3] = 1;
  s->m[k * 4 + 4 - 1].w[1] = 1;
 }
 unsigned char hcut = 1 + (rand() % s->r) + s->i;
 unsigned char vcut = 1 + (rand() % s->c) + s->j;
 for (int k = s->j; k <= s->j + s->c; ++k)
  set_top_wall(s,1,hcut,k);
 for (int k = s->i; k <= s->i + s->r; ++k)
  set_left_wall(s,1,k,vcut);
 int no_hole = rand() % 4;
 int hole;
 if (no_hole != 0) {
  hole = s->i + (rand() % (hcut - s->i));
  set_left_wall(s,0,hole,vcut);
 }
 if (no_hole != 1) {
  hole = hcut + (rand() % (s->i + s->r - hcut + 1));
  set_left_wall(s,0,hole,vcut);
 }
 if (no_hole != 2) {
  hole = vcut + (rand() % (s->j + s->c - vcut + 1));
  set_top_wall(s,0,hcut,hole);
 }
 if (no_hole != 3) {
  hole = s->j + (rand() % (vcut - s->j));
  set_top_wall(s,0,hcut,hole);
 }
 struct submaze t[4];
 new_submaze(t,s,vcut,hcut);
 for (int i = 0; i < 4; ++i)
  gen_maze(&t[i]);
}

variable_types: k int

variable_types: hole int

variable_types: struct submaze { struct square { _Bool w[4]; } *m; unsigned char i; unsigned char j; unsigned char r; unsigned char c; } [4]


itinerary

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

*(_QWORD *)(a2 + 8) = a1;
*(_WORD *)a2 = (unsigned __int8)node_at(1LL, a1) == 0 ? 13 : 1;
result = (unsigned __int8)node_at(12LL, a1) == 0 ? 24 : 12;
*(_WORD *)(a2 + 2) = result;
return result;
}

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

*(_QWORD *)(a2 + 8) = a1;
*(_WORD *)a2 = (unsigned __int8)node_at(1LL, a1) == 0 ? 13 : 1;
result = (unsigned __int8)node_at(12LL, a1) == 0 ? 24 : 12;
*(_WORD *)(a2 + 2) = result;
return result;
}

original_code:
void itinerary(struct square *m,struct maze *maze) {
 maze->m = m;
 if (node_at(1,m))
  maze->start_id = 1;
 else
  maze->start_id = 4*(4 -1) + 1;
 if (node_at(4*(4 -1),m))
  maze->end_id = 4*(4 -1);
 else
  maze->end_id = 2*4*(4 -1);
 return;
}

canonical_original_code:
void itinerary(struct square *m, struct maze *maze) {
 maze->m = m;
 if (node_at(1,m))
  maze->start_id = 1;
 else
  maze->start_id = 4*(4 -1) + 1;
 if (node_at(4*(4 -1),m))
  maze->end_id = 4*(4 -1);
 else
  maze->end_id = 2*4*(4 -1);
 return;
}


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // rdx
int result; // eax
int v5; // eax
char *v6; // rdi
__int64 i; // rcx
__m128i v8; // [rsp+0h] [rbp-A8h] BYREF
_WORD v9[8]; // [rsp+10h] [rbp-98h] BYREF
char v10[64]; // [rsp+20h] [rbp-88h] BYREF
char v11[72]; // [rsp+60h] [rbp-48h] BYREF

if ( argc == 2 )
{
v5 = atoi(argv[1]);
srand(v5);
v6 = v11;
for ( i = 16LL; i; --i )
{
*(_DWORD *)v6 = 0;
v6 += 4;
}
v8.m128i_i32[2] = 50528256;
v8.m128i_i64[0] = (__int64)v11;
gen_maze(&v8);
itinerary(v8.m128i_i64[0], (__int64)v9);
fastest_path(v9, v10);
draw(v8.m128i_i64[0], (__int64)v10, v9);
result = 0;
}
else
{
v3 = "maze-test";
if ( argc )
v3 = *argv;
fprintf(stderr, "usage: %s <arg>\n", v3);
result = 1;
}
return result;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // rdx
int result; // eax
int v5; // eax
char *v6; // rdi
__int64 i; // rcx
__m128i v8; // [rsp+0h] [rbp-A8h] BYREF
_WORD v9[8]; // [rsp+10h] [rbp-98h] BYREF
char v10[64]; // [rsp+20h] [rbp-88h] BYREF
char v11[72]; // [rsp+60h] [rbp-48h] BYREF

if ( argc == 2 )
{
v5 = atoi(argv[1]);
srand(v5);
v6 = v11;
for ( i = 16LL; i; --i )
{
*(_DWORD *)v6 = 0;
v6 += 4;
}
v8.m128i_i32[2] = 50528256;
v8.m128i_i64[0] = (__int64)v11;
func5(&v8);
func6(v8.m128i_i64[0], (__int64)v9);
fastest_path(v9, v10);
func1(v8.m128i_i64[0], (__int64)v10, v9);
result = 0;
}
else
{
v3 = "maze-test";
if ( argc )
v3 = *argv;
fprintf(stderr, "usage: %s <arg>\n", v3);
result = 1;
}
return result;
}

original_code:
int main (int argc, char *argv[] ) {
 if (argc != 2) {
  fprintf(stderr, "usage: %s <arg>\n", argc?argv[0]:"maze-test");
  return 1;
 }
 srand(atoi(argv[1]));
 struct square mz[4 * 4] = {};
 struct submaze s_, *s = &s_;
 s->m = mz;
 s->i = 0;
 s->j = 0;
 s->r = 4 -1;
 s->c = 4 -1;
 gen_maze(s);
 struct maze maze;
 itinerary(s->m,&maze);
 struct tbl tbl;
 fastest_path(&maze,&tbl);
 draw(s->m,&tbl,&maze);
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[]) {
 if (argc != 2) {
  fprintf(stderr, "usage: %s <arg>\n", argc?argv[0]:"maze-test");
  return 1;
 }
 srand(atoi(argv[1]));
 struct square mz[-1] = {};
 struct submaze s_; struct submaze *s = &s_;
 s->m = mz;
 s->i = 0;
 s->j = 0;
 s->r = 4 -1;
 s->c = 4 -1;
 gen_maze(s);
 struct maze maze;
 itinerary(s->m,&maze);
 struct tbl tbl;
 fastest_path(&maze,&tbl);
 draw(s->m,&tbl,&maze);
 return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types:
mz
struct square { _Bool w[4]; } [-1]

variable_types: struct submaze { struct square { _Bool w[4]; } *m; unsigned char i; unsigned char j; unsigned char r; unsigned char c; }

variable_types: struct maze { unsigned short start_id; unsigned short end_id; struct square { _Bool w[4]; } *m; }

variable_types: struct tbl { struct node { unsigned short time; unsigned short id; unsigned short pre; struct node *nxt_in_tbl; } *t[-1]; unsigned short n_tbl; }


repo: threedaymonk/ansitee

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
int v3; // er12
unsigned int v4; // ebp
int v5; // eax
const char **v6; // r13
char *v7; // rbx
int v8; // er14
int v9; // er12
int v10; // er14
int i; // eax
const char *v12; // rdi
__int64 v13; // r15
int v14; // eax
int v15; // ebp
char *v16; // r14
int v17; // er13
signed int v18; // eax
int v19; // edi

v3 = 0;
v4 = 0;
while ( 1 )
{
v5 = getopt(argc, (char *const *)argv, "aish");
if ( v5 == -1 )
break;
if ( (_BYTE)v5 == 105 )
{
signal(2, (__sighandler_t)1);
}
else if ( (_BYTE)v5 == 115 )
{
v4 = 1;
}
else
{
if ( (_BYTE)v5 != 97 )
usage();
v3 = 1;
}
}
v6 = &argv[optind];
v7 = (char *)malloc(0x2000uLL);
if ( !v7 )
err(1, "malloc");
add(1LL, 0LL, "stdout");
if ( *v6 )
{
v8 = -(v3 == 0);
v9 = 0;
v10 = (v8 & 0xFFFFFE00) + 1089;
for ( i = open(*v6, v10, 438LL); ; i = open(v12, v10, 438LL) )
{
if ( i >= 0 )
{
add((unsigned int)i, v4, *v6);
}
else
{
v9 = 1;
warn("%s", *v6);
}
v12 = v6[1];
++v6;
if ( !v12 )
break;
}
}
else
{
v9 = 0;
}
while ( 1 )
{
do
{
v14 = read(0, v7, 0x2000uLL);
v15 = v14;
if ( v14 <= 0 )
{
if ( v14 )
err(1, "read");
exit(v9);
}
v13 = head;
}
while ( !head );
do
{
v16 = v7;
v17 = v15;
while ( 1 )
{
v19 = *(_DWORD *)(v13 + 8);
v18 = *(_DWORD *)(v13 + 12) ? (unsigned int)write_without_ansi(v19) : (unsigned int)write(v19, v16, v17);
if ( v18 == -1 )
break;
v16 += v18;
v17 -= v18;
if ( !v17 )
goto LABEL_19;
}
v9 = 1;
warn("%s", *(const char **)(v13 + 16));
LABEL_19:
v13 = *(_QWORD *)v13;
}
while ( v13 );
}
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
int v3; // er12
unsigned int v4; // ebp
int v5; // eax
const char **v6; // r13
char *v7; // rbx
int v8; // er14
int v9; // er12
int v10; // er14
int i; // eax
const char *v12; // rdi
__int64 v13; // r15
int v14; // eax
int v15; // ebp
char *v16; // r14
int v17; // er13
signed int v18; // eax
int v19; // edi

v3 = 0;
v4 = 0;
while ( 1 )
{
v5 = getopt(argc, (char *const *)argv, "aish");
if ( v5 == -1 )
break;
if ( (_BYTE)v5 == 105 )
{
signal(2, (__sighandler_t)1);
}
else if ( (_BYTE)v5 == 115 )
{
v4 = 1;
}
else
{
if ( (_BYTE)v5 != 97 )
func8();
v3 = 1;
}
}
v6 = &argv[optind];
v7 = (char *)malloc(0x2000uLL);
if ( !v7 )
err(1, "malloc");
add(1LL, 0LL, "stdout");
if ( *v6 )
{
v8 = -(v3 == 0);
v9 = 0;
v10 = (v8 & 0xFFFFFE00) + 1089;
for ( i = open(*v6, v10, 438LL); ; i = open(v12, v10, 438LL) )
{
if ( i >= 0 )
{
add((unsigned int)i, v4, *v6);
}
else
{
v9 = 1;
warn("%s", *v6);
}
v12 = v6[1];
++v6;
if ( !v12 )
break;
}
}
else
{
v9 = 0;
}
while ( 1 )
{
do
{
v14 = read(0, v7, 0x2000uLL);
v15 = v14;
if ( v14 <= 0 )
{
if ( v14 )
err(1, "read");
exit(v9);
}
v13 = head;
}
while ( !head );
do
{
v16 = v7;
v17 = v15;
while ( 1 )
{
v19 = *(_DWORD *)(v13 + 8);
v18 = *(_DWORD *)(v13 + 12) ? (unsigned int)func7(v19) : (unsigned int)write(v19, v16, v17);
if ( v18 == -1 )
break;
v16 += v18;
v17 -= v18;
if ( !v17 )
goto LABEL_19;
}
v9 = 1;
warn("%s", *(const char **)(v13 + 16));
LABEL_19:
v13 = *(_QWORD *)v13;
}
while ( v13 );
}
}

original_code:
int
main(int argc, char *argv[]) {
    LIST *p;
    int n, fd, rval, wval;
    char *bp;
    int append, strip_ansi, ch, exitval;
    char *buf;
    append = 0;
    strip_ansi = 0;
    while ((ch = getopt(argc, argv, "aish")) != -1) {
        switch((char)ch) {
            case 'a':
                append = 1;
                break;
            case 'i':
                (void)signal(2, ((__sighandler_t) 1));
                break;
            case 's':
                strip_ansi = 1;
                break;
            case '?':
            case 'h':
            default:
                usage();
        }
    }
    argv += optind;
    argc -= optind;
    if ((buf = malloc((8 * 1024))) == ((void *)0)) {
        err(1, "malloc");
    }
    add(1, 0, "stdout");
    for (exitval = 0; *argv; ++argv) {
        if ((fd = open(*argv,
                       01 | 0100 | (append ? 02000 : 01000),
                       (0400|0200|(0400 >> 3)|(0200 >> 3)|((0400 >> 3) >> 3)|((0200 >> 3) >> 3)))) < 0) {
            warn("%s", *argv);
            exitval = 1;
        } else {
            add(fd, strip_ansi, *argv);
        }
    }
    while ((rval = read(0, buf, (8 * 1024))) > 0) {
        for (p = head; p; p = p->next) {
            n = rval;
            bp = buf;
            do {
                if (p->strip_ansi == 0) {
                    wval = write(p->fd, bp, n);
                } else {
                    wval = write_without_ansi(p->fd, bp, n);
                }
                if (wval == -1) {
                    warn("%s", p->name);
                    exitval = 1;
                    break;
                }
                bp += wval;
            } while (n -= wval);
        }
    }
    if (rval < 0) {
        err(1, "read");
    }
    exit(exitval);
}

canonical_original_code:
int main(int argc, char *argv[]) {
    struct _list *p;
    int n; int fd; int rval; int wval;
    char *bp;
    int append; int strip_ansi; int ch; int exitval;
    char *buf;
    append = 0;
    strip_ansi = 0;
    while ((ch = getopt(argc, argv, "aish")) != -1) {
        switch((char)ch) {
            case 'a':
                append = 1;
                break;
            case 'i':
                (void)signal(2, ((void (*)(int)) 1));
                break;
            case 's':
                strip_ansi = 1;
                break;
            case '?':
            case 'h':
            default:
                usage();
        }
    }
    argv += optind;
    argc -= optind;
    if ((buf = malloc((8 * 1024))) == ((void *)0)) {
        err(1, "malloc");
    }
    add(1, 0, "stdout");
    for (exitval = 0; *argv; ++argv) {
        if ((fd = open(*argv,
                       01 | 0100 | (append ? 02000 : 01000),
                       (0400|0200|(0400 >> 3)|(0200 >> 3)|((0400 >> 3) >> 3)|((0200 >> 3) >> 3)))) < 0) {
            warn("%s", *argv);
            exitval = 1;
        } else {
            add(fd, strip_ansi, *argv);
        }
    }
    while ((rval = read(0, buf, (8 * 1024))) > 0) {
        for (p = head; p; p = p->next) {
            n = rval;
            bp = buf;
            do {
                if (p->strip_ansi == 0) {
                    wval = write(p->fd, bp, n);
                } else {
                    wval = write_without_ansi(p->fd, bp, n);
                }
                if (wval == -1) {
                    warn("%s", p->name);
                    exitval = 1;
                    break;
                }
                bp += wval;
            } while (n -= wval);
        }
    }
    if (rval < 0) {
        err(1, "read");
    }
    exit(exitval);
}

variable_types: struct _list { struct _list *next; int fd; int strip_ansi; char *name; } *

variable_types: n int

variable_types: fd int

variable_types: rval int

variable_types: wval int

variable_types:
bp
char *

variable_types: append int

variable_types: ch int

variable_types: exitval int

variable_types:
buf
char *


decompiled_code:
void __fastcall write_without_ansi(int fd, char *a2, unsigned __int64 a3)
{
char v4; // dl
unsigned __int64 v5; // rbx
unsigned __int64 v6; // rax
char v7; // dl
char v8; // dl
char buf; // [rsp+Eh] [rbp-2Ah] BYREF
char v10[41]; // [rsp+Fh] [rbp-29h] BYREF

v10[0] = 27;
if ( a3 )
{
v4 = *a2;
v5 = 0LL;
for ( buf = *a2; ; buf = v4 )
{
LODWORD(v6) = v5++;
if ( v4 == 27 )
break;
LABEL_11:
write(fd, &buf, 1uLL);
if ( a3 <= v5 )
return;
LABEL_12:
v4 = a2[v5];
}
while ( a3 > v5 )
{
v7 = a2[v5];
v5 = (int)v6 + 2;
buf = v7;
if ( v7 != 91 )
{
write(fd, v10, 1uLL);
if ( a3 > v5 )
goto LABEL_12;
return;
}
if ( a3 <= v5 )
return;
v8 = a2[v5];
v6 = (int)v6 + 3;
while ( (unsigned __int8)(v8 - 64) > 0x3Eu )
{
if ( a3 == v6 )
return;
v8 = a2[v6++];
}
if ( a3 <= v6 )
return;
v5 = (int)v6 + 1LL;
buf = a2[v6];
if ( buf != 27 )
goto LABEL_11;
}
}
}

canonical_decompiled_code:
void __fastcall func7(int fd, char *a2, unsigned __int64 a3)
{
char v4; // dl
unsigned __int64 v5; // rbx
unsigned __int64 v6; // rax
char v7; // dl
char v8; // dl
char buf; // [rsp+Eh] [rbp-2Ah] BYREF
char v10[41]; // [rsp+Fh] [rbp-29h] BYREF

v10[0] = 27;
if ( a3 )
{
v4 = *a2;
v5 = 0LL;
for ( buf = *a2; ; buf = v4 )
{
LODWORD(v6) = v5++;
if ( v4 == 27 )
break;
LABEL_11:
write(fd, &buf, 1uLL);
if ( a3 <= v5 )
return;
LABEL_12:
v4 = a2[v5];
}
while ( a3 > v5 )
{
v7 = a2[v5];
v5 = (int)v6 + 2;
buf = v7;
if ( v7 != 91 )
{
write(fd, v10, 1uLL);
if ( a3 > v5 )
goto LABEL_12;
return;
}
if ( a3 <= v5 )
return;
v8 = a2[v5];
v6 = (int)v6 + 3;
while ( (unsigned __int8)(v8 - 64) > 0x3Eu )
{
if ( a3 == v6 )
return;
v8 = a2[v6++];
}
if ( a3 <= v6 )
return;
v5 = (int)v6 + 1LL;
buf = a2[v6];
if ( buf != 27 )
goto LABEL_11;
}
}
}

original_code:
static ssize_t
write_without_ansi(int fd, const void *buf, size_t count) {
    int state = 0, i;
    char ch, esc = 0x1B;
    for (i = 0; i < count; i++) {
        ch = ((char *)buf)[i];
        switch (state) {
            case 0:
                if (ch == 0x1B) {
                    state = 1;
                } else {
                    write(fd, &ch, 1);
                }
                break;
            case 1:
                if (ch == '[') {
                    state = 2;
                } else {
                    state = 0;
                    write(fd, &esc, 1);
                }
                break;
            case 2:
                if (((ch) >= 0x40 && (ch) <= 0x7E)) {
                    state = 0;
                }
        }
    }
}

canonical_original_code:
static long write_without_ansi(int fd, void *buf, unsigned long count) {
    int state = 0; int i;
    char ch; char esc = 0x1B;
    for (i = 0; i < count; i++) {
        ch = ((char *)buf)[i];
        switch (state) {
            case 0:
                if (ch == 0x1B) {
                    state = 1;
                } else {
                    write(fd, &ch, 1);
                }
                break;
            case 1:
                if (ch == '[') {
                    state = 2;
                } else {
                    state = 0;
                    write(fd, &esc, 1);
                }
                break;
            case 2:
                if (((ch) >= 0x40 && (ch) <= 0x7E)) {
                    state = 0;
                }
        }
    }
}

variable_types:
buf
void *

variable_types:
count
unsigned long

variable_types: state int

variable_types: i int

variable_types: ch char

variable_types: esc char

return_type: long


usage

decompiled_code:
void __noreturn usage()
{
fwrite("usage: tee [-ai] [file ...]\n", 1uLL, 0x1CuLL, stderr);
exit(1);
}

canonical_decompiled_code:
void __noreturn func8()
{
fwrite("usage: tee [-ai] [file ...]\n", 1uLL, 0x1CuLL, stderr);
exit(1);
}

original_code:
static void
usage(void) {
    (void)fprintf(stderr, "usage: tee [-ai] [file ...]\n");
    exit(1);
}

canonical_original_code:
static void usage() {
    (void)fprintf(stderr, "usage: tee [-ai] [file ...]\n");
    exit(1);
}


repo: thrimbor/mandelbrot

canonical_original_code:
static inline float complex_mul(float a, float b)
{
 return _mm_addsub_ps( _mm_mul_ps(_mm_moveldup_ps(a), b),
        _mm_mul_ps(_mm_movehdup_ps(a), ((float) __builtin_ia32_shufps ((__v4sf)(__m128)(b), (__v4sf)(__m128)(b), (int)((((2) << 6) | ((3) << 4) | ((0) << 2) | (1)))))));
}

variable_types: a float

variable_types: b float

return_type: float


testEscapeSeriesForPoint

decompiled_code:
__int64 __fastcall testEscapeSeriesForPoint(int a1, double a2)
{
unsigned int v2; // xmm1_4
unsigned int v3; // xmm2_4
int v4; // er12
int v5; // er14
int v6; // er15
float v7; // xmm0_4
double v8; // xmm0_8
unsigned __int64 v10; // [rsp+18h] [rbp-60h]
double v11; // [rsp+20h] [rbp-58h]

v2 = 0;
v3 = 0;
v4 = 0;
v5 = _mm_cvtsi128_si32((__m128i)LODWORD(a2));
v6 = _mm_cvtsi128_si32((__m128i)HIDWORD(a2));
while ( complex_abs(COERCE_DOUBLE(__PAIR64__(v3, v2))) <= 2.0 )
{
if ( v4 >= a1 )
return (unsigned int)v4;
++v4;
*(_QWORD *)&v11 = complex_mul(COERCE_DOUBLE(__PAIR64__(v3, v2)), COERCE_DOUBLE(__PAIR64__(v3, v2))).m128i_u64[0];
v10 = complex_add(v11, COERCE_DOUBLE(__PAIR64__(v6, v5))).m128i_u64[0];
v2 = v10;
v3 = HIDWORD(v10);
}
if ( v4 < a1 )
{
v7 = complex_abs(COERCE_DOUBLE(__PAIR64__(v3, v2)));
v8 = log(v7);
v4 = (int)(1.0 - log(v8 / 0.6931471805599453) / 0.6931471805599453 + (double)v4);
}
return (unsigned int)v4;
}

original_code:
__attribute__ ((hot)) static inline void
testEscapeSeriesForPoint(__m128 c, int maxIterations, int* it1, int* it2)
{
 float r = 2*2;
 float f = 0;
 float g = 0;
    __m128 z = _mm_setzero_ps();
 int iteration1 = 0;
 int iteration2 = 0;
 int it1_done = 0;
 int it2_done = 0;
 float f_sqrt=0, g_sqrt=0;
 while (iteration1 < maxIterations && iteration2 < maxIterations)
 {
  complex_abs_sqr(z, &f, &g);
  if ((f > r) && (g > r)) {
   break;
  } else if (f>r && !it1_done) {
   it1_done = -1;
   f_sqrt = sqrt(f);
   z = ((__m128) __builtin_ia32_shufps ((__v4sf)(__m128)(z), (__v4sf)(__m128)(z), (int)((((3) << 6) | ((2) << 4) | ((3) << 2) | (2)))));
  } else if (g>r && !it2_done) {
   it2_done = -1;
   g_sqrt = sqrt(g);
   z = ((__m128) __builtin_ia32_shufps ((__v4sf)(__m128)(z), (__v4sf)(__m128)(z), (int)((((1) << 6) | ((0) << 4) | ((1) << 2) | (0)))));
  }
  if (it1_done && it2_done) break;
  z = _mm_add_ps(complex_mul(z,z), c);
  if (!it1_done)
   iteration1++;
  if (!it2_done)
   iteration2++;
 }
 if (iteration1 < maxIterations)
 {
  if (!it1_done) f_sqrt = sqrt(f);
  iteration1 += 1.0f - (log(log(f_sqrt) / logof2) / logof2);
 }
 if (iteration2 < maxIterations)
 {
  if (!it2_done) g_sqrt = sqrt(g);
  iteration2 += 1.0f - (log(log(g_sqrt) / logof2) / logof2);
 }
 *it1 = iteration1;
 *it2 = iteration2;
}

canonical_original_code:
static inline void testEscapeSeriesForPoint(float c, int maxIterations, int *it1, int *it2)
{
 float r = 2*2;
 float f = 0;
 float g = 0;
    float z = _mm_setzero_ps();
 int iteration1 = 0;
 int iteration2 = 0;
 int it1_done = 0;
 int it2_done = 0;
 float f_sqrt = 0; float g_sqrt = 0;
 while (iteration1 < maxIterations && iteration2 < maxIterations)
 {
  complex_abs_sqr(z, &f, &g);
  if ((f > r) && (g > r)) {
   break;
  } else if (f>r && !it1_done) {
   it1_done = -1;
   f_sqrt = sqrt(f);
   z = ((float) __builtin_ia32_shufps ((__v4sf)(__m128)(z), (__v4sf)(__m128)(z), (int)((((3) << 6) | ((2) << 4) | ((3) << 2) | (2)))));
  } else if (g>r && !it2_done) {
   it2_done = -1;
   g_sqrt = sqrt(g);
   z = ((float) __builtin_ia32_shufps ((__v4sf)(__m128)(z), (__v4sf)(__m128)(z), (int)((((1) << 6) | ((0) << 4) | ((1) << 2) | (0)))));
  }
  if (it1_done && it2_done) break;
  z = _mm_add_ps(complex_mul(z,z), c);
  if (!it1_done)
   iteration1++;
  if (!it2_done)
   iteration2++;
 }
 if (iteration1 < maxIterations)
 {
  if (!it1_done) f_sqrt = sqrt(f);
  iteration1 += 1.0f - (log(log(f_sqrt) / logof2) / logof2);
 }
 if (iteration2 < maxIterations)
 {
  if (!it2_done) g_sqrt = sqrt(g);
  iteration2 += 1.0f - (log(log(g_sqrt) / logof2) / logof2);
 }
 *it1 = iteration1;
 *it2 = iteration2;
}

variable_types: c float

variable_types: maxIterations int

variable_types: r float

variable_types: f float

variable_types: g float

variable_types: z float


decompiled_code:
__m128 __fastcall complex_mul(__m128 a1, __m128 a2)
{
return _mm_addsub_ps(
_mm_mul_ps(a2, _mm_moveldup_ps(a1)),
_mm_mul_ps(_mm_shuffle_ps(a2, a2, 177), _mm_movehdup_ps(a1)));
}

canonical_decompiled_code:
__m128 __fastcall func4(__m128 a1, __m128 a2)
{
return _mm_addsub_ps(
_mm_mul_ps(a2, _mm_moveldup_ps(a1)),
_mm_mul_ps(_mm_shuffle_ps(a2, a2, 177), _mm_movehdup_ps(a1)));
}


help

decompiled_code:
int help()
{
puts("USAGE: mandelbrot_cli [OPTIONS]");
puts("With [OPTIONS]:");
puts("\t -i --maxiterations INT \t maximum number of series iterations per pixel");
puts("\t -o --outfile FILE \t filename (without appendix) for output picture in PPM format");
return putchar(10);
}

canonical_decompiled_code:
int func10()
{
puts("USAGE: mandelbrot_cli [OPTIONS]");
puts("With [OPTIONS]:");
puts("\t -i --maxiterations INT \t maximum number of series iterations per pixel");
puts("\t -o --outfile FILE \t filename (without appendix) for output picture in PPM format");
return putchar(10);
}

original_code:
void
help(void)
{
    printf("USAGE: mandelbrot_cli [OPTIONS]\n");
    printf("With [OPTIONS]:\n");
    printf("\t -i --maxiterations INT \t maximum number of series iterations per pixel\n");
    printf("\t -o --outfile FILE \t filename (without appendix) for output picture in PPM format\n");
    printf("\n");
}

canonical_original_code:
void help()
{
    printf("USAGE: mandelbrot_cli [OPTIONS]\n");
    printf("With [OPTIONS]:\n");
    printf("\t -i --maxiterations INT \t maximum number of series iterations per pixel\n");
    printf("\t -o --outfile FILE \t filename (without appendix) for output picture in PPM format\n");
    printf("\n");
}


main

repo: tigerjibo/yuv

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v4; // ebx
int v5; // ebp
int v6; // eax
const char *v7; // rsi
const char *v8; // r15
int v9; // er13
int v10; // er12
int v11; // esi
double v13; // xmm0_8
double v14; // xmm0_8
double v15; // xmm0_8
double v16; // xmm0_8
double v17; // xmm0_8
int v18; // [rsp+18h] [rbp-50h] BYREF
int v19; // [rsp+1Ch] [rbp-4Ch] BYREF
void *ptr; // [rsp+20h] [rbp-48h] BYREF
void *v21; // [rsp+28h] [rbp-40h] BYREF

v4 = atoi(argv[1]);
v5 = atoi(argv[2]);
v6 = atoi(argv[3]);
v7 = argv[5];
v8 = argv[4];
v9 = v6;
ptr = 0LL;
v21 = 0LL;
if ( (unsigned int)get_yuv_format(&v18, v7, v4, v5, &ptr) )
return -1;
v10 = get_yuv_format(&v19, argv[6], v4, v5, &v21);
if ( v10 )
return -1;
v11 = v18;
if ( argc > 7 && (v11 = v18, atoi(argv[7])) )
{
v13 = test_3d_constprop_0(v9, v11, ptr, v19, v21, v4, v5);
printf("i420_3d_to_yuyv422_sbs> elapsed=%fms, avg=%fms\n", v13, v13 / (double)v9);
}
else if ( v11 == 1 )
{
v16 = test(
v9,
1,
ptr,
v19,
v21,
v4,
v5,
(__int64)v8,
(__int64)"i420_4b.yuv",
(void (__fastcall *)(void *, const void *, _QWORD, _QWORD))&uyvy422_to_i420_4byte);
printf("uyvy_to_i420_4b> elapsed=%fms, avg=%fms\n", v16, v16 / (double)v9);
v17 = test(
v9,
v18,
ptr,
v19,
v21,
v4,
v5,
(__int64)v8,
(__int64)"i420_wh.yuv",
(void (__fastcall *)(void *, const void *, _QWORD, _QWORD))&uyvy422_to_i420_wh);
printf("uyvy_to_i420_wh> elapsed=%fms, avg=%fms\n", v17, v17 / (double)v9);
}
else if ( !v11 && v19 == 1 )
{
v14 = test(
v9,
0,
ptr,
1,
v21,
v4,
v5,
(__int64)v8,
(__int64)"uyvy422.yuv",
(void (__fastcall *)(void *, const void *, _QWORD, _QWORD))&i420_to_uyvy422);
printf("i420_to_uyvy> elapsed=%fms, avg=%fms\n", v14, v14 / (double)v9);
v15 = test(
v9,
v18,
ptr,
v19,
v21,
v4,
v5,
(__int64)v8,
(__int64)"uyvy422_bottom.yuv",
(void (__fastcall *)(void *, const void *, _QWORD, _QWORD))&i420_to_uyvy422_bottom);
printf("i420_to_uyvy_bottom> elapsed=%fms, avg=%fms\n", v15, v15 / (double)v9);
}
else
{
printf("fopen(%s) failed\n", v8);
}
if ( ptr )
free(ptr);
if ( v21 )
free(v21);
return v10;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v4; // ebx
int v5; // ebp
int v6; // eax
const char *v7; // rsi
const char *v8; // r15
int v9; // er13
int v10; // er12
int v11; // esi
double v13; // xmm0_8
double v14; // xmm0_8
double v15; // xmm0_8
double v16; // xmm0_8
double v17; // xmm0_8
int v18; // [rsp+18h] [rbp-50h] BYREF
int v19; // [rsp+1Ch] [rbp-4Ch] BYREF
void *ptr; // [rsp+20h] [rbp-48h] BYREF
void *v21; // [rsp+28h] [rbp-40h] BYREF

v4 = atoi(argv[1]);
v5 = atoi(argv[2]);
v6 = atoi(argv[3]);
v7 = argv[5];
v8 = argv[4];
v9 = v6;
ptr = 0LL;
v21 = 0LL;
if ( (unsigned int)func0(&v18, v7, v4, v5, &ptr) )
return -1;
v10 = func0(&v19, argv[6], v4, v5, &v21);
if ( v10 )
return -1;
v11 = v18;
if ( argc > 7 && (v11 = v18, atoi(argv[7])) )
{
v13 = func5(v9, v11, ptr, v19, v21, v4, v5);
printf("i420_3d_to_yuyv422_sbs> elapsed=%fms, avg=%fms\n", v13, v13 / (double)v9);
}
else if ( v11 == 1 )
{
v16 = func6(
v9,
1,
ptr,
v19,
v21,
v4,
v5,
(__int64)v8,
(__int64)"i420_4b.yuv",
(void (__fastcall *)(void *, const void *, _QWORD, _QWORD))&uyvy422_to_i420_4byte);
printf("uyvy_to_i420_4b> elapsed=%fms, avg=%fms\n", v16, v16 / (double)v9);
v17 = func6(
v9,
v18,
ptr,
v19,
v21,
v4,
v5,
(__int64)v8,
(__int64)"i420_wh.yuv",
(void (__fastcall *)(void *, const void *, _QWORD, _QWORD))&uyvy422_to_i420_wh);
printf("uyvy_to_i420_wh> elapsed=%fms, avg=%fms\n", v17, v17 / (double)v9);
}
else if ( !v11 && v19 == 1 )
{
v14 = func6(
v9,
0,
ptr,
1,
v21,
v4,
v5,
(__int64)v8,
(__int64)"uyvy422.yuv",
(void (__fastcall *)(void *, const void *, _QWORD, _QWORD))&i420_to_uyvy422);
printf("i420_to_uyvy> elapsed=%fms, avg=%fms\n", v14, v14 / (double)v9);
v15 = func6(
v9,
v18,
ptr,
v19,
v21,
v4,
v5,
(__int64)v8,
(__int64)"uyvy422_bottom.yuv",
(void (__fastcall *)(void *, const void *, _QWORD, _QWORD))&i420_to_uyvy422_bottom);
printf("i420_to_uyvy_bottom> elapsed=%fms, avg=%fms\n", v15, v15 / (double)v9);
}
else
{
printf("fopen(%s) failed\n", v8);
}
if ( ptr )
free(ptr);
if ( v21 )
free(v21);
return v10;
}

original_code:
int main(int argc, char **argv)
{
    unsigned int w = (unsigned int) atoi(argv[1]);
    unsigned int h = (unsigned int) atoi(argv[2]);
    int count = atoi(argv[3]);
    char *filepath = argv[4];
    enum yuv_format sf, df;
    char *src = ((void *)0);
    char *dst = ((void *)0);
    double elapsed;
    if (_get_yuv_format(&sf, argv[5], w, h, &src))
        return -1;
    if (_get_yuv_format(&df, argv[6], w, h, &dst))
        return -1;
    if (argc >= 8) {
        if (atoi(argv[7])) {
            elapsed = _test_3d(count, sf, src, df, dst, w, h, filepath, "yuyv422_sbs.yuv");
            printf("i420_3d_to_yuyv422_sbs> elapsed=%fms, avg=%fms\n", elapsed, elapsed / count);
            goto exit;
        }
    }
    if (sf == yuv_uyvy) {
        elapsed = _test(count, sf, src, df, dst, w, h, filepath, "i420_4b.yuv", uyvy422_to_i420_4byte);
        printf("uyvy_to_i420_4b> elapsed=%fms, avg=%fms\n", elapsed, elapsed / count);
        elapsed = _test(count, sf, src, df, dst, w, h, filepath, "i420_wh.yuv", uyvy422_to_i420_wh);
        printf("uyvy_to_i420_wh> elapsed=%fms, avg=%fms\n", elapsed, elapsed / count);
    } else if (sf == yuv_i420 && df == yuv_uyvy) {
        elapsed = _test(count, sf, src, df, dst, w, h, filepath, "uyvy422.yuv", i420_to_uyvy422);
        printf("i420_to_uyvy> elapsed=%fms, avg=%fms\n", elapsed, elapsed / count);
        elapsed = _test(count, sf, src, df, dst, w, h, filepath, "uyvy422_bottom.yuv", i420_to_uyvy422_bottom);
        printf("i420_to_uyvy_bottom> elapsed=%fms, avg=%fms\n", elapsed, elapsed / count);
    } else {
        printf("fopen(%s) failed\n", filepath);
        goto exit;
    }
exit:
    if (src)
        free(src);
    if (dst)
        free(dst);
    return 0;
}

canonical_original_code:
int main(int argc, char **argv)
{
    unsigned int w = (unsigned int) atoi(argv[1]);
    unsigned int h = (unsigned int) atoi(argv[2]);
    int count = atoi(argv[3]);
    char *filepath = argv[4];
    enum yuv_format sf; enum yuv_format df;
    char *src = ((void *)0);
    char *dst = ((void *)0);
    double elapsed;
    if (_get_yuv_format(&sf, argv[5], w, h, &src))
        return -1;
    if (_get_yuv_format(&df, argv[6], w, h, &dst))
        return -1;
    if (argc >= 8) {
        if (atoi(argv[7])) {
            elapsed = _test_3d(count, sf, src, df, dst, w, h, filepath, "yuyv422_sbs.yuv");
            printf("i420_3d_to_yuyv422_sbs> elapsed=%fms, avg=%fms\n", elapsed, elapsed / count);
            goto exit;
        }
    }
    if (sf == yuv_uyvy) {
        elapsed = _test(count, sf, src, df, dst, w, h, filepath, "i420_4b.yuv", uyvy422_to_i420_4byte);
        printf("uyvy_to_i420_4b> elapsed=%fms, avg=%fms\n", elapsed, elapsed / count);
        elapsed = _test(count, sf, src, df, dst, w, h, filepath, "i420_wh.yuv", uyvy422_to_i420_wh);
        printf("uyvy_to_i420_wh> elapsed=%fms, avg=%fms\n", elapsed, elapsed / count);
    } else if (sf == yuv_i420 && df == yuv_uyvy) {
        elapsed = _test(count, sf, src, df, dst, w, h, filepath, "uyvy422.yuv", i420_to_uyvy422);
        printf("i420_to_uyvy> elapsed=%fms, avg=%fms\n", elapsed, elapsed / count);
        elapsed = _test(count, sf, src, df, dst, w, h, filepath, "uyvy422_bottom.yuv", i420_to_uyvy422_bottom);
        printf("i420_to_uyvy_bottom> elapsed=%fms, avg=%fms\n", elapsed, elapsed / count);
    } else {
        printf("fopen(%s) failed\n", filepath);
        goto exit;
    }
exit:
    if (src)
        free(src);
    if (dst)
        free(dst);
    return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types:
w
unsigned int

variable_types:
h
unsigned int

variable_types: count int

variable_types:
filepath
char *

variable_types: enum yuv_format { yuv_i420=0, yuv_uyvy=1, yuv_yuyv=2 }

variable_types:
src
char *

variable_types:
dst
char *

variable_types: elapsed double


repo: tigerking/zmodem-android

decompiled_code:
void tcp_alarm_handler()
{
;
}

canonical_decompiled_code:
void func0()
{
;
}

original_code:
static void
tcp_alarm_handler(int dummy __attribute__((__unused__)))
{
}

canonical_original_code:
static void tcp_alarm_handler(int dummy)
{
}

variable_types: dummy int


decompiled_code:
__int64 __fastcall tcp_server(char *s)
{
int v1; // er12
socklen_t v2; // edx
unsigned __int16 v3; // bx
char *v4; // rax
int *v6; // rax
int *v7; // rax
int *v8; // rax
int *v9; // rax
int *v10; // rax
int optval; // [rsp+4h] [rbp-44h] BYREF
socklen_t len[2]; // [rsp+8h] [rbp-40h] BYREF
struct sockaddr v13; // [rsp+10h] [rbp-38h] BYREF
struct sockaddr addr; // [rsp+20h] [rbp-28h] BYREF

optval = 1;
v1 = socket(2, 1, 6);
if ( v1 < 0 )
{
v9 = _errno_location();
error(1, *v9, "socket");
}
if ( setsockopt(v1, 1, 2, &optval, 4u) < 0 )
{
v8 = _errno_location();
error(1, *v8, "setsockopt (reuse address)");
}
v13 = 0LL;
v13.sa_family = 2;
*(_DWORD *)&v13.sa_data[2] = _bswap_32_constprop_0((unsigned int)v1, &v13, 16LL);
if ( bind(v1, &v13, v2) < 0 )
{
v7 = _errno_location();
error(1, *v7, "bind");
}
*(_QWORD *)len = 16LL;
if ( getsockname(v1, &addr, len) )
{
v6 = _errno_location();
error(1, *v6, "getsockname");
}
v3 = _bswap_16(*(__int16 *)addr.sa_data);
v4 = inet_ntoa(*(struct in_addr *)&addr.sa_data[2]);
sprintf(s, "[%s] <%d>\n", v4, v3);
if ( listen(v1, 1) < 0 )
{
v10 = _errno_location();
error(1, *v10, "listen");
}
getsockname(v1, &addr, len);
return (unsigned int)v1;
}

canonical_decompiled_code:
__int64 __fastcall func3(char *s)
{
int v1; // er12
socklen_t v2; // edx
unsigned __int16 v3; // bx
char *v4; // rax
int *v6; // rax
int *v7; // rax
int *v8; // rax
int *v9; // rax
int *v10; // rax
int optval; // [rsp+4h] [rbp-44h] BYREF
socklen_t len[2]; // [rsp+8h] [rbp-40h] BYREF
struct sockaddr v13; // [rsp+10h] [rbp-38h] BYREF
struct sockaddr addr; // [rsp+20h] [rbp-28h] BYREF

optval = 1;
v1 = socket(2, 1, 6);
if ( v1 < 0 )
{
v9 = _errno_location();
error(1, *v9, "socket");
}
if ( setsockopt(v1, 1, 2, &optval, 4u) < 0 )
{
v8 = _errno_location();
error(1, *v8, "setsockopt (reuse address)");
}
v13 = 0LL;
v13.sa_family = 2;
*(_DWORD *)&v13.sa_data[2] = func2((unsigned int)v1, &v13, 16LL);
if ( bind(v1, &v13, v2) < 0 )
{
v7 = _errno_location();
error(1, *v7, "bind");
}
*(_QWORD *)len = 16LL;
if ( getsockname(v1, &addr, len) )
{
v6 = _errno_location();
error(1, *v6, "getsockname");
}
v3 = func1(*(__int16 *)addr.sa_data);
v4 = inet_ntoa(*(struct in_addr *)&addr.sa_data[2]);
sprintf(s, "[%s] <%d>\n", v4, v3);
if ( listen(v1, 1) < 0 )
{
v10 = _errno_location();
error(1, *v10, "listen");
}
getsockname(v1, &addr, len);
return (unsigned int)v1;
}

original_code:
int
tcp_server (char *buf)
{
 int sock;
 struct sockaddr_in s;
 struct sockaddr_in t;
 int on=1;
 size_t len;
 if ((sock = socket (2, SOCK_STREAM, IPPROTO_TCP)) < 0) {
  error(1,(*__errno_location ()),"socket");
 }
 if (setsockopt(sock, 1, 2, (char *)&on, sizeof (on)) < 0) {
  error(1,(*__errno_location ()),"setsockopt (reuse address)");
 }
 memset (&s, 0, sizeof (s));
 s.sin_family = 2;
 s.sin_port=0;
 s.sin_addr.s_addr=htonl(((in_addr_t) 0x00000000));
 if (bind(sock, (struct sockaddr *)&s, sizeof (s)) < 0) {
  error(1,(*__errno_location ()),"bind");
 }
 len=sizeof(t);
 if (getsockname (sock, (struct sockaddr *) &t, &len)) {
  error(1,(*__errno_location ()),"getsockname");
 }
 sprintf(buf,"[%s] <%d>\n",inet_ntoa(t.sin_addr),ntohs(t.sin_port));
 if (listen(sock, 1) < 0) {
  error(1,(*__errno_location ()),"listen");
 }
 getsockname (sock, (struct sockaddr *) &t, &len);
 return (sock);
}

canonical_original_code:
int tcp_server(char *buf)
{
 int sock;
 struct sockaddr_in s;
 struct sockaddr_in t;
 int on = 1;
 unsigned long len;
 if ((sock = socket (2, SOCK_STREAM, IPPROTO_TCP)) < 0) {
  error(1,(*__errno_location ()),"socket");
 }
 if (setsockopt(sock, 1, 2, (char *)&on, sizeof (on)) < 0) {
  error(1,(*__errno_location ()),"setsockopt (reuse address)");
 }
 memset (&s, 0, sizeof (s));
 s.sin_family = 2;
 s.sin_port=0;
 s.sin_addr.s_addr=htonl(((unsigned int) 0x00000000));
 if (bind(sock, (struct sockaddr *)&s, sizeof (s)) < 0) {
  error(1,(*__errno_location ()),"bind");
 }
 len=sizeof(t);
 if (getsockname (sock, (struct sockaddr *) &t, &len)) {
  error(1,(*__errno_location ()),"getsockname");
 }
 sprintf(buf,"[%s] <%d>\n",inet_ntoa(t.sin_addr),ntohs(t.sin_port));
 if (listen(sock, 1) < 0) {
  error(1,(*__errno_location ()),"listen");
 }
 getsockname (sock, (struct sockaddr *) &t, &len);
 return (sock);
}

variable_types:
buf
char *

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: on int

variable_types:
len
unsigned long


decompiled_code:
__int64 __fastcall tcp_accept(int fd)
{
int v1; // ebx
int v2; // er12
int v3; // esi
socklen_t addr_len[2]; // [rsp+0h] [rbp-30h] BYREF
struct sockaddr addr; // [rsp+8h] [rbp-28h] BYREF

v1 = 6;
*(_QWORD *)addr_len = 16LL;
addr = 0LL;
while ( 1 )
{
signal(14, (__sighandler_t)tcp_alarm_handler);
alarm(0x1Eu);
v2 = accept(fd, &addr, addr_len);
if ( v2 >= 0 )
break;
v3 = *_errno_location();
if ( v3 == 4 )
{
if ( --v1 )
continue;
}
error(1, v3, "accept");
break;
}
alarm(0);
return (unsigned int)v2;
}

canonical_decompiled_code:
__int64 __fastcall func4(int fd)
{
int v1; // ebx
int v2; // er12
int v3; // esi
socklen_t addr_len[2]; // [rsp+0h] [rbp-30h] BYREF
struct sockaddr addr; // [rsp+8h] [rbp-28h] BYREF

v1 = 6;
*(_QWORD *)addr_len = 16LL;
addr = 0LL;
while ( 1 )
{
signal(14, (__sighandler_t)tcp_alarm_handler);
alarm(0x1Eu);
v2 = accept(fd, &addr, addr_len);
if ( v2 >= 0 )
break;
v3 = *_errno_location();
if ( v3 == 4 )
{
if ( --v1 )
continue;
}
error(1, v3, "accept");
break;
}
alarm(0);
return (unsigned int)v2;
}

original_code:
int
tcp_accept (int d)
{
 int so;
 struct sockaddr_in s;
 size_t namelen;
 int num=0;
 namelen = sizeof(s);
 memset((char*)&s,0, namelen);
retry:
 signal(14, tcp_alarm_handler);
 alarm(30);
 if ((so = accept(d, (struct sockaddr*)&s, &namelen)) < 0) {
  if ((*__errno_location ()) == 4) {
   if (++num<=5)
    goto retry;
  }
  error(1,(*__errno_location ()),"accept");
 }
 alarm(0);
 return so;
}

canonical_original_code:
int tcp_accept(int d)
{
 int so;
 struct sockaddr_in s;
 unsigned long namelen;
 int num = 0;
 namelen = sizeof(s);
 memset((char *)&s,0, namelen);
retry:
 signal(14, tcp_alarm_handler);
 alarm(30);
 if ((so = accept(d, (struct sockaddr *)&s, &namelen)) < 0) {
  if ((*__errno_location ()) == 4) {
   if (++num<=5)
    goto retry;
  }
  error(1,(*__errno_location ()),"accept");
 }
 alarm(0);
 return so;
}

variable_types: d int

variable_types: so int

variable_types:
namelen
unsigned long

variable_types: num int


decompiled_code:
__int64 __fastcall tcp_connect(__int64 a1)
{
bool v1; // zf
const char *v2; // r12
char *v3; // rbx
const char *v4; // rbp
const unsigned __int16 *v5; // rcx
__int64 v6; // rdx
__int16 v7; // ax
int v8; // edx
int v9; // er12
int *v11; // rax
int *v12; // rax
struct hostent *v13; // rbx
struct sockaddr dest; // [rsp+0h] [rbp-28h] BYREF

v1 = *(_BYTE *)a1 == 91;
dest = 0LL;
dest.sa_family = 2;
if ( !v1 )
error(1, 0, "tcp_connect: illegal format1\n");
v2 = (const char *)(a1 + 1);
v3 = strchr((const char *)(a1 + 1), 93);
if ( !v3 )
error(1, 0, "tcp_connect: illegal format2\n");
*v3 = 0;
v4 = v3 + 1;
*(_DWORD *)&dest.sa_data[2] = inet_addr(v2);
if ( *(_DWORD *)&dest.sa_data[2] == -1 )
{
v13 = gethostbyname(v2);
if ( !v13 )
error(1, 0, "tcp_connect: illegal format3\n");
memcpy(&dest.sa_data[2], *(const void **)v13->h_addr_list, v13->h_length);
}
v5 = *_ctype_b_loc();
do
v6 = *(unsigned __int8 *)v4++;
while ( (v5[v6] & 0x2000) != 0 );
if ( (_BYTE)v6 != 60 )
error(1, 0, "tcp_connect: illegal format4\n");
if ( !strchr(v4, 62) )
error(1, 0, "tcp_connect: illegal format5\n");
v7 = strtol(v4, 0LL, 10);
*(_WORD *)dest.sa_data = _bswap_16(v7);
v9 = socket(2, 1, v8);
if ( v9 < 0 )
{
v11 = _errno_location();
error(1, *v11, "socket");
}
signal(14, (__sighandler_t)tcp_alarm_handler);
alarm(0x1Eu);
if ( connect(v9, &dest, 0x10u) < 0 )
{
v12 = _errno_location();
error(1, *v12, "connect");
}
alarm(0);
return (unsigned int)v9;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1)
{
bool v1; // zf
const char *v2; // r12
char *v3; // rbx
const char *v4; // rbp
const unsigned __int16 *v5; // rcx
__int64 v6; // rdx
__int16 v7; // ax
int v8; // edx
int v9; // er12
int *v11; // rax
int *v12; // rax
struct hostent *v13; // rbx
struct sockaddr dest; // [rsp+0h] [rbp-28h] BYREF

v1 = *(_BYTE *)a1 == 91;
dest = 0LL;
dest.sa_family = 2;
if ( !v1 )
error(1, 0, "tcp_connect: illegal format1\n");
v2 = (const char *)(a1 + 1);
v3 = strchr((const char *)(a1 + 1), 93);
if ( !v3 )
error(1, 0, "tcp_connect: illegal format2\n");
*v3 = 0;
v4 = v3 + 1;
*(_DWORD *)&dest.sa_data[2] = inet_addr(v2);
if ( *(_DWORD *)&dest.sa_data[2] == -1 )
{
v13 = gethostbyname(v2);
if ( !v13 )
error(1, 0, "tcp_connect: illegal format3\n");
memcpy(&dest.sa_data[2], *(const void **)v13->h_addr_list, v13->h_length);
}
v5 = *_ctype_b_loc();
do
v6 = *(unsigned __int8 *)v4++;
while ( (v5[v6] & 0x2000) != 0 );
if ( (_BYTE)v6 != 60 )
error(1, 0, "tcp_connect: illegal format4\n");
if ( !strchr(v4, 62) )
error(1, 0, "tcp_connect: illegal format5\n");
v7 = strtol(v4, 0LL, 10);
*(_WORD *)dest.sa_data = func1(v7);
v9 = socket(2, 1, v8);
if ( v9 < 0 )
{
v11 = _errno_location();
error(1, *v11, "socket");
}
signal(14, (__sighandler_t)tcp_alarm_handler);
alarm(0x1Eu);
if ( connect(v9, &dest, 0x10u) < 0 )
{
v12 = _errno_location();
error(1, *v12, "connect");
}
alarm(0);
return (unsigned int)v9;
}

original_code:
int
tcp_connect (char *buf)
{
 int sock;
 struct sockaddr_in s_in;
 char *p;
 char *q;
 memset(&s_in,0,sizeof(s_in));
 s_in.sin_family = 2;
 if (*buf!='[') {
  error(1,0,"tcp_connect: illegal format1\n");
 }
 p=strchr(buf+1,']');
 if (!p) {
  error(1,0,"tcp_connect: illegal format2\n");
 }
 *p++=0;
 s_in.sin_addr.s_addr=inet_addr(buf+1);
 if (s_in.sin_addr.s_addr== (unsigned long) ((in_addr_t) 0xffffffff)) {
  struct hostent *h=gethostbyname(buf+1);
  if (!h)
   error(1,0,"tcp_connect: illegal format3\n");
  memcpy(& s_in.sin_addr.s_addr,h->h_addr_list[0],h->h_length);
 }
 while (((*__ctype_b_loc ())[(int) (((unsigned char)(*p)))] & (unsigned short int) _ISspace))
  p++;
 if (*p!='<') {
  error(1,0,"tcp_connect: illegal format4\n");
 }
 q=strchr(p+1,'>');
 if (!q)
  error(1,0,"tcp_connect: illegal format5\n");
 s_in.sin_port = htons(strtol(p+1,((void *)0),10));
 if ((sock = socket (2, SOCK_STREAM, IPPROTO_TCP)) < 0) {
  error(1,(*__errno_location ()),"socket");
 }
 signal(14, tcp_alarm_handler);
 alarm(30);
 if (connect (sock, (struct sockaddr *) &s_in, sizeof (s_in)) < 0) {
  error(1,(*__errno_location ()),"connect");
 }
 alarm(0);
 return (sock);
}

canonical_original_code:
int tcp_connect(char *buf)
{
 int sock;
 struct sockaddr_in s_in;
 char *p;
 char *q;
 memset(&s_in,0,sizeof(s_in));
 s_in.sin_family = 2;
 if (*buf!='[') {
  error(1,0,"tcp_connect: illegal format1\n");
 }
 p=strchr(buf+1,']');
 if (!p) {
  error(1,0,"tcp_connect: illegal format2\n");
 }
 *p++=0;
 s_in.sin_addr.s_addr=inet_addr(buf+1);
 if (s_in.sin_addr.s_addr== (unsigned long) ((unsigned int) 0xffffffff)) {
  struct hostent *h = gethostbyname(buf+1);
  if (!h)
   error(1,0,"tcp_connect: illegal format3\n");
  memcpy(& s_in.sin_addr.s_addr,h->h_addr_list[0],h->h_length);
 }
 while (((*__ctype_b_loc ())[(int) (((unsigned char)(*p)))] & (unsigned short) _ISspace))
  p++;
 if (*p!='<') {
  error(1,0,"tcp_connect: illegal format4\n");
 }
 q=strchr(p+1,'>');
 if (!q)
  error(1,0,"tcp_connect: illegal format5\n");
 s_in.sin_port = htons(strtol(p+1,((void *)0),10));
 if ((sock = socket (2, SOCK_STREAM, IPPROTO_TCP)) < 0) {
  error(1,(*__errno_location ()),"socket");
 }
 signal(14, tcp_alarm_handler);
 alarm(30);
 if (connect (sock, (struct sockaddr *) &s_in, sizeof (s_in)) < 0) {
  error(1,(*__errno_location ()),"connect");
 }
 alarm(0);
 return (sock);
}

variable_types:
p
char *

variable_types:
q
char *

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


getspeed

decompiled_code:
__int64 __fastcall getspeed(int a1)
{
unsigned int *v1; // rax
int v2; // edx
unsigned int v3; // er8

v1 = (unsigned int *)&unk_4C8;
v2 = 3;
v3 = 110;
while ( 1 )
{
if ( a1 == v2 )
return v3;
v3 = *v1;
v1 += 2;
if ( !v3 )
break;
v2 = *(v1 - 1);
}
return 38400LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1)
{
unsigned int *v1; // rax
int v2; // edx
unsigned int v3; // er8

v1 = (unsigned int *)&unk_4C8;
v2 = 3;
v3 = 110;
while ( 1 )
{
if ( a1 == v2 )
return v3;
v3 = *v1;
v1 += 2;
if ( !v3 )
break;
v2 = *(v1 - 1);
}
return 38400LL;
}

original_code:
static unsigned
getspeed(speed_t code)
{
 int n;
 for (n=0; speeds[n].baudr; ++n)
  if (speeds[n].speedcode == code)
   return speeds[n].baudr;
 return 38400;
}

canonical_original_code:
static unsigned int getspeed(unsigned int code)
{
 int n;
 for (n=0; speeds[n].baudr; ++n)
  if (speeds[n].speedcode == code)
   return speeds[n].baudr;
 return 38400;
}

variable_types:
code
unsigned int

variable_types: n int

return_type: unsigned int