decompiled_code:
unsigned __int64 print_commands()
{
unsigned __int64 v1; // [rsp+8h] [rbp-10h]

v1 = __readfsqword(0x28u);
puts("Unrecognizable command");
puts("Printing commands and their usage!");
puts("Invalid command, valid commands are:");
puts("quit");
puts("list");
puts("show <email_address>");
puts("paths <email_address>");
return v1 - __readfsqword(0x28u);
}

canonical_decompiled_code:
unsigned __int64 func9()
{
unsigned __int64 v1; // [rsp+8h] [rbp-10h]

v1 = __readfsqword(0x28u);
puts("Unrecognizable command");
puts("Printing commands and their usage!");
puts("Invalid command, valid commands are:");
puts("quit");
puts("list");
puts("show <email_address>");
puts("paths <email_address>");
return v1 - __readfsqword(0x28u);
}

original_code:
void print_commands()
{
  printf("Unrecognizable command\n");
  printf("Printing commands and their usage!\n");
  printf("Invalid command, valid commands are:\n");
  printf("quit\n");
  printf("list\n");
  printf("show <email_address>\n");
  printf("paths <email_address>\n");
  return;
}


repo: ExperimentMonty/tutoring

decompiled_code:
unsigned __int64 __fastcall show_statistics(const char *a1)
{
unsigned __int64 v2; // [rsp+8h] [rbp-10h]

v2 = __readfsqword(0x28u);
printf("Showing statistics about %s\n", a1);
return v2 - __readfsqword(0x28u);
}

canonical_decompiled_code:
unsigned __int64 __fastcall func10(const char *a1)
{
unsigned __int64 v2; // [rsp+8h] [rbp-10h]

v2 = __readfsqword(0x28u);
printf("Showing statistics about %s\n", a1);
return v2 - __readfsqword(0x28u);
}

original_code:
void show_statistics(char* email)
{
  printf("Showing statistics about %s\n", email);
  return;
}

canonical_original_code:
void show_statistics(char *email)
{
  printf("Showing statistics about %s\n", email);
  return;
}

variable_types:
email
char *

return_type: void


decompiled_code:
unsigned __int64 __fastcall show_paths(const char *a1)
{
unsigned __int64 v2; // [rsp+8h] [rbp-10h]

v2 = __readfsqword(0x28u);
printf("Showing paths for %s\n", a1);
return v2 - __readfsqword(0x28u);
}

canonical_decompiled_code:
unsigned __int64 __fastcall func11(const char *a1)
{
unsigned __int64 v2; // [rsp+8h] [rbp-10h]

v2 = __readfsqword(0x28u);
printf("Showing paths for %s\n", a1);
return v2 - __readfsqword(0x28u);
}

original_code:
void show_paths(char* email)
{
  printf("Showing paths for %s\n", email);
  return;
}

canonical_original_code:
void show_paths(char *email)
{
  printf("Showing paths for %s\n", email);
  return;
}


repo: Extraterrestrial/zombies

decompiled_code:
int zombies_lookout()
{
__int64 v0; // rbx
int result; // eax

if ( zombie_size > 0 )
{
v0 = 0LL;
do
result = printf("Zombie \"%s\".\n", *((const char **)zombie + v0++));
while ( zombie_size > (int)v0 );
}
return result;
}

canonical_decompiled_code:
int func7()
{
__int64 v0; // rbx
int result; // eax

if ( zombie_size > 0 )
{
v0 = 0LL;
do
result = printf("Zombie \"%s\".\n", *((const char **)zombie + v0++));
while ( zombie_size > (int)v0 );
}
return result;
}

original_code:
void zombies_lookout()
{
  int i = 0;
  for(i = 0; i < zombie_size; i++)
  printf("Zombie \"%s\".\n", zombie[i]);
  return;
}

variable_types: i int


decompiled_code:
__int64 zombies_check_corpses()
{
const char **v0; // rax
unsigned int v1; // er8

if ( zombie_size <= 0 )
return 0;
v0 = (const char **)zombie;
v1 = 0;
do
v1 += strcmp(*v0++, "_CORPSE") == 0;
while ( v0 != (const char **)((char *)zombie + 8 * (unsigned int)(zombie_size - 1) + 8) );
return v1;
}

canonical_decompiled_code:
__int64 func8()
{
const char **v0; // rax
unsigned int v1; // er8

if ( zombie_size <= 0 )
return 0;
v0 = (const char **)zombie;
v1 = 0;
do
v1 += strcmp(*v0++, "_CORPSE") == 0;
while ( v0 != (const char **)((char *)zombie + 8 * (unsigned int)(zombie_size - 1) + 8) );
return v1;
}

original_code:
int zombies_check_corpses()
{
  int i, corpse_count;
  for(i = 0; i < zombie_size; i++) {
    if(!strcmp(zombie[i], "_CORPSE"))
      corpse_count++;
  }
  return corpse_count;
}

canonical_original_code:
int zombies_check_corpses()
{
  int i; int corpse_count;
  for(i = 0; i < zombie_size; i++) {
    if(!strcmp(zombie[i], "_CORPSE"))
      corpse_count++;
  }
  return corpse_count;
}

return_type: int


decompiled_code:
__int64 zombies_reload_ammo()
{
puts("Reloading shotgun...");
usleep(0x2DC6C0u);
return 7LL;
}

canonical_decompiled_code:
__int64 func9()
{
puts("Reloading shotgun...");
usleep(0x2DC6C0u);
return 7LL;
}

original_code:
int zombies_reload_ammo(int ammo)
{
  printf("Reloading shotgun...\n");
  usleep((3000)*1000);
  ammo = 7;
  return ammo;
}

variable_types: ammo int


decompiled_code:
__int64 zombies_start()
{
unsigned int v0; // eax
int v1; // ebx
__int64 v2; // rbx
int v3; // eax
char **v4; // rbp
__int64 v5; // rbx

free(zombie);
v0 = time(0LL);
srand(v0);
++wave;
v1 = zombie_size + 5;
zombie_size = v1;
zombie = malloc(8LL * v1);
if ( v1 > 0 )
{
v2 = 0LL;
do
{
v3 = rand();
v4 = (char **)((char *)zombie + 8 * v2);
*v4 = strdup((&names)[v3 % 57]);
++v2;
}
while ( zombie_size > (int)v2 );
}
printf("Wave %d, get ready...\n", (unsigned int)wave);
usleep(0x2DC6C0u);
zombies_lookout();
if ( zombie_size > 0 )
{
v5 = 0LL;
do
{
if ( !strcmp(*((const char **)zombie + v5), "_CORPSE") )
{
usleep(1000 * zomb_time);
if ( (unsigned int)zombies_check_corpses() == zombie_size )
return 0LL;
}
else
{
printf("Zombie \"%s\" is nearby, shoot them NOW!!!\n", *((const char **)zombie + v5));
usleep(1000 * zomb_time);
}
if ( strcmp(*((const char **)zombie + v5), "_CORPSE") )
{
printf("\nZombie \"%s\" kill you!\n", *((const char **)zombie + v5));
puts("You was eaten by zombies.");
puts("Your dead of valor will be remembered.");
killme = 1;
printf("Your score: %d zombies.\n", (unsigned int)score);
free(zombie);
exit(0);
}
++v5;
}
while ( zombie_size > (int)v5 );
}
if ( wave == 5 * (wave / 5) )
{
if ( zomb_time > 1300 )
{
zomb_time -= 200;
puts("Zombie time has increased...");
}
zombie_size = 0;
}
return 0LL;
}

canonical_decompiled_code:
__int64 func10()
{
unsigned int v0; // eax
int v1; // ebx
__int64 v2; // rbx
int v3; // eax
char **v4; // rbp
__int64 v5; // rbx

free(zombie);
v0 = time(0LL);
srand(v0);
++wave;
v1 = zombie_size + 5;
zombie_size = v1;
zombie = malloc(8LL * v1);
if ( v1 > 0 )
{
v2 = 0LL;
do
{
v3 = rand();
v4 = (char **)((char *)zombie + 8 * v2);
*v4 = strdup((&names)[v3 % 57]);
++v2;
}
while ( zombie_size > (int)v2 );
}
printf("Wave %d, get ready...\n", (unsigned int)wave);
usleep(0x2DC6C0u);
func7();
if ( zombie_size > 0 )
{
v5 = 0LL;
do
{
if ( !strcmp(*((const char **)zombie + v5), "_CORPSE") )
{
usleep(1000 * zomb_time);
if ( (unsigned int)func8() == zombie_size )
return 0LL;
}
else
{
printf("Zombie \"%s\" is nearby, shoot them NOW!!!\n", *((const char **)zombie + v5));
usleep(1000 * zomb_time);
}
if ( strcmp(*((const char **)zombie + v5), "_CORPSE") )
{
printf("\nZombie \"%s\" kill you!\n", *((const char **)zombie + v5));
puts("You was eaten by zombies.");
puts("Your dead of valor will be remembered.");
killme = 1;
printf("Your score: %d zombies.\n", (unsigned int)score);
free(zombie);
exit(0);
}
++v5;
}
while ( zombie_size > (int)v5 );
}
if ( wave == 5 * (wave / 5) )
{
if ( zomb_time > 1300 )
{
zomb_time -= 200;
puts("Zombie time has increased...");
}
zombie_size = 0;
}
return 0LL;
}

original_code:
int zombies_start()
{
  int i = 0;
  free(zombie);
  srand(time(((void *)0)));
  wave++;
  zombie_size += 5;
  zombie = malloc(sizeof(char *) * zombie_size);
  for(i = 0; i < zombie_size; i++) {
    zombie[i] = strdup(names[rand() % 57]);
  }
  printf("Wave %d, get ready...\n", wave);
  usleep((3000)*1000);
  zombies_lookout();
  for(i = 0; i < zombie_size; i++) {
    if(strcmp(zombie[i], "_CORPSE")) {
      printf("Zombie \"%s\" is nearby, shoot them NOW!!!\n", zombie[i]);
      usleep((zomb_time)*1000);
    }
    else {
      usleep((zomb_time)*1000);
      if(zombies_check_corpses() == zombie_size)
        return 0;
    }
    if(strcmp(zombie[i], "_CORPSE")) {
      printf("\nZombie \"%s\" kill you!\n", zombie[i]);
      printf("You was eaten by zombies.\n");
      printf("Your dead of valor will be remembered.\n");
      killme = 1;
      printf("Your score: %d zombies.\n", score);
      free(zombie);
      exit(0);
    }
  }
  if(wave % 5 == 0) {
    if(zomb_time > 1300) {
        zomb_time-=200;
        printf("Zombie time has increased...\n");
    }
    zombie_size = 0;
  }
  return 0;
}


threadfunc

decompiled_code:
void __fastcall __noreturn threadfunc(void *a1)
{
while ( 1 )
zombies_start(a1);
}

canonical_decompiled_code:
void __fastcall __noreturn func11(void *a1)
{
while ( 1 )
func10(a1);
}

original_code:
static void * threadfunc(void * arg)
{
  while(1) {
    zombies_start();
  }
}

canonical_original_code:
static void *threadfunc(void *arg)
{
  while(1) {
    zombies_start();
  }
}

variable_types:
arg
void *

return_type: void *


shoot

decompiled_code:
__int64 shoot()
{
const char *v0; // r12
bool v1; // al
bool v2; // cf
bool v3; // zf
char *v4; // rdi
__int64 v5; // rcx
const char *v6; // rsi
const char **v7; // rbp
const char **v8; // r14
char *v9; // r13
unsigned int v10; // ebx

v0 = (const char *)malloc(0xFFuLL);
usleep(0x3E8u);
printf("Target: ");
__isoc99_scanf();
if ( !strcmp(v0, "l") )
{
zombies_lookout();
v10 = 1;
}
else
{
v1 = strcmp(v0, "a") != 0;
v2 = 0;
v3 = !v1;
if ( v1 )
{
v4 = "r";
v5 = 2LL;
v6 = v0;
do
{
if ( !v5 )
break;
v2 = (unsigned int)*v6 < (unsigned __int8)*v4;
v3 = *v6++ == (unsigned __int8)*v4++;
--v5;
}
while ( v3 );
if ( (!v2 && !v3) == v2 )
{
ammo_0 = zombies_reload_ammo((unsigned int)ammo_0, v6);
v10 = 1;
}
else if ( ammo_0 )
{
if ( !strcmp(v0, "_CORPSE") )
{
puts("You can't kill corpse, lol");
--ammo_0;
v10 = 1;
}
else
{
puts("Player shoots with good shotgun...");
--ammo_0;
if ( zombie_size <= 0 )
{
LABEL_13:
puts("You are missed, zombie is still alive...");
v10 = 1;
}
else
{
v7 = (const char **)zombie;
v8 = (const char **)((char *)zombie + 8 * (unsigned int)(zombie_size - 1) + 8);
while ( 1 )
{
v9 = (char *)*v7;
v10 = strcmp(*v7, v0);
if ( !v10 )
break;
if ( ++v7 == v8 )
goto LABEL_13;
}
*(_QWORD *)v9 = 0x455350524F435FLL;
puts("Zombie killed!\n");
++score;
}
}
}
else
{
puts("You have no ammo in the shotgun.");
v10 = 1;
}
}
else
{
printf("Ammo: %d/7\n", (unsigned int)ammo_0);
v10 = 1;
}
}
return v10;
}

canonical_decompiled_code:
__int64 func12()
{
const char *v0; // r12
bool v1; // al
bool v2; // cf
bool v3; // zf
char *v4; // rdi
__int64 v5; // rcx
const char *v6; // rsi
const char **v7; // rbp
const char **v8; // r14
char *v9; // r13
unsigned int v10; // ebx

v0 = (const char *)malloc(0xFFuLL);
usleep(0x3E8u);
printf("Target: ");
__isoc99_scanf();
if ( !strcmp(v0, "l") )
{
func7();
v10 = 1;
}
else
{
v1 = strcmp(v0, "a") != 0;
v2 = 0;
v3 = !v1;
if ( v1 )
{
v4 = "r";
v5 = 2LL;
v6 = v0;
do
{
if ( !v5 )
break;
v2 = (unsigned int)*v6 < (unsigned __int8)*v4;
v3 = *v6++ == (unsigned __int8)*v4++;
--v5;
}
while ( v3 );
if ( (!v2 && !v3) == v2 )
{
ammo_0 = func9((unsigned int)ammo_0, v6);
v10 = 1;
}
else if ( ammo_0 )
{
if ( !strcmp(v0, "_CORPSE") )
{
puts("You can't kill corpse, lol");
--ammo_0;
v10 = 1;
}
else
{
puts("Player shoots with good shotgun...");
--ammo_0;
if ( zombie_size <= 0 )
{
LABEL_13:
puts("You are missed, zombie is still alive...");
v10 = 1;
}
else
{
v7 = (const char **)zombie;
v8 = (const char **)((char *)zombie + 8 * (unsigned int)(zombie_size - 1) + 8);
while ( 1 )
{
v9 = (char *)*v7;
v10 = strcmp(*v7, v0);
if ( !v10 )
break;
if ( ++v7 == v8 )
goto LABEL_13;
}
*(_QWORD *)v9 = 0x455350524F435FLL;
puts("Zombie killed!\n");
++score;
}
}
}
else
{
puts("You have no ammo in the shotgun.");
v10 = 1;
}
}
else
{
printf("Ammo: %d/7\n", (unsigned int)ammo_0);
v10 = 1;
}
}
return v10;
}

