main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // rax
const char **v4; // rbx
double v5; // xmm0_8
const char *v6; // rdi
double v7; // xmm0_8
const char *v8; // rdi
double v9; // xmm0_8
const char *v10; // rdi
double v11; // xmm0_8
const char *v12; // rdx

v3 = argv[1];
v4 = argv;
if ( *(_WORD *)v3 == 28717 && !v3[2] )
{
allow_proposed = 1;
v4 = argv + 1;
}
v5 = atof(v4[2]);
v6 = v4[3];
lon_min = *(_QWORD *)&v5;
v7 = atof(v6);
v8 = v4[4];
lon_max = *(_QWORD *)&v7;
v9 = atof(v8);
v10 = v4[5];
lat_min = *(_QWORD *)&v9;
v11 = atof(v10);
v12 = v4[1];
lat_max = *(_QWORD *)&v11;
fprintf(stderr, "reading %s\n", v12);
read_osm_xml(v4[1]);
fwrite("calculating distances\n", 1uLL, 0x16uLL, stderr);
prepare_routing();
fwrite("routing\n", 1uLL, 8uLL, stderr);
find_distances();
fwrite("writing output\n", 1uLL, 0xFuLL, stderr);
dump_db();
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // rax
const char **v4; // rbx
double v5; // xmm0_8
const char *v6; // rdi
double v7; // xmm0_8
const char *v8; // rdi
double v9; // xmm0_8
const char *v10; // rdi
double v11; // xmm0_8
const char *v12; // rdx

v3 = argv[1];
v4 = argv;
if ( *(_WORD *)v3 == 28717 && !v3[2] )
{
allow_proposed = 1;
v4 = argv + 1;
}
v5 = atof(v4[2]);
v6 = v4[3];
lon_min = *(_QWORD *)&v5;
v7 = atof(v6);
v8 = v4[4];
lon_max = *(_QWORD *)&v7;
v9 = atof(v8);
v10 = v4[5];
lat_min = *(_QWORD *)&v9;
v11 = atof(v10);
v12 = v4[1];
lat_max = *(_QWORD *)&v11;
fprintf(stderr, "reading %s\n", v12);
read_osm_xml(v4[1]);
fwrite("calculating distances\n", 1uLL, 0x16uLL, stderr);
func3();
fwrite("routing\n", 1uLL, 8uLL, stderr);
func4();
fwrite("writing output\n", 1uLL, 0xFuLL, stderr);
func6();
return 0;
}

original_code:
int main(int argc, char **argv)
{
 if (!strcmp(argv[1], "-p")) {
  allow_proposed = 1;
  argv++;
 }
 lon_min = atof(argv[2]);
 lon_max = atof(argv[3]);
 lat_min = atof(argv[4]);
 lat_max = atof(argv[5]);
 fprintf(stderr, "reading %s\n", argv[1]);
 read_osm_xml(argv[1]);
 fprintf(stderr, "calculating distances\n");
 prepare_routing();
 fprintf(stderr, "routing\n");
 find_distances();
 fprintf(stderr, "writing output\n");
 dump_db();
 return 0;
}

variable_types: argc int

variable_types:
argv
char **


repo: wpwrak/subosm

decompiled_code:
__int64 __fastcall node_comp(_DWORD *a1, _DWORD *a2)
{
return (unsigned int)(*a1 - *a2);
}

canonical_decompiled_code:
__int64 __fastcall func0(_DWORD *a1, _DWORD *a2)
{
return (unsigned int)(*a1 - *a2);
}

original_code:
static int node_comp(gconstpointer a, gconstpointer b)
{
 const struct node *na = a, *nb = b;
 return na->id - nb->id;
}

canonical_original_code:
static int node_comp(void *a, void *b)
{
 struct node *na = a; struct node *nb = b;
 return na->id - nb->id;
}

variable_types:
a
void *

variable_types:
b
void *

variable_types: struct node { int id; int x; _Bool station; _Bool proposed; int distance; struct edge { struct node *n; int len; int tag; } *edges; int n_edges; int tag; } *

return_type: int

user_defined_types: struct node { int id; int x; _Bool station; _Bool proposed; int distance; struct edge *edges; int n_edges; int tag; }


decompiled_code:
__int64 null_handler()
{
return 0LL;
}

canonical_decompiled_code:
__int64 func1()
{
return 0LL;
}

original_code:
static struct handler *null_handler(void *obj, const char *name,
    const char **attr)
{
 return ((void *)0);
}

canonical_original_code:
static struct handler *null_handler(void *obj, char *name, char **attr)
{
 return ((void *)0);
}

variable_types:
obj
void *

variable_types:
name
char *

variable_types:
attr
char **

return_type: struct handler { struct handler *(*fn)(void *obj, char *name, char **attr); void (*end)(void *obj); void *obj; struct handler *prev; } *


decompiled_code:
__int64 __fastcall node_handler(__int64 a1, const char *a2, __int64 *a3)
{
__int64 v3; // rax

if ( *(_BYTE *)(a1 + 12) )
return 0LL;
if ( strcmp(a2, (const char *)&off_17D78CC8) )
return 0LL;
v3 = *a3;
if ( !*a3 )
return 0LL;
while ( *(_BYTE *)v3 != 118
|| *(_BYTE *)(v3 + 1)
|| strcmp((const char *)a3[1], (const char *)&off_17D78CC8 + 4) && strcmp((const char *)a3[1], "subway_entrance") )
{
if ( !strcmp((const char *)v3, "proposed") || !strcmp((const char *)a3[1], "proposed") )
*(_BYTE *)(a1 + 13) = 1;
v3 = a3[2];
a3 += 2;
if ( !v3 )
return 0LL;
}
*(_BYTE *)(a1 + 12) = 1;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, const char *a2, __int64 *a3)
{
__int64 v3; // rax

if ( *(_BYTE *)(a1 + 12) )
return 0LL;
if ( strcmp(a2, (const char *)&off_17D78CC8) )
return 0LL;
v3 = *a3;
if ( !*a3 )
return 0LL;
while ( *(_BYTE *)v3 != 118
|| *(_BYTE *)(v3 + 1)
|| strcmp((const char *)a3[1], (const char *)&off_17D78CC8 + 4) && strcmp((const char *)a3[1], "subway_entrance") )
{
if ( !strcmp((const char *)v3, "proposed") || !strcmp((const char *)a3[1], "proposed") )
*(_BYTE *)(a1 + 13) = 1;
v3 = a3[2];
a3 += 2;
if ( !v3 )
return 0LL;
}
*(_BYTE *)(a1 + 12) = 1;
return 0LL;
}

original_code:
static struct handler *node_handler(void *obj, const char *name,
    const char **attr)
{
 struct node *n = obj;
 if (n->station)
  return ((void *)0);
 if (strcmp(name, "tag"))
  return ((void *)0);
 while (*attr) {
  if (!strcmp(attr[0], "v") &&
      (!strcmp(attr[1], "subway") ||
      !strcmp(attr[1], "subway_entrance"))) {
   n->station = 1;
   break;
  }
  if (!strcmp(attr[0], "proposed") ||
      !strcmp(attr[1], "proposed"))
   n->proposed = 1;
  attr += 2;
 }
 return ((void *)0);
}

canonical_original_code:
static struct handler *node_handler(void *obj, char *name, char **attr)
{
 struct node *n = obj;
 if (n->station)
  return ((void *)0);
 if (strcmp(name, "tag"))
  return ((void *)0);
 while (*attr) {
  if (!strcmp(attr[0], "v") &&
      (!strcmp(attr[1], "subway") ||
      !strcmp(attr[1], "subway_entrance"))) {
   n->station = 1;
   break;
  }
  if (!strcmp(attr[0], "proposed") ||
      !strcmp(attr[1], "proposed"))
   n->proposed = 1;
  attr += 2;
 }
 return ((void *)0);
}

user_defined_types: struct handler { struct handler *(*fn)(void *obj, char *name, char **attr); void (*end)(void *obj); void *obj; struct handler *prev; }

user_defined_types: struct edge { struct node *n; int len; int tag; }


variable_types: lat double

variable_types: lon double

return_type: void


end

decompiled_code:
void end()
{
_QWORD *v0; // rdi
void (__fastcall *v1)(_QWORD); // rax
void *v2; // rbx

v0 = handler;
v1 = (void (__fastcall *)(_QWORD))*((_QWORD *)handler + 1);
if ( v1 )
{
v1(*((_QWORD *)handler + 2));
v0 = handler;
}
v2 = (void *)v0[3];
free(v0);
handler = v2;
}

canonical_decompiled_code:
void func4()
{
_QWORD *v0; // rdi
void (__fastcall *v1)(_QWORD); // rax
void *v2; // rbx

v0 = handler;
v1 = (void (__fastcall *)(_QWORD))*((_QWORD *)handler + 1);
if ( v1 )
{
v1(*((_QWORD *)handler + 2));
v0 = handler;
}
v2 = (void *)v0[3];
free(v0);
handler = v2;
}

original_code:
static void end(void *user, const char *name)
{
 struct handler *prev;
 if (handler->end)
  handler->end(handler->obj);
 prev = handler->prev;
 free(handler);
 handler = prev;
}

canonical_original_code:
static void end(void *user, char *name)
{
 struct handler *prev;
 if (handler->end)
  handler->end(handler->obj);
 prev = handler->prev;
 free(handler);
 handler = prev;
}

variable_types:
user
void *

variable_types: struct handler { struct handler *(*fn)(void *obj, char *name, char **attr); void (*end)(void *obj); void *obj; struct handler *prev; } *


decompiled_code:
char *__fastcall link_nodes(__int64 a1, __int64 a2)
{
__int64 v4; // rsi
char *v5; // rdi
__int64 v6; // rsi
char *result; // rax
void *v8; // rax
void *v9; // rdx
__int64 v10; // rax
int v11; // ecx

v4 = *(int *)(a1 + 32);
v5 = *(char **)(a1 + 24);
v6 = 16 * v4;
if ( v5 == &v5[v6] )
{
LABEL_6:
v8 = realloc(v5, v6 + 16);
++n_edges;
*(_QWORD *)(a1 + 24) = v8;
v9 = v8;
v10 = *(int *)(a1 + 32);
v11 = v10 + 1;
result = (char *)(16 * v10);
*(_DWORD *)(a1 + 32) = v11;
*(_QWORD *)&result[(_QWORD)v9] = a2;
}
else
{
result = v5;
while ( *(_QWORD *)result != a2 )
{
result += 16;
if ( result == &v5[v6] )
goto LABEL_6;
}
}
return result;
}

original_code:
static void link_nodes(struct node *a, struct node *b)
{
 struct edge *e;
 for (e = a->edges; e != a->edges+a->n_edges; e++)
  if (e->n == b) {
   if (verbose)
    fprintf(stderr,
        "ignoring redundant edge %d -> %d\n",
        a->id, b->id);
   return;
  }
 a->edges = realloc(a->edges, sizeof(struct edge) * (a->n_edges + 1));
 a->edges[a->n_edges++].n = b;
 n_edges++;
}

variable_types:
b
struct node *

variable_types: struct edge { struct node { int id; int x; _Bool station; _Bool proposed; int distance; struct edge *edges; int n_edges; int tag; } *n; int len; int tag; } *


decompiled_code:
void end_way()
{
__int64 v0; // rbx
__int64 *v1; // rax
_QWORD *v2; // rdi
char v3; // bp
__int64 v4; // rbx

if ( keep )
{
v0 = vertices;
if ( !vertices )
return;
do
{
v1 = *(__int64 **)(v0 + 8);
if ( !v1 )
break;
link_nodes(*(_QWORD *)v0, *v1);
link_nodes(**(_QWORD **)(v0 + 8), *(_QWORD *)v0);
v0 = *(_QWORD *)(v0 + 8);
}
while ( v0 );
}
v2 = (_QWORD *)vertices;
v3 = subway;
if ( vertices )
{
while ( 1 )
{
if ( v3 )
*(_BYTE *)(*v2 + 12LL) = 1;
v4 = v2[1];
free(v2);
vertices = v4;
if ( !v4 )
break;
v2 = (_QWORD *)v4;
}
}
}

canonical_decompiled_code:
void func6()
{
__int64 v0; // rbx
__int64 *v1; // rax
_QWORD *v2; // rdi
char v3; // bp
__int64 v4; // rbx

if ( keep )
{
v0 = vertices;
if ( !vertices )
return;
do
{
v1 = *(__int64 **)(v0 + 8);
if ( !v1 )
break;
func5(*(_QWORD *)v0, *v1);
func5(**(_QWORD **)(v0 + 8), *(_QWORD *)v0);
v0 = *(_QWORD *)(v0 + 8);
}
while ( v0 );
}
v2 = (_QWORD *)vertices;
v3 = subway;
if ( vertices )
{
while ( 1 )
{
if ( v3 )
*(_BYTE *)(*v2 + 12LL) = 1;
v4 = v2[1];
free(v2);
vertices = v4;
if ( !v4 )
break;
v2 = (_QWORD *)v4;
}
}
}

original_code:
static void end_way(void *obj)
{
 struct vertex *v, *prev;
 if (keep)
  for (v = vertices; v && v->prev; v = v->prev) {
   link_nodes(v->node, v->prev->node);
   link_nodes(v->prev->node, v->node);
  }
 while (vertices) {
  if (subway)
   vertices->node->station = 1;
  prev = vertices->prev;
  free(vertices);
  vertices = prev;
 }
}

canonical_original_code:
static void end_way(void *obj)
{
 struct vertex *v; struct vertex *prev;
 if (keep)
  for (v = vertices; v && v->prev; v = v->prev) {
   link_nodes(v->node, v->prev->node);
   link_nodes(v->prev->node, v->node);
  }
 while (vertices) {
  if (subway)
   vertices->node->station = 1;
  prev = vertices->prev;
  free(vertices);
  vertices = prev;
 }
}

variable_types: struct vertex { struct node { int id; int x; _Bool station; _Bool proposed; int distance; struct edge { struct node *n; int len; int tag; } *edges; int n_edges; int tag; } *node; struct vertex *prev; } *

user_defined_types: struct vertex { struct node *node; struct vertex *prev; }


decompiled_code:
__int64 __fastcall way_handler(__int64 a1, __int64 a2, const char **a3)
{
const char *v3; // rax
int v4; // er8
const char *v6; // rsi
__int64 v7; // rbx
_QWORD *v8; // rax
__int64 v9; // rdx
int v10[3]; // [rsp+Ch] [rbp-Ch] BYREF

v10[0] = 0;
if ( !strcmp((const char *)a2, (const char *)&off_17D78CC8) )
{
if ( !keep )
{
v3 = *a3;
if ( *a3 )
{
while ( 1 )
{
v4 = *(unsigned __int8 *)v3;
if ( v4 == 107 && !v3[1] && !strcmp(a3[1], "highway") )
break;
if ( v4 == 118 && !v3[1] && !strcmp(a3[1], "subway_entrance") )
subway = 1;
v3 = a3[2];
a3 += 2;
if ( !v3 )
return 0LL;
}
keep = 1;
}
}
return 0LL;
}
if ( *(_BYTE *)a2 != 110 || *(_BYTE *)(a2 + 1) != 100 || *(_BYTE *)(a2 + 2) )
return 0LL;
v6 = *a3;
if ( *a3 )
{
while ( strcmp(v6, (const char *)&off_17D78CF4) )
{
v6 = a3[2];
a3 += 2;
if ( !v6 )
goto LABEL_21;
}
v10[0] = atoi(a3[1]);
}
LABEL_21:
v7 = g_tree_lookup(tree, v10, a3);
if ( !v7 )
return 0LL;
v8 = malloc(0x10uLL);
v9 = vertices;
*v8 = v7;
v8[1] = v9;
vertices = (__int64)v8;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, __int64 a2, const char **a3)
{
const char *v3; // rax
int v4; // er8
const char *v6; // rsi
__int64 v7; // rbx
_QWORD *v8; // rax
__int64 v9; // rdx
int v10[3]; // [rsp+Ch] [rbp-Ch] BYREF

v10[0] = 0;
if ( !strcmp((const char *)a2, (const char *)&off_17D78CC8) )
{
if ( !keep )
{
v3 = *a3;
if ( *a3 )
{
while ( 1 )
{
v4 = *(unsigned __int8 *)v3;
if ( v4 == 107 && !v3[1] && !strcmp(a3[1], "highway") )
break;
if ( v4 == 118 && !v3[1] && !strcmp(a3[1], "subway_entrance") )
subway = 1;
v3 = a3[2];
a3 += 2;
if ( !v3 )
return 0LL;
}
keep = 1;
}
}
return 0LL;
}
if ( *(_BYTE *)a2 != 110 || *(_BYTE *)(a2 + 1) != 100 || *(_BYTE *)(a2 + 2) )
return 0LL;
v6 = *a3;
if ( *a3 )
{
while ( strcmp(v6, (const char *)&off_17D78CF4) )
{
v6 = a3[2];
a3 += 2;
if ( !v6 )
goto LABEL_21;
}
v10[0] = atoi(a3[1]);
}
LABEL_21:
v7 = g_tree_lookup(tree, v10, a3);
if ( !v7 )
return 0LL;
v8 = malloc(0x10uLL);
v9 = vertices;
*v8 = v7;
v8[1] = v9;
vertices = (__int64)v8;
return 0LL;
}

