original_code:
size_t cuckoo_hf (size_t index,
  signed_integral_type source_node,
  character_type letter,
  const hash_settings *hs) {
 unsigned long long key =
  (unsigned long long)(source_node) ^
  ((unsigned long long)(letter) << 32);
 return (size_t)(((
    (unsigned long long)(hs->chf_as[index]) *
    key +
    (unsigned long long)(hs->chf_bs[index])) %
    (unsigned long long)(hs->npu_size)) %
   (unsigned long long)(hs->cp_sizes[index]) +
   (unsigned long long)(hs->cp_offsets[index]));
}

canonical_original_code:
unsigned long cuckoo_hf(unsigned long index, int source_node, char letter, struct hash_settings_struct *hs) {
 unsigned long long key = (unsigned long long)(source_node) ^
  ((unsigned long long)(letter) << 32);
 return (unsigned long)(((
    (unsigned long long)(hs->chf_as[index]) *
    key +
    (unsigned long long)(hs->chf_bs[index])) %
    (unsigned long long)(hs->npu_size)) %
   (unsigned long long)(hs->cp_sizes[index]) +
   (unsigned long long)(hs->cp_offsets[index]));
}

variable_types:
index
unsigned long


repo: pbasista/stc

decompiled_code:
__int64 __fastcall st_slai_create_pwotd(__int64 a1, __int64 a2, __int64 a3, _QWORD *a4)
{
__int64 v4; // r15
unsigned __int64 v5; // r14
unsigned __int64 i; // rax
__int64 v10; // rsi
__int64 v11; // rax
__int64 v12; // rax
__int64 v13; // r12
__int64 v14; // r14
__int64 result; // rax

v4 = 0LL;
v5 = a3 + 1;
puts("Creating the suffix tree using the PWOTD algorithm\n");
if ( v5 > 0x100000 )
{
v4 = 1LL;
for ( i = v5 >> 25; i; i >>= 5 )
++v4;
}
if ( a1 >= 0 )
{
v10 = v4;
v4 = a1;
printf("Abandoning the automatically determined prefix length: %zu\n", v10);
}
printf("The selected prefix length: %zu\n\n", v4);
if ( (int)st_slai_allocate(a3, a4) > 0 )
{
fwrite("Suffix tree allocation error. Exiting.\n", 1uLL, 0x27uLL, stderr);
return 1LL;
}
if ( (int)pwotd_cdata_allocate(a3, a4 + 5) > 0 )
{
fwrite("Auxiliary data structures allocation error. Exiting.\n", 1uLL, 0x35uLL, stderr);
return 2LL;
}
pwotd_initialize_suffixes(a4 + 5);
if ( v4 )
{
if ( (int)pwotd_partition_suffixes(v4, a2, a3, a4 + 5) > 0 )
{
fwrite("Error: Could not perform the partitioning phase! Exiting.\n", 1uLL, 0x3AuLL, stderr);
return 3LL;
}
}
else
{
if ( (int)pwotd_cdata_tsuffixes_tmp_reallocate(v5, a3, a4 + 5) > 0 )
{
fwrite(
"Error: Could not allocate the memory for the temporary table of suffixes! Exiting.\n",
1uLL,
0x53uLL,
stderr);
return 4LL;
}
if ( (int)pwotd_cdata_partitions_reallocate(1LL, a3, a4 + 5) > 0 )
{
fwrite("Error: Could not allocate the memory for the table of partitions! Exiting.\n", 1uLL, 0x4BuLL, stderr);
return 5LL;
}
a4[32] = 0LL;
puts("Creating a single partition!");
pwotd_insert_partition(1LL, a3 + 2, 0LL, a3, a4 + 5);
puts("The partition has been created!");
}
if ( (int)pwotd_cdata_partitions_tbp_reallocate(a4[20], a3, a4 + 5) > 0 )
{
fwrite(
"Error: st_slai_create_pwotd:\nCould not reallocate the memory\nfor the table of partitions to be processed.\n",
1uLL,
0x6AuLL,
stderr);
result = 6LL;
}
else if ( (int)pwotd_cdata_partitions_stack_reallocate(a4[32] << 8, a3, a4 + 5) > 0 )
{
fwrite("Error: Could not reallocate the memory for the partitions stack. Exiting.\n", 1uLL, 0x4AuLL, stderr);
result = 7LL;
}
else
{
st_slai_process_partitions_range(0LL, a4[20], 0LL, 0LL, a2, a3, a4);
if ( (int)st_slai_empty_partitions_stack(a2, a3, a4) <= 0 )
{
while ( 1 )
{
v12 = a4[23];
if ( !v12 )
break;
v11 = v12 - 1;
a4[23] = v11;
st_slai_process_partition(
*(_QWORD *)(a4[13] + 24 * v11),
*(_QWORD *)(a4[13] + 24 * v11 + 8),
*(_QWORD *)(a4[13] + 24 * v11 + 16),
a2,
a3,
a4);
}
pwotd_print_memory_usage_stats(stdout, a3, a4 + 5);
v13 = a4[34];
v14 = a4[33];
if ( (int)pwotd_cdata_deallocate(a4 + 5) > 0 )
{
fwrite("Deallocation error. Exiting.\n", 1uLL, 0x1DuLL, stderr);
result = 9LL;
}
else
{
puts("\nThe suffix tree has been successfully created.");
st_print_stats(a3, 0LL, a4[1], a4[2] - 1LL, 0LL, 0LL, a4[3], 0LL, 0LL, 0LL, 4LL, v13, v14);
result = 0LL;
}
}
else
{
fwrite("Error: Could not successfully empty the partitions stack Exiting.\n", 1uLL, 0x42uLL, stderr);
result = 8LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int64 a2, __int64 a3, _QWORD *a4)
{
__int64 v4; // r15
unsigned __int64 v5; // r14
unsigned __int64 i; // rax
__int64 v10; // rsi
__int64 v11; // rax
__int64 v12; // rax
__int64 v13; // r12
__int64 v14; // r14
__int64 result; // rax

v4 = 0LL;
v5 = a3 + 1;
puts("Creating the suffix tree using the PWOTD algorithm\n");
if ( v5 > 0x100000 )
{
v4 = 1LL;
for ( i = v5 >> 25; i; i >>= 5 )
++v4;
}
if ( a1 >= 0 )
{
v10 = v4;
v4 = a1;
printf("Abandoning the automatically determined prefix length: %zu\n", v10);
}
printf("The selected prefix length: %zu\n\n", v4);
if ( (int)st_slai_allocate(a3, a4) > 0 )
{
fwrite("Suffix tree allocation error. Exiting.\n", 1uLL, 0x27uLL, stderr);
return 1LL;
}
if ( (int)pwotd_cdata_allocate(a3, a4 + 5) > 0 )
{
fwrite("Auxiliary data structures allocation error. Exiting.\n", 1uLL, 0x35uLL, stderr);
return 2LL;
}
pwotd_initialize_suffixes(a4 + 5);
if ( v4 )
{
if ( (int)pwotd_partition_suffixes(v4, a2, a3, a4 + 5) > 0 )
{
fwrite("Error: Could not perform the partitioning phase! Exiting.\n", 1uLL, 0x3AuLL, stderr);
return 3LL;
}
}
else
{
if ( (int)pwotd_cdata_tsuffixes_tmp_reallocate(v5, a3, a4 + 5) > 0 )
{
fwrite(
"Error: Could not allocate the memory for the temporary table of suffixes! Exiting.\n",
1uLL,
0x53uLL,
stderr);
return 4LL;
}
if ( (int)pwotd_cdata_partitions_reallocate(1LL, a3, a4 + 5) > 0 )
{
fwrite("Error: Could not allocate the memory for the table of partitions! Exiting.\n", 1uLL, 0x4BuLL, stderr);
return 5LL;
}
a4[32] = 0LL;
puts("Creating a single partition!");
pwotd_insert_partition(1LL, a3 + 2, 0LL, a3, a4 + 5);
puts("The partition has been created!");
}
if ( (int)pwotd_cdata_partitions_tbp_reallocate(a4[20], a3, a4 + 5) > 0 )
{
fwrite(
"Error: st_slai_create_pwotd:\nCould not reallocate the memory\nfor the table of partitions to be processed.\n",
1uLL,
0x6AuLL,
stderr);
result = 6LL;
}
else if ( (int)pwotd_cdata_partitions_stack_reallocate(a4[32] << 8, a3, a4 + 5) > 0 )
{
fwrite("Error: Could not reallocate the memory for the partitions stack. Exiting.\n", 1uLL, 0x4AuLL, stderr);
result = 7LL;
}
else
{
st_slai_process_partitions_range(0LL, a4[20], 0LL, 0LL, a2, a3, a4);
if ( (int)st_slai_empty_partitions_stack(a2, a3, a4) <= 0 )
{
while ( 1 )
{
v12 = a4[23];
if ( !v12 )
break;
v11 = v12 - 1;
a4[23] = v11;
st_slai_process_partition(
*(_QWORD *)(a4[13] + 24 * v11),
*(_QWORD *)(a4[13] + 24 * v11 + 8),
*(_QWORD *)(a4[13] + 24 * v11 + 16),
a2,
a3,
a4);
}
pwotd_print_memory_usage_stats(stdout, a3, a4 + 5);
v13 = a4[34];
v14 = a4[33];
if ( (int)pwotd_cdata_deallocate(a4 + 5) > 0 )
{
fwrite("Deallocation error. Exiting.\n", 1uLL, 0x1DuLL, stderr);
result = 9LL;
}
else
{
puts("\nThe suffix tree has been successfully created.");
st_print_stats(a3, 0LL, a4[1], a4[2] - 1LL, 0LL, 0LL, a4[3], 0LL, 0LL, 0LL, 4LL, v13, v14);
result = 0LL;
}
}
else
{
fwrite("Error: Could not successfully empty the partitions stack Exiting.\n", 1uLL, 0x42uLL, stderr);
result = 8LL;
}
}
return result;
}

original_code:
int st_slai_create_pwotd (long int desired_prefix_length,
  const character_type *text,
  size_t length,
  suffix_tree_slai *stree) {
 size_t prefix_length = 0;
 size_t text_length = length + 1;
 size_t tmp_text_length = text_length;
 size_t extra_allocated_memory_size = 0;
 size_t extra_used_memory_size = 0;
 partition_process_record_pwotd *ppr = ((void *)0);
 printf("Creating the suffix tree using the PWOTD algorithm\n\n");
 if (tmp_text_length > 1048576) {
  prefix_length = 1;
  tmp_text_length = tmp_text_length >> 25;
  while (tmp_text_length > 0) {
   ++prefix_length;
   tmp_text_length = tmp_text_length >> 5;
  }
 }
 if (desired_prefix_length >= 0) {
  printf("Abandoning the automatically determined "
    "prefix length: %zu\n", prefix_length);
  prefix_length = (size_t)(desired_prefix_length);
 }
 printf("The selected prefix length: %zu\n\n",
   prefix_length);
 if (st_slai_allocate(length, stree) > 0) {
  fprintf(stderr, "Suffix tree allocation error. Exiting.\n");
  return (1);
 }
 if (pwotd_cdata_allocate(length, &stree->cdata) > 0) {
  fprintf(stderr, "Auxiliary data structures "
    "allocation error. Exiting.\n");
  return (2);
 }
 pwotd_initialize_suffixes(&stree->cdata);
 if (prefix_length > 0) {
  if (pwotd_partition_suffixes(prefix_length, text,
     length, &stree->cdata) > 0) {
   fprintf(stderr, "Error: Could not perform "
     "the partitioning phase! Exiting.\n");
   return (3);
  }
 } else {
  if (pwotd_cdata_tsuffixes_tmp_reallocate(text_length,
     length, &stree->cdata) > 0) {
   fprintf(stderr, "Error: Could not allocate "
     "the memory for the temporary "
     "table of suffixes! Exiting.\n");
   return (4);
  }
  if (pwotd_cdata_partitions_reallocate((size_t)(1),
     length, &stree->cdata) > 0) {
   fprintf(stderr, "Error: Could not allocate "
     "the memory for the table "
     "of partitions! Exiting.\n");
   return (5);
  }
  stree->cdata.prefix_length = 0;
  printf("Creating a single partition!\n");
  pwotd_insert_partition((size_t)(1), text_length + 1,
    (size_t)(0), length, &stree->cdata);
  printf("The partition has been created!\n");
 }
 if (pwotd_cdata_partitions_tbp_reallocate(
    stree->cdata.partitions_number,
    length, &stree->cdata) > 0) {
  fprintf(stderr, "Error: st_slai_create_pwotd:\n"
    "Could not reallocate the memory\n"
    "for the table of partitions "
    "to be processed.\n");
  return (6);
 }
 if (pwotd_cdata_partitions_stack_reallocate(
    256 * stree->cdata.prefix_length,
    length, &stree->cdata) > 0) {
  fprintf(stderr, "Error: Could not reallocate "
    "the memory for the partitions "
    "stack. Exiting.\n");
  return (7);
 }
 st_slai_process_partitions_range((size_t)(0),
   stree->cdata.partitions_number,
   (size_t)(0), (size_t)(0),
   text, length, stree);
 if (st_slai_empty_partitions_stack(text, length, stree) > 0) {
  fprintf(stderr, "Error: Could not successfully "
    "empty the partitions stack "
    "Exiting.\n");
  return (8);
 }
 while (stree->cdata.partitions_tbp_number > 0) {
  --stree->cdata.partitions_tbp_number;
  ppr = stree->cdata.partitions_tbp +
   stree->cdata.partitions_tbp_number;
  st_slai_process_partition(ppr->index, ppr->tnode_offset,
    ppr->parents_depth, text, length, stree);
 }
 pwotd_print_memory_usage_stats(stdout, length, &stree->cdata);
 extra_allocated_memory_size = stree->cdata.maximum_memory_allocated;
 extra_used_memory_size = stree->cdata.total_memory_allocated;
 if (pwotd_cdata_deallocate(&stree->cdata) > 0) {
  fprintf(stderr, "Deallocation error. Exiting.\n");
  return (9);
 }
 printf("\nThe suffix tree has been successfully created.\n");
 st_print_stats(length, (size_t)(0), stree->branching_nodes,
   stree->tnode_top - 1, (size_t)(0), (size_t)(0),
   stree->tnode_size, (size_t)(0), (size_t)(0),
   (size_t)(0), sizeof (unsigned_integral_type),
   extra_allocated_memory_size,
   extra_used_memory_size);
 return (0);
}

canonical_original_code:
int st_slai_create_pwotd(long desired_prefix_length, char *text, unsigned long length, struct suffix_tree_slai_struct *stree) {
 unsigned long prefix_length = 0;
 unsigned long text_length = length + 1;
 unsigned long tmp_text_length = text_length;
 unsigned long extra_allocated_memory_size = 0;
 unsigned long extra_used_memory_size = 0;
 struct partition_process_record_pwotd_struct *ppr = ((void *)0);
 printf("Creating the suffix tree using the PWOTD algorithm\n\n");
 if (tmp_text_length > 1048576) {
  prefix_length = 1;
  tmp_text_length = tmp_text_length >> 25;
  while (tmp_text_length > 0) {
   ++prefix_length;
   tmp_text_length = tmp_text_length >> 5;
  }
 }
 if (desired_prefix_length >= 0) {
  printf("Abandoning the automatically determined "
    "prefix length: %zu\n", prefix_length);
  prefix_length = (unsigned long)(desired_prefix_length);
 }
 printf("The selected prefix length: %zu\n\n",
   prefix_length);
 if (st_slai_allocate(length, stree) > 0) {
  fprintf(stderr, "Suffix tree allocation error. Exiting.\n");
  return (1);
 }
 if (pwotd_cdata_allocate(length, &stree->cdata) > 0) {
  fprintf(stderr, "Auxiliary data structures "
    "allocation error. Exiting.\n");
  return (2);
 }
 pwotd_initialize_suffixes(&stree->cdata);
 if (prefix_length > 0) {
  if (pwotd_partition_suffixes(prefix_length, text,
     length, &stree->cdata) > 0) {
   fprintf(stderr, "Error: Could not perform "
     "the partitioning phase! Exiting.\n");
   return (3);
  }
 } else {
  if (pwotd_cdata_tsuffixes_tmp_reallocate(text_length,
     length, &stree->cdata) > 0) {
   fprintf(stderr, "Error: Could not allocate "
     "the memory for the temporary "
     "table of suffixes! Exiting.\n");
   return (4);
  }
  if (pwotd_cdata_partitions_reallocate((unsigned long)(1),
     length, &stree->cdata) > 0) {
   fprintf(stderr, "Error: Could not allocate "
     "the memory for the table "
     "of partitions! Exiting.\n");
   return (5);
  }
  stree->cdata.prefix_length = 0;
  printf("Creating a single partition!\n");
  pwotd_insert_partition((unsigned long)(1), text_length + 1,
    (unsigned long)(0), length, &stree->cdata);
  printf("The partition has been created!\n");
 }
 if (pwotd_cdata_partitions_tbp_reallocate(
    stree->cdata.partitions_number,
    length, &stree->cdata) > 0) {
  fprintf(stderr, "Error: st_slai_create_pwotd:\n"
    "Could not reallocate the memory\n"
    "for the table of partitions "
    "to be processed.\n");
  return (6);
 }
 if (pwotd_cdata_partitions_stack_reallocate(
    256 * stree->cdata.prefix_length,
    length, &stree->cdata) > 0) {
  fprintf(stderr, "Error: Could not reallocate "
    "the memory for the partitions "
    "stack. Exiting.\n");
  return (7);
 }
 st_slai_process_partitions_range((unsigned long)(0),
   stree->cdata.partitions_number,
   (unsigned long)(0), (unsigned long)(0),
   text, length, stree);
 if (st_slai_empty_partitions_stack(text, length, stree) > 0) {
  fprintf(stderr, "Error: Could not successfully "
    "empty the partitions stack "
    "Exiting.\n");
  return (8);
 }
 while (stree->cdata.partitions_tbp_number > 0) {
  --stree->cdata.partitions_tbp_number;
  ppr = stree->cdata.partitions_tbp +
   stree->cdata.partitions_tbp_number;
  st_slai_process_partition(ppr->index, ppr->tnode_offset,
    ppr->parents_depth, text, length, stree);
 }
 pwotd_print_memory_usage_stats(stdout, length, &stree->cdata);
 extra_allocated_memory_size = stree->cdata.maximum_memory_allocated;
 extra_used_memory_size = stree->cdata.total_memory_allocated;
 if (pwotd_cdata_deallocate(&stree->cdata) > 0) {
  fprintf(stderr, "Deallocation error. Exiting.\n");
  return (9);
 }
 printf("\nThe suffix tree has been successfully created.\n");
 st_print_stats(length, (unsigned long)(0), stree->branching_nodes,
   stree->tnode_top - 1, (unsigned long)(0), (unsigned long)(0),
   stree->tnode_size, (unsigned long)(0), (unsigned long)(0),
   (unsigned long)(0), sizeof (unsigned_integral_type),
   extra_allocated_memory_size,
   extra_used_memory_size);
 return (0);
}

variable_types:
text
char *

variable_types:
length
unsigned long

variable_types: struct suffix_tree_slai_struct { unsigned int *tnode; unsigned long branching_nodes; unsigned long tnode_top; unsigned long tnode_size; unsigned long tnode_size_increase; struct pwotd_construction_data_struct { unsigned long s_size; unsigned long pr_size; unsigned long ppr_size; unsigned long psr_size; unsigned long sr_size; unsigned int *tsuffixes; unsigned int *tsuffixes_tmp; struct partition_record_pwotd_struct { unsigned long begin_offset; unsigned long end_offset; unsigned long lcp_size; unsigned long text_offset; } *partitions; struct partition_process_record_pwotd_struct { unsigned long index; unsigned long tnode_offset; unsigned long parents_depth; } *partitions_tbp; unsigned int *current_partition; struct partitions_stack_record_pwotd_struct { unsigned long range_begin; unsigned long range_end; unsigned long lcp_size; unsigned long tnode_offset; } *partitions_stack; struct stack_record_pwotd_struct { unsigned long range_begin; unsigned long range_end; unsigned long lcp_size; unsigned long tnode_offset; } *stack; unsigned long tsuffixes_size; unsigned long tsuffixes_tmp_size; unsigned long cp_index; unsigned long partitions_number; unsigned long partitions_size; unsigned long partitions_size_increase; unsigned long partitions_tbp_number; unsigned long partitions_tbp_size; unsigned long partitions_tbp_size_increase; unsigned long partitions_stack_top; unsigned long partitions_stack_size; unsigned long partitions_stack_size_increase; unsigned long stack_top; unsigned long stack_size; unsigned long stack_size_increase; unsigned long prefix_length; unsigned long total_memory_allocated; unsigned long maximum_memory_allocated; } cdata; } *

return_type: int

user_defined_types: struct suffix_tree_slai_struct { unsigned int *tnode; unsigned long branching_nodes; unsigned long tnode_top; unsigned long tnode_size; unsigned long tnode_size_increase; struct pwotd_construction_data_struct cdata; }

user_defined_types: struct pwotd_construction_data_struct { unsigned long s_size; unsigned long pr_size; unsigned long ppr_size; unsigned long psr_size; unsigned long sr_size; unsigned int *tsuffixes; unsigned int *tsuffixes_tmp; struct partition_record_pwotd_struct *partitions; struct partition_process_record_pwotd_struct *partitions_tbp; unsigned int *current_partition; struct partitions_stack_record_pwotd_struct *partitions_stack; struct stack_record_pwotd_struct *stack; unsigned long tsuffixes_size; unsigned long tsuffixes_tmp_size; unsigned long cp_index; unsigned long partitions_number; unsigned long partitions_size; unsigned long partitions_size_increase; unsigned long partitions_tbp_number; unsigned long partitions_tbp_size; unsigned long partitions_tbp_size_increase; unsigned long partitions_stack_top; unsigned long partitions_stack_size; unsigned long partitions_stack_size_increase; unsigned long stack_top; unsigned long stack_size; unsigned long stack_size_increase; unsigned long prefix_length; unsigned long total_memory_allocated; unsigned long maximum_memory_allocated; }


ullrandom

decompiled_code:
unsigned __int64 __fastcall ullrandom(unsigned __int64 a1)
{
__int64 v1; // rbp

v1 = random();
return (v1 | (unsigned __int64)(random() << 32)) % a1;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func0(unsigned __int64 a1)
{
__int64 v1; // rbp

v1 = random();
return (v1 | (unsigned __int64)(random() << 32)) % a1;
}

original_code:
ull ullrandom (ull upper_bound) {
 ull result = 0;
 long int low_bits = random();
 long int high_bits = random();
 result = (((ull)(high_bits) << 32) | (ull)(low_bits)) % upper_bound;
 return (result);
}

canonical_original_code:
unsigned long long ullrandom(unsigned long long upper_bound) {
 unsigned long long result = 0;
 long low_bits = random();
 long high_bits = random();
 result = (((ull)(high_bits) << 32) | (ull)(low_bits)) % upper_bound;
 return (result);
}

variable_types:
result
unsigned long long

return_type: unsigned long long


decompiled_code:
unsigned __int64 __fastcall mul_modular(unsigned __int64 a1, unsigned __int64 a2, unsigned __int64 a3)
{
unsigned __int64 v3; // r9
unsigned __int64 i; // r8

v3 = 0LL;
for ( i = a1 % a3; a2; i = 2 * i % a3 )
{
if ( (a2 & 1) != 0 )
v3 = (v3 + i) % a3;
a2 >>= 1;
}
return v3;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func1(unsigned __int64 a1, unsigned __int64 a2, unsigned __int64 a3)
{
unsigned __int64 v3; // r9
unsigned __int64 i; // r8

v3 = 0LL;
for ( i = a1 % a3; a2; i = 2 * i % a3 )
{
if ( (a2 & 1) != 0 )
v3 = (v3 + i) % a3;
a2 >>= 1;
}
return v3;
}

original_code:
ull mul_modular (ull a, ull b, ull c) {
 ull result = 0;
 ull add = a % c;
 while (b > 0) {
  if (b % 2 == 1) {
   result = (result + add) % c;
  }
  add = add * 2 % c;
  b /= 2;
 }
 return (result);
}

canonical_original_code:
unsigned long long mul_modular(unsigned long long a, unsigned long long b, unsigned long long c) {
 unsigned long long result = 0;
 unsigned long long add = a % c;
 while (b > 0) {
  if (b % 2 == 1) {
   result = (result + add) % c;
  }
  add = add * 2 % c;
  b /= 2;
 }
 return (result);
}

variable_types:
a
unsigned long long

variable_types:
b
unsigned long long

variable_types:
c
unsigned long long

variable_types:
add
unsigned long long


decompiled_code:
__int64 __fastcall pow_modular(unsigned __int64 a1, __int64 a2, unsigned __int64 a3)
{
unsigned __int64 v4; // r11
__int64 v6; // rbp
unsigned __int64 v7; // rax
unsigned __int64 v8; // r11

if ( !a2 )
return 1LL;
LOBYTE(v4) = a2;
v6 = 1LL;
do
{
if ( (v4 & 1) != 0 )
v6 = mul_modular(v6, a1, a3);
v7 = mul_modular(a1, a1, a3);
v4 = v8 >> 1;
a1 = v7;
}
while ( v4 );
return v6;
}

canonical_decompiled_code:
__int64 __fastcall func2(unsigned __int64 a1, __int64 a2, unsigned __int64 a3)
{
unsigned __int64 v4; // r11
__int64 v6; // rbp
unsigned __int64 v7; // rax
unsigned __int64 v8; // r11

if ( !a2 )
return 1LL;
LOBYTE(v4) = a2;
v6 = 1LL;
do
{
if ( (v4 & 1) != 0 )
v6 = func1(v6, a1, a3);
v7 = func1(a1, a1, a3);
v4 = v8 >> 1;
a1 = v7;
}
while ( v4 );
return v6;
}

original_code:
ull pow_modular (ull a, ull b, ull c) {
 ull result = 1;
 ull mul = a;
 while (b > 0) {
  if (b % 2 == 1) {
   result = mul_modular(result, mul, c);
  }
  mul = mul_modular(mul, mul, c);
  b /= 2;
 }
 return (result);
}

canonical_original_code:
unsigned long long pow_modular(unsigned long long a, unsigned long long b, unsigned long long c) {
 unsigned long long result = 1;
 unsigned long long mul = a;
 while (b > 0) {
  if (b % 2 == 1) {
   result = mul_modular(result, mul, c);
  }
  mul = mul_modular(mul, mul, c);
  b /= 2;
 }
 return (result);
}

variable_types:
mul
unsigned long long


decompiled_code:
unsigned __int64 __fastcall fermat_test(unsigned __int64 a1, __int64 a2)
{
unsigned __int64 v2; // rbp
__int64 v3; // rbx
unsigned __int64 v4; // r12

if ( !a2 )
return 0LL;
v2 = a1 - 1;
v3 = 0LL;
while ( 1 )
{
v4 = ullrandom(v2) + 1;
if ( pow_modular(v4, v2, a1) != 1 )
break;
if ( a2 == ++v3 )
return 0LL;
}
return v4;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func3(unsigned __int64 a1, __int64 a2)
{
unsigned __int64 v2; // rbp
__int64 v3; // rbx
unsigned __int64 v4; // r12

if ( !a2 )
return 0LL;
v2 = a1 - 1;
v3 = 0LL;
while ( 1 )
{
v4 = func0(v2) + 1;
if ( func2(v4, v2, a1) != 1 )
break;
if ( a2 == ++v3 )
return 0LL;
}
return v4;
}

original_code:
ull fermat_test (ull number, ull repeats) {
 ull i = 0;
 ull nd1 = number - 1;
 ull witness = 0;
 for (i = 0; i < repeats; ++i) {
  witness = ullrandom(nd1) + 1;
  if (pow_modular(witness, nd1, number) != 1) {
   return (witness);
  }
 }
 return (0);
}

canonical_original_code:
unsigned long long fermat_test(unsigned long long number, unsigned long long repeats) {
 unsigned long long i = 0;
 unsigned long long nd1 = number - 1;
 unsigned long long witness = 0;
 for (i = 0; i < repeats; ++i) {
  witness = ullrandom(nd1) + 1;
  if (pow_modular(witness, nd1, number) != 1) {
   return (witness);
  }
 }
 return (0);
}

variable_types:
number
unsigned long long

variable_types:
repeats
unsigned long long

variable_types:
i
unsigned long long

variable_types:
witness
unsigned long long


decompiled_code:
unsigned __int64 __fastcall mr_test(unsigned __int64 a1, __int64 a2)
{
unsigned __int64 v2; // rbx
__int64 v3; // r12
unsigned __int64 v4; // r15
unsigned __int64 v5; // r14
__int64 v6; // rax

if ( !a2 )
return 0LL;
v2 = a1 - 1;
v3 = 0LL;
while ( 1 )
{
v4 = ullrandom(v2) + 1;
if ( pow_modular(v4, v2, a1) != 1 )
break;
v5 = a1 - 1;
while ( (v5 & 1) == 0 )
{
v5 >>= 1;
v6 = pow_modular(v4, v5, a1);
if ( v2 == v6 )
break;
if ( v6 != 1 )
return v4;
}
if ( a2 == ++v3 )
return 0LL;
}
return v4;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func4(unsigned __int64 a1, __int64 a2)
{
unsigned __int64 v2; // rbx
__int64 v3; // r12
unsigned __int64 v4; // r15
unsigned __int64 v5; // r14
__int64 v6; // rax

if ( !a2 )
return 0LL;
v2 = a1 - 1;
v3 = 0LL;
while ( 1 )
{
v4 = func0(v2) + 1;
if ( func2(v4, v2, a1) != 1 )
break;
v5 = a1 - 1;
while ( (v5 & 1) == 0 )
{
v5 >>= 1;
v6 = func2(v4, v5, a1);
if ( v2 == v6 )
break;
if ( v6 != 1 )
return v4;
}
if ( a2 == ++v3 )
return 0LL;
}
return v4;
}

original_code:
ull mr_test (ull number, ull repeats) {
 ull i = 0;
 ull witness = 0;
 ull nd1 = number - 1;
 ull rex = 0;
 ull mod = 0;
 for (i = 0; i < repeats; ++i) {
  witness = ullrandom(nd1) + 1;
  if (pow_modular(witness, nd1, number) == 1) {
   rex = nd1;
   while (rex % 2 == 0) {
    rex /= 2;
    mod = pow_modular(witness, rex, number);
    if (mod == nd1) {
     break;
    } else if (mod != 1) {
     return (witness);
    }
   }
  } else {
   return (witness);
  }
 }
 return (0);
}

canonical_original_code:
unsigned long long mr_test(unsigned long long number, unsigned long long repeats) {
 unsigned long long i = 0;
 unsigned long long witness = 0;
 unsigned long long nd1 = number - 1;
 unsigned long long rex = 0;
 unsigned long long mod = 0;
 for (i = 0; i < repeats; ++i) {
  witness = ullrandom(nd1) + 1;
  if (pow_modular(witness, nd1, number) == 1) {
   rex = nd1;
   while (rex % 2 == 0) {
    rex /= 2;
    mod = pow_modular(witness, rex, number);
    if (mod == nd1) {
     break;
    } else if (mod != 1) {
     return (witness);
    }
   }
  } else {
   return (witness);
  }
 }
 return (0);
}

variable_types:
rex
unsigned long long

variable_types:
mod
unsigned long long


decompiled_code:
unsigned __int64 __fastcall next_prime(unsigned __int64 a1)
{
do
++a1;
while ( mr_test(a1, 100LL) );
return a1;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func5(unsigned __int64 a1)
{
do
++a1;
while ( func4(a1, 100LL) );
return a1;
}

original_code:
ull next_prime (ull number) {
 while (mr_test(++number, (ull)(100)) != 0) {
 }
 return (number);
}

canonical_original_code:
unsigned long long next_prime(unsigned long long number) {
 while (mr_test(++number, (ull)(100)) != 0) {
 }
 return (number);
}


main

canonical_name: main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // eax
unsigned int v4; // eax
unsigned int v5; // ebp
_BYTE v6[40]; // [rsp+0h] [rbp-28h] BYREF

if ( argc != 4 )
{
fprintf(
stderr,
"Exactly three arguments expected: hostname, numeric port, timeout in seconds. %d received instead.\n",
(unsigned int)(argc - 1));
exit(1);
}
v3 = atoi(argv[3]);
if ( (unsigned int)set_up_timeout(v6, v3) )
{
v4 = connect_to(argv[1], argv[2]);
v5 = v4;
if ( v4 != -1 )
{
if ( (int)wait_for_socket(v4, v6) > 0 )
{
if ( (unsigned int)get_socket_error(v5) )
{
fwrite("Connection closed.\n", 1uLL, 0x13uLL, stderr);
exit(1);
}
exit(0);
}
fwrite("Connection timed out.\n", 1uLL, 0x16uLL, stderr);
exit(1);
}
fwrite("Failed to open a socket. Invalid hostname or port number?\n", 1uLL, 0x3AuLL, stderr);
exit(1);
}
fprintf(stderr, "Invalid timeout \"%s\" specified. Must be a positive integer.\n", argv[3]);
exit(1);
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // eax
unsigned int v4; // eax
unsigned int v5; // ebp
_BYTE v6[40]; // [rsp+0h] [rbp-28h] BYREF

if ( argc != 4 )
{
fprintf(
stderr,
"Exactly three arguments expected: hostname, numeric port, timeout in seconds. %d received instead.\n",
(unsigned int)(argc - 1));
exit(1);
}
v3 = atoi(argv[3]);
if ( (unsigned int)func7(v6, v3) )
{
v4 = func10(argv[1], argv[2]);
v5 = v4;
if ( v4 != -1 )
{
if ( (int)func11(v4, v6) > 0 )
{
if ( (unsigned int)func12(v5) )
{
fwrite("Connection closed.\n", 1uLL, 0x13uLL, stderr);
exit(1);
}
exit(0);
}
fwrite("Connection timed out.\n", 1uLL, 0x16uLL, stderr);
exit(1);
}
fwrite("Failed to open a socket. Invalid hostname or port number?\n", 1uLL, 0x3AuLL, stderr);
exit(1);
}
fprintf(stderr, "Invalid timeout \"%s\" specified. Must be a positive integer.\n", argv[3]);
exit(1);
}

original_code:
int main(int argc, char **argv) {
 int handle_socket;
 struct timeval timeout;
 if (argc != (3 + 1)) {
  fprintf(stderr,
    "Exactly three arguments expected: hostname, numeric port, timeout in seconds. %d received instead.\n",
    argc - 1);
  exit(1);
 }
 if (! set_up_timeout(&timeout, atoi(argv[3]))) {
  fprintf(stderr,
    "Invalid timeout \"%s\" specified. Must be a positive integer.\n",
    argv[3]);
  exit(1);
 }
 if ((handle_socket = connect_to(argv[1], argv[2])) == -1) {
  fprintf(stderr,
    "Failed to open a socket. Invalid hostname or port number?\n");
  exit(1);
 }
 if (wait_for_socket(handle_socket, &timeout) <= 0) {
  fprintf(stderr, "Connection timed out.\n");
  exit(1);
 }
 if (get_socket_error(handle_socket) != 0) {
  fprintf(stderr, "Connection closed.\n");
  exit(1);
 }
 exit(0);
}

variable_types: argc int

variable_types:
argv
char **

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


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

result = 0LL;
if ( a2 > 0 )
{
a1[1] = 0LL;
*a1 = a2;
result = (unsigned int)a2;
}
return result;
}

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

result = 0LL;
if ( a2 > 0 )
{
a1[1] = 0LL;
*a1 = a2;
result = (unsigned int)a2;
}
return result;
}

original_code:
int set_up_timeout(struct timeval *timeout, int seconds) {
 if (seconds <= 0) {
  return 0;
 }
 timeout->tv_usec = 0;
 timeout->tv_sec = seconds;
 return seconds;
}

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

variable_types: seconds int


decompiled_code:
int __fastcall raise_socket_flags(int fd, __int64 a2)
{
int v2; // eax
int result; // eax

v2 = fcntl(fd, 3, 0LL);
if ( v2 == -1 )
result = -1;
else
result = fcntl(fd, 4, a2 | v2);
return result;
}

canonical_decompiled_code:
int __fastcall func8(int fd, __int64 a2)
{
int v2; // eax
int result; // eax

v2 = fcntl(fd, 3, 0LL);
if ( v2 == -1 )
result = -1;
else
result = fcntl(fd, 4, a2 | v2);
return result;
}

original_code:
int raise_socket_flags(int handle_socket, long new_socket_flags) {
 long socket_flags;
 if ((socket_flags = fcntl(handle_socket, 3, ((void *)0))) == -1) {
  return socket_flags;
 }
 socket_flags |= new_socket_flags;
 return fcntl(handle_socket, 4, socket_flags);
}


decompiled_code:
__int64 __fastcall connect_by_addrinfo(__int64 a1)
{
int v1; // eax
unsigned int v2; // er12

v1 = socket(2, 1, 6);
if ( v1 == -1
|| (v2 = v1, raise_socket_flags(v1, 2048LL) == -1)
|| connect(v2, *(const struct sockaddr **)(a1 + 24), *(_DWORD *)(a1 + 16)) != -1
|| *__errno_location() != 115 )
{
v2 = -1;
}
return v2;
}

original_code:
int connect_by_addrinfo(struct addrinfo *address_info) {
 int handle_socket;
 if ((handle_socket = socket(2, SOCK_STREAM, IPPROTO_TCP)) == -1) {
  return handle_socket;
 }
 if (raise_socket_flags(handle_socket, 04000) == -1) {
  return -1;
 }
 if (connect(handle_socket, address_info->ai_addr, address_info->ai_addrlen) != -1) {
  return -1;
 }
 if ((*__errno_location ()) != 115) {
  return -1;
 }
 return handle_socket;
}

variable_types: struct addrinfo { int ai_flags; int ai_family; int ai_socktype; int ai_protocol; unsigned int ai_addrlen; struct sockaddr { unsigned short sa_family; char sa_data[14]; } *ai_addr; char *ai_canonname; struct addrinfo *ai_next; } *

user_defined_types: struct addrinfo { int ai_flags; int ai_family; int ai_socktype; int ai_protocol; unsigned int ai_addrlen; struct sockaddr *ai_addr; char *ai_canonname; struct addrinfo *ai_next; }


decompiled_code:
__int64 __fastcall connect_to(const char *a1, const char *a2)
{
unsigned int v2; // er12
struct addrinfo *pai; // [rsp+8h] [rbp-10h] BYREF

if ( getaddrinfo(a1, a2, 0LL, &pai) )
return (unsigned int)-1;
v2 = connect_by_addrinfo((__int64)pai);
freeaddrinfo(pai);
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func10(const char *a1, const char *a2)
{
unsigned int v2; // er12
struct addrinfo *pai; // [rsp+8h] [rbp-10h] BYREF

if ( getaddrinfo(a1, a2, 0LL, &pai) )
return (unsigned int)-1;
v2 = func9((__int64)pai);
freeaddrinfo(pai);
return v2;
}

original_code:
int connect_to(const char *remote_addr, const char *remote_port) {
 struct addrinfo *address_info;
 int handle_socket;
 if (getaddrinfo(remote_addr, remote_port, ((void *)0), &address_info) != 0) {
  return -1;
 }
 handle_socket = connect_by_addrinfo(address_info);
 freeaddrinfo(address_info);
 return handle_socket;
}

canonical_original_code:
int connect_to(char *remote_addr, char *remote_port) {
 struct addrinfo *address_info;
 int handle_socket;
 if (getaddrinfo(remote_addr, remote_port, ((void *)0), &address_info) != 0) {
  return -1;
 }
 handle_socket = connect_by_addrinfo(address_info);
 freeaddrinfo(address_info);
 return handle_socket;
}

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


decompiled_code:
int __fastcall wait_for_socket(int a1, struct timeval *a2)
{
int v3; // eax
int v4; // edi
fd_set v6; // [rsp+0h] [rbp-88h] BYREF

memset(&v6, 0, sizeof(v6));
v3 = a1 + 63;
v4 = a1 + 1;
if ( a1 >= 0 )
v3 = a1;
v6.fds_bits[v3 >> 6] |= 1LL << (a1 % 64);
return select(v4, 0LL, &v6, 0LL, a2);
}

canonical_decompiled_code:
int __fastcall func11(int a1, struct timeval *a2)
{
int v3; // eax
int v4; // edi
fd_set v6; // [rsp+0h] [rbp-88h] BYREF

memset(&v6, 0, sizeof(v6));
v3 = a1 + 63;
v4 = a1 + 1;
if ( a1 >= 0 )
v3 = a1;
v6.fds_bits[v3 >> 6] |= 1LL << (a1 % 64);
return select(v4, 0LL, &v6, 0LL, a2);
}

original_code:
int wait_for_socket(int handle_socket, struct timeval *timeout) {
 fd_set handles_monitored;
 do { int __d0, __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&handles_monitored)->__fds_bits)[0]) : "memory"); } while (0);
 ((void) (((&handles_monitored)->__fds_bits)[((handle_socket) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((handle_socket) % (8 * (int) sizeof (__fd_mask)))))));
 return select(handle_socket + 1, ((void *)0), &handles_monitored, ((void *)0), timeout);
}

canonical_original_code:
int wait_for_socket(int handle_socket, struct timeval *timeout) {
 struct fd_set handles_monitored;
 do { int __d0; int __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&handles_monitored)->__fds_bits)[0]) : "memory"); } while (0);
 ((void) (((&handles_monitored)->__fds_bits)[((handle_socket) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((handle_socket) % (8 * (int) sizeof (__fd_mask)))))));
 return select(handle_socket + 1, ((void *)0), &handles_monitored, ((void *)0), timeout);
}

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


