decompiled_code:
ssize_t __fastcall udp_recvfrom(int a1, void *a2, size_t a3, struct sockaddr *a4)
{
ssize_t v4; // rax
ssize_t v5; // r12
ssize_t result; // rax
socklen_t addr_len[3]; // [rsp+Ch] [rbp-Ch] BYREF

addr_len[0] = 16;
v4 = recvfrom(a1, a2, a3, 0, a4, addr_len);
if ( v4 < 0 )
{
perror("recvfrom");
result = -*_errno_location();
}
else
{
v5 = v4;
if ( opt_verbose )
fprintf(stderr, "DEBUG: UDP recvfrom size %ld [in %s() at src/udp.c:115]\n", v4, "udp_recvfrom");
result = v5;
}
return result;
}

canonical_decompiled_code:
ssize_t __fastcall func5(int a1, void *a2, size_t a3, struct sockaddr *a4)
{
ssize_t v4; // rax
ssize_t v5; // r12
ssize_t result; // rax
socklen_t addr_len[3]; // [rsp+Ch] [rbp-Ch] BYREF

addr_len[0] = 16;
v4 = recvfrom(a1, a2, a3, 0, a4, addr_len);
if ( v4 < 0 )
{
perror("recvfrom");
result = -*_errno_location();
}
else
{
v5 = v4;
if ( opt_verbose )
fprintf(stderr, "DEBUG: UDP recvfrom size %ld [in %s() at src/udp.c:115]\n", v4, "udp_recvfrom");
result = v5;
}
return result;
}

original_code:
ssize_t udp_recvfrom(int sock, void *buf, size_t len,
  struct sockaddr *src_addr)
{
 ssize_t recv_size;
 socklen_t addrlen = sizeof(struct sockaddr);
 recv_size = recvfrom(sock, buf, len, 0, src_addr, &addrlen);
 if (recv_size < 0) {
  perror("recvfrom");
  recv_size = -(*__errno_location ());
  goto error;
 }
 do { if (opt_verbose && (0x1 & 0x1)) { fprintf(stderr, "DEBUG: " "UDP recvfrom size %ld" " [in %s() at " "src/udp.c" ":" "115" "]\n", recv_size, __func__); } else if (0x1 & 0x2) { fprintf(stderr, "DEBUG: " "UDP recvfrom size %ld" " [in %s() at " "src/udp.c" ":" "115" "]\n", recv_size, __func__); } } while (0);;
error:
 return recv_size;
}

canonical_original_code:
long udp_recvfrom(int sock, void *buf, unsigned long len, struct sockaddr *src_addr)
{
 long recv_size;
 unsigned int addrlen = sizeof(struct sockaddr);
 recv_size = recvfrom(sock, buf, len, 0, src_addr, &addrlen);
 if (recv_size < 0) {
  perror("recvfrom");
  recv_size = -(*__errno_location ());
  goto error;
 }
 do { if (opt_verbose && (0x1 & 0x1)) { fprintf(stderr, "DEBUG: " "UDP recvfrom size %ld" " [in %s() at " "src/udp.c" ":" "115" "]\n", recv_size, __func__); } else if (0x1 & 0x2) { fprintf(stderr, "DEBUG: " "UDP recvfrom size %ld" " [in %s() at " "src/udp.c" ":" "115" "]\n", recv_size, __func__); } } while (0);;
error:
 return recv_size;
}


repo: dgoulet/debind

decompiled_code:
__int64 netfilter_write_log()
{
return dns_log(log_file, pkt_buffer);
}

canonical_decompiled_code:
__int64 func4()
{
return dns_log(log_file, pkt_buffer);
}

original_code:
void netfilter_write_log(void)
{
 dns_log(log_file, pkt_buffer);
}

canonical_original_code:
void netfilter_write_log()
{
 dns_log(log_file, pkt_buffer);
}

return_type: void


decompiled_code:
__int64 netfilter_init()
{
__int64 v0; // rax

v0 = nfq_open();
handle = v0;
if ( v0 )
{
if ( (int)nfq_unbind_pf(v0, 2LL) < 0 )
{
fwrite("Error: error during nfq_unbind_pf()\n", 1uLL, 0x24uLL, stderr);
}
else if ( (int)nfq_bind_pf(handle, 2LL) < 0 )
{
fwrite("Error: error during nfq_bind_pf()\n", 1uLL, 0x22uLL, stderr);
}
else
{
queue_handle = nfq_create_queue(handle, 0LL, packet_handler, 0LL);
if ( queue_handle )
{
if ( (int)nfq_set_mode(queue_handle, 2LL, 0xFFFFLL) >= 0 )
return nfq_fd(handle);
fwrite("Error: can't set packet_copy mode\n", 1uLL, 0x22uLL, stderr);
}
else
{
fwrite("Error: Error during nfq_create_queue\n", 1uLL, 0x25uLL, stderr);
}
}
}
else
{
fwrite("Error: Error during nfq_open()\n", 1uLL, 0x1FuLL, stderr);
}
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 func5()
{
__int64 v0; // rax

v0 = nfq_open();
handle = v0;
if ( v0 )
{
if ( (int)nfq_unbind_pf(v0, 2LL) < 0 )
{
fwrite("Error: error during nfq_unbind_pf()\n", 1uLL, 0x24uLL, stderr);
}
else if ( (int)nfq_bind_pf(handle, 2LL) < 0 )
{
fwrite("Error: error during nfq_bind_pf()\n", 1uLL, 0x22uLL, stderr);
}
else
{
queue_handle = nfq_create_queue(handle, 0LL, packet_handler, 0LL);
if ( queue_handle )
{
if ( (int)nfq_set_mode(queue_handle, 2LL, 0xFFFFLL) >= 0 )
return nfq_fd(handle);
fwrite("Error: can't set packet_copy mode\n", 1uLL, 0x22uLL, stderr);
}
else
{
fwrite("Error: Error during nfq_create_queue\n", 1uLL, 0x25uLL, stderr);
}
}
}
else
{
fwrite("Error: Error during nfq_open()\n", 1uLL, 0x1FuLL, stderr);
}
return 0xFFFFFFFFLL;
}

original_code:
int netfilter_init(void)
{
 int ret;
 handle = nfq_open();
 if (handle == ((void *)0)) {
  do { if (opt_verbose && (0x2 & 0x1)) { fprintf(stderr, "Error: " "Error during nfq_open()" "\n"); } else if (0x2 & 0x2) { fprintf(stderr, "Error: " "Error during nfq_open()" "\n"); } } while (0);;
  goto error;
 }
 ret = nfq_unbind_pf(handle, 2);
 if (ret < 0) {
  do { if (opt_verbose && (0x2 & 0x1)) { fprintf(stderr, "Error: " "error during nfq_unbind_pf()" "\n"); } else if (0x2 & 0x2) { fprintf(stderr, "Error: " "error during nfq_unbind_pf()" "\n"); } } while (0);;
  goto error;
 }
 ret = nfq_bind_pf(handle, 2);
 if (ret < 0) {
  do { if (opt_verbose && (0x2 & 0x1)) { fprintf(stderr, "Error: " "error during nfq_bind_pf()" "\n"); } else if (0x2 & 0x2) { fprintf(stderr, "Error: " "error during nfq_bind_pf()" "\n"); } } while (0);;
  goto error;
 }
 queue_handle = nfq_create_queue(handle, 0, &packet_handler, ((void *)0));
 if (queue_handle == ((void *)0)) {
  do { if (opt_verbose && (0x2 & 0x1)) { fprintf(stderr, "Error: " "Error during nfq_create_queue" "\n"); } else if (0x2 & 0x2) { fprintf(stderr, "Error: " "Error during nfq_create_queue" "\n"); } } while (0);;
  goto error;
 }
 ret = nfq_set_mode(queue_handle, NFQNL_COPY_PACKET, 0xffff);
 if (ret < 0) {
  do { if (opt_verbose && (0x2 & 0x1)) { fprintf(stderr, "Error: " "can't set packet_copy mode" "\n"); } else if (0x2 & 0x2) { fprintf(stderr, "Error: " "can't set packet_copy mode" "\n"); } } while (0);;
  goto error;
 }
 return nfq_fd(handle);
error:
 return -1;
}

canonical_original_code:
int netfilter_init()
{
 int ret;
 handle = nfq_open();
 if (handle == ((void *)0)) {
  do { if (opt_verbose && (0x2 & 0x1)) { fprintf(stderr, "Error: " "Error during nfq_open()" "\n"); } else if (0x2 & 0x2) { fprintf(stderr, "Error: " "Error during nfq_open()" "\n"); } } while (0);;
  goto error;
 }
 ret = nfq_unbind_pf(handle, 2);
 if (ret < 0) {
  do { if (opt_verbose && (0x2 & 0x1)) { fprintf(stderr, "Error: " "error during nfq_unbind_pf()" "\n"); } else if (0x2 & 0x2) { fprintf(stderr, "Error: " "error during nfq_unbind_pf()" "\n"); } } while (0);;
  goto error;
 }
 ret = nfq_bind_pf(handle, 2);
 if (ret < 0) {
  do { if (opt_verbose && (0x2 & 0x1)) { fprintf(stderr, "Error: " "error during nfq_bind_pf()" "\n"); } else if (0x2 & 0x2) { fprintf(stderr, "Error: " "error during nfq_bind_pf()" "\n"); } } while (0);;
  goto error;
 }
 queue_handle = nfq_create_queue(handle, 0, &packet_handler, ((void *)0));
 if (queue_handle == ((void *)0)) {
  do { if (opt_verbose && (0x2 & 0x1)) { fprintf(stderr, "Error: " "Error during nfq_create_queue" "\n"); } else if (0x2 & 0x2) { fprintf(stderr, "Error: " "Error during nfq_create_queue" "\n"); } } while (0);;
  goto error;
 }
 ret = nfq_set_mode(queue_handle, NFQNL_COPY_PACKET, 0xffff);
 if (ret < 0) {
  do { if (opt_verbose && (0x2 & 0x1)) { fprintf(stderr, "Error: " "can't set packet_copy mode" "\n"); } else if (0x2 & 0x2) { fprintf(stderr, "Error: " "can't set packet_copy mode" "\n"); } } while (0);;
  goto error;
 }
 return nfq_fd(handle);
error:
 return -1;
}

variable_types: ret int

return_type: int


decompiled_code:
int netfilter_clean()
{
int result; // eax

nfq_destroy_queue(queue_handle);
result = nfq_close(handle);
if ( log_file )
result = fclose(log_file);
return result;
}

canonical_decompiled_code:
int func6()
{
int result; // eax

nfq_destroy_queue(queue_handle);
result = nfq_close(handle);
if ( log_file )
result = fclose(log_file);
return result;
}

original_code:
void netfilter_clean(void)
{
 nfq_destroy_queue(queue_handle);
 nfq_close(handle);
 if (log_file) {
  fclose(log_file);
 }
}

canonical_original_code:
void netfilter_clean()
{
 nfq_destroy_queue(queue_handle);
 nfq_close(handle);
 if (log_file) {
  fclose(log_file);
 }
}


decompiled_code:
int __fastcall tcp_connect_socket(int fd, __int16 a2)
{
const char *v2; // rdx
int result; // eax
int v4; // [rsp+0h] [rbp-1Ch]
struct sockaddr addr; // [rsp+4h] [rbp-18h] BYREF

addr = 0LL;
addr.sa_family = 2;
*(_WORD *)addr.sa_data = _bswap_16(a2);
if ( v2 )
*(_DWORD *)&addr.sa_data[2] = inet_addr(v2);
else
*(_DWORD *)&addr.sa_data[2] = _bswap_32_constprop_0();
result = connect(fd, &addr, 0x10u);
if ( result < 0 )
{
v4 = result;
perror("connect");
result = v4;
}
return result;
}

canonical_decompiled_code:
int __fastcall func2(int fd, __int16 a2)
{
const char *v2; // rdx
int result; // eax
int v4; // [rsp+0h] [rbp-1Ch]
struct sockaddr addr; // [rsp+4h] [rbp-18h] BYREF

addr = 0LL;
addr.sa_family = 2;
*(_WORD *)addr.sa_data = func0(a2);
if ( v2 )
*(_DWORD *)&addr.sa_data[2] = inet_addr(v2);
else
*(_DWORD *)&addr.sa_data[2] = func1();
result = connect(fd, &addr, 0x10u);
if ( result < 0 )
{
v4 = result;
perror("connect");
result = v4;
}
return result;
}

original_code:
int tcp_connect_socket(int sock, int port, char *ip)
{
 int ret = -1;
 struct sockaddr_in saddr;
 memset(&saddr, 0, sizeof(saddr));
 saddr.sin_family = 2;
 saddr.sin_port = htons(port);
 if (ip != ((void *)0)) {
  saddr.sin_addr.s_addr = inet_addr(ip);
 } else {
  saddr.sin_addr.s_addr = htonl(((in_addr_t) 0x7f000001));
 }
 ret = connect(sock, (struct sockaddr *)&saddr, sizeof(saddr));
 if (ret < 0) {
  perror("connect");
  goto error;
 }
error:
 return ret;
}

canonical_original_code:
int tcp_connect_socket(int sock, int port, char *ip)
{
 int ret = -1;
 struct sockaddr_in saddr;
 memset(&saddr, 0, sizeof(saddr));
 saddr.sin_family = 2;
 saddr.sin_port = htons(port);
 if (ip != ((void *)0)) {
  saddr.sin_addr.s_addr = inet_addr(ip);
 } else {
  saddr.sin_addr.s_addr = htonl(((unsigned int) 0x7f000001));
 }
 ret = connect(sock, (struct sockaddr *)&saddr, sizeof(saddr));
 if (ret < 0) {
  perror("connect");
  goto error;
 }
error:
 return ret;
}

variable_types: sock int

variable_types: port int

variable_types:
ip
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]; }

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:
int tcp_create_socket()
{
int result; // eax
int v1; // [rsp+Ch] [rbp-Ch]

result = socket(2, 1, 6);
if ( result < 0 )
{
v1 = result;
perror("socket tcp");
result = v1;
}
return result;
}

canonical_decompiled_code:
int func3()
{
int result; // eax
int v1; // [rsp+Ch] [rbp-Ch]

result = socket(2, 1, 6);
if ( result < 0 )
{
v1 = result;
perror("socket tcp");
result = v1;
}
return result;
}

original_code:
int tcp_create_socket(void)
{
 int sock;
 sock = socket(2, SOCK_STREAM, IPPROTO_TCP);
 if (sock < 0) {
  perror("socket tcp");
  goto error;
 }
error:
 return sock;
}

canonical_original_code:
int tcp_create_socket()
{
 int sock;
 sock = socket(2, SOCK_STREAM, IPPROTO_TCP);
 if (sock < 0) {
  perror("socket tcp");
  goto error;
 }
error:
 return sock;
}


decompiled_code:
int old_func()
{
return puts("this is deprecated");
}

canonical_decompiled_code:
int func7()
{
return puts("this is deprecated");
}

original_code: void old_func(void) {printf("this is deprecated\n");}

canonical_original_code: void old_func() {printf("this is deprecated\n");}


decompiled_code:
__int64 __fastcall const_func(int a1)
{
return (unsigned int)(a1 + 2);
}

canonical_decompiled_code:
__int64 __fastcall func8(int a1)
{
return (unsigned int)(a1 + 2);
}

original_code: int const_func(int x) { return x + 2; }

canonical_original_code: int const_func(int x) { return x + 2; }

variable_types: x int


decompiled_code:
__int64 __fastcall pure_func(int a1)
{
return (unsigned int)(a1 + 7);
}