original_code:
static struct handler *way_handler(void *obj, const char *name,
    const char **attr)
{
 struct node *node;
 struct vertex *v;
 int ref = 0;
 if (!strcmp(name, "tag")) {
  if (keep)
   return ((void *)0);
  while (*attr) {
   if (!strcmp(attr[0], "k") &&
       !strcmp(attr[1], "highway")) {
    keep = 1;
    break;
   }
   if (!strcmp(attr[0], "v") &&
       !strcmp(attr[1], "subway_entrance")) {
    subway = 1;
   }
   attr += 2;
  }
  return ((void *)0);
 }
 if (strcmp(name, "nd"))
  return ((void *)0);
 while (*attr) {
  if (!strcmp(attr[0], "ref")) {
   ref = atoi(attr[1]);
   break;
  }
  attr += 2;
 }
 node = g_tree_lookup(tree, &ref);
 if (!node) {
  if (verbose)
   fprintf(stderr, "unknown node %d\n", ref);
  return ((void *)0);
 }
 v = (struct vertex *) malloc(sizeof(struct vertex));
 v->node = node;
 v->prev = vertices;
 vertices = v;
 return ((void *)0);
}

canonical_original_code:
static struct handler *way_handler(void *obj, char *name, char **attr)
{
 struct node *node;
 struct vertex *v;
 int ref = 0;
 if (!strcmp(name, "tag")) {
  if (keep)
   return ((void *)0);
  while (*attr) {
   if (!strcmp(attr[0], "k") &&
       !strcmp(attr[1], "highway")) {
    keep = 1;
    break;
   }
   if (!strcmp(attr[0], "v") &&
       !strcmp(attr[1], "subway_entrance")) {
    subway = 1;
   }
   attr += 2;
  }
  return ((void *)0);
 }
 if (strcmp(name, "nd"))
  return ((void *)0);
 while (*attr) {
  if (!strcmp(attr[0], "ref")) {
   ref = atoi(attr[1]);
   break;
  }
  attr += 2;
 }
 node = g_tree_lookup(tree, &ref);
 if (!node) {
  if (verbose)
   fprintf(stderr, "unknown node %d\n", ref);
  return ((void *)0);
 }
 v = (struct vertex *) malloc(sizeof(struct vertex));
 v->node = node;
 v->prev = vertices;
 vertices = v;
 return ((void *)0);
}

variable_types: ref int


deleteSudoku

repo: wrousseau/sudoku-multithread-solver

decompiled_code:
void deleteSudoku()
{
void **v0; // rax
__int64 v1; // rbx
void *v2; // rdi

v0 = (void **)sudoku;
if ( *((_BYTE *)sudoku + 12) )
{
v1 = 0LL;
do
{
v2 = (void *)*((_QWORD *)*v0 + v1++);
free(v2);
v0 = (void **)sudoku;
}
while ( *((unsigned __int8 *)sudoku + 12) > (int)v1 );
}
free(*v0);
free(sudoku);
}

canonical_decompiled_code:
void func0()
{
void **v0; // rax
__int64 v1; // rbx
void *v2; // rdi

v0 = (void **)sudoku;
if ( *((_BYTE *)sudoku + 12) )
{
v1 = 0LL;
do
{
v2 = (void *)*((_QWORD *)*v0 + v1++);
free(v2);
v0 = (void **)sudoku;
}
while ( *((unsigned __int8 *)sudoku + 12) > (int)v1 );
}
free(*v0);
free(sudoku);
}

original_code:
void deleteSudoku()
{
 for( int i = 0; i < sudoku->blocksPerSquare ; i++)
 {
  free(sudoku->grid[i]);
 }
 free(sudoku->grid);
 free(sudoku);
}

variable_types: i int


initSubGrid

decompiled_code:
__int64 __fastcall initSubGrid(__int64 a1, int a2)
{
int v2; // eax
double v3; // xmm0_8
double v4; // xmm0_8
int v5; // er13
_QWORD *v6; // rax
_QWORD *v7; // rbx
size_t v8; // r12
__int64 v9; // r13
void *v10; // rax

v2 = a2;
v3 = (double)*((unsigned __int8 *)sudoku + 12);
if ( v3 < 0.0 )
{
v4 = sqrt(v3);
v2 = a2;
}
else
{
v4 = sqrt(v3);
}
v5 = (int)v4;
*(_DWORD *)(a1 + 12) = 0;
*(_QWORD *)(a1 + 16) = 0LL;
*(_QWORD *)(a1 + 24) = 0LL;
*(_BYTE *)(a1 + 32) = v2 % (int)v4;
*(_BYTE *)(a1 + 33) = v2 / (int)v4;
v6 = malloc(8LL * (int)v4);
*(_QWORD *)(a1 + 40) = v6;
v7 = v6;
if ( !v6 )
goto LABEL_9;
if ( v5 > 0 )
{
v8 = 260LL * v5;
v9 = (__int64)&v6[(unsigned int)(v5 - 1) + 1];
while ( 1 )
{
v10 = malloc(v8);
*v7 = v10;
if ( !v10 )
break;
if ( (_QWORD *)v9 == ++v7 )
return initChoices(a1);
}
LABEL_9:
perror(aProbl);
exit(1);
}
return initChoices(a1);
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, int a2)
{
int v2; // eax
double v3; // xmm0_8
double v4; // xmm0_8
int v5; // er13
_QWORD *v6; // rax
_QWORD *v7; // rbx
size_t v8; // r12
__int64 v9; // r13
void *v10; // rax

v2 = a2;
v3 = (double)*((unsigned __int8 *)sudoku + 12);
if ( v3 < 0.0 )
{
v4 = sqrt(v3);
v2 = a2;
}
else
{
v4 = sqrt(v3);
}
v5 = (int)v4;
*(_DWORD *)(a1 + 12) = 0;
*(_QWORD *)(a1 + 16) = 0LL;
*(_QWORD *)(a1 + 24) = 0LL;
*(_BYTE *)(a1 + 32) = v2 % (int)v4;
*(_BYTE *)(a1 + 33) = v2 / (int)v4;
v6 = malloc(8LL * (int)v4);
*(_QWORD *)(a1 + 40) = v6;
v7 = v6;
if ( !v6 )
goto LABEL_9;
if ( v5 > 0 )
{
v8 = 260LL * v5;
v9 = (__int64)&v6[(unsigned int)(v5 - 1) + 1];
while ( 1 )
{
v10 = malloc(v8);
*v7 = v10;
if ( !v10 )
break;
if ( (_QWORD *)v9 == ++v7 )
return initChoices(a1);
}
LABEL_9:
perror(aProbl);
exit(1);
}
return initChoices(a1);
}

original_code:
void initSubGrid( subGrid* subGrid , int threadNumber )
{
 int widthSubSquare, numberOfBlocks = sudoku->blocksPerSquare;
 widthSubSquare = (int) sqrt( numberOfBlocks );
 subGrid -> x = threadNumber % widthSubSquare;
 subGrid -> y = threadNumber / widthSubSquare;
 subGrid -> successLaunch = 0;
 subGrid -> failLaunch = 0;
 subGrid -> numberLaunch = 0;
 subGrid -> solAtBoot = 0;
 subGrid -> emptyAtBoot = 0;
 if( ( subGrid -> solution = (Solution**) malloc(widthSubSquare * sizeof (Solution*)) ) == ((void *)0))
 {
  perror("Problème de Malloc ");
  exit ( 1 );
 }
 for (int i = 0 ; i < widthSubSquare ; i++)
 {
  if( ( subGrid -> solution[i] = (Solution*) malloc(widthSubSquare * sizeof (Solution)) ) == ((void *)0))
  {
   perror("Problème de Malloc ");
   exit ( 1 );
  }
 }
 initChoices( subGrid );
}

canonical_original_code:
void initSubGrid(struct subGrid *subGrid, int threadNumber)
{
 int widthSubSquare; int numberOfBlocks = sudoku->blocksPerSquare;
 widthSubSquare = (int) sqrt( numberOfBlocks );
 subGrid -> x = threadNumber % widthSubSquare;
 subGrid -> y = threadNumber / widthSubSquare;
 subGrid -> successLaunch = 0;
 subGrid -> failLaunch = 0;
 subGrid -> numberLaunch = 0;
 subGrid -> solAtBoot = 0;
 subGrid -> emptyAtBoot = 0;
 if( ( subGrid -> solution = (struct Solution **) malloc(widthSubSquare * sizeof (struct Solution *)) ) == ((void *)0))
 {
  perror("Problème de Malloc ");
  exit ( 1 );
 }
 for (int i = 0; i < widthSubSquare ; i++)
 {
  if( ( subGrid -> solution[i] = (struct Solution *) malloc(widthSubSquare * sizeof (Solution)) ) == ((void *)0))
  {
   perror("Problème de Malloc ");
   exit ( 1 );
  }
 }
 initChoices( subGrid );
}

variable_types: struct subGrid { unsigned long thread; int emptyBlocks; int solAtBoot; int emptyAtBoot; int numberLaunch; int successLaunch; int failLaunch; unsigned char x; unsigned char y; struct Solution { int N_sol; unsigned char choices[255]; } **solution; } *

variable_types: threadNumber int

variable_types: widthSubSquare int

variable_types: numberOfBlocks int

user_defined_types: struct subGrid { unsigned long thread; int emptyBlocks; int solAtBoot; int emptyAtBoot; int numberLaunch; int successLaunch; int failLaunch; unsigned char x; unsigned char y; struct Solution **solution; }


initResult

decompiled_code:
void *__fastcall initResult(_QWORD *a1)
{
void *result; // rax

result = malloc(3 * *((unsigned __int8 *)sudoku + 12) + 3);
*a1 = result;
if ( !result )
{
perror("Malloc : ");
exit(1);
}
return result;
}

canonical_decompiled_code:
void *__fastcall func2(_QWORD *a1)
{
void *result; // rax

result = malloc(3 * *((unsigned __int8 *)sudoku + 12) + 3);
*a1 = result;
if ( !result )
{
perror("Malloc : ");
exit(1);
}
return result;
}

original_code:
void initResult(unsigned char **result)
{
 if( (*result = malloc((sudoku->blocksPerSquare + 1)*3*sizeof(unsigned char)) ) == ((void *)0))
 {
  perror ( "Malloc : " );
  exit ( 1 );
 }
}

variable_types:
result
unsigned char **


cleanSubGrids

decompiled_code:
void __fastcall cleanSubGrids(__int64 a1)
{
double v2; // xmm0_8
double v3; // xmm0_8
__int64 v4; // rbx
void *v5; // rdi

v2 = (double)*((unsigned __int8 *)sudoku + 12);
if ( v2 < 0.0 )
v3 = sqrt(v2);
else
v3 = sqrt(v2);
if ( (int)v3 )
{
v4 = 0LL;
do
{
v5 = *(void **)(*(_QWORD *)(*(_QWORD *)(a1 + 8) + 40LL) + v4);
v4 += 8LL;
free(v5);
}
while ( 8LL * (int)v3 != v4 );
}
free(*(void **)(*(_QWORD *)(a1 + 8) + 40LL));
}

canonical_decompiled_code:
void __fastcall func3(__int64 a1)
{
double v2; // xmm0_8
double v3; // xmm0_8
__int64 v4; // rbx
void *v5; // rdi

v2 = (double)*((unsigned __int8 *)sudoku + 12);
if ( v2 < 0.0 )
v3 = sqrt(v2);
else
v3 = sqrt(v2);
if ( (int)v3 )
{
v4 = 0LL;
do
{
v5 = *(void **)(*(_QWORD *)(*(_QWORD *)(a1 + 8) + 40LL) + v4);
v4 += 8LL;
free(v5);
}
while ( 8LL * (int)v3 != v4 );
}
free(*(void **)(*(_QWORD *)(a1 + 8) + 40LL));
}

original_code:
void cleanSubGrids( threadParameters* parameters)
{
 int widthSubSquare = sqrt(sudoku->blocksPerSquare);
 for(int i = 0 ; i < widthSubSquare ; i++)
 {
  free(parameters->subGrid->solution[i]);
 }
 free(parameters->subGrid->solution);
 return;
}

canonical_original_code:
void cleanSubGrids(struct threadParameters *parameters)
{
 int widthSubSquare = sqrt(sudoku->blocksPerSquare);
 for(int i = 0; i < widthSubSquare ; i++)
 {
  free(parameters->subGrid->solution[i]);
 }
 free(parameters->subGrid->solution);
 return;
}

variable_types: struct threadParameters { int threadNumber; int numberOfBlocks; struct subGrid { unsigned long thread; int emptyBlocks; int solAtBoot; int emptyAtBoot; int numberLaunch; int successLaunch; int failLaunch; unsigned char x; unsigned char y; struct Solution { int N_sol; unsigned char choices[255]; } **solution; } *subGrid; } *

user_defined_types: struct threadParameters { int threadNumber; int numberOfBlocks; struct subGrid *subGrid; }


launchThreads

decompiled_code:
void __fastcall launchThreads(_QWORD *a1)
{
int v2; // er12
char *v3; // rax
char *v4; // r14
void *v5; // rax
char *v6; // rbx
_DWORD *v7; // r15
__int64 v8; // r13
pthread_t *v9; // rdi
__int64 v10; // r12
__int64 v11; // rdi
__int64 v12; // [rsp+8h] [rbp-40h]

v2 = *((unsigned __int8 *)sudoku + 12);
v12 = (unsigned __int8)v2;
v3 = (char *)malloc(16LL * (unsigned __int8)v2);
if ( !v3 )
{
perror(aProbl_0);
exit(1);
}
v4 = v3;
v5 = malloc(48LL * (unsigned __int8)v2);
*a1 = v5;
if ( !v5 )
{
perror(aErreurDeM);
exit(1);
}
printf("Lancement de %d threads\n", (unsigned int)v2);
pthread_mutex_init((pthread_mutex_t *)((char *)sudoku + 16), 0LL);
if ( v2 )
{
v6 = v4;
v7 = v4;
v8 = 0LL;
do
{
*v7 = v8;
v9 = (pthread_t *)(*a1 + 48 * v8);
v7[1] = v2;
*((_QWORD *)v7 + 1) = v9;
if ( pthread_create(v9, 0LL, (void *(*)(void *))&threadStart, v7) )
{
perror("Erreur dans pthread_create");
exit(1);
}
++v8;
v7 += 4;
}
while ( v2 > (int)v8 );
v10 = 0LL;
do
{
if ( pthread_join(*(_QWORD *)(*a1 + v10), 0LL) )
{
perror("Erreur dans pthread_join");
exit(1);
}
v10 += 48LL;
printStatsThread(v6, 0.0);
v11 = (__int64)v6;
v6 += 16;
cleanSubGrids(v11);
}
while ( v6 != &v4[16 * v12] );
}
free(v4);
}