decompiled_code:
__int64 __fastcall get_socket_error(int a1)
{
__int64 result; // rax
unsigned int optval; // [rsp+8h] [rbp-10h] BYREF
socklen_t optlen[3]; // [rsp+Ch] [rbp-Ch] BYREF

optlen[0] = 4;
if ( getsockopt(a1, 1, 4, &optval, optlen) )
result = 0xFFFFFFFFLL;
else
result = optval;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func12(int a1)
{
__int64 result; // rax
unsigned int optval; // [rsp+8h] [rbp-10h] BYREF
socklen_t optlen[3]; // [rsp+Ch] [rbp-Ch] BYREF

optlen[0] = 4;
if ( getsockopt(a1, 1, 4, &optval, optlen) )
result = 0xFFFFFFFFLL;
else
result = optval;
return result;
}

original_code:
int get_socket_error(int handle_socket) {
 int socket_option;
 socklen_t socket_option_length = sizeof(socket_option);
 if (getsockopt(handle_socket, 1, 4, (void *)&socket_option, &socket_option_length) != 0) {
  return -1;
 }
 return socket_option;
}

canonical_original_code:
int get_socket_error(int handle_socket) {
 int socket_option;
 unsigned int socket_option_length = sizeof(socket_option);
 if (getsockopt(handle_socket, 1, 4, (void *)&socket_option, &socket_option_length) != 0) {
  return -1;
 }
 return socket_option;
}


repo: pbrisbin/android-receiver

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
int v3; // eax
int v4; // ebx
socklen_t v5; // edx
socklen_t addr_len; // [rsp+Ch] [rbp-42Ch] BYREF
struct sockaddr v7; // [rsp+10h] [rbp-428h] BYREF
struct sockaddr addr; // [rsp+20h] [rbp-418h] BYREF
char buf[1032]; // [rsp+30h] [rbp-408h] BYREF

addr_len = 16;
parse_options(argc, (char **)argv);
v3 = socket(2, 2, 0);
if ( v3 >= 0 )
{
v4 = v3;
v7 = 0LL;
v7.sa_family = 2;
*(_WORD *)v7.sa_data = _bswap_16((unsigned __int16)portno, &v7, 16LL);
if ( bind(v4, &v7, v5) >= 0 )
{
while ( 1 )
{
if ( (int)recvfrom(v4, buf, 0x400uLL, 0, &addr, &addr_len) < 0 )
{
if ( *__errno_location() != 4 )
{
perror("error receiving from socket");
exit(1);
}
}
else
{
handle_message(buf);
}
}
}
perror("error binding to socket");
exit(1);
}
perror("error opening socket");
exit(1);
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
int v3; // eax
int v4; // ebx
socklen_t v5; // edx
socklen_t addr_len; // [rsp+Ch] [rbp-42Ch] BYREF
struct sockaddr v7; // [rsp+10h] [rbp-428h] BYREF
struct sockaddr addr; // [rsp+20h] [rbp-418h] BYREF
char buf[1032]; // [rsp+30h] [rbp-408h] BYREF

addr_len = 16;
func7(argc, (char **)argv);
v3 = socket(2, 2, 0);
if ( v3 >= 0 )
{
v4 = v3;
v7 = 0LL;
v7.sa_family = 2;
*(_WORD *)v7.sa_data = func8((unsigned __int16)portno, &v7, 16LL);
if ( bind(v4, &v7, v5) >= 0 )
{
while ( 1 )
{
if ( (int)recvfrom(v4, buf, 0x400uLL, 0, &addr, &addr_len) < 0 )
{
if ( *__errno_location() != 4 )
{
perror("error receiving from socket");
exit(1);
}
}
else
{
func9(buf);
}
}
}
perror("error binding to socket");
exit(1);
}
perror("error opening socket");
exit(1);
}

