decompiled_code:
__int64 __fastcall new_socket(double a1)
{
int v1; // eax
_DWORD *v2; // rbp
__int64 v3; // rax
socklen_t len; // [rsp+8h] [rbp-20h] BYREF
socklen_t addr_len; // [rsp+Ch] [rbp-1Ch] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-18h] BYREF

len = 16;
getsockname(host, &addr, &len);
v1 = accept(host, &addr, &addr_len);
len = v1;
if ( v1 < 0 || fcntl(v1, 4, 2048LL) == -1 )
return 0LL;
v2 = (_DWORD *)socket_free;
if ( socket_free )
{
socket_free = *(_QWORD *)socket_free;
*(_QWORD *)v2 = 0LL;
}
else
{
v2 = calloc(0x2038uLL, 1uLL);
}
init_socket((__int64)v2);
v2[2060] = len;
v3 = socket_list;
if ( socket_list )
{
*(_QWORD *)(socket_list + 8) = v2;
*(_QWORD *)v2 = v3;
}
socket_list = (__int64)v2;
send_to((__int64)v2, welcome_message);
send_to((__int64)v2, "What is your name? ");
get_address((__int64)v2, (__int64)&addr, a1);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func6(double a1)
{
int v1; // eax
_DWORD *v2; // rbp
__int64 v3; // rax
socklen_t len; // [rsp+8h] [rbp-20h] BYREF
socklen_t addr_len; // [rsp+Ch] [rbp-1Ch] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-18h] BYREF

len = 16;
getsockname(host, &addr, &len);
v1 = accept(host, &addr, &addr_len);
len = v1;
if ( v1 < 0 || fcntl(v1, 4, 2048LL) == -1 )
return 0LL;
v2 = (_DWORD *)socket_free;
if ( socket_free )
{
socket_free = *(_QWORD *)socket_free;
*(_QWORD *)v2 = 0LL;
}
else
{
v2 = calloc(0x2038uLL, 1uLL);
}
func1((__int64)v2);
v2[2060] = len;
v3 = socket_list;
if ( socket_list )
{
*(_QWORD *)(socket_list + 8) = v2;
*(_QWORD *)v2 = v3;
}
socket_list = (__int64)v2;
func3((__int64)v2, welcome_message);
func3((__int64)v2, "What is your name? ");
func4((__int64)v2, (__int64)&addr, a1);
return 1LL;
}

original_code:
int new_socket(void) {
 SOCKET_T *sock = 0;
 int desc = sizeof(struct sockaddr_in);
 unsigned int len;
 struct sockaddr_in sockad;
 getsockname(host, (struct sockaddr*)&sockad, &desc);
 if((desc = accept(host, &sockad, &len)) < 0)
  return 0;
 if(fcntl(desc, 4, 04000) == -1)
  return 0;
 if( socket_free == 0 ) { sock = malloc(sizeof(*sock)); memset(sock,0,sizeof(*sock)); } else { sock = socket_free; socket_free = socket_free->next; sock->next = ((void *)0); };
 init_socket(sock);
 sock->desc = desc;
 if( socket_list != 0 ) { socket_list->prev = sock; sock->next = socket_list; socket_list = sock; } else { socket_list = sock; };
 send_to(sock, welcome_message);
 send_to(sock, "What is your name? ");
 get_address(sock,&sockad);
 return 1;
}

canonical_original_code:
int new_socket() {
 struct socket_t *sock = 0;
 int desc = sizeof(struct sockaddr_in);
 unsigned int len;
 struct sockaddr_in sockad;
 getsockname(host, (struct sockaddr *)&sockad, &desc);
 if((desc = accept(host, &sockad, &len)) < 0)
  return 0;
 if(fcntl(desc, 4, 04000) == -1)
  return 0;
 if( socket_free == 0 ) { sock = malloc(sizeof(*sock)); memset(sock,0,sizeof(*sock)); } else { sock = socket_free; socket_free = socket_free->next; sock->next = ((void *)0); };
 init_socket(sock);
 sock->desc = desc;
 if( socket_list != 0 ) { socket_list->prev = sock; sock->next = socket_list; socket_list = sock; } else { socket_list = sock; };
 send_to(sock, welcome_message);
 send_to(sock, "What is your name? ");
 get_address(sock,&sockad);
 return 1;
}

variable_types: desc int

variable_types:
len
unsigned int


decompiled_code:
__int64 __fastcall process_output(__int64 a1)
{
__int64 result; // rax
unsigned int i; // ebx
int v3; // eax
size_t v4; // rax

result = 1LL;
if ( *(_BYTE *)(a1 + 4120) )
{
for ( i = 0; ; i += v3 )
{
v4 = strlen((const char *)(a1 + 4120));
if ( i >= v4 )
{
*(_BYTE *)(a1 + 4120) = 0;
return 1LL;
}
v3 = write(*(_DWORD *)(a1 + 8240), (const void *)(a1 + i + 4120), (int)(v4 - i));
if ( v3 < 0 )
break;
}
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1)
{
__int64 result; // rax
unsigned int i; // ebx
int v3; // eax
size_t v4; // rax

result = 1LL;
if ( *(_BYTE *)(a1 + 4120) )
{
for ( i = 0; ; i += v3 )
{
v4 = strlen((const char *)(a1 + 4120));
if ( i >= v4 )
{
*(_BYTE *)(a1 + 4120) = 0;
return 1LL;
}
v3 = write(*(_DWORD *)(a1 + 8240), (const void *)(a1 + i + 4120), (int)(v4 - i));
if ( v3 < 0 )
break;
}
result = 0LL;
}
return result;
}

original_code:
int process_output(SOCKET_T *sock) {
 int i = 0;
 unsigned int total = 0;
 int block;
 if(sock->outbuf[0] == '\0')
  return 1;
 while(total < strlen(sock->outbuf))
 {
  block = strlen(sock->outbuf) - total;
  if((i = write(sock->desc, &sock->outbuf[total], block)) < 0)
   return 0;
  total += i;
 }
 sock->outbuf[0] = '\0';
 return 1;
}

canonical_original_code:
int process_output(struct socket_t *sock) {
 int i = 0;
 unsigned int total = 0;
 int block;
 if(sock->outbuf[0] == '\0')
  return 1;
 while(total < strlen(sock->outbuf))
 {
  block = strlen(sock->outbuf) - total;
  if((i = write(sock->desc, &sock->outbuf[total], block)) < 0)
   return 0;
  total += i;
 }
 sock->outbuf[0] = '\0';
 return 1;
}

variable_types: struct socket_t { struct socket_t *next; struct socket_t *prev; struct socket_t *reply; char inbuf[4096]; char outbuf[4096]; char *name; char *password; char *host; int desc; int connected; } *

variable_types: i int

variable_types:
total
unsigned int

variable_types: block int

return_type: int


original_code:
int process_input(SOCKET_T *sock) {
 unsigned int len = 0;
 unsigned int result;
 for(;;) {
  len += result = read(sock->desc, sock->inbuf + len, sizeof(sock->inbuf) - len - 10);
  if(sock->inbuf[len-1] == '\n' || sock->inbuf[len-1] == '\r') {
   sock->inbuf[len-1] = '\0';
   for( result = 0; result < strlen(sock->inbuf); result++ ) {
    if(sock->inbuf[result] == '\n' || sock->inbuf[result] == '\r')
     sock->inbuf[result] = '\0';
   }
   break;
  }
  else if(result <= 0) {
   return 0;
  }
 }
 nanny(sock,sock->inbuf);
 sock->inbuf[0] = '\0';
 return 1;
}

canonical_original_code:
int process_input(struct socket_t *sock) {
 unsigned int len = 0;
 unsigned int result;
 for(;;) {
  len += result = read(sock->desc, sock->inbuf + len, sizeof(sock->inbuf) - len - 10);
  if(sock->inbuf[len-1] == '\n' || sock->inbuf[len-1] == '\r') {
   sock->inbuf[len-1] = '\0';
   for( result = 0; result < strlen(sock->inbuf); result++ ) {
    if(sock->inbuf[result] == '\n' || sock->inbuf[result] == '\r')
     sock->inbuf[result] = '\0';
   }
   break;
  }
  else if(result <= 0) {
   return 0;
  }
 }
 nanny(sock,sock->inbuf);
 sock->inbuf[0] = '\0';
 return 1;
}

variable_types:
result
unsigned int

user_defined_types: struct socket_t { struct socket_t *next; struct socket_t *prev; struct socket_t *reply; char inbuf[4096]; char outbuf[4096]; char *name; char *password; char *host; int desc; int connected; }


decompiled_code:
__int64 __fastcall check_connections(double a1)
{
int v1; // er8
__int64 v2; // rsi
int v3; // ecx
int v4; // eax
__int64 v5; // rax
__int64 v6; // rdx
int v7; // er8
__int64 result; // rax
_QWORD *v9; // rbp
__int64 v10; // r12
int v11; // ecx
int v12; // eax
int v13; // eax
__int64 v14; // rdx
int v15; // edx
int v16; // eax

v1 = host;
memset(&fd_read, 0, sizeof(fd_read));
memset(&fd_write, 0, sizeof(fd_write));
memset(&fd_exc, 0, sizeof(fd_exc));
v2 = socket_list;
for ( fd_read.fds_bits[host / 64] |= 1LL << (host % 64); v2; fd_exc.fds_bits[v5] |= v6 )
{
v3 = *(_DWORD *)(v2 + 8240);
v2 = *(_QWORD *)v2;
v4 = v3 + 63;
if ( v1 < v3 )
v1 = v3;
if ( v3 >= 0 )
v4 = v3;
v5 = v4 >> 6;
v6 = 1LL << (v3 % 64);
fd_read.fds_bits[v5] |= v6;
fd_write.fds_bits[v5] |= v6;
}
v7 = select(v1 + 1, &fd_read, &fd_write, &fd_exc, 0LL);
result = 0LL;
if ( v7 >= 0 )
{
if ( (fd_read.fds_bits[host / 64] & (1LL << (host % 64))) != 0 )
new_socket(a1);
v9 = (_QWORD *)socket_list;
while ( v9 )
{
while ( 1 )
{
v10 = (__int64)v9;
v9 = (_QWORD *)*v9;
v11 = *(_DWORD *)(v10 + 8240);
v12 = v11 + 63;
if ( v11 >= 0 )
v12 = *(_DWORD *)(v10 + 8240);
v13 = v12 >> 6;
v14 = 1LL << (*(_DWORD *)(v10 + 8240) % 64);
if ( (fd_exc.fds_bits[v13] & v14) == 0 )
{
if ( (fd_read.fds_bits[v13] & v14) != 0 )
{
if ( !(unsigned int)process_input(v10) )
free_socket(v10);
v15 = *(_DWORD *)(v10 + 8240);
v16 = v15 + 63;
if ( v15 >= 0 )
v16 = *(_DWORD *)(v10 + 8240);
v13 = v16 >> 6;
v14 = 1LL << (*(_DWORD *)(v10 + 8240) % 64);
}
if ( (fd_write.fds_bits[v13] & v14) != 0 && !(unsigned int)process_output(v10) )
free_socket(v10);
if ( *(_DWORD *)(v10 + 8244) )
break;
}
free_socket(v10);
if ( !v9 )
goto LABEL_19;
}
}
LABEL_19:
result = 1LL;
}
return result;
}

original_code:
int check_connections(void) {
 SOCKET_T *sock;
 SOCKET_T *sock_next;
 int high = host;
 do { int __d0, __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&fd_read)->__fds_bits)[0]) : "memory"); } while (0);
 do { int __d0, __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&fd_write)->__fds_bits)[0]) : "memory"); } while (0);
 do { int __d0, __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&fd_exc)->__fds_bits)[0]) : "memory"); } while (0);
 ((void) (((&fd_read)->__fds_bits)[((host) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((host) % (8 * (int) sizeof (__fd_mask)))))));
 for(sock = socket_list; sock; sock = sock->next) {
  if(sock->desc > high)
   high = sock->desc;
  ((void) (((&fd_read)->__fds_bits)[((sock->desc) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((sock->desc) % (8 * (int) sizeof (__fd_mask)))))));
  ((void) (((&fd_write)->__fds_bits)[((sock->desc) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((sock->desc) % (8 * (int) sizeof (__fd_mask)))))));
  ((void) (((&fd_exc)->__fds_bits)[((sock->desc) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((sock->desc) % (8 * (int) sizeof (__fd_mask)))))));
 }
 if(select(high+1, &fd_read, &fd_write, &fd_exc, 0) < 0)
  return 0;
 if(((((&fd_read)->__fds_bits)[((host) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((host) % (8 * (int) sizeof (__fd_mask)))))) != 0))
  new_socket();
 for(sock = socket_list; sock; sock = sock_next) {
  sock_next = sock->next;
  if(((((&fd_exc)->__fds_bits)[((sock->desc) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((sock->desc) % (8 * (int) sizeof (__fd_mask)))))) != 0)) {
   free_socket(sock);
   continue;
  }
  if(((((&fd_read)->__fds_bits)[((sock->desc) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((sock->desc) % (8 * (int) sizeof (__fd_mask)))))) != 0)) {
   if(!process_input(sock))
    free_socket(sock);
  }
  if(((((&fd_write)->__fds_bits)[((sock->desc) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((sock->desc) % (8 * (int) sizeof (__fd_mask)))))) != 0)) {
   if(!process_output(sock))
    free_socket(sock);
  }
  if(sock->connected == 0) {
   free_socket(sock);
   continue;
  }
 }
 return 1;
}

canonical_original_code:
int check_connections() {
 struct socket_t *sock;
 struct socket_t *sock_next;
 int high = host;
 do { int __d0; int __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&fd_read)->__fds_bits)[0]) : "memory"); } while (0);
 do { int __d0; int __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&fd_write)->__fds_bits)[0]) : "memory"); } while (0);
 do { int __d0; int __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&fd_exc)->__fds_bits)[0]) : "memory"); } while (0);
 ((void) (((&fd_read)->__fds_bits)[((host) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((host) % (8 * (int) sizeof (__fd_mask)))))));
 for(sock = socket_list; sock; sock = sock->next) {
  if(sock->desc > high)
   high = sock->desc;
  ((void) (((&fd_read)->__fds_bits)[((sock->desc) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((sock->desc) % (8 * (int) sizeof (__fd_mask)))))));
  ((void) (((&fd_write)->__fds_bits)[((sock->desc) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((sock->desc) % (8 * (int) sizeof (__fd_mask)))))));
  ((void) (((&fd_exc)->__fds_bits)[((sock->desc) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((sock->desc) % (8 * (int) sizeof (__fd_mask)))))));
 }
 if(select(high+1, &fd_read, &fd_write, &fd_exc, 0) < 0)
  return 0;
 if(((((&fd_read)->__fds_bits)[((host) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((host) % (8 * (int) sizeof (__fd_mask)))))) != 0))
  new_socket();
 for(sock = socket_list; sock; sock = sock_next) {
  sock_next = sock->next;
  if(((((&fd_exc)->__fds_bits)[((sock->desc) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((sock->desc) % (8 * (int) sizeof (__fd_mask)))))) != 0)) {
   free_socket(sock);
   continue;
  }
  if(((((&fd_read)->__fds_bits)[((sock->desc) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((sock->desc) % (8 * (int) sizeof (__fd_mask)))))) != 0)) {
   if(!process_input(sock))
    free_socket(sock);
  }
  if(((((&fd_write)->__fds_bits)[((sock->desc) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((sock->desc) % (8 * (int) sizeof (__fd_mask)))))) != 0)) {
   if(!process_output(sock))
    free_socket(sock);
  }
  if(sock->connected == 0) {
   free_socket(sock);
   continue;
  }
 }
 return 1;
}

variable_types: high int