canonical_decompiled_code:
void __fastcall func4(_QWORD *a1)
{
int v2; // er12
char *v3; // rax
char *v4; // r14
void *v5; // rax
char *v6; // rbx
_DWORD *v7; // r15
__int64 v8; // r13
pthread_t *v9; // rdi
__int64 v10; // r12
__int64 v11; // rdi
__int64 v12; // [rsp+8h] [rbp-40h]

v2 = *((unsigned __int8 *)sudoku + 12);
v12 = (unsigned __int8)v2;
v3 = (char *)malloc(16LL * (unsigned __int8)v2);
if ( !v3 )
{
perror(aProbl_0);
exit(1);
}
v4 = v3;
v5 = malloc(48LL * (unsigned __int8)v2);
*a1 = v5;
if ( !v5 )
{
perror(aErreurDeM);
exit(1);
}
printf("Lancement de %d threads\n", (unsigned int)v2);
pthread_mutex_init((pthread_mutex_t *)((char *)sudoku + 16), 0LL);
if ( v2 )
{
v6 = v4;
v7 = v4;
v8 = 0LL;
do
{
*v7 = v8;
v9 = (pthread_t *)(*a1 + 48 * v8);
v7[1] = v2;
*((_QWORD *)v7 + 1) = v9;
if ( pthread_create(v9, 0LL, (void *(*)(void *))&threadStart, v7) )
{
perror("Erreur dans pthread_create");
exit(1);
}
++v8;
v7 += 4;
}
while ( v2 > (int)v8 );
v10 = 0LL;
do
{
if ( pthread_join(*(_QWORD *)(*a1 + v10), 0LL) )
{
perror("Erreur dans pthread_join");
exit(1);
}
v10 += 48LL;
printStatsThread(v6, 0.0);
v11 = (__int64)v6;
v6 += 16;
func3(v11);
}
while ( v6 != &v4[16 * v12] );
}
free(v4);
}

original_code:
void launchThreads( subGrid** subGridsAdresses )
{
 int blocksPerSquare = sudoku->blocksPerSquare;
 threadParameters *arg;
 arg = malloc ( blocksPerSquare*sizeof(threadParameters) );
 if ( arg == ((void *)0) )
 {
  perror( "Problème de Mémoire (Malloc)" );
  exit ( 1 );
 }
 *subGridsAdresses = malloc( blocksPerSquare * sizeof( subGrid ) );
 if( *subGridsAdresses == ((void *)0) )
 {
  perror( "Erreur de Mémoire (Malloc)" );
  exit( 1 );
 }
 printf ( "Lancement de %d threads\n" , blocksPerSquare );
 pthread_mutex_init (&(sudoku->mutex), ((void *)0));
 for( int i = 0 ; i < blocksPerSquare ; i++ )
 {
  arg[i].threadNumber = i;
  arg[i].numberOfBlocks = blocksPerSquare;
  arg[i].subGrid = &( ( *subGridsAdresses )[i] );
  if ( pthread_create( &( (*subGridsAdresses)[i].thread ) , ((void *)0), threadStart , &(arg[i]) ) != 0 )
        {
                perror( "Erreur dans pthread_create" );
                exit( 1 );
        }
 }
 for( int i = 0 ; i < blocksPerSquare ; i++ )
 {
  if ( pthread_join ( (*subGridsAdresses)[i].thread , ((void *)0) ) != 0 )
        {
                perror ( "Erreur dans pthread_join" );
                exit ( 1 );
        }
        printStatsThread( &(arg[i]), 0);
        cleanSubGrids( &(arg[i]));
 }
 free(arg);
    return;
}

canonical_original_code:
void launchThreads(struct subGrid **subGridsAdresses)
{
 int blocksPerSquare = sudoku->blocksPerSquare;
 struct threadParameters *arg;
 arg = malloc ( blocksPerSquare*sizeof(threadParameters) );
 if ( arg == ((void *)0) )
 {
  perror( "Problème de Mémoire (Malloc)" );
  exit ( 1 );
 }
 *subGridsAdresses = malloc( blocksPerSquare * sizeof( subGrid ) );
 if( *subGridsAdresses == ((void *)0) )
 {
  perror( "Erreur de Mémoire (Malloc)" );
  exit( 1 );
 }
 printf ( "Lancement de %d threads\n" , blocksPerSquare );
 pthread_mutex_init (&(sudoku->mutex), ((void *)0));
 for( int i = 0; i < blocksPerSquare ; i++ )
 {
  arg[i].threadNumber = i;
  arg[i].numberOfBlocks = blocksPerSquare;
  arg[i].subGrid = &( ( *subGridsAdresses )[i] );
  if ( pthread_create( &( (*subGridsAdresses)[i].thread ) , ((void *)0), threadStart , &(arg[i]) ) != 0 )
        {
                perror( "Erreur dans pthread_create" );
                exit( 1 );
        }
 }
 for( int i = 0; i < blocksPerSquare ; i++ )
 {
  if ( pthread_join ( (*subGridsAdresses)[i].thread , ((void *)0) ) != 0 )
        {
                perror ( "Erreur dans pthread_join" );
                exit ( 1 );
        }
        printStatsThread( &(arg[i]), 0);
        cleanSubGrids( &(arg[i]));
 }
 free(arg);
    return;
}

variable_types: struct subGrid { unsigned long thread; int emptyBlocks; int solAtBoot; int emptyAtBoot; int numberLaunch; int successLaunch; int failLaunch; unsigned char x; unsigned char y; struct Solution { int N_sol; unsigned char choices[255]; } **solution; } **

variable_types: blocksPerSquare int


displayUsage

decompiled_code:
void __noreturn displayUsage()
{
fwrite("Usage :\n", 1uLL, 8uLL, stdout);
fwrite(&unk_C0, 1uLL, 0x63uLL, stdout);
fwrite(&unk_128, 1uLL, 0x37uLL, stdout);
fwrite(&unk_160, 1uLL, 0x4FuLL, stdout);
exit(0);
}

canonical_decompiled_code:
void __noreturn func0()
{
fwrite("Usage :\n", 1uLL, 8uLL, stdout);
fwrite(&unk_C0, 1uLL, 0x63uLL, stdout);
fwrite(&unk_128, 1uLL, 0x37uLL, stdout);
fwrite(&unk_160, 1uLL, 0x4FuLL, stdout);
exit(0);
}

original_code:
void displayUsage()
{
 fprintf(stdout , "Usage :\n");
 fprintf(stdout, "\"./exe/sudoku\" / \"make run\" : Default avec \"sudoku.in.txt\" en entrée et sudoku.out.txt en sortie.\n");
 fprintf(stdout, "\"./exe/sudoku [INPUT]\" : Grille d\'entrée spécifiée.\n");
 fprintf(stdout, "\"./exe/sudoku [INPUT] [OUTPUT]\" : Grilles d\'entrée et de sortie spécifiées.\n");
 exit ( 0 );
}


main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
const char **v3; // rbp
bool v5; // cf
bool v6; // zf
struct timeb *v7; // rdi
__int64 v8; // rcx
double v9; // xmm2_8
double v10; // xmm1_8
const char *v11; // rbp
const char *v12; // r14
__int64 v13; // r12
double v14; // [rsp+0h] [rbp-58h]
__int64 v15; // [rsp+10h] [rbp-48h] BYREF
__int64 v16; // [rsp+18h] [rbp-40h] BYREF
struct timeb timebuf; // [rsp+20h] [rbp-38h] BYREF

v3 = argv;
v5 = argc == 0;
v6 = argc == 1;
if ( argc <= 1 )
{
v7 = &timebuf;
ftime(&timebuf);
v9 = *(double *)&LC7;
v16 = 0LL;
v10 = (double)timebuf.millitm / 1000.0 + (double)SLODWORD(timebuf.time);
}
else
{
argv = (const char **)argv[1];
v7 = (struct timeb *)"help";
v8 = 5LL;
do
{
if ( !v8 )
break;
v5 = *(_BYTE *)argv < LOBYTE(v7->time);
v6 = *(_BYTE *)argv == LOBYTE(v7->time);
argv = (const char **)((char *)argv + 1);
v7 = (struct timeb *)((char *)v7 + 1);
--v8;
}
while ( v6 );
if ( (!v5 && !v6) == v5 )
LABEL_9:
displayUsage(v7, argv, envp);
v7 = &timebuf;
ftime(&timebuf);
v9 = *(double *)&LC7;
v16 = 0LL;
v10 = (double)timebuf.millitm / 1000.0 + (double)SLODWORD(timebuf.time);
if ( argc == 2 )
{
v12 = v3[1];
v11 = "example/sudoku.out.txt";
goto LABEL_12;
}
}
if ( argc == 3 )
{
v12 = v3[1];
v11 = v3[2];
}
else
{
if ( argc != 1 )
goto LABEL_9;
v11 = "example/sudoku.out.txt";
v12 = "example/sudoku.in.txt";
}
LABEL_12:
v13 = (unsigned __int8)readDimensions(v12, argv);
createGrid(v13, &v15);
readGrid(v12, v15, (unsigned int)v13);
initSudoku(v15, (unsigned int)v13);
launchThreads(&v16);
writeGrid(v11, v15, (unsigned int)v13);
deleteSudoku(sudoku);
ftime(&timebuf);
v14 = (double)timebuf.millitm / v9 + (double)SLODWORD(timebuf.time) - v10;
printStatsThread(0LL);
printf(format, v14);
exit(0);
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
const char **v3; // rbp
bool v5; // cf
bool v6; // zf
struct timeb *v7; // rdi
__int64 v8; // rcx
double v9; // xmm2_8
double v10; // xmm1_8
const char *v11; // rbp
const char *v12; // r14
__int64 v13; // r12
double v14; // [rsp+0h] [rbp-58h]
__int64 v15; // [rsp+10h] [rbp-48h] BYREF
__int64 v16; // [rsp+18h] [rbp-40h] BYREF
struct timeb timebuf; // [rsp+20h] [rbp-38h] BYREF

v3 = argv;
v5 = argc == 0;
v6 = argc == 1;
if ( argc <= 1 )
{
v7 = &timebuf;
ftime(&timebuf);
v9 = *(double *)&LC7;
v16 = 0LL;
v10 = (double)timebuf.millitm / 1000.0 + (double)SLODWORD(timebuf.time);
}
else
{
argv = (const char **)argv[1];
v7 = (struct timeb *)"help";
v8 = 5LL;
do
{
if ( !v8 )
break;
v5 = *(_BYTE *)argv < LOBYTE(v7->time);
v6 = *(_BYTE *)argv == LOBYTE(v7->time);
argv = (const char **)((char *)argv + 1);
v7 = (struct timeb *)((char *)v7 + 1);
--v8;
}
while ( v6 );
if ( (!v5 && !v6) == v5 )
LABEL_9:
func0(v7, argv, envp);
v7 = &timebuf;
ftime(&timebuf);
v9 = *(double *)&LC7;
v16 = 0LL;
v10 = (double)timebuf.millitm / 1000.0 + (double)SLODWORD(timebuf.time);
if ( argc == 2 )
{
v12 = v3[1];
v11 = "example/sudoku.out.txt";
goto LABEL_12;
}
}
if ( argc == 3 )
{
v12 = v3[1];
v11 = v3[2];
}
else
{
if ( argc != 1 )
goto LABEL_9;
v11 = "example/sudoku.out.txt";
v12 = "example/sudoku.in.txt";
}
LABEL_12:
v13 = (unsigned __int8)readDimensions(v12, argv);
createGrid(v13, &v15);
readGrid(v12, v15, (unsigned int)v13);
initSudoku(v15, (unsigned int)v13);
launchThreads(&v16);
writeGrid(v11, v15, (unsigned int)v13);
deleteSudoku(sudoku);
ftime(&timebuf);
v14 = (double)timebuf.millitm / v9 + (double)SLODWORD(timebuf.time) - v10;
printStatsThread(0LL);
printf(format, v14);
exit(0);
}

original_code:
int main (int argc, char **argv)
{
 if ( ( argc >= 2) && (strcmp ( argv[1] , "help" ) == 0) )
 {
  displayUsage();
  exit ( 0 );
 }
 struct timeb timeTmp;
 ftime(&timeTmp);
 double timeStart, timeEnd;
 double time_spent;
 timeStart = ( (double) timeTmp.time) + ( (double) timeTmp.millitm/1000);
 unsigned char** grid;
 unsigned char blocksPerSquare;
 subGrid* threads = ((void *)0);
 char *filePath = "example/sudoku.in.txt", *resultPath = "example/sudoku.out.txt";
 switch (argc)
 {
  case 1:
   break;
  case 2:
   filePath = argv[1];
   break;
  case 3:
   filePath = argv[1];
   resultPath = argv[2];
   break;
  default:
   displayUsage();
 }
 blocksPerSquare = readDimensions(filePath);
 createGrid(blocksPerSquare, &grid);
 readGrid(filePath, grid, blocksPerSquare);
 initSudoku( grid, blocksPerSquare);
 launchThreads( &threads );
 writeGrid(resultPath, grid, blocksPerSquare);
 deleteSudoku(sudoku);
 ftime(&timeTmp);
 timeEnd = ( (double) timeTmp.time) + ( (double) timeTmp.millitm/1000);
 time_spent = timeEnd - timeStart;
 printStatsThread(((void *)0), time_spent);
 printf("Temps d'Exécution : %0.3f secondes\n" ,time_spent);
 exit( 0 );
}

canonical_original_code:
int main(int argc, char **argv)
{
 if ( ( argc >= 2) && (strcmp ( argv[1] , "help" ) == 0) )
 {
  displayUsage();
  exit ( 0 );
 }
 struct timeb timeTmp;
 ftime(&timeTmp);
 double timeStart; double timeEnd;
 double time_spent;
 timeStart = ( (double) timeTmp.time) + ( (double) timeTmp.millitm/1000);
 unsigned char **grid;
 unsigned char blocksPerSquare;
 struct subGrid *threads = ((void *)0);
 char *filePath = "example/sudoku.in.txt"; char *resultPath = "example/sudoku.out.txt";
 switch (argc)
 {
  case 1:
   break;
  case 2:
   filePath = argv[1];
   break;
  case 3:
   filePath = argv[1];
   resultPath = argv[2];
   break;
  default:
   displayUsage();
 }
 blocksPerSquare = readDimensions(filePath);
 createGrid(blocksPerSquare, &grid);
 readGrid(filePath, grid, blocksPerSquare);
 initSudoku( grid, blocksPerSquare);
 launchThreads( &threads );
 writeGrid(resultPath, grid, blocksPerSquare);
 deleteSudoku(sudoku);
 ftime(&timeTmp);
 timeEnd = ( (double) timeTmp.time) + ( (double) timeTmp.millitm/1000);
 time_spent = timeEnd - timeStart;
 printStatsThread(((void *)0), time_spent);
 printf("Temps d'Exécution : %0.3f secondes\n" ,time_spent);
 exit( 0 );
}

variable_types: argc int

variable_types:
argv
char **

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

variable_types: timeStart double

variable_types: timeEnd double

variable_types:
grid
unsigned char **

variable_types:
blocksPerSquare
unsigned char

variable_types:
filePath
char *

variable_types:
resultPath
char *

user_defined_types: struct Solution { int N_sol; unsigned char choices[255]; }


printGrid

decompiled_code:
int printGrid()
{
__int64 v0; // r12
_QWORD *v1; // rax
unsigned __int8 v2; // dl
__int64 v3; // rbx
__int64 v4; // rsi

v0 = 0LL;
printf("GRID empty:%d\n", *(unsigned int *)(sudoku + 8LL));
v1 = (_QWORD *)sudoku;
v2 = *(_BYTE *)(sudoku + 12LL);
if ( v2 )
{
do
{
v3 = 0LL;
if ( v2 )
{
do
{
v4 = *(unsigned __int8 *)(*(_QWORD *)(*v1 + 8 * v0) + v3++);
printf("%d ", v4);
v1 = (_QWORD *)sudoku;
}
while ( *(unsigned __int8 *)(sudoku + 12LL) > (int)v3 );
}
++v0;
putchar(10);
v1 = (_QWORD *)sudoku;
v2 = *(_BYTE *)(sudoku + 12LL);
}
while ( v2 > (int)v0 );
}
return putchar(10);
}

