ReadName

decompiled_code:
const char *__fastcall ReadName(unsigned __int8 *a1, __int64 a2, _DWORD *a3)
{
unsigned __int8 *v5; // rbx
const char *v6; // rax
const char *v7; // r12
int v8; // eax
int v9; // ecx
__int64 v10; // rdx
unsigned int v11; // esi
int i; // ebx
char *v13; // rdi
int v14; // ebp
const char *v15; // rsi

v5 = a1;
*a3 = 1;
v6 = (const char *)nss_tk_myalloc(256LL);
*v6 = 0;
v7 = v6;
v8 = *a1;
if ( !(_BYTE)v8 )
goto LABEL_10;
v9 = 0;
v10 = 0LL;
do
{
while ( (unsigned __int8)v8 > 0xBFu )
{
v9 = 1;
v5 = (unsigned __int8 *)(a2 + v5[1] + (v8 << 8) - 49152);
LABEL_4:
v8 = *v5;
if ( !(_BYTE)v8 )
goto LABEL_8;
}
v11 = v10 + 1;
v7[v10] = v8;
++v5;
v10 = (unsigned int)(v10 + 1);
if ( v9 )
goto LABEL_4;
++*a3;
v8 = *v5;
v10 = v11;
}
while ( (_BYTE)v8 );
LABEL_8:
v7[v10] = 0;
if ( v9 == 1 )
++*a3;
LABEL_10:
for ( i = 0; i < (int)strlen(v7); ++i )
{
v13 = (char *)&v7[i];
v14 = (unsigned __int8)*v13;
if ( (_BYTE)v14 )
{
v15 = &v7[i + 1];
i += v14;
memmove(v13, v15, (unsigned __int8)v14);
v13 = (char *)&v7[i];
}
*v13 = 46;
}
v7[i - 1] = 0;
return v7;
}

canonical_decompiled_code:
const char *__fastcall func1(unsigned __int8 *a1, __int64 a2, _DWORD *a3)
{
unsigned __int8 *v5; // rbx
const char *v6; // rax
const char *v7; // r12
int v8; // eax
int v9; // ecx
__int64 v10; // rdx
unsigned int v11; // esi
int i; // ebx
char *v13; // rdi
int v14; // ebp
const char *v15; // rsi

v5 = a1;
*a3 = 1;
v6 = (const char *)nss_tk_myalloc(256LL);
*v6 = 0;
v7 = v6;
v8 = *a1;
if ( !(_BYTE)v8 )
goto LABEL_10;
v9 = 0;
v10 = 0LL;
do
{
while ( (unsigned __int8)v8 > 0xBFu )
{
v9 = 1;
v5 = (unsigned __int8 *)(a2 + v5[1] + (v8 << 8) - 49152);
LABEL_4:
v8 = *v5;
if ( !(_BYTE)v8 )
goto LABEL_8;
}
v11 = v10 + 1;
v7[v10] = v8;
++v5;
v10 = (unsigned int)(v10 + 1);
if ( v9 )
goto LABEL_4;
++*a3;
v8 = *v5;
v10 = v11;
}
while ( (_BYTE)v8 );
LABEL_8:
v7[v10] = 0;
if ( v9 == 1 )
++*a3;
LABEL_10:
for ( i = 0; i < (int)strlen(v7); ++i )
{
v13 = (char *)&v7[i];
v14 = (unsigned __int8)*v13;
if ( (_BYTE)v14 )
{
v15 = &v7[i + 1];
i += v14;
memmove(v13, v15, (unsigned __int8)v14);
v13 = (char *)&v7[i];
}
*v13 = 46;
}
v7[i - 1] = 0;
return v7;
}

original_code:
u_char *ReadName(UCHAR * reader, UCHAR * buffer, int *count)
{
 UCHAR *name;
 unsigned int p = 0, jumped = 0, offset;
 int i, j;
 *count = 1;
 name = (UCHAR *) _nss_tk_myalloc(256 * sizeof(UCHAR));
 name[0] = '\0';
 while (*reader != 0) {
  if (*reader >= 192) {
   offset = (*reader) * 256 + *(reader + 1) - 49152;
   reader = buffer + offset - 1;
   jumped = 1;
  } else {
   name[p++] = *reader;
  }
  reader = reader + 1;
  if (jumped == 0) {
   *count = *count + 1;
  }
 }
 name[p] = '\0';
 if (jumped == 1) {
  *count = *count + 1;
 }
 for (i = 0; i < (int)strlen((const char *)name); i++) {
  p = name[i];
  for (j = 0; j < (int)p; j++) {
   name[i] = name[i + 1];
   i = i + 1;
  }
  name[i] = '.';
 }
 name[i - 1] = '\0';
 return name;
}

canonical_original_code:
unsigned char *ReadName(unsigned char *reader, unsigned char *buffer, int *count)
{
 unsigned char *name;
 unsigned int p = 0; unsigned int jumped = 0; unsigned int offset;
 int i; int j;
 *count = 1;
 name = (unsigned char *) _nss_tk_myalloc(256 * sizeof(UCHAR));
 name[0] = '\0';
 while (*reader != 0) {
  if (*reader >= 192) {
   offset = (*reader) * 256 + *(reader + 1) - 49152;
   reader = buffer + offset - 1;
   jumped = 1;
  } else {
   name[p++] = *reader;
  }
  reader = reader + 1;
  if (jumped == 0) {
   *count = *count + 1;
  }
 }
 name[p] = '\0';
 if (jumped == 1) {
  *count = *count + 1;
 }
 for (i = 0; i < (int)strlen((char *)name); i++) {
  p = name[i];
  for (j = 0; j < (int)p; j++) {
   name[i] = name[i + 1];
   i = i + 1;
  }
  name[i] = '.';
 }
 name[i - 1] = '\0';
 return name;
}

variable_types:
reader
unsigned char *

variable_types:
buffer
unsigned char *

variable_types:
count
int *

variable_types:
name
unsigned char *

variable_types:
p
unsigned int

variable_types:
jumped
unsigned int

variable_types:
offset
unsigned int

variable_types: i int

variable_types: j int


ngethostbyname

repo: torrentkino/torrentkino

decompiled_code:
__int64 __fastcall ngethostbyname(const char *a1, __int64 a2, __int64 a3, __int64 a4, __int16 a5)
{
int v7; // eax
int v8; // ebp
__int16 v9; // ax
__int16 v10; // ax
__int16 v11; // dx
__int16 v12; // ax
__int16 v13; // cx
__int16 v14; // ax
__int16 *v15; // rcx
size_t v16; // rax
__int64 result; // rax
__int64 v18; // rbx
int v19; // er14
size_t v20; // rax
unsigned __int16 v21; // dx
unsigned __int8 *v22; // rbp
int v23; // edx
int v24; // eax
unsigned __int8 *v25; // rbp
__int16 v26; // [rsp+Ch] [rbp-1012Ch]
__int16 v27; // [rsp+Ch] [rbp-1012Ch]
socklen_t addr_len; // [rsp+18h] [rbp-10120h] BYREF
int v29; // [rsp+1Ch] [rbp-1011Ch] BYREF
__int64 optval[2]; // [rsp+20h] [rbp-10118h] BYREF
struct sockaddr addr; // [rsp+30h] [rbp-10108h] BYREF
__int64 v32[24]; // [rsp+40h] [rbp-100F8h]
__int16 buf[2]; // [rsp+100h] [rbp-10038h] BYREF
__int16 v34; // [rsp+104h] [rbp-10034h]
int v35; // [rsp+106h] [rbp-10032h]
__int16 v36; // [rsp+10Ah] [rbp-1002Eh]
char s[65580]; // [rsp+10Ch] [rbp-1002Ch] BYREF

v7 = socket(2, 2, 17);
if ( v7 < 0 )
return 0LL;
v8 = v7;
optval[0] = 10LL;
optval[1] = 0LL;
setsockopt(v7, 1, 20, optval, 0x10u);
addr.sa_family = 2;
*(_WORD *)addr.sa_data = _bswap_16(6853);
*(_DWORD *)&addr.sa_data[2] = inet_addr("127.0.0.1");
v9 = getpid();
v10 = _bswap_16(v9);
buf[1] = v11;
buf[0] = v10;
v12 = _bswap_16(1);
v36 = v13;
v34 = v12;
v26 = v12;
v35 = 0;
ChangetoDnsNameFormat(s, a1);
strlen(s);
v14 = _bswap_16(a5);
*v15 = v14;
v15[1] = v26;
v16 = strlen(s);
if ( sendto(v8, buf, v16 + 17, 0, &addr, 0x10u) < 0 )
return 0LL;
addr_len = 16;
if ( recvfrom(v8, buf, 0x10000uLL, 0, &addr, &addr_len) < 0 )
return 0LL;
if ( _bswap_16(v34) != 1 )
return 0LL;
v27 = _bswap_16(v35);
if ( (unsigned __int16)(v27 - 1) > 7u || _bswap_16(SHIWORD(v35)) || _bswap_16(v36) )
return 0LL;
v18 = 0LL;
v19 = 0;
v20 = strlen(s);
v29 = 0;
v21 = v27;
addr_len = 0;
v22 = (unsigned __int8 *)&buf[8] + v20 + 1;
while ( 1 )
{
result = (unsigned int)v18;
if ( v19 > 7 || v21 <= v19 )
break;
v32[3 * v19] = (__int64)ReadName(v22, (__int64)buf, &v29);
v25 = &v22[v29];
if ( _bswap_16(*((_WORD *)v25 + 4)) != 4 || _bswap_16(*(_WORD *)v25) != 1 )
return 0LL;
v24 = *(_DWORD *)(v25 + 10);
v22 = v25 + 14;
*(_DWORD *)(a3 + 4 * v18++) = v24;
nss_tk_myfree(v32[3 * v23]);
v19 = ++addr_len;
v21 = _bswap_16(v35);
}
return result;
}

original_code:
int ngethostbyname(const char *host, int hostsize, UCHAR * address,
     int address_size, int query_type)
{
 UCHAR buf[65536], *qname, *reader;
 int i, stop, s;
 struct timeval tv;
 UCHAR *p = address;
 int result = 0;
 IP dest;
 struct RES_RECORD answers[8];
 struct DNS_HEADER *dns = ((void *)0);
 struct QUESTION *qinfo = ((void *)0);
 s = socket(2, SOCK_DGRAM, IPPROTO_UDP);
 if (s < 0) {
  return 0;
 }
 tv.tv_sec = 10;
 tv.tv_usec = 0;
 setsockopt(s, 1, 20, (char *)&tv,
     sizeof(struct timeval));
 dest.sin_family = 2;
 dest.sin_port = htons(6853);
 dest.sin_addr.s_addr = inet_addr("127.0.0.1");
 dns = (struct DNS_HEADER *)&buf;
 dns->id = (USHORT) htons(getpid());
 dns->qr = 0;
 dns->opcode = 0;
 dns->aa = 0;
 dns->tc = 0;
 dns->rd = 1;
 dns->ra = 0;
 dns->z = 0;
 dns->ad = 0;
 dns->cd = 0;
 dns->rcode = 0;
 dns->q_count = htons(1);
 dns->ans_count = 0;
 dns->auth_count = 0;
 dns->add_count = 0;
 qname = (UCHAR *) & buf[sizeof(struct DNS_HEADER)];
 ChangetoDnsNameFormat(qname, host);
 qinfo =
     (struct QUESTION *)&buf[sizeof(struct DNS_HEADER) +
        (strlen((const char *)qname) + 1)];
 qinfo->qtype = htons(query_type);
 qinfo->qclass = htons(1);
 if (sendto(s, (char *)buf,
     sizeof(struct DNS_HEADER) + (strlen((const char *)qname) +
      1) + sizeof(struct QUESTION), 0,
     (struct sockaddr *)&dest, sizeof(dest)) < 0) {
  return 0;
 }
 i = sizeof dest;
 if (recvfrom
     (s, (char *)buf, 65536, 0, (struct sockaddr *)&dest,
      (socklen_t *) & i) < 0) {
  return 0;
 }
 dns = (struct DNS_HEADER *)buf;
 if (ntohs(dns->q_count) != 1) {
  return 0;
 }
 if (ntohs(dns->ans_count) < 1 || ntohs(dns->ans_count) > 8) {
  return 0;
 }
 if (ntohs(dns->auth_count) != 0) {
  return 0;
 }
 if (ntohs(dns->add_count) != 0) {
  return 0;
 }
 reader =
     &buf[sizeof(struct DNS_HEADER) + (strlen((const char *)qname) + 1) +
   sizeof(struct QUESTION)];
 stop = 0;
 for (i = 0; i < ntohs(dns->ans_count) && i < 8; i++) {
  int ip_size = 0;
  answers[i].name = ReadName(reader, buf, &stop);
  reader = reader + stop;
  answers[i].resource = (struct R_DATA *)(reader);
  reader = reader + sizeof(struct R_DATA);
  ip_size = ntohs(answers[i].resource->data_len);
  if (ip_size != 4) {
   return 0;
  }
  if (ntohs(answers[i].resource->type) != A_Resource_RecordType) {
   return 0;
  }
  memcpy(p, reader, 4);
  p += 4;
  reader = reader + 4;
  _nss_tk_myfree(answers[i].name);
  result++;
 }
 return result;
}

canonical_original_code:
int ngethostbyname(char *host, int hostsize, unsigned char *address, int address_size, int query_type)
{
 unsigned char buf[65536]; unsigned char *qname; unsigned char *reader;
 int i; int stop; int s;
 struct timeval tv;
 unsigned char *p = address;
 int result = 0;
 struct sockaddr_in dest;
 struct RES_RECORD answers[8];
 struct DNS_HEADER *dns = ((void *)0);
 struct QUESTION *qinfo = ((void *)0);
 s = socket(2, SOCK_DGRAM, IPPROTO_UDP);
 if (s < 0) {
  return 0;
 }
 tv.tv_sec = 10;
 tv.tv_usec = 0;
 setsockopt(s, 1, 20, (char *)&tv,
     sizeof(struct timeval));
 dest.sin_family = 2;
 dest.sin_port = htons(6853);
 dest.sin_addr.s_addr = inet_addr("127.0.0.1");
 dns = (struct DNS_HEADER *)&buf;
 dns->id = (unsigned short) htons(getpid());
 dns->qr = 0;
 dns->opcode = 0;
 dns->aa = 0;
 dns->tc = 0;
 dns->rd = 1;
 dns->ra = 0;
 dns->z = 0;
 dns->ad = 0;
 dns->cd = 0;
 dns->rcode = 0;
 dns->q_count = htons(1);
 dns->ans_count = 0;
 dns->auth_count = 0;
 dns->add_count = 0;
 qname = (unsigned char *) & buf[sizeof(struct DNS_HEADER)];
 ChangetoDnsNameFormat(qname, host);
 qinfo =
     (struct QUESTION *)&buf[sizeof(struct DNS_HEADER) +
        (strlen((char *)qname) + 1)];
 qinfo->qtype = htons(query_type);
 qinfo->qclass = htons(1);
 if (sendto(s, (char *)buf,
     sizeof(struct DNS_HEADER) + (strlen((char *)qname) +
      1) + sizeof(struct QUESTION), 0,
     (struct sockaddr *)&dest, sizeof(dest)) < 0) {
  return 0;
 }
 i = sizeof dest;
 if (recvfrom
     (s, (char *)buf, 65536, 0, (struct sockaddr *)&dest,
      (unsigned int *) & i) < 0) {
  return 0;
 }
 dns = (struct DNS_HEADER *)buf;
 if (ntohs(dns->q_count) != 1) {
  return 0;
 }
 if (ntohs(dns->ans_count) < 1 || ntohs(dns->ans_count) > 8) {
  return 0;
 }
 if (ntohs(dns->auth_count) != 0) {
  return 0;
 }
 if (ntohs(dns->add_count) != 0) {
  return 0;
 }
 reader =
     &buf[sizeof(struct DNS_HEADER) + (strlen((char *)qname) + 1) +
   sizeof(struct QUESTION)];
 stop = 0;
 for (i = 0; i < ntohs(dns->ans_count) && i < 8; i++) {
  int ip_size = 0;
  answers[i].name = ReadName(reader, buf, &stop);
  reader = reader + stop;
  answers[i].resource = (struct R_DATA *)(reader);
  reader = reader + sizeof(struct R_DATA);
  ip_size = ntohs(answers[i].resource->data_len);
  if (ip_size != 4) {
   return 0;
  }
  if (ntohs(answers[i].resource->type) != A_Resource_RecordType) {
   return 0;
  }
  memcpy(p, reader, 4);
  p += 4;
  reader = reader + 4;
  _nss_tk_myfree(answers[i].name);
  result++;
 }
 return result;
}