decompiled_code:
char *__fastcall strip_argument(char *a1, char *a2)
{
const unsigned __int16 **v4; // rax
const unsigned __int16 *v5; // rsi
const unsigned __int16 **v6; // rdi
char *result; // rax
__int64 v8; // rcx
char v9; // dl
char v10; // cl
__int64 v11; // rdx

v4 = _ctype_b_loc();
v5 = *v4;
v6 = v4;
for ( result = a1; ; ++result )
{
v8 = *result;
v9 = *result;
if ( (v5[v8] & 0x2000) == 0 )
break;
}
if ( (_BYTE)v8 == 39 || (v10 = 32, v9 == 34) )
{
v10 = *result++;
v9 = *result;
}
if ( v9 )
{
do
{
++result;
if ( v10 == v9 )
break;
*a2 = v9;
v9 = *result;
++a2;
}
while ( *result );
}
*a2 = 0;
if ( ((*v6)[*result] & 0x2000) != 0 )
{
do
v11 = *++result;
while ( ((*v6)[v11] & 0x2000) != 0 );
}
return result;
}

canonical_decompiled_code:
char *__fastcall func0(char *a1, char *a2)
{
const unsigned __int16 **v4; // rax
const unsigned __int16 *v5; // rsi
const unsigned __int16 **v6; // rdi
char *result; // rax
__int64 v8; // rcx
char v9; // dl
char v10; // cl
__int64 v11; // rdx

v4 = _ctype_b_loc();
v5 = *v4;
v6 = v4;
for ( result = a1; ; ++result )
{
v8 = *result;
v9 = *result;
if ( (v5[v8] & 0x2000) == 0 )
break;
}
if ( (_BYTE)v8 == 39 || (v10 = 32, v9 == 34) )
{
v10 = *result++;
v9 = *result;
}
if ( v9 )
{
do
{
++result;
if ( v10 == v9 )
break;
*a2 = v9;
v9 = *result;
++a2;
}
while ( *result );
}
*a2 = 0;
if ( ((*v6)[*result] & 0x2000) != 0 )
{
do
v11 = *++result;
while ( ((*v6)[v11] & 0x2000) != 0 );
}
return result;
}

original_code:
char *strip_argument(char *argument, char *arg_first) {
 char deli;
 while( ((*__ctype_b_loc ())[(int) ((*argument))] & (unsigned short int) _ISspace) )
  argument++;
 deli = ' ';
 if( *argument == '\'' || *argument == '"' )
  deli = *argument++;
 while( *argument != '\0' ) {
  if(*argument == deli) {
   argument++;
   break;
  }
  *arg_first = *argument;
  arg_first++;
  argument++;
 }
 *arg_first = '\0';
 while(((*__ctype_b_loc ())[(int) ((*argument))] & (unsigned short int) _ISspace))
  argument++;
 return argument;
}

canonical_original_code:
char *strip_argument(char *argument, char *arg_first) {
 char deli;
 while( ((*__ctype_b_loc ())[(int) ((*argument))] & (unsigned short) _ISspace) )
  argument++;
 deli = ' ';
 if( *argument == '\'' || *argument == '"' )
  deli = *argument++;
 while( *argument != '\0' ) {
  if(*argument == deli) {
   argument++;
   break;
  }
  *arg_first = *argument;
  arg_first++;
  argument++;
 }
 *arg_first = '\0';
 while(((*__ctype_b_loc ())[(int) ((*argument))] & (unsigned short) _ISspace))
  argument++;
 return argument;
}

variable_types:
argument
char *

variable_types: deli char

return_type: char *


mudsleep

decompiled_code:
int __fastcall mudsleep(int a1)
{
int result; // eax
struct timeval v2; // [rsp+0h] [rbp-18h] BYREF

v2.tv_sec = a1;
v2.tv_usec = 0LL;
result = select(0, 0LL, 0LL, 0LL, &v2);
if ( result < 0 )
{
perror("mudsleep: select is not responding");
exit(1);
}
return result;
}

canonical_decompiled_code:
int __fastcall func0(int a1)
{
int result; // eax
struct timeval v2; // [rsp+0h] [rbp-18h] BYREF

v2.tv_sec = a1;
v2.tv_usec = 0LL;
result = select(0, 0LL, 0LL, 0LL, &v2);
if ( result < 0 )
{
perror("mudsleep: select is not responding");
exit(1);
}
return result;
}

original_code:
void mudsleep(int seconds)
{
 struct timeval wait_time;
 wait_time.tv_usec = 0;
 wait_time.tv_sec = seconds;
 if(select(0, 0, 0, 0, &wait_time) < 0) {
  perror("mudsleep: select is not responding");
  exit(1);
 }
}

variable_types: seconds int

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

return_type: void


log

decompiled_code:
void __fastcall log(double x, const char *a2)
{
char *v2; // r12

v2 = ctime(&current_time);
v2[strlen(v2) - 1] = 0;
fprintf(stderr, "%s :: %s\n", v2, a2);
}

canonical_decompiled_code:
void __fastcall func0(double x, const char *a2)
{
char *v2; // r12

v2 = ctime(&current_time);
v2[strlen(v2) - 1] = 0;
fprintf(stderr, "%s :: %s\n", v2, a2);
}

original_code:
void log( const char *str ) {
 char *logstr;
 logstr = ctime( &current_time );
 logstr[strlen(logstr)-1] = '\0';
 fprintf( stderr, "%s :: %s\n", logstr, str );
}

canonical_original_code:
void log(char *str) {
 char *logstr;
 logstr = ctime( &current_time );
 logstr[strlen(logstr)-1] = '\0';
 fprintf( stderr, "%s :: %s\n", logstr, str );
}

variable_types:
str
char *

variable_types:
logstr
char *


chatroom

decompiled_code:
int __fastcall chatroom(__int64 a1, const char *a2)
{
int result; // eax
__int64 *v3; // rbx
const char *v4; // r13
__int64 v5; // rax
__int64 **v6; // rbx
size_t v7; // rax
__int64 *v8; // rbx
const char *v9; // r13
__int64 *v10; // rbx
char v11[4096]; // [rsp+0h] [rbp-2028h] BYREF
char s2; // [rsp+1000h] [rbp-1028h] BYREF
char s1[4135]; // [rsp+1001h] [rbp-1027h] BYREF

if ( *a2 == 47 )
{
v4 = (const char *)strip_argument(a2, &s2);
if ( !strcasecmp(s1, "who") )
{
v6 = (__int64 **)socket_list;
v11[0] = 0;
if ( socket_list )
{
do
{
v7 = strlen(v11);
sprintf(&v11[v7], "%-12s\n\r", (const char *)v6[1027]);
v6 = (__int64 **)*v6;
}
while ( v6 );
}
result = send_to(a1, v11);
}
else if ( !strcasecmp(s1, "quit") )
{
result = send_to(a1, "Okay, press enter.\n\r");
*(_DWORD *)(a1 + 8244) = 7;
}
else if ( !strcasecmp(s1, "emote") )
{
result = sprintf(v11, "@%s %s\n\r", *(const char **)(a1 + 8216), v4);
v8 = (__int64 *)socket_list;
if ( socket_list )
{
do
{
if ( *((_DWORD *)v8 + 2061) == 8 )
result = send_to(v8, v11);
v8 = (__int64 *)*v8;
}
while ( v8 );
}
}
else if ( !strcasecmp(s1, "tell") )
{
v9 = (const char *)strip_argument(v4, &s2);
sprintf(v11, "You tell %s> %s\n\r", *(const char **)(a1 + 8216), v9);
send_to(a1, v11);
result = sprintf(v11, "%s tells you> %s\n\r", *(const char **)(a1 + 8216), v9);
v10 = (__int64 *)socket_list;
if ( socket_list )
{
while ( 1 )
{
if ( *((_DWORD *)v10 + 2061) == 8 )
{
result = strcasecmp((const char *)v10[1027], &s2);
if ( !result )
break;
}
v10 = (__int64 *)*v10;
if ( !v10 )
return result;
}
result = send_to(v10, v11);
v10[2] = a1;
}
}
else if ( !strcasecmp(s1, "reply") )
{
v5 = *(_QWORD *)(a1 + 16);
if ( v5 && *(_DWORD *)(v5 + 8244) == 8 )
{
sprintf(v11, "You reply to %s> %s\n\r", *(const char **)(v5 + 8216), v4);
send_to(a1, v11);
sprintf(v11, "%s replies> %s\n\r", *(const char **)(a1 + 8216), v4);
result = send_to(*(_QWORD *)(a1 + 16), v11);
}
else
{
result = send_to(a1, "They aren't here.\n\r");
}
}
else
{
result = send_to(a1, "Invalid command.\n\r");
}
}
else
{
result = sprintf(v11, "%s> %s\n\r", *(const char **)(a1 + 8216), a2);
v3 = (__int64 *)socket_list;
if ( socket_list )
{
do
{
while ( *((_DWORD *)v3 + 2061) != 8 )
{
v3 = (__int64 *)*v3;
if ( !v3 )
return result;
}
result = send_to(v3, v11);
v3 = (__int64 *)*v3;
}
while ( v3 );
}
}
return result;
}

canonical_decompiled_code:
int __fastcall func0(__int64 a1, const char *a2)
{
int result; // eax
__int64 *v3; // rbx
const char *v4; // r13
__int64 v5; // rax
__int64 **v6; // rbx
size_t v7; // rax
__int64 *v8; // rbx
const char *v9; // r13
__int64 *v10; // rbx
char v11[4096]; // [rsp+0h] [rbp-2028h] BYREF
char s2; // [rsp+1000h] [rbp-1028h] BYREF
char s1[4135]; // [rsp+1001h] [rbp-1027h] BYREF

if ( *a2 == 47 )
{
v4 = (const char *)strip_argument(a2, &s2);
if ( !strcasecmp(s1, "who") )
{
v6 = (__int64 **)socket_list;
v11[0] = 0;
if ( socket_list )
{
do
{
v7 = strlen(v11);
sprintf(&v11[v7], "%-12s\n\r", (const char *)v6[1027]);
v6 = (__int64 **)*v6;
}
while ( v6 );
}
result = send_to(a1, v11);
}
else if ( !strcasecmp(s1, "quit") )
{
result = send_to(a1, "Okay, press enter.\n\r");
*(_DWORD *)(a1 + 8244) = 7;
}
else if ( !strcasecmp(s1, "emote") )
{
result = sprintf(v11, "@%s %s\n\r", *(const char **)(a1 + 8216), v4);
v8 = (__int64 *)socket_list;
if ( socket_list )
{
do
{
if ( *((_DWORD *)v8 + 2061) == 8 )
result = send_to(v8, v11);
v8 = (__int64 *)*v8;
}
while ( v8 );
}
}
else if ( !strcasecmp(s1, "tell") )
{
v9 = (const char *)strip_argument(v4, &s2);
sprintf(v11, "You tell %s> %s\n\r", *(const char **)(a1 + 8216), v9);
send_to(a1, v11);
result = sprintf(v11, "%s tells you> %s\n\r", *(const char **)(a1 + 8216), v9);
v10 = (__int64 *)socket_list;
if ( socket_list )
{
while ( 1 )
{
if ( *((_DWORD *)v10 + 2061) == 8 )
{
result = strcasecmp((const char *)v10[1027], &s2);
if ( !result )
break;
}
v10 = (__int64 *)*v10;
if ( !v10 )
return result;
}
result = send_to(v10, v11);
v10[2] = a1;
}
}
else if ( !strcasecmp(s1, "reply") )
{
v5 = *(_QWORD *)(a1 + 16);
if ( v5 && *(_DWORD *)(v5 + 8244) == 8 )
{
sprintf(v11, "You reply to %s> %s\n\r", *(const char **)(v5 + 8216), v4);
send_to(a1, v11);
sprintf(v11, "%s replies> %s\n\r", *(const char **)(a1 + 8216), v4);
result = send_to(*(_QWORD *)(a1 + 16), v11);
}
else
{
result = send_to(a1, "They aren't here.\n\r");
}
}
else
{
result = send_to(a1, "Invalid command.\n\r");
}
}
else
{
result = sprintf(v11, "%s> %s\n\r", *(const char **)(a1 + 8216), a2);
v3 = (__int64 *)socket_list;
if ( socket_list )
{
do
{
while ( *((_DWORD *)v3 + 2061) != 8 )
{
v3 = (__int64 *)*v3;
if ( !v3 )
return result;
}
result = send_to(v3, v11);
v3 = (__int64 *)*v3;
}
while ( v3 );
}
}
return result;
}

original_code:
void chatroom(SOCKET_T *sock, char *argument) {
 char buf[4096];
 char arg[4096];
 SOCKET_T *slist;
 if(argument[0] == '/') {
  argument = strip_argument(argument,arg);
  if(!strcasecmp(arg+1,"who")) {
   buf[0] = '\0';
   for(slist = socket_list; slist; slist = slist->next) {
    sprintf(buf+strlen(buf),"%-12s\n\r", slist->name );
   }
   send_to(sock,buf);
   return;
  }
  if(!strcasecmp(arg+1,"quit")) {
   send_to(sock,"Okay, press enter.\n\r");
   sock->connected = 7;
   return;
  }
  if(!strcasecmp(arg+1,"emote")) {
   sprintf(buf,"@%s %s\n\r",sock->name,argument);
   for(slist = socket_list; slist; slist = slist->next) {
    if(slist->connected == 8)
     send_to(slist,buf);
   }
   return;
  }
  if(!strcasecmp(arg+1,"tell")) {
   argument = strip_argument(argument,arg);
   sprintf(buf,"You tell %s> %s\n\r",sock->name,argument);
   send_to(sock,buf);
   sprintf(buf,"%s tells you> %s\n\r",sock->name,argument);
   for(slist = socket_list; slist; slist = slist->next) {
    if(slist->connected == 8 && !strcasecmp(slist->name,arg) ) {
     send_to(slist,buf);
     slist->reply = sock;
     break;
    }
   }
   return;
  }
  if(!strcasecmp(arg+1,"reply")) {
   if( !sock->reply || sock->reply->connected != 8 ) {
    send_to(sock,"They aren't here.\n\r");
    return;
   }
   sprintf(buf,"You reply to %s> %s\n\r",sock->reply->name,argument);
   send_to(sock,buf);
   sprintf(buf,"%s replies> %s\n\r",sock->name,argument);
   send_to(sock->reply,buf);
   return;
  }
  send_to(sock,"Invalid command.\n\r");
  return;
 }
 sprintf(buf,"%s> %s\n\r",sock->name,argument);
 for(slist = socket_list; slist; slist = slist->next) {
  if(slist->connected == 8)
   send_to(slist,buf);
 }
 return;
}