canonical_decompiled_code:
int func3()
{
__int64 v0; // r12
_QWORD *v1; // rax
unsigned __int8 v2; // dl
__int64 v3; // rbx
__int64 v4; // rsi

v0 = 0LL;
printf("GRID empty:%d\n", *(unsigned int *)(sudoku + 8LL));
v1 = (_QWORD *)sudoku;
v2 = *(_BYTE *)(sudoku + 12LL);
if ( v2 )
{
do
{
v3 = 0LL;
if ( v2 )
{
do
{
v4 = *(unsigned __int8 *)(*(_QWORD *)(*v1 + 8 * v0) + v3++);
printf("%d ", v4);
v1 = (_QWORD *)sudoku;
}
while ( *(unsigned __int8 *)(sudoku + 12LL) > (int)v3 );
}
++v0;
putchar(10);
v1 = (_QWORD *)sudoku;
v2 = *(_BYTE *)(sudoku + 12LL);
}
while ( v2 > (int)v0 );
}
return putchar(10);
}

original_code:
void printGrid()
{
 printf("GRID empty:%d\n", sudoku->emptyBlocks);
 for( int i = 0 ; i < sudoku->blocksPerSquare ; i++)
 {
  for( int j = 0 ; j < sudoku->blocksPerSquare ; j++)
  {
   printf("%d ",sudoku->grid[i][j]);
  }
  printf("\n");
 }
 printf("\n");
 return;
}

canonical_original_code:
void printGrid()
{
 printf("GRID empty:%d\n", sudoku->emptyBlocks);
 for( int i = 0; i < sudoku->blocksPerSquare ; i++)
 {
  for( int j = 0; j < sudoku->blocksPerSquare ; j++)
  {
   printf("%d ",sudoku->grid[i][j]);
  }
  printf("\n");
 }
 printf("\n");
 return;
}

variable_types: i int

variable_types: j int


randomize

repo: wrstone/super-startrek

decompiled_code:
void randomize()
{
unsigned int v0; // eax

v0 = time(0LL);
srand(v0);
}

canonical_decompiled_code:
void func0()
{
unsigned int v0; // eax

v0 = time(0LL);
srand(v0);
}

original_code:
void randomize(void) {
 srand((int)time(((void *)0)));
}

canonical_original_code:
void randomize() {
 srand((int)time(((void *)0)));
}


max

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

result = a2;
if ( (int)a1 >= (int)a2 )
result = a1;
return result;
}

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

result = a2;
if ( (int)a1 >= (int)a2 )
result = a1;
return result;
}

original_code:
int max(int a, int b) {
 if (a > b) return a;
 return b;
}

variable_types: a int

variable_types: b int


min

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

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

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

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

original_code:
int min(int a, int b) {
 if (a < b) return a;
 return b;
}


getch

decompiled_code:
__int64 getch()
{
__m128i v0; // xmm1
__m128i v1; // xmm2
char buf; // [rsp+Fh] [rbp-89h] BYREF
struct termios termios_p; // [rsp+10h] [rbp-88h] BYREF
struct termios v5; // [rsp+50h] [rbp-48h] BYREF

fflush(stdout);
tcgetattr(0, &termios_p);
v0 = _mm_loadu_si128((const __m128i *)&termios_p.c_line);
v1 = _mm_loadu_si128((const __m128i *)&termios_p.c_cc[15]);
*(__m128i *)&v5.c_iflag = _mm_loadu_si128((const __m128i *)&termios_p);
*(_QWORD *)&v5.c_cc[31] = *(_QWORD *)&termios_p.c_cc[31];
*(__m128i *)&v5.c_line = v0;
*(__m128i *)&v5.c_cc[15] = v1;
v5.c_lflag &= 0xFFFFFFF5;
v5.c_ospeed = termios_p.c_ospeed;
tcsetattr(0, 0, &v5);
read(0, &buf, 1uLL);
tcsetattr(0, 0, &termios_p);
return (unsigned int)buf;
}

canonical_decompiled_code:
__int64 func3()
{
__m128i v0; // xmm1
__m128i v1; // xmm2
char buf; // [rsp+Fh] [rbp-89h] BYREF
struct termios termios_p; // [rsp+10h] [rbp-88h] BYREF
struct termios v5; // [rsp+50h] [rbp-48h] BYREF

fflush(stdout);
tcgetattr(0, &termios_p);
v0 = _mm_loadu_si128((const __m128i *)&termios_p.c_line);
v1 = _mm_loadu_si128((const __m128i *)&termios_p.c_cc[15]);
*(__m128i *)&v5.c_iflag = _mm_loadu_si128((const __m128i *)&termios_p);
*(_QWORD *)&v5.c_cc[31] = *(_QWORD *)&termios_p.c_cc[31];
*(__m128i *)&v5.c_line = v0;
*(__m128i *)&v5.c_cc[15] = v1;
v5.c_lflag &= 0xFFFFFFF5;
v5.c_ospeed = termios_p.c_ospeed;
tcsetattr(0, 0, &v5);
read(0, &buf, 1uLL);
tcsetattr(0, 0, &termios_p);
return (unsigned int)buf;
}

original_code:
int
getch
(void) {
 char chbuf[1];
    struct termios oldstate, newstate;
    fflush(stdout);
 tcgetattr(0, &oldstate);
 newstate = oldstate;
 newstate.c_lflag &= ~0000002;
 newstate.c_lflag &= ~0000010;
 tcsetattr(0, 0, &newstate);
 read(0, &chbuf, 1);
 tcsetattr(0, 0, &oldstate);
        return chbuf[0];
}

canonical_original_code:
int getch() {
 char chbuf[1];
    struct termios oldstate; struct termios newstate;
    fflush(stdout);
 tcgetattr(0, &oldstate);
 newstate = oldstate;
 newstate.c_lflag &= ~0000002;
 newstate.c_lflag &= ~0000010;
 tcsetattr(0, 0, &newstate);
 read(0, &chbuf, 1);
 tcsetattr(0, 0, &oldstate);
        return chbuf[0];
}

variable_types:
chbuf
char [1]

variable_types: struct termios { unsigned int c_iflag; unsigned int c_oflag; unsigned int c_cflag; unsigned int c_lflag; unsigned char c_line; unsigned char c_cc[32]; unsigned int c_ispeed; unsigned int c_ospeed; }


consumeTime

decompiled_code:
_BOOL8 consumeTime()
{
_BOOL8 result; // rax

a[21] = 1;
events();
result = 1LL;
if ( !a[25] && d[9 * a[8] + 8 + a[9]] != 1000 )
result = a[24] != 0;
return result;
}

original_code:
static int consumeTime(void) {
 a.ididit = 1;
 events();
 if (a.alldone || d.galaxy[a.quadx][a.quady] == 1000 || a.justin != 0) return 1;
 return 0;
}

canonical_original_code:
static int consumeTime() {
 a.ididit = 1;
 events();
 if (a.alldone || d.galaxy[a.quadx][a.quady] == 1000 || a.justin != 0) return 1;
 return 0;
}


preport

decompiled_code:
__int64 preport()
{
__int64 result; // rax
unsigned __int64 v1; // rbx
int v2; // ebp
int v3; // er12

skip(1LL);
chew();
prout("Spock- \"Planet report follows, Captain.\"");
result = skip(1LL);
if ( a[35] <= 0 )
return prout("No information available.");
v1 = (unsigned int)((_DWORD)d + 864);
v2 = 1;
v3 = 0;
do
{
while ( 1 )
{
if ( *(_DWORD *)(v1 + 16) )
{
cramlc(1LL, *(unsigned int *)v1, *(unsigned int *)(v1 + 4));
proutn(" class ");
proutn((char *)&classes + 2 * *(int *)(v1 + 8));
proutn(" ");
if ( !*(_DWORD *)(v1 + 12) )
proutn("no ");
v3 = 1;
result = prout("dilithium crystals present.");
if ( *(_DWORD *)(v1 + 16) == 2 )
break;
}
++v2;
v1 += 20LL;
if ( a[35] < v2 )
goto LABEL_9;
}
++v2;
v1 += 20LL;
result = prout(" Shuttle Craft Galileo on surface.");
}
while ( a[35] >= v2 );
LABEL_9:
if ( !v3 )
return prout("No information available.");
return result;
}

canonical_decompiled_code:
__int64 func1()
{
__int64 result; // rax
unsigned __int64 v1; // rbx
int v2; // ebp
int v3; // er12

skip(1LL);
chew();
prout("Spock- \"Planet report follows, Captain.\"");
result = skip(1LL);
if ( a[35] <= 0 )
return prout("No information available.");
v1 = (unsigned int)((_DWORD)d + 864);
v2 = 1;
v3 = 0;
do
{
while ( 1 )
{
if ( *(_DWORD *)(v1 + 16) )
{
cramlc(1LL, *(unsigned int *)v1, *(unsigned int *)(v1 + 4));
proutn(" class ");
proutn((char *)&classes + 2 * *(int *)(v1 + 8));
proutn(" ");
if ( !*(_DWORD *)(v1 + 12) )
proutn("no ");
v3 = 1;
result = prout("dilithium crystals present.");
if ( *(_DWORD *)(v1 + 16) == 2 )
break;
}
++v2;
v1 += 20LL;
if ( a[35] < v2 )
goto LABEL_9;
}
++v2;
v1 += 20LL;
result = prout(" Shuttle Craft Galileo on surface.");
}
while ( a[35] >= v2 );
LABEL_9:
if ( !v3 )
return prout("No information available.");
return result;
}

original_code:
void preport(void) {
 int iknow = 0, i;
 skip(1);
 chew();
 prout("Spock-  \"Planet report follows, Captain.\"");
 skip(1);
 for (i = 1; i <= a.inplan; i++) {
  if (d.plnets[i].known
   ) {
   iknow = 1;
   cramlc(1, d.plnets[i].x, d.plnets[i].y);
   proutn("   class ");
   proutn(classes[d.plnets[i].pclass]);
   proutn("   ");
   if (d.plnets[i].crystals == 0) proutn("no ");
   prout("dilithium crystals present.");
   if (d.plnets[i].known==2)
    prout("    Shuttle Craft Galileo on surface.");
  }
 }
 if (iknow==0) prout("No information available.");
}

canonical_original_code:
void preport() {
 int iknow = 0; int i;
 skip(1);
 chew();
 prout("Spock-  \"Planet report follows, Captain.\"");
 skip(1);
 for (i = 1; i <= a.inplan; i++) {
  if (d.plnets[i].known
   ) {
   iknow = 1;
   cramlc(1, d.plnets[i].x, d.plnets[i].y);
   proutn("   class ");
   proutn(classes[d.plnets[i].pclass]);
   proutn("   ");
   if (d.plnets[i].crystals == 0) proutn("no ");
   prout("dilithium crystals present.");
   if (d.plnets[i].known==2)
    prout("    Shuttle Craft Galileo on surface.");
  }
 }
 if (iknow==0) prout("No information available.");
}

variable_types: iknow int


orbit

decompiled_code:
__int64 orbit()
{
int v0; // eax
int v1; // edx
__int64 result; // rax

skip(1LL);
chew();
v0 = a[31];
a[21] = 0;
if ( v0 )
return prout("Already in standard orbit.");
if ( damage[6] != 0.0 && damage[7] != 0.0 )
return prout("Both warp and impulse engines damaged.");
v1 = a[29];
if ( v1 && (int)abs32(a[10] - v1) <= 1 && (int)abs32(a[11] - a[30]) <= 1 )
{
*(double *)&a[94] = Rand() * 0.03 + 0.02;
prout("Helmsman Sulu- \"Entering standard orbit, Sir.\"");
newcnd();
result = consumeTime();
if ( !(_DWORD)result )
{
proutn("Sulu- \"Entered orbit at altitude ");
height = (int)(Rand() * 7200.0 + 1400.0);
cramf(0LL, 2LL, (double)height);
result = prout(" kilometers.\"");
a[31] = 1;
}
}
else
{
crmshp();
result = prout(" not adjacent to planet.\n");
}
return result;
}

canonical_decompiled_code:
__int64 func2()
{
int v0; // eax
int v1; // edx
__int64 result; // rax

skip(1LL);
chew();
v0 = a[31];
a[21] = 0;
if ( v0 )
return prout("Already in standard orbit.");
if ( damage[6] != 0.0 && damage[7] != 0.0 )
return prout("Both warp and impulse engines damaged.");
v1 = a[29];
if ( v1 && (int)abs32(a[10] - v1) <= 1 && (int)abs32(a[11] - a[30]) <= 1 )
{
*(double *)&a[94] = Rand() * 0.03 + 0.02;
prout("Helmsman Sulu- \"Entering standard orbit, Sir.\"");
newcnd();
result = func0();
if ( !(_DWORD)result )
{
proutn("Sulu- \"Entered orbit at altitude ");
height = (int)(Rand() * 7200.0 + 1400.0);
cramf(0LL, 2LL, (double)height);
result = prout(" kilometers.\"");
a[31] = 1;
}
}
else
{
crmshp();
result = prout(" not adjacent to planet.\n");
}
return result;
}

original_code:
void orbit(void) {
 double asave;
 skip(1);
 chew();
 a.ididit=0;
 if (a.inorbit!=0) {
  prout("Already in standard orbit.");
  return;
 }
 if (damage[6] != 0 && damage[7] != 0) {
  prout("Both warp and impulse engines damaged.");
  return;
 }
 if (a.plnetx == 0 || abs(a.sectx-a.plnetx) > 1 || abs(a.secty-a.plnety) > 1) {
  crmshp();
  prout(" not adjacent to planet.\n");
  return;
 }
 a.Time = 0.02+0.03*Rand();
 prout("Helmsman Sulu-  \"Entering standard orbit, Sir.\"");
 newcnd();
 if (consumeTime()) return;
 proutn("Sulu-  \"Entered orbit at altitude ");
 cramf(height = (1400.+7200.*Rand()), 0, 2);
 prout(" kilometers.\"");
 a.inorbit = 1;
 return;
}

canonical_original_code:
void orbit() {
 double asave;
 skip(1);
 chew();
 a.ididit=0;
 if (a.inorbit!=0) {
  prout("Already in standard orbit.");
  return;
 }
 if (damage[6] != 0 && damage[7] != 0) {
  prout("Both warp and impulse engines damaged.");
  return;
 }
 if (a.plnetx == 0 || abs(a.sectx-a.plnetx) > 1 || abs(a.secty-a.plnety) > 1) {
  crmshp();
  prout(" not adjacent to planet.\n");
  return;
 }
 a.Time = 0.02+0.03*Rand();
 prout("Helmsman Sulu-  \"Entering standard orbit, Sir.\"");
 newcnd();
 if (consumeTime()) return;
 proutn("Sulu-  \"Entered orbit at altitude ");
 cramf(height = (1400.+7200.*Rand()), 0, 2);
 prout(" kilometers.\"");
 a.inorbit = 1;
 return;
}

variable_types: asave double


sensor

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

skip(1LL);
chew();
if ( damage[1] != 0.0 )
return (_DWORD *)prout("Short range sensors damaged.");
if ( !a[29] )
return (_DWORD *)prout("No planet in this quadrant.");
proutn("Spock- \"Sensor scan for");
cramlc(1LL, (unsigned int)a[8], (unsigned int)a[9]);
prout("-");
skip(1LL);
proutn(" Planet at");
cramlc(2LL, (unsigned int)a[29], (unsigned int)a[30]);
proutn(" is of class ");
proutn((char *)&classes + 2 * d[5 * a[33] + 213]);
prout(".");
if ( d[5 * a[33] + 215] == 2 )
prout(" Sensors show Galileo still on surface.");
proutn(" Readings indicate");
if ( !d[5 * a[33] + 214] )
proutn(" no");
prout(" dilithium crystals present.\"");
result = &d[5 * a[33]];
if ( !result[215] )
result[215] = 1;
return result;
}

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

skip(1LL);
chew();
if ( damage[1] != 0.0 )
return (_DWORD *)prout("Short range sensors damaged.");
if ( !a[29] )
return (_DWORD *)prout("No planet in this quadrant.");
proutn("Spock- \"Sensor scan for");
cramlc(1LL, (unsigned int)a[8], (unsigned int)a[9]);
prout("-");
skip(1LL);
proutn(" Planet at");
cramlc(2LL, (unsigned int)a[29], (unsigned int)a[30]);
proutn(" is of class ");
proutn((char *)&classes + 2 * d[5 * a[33] + 213]);
prout(".");
if ( d[5 * a[33] + 215] == 2 )
prout(" Sensors show Galileo still on surface.");
proutn(" Readings indicate");
if ( !d[5 * a[33] + 214] )
proutn(" no");
prout(" dilithium crystals present.\"");
result = &d[5 * a[33]];
if ( !result[215] )
result[215] = 1;
return result;
}