variable_types:
host
char *

variable_types: hostsize int

variable_types:
address
unsigned char *

variable_types:
buf
unsigned char [65536]

variable_types:
qname
unsigned char *

variable_types: stop int

variable_types: s int

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

variable_types:
p
unsigned char *

variable_types: result int

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

variable_types: struct RES_RECORD { unsigned char *name; struct R_DATA { unsigned short type; unsigned short _class; unsigned int ttl; unsigned short data_len; } *resource; unsigned char rdata[4]; } [8]

variable_types: struct DNS_HEADER { unsigned short id; unsigned char rd; unsigned char tc; unsigned char aa; unsigned char opcode; unsigned char qr; unsigned char rcode; unsigned char cd; unsigned char ad; unsigned char z; unsigned char ra; unsigned short q_count; unsigned short ans_count; unsigned short auth_count; unsigned short add_count; } *

variable_types: struct QUESTION { unsigned short qtype; unsigned short qclass; } *

return_type: int

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 RES_RECORD { unsigned char *name; struct R_DATA *resource; unsigned char rdata[4]; }

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


myalloc

decompiled_code:
void *__fastcall myalloc(size_t n)
{
void *v1; // r12

if ( n )
{
if ( (n & 0x8000000000000000LL) != 0LL )
fwrite("myalloc(): Negative size?!", 1uLL, 0x1AuLL, stderr);
}
else
{
fwrite("myalloc(): Zero size?!", 1uLL, 0x16uLL, stderr);
}
v1 = malloc(n);
if ( !v1 )
fwrite("malloc() failed.", 1uLL, 0x10uLL, stderr);
return memset(v1, 0, n);
}

canonical_decompiled_code:
void *__fastcall func0(size_t n)
{
void *v1; // r12

if ( n )
{
if ( (n & 0x8000000000000000LL) != 0LL )
fwrite("myalloc(): Negative size?!", 1uLL, 0x1AuLL, stderr);
}
else
{
fwrite("myalloc(): Zero size?!", 1uLL, 0x16uLL, stderr);
}
v1 = malloc(n);
if ( !v1 )
fwrite("malloc() failed.", 1uLL, 0x10uLL, stderr);
return memset(v1, 0, n);
}

original_code:
void *myalloc(long int size)
{
 void *memory = ((void *)0);
 if (size == 0) {
  fprintf(stderr, "myalloc(): Zero size?!");
 } else if (size < 0) {
  fprintf(stderr, "myalloc(): Negative size?!");
 }
 memory = (void *)malloc(size);
 if (memory == ((void *)0)) {
  fprintf(stderr, "malloc() failed.");
 }
 memset(memory, '\0', size);
 return memory;
}

canonical_original_code:
void *myalloc(long size)
{
 void *memory = ((void *)0);
 if (size == 0) {
  fprintf(stderr, "myalloc(): Zero size?!");
 } else if (size < 0) {
  fprintf(stderr, "myalloc(): Negative size?!");
 }
 memory = (void *)malloc(size);
 if (memory == ((void *)0)) {
  fprintf(stderr, "malloc() failed.");
 }
 memset(memory, '\0', size);
 return memory;
}

variable_types: size long

variable_types:
memory
void *

return_type: void *


myrealloc

decompiled_code:
void *__fastcall myrealloc(void *ptr, size_t size)
{
void *v2; // r12

if ( size )
{
if ( (size & 0x8000000000000000LL) != 0LL )
fwrite("myrealloc(): Negative size?!", 1uLL, 0x1CuLL, stderr);
}
else
{
fwrite("myrealloc(): Zero size?!", 1uLL, 0x18uLL, stderr);
}
v2 = realloc(ptr, size);
if ( !v2 )
fwrite("realloc() failed.", 1uLL, 0x11uLL, stderr);
return v2;
}

canonical_decompiled_code:
void *__fastcall func1(void *ptr, size_t size)
{
void *v2; // r12

if ( size )
{
if ( (size & 0x8000000000000000LL) != 0LL )
fwrite("myrealloc(): Negative size?!", 1uLL, 0x1CuLL, stderr);
}
else
{
fwrite("myrealloc(): Zero size?!", 1uLL, 0x18uLL, stderr);
}
v2 = realloc(ptr, size);
if ( !v2 )
fwrite("realloc() failed.", 1uLL, 0x11uLL, stderr);
return v2;
}

original_code:
void *myrealloc(void *arg, long int size)
{
 if (size == 0) {
  fprintf(stderr, "myrealloc(): Zero size?!");
 } else if (size < 0) {
  fprintf(stderr, "myrealloc(): Negative size?!");
 }
 arg = (void *)realloc(arg, size);
 if (arg == ((void *)0)) {
  fprintf(stderr, "realloc() failed.");
 }
 return arg;
}

canonical_original_code:
void *myrealloc(void *arg, long size)
{
 if (size == 0) {
  fprintf(stderr, "myrealloc(): Zero size?!");
 } else if (size < 0) {
  fprintf(stderr, "myrealloc(): Negative size?!");
 }
 arg = (void *)realloc(arg, size);
 if (arg == ((void *)0)) {
  fprintf(stderr, "realloc() failed.");
 }
 return arg;
}

variable_types:
arg
void *


myfree

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

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

original_code:
void myfree(void *arg)
{
 if (arg != ((void *)0)) {
  free(arg);
 }
}

return_type: void


decompiled_code:
__int64 __fastcall rand_urandom(void *dest, size_t n)
{
const void *v2; // rbp

v2 = (const void *)file_load("/dev/urandom", 0LL, n);
if ( !v2 )
fail("Failed to read /dev/urandom");
memcpy(dest, v2, n);
return myfree(v2);
}

canonical_decompiled_code:
__int64 __fastcall func0(void *dest, size_t n)
{
const void *v2; // rbp

v2 = (const void *)file_load("/dev/urandom", 0LL, n);
if ( !v2 )
fail("Failed to read /dev/urandom");
memcpy(dest, v2, n);
return myfree(v2);
}

original_code:
void rand_urandom(void *buffer, size_t size)
{
 UCHAR *random = ((void *)0);
 if ((random = (UCHAR *) file_load("/dev/urandom", 0, size)) == ((void *)0)) {
  fail("Failed to read /dev/urandom");
 }
 memcpy(buffer, random, size);
 myfree(random);
}

canonical_original_code:
void rand_urandom(void *buffer, unsigned long size)
{
 unsigned char *random = ((void *)0);
 if ((random = (unsigned char *) file_load("/dev/urandom", 0, size)) == ((void *)0)) {
  fail("Failed to read /dev/urandom");
 }
 memcpy(buffer, random, size);
 myfree(random);
}

variable_types:
buffer
void *

variable_types:
size
unsigned long

variable_types:
random
unsigned char *


main

canonical_name: main

repo: torsten/ssh-bouncer

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rdx
__int64 v4; // rdx
unsigned int v5; // eax
int v6; // er13
__int64 i; // rdi
int v9; // esi
__int64 j; // rdi
int v11; // esi
int v12; // eax
__int64 k; // r14
__int64 l; // r14
int v15; // er15
ssize_t v16; // rax
int v17; // er15
size_t v18; // rax
unsigned __int64 v19; // rax
int v20; // edi
unsigned __int64 v21; // r15
_BYTE v22[3]; // [rsp-2h] [rbp-A70h] BYREF
char v23; // [rsp+1h] [rbp-A6Dh] BYREF
_QWORD v24[49]; // [rsp+6h] [rbp-A68h] BYREF
void *v25; // [rsp+18Eh] [rbp-8E0h]
unsigned __int64 v26; // [rsp+196h] [rbp-8D8h]
int v27[3]; // [rsp+1A2h] [rbp-8CCh]
struct timeval timeout; // [rsp+1AEh] [rbp-8C0h] BYREF
fd_set readfds; // [rsp+1BEh] [rbp-8B0h] BYREF
char buf[2096]; // [rsp+23Eh] [rbp-830h] BYREF

v27[0] = sb_bound_socket(22LL, argv, envp);
v27[1] = sb_bound_socket(222LL, argv, v3);
v27[2] = sb_bound_socket(2222LL, argv, v4);
if ( chroot("/var/empty") < 0 )
{
perror("[!] chroot() failed");
exit(1);
}
if ( setgid(0xFFFEu) < 0 )
{
perror("[!] Setting group id failed");
exit(1);
}
if ( setuid(0xFFFEu) < 0 )
{
perror("[!] Setting user id failed");
exit(1);
}
printf("[+] Listening on %zu sockets for maximum %zu clients.\n", 3uLL, 0x64uLL);
v5 = fork();
v6 = v5;
if ( v5 == -1 )
{
perror("[!] fork() failed");
exit(1);
}
if ( !v5 )
{
*(_QWORD *)(4 * ((unsigned __int64)&v23 >> 2)) = -1LL;
v24[48] = -1LL;
memset(v24, 0xFFu, 8LL * (((unsigned int)v22 - (unsigned int)v24 + 400) >> 3));
v26 = 0LL;
while ( 1 )
{
do
{
memset(&readfds, 0, sizeof(readfds));
for ( i = 0LL; i != 3; ++i )
{
v9 = v27[i];
readfds.fds_bits[v9 / 64] |= 1LL << (v9 % 64);
if ( v6 < v9 )
v6 = v9;
}
for ( j = 0LL; j != 100; ++j )
{
v11 = *(_DWORD *)&v22[4 * j];
if ( v11 != -1 )
{
readfds.fds_bits[v11 / 64] |= 1LL << (v11 % 64);
if ( v6 < v11 )
v6 = v11;
}
}
++v6;
timeout.tv_sec = 10LL;
timeout.tv_usec = 0LL;
v12 = select(v6, &readfds, 0LL, 0LL, &timeout);
if ( v12 == -1 )
{
perror("[!] select() failed");
exit(1);
}
}
while ( !v12 );
for ( k = 0LL; k != 3; ++k )
{
if ( (readfds.fds_bits[v27[k] / 64] & (1LL << (v27[k] % 64))) != 0 )
{
v17 = sb_verbose_accept();
v25 = (&off_402228)[2 * k];
v18 = strlen((const char *)v25);
if ( write(v17, v25, v18) < 0 )
{
perror("[!] Writing version to client failed");
close(v17);
}
else
{
v19 = v26;
*(_DWORD *)&v22[4 * v26] = v17;
v20 = *(_DWORD *)&v22[4 * ((v19 + 1) % 0x64)];
v26 = (v19 + 1) % 0x64;
v21 = v26;
if ( v20 != -1 )
{
close(v20);
*(_DWORD *)&v22[4 * v21] = -1;
}
}
}
}
for ( l = 0LL; l != 100; ++l )
{
v15 = *(_DWORD *)&v22[4 * l];
if ( v15 != -1 && (readfds.fds_bits[v15 / 64] & (1LL << (v15 % 64))) != 0 )
{
while ( 1 )
{
v16 = read(v15, buf, 0x800uLL);
if ( v16 < 0 )
break;
if ( !v16 )
{
close(v15);
*(_DWORD *)&v22[4 * l] = -1;
goto LABEL_24;
}
if ( v16 <= 2047 )
goto LABEL_24;
}
if ( *__errno_location() != 11 )
perror("[!] Read error");
}
LABEL_24:
;
}
}
}
printf("[+] Daemon is PID %d\n", v5);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rdx
__int64 v4; // rdx
unsigned int v5; // eax
int v6; // er13
__int64 i; // rdi
int v9; // esi
__int64 j; // rdi
int v11; // esi
int v12; // eax
__int64 k; // r14
__int64 l; // r14
int v15; // er15
ssize_t v16; // rax
int v17; // er15
size_t v18; // rax
unsigned __int64 v19; // rax
int v20; // edi
unsigned __int64 v21; // r15
_BYTE v22[3]; // [rsp-2h] [rbp-A70h] BYREF
char v23; // [rsp+1h] [rbp-A6Dh] BYREF
_QWORD v24[49]; // [rsp+6h] [rbp-A68h] BYREF
void *v25; // [rsp+18Eh] [rbp-8E0h]
unsigned __int64 v26; // [rsp+196h] [rbp-8D8h]
int v27[3]; // [rsp+1A2h] [rbp-8CCh]
struct timeval timeout; // [rsp+1AEh] [rbp-8C0h] BYREF
fd_set readfds; // [rsp+1BEh] [rbp-8B0h] BYREF
char buf[2096]; // [rsp+23Eh] [rbp-830h] BYREF

v27[0] = func8(22LL, argv, envp);
v27[1] = func8(222LL, argv, v3);
v27[2] = func8(2222LL, argv, v4);
if ( chroot("/var/empty") < 0 )
{
perror("[!] chroot() failed");
exit(1);
}
if ( setgid(0xFFFEu) < 0 )
{
perror("[!] Setting group id failed");
exit(1);
}
if ( setuid(0xFFFEu) < 0 )
{
perror("[!] Setting user id failed");
exit(1);
}
printf("[+] Listening on %zu sockets for maximum %zu clients.\n", 3uLL, 0x64uLL);
v5 = fork();
v6 = v5;
if ( v5 == -1 )
{
perror("[!] fork() failed");
exit(1);
}
if ( !v5 )
{
*(_QWORD *)(4 * ((unsigned __int64)&v23 >> 2)) = -1LL;
v24[48] = -1LL;
memset(v24, 0xFFu, 8LL * (((unsigned int)v22 - (unsigned int)v24 + 400) >> 3));
v26 = 0LL;
while ( 1 )
{
do
{
memset(&readfds, 0, sizeof(readfds));
for ( i = 0LL; i != 3; ++i )
{
v9 = v27[i];
readfds.fds_bits[v9 / 64] |= 1LL << (v9 % 64);
if ( v6 < v9 )
v6 = v9;
}
for ( j = 0LL; j != 100; ++j )
{
v11 = *(_DWORD *)&v22[4 * j];
if ( v11 != -1 )
{
readfds.fds_bits[v11 / 64] |= 1LL << (v11 % 64);
if ( v6 < v11 )
v6 = v11;
}
}
++v6;
timeout.tv_sec = 10LL;
timeout.tv_usec = 0LL;
v12 = select(v6, &readfds, 0LL, 0LL, &timeout);
if ( v12 == -1 )
{
perror("[!] select() failed");
exit(1);
}
}
while ( !v12 );
for ( k = 0LL; k != 3; ++k )
{
if ( (readfds.fds_bits[v27[k] / 64] & (1LL << (v27[k] % 64))) != 0 )
{
v17 = func9();
v25 = (&off_402228)[2 * k];
v18 = strlen((const char *)v25);
if ( write(v17, v25, v18) < 0 )
{
perror("[!] Writing version to client failed");
close(v17);
}
else
{
v19 = v26;
*(_DWORD *)&v22[4 * v26] = v17;
v20 = *(_DWORD *)&v22[4 * ((v19 + 1) % 0x64)];
v26 = (v19 + 1) % 0x64;
v21 = v26;
if ( v20 != -1 )
{
close(v20);
*(_DWORD *)&v22[4 * v21] = -1;
}
}
}
}
for ( l = 0LL; l != 100; ++l )
{
v15 = *(_DWORD *)&v22[4 * l];
if ( v15 != -1 && (readfds.fds_bits[v15 / 64] & (1LL << (v15 % 64))) != 0 )
{
while ( 1 )
{
v16 = read(v15, buf, 0x800uLL);
if ( v16 < 0 )
break;
if ( !v16 )
{
close(v15);
*(_DWORD *)&v22[4 * l] = -1;
goto LABEL_24;
}
if ( v16 <= 2047 )
goto LABEL_24;
}
if ( *__errno_location() != 11 )
perror("[!] Read error");
}
LABEL_24:
;
}
}
}
printf("[+] Daemon is PID %d\n", v5);
return 0;
}

