decompiled_code:
__int64 __fastcall get_config_entry_uint64(const char *a1, _QWORD *a2)
{
int *v2; // rbp
__int64 result; // rax
_BYTE v4[4104]; // [rsp+0h] [rbp-1028h] BYREF
__int64 v5; // [rsp+1008h] [rbp-20h] BYREF

fflush(stdin);
printf("Enter new %s\n", a1);
if ( (int)readline_unbuf(0, (__int64)v4, 4096LL) < 0 )
{
fprintf(stderr, "Error: expected digital input for %s\n", a1);
result = wait_for_key();
}
else
{
v2 = _errno_location();
*v2 = 0;
if ( (unsigned int)_isoc99_sscanf(v4, "%lu", &v5) != 1 || *v2 )
{
perror("fscanf");
fprintf(stderr, "Error: expected digital input for %s\n", a1);
result = wait_for_key();
}
else
{
result = v5;
*a2 = v5;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(const char *a1, _QWORD *a2)
{
int *v2; // rbp
__int64 result; // rax
_BYTE v4[4104]; // [rsp+0h] [rbp-1028h] BYREF
__int64 v5; // [rsp+1008h] [rbp-20h] BYREF

fflush(stdin);
printf("Enter new %s\n", a1);
if ( (int)func1(0, (__int64)v4, 4096LL) < 0 )
{
fprintf(stderr, "Error: expected digital input for %s\n", a1);
result = func2();
}
else
{
v2 = _errno_location();
*v2 = 0;
if ( (unsigned int)_isoc99_sscanf(v4, "%lu", &v5) != 1 || *v2 )
{
perror("fscanf");
fprintf(stderr, "Error: expected digital input for %s\n", a1);
result = func2();
}
else
{
result = v5;
*a2 = v5;
}
}
return result;
}

original_code:
static
void get_config_entry_uint64(const char *name,
  uint64_t *value)
{
 uint64_t new_size;
 char read_buf[4096];
 int ret;
 fflush(stdin);
 printf("Enter new %s\n", name);
 ret = readline_unbuf(0, read_buf, sizeof(read_buf));
 if (ret < 0) {
  fprintf(stderr, "Error: expected digital input for %s\n",
   name);
  wait_for_key();
  return;
 }
 (*__errno_location ()) = 0;
 ret = sscanf(read_buf, "%" "l" "u", &new_size);
 if (ret != 1 || (*__errno_location ()) != 0) {
  perror("fscanf");
  fprintf(stderr, "Error: expected digital input for %s\n",
   name);
  wait_for_key();
  return;
 }
 *value = new_size;
}

canonical_original_code:
static void get_config_entry_uint64(char *name, unsigned long *value)
{
 unsigned long new_size;
 char read_buf[4096];
 int ret;
 fflush(stdin);
 printf("Enter new %s\n", name);
 ret = readline_unbuf(0, read_buf, sizeof(read_buf));
 if (ret < 0) {
  fprintf(stderr, "Error: expected digital input for %s\n",
   name);
  wait_for_key();
  return;
 }
 (*__errno_location ()) = 0;
 ret = sscanf(read_buf, "%" "l" "u", &new_size);
 if (ret != 1 || (*__errno_location ()) != 0) {
  perror("fscanf");
  fprintf(stderr, "Error: expected digital input for %s\n",
   name);
  wait_for_key();
  return;
 }
 *value = new_size;
}

variable_types:
name
char *

variable_types:
value
unsigned long *


repo: efficios/urcu-tutorial

decompiled_code:
__int64 do_config()
{
__int64 v0; // rax
__int64 v1; // rbx
__int64 result; // rax
unsigned __int64 v3; // [rsp+0h] [rbp-28h] BYREF
char v4[25]; // [rsp+Fh] [rbp-19h] BYREF

v0 = urcu_game_config_update_begin();
if ( !v0 )
abort();
v1 = v0;
while ( 2 )
{
clear_screen();
puts("[ root > configuration ]");
puts("Enter the config field you wish to update:");
puts(" key\tDescription");
puts("---------------------------------");
puts(" q\tCancel update");
puts(" x\tSave update and exit configuration menu");
printf(" i\tIsland size (%lu)\n", *(_QWORD *)v1);
printf(" d\tStep delay (%d ms)\n", *(unsigned int *)(v1 + 8));
printf(" g\tGerbil max birth stamina (%lu)\n", *(_QWORD *)(v1 + 16));
printf(" c\tCat max birth stamina (%lu)\n", *(_QWORD *)(v1 + 40));
printf(" s\tSnake max birth stamina (%lu)\n", *(_QWORD *)(v1 + 64));
result = getch(v4);
if ( (int)result >= 0 )
{
if ( verbose )
printf("[debug %s()@user-input.c:%d] User input: '%c'\n", "do_config", 184LL, (unsigned int)v4[0]);
switch ( v4[0] )
{
case 'c':
get_config_entry_uint64("cat stamina", (_QWORD *)(v1 + 40));
continue;
case 'd':
get_config_entry_uint64("step delay (ms)", &v3);
if ( v3 >= 0x80000000 )
{
puts("Error: delay specified is too large.");
wait_for_key();
}
else
{
*(_DWORD *)(v1 + 8) = v3;
}
continue;
case 'g':
get_config_entry_uint64("gerbil stamina", (_QWORD *)(v1 + 16));
continue;
case 'i':
get_config_entry_uint64("island size (increase only)", &v3);
if ( *(_QWORD *)v1 >= v3 )
puts("Error: Island size can only be increased.");
else
*(_QWORD *)v1 = v3;
continue;
case 'q':
puts("Configuration update cancelled.");
urcu_game_config_update_abort(v1);
result = wait_for_key();
break;
case 's':
get_config_entry_uint64("snake stamina", (_QWORD *)(v1 + 64));
continue;
case 'x':
puts("Configuration saved.");
urcu_game_config_update_end(v1);
result = wait_for_key();
break;
default:
printf("Unknown key: '%c'\n", (unsigned int)v4[0]);
wait_for_key();
continue;
}
}
break;
}
return result;
}

canonical_decompiled_code:
__int64 func6()
{
__int64 v0; // rax
__int64 v1; // rbx
__int64 result; // rax
unsigned __int64 v3; // [rsp+0h] [rbp-28h] BYREF
char v4[25]; // [rsp+Fh] [rbp-19h] BYREF

v0 = urcu_game_config_update_begin();
if ( !v0 )
abort();
v1 = v0;
while ( 2 )
{
func3();
puts("[ root > configuration ]");
puts("Enter the config field you wish to update:");
puts(" key\tDescription");
puts("---------------------------------");
puts(" q\tCancel update");
puts(" x\tSave update and exit configuration menu");
printf(" i\tIsland size (%lu)\n", *(_QWORD *)v1);
printf(" d\tStep delay (%d ms)\n", *(unsigned int *)(v1 + 8));
printf(" g\tGerbil max birth stamina (%lu)\n", *(_QWORD *)(v1 + 16));
printf(" c\tCat max birth stamina (%lu)\n", *(_QWORD *)(v1 + 40));
printf(" s\tSnake max birth stamina (%lu)\n", *(_QWORD *)(v1 + 64));
result = func0(v4);
if ( (int)result >= 0 )
{
if ( verbose )
printf("[debug %s()@user-input.c:%d] User input: '%c'\n", "do_config", 184LL, (unsigned int)v4[0]);
switch ( v4[0] )
{
case 'c':
func5("cat stamina", (_QWORD *)(v1 + 40));
continue;
case 'd':
func5("step delay (ms)", &v3);
if ( v3 >= 0x80000000 )
{
puts("Error: delay specified is too large.");
func2();
}
else
{
*(_DWORD *)(v1 + 8) = v3;
}
continue;
case 'g':
func5("gerbil stamina", (_QWORD *)(v1 + 16));
continue;
case 'i':
func5("island size (increase only)", &v3);
if ( *(_QWORD *)v1 >= v3 )
puts("Error: Island size can only be increased.");
else
*(_QWORD *)v1 = v3;
continue;
case 'q':
puts("Configuration update cancelled.");
urcu_game_config_update_abort(v1);
result = func2();
break;
case 's':
func5("snake stamina", (_QWORD *)(v1 + 64));
continue;
case 'x':
puts("Configuration saved.");
urcu_game_config_update_end(v1);
result = func2();
break;
default:
printf("Unknown key: '%c'\n", (unsigned int)v4[0]);
func2();
continue;
}
}
break;
}
return result;
}

original_code:
static
void do_config(void)
{
 struct urcu_game_config *new_config;
 char key;
 int ret;
 new_config = urcu_game_config_update_begin();
 if (!new_config)
  abort();
 for (;;) {
  clear_screen();
  printf("[ root > configuration ]\n");
  printf("Enter the config field you wish to update:\n");
  printf(" key	Description\n");
  printf("---------------------------------\n");
  printf("  q	Cancel update\n");
  printf("  x	Save update and exit configuration menu\n");
  printf("  i	Island size (%" "l" "u" ")\n", new_config->island_size);
  printf("  d	Step delay (%d ms)\n", new_config->step_delay);
  printf("  g	Gerbil max birth stamina (%" "l" "u" ")\n",
    new_config->gerbil.max_birth_stamina);
  printf("  c	Cat max birth stamina (%" "l" "u" ")\n",
    new_config->cat.max_birth_stamina);
  printf("  s	Snake max birth stamina (%" "l" "u" ")\n",
    new_config->snake.max_birth_stamina);
  ret = getch(&key);
  if (ret < 0)
   goto end;
  do { if (verbose) printf("[debug %s()@" "user-input.c" ":%d] " "User input: \'%c\'" "\n", __func__, 184, key); } while (0);
  switch(key) {
  case 'x':
   printf("Configuration saved.\n");
   urcu_game_config_update_end(new_config);
   wait_for_key();
   goto end;
  case 'q':
   printf("Configuration update cancelled.\n");
   urcu_game_config_update_abort(new_config);
   wait_for_key();
   goto end;
  case 'i':
  {
   uint64_t new_size;
   get_config_entry_uint64("island size (increase only)",
    &new_size);
   if (new_size <= new_config->island_size) {
    printf("Error: Island size can only be increased.\n");
    break;
   }
   new_config->island_size = new_size;
   break;
  }
  case 'd':
  {
   uint64_t new_delay;
   get_config_entry_uint64("step delay (ms)",
    &new_delay);
   if (new_delay > 0x7fffffff) {
    printf("Error: delay specified is too large.\n");
    wait_for_key();
    break;
   }
   new_config->step_delay = (int) new_delay;
   break;
  }
  case 'g':
   get_config_entry_uint64("gerbil stamina",
    &new_config->gerbil.max_birth_stamina);
   break;
  case 'c':
   get_config_entry_uint64("cat stamina",
    &new_config->cat.max_birth_stamina);
   break;
  case 's':
   get_config_entry_uint64("snake stamina",
    &new_config->snake.max_birth_stamina);
   break;
  default:
   printf("Unknown key: \'%c\'\n", key);
   wait_for_key();
   break;
  }
 }
end:
 return;
}

canonical_original_code:
static void do_config()
{
 struct urcu_game_config *new_config;
 char key;
 int ret;
 new_config = urcu_game_config_update_begin();
 if (!new_config)
  abort();
 for (;;) {
  clear_screen();
  printf("[ root > configuration ]\n");
  printf("Enter the config field you wish to update:\n");
  printf(" key	Description\n");
  printf("---------------------------------\n");
  printf("  q	Cancel update\n");
  printf("  x	Save update and exit configuration menu\n");
  printf("  i	Island size (%" "l" "u" ")\n", new_config->island_size);
  printf("  d	Step delay (%d ms)\n", new_config->step_delay);
  printf("  g	Gerbil max birth stamina (%" "l" "u" ")\n",
    new_config->gerbil.max_birth_stamina);
  printf("  c	Cat max birth stamina (%" "l" "u" ")\n",
    new_config->cat.max_birth_stamina);
  printf("  s	Snake max birth stamina (%" "l" "u" ")\n",
    new_config->snake.max_birth_stamina);
  ret = getch(&key);
  if (ret < 0)
   goto end;
  do { if (verbose) printf("[debug %s()@" "user-input.c" ":%d] " "User input: \'%c\'" "\n", __func__, 184, key); } while (0);
  switch(key) {
  case 'x':
   printf("Configuration saved.\n");
   urcu_game_config_update_end(new_config);
   wait_for_key();
   goto end;
  case 'q':
   printf("Configuration update cancelled.\n");
   urcu_game_config_update_abort(new_config);
   wait_for_key();
   goto end;
  case 'i':
  {
   unsigned long new_size;
   get_config_entry_uint64("island size (increase only)",
    &new_size);
   if (new_size <= new_config->island_size) {
    printf("Error: Island size can only be increased.\n");
    break;
   }
   new_config->island_size = new_size;
   break;
  }
  case 'd':
  {
   unsigned long new_delay;
   get_config_entry_uint64("step delay (ms)",
    &new_delay);
   if (new_delay > 0x7fffffff) {
    printf("Error: delay specified is too large.\n");
    wait_for_key();
    break;
   }
   new_config->step_delay = (int) new_delay;
   break;
  }
  case 'g':
   get_config_entry_uint64("gerbil stamina",
    &new_config->gerbil.max_birth_stamina);
   break;
  case 'c':
   get_config_entry_uint64("cat stamina",
    &new_config->cat.max_birth_stamina);
   break;
  case 's':
   get_config_entry_uint64("snake stamina",
    &new_config->snake.max_birth_stamina);
   break;
  default:
   printf("Unknown key: \'%c\'\n", key);
   wait_for_key();
   break;
  }
 }
end:
 return;
}

variable_types: struct urcu_game_config { unsigned long island_size; unsigned int step_delay; struct animal_kind { unsigned long max_birth_stamina; unsigned long max_pregnant; enum animal_types { GERBIL=0, CAT=1, SNAKE=2 } animal; unsigned int diet; } gerbil; struct animal_kind cat; struct animal_kind snake; } *

variable_types: key char

variable_types: ret int

return_type: void

user_defined_types: struct urcu_game_config { unsigned long island_size; unsigned int step_delay; struct animal_kind gerbil; struct animal_kind cat; struct animal_kind snake; }

user_defined_types: struct animal_kind { unsigned long max_birth_stamina; unsigned long max_pregnant; enum animal_types animal; unsigned int diet; }


decompiled_code:
__int64 do_god()
{
__int64 result; // rax
__int64 v1; // [rsp+0h] [rbp-18h] BYREF
char v2[9]; // [rsp+Fh] [rbp-9h] BYREF

while ( 2 )
{
clear_screen();
puts("[ root > god ]");
puts("Enter the animal or vegetation you wish to modify:");
puts("Modifications take effect immediately.");
puts(" key\tDescription");
puts("---------------------------------");
puts(" x\tExit menu");
puts(" f\tNumber of flowers");
puts(" t\tNumber of trees");
puts(" g\tCreate gerbils");
puts(" c\tCreate cats");
puts(" s\tCreate snakes");
result = getch(v2);
if ( (int)result >= 0 )
{
if ( verbose )
printf("[debug %s()@user-input.c:%d] User input: '%c'\n", "do_god", 270LL, (unsigned int)v2[0]);
result = (unsigned __int8)(v2[0] - 99);
switch ( v2[0] )
{
case 'c':
get_config_entry_uint64("amount of cats to try creating", &v1);
create_animals(1LL, v1);
continue;
case 'f':
get_config_entry_uint64("number of flowers", &v1);
pthread_mutex_lock((pthread_mutex_t *)(unsigned int)((_DWORD)&vegetation + 16));
vegetation.__align = v1;
pthread_mutex_unlock((pthread_mutex_t *)(unsigned int)((_DWORD)&vegetation + 16));
continue;
case 'g':
get_config_entry_uint64("amount of gerbils to try creating", &v1);
create_animals(0LL, v1);
continue;
case 's':
get_config_entry_uint64("amount of snakes to try creating", &v1);
create_animals(2LL, v1);
continue;
case 't':
get_config_entry_uint64("number of trees", &v1);
pthread_mutex_lock((pthread_mutex_t *)(unsigned int)((_DWORD)&vegetation + 16));
*(&vegetation.__align + 1) = v1;
pthread_mutex_unlock((pthread_mutex_t *)(unsigned int)((_DWORD)&vegetation + 16));
continue;
case 'x':
return result;
default:
printf("Unknown key: '%c'\n", (unsigned int)v2[0]);
wait_for_key();
continue;
}
}
break;
}
return result;
}

canonical_decompiled_code:
__int64 func7()
{
__int64 result; // rax
__int64 v1; // [rsp+0h] [rbp-18h] BYREF
char v2[9]; // [rsp+Fh] [rbp-9h] BYREF

while ( 2 )
{
func3();
puts("[ root > god ]");
puts("Enter the animal or vegetation you wish to modify:");
puts("Modifications take effect immediately.");
puts(" key\tDescription");
puts("---------------------------------");
puts(" x\tExit menu");
puts(" f\tNumber of flowers");
puts(" t\tNumber of trees");
puts(" g\tCreate gerbils");
puts(" c\tCreate cats");
puts(" s\tCreate snakes");
result = func0(v2);
if ( (int)result >= 0 )
{
if ( verbose )
printf("[debug %s()@user-input.c:%d] User input: '%c'\n", "do_god", 270LL, (unsigned int)v2[0]);
result = (unsigned __int8)(v2[0] - 99);
switch ( v2[0] )
{
case 'c':
func5("amount of cats to try creating", &v1);
create_animals(1LL, v1);
continue;
case 'f':
func5("number of flowers", &v1);
pthread_mutex_lock((pthread_mutex_t *)(unsigned int)((_DWORD)&vegetation + 16));
vegetation.__align = v1;
pthread_mutex_unlock((pthread_mutex_t *)(unsigned int)((_DWORD)&vegetation + 16));
continue;
case 'g':
func5("amount of gerbils to try creating", &v1);
create_animals(0LL, v1);
continue;
case 's':
func5("amount of snakes to try creating", &v1);
create_animals(2LL, v1);
continue;
case 't':
func5("number of trees", &v1);
pthread_mutex_lock((pthread_mutex_t *)(unsigned int)((_DWORD)&vegetation + 16));
*(&vegetation.__align + 1) = v1;
pthread_mutex_unlock((pthread_mutex_t *)(unsigned int)((_DWORD)&vegetation + 16));
continue;
case 'x':
return result;
default:
printf("Unknown key: '%c'\n", (unsigned int)v2[0]);
func2();
continue;
}
}
break;
}
return result;
}

original_code:
static
void do_god(void)
{
 char key;
 int ret;
 for (;;) {
  clear_screen();
  printf("[ root > god ]\n");
  printf("Enter the animal or vegetation you wish to modify:\n");
  printf("Modifications take effect immediately.\n");
  printf(" key	Description\n");
  printf("---------------------------------\n");
  printf("  x	Exit menu\n");
  printf("  f	Number of flowers\n");
  printf("  t	Number of trees\n");
  printf("  g	Create gerbils\n");
  printf("  c	Create cats\n");
  printf("  s	Create snakes\n");
  ret = getch(&key);
  if (ret < 0)
   goto end;
  do { if (verbose) printf("[debug %s()@" "user-input.c" ":%d] " "User input: \'%c\'" "\n", __func__, 270, key); } while (0);
  switch(key) {
  case 'x':
   goto end;
  case 'f':
  {
   uint64_t value;
   get_config_entry_uint64("number of flowers",
    &value);
   pthread_mutex_lock(&vegetation.lock);
   vegetation.flowers = value;
   pthread_mutex_unlock(&vegetation.lock);
   break;
  }
  case 't':
  {
   uint64_t value;
   get_config_entry_uint64("number of trees",
    &value);
   pthread_mutex_lock(&vegetation.lock);
   vegetation.trees = value;
   pthread_mutex_unlock(&vegetation.lock);
   break;
  }
  case 'g':
  {
   uint64_t value;
   get_config_entry_uint64("amount of gerbils to try creating",
    &value);
   create_animals(GERBIL, value);
   break;
  }
  case 'c':
  {
   uint64_t value;
   get_config_entry_uint64("amount of cats to try creating",
    &value);
   create_animals(CAT, value);
   break;
  }
  case 's':
  {
   uint64_t value;
   get_config_entry_uint64("amount of snakes to try creating",
    &value);
   create_animals(SNAKE, value);
   break;
  }
  default:
   printf("Unknown key: \'%c\'\n", key);
   wait_for_key();
   break;
  }
 }
end:
 return;
}

canonical_original_code:
static void do_god()
{
 char key;
 int ret;
 for (;;) {
  clear_screen();
  printf("[ root > god ]\n");
  printf("Enter the animal or vegetation you wish to modify:\n");
  printf("Modifications take effect immediately.\n");
  printf(" key	Description\n");
  printf("---------------------------------\n");
  printf("  x	Exit menu\n");
  printf("  f	Number of flowers\n");
  printf("  t	Number of trees\n");
  printf("  g	Create gerbils\n");
  printf("  c	Create cats\n");
  printf("  s	Create snakes\n");
  ret = getch(&key);
  if (ret < 0)
   goto end;
  do { if (verbose) printf("[debug %s()@" "user-input.c" ":%d] " "User input: \'%c\'" "\n", __func__, 270, key); } while (0);
  switch(key) {
  case 'x':
   goto end;
  case 'f':
  {
   unsigned long value;
   get_config_entry_uint64("number of flowers",
    &value);
   pthread_mutex_lock(&vegetation.lock);
   vegetation.flowers = value;
   pthread_mutex_unlock(&vegetation.lock);
   break;
  }
  case 't':
  {
   unsigned long value;
   get_config_entry_uint64("number of trees",
    &value);
   pthread_mutex_lock(&vegetation.lock);
   vegetation.trees = value;
   pthread_mutex_unlock(&vegetation.lock);
   break;
  }
  case 'g':
  {
   unsigned long value;
   get_config_entry_uint64("amount of gerbils to try creating",
    &value);
   create_animals(GERBIL, value);
   break;
  }
  case 'c':
  {
   unsigned long value;
   get_config_entry_uint64("amount of cats to try creating",
    &value);
   create_animals(CAT, value);
   break;
  }
  case 's':
  {
   unsigned long value;
   get_config_entry_uint64("amount of snakes to try creating",
    &value);
   create_animals(SNAKE, value);
   break;
  }
  default:
   printf("Unknown key: \'%c\'\n", key);
   wait_for_key();
   break;
  }
 }
end:
 return;
}

variable_types:
value
unsigned long


decompiled_code:
__int64 create_input_thread()
{
if ( pthread_create(&input_thread_id, 0LL, input_thread_fct, 0LL) )
abort();
return 0LL;
}

canonical_decompiled_code:
__int64 func10()
{
if ( pthread_create(&input_thread_id, 0LL, input_thread_fct, 0LL) )
abort();
return 0LL;
}

original_code:
int create_input_thread(void)
{
 int err;
 err = pthread_create(&input_thread_id, ((void *)0),
  input_thread_fct, ((void *)0));
 if (err)
  abort();
 return 0;
}

canonical_original_code:
int create_input_thread()
{
 int err;
 err = pthread_create(&input_thread_id, ((void *)0),
  input_thread_fct, ((void *)0));
 if (err)
  abort();
 return 0;
}

variable_types: err int

return_type: int


decompiled_code:
__int64 join_input_thread()
{
void *thread_return; // [rsp+8h] [rbp-10h] BYREF

if ( pthread_join(input_thread_id, &thread_return) )
abort();
return 0LL;
}

canonical_decompiled_code:
__int64 func11()
{
void *thread_return; // [rsp+8h] [rbp-10h] BYREF

if ( pthread_join(input_thread_id, &thread_return) )
abort();
return 0LL;
}

original_code:
int join_input_thread(void)
{
 int ret;
 void *tret;
 ret = pthread_join(input_thread_id, &tret);
 if (ret)
  abort();
 return 0;
}

canonical_original_code:
int join_input_thread()
{
 int ret;
 void *tret;
 ret = pthread_join(input_thread_id, &tret);
 if (ret)
  abort();
 return 0;
}

variable_types:
tret
void *


decompiled_code:
int __fastcall show_usage(__int64 a1, const char **a2)
{
printf("Usage: %s <OPTIONS>\n", *a2);
puts("OPTIONS:");
puts(" [-v] Verbose output.");
puts(" [-c] Disable clear screen.");
puts(" [-w nr_threads] Number of worker threads.");
puts(" [-h] Show this help.");
return putchar(10);
}

canonical_decompiled_code:
int __fastcall func1(__int64 a1, const char **a2)
{
printf("Usage: %s <OPTIONS>\n", *a2);
puts("OPTIONS:");
puts(" [-v] Verbose output.");
puts(" [-c] Disable clear screen.");
puts(" [-w nr_threads] Number of worker threads.");
puts(" [-h] Show this help.");
return putchar(10);
}

original_code:
void show_usage(int argc, char **argv)
{
 printf("Usage: %s <OPTIONS>\n", argv[0]);
 printf("OPTIONS:\n");
        printf("        [-v]             Verbose output.\n");
        printf("        [-c]             Disable clear screen.\n");
        printf("        [-w nr_threads]  Number of worker threads.\n");
 printf("        [-h]             Show this help.\n");
 printf("\n");
}

variable_types: argc int

variable_types:
argv
char **


decompiled_code:
__int64 __fastcall parse_args(int a1, const char **a2)
{
int i; // ebx
unsigned int v4; // ebx
__int64 v5; // rdx
const char *v6; // rsi
char v7; // al

if ( a1 <= 1 )
return 0;
for ( i = 1; i < a1; ++i )
{
v5 = i;
v6 = a2[v5];
if ( *v6 != 45 )
{
v4 = -1;
goto LABEL_15;
}
v7 = v6[1];
if ( v7 == 118 )
{
verbose = 1;
}
else if ( v7 > 118 )
{
if ( v7 != 119 )
goto LABEL_18;
if ( ++i >= a1 )
{
v4 = -1;
goto LABEL_15;
}
nr_worker_threads = atol(a2[v5 + 1]);
if ( nr_worker_threads <= 0 )
{
puts("Please specify a positive and non-zero number of worker threads.");
v4 = -1;
goto LABEL_15;
}
}
else
{
if ( v7 != 99 )
{
if ( v7 == 104 )
{
v4 = 1;
}
else
{
LABEL_18:
printf("Unrecognised option %s\n", v6);
v4 = -1;
}
LABEL_15:
show_usage((unsigned int)a1, a2);
return v4;
}
clear_screen_enable = 0;
}
}
return 0;
}

canonical_decompiled_code:
__int64 __fastcall func2(int a1, const char **a2)
{
int i; // ebx
unsigned int v4; // ebx
__int64 v5; // rdx
const char *v6; // rsi
char v7; // al

if ( a1 <= 1 )
return 0;
for ( i = 1; i < a1; ++i )
{
v5 = i;
v6 = a2[v5];
if ( *v6 != 45 )
{
v4 = -1;
goto LABEL_15;
}
v7 = v6[1];
if ( v7 == 118 )
{
verbose = 1;
}
else if ( v7 > 118 )
{
if ( v7 != 119 )
goto LABEL_18;
if ( ++i >= a1 )
{
v4 = -1;
goto LABEL_15;
}
nr_worker_threads = atol(a2[v5 + 1]);
if ( nr_worker_threads <= 0 )
{
puts("Please specify a positive and non-zero number of worker threads.");
v4 = -1;
goto LABEL_15;
}
}
else
{
if ( v7 != 99 )
{
if ( v7 == 104 )
{
v4 = 1;
}
else
{
LABEL_18:
printf("Unrecognised option %s\n", v6);
v4 = -1;
}
LABEL_15:
func1((unsigned int)a1, a2);
return v4;
}
clear_screen_enable = 0;
}
}
return 0;
}

original_code:
int parse_args(int argc, char **argv)
{
 int i, err = 0;
 for (i = 1; i < argc; i++) {
  if (argv[i][0] != '-') {
   err = -1;
   goto end;
  }
  switch(argv[i][1]) {
  case 'w':
   if (argc < i + 2) {
    err = -1;
    goto end;
   }
   nr_worker_threads = atol(argv[++i]);
   if (nr_worker_threads <= 0) {
    printf("Please specify a positive and non-zero number of worker threads.\n");
    err = -1;
    goto end;
   }
   break;
  case 'v':
   verbose = 1;
   break;
  case 'c':
   clear_screen_enable = 0;
   break;
  case 'h':
   err = 1;
   goto end;
  default:
   printf("Unrecognised option %s\n", argv[i]);
   err = -1;
   goto end;
  }
 }
end:
 if (err)
  show_usage(argc, argv);
 return err;
}

canonical_original_code:
int parse_args(int argc, char **argv)
{
 int i; int err = 0;
 for (i = 1; i < argc; i++) {
  if (argv[i][0] != '-') {
   err = -1;
   goto end;
  }
  switch(argv[i][1]) {
  case 'w':
   if (argc < i + 2) {
    err = -1;
    goto end;
   }
   nr_worker_threads = atol(argv[++i]);
   if (nr_worker_threads <= 0) {
    printf("Please specify a positive and non-zero number of worker threads.\n");
    err = -1;
    goto end;
   }
   break;
  case 'v':
   verbose = 1;
   break;
  case 'c':
   clear_screen_enable = 0;
   break;
  case 'h':
   err = 1;
   goto end;
  default:
   printf("Unrecognised option %s\n", argv[i]);
   err = -1;
   goto end;
  }
 }
end:
 if (err)
  show_usage(argc, argv);
 return err;
}

variable_types: i int


main

canonical_name: main

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

rcu_register_thread_memb(argc, argv, envp);
v3 = parse_args(argc, argv);
if ( v3 >= 0 )
{
if ( v3 > 0 )
{
rcu_unregister_thread_memb();
goto LABEL_10;
}
puts("Welcome to the Island of RCU\n");
printf("Spawning %ld worker threads.\n", nr_worker_threads);
init_game_config();
live_animals[4] = time(0LL);
v4 = cds_lfht_new(4096LL, 1LL, 0LL, 3LL, 0LL);
live_animals[3] = v4;
if ( !v4 )
abort();
live_animals[0] = cds_lfht_new(4096LL, 1LL, 0LL, 3LL, 0LL);
if ( !live_animals[0] )
abort();
v5 = cds_lfht_new(4096LL, 1LL, 0LL, 3LL, 0LL);
live_animals[1] = v5;
if ( !v5 )
abort();
v6 = cds_lfht_new(4096LL, 1LL, 0LL, 3LL, 0LL);
live_animals[2] = v6;
if ( !v6 )
abort();
if ( !(unsigned int)create_worker_threads(nr_worker_threads)
&& !(unsigned int)create_input_thread()
&& !(unsigned int)create_output_thread()
&& !(unsigned int)create_dispatch_thread()
&& !(unsigned int)join_dispatch_thread()
&& !(unsigned int)join_output_thread()
&& !(unsigned int)join_input_thread()
&& !(unsigned int)join_worker_threads() )
{
apocalypse();
if ( !(unsigned int)cds_lfht_destroy(live_animals[2], 0LL)
&& !(unsigned int)cds_lfht_destroy(live_animals[1], 0LL)
&& !(unsigned int)cds_lfht_destroy(live_animals[0], 0LL)
&& !(unsigned int)cds_lfht_destroy(live_animals[3], 0LL) )
{
rcu_barrier_memb();
puts("Goodbye!");
rcu_unregister_thread_memb();
LABEL_10:
exit(0);
}
}
}
rcu_unregister_thread_memb();
fwrite("Something went wrong!\n", 1uLL, 0x16uLL, stderr);
exit(1);
}

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

rcu_register_thread_memb(argc, argv, envp);
v3 = func2(argc, argv);
if ( v3 >= 0 )
{
if ( v3 > 0 )
{
rcu_unregister_thread_memb();
goto LABEL_10;
}
puts("Welcome to the Island of RCU\n");
printf("Spawning %ld worker threads.\n", nr_worker_threads);
init_game_config();
live_animals[4] = time(0LL);
v4 = func0(4096LL, 1LL, 0LL, 3LL, 0LL);
live_animals[3] = v4;
if ( !v4 )
abort();
live_animals[0] = func0(4096LL, 1LL, 0LL, 3LL, 0LL);
if ( !live_animals[0] )
abort();
v5 = func0(4096LL, 1LL, 0LL, 3LL, 0LL);
live_animals[1] = v5;
if ( !v5 )
abort();
v6 = func0(4096LL, 1LL, 0LL, 3LL, 0LL);
live_animals[2] = v6;
if ( !v6 )
abort();
if ( !(unsigned int)create_worker_threads(nr_worker_threads)
&& !(unsigned int)create_input_thread()
&& !(unsigned int)create_output_thread()
&& !(unsigned int)create_dispatch_thread()
&& !(unsigned int)join_dispatch_thread()
&& !(unsigned int)join_output_thread()
&& !(unsigned int)join_input_thread()
&& !(unsigned int)join_worker_threads() )
{
apocalypse();
if ( !(unsigned int)cds_lfht_destroy(live_animals[2], 0LL)
&& !(unsigned int)cds_lfht_destroy(live_animals[1], 0LL)
&& !(unsigned int)cds_lfht_destroy(live_animals[0], 0LL)
&& !(unsigned int)cds_lfht_destroy(live_animals[3], 0LL) )
{
rcu_barrier_memb();
puts("Goodbye!");
rcu_unregister_thread_memb();
LABEL_10:
exit(0);
}
}
}
rcu_unregister_thread_memb();
fwrite("Something went wrong!\n", 1uLL, 0x16uLL, stderr);
exit(1);
}

original_code:
int main(int argc, char **argv)
{
 int err;
 rcu_register_thread_memb();
 err = parse_args(argc, argv);
 if (err < 0)
  goto end;
 else if (err > 0) {
  err = 0;
  goto end;
 }
 printf("Welcome to the Island of RCU\n\n");
 printf("Spawning %ld worker threads.\n",
  nr_worker_threads);
 init_game_config();
 live_animals.ht_seed = time(((void *)0));
 live_animals.all = cds_lfht_new(4096, 1, 0,
  CDS_LFHT_AUTO_RESIZE | CDS_LFHT_ACCOUNTING, ((void *)0));
 if (!live_animals.all)
  abort();
 live_animals.gerbil = cds_lfht_new(4096, 1, 0,
  CDS_LFHT_AUTO_RESIZE | CDS_LFHT_ACCOUNTING, ((void *)0));
 if (!live_animals.gerbil)
  abort();
 live_animals.cat = cds_lfht_new(4096, 1, 0,
  CDS_LFHT_AUTO_RESIZE | CDS_LFHT_ACCOUNTING, ((void *)0));
 if (!live_animals.cat)
  abort();
 live_animals.snake = cds_lfht_new(4096, 1, 0,
  CDS_LFHT_AUTO_RESIZE | CDS_LFHT_ACCOUNTING, ((void *)0));
 if (!live_animals.snake)
  abort();
 err = create_worker_threads(nr_worker_threads);
 if (err)
  goto end;
 err = create_input_thread();
 if (err)
  goto end;
 err = create_output_thread();
 if (err)
  goto end;
 err = create_dispatch_thread();
 if (err)
  goto end;
 err = join_dispatch_thread();
 if (err)
  goto end;
 err = join_output_thread();
 if (err)
  goto end;
 err = join_input_thread();
 if (err)
  goto end;
 err = join_worker_threads();
 if (err)
  goto end;
 apocalypse();
 err = cds_lfht_destroy(live_animals.snake, ((void *)0));
 if (err)
  goto end;
 err = cds_lfht_destroy(live_animals.cat, ((void *)0));
 if (err)
  goto end;
 err = cds_lfht_destroy(live_animals.gerbil, ((void *)0));
 if (err)
  goto end;
 err = cds_lfht_destroy(live_animals.all, ((void *)0));
 if (err)
  goto end;
 rcu_barrier_memb();
 printf("Goodbye!\n");
end:
 rcu_unregister_thread_memb();
 if (err) {
  fprintf(stderr, "Something went wrong!\n");
  exit(1);
 } else {
  exit(0);
 }
}


decompiled_code:
__int64 __fastcall do_work(__int64 a1)
{
unsigned int v1; // er13
__int64 v2; // rbp
__int64 v3; // rax
__int64 v4; // r12

v1 = *(_DWORD *)(a1 + 24);
if ( v1 )
return 1;
if ( verbose )
printf(
"[debug %s()@worker-thread.c:%d] do work: key1 %lu, key2 %lu\n",
"do_work",
49LL,
*(_QWORD *)(a1 + 8),
*(_QWORD *)(a1 + 16));
rcu_read_lock_memb();
v2 = find_animal(*(_QWORD *)(a1 + 8));
v3 = find_animal(*(_QWORD *)(a1 + 16));
v4 = v3;
if ( v2 )
goto LABEL_5;
if ( v3 )
{
v2 = v3;
v4 = 0LL;
LABEL_5:
if ( (unsigned int)try_birth(v2, *(_QWORD *)(a1 + 16), 0LL) && verbose )
printf("[debug %s()@worker-thread.c:%d] birth success\n", "do_work", 73LL);
if ( (unsigned int)try_eat(v2, v4) && verbose )
printf("[debug %s()@worker-thread.c:%d] eat success\n", "do_work", 75LL);
if ( (unsigned int)try_mate(v2, v4) && verbose )
printf("[debug %s()@worker-thread.c:%d] mate success\n", "do_work", 77LL);
}
rcu_read_unlock_memb();
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
unsigned int v1; // er13
__int64 v2; // rbp
__int64 v3; // rax
__int64 v4; // r12

v1 = *(_DWORD *)(a1 + 24);
if ( v1 )
return 1;
if ( verbose )
printf(
"[debug %s()@worker-thread.c:%d] do work: key1 %lu, key2 %lu\n",
"do_work",
49LL,
*(_QWORD *)(a1 + 8),
*(_QWORD *)(a1 + 16));
rcu_read_lock_memb();
v2 = find_animal(*(_QWORD *)(a1 + 8));
v3 = find_animal(*(_QWORD *)(a1 + 16));
v4 = v3;
if ( v2 )
goto LABEL_5;
if ( v3 )
{
v2 = v3;
v4 = 0LL;
LABEL_5:
if ( (unsigned int)try_birth(v2, *(_QWORD *)(a1 + 16), 0LL) && verbose )
printf("[debug %s()@worker-thread.c:%d] birth success\n", "do_work", 73LL);
if ( (unsigned int)try_eat(v2, v4) && verbose )
printf("[debug %s()@worker-thread.c:%d] eat success\n", "do_work", 75LL);
if ( (unsigned int)try_mate(v2, v4) && verbose )
printf("[debug %s()@worker-thread.c:%d] mate success\n", "do_work", 77LL);
}
rcu_read_unlock_memb();
return v1;
}

original_code:
static
int do_work(struct urcu_game_work *work)
{
 struct animal *first, *second;
 if (work->exit_thread)
  return 1;
 do { if (verbose) printf("[debug %s()@" "worker-thread.c" ":%d] " "do work: key1 %" "l" "u" ", key2 %" "l" "u" "\n", __func__, 49, work->first_key, work->second_key); } while (0);
 rcu_read_lock_memb();
 first = find_animal(work->first_key);
 second = find_animal(work->second_key);
 if (!first) {
  first = second;
  if (!first)
   goto end;
  if (first == second) {
   second = ((void *)0);
  }
 }
 if (try_birth(first, work->second_key, 0))
  do { if (verbose) printf("[debug %s()@" "worker-thread.c" ":%d] " "birth success" "\n", __func__, 73); } while (0);
 if (try_eat(first, second))
  do { if (verbose) printf("[debug %s()@" "worker-thread.c" ":%d] " "eat success" "\n", __func__, 75); } while (0);
 if (try_mate(first, second))
  do { if (verbose) printf("[debug %s()@" "worker-thread.c" ":%d] " "mate success" "\n", __func__, 77); } while (0);
end:
 rcu_read_unlock_memb();
 return 0;
}

canonical_original_code:
static int do_work(struct urcu_game_work *work)
{
 struct animal *first; struct animal *second;
 if (work->exit_thread)
  return 1;
 do { if (verbose) printf("[debug %s()@" "worker-thread.c" ":%d] " "do work: key1 %" "l" "u" ", key2 %" "l" "u" "\n", __func__, 49, work->first_key, work->second_key); } while (0);
 rcu_read_lock_memb();
 first = find_animal(work->first_key);
 second = find_animal(work->second_key);
 if (!first) {
  first = second;
  if (!first)
   goto end;
  if (first == second) {
   second = ((void *)0);
  }
 }
 if (try_birth(first, work->second_key, 0))
  do { if (verbose) printf("[debug %s()@" "worker-thread.c" ":%d] " "birth success" "\n", __func__, 73); } while (0);
 if (try_eat(first, second))
  do { if (verbose) printf("[debug %s()@" "worker-thread.c" ":%d] " "eat success" "\n", __func__, 75); } while (0);
 if (try_mate(first, second))
  do { if (verbose) printf("[debug %s()@" "worker-thread.c" ":%d] " "mate success" "\n", __func__, 77); } while (0);
end:
 rcu_read_unlock_memb();
 return 0;
}

variable_types: struct urcu_game_work { struct cds_wfcq_node { struct cds_wfcq_node *next; } q_node; unsigned long first_key; unsigned long second_key; int exit_thread; } *

variable_types: struct animal { struct animal_kind { unsigned long max_birth_stamina; unsigned long max_pregnant; enum animal_types { GERBIL=0, CAT=1, SNAKE=2 } animal; unsigned int diet; } kind; enum animal_sex { ANIMAL_MALE=0, ANIMAL_FEMALE=1 } animal_sex; unsigned long key; unsigned long stamina; unsigned long nr_pregnant; union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } lock; struct cds_lfht_node { struct cds_lfht_node *next; unsigned long reverse_hash; } kind_node; struct cds_lfht_node all_node; struct rcu_head { struct cds_wfcq_node { struct cds_wfcq_node *next; } next; void (*func)(struct rcu_head *head); } rcu_head; } *