original_code:
int shoot()
{
  char * target = malloc(255);
  int i = 0;
  static char ammo = 7;
  usleep((1)*1000);
  printf("Target: ");
 scanf("%s", target);
 if(!strcmp(target, "l")) {
   zombies_lookout();
   return 1;
  }
  else if(!strcmp(target, "a")) {
   printf("Ammo: %d/7\n", ammo);
   return 1;
  }
  else if(!strcmp(target, "r")) {
    ammo = zombies_reload_ammo(ammo);
    return 1;
  }
  if(ammo == 0) {
    printf("You have no ammo in the shotgun.\n");
    return 1;
  }
  else if(!strcmp(target, "_CORPSE")) {
    printf("You can't kill corpse, lol\n");
    ammo--;
    return 1;
  }
  printf("Player shoots with good shotgun...\n");
  ammo--;
  for(i = 0; i < zombie_size; i++) {
    if(!strcmp(zombie[i], target)) {
      strcpy(zombie[i], "_CORPSE");
      printf("Zombie killed!\n\n");
      score++;
      return 0;
    }
  }
  printf("You are missed, zombie is still alive...\n");
  return 1;
}

canonical_original_code:
int shoot()
{
  char *target = malloc(255);
  int i = 0;
  static char ammo = 7;
  usleep((1)*1000);
  printf("Target: ");
 scanf("%s", target);
 if(!strcmp(target, "l")) {
   zombies_lookout();
   return 1;
  }
  else if(!strcmp(target, "a")) {
   printf("Ammo: %d/7\n", ammo);
   return 1;
  }
  else if(!strcmp(target, "r")) {
    ammo = zombies_reload_ammo(ammo);
    return 1;
  }
  if(ammo == 0) {
    printf("You have no ammo in the shotgun.\n");
    return 1;
  }
  else if(!strcmp(target, "_CORPSE")) {
    printf("You can't kill corpse, lol\n");
    ammo--;
    return 1;
  }
  printf("Player shoots with good shotgun...\n");
  ammo--;
  for(i = 0; i < zombie_size; i++) {
    if(!strcmp(zombie[i], target)) {
      strcpy(zombie[i], "_CORPSE");
      printf("Zombie killed!\n\n");
      score++;
      return 0;
    }
  }
  printf("You are missed, zombie is still alive...\n");
  return 1;
}

variable_types:
target
char *

variable_types: ammo char


main

canonical_name: main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
pthread_attr_init(&attr);
pthread_attr_setdetachstate(&attr, 1);
usleep(0x3E8u);
pthread_create(&pthread, &attr, (void *(*)(void *))threadfunc, 0LL);
while ( 1 )
shoot();
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
pthread_attr_init(&attr);
pthread_attr_setdetachstate(&attr, 1);
usleep(0x3E8u);
pthread_create(&pthread, &attr, (void *(*)(void *))threadfunc, 0LL);
while ( 1 )
func12();
}

original_code:
int main()
{
  pthread_attr_init(&attr);
  pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
  usleep((1)*1000);
  pthread_create(&pthread, &attr, threadfunc, ((void *)0));
  while(1) {
    shoot();
  }
  return 0;
}


seconds

repo: FEPC-Expert/FEPC

decompiled_code:
double seconds()
{
struct timeval v1; // [rsp+0h] [rbp-18h] BYREF

gettimeofday(&v1, 0LL);
return (double)SLODWORD(v1.tv_usec) * 0.000001 + (double)SLODWORD(v1.tv_sec);
}

canonical_decompiled_code:
double func0()
{
struct timeval v1; // [rsp+0h] [rbp-18h] BYREF

gettimeofday(&v1, 0LL);
return (double)SLODWORD(v1.tv_usec) * 0.000001 + (double)SLODWORD(v1.tv_sec);
}

original_code:
double
seconds ()
{
    double sec, usec;
    struct timeval tvd;
    gettimeofday( & tvd, ((void *)0) );
    sec = tvd.tv_sec;
    usec = tvd.tv_usec;
    return sec + (usec * 1e-6);
}

canonical_original_code:
double seconds()
{
    double sec; double usec;
    struct timeval tvd;
    gettimeofday( & tvd, ((void *)0) );
    sec = tvd.tv_sec;
    usec = tvd.tv_usec;
    return sec + (usec * 1e-6);
}

variable_types: sec double

variable_types: usec double

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

return_type: double


main

original_code:
int main(int argc, char* argv[]) {
 func_p f, g, w, fepc, ref;
 fepc_real_t norm;
 fepc_real_t a,b,c, mesh, temp1, temp2;
 int dim, i,j , l, pos;
 vec_p grad, start, lang, r, s;
 vec_real_p h;
 char dateiname1[20];
 dim = 2;
 a = 0.15;
 b = 4.;
 c = -3.5;
 mesh = 0.2;
 h = vec_real_new(5);
 for(l=0;l<5;l++) {
  h->array[l] = mesh*pow(2,-l);
 }
 f = func_new(2,dim);
 for(l=0;l<=f->maxlevel;l++) {
  grad = vec_new(dim);
  grad->array[0] = 0;
  grad->array[1] = 0;
  f->hierarchie[l] = folgen_vektor_new( grad );
 }
 start = vec_new(dim);
 lang = vec_new(dim);
 start->array[0] = 0;
 start->array[1] = 0;
 lang->array[0] = 5;
 lang->array[1] = 5;
 f->hierarchie[0]->vektor[0] = folge_new(start,lang);
 for(l=1;l<=f->maxlevel;l++) {
  start = vec_new(dim);
  lang = vec_new(dim);
  start->array[0] = 0;
  start->array[1] = 0;
  lang->array[0] = 4;
  lang->array[1] = pow(2,l)*5;
  f->hierarchie[l]->vektor[0] = folge_new(start,lang);
 }
 l=0;
 for(i=2;i<5;i++) {
  for(j=0;j<5;j++) {
   r = vec_new(dim);
   r->array[0] = i;
   r->array[1] = j;
   pos = entry_d2one(r,f->hierarchie[l]->vektor[0]->lang);
   vec_del(r);
   f->hierarchie[l]->vektor[0]->glied[pos] = log((i+1)*h->array[l]+a) - log(i*h->array[l]+a);
  }
 }
 for(l=1;l<f->maxlevel;l++) {
  for(i=2;i<4;i++) {
   for(j=0;j<(5*pow(2,l));j++) {
    r = vec_new(dim);
    r->array[0] = i;
    r->array[1] = j;
    pos = entry_d2one(r,f->hierarchie[l]->vektor[0]->lang);
    vec_del(r);
    f->hierarchie[l]->vektor[0]->glied[pos] = log((i+1)*h->array[l]+a) - log(i*h->array[l]+a);
   }
  }
 }
 l=f->maxlevel;
 for(i=0;i<4;i++) {
  for(j=0;j<(5*pow(2,l));j++) {
   r = vec_new(dim);
   r->array[0] = i;
   r->array[1] = j;
   pos = entry_d2one(r,f->hierarchie[l]->vektor[0]->lang);
   vec_del(r);
   f->hierarchie[l]->vektor[0]->glied[pos] = log((i+1)*h->array[l]+a) - log(i*h->array[l]+a);
  }
 }
 g = func_new(0,dim);
 for(l=0;l<=g->maxlevel;l++) {
  grad = vec_new(dim);
  grad->array[0] = 0;
  grad->array[1] = 0;
  g->hierarchie[l] = folgen_vektor_new( grad );
 }
 for(l=0;l<=g->maxlevel;l++) {
  start = vec_new(dim);
  lang = vec_new(dim);
  start->array[0] = 0;
  lang->array[0] = 5*pow(2,l);
  start->array[1] = 0;
  lang->array[1] = 5*pow(2,l);
  g->hierarchie[l]->vektor[0] = folge_new(start,lang);
 }
 l=g->maxlevel;
 for(i=0;i<(5*pow(2,l));i++) {
  for(j=0;j<(5*pow(2,l));j++) {
   r = vec_new(dim);
   r->array[0] = i;
   r->array[1] = j;
   pos = entry_d2one(r,g->hierarchie[l]->vektor[0]->lang);
   vec_del(r);
   temp1 = b/2.*pow(h->array[l],2);
   temp2 = 2*i + 1;
   g->hierarchie[l]->vektor[0]->glied[pos] = temp1*temp2 + c*h->array[l];
  }
 }
 w = func_new(2,dim);
 for(l=0;l<=w->maxlevel;l++) {
  grad = vec_new(dim);
  grad->array[0] = 0;
  grad->array[1] = 0;
  w->hierarchie[l] = folgen_vektor_new( grad );
 }
 start = vec_new(dim);
 lang = vec_new(dim);
 start->array[0] = 0;
 lang->array[0] = 5;
 start->array[1] = 0;
 lang->array[1] = 5;
 w->hierarchie[0]->vektor[0] = folge_new(start,lang);
 start = vec_new(dim);
 lang = vec_new(dim);
 start->array[0] = 2;
 lang->array[0] = 6;
 start->array[1] = 4;
 lang->array[1] = 6;
 w->hierarchie[1]->vektor[0] = folge_new(start,lang);
 start = vec_new(dim);
 lang = vec_new(dim);
 start->array[0] = 8;
 lang->array[0] = 4;
 start->array[1] = 16;
 lang->array[1] = 4;
 w->hierarchie[2]->vektor[0] = folge_new(start,lang);
 fepc = faltung_fepc(f,g,w,mesh);
 ref = faltung_ref(f,g,w,mesh);
 norm = faltung_hilfe_norm(fepc,ref);
 printf("\n Norm %lf \n",norm);
 sprintf(dateiname1,"Beispiel_2d/tab.xyz");
 func_plot_2d( fepc, dateiname1, mesh);
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[]) {
 struct func_t *f; struct func_t *g; struct func_t *w; struct func_t *fepc; struct func_t *ref;
 double norm;
 double a; double b; double c; double mesh; double temp1; double temp2;
 int dim; int i; int j; int l; int pos;
 struct vec_t *grad; struct vec_t *start; struct vec_t *lang; struct vec_t *r; struct vec_t *s;
 struct vec_real_t *h;
 char dateiname1[20];
 dim = 2;
 a = 0.15;
 b = 4.;
 c = -3.5;
 mesh = 0.2;
 h = vec_real_new(5);
 for(l=0;l<5;l++) {
  h->array[l] = mesh*pow(2,-l);
 }
 f = func_new(2,dim);
 for(l=0;l<=f->maxlevel;l++) {
  grad = vec_new(dim);
  grad->array[0] = 0;
  grad->array[1] = 0;
  f->hierarchie[l] = folgen_vektor_new( grad );
 }
 start = vec_new(dim);
 lang = vec_new(dim);
 start->array[0] = 0;
 start->array[1] = 0;
 lang->array[0] = 5;
 lang->array[1] = 5;
 f->hierarchie[0]->vektor[0] = folge_new(start,lang);
 for(l=1;l<=f->maxlevel;l++) {
  start = vec_new(dim);
  lang = vec_new(dim);
  start->array[0] = 0;
  start->array[1] = 0;
  lang->array[0] = 4;
  lang->array[1] = pow(2,l)*5;
  f->hierarchie[l]->vektor[0] = folge_new(start,lang);
 }
 l=0;
 for(i=2;i<5;i++) {
  for(j=0;j<5;j++) {
   r = vec_new(dim);
   r->array[0] = i;
   r->array[1] = j;
   pos = entry_d2one(r,f->hierarchie[l]->vektor[0]->lang);
   vec_del(r);
   f->hierarchie[l]->vektor[0]->glied[pos] = log((i+1)*h->array[l]+a) - log(i*h->array[l]+a);
  }
 }
 for(l=1;l<f->maxlevel;l++) {
  for(i=2;i<4;i++) {
   for(j=0;j<(5*pow(2,l));j++) {
    r = vec_new(dim);
    r->array[0] = i;
    r->array[1] = j;
    pos = entry_d2one(r,f->hierarchie[l]->vektor[0]->lang);
    vec_del(r);
    f->hierarchie[l]->vektor[0]->glied[pos] = log((i+1)*h->array[l]+a) - log(i*h->array[l]+a);
   }
  }
 }
 l=f->maxlevel;
 for(i=0;i<4;i++) {
  for(j=0;j<(5*pow(2,l));j++) {
   r = vec_new(dim);
   r->array[0] = i;
   r->array[1] = j;
   pos = entry_d2one(r,f->hierarchie[l]->vektor[0]->lang);
   vec_del(r);
   f->hierarchie[l]->vektor[0]->glied[pos] = log((i+1)*h->array[l]+a) - log(i*h->array[l]+a);
  }
 }
 g = func_new(0,dim);
 for(l=0;l<=g->maxlevel;l++) {
  grad = vec_new(dim);
  grad->array[0] = 0;
  grad->array[1] = 0;
  g->hierarchie[l] = folgen_vektor_new( grad );
 }
 for(l=0;l<=g->maxlevel;l++) {
  start = vec_new(dim);
  lang = vec_new(dim);
  start->array[0] = 0;
  lang->array[0] = 5*pow(2,l);
  start->array[1] = 0;
  lang->array[1] = 5*pow(2,l);
  g->hierarchie[l]->vektor[0] = folge_new(start,lang);
 }
 l=g->maxlevel;
 for(i=0;i<(5*pow(2,l));i++) {
  for(j=0;j<(5*pow(2,l));j++) {
   r = vec_new(dim);
   r->array[0] = i;
   r->array[1] = j;
   pos = entry_d2one(r,g->hierarchie[l]->vektor[0]->lang);
   vec_del(r);
   temp1 = b/2.*pow(h->array[l],2);
   temp2 = 2*i + 1;
   g->hierarchie[l]->vektor[0]->glied[pos] = temp1*temp2 + c*h->array[l];
  }
 }
 w = func_new(2,dim);
 for(l=0;l<=w->maxlevel;l++) {
  grad = vec_new(dim);
  grad->array[0] = 0;
  grad->array[1] = 0;
  w->hierarchie[l] = folgen_vektor_new( grad );
 }
 start = vec_new(dim);
 lang = vec_new(dim);
 start->array[0] = 0;
 lang->array[0] = 5;
 start->array[1] = 0;
 lang->array[1] = 5;
 w->hierarchie[0]->vektor[0] = folge_new(start,lang);
 start = vec_new(dim);
 lang = vec_new(dim);
 start->array[0] = 2;
 lang->array[0] = 6;
 start->array[1] = 4;
 lang->array[1] = 6;
 w->hierarchie[1]->vektor[0] = folge_new(start,lang);
 start = vec_new(dim);
 lang = vec_new(dim);
 start->array[0] = 8;
 lang->array[0] = 4;
 start->array[1] = 16;
 lang->array[1] = 4;
 w->hierarchie[2]->vektor[0] = folge_new(start,lang);
 fepc = faltung_fepc(f,g,w,mesh);
 ref = faltung_ref(f,g,w,mesh);
 norm = faltung_hilfe_norm(fepc,ref);
 printf("\n Norm %lf \n",norm);
 sprintf(dateiname1,"Beispiel_2d/tab.xyz");
 func_plot_2d( fepc, dateiname1, mesh);
 return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: struct func_t { int dim; int maxlevel; struct folgen_vektor_t { struct vec_t { int dim; int *array; } *grad; struct folge_t { struct vec_t *start; struct vec_t *lang; double *glied; } **vektor; } **hierarchie; } *

variable_types: norm double

variable_types: a double

variable_types: b double

variable_types: c double

variable_types: mesh double

variable_types: dim int

variable_types: j int

variable_types: l int

variable_types: pos int

variable_types:
grad
struct vec_t { int dim; int *array; } *

variable_types:
start
struct vec_t { int dim; int *array; } *

variable_types:
lang
struct vec_t { int dim; int *array; } *

variable_types:
r
struct vec_t { int dim; int *array; } *

variable_types:
s
struct vec_t { int dim; int *array; } *

variable_types: struct vec_real_t { int dim; double *array; } *

user_defined_types: struct func_t { int dim; int maxlevel; struct folgen_vektor_t **hierarchie; }

user_defined_types: struct folgen_vektor_t { struct vec_t *grad; struct folge_t **vektor; }


fliptable

repo: Faison/fliptable

decompiled_code:
int fliptable()
{
return puts(&s);
}

canonical_decompiled_code:
int func7()
{
return puts(&s);
}

original_code:
void fliptable()
{
 puts(FLIP_STRING);
}

canonical_original_code:
void fliptable()
{
 puts(FLIP_STRING);
}


decompiled_code:
int double_fliptable()
{
return puts(&byte_402028);
}

canonical_decompiled_code:
int func8()
{
return puts(&byte_402028);
}

original_code:
void double_fliptable()
{
 puts(DOUBLE_FLIP_STRING);
}


decompiled_code:
__int64 get_fliptable()
{
return (int)strdup(&s);
}

canonical_decompiled_code:
__int64 func9()
{
return (int)strdup(&s);
}

original_code:
char* get_fliptable()
{
 return strdup(FLIP_STRING);
}

canonical_original_code:
char *get_fliptable()
{
 return strdup(FLIP_STRING);
}

return_type: char *


decompiled_code:
__int64 get_double_fliptable()
{
return (int)strdup(&byte_402028);
}

canonical_decompiled_code:
__int64 func10()
{
return (int)strdup(&byte_402028);
}

original_code:
char* get_double_fliptable()
{
 return strdup(DOUBLE_FLIP_STRING);
}

canonical_original_code:
char *get_double_fliptable()
{
 return strdup(DOUBLE_FLIP_STRING);
}


main

decompiled_code:
// local variable allocation has failed, the output may be wrong!
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char **v3; // rbx
const char **v4; // rbp
char v6; // al
char *v7; // r12

if ( argc == 1 )
{
fliptable();
}
else if ( argc > 1 )
{
v3 = argv + 1;
v4 = &argv[(unsigned int)(argc - 2) + 2];
do
{
if ( **v3 == 45 )
{
v6 = (*v3)[1];
if ( v6 == 100 )
{
double_fliptable();
}
else if ( v6 == 118 )
{
v7 = (char *)get_fliptable(*(_QWORD *)&argc, argv, envp);
argv = (const char **)"1.0";
printf("fliptable %s, written by Faison for fun! %s\n", "1.0", v7);
*(_QWORD *)&argc = v7;
free(v7);
}
}
++v3;
}
while ( v3 != v4 );
}
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char **v3; // rbx
const char **v4; // rbp
char v6; // al
char *v7; // r12

if ( argc == 1 )
{
func7();
}
else if ( argc > 1 )
{
v3 = argv + 1;
v4 = &argv[(unsigned int)(argc - 2) + 2];
do
{
if ( **v3 == 45 )
{
v6 = (*v3)[1];
if ( v6 == 100 )
{
func8();
}
else if ( v6 == 118 )
{
v7 = (char *)func9(*(_QWORD *)&argc, argv, envp);
argv = (const char **)"1.0";
printf("fliptable %s, written by Faison for fun! %s\n", "1.0", v7);
*(_QWORD *)&argc = v7;
free(v7);
}
}
++v3;
}
while ( v3 != v4 );
}
return 0;
}

