main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rdi
__int64 v4; // rbp
__int64 v5; // rdi
unsigned int v6; // eax
__int64 v7; // rbx

puts("[ Project Euler: Problem 10 ]\n\n");
clear_bitmap("[ Project Euler: Problem 10 ]\n\n", argv);
v3 = 0LL;
v4 = 2LL;
while ( 1 )
{
v6 = find(v3, 0LL);
v7 = v6;
if ( v6 > 0xF423E )
break;
v5 = 2LL * v6 + 3;
v4 += v5;
filter(v5);
v3 = v7 + 1;
}
printf("Total: %lu.\n", v4);
puts("\n\n[ done ]");
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rdi
__int64 v4; // rbp
__int64 v5; // rdi
unsigned int v6; // eax
__int64 v7; // rbx

puts("[ Project Euler: Problem 10 ]\n\n");
func8("[ Project Euler: Problem 10 ]\n\n", argv);
v3 = 0LL;
v4 = 2LL;
while ( 1 )
{
v6 = func12(v3, 0LL);
v7 = v6;
if ( v6 > 0xF423E )
break;
v5 = 2LL * v6 + 3;
v4 += v5;
func7(v5);
v3 = v7 + 1;
}
printf("Total: %lu.\n", v4);
puts("\n\n[ done ]");
return 0;
}

original_code:
int main(int argc, char** argv)
{
    printf("[ Project Euler: Problem 10 ]\n\n\n");
    natural total = 2;
    clear_bitmap();
    natural next_prime;
    natural prime_index = 0;
    while ((prime_index = find(prime_index, 0)) <= ((1999999 -3) / 2))
    {
      next_prime = (2*prime_index + 3);
      total += next_prime;
      filter(next_prime);
      prime_index++;
    }
    printf("Total: %lu.\n", total);
    printf("\n\n[ done ]\n");
    return 0;
}

canonical_original_code:
int main(int argc, char **argv)
{
    printf("[ Project Euler: Problem 10 ]\n\n\n");
    unsigned long total = 2;
    clear_bitmap();
    unsigned long next_prime;
    unsigned long prime_index = 0;
    while ((prime_index = find(prime_index, 0)) <= ((1999999 -3) / 2))
    {
      next_prime = (2*prime_index + 3);
      total += next_prime;
      filter(next_prime);
      prime_index++;
    }
    printf("Total: %lu.\n", total);
    printf("\n\n[ done ]\n");
    return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types:
total
unsigned long


segment

decompiled_code:
void *__fastcall segment(void *a1)
{
unsigned int v1; // er12
__int64 v2; // rbx
char v3; // bp
__int64 v4; // rsi
unsigned __int64 v5; // rax

if ( State <= 1 )
{
while ( 1 )
sched_yield();
}
v1 = *(_DWORD *)a1;
LABEL_16:
while ( State == 2 )
{
if ( v1 == 8 && (unsigned __int8)add(buff[0], transfer[0]) )
{
transfer[0] += 2LL;
if ( (unsigned int)listlength <= 8 )
goto LABEL_16;
LODWORD(v2) = 8;
v3 = 1;
}
else
{
LODWORD(v2) = v1;
v3 = 0;
if ( v1 >= listlength )
goto LABEL_20;
}
v2 = (int)v2;
do
{
v4 = transfer[v2];
if ( v4 )
{
if ( (unsigned __int8)add(buff[v2], v4) )
{
transfer[v2] = 0LL;
v3 = 1;
}
else if ( transfer[v2] )
{
goto LABEL_10;
}
}
v5 = get(buff[(int)v2 - 1]);
if ( v5 && v5 % prime[v2] )
{
transfer[v2] = v5;
v3 = 1;
}
LABEL_10:
v2 += 8LL;
}
while ( listlength > (unsigned int)v2 );
if ( v3 )
goto LABEL_16;
LABEL_20:
sched_yield();
}
return 0LL;
}

canonical_decompiled_code:
void *__fastcall func0(void *a1)
{
unsigned int v1; // er12
__int64 v2; // rbx
char v3; // bp
__int64 v4; // rsi
unsigned __int64 v5; // rax

if ( State <= 1 )
{
while ( 1 )
sched_yield();
}
v1 = *(_DWORD *)a1;
LABEL_16:
while ( State == 2 )
{
if ( v1 == 8 && (unsigned __int8)add(buff[0], transfer[0]) )
{
transfer[0] += 2LL;
if ( (unsigned int)listlength <= 8 )
goto LABEL_16;
LODWORD(v2) = 8;
v3 = 1;
}
else
{
LODWORD(v2) = v1;
v3 = 0;
if ( v1 >= listlength )
goto LABEL_20;
}
v2 = (int)v2;
do
{
v4 = transfer[v2];
if ( v4 )
{
if ( (unsigned __int8)add(buff[v2], v4) )
{
transfer[v2] = 0LL;
v3 = 1;
}
else if ( transfer[v2] )
{
goto LABEL_10;
}
}
v5 = get(buff[(int)v2 - 1]);
if ( v5 && v5 % prime[v2] )
{
transfer[v2] = v5;
v3 = 1;
}
LABEL_10:
v2 += 8LL;
}
while ( listlength > (unsigned int)v2 );
if ( v3 )
goto LABEL_16;
LABEL_20:
sched_yield();
}
return 0LL;
}

original_code:
void* segment(void* arg)
{
  int id = *((int*) arg);
  char progress = 0;
  while (State < 2)
  {
    sched_yield();
  }
  while (State == 2)
  {
    progress = 0;
    if (id == 8)
    {
      if (add(buff[0], transfer[0]))
      {
        transfer[0] += 2;
        progress = 1;
      }
    }
    unsigned long x;
    for (int pos = id; pos < listlength; pos += 8)
    {
      if ((x = transfer[pos]))
      {
        if (add(buff[pos], x))
        {
          transfer[pos] = 0;
          progress = 1;
        }
      }
      if (transfer[pos] == 0)
      {
        if ((x = get(buff[pos - 1])))
        {
          if (x % prime[pos] != 0)
          {
            transfer[pos] = x;
            progress = 1;
          }
        }
      }
    }
    if (!progress)
    {
      sched_yield();
    }
  }
  return ((void *)0);
}

canonical_original_code:
void *segment(void *arg)
{
  int id = *((int*) arg);
  char progress = 0;
  while (State < 2)
  {
    sched_yield();
  }
  while (State == 2)
  {
    progress = 0;
    if (id == 8)
    {
      if (add(buff[0], transfer[0]))
      {
        transfer[0] += 2;
        progress = 1;
      }
    }
    unsigned long x;
    for (int pos = id; pos < listlength; pos += 8)
    {
      if ((x = transfer[pos]))
      {
        if (add(buff[pos], x))
        {
          transfer[pos] = 0;
          progress = 1;
        }
      }
      if (transfer[pos] == 0)
      {
        if ((x = get(buff[pos - 1])))
        {
          if (x % prime[pos] != 0)
          {
            transfer[pos] = x;
            progress = 1;
          }
        }
      }
    }
    if (!progress)
    {
      sched_yield();
    }
  }
  return ((void *)0);
}

variable_types:
arg
void *

variable_types: id int

variable_types: progress char

variable_types:
x
unsigned long

variable_types: pos int

return_type: void *


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

if ( listlength > (unsigned int)&unk_1000000 )
{
printf("{ error } All %lu primes calculated.\n", &unk_1000000);
result = 1LL;
}
else
{
result = get(buff[listlength - 1]);
prime[listlength] = result;
}
return result;
}

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

if ( listlength > (unsigned int)&unk_1000000 )
{
printf("{ error } All %lu primes calculated.\n", &unk_1000000);
result = 1LL;
}
else
{
result = get(buff[listlength - 1]);
prime[listlength] = result;
}
return result;
}

original_code:
unsigned long get_prime()
{
  if (listlength > 16777216)
  {
    printf("{ error } All %lu primes calculated.\n", (unsigned long) 16777216);
    return 1;
  }
  unsigned long p = get(buff[listlength - 1]);
  prime[listlength] = p;
  return p;
}

variable_types:
p
unsigned long

return_type: unsigned long


advance

decompiled_code:
int advance()
{
int v0; // ebx
__int64 v1; // rax

v0 = listlength;
if ( prime[listlength] )
{
if ( listlength > (unsigned int)&unk_FFFFFF )
{
LODWORD(v1) = puts("{ warning } Cannot advance; already full.");
}
else
{
v1 = init_buffer();
buff[v0] = v1;
++listlength;
}
}
else
{
LODWORD(v1) = puts("{ warning } Prime not yet calculated.");
}
return v1;
}

canonical_decompiled_code:
int func2()
{
int v0; // ebx
__int64 v1; // rax

v0 = listlength;
if ( prime[listlength] )
{
if ( listlength > (unsigned int)&unk_FFFFFF )
{
LODWORD(v1) = puts("{ warning } Cannot advance; already full.");
}
else
{
v1 = init_buffer();
buff[v0] = v1;
++listlength;
}
}
else
{
LODWORD(v1) = puts("{ warning } Prime not yet calculated.");
}
return v1;
}

original_code:
void advance()
{
  if (!prime[listlength])
  {
    printf("{ warning } Prime not yet calculated.\n");
    return;
  }
  if (listlength >= 16777216)
  {
    printf("{ warning } Cannot advance; already full.\n");
    return;
  }
  buff[listlength] = init_buffer();
  listlength++;
}

return_type: void


decompiled_code:
int init_sieve()
{
unsigned __int64 v0; // rax
_DWORD *v1; // rbp
__int64 i; // rbx
int result; // eax

if ( State )
return puts("{ warning } Sieve already initialised.");
prime[0] = 2LL;
transfer[0] = 3LL;
buff[0] = init_buffer();
v0 = 8LL;
do
{
prime[v0 / 8] = 0LL;
transfer[v0 / 8] = 0LL;
buff[v0 / 8] = 0LL;
v0 += 8LL;
}
while ( (_UNKNOWN *)v0 != &unk_8000000 );
listlength = 1;
pthread_attr_init(&ptattr);
pthread_attr_setscope(&ptattr, 0);
v1 = &PTID;
for ( i = 0LL; i != 8; ++i )
{
*v1 = i + 1;
result = pthread_create(&PT[i], &ptattr, segment, v1);
if ( result )
{
printf("{ fatal error } Could not create pthread %d.\n", (unsigned int)i);
exit(-1);
}
++v1;
}
State = 1;
return result;
}

canonical_decompiled_code:
int func3()
{
unsigned __int64 v0; // rax
_DWORD *v1; // rbp
__int64 i; // rbx
int result; // eax

if ( State )
return puts("{ warning } Sieve already initialised.");
prime[0] = 2LL;
transfer[0] = 3LL;
buff[0] = init_buffer();
v0 = 8LL;
do
{
prime[v0 / 8] = 0LL;
transfer[v0 / 8] = 0LL;
buff[v0 / 8] = 0LL;
v0 += 8LL;
}
while ( (_UNKNOWN *)v0 != &unk_8000000 );
listlength = 1;
pthread_attr_init(&ptattr);
pthread_attr_setscope(&ptattr, 0);
v1 = &PTID;
for ( i = 0LL; i != 8; ++i )
{
*v1 = i + 1;
result = pthread_create(&PT[i], &ptattr, segment, v1);
if ( result )
{
printf("{ fatal error } Could not create pthread %d.\n", (unsigned int)i);
exit(-1);
}
++v1;
}
State = 1;
return result;
}

original_code:
void init_sieve()
{
  if (State != 0)
  {
    printf("{ warning } Sieve already initialised.\n");
    return;
  }
  prime[0] = 2;
  transfer[0] = 3;
  buff[0] = init_buffer();
  for (int i = 1; i < 16777216; i++)
  {
    prime[i] = 0;
    transfer[i] = 0;
    buff[i] = ((void *)0);
  }
  listlength = 1;
  pthread_attr_init(&ptattr);
  pthread_attr_setscope(&ptattr, PTHREAD_SCOPE_SYSTEM);
  for (int i = 0; i < 8; i++)
  {
    PTID[i] = i + 1;
    if (pthread_create(&PT[i], &ptattr, &segment, &PTID[i]))
    {
      printf("{ fatal error } Could not create pthread %d.\n", i);
      exit(-1);
    }
  }
  State = 1;
}

variable_types: i int


decompiled_code:
int free_sieve()
{
__int64 v0; // rbx
int result; // eax
__int64 *v2; // rbx

v0 = 0LL;
if ( State != 3 )
return puts("{ warning } Sieve has not finished or already freed.");
do
{
if ( pthread_join(PT[v0], 0LL) )
printf("{ error } Could not join pthread %d.\n", (unsigned int)v0);
++v0;
}
while ( v0 != 8 );
v2 = buff;
do
{
if ( *v2 )
free_buffer();
++v2;
}
while ( v2 != (__int64 *)((char *)&unk_8000000 + (_QWORD)buff) );
result = pthread_attr_destroy(&ptattr);
State = 4;
return result;
}

canonical_decompiled_code:
int func4()
{
__int64 v0; // rbx
int result; // eax
__int64 *v2; // rbx

v0 = 0LL;
if ( State != 3 )
return puts("{ warning } Sieve has not finished or already freed.");
do
{
if ( pthread_join(PT[v0], 0LL) )
printf("{ error } Could not join pthread %d.\n", (unsigned int)v0);
++v0;
}
while ( v0 != 8 );
v2 = buff;
do
{
if ( *v2 )
free_buffer();
++v2;
}
while ( v2 != (__int64 *)((char *)&unk_8000000 + (_QWORD)buff) );
result = pthread_attr_destroy(&ptattr);
State = 4;
return result;
}

original_code:
void free_sieve()
{
  if (State != 3)
  {
    printf("{ warning } Sieve has not finished or already freed.\n");
    return;
  }
  for (int i = 0; i < 8; i++)
  {
    if (pthread_join(PT[i], ((void *)0)))
    {
      printf("{ error } Could not join pthread %d.\n", i);
    }
  }
  for (int i = 0; i < 16777216; i++)
  {
    if (buff[i])
    {
      free_buffer(buff[i]);
    }
  }
  pthread_attr_destroy(&ptattr);
  State = 4;
}


start

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

if ( State != 1 )
return puts("{ warning } Sieve not yet ready or already started.");
State = 2;
return result;
}

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

if ( State != 1 )
return puts("{ warning } Sieve not yet ready or already started.");
State = 2;
return result;
}

original_code:
void start()
{
  if (State == 1)
  {
    State = 2;
  }
  else
  {
    printf("{ warning } Sieve not yet ready or already started.\n");
  }
}


end

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

if ( State != 2 )
return puts("{ warning } Sieve not running.");
State = 3;
return result;
}

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

if ( State != 2 )
return puts("{ warning } Sieve not running.");
State = 3;
return result;
}

original_code:
void end()
{
  if (State == 2)
  {
    State = 3;
  }
  else
  {
    printf("{ warning } Sieve not running.\n");
  }
}


start

decompiled_code:
// positive sp value has been detected, the output may be wrong!
void __fastcall __noreturn start(__int64 a1, __int64 a2, void (*a3)(void))
{
__int64 v3; // rax
int v4; // esi
__int64 v5; // [rsp-8h] [rbp-8h] BYREF
char *retaddr; // [rsp+0h] [rbp+0h] BYREF

v4 = v5;
v5 = v3;
_libc_start_main(
(int (__fastcall *)(int, char **, char **))main,
v4,
&retaddr,
_libc_csu_init,
_libc_csu_fini,
a3,
&v5);
__halt();
}