user_defined_types: struct urcu_game_work { struct cds_wfcq_node q_node; unsigned long first_key; unsigned long second_key; int exit_thread; }

user_defined_types: struct animal { struct animal_kind kind; enum animal_sex animal_sex; unsigned long key; unsigned long stamina; unsigned long nr_pregnant; union pthread_mutex_t lock; struct cds_lfht_node kind_node; struct cds_lfht_node all_node; struct rcu_head rcu_head; }

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

user_defined_types: struct rcu_head { struct cds_wfcq_node next; void (*func)(struct rcu_head *head); }

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


decompiled_code:
__int64 get_nr_worker_threads()
{
return nr_worker_threads;
}

canonical_decompiled_code:
__int64 func2()
{
return nr_worker_threads;
}

original_code:
unsigned long get_nr_worker_threads(void)
{
 return nr_worker_threads;
}

canonical_original_code:
unsigned long get_nr_worker_threads()
{
 return nr_worker_threads;
}

return_type: unsigned long


decompiled_code:
__int64 __fastcall create_worker_threads(size_t a1)
{
pthread_t i; // rbp
pthread_t *v2; // rbx

worker_threads = calloc(a1, 0x80uLL);
if ( !worker_threads )
return 0xFFFFFFFFLL;
if ( a1 )
{
for ( i = 0LL; i != a1; ++i )
{
v2 = (pthread_t *)((char *)worker_threads + 128 * i);
cds_wfcq_init(v2 + 1, v2);
v2[8] = i;
if ( pthread_create(v2 + 9, 0LL, worker_thread_fct, v2) )
abort();
}
}
nr_worker_threads = a1;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(size_t a1)
{
pthread_t i; // rbp
pthread_t *v2; // rbx

worker_threads = calloc(a1, 0x80uLL);
if ( !worker_threads )
return 0xFFFFFFFFLL;
if ( a1 )
{
for ( i = 0LL; i != a1; ++i )
{
v2 = (pthread_t *)((char *)worker_threads + 128 * i);
cds_wfcq_init(v2 + 1, v2);
v2[8] = i;
if ( pthread_create(v2 + 9, 0LL, worker_thread_fct, v2) )
abort();
}
}
nr_worker_threads = a1;
return 0LL;
}

original_code:
int create_worker_threads(unsigned long nr_threads)
{
 unsigned long i;
 int err;
 worker_threads = calloc(nr_threads, sizeof(*worker_threads));
 if (!worker_threads)
  return -1;
 for (i = 0; i < nr_threads; i++) {
  struct worker_thread *worker;
  worker = &worker_threads[i];
  cds_wfcq_init(&worker->q_head, &worker->q_tail);
  worker->id = i;
  err = pthread_create(&worker->thread_id, ((void *)0),
   worker_thread_fct, worker);
  if (err)
   abort();
 }
 nr_worker_threads = nr_threads;
 return 0;
}

variable_types:
i
unsigned long

variable_types: struct worker_thread { struct cds_wfcq_tail { struct cds_wfcq_node { struct cds_wfcq_node *next; } *p; } q_tail; struct cds_wfcq_head { struct cds_wfcq_node node; union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } lock; } q_head; unsigned long q_len; unsigned long id; unsigned long thread_id; } *