canonical_decompiled_code:
__int64 __fastcall func9(int a1)
{
return (unsigned int)(a1 + 7);
}

original_code: int pure_func(int x) { return x + a; }

canonical_original_code: int pure_func(int x) { return x + a; }


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
printf("foo is at %08x, size = %d bytes\n", &foo, 4096LL);
printf("x is at %08x\n", &x);
printf("y is at %08x\n", &y);
printf("sizeof(struct Foo) = %d\n", 8LL);
printf("sizeof(struct Bar) = %d\n", 6LL);
printf("add(1, 1) = %d\n", 2LL);
old_func();
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
printf("foo is at %08x, size = %d bytes\n", &foo, 4096LL);
printf("x is at %08x\n", &x);
printf("y is at %08x\n", &y);
printf("sizeof(struct Foo) = %d\n", 8LL);
printf("sizeof(struct Bar) = %d\n", 6LL);
printf("add(1, 1) = %d\n", 2LL);
func7();
return 0;
}

original_code:
int
main(int argc, char **argv)
{
 printf("foo is at %08x, size = %d bytes\n", &foo, sizeof(foo));
 printf("x is at %08x\n", &x);
 printf("y is at %08x\n", &y);
 printf("sizeof(struct Foo) = %d\n", sizeof(struct Foo));
 printf("sizeof(struct Bar) = %d\n", sizeof(struct Bar));
 printf("add(1, 1) = %d\n", add(1, 1));
 old_func();
 return 0;
}

variable_types: argc int

variable_types:
argv
char **

user_defined_types:
struct Foo { int a; short b; }
struct Bar { int a; short b; }


decompiled_code:
int struct_bitfield()
{
printf("struct Foo_normal is %d bytes\n", 12LL);
return printf("struct Foo is %d bytes\n", 4LL);
}

canonical_decompiled_code:
int func7()
{
printf("struct Foo_normal is %d bytes\n", 12LL);
return printf("struct Foo is %d bytes\n", 4LL);
}

original_code:
void
struct_bitfield(void)
{
 printf("struct Foo_normal is %d bytes\n", sizeof(struct Foo_normal));
 printf("struct Foo is %d bytes\n", sizeof(struct Foo));
}

canonical_original_code:
void struct_bitfield()
{
 printf("struct Foo_normal is %d bytes\n", sizeof(struct Foo_normal));
 printf("struct Foo is %d bytes\n", sizeof(struct Foo));
}

user_defined_types: struct Foo_normal { int a; int b; int c; }


decompiled_code:
int ptr_arith()
{
int v0; // eax
_DWORD *v1; // rdx
unsigned int *v2; // rbp
unsigned int i; // ebx
__int64 v4; // rdx
__int64 v5; // rsi
int result; // eax
_BYTE v7[152]; // [rsp+0h] [rbp-98h] BYREF

v0 = 0;
v1 = v7;
do
{
*v1 = v0++;
v1 += 3;
}
while ( v0 != 10 );
v2 = (unsigned int *)v7;
for ( i = 0; i != 10; ++i )
{
v4 = *v2;
v5 = i;
v2 += 3;
result = printf("foo[%d].a = %d\n", v5, v4);
}
return result;
}

canonical_decompiled_code:
int func8()
{
int v0; // eax
_DWORD *v1; // rdx
unsigned int *v2; // rbp
unsigned int i; // ebx
__int64 v4; // rdx
__int64 v5; // rsi
int result; // eax
_BYTE v7[152]; // [rsp+0h] [rbp-98h] BYREF

v0 = 0;
v1 = v7;
do
{
*v1 = v0++;
v1 += 3;
}
while ( v0 != 10 );
v2 = (unsigned int *)v7;
for ( i = 0; i != 10; ++i )
{
v4 = *v2;
v5 = i;
v2 += 3;
result = printf("foo[%d].a = %d\n", v5, v4);
}
return result;
}

original_code:
void
ptr_arith(void)
{
 struct Foo_normal foo[10];
 int i;
 struct Foo_normal *foo_ptr = &foo[0];
 for (i = 0; i < 10; i++)
  foo[i].a = i;
 for (i = 0; i < 10; i++)
  printf("foo[%d].a = %d\n", i, (foo_ptr++)->a);
}

canonical_original_code:
void ptr_arith()
{
 struct Foo_normal foo[10];
 int i;
 struct Foo_normal *foo_ptr = &foo[0];
 for (i = 0; i < 10; i++)
  foo[i].a = i;
 for (i = 0; i < 10; i++)
  printf("foo[%d].a = %d\n", i, (foo_ptr++)->a);
}

variable_types: struct Foo_normal { int a; int b; int c; } [10]

variable_types: i int

variable_types: struct Foo_normal { int a; int b; int c; } *


original_code:
void
union_demo(void)
{
 union Bar bar;
 bar.a = 0xcafebabe;
 printf("bar.a = %X, bar.b[0] = %X, bar.b[1] = %X\n", bar.a, bar.b[0] & 0xffff, bar.b[1] & 0xffff);
 printf("nib3 = %X, nib7 = %X\n", bar.nib3 & 0xf, bar.nib6 & 0xf);
}

canonical_original_code:
void union_demo()
{
 union Bar bar;
 bar.a = 0xcafebabe;
 printf("bar.a = %X, bar.b[0] = %X, bar.b[1] = %X\n", bar.a, bar.b[0] & 0xffff, bar.b[1] & 0xffff);
 printf("nib3 = %X, nib7 = %X\n", bar.nib3 & 0xf, bar.nib6 & 0xf);
}

variable_types: union Bar { int a; short b[2]; struct { int nib1; int nib2; int nib3; int nib4; int nib5; int nib6; int nib7; int nib8; }; }


decompiled_code:
int __fastcall print_enum(unsigned int a1)
{
if ( a1 == 1 )
return puts("first");
if ( a1 == 5 )
return puts("fifth");
return printf("enum: %d\n", a1);
}

canonical_decompiled_code:
int __fastcall func10(unsigned int a1)
{
if ( a1 == 1 )
return puts("first");
if ( a1 == 5 )
return puts("fifth");
return printf("enum: %d\n", a1);
}

original_code:
void print_enum(enum Baz baz) {
 switch (baz) {
 case first:
  printf("first\n");
  break;
 case fifth:
  printf("fifth\n");
  break;
 default:
  printf("enum: %d\n", baz);
  break;
 }
}

variable_types: enum Baz { first=1, second=2, third=3, fifth=5, sixth=6 }


decompiled_code:
int enum_demo()
{
print_enum(1u);
print_enum(5u);
print_enum(2u);
print_enum(6u);
print_enum(3u);
print_enum(4u);
return print_enum(8u);
}

canonical_decompiled_code:
int func11()
{
func10(1u);
func10(5u);
func10(2u);
func10(6u);
func10(3u);
func10(4u);
return func10(8u);
}

original_code:
void
enum_demo(void)
{
 print_enum(first);
 print_enum(fifth);
 print_enum(second);
 print_enum(sixth);
 print_enum(3);
 print_enum(4);
 print_enum(8);
}

canonical_original_code:
void enum_demo()
{
 print_enum(first);
 print_enum(fifth);
 print_enum(second);
 print_enum(sixth);
 print_enum(3);
 print_enum(4);
 print_enum(8);
}


decompiled_code:
int anon_enum()
{
return printf("red=%d, green=%d, blue=%d\n", 0LL, 1LL, 2LL);
}

canonical_decompiled_code:
int func12()
{
return printf("red=%d, green=%d, blue=%d\n", 0LL, 1LL, 2LL);
}

original_code:
void
anon_enum(void)
{
 printf("red=%d, green=%d, blue=%d\n", red, green, blue);
}

canonical_original_code:
void anon_enum()
{
 printf("red=%d, green=%d, blue=%d\n", red, green, blue);
}


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
struct_bitfield(argc, argv, envp);
ptr_arith();
union_demo();
enum_demo();
anon_enum();
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
func7(argc, argv, envp);
func8();
func9();
func11();
func12();
return 0;
}

original_code:
int
main(int argc, char **argv)
{
 struct_bitfield();
 ptr_arith();
 union_demo();
 enum_demo();
 anon_enum();
 return 0;
}


sub

decompiled_code:
__int64 __fastcall sub(int a1, int a2)
{
return (unsigned int)(a1 - a2);
}

canonical_decompiled_code:
__int64 __fastcall func8(int a1, int a2)
{
return (unsigned int)(a1 - a2);
}

original_code: int sub(int x, int y) { return x - y; }

canonical_original_code: int sub(int x, int y) { return x - y; }

variable_types: y int


mul

decompiled_code:
__int64 __fastcall mul(int a1, int a2)
{
return (unsigned int)(a2 * a1);
}

canonical_decompiled_code:
__int64 __fastcall func9(int a1, int a2)
{
return (unsigned int)(a2 * a1);
}

original_code: int mul(int x, int y) { return x * y; }

canonical_original_code: int mul(int x, int y) { return x * y; }


div

decompiled_code:
__int64 __fastcall div(int a1, int a2)
{
return (unsigned int)(a1 / a2);
}

canonical_decompiled_code:
__int64 __fastcall func10(int a1, int a2)
{
return (unsigned int)(a1 / a2);
}

original_code: int div(int x, int y) { return x / y; }

canonical_original_code: int div(int x, int y) { return x / y; }


decompiled_code:
__int64 switch_helper()
{
print_sw_0(0, 4u, 5u);
print_sw_0(3u, 8u, 2u);
switch_dispatch(7, 0, 0);
switch_dispatch(10, 0, 0);
switch_dispatch(15, 0, 0);
return switch_dispatch(20, 0, 0);
}

original_code:
void
switch_helper(void)
{
 void print_sw(int op, int r, int s) {
  printf("SWCH: op %d (%d, %d) = %d\n", op, r, s, switch_dispatch(op, r, s));
 }
 print_sw(OP_ADD, 4, 5);
 print_sw(OP_DIV, 8, 2);
 switch_dispatch(7, 0, 0);
 switch_dispatch(10, 0, 0);
 switch_dispatch(15, 0, 0);
 switch_dispatch(20, 0, 0);
}

canonical_original_code:
void switch_helper()
{
 void print_sw(int op, int r, int s) {
  printf("SWCH: op %d (%d, %d) = %d\n", op, r, s, switch_dispatch(op, r, s));
 }
 print_sw(OP_ADD, 4, 5);
 print_sw(OP_DIV, 8, 2);
 switch_dispatch(7, 0, 0);
 switch_dispatch(10, 0, 0);
 switch_dispatch(15, 0, 0);
 switch_dispatch(20, 0, 0);
}


decompiled_code:
__int64 __fastcall func_dispatch(int a1, int a2, int a3)
{
return ((__int64 (__fastcall *)(int, int))jumptable_4[a1])(a2, a3);
}

canonical_decompiled_code:
__int64 __fastcall func14(int a1, int a2, int a3)
{
return ((__int64 (__fastcall *)(int, int))jumptable_4[a1])(a2, a3);
}

original_code:
int
func_dispatch(int op, int x, int y)
{
 static int (*jumptable[OP_MAX])(int a, int b) = {
  [OP_MUL] = mul,
  [OP_SUB] = sub,
  [OP_DIV] = div,
  [OP_ADD] = add
 };
 return jumptable[op](x, y);
}

canonical_original_code:
int func_dispatch(int op, int x, int y)
{
 static int (*jumptable[-1])(int a, int b) = {
  [OP_MUL] = mul,
  [OP_SUB] = sub,
  [OP_DIV] = div,
  [OP_ADD] = add
 };
 return jumptable[op](x, y);
}

variable_types: op int

variable_types:
jumptable
int (*[-1])(int a, int b)


decompiled_code:
int func_helper()
{
print_func_1(0, 4u, 5u);
return print_func_1(3u, 8u, 2u);
}

canonical_decompiled_code:
int func16()
{
func15(0, 4u, 5u);
return func15(3u, 8u, 2u);
}

original_code:
void
func_helper(void)
{
 void print_func(int op, int r, int s) {
  printf("FUNC: op %d (%d, %d) = %d\n", op, r, s, func_dispatch(op, r, s));
 };
 print_func(OP_ADD, 4, 5);
 print_func(OP_DIV, 8, 2);
}

canonical_original_code:
void func_helper()
{
 void print_func(int op, int r, int s) {
  printf("FUNC: op %d (%d, %d) = %d\n", op, r, s, func_dispatch(op, r, s));
 };
 print_func(OP_ADD, 4, 5);
 print_func(OP_DIV, 8, 2);
}


decompiled_code:
int goto_helper()
{
print_goto_2(0, 4u, 5);
return print_goto_2(3, 8u, 2);
}

original_code:
void
goto_helper(void)
{
 void print_goto(int op, int r, int s) {
  printf("GOTO: op %d (%d, %d) = %d\n", op, r, s, goto_dispatch(op, r, s));
 }
 print_goto(OP_ADD, 4, 5);
 print_goto(OP_DIV, 8, 2);
}

canonical_original_code:
void goto_helper()
{
 void print_goto(int op, int r, int s) {
  printf("GOTO: op %d (%d, %d) = %d\n", op, r, s, goto_dispatch(op, r, s));
 }
 print_goto(OP_ADD, 4, 5);
 print_goto(OP_DIV, 8, 2);
}


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
switch_helper(argc, argv, envp);
func_helper();
goto_helper();
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
func13(argc, argv, envp);
func16();
func19();
return 0;
}

original_code:
int
main(int argc, char **argv)
{
 switch_helper();
 func_helper();
 goto_helper();
 return 0;
}


add

decompiled_code:
__int64 __fastcall add(int a1, int a2)
{
return (unsigned int)(a1 + a2);
}

canonical_decompiled_code:
__int64 __fastcall func7(int a1, int a2)
{
return (unsigned int)(a1 + a2);
}

original_code: int add(int x, int y) { return x + y; }

canonical_original_code: int add(int x, int y) { return x + y; }


decompiled_code:
int func_foo()
{
return puts("function foo");
}

canonical_decompiled_code:
int func7()
{
return puts("function foo");
}

original_code: void func_foo(void) {printf("function foo\n");}

canonical_original_code: void func_foo() {printf("function foo\n");}


decompiled_code:
int func_bar()
{
return puts("function bar");
}

canonical_decompiled_code:
int func8()
{
return puts("function bar");
}

original_code: void func_bar(void) {printf("function bar\n");}

canonical_original_code: void func_bar() {printf("function bar\n");}


decompiled_code:
int func_baz()
{
return puts("function baz");
}

canonical_decompiled_code:
int func9()
{
return puts("function baz");
}

original_code: void func_baz(void) {printf("function baz\n");}

canonical_original_code: void func_baz() {printf("function baz\n");}


decompiled_code:
int func_quux()
{
return puts("function quux");
}

canonical_decompiled_code:
int func10()
{
return puts("function quux");
}

original_code: void func_quux(void) {printf("function quux\n");}

canonical_original_code: void func_quux() {printf("function quux\n");}


decompiled_code:
void part2()
{
;
}

canonical_decompiled_code:
void func8()
{
;
}

original_code:
void
part2(void)
{
 meter a = 19;
 mile b = a;
}

canonical_original_code:
void part2()
{
 int a = 19;
 int b = a;
}

variable_types: a int

variable_types: b int


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
part1(argc, argv, envp);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
func7(argc, argv, envp);
return 0;
}

original_code:
int
main(int argc, char **argv)
{
 part1();
 part2();
 return 0;
}


decompiled_code:
void *__fastcall type_dup(__int64 (**a1)(void), const void *a2, __int64 (__fastcall *a3)(size_t))
{
size_t v4; // r12
void *v5; // rax
void *v6; // r8

if ( !a2 )
return 0LL;
v4 = (*a1)();
v5 = (void *)a3(v4);
v6 = v5;
if ( v5 )
v6 = memcpy(v5, a2, v4);
return v6;
}