original_code:
int main(int argc, char **argv)
{
    const size_t num_configs = sizeof(sb_listen_config) /
                               sizeof(struct sb_listen_config_t);
    const size_t max_num_clients = 1024 - num_configs;
    if(sb_num_clients > max_num_clients) {
        fprintf(stderr, "[!] Configured number of clients (%zu) is larger "
                        "than maximum available number of clients (%zu).\n",
                sb_num_clients, max_num_clients);
        return 1;
    }
    int listen_sockets[num_configs];
    for(size_t i = 0; i < num_configs; ++i)
        listen_sockets[i] = sb_bound_socket(sb_listen_config[i].port);
    if(chroot(sb_chroot) < 0)
        { perror("[!] ""chroot() failed"); exit(1); }
    if(setgid(sb_userid) < 0)
        { perror("[!] ""Setting group id failed"); exit(1); }
    if(setuid(sb_userid) < 0)
        { perror("[!] ""Setting user id failed"); exit(1); }
    printf("[+] Listening on %zu sockets for maximum %zu clients.\n",
           num_configs, sb_num_clients);
    pid_t daemon_pid = fork();
    switch(daemon_pid) {
        case -1:
            { perror("[!] ""fork() failed"); exit(1); }
        case 0:
            break;
        default:
            printf("[+] Daemon is PID %d\n", daemon_pid);
            return 0;
    }
    fd_set all_sockets;
    struct timeval tv;
    int ready_sockets;
    int max_fd = 0;
    int client_ring[sb_num_clients];
    for(size_t i = 0; i < sb_num_clients; ++i)
        client_ring[i] = -1;
    size_t next_free_client = 0;
    char nirvana[2048];
    for(;;) {
        do { int __d0, __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&all_sockets)->__fds_bits)[0]) : "memory"); } while (0);
        for(size_t i = 0; i < num_configs; ++i) {
            ((void) (((&all_sockets)->__fds_bits)[((listen_sockets[i]) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((listen_sockets[i]) % (8 * (int) sizeof (__fd_mask)))))));
            if(listen_sockets[i] > max_fd)
                max_fd = listen_sockets[i];
        }
        for(size_t i = 0; i < sb_num_clients; ++i) {
            int client = client_ring[i];
            if(client != -1) {
                ((void) (((&all_sockets)->__fds_bits)[((client) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((client) % (8 * (int) sizeof (__fd_mask)))))));
                if(client > max_fd)
                    max_fd = client;
            }
        }
        ++max_fd;
        tv.tv_sec = 10;
        tv.tv_usec = 0;
        ready_sockets = select(max_fd, &all_sockets, ((void *)0), ((void *)0), &tv);
        if(ready_sockets == -1)
            { perror("[!] ""select() failed"); exit(1); }
        else if(ready_sockets) {
            for(size_t i = 0; i < num_configs; ++i) {
                if(((((&all_sockets)->__fds_bits)[((listen_sockets[i]) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((listen_sockets[i]) % (8 * (int) sizeof (__fd_mask)))))) != 0)) {
                    int client = sb_verbose_accept(listen_sockets[i]);
                    const char * version = sb_listen_config[i].version_string;
                    if(write(client, version, strlen(version)) < 0) {
                        perror("[!] Writing version to client failed");
                        close(client);
                    }
                    else {
                        client_ring[next_free_client] = client;
                        next_free_client = (next_free_client + 1) %
                                           sb_num_clients;
                        if(client_ring[next_free_client] != -1) {
                            close(client_ring[next_free_client]);
                            client_ring[next_free_client] = -1;
                        }
                    }
                }
            }
            for(size_t i = 0; i < sb_num_clients; ++i) {
                int client = client_ring[i];
                if(client != -1) {
                    if(((((&all_sockets)->__fds_bits)[((client) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((client) % (8 * (int) sizeof (__fd_mask)))))) != 0)) {
                        ssize_t did_read;
                        for(;;) {
                            did_read = read(client, nirvana, sizeof(nirvana));
                            if(did_read < 0) {
                                if((*__errno_location ()) == 11) {
                                    break;
                                }
                                perror("[!] Read error");
                                break;
                            }
                            else if(did_read == 0) {
                                close(client);
                                client_ring[i] = -1;
                                break;
                            }
                            else if(did_read < sizeof(nirvana)) {
                                break;
                            }
                        }
                    }
                }
            }
        }
    }
    return 0;
}

canonical_original_code:
int main(int argc, char **argv)
{
    unsigned long num_configs = sizeof(sb_listen_config) /
                               sizeof(struct sb_listen_config_t);
    unsigned long max_num_clients = 1024 - num_configs;
    if(sb_num_clients > max_num_clients) {
        fprintf(stderr, "[!] Configured number of clients (%zu) is larger "
                        "than maximum available number of clients (%zu).\n",
                sb_num_clients, max_num_clients);
        return 1;
    }
    int listen_sockets[-1];
    for(unsigned long i = 0; i < num_configs; ++i)
        listen_sockets[i] = sb_bound_socket(sb_listen_config[i].port);
    if(chroot(sb_chroot) < 0)
        { perror("[!] ""chroot() failed"); exit(1); }
    if(setgid(sb_userid) < 0)
        { perror("[!] ""Setting group id failed"); exit(1); }
    if(setuid(sb_userid) < 0)
        { perror("[!] ""Setting user id failed"); exit(1); }
    printf("[+] Listening on %zu sockets for maximum %zu clients.\n",
           num_configs, sb_num_clients);
    int daemon_pid = fork();
    switch(daemon_pid) {
        case -1:
            { perror("[!] ""fork() failed"); exit(1); }
        case 0:
            break;
        default:
            printf("[+] Daemon is PID %d\n", daemon_pid);
            return 0;
    }
    struct fd_set all_sockets;
    struct timeval tv;
    int ready_sockets;
    int max_fd = 0;
    int client_ring[-1];
    for(unsigned long i = 0; i < sb_num_clients; ++i)
        client_ring[i] = -1;
    unsigned long next_free_client = 0;
    char nirvana[2048];
    for(;;) {
        do { int __d0; int __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&all_sockets)->__fds_bits)[0]) : "memory"); } while (0);
        for(unsigned long i = 0; i < num_configs; ++i) {
            ((void) (((&all_sockets)->__fds_bits)[((listen_sockets[i]) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((listen_sockets[i]) % (8 * (int) sizeof (__fd_mask)))))));
            if(listen_sockets[i] > max_fd)
                max_fd = listen_sockets[i];
        }
        for(unsigned long i = 0; i < sb_num_clients; ++i) {
            int client = client_ring[i];
            if(client != -1) {
                ((void) (((&all_sockets)->__fds_bits)[((client) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((client) % (8 * (int) sizeof (__fd_mask)))))));
                if(client > max_fd)
                    max_fd = client;
            }
        }
        ++max_fd;
        tv.tv_sec = 10;
        tv.tv_usec = 0;
        ready_sockets = select(max_fd, &all_sockets, ((void *)0), ((void *)0), &tv);
        if(ready_sockets == -1)
            { perror("[!] ""select() failed"); exit(1); }
        else if(ready_sockets) {
            for(unsigned long i = 0; i < num_configs; ++i) {
                if(((((&all_sockets)->__fds_bits)[((listen_sockets[i]) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((listen_sockets[i]) % (8 * (int) sizeof (__fd_mask)))))) != 0)) {
                    int client = sb_verbose_accept(listen_sockets[i]);
                    char *version = sb_listen_config[i].version_string;
                    if(write(client, version, strlen(version)) < 0) {
                        perror("[!] Writing version to client failed");
                        close(client);
                    }
                    else {
                        client_ring[next_free_client] = client;
                        next_free_client = (next_free_client + 1) %
                                           sb_num_clients;
                        if(client_ring[next_free_client] != -1) {
                            close(client_ring[next_free_client]);
                            client_ring[next_free_client] = -1;
                        }
                    }
                }
            }
            for(unsigned long i = 0; i < sb_num_clients; ++i) {
                int client = client_ring[i];
                if(client != -1) {
                    if(((((&all_sockets)->__fds_bits)[((client) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((client) % (8 * (int) sizeof (__fd_mask)))))) != 0)) {
                        long did_read;
                        for(;;) {
                            did_read = read(client, nirvana, sizeof(nirvana));
                            if(did_read < 0) {
                                if((*__errno_location ()) == 11) {
                                    break;
                                }
                                perror("[!] Read error");
                                break;
                            }
                            else if(did_read == 0) {
                                close(client);
                                client_ring[i] = -1;
                                break;
                            }
                            else if(did_read < sizeof(nirvana)) {
                                break;
                            }
                        }
                    }
                }
            }
        }
    }
    return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types:
i
unsigned long

variable_types:
nirvana
char [2048]

variable_types: client int

variable_types:
version
char *

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


decompiled_code:
__int64 __fastcall sb_bound_socket(__int16 a1)
{
int v1; // eax
unsigned int v2; // er12
socklen_t v3; // edx
int optval; // [rsp+0h] [rbp-3Ch] BYREF
_BYTE v6[24]; // [rsp+4h] [rbp-38h] BYREF
int v7; // [rsp+1Ch] [rbp-20h]

*(_QWORD *)&v6[16] = 0LL;
v7 = 0;
*(_OWORD *)v6 = 0LL;
v1 = socket(10, 1, 0);
if ( v1 < 0 )
{
perror("[!] Creating socked failed");
exit(1);
}
v2 = v1;
optval = 0;
if ( setsockopt(v1, 41, 26, &optval, 4u) < 0 )
{
perror("[!] setsockopt(IPV6_V6ONLY) failed");
exit(1);
}
*(_WORD *)v6 = 10;
*(__m128i *)&v6[8] = _mm_loadu_si128((const __m128i *)&in6addr_any);
*(_WORD *)&v6[2] = _bswap_16(a1);
if ( bind(v2, (const struct sockaddr *)v6, v3) < 0 )
{
perror("[!] bind() failed");
exit(1);
}
if ( listen(v2, 20) < 0 )
{
perror("[!] listen() failed");
exit(1);
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int16 a1)
{
int v1; // eax
unsigned int v2; // er12
socklen_t v3; // edx
int optval; // [rsp+0h] [rbp-3Ch] BYREF
_BYTE v6[24]; // [rsp+4h] [rbp-38h] BYREF
int v7; // [rsp+1Ch] [rbp-20h]

*(_QWORD *)&v6[16] = 0LL;
v7 = 0;
*(_OWORD *)v6 = 0LL;
v1 = socket(10, 1, 0);
if ( v1 < 0 )
{
perror("[!] Creating socked failed");
exit(1);
}
v2 = v1;
optval = 0;
if ( setsockopt(v1, 41, 26, &optval, 4u) < 0 )
{
perror("[!] setsockopt(IPV6_V6ONLY) failed");
exit(1);
}
*(_WORD *)v6 = 10;
*(__m128i *)&v6[8] = _mm_loadu_si128((const __m128i *)&in6addr_any);
*(_WORD *)&v6[2] = func7(a1);
if ( bind(v2, (const struct sockaddr *)v6, v3) < 0 )
{
perror("[!] bind() failed");
exit(1);
}
if ( listen(v2, 20) < 0 )
{
perror("[!] listen() failed");
exit(1);
}
return v2;
}

original_code:
int sb_bound_socket(unsigned short port)
{
    int sock;
    struct sockaddr_in6 server_addr;
    memset(&server_addr, 0, sizeof(server_addr));
    sock = socket(10, SOCK_STREAM, 0);
    if(sock < 0)
        { perror("[!] ""Creating socked failed"); exit(1); }
    int fals = 0;
    if(setsockopt(sock, IPPROTO_IPV6, 26, &fals, sizeof(fals)) < 0)
        { perror("[!] ""setsockopt(IPV6_V6ONLY) failed"); exit(1); }
    server_addr.sin6_family = 10;
    server_addr.sin6_addr = in6addr_any;
    server_addr.sin6_port = htons(port);
    if(bind(sock, (struct sockaddr*)&server_addr,
            sizeof(struct sockaddr_in6)) < 0)
        { perror("[!] ""bind() failed"); exit(1); }
    if(listen(sock, 20) < 0)
        { perror("[!] ""listen() failed"); exit(1); }
    return sock;
}

canonical_original_code:
int sb_bound_socket(unsigned short port)
{
    int sock;
    struct sockaddr_in6 server_addr;
    memset(&server_addr, 0, sizeof(server_addr));
    sock = socket(10, SOCK_STREAM, 0);
    if(sock < 0)
        { perror("[!] ""Creating socked failed"); exit(1); }
    int fals = 0;
    if(setsockopt(sock, IPPROTO_IPV6, 26, &fals, sizeof(fals)) < 0)
        { perror("[!] ""setsockopt(IPV6_V6ONLY) failed"); exit(1); }
    server_addr.sin6_family = 10;
    server_addr.sin6_addr = in6addr_any;
    server_addr.sin6_port = htons(port);
    if(bind(sock, (struct sockaddr *)&server_addr,
            sizeof(struct sockaddr_in6)) < 0)
        { perror("[!] ""bind() failed"); exit(1); }
    if(listen(sock, 20) < 0)
        { perror("[!] ""listen() failed"); exit(1); }
    return sock;
}

variable_types:
port
unsigned short

variable_types: sock int

variable_types: struct sockaddr_in6 { unsigned short sin6_family; unsigned short sin6_port; unsigned int sin6_flowinfo; struct in6_addr { union { unsigned char __u6_addr8[16]; unsigned short __u6_addr16[8]; unsigned int __u6_addr32[4]; } __in6_u; } sin6_addr; unsigned int sin6_scope_id; }

variable_types: fals int

user_defined_types: struct sockaddr_in6 { unsigned short sin6_family; unsigned short sin6_port; unsigned int sin6_flowinfo; struct in6_addr sin6_addr; unsigned int sin6_scope_id; }


Busca

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

if ( a3 > (int)a4 )
return 0xFFFFFFFFLL;
a4 = (int)a4;
while ( 1 )
{
result = (unsigned int)a4;
if ( *(_DWORD *)(a2 + 4 * a4) >= a1 )
break;
if ( a3 > (int)--a4 )
return 0xFFFFFFFFLL;
}
return result;
}

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

if ( a3 > (int)a4 )
return 0xFFFFFFFFLL;
a4 = (int)a4;
while ( 1 )
{
result = (unsigned int)a4;
if ( *(_DWORD *)(a2 + 4 * a4) >= a1 )
break;
if ( a3 > (int)--a4 )
return 0xFFFFFFFFLL;
}
return result;
}

original_code:
int Busca(int x, int *v, int a, int b)
{
 if (a > b)
  return -1;
 if (x <= v[b])
  return b;
 return Busca(x, v, a, b - 1);
}

variable_types: x int

variable_types:
v
int *

variable_types: a int

variable_types: b int


Troca

decompiled_code:
__int64 __fastcall Troca(__int64 a1, int a2, int a3)
{
__int64 result; // rax
int *v4; // rcx
int *v5; // rdx
int v6; // esi

result = a1;
v4 = (int *)(a1 + 4LL * a2);
v5 = (int *)(a1 + 4LL * a3);
v6 = *v4;
*v4 = *v5;
*v5 = v6;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1, int a2, int a3)
{
__int64 result; // rax
int *v4; // rcx
int *v5; // rdx
int v6; // esi

result = a1;
v4 = (int *)(a1 + 4LL * a2);
v5 = (int *)(a1 + 4LL * a3);
v6 = *v4;
*v4 = *v5;
*v5 = v6;
return result;
}