canonical_original_code:
void chatroom(struct socket_t *sock, char *argument) {
 char buf[4096];
 char arg[4096];
 struct socket_t *slist;
 if(argument[0] == '/') {
  argument = strip_argument(argument,arg);
  if(!strcasecmp(arg+1,"who")) {
   buf[0] = '\0';
   for(slist = socket_list; slist; slist = slist->next) {
    sprintf(buf+strlen(buf),"%-12s\n\r", slist->name );
   }
   send_to(sock,buf);
   return;
  }
  if(!strcasecmp(arg+1,"quit")) {
   send_to(sock,"Okay, press enter.\n\r");
   sock->connected = 7;
   return;
  }
  if(!strcasecmp(arg+1,"emote")) {
   sprintf(buf,"@%s %s\n\r",sock->name,argument);
   for(slist = socket_list; slist; slist = slist->next) {
    if(slist->connected == 8)
     send_to(slist,buf);
   }
   return;
  }
  if(!strcasecmp(arg+1,"tell")) {
   argument = strip_argument(argument,arg);
   sprintf(buf,"You tell %s> %s\n\r",sock->name,argument);
   send_to(sock,buf);
   sprintf(buf,"%s tells you> %s\n\r",sock->name,argument);
   for(slist = socket_list; slist; slist = slist->next) {
    if(slist->connected == 8 && !strcasecmp(slist->name,arg) ) {
     send_to(slist,buf);
     slist->reply = sock;
     break;
    }
   }
   return;
  }
  if(!strcasecmp(arg+1,"reply")) {
   if( !sock->reply || sock->reply->connected != 8 ) {
    send_to(sock,"They aren't here.\n\r");
    return;
   }
   sprintf(buf,"You reply to %s> %s\n\r",sock->reply->name,argument);
   send_to(sock,buf);
   sprintf(buf,"%s replies> %s\n\r",sock->name,argument);
   send_to(sock->reply,buf);
   return;
  }
  send_to(sock,"Invalid command.\n\r");
  return;
 }
 sprintf(buf,"%s> %s\n\r",sock->name,argument);
 for(slist = socket_list; slist; slist = slist->next) {
  if(slist->connected == 8)
   send_to(slist,buf);
 }
 return;
}

variable_types:
buf
char [4096]

variable_types:
arg
char [4096]


main

canonical_name: main

repo: apaznikov/qdmd

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
if ( argc == 3 )
{
md_initialize(argv[1], argv[2], envp);
}
else if ( argc == 2 )
{
md_initialize(argv[1], "md.input", envp);
}
else
{
md_initialize("mdf.cls", "md.input", envp);
}
md_run();
md_finalize();
return 0;
}

original_code:
int main(int argc, char **argv)
{
    if (argc == 3) {
        md_initialize(argv[1], argv[2]);
    } else if (argc == 2) {
        md_initialize(argv[1], "md.input");
    } else {
        md_initialize("mdf.cls", "md.input");
    }
    md_run();
    md_finalize();
    return 0;
}

variable_types: argc int

variable_types:
argv
char **


decompiled_code:
_BOOL8 __fastcall t1_iszero(double a1)
{
return a1 > 0.000001;
}

canonical_decompiled_code:
_BOOL8 __fastcall func0(double a1)
{
return a1 > 0.000001;
}

original_code:
static inline int t1_iszero(double x)
{
    return x > 1e-6;
}

variable_types: x double


decompiled_code:
void __fastcall t1_distance(int a1, int a2)
{
double v2; // xmm0_8
double v3; // xmm1_8
double v4; // xmm2_8
double v5; // xmm0_8

v2 = *(double *)(x + 8LL * a1) - *(double *)(x + 8LL * a2);
v3 = *(double *)(y + 8LL * a1) - *(double *)(y + 8LL * a2);
v4 = *(double *)(z + 8LL * a1) - *(double *)(z + 8LL * a2);
v5 = v2 * v2 + v3 * v3 + v4 * v4;
if ( v5 < 0.0 )
sqrt(v5);
}

canonical_decompiled_code:
void __fastcall func1(int a1, int a2)
{
double v2; // xmm0_8
double v3; // xmm1_8
double v4; // xmm2_8
double v5; // xmm0_8

v2 = *(double *)(x + 8LL * a1) - *(double *)(x + 8LL * a2);
v3 = *(double *)(y + 8LL * a1) - *(double *)(y + 8LL * a2);
v4 = *(double *)(z + 8LL * a1) - *(double *)(z + 8LL * a2);
v5 = v2 * v2 + v3 * v3 + v4 * v4;
if ( v5 < 0.0 )
sqrt(v5);
}

original_code:
static inline double t1_distance(int i, int j)
{
    return sqrt(pow(x[i] - x[j], 2) +
                pow(y[i] - y[j], 2) +
                pow(z[i] - z[j], 2));
}

variable_types: j int

return_type: double


original_code:
inline double t1_eta(int i, int j, double rij)
{
    double rik, f_cutoff_val, sum = 0;
    int k;
    for (k = 0; k < natoms; k++) {
        if ((k != i) && (k != j)) {
            rik = t1_distance(i, k);
            f_cutoff_val = t1_f_cutoff(rik);
            if (f_cutoff_val > 1e-6) {
                sum += f_cutoff_val * exp(pow(1.3258, 3) *
                                          pow(rij - rik, 3));
            }
        }
    }
    return sum;
}

canonical_original_code:
inline double t1_eta(int i, int j, double rij)
{
    double rik; double f_cutoff_val; double sum = 0;
    int k;
    for (k = 0; k < natoms; k++) {
        if ((k != i) && (k != j)) {
            rik = t1_distance(i, k);
            f_cutoff_val = t1_f_cutoff(rik);
            if (f_cutoff_val > 1e-6) {
                sum += f_cutoff_val * exp(pow(1.3258, 3) *
                                          pow(rij - rik, 3));
            }
        }
    }
    return sum;
}

variable_types: i int

variable_types: rij double

variable_types: rik double

variable_types: sum double

variable_types: k int


original_code:
inline double t1_zeta(int i, int j, double rij)
{
    double rik, f_cutoff_val, sum = 0;
    int k;
    for (k = 0; k < natoms; k++) {
        if ((k != i) && (k != j)) {
            rik = t1_distance(i, k);
            f_cutoff_val = t1_f_cutoff(rik);
            if (f_cutoff_val > 1e-6) {
                sum += f_cutoff_val * t1_g(i, j, k) * exp(pow(1.3258, 3) *
                                                      pow(rij - rik, 3));
            }
        }
    }
    return sum;
}

canonical_original_code:
inline double t1_zeta(int i, int j, double rij)
{
    double rik; double f_cutoff_val; double sum = 0;
    int k;
    for (k = 0; k < natoms; k++) {
        if ((k != i) && (k != j)) {
            rik = t1_distance(i, k);
            f_cutoff_val = t1_f_cutoff(rik);
            if (f_cutoff_val > 1e-6) {
                sum += f_cutoff_val * t1_g(i, j, k) * exp(pow(1.3258, 3) *
                                                      pow(rij - rik, 3));
            }
        }
    }
    return sum;
}


decompiled_code:
void __fastcall tersoff1_forces(double a1)
{
int v1; // er13
void *v2; // rbp
_QWORD *v3; // rdi
__int64 v4; // r12
void *v5; // r14
int v6; // er12
int v7; // ebp
int v8; // ebx
int v9; // esi
__int64 v10; // rax
double v11; // [rsp+8h] [rbp-30h]

v1 = natoms;
if ( natoms > 0 )
{
v2 = ay;
v3 = s;
v4 = 8LL * natoms;
v5 = az;
if ( (s >= (char *)az + v4 || az >= (char *)s + v4)
&& (ay >= (char *)s + v4 || s >= (char *)ay + v4)
&& (ay >= (char *)az + v4 || az >= (char *)ay + v4) )
{
memset(s, 0, 8LL * natoms);
memset(v5, 0, 8LL * v1);
memset(v2, 0, 8LL * v1);
}
else
{
v10 = 0LL;
do
{
v3[v10] = 0LL;
*((_QWORD *)v2 + v10) = 0LL;
*((_QWORD *)v5 + v10++) = 0LL;
}
while ( v1 != v10 );
}
if ( v1 > 1 )
{
v6 = 0;
do
{
v7 = v6++;
if ( v6 < v1 )
{
v8 = v6;
do
{
while ( 1 )
{
t1_distance(v7, v8);
v11 = a1;
a1 = t1_f_cutoff(a1);
if ( !t1_iszero(a1) )
break;
v1 = natoms;
if ( natoms <= ++v8 )
goto LABEL_12;
}
t1_a_isra_0(v7, v8, v11);
t1_f_repulsive_isra_0(v11);
v9 = v8++;
t1_b_isra_0(v7, v9, v11);
a1 = v11;
t1_f_attractive_isra_0(v11);
v1 = natoms;
}
while ( natoms > v8 );
}
LABEL_12:
;
}
while ( v1 - 1 > v6 );
}
}
}

original_code:
void tersoff1_forces()
{
    int i, j;
    double rij;
    double Uij;
    double U = 0;
    double f_cutoff_val;
    for (i = 0; i < natoms; i++) {
        ax[i] = 0.0;
        ay[i] = 0.0;
        az[i] = 0.0;
    }
    for (i = 0; i < natoms - 1; i++) {
        for (j = i + 1; j < natoms; j++) {
            rij = t1_distance(i, j);
            f_cutoff_val = t1_f_cutoff(rij);
            if (!t1_iszero(f_cutoff_val)) {
                Uij = f_cutoff_val * (t1_a(i, j, rij) * t1_f_repulsive(rij) +
                                      t1_b(i, j, rij) * t1_f_attractive(rij));
                U += Uij;
            }
        }
    }
}

canonical_original_code:
void tersoff1_forces()
{
    int i; int j;
    double rij;
    double Uij;
    double U = 0;
    double f_cutoff_val;
    for (i = 0; i < natoms; i++) {
        ax[i] = 0.0;
        ay[i] = 0.0;
        az[i] = 0.0;
    }
    for (i = 0; i < natoms - 1; i++) {
        for (j = i + 1; j < natoms; j++) {
            rij = t1_distance(i, j);
            f_cutoff_val = t1_f_cutoff(rij);
            if (!t1_iszero(f_cutoff_val)) {
                Uij = f_cutoff_val * (t1_a(i, j, rij) * t1_f_repulsive(rij) +
                                      t1_b(i, j, rij) * t1_f_attractive(rij));
                U += Uij;
            }
        }
    }
}

variable_types: Uij double

variable_types: U double


decompiled_code:
_BOOL8 __fastcall kronecker_delta(int a1, int a2)
{
return a1 == a2;
}

canonical_decompiled_code:
_BOOL8 __fastcall func0(int a1, int a2)
{
return a1 == a2;
}

original_code:
static int kronecker_delta(int i, int j)
{
    return i == j ? 1 : 0;
}


getcoord

decompiled_code:
double __fastcall getcoord(int a1, int a2)
{
if ( a2 == 1 )
return *(double *)(y + 8LL * a1);
if ( a2 == 2 )
return *(double *)(z + 8LL * a1);
return *(double *)(x + 8LL * a1);
}

canonical_decompiled_code:
double __fastcall func1(int a1, int a2)
{
if ( a2 == 1 )
return *(double *)(y + 8LL * a1);
if ( a2 == 2 )
return *(double *)(z + 8LL * a1);
return *(double *)(x + 8LL * a1);
}

original_code:
static double getcoord(int i, coord_t coord)
{
    switch(coord) {
        case COORD_X:
            return x[i];
            break;
        case COORD_Y:
            return y[i];
            break;
        case COORD_Z:
            return z[i];
            break;
    }
    return 0;
}

canonical_original_code:
static double getcoord(int i, enum coord_t coord)
{
    switch(coord) {
        case COORD_X:
            return x[i];
            break;
        case COORD_Y:
            return y[i];
            break;
        case COORD_Z:
            return z[i];
            break;
    }
    return 0;
}

variable_types: enum coord_t { COORD_X=0, COORD_Y=1, COORD_Z=2 }


decompiled_code:
double __fastcall rij_diff(int a1, int a2, int a3, int a4, double a5)
{
double result; // xmm0_8
double v9; // xmm0_8
int v10; // er8
int v11; // edi
double v12; // xmm1_8
double v13; // xmm0_8
int v14; // edx

if ( a1 == a2 )
{
v13 = getcoord(a1, a4);
v11 = v14;
v12 = v13;
}
else
{
result = 0.0;
if ( a1 != a3 )
return result;
v9 = getcoord(a1, a4);
v11 = v10;
v12 = v9;
}
return (v12 - getcoord(v11, a4)) / a5;
}

canonical_decompiled_code:
double __fastcall func2(int a1, int a2, int a3, int a4, double a5)
{
double result; // xmm0_8
double v9; // xmm0_8
int v10; // er8
int v11; // edi
double v12; // xmm1_8
double v13; // xmm0_8
int v14; // edx

if ( a1 == a2 )
{
v13 = func1(a1, a4);
v11 = v14;
v12 = v13;
}
else
{
result = 0.0;
if ( a1 != a3 )
return result;
v9 = func1(a1, a4);
v11 = v10;
v12 = v9;
}
return (v12 - func1(v11, a4)) / a5;
}

original_code:
static double rij_diff(int z, int i, int j, double rij, coord_t coord)
{
    if (z == i) {
        return (getcoord(i, coord) - getcoord(j, coord)) / rij;
    } else if (z == j) {
        return (getcoord(j, coord) - getcoord(i, coord)) / rij;
    } else {
        return 0;
    }
}

canonical_original_code:
static double rij_diff(int z, int i, int j, double rij, enum coord_t coord)
{
    if (z == i) {
        return (getcoord(i, coord) - getcoord(j, coord)) / rij;
    } else if (z == j) {
        return (getcoord(j, coord) - getcoord(i, coord)) / rij;
    } else {
        return 0;
    }
}

variable_types: z int

user_defined_types: enum coord_t { COORD_X=0, COORD_Y=1, COORD_Z=2 }


decompiled_code:
double __fastcall f_repulsive_diff(int a1, unsigned int a2, unsigned int a3, int a4, double a5)
{
double v7; // xmm0_8
double v8; // xmm3_8
double v11; // [rsp+8h] [rbp-30h]
double v12; // [rsp+8h] [rbp-30h]

v11 = lambda_ij(a2, a3);
v12 = v11 * Bij(a2, a3);
v7 = lambda_ij(a2, a3);
v8 = v12 * exp(COERCE_DOUBLE(*(_QWORD *)&v7 ^ LC1) * a5);
return rij_diff(a1, a2, a3, a4, a5) * v8;
}

canonical_decompiled_code:
double __fastcall func3(int a1, unsigned int a2, unsigned int a3, int a4, double a5)
{
double v7; // xmm0_8
double v8; // xmm3_8
double v11; // [rsp+8h] [rbp-30h]
double v12; // [rsp+8h] [rbp-30h]

v11 = lambda_ij(a2, a3);
v12 = v11 * Bij(a2, a3);
v7 = lambda_ij(a2, a3);
v8 = v12 * exp(COERCE_DOUBLE(*(_QWORD *)&v7 ^ LC1) * a5);
return func2(a1, a2, a3, a4, a5) * v8;
}

original_code:
static double f_repulsive_diff(int z, int i, int j, double rij, coord_t coord)
{
    return -lambda_ij(i, j) * -Bij(i, j) * exp(-lambda_ij(i, j) * rij) *
            rij_diff(z, i, j, rij, coord);
}

canonical_original_code:
static double f_repulsive_diff(int z, int i, int j, double rij, enum coord_t coord)
{
    return -lambda_ij(i, j) * -Bij(i, j) * exp(-lambda_ij(i, j) * rij) *
            rij_diff(z, i, j, rij, coord);
}


decompiled_code:
double __fastcall g_diff(unsigned int a1, unsigned int a2, unsigned int a3, unsigned int a4, int a5, double a6, double a7)
{
double v10; // xmm0_8
double v11; // xmm0_8
double v13; // [rsp+8h] [rbp-60h]
double v14; // [rsp+10h] [rbp-58h]
double v15; // [rsp+18h] [rbp-50h]
double v16; // [rsp+20h] [rbp-48h]
double v17; // [rsp+28h] [rbp-40h]

v17 = c(a2);
v16 = h(a2);
v13 = t2_cos_theta(a2);
v10 = d(a2, a3);
v14 = v10 * v10;
v15 = h(a2);
v11 = t2_cos_theta(a2);
return COERCE_DOUBLE(cos_theta_diff(a6, a7, a1, a2, a3, a4, a5))
* (COERCE_DOUBLE(COERCE_UNSIGNED_INT64((v17 * v17 + v17 * v17) * (v16 - v13)) ^ LC1)
/ (((v15 - v11) * (v15 - v11) + v14)
* ((v15 - v11) * (v15 - v11) + v14)));
}