canonical_decompiled_code:
void *__fastcall func30(__int64 (**a1)(void), const void *a2, __int64 (__fastcall *a3)(size_t))
{
size_t v4; // r12
void *v5; // rax
void *v6; // r8

if ( !a2 )
return 0LL;
v4 = (*a1)();
v5 = (void *)a3(v4);
v6 = v5;
if ( v5 )
v6 = memcpy(v5, a2, v4);
return v6;
}

original_code:
void *type_dup(const type_t *t, const void *data, init_f alloc)
{
  if (data == ((void *)0))
  { return(((void *)0)); }
  size_t size = t->size(t, data);
  void *ddata = alloc(size);
  if (ddata != ((void *)0))
  { memcpy(ddata, data, size); }
  return(ddata);
}

canonical_original_code:
void *type_dup(struct type_t *t, void *data, void *(*alloc)(unsigned long))
{
  if (data == ((void *)0))
  { return(((void *)0)); }
  unsigned long size = t->size(t, data);
  void *ddata = alloc(size);
  if (ddata != ((void *)0))
  { memcpy(ddata, data, size); }
  return(ddata);
}

variable_types: struct type_t { unsigned long (*size)(struct type_t *, void *); enum ord_e { EQ=0, LT=1, GT=2 } (*compare)(struct type_t *, void *, void *); _Bool (*equals)(struct type_t *, void *, void *); unsigned long (*hashcode)(struct type_t *, void *); } *

variable_types:
data
void *

variable_types:
alloc
void *(*)(unsigned long)

variable_types:
size
unsigned long

variable_types:
ddata
void *

return_type: void *

user_defined_types: struct type_t { unsigned long (*size)(struct type_t *, void *); enum ord_e (*compare)(struct type_t *, void *, void *); _Bool (*equals)(struct type_t *, void *, void *); unsigned long (*hashcode)(struct type_t *, void *); }


repo: dhruvbhaskar/tic-tac-toe

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // eax
const char *v4; // rbp
_BOOL8 v5; // rbp
int v6; // ebx
_BYTE v8[9]; // [rsp+3h] [rbp-35h] BYREF
char s1[10]; // [rsp+Ch] [rbp-2Ch] BYREF
char v10[34]; // [rsp+16h] [rbp-22h] BYREF

strcpy(s1, "easy");
strcpy(v10, "advanced");
v3 = time(0LL);
srand(v3);
if ( argc <= 1 )
{
puts("\n\nUsage : Give argument 'easy' for easy or 'advanced' for advanced level \n");
}
else
{
v4 = argv[1];
if ( !strcmp(s1, v4) || !strcmp(v10, v4) )
{
puts("\nTIC-TAC-TOE \n ");
qmemcpy(v8, "123456789", sizeof(v8));
print_board(v8);
v5 = strcmp(s1, argv[1]) != 0;
v6 = 0;
while ( 1 )
{
if ( (v6++ & 1) != 0 )
comp_move(v8, v5);
else
user_turn(v8);
print_board(v8);
if ( (unsigned int)check_win(v8) )
break;
if ( v6 == 9 )
{
puts("\n\nIts's a draw!\n");
return 0;
}
}
if ( (v6 & 1) != 0 )
puts("\n\nYou Win!\n");
else
puts("\n\nComputer Wins!\n");
}
else
{
puts("\nARGUMENT NOT RECOGNIZED \n ");
}
}
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // eax
const char *v4; // rbp
_BOOL8 v5; // rbp
int v6; // ebx
_BYTE v8[9]; // [rsp+3h] [rbp-35h] BYREF
char s1[10]; // [rsp+Ch] [rbp-2Ch] BYREF
char v10[34]; // [rsp+16h] [rbp-22h] BYREF

strcpy(s1, "easy");
strcpy(v10, "advanced");
v3 = time(0LL);
srand(v3);
if ( argc <= 1 )
{
puts("\n\nUsage : Give argument 'easy' for easy or 'advanced' for advanced level \n");
}
else
{
v4 = argv[1];
if ( !strcmp(s1, v4) || !strcmp(v10, v4) )
{
puts("\nTIC-TAC-TOE \n ");
qmemcpy(v8, "123456789", sizeof(v8));
func8(v8);
v5 = strcmp(s1, argv[1]) != 0;
v6 = 0;
while ( 1 )
{
if ( (v6++ & 1) != 0 )
func7(v8, v5);
else
func9(v8);
func8(v8);
if ( (unsigned int)func10(v8) )
break;
if ( v6 == 9 )
{
puts("\n\nIts's a draw!\n");
return 0;
}
}
if ( (v6 & 1) != 0 )
puts("\n\nYou Win!\n");
else
puts("\n\nComputer Wins!\n");
}
else
{
puts("\nARGUMENT NOT RECOGNIZED \n ");
}
}
return 0;
}

original_code:
int main (int argc, char *argv[])
{
 char str1[10];
 char str2[10];
 strcpy (str1, "easy");
 strcpy (str2, "advanced");
 srand (time (((void *)0)));
 if (argc < 2)
  printf("\n\nUsage : Give argument 'easy' for easy or 'advanced' for advanced level \n\n");
 else if (strcmp (str1, argv[1]) != 0 && strcmp (str2, argv[1]) != 0)
  printf ("\nARGUMENT NOT RECOGNIZED \n \n");
 else
 {
  printf ("\nTIC-TAC-TOE \n \n");
  char board[] = { '1', '2', '3', '4', '5', '6', '7', '8', '9' };
  int i;
  print_board (board);
  if (strcmp (str1, argv[1]) == 0)
   i = 0;
  else
   i = 1;
  int turn_number = 0;
  int is_win = 0;
  while (turn_number < 9)
  {
   if (turn_number % 2 == 0)
    user_turn(board);
   else
    comp_move(board, i);
   turn_number++;
   print_board (board);
   if (check_win(board))
   {
    if (turn_number % 2 == 1)
     printf("\n\nYou Win!\n\n");
    else
     printf("\n\nComputer Wins!\n\n");
    is_win = 1;
    break;
   }
  }
  if (is_win == 0)
  printf("\n\nIts's a draw!\n\n");
 }
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
 char str1[10];
 char str2[10];
 strcpy (str1, "easy");
 strcpy (str2, "advanced");
 srand (time (((void *)0)));
 if (argc < 2)
  printf("\n\nUsage : Give argument 'easy' for easy or 'advanced' for advanced level \n\n");
 else if (strcmp (str1, argv[1]) != 0 && strcmp (str2, argv[1]) != 0)
  printf ("\nARGUMENT NOT RECOGNIZED \n \n");
 else
 {
  printf ("\nTIC-TAC-TOE \n \n");
  char board[] = { '1', '2', '3', '4', '5', '6', '7', '8', '9' };
  int i;
  print_board (board);
  if (strcmp (str1, argv[1]) == 0)
   i = 0;
  else
   i = 1;
  int turn_number = 0;
  int is_win = 0;
  while (turn_number < 9)
  {
   if (turn_number % 2 == 0)
    user_turn(board);
   else
    comp_move(board, i);
   turn_number++;
   print_board (board);
   if (check_win(board))
   {
    if (turn_number % 2 == 1)
     printf("\n\nYou Win!\n\n");
    else
     printf("\n\nComputer Wins!\n\n");
    is_win = 1;
    break;
   }
  }
  if (is_win == 0)
  printf("\n\nIts's a draw!\n\n");
 }
 return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types:
board
char []


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

if ( a2 )
result = comp_turn();
else
result = comp_random();
return result;
}

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

if ( a2 )
result = comp_turn();
else
result = comp_random();
return result;
}

original_code:
void comp_move (char board[], int i)
{
 if (i == 0)
  comp_random (board);
 else
  comp_turn (board);
}

canonical_original_code:
void comp_move(char board[], int i)
{
 if (i == 0)
  comp_random (board);
 else
  comp_turn (board);
}

variable_types: i int


decompiled_code:
int __fastcall print_board(char *a1)
{
printf("\n %c | %c | %c \n", (unsigned int)*a1, (unsigned int)a1[1], (unsigned int)a1[2]);
puts("---|---|--- ");
printf(" %c | %c | %c \n", (unsigned int)a1[3], (unsigned int)a1[4], (unsigned int)a1[5]);
puts("---|---|--- ");
printf(" %c | %c | %c \n", (unsigned int)a1[6], (unsigned int)a1[7], (unsigned int)a1[8]);
return putchar(10);
}

canonical_decompiled_code:
int __fastcall func8(char *a1)
{
printf("\n %c | %c | %c \n", (unsigned int)*a1, (unsigned int)a1[1], (unsigned int)a1[2]);
puts("---|---|--- ");
printf(" %c | %c | %c \n", (unsigned int)a1[3], (unsigned int)a1[4], (unsigned int)a1[5]);
puts("---|---|--- ");
printf(" %c | %c | %c \n", (unsigned int)a1[6], (unsigned int)a1[7], (unsigned int)a1[8]);
return putchar(10);
}

original_code:
void print_board (char board[])
{
 printf ("\n %c | %c | %c \n", board[0], board[1], board[2]);
 printf ("---|---|--- \n");
 printf (" %c | %c | %c \n", board[3], board[4], board[5]);
 printf ("---|---|--- \n");
 printf (" %c | %c | %c \n", board[6], board[7], board[8]);
 printf("\n");
}

canonical_original_code:
void print_board(char board[])
{
 printf ("\n %c | %c | %c \n", board[0], board[1], board[2]);
 printf ("---|---|--- \n");
 printf (" %c | %c | %c \n", board[3], board[4], board[5]);
 printf ("---|---|--- \n");
 printf (" %c | %c | %c \n", board[6], board[7], board[8]);
 printf("\n");
}


original_code:
int check_win (char board[])
{
 int i;
 for (i = 0; i < 7; i = i + 3)
 {
  if (board[i] == board[i + 1] && board[i + 1] == board[i + 2])
   return 1;
 }
 for (i = 0; i < 3; i = i + 1)
  {
  int m = i;
  if (board[m] == board[m + 3] && board[m + 3] == board[m + 6])
   return 1;
 }
 if (board[0] == board[4] && board[4] == board[8])
  return 1;
 if (board[2] == board[4] && board[4] == board[6])
  return 1;
 return 0;
}

canonical_original_code:
int check_win(char board[])
{
 int i;
 for (i = 0; i < 7; i = i + 3)
 {
  if (board[i] == board[i + 1] && board[i + 1] == board[i + 2])
   return 1;
 }
 for (i = 0; i < 3; i = i + 1)
  {
  int m = i;
  if (board[m] == board[m + 3] && board[m + 3] == board[m + 6])
   return 1;
 }
 if (board[0] == board[4] && board[4] == board[8])
  return 1;
 if (board[2] == board[4] && board[4] == board[6])
  return 1;
 return 0;
}

variable_types: m int