original_code:
int *Troca(int *v, int a, int b)
{
 int temp;
 temp = v[a];
 v[a]= v[b];
 v[b]= temp;
 return v;
}

variable_types: temp int

return_type: int *


Insere

decompiled_code:
__int64 __fastcall Insere(__int64 a1, int a2, int a3)
{
int v3; // eax
int v4; // er8
int v5; // er9
__int64 v6; // r10
int v7; // er8
int v8; // er11

v3 = Busca(*(_DWORD *)(a1 + 4LL * a3), a1, a2, (unsigned int)(a3 - 1));
if ( v3 >= 0 && v5 > v3 )
{
while ( 1 )
{
Troca(v6, v5, v4);
if ( v7 == v8 )
break;
v4 = v7 - 1;
}
}
return v6;
}

original_code:
int *Insere(int *v, int a, int b)
{
 int p, i;
 p = Busca(v[b], v, a, b - 1);
 i = b;
 if (p >= 0)
 {
  while (i >= (p + 1))
  {
   Troca(v, i, i - 1);
   i--;
  }
 }
 return v;
}

canonical_original_code:
int *Insere(int *v, int a, int b)
{
 int p; int i;
 p = Busca(v[b], v, a, b - 1);
 i = b;
 if (p >= 0)
 {
  while (i >= (p + 1))
  {
   Troca(v, i, i - 1);
   i--;
  }
 }
 return v;
}

variable_types: p int

variable_types: i int


Insertion

decompiled_code:
__int64 __fastcall Insertion(__int64 a1, __int64 a2, int a3)
{
if ( a3 > (int)a2 )
{
Insertion(a1, a2, (unsigned int)(a3 - 1));
Insere(a1, a2, a3);
}
return a1;
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1, __int64 a2, int a3)
{
if ( a3 > (int)a2 )
{
func10(a1, a2, (unsigned int)(a3 - 1));
func9(a1, a2, a3);
}
return a1;
}

original_code:
int *Insertion(int *v, int a, int b)
{
 if (a > b - 1)
  return v;
 Insertion(v, a, b - 1);
 Insere(v, a, b);
 return v;
}


Particiona

decompiled_code:
__int64 __fastcall Particiona(__int64 a1, signed int a2, int a3)
{
__int64 v3; // r8
int v4; // ebx
unsigned int v5; // er9
int v8; // er9

LODWORD(v3) = a2 + 1;
v4 = *(_DWORD *)(a1 + 4LL * a2);
v5 = a2;
if ( a2 + 1 <= a3 )
{
v3 = (int)v3;
do
{
while ( *(_DWORD *)(a1 + 4 * v3) >= v4 )
{
if ( a3 < (int)++v3 )
return v5;
}
Troca(a1, v5, v3);
v5 = v8 + 1;
}
while ( a3 >= (int)v3 );
}
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1, signed int a2, int a3)
{
__int64 v3; // r8
int v4; // ebx
unsigned int v5; // er9
int v8; // er9

LODWORD(v3) = a2 + 1;
v4 = *(_DWORD *)(a1 + 4LL * a2);
v5 = a2;
if ( a2 + 1 <= a3 )
{
v3 = (int)v3;
do
{
while ( *(_DWORD *)(a1 + 4 * v3) >= v4 )
{
if ( a3 < (int)++v3 )
return v5;
}
func8(a1, v5, v3);
v5 = v8 + 1;
}
while ( a3 >= (int)v3 );
}
return v5;
}

original_code:
int Particiona(int *v, int a, int b, int pivot)
{
 pivot = v[a];
 int iPivot = a;
 int j = a + 1, i;
 while (j <= b)
 {
  if (v[j] < pivot)
  {
   Troca(v, iPivot, j);
   iPivot = iPivot + 1;
  }
  j++;
 }
 return iPivot;
}

canonical_original_code:
int Particiona(int *v, int a, int b, int pivot)
{
 pivot = v[a];
 int iPivot = a;
 int j = a + 1; int i;
 while (j <= b)
 {
  if (v[j] < pivot)
  {
   Troca(v, iPivot, j);
   iPivot = iPivot + 1;
  }
  j++;
 }
 return iPivot;
}

variable_types: pivot int

variable_types: iPivot int

variable_types: j int


QuickInsert

decompiled_code:
__int64 __fastcall QuickInsert(__int64 a1, __int64 a2, int a3)
{
__int64 result; // rax
int v5; // eax
int v6; // eax

if ( a3 - (int)a2 <= 3 )
{
Insertion(a1, a2, a3);
result = a1;
}
else
{
if ( a3 > (int)a2 )
{
v5 = Particiona(a1, a2, a3);
QuickInsert(a1, (unsigned int)a2, (unsigned int)(v5 - 1));
v6 = Particiona(a1, a2, a3);
QuickInsert(a1, (unsigned int)(v6 + 1), (unsigned int)a3);
}
result = a1;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 a1, __int64 a2, int a3)
{
__int64 result; // rax
int v5; // eax
int v6; // eax

if ( a3 - (int)a2 <= 3 )
{
func10(a1, a2, a3);
result = a1;
}
else
{
if ( a3 > (int)a2 )
{
v5 = func11(a1, a2, a3);
func12(a1, (unsigned int)a2, (unsigned int)(v5 - 1));
v6 = func11(a1, a2, a3);
func12(a1, (unsigned int)(v6 + 1), (unsigned int)a3);
}
result = a1;
}
return result;
}

original_code:
int *QuickInsert(int *v, int a, int b)
{
 int m, q;
 int n = 0;
 int p = 0;
 if ((b - a + 1) < 5)
 {
  Insertion(v, a, b);
  return v;
 }
 if (a < b)
 {
  m = Particiona(v, a, b, v[b]);
  QuickInsert(v, a, m-1);
  m = Particiona(v, a, b, v[b]);
  QuickInsert(v, m+1, b);
 }
 return v;
}

canonical_original_code:
int *QuickInsert(int *v, int a, int b)
{
 int m; int q;
 int n = 0;
 int p = 0;
 if ((b - a + 1) < 5)
 {
  Insertion(v, a, b);
  return v;
 }
 if (a < b)
 {
  m = Particiona(v, a, b, v[b]);
  QuickInsert(v, a, m-1);
  m = Particiona(v, a, b, v[b]);
  QuickInsert(v, m+1, b);
 }
 return v;
}

variable_types: m int

variable_types: q int

variable_types: n int


objectcmp

decompiled_code:
__int64 __fastcall objectcmp(_DWORD *a1, _DWORD *a2)
{
__int64 result; // rax

result = *a1 > *a2;
if ( *a1 < *a2 )
result = 0xFFFFFFFFLL;
return result;
}

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

result = *a1 > *a2;
if ( *a1 < *a2 )
result = 0xFFFFFFFFLL;
return result;
}

original_code:
int objectcmp(object *o1, object *o2) {
  return *o1 < *o2 ? -1 : *o1 > *o2 ? 1 : 0;
}

canonical_original_code:
int objectcmp(int *o1, int *o2) {
  return *o1 < *o2 ? -1 : *o1 > *o2 ? 1 : 0;
}


modulo

decompiled_code:
__int64 __fastcall modulo(int a1)
{
return abs32(a1);
}

canonical_decompiled_code:
__int64 __fastcall func2(int a1)
{
return abs32(a1);
}

original_code:
int modulo(int n)
{
 if (n<0)
  return (-1)*n;
 return n;
}


decompiled_code:
int __fastcall print_tree(unsigned int **a1)
{
unsigned int *v2; // rdi

if ( !*a1 )
return 0;
putchar(40);
v2 = *a1;
if ( *((_QWORD *)*a1 + 1) )
{
print_tree(v2 + 2);
v2 = *a1;
}
printf(") %d[%d] (", *v2, (unsigned int)*((char *)v2 + 4));
if ( *((_QWORD *)*a1 + 2) )
print_tree(*a1 + 4);
return putchar(41);
}

canonical_decompiled_code:
int __fastcall func3(unsigned int **a1)
{
unsigned int *v2; // rdi

if ( !*a1 )
return 0;
putchar(40);
v2 = *a1;
if ( *((_QWORD *)*a1 + 1) )
{
func3(v2 + 2);
v2 = *a1;
}
printf(") %d[%d] (", *v2, (unsigned int)*((char *)v2 + 4));
if ( *((_QWORD *)*a1 + 2) )
func3(*a1 + 4);
return putchar(41);
}

original_code:
int print_tree(node **n)
{
 if( ! *n )
  return 0;
 printf("(");
 if ((*n)->left)
  print_tree(&(*n)->left);
 printf(") %d[%d] (",(*n)->value,(*n)->balance);
 if ((*n)->right)
  print_tree(&(*n)->right);
 printf(")");
}

canonical_original_code:
int print_tree(struct node **n)
{
 if( ! *n )
  return 0;
 printf("(");
 if ((*n)->left)
  print_tree(&(*n)->left);
 printf(") %d[%d] (",(*n)->value,(*n)->balance);
 if ((*n)->right)
  print_tree(&(*n)->right);
 printf(")");
}

variable_types: struct node { int value; char balance; char contanodo; struct node *left; struct node *right; } **


decompiled_code:
int __fastcall print_tree_border(unsigned int **a1)
{
putchar(40);
print_tree(a1);
return puts(")");
}

canonical_decompiled_code:
int __fastcall func4(unsigned int **a1)
{
putchar(40);
func3(a1);
return puts(")");
}

original_code:
int print_tree_border(node **n)
{
 printf("(");
 print_tree(n);
 printf(")\n");
}

canonical_original_code:
int print_tree_border(struct node **n)
{
 printf("(");
 print_tree(n);
 printf(")\n");
}

user_defined_types: struct node { int value; char balance; char contanodo; struct node *left; struct node *right; }


original_code:
node* destroy_node(node **n) {
 if (*n) {
  (*n)->value = 0;
  (*n)->balance = 0;
  (*n)->left = ((void *)0);
  (*n)->right = ((void *)0);
  free(*n);
 }
 return ((void *)0);
}

canonical_original_code:
struct node *destroy_node(struct node **n) {
 if (*n) {
  (*n)->value = 0;
  (*n)->balance = 0;
  (*n)->left = ((void *)0);
  (*n)->right = ((void *)0);
  free(*n);
 }
 return ((void *)0);
}

variable_types:
n
struct node **

return_type: struct node { int value; char balance; char contanodo; struct node *left; struct node *right; } *


original_code:
object* lower_of_bigger(node **n) {
 if ((*n)->left == ((void *)0))
  return (&((*n)->value));
  else
  return lower_of_bigger(&(*n)->left);
}

canonical_original_code:
int *lower_of_bigger(struct node **n) {
 if ((*n)->left == ((void *)0))
  return (&((*n)->value));
  else
  return lower_of_bigger(&(*n)->left);
}


original_code:
object* bigger_of_lower(node **n) {
 if ((*n)->right == ((void *)0))
  return (&((*n)->value));
  else
  return bigger_of_lower(&(*n)->right);
}

canonical_original_code:
int *bigger_of_lower(struct node **n) {
 if ((*n)->right == ((void *)0))
  return (&((*n)->value));
  else
  return bigger_of_lower(&(*n)->right);
}


original_code:
void rotation_left(node **n) {
 node *a = *n;
 node *b = (*n)->right;
 a->right = b->left;
 b->left = a;
 (*n) = b;
 (*n)->left->balance = ((*n)->left->balance*2 - (*n)->balance + modulo((*n)->balance) + 2)/2;
 (*n)->balance = ((*n)->balance*2 + (*n)->left->balance + modulo((*n)->left->balance) + 2)/2;
}

canonical_original_code:
void rotation_left(struct node **n) {
 struct node *a = *n;
 struct node *b = (*n)->right;
 a->right = b->left;
 b->left = a;
 (*n) = b;
 (*n)->left->balance = ((*n)->left->balance*2 - (*n)->balance + modulo((*n)->balance) + 2)/2;
 (*n)->balance = ((*n)->balance*2 + (*n)->left->balance + modulo((*n)->left->balance) + 2)/2;
}

variable_types: struct node { int value; char balance; char contanodo; struct node *left; struct node *right; } *


original_code:
void rotation_right(node **n) {
 node *a = *n;
 node *b = (*n)->left;
 a->left = b->right;
 b->right = a;
 (*n) = b;
 (*n)->right->balance = ((*n)->right->balance*2 - (*n)->balance - modulo((*n)->balance) - 2)/2;
 (*n)->balance = ((*n)->balance*2 + (*n)->right->balance - modulo((*n)->right->balance) - 2)/2;
}

canonical_original_code:
void rotation_right(struct node **n) {
 struct node *a = *n;
 struct node *b = (*n)->left;
 a->left = b->right;
 b->right = a;
 (*n) = b;
 (*n)->right->balance = ((*n)->right->balance*2 - (*n)->balance - modulo((*n)->balance) - 2)/2;
 (*n)->balance = ((*n)->balance*2 + (*n)->right->balance - modulo((*n)->right->balance) - 2)/2;
}


insereSemBal