user_defined_types: struct worker_thread { struct cds_wfcq_tail q_tail; struct cds_wfcq_head q_head; unsigned long q_len; unsigned long id; unsigned long thread_id; }

user_defined_types: struct cds_wfcq_tail { struct cds_wfcq_node *p; }

user_defined_types: struct cds_wfcq_head { struct cds_wfcq_node node; union pthread_mutex_t lock; }


decompiled_code:
__int64 join_worker_threads()
{
unsigned __int64 v0; // rbx
void *thread_return; // [rsp+8h] [rbp-10h] BYREF

if ( nr_worker_threads )
{
v0 = 0LL;
do
{
if ( pthread_join(*((_QWORD *)worker_threads + 16 * v0 + 9), &thread_return) )
abort();
++v0;
}
while ( nr_worker_threads > v0 );
}
free(worker_threads);
return 0LL;
}

canonical_decompiled_code:
__int64 func4()
{
unsigned __int64 v0; // rbx
void *thread_return; // [rsp+8h] [rbp-10h] BYREF

if ( nr_worker_threads )
{
v0 = 0LL;
do
{
if ( pthread_join(*((_QWORD *)worker_threads + 16 * v0 + 9), &thread_return) )
abort();
++v0;
}
while ( nr_worker_threads > v0 );
}
free(worker_threads);
return 0LL;
}