decompiled_code:
__int64 __fastcall comp_check(_BYTE *a1, int a2)
{
_BYTE *v2; // r9
__int64 result; // rax
_BYTE *v4; // r9
char v5; // r10

v2 = &a1[a2];
if ( *v2 == 120 || *v2 == 111 )
return 0LL;
*v2 = 111;
result = check_win(a1);
*v4 = v5;
if ( (_DWORD)result )
result = 1LL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func11(_BYTE *a1, int a2)
{
_BYTE *v2; // r9
__int64 result; // rax
_BYTE *v4; // r9
char v5; // r10

v2 = &a1[a2];
if ( *v2 == 120 || *v2 == 111 )
return 0LL;
*v2 = 111;
result = func10(a1);
*v4 = v5;
if ( (_DWORD)result )
result = 1LL;
return result;
}

original_code:
int comp_check (char board[], int i)
{
 int temp = board[i];
 if (board[i] != 'x' && board[i] != 'o')
 {
  board[i] = 'o';
  if (check_win (board))
  {
   board[i] = temp;
   return 1;
  }
  board[i] = temp;
 }
 return 0;
}

canonical_original_code:
int comp_check(char board[], int i)
{
 int temp = board[i];
 if (board[i] != 'x' && board[i] != 'o')
 {
  board[i] = 'o';
  if (check_win (board))
  {
   board[i] = temp;
   return 1;
  }
  board[i] = temp;
 }
 return 0;
}

variable_types: temp int


decompiled_code:
__int64 __fastcall user_check(_BYTE *a1, int a2)
{
_BYTE *v2; // r9
__int64 result; // rax
_BYTE *v4; // r9
char v5; // r10

v2 = &a1[a2];
if ( *v2 == 120 || *v2 == 111 )
return 0LL;
*v2 = 120;
result = check_win(a1);
*v4 = v5;
if ( (_DWORD)result )
result = 1LL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func12(_BYTE *a1, int a2)
{
_BYTE *v2; // r9
__int64 result; // rax
_BYTE *v4; // r9
char v5; // r10

v2 = &a1[a2];
if ( *v2 == 120 || *v2 == 111 )
return 0LL;
*v2 = 120;
result = func10(a1);
*v4 = v5;
if ( (_DWORD)result )
result = 1LL;
return result;
}

original_code:
int user_check (char board[], int i)
{
 int temp = board[i];
 if (board[i] != 'x' && board[i] != 'o')
 {
  board[i] = 'x';
  if (check_win (board))
  {
   board[i] = temp;
   return 1;
  }
  board[i] = temp;
 }
 return 0;
}

canonical_original_code:
int user_check(char board[], int i)
{
 int temp = board[i];
 if (board[i] != 'x' && board[i] != 'o')
 {
  board[i] = 'x';
  if (check_win (board))
  {
   board[i] = temp;
   return 1;
  }
  board[i] = temp;
 }
 return 0;
}


repo: dhutchis/ppp

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // r14
const char *v4; // r12
const char *v5; // r13
int v6; // ebp
int v7; // er13
__int64 v8; // rax
__int64 v9; // rbp
unsigned int v11; // eax
int v12; // ebp
int v13; // er12
int v14; // edi
_DWORD *v15; // rax
void *v16; // rbp
_DWORD *v17; // rax
int v18; // edi
const char *v19; // rax
char *v20; // rax
char *v21; // rax
pthread_t newthread; // [rsp+8h] [rbp-D0h] BYREF
pthread_attr_t attr; // [rsp+10h] [rbp-C8h] BYREF
char s[136]; // [rsp+50h] [rbp-88h] BYREF

if ( argc != 4 )
DieWithMessage("Usage: name_server php_port loop_port", &unk_1A2);
v3 = argv[1];
v4 = argv[2];
v5 = argv[3];
if ( strlen(v3) > 0xF )
DieWithMessage("name_server is too long - max 15 characters", v3);
v6 = setupTCPServerSocket(v5);
if ( v6 < 0 )
DieWithMessage("SetupTCPServerSocket() failed on loop_port", v5);
v7 = acceptTCPConnection((unsigned int)v6);
close(v6);
snprintf(s, 0x60uLL, "http://www.cs.stevens.edu/~dhutchis/make_conn.php?n=%s&p=%s", v3, v4);
v8 = curl_easy_init();
v9 = v8;
if ( v8 )
{
curl_easy_setopt(v8, 10002LL, s);
v11 = curl_easy_perform(v9);
if ( v11 )
{
v19 = (const char *)curl_easy_strerror(v11);
fprintf(stderr, "curl_easy_perform() failed: %s\n", v19);
}
curl_easy_cleanup(v9);
v12 = setupTCPServerSocket(v4);
if ( v12 < 0 )
DieWithMessage("setupTCPClientSocket() failed on php_port", v4);
v13 = acceptTCPConnection((unsigned int)v12);
close(v12);
v14 = pthread_attr_init(&attr);
if ( v14 )
{
v21 = strerror(v14);
DieWithMessage("pthread_attr_init() failed", v21);
}
pthread_attr_setdetachstate(&attr, 1);
newthread = 0LL;
v15 = malloc(8uLL);
*v15 = v7;
v16 = v15;
v15[1] = v13;
v17 = malloc(8uLL);
*v17 = v13;
v17[1] = v7;
v18 = pthread_create(&newthread, &attr, (void *(*)(void *))thread_main, v17);
if ( v18 )
{
v20 = strerror(v18);
DieWithMessage("pthread_create() failed", v20);
}
pthread_attr_destroy(&attr);
thread_main(v16);
}
fwrite("no curl from curl_easy_init(); libcurl broke\n", 1uLL, 0x2DuLL, stderr);
close(v7);
return 1;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // r14
const char *v4; // r12
const char *v5; // r13
int v6; // ebp
int v7; // er13
__int64 v8; // rax
__int64 v9; // rbp
unsigned int v11; // eax
int v12; // ebp
int v13; // er12
int v14; // edi
_DWORD *v15; // rax
void *v16; // rbp
_DWORD *v17; // rax
int v18; // edi
const char *v19; // rax
char *v20; // rax
char *v21; // rax
pthread_t newthread; // [rsp+8h] [rbp-D0h] BYREF
pthread_attr_t attr; // [rsp+10h] [rbp-C8h] BYREF
char s[136]; // [rsp+50h] [rbp-88h] BYREF

if ( argc != 4 )
DieWithMessage("Usage: name_server php_port loop_port", &unk_1A2);
v3 = argv[1];
v4 = argv[2];
v5 = argv[3];
if ( strlen(v3) > 0xF )
DieWithMessage("name_server is too long - max 15 characters", v3);
v6 = setupTCPServerSocket(v5);
if ( v6 < 0 )
DieWithMessage("SetupTCPServerSocket() failed on loop_port", v5);
v7 = acceptTCPConnection((unsigned int)v6);
close(v6);
snprintf(s, 0x60uLL, "http://www.cs.stevens.edu/~dhutchis/make_conn.php?n=%s&p=%s", v3, v4);
v8 = curl_easy_init();
v9 = v8;
if ( v8 )
{
curl_easy_setopt(v8, 10002LL, s);
v11 = curl_easy_perform(v9);
if ( v11 )
{
v19 = (const char *)curl_easy_strerror(v11);
fprintf(stderr, "curl_easy_perform() failed: %s\n", v19);
}
curl_easy_cleanup(v9);
v12 = setupTCPServerSocket(v4);
if ( v12 < 0 )
DieWithMessage("setupTCPClientSocket() failed on php_port", v4);
v13 = acceptTCPConnection((unsigned int)v12);
close(v12);
v14 = pthread_attr_init(&attr);
if ( v14 )
{
v21 = strerror(v14);
DieWithMessage("pthread_attr_init() failed", v21);
}
pthread_attr_setdetachstate(&attr, 1);
newthread = 0LL;
v15 = malloc(8uLL);
*v15 = v7;
v16 = v15;
v15[1] = v13;
v17 = malloc(8uLL);
*v17 = v13;
v17[1] = v7;
v18 = pthread_create(&newthread, &attr, (void *(*)(void *))thread_main, v17);
if ( v18 )
{
v20 = strerror(v18);
DieWithMessage("pthread_create() failed", v20);
}
pthread_attr_destroy(&attr);
func0(v16);
}
fwrite("no curl from curl_easy_init(); libcurl broke\n", 1uLL, 0x2DuLL, stderr);
close(v7);
return 1;
}

original_code:
int main(int argc, char* argv[]) {
 char *a1, *a2, *p1, *p2;
 int sock1, sock2;
    if (argc != 5)
  DieWithMessage("Usage: address1 port1 address2 port2","");
 a1 = argv[1]; p1 = argv[2]; a2 = argv[3]; p2 = argv[4];
    sock1 = setupTCPClientSocket(a1, p1);
 if (sock1 < 0)
        DieWithMessage("setupTCPClientSocket() failed to connect to", a1);
 sock2 = setupTCPClientSocket(a2, p2);
 if (sock2 < 0)
        DieWithMessage("setupTCPClientSocket() failed to connect to", a2);
 pthread_attr_t thr_options;
    int rtnVal = pthread_attr_init(&thr_options);
    if (rtnVal != 0)
        DieWithMessage("pthread_attr_init() failed", strerror(rtnVal));
    pthread_attr_setdetachstate(&thr_options, PTHREAD_CREATE_DETACHED);
 t_thread_args *thrarg1, *thrarg2;
 pthread_t tid2=0;
 thrarg1 = (t_thread_args*)malloc(sizeof(t_thread_args));
 thrarg1->sock1 = sock1; thrarg1->sock2 = sock2;
 thrarg2 = (t_thread_args*)malloc(sizeof(t_thread_args));
 thrarg2->sock1 = sock2; thrarg2->sock2 = sock1;
 rtnVal = pthread_create(&tid2, &thr_options, &thread_main, thrarg2);
 if (rtnVal != 0)
  DieWithMessage("pthread_create() failed", strerror(rtnVal));
    pthread_attr_destroy(&thr_options);
 (void)thread_main(thrarg1);
    return 0;
}

canonical_original_code:
int main(int argc, char *argv[]) {
 char *a1; char *a2; char *p1; char *p2;
 int sock1; int sock2;
    if (argc != 5)
  DieWithMessage("Usage: address1 port1 address2 port2","");
 a1 = argv[1]; p1 = argv[2]; a2 = argv[3]; p2 = argv[4];
    sock1 = setupTCPClientSocket(a1, p1);
 if (sock1 < 0)
        DieWithMessage("setupTCPClientSocket() failed to connect to", a1);
 sock2 = setupTCPClientSocket(a2, p2);
 if (sock2 < 0)
        DieWithMessage("setupTCPClientSocket() failed to connect to", a2);
 union pthread_attr_t thr_options;
    int rtnVal = pthread_attr_init(&thr_options);
    if (rtnVal != 0)
        DieWithMessage("pthread_attr_init() failed", strerror(rtnVal));
    pthread_attr_setdetachstate(&thr_options, PTHREAD_CREATE_DETACHED);
 struct s_thread_args *thrarg1; struct s_thread_args *thrarg2;
 unsigned long tid2 = 0;
 thrarg1 = (struct s_thread_args *)malloc(sizeof(t_thread_args));
 thrarg1->sock1 = sock1; thrarg1->sock2 = sock2;
 thrarg2 = (struct s_thread_args *)malloc(sizeof(t_thread_args));
 thrarg2->sock1 = sock2; thrarg2->sock2 = sock1;
 rtnVal = pthread_create(&tid2, &thr_options, &thread_main, thrarg2);
 if (rtnVal != 0)
  DieWithMessage("pthread_create() failed", strerror(rtnVal));
    pthread_attr_destroy(&thr_options);
 (void)thread_main(thrarg1);
    return 0;
}

variable_types: union pthread_attr_t { char __size[56]; long __align; }

variable_types: rtnVal int

variable_types: struct s_thread_args { int sock1; int sock2; } *


decompiled_code:
void __fastcall __noreturn thread_main(void *a1)
{
pthread_t v1; // rax
int v2; // er13
int v3; // er14
ssize_t v4; // rax
size_t v5; // r12
ssize_t v6; // rax
ssize_t v7; // rax
_BYTE v8[8240]; // [rsp-2000h] [rbp-2030h] BYREF

v1 = pthread_self();
printf("%lu is starting...\n", v1);
v2 = *(_DWORD *)a1;
v3 = *((_DWORD *)a1 + 1);
free(a1);
while ( 1 )
{
v4 = recv(v2, v8, 0x2000uLL, 0);
v5 = v4;
if ( v4 < 0 )
{
DieWithPerrorMessage("recv() failed");
printf("First Received: %d bytes\n", v5);
}
else
{
printf("First Received: %d bytes\n", v4);
if ( v5 )
{
while ( 1 )
{
v6 = send(v3, v8, v5, 0);
if ( v6 < 0 )
{
DieWithPerrorMessage("send() failed");
}
else if ( v6 != v5 )
{
DieWithMessage("send()", "sent unexpected number of bytes");
}
v7 = recv(v2, v8, 0x2000uLL, 0);
v5 = v7;
if ( v7 < 0 )
break;
printf("Received: %d bytes\n", v7);
if ( !v5 )
goto LABEL_9;
}
DieWithPerrorMessage("recv() failed");
printf("Received: %d bytes\n", v5);
}
}
LABEL_9:
close(v2);
close(v3);
}
}

canonical_decompiled_code:
void __fastcall __noreturn func0(void *a1)
{
pthread_t v1; // rax
int v2; // er13
int v3; // er14
ssize_t v4; // rax
size_t v5; // r12
ssize_t v6; // rax
ssize_t v7; // rax
_BYTE v8[8240]; // [rsp-2000h] [rbp-2030h] BYREF

v1 = pthread_self();
printf("%lu is starting...\n", v1);
v2 = *(_DWORD *)a1;
v3 = *((_DWORD *)a1 + 1);
free(a1);
while ( 1 )
{
v4 = recv(v2, v8, 0x2000uLL, 0);
v5 = v4;
if ( v4 < 0 )
{
DieWithPerrorMessage("recv() failed");
printf("First Received: %d bytes\n", v5);
}
else
{
printf("First Received: %d bytes\n", v4);
if ( v5 )
{
while ( 1 )
{
v6 = send(v3, v8, v5, 0);
if ( v6 < 0 )
{
DieWithPerrorMessage("send() failed");
}
else if ( v6 != v5 )
{
DieWithMessage("send()", "sent unexpected number of bytes");
}
v7 = recv(v2, v8, 0x2000uLL, 0);
v5 = v7;
if ( v7 < 0 )
break;
printf("Received: %d bytes\n", v7);
if ( !v5 )
goto LABEL_9;
}
DieWithPerrorMessage("recv() failed");
printf("Received: %d bytes\n", v5);
}
}
LABEL_9:
close(v2);
close(v3);
}
}

original_code:
void* thread_main(void* arg)
{
    int sock1 = ((t_thread_args*)arg)->sock1;
    int sock2 = ((t_thread_args*)arg)->sock2;
    free(arg);
    while (1)
 {
  char buffer[BUFSIZE];
  ssize_t numBytesRcvd = recv(sock1, buffer, BUFSIZE, 0);
  if (numBytesRcvd < 0)
   DieWithPerrorMessage("recv() failed");
  while (numBytesRcvd > 0) {
   ssize_t numBytesSent = send(sock2, buffer, numBytesRcvd, 0);
   if (numBytesSent < 0)
    DieWithPerrorMessage("send() failed");
   else if (numBytesSent != numBytesRcvd)
    DieWithMessage("send()", "sent unexpected number of bytes");
   numBytesRcvd = recv(sock1, buffer, BUFSIZE, 0);
   if (numBytesRcvd < 0)
    DieWithPerrorMessage("recv() failed");
  }
  close(sock1);
  close(sock2);
 }
    return ((void *)0);
}

canonical_original_code:
void *thread_main(void *arg)
{
    int sock1 = ((t_thread_args*)arg)->sock1;
    int sock2 = ((t_thread_args*)arg)->sock2;
    free(arg);
    while (1)
 {
  char buffer[-1];
  long numBytesRcvd = recv(sock1, buffer, BUFSIZE, 0);
  if (numBytesRcvd < 0)
   DieWithPerrorMessage("recv() failed");
  while (numBytesRcvd > 0) {
   long numBytesSent = send(sock2, buffer, numBytesRcvd, 0);
   if (numBytesSent < 0)
    DieWithPerrorMessage("send() failed");
   else if (numBytesSent != numBytesRcvd)
    DieWithMessage("send()", "sent unexpected number of bytes");
   numBytesRcvd = recv(sock1, buffer, BUFSIZE, 0);
   if (numBytesRcvd < 0)
    DieWithPerrorMessage("recv() failed");
  }
  close(sock1);
  close(sock2);
 }
    return ((void *)0);
}

variable_types:
arg
void *

variable_types:
buffer
char [-1]

variable_types: numBytesRcvd long

variable_types: numBytesSent long


acceptTCPConnection

decompiled_code:
int __fastcall acceptTCPConnection(int a1)
{
int result; // eax
int v2; // [rsp+Ch] [rbp-9Ch]
socklen_t addr_len; // [rsp+1Ch] [rbp-8Ch] BYREF
struct sockaddr addr; // [rsp+20h] [rbp-88h] BYREF

addr_len = 128;
result = accept(a1, &addr, &addr_len);
if ( result < 0 )
{
v2 = result;
DieWithPerrorMessage("accept() failed");
result = v2;
}
return result;
}

canonical_decompiled_code:
int __fastcall func0(int a1)
{
int result; // eax
int v2; // [rsp+Ch] [rbp-9Ch]
socklen_t addr_len; // [rsp+1Ch] [rbp-8Ch] BYREF
struct sockaddr addr; // [rsp+20h] [rbp-88h] BYREF

addr_len = 128;
result = accept(a1, &addr, &addr_len);
if ( result < 0 )
{
v2 = result;
DieWithPerrorMessage("accept() failed");
result = v2;
}
return result;
}

original_code:
int acceptTCPConnection(int servSock)
{
  struct sockaddr_storage clntAddr;
  socklen_t clntAddrLen = sizeof(clntAddr);
  int clntSock;
  clntSock = accept(servSock, (struct sockaddr*) &clntAddr, &clntAddrLen);
  if (clntSock < 0)
    DieWithPerrorMessage("accept() failed");
  return clntSock;
}

canonical_original_code:
int acceptTCPConnection(int servSock)
{
  struct sockaddr_storage clntAddr;
  unsigned int clntAddrLen = sizeof(clntAddr);
  int clntSock;
  clntSock = accept(servSock, (struct sockaddr *) &clntAddr, &clntAddrLen);
  if (clntSock < 0)
    DieWithPerrorMessage("accept() failed");
  return clntSock;
}

variable_types: servSock int

variable_types: struct sockaddr_storage { unsigned short ss_family; char __ss_padding[-1]; unsigned long __ss_align; }

variable_types:
clntAddrLen
unsigned int

variable_types: clntSock int


setupTCPServerSocket

decompiled_code:
__int64 __fastcall setupTCPServerSocket(char *service)
{
int v1; // eax
struct addrinfo *v2; // rbp
int v3; // eax
unsigned int v4; // er12
int v5; // edi
const char *v7; // rax
socklen_t len; // [rsp+0h] [rbp-D4h] BYREF
struct addrinfo *pai; // [rsp+4h] [rbp-D0h] BYREF
struct addrinfo req; // [rsp+Ch] [rbp-C8h] BYREF
struct sockaddr addr; // [rsp+3Ch] [rbp-98h] BYREF

*(_QWORD *)&req.ai_flags = 0x200000001LL;
*(_QWORD *)&req.ai_socktype = 0x600000001LL;
*(_OWORD *)&req.ai_addrlen = 0LL;
*(_OWORD *)&req.ai_canonname = 0LL;
v1 = getaddrinfo(0LL, service, &req, &pai);
if ( v1 )
{
v7 = gai_strerror(v1);
DieWithMessage("getaddrinfo() failed", v7);
}
v2 = pai;
if ( !pai )
{
v4 = -1;
goto LABEL_10;
}
while ( 1 )
{
v3 = socket(v2->ai_family, v2->ai_socktype, v2->ai_protocol);
v4 = v3;
if ( v3 >= 0 )
break;
LABEL_8:
v2 = v2->ai_next;
if ( !v2 )
{
v2 = pai;
goto LABEL_10;
}
}
if ( bind(v3, v2->ai_addr, v2->ai_addrlen) || listen(v4, 5) )
{
v5 = v4;
v4 = -1;
close(v5);
goto LABEL_8;
}
len = 128;
if ( getsockname(v4, &addr, &len) < 0 )
DieWithPerrorMessage("getsockname() failed");
puts("Binding to ");
printSocketAddress(&addr, stdout);
fputc(10, stdout);
v2 = pai;
LABEL_10:
freeaddrinfo(v2);
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func0(char *service)
{
int v1; // eax
struct addrinfo *v2; // rbp
int v3; // eax
unsigned int v4; // er12
int v5; // edi
const char *v7; // rax
socklen_t len; // [rsp+0h] [rbp-D4h] BYREF
struct addrinfo *pai; // [rsp+4h] [rbp-D0h] BYREF
struct addrinfo req; // [rsp+Ch] [rbp-C8h] BYREF
struct sockaddr addr; // [rsp+3Ch] [rbp-98h] BYREF

*(_QWORD *)&req.ai_flags = 0x200000001LL;
*(_QWORD *)&req.ai_socktype = 0x600000001LL;
*(_OWORD *)&req.ai_addrlen = 0LL;
*(_OWORD *)&req.ai_canonname = 0LL;
v1 = getaddrinfo(0LL, service, &req, &pai);
if ( v1 )
{
v7 = gai_strerror(v1);
DieWithMessage("getaddrinfo() failed", v7);
}
v2 = pai;
if ( !pai )
{
v4 = -1;
goto LABEL_10;
}
while ( 1 )
{
v3 = socket(v2->ai_family, v2->ai_socktype, v2->ai_protocol);
v4 = v3;
if ( v3 >= 0 )
break;
LABEL_8:
v2 = v2->ai_next;
if ( !v2 )
{
v2 = pai;
goto LABEL_10;
}
}
if ( bind(v3, v2->ai_addr, v2->ai_addrlen) || listen(v4, 5) )
{
v5 = v4;
v4 = -1;
close(v5);
goto LABEL_8;
}
len = 128;
if ( getsockname(v4, &addr, &len) < 0 )
DieWithPerrorMessage("getsockname() failed");
puts("Binding to ");
printSocketAddress(&addr, stdout);
fputc(10, stdout);
v2 = pai;
LABEL_10:
freeaddrinfo(v2);
return v4;
}

original_code:
int setupTCPServerSocket(const char* service) {
  struct addrinfo addrCriteria;
  struct addrinfo* servAddr;
  int servSock;
  int rtnVal;
  memset(&addrCriteria, 0, sizeof(addrCriteria));
  addrCriteria.ai_family = 2;
  addrCriteria.ai_flags = 0x0001;
  addrCriteria.ai_socktype = SOCK_STREAM;
  addrCriteria.ai_protocol = IPPROTO_TCP;
  rtnVal = getaddrinfo(0, service, &addrCriteria, &servAddr);
  if (rtnVal != 0)
    DieWithMessage("getaddrinfo() failed", gai_strerror(rtnVal));
  servSock = -1;
  struct addrinfo* addr;
  int i=0;
  for (addr = servAddr; addr != 0; addr = addr->ai_next)
    i++;
  for (addr = servAddr; addr != 0; addr = addr->ai_next) {
    servSock = socket(addr->ai_family, addr->ai_socktype, addr->ai_protocol);
    if (servSock < 0)
      continue;
    if ((bind(servSock, addr->ai_addr, addr->ai_addrlen) == 0) &&
 (listen(servSock, MAXPENDING) == 0)) {
      struct sockaddr_storage localAddr;
      socklen_t addrSize = sizeof(localAddr);
      if (getsockname(servSock, (struct sockaddr* ) &localAddr, &addrSize) < 0)
 DieWithPerrorMessage("getsockname() failed");
      puts("Binding to ");
      printSocketAddress((struct sockaddr* ) &localAddr, stdout);
      fputc('\n', stdout);
      break;
    }
    close(servSock);
    servSock = -1;
  }
  freeaddrinfo(servAddr);
  return servSock;
}

canonical_original_code:
int setupTCPServerSocket(char *service) {
  struct addrinfo addrCriteria;
  struct addrinfo *servAddr;
  int servSock;
  int rtnVal;
  memset(&addrCriteria, 0, sizeof(addrCriteria));
  addrCriteria.ai_family = 2;
  addrCriteria.ai_flags = 0x0001;
  addrCriteria.ai_socktype = SOCK_STREAM;
  addrCriteria.ai_protocol = IPPROTO_TCP;
  rtnVal = getaddrinfo(0, service, &addrCriteria, &servAddr);
  if (rtnVal != 0)
    DieWithMessage("getaddrinfo() failed", gai_strerror(rtnVal));
  servSock = -1;
  struct addrinfo *addr;
  int i = 0;
  for (addr = servAddr; addr != 0; addr = addr->ai_next)
    i++;
  for (addr = servAddr; addr != 0; addr = addr->ai_next) {
    servSock = socket(addr->ai_family, addr->ai_socktype, addr->ai_protocol);
    if (servSock < 0)
      continue;
    if ((bind(servSock, addr->ai_addr, addr->ai_addrlen) == 0) &&
 (listen(servSock, MAXPENDING) == 0)) {
      struct sockaddr_storage localAddr;
      unsigned int addrSize = sizeof(localAddr);
      if (getsockname(servSock, (struct sockaddr * ) &localAddr, &addrSize) < 0)
 DieWithPerrorMessage("getsockname() failed");
      puts("Binding to ");
      printSocketAddress((struct sockaddr * ) &localAddr, stdout);
      fputc('\n', stdout);
      break;
    }
    close(servSock);
    servSock = -1;
  }
  freeaddrinfo(servAddr);
  return servSock;
}

variable_types:
service
char *

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

variable_types:
addrSize
unsigned int

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

user_defined_types: struct sockaddr_storage { unsigned short ss_family; char __ss_padding[-1]; unsigned long __ss_align; }


DieWithMessage

decompiled_code:
void __fastcall __noreturn DieWithMessage(const char *a1, const char *a2)
{
if ( a1 )
{
fputs(a1, stderr);
if ( a2 )
{
fwrite(&unk_86, 1uLL, 3uLL, stderr);
fputs(a2, stderr);
}
fputc(10, stderr);
}
exit(1);
}

canonical_decompiled_code:
void __fastcall __noreturn func0(const char *a1, const char *a2)
{
if ( a1 )
{
fputs(a1, stderr);
if ( a2 )
{
fwrite(&unk_86, 1uLL, 3uLL, stderr);
fputs(a2, stderr);
}
fputc(10, stderr);
}
exit(1);
}

original_code:
void DieWithMessage(const char* msg, const char* msg2)
{
  if (msg) {
    fputs(msg, stderr);
    if (msg2) {
      fputs(" : ", stderr);
      fputs(msg2, stderr);
    }
    fputc('\n',stderr);
  }
  exit(1);
}

canonical_original_code:
void DieWithMessage(char *msg, char *msg2)
{
  if (msg) {
    fputs(msg, stderr);
    if (msg2) {
      fputs(" : ", stderr);
      fputs(msg2, stderr);
    }
    fputc('\n',stderr);
  }
  exit(1);
}

variable_types:
msg
char *


DieWithPerrorMessage

decompiled_code:
void __fastcall __noreturn DieWithPerrorMessage(const char *a1)
{
perror(a1);
fputc(10, stderr);
exit(1);
}

canonical_decompiled_code:
void __fastcall __noreturn func1(const char *a1)
{
perror(a1);
fputc(10, stderr);
exit(1);
}

original_code:
void DieWithPerrorMessage(const char* msg)
{
  perror(msg);
  fputc('\n',stderr);
  exit(1);
}

canonical_original_code:
void DieWithPerrorMessage(char *msg)
{
  perror(msg);
  fputc('\n',stderr);
  exit(1);
}


setupTCPClientSocket

decompiled_code:
__int64 __fastcall setupTCPClientSocket(const char *a1, const char *a2)
{
int v2; // eax
struct addrinfo *v3; // rbp
int v4; // eax
unsigned int v5; // er12
int v6; // edi
const char *v8; // rax
struct addrinfo *pai; // [rsp+0h] [rbp-50h] BYREF
struct addrinfo req; // [rsp+8h] [rbp-48h] BYREF

req.ai_flags = 0;
*(_OWORD *)&req.ai_addrlen = 0LL;
req.ai_family = 2;
*(_QWORD *)&req.ai_socktype = 0x600000001LL;
*(_OWORD *)&req.ai_canonname = 0LL;
v2 = getaddrinfo(a1, a2, &req, &pai);
if ( v2 )
{
v8 = gai_strerror(v2);
DieWithMessage("getaddrinfo() failed", v8);
}
v3 = pai;
if ( pai )
{
do
{
v4 = socket(v3->ai_family, v3->ai_socktype, v3->ai_protocol);
v5 = v4;
if ( v4 >= 0 )
{
if ( !connect(v4, v3->ai_addr, v3->ai_addrlen) )
break;
v6 = v5;
v5 = -1;
close(v6);
}
v3 = v3->ai_next;
}
while ( v3 );
v3 = pai;
}
else
{
v5 = -1;
}
freeaddrinfo(v3);
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func0(const char *a1, const char *a2)
{
int v2; // eax
struct addrinfo *v3; // rbp
int v4; // eax
unsigned int v5; // er12
int v6; // edi
const char *v8; // rax
struct addrinfo *pai; // [rsp+0h] [rbp-50h] BYREF
struct addrinfo req; // [rsp+8h] [rbp-48h] BYREF

req.ai_flags = 0;
*(_OWORD *)&req.ai_addrlen = 0LL;
req.ai_family = 2;
*(_QWORD *)&req.ai_socktype = 0x600000001LL;
*(_OWORD *)&req.ai_canonname = 0LL;
v2 = getaddrinfo(a1, a2, &req, &pai);
if ( v2 )
{
v8 = gai_strerror(v2);
DieWithMessage("getaddrinfo() failed", v8);
}
v3 = pai;
if ( pai )
{
do
{
v4 = socket(v3->ai_family, v3->ai_socktype, v3->ai_protocol);
v5 = v4;
if ( v4 >= 0 )
{
if ( !connect(v4, v3->ai_addr, v3->ai_addrlen) )
break;
v6 = v5;
v5 = -1;
close(v6);
}
v3 = v3->ai_next;
}
while ( v3 );
v3 = pai;
}
else
{
v5 = -1;
}
freeaddrinfo(v3);
return v5;
}

original_code:
int setupTCPClientSocket(const char *host, const char *service) {
  struct addrinfo addrCriteria;
  memset(&addrCriteria, 0, sizeof(addrCriteria));
  addrCriteria.ai_family = 2;
  addrCriteria.ai_socktype = SOCK_STREAM;
  addrCriteria.ai_protocol = IPPROTO_TCP;
  struct addrinfo *servAddr;
  int rtnVal = getaddrinfo(host, service, &addrCriteria, &servAddr);
  if (rtnVal != 0)
    DieWithMessage("getaddrinfo() failed", gai_strerror(rtnVal));
  int sock = -1;
  struct addrinfo *addr;
  for (addr = servAddr; addr != ((void *)0); addr = addr->ai_next) {
    sock = socket(addr->ai_family, addr->ai_socktype, addr->ai_protocol);
    if (sock < 0)
      continue;
    if (connect(sock, addr->ai_addr, addr->ai_addrlen) == 0)
      break;
    close(sock);
    sock = -1;
  }
  freeaddrinfo(servAddr);
  return sock;
}

canonical_original_code:
int setupTCPClientSocket(char *host, char *service) {
  struct addrinfo addrCriteria;
  memset(&addrCriteria, 0, sizeof(addrCriteria));
  addrCriteria.ai_family = 2;
  addrCriteria.ai_socktype = SOCK_STREAM;
  addrCriteria.ai_protocol = IPPROTO_TCP;
  struct addrinfo *servAddr;
  int rtnVal = getaddrinfo(host, service, &addrCriteria, &servAddr);
  if (rtnVal != 0)
    DieWithMessage("getaddrinfo() failed", gai_strerror(rtnVal));
  int sock = -1;
  struct addrinfo *addr;
  for (addr = servAddr; addr != ((void *)0); addr = addr->ai_next) {
    sock = socket(addr->ai_family, addr->ai_socktype, addr->ai_protocol);
    if (sock < 0)
      continue;
    if (connect(sock, addr->ai_addr, addr->ai_addrlen) == 0)
      break;
    close(sock);
    sock = -1;
  }
  freeaddrinfo(servAddr);
  return sock;
}

variable_types:
host
char *

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

variable_types: sock int


decompiled_code:
__int64 __fastcall draw_square_arena(double *a1)
{
float v1; // xmm0_4
float v2; // xmm1_4
float v3; // xmm0_4
float v4; // xmm1_4
float v5; // xmm0_4
float v6; // xmm1_4
float v7; // xmm0_4
float v8; // xmm1_4

glBegin(2LL);
v1 = *a1;
v2 = a1[1];
glVertex3f(v1, v2, 0.0);
v3 = a1[2];
v4 = a1[1];
glVertex3f(v3, v4, 0.0);
v5 = a1[2];
v6 = a1[3];
glVertex3f(v5, v6, 0.0);
v7 = *a1;
v8 = a1[3];
glVertex3f(v7, v8, 0.0);
return glEnd();
}

canonical_decompiled_code:
__int64 __fastcall func0(double *a1)
{
float v1; // xmm0_4
float v2; // xmm1_4
float v3; // xmm0_4
float v4; // xmm1_4
float v5; // xmm0_4
float v6; // xmm1_4
float v7; // xmm0_4
float v8; // xmm1_4

glBegin(2LL);
v1 = *a1;
v2 = a1[1];
glVertex3f(v1, v2, 0.0);
v3 = a1[2];
v4 = a1[1];
glVertex3f(v3, v4, 0.0);
v5 = a1[2];
v6 = a1[3];
glVertex3f(v5, v6, 0.0);
v7 = *a1;
v8 = a1[3];
glVertex3f(v7, v8, 0.0);
return glEnd();
}

original_code:
void draw_square_arena(Arena *arena)
{
   glBegin(0x0002);
   glVertex3f(arena->min[0], arena->min[1], 0.0);
   glVertex3f(arena->max[0], arena->min[1], 0.0);
   glVertex3f(arena->max[0], arena->max[1], 0.0);
   glVertex3f(arena->min[0], arena->max[1], 0.0);
   glEnd();
}

canonical_original_code:
void draw_square_arena(struct Arena *arena)
{
   glBegin(0x0002);
   glVertex3f(arena->min[0], arena->min[1], 0.0);
   glVertex3f(arena->max[0], arena->min[1], 0.0);
   glVertex3f(arena->max[0], arena->max[1], 0.0);
   glVertex3f(arena->min[0], arena->max[1], 0.0);
   glEnd();
}

variable_types: struct Arena { double min[2]; double momentum[2]; } *


decompiled_code:
__int64 draw_circular_arena()
{
gluQuadricDrawStyle(quadric, 100013LL);
return gluDisk(quadric, 64LL, 64LL, 0.0, 9.0);
}

canonical_decompiled_code:
__int64 func1()
{
gluQuadricDrawStyle(quadric, 100013LL);
return gluDisk(quadric, 64LL, 64LL, 0.0, 9.0);
}

original_code:
void draw_circular_arena()
{
 gluQuadricDrawStyle(quadric, 100013);
   gluDisk(quadric, 0.0, 9.0, 64, 64);
}


initialiseArena

decompiled_code:
__int64 __fastcall initialiseArena(_QWORD *a1)
{
__int64 result; // rax

a1[4] = 0LL;
a1[5] = 0LL;
*a1 = LC3;
a1[1] = LC3;
a1[2] = LC1;
a1[3] = LC1;
circular_arena_image = texture_load("images/background.jpg");
result = gluNewQuadric();
quadric = result;
return result;
}

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

a1[4] = 0LL;
a1[5] = 0LL;
*a1 = LC3;
a1[1] = LC3;
a1[2] = LC1;
a1[3] = LC1;
circular_arena_image = texture_load("images/background.jpg");
result = gluNewQuadric();
quadric = result;
return result;
}

original_code:
void initialiseArena(Arena *arena)
{
   arena->min[0] = -9.0;
   arena->min[1] = -9.0;
   arena->max[0] = 9.0;
   arena->max[1] = 9.0;
   arena->momentum[0] = 0.0;
   arena->momentum[1] = 0.0;
 circular_arena_image = texture_load("images/background.jpg");
  quadric = gluNewQuadric();
}

canonical_original_code:
void initialiseArena(struct Arena *arena)
{
   arena->min[0] = -9.0;
   arena->min[1] = -9.0;
   arena->max[0] = 9.0;
   arena->max[1] = 9.0;
   arena->momentum[0] = 0.0;
   arena->momentum[1] = 0.0;
 circular_arena_image = texture_load("images/background.jpg");
  quadric = gluNewQuadric();
}

user_defined_types: struct Arena { double min[2]; double momentum[2]; }


displayArena

decompiled_code:
__int64 __fastcall displayArena(double *a1, char a2)
{
glPushAttrib(0x2000LL);
glDisable(2929LL);
glDisable(2896LL);
glPushMatrix();
if ( a2 )
draw_square_arena(a1);
else
draw_circular_arena();
glPopMatrix();
return glPopAttrib();
}

canonical_decompiled_code:
__int64 __fastcall func3(double *a1, char a2)
{
glPushAttrib(0x2000LL);
glDisable(2929LL);
glDisable(2896LL);
glPushMatrix();
if ( a2 )
func0(a1);
else
func1();
glPopMatrix();
return glPopAttrib();
}

original_code:
void displayArena(Arena *arena, _Bool square_arena)
{
 glPushAttrib(0x00002000);
 glDisable(0x0B71);
 glDisable(0x0B50);
 glPushMatrix();
 if(square_arena)
  draw_square_arena(arena);
 else
  draw_circular_arena();
 glPopMatrix();
 glPopAttrib();
}

canonical_original_code:
void displayArena(struct Arena *arena, _Bool square_arena)
{
 glPushAttrib(0x00002000);
 glDisable(0x0B71);
 glDisable(0x0B50);
 glPushMatrix();
 if(square_arena)
  draw_square_arena(arena);
 else
  draw_circular_arena();
 glPopMatrix();
 glPopAttrib();
}


panic

decompiled_code:
void __fastcall __noreturn panic(const char *a1)
{
printf("%s", a1);
exit(1);
}

canonical_decompiled_code:
void __fastcall __noreturn func0(const char *a1)
{
printf("%s", a1);
exit(1);
}

original_code:
void panic(const char *m)
{
   printf("%s", m);
   exit(1);
}

canonical_original_code:
void panic(char *m)
{
   printf("%s", m);
   exit(1);
}

variable_types:
m
char *


decompiled_code:
double random_uniform()
{
return (float)((float)rand() * 4.6566129e-10);
}

canonical_decompiled_code:
double func0()
{
return (float)((float)rand() * 4.6566129e-10);
}

original_code:
Real random_uniform()
{
   return rand()/(float)2147483647;
}

canonical_original_code:
double random_uniform()
{
   return rand()/(float)2147483647;
}

return_type: double


decompiled_code:
__int64 __fastcall is_power_2(int a1)
{
for ( ; a1; a1 >>= 1 )
;
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1)
{
for ( ; a1; a1 >>= 1 )
;
return 1LL;
}

original_code:
int is_power_2(int val)
{
    int count = 0;
    while (val)
    {
        count += val & 1;
        val >>= 1;
    }
    return 1;
}

variable_types: val int

variable_types: count int


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

result = is_power_2(a1);
if ( (_DWORD)result )
result = (unsigned int)is_power_2(a2) != 0;
return result;
}

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

result = func0(a1);
if ( (_DWORD)result )
result = (unsigned int)func0(a2) != 0;
return result;
}