canonical_decompiled_code:
void __fastcall __noreturn func1(__int64 a1, __int64 a2, void (*a3)(void))
{
__int64 v3; // rax
int v4; // esi
__int64 v5; // [rsp-8h] [rbp-8h] BYREF
char *retaddr; // [rsp+0h] [rbp+0h] BYREF

v4 = v5;
v5 = v3;
_libc_start_main(
(int (__fastcall *)(int, char **, char **))main,
v4,
&retaddr,
_libc_csu_init,
_libc_csu_fini,
a3,
&v5);
__halt();
}

canonical_original_code:
void start()
{
  if (State == 1)
  {
    State = 2;
  }
  else
  {
    printf("{ warning } Sieve not yet ready or already started.\n");
  }
}


decompiled_code:
int print_names()
{
const char *v0; // rbp
unsigned int v1; // ebx

printf("Names:\t\t");
if ( nNames )
{
v0 = name;
v1 = 0;
do
{
printf("%12s,\t", v0);
++v1;
v0 += 12;
}
while ( nNames > v1 );
}
return puts("\tend.");
}

canonical_decompiled_code:
int func7()
{
const char *v0; // rbp
unsigned int v1; // ebx

printf("Names:\t\t");
if ( nNames )
{
v0 = name;
v1 = 0;
do
{
printf("%12s,\t", v0);
++v1;
v0 += 12;
}
while ( nNames > v1 );
}
return puts("\tend.");
}

original_code:
void print_names()
{
  printf("Names:\t\t");
  for (int i = 0; i < nNames; i++)
  {
    printf("%12s,\t", name[i]);
  }
  printf("\tend.\n");
}


decompiled_code:
_DWORD *init_buffer()
{
_DWORD *v0; // rax
_DWORD *v1; // rbx
pthread_mutex_t *v2; // rax

v0 = malloc(0x810uLL);
if ( !v0 )
{
puts("{ fatal error } Could not allocate buffer.");
exit(-1);
}
v1 = v0;
v0[512] = 0;
v0[513] = 0;
v2 = (pthread_mutex_t *)malloc(0x28uLL);
*((_QWORD *)v1 + 257) = v2;
pthread_mutex_init(v2, 0LL);
return v1;
}

canonical_decompiled_code:
_DWORD *func0()
{
_DWORD *v0; // rax
_DWORD *v1; // rbx
pthread_mutex_t *v2; // rax

v0 = malloc(0x810uLL);
if ( !v0 )
{
puts("{ fatal error } Could not allocate buffer.");
exit(-1);
}
v1 = v0;
v0[512] = 0;
v0[513] = 0;
v2 = (pthread_mutex_t *)malloc(0x28uLL);
*((_QWORD *)v1 + 257) = v2;
pthread_mutex_init(v2, 0LL);
return v1;
}

original_code:
buffer* init_buffer()
{
  buffer* B = malloc(sizeof(buffer));
  if (!B)
  {
    printf("{ fatal error } Could not allocate buffer.\n");
    exit(-1);
  }
  B->index = 0;
  B->size = 0;
  B->bufferlock = malloc(sizeof(pthread_mutex_t));
  pthread_mutex_init(B->bufferlock, ((void *)0));
  return B;
}

canonical_original_code:
struct buffer *init_buffer()
{
  struct buffer *B = malloc(sizeof(buffer));
  if (!B)
  {
    printf("{ fatal error } Could not allocate buffer.\n");
    exit(-1);
  }
  B->index = 0;
  B->size = 0;
  B->bufferlock = malloc(sizeof(pthread_mutex_t));
  pthread_mutex_init(B->bufferlock, ((void *)0));
  return B;
}

variable_types: struct buffer { unsigned long data[-1]; unsigned int index; union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } *bufferlock; } *

user_defined_types: struct buffer { unsigned long data[-1]; unsigned int index; union pthread_mutex_t *bufferlock; }

user_defined_types: union pthread_mutex_t { struct __pthread_mutex_s __data; char __size[40]; long __align; }

user_defined_types: struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list __list; }


decompiled_code:
void __fastcall free_buffer(void *ptr)
{
if ( ptr )
{
pthread_mutex_destroy(*((pthread_mutex_t **)ptr + 257));
free(*((void **)ptr + 257));
free(ptr);
}
}

canonical_decompiled_code:
void __fastcall func1(void *ptr)
{
if ( ptr )
{
pthread_mutex_destroy(*((pthread_mutex_t **)ptr + 257));
free(*((void **)ptr + 257));
free(ptr);
}
}

original_code:
void free_buffer(buffer* B)
{
  if (B)
  {
    pthread_mutex_destroy(B->bufferlock);
    free(B->bufferlock);
    free(B);
  }
}

canonical_original_code:
void free_buffer(struct buffer *B)
{
  if (B)
  {
    pthread_mutex_destroy(B->bufferlock);
    free(B->bufferlock);
    free(B);
  }
}

user_defined_types: struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; }


add