original_code:
int main(int argc, char *argv[]) {
    char buf[1024];
    struct sockaddr_in server, from;
    int sock, n;
    unsigned int fromlen = sizeof from;
    parse_options(argc, argv);
    if ((sock = socket(2, SOCK_DGRAM, 0)) < 0) {
        perror("error opening socket");
        exit(1);
    }
    memset(&server, '\0', sizeof server);
    server.sin_family = 2;
    server.sin_port = htons(portno);
    server.sin_addr.s_addr = ((in_addr_t) 0x00000000);
    if (bind(sock, (struct sockaddr *)&server, sizeof server) < 0) {
        perror("error binding to socket");
        exit(1);
    }
    while (1) {
        while ((n = recvfrom(sock, buf, 1024, 0, (struct sockaddr *)&from, &fromlen)) < 0 && (*__errno_location ()) == 4)
            ;
        if (n < 0) {
            perror("error receiving from socket");
            exit(1);
        }
        handle_message(buf);
    }
}

canonical_original_code:
int main(int argc, char *argv[]) {
    char buf[1024];
    struct sockaddr_in server; struct sockaddr_in from;
    int sock; int n;
    unsigned int fromlen = sizeof from;
    parse_options(argc, argv);
    if ((sock = socket(2, SOCK_DGRAM, 0)) < 0) {
        perror("error opening socket");
        exit(1);
    }
    memset(&server, '\0', sizeof server);
    server.sin_family = 2;
    server.sin_port = htons(portno);
    server.sin_addr.s_addr = ((unsigned int) 0x00000000);
    if (bind(sock, (struct sockaddr *)&server, sizeof server) < 0) {
        perror("error binding to socket");
        exit(1);
    }
    while (1) {
        while ((n = recvfrom(sock, buf, 1024, 0, (struct sockaddr *)&from, &fromlen)) < 0 && (*__errno_location ()) == 4)
            ;
        if (n < 0) {
            perror("error receiving from socket");
            exit(1);
        }
        handle_message(buf);
    }
}

variable_types:
argv
char *[]