canonical_decompiled_code:
double __fastcall func4(unsigned int a1, unsigned int a2, unsigned int a3, unsigned int a4, int a5, double a6, double a7)
{
double v10; // xmm0_8
double v11; // xmm0_8
double v13; // [rsp+8h] [rbp-60h]
double v14; // [rsp+10h] [rbp-58h]
double v15; // [rsp+18h] [rbp-50h]
double v16; // [rsp+20h] [rbp-48h]
double v17; // [rsp+28h] [rbp-40h]

v17 = c(a2);
v16 = h(a2);
v13 = t2_cos_theta(a2);
v10 = d(a2, a3);
v14 = v10 * v10;
v15 = h(a2);
v11 = t2_cos_theta(a2);
return COERCE_DOUBLE(cos_theta_diff(a6, a7, a1, a2, a3, a4, a5))
* (COERCE_DOUBLE(COERCE_UNSIGNED_INT64((v17 * v17 + v17 * v17) * (v16 - v13)) ^ LC1)
/ (((v15 - v11) * (v15 - v11) + v14)
* ((v15 - v11) * (v15 - v11) + v14)));
}

original_code:
static double g_diff(int z, int i, int j, int k,
                     double rij, double rik, coord_t coord)
{
    return -(2 * pow(c(i), 2) * (h(i) - t2_cos_theta(i, j, k))) /
            pow(pow(d(i), 2) +
                pow(h(i) - t2_cos_theta(i, j, k), 2), 2) *
            cos_theta_diff(z, i, j, k, rij, rik, coord);
}

canonical_original_code:
static double g_diff(int z, int i, int j, int k, double rij, double rik, enum coord_t coord)
{
    return -(2 * pow(c(i), 2) * (h(i) - t2_cos_theta(i, j, k))) /
            pow(pow(d(i), 2) +
                pow(h(i) - t2_cos_theta(i, j, k), 2), 2) *
            cos_theta_diff(z, i, j, k, rij, rik, coord);
}


decompiled_code:
double __fastcall f_attractive_diff(int a1, unsigned int a2, unsigned int a3, int a4, double a5)
{
double v7; // xmm0_8
double v8; // xmm3_8
double v11; // [rsp+8h] [rbp-30h]
double v12; // [rsp+8h] [rbp-30h]

v11 = lambda_ij(a2, a3);
v12 = COERCE_DOUBLE(*(_QWORD *)&v11 ^ LC1) * Aij(a2, a3);
v7 = lambda_ij(a2, a3);
v8 = v12 * exp(COERCE_DOUBLE(*(_QWORD *)&v7 ^ LC1) * a5);
return rij_diff(a1, a2, a3, a4, a5) * v8;
}

canonical_decompiled_code:
double __fastcall func5(int a1, unsigned int a2, unsigned int a3, int a4, double a5)
{
double v7; // xmm0_8
double v8; // xmm3_8
double v11; // [rsp+8h] [rbp-30h]
double v12; // [rsp+8h] [rbp-30h]

v11 = lambda_ij(a2, a3);
v12 = COERCE_DOUBLE(*(_QWORD *)&v11 ^ LC1) * Aij(a2, a3);
v7 = lambda_ij(a2, a3);
v8 = v12 * exp(COERCE_DOUBLE(*(_QWORD *)&v7 ^ LC1) * a5);
return func2(a1, a2, a3, a4, a5) * v8;
}

original_code:
static double f_attractive_diff(int z, int i, int j, double rij, coord_t coord)
{
    return -lambda_ij(i, j) * Aij(i, j) * exp(-lambda_ij(i, j) * rij) *
            rij_diff(z, i, j, rij, coord);
}

canonical_original_code:
static double f_attractive_diff(int z, int i, int j, double rij, enum coord_t coord)
{
    return -lambda_ij(i, j) * Aij(i, j) * exp(-lambda_ij(i, j) * rij) *
            rij_diff(z, i, j, rij, coord);
}


original_code:
static double f_cutoff_diff(int z, int i, int j, double rij, coord_t coord)
{
    if (rij < Rij(i, j)) {
        return 0;
    } else if ((rij > Rij(i, j)) && (rij < Sij(i, j))) {
        return - 3.14159265358979323846 / (2 * (Sij(i, j), Rij(i, j))) *
                 cos(3.14159265358979323846 * (rij - Rij(i, j)) / (Sij(i, j) - Rij(i, j))) *
                 rij_diff(z, i, j, rij, coord);
    } else {
        return 0;
    }
}

canonical_original_code:
static double f_cutoff_diff(int z, int i, int j, double rij, enum coord_t coord)
{
    if (rij < Rij(i, j)) {
        return 0;
    } else if ((rij > Rij(i, j)) && (rij < Sij(i, j))) {
        return - 3.14159265358979323846 / (2 * (Sij(i, j), Rij(i, j))) *
                 cos(3.14159265358979323846 * (rij - Rij(i, j)) / (Sij(i, j) - Rij(i, j))) *
                 rij_diff(z, i, j, rij, coord);
    } else {
        return 0;
    }
}


decompiled_code:
double __fastcall zeta_diff(unsigned int a1, unsigned int a2, unsigned int a3, int a4, double a5)
{
unsigned int v8; // ebx
double v10; // [rsp+8h] [rbp-50h]
double v11; // [rsp+8h] [rbp-50h]
double v12; // [rsp+8h] [rbp-50h]
double v13; // [rsp+8h] [rbp-50h]
double v14; // [rsp+10h] [rbp-48h]
double v15; // [rsp+18h] [rbp-40h]

if ( natoms <= 0 )
return 0.0;
v8 = 0;
v15 = 0.0;
do
{
if ( a2 != v8 && a3 != v8 )
{
v14 = t2_distance(a2, v8);
v10 = t2_f_cutoff(a2, v8);
if ( !(unsigned int)iszero() )
{
v11 = omega_ij(a2, v8) * v10;
v15 = v11 * g_diff(a1, a2, a3, v8, a4, a5, v14);
v12 = f_cutoff_diff(a1, a2, v8, a4, v14);
if ( !(unsigned int)iszero() )
{
v13 = omega_ij(a2, v8) * v12;
v15 = t2_g(a2, a3, v8) * v13 + v15;
}
}
}
++v8;
}
while ( natoms > (int)v8 );
return v15;
}

canonical_decompiled_code:
double __fastcall func7(unsigned int a1, unsigned int a2, unsigned int a3, int a4, double a5)
{
unsigned int v8; // ebx
double v10; // [rsp+8h] [rbp-50h]
double v11; // [rsp+8h] [rbp-50h]
double v12; // [rsp+8h] [rbp-50h]
double v13; // [rsp+8h] [rbp-50h]
double v14; // [rsp+10h] [rbp-48h]
double v15; // [rsp+18h] [rbp-40h]

if ( natoms <= 0 )
return 0.0;
v8 = 0;
v15 = 0.0;
do
{
if ( a2 != v8 && a3 != v8 )
{
v14 = t2_distance(a2, v8);
v10 = t2_f_cutoff(a2, v8);
if ( !(unsigned int)iszero() )
{
v11 = omega_ij(a2, v8) * v10;
v15 = v11 * func4(a1, a2, a3, v8, a4, a5, v14);
v12 = func6(a1, a2, v8, a4, v14);
if ( !(unsigned int)iszero() )
{
v13 = omega_ij(a2, v8) * v12;
v15 = t2_g(a2, a3, v8) * v13 + v15;
}
}
}
++v8;
}
while ( natoms > (int)v8 );
return v15;
}

original_code:
static double zeta_diff(int z, int i, int j, double rij, coord_t coord)
{
    double rik, f_cutoff_val, f_cutoff_diff_val, sum = 0;
    int k;
    for (k = 0; k < natoms; k++) {
        if ((k != i) && (k != j)) {
            rik = t2_distance(i, k);
            f_cutoff_val = t2_f_cutoff(i, k, rik);
            if (!iszero(f_cutoff_val)) {
                sum = f_cutoff_val * omega_ij(i, k) *
                      g_diff(z, i, j, k, rij, rik, coord);
                f_cutoff_diff_val = f_cutoff_diff(z, i, k, rik, coord);
                if (!iszero(f_cutoff_diff_val)) {
                    sum += f_cutoff_diff_val * omega_ij(i, k) * t2_g(i, j, k);
                }
            }
        }
    }
    return sum;
}

canonical_original_code:
static double zeta_diff(int z, int i, int j, double rij, enum coord_t coord)
{
    double rik; double f_cutoff_val; double f_cutoff_diff_val; double sum = 0;
    int k;
    for (k = 0; k < natoms; k++) {
        if ((k != i) && (k != j)) {
            rik = t2_distance(i, k);
            f_cutoff_val = t2_f_cutoff(i, k, rik);
            if (!iszero(f_cutoff_val)) {
                sum = f_cutoff_val * omega_ij(i, k) *
                      g_diff(z, i, j, k, rij, rik, coord);
                f_cutoff_diff_val = f_cutoff_diff(z, i, k, rik, coord);
                if (!iszero(f_cutoff_diff_val)) {
                    sum += f_cutoff_diff_val * omega_ij(i, k) * t2_g(i, j, k);
                }
            }
        }
    }
    return sum;
}


decompiled_code:
void __fastcall bij_diff(unsigned int a1, unsigned int a2, unsigned int a3, int a4, double a5)
{
double v8; // xmm0_8
double v9; // xmm0_8
double v10; // rbx
double v11; // xmm0_8
double v12; // xmm1_8
double v13; // xmm0_8
double ya; // [rsp+0h] [rbp-50h]
double yb; // [rsp+0h] [rbp-50h]
double y; // [rsp+0h] [rbp-50h]
double v17; // [rsp+8h] [rbp-48h]
double v18; // [rsp+8h] [rbp-48h]

ya = n(a2);
v8 = beta(a2);
yb = pow(v8, ya);
v17 = n(a2);
v9 = t2_zeta(a2, a3);
v10 = pow(v9, v17) * yb + 1.0;
if ( !(unsigned int)iszero() )
{
y = t2_zeta(a2, a3);
if ( !(unsigned int)iszero() )
{
chi(a2, a3);
v18 = n(a2);
v11 = beta(a2);
pow(v11, v18);
v12 = n(a2) - 1.0;
pow(y, v12);
v13 = n(a2);
pow(v10, 1.0 / (v13 + v13) + 1.0);
zeta_diff(a1, a2, a3, a4, a5);
}
}
}

canonical_decompiled_code:
void __fastcall func8(unsigned int a1, unsigned int a2, unsigned int a3, int a4, double a5)
{
double v8; // xmm0_8
double v9; // xmm0_8
double v10; // rbx
double v11; // xmm0_8
double v12; // xmm1_8
double v13; // xmm0_8
double ya; // [rsp+0h] [rbp-50h]
double yb; // [rsp+0h] [rbp-50h]
double y; // [rsp+0h] [rbp-50h]
double v17; // [rsp+8h] [rbp-48h]
double v18; // [rsp+8h] [rbp-48h]

ya = n(a2);
v8 = beta(a2);
yb = pow(v8, ya);
v17 = n(a2);
v9 = t2_zeta(a2, a3);
v10 = pow(v9, v17) * yb + 1.0;
if ( !(unsigned int)iszero() )
{
y = t2_zeta(a2, a3);
if ( !(unsigned int)iszero() )
{
chi(a2, a3);
v18 = n(a2);
v11 = beta(a2);
pow(v11, v18);
v12 = n(a2) - 1.0;
pow(y, v12);
v13 = n(a2);
pow(v10, 1.0 / (v13 + v13) + 1.0);
func7(a1, a2, a3, a4, a5);
}
}
}

original_code:
static double bij_diff(int z, int i, int j, double rij, coord_t coord)
{
    double bij_denom_tmp, t2_zeta_val;
    bij_denom_tmp = 1 + pow(beta(i), n(i)) * pow(t2_zeta(i, j), n(i));
    if (iszero(bij_denom_tmp)) {
        return 0.0;
    } else {
        t2_zeta_val = t2_zeta(i, j);
        if (iszero(t2_zeta_val)) {
            return 0.0;
        } else {
            return chi(i, j) * (-pow(beta(i), n(i)) *
                                 pow(t2_zeta_val, n(i) - 1)) /
                   (2 * pow(bij_denom_tmp, 1 / (2 * n(i)) + 1)) *
                   zeta_diff(z, i, j, rij, coord);
        }
    }
}

canonical_original_code:
static double bij_diff(int z, int i, int j, double rij, enum coord_t coord)
{
    double bij_denom_tmp; double t2_zeta_val;
    bij_denom_tmp = 1 + pow(beta(i), n(i)) * pow(t2_zeta(i, j), n(i));
    if (iszero(bij_denom_tmp)) {
        return 0.0;
    } else {
        t2_zeta_val = t2_zeta(i, j);
        if (iszero(t2_zeta_val)) {
            return 0.0;
        } else {
            return chi(i, j) * (-pow(beta(i), n(i)) *
                                 pow(t2_zeta_val, n(i) - 1)) /
                   (2 * pow(bij_denom_tmp, 1 / (2 * n(i)) + 1)) *
                   zeta_diff(z, i, j, rij, coord);
        }
    }
}


decompiled_code:
void __fastcall tersoff2_forces_ij(unsigned int a1, unsigned int a2)
{
if ( a1 != a2 )
{
*(double *)&Fx = COERCE_DOUBLE(Uij_diff(atom_z, a1, a2, 0)) + *(double *)&Fx;
*(double *)&Fy = COERCE_DOUBLE(Uij_diff(atom_z, a1, a2, 1)) + *(double *)&Fy;
*(double *)&Fz = COERCE_DOUBLE(Uij_diff(atom_z, a1, a2, 2)) + *(double *)&Fz;
}
}

canonical_decompiled_code:
void __fastcall func9(unsigned int a1, unsigned int a2)
{
if ( a1 != a2 )
{
*(double *)&Fx = COERCE_DOUBLE(Uij_diff(atom_z, a1, a2, 0)) + *(double *)&Fx;
*(double *)&Fy = COERCE_DOUBLE(Uij_diff(atom_z, a1, a2, 1)) + *(double *)&Fy;
*(double *)&Fz = COERCE_DOUBLE(Uij_diff(atom_z, a1, a2, 2)) + *(double *)&Fz;
}
}

original_code:
static void tersoff2_forces_ij(int atom_i, int atom_j)
{
    if (atom_i != atom_j) {
        Fx += Uij_diff(atom_z, atom_i, atom_j, COORD_X);
        Fy += Uij_diff(atom_z, atom_i, atom_j, COORD_Y);
        Fz += Uij_diff(atom_z, atom_i, atom_j, COORD_Z);
    }
}


decompiled_code:
__int64 tersoff2_forces()
{
__int64 result; // rax
__int64 v1; // rsi
double v2; // xmm0_8
__int64 v3; // rdi
double v4; // xmm0_8
__int64 v5; // rdi
double v6; // xmm0_8
bool v7; // cc
double v8; // [rsp+0h] [rbp-10h]
double v9; // [rsp+0h] [rbp-10h]
double v10; // [rsp+0h] [rbp-10h]

atom_z = 0;
result = natoms;
if ( natoms > 0 )
{
v1 = 0LL;
do
{
printf("z = %d\n", v1);
Fz = 0LL;
Fy = 0LL;
Fx = 0LL;
celllist_scan_atoms(tersoff2_forces_ij);
*(double *)&Fy = -0.5 * *(double *)&Fy;
*(double *)&Fx = -0.5 * *(double *)&Fx;
v8 = *(double *)&Fx;
*(double *)&Fz = -0.5 * *(double *)&Fz;
v2 = mass((unsigned int)atom_z);
v3 = atom_z;
*(double *)(qword_1018 + 8LL * atom_z) = v8 / v2;
v9 = *(double *)&Fy;
v4 = mass(v3);
v5 = atom_z;
*(double *)(ay + 8LL * atom_z) = v9 / v4;
v10 = *(double *)&Fz;
v6 = mass(v5);
result = az;
v1 = (unsigned int)(atom_z + 1);
v7 = (int)v1 < natoms;
*(double *)(az + 8LL * atom_z) = v10 / v6;
atom_z = v1;
}
while ( v7 );
}
return result;
}