original_code:
void sensor(void) {
 skip(1);
 chew();
 if (damage[1] != 0.0) {
  prout("Short range sensors damaged.");
  return;
 }
 if (a.plnetx == 0) {
  prout("No planet in this quadrant.");
  return;
 }
 proutn("Spock-  \"Sensor scan for");
 cramlc(1, a.quadx, a.quady);
 prout("-");
 skip(1);
 proutn("         Planet at");
 cramlc(2, a.plnetx, a.plnety);
 proutn(" is of class ");
 proutn(classes[d.plnets[a.iplnet].pclass]);
 prout(".");
 if (d.plnets[a.iplnet].known==2)
  prout("         Sensors show Galileo still on surface.");
 proutn("         Readings indicate");
 if (d.plnets[a.iplnet].crystals == 0) proutn(" no");
 prout(" dilithium crystals present.\"");
 if (d.plnets[a.iplnet].known == 0) d.plnets[a.iplnet].known = 1;
 return;
}

canonical_original_code:
void sensor() {
 skip(1);
 chew();
 if (damage[1] != 0.0) {
  prout("Short range sensors damaged.");
  return;
 }
 if (a.plnetx == 0) {
  prout("No planet in this quadrant.");
  return;
 }
 proutn("Spock-  \"Sensor scan for");
 cramlc(1, a.quadx, a.quady);
 prout("-");
 skip(1);
 proutn("         Planet at");
 cramlc(2, a.plnetx, a.plnety);
 proutn(" is of class ");
 proutn(classes[d.plnets[a.iplnet].pclass]);
 prout(".");
 if (d.plnets[a.iplnet].known==2)
  prout("         Sensors show Galileo still on surface.");
 proutn("         Readings indicate");
 if (d.plnets[a.iplnet].crystals == 0) proutn(" no");
 prout(" dilithium crystals present.\"");
 if (d.plnets[a.iplnet].known == 0) d.plnets[a.iplnet].known = 1;
 return;
}


mine

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

a[21] = 0;
skip(1LL);
chew();
if ( a[32] != 1 )
return prout("Mining party not on planet.");
if ( !d[5 * a[33] + 214] )
return prout("No dilithium crystals on this planet.");
if ( a[34] == 1 )
return prout("You've already mined enough crystals for this trip.");
if ( a[51] == 1 && 0.05 == *(double *)&a[104] )
{
proutn("With all those fresh crystals aboard the ");
crmshp();
skip(1LL);
result = prout("there's no reason to mine more at this time.");
}
else
{
*(double *)&a[94] = (Rand() * 0.2 + 0.1) * (double)(int)d[5 * a[33] + 213];
result = consumeTime();
if ( !(_DWORD)result )
{
result = prout("Mining operation complete.");
a[34] = 1;
}
}
return result;
}

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

a[21] = 0;
skip(1LL);
chew();
if ( a[32] != 1 )
return prout("Mining party not on planet.");
if ( !d[5 * a[33] + 214] )
return prout("No dilithium crystals on this planet.");
if ( a[34] == 1 )
return prout("You've already mined enough crystals for this trip.");
if ( a[51] == 1 && 0.05 == *(double *)&a[104] )
{
proutn("With all those fresh crystals aboard the ");
crmshp();
skip(1LL);
result = prout("there's no reason to mine more at this time.");
}
else
{
*(double *)&a[94] = (Rand() * 0.2 + 0.1) * (double)(int)d[5 * a[33] + 213];
result = func0();
if ( !(_DWORD)result )
{
result = prout("Mining operation complete.");
a[34] = 1;
}
}
return result;
}

original_code:
void mine(void) {
 a.ididit = 0;
 skip(1);
 chew();
 if (a.landed!= 1) {
  prout("Mining party not on planet.");
  return;
 }
 if (d.plnets[a.iplnet].crystals == 0) {
  prout("No dilithium crystals on this planet.");
  return;
 }
 if (a.imine == 1) {
  prout("You've already mined enough crystals for this trip.");
  return;
 }
 if (a.icrystl == 1 && a.cryprob == 0.05) {
  proutn("With all those fresh crystals aboard the ");
  crmshp();
  skip(1);
  prout("there's no reason to mine more at this time.");
  return;
 }
 a.Time = (0.1+0.2*Rand())*d.plnets[a.iplnet].pclass;
 if (consumeTime()) return;
 prout("Mining operation complete.");
 a.imine = 1;
 return;
}

canonical_original_code:
void mine() {
 a.ididit = 0;
 skip(1);
 chew();
 if (a.landed!= 1) {
  prout("Mining party not on planet.");
  return;
 }
 if (d.plnets[a.iplnet].crystals == 0) {
  prout("No dilithium crystals on this planet.");
  return;
 }
 if (a.imine == 1) {
  prout("You've already mined enough crystals for this trip.");
  return;
 }
 if (a.icrystl == 1 && a.cryprob == 0.05) {
  proutn("With all those fresh crystals aboard the ");
  crmshp();
  skip(1);
  prout("there's no reason to mine more at this time.");
  return;
 }
 a.Time = (0.1+0.2*Rand())*d.plnets[a.iplnet].pclass;
 if (consumeTime()) return;
 prout("Mining operation complete.");
 a.imine = 1;
 return;
}


usecrystals

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

skip(1LL);
chew();
if ( a[51] != 1 )
return prout("No dilithium crystals available.");
if ( *(double *)&a[78] >= 1000.0 )
{
prout("Spock- \"Captain, Starfleet Regulations prohibit such an operation");
result = prout(" except when condition Yellow exists.");
}
else
{
prout("Spock- \"Captain, I must warn you that loading");
prout(" raw dilithium crystals into the ship's power");
prout(" system may risk a severe explosion.");
proutn(" Are you sure this is wise?\" ");
if ( (unsigned int)ja() )
{
skip(1LL);
prout("Engineering Officer Scott- \"(GULP) Aye Sir.");
prout(" Mr. Spock and I will try it.\"");
skip(1LL);
prout("Spock- \"Crystals in place, Sir.");
prout(" Ready to activate circuit.\"");
skip(1LL);
prouts("Scotty- \"Keep your fingers crossed, Sir!\"");
skip(1LL);
if ( *(double *)&a[104] >= Rand() )
{
prouts(" \"Activating now! - - No good! It's***");
skip(2LL);
prouts("***RED ALERT! RED A*L********************************");
skip(1LL);
stars();
prouts("****************** KA-BOOM!!!! *******************");
skip(1LL);
result = kaboom();
}
else
{
*(double *)&a[78] = (Rand() * 0.9 + 1.0) * 5000.0 + *(double *)&a[78];
prouts(" \"Activating now! - - ");
prout("The instruments");
prout(" are going crazy, but I think it's");
result = prout(" going to work!! Congratulations, Sir!\"");
*(double *)&a[104] = *(double *)&a[104] + *(double *)&a[104];
}
}
else
{
result = chew();
}
}
return result;
}

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

skip(1LL);
chew();
if ( a[51] != 1 )
return prout("No dilithium crystals available.");
if ( *(double *)&a[78] >= 1000.0 )
{
prout("Spock- \"Captain, Starfleet Regulations prohibit such an operation");
result = prout(" except when condition Yellow exists.");
}
else
{
prout("Spock- \"Captain, I must warn you that loading");
prout(" raw dilithium crystals into the ship's power");
prout(" system may risk a severe explosion.");
proutn(" Are you sure this is wise?\" ");
if ( (unsigned int)ja() )
{
skip(1LL);
prout("Engineering Officer Scott- \"(GULP) Aye Sir.");
prout(" Mr. Spock and I will try it.\"");
skip(1LL);
prout("Spock- \"Crystals in place, Sir.");
prout(" Ready to activate circuit.\"");
skip(1LL);
prouts("Scotty- \"Keep your fingers crossed, Sir!\"");
skip(1LL);
if ( *(double *)&a[104] >= Rand() )
{
prouts(" \"Activating now! - - No good! It's***");
skip(2LL);
prouts("***RED ALERT! RED A*L********************************");
skip(1LL);
stars();
prouts("****************** KA-BOOM!!!! *******************");
skip(1LL);
result = kaboom();
}
else
{
*(double *)&a[78] = (Rand() * 0.9 + 1.0) * 5000.0 + *(double *)&a[78];
prouts(" \"Activating now! - - ");
prout("The instruments");
prout(" are going crazy, but I think it's");
result = prout(" going to work!! Congratulations, Sir!\"");
*(double *)&a[104] = *(double *)&a[104] + *(double *)&a[104];
}
}
else
{
result = chew();
}
}
return result;
}

original_code:
void usecrystals(void) {
 skip(1);
 chew();
 if (a.icrystl!=1) {
  prout("No dilithium crystals available.");
  return;
 }
 if (a.energy >= 1000) {
  prout("Spock-  \"Captain, Starfleet Regulations prohibit such an operation");
  prout("  except when condition Yellow exists.");
  return;
 }
 prout("Spock- \"Captain, I must warn you that loading");
 prout("  raw dilithium crystals into the ship's power");
 prout("  system may risk a severe explosion.");
 proutn("  Are you sure this is wise?\" ");
 if (ja()==0) {
  chew();
  return;
 }
 skip(1);
 prout("Engineering Officer Scott-  \"(GULP) Aye Sir.");
 prout("  Mr. Spock and I will try it.\"");
 skip(1);
 prout("Spock-  \"Crystals in place, Sir.");
 prout("  Ready to activate circuit.\"");
 skip(1);
 prouts("Scotty-  \"Keep your fingers crossed, Sir!\"");
 skip(1);
 if (Rand() <= a.cryprob) {
  prouts("  \"Activating now! - - No good!  It's***");
  skip(2);
  prouts("***RED ALERT!  RED A*L********************************");
  skip(1);
  stars();
  prouts("******************   KA-BOOM!!!!   *******************");
  skip(1);
  kaboom();
  return;
 }
 a.energy += 5000.0*(1.0 + 0.9*Rand());
 prouts("  \"Activating now! - - ");
 prout("The instruments");
 prout("   are going crazy, but I think it's");
 prout("   going to work!!  Congratulations, Sir!\"");
 a.cryprob *= 2.0;
 return;
}

canonical_original_code:
void usecrystals() {
 skip(1);
 chew();
 if (a.icrystl!=1) {
  prout("No dilithium crystals available.");
  return;
 }
 if (a.energy >= 1000) {
  prout("Spock-  \"Captain, Starfleet Regulations prohibit such an operation");
  prout("  except when condition Yellow exists.");
  return;
 }
 prout("Spock- \"Captain, I must warn you that loading");
 prout("  raw dilithium crystals into the ship's power");
 prout("  system may risk a severe explosion.");
 proutn("  Are you sure this is wise?\" ");
 if (ja()==0) {
  chew();
  return;
 }
 skip(1);
 prout("Engineering Officer Scott-  \"(GULP) Aye Sir.");
 prout("  Mr. Spock and I will try it.\"");
 skip(1);
 prout("Spock-  \"Crystals in place, Sir.");
 prout("  Ready to activate circuit.\"");
 skip(1);
 prouts("Scotty-  \"Keep your fingers crossed, Sir!\"");
 skip(1);
 if (Rand() <= a.cryprob) {
  prouts("  \"Activating now! - - No good!  It's***");
  skip(2);
  prouts("***RED ALERT!  RED A*L********************************");
  skip(1);
  stars();
  prouts("******************   KA-BOOM!!!!   *******************");
  skip(1);
  kaboom();
  return;
 }
 a.energy += 5000.0*(1.0 + 0.9*Rand());
 prouts("  \"Activating now! - - ");
 prout("The instruments");
 prout("   are going crazy, but I think it's");
 prout("   going to work!!  Congratulations, Sir!\"");
 a.cryprob *= 2.0;
 return;
}


shuttle

decompiled_code:
__int64 shuttle()
{
double v0; // xmm0_8
int v1; // eax
double v2; // xmm2_8
double v3; // xmm0_8
__int64 result; // rax
__int64 v5; // rax
int v6; // eax
__int64 v7; // rax

chew();
skip(1LL);
v0 = damage[10];
a[21] = 0;
if ( v0 == 0.0 )
{
if ( !a[31] )
{
crmshp();
return prout(" not in standard orbit.");
}
v1 = d[5 * a[33] + 215];
if ( v1 == 2 )
{
if ( a[32] == -1 )
return prout("You will have to beam down to retrieve the shuttle craft.");
}
else if ( a[42] != 1 )
{
return prout("Shuttle craft not currently available.");
}
if ( *(double *)&a[82] != 0.0 || a[5] == 68 )
return prout("Shuttle craft cannot pass through shields.");
if ( !v1 )
{
prout("Spock- \"Captain, we have no information on this planet");
prout(" and Starfleet Regulations clearly state that in this situation");
return prout(" you may not fly down.\"");
}
v2 = 0.8 * *(double *)&d[272];
v3 = (double)height * 0.00003;
*(double *)&a[94] = v3;
if ( v3 >= v2 )
{
prout("First Officer Spock- \"Captain, I compute that such");
prout(" a maneuver would require approximately ");
v3 = 100.0 * *(double *)&a[94] / *(double *)&d[272];
cramf(0LL, 4LL, v3);
prout("% of our", 4LL);
prout("remaining time.");
prout("Are you sure this is wise?\" ");
result = ja();
if ( !(_DWORD)result )
{
*(_QWORD *)&a[94] = 0LL;
return result;
}
}
if ( a[32] == 1 )
{
if ( a[42] == 1 )
{
if ( damage[12] == 0.0 )
{
proutn("Spock- \"Would you rather use the transporter?\" ");
if ( (unsigned int)ja() )
return beam();
proutn("Shuttle crew");
}
else
{
proutn("Rescue party");
}
prout(" boards Galileo and swoops toward planet surface.");
a[42] = 0;
skip(1LL);
result = consumeTime();
if ( !(_DWORD)result )
{
d[5 * a[33] + 215] = 2;
result = prout("Trip complete.");
}
}
else
{
prout("You and your mining party board the", v3, 0.0);
prout("shuttle craft for the trip back to the Enterprise.");
skip(1LL);
prout("The short hop begins . . .");
v5 = a[33];
a[40] = 1;
d[5 * v5 + 215] = 1;
skip(1LL);
a[32] = -1;
result = consumeTime();
if ( !(_DWORD)result )
{
a[42] = 1;
v6 = a[34];
a[40] = 0;
if ( v6 )
{
a[51] = 1;
*(_QWORD *)&a[104] = LC32;
}
a[34] = 0;
result = prout("Trip complete.");
}
}
}
else
{
prout("Mining party assembles in the hangar deck,");
prout("ready to board the shuttle craft \"Galileo\".");
skip(1LL);
prouts("The hangar doors open; the trip begins.");
skip(1LL);
a[40] = 1;
a[42] = 0;
result = consumeTime();
if ( !(_DWORD)result )
{
v7 = a[33];
a[32] = 1;
a[40] = 0;
d[5 * v7 + 215] = 2;
result = prout("Trip complete", v3, 0.0);
}
}
}
else if ( v0 == -1.0 )
{
if ( a[31] && d[5 * a[33] + 215] == 2 )
result = prout("Ye Faerie Queene has no shuttle craft bay to dock it at.");
else
result = prout("Ye Faerie Queene had no shuttle craft.");
}
else if ( v0 <= 0.0 )
{
result = prout("Shuttle craft is now serving Big Mac's.");
}
else
{
result = prout("The Galileo is damaged.");
}
return result;
}