variable_types:
buf
char [1024]

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

variable_types: sock int

variable_types: n int

variable_types:
fromlen
unsigned int

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


decompiled_code:
int __fastcall parse_options(int argc, char **argv)
{
int result; // eax
int v3; // eax
int longind; // [rsp+4h] [rbp-24h] BYREF
char *endptr; // [rsp+8h] [rbp-20h] BYREF

longind = 0;
while ( 1 )
{
result = getopt_long(argc, argv, "hp:", &opts_0, &longind);
if ( result == -1 )
break;
if ( result == 104 )
{
puts("usage: android-receiver [ -p <port> ]");
exit(0);
}
if ( result != 112 )
{
fwrite("invalid option, try -h or --help\n", 1uLL, 0x21uLL, stderr);
exit(1);
}
v3 = strtol(optarg, &endptr, 10);
portno = v3;
if ( *endptr || (unsigned int)(v3 - 1) > 0xFFFE )
{
fwrite("invalid port number\n", 1uLL, 0x14uLL, stderr);
exit(1);
}
}
return result;
}

canonical_decompiled_code:
int __fastcall func7(int argc, char **argv)
{
int result; // eax
int v3; // eax
int longind; // [rsp+4h] [rbp-24h] BYREF
char *endptr; // [rsp+8h] [rbp-20h] BYREF

longind = 0;
while ( 1 )
{
result = getopt_long(argc, argv, "hp:", &opts_0, &longind);
if ( result == -1 )
break;
if ( result == 104 )
{
puts("usage: android-receiver [ -p <port> ]");
exit(0);
}
if ( result != 112 )
{
fwrite("invalid option, try -h or --help\n", 1uLL, 0x21uLL, stderr);
exit(1);
}
v3 = strtol(optarg, &endptr, 10);
portno = v3;
if ( *endptr || (unsigned int)(v3 - 1) > 0xFFFE )
{
fwrite("invalid port number\n", 1uLL, 0x14uLL, stderr);
exit(1);
}
}
return result;
}

original_code:
static void parse_options(int argc, char *argv[]) {
    int opt, option_index = 0;
    char *token;
    static struct option opts[] = {
        { "port" , 1, 0, 'p'},
        { "help" , 0, 0, 'h'},
        { 0 , 0 , 0, 0 }
    };
    while ((opt = getopt_long(argc, argv, "hp:", opts, &option_index)) != -1) {
        switch (opt) {
            case 'p':
                portno = strtol(optarg, &token, 10);
                if (*token != '\0' || portno <= 0 || portno > 65535) {
                    fprintf(stderr, "invalid port number\n");
                    exit(1);
                }
                break;
            case 'h':
                printf("usage: android-receiver [ -p <port> ]\n");
                exit(0);
            default:
                fprintf(stderr, "invalid option, try -h or --help\n");
                exit(1);
        }
    }
}

canonical_original_code:
static void parse_options(int argc, char *argv[]) {
    int opt; int option_index = 0;
    char *token;
    static struct option opts[] = {
        { "port" , 1, 0, 'p'},
        { "help" , 0, 0, 'h'},
        { 0 , 0 , 0, 0 }
    };
    while ((opt = getopt_long(argc, argv, "hp:", opts, &option_index)) != -1) {
        switch (opt) {
            case 'p':
                portno = strtol(optarg, &token, 10);
                if (*token != '\0' || portno <= 0 || portno > 65535) {
                    fprintf(stderr, "invalid port number\n");
                    exit(1);
                }
                break;
            case 'h':
                printf("usage: android-receiver [ -p <port> ]\n");
                exit(0);
            default:
                fprintf(stderr, "invalid option, try -h or --help\n");
                exit(1);
        }
    }
}

variable_types: opt int

variable_types:
token
char *

variable_types: struct option { char *name; int has_arg; int *flag; int val; } []

return_type: void


help

repo: pc-coholic/Quarto

decompiled_code:
int help()
{
puts("\nNutzung des Clienten:\tclient [Game-ID] -p [0|1] -c [dateinname] -l [0|1|2]");
puts(aPGew);
puts("\t-c:\tandere Konfigurationsdatei (Default: client.conf)");
puts(aLLoglevel0F);
return putchar(10);
}

canonical_decompiled_code:
int func0()
{
puts("\nNutzung des Clienten:\tclient [Game-ID] -p [0|1] -c [dateinname] -l [0|1|2]");
puts(aPGew);
puts("\t-c:\tandere Konfigurationsdatei (Default: client.conf)");
puts(aLLoglevel0F);
return putchar(10);
}

original_code:
void help() {
 printf("\nNutzung des Clienten:	client [Game-ID] -p [0|1] -c [dateinname] -l [0|1|2]\n");
 printf("\n	-p:	gewünschte Spielernummer: 0 für Spieler 1, 1 für Spieler 2\n");
 printf("	-c:	andere Konfigurationsdatei (Default: client.conf)\n");
 printf("	-l:	Loglevel: 0 für Errors, 1 für Spielinfo, 2 für Debuginfo (Default steht in Konfigurationsdatei\n");
 printf("\n");
}


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char *v3; // r13
unsigned int v4; // ebp
int v5; // eax
const char *v6; // rdi
__int64 v7; // r12
__pid_t v8; // eax
bool v9; // cf
bool v10; // zf
__int64 v11; // rax
__int64 v12; // rdx
__int64 v13; // rcx
const char *v14; // rdi
const char *v15; // rsi
char *v16; // r8
char v17; // al
bool v18; // cf
bool v19; // zf
__int64 v20; // rcx
const char *v21; // rsi
const char *v22; // rdi
bool v23; // al
bool v24; // cf
bool v25; // zf
__int64 v26; // rcx
const char *v27; // rsi
const char *v28; // rdi
char v29; // al
bool v30; // cf
bool v31; // zf
__int64 v32; // rcx
const char *v33; // rsi
const char *v34; // rdi
char *v35; // rdi
__int64 v36; // rdx
__int64 v37; // rcx
__int64 v38; // rdx
__int64 v39; // rcx
__pid_t v40; // eax
char *s1; // [rsp+8h] [rbp-C70h]
char *s1a; // [rsp+8h] [rbp-C70h]
char v44[3072]; // [rsp+10h] [rbp-C68h] BYREF
int v45; // [rsp+C10h] [rbp-68h]
int pipedes[2]; // [rsp+C28h] [rbp-50h] BYREF
char dest[71]; // [rsp+C31h] [rbp-47h] BYREF

v3 = (char *)malloc(0x100uLL);
strcpy(v3, "client.conf");
log_printf(2LL, "Using config-file %s\n", v3);
get_config(v44, v3);
qmemcpy(&configstruct, v44, 0xC00uLL);
*((_DWORD *)&configstruct + 768) = v45;
log_printf(1LL, "\n");
if ( argc <= 1 )
{
v6 = "Keine Game-Id angegeben!";
goto LABEL_9;
}
if ( stpcpy(dest, argv[1]) - dest != 11 )
{
v6 = "Game-Id muss 11-stellig sein!";
goto LABEL_9;
}
v4 = 51;
while ( 1 )
{
v5 = getopt(argc, (char *const *)argv, "p:c:l:");
if ( v5 == -1 )
break;
switch ( v5 )
{
case 'l':
*((_DWORD *)&configstruct + 768) = atoi(optarg);
break;
case 'p':
v4 = *optarg;
if ( (unsigned __int8)(*optarg - 48) > 1u )
{
v6 = "Es gibt nur 2 Spieler! 0 oder 1 eingeben!";
LABEL_9:
puts(v6);
LABEL_11:
help();
exit(1);
}
break;
case 'c':
strcpy(v3, optarg);
break;
default:
goto LABEL_11;
}
}
v7 = (unsigned int)shmSegment(604LL);
shmPtr = shmAnbinden(v7);
shmDelete((unsigned int)v7);
if ( pipe(pipedes) < 0 )
log_printf(0LL, "Fehler bei Pipe anlegen");
v8 = fork();
if ( v8 == -1 )
{
log_printf(0LL, "Fehler bei fork()\n");
}
else
{
if ( v8 )
{
*(_DWORD *)(shmPtr + 40) = v8;
signal(10, (__sighandler_t)&signalHandler);
signal(17, (__sighandler_t)&endHandler);
while ( 1 )
{
pause();
log_printf(2LL, "thinker hat fertig gedacht\n");
pipe_write(pipedes);
}
}
*(_DWORD *)(shmPtr + 44) = 0;
netConnect((unsigned int)((_DWORD)&configstruct + 1024), &configstruct);
while ( 1 )
{
while ( 1 )
{
while ( 1 )
{
while ( 1 )
{
while ( 1 )
{
while ( 1 )
{
while ( 1 )
{
while ( 1 )
{
do
{
while ( 1 )
{
while ( 1 )
{
while ( 1 )
{
v11 = netReadLine();
v13 = 6LL;
v14 = "+ MNM ";
v15 = (const char *)v11;
v16 = (char *)v11;
do
{
if ( !v13 )
break;
v9 = *v15 < (unsigned int)*v14;
v10 = *v15++ == *v14++;
--v13;
}
while ( v10 );
v17 = (!v9 && !v10) - v9;
v18 = 0;
v19 = v17 == 0;
if ( v17 )
break;
sendVersion(v14, v15, v12, v13, v16);
}
v20 = 6LL;
v21 = v16;
v22 = "+ Clie";
do
{
if ( !v20 )
break;
v18 = *v21 < (unsigned int)*v22;
v19 = *v21++ == *v22++;
--v20;
}
while ( v19 );
if ( (!v18 && !v19) != v18 )
break;
sendGameId(dest, v21);
}
if ( memcmp(v16, "+ PLAY", 6uLL) )
break;
parseGamekind(v16, shmPtr);
sendPlayer(v4, shmPtr);
}
}
while ( !memcmp(v16, "+ ENDP", 6uLL) );
if ( memcmp(v16, "+ MOVE", 6uLL) )
break;
parseMovetimeout(v16, shmPtr);
}
v23 = memcmp(v16, "+ NEXT", 6uLL) != 0;
v24 = 0;
v25 = !v23;
if ( v23 )
break;
parseNext(v16, shmPtr);
}
v26 = 6LL;
v27 = v16;
v28 = "+ FIEL";
do
{
if ( !v26 )
break;
v24 = *v27 < (unsigned int)*v28;
v25 = *v27++ == *v28++;
--v26;
}
while ( v25 );
v29 = (!v24 && !v25) - v24;
v30 = 0;
v31 = v29 == 0;
if ( v29 )
break;
parseField(v16, v27);
}
v32 = 6LL;
v33 = v16;
v34 = "+ ENDF";
do
{
if ( !v32 )
break;
v30 = *v33 < (unsigned int)*v34;
v31 = *v33++ == *v34++;
--v32;
}
while ( v31 );
if ( (!v30 && !v31) != v30 )
break;
if ( *(_DWORD *)(shmPtr + 600) != 1 )
sendThinking(v34, v33);
}
if ( memcmp(v16, "+ OKTH", 6uLL) )
break;
s1a = v16;
if ( (unsigned int)ueberwacheFd(pipedes, v16) == 1 )
{
log_printf(2LL, "Gandalf hat gesprochen und wurde vor dem ertrinken gerettet!\n");
sendMove(s1a);
}
else
{
log_printf(1LL, "Gandalf ist ersoffen\n");
}
}
v35 = v16;
s1 = v16;
if ( strncmp(v16, "+ WAIT", 6uLL) )
break;
sendOkwait(v35, "+ WAIT", v36, v37, s1);
}
if ( strncmp(s1, "+ GAME", 6uLL) )
break;
*(_DWORD *)(shmPtr + 600) = 1;
parseGameover(s1);
}
if ( !strncmp(s1, "+ QUIT", 6uLL) )
break;
if ( *s1 == 45 )
{
netDisconnect(s1, "+ QUIT", v38, v39, s1);
free(v3);
v40 = getppid();
kill(v40, 17);
return 0;
}
}
netDisconnect(s1, "+ QUIT", v38, v39, s1);
}
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char *v3; // r13
unsigned int v4; // ebp
int v5; // eax
const char *v6; // rdi
__int64 v7; // r12
__pid_t v8; // eax
bool v9; // cf
bool v10; // zf
__int64 v11; // rax
__int64 v12; // rdx
__int64 v13; // rcx
const char *v14; // rdi
const char *v15; // rsi
char *v16; // r8
char v17; // al
bool v18; // cf
bool v19; // zf
__int64 v20; // rcx
const char *v21; // rsi
const char *v22; // rdi
bool v23; // al
bool v24; // cf
bool v25; // zf
__int64 v26; // rcx
const char *v27; // rsi
const char *v28; // rdi
char v29; // al
bool v30; // cf
bool v31; // zf
__int64 v32; // rcx
const char *v33; // rsi
const char *v34; // rdi
char *v35; // rdi
__int64 v36; // rdx
__int64 v37; // rcx
__int64 v38; // rdx
__int64 v39; // rcx
__pid_t v40; // eax
char *s1; // [rsp+8h] [rbp-C70h]
char *s1a; // [rsp+8h] [rbp-C70h]
char v44[3072]; // [rsp+10h] [rbp-C68h] BYREF
int v45; // [rsp+C10h] [rbp-68h]
int pipedes[2]; // [rsp+C28h] [rbp-50h] BYREF
char dest[71]; // [rsp+C31h] [rbp-47h] BYREF