decompiled_code:
__int64 __fastcall add(__int64 a1, __int64 a2)
{
unsigned int v2; // eax
__int64 result; // rax

if ( a1 )
{
pthread_mutex_lock(*(pthread_mutex_t **)(a1 + 2056));
v2 = *(_DWORD *)(a1 + 2052);
if ( v2 <= 0xFF )
{
*(_QWORD *)(a1 + 8LL * (unsigned __int8)(*(_BYTE *)(a1 + 2048) + v2)) = a2;
*(_DWORD *)(a1 + 2052) = v2 + 1;
pthread_mutex_unlock(*(pthread_mutex_t **)(a1 + 2056));
result = 1LL;
}
else
{
pthread_mutex_unlock(*(pthread_mutex_t **)(a1 + 2056));
result = 0LL;
}
}
else
{
puts("{ error } This is not a buffer.");
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int64 a2)
{
unsigned int v2; // eax
__int64 result; // rax

if ( a1 )
{
pthread_mutex_lock(*(pthread_mutex_t **)(a1 + 2056));
v2 = *(_DWORD *)(a1 + 2052);
if ( v2 <= 0xFF )
{
*(_QWORD *)(a1 + 8LL * (unsigned __int8)(*(_BYTE *)(a1 + 2048) + v2)) = a2;
*(_DWORD *)(a1 + 2052) = v2 + 1;
pthread_mutex_unlock(*(pthread_mutex_t **)(a1 + 2056));
result = 1LL;
}
else
{
pthread_mutex_unlock(*(pthread_mutex_t **)(a1 + 2056));
result = 0LL;
}
}
else
{
puts("{ error } This is not a buffer.");
result = 0LL;
}
return result;
}

original_code:
char add(buffer* B, unsigned long x)
{
  if (!B)
  {
    printf("{ error } This is not a buffer.\n");
    return 0;
  }
  pthread_mutex_lock(B->bufferlock);
  if (B->size < (1<<8))
  {
    B->data[(B->index + B->size) % (1<<8)] = x;
    B->size += 1;
    pthread_mutex_unlock(B->bufferlock);
    return 1;
  }
  pthread_mutex_unlock(B->bufferlock);
  return 0;
}

canonical_original_code:
char add(struct buffer *B, unsigned long x)
{
  if (!B)
  {
    printf("{ error } This is not a buffer.\n");
    return 0;
  }
  pthread_mutex_lock(B->bufferlock);
  if (B->size < (1<<8))
  {
    B->data[(B->index + B->size) % (1<<8)] = x;
    B->size += 1;
    pthread_mutex_unlock(B->bufferlock);
    return 1;
  }
  pthread_mutex_unlock(B->bufferlock);
  return 0;
}

return_type: char


get

decompiled_code:
__int64 __fastcall get(__int64 a1)
{
int v1; // eax
__int64 v2; // rbp
__int64 v4; // rcx

if ( a1 )
{
pthread_mutex_lock(*(pthread_mutex_t **)(a1 + 2056));
v1 = *(_DWORD *)(a1 + 2052);
if ( v1 )
{
v4 = *(unsigned int *)(a1 + 2048);
v2 = *(_QWORD *)(a1 + 8 * v4);
*(_DWORD *)(a1 + 2048) = (unsigned __int8)(v4 + 1);
*(_DWORD *)(a1 + 2052) = v1 - 1;
pthread_mutex_unlock(*(pthread_mutex_t **)(a1 + 2056));
}
else
{
pthread_mutex_unlock(*(pthread_mutex_t **)(a1 + 2056));
v2 = 0LL;
}
}
else
{
puts("{ error } This is not a buffer.");
v2 = 0LL;
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
int v1; // eax
__int64 v2; // rbp
__int64 v4; // rcx

if ( a1 )
{
pthread_mutex_lock(*(pthread_mutex_t **)(a1 + 2056));
v1 = *(_DWORD *)(a1 + 2052);
if ( v1 )
{
v4 = *(unsigned int *)(a1 + 2048);
v2 = *(_QWORD *)(a1 + 8 * v4);
*(_DWORD *)(a1 + 2048) = (unsigned __int8)(v4 + 1);
*(_DWORD *)(a1 + 2052) = v1 - 1;
pthread_mutex_unlock(*(pthread_mutex_t **)(a1 + 2056));
}
else
{
pthread_mutex_unlock(*(pthread_mutex_t **)(a1 + 2056));
v2 = 0LL;
}
}
else
{
puts("{ error } This is not a buffer.");
v2 = 0LL;
}
return v2;
}

original_code:
unsigned long get(buffer* B)
{
  if (!B)
  {
    printf("{ error } This is not a buffer.\n");
    return 0;
  }
  pthread_mutex_lock(B->bufferlock);
  if (B->size > 0)
  {
    unsigned long x = B->data[B->index];
    B->index = (B->index + 1) % (1<<8);
    B->size -= 1;
    pthread_mutex_unlock(B->bufferlock);
    return x;
  }
  pthread_mutex_unlock(B->bufferlock);
  return 0;
}

canonical_original_code:
unsigned long get(struct buffer *B)
{
  if (!B)
  {
    printf("{ error } This is not a buffer.\n");
    return 0;
  }
  pthread_mutex_lock(B->bufferlock);
  if (B->size > 0)
  {
    unsigned long x = B->data[B->index];
    B->index = (B->index + 1) % (1<<8);
    B->size -= 1;
    pthread_mutex_unlock(B->bufferlock);
    return x;
  }
  pthread_mutex_unlock(B->bufferlock);
  return 0;
}


decompiled_code:
__int64 __fastcall socket_open(int a1, int a2, int a3)
{
int v3; // ebx

v3 = socket(a1, a2, a3);
if ( v3 < 0 )
perror("socket open error");
return (unsigned int)v3;
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1, int a2, int a3)
{
int v3; // ebx

v3 = socket(a1, a2, a3);
if ( v3 < 0 )
perror("socket open error");
return (unsigned int)v3;
}

original_code:
int socket_open(int family, int type, int protocol)
{
    int n;
    if ((n = socket(family, type, protocol)) < 0) {
        perror("socket open error");
    }
    return n;
}

variable_types: family int

variable_types: type int

variable_types: protocol int

variable_types: n int

return_type: int


decompiled_code:
void __fastcall socket_close(int a1)
{
if ( close(a1) == -1 )
perror("socket close error");
}

canonical_decompiled_code:
void __fastcall func1(int a1)
{
if ( close(a1) == -1 )
perror("socket close error");
}

original_code:
void socket_close(int fd)
{
    if (close(fd) == -1) {
        perror("socket close error");
    }
    return;
}

variable_types: fd int


decompiled_code:
__int64 __fastcall socket_accept(int fd, struct sockaddr *addr, socklen_t *addr_len)
{
int v4; // ebx
int v5; // eax

while ( 1 )
{
v4 = accept(fd, addr, addr_len);
if ( v4 >= 0 )
break;
v5 = *_errno_location();
if ( v5 != 103 && v5 != 4 )
{
perror("socket accept error");
return (unsigned int)v4;
}
}
return (unsigned int)v4;
}

canonical_decompiled_code:
__int64 __fastcall func2(int fd, struct sockaddr *addr, socklen_t *addr_len)
{
int v4; // ebx
int v5; // eax

while ( 1 )
{
v4 = accept(fd, addr, addr_len);
if ( v4 >= 0 )
break;
v5 = *_errno_location();
if ( v5 != 103 && v5 != 4 )
{
perror("socket accept error");
return (unsigned int)v4;
}
}
return (unsigned int)v4;
}

original_code:
int socket_accept(int fd, struct sockaddr *addr, socklen_t *len)
{
    int n;
again:
    if ((n = accept(fd, addr, len)) < 0) {
        if (((*__errno_location ()) == 103) || ((*__errno_location ()) == 4)) {
            goto again;
        } else {
            perror("socket accept error");
        }
    }
    return n;
}

canonical_original_code:
int socket_accept(int fd, struct sockaddr *addr, unsigned int *len)
{
    int n;
again:
    if ((n = accept(fd, addr, len)) < 0) {
        if (((*__errno_location ()) == 103) || ((*__errno_location ()) == 4)) {
            goto again;
        } else {
            perror("socket accept error");
        }
    }
    return n;
}

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

variable_types:
len
unsigned int *


decompiled_code:
void __fastcall socket_bind(int a1, const struct sockaddr *a2, socklen_t a3)
{
if ( bind(a1, a2, a3) < 0 )
perror("socket bind error");
}

canonical_decompiled_code:
void __fastcall func3(int a1, const struct sockaddr *a2, socklen_t a3)
{
if ( bind(a1, a2, a3) < 0 )
perror("socket bind error");
}

original_code:
void socket_bind(int fd, const struct sockaddr *addr, socklen_t len)
{
    if (bind(fd, addr, len) < 0) {
        perror("socket bind error");
    }
    return;
}

canonical_original_code:
void socket_bind(int fd, struct sockaddr *addr, unsigned int len)
{
    if (bind(fd, addr, len) < 0) {
        perror("socket bind error");
    }
    return;
}

variable_types:
len
unsigned int

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


decompiled_code:
void __fastcall socket_connect(int a1, const struct sockaddr *a2, socklen_t a3)
{
if ( connect(a1, a2, a3) < 0 )
perror("socket connect error");
}

canonical_decompiled_code:
void __fastcall func4(int a1, const struct sockaddr *a2, socklen_t a3)
{
if ( connect(a1, a2, a3) < 0 )
perror("socket connect error");
}

original_code:
void socket_connect(int fd, const struct sockaddr *addr, socklen_t len)
{
    if (connect(fd, addr, len) < 0) {
        perror("socket connect error");
    }
    return;
}

canonical_original_code:
void socket_connect(int fd, struct sockaddr *addr, unsigned int len)
{
    if (connect(fd, addr, len) < 0) {
        perror("socket connect error");
    }
    return;
}


decompiled_code:
void __fastcall socket_listen(int a1, int a2)
{
if ( listen(a1, a2) < 0 )
perror("socket listen error");
}

canonical_decompiled_code:
void __fastcall func5(int a1, int a2)
{
if ( listen(a1, a2) < 0 )
perror("socket listen error");
}

original_code:
void socket_listen(int fd, int backlog)
{
    if (listen(fd, backlog) < 0) {
        perror("socket listen error");
    }
    return ;
}

variable_types: backlog int


decompiled_code:
ssize_t __fastcall socket_read(int fd, void *buf, size_t nbytes)
{
ssize_t v4; // rbx

do
v4 = read(fd, buf, nbytes);
while ( v4 == -1 && *_errno_location() == 4 );
return v4;
}

canonical_decompiled_code:
ssize_t __fastcall func6(int fd, void *buf, size_t nbytes)
{
ssize_t v4; // rbx

do
v4 = read(fd, buf, nbytes);
while ( v4 == -1 && *_errno_location() == 4 );
return v4;
}

original_code:
ssize_t socket_read(int fd, void *buf, size_t nbytes)
{
    ssize_t n;
again:
    if ((n = read(fd, buf, nbytes)) == -1) {
        if ((*__errno_location ()) == 4) {
            goto again;
        } else {
            return -1;
        }
    }
    return n;
}

canonical_original_code:
long socket_read(int fd, void *buf, unsigned long nbytes)
{
    long n;
again:
    if ((n = read(fd, buf, nbytes)) == -1) {
        if ((*__errno_location ()) == 4) {
            goto again;
        } else {
            return -1;
        }
    }
    return n;
}

variable_types:
buf
void *

variable_types:
nbytes
unsigned long

variable_types: n long

return_type: long


decompiled_code:
size_t __fastcall socket_readn(int fd, void *buf, size_t nbytes)
{
size_t v3; // r13
size_t v4; // rbx
ssize_t v5; // rax

v3 = nbytes;
if ( nbytes )
{
v4 = nbytes;
while ( 1 )
{
v5 = read(fd, buf, v4);
if ( v5 < 0 )
{
if ( *_errno_location() != 4 )
return -1LL;
v5 = 0LL;
}
else if ( !v5 )
{
return v3 - v4;
}
v4 -= v5;
if ( !v4 )
return v3 - v4;
}
}
v4 = 0LL;
return v3 - v4;
}

canonical_decompiled_code:
size_t __fastcall func7(int fd, void *buf, size_t nbytes)
{
size_t v3; // r13
size_t v4; // rbx
ssize_t v5; // rax

v3 = nbytes;
if ( nbytes )
{
v4 = nbytes;
while ( 1 )
{
v5 = read(fd, buf, v4);
if ( v5 < 0 )
{
if ( *_errno_location() != 4 )
return -1LL;
v5 = 0LL;
}
else if ( !v5 )
{
return v3 - v4;
}
v4 -= v5;
if ( !v4 )
return v3 - v4;
}
}
v4 = 0LL;
return v3 - v4;
}

original_code:
ssize_t socket_readn(int fd, void *buf, size_t n)
{
    size_t nleft;
    ssize_t nread;
    char *p;
    p = buf;
    nleft = n;
    while (nleft > 0) {
        if ((nread = read(fd, buf, nleft)) < 0) {
            if ((*__errno_location ()) == 4) {
                nread = 0;
            } else {
                return -1;
            }
        } else if (nread == 0) {
            break;
        }
        nleft -= nread;
        p += nread;
    }
    return n - nleft;
}

canonical_original_code:
long socket_readn(int fd, void *buf, unsigned long n)
{
    unsigned long nleft;
    long nread;
    char *p;
    p = buf;
    nleft = n;
    while (nleft > 0) {
        if ((nread = read(fd, buf, nleft)) < 0) {
            if ((*__errno_location ()) == 4) {
                nread = 0;
            } else {
                return -1;
            }
        } else if (nread == 0) {
            break;
        }
        nleft -= nread;
        p += nread;
    }
    return n - nleft;
}

variable_types:
n
unsigned long

variable_types:
nleft
unsigned long

variable_types: nread long

variable_types:
p
char *


decompiled_code:
ssize_t __fastcall socket_write(int fd, void *buf, size_t n)
{
ssize_t v4; // rbx

do
v4 = write(fd, buf, n);
while ( v4 == -1 && *_errno_location() == 4 );
return v4;
}

canonical_decompiled_code:
ssize_t __fastcall func8(int fd, void *buf, size_t n)
{
ssize_t v4; // rbx

do
v4 = write(fd, buf, n);
while ( v4 == -1 && *_errno_location() == 4 );
return v4;
}

original_code:
ssize_t socket_write(int fd, const void *buf, size_t nbytes)
{
    ssize_t n;
again:
    if ((n = write(fd, buf, nbytes)) == -1) {
        if ((*__errno_location ()) == 4) {
            goto again;
        } else {
            return -1;
        }
    }
    return n;
}

canonical_original_code:
long socket_write(int fd, void *buf, unsigned long nbytes)
{
    long n;
again:
    if ((n = write(fd, buf, nbytes)) == -1) {
        if ((*__errno_location ()) == 4) {
            goto again;
        } else {
            return -1;
        }
    }
    return n;
}


decompiled_code:
size_t __fastcall socket_writen(int fd, void *buf, size_t n)
{
size_t v3; // r13
size_t v4; // rbx
ssize_t v5; // rax

v3 = n;
if ( !n )
return v3;
v4 = n;
while ( 1 )
{
v5 = write(fd, buf, v4);
if ( v5 <= 0 )
break;
LABEL_3:
v4 -= v5;
if ( !v4 )
return v3;
}
if ( v5 >= 0 )
return -1LL;
if ( *_errno_location() == 4 )
{
v5 = 0LL;
goto LABEL_3;
}
return -1LL;
}

canonical_decompiled_code:
size_t __fastcall func9(int fd, void *buf, size_t n)
{
size_t v3; // r13
size_t v4; // rbx
ssize_t v5; // rax

v3 = n;
if ( !n )
return v3;
v4 = n;
while ( 1 )
{
v5 = write(fd, buf, v4);
if ( v5 <= 0 )
break;
LABEL_3:
v4 -= v5;
if ( !v4 )
return v3;
}
if ( v5 >= 0 )
return -1LL;
if ( *_errno_location() == 4 )
{
v5 = 0LL;
goto LABEL_3;
}
return -1LL;
}

original_code:
ssize_t socket_writen(int fd, const void *buf, size_t n)
{
    size_t nleft;
    ssize_t nwritten;
    const char *p;
    p = buf;
    nleft = n;
    while (nleft > 0) {
        if ((nwritten = write(fd, buf, nleft)) <= 0) {
            if (nwritten < 0 && (*__errno_location ()) == 4) {
                nwritten = 0;
            } else {
                return -1;
            }
        }
        nleft -= nwritten;
        p += nwritten;
    }
    return n;
}

canonical_original_code:
long socket_writen(int fd, void *buf, unsigned long n)
{
    unsigned long nleft;
    long nwritten;
    char *p;
    p = buf;
    nleft = n;
    while (nleft > 0) {
        if ((nwritten = write(fd, buf, nleft)) <= 0) {
            if (nwritten < 0 && (*__errno_location ()) == 4) {
                nwritten = 0;
            } else {
                return -1;
            }
        }
        nleft -= nwritten;
        p += nwritten;
    }
    return n;
}

variable_types: nwritten long


decompiled_code:
__int64 __fastcall socket_recvfrom(int a1, void *a2, size_t a3, int a4, struct sockaddr *a5, socklen_t *a6)
{
int v6; // ebx

v6 = recvfrom(a1, a2, a3, a4, a5, a6);
if ( v6 == -1 )
perror("socket recvfrom error");
return v6;
}

canonical_decompiled_code:
__int64 __fastcall func10(int a1, void *a2, size_t a3, int a4, struct sockaddr *a5, socklen_t *a6)
{
int v6; // ebx

v6 = recvfrom(a1, a2, a3, a4, a5, a6);
if ( v6 == -1 )
perror("socket recvfrom error");
return v6;
}

original_code:
ssize_t socket_recvfrom(int fd, void *buf, size_t len, int flags,
    struct sockaddr *src_addr, socklen_t *addr_len)
{
    int n = recvfrom(fd, buf, len, flags, src_addr, addr_len);
    if (n == -1) {
        perror("socket recvfrom error");
    }
    return n;
}

canonical_original_code:
long socket_recvfrom(int fd, void *buf, unsigned long len, int flags, struct sockaddr *src_addr, unsigned int *addr_len)
{
    int n = recvfrom(fd, buf, len, flags, src_addr, addr_len);
    if (n == -1) {
        perror("socket recvfrom error");
    }
    return n;
}

variable_types:
len
unsigned long

variable_types: flags int


decompiled_code:
__int64 __fastcall socket_sendto(int a1, const void *a2, size_t a3, int a4, const struct sockaddr *a5, socklen_t a6)
{
int v6; // ebx

v6 = sendto(a1, a2, a3, a4, a5, a6);
if ( v6 == -1 )
perror("socket sendto error");
return v6;
}

canonical_decompiled_code:
__int64 __fastcall func11(int a1, const void *a2, size_t a3, int a4, const struct sockaddr *a5, socklen_t a6)
{
int v6; // ebx

v6 = sendto(a1, a2, a3, a4, a5, a6);
if ( v6 == -1 )
perror("socket sendto error");
return v6;
}

original_code:
ssize_t socket_sendto(int fd, const void *buf, size_t len, int flags,
    const struct sockaddr *dst_addr, socklen_t addr_len)
{
    int n = sendto(fd, buf, len, flags, dst_addr, addr_len);
    if (n == -1) {
        perror("socket sendto error");
    }
    return n;
}

canonical_original_code:
long socket_sendto(int fd, void *buf, unsigned long len, int flags, struct sockaddr *dst_addr, unsigned int addr_len)
{
    int n = sendto(fd, buf, len, flags, dst_addr, addr_len);
    if (n == -1) {
        perror("socket sendto error");
    }
    return n;
}


decompiled_code:
void *__fastcall client_send_notify(void *a1)
{
size_t v1; // rax
size_t v2; // rax
int v4; // [rsp+0h] [rbp-B8h] BYREF
char dest[180]; // [rsp+4h] [rbp-B4h] BYREF

v4 = 0;
strcpy(dest, src);
while ( pthread_mutex_trylock(&subthread_exit) )
{
v1 = strlen(dest);
((void (__fastcall *)(_QWORD, int *, size_t, _QWORD, __int16 *, __int64))socket_sendto)(
(unsigned int)socket_fd,
&v4,
v1 + 5,
0LL,
&server_addr,
16LL);
sleep(2u);
}
v4 = 2;
v2 = strlen(dest);
((void (__fastcall *)(_QWORD, int *, size_t, _QWORD, __int16 *, __int64))socket_sendto)(
(unsigned int)socket_fd,
&v4,
v2 + 5,
0LL,
&server_addr,
16LL);
return 0LL;
}

canonical_decompiled_code:
void *__fastcall func0(void *a1)
{
size_t v1; // rax
size_t v2; // rax
int v4; // [rsp+0h] [rbp-B8h] BYREF
char dest[180]; // [rsp+4h] [rbp-B4h] BYREF

v4 = 0;
strcpy(dest, src);
while ( pthread_mutex_trylock(&subthread_exit) )
{
v1 = strlen(dest);
((void (__fastcall *)(_QWORD, int *, size_t, _QWORD, __int16 *, __int64))socket_sendto)(
(unsigned int)socket_fd,
&v4,
v1 + 5,
0LL,
&server_addr,
16LL);
sleep(2u);
}
v4 = 2;
v2 = strlen(dest);
((void (__fastcall *)(_QWORD, int *, size_t, _QWORD, __int16 *, __int64))socket_sendto)(
(unsigned int)socket_fd,
&v4,
v2 + 5,
0LL,
&server_addr,
16LL);
return 0LL;
}

original_code:
static void *client_send_notify(void *arg)
{
    msg_t notify;
    notify.type = MSG_TYPE_NOTIFY;
    strcpy(notify.name, msg.name);
    while (pthread_mutex_trylock(&subthread_exit)) {
        socket_sendto(socket_fd, &notify, sizeof(notify.type) + strlen(notify.name) + 1, 0,
            (struct sockaddr *) &server_addr, sizeof(server_addr));
        sleep(2);
    }
    notify.type = MSG_TYPE_EXIT;
    socket_sendto(socket_fd, &notify, sizeof(notify.type) + strlen(notify.name) + 1, 0,
        (struct sockaddr *) &server_addr, sizeof(server_addr));
    return ((void *)0);
}

canonical_original_code:
static void *client_send_notify(void *arg)
{
    struct message notify;
    notify.type = MSG_TYPE_NOTIFY;
    strcpy(notify.name, msg.name);
    while (pthread_mutex_trylock(&subthread_exit)) {
        socket_sendto(socket_fd, &notify, sizeof(notify.type) + strlen(notify.name) + 1, 0,
            (struct sockaddr *) &server_addr, sizeof(server_addr));
        sleep(2);
    }
    notify.type = MSG_TYPE_EXIT;
    socket_sendto(socket_fd, &notify, sizeof(notify.type) + strlen(notify.name) + 1, 0,
        (struct sockaddr *) &server_addr, sizeof(server_addr));
    return ((void *)0);
}

variable_types:
arg
void *

variable_types: struct message { enum msg_type { MSG_TYPE_NOTIFY=0, MSG_TYPE_CHAT=1, MSG_TYPE_EXIT=2 } type; char name[16]; char buf[128]; char ip[16]; }

user_defined_types: struct message { enum msg_type type; char name[16]; char buf[128]; char ip[16]; }


decompiled_code:
char *__fastcall client_send_msg(char *src)
{
return strncpy(dest, src, 0x80uLL);
}

canonical_decompiled_code:
char *__fastcall func3(char *src)
{
return strncpy(dest, src, 0x80uLL);
}

original_code:
void client_send_msg(char *s)
{
    strncpy(msg.buf, s, 128);
    return;
}

variable_types:
s
char *


decompiled_code:
__int64 client_main()
{
char *v0; // rax
size_t v1; // rax
int v3; // [rsp+0h] [rbp-18h]
int optval; // [rsp+4h] [rbp-14h] BYREF
pthread_t newthread[2]; // [rsp+8h] [rbp-10h] BYREF

v0 = getlogin();
strncpy(src, v0, 0x10uLL);
socket_fd = socket_open(2LL, 2LL, 0LL);
optval = 1;
setsockopt(socket_fd, 1, 6, &optval, 4u);
*(__int64 *)((char *)&qword_274 + 4) = 0LL;
server_addr = 2;
qword_274 = (unsigned int)_bswap_32(0xFFFFFFFF);
word_272 = _bswap_16(7201);
pthread_mutex_lock(&subthread_exit);
pthread_create(newthread, 0LL, client_send_notify, 0LL);
while ( 1 )
{
pthread_mutex_lock(&client_request);
if ( !pthread_mutex_trylock(&client_exit) )
break;
msg = 1;
v1 = strlen(dest);
socket_sendto((unsigned int)socket_fd, &msg, v1 + 21, 0LL, &server_addr, 16LL, v3);
pthread_mutex_unlock(&client_done);
}
pthread_mutex_unlock(&subthread_exit);
pthread_join(newthread[0], 0LL);
return 0LL;
}

canonical_decompiled_code:
__int64 func4()
{
char *v0; // rax
size_t v1; // rax
int v3; // [rsp+0h] [rbp-18h]
int optval; // [rsp+4h] [rbp-14h] BYREF
pthread_t newthread[2]; // [rsp+8h] [rbp-10h] BYREF

v0 = getlogin();
strncpy(src, v0, 0x10uLL);
socket_fd = socket_open(2LL, 2LL, 0LL);
optval = 1;
setsockopt(socket_fd, 1, 6, &optval, 4u);
*(__int64 *)((char *)&qword_274 + 4) = 0LL;
server_addr = 2;
qword_274 = (unsigned int)func1(0xFFFFFFFF);
word_272 = func2(7201);
pthread_mutex_lock(&subthread_exit);
pthread_create(newthread, 0LL, client_send_notify, 0LL);
while ( 1 )
{
pthread_mutex_lock(&client_request);
if ( !pthread_mutex_trylock(&client_exit) )
break;
msg = 1;
v1 = strlen(dest);
socket_sendto((unsigned int)socket_fd, &msg, v1 + 21, 0LL, &server_addr, 16LL, v3);
pthread_mutex_unlock(&client_done);
}
pthread_mutex_unlock(&subthread_exit);
pthread_join(newthread[0], 0LL);
return 0LL;
}

original_code:
void *client_main(void *arg)
{
    socklen_t server_addr_len;
    pthread_t tid;
    strncpy(msg.name, getlogin(), sizeof(msg.name));
    socket_fd = socket_open(2, SOCK_DGRAM, 0);
    int opt = 1;
    setsockopt(socket_fd, 1, 6, &opt, sizeof(opt));
    memset(&server_addr, 0, sizeof(server_addr));
    server_addr.sin_family = 2;
    server_addr.sin_addr.s_addr = htonl(((in_addr_t) 0xffffffff));
    server_addr.sin_port = htons(7201);
    pthread_mutex_lock(&subthread_exit);
    pthread_create(&tid, ((void *)0), client_send_notify, ((void *)0));
    while (1) {
        pthread_mutex_lock(&client_request);
        if (pthread_mutex_trylock(&client_exit) == 0) {
            break;
        }
        msg.type = MSG_TYPE_CHAT;
        socket_sendto(socket_fd, &msg,
            sizeof(msg.type) + sizeof(msg.name) + strlen(msg.buf) + 1, 0,
            (struct sockaddr *) &server_addr, sizeof(server_addr));
        pthread_mutex_unlock(&client_done);
    }
    pthread_mutex_unlock(&subthread_exit);
    pthread_join(tid, ((void *)0));
    return ((void *)0);
}

canonical_original_code:
void *client_main(void *arg)
{
    unsigned int server_addr_len;
    unsigned long tid;
    strncpy(msg.name, getlogin(), sizeof(msg.name));
    socket_fd = socket_open(2, SOCK_DGRAM, 0);
    int opt = 1;
    setsockopt(socket_fd, 1, 6, &opt, sizeof(opt));
    memset(&server_addr, 0, sizeof(server_addr));
    server_addr.sin_family = 2;
    server_addr.sin_addr.s_addr = htonl(((unsigned int) 0xffffffff));
    server_addr.sin_port = htons(7201);
    pthread_mutex_lock(&subthread_exit);
    pthread_create(&tid, ((void *)0), client_send_notify, ((void *)0));
    while (1) {
        pthread_mutex_lock(&client_request);
        if (pthread_mutex_trylock(&client_exit) == 0) {
            break;
        }
        msg.type = MSG_TYPE_CHAT;
        socket_sendto(socket_fd, &msg,
            sizeof(msg.type) + sizeof(msg.name) + strlen(msg.buf) + 1, 0,
            (struct sockaddr *) &server_addr, sizeof(server_addr));
        pthread_mutex_unlock(&client_done);
    }
    pthread_mutex_unlock(&subthread_exit);
    pthread_join(tid, ((void *)0));
    return ((void *)0);
}

variable_types:
tid
unsigned long

variable_types: opt int


decompiled_code:
void __noreturn server_main()
{
unsigned int v0; // ebx
_BYTE v1[148]; // [rsp+0h] [rbp-D8h] BYREF
char buf[24]; // [rsp+94h] [rbp-44h] BYREF
int v3; // [rsp+ACh] [rbp-2Ch] BYREF
char v4[4]; // [rsp+B0h] [rbp-28h] BYREF
char cp[12]; // [rsp+B4h] [rbp-24h] BYREF
__int16 v6[2]; // [rsp+C0h] [rbp-18h] BYREF
__int64 v7; // [rsp+C4h] [rbp-14h]
int v8; // [rsp+CCh] [rbp-Ch]

v0 = socket_open(2LL, 2LL, 0LL);
v8 = 0;
v6[0] = 2;
v7 = (unsigned int)_bswap_32(0);
v6[1] = _bswap_16(7201);
socket_bind(v0, v6, 16LL);
while ( 1 )
{
v3 = 16;
socket_recvfrom(v0, v1, 164LL, 0LL, v4, &v3);
inet_ntop(2, cp, buf, 0x10u);
pthread_mutex_lock(&server_request);
transform_msg(v1);
pthread_mutex_unlock(&server_done);
}
}

canonical_decompiled_code:
void __noreturn func2()
{
unsigned int v0; // ebx
_BYTE v1[148]; // [rsp+0h] [rbp-D8h] BYREF
char buf[24]; // [rsp+94h] [rbp-44h] BYREF
int v3; // [rsp+ACh] [rbp-2Ch] BYREF
char v4[4]; // [rsp+B0h] [rbp-28h] BYREF
char cp[12]; // [rsp+B4h] [rbp-24h] BYREF
__int16 v6[2]; // [rsp+C0h] [rbp-18h] BYREF
__int64 v7; // [rsp+C4h] [rbp-14h]
int v8; // [rsp+CCh] [rbp-Ch]

v0 = socket_open(2LL, 2LL, 0LL);
v8 = 0;
v6[0] = 2;
v7 = (unsigned int)func0(0);
v6[1] = func1(7201);
socket_bind(v0, v6, 16LL);
while ( 1 )
{
v3 = 16;
socket_recvfrom(v0, v1, 164LL, 0LL, v4, &v3);
inet_ntop(2, cp, buf, 0x10u);
pthread_mutex_lock(&server_request);
transform_msg(v1);
pthread_mutex_unlock(&server_done);
}
}

original_code:
void *server_main(void *arg)
{
    struct sockaddr_in my_addr, client_addr;
    socklen_t client_addr_len;
    int socket_fd;
    msg_t msg;
    char buf[1024];
    char str[16];
    int i, n;
    socket_fd = socket_open(2, SOCK_DGRAM, 0);
    memset(&my_addr, 0, sizeof(my_addr));
    my_addr.sin_family = 2;
    my_addr.sin_addr.s_addr = htonl(((in_addr_t) 0x00000000));
    my_addr.sin_port = htons(7201);
    socket_bind(socket_fd,
        (struct sockaddr *) &my_addr, sizeof(my_addr));
    while (1) {
        client_addr_len = sizeof(client_addr);
        n = socket_recvfrom(socket_fd, &msg, sizeof(msg), 0,
                (struct sockaddr *) &client_addr, &client_addr_len);
        inet_ntop(2, &client_addr.sin_addr, msg.ip, sizeof(msg.ip));
        pthread_mutex_lock(&server_request);
        transform_msg(&msg);
        pthread_mutex_unlock(&server_done);
    }
    return ((void *)0);
}

canonical_original_code:
void *server_main(void *arg)
{
    struct sockaddr_in my_addr; struct sockaddr_in client_addr;
    unsigned int client_addr_len;
    int socket_fd;
    struct message msg;
    char buf[1024];
    char str[16];
    int i; int n;
    socket_fd = socket_open(2, SOCK_DGRAM, 0);
    memset(&my_addr, 0, sizeof(my_addr));
    my_addr.sin_family = 2;
    my_addr.sin_addr.s_addr = htonl(((unsigned int) 0x00000000));
    my_addr.sin_port = htons(7201);
    socket_bind(socket_fd,
        (struct sockaddr *) &my_addr, sizeof(my_addr));
    while (1) {
        client_addr_len = sizeof(client_addr);
        n = socket_recvfrom(socket_fd, &msg, sizeof(msg), 0,
                (struct sockaddr *) &client_addr, &client_addr_len);
        inet_ntop(2, &client_addr.sin_addr, msg.ip, sizeof(msg.ip));
        pthread_mutex_lock(&server_request);
        transform_msg(&msg);
        pthread_mutex_unlock(&server_done);
    }
    return ((void *)0);
}

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

variable_types:
buf
char [1024]

variable_types:
str
char [16]

variable_types: i int

variable_types: n int

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

user_defined_types: enum msg_type { MSG_TYPE_NOTIFY=0, MSG_TYPE_CHAT=1, MSG_TYPE_EXIT=2 }


min

repo: Saicheg/computer-architecture

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

result = a1;
if ( a2 <= a1 )
result = a2;
return result;
}

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

result = a1;
if ( a2 <= a1 )
result = a2;
return result;
}