canonical_decompiled_code:
__int64 func10()
{
__int64 result; // rax
__int64 v1; // rsi
double v2; // xmm0_8
__int64 v3; // rdi
double v4; // xmm0_8
__int64 v5; // rdi
double v6; // xmm0_8
bool v7; // cc
double v8; // [rsp+0h] [rbp-10h]
double v9; // [rsp+0h] [rbp-10h]
double v10; // [rsp+0h] [rbp-10h]

atom_z = 0;
result = natoms;
if ( natoms > 0 )
{
v1 = 0LL;
do
{
printf("z = %d\n", v1);
Fz = 0LL;
Fy = 0LL;
Fx = 0LL;
celllist_scan_atoms(tersoff2_forces_ij);
*(double *)&Fy = -0.5 * *(double *)&Fy;
*(double *)&Fx = -0.5 * *(double *)&Fx;
v8 = *(double *)&Fx;
*(double *)&Fz = -0.5 * *(double *)&Fz;
v2 = mass((unsigned int)atom_z);
v3 = atom_z;
*(double *)(qword_1018 + 8LL * atom_z) = v8 / v2;
v9 = *(double *)&Fy;
v4 = mass(v3);
v5 = atom_z;
*(double *)(ay + 8LL * atom_z) = v9 / v4;
v10 = *(double *)&Fz;
v6 = mass(v5);
result = az;
v1 = (unsigned int)(atom_z + 1);
v7 = (int)v1 < natoms;
*(double *)(az + 8LL * atom_z) = v10 / v6;
atom_z = v1;
}
while ( v7 );
}
return result;
}

original_code:
void tersoff2_forces()
{
    for (atom_z = 0; atom_z < natoms; atom_z++) {
        printf("z = %d\n", atom_z);
        Fx = Fy = Fz = 0;
        celllist_scan_atoms(tersoff2_forces_ij);
        Fx *= -0.5;
        Fy *= -0.5;
        Fz *= -0.5;
        ax[atom_z] = Fx / mass(atom_z);
        ay[atom_z] = Fy / mass(atom_z);
        az[atom_z] = Fz / mass(atom_z);
    }
}


original_code:
static _Bool scan_cells(cell_t *cell)
{
    cell->z++;
    if (cell->z == cell_Lz) {
        cell->z = 0;
        cell->y++;
        if (cell->y == cell_Ly) {
            cell->y = 0;
            cell->x++;
            if (cell->x == cell_Lx) {
                cell->x = 0;
                return 0;
            }
        }
    }
    return 1;
}

canonical_original_code:
static _Bool scan_cells(struct cell_s *cell)
{
    cell->z++;
    if (cell->z == cell_Lz) {
        cell->z = 0;
        cell->y++;
        if (cell->y == cell_Ly) {
            cell->y = 0;
            cell->x++;
            if (cell->x == cell_Lx) {
                cell->x = 0;
                return 0;
            }
        }
    }
    return 1;
}

variable_types: struct cell_s { int x; int y; int z; int scal; } *


decompiled_code:
__int64 __fastcall celllist_scan_atoms(void (*a1)(void))
{
__int64 result; // rax
_DWORD *v2; // rcx
int v3; // [rsp+0h] [rbp-58h] BYREF
int v4; // [rsp+4h] [rbp-54h] BYREF
__int64 v5; // [rsp+8h] [rbp-50h] BYREF
__int64 v6; // [rsp+10h] [rbp-48h] BYREF
__int64 v7; // [rsp+18h] [rbp-40h] BYREF
int v8; // [rsp+20h] [rbp-38h] BYREF
int v9; // [rsp+24h] [rbp-34h]
int v10; // [rsp+28h] [rbp-30h]
int v11; // [rsp+2Ch] [rbp-2Ch]
int v12[4]; // [rsp+30h] [rbp-28h] BYREF
int v13[3]; // [rsp+40h] [rbp-18h] BYREF
int v14; // [rsp+4Ch] [rbp-Ch]

init_cell((__int64)&v8);
while ( 1 )
{
result = scan_cells(&v8);
if ( !(_BYTE)result )
break;
cell_vec_to_scal(&v8);
if ( __ROR4__(652835029 * v11 + 17179864, 3) <= 0x418936u )
printf("cell = %d\n", (unsigned int)v11);
init_neigh_cell_isra_0(v8, v9, v10, v12);
while ( (unsigned __int8)scan_neigh_cells_isra_0(v8, v9, v10, v12) )
{
cell_periodic_bound_cond_isra_0(v12[0], v12[1], v12[2], v13, &v5, &v6, &v7);
cell_vec_to_scal(v2);
if ( v11 < v14 && init_atom_in_cell_isra_0(v11, &v3) )
{
do
{
if ( init_atom_in_cell_isra_0(v14, &v4) )
{
do
{
if ( v3 < v4 )
a1();
}
while ( scan_atom_in_cell_constprop_0(&v4) );
}
}
while ( scan_atom_in_cell_constprop_0(&v3) );
}
}
}
return result;
}

original_code:
void celllist_scan_atoms(void (*func) (int atom_i, int atom_j))
{
    cell_t cell;
    cell_t neigh_cell_raw;
    cell_t neigh_cell;
    init_cell(&cell);
    while (scan_cells(&cell)) {
        cell_vec_to_scal(&cell);
        if (cell.scal % 1000 == 0) {
            printf("cell = %d\n", cell.scal);
        }
        init_neigh_cell(cell, &neigh_cell_raw);
        while (scan_neigh_cells(cell, &neigh_cell_raw)) {
            int atom_cell, atom_neighcell;
            double atom_shift_x, atom_shift_y, atom_shift_z;
            cell_periodic_bound_cond(neigh_cell_raw, &neigh_cell,
                                   &atom_shift_x, &atom_shift_y, &atom_shift_z);
            cell_vec_to_scal(&neigh_cell);
            if (cell.scal >= neigh_cell.scal) {
                continue;
            }
            if (!init_atom_in_cell(cell, &atom_cell)) {
                continue;
            }
            do {
                if (!init_atom_in_cell(neigh_cell, &atom_neighcell)) {
                    continue;
                }
                do {
                    int atom_i = atom_cell;
                    int atom_j = atom_neighcell;
                    if (atom_i >= atom_j) {
                        continue;
                    }
                    func(atom_i, atom_j);
                } while (scan_atom_in_cell(neigh_cell, &atom_neighcell));
            } while (scan_atom_in_cell(cell, &atom_cell));
        }
    }
}

canonical_original_code:
void celllist_scan_atoms(void (*func)(int atom_i, int atom_j))
{
    struct cell_s cell;
    struct cell_s neigh_cell_raw;
    struct cell_s neigh_cell;
    init_cell(&cell);
    while (scan_cells(&cell)) {
        cell_vec_to_scal(&cell);
        if (cell.scal % 1000 == 0) {
            printf("cell = %d\n", cell.scal);
        }
        init_neigh_cell(cell, &neigh_cell_raw);
        while (scan_neigh_cells(cell, &neigh_cell_raw)) {
            int atom_cell; int atom_neighcell;
            double atom_shift_x; double atom_shift_y; double atom_shift_z;
            cell_periodic_bound_cond(neigh_cell_raw, &neigh_cell,
                                   &atom_shift_x, &atom_shift_y, &atom_shift_z);
            cell_vec_to_scal(&neigh_cell);
            if (cell.scal >= neigh_cell.scal) {
                continue;
            }
            if (!init_atom_in_cell(cell, &atom_cell)) {
                continue;
            }
            do {
                if (!init_atom_in_cell(neigh_cell, &atom_neighcell)) {
                    continue;
                }
                do {
                    int atom_i = atom_cell;
                    int atom_j = atom_neighcell;
                    if (atom_i >= atom_j) {
                        continue;
                    }
                    func(atom_i, atom_j);
                } while (scan_atom_in_cell(neigh_cell, &atom_neighcell));
            } while (scan_atom_in_cell(cell, &atom_cell));
        }
    }
}

variable_types:
func
void (*)(int atom_i, int atom_j)

variable_types: struct cell_s { int x; int y; int z; int scal; }


original_code:
void linked_cell_init()
{
    const double r_cutoff_more = r_cutoff + delta_r;
    int cell;
    cell_Lx = floor(Lx / r_cutoff_more);
    cell_Ly = floor(Ly / r_cutoff_more);
    cell_Lz = floor(Lz / r_cutoff_more);
    ncells = cell_Lx * cell_Ly * cell_Lz;
    cell_LyLz = cell_Ly * cell_Lz;
    cell_rx = Lx / cell_Lx;
    cell_ry = Ly / cell_Ly;
    cell_rz = Lz / cell_Lz;
    list = xmalloc(sizeof(*list) * natoms);
    head = xmalloc(sizeof(*head) * ncells);
    for (cell = 0; cell < ncells; cell++) {
        head[cell] = LIST_END;
    }
}

canonical_original_code:
void linked_cell_init()
{
    double r_cutoff_more = r_cutoff + delta_r;
    int cell;
    cell_Lx = floor(Lx / r_cutoff_more);
    cell_Ly = floor(Ly / r_cutoff_more);
    cell_Lz = floor(Lz / r_cutoff_more);
    ncells = cell_Lx * cell_Ly * cell_Lz;
    cell_LyLz = cell_Ly * cell_Lz;
    cell_rx = Lx / cell_Lx;
    cell_ry = Ly / cell_Ly;
    cell_rz = Lz / cell_Lz;
    list = xmalloc(sizeof(*list) * natoms);
    head = xmalloc(sizeof(*head) * ncells);
    for (cell = 0; cell < ncells; cell++) {
        head[cell] = LIST_END;
    }
}

variable_types: cell int


decompiled_code:
__int64 linked_cell_update()
{
__int64 result; // rax
double v1; // xmm3_8
__int64 v2; // rcx
double v3; // xmm2_8
double v4; // xmm1_8
_DWORD *v5; // rsi
__int64 v6; // rcx
__int64 v7; // r8
int v8[3]; // [rsp+0h] [rbp-10h] BYREF
int v9; // [rsp+Ch] [rbp-4h]

result = natoms;
if ( natoms > 0 )
{
v1 = *(double *)&cell_rx;
v2 = 0LL;
v3 = *(double *)&cell_ry;
v4 = *(double *)&cell_rz;
v5 = head;
do
{
v8[0] = (int)(*(double *)(x + 8 * v2) / v1);
v8[1] = (int)(*(double *)(y + 8 * v2) / v3);
v8[2] = (int)(*(double *)(z + 8 * v2) / v4);
cell_vec_to_scal(v8);
*(_DWORD *)(v7 + 4 * v6) = v5[v9];
result = v9;
v5[v9] = v6;
v2 = v6 + 1;
}
while ( natoms > (int)v2 );
}
return result;
}

canonical_decompiled_code:
__int64 func10()
{
__int64 result; // rax
double v1; // xmm3_8
__int64 v2; // rcx
double v3; // xmm2_8
double v4; // xmm1_8
_DWORD *v5; // rsi
__int64 v6; // rcx
__int64 v7; // r8
int v8[3]; // [rsp+0h] [rbp-10h] BYREF
int v9; // [rsp+Ch] [rbp-4h]

result = natoms;
if ( natoms > 0 )
{
v1 = *(double *)&cell_rx;
v2 = 0LL;
v3 = *(double *)&cell_ry;
v4 = *(double *)&cell_rz;
v5 = head;
do
{
v8[0] = (int)(*(double *)(x + 8 * v2) / v1);
v8[1] = (int)(*(double *)(y + 8 * v2) / v3);
v8[2] = (int)(*(double *)(z + 8 * v2) / v4);
func0(v8);
*(_DWORD *)(v7 + 4 * v6) = v5[v9];
result = v9;
v5[v9] = v6;
v2 = v6 + 1;
}
while ( natoms > (int)v2 );
}
return result;
}

original_code:
void linked_cell_update()
{
    int atom;
    cell_t cell;
    for (atom = 0; atom < natoms; atom++) {
        cell.x = x[atom] / cell_rx;
        cell.y = y[atom] / cell_ry;
        cell.z = z[atom] / cell_rz;
        cell_vec_to_scal(&cell);
        list[atom] = head[cell.scal];
        head[cell.scal] = atom;
    }
}

canonical_original_code:
void linked_cell_update()
{
    int atom;
    struct cell_s cell;
    for (atom = 0; atom < natoms; atom++) {
        cell.x = x[atom] / cell_rx;
        cell.y = y[atom] / cell_ry;
        cell.z = z[atom] / cell_rz;
        cell_vec_to_scal(&cell);
        list[atom] = head[cell.scal];
        head[cell.scal] = atom;
    }
}

variable_types: atom int

user_defined_types: struct cell_s { int x; int y; int z; int scal; }


decompiled_code:
void linked_cell_finalize()
{
free(list);
free(head);
}

canonical_decompiled_code:
void func11()
{
free(list);
free(head);
}


decompiled_code:
bool cell_update_test()
{
double v0; // xmm0_8
__int64 i; // rax
double v2; // xmm1_8

v0 = *vx;
if ( natoms > 0 )
{
for ( i = 0LL; ; v0 = fmax(*(double *)(vx + i), v2) )
{
v2 = fmax(*(double *)(vz + i), fmax(*(double *)(vy + i), v0));
v0 = v2;
if ( 8LL * (unsigned int)(natoms - 1) == i )
break;
i += 8LL;
}
}
*(double *)&sum_max_v_0 = v0 + *(double *)&sum_max_v_0;
return *(double *)&sum_max_v_0 > 0.35 / (*(double *)&timestep_dt + *(double *)&timestep_dt);
}

canonical_decompiled_code:
bool func12()
{
double v0; // xmm0_8
__int64 i; // rax
double v2; // xmm1_8

v0 = *vx;
if ( natoms > 0 )
{
for ( i = 0LL; ; v0 = fmax(*(double *)(vx + i), v2) )
{
v2 = fmax(*(double *)(vz + i), fmax(*(double *)(vy + i), v0));
v0 = v2;
if ( 8LL * (unsigned int)(natoms - 1) == i )
break;
i += 8LL;
}
}
*(double *)&sum_max_v_0 = v0 + *(double *)&sum_max_v_0;
return *(double *)&sum_max_v_0 > 0.35 / (*(double *)&timestep_dt + *(double *)&timestep_dt);
}

original_code:
_Bool cell_update_test()
{
    int atom;
    double max_v = vx[0];
    static double sum_max_v = 0;
    for (atom = 0; atom < natoms; atom++) {
        if (vx[atom] > max_v) {
            max_v = vx[atom];
        }
        if (vy[atom] > max_v) {
            max_v = vy[atom];
        }
        if (vz[atom] > max_v) {
            max_v = vz[atom];
        }
    }
    sum_max_v += max_v;
    if (sum_max_v > delta_r / (2 * timestep_dt)) {
        return 1;
        sum_max_v = 0;
    } else {
        return 0;
    }
    return 1;
}