original_code:
int join_worker_threads(void)
{
 unsigned long i;
 for (i = 0; i < nr_worker_threads; i++) {
  struct worker_thread *worker;
  void *tret;
  int ret;
  worker = &worker_threads[i];
  ret = pthread_join(worker->thread_id, &tret);
  if (ret)
   abort();
 }
 free(worker_threads);
 return 0;
}

canonical_original_code:
int join_worker_threads()
{
 unsigned long i;
 for (i = 0; i < nr_worker_threads; i++) {
  struct worker_thread *worker;
  void *tret;
  int ret;
  worker = &worker_threads[i];
  ret = pthread_join(worker->thread_id, &tret);
  if (ret)
   abort();
 }
 free(worker_threads);
 return 0;
}

user_defined_types: struct cds_wfcq_node { struct cds_wfcq_node *next; }

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


decompiled_code:
__int64 __fastcall stop_thread(__int64 a1)
{
_DWORD *v1; // rax
__int64 result; // rax

v1 = calloc(1uLL, 0x80uLL);
if ( !v1 )
abort();
v1[6] = 1;
result = enqueue_work(*(_QWORD *)(a1 + 64), (__int64)v1);
if ( (_DWORD)result )
abort();
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1)
{
_DWORD *v1; // rax
__int64 result; // rax

v1 = calloc(1uLL, 0x80uLL);
if ( !v1 )
abort();
v1[6] = 1;
result = func5(*(_QWORD *)(a1 + 64), (__int64)v1);
if ( (_DWORD)result )
abort();
return result;
}

original_code:
static
void stop_thread(struct worker_thread *thread)
{
 struct urcu_game_work *work;
 int ret;
 work = calloc(1, sizeof(*work));
 if (!work)
  abort();
 work->exit_thread = 1;
 ret = enqueue_work(thread->id, work);
 if (ret)
  abort();
}


decompiled_code:
__int64 stop_worker_threads()
{
unsigned __int64 v0; // rbx
__int64 result; // rax

if ( nr_worker_threads )
{
v0 = 0LL;
do
result = stop_thread((__int64)worker_threads + 128 * v0++);
while ( nr_worker_threads > v0 );
}
return result;
}

canonical_decompiled_code:
__int64 func7()
{
unsigned __int64 v0; // rbx
__int64 result; // rax

if ( nr_worker_threads )
{
v0 = 0LL;
do
result = func6((__int64)worker_threads + 128 * v0++);
while ( nr_worker_threads > v0 );
}
return result;
}

original_code:
void stop_worker_threads(void)
{
 unsigned long i;
 for (i = 0; i < nr_worker_threads; i++) {
  struct worker_thread *worker;
  worker = &worker_threads[i];
  stop_thread(worker);
 }
}

canonical_original_code:
void stop_worker_threads()
{
 unsigned long i;
 for (i = 0; i < nr_worker_threads; i++) {
  struct worker_thread *worker;
  worker = &worker_threads[i];
  stop_thread(worker);
 }
}


decompiled_code:
__m128i *urcu_game_config_update_begin()
{
__m128i *v0; // rbx
const __m128i *v1; // rax

v0 = (__m128i *)malloc(0x58uLL);
if ( v0 )
{
pthread_mutex_lock(&config_mutex);
v1 = (const __m128i *)current_config;
if ( current_config )
{
*v0 = _mm_loadu_si128((const __m128i *)current_config);
v0[1] = _mm_loadu_si128(v1 + 1);
v0[2] = _mm_loadu_si128(v1 + 2);
v0[3] = _mm_loadu_si128(v1 + 3);
v0[4] = _mm_loadu_si128(v1 + 4);
v0[5].m128i_i64[0] = v1[5].m128i_i64[0];
}
else
{
memset(v0, 0, 0x58uLL);
}
}
return v0;
}

original_code:
struct urcu_game_config *urcu_game_config_update_begin(void)
{
 struct urcu_game_config *new_config;
 new_config = malloc(sizeof(*new_config));
 if (!new_config) {
  return ((void *)0);
 }
 pthread_mutex_lock(&config_mutex);
 if (current_config)
  memcpy(new_config, current_config, sizeof(*new_config));
 else
  memset(new_config, 0, sizeof(*new_config));
 return new_config;
}

canonical_original_code:
struct urcu_game_config *urcu_game_config_update_begin()
{
 struct urcu_game_config *new_config;
 new_config = malloc(sizeof(*new_config));
 if (!new_config) {
  return ((void *)0);
 }
 pthread_mutex_lock(&config_mutex);
 if (current_config)
  memcpy(new_config, current_config, sizeof(*new_config));
 else
  memset(new_config, 0, sizeof(*new_config));
 return new_config;
}

return_type: struct urcu_game_config { unsigned long island_size; unsigned int step_delay; struct animal_kind { unsigned long max_birth_stamina; unsigned long max_pregnant; enum animal_types { GERBIL=0, CAT=1, SNAKE=2 } animal; unsigned int diet; } gerbil; struct animal_kind cat; struct animal_kind snake; } *


decompiled_code:
void __fastcall urcu_game_config_update_end(__int64 a1)
{
void *v1; // rbx

v1 = current_config;
rcu_set_pointer_sym(&current_config, a1);
pthread_mutex_unlock(&config_mutex);
if ( v1 )
{
synchronize_rcu_memb();
free(v1);
}
}

canonical_decompiled_code:
void __fastcall func2(__int64 a1)
{
void *v1; // rbx

v1 = current_config;
rcu_set_pointer_sym(&current_config, a1);
pthread_mutex_unlock(&config_mutex);
if ( v1 )
{
synchronize_rcu_memb();
free(v1);
}
}

original_code:
void urcu_game_config_update_end(struct urcu_game_config *new_config)
{
 struct urcu_game_config *old_config;
 old_config = current_config;
 do { __typeof__(*(&current_config)) _________pv = (new_config); (void) rcu_set_pointer_sym(((void **) (&current_config)), _________pv); } while (0);
 pthread_mutex_unlock(&config_mutex);
 if (old_config) {
  synchronize_rcu_memb();
  free(old_config);
 }
}

user_defined_types: enum animal_types { GERBIL=0, CAT=1, SNAKE=2 }


decompiled_code:
void __fastcall urcu_game_config_update_abort(void *ptr)
{
pthread_mutex_unlock(&config_mutex);
free(ptr);
}

canonical_decompiled_code:
void __fastcall func3(void *ptr)
{
pthread_mutex_unlock(&config_mutex);
free(ptr);
}

original_code:
void urcu_game_config_update_abort(struct urcu_game_config *new_config)
{
 pthread_mutex_unlock(&config_mutex);
 free(new_config);
}


original_code:
void init_game_config(void)
{
 struct urcu_game_config *new_config;
 new_config = urcu_game_config_update_begin();
 new_config->island_size = 2 * (1000 + 200);
 new_config->step_delay = 1000;
 new_config->gerbil.max_birth_stamina =
   70;
 new_config->gerbil.animal = GERBIL;
 new_config->gerbil.diet = DIET_FLOWERS | DIET_TREES;
 new_config->gerbil.max_pregnant = 10;
 new_config->cat.max_birth_stamina =
   80;
 new_config->cat.animal = CAT;
 new_config->cat.diet = DIET_GERBIL | DIET_FLOWERS;
 new_config->cat.max_pregnant = 4;
 new_config->snake.max_birth_stamina =
   30;
 new_config->snake.animal = SNAKE;
 new_config->snake.diet = DIET_GERBIL | DIET_CAT;
 new_config->snake.max_pregnant = 1;
 urcu_game_config_update_end(new_config);
}

canonical_original_code:
void init_game_config()
{
 struct urcu_game_config *new_config;
 new_config = urcu_game_config_update_begin();
 new_config->island_size = 2 * (1000 + 200);
 new_config->step_delay = 1000;
 new_config->gerbil.max_birth_stamina =
   70;
 new_config->gerbil.animal = GERBIL;
 new_config->gerbil.diet = DIET_FLOWERS | DIET_TREES;
 new_config->gerbil.max_pregnant = 10;
 new_config->cat.max_birth_stamina =
   80;
 new_config->cat.animal = CAT;
 new_config->cat.diet = DIET_GERBIL | DIET_FLOWERS;
 new_config->cat.max_pregnant = 4;
 new_config->snake.max_birth_stamina =
   30;
 new_config->snake.animal = SNAKE;
 new_config->snake.diet = DIET_GERBIL | DIET_CAT;
 new_config->snake.max_pregnant = 1;
 urcu_game_config_update_end(new_config);
}


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

result = putchar(10);
if ( clear_screen_enable )
result = printf("%c[2J%c[;H", 27LL, 27LL);
return result;
}

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

result = putchar(10);
if ( clear_screen_enable )
result = printf("%c[2J%c[;H", 27LL, 27LL);
return result;
}

original_code:
static inline
void clear_screen(void)
{
 printf("\n");
 if (clear_screen_enable)
  printf("%c[2J%c[;H", (char) 27, (char) 27);
}

canonical_original_code:
static inline void clear_screen()
{
 printf("\n");
 if (clear_screen_enable)
  printf("%c[2J%c[;H", (char) 27, (char) 27);
}


decompiled_code:
__int64 create_output_thread()
{
if ( pthread_create(&output_thread_id, 0LL, output_thread_fct, 0LL) )
abort();
return 0LL;
}

canonical_decompiled_code:
__int64 func4()
{
if ( pthread_create(&output_thread_id, 0LL, output_thread_fct, 0LL) )
abort();
return 0LL;
}

original_code:
int create_output_thread(void)
{
 int err;
 err = pthread_create(&output_thread_id, ((void *)0),
  output_thread_fct, ((void *)0));
 if (err)
  abort();
 return 0;
}

canonical_original_code:
int create_output_thread()
{
 int err;
 err = pthread_create(&output_thread_id, ((void *)0),
  output_thread_fct, ((void *)0));
 if (err)
  abort();
 return 0;
}


decompiled_code:
__int64 join_output_thread()
{
void *thread_return; // [rsp+8h] [rbp-10h] BYREF

if ( pthread_join(output_thread_id, &thread_return) )
abort();
return 0LL;
}

canonical_decompiled_code:
__int64 func5()
{
void *thread_return; // [rsp+8h] [rbp-10h] BYREF

if ( pthread_join(output_thread_id, &thread_return) )
abort();
return 0LL;
}

original_code:
int join_output_thread(void)
{
 int ret;
 void *tret;
 ret = pthread_join(output_thread_id, &tret);
 if (ret)
  abort();
 return 0;
}

canonical_original_code:
int join_output_thread()
{
 int ret;
 void *tret;
 ret = pthread_join(output_thread_id, &tret);
 if (ret)
  abort();
 return 0;
}


decompiled_code:
__int64 do_dispatch()
{
unsigned __int64 v0; // rbp
__int64 result; // rax
__int64 v2; // r13
__int64 i; // r12
_QWORD *v4; // rbx
unsigned int *v5; // r14

rcu_read_lock_memb();
v0 = *(_QWORD *)urcu_game_config_get();
rcu_read_unlock_memb();
result = get_nr_worker_threads();
if ( result )
{
v2 = result;
for ( i = 0LL; i != v2; ++i )
{
v4 = calloc(1uLL, 0x80uLL);
if ( !v4 )
abort();
v5 = (unsigned int *)((char *)&thread_rand_seed + __readfsqword(0));
v4[1] = rand_r(v5) % v0;
v4[2] = rand_r(v5) % v0;
result = enqueue_work(i, v4);
if ( (_DWORD)result )
abort();
}
}
return result;
}

