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));
}


repo: wal-rus/song

decompiled_code:
__int64 __fastcall callback_send_node_index_subscribe(__int64 a1, int a2)
{
__int64 v2; // r13
int v3; // er15
unsigned int v4; // ebx
__int64 v5; // rax
__int64 result; // rax
int v7; // [rsp+Ch] [rbp-3Ch]

v2 = 0LL;
v3 = 1;
do
{
if ( (v3 & a2) != 0 )
{
if ( *((_DWORD *)&VSNodeStorage + 2) )
{
v4 = 0;
do
{
v5 = *((_QWORD *)VSNodeStorage + v4);
if ( v5 && *(_DWORD *)(v5 + 4) == (_DWORD)v2 )
{
v7 = *(_DWORD *)(v5 + 8);
if ( v7 == (unsigned int)verse_session_get_avatar() )
verse_send_node_create(**((unsigned int **)VSNodeStorage + v4), (unsigned int)v2, 1LL);
else
verse_send_node_create(**((unsigned int **)VSNodeStorage + v4), (unsigned int)v2, 0LL);
}
++v4;
}
while ( *((_DWORD *)&VSNodeStorage + 2) > v4 );
}
result = vs_add_new_subscriptor(qword_510[v2]);
}
else
{
result = vs_remove_subscriptor(qword_510[v2]);
}
v3 *= 2;
++v2;
}
while ( v2 != 7 );
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, int a2)
{
__int64 v2; // r13
int v3; // er15
unsigned int v4; // ebx
__int64 v5; // rax
__int64 result; // rax
int v7; // [rsp+Ch] [rbp-3Ch]

v2 = 0LL;
v3 = 1;
do
{
if ( (v3 & a2) != 0 )
{
if ( *((_DWORD *)&VSNodeStorage + 2) )
{
v4 = 0;
do
{
v5 = *((_QWORD *)VSNodeStorage + v4);
if ( v5 && *(_DWORD *)(v5 + 4) == (_DWORD)v2 )
{
v7 = *(_DWORD *)(v5 + 8);
if ( v7 == (unsigned int)verse_session_get_avatar() )
verse_send_node_create(**((unsigned int **)VSNodeStorage + v4), (unsigned int)v2, 1LL);
else
verse_send_node_create(**((unsigned int **)VSNodeStorage + v4), (unsigned int)v2, 0LL);
}
++v4;
}
while ( *((_DWORD *)&VSNodeStorage + 2) > v4 );
}
result = vs_add_new_subscriptor(qword_510[v2]);
}
else
{
result = vs_remove_subscriptor(qword_510[v2]);
}
v3 *= 2;
++v2;
}
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:
i
unsigned int

variable_types:
j
unsigned int

variable_types:
pow
unsigned int

return_type: void

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 vs_init_node_storage()
{
char *v0; // rbx
__int64 result; // rax

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

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

VSNodeStorage = malloc(0x80uLL);
*(_QWORD *)VSNodeStorage = 0LL;
dword_508 = 0;
dword_50C = 16;
v0 = (char *)qword_510;
do
{
result = vs_create_subscription_list();
*(_QWORD *)v0 = result;
v0 += 8;
}
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; // ebx
_QWORD *v3; // rdx
unsigned int v4; // eax
unsigned int v5; // ebp
unsigned int v7; // eax

v2 = dword_508;
if ( dword_508 )
{
v3 = VSNodeStorage;
v4 = 0;
while ( *v3 )
{
++v4;
++v3;
if ( v4 == dword_508 )
goto LABEL_7;
}
v2 = v4;
}
LABEL_7:
v5 = dword_50C;
if ( dword_50C <= v2 )
{
dword_50C += 16;
VSNodeStorage = realloc(VSNodeStorage, 8LL * (v5 + 16));
if ( v5 < dword_50C )
{
do
{
v7 = v5++;
*((_QWORD *)VSNodeStorage + v7) = 0LL;
}
while ( *((_DWORD *)&VSNodeStorage + 3) > v5 );
}
}
*((_QWORD *)VSNodeStorage + v2) = a1;
if ( dword_508 <= v2 )
dword_508 = v2 + 1;
*a1 = v2;
a1[1] = a2;
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func2(unsigned int *a1, unsigned int a2)
{
unsigned int v2; // ebx
_QWORD *v3; // rdx
unsigned int v4; // eax
unsigned int v5; // ebp
unsigned int v7; // eax

v2 = dword_508;
if ( dword_508 )
{
v3 = VSNodeStorage;
v4 = 0;
while ( *v3 )
{
++v4;
++v3;
if ( v4 == dword_508 )
goto LABEL_7;
}
v2 = v4;
}
LABEL_7:
v5 = dword_50C;
if ( dword_50C <= v2 )
{
dword_50C += 16;
VSNodeStorage = realloc(VSNodeStorage, 8LL * (v5 + 16));
if ( v5 < dword_50C )
{
do
{
v7 = v5++;
*((_QWORD *)VSNodeStorage + v7) = 0LL;
}
while ( *((_DWORD *)&VSNodeStorage + 3) > v5 );
}
}
*((_QWORD *)VSNodeStorage + v2) = a1;
if ( dword_508 <= v2 )
dword_508 = v2 + 1;
*a1 = v2;
a1[1] = a2;
return v2;
}

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

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; }


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

result = 0LL;
if ( dword_508 > 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 ( dword_508 > 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 ( dword_508 > a1 )
result = *((_QWORD *)VSNodeStorage + a1);
return result;
}

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

result = 0LL;
if ( dword_508 > 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
unsigned int v3; // ebp
int v4; // er13
unsigned int v5; // ebx
__int64 v6; // rbp

v2 = vs_get_node_head(a2);
if ( v2 )
{
*((_QWORD *)VSNodeStorage + a2) = 0LL;
v3 = *(_DWORD *)(v2 + 4);
switch ( v3 )
{
case 0u:
vs_o_destroy_node();
goto LABEL_4;
case 1u:
vs_g_destroy_node();
goto LABEL_4;
case 2u:
vs_m_destroy_node();
goto LABEL_4;
case 3u:
vs_b_destroy_node();
goto LABEL_4;
case 4u:
vs_t_destroy_node();
goto LABEL_4;
case 5u:
case 6u:
vs_c_destroy_node();
LABEL_4:
v4 = vs_get_subscript_count(qword_510[v3]);
if ( v4 )
{
v5 = 0;
v6 = v3 + 2LL;
do
{
vs_set_subscript_session(*(&VSNodeStorage + v6), v5);
verse_send_node_destroy(a2);
++v5;
}
while ( v4 != v5 );
}
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", v3);
break;
}
}
return v2;
}

canonical_decompiled_code:
int __fastcall func5(__int64 a1, unsigned int a2)
{
__int64 v2; // rax
unsigned int v3; // ebp
int v4; // er13
unsigned int v5; // ebx
__int64 v6; // rbp

v2 = func4(a2);
if ( v2 )
{
*((_QWORD *)VSNodeStorage + a2) = 0LL;
v3 = *(_DWORD *)(v2 + 4);
switch ( v3 )
{
case 0u:
vs_o_destroy_node();
goto LABEL_4;
case 1u:
vs_g_destroy_node();
goto LABEL_4;
case 2u:
vs_m_destroy_node();
goto LABEL_4;
case 3u:
vs_b_destroy_node();
goto LABEL_4;
case 4u:
vs_t_destroy_node();
goto LABEL_4;
case 5u:
case 6u:
vs_c_destroy_node();
LABEL_4:
v4 = vs_get_subscript_count(qword_510[v3]);
if ( v4 )
{
v5 = 0;
v6 = v3 + 2LL;
do
{
vs_set_subscript_session(*(&VSNodeStorage + v6), v5);
verse_send_node_destroy(a2);
++v5;
}
while ( v4 != v5 );
}
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", v3);
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:
count
unsigned int

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
unsigned int v3; // er15
int v4; // er13
unsigned int i; // 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 = *v2;
v4 = vs_get_subscript_count(qword_510[a2]);
if ( v4 )
{
for ( i = 0; i != v4; ++i )
{
vs_set_subscript_session(*(&VSNodeStorage + a2 + 2), i);
if ( (unsigned int)verse_session_get_avatar() == a1 )
verse_send_node_create(v3, a2, 1LL);
else
verse_send_node_create(v3, a2, 0LL);
}
vs_reset_subscript_session();
}
break;
default:
fprintf(stderr, "Can't create node of unknown type %u\n", a2);
v3 = 0;
break;
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func6(unsigned int a1, unsigned int a2)
{
unsigned int *v2; // rax
unsigned int v3; // er15
int v4; // er13
unsigned int i; // 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 = *v2;
v4 = vs_get_subscript_count(qword_510[a2]);
if ( v4 )
{
for ( i = 0; i != v4; ++i )
{
vs_set_subscript_session(*(&VSNodeStorage + a2 + 2), i);
if ( (unsigned int)verse_session_get_avatar() == a1 )
verse_send_node_create(v3, a2, 1LL);
else
verse_send_node_create(v3, a2, 0LL);
}
vs_reset_subscript_session();
}
break;
default:
fprintf(stderr, "Can't create node of unknown type %u\n", a2);
v3 = 0;
break;
}
return v3;
}

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

variable_types:
name
char *


decompiled_code:
void __fastcall vs_reset_owner(int a1)
{
_QWORD *v1; // rsi
unsigned int v2; // eax
__int64 v3; // rdx

if ( dword_508 )
{
v1 = VSNodeStorage;
v2 = 0;
do
{
v3 = v1[v2];
if ( v3 )
{
if ( *(_DWORD *)(v3 + 8) == a1 )
*(_DWORD *)(v3 + 8) = -1;
}
++v2;
}
while ( *((_DWORD *)&VSNodeStorage + 2) > v2 );
}
}

canonical_decompiled_code:
void __fastcall func9(int a1)
{
_QWORD *v1; // rsi
unsigned int v2; // eax
__int64 v3; // rdx

if ( dword_508 )
{
v1 = VSNodeStorage;
v2 = 0;
do
{
v3 = v1[v2];
if ( v3 )
{
if ( *(_DWORD *)(v3 + 8) == a1 )
*(_DWORD *)(v3 + 8) = -1;
}
++v2;
}
while ( *((_DWORD *)&VSNodeStorage + 2) > v2 );
}
}

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;
}


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; // rbx
_QWORD *v2; // rax
void *v3; // rdi
_QWORD *v4; // rax
void *v5; // rdi

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

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

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

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:
size_t __fastcall createNode(int a1, const char *a2)
{
__int64 v2; // rbx
size_t result; // rax
int v4; // ebp
void *v5; // rdi
char *v6; // rdi
void *v7; // rax
int *v8; // rax
int *v9; // rax

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

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

v2 = getNode();
if ( !v2 )
{
v7 = malloc(0x18uLL);
v2 = (__int64)v7;
if ( !v7 )
{
perror("malloc");
v8 = _errno_location();
exit(*v8);
}
addNode(v7);
*(_DWORD *)v2 = a1;
}
result = strlen(a2);
v4 = result;
if ( (_DWORD)result )
{
v5 = *(void **)(v2 + 8);
if ( v5 )
free(v5);
v6 = (char *)malloc(v4);
*(_QWORD *)(v2 + 8) = v6;
if ( !v6 )
{
perror("malloc");
v9 = _errno_location();
exit(*v9);
}
result = (size_t)strncpy(v6, a2, v4);
}
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:
size_t __fastcall createEdge(char *src, int a2, const char *a3, int a4, const char *a5)
{
void *v8; // rax
void *v9; // rbx
int v10; // eax
size_t v11; // rbp
char *v12; // rdi
int *v14; // rax
int *v15; // rax

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

canonical_decompiled_code:
size_t __fastcall func3(char *src, int a2, const char *a3, int a4, const char *a5)
{
void *v8; // rax
void *v9; // rbx
int v10; // eax
size_t v11; // rbp
char *v12; // rdi
int *v14; // rax
int *v15; // rax

v8 = malloc(0x18uLL);
if ( !v8 )
{
perror("malloc");
v14 = _errno_location();
exit(*v14);
}
v9 = v8;
addEdge(v8);
v10 = strlen(src);
if ( v10 )
{
v11 = v10;
v12 = (char *)malloc(v10);
*((_QWORD *)v9 + 1) = v12;
if ( !v12 )
{
perror("malloc");
v15 = _errno_location();
exit(*v15);
}
strncpy(v12, src, v11);
}
*(_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
__int64 v4[17]; // [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;
v4[8] = 0LL;
v4[9] = 0LL;
v4[10] = 0LL;
v4[11] = 0LL;
v4[12] = 0LL;
v4[13] = 0LL;
v4[14] = 0LL;
v4[15] = 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)
{
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, 37LL) == -1 )
{
perror("findpath");
exit(1);
}
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, 12LL) == -1 )
{
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)
{
int v2; // eax
__int64 result; // rax

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

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

v2 = step_0;
if ( step_0 >= pathlength_ )
{
step_0 = 0;
errno = 1;
result = 0xFFFFFFFFLL;
}
else
{
*a1 = *((_DWORD *)&path_ + 2 * step_0);
*a2 = *((_DWORD *)&path_ + 2 * v2 + 1);
step_0 = v2 + 1;
errno = 0;
result = 0LL;
}
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, int a2, int a3)
{
unsigned __int16 v4; // r14
int v5; // ebx
__int64 result; // rax

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

canonical_decompiled_code:
__int64 __fastcall func2(__int16 a1, int a2, int a3)
{
unsigned __int16 v4; // r14
int v5; // ebx
__int64 result; // rax

v4 = 8 * a1;
do
{
v5 = 8 * a2;
do
result = func1(v4, v5++, a3);
while ( 8 * (_WORD)a2 + 8 != (_WORD)v5 );
++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; // eax
__int64 v2; // rbx
int v3; // eax

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

canonical_decompiled_code:
__int64 func4()
{
__int64 v0; // rbx
int v1; // eax
__int64 v2; // rbx
int v3; // eax

if ( openedNodes > 0 )
{
v0 = 0LL;
do
{
v1 = SDL_MapRGB(*(_QWORD *)(screen + 8), 52LL, 101LL, 164LL);
func2(
*(_WORD *)(*((_QWORD *)&openedNodes + v0 + 1) + 8LL),
*(unsigned __int16 *)(*((_QWORD *)&openedNodes + v0 + 1) + 12LL),
v1);
++v0;
}
while ( openedNodes > (int)v0 );
}
if ( closedNodes > 0 )
{
v2 = 0LL;
do
{
v3 = SDL_MapRGB(*(_QWORD *)(screen + 8), 196LL, 160LL, 0LL);
func2(
*(_WORD *)(*((_QWORD *)&closedNodes + v2 + 1) + 8LL),
*(unsigned __int16 *)(*((_QWORD *)&closedNodes + v2 + 1) + 12LL),
v3);
++v2;
}
while ( closedNodes > (int)v2 );
}
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
int v2; // ebx
int v3; // eax

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

canonical_decompiled_code:
__int64 func6()
{
__int64 v0; // rbx
int v1; // eax
int v2; // ebx
int v3; // eax

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

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

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

*(_DWORD *)(a1 + 16) = 42;
LODWORD(result) = LODWORD(openedNodes[0])++;
result = (int)result;
openedNodes[(int)result + 1] = a1;
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
int v5; // ecx

*(_DWORD *)(a1 + 16) = 0;
result = LODWORD(openedNodes[0]);
v2 = LODWORD(openedNodes[0]) - 1;
LODWORD(openedNodes[0]) = v2;
if ( v2 > 0 )
{
v3 = *(_QWORD *)(a1 + 8);
v4 = (unsigned int)(result - 2);
for ( result = 0LL; ; ++result )
{
v5 = 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
int v5; // ecx

*(_DWORD *)(a1 + 16) = 0;
result = LODWORD(openedNodes[0]);
v2 = LODWORD(openedNodes[0]) - 1;
LODWORD(openedNodes[0]) = v2;
if ( v2 > 0 )
{
v3 = *(_QWORD *)(a1 + 8);
v4 = (unsigned int)(result - 2);
for ( result = 0LL; ; ++result )
{
v5 = 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

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

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

*(_DWORD *)(a1 + 20) = 42;
LODWORD(result) = LODWORD(closedNodes[0])++;
result = (int)result;
closedNodes[(int)result + 1] = a1;
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)
{
int v4; // eax
__int64 v5; // rcx
int v6; // edx
int v7; // er13
int v8; // er14
int v9; // ebp
__int64 i; // rbx
__int64 result; // rax
int v12; // eax
int v13; // edx

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

canonical_decompiled_code:
__int64 __fastcall func4(__int64 *a1, int a2, int a3)
{
int v4; // eax
__int64 v5; // rcx
int v6; // edx
int v7; // er13
int v8; // er14
int v9; // ebp
__int64 i; // rbx
__int64 result; // rax
int v12; // eax
int v13; // edx

pathlength = 0;
while ( 1 )
{
v6 = *((_DWORD *)a1 + 2);
if ( v6 == a2 && *((_DWORD *)a1 + 3) == a3 )
break;
v4 = pathlength;
v5 = pathlength;
LODWORD(path[pathlength]) = v6;
HIDWORD(path[v5]) = *((_DWORD *)a1 + 3);
pathlength = v4 + 1;
a1 = (__int64 *)*a1;
}
if ( pathlength <= 3 )
{
LODWORD(result) = pathlength_++;
result = (int)result;
path_[(int)result] = path[0];
}
else
{
v7 = path[0];
v8 = HIDWORD(path[0]);
v9 = pathlength - 1;
for ( i = pathlength - 3; LODWORD(path[i]) != v7 || HIDWORD(path[i]) != v8; --i )
{
if ( !(unsigned int)func3(path[(int)i], path[v9]) )
{
v9 = i + 1;
v12 = pathlength_++;
path_[v12] = path[(int)i + 1];
}
}
v13 = pathlength_++;
result = path[(int)i];
path_[v13] = result;
}
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 v3; // ebx

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

canonical_decompiled_code:
__int64 __fastcall func6(int a1, int a2)
{
__int64 result; // rax
int v3; // ebx

result = (unsigned int)(2 * a1 + 1);
if ( a2 > (int)result )
{
while ( 1 )
{
v3 = 2 * a1 + 2;
if ( v3 >= a2 )
{
v3 = result;
}
else if ( *(_DWORD *)(openedNodes[v3 + 1] + 32) <= *(_DWORD *)(openedNodes[(int)result + 1] + 32) )
{
v3 = result;
}
result = *(unsigned int *)(openedNodes[v3 + 1] + 32);
if ( *(_DWORD *)(openedNodes[a1 + 1] + 32) >= (int)result )
break;
func5(a1, v3);
result = (unsigned int)(2 * v3 + 1);
if ( (int)result >= a2 )
break;
a1 = v3;
}
}
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; // ebx
int v1; // edi
__int64 result; // rax
int v3; // ebx
int v4; // esi

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

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

v0 = SLODWORD(openedNodes[0]) / 2 - 1;
if ( v0 >= 0 )
{
do
{
v1 = v0--;
func6(v1, openedNodes[0]);
}
while ( v0 != -1 );
}
result = LODWORD(openedNodes[0]);
v3 = LODWORD(openedNodes[0]) - 1;
if ( LODWORD(openedNodes[0]) - 1 > 0 )
{
do
{
func5(v3, 0);
v4 = v3--;
result = func6(0, v4);
}
while ( v3 );
}
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

decompiled_code:
__int64 __fastcall findpath(int a1, int a2, int a3, unsigned int a4)
{
int v4; // ebx
unsigned int v5; // er14
__int64 *v6; // rsi
int i; // ecx
__int64 *v8; // rax
int j; // edx
__int64 v10; // rdx
int v11; // eax
__int64 v12; // rcx
__int64 v13; // rdx
__int64 result; // rax
__int64 v15; // r8
__int64 v16; // rdx
__int64 k; // r15
int v18; // ebx
int v19; // ebp
int v20; // esi
int v21; // edi
int v22; // er12
int v23; // edx
int v24; // esi
__int64 v25; // rdx
_DWORD *v26; // r14
int v31; // [rsp+2Ch] [rbp-7Ch]
int v32[8]; // [rsp+30h] [rbp-78h]
int v33[22]; // [rsp+50h] [rbp-58h]

v4 = a3;
v5 = a4;
printf("End \tx = %d\ty = %d\n", (unsigned int)a3, a4);
LODWORD(openedNodes[0]) = 0;
LODWORD(closedNodes[0]) = 0;
pathlength = 0;
pathlength_ = 0;
if ( v4 == a1 && v5 == a2 )
{
errno = 2;
result = 0xFFFFFFFFLL;
}
else if ( (unsigned int)a1 > 0x3F || (unsigned int)a2 > 0x3F )
{
errno = 4;
result = 0xFFFFFFFFLL;
}
else if ( ((map[16 * a2 + (a1 >> 2)] >> (2
* (((unsigned int)(a1 >> 31) >> 30)
- ((a1 + ((unsigned int)(a1 >> 31) >> 30)) & 3))
+ 6)) & 3) == 3 )
{
errno = 3;
result = 0xFFFFFFFFLL;
}
else if ( (unsigned int)a3 > 0x3F || a4 > 0x3F )
{
errno = 6;
result = 0xFFFFFFFFLL;
}
else if ( ((map[16 * a4 + (a3 >> 2)] >> (2
* (((unsigned int)(a3 >> 31) >> 30)
- ((a3 + ((unsigned int)(a3 >> 31) >> 30)) & 3))
+ 6)) & 3) == 3 )
{
errno = 5;
result = 0xFFFFFFFFLL;
}
else
{
v6 = graph;
for ( i = 0; i != 64; ++i )
{
v8 = v6;
for ( j = 0; j != 64; ++j )
{
*v8 = 0LL;
*((_DWORD *)v8 + 2) = j;
*((_DWORD *)v8 + 3) = i;
*((_DWORD *)v8 + 4) = 0;
*((_DWORD *)v8 + 5) = 0;
*((_DWORD *)v8 + 6) = 0;
*((_DWORD *)v8 + 7) = 0;
*((_DWORD *)v8 + 8) = 0;
v8 += 5;
}
v6 += 1280;
}
v10 = 5LL * a1;
LODWORD(graph[1280 * a2 + 1 + v10]) = a1;
HIDWORD(graph[1280 * a2 + 1 + v10]) = a2;
v11 = heuristic(a1, a2, a3, a4);
v12 = 5LL * a1;
HIDWORD(graph[1280 * a2 + 3 + v12]) = v11;
v13 = 1280LL * a2;
LODWORD(graph[v12 + 4 + v13]) = v11;
addOpenedNodes((__int64)&graph[5 * a1 + v13]);
v31 = 1001;
if ( LODWORD(openedNodes[0]) )
{
while ( 1 )
{
heapsort();
v26 = (_DWORD *)openedNodes[1];
if ( v26[2] == a3 && v26[3] == a4 )
break;
delOpenedNodes(openedNodes[1]);
addClosedNodes((__int64)v26);
v32[0] = -1;
v32[1] = 0;
v32[2] = 1;
v32[3] = -1;
v32[4] = 1;
v32[5] = -1;
v32[6] = 0;
v32[7] = 1;
v33[0] = -1;
v33[1] = -1;
v33[2] = -1;
v33[3] = 0;
v33[4] = 0;
v33[5] = 1;
v33[6] = 1;
v33[7] = 1;
for ( k = 0LL; k != 8; ++k )
{
v18 = v26[2] + v32[k];
v19 = v26[3] + v33[k];
if ( (unsigned int)v18 <= 0x3F
&& (unsigned int)v19 <= 0x3F
&& ((map[16 * v19 + (v18 >> 2)] >> (2 * (3 - v18 % 4))) & 3) != 3
&& !HIDWORD(graph[1280 * v19 + 2 + 5 * v18]) )
{
v20 = HIDWORD(graph[1280 * v19 + 1 + 5 * v18]);
v21 = graph[1280 * v19 + 1 + 5 * v18];
v22 = v26[6] + ((map[16 * v20 + v21 / 4] >> (2 * (3 - v21 % 4))) & 3);
v23 = heuristic(v21, v20, a3, a4);
v24 = v22 + v23;
if ( LODWORD(graph[1280 * v19 + 2 + 5 * v18]) )
{
if ( v26[8] > v24 )
{
LODWORD(graph[1280 * v19 + 3 + 5 * v18]) = v22;
HIDWORD(graph[1280 * v19 + 3 + 5 * v18]) = v23;
v25 = 1280LL * v19;
LODWORD(graph[5 * v18 + 4 + v25]) = v24;
graph[5 * v18 + v25] = (__int64)v26;
}
}
else
{
v15 = 5LL * v18;
LODWORD(graph[1280 * v19 + 3 + v15]) = v22;
HIDWORD(graph[1280 * v19 + 3 + v15]) = v23;
LODWORD(graph[1280 * v19 + 4 + v15]) = v24;
v16 = 1280LL * v19;
graph[v15 + v16] = (__int64)v26;
addOpenedNodes((__int64)&graph[5 * v18 + v16]);
}
}
}
lists();
usleep(0x1388u);
if ( !LODWORD(openedNodes[0]) )
goto LABEL_14;
if ( !--v31 )
{
errno = 7;
return 0xFFFFFFFFLL;
}
}
makepath((__int64 *)openedNodes[1], a1, a2);
errno = 0;
result = 0LL;
}
else
{
LABEL_14:
errno = 8;
result = 0xFFFFFFFFLL;
}
}
return result;
}

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; }


getY

decompiled_code:
__int64 getY()
{
return (unsigned int)y;
}

canonical_decompiled_code:
__int64 func1()
{
return (unsigned int)y;
}

original_code: int getY () { return y; }

canonical_original_code: int getY() { return y; }


hexdump

repo: walimis/usbdump

original_code:
void
hexdump(char *linebuf, void *address, int length)
{
 int n, i;
 unsigned char *buf;
 n = strlen(linebuf);
 buf = address;
 for (i = 0; i < length; i++) {
  if (n > 16383 - 4)
   continue;
  if (i && !(i & 0x01)) {
   linebuf[n++] = ' ';
   linebuf[n] = '\0';
  }
  if (i && !(i & 0x0f)) {
   linebuf[n++] = ' ';
   linebuf[n] = '\0';
  }
  snprintf(linebuf + n, 16383 - n, "%.2x", buf[i]);
  n += 2;
 }
}

canonical_original_code:
void hexdump(char *linebuf, void *address, int length)
{
 int n; int i;
 unsigned char *buf;
 n = strlen(linebuf);
 buf = address;
 for (i = 0; i < length; i++) {
  if (n > 16383 - 4)
   continue;
  if (i && !(i & 0x01)) {
   linebuf[n++] = ' ';
   linebuf[n] = '\0';
  }
  if (i && !(i & 0x0f)) {
   linebuf[n++] = ' ';
   linebuf[n] = '\0';
  }
  snprintf(linebuf + n, 16383 - n, "%.2x", buf[i]);
  n += 2;
 }
}

variable_types:
linebuf
char *

variable_types:
address
void *

variable_types: length int

variable_types: n int

variable_types: i int

variable_types:
buf
unsigned char *


decompiled_code:
void __fastcall process_packet(__int64 a1, __int64 a2)
{
const char *v2; // rax
char *v3; // rbp
__int64 v4; // r13
unsigned int v5; // er12
char v6; // r14
size_t v7; // rax
unsigned int v8; // er14
unsigned int v9; // er15
size_t v10; // rax
__int64 v11; // rbx
char **v12; // rbx
char **v13; // rbx

if ( *(_BYTE *)(a1 + 9) != 2 )
{
if ( *(char *)(a1 + 10) < 0 )
{
if ( *(_BYTE *)(a1 + 8) == 83 )
return;
}
else if ( *(_BYTE *)(a1 + 8) == 67 )
{
return;
}
}
if ( !start_ts && !start_ts_us )
{
start_ts = *(_QWORD *)(a1 + 16);
start_ts_us = *(_DWORD *)(a1 + 24);
}
v2 = (const char *)malloc(0x4000uLL);
v3 = (char *)v2;
*v2 = 0;
v4 = *(_QWORD *)(a1 + 16) - start_ts;
v5 = *(_DWORD *)(a1 + 24) - start_ts_us;
if ( (v5 & 0x80000000) != 0 )
{
--v4;
v5 += 1000000;
}
v6 = *(_BYTE *)(a1 + 10);
v7 = strlen(v2);
if ( v6 < 0 )
snprintf(&v3[v7], 0x3FFF - v7, "%d<-- ", v6 & 0x7F);
else
snprintf(&v3[v7], 0x3FFF - v7, "-->%d ", v6 & 0x7F);
v8 = *(_DWORD *)(a1 + 36);
if ( v8 )
{
v9 = *(_DWORD *)(a1 + 32);
v10 = strlen(v3);
if ( v8 == v9 )
snprintf(&v3[v10], 0x3FFF - v10, "%d: ", v8);
else
snprintf(&v3[v10], 0x3FFF - v10, "%d/%d: ", v8, v9);
hexdump(v3, a2, *(_DWORD *)(a1 + 36));
}
if ( opt_unique_num )
{
if ( unique_ready_2 )
{
if ( strcmp(v3, *(const char **)(lines + 8LL * unique_cnt_1)) )
{
if ( unique_setcnt_0 > 1 )
putchar(10);
if ( unique_cnt_1 > 0 )
{
v11 = 0LL;
do
{
printf("%3ld.%.6d %s\n", v4, v5, *(const char **)(lines + 8 * v11));
free(*(void **)(lines + 8 * v11++));
}
while ( unique_cnt_1 > (int)v11 );
}
printf("%3ld.%.6d %s\n", v4, v5, v3);
v12 = (char **)lines;
*v12 = strdup(v3);
unique_cnt_1 = 0;
unique_setcnt_0 = 0;
unique_ready_2 = 0;
}
}
else
{
v13 = (char **)(lines + 8LL * unique_cnt_1);
*v13 = strdup(v3);
printf("%3ld.%.6d %s\n", v4, v5, v3);
}
if ( ++unique_cnt_1 == opt_unique_num )
{
if ( unique_ready_2 )
{
printf("last %d lines repeated %d times\r", (unsigned int)opt_unique_num, (unsigned int)unique_setcnt_0);
fflush(stdout);
}
unique_ready_2 = 1;
unique_cnt_1 = 0;
++unique_setcnt_0;
}
}
else
{
printf("%3ld.%.6d %s\n", v4, v5, v3);
}
free(v3);
}

canonical_decompiled_code:
void __fastcall func1(__int64 a1, __int64 a2)
{
const char *v2; // rax
char *v3; // rbp
__int64 v4; // r13
unsigned int v5; // er12
char v6; // r14
size_t v7; // rax
unsigned int v8; // er14
unsigned int v9; // er15
size_t v10; // rax
__int64 v11; // rbx
char **v12; // rbx
char **v13; // rbx

if ( *(_BYTE *)(a1 + 9) != 2 )
{
if ( *(char *)(a1 + 10) < 0 )
{
if ( *(_BYTE *)(a1 + 8) == 83 )
return;
}
else if ( *(_BYTE *)(a1 + 8) == 67 )
{
return;
}
}
if ( !start_ts && !start_ts_us )
{
start_ts = *(_QWORD *)(a1 + 16);
start_ts_us = *(_DWORD *)(a1 + 24);
}
v2 = (const char *)malloc(0x4000uLL);
v3 = (char *)v2;
*v2 = 0;
v4 = *(_QWORD *)(a1 + 16) - start_ts;
v5 = *(_DWORD *)(a1 + 24) - start_ts_us;
if ( (v5 & 0x80000000) != 0 )
{
--v4;
v5 += 1000000;
}
v6 = *(_BYTE *)(a1 + 10);
v7 = strlen(v2);
if ( v6 < 0 )
snprintf(&v3[v7], 0x3FFF - v7, "%d<-- ", v6 & 0x7F);
else
snprintf(&v3[v7], 0x3FFF - v7, "-->%d ", v6 & 0x7F);
v8 = *(_DWORD *)(a1 + 36);
if ( v8 )
{
v9 = *(_DWORD *)(a1 + 32);
v10 = strlen(v3);
if ( v8 == v9 )
snprintf(&v3[v10], 0x3FFF - v10, "%d: ", v8);
else
snprintf(&v3[v10], 0x3FFF - v10, "%d/%d: ", v8, v9);
func0(v3, a2, *(_DWORD *)(a1 + 36));
}
if ( opt_unique_num )
{
if ( unique_ready_2 )
{
if ( strcmp(v3, *(const char **)(lines + 8LL * unique_cnt_1)) )
{
if ( unique_setcnt_0 > 1 )
putchar(10);
if ( unique_cnt_1 > 0 )
{
v11 = 0LL;
do
{
printf("%3ld.%.6d %s\n", v4, v5, *(const char **)(lines + 8 * v11));
free(*(void **)(lines + 8 * v11++));
}
while ( unique_cnt_1 > (int)v11 );
}
printf("%3ld.%.6d %s\n", v4, v5, v3);
v12 = (char **)lines;
*v12 = strdup(v3);
unique_cnt_1 = 0;
unique_setcnt_0 = 0;
unique_ready_2 = 0;
}
}
else
{
v13 = (char **)(lines + 8LL * unique_cnt_1);
*v13 = strdup(v3);
printf("%3ld.%.6d %s\n", v4, v5, v3);
}
if ( ++unique_cnt_1 == opt_unique_num )
{
if ( unique_ready_2 )
{
printf("last %d lines repeated %d times\r", (unsigned int)opt_unique_num, (unsigned int)unique_setcnt_0);
fflush(stdout);
}
unique_ready_2 = 1;
unique_cnt_1 = 0;
++unique_setcnt_0;
}
}
else
{
printf("%3ld.%.6d %s\n", v4, v5, v3);
}
free(v3);
}

original_code:
void
process_packet(struct usbmon_packet *hdr, char *data)
{
 static int unique_ready = 0, unique_cnt = 0, unique_setcnt = 0, cnt =
  0;
 int i;
 int64_t ts;
 int32_t ts_us;
 char *linebuf;
 if (hdr->xfer_type != 2) {
  if (hdr->epnum & 0x80) {
   if (hdr->type == 'S')
    return;
  }
  else {
   if (hdr->type == 'C')
    return;
  }
 }
 if (!start_ts && !start_ts_us) {
  start_ts = hdr->ts_sec;
  start_ts_us = hdr->ts_usec;
 }
 linebuf = malloc(16383 + 1);
 linebuf[0] = '\0';
 ts = hdr->ts_sec - start_ts;
 ts_us = hdr->ts_usec - start_ts_us;
 if (ts_us < 0) {
  ts -= 1;
  ts_us = 1000000 + ts_us;
 }
 if (hdr->epnum & 0x80)
  snprintf(linebuf + strlen(linebuf),
    16383 - strlen(linebuf), "%d<-- ",
    hdr->epnum & 0x7f);
 else
  snprintf(linebuf + strlen(linebuf),
    16383 - strlen(linebuf), "-->%d ",
    hdr->epnum & 0x7f);
 if (hdr->len_cap > 0) {
  if (hdr->len_cap == hdr->length)
   snprintf(linebuf + strlen(linebuf),
     16383 - strlen(linebuf), "%d: ",
     hdr->len_cap);
  else
   snprintf(linebuf + strlen(linebuf),
     16383 - strlen(linebuf), "%d/%d: ",
     hdr->len_cap, hdr->length);
  hexdump(linebuf, data, hdr->len_cap);
 }
 if (opt_unique_num) {
  if (!unique_ready) {
   lines[unique_cnt] = strdup(linebuf);
   printf("%3" "l" "d" ".%.6d %s\n", ts, ts_us, linebuf);
  }
  else if (strcmp(linebuf, lines[unique_cnt])) {
   if (unique_setcnt > 1)
    printf("\n");
   for (i = 0; i < unique_cnt; i++) {
    printf("%3" "l" "d" ".%.6d %s\n", ts, ts_us,
           lines[i]);
    free(lines[i]);
   }
   printf("%3" "l" "d" ".%.6d %s\n", ts, ts_us, linebuf);
   lines[0] = strdup(linebuf);
   unique_cnt = 0;
   unique_setcnt = 0;
   unique_ready = 0;
  }
  if (++unique_cnt == opt_unique_num) {
   if (unique_ready) {
    printf("last %d lines repeated %d times\r",
           opt_unique_num, unique_setcnt);
    fflush(stdout);
   }
   unique_ready = 1;
   unique_cnt = 0;
   unique_setcnt++;
  }
 }
 else
  printf("%3" "l" "d" ".%.6d %s\n", ts, ts_us, linebuf);
 free(linebuf);
}

canonical_original_code:
void process_packet(struct usbmon_packet *hdr, char *data)
{
 static int unique_ready = 0; static int unique_cnt = 0; static int unique_setcnt = 0; static int cnt = 0;
 int i;
 long ts;
 int ts_us;
 char *linebuf;
 if (hdr->xfer_type != 2) {
  if (hdr->epnum & 0x80) {
   if (hdr->type == 'S')
    return;
  }
  else {
   if (hdr->type == 'C')
    return;
  }
 }
 if (!start_ts && !start_ts_us) {
  start_ts = hdr->ts_sec;
  start_ts_us = hdr->ts_usec;
 }
 linebuf = malloc(16383 + 1);
 linebuf[0] = '\0';
 ts = hdr->ts_sec - start_ts;
 ts_us = hdr->ts_usec - start_ts_us;
 if (ts_us < 0) {
  ts -= 1;
  ts_us = 1000000 + ts_us;
 }
 if (hdr->epnum & 0x80)
  snprintf(linebuf + strlen(linebuf),
    16383 - strlen(linebuf), "%d<-- ",
    hdr->epnum & 0x7f);
 else
  snprintf(linebuf + strlen(linebuf),
    16383 - strlen(linebuf), "-->%d ",
    hdr->epnum & 0x7f);
 if (hdr->len_cap > 0) {
  if (hdr->len_cap == hdr->length)
   snprintf(linebuf + strlen(linebuf),
     16383 - strlen(linebuf), "%d: ",
     hdr->len_cap);
  else
   snprintf(linebuf + strlen(linebuf),
     16383 - strlen(linebuf), "%d/%d: ",
     hdr->len_cap, hdr->length);
  hexdump(linebuf, data, hdr->len_cap);
 }
 if (opt_unique_num) {
  if (!unique_ready) {
   lines[unique_cnt] = strdup(linebuf);
   printf("%3" "l" "d" ".%.6d %s\n", ts, ts_us, linebuf);
  }
  else if (strcmp(linebuf, lines[unique_cnt])) {
   if (unique_setcnt > 1)
    printf("\n");
   for (i = 0; i < unique_cnt; i++) {
    printf("%3" "l" "d" ".%.6d %s\n", ts, ts_us,
           lines[i]);
    free(lines[i]);
   }
   printf("%3" "l" "d" ".%.6d %s\n", ts, ts_us, linebuf);
   lines[0] = strdup(linebuf);
   unique_cnt = 0;
   unique_setcnt = 0;
   unique_ready = 0;
  }
  if (++unique_cnt == opt_unique_num) {
   if (unique_ready) {
    printf("last %d lines repeated %d times\r",
           opt_unique_num, unique_setcnt);
    fflush(stdout);
   }
   unique_ready = 1;
   unique_cnt = 0;
   unique_setcnt++;
  }
 }
 else
  printf("%3" "l" "d" ".%.6d %s\n", ts, ts_us, linebuf);
 free(linebuf);
}

variable_types: struct usbmon_packet { unsigned long id; unsigned char type; unsigned char xfer_type; unsigned char epnum; unsigned char devnum; unsigned short busnum; char flag_setup; char flag_data; long ts_sec; int ts_usec; int status; unsigned int length; unsigned int len_cap; union { unsigned char setup[8]; struct iso_rec { int error_count; int numdesc; } iso; } s; int interval; int start_frame; unsigned int xfer_flags; unsigned int ndesc; } *

variable_types:
data
char *

variable_types: cnt int

variable_types: ts long

user_defined_types: struct usbmon_packet { unsigned long id; unsigned char type; unsigned char xfer_type; unsigned char epnum; unsigned char devnum; unsigned short busnum; char flag_setup; char flag_data; long ts_sec; int ts_usec; int status; unsigned int length; unsigned int len_cap; union { unsigned char setup[8]; struct iso_rec iso; } s; int interval; int start_frame; unsigned int xfer_flags; unsigned int ndesc; }


decompiled_code:
int __fastcall usb_sniff(unsigned int a1, int a2)
{
int v3; // eax
int v4; // er14
int v5; // eax
unsigned int v6; // ebx
_BYTE *v7; // r12
int v8; // ebp
int *v9; // rax
char *v10; // rax
int result; // eax
int *v12; // rax
char *v13; // rax
int *v14; // rax
char *v15; // rax
__int64 v16; // rbx
__int64 v17; // rax
__int64 v18; // rdi
int v19[32]; // [rsp+0h] [rbp-108h] BYREF
char s[64]; // [rsp+80h] [rbp-88h] BYREF
int *v21; // [rsp+C0h] [rbp-48h] BYREF
unsigned int v22; // [rsp+C8h] [rbp-40h]
int v23; // [rsp+CCh] [rbp-3Ch]

snprintf(s, 0x3FuLL, "%s%d", "/dev/usbmon", a1);
v3 = open(s, 0);
if ( v3 == -1 )
{
v9 = _errno_location();
v10 = strerror(*v9);
result = printf("unable to open %s: %s\n", s, v10);
}
else
{
v4 = v3;
v5 = ioctl(v3, 0x9205uLL);
v6 = v5;
if ( v5 <= 0 )
{
v12 = _errno_location();
v13 = strerror(*v12);
result = printf("failed to determine kernel USB buffer size: %s\n", v13);
}
else
{
v7 = mmap(0LL, v5, 1, 1, v4, 0LL);
if ( v7 != (_BYTE *)-1LL )
{
if ( opt_unique_num )
lines = (__int64)malloc(8LL * opt_unique_num);
v8 = 0;
while ( 1 )
{
do
{
v21 = v19;
v22 = 32;
v23 = v8;
ioctl(v4, 0xC0109207uLL, &v21);
v8 = v22;
}
while ( !v22 );
v16 = 0LL;
do
{
v17 = (unsigned int)v19[v16];
v18 = (__int64)&v7[v17];
if ( v7[v17 + 8] != 64
&& (!a1 || *(unsigned __int16 *)(v18 + 12) == a1)
&& (!a2 || *(unsigned __int8 *)(v18 + 11) == a2) )
{
process_packet(v18, (__int64)&v7[v17 + 64]);
}
++v16;
}
while ( v22 > (unsigned int)v16 );
}
}
v14 = _errno_location();
v15 = strerror(*v14);
result = printf("unable to mmap %d bytes: %s\n", v6, v15);
}
}
return result;
}

canonical_decompiled_code:
int __fastcall func2(unsigned int a1, int a2)
{
int v3; // eax
int v4; // er14
int v5; // eax
unsigned int v6; // ebx
_BYTE *v7; // r12
int v8; // ebp
int *v9; // rax
char *v10; // rax
int result; // eax
int *v12; // rax
char *v13; // rax
int *v14; // rax
char *v15; // rax
__int64 v16; // rbx
__int64 v17; // rax
__int64 v18; // rdi
int v19[32]; // [rsp+0h] [rbp-108h] BYREF
char s[64]; // [rsp+80h] [rbp-88h] BYREF
int *v21; // [rsp+C0h] [rbp-48h] BYREF
unsigned int v22; // [rsp+C8h] [rbp-40h]
int v23; // [rsp+CCh] [rbp-3Ch]

snprintf(s, 0x3FuLL, "%s%d", "/dev/usbmon", a1);
v3 = open(s, 0);
if ( v3 == -1 )
{
v9 = _errno_location();
v10 = strerror(*v9);
result = printf("unable to open %s: %s\n", s, v10);
}
else
{
v4 = v3;
v5 = ioctl(v3, 0x9205uLL);
v6 = v5;
if ( v5 <= 0 )
{
v12 = _errno_location();
v13 = strerror(*v12);
result = printf("failed to determine kernel USB buffer size: %s\n", v13);
}
else
{
v7 = mmap(0LL, v5, 1, 1, v4, 0LL);
if ( v7 != (_BYTE *)-1LL )
{
if ( opt_unique_num )
lines = (__int64)malloc(8LL * opt_unique_num);
v8 = 0;
while ( 1 )
{
do
{
v21 = v19;
v22 = 32;
v23 = v8;
ioctl(v4, 0xC0109207uLL, &v21);
v8 = v22;
}
while ( !v22 );
v16 = 0LL;
do
{
v17 = (unsigned int)v19[v16];
v18 = (__int64)&v7[v17];
if ( v7[v17 + 8] != 64
&& (!a1 || *(unsigned __int16 *)(v18 + 12) == a1)
&& (!a2 || *(unsigned __int8 *)(v18 + 11) == a2) )
{
func1(v18, (__int64)&v7[v17 + 64]);
}
++v16;
}
while ( v22 > (unsigned int)v16 );
}
}
v14 = _errno_location();
v15 = strerror(*v14);
result = printf("unable to mmap %d bytes: %s\n", v6, v15);
}
}
return result;
}

original_code:
void
usb_sniff(int bus, int address)
{
 struct mon_mfetch_arg mfetch;
 struct usbmon_packet *hdr;
 int kbuf_len, fd, nflush, i;
 char *mbuf, path[64];
 uint32_t vec[32];
 snprintf(path, 63, "%s%d", "/dev/usbmon", bus);
 if ((fd = open(path, 00)) == -1) {
  printf("unable to open %s: %s\n", path, strerror((*__errno_location ())));
  return;
 }
 if ((kbuf_len = ioctl(fd, (((0U) << (((0 +8)+8)+14)) | (((0x92)) << (0 +8)) | (((5)) << 0) | ((0) << ((0 +8)+8))))) <= 0) {
  printf("failed to determine kernel USB buffer size: %s\n",
         strerror((*__errno_location ())));
  return;
 }
 if ((mbuf =
      mmap(((void *)0), kbuf_len, 0x1, 0x01, fd,
    0)) == ((void *) -1)) {
  printf("unable to mmap %d bytes: %s\n", kbuf_len,
         strerror((*__errno_location ())));
  return;
 }
 if (opt_unique_num)
  lines = malloc(opt_unique_num * sizeof(char *));
 nflush = 0;
 while (1) {
  mfetch.offvec = vec;
  mfetch.nfetch = 32;
  mfetch.nflush = nflush;
  ioctl(fd, (((2U|1U) << (((0 +8)+8)+14)) | (((0x92)) << (0 +8)) | (((7)) << 0) | ((((sizeof(struct mon_mfetch_arg)))) << ((0 +8)+8))), &mfetch);
  nflush = mfetch.nfetch;
  for (i = 0; i < mfetch.nfetch; i++) {
   hdr = (struct usbmon_packet *) &mbuf[vec[i]];
   if (hdr->type == '@')
    continue;
   if ((bus != 0 && hdr->busnum != bus) ||
    ((address != 0) && (hdr->devnum != address)))
    continue;
   process_packet(hdr,
           &mbuf[vec[i]] +
           sizeof(struct usbmon_packet));
  }
 }
 free(lines);
 munmap(mbuf, kbuf_len);
 ioctl(fd, (((0U) << (((0 +8)+8)+14)) | (((0x92)) << (0 +8)) | (((8)) << 0) | ((0) << ((0 +8)+8))), mfetch.nfetch);
 close(fd);
}

canonical_original_code:
void usb_sniff(int bus, int address)
{
 struct mon_mfetch_arg mfetch;
 struct usbmon_packet *hdr;
 int kbuf_len; int fd; int nflush; int i;
 char *mbuf; char path[64];
 unsigned int vec[32];
 snprintf(path, 63, "%s%d", "/dev/usbmon", bus);
 if ((fd = open(path, 00)) == -1) {
  printf("unable to open %s: %s\n", path, strerror((*__errno_location ())));
  return;
 }
 if ((kbuf_len = ioctl(fd, (((0U) << (((0 +8)+8)+14)) | (((0x92)) << (0 +8)) | (((5)) << 0) | ((0) << ((0 +8)+8))))) <= 0) {
  printf("failed to determine kernel USB buffer size: %s\n",
         strerror((*__errno_location ())));
  return;
 }
 if ((mbuf =
      mmap(((void *)0), kbuf_len, 0x1, 0x01, fd,
    0)) == ((void *) -1)) {
  printf("unable to mmap %d bytes: %s\n", kbuf_len,
         strerror((*__errno_location ())));
  return;
 }
 if (opt_unique_num)
  lines = malloc(opt_unique_num * sizeof(char *));
 nflush = 0;
 while (1) {
  mfetch.offvec = vec;
  mfetch.nfetch = 32;
  mfetch.nflush = nflush;
  ioctl(fd, (((2U|1U) << (((0 +8)+8)+14)) | (((0x92)) << (0 +8)) | (((7)) << 0) | ((((sizeof(struct mon_mfetch_arg)))) << ((0 +8)+8))), &mfetch);
  nflush = mfetch.nfetch;
  for (i = 0; i < mfetch.nfetch; i++) {
   hdr = (struct usbmon_packet *) &mbuf[vec[i]];
   if (hdr->type == '@')
    continue;
   if ((bus != 0 && hdr->busnum != bus) ||
    ((address != 0) && (hdr->devnum != address)))
    continue;
   process_packet(hdr,
           &mbuf[vec[i]] +
           sizeof(struct usbmon_packet));
  }
 }
 free(lines);
 munmap(mbuf, kbuf_len);
 ioctl(fd, (((0U) << (((0 +8)+8)+14)) | (((0x92)) << (0 +8)) | (((8)) << 0) | ((0) << ((0 +8)+8))), mfetch.nfetch);
 close(fd);
}

variable_types: bus int

variable_types: address int

variable_types: struct mon_mfetch_arg { unsigned int *offvec; unsigned int nfetch; unsigned int nflush; }

variable_types: fd int

variable_types: nflush int

variable_types:
mbuf
char *

variable_types:
path
char [64]

variable_types:
vec
unsigned int [32]

user_defined_types: struct iso_rec { int error_count; int numdesc; }


decompiled_code:
__int64 __fastcall check_device(__int64 a1, __int64 a2, _DWORD *a3, _DWORD *a4)
{
const char *v6; // rbp
int v7; // eax
unsigned int v8; // er13
int v9; // ebx
int v11; // eax
int v12; // ebx
int v13; // eax
int v14; // eax
int buf; // [rsp+6h] [rbp-C2h] BYREF
char v16; // [rsp+Ah] [rbp-BEh]
char s1[4]; // [rsp+Bh] [rbp-BDh] BYREF
char v18; // [rsp+Fh] [rbp-B9h]
char s[184]; // [rsp+10h] [rbp-B8h] BYREF

*(_DWORD *)s1 = *(_DWORD *)a2;
v18 = 0;
v6 = (const char *)(a1 + 19);
sprintf(s, "%s/%s/idVendor", "/sys/bus/usb/devices", (const char *)(a1 + 19));
v7 = open(s, 0);
v8 = 0;
if ( v7 != -1 )
{
v9 = v7;
v16 = 0;
if ( read(v7, &buf, 4uLL) == 4 && (v8 = strncmp(s1, (const char *)&buf, 4uLL)) == 0 )
{
sprintf(s, "%s/%s/idProduct", "/sys/bus/usb/devices", v6);
v11 = open(s, 0);
v12 = v11;
if ( v11 != -1 )
{
v16 = 0;
if ( read(v11, &buf, 4uLL) == 4 && !strncmp((const char *)(a2 + 5), (const char *)&buf, 4uLL) )
{
sprintf(s, "%s/%s/busnum", "/sys/bus/usb/devices", v6);
v13 = open(s, 0);
v8 = 0;
if ( v13 != -1 )
{
buf = 0;
v16 = 0;
read(v13, &buf, 4uLL);
*a3 = strtol((const char *)&buf, 0LL, 10);
sprintf(s, "%s/%s/devnum", "/sys/bus/usb/devices", v6);
v14 = open(s, 0);
if ( v14 != -1 )
{
buf = 0;
v16 = 0;
read(v14, &buf, 4uLL);
*a4 = strtol((const char *)&buf, 0LL, 10);
v8 = 1;
}
}
}
else
{
close(v12);
}
}
}
else
{
close(v9);
v8 = 0;
}
}
return v8;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, __int64 a2, _DWORD *a3, _DWORD *a4)
{
const char *v6; // rbp
int v7; // eax
unsigned int v8; // er13
int v9; // ebx
int v11; // eax
int v12; // ebx
int v13; // eax
int v14; // eax
int buf; // [rsp+6h] [rbp-C2h] BYREF
char v16; // [rsp+Ah] [rbp-BEh]
char s1[4]; // [rsp+Bh] [rbp-BDh] BYREF
char v18; // [rsp+Fh] [rbp-B9h]
char s[184]; // [rsp+10h] [rbp-B8h] BYREF

*(_DWORD *)s1 = *(_DWORD *)a2;
v18 = 0;
v6 = (const char *)(a1 + 19);
sprintf(s, "%s/%s/idVendor", "/sys/bus/usb/devices", (const char *)(a1 + 19));
v7 = open(s, 0);
v8 = 0;
if ( v7 != -1 )
{
v9 = v7;
v16 = 0;
if ( read(v7, &buf, 4uLL) == 4 && (v8 = strncmp(s1, (const char *)&buf, 4uLL)) == 0 )
{
sprintf(s, "%s/%s/idProduct", "/sys/bus/usb/devices", v6);
v11 = open(s, 0);
v12 = v11;
if ( v11 != -1 )
{
v16 = 0;
if ( read(v11, &buf, 4uLL) == 4 && !strncmp((const char *)(a2 + 5), (const char *)&buf, 4uLL) )
{
sprintf(s, "%s/%s/busnum", "/sys/bus/usb/devices", v6);
v13 = open(s, 0);
v8 = 0;
if ( v13 != -1 )
{
buf = 0;
v16 = 0;
read(v13, &buf, 4uLL);
*a3 = strtol((const char *)&buf, 0LL, 10);
sprintf(s, "%s/%s/devnum", "/sys/bus/usb/devices", v6);
v14 = open(s, 0);
if ( v14 != -1 )
{
buf = 0;
v16 = 0;
read(v14, &buf, 4uLL);
*a4 = strtol((const char *)&buf, 0LL, 10);
v8 = 1;
}
}
}
else
{
close(v12);
}
}
}
else
{
close(v9);
v8 = 0;
}
}
return v8;
}

original_code:
int
check_device(struct dirent *de, char *vidpid, int *bus, int *address)
{
 int fd;
 char path[128], vid[5], buf[5];
 memcpy(vid, vidpid, 4);
 vid[4] = '\0';
 sprintf(path, "%s/%s/idVendor", "/sys/bus/usb/devices", de->d_name);
 if ((fd = open(path, 00)) == -1)
  return 0;
 buf[4] = '\0';
 if ((read(fd, buf, 4) != 4) || strncmp(vid, buf, 4)) {
  close(fd);
  return 0;
 }
 sprintf(path, "%s/%s/idProduct", "/sys/bus/usb/devices", de->d_name);
 if ((fd = open(path, 00)) == -1)
  return 0;
 buf[4] = '\0';
 if ((read(fd, buf, 4) != 4) || strncmp(vidpid + 5, buf, 4)) {
  close(fd);
  return 0;
 }
 sprintf(path, "%s/%s/busnum", "/sys/bus/usb/devices", de->d_name);
 if ((fd = open(path, 00)) == -1)
  return 0;
 memset(buf, 0, 5);
 read(fd, buf, 4);
 *bus = strtol(buf, ((void *)0), 10);
 sprintf(path, "%s/%s/devnum", "/sys/bus/usb/devices", de->d_name);
 if ((fd = open(path, 00)) == -1)
  return 0;
 memset(buf, 0, 5);
 read(fd, buf, 4);
 *address = strtol(buf, ((void *)0), 10);
 return 1;
}

canonical_original_code:
int check_device(struct dirent *de, char *vidpid, int *bus, int *address)
{
 int fd;
 char path[128]; char vid[5]; char buf[5];
 memcpy(vid, vidpid, 4);
 vid[4] = '\0';
 sprintf(path, "%s/%s/idVendor", "/sys/bus/usb/devices", de->d_name);
 if ((fd = open(path, 00)) == -1)
  return 0;
 buf[4] = '\0';
 if ((read(fd, buf, 4) != 4) || strncmp(vid, buf, 4)) {
  close(fd);
  return 0;
 }
 sprintf(path, "%s/%s/idProduct", "/sys/bus/usb/devices", de->d_name);
 if ((fd = open(path, 00)) == -1)
  return 0;
 buf[4] = '\0';
 if ((read(fd, buf, 4) != 4) || strncmp(vidpid + 5, buf, 4)) {
  close(fd);
  return 0;
 }
 sprintf(path, "%s/%s/busnum", "/sys/bus/usb/devices", de->d_name);
 if ((fd = open(path, 00)) == -1)
  return 0;
 memset(buf, 0, 5);
 read(fd, buf, 4);
 *bus = strtol(buf, ((void *)0), 10);
 sprintf(path, "%s/%s/devnum", "/sys/bus/usb/devices", de->d_name);
 if ((fd = open(path, 00)) == -1)
  return 0;
 memset(buf, 0, 5);
 read(fd, buf, 4);
 *address = strtol(buf, ((void *)0), 10);
 return 1;
}

variable_types: struct dirent { unsigned long d_ino; long d_off; unsigned short d_reclen; unsigned char d_type; char d_name[256]; } *

variable_types:
vidpid
char *

variable_types:
bus
int *

variable_types:
address
int *

variable_types:
path
char [128]

variable_types:
vid
char [5]

variable_types:
buf
char [5]