decompiled_code:
__int64 __fastcall callback_send_t_buffer_destroy(__int64 a1, unsigned int a2, unsigned __int16 a3)
{
__int64 result; // rax
__int64 v6; // rbp
unsigned int v7; // er13
__int64 v8; // rbx
__int64 v9; // rdi
unsigned int v10; // ebx
int v11; // er14
__int64 v12; // rsi

result = vs_get_node(a2, 4LL);
if ( result )
{
v6 = result;
v7 = a3;
if ( (unsigned int)a3 < *(_DWORD *)(result + 568) )
{
v8 = 48LL * a3;
result = v8 + *(_QWORD *)(result + 560);
if ( *(_BYTE *)result )
{
*(_BYTE *)result = 0;
free(*(void **)(result + 16));
v9 = *(_QWORD *)(*(_QWORD *)(v6 + 560) + v8 + 40);
v10 = 0;
vs_destroy_subscription_list(v9);
v11 = vs_get_subscript_count(*(_QWORD *)(v6 + 40));
if ( v11 )
{
do
{
v12 = v10++;
vs_set_subscript_session(*(_QWORD *)(v6 + 40), v12);
verse_send_t_buffer_destroy(a2, v7);
}
while ( v11 != v10 );
}
result = vs_reset_subscript_session();
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, unsigned int a2, unsigned __int16 a3)
{
__int64 result; // rax
__int64 v6; // rbp
unsigned int v7; // er13
__int64 v8; // rbx
__int64 v9; // rdi
unsigned int v10; // ebx
int v11; // er14
__int64 v12; // rsi

result = vs_get_node(a2, 4LL);
if ( result )
{
v6 = result;
v7 = a3;
if ( (unsigned int)a3 < *(_DWORD *)(result + 568) )
{
v8 = 48LL * a3;
result = v8 + *(_QWORD *)(result + 560);
if ( *(_BYTE *)result )
{
*(_BYTE *)result = 0;
free(*(void **)(result + 16));
v9 = *(_QWORD *)(*(_QWORD *)(v6 + 560) + v8 + 40);
v10 = 0;
vs_destroy_subscription_list(v9);
v11 = vs_get_subscript_count(*(_QWORD *)(v6 + 40));
if ( v11 )
{
do
{
v12 = v10++;
vs_set_subscript_session(*(_QWORD *)(v6 + 40), v12);
verse_send_t_buffer_destroy(a2, v7);
}
while ( v11 != v10 );
}
result = vs_reset_subscript_session();
}
}
}
return result;
}

original_code:
void callback_send_t_buffer_destroy(void *user, VNodeID node_id, VBufferID buffer_id)
{
 VSNodeText *node;
 unsigned int i, count;
 node = (VSNodeText *)vs_get_node(node_id, V_NT_TEXT);
 if(node == ((void *)0))
  return;
 if(buffer_id >= node->buffer_count || node->buffer[buffer_id].name[0] == 0)
  return;
 node->buffer[buffer_id].name[0] = 0;
 free(node->buffer[buffer_id].text);
 vs_destroy_subscription_list(node->buffer[buffer_id].subscribers);
 count = vs_get_subscript_count(node->head.subscribers);
 for(i = 0; i < count; i++)
 {
  vs_set_subscript_session(node->head.subscribers, i);
  verse_send_t_buffer_destroy(node_id, buffer_id);
 }
 vs_reset_subscript_session();
}

canonical_original_code:
void callback_send_t_buffer_destroy(void *user, unsigned int node_id, unsigned short buffer_id)
{
 struct VSNodeText *node;
 unsigned int i; unsigned int count;
 node = (struct VSNodeText *)vs_get_node(node_id, V_NT_TEXT);
 if(node == ((void *)0))
  return;
 if(buffer_id >= node->buffer_count || node->buffer[buffer_id].name[0] == 0)
  return;
 node->buffer[buffer_id].name[0] = 0;
 free(node->buffer[buffer_id].text);
 vs_destroy_subscription_list(node->buffer[buffer_id].subscribers);
 count = vs_get_subscript_count(node->head.subscribers);
 for(i = 0; i < count; i++)
 {
  vs_set_subscript_session(node->head.subscribers, i);
  verse_send_t_buffer_destroy(node_id, buffer_id);
 }
 vs_reset_subscript_session();
}

user_defined_types: struct VSTextBuffer { char name[16]; char *text; unsigned long length; unsigned long allocated; void *subscribers; }


repo: wal-rus/song

decompiled_code:
__int64 __fastcall callback_send_t_language_set(__int64 a1, unsigned int a2, __int64 a3)
{
__int64 result; // rax
__int64 v6; // rbp
__int64 v7; // rax
char v8; // dl
__int64 v9; // rcx
int v10; // er14
unsigned int i; // ebx
__int64 v12; // rsi

result = vs_get_node(a2, 4LL);
if ( result )
{
v6 = result;
v7 = 0LL;
while ( 1 )
{
v8 = *(_BYTE *)(a3 + v7);
v9 = (unsigned int)v7;
if ( !v8 )
break;
*(_BYTE *)(v6 + v7++ + 48) = v8;
if ( v7 == 511 )
{
v9 = 511LL;
break;
}
}
*(_BYTE *)(v6 + v9 + 48) = 0;
v10 = vs_get_subscript_count(*(_QWORD *)(v6 + 40));
if ( v10 )
{
for ( i = 0; i != v10; ++i )
{
v12 = i;
vs_set_subscript_session(*(_QWORD *)(v6 + 40), v12);
verse_send_t_language_set(a2, a3);
}
}
result = vs_reset_subscript_session();
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, unsigned int a2, __int64 a3)
{
__int64 result; // rax
__int64 v6; // rbp
__int64 v7; // rax
char v8; // dl
__int64 v9; // rcx
int v10; // er14
unsigned int i; // ebx
__int64 v12; // rsi

result = vs_get_node(a2, 4LL);
if ( result )
{
v6 = result;
v7 = 0LL;
while ( 1 )
{
v8 = *(_BYTE *)(a3 + v7);
v9 = (unsigned int)v7;
if ( !v8 )
break;
*(_BYTE *)(v6 + v7++ + 48) = v8;
if ( v7 == 511 )
{
v9 = 511LL;
break;
}
}
*(_BYTE *)(v6 + v9 + 48) = 0;
v10 = vs_get_subscript_count(*(_QWORD *)(v6 + 40));
if ( v10 )
{
for ( i = 0; i != v10; ++i )
{
v12 = i;
vs_set_subscript_session(*(_QWORD *)(v6 + 40), v12);
verse_send_t_language_set(a2, a3);
}
}
result = vs_reset_subscript_session();
}
return result;
}

original_code:
static void callback_send_t_language_set(void *user, VNodeID node_id, char *language)
{
 VSNodeText *node;
 unsigned int i, count;
 node = (VSNodeText *)vs_get_node(node_id, V_NT_TEXT);
 if(node == ((void *)0))
  return;
 for(i = 0; i < 511 && language[i]; i++)
  node->language[i] = language[i];
 node->language[i] = 0;
 count = vs_get_subscript_count(node->head.subscribers);
 for(i = 0; i < count; i++)
 {
  vs_set_subscript_session(node->head.subscribers, i);
  verse_send_t_language_set(node_id, language);
 }
 vs_reset_subscript_session();
}

canonical_original_code:
static void callback_send_t_language_set(void *user, unsigned int node_id, char *language)
{
 struct VSNodeText *node;
 unsigned int i; unsigned int count;
 node = (struct VSNodeText *)vs_get_node(node_id, V_NT_TEXT);
 if(node == ((void *)0))
  return;
 for(i = 0; i < 511 && language[i]; i++)
  node->language[i] = language[i];
 node->language[i] = 0;
 count = vs_get_subscript_count(node->head.subscribers);
 for(i = 0; i < count; i++)
 {
  vs_set_subscript_session(node->head.subscribers, i);
  verse_send_t_language_set(node_id, language);
 }
 vs_reset_subscript_session();
}

variable_types:
user
void *

variable_types:
language
char *

variable_types: struct VSNodeText { struct VSNodeHead { unsigned int id; enum VNodeType { V_NT_OBJECT=0, V_NT_GEOMETRY=1, V_NT_MATERIAL=2, V_NT_BITMAP=3, V_NT_TEXT=4, V_NT_CURVE=5, V_NT_AUDIO=6, V_NT_NUM_TYPES=7, V_NT_SYSTEM=expr, V_NT_NUM_TYPES_NETPACK=expr } type; unsigned int owner; char *name; void *tag_groups; unsigned short group_count; void *subscribers; } head; char language[512]; struct VSTextBuffer { char name[16]; char *text; unsigned long length; unsigned long allocated; void *subscribers; } *buffer; unsigned int buffer_count; } *

variable_types:
i
unsigned int

variable_types:
count
unsigned int

return_type: void

user_defined_types: struct VSNodeText { struct VSNodeHead head; char language[512]; struct VSTextBuffer *buffer; unsigned int buffer_count; }

user_defined_types: struct VSNodeHead { unsigned int id; enum VNodeType type; unsigned int owner; char *name; void *tag_groups; unsigned short group_count; void *subscribers; }


original_code:
static void callback_send_t_text_set(void *user, VNodeID node_id, VBufferID buffer_id, uint32 pos, uint32 length, const char *text)
{
 VSNodeText *node;
 VSTextBuffer *tb;
 unsigned int i, count, text_length;
 char *buf;
 node = (VSNodeText *) vs_get_node(node_id, V_NT_TEXT);
 if(node == ((void *)0))
  return;
 if(buffer_id >= node->buffer_count || node->buffer[buffer_id].name[0] == 0)
  return;
 tb = &node->buffer[buffer_id];
 text_length = strlen(text);
 if(pos > tb->length)
  pos = tb->length;
 if(pos + length > tb->length)
  length = tb->length - pos;
 buf = tb->text;
 if(tb->length + text_length - length > tb->allocated)
 {
  buf = realloc(buf, tb->length + text_length - length + 4096);
  tb->allocated = tb->length + text_length - length + 4096;
 }
 if(text_length < length)
 {
  memmove(buf + pos + text_length, buf + pos + length, tb->length - (pos + length));
  memcpy(buf + pos, text, text_length);
 }
 else
 {
  memmove(buf + pos + text_length, buf + pos + length, tb->length - pos);
  memcpy(buf + pos, text, text_length);
 }
 tb->length += (int) text_length - length;
 buf[tb->length] = '\0';
 if(tb->allocated > 4096 * 8 && tb->allocated * 2 > tb->length)
 {
  buf = realloc(buf, tb->length + 4096);
  tb->allocated = tb->length + 4096;
 }
 tb->text = buf;
 count = vs_get_subscript_count(tb->subscribers);
 for(i = 0; i < count; i++)
 {
  vs_set_subscript_session(tb->subscribers, i);
  verse_send_t_text_set(node_id, buffer_id, pos, length, text);
 }
 vs_reset_subscript_session();
}

canonical_original_code:
static void callback_send_t_text_set(void *user, unsigned int node_id, unsigned short buffer_id, unsigned int pos, unsigned int length, char *text)
{
 struct VSNodeText *node;
 struct VSTextBuffer *tb;
 unsigned int i; unsigned int count; unsigned int text_length;
 char *buf;
 node = (struct VSNodeText *) vs_get_node(node_id, V_NT_TEXT);
 if(node == ((void *)0))
  return;
 if(buffer_id >= node->buffer_count || node->buffer[buffer_id].name[0] == 0)
  return;
 tb = &node->buffer[buffer_id];
 text_length = strlen(text);
 if(pos > tb->length)
  pos = tb->length;
 if(pos + length > tb->length)
  length = tb->length - pos;
 buf = tb->text;
 if(tb->length + text_length - length > tb->allocated)
 {
  buf = realloc(buf, tb->length + text_length - length + 4096);
  tb->allocated = tb->length + text_length - length + 4096;
 }
 if(text_length < length)
 {
  memmove(buf + pos + text_length, buf + pos + length, tb->length - (pos + length));
  memcpy(buf + pos, text, text_length);
 }
 else
 {
  memmove(buf + pos + text_length, buf + pos + length, tb->length - pos);
  memcpy(buf + pos, text, text_length);
 }
 tb->length += (int) text_length - length;
 buf[tb->length] = '\0';
 if(tb->allocated > 4096 * 8 && tb->allocated * 2 > tb->length)
 {
  buf = realloc(buf, tb->length + 4096);
  tb->allocated = tb->length + 4096;
 }
 tb->text = buf;
 count = vs_get_subscript_count(tb->subscribers);
 for(i = 0; i < count; i++)
 {
  vs_set_subscript_session(tb->subscribers, i);
  verse_send_t_text_set(node_id, buffer_id, pos, length, text);
 }
 vs_reset_subscript_session();
}

variable_types:
pos
unsigned int

variable_types:
length
unsigned int

variable_types:
text
char *

variable_types: struct VSTextBuffer { char name[16]; char *text; unsigned long length; unsigned long allocated; void *subscribers; } *

variable_types:
buf
char *

user_defined_types: enum VNodeType { V_NT_OBJECT=0, V_NT_GEOMETRY=1, V_NT_MATERIAL=2, V_NT_BITMAP=3, V_NT_TEXT=4, V_NT_CURVE=5, V_NT_AUDIO=6, V_NT_NUM_TYPES=7, V_NT_SYSTEM=expr, V_NT_NUM_TYPES_NETPACK=expr }


decompiled_code:
__int64 __fastcall callback_send_t_buffer_subscribe(__int64 a1, unsigned int a2, unsigned __int16 a3)
{
unsigned int v3; // er13
__int64 result; // rax
__int64 v6; // rbp
__int64 v7; // rbx
unsigned __int64 v8; // rcx
unsigned int v9; // er15
__int64 v10; // r14
__int64 v11; // rdx
__int64 v12; // r8

v3 = a3;
result = vs_get_node(a2, 4LL);
if ( result )
{
v6 = result;
result = a3;
if ( (unsigned int)a3 < *(_DWORD *)(v6 + 568) )
{
v7 = 48LL * a3;
result = v7 + *(_QWORD *)(v6 + 560);
if ( *(_BYTE *)result )
{
result = vs_add_new_subscriptor(*(_QWORD *)(result + 40));
if ( (_DWORD)result )
{
result = v7 + *(_QWORD *)(v6 + 560);
v8 = *(_QWORD *)(result + 24);
if ( v8 )
{
v9 = 0;
v10 = 0LL;
do
{
v11 = v9;
v9 += 1450;
v12 = *(_QWORD *)(result + 16) + v10;
v10 = v9;
if ( v9 > v8 )
verse_send_t_text_set(a2, v3, v11, (unsigned int)(v8 - v11), v12);
else
verse_send_t_text_set(a2, v3, v11, 1450LL, v12);
result = v7 + *(_QWORD *)(v6 + 560);
v8 = *(_QWORD *)(result + 24);
}
while ( v9 < v8 );
}
}
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, unsigned int a2, unsigned __int16 a3)
{
unsigned int v3; // er13
__int64 result; // rax
__int64 v6; // rbp
__int64 v7; // rbx
unsigned __int64 v8; // rcx
unsigned int v9; // er15
__int64 v10; // r14
__int64 v11; // rdx
__int64 v12; // r8

v3 = a3;
result = vs_get_node(a2, 4LL);
if ( result )
{
v6 = result;
result = a3;
if ( (unsigned int)a3 < *(_DWORD *)(v6 + 568) )
{
v7 = 48LL * a3;
result = v7 + *(_QWORD *)(v6 + 560);
if ( *(_BYTE *)result )
{
result = vs_add_new_subscriptor(*(_QWORD *)(result + 40));
if ( (_DWORD)result )
{
result = v7 + *(_QWORD *)(v6 + 560);
v8 = *(_QWORD *)(result + 24);
if ( v8 )
{
v9 = 0;
v10 = 0LL;
do
{
v11 = v9;
v9 += 1450;
v12 = *(_QWORD *)(result + 16) + v10;
v10 = v9;
if ( v9 > v8 )
verse_send_t_text_set(a2, v3, v11, (unsigned int)(v8 - v11), v12);
else
verse_send_t_text_set(a2, v3, v11, 1450LL, v12);
result = v7 + *(_QWORD *)(v6 + 560);
v8 = *(_QWORD *)(result + 24);
}
while ( v9 < v8 );
}
}
}
}
}
return result;
}

original_code:
static void callback_send_t_buffer_subscribe(void *user, VNodeID node_id, VBufferID buffer_id)
{
 VSNodeText *node;
 unsigned int i;
 node = (VSNodeText *)vs_get_node(node_id, V_NT_TEXT);
 if(node == ((void *)0))
  return;
 if(buffer_id >= node->buffer_count || node->buffer[buffer_id].name[0] == 0)
  return;
 if(vs_add_new_subscriptor(node->buffer[buffer_id].subscribers) == 0)
  return;
 for(i = 0; i < node->buffer[buffer_id].length; i += VN_T_MAX_TEXT_CMD_SIZE)
 {
  if(i + VN_T_MAX_TEXT_CMD_SIZE > node->buffer[buffer_id].length)
   verse_send_t_text_set(node_id, buffer_id, i, node->buffer[buffer_id].length - i, &node->buffer[buffer_id].text[i]);
  else
   verse_send_t_text_set(node_id, buffer_id, i, VN_T_MAX_TEXT_CMD_SIZE, &node->buffer[buffer_id].text[i]);
 }
}

canonical_original_code:
static void callback_send_t_buffer_subscribe(void *user, unsigned int node_id, unsigned short buffer_id)
{
 struct VSNodeText *node;
 unsigned int i;
 node = (struct VSNodeText *)vs_get_node(node_id, V_NT_TEXT);
 if(node == ((void *)0))
  return;
 if(buffer_id >= node->buffer_count || node->buffer[buffer_id].name[0] == 0)
  return;
 if(vs_add_new_subscriptor(node->buffer[buffer_id].subscribers) == 0)
  return;
 for(i = 0; i < node->buffer[buffer_id].length; i += VN_T_MAX_TEXT_CMD_SIZE)
 {
  if(i + VN_T_MAX_TEXT_CMD_SIZE > node->buffer[buffer_id].length)
   verse_send_t_text_set(node_id, buffer_id, i, node->buffer[buffer_id].length - i, &node->buffer[buffer_id].text[i]);
  else
   verse_send_t_text_set(node_id, buffer_id, i, VN_T_MAX_TEXT_CMD_SIZE, &node->buffer[buffer_id].text[i]);
 }
}


original_code:
static void callback_send_t_buffer_create(void *user, VNodeID node_id, VBufferID buffer_id, const char *name)
{
 VSNodeText *node;
 unsigned int i, count;
 node = (VSNodeText *)vs_get_node(node_id, V_NT_TEXT);
 if(node == ((void *)0))
  return;
 if(buffer_id >= node->buffer_count || node->buffer[buffer_id].name[0] != 0)
 {
  for(buffer_id = 0; buffer_id < node->buffer_count && node->buffer[buffer_id].name[0] != 0; buffer_id++)
   ;
  if(buffer_id == node->buffer_count)
  {
   node->buffer = realloc(node->buffer, (sizeof *node->buffer) * node->buffer_count);
   for(i = node->buffer_count; i < node->buffer_count + 16; i++)
    node->buffer[i].name[0] = 0;
   node->buffer_count = i;
  }
 }
 if(node->buffer[buffer_id].name[0] == 0)
 {
  node->buffer[buffer_id].allocated = 4096;
  node->buffer[buffer_id].text = malloc(node->buffer[buffer_id].allocated);
  node->buffer[buffer_id].length = 0;
  node->buffer[buffer_id].subscribers = vs_create_subscription_list();
 }
 for(i = 0; i < 15 && name[i] != 0; i++)
  node->buffer[buffer_id].name[i] = name[i];
 node->buffer[buffer_id].name[i] = 0;
 count = vs_get_subscript_count(node->head.subscribers);
 for(i = 0; i < count; i++)
 {
  vs_set_subscript_session(node->head.subscribers, i);
  verse_send_t_buffer_create(node_id, buffer_id, name);
 }
 vs_reset_subscript_session();
}

canonical_original_code:
static void callback_send_t_buffer_create(void *user, unsigned int node_id, unsigned short buffer_id, char *name)
{
 struct VSNodeText *node;
 unsigned int i; unsigned int count;
 node = (struct VSNodeText *)vs_get_node(node_id, V_NT_TEXT);
 if(node == ((void *)0))
  return;
 if(buffer_id >= node->buffer_count || node->buffer[buffer_id].name[0] != 0)
 {
  for(buffer_id = 0; buffer_id < node->buffer_count && node->buffer[buffer_id].name[0] != 0; buffer_id++)
   ;
  if(buffer_id == node->buffer_count)
  {
   node->buffer = realloc(node->buffer, (sizeof *node->buffer) * node->buffer_count);
   for(i = node->buffer_count; i < node->buffer_count + 16; i++)
    node->buffer[i].name[0] = 0;
   node->buffer_count = i;
  }
 }
 if(node->buffer[buffer_id].name[0] == 0)
 {
  node->buffer[buffer_id].allocated = 4096;
  node->buffer[buffer_id].text = malloc(node->buffer[buffer_id].allocated);
  node->buffer[buffer_id].length = 0;
  node->buffer[buffer_id].subscribers = vs_create_subscription_list();
 }
 for(i = 0; i < 15 && name[i] != 0; i++)
  node->buffer[buffer_id].name[i] = name[i];
 node->buffer[buffer_id].name[i] = 0;
 count = vs_get_subscript_count(node->head.subscribers);
 for(i = 0; i < count; i++)
 {
  vs_set_subscript_session(node->head.subscribers, i);
  verse_send_t_buffer_create(node_id, buffer_id, name);
 }
 vs_reset_subscript_session();
}

variable_types:
name
char *


decompiled_code:
unsigned int *__fastcall vs_t_create_node(unsigned int a1)
{
unsigned int *v1; // r12
_BYTE *v2; // rax
_BYTE *v3; // rdx
char v5[72]; // [rsp+0h] [rbp-48h] BYREF

v1 = (unsigned int *)malloc(0x240uLL);
vs_add_new_node(v1, 4LL);
sprintf(v5, "Text_Node_%u", *v1);
create_node_head(v1, v5, a1);
*((_BYTE *)v1 + 48) = 0;
v1[142] = 16;
v2 = malloc(0x300uLL);
*((_QWORD *)v1 + 70) = v2;
v3 = v2 + 768;
do
{
*v2 = 0;
v2 += 48;
}
while ( v2 != v3 );
return v1;
}

canonical_decompiled_code:
unsigned int *__fastcall func6(unsigned int a1)
{
unsigned int *v1; // r12
_BYTE *v2; // rax
_BYTE *v3; // rdx
char v5[72]; // [rsp+0h] [rbp-48h] BYREF

v1 = (unsigned int *)malloc(0x240uLL);
vs_add_new_node(v1, 4LL);
sprintf(v5, "Text_Node_%u", *v1);
create_node_head(v1, v5, a1);
*((_BYTE *)v1 + 48) = 0;
v1[142] = 16;
v2 = malloc(0x300uLL);
*((_QWORD *)v1 + 70) = v2;
v3 = v2 + 768;
do
{
*v2 = 0;
v2 += 48;
}
while ( v2 != v3 );
return v1;
}

original_code:
VSNodeText * vs_t_create_node(unsigned int owner)
{
 VSNodeText *node;
 char name[48];
 unsigned int i;
 node = malloc(sizeof *node);
 vs_add_new_node(&node->head, V_NT_TEXT);
 sprintf(name, "Text_Node_%u", node->head.id);
 create_node_head(&node->head, name, owner);
 node->language[0] = 0;
 node->buffer_count = 16;
 node->buffer = malloc((sizeof *node->buffer) * node->buffer_count);
 for(i = 0; i < node->buffer_count; i++)
  node->buffer[i].name[0] = 0;
 return node;
}

canonical_original_code:
struct VSNodeText *vs_t_create_node(unsigned int owner)
{
 struct VSNodeText *node;
 char name[48];
 unsigned int i;
 node = malloc(sizeof *node);
 vs_add_new_node(&node->head, V_NT_TEXT);
 sprintf(name, "Text_Node_%u", node->head.id);
 create_node_head(&node->head, name, owner);
 node->language[0] = 0;
 node->buffer_count = 16;
 node->buffer = malloc((sizeof *node->buffer) * node->buffer_count);
 for(i = 0; i < node->buffer_count; i++)
  node->buffer[i].name[0] = 0;
 return node;
}

variable_types:
owner
unsigned int

variable_types:
name
char [48]

return_type: struct VSNodeText { struct VSNodeHead { unsigned int id; enum VNodeType { V_NT_OBJECT=0, V_NT_GEOMETRY=1, V_NT_MATERIAL=2, V_NT_BITMAP=3, V_NT_TEXT=4, V_NT_CURVE=5, V_NT_AUDIO=6, V_NT_NUM_TYPES=7, V_NT_SYSTEM=expr, V_NT_NUM_TYPES_NETPACK=expr } type; unsigned int owner; char *name; void *tag_groups; unsigned short group_count; void *subscribers; } head; char language[512]; struct VSTextBuffer { char name[16]; char *text; unsigned long length; unsigned long allocated; void *subscribers; } *buffer; unsigned int buffer_count; } *


decompiled_code:
void __fastcall vs_t_destroy_node(void *ptr)
{
int v2; // eax
_BYTE *v3; // rdi
unsigned int v4; // ebp
__int64 v5; // rbx

destroy_node_head();
v2 = *((_DWORD *)ptr + 142);
v3 = (_BYTE *)*((_QWORD *)ptr + 70);
if ( v2 )
{
v4 = 0;
do
{
while ( 1 )
{
v5 = 48LL * v4;
if ( v3[v5] )
break;
if ( *((_DWORD *)ptr + 142) <= ++v4 )
goto LABEL_6;
}
++v4;
free(*(void **)&v3[v5 + 16]);
vs_destroy_subscription_list(*(_QWORD *)(*((_QWORD *)ptr + 70) + v5 + 40));
v3 = (_BYTE *)*((_QWORD *)ptr + 70);
}
while ( *((_DWORD *)ptr + 142) > v4 );
}
LABEL_6:
free(v3);
free(ptr);
}

canonical_decompiled_code:
void __fastcall func7(void *ptr)
{
int v2; // eax
_BYTE *v3; // rdi
unsigned int v4; // ebp
__int64 v5; // rbx

destroy_node_head();
v2 = *((_DWORD *)ptr + 142);
v3 = (_BYTE *)*((_QWORD *)ptr + 70);
if ( v2 )
{
v4 = 0;
do
{
while ( 1 )
{
v5 = 48LL * v4;
if ( v3[v5] )
break;
if ( *((_DWORD *)ptr + 142) <= ++v4 )
goto LABEL_6;
}
++v4;
free(*(void **)&v3[v5 + 16]);
vs_destroy_subscription_list(*(_QWORD *)(*((_QWORD *)ptr + 70) + v5 + 40));
v3 = (_BYTE *)*((_QWORD *)ptr + 70);
}
while ( *((_DWORD *)ptr + 142) > v4 );
}
LABEL_6:
free(v3);
free(ptr);
}

original_code:
void vs_t_destroy_node(VSNodeText *node)
{
 unsigned int i;
 destroy_node_head(&node->head);
 for(i = 0; i < node->buffer_count; i++)
 {
  if(node->buffer[i].name[0] != 0)
  {
   free(node->buffer[i].text);
   vs_destroy_subscription_list(node->buffer[i].subscribers);
  }
 }
 free(node->buffer);
 free(node);
}

canonical_original_code:
void vs_t_destroy_node(struct VSNodeText *node)
{
 unsigned int i;
 destroy_node_head(&node->head);
 for(i = 0; i < node->buffer_count; i++)
 {
  if(node->buffer[i].name[0] != 0)
  {
   free(node->buffer[i].text);
   vs_destroy_subscription_list(node->buffer[i].subscribers);
  }
 }
 free(node->buffer);
 free(node);
}


decompiled_code:
__int64 __fastcall vs_t_subscribe(unsigned int *a1)
{
__int64 result; // rax
unsigned int v2; // ebx
_BYTE *v3; // rdx
__int64 v4; // rsi

verse_send_t_language_set(*a1, a1 + 12);
result = a1[142];
if ( (_DWORD)result )
{
v2 = 0;
do
{
while ( 1 )
{
result = v2;
v3 = (_BYTE *)(*((_QWORD *)a1 + 70) + 48LL * v2);
if ( *v3 )
break;
if ( a1[142] <= ++v2 )
return result;
}
v4 = (unsigned __int16)v2++;
result = verse_send_t_buffer_create(*a1, v4, v3);
}
while ( a1[142] > v2 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(unsigned int *a1)
{
__int64 result; // rax
unsigned int v2; // ebx
_BYTE *v3; // rdx
__int64 v4; // rsi

verse_send_t_language_set(*a1, a1 + 12);
result = a1[142];
if ( (_DWORD)result )
{
v2 = 0;
do
{
while ( 1 )
{
result = v2;
v3 = (_BYTE *)(*((_QWORD *)a1 + 70) + 48LL * v2);
if ( *v3 )
break;
if ( a1[142] <= ++v2 )
return result;
}
v4 = (unsigned __int16)v2++;
result = verse_send_t_buffer_create(*a1, v4, v3);
}
while ( a1[142] > v2 );
}
return result;
}

original_code:
void vs_t_subscribe(VSNodeText *node)
{
 unsigned int i;
 verse_send_t_language_set(node->head.id, node->language);
 for(i = 0; i < node->buffer_count; i++)
  if(node->buffer[i].name[0] != 0)
   verse_send_t_buffer_create(node->head.id, i, node->buffer[i].name);
}

canonical_original_code:
void vs_t_subscribe(struct VSNodeText *node)
{
 unsigned int i;
 verse_send_t_language_set(node->head.id, node->language);
 for(i = 0; i < node->buffer_count; i++)
  if(node->buffer[i].name[0] != 0)
   verse_send_t_buffer_create(node->head.id, i, node->buffer[i].name);
}


decompiled_code:
__int64 __fastcall vs_t_unsubscribe(__int64 a1)
{
__int64 result; // rax
unsigned int v2; // ebx

result = *(unsigned int *)(a1 + 568);
if ( (_DWORD)result )
{
v2 = 0;
do
{
while ( 1 )
{
result = *(_QWORD *)(a1 + 560) + 48LL * v2;
if ( *(_BYTE *)result )
break;
if ( *(_DWORD *)(a1 + 568) <= ++v2 )
return result;
}
++v2;
result = vs_remove_subscriptor(*(_QWORD *)(result + 40));
}
while ( *(_DWORD *)(a1 + 568) > v2 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1)
{
__int64 result; // rax
unsigned int v2; // ebx

result = *(unsigned int *)(a1 + 568);
if ( (_DWORD)result )
{
v2 = 0;
do
{
while ( 1 )
{
result = *(_QWORD *)(a1 + 560) + 48LL * v2;
if ( *(_BYTE *)result )
break;
if ( *(_DWORD *)(a1 + 568) <= ++v2 )
return result;
}
++v2;
result = vs_remove_subscriptor(*(_QWORD *)(result + 40));
}
while ( *(_DWORD *)(a1 + 568) > v2 );
}
return result;
}

original_code:
void vs_t_unsubscribe(VSNodeText *node)
{
 unsigned int i;
 for(i = 0; i < node->buffer_count; i++)
  if(node->buffer[i].name[0] != 0)
   vs_remove_subscriptor(node->buffer[i].subscribers);
}

canonical_original_code:
void vs_t_unsubscribe(struct VSNodeText *node)
{
 unsigned int i;
 for(i = 0; i < node->buffer_count; i++)
  if(node->buffer[i].name[0] != 0)
   vs_remove_subscriptor(node->buffer[i].subscribers);
}


decompiled_code:
__int64 vs_t_callback_init()
{
verse_callback_set(&verse_send_t_language_set, callback_send_t_language_set, 0LL);
verse_callback_set(&verse_send_t_buffer_create, callback_send_t_buffer_create, 0LL);
verse_callback_set(&verse_send_t_buffer_destroy, callback_send_t_buffer_destroy, 0LL);
verse_callback_set(&verse_send_t_buffer_subscribe, callback_send_t_buffer_subscribe, 0LL);
verse_callback_set(&verse_send_t_buffer_unsubscribe, callback_send_t_buffer_unsubscribe, 0LL);
return verse_callback_set(&verse_send_t_text_set, callback_send_t_text_set, 0LL);
}

canonical_decompiled_code:
__int64 func10()
{
verse_callback_set(&verse_send_t_language_set, callback_send_t_language_set, 0LL);
verse_callback_set(&verse_send_t_buffer_create, callback_send_t_buffer_create, 0LL);
verse_callback_set(&verse_send_t_buffer_destroy, callback_send_t_buffer_destroy, 0LL);
verse_callback_set(&verse_send_t_buffer_subscribe, callback_send_t_buffer_subscribe, 0LL);
verse_callback_set(&verse_send_t_buffer_unsubscribe, callback_send_t_buffer_unsubscribe, 0LL);
return verse_callback_set(&verse_send_t_text_set, callback_send_t_text_set, 0LL);
}

original_code:
void vs_t_callback_init(void)
{
 verse_callback_set(verse_send_t_language_set, callback_send_t_language_set, ((void *)0));
 verse_callback_set(verse_send_t_buffer_create, callback_send_t_buffer_create, ((void *)0));
 verse_callback_set(verse_send_t_buffer_destroy, callback_send_t_buffer_destroy, ((void *)0));
 verse_callback_set(verse_send_t_buffer_subscribe, callback_send_t_buffer_subscribe, ((void *)0));
 verse_callback_set(verse_send_t_buffer_unsubscribe, callback_send_t_buffer_unsubscribe, ((void *)0));
 verse_callback_set(verse_send_t_text_set, callback_send_t_text_set, ((void *)0));
}

canonical_original_code:
void vs_t_callback_init()
{
 verse_callback_set(verse_send_t_language_set, callback_send_t_language_set, ((void *)0));
 verse_callback_set(verse_send_t_buffer_create, callback_send_t_buffer_create, ((void *)0));
 verse_callback_set(verse_send_t_buffer_destroy, callback_send_t_buffer_destroy, ((void *)0));
 verse_callback_set(verse_send_t_buffer_subscribe, callback_send_t_buffer_subscribe, ((void *)0));
 verse_callback_set(verse_send_t_buffer_unsubscribe, callback_send_t_buffer_unsubscribe, ((void *)0));
 verse_callback_set(verse_send_t_text_set, callback_send_t_text_set, ((void *)0));
}


decompiled_code:
__int64 __fastcall callback_send_node_index_subscribe(__int64 a1, int a2)
{
__int64 v2; // r14
int v3; // er12
__int64 v4; // rdi
__int64 result; // rax
unsigned int v6; // ebx
__int64 v7; // rax
bool v8; // zf
unsigned int *v9; // rax
__int64 v10; // rdi
int v11; // [rsp+Ch] [rbp-3Ch]

v2 = 0LL;
v3 = 1;
do
{
while ( (v3 & a2) == 0 )
{
v4 = qword_5F0[v2++];
v3 *= 2;
result = vs_remove_subscriptor(v4);
if ( v2 == 7 )
return result;
}
if ( (_DWORD)qword_5E8 )
{
v6 = 0;
while ( 1 )
{
v7 = *((_QWORD *)VSNodeStorage + v6);
if ( !v7 || *(_DWORD *)(v7 + 4) != (_DWORD)v2 )
goto LABEL_6;
v11 = *(_DWORD *)(v7 + 8);
v8 = v11 == (unsigned int)verse_session_get_avatar();
v9 = (unsigned int *)*((_QWORD *)VSNodeStorage + v6);
if ( v8 )
{
verse_send_node_create(*v9, (unsigned int)v2, 1LL);
LABEL_6:
if ( (unsigned int)qword_5E8 <= ++v6 )
break;
}
else
{
++v6;
verse_send_node_create(*v9, (unsigned int)v2, 0LL);
if ( (unsigned int)qword_5E8 <= v6 )
break;
}
}
}
v10 = qword_5F0[v2++];
v3 *= 2;
result = vs_add_new_subscriptor(v10);
}
while ( v2 != 7 );
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, int a2)
{
__int64 v2; // r14
int v3; // er12
__int64 v4; // rdi
__int64 result; // rax
unsigned int v6; // ebx
__int64 v7; // rax
bool v8; // zf
unsigned int *v9; // rax
__int64 v10; // rdi
int v11; // [rsp+Ch] [rbp-3Ch]

v2 = 0LL;
v3 = 1;
do
{
while ( (v3 & a2) == 0 )
{
v4 = qword_5F0[v2++];
v3 *= 2;
result = vs_remove_subscriptor(v4);
if ( v2 == 7 )
return result;
}
if ( (_DWORD)qword_5E8 )
{
v6 = 0;
while ( 1 )
{
v7 = *((_QWORD *)VSNodeStorage + v6);
if ( !v7 || *(_DWORD *)(v7 + 4) != (_DWORD)v2 )
goto LABEL_6;
v11 = *(_DWORD *)(v7 + 8);
v8 = v11 == (unsigned int)verse_session_get_avatar();
v9 = (unsigned int *)*((_QWORD *)VSNodeStorage + v6);
if ( v8 )
{
verse_send_node_create(*v9, (unsigned int)v2, 1LL);
LABEL_6:
if ( (unsigned int)qword_5E8 <= ++v6 )
break;
}
else
{
++v6;
verse_send_node_create(*v9, (unsigned int)v2, 0LL);
if ( (unsigned int)qword_5E8 <= v6 )
break;
}
}
}
v10 = qword_5F0[v2++];
v3 *= 2;
result = vs_add_new_subscriptor(v10);
}
while ( v2 != 7 );
return result;
}

original_code:
static void callback_send_node_index_subscribe(void *user_data, uint32 mask)
{
 unsigned int i, j, pow = 1;
 for(i = 0; i < V_NT_NUM_TYPES; i++, pow <<= 1)
 {
  if((mask & pow) != 0)
  {
   for(j = 0; j < VSNodeStorage.node_length; j++)
   {
    if(VSNodeStorage.nodes[j] != ((void *)0) && VSNodeStorage.nodes[j]->type == (VNodeType)i)
    {
     if(VSNodeStorage.nodes[j]->owner == verse_session_get_avatar())
      verse_send_node_create(VSNodeStorage.nodes[j]->id, i, VN_OWNER_MINE);
     else
      verse_send_node_create(VSNodeStorage.nodes[j]->id, i, VN_OWNER_OTHER);
    }
   }
   vs_add_new_subscriptor(VSNodeStorage.list[i]);
  }
  else
   vs_remove_subscriptor(VSNodeStorage.list[i]);
 }
}

canonical_original_code:
static void callback_send_node_index_subscribe(void *user_data, unsigned int mask)
{
 unsigned int i; unsigned int j; unsigned int pow = 1;
 for(i = 0; i < V_NT_NUM_TYPES; i++, pow <<= 1)
 {
  if((mask & pow) != 0)
  {
   for(j = 0; j < VSNodeStorage.node_length; j++)
   {
    if(VSNodeStorage.nodes[j] != ((void *)0) && VSNodeStorage.nodes[j]->type == (enum VNodeType)i)
    {
     if(VSNodeStorage.nodes[j]->owner == verse_session_get_avatar())
      verse_send_node_create(VSNodeStorage.nodes[j]->id, i, VN_OWNER_MINE);
     else
      verse_send_node_create(VSNodeStorage.nodes[j]->id, i, VN_OWNER_OTHER);
    }
   }
   vs_add_new_subscriptor(VSNodeStorage.list[i]);
  }
  else
   vs_remove_subscriptor(VSNodeStorage.list[i]);
 }
}

variable_types:
mask
unsigned int

variable_types:
j
unsigned int

variable_types:
pow
unsigned int


decompiled_code:
__int64 vs_init_node_storage()
{
const char *v0; // rbx
__int64 result; // rax

v0 = (const char *)qword_5F0;
VSNodeStorage = malloc(0x80uLL);
*(_QWORD *)VSNodeStorage = 0LL;
qword_5E8 = 0x1000000000LL;
do
{
result = vs_create_subscription_list();
v0 += 8;
*((_QWORD *)v0 - 1) = result;
}
while ( v0 != "vs_node_storage.c Can't handle node_destroy for type %d--not implemented" );
return result;
}

canonical_decompiled_code:
__int64 func1()
{
const char *v0; // rbx
__int64 result; // rax

v0 = (const char *)qword_5F0;
VSNodeStorage = malloc(0x80uLL);
*(_QWORD *)VSNodeStorage = 0LL;
qword_5E8 = 0x1000000000LL;
do
{
result = vs_create_subscription_list();
v0 += 8;
*((_QWORD *)v0 - 1) = result;
}
while ( v0 != "vs_node_storage.c Can't handle node_destroy for type %d--not implemented" );
return result;
}

original_code:
void vs_init_node_storage(void)
{
 unsigned int i;
 VSNodeStorage.nodes = malloc((sizeof *VSNodeStorage.nodes) * 16);
 VSNodeStorage.nodes[0] = ((void *)0);
 VSNodeStorage.node_length = 0;
 VSNodeStorage.node_allocated = 16;
 for(i = 0; i < V_NT_NUM_TYPES; i++)
  VSNodeStorage.list[i] = vs_create_subscription_list();
}

canonical_original_code:
void vs_init_node_storage()
{
 unsigned int i;
 VSNodeStorage.nodes = malloc((sizeof *VSNodeStorage.nodes) * 16);
 VSNodeStorage.nodes[0] = ((void *)0);
 VSNodeStorage.node_length = 0;
 VSNodeStorage.node_allocated = 16;
 for(i = 0; i < V_NT_NUM_TYPES; i++)
  VSNodeStorage.list[i] = vs_create_subscription_list();
}


decompiled_code:
__int64 __fastcall vs_add_new_node(unsigned int *a1, unsigned int a2)
{
unsigned int v2; // er12
__int64 v3; // rbx
unsigned int v4; // eax
char *v5; // rbp
__int64 v6; // r15
__int64 result; // rax

v2 = 0;
v3 = 0LL;
v4 = qword_5E8;
v5 = (char *)VSNodeStorage;
if ( (_DWORD)qword_5E8 )
{
while ( *(_QWORD *)((char *)VSNodeStorage + v3) )
{
++v2;
v3 += 8LL;
if ( v2 == (_DWORD)qword_5E8 )
{
v3 = 8LL * v2;
goto LABEL_9;
}
}
v6 = HIDWORD(qword_5E8);
if ( HIDWORD(qword_5E8) <= v2 )
goto LABEL_12;
}
else
{
LABEL_9:
v6 = HIDWORD(qword_5E8);
if ( HIDWORD(qword_5E8) > v2 )
{
*(_QWORD *)((char *)VSNodeStorage + v3) = a1;
goto LABEL_11;
}
LABEL_12:
HIDWORD(qword_5E8) = v6 + 16;
VSNodeStorage = realloc(VSNodeStorage, 8LL * (unsigned int)(v6 + 16));
v5 = (char *)VSNodeStorage;
if ( (unsigned int)v6 < HIDWORD(qword_5E8) )
memset((char *)VSNodeStorage + 8 * v6, 0, 8LL * (unsigned int)(HIDWORD(qword_5E8) - 1 - v6) + 8);
v4 = qword_5E8;
}
*(_QWORD *)&v5[v3] = a1;
if ( v2 >= v4 )
LABEL_11:
LODWORD(qword_5E8) = v2 + 1;
*a1 = v2;
result = v2;
a1[1] = a2;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(unsigned int *a1, unsigned int a2)
{
unsigned int v2; // er12
__int64 v3; // rbx
unsigned int v4; // eax
char *v5; // rbp
__int64 v6; // r15
__int64 result; // rax

v2 = 0;
v3 = 0LL;
v4 = qword_5E8;
v5 = (char *)VSNodeStorage;
if ( (_DWORD)qword_5E8 )
{
while ( *(_QWORD *)((char *)VSNodeStorage + v3) )
{
++v2;
v3 += 8LL;
if ( v2 == (_DWORD)qword_5E8 )
{
v3 = 8LL * v2;
goto LABEL_9;
}
}
v6 = HIDWORD(qword_5E8);
if ( HIDWORD(qword_5E8) <= v2 )
goto LABEL_12;
}
else
{
LABEL_9:
v6 = HIDWORD(qword_5E8);
if ( HIDWORD(qword_5E8) > v2 )
{
*(_QWORD *)((char *)VSNodeStorage + v3) = a1;
goto LABEL_11;
}
LABEL_12:
HIDWORD(qword_5E8) = v6 + 16;
VSNodeStorage = realloc(VSNodeStorage, 8LL * (unsigned int)(v6 + 16));
v5 = (char *)VSNodeStorage;
if ( (unsigned int)v6 < HIDWORD(qword_5E8) )
memset((char *)VSNodeStorage + 8 * v6, 0, 8LL * (unsigned int)(HIDWORD(qword_5E8) - 1 - v6) + 8);
v4 = qword_5E8;
}
*(_QWORD *)&v5[v3] = a1;
if ( v2 >= v4 )
LABEL_11:
LODWORD(qword_5E8) = v2 + 1;
*a1 = v2;
result = v2;
a1[1] = a2;
return result;
}

original_code:
unsigned int vs_add_new_node(VSNodeHead *node, VNodeType type)
{
 unsigned int i, j;
 for(i = 0; i < VSNodeStorage.node_length && VSNodeStorage.nodes[i] != ((void *)0); i++);
 if(i >= VSNodeStorage.node_allocated)
 {
  j = VSNodeStorage.node_allocated;
  VSNodeStorage.node_allocated += 16;
  VSNodeStorage.nodes = realloc(VSNodeStorage.nodes, (sizeof *VSNodeStorage.nodes) * VSNodeStorage.node_allocated);
  while(j < VSNodeStorage.node_allocated)
   VSNodeStorage.nodes[j++] = ((void *)0);
 }
 VSNodeStorage.nodes[i] = node;
 if(i >= VSNodeStorage.node_length)
  VSNodeStorage.node_length = i + 1;
 node->id = i;
 node->type = type;
 return node->id;
}

canonical_original_code:
unsigned int vs_add_new_node(struct VSNodeHead *node, enum VNodeType type)
{
 unsigned int i; unsigned int j;
 for(i = 0; i < VSNodeStorage.node_length && VSNodeStorage.nodes[i] != ((void *)0); i++);
 if(i >= VSNodeStorage.node_allocated)
 {
  j = VSNodeStorage.node_allocated;
  VSNodeStorage.node_allocated += 16;
  VSNodeStorage.nodes = realloc(VSNodeStorage.nodes, (sizeof *VSNodeStorage.nodes) * VSNodeStorage.node_allocated);
  while(j < VSNodeStorage.node_allocated)
   VSNodeStorage.nodes[j++] = ((void *)0);
 }
 VSNodeStorage.nodes[i] = node;
 if(i >= VSNodeStorage.node_length)
  VSNodeStorage.node_length = i + 1;
 node->id = i;
 node->type = type;
 return node->id;
}

variable_types: struct VSNodeHead { unsigned int id; enum VNodeType { V_NT_OBJECT=0, V_NT_GEOMETRY=1, V_NT_MATERIAL=2, V_NT_BITMAP=3, V_NT_TEXT=4, V_NT_CURVE=5, V_NT_AUDIO=6, V_NT_NUM_TYPES=7, V_NT_SYSTEM=expr, V_NT_NUM_TYPES_NETPACK=expr } type; unsigned int owner; char *name; void *tag_groups; unsigned short group_count; void *subscribers; } *

return_type: unsigned int


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

result = 0LL;
if ( (unsigned int)qword_5E8 > a1 )
{
result = *((_QWORD *)VSNodeStorage + a1);
if ( result )
{
if ( *(_DWORD *)(result + 4) != a2 )
result = 0LL;
}
}
return result;
}

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

result = 0LL;
if ( (unsigned int)qword_5E8 > a1 )
{
result = *((_QWORD *)VSNodeStorage + a1);
if ( result )
{
if ( *(_DWORD *)(result + 4) != a2 )
result = 0LL;
}
}
return result;
}

original_code:
VSNodeHead *vs_get_node(unsigned int node_id, VNodeType type)
{
 if(VSNodeStorage.node_length > node_id)
 {
  VSNodeHead *node = VSNodeStorage.nodes[node_id];
  if(node != ((void *)0) && node->type == type)
   return node;
 }
 return ((void *)0);
}

canonical_original_code:
struct VSNodeHead *vs_get_node(unsigned int node_id, enum VNodeType type)
{
 if(VSNodeStorage.node_length > node_id)
 {
  struct VSNodeHead *node = VSNodeStorage.nodes[node_id];
  if(node != ((void *)0) && node->type == type)
   return node;
 }
 return ((void *)0);
}

return_type: struct VSNodeHead { unsigned int id; enum VNodeType { V_NT_OBJECT=0, V_NT_GEOMETRY=1, V_NT_MATERIAL=2, V_NT_BITMAP=3, V_NT_TEXT=4, V_NT_CURVE=5, V_NT_AUDIO=6, V_NT_NUM_TYPES=7, V_NT_SYSTEM=expr, V_NT_NUM_TYPES_NETPACK=expr } type; unsigned int owner; char *name; void *tag_groups; unsigned short group_count; void *subscribers; } *


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

result = 0LL;
if ( (unsigned int)qword_5E8 > a1 )
result = *((_QWORD *)VSNodeStorage + a1);
return result;
}

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

result = 0LL;
if ( (unsigned int)qword_5E8 > a1 )
result = *((_QWORD *)VSNodeStorage + a1);
return result;
}

canonical_original_code:
struct VSNodeHead *vs_get_node_head(unsigned int node_id)
{
 if(VSNodeStorage.node_length > node_id)
  return VSNodeStorage.nodes[node_id];
 return ((void *)0);
}


decompiled_code:
int __fastcall callback_send_node_destroy(__int64 a1, unsigned int a2)
{
__int64 v2; // rax
__int64 v4; // rdx
__int64 v5; // rbp
__int64 v6; // rbp
int v7; // er13
unsigned int i; // ebx
__int64 v9; // rsi

v2 = vs_get_node_head(a2);
if ( v2 )
{
*((_QWORD *)VSNodeStorage + a2) = 0LL;
v4 = *(unsigned int *)(v2 + 4);
v5 = (unsigned int)v4;
switch ( (int)v4 )
{
case 0:
vs_o_destroy_node();
goto LABEL_4;
case 1:
vs_g_destroy_node();
goto LABEL_4;
case 2:
vs_m_destroy_node();
goto LABEL_4;
case 3:
vs_b_destroy_node();
goto LABEL_4;
case 4:
vs_t_destroy_node();
goto LABEL_4;
case 5:
case 6:
vs_c_destroy_node();
LABEL_4:
v6 = v5 + 2;
v7 = vs_get_subscript_count(*(&VSNodeStorage + v6));
if ( v7 )
{
for ( i = 0; i != v7; ++i )
{
v9 = i;
vs_set_subscript_session(*(&VSNodeStorage + v6), v9);
verse_send_node_destroy(a2);
}
}
LODWORD(v2) = vs_reset_subscript_session();
break;
default:
LODWORD(v2) = fprintf(stderr, "vs_node_storage.c Can't handle node_destroy for type %d--not implemented", v4);
break;
}
}
return v2;
}

canonical_decompiled_code:
int __fastcall func5(__int64 a1, unsigned int a2)
{
__int64 v2; // rax
__int64 v4; // rdx
__int64 v5; // rbp
__int64 v6; // rbp
int v7; // er13
unsigned int i; // ebx
__int64 v9; // rsi

v2 = func4(a2);
if ( v2 )
{
*((_QWORD *)VSNodeStorage + a2) = 0LL;
v4 = *(unsigned int *)(v2 + 4);
v5 = (unsigned int)v4;
switch ( (int)v4 )
{
case 0:
vs_o_destroy_node();
goto LABEL_4;
case 1:
vs_g_destroy_node();
goto LABEL_4;
case 2:
vs_m_destroy_node();
goto LABEL_4;
case 3:
vs_b_destroy_node();
goto LABEL_4;
case 4:
vs_t_destroy_node();
goto LABEL_4;
case 5:
case 6:
vs_c_destroy_node();
LABEL_4:
v6 = v5 + 2;
v7 = vs_get_subscript_count(*(&VSNodeStorage + v6));
if ( v7 )
{
for ( i = 0; i != v7; ++i )
{
v9 = i;
vs_set_subscript_session(*(&VSNodeStorage + v6), v9);
verse_send_node_destroy(a2);
}
}
LODWORD(v2) = vs_reset_subscript_session();
break;
default:
LODWORD(v2) = fprintf(stderr, "vs_node_storage.c Can't handle node_destroy for type %d--not implemented", v4);
break;
}
}
return v2;
}

original_code:
void callback_send_node_destroy(void *user_data, VNodeID node_id)
{
 unsigned int count, i;
 VSNodeHead *node;
 VNodeType type;
 node = vs_get_node_head(node_id);
 if(node == ((void *)0))
  return;
 VSNodeStorage.nodes[node_id] = ((void *)0);
 type = node->type;
 switch(type)
 {
  case V_NT_OBJECT :
   vs_o_destroy_node(node);
  break;
  case V_NT_GEOMETRY :
   vs_g_destroy_node(node);
  break;
  case V_NT_MATERIAL :
   vs_m_destroy_node(node);
  break;
  case V_NT_BITMAP :
   vs_b_destroy_node(node);
  break;
  case V_NT_TEXT :
   vs_t_destroy_node(node);
  break;
  case V_NT_CURVE :
   vs_c_destroy_node(node);
  break;
  case V_NT_AUDIO :
   vs_c_destroy_node(node);
  break;
  default:
   fprintf(stderr, "vs_node_storage.c" " Can't handle node_destroy for type %d--not implemented", type);
  return;
 }
 count = vs_get_subscript_count(VSNodeStorage.list[type]);
 for(i = 0; i < count; i++)
 {
  vs_set_subscript_session(VSNodeStorage.list[type], i);
  verse_send_node_destroy(node_id);
 }
 vs_reset_subscript_session();
}

canonical_original_code:
void callback_send_node_destroy(void *user_data, unsigned int node_id)
{
 unsigned int count; unsigned int i;
 struct VSNodeHead *node;
 enum VNodeType type;
 node = vs_get_node_head(node_id);
 if(node == ((void *)0))
  return;
 VSNodeStorage.nodes[node_id] = ((void *)0);
 type = node->type;
 switch(type)
 {
  case V_NT_OBJECT :
   vs_o_destroy_node(node);
  break;
  case V_NT_GEOMETRY :
   vs_g_destroy_node(node);
  break;
  case V_NT_MATERIAL :
   vs_m_destroy_node(node);
  break;
  case V_NT_BITMAP :
   vs_b_destroy_node(node);
  break;
  case V_NT_TEXT :
   vs_t_destroy_node(node);
  break;
  case V_NT_CURVE :
   vs_c_destroy_node(node);
  break;
  case V_NT_AUDIO :
   vs_c_destroy_node(node);
  break;
  default:
   fprintf(stderr, "vs_node_storage.c" " Can't handle node_destroy for type %d--not implemented", type);
  return;
 }
 count = vs_get_subscript_count(VSNodeStorage.list[type]);
 for(i = 0; i < count; i++)
 {
  vs_set_subscript_session(VSNodeStorage.list[type], i);
  verse_send_node_destroy(node_id);
 }
 vs_reset_subscript_session();
}

variable_types: enum VNodeType { V_NT_OBJECT=0, V_NT_GEOMETRY=1, V_NT_MATERIAL=2, V_NT_BITMAP=3, V_NT_TEXT=4, V_NT_CURVE=5, V_NT_AUDIO=6, V_NT_NUM_TYPES=7, V_NT_SYSTEM=expr, V_NT_NUM_TYPES_NETPACK=expr }


decompiled_code:
__int64 __fastcall vs_node_create(unsigned int a1, unsigned int a2)
{
unsigned int *v2; // rax
__int64 v3; // r13
unsigned int v4; // er15
int v5; // er14
unsigned int v6; // ebx

printf("vs_node_create(%u, %u)\n", a1, a2);
switch ( a2 )
{
case 0u:
v2 = (unsigned int *)vs_o_create_node(a1);
goto LABEL_3;
case 1u:
v2 = (unsigned int *)vs_g_create_node(a1);
goto LABEL_3;
case 2u:
v2 = (unsigned int *)vs_m_create_node(a1);
goto LABEL_3;
case 3u:
v2 = (unsigned int *)vs_b_create_node(a1);
goto LABEL_3;
case 4u:
v2 = (unsigned int *)vs_t_create_node(a1);
goto LABEL_3;
case 5u:
v2 = (unsigned int *)vs_c_create_node(a1);
goto LABEL_3;
case 6u:
v2 = (unsigned int *)vs_a_create_node(a1);
LABEL_3:
v3 = a2 + 2LL;
v4 = *v2;
v5 = vs_get_subscript_count(*(&VSNodeStorage + v3));
if ( !v5 )
return v4;
v6 = 0;
break;
default:
v4 = 0;
fprintf(stderr, "Can't create node of unknown type %u\n", a2);
return v4;
}
do
{
while ( 1 )
{
vs_set_subscript_session(*(&VSNodeStorage + v3), v6);
if ( (unsigned int)verse_session_get_avatar() == a1 )
break;
++v6;
verse_send_node_create(v4, a2, 0LL);
if ( v5 == v6 )
goto LABEL_8;
}
++v6;
verse_send_node_create(v4, a2, 1LL);
}
while ( v5 != v6 );
LABEL_8:
vs_reset_subscript_session();
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func6(unsigned int a1, unsigned int a2)
{
unsigned int *v2; // rax
__int64 v3; // r13
unsigned int v4; // er15
int v5; // er14
unsigned int v6; // ebx

printf("vs_node_create(%u, %u)\n", a1, a2);
switch ( a2 )
{
case 0u:
v2 = (unsigned int *)vs_o_create_node(a1);
goto LABEL_3;
case 1u:
v2 = (unsigned int *)vs_g_create_node(a1);
goto LABEL_3;
case 2u:
v2 = (unsigned int *)vs_m_create_node(a1);
goto LABEL_3;
case 3u:
v2 = (unsigned int *)vs_b_create_node(a1);
goto LABEL_3;
case 4u:
v2 = (unsigned int *)vs_t_create_node(a1);
goto LABEL_3;
case 5u:
v2 = (unsigned int *)vs_c_create_node(a1);
goto LABEL_3;
case 6u:
v2 = (unsigned int *)vs_a_create_node(a1);
LABEL_3:
v3 = a2 + 2LL;
v4 = *v2;
v5 = vs_get_subscript_count(*(&VSNodeStorage + v3));
if ( !v5 )
return v4;
v6 = 0;
break;
default:
v4 = 0;
fprintf(stderr, "Can't create node of unknown type %u\n", a2);
return v4;
}
do
{
while ( 1 )
{
vs_set_subscript_session(*(&VSNodeStorage + v3), v6);
if ( (unsigned int)verse_session_get_avatar() == a1 )
break;
++v6;
verse_send_node_create(v4, a2, 0LL);
if ( v5 == v6 )
goto LABEL_8;
}
++v6;
verse_send_node_create(v4, a2, 1LL);
}
while ( v5 != v6 );
LABEL_8:
vs_reset_subscript_session();
return v4;
}

original_code:
VNodeID vs_node_create(VNodeID owner_id, unsigned int type)
{
 unsigned int count, i;
 VSNodeHead *node;
 VNodeID node_id;
 printf("vs_node_create(%u, %u)\n", owner_id, type);
 switch(type)
 {
  case V_NT_OBJECT :
   node = vs_o_create_node(owner_id);
  break;
  case V_NT_GEOMETRY :
   node = vs_g_create_node(owner_id);
  break;
  case V_NT_MATERIAL :
   node = vs_m_create_node(owner_id);
  break;
  case V_NT_BITMAP :
   node = vs_b_create_node(owner_id);
  break;
  case V_NT_TEXT :
   node = vs_t_create_node(owner_id);
  break;
  case V_NT_CURVE :
   node = vs_c_create_node(owner_id);
  break;
  case V_NT_AUDIO :
   node = vs_a_create_node(owner_id);
  break;
  default:
   fprintf(stderr, "Can't create node of unknown type %u\n", type);
   return 0U;
 }
 node_id = node->id;
 count = vs_get_subscript_count(VSNodeStorage.list[type]);
 for(i = 0; i < count; i++)
 {
  vs_set_subscript_session(VSNodeStorage.list[type], i);
  if(owner_id != verse_session_get_avatar())
   verse_send_node_create(node_id, type, VN_OWNER_OTHER);
  else
   verse_send_node_create(node_id, type, VN_OWNER_MINE);
 }
 if(count != 0)
  vs_reset_subscript_session();
 return node_id;
}

canonical_original_code:
unsigned int vs_node_create(unsigned int owner_id, unsigned int type)
{
 unsigned int count; unsigned int i;
 struct VSNodeHead *node;
 unsigned int node_id;
 printf("vs_node_create(%u, %u)\n", owner_id, type);
 switch(type)
 {
  case V_NT_OBJECT :
   node = vs_o_create_node(owner_id);
  break;
  case V_NT_GEOMETRY :
   node = vs_g_create_node(owner_id);
  break;
  case V_NT_MATERIAL :
   node = vs_m_create_node(owner_id);
  break;
  case V_NT_BITMAP :
   node = vs_b_create_node(owner_id);
  break;
  case V_NT_TEXT :
   node = vs_t_create_node(owner_id);
  break;
  case V_NT_CURVE :
   node = vs_c_create_node(owner_id);
  break;
  case V_NT_AUDIO :
   node = vs_a_create_node(owner_id);
  break;
  default:
   fprintf(stderr, "Can't create node of unknown type %u\n", type);
   return 0U;
 }
 node_id = node->id;
 count = vs_get_subscript_count(VSNodeStorage.list[type]);
 for(i = 0; i < count; i++)
 {
  vs_set_subscript_session(VSNodeStorage.list[type], i);
  if(owner_id != verse_session_get_avatar())
   verse_send_node_create(node_id, type, VN_OWNER_OTHER);
  else
   verse_send_node_create(node_id, type, VN_OWNER_MINE);
 }
 if(count != 0)
  vs_reset_subscript_session();
 return node_id;
}

variable_types:
type
unsigned int


decompiled_code:
__int64 __fastcall callback_send_node_create(__int64 a1, __int64 a2, unsigned __int8 a3)
{
unsigned int v4; // eax

v4 = vs_get_avatar();
return vs_node_create(v4, a3);
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, __int64 a2, unsigned __int8 a3)
{
unsigned int v4; // eax

v4 = vs_get_avatar();
return func6(v4, a3);
}

original_code:
static void callback_send_node_create(void *user_data, VNodeID node_id, uint8 type, VNodeOwner owner_id)
{
 vs_node_create(vs_get_avatar(), type);
}

canonical_original_code:
static void callback_send_node_create(void *user_data, unsigned int node_id, unsigned char type, enum VNodeOwner owner_id)
{
 vs_node_create(vs_get_avatar(), type);
}

variable_types:
type
unsigned char

variable_types: enum VNodeOwner { VN_OWNER_OTHER=0, VN_OWNER_MINE=1 }


decompiled_code:
__int64 __fastcall vs_avatar_init(unsigned int a1)
{
return callback_send_tag_group_create(0LL, a1, 0xFFFFLL, "avatar");
}

canonical_decompiled_code:
__int64 __fastcall func8(unsigned int a1)
{
return callback_send_tag_group_create(0LL, a1, 0xFFFFLL, "avatar");
}

original_code:
void vs_avatar_init(VNodeID id, const char *name)
{
 callback_send_tag_group_create(((void *)0), id, (short) ~0u, "avatar");
}

canonical_original_code:
void vs_avatar_init(unsigned int id, char *name)
{
 callback_send_tag_group_create(((void *)0), id, (short) ~0u, "avatar");
}

variable_types:
id
unsigned int


decompiled_code:
unsigned __int64 __fastcall vs_reset_owner(int a1)
{
unsigned __int64 result; // rax
__int64 *v2; // rdx
char *v3; // rcx
__int64 v4; // rdx

result = (unsigned int)qword_5E8;
if ( (_DWORD)qword_5E8 )
{
v2 = (__int64 *)VSNodeStorage;
result = (unsigned __int64)VSNodeStorage + 8;
v3 = (char *)VSNodeStorage + 8 * (unsigned int)(qword_5E8 - 1) + 8;
while ( 1 )
{
v4 = *v2;
if ( v4 )
{
if ( *(_DWORD *)(v4 + 8) == a1 )
*(_DWORD *)(v4 + 8) = -1;
}
v2 = (__int64 *)result;
if ( (char *)result == v3 )
break;
result += 8LL;
}
}
return result;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func9(int a1)
{
unsigned __int64 result; // rax
__int64 *v2; // rdx
char *v3; // rcx
__int64 v4; // rdx

result = (unsigned int)qword_5E8;
if ( (_DWORD)qword_5E8 )
{
v2 = (__int64 *)VSNodeStorage;
result = (unsigned __int64)VSNodeStorage + 8;
v3 = (char *)VSNodeStorage + 8 * (unsigned int)(qword_5E8 - 1) + 8;
while ( 1 )
{
v4 = *v2;
if ( v4 )
{
if ( *(_DWORD *)(v4 + 8) == a1 )
*(_DWORD *)(v4 + 8) = -1;
}
v2 = (__int64 *)result;
if ( (char *)result == v3 )
break;
result += 8LL;
}
}
return result;
}

original_code:
void vs_reset_owner(VNodeID owner_id)
{
 unsigned int i;
 for(i = 0; i < VSNodeStorage.node_length; i++)
  if(VSNodeStorage.nodes[i] != ((void *)0))
   if(VSNodeStorage.nodes[i]->owner == owner_id)
    VSNodeStorage.nodes[i]->owner = ~0;
}

canonical_original_code:
void vs_reset_owner(unsigned int owner_id)
{
 unsigned int i;
 for(i = 0; i < VSNodeStorage.node_length; i++)
  if(VSNodeStorage.nodes[i] != ((void *)0))
   if(VSNodeStorage.nodes[i]->owner == owner_id)
    VSNodeStorage.nodes[i]->owner = ~0;
}

variable_types:
i
unsigned int


decompiled_code:
__int64 init_callback_node_storage()
{
verse_callback_set(&verse_send_node_index_subscribe, callback_send_node_index_subscribe, 0LL);
verse_callback_set(&verse_send_node_create, callback_send_node_create, 0LL);
return verse_callback_set(&verse_send_node_destroy, callback_send_node_destroy, 0LL);
}

canonical_decompiled_code:
__int64 func10()
{
verse_callback_set(&verse_send_node_index_subscribe, callback_send_node_index_subscribe, 0LL);
verse_callback_set(&verse_send_node_create, callback_send_node_create, 0LL);
return verse_callback_set(&verse_send_node_destroy, callback_send_node_destroy, 0LL);
}

original_code:
void init_callback_node_storage(void)
{
 verse_callback_set(verse_send_node_index_subscribe, callback_send_node_index_subscribe, ((void *)0));
 verse_callback_set(verse_send_node_create, callback_send_node_create, ((void *)0));
 verse_callback_set(verse_send_node_destroy, callback_send_node_destroy, ((void *)0));
}

canonical_original_code:
void init_callback_node_storage()
{
 verse_callback_set(verse_send_node_index_subscribe, callback_send_node_index_subscribe, ((void *)0));
 verse_callback_set(verse_send_node_create, callback_send_node_create, ((void *)0));
 verse_callback_set(verse_send_node_destroy, callback_send_node_destroy, ((void *)0));
}


displayGraph

decompiled_code:
int displayGraph()
{
const char **v0; // rbx
const char **v1; // rbx

puts("\nSommets:");
v0 = (const char **)nodeList;
if ( nodeList )
{
do
{
printf(" [%d]\t\t%s\n", *(unsigned int *)v0, v0[1]);
v0 = (const char **)v0[2];
}
while ( v0 );
}
puts("\nArcs:");
v1 = (const char **)edgeList;
if ( edgeList )
{
do
{
printf(" [%d]\t-> [%d] \t%s\n", *(unsigned int *)v1, *((unsigned int *)v1 + 1), v1[1]);
v1 = (const char **)v1[2];
}
while ( v1 );
}
return putchar(10);
}

canonical_decompiled_code:
int func0()
{
const char **v0; // rbx
const char **v1; // rbx

puts("\nSommets:");
v0 = (const char **)nodeList;
if ( nodeList )
{
do
{
printf(" [%d]\t\t%s\n", *(unsigned int *)v0, v0[1]);
v0 = (const char **)v0[2];
}
while ( v0 );
}
puts("\nArcs:");
v1 = (const char **)edgeList;
if ( edgeList )
{
do
{
printf(" [%d]\t-> [%d] \t%s\n", *(unsigned int *)v1, *((unsigned int *)v1 + 1), v1[1]);
v1 = (const char **)v1[2];
}
while ( v1 );
}
return putchar(10);
}

original_code:
void
displayGraph ( )
{
    printf ( "\nSommets:\n" );
    Node *node = nodeList;
    while ( node != ((void *)0) )
    {
        printf ( "   [%d]\t\t%s\n", node -> ID, node -> label );
        node = node -> next;
    }
    printf ( "\nArcs:\n" );
    Edge *edge = edgeList;
    while ( edge != ((void *)0) )
    {
        printf ( "   [%d]\t->  [%d] \t%s\n", edge -> nodeID, edge -> nodeID_, edge -> label );
        edge = edge -> next;
    }
    printf ( "\n" );
}

canonical_original_code:
void displayGraph()
{
    printf ( "\nSommets:\n" );
    struct _Node *node = nodeList;
    while ( node != ((void *)0) )
    {
        printf ( "   [%d]\t\t%s\n", node -> ID, node -> label );
        node = node -> next;
    }
    printf ( "\nArcs:\n" );
    struct _Edge *edge = edgeList;
    while ( edge != ((void *)0) )
    {
        printf ( "   [%d]\t->  [%d] \t%s\n", edge -> nodeID, edge -> nodeID_, edge -> label );
        edge = edge -> next;
    }
    printf ( "\n" );
}

variable_types: struct _Node { int ID; char *label; struct _Node *next; } *

variable_types: struct _Edge { int nodeID; int nodeID_; char *label; struct _Edge *next; } *


destroyGraph

decompiled_code:
void destroyGraph()
{
_QWORD *v0; // rbx
_QWORD *v1; // rax
void *v2; // rdi
_QWORD *v3; // rbx
_QWORD *v4; // rax
void *v5; // rdi

v0 = edgeList;
if ( edgeList )
{
do
{
v1 = v0;
v0 = (_QWORD *)v0[2];
v2 = (void *)v1[1];
if ( v2 )
free(v2);
if ( edgeList )
free(edgeList);
edgeList = v0;
}
while ( v0 );
}
v3 = nodeList;
if ( nodeList )
{
do
{
v4 = v3;
v3 = (_QWORD *)v3[2];
v5 = (void *)v4[1];
if ( v5 )
free(v5);
if ( nodeList )
free(nodeList);
nodeList = v3;
}
while ( v3 );
}
}

canonical_decompiled_code:
void func1()
{
_QWORD *v0; // rbx
_QWORD *v1; // rax
void *v2; // rdi
_QWORD *v3; // rbx
_QWORD *v4; // rax
void *v5; // rdi

v0 = edgeList;
if ( edgeList )
{
do
{
v1 = v0;
v0 = (_QWORD *)v0[2];
v2 = (void *)v1[1];
if ( v2 )
free(v2);
if ( edgeList )
free(edgeList);
edgeList = v0;
}
while ( v0 );
}
v3 = nodeList;
if ( nodeList )
{
do
{
v4 = v3;
v3 = (_QWORD *)v3[2];
v5 = (void *)v4[1];
if ( v5 )
free(v5);
if ( nodeList )
free(nodeList);
nodeList = v3;
}
while ( v3 );
}
}

original_code:
void
destroyGraph ( )
{
    Edge *nextEdge = ((void *)0);
    while ( edgeList != ((void *)0) )
    {
        nextEdge = edgeList -> next;
        if ( edgeList -> label != ((void *)0) )
            free ( edgeList -> label );
        if ( edgeList != ((void *)0) )
            free ( edgeList );
        edgeList = nextEdge;
    }
    Node *nextNode = ((void *)0);
    while ( nodeList != ((void *)0) )
    {
        nextNode = nodeList -> next;
        if ( nodeList -> label != ((void *)0) )
            free ( nodeList -> label );
        if ( nodeList != ((void *)0) )
            free ( nodeList );
        nodeList = nextNode;
    }
}

canonical_original_code:
void destroyGraph()
{
    struct _Edge *nextEdge = ((void *)0);
    while ( edgeList != ((void *)0) )
    {
        nextEdge = edgeList -> next;
        if ( edgeList -> label != ((void *)0) )
            free ( edgeList -> label );
        if ( edgeList != ((void *)0) )
            free ( edgeList );
        edgeList = nextEdge;
    }
    struct _Node *nextNode = ((void *)0);
    while ( nodeList != ((void *)0) )
    {
        nextNode = nodeList -> next;
        if ( nodeList -> label != ((void *)0) )
            free ( nodeList -> label );
        if ( nodeList != ((void *)0) )
            free ( nodeList );
        nodeList = nextNode;
    }
}

user_defined_types: struct _Edge { int nodeID; int nodeID_; char *label; struct _Edge *next; }

user_defined_types: struct _Node { int ID; char *label; struct _Node *next; }


createNode

decompiled_code:
char *__fastcall createNode(int a1, const char *a2)
{
__int64 v2; // rbx
char *result; // rax
int v4; // er12
void *v5; // rdi
char *v6; // rax
void *v7; // rax
int *v8; // rax

v2 = getNode();
if ( !v2 )
{
v7 = malloc(0x18uLL);
v2 = (__int64)v7;
if ( !v7 )
goto LABEL_10;
addNode(v7);
*(_DWORD *)v2 = a1;
}
result = (char *)strlen(a2);
v4 = (int)result;
if ( (_DWORD)result )
{
v5 = *(void **)(v2 + 8);
if ( v5 )
free(v5);
v6 = (char *)malloc(v4);
*(_QWORD *)(v2 + 8) = v6;
if ( v6 )
return strncpy(v6, a2, v4);
LABEL_10:
perror("malloc");
v8 = _errno_location();
exit(*v8);
}
return result;
}

canonical_decompiled_code:
char *__fastcall func2(int a1, const char *a2)
{
__int64 v2; // rbx
char *result; // rax
int v4; // er12
void *v5; // rdi
char *v6; // rax
void *v7; // rax
int *v8; // rax

v2 = getNode();
if ( !v2 )
{
v7 = malloc(0x18uLL);
v2 = (__int64)v7;
if ( !v7 )
goto LABEL_10;
addNode(v7);
*(_DWORD *)v2 = a1;
}
result = (char *)strlen(a2);
v4 = (int)result;
if ( (_DWORD)result )
{
v5 = *(void **)(v2 + 8);
if ( v5 )
free(v5);
v6 = (char *)malloc(v4);
*(_QWORD *)(v2 + 8) = v6;
if ( v6 )
return strncpy(v6, a2, v4);
LABEL_10:
perror("malloc");
v8 = _errno_location();
exit(*v8);
}
return result;
}

original_code:
void
createNode ( int ID, char *label )
{
    Node *node = getNode ( ID );
    if ( node == ((void *)0) )
    {
        node = ( Node * ) malloc ( sizeof ( Node ) );
        if ( node == ((void *)0) )
        {
            perror ( "malloc" );
            exit ( (*__errno_location ()) );
        }
        addNode ( node );
        node -> ID = ID;
    }
    int labelLength = strlen ( label );
    if ( labelLength )
    {
        if ( node -> label != ((void *)0) )
            free ( node -> label );
        node -> label = ( char * ) malloc ( sizeof ( char ) * labelLength );
        if ( node -> label == ((void *)0) )
        {
            perror ( "malloc" );
            exit ( (*__errno_location ()) );
        }
        strncpy ( node -> label, label, labelLength );
    }
}

canonical_original_code:
void createNode(int ID, char *label)
{
    struct _Node *node = getNode ( ID );
    if ( node == ((void *)0) )
    {
        node = ( struct _Node * ) malloc ( sizeof ( Node ) );
        if ( node == ((void *)0) )
        {
            perror ( "malloc" );
            exit ( (*__errno_location ()) );
        }
        addNode ( node );
        node -> ID = ID;
    }
    int labelLength = strlen ( label );
    if ( labelLength )
    {
        if ( node -> label != ((void *)0) )
            free ( node -> label );
        node -> label = ( char * ) malloc ( sizeof ( char ) * labelLength );
        if ( node -> label == ((void *)0) )
        {
            perror ( "malloc" );
            exit ( (*__errno_location ()) );
        }
        strncpy ( node -> label, label, labelLength );
    }
}

variable_types: ID int

variable_types:
label
char *

variable_types: labelLength int


createEdge

decompiled_code:
char *__fastcall createEdge(char *src, int a2, const char *a3, int a4, const char *a5)
{
void *v8; // rax
void *v9; // rbx
int v10; // eax
char *v11; // rax
int *v13; // rax
size_t n; // [rsp+8h] [rbp-40h]

v8 = malloc(0x18uLL);
if ( !v8 )
goto LABEL_6;
v9 = v8;
addEdge(v8);
v10 = strlen(src);
if ( v10 )
{
n = v10;
v11 = (char *)malloc(v10);
*((_QWORD *)v9 + 1) = v11;
if ( v11 )
{
strncpy(v11, src, n);
goto LABEL_5;
}
LABEL_6:
perror("malloc");
v13 = _errno_location();
exit(*v13);
}
LABEL_5:
*(_DWORD *)v9 = a2;
*((_DWORD *)v9 + 1) = a4;
*((_QWORD *)v9 + 2) = 0LL;
createNode(a2, a3);
return createNode(*((_DWORD *)v9 + 1), a5);
}

canonical_decompiled_code:
char *__fastcall func3(char *src, int a2, const char *a3, int a4, const char *a5)
{
void *v8; // rax
void *v9; // rbx
int v10; // eax
char *v11; // rax
int *v13; // rax
size_t n; // [rsp+8h] [rbp-40h]

v8 = malloc(0x18uLL);
if ( !v8 )
goto LABEL_6;
v9 = v8;
addEdge(v8);
v10 = strlen(src);
if ( v10 )
{
n = v10;
v11 = (char *)malloc(v10);
*((_QWORD *)v9 + 1) = v11;
if ( v11 )
{
strncpy(v11, src, n);
goto LABEL_5;
}
LABEL_6:
perror("malloc");
v13 = _errno_location();
exit(*v13);
}
LABEL_5:
*(_DWORD *)v9 = a2;
*((_DWORD *)v9 + 1) = a4;
*((_QWORD *)v9 + 2) = 0LL;
func2(a2, a3);
return func2(*((_DWORD *)v9 + 1), a5);
}

original_code:
void
createEdge ( char *edgeLabel, int nodeID, char *nodeLabel, int nodeID_, char *nodeLabel_ )
{
    Edge *edge = ( Edge * ) malloc ( sizeof ( Edge ) );
    if ( edge == ((void *)0) )
    {
        perror ( "malloc" );
        exit ( (*__errno_location ()) );
    }
    addEdge ( edge );
    int edgeLabelLength = strlen ( edgeLabel );
    if ( edgeLabelLength )
    {
        edge -> label = ( char * ) malloc ( sizeof ( char ) * edgeLabelLength );
        if ( edge -> label == ((void *)0) )
        {
            perror ( "malloc" );
            exit ( (*__errno_location ()) );
        }
        strncpy ( edge -> label, edgeLabel, edgeLabelLength );
    }
    edge -> nodeID = nodeID;
    edge -> nodeID_ = nodeID_;
    edge -> next = ((void *)0);
    createNode ( edge -> nodeID, nodeLabel );
    createNode ( edge -> nodeID_, nodeLabel_ );
}

canonical_original_code:
void createEdge(char *edgeLabel, int nodeID, char *nodeLabel, int nodeID_, char *nodeLabel_)
{
    struct _Edge *edge = ( Edge * ) malloc ( sizeof ( Edge ) );
    if ( edge == ((void *)0) )
    {
        perror ( "malloc" );
        exit ( (*__errno_location ()) );
    }
    addEdge ( edge );
    int edgeLabelLength = strlen ( edgeLabel );
    if ( edgeLabelLength )
    {
        edge -> label = ( char * ) malloc ( sizeof ( char ) * edgeLabelLength );
        if ( edge -> label == ((void *)0) )
        {
            perror ( "malloc" );
            exit ( (*__errno_location ()) );
        }
        strncpy ( edge -> label, edgeLabel, edgeLabelLength );
    }
    edge -> nodeID = nodeID;
    edge -> nodeID_ = nodeID_;
    edge -> next = ((void *)0);
    createNode ( edge -> nodeID, nodeLabel );
    createNode ( edge -> nodeID_, nodeLabel_ );
}

variable_types:
edgeLabel
char *

variable_types: nodeID int

variable_types:
nodeLabel
char *

variable_types: edgeLabelLength int


formatCondition

original_code:
void
formatCondition ( char *condition, char *instruction, int notNegated )
{
    int i = 0;
    int length = -1;
    char condition_[256] = { 0 };
    if ( !notNegated )
    {
        i = 2;
        strncpy ( condition_, "¬", i );
    }
    else
    {
        i = 1;
        strncpy ( condition_, " ", i );
    }
    if ( !indexOf ( instructions[IF].label, instruction, 0 ) )
    {
        length = strlen ( instruction ) - 7;
        strncpy ( &(condition_[i]), &(instruction[2]), length );
    }
    else if ( !indexOf ( instructions[LOOP].label, instruction, 0 ) )
    {
        length = strlen ( instruction ) - 12;
        strncpy ( &(condition_[i]), &(instruction[7]), length );
    }
    else
    {
        length = strlen ( condition );
        strncpy ( &(condition_[i]), condition, length );
    }
    length = strlen ( condition_ );
    condition_[length] = '\0';
    strncpy ( condition, condition_, length+1 );
}

canonical_original_code:
void formatCondition(char *condition, char *instruction, int notNegated)
{
    int i = 0;
    int length = -1;
    char condition_[256] = { 0 };
    if ( !notNegated )
    {
        i = 2;
        strncpy ( condition_, "¬", i );
    }
    else
    {
        i = 1;
        strncpy ( condition_, " ", i );
    }
    if ( !indexOf ( instructions[IF].label, instruction, 0 ) )
    {
        length = strlen ( instruction ) - 7;
        strncpy ( &(condition_[i]), &(instruction[2]), length );
    }
    else if ( !indexOf ( instructions[LOOP].label, instruction, 0 ) )
    {
        length = strlen ( instruction ) - 12;
        strncpy ( &(condition_[i]), &(instruction[7]), length );
    }
    else
    {
        length = strlen ( condition );
        strncpy ( &(condition_[i]), condition, length );
    }
    length = strlen ( condition_ );
    condition_[length] = '\0';
    strncpy ( condition, condition_, length+1 );
}

variable_types:
condition
char *

variable_types:
instruction
char *

variable_types: notNegated int

variable_types: i int

variable_types: length int


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int result; // eax
__int128 v4[8]; // [rsp+0h] [rbp-88h] BYREF

v4[0] = 0LL;
v4[1] = 0LL;
v4[2] = 0LL;
v4[3] = 0LL;
v4[4] = 0LL;
v4[5] = 0LL;
v4[6] = 0LL;
v4[7] = 0LL;
printf("Nom du ficher: ");
_isoc99_scanf("%s", v4);
puts(&s);
file = fopen((const char *)v4, "r");
if ( file )
{
createGraph();
displayGraph();
puts("MacCabe:");
macCabe();
puts("\nCouverture des chemins:");
pathCoverage(0LL);
puts("\nCouverture des sommets:");
nodeCoverage(0LL);
puts("\nCouverture des arcs:");
edgeCoverage(0LL);
puts("\nCouverture des instructions de controle:");
instructionCoverage(0LL);
puts(aCouvertureDesC_0);
conditionCoverage(0LL);
puts(&s);
destroyGraph();
fclose(file);
result = 0;
}
else
{
perror("fopen");
result = *_errno_location();
}
return result;
}

original_code:
int
main ( int argc, char **argv )
{
    char filename[128] = { 0 };
    printf ( "Nom du ficher: " );
    scanf ( "%s", ( char * ) filename );
    puts ( "" );
    file = fopen ( filename, "r" );
    if ( file == ((void *)0) )
    {
        perror ( "fopen" );
        return (*__errno_location ());
    }
    createGraph ( );
    displayGraph ( );
    puts ( "MacCabe:" );
    macCabe ();
    puts ( "\nCouverture des chemins:" );
    pathCoverage ( 0 );
    puts ( "\nCouverture des sommets:" );
    nodeCoverage ( 0 );
    puts ( "\nCouverture des arcs:" );
    edgeCoverage ( 0 );
    puts ( "\nCouverture des instructions de controle:" );
    instructionCoverage ( 0 );
    puts ( "\nCouverture des conditions élémentaires:" );
    conditionCoverage ( 0 );
    puts ( "" );
    destroyGraph ( );
    fclose ( file );
    return 0;
}

canonical_original_code:
int main(int argc, char **argv)
{
    char filename[128] = { 0 };
    printf ( "Nom du ficher: " );
    scanf ( "%s", ( char * ) filename );
    puts ( "" );
    file = fopen ( filename, "r" );
    if ( file == ((void *)0) )
    {
        perror ( "fopen" );
        return (*__errno_location ());
    }
    createGraph ( );
    displayGraph ( );
    puts ( "MacCabe:" );
    macCabe ();
    puts ( "\nCouverture des chemins:" );
    pathCoverage ( 0 );
    puts ( "\nCouverture des sommets:" );
    nodeCoverage ( 0 );
    puts ( "\nCouverture des arcs:" );
    edgeCoverage ( 0 );
    puts ( "\nCouverture des instructions de controle:" );
    instructionCoverage ( 0 );
    puts ( "\nCouverture des conditions élémentaires:" );
    conditionCoverage ( 0 );
    puts ( "" );
    destroyGraph ( );
    fclose ( file );
    return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types:
filename
char [128]

return_type: int


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

pthread_mutex_lock(&mutex);
pthread_create(&tid, 0LL, (void *(*)(void *))&display, 0LL);
pthread_cond_wait(&cond, &mutex);
pthread_mutex_unlock(&mutex);
obstacles();
x = getX();
y = getY();
printf("Start\tx = %d\ty = %d\n", x, y);
startx = x;
starty = y;
if ( (unsigned int)findpath(x, y, 13LL, " \tx = %d\ty = %d\n", v3, v4) == -1 )
goto LABEL_10;
while ( !(unsigned int)nextstep(&x, &y) )
printf("Next \tx = %d\ty = %d\n", x, y);
paths();
x = getX();
y = getY();
printf("\nStart\tx = %d\ty = %d\n", x, y);
startx = x;
starty = y;
if ( (unsigned int)findpath(x, y, 57LL, " %d\ty = %d\n", v5, v6) == -1 )
{
LABEL_10:
perror("findpath");
exit(1);
}
while ( !(unsigned int)nextstep(&x, &y) )
printf("Next \tx = %d\ty = %d\n", x, y);
paths();
pthread_join(tid, 0LL);
return 0;
}

original_code:
int
main (int argc, char **argv)
{
  int err;
  pthread_mutex_lock (&mutex);
  pthread_create (&tid, ((void *)0), display, ((void *)0));
  pthread_cond_wait (&cond, &mutex);
  pthread_mutex_unlock (&mutex);
  obstacles ();
  x = getX ();
  y = getY ();
  printf ("Start\tx = %d\ty = %d\n", x, y);
  startx = x;
  starty = y;
  err = findpath (x, y, 13, 37);
  if (err == -1)
    {
      _perror ("findpath");
      exit (1);
    }
  while (!(err = nextstep (&x, &y)))
    {
      printf ("Next \tx = %d\ty = %d\n", x, y);
    }
  paths ();
  x = getX ();
  y = getY ();
  printf ("\nStart\tx = %d\ty = %d\n", x, y);
  startx = x;
  starty = y;
  err = findpath (x, y, 57, 12);
  if (err == -1)
    {
      _perror ("findpath");
      exit (1);
    }
  while (!(err = nextstep (&x, &y)))
    {
      printf ("Next \tx = %d\ty = %d\n", x, y);
    }
  paths ();
  pthread_join (tid, ((void *)0));
  return 0;
}

canonical_original_code:
int main(int argc, char **argv)
{
  int err;
  pthread_mutex_lock (&mutex);
  pthread_create (&tid, ((void *)0), display, ((void *)0));
  pthread_cond_wait (&cond, &mutex);
  pthread_mutex_unlock (&mutex);
  obstacles ();
  x = getX ();
  y = getY ();
  printf ("Start\tx = %d\ty = %d\n", x, y);
  startx = x;
  starty = y;
  err = findpath (x, y, 13, 37);
  if (err == -1)
    {
      _perror ("findpath");
      exit (1);
    }
  while (!(err = nextstep (&x, &y)))
    {
      printf ("Next \tx = %d\ty = %d\n", x, y);
    }
  paths ();
  x = getX ();
  y = getY ();
  printf ("\nStart\tx = %d\ty = %d\n", x, y);
  startx = x;
  starty = y;
  err = findpath (x, y, 57, 12);
  if (err == -1)
    {
      _perror ("findpath");
      exit (1);
    }
  while (!(err = nextstep (&x, &y)))
    {
      printf ("Next \tx = %d\ty = %d\n", x, y);
    }
  paths ();
  pthread_join (tid, ((void *)0));
  return 0;
}

variable_types: err int


nextstep

decompiled_code:
__int64 __fastcall nextstep(_DWORD *a1, _DWORD *a2)
{
__int64 v2; // rdx
int v3; // ecx
__int64 result; // rax

if ( step_0 >= pathlength_ )
{
step_0 = 0;
result = 0xFFFFFFFFLL;
errno = 1;
}
else
{
v2 = step_0;
v3 = *((_DWORD *)&path_ + 2 * step_0++);
result = 0LL;
*a1 = v3;
*a2 = *((_DWORD *)&path_ + 2 * v2 + 1);
errno = 0;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(_DWORD *a1, _DWORD *a2)
{
__int64 v2; // rdx
int v3; // ecx
__int64 result; // rax

if ( step_0 >= pathlength_ )
{
step_0 = 0;
result = 0xFFFFFFFFLL;
errno = 1;
}
else
{
v2 = step_0;
v3 = *((_DWORD *)&path_ + 2 * step_0++);
result = 0LL;
*a1 = v3;
*a2 = *((_DWORD *)&path_ + 2 * v2 + 1);
errno = 0;
}
return result;
}

original_code:
int
nextstep (int *x, int *y)
{
  static int step = 0;
  if (step >= pathlength_)
    {
      step = 0;
      errno = 1;
      return -1;
    }
  *x = path_[step].x;
  *y = path_[step].y;
  step++;
  errno = 0;
  return 0;
}

canonical_original_code:
int nextstep(int *x, int *y)
{
  static int step = 0;
  if (step >= pathlength_)
    {
      step = 0;
      errno = 1;
      return -1;
    }
  *x = path_[step].x;
  *y = path_[step].y;
  step++;
  errno = 0;
  return 0;
}

variable_types:
x
int *

variable_types:
y
int *

variable_types: step int


draw

decompiled_code:
__int64 __fastcall draw(__int16 a1, __int16 a2, int a3)
{
unsigned __int16 v4; // bp
unsigned __int16 v5; // r10
unsigned __int16 v6; // r9
__int64 result; // rax

v4 = 8 * a1;
do
{
v5 = v4;
v6 = 8 * a2;
do
result = putPixel(v5, v6, a3);
while ( 8 * a2 + 8 != v6 );
++v4;
}
while ( 8 * a1 + 8 != v4 );
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int16 a1, __int16 a2, int a3)
{
unsigned __int16 v4; // bp
unsigned __int16 v5; // r10
unsigned __int16 v6; // r9
__int64 result; // rax

v4 = 8 * a1;
do
{
v5 = v4;
v6 = 8 * a2;
do
result = func1(v5, v6, a3);
while ( 8 * a2 + 8 != v6 );
++v4;
}
while ( 8 * a1 + 8 != v4 );
return result;
}

original_code:
void
draw (Uint16 x, Uint16 y, Uint32 color)
{
  for (int i = 0; i < 8; i++)
    {
      for (int j = 0; j < 8; j++)
        {
   putPixel ((x * 8 + i), (y * 8 + j), color);
        }
    }
}

canonical_original_code:
void draw(unsigned short x, unsigned short y, unsigned int color)
{
  for (int i = 0; i < 8; i++)
    {
      for (int j = 0; j < 8; j++)
        {
   putPixel ((x * 8 + i), (y * 8 + j), color);
        }
    }
}

variable_types:
x
unsigned short

variable_types:
y
unsigned short

variable_types:
color
unsigned int

variable_types: j int


obstacles

original_code:
void
obstacles ()
{
  for (int x = 0; x < 16; x++)
    {
      for (int y = 0; y < 64; y++)
        {
   for (int z = 0; z < 4; z++)
            {
       switch ((map[y][x] >> (6 - z * 2)) & 0x03)
                {
  case 0:
    draw (x * 4 + z, y, (SDL_MapRGB (screen -> format, 211, 215, 207)));
    break;
  case 3:
    draw (x * 4 + z, y, (SDL_MapRGB (screen -> format, 46, 52, 54)));
    break;
  default:
    break;
                }
            }
        }
    }
}

canonical_original_code:
void obstacles()
{
  for (int x = 0; x < 16; x++)
    {
      for (int y = 0; y < 64; y++)
        {
   for (int z = 0; z < 4; z++)
            {
       switch ((map[y][x] >> (6 - z * 2)) & 0x03)
                {
  case 0:
    draw (x * 4 + z, y, (SDL_MapRGB (screen -> format, 211, 215, 207)));
    break;
  case 3:
    draw (x * 4 + z, y, (SDL_MapRGB (screen -> format, 46, 52, 54)));
    break;
  default:
    break;
                }
            }
        }
    }
}

variable_types: x int

variable_types: y int

variable_types: z int


lists

decompiled_code:
__int64 lists()
{
__int64 v0; // rbx
int v1; // edx
__int64 v2; // rax
__int64 v3; // rbx
int v4; // edx
__int64 v5; // rax

if ( openedNodes > 0 )
{
v0 = 0LL;
do
{
v1 = SDL_MapRGB(*(_QWORD *)(screen + 8), 52LL, 101LL, 164LL);
v2 = *((_QWORD *)&openedNodes + ++v0);
draw(*(_WORD *)(v2 + 8), *(_WORD *)(v2 + 12), v1);
}
while ( openedNodes > (int)v0 );
}
if ( closedNodes > 0 )
{
v3 = 0LL;
do
{
v4 = SDL_MapRGB(*(_QWORD *)(screen + 8), 196LL, 160LL, 0LL);
v5 = *((_QWORD *)&closedNodes + ++v3);
draw(*(_WORD *)(v5 + 8), *(_WORD *)(v5 + 12), v4);
}
while ( closedNodes > (int)v3 );
}
return SDL_Flip(screen);
}

canonical_decompiled_code:
__int64 func4()
{
__int64 v0; // rbx
int v1; // edx
__int64 v2; // rax
__int64 v3; // rbx
int v4; // edx
__int64 v5; // rax

if ( openedNodes > 0 )
{
v0 = 0LL;
do
{
v1 = SDL_MapRGB(*(_QWORD *)(screen + 8), 52LL, 101LL, 164LL);
v2 = *((_QWORD *)&openedNodes + ++v0);
func2(*(_WORD *)(v2 + 8), *(_WORD *)(v2 + 12), v1);
}
while ( openedNodes > (int)v0 );
}
if ( closedNodes > 0 )
{
v3 = 0LL;
do
{
v4 = SDL_MapRGB(*(_QWORD *)(screen + 8), 196LL, 160LL, 0LL);
v5 = *((_QWORD *)&closedNodes + ++v3);
func2(*(_WORD *)(v5 + 8), *(_WORD *)(v5 + 12), v4);
}
while ( closedNodes > (int)v3 );
}
return SDL_Flip(screen);
}

original_code:
void
lists ()
{
  for (int i = 0; i < openedNodes.number; i++)
    draw (openedNodes.node[i] -> x, openedNodes.node[i] -> y, (SDL_MapRGB (screen -> format, 52, 101, 164)));
  for (int i = 0; i < closedNodes.number; i++)
    draw (closedNodes.node[i] -> x, closedNodes.node[i] -> y, (SDL_MapRGB (screen -> format, 196, 160, 0)));
  SDL_Flip (screen);
}

canonical_original_code:
void lists()
{
  for (int i = 0; i < openedNodes.number; i++)
    draw (openedNodes.node[i] -> x, openedNodes.node[i] -> y, (SDL_MapRGB (screen -> format, 52, 101, 164)));
  for (int i = 0; i < closedNodes.number; i++)
    draw (closedNodes.node[i] -> x, closedNodes.node[i] -> y, (SDL_MapRGB (screen -> format, 196, 160, 0)));
  SDL_Flip (screen);
}


segments

original_code:
void
segments (Point a, Point b)
{
  int x = a.x;
  int y = a.y;
  int dx = b.x - x;
  int dy = b.y - y;
  int xinc = (dx > 0) ? 1 : -1;
  int yinc = (dy > 0) ? 1 : -1;
  dx = (dx > 0) ? dx : -dx;
  dy = (dy > 0) ? dy : -dy;
  if (dx > dy)
    {
      int cumul = dx / 2;
      for (int i = 0; i < dx; i++)
 {
   x += xinc;
   cumul += dy;
   if (cumul >= dx)
     {
       y += yinc;
       cumul -= dx;
     }
   draw (x, y, (SDL_MapRGB (screen -> format, 78, 154, 6)));
 }
    }
  else
    {
      int cumul = dy / 2;
      for (int i = 0; i < dy; i++)
 {
   y += yinc;
   cumul += dx;
   if (cumul >= dy)
     {
       x += xinc;
       cumul -= dy;
     }
   draw (x, y, (SDL_MapRGB (screen -> format, 78, 154, 6)));
 }
    }
}

canonical_original_code:
void segments(struct _Point a, struct _Point b)
{
  int x = a.x;
  int y = a.y;
  int dx = b.x - x;
  int dy = b.y - y;
  int xinc = (dx > 0) ? 1 : -1;
  int yinc = (dy > 0) ? 1 : -1;
  dx = (dx > 0) ? dx : -dx;
  dy = (dy > 0) ? dy : -dy;
  if (dx > dy)
    {
      int cumul = dx / 2;
      for (int i = 0; i < dx; i++)
 {
   x += xinc;
   cumul += dy;
   if (cumul >= dx)
     {
       y += yinc;
       cumul -= dx;
     }
   draw (x, y, (SDL_MapRGB (screen -> format, 78, 154, 6)));
 }
    }
  else
    {
      int cumul = dy / 2;
      for (int i = 0; i < dy; i++)
 {
   y += yinc;
   cumul += dx;
   if (cumul >= dy)
     {
       x += xinc;
       cumul -= dy;
     }
   draw (x, y, (SDL_MapRGB (screen -> format, 78, 154, 6)));
 }
    }
}

variable_types:
a
struct _Point { int x; int y; }

variable_types:
b
struct _Point

variable_types: dx int

variable_types: dy int

variable_types: xinc int

variable_types: yinc int

variable_types: cumul int


paths

decompiled_code:
__int64 paths()
{
__int64 v0; // rbx
int v1; // eax
__int16 v2; // si
__int16 v3; // di
int v4; // ebx
__int64 v5; // rax

if ( pathlength > 0 )
{
v0 = 0LL;
do
{
v1 = SDL_MapRGB(*(_QWORD *)(screen + 8), 204LL, 0LL, 0LL);
v2 = *((_WORD *)&path + 4 * v0 + 2);
v3 = *((_WORD *)&path + 4 * v0++);
draw(v3, v2, v1);
}
while ( pathlength > (int)v0 );
}
segments(((unsigned __int64)(unsigned int)starty << 32) | (unsigned int)startx, path_);
if ( pathlength_ > 1 )
{
v4 = 0;
do
{
v5 = v4++;
segments(*((_QWORD *)&path_ + v5), *((_QWORD *)&path_ + v4));
}
while ( v4 < pathlength_ - 1 );
}
return SDL_Flip(screen);
}

canonical_decompiled_code:
__int64 func6()
{
__int64 v0; // rbx
int v1; // eax
__int16 v2; // si
__int16 v3; // di
int v4; // ebx
__int64 v5; // rax

if ( pathlength > 0 )
{
v0 = 0LL;
do
{
v1 = SDL_MapRGB(*(_QWORD *)(screen + 8), 204LL, 0LL, 0LL);
v2 = *((_WORD *)&path + 4 * v0 + 2);
v3 = *((_WORD *)&path + 4 * v0++);
func2(v3, v2, v1);
}
while ( pathlength > (int)v0 );
}
func5(((unsigned __int64)(unsigned int)starty << 32) | (unsigned int)startx, path_);
if ( pathlength_ > 1 )
{
v4 = 0;
do
{
v5 = v4++;
func5(*((_QWORD *)&path_ + v5), *((_QWORD *)&path_ + v4));
}
while ( v4 < pathlength_ - 1 );
}
return SDL_Flip(screen);
}

original_code:
void
paths ()
{
  for (int i = 0; i < pathlength; i++)
    draw (path[i].x, path[i].y, (SDL_MapRGB (screen -> format, 204, 0, 0)));
  Point start = { startx, starty };
  segments (start, path_[0]);
  for (int i = 0; i < pathlength_ - 1; i++)
    segments (path_[i], path_[i+1]);
  SDL_Flip (screen);
}

canonical_original_code:
void paths()
{
  for (int i = 0; i < pathlength; i++)
    draw (path[i].x, path[i].y, (SDL_MapRGB (screen -> format, 204, 0, 0)));
  struct _Point start = { startx, starty };
  segments (start, path_[0]);
  for (int i = 0; i < pathlength_ - 1; i++)
    segments (path_[i], path_[i+1]);
  SDL_Flip (screen);
}

variable_types: i int

variable_types:
start
struct _Point { int x; int y; }


addOpenedNodes

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

result = SLODWORD(openedNodes[0]);
*(_DWORD *)(a1 + 16) = 42;
openedNodes[result + 1] = a1;
LODWORD(openedNodes[0]) = result + 1;
return result;
}

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

result = SLODWORD(openedNodes[0]);
*(_DWORD *)(a1 + 16) = 42;
openedNodes[result + 1] = a1;
LODWORD(openedNodes[0]) = result + 1;
return result;
}

original_code:
void
addOpenedNodes (Node *node)
{
  node -> opened = 42;
  openedNodes.node[openedNodes.number++] = node;
}

canonical_original_code:
void addOpenedNodes(struct _Node *node)
{
  node -> opened = 42;
  openedNodes.node[openedNodes.number++] = node;
}

variable_types: struct _Node { struct _Node *parent; int x; int y; int opened; int closed; int G; int H; int F; } *


delOpenedNodes

decompiled_code:
__int64 __fastcall delOpenedNodes(__int64 a1)
{
__int64 result; // rax
int v2; // er8
__int64 v3; // rsi
__int64 v4; // rdi
__int64 v5; // rcx

result = LODWORD(openedNodes[0]);
*(_DWORD *)(a1 + 16) = 0;
v2 = result - 1;
LODWORD(openedNodes[0]) = result - 1;
if ( (int)result - 1 > 0 )
{
v3 = *(_QWORD *)(a1 + 8);
v4 = (unsigned int)(result - 2);
for ( result = 0LL; ; ++result )
{
v5 = (int)result;
if ( *(_QWORD *)(openedNodes[result + 1] + 8) == v3 )
break;
if ( result == v4 )
return result;
}
result = openedNodes[v2 + 1];
openedNodes[v5 + 1] = result;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
__int64 result; // rax
int v2; // er8
__int64 v3; // rsi
__int64 v4; // rdi
__int64 v5; // rcx

result = LODWORD(openedNodes[0]);
*(_DWORD *)(a1 + 16) = 0;
v2 = result - 1;
LODWORD(openedNodes[0]) = result - 1;
if ( (int)result - 1 > 0 )
{
v3 = *(_QWORD *)(a1 + 8);
v4 = (unsigned int)(result - 2);
for ( result = 0LL; ; ++result )
{
v5 = (int)result;
if ( *(_QWORD *)(openedNodes[result + 1] + 8) == v3 )
break;
if ( result == v4 )
return result;
}
result = openedNodes[v2 + 1];
openedNodes[v5 + 1] = result;
}
return result;
}

original_code:
void
delOpenedNodes (Node *node)
{
  node -> opened = 0;
  openedNodes.number--;
  for (int i = 0; i < openedNodes.number; i++)
    {
      if (openedNodes.node[i] -> x == node -> x &&
          openedNodes.node[i] -> y == node -> y)
        {
   openedNodes.node[i] = openedNodes.node[openedNodes.number];
   break;
        }
    }
}

canonical_original_code:
void delOpenedNodes(struct _Node *node)
{
  node -> opened = 0;
  openedNodes.number--;
  for (int i = 0; i < openedNodes.number; i++)
    {
      if (openedNodes.node[i] -> x == node -> x &&
          openedNodes.node[i] -> y == node -> y)
        {
   openedNodes.node[i] = openedNodes.node[openedNodes.number];
   break;
        }
    }
}

user_defined_types: struct _Node { struct _Node *parent; int x; int y; int opened; int closed; int G; int H; int F; }


addClosedNodes

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

result = SLODWORD(closedNodes[0]);
*(_DWORD *)(a1 + 20) = 42;
closedNodes[result + 1] = a1;
LODWORD(closedNodes[0]) = result + 1;
return result;
}

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

result = SLODWORD(closedNodes[0]);
*(_DWORD *)(a1 + 20) = 42;
closedNodes[result + 1] = a1;
LODWORD(closedNodes[0]) = result + 1;
return result;
}

original_code:
void
addClosedNodes (Node *node)
{
  node -> closed = 42;
  closedNodes.node[closedNodes.number++] = node;
}

canonical_original_code:
void addClosedNodes(struct _Node *node)
{
  node -> closed = 42;
  closedNodes.node[closedNodes.number++] = node;
}


walkable

original_code:
int
walkable (Point a, Point b)
{
  int x = a.x;
  int y = a.y;
  int dx = b.x - x;
  int dy = b.y - y;
  int xinc = (dx > 0) ? 1 : -1;
  int yinc = (dy > 0) ? 1 : -1;
  dx = (dx > 0) ? dx : -dx;
  dy = (dy > 0) ? dy : -dy;
  if (dx > dy)
    {
      int cumul = dx / 2;
      for (int i = 0; i < dx; i++)
 {
   x += xinc;
   cumul += dy;
   if (cumul >= dx)
     {
       y += yinc;
       cumul -= dx;
     }
   if ((map [(y)][(x) / 4] >> (6 - (((x) % 4) * 2)) & 0x03) == 3)
     return 0;
 }
    }
  else
    {
      int cumul = dy / 2;
      for (int i = 0; i < dy; i++)
 {
   y += yinc;
   cumul += dx;
   if (cumul >= dy)
     {
       x += xinc;
       cumul -= dy;
     }
   if ((map [(y)][(x) / 4] >> (6 - (((x) % 4) * 2)) & 0x03) == 3)
     return 0;
 }
    }
  return 42;
}

canonical_original_code:
int walkable(struct _Point a, struct _Point b)
{
  int x = a.x;
  int y = a.y;
  int dx = b.x - x;
  int dy = b.y - y;
  int xinc = (dx > 0) ? 1 : -1;
  int yinc = (dy > 0) ? 1 : -1;
  dx = (dx > 0) ? dx : -dx;
  dy = (dy > 0) ? dy : -dy;
  if (dx > dy)
    {
      int cumul = dx / 2;
      for (int i = 0; i < dx; i++)
 {
   x += xinc;
   cumul += dy;
   if (cumul >= dx)
     {
       y += yinc;
       cumul -= dx;
     }
   if ((map [(y)][(x) / 4] >> (6 - (((x) % 4) * 2)) & 0x03) == 3)
     return 0;
 }
    }
  else
    {
      int cumul = dy / 2;
      for (int i = 0; i < dy; i++)
 {
   y += yinc;
   cumul += dx;
   if (cumul >= dy)
     {
       x += xinc;
       cumul -= dy;
     }
   if ((map [(y)][(x) / 4] >> (6 - (((x) % 4) * 2)) & 0x03) == 3)
     return 0;
 }
    }
  return 42;
}


makepath

decompiled_code:
__int64 __fastcall makepath(__int64 *a1, int a2, int a3)
{
__int64 v4; // rax
char v5; // r8
int v6; // edx
int v7; // ecx
__int64 v8; // rbp
int v9; // er14
int v10; // er15
int v11; // er12
__int64 i; // rbx
__int64 result; // rax

v4 = 0LL;
v5 = 0;
pathlength = 0;
while ( 1 )
{
v6 = *((_DWORD *)a1 + 2);
v7 = *((_DWORD *)a1 + 3);
if ( v6 == a2 && a3 == v7 )
break;
a1 = (__int64 *)*a1;
LODWORD(path[v4]) = v6;
v5 = 1;
HIDWORD(path[v4++]) = v7;
}
v8 = pathlength_;
if ( v5 && (pathlength = v4, v8 = pathlength_, (int)v4 > 3) )
{
v9 = path[0];
v10 = HIDWORD(path[0]);
v11 = v4 - 1;
for ( i = (int)v4 - 3; LODWORD(path[i]) != v9 || HIDWORD(path[i]) != v10; --i )
{
if ( !(unsigned int)walkable(path[(int)i], path[v11]) )
{
v11 = i + 1;
pathlength_ = v8 + 1;
path_[v8] = path[(int)i + 1];
v8 = (int)v8 + 1;
}
}
pathlength_ = v8 + 1;
result = path[(int)i];
path_[v8] = result;
}
else
{
pathlength_ = v8 + 1;
result = path[0];
path_[v8] = path[0];
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 *a1, int a2, int a3)
{
__int64 v4; // rax
char v5; // r8
int v6; // edx
int v7; // ecx
__int64 v8; // rbp
int v9; // er14
int v10; // er15
int v11; // er12
__int64 i; // rbx
__int64 result; // rax

v4 = 0LL;
v5 = 0;
pathlength = 0;
while ( 1 )
{
v6 = *((_DWORD *)a1 + 2);
v7 = *((_DWORD *)a1 + 3);
if ( v6 == a2 && a3 == v7 )
break;
a1 = (__int64 *)*a1;
LODWORD(path[v4]) = v6;
v5 = 1;
HIDWORD(path[v4++]) = v7;
}
v8 = pathlength_;
if ( v5 && (pathlength = v4, v8 = pathlength_, (int)v4 > 3) )
{
v9 = path[0];
v10 = HIDWORD(path[0]);
v11 = v4 - 1;
for ( i = (int)v4 - 3; LODWORD(path[i]) != v9 || HIDWORD(path[i]) != v10; --i )
{
if ( !(unsigned int)func3(path[(int)i], path[v11]) )
{
v11 = i + 1;
pathlength_ = v8 + 1;
path_[v8] = path[(int)i + 1];
v8 = (int)v8 + 1;
}
}
pathlength_ = v8 + 1;
result = path[(int)i];
path_[v8] = result;
}
else
{
pathlength_ = v8 + 1;
result = path[0];
path_[v8] = path[0];
}
return result;
}

original_code:
void
makepath (Node* node, int x, int y)
{
  pathlength = 0;
  while (node -> x != x ||
         node -> y != y)
    {
      path[pathlength].x = node -> x;
      path[pathlength].y = node -> y;
      pathlength++;
      node = node -> parent;
    }
  if (pathlength < 4)
    {
      path_[pathlength_++] = path[0];
      return;
    }
  int endx = path[0].x;
  int endy = path[0].y;
  int firstpoint = pathlength - 1;
  int lastpoint = firstpoint - 2;
  while (path[lastpoint].x != endx ||
  path[lastpoint].y != endy)
    {
      if (!walkable (path[lastpoint], path[firstpoint]))
 {
   path_[pathlength_++] = path[lastpoint+1];
   firstpoint = lastpoint+1;
 }
      lastpoint--;
    }
  path_[pathlength_++] = path[lastpoint];
}

canonical_original_code:
void makepath(struct _Node *node, int x, int y)
{
  pathlength = 0;
  while (node -> x != x ||
         node -> y != y)
    {
      path[pathlength].x = node -> x;
      path[pathlength].y = node -> y;
      pathlength++;
      node = node -> parent;
    }
  if (pathlength < 4)
    {
      path_[pathlength_++] = path[0];
      return;
    }
  int endx = path[0].x;
  int endy = path[0].y;
  int firstpoint = pathlength - 1;
  int lastpoint = firstpoint - 2;
  while (path[lastpoint].x != endx ||
  path[lastpoint].y != endy)
    {
      if (!walkable (path[lastpoint], path[firstpoint]))
 {
   path_[pathlength_++] = path[lastpoint+1];
   firstpoint = lastpoint+1;
 }
      lastpoint--;
    }
  path_[pathlength_++] = path[lastpoint];
}

variable_types: endx int

variable_types: endy int

variable_types: firstpoint int

variable_types: lastpoint int


swap

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

result = openedNodes[a1 + 1];
openedNodes[a1 + 1] = openedNodes[a2 + 1];
openedNodes[a2 + 1] = result;
return result;
}

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

result = openedNodes[a1 + 1];
openedNodes[a1 + 1] = openedNodes[a2 + 1];
openedNodes[a2 + 1] = result;
return result;
}

original_code:
void
swap (int i, int j)
{
  Node *tmp = openedNodes.node[i];
  openedNodes.node[i] = openedNodes.node[j];
  openedNodes.node[j] = tmp;
}

canonical_original_code:
void swap(int i, int j)
{
  struct _Node *tmp = openedNodes.node[i];
  openedNodes.node[i] = openedNodes.node[j];
  openedNodes.node[j] = tmp;
}

variable_types: j int


sift

decompiled_code:
__int64 __fastcall sift(int a1, int a2)
{
__int64 result; // rax
int v4; // esi
int v5; // ecx
int v6; // ecx
int v7; // edx

result = (unsigned int)(2 * a1 + 1);
if ( a2 > (int)result )
{
while ( 1 )
{
v6 = 2 * a1 + 2;
v7 = *(_DWORD *)(openedNodes[(int)result + 1] + 32);
if ( v6 >= a2 || (v4 = *(_DWORD *)(openedNodes[v6 + 1] + 32), v4 <= v7) )
{
v6 = result;
result = openedNodes[a1 + 1];
if ( *(_DWORD *)(result + 32) >= v7 )
return result;
}
else
{
result = openedNodes[a1 + 1];
if ( *(_DWORD *)(result + 32) >= v4 )
return result;
}
swap(a1, v6);
result = (unsigned int)(2 * v5 + 1);
if ( (int)result >= a2 )
return result;
a1 = v5;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(int a1, int a2)
{
__int64 result; // rax
int v4; // esi
int v5; // ecx
int v6; // ecx
int v7; // edx

result = (unsigned int)(2 * a1 + 1);
if ( a2 > (int)result )
{
while ( 1 )
{
v6 = 2 * a1 + 2;
v7 = *(_DWORD *)(openedNodes[(int)result + 1] + 32);
if ( v6 >= a2 || (v4 = *(_DWORD *)(openedNodes[v6 + 1] + 32), v4 <= v7) )
{
v6 = result;
result = openedNodes[a1 + 1];
if ( *(_DWORD *)(result + 32) >= v7 )
return result;
}
else
{
result = openedNodes[a1 + 1];
if ( *(_DWORD *)(result + 32) >= v4 )
return result;
}
func5(a1, v6);
result = (unsigned int)(2 * v5 + 1);
if ( (int)result >= a2 )
return result;
a1 = v5;
}
}
return result;
}

original_code:
void
sift (int root, int size)
{
  int child = -1;
  while ((child = root * 2 + 1) < size)
    {
      if (child+1 < size)
 child = (openedNodes.node[child+1] -> F > openedNodes.node[child] -> F ? child+1 : child);
      if (!(openedNodes.node[root] -> F < openedNodes.node[child] -> F))
 return;
      swap (root, child);
      root = child;
    }
}

canonical_original_code:
void sift(int root, int size)
{
  int child = -1;
  while ((child = root * 2 + 1) < size)
    {
      if (child+1 < size)
 child = (openedNodes.node[child+1] -> F > openedNodes.node[child] -> F ? child+1 : child);
      if (!(openedNodes.node[root] -> F < openedNodes.node[child] -> F))
 return;
      swap (root, child);
      root = child;
    }
}

variable_types: root int

variable_types: size int

variable_types: child int


heapsort

decompiled_code:
__int64 heapsort()
{
int v0; // esi
int v1; // edi
__int64 result; // rax
int v3; // er9
int v4; // er9
int v5; // er9

v0 = openedNodes[0];
v1 = SLODWORD(openedNodes[0]) / 2 - 1;
if ( v1 >= 0 )
{
while ( 1 )
{
result = sift(v1, v0);
v0 = openedNodes[0];
if ( v3 == -1 )
break;
v1 = v3;
}
}
v4 = v0 - 1;
if ( v0 - 1 > 0 )
{
do
{
swap(v4, 0);
result = sift(0, v5);
}
while ( v4 );
}
return result;
}

canonical_decompiled_code:
__int64 func7()
{
int v0; // esi
int v1; // edi
__int64 result; // rax
int v3; // er9
int v4; // er9
int v5; // er9

v0 = openedNodes[0];
v1 = SLODWORD(openedNodes[0]) / 2 - 1;
if ( v1 >= 0 )
{
while ( 1 )
{
result = func6(v1, v0);
v0 = openedNodes[0];
if ( v3 == -1 )
break;
v1 = v3;
}
}
v4 = v0 - 1;
if ( v0 - 1 > 0 )
{
do
{
func5(v4, 0);
result = func6(0, v5);
}
while ( v4 );
}
return result;
}

original_code:
void
heapsort ()
{
  int root = openedNodes.number / 2 - 1;
  while (root > -1)
    sift (root--, openedNodes.number);
  int end = openedNodes.number - 1;
  while (end > 0)
    {
      swap (end, 0);
      sift (0, end--);
    }
}

canonical_original_code:
void heapsort()
{
  int root = openedNodes.number / 2 - 1;
  while (root > -1)
    sift (root--, openedNodes.number);
  int end = openedNodes.number - 1;
  while (end > 0)
    {
      swap (end, 0);
      sift (0, end--);
    }
}

variable_types: end int


heuristic

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

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

original_code:
int
heuristic (int x, int y, int x_, int y_)
{
  return (x - x_) * (x - x_) + (y - y_) * (y - y_);
}

canonical_original_code:
int heuristic(int x, int y, int x_, int y_)
{
  return (x - x_) * (x - x_) + (y - y_) * (y - y_);
}

variable_types: x int

variable_types: y int


findpath

original_code:
int
findpath (const int x, const int y, const int x_, const int y_)
{
  printf ("End  \tx = %d\ty = %d\n", x_, y_);
  openedNodes.number = 0;
  closedNodes.number = 0;
  pathlength = 0;
  pathlength_ = 0;
  if (x == x_ &&
      y == y_)
    {
      errno = 2;
      return -1;
    }
  if (x < 0 || x > ((16 * 4) - 1) ||
      y < 0 || y > ( 64 - 1))
    {
      errno = 4;
      return -1;
    }
  if ((map [(y)][(x) / 4] >> (6 - (((x) % 4) * 2)) & 0x03) == 3)
    {
      errno = 3;
      return -1;
    }
  if (x_ < 0 || x_ > ((16 * 4) - 1) ||
      y_ < 0 || y_ > ( 64 - 1))
    {
      errno = 6;
      return -1;
    }
  if ((map [(y_)][(x_) / 4] >> (6 - (((x_) % 4) * 2)) & 0x03) == 3)
    {
      errno = 5;
      return -1;
    }
  for (int y = 0; y < 64; y++)
    {
      for (int x = 0; x < 16 * 4; x++)
        {
   graph[y][x].parent = ((void *)0);
   graph[y][x].x = x;
   graph[y][x].y = y;
   graph[y][x].opened = 0;
   graph[y][x].closed = 0;
   graph[y][x].G = 0;
   graph[y][x].H = 0;
   graph[y][x].F = 0;
        }
    }
  Node *current = &(graph[y][x]);
  current -> x = x;
  current -> y = y;
  current -> H = heuristic (x, y, x_, y_);
  current -> F = current -> H;
  addOpenedNodes (current);
  int loop = 0;
  while (openedNodes.number)
    {
      if (loop > 1000)
 {
   errno = 7;
   return -1;
 }
      loop++;
      heapsort();
      current = openedNodes.node[0];
      if (current -> x == x_ &&
          current -> y == y_)
        {
   makepath (current, x, y);
   errno = 0;
   return 0;
        }
      delOpenedNodes (current);
      addClosedNodes (current);
      int xoffset[] = { -1, 0, 1, -1, 1, -1, 0, 1 };
      int yoffset[] = { -1, -1, -1, 0, 0, 1, 1, 1 };
      for (int i = 0; i < 8; i++)
        {
   int xneighbor = current -> x + xoffset[i];
   int yneighbor = current -> y + yoffset[i];
   if (xneighbor < 0 || xneighbor > ((16 * 4) - 1) ||
              yneighbor < 0 || yneighbor > ( 64 - 1))
     continue;
   if ((map [(yneighbor)][(xneighbor) / 4] >> (6 - (((xneighbor) % 4) * 2)) & 0x03) == 3)
     continue;
   Node *neighbor = &(graph[yneighbor][xneighbor]);
   if (neighbor -> closed)
     continue;
   int G = current -> G + (map [(neighbor -> y)][(neighbor -> x) / 4] >> (6 - (((neighbor -> x) % 4) * 2)) & 0x03);
   int H = heuristic (neighbor -> x, neighbor -> y, x_, y_);
   int F = G + H;
   if (neighbor -> opened)
            {
       if (F < current -> F)
                {
    neighbor -> G = G;
    neighbor -> H = H;
    neighbor -> F = F;
    neighbor -> parent = current;
                }
            }
   else
            {
       neighbor -> G = G;
       neighbor -> H = H;
       neighbor -> F = F;
       neighbor -> parent = current;
       addOpenedNodes (neighbor);
            }
        }
      lists ();
      usleep (5000);
    }
  errno = 8;
  return -1;
}

canonical_original_code:
int findpath(int x, int y, int x_, int y_)
{
  printf ("End  \tx = %d\ty = %d\n", x_, y_);
  openedNodes.number = 0;
  closedNodes.number = 0;
  pathlength = 0;
  pathlength_ = 0;
  if (x == x_ &&
      y == y_)
    {
      errno = 2;
      return -1;
    }
  if (x < 0 || x > ((16 * 4) - 1) ||
      y < 0 || y > ( 64 - 1))
    {
      errno = 4;
      return -1;
    }
  if ((map [(y)][(x) / 4] >> (6 - (((x) % 4) * 2)) & 0x03) == 3)
    {
      errno = 3;
      return -1;
    }
  if (x_ < 0 || x_ > ((16 * 4) - 1) ||
      y_ < 0 || y_ > ( 64 - 1))
    {
      errno = 6;
      return -1;
    }
  if ((map [(y_)][(x_) / 4] >> (6 - (((x_) % 4) * 2)) & 0x03) == 3)
    {
      errno = 5;
      return -1;
    }
  for (int y = 0; y < 64; y++)
    {
      for (int x = 0; x < 16 * 4; x++)
        {
   graph[y][x].parent = ((void *)0);
   graph[y][x].x = x;
   graph[y][x].y = y;
   graph[y][x].opened = 0;
   graph[y][x].closed = 0;
   graph[y][x].G = 0;
   graph[y][x].H = 0;
   graph[y][x].F = 0;
        }
    }
  struct _Node *current = &(graph[y][x]);
  current -> x = x;
  current -> y = y;
  current -> H = heuristic (x, y, x_, y_);
  current -> F = current -> H;
  addOpenedNodes (current);
  int loop = 0;
  while (openedNodes.number)
    {
      if (loop > 1000)
 {
   errno = 7;
   return -1;
 }
      loop++;
      heapsort();
      current = openedNodes.node[0];
      if (current -> x == x_ &&
          current -> y == y_)
        {
   makepath (current, x, y);
   errno = 0;
   return 0;
        }
      delOpenedNodes (current);
      addClosedNodes (current);
      int xoffset[] = { -1, 0, 1, -1, 1, -1, 0, 1 };
      int yoffset[] = { -1, -1, -1, 0, 0, 1, 1, 1 };
      for (int i = 0; i < 8; i++)
        {
   int xneighbor = current -> x + xoffset[i];
   int yneighbor = current -> y + yoffset[i];
   if (xneighbor < 0 || xneighbor > ((16 * 4) - 1) ||
              yneighbor < 0 || yneighbor > ( 64 - 1))
     continue;
   if ((map [(yneighbor)][(xneighbor) / 4] >> (6 - (((xneighbor) % 4) * 2)) & 0x03) == 3)
     continue;
   struct _Node *neighbor = &(graph[yneighbor][xneighbor]);
   if (neighbor -> closed)
     continue;
   int G = current -> G + (map [(neighbor -> y)][(neighbor -> x) / 4] >> (6 - (((neighbor -> x) % 4) * 2)) & 0x03);
   int H = heuristic (neighbor -> x, neighbor -> y, x_, y_);
   int F = G + H;
   if (neighbor -> opened)
            {
       if (F < current -> F)
                {
    neighbor -> G = G;
    neighbor -> H = H;
    neighbor -> F = F;
    neighbor -> parent = current;
                }
            }
   else
            {
       neighbor -> G = G;
       neighbor -> H = H;
       neighbor -> F = F;
       neighbor -> parent = current;
       addOpenedNodes (neighbor);
            }
        }
      lists ();
      usleep (5000);
    }
  errno = 8;
  return -1;
}

variable_types: loop int

variable_types:
xoffset
int []

variable_types:
yoffset
int []

variable_types: xneighbor int

variable_types: yneighbor int

variable_types: G int

variable_types: H int

variable_types: F int


getX

decompiled_code:
__int64 getX()
{
return (unsigned int)x;
}

canonical_decompiled_code:
__int64 func0()
{
return (unsigned int)x;
}

original_code: int getX () { return x; }

canonical_original_code: int getX() { return x; }