original_code:
long min(long a, long b) {
    return(a < b) ? a : b;
}

variable_types: a long

variable_types: b long


rdtsc

decompiled_code:
unsigned __int64 rdtsc()
{
return __rdtsc();
}

canonical_decompiled_code:
unsigned __int64 func8()
{
return __rdtsc();
}

original_code:
unsigned long long int rdtsc() {
    unsigned long long int c, d;
    asm volatile("rdtsc" : "=a" (c), "=d" (d));
    return c | (d << 32);
}

canonical_original_code:
unsigned long long rdtsc() {
    unsigned long long c; unsigned long long d;
    asm volatile("rdtsc" : "=a" (c), "=d" (d));
    return c | (d << 32);
}

variable_types:
c
unsigned long long

variable_types:
d
unsigned long long

return_type: unsigned long long


createMatrix

decompiled_code:
float *__fastcall createMatrix(int a1)
{
float *v1; // rax
float *v2; // rbp
float *v3; // rbx
float *v4; // r12
float *v6; // rdx

v1 = (float *)memalign(0x40uLL, 0x3D0900uLL);
v2 = v1;
if ( a1 )
{
v3 = v1;
v4 = v1 + 1000000;
do
*v3++ = (float)rand() / 100.0;
while ( v3 != v4 );
}
else
{
v6 = v1 + 1000000;
do
*v1++ = 0.0;
while ( v1 != v6 );
}
return v2;
}

canonical_decompiled_code:
float *__fastcall func9(int a1)
{
float *v1; // rax
float *v2; // rbp
float *v3; // rbx
float *v4; // r12
float *v6; // rdx

v1 = (float *)memalign(0x40uLL, 0x3D0900uLL);
v2 = v1;
if ( a1 )
{
v3 = v1;
v4 = v1 + 1000000;
do
*v3++ = (float)rand() / 100.0;
while ( v3 != v4 );
}
else
{
v6 = v1 + 1000000;
do
*v1++ = 0.0;
while ( v1 != v6 );
}
return v2;
}

original_code:
float* createMatrix(int randomize) {
    float *matrix = (float*) memalign(64, sizeof(float) * (1000*1000));
    if (randomize != 0) {
        for (int i = 0; i < (1000*1000); i++) {
            matrix[i] = (float) rand() / (float) 100;
        }
    } else {
        for (int i = 0; i < (1000*1000); i++) {
            matrix[i] = 0.0;
        }
    }
    return matrix;
}

canonical_original_code:
float *createMatrix(int randomize) {
    float *matrix = (float*) memalign(64, sizeof(float) * (1000*1000));
    if (randomize != 0) {
        for (int i = 0; i < (1000*1000); i++) {
            matrix[i] = (float) rand() / (float) 100;
        }
    } else {
        for (int i = 0; i < (1000*1000); i++) {
            matrix[i] = 0.0;
        }
    }
    return matrix;
}

variable_types: randomize int

variable_types:
matrix
float *

return_type: float *


freeMatrix

decompiled_code:
void __fastcall freeMatrix(void **a1)
{
free(*a1);
*a1 = 0LL;
}

canonical_decompiled_code:
void __fastcall func10(void **a1)
{
free(*a1);
*a1 = 0LL;
}

original_code:
void freeMatrix(float ** matrix) {
    free(*matrix);
    (*matrix) = ((void *)0);
}

canonical_original_code:
void freeMatrix(float **matrix) {
    free(*matrix);
    (*matrix) = ((void *)0);
}

variable_types:
matrix
float **


computeMatrix

variable_types: j int

variable_types: k int


original_code:
void calculateBlockL1(int i_start, int i_end,
                      int j_start, int j_end,
                      int k_start, int k_end) {
    for (int i = i_start; i < i_end; i += cache_l1_line) {
        for (int j = j_start; j < j_end; j += cache_l1_line) {
            for (int k = k_start; k < k_end; k += cache_l1_block_size) {
                int ii_end = min(i + cache_l1_line, i_end);
                int jj_end = min(j + cache_l1_line, j_end);
                int kk_end = min(k + cache_l1_block_size, k_end);
                for (int ii = i; ii < ii_end; ii++) {
                    for (int jj = j; jj < jj_end; jj++) {
                        for (int kk = k; kk < kk_end; kk++) {
                            matrix_result_2[ii*1000 +jj] += matrix_a[ii*1000 +kk] * matrix_b[kk*1000 +jj];
                        }
                    }
                }
            }
        }
    }
}

variable_types: ii int

variable_types: jj int

variable_types: kk int