canonical_decompiled_code:
__int64 func6()
{
double v0; // xmm0_8
int v1; // eax
double v2; // xmm2_8
double v3; // xmm0_8
__int64 result; // rax
__int64 v5; // rax
int v6; // eax
__int64 v7; // rax

chew();
skip(1LL);
v0 = damage[10];
a[21] = 0;
if ( v0 == 0.0 )
{
if ( !a[31] )
{
crmshp();
return prout(" not in standard orbit.");
}
v1 = d[5 * a[33] + 215];
if ( v1 == 2 )
{
if ( a[32] == -1 )
return prout("You will have to beam down to retrieve the shuttle craft.");
}
else if ( a[42] != 1 )
{
return prout("Shuttle craft not currently available.");
}
if ( *(double *)&a[82] != 0.0 || a[5] == 68 )
return prout("Shuttle craft cannot pass through shields.");
if ( !v1 )
{
prout("Spock- \"Captain, we have no information on this planet");
prout(" and Starfleet Regulations clearly state that in this situation");
return prout(" you may not fly down.\"");
}
v2 = 0.8 * *(double *)&d[272];
v3 = (double)height * 0.00003;
*(double *)&a[94] = v3;
if ( v3 >= v2 )
{
prout("First Officer Spock- \"Captain, I compute that such");
prout(" a maneuver would require approximately ");
v3 = 100.0 * *(double *)&a[94] / *(double *)&d[272];
cramf(0LL, 4LL, v3);
prout("% of our", 4LL);
prout("remaining time.");
prout("Are you sure this is wise?\" ");
result = ja();
if ( !(_DWORD)result )
{
*(_QWORD *)&a[94] = 0LL;
return result;
}
}
if ( a[32] == 1 )
{
if ( a[42] == 1 )
{
if ( damage[12] == 0.0 )
{
proutn("Spock- \"Would you rather use the transporter?\" ");
if ( (unsigned int)ja() )
return func7();
proutn("Shuttle crew");
}
else
{
proutn("Rescue party");
}
prout(" boards Galileo and swoops toward planet surface.");
a[42] = 0;
skip(1LL);
result = func0();
if ( !(_DWORD)result )
{
d[5 * a[33] + 215] = 2;
result = prout("Trip complete.");
}
}
else
{
prout("You and your mining party board the", v3, 0.0);
prout("shuttle craft for the trip back to the Enterprise.");
skip(1LL);
prout("The short hop begins . . .");
v5 = a[33];
a[40] = 1;
d[5 * v5 + 215] = 1;
skip(1LL);
a[32] = -1;
result = func0();
if ( !(_DWORD)result )
{
a[42] = 1;
v6 = a[34];
a[40] = 0;
if ( v6 )
{
a[51] = 1;
*(_QWORD *)&a[104] = LC32;
}
a[34] = 0;
result = prout("Trip complete.");
}
}
}
else
{
prout("Mining party assembles in the hangar deck,");
prout("ready to board the shuttle craft \"Galileo\".");
skip(1LL);
prouts("The hangar doors open; the trip begins.");
skip(1LL);
a[40] = 1;
a[42] = 0;
result = func0();
if ( !(_DWORD)result )
{
v7 = a[33];
a[32] = 1;
a[40] = 0;
d[5 * v7 + 215] = 2;
result = prout("Trip complete", v3, 0.0);
}
}
}
else if ( v0 == -1.0 )
{
if ( a[31] && d[5 * a[33] + 215] == 2 )
result = prout("Ye Faerie Queene has no shuttle craft bay to dock it at.");
else
result = prout("Ye Faerie Queene had no shuttle craft.");
}
else if ( v0 <= 0.0 )
{
result = prout("Shuttle craft is now serving Big Mac's.");
}
else
{
result = prout("The Galileo is damaged.");
}
return result;
}

original_code:
void shuttle(void) {
 chew();
 skip(1);
 a.ididit = 0;
 if(damage[10] != 0.0) {
  if (damage[10] == -1.0) {
   if (a.inorbit && d.plnets[a.iplnet].known == 2)
    prout("Ye Faerie Queene has no shuttle craft bay to dock it at.");
   else
    prout("Ye Faerie Queene had no shuttle craft.");
  }
  else if (damage[10] > 0)
   prout("The Galileo is damaged.");
  else prout("Shuttle craft is now serving Big Mac's.");
  return;
 }
 if (a.inorbit==0) {
  crmshp();
  prout(" not in standard orbit.");
  return;
 }
 if ((d.plnets[a.iplnet].known != 2) && a.iscraft != 1) {
  prout("Shuttle craft not currently available.");
  return;
 }
 if (a.landed==-1 && d.plnets[a.iplnet].known==2) {
  prout("You will have to beam down to retrieve the shuttle craft.");
  return;
 }
 if (a.shldup!=0 || a.condit == 'D') {
  prout("Shuttle craft cannot pass through shields.");
  return;
 }
 if (d.plnets[a.iplnet].known==0) {
  prout("Spock-  \"Captain, we have no information on this planet");
  prout("  and Starfleet Regulations clearly state that in this situation");
  prout("  you may not fly down.\"");
  return;
 }
 a.Time = 3.0e-5*height;
 if (a.Time >= 0.8*d.remtime) {
  prout("First Officer Spock-  \"Captain, I compute that such");
  prout("  a maneuver would require approximately ");
  cramf(100*a.Time/d.remtime,0,4);
  prout("% of our");
  prout("remaining time.");
  prout("Are you sure this is wise?\" ");
  if (ja()==0) {
   a.Time = 0.0;
   return;
  }
 }
 if (a.landed == 1) {
  if (a.iscraft==1) {
   if (damage[12]==0) {
    proutn("Spock-  \"Would you rather use the transporter?\" ");
    if (ja() != 0) {
     beam();
     return;
    }
    proutn("Shuttle crew");
   }
   else
    proutn("Rescue party");
   prout(" boards Galileo and swoops toward planet surface.");
   a.iscraft = 0;
   skip(1);
   if (consumeTime()) return;
   d.plnets[a.iplnet].known=2;
   prout("Trip complete.");
   return;
  }
  else {
   prout("You and your mining party board the");
   prout("shuttle craft for the trip back to the Enterprise.");
   skip(1);
   prout("The short hop begins . . .");
   d.plnets[a.iplnet].known=1;
   a.icraft = 1;
   skip(1);
   a.landed = -1;
   if (consumeTime()) return;
   a.iscraft = 1;
   a.icraft = 0;
   if (a.imine!=0) {
    a.icrystl = 1;
    a.cryprob = 0.05;
   }
   a.imine = 0;
   prout("Trip complete.");
   return;
  }
 }
 else {
  prout("Mining party assembles in the hangar deck,");
  prout("ready to board the shuttle craft \"Galileo\".");
  skip(1);
  prouts("The hangar doors open; the trip begins.");
  skip(1);
  a.icraft = 1;
  a.iscraft = 0;
  if (consumeTime()) return;
  d.plnets[a.iplnet].known = 2;
  a.landed = 1;
  a.icraft = 0;
  prout("Trip complete");
  return;
 }
}

canonical_original_code:
void shuttle() {
 chew();
 skip(1);
 a.ididit = 0;
 if(damage[10] != 0.0) {
  if (damage[10] == -1.0) {
   if (a.inorbit && d.plnets[a.iplnet].known == 2)
    prout("Ye Faerie Queene has no shuttle craft bay to dock it at.");
   else
    prout("Ye Faerie Queene had no shuttle craft.");
  }
  else if (damage[10] > 0)
   prout("The Galileo is damaged.");
  else prout("Shuttle craft is now serving Big Mac's.");
  return;
 }
 if (a.inorbit==0) {
  crmshp();
  prout(" not in standard orbit.");
  return;
 }
 if ((d.plnets[a.iplnet].known != 2) && a.iscraft != 1) {
  prout("Shuttle craft not currently available.");
  return;
 }
 if (a.landed==-1 && d.plnets[a.iplnet].known==2) {
  prout("You will have to beam down to retrieve the shuttle craft.");
  return;
 }
 if (a.shldup!=0 || a.condit == 'D') {
  prout("Shuttle craft cannot pass through shields.");
  return;
 }
 if (d.plnets[a.iplnet].known==0) {
  prout("Spock-  \"Captain, we have no information on this planet");
  prout("  and Starfleet Regulations clearly state that in this situation");
  prout("  you may not fly down.\"");
  return;
 }
 a.Time = 3.0e-5*height;
 if (a.Time >= 0.8*d.remtime) {
  prout("First Officer Spock-  \"Captain, I compute that such");
  prout("  a maneuver would require approximately ");
  cramf(100*a.Time/d.remtime,0,4);
  prout("% of our");
  prout("remaining time.");
  prout("Are you sure this is wise?\" ");
  if (ja()==0) {
   a.Time = 0.0;
   return;
  }
 }
 if (a.landed == 1) {
  if (a.iscraft==1) {
   if (damage[12]==0) {
    proutn("Spock-  \"Would you rather use the transporter?\" ");
    if (ja() != 0) {
     beam();
     return;
    }
    proutn("Shuttle crew");
   }
   else
    proutn("Rescue party");
   prout(" boards Galileo and swoops toward planet surface.");
   a.iscraft = 0;
   skip(1);
   if (consumeTime()) return;
   d.plnets[a.iplnet].known=2;
   prout("Trip complete.");
   return;
  }
  else {
   prout("You and your mining party board the");
   prout("shuttle craft for the trip back to the Enterprise.");
   skip(1);
   prout("The short hop begins . . .");
   d.plnets[a.iplnet].known=1;
   a.icraft = 1;
   skip(1);
   a.landed = -1;
   if (consumeTime()) return;
   a.iscraft = 1;
   a.icraft = 0;
   if (a.imine!=0) {
    a.icrystl = 1;
    a.cryprob = 0.05;
   }
   a.imine = 0;
   prout("Trip complete.");
   return;
  }
 }
 else {
  prout("Mining party assembles in the hangar deck,");
  prout("ready to board the shuttle craft \"Galileo\".");
  skip(1);
  prouts("The hangar doors open; the trip begins.");
  skip(1);
  a.icraft = 1;
  a.iscraft = 0;
  if (consumeTime()) return;
  d.plnets[a.iplnet].known = 2;
  a.landed = 1;
  a.icraft = 0;
  prout("Trip complete");
  return;
 }
}


beam

decompiled_code:
__int64 beam()
{
_DWORD *v0; // rax
int v1; // edx
__int64 result; // rax
int v3; // edx

chew();
skip(1LL);
if ( damage[12] == 0.0 )
{
if ( !a[31] )
{
crmshp();
return prout(" not in standard orbit.");
}
if ( *(double *)&a[82] != 0.0 )
return prout("Impossible to transport through shields.");
v0 = &d[5 * a[33]];
v1 = v0[215];
if ( !v1 )
{
prout("Spock- \"Captain, we have no information on this planet");
prout(" and Starfleet Regulations clearly state that in this situation");
return prout(" you may not go down.\"");
}
if ( a[32] == 1 )
{
if ( v1 == 2 )
{
proutn("Spock- \"Wouldn't you rather take the Galileo?\" ");
if ( (unsigned int)ja() )
return chew();
prout("Your crew hides the Galileo to prevent capture by aliens.");
}
prout("Landing party assembled, ready to beam up.");
skip(1LL);
prout("Kirk whips out communicator...");
prouts("BEEP BEEP BEEP");
skip(2LL);
prout("\"Kirk to enterprise- Lock on coordinates...energize.\"");
}
else
{
if ( !v0[214] )
{
prout("Spock- \"Captain, I fail to see the logic in");
prout(" exploring a planet with no dilithium crystals.");
proutn(" Are you sure this is wise?\" ");
if ( !(unsigned int)ja() )
return chew();
}
prout("Scotty- \"Transporter room ready, Sir.\"");
skip(1LL);
prout("Kirk, and landing party prepare to beam down to planet surface.");
skip(1LL);
prout("Kirk- \"Energize.\"");
}
skip(1LL);
prouts("WWHOOOIIIIIRRRRREEEE.E.E. . . . . . .");
skip(2LL);
if ( Rand() > 0.98 )
{
prouts("BOOOIIIOOOIIOOOOIIIOIING . . .");
skip(2LL);
prout("Scotty- \"Oh my God! I've lost them.\"");
return finish(12LL);
}
prouts(". . . . . . .E.E.EEEERRRRRIIIIIOOOHWW");
skip(2LL);
prout("Transport complete.");
result = (unsigned int)a[32];
v3 = -a[32];
a[32] = v3;
if ( (_DWORD)result == -1 )
{
result = 5LL * a[33];
if ( d[5 * a[33] + 215] != 2 )
{
LABEL_13:
a[34] = 0;
return result;
}
result = prout("The shuttle craft Galileo is here!");
v3 = a[32];
}
if ( v3 != 1 && a[34] == 1 )
{
result = LC32;
a[51] = 1;
*(_QWORD *)&a[104] = LC32;
}
goto LABEL_13;
}
result = prout("Transporter damaged.");
if ( damage[10] == 0.0 )
{
result = 5LL * a[33];
if ( d[5 * a[33] + 215] == 2 || a[42] == 1 )
{
skip(1LL);
prout("Spock- \"May I suggest the shuttle craft, Sir?\" ", 0.0);
result = ja();
if ( (_DWORD)result )
result = shuttle();
}
}
return result;
}

canonical_decompiled_code:
__int64 func7()
{
_DWORD *v0; // rax
int v1; // edx
__int64 result; // rax
int v3; // edx

chew();
skip(1LL);
if ( damage[12] == 0.0 )
{
if ( !a[31] )
{
crmshp();
return prout(" not in standard orbit.");
}
if ( *(double *)&a[82] != 0.0 )
return prout("Impossible to transport through shields.");
v0 = &d[5 * a[33]];
v1 = v0[215];
if ( !v1 )
{
prout("Spock- \"Captain, we have no information on this planet");
prout(" and Starfleet Regulations clearly state that in this situation");
return prout(" you may not go down.\"");
}
if ( a[32] == 1 )
{
if ( v1 == 2 )
{
proutn("Spock- \"Wouldn't you rather take the Galileo?\" ");
if ( (unsigned int)ja() )
return chew();
prout("Your crew hides the Galileo to prevent capture by aliens.");
}
prout("Landing party assembled, ready to beam up.");
skip(1LL);
prout("Kirk whips out communicator...");
prouts("BEEP BEEP BEEP");
skip(2LL);
prout("\"Kirk to enterprise- Lock on coordinates...energize.\"");
}
else
{
if ( !v0[214] )
{
prout("Spock- \"Captain, I fail to see the logic in");
prout(" exploring a planet with no dilithium crystals.");
proutn(" Are you sure this is wise?\" ");
if ( !(unsigned int)ja() )
return chew();
}
prout("Scotty- \"Transporter room ready, Sir.\"");
skip(1LL);
prout("Kirk, and landing party prepare to beam down to planet surface.");
skip(1LL);
prout("Kirk- \"Energize.\"");
}
skip(1LL);
prouts("WWHOOOIIIIIRRRRREEEE.E.E. . . . . . .");
skip(2LL);
if ( Rand() > 0.98 )
{
prouts("BOOOIIIOOOIIOOOOIIIOIING . . .");
skip(2LL);
prout("Scotty- \"Oh my God! I've lost them.\"");
return finish(12LL);
}
prouts(". . . . . . .E.E.EEEERRRRRIIIIIOOOHWW");
skip(2LL);
prout("Transport complete.");
result = (unsigned int)a[32];
v3 = -a[32];
a[32] = v3;
if ( (_DWORD)result == -1 )
{
result = 5LL * a[33];
if ( d[5 * a[33] + 215] != 2 )
{
LABEL_13:
a[34] = 0;
return result;
}
result = prout("The shuttle craft Galileo is here!");
v3 = a[32];
}
if ( v3 != 1 && a[34] == 1 )
{
result = LC32;
a[51] = 1;
*(_QWORD *)&a[104] = LC32;
}
goto LABEL_13;
}
result = prout("Transporter damaged.");
if ( damage[10] == 0.0 )
{
result = 5LL * a[33];
if ( d[5 * a[33] + 215] == 2 || a[42] == 1 )
{
skip(1LL);
prout("Spock- \"May I suggest the shuttle craft, Sir?\" ", 0.0);
result = ja();
if ( (_DWORD)result )
result = func6();
}
}
return result;
}