original_code:
int texture_is_valid_dimensions(int width, int height)
{
    return is_power_2(width) && is_power_2(height);
}

variable_types: width int

variable_types: height int


original_code:
void flip_data(char *data, int pitch, int height)
{
    char *row1 = data;
    char *row2 = data + (height - 1) * pitch;
    int x, y;
    char tmp;
    for (y = 0; y < height >> 1; y++)
    {
        for (x = 0; x < pitch; x++)
        {
            tmp = row1[x];
            row1[x] = row2[x];
            row2[x] = tmp;
        }
        row1 += pitch;
        row2 -= pitch;
    }
}

canonical_original_code:
void flip_data(char *data, int pitch, int height)
{
    char *row1 = data;
    char *row2 = data + (height - 1) * pitch;
    int x; int y;
    char tmp;
    for (y = 0; y < height >> 1; y++)
    {
        for (x = 0; x < pitch; x++)
        {
            tmp = row1[x];
            row1[x] = row2[x];
            row2[x] = tmp;
        }
        row1 += pitch;
        row2 -= pitch;
    }
}

variable_types:
data
char *

variable_types: pitch int

variable_types: x int

variable_types: y int

variable_types: tmp char


decompiled_code:
__int64 __fastcall texture_load_data(__int64 a1, __int64 a2, unsigned int a3, int a4, int a5, unsigned int a6, unsigned int a7, unsigned int a8)
{
unsigned int v8; // er15
int v10; // er12
unsigned int v12; // ebp
__int64 v13; // rdx
unsigned int v14; // er12
int v16; // [rsp+Ch] [rbp-4Ch]
unsigned int v17[15]; // [rsp+1Ch] [rbp-3Ch] BYREF

v8 = a2;
v10 = a5;
if ( a5 < 0 )
{
v10 = -a5;
v16 = a4;
a2 = (unsigned int)-a5;
flip_data(a1, -a5, a3);
a4 = v16;
}
v12 = v10 & 1;
if ( (v10 & 1) == 0 )
v12 = (v10 & 2) == 0 ? 4 : 2;
v13 = (unsigned int)(v10 >> 31);
LODWORD(v13) = v10 % a4;
v14 = v10 / a4;
glPushClientAttrib(1LL, a2, v13);
glPixelStorei(3317LL, v12);
glPixelStorei(3314LL, v14);
glGenTextures(1LL, v17);
glBindTexture(3553LL, v17[0]);
glTexImage2D(3553LL, 0LL, a6, v8, a3, 0LL, a7, a8, a1);
glTexParameteri(3553LL, 10241LL, 9729LL);
glTexParameteri(3553LL, 10240LL, 9729LL);
glFinish();
glPopClientAttrib();
return v17[0];
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, __int64 a2, unsigned int a3, int a4, int a5, unsigned int a6, unsigned int a7, unsigned int a8)
{
unsigned int v8; // er15
int v10; // er12
unsigned int v12; // ebp
__int64 v13; // rdx
unsigned int v14; // er12
int v16; // [rsp+Ch] [rbp-4Ch]
unsigned int v17[15]; // [rsp+1Ch] [rbp-3Ch] BYREF

v8 = a2;
v10 = a5;
if ( a5 < 0 )
{
v10 = -a5;
v16 = a4;
a2 = (unsigned int)-a5;
func2(a1, -a5, a3);
a4 = v16;
}
v12 = v10 & 1;
if ( (v10 & 1) == 0 )
v12 = (v10 & 2) == 0 ? 4 : 2;
v13 = (unsigned int)(v10 >> 31);
LODWORD(v13) = v10 % a4;
v14 = v10 / a4;
glPushClientAttrib(1LL, a2, v13);
glPixelStorei(3317LL, v12);
glPixelStorei(3314LL, v14);
glGenTextures(1LL, v17);
glBindTexture(3553LL, v17[0]);
glTexImage2D(3553LL, 0LL, a6, v8, a3, 0LL, a7, a8, a1);
glTexParameteri(3553LL, 10241LL, 9729LL);
glTexParameteri(3553LL, 10240LL, 9729LL);
glFinish();
glPopClientAttrib();
return v17[0];
}