canonical_decompiled_code:
__int64 func0()
{
unsigned __int64 v0; // rbp
__int64 result; // rax
__int64 v2; // r13
__int64 i; // r12
_QWORD *v4; // rbx
unsigned int *v5; // r14

rcu_read_lock_memb();
v0 = *(_QWORD *)urcu_game_config_get();
rcu_read_unlock_memb();
result = get_nr_worker_threads();
if ( result )
{
v2 = result;
for ( i = 0LL; i != v2; ++i )
{
v4 = calloc(1uLL, 0x80uLL);
if ( !v4 )
abort();
v5 = (unsigned int *)((char *)&thread_rand_seed + __readfsqword(0));
v4[1] = rand_r(v5) % v0;
v4[2] = rand_r(v5) % v0;
result = enqueue_work(i, v4);
if ( (_DWORD)result )
abort();
}
}
return result;
}

original_code:
static
void do_dispatch(void)
{
 struct urcu_game_config *config;
 unsigned long i, nr_threads;
 uint64_t island_size;
 int ret;
 rcu_read_lock_memb();
 config = urcu_game_config_get();
 island_size = config->island_size;
 rcu_read_unlock_memb();
 nr_threads = get_nr_worker_threads();
 for (i = 0; i < nr_threads; i++) {
  struct urcu_game_work *work;
  work = calloc(1, sizeof(*work));
  if (!work)
   abort();
  work->first_key = rand_r(&thread_rand_seed) % island_size;
  work->second_key = rand_r(&thread_rand_seed) % island_size;
  ret = enqueue_work(i, work);
  if (ret)
   abort();
 }
}

canonical_original_code:
static void do_dispatch()
{
 struct urcu_game_config *config;
 unsigned long i; unsigned long nr_threads;
 unsigned long island_size;
 int ret;
 rcu_read_lock_memb();
 config = urcu_game_config_get();
 island_size = config->island_size;
 rcu_read_unlock_memb();
 nr_threads = get_nr_worker_threads();
 for (i = 0; i < nr_threads; i++) {
  struct urcu_game_work *work;
  work = calloc(1, sizeof(*work));
  if (!work)
   abort();
  work->first_key = rand_r(&thread_rand_seed) % island_size;
  work->second_key = rand_r(&thread_rand_seed) % island_size;
  ret = enqueue_work(i, work);
  if (ret)
   abort();
 }
}


decompiled_code:
__int64 create_dispatch_thread()
{
if ( pthread_create(&dispatch_thread_id, 0LL, dispatch_thread_fct, 0LL) )
abort();
return 0LL;
}

canonical_decompiled_code:
__int64 func2()
{
if ( pthread_create(&dispatch_thread_id, 0LL, dispatch_thread_fct, 0LL) )
abort();
return 0LL;
}

original_code:
int create_dispatch_thread(void)
{
 int err;
 err = pthread_create(&dispatch_thread_id, ((void *)0),
  dispatch_thread_fct, ((void *)0));
 if (err)
  abort();
 return 0;
}

canonical_original_code:
int create_dispatch_thread()
{
 int err;
 err = pthread_create(&dispatch_thread_id, ((void *)0),
  dispatch_thread_fct, ((void *)0));
 if (err)
  abort();
 return 0;
}


decompiled_code:
__int64 join_dispatch_thread()
{
void *thread_return; // [rsp+8h] [rbp-10h] BYREF

if ( pthread_join(dispatch_thread_id, &thread_return) )
abort();
return 0LL;
}

canonical_decompiled_code:
__int64 func3()
{
void *thread_return; // [rsp+8h] [rbp-10h] BYREF

if ( pthread_join(dispatch_thread_id, &thread_return) )
abort();
return 0LL;
}

original_code:
int join_dispatch_thread(void)
{
 int ret;
 void *tret;
 ret = pthread_join(dispatch_thread_id, &tret);
 if (ret)
  abort();
 return 0;
}

canonical_original_code:
int join_dispatch_thread()
{
 int ret;
 void *tret;
 ret = pthread_join(dispatch_thread_id, &tret);
 if (ret)
  abort();
 return 0;
}


repo: egcodes/key-syncSubtitle

decompiled_code:
int __fastcall fprint_dur(unsigned int *a1)
{
return fprintf(fD, "0%d:%02d:%02d,%03d", *a1, a1[1], a1[2], a1[3]);
}

canonical_decompiled_code:
int __fastcall func7(unsigned int *a1)
{
return fprintf(fD, "0%d:%02d:%02d,%03d", *a1, a1[1], a1[2], a1[3]);
}

original_code:
void fprint_dur(const Dur *p)
{
    fprintf(fD, "0%d:%02d:%02d,%03d", p->hour, p->min, p->sec, p->msec);
}

canonical_original_code:
void fprint_dur(struct _Dur *p)
{
    fprintf(fD, "0%d:%02d:%02d,%03d", p->hour, p->min, p->sec, p->msec);
}

variable_types:
p
struct _Dur { int hour; } *


variable_types: sync double

variable_types: sum int


usage

decompiled_code:
void __noreturn usage()
{
printf(
"\n"
"Key v%s (Usage)\n"
"Sync : key -l <subtitle-path> -s <second>\n"
"( 5) -> add 5 second\n"
"(-5) -> reduce 5 second\n"
"\n"
"Help : key -h\n"
"\n",
"0.1");
exit(1);
}

canonical_decompiled_code:
void __noreturn func9()
{
printf(
"\n"
"Key v%s (Usage)\n"
"Sync : key -l <subtitle-path> -s <second>\n"
"( 5) -> add 5 second\n"
"(-5) -> reduce 5 second\n"
"\n"
"Help : key -h\n"
"\n",
"0.1");
exit(1);
}

original_code:
void usage(void)
{
    printf("\nKey v%s (Usage)\n"
           "Sync  : key -l <subtitle-path> -s <second>\n"
           "( 5)   -> add 5 second\n"
           "(-5)   -> reduce 5 second\n\n"
           "Help  : key -h\n\n", "0.1");
    exit(1);
}

canonical_original_code:
void usage()
{
    printf("\nKey v%s (Usage)\n"
           "Sync  : key -l <subtitle-path> -s <second>\n"
           "( 5)   -> add 5 second\n"
           "(-5)   -> reduce 5 second\n\n"
           "Help  : key -h\n\n", "0.1");
    exit(1);
}


checkArgc

decompiled_code:
__int64 __fastcall checkArgc(int a1)
{
if ( a1 <= 1 )
usage();
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func10(int a1)
{
if ( a1 <= 1 )
func9();
return 0LL;
}

original_code:
int checkArgc(int argc)
{
    if (argc < 2)
        usage();
    return 0;
}


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
double v3; // rbx
const char *v4; // r13
char v5; // al
int v6; // ebp
int v7; // eax
char *v8; // rax
int v9; // eax
char *v10; // rax
char *v11; // rax
int v12; // ebp
char v14; // [rsp+0h] [rbp-728h] BYREF
char nptr[2]; // [rsp+1h] [rbp-727h] BYREF
char v16[3]; // [rsp+3h] [rbp-725h] BYREF
char v17[3]; // [rsp+6h] [rbp-722h] BYREF
char v18[8]; // [rsp+9h] [rbp-71Fh] BYREF
char v19[3]; // [rsp+11h] [rbp-717h] BYREF
char v20[3]; // [rsp+14h] [rbp-714h] BYREF
char v21[3]; // [rsp+17h] [rbp-711h] BYREF
char v22[982]; // [rsp+1Ah] [rbp-70Eh] BYREF
char dest[256]; // [rsp+3F0h] [rbp-338h] BYREF
char s[256]; // [rsp+4F0h] [rbp-238h] BYREF
char newa[256]; // [rsp+5F0h] [rbp-138h] BYREF
int v26; // [rsp+6F0h] [rbp-38h] BYREF
int v27; // [rsp+6F4h] [rbp-34h]
int v28; // [rsp+6F8h] [rbp-30h]
int v29; // [rsp+6FCh] [rbp-2Ch]

if ( (unsigned int)checkArgc(argc) )
usage();
while ( 1 )
{
v5 = getopt(argc, (char *const *)argv, "hl:s:");
if ( v5 == -1 )
break;
if ( v5 == 108 )
{
v4 = _bss_start;
}
else
{
if ( v5 != 115 )
{
if ( v5 != 104 )
usage();
usage();
}
v3 = atof(_bss_start);
}
}
sprintf(s, "%s-temp.txt", v4);
stream = fopen(v4, "r");
if ( !stream )
{
puts("Subtitle not open...");
exit(1);
}
fD = fopen(s, "w");
if ( !fD )
{
puts("Cannot open file...");
exit(1);
}
if ( strstr(v4, ".sub") )
{
v6 = (int)(v3 * 1000.0);
while ( fgets(&v14, 900, stream) )
{
if ( v14 == 123 )
{
v7 = atoi(nptr);
fprintf(fD, "{%d}", (unsigned int)(v6 + v7));
v8 = strchr(nptr, 123);
v9 = atoi(v8 + 1);
fprintf(fD, "{%d}", (unsigned int)(v6 + v9));
v10 = strchr(&v14, 125);
v11 = strchr(v10 + 1, 125);
fputs(v11 + 1, fD);
}
}
}
v12 = 1;
if ( strstr(v4, ".srt") )
{
while ( fgets(&v14, 900, stream) )
{
fputs(&v14, fD);
if ( v12 == atoi(&v14) )
{
fgets(&v14, 900, stream);
v26 = atoi(&v14);
v27 = atoi(v16);
v28 = atoi(v17);
v29 = atoi(v18);
set_dur(&v26, v3);
fprint_dur((unsigned int *)&v26);
fwrite(" --> ", 1uLL, 5uLL, fD);
v26 = atoi(v19);
v27 = atoi(v20);
v28 = atoi(v21);
v29 = atoi(v22);
set_dur(&v26, v3);
fprint_dur((unsigned int *)&v26);
fputc(10, fD);
++v12;
}
}
}
fclose(stream);
fclose(fD);
sprintf(newa, "%s(old)", v4);
rename(v4, newa);
strcpy(dest, v4);
rename(s, dest);
printf("\nNew Subtitle Path : %s\n", dest);
puts("Press any key to close");
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
double v3; // rbx
const char *v4; // r13
char v5; // al
int v6; // ebp
int v7; // eax
char *v8; // rax
int v9; // eax
char *v10; // rax
char *v11; // rax
int v12; // ebp
char v14; // [rsp+0h] [rbp-728h] BYREF
char nptr[2]; // [rsp+1h] [rbp-727h] BYREF
char v16[3]; // [rsp+3h] [rbp-725h] BYREF
char v17[3]; // [rsp+6h] [rbp-722h] BYREF
char v18[8]; // [rsp+9h] [rbp-71Fh] BYREF
char v19[3]; // [rsp+11h] [rbp-717h] BYREF
char v20[3]; // [rsp+14h] [rbp-714h] BYREF
char v21[3]; // [rsp+17h] [rbp-711h] BYREF
char v22[982]; // [rsp+1Ah] [rbp-70Eh] BYREF
char dest[256]; // [rsp+3F0h] [rbp-338h] BYREF
char s[256]; // [rsp+4F0h] [rbp-238h] BYREF
char newa[256]; // [rsp+5F0h] [rbp-138h] BYREF
int v26; // [rsp+6F0h] [rbp-38h] BYREF
int v27; // [rsp+6F4h] [rbp-34h]
int v28; // [rsp+6F8h] [rbp-30h]
int v29; // [rsp+6FCh] [rbp-2Ch]

if ( (unsigned int)func10(argc) )
func9();
while ( 1 )
{
v5 = getopt(argc, (char *const *)argv, "hl:s:");
if ( v5 == -1 )
break;
if ( v5 == 108 )
{
v4 = _bss_start;
}
else
{
if ( v5 != 115 )
{
if ( v5 != 104 )
func9();
func9();
}
v3 = atof(_bss_start);
}
}
sprintf(s, "%s-temp.txt", v4);
stream = fopen(v4, "r");
if ( !stream )
{
puts("Subtitle not open...");
exit(1);
}
fD = fopen(s, "w");
if ( !fD )
{
puts("Cannot open file...");
exit(1);
}
if ( strstr(v4, ".sub") )
{
v6 = (int)(v3 * 1000.0);
while ( fgets(&v14, 900, stream) )
{
if ( v14 == 123 )
{
v7 = atoi(nptr);
fprintf(fD, "{%d}", (unsigned int)(v6 + v7));
v8 = strchr(nptr, 123);
v9 = atoi(v8 + 1);
fprintf(fD, "{%d}", (unsigned int)(v6 + v9));
v10 = strchr(&v14, 125);
v11 = strchr(v10 + 1, 125);
fputs(v11 + 1, fD);
}
}
}
v12 = 1;
if ( strstr(v4, ".srt") )
{
while ( fgets(&v14, 900, stream) )
{
fputs(&v14, fD);
if ( v12 == atoi(&v14) )
{
fgets(&v14, 900, stream);
v26 = atoi(&v14);
v27 = atoi(v16);
v28 = atoi(v17);
v29 = atoi(v18);
func8(&v26, v3);
func7((unsigned int *)&v26);
fwrite(" --> ", 1uLL, 5uLL, fD);
v26 = atoi(v19);
v27 = atoi(v20);
v28 = atoi(v21);
v29 = atoi(v22);
func8(&v26, v3);
func7((unsigned int *)&v26);
fputc(10, fD);
++v12;
}
}
}
fclose(stream);
fclose(fD);
sprintf(newa, "%s(old)", v4);
rename(v4, newa);
strcpy(dest, v4);
rename(s, dest);
printf("\nNew Subtitle Path : %s\n", dest);
puts("Press any key to close");
return 0;
}