original_code:
int main(int argc, char *argv[])
{
 if(argc == 1) {
  fliptable();
 } else if(argc > 1) {
  for(int i = 1; i < argc; i++) {
   if(argv[i][0] == '-') {
    switch(argv[i][1]) {
     case 'v':
     {
      char *flip = get_fliptable();
      printf("fliptable %s, written by Faison for fun! %s\n", VERSION, flip);
      free(flip);
      break;
     }
     case 'd':
     {
      double_fliptable();
     }
    }
   }
  }
 }
 return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: i int

variable_types:
flip
char *


decompiled_code:
int __fastcall pro_document_manager(__int64 a1, char a2)
{
int result; // eax
char s[264]; // [rsp+0h] [rbp-108h] BYREF

memset(s, 0, 0x100uLL);
if ( a2 == 102 )
{
sprintf(s, format, a1, a1, a1, a1, a1, a1);
result = system(s);
}
else
{
result = 0;
if ( a2 == 117 )
{
sprintf(s, aRmS, a1, a1, a1, a1, a1, a1);
result = system(s);
}
}
return result;
}

canonical_decompiled_code:
int __fastcall func7(__int64 a1, char a2)
{
int result; // eax
char s[264]; // [rsp+0h] [rbp-108h] BYREF

memset(s, 0, 0x100uLL);
if ( a2 == 102 )
{
sprintf(s, format, a1, a1, a1, a1, a1, a1);
result = system(s);
}
else
{
result = 0;
if ( a2 == 117 )
{
sprintf(s, aRmS, a1, a1, a1, a1, a1, a1);
result = system(s);
}
}
return result;
}

original_code:
int pro_document_manager(const char *path, char ch)
{
    char buf[256];
    memset(buf, 0, 256);
    if(ch == 'f')
    {
        sprintf(buf, "touch %s可行性分析.odt %s需求分析.odt %s概要设计.odt %s详细设计.odt %s测试计划及结果.odt %s使用手册.odt", path, path, path, path, path, path);
        return system(buf);
    }
    else if(ch == 'u')
    {
        sprintf(buf, "rm %s可行性分析.odt %s需求分析.odt %s概要设计.odt %s详细设计.odt %s测试计划及结果.odt %s使用手册.odt", path, path, path, path, path, path);
        return system(buf);
    }
    return 0;
}

canonical_original_code:
int pro_document_manager(char *path, char ch)
{
    char buf[256];
    memset(buf, 0, 256);
    if(ch == 'f')
    {
        sprintf(buf, "touch %s可行性分析.odt %s需求分析.odt %s概要设计.odt %s详细设计.odt %s测试计划及结果.odt %s使用手册.odt", path, path, path, path, path, path);
        return system(buf);
    }
    else if(ch == 'u')
    {
        sprintf(buf, "rm %s可行性分析.odt %s需求分析.odt %s概要设计.odt %s详细设计.odt %s测试计划及结果.odt %s使用手册.odt", path, path, path, path, path, path);
        return system(buf);
    }
    return 0;
}

variable_types:
path
char *

variable_types: ch char

variable_types:
buf
char [256]


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

if ( (unsigned int)(argc - 2) > 1 )
{
puts("Using: ./app -c/-m/-d [path]");
result = 1;
}
else
{
if ( argc == 2 )
argv[2] = "./";
v3 = hens(argv[1], argv[2], envp);
result = 0;
if ( v3 == -1 )
{
puts("Invalid command -- you can use: doc -help");
result = 0;
}
}
return result;
}

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

if ( (unsigned int)(argc - 2) > 1 )
{
puts("Using: ./app -c/-m/-d [path]");
result = 1;
}
else
{
if ( argc == 2 )
argv[2] = "./";
v3 = func13(argv[1], argv[2], envp);
result = 0;
if ( v3 == -1 )
{
puts("Invalid command -- you can use: doc -help");
result = 0;
}
}
return result;
}

original_code:
int main(int argc, const char *argv[])
{
    if(argc < 2 || argc > 3)
    {
        printf("Using: ./app -c/-m/-d [path]\n");
        return 1;
    }
    if(2 == argc)
        argv[2] = "./";
    if((-1 == hens (argv[1], argv[2])))
    {
        printf("Invalid command -- you can use: doc -help\n");
    }
    return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
    if(argc < 2 || argc > 3)
    {
        printf("Using: ./app -c/-m/-d [path]\n");
        return 1;
    }
    if(2 == argc)
        argv[2] = "./";
    if((-1 == hens (argv[1], argv[2])))
    {
        printf("Invalid command -- you can use: doc -help\n");
    }
    return 0;
}


decompiled_code:
__int64 __fastcall make_dir(const char *a1)
{
char v2[264]; // [rsp+0h] [rbp-108h] BYREF

init(v2, 256);
sprintf(v2, "mkdir %s", a1);
return (unsigned int)-(system(v2) != 0);
}

canonical_decompiled_code:
__int64 __fastcall func9(const char *a1)
{
char v2[264]; // [rsp+0h] [rbp-108h] BYREF

func8(v2, 256);
sprintf(v2, "mkdir %s", a1);
return (unsigned int)-(system(v2) != 0);
}

original_code:
static int make_dir (char d_name[])
{
    char buf[256];
    init(buf, 256);
    sprintf(buf, "mkdir %s", d_name);
    if(system(buf))
    {
        return -1;
    }
    return 0;
}

canonical_original_code:
static int make_dir(char d_name[])
{
    char buf[256];
    init(buf, 256);
    sprintf(buf, "mkdir %s", d_name);
    if(system(buf))
    {
        return -1;
    }
    return 0;
}


decompiled_code:
__pid_t __fastcall mv_file(__int64 a1, __int64 a2)
{
__pid_t v2; // eax
__pid_t result; // eax

v2 = fork();
if ( v2 < 0 )
{
perror("fork");
exit(1);
}
if ( v2 <= 0 || (result = execlp("mv", "mv", a2, a1, 0LL)) != 0 )
result = wait(0LL);
return result;
}

canonical_decompiled_code:
__pid_t __fastcall func10(__int64 a1, __int64 a2)
{
__pid_t v2; // eax
__pid_t result; // eax

v2 = fork();
if ( v2 < 0 )
{
perror("fork");
exit(1);
}
if ( v2 <= 0 || (result = execlp("mv", "mv", a2, a1, 0LL)) != 0 )
result = wait(0LL);
return result;
}

original_code:
static void mv_file (char d_name[], char f_name[])
{
    pid_t pid = fork();
    if(pid < 0) {
        perror("fork");
        exit(1);
    }
    if(pid > 0){
        if(!(execlp("mv", "mv", f_name, d_name, ((void *)0))))
        {
            return;
        }
    }
    wait(((void *)0));
}

canonical_original_code:
static void mv_file(char d_name[], char f_name[])
{
    int pid = fork();
    if(pid < 0) {
        perror("fork");
        exit(1);
    }
    if(pid > 0){
        if(!(execlp("mv", "mv", f_name, d_name, ((void *)0))))
        {
            return;
        }
    }
    wait(((void *)0));
}

variable_types: pid int


hens