original_code:
GLuint texture_load_data(unsigned char *data, int width, int height,
                         int components, int pitch,
                         GLint internalFormat, GLenum format, GLenum type)
{
    GLuint id;
    int alignment;
    int row_length;
    if (pitch < 0)
    {
        pitch = -pitch;
        flip_data(data, pitch, height);
    }
    if (pitch & 0x1)
        alignment = 1;
    else if (pitch & 0x2)
        alignment = 2;
    else
        alignment = 4;
    row_length = pitch / components;
    glPushClientAttrib(0x00000001);
    glPixelStorei(0x0CF5, alignment);
    glPixelStorei(0x0CF2, row_length);
    glGenTextures(1, &id);
    glBindTexture(0x0DE1, id);
    glTexImage2D(0x0DE1, 0, internalFormat, width, height, 0, format,
                 type, data);
    glTexParameteri(0x0DE1, 0x2801, 0x2601);
    glTexParameteri(0x0DE1, 0x2800, 0x2601);
    glFinish();
    glPopClientAttrib();
    return id;
}

canonical_original_code:
unsigned int texture_load_data(unsigned char *data, int width, int height, int components, int pitch, int internalFormat, unsigned int format, unsigned int type)
{
    unsigned int id;
    int alignment;
    int row_length;
    if (pitch < 0)
    {
        pitch = -pitch;
        flip_data(data, pitch, height);
    }
    if (pitch & 0x1)
        alignment = 1;
    else if (pitch & 0x2)
        alignment = 2;
    else
        alignment = 4;
    row_length = pitch / components;
    glPushClientAttrib(0x00000001);
    glPixelStorei(0x0CF5, alignment);
    glPixelStorei(0x0CF2, row_length);
    glGenTextures(1, &id);
    glBindTexture(0x0DE1, id);
    glTexImage2D(0x0DE1, 0, internalFormat, width, height, 0, format,
                 type, data);
    glTexParameteri(0x0DE1, 0x2801, 0x2601);
    glTexParameteri(0x0DE1, 0x2800, 0x2601);
    glFinish();
    glPopClientAttrib();
    return id;
}

variable_types:
data
unsigned char *

variable_types: components int

variable_types: internalFormat int

variable_types:
format
unsigned int

variable_types:
type
unsigned int

variable_types:
id
unsigned int

variable_types: alignment int

return_type: unsigned int


repo: diegonc/burp

decompiled_code:
void __fastcall delete_file(char *name)
{
struct stat v1; // [rsp-98h] [rbp-98h] BYREF

if ( name )
{
if ( !stat(name, &v1) )
unlink(name);
}
}

canonical_decompiled_code:
void __fastcall func0(char *name)
{
struct stat v1; // [rsp-98h] [rbp-98h] BYREF

if ( name )
{
if ( !stat(name, &v1) )
unlink(name);
}
}

original_code:
void delete_file(const char *filename) {
  struct stat st;
  if (filename == ((void *)0)) {
    return;
  }
  if (stat(filename, &st) == 0) {
    unlink(filename);
  }
}

canonical_original_code:
void delete_file(char *filename) {
  struct stat st;
  if (filename == ((void *)0)) {
    return;
  }
  if (stat(filename, &st) == 0) {
    unlink(filename);
  }
}

variable_types:
filename
char *

variable_types: struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; struct timespec { long tv_sec; long tv_nsec; } st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; }

user_defined_types: struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; struct timespec st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; }


die

decompiled_code:
void __noreturn die(char *format, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

va_start(arg, format);
vfprintf(stderr, format, arg);
exit(1);
}

canonical_decompiled_code:
void __noreturn func1(char *format, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

va_start(arg, format);
vfprintf(stderr, format, arg);
exit(1);
}

original_code:
void die(const char *errstr, ...) {
  va_list ap;
  __builtin_va_start(ap,errstr);
  vfprintf(stderr, errstr, ap);
  __builtin_va_end(ap);
  exit(1);
}

canonical_original_code:
void die(char *errstr, ...) {
  __builtin_va_list ap;
  __builtin_va_start(ap,errstr);
  vfprintf(stderr, errstr, ap);
  __builtin_va_end(ap);
  exit(1);
}

variable_types:
errstr
char *