decompiled_code:
void compute_pos()
{
__int64 v0; // rbp
double *v1; // rsi
double *v2; // r9
__int64 v3; // rax
double *v4; // rbx
double *v5; // rcx
double *v6; // r8
double *v7; // r11
double *v8; // rdx
double *v9; // rdi
double *v10; // r10
double v11; // xmm1_8
double v12; // xmm1_8
double v13; // xmm1_8

v0 = natoms;
if ( natoms > 0 )
{
v1 = (double *)x;
v2 = (double *)vx;
v3 = 0LL;
v4 = (double *)ptr;
v5 = (double *)y;
v6 = (double *)vy;
v7 = (double *)ay;
v8 = (double *)z;
v9 = (double *)vz;
v10 = (double *)az;
do
{
v1[v3] = v2[v3] * *(double *)&timestep_dt
+ v1[v3]
+ v4[v3] * 0.5 * *(double *)&timestep_dt * *(double *)&timestep_dt;
v5[v3] = v6[v3] * *(double *)&timestep_dt
+ v5[v3]
+ v7[v3] * 0.5 * *(double *)&timestep_dt * *(double *)&timestep_dt;
v8[v3] = v9[v3] * *(double *)&timestep_dt
+ v8[v3]
+ v10[v3] * 0.5 * *(double *)&timestep_dt * *(double *)&timestep_dt;
v12 = v1[v3];
if ( v12 < *(double *)&Lx * 0.5 )
{
if ( COERCE_DOUBLE(Lx ^ LC1) * 0.5 > v12 )
v1[v3] = v12 + *(double *)&Lx;
}
else
{
v1[v3] = v12 - *(double *)&Lx;
}
v13 = v5[v3];
if ( v13 >= *(double *)&Ly * 0.5 )
{
v5[v3] = v13 - *(double *)&Ly;
}
else if ( COERCE_DOUBLE(Ly ^ LC1) * 0.5 > v13 )
{
v5[v3] = v13 + *(double *)&Ly;
}
v11 = v8[v3];
if ( v11 < *(double *)&Lz * 0.5 )
{
if ( COERCE_DOUBLE(Lz ^ LC1) * 0.5 > v11 )
v8[v3] = v11 + *(double *)&Lz;
}
else
{
v8[v3] = v11 - *(double *)&Lz;
}
v2[v3] = v4[v3] * 0.5 * *(double *)&timestep_dt + v2[v3];
v6[v3] = v7[v3] * 0.5 * *(double *)&timestep_dt + v6[v3];
v9[v3] = v10[v3] * 0.5 * *(double *)&timestep_dt + v9[v3];
++v3;
}
while ( v0 != v3 );
}
}

canonical_decompiled_code:
void func0()
{
__int64 v0; // rbp
double *v1; // rsi
double *v2; // r9
__int64 v3; // rax
double *v4; // rbx
double *v5; // rcx
double *v6; // r8
double *v7; // r11
double *v8; // rdx
double *v9; // rdi
double *v10; // r10
double v11; // xmm1_8
double v12; // xmm1_8
double v13; // xmm1_8

v0 = natoms;
if ( natoms > 0 )
{
v1 = (double *)x;
v2 = (double *)vx;
v3 = 0LL;
v4 = (double *)ptr;
v5 = (double *)y;
v6 = (double *)vy;
v7 = (double *)ay;
v8 = (double *)z;
v9 = (double *)vz;
v10 = (double *)az;
do
{
v1[v3] = v2[v3] * *(double *)&timestep_dt
+ v1[v3]
+ v4[v3] * 0.5 * *(double *)&timestep_dt * *(double *)&timestep_dt;
v5[v3] = v6[v3] * *(double *)&timestep_dt
+ v5[v3]
+ v7[v3] * 0.5 * *(double *)&timestep_dt * *(double *)&timestep_dt;
v8[v3] = v9[v3] * *(double *)&timestep_dt
+ v8[v3]
+ v10[v3] * 0.5 * *(double *)&timestep_dt * *(double *)&timestep_dt;
v12 = v1[v3];
if ( v12 < *(double *)&Lx * 0.5 )
{
if ( COERCE_DOUBLE(Lx ^ LC1) * 0.5 > v12 )
v1[v3] = v12 + *(double *)&Lx;
}
else
{
v1[v3] = v12 - *(double *)&Lx;
}
v13 = v5[v3];
if ( v13 >= *(double *)&Ly * 0.5 )
{
v5[v3] = v13 - *(double *)&Ly;
}
else if ( COERCE_DOUBLE(Ly ^ LC1) * 0.5 > v13 )
{
v5[v3] = v13 + *(double *)&Ly;
}
v11 = v8[v3];
if ( v11 < *(double *)&Lz * 0.5 )
{
if ( COERCE_DOUBLE(Lz ^ LC1) * 0.5 > v11 )
v8[v3] = v11 + *(double *)&Lz;
}
else
{
v8[v3] = v11 - *(double *)&Lz;
}
v2[v3] = v4[v3] * 0.5 * *(double *)&timestep_dt + v2[v3];
v6[v3] = v7[v3] * 0.5 * *(double *)&timestep_dt + v6[v3];
v9[v3] = v10[v3] * 0.5 * *(double *)&timestep_dt + v9[v3];
++v3;
}
while ( v0 != v3 );
}
}

original_code:
static void compute_pos()
{
    int atom;
    for (atom = 0; atom < natoms; atom++) {
        x[atom] = x[atom] + vx[atom] * timestep_dt +
               0.5 * ax[atom] * timestep_dt * timestep_dt;
        y[atom] = y[atom] + vy[atom] * timestep_dt +
               0.5 * ay[atom] * timestep_dt * timestep_dt;
        z[atom] = z[atom] + vz[atom] * timestep_dt +
               0.5 * az[atom] * timestep_dt * timestep_dt;
        if (x[atom] >= Lx / 2) {
            x[atom] = x[atom] - Lx;
        } else if (x[atom] < -Lx / 2) {
            x[atom] = x[atom] + Lx;
        }
        if (y[atom] >= Ly / 2) {
            y[atom] = y[atom] - Ly;
        } else if (y[atom] < -Ly / 2) {
            y[atom] = y[atom] + Ly;
        }
        if (z[atom] >= Lz / 2) {
            z[atom] = z[atom] - Lz;
        } else if (z[atom] < -Lz / 2) {
            z[atom] = z[atom] + Lz;
        }
        vx[atom] = vx[atom] + 0.5 * ax[atom] * timestep_dt;
        vy[atom] = vy[atom] + 0.5 * ay[atom] * timestep_dt;
        vz[atom] = vz[atom] + 0.5 * az[atom] * timestep_dt;
    }
}


decompiled_code:
void compute_velocities()
{
__int64 v0; // rdi
double *v1; // rsi
double *v2; // r10
__int64 v3; // rax
double *v4; // rcx
double *v5; // r9
double *v6; // rdx
double *v7; // r8

v0 = natoms;
if ( natoms > 0 )
{
v1 = (double *)vx;
v2 = (double *)ptr;
v3 = 0LL;
v4 = (double *)vy;
v5 = (double *)ay;
v6 = (double *)vz;
v7 = (double *)az;
do
{
v1[v3] = v2[v3] * 0.5 * *(double *)&timestep_dt + v1[v3];
v4[v3] = v5[v3] * 0.5 * *(double *)&timestep_dt + v4[v3];
v6[v3] = v7[v3] * 0.5 * *(double *)&timestep_dt + v6[v3];
++v3;
}
while ( v0 != v3 );
}
}

canonical_decompiled_code:
void func1()
{
__int64 v0; // rdi
double *v1; // rsi
double *v2; // r10
__int64 v3; // rax
double *v4; // rcx
double *v5; // r9
double *v6; // rdx
double *v7; // r8

v0 = natoms;
if ( natoms > 0 )
{
v1 = (double *)vx;
v2 = (double *)ptr;
v3 = 0LL;
v4 = (double *)vy;
v5 = (double *)ay;
v6 = (double *)vz;
v7 = (double *)az;
do
{
v1[v3] = v2[v3] * 0.5 * *(double *)&timestep_dt + v1[v3];
v4[v3] = v5[v3] * 0.5 * *(double *)&timestep_dt + v4[v3];
v6[v3] = v7[v3] * 0.5 * *(double *)&timestep_dt + v6[v3];
++v3;
}
while ( v0 != v3 );
}
}

original_code:
static void compute_velocities()
{
    int atom;
    for (atom = 0; atom < natoms; atom++) {
        vx[atom] = vx[atom] + 0.5 * ax[atom] * timestep_dt;
        vy[atom] = vy[atom] + 0.5 * ay[atom] * timestep_dt;
        vz[atom] = vz[atom] + 0.5 * az[atom] * timestep_dt;
    }
}


integrate

canonical_decompiled_code:
void func2()
{
func0();
tersoff2_forces();
tersoff2_energy();
func1();
}

original_code:
static void integrate()
{
    compute_pos();
    tersoff2_forces();
    tersoff2_energy();
    compute_velocities();
}


decompiled_code:
void *allocate_memory()
{
void *result; // rax

x = (void *)xmalloc(8LL * natoms);
y = (void *)xmalloc(8LL * natoms);
z = (void *)xmalloc(8LL * natoms);
vx = (void *)xmalloc(8LL * natoms);
vy = (void *)xmalloc(8LL * natoms);
vz = (void *)xmalloc(8LL * natoms);
ptr = (void *)xmalloc(8LL * natoms);
ay = (void *)xmalloc(8LL * natoms);
az = (void *)xmalloc(8LL * natoms);
result = (void *)xmalloc(4LL * natoms);
atomspecies = result;
return result;
}

canonical_decompiled_code:
void *func4()
{
void *result; // rax

x = (void *)xmalloc(8LL * natoms);
y = (void *)xmalloc(8LL * natoms);
z = (void *)xmalloc(8LL * natoms);
vx = (void *)xmalloc(8LL * natoms);
vy = (void *)xmalloc(8LL * natoms);
vz = (void *)xmalloc(8LL * natoms);
ptr = (void *)xmalloc(8LL * natoms);
ay = (void *)xmalloc(8LL * natoms);
az = (void *)xmalloc(8LL * natoms);
result = (void *)xmalloc(4LL * natoms);
atomspecies = result;
return result;
}

original_code:
static void allocate_memory()
{
    x = xmalloc(sizeof(*x) * natoms);
    y = xmalloc(sizeof(*y) * natoms);
    z = xmalloc(sizeof(*z) * natoms);
    vx = xmalloc(sizeof(*vx) * natoms);
    vy = xmalloc(sizeof(*vy) * natoms);
    vz = xmalloc(sizeof(*vz) * natoms);
    ax = xmalloc(sizeof(*ax) * natoms);
    ay = xmalloc(sizeof(*ay) * natoms);
    az = xmalloc(sizeof(*az) * natoms);
    atomspecies = xmalloc(sizeof(*atomspecies) * natoms);
}


decompiled_code:
void free_memory()
{
__int64 v0; // rbx
void *v1; // rdi

free(x);
free(y);
free(z);
free(vx);
free(vy);
free(vz);
free(ptr);
free(ay);
free(az);
free(atomspecies);
if ( natomspecies > 0 )
{
v0 = 0LL;
do
{
v1 = (void *)*((_QWORD *)atomspecies_names + v0++);
free(v1);
}
while ( natomspecies > (int)v0 );
}
free(atomspecies_names);
}

canonical_decompiled_code:
void func8()
{
__int64 v0; // rbx
void *v1; // rdi

free(x);
free(y);
free(z);
free(vx);
free(vy);
free(vz);
free(ptr);
free(ay);
free(az);
free(atomspecies);
if ( natomspecies > 0 )
{
v0 = 0LL;
do
{
v1 = (void *)*((_QWORD *)atomspecies_names + v0++);
free(v1);
}
while ( natomspecies > (int)v0 );
}
free(atomspecies_names);
}

original_code:
static void free_memory()
{
    int species;
    free(x);
    free(y);
    free(z);
    free(vx);
    free(vy);
    free(vz);
    free(ax);
    free(ay);
    free(az);
    free(atomspecies);
    for (species = 0; species < natomspecies; species++) {
        free(atomspecies_names[species]);
    }
    free(atomspecies_names);
}

variable_types: species int


decompiled_code:
__int64 md_run()
{
__int64 v0; // rsi

puts("Run modelling");
tersoff2_param_init();
linked_cell_init();
linked_cell_update();
tersoff2_energy();
tersoff2_forces();
timestep = 1;
if ( ntimesteps > 0 )
{
v0 = 1LL;
do
{
printf("step %6d timestep: %E sec.\n", v0, (double)(int)v0 * *(double *)&timestep_dt);
integrate();
if ( (unsigned int)cell_update_test() )
linked_cell_update();
v0 = (unsigned int)++timestep;
}
while ( timestep <= ntimesteps );
}
tersoff2_param_finalize();
return linked_cell_finalize();
}

canonical_decompiled_code:
__int64 func9()
{
__int64 v0; // rsi

puts("Run modelling");
tersoff2_param_init();
linked_cell_init();
linked_cell_update();
tersoff2_energy();
tersoff2_forces();
timestep = 1;
if ( ntimesteps > 0 )
{
v0 = 1LL;
do
{
printf("step %6d timestep: %E sec.\n", v0, (double)(int)v0 * *(double *)&timestep_dt);
func2();
if ( (unsigned int)cell_update_test() )
linked_cell_update();
v0 = (unsigned int)++timestep;
}
while ( timestep <= ntimesteps );
}
tersoff2_param_finalize();
return linked_cell_finalize();
}

original_code:
void md_run()
{
    double t;
    printf("Run modelling\n");
    tersoff2_param_init();
    linked_cell_init();
    linked_cell_update();
    tersoff2_energy();
    tersoff2_forces();
    for (timestep = 1; timestep <= ntimesteps; timestep++) {
        t = timestep * timestep_dt;
        printf("step %6d timestep: %E sec.\n", timestep, t);
        integrate();
        if (cell_update_test()) {
            linked_cell_update();
        }
    }
    tersoff2_param_finalize();
    linked_cell_finalize();
}

variable_types: t double


decompiled_code:
int __fastcall md_initialize(char *a1, char *a2)
{
read_atoms(a1);
return read_inputfile(a2);
}

canonical_decompiled_code:
int __fastcall func10(char *a1, char *a2)
{
func5(a1);
return func7(a2);
}

original_code:
void md_initialize(const char *cls_file, const char *input_file)
{
    read_atoms(cls_file);
    read_inputfile(input_file);
}

canonical_original_code:
void md_initialize(char *cls_file, char *input_file)
{
    read_atoms(cls_file);
    read_inputfile(input_file);
}


decompiled_code:
void md_finalize()
{
free_memory();
}

canonical_decompiled_code:
void func11()
{
func8();
}

original_code:
void md_finalize()
{
    free_memory();
}

canonical_original_code:
void md_finalize()
{
    free_memory();
}


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

va_start(arg, format);
vsprintf(&buf_0, format, arg);
if ( buf_0 )
fprintf(stderr, "error: %s\n", &buf_0);
exit(1);
}

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

va_start(arg, format);
vsprintf(&buf_0, format, arg);
if ( buf_0 )
fprintf(stderr, "error: %s\n", &buf_0);
exit(1);
}

original_code:
void exit_error(const char *format, ...)
{
    va_list ap;
    static char buf[ERROR_BUF_MAX];
    __builtin_va_start(ap,format);
    vsprintf(buf, format, ap);
    __builtin_va_end(ap);
    if (strlen(buf) > 0)
        fprintf(stderr, "error: %s\n", buf);
    exit(1);
}

canonical_original_code:
void exit_error(char *format, ...)
{
    __builtin_va_list ap;
    static char buf[-1];
    __builtin_va_start(ap,format);
    vsprintf(buf, format, ap);
    __builtin_va_end(ap);
    if (strlen(buf) > 0)
        fprintf(stderr, "error: %s\n", buf);
    exit(1);
}

variable_types:
format
char *