decompiled_code:
__int64 __fastcall calculateBlockL2(int a1, int a2, int a3, int a4, int a5, int a6)
{
__int64 v6; // rbp
int v7; // er13
int v8; // eax
int j; // er12
__int64 v10; // rax
int v11; // ebx
int i; // er14
int v13; // ebx
__int64 result; // rax

while ( 1 )
{
result = min(a2, cache_l2_line + a1);
if ( a1 >= result )
break;
for ( i = a3; ; i += cache_l2_line )
{
v13 = cache_l2_line;
if ( i >= min(a4, i + cache_l2_line) )
break;
for ( j = a5; ; j += cache_l2_block_size )
{
v10 = min(a6, cache_l2_block_size + j);
v11 = v10;
if ( j >= v10 )
break;
v6 = cache_l2_line;
v7 = min(a4, cache_l2_line + i);
v8 = min(a2, v6 + a1);
calculateBlockL1(a1, v8, i, v7, j, v11);
}
}
a1 += v13;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func13(int a1, int a2, int a3, int a4, int a5, int a6)
{
__int64 v6; // rbp
int v7; // er13
int v8; // eax
int j; // er12
__int64 v10; // rax
int v11; // ebx
int i; // er14
int v13; // ebx
__int64 result; // rax

while ( 1 )
{
result = func7(a2, cache_l2_line + a1);
if ( a1 >= result )
break;
for ( i = a3; ; i += cache_l2_line )
{
v13 = cache_l2_line;
if ( i >= func7(a4, i + cache_l2_line) )
break;
for ( j = a5; ; j += cache_l2_block_size )
{
v10 = func7(a6, cache_l2_block_size + j);
v11 = v10;
if ( j >= v10 )
break;
v6 = cache_l2_line;
v7 = func7(a4, cache_l2_line + i);
v8 = func7(a2, v6 + a1);
func12(a1, v8, i, v7, j, v11);
}
}
a1 += v13;
}
return result;
}

original_code:
void calculateBlockL2(int i_start, int i_end,
                      int j_start, int j_end,
                      int k_start, int k_end) {
    for (int i = i_start; i < min(i_end, i + cache_l2_line); i += cache_l2_line) {
        for (int j = j_start; j < min(j_end, j + cache_l2_line); j += cache_l2_line) {
            for (int k = k_start; k < min(k_end, k + cache_l2_block_size); k += cache_l2_block_size) {
                calculateBlockL1(i, min(i_end, i + cache_l2_line),
                                 j, min(j_end, j + cache_l2_line),
                                 k, min(k_end, k + cache_l2_block_size));
            }
        }
    }
}


decompiled_code:
__int64 __fastcall calculateBlockL3(int a1, int a2, int a3, int a4, int a5, int a6)
{
__int64 v6; // rbp
int v7; // er13
int v8; // eax
int j; // er12
__int64 v10; // rax
int v11; // ebx
int i; // er14
int v13; // ebx
__int64 result; // rax

while ( 1 )
{
result = min(a2, cache_l3_line + a1);
if ( a1 >= result )
break;
for ( i = a3; ; i += cache_l3_line )
{
v13 = cache_l3_line;
if ( i >= min(a4, i + cache_l3_line) )
break;
for ( j = a5; ; j += cache_l3_block_size )
{
v10 = min(a6, cache_l3_block_size + j);
v11 = v10;
if ( j >= v10 )
break;
v6 = cache_l3_line;
v7 = min(a4, cache_l3_line + i);
v8 = min(a2, v6 + a1);
calculateBlockL2(a1, v8, i, v7, j, v11);
}
}
a1 += v13;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func14(int a1, int a2, int a3, int a4, int a5, int a6)
{
__int64 v6; // rbp
int v7; // er13
int v8; // eax
int j; // er12
__int64 v10; // rax
int v11; // ebx
int i; // er14
int v13; // ebx
__int64 result; // rax

while ( 1 )
{
result = func7(a2, cache_l3_line + a1);
if ( a1 >= result )
break;
for ( i = a3; ; i += cache_l3_line )
{
v13 = cache_l3_line;
if ( i >= func7(a4, i + cache_l3_line) )
break;
for ( j = a5; ; j += cache_l3_block_size )
{
v10 = func7(a6, cache_l3_block_size + j);
v11 = v10;
if ( j >= v10 )
break;
v6 = cache_l3_line;
v7 = func7(a4, cache_l3_line + i);
v8 = func7(a2, v6 + a1);
func13(a1, v8, i, v7, j, v11);
}
}
a1 += v13;
}
return result;
}

original_code:
void calculateBlockL3(int i_start, int i_end,
                      int j_start, int j_end,
                      int k_start, int k_end) {
    for (int i = i_start; i < min(i_end, i + cache_l3_line); i += cache_l3_line) {
        for (int j = j_start; j < min(j_end, j + cache_l3_line); j += cache_l3_line) {
            for (int k = k_start; k < min(k_end, k + cache_l3_block_size); k += cache_l3_block_size) {
                calculateBlockL2(i, min(i_end, i + cache_l3_line),
                                 j, min(j_end, j + cache_l3_line),
                                 k, min(k_end, k + cache_l3_block_size));
            }
        }
    }
}


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // eax
unsigned __int64 v4; // r15
unsigned __int64 v5; // r13
unsigned __int64 v6; // r14
unsigned __int64 v7; // r12
__int64 v8; // rbx
__int64 v9; // rbp
float v10; // xmm2_4

matrix_element_size = 4LL;
printf("Size of float: %ld\n\n", 4LL);
printf("Querying cache parameters... ");
cache_l1_size = sysconf(188);
cache_l1_assoc = sysconf(189);
cache_l1_line = sysconf(190);
cache_l2_size = sysconf(191);
cache_l2_assoc = sysconf(192);
cache_l2_line = sysconf(193);
cache_l3_size = sysconf(194);
cache_l3_assoc = sysconf(195);
cache_l3_line = sysconf(196);
if ( cache_l3_size )
cache_l3_exists = 1;
puts("done.\n");
puts("Cache settings:");
printf(
" L1: %ld KiB, %ld lines, line size of %ld bytes, %ld-associative\n",
cache_l1_size / 1024,
cache_l1_size / cache_l1_line,
cache_l1_line,
cache_l1_assoc);
printf(
" L2: %ld KiB, %ld lines, line size of %ld bytes, %ld-associative\n",
cache_l2_size / 1024,
cache_l2_size / cache_l2_line,
cache_l2_line,
cache_l2_assoc);
if ( cache_l3_exists )
printf(
" L3: %ld KiB, %ld lines, line size of %ld bytes, %ld-associative\n",
cache_l3_size / 1024,
cache_l3_size / cache_l3_line,
cache_l3_line,
cache_l3_assoc);
else
puts(" L3: no cache");
cache_l1_block_size = cache_l1_size / matrix_element_size / cache_l1_line / 3;
cache_l2_block_size = cache_l2_size / matrix_element_size / cache_l2_line / 3;
if ( cache_l3_exists )
cache_l3_block_size = cache_l3_size / matrix_element_size / cache_l3_line / 3;
puts("\nBlock sizes:");
printf(" L1: %ld x %ld\n", cache_l1_line, cache_l1_block_size);
printf(" L2: %ld x %ld\n", cache_l2_line, cache_l2_block_size);
if ( cache_l3_exists )
printf(" L3: %ld x %ld\n", cache_l3_line, cache_l3_block_size);
v3 = time(0LL);
srand(v3);
printf("\nAllocating argument matrixes... ");
matrix_a = createMatrix(1);
matrix_b = createMatrix(1);
puts("done.");
printf("Allocating result 1 matrix... ");
matrix_result_1 = createMatrix(0);
printf("done. \nComputing result 1... ");
fflush(_bss_start);
v4 = rdtsc();
computeMatrix(matrix_a, matrix_b, matrix_result_1);
v5 = rdtsc();
printf("done. \nAllocating result 2 matrix...");
matrix_result_2 = createMatrix(0);
printf("done. \nComputing result 2... ");
fflush(_bss_start);
v6 = rdtsc();
if ( cache_l3_exists )
calculateBlockL3(0, 1000, 0, 1000, 0, 1000);
else
calculateBlockL2(0, 1000, 0, 1000, 0, 1000);
v7 = rdtsc();
puts("done.\n");
free(matrix_a);
free(matrix_b);
v8 = 0LL;
v9 = 0LL;
do
{
v10 = *(float *)((char *)matrix_result_2 + v8);
if ( fabs(1.0 - (float)(*(float *)((char *)matrix_result_1 + v8) / v10)) > 0.0001 )
{
if ( v9 <= 9 )
printf("Got %f while expected %f\n", v10, *(float *)((char *)matrix_result_1 + v8));
++v9;
}
v8 += 4LL;
}
while ( v8 != 4000000 );
printf("Result 1: %llu ticks\n", v5 - v4);
printf("Result 2: %llu ticks\n", v7 - v6);
printf("%ld of total %ld differs in values\n", v9, 1000000LL);
free(matrix_result_1);
free(matrix_result_2);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // eax
unsigned __int64 v4; // r15
unsigned __int64 v5; // r13
unsigned __int64 v6; // r14
unsigned __int64 v7; // r12
__int64 v8; // rbx
__int64 v9; // rbp
float v10; // xmm2_4

matrix_element_size = 4LL;
printf("Size of float: %ld\n\n", 4LL);
printf("Querying cache parameters... ");
cache_l1_size = sysconf(188);
cache_l1_assoc = sysconf(189);
cache_l1_line = sysconf(190);
cache_l2_size = sysconf(191);
cache_l2_assoc = sysconf(192);
cache_l2_line = sysconf(193);
cache_l3_size = sysconf(194);
cache_l3_assoc = sysconf(195);
cache_l3_line = sysconf(196);
if ( cache_l3_size )
cache_l3_exists = 1;
puts("done.\n");
puts("Cache settings:");
printf(
" L1: %ld KiB, %ld lines, line size of %ld bytes, %ld-associative\n",
cache_l1_size / 1024,
cache_l1_size / cache_l1_line,
cache_l1_line,
cache_l1_assoc);
printf(
" L2: %ld KiB, %ld lines, line size of %ld bytes, %ld-associative\n",
cache_l2_size / 1024,
cache_l2_size / cache_l2_line,
cache_l2_line,
cache_l2_assoc);
if ( cache_l3_exists )
printf(
" L3: %ld KiB, %ld lines, line size of %ld bytes, %ld-associative\n",
cache_l3_size / 1024,
cache_l3_size / cache_l3_line,
cache_l3_line,
cache_l3_assoc);
else
puts(" L3: no cache");
cache_l1_block_size = cache_l1_size / matrix_element_size / cache_l1_line / 3;
cache_l2_block_size = cache_l2_size / matrix_element_size / cache_l2_line / 3;
if ( cache_l3_exists )
cache_l3_block_size = cache_l3_size / matrix_element_size / cache_l3_line / 3;
puts("\nBlock sizes:");
printf(" L1: %ld x %ld\n", cache_l1_line, cache_l1_block_size);
printf(" L2: %ld x %ld\n", cache_l2_line, cache_l2_block_size);
if ( cache_l3_exists )
printf(" L3: %ld x %ld\n", cache_l3_line, cache_l3_block_size);
v3 = time(0LL);
srand(v3);
printf("\nAllocating argument matrixes... ");
matrix_a = func9(1);
matrix_b = func9(1);
puts("done.");
printf("Allocating result 1 matrix... ");
matrix_result_1 = func9(0);
printf("done. \nComputing result 1... ");
fflush(_bss_start);
v4 = func8();
func11(matrix_a, matrix_b, matrix_result_1);
v5 = func8();
printf("done. \nAllocating result 2 matrix...");
matrix_result_2 = func9(0);
printf("done. \nComputing result 2... ");
fflush(_bss_start);
v6 = func8();
if ( cache_l3_exists )
func14(0, 1000, 0, 1000, 0, 1000);
else
func13(0, 1000, 0, 1000, 0, 1000);
v7 = func8();
puts("done.\n");
free(matrix_a);
free(matrix_b);
v8 = 0LL;
v9 = 0LL;
do
{
v10 = *(float *)((char *)matrix_result_2 + v8);
if ( fabs(1.0 - (float)(*(float *)((char *)matrix_result_1 + v8) / v10)) > 0.0001 )
{
if ( v9 <= 9 )
printf("Got %f while expected %f\n", v10, *(float *)((char *)matrix_result_1 + v8));
++v9;
}
v8 += 4LL;
}
while ( v8 != 4000000 );
printf("Result 1: %llu ticks\n", v5 - v4);
printf("Result 2: %llu ticks\n", v7 - v6);
printf("%ld of total %ld differs in values\n", v9, 1000000LL);
free(matrix_result_1);
free(matrix_result_2);
return 0;
}

original_code:
int main() {
    matrix_element_size = sizeof(float);
    printf("Size of float: %ld\n\n", sizeof(float));
    printf("Querying cache parameters... ");
    cache_l1_size = sysconf(_SC_LEVEL1_DCACHE_SIZE);
    cache_l1_assoc = sysconf(_SC_LEVEL1_DCACHE_ASSOC);
    cache_l1_line = sysconf(_SC_LEVEL1_DCACHE_LINESIZE);
    cache_l2_size = sysconf(_SC_LEVEL2_CACHE_SIZE);
    cache_l2_assoc = sysconf(_SC_LEVEL2_CACHE_ASSOC);
    cache_l2_line = sysconf(_SC_LEVEL2_CACHE_LINESIZE);
    cache_l3_size = sysconf(_SC_LEVEL3_CACHE_SIZE);
    cache_l3_assoc = sysconf(_SC_LEVEL3_CACHE_ASSOC);
    cache_l3_line = sysconf(_SC_LEVEL3_CACHE_LINESIZE);
    if (cache_l3_size != 0) {
        cache_l3_exists = 1;
    }
    printf("done.\n\n");
    printf("Cache settings:\n");
    printf("  L1: %ld KiB, %ld lines, line size of %ld bytes, %ld-associative\n",
           cache_l1_size / 1024,
           cache_l1_size / cache_l1_line,
           cache_l1_line,
           cache_l1_assoc);
    printf("  L2: %ld KiB, %ld lines, line size of %ld bytes, %ld-associative\n",
           cache_l2_size / 1024,
           cache_l2_size / cache_l2_line,
           cache_l2_line,
           cache_l2_assoc);
    if (cache_l3_exists == 0) {
        printf("  L3: no cache\n");
    } else {
        printf("  L3: %ld KiB, %ld lines, line size of %ld bytes, %ld-associative\n",
               cache_l3_size / 1024,
               cache_l3_size / cache_l3_line,
               cache_l3_line,
               cache_l3_assoc);
    }
    cache_l1_block_size = cache_l1_size / matrix_element_size / cache_l1_line / 3;
    cache_l2_block_size = cache_l2_size / matrix_element_size / cache_l2_line / 3;
    if (cache_l3_exists != 0) {
        cache_l3_block_size = cache_l3_size / matrix_element_size / cache_l3_line / 3;
    }
    printf("\nBlock sizes:\n");
    printf("  L1: %ld x %ld\n", cache_l1_line, cache_l1_block_size);
    printf("  L2: %ld x %ld\n", cache_l2_line, cache_l2_block_size);
    if (cache_l3_exists != 0) {
        printf("  L3: %ld x %ld\n", cache_l3_line, cache_l3_block_size);
    }
    srand(time(((void *)0)));
    printf("\nAllocating argument matrixes... ");
    matrix_a = createMatrix(1);
    matrix_b = createMatrix(1);
    printf("done.\n");
    unsigned long long time_auto_start, time_auto_end,
        time_manual_start, time_manual_end;
    printf("Allocating result 1 matrix... ");
    matrix_result_1 = createMatrix(0);
    printf("done. \nComputing result 1... ");
    fflush(stdout);
    time_auto_start = rdtsc();
    computeMatrix(matrix_a, matrix_b, matrix_result_1);
    time_auto_end = rdtsc();
    printf("done. \nAllocating result 2 matrix...");
    matrix_result_2 = createMatrix(0);
    printf("done. \nComputing result 2... ");
    fflush(stdout);
    time_manual_start = rdtsc();
    if (cache_l3_exists != 0) {
        calculateBlockL3(0, 1000,
                         0, 1000,
                         0, 1000);
    } else {
        calculateBlockL2(0, 1000,
                         0, 1000,
                         0, 1000);
    }
    time_manual_end = rdtsc();
    printf("done.\n\n");
    free(matrix_a);
    free(matrix_b);
    long error_count = 0;
    for (long i = 0; i < (1000*1000); i++) {
        if (fabs(1 - matrix_result_1[i] / matrix_result_2[i]) > (0.01 / 100.0)) {
            if (error_count < 10)
                printf("Got %f while expected %f\n", matrix_result_2[i], matrix_result_1[i]);
            error_count++;
        }
    }
    printf("Result 1: %llu ticks\n", time_auto_end - time_auto_start);
    printf("Result 2: %llu ticks\n", time_manual_end - time_manual_start);
    printf("%ld of total %ld differs in values\n",
           error_count,
           (long) ((1000*1000)));
    free(matrix_result_1);
    free(matrix_result_2);
    return 0;
}

canonical_original_code:
int main() {
    matrix_element_size = sizeof(float);
    printf("Size of float: %ld\n\n", sizeof(float));
    printf("Querying cache parameters... ");
    cache_l1_size = sysconf(_SC_LEVEL1_DCACHE_SIZE);
    cache_l1_assoc = sysconf(_SC_LEVEL1_DCACHE_ASSOC);
    cache_l1_line = sysconf(_SC_LEVEL1_DCACHE_LINESIZE);
    cache_l2_size = sysconf(_SC_LEVEL2_CACHE_SIZE);
    cache_l2_assoc = sysconf(_SC_LEVEL2_CACHE_ASSOC);
    cache_l2_line = sysconf(_SC_LEVEL2_CACHE_LINESIZE);
    cache_l3_size = sysconf(_SC_LEVEL3_CACHE_SIZE);
    cache_l3_assoc = sysconf(_SC_LEVEL3_CACHE_ASSOC);
    cache_l3_line = sysconf(_SC_LEVEL3_CACHE_LINESIZE);
    if (cache_l3_size != 0) {
        cache_l3_exists = 1;
    }
    printf("done.\n\n");
    printf("Cache settings:\n");
    printf("  L1: %ld KiB, %ld lines, line size of %ld bytes, %ld-associative\n",
           cache_l1_size / 1024,
           cache_l1_size / cache_l1_line,
           cache_l1_line,
           cache_l1_assoc);
    printf("  L2: %ld KiB, %ld lines, line size of %ld bytes, %ld-associative\n",
           cache_l2_size / 1024,
           cache_l2_size / cache_l2_line,
           cache_l2_line,
           cache_l2_assoc);
    if (cache_l3_exists == 0) {
        printf("  L3: no cache\n");
    } else {
        printf("  L3: %ld KiB, %ld lines, line size of %ld bytes, %ld-associative\n",
               cache_l3_size / 1024,
               cache_l3_size / cache_l3_line,
               cache_l3_line,
               cache_l3_assoc);
    }
    cache_l1_block_size = cache_l1_size / matrix_element_size / cache_l1_line / 3;
    cache_l2_block_size = cache_l2_size / matrix_element_size / cache_l2_line / 3;
    if (cache_l3_exists != 0) {
        cache_l3_block_size = cache_l3_size / matrix_element_size / cache_l3_line / 3;
    }
    printf("\nBlock sizes:\n");
    printf("  L1: %ld x %ld\n", cache_l1_line, cache_l1_block_size);
    printf("  L2: %ld x %ld\n", cache_l2_line, cache_l2_block_size);
    if (cache_l3_exists != 0) {
        printf("  L3: %ld x %ld\n", cache_l3_line, cache_l3_block_size);
    }
    srand(time(((void *)0)));
    printf("\nAllocating argument matrixes... ");
    matrix_a = createMatrix(1);
    matrix_b = createMatrix(1);
    printf("done.\n");
    unsigned long long time_auto_start; unsigned long long time_auto_end; unsigned long long time_manual_start; unsigned long long time_manual_end;
    printf("Allocating result 1 matrix... ");
    matrix_result_1 = createMatrix(0);
    printf("done. \nComputing result 1... ");
    fflush(stdout);
    time_auto_start = rdtsc();
    computeMatrix(matrix_a, matrix_b, matrix_result_1);
    time_auto_end = rdtsc();
    printf("done. \nAllocating result 2 matrix...");
    matrix_result_2 = createMatrix(0);
    printf("done. \nComputing result 2... ");
    fflush(stdout);
    time_manual_start = rdtsc();
    if (cache_l3_exists != 0) {
        calculateBlockL3(0, 1000,
                         0, 1000,
                         0, 1000);
    } else {
        calculateBlockL2(0, 1000,
                         0, 1000,
                         0, 1000);
    }
    time_manual_end = rdtsc();
    printf("done.\n\n");
    free(matrix_a);
    free(matrix_b);
    long error_count = 0;
    for (long i = 0; i < (1000*1000); i++) {
        if (fabs(1 - matrix_result_1[i] / matrix_result_2[i]) > (0.01 / 100.0)) {
            if (error_count < 10)
                printf("Got %f while expected %f\n", matrix_result_2[i], matrix_result_1[i]);
            error_count++;
        }
    }
    printf("Result 1: %llu ticks\n", time_auto_end - time_auto_start);
    printf("Result 2: %llu ticks\n", time_manual_end - time_manual_start);
    printf("%ld of total %ld differs in values\n",
           error_count,
           (long) ((1000*1000)));
    free(matrix_result_1);
    free(matrix_result_2);
    return 0;
}

variable_types: i long


repo: Sakibs/Snake

original_code:
int setup_snakey(Snake *snakey, int begx, int begy){
 snakey->cur_snakey_length = 5;
 int i;
 for (i = 0; i<5; i++){
  snakey->body[i].x = begx-i;
  snakey->body[i].y = begy;
 }
 for(; i<40; i++){
  snakey->body[i].x = 0;
  snakey->body[i].y = 0;
 }
 return 0;
}

canonical_original_code:
int setup_snakey(struct SnakeData *snakey, int begx, int begy){
 snakey->cur_snakey_length = 5;
 int i;
 for (i = 0; i<5; i++){
  snakey->body[i].x = begx-i;
  snakey->body[i].y = begy;
 }
 for(; i<40; i++){
  snakey->body[i].x = 0;
  snakey->body[i].y = 0;
 }
 return 0;
}

variable_types: struct SnakeData { int cur_snakey_length; struct spart { int x; int y; } body[40]; } *

variable_types: begx int

variable_types: begy int

user_defined_types: struct SnakeData { int cur_snakey_length; struct spart body[40]; }


original_code:
int update_snakey_pos(Snake *snakey, int direction){
 int i;
 int cur_snakey_len = snakey->cur_snakey_length;
 for(i=cur_snakey_len-1; i>0 ; i--){
  snakey->body[i] = snakey->body[i-1];
 }
 int x = snakey->body[0].x;
 int y = snakey->body[0].y;
 switch(direction){
  case UP:
   y-1 == 0 ? y = 20 -2 : y--;
   break;
  case DOWN:
   y+1 == 20 -1 ? y = 1 : y++;
   break;
  case RIGHT:
   x+1 == 50 -1 ? x = 1 : x++;
   break;
  case LEFT:
   x-1 == 0 ? x = 50 -2 : x--;
   break;
  default:
   break;
 }
 snakey->body[0].x = x;
 snakey->body[0].y = y;
 return 0;
}

canonical_original_code:
int update_snakey_pos(struct SnakeData *snakey, int direction){
 int i;
 int cur_snakey_len = snakey->cur_snakey_length;
 for(i=cur_snakey_len-1; i>0 ; i--){
  snakey->body[i] = snakey->body[i-1];
 }
 int x = snakey->body[0].x;
 int y = snakey->body[0].y;
 switch(direction){
  case UP:
   y-1 == 0 ? y = 20 -2 : y--;
   break;
  case DOWN:
   y+1 == 20 -1 ? y = 1 : y++;
   break;
  case RIGHT:
   x+1 == 50 -1 ? x = 1 : x++;
   break;
  case LEFT:
   x-1 == 0 ? x = 50 -2 : x--;
   break;
  default:
   break;
 }
 snakey->body[0].x = x;
 snakey->body[0].y = y;
 return 0;
}

variable_types: direction int

variable_types: i int

variable_types: x int

variable_types: y int


decompiled_code:
__int64 __fastcall grow_snakey(_DWORD *a1)
{
__int64 result; // rax
__int64 v2; // rdx

result = (unsigned int)*a1;
if ( (int)result <= 39 )
{
*a1 = result + 1;
v2 = (int)result + 1;
result = *(_QWORD *)&a1[2 * (int)result + 1];
*(_QWORD *)&a1[2 * v2 + 1] = result;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(_DWORD *a1)
{
__int64 result; // rax
__int64 v2; // rdx

result = (unsigned int)*a1;
if ( (int)result <= 39 )
{
*a1 = result + 1;
v2 = (int)result + 1;
result = *(_QWORD *)&a1[2 * (int)result + 1];
*(_QWORD *)&a1[2 * v2 + 1] = result;
}
return result;
}

original_code:
void grow_snakey(Snake* snakey){
 if(snakey->cur_snakey_length < 40){
  snakey->cur_snakey_length++;
  int new_part = snakey->cur_snakey_length;
  snakey->body[new_part] = snakey->body[new_part-1];
 }
}

canonical_original_code:
void grow_snakey(struct SnakeData *snakey){
 if(snakey->cur_snakey_length < 40){
  snakey->cur_snakey_length++;
  int new_part = snakey->cur_snakey_length;
  snakey->body[new_part] = snakey->body[new_part-1];
 }
}


original_code:
int check_collision(Snake *snakey){
 int headx = snakey->body[0].x;
 int heady = snakey->body[0].y;
 int cur_len = snakey->cur_snakey_length;
 int i;
 for(i = 1; i<cur_len; i++)
  if(snakey->body[i].x == headx && snakey->body[i].y == heady)
   return 1;
 return 0;
}

canonical_original_code:
int check_collision(struct SnakeData *snakey){
 int headx = snakey->body[0].x;
 int heady = snakey->body[0].y;
 int cur_len = snakey->cur_snakey_length;
 int i;
 for(i = 1; i<cur_len; i++)
  if(snakey->body[i].x == headx && snakey->body[i].y == heady)
   return 1;
 return 0;
}

variable_types: headx int

variable_types: heady int


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

result = 0LL;
if ( *(_DWORD *)(a1 + 4) == *a2 )
result = *(_DWORD *)(a1 + 8) == a2[1];
return result;
}

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

result = 0LL;
if ( *(_DWORD *)(a1 + 4) == *a2 )
result = *(_DWORD *)(a1 + 8) == a2[1];
return result;
}

original_code:
int check_ate_food(Snake *snakey, Food *byte){
 if(snakey->body[0].x == byte->x && snakey->body[0].y == byte->y)
  return 1;
 return 0;
}

canonical_original_code:
int check_ate_food(struct SnakeData *snakey, struct coord *byte){
 if(snakey->body[0].x == byte->x && snakey->body[0].y == byte->y)
  return 1;
 return 0;
}

variable_types:
byte
struct coord { int x; int y; } *


decompiled_code:
unsigned __int64 __fastcall set_food_coord(int *a1, int *a2)
{
int v3; // ebx
unsigned __int64 result; // rax
int v5; // esi
int v6; // edx

do
{
v3 = rand() % 50;
result = (unsigned int)(rand() % 20);
v6 = result;
if ( v3 )
{
if ( v3 == 49 )
v3 = 48;
}
else
{
v3 = 1;
}
if ( !(_DWORD)result )
v6 = 1;
if ( *a1 <= 0 )
break;
result = (unsigned __int64)(a1 + 1);
v5 = 1;
do
{
if ( *(_DWORD *)result == v3 && *(_DWORD *)(result + 4) == v6 )
v5 = 0;
result += 8LL;
}
while ( (int *)result != &a1[2 * (*a1 - 1) + 3] );
}
while ( v5 != 1 );
*a2 = v3;
a2[1] = v6;
return result;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func13(int *a1, int *a2)
{
int v3; // ebx
unsigned __int64 result; // rax
int v5; // esi
int v6; // edx

do
{
v3 = rand() % 50;
result = (unsigned int)(rand() % 20);
v6 = result;
if ( v3 )
{
if ( v3 == 49 )
v3 = 48;
}
else
{
v3 = 1;
}
if ( !(_DWORD)result )
v6 = 1;
if ( *a1 <= 0 )
break;
result = (unsigned __int64)(a1 + 1);
v5 = 1;
do
{
if ( *(_DWORD *)result == v3 && *(_DWORD *)(result + 4) == v6 )
v5 = 0;
result += 8LL;
}
while ( (int *)result != &a1[2 * (*a1 - 1) + 3] );
}
while ( v5 != 1 );
*a2 = v3;
a2[1] = v6;
return result;
}

original_code:
void set_food_coord(Snake *snakey, Food* byte){
 int clear = 1;
 int newx, newy;
 do{
  if(clear == 0)
   clear = 1;
  newx = rand() % 50;
  newy = rand() % 20;
  if(newx == 0)
   newx++;
  else if(newx == 49)
   newx--;
  if(newy == 0)
   newy++;
  else if(newy == 49)
   newy--;
  int snakey_len = snakey->cur_snakey_length;
  int i;
  for(i=0; i<snakey_len; i++)
   if(snakey->body[i].x == newx && snakey->body[i].y == newy)
    clear = 0;
 }while(clear != 1);
 byte->x = newx;
 byte->y = newy;
}

canonical_original_code:
void set_food_coord(struct SnakeData *snakey, struct coord *byte){
 int clear = 1;
 int newx; int newy;
 do{
  if(clear == 0)
   clear = 1;
  newx = rand() % 50;
  newy = rand() % 20;
  if(newx == 0)
   newx++;
  else if(newx == 49)
   newx--;
  if(newy == 0)
   newy++;
  else if(newy == 49)
   newy--;
  int snakey_len = snakey->cur_snakey_length;
  int i;
  for(i=0; i<snakey_len; i++)
   if(snakey->body[i].x == newx && snakey->body[i].y == newy)
    clear = 0;
 }while(clear != 1);
 byte->x = newx;
 byte->y = newy;
}

variable_types: clear int

variable_types: newx int

variable_types: newy int


repo: SamChill/chillvm

decompiled_code:
void __fastcall destroy_vm(void *ptr)
{
free(*(void **)ptr);
free(ptr);
}

canonical_decompiled_code:
void __fastcall func7(void *ptr)
{
free(*(void **)ptr);
free(ptr);
}

original_code:
void destroy_vm(struct vm_t *vm)
{
    free(vm->mem);
    free(vm);
}

variable_types: struct vm_t { void *mem; unsigned long reg[256]; unsigned int reg_sp[32]; unsigned long ip; } *


decompiled_code:
__int64 __fastcall swap_uint32(unsigned int a1)
{
return (unsigned int)__ROL4__((a1 << 8) & 0xFF00FF00 | (a1 >> 8) & 0xFF00FF, 16);
}

canonical_decompiled_code:
__int64 __fastcall func8(unsigned int a1)
{
return (unsigned int)__ROL4__((a1 << 8) & 0xFF00FF00 | (a1 >> 8) & 0xFF00FF, 16);
}

canonical_original_code:
unsigned int swap_uint32(unsigned int val)
{
    val = ((val << 8) & 0xFF00FF00 ) | ((val >> 8) & 0xFF00FF );
    return (val << 16) | (val >> 16);
}

variable_types:
val
unsigned int

return_type: unsigned int


decompiled_code:
__int64 __fastcall swap_uint64(unsigned __int64 a1)
{
unsigned __int64 v1; // rax

v1 = (a1 >> 8) & 0xFF00FF00FF00FFLL | (a1 << 8) & 0xFF00FF00FF00FF00LL;
return __ROL8__((v1 << 16) & 0xFFFF0000FFFF0000LL | (v1 >> 16) & 0xFFFF0000FFFFLL, 32);
}

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

v1 = (a1 >> 8) & 0xFF00FF00FF00FFLL | (a1 << 8) & 0xFF00FF00FF00FF00LL;
return __ROL8__((v1 << 16) & 0xFFFF0000FFFF0000LL | (v1 >> 16) & 0xFFFF0000FFFFLL, 32);
}

canonical_original_code:
unsigned long swap_uint64(unsigned long val)
{
    val = ((val << 8) & 0xFF00FF00FF00FF00ULL ) |
          ((val >> 8) & 0x00FF00FF00FF00FFULL );
    val = ((val << 16) & 0xFFFF0000FFFF0000ULL ) |
          ((val >> 16) & 0x0000FFFF0000FFFFULL );
    return (val << 32) | (val >> 32);
}

variable_types:
val
unsigned long


decompiled_code:
void __fastcall execute_vm(__int64 *a1, __int64 a2)
{
__int64 v2; // r15
unsigned __int64 v3; // rax
bool v4; // zf
__int64 v5; // rbp
__int64 v6; // rdx
unsigned __int8 v7; // r12
_WORD *v8; // rcx
unsigned __int8 v9; // r14
unsigned __int8 v10; // r13
unsigned __int16 v11; // [rsp+8h] [rbp-40h]
int v12; // [rsp+Ch] [rbp-3Ch]

if ( a2 )
{
v2 = 0LL;
while ( 2 )
{
v4 = v2++ == -1;
v5 = *a1;
v6 = a1[273];
v7 = *(_BYTE *)(*a1 + 4 * v6 + 1);
v8 = (_WORD *)(*a1 + 4 * v6 + 2);
v9 = *(_BYTE *)v8;
v10 = *(_BYTE *)(*a1 + 4 * v6 + 3);
v11 = __ROL2__(*v8, 8);
if ( !__CFSHL__(*v8, 8) && !v4 )
LABEL_54:
exit(1);
switch ( *(_BYTE *)(*a1 + 4 * v6) )
{
case 0:
if ( !(v10 | (unsigned __int8)(v9 | v7)) )
return;
if ( v9 == 7 && v7 == 0 && v10 == 1 )
{
v3 = swap_uint64(a1[256]);
fputs((const char *)(v5 + (v3 >> 3)), stdout);
}
goto LABEL_42;
case 1:
case 2:
case 3:
case 4:
case 5:
case 6:
case 7:
case 8:
case 9:
case 0xA:
case 0xB:
case 0xC:
case 0xD:
case 0xE:
case 0xF:
case 0x10:
case 0x11:
case 0x12:
case 0x13:
case 0x14:
case 0x15:
case 0x16:
case 0x17:
case 0x1A:
case 0x1B:
case 0x1C:
case 0x1D:
case 0x1E:
case 0x1F:
case 0x22:
case 0x23:
case 0x26:
case 0x27:
case 0x28:
case 0x29:
case 0x2A:
case 0x2B:
case 0x2C:
case 0x2D:
case 0x2E:
case 0x2F:
case 0x30:
case 0x31:
case 0x32:
case 0x33:
case 0x34:
case 0x35:
case 0x36:
case 0x37:
case 0x38:
case 0x39:
case 0x3A:
case 0x3B:
case 0x3C:
case 0x3D:
case 0x3E:
case 0x3F:
case 0x40:
case 0x41:
goto LABEL_54;
case 0x18:
iswap_uint64(&a1[v9 + 1]);
if ( v9 == v10 )
{
v12 = v10;
a1[v7 + 1] = a1[v10 + 1] * a1[v9 + 1];
iswap_uint64(&a1[v7 + 1]);
if ( v7 == v9 )
goto LABEL_12;
}
else
{
v12 = v10;
iswap_uint64(&a1[v10 + 1]);
a1[v7 + 1] = a1[v10 + 1] * a1[v9 + 1];
iswap_uint64(&a1[v7 + 1]);
if ( v7 == v9 )
goto LABEL_36;
}
iswap_uint64(&a1[v9 + 1]);
LABEL_12:
if ( v9 != v10 || v7 != v10 )
goto LABEL_36;
goto LABEL_42;
case 0x19:
iswap_uint64(&a1[v9 + 1]);
a1[v7 + 1] = a1[v9 + 1] * v10;
iswap_uint64(&a1[v7 + 1]);
if ( v7 != v9 )
goto LABEL_38;
goto LABEL_42;
case 0x20:
iswap_uint64(&a1[v9 + 1]);
if ( v9 == v10 )
{
v12 = v10;
a1[v7 + 1] = a1[v9 + 1] + a1[v10 + 1];
iswap_uint64(&a1[v7 + 1]);
if ( v7 == v9 )
goto LABEL_22;
}
else
{
v12 = v10;
iswap_uint64(&a1[v10 + 1]);
a1[v7 + 1] = a1[v9 + 1] + a1[v10 + 1];
iswap_uint64(&a1[v7 + 1]);
if ( v7 == v9 )
goto LABEL_36;
}
iswap_uint64(&a1[v9 + 1]);
LABEL_22:
if ( v9 != v10 || v7 != v10 )
goto LABEL_36;
goto LABEL_42;
case 0x21:
iswap_uint64(&a1[v9 + 1]);
a1[v7 + 1] = a1[v9 + 1] + v10;
iswap_uint64(&a1[v7 + 1]);
if ( v7 != v9 )
goto LABEL_38;
goto LABEL_42;
case 0x24:
iswap_uint64(&a1[v9 + 1]);
if ( v9 == v10 )
{
v12 = v10;
a1[v7 + 1] = a1[v9 + 1] - a1[v10 + 1];
iswap_uint64(&a1[v7 + 1]);
if ( v7 == v9 )
goto LABEL_32;
}
else
{
v12 = v10;
iswap_uint64(&a1[v10 + 1]);
a1[v7 + 1] = a1[v9 + 1] - a1[v10 + 1];
iswap_uint64(&a1[v7 + 1]);
if ( v7 == v9 )
goto LABEL_36;
}
iswap_uint64(&a1[v9 + 1]);
LABEL_32:
if ( v9 != v10 || v7 != v10 )
LABEL_36:
iswap_uint64(&a1[v12 + 1]);
LABEL_42:
++a1[273];
if ( v2 != a2 )
continue;
return;
case 0x25:
iswap_uint64(&a1[v9 + 1]);
a1[v7 + 1] = a1[v9 + 1] - v10;
iswap_uint64(&a1[v7 + 1]);
if ( v7 != v9 )
LABEL_38:
iswap_uint64(&a1[v9 + 1]);
goto LABEL_42;
case 0x42:
iswap_uint64(&a1[v7 + 1]);
if ( !a1[v7 + 1] )
a1[273] += v11;
goto LABEL_41;
case 0x43:
iswap_uint64(&a1[v7 + 1]);
if ( !a1[v7 + 1] )
a1[273] -= v11;
goto LABEL_41;
case 0x44:
iswap_uint64(&a1[v7 + 1]);
if ( a1[v7 + 1] )
a1[273] += v11;
goto LABEL_41;
case 0x45:
iswap_uint64(&a1[v7 + 1]);
if ( a1[v7 + 1] )
a1[273] -= v11;
LABEL_41:
iswap_uint64(&a1[v7 + 1]);
goto LABEL_42;
default:
if ( *(unsigned __int8 *)(*a1 + 4 * v6) != 227 )
goto LABEL_54;
iswap_uint64(&a1[v7 + 1]);
a1[v7 + 1] = v11;
iswap_uint64(&a1[v7 + 1]);
goto LABEL_42;
}
}
}
}

original_code:
void execute_vm(struct vm_t *vm, long max_steps)
{
    uint8_t opcode, X, Y, Z;
    uint16_t YZ;
    uint32_t XYZ;
    long step=0;
    while (1) {
        if (step == max_steps) {
            break;
        }
        step++;
        opcode = (uint8_t)((uint32_t *)vm->mem)[vm->ip];
        X = (uint8_t)((uint8_t *)vm->mem)[4*vm->ip+1];
        Y = (uint8_t)((uint8_t *)vm->mem)[4*vm->ip+2];
        Z = (uint8_t)((uint8_t *)vm->mem)[4*vm->ip+3];
        YZ = (uint16_t)((uint16_t *)vm->mem)[2*vm->ip+1];
        YZ = (YZ << 8) | (YZ >> 8 );
        switch (opcode) {
            case 0x00:
                do { if (0) fprintf(stderr, "opcode: TRAP %""u"" %""u"" %""u""\n", X, Y, Z); } while (0);
                if (X == 0 && Y == 0 && Z == 0) return;
                if (X == 0 && Y == 7 && Z == 1) {
                    uint64_t ptr = swap_uint64(vm->reg[255]);
                    fputs((char *)vm->mem + ptr/8, stdout);
                }
                break;
            case 0x18:
                do { if (0) fprintf(stderr, "opcode: MUL $%""u"",$%""u"",$%""u""\n", X, Y, Z); } while (0);
                iswap_uint64(&vm->reg[Y]); if (Z != Y) iswap_uint64(&vm->reg[Z]);;
                vm->reg[X] = vm->reg[Y] * vm->reg[Z];
                iswap_uint64(&vm->reg[X]); if (Y != X) iswap_uint64(&vm->reg[Y]); if (Z != Y || Z != X) iswap_uint64(&vm->reg[Z]);;
                break;
            case 0x19:
                do { if (0) fprintf(stderr, "opcode: MUL $%""u"",$%""u"",%""u""\n", X, Y, Z); } while (0);
                iswap_uint64(&vm->reg[Y]);
                do { if (0) fprintf(stderr, "        MUL %""l" "u"" %""l" "u"" %""u""\n", vm->reg[X], vm->reg[Y], Z); } while (0);
                vm->reg[X] = vm->reg[Y] * Z;
                iswap_uint64(&vm->reg[X]); if (Y != X) iswap_uint64(&vm->reg[Y]);;
                break;
            case 0x20:
                do { if (0) fprintf(stderr, "opcode: ADD $%""u"",$%""u"",$%""u""\n", X, Y, Z); } while (0);
                iswap_uint64(&vm->reg[Y]); if (Z != Y) iswap_uint64(&vm->reg[Z]);;
                vm->reg[X] = vm->reg[Y] + vm->reg[Z];
                iswap_uint64(&vm->reg[X]); if (Y != X) iswap_uint64(&vm->reg[Y]); if (Z != Y || Z != X) iswap_uint64(&vm->reg[Z]);;
                break;
            case 0x21:
                do { if (0) fprintf(stderr, "opcode: ADD $%""u"",$%""u"",%""u""\n", X, Y, Z); } while (0);
                iswap_uint64(&vm->reg[Y]);
                vm->reg[X] = vm->reg[Y] + Z;
                iswap_uint64(&vm->reg[X]); if (Y != X) iswap_uint64(&vm->reg[Y]);;
                break;
            case 0x24:
                do { if (0) fprintf(stderr, "opcode: SUB $%""u"",$%""u"",$%""u""\n", X, Y, Z); } while (0);
                iswap_uint64(&vm->reg[Y]); if (Z != Y) iswap_uint64(&vm->reg[Z]);;
                vm->reg[X] = vm->reg[Y] - vm->reg[Z];
                iswap_uint64(&vm->reg[X]); if (Y != X) iswap_uint64(&vm->reg[Y]); if (Z != Y || Z != X) iswap_uint64(&vm->reg[Z]);;
                break;
            case 0x25:
                do { if (0) fprintf(stderr, "opcode: SUB $%""u"",$%""u"",%""u""\n", X, Y, Z); } while (0);
                iswap_uint64(&vm->reg[Y]);
                do { if (0) fprintf(stderr, "        SUB %""l" "u"",%""l" "u"",%""u""\n", vm->reg[X], vm->reg[Y], Z); } while (0);
                vm->reg[X] = vm->reg[Y] - Z;
                iswap_uint64(&vm->reg[X]); if (Y != X) iswap_uint64(&vm->reg[Y]);;
                break;
            case 0x42:
                do { if (0) fprintf(stderr, "opcode: BZ  $%""u"",%""u""\n", X, YZ); } while (0);
                iswap_uint64(&vm->reg[X]);
                if (vm->reg[X] == 0) vm->ip += YZ;
                iswap_uint64(&vm->reg[X]);
                break;
            case 0x43:
                do { if (0) fprintf(stderr, "opcode: BZ  $%""u"",-%""u""\n", X, YZ); } while (0);
                iswap_uint64(&vm->reg[X]);
                if (vm->reg[X] == 0) vm->ip -= YZ;
                iswap_uint64(&vm->reg[X]);
                break;
            case 0x44:
                do { if (0) fprintf(stderr, "opcode: BP  $%""u"",%""u""\n", X, YZ); } while (0);
                iswap_uint64(&vm->reg[X]);
                if (vm->reg[X] > 0) vm->ip += YZ;
                iswap_uint64(&vm->reg[X]);
                break;
            case 0x45:
                do { if (0) fprintf(stderr, "opcode: BP  $%""u"",-%""u""\n", X, YZ); } while (0);
                iswap_uint64(&vm->reg[X]);
                do { if (0) fprintf(stderr, "        BP  %""l" "u"",-%""u""\n", vm->reg[X], YZ); } while (0);
                if (vm->reg[X] > 0) vm->ip -= YZ;
                iswap_uint64(&vm->reg[X]);
                break;
            case 0xE3:
                do { if (0) fprintf(stderr, "opcode: SETL $%""u"",%""u""\n", X, YZ); } while (0);
                iswap_uint64(&vm->reg[X]);
                do { if (0) fprintf(stderr, "        SETL %""l" "u"",%""u""\n", vm->reg[X], YZ); } while (0);
                vm->reg[X] = YZ;
                iswap_uint64(&vm->reg[X]);
                break;
            default:
                do { if (0) fprintf(stderr, "error: unknown opcode: %.2""x""\n", opcode); } while (0);
                exit(1);
        }
        vm->ip++;
    }
}

canonical_original_code:
void execute_vm(struct vm_t *vm, long max_steps)
{
    unsigned char opcode; unsigned char X; unsigned char Y; unsigned char Z;
    unsigned short YZ;
    unsigned int XYZ;
    long step = 0;
    while (1) {
        if (step == max_steps) {
            break;
        }
        step++;
        opcode = (unsigned char)((unsigned int *)vm->mem)[vm->ip];
        X = (unsigned char)((unsigned char *)vm->mem)[4*vm->ip+1];
        Y = (unsigned char)((unsigned char *)vm->mem)[4*vm->ip+2];
        Z = (unsigned char)((unsigned char *)vm->mem)[4*vm->ip+3];
        YZ = (unsigned short)((unsigned short *)vm->mem)[2*vm->ip+1];
        YZ = (YZ << 8) | (YZ >> 8 );
        switch (opcode) {
            case 0x00:
                do { if (0) fprintf(stderr, "opcode: TRAP %""u"" %""u"" %""u""\n", X, Y, Z); } while (0);
                if (X == 0 && Y == 0 && Z == 0) return;
                if (X == 0 && Y == 7 && Z == 1) {
                    unsigned long ptr = swap_uint64(vm->reg[255]);
                    fputs((char *)vm->mem + ptr/8, stdout);
                }
                break;
            case 0x18:
                do { if (0) fprintf(stderr, "opcode: MUL $%""u"",$%""u"",$%""u""\n", X, Y, Z); } while (0);
                iswap_uint64(&vm->reg[Y]); if (Z != Y) iswap_uint64(&vm->reg[Z]);;
                vm->reg[X] = vm->reg[Y] * vm->reg[Z];
                iswap_uint64(&vm->reg[X]); if (Y != X) iswap_uint64(&vm->reg[Y]); if (Z != Y || Z != X) iswap_uint64(&vm->reg[Z]);;
                break;
            case 0x19:
                do { if (0) fprintf(stderr, "opcode: MUL $%""u"",$%""u"",%""u""\n", X, Y, Z); } while (0);
                iswap_uint64(&vm->reg[Y]);
                do { if (0) fprintf(stderr, "        MUL %""l" "u"" %""l" "u"" %""u""\n", vm->reg[X], vm->reg[Y], Z); } while (0);
                vm->reg[X] = vm->reg[Y] * Z;
                iswap_uint64(&vm->reg[X]); if (Y != X) iswap_uint64(&vm->reg[Y]);;
                break;
            case 0x20:
                do { if (0) fprintf(stderr, "opcode: ADD $%""u"",$%""u"",$%""u""\n", X, Y, Z); } while (0);
                iswap_uint64(&vm->reg[Y]); if (Z != Y) iswap_uint64(&vm->reg[Z]);;
                vm->reg[X] = vm->reg[Y] + vm->reg[Z];
                iswap_uint64(&vm->reg[X]); if (Y != X) iswap_uint64(&vm->reg[Y]); if (Z != Y || Z != X) iswap_uint64(&vm->reg[Z]);;
                break;
            case 0x21:
                do { if (0) fprintf(stderr, "opcode: ADD $%""u"",$%""u"",%""u""\n", X, Y, Z); } while (0);
                iswap_uint64(&vm->reg[Y]);
                vm->reg[X] = vm->reg[Y] + Z;
                iswap_uint64(&vm->reg[X]); if (Y != X) iswap_uint64(&vm->reg[Y]);;
                break;
            case 0x24:
                do { if (0) fprintf(stderr, "opcode: SUB $%""u"",$%""u"",$%""u""\n", X, Y, Z); } while (0);
                iswap_uint64(&vm->reg[Y]); if (Z != Y) iswap_uint64(&vm->reg[Z]);;
                vm->reg[X] = vm->reg[Y] - vm->reg[Z];
                iswap_uint64(&vm->reg[X]); if (Y != X) iswap_uint64(&vm->reg[Y]); if (Z != Y || Z != X) iswap_uint64(&vm->reg[Z]);;
                break;
            case 0x25:
                do { if (0) fprintf(stderr, "opcode: SUB $%""u"",$%""u"",%""u""\n", X, Y, Z); } while (0);
                iswap_uint64(&vm->reg[Y]);
                do { if (0) fprintf(stderr, "        SUB %""l" "u"",%""l" "u"",%""u""\n", vm->reg[X], vm->reg[Y], Z); } while (0);
                vm->reg[X] = vm->reg[Y] - Z;
                iswap_uint64(&vm->reg[X]); if (Y != X) iswap_uint64(&vm->reg[Y]);;
                break;
            case 0x42:
                do { if (0) fprintf(stderr, "opcode: BZ  $%""u"",%""u""\n", X, YZ); } while (0);
                iswap_uint64(&vm->reg[X]);
                if (vm->reg[X] == 0) vm->ip += YZ;
                iswap_uint64(&vm->reg[X]);
                break;
            case 0x43:
                do { if (0) fprintf(stderr, "opcode: BZ  $%""u"",-%""u""\n", X, YZ); } while (0);
                iswap_uint64(&vm->reg[X]);
                if (vm->reg[X] == 0) vm->ip -= YZ;
                iswap_uint64(&vm->reg[X]);
                break;
            case 0x44:
                do { if (0) fprintf(stderr, "opcode: BP  $%""u"",%""u""\n", X, YZ); } while (0);
                iswap_uint64(&vm->reg[X]);
                if (vm->reg[X] > 0) vm->ip += YZ;
                iswap_uint64(&vm->reg[X]);
                break;
            case 0x45:
                do { if (0) fprintf(stderr, "opcode: BP  $%""u"",-%""u""\n", X, YZ); } while (0);
                iswap_uint64(&vm->reg[X]);
                do { if (0) fprintf(stderr, "        BP  %""l" "u"",-%""u""\n", vm->reg[X], YZ); } while (0);
                if (vm->reg[X] > 0) vm->ip -= YZ;
                iswap_uint64(&vm->reg[X]);
                break;
            case 0xE3:
                do { if (0) fprintf(stderr, "opcode: SETL $%""u"",%""u""\n", X, YZ); } while (0);
                iswap_uint64(&vm->reg[X]);
                do { if (0) fprintf(stderr, "        SETL %""l" "u"",%""u""\n", vm->reg[X], YZ); } while (0);
                vm->reg[X] = YZ;
                iswap_uint64(&vm->reg[X]);
                break;
            default:
                do { if (0) fprintf(stderr, "error: unknown opcode: %.2""x""\n", opcode); } while (0);
                exit(1);
        }
        vm->ip++;
    }
}

variable_types:
opcode
unsigned char

variable_types:
X
unsigned char

variable_types:
Y
unsigned char

variable_types:
Z
unsigned char

variable_types:
YZ
unsigned short

variable_types:
XYZ
unsigned int

variable_types: step long

variable_types:
ptr
unsigned long

user_defined_types: struct vm_t { void *mem; unsigned long reg[256]; unsigned int reg_sp[32]; unsigned long ip; }


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 *v3; // rax
__int64 *v4; // rbx
int result; // eax

if ( argc <= 1 )
{
fprintf(stderr, "usage: %s EXE\n", *argv);
result = 1;
}
else
{
v3 = (__int64 *)loader(argc - 1, argv + 1, 0x100000uLL);
v4 = v3;
if ( v3 )
{
execute_vm(v3, 10000LL);
destroy_vm(v4);
result = 0;
}
else
{
fprintf(stderr, "error: problem loading %s\n", argv[1]);
result = 1;
}
}
return result;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 *v3; // rax
__int64 *v4; // rbx
int result; // eax

if ( argc <= 1 )
{
fprintf(stderr, "usage: %s EXE\n", *argv);
result = 1;
}
else
{
v3 = (__int64 *)func11(argc - 1, argv + 1, 0x100000uLL);
v4 = v3;
if ( v3 )
{
func12(v3, 10000LL);
func7(v4);
result = 0;
}
else
{
fprintf(stderr, "error: problem loading %s\n", argv[1]);
result = 1;
}
}
return result;
}

original_code:
int main(int argc, char **argv)
{
    if (argc < 2) {
        fprintf(stderr, "usage: %s EXE\n", argv[0]);
        return 1;
    }
    struct vm_t *vm = loader(argc-1, argv+1, 1024*1024);
    if (vm == ((void *)0)) {
        fprintf(stderr, "error: problem loading %s\n", argv[1]);
        return 1;
    }
    execute_vm(vm, 10000);
    destroy_vm(vm);
    return 0;
}

variable_types: argc int

variable_types:
argv
char **


Fatal

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

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

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

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

original_code:
void Fatal(const char* format , ...)
{
   va_list args;
   __builtin_va_start(args,format);
   vfprintf(stderr,format,args);
   __builtin_va_end(args);
   exit(1);
}

canonical_original_code:
void Fatal(char *format, ...)
{
   __builtin_va_list args;
   __builtin_va_start(args,format);
   vfprintf(stderr,format,args);
   __builtin_va_end(args);
   exit(1);
}

variable_types:
format
char *


decompiled_code:
void *__fastcall flock_init(__int64 a1, int a2)
{
void *result; // rax
__int64 v3; // r12
__int64 v4; // rbx

*(_QWORD *)a1 = malloc(264LL * a2);
result = malloc(100LL * a2);
*(_QWORD *)(a1 + 8) = result;
*(_DWORD *)(a1 + 16) = a2;
if ( a2 > 0 )
{
v3 = 0LL;
v4 = 0LL;
do
{
Boid_init(*(_QWORD *)(a1 + 8) + v4, 0.0, 0.0, 0.0);
bird_initBird(*(_QWORD *)a1 + v3, *(_QWORD *)(a1 + 8) + v4);
result = (void *)bird_randomizePosition(*(_QWORD *)a1 + v3);
v4 += 100LL;
v3 += 264LL;
}
while ( v4 != 100LL * (unsigned int)a2 );
}
return result;
}

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

*(_QWORD *)a1 = malloc(264LL * a2);
result = malloc(100LL * a2);
*(_QWORD *)(a1 + 8) = result;
*(_DWORD *)(a1 + 16) = a2;
if ( a2 > 0 )
{
v3 = 0LL;
v4 = 0LL;
do
{
Boid_init(*(_QWORD *)(a1 + 8) + v4, 0.0, 0.0, 0.0);
bird_initBird(*(_QWORD *)a1 + v3, *(_QWORD *)(a1 + 8) + v4);
result = (void *)bird_randomizePosition(*(_QWORD *)a1 + v3);
v4 += 100LL;
v3 += 264LL;
}
while ( v4 != 100LL * (unsigned int)a2 );
}
return result;
}

original_code:
void flock_init(Flock * flock, int numBirds)
{
    int i;
    flock->birds = malloc(sizeof(Bird) * numBirds);
    flock->boids = malloc(sizeof(Boid) * numBirds);
    flock->numBirds = numBirds;
    for(i=0; i<numBirds; i++)
    {
        Boid_init(flock->boids+i, 0, 0, 0);
        bird_initBird(flock->birds+i, flock->boids+i);
        bird_randomizePosition(flock->birds+i);
    }
}

canonical_original_code:
void flock_init(struct Flock *flock, int numBirds)
{
    int i;
    flock->birds = malloc(sizeof(Bird) * numBirds);
    flock->boids = malloc(sizeof(Boid) * numBirds);
    flock->numBirds = numBirds;
    for(i=0; i<numBirds; i++)
    {
        Boid_init(flock->boids+i, 0, 0, 0);
        bird_initBird(flock->birds+i, flock->boids+i);
        bird_randomizePosition(flock->birds+i);
    }
}

variable_types: struct Flock { struct Bird { struct QuadObject { struct ColoredVertex { float pos[3]; float col[3]; } *ver; int numVer; struct Quad { unsigned int ver[4]; float norm[3]; int hasTexture; int textureNum; } *quad; int numQuad; short outOfBounds; int numQuadAssigned; int numVerAssigned; float r; float g; float b; float x; float y; float z; int hasTexture; int textureNum; float curX; float curY; float curZ; float curRot; float curRoll; float curPitch; float curYaw; float xScale; float yScale; float zScale; } quadObject; int flapping; float flappingAmount; int *frontTopLeftWing; int *backTopLeftWing; int *frontBottomLeftWing; int *backBottomLeftWing; int *frontTopRightWing; int *backTopRightWing; int *frontBottomRightWing; int *backBottomRightWing; struct ColoredVertex *origFrontTopLeftWing; struct ColoredVertex *origBackTopLeftWing; struct ColoredVertex *origFrontBottomLeftWing; struct ColoredVertex *origBackBottomLeftWing; struct ColoredVertex *origFrontTopRightWing; struct ColoredVertex *origBackTopRightWing; struct ColoredVertex *origFrontBottomRightWing; struct ColoredVertex *origBackBottomRightWing; int startWingQuadIndex; int endWingQuadIndex; struct Boid { struct PhysicsObject { float mass; struct PhysicsVector { float x; float y; float z; } position; struct PhysicsVector acceleration; struct PhysicsVector velocity; } physicsObject; struct PhysicsVector heading; float r; float maxForce; float maxSpeed; int minX; int minY; int minZ; int maxX; int maxY; int maxZ; float seperationWeight; float alignWeight; float cohesionWeight; } *boid; } *birds; struct Boid *boids; int numBirds; } *

variable_types: numBirds int

variable_types: i int

user_defined_types: struct Flock { struct Bird *birds; struct Boid *boids; int numBirds; }

user_defined_types: struct Bird { struct QuadObject quadObject; int flapping; float flappingAmount; int *frontTopLeftWing; int *backTopLeftWing; int *frontBottomLeftWing; int *backBottomLeftWing; int *frontTopRightWing; int *backTopRightWing; int *frontBottomRightWing; int *backBottomRightWing; struct ColoredVertex *origFrontTopLeftWing; struct ColoredVertex *origBackTopLeftWing; struct ColoredVertex *origFrontBottomLeftWing; struct ColoredVertex *origBackBottomLeftWing; struct ColoredVertex *origFrontTopRightWing; struct ColoredVertex *origBackTopRightWing; struct ColoredVertex *origFrontBottomRightWing; struct ColoredVertex *origBackBottomRightWing; int startWingQuadIndex; int endWingQuadIndex; struct Boid *boid; }

user_defined_types: struct QuadObject { struct ColoredVertex *ver; int numVer; struct Quad *quad; int numQuad; short outOfBounds; int numQuadAssigned; int numVerAssigned; float r; float g; float b; float x; float y; float z; int hasTexture; int textureNum; float curX; float curY; float curZ; float curRot; float curRoll; float curPitch; float curYaw; float xScale; float yScale; float zScale; }

user_defined_types: struct Boid { struct PhysicsObject physicsObject; struct PhysicsVector heading; float r; float maxForce; float maxSpeed; int minX; int minY; int minZ; int maxX; int maxY; int maxZ; float seperationWeight; float alignWeight; float cohesionWeight; }

user_defined_types: struct PhysicsObject { float mass; struct PhysicsVector position; struct PhysicsVector acceleration; struct PhysicsVector velocity; }


decompiled_code:
__int64 __fastcall flock_getBird(_QWORD *a1, int a2)
{
return *a1 + 264LL * a2;
}

canonical_decompiled_code:
__int64 __fastcall func1(_QWORD *a1, int a2)
{
return *a1 + 264LL * a2;
}

original_code:
Bird * flock_getBird(Flock * flock, int index)
{
    return flock->birds+index;
}

canonical_original_code:
struct Bird *flock_getBird(struct Flock *flock, int index)
{
    return flock->birds+index;
}

variable_types: struct Flock { struct Bird *birds; struct Boid *boids; int numBirds; } *

variable_types: index int

return_type: struct Bird { struct QuadObject { struct ColoredVertex { float pos[3]; float col[3]; } *ver; int numVer; struct Quad { unsigned int ver[4]; float norm[3]; int hasTexture; int textureNum; } *quad; int numQuad; short outOfBounds; int numQuadAssigned; int numVerAssigned; float r; float g; float b; float x; float y; float z; int hasTexture; int textureNum; float curX; float curY; float curZ; float curRot; float curRoll; float curPitch; float curYaw; float xScale; float yScale; float zScale; } quadObject; int flapping; float flappingAmount; int *frontTopLeftWing; int *backTopLeftWing; int *frontBottomLeftWing; int *backBottomLeftWing; int *frontTopRightWing; int *backTopRightWing; int *frontBottomRightWing; int *backBottomRightWing; struct ColoredVertex *origFrontTopLeftWing; struct ColoredVertex *origBackTopLeftWing; struct ColoredVertex *origFrontBottomLeftWing; struct ColoredVertex *origBackBottomLeftWing; struct ColoredVertex *origFrontTopRightWing; struct ColoredVertex *origBackTopRightWing; struct ColoredVertex *origFrontBottomRightWing; struct ColoredVertex *origBackBottomRightWing; int startWingQuadIndex; int endWingQuadIndex; struct Boid { struct PhysicsObject { float mass; struct PhysicsVector { float x; float y; float z; } position; struct PhysicsVector acceleration; struct PhysicsVector velocity; } physicsObject; struct PhysicsVector heading; float r; float maxForce; float maxSpeed; int minX; int minY; int minZ; int maxX; int maxY; int maxZ; float seperationWeight; float alignWeight; float cohesionWeight; } *boid; } *