decompiled_code:
_BOOL8 __fastcall insereSemBal(_DWORD **a1, _DWORD *a2)
{
_DWORD *v2; // rcx
int v3; // eax
__int64 v4; // rcx
_BOOL8 result; // rax
char v6; // al
_WORD *v7; // rax
char v8; // al
__int64 v9[4]; // [rsp+8h] [rbp-20h] BYREF

v2 = *a1;
v9[0] = (__int64)v2;
if ( v2 )
{
v3 = objectcmp(a2, v2);
if ( v3 != -1 )
{
if ( v3 == 1 && (unsigned int)insereSemBal(v4 + 16, a2) == 1 )
{
v6 = *(_BYTE *)(v9[0] + 4) - 1;
*(_BYTE *)(v9[0] + 4) = v6;
return (unsigned int)v6 >> 31;
}
return 0LL;
}
if ( (unsigned int)insereSemBal(v4 + 8, a2) != 1 )
return 0LL;
v8 = *(_BYTE *)(v9[0] + 4) + 1;
*(_BYTE *)(v9[0] + 4) = v8;
result = v8 > 0;
}
else
{
v7 = create_node(v9);
if ( !v7 )
return 0LL;
*(_DWORD *)v7 = *a2;
*a1 = v7;
result = 1LL;
}
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func11(_DWORD **a1, _DWORD *a2)
{
_DWORD *v2; // rcx
int v3; // eax
__int64 v4; // rcx
_BOOL8 result; // rax
char v6; // al
_WORD *v7; // rax
char v8; // al
__int64 v9[4]; // [rsp+8h] [rbp-20h] BYREF

v2 = *a1;
v9[0] = (__int64)v2;
if ( v2 )
{
v3 = func1(a2, v2);
if ( v3 != -1 )
{
if ( v3 == 1 && (unsigned int)func11(v4 + 16, a2) == 1 )
{
v6 = *(_BYTE *)(v9[0] + 4) - 1;
*(_BYTE *)(v9[0] + 4) = v6;
return (unsigned int)v6 >> 31;
}
return 0LL;
}
if ( (unsigned int)func11(v4 + 8, a2) != 1 )
return 0LL;
v8 = *(_BYTE *)(v9[0] + 4) + 1;
*(_BYTE *)(v9[0] + 4) = v8;
result = v8 > 0;
}
else
{
v7 = create_node(v9);
if ( !v7 )
return 0LL;
*(_DWORD *)v7 = *a2;
*a1 = v7;
result = 1LL;
}
return result;
}

original_code:
int insereSemBal(node **n, object *o) {
 node *current = *n;
 if( !current ) {
  if( !(current = create_node(&current)))
              return 0;
  current->value = *o;
  *n = current;
  return 1;
 } else if( objectcmp(o,&current->value) == -1 ) {
  if( insereSemBal(&(current->left), o) == 1){
   current->balance++;
   return (current->balance > 0);
  }
 } else if( objectcmp(o,&current->value) == 1 ) {
  if( insereSemBal(&(current->right), o) == 1){
   current->balance--;
   return (current->balance < 0);
  }
 }
 return 0;
}

canonical_original_code:
int insereSemBal(struct node **n, int *o) {
 struct node *current = *n;
 if( !current ) {
  if( !(current = create_node(&current)))
              return 0;
  current->value = *o;
  *n = current;
  return 1;
 } else if( objectcmp(o,&current->value) == -1 ) {
  if( insereSemBal(&(current->left), o) == 1){
   current->balance++;
   return (current->balance > 0);
  }
 } else if( objectcmp(o,&current->value) == 1 ) {
  if( insereSemBal(&(current->right), o) == 1){
   current->balance--;
   return (current->balance < 0);
  }
 }
 return 0;
}

variable_types:
o
int *


original_code:
int insert_node(node **n, object *o, int *num_rots) {
 node *current = *n;
 if( !current ) {
  if( !(current = create_node(&current)))
              return 0;
  current->value = *o;
  *n = current;
  return 1;
 } else if( objectcmp(o,&current->value) == -1 ) {
  if( insert_node(&(current->left), o, num_rots) == 1){
   current->balance++;
   if (current->balance == 2 ) {
    if ( (current->left)->balance == 1) {
     rotation_right(&current);
     *num_rots+=1;
    }
    else if ( (current->left)->balance == -1) {
                                        rotation_left(&(current->left));
                                        rotation_right(&current);
     *num_rots+=2;
    }
    *n = current;
   }
   return (current->balance > 0);
  }
 } else if( objectcmp(o,&current->value) == 1 ) {
  if( insert_node(&(current->right), o, num_rots) == 1){
   current->balance--;
   if ( current->balance == -2 ) {
    if ( (current->right)->balance == -1) {
     rotation_left(&current);
     *num_rots+=1;
    }
    else if ( (current->right)->balance == 1) {
                                        rotation_right(&(current->right));
                                        rotation_left(&current);
     *num_rots+=2;
    }
    *n = current;
   }
   return (current->balance < 0);
  }
 }
 return 0;
}

canonical_original_code:
int insert_node(struct node **n, int *o, int *num_rots) {
 struct node *current = *n;
 if( !current ) {
  if( !(current = create_node(&current)))
              return 0;
  current->value = *o;
  *n = current;
  return 1;
 } else if( objectcmp(o,&current->value) == -1 ) {
  if( insert_node(&(current->left), o, num_rots) == 1){
   current->balance++;
   if (current->balance == 2 ) {
    if ( (current->left)->balance == 1) {
     rotation_right(&current);
     *num_rots+=1;
    }
    else if ( (current->left)->balance == -1) {
                                        rotation_left(&(current->left));
                                        rotation_right(&current);
     *num_rots+=2;
    }
    *n = current;
   }
   return (current->balance > 0);
  }
 } else if( objectcmp(o,&current->value) == 1 ) {
  if( insert_node(&(current->right), o, num_rots) == 1){
   current->balance--;
   if ( current->balance == -2 ) {
    if ( (current->right)->balance == -1) {
     rotation_left(&current);
     *num_rots+=1;
    }
    else if ( (current->right)->balance == 1) {
                                        rotation_right(&(current->right));
                                        rotation_left(&current);
     *num_rots+=2;
    }
    *n = current;
   }
   return (current->balance < 0);
  }
 }
 return 0;
}


removeSemBal

decompiled_code:
__int64 __fastcall removeSemBal(_DWORD **a1, _DWORD *a2)
{
int v3; // eax
__int64 *v4; // rcx
__int64 v5; // r8
_DWORD *v6; // rax
_DWORD *v7; // rdx
_QWORD *v8; // rdi
_DWORD *v9; // rax
_DWORD *v10; // rcx
char v12; // al
char v13; // al
__int64 *v15; // [rsp+0h] [rbp-10h] BYREF

if ( !*a1 )
return 0LL;
v3 = objectcmp(a2, *a1);
switch ( v3 )
{
case -1:
if ( (unsigned int)removeSemBal(v4 + 1, v5) == 1 )
{
v12 = *((_BYTE *)*a1 + 4) - 1;
*((_BYTE *)*a1 + 4) = v12;
return v12 >= 0;
}
return 0LL;
case 1:
if ( (unsigned int)removeSemBal(v4 + 2, v5) == 1 )
{
v13 = *((_BYTE *)*a1 + 4) + 1;
*((_BYTE *)*a1 + 4) = v13;
return v13 <= 0;
}
return 0LL;
case 0:
v6 = (_DWORD *)v4[1];
v7 = (_DWORD *)v4[2];
if ( v6 )
{
if ( v7 )
{
v8 = v4 + 2;
v9 = (_DWORD *)lower_of_bigger(v4 + 2);
*v10 = *v9;
if ( (unsigned int)removeSemBal(v8, v9) == 1 )
return (*((_BYTE *)*a1 + 4))++ == 0xFF;
return 0LL;
}
v15 = v4;
*a1 = v6;
}
else
{
v15 = v4;
*a1 = v7;
}
destroy_node((void **)&v15);
return 1LL;
}
return 0LL;
}

original_code:
int removeSemBal(node **n, object *o) {
 if( ! *n )
  return 0;
 if( objectcmp(o,&((*n)->value)) == -1 ) {
  if( removeSemBal(&((*n)->left), o) == 1){
   (*n)->balance -= 1;
   return ((*n)->balance >= 0);
  }
 }
  else if( objectcmp(o,&((*n)->value)) == 1 ) {
  if( removeSemBal(&((*n)->right), o) == 1){
   (*n)->balance += 1;
   return ((*n)->balance <= 0);
  }
 }
 else if ( objectcmp(o, &((*n)->value)) == 0) {
  if ((*n)->left && (*n)->right) {
   object* lower = lower_of_bigger(&((*n)->right));
   (*n)->value = *lower;
   if (removeSemBal(&((*n)->right), lower) == 1) {
   (*n)->balance += 1;
   return ((*n)->balance == 0);
   }
  }
  else {
   node *m = *n;
   if ((*n)->left)
    *n = (*n)->left;
   else
    *n = (*n)->right;
   destroy_node(&m);
  return 1;
  }
}
 return 0;
}

canonical_original_code:
int removeSemBal(struct node **n, int *o) {
 if( ! *n )
  return 0;
 if( objectcmp(o,&((*n)->value)) == -1 ) {
  if( removeSemBal(&((*n)->left), o) == 1){
   (*n)->balance -= 1;
   return ((*n)->balance >= 0);
  }
 }
  else if( objectcmp(o,&((*n)->value)) == 1 ) {
  if( removeSemBal(&((*n)->right), o) == 1){
   (*n)->balance += 1;
   return ((*n)->balance <= 0);
  }
 }
 else if ( objectcmp(o, &((*n)->value)) == 0) {
  if ((*n)->left && (*n)->right) {
   int *lower = lower_of_bigger(&((*n)->right));
   (*n)->value = *lower;
   if (removeSemBal(&((*n)->right), lower) == 1) {
   (*n)->balance += 1;
   return ((*n)->balance == 0);
   }
  }
  else {
   struct node *m = *n;
   if ((*n)->left)
    *n = (*n)->left;
   else
    *n = (*n)->right;
   destroy_node(&m);
  return 1;
  }
}
 return 0;
}

variable_types:
lower
int *


original_code:
int remove_node(node **n, object *o, int *num_rots) {
 if( ! *n )
  return 0;
 if( objectcmp(o,&((*n)->value)) == -1 ) {
  if( remove_node(&((*n)->left), o, num_rots) == 1){
   (*n)->balance -= 1;
   if ( (*n)->balance == -2 ) {
    if ( (*n)->right ){
     if ( ((*n)->right)->balance == 1) {
      rotation_right(&(*n)->right);
      rotation_left(n);
      *num_rots+=2;
     }
     else if ( ((*n)->right)->balance == 0) {
      rotation_left(n);
      *num_rots+=1;
     }
     else if ( ((*n)->right)->balance == -1) {
      rotation_left(n);
      *num_rots+=1;
     }
    }
   }
   return ((*n)->balance == 0);
  }
 }
  else if( objectcmp(o,&((*n)->value)) == 1 ) {
  if( remove_node(&((*n)->right), o, num_rots) == 1){
   (*n)->balance += 1;
   if ( (*n)->balance == 2 ) {
    if ( (*n)->left ) {
     if ( ((*n)->left)->balance == 1 ) {
      rotation_right(n);
      *num_rots+=1;
     }
     else if ( ((*n)->left)->balance == 0) {
      rotation_right(n);
      *num_rots+=1;
     }
     else if ( ((*n)->left)->balance == -1) {
      rotation_left(&(*n)->left);
      rotation_right(n);
      *num_rots+=2;
     }
    }
   }
   return ((*n)->balance == 0);
  }
 }
 else if ( objectcmp(o, &((*n)->value)) == 0) {
  if ((*n)->left && (*n)->right) {
   object* lower = lower_of_bigger(&((*n)->right));
   (*n)->value = *lower;
   if (remove_node(&((*n)->right), lower, num_rots) == 1) {
   (*n)->balance += 1;
   if ( (*n)->balance == 2 ) {
    if ( (*n)->left ) {
     if ( ((*n)->left)->balance == 1 ) {
      rotation_right(n);
      *num_rots+=1;
     }
     else if ( ((*n)->left)->balance == 0) {
      rotation_right(n);
      *num_rots+=1;
     }
     else if ( ((*n)->left)->balance == -1) {
      rotation_left(&(*n)->left);
      rotation_right(n);
      *num_rots+=2;
     }
    }
   }
   return ((*n)->balance == 0);
   }
  }
  else {
   node *m = *n;
   if ((*n)->left)
    *n = (*n)->left;
   else
    *n = (*n)->right;
   destroy_node(&m);
  return 1;
  }
}
 return 0;
}

canonical_original_code:
int remove_node(struct node **n, int *o, int *num_rots) {
 if( ! *n )
  return 0;
 if( objectcmp(o,&((*n)->value)) == -1 ) {
  if( remove_node(&((*n)->left), o, num_rots) == 1){
   (*n)->balance -= 1;
   if ( (*n)->balance == -2 ) {
    if ( (*n)->right ){
     if ( ((*n)->right)->balance == 1) {
      rotation_right(&(*n)->right);
      rotation_left(n);
      *num_rots+=2;
     }
     else if ( ((*n)->right)->balance == 0) {
      rotation_left(n);
      *num_rots+=1;
     }
     else if ( ((*n)->right)->balance == -1) {
      rotation_left(n);
      *num_rots+=1;
     }
    }
   }
   return ((*n)->balance == 0);
  }
 }
  else if( objectcmp(o,&((*n)->value)) == 1 ) {
  if( remove_node(&((*n)->right), o, num_rots) == 1){
   (*n)->balance += 1;
   if ( (*n)->balance == 2 ) {
    if ( (*n)->left ) {
     if ( ((*n)->left)->balance == 1 ) {
      rotation_right(n);
      *num_rots+=1;
     }
     else if ( ((*n)->left)->balance == 0) {
      rotation_right(n);
      *num_rots+=1;
     }
     else if ( ((*n)->left)->balance == -1) {
      rotation_left(&(*n)->left);
      rotation_right(n);
      *num_rots+=2;
     }
    }
   }
   return ((*n)->balance == 0);
  }
 }
 else if ( objectcmp(o, &((*n)->value)) == 0) {
  if ((*n)->left && (*n)->right) {
   int *lower = lower_of_bigger(&((*n)->right));
   (*n)->value = *lower;
   if (remove_node(&((*n)->right), lower, num_rots) == 1) {
   (*n)->balance += 1;
   if ( (*n)->balance == 2 ) {
    if ( (*n)->left ) {
     if ( ((*n)->left)->balance == 1 ) {
      rotation_right(n);
      *num_rots+=1;
     }
     else if ( ((*n)->left)->balance == 0) {
      rotation_right(n);
      *num_rots+=1;
     }
     else if ( ((*n)->left)->balance == -1) {
      rotation_left(&(*n)->left);
      rotation_right(n);
      *num_rots+=2;
     }
    }
   }
   return ((*n)->balance == 0);
   }
  }
  else {
   struct node *m = *n;
   if ((*n)->left)
    *n = (*n)->left;
   else
    *n = (*n)->right;
   destroy_node(&m);
  return 1;
  }
}
 return 0;
}


decompiled_code:
__int64 __fastcall calcula_balanc(__int64 *a1)
{
__int64 v2; // rdi
int v3; // eax
int v4; // ebp
char v5; // r12
int v6; // eax
char v7; // dl
bool v8; // cc
unsigned int v9; // edx
__int64 result; // rax

v2 = *a1;
if ( !*(_QWORD *)(v2 + 8) )
{
if ( !*(_QWORD *)(v2 + 16) )
{
*(_BYTE *)(v2 + 4) = 0;
return 1LL;
}
v5 = 0;
v4 = 0;
goto LABEL_3;
}
v3 = calcula_balanc(v2 + 8);
v2 = *a1;
v4 = v3;
v5 = v3;
if ( *(_QWORD *)(*a1 + 16) )
{
LABEL_3:
v6 = calcula_balanc(v2 + 16);
v2 = *a1;
v7 = v5 - v6;
goto LABEL_4;
}
v7 = v3;
v6 = 0;
LABEL_4:
*(_BYTE *)(v2 + 4) = v7;
v8 = v6 < v4;
v9 = v6 + 1;
result = (unsigned int)(v4 + 1);
if ( !v8 )
result = v9;
return result;
}

original_code:
int calcula_balanc(node **n)
{
 int hesq=0, hdir=0;
 if ((*n)->left)
  hesq=calcula_balanc(&(*n)->left);
 if ((*n)->right)
  hdir=calcula_balanc(&(*n)->right);
 (*n)->balance=hesq-hdir;
 if (hesq>hdir)
  return hesq+1;
 else
  return hdir+1;
}

canonical_original_code:
int calcula_balanc(struct node **n)
{
 int hesq = 0; int hdir = 0;
 if ((*n)->left)
  hesq=calcula_balanc(&(*n)->left);
 if ((*n)->right)
  hdir=calcula_balanc(&(*n)->right);
 (*n)->balance=hesq-hdir;
 if (hesq>hdir)
  return hesq+1;
 else
  return hdir+1;
}

variable_types: hesq int

variable_types: hdir int


decompiled_code:
__int64 __fastcall calcula_contanodos(__int64 *a1)
{
char v2; // bl
__int64 v3; // rdi
char v4; // al
char v5; // al
char v6; // al

v2 = 1;
v3 = *a1;
if ( *(_QWORD *)(v3 + 8) )
{
v4 = calcula_contanodos(v3 + 8);
v3 = *a1;
v2 = v4 + 1;
}
v5 = 0;
if ( *(_QWORD *)(v3 + 16) )
{
v5 = calcula_contanodos(v3 + 16);
v3 = *a1;
}
v6 = v2 + v5;
*(_BYTE *)(v3 + 5) = v6;
return (unsigned int)v6;
}

original_code:
int calcula_contanodos(node **n)
{
 int pesq =0, pdir=0;
 if( (*n)->left )
  pesq = calcula_contanodos(&(*n)->left);
 if( (*n)->right )
  pdir = calcula_contanodos(&(*n)->right);
 (*n)->contanodo = pesq + pdir + 1;
 return (*n)->contanodo;
}

canonical_original_code:
int calcula_contanodos(struct node **n)
{
 int pesq = 0; int pdir = 0;
 if( (*n)->left )
  pesq = calcula_contanodos(&(*n)->left);
 if( (*n)->right )
  pdir = calcula_contanodos(&(*n)->right);
 (*n)->contanodo = pesq + pdir + 1;
 return (*n)->contanodo;
}

variable_types: pesq int

variable_types: pdir int


partPontoMed

decompiled_code:
__int64 __fastcall partPontoMed(__int64 *a1, _DWORD *a2)
{
double v3; // xmm0_8
__m128d v4; // xmm2
__m128d v5; // xmm1
__int64 result; // rax
__int64 v7; // rdi

while ( 1 )
{
calcula_contanodos(a1);
v3 = (double)*(char *)(*a1 + 5) * 0.5;
if ( COERCE_DOUBLE(LC11 & *(_QWORD *)&v3) < 4.503599627370496e15 )
{
v4.m128d_f64[0] = (double)*(char *)(*a1 + 5) * 0.5;
v5.m128d_f64[0] = (double)(int)v3;
*(_QWORD *)&v3 = COERCE_UNSIGNED_INT64(v5.m128d_f64[0] + COERCE_DOUBLE(*(_OWORD *)&_mm_cmpgt_sd(v4, v5) & LC10)) | ~LC11 & *(_QWORD *)&v3;
}
result = particionar(a1, (unsigned int)(int)v3, a2);
v7 = *a1;
if ( *(_QWORD *)(*a1 + 8) )
{
result = partPontoMed(v7 + 8, a2);
v7 = *a1;
}
if ( !*(_QWORD *)(v7 + 16) )
break;
a1 = (__int64 *)(v7 + 16);
}
return result;
}

original_code:
int partPontoMed(node **n, int *num_rots)
{
 calcula_contanodos(n);
 int metade=ceil((*n)->contanodo/2.0);
 particionar(n,metade, num_rots);
 if( (*n)->left )
  partPontoMed(&(*n)->left, num_rots);
 if( (*n)->right )
  partPontoMed(&(*n)->right, num_rots);
}

canonical_original_code:
int partPontoMed(struct node **n, int *num_rots)
{
 calcula_contanodos(n);
 int metade = ceil((*n)->contanodo/2.0);
 particionar(n,metade, num_rots);
 if( (*n)->left )
  partPontoMed(&(*n)->left, num_rots);
 if( (*n)->right )
  partPontoMed(&(*n)->right, num_rots);
}

variable_types: metade int


decompiled_code:
int __fastcall search_node(unsigned int **a1, _DWORD *a2)
{
unsigned int *v2; // rbx
int v3; // eax
unsigned int *v4; // rdx

v2 = *a1;
printf("%d", **a1);
v3 = objectcmp(a2, v2);
do
{
v4 = (unsigned int *)*((_QWORD *)v2 + 1);
if ( v3 != -1 )
v4 = (unsigned int *)*((_QWORD *)v2 + 2);
v2 = v4;
printf(",%d", *v4);
v3 = objectcmp(a2, v2);
}
while ( v3 );
return putchar(10);
}

canonical_decompiled_code:
int __fastcall func19(unsigned int **a1, _DWORD *a2)
{
unsigned int *v2; // rbx
int v3; // eax
unsigned int *v4; // rdx

v2 = *a1;
printf("%d", **a1);
v3 = func1(a2, v2);
do
{
v4 = (unsigned int *)*((_QWORD *)v2 + 1);
if ( v3 != -1 )
v4 = (unsigned int *)*((_QWORD *)v2 + 2);
v2 = v4;
printf(",%d", *v4);
v3 = func1(a2, v2);
}
while ( v3 );
return putchar(10);
}

original_code:
void search_node(node **n, object *o) {
 node *cptree = *n;
 printf("%d",cptree->value);
 do {
  if (objectcmp(o, &cptree->value) == -1 )
   cptree = cptree->left;
  else
   cptree = cptree->right;
  printf(",%d",cptree->value);
 } while ( objectcmp(o, &cptree->value) != 0 );
 printf("\n");
}

canonical_original_code:
void search_node(struct node **n, int *o) {
 struct node *cptree = *n;
 printf("%d",cptree->value);
 do {
  if (objectcmp(o, &cptree->value) == -1 )
   cptree = cptree->left;
  else
   cptree = cptree->right;
  printf(",%d",cptree->value);
 } while ( objectcmp(o, &cptree->value) != 0 );
 printf("\n");
}


buscaMenor

original_code:
int buscaMenor(tipoS dados, int aux)
{
 int i, indice = 0;
 int menor = dados.dist[0];
 for (i = 1; i < aux; i++)
  if (dados.dist[i] < menor)
  {
   menor = dados.dist[i];
   indice = i;
  }
 return indice;
}

canonical_original_code:
int buscaMenor(struct estrutura dados, int aux)
{
 int i; int indice = 0;
 int menor = dados.dist[0];
 for (i = 1; i < aux; i++)
  if (dados.dist[i] < menor)
  {
   menor = dados.dist[i];
   indice = i;
  }
 return indice;
}

variable_types: struct estrutura { int *cent; int *conta; int *soma; int *centaux; int *dist; }

variable_types: aux int

variable_types: i int

variable_types: indice int

variable_types: menor int


segmenta

original_code:
int segmenta(int *vetorIn, int *vetorOut, int linhas ,int colunas, int max, int aux)
{
 int tam = linhas * colunas;
 int i, j, indice;
 int mudou = 1;
 srand(time(((void *)0)));
 tipoS dados;
 dados.cent = (int *) malloc(sizeof(int) * aux);
 dados.conta = (int *) malloc(sizeof(int) * aux);
 dados.soma = (int *) malloc(sizeof(int) * aux);
 dados.centaux = (int *) malloc(sizeof(int) * aux);
 dados.dist = (int *) malloc(sizeof(int) * aux);
 if ((!dados.cent) || (!dados.conta) || (!dados.soma) || (!dados.centaux) || (!dados.dist))
  return 0;
 for (i = 0; i < aux; i++)
 {
  dados.cent[i] = rand () % max + 1;
  dados.centaux[i] = dados.cent[i];
 }
 while (mudou != 0)
 {
  mudou = 0;
  for (i = 0; i < aux; i++)
  {
   dados.conta[i] = 0;
   dados.soma[i] = 0;
  }
  for (i = 0; i < tam; i++)
  {
   for (j = 0; j < aux; j++)
   {
    dados.dist[j] = vetorIn[i] - dados.cent[j];
    if (dados.dist[j] < 0)
     dados.dist[j] = dados.dist[j] * -1;
   }
   indice = buscaMenor(dados, aux);
   vetorOut[i] = dados.cent[indice];
   dados.soma[indice] = dados.soma[indice] + vetorIn[i];
   dados.conta[indice]++;
  }
  for (i = 0; i < aux; i++)
  {
   if (dados.conta[i] != 0)
   {
    dados.cent[i] = dados.soma[i] / dados.conta[i];
   }
   if (dados.cent[i] != dados.centaux[i])
   {
    dados.centaux[i] = dados.cent[i];
    mudou = mudou + 1;
   }
  }
 }
 return 1;
}

canonical_original_code:
int segmenta(int *vetorIn, int *vetorOut, int linhas, int colunas, int max, int aux)
{
 int tam = linhas * colunas;
 int i; int j; int indice;
 int mudou = 1;
 srand(time(((void *)0)));
 struct estrutura dados;
 dados.cent = (int *) malloc(sizeof(int) * aux);
 dados.conta = (int *) malloc(sizeof(int) * aux);
 dados.soma = (int *) malloc(sizeof(int) * aux);
 dados.centaux = (int *) malloc(sizeof(int) * aux);
 dados.dist = (int *) malloc(sizeof(int) * aux);
 if ((!dados.cent) || (!dados.conta) || (!dados.soma) || (!dados.centaux) || (!dados.dist))
  return 0;
 for (i = 0; i < aux; i++)
 {
  dados.cent[i] = rand () % max + 1;
  dados.centaux[i] = dados.cent[i];
 }
 while (mudou != 0)
 {
  mudou = 0;
  for (i = 0; i < aux; i++)
  {
   dados.conta[i] = 0;
   dados.soma[i] = 0;
  }
  for (i = 0; i < tam; i++)
  {
   for (j = 0; j < aux; j++)
   {
    dados.dist[j] = vetorIn[i] - dados.cent[j];
    if (dados.dist[j] < 0)
     dados.dist[j] = dados.dist[j] * -1;
   }
   indice = buscaMenor(dados, aux);
   vetorOut[i] = dados.cent[indice];
   dados.soma[indice] = dados.soma[indice] + vetorIn[i];
   dados.conta[indice]++;
  }
  for (i = 0; i < aux; i++)
  {
   if (dados.conta[i] != 0)
   {
    dados.cent[i] = dados.soma[i] / dados.conta[i];
   }
   if (dados.cent[i] != dados.centaux[i])
   {
    dados.centaux[i] = dados.cent[i];
    mudou = mudou + 1;
   }
  }
 }
 return 1;
}

variable_types:
vetorIn
int *

variable_types:
vetorOut
int *

variable_types: linhas int

variable_types: colunas int

variable_types: max int

variable_types: tam int

variable_types: j int

variable_types: mudou int

user_defined_types: struct estrutura { int *cent; int *conta; int *soma; int *centaux; int *dist; }


repo: tospectre/mariokart

decompiled_code:
__int64 __fastcall aff_map(__int64 a1, int a2)
{
__int64 v3; // rbx
__int64 v4; // rdi
__int64 result; // rax

if ( a2 >= 0 )
{
v3 = 0LL;
do
{
v4 = *(_QWORD *)(a1 + 8 * v3++);
my_putstr(v4);
result = my_putchar(10LL);
}
while ( a2 >= (int)v3 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, int a2)
{
__int64 v3; // rbx
__int64 v4; // rdi
__int64 result; // rax

if ( a2 >= 0 )
{
v3 = 0LL;
do
{
v4 = *(_QWORD *)(a1 + 8 * v3++);
my_putstr(v4);
result = my_putchar(10LL);
}
while ( a2 >= (int)v3 );
}
return result;
}

original_code:
void aff_map(char **map, int width)
{
  int x;
  x = 0;
  while(x <= width)
    {
      my_putstr(map[x]);
      my_putchar('\n');
      x++;
    }
}

variable_types:
map
char **

variable_types: width int

variable_types: x int


decompiled_code:
__int64 score_value()
{
my_putstr("Your Score = ");
my_put_nbr(15LL);
return my_putchar(10LL);
}

canonical_decompiled_code:
__int64 func1()
{
my_putstr("Your Score = ");
my_put_nbr(15LL);
return my_putchar(10LL);
}

original_code:
void score_value()
{
  int score;
  score = 15;
  my_putstr("Your Score = ");
  my_put_nbr(score);
  my_putchar('\n');
}

variable_types: score int


original_code:
void print_map(char **map, int width, int height)
{
  int x;
  int y;
  score_value();
  x = 0;
  while(x <= width)
    {
      y = 0;
      while(y <= height)
 {
   if (((y == 0) || (y == height)) || ((x == 0) || (x == width)))
     map[x][y] = '#';
   else
     map[x][y] = ' ';
   y++;
 }
      map[x][y] = '\0';
      x++;
    }
  map[x] = '\0';
  aff_map(map, width);
}

variable_types: height int

variable_types: y int


decompiled_code:
__int64 __fastcall set_map(int a1, int a2)
{
void *v2; // rax
__int64 v3; // r12
__int64 v4; // r14
void *v5; // rax

v2 = malloc(8LL * a1 + 1);
if ( !v2 )
goto LABEL_6;
v3 = (__int64)v2;
v4 = 0LL;
if ( a1 >= 0 )
{
while ( 1 )
{
v5 = malloc(a2 + 1LL);
*(_QWORD *)(v3 + 8 * v4) = v5;
if ( !v5 )
break;
if ( a1 < (int)++v4 )
return print_map(v3, a1, a2);
}
LABEL_6:
my_putstr("[ERROR]: malloc failed\n");
exit(1);
}
return print_map(v3, a1, a2);
}

canonical_decompiled_code:
__int64 __fastcall func3(int a1, int a2)
{
void *v2; // rax
__int64 v3; // r12
__int64 v4; // r14
void *v5; // rax

v2 = malloc(8LL * a1 + 1);
if ( !v2 )
goto LABEL_6;
v3 = (__int64)v2;
v4 = 0LL;
if ( a1 >= 0 )
{
while ( 1 )
{
v5 = malloc(a2 + 1LL);
*(_QWORD *)(v3 + 8 * v4) = v5;
if ( !v5 )
break;
if ( a1 < (int)++v4 )
return func2(v3, a1, a2);
}
LABEL_6:
my_putstr("[ERROR]: malloc failed\n");
exit(1);
}
return func2(v3, a1, a2);
}

original_code:
void set_map(int x, int y)
{
  char **map;
  int i;
  i = 0;
  if ((map = malloc(sizeof(char*) * x + 1)) == ((void *)0))
    {
      my_putstr("[ERROR]: malloc failed\n");
      exit(1);
    }
  while(i <= x)
    {
      if ((map[i] = malloc(sizeof(char) * y + 1)) == ((void *)0))
 {
   my_putstr("[ERROR]: malloc failed\n");
   exit(1);
 }
      i++;
    }
  print_map(map, x, y);
}

canonical_original_code:
void set_map(int x, int y)
{
  char **map;
  int i;
  i = 0;
  if ((map = malloc(sizeof(char *) * x + 1)) == ((void *)0))
    {
      my_putstr("[ERROR]: malloc failed\n");
      exit(1);
    }
  while(i <= x)
    {
      if ((map[i] = malloc(sizeof(char) * y + 1)) == ((void *)0))
 {
   my_putstr("[ERROR]: malloc failed\n");
   exit(1);
 }
      i++;
    }
  print_map(map, x, y);
}

variable_types: i int


main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rdx
__int64 v4; // rdx
unsigned int v5; // ebp
__int64 v6; // r12

if ( argc != 3 )
{
my_putstr("[USAGE] : ", argv, envp);
my_putstr(*argv, argv, v3);
my_putstr(": Enter HEIGHT and WIDTH !\n", argv, v4);
exit(1);
}
v5 = my_getnbr(argv[1]);
v6 = (unsigned int)my_getnbr(argv[2]);
check_param(v5, v6);
set_map(v5, (unsigned int)v6);
exit(0);
}

original_code:
int main(int argc, char **argv)
{
  int height;
  int width;
  if (argc != 3)
    {
      my_putstr("[USAGE] : ");
      my_putstr(argv[0]);
      my_putstr(":  Enter HEIGHT and WIDTH !\n");
      exit(1);
    }
  width = my_getnbr(argv[1]);
  height = my_getnbr(argv[2]);
  check_param(width, height);
  set_map(width, height);
  exit(0);
}

variable_types: argc int

variable_types:
argv
char **


decompiled_code:
void __fastcall check_param(int a1, int a2)
{
if ( a1 <= 0 || a2 <= 0 )
{
my_putstr("[ERROR] : You must put positive values.\n");
exit(1);
}
}

canonical_decompiled_code:
void __fastcall func0(int a1, int a2)
{
if ( a1 <= 0 || a2 <= 0 )
{
my_putstr("[ERROR] : You must put positive values.\n");
exit(1);
}
}

original_code:
void check_param(int width, int height)
{
  if ((width <= 0) || (height <= 0))
    {
      my_putstr("[ERROR] : You must put positive values.\n");
      exit(1);
    }
}


repo: totomo/math

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rbp
__int64 v4; // r12
int v5; // ebx

verifyArguments(argc, argv, envp);
v3 = extractFromArguments(argv);
if ( v3 <= 0 )
{
v5 = 0;
}
else
{
v4 = 0LL;
v5 = 0;
do
{
++v4;
v5 += (char)isContainCircle(0.0, 0.0);
}
while ( v3 != v4 );
}
fprintf(stdout, "result: %3.7f\n", (double)v5 / (double)(int)v3 * 4.0);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rbp
__int64 v4; // r12
int v5; // ebx

func10(argc, argv, envp);
v3 = func9(argv);
if ( v3 <= 0 )
{
v5 = 0;
}
else
{
v4 = 0LL;
v5 = 0;
do
{
++v4;
v5 += (char)func8(0.0, 0.0);
}
while ( v3 != v4 );
}
fprintf(stdout, "result: %3.7f\n", (double)v5 / (double)(int)v3 * 4.0);
return 0;
}

original_code:
int main(int argc, char **argv){
 coord p;
 long number;
 int i;
 int count = 0;
 verifyArguments(argc);
 number = extractFromArguments(argv);
 for( i=0; i<number; i++ ){
  count += isContainCircle(p);
 }
 fprintf(stdout, "result: %3.7f\n", (double)count / number * 4.0);
 return 0;
}

canonical_original_code:
int main(int argc, char **argv){
 struct coord p;
 long number;
 int i;
 int count = 0;
 verifyArguments(argc);
 number = extractFromArguments(argv);
 for( i=0; i<number; i++ ){
  count += isContainCircle(p);
 }
 fprintf(stdout, "result: %3.7f\n", (double)count / number * 4.0);
 return 0;
}

variable_types:
p
struct coord { double x; double y; }

variable_types: number long

variable_types: count int


usage

decompiled_code:
size_t usage()
{
fwrite("Usage: estpi ... NumberOfIteration\n", 1uLL, 0x23uLL, stderr);
fwrite("Options:\n", 1uLL, 9uLL, stderr);
return fwrite("--help, -h: show the usage.\n", 1uLL, 0x1CuLL, stderr);
}

canonical_decompiled_code:
size_t func7()
{
fwrite("Usage: estpi ... NumberOfIteration\n", 1uLL, 0x23uLL, stderr);
fwrite("Options:\n", 1uLL, 9uLL, stderr);
return fwrite("--help, -h: show the usage.\n", 1uLL, 0x1CuLL, stderr);
}

original_code:
void usage(){
 fprintf(stderr, "Usage: estpi ... NumberOfIteration\n");
 fprintf(stderr, "Options:\n");
 fprintf(stderr, "--help, -h: show the usage.\n");
}


isContainCircle

original_code:
char isContainCircle(coord p){
 p.x =(double) rand() / 2147483647;
 p.y =(double) rand() / 2147483647;
 if( pow(p.x, 2) + pow(p.y, 2) <= 1.0 ){
  return 1;
 }
 else {
  return 0;
 }
}

canonical_original_code:
char isContainCircle(struct coord p){
 p.x =(double) rand() / 2147483647;
 p.y =(double) rand() / 2147483647;
 if( pow(p.x, 2) + pow(p.y, 2) <= 1.0 ){
  return 1;
 }
 else {
  return 0;
 }
}

return_type: char


extractFromArguments

decompiled_code:
void __fastcall extractFromArguments(__int64 a1)
{
const char *v1; // r8
bool v2; // zf
int v3; // edx

v1 = *(const char **)(a1 + 8);
if ( v1 )
{
v2 = strcmp(v1, "--help") == 0;
v3 = *(unsigned __int8 *)v1 - 45;
if ( *v1 == 45 )
{
v3 = *((unsigned __int8 *)v1 + 1) - 104;
if ( v1[1] == 104 )
v3 = *((unsigned __int8 *)v1 + 2);
}
if ( !(v3 * !v2) )
{
usage();
exit(1);
}
atoi(v1);
}
}

original_code:
long extractFromArguments(char **argv){
 int i=1;
 while( argv[i] != ((void *)0) ){
  if( strcmp(argv[i], "--help") * strcmp(argv[i], "-h") ==0 ){
   usage();
   exit(1);
  }
  else{
   return atoi(argv[i]);
  }
  i++;
 }
}

canonical_original_code:
long extractFromArguments(char **argv){
 int i = 1;
 while( argv[i] != ((void *)0) ){
  if( strcmp(argv[i], "--help") * strcmp(argv[i], "-h") ==0 ){
   usage();
   exit(1);
  }
  else{
   return atoi(argv[i]);
  }
  i++;
 }
}

return_type: long


verifyArguments

decompiled_code:
void __fastcall verifyArguments(int a1)
{
if ( (unsigned int)(a1 - 2) > 1 )
exit(1);
}

canonical_decompiled_code:
void __fastcall func10(int a1)
{
if ( (unsigned int)(a1 - 2) > 1 )
exit(1);
}

original_code:
void verifyArguments(int argc){
 if(argc!=2 && argc!=3){
  exit(1);
 }
}


decompiled_code:
__int64 interval_work_init_generic()
{
double v0; // xmm1_8
__int64 result; // rax

state_of_cpu = 0;
v0 = (double)(int)(1000000.0 * *(double *)&cpu_clock_mhz / *(double *)&vsync_freq_hz);
vsync_intr_base = (int)(1000000.0 * *(double *)&cpu_clock_mhz / *(double *)&vsync_freq_hz);
vsync_intr_timer = (int)(1000000.0 * *(double *)&cpu_clock_mhz / *(double *)&vsync_freq_hz);
state_of_vsync = (int)(1000000.0 * *(double *)&cpu_clock_mhz / *(double *)&vsync_freq_hz);
result = (unsigned int)boost;
vrtc_base = (int)(0.1066964285714286 * v0);
vrtc_timer = (int)(0.1066964285714286 * v0);
vrtc_base2 = (int)(v0 * 0.8928571428571429);
rtc_intr_base = (int)(1000000.0 * *(double *)&cpu_clock_mhz / 600.0);
rtc_intr_timer = (int)(1000000.0 * *(double *)&cpu_clock_mhz / 600.0);
if ( boost <= 0 )
boost = 1;
boost_cnt = 0;
return result;
}

canonical_decompiled_code:
__int64 func0()
{
double v0; // xmm1_8
__int64 result; // rax

state_of_cpu = 0;
v0 = (double)(int)(1000000.0 * *(double *)&cpu_clock_mhz / *(double *)&vsync_freq_hz);
vsync_intr_base = (int)(1000000.0 * *(double *)&cpu_clock_mhz / *(double *)&vsync_freq_hz);
vsync_intr_timer = (int)(1000000.0 * *(double *)&cpu_clock_mhz / *(double *)&vsync_freq_hz);
state_of_vsync = (int)(1000000.0 * *(double *)&cpu_clock_mhz / *(double *)&vsync_freq_hz);
result = (unsigned int)boost;
vrtc_base = (int)(0.1066964285714286 * v0);
vrtc_timer = (int)(0.1066964285714286 * v0);
vrtc_base2 = (int)(v0 * 0.8928571428571429);
rtc_intr_base = (int)(1000000.0 * *(double *)&cpu_clock_mhz / 600.0);
rtc_intr_timer = (int)(1000000.0 * *(double *)&cpu_clock_mhz / 600.0);
if ( boost <= 0 )
boost = 1;
boost_cnt = 0;
return result;
}

original_code:
static void interval_work_init_generic( void )
{
  vsync_intr_timer = vsync_intr_base = (cpu_clock_mhz * 1000000) / vsync_freq_hz;
  vrtc_timer = vrtc_base = (vsync_intr_base * (( 47.8 ) /448.0));
                     vrtc_base2 = (vsync_intr_base * (( 400.0 ) /448.0));
  rtc_intr_timer = rtc_intr_base = (cpu_clock_mhz * 1000000) / (600);
  state_of_vsync = vsync_intr_base;
  state_of_cpu = 0;
  if( boost < 1 ) boost = 1;
  boost_cnt = 0;
}

canonical_original_code:
static void interval_work_init_generic()
{
  vsync_intr_timer = vsync_intr_base = (cpu_clock_mhz * 1000000) / vsync_freq_hz;
  vrtc_timer = vrtc_base = (vsync_intr_base * (( 47.8 ) /448.0));
                     vrtc_base2 = (vsync_intr_base * (( 400.0 ) /448.0));
  rtc_intr_timer = rtc_intr_base = (cpu_clock_mhz * 1000000) / (600);
  state_of_vsync = vsync_intr_base;
  state_of_cpu = 0;
  if( boost < 1 ) boost = 1;
  boost_cnt = 0;
}


decompiled_code:
__int64 check_sound_parm_update()
{
int v0; // ecx
int v1; // esi
__int64 result; // rax
unsigned __int8 v3; // dl
unsigned __int8 v4; // si
unsigned __int8 v5; // cl
char v6; // dl
char v7; // al
char v8; // dl

v0 = sound_prescaler_update;
if ( sound_prescaler_update )
{
v1 = sound_prescaler;
sound_prescaler_update = 0;
sound_prescaler = v0;
sd_A_intr_base = v0 * sd_A_intr_base / v1;
sd_A_intr_timer = v0 * sd_A_intr_timer / v1;
sd_B_intr_base = v0 * sd_B_intr_base / v1;
sd_B_intr_timer = v0 * sd_B_intr_timer / v1;
}
result = (unsigned int)sound_flags_update;
switch ( sound_flags_update )
{
case 39:
v3 = sound_reg[39];
v4 = v3 & 1;
if ( !sound_LOAD_A && v4 )
sd_A_intr_timer = sd_A_intr_base;
v5 = v3 & 2;
if ( !sound_LOAD_B && v5 )
sd_B_intr_timer = sd_B_intr_base;
sound_LOAD_B = v5;
result = ((int)v3 >> 3) & 1;
sound_LOAD_A = v4;
sound_ENABLE_B = ((int)v3 >> 3) & 1;
sound_ENABLE_A = ((int)v3 >> 2) & 1;
if ( (v3 & 0x10) != 0 )
sound_FLAG_A = 0;
if ( (v3 & 0x20) == 0 )
goto LABEL_6;
sound_FLAG_B = 0;
sound_flags_update = 0;
break;
case 41:
if ( sound_board == 1 )
{
v7 = sound_reg[41];
sound2_EN_TA = v7 & 1;
sound2_EN_TB = v7 & 2;
sound2_EN_EOS = v7 & 4;
v8 = v7;
result = v7 & 0x10;
sound2_EN_ZERO = result;
sound2_EN_BRDY = v8 & 8;
}
goto LABEL_6;
case 16:
result = sound2_reg[16];
if ( (result & 0x80u) != 0LL )
{
sound_FLAG_A = 0;
sound_FLAG_B = 0;
sound2_FLAG_EOS = 0;
sound2_FLAG_BRDY = 0;
sound2_FLAG_ZERO = 0;
sound_flags_update = 0;
}
else
{
sound_flags_update = 0;
sound2_MSK_TA = result & 1;
sound2_MSK_TB = result & 2;
sound2_MSK_EOS = result & 4;
v6 = result;
result &= 0x10u;
sound2_MSK_ZERO = result;
sound2_MSK_BRDY = v6 & 8;
}
break;
default:
LABEL_6:
sound_flags_update = 0;
return result;
}
return result;
}

canonical_decompiled_code:
__int64 func1()
{
int v0; // ecx
int v1; // esi
__int64 result; // rax
unsigned __int8 v3; // dl
unsigned __int8 v4; // si
unsigned __int8 v5; // cl
char v6; // dl
char v7; // al
char v8; // dl

v0 = sound_prescaler_update;
if ( sound_prescaler_update )
{
v1 = sound_prescaler;
sound_prescaler_update = 0;
sound_prescaler = v0;
sd_A_intr_base = v0 * sd_A_intr_base / v1;
sd_A_intr_timer = v0 * sd_A_intr_timer / v1;
sd_B_intr_base = v0 * sd_B_intr_base / v1;
sd_B_intr_timer = v0 * sd_B_intr_timer / v1;
}
result = (unsigned int)sound_flags_update;
switch ( sound_flags_update )
{
case 39:
v3 = sound_reg[39];
v4 = v3 & 1;
if ( !sound_LOAD_A && v4 )
sd_A_intr_timer = sd_A_intr_base;
v5 = v3 & 2;
if ( !sound_LOAD_B && v5 )
sd_B_intr_timer = sd_B_intr_base;
sound_LOAD_B = v5;
result = ((int)v3 >> 3) & 1;
sound_LOAD_A = v4;
sound_ENABLE_B = ((int)v3 >> 3) & 1;
sound_ENABLE_A = ((int)v3 >> 2) & 1;
if ( (v3 & 0x10) != 0 )
sound_FLAG_A = 0;
if ( (v3 & 0x20) == 0 )
goto LABEL_6;
sound_FLAG_B = 0;
sound_flags_update = 0;
break;
case 41:
if ( sound_board == 1 )
{
v7 = sound_reg[41];
sound2_EN_TA = v7 & 1;
sound2_EN_TB = v7 & 2;
sound2_EN_EOS = v7 & 4;
v8 = v7;
result = v7 & 0x10;
sound2_EN_ZERO = result;
sound2_EN_BRDY = v8 & 8;
}
goto LABEL_6;
case 16:
result = sound2_reg[16];
if ( (result & 0x80u) != 0LL )
{
sound_FLAG_A = 0;
sound_FLAG_B = 0;
sound2_FLAG_EOS = 0;
sound2_FLAG_BRDY = 0;
sound2_FLAG_ZERO = 0;
sound_flags_update = 0;
}
else
{
sound_flags_update = 0;
sound2_MSK_TA = result & 1;
sound2_MSK_TB = result & 2;
sound2_MSK_EOS = result & 4;
v6 = result;
result &= 0x10u;
sound2_MSK_ZERO = result;
sound2_MSK_BRDY = v6 & 8;
}
break;
default:
LABEL_6:
sound_flags_update = 0;
return result;
}
return result;
}

original_code:
static void check_sound_parm_update( void )
{
  byte data;
  if( sound_prescaler_update ){
    sd_A_intr_base = sd_A_intr_base * sound_prescaler_update/sound_prescaler;
    sd_A_intr_timer = sd_A_intr_timer * sound_prescaler_update/sound_prescaler;
    sd_B_intr_base = sd_B_intr_base * sound_prescaler_update/sound_prescaler;
    sd_B_intr_timer = sd_B_intr_timer * sound_prescaler_update/sound_prescaler;
    sound_prescaler = sound_prescaler_update;
    sound_prescaler_update = 0;
  }
  switch( sound_flags_update ){
  case 0x27:
    data = sound_reg[0x27];
    if( (sound_LOAD_A==0) && (data&0x01) ) sd_A_intr_timer = sd_A_intr_base;
    if( (sound_LOAD_B==0) && (data&0x02) ) sd_B_intr_timer = sd_B_intr_base;
    sound_LOAD_A = data & 0x01;
    sound_LOAD_B = data & 0x02;
    sound_ENABLE_A = ( data & 0x04 ) ? 1 : 0;
    sound_ENABLE_B = ( data & 0x08 ) ? 1 : 0;
    if( data & 0x10 ) sound_FLAG_A = 0;
    if( data & 0x20 ) sound_FLAG_B = 0;
    break;
  case 0x29:
    if( sound_board==SOUND_II ){
      data = sound_reg[0x29];
      sound2_EN_TA = data & 0x01;
      sound2_EN_TB = data & 0x02;
      sound2_EN_EOS = data & 0x04;
      sound2_EN_BRDY = data & 0x08;
      sound2_EN_ZERO = data & 0x10;
    }
    break;
  case 0x10:
    data = sound2_reg[0x10];
    if( data & 0x80 ){
      sound_FLAG_A = 0;
      sound_FLAG_B = 0;
      sound2_FLAG_EOS = 0;
      sound2_FLAG_BRDY = 0;
      sound2_FLAG_ZERO = 0;
    }else{
      sound2_MSK_TA = data & 0x01;
      sound2_MSK_TB = data & 0x02;
      sound2_MSK_EOS = data & 0x04;
      sound2_MSK_BRDY = data & 0x08;
      sound2_MSK_ZERO = data & 0x10;
    }
    break;
  }
  sound_flags_update = 0;
}

canonical_original_code:
static void check_sound_parm_update()
{
  unsigned char data;
  if( sound_prescaler_update ){
    sd_A_intr_base = sd_A_intr_base * sound_prescaler_update/sound_prescaler;
    sd_A_intr_timer = sd_A_intr_timer * sound_prescaler_update/sound_prescaler;
    sd_B_intr_base = sd_B_intr_base * sound_prescaler_update/sound_prescaler;
    sd_B_intr_timer = sd_B_intr_timer * sound_prescaler_update/sound_prescaler;
    sound_prescaler = sound_prescaler_update;
    sound_prescaler_update = 0;
  }
  switch( sound_flags_update ){
  case 0x27:
    data = sound_reg[0x27];
    if( (sound_LOAD_A==0) && (data&0x01) ) sd_A_intr_timer = sd_A_intr_base;
    if( (sound_LOAD_B==0) && (data&0x02) ) sd_B_intr_timer = sd_B_intr_base;
    sound_LOAD_A = data & 0x01;
    sound_LOAD_B = data & 0x02;
    sound_ENABLE_A = ( data & 0x04 ) ? 1 : 0;
    sound_ENABLE_B = ( data & 0x08 ) ? 1 : 0;
    if( data & 0x10 ) sound_FLAG_A = 0;
    if( data & 0x20 ) sound_FLAG_B = 0;
    break;
  case 0x29:
    if( sound_board==SOUND_II ){
      data = sound_reg[0x29];
      sound2_EN_TA = data & 0x01;
      sound2_EN_TB = data & 0x02;
      sound2_EN_EOS = data & 0x04;
      sound2_EN_BRDY = data & 0x08;
      sound2_EN_ZERO = data & 0x10;
    }
    break;
  case 0x10:
    data = sound2_reg[0x10];
    if( data & 0x80 ){
      sound_FLAG_A = 0;
      sound_FLAG_B = 0;
      sound2_FLAG_EOS = 0;
      sound2_FLAG_BRDY = 0;
      sound2_FLAG_ZERO = 0;
    }else{
      sound2_MSK_TA = data & 0x01;
      sound2_MSK_TB = data & 0x02;
      sound2_MSK_EOS = data & 0x04;
      sound2_MSK_BRDY = data & 0x08;
      sound2_MSK_ZERO = data & 0x10;
    }
    break;
  }
  sound_flags_update = 0;
}

variable_types:
data
unsigned char


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

result = (unsigned int)intr_level;
z80main_cpu[8] = intr_level
&& (intr_level > 0 && RS232C_flag
|| intr_level > 1 && VSYNC_flag
|| intr_level > 2 && RTC_flag
|| intr_level > 4 && (result = (unsigned int)SOUND_flag, SOUND_flag));
return result;
}

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