decompiled_code:
__int64 __fastcall hens(const char *a1, const char *a2)
{
unsigned int v2; // ebx
bool v4; // zf
int v5; // [rsp+Ch] [rbp-1Ch]

v5 = 0;
if ( !strcmp(a1, "-c") )
{
v5 = 22;
LABEL_3:
document_handle(a2, v5);
return 0;
}
if ( !strcmp(a1, "-m") )
{
document_handle(a2, 33);
return 0;
}
v4 = strcmp(a1, "-d") == 0;
v2 = !v4;
if ( v4 )
{
if ( pro_document_manager((__int64)a2, 102) == -1 )
{
fprintf(_bss_start, "%s\n", "failed to create project document");
v2 = 1;
}
}
else
{
v4 = strcmp(a1, "-ud") == 0;
v2 = !v4;
if ( !v4 )
{
v2 = -1;
if ( strcmp(a1, "-help") )
return v2;
help_tip();
goto LABEL_3;
}
if ( pro_document_manager((__int64)a2, 117) == -1 )
{
fprintf(_bss_start, "%s\n", "failed to clean project document");
v2 = 1;
}
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func13(const char *a1, const char *a2)
{
unsigned int v2; // ebx
bool v4; // zf
int v5; // [rsp+Ch] [rbp-1Ch]

v5 = 0;
if ( !strcmp(a1, "-c") )
{
v5 = 22;
LABEL_3:
func11(a2, v5);
return 0;
}
if ( !strcmp(a1, "-m") )
{
func11(a2, 33);
return 0;
}
v4 = strcmp(a1, "-d") == 0;
v2 = !v4;
if ( v4 )
{
if ( func7((__int64)a2, 102) == -1 )
{
fprintf(_bss_start, "%s\n", "failed to create project document");
v2 = 1;
}
}
else
{
v4 = strcmp(a1, "-ud") == 0;
v2 = !v4;
if ( !v4 )
{
v2 = -1;
if ( strcmp(a1, "-help") )
return v2;
func12();
goto LABEL_3;
}
if ( func7((__int64)a2, 117) == -1 )
{
fprintf(_bss_start, "%s\n", "failed to clean project document");
v2 = 1;
}
}
return v2;
}

original_code:
int hens (const char *arg, const char *path)
{
    volatile int mode = 0;
    if(0 == strcmp(arg, "-c"))
    {
        mode = 22;
    }
    else if(0 == strcmp(arg, "-m"))
    {
        mode = 33;
    }
    else if(0 == strcmp(arg, "-d"))
    {
        if(-1 == pro_document_manager(path, 'f'))
        {
            fprintf(stdout, "%s\n", "failed to create project document");
            return 1;
        }
        return 0;
    }
    else if(0 == strcmp(arg, "-ud"))
    {
        if(-1 == pro_document_manager(path, 'u'))
        {
            fprintf(stdout, "%s\n", "failed to clean project document");
            return 1;
        }
        return 0;
    }
    else if(0 == strcmp(arg, "-help"))
    {
        help_tip();
    }
    else{
        return -1;
    }
    document_handle (path, mode);
    return 0;
}

canonical_original_code:
int hens(char *arg, char *path)
{
    int mode = 0;
    if(0 == strcmp(arg, "-c"))
    {
        mode = 22;
    }
    else if(0 == strcmp(arg, "-m"))
    {
        mode = 33;
    }
    else if(0 == strcmp(arg, "-d"))
    {
        if(-1 == pro_document_manager(path, 'f'))
        {
            fprintf(stdout, "%s\n", "failed to create project document");
            return 1;
        }
        return 0;
    }
    else if(0 == strcmp(arg, "-ud"))
    {
        if(-1 == pro_document_manager(path, 'u'))
        {
            fprintf(stdout, "%s\n", "failed to clean project document");
            return 1;
        }
        return 0;
    }
    else if(0 == strcmp(arg, "-help"))
    {
        help_tip();
    }
    else{
        return -1;
    }
    document_handle (path, mode);
    return 0;
}

variable_types:
arg
char *

variable_types: mode int


decompiled_code:
time_t get_elapsed()
{
time_t v0; // rax
unsigned __int16 v1; // dx
struct timeb v3; // [rsp+0h] [rbp-18h] BYREF

ftime(&v3);
v0 = v3.time - start.time;
v3.time -= start.time;
v1 = start.millitm;
if ( v3.millitm < v1 )
{
v3.time = v0 - 1;
v3.millitm = v1 - v3.millitm;
}
else
{
v3.millitm -= v1;
}
return v3.time;
}

canonical_decompiled_code:
time_t func1()
{
time_t v0; // rax
unsigned __int16 v1; // dx
struct timeb v3; // [rsp+0h] [rbp-18h] BYREF

ftime(&v3);
v0 = v3.time - start.time;
v3.time -= start.time;
v1 = start.millitm;
if ( v3.millitm < v1 )
{
v3.time = v0 - 1;
v3.millitm = v1 - v3.millitm;
}
else
{
v3.millitm -= v1;
}
return v3.time;
}

original_code:
struct timeb get_elapsed() {
 struct timeb now;
 ftime(&now);
 now.time -= start.time;
 if ( now.millitm >= start.millitm ) {
  now.millitm -= start.millitm;
 } else {
  now.time--;
  now.millitm = start.millitm - now.millitm;
 }
 return now;
}

variable_types: struct timeb { long time; unsigned short millitm; short timezone; short dstflag; }


decompiled_code:
__int64 __fastcall priority_encoder(unsigned int a1)
{
unsigned int v1; // esi
int v2; // ecx

v1 = a1;
if ( (_BYTE)a1 && (a1 & 0x7F) > 1 )
{
v2 = -128;
do
{
v1 &= ~v2;
LOBYTE(v2) = (unsigned __int8)v2 >> 1;
}
while ( (~(unsigned __int8)v2 & (unsigned __int8)v1) > 1 );
}
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func4(unsigned int a1)
{
unsigned int v1; // esi
int v2; // ecx

v1 = a1;
if ( (_BYTE)a1 && (a1 & 0x7F) > 1 )
{
v2 = -128;
do
{
v1 &= ~v2;
LOBYTE(v2) = (unsigned __int8)v2 >> 1;
}
while ( (~(unsigned __int8)v2 & (unsigned __int8)v1) > 1 );
}
return v1;
}

original_code:
loglevel_t priority_encoder(loglevel_t level) {
 loglevel_t mask = 1 << (8 * sizeof(loglevel_t) - 1);
 if ( level == 0 ) return level;
 while ( (level & (~mask)) > 1 ) {
  level &= ~mask;
  mask >>= 1;
 }
 return level;
}

canonical_original_code:
unsigned char priority_encoder(unsigned char level) {
 unsigned char mask = 1 << (8 * sizeof(loglevel_t) - 1);
 if ( level == 0 ) return level;
 while ( (level & (~mask)) > 1 ) {
  level &= ~mask;
  mask >>= 1;
 }
 return level;
}

variable_types:
level
unsigned char

variable_types:
mask
unsigned char

return_type: unsigned char


decompiled_code:
__int64 flog_message(unsigned __int8 a1, const char *a2, ...)
{
char *v2; // rbx
unsigned int v3; // ebp
gcc_va_list arg; // [rsp+8h] [rbp-E0h] BYREF

v2 = (char *)malloc(0x400uLL);
if ( !v2 )
{
log_error("Errore su malloc()");
exit(1);
}
va_start(arg, a2);
vsprintf(v2, a2, arg);
v3 = log_message(a1, v2);
free(v2);
return v3;
}

canonical_decompiled_code:
__int64 func6(unsigned __int8 a1, const char *a2, ...)
{
char *v2; // rbx
unsigned int v3; // ebp
gcc_va_list arg; // [rsp+8h] [rbp-E0h] BYREF

v2 = (char *)malloc(0x400uLL);
if ( !v2 )
{
func7("Errore su malloc()");
exit(1);
}
va_start(arg, a2);
vsprintf(v2, a2, arg);
v3 = func5(a1, v2);
free(v2);
return v3;
}

original_code:
int flog_message(loglevel_t level, const char *format, ...) {
 va_list args;
 int count;
 char *message = malloc(1024);
 ((void) (0));
 if ( message == ((void *)0) ) { log_error("Errore su malloc()"); exit(1); };
 __builtin_va_start(args,format);
 vsprintf(message, format, args);
 count = log_message(level, message);
 free(message);
 __builtin_va_end(args);
 return count;
}

canonical_original_code:
int flog_message(unsigned char level, char *format, ...) {
 __builtin_va_list args;
 int count;
 char *message = malloc(1024);
 ((void) (0));
 if ( message == ((void *)0) ) { log_error("Errore su malloc()"); exit(1); };
 __builtin_va_start(args,format);
 vsprintf(message, format, args);
 count = log_message(level, message);
 free(message);
 __builtin_va_end(args);
 return count;
}

variable_types:
format
char *

variable_types: count int

variable_types:
message
char *


decompiled_code:
__int64 __fastcall log_error(const char *a1)
{
int *v1; // rax
char *v2; // rax

v1 = _errno_location();
v2 = strerror(*v1);
return flog_message(4u, "%s: %s", a1, v2);
}

canonical_decompiled_code:
__int64 __fastcall func7(const char *a1)
{
int *v1; // rax
char *v2; // rax

v1 = _errno_location();
v2 = strerror(*v1);
return func6(4u, "%s: %s", a1, v2);
}

original_code:
int log_error(const char *message) {
 return flog_message(4, "%s: %s", message, strerror((*__errno_location ())));
}

canonical_original_code:
int log_error(char *message) {
 return flog_message(4, "%s: %s", message, strerror((*__errno_location ())));
}


decompiled_code:
__int64 __fastcall log_multiline(unsigned __int8 a1, const char *a2)
{
size_t v2; // rax
char *v3; // rax
char *v4; // r13
const char *i; // rbp
char *v6; // rax
char *v7; // rbx
unsigned int v8; // ebx

v2 = strlen(a2);
v3 = (char *)malloc(v2);
if ( !v3 )
{
log_error("Errore su malloc()");
exit(1);
}
v4 = v3;
strcpy(v3, a2);
for ( i = v4; ; i = v7 + 1 )
{
v6 = strchr(i, 10);
v7 = v6;
if ( !v6 )
break;
*v6 = 0;
log_message(a1, i);
}
v8 = log_message(a1, i);
free(v4);
return v8;
}

canonical_decompiled_code:
__int64 __fastcall func10(unsigned __int8 a1, const char *a2)
{
size_t v2; // rax
char *v3; // rax
char *v4; // r13
const char *i; // rbp
char *v6; // rax
char *v7; // rbx
unsigned int v8; // ebx

v2 = strlen(a2);
v3 = (char *)malloc(v2);
if ( !v3 )
{
func7("Errore su malloc()");
exit(1);
}
v4 = v3;
strcpy(v3, a2);
for ( i = v4; ; i = v7 + 1 )
{
v6 = strchr(i, 10);
v7 = v6;
if ( !v6 )
break;
*v6 = 0;
func5(a1, i);
}
v8 = func5(a1, i);
free(v4);
return v8;
}

original_code:
int log_multiline(loglevel_t level, const char *message) {
 char *split, *start, *end;
 int count;
 ((void) (0));
 ((void) (0));
 split = malloc(strlen(message));
 if ( split == ((void *)0) ) { log_error("Errore su malloc()"); exit(1); };
 strcpy(split, message);
 start = end = split;
 while ( (end = strchr(start, '\n')) != ((void *)0) ) {
  *end = '\0';
  log_message(level, start);
  start = end + 1;
 }
 count = log_message(level, start);
 free(split);
 return count;
}

canonical_original_code:
int log_multiline(unsigned char level, char *message) {
 char *split; char *start; char *end;
 int count;
 ((void) (0));
 ((void) (0));
 split = malloc(strlen(message));
 if ( split == ((void *)0) ) { log_error("Errore su malloc()"); exit(1); };
 strcpy(split, message);
 start = end = split;
 while ( (end = strchr(start, '\n')) != ((void *)0) ) {
  *end = '\0';
  log_message(level, start);
  start = end + 1;
 }
 count = log_message(level, start);
 free(split);
 return count;
}

variable_types:
split
char *

variable_types:
start
char *

variable_types:
end
char *


decompiled_code:
void __fastcall __noreturn sig_handler(unsigned int a1)
{
switch ( a1 )
{
case 6u:
log_message(0x40u, "Received SIGABRT");
break;
case 0xFu:
log_message(0x40u, "Received SIGTERM");
break;
case 2u:
log_message(0x40u, "Received SIGINT");
break;
default:
flog_message(0x40u, "Received signal %d", a1);
break;
}
exit(1);
}

canonical_decompiled_code:
void __fastcall __noreturn func11(unsigned int a1)
{
switch ( a1 )
{
case 6u:
func5(0x40u, "Received SIGABRT");
break;
case 0xFu:
func5(0x40u, "Received SIGTERM");
break;
case 2u:
func5(0x40u, "Received SIGINT");
break;
default:
func6(0x40u, "Received signal %d", a1);
break;
}
exit(1);
}

original_code:
void sig_handler(int signal) {
 switch ( signal ) {
  case 6: log_message(64, "Received SIGABRT"); break;
  case 2: log_message(64, "Received SIGINT"); break;
  case 15: log_message(64, "Received SIGTERM"); break;
  default: flog_message(64, "Received signal %d", signal);
 }
 exit(1);
}

variable_types: signal int


decompiled_code:
_DWORD *create_client_node()
{
_DWORD *result; // rax

result = malloc(0x88uLL);
if ( !result )
{
log_error("Errore su malloc()");
exit(1);
}
result[9] = 0;
*((_QWORD *)result + 8) = 0LL;
*((_QWORD *)result + 9) = 0LL;
*((_QWORD *)result + 10) = 0LL;
*((_QWORD *)result + 11) = 0LL;
*((_QWORD *)result + 12) = 0LL;
result[26] = 0;
result[27] = 0;
*((_QWORD *)result + 14) = 0LL;
*((_QWORD *)result + 15) = 0LL;
*((_BYTE *)result + 128) = 0;
return result;
}

canonical_decompiled_code:
_DWORD *func1()
{
_DWORD *result; // rax

result = malloc(0x88uLL);
if ( !result )
{
log_error("Errore su malloc()");
exit(1);
}
result[9] = 0;
*((_QWORD *)result + 8) = 0LL;
*((_QWORD *)result + 9) = 0LL;
*((_QWORD *)result + 10) = 0LL;
*((_QWORD *)result + 11) = 0LL;
*((_QWORD *)result + 12) = 0LL;
result[26] = 0;
result[27] = 0;
*((_QWORD *)result + 14) = 0LL;
*((_QWORD *)result + 15) = 0LL;
*((_BYTE *)result + 128) = 0;
return result;
}

original_code:
struct client_node *create_client_node() {
 struct client_node *cn = malloc(sizeof(struct client_node));
 if ( cn == ((void *)0) ) { log_error("Errore su malloc()"); exit(1); };
 cn->state = NONE;
 cn->next = ((void *)0);
 cn->req_to = ((void *)0);
 cn->req_from = ((void *)0);
 cn->play_with = ((void *)0);
 cn->data = ((void *)0);
 cn->data_count = 0;
 cn->data_cursor = 0;
 cn->read_dispatch = ((void *)0);
 cn->write_dispatch = ((void *)0);
 cn->muted = 0;
 return cn;
}

variable_types: struct client_node { unsigned char username_len; char username[-1]; int socket; enum client_state { NONE=0, CONNECTED=1, FREE=2, BUSY=3, PLAY=4 } state; 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]; } addr; unsigned short udp_port; unsigned char byte_resp; struct client_node *next; char *data; int data_count; void (*read_dispatch)(struct client_node *); void (*write_dispatch)(struct client_node *); unsigned char muted; } *

user_defined_types: struct client_node { unsigned char username_len; char username[-1]; int socket; enum client_state state; struct sockaddr_in addr; unsigned short udp_port; unsigned char byte_resp; struct client_node *next; char *data; int data_count; void (*read_dispatch)(struct client_node *); void (*write_dispatch)(struct client_node *); unsigned char muted; }

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


decompiled_code:
__int64 __fastcall destroy_client_node(void *ptr)
{
__int64 v2; // rbp
void *v3; // rdi

v2 = *((_QWORD *)ptr + 8);
v3 = (void *)*((_QWORD *)ptr + 12);
if ( v3 )
free(v3);
free(ptr);
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func2(void *ptr)
{
__int64 v2; // rbp
void *v3; // rdi

v2 = *((_QWORD *)ptr + 8);
v3 = (void *)*((_QWORD *)ptr + 12);
if ( v3 )
free(v3);
free(ptr);
return v2;
}

original_code:
struct client_node *destroy_client_node(struct client_node *cn) {
 struct client_node *ret;
 ((void) (0));
 ret = cn->next;
 if ( cn->data != ((void *)0) ) free(cn->data);
 free(cn);
 return ret;
}

variable_types:
cn
struct client_node *

return_type: struct client_node { unsigned char username_len; char username[-1]; int socket; enum client_state { NONE=0, CONNECTED=1, FREE=2, BUSY=3, PLAY=4 } state; 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]; } addr; unsigned short udp_port; unsigned char byte_resp; struct client_node *next; char *data; int data_count; void (*read_dispatch)(struct client_node *); void (*write_dispatch)(struct client_node *); unsigned char muted; } *


decompiled_code:
void __fastcall destroy_client_list(void *a1)
{
for ( ; a1; a1 = (void *)destroy_client_node(a1) )
;
}

canonical_decompiled_code:
void __fastcall func3(void *a1)
{
for ( ; a1; a1 = (void *)func2(a1) )
;
}

original_code:
void destroy_client_list(struct client_node *cn) {
 while ( cn != ((void *)0) )
  cn = destroy_client_node(cn);
}

user_defined_types: enum client_state { NONE=0, CONNECTED=1, FREE=2, BUSY=3, PLAY=4 }


decompiled_code:
__int64 __fastcall add_client_node(__int64 a1)
{
__int64 result; // rax

result = *(&client_list + 1);
if ( result )
{
*(_QWORD *)(result + 64) = a1;
*(&client_list + 1) = a1;
}
else
{
*(&client_list + 1) = a1;
client_list = a1;
}
*(_QWORD *)(a1 + 64) = 0LL;
++*((_DWORD *)&client_list + 4);
return result;
}

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

result = *(&client_list + 1);
if ( result )
{
*(_QWORD *)(result + 64) = a1;
*(&client_list + 1) = a1;
}
else
{
*(&client_list + 1) = a1;
client_list = a1;
}
*(_QWORD *)(a1 + 64) = 0LL;
++*((_DWORD *)&client_list + 4);
return result;
}

original_code:
void add_client_node(struct client_node *cn) {
 ((void) (0));
 if ( client_list.tail == ((void *)0) ) {
  client_list.head = client_list.tail = cn;
 } else {
  client_list.tail->next = cn;
  client_list.tail = cn;
 }
 cn->next = ((void *)0);
 client_list.count++;
}