original_code:
void beam(void) {
 chew();
 skip(1);
 if (damage[12] != 0) {
  prout("Transporter damaged.");
  if (damage[10]==0 && (d.plnets[a.iplnet].known==2 || a.iscraft == 1)) {
   skip(1);
   prout("Spock-  \"May I suggest the shuttle craft, Sir?\" ");
   if (ja() != 0) shuttle();
  }
  return;
 }
 if (a.inorbit==0) {
  crmshp();
  prout(" not in standard orbit.");
  return;
 }
 if (a.shldup!=0) {
  prout("Impossible to transport through shields.");
  return;
 }
 if (d.plnets[a.iplnet].known==0) {
  prout("Spock-  \"Captain, we have no information on this planet");
  prout("  and Starfleet Regulations clearly state that in this situation");
  prout("  you may not go down.\"");
  return;
 }
 if (a.landed==1) {
  if (d.plnets[a.iplnet].known==2) {
   proutn("Spock-  \"Wouldn't you rather take the Galileo?\" ");
   if (ja() != 0) {
    chew();
    return;
   }
   prout("Your crew hides the Galileo to prevent capture by aliens.");
  }
  prout("Landing party assembled, ready to beam up.");
  skip(1);
  prout("Kirk whips out communicator...");
  prouts("BEEP  BEEP  BEEP");
  skip(2);
  prout("\"Kirk to enterprise-  Lock on coordinates...energize.\"");
 }
 else {
  if (d.plnets[a.iplnet].crystals==0) {
   prout("Spock-  \"Captain, I fail to see the logic in");
   prout("  exploring a planet with no dilithium crystals.");
   proutn("  Are you sure this is wise?\" ");
   if (ja()==0) {
    chew();
    return;
   }
  }
  prout("Scotty-  \"Transporter room ready, Sir.\"");
  skip(1);
  prout("Kirk, and landing party prepare to beam down to planet surface.");
  skip(1);
  prout("Kirk-  \"Energize.\"");
 }
 skip(1);
 prouts("WWHOOOIIIIIRRRRREEEE.E.E.  .  .  .  .   .    .");
 skip(2);
 if (Rand() > 0.98) {
  prouts("BOOOIIIOOOIIOOOOIIIOIING . . .");
  skip(2);
  prout("Scotty-  \"Oh my God!  I've lost them.\"");
  finish(FLOST);
  return;
 }
 prouts(".    .   .  .  .  .  .E.E.EEEERRRRRIIIIIOOOHWW");
 skip(2);
 prout("Transport complete.");
 a.landed = -a.landed;
 if (a.landed==1 && d.plnets[a.iplnet].known==2) {
  prout("The shuttle craft Galileo is here!");
 }
 if (a.landed!=1 && a.imine==1) {
  a.icrystl = 1;
  a.cryprob = 0.05;
 }
 a.imine = 0;
 return;
}

canonical_original_code:
void beam() {
 chew();
 skip(1);
 if (damage[12] != 0) {
  prout("Transporter damaged.");
  if (damage[10]==0 && (d.plnets[a.iplnet].known==2 || a.iscraft == 1)) {
   skip(1);
   prout("Spock-  \"May I suggest the shuttle craft, Sir?\" ");
   if (ja() != 0) shuttle();
  }
  return;
 }
 if (a.inorbit==0) {
  crmshp();
  prout(" not in standard orbit.");
  return;
 }
 if (a.shldup!=0) {
  prout("Impossible to transport through shields.");
  return;
 }
 if (d.plnets[a.iplnet].known==0) {
  prout("Spock-  \"Captain, we have no information on this planet");
  prout("  and Starfleet Regulations clearly state that in this situation");
  prout("  you may not go down.\"");
  return;
 }
 if (a.landed==1) {
  if (d.plnets[a.iplnet].known==2) {
   proutn("Spock-  \"Wouldn't you rather take the Galileo?\" ");
   if (ja() != 0) {
    chew();
    return;
   }
   prout("Your crew hides the Galileo to prevent capture by aliens.");
  }
  prout("Landing party assembled, ready to beam up.");
  skip(1);
  prout("Kirk whips out communicator...");
  prouts("BEEP  BEEP  BEEP");
  skip(2);
  prout("\"Kirk to enterprise-  Lock on coordinates...energize.\"");
 }
 else {
  if (d.plnets[a.iplnet].crystals==0) {
   prout("Spock-  \"Captain, I fail to see the logic in");
   prout("  exploring a planet with no dilithium crystals.");
   proutn("  Are you sure this is wise?\" ");
   if (ja()==0) {
    chew();
    return;
   }
  }
  prout("Scotty-  \"Transporter room ready, Sir.\"");
  skip(1);
  prout("Kirk, and landing party prepare to beam down to planet surface.");
  skip(1);
  prout("Kirk-  \"Energize.\"");
 }
 skip(1);
 prouts("WWHOOOIIIIIRRRRREEEE.E.E.  .  .  .  .   .    .");
 skip(2);
 if (Rand() > 0.98) {
  prouts("BOOOIIIOOOIIOOOOIIIOIING . . .");
  skip(2);
  prout("Scotty-  \"Oh my God!  I've lost them.\"");
  finish(FLOST);
  return;
 }
 prouts(".    .   .  .  .  .  .E.E.EEEERRRRRIIIIIOOOHWW");
 skip(2);
 prout("Transport complete.");
 a.landed = -a.landed;
 if (a.landed==1 && d.plnets[a.iplnet].known==2) {
  prout("The shuttle craft Galileo is here!");
 }
 if (a.landed!=1 && a.imine==1) {
  a.icrystl = 1;
  a.cryprob = 0.05;
 }
 a.imine = 0;
 return;
}


deathray

decompiled_code:
__int64 deathray()
{
double v0; // xmm0_8
__int64 v1; // rsi
__int64 result; // rax
double v3; // xmm0_8
char *v4; // rdx
char *v5; // rax

v0 = Rand();
a[21] = 0;
skip(1LL);
chew();
if ( a[7] != 69 )
return prout("Ye Faerie Queene has no death ray.");
v1 = (unsigned int)a[36];
if ( !(_DWORD)v1 )
return prout("Sulu- \"But Sir, there are no enemies in this quadrant.\"");
if ( damage[14] > 0.0 )
return prout("Death Ray is damaged.");
prout("Spock- \"Captain, the 'Experimental Death Ray'");
prout(" is highly unpredictable. Considering the alternatives,");
prout(" are you sure this is wise?\" ");
result = ja();
if ( (_DWORD)result )
{
prout("Spock- \"Acknowledged.\"");
skip(1LL);
a[21] = 1;
prouts("WHOOEE ... WHOOEE ... WHOOEE ... WHOOEE");
skip(1LL);
prout("Crew scrambles in emergency preparation.");
prout("Spock and Scotty ready the death ray and");
prout("prepare to channel all ship's power to the device.");
skip(1LL);
prout("Spock- \"Preparations complete, sir.\"");
prout("Kirk- \"Engage!\"");
skip(1LL);
prouts("WHIRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR");
skip(1LL);
if ( v0 > 0.3 )
{
prouts("Sulu- \"Captain! It's working!\"");
skip(2LL);
while ( a[36] > 0 )
deadkl(
*((int *)&kx + 1),
*((int *)&ky + 1),
(unsigned int)quad[11 * *((int *)&kx + 1) + *((int *)&ky + 1)],
*((unsigned int *)&kx + 1),
*((unsigned int *)&ky + 1));
prout("Ensign Chekov- \"Congratulations, Captain!\"");
if ( !d[1] )
finish(0LL);
prout("Spock- \"Captain, I believe the `Experimental Death Ray'");
if ( Rand() > 0.05 )
{
prout(" has been rendered dysfunctional.\"");
result = LC135;
*(_QWORD *)&damage[14] = LC135;
}
else
{
result = prout(" is still operational.\"");
}
}
else
{
v3 = Rand();
if ( v3 <= 0.3 )
{
prouts("Sulu- \"Captain! It's working!\"");
skip(1LL);
prouts("***RED ALERT! RED ALERT!");
skip(1LL);
prout("***MATTER-ANTIMATTER IMPLOSION IMMINENT!");
skip(1LL);
prouts("***RED ALERT! RED A*L********************************");
skip(1LL);
stars();
prouts("****************** KA-BOOM!!!! *******************");
skip(1LL);
result = kaboom();
}
else if ( v3 <= 0.55 )
{
prouts("Sulu- \"Captain! Yagabandaghangrapl, brachriigringlanbla!\"");
skip(1LL);
prout("Lt. Uhura- \"Graaeek! Graaeek!\"");
skip(1LL);
prout("Spock- \"Fascinating! . . . All humans aboard");
prout(" have apparently been transformed into strange mutations.");
prout(" Vulcans do not seem to be affected.");
skip(1LL);
prout("Kirk- \"Raauch! Raauch!\"");
result = finish(18LL);
}
else if ( v3 <= 0.75 )
{
prouts("Sulu- \"Captain! It's --WHAT?!?!\"");
skip(2LL);
proutn("Spock- \"I believe the word is");
prouts(" *ASTONISHING*");
prout(" Mr. Sulu.");
v4 = (char *)(unsigned int)((_DWORD)quad + 21);
do
{
v5 = v4 - 10;
do
{
if ( v5[1] == 46 )
v5[1] = 63;
++v5;
}
while ( v5 != v4 );
v4 = v5 + 11;
}
while ( v5 != &quad[120] );
prout(" Captain, our quadrant is now infested with", v1, v4);
prouts(" - - - - - - *THINGS*.");
skip(1LL);
result = prout(" I have no logical explanation.\"");
}
else
{
prouts("Sulu- \"Captain! The Death Ray is creating tribbles!\"");
skip(1LL);
prout("Scotty- \"There are so many tribbles down here");
prout(" in Engineering, we can't move for 'em, Captain.\"");
result = finish(19LL);
}
}
}
return result;
}

canonical_decompiled_code:
__int64 func8()
{
double v0; // xmm0_8
__int64 v1; // rsi
__int64 result; // rax
double v3; // xmm0_8
char *v4; // rdx
char *v5; // rax

v0 = Rand();
a[21] = 0;
skip(1LL);
chew();
if ( a[7] != 69 )
return prout("Ye Faerie Queene has no death ray.");
v1 = (unsigned int)a[36];
if ( !(_DWORD)v1 )
return prout("Sulu- \"But Sir, there are no enemies in this quadrant.\"");
if ( damage[14] > 0.0 )
return prout("Death Ray is damaged.");
prout("Spock- \"Captain, the 'Experimental Death Ray'");
prout(" is highly unpredictable. Considering the alternatives,");
prout(" are you sure this is wise?\" ");
result = ja();
if ( (_DWORD)result )
{
prout("Spock- \"Acknowledged.\"");
skip(1LL);
a[21] = 1;
prouts("WHOOEE ... WHOOEE ... WHOOEE ... WHOOEE");
skip(1LL);
prout("Crew scrambles in emergency preparation.");
prout("Spock and Scotty ready the death ray and");
prout("prepare to channel all ship's power to the device.");
skip(1LL);
prout("Spock- \"Preparations complete, sir.\"");
prout("Kirk- \"Engage!\"");
skip(1LL);
prouts("WHIRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR");
skip(1LL);
if ( v0 > 0.3 )
{
prouts("Sulu- \"Captain! It's working!\"");
skip(2LL);
while ( a[36] > 0 )
deadkl(
*((int *)&kx + 1),
*((int *)&ky + 1),
(unsigned int)quad[11 * *((int *)&kx + 1) + *((int *)&ky + 1)],
*((unsigned int *)&kx + 1),
*((unsigned int *)&ky + 1));
prout("Ensign Chekov- \"Congratulations, Captain!\"");
if ( !d[1] )
finish(0LL);
prout("Spock- \"Captain, I believe the `Experimental Death Ray'");
if ( Rand() > 0.05 )
{
prout(" has been rendered dysfunctional.\"");
result = LC135;
*(_QWORD *)&damage[14] = LC135;
}
else
{
result = prout(" is still operational.\"");
}
}
else
{
v3 = Rand();
if ( v3 <= 0.3 )
{
prouts("Sulu- \"Captain! It's working!\"");
skip(1LL);
prouts("***RED ALERT! RED ALERT!");
skip(1LL);
prout("***MATTER-ANTIMATTER IMPLOSION IMMINENT!");
skip(1LL);
prouts("***RED ALERT! RED A*L********************************");
skip(1LL);
stars();
prouts("****************** KA-BOOM!!!! *******************");
skip(1LL);
result = kaboom();
}
else if ( v3 <= 0.55 )
{
prouts("Sulu- \"Captain! Yagabandaghangrapl, brachriigringlanbla!\"");
skip(1LL);
prout("Lt. Uhura- \"Graaeek! Graaeek!\"");
skip(1LL);
prout("Spock- \"Fascinating! . . . All humans aboard");
prout(" have apparently been transformed into strange mutations.");
prout(" Vulcans do not seem to be affected.");
skip(1LL);
prout("Kirk- \"Raauch! Raauch!\"");
result = finish(18LL);
}
else if ( v3 <= 0.75 )
{
prouts("Sulu- \"Captain! It's --WHAT?!?!\"");
skip(2LL);
proutn("Spock- \"I believe the word is");
prouts(" *ASTONISHING*");
prout(" Mr. Sulu.");
v4 = (char *)(unsigned int)((_DWORD)quad + 21);
do
{
v5 = v4 - 10;
do
{
if ( v5[1] == 46 )
v5[1] = 63;
++v5;
}
while ( v5 != v4 );
v4 = v5 + 11;
}
while ( v5 != &quad[120] );
prout(" Captain, our quadrant is now infested with", v1, v4);
prouts(" - - - - - - *THINGS*.");
skip(1LL);
result = prout(" I have no logical explanation.\"");
}
else
{
prouts("Sulu- \"Captain! The Death Ray is creating tribbles!\"");
skip(1LL);
prout("Scotty- \"There are so many tribbles down here");
prout(" in Engineering, we can't move for 'em, Captain.\"");
result = finish(19LL);
}
}
}
return result;
}

original_code:
void deathray(void) {
 double r = Rand();
 a.ididit = 0;
 skip(1);
 chew();
 if (a.ship != 'E') {
  prout("Ye Faerie Queene has no death ray.");
  return;
 }
 if (a.nenhere==0) {
  prout("Sulu-  \"But Sir, there are no enemies in this quadrant.\"");
  return;
 }
 if (damage[14] > 0.0) {
  prout("Death Ray is damaged.");
  return;
 }
 prout("Spock-  \"Captain, the 'Experimental Death Ray'");
 prout("  is highly unpredictable.  Considering the alternatives,");
 prout("  are you sure this is wise?\" ");
 if (ja()==0) return;
 prout("Spock-  \"Acknowledged.\"");
 skip(1);
 a.ididit=1;
 prouts("WHOOEE ... WHOOEE ... WHOOEE ... WHOOEE");
 skip(1);
 prout("Crew scrambles in emergency preparation.");
 prout("Spock and Scotty ready the death ray and");
 prout("prepare to channel all ship's power to the device.");
 skip(1);
 prout("Spock-  \"Preparations complete, sir.\"");
 prout("Kirk-  \"Engage!\"");
 skip(1);
 prouts("WHIRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR");
 skip(1);
 if (r > .30) {
  prouts("Sulu- \"Captain!  It's working!\"");
  skip(2);
  while (a.nenhere > 0) {
   deadkl(kx[1],ky[1],quad[kx[1]][ky[1]],kx[1],ky[1]);
  }
  prout("Ensign Chekov-  \"Congratulations, Captain!\"");
  if (d.remkl == 0) finish(FWON);
  prout("Spock-  \"Captain, I believe the `Experimental Death Ray'");
  if (Rand() <= 0.05) {
   prout("   is still operational.\"");
  }
  else {
   prout("   has been rendered dysfunctional.\"");
   damage[14] = 39.95;
  }
  return;
 }
 r = Rand();
 if (r <= .30) {
  prouts("Sulu- \"Captain!  It's working!\"");
  skip(1);
  prouts("***RED ALERT!  RED ALERT!");
  skip(1);
  prout("***MATTER-ANTIMATTER IMPLOSION IMMINENT!");
  skip(1);
  prouts("***RED ALERT!  RED A*L********************************");
  skip(1);
  stars();
  prouts("******************   KA-BOOM!!!!   *******************");
  skip(1);
  kaboom();
  return;
 }
 if (r <= .55) {
  prouts("Sulu- \"Captain!  Yagabandaghangrapl, brachriigringlanbla!\"");
  skip(1);
  prout("Lt. Uhura-  \"Graaeek!  Graaeek!\"");
  skip(1);
  prout("Spock-  \"Fascinating!  . . . All humans aboard");
  prout("  have apparently been transformed into strange mutations.");
  prout("  Vulcans do not seem to be affected.");
  skip(1);
  prout("Kirk-  \"Raauch!  Raauch!\"");
  finish(FDRAY);
  return;
 }
 if (r <= 0.75) {
  int i,j;
  prouts("Sulu- \"Captain!  It's   --WHAT?!?!\"");
  skip(2);
  proutn("Spock-  \"I believe the word is");
  prouts(" *ASTONISHING*");
  prout(" Mr. Sulu.");
  for (i=1; i<=10; i++)
   for (j=1; j<=10; j++)
    if (quad[i][j] == '.') quad[i][j] = '?';
  prout("  Captain, our quadrant is now infested with");
  prouts(" - - - - - -  *THINGS*.");
  skip(1);
  prout("  I have no logical explanation.\"");
  return;
 }
 prouts("Sulu- \"Captain!  The Death Ray is creating tribbles!\"");
 skip(1);
 prout("Scotty-  \"There are so many tribbles down here");
 prout("  in Engineering, we can't move for 'em, Captain.\"");
 finish(FTRIBBLE);
 return;
}