result = (unsigned int)intr_level;
z80main_cpu[8] = intr_level
&& (intr_level > 0 && RS232C_flag
|| intr_level > 1 && VSYNC_flag
|| intr_level > 2 && RTC_flag
|| intr_level > 4 && (result = (unsigned int)SOUND_flag, SOUND_flag));
return result;
}

original_code:
static __inline__ void set_INT_active( void )
{
  if( intr_level==0 ){
    z80main_cpu.INT_active = (0);
  }
  else if( intr_level>=1 &&
                         RS232C_flag ){
    z80main_cpu.INT_active = (1);
  }
  else if( intr_level>=2 &&
                           VSYNC_flag ){
    z80main_cpu.INT_active = (1);
  }
  else if( intr_level>=3 &&
                         RTC_flag ){
    z80main_cpu.INT_active = (1);
  }
  else if( intr_level>=5 &&
                           SOUND_flag ){
    z80main_cpu.INT_active = (1);
  }
  else{
    z80main_cpu.INT_active = (0);
  }
}

canonical_original_code:
static __inline__ void set_INT_active()
{
  if( intr_level==0 ){
    z80main_cpu.INT_active = (0);
  }
  else if( intr_level>=1 &&
                         RS232C_flag ){
    z80main_cpu.INT_active = (1);
  }
  else if( intr_level>=2 &&
                           VSYNC_flag ){
    z80main_cpu.INT_active = (1);
  }
  else if( intr_level>=3 &&
                         RTC_flag ){
    z80main_cpu.INT_active = (1);
  }
  else if( intr_level>=5 &&
                           SOUND_flag ){
    z80main_cpu.INT_active = (1);
  }
  else{
    z80main_cpu.INT_active = (0);
  }
}