v3 = (char *)malloc(0x100uLL);
strcpy(v3, "client.conf");
log_printf(2LL, "Using config-file %s\n", v3);
get_config(v44, v3);
qmemcpy(&configstruct, v44, 0xC00uLL);
*((_DWORD *)&configstruct + 768) = v45;
log_printf(1LL, "\n");
if ( argc <= 1 )
{
v6 = "Keine Game-Id angegeben!";
goto LABEL_9;
}
if ( stpcpy(dest, argv[1]) - dest != 11 )
{
v6 = "Game-Id muss 11-stellig sein!";
goto LABEL_9;
}
v4 = 51;
while ( 1 )
{
v5 = getopt(argc, (char *const *)argv, "p:c:l:");
if ( v5 == -1 )
break;
switch ( v5 )
{
case 'l':
*((_DWORD *)&configstruct + 768) = atoi(optarg);
break;
case 'p':
v4 = *optarg;
if ( (unsigned __int8)(*optarg - 48) > 1u )
{
v6 = "Es gibt nur 2 Spieler! 0 oder 1 eingeben!";
LABEL_9:
puts(v6);
LABEL_11:
func0();
exit(1);
}
break;
case 'c':
strcpy(v3, optarg);
break;
default:
goto LABEL_11;
}
}
v7 = (unsigned int)shmSegment(604LL);
shmPtr = shmAnbinden(v7);
shmDelete((unsigned int)v7);
if ( pipe(pipedes) < 0 )
log_printf(0LL, "Fehler bei Pipe anlegen");
v8 = fork();
if ( v8 == -1 )
{
log_printf(0LL, "Fehler bei fork()\n");
}
else
{
if ( v8 )
{
*(_DWORD *)(shmPtr + 40) = v8;
signal(10, (__sighandler_t)&signalHandler);
signal(17, (__sighandler_t)&endHandler);
while ( 1 )
{
pause();
log_printf(2LL, "thinker hat fertig gedacht\n");
pipe_write(pipedes);
}
}
*(_DWORD *)(shmPtr + 44) = 0;
netConnect((unsigned int)((_DWORD)&configstruct + 1024), &configstruct);
while ( 1 )
{
while ( 1 )
{
while ( 1 )
{
while ( 1 )
{
while ( 1 )
{
while ( 1 )
{
while ( 1 )
{
while ( 1 )
{
do
{
while ( 1 )
{
while ( 1 )
{
while ( 1 )
{
v11 = netReadLine();
v13 = 6LL;
v14 = "+ MNM ";
v15 = (const char *)v11;
v16 = (char *)v11;
do
{
if ( !v13 )
break;
v9 = *v15 < (unsigned int)*v14;
v10 = *v15++ == *v14++;
--v13;
}
while ( v10 );
v17 = (!v9 && !v10) - v9;
v18 = 0;
v19 = v17 == 0;
if ( v17 )
break;
sendVersion(v14, v15, v12, v13, v16);
}
v20 = 6LL;
v21 = v16;
v22 = "+ Clie";
do
{
if ( !v20 )
break;
v18 = *v21 < (unsigned int)*v22;
v19 = *v21++ == *v22++;
--v20;
}
while ( v19 );
if ( (!v18 && !v19) != v18 )
break;
sendGameId(dest, v21);
}
if ( memcmp(v16, "+ PLAY", 6uLL) )
break;
parseGamekind(v16, shmPtr);
sendPlayer(v4, shmPtr);
}
}
while ( !memcmp(v16, "+ ENDP", 6uLL) );
if ( memcmp(v16, "+ MOVE", 6uLL) )
break;
parseMovetimeout(v16, shmPtr);
}
v23 = memcmp(v16, "+ NEXT", 6uLL) != 0;
v24 = 0;
v25 = !v23;
if ( v23 )
break;
parseNext(v16, shmPtr);
}
v26 = 6LL;
v27 = v16;
v28 = "+ FIEL";
do
{
if ( !v26 )
break;
v24 = *v27 < (unsigned int)*v28;
v25 = *v27++ == *v28++;
--v26;
}
while ( v25 );
v29 = (!v24 && !v25) - v24;
v30 = 0;
v31 = v29 == 0;
if ( v29 )
break;
parseField(v16, v27);
}
v32 = 6LL;
v33 = v16;
v34 = "+ ENDF";
do
{
if ( !v32 )
break;
v30 = *v33 < (unsigned int)*v34;
v31 = *v33++ == *v34++;
--v32;
}
while ( v31 );
if ( (!v30 && !v31) != v30 )
break;
if ( *(_DWORD *)(shmPtr + 600) != 1 )
sendThinking(v34, v33);
}
if ( memcmp(v16, "+ OKTH", 6uLL) )
break;
s1a = v16;
if ( (unsigned int)ueberwacheFd(pipedes, v16) == 1 )
{
log_printf(2LL, "Gandalf hat gesprochen und wurde vor dem ertrinken gerettet!\n");
sendMove(s1a);
}
else
{
log_printf(1LL, "Gandalf ist ersoffen\n");
}
}
v35 = v16;
s1 = v16;
if ( strncmp(v16, "+ WAIT", 6uLL) )
break;
sendOkwait(v35, "+ WAIT", v36, v37, s1);
}
if ( strncmp(s1, "+ GAME", 6uLL) )
break;
*(_DWORD *)(shmPtr + 600) = 1;
parseGameover(s1);
}
if ( !strncmp(s1, "+ QUIT", 6uLL) )
break;
if ( *s1 == 45 )
{
netDisconnect(s1, "+ QUIT", v38, v39, s1);
free(v3);
v40 = getppid();
kill(v40, 17);
return 0;
}
}
netDisconnect(s1, "+ QUIT", v38, v39, s1);
}
return 0;
}

original_code:
int main(int argc, char *argv[]) {
 int ret;
 char player = '3';
 char gameId[15];
 char *confDateiName = malloc(256);
 strcpy(confDateiName, "client.conf");
 pid_t pid;
 log_printf(2,"Using config-file %s\n",confDateiName);
 configstruct = get_config(confDateiName);
 log_printf(1,"\n");
 if (argc < 2) {
  printf("Keine Game-Id angegeben!\n");
  help();
  exit(1);
 }
 strcpy(gameId,argv[1]);
 if(strlen(gameId) != 11) {
  printf("Game-Id muss 11-stellig sein!\n");
  help();
  exit(1);
 }
 while ((ret=getopt(argc, argv, "p:c:l:")) != -1) {
 switch (ret) {
 case 'p':
  player = optarg[0];
  if (player!='0' && player != '1') {
   printf("Es gibt nur 2 Spieler! 0 oder 1 eingeben!\n");
   help();
   exit(1);
  }
  break;
 case 'c':
  strcpy(confDateiName, optarg);
  break;
 case 'l':
  configstruct.loglevel = atoi(optarg);
  break;
 default:
  help();
  exit(1);
 }
 }
 int shmid = shmSegment(sizeof(struct shmInfos));
 shmPtr = shmAnbinden(shmid);
 shmDelete(shmid);
 int pipe_fd[2];
 if(pipe(pipe_fd)<0){
  log_printf(0,"Fehler bei Pipe anlegen");
 };
 switch (pid = fork ()) {
 case -1:
  log_printf (0,"Fehler bei fork()\n");
  break;
 case 0:
  shmPtr->pid1=pid;
  char *getText;
  netConnect(configstruct.port, configstruct.hostname);
  while (1) {
   getText = netReadLine();
   if (strncmp(getText, "+ MNM ",6) == 0) {
    sendVersion();
   } else if (strncmp(getText, "+ Clie",6) == 0) {
    sendGameId(gameId);
   } else if (strncmp(getText, "+ PLAY",6) == 0) {
    parseGamekind(getText, shmPtr);
    sendPlayer(player, shmPtr);
   } else if (strncmp(getText, "+ ENDP",6) == 0) {
   } else if (strncmp(getText, "+ MOVE",6) == 0) {
    parseMovetimeout(getText, shmPtr);
   } else if (strncmp(getText, "+ NEXT",6) == 0) {
    parseNext(getText, shmPtr);
   } else if (strncmp(getText, "+ FIEL",6) == 0) {
    parseField(getText);
   } else if (strncmp(getText, "+ ENDF",6) == 0) {
        if (shmPtr->gameover != 1) {
      sendThinking();
        }
   } else if (strncmp(getText, "+ OKTH",6) == 0) {
    if(ueberwacheFd(pipe_fd,getText)==1){
     log_printf(2,"Gandalf hat gesprochen und wurde vor dem ertrinken gerettet!\n");
     sendMove(getText);
    }
    else{
     log_printf(1,"Gandalf ist ersoffen\n");
    }
   } else if (strncmp(getText, "+ WAIT",6) == 0) {
    sendOkwait();
   } else if (strncmp(getText, "+ GAME",6) == 0) {
        shmPtr->gameover = 1;
    parseGameover(getText);
   } else if (strncmp(getText, "+ QUIT",6) == 0) {
    netDisconnect();
    break;
   } else if (strncmp(getText, "-",1) == 0) {
    netDisconnect();
    free(confDateiName);
    kill(getppid(),17);
    break;
   }
  }
  break;
 default:
  shmPtr->pid0=pid;
  signal(10, signalHandler);
  signal(17, endHandler);
  while (1){
   pause();
   log_printf(2,"thinker hat fertig gedacht\n");
   pipe_write(pipe_fd);
  }
  if (wait (((void *)0)) != pid) {
   log_printf(0,"Fehler beim Warten auf den Kindprozess\n");
   return 1;
  }
  break;
 }
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[]) {
 int ret;
 char player = '3';
 char gameId[15];
 char *confDateiName = malloc(256);
 strcpy(confDateiName, "client.conf");
 int pid;
 log_printf(2,"Using config-file %s\n",confDateiName);
 configstruct = get_config(confDateiName);
 log_printf(1,"\n");
 if (argc < 2) {
  printf("Keine Game-Id angegeben!\n");
  help();
  exit(1);
 }
 strcpy(gameId,argv[1]);
 if(strlen(gameId) != 11) {
  printf("Game-Id muss 11-stellig sein!\n");
  help();
  exit(1);
 }
 while ((ret=getopt(argc, argv, "p:c:l:")) != -1) {
 switch (ret) {
 case 'p':
  player = optarg[0];
  if (player!='0' && player != '1') {
   printf("Es gibt nur 2 Spieler! 0 oder 1 eingeben!\n");
   help();
   exit(1);
  }
  break;
 case 'c':
  strcpy(confDateiName, optarg);
  break;
 case 'l':
  configstruct.loglevel = atoi(optarg);
  break;
 default:
  help();
  exit(1);
 }
 }
 int shmid = shmSegment(sizeof(struct shmInfos));
 shmPtr = shmAnbinden(shmid);
 shmDelete(shmid);
 int pipe_fd[2];
 if(pipe(pipe_fd)<0){
  log_printf(0,"Fehler bei Pipe anlegen");
 };
 switch (pid = fork ()) {
 case -1:
  log_printf (0,"Fehler bei fork()\n");
  break;
 case 0:
  shmPtr->pid1=pid;
  char *getText;
  netConnect(configstruct.port, configstruct.hostname);
  while (1) {
   getText = netReadLine();
   if (strncmp(getText, "+ MNM ",6) == 0) {
    sendVersion();
   } else if (strncmp(getText, "+ Clie",6) == 0) {
    sendGameId(gameId);
   } else if (strncmp(getText, "+ PLAY",6) == 0) {
    parseGamekind(getText, shmPtr);
    sendPlayer(player, shmPtr);
   } else if (strncmp(getText, "+ ENDP",6) == 0) {
   } else if (strncmp(getText, "+ MOVE",6) == 0) {
    parseMovetimeout(getText, shmPtr);
   } else if (strncmp(getText, "+ NEXT",6) == 0) {
    parseNext(getText, shmPtr);
   } else if (strncmp(getText, "+ FIEL",6) == 0) {
    parseField(getText);
   } else if (strncmp(getText, "+ ENDF",6) == 0) {
        if (shmPtr->gameover != 1) {
      sendThinking();
        }
   } else if (strncmp(getText, "+ OKTH",6) == 0) {
    if(ueberwacheFd(pipe_fd,getText)==1){
     log_printf(2,"Gandalf hat gesprochen und wurde vor dem ertrinken gerettet!\n");
     sendMove(getText);
    }
    else{
     log_printf(1,"Gandalf ist ersoffen\n");
    }
   } else if (strncmp(getText, "+ WAIT",6) == 0) {
    sendOkwait();
   } else if (strncmp(getText, "+ GAME",6) == 0) {
        shmPtr->gameover = 1;
    parseGameover(getText);
   } else if (strncmp(getText, "+ QUIT",6) == 0) {
    netDisconnect();
    break;
   } else if (strncmp(getText, "-",1) == 0) {
    netDisconnect();
    free(confDateiName);
    kill(getppid(),17);
    break;
   }
  }
  break;
 default:
  shmPtr->pid0=pid;
  signal(10, signalHandler);
  signal(17, endHandler);
  while (1){
   pause();
   log_printf(2,"thinker hat fertig gedacht\n");
   pipe_write(pipe_fd);
  }
  if (wait (((void *)0)) != pid) {
   log_printf(0,"Fehler beim Warten auf den Kindprozess\n");
   return 1;
  }
  break;
 }
 return 0;
}

variable_types: ret int

variable_types: player char

variable_types:
gameId
char [15]

variable_types:
confDateiName
char *

variable_types: pid int

variable_types: shmid int

variable_types:
getText
char *


decompiled_code:
int __fastcall connector2thinker(__pid_t a1)
{
return kill(a1, 10);
}

canonical_decompiled_code:
int __fastcall func0(__pid_t a1)
{
return kill(a1, 10);
}

original_code:
void connector2thinker( pid_t pid ) {
   kill(pid, 10);
}

canonical_original_code:
void connector2thinker(int pid) {
   kill(pid, 10);
}


signalHandler

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

result = shmPtr;
if ( *(_DWORD *)(shmPtr + 48LL) )
{
*(_DWORD *)(shmPtr + 48LL) = 0;
result = think();
}
return result;
}

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

result = shmPtr;
if ( *(_DWORD *)(shmPtr + 48LL) )
{
*(_DWORD *)(shmPtr + 48LL) = 0;
result = think();
}
return result;
}

original_code:
void signalHandler(int signum) {
 if (shmPtr->flag == 0) {
  return;
 }
 shmPtr->flag = 0;
 think();
}

variable_types: signum int


endHandler

decompiled_code:
void __noreturn endHandler()
{
exit(1);
}

canonical_decompiled_code:
void __noreturn func2()
{
exit(1);
}

original_code:
void endHandler(int signum) {
 exit(1);
}


sendOkwait

decompiled_code:
__int64 sendOkwait()
{
__int64 v1[33]; // [rsp+0h] [rbp-108h] BYREF

v1[0] = 0xA544941574B4FLL;
netWrite(v1);
return log_printf(1LL, "Warten auf den anderen Spieler\n");
}

canonical_decompiled_code:
__int64 func1()
{
__int64 v1[33]; // [rsp+0h] [rbp-108h] BYREF

v1[0] = 0xA544941574B4FLL;
netWrite(v1);
return log_printf(1LL, "Warten auf den anderen Spieler\n");
}

original_code:
void sendOkwait() {
 char sendText[251];
 snprintf(sendText,10,"OKWAIT\n");
 netWrite(sendText);
 log_printf(1,"Warten auf den anderen Spieler\n");
}

variable_types:
sendText
char [251]


sendVersion

decompiled_code:
__int64 sendVersion()
{
char v1[264]; // [rsp+0h] [rbp-108h] BYREF

snprintf(v1, 0x17uLL, "VERSION %s\n", "1.42");
return netWrite(v1);
}

canonical_decompiled_code:
__int64 func2()
{
char v1[264]; // [rsp+0h] [rbp-108h] BYREF

snprintf(v1, 0x17uLL, "VERSION %s\n", "1.42");
return netWrite(v1);
}

original_code:
void sendVersion() {
 char sendText[251];
 snprintf(sendText,23,"VERSION %s\n","1.42");
 netWrite(sendText);
}


sendGameId

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

snprintf(v2, 0x10uLL, "ID %s\n", a1);
netWrite(v2);
return log_printf(1LL, "Game ID: %s\n", a1);
}

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

snprintf(v2, 0x10uLL, "ID %s\n", a1);
netWrite(v2);
return log_printf(1LL, "Game ID: %s\n", a1);
}

original_code:
void sendGameId(char* gameId) {
 char sendText[251];
 snprintf(sendText,16,"ID %s\n",gameId);
 netWrite(sendText);
 log_printf(1,"Game ID: %s\n",gameId);
}

canonical_original_code:
void sendGameId(char *gameId) {
 char sendText[251];
 snprintf(sendText,16,"ID %s\n",gameId);
 netWrite(sendText);
 log_printf(1,"Game ID: %s\n",gameId);
}

variable_types:
gameId
char *


parseGamekind

decompiled_code:
__int64 __fastcall parseGamekind(char *src, char *dest)
{
bool v2; // cf
bool v3; // zf
char *v4; // rsi
const char *v5; // rdi
__int64 v6; // rcx
__int64 v7; // rax

log_printf(1LL, "%s\n\n", src + 2);
strcpy(dest, src);
v4 = src + 10;
v5 = "Quarto";
v6 = 7LL;
do
{
if ( !v6 )
break;
v2 = (unsigned __int8)*v4 < (unsigned int)*v5;
v3 = *v4++ == *v5++;
--v6;
}
while ( v3 );
if ( (!v2 && !v3) != v2 )
{
log_printf(0LL, "Du spielst nicht Quarto, du Depp!");
exit(1);
}
v7 = netReadLine(v5, v4);
return log_printf(1LL, "Name: %s\n", (const char *)(v7 + 2));
}

canonical_decompiled_code:
__int64 __fastcall func4(char *src, char *dest)
{
bool v2; // cf
bool v3; // zf
char *v4; // rsi
const char *v5; // rdi
__int64 v6; // rcx
__int64 v7; // rax

log_printf(1LL, "%s\n\n", src + 2);
strcpy(dest, src);
v4 = src + 10;
v5 = "Quarto";
v6 = 7LL;
do
{
if ( !v6 )
break;
v2 = (unsigned __int8)*v4 < (unsigned int)*v5;
v3 = *v4++ == *v5++;
--v6;
}
while ( v3 );
if ( (!v2 && !v3) != v2 )
{
log_printf(0LL, "Du spielst nicht Quarto, du Depp!");
exit(1);
}
v7 = netReadLine(v5, v4);
return log_printf(1LL, "Name: %s\n", (const char *)(v7 + 2));
}