variable_types:
buf
char [-1]


xmalloc

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

if ( !a1 )
return 0LL;
result = malloc(a1);
if ( !result )
exit_error("xmalloc: No enough memory");
return result;
}

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

if ( !a1 )
return 0LL;
result = malloc(a1);
if ( !result )
func0("xmalloc: No enough memory");
return result;
}

original_code:
void *xmalloc(size_t size)
{
    void *p;
    if (size == 0)
        return ((void *)0);
    if ( (p = malloc(size)) == ((void *)0)) {
        exit_error("xmalloc: No enough memory");
    }
    return p;
}

canonical_original_code:
void *xmalloc(unsigned long size)
{
    void *p;
    if (size == 0)
        return ((void *)0);
    if ( (p = malloc(size)) == ((void *)0)) {
        exit_error("xmalloc: No enough memory");
    }
    return p;
}

variable_types:
size
unsigned long

variable_types:
p
void *

return_type: void *


xrealloc

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

result = realloc(a1, a2);
if ( !result )
exit_error("xrealloc: No enough memory");
return result;
}

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

result = realloc(a1, a2);
if ( !result )
func0("xrealloc: No enough memory");
return result;
}

original_code:
void *xrealloc(void *ptr, size_t size)
{
    void *p;
    if ( (p = realloc(ptr, size)) == ((void *)0)) {
        exit_error("xrealloc: No enough memory");
    }
    return p;
}

canonical_original_code:
void *xrealloc(void *ptr, unsigned long size)
{
    void *p;
    if ( (p = realloc(ptr, size)) == ((void *)0)) {
        exit_error("xrealloc: No enough memory");
    }
    return p;
}

variable_types:
ptr
void *


decompiled_code:
void __fastcall tersoff2_energy_ij(unsigned int a1, unsigned int a2)
{
double v2; // xmm2_8
double v3; // xmm0_8
double v4; // [rsp+0h] [rbp-38h]
double v5; // [rsp+0h] [rbp-38h]
double v6; // [rsp+8h] [rbp-30h]
double v7; // [rsp+18h] [rbp-20h]

v6 = t2_distance_noPBC();
v4 = t2_f_cutoff(a1, a2);
v2 = v4;
if ( !(unsigned int)iszero() )
{
v7 = v4;
v5 = t2_f_repulsive(a1, a2, v6);
v3 = t2_b(a1, a2, v5, v6, v2);
*(double *)&U = (t2_f_attractive(a1, a2, v6) * v3 + v5) * v7 + *(double *)&U;
}
}

canonical_decompiled_code:
void __fastcall func0(unsigned int a1, unsigned int a2)
{
double v2; // xmm2_8
double v3; // xmm0_8
double v4; // [rsp+0h] [rbp-38h]
double v5; // [rsp+0h] [rbp-38h]
double v6; // [rsp+8h] [rbp-30h]
double v7; // [rsp+18h] [rbp-20h]

v6 = t2_distance_noPBC();
v4 = t2_f_cutoff(a1, a2);
v2 = v4;
if ( !(unsigned int)iszero() )
{
v7 = v4;
v5 = t2_f_repulsive(a1, a2, v6);
v3 = t2_b(a1, a2, v5, v6, v2);
*(double *)&U = (t2_f_attractive(a1, a2, v6) * v3 + v5) * v7 + *(double *)&U;
}
}

original_code:
static void tersoff2_energy_ij(int atom_i, int atom_j)
{
    double rij;
    double f_cutoff_val;
    rij = t2_distance_noPBC(atom_i, atom_j);
    f_cutoff_val = t2_f_cutoff(atom_i, atom_j, rij);
    if (!iszero(f_cutoff_val)) {
        double Uij;
        Uij = f_cutoff_val *
              (t2_f_repulsive(atom_i, atom_j, rij) +
               t2_b(atom_i, atom_j) *
               t2_f_attractive(atom_i, atom_j, rij));
        U += Uij;
    }
}

variable_types: rij double


decompiled_code:
void __noreturn tersoff2_energy()
{
celllist_scan_atoms(tersoff2_energy_ij);
exit(0);
}

canonical_decompiled_code:
void __noreturn func1()
{
celllist_scan_atoms(tersoff2_energy_ij);
exit(0);
}

original_code:
void tersoff2_energy()
{
    celllist_scan_atoms(tersoff2_energy_ij);
    exit(0);
}


decompiled_code:
int __fastcall print_array(unsigned int *a1, int a2)
{
__int64 v2; // rbp
unsigned int *v3; // rbx
__int64 v4; // rsi

if ( a2 > 0 )
{
v2 = (__int64)&a1[a2 - 1 + 1];
v3 = a1;
do
{
v4 = *v3++;
printf("%d ", v4);
}
while ( v3 != (unsigned int *)v2 );
}
return putchar(10);
}

canonical_decompiled_code:
int __fastcall func7(unsigned int *a1, int a2)
{
__int64 v2; // rbp
unsigned int *v3; // rbx
__int64 v4; // rsi

if ( a2 > 0 )
{
v2 = (__int64)&a1[a2 - 1 + 1];
v3 = a1;
do
{
v4 = *v3++;
printf("%d ", v4);
}
while ( v3 != (unsigned int *)v2 );
}
return putchar(10);
}

original_code:
void print_array(int a[], int num_elements){
   int i;
   for(i=0; i<num_elements; i++)
   {
     printf("%d ", a[i]);
   }
   printf("\n");
}

variable_types:
a
int []

variable_types: i int


decompiled_code:
__int64 __fastcall max_array(_DWORD *a1, int a2)
{
__int64 v2; // rcx
__int64 result; // rax

if ( a2 <= 0 )
return 4294935296LL;
v2 = (__int64)&a1[a2 - 1 + 1];
result = 4294935296LL;
do
{
if ( (int)result < *a1 )
result = (unsigned int)*a1;
++a1;
}
while ( a1 != (_DWORD *)v2 );
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(_DWORD *a1, int a2)
{
__int64 v2; // rcx
__int64 result; // rax

if ( a2 <= 0 )
return 4294935296LL;
v2 = (__int64)&a1[a2 - 1 + 1];
result = 4294935296LL;
do
{
if ( (int)result < *a1 )
result = (unsigned int)*a1;
++a1;
}
while ( a1 != (_DWORD *)v2 );
return result;
}

original_code:
int max_array(int a[], int num_elements){
   int i, max=-32000;
   for (i=0; i<num_elements; i++){
     if (a[i]>max){
        max=a[i];
     }
   }
   return(max);
}

canonical_original_code:
int max_array(int a[], int num_elements){
   int i; int max = -32000;
   for (i=0; i<num_elements; i++){
     if (a[i]>max){
        max=a[i];
     }
   }
   return(max);
}

variable_types: max int


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 i; // rbx
int v5[13]; // [rsp+0h] [rbp-9FBCh]
int v6[13]; // [rsp+4h] [rbp-9FB8h] BYREF
char v7[816]; // [rsp+34h] [rbp-9F88h] BYREF
char v8[40024]; // [rsp+364h] [rbp-9C58h] BYREF

for ( i = 1LL; i != 11; ++i )
v5[i] = atoi(argv[i]);
generator(v7, v6);
optimalAlgorithm(v7, v8);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 i; // rbx
int v5[13]; // [rsp+0h] [rbp-9FBCh]
int v6[13]; // [rsp+4h] [rbp-9FB8h] BYREF
char v7[816]; // [rsp+34h] [rbp-9F88h] BYREF
char v8[40024]; // [rsp+364h] [rbp-9C58h] BYREF

for ( i = 1LL; i != 11; ++i )
v5[i] = atoi(argv[i]);
generator(v7, v6);
func10(v7, v8);
return 0;
}

original_code:
int main(int argc, char *argv[]){
    int restr[10];
    int i;
    for(i=0; i <= 10 -1; i++){
        restr[i] = atoi(argv[i+1]);
    }
    knapsack sack = generator(restr);
    table t[50][50];
    optimalAlgorithm(&sack, t);
    return 0;
}

canonical_original_code:
int main(int argc, char *argv[]){
    int restr[10];
    int i;
    for(i=0; i <= 10 -1; i++){
        restr[i] = atoi(argv[i+1]);
    }
    struct struct2 sack = generator(restr);
    struct struct3 t[50][50];
    optimalAlgorithm(&sack, t);
    return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types:
restr
int [10]

variable_types: struct struct2 { int capacity; int objectsNum; struct struct1 { int name; int cost; int value; int copies; } objects[50]; }

variable_types: struct struct3 { int name; int value; int copiesNum; short color; } [50][50]

user_defined_types: struct struct2 { int capacity; int objectsNum; struct struct1 objects[50]; }


randomizer

decompiled_code:
__int64 __fastcall randomizer(int a1, int a2)
{
int v2; // er12
int v3; // eax

v2 = time(0LL);
v3 = rand();
srand(v3 + v2);
return (unsigned int)(rand() % (a1 + 1) + a2 - a1);
}

canonical_decompiled_code:
__int64 __fastcall func8(int a1, int a2)
{
int v2; // er12
int v3; // eax

v2 = time(0LL);
v3 = rand();
srand(v3 + v2);
return (unsigned int)(rand() % (a1 + 1) + a2 - a1);
}

original_code:
int randomizer(int min, int max){
    int x;
    srand (time(((void *)0))+rand());
    x = (int)(rand() % (min+1) + (max-min));
    return x;
}

variable_types: min int

variable_types: x int


main

repo: apk/asciztalker

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
char *v3; // rbp
__pid_t v4; // eax
int v5; // er12
int v6; // eax
int v7; // esi
int v8; // eax
__int64 v9; // rsi
int v10; // eax
__int64 v11; // rdx
__int64 i; // r15
int fds[2]; // [rsp+18h] [rbp-960h] BYREF
fd_set readfds; // [rsp+20h] [rbp-958h] BYREF
fd_set writefds; // [rsp+A0h] [rbp-8D8h] BYREF
char dest[1024]; // [rsp+120h] [rbp-858h] BYREF
int v17; // [rsp+520h] [rbp-458h]
unsigned int v18; // [rsp+524h] [rbp-454h]
char v19[1096]; // [rsp+530h] [rbp-448h] BYREF

v3 = getenv("yyx");
if ( socketpair(1, 1, 0, fds) == -1 )
{
perror("socketpair");
exit(1);
}
if ( !v3 )
{
fwrite("no target", 1uLL, 9uLL, stderr);
exit(1);
}
v4 = fork();
pid = v4;
if ( v4 == -1 )
{
perror("fork");
exit(1);
}
if ( !v4 )
{
dup2(fds[1], 0);
dup2(fds[1], 1);
close(fds[0]);
execvp(argv[1], (char *const *)argv + 1);
_exit(4);
}
v5 = 0;
buf_init(dest, v3);
buf_init(v19, v3);
buf_appendz();
close(fds[1]);
while ( 1 )
{
LABEL_8:
memset(&readfds, 0, sizeof(readfds));
memset(&writefds, 0, sizeof(writefds));
if ( v5 && (unsigned int)buf_rd_p(v19) )
readfds.fds_bits[0] |= 1uLL;
v6 = buf_wr_p(v19);
v7 = fds[0];
if ( v6 )
writefds.fds_bits[fds[0] / 64] |= 1LL << (fds[0] % 64);
if ( (unsigned int)buf_rd_p(dest) )
readfds.fds_bits[v7 / 64] |= 1LL << (v7 % 64);
if ( v5 && (unsigned int)buf_wr_p(dest) )
writefds.fds_bits[0] |= 2uLL;
v8 = select(v7 + 1, &readfds, &writefds, 0LL, 0LL);
if ( v8 == -1 )
break;
if ( !v8 )
{
fwrite("Oops\n", 1uLL, 5uLL, stderr);
LABEL_33:
kill(pid, 2);
exit(1);
}
if ( v5 && (readfds.fds_bits[0] & 1) != 0 )
buf_rd_x(v19, 0LL);
v9 = (unsigned int)fds[0];
v10 = fds[0] / 64;
v11 = 1LL << (fds[0] % 64);
if ( (writefds.fds_bits[fds[0] / 64] & v11) != 0 )
{
buf_wr_x(v19, fds[0]);
v9 = (unsigned int)fds[0];
v10 = fds[0] / 64;
v11 = 1LL << (fds[0] % 64);
}
if ( (readfds.fds_bits[v10] & v11) != 0 )
buf_rd_x(dest, v9);
if ( !v5 )
{
fprintf(stderr, "up: %d..%d\n", v18, (unsigned int)v17);
for ( i = (int)v18; ; ++i )
{
if ( v17 <= (int)i )
goto LABEL_8;
fprintf(stderr, " [%d]: %d\n", (unsigned int)i, (unsigned int)dest[i]);
if ( !dest[i] )
{
if ( v18 != (_DWORD)i )
{
fprintf(stderr, "FAIL '%s'\n", &dest[v18]);
goto LABEL_33;
}
++v18;
v5 = 1;
fwrite("Good!\n", 1uLL, 6uLL, stderr);
}
}
}
if ( (writefds.fds_bits[0] & 2) != 0 )
buf_wr_x(dest, 1);
}
perror("select");
goto LABEL_33;
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
char *v3; // rbp
__pid_t v4; // eax
int v5; // er12
int v6; // eax
int v7; // esi
int v8; // eax
__int64 v9; // rsi
int v10; // eax
__int64 v11; // rdx
__int64 i; // r15
int fds[2]; // [rsp+18h] [rbp-960h] BYREF
fd_set readfds; // [rsp+20h] [rbp-958h] BYREF
fd_set writefds; // [rsp+A0h] [rbp-8D8h] BYREF
char dest[1024]; // [rsp+120h] [rbp-858h] BYREF
int v17; // [rsp+520h] [rbp-458h]
unsigned int v18; // [rsp+524h] [rbp-454h]
char v19[1096]; // [rsp+530h] [rbp-448h] BYREF

v3 = getenv("yyx");
if ( socketpair(1, 1, 0, fds) == -1 )
{
perror("socketpair");
exit(1);
}
if ( !v3 )
{
fwrite("no target", 1uLL, 9uLL, stderr);
exit(1);
}
v4 = fork();
pid = v4;
if ( v4 == -1 )
{
perror("fork");
exit(1);
}
if ( !v4 )
{
dup2(fds[1], 0);
dup2(fds[1], 1);
close(fds[0]);
execvp(argv[1], (char *const *)argv + 1);
_exit(4);
}
v5 = 0;
func7(dest, v3);
func7(v19, v3);
func8();
close(fds[1]);
while ( 1 )
{
LABEL_8:
memset(&readfds, 0, sizeof(readfds));
memset(&writefds, 0, sizeof(writefds));
if ( v5 && (unsigned int)func9(v19) )
readfds.fds_bits[0] |= 1uLL;
v6 = func10(v19);
v7 = fds[0];
if ( v6 )
writefds.fds_bits[fds[0] / 64] |= 1LL << (fds[0] % 64);
if ( (unsigned int)func9(dest) )
readfds.fds_bits[v7 / 64] |= 1LL << (v7 % 64);
if ( v5 && (unsigned int)func10(dest) )
writefds.fds_bits[0] |= 2uLL;
v8 = select(v7 + 1, &readfds, &writefds, 0LL, 0LL);
if ( v8 == -1 )
break;
if ( !v8 )
{
fwrite("Oops\n", 1uLL, 5uLL, stderr);
LABEL_33:
kill(pid, 2);
exit(1);
}
if ( v5 && (readfds.fds_bits[0] & 1) != 0 )
func11(v19, 0LL);
v9 = (unsigned int)fds[0];
v10 = fds[0] / 64;
v11 = 1LL << (fds[0] % 64);
if ( (writefds.fds_bits[fds[0] / 64] & v11) != 0 )
{
func12(v19, fds[0]);
v9 = (unsigned int)fds[0];
v10 = fds[0] / 64;
v11 = 1LL << (fds[0] % 64);
}
if ( (readfds.fds_bits[v10] & v11) != 0 )
func11(dest, v9);
if ( !v5 )
{
fprintf(stderr, "up: %d..%d\n", v18, (unsigned int)v17);
for ( i = (int)v18; ; ++i )
{
if ( v17 <= (int)i )
goto LABEL_8;
fprintf(stderr, " [%d]: %d\n", (unsigned int)i, (unsigned int)dest[i]);
if ( !dest[i] )
{
if ( v18 != (_DWORD)i )
{
fprintf(stderr, "FAIL '%s'\n", &dest[v18]);
goto LABEL_33;
}
++v18;
v5 = 1;
fwrite("Good!\n", 1uLL, 6uLL, stderr);
}
}
}
if ( (writefds.fds_bits[0] & 2) != 0 )
func12(dest, 1);
}
perror("select");
goto LABEL_33;
}