vsync

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

if ( ++boost_cnt < boost )
{
if ( boost_cnt )
goto LABEL_7;
}
else
{
boost_cnt = 0;
}
xmame_sound_update();
if ( !no_wait )
wait_vsync();
xmame_update_video_and_audio();
event_handle();
scan_keyboard();
LABEL_7:
dma_wait_count = crtc_sz_lines * crtc_byte_per_line;
result = (unsigned int)state_of_vsync;
state_of_cpu -= state_of_vsync;
return result;
}

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

if ( ++boost_cnt < boost )
{
if ( boost_cnt )
goto LABEL_7;
}
else
{
boost_cnt = 0;
}
xmame_sound_update();
if ( !no_wait )
wait_vsync();
xmame_update_video_and_audio();
event_handle();
scan_keyboard();
LABEL_7:
dma_wait_count = crtc_sz_lines * crtc_byte_per_line;
result = (unsigned int)state_of_vsync;
state_of_cpu -= state_of_vsync;
return result;
}

original_code:
static void vsync( void )
{
  if( ++ boost_cnt >= boost ){
    boost_cnt = 0;
  }
  if( boost_cnt == 0 ){
    xmame_sound_update();
    if( !no_wait ) wait_vsync();
    xmame_update_video_and_audio();
    event_handle();
    scan_keyboard();
  }
  dma_wait_count = crtc_byte_per_line * crtc_sz_lines;
  state_of_cpu -= state_of_vsync;
}