original_code:
int main(int argc, char *argv[])
{
    Dur time;
    char *spath;
    char snewpath[256];
    char dpath[256];
    char dnewpath[256];
    int count = 1;
    double sync;
    char buf[1000];
    char c;
    int sub, sub_sync;
    if (checkArgc(argc))
        usage();
    while ((c = getopt (argc, argv, "hl:s:")) != -1)
        switch (c)
        {
            case 'h':
                usage();
                break;
            case 'l':
                spath = optarg;
                break;
            case 's':
                sync = atof(optarg);
                break;
            default:
                usage();
                break;
        }
    sprintf(dpath, "%s-temp.txt", spath);
    sub_sync = sync * 1000;
    if ((fS = fopen(spath, "r")) == ((void *)0)) {
        printf("Subtitle not open...\n");
        exit(1);
    }
    if ((fD = fopen(dpath, "w")) == ((void *)0)) {
        printf("Cannot open file...\n");
        exit(1);
    }
    if (strstr(spath, ".sub"))
     while (((void *)0) != fgets(buf, 900, fS))
         if (buf[0] == '{') {
       sub = atoi(buf + 1);
       sub += sub_sync;
       fprintf(fD, "{%d}", sub);
       sub = atoi(strchr(buf + 1, '{') + 1);
       sub += sub_sync;
       fprintf(fD, "{%d}", sub);
       fprintf(fD, "%s", strchr(strchr(buf, '}') + 1, '}') + 1);
      }
    if (strstr(spath, ".srt"))
     while (((void *)0) != fgets(buf, 900, fS)) {
           fprintf(fD, "%s", buf);
           if (atoi(buf) == count) {
               fgets(buf, 900, fS);
               time.hour = atoi(buf);
               time.min = atoi(buf + 3);
               time.sec = atoi(buf + 6);
               time.msec = atoi(buf + 9);
               set_dur(&time, sync);
               fprint_dur(&time);
               fprintf(fD, " --> ");
               time.hour = atoi(buf + 17);
               time.min = atoi(buf + 20);
               time.sec = atoi(buf + 23);
               time.msec = atoi(buf + 26);
               set_dur(&time, sync);
               fprint_dur(&time);
               fprintf(fD, "\n");
               count++;
           }
     }
    fclose(fS);
    fclose(fD);
    sprintf(snewpath, "%s(old)", spath);
    rename(spath, snewpath);
    sprintf(dnewpath, "%s", spath);
    rename(dpath, dnewpath);
    printf("\nNew Subtitle Path : %s\n",dnewpath);
    printf("Press any key to close\n");
    return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
    struct _Dur time;
    char *spath;
    char snewpath[256];
    char dpath[256];
    char dnewpath[256];
    int count = 1;
    double sync;
    char buf[1000];
    char c;
    int sub; int sub_sync;
    if (checkArgc(argc))
        usage();
    while ((c = getopt (argc, argv, "hl:s:")) != -1)
        switch (c)
        {
            case 'h':
                usage();
                break;
            case 'l':
                spath = optarg;
                break;
            case 's':
                sync = atof(optarg);
                break;
            default:
                usage();
                break;
        }
    sprintf(dpath, "%s-temp.txt", spath);
    sub_sync = sync * 1000;
    if ((fS = fopen(spath, "r")) == ((void *)0)) {
        printf("Subtitle not open...\n");
        exit(1);
    }
    if ((fD = fopen(dpath, "w")) == ((void *)0)) {
        printf("Cannot open file...\n");
        exit(1);
    }
    if (strstr(spath, ".sub"))
     while (((void *)0) != fgets(buf, 900, fS))
         if (buf[0] == '{') {
       sub = atoi(buf + 1);
       sub += sub_sync;
       fprintf(fD, "{%d}", sub);
       sub = atoi(strchr(buf + 1, '{') + 1);
       sub += sub_sync;
       fprintf(fD, "{%d}", sub);
       fprintf(fD, "%s", strchr(strchr(buf, '}') + 1, '}') + 1);
      }
    if (strstr(spath, ".srt"))
     while (((void *)0) != fgets(buf, 900, fS)) {
           fprintf(fD, "%s", buf);
           if (atoi(buf) == count) {
               fgets(buf, 900, fS);
               time.hour = atoi(buf);
               time.min = atoi(buf + 3);
               time.sec = atoi(buf + 6);
               time.msec = atoi(buf + 9);
               set_dur(&time, sync);
               fprint_dur(&time);
               fprintf(fD, " --> ");
               time.hour = atoi(buf + 17);
               time.min = atoi(buf + 20);
               time.sec = atoi(buf + 23);
               time.msec = atoi(buf + 26);
               set_dur(&time, sync);
               fprint_dur(&time);
               fprintf(fD, "\n");
               count++;
           }
     }
    fclose(fS);
    fclose(fD);
    sprintf(snewpath, "%s(old)", spath);
    rename(spath, snewpath);
    sprintf(dnewpath, "%s", spath);
    rename(dpath, dnewpath);
    printf("\nNew Subtitle Path : %s\n",dnewpath);
    printf("Press any key to close\n");
    return 0;
}

variable_types:
argv
char *[]

variable_types:
time
struct _Dur { int hour; }

variable_types:
spath
char *

variable_types:
snewpath
char [256]

variable_types:
dpath
char [256]

variable_types:
dnewpath
char [256]

variable_types: count int

variable_types:
buf
char [1000]

variable_types: c char

variable_types: sub int


decompiled_code:
void __fastcall __noreturn count_down(int a1)
{
unsigned int v1; // ebx

v1 = a1;
strcpy(buf, "time to die");
puts("\nChild 2 process executing...");
if ( close(pfd2[0]) != -1 )
{
if ( close(fd) != -1 )
{
if ( close(pfd1[0]) != -1 )
{
if ( a1 > 0 )
{
do
{
printf("Count Down: 00:0%d\n", v1);
write(dword_4040BC, "not die yet", 0xCuLL);
sleep(1u);
--v1;
}
while ( v1 );
}
write(dword_4040BC, buf, 0xCuLL);
if ( close(dword_4040BC) != -1 )
{
puts("Count Down: 0");
puts("End of Count Down(child 2) process...");
exit(1);
}
printf("Error closing writing end of pipe 2");
_exit(1);
}
puts("Error closing reading end of pipe 1");
_exit(1);
}
puts("Error closing writing end of pipe 1");
_exit(1);
}
puts("Error closing reading end of pipe 2");
_exit(1);
}

canonical_decompiled_code:
void __fastcall __noreturn func7(int a1)
{
unsigned int v1; // ebx

v1 = a1;
strcpy(buf, "time to die");
puts("\nChild 2 process executing...");
if ( close(pfd2[0]) != -1 )
{
if ( close(fd) != -1 )
{
if ( close(pfd1[0]) != -1 )
{
if ( a1 > 0 )
{
do
{
printf("Count Down: 00:0%d\n", v1);
write(dword_4040BC, "not die yet", 0xCuLL);
sleep(1u);
--v1;
}
while ( v1 );
}
write(dword_4040BC, buf, 0xCuLL);
if ( close(dword_4040BC) != -1 )
{
puts("Count Down: 0");
puts("End of Count Down(child 2) process...");
exit(1);
}
printf("Error closing writing end of pipe 2");
_exit(1);
}
puts("Error closing reading end of pipe 1");
_exit(1);
}
puts("Error closing writing end of pipe 1");
_exit(1);
}
puts("Error closing reading end of pipe 2");
_exit(1);
}

original_code:
void count_down(int start)
{
 strcpy(buf, "time to die");
    printf("\nChild 2 process executing...\n");
    if (close(pfd2[0]) == -1)
    {
        printf("Error closing reading end of pipe 2\n");
        _exit(1);
    }
 if (close(pfd1[1]) == -1)
    {
        printf("Error closing writing end of pipe 1\n");
        _exit(1);
    }
    if (close(pfd1[0]) == -1)
    {
        printf("Error closing reading end of pipe 1\n");
        _exit(1);
    }
    for( ;start>0; start--)
    {
  printf("Count Down: 00:0%d\n", start);
        write(pfd2[1], "not die yet",12);
  sleep(1);
    }
    write(pfd2[1], buf, sizeof(buf));
    if (close(pfd2[1]) == -1)
    {
        printf("Error closing writing end of pipe 2");
        _exit(1);
    }
    printf("Count Down: 0\n");
 printf("End of Count Down(child 2) process...\n");
    exit(1);
}

variable_types: start int


decompiled_code:
void __noreturn wall_clock()
{
struct tm *v0; // rbx
time_t timer; // [rsp+8h] [rbp-20h] BYREF
char s1[20]; // [rsp+14h] [rbp-14h] BYREF

strcpy(s1, "time to die");
puts("\nChild 1 process executing...");
if ( close(pfd1[0]) != -1 )
{
if ( close(dword_4040BC) != -1 )
{
if ( close(fd) == -1 )
{
puts("Error closing writing end of pipe 1");
_exit(1);
}
while ( 1 )
{
timer = time(0LL);
v0 = localtime(&timer);
read(pfd2[0], buf, 0xCuLL);
if ( !strcmp(s1, buf) )
break;
printf("The time is %d:%d:%d\n", (unsigned int)v0->tm_hour, (unsigned int)v0->tm_min, (unsigned int)v0->tm_sec);
sleep(1u);
}
if ( close(pfd2[0]) != -1 )
{
puts("End of Wall Clock(child 1) process...");
exit(1);
}
puts("Error closing writing end of pipe 2");
_exit(1);
}
puts("Error closing writing end of pipe 2");
_exit(1);
}
puts("Error closing reading end of pipe 1");
_exit(1);
}

canonical_decompiled_code:
void __noreturn func8()
{
struct tm *v0; // rbx
time_t timer; // [rsp+8h] [rbp-20h] BYREF
char s1[20]; // [rsp+14h] [rbp-14h] BYREF

strcpy(s1, "time to die");
puts("\nChild 1 process executing...");
if ( close(pfd1[0]) != -1 )
{
if ( close(dword_4040BC) != -1 )
{
if ( close(fd) == -1 )
{
puts("Error closing writing end of pipe 1");
_exit(1);
}
while ( 1 )
{
timer = time(0LL);
v0 = localtime(&timer);
read(pfd2[0], buf, 0xCuLL);
if ( !strcmp(s1, buf) )
break;
printf("The time is %d:%d:%d\n", (unsigned int)v0->tm_hour, (unsigned int)v0->tm_min, (unsigned int)v0->tm_sec);
sleep(1u);
}
if ( close(pfd2[0]) != -1 )
{
puts("End of Wall Clock(child 1) process...");
exit(1);
}
puts("Error closing writing end of pipe 2");
_exit(1);
}
puts("Error closing writing end of pipe 2");
_exit(1);
}
puts("Error closing reading end of pipe 1");
_exit(1);
}

original_code:
void wall_clock()
{
 char str1[12];
 strcpy(str1, "time to die");
 printf("\nChild 1 process executing...\n");
    time_t now;
    struct tm *lcltime;
    if (close(pfd1[0]) == -1)
    {
        printf("Error closing reading end of pipe 1\n");
        _exit(1);
    }
 if (close(pfd2[1]) == -1)
    {
        printf("Error closing writing end of pipe 2\n");
        _exit(1);
    }
 if (close(pfd1[1]) == -1)
    {
        printf("Error closing writing end of pipe 1\n");
        _exit(1);
    }
    for(;;)
    {
        now = time ( ((void *)0) );
        lcltime = localtime ( &now );
  int status = read(pfd2[0], buf, 12);
        int ret = strcmp(str1, buf);
  if (ret != 0)
  {
            printf ("The time is %d:%d:%d\n", lcltime->tm_hour, lcltime->tm_min, lcltime->tm_sec );
            sleep(1);
  }
  if(ret == 0)
        {
            if (close(pfd2[0]) == -1)
            {
                printf("Error closing writing end of pipe 2\n");
                _exit(1);
            }
            printf("End of Wall Clock(child 1) process...\n");
            exit(1);
        }
    }
}

canonical_original_code:
void wall_clock()
{
 char str1[12];
 strcpy(str1, "time to die");
 printf("\nChild 1 process executing...\n");
    long now;
    struct tm *lcltime;
    if (close(pfd1[0]) == -1)
    {
        printf("Error closing reading end of pipe 1\n");
        _exit(1);
    }
 if (close(pfd2[1]) == -1)
    {
        printf("Error closing writing end of pipe 2\n");
        _exit(1);
    }
 if (close(pfd1[1]) == -1)
    {
        printf("Error closing writing end of pipe 1\n");
        _exit(1);
    }
    for(;;)
    {
        now = time ( ((void *)0) );
        lcltime = localtime ( &now );
  int status = read(pfd2[0], buf, 12);
        int ret = strcmp(str1, buf);
  if (ret != 0)
  {
            printf ("The time is %d:%d:%d\n", lcltime->tm_hour, lcltime->tm_min, lcltime->tm_sec );
            sleep(1);
  }
  if(ret == 0)
        {
            if (close(pfd2[0]) == -1)
            {
                printf("Error closing writing end of pipe 2\n");
                _exit(1);
            }
            printf("End of Wall Clock(child 1) process...\n");
            exit(1);
        }
    }
}

variable_types: now long

variable_types: struct tm { int tm_sec; int tm_min; int tm_hour; int tm_mday; int tm_mon; int tm_year; int tm_wday; int tm_yday; int tm_isdst; long tm_gmtoff; char *tm_zone; } *

variable_types: status int

variable_types: ret int


decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
int v3; // ebx
__pid_t v4; // eax
__pid_t v5; // eax

v3 = 6;
if ( argc == 2 )
v3 = atoi(argv[1]);
if ( pipe(pfd1) != -1 )
{
if ( pipe(pfd2) != -1 )
{
puts("Pipes opened, now creating child process!");
v4 = fork();
if ( v4 != -1 )
{
if ( v4 )
{
v5 = fork();
if ( v5 != -1 )
{
if ( v5 )
{
puts("Parent closing pipes");
if ( close(pfd1[0]) != -1 )
{
if ( close(fd) != -1 )
{
if ( close(pfd2[0]) != -1 )
{
if ( close(dword_4040BC) != -1 )
{
puts("Parent waiting for children completion...");
if ( wait(0LL) != -1 )
{
if ( wait(0LL) != -1 )
{
puts("Time to print out a Friendly Message!");
puts("Parent process finishing, bye!");
exit(0);
}
puts("Error wating, no child process is ended!");
exit(1);
}
puts("Error wating, no child process is ended!");
exit(1);
}
puts("Error closing writing end of the pipe 2");
exit(1);
}
puts("Error closing reading end of the pipe 2");
exit(1);
}
puts("Error closing writing end of the pipe 1");
exit(1);
}
puts("Error closing reading end of the pipe 1");
exit(1);
}
count_down(v3);
}
puts("Error forking child 2!");
exit(1);
}
wall_clock("Pipes opened, now creating child process!", argv);
}
puts("Error forking child 1!");
exit(1);
}
puts("Error opening pipe 2!");
exit(1);
}
puts("Error opening pipe 1!");
exit(1);
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
int v3; // ebx
__pid_t v4; // eax
__pid_t v5; // eax