canonical_original_code:
void deathray() {
 double r = Rand();
 a.ididit = 0;
 skip(1);
 chew();
 if (a.ship != 'E') {
  prout("Ye Faerie Queene has no death ray.");
  return;
 }
 if (a.nenhere==0) {
  prout("Sulu-  \"But Sir, there are no enemies in this quadrant.\"");
  return;
 }
 if (damage[14] > 0.0) {
  prout("Death Ray is damaged.");
  return;
 }
 prout("Spock-  \"Captain, the 'Experimental Death Ray'");
 prout("  is highly unpredictable.  Considering the alternatives,");
 prout("  are you sure this is wise?\" ");
 if (ja()==0) return;
 prout("Spock-  \"Acknowledged.\"");
 skip(1);
 a.ididit=1;
 prouts("WHOOEE ... WHOOEE ... WHOOEE ... WHOOEE");
 skip(1);
 prout("Crew scrambles in emergency preparation.");
 prout("Spock and Scotty ready the death ray and");
 prout("prepare to channel all ship's power to the device.");
 skip(1);
 prout("Spock-  \"Preparations complete, sir.\"");
 prout("Kirk-  \"Engage!\"");
 skip(1);
 prouts("WHIRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR");
 skip(1);
 if (r > .30) {
  prouts("Sulu- \"Captain!  It's working!\"");
  skip(2);
  while (a.nenhere > 0) {
   deadkl(kx[1],ky[1],quad[kx[1]][ky[1]],kx[1],ky[1]);
  }
  prout("Ensign Chekov-  \"Congratulations, Captain!\"");
  if (d.remkl == 0) finish(FWON);
  prout("Spock-  \"Captain, I believe the `Experimental Death Ray'");
  if (Rand() <= 0.05) {
   prout("   is still operational.\"");
  }
  else {
   prout("   has been rendered dysfunctional.\"");
   damage[14] = 39.95;
  }
  return;
 }
 r = Rand();
 if (r <= .30) {
  prouts("Sulu- \"Captain!  It's working!\"");
  skip(1);
  prouts("***RED ALERT!  RED ALERT!");
  skip(1);
  prout("***MATTER-ANTIMATTER IMPLOSION IMMINENT!");
  skip(1);
  prouts("***RED ALERT!  RED A*L********************************");
  skip(1);
  stars();
  prouts("******************   KA-BOOM!!!!   *******************");
  skip(1);
  kaboom();
  return;
 }
 if (r <= .55) {
  prouts("Sulu- \"Captain!  Yagabandaghangrapl, brachriigringlanbla!\"");
  skip(1);
  prout("Lt. Uhura-  \"Graaeek!  Graaeek!\"");
  skip(1);
  prout("Spock-  \"Fascinating!  . . . All humans aboard");
  prout("  have apparently been transformed into strange mutations.");
  prout("  Vulcans do not seem to be affected.");
  skip(1);
  prout("Kirk-  \"Raauch!  Raauch!\"");
  finish(FDRAY);
  return;
 }
 if (r <= 0.75) {
  int i; int j;
  prouts("Sulu- \"Captain!  It's   --WHAT?!?!\"");
  skip(2);
  proutn("Spock-  \"I believe the word is");
  prouts(" *ASTONISHING*");
  prout(" Mr. Sulu.");
  for (i=1; i<=10; i++)
   for (j=1; j<=10; j++)
    if (quad[i][j] == '.') quad[i][j] = '?';
  prout("  Captain, our quadrant is now infested with");
  prouts(" - - - - - -  *THINGS*.");
  skip(1);
  prout("  I have no logical explanation.\"");
  return;
 }
 prouts("Sulu- \"Captain!  The Death Ray is creating tribbles!\"");
 skip(1);
 prout("Scotty-  \"There are so many tribbles down here");
 prout("  in Engineering, we can't move for 'em, Captain.\"");
 finish(FTRIBBLE);
 return;
}

variable_types: r double


decompiled_code:
__int64 __fastcall roznica_dat(__int64 a1, int a2, __int64 a3, int a4)
{
return (unsigned int)(30 * (HIDWORD(a1) - HIDWORD(a3)) + 365 * (a2 - a4) + a1 - a3);
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, int a2, __int64 a3, int a4)
{
return (unsigned int)(30 * (HIDWORD(a1) - HIDWORD(a3)) + 365 * (a2 - a4) + a1 - a3);
}

original_code:
int roznica_dat(data a, data b) {
   int roznica;
   roznica = (a.rok - b.rok) * 365 + (a.miesiac - b.miesiac) * 30 + (a.dzien - b.dzien);
   return roznica;
}

canonical_original_code:
int roznica_dat(struct dat a, struct dat b) {
   int roznica;
   roznica = (a.rok - b.rok) * 365 + (a.miesiac - b.miesiac) * 30 + (a.dzien - b.dzien);
   return roznica;
}

variable_types: struct dat { int dzien; int miesiac; int rok; }

variable_types:
b
struct dat

variable_types: roznica int


decompiled_code:
unsigned __int64 __fastcall dodaj_do_daty(unsigned __int64 a1, __int64 a2, int a3)
{
int v3; // edx
unsigned __int64 v4; // rcx

v3 = a1 + a3;
v4 = HIDWORD(a1);
if ( v3 > 30 )
{
v3 %= 30;
if ( SHIDWORD(a1) > 12 )
LODWORD(v4) = SHIDWORD(a1) % 12;
}
return __PAIR64__(v4, v3);
}

canonical_decompiled_code:
unsigned __int64 __fastcall func1(unsigned __int64 a1, __int64 a2, int a3)
{
int v3; // edx
unsigned __int64 v4; // rcx

v3 = a1 + a3;
v4 = HIDWORD(a1);
if ( v3 > 30 )
{
v3 %= 30;
if ( SHIDWORD(a1) > 12 )
LODWORD(v4) = SHIDWORD(a1) % 12;
}
return __PAIR64__(v4, v3);
}

original_code:
data dodaj_do_daty(data a, int n) {
   a.dzien = a.dzien + n;
   if(a.dzien > 30) {
      a.dzien = a.dzien % 30;
      a.miesiac = a.miesiac + a.dzien / 30;
      if(a.miesiac > 12) {
         a.miesiac = a.miesiac % 12;
         a.rok = a.rok + a.miesiac / 12;
      }
   }
   return a;
}

canonical_original_code:
struct dat dodaj_do_daty(struct dat a, int n) {
   a.dzien = a.dzien + n;
   if(a.dzien > 30) {
      a.dzien = a.dzien % 30;
      a.miesiac = a.miesiac + a.dzien / 30;
      if(a.miesiac > 12) {
         a.miesiac = a.miesiac % 12;
         a.rok = a.rok + a.miesiac / 12;
      }
   }
   return a;
}

variable_types:
a
struct dat

variable_types: n int

return_type: struct dat { int dzien; int miesiac; int rok; }


decompiled_code:
__int64 __fastcall szukaj_indeksu_miasta(char *s2, __int64 a2, int a3)
{
__int64 v3; // rbp
__int64 v4; // rbx
unsigned int v5; // er15
const char *v6; // r14
size_t v7; // rax

if ( a3 <= 0 )
goto LABEL_8;
v3 = a3;
v4 = 0LL;
v5 = -1;
do
{
v6 = *(const char **)(a2 + 8 * v4);
v7 = strlen(v6);
if ( !strncmp(v6, s2, v7 - 1) )
v5 = v4;
++v4;
}
while ( v3 != v4 );
if ( v5 == -1 )
{
LABEL_8:
printf("Blad! W plikach znajduja sie bledne dane!");
exit(1);
}
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func2(char *s2, __int64 a2, int a3)
{
__int64 v3; // rbp
__int64 v4; // rbx
unsigned int v5; // er15
const char *v6; // r14
size_t v7; // rax

if ( a3 <= 0 )
goto LABEL_8;
v3 = a3;
v4 = 0LL;
v5 = -1;
do
{
v6 = *(const char **)(a2 + 8 * v4);
v7 = strlen(v6);
if ( !strncmp(v6, s2, v7 - 1) )
v5 = v4;
++v4;
}
while ( v3 != v4 );
if ( v5 == -1 )
{
LABEL_8:
printf("Blad! W plikach znajduja sie bledne dane!");
exit(1);
}
return v5;
}

original_code:
int szukaj_indeksu_miasta(char *miasto, char ** miasta, int rozmiar) {
   int index, i;
   index = -1;
   for(i = 0; i < rozmiar; i++) {
      if(strncmp(miasta[i], miasto, strlen(miasta[i]) - 1) == 0)
         index = i;
   }
   if(index == -1) {
      printf("Blad! W plikach znajduja sie bledne dane!");
      exit(1);
   }
   return index;
}

canonical_original_code:
int szukaj_indeksu_miasta(char *miasto, char **miasta, int rozmiar) {
   int index; int i;
   index = -1;
   for(i = 0; i < rozmiar; i++) {
      if(strncmp(miasta[i], miasto, strlen(miasta[i]) - 1) == 0)
         index = i;
   }
   if(index == -1) {
      printf("Blad! W plikach znajduja sie bledne dane!");
      exit(1);
   }
   return index;
}

variable_types:
miasto
char *

variable_types:
miasta
char **

variable_types: rozmiar int

variable_types: index int


decompiled_code:
__int64 __fastcall znajdz_ID(__int64 *a1, int a2, const char *a3)
{
__int64 *v4; // rbx
__int64 v5; // r13
const char *v6; // r14
size_t v7; // rax

if ( a2 <= 0 )
goto LABEL_8;
v4 = a1;
v5 = -1LL;
do
{
v6 = (const char *)v4[1];
v7 = strlen(v6);
if ( !strncmp(v6, a3, v7 - 1) )
v5 = *v4;
v4 += 2;
}
while ( v4 != &a1[2 * (unsigned int)(a2 - 1) + 2] );
if ( v5 == -1 )
{
LABEL_8:
printf("Blad! W plikach znajduja sie bledne dane!");
exit(1);
}
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 *a1, int a2, const char *a3)
{
__int64 *v4; // rbx
__int64 v5; // r13
const char *v6; // r14
size_t v7; // rax

if ( a2 <= 0 )
goto LABEL_8;
v4 = a1;
v5 = -1LL;
do
{
v6 = (const char *)v4[1];
v7 = strlen(v6);
if ( !strncmp(v6, a3, v7 - 1) )
v5 = *v4;
v4 += 2;
}
while ( v4 != &a1[2 * (unsigned int)(a2 - 1) + 2] );
if ( v5 == -1 )
{
LABEL_8:
printf("Blad! W plikach znajduja sie bledne dane!");
exit(1);
}
return v5;
}

original_code:
long int znajdz_ID(artykul * artykuly, int liczba_artykulow, char * nazwa) {
   int i;
   long int ID = -1;
   for(i = 0; i < liczba_artykulow; i++) {
      if(strncmp(artykuly[i].nazwa, nazwa, strlen(artykuly[i].nazwa) - 1) == 0)
         ID = artykuly[i].ID;
   }
   if(ID == -1) {
      printf("Blad! W plikach znajduja sie bledne dane!");
      exit(1);
   }
   return ID;
}

canonical_original_code:
long znajdz_ID(struct art *artykuly, int liczba_artykulow, char *nazwa) {
   int i;
   long ID = -1;
   for(i = 0; i < liczba_artykulow; i++) {
      if(strncmp(artykuly[i].nazwa, nazwa, strlen(artykuly[i].nazwa) - 1) == 0)
         ID = artykuly[i].ID;
   }
   if(ID == -1) {
      printf("Blad! W plikach znajduja sie bledne dane!");
      exit(1);
   }
   return ID;
}

variable_types:
artykuly
struct art { long ID; char *nazwa; } *

variable_types:
nazwa
char *

variable_types: i int

variable_types: ID long

return_type: long


decompiled_code:
void *__fastcall znajdz_nazwe(_QWORD *a1, int a2, __int64 a3)
{
_QWORD *v4; // rbx
void *v5; // r8
__int64 v6; // r12
const char *v7; // r14
size_t v8; // r13
void *v9; // rax

if ( a2 <= 0 )
goto LABEL_8;
v4 = a1;
v5 = 0LL;
v6 = (__int64)&a1[2 * (unsigned int)(a2 - 1) + 2];
do
{
while ( *v4 != a3 )
{
v4 += 2;
if ( v4 == (_QWORD *)v6 )
goto LABEL_6;
}
v7 = (const char *)v4[1];
v4 += 2;
v8 = strlen(v7) + 1;
v9 = malloc(v8);
v5 = memcpy(v9, v7, v8);
}
while ( v4 != (_QWORD *)v6 );
LABEL_6:
if ( !v5 )
{
LABEL_8:
printf("Blad! W plikach znajduja sie bledne dane!");
exit(1);
}
return v5;
}

canonical_decompiled_code:
void *__fastcall func4(_QWORD *a1, int a2, __int64 a3)
{
_QWORD *v4; // rbx
void *v5; // r8
__int64 v6; // r12
const char *v7; // r14
size_t v8; // r13
void *v9; // rax

if ( a2 <= 0 )
goto LABEL_8;
v4 = a1;
v5 = 0LL;
v6 = (__int64)&a1[2 * (unsigned int)(a2 - 1) + 2];
do
{
while ( *v4 != a3 )
{
v4 += 2;
if ( v4 == (_QWORD *)v6 )
goto LABEL_6;
}
v7 = (const char *)v4[1];
v4 += 2;
v8 = strlen(v7) + 1;
v9 = malloc(v8);
v5 = memcpy(v9, v7, v8);
}
while ( v4 != (_QWORD *)v6 );
LABEL_6:
if ( !v5 )
{
LABEL_8:
printf("Blad! W plikach znajduja sie bledne dane!");
exit(1);
}
return v5;
}

original_code:
char * znajdz_nazwe(artykul * artykuly, int liczba_artykulow, long int ID) {
   int i;
   char * nazwa = ((void *)0);
   for(i = 0; i < liczba_artykulow; i++) {
      if(artykuly[i].ID == ID) {
         nazwa = malloc((strlen(artykuly[i].nazwa) + 1) * sizeof(char));
         strcpy(nazwa, artykuly[i].nazwa);
      }
   }
   if(nazwa == ((void *)0)) {
      printf("Blad! W plikach znajduja sie bledne dane!");
      exit(1);
   }
   return nazwa;
}

canonical_original_code:
char *znajdz_nazwe(struct art *artykuly, int liczba_artykulow, long ID) {
   int i;
   char *nazwa = ((void *)0);
   for(i = 0; i < liczba_artykulow; i++) {
      if(artykuly[i].ID == ID) {
         nazwa = malloc((strlen(artykuly[i].nazwa) + 1) * sizeof(char));
         strcpy(nazwa, artykuly[i].nazwa);
      }
   }
   if(nazwa == ((void *)0)) {
      printf("Blad! W plikach znajduja sie bledne dane!");
      exit(1);
   }
   return nazwa;
}

return_type: char *