decompiled_code:
__int64 __fastcall remove_client_node(__int64 a1)
{
__int64 result; // rax

if ( client_list == a1 )
client_list = *(_QWORD *)(a1 + 64);
for ( result = client_list; result; result = *(_QWORD *)(result + 64) )
{
if ( *(_QWORD *)(result + 64) == a1 )
{
*(_QWORD *)(result + 64) = *(_QWORD *)(a1 + 64);
break;
}
}
if ( *(&client_list + 1) == a1 )
*(&client_list + 1) = result;
--*((_DWORD *)&client_list + 4);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1)
{
__int64 result; // rax

if ( client_list == a1 )
client_list = *(_QWORD *)(a1 + 64);
for ( result = client_list; result; result = *(_QWORD *)(result + 64) )
{
if ( *(_QWORD *)(result + 64) == a1 )
{
*(_QWORD *)(result + 64) = *(_QWORD *)(a1 + 64);
break;
}
}
if ( *(&client_list + 1) == a1 )
*(&client_list + 1) = result;
--*((_DWORD *)&client_list + 4);
return result;
}

original_code:
struct client_node *remove_client_node(struct client_node *cn) {
 struct client_node *ptr;
 ((void) (0));
 if ( client_list.head == cn ) client_list.head = cn->next;
 ptr = client_list.head;
 while ( ptr != ((void *)0) && ptr->next != cn ) ptr = ptr->next;
 if ( ptr != ((void *)0) && ptr->next == cn ) ptr->next = cn->next;
 if ( client_list.tail == cn ) client_list.tail = ptr;
 client_list.count--;
 return ptr;
}


decompiled_code:
__int64 __fastcall get_client_by_socket(int a1)
{
__int64 result; // rax

for ( result = client_list; result; result = *(_QWORD *)(result + 64) )
{
if ( *(_DWORD *)(result + 32) == a1 )
break;
}
return result;
}

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

for ( result = client_list; result; result = *(_QWORD *)(result + 64) )
{
if ( *(_DWORD *)(result + 32) == a1 )
break;
}
return result;
}

original_code:
struct client_node *get_client_by_socket(int socket) {
 struct client_node *nc = client_list.head;
 while ( nc != ((void *)0) && nc->socket != socket ) nc = nc->next;
 return nc;
}

variable_types: socket int


decompiled_code:
__int64 __fastcall get_client_by_username(char *s2)
{
__int64 i; // rbx

for ( i = client_list; i; i = *(_QWORD *)(i + 64) )
{
if ( *(_DWORD *)(i + 36) != 1 && !strcmp((const char *)(i + 1), s2) )
break;
}
return i;
}

canonical_decompiled_code:
__int64 __fastcall func7(char *s2)
{
__int64 i; // rbx

for ( i = client_list; i; i = *(_QWORD *)(i + 64) )
{
if ( *(_DWORD *)(i + 36) != 1 && !strcmp((const char *)(i + 1), s2) )
break;
}
return i;
}

original_code:
struct client_node *get_client_by_username(const char *username) {
 struct client_node *nc = client_list.head;
 while ( nc &&
               (nc->state == CONNECTED || strcmp(nc->username, username) != 0) )
  nc = nc->next;
 return nc;
}

canonical_original_code:
struct client_node *get_client_by_username(char *username) {
 struct client_node *nc = client_list.head;
 while ( nc &&
               (nc->state == CONNECTED || strcmp(nc->username, username) != 0) )
  nc = nc->next;
 return nc;
}

variable_types:
username
char *


decompiled_code:
char *__fastcall client_sockaddr_p(__int64 a1)
{
unsigned __int16 v1; // bx
size_t v2; // rax

if ( !inet_ntop(2, (const void *)(a1 + 44), client_repr_buffer, 0x10u) )
log_message(1LL, "Client has invalid address");
v1 = _bswap_16(*(_WORD *)(a1 + 42));
v2 = strlen(client_repr_buffer);
sprintf(&client_repr_buffer[v2], ":%hu", v1);
return client_repr_buffer;
}

canonical_decompiled_code:
char *__fastcall func8(__int64 a1)
{
unsigned __int16 v1; // bx
size_t v2; // rax

if ( !inet_ntop(2, (const void *)(a1 + 44), client_repr_buffer, 0x10u) )
log_message(1LL, "Client has invalid address");
v1 = func0(*(_WORD *)(a1 + 42));
v2 = strlen(client_repr_buffer);
sprintf(&client_repr_buffer[v2], ":%hu", v1);
return client_repr_buffer;
}

original_code:
const char *client_sockaddr_p(struct client_node *client) {
 const char *s;
 ((void) (0));
 s = inet_ntop(2, &(client->addr.sin_addr), client_repr_buffer,
                                                               16);
 if ( s == ((void *)0) ) log_message(1, "Client has invalid address");
 sprintf(client_repr_buffer + strlen(client_repr_buffer), ":%hu",
                                                  ntohs(client->addr.sin_port));
 return client_repr_buffer;
}

canonical_original_code:
char *client_sockaddr_p(struct client_node *client) {
 char *s;
 ((void) (0));
 s = inet_ntop(2, &(client->addr.sin_addr), client_repr_buffer,
                                                               16);
 if ( s == ((void *)0) ) log_message(1, "Client has invalid address");
 sprintf(client_repr_buffer + strlen(client_repr_buffer), ":%hu",
                                                  ntohs(client->addr.sin_port));
 return client_repr_buffer;
}

variable_types:
s
char *


decompiled_code:
char *__fastcall client_canon_p(__int64 a1)
{
unsigned int v1; // eax
char *v2; // rdx

v1 = *(_DWORD *)(a1 + 36);
if ( v1 <= 1 )
return client_sockaddr_p(a1);
v2 = client_repr_buffer;
if ( v1 - 2 <= 2 )
{
sprintf(client_repr_buffer, "[%s]", (const char *)(a1 + 1));
v2 = client_repr_buffer;
}
return v2;
}

canonical_decompiled_code:
char *__fastcall func9(__int64 a1)
{
unsigned int v1; // eax
char *v2; // rdx

v1 = *(_DWORD *)(a1 + 36);
if ( v1 <= 1 )
return func8(a1);
v2 = client_repr_buffer;
if ( v1 - 2 <= 2 )
{
sprintf(client_repr_buffer, "[%s]", (const char *)(a1 + 1));
v2 = client_repr_buffer;
}
return v2;
}

original_code:
const char *client_canon_p(struct client_node *client) {
 ((void) (0));
 switch ( client->state ) {
  case NONE:
  case CONNECTED:
   return client_sockaddr_p(client);
  case FREE:
  case BUSY:
  case PLAY:
   sprintf(client_repr_buffer, "[%s]", client->username);
 }
 return client_repr_buffer;
}


decompiled_code:
__int64 __fastcall log_statechange(__int64 a1)
{
const char *v1; // rbp
char *v2; // rax

v1 = (const char *)state_name(*(unsigned int *)(a1 + 36));
v2 = client_canon_p(a1);
return flog_message(1LL, "%s is now %s", v2, v1);
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1)
{
const char *v1; // rbp
char *v2; // rax

v1 = (const char *)state_name(*(unsigned int *)(a1 + 36));
v2 = func9(a1);
return flog_message(1LL, "%s is now %s", v2, v1);
}

original_code:
int log_statechange(struct client_node *client) {
 ((void) (0));
 return flog_message(1, "%s is now %s", client_canon_p(client),
                                                     state_name(client->state));
}


original_code:
void init_grid(struct tris_grid *grid) {
 struct tris_grid copy = {{'\0', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '}, 0, 0x92fd0413};
 memcpy(grid, &copy, sizeof(struct tris_grid));
}

variable_types: struct tris_grid { char cells[10]; unsigned int seed; } *


original_code:
char get_winner(const struct tris_grid *grid) {
 int i, c = 0;
 for ( i = 1; i <= 9; i++ ) {
  if ( grid->cells[i] == 'X' || grid->cells[i] == 'O') c++;
  else ((void) (0));
 }
 for ( i = 0; i < 8; i++ ) {
  if ( grid->cells[ win[i][0] ] == 'X' &&
       grid->cells[ win[i][1] ] == 'X' &&
       grid->cells[ win[i][2] ] == 'X' ) return 'X';
  if ( grid->cells[ win[i][0] ] == 'O' &&
       grid->cells[ win[i][1] ] == 'O' &&
       grid->cells[ win[i][2] ] == 'O' ) return 'O';
 }
 if ( c < 9 ) return ' ';
 else return 'D';
}

canonical_original_code:
char get_winner(struct tris_grid *grid) {
 int i; int c = 0;
 for ( i = 1; i <= 9; i++ ) {
  if ( grid->cells[i] == 'X' || grid->cells[i] == 'O') c++;
  else ((void) (0));
 }
 for ( i = 0; i < 8; i++ ) {
  if ( grid->cells[ win[i][0] ] == 'X' &&
       grid->cells[ win[i][1] ] == 'X' &&
       grid->cells[ win[i][2] ] == 'X' ) return 'X';
  if ( grid->cells[ win[i][0] ] == 'O' &&
       grid->cells[ win[i][1] ] == 'O' &&
       grid->cells[ win[i][2] ] == 'O' ) return 'O';
 }
 if ( c < 9 ) return ' ';
 else return 'D';
}

variable_types: i int

variable_types: c int

return_type: char

user_defined_types: struct tris_grid { char cells[10]; unsigned int seed; }


decompiled_code:
__int64 __fastcall better_for(char a1, char a2, int a3)
{
unsigned int v3; // eax

if ( a1 == a2 || a2 == (_BYTE)a3 )
return 0LL;
LOBYTE(v3) = a1 == 68;
LOBYTE(a3) = a1 == (char)a3;
return a3 | v3;
}

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

if ( a1 == a2 || a2 == (_BYTE)a3 )
return 0LL;
LOBYTE(v3) = a1 == 68;
LOBYTE(a3) = a1 == (char)a3;
return a3 | v3;
}

original_code:
bool better_for(char a, char b, char player) {
 ((void) (0));
 ((void) (0));
 ((void) (0));
 if ( a == b || b == player ) return 0;
 if ( a == player ) return 1;
 ((void) (0));
 if ( a == 'D' ) return 1;
 ((void) (0));
 return 0;
}

canonical_original_code:
unsigned char better_for(char a, char b, char player) {
 ((void) (0));
 ((void) (0));
 ((void) (0));
 if ( a == b || b == player ) return 0;
 if ( a == player ) return 1;
 ((void) (0));
 if ( a == 'D' ) return 1;
 ((void) (0));
 return 0;
}

variable_types: a char

variable_types: b char

variable_types: player char


inverse

decompiled_code:
__int64 __fastcall inverse(unsigned int a1)
{
__int64 result; // rax

result = a1;
if ( (_BYTE)a1 == 79 )
return 88LL;
if ( (_BYTE)a1 == 88 )
result = 79LL;
return result;
}

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

result = a1;
if ( (_BYTE)a1 == 79 )
return 88LL;
if ( (_BYTE)a1 == 88 )
result = 79LL;
return result;
}

original_code:
char inverse(char player) {
 switch ( player ) {
  case 'X': return 'O';
  case 'O': return 'X';
  default: return player;
 }
}


sprintgrid

decompiled_code:
char *__fastcall sprintgrid(char *dest, __int64 a2, const char *a3, size_t a4)
{
const char *v4; // r13
__int64 i; // r12
__int64 j; // rbx
char s[61]; // [rsp+Bh] [rbp-3Dh] BYREF

v4 = a3;
if ( !a3 )
v4 = &src;
if ( 7 * strlen(v4) + 98 > a4 )
return 0LL;
*dest = 0;
for ( i = 0LL; i != 9; i += 3LL )
{
strcat(dest, v4);
strcat(dest, "+---+---+---+\n");
strcat(dest, v4);
for ( j = 0LL; j != 3; ++j )
{
sprintf(s, "| %c ", (unsigned int)*(char *)(a2 + print[j + i]));
strcat(dest, s);
}
strcat(dest, "|\n");
}
strcat(dest, v4);
strcat(dest, "+---+---+---+");
return dest;
}

canonical_decompiled_code:
char *__fastcall func4(char *dest, __int64 a2, const char *a3, size_t a4)
{
const char *v4; // r13
__int64 i; // r12
__int64 j; // rbx
char s[61]; // [rsp+Bh] [rbp-3Dh] BYREF

v4 = a3;
if ( !a3 )
v4 = &src;
if ( 7 * strlen(v4) + 98 > a4 )
return 0LL;
*dest = 0;
for ( i = 0LL; i != 9; i += 3LL )
{
strcat(dest, v4);
strcat(dest, "+---+---+---+\n");
strcat(dest, v4);
for ( j = 0LL; j != 3; ++j )
{
sprintf(s, "| %c ", (unsigned int)*(char *)(a2 + print[j + i]));
strcat(dest, s);
}
strcat(dest, "|\n");
}
strcat(dest, v4);
strcat(dest, "+---+---+---+");
return dest;
}

original_code:
char *sprintgrid(char *buffer, const struct tris_grid *grid, const char *pre,
                                                                     size_t n) {
 int i, j;
 char temp[5];
 ((void) (0));
 ((void) (0));
 if ( pre == ((void *)0) ) pre = "";
 if ( 7*(strlen(pre) + 13) + 6 + 1 > n ) return ((void *)0);
 buffer[0] = '\0';
 for ( i = 0; i < 3; i++ ) {
  strcat(buffer, pre);
  strcat(buffer, "+---+---+---+\n");
  strcat(buffer, pre);
  for ( j = 0; j < 3; j++ ) {
   sprintf(temp, "| %c ", grid->cells[ print[i][j] ]);
   strcat(buffer, temp);
  }
  strcat(buffer, "|\n");
 }
 strcat(buffer, pre);
 strcat(buffer, "+---+---+---+");
 return buffer;
}

canonical_original_code:
char *sprintgrid(char *buffer, struct tris_grid *grid, char *pre, unsigned long n) {
 int i; int j;
 char temp[5];
 ((void) (0));
 ((void) (0));
 if ( pre == ((void *)0) ) pre = "";
 if ( 7*(strlen(pre) + 13) + 6 + 1 > n ) return ((void *)0);
 buffer[0] = '\0';
 for ( i = 0; i < 3; i++ ) {
  strcat(buffer, pre);
  strcat(buffer, "+---+---+---+\n");
  strcat(buffer, pre);
  for ( j = 0; j < 3; j++ ) {
   sprintf(temp, "| %c ", grid->cells[ print[i][j] ]);
   strcat(buffer, temp);
  }
  strcat(buffer, "|\n");
 }
 strcat(buffer, pre);
 strcat(buffer, "+---+---+---+");
 return buffer;
}

variable_types:
buffer
char *

variable_types:
pre
char *

variable_types:
n
unsigned long

variable_types: j int

variable_types:
temp
char [5]


original_code:
uint32_t jenkins1(const char *data, size_t length, uint32_t h) {
 uint32_t i;
 for ( i = 0; i < length; i++ ) {
  h += data[i];
  h += (h << 10);
  h ^= (h >> 6);
 }
 h += (h << 3);
 h ^= (h >> 11);
 h += (h << 15);
 return h;
}