original_code:
void parseGamekind(char* getText, struct shmInfos *shmPtr) {
 log_printf(1,"%s\n\n",getText+2);
 strcpy(shmPtr->spielname,getText);
 if(strcmp((getText+10),"Quarto")!=0) {
  log_printf(0,"Du spielst nicht Quarto, du Depp!");
  exit(1);
 }
 getText = netReadLine();
 log_printf(1,"Name: %s\n",getText+2);
}

canonical_original_code:
void parseGamekind(char *getText, struct shmInfos *shmPtr) {
 log_printf(1,"%s\n\n",getText+2);
 strcpy(shmPtr->spielname,getText);
 if(strcmp((getText+10),"Quarto")!=0) {
  log_printf(0,"Du spielst nicht Quarto, du Depp!");
  exit(1);
 }
 getText = netReadLine();
 log_printf(1,"Name: %s\n",getText+2);
}

variable_types: struct shmInfos { char spielname[30]; int eigSpielernummer; int anzahlSpieler; int pid0; int pid1; int flag; struct playerAttr { int spielerNr; char name[256]; int registered; } attr[2]; int moveTimeout; int nextStone; int breite; int hoehe; int shmid_Sf; int gameover; } *

user_defined_types: struct shmInfos { char spielname[30]; int eigSpielernummer; int anzahlSpieler; int pid0; int pid1; int flag; struct playerAttr attr[2]; int moveTimeout; int nextStone; int breite; int hoehe; int shmid_Sf; int gameover; }


sendPlayer

original_code:
void sendPlayer(int player, struct shmInfos *shmPtr) {
 char sendText[251];
 char *getText;
 int i=0;
 if (player!='3') {
  snprintf(sendText,15,"PLAYER %c\n", player);
 }
 else {
  snprintf(sendText,10,"PLAYER\n");
 }
 netWrite(sendText);
 getText = netReadLine();
 shmPtr->eigSpielernummer = getText[6]-'0';
 shmPtr->attr[shmPtr->eigSpielernummer].spielerNr = shmPtr->eigSpielernummer;
 strcpy(shmPtr->attr[shmPtr->eigSpielernummer].name,getText+8);
 shmPtr->attr[shmPtr->eigSpielernummer].registered = 1;
 log_printf(1,"You are Player %i (",getText[6]-'0'+1);
 i=8;
 while(getText[i] != '\0') {
  log_printf(1,"%c",getText[i]);
  i++;
 }
 log_printf(1,")\n");
 log_printf(1,"\n");
 getText = netReadLine();
 shmPtr->anzahlSpieler = getText[8]-'0';
 getText = netReadLine();
 int anzSp = (getText[2]-'0')-1;
 shmPtr->attr[anzSp].spielerNr = anzSp;
 strncpy(shmPtr->attr[anzSp].name,getText+4,strlen(getText+4)-2);
 shmPtr->attr[anzSp].name[strlen(getText+4)-2] = '\0';
 shmPtr->attr[anzSp].registered = getText[strlen(getText)-1]-'0';
 log_printf(1,"Player %c (",getText[2]);
 i=4;
 while(getText[i+2] != '\0') {
  log_printf(1,"%c",getText[i]);
  i++;
 }
 log_printf(1,") is ");
 if (getText[i+1] == '1') {
  log_printf(1,"ready\n\n");
 } else
 {
  log_printf(1,"not ready\n\n");
 }
}

canonical_original_code:
void sendPlayer(int player, struct shmInfos *shmPtr) {
 char sendText[251];
 char *getText;
 int i = 0;
 if (player!='3') {
  snprintf(sendText,15,"PLAYER %c\n", player);
 }
 else {
  snprintf(sendText,10,"PLAYER\n");
 }
 netWrite(sendText);
 getText = netReadLine();
 shmPtr->eigSpielernummer = getText[6]-'0';
 shmPtr->attr[shmPtr->eigSpielernummer].spielerNr = shmPtr->eigSpielernummer;
 strcpy(shmPtr->attr[shmPtr->eigSpielernummer].name,getText+8);
 shmPtr->attr[shmPtr->eigSpielernummer].registered = 1;
 log_printf(1,"You are Player %i (",getText[6]-'0'+1);
 i=8;
 while(getText[i] != '\0') {
  log_printf(1,"%c",getText[i]);
  i++;
 }
 log_printf(1,")\n");
 log_printf(1,"\n");
 getText = netReadLine();
 shmPtr->anzahlSpieler = getText[8]-'0';
 getText = netReadLine();
 int anzSp = (getText[2]-'0')-1;
 shmPtr->attr[anzSp].spielerNr = anzSp;
 strncpy(shmPtr->attr[anzSp].name,getText+4,strlen(getText+4)-2);
 shmPtr->attr[anzSp].name[strlen(getText+4)-2] = '\0';
 shmPtr->attr[anzSp].registered = getText[strlen(getText)-1]-'0';
 log_printf(1,"Player %c (",getText[2]);
 i=4;
 while(getText[i+2] != '\0') {
  log_printf(1,"%c",getText[i]);
  i++;
 }
 log_printf(1,") is ");
 if (getText[i+1] == '1') {
  log_printf(1,"ready\n\n");
 } else
 {
  log_printf(1,"not ready\n\n");
 }
}

variable_types: player int

variable_types: i int

variable_types: anzSp int

user_defined_types: struct playerAttr { int spielerNr; char name[256]; int registered; }


parseMovetimeout

decompiled_code:
int __fastcall parseMovetimeout(__int64 a1, __int64 a2)
{
int result; // eax

result = atoi((const char *)(a1 + 7));
*(_DWORD *)(a2 + 580) = result;
return result;
}

canonical_decompiled_code:
int __fastcall func6(__int64 a1, __int64 a2)
{
int result; // eax

result = atoi((const char *)(a1 + 7));
*(_DWORD *)(a2 + 580) = result;
return result;
}

original_code:
void parseMovetimeout(char* getText, struct shmInfos *shmPtr) {
 int time = atoi(getText+7);
 shmPtr->moveTimeout = time;
}

canonical_original_code:
void parseMovetimeout(char *getText, struct shmInfos *shmPtr) {
 int time = atoi(getText+7);
 shmPtr->moveTimeout = time;
}

variable_types: time int


parseNext

decompiled_code:
int __fastcall parseNext(__int64 a1, __int64 a2)
{
int result; // eax

result = atoi((const char *)(a1 + 7));
*(_DWORD *)(a2 + 584) = result;
return result;
}

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

result = atoi((const char *)(a1 + 7));
*(_DWORD *)(a2 + 584) = result;
return result;
}

original_code:
void parseNext(char* getText, struct shmInfos *shmPtr) {
 int next = atoi(getText+7);
 shmPtr->nextStone = next;
}

canonical_original_code:
void parseNext(char *getText, struct shmInfos *shmPtr) {
 int next = atoi(getText+7);
 shmPtr->nextStone = next;
}

variable_types: next int


parseField

decompiled_code:
__int64 __fastcall parseField(const char *a1, const char *a2)
{
__int64 v2; // rbp
int v3; // eax
char v4; // dl
__int64 v5; // rcx
__int64 v6; // rax
__int64 v7; // rcx
size_t v8; // rax
int v9; // ebp
__int64 v10; // rbx
unsigned int v11; // er12
__int64 v12; // rax
int i; // ebx
__int64 v14; // rbx
__int64 v15; // rdx
char v17; // [rsp+1h] [rbp-39h]
char v18[8]; // [rsp+2h] [rbp-38h] BYREF
char nptr[48]; // [rsp+Ah] [rbp-30h] BYREF

v2 = *(int *)(shmPtr + 588LL);
if ( (_DWORD)v2 )
{
v9 = *(_DWORD *)(shmPtr + 592LL);
}
else
{
v3 = strlen(a1);
v4 = *a1;
if ( *a1 != 44 && v3 > 1 )
{
v5 = (unsigned int)(v3 - 2);
v6 = 1LL;
v7 = v5 + 2;
do
{
*(&v17 + v6) = v4;
v4 = a1[v6];
v2 = (int)v6;
if ( v4 == 44 )
break;
++v6;
}
while ( v6 != v7 );
}
v18[v2] = 0;
v8 = strlen(v18);
v9 = atoi(&a1[v8 + 1]);
v10 = (unsigned int)atoi(nptr);
log_printf(1LL, "Breite: %i\n", v10);
log_printf(1LL, "Hoehe: %i\n", (unsigned int)v9);
v11 = shmSegment((unsigned int)(4 * v10 * v9));
*(_DWORD *)(shmPtr + 596LL) = v11;
shmPtr_Sf = shmSpielfeldAnbinden(v11);
shmDelete(v11);
v12 = shmPtr;
*(_DWORD *)(shmPtr + 588LL) = v10;
*(_DWORD *)(v12 + 592) = v9;
log_printf(2LL, "Hoehe im Shared Memory: %i\n", (unsigned int)v9);
a2 = "Breite im Shared Memory: %i\n";
a1 = (_BYTE *)&loc_2;
log_printf(2LL, "Breite im Shared Memory: %i\n", *(unsigned int *)(shmPtr + 588LL));
}
if ( v9 > 0 )
{
for ( i = 0; i != v9; ++i )
{
a1 = (const char *)netReadLine(a1, a2);
saveField((__int64)a1);
}
}
v14 = 0LL;
log_printf(2LL, "Spielfeldarray: ");
do
{
v15 = *(unsigned int *)(shmPtr_Sf + v14);
v14 += 4LL;
log_printf(2LL, "%i ", v15);
}
while ( v14 != 64 );
log_printf(2LL, "\n");
log_printf(1LL, aN, *(unsigned int *)(shmPtr + 584LL));
printSpielstein(*(unsigned int *)(shmPtr + 584LL));
log_printf(1LL, "\n");
return printField();
}

canonical_decompiled_code:
__int64 __fastcall func8(const char *a1, const char *a2)
{
__int64 v2; // rbp
int v3; // eax
char v4; // dl
__int64 v5; // rcx
__int64 v6; // rax
__int64 v7; // rcx
size_t v8; // rax
int v9; // ebp
__int64 v10; // rbx
unsigned int v11; // er12
__int64 v12; // rax
int i; // ebx
__int64 v14; // rbx
__int64 v15; // rdx
char v17; // [rsp+1h] [rbp-39h]
char v18[8]; // [rsp+2h] [rbp-38h] BYREF
char nptr[48]; // [rsp+Ah] [rbp-30h] BYREF

v2 = *(int *)(shmPtr + 588LL);
if ( (_DWORD)v2 )
{
v9 = *(_DWORD *)(shmPtr + 592LL);
}
else
{
v3 = strlen(a1);
v4 = *a1;
if ( *a1 != 44 && v3 > 1 )
{
v5 = (unsigned int)(v3 - 2);
v6 = 1LL;
v7 = v5 + 2;
do
{
*(&v17 + v6) = v4;
v4 = a1[v6];
v2 = (int)v6;
if ( v4 == 44 )
break;
++v6;
}
while ( v6 != v7 );
}
v18[v2] = 0;
v8 = strlen(v18);
v9 = atoi(&a1[v8 + 1]);
v10 = (unsigned int)atoi(nptr);
log_printf(1LL, "Breite: %i\n", v10);
log_printf(1LL, "Hoehe: %i\n", (unsigned int)v9);
v11 = shmSegment((unsigned int)(4 * v10 * v9));
*(_DWORD *)(shmPtr + 596LL) = v11;
shmPtr_Sf = shmSpielfeldAnbinden(v11);
shmDelete(v11);
v12 = shmPtr;
*(_DWORD *)(shmPtr + 588LL) = v10;
*(_DWORD *)(v12 + 592) = v9;
log_printf(2LL, "Hoehe im Shared Memory: %i\n", (unsigned int)v9);
a2 = "Breite im Shared Memory: %i\n";
a1 = (_BYTE *)&loc_2;
log_printf(2LL, "Breite im Shared Memory: %i\n", *(unsigned int *)(shmPtr + 588LL));
}
if ( v9 > 0 )
{
for ( i = 0; i != v9; ++i )
{
a1 = (const char *)netReadLine(a1, a2);
func0((__int64)a1);
}
}
v14 = 0LL;
log_printf(2LL, "Spielfeldarray: ");
do
{
v15 = *(unsigned int *)(shmPtr_Sf + v14);
v14 += 4LL;
log_printf(2LL, "%i ", v15);
}
while ( v14 != 64 );
log_printf(2LL, "\n");
log_printf(1LL, aN, *(unsigned int *)(shmPtr + 584LL));
printSpielstein(*(unsigned int *)(shmPtr + 584LL));
log_printf(1LL, "\n");
return printField();
}

original_code:
void parseField(char* getText) {
 int hoehe;
 int breite;
 if (shmPtr->breite == 0) {
  int len = strlen(getText);
  char breiteChar[20];
  int i=0;
  while (getText[i] != ',' && i<len-1) {
   breiteChar[i] = getText[i];
   i++;
  }
  breiteChar[i] = '\0';
  int lenB = strlen(breiteChar);
  hoehe = atoi(getText+lenB+1);
  breite = atoi(breiteChar+8);
  log_printf(1,"Breite: %i\n",breite);
  log_printf(1,"Hoehe: %i\n",hoehe);
  int shmid_Sf = shmSegment(hoehe*breite*sizeof(int));
  shmPtr->shmid_Sf = shmid_Sf;
  shmPtr_Sf = shmSpielfeldAnbinden(shmid_Sf);
  shmDelete(shmid_Sf);
  shmPtr->breite = breite;
  shmPtr->hoehe = hoehe;
  log_printf(2,"Hoehe im Shared Memory: %i\n",shmPtr->hoehe);
  log_printf(2,"Breite im Shared Memory: %i\n",shmPtr->breite);
 }
 else {
  breite = shmPtr->breite;
  hoehe = shmPtr->hoehe;
 }
 for (int i=0; i<hoehe; i++) {
  getText = netReadLine();
  saveField(getText);
 }
 log_printf(2,"Spielfeldarray: ");
 for(int i=0; i<16; i++) {
  log_printf(2,"%i ",shmPtr_Sf[i]);
 }
 log_printf(2,"\n");
 log_printf(1,"\nNächster Stein: (%i)",shmPtr->nextStone);
 printSpielstein(shmPtr->nextStone);
 log_printf(1,"\n");
 printField();
}

canonical_original_code:
void parseField(char *getText) {
 int hoehe;
 int breite;
 if (shmPtr->breite == 0) {
  int len = strlen(getText);
  char breiteChar[20];
  int i = 0;
  while (getText[i] != ',' && i<len-1) {
   breiteChar[i] = getText[i];
   i++;
  }
  breiteChar[i] = '\0';
  int lenB = strlen(breiteChar);
  hoehe = atoi(getText+lenB+1);
  breite = atoi(breiteChar+8);
  log_printf(1,"Breite: %i\n",breite);
  log_printf(1,"Hoehe: %i\n",hoehe);
  int shmid_Sf = shmSegment(hoehe*breite*sizeof(int));
  shmPtr->shmid_Sf = shmid_Sf;
  shmPtr_Sf = shmSpielfeldAnbinden(shmid_Sf);
  shmDelete(shmid_Sf);
  shmPtr->breite = breite;
  shmPtr->hoehe = hoehe;
  log_printf(2,"Hoehe im Shared Memory: %i\n",shmPtr->hoehe);
  log_printf(2,"Breite im Shared Memory: %i\n",shmPtr->breite);
 }
 else {
  breite = shmPtr->breite;
  hoehe = shmPtr->hoehe;
 }
 for (int i = 0; i<hoehe; i++) {
  getText = netReadLine();
  saveField(getText);
 }
 log_printf(2,"Spielfeldarray: ");
 for(int i = 0; i<16; i++) {
  log_printf(2,"%i ",shmPtr_Sf[i]);
 }
 log_printf(2,"\n");
 log_printf(1,"\nNächster Stein: (%i)",shmPtr->nextStone);
 printSpielstein(shmPtr->nextStone);
 log_printf(1,"\n");
 printField();
}