decompiled_code:
_BOOL8 __fastcall file_exists(const char *a1)
{
struct stat v2; // [rsp+0h] [rbp-98h] BYREF

return stat(a1, &v2) == 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func2(const char *a1)
{
struct stat v2; // [rsp+0h] [rbp-98h] BYREF

return stat(a1, &v2) == 0;
}

original_code:
int file_exists(const char *filename) {
  struct stat st;
  return(stat(filename, &st) == 0);
}

canonical_original_code:
int file_exists(char *filename) {
  struct stat st;
  return(stat(filename, &st) == 0);
}

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


decompiled_code:
char *__fastcall get_tmpfile(char *fmt)
{
unsigned int v1; // eax
char *ptr; // [rsp+8h] [rbp-10h] BYREF

v1 = getpid();
asprintf(&ptr, fmt, v1);
return ptr;
}

canonical_decompiled_code:
char *__fastcall func3(char *fmt)
{
unsigned int v1; // eax
char *ptr; // [rsp+8h] [rbp-10h] BYREF

v1 = getpid();
asprintf(&ptr, fmt, v1);
return ptr;
}

original_code:
char *get_tmpfile(const char *format) {
  char *buf;
  asprintf(&buf, format, getpid());
  return(buf);
}

canonical_original_code:
char *get_tmpfile(char *format) {
  char *buf;
  asprintf(&buf, format, getpid());
  return(buf);
}

variable_types:
format
char *

variable_types:
buf
char *

return_type: char *


strtrim

decompiled_code:
void *__fastcall strtrim(void *src)
{
__int64 v1; // rbx
const unsigned __int16 **v2; // rax
const char *v3; // rbp
const unsigned __int16 *v4; // r12
const unsigned __int16 **v5; // r14
size_t v6; // rax
char *v8; // rax
__int64 v9; // rdx

if ( !src )
return src;
v1 = *(char *)src;
if ( !(_BYTE)v1 )
return src;
v2 = _ctype_b_loc();
v3 = (const char *)src;
v4 = *v2;
v5 = v2;
while ( (v4[v1] & 0x2000) != 0 )
v1 = *++v3;
if ( v3 != src )
{
v6 = strlen(v3);
memmove(src, v3, v6 + 1);
if ( !*(_BYTE *)src )
return src;
v4 = *v5;
}
v8 = (char *)src + strlen((const char *)src) - 1;
if ( (v4[*v8] & 0x2000) != 0 )
{
do
v9 = *--v8;
while ( (v4[v9] & 0x2000) != 0 );
}
v8[1] = 0;
return src;
}

canonical_decompiled_code:
void *__fastcall func4(void *src)
{
__int64 v1; // rbx
const unsigned __int16 **v2; // rax
const char *v3; // rbp
const unsigned __int16 *v4; // r12
const unsigned __int16 **v5; // r14
size_t v6; // rax
char *v8; // rax
__int64 v9; // rdx

if ( !src )
return src;
v1 = *(char *)src;
if ( !(_BYTE)v1 )
return src;
v2 = _ctype_b_loc();
v3 = (const char *)src;
v4 = *v2;
v5 = v2;
while ( (v4[v1] & 0x2000) != 0 )
v1 = *++v3;
if ( v3 != src )
{
v6 = strlen(v3);
memmove(src, v3, v6 + 1);
if ( !*(_BYTE *)src )
return src;
v4 = *v5;
}
v8 = (char *)src + strlen((const char *)src) - 1;
if ( (v4[*v8] & 0x2000) != 0 )
{
do
v9 = *--v8;
while ( (v4[v9] & 0x2000) != 0 );
}
v8[1] = 0;
return src;
}

original_code:
char *strtrim(char *str) {
  char *pch = str;
  if (str == ((void *)0) || *str == '\0') {
    return(str);
  }
  while (((*__ctype_b_loc ())[(int) ((*pch))] & (unsigned short int) _ISspace)) {
    pch++;
  }
  if (pch != str) {
    memmove(str, pch, (strlen(pch) + 1));
  }
  if (*str == '\0') {
    return(str);
  }
  pch = (str + strlen(str) - 1);
  while (((*__ctype_b_loc ())[(int) ((*pch))] & (unsigned short int) _ISspace)) {
    pch--;
  }
  *++pch = '\0';
  return(str);
}

canonical_original_code:
char *strtrim(char *str) {
  char *pch = str;
  if (str == ((void *)0) || *str == '\0') {
    return(str);
  }
  while (((*__ctype_b_loc ())[(int) ((*pch))] & (unsigned short) _ISspace)) {
    pch++;
  }
  if (pch != str) {
    memmove(str, pch, (strlen(pch) + 1));
  }
  if (*str == '\0') {
    return(str);
  }
  pch = (str + strlen(str) - 1);
  while (((*__ctype_b_loc ())[(int) ((*pch))] & (unsigned short) _ISspace)) {
    pch--;
  }
  *++pch = '\0';
  return(str);
}

variable_types:
str
char *

variable_types:
pch
char *


touch

decompiled_code:
int __fastcall touch(const char *a1)
{
int v1; // eax
int result; // eax

v1 = open(a1, 2369, 438LL);
if ( v1 == -1 )
result = 1;
else
result = close(v1);
return result;
}

canonical_decompiled_code:
int __fastcall func5(const char *a1)
{
int v1; // eax
int result; // eax

v1 = open(a1, 2369, 438LL);
if ( v1 == -1 )
result = 1;
else
result = close(v1);
return result;
}

variable_types: fd int


xmalloc

decompiled_code:
void *__fastcall xmalloc(size_t a1)
{
void *result; // rax

result = malloc(a1);
if ( !result )
die("error: failed to allocate %zd bytes", a1);
return result;
}

canonical_decompiled_code:
void *__fastcall func6(size_t a1)
{
void *result; // rax

result = malloc(a1);
if ( !result )
func1("error: failed to allocate %zd bytes", a1);
return result;
}

original_code:
void *xmalloc(size_t size) {
  void *ret = malloc(size);
  if (!ret) {
    die("error: failed to allocate %zd bytes", size);
  }
  return(ret);
}

canonical_original_code:
void *xmalloc(unsigned long size) {
  void *ret = malloc(size);
  if (!ret) {
    die("error: failed to allocate %zd bytes", size);
  }
  return(ret);
}

variable_types:
size
unsigned long

variable_types:
ret
void *


xcalloc

decompiled_code:
void *__fastcall xcalloc(size_t a1, size_t a2)
{
void *result; // rax

result = calloc(a1, a2);
if ( !result )
die("error: failed to allocate %zd bytes", a2);
return result;
}

canonical_decompiled_code:
void *__fastcall func7(size_t a1, size_t a2)
{
void *result; // rax

result = calloc(a1, a2);
if ( !result )
func1("error: failed to allocate %zd bytes", a2);
return result;
}

original_code:
void *xcalloc(size_t nmemb, size_t size) {
  void *ret = calloc(nmemb, size);
  if (!ret) {
    die("error: failed to allocate %zd bytes", size);
  }
  return(ret);
}

canonical_original_code:
void *xcalloc(unsigned long nmemb, unsigned long size) {
  void *ret = calloc(nmemb, size);
  if (!ret) {
    die("error: failed to allocate %zd bytes", size);
  }
  return(ret);
}

variable_types:
nmemb
unsigned long


decompiled_code:
char *__fastcall get_password(__int64 a1)
{
char *v1; // r12
int v2; // eax
int v3; // eax
int v4; // eax
struct termios v6; // [rsp+0h] [rbp-58h] BYREF

v1 = (char *)xcalloc(1uLL, a1 + 1);
printf("Enter password: ");
v2 = fileno(stdin);
tcgetattr(v2, &v6);
v6.c_lflag &= 0xFFFFFFF7;
v3 = fileno(stdin);
tcsetattr(v3, 0, &v6);
fgets(v1, a1 + 1, stdin);
v1[strlen(v1) - 1] = 0;
putchar(10);
v6.c_lflag |= 8u;
v4 = fileno(stdin);
tcsetattr(v4, 0, &v6);
return v1;
}

canonical_decompiled_code:
char *__fastcall func8(__int64 a1)
{
char *v1; // r12
int v2; // eax
int v3; // eax
int v4; // eax
struct termios v6; // [rsp+0h] [rbp-58h] BYREF

v1 = (char *)func7(1uLL, a1 + 1);
printf("Enter password: ");
v2 = fileno(stdin);
tcgetattr(v2, &v6);
v6.c_lflag &= 0xFFFFFFF7;
v3 = fileno(stdin);
tcsetattr(v3, 0, &v6);
fgets(v1, a1 + 1, stdin);
v1[strlen(v1) - 1] = 0;
putchar(10);
v6.c_lflag |= 8u;
v4 = fileno(stdin);
tcsetattr(v4, 0, &v6);
return v1;
}

original_code:
char *get_password(size_t maxlen) {
  struct termios t;
  char *buf;
  buf = xcalloc(1, ++maxlen);
  printf("Enter password: ");
  tcgetattr(fileno(stdin), &t);
  t.c_lflag &= ~0000010;
  tcsetattr(fileno(stdin), 0, &t);
  fgets(buf, maxlen, stdin);
  *(buf + strlen(buf) - 1) = '\0';
  putchar('\n');
  t.c_lflag |= 0000010;
  tcsetattr(fileno(stdin), 0, &t);
  return(buf);
}

canonical_original_code:
char *get_password(unsigned long maxlen) {
  struct termios t;
  char *buf;
  buf = xcalloc(1, ++maxlen);
  printf("Enter password: ");
  tcgetattr(fileno(stdin), &t);
  t.c_lflag &= ~0000010;
  tcsetattr(fileno(stdin), 0, &t);
  fgets(buf, maxlen, stdin);
  *(buf + strlen(buf) - 1) = '\0';
  putchar('\n');
  t.c_lflag |= 0000010;
  tcsetattr(fileno(stdin), 0, &t);
  return(buf);
}

variable_types:
maxlen
unsigned long

variable_types: struct termios { unsigned int c_iflag; unsigned int c_oflag; unsigned int c_cflag; unsigned int c_lflag; unsigned char c_line; unsigned char c_cc[32]; unsigned int c_ispeed; unsigned int c_ospeed; }


decompiled_code:
char *__fastcall get_username(__int64 a1)
{
char *v1; // r12

v1 = (char *)xcalloc(1uLL, a1 + 1);
printf("Enter username: ");
fgets(v1, a1 + 1, stdin);
v1[strlen(v1) - 1] = 0;
return v1;
}

canonical_decompiled_code:
char *__fastcall func9(__int64 a1)
{
char *v1; // r12

v1 = (char *)func7(1uLL, a1 + 1);
printf("Enter username: ");
fgets(v1, a1 + 1, stdin);
v1[strlen(v1) - 1] = 0;
return v1;
}

original_code:
char *get_username(size_t maxlen) {
  char *buf;
  buf = xcalloc(1, ++maxlen);
  printf("Enter username: ");
  fgets(buf, maxlen, stdin);
  *(buf + strlen(buf) - 1) = '\0';
  return(buf);
}

canonical_original_code:
char *get_username(unsigned long maxlen) {
  char *buf;
  buf = xcalloc(1, ++maxlen);
  printf("Enter username: ");
  fgets(buf, maxlen, stdin);
  *(buf + strlen(buf) - 1) = '\0';
  return(buf);
}


original_code:
static size_t write_response(void *ptr, size_t size, size_t nmemb, void *stream) {
  struct write_result *mem = (struct write_result*)stream;
  size_t realsize = nmemb * size;
  mem->memory = realloc(mem->memory, mem->size + realsize + 1);
  if (mem->memory) {
    memcpy(&(mem->memory[mem->size]), ptr, realsize);
    mem->size += realsize;
    mem->memory[mem->size] = 0;
  }
  return(realsize);
}

canonical_original_code:
static unsigned long write_response(void *ptr, unsigned long size, unsigned long nmemb, void *stream) {
  struct write_result *mem = (struct write_result*)stream;
  unsigned long realsize = nmemb * size;
  mem->memory = realloc(mem->memory, mem->size + realsize + 1);
  if (mem->memory) {
    memcpy(&(mem->memory[mem->size]), ptr, realsize);
    mem->size += realsize;
    mem->memory[mem->size] = 0;
  }
  return(realsize);
}

variable_types:
ptr
void *

variable_types:
stream
void *

variable_types: struct write_result { char *memory; unsigned long size; } *

variable_types:
realsize
unsigned long

return_type: unsigned long


decompiled_code:
_BOOL8 __fastcall cookie_still_valid(time_t a1)
{
return time(0LL) < a1;
}

canonical_decompiled_code:
_BOOL8 __fastcall func0(time_t a1)
{
return time(0LL) < a1;
}

original_code:
int cookie_still_valid(long expire) {
  return(time(((void *)0)) < expire);
}

variable_types: expire long


decompiled_code:
char **__fastcall cookie_to_struct(char *a1, char ***a2)
{
char **v2; // rbp
char *v3; // rax
char **v4; // rbp
char *v5; // rax
char **v6; // rbp
char **v7; // rbp
char **v8; // rbp

v2 = *a2;
*v2 = strtok(a1, "\t");
v3 = strtok(0LL, "\t");
v4 = *a2;
*((_DWORD *)v4 + 2) = strcmp(v3, "TRUE") == 0;
v4[2] = strtok(0LL, "\t");
*((_DWORD *)*a2 + 6) = strcmp(strtok(0LL, "\t"), "TRUE") == 0;
v5 = strtok(0LL, "\t");
v6 = *a2;
v6[4] = (char *)strtol(v5, 0LL, 10);
v7 = *a2;
v7[5] = strtok(0LL, "\t");
v8 = *a2;
v8[6] = strtok(0LL, "\t");
return *a2;
}

original_code:
cookie_t *cookie_to_struct(char *co, cookie_t **cookie) {
  (*cookie)->domain = strtok(co, "\t");
  (*cookie)->secure = strcmp(strtok(((void *)0), "\t"),"TRUE") == 0 ? 1 : 0;
  (*cookie)->path = strtok(((void *)0), "\t");
  (*cookie)->httponly = strcmp(strtok(((void *)0), "\t"),"TRUE") == 0 ? 1 : 0;
  (*cookie)->expire = strtol(strtok(((void *)0), "\t"), ((void *)0), 10);
  (*cookie)->name = strtok(((void *)0), "\t");
  (*cookie)->value = strtok(((void *)0), "\t");
  return(*cookie);
}

canonical_original_code:
struct __cookie_t *cookie_to_struct(char *co, struct __cookie_t **cookie) {
  (*cookie)->domain = strtok(co, "\t");
  (*cookie)->secure = strcmp(strtok(((void *)0), "\t"),"TRUE") == 0 ? 1 : 0;
  (*cookie)->path = strtok(((void *)0), "\t");
  (*cookie)->httponly = strcmp(strtok(((void *)0), "\t"),"TRUE") == 0 ? 1 : 0;
  (*cookie)->expire = strtol(strtok(((void *)0), "\t"), ((void *)0), 10);
  (*cookie)->name = strtok(((void *)0), "\t");
  (*cookie)->value = strtok(((void *)0), "\t");
  return(*cookie);
}

variable_types:
co
char *

variable_types:
cookie
struct __cookie_t **

return_type: struct __cookie_t { char *domain; int secure; char *path; int httponly; long expire; char *name; char *value; } *


decompiled_code:
void __fastcall config_free(void *ptr)
{
void *v2; // rdi
void *v3; // rdi
void *v4; // rdi

v2 = *(void **)ptr;
if ( v2 )
free(v2);
v3 = (void *)*((_QWORD *)ptr + 1);
if ( v3 )
free(v3);
v4 = (void *)*((_QWORD *)ptr + 2);
if ( v4 )
free(v4);
if ( *((_QWORD *)ptr + 3) && strcmp(*((const char **)ptr + 3), "None") )
{
free(*((void **)ptr + 3));
free(ptr);
}
else
{
free(ptr);
}
}

canonical_decompiled_code:
void __fastcall func0(void *ptr)
{
void *v2; // rdi
void *v3; // rdi
void *v4; // rdi

v2 = *(void **)ptr;
if ( v2 )
free(v2);
v3 = (void *)*((_QWORD *)ptr + 1);
if ( v3 )
free(v3);
v4 = (void *)*((_QWORD *)ptr + 2);
if ( v4 )
free(v4);
if ( *((_QWORD *)ptr + 3) && strcmp(*((const char **)ptr + 3), "None") )
{
free(*((void **)ptr + 3));
free(ptr);
}
else
{
free(ptr);
}
}

original_code:
void config_free(config_t *config) {
  if (config->user) {
    free(config->user);
  }
  if (config->password) {
    free(config->password);
  }
  if (config->cookies) {
    free(config->cookies);
  }
  if (config->category && strcmp(config->category,"None") != 0) {
    free(config->category);
  }
  free(config);
}

canonical_original_code:
void config_free(struct __config_t *config) {
  if (config->user) {
    free(config->user);
  }
  if (config->password) {
    free(config->password);
  }
  if (config->cookies) {
    free(config->cookies);
  }
  if (config->category && strcmp(config->category,"None") != 0) {
    free(config->category);
  }
  free(config);
}

variable_types: struct __config_t { char *user; char *password; char *cookies; char *category; int catnum; int persist; int verbose; } *


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

result = xcalloc(1LL, 48LL);
*(_QWORD *)result = 0LL;
*(_QWORD *)(result + 8) = 0LL;
*(_QWORD *)(result + 16) = 0LL;
*(_QWORD *)(result + 24) = 0LL;
*(_QWORD *)(result + 32) = 1LL;
*(_DWORD *)(result + 40) = 0;
return result;
}

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

result = xcalloc(1LL, 48LL);
*(_QWORD *)result = 0LL;
*(_QWORD *)(result + 8) = 0LL;
*(_QWORD *)(result + 16) = 0LL;
*(_QWORD *)(result + 24) = 0LL;
*(_QWORD *)(result + 32) = 1LL;
*(_DWORD *)(result + 40) = 0;
return result;
}

original_code:
config_t *config_new(void) {
  config_t *config = xcalloc(1, sizeof *config);
  config->user = config->password = config->cookies = config->category = ((void *)0);
  config->persist = 0;
  config->verbose = 0;
  config->catnum = 1;
  return(config);
}

canonical_original_code:
struct __config_t *config_new() {
  struct __config_t *config = xcalloc(1, sizeof *config);
  config->user = config->password = config->cookies = config->category = ((void *)0);
  config->persist = 0;
  config->verbose = 0;
  config->catnum = 1;
  return(config);
}

return_type: struct __config_t { char *user; char *password; char *cookies; char *category; int catnum; int persist; int verbose; } *