canonical_original_code:
unsigned int jenkins1(char *data, unsigned long length, unsigned int h) {
 unsigned int i;
 for ( i = 0; i < length; i++ ) {
  h += data[i];
  h += (h << 10);
  h ^= (h >> 6);
 }
 h += (h << 3);
 h ^= (h >> 11);
 h += (h << 15);
 return h;
}

variable_types:
data
char *

variable_types:
length
unsigned long

variable_types:
h
unsigned int

variable_types:
i
unsigned int

return_type: unsigned int


decompiled_code:
__int64 __fastcall update_hash(__int64 a1)
{
unsigned int v1; // ebp
__int64 result; // rax

v1 = *(_DWORD *)(a1 + 16);
result = jenkins1(a1, 0xAuLL, *(_DWORD *)(a1 + 12) ^ v1);
*(_DWORD *)(a1 + 16) = result ^ v1;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1)
{
unsigned int v1; // ebp
__int64 result; // rax

v1 = *(_DWORD *)(a1 + 16);
result = func5(a1, 0xAuLL, *(_DWORD *)(a1 + 12) ^ v1);
*(_DWORD *)(a1 + 16) = result ^ v1;
return result;
}

original_code:
void update_hash(struct tris_grid *grid) {
 grid->hash ^= jenkins1(grid->cells, 10, grid->seed ^ grid->hash);
}


evaluate

decompiled_code:
__int64 __fastcall evaluate(__int64 a1, char a2)
{
__int64 result; // rax
char v3[28]; // [rsp+Ch] [rbp-1Ch] BYREF

result = get_winner(a1);
if ( (_BYTE)result == 32 )
result = backtrack(a1, (unsigned int)a2, v3);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, char a2)
{
__int64 result; // rax
char v3[28]; // [rsp+Ch] [rbp-1Ch] BYREF

result = func1(a1);
if ( (_BYTE)result == 32 )
result = func8(a1, (unsigned int)a2, v3);
return result;
}

original_code:
char evaluate(const struct tris_grid *grid, char player) {
 char best_result;
 int move;
 ((void) (0));
 if ( (best_result = get_winner(grid)) != ' ' ) return best_result;
 else return backtrack(grid, player, &move);
}

canonical_original_code:
char evaluate(struct tris_grid *grid, char player) {
 char best_result;
 int move;
 ((void) (0));
 if ( (best_result = get_winner(grid)) != ' ' ) return best_result;
 else return backtrack(grid, player, &move);
}

variable_types: move int


backtrack

original_code:
char backtrack(const struct tris_grid *grid, char player, int *move) {
 int i, best_move;
 char opp = inverse(player);
 char best_result = opp;
 struct tris_grid try;
 ((void) (0));
 ((void) (0));
 try = *grid;
 for ( i = 1; i <= 9; i++ ) {
  if ( try.cells[i] == ' ' ) {
   char this_best_result;
   try.cells[i] = player;
   this_best_result = evaluate(&try, opp);
   if ( this_best_result == player ) {
    *move = i;
    return this_best_result;
   } else if ( better_for(this_best_result, best_result, player) ) {
    best_result = this_best_result;
    best_move = i;
   }
   try.cells[i] = ' ';
  }
 }
 *move = best_move;
 return best_result;
}

canonical_original_code:
char backtrack(struct tris_grid *grid, char player, int *move) {
 int i; int best_move;
 char opp = inverse(player);
 char best_result = opp;
 struct tris_grid try;
 ((void) (0));
 ((void) (0));
 try = *grid;
 for ( i = 1; i <= 9; i++ ) {
  if ( try.cells[i] == ' ' ) {
   char this_best_result;
   try.cells[i] = player;
   this_best_result = evaluate(&try, opp);
   if ( this_best_result == player ) {
    *move = i;
    return this_best_result;
   } else if ( better_for(this_best_result, best_result, player) ) {
    best_result = this_best_result;
    best_move = i;
   }
   try.cells[i] = ' ';
  }
 }
 *move = best_move;
 return best_result;
}

variable_types:
move
int *

variable_types: opp char

variable_types: struct tris_grid { char cells[10]; unsigned int seed; }


decompiled_code:
__int64 __fastcall username_is_valid(char *a1, unsigned __int8 a2)
{
__int64 result; // rax
char *v3; // rbx

result = 0LL;
if ( (unsigned __int8)(a2 - 3) <= 0x1Bu )
{
v3 = a1;
while ( strchr("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_.-", *v3) )
{
if ( ++v3 == &a1[a2] )
return 1LL;
}
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(char *a1, unsigned __int8 a2)
{
__int64 result; // rax
char *v3; // rbx

result = 0LL;
if ( (unsigned __int8)(a2 - 3) <= 0x1Bu )
{
v3 = a1;
while ( strchr("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_.-", *v3) )
{
if ( ++v3 == &a1[a2] )
return 1LL;
}
result = 0LL;
}
return result;
}

original_code:
bool username_is_valid(const char *username, uint8_t length) {
 int i;
 ((void) (0));
 if ( length < 3 ) return 0;
 if ( length > 30 ) return 0;
 ((void) (0));
 for ( i = 0; i < length; i++ )
  if ( strchr("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_.-", username[i]) == ((void *)0) )
   return 0;
 return 1;
}

canonical_original_code:
unsigned char username_is_valid(char *username, unsigned char length) {
 int i;
 ((void) (0));
 if ( length < 3 ) return 0;
 if ( length > 30 ) return 0;
 ((void) (0));
 for ( i = 0; i < length; i++ )
  if ( strchr("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_.-", username[i]) == ((void *)0) )
   return 0;
 return 1;
}

variable_types:
username
char *

variable_types:
length
unsigned char

variable_types: i int


decompiled_code:
const char *__fastcall magic_name(unsigned __int8 a1)
{
const char *result; // rax

if ( a1 > 0x72u )
{
result = "RESP_OK_LOGIN";
switch ( a1 )
{
case 0x94:
return result;
case 0x99:
return "REQ_END";
case 0x83:
return "RESP_NONEXIST";
}
LABEL_22:
sprintf(magic_name_buffer, "0x%02hx", a1);
return magic_name_buffer;
}
if ( a1 <= 0x15u )
{
result = "REQ_LOGIN";
if ( a1 == 7 )
return result;
goto LABEL_22;
}
switch ( a1 )
{
case 0x16u:
result = "RESP_OK_PLAY";
break;
case 0x24u:
result = "RESP_BADUSR";
break;
case 0x26u:
result = "REQ_PLAY";
break;
case 0x36u:
result = "RESP_WHO";
break;
case 0x41u:
result = "RESP_BUSY";
break;
case 0x44u:
result = "REQ_HELLO";
break;
case 0x47u:
result = "RESP_REFUSE";
break;
case 0x49u:
result = "RESP_EXIST";
break;
case 0x54u:
result = "RESP_BADREQ";
break;
case 0x62u:
result = "REQ_WHO";
break;
case 0x66u:
result = "REQ_HIT";
break;
case 0x72u:
result = "RESP_OK_FREE";
break;
default:
goto LABEL_22;
}
return result;
}

canonical_decompiled_code:
const char *__fastcall func3(unsigned __int8 a1)
{
const char *result; // rax

if ( a1 > 0x72u )
{
result = "RESP_OK_LOGIN";
switch ( a1 )
{
case 0x94:
return result;
case 0x99:
return "REQ_END";
case 0x83:
return "RESP_NONEXIST";
}
LABEL_22:
sprintf(magic_name_buffer, "0x%02hx", a1);
return magic_name_buffer;
}
if ( a1 <= 0x15u )
{
result = "REQ_LOGIN";
if ( a1 == 7 )
return result;
goto LABEL_22;
}
switch ( a1 )
{
case 0x16u:
result = "RESP_OK_PLAY";
break;
case 0x24u:
result = "RESP_BADUSR";
break;
case 0x26u:
result = "REQ_PLAY";
break;
case 0x36u:
result = "RESP_WHO";
break;
case 0x41u:
result = "RESP_BUSY";
break;
case 0x44u:
result = "REQ_HELLO";
break;
case 0x47u:
result = "RESP_REFUSE";
break;
case 0x49u:
result = "RESP_EXIST";
break;
case 0x54u:
result = "RESP_BADREQ";
break;
case 0x62u:
result = "REQ_WHO";
break;
case 0x66u:
result = "REQ_HIT";
break;
case 0x72u:
result = "RESP_OK_FREE";
break;
default:
goto LABEL_22;
}
return result;
}

original_code:
const char *magic_name(uint8_t value) {
 switch ( value ) {
  case 0x99: return "REQ_END";
  case 0x44: return "REQ_HELLO";
  case 0x66: return "REQ_HIT";
  case 0x07: return "REQ_LOGIN";
  case 0x26: return "REQ_PLAY";
  case 0x62: return "REQ_WHO";
  case 0x54: return "RESP_BADREQ";
  case 0x24: return "RESP_BADUSR";
  case 0x41: return "RESP_BUSY";
  case 0x49: return "RESP_EXIST";
  case 0x83: return "RESP_NONEXIST";
  case 0x72: return "RESP_OK_FREE";
  case 0x94: return "RESP_OK_LOGIN";
  case 0x16: return "RESP_OK_PLAY";
  case 0x47: return "RESP_REFUSE";
  case 0x36: return "RESP_WHO";
  default:
   sprintf(magic_name_buffer, "0x%02hx", (uint16_t) value);
   return magic_name_buffer;
 }
}

canonical_original_code:
char *magic_name(unsigned char value) {
 switch ( value ) {
  case 0x99: return "REQ_END";
  case 0x44: return "REQ_HELLO";
  case 0x66: return "REQ_HIT";
  case 0x07: return "REQ_LOGIN";
  case 0x26: return "REQ_PLAY";
  case 0x62: return "REQ_WHO";
  case 0x54: return "RESP_BADREQ";
  case 0x24: return "RESP_BADUSR";
  case 0x41: return "RESP_BUSY";
  case 0x49: return "RESP_EXIST";
  case 0x83: return "RESP_NONEXIST";
  case 0x72: return "RESP_OK_FREE";
  case 0x94: return "RESP_OK_LOGIN";
  case 0x16: return "RESP_OK_PLAY";
  case 0x47: return "RESP_REFUSE";
  case 0x36: return "RESP_WHO";
  default:
   sprintf(magic_name_buffer, "0x%02hx", (unsigned short) value);
   return magic_name_buffer;
 }
}

variable_types:
value
unsigned char


decompiled_code:
const char *__fastcall state_name(int a1)
{
const char *result; // rax

switch ( a1 )
{
case 0:
result = "NONE";
break;
case 1:
result = "CONNECTED";
break;
case 2:
result = "FREE";
break;
case 3:
result = "BUSY";
break;
case 4:
result = "PLAY";
break;
default:
result = 0LL;
break;
}
return result;
}

canonical_decompiled_code:
const char *__fastcall func4(int a1)
{
const char *result; // rax

switch ( a1 )
{
case 0:
result = "NONE";
break;
case 1:
result = "CONNECTED";
break;
case 2:
result = "FREE";
break;
case 3:
result = "BUSY";
break;
case 4:
result = "PLAY";
break;
default:
result = 0LL;
break;
}
return result;
}

original_code:
const char *state_name(enum client_state state) {
 switch ( state ) {
  case NONE: return "NONE";
  case CONNECTED: return "CONNECTED";
  case FREE: return "FREE";
  case BUSY: return "BUSY";
  case PLAY: return "PLAY";
 }
 ((void) (0));
 return ((void *)0);
}

variable_types: enum client_state { NONE=0, CONNECTED=1, FREE=2, BUSY=3, PLAY=4 }


decompiled_code:
__int64 __fastcall state_encode(int a1)
{
__int64 result; // rax

switch ( a1 )
{
case 0:
result = 78LL;
break;
case 1:
result = 67LL;
break;
case 2:
result = 70LL;
break;
case 3:
result = 66LL;
break;
case 4:
result = 80LL;
break;
default:
result = 0LL;
break;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(int a1)
{
__int64 result; // rax

switch ( a1 )
{
case 0:
result = 78LL;
break;
case 1:
result = 67LL;
break;
case 2:
result = 70LL;
break;
case 3:
result = 66LL;
break;
case 4:
result = 80LL;
break;
default:
result = 0LL;
break;
}
return result;
}

original_code:
uint8_t state_encode(enum client_state state) {
 switch ( state ) {
  case NONE: return 'N';
  case CONNECTED: return 'C';
  case FREE: return 'F';
  case BUSY: return 'B';
  case PLAY: return 'P';
 }
 ((void) (0));
 return '\0';
}

canonical_original_code:
unsigned char state_encode(enum client_state state) {
 switch ( state ) {
  case NONE: return 'N';
  case CONNECTED: return 'C';
  case FREE: return 'F';
  case BUSY: return 'B';
  case PLAY: return 'P';
 }
 ((void) (0));
 return '\0';
}


decompiled_code:
__int64 __fastcall state_decode(unsigned __int8 a1)
{
__int64 result; // rax

if ( a1 == 70 )
return 2LL;
if ( a1 > 0x46u )
return 4 * (unsigned int)(a1 == 80);
result = 3LL;
if ( a1 != 66 )
result = a1 == 67;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(unsigned __int8 a1)
{
__int64 result; // rax

if ( a1 == 70 )
return 2LL;
if ( a1 > 0x46u )
return 4 * (unsigned int)(a1 == 80);
result = 3LL;
if ( a1 != 66 )
result = a1 == 67;
return result;
}

original_code:
enum client_state state_decode(uint8_t enc) {
 switch ( enc ) {
  case 'N': return NONE;
  case 'C': return CONNECTED;
  case 'F': return FREE;
  case 'B': return BUSY;
  case 'P': return PLAY;
 }
 ((void) (0));
 return NONE;
}

canonical_original_code:
enum client_state state_decode(unsigned char enc) {
 switch ( enc ) {
  case 'N': return NONE;
  case 'C': return CONNECTED;
  case 'F': return FREE;
  case 'B': return BUSY;
  case 'P': return PLAY;
 }
 ((void) (0));
 return NONE;
}

variable_types:
enc
unsigned char

return_type: enum client_state { NONE=0, CONNECTED=1, FREE=2, BUSY=3, PLAY=4 }


decompiled_code:
__int64 __fastcall get_line(char *s, int a2)
{
__int64 result; // rax

fgets(s, a2, stdin);
result = (unsigned int)strlen(s) - 1;
s[(int)result] = 0;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(char *s, int a2)
{
__int64 result; // rax

fgets(s, a2, stdin);
result = (unsigned int)strlen(s) - 1;
s[(int)result] = 0;
return result;
}

original_code:
int get_line(char *buffer, int size) {
 int length;
 ((void) (0));
 fgets(buffer, size, stdin);
 length = strlen(buffer) - 1;
 buffer[length] = '\0';
 return length;
}

variable_types:
buffer
char *

variable_types: size int

variable_types: length int


decompiled_code:
__int64 __fastcall send_buffer(int fd, __int64 a2, int a3)
{
int v4; // ebx
int v5; // eax
unsigned int v6; // edx

if ( a3 <= 0 )
return 0LL;
v4 = 0;
while ( 1 )
{
v5 = send(fd, (const void *)(a2 + v4), a3 - v4, 0);
v6 = v5;
if ( v5 < 0 )
break;
v4 += v5;
if ( a3 <= v4 )
return 0;
}
return v6;
}

canonical_decompiled_code:
__int64 __fastcall func8(int fd, __int64 a2, int a3)
{
int v4; // ebx
int v5; // eax
unsigned int v6; // edx

if ( a3 <= 0 )
return 0LL;
v4 = 0;
while ( 1 )
{
v5 = send(fd, (const void *)(a2 + v4), a3 - v4, 0);
v6 = v5;
if ( v5 < 0 )
break;
v4 += v5;
if ( a3 <= v4 )
return 0;
}
return v6;
}

original_code:
int send_buffer(int socket, const char *buffer, int length) {
 int sent, counter = 0;
 while ( length > counter ) {
  sent = send(socket, buffer + counter, length - counter, 0);
  if ( sent < 0 ) return sent;
  counter += sent;
 }
 return 0;
}

canonical_original_code:
int send_buffer(int socket, char *buffer, int length) {
 int sent; int counter = 0;
 while ( length > counter ) {
  sent = send(socket, buffer + counter, length - counter, 0);
  if ( sent < 0 ) return sent;
  counter += sent;
 }
 return 0;
}

variable_types: socket int

variable_types: sent int

variable_types: counter int


decompiled_code:
ssize_t __fastcall send_byte(int a1, char a2)
{
char buf[12]; // [rsp+Ch] [rbp-Ch] BYREF

buf[0] = a2;
return send(a1, buf, 1uLL, 0);
}

canonical_decompiled_code:
ssize_t __fastcall func9(int a1, char a2)
{
char buf[12]; // [rsp+Ch] [rbp-Ch] BYREF

buf[0] = a2;
return send(a1, buf, 1uLL, 0);
}

original_code:
int send_byte(int socket, uint8_t byte) {
 return send(socket, &byte, 1, 0);
}

canonical_original_code:
int send_byte(int socket, unsigned char byte) {
 return send(socket, &byte, 1, 0);
}

variable_types:
byte
unsigned char


decompiled_code:
int __fastcall set_handler(int sig, void (*a2)(int))
{
struct sigaction v3; // [rsp+0h] [rbp-A8h] BYREF

v3.sa_handler = a2;
sigfillset(&v3.sa_mask);
v3.sa_flags = 0;
return sigaction(sig, &v3, 0LL);
}

canonical_decompiled_code:
int __fastcall func0(int sig, void (*a2)(int))
{
struct sigaction v3; // [rsp+0h] [rbp-A8h] BYREF

v3.sa_handler = a2;
sigfillset(&v3.sa_mask);
v3.sa_flags = 0;
return sigaction(sig, &v3, 0LL);
}

original_code:
int set_handler(int signal, void (*handler)(int)) {
 struct sigaction sa;
 sa.sa_handler = handler;
 sigfillset(&sa.sa_mask);
 sa.sa_flags = 0;
 return sigaction(signal, &sa, ((void *)0));
}

variable_types: signal int

variable_types:
handler
void (*)(int)

variable_types: struct sigaction { void (*sa_handler)(int); struct __sigset_t { unsigned long __val[-1]; } sa_mask; int sa_flags; void (*sa_restorer)(); }

user_defined_types: struct sigaction { void (*sa_handler)(int); struct __sigset_t sa_mask; int sa_flags; void (*sa_restorer)(); }


repo: FedericoVaga/libuinput

decompiled_code:
int __fastcall flush_kmsg(int fd)
{
int result; // eax
fd_set v2; // [rsp+0h] [rbp-4B8h] BYREF
char buf[1024]; // [rsp+80h] [rbp-438h] BYREF
struct timeval timeout; // [rsp+480h] [rbp-38h] BYREF

timeout.tv_sec = 0LL;
timeout.tv_usec = 0LL;
while ( 1 )
{
memset(&v2, 0, sizeof(v2));
v2.fds_bits[fd / 64] |= 1LL << (fd % 64);
result = select(fd + 1, &v2, 0LL, 0LL, &timeout);
if ( result != 1 )
break;
read(fd, buf, 0x400uLL);
}
return result;
}

canonical_decompiled_code:
int __fastcall func6(int fd)
{
int result; // eax
fd_set v2; // [rsp+0h] [rbp-4B8h] BYREF
char buf[1024]; // [rsp+80h] [rbp-438h] BYREF
struct timeval timeout; // [rsp+480h] [rbp-38h] BYREF

timeout.tv_sec = 0LL;
timeout.tv_usec = 0LL;
while ( 1 )
{
memset(&v2, 0, sizeof(v2));
v2.fds_bits[fd / 64] |= 1LL << (fd % 64);
result = select(fd + 1, &v2, 0LL, 0LL, &timeout);
if ( result != 1 )
break;
read(fd, buf, 0x400uLL);
}
return result;
}

original_code:
static void flush_kmsg(int fd)
{
 struct timeval timeout = {0, 0};
 char buf[1024];
 fd_set set;
 int err;
 while (1) {
  do { int __d0, __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&set)->__fds_bits)[0]) : "memory"); } while (0);
  ((void) (((&set)->__fds_bits)[((fd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((fd) % (8 * (int) sizeof (__fd_mask)))))));
  err = select(fd + 1, &set, ((void *)0), ((void *)0), &timeout);
  if (err != 1)
   break;
  read(fd, &buf, 1024);
 }
}

canonical_original_code:
static void flush_kmsg(int fd)
{
 struct timeval timeout = {0, 0};
 char buf[1024];
 struct fd_set set;
 int err;
 while (1) {
  do { int __d0; int __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&set)->__fds_bits)[0]) : "memory"); } while (0);
  ((void) (((&set)->__fds_bits)[((fd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((fd) % (8 * (int) sizeof (__fd_mask)))))));
  err = select(fd + 1, &set, ((void *)0), ((void *)0), &timeout);
  if (err != 1)
   break;
  read(fd, &buf, 1024);
 }
}