v3 = 6;
if ( argc == 2 )
v3 = atoi(argv[1]);
if ( pipe(pfd1) != -1 )
{
if ( pipe(pfd2) != -1 )
{
puts("Pipes opened, now creating child process!");
v4 = fork();
if ( v4 != -1 )
{
if ( v4 )
{
v5 = fork();
if ( v5 != -1 )
{
if ( v5 )
{
puts("Parent closing pipes");
if ( close(pfd1[0]) != -1 )
{
if ( close(fd) != -1 )
{
if ( close(pfd2[0]) != -1 )
{
if ( close(dword_4040BC) != -1 )
{
puts("Parent waiting for children completion...");
if ( wait(0LL) != -1 )
{
if ( wait(0LL) != -1 )
{
puts("Time to print out a Friendly Message!");
puts("Parent process finishing, bye!");
exit(0);
}
puts("Error wating, no child process is ended!");
exit(1);
}
puts("Error wating, no child process is ended!");
exit(1);
}
puts("Error closing writing end of the pipe 2");
exit(1);
}
puts("Error closing reading end of the pipe 2");
exit(1);
}
puts("Error closing writing end of the pipe 1");
exit(1);
}
puts("Error closing reading end of the pipe 1");
exit(1);
}
func7(v3);
}
puts("Error forking child 2!");
exit(1);
}
func8("Pipes opened, now creating child process!", argv);
}
puts("Error forking child 1!");
exit(1);
}
puts("Error opening pipe 2!");
exit(1);
}
puts("Error opening pipe 1!");
exit(1);
}

original_code:
int main(int argc, const char * argv[])
{
    int time=6;
    if(argc==2)
    {
        time=atoi(argv[1]);
    }
    if (pipe(pfd1) == -1)
    {
        printf("Error opening pipe 1!\n");
        exit(1);
    }
    if (pipe(pfd2) == -1)
    {
        printf("Error opening pipe 2!\n");
        exit(1);
    }
    printf("Pipes opened, now creating child process!\n");
    switch (fork())
    {
        case -1:
            printf("Error forking child 1!\n");
            exit(1);
        case 0:
            wall_clock();
            exit(1);
        default:
            break;
    }
    switch (fork())
    {
        case -1:
            printf("Error forking child 2!\n");
            exit(1);
        case 0:
            count_down(time);
            exit(1);
        default:
            break;
    }
    printf("Parent closing pipes\n");
    if (close(pfd1[0]) == -1)
    {
        printf("Error closing reading end of the pipe 1\n");
        exit(1);
    }
    if (close(pfd1[1]) == -1)
    {
        printf("Error closing writing end of the pipe 1\n");
        exit(1);
    }
    if (close(pfd2[0]) == -1)
    {
        printf("Error closing reading end of the pipe 2\n");
        exit(1);
    }
    if (close(pfd2[1]) == -1)
    {
        printf("Error closing writing end of the pipe 2\n");
        exit(1);
    }
    printf("Parent waiting for children completion...\n");
    if (wait(((void *)0)) == -1)
    {
        printf("Error wating, no child process is ended!\n");
        exit(1);
    }
    if (wait(((void *)0)) == -1)
    {
        printf("Error wating, no child process is ended!\n");
        exit(1);
    }
    printf("Time to print out a Friendly Message!\n");
 printf("Parent process finishing, bye!\n");
    exit(0);
}

canonical_original_code:
int main(int argc, char *argv[])
{
    int time = 6;
    if(argc==2)
    {
        time=atoi(argv[1]);
    }
    if (pipe(pfd1) == -1)
    {
        printf("Error opening pipe 1!\n");
        exit(1);
    }
    if (pipe(pfd2) == -1)
    {
        printf("Error opening pipe 2!\n");
        exit(1);
    }
    printf("Pipes opened, now creating child process!\n");
    switch (fork())
    {
        case -1:
            printf("Error forking child 1!\n");
            exit(1);
        case 0:
            wall_clock();
            exit(1);
        default:
            break;
    }
    switch (fork())
    {
        case -1:
            printf("Error forking child 2!\n");
            exit(1);
        case 0:
            count_down(time);
            exit(1);
        default:
            break;
    }
    printf("Parent closing pipes\n");
    if (close(pfd1[0]) == -1)
    {
        printf("Error closing reading end of the pipe 1\n");
        exit(1);
    }
    if (close(pfd1[1]) == -1)
    {
        printf("Error closing writing end of the pipe 1\n");
        exit(1);
    }
    if (close(pfd2[0]) == -1)
    {
        printf("Error closing reading end of the pipe 2\n");
        exit(1);
    }
    if (close(pfd2[1]) == -1)
    {
        printf("Error closing writing end of the pipe 2\n");
        exit(1);
    }
    printf("Parent waiting for children completion...\n");
    if (wait(((void *)0)) == -1)
    {
        printf("Error wating, no child process is ended!\n");
        exit(1);
    }
    if (wait(((void *)0)) == -1)
    {
        printf("Error wating, no child process is ended!\n");
        exit(1);
    }
    printf("Time to print out a Friendly Message!\n");
 printf("Parent process finishing, bye!\n");
    exit(0);
}

variable_types: argc int

variable_types: time int


repo: egillespie/randword

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // edi
__int16 v4; // bx
int v5; // ebp
int v6; // ebx
int v7; // er13
char v9[72]; // [rsp+0h] [rbp-48h] BYREF

parseArgs(argc, argv, envp);
v3 = time(0LL);
srand(v3);
InitProgram();
signal(2, (__sighandler_t)&SigHandler);
atexit((void (*)(void))&ExitProgram);
do
{
v5 = minWordLength + rand() % (maxWordLength - minWordLength + 1);
if ( v5 > 0 )
{
v6 = 0;
v7 = 0;
do
{
v9[v7] = rand() % 26 + 97;
v7 = (__int16)++v6;
}
while ( (__int16)v6 < v5 );
}
v9[v5] = 0;
++totalcount;
if ( (unsigned int)CheckWord(v9, (unsigned int)v5) )
{
++numfound;
printf("%s", v9);
if ( verbose )
printf(" *");
putchar(10);
v4 = stopAfterLength;
if ( stopAfterLength )
v4 = xLength == v5;
}
else
{
v4 = verbose;
if ( verbose )
{
printf("%s%s", v9, "\n");
v4 = 0;
}
}
}
while ( (!stopAfterWord || strcmp(xWord, v9)) && (!stopAfterHits || numfound != xHits) && !v4 );
return 0;
}

original_code:
int main(int argc, char **argv) {
   char randword[20 + 1];
   int randlen;
   short i, stop = 0;
   parseArgs(argc, argv);
   srand(time(((void *)0)));
   InitProgram();
   signal(2, SigHandler);
   atexit(ExitProgram);
   while (!stop) {
      randlen = rand() % (maxWordLength - minWordLength + 1) + minWordLength;
      for (i = 0; i < randlen; i++)
         randword[i] = (unsigned char)(rand() % 26 + 97);
      randword[randlen] = '\0';
      totalcount++;
      if (CheckWord(randword, randlen)) {
         numfound++;
         printf("%s", randword);
         if (verbose)
            printf(" *");
         printf("%s", "\n");
         if (stopAfterLength && randlen == xLength)
            stop = 1;
      }
      else if (verbose)
         printf("%s%s", randword, "\n");
      if (stopAfterWord && strcmp(xWord, randword) == 0)
         stop = 1;
      if (stopAfterHits && numfound == xHits)
         stop = 1;
   }
   return 0;
}

canonical_original_code:
int main(int argc, char **argv) {
   char randword[-1];
   int randlen;
   short i; short stop = 0;
   parseArgs(argc, argv);
   srand(time(((void *)0)));
   InitProgram();
   signal(2, SigHandler);
   atexit(ExitProgram);
   while (!stop) {
      randlen = rand() % (maxWordLength - minWordLength + 1) + minWordLength;
      for (i = 0; i < randlen; i++)
         randword[i] = (unsigned char)(rand() % 26 + 97);
      randword[randlen] = '\0';
      totalcount++;
      if (CheckWord(randword, randlen)) {
         numfound++;
         printf("%s", randword);
         if (verbose)
            printf(" *");
         printf("%s", "\n");
         if (stopAfterLength && randlen == xLength)
            stop = 1;
      }
      else if (verbose)
         printf("%s%s", randword, "\n");
      if (stopAfterWord && strcmp(xWord, randword) == 0)
         stop = 1;
      if (stopAfterHits && numfound == xHits)
         stop = 1;
   }
   return 0;
}

variable_types:
argv
char **

variable_types:
randword
char [-1]

variable_types: randlen int

variable_types: i short

variable_types: stop short


argSetSearchOnDisk

decompiled_code:
void argSetSearchOnDisk()
{
searchOnDisk = 1;
}

canonical_decompiled_code:
void func0()
{
searchOnDisk = 1;
}

original_code:
void argSetSearchOnDisk(char* szparam) {
   searchOnDisk = 1;
}

canonical_original_code:
void argSetSearchOnDisk(char *szparam) {
   searchOnDisk = 1;
}

variable_types:
szparam
char *


argSetQuiet

decompiled_code:
void argSetQuiet()
{
quiet = 1;
}

canonical_decompiled_code:
void func1()
{
quiet = 1;
}

original_code:
void argSetQuiet(char* szparam) {
   quiet = 1;
}

canonical_original_code:
void argSetQuiet(char *szparam) {
   quiet = 1;
}


argSetVerbose

decompiled_code:
void argSetVerbose()
{
verbose = 1;
}

canonical_decompiled_code:
void func2()
{
verbose = 1;
}

original_code:
void argSetVerbose(char *szparam) {
   verbose = 1;
}


infoSetSearchOnDisk

decompiled_code:
int infoSetSearchOnDisk()
{
return printf("Keep the dictionary on the disk when searching%s", "\n");
}

canonical_decompiled_code:
int func3()
{
return printf("Keep the dictionary on the disk when searching%s", "\n");
}

original_code:
void infoSetSearchOnDisk(void) {
   printf("Keep the dictionary on the disk when searching%s", "\n");
}

canonical_original_code:
void infoSetSearchOnDisk() {
   printf("Keep the dictionary on the disk when searching%s", "\n");
}


infoSetMinWordLength

decompiled_code:
int infoSetMinWordLength()
{
return printf("Sets the minimum word length (default = %d).%s", 3LL, "\n");
}

canonical_decompiled_code:
int func4()
{
return printf("Sets the minimum word length (default = %d).%s", 3LL, "\n");
}

original_code:
void infoSetMinWordLength(void) {
   printf("Sets the minimum word length (default = %d).%s", 3, "\n");
}

canonical_original_code:
void infoSetMinWordLength() {
   printf("Sets the minimum word length (default = %d).%s", 3, "\n");
}


infoSetMaxWordLength

decompiled_code:
int infoSetMaxWordLength()
{
return printf("Sets the maximum word length (default = %d).%s", 20LL, "\n");
}

canonical_decompiled_code:
int func5()
{
return printf("Sets the maximum word length (default = %d).%s", 20LL, "\n");
}

original_code:
void infoSetMaxWordLength(void) {
   printf("Sets the maximum word length (default = %d).%s", 20, "\n");
}

canonical_original_code:
void infoSetMaxWordLength() {
   printf("Sets the maximum word length (default = %d).%s", 20, "\n");
}


infoSetStopHits

decompiled_code:
int infoSetStopHits()
{
return printf("Stop after arg words are generated.%s", "\n");
}

canonical_decompiled_code:
int func6()
{
return printf("Stop after arg words are generated.%s", "\n");
}

original_code:
void infoSetStopHits(void) {
   printf("Stop after arg words are generated.%s", "\n");
}

canonical_original_code:
void infoSetStopHits() {
   printf("Stop after arg words are generated.%s", "\n");
}


infoSetStopWord

decompiled_code:
int infoSetStopWord()
{
return printf("Stop after specified word is generated.%s", "\n");
}

canonical_decompiled_code:
int func7()
{
return printf("Stop after specified word is generated.%s", "\n");
}

original_code:
void infoSetStopWord(void) {
   printf("Stop after specified word is generated.%s", "\n");
}

canonical_original_code:
void infoSetStopWord() {
   printf("Stop after specified word is generated.%s", "\n");
}


infoSetStopLength

decompiled_code:
int infoSetStopLength()
{
return printf("Stop after arg length word is found.%s", "\n");
}

canonical_decompiled_code:
int func8()
{
return printf("Stop after arg length word is found.%s", "\n");
}

original_code:
void infoSetStopLength(void) {
   printf("Stop after arg length word is found.%s", "\n");
}

canonical_original_code:
void infoSetStopLength() {
   printf("Stop after arg length word is found.%s", "\n");
}


infoSetQuiet

decompiled_code:
int infoSetQuiet()
{
return printf("Quiet mode. Only print words found in the dictionary.%s", "\n");
}

canonical_decompiled_code:
int func9()
{
return printf("Quiet mode. Only print words found in the dictionary.%s", "\n");
}

original_code:
void infoSetQuiet(void) {
   printf("Quiet mode.  Only print words found in the dictionary.%s", "\n");
}

canonical_original_code:
void infoSetQuiet() {
   printf("Quiet mode.  Only print words found in the dictionary.%s", "\n");
}


infoSetVerbose

decompiled_code:
int infoSetVerbose()
{
return printf("Verbose mode. Print all randomly generated strings.%s", "\n");
}

canonical_decompiled_code:
int func10()
{
return printf("Verbose mode. Print all randomly generated strings.%s", "\n");
}

original_code:
void infoSetVerbose(void) {
   printf("Verbose mode.  Print all randomly generated strings.%s", "\n");
}

canonical_original_code:
void infoSetVerbose() {
   printf("Verbose mode.  Print all randomly generated strings.%s", "\n");
}


infoPrintHelp

decompiled_code:
int infoPrintHelp()
{
return printf("Displays this help message and exits.%s", "\n");
}

canonical_decompiled_code:
int func11()
{
return printf("Displays this help message and exits.%s", "\n");
}

original_code:
void infoPrintHelp(void) {
   printf("Displays this help message and exits.%s", "\n");
}

canonical_original_code:
void infoPrintHelp() {
   printf("Displays this help message and exits.%s", "\n");
}


argPrintVersion

decompiled_code:
void __noreturn argPrintVersion()
{
printf("%s %s.%s%s", "randword", "1", "1", "\n");
exit(0);
}

canonical_decompiled_code:
void __noreturn func12()
{
printf("%s %s.%s%s", "randword", "1", "1", "\n");
exit(0);
}

original_code:
void argPrintVersion(char* szparam) {
   printf("%s %s.%s%s", "randword", "1", "1", "\n");
   exit(0);
}

canonical_original_code:
void argPrintVersion(char *szparam) {
   printf("%s %s.%s%s", "randword", "1", "1", "\n");
   exit(0);
}


infoPrintVersion

decompiled_code:
int infoPrintVersion()
{
return printf("Displays %s's version information and exits.%s", "randword", "\n");
}

canonical_decompiled_code:
int func13()
{
return printf("Displays %s's version information and exits.%s", "randword", "\n");
}

original_code:
void infoPrintVersion(void) {
   printf("Displays %s's version information and exits.%s", "randword", "\n");
}

canonical_original_code:
void infoPrintVersion() {
   printf("Displays %s's version information and exits.%s", "randword", "\n");
}