decompiled_code:
void *__fastcall GenericMemoryManager_malloc_f(__int64 a1)
{
size_t v1; // rbp
void *v2; // r12
__int64 v3; // rax
__int64 v4; // rbx
_DWORD *v5; // rax
int v6; // edx
void *result; // rax
_DWORD *v8; // rax

v1 = *(_QWORD *)a1;
v2 = malloc(*(_QWORD *)a1);
printf("[INFO] allocated %zu bytes of memory at %p\n", v1, v2);
v3 = *(_QWORD *)(a1 + 16);
++*(_DWORD *)(a1 + 8);
if ( v3 )
{
do
{
v4 = v3;
v3 = *(_QWORD *)(v3 + 16);
}
while ( v3 );
v5 = malloc(0x18uLL);
v6 = *(_DWORD *)(v4 + 8);
*(_QWORD *)(v4 + 16) = v5;
*(_QWORD *)v5 = v2;
v5[2] = v6 + 1;
result = v2;
}
else
{
v8 = malloc(0x18uLL);
*(_QWORD *)(a1 + 16) = v8;
*(_QWORD *)v8 = v2;
v8[2] = 0;
result = v2;
}
return result;
}

canonical_decompiled_code:
void *__fastcall func0(__int64 a1)
{
size_t v1; // rbp
void *v2; // r12
__int64 v3; // rax
__int64 v4; // rbx
_DWORD *v5; // rax
int v6; // edx
void *result; // rax
_DWORD *v8; // rax

v1 = *(_QWORD *)a1;
v2 = malloc(*(_QWORD *)a1);
printf("[INFO] allocated %zu bytes of memory at %p\n", v1, v2);
v3 = *(_QWORD *)(a1 + 16);
++*(_DWORD *)(a1 + 8);
if ( v3 )
{
do
{
v4 = v3;
v3 = *(_QWORD *)(v3 + 16);
}
while ( v3 );
v5 = malloc(0x18uLL);
v6 = *(_DWORD *)(v4 + 8);
*(_QWORD *)(v4 + 16) = v5;
*(_QWORD *)v5 = v2;
v5[2] = v6 + 1;
result = v2;
}
else
{
v8 = malloc(0x18uLL);
*(_QWORD *)(a1 + 16) = v8;
*(_QWORD *)v8 = v2;
v8[2] = 0;
result = v2;
}
return result;
}

original_code:
void* GenericMemoryManager_malloc_f(struct GenericMemoryManager* this)
{
    void *m = malloc(this->memsize);
        printf("[INFO] allocated %zu bytes of memory at %p\n", this->memsize, m);
    ++this->malloc_stats;
    {
  struct ManagedMemoryArea_list* current = this->mamanged_memory_chunks;
  struct ManagedMemoryArea_list* head = current;
  for(; current; current = current->next){
   head = current;
  }
  struct ManagedMemoryArea_list *new = malloc((sizeof(struct ManagedMemoryArea_list)));
  int id;
  if(head == ((void *)0)){
   this->mamanged_memory_chunks = new;
   id = 0;
  }else{
   head->next = new;
   id = head->elem.id + 1;
  }
  new->elem.start = m;
  new->elem.id = id;
    }
    return m;
}

canonical_original_code:
void *GenericMemoryManager_malloc_f(struct GenericMemoryManager *this)
{
    void *m = malloc(this->memsize);
        printf("[INFO] allocated %zu bytes of memory at %p\n", this->memsize, m);
    ++this->malloc_stats;
    {
  struct ManagedMemoryArea_list *current = this->mamanged_memory_chunks;
  struct ManagedMemoryArea_list *head = current;
  for(; current; current = current->next){
   head = current;
  }
  struct ManagedMemoryArea_list *new = malloc((sizeof(struct ManagedMemoryArea_list)));
  int id;
  if(head == ((void *)0)){
   this->mamanged_memory_chunks = new;
   id = 0;
  }else{
   head->next = new;
   id = head->elem.id + 1;
  }
  new->elem.start = m;
  new->elem.id = id;
    }
    return m;
}

variable_types: struct GenericMemoryManager { unsigned long memsize; unsigned int malloc_stats; unsigned int free_stats; struct ManagedMemoryArea_list { struct ManagedMemoryArea { void *start; unsigned int id; } elem; struct ManagedMemoryArea_list *next; } *mamanged_memory_chunks; } *

variable_types:
m
void *

variable_types: id int

user_defined_types: struct GenericMemoryManager { unsigned long memsize; unsigned int malloc_stats; unsigned int free_stats; struct ManagedMemoryArea_list *mamanged_memory_chunks; }

user_defined_types: struct ManagedMemoryArea_list { struct ManagedMemoryArea elem; struct ManagedMemoryArea_list *next; }


decompiled_code:
void __fastcall GenericMemoryManager_free_f(size_t *a1, void *a2)
{
_QWORD *v2; // rbp
_QWORD *v3; // rbx

printf("[INFO] freeing %zu bytes of memory at %p\n", *a1, a2);
bzero(a2, *a1);
v2 = (_QWORD *)a1[2];
if ( v2 )
{
v3 = 0LL;
while ( (void *)*v2 != a2 )
{
v3 = v2;
if ( !v2[2] )
goto LABEL_9;
v2 = (_QWORD *)v2[2];
}
printf("[INFO] free: found memory with id %d\n", *((unsigned int *)v2 + 2));
if ( v3 )
v3[2] = v2[2];
else
a1[2] = 0LL;
free(v2);
}
else
{
LABEL_9:
printf("[ERROR] memory at %p not managed by this manager!\n", a2);
}
free(a2);
++*((_DWORD *)a1 + 3);
}

canonical_decompiled_code:
void __fastcall func1(size_t *a1, void *a2)
{
_QWORD *v2; // rbp
_QWORD *v3; // rbx

printf("[INFO] freeing %zu bytes of memory at %p\n", *a1, a2);
bzero(a2, *a1);
v2 = (_QWORD *)a1[2];
if ( v2 )
{
v3 = 0LL;
while ( (void *)*v2 != a2 )
{
v3 = v2;
if ( !v2[2] )
goto LABEL_9;
v2 = (_QWORD *)v2[2];
}
printf("[INFO] free: found memory with id %d\n", *((unsigned int *)v2 + 2));
if ( v3 )
v3[2] = v2[2];
else
a1[2] = 0LL;
free(v2);
}
else
{
LABEL_9:
printf("[ERROR] memory at %p not managed by this manager!\n", a2);
}
free(a2);
++*((_DWORD *)a1 + 3);
}

original_code:
void GenericMemoryManager_free_f(struct GenericMemoryManager* this, void* m)
{
        printf("[INFO] freeing %zu bytes of memory at %p\n", this->memsize, m);
    bzero(m, this->memsize);
    {
  struct ManagedMemoryArea_list* current = this->mamanged_memory_chunks;
  struct ManagedMemoryArea_list* prev = ((void *)0);
  int found = 0;
  for(; current; current = current->next){
   if(current->elem.start == m){
     printf("[INFO] free: found memory with id %d\n", current->elem.id);
    found = 1;
    break;
   }
   prev = current;
  }
  if(found){
   if(prev){
    prev->next = current->next;
   }else{
    this->mamanged_memory_chunks = ((void *)0);
   }
   free(current);
  }else{
   printf("[ERROR] memory at %p not managed by this manager!\n", m);
  }
 }
    free(m);
    ++this->free_stats;
}

canonical_original_code:
void GenericMemoryManager_free_f(struct GenericMemoryManager *this, void *m)
{
        printf("[INFO] freeing %zu bytes of memory at %p\n", this->memsize, m);
    bzero(m, this->memsize);
    {
  struct ManagedMemoryArea_list *current = this->mamanged_memory_chunks;
  struct ManagedMemoryArea_list *prev = ((void *)0);
  int found = 0;
  for(; current; current = current->next){
   if(current->elem.start == m){
     printf("[INFO] free: found memory with id %d\n", current->elem.id);
    found = 1;
    break;
   }
   prev = current;
  }
  if(found){
   if(prev){
    prev->next = current->next;
   }else{
    this->mamanged_memory_chunks = ((void *)0);
   }
   free(current);
  }else{
   printf("[ERROR] memory at %p not managed by this manager!\n", m);
  }
 }
    free(m);
    ++this->free_stats;
}

variable_types: struct ManagedMemoryArea_list { struct ManagedMemoryArea { void *start; unsigned int id; } elem; struct ManagedMemoryArea_list *next; } *

variable_types: found int


decompiled_code:
int __fastcall GenericMemoryManager_print_stats(__int64 a1)
{
int result; // eax
__int64 i; // rbx

printf("Num malloc: %u, Num free: %u \n", *(unsigned int *)(a1 + 8), *(unsigned int *)(a1 + 12));
result = puts("Managed chunks:");
for ( i = *(_QWORD *)(a1 + 16); i; i = *(_QWORD *)(i + 16) )
result = printf(" id: %u\n", *(unsigned int *)(i + 8));
return result;
}

canonical_decompiled_code:
int __fastcall func2(__int64 a1)
{
int result; // eax
__int64 i; // rbx

printf("Num malloc: %u, Num free: %u \n", *(unsigned int *)(a1 + 8), *(unsigned int *)(a1 + 12));
result = puts("Managed chunks:");
for ( i = *(_QWORD *)(a1 + 16); i; i = *(_QWORD *)(i + 16) )
result = printf(" id: %u\n", *(unsigned int *)(i + 8));
return result;
}

original_code:
void GenericMemoryManager_print_stats(struct GenericMemoryManager* this)
{
    printf("Num malloc: %u, Num free: %u \n", this->malloc_stats, this->free_stats);
    printf("Managed chunks:\n");
    struct ManagedMemoryArea_list* current = this->mamanged_memory_chunks;
 for(; current; current = current->next){
     printf("  id: %u\n", current->elem.id);
 }
}

canonical_original_code:
void GenericMemoryManager_print_stats(struct GenericMemoryManager *this)
{
    printf("Num malloc: %u, Num free: %u \n", this->malloc_stats, this->free_stats);
    printf("Managed chunks:\n");
    struct ManagedMemoryArea_list *current = this->mamanged_memory_chunks;
 for(; current; current = current->next){
     printf("  id: %u\n", current->elem.id);
 }
}

user_defined_types: struct ManagedMemoryArea { void *start; unsigned int id; }


decompiled_code:
void __fastcall GenericMemoryManager_delete(void *ptr)
{
printf("[INFO] Deleting GenericMemoryManager at %p for memory of size %zu\n", ptr, *(_QWORD *)ptr);
if ( *((_QWORD *)ptr + 2) )
{
puts("[ERROR] Memory Mamanager still has managed memory chunks, cannot delete");
}
else
{
if ( *((_DWORD *)ptr + 2) != *((_DWORD *)ptr + 3) )
puts("[ERROR] numer of frees neq number of mallocs");
free(ptr);
}
}

canonical_decompiled_code:
void __fastcall func3(void *ptr)
{
printf("[INFO] Deleting GenericMemoryManager at %p for memory of size %zu\n", ptr, *(_QWORD *)ptr);
if ( *((_QWORD *)ptr + 2) )
{
puts("[ERROR] Memory Mamanager still has managed memory chunks, cannot delete");
}
else
{
if ( *((_DWORD *)ptr + 2) != *((_DWORD *)ptr + 3) )
puts("[ERROR] numer of frees neq number of mallocs");
free(ptr);
}
}

original_code:
void GenericMemoryManager_delete(struct GenericMemoryManager *this)
{
        printf("[INFO] Deleting GenericMemoryManager at %p for memory of size"
            " %zu\n", this, this->memsize);
    if(this->mamanged_memory_chunks != ((void *)0)){
     printf("[ERROR] Memory Mamanager still has managed memory chunks, cannot delete\n");
    }else{
     if(this->malloc_stats != this->free_stats){
      printf("[ERROR] numer of frees neq number of mallocs\n");
     }
     free(this);
    }
}


isEncrypted

repo: diffalot/DReaM

decompiled_code:
bool __fastcall isEncrypted(const char *a1)
{
return (unsigned int)strcasestr(a1, ".en.mpg") != 0;
}

canonical_decompiled_code:
bool __fastcall func0(const char *a1)
{
return (unsigned int)strcasestr(a1, ".en.mpg") != 0;
}

original_code:
static unsigned char isEncrypted( char *media_url )
{
    char *isEnc = strcasestr( media_url, ".en.mpg" );
    return ( isEnc ? 1 : 0 );
}

canonical_original_code:
static unsigned char isEncrypted(char *media_url)
{
    char *isEnc = strcasestr( media_url, ".en.mpg" );
    return ( isEnc ? 1 : 0 );
}

variable_types:
isEnc
char *

return_type: unsigned char


reportAction

decompiled_code:
__int64 __fastcall reportAction(unsigned int a1, __int64 a2)
{
return jniReportUsage(xface_ptr, a1, a2);
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned int a1, __int64 a2)
{
return jniReportUsage(xface_ptr, a1, a2);
}

original_code:
static void reportAction( ActionId id, char * media_url )
{
    jniReportUsage( xface_ptr, id, media_url );
}

canonical_original_code:
static void reportAction(enum ActionId id, char *media_url)
{
    jniReportUsage( xface_ptr, id, media_url );
}

variable_types: enum ActionId { PLAY=0, RECORD=1, FFWD=2, RWND=3, CLEAR_COPY=4, ADAPT=5 }


canDoAction

decompiled_code:
__int64 __fastcall canDoAction(unsigned int a1, const char *a2, __int64 a3)
{
unsigned int v3; // er13

v3 = 1;
if ( isEncrypted(a2) )
{
v3 = jniCheckRights(xface_ptr, a1, a2, a3);
fprintf(stderr, "\n%s:%d::media_url %s retval %d", "rights_xface.c", 65LL, a2, (unsigned __int8)v3);
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func2(unsigned int a1, const char *a2, __int64 a3)
{
unsigned int v3; // er13

v3 = 1;
if ( func0(a2) )
{
v3 = jniCheckRights(xface_ptr, a1, a2, a3);
fprintf(stderr, "\n%s:%d::media_url %s retval %d", "rights_xface.c", 65LL, a2, (unsigned __int8)v3);
}
return v3;
}

original_code:
static unsigned char canDoAction( ActionId id, char * media_url,
                    ActionStat * stat )
{
    if( !isEncrypted( media_url ) ) {
        return 1;
    }
    unsigned char ret = jniCheckRights( xface_ptr, id, media_url, stat);
    fprintf( stderr, "\n%s:%d::media_url %s retval %d", "rights_xface.c", 65,
    media_url, ret );
    return ret;
}

canonical_original_code:
static unsigned char canDoAction(enum ActionId id, char *media_url, struct ActionStat *stat)
{
    if( !isEncrypted( media_url ) ) {
        return 1;
    }
    unsigned char ret = jniCheckRights( xface_ptr, id, media_url, stat);
    fprintf( stderr, "\n%s:%d::media_url %s retval %d", "rights_xface.c", 65,
    media_url, ret );
    return ret;
}

variable_types: struct ActionStat { int cnt; struct Period { int millis; } start; struct Period end; struct Scale { int nr; int dr; } scale; enum DeviceTarget { N_A=0, DVD=1, CD=2 } target; unsigned char *keys; int keys_len; } *

variable_types:
ret
unsigned char

user_defined_types: enum ActionId { PLAY=0, RECORD=1, FFWD=2, RWND=3, CLEAR_COPY=4, ADAPT=5 }

user_defined_types: struct ActionStat { int cnt; struct Period start; struct Period end; struct Scale scale; enum DeviceTarget target; unsigned char *keys; int keys_len; }