variable_types: fd int

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

variable_types:
buf
char [1024]

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

variable_types: err int


regGetName

repo: Fedjmike/fcc

decompiled_code:
const char *__fastcall regGetName(_QWORD *a1, unsigned int a2)
{
switch ( a2 )
{
case 1u:
return (const char *)a1[1];
case 2u:
return (const char *)a1[2];
case 4u:
return (const char *)a1[3];
case 8u:
return (const char *)a1[4];
}
debugErrorUnhandledInt("regGetName", "register size", a2);
return "unhandled";
}

canonical_decompiled_code:
const char *__fastcall func0(_QWORD *a1, unsigned int a2)
{
switch ( a2 )
{
case 1u:
return (const char *)a1[1];
case 2u:
return (const char *)a1[2];
case 4u:
return (const char *)a1[3];
case 8u:
return (const char *)a1[4];
}
debugErrorUnhandledInt("regGetName", "register size", a2);
return "unhandled";
}

original_code:
static const char* regGetName (const reg* r, int size) {
    if (size == 1)
        return r->names[0];
    else if (size == 2)
        return r->names[1];
    else if (size == 4)
        return r->names[2];
    else if (size == 8)
        return r->names[3];
    else {
        debugErrorUnhandledInt("regGetName", "register size", size);
        return "unhandled";
    }
}

canonical_original_code:
static char *regGetName(struct reg *r, int size) {
    if (size == 1)
        return r->names[0];
    else if (size == 2)
        return r->names[1];
    else if (size == 4)
        return r->names[2];
    else if (size == 8)
        return r->names[3];
    else {
        debugErrorUnhandledInt("regGetName", "register size", size);
        return "unhandled";
    }
}

variable_types: struct reg { int size; char *names[4]; int allocatedAs; } *


regGet

decompiled_code:
int *__fastcall regGet(int a1)
{
return &regs[12 * a1];
}

canonical_decompiled_code:
int *__fastcall func2(int a1)
{
return &regs[12 * a1];
}

original_code:
const reg* regGet (regIndex r) {
    return &regs[r];
}

canonical_original_code:
struct reg *regGet(enum regIndex r) {
    return &regs[r];
}

variable_types: enum regIndex { regUndefined=0, regRAX=1, regRBX=2, regRCX=3, regRDX=4, regRSI=5, regRDI=6, regR8=7, regR9=8, regR10=9, regR11=10, regR12=11, regR13=12, regR14=13, regR15=14, regRBP=15, regRSP=16, regMax=17 }

return_type: struct reg { int size; char *names[4]; int allocatedAs; } *


regFree

decompiled_code:
void __fastcall regFree(__int64 a1)
{
*(_DWORD *)(a1 + 40) = 0;
}

canonical_decompiled_code:
void __fastcall func3(__int64 a1)
{
*(_DWORD *)(a1 + 40) = 0;
}

original_code:
void regFree (reg* r) {
    r->allocatedAs = false;
}

canonical_original_code:
void regFree(struct reg *r) {
    r->allocatedAs = false;
}

user_defined_types: struct reg { int size; char *names[4]; int allocatedAs; }


regIndexGetName

decompiled_code:
const char *__fastcall regIndexGetName(int a1, unsigned int a2)
{
return regGetName(&regs[12 * a1], a2);
}

canonical_decompiled_code:
const char *__fastcall func4(int a1, unsigned int a2)
{
return func0(&regs[12 * a1], a2);
}

original_code:
const char* regIndexGetName (regIndex r, int size) {
    return regGetName(&regs[r], size);
}

canonical_original_code:
char *regIndexGetName(enum regIndex r, int size) {
    return regGetName(&regs[r], size);
}

user_defined_types: enum regIndex { regUndefined=0, regRAX=1, regRBX=2, regRCX=3, regRDX=4, regRSI=5, regRDI=6, regR8=7, regR9=8, regR10=9, regR11=10, regR12=11, regR13=12, regR14=13, regR15=14, regRBP=15, regRSP=16, regMax=17 }


regRequest

decompiled_code:
int *__fastcall regRequest(int a1, int a2)
{
int *result; // rax
const char *v3; // rax

if ( !a2 )
{
v3 = regIndexGetName(a1, 8u);
debugError("regRequest", "zero sized register requested, %s", v3);
a2 = regs[12 * a1];
if ( a2 == 8 )
{
if ( regs[12 * a1 + 10] )
return 0LL;
goto LABEL_4;
}
a2 = 4;
}
if ( regs[12 * a1 + 10] )
return 0LL;
result = 0LL;
if ( regs[12 * a1] <= a2 )
{
LABEL_4:
regs[12 * a1 + 10] = a2;
result = &regs[12 * a1];
}
return result;
}

canonical_decompiled_code:
int *__fastcall func5(int a1, int a2)
{
int *result; // rax
const char *v3; // rax

if ( !a2 )
{
v3 = func4(a1, 8u);
debugError("regRequest", "zero sized register requested, %s", v3);
a2 = regs[12 * a1];
if ( a2 == 8 )
{
if ( regs[12 * a1 + 10] )
return 0LL;
goto LABEL_4;
}
a2 = 4;
}
if ( regs[12 * a1 + 10] )
return 0LL;
result = 0LL;
if ( regs[12 * a1] <= a2 )
{
LABEL_4:
regs[12 * a1 + 10] = a2;
result = &regs[12 * a1];
}
return result;
}

original_code:
reg* regRequest (regIndex r, int size) {
    if (size == 0) {
        debugError("regRequest", "zero sized register requested, %s", regIndexGetName(r, 8));
        size = regs[r].size == 8 ? 8 : 4;
    }
    if (regs[r].allocatedAs == 0 && regs[r].size <= size) {
        regs[r].allocatedAs = size;
        return &regs[r];
    } else
        return 0;
}

canonical_original_code:
struct reg *regRequest(enum regIndex r, int size) {
    if (size == 0) {
        debugError("regRequest", "zero sized register requested, %s", regIndexGetName(r, 8));
        size = regs[r].size == 8 ? 8 : 4;
    }
    if (regs[r].allocatedAs == 0 && regs[r].size <= size) {
        regs[r].allocatedAs = size;
        return &regs[r];
    } else
        return 0;
}


regAlloc

decompiled_code:
int *__fastcall regAlloc(int a1)
{
unsigned int i; // ebx

if ( !a1 )
return 0LL;
for ( i = 2; i <= 0xE; ++i )
{
if ( regRequest(i, a1) )
return &regs[12 * i];
}
if ( regIsUsed(1) )
debugError("regAlloc", "no registers left");
return regRequest(1, a1);
}

canonical_decompiled_code:
int *__fastcall func6(int a1)
{
unsigned int i; // ebx

if ( !a1 )
return 0LL;
for ( i = 2; i <= 0xE; ++i )
{
if ( func5(i, a1) )
return &regs[12 * i];
}
if ( func1(1) )
debugError("regAlloc", "no registers left");
return func5(1, a1);
}

original_code:
reg* regAlloc (int size) {
    if (size == 0)
        return 0;
    for (regIndex r = regRBX; r <= regR15; r++)
        if (regRequest(r, size) != 0)
            return &regs[r];
    if (regIsUsed(regRAX))
        debugError("regAlloc", "no registers left");
    return regRequest(regRAX, size);
}

canonical_original_code:
struct reg *regAlloc(int size) {
    if (size == 0)
        return 0;
    for (enum regIndex r = regRBX; r <= regR15; r++)
        if (regRequest(r, size) != 0)
            return &regs[r];
    if (regIsUsed(regRAX))
        debugError("regAlloc", "no registers left");
    return regRequest(regRAX, size);
}


regGetStr

decompiled_code:
const char *__fastcall regGetStr(__int64 a1)
{
return regGetName((_QWORD *)a1, *(_DWORD *)(a1 + 40));
}

canonical_decompiled_code:
const char *__fastcall func7(__int64 a1)
{
return func0((_QWORD *)a1, *(_DWORD *)(a1 + 40));
}

original_code:
const char* regGetStr (const reg* r) {
    return regGetName(r, r->allocatedAs);
}

canonical_original_code:
char *regGetStr(struct reg *r) {
    return regGetName(r, r->allocatedAs);
}


debugSetMode

decompiled_code:
__int64 __fastcall debugSetMode(int a1)
{
__int64 result; // rax

result = (unsigned int)mode;
mode = a1;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1)
{
__int64 result; // rax

result = (unsigned int)mode;
mode = a1;
return result;
}

original_code:
debugMode debugSetMode (debugMode nmode) {
    debugMode old = mode;
    mode = nmode;
    return old;
}

canonical_original_code:
enum debugMode debugSetMode(enum debugMode nmode) {
    enum debugMode old = mode;
    mode = nmode;
    return old;
}

variable_types: enum debugMode { debugFull=0, debugCompressed=1, debugMinimal=2, debugSilent=3 }


debugWait

decompiled_code:
void debugWait()
{
;
}

canonical_decompiled_code:
void func2()
{
;
}

original_code:
void debugWait () {
}

canonical_original_code:
void debugWait() {
}


debugOut

decompiled_code:
char *__fastcall debugOut(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, char a7)
{
return &a7;
}

canonical_decompiled_code:
char *__fastcall func3(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, char a7)
{
return &a7;
}