variable_types: hoehe int

variable_types: breite int

variable_types: len int

variable_types:
breiteChar
char [20]

variable_types: lenB int


sendThinking

decompiled_code:
__int64 sendThinking()
{
unsigned int v0; // eax
char v2[264]; // [rsp+0h] [rbp-108h] BYREF

*(_DWORD *)(shmPtr + 48LL) = 1;
v0 = getppid();
connector2thinker(v0);
strcpy(v2, "THINKING\n");
netWrite(v2);
return log_printf(1LL, "\nSpielzug wird berechnet...");
}

canonical_decompiled_code:
__int64 func9()
{
unsigned int v0; // eax
char v2[264]; // [rsp+0h] [rbp-108h] BYREF

*(_DWORD *)(shmPtr + 48LL) = 1;
v0 = getppid();
connector2thinker(v0);
strcpy(v2, "THINKING\n");
netWrite(v2);
return log_printf(1LL, "\nSpielzug wird berechnet...");
}

original_code:
void sendThinking() {
 shmPtr->flag = 1;
 connector2thinker(getppid());
 char sendText[251];
 snprintf(sendText,12,"THINKING\n");
 netWrite(sendText);
 log_printf(1,"\nSpielzug wird berechnet...");
}


parseGameover

decompiled_code:
__int64 __fastcall parseGameover(__int64 a1)
{
int v1; // eax
__int64 result; // rax

v1 = atoi((const char *)(a1 + 11)) - 1;
if ( v1 == *(_DWORD *)(shmPtr + 32LL) )
result = log_printf(1LL, "\x1B[1m\x1B[32mYou, %s, won the game.\n\x1B[0m", (const char *)(shmPtr + 264LL * v1 + 56));
else
result = log_printf(
1LL,
"\x1B[1m\x1B[31mYou lost the game. %s won.\n\x1B[0m",
(const char *)(shmPtr + 264LL * v1 + 56));
return result;
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1)
{
int v1; // eax
__int64 result; // rax

v1 = atoi((const char *)(a1 + 11)) - 1;
if ( v1 == *(_DWORD *)(shmPtr + 32LL) )
result = log_printf(1LL, "\x1B[1m\x1B[32mYou, %s, won the game.\n\x1B[0m", (const char *)(shmPtr + 264LL * v1 + 56));
else
result = log_printf(
1LL,
"\x1B[1m\x1B[31mYou lost the game. %s won.\n\x1B[0m",
(const char *)(shmPtr + 264LL * v1 + 56));
return result;
}

original_code:
void parseGameover(char* getText) {
  int winnerid = atoi(getText+11);
  if (winnerid - 1 == shmPtr->eigSpielernummer) {
    log_printf(1, "\033[1m\033[32m""You, %s, won the game.\n""\033[0m", shmPtr->attr[shmPtr->eigSpielernummer].name);
  } else {
    log_printf(1, "\033[1m\033[31m""You lost the game. %s won.\n""\033[0m", shmPtr->attr[winnerid - 1].name);
  }
}

canonical_original_code:
void parseGameover(char *getText) {
  int winnerid = atoi(getText+11);
  if (winnerid - 1 == shmPtr->eigSpielernummer) {
    log_printf(1, "\033[1m\033[32m""You, %s, won the game.\n""\033[0m", shmPtr->attr[shmPtr->eigSpielernummer].name);
  } else {
    log_printf(1, "\033[1m\033[31m""You lost the game. %s won.\n""\033[0m", shmPtr->attr[winnerid - 1].name);
  }
}

variable_types: winnerid int


sendMove

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

snprintf(v2, 0xFuLL, "PLAY %s\n", a1);
netWrite(v2);
return log_printf(1LL, "Done: %s\n", a1);
}

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

snprintf(v2, 0xFuLL, "PLAY %s\n", a1);
netWrite(v2);
return log_printf(1LL, "Done: %s\n", a1);
}

original_code:
void sendMove(char *spielzug) {
 char sendText[251];
 snprintf(sendText,15,"PLAY %s\n", spielzug);
 netWrite(sendText);
 log_printf(1,"Done: %s\n",spielzug);
}

variable_types:
spielzug
char *


saveField

original_code:
void saveField(char *getText) {
  int breite = shmPtr->breite;
 char charHelp[255];
  int i = 2;
  int j =0;
 while (getText[i] != ' ') {
  charHelp[j] = getText[i];
  j++;
  i++;
 }
 charHelp[j] = '\0';
 i++;
 int zeile = breite-atoi(charHelp);
  int currentField = zeile*breite;
 while (breite) {
   if (getText[i] == '*') {
     shmPtr_Sf[currentField]= -1;
   i++;
  }
  else if(getText[i] !=' ') {
   j=0;
   while(getText[i] != ' ') {
    charHelp[j] = getText[i];
    j++;
    i++;
   }
   charHelp[j] = '\0';
   shmPtr_Sf[currentField] = atoi(charHelp);
  }
  currentField++;
  i++;
  breite--;
 }
}

canonical_original_code:
void saveField(char *getText) {
  int breite = shmPtr->breite;
 char charHelp[255];
  int i = 2;
  int j = 0;
 while (getText[i] != ' ') {
  charHelp[j] = getText[i];
  j++;
  i++;
 }
 charHelp[j] = '\0';
 i++;
 int zeile = breite-atoi(charHelp);
  int currentField = zeile*breite;
 while (breite) {
   if (getText[i] == '*') {
     shmPtr_Sf[currentField]= -1;
   i++;
  }
  else if(getText[i] !=' ') {
   j=0;
   while(getText[i] != ' ') {
    charHelp[j] = getText[i];
    j++;
    i++;
   }
   charHelp[j] = '\0';
   shmPtr_Sf[currentField] = atoi(charHelp);
  }
  currentField++;
  i++;
  breite--;
 }
}

variable_types:
getText
char *

variable_types:
charHelp
char [255]

variable_types: j int

variable_types: zeile int

variable_types: currentField int


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

if ( configstruct[768] >= a1 )
{
va_start(arg, a2);
vsnprintf(s, 0x400uLL, a2, arg);
if ( !a1 )
printf("\x1B[1m\x1B[31m");
result = printf("%s\x1B[0m", s);
}
return result;
}

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

if ( configstruct[768] >= a1 )
{
va_start(arg, a2);
vsnprintf(s, 0x400uLL, a2, arg);
if ( !a1 )
printf("\x1B[1m\x1B[31m");
result = printf("%s\x1B[0m", s);
}
return result;
}

original_code:
void log_printf(int level, const char *fmt, ...)
{
    if (level > configstruct.loglevel) return;
    va_list ap;
    char msg[1024];
    __builtin_va_start(ap,fmt);
    vsnprintf(msg, sizeof(msg), fmt, ap);
    __builtin_va_end(ap);
    if (level == 0) {
 printf("\033[1m\033[31m");
    }
    printf("%s""\033[0m", msg);
}

canonical_original_code:
void log_printf(int level, char *fmt, ...)
{
    if (level > configstruct.loglevel) return;
    __builtin_va_list ap;
    char msg[1024];
    __builtin_va_start(ap,fmt);
    vsnprintf(msg, sizeof(msg), fmt, ap);
    __builtin_va_end(ap);
    if (level == 0) {
 printf("\033[1m\033[31m");
    }
    printf("%s""\033[0m", msg);
}

variable_types: level int

variable_types:
fmt
char *

variable_types:
msg
char [1024]


trimwhitespace

decompiled_code:
char *__fastcall trimwhitespace(char *s)
{
const unsigned __int16 *v2; // rbx
__int64 v3; // rdx
char *v4; // rax

v2 = *_ctype_b_loc();
while ( 1 )
{
v3 = *s;
if ( (v2[v3] & 0x2000) == 0 )
break;
++s;
}
if ( (_BYTE)v3 )
{
v4 = &s[strlen(s) - 1];
if ( s < v4 )
{
do
{
if ( (v2[*v4] & 0x2000) == 0 )
break;
--v4;
}
while ( s != v4 );
}
v4[1] = 0;
}
return s;
}

original_code:
char *trimwhitespace(char *str)
{
  char *end;
  while(((*__ctype_b_loc ())[(int) ((*str))] & (unsigned short int) _ISspace)) str++;
  if(*str == 0)
    return str;
  end = str + strlen(str) - 1;
  while(end > str && ((*__ctype_b_loc ())[(int) ((*end))] & (unsigned short int) _ISspace)) end--;
  *(end+1) = 0;
  return str;
}

canonical_original_code:
char *trimwhitespace(char *str)
{
  char *end;
  while(((*__ctype_b_loc ())[(int) ((*str))] & (unsigned short) _ISspace)) str++;
  if(*str == 0)
    return str;
  end = str + strlen(str) - 1;
  while(end > str && ((*__ctype_b_loc ())[(int) ((*end))] & (unsigned short) _ISspace)) end--;
  *(end+1) = 0;
  return str;
}

variable_types:
str
char *

variable_types:
end
char *

return_type: char *


decompiled_code:
size_t __fastcall trimwhitespace2(void *dest, __int64 a2, const char *a3)
{
size_t v3; // r12
const unsigned __int16 *v5; // r12
__int64 v6; // rdx
size_t v7; // rdx
const char *v8; // rax
unsigned __int64 v9; // rax

v3 = 0LL;
if ( !a2 )
return v3;
v5 = *_ctype_b_loc();
while ( 1 )
{
v6 = *a3;
if ( (v5[v6] & 0x2000) == 0 )
break;
++a3;
}
if ( (_BYTE)v6 )
{
v7 = strlen(a3);
v8 = &a3[v7 - 1];
if ( a3 < v8 )
{
while ( (v5[*v8] & 0x2000) != 0 )
{
if ( a3 == v8 - 1 )
goto LABEL_12;
--v8;
}
++v8;
}
else
{
v8 = &a3[v7];
}
LABEL_12:
v9 = v8 - a3;
v3 = a2 - 1;
if ( a2 - 1 > v9 )
v3 = v9;
memcpy(dest, a3, v3);
*((_BYTE *)dest + v3) = 0;
return v3;
}
*(_BYTE *)dest = 0;
return 1LL;
}

canonical_decompiled_code:
size_t __fastcall func1(void *dest, __int64 a2, const char *a3)
{
size_t v3; // r12
const unsigned __int16 *v5; // r12
__int64 v6; // rdx
size_t v7; // rdx
const char *v8; // rax
unsigned __int64 v9; // rax

v3 = 0LL;
if ( !a2 )
return v3;
v5 = *_ctype_b_loc();
while ( 1 )
{
v6 = *a3;
if ( (v5[v6] & 0x2000) == 0 )
break;
++a3;
}
if ( (_BYTE)v6 )
{
v7 = strlen(a3);
v8 = &a3[v7 - 1];
if ( a3 < v8 )
{
while ( (v5[*v8] & 0x2000) != 0 )
{
if ( a3 == v8 - 1 )
goto LABEL_12;
--v8;
}
++v8;
}
else
{
v8 = &a3[v7];
}
LABEL_12:
v9 = v8 - a3;
v3 = a2 - 1;
if ( a2 - 1 > v9 )
v3 = v9;
memcpy(dest, a3, v3);
*((_BYTE *)dest + v3) = 0;
return v3;
}
*(_BYTE *)dest = 0;
return 1LL;
}

original_code:
size_t trimwhitespace2(char *out, size_t len, const char *str)
{
  if(len == 0)
    return 0;
  const char *end;
  size_t out_size;
  while(((*__ctype_b_loc ())[(int) ((*str))] & (unsigned short int) _ISspace)) str++;
  if(*str == 0)
  {
    *out = 0;
    return 1;
  }
  end = str + strlen(str) - 1;
  while(end > str && ((*__ctype_b_loc ())[(int) ((*end))] & (unsigned short int) _ISspace)) end--;
  end++;
  out_size = (end - str) < len-1 ? (end - str) : len-1;
  memcpy(out, str, out_size);
  out[out_size] = 0;
  return out_size;
}

canonical_original_code:
unsigned long trimwhitespace2(char *out, unsigned long len, char *str)
{
  if(len == 0)
    return 0;
  char *end;
  unsigned long out_size;
  while(((*__ctype_b_loc ())[(int) ((*str))] & (unsigned short) _ISspace)) str++;
  if(*str == 0)
  {
    *out = 0;
    return 1;
  }
  end = str + strlen(str) - 1;
  while(end > str && ((*__ctype_b_loc ())[(int) ((*end))] & (unsigned short) _ISspace)) end--;
  end++;
  out_size = (end - str) < len-1 ? (end - str) : len-1;
  memcpy(out, str, out_size);
  out[out_size] = 0;
  return out_size;
}

variable_types:
out
char *

variable_types:
len
unsigned long

return_type: unsigned long


decompiled_code:
int __fastcall trimwhitespace2ToInt(const char *a1)
{
char v2[1032]; // [rsp+0h] [rbp-408h] BYREF

trimwhitespace2(v2, 1024LL, a1);
return atoi(v2);
}

canonical_decompiled_code:
int __fastcall func2(const char *a1)
{
char v2[1032]; // [rsp+0h] [rbp-408h] BYREF

func1(v2, 1024LL, a1);
return atoi(v2);
}

original_code:
int trimwhitespace2ToInt(const char *str)
{
 char outline[1024];
 trimwhitespace2(outline, 1024, str);
 return atoi(outline);
}

canonical_original_code:
int trimwhitespace2ToInt(char *str)
{
 char outline[1024];
 trimwhitespace2(outline, 1024, str);
 return atoi(outline);
}

variable_types:
outline
char [1024]


cmpTwoInvertBits

decompiled_code:
__int64 __fastcall cmpTwoInvertBits(int a1, int a2)
{
int v2; // esi
int v3; // eax
unsigned int v4; // er8

v2 = a1 & a2;
v3 = 4;
do
{
v4 = v2 & 1;
if ( (v2 & 1) != 0 )
break;
v2 >>= 1;
--v3;
}
while ( v3 );
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1, int a2)
{
int v2; // esi
int v3; // eax
unsigned int v4; // er8

v2 = a1 & a2;
v3 = 4;
do
{
v4 = v2 & 1;
if ( (v2 & 1) != 0 )
break;
v2 >>= 1;
--v3;
}
while ( v3 );
return v4;
}

original_code:
int cmpTwoInvertBits(int a, int b) {
 int i = 4;
 int zwerg = a&b;
 while(i) {
  if(zwerg & 1) {
   return 1;
  }
  zwerg >>= 1;
  i--;
 }
 return 0;
}

variable_types: a int

variable_types: b int

variable_types: i int

variable_types: zwerg int


compareFourStones

decompiled_code:
__int64 __fastcall compareFourStones(int a1, int a2, int a3, int a4)
{
unsigned int v4; // er11
int v5; // edx
unsigned int v6; // er9
int v7; // er10
int v9; // edx
int v10; // ecx
unsigned int v11; // er9

v4 = 1;
if ( (a1 & a2 & a4 & a3) <= 0
&& (unsigned int)cmpTwoInvertBits(~a1, ~a2) == 1
&& (unsigned int)cmpTwoInvertBits(~(v7 | v6), ~v5) == 1 )
{
LOBYTE(v4) = (unsigned int)cmpTwoInvertBits(~(v9 | v11), ~v10) == 1;
}
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func2(int a1, int a2, int a3, int a4)
{
unsigned int v4; // er11
int v5; // edx
unsigned int v6; // er9
int v7; // er10
int v9; // edx
int v10; // ecx
unsigned int v11; // er9

v4 = 1;
if ( (a1 & a2 & a4 & a3) <= 0
&& (unsigned int)func1(~a1, ~a2) == 1
&& (unsigned int)func1(~(v7 | v6), ~v5) == 1 )
{
LOBYTE(v4) = (unsigned int)func1(~(v9 | v11), ~v10) == 1;
}
return v4;
}

original_code:
int compareFourStones(int a, int b, int c, int d) {
 int zwerg;
 if ((a&b&c&d) >0) {
  return 1;
 }
 a = ~a;
 b = ~b;
 c = ~c;
 d = ~d;
 if (cmpTwoInvertBits(a,b) ==1) {
  zwerg = a & b;
  if (cmpTwoInvertBits(zwerg,c) == 1) {
   zwerg = zwerg & c;
   if (cmpTwoInvertBits(zwerg,d) ==1) {
    return 1;
   }
  }
 }
 return 0;
}

variable_types: c int

variable_types: d int


checkFreiesFeld

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

result = a1;
if ( *(int *)(shmPtr_Sf + 4LL * a1) >= 0 )
{
result = a2;
if ( *(int *)(shmPtr_Sf + 4LL * (int)a2) >= 0 )
{
result = a3;
if ( *(int *)(shmPtr_Sf + 4LL * (int)a3) >= 0 )
result = a4 & (unsigned int)(*(int *)(shmPtr_Sf + 4LL * a4) >> 31);
}
}
return result;
}

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