original_code:
int main (int argc, char **argv) {
  int fds [2];
  char *tg = getenv ("yyx");
  int r = socketpair (1, SOCK_STREAM, 0, fds);
  if (r == -1) {
    perror ("socketpair");
    exit (1);
  }
  if (!tg) {
    fprintf (stderr, "no target");
    exit (1);
  }
  pid = fork ();
  if (pid == -1) {
    perror ("fork");
    exit (1);
  } else if (pid == 0) {
    dup2 (fds [1], 0);
    dup2 (fds [1], 1);
    close (fds [0]);
    execvp (argv [1], argv + 1);
    _exit (4);
  } else {
    int op = 0;
    struct buf up, down;
    buf_init (&up);
    buf_init (&down);
    buf_appendz (&down, tg);
    close (fds [1]);
    while (1) {
      fd_set R, W;
      do { int __d0, __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&R)->__fds_bits)[0]) : "memory"); } while (0);
      do { int __d0, __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&W)->__fds_bits)[0]) : "memory"); } while (0);
      if (op && buf_rd_p (&down)) {
 ((void) (((&R)->__fds_bits)[((0) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((0) % (8 * (int) sizeof (__fd_mask)))))));
      }
      if (buf_wr_p (&down)) {
 ((void) (((&W)->__fds_bits)[((fds [0]) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((fds [0]) % (8 * (int) sizeof (__fd_mask)))))));
      }
      if (buf_rd_p (&up)) {
 ((void) (((&R)->__fds_bits)[((fds [0]) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((fds [0]) % (8 * (int) sizeof (__fd_mask)))))));
      }
      if (op && buf_wr_p (&up)) {
 ((void) (((&W)->__fds_bits)[((1) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((1) % (8 * (int) sizeof (__fd_mask)))))));
      }
      r = select (fds [0] + 1, &R, &W, 0, 0);
      if (r == -1) {
 perror ("select");
 kill (pid, 2);
 exit (1);
      }
      if (r == 0) {
 fprintf (stderr, "Oops\n");
 kill (pid, 2);
 exit (1);
      }
      if (op && ((((&R)->__fds_bits)[((0) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((0) % (8 * (int) sizeof (__fd_mask)))))) != 0)) {
 buf_rd_x (&down, 0);
      }
      if (((((&W)->__fds_bits)[((fds [0]) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((fds [0]) % (8 * (int) sizeof (__fd_mask)))))) != 0)) {
 buf_wr_x (&down, fds [0]);
      }
      if (((((&R)->__fds_bits)[((fds [0]) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((fds [0]) % (8 * (int) sizeof (__fd_mask)))))) != 0)) {
 buf_rd_x (&up, fds [0]);
      }
      if (op && ((((&W)->__fds_bits)[((1) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((1) % (8 * (int) sizeof (__fd_mask)))))) != 0)) {
 buf_wr_x (&up, 1);
      }
      if (!op) {
 int i;
 fprintf (stderr, "up: %d..%d\n", up.pos, up.fill);
 for (i = up.pos; i < up.fill; i ++) {
   fprintf (stderr, "  [%d]: %d\n", i, up.buf [i]);
   if (up.buf [i] == 0) {
     if (i == up.pos) {
       up.pos ++;
       fprintf (stderr, "Good!\n");
       op = 1;
       continue;
     } else {
       fprintf (stderr, "FAIL '%s'\n", up.buf + up.pos);
       kill (pid, 2);
       exit (1);
     }
   }
 }
      }
    }
  }
  return 0;
}

canonical_original_code:
int main(int argc, char **argv) {
  int fds[2];
  char *tg = getenv ("yyx");
  int r = socketpair (1, SOCK_STREAM, 0, fds);
  if (r == -1) {
    perror ("socketpair");
    exit (1);
  }
  if (!tg) {
    fprintf (stderr, "no target");
    exit (1);
  }
  pid = fork ();
  if (pid == -1) {
    perror ("fork");
    exit (1);
  } else if (pid == 0) {
    dup2 (fds [1], 0);
    dup2 (fds [1], 1);
    close (fds [0]);
    execvp (argv [1], argv + 1);
    _exit (4);
  } else {
    int op = 0;
    struct buf up; struct buf down;
    buf_init (&up);
    buf_init (&down);
    buf_appendz (&down, tg);
    close (fds [1]);
    while (1) {
      struct fd_set R; struct fd_set W;
      do { int __d0; int __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&R)->__fds_bits)[0]) : "memory"); } while (0);
      do { int __d0; int __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&W)->__fds_bits)[0]) : "memory"); } while (0);
      if (op && buf_rd_p (&down)) {
 ((void) (((&R)->__fds_bits)[((0) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((0) % (8 * (int) sizeof (__fd_mask)))))));
      }
      if (buf_wr_p (&down)) {
 ((void) (((&W)->__fds_bits)[((fds [0]) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((fds [0]) % (8 * (int) sizeof (__fd_mask)))))));
      }
      if (buf_rd_p (&up)) {
 ((void) (((&R)->__fds_bits)[((fds [0]) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((fds [0]) % (8 * (int) sizeof (__fd_mask)))))));
      }
      if (op && buf_wr_p (&up)) {
 ((void) (((&W)->__fds_bits)[((1) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((1) % (8 * (int) sizeof (__fd_mask)))))));
      }
      r = select (fds [0] + 1, &R, &W, 0, 0);
      if (r == -1) {
 perror ("select");
 kill (pid, 2);
 exit (1);
      }
      if (r == 0) {
 fprintf (stderr, "Oops\n");
 kill (pid, 2);
 exit (1);
      }
      if (op && ((((&R)->__fds_bits)[((0) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((0) % (8 * (int) sizeof (__fd_mask)))))) != 0)) {
 buf_rd_x (&down, 0);
      }
      if (((((&W)->__fds_bits)[((fds [0]) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((fds [0]) % (8 * (int) sizeof (__fd_mask)))))) != 0)) {
 buf_wr_x (&down, fds [0]);
      }
      if (((((&R)->__fds_bits)[((fds [0]) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((fds [0]) % (8 * (int) sizeof (__fd_mask)))))) != 0)) {
 buf_rd_x (&up, fds [0]);
      }
      if (op && ((((&W)->__fds_bits)[((1) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((1) % (8 * (int) sizeof (__fd_mask)))))) != 0)) {
 buf_wr_x (&up, 1);
      }
      if (!op) {
 int i;
 fprintf (stderr, "up: %d..%d\n", up.pos, up.fill);
 for (i = up.pos; i < up.fill; i ++) {
   fprintf (stderr, "  [%d]: %d\n", i, up.buf [i]);
   if (up.buf [i] == 0) {
     if (i == up.pos) {
       up.pos ++;
       fprintf (stderr, "Good!\n");
       op = 1;
       continue;
     } else {
       fprintf (stderr, "FAIL '%s'\n", up.buf + up.pos);
       kill (pid, 2);
       exit (1);
     }
   }
 }
      }
    }
  }
  return 0;
}

variable_types:
argv
char **

variable_types:
fds
int [2]

variable_types:
tg
char *

variable_types: r int

variable_types: op int

variable_types: struct buf { char buf[1024]; int fill; int pos; }

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

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


decompiled_code:
void __fastcall buf_init(__int64 a1)
{
*(_QWORD *)(a1 + 1024) = 0LL;
}

canonical_decompiled_code:
void __fastcall func7(__int64 a1)
{
*(_QWORD *)(a1 + 1024) = 0LL;
}

original_code:
void buf_init (struct buf *b) {
  b->pos = 0;
  b->fill = 0;
}

canonical_original_code:
void buf_init(struct buf *b) {
  b->pos = 0;
  b->fill = 0;
}

variable_types: struct buf { char buf[1024]; int fill; int pos; } *


decompiled_code:
__int64 __fastcall buf_appendz(__int64 a1, __int64 a2)
{
__int64 result; // rax
__int64 v3; // rsi
char v4; // dl

result = *(int *)(a1 + 1024);
v3 = a2 - result;
do
{
if ( (unsigned int)result > 0x3FF )
{
fwrite("Overflow\n", 1uLL, 9uLL, stderr);
exit(1);
}
*(_DWORD *)(a1 + 1024) = result + 1;
v4 = *(_BYTE *)(v3 + result);
*(_BYTE *)(a1 + result++) = v4;
}
while ( v4 );
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1, __int64 a2)
{
__int64 result; // rax
__int64 v3; // rsi
char v4; // dl

result = *(int *)(a1 + 1024);
v3 = a2 - result;
do
{
if ( (unsigned int)result > 0x3FF )
{
fwrite("Overflow\n", 1uLL, 9uLL, stderr);
exit(1);
}
*(_DWORD *)(a1 + 1024) = result + 1;
v4 = *(_BYTE *)(v3 + result);
*(_BYTE *)(a1 + result++) = v4;
}
while ( v4 );
return result;
}

original_code:
void buf_appendz (struct buf *b, char *p) {
  do {
    if (b->fill >= sizeof (b->buf)) {
      fprintf (stderr, "Overflow\n");
      exit (1);
    }
  } while ((b->buf [b->fill ++] = *p ++));
}

canonical_original_code:
void buf_appendz(struct buf *b, char *p) {
  do {
    if (b->fill >= sizeof (b->buf)) {
      fprintf (stderr, "Overflow\n");
      exit (1);
    }
  } while ((b->buf [b->fill ++] = *p ++));
}

variable_types:
p
char *

user_defined_types: struct buf { char buf[1024]; int fill; int pos; }


decompiled_code:
_BOOL8 __fastcall buf_rd_p(__int64 a1)
{
return *(_DWORD *)(a1 + 1024) <= 0x3FFu;
}

canonical_decompiled_code:
_BOOL8 __fastcall func9(__int64 a1)
{
return *(_DWORD *)(a1 + 1024) <= 0x3FFu;
}

original_code:
int buf_rd_p (struct buf *b) {
  return b->fill < sizeof (b->buf);
}

canonical_original_code:
int buf_rd_p(struct buf *b) {
  return b->fill < sizeof (b->buf);
}


original_code:
int buf_wr_p (struct buf *b) {
  return b->pos < b->fill;
}

canonical_original_code:
int buf_wr_p(struct buf *b) {
  return b->pos < b->fill;
}


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

result = read(a2, (void *)(a1 + *(int *)(a1 + 1024)), 1024 - *(_DWORD *)(a1 + 1024));
if ( (_DWORD)result == -1 )
{
perror("read");
exit(1);
}
if ( !(_DWORD)result )
{
fwrite("EOF\n", 1uLL, 4uLL, stderr);
kill(pid, 2);
exit(1);
}
*(_DWORD *)(a1 + 1024) += result;
return result;
}

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

result = read(a2, (void *)(a1 + *(int *)(a1 + 1024)), 1024 - *(_DWORD *)(a1 + 1024));
if ( (_DWORD)result == -1 )
{
perror("read");
exit(1);
}
if ( !(_DWORD)result )
{
fwrite("EOF\n", 1uLL, 4uLL, stderr);
kill(pid, 2);
exit(1);
}
*(_DWORD *)(a1 + 1024) += result;
return result;
}

original_code:
void buf_rd_x (struct buf *b, int fd) {
  int sz = sizeof (b->buf) - b->fill;
  int r = read (fd, b->buf + b->fill, sz);
  if (r == -1) {
    perror ("read");
    exit (1);
  }
  if (r == 0) {
    fprintf (stderr, "EOF\n");
    kill (pid, 2);
    exit (1);
  }
  b->fill += r;
}

canonical_original_code:
void buf_rd_x(struct buf *b, int fd) {
  int sz = sizeof (b->buf) - b->fill;
  int r = read (fd, b->buf + b->fill, sz);
  if (r == -1) {
    perror ("read");
    exit (1);
  }
  if (r == 0) {
    fprintf (stderr, "EOF\n");
    kill (pid, 2);
    exit (1);
  }
  b->fill += r;
}

variable_types: fd int

variable_types: sz int


decompiled_code:
__int64 __fastcall buf_wr_x(void *dest, int fd)
{
int v2; // eax
__int64 result; // rax

v2 = write(fd, (char *)dest + *((int *)dest + 257), *((_DWORD *)dest + 256) - *((_DWORD *)dest + 257));
if ( v2 == -1 )
{
perror("read");
exit(1);
}
if ( !v2 )
{
fwrite("FULL?\n", 1uLL, 6uLL, stderr);
exit(1);
}
result = (unsigned int)(*((_DWORD *)dest + 257) + v2);
*((_DWORD *)dest + 257) = result;
if ( (unsigned int)result > 0x200 )
{
memmove(dest, (char *)dest + (int)result, *((_DWORD *)dest + 256) - (int)result);
result = *((unsigned int *)dest + 257);
*((_DWORD *)dest + 257) = 0;
*((_DWORD *)dest + 256) -= result;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func12(void *dest, int fd)
{
int v2; // eax
__int64 result; // rax

v2 = write(fd, (char *)dest + *((int *)dest + 257), *((_DWORD *)dest + 256) - *((_DWORD *)dest + 257));
if ( v2 == -1 )
{
perror("read");
exit(1);
}
if ( !v2 )
{
fwrite("FULL?\n", 1uLL, 6uLL, stderr);
exit(1);
}
result = (unsigned int)(*((_DWORD *)dest + 257) + v2);
*((_DWORD *)dest + 257) = result;
if ( (unsigned int)result > 0x200 )
{
memmove(dest, (char *)dest + (int)result, *((_DWORD *)dest + 256) - (int)result);
result = *((unsigned int *)dest + 257);
*((_DWORD *)dest + 257) = 0;
*((_DWORD *)dest + 256) -= result;
}
return result;
}

original_code:
void buf_wr_x (struct buf *b, int fd) {
  int sz = b->fill - b->pos;
  int r = write (fd, b->buf + b->pos, sz);
  if (r == -1) {
    perror ("read");
    exit (1);
  }
  if (r == 0) {
    fprintf (stderr, "FULL?\n");
    exit (1);
  }
  b->pos += r;
  if (b->pos > sizeof (b->buf) / 2) {
    memmove (b->buf, b->buf + b->pos, b->fill - b->pos);
    b->fill -= b->pos;
    b->pos = 0;
  }
}

canonical_original_code:
void buf_wr_x(struct buf *b, int fd) {
  int sz = b->fill - b->pos;
  int r = write (fd, b->buf + b->pos, sz);
  if (r == -1) {
    perror ("read");
    exit (1);
  }
  if (r == 0) {
    fprintf (stderr, "FULL?\n");
    exit (1);
  }
  b->pos += r;
  if (b->pos > sizeof (b->buf) / 2) {
    memmove (b->buf, b->buf + b->pos, b->fill - b->pos);
    b->fill -= b->pos;
    b->pos = 0;
  }
}