original_code:
void debugOut (const char* format, ...) {
    va_list args;
    __builtin_va_start(args,format);
    debugVarOut(format, args);
    __builtin_va_end(args);
}

canonical_original_code:
void debugOut(char *format, ...) {
    __builtin_va_list args;
    __builtin_va_start(args,format);
    debugVarOut(format, args);
    __builtin_va_end(args);
}

variable_types:
format
char *


debugMsg

decompiled_code:
char *debugMsg(__int64 a1, ...)
{
gcc_va_list va; // [rsp+8h] [rbp-D0h] BYREF
__int64 v3; // [rsp+28h] [rbp-B0h]
__int64 v4; // [rsp+30h] [rbp-A8h]
__int64 v5; // [rsp+38h] [rbp-A0h]
__int64 v6; // [rsp+40h] [rbp-98h]
__int64 v7; // [rsp+48h] [rbp-90h]

va_start(va, a1);
v3 = va_arg(va, _QWORD);
v4 = va_arg(va, _QWORD);
v5 = va_arg(va, _QWORD);
v6 = va_arg(va, _QWORD);
v7 = va_arg(va, _QWORD);
va_end(va);
va_start(va, a1);
return debugVarMsg(a1, (__int64)va, v4, v5, v6, v7);
}

canonical_decompiled_code:
char *func5(__int64 a1, ...)
{
gcc_va_list va; // [rsp+8h] [rbp-D0h] BYREF
__int64 v3; // [rsp+28h] [rbp-B0h]
__int64 v4; // [rsp+30h] [rbp-A8h]
__int64 v5; // [rsp+38h] [rbp-A0h]
__int64 v6; // [rsp+40h] [rbp-98h]
__int64 v7; // [rsp+48h] [rbp-90h]

va_start(va, a1);
v3 = va_arg(va, _QWORD);
v4 = va_arg(va, _QWORD);
v5 = va_arg(va, _QWORD);
v6 = va_arg(va, _QWORD);
v7 = va_arg(va, _QWORD);
va_end(va);
va_start(va, a1);
return func4(a1, (__int64)va, v4, v5, v6, v7);
}

original_code:
void debugMsg (const char* format, ...) {
    va_list args;
    __builtin_va_start(args,format);
    debugVarMsg(format, args);
    __builtin_va_end(args);
}

canonical_original_code:
void debugMsg(char *format, ...) {
    __builtin_va_list args;
    __builtin_va_start(args,format);
    debugVarMsg(format, args);
    __builtin_va_end(args);
}


debugEnter

decompiled_code:
char *__fastcall debugEnter(const char *a1)
{
char *result; // rax

if ( (unsigned int)mode <= 1 )
{
result = debugMsg((__int64)"+ %s", a1);
++depth;
}
return result;
}

canonical_decompiled_code:
char *__fastcall func6(const char *a1)
{
char *result; // rax

if ( (unsigned int)mode <= 1 )
{
result = func5((__int64)"+ %s", a1);
++depth;
}
return result;
}

original_code:
void debugEnter (const char* str) {
    if (mode <= debugCompressed) {
        debugMsg("+ %s", str);
        depth++;
    }
}

canonical_original_code:
void debugEnter(char *str) {
    if (mode <= debugCompressed) {
        debugMsg("+ %s", str);
        depth++;
    }
}

variable_types:
str
char *


debugLeave

decompiled_code:
char *debugLeave()
{
char *result; // rax

result = (char *)(unsigned int)mode;
if ( (unsigned int)mode <= 1 )
--depth;
if ( !mode )
result = debugMsg((__int64)"-");
return result;
}

canonical_decompiled_code:
char *func7()
{
char *result; // rax

result = (char *)(unsigned int)mode;
if ( (unsigned int)mode <= 1 )
--depth;
if ( !mode )
result = func5((__int64)"-");
return result;
}

original_code:
void debugLeave () {
    if (mode <= debugCompressed)
        depth--;
    if (mode == debugFull)
        debugMsg("-");
}

canonical_original_code:
void debugLeave() {
    if (mode <= debugCompressed)
        depth--;
    if (mode == debugFull)
        debugMsg("-");
}


debugVarOut

decompiled_code:
void debugVarOut()
{
;
}

canonical_decompiled_code:
void func8()
{
;
}

original_code:
void debugVarOut (const char* format, va_list args) {
    (void) args, (void) format;
}

canonical_original_code:
void debugVarOut(char *format, __builtin_va_list args) {
    (void) args, (void) format;
}


debugError

decompiled_code:
int debugError(const char *a1, const char *a2, ...)
{
int result; // eax
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

va_start(arg, a2);
fprintf(logFile, "internal error(%s): ", a1);
vfprintf(logFile, a2, arg);
result = fputc(10, logFile);
++internalErrors;
return result;
}

canonical_decompiled_code:
int func9(const char *a1, const char *a2, ...)
{
int result; // eax
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

va_start(arg, a2);
fprintf(logFile, "internal error(%s): ", a1);
vfprintf(logFile, a2, arg);
result = fputc(10, logFile);
++internalErrors;
return result;
}

original_code:
void debugError (const char* functionName,
                 const char* format, ...) {
    fprintf(logFile, "internal error(%s): ", functionName);
    va_list args;
    __builtin_va_start(args,format);
    vfprintf(logFile, format, args);
    __builtin_va_end(args);
    fputc('\n', logFile);
    debugWait();
    internalErrors++;
}

canonical_original_code:
void debugError(char *functionName, char *format, ...) {
    fprintf(logFile, "internal error(%s): ", functionName);
    __builtin_va_list args;
    __builtin_va_start(args,format);
    vfprintf(logFile, format, args);
    __builtin_va_end(args);
    fputc('\n', logFile);
    debugWait();
    internalErrors++;
}

variable_types:
functionName
char *


debugErrorUnhandled

decompiled_code:
int __fastcall debugErrorUnhandled(const char *a1, const char *a2, const char *a3)
{
return debugError(a1, "unhandled %s: '%s'", a2, a3);
}

canonical_decompiled_code:
int __fastcall func11(const char *a1, const char *a2, const char *a3)
{
return func9(a1, "unhandled %s: '%s'", a2, a3);
}

original_code:
void debugErrorUnhandled (const char* functionName,
                          const char* className,
                          const char* classStr) {
    debugError(functionName, "unhandled %s: '%s'", className, classStr);
}

canonical_original_code:
void debugErrorUnhandled(char *functionName, char *className, char *classStr) {
    debugError(functionName, "unhandled %s: '%s'", className, classStr);
}

variable_types:
className
char *

variable_types:
classStr
char *


debugErrorUnhandledInt

decompiled_code:
int __fastcall debugErrorUnhandledInt(const char *a1, const char *a2, unsigned int a3)
{
return debugError(a1, "unhandled %s: %d", a2, a3);
}

canonical_decompiled_code:
int __fastcall func12(const char *a1, const char *a2, unsigned int a3)
{
return func9(a1, "unhandled %s: %d", a2, a3);
}

original_code:
void debugErrorUnhandledInt (const char* functionName,
                             const char* className,
                             int classInt) {
    debugError(functionName, "unhandled %s: %d", className, classInt);
}

canonical_original_code:
void debugErrorUnhandledInt(char *functionName, char *className, int classInt) {
    debugError(functionName, "unhandled %s: %d", className, classInt);
}

variable_types: classInt int


debugErrorUnhandledChar

decompiled_code:
int __fastcall debugErrorUnhandledChar(const char *a1, const char *a2, char a3)
{
return debugError(a1, "unhandled %s: '%c'", a2, (unsigned int)a3);
}

canonical_decompiled_code:
int __fastcall func13(const char *a1, const char *a2, char a3)
{
return func9(a1, "unhandled %s: '%c'", a2, (unsigned int)a3);
}

original_code:
void debugErrorUnhandledChar (const char* functionName,
                              const char* className,
                              char classChar) {
    debugError(functionName, "unhandled %s: '%c'", className, classChar);
}

canonical_original_code:
void debugErrorUnhandledChar(char *functionName, char *className, char classChar) {
    debugError(functionName, "unhandled %s: '%c'", className, classChar);
}

variable_types: classChar char


reportRegs

original_code:
void reportRegs () {
    debugOut("[ ");
    for (regIndex r = 0; r < regMax; r++)
        if (regIsUsed(r))
            debugOut("%s ", regGetStr(regGet(r)));
    debugOut(" ]\n");
}

canonical_original_code:
void reportRegs() {
    debugOut("[ ");
    for (enum regIndex r = 0; r < regMax; r++)
        if (regIsUsed(r))
            debugOut("%s ", regGetStr(regGet(r)));
    debugOut(" ]\n");
}


vectorResize

decompiled_code:
void *__fastcall vectorResize(__int64 a1, int a2)
{
void *result; // rax

*(_DWORD *)(a1 + 4) = a2;
result = realloc(*(void **)(a1 + 8), 8LL * a2);
*(_QWORD *)(a1 + 8) = result;
return result;
}

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

*(_DWORD *)(a1 + 4) = a2;
result = realloc(*(void **)(a1 + 8), 8LL * a2);
*(_QWORD *)(a1 + 8) = result;
return result;
}

original_code:
static void vectorResize (vector* v, int size) {
    v->capacity = size;
    v->buffer = realloc(v->buffer, v->capacity*sizeof(void*));
}

canonical_original_code:
static void vectorResize(struct vector *v, int size) {
    v->capacity = size;
    v->buffer = realloc(v->buffer, v->capacity*sizeof(void *));
}

variable_types: struct vector { int length; void **buffer; } *

variable_types: size int


vectorInit

decompiled_code:
__int64 __fastcall vectorInit(__int64 a1, int a2)
{
*(_DWORD *)a1 = 0;
*(_DWORD *)(a1 + 4) = a2;
*(_QWORD *)(a1 + 8) = malloc(8LL * a2);
return a1;
}

original_code:
vector* vectorInit (vector* v, int initialCapacity) {
    v->length = 0;
    v->capacity = initialCapacity;
    v->buffer = malloc(initialCapacity*sizeof(void*));
    return v;
}

canonical_original_code:
struct vector *vectorInit(struct vector *v, int initialCapacity) {
    v->length = 0;
    v->capacity = initialCapacity;
    v->buffer = malloc(initialCapacity*sizeof(void *));
    return v;
}

variable_types:
v
struct vector *

variable_types: initialCapacity int

return_type: struct vector { int length; void **buffer; } *


vectorFree

original_code:
void vectorFree (vector* v) {
    free(v->buffer);
    v->length = 0;
    v->capacity = 0;
    v->buffer = 0;
}

canonical_original_code:
void vectorFree(struct vector *v) {
    free(v->buffer);
    v->length = 0;
    v->capacity = 0;
    v->buffer = 0;
}

user_defined_types: struct vector { int length; void **buffer; }


vectorPush

decompiled_code:
__int64 __fastcall vectorPush(int *a1, __int64 a2)
{
int v3; // esi
__int64 result; // rax

v3 = a1[1];
if ( *a1 == v3 )
vectorResize((__int64)a1, 2 * v3);
*(_QWORD *)(*((_QWORD *)a1 + 1) + 8LL * *a1) = a2;
result = (unsigned int)*a1;
*a1 = result + 1;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(int *a1, __int64 a2)
{
int v3; // esi
__int64 result; // rax

v3 = a1[1];
if ( *a1 == v3 )
func0((__int64)a1, 2 * v3);
*(_QWORD *)(*((_QWORD *)a1 + 1) + 8LL * *a1) = a2;
result = (unsigned int)*a1;
*a1 = result + 1;
return result;
}

original_code:
int vectorPush (vector* v, void* item) {
    if (v->length == v->capacity)
        vectorResize(v, v->capacity*2);
    v->buffer[v->length] = item;
    return v->length++;
}

canonical_original_code:
int vectorPush(struct vector *v, void *item) {
    if (v->length == v->capacity)
        vectorResize(v, v->capacity*2);
    v->buffer[v->length] = item;
    return v->length++;
}

variable_types:
item
void *


vectorPushFromArray

decompiled_code:
int *__fastcall vectorPushFromArray(int *a1, char *a2, int a3, int a4)
{
char *v4; // rbp
int v7; // eax
__int64 v8; // rbx

v4 = a2;
v7 = a1[1];
if ( v7 < *a1 + a3 )
vectorResize((__int64)a1, v7 + 2 * a3);
if ( a4 == 8 )
{
memcpy((void *)(*((_QWORD *)a1 + 1) + 8LL * *a1), a2, 8 * a3);
}
else if ( a3 > 0 )
{
v8 = 0LL;
do
{
memcpy((void *)(*((_QWORD *)a1 + 1) + v8), v4, a4);
v8 += 8LL;
v4 += a4;
}
while ( v8 != 8LL * (unsigned int)a3 );
}
*a1 += a3;
return a1;
}

original_code:
vector* vectorPushFromArray (vector* v, void** array, int length, int elementSize) {
    if (v->capacity < v->length + length)
        vectorResize(v, v->capacity + length*2);
    if (elementSize == sizeof(void*))
        memcpy(v->buffer+v->length, array, length*elementSize);
    else
        for (int i = 0; i < length; i++)
            memcpy(v->buffer+i, (char*) array + i*elementSize, elementSize);
    v->length += length;
    return v;
}

canonical_original_code:
struct vector *vectorPushFromArray(struct vector *v, void **array, int length, int elementSize) {
    if (v->capacity < v->length + length)
        vectorResize(v, v->capacity + length*2);
    if (elementSize == sizeof(void *))
        memcpy(v->buffer+v->length, array, length*elementSize);
    else
        for (int i = 0; i < length; i++)
            memcpy(v->buffer+i, (char *) array + i*elementSize, elementSize);
    v->length += length;
    return v;
}

variable_types:
array
void **

variable_types: length int

variable_types: elementSize int

variable_types: i int


vectorPushFromVector

decompiled_code:
int *__fastcall vectorPushFromVector(int *a1, __int64 a2)
{
return vectorPushFromArray(a1, *(char **)(a2 + 8), *(_DWORD *)a2, 8);
}

canonical_decompiled_code:
int *__fastcall func5(int *a1, __int64 a2)
{
return func4(a1, *(char **)(a2 + 8), *(_DWORD *)a2, 8);
}

original_code:
vector* vectorPushFromVector (vector* dest, const vector* src) {
    return vectorPushFromArray(dest, src->buffer, src->length, sizeof(void*));
}

canonical_original_code:
struct vector *vectorPushFromVector(struct vector *dest, struct vector *src) {
    return vectorPushFromArray(dest, src->buffer, src->length, sizeof(void *));
}

variable_types:
dest
struct vector *

variable_types:
src
struct vector *


vectorPop

decompiled_code:
__int64 __fastcall vectorPop(__int64 a1)
{
__int64 v1; // rdx
int v2; // eax

v1 = *(_QWORD *)(a1 + 8);
v2 = *(_DWORD *)a1 - 1;
*(_DWORD *)a1 = v2;
return *(_QWORD *)(v1 + 8LL * v2);
}

original_code:
void* vectorPop (vector* v) {
    return v->buffer[--v->length];
}

canonical_original_code:
void *vectorPop(struct vector *v) {
    return v->buffer[--v->length];
}