argSetMinWordLength

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

minWordLength = atoi(a1);
result = (unsigned int)(minWordLength - 3);
if ( (unsigned int)result > 0x11 )
{
fprintf(stderr, "%s : Invalid minimum word length%s", "randword", "\n");
exit(1);
}
return result;
}

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

minWordLength = atoi(a1);
result = (unsigned int)(minWordLength - 3);
if ( (unsigned int)result > 0x11 )
{
fprintf(stderr, "%s : Invalid minimum word length%s", "randword", "\n");
exit(1);
}
return result;
}

original_code:
void argSetMinWordLength(char* szparam) {
   minWordLength = atoi(szparam);
   if (minWordLength < 3 || minWordLength > 20) {
      fprintf(stderr, "%s : Invalid minimum word length%s", "randword", "\n");
      exit(1);
   }
}

canonical_original_code:
void argSetMinWordLength(char *szparam) {
   minWordLength = atoi(szparam);
   if (minWordLength < 3 || minWordLength > 20) {
      fprintf(stderr, "%s : Invalid minimum word length%s", "randword", "\n");
      exit(1);
   }
}


argSetMaxWordLength

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

maxWordLength = atoi(a1);
result = (unsigned int)(maxWordLength - 3);
if ( (unsigned int)result > 0x11 )
{
fprintf(stderr, "%s : Invalid maximum word length%s", "randword", "\n");
exit(1);
}
return result;
}

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

maxWordLength = atoi(a1);
result = (unsigned int)(maxWordLength - 3);
if ( (unsigned int)result > 0x11 )
{
fprintf(stderr, "%s : Invalid maximum word length%s", "randword", "\n");
exit(1);
}
return result;
}

original_code:
void argSetMaxWordLength(char* szparam) {
   maxWordLength = atoi(szparam);
   if (maxWordLength < 3 || maxWordLength > 20) {
      fprintf(stderr, "%s : Invalid maximum word length%s", "randword", "\n");
      exit(1);
   }
}

canonical_original_code:
void argSetMaxWordLength(char *szparam) {
   maxWordLength = atoi(szparam);
   if (maxWordLength < 3 || maxWordLength > 20) {
      fprintf(stderr, "%s : Invalid maximum word length%s", "randword", "\n");
      exit(1);
   }
}


argSetStopLength

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

stopAfterLength = 1;
v1 = atoi(a1);
xLength = v1;
result = (unsigned int)(v1 - 3);
if ( (unsigned __int16)result > 0x11u )
{
fprintf(stderr, "%s : Specified length is invalid%s", "randword", "\n");
exit(1);
}
return result;
}

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

stopAfterLength = 1;
v1 = atoi(a1);
xLength = v1;
result = (unsigned int)(v1 - 3);
if ( (unsigned __int16)result > 0x11u )
{
fprintf(stderr, "%s : Specified length is invalid%s", "randword", "\n");
exit(1);
}
return result;
}

original_code:
void argSetStopLength(char* szparam) {
   stopAfterLength = 1;
   xLength = atoi(szparam);
   if (xLength < 3 || xLength > 20) {
      fprintf(stderr, "%s : Specified length is invalid%s", "randword", "\n");
      exit(1);
   }
}

canonical_original_code:
void argSetStopLength(char *szparam) {
   stopAfterLength = 1;
   xLength = atoi(szparam);
   if (xLength < 3 || xLength > 20) {
      fprintf(stderr, "%s : Specified length is invalid%s", "randword", "\n");
      exit(1);
   }
}


argSetStopHits

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

stopAfterHits = 1;
result = atol(a1);
xHits = result;
if ( result <= 0 )
{
fprintf(stderr, "%s : Invalid value for parameter -h%s", "randword", "\n");
exit(1);
}
return result;
}

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

stopAfterHits = 1;
result = atol(a1);
xHits = result;
if ( result <= 0 )
{
fprintf(stderr, "%s : Invalid value for parameter -h%s", "randword", "\n");
exit(1);
}
return result;
}

original_code:
void argSetStopHits(char* szparam) {
   stopAfterHits = 1;
   xHits = atol(szparam);
   if (xHits <= 0) {
      fprintf(stderr, "%s : Invalid value for parameter -h%s", "randword", "\n");
      exit(1);
   }
}

canonical_original_code:
void argSetStopHits(char *szparam) {
   stopAfterHits = 1;
   xHits = atol(szparam);
   if (xHits <= 0) {
      fprintf(stderr, "%s : Invalid value for parameter -h%s", "randword", "\n");
      exit(1);
   }
}


argSetStopWord

decompiled_code:
char *__fastcall argSetStopWord(char *src)
{
__int16 v1; // ax

v1 = strlen(src);
stopAfterWord = 1;
if ( v1 <= 2 )
{
fprintf(stderr, "%s : Specified word is too short%s", "randword", "\n");
exit(1);
}
if ( v1 > 20 )
{
fprintf(stderr, "%s : Specified word is too long%s", "randword", "\n");
exit(1);
}
return strcpy(xWord, src);
}

canonical_decompiled_code:
char *__fastcall func18(char *src)
{
__int16 v1; // ax

v1 = strlen(src);
stopAfterWord = 1;
if ( v1 <= 2 )
{
fprintf(stderr, "%s : Specified word is too short%s", "randword", "\n");
exit(1);
}
if ( v1 > 20 )
{
fprintf(stderr, "%s : Specified word is too long%s", "randword", "\n");
exit(1);
}
return strcpy(xWord, src);
}

original_code:
void argSetStopWord(char* szparam) {
   short paramLength = strlen(szparam);
   stopAfterWord = 1;
   if (paramLength < 3) {
      fprintf(stderr, "%s : Specified word is too short%s", "randword", "\n");
      exit(1);
   }
   else if (paramLength > 20) {
      fprintf(stderr, "%s : Specified word is too long%s", "randword", "\n");
      exit(1);
   }
   strcpy(xWord, szparam);
}

canonical_original_code:
void argSetStopWord(char *szparam) {
   short paramLength = strlen(szparam);
   stopAfterWord = 1;
   if (paramLength < 3) {
      fprintf(stderr, "%s : Specified word is too short%s", "randword", "\n");
      exit(1);
   }
   else if (paramLength > 20) {
      fprintf(stderr, "%s : Specified word is too long%s", "randword", "\n");
      exit(1);
   }
   strcpy(xWord, szparam);
}

variable_types: paramLength short


argPrintHelp

decompiled_code:
void __noreturn argPrintHelp()
{
int v0; // er12
int v1; // ebx
const char *v2; // r13
unsigned __int16 i; // bp
__int64 v4; // rax

printf("Usage : %s [options] filename%s%s", "randword", "\n", "\n");
printf("Displays a list of randomly generated words.%s%s", "\n", "\n");
if ( arg[0] )
{
v0 = 0;
v1 = 0;
do
{
v4 = 32LL * v1;
if ( *(_WORD *)&arg[v4 + 10] )
{
v2 = &arg[v4];
printf(" -%s arg", &arg[v4]);
for ( i = 0; i < 12 - strlen(v2); ++i )
putchar(32);
}
else
{
printf(" -%-10s ", &arg[32 * v1]);
}
(*(void (**)(void))&arg[32 * v1 + 24])();
v1 = (unsigned __int16)++v0;
}
while ( arg[32 * (unsigned __int16)v0] );
}
putchar(10);
printf("Send bugs and comments to %s <%s>%s", "Erik Gillespie", "erik.gillespie@gmail.com", "\n");
exit(0);
}

canonical_decompiled_code:
void __noreturn func19()
{
int v0; // er12
int v1; // ebx
const char *v2; // r13
unsigned __int16 i; // bp
__int64 v4; // rax

printf("Usage : %s [options] filename%s%s", "randword", "\n", "\n");
printf("Displays a list of randomly generated words.%s%s", "\n", "\n");
if ( arg[0] )
{
v0 = 0;
v1 = 0;
do
{
v4 = 32LL * v1;
if ( *(_WORD *)&arg[v4 + 10] )
{
v2 = &arg[v4];
printf(" -%s arg", &arg[v4]);
for ( i = 0; i < 12 - strlen(v2); ++i )
putchar(32);
}
else
{
printf(" -%-10s ", &arg[32 * v1]);
}
(*(void (**)(void))&arg[32 * v1 + 24])();
v1 = (unsigned __int16)++v0;
}
while ( arg[32 * (unsigned __int16)v0] );
}
putchar(10);
printf("Send bugs and comments to %s <%s>%s", "Erik Gillespie", "erik.gillespie@gmail.com", "\n");
exit(0);
}

original_code:
void argPrintHelp(char* szparam) {
   unsigned short i, j;
   printf("Usage : %s [options] filename%s%s", "randword", "\n", "\n");
   printf("Displays a list of randomly generated words.%s%s", "\n", "\n");
   i = 0;
   while (*arg[i].argName) {
      if (arg[i].argHasArg) {
         printf("  -%s arg", arg[i].argName);
         for (j = 0; j < 12 - strlen(arg[i].argName); j++)
            printf(" ");
      }
      else
         printf("  -%-10s      ", arg[i].argName);
      arg[i].argInfo();
      i++;
   }
   printf("%s", "\n");
   printf("Send bugs and comments to %s <%s>%s", "Erik Gillespie", "erik.gillespie@gmail.com", "\n");
   exit(0);
}

canonical_original_code:
void argPrintHelp(char *szparam) {
   unsigned short i; unsigned short j;
   printf("Usage : %s [options] filename%s%s", "randword", "\n", "\n");
   printf("Displays a list of randomly generated words.%s%s", "\n", "\n");
   i = 0;
   while (*arg[i].argName) {
      if (arg[i].argHasArg) {
         printf("  -%s arg", arg[i].argName);
         for (j = 0; j < 12 - strlen(arg[i].argName); j++)
            printf(" ");
      }
      else
         printf("  -%-10s      ", arg[i].argName);
      arg[i].argInfo();
      i++;
   }
   printf("%s", "\n");
   printf("Send bugs and comments to %s <%s>%s", "Erik Gillespie", "erik.gillespie@gmail.com", "\n");
   exit(0);
}

variable_types:
i
unsigned short

variable_types:
j
unsigned short


argSanityCheck

decompiled_code:
__int64 argSanityCheck()
{
__int64 result; // rax
int v1; // ebx

result = (unsigned int)maxWordLength;
if ( minWordLength > maxWordLength )
{
fprintf(stderr, "%s : Minimum word length exceeds maximum word length%s", "randword", "\n");
exit(1);
}
if ( quiet && verbose )
{
fprintf(stderr, "%s : Only one of -q and -v may be specified%s", "randword", "\n");
exit(1);
}
if ( stopAfterWord )
{
v1 = strlen(xWord);
result = CheckOnDisk(xWord, (unsigned int)v1);
if ( !(_DWORD)result )
{
fprintf(stderr, "%s : Specified word is not in the dictionary%s", "randword", "\n");
exit(1);
}
if ( minWordLength > v1 || maxWordLength < v1 )
{
fprintf(stderr, "%s : The specified word will never be found%s", "randword", "\n");
exit(1);
}
}
if ( stopAfterLength )
{
result = (unsigned int)xLength;
if ( (int)result < minWordLength || (int)result > maxWordLength )
{
fprintf(stderr, "%s : A word of the specified length will never be found%s", "randword", "\n");
exit(1);
}
}
return result;
}

canonical_decompiled_code:
__int64 func20()
{
__int64 result; // rax
int v1; // ebx

result = (unsigned int)maxWordLength;
if ( minWordLength > maxWordLength )
{
fprintf(stderr, "%s : Minimum word length exceeds maximum word length%s", "randword", "\n");
exit(1);
}
if ( quiet && verbose )
{
fprintf(stderr, "%s : Only one of -q and -v may be specified%s", "randword", "\n");
exit(1);
}
if ( stopAfterWord )
{
v1 = strlen(xWord);
result = CheckOnDisk(xWord, (unsigned int)v1);
if ( !(_DWORD)result )
{
fprintf(stderr, "%s : Specified word is not in the dictionary%s", "randword", "\n");
exit(1);
}
if ( minWordLength > v1 || maxWordLength < v1 )
{
fprintf(stderr, "%s : The specified word will never be found%s", "randword", "\n");
exit(1);
}
}
if ( stopAfterLength )
{
result = (unsigned int)xLength;
if ( (int)result < minWordLength || (int)result > maxWordLength )
{
fprintf(stderr, "%s : A word of the specified length will never be found%s", "randword", "\n");
exit(1);
}
}
return result;
}

original_code:
void argSanityCheck(void) {
   int xWordLen;
   if (minWordLength > maxWordLength) {
      fprintf(stderr, "%s : Minimum word length exceeds maximum word length%s", "randword", "\n");
      exit(1);
   }
   if (quiet && verbose) {
      fprintf(stderr, "%s : Only one of -q and -v may be specified%s", "randword", "\n");
      exit(1);
   }
   if (stopAfterWord) {
      xWordLen = strlen(xWord);
      if (CheckOnDisk(xWord, xWordLen) == 0) {
  fprintf(stderr, "%s : Specified word is not in the dictionary%s", "randword", "\n");
  exit(1);
      }
      else if (xWordLen < minWordLength || xWordLen > maxWordLength) {
         fprintf(stderr, "%s : The specified word will never be found%s", "randword", "\n");
         exit(1);
      }
   }
   if (stopAfterLength) {
      if (xLength < minWordLength || xLength > maxWordLength) {
         fprintf(stderr, "%s : A word of the specified length will never be found%s", "randword", "\n");
         exit(1);
      }
   }
}

canonical_original_code:
void argSanityCheck() {
   int xWordLen;
   if (minWordLength > maxWordLength) {
      fprintf(stderr, "%s : Minimum word length exceeds maximum word length%s", "randword", "\n");
      exit(1);
   }
   if (quiet && verbose) {
      fprintf(stderr, "%s : Only one of -q and -v may be specified%s", "randword", "\n");
      exit(1);
   }
   if (stopAfterWord) {
      xWordLen = strlen(xWord);
      if (CheckOnDisk(xWord, xWordLen) == 0) {
  fprintf(stderr, "%s : Specified word is not in the dictionary%s", "randword", "\n");
  exit(1);
      }
      else if (xWordLen < minWordLength || xWordLen > maxWordLength) {
         fprintf(stderr, "%s : The specified word will never be found%s", "randword", "\n");
         exit(1);
      }
   }
   if (stopAfterLength) {
      if (xLength < minWordLength || xLength > maxWordLength) {
         fprintf(stderr, "%s : A word of the specified length will never be found%s", "randword", "\n");
         exit(1);
      }
   }
}

variable_types: xWordLen int