result = a1;
if ( *(int *)(shmPtr_Sf + 4LL * a1) >= 0 )
{
result = a2;
if ( *(int *)(shmPtr_Sf + 4LL * (int)a2) >= 0 )
{
result = a3;
if ( *(int *)(shmPtr_Sf + 4LL * (int)a3) >= 0 )
result = a4 & (unsigned int)(*(int *)(shmPtr_Sf + 4LL * a4) >> 31);
}
}
return result;
}

original_code:
int checkFreiesFeld(int a, int b, int c, int d) {
 if (shmPtr_Sf[a] <0 ) return a;
 if (shmPtr_Sf[b] <0 ) return b;
 if (shmPtr_Sf[c] <0 ) return c;
 if (shmPtr_Sf[d] <0 ) return d;
 return 0;
}


checkReihe

decompiled_code:
__int64 __fastcall checkReihe(int a1, signed int a2, signed int a3, int a4, __int64 a5, __int64 a6)
{
__int64 v6; // r12
__int64 v7; // rbx
__int64 v8; // r15
int v9; // er12
int v10; // edx
int v11; // er13
int v12; // er14
int v13; // edx
__int64 v14; // rbx
unsigned int v15; // eax
int v16; // er15
int v17; // er13
unsigned int v18; // er12
unsigned int v19; // er15
int v21; // edi
int *v22; // [rsp+10h] [rbp-78h]
int *v23; // [rsp+18h] [rbp-70h]
int *v24; // [rsp+20h] [rbp-68h]
int *v25; // [rsp+28h] [rbp-60h]
__int64 v29; // [rsp+40h] [rbp-48h]
__int64 v30; // [rsp+48h] [rbp-40h]

v6 = a3;
v7 = a4;
v29 = 4LL * a3;
v30 = 4LL * a4;
if ( *(_DWORD *)(a5 + v30) + *(_DWORD *)(a5 + v29) + *(_DWORD *)(a5 + 4LL * a1) + *(_DWORD *)(a5 + 4LL * a2) != 3 )
return (unsigned int)-1;
v8 = (unsigned int)checkFreiesFeld(a1, a2, a3, a4);
log_printf(2LL, "freies Feld: %i\n", v8);
if ( a1 == (_DWORD)v8 )
{
v12 = *(_DWORD *)(shmPtr + 584LL);
v10 = *(_DWORD *)(shmPtr_Sf + 4 * v6);
v11 = *(_DWORD *)(shmPtr_Sf + 4LL * a2);
v9 = *(_DWORD *)(shmPtr_Sf + 4 * v7);
}
else if ( a2 == (_DWORD)v8 )
{
v12 = *(_DWORD *)(shmPtr_Sf + 4LL * a1);
v11 = *(_DWORD *)(shmPtr + 584LL);
v10 = *(_DWORD *)(shmPtr_Sf + 4 * v6);
v9 = *(_DWORD *)(shmPtr_Sf + 4 * v7);
}
else if ( a3 == (_DWORD)v8 )
{
v12 = *(_DWORD *)(shmPtr_Sf + 4LL * a1);
v11 = *(_DWORD *)(shmPtr_Sf + 4LL * a2);
v10 = *(_DWORD *)(shmPtr + 584LL);
v9 = *(_DWORD *)(shmPtr_Sf + 4 * v7);
}
else if ( a4 == (_DWORD)v8 )
{
v10 = *(_DWORD *)(shmPtr_Sf + 4 * v6);
v12 = *(_DWORD *)(shmPtr_Sf + 4LL * a1);
v11 = *(_DWORD *)(shmPtr_Sf + 4LL * a2);
v9 = *(_DWORD *)(shmPtr + 584LL);
}
else
{
v9 = 0;
v10 = 0;
v11 = 0;
v12 = 0;
}
if ( (unsigned int)compareFourStones(v12, v11, v10, v9) == 1 )
{
v21 = v8;
v19 = 16;
saveField(v21);
log_printf(2LL, "gewonnen!\n");
}
else
{
v14 = 0LL;
v25 = (int *)(shmPtr_Sf + 4LL * a1);
v24 = (int *)(shmPtr_Sf + 4LL * a2);
v23 = (int *)(shmPtr_Sf + v29);
v22 = (int *)(shmPtr_Sf + v30);
v15 = v8;
v16 = v11;
v17 = v9;
v18 = v15;
do
{
if ( a1 == v18 )
{
v12 = v14;
v16 = *v24;
v13 = *v23;
v17 = *v22;
}
else if ( a2 == v18 )
{
v16 = v14;
v12 = *v25;
v13 = *v23;
v17 = *v22;
}
else if ( a3 == v18 )
{
v13 = v14;
v12 = *v25;
v16 = *v24;
v17 = *v22;
}
else if ( a4 == v18 )
{
v17 = v14;
v12 = *v25;
v16 = *v24;
v13 = *v23;
}
if ( (unsigned int)compareFourStones(v12, v16, v13, v17) == 1 )
*(_DWORD *)(a6 + 4 * v14) = 1;
++v14;
}
while ( v14 != 16 );
v19 = v18;
}
return v19;
}

original_code:
int checkReihe(int a, int b, int c, int d, int felder[], int badStones[]) {
 if (felder[a]+felder[b]+felder[c]+felder[d] == 3) {
  int frei = checkFreiesFeld(a,b,c,d);
  int stein1,stein2,stein3,stein4;
  stein1 =0; stein2 =0; stein3 =0; stein4 =0;
  log_printf(2,"freies Feld: %i\n",frei);
  if (frei == a) {
   stein1 = shmPtr->nextStone;
   stein2 = shmPtr_Sf[b];
   stein3 = shmPtr_Sf[c];
   stein4 = shmPtr_Sf[d];
  }
  else if (frei == b) {
   stein1 = shmPtr_Sf[a];
   stein2 = shmPtr->nextStone;
   stein3 = shmPtr_Sf[c];
   stein4 = shmPtr_Sf[d];
  }
  else if (frei == c) {
   stein1 = shmPtr_Sf[a];
   stein2 = shmPtr_Sf[b];
   stein3 = shmPtr->nextStone;
   stein4 = shmPtr_Sf[d];
  }
  else if (frei == d) {
   stein1 = shmPtr_Sf[a];
   stein2 = shmPtr_Sf[b];
   stein3 = shmPtr_Sf[c];
   stein4 = shmPtr->nextStone;
  }
  if (compareFourStones(stein1,stein2,stein3,stein4) == 1) {
   saveField(frei);
   log_printf(2,"gewonnen!\n");
   return 16;
  }
  for(int i=0;i<16;i++) {
   if (frei == a) {
    stein1 = i;
    stein2 = shmPtr_Sf[b];
    stein3 = shmPtr_Sf[c];
    stein4 = shmPtr_Sf[d];
   }
   else if (frei == b) {
    stein1 = shmPtr_Sf[a];
    stein2 = i;
    stein3 = shmPtr_Sf[c];
    stein4 = shmPtr_Sf[d];
   }
   else if (frei == c) {
    stein1 = shmPtr_Sf[a];
    stein2 = shmPtr_Sf[b];
    stein3 = i;
    stein4 = shmPtr_Sf[d];
   }
   else if (frei == d) {
    stein1 = shmPtr_Sf[a];
    stein2 = shmPtr_Sf[b];
    stein3 = shmPtr_Sf[c];
    stein4 = i;
   }
   if (compareFourStones(stein1,stein2,stein3,stein4) ==1) {
    badStones[i] = 1;
   }
  }
  return frei;
 }
 return -1;
}

canonical_original_code:
int checkReihe(int a, int b, int c, int d, int felder[], int badStones[]) {
 if (felder[a]+felder[b]+felder[c]+felder[d] == 3) {
  int frei = checkFreiesFeld(a,b,c,d);
  int stein1; int stein2; int stein3; int stein4;
  stein1 =0; stein2 =0; stein3 =0; stein4 =0;
  log_printf(2,"freies Feld: %i\n",frei);
  if (frei == a) {
   stein1 = shmPtr->nextStone;
   stein2 = shmPtr_Sf[b];
   stein3 = shmPtr_Sf[c];
   stein4 = shmPtr_Sf[d];
  }
  else if (frei == b) {
   stein1 = shmPtr_Sf[a];
   stein2 = shmPtr->nextStone;
   stein3 = shmPtr_Sf[c];
   stein4 = shmPtr_Sf[d];
  }
  else if (frei == c) {
   stein1 = shmPtr_Sf[a];
   stein2 = shmPtr_Sf[b];
   stein3 = shmPtr->nextStone;
   stein4 = shmPtr_Sf[d];
  }
  else if (frei == d) {
   stein1 = shmPtr_Sf[a];
   stein2 = shmPtr_Sf[b];
   stein3 = shmPtr_Sf[c];
   stein4 = shmPtr->nextStone;
  }
  if (compareFourStones(stein1,stein2,stein3,stein4) == 1) {
   saveField(frei);
   log_printf(2,"gewonnen!\n");
   return 16;
  }
  for(int i = 0;i<16;i++) {
   if (frei == a) {
    stein1 = i;
    stein2 = shmPtr_Sf[b];
    stein3 = shmPtr_Sf[c];
    stein4 = shmPtr_Sf[d];
   }
   else if (frei == b) {
    stein1 = shmPtr_Sf[a];
    stein2 = i;
    stein3 = shmPtr_Sf[c];
    stein4 = shmPtr_Sf[d];
   }
   else if (frei == c) {
    stein1 = shmPtr_Sf[a];
    stein2 = shmPtr_Sf[b];
    stein3 = i;
    stein4 = shmPtr_Sf[d];
   }
   else if (frei == d) {
    stein1 = shmPtr_Sf[a];
    stein2 = shmPtr_Sf[b];
    stein3 = shmPtr_Sf[c];
    stein4 = i;
   }
   if (compareFourStones(stein1,stein2,stein3,stein4) ==1) {
    badStones[i] = 1;
   }
  }
  return frei;
 }
 return -1;
}

variable_types:
felder
int []

variable_types:
badStones
int []

variable_types: frei int


randomStone

decompiled_code:
__int64 __fastcall randomStone(__int64 a1)
{
unsigned int v1; // er12

do
v1 = rand() % 16;
while ( *(_DWORD *)(a1 + 4LL * (int)v1) );
log_printf(2LL, "Naechster Stein: %i\n", v1);
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1)
{
unsigned int v1; // er12

do
v1 = rand() % 16;
while ( *(_DWORD *)(a1 + 4LL * (int)v1) );
log_printf(2LL, "Naechster Stein: %i\n", v1);
return v1;
}

original_code:
int randomStone(int stones[]) {
 int nextStein = rand() % 16;
while(1){
 if (stones[nextStein] ==0){
   log_printf(2,"Naechster Stein: %i\n",nextStein);
   return nextStein;
  }
 else{
   nextStein = rand() % 16;
  }
 }
 log_printf(2,"Naechster Stein: %i\n",nextStein);
 return -1;
}

variable_types:
stones
int []

variable_types: nextStein int


randomField

decompiled_code:
__int64 __fastcall randomField(_DWORD *a1)
{
int v1; // ebx
_DWORD *v2; // rax
int v3; // ecx
int v4; // edx
int v5; // edx
void *v6; // rsp
__int64 v7; // rax
__int64 v8; // rsi
unsigned int v9; // er12
void *v11; // rsp
_DWORD v12[4]; // [rsp+0h] [rbp-10h]

v1 = *(_DWORD *)(shmPtr + 588LL) * *(_DWORD *)(shmPtr + 592LL);
if ( v1 <= 0 )
{
v11 = alloca(4LL * v1);
}
else
{
v2 = a1;
v3 = *(_DWORD *)(shmPtr + 588LL) * *(_DWORD *)(shmPtr + 592LL);
v4 = 0;
do
v4 += *v2++;
while ( &a1[v1 - 1 + 1] != v2 );
v1 -= v4;
v5 = 0;
v6 = alloca(4LL * v1);
v7 = 0LL;
do
{
if ( !a1[v7] )
{
v8 = v5++;
v12[v8] = v7;
}
++v7;
}
while ( v3 != v7 );
}
v9 = v12[rand() % v1];
log_printf(2LL, "Tolles freies Feld: %i\n", v9);
return v9;
}

canonical_decompiled_code:
__int64 __fastcall func6(_DWORD *a1)
{
int v1; // ebx
_DWORD *v2; // rax
int v3; // ecx
int v4; // edx
int v5; // edx
void *v6; // rsp
__int64 v7; // rax
__int64 v8; // rsi
unsigned int v9; // er12
void *v11; // rsp
_DWORD v12[4]; // [rsp+0h] [rbp-10h]

v1 = *(_DWORD *)(shmPtr + 588LL) * *(_DWORD *)(shmPtr + 592LL);
if ( v1 <= 0 )
{
v11 = alloca(4LL * v1);
}
else
{
v2 = a1;
v3 = *(_DWORD *)(shmPtr + 588LL) * *(_DWORD *)(shmPtr + 592LL);
v4 = 0;
do
v4 += *v2++;
while ( &a1[v1 - 1 + 1] != v2 );
v1 -= v4;
v5 = 0;
v6 = alloca(4LL * v1);
v7 = 0LL;
do
{
if ( !a1[v7] )
{
v8 = v5++;
v12[v8] = v7;
}
++v7;
}
while ( v3 != v7 );
}
v9 = v12[rand() % v1];
log_printf(2LL, "Tolles freies Feld: %i\n", v9);
return v9;
}

original_code:
int randomField(int felder[]) {
 int len = shmPtr->hoehe * shmPtr->breite;
 int anzahlBesetzt = 0;
 for(int i = 0; i<len;i++){
  anzahlBesetzt += felder[i];
 }
 int freieFelder = len-anzahlBesetzt;
 int freieFelderArray[freieFelder];
 int j = 0;
 for(int i = 0; i<len;i++){
  if(felder[i] == 0){
   freieFelderArray[j] = i;
   j++;
  }
 }
 int random = rand() % freieFelder;
 int index = freieFelderArray[random];
 log_printf(2,"Tolles freies Feld: %i\n",index);
 return index;
}

canonical_original_code:
int randomField(int felder[]) {
 int len = shmPtr->hoehe * shmPtr->breite;
 int anzahlBesetzt = 0;
 for(int i = 0; i<len;i++){
  anzahlBesetzt += felder[i];
 }
 int freieFelder = len-anzahlBesetzt;
 int freieFelderArray[-1];
 int j = 0;
 for(int i = 0; i<len;i++){
  if(felder[i] == 0){
   freieFelderArray[j] = i;
   j++;
  }
 }
 int random = rand() % freieFelder;
 int index = freieFelderArray[random];
 log_printf(2,"Tolles freies Feld: %i\n",index);
 return index;
}

variable_types: len int

variable_types: anzahlBesetzt int

variable_types: freieFelder int

variable_types:
freieFelderArray
int [-1]

variable_types: j int

variable_types: random int

variable_types: index int