canonical_original_code:
static void vsync()
{
  if( ++ boost_cnt >= boost ){
    boost_cnt = 0;
  }
  if( boost_cnt == 0 ){
    xmame_sound_update();
    if( !no_wait ) wait_vsync();
    xmame_update_video_and_audio();
    event_handle();
    scan_keyboard();
  }
  dma_wait_count = crtc_byte_per_line * crtc_sz_lines;
  state_of_cpu -= state_of_vsync;
}


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

if ( a1 && a2 )
{
result = (unsigned int)(int)(1000000.0 * *(double *)&cpu_clock_mhz / ((double)a1 / (double)a2));
if ( (int)result > 99 )
{
rs232c_intr_base = (int)(1000000.0 * *(double *)&cpu_clock_mhz / ((double)a1 / (double)a2));
rs232c_intr_timer = rs232c_intr_base;
}
else
{
rs232c_intr_base = 100;
result = 100LL;
rs232c_intr_timer = 100;
}
}
else
{
rs232c_intr_base = 0x7FFFFFFF;
result = 0x7FFFFFFFLL;
rs232c_intr_timer = 0x7FFFFFFF;
}
return result;
}

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

if ( a1 && a2 )
{
result = (unsigned int)(int)(1000000.0 * *(double *)&cpu_clock_mhz / ((double)a1 / (double)a2));
if ( (int)result > 99 )
{
rs232c_intr_base = (int)(1000000.0 * *(double *)&cpu_clock_mhz / ((double)a1 / (double)a2));
rs232c_intr_timer = rs232c_intr_base;
}
else
{
rs232c_intr_base = 100;
result = 100LL;
rs232c_intr_timer = 100;
}
}
else
{
rs232c_intr_base = 0x7FFFFFFF;
result = 0x7FFFFFFFLL;
rs232c_intr_timer = 0x7FFFFFFF;
}
return result;
}

original_code:
void interval_work_set_RS232C( int bps, int framesize )
{
  if( bps == 0 || framesize == 0 ){
    rs232c_intr_base = 0x7fffffff;
  }else{
    rs232c_intr_base = (cpu_clock_mhz * 1000000) / ( (double)bps / (double)framesize );
    if( rs232c_intr_base < 100 ) rs232c_intr_base = 100;
  }
  rs232c_intr_timer = rs232c_intr_base;
}

canonical_original_code:
void interval_work_set_RS232C(int bps, int framesize)
{
  if( bps == 0 || framesize == 0 ){
    rs232c_intr_base = 0x7fffffff;
  }else{
    rs232c_intr_base = (cpu_clock_mhz * 1000000) / ( (double)bps / (double)framesize );
    if( rs232c_intr_base < 100 ) rs232c_intr_base = 100;
  }
  rs232c_intr_timer = rs232c_intr_base;
}

variable_types: bps int

variable_types: framesize int


decompiled_code:
__int64 interval_work_init_RS232C()
{
return interval_work_set_RS232C(0, 0);
}

canonical_decompiled_code:
__int64 func5()
{
return func4(0, 0);
}

original_code:
static void interval_work_init_RS232C( void )
{
  interval_work_set_RS232C( 0, 0 );
}

canonical_original_code:
static void interval_work_init_RS232C()
{
  interval_work_set_RS232C( 0, 0 );
}


decompiled_code:
__int64 __fastcall boost_change(int a1)
{
__int64 result; // rax
double v2; // xmm0_8
double v3; // xmm0_8

if ( a1 < 0 )
a1 = 1;
result = (unsigned int)boost;
if ( boost != a1 )
{
boost = a1;
boost_cnt = 0;
v2 = (double)a1 / (double)(int)result;
sd_A_intr_base = (int)((double)sd_A_intr_base * v2);
sd_A_intr_timer = (int)((double)sd_A_intr_timer * v2);
sd_B_intr_base = (int)((double)sd_B_intr_base * v2);
v3 = v2 * (double)sd_B_intr_timer;
result = (unsigned int)(int)v3;
sd_B_intr_timer = (int)v3;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(int a1)
{
__int64 result; // rax
double v2; // xmm0_8
double v3; // xmm0_8

if ( a1 < 0 )
a1 = 1;
result = (unsigned int)boost;
if ( boost != a1 )
{
boost = a1;
boost_cnt = 0;
v2 = (double)a1 / (double)(int)result;
sd_A_intr_base = (int)((double)sd_A_intr_base * v2);
sd_A_intr_timer = (int)((double)sd_A_intr_timer * v2);
sd_B_intr_base = (int)((double)sd_B_intr_base * v2);
v3 = v2 * (double)sd_B_intr_timer;
result = (unsigned int)(int)v3;
sd_B_intr_timer = (int)v3;
}
return result;
}

original_code:
void boost_change( int new_val )
{
  if( new_val < 0 ) new_val = 1;
  if( boost != new_val ){
    double rate = (double)new_val / boost;
    sd_A_intr_base *= rate;
    sd_A_intr_timer *= rate;
    sd_B_intr_base *= rate;
    sd_B_intr_timer *= rate;
    boost = new_val;
    boost_cnt = 0;
  }
}

canonical_original_code:
void boost_change(int new_val)
{
  if( new_val < 0 ) new_val = 1;
  if( boost != new_val ){
    double rate = (double)new_val / boost;
    sd_A_intr_base *= rate;
    sd_A_intr_timer *= rate;
    sd_B_intr_base *= rate;
    sd_B_intr_timer *= rate;
    boost = new_val;
    boost_cnt = 0;
  }
}

variable_types: rate double


decompiled_code:
__int64 interval_work_set_TIMER_A()
{
double v0; // xmm0_8
__int64 result; // rax

v0 = (double)(12 * sound_prescaler * (1024 - sound_TIMER_A))
* (*(double *)&cpu_clock_mhz
/ *(double *)&sound_clock_mhz);
result = (unsigned int)(boost * (int)v0);
sd_A_intr_base = boost * (int)v0;
return result;
}

canonical_decompiled_code:
__int64 func7()
{
double v0; // xmm0_8
__int64 result; // rax

v0 = (double)(12 * sound_prescaler * (1024 - sound_TIMER_A))
* (*(double *)&cpu_clock_mhz
/ *(double *)&sound_clock_mhz);
result = (unsigned int)(boost * (int)v0);
sd_A_intr_base = boost * (int)v0;
return result;
}

original_code:
void interval_work_set_TIMER_A( void )
{
  sd_A_intr_base = (12) * sound_prescaler * (1024 - sound_TIMER_A)
     * ( cpu_clock_mhz / sound_clock_mhz );
  sd_A_intr_base *= boost;
}

canonical_original_code:
void interval_work_set_TIMER_A()
{
  sd_A_intr_base = (12) * sound_prescaler * (1024 - sound_TIMER_A)
     * ( cpu_clock_mhz / sound_clock_mhz );
  sd_A_intr_base *= boost;
}


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

interval_work_set_TIMER_A();
result = (unsigned int)sd_A_intr_base;
sd_A_intr_timer = sd_A_intr_base;
return result;
}

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

func7();
result = (unsigned int)sd_A_intr_base;
sd_A_intr_timer = sd_A_intr_base;
return result;
}

original_code:
static void interval_work_init_TIMER_A( void )
{
  interval_work_set_TIMER_A();
  sd_A_intr_timer = sd_A_intr_base;
}

canonical_original_code:
static void interval_work_init_TIMER_A()
{
  interval_work_set_TIMER_A();
  sd_A_intr_timer = sd_A_intr_base;
}


decompiled_code:
__int64 interval_work_set_TIMER_B()
{
double v0; // xmm0_8
__int64 result; // rax

v0 = (double)(192 * sound_prescaler * (256 - sound_TIMER_B))
* (*(double *)&cpu_clock_mhz
/ *(double *)&sound_clock_mhz);
result = (unsigned int)(boost * (int)v0);
sd_B_intr_base = boost * (int)v0;
return result;
}

canonical_decompiled_code:
__int64 func9()
{
double v0; // xmm0_8
__int64 result; // rax

v0 = (double)(192 * sound_prescaler * (256 - sound_TIMER_B))
* (*(double *)&cpu_clock_mhz
/ *(double *)&sound_clock_mhz);
result = (unsigned int)(boost * (int)v0);
sd_B_intr_base = boost * (int)v0;
return result;
}

original_code:
void interval_work_set_TIMER_B( void )
{
  sd_B_intr_base = (192) * sound_prescaler * (256 - sound_TIMER_B)
     * ( cpu_clock_mhz / sound_clock_mhz );
  sd_B_intr_base *= boost;
}

canonical_original_code:
void interval_work_set_TIMER_B()
{
  sd_B_intr_base = (192) * sound_prescaler * (256 - sound_TIMER_B)
     * ( cpu_clock_mhz / sound_clock_mhz );
  sd_B_intr_base *= boost;
}


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

interval_work_set_TIMER_B();
result = (unsigned int)sd_B_intr_base;
sd_B_intr_timer = sd_B_intr_base;
return result;
}

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

func9();
result = (unsigned int)sd_B_intr_base;
sd_B_intr_timer = sd_B_intr_base;
return result;
}

original_code:
static void interval_work_init_TIMER_B( void )
{
  interval_work_set_TIMER_B();
  sd_B_intr_timer = sd_B_intr_base;
}

canonical_original_code:
static void interval_work_init_TIMER_B()
{
  interval_work_set_TIMER_B();
  sd_B_intr_timer = sd_B_intr_base;
}


decompiled_code:
__int64 interval_work_init_all()
{
interval_work_init_generic();
interval_work_init_RS232C();
interval_work_init_TIMER_A();
return interval_work_init_TIMER_B();
}

canonical_decompiled_code:
__int64 func11()
{
func0();
func5();
func8();
return func10();
}

original_code:
void interval_work_init_all( void )
{
  interval_work_init_generic();
  interval_work_init_RS232C();
  interval_work_init_TIMER_A();
  interval_work_init_TIMER_B();
}

canonical_original_code:
void interval_work_init_all()
{
  interval_work_init_generic();
  interval_work_init_RS232C();
  interval_work_init_TIMER_A();
  interval_work_init_TIMER_B();
}