decompiled_code:
__int64 __fastcall add_neighbor_to_vertex(__int64 a1, int a2, double a3)
{
double *v3; // rbx
_QWORD *v4; // rax
_QWORD *v5; // rdx
__int64 result; // rax
__int64 v7; // rcx
__int64 v8; // rcx

if ( a3 == 0.0 )
{
puts("Error: edge weight must be positive.");
result = 0LL;
}
else
{
v3 = (double *)malloc(0x18uLL);
v4 = malloc(0x18uLL);
v5 = v4;
if ( v3 && v4 )
{
v4[2] = 0LL;
*(_DWORD *)v4 = a2;
*((double *)v4 + 1) = a3;
result = *(_QWORD *)(a1 + 504);
v3[2] = 0.0;
*(_DWORD *)v3 = a2;
v3[1] = a3;
if ( result )
{
do
{
v7 = result;
result = *(_QWORD *)(result + 16);
}
while ( result );
*(_QWORD *)(v7 + 16) = v3;
result = *(_QWORD *)(a1 + 512);
v3[2] = 0.0;
do
{
v8 = result;
result = *(_QWORD *)(result + 16);
}
while ( result );
*(_QWORD *)(v8 + 16) = v5;
v5[2] = 0LL;
}
else
{
*(_QWORD *)(a1 + 504) = v3;
*(_QWORD *)(a1 + 512) = v5;
}
}
else
{
puts("Error: Unable to allocate memory for vertex neighbor.");
result = 1LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, int a2, double a3)
{
double *v3; // rbx
_QWORD *v4; // rax
_QWORD *v5; // rdx
__int64 result; // rax
__int64 v7; // rcx
__int64 v8; // rcx

if ( a3 == 0.0 )
{
puts("Error: edge weight must be positive.");
result = 0LL;
}
else
{
v3 = (double *)malloc(0x18uLL);
v4 = malloc(0x18uLL);
v5 = v4;
if ( v3 && v4 )
{
v4[2] = 0LL;
*(_DWORD *)v4 = a2;
*((double *)v4 + 1) = a3;
result = *(_QWORD *)(a1 + 504);
v3[2] = 0.0;
*(_DWORD *)v3 = a2;
v3[1] = a3;
if ( result )
{
do
{
v7 = result;
result = *(_QWORD *)(result + 16);
}
while ( result );
*(_QWORD *)(v7 + 16) = v3;
result = *(_QWORD *)(a1 + 512);
v3[2] = 0.0;
do
{
v8 = result;
result = *(_QWORD *)(result + 16);
}
while ( result );
*(_QWORD *)(v8 + 16) = v5;
v5[2] = 0LL;
}
else
{
*(_QWORD *)(a1 + 504) = v3;
*(_QWORD *)(a1 + 512) = v5;
}
}
else
{
puts("Error: Unable to allocate memory for vertex neighbor.");
result = 1LL;
}
}
return result;
}

original_code:
int add_neighbor_to_vertex(Vertex *vertex, int newVertexNeighborID, double edgeWeight)
{
    Neighbor *temp,*temp2,*right;
    if (edgeWeight == 0) {
     printf("Error: edge weight must be positive.\n");
     return 0;
    }
    temp = malloc(sizeof(Neighbor));
    temp2 = malloc(sizeof(Neighbor));
    if(temp == ((void *)0) || temp2 == ((void *)0)) {
     printf("Error: Unable to allocate memory for vertex neighbor.\n");
     return 1;
    }
    temp->next = ((void *)0);
    temp->vertexID = newVertexNeighborID;
    temp->weight = edgeWeight;
    temp2->next = ((void *)0);
    temp2->vertexID = newVertexNeighborID;
    temp2->weight = edgeWeight;
    if (vertex->neighbors == ((void *)0)){
     vertex->neighbors = temp;
     vertex->originals = temp2;
     return 0;
    }
    right = vertex->neighbors;
    while(right->next != ((void *)0)) {
     right = right->next;
    }
    right->next = temp;
    right = temp;
    right->next = ((void *)0);
    right = vertex->originals;
    while(right->next != ((void *)0)) {
        right = right->next;
       }
    right->next = temp2;
    right = temp2;
    right->next = ((void *)0);
    return 0;
}

canonical_original_code:
int add_neighbor_to_vertex(struct Vertex *vertex, int newVertexNeighborID, double edgeWeight)
{
    struct Neighbor *temp; struct Neighbor *temp2; struct Neighbor *right;
    if (edgeWeight == 0) {
     printf("Error: edge weight must be positive.\n");
     return 0;
    }
    temp = malloc(sizeof(Neighbor));
    temp2 = malloc(sizeof(Neighbor));
    if(temp == ((void *)0) || temp2 == ((void *)0)) {
     printf("Error: Unable to allocate memory for vertex neighbor.\n");
     return 1;
    }
    temp->next = ((void *)0);
    temp->vertexID = newVertexNeighborID;
    temp->weight = edgeWeight;
    temp2->next = ((void *)0);
    temp2->vertexID = newVertexNeighborID;
    temp2->weight = edgeWeight;
    if (vertex->neighbors == ((void *)0)){
     vertex->neighbors = temp;
     vertex->originals = temp2;
     return 0;
    }
    right = vertex->neighbors;
    while(right->next != ((void *)0)) {
     right = right->next;
    }
    right->next = temp;
    right = temp;
    right->next = ((void *)0);
    right = vertex->originals;
    while(right->next != ((void *)0)) {
        right = right->next;
       }
    right->next = temp2;
    right = temp2;
    right->next = ((void *)0);
    return 0;
}

variable_types: newVertexNeighborID int

variable_types: edgeWeight double

variable_types: struct Neighbor { int vertexID; double weight; struct Neighbor *next; } *


GetVertexNeighbors

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

result = *a1;
if ( *a1 )
{
while ( *(_DWORD *)(result + 500) != a2 )
{
result = *(_QWORD *)(result + 520);
if ( !result )
return result;
}
result = *(_QWORD *)(result + 504);
}
return result;
}

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

result = *a1;
if ( *a1 )
{
while ( *(_DWORD *)(result + 500) != a2 )
{
result = *(_QWORD *)(result + 520);
if ( !result )
return result;
}
result = *(_QWORD *)(result + 504);
}
return result;
}

original_code:
Neighbor * GetVertexNeighbors(Graph * graph, int vertexID) {
 Vertex * vertex = graph->vertices;
 while(vertex != ((void *)0)) {
  if(vertex->vertexID == vertexID) {
   return (vertex->neighbors);
  }
  vertex = vertex->next;
 }
 return ((void *)0);
}

canonical_original_code:
struct Neighbor *GetVertexNeighbors(struct Graph *graph, int vertexID) {
 struct Vertex *vertex = graph->vertices;
 while(vertex != ((void *)0)) {
  if(vertex->vertexID == vertexID) {
   return (vertex->neighbors);
  }
  vertex = vertex->next;
 }
 return ((void *)0);
}

variable_types: struct Graph { struct Vertex { char vertexName[500]; int vertexID; struct Neighbor *neighbors; struct Neighbor *originals; struct Vertex *next; int clusterID; } *vertices; int vertexCounter; int edgeCounter; int edgeOriginal; double C; } *

variable_types: vertexID int

variable_types: struct Vertex { char vertexName[500]; int vertexID; struct Neighbor { int vertexID; double weight; struct Neighbor *next; } *neighbors; struct Neighbor *originals; struct Vertex *next; int clusterID; } *

user_defined_types: struct Graph { struct Vertex *vertices; int vertexCounter; int edgeCounter; int edgeOriginal; double C; }


GetVertexOriginals

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

result = *a1;
if ( *a1 )
{
while ( *(_DWORD *)(result + 500) != a2 )
{
result = *(_QWORD *)(result + 520);
if ( !result )
return result;
}
result = *(_QWORD *)(result + 512);
}
return result;
}

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

result = *a1;
if ( *a1 )
{
while ( *(_DWORD *)(result + 500) != a2 )
{
result = *(_QWORD *)(result + 520);
if ( !result )
return result;
}
result = *(_QWORD *)(result + 512);
}
return result;
}

original_code:
Neighbor * GetVertexOriginals(Graph * graph, int vertexID) {
 Vertex * vertex = graph->vertices;
 while(vertex != ((void *)0)) {
  if(vertex->vertexID == vertexID) {
   return (vertex->originals);
  }
  vertex = vertex->next;
 }
 return ((void *)0);
}

canonical_original_code:
struct Neighbor *GetVertexOriginals(struct Graph *graph, int vertexID) {
 struct Vertex *vertex = graph->vertices;
 while(vertex != ((void *)0)) {
  if(vertex->vertexID == vertexID) {
   return (vertex->originals);
  }
  vertex = vertex->next;
 }
 return ((void *)0);
}

return_type: struct Neighbor { int vertexID; double weight; struct Neighbor *next; } *

user_defined_types: struct Vertex { char vertexName[500]; int vertexID; struct Neighbor *neighbors; struct Neighbor *originals; struct Vertex *next; int clusterID; }


GetVertex

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

for ( result = *a1; result; result = *(_QWORD *)(result + 520) )
{
if ( *(_DWORD *)(result + 500) == a2 )
break;
}
return result;
}

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

for ( result = *a1; result; result = *(_QWORD *)(result + 520) )
{
if ( *(_DWORD *)(result + 500) == a2 )
break;
}
return result;
}

original_code:
Vertex * GetVertex(Graph * graph, int vertexID) {
 Vertex * vertex = graph->vertices;
 while(vertex != ((void *)0)) {
  if(vertex->vertexID == vertexID) {
   return vertex;
  }
  vertex = vertex->next;
 }
 return ((void *)0);
}

canonical_original_code:
struct Vertex *GetVertex(struct Graph *graph, int vertexID) {
 struct Vertex *vertex = graph->vertices;
 while(vertex != ((void *)0)) {
  if(vertex->vertexID == vertexID) {
   return vertex;
  }
  vertex = vertex->next;
 }
 return ((void *)0);
}

variable_types: struct Graph { struct Vertex *vertices; int vertexCounter; int edgeCounter; int edgeOriginal; double C; } *

return_type: struct Vertex { char vertexName[500]; int vertexID; struct Neighbor { int vertexID; double weight; struct Neighbor *next; } *neighbors; struct Neighbor *originals; struct Vertex *next; int clusterID; } *


decompiled_code:
double __fastcall get_edge_weight_by_vertices(int a1)
{
__int64 v1; // rax
int v2; // edx

v1 = GetVertexNeighbors((__int64 *)graph, a1);
if ( !v1 )
return *(double *)&LC4;
while ( *(_DWORD *)v1 != v2 )
{
v1 = *(_QWORD *)(v1 + 16);
if ( !v1 )
return *(double *)&LC4;
}
return *(double *)(v1 + 8);
}

canonical_decompiled_code:
double __fastcall func5(int a1)
{
__int64 v1; // rax
int v2; // edx

v1 = func2((__int64 *)graph, a1);
if ( !v1 )
return *(double *)&LC4;
while ( *(_DWORD *)v1 != v2 )
{
v1 = *(_QWORD *)(v1 + 16);
if ( !v1 )
return *(double *)&LC4;
}
return *(double *)(v1 + 8);
}

original_code:
double get_edge_weight_by_vertices(int vertexID1, int vertexID2) {
 Neighbor * neighbors = GetVertexNeighbors(graph, vertexID1);
 while(neighbors != ((void *)0)) {
  if(neighbors->vertexID == vertexID2) {
   return neighbors->weight;
  }
  neighbors = neighbors->next;
 }
 return -1.0;
}

canonical_original_code:
double get_edge_weight_by_vertices(int vertexID1, int vertexID2) {
 struct Neighbor *neighbors = GetVertexNeighbors(graph, vertexID1);
 while(neighbors != ((void *)0)) {
  if(neighbors->vertexID == vertexID2) {
   return neighbors->weight;
  }
  neighbors = neighbors->next;
 }
 return -1.0;
}

return_type: double

user_defined_types: struct Neighbor { int vertexID; double weight; struct Neighbor *next; }


GetEdgeWeightByOriginals

decompiled_code:
double __fastcall GetEdgeWeightByOriginals(__int64 *a1, int a2)
{
__int64 v2; // rax
int v3; // edx

v2 = GetVertexOriginals(a1, a2);
if ( !v2 )
return *(double *)&LC4;
while ( *(_DWORD *)v2 != v3 )
{
v2 = *(_QWORD *)(v2 + 16);
if ( !v2 )
return *(double *)&LC4;
}
return *(double *)(v2 + 8);
}

canonical_decompiled_code:
double __fastcall func6(__int64 *a1, int a2)
{
__int64 v2; // rax
int v3; // edx

v2 = func3(a1, a2);
if ( !v2 )
return *(double *)&LC4;
while ( *(_DWORD *)v2 != v3 )
{
v2 = *(_QWORD *)(v2 + 16);
if ( !v2 )
return *(double *)&LC4;
}
return *(double *)(v2 + 8);
}

original_code:
double GetEdgeWeightByOriginals(Graph * graph, int vertexID1, int vertexID2) {
 Neighbor * neighbors = GetVertexOriginals(graph, vertexID1);
 while(neighbors != ((void *)0)) {
  if(neighbors->vertexID == vertexID2) {
   return neighbors->weight;
  }
  neighbors = neighbors->next;
 }
 return -1.0;
}

canonical_original_code:
double GetEdgeWeightByOriginals(struct Graph *graph, int vertexID1, int vertexID2) {
 struct Neighbor *neighbors = GetVertexOriginals(graph, vertexID1);
 while(neighbors != ((void *)0)) {
  if(neighbors->vertexID == vertexID2) {
   return neighbors->weight;
  }
  neighbors = neighbors->next;
 }
 return -1.0;
}

variable_types: struct Graph { struct Vertex { char vertexName[500]; int vertexID; struct Neighbor { int vertexID; double weight; struct Neighbor *next; } *neighbors; struct Neighbor *originals; struct Vertex *next; int clusterID; } *vertices; int vertexCounter; int edgeCounter; int edgeOriginal; double C; } *


DeleteNeighborByVertex

decompiled_code:
void __fastcall DeleteNeighborByVertex(int a1)
{
__int64 v1; // rax
int v2; // edx
_QWORD *v3; // r8
__int64 v4; // rsi
_QWORD *v5; // rdi
_QWORD *v6; // rcx
__int64 v7; // rax

v1 = GetVertex((__int64 *)graph, a1);
v3 = *(_QWORD **)(v1 + 504);
if ( v3 )
{
v4 = v1;
v5 = *(_QWORD **)(v1 + 504);
v6 = 0LL;
while ( 1 )
{
v7 = v5[2];
if ( *(_DWORD *)v5 == v2 )
break;
v6 = v5;
if ( !v7 )
return;
v5 = (_QWORD *)v5[2];
}
if ( v3 == v5 )
{
*(_QWORD *)(v4 + 504) = v7;
free(v3);
}
else
{
v6[2] = v7;
free(v5);
}
}
}

original_code:
void DeleteNeighborByVertex(int vertexID, int neighborID) {
 Vertex *vertex = GetVertex(graph, vertexID);
 Neighbor * temp = vertex->neighbors;
 Neighbor * prev = ((void *)0);
 while(temp != ((void *)0)) {
  if(temp->vertexID == neighborID) {
   if(temp == vertex->neighbors) {
    vertex->neighbors = temp->next;
    free(temp);
    return;
   }
   else {
    prev->next = temp->next;
    free(temp);
    return;
   }
  }
  prev = temp;
  temp = temp->next;
 }
}

canonical_original_code:
void DeleteNeighborByVertex(int vertexID, int neighborID) {
 struct Vertex *vertex = GetVertex(graph, vertexID);
 struct Neighbor *temp = vertex->neighbors;
 struct Neighbor *prev = ((void *)0);
 while(temp != ((void *)0)) {
  if(temp->vertexID == neighborID) {
   if(temp == vertex->neighbors) {
    vertex->neighbors = temp->next;
    free(temp);
    return;
   }
   else {
    prev->next = temp->next;
    free(temp);
    return;
   }
  }
  prev = temp;
  temp = temp->next;
 }
}

variable_types: neighborID int

return_type: void


IsNeighborByVertex

decompiled_code:
__int64 __fastcall IsNeighborByVertex(__int64 *a1, int a2)
{
__int64 result; // rax
int v3; // edx

result = GetVertexNeighbors(a1, a2);
if ( !result )
return 0LL;
while ( *(_DWORD *)result != v3 )
{
result = *(_QWORD *)(result + 16);
if ( !result )
return result;
}
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 *a1, int a2)
{
__int64 result; // rax
int v3; // edx

result = func2(a1, a2);
if ( !result )
return 0LL;
while ( *(_DWORD *)result != v3 )
{
result = *(_QWORD *)(result + 16);
if ( !result )
return result;
}
return 1LL;
}

original_code:
int IsNeighborByVertex(Graph * graph, int vertexID1, int vertexID2) {
 Neighbor * neighbors = GetVertexNeighbors(graph, vertexID1);
 while(neighbors != ((void *)0)) {
  if(neighbors->vertexID == vertexID2) return 1;
  neighbors = neighbors->next;
 }
 return 0;
}

canonical_original_code:
int IsNeighborByVertex(struct Graph *graph, int vertexID1, int vertexID2) {
 struct Neighbor *neighbors = GetVertexNeighbors(graph, vertexID1);
 while(neighbors != ((void *)0)) {
  if(neighbors->vertexID == vertexID2) return 1;
  neighbors = neighbors->next;
 }
 return 0;
}

return_type: int


decompiled_code:
void *__fastcall delete_edge(int a1, int a2)
{
int v2; // er12
__int64 *v5; // rdi
void *result; // rax

v2 = a1;
v5 = (__int64 *)graph;
result = (void *)IsNeighborByVertex((__int64 *)graph, a1);
if ( (_DWORD)result )
{
result = (void *)IsNeighborByVertex(v5, a2);
if ( (_DWORD)result )
{
DeleteNeighborByVertex(v2);
DeleteNeighborByVertex(a2);
result = graph;
--*((_DWORD *)graph + 3);
}
}
return result;
}

canonical_decompiled_code:
void *__fastcall func9(int a1, int a2)
{
int v2; // er12
__int64 *v5; // rdi
void *result; // rax

v2 = a1;
v5 = (__int64 *)graph;
result = (void *)func8((__int64 *)graph, a1);
if ( (_DWORD)result )
{
result = (void *)func8(v5, a2);
if ( (_DWORD)result )
{
func7(v2);
func7(a2);
result = graph;
--*((_DWORD *)graph + 3);
}
}
return result;
}

original_code:
void delete_edge(int vertexID1, int vertexID2) {
 if(IsNeighborByVertex(graph, vertexID1, vertexID2) && IsNeighborByVertex(graph, vertexID2, vertexID1)) {
  DeleteNeighborByVertex(vertexID1,vertexID2);
  DeleteNeighborByVertex(vertexID2,vertexID1);
  graph->edgeCounter--;
 }
}


decompiled_code:
__int64 __fastcall verify_add_vertex_command(char *s2, _BYTE *a2)
{
__int64 v2; // rbx
__int64 result; // rax

if ( *s2 )
{
if ( *a2 )
{
printf("%s %s %s", "Error: The command \"add_vertex\" has more than 1 parameter. First Parameter:", s2, "\n");
result = 1LL;
}
else
{
v2 = *(_QWORD *)graph;
if ( *(_QWORD *)graph )
{
while ( strcmp((const char *)v2, s2) )
{
v2 = *(_QWORD *)(v2 + 520);
if ( !v2 )
goto LABEL_8;
}
printf("%s %s %s", "Error: A vertex named", s2, "already exists.\n");
result = 1LL;
}
else
{
LABEL_8:
result = 0LL;
}
}
}
else
{
puts("Error: The command \"add_vertex\" has no parameters.");
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func10(char *s2, _BYTE *a2)
{
__int64 v2; // rbx
__int64 result; // rax

if ( *s2 )
{
if ( *a2 )
{
printf("%s %s %s", "Error: The command \"add_vertex\" has more than 1 parameter. First Parameter:", s2, "\n");
result = 1LL;
}
else
{
v2 = *(_QWORD *)graph;
if ( *(_QWORD *)graph )
{
while ( strcmp((const char *)v2, s2) )
{
v2 = *(_QWORD *)(v2 + 520);
if ( !v2 )
goto LABEL_8;
}
printf("%s %s %s", "Error: A vertex named", s2, "already exists.\n");
result = 1LL;
}
else
{
LABEL_8:
result = 0LL;
}
}
}
else
{
puts("Error: The command \"add_vertex\" has no parameters.");
result = 1LL;
}
return result;
}

original_code:
int verify_add_vertex_command(char *param1, char *param2) {
 Vertex * vertex = graph->vertices;
 if (!strcmp(param1,"\0")) {
  printf("%s","Error: The command \"add_vertex\" has no parameters.\n");
  return 1;
 }
 if (strcmp(param2,"\0")) {
  printf("%s %s %s","Error: The command \"add_vertex\" has more than 1 parameter. First Parameter:",param1, "\n");
  return 1;
 }
 while(vertex != ((void *)0)) {
  if(!strcmp(vertex->vertexName,param1)) {
   printf("%s %s %s","Error: A vertex named",param1,"already exists.\n");
   return 1;
  }
  vertex = vertex->next;
 }
 return 0;
}

canonical_original_code:
int verify_add_vertex_command(char *param1, char *param2) {
 struct Vertex *vertex = graph->vertices;
 if (!strcmp(param1,"\0")) {
  printf("%s","Error: The command \"add_vertex\" has no parameters.\n");
  return 1;
 }
 if (strcmp(param2,"\0")) {
  printf("%s %s %s","Error: The command \"add_vertex\" has more than 1 parameter. First Parameter:",param1, "\n");
  return 1;
 }
 while(vertex != ((void *)0)) {
  if(!strcmp(vertex->vertexName,param1)) {
   printf("%s %s %s","Error: A vertex named",param1,"already exists.\n");
   return 1;
  }
  vertex = vertex->next;
 }
 return 0;
}


isNumeric

decompiled_code:
_BOOL8 __fastcall isNumeric(char *nptr)
{
__int64 v1; // rbx
char *endptr; // [rsp+8h] [rbp-20h] BYREF

if ( !nptr )
return 0LL;
v1 = *nptr;
if ( !(_BYTE)v1 || ((*_ctype_b_loc())[v1] & 0x2000) != 0 )
return 0LL;
strtod(nptr, &endptr);
return *endptr == 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func11(char *nptr)
{
__int64 v1; // rbx
char *endptr; // [rsp+8h] [rbp-20h] BYREF

if ( !nptr )
return 0LL;
v1 = *nptr;
if ( !(_BYTE)v1 || ((*_ctype_b_loc())[v1] & 0x2000) != 0 )
return 0LL;
strtod(nptr, &endptr);
return *endptr == 0;
}

original_code:
int isNumeric (const char * s)
{
 char * p;
 if (s == ((void *)0) || *s == '\0' || ((*__ctype_b_loc ())[(int) ((*s))] & (unsigned short int) _ISspace)) {
      return 0;
 }
    strtod (s, &p);
    return *p == '\0';
}

canonical_original_code:
int isNumeric(char *s)
{
 char *p;
 if (s == ((void *)0) || *s == '\0' || ((*__ctype_b_loc ())[(int) ((*s))] & (unsigned short) _ISspace)) {
      return 0;
 }
    strtod (s, &p);
    return *p == '\0';
}

variable_types:
s
char *

variable_types:
p
char *


decompiled_code:
__int64 __fastcall verify_add_edge_command(char *nptr, char *a2, char *a3, _BYTE *a4)
{
__int64 result; // rax
unsigned int v6; // er14
unsigned int v7; // er12
double v8; // xmm0_8
double v9; // xmm0_8
signed int v10; // eax
double v11; // xmm0_8
char v12[552]; // [rsp+0h] [rbp-228h] BYREF

if ( *a4 )
{
puts("Error: The command \"add_edge\" has more than 3 parameters.");
return 1LL;
}
if ( !*nptr || !*a2 || !*a3 )
{
puts("Error: The command \"add_edge\" has less than 3 parameters.");
return 1LL;
}
if ( !isNumeric(nptr) || !isNumeric(a2) || !isNumeric(a3) )
{
puts("Error: At least on of the parameters of the command \"add_edge\" is not numeric.");
return 1LL;
}
v6 = atoi(nptr);
v7 = atoi(a2);
v8 = atof(a3);
sprintf(v12, "%.3f", v8);
if ( (v6 & 0x80000000) != 0 || (v7 & 0x80000000) != 0 )
{
puts("Error: There is an edge with a negative ID for vertex.");
return 1LL;
}
v9 = atof(v12);
if ( v9 < 0.0 )
{
puts("Error: There is an edge with a negative weight.");
return 1LL;
}
if ( v9 == 0.0 )
{
puts("Error: There is an edge with a zero weight.");
return 1LL;
}
if ( v9 > 1.0 )
{
puts("Error: There is an edge with a weight greater than 1.");
return 1LL;
}
if ( v6 == v7 )
{
printf("%s %d%s", "Error: There is a self loop of vertex", v6, ".\n");
return 1LL;
}
v10 = *((_DWORD *)graph + 2);
if ( v10 <= (int)v6 )
{
printf("%s%d,%d%s%d%s", "Error: Trying to add an edge (", v6, v7, ") where vertex ", v6, " does not exists.\n");
return 1LL;
}
if ( v10 <= (int)v7 )
{
printf("%s%d,%d%s%d%s", "Error: Trying to add an edge (", v6, v7, ") where vertex ", v7, " does not exists.\n");
return 1LL;
}
v11 = get_edge_weight_by_vertices(v6);
result = 0LL;
if ( v11 > 0.0 )
{
printf("%s%d,%d%s", "Error: Edge (", v6, v7, ") already exists.\n");
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func12(char *nptr, char *a2, char *a3, _BYTE *a4)
{
__int64 result; // rax
unsigned int v6; // er14
unsigned int v7; // er12
double v8; // xmm0_8
double v9; // xmm0_8
signed int v10; // eax
double v11; // xmm0_8
char v12[552]; // [rsp+0h] [rbp-228h] BYREF

if ( *a4 )
{
puts("Error: The command \"add_edge\" has more than 3 parameters.");
return 1LL;
}
if ( !*nptr || !*a2 || !*a3 )
{
puts("Error: The command \"add_edge\" has less than 3 parameters.");
return 1LL;
}
if ( !func11(nptr) || !func11(a2) || !func11(a3) )
{
puts("Error: At least on of the parameters of the command \"add_edge\" is not numeric.");
return 1LL;
}
v6 = atoi(nptr);
v7 = atoi(a2);
v8 = atof(a3);
sprintf(v12, "%.3f", v8);
if ( (v6 & 0x80000000) != 0 || (v7 & 0x80000000) != 0 )
{
puts("Error: There is an edge with a negative ID for vertex.");
return 1LL;
}
v9 = atof(v12);
if ( v9 < 0.0 )
{
puts("Error: There is an edge with a negative weight.");
return 1LL;
}
if ( v9 == 0.0 )
{
puts("Error: There is an edge with a zero weight.");
return 1LL;
}
if ( v9 > 1.0 )
{
puts("Error: There is an edge with a weight greater than 1.");
return 1LL;
}
if ( v6 == v7 )
{
printf("%s %d%s", "Error: There is a self loop of vertex", v6, ".\n");
return 1LL;
}
v10 = *((_DWORD *)graph + 2);
if ( v10 <= (int)v6 )
{
printf("%s%d,%d%s%d%s", "Error: Trying to add an edge (", v6, v7, ") where vertex ", v6, " does not exists.\n");
return 1LL;
}
if ( v10 <= (int)v7 )
{
printf("%s%d,%d%s%d%s", "Error: Trying to add an edge (", v6, v7, ") where vertex ", v7, " does not exists.\n");
return 1LL;
}
v11 = func5(v6);
result = 0LL;
if ( v11 > 0.0 )
{
printf("%s%d,%d%s", "Error: Edge (", v6, v7, ") already exists.\n");
result = 1LL;
}
return result;
}

original_code:
int verify_add_edge_command(char *param1, char *param2,char *param3, char *param4) {
 int vertexID1, vertexID2;
 char weight[500];
 double realWeight;
 if (strcmp(param4,"\0")){
  printf("%s","Error: The command \"add_edge\" has more than 3 parameters.\n");
  return 1;
 }
 if (!strcmp(param1,"\0") || !strcmp(param2,"\0") || !strcmp(param3,"\0")) {
  printf("%s","Error: The command \"add_edge\" has less than 3 parameters.\n");
  return 1;
 }
 if(!isNumeric(param1) || !isNumeric(param2) || !isNumeric(param3)) {
  printf("%s","Error: At least on of the parameters of the command \"add_edge\" is not numeric.\n");
  return 1;
 }
 vertexID1 = atoi(param1);
 vertexID2 = atoi(param2);
 sprintf(weight,"%.3f",atof(param3));
 realWeight = atof(weight);
 if(vertexID1 < 0 || vertexID2 < 0) {
  printf("%s","Error: There is an edge with a negative ID for vertex.\n");
  return 1;
 }
 if(realWeight < 0) {
  printf("%s","Error: There is an edge with a negative weight.\n");
  return 1;
 }
 if(realWeight == 0) {
  printf("%s","Error: There is an edge with a zero weight.\n");
  return 1;
 }
 if(realWeight > 1) {
  printf("%s","Error: There is an edge with a weight greater than 1.\n");
  return 1;
 }
 if(vertexID1 == vertexID2) {
  printf("%s %d%s","Error: There is a self loop of vertex", vertexID1,".\n");
  return 1;
 }
 if(vertexID1 >= graph->vertexCounter) {
  printf("%s%d,%d%s%d%s","Error: Trying to add an edge (",vertexID1,vertexID2,") where vertex ",vertexID1," does not exists.\n");
  return 1;
 }
 if(vertexID2 >= graph->vertexCounter) {
  printf("%s%d,%d%s%d%s","Error: Trying to add an edge (",vertexID1,vertexID2,") where vertex ",vertexID2," does not exists.\n");
  return 1;
 }
 if(get_edge_weight_by_vertices(vertexID1,vertexID2) > 0) {
  printf("%s%d,%d%s","Error: Edge (",vertexID1,vertexID2,") already exists.\n");
  return 1;
 }
 return 0;
}

canonical_original_code:
int verify_add_edge_command(char *param1, char *param2, char *param3, char *param4) {
 int vertexID1; int vertexID2;
 char weight[500];
 double realWeight;
 if (strcmp(param4,"\0")){
  printf("%s","Error: The command \"add_edge\" has more than 3 parameters.\n");
  return 1;
 }
 if (!strcmp(param1,"\0") || !strcmp(param2,"\0") || !strcmp(param3,"\0")) {
  printf("%s","Error: The command \"add_edge\" has less than 3 parameters.\n");
  return 1;
 }
 if(!isNumeric(param1) || !isNumeric(param2) || !isNumeric(param3)) {
  printf("%s","Error: At least on of the parameters of the command \"add_edge\" is not numeric.\n");
  return 1;
 }
 vertexID1 = atoi(param1);
 vertexID2 = atoi(param2);
 sprintf(weight,"%.3f",atof(param3));
 realWeight = atof(weight);
 if(vertexID1 < 0 || vertexID2 < 0) {
  printf("%s","Error: There is an edge with a negative ID for vertex.\n");
  return 1;
 }
 if(realWeight < 0) {
  printf("%s","Error: There is an edge with a negative weight.\n");
  return 1;
 }
 if(realWeight == 0) {
  printf("%s","Error: There is an edge with a zero weight.\n");
  return 1;
 }
 if(realWeight > 1) {
  printf("%s","Error: There is an edge with a weight greater than 1.\n");
  return 1;
 }
 if(vertexID1 == vertexID2) {
  printf("%s %d%s","Error: There is a self loop of vertex", vertexID1,".\n");
  return 1;
 }
 if(vertexID1 >= graph->vertexCounter) {
  printf("%s%d,%d%s%d%s","Error: Trying to add an edge (",vertexID1,vertexID2,") where vertex ",vertexID1," does not exists.\n");
  return 1;
 }
 if(vertexID2 >= graph->vertexCounter) {
  printf("%s%d,%d%s%d%s","Error: Trying to add an edge (",vertexID1,vertexID2,") where vertex ",vertexID2," does not exists.\n");
  return 1;
 }
 if(get_edge_weight_by_vertices(vertexID1,vertexID2) > 0) {
  printf("%s%d,%d%s","Error: Edge (",vertexID1,vertexID2,") already exists.\n");
  return 1;
 }
 return 0;
}

variable_types:
weight
char [500]

variable_types: realWeight double


decompiled_code:
__int64 __fastcall initialize_graph(double a1)
{
_QWORD *v1; // rax
__int64 result; // rax

v1 = calloc(1uLL, 0x20uLL);
graph = v1;
if ( v1 )
{
*v1 = 0LL;
v1[1] = 0LL;
*((_DWORD *)v1 + 4) = 0;
*((double *)v1 + 3) = a1;
result = 0LL;
}
else
{
perror("Error: failed allocating memory for the graph.\n");
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func13(double a1)
{
_QWORD *v1; // rax
__int64 result; // rax

v1 = calloc(1uLL, 0x20uLL);
graph = v1;
if ( v1 )
{
*v1 = 0LL;
v1[1] = 0LL;
*((_DWORD *)v1 + 4) = 0;
*((double *)v1 + 3) = a1;
result = 0LL;
}
else
{
perror("Error: failed allocating memory for the graph.\n");
result = 1LL;
}
return result;
}

original_code:
int initialize_graph(double C) {
 graph = calloc(1, sizeof(Graph));
 if (graph == ((void *)0)) {
  perror("Error: failed allocating memory for the graph.\n");
  return 1;
 }
 graph->vertices = ((void *)0);
 graph->vertexCounter = 0;
 graph->edgeCounter = 0;
 graph->edgeOriginal = 0;
 graph->C = C;
 return 0;
}

variable_types: C double


decompiled_code:
void free_graph()
{
void *v0; // rdi
_QWORD *v1; // rbp
_QWORD *v2; // rbx
void *v3; // rdi
_QWORD *v4; // rbx
void *v5; // rdi
_QWORD *v6; // rbx

v0 = graph;
if ( graph )
{
v1 = *(_QWORD **)graph;
if ( *(_QWORD *)graph )
{
while ( 1 )
{
v2 = (_QWORD *)v1[63];
while ( v2 )
{
v3 = v2;
v2 = (_QWORD *)v2[2];
free(v3);
}
v4 = (_QWORD *)v1[64];
while ( v4 )
{
v5 = v4;
v4 = (_QWORD *)v4[2];
free(v5);
}
v6 = (_QWORD *)v1[65];
free(v1);
if ( !v6 )
break;
v1 = v6;
}
v0 = graph;
}
free(v0);
}
}

canonical_decompiled_code:
void func15()
{
void *v0; // rdi
_QWORD *v1; // rbp
_QWORD *v2; // rbx
void *v3; // rdi
_QWORD *v4; // rbx
void *v5; // rdi
_QWORD *v6; // rbx

v0 = graph;
if ( graph )
{
v1 = *(_QWORD **)graph;
if ( *(_QWORD *)graph )
{
while ( 1 )
{
v2 = (_QWORD *)v1[63];
while ( v2 )
{
v3 = v2;
v2 = (_QWORD *)v2[2];
free(v3);
}
v4 = (_QWORD *)v1[64];
while ( v4 )
{
v5 = v4;
v4 = (_QWORD *)v4[2];
free(v5);
}
v6 = (_QWORD *)v1[65];
free(v1);
if ( !v6 )
break;
v1 = v6;
}
v0 = graph;
}
free(v0);
}
}

original_code:
void free_graph(){
 Vertex *next_ver,*temp_ver;
 Neighbor *next_edge, *temp_edge;
 if (graph == ((void *)0)){
  return;
 }
 next_ver = graph->vertices;
 while (next_ver != ((void *)0)){
  next_edge = next_ver->neighbors;
  while (next_edge != ((void *)0)){
   temp_edge = next_edge;
   next_edge = next_edge->next;
   free(temp_edge);
  }
  next_edge = next_ver->originals;
  while (next_edge != ((void *)0)){
   temp_edge = next_edge;
   next_edge = next_edge->next;
   free(temp_edge);
  }
  temp_ver = next_ver;
  next_ver = next_ver->next;
  free(temp_ver);
 }
 free(graph);
}

canonical_original_code:
void free_graph(){
 struct Vertex *next_ver; struct Vertex *temp_ver;
 struct Neighbor *next_edge; struct Neighbor *temp_edge;
 if (graph == ((void *)0)){
  return;
 }
 next_ver = graph->vertices;
 while (next_ver != ((void *)0)){
  next_edge = next_ver->neighbors;
  while (next_edge != ((void *)0)){
   temp_edge = next_edge;
   next_edge = next_edge->next;
   free(temp_edge);
  }
  next_edge = next_ver->originals;
  while (next_edge != ((void *)0)){
   temp_edge = next_edge;
   next_edge = next_edge->next;
   free(temp_edge);
  }
  temp_ver = next_ver;
  next_ver = next_ver->next;
  free(temp_ver);
 }
 free(graph);
}


initializeGLES

repo: mayankbhagya/RaspberryPi

decompiled_code:
__int64 initializeGLES()
{
__int64 v0; // rbp
__int64 v1; // rax
__int64 v2; // r13
unsigned int v3; // er14
unsigned int v4; // er12
__int64 v5; // r12
int v7; // [rsp+Ch] [rbp-9Ch] BYREF
int v8; // [rsp+10h] [rbp-98h] BYREF
char v9[4]; // [rsp+14h] [rbp-94h] BYREF
__int64 v10; // [rsp+18h] [rbp-90h] BYREF
__int64 v11; // [rsp+24h] [rbp-84h] BYREF
int v12; // [rsp+2Ch] [rbp-7Ch]
__int64 v13; // [rsp+30h] [rbp-78h] BYREF
int v14; // [rsp+38h] [rbp-70h]
int v15; // [rsp+3Ch] [rbp-6Ch]
__int64 v16; // [rsp+40h] [rbp-68h] BYREF
int v17; // [rsp+48h] [rbp-60h]
int v18; // [rsp+4Ch] [rbp-5Ch]
__int64 v19[5]; // [rsp+50h] [rbp-58h] BYREF
int v20; // [rsp+78h] [rbp-30h]

bcm_host_init();
graphics_get_display_size(0LL, &v7, &v8);
v0 = eglGetDisplay(0LL);
eglInitialize(v0, 0LL, 0LL);
v20 = 12344;
v19[0] = 0x800003024LL;
v19[1] = 0x800003023LL;
v19[2] = 0x800003022LL;
v19[3] = 0x800003021LL;
v19[4] = 0x400003033LL;
eglChooseConfig(v0, v19, &v10, 1LL, v9);
eglBindAPI(12448LL);
v12 = 12344;
v11 = 0x200003098LL;
v1 = eglCreateContext(v0, v10, 0LL, &v11);
v13 = 0LL;
v16 = 0LL;
v2 = v1;
v14 = v7;
v15 = v8;
v17 = v7 << 16;
v18 = v8 << 16;
v3 = vc_dispmanx_display_open(0LL);
v4 = vc_dispmanx_update_start(0LL);
nativeWindow_0 = vc_dispmanx_element_add(v4, v3, 0LL, &v13, 0LL, &v16, 0LL, 0LL, 0LL, 0LL);
dword_1DC = v7;
dword_1E0 = v8;
vc_dispmanx_update_submit_sync(v4);
v5 = eglCreateWindowSurface(v0, v10, &nativeWindow_0, 0LL);
eglMakeCurrent(v0, v5, v5, v2);
glBindFramebuffer(36160LL, 0LL);
glClearColor(1.0, 0.0);
glClear(0x4000LL);
glFlush();
glFinish();
return eglSwapBuffers(v0, v5);
}

canonical_decompiled_code:
__int64 func0()
{
__int64 v0; // rbp
__int64 v1; // rax
__int64 v2; // r13
unsigned int v3; // er14
unsigned int v4; // er12
__int64 v5; // r12
int v7; // [rsp+Ch] [rbp-9Ch] BYREF
int v8; // [rsp+10h] [rbp-98h] BYREF
char v9[4]; // [rsp+14h] [rbp-94h] BYREF
__int64 v10; // [rsp+18h] [rbp-90h] BYREF
__int64 v11; // [rsp+24h] [rbp-84h] BYREF
int v12; // [rsp+2Ch] [rbp-7Ch]
__int64 v13; // [rsp+30h] [rbp-78h] BYREF
int v14; // [rsp+38h] [rbp-70h]
int v15; // [rsp+3Ch] [rbp-6Ch]
__int64 v16; // [rsp+40h] [rbp-68h] BYREF
int v17; // [rsp+48h] [rbp-60h]
int v18; // [rsp+4Ch] [rbp-5Ch]
__int64 v19[5]; // [rsp+50h] [rbp-58h] BYREF
int v20; // [rsp+78h] [rbp-30h]

bcm_host_init();
graphics_get_display_size(0LL, &v7, &v8);
v0 = eglGetDisplay(0LL);
eglInitialize(v0, 0LL, 0LL);
v20 = 12344;
v19[0] = 0x800003024LL;
v19[1] = 0x800003023LL;
v19[2] = 0x800003022LL;
v19[3] = 0x800003021LL;
v19[4] = 0x400003033LL;
eglChooseConfig(v0, v19, &v10, 1LL, v9);
eglBindAPI(12448LL);
v12 = 12344;
v11 = 0x200003098LL;
v1 = eglCreateContext(v0, v10, 0LL, &v11);
v13 = 0LL;
v16 = 0LL;
v2 = v1;
v14 = v7;
v15 = v8;
v17 = v7 << 16;
v18 = v8 << 16;
v3 = vc_dispmanx_display_open(0LL);
v4 = vc_dispmanx_update_start(0LL);
nativeWindow_0 = vc_dispmanx_element_add(v4, v3, 0LL, &v13, 0LL, &v16, 0LL, 0LL, 0LL, 0LL);
dword_1DC = v7;
dword_1E0 = v8;
vc_dispmanx_update_submit_sync(v4);
v5 = eglCreateWindowSurface(v0, v10, &nativeWindow_0, 0LL);
eglMakeCurrent(v0, v5, v5, v2);
glBindFramebuffer(36160LL, 0LL);
glClearColor(1.0, 0.0);
glClear(0x4000LL);
glFlush();
glFinish();
return eglSwapBuffers(v0, v5);
}

original_code:
void initializeGLES()
{
    bcm_host_init();
    uint32_t disp_width, disp_height;
    int32_t ret = graphics_get_display_size(0, &disp_width, &disp_height);
    EGLBoolean res;
    EGLDisplay disp = eglGetDisplay(((EGLNativeDisplayType)0));
    res = eglInitialize(disp, ((void *)0), ((void *)0));
    EGLint num_configs;
    EGLConfig config;
    EGLint config_attributes[]=
    {
        0x3024, 8,
        0x3023, 8,
        0x3022, 8,
        0x3021, 8,
        0x3033, 0x0004,
        0x3038
    };
    res = eglChooseConfig(disp, config_attributes, &config, 1, &num_configs);
    res = eglBindAPI(0x30A0);
    EGLint context_attributes[]=
    {
        0x3098, 2,
        0x3038
    };
    EGLContext ctx = eglCreateContext(disp, config, ((EGLContext)0), context_attributes);
    static EGL_DISPMANX_WINDOW_T nativeWindow;
    DISPMANX_ELEMENT_HANDLE_T dispman_element;
    DISPMANX_DISPLAY_HANDLE_T dispman_display;
    DISPMANX_UPDATE_HANDLE_T dispman_update;
    VC_RECT_T dst_rect;
    VC_RECT_T src_rect;
    dst_rect.x = 0;
    dst_rect.y = 0;
    dst_rect.width = disp_width;
    dst_rect.height = disp_height;
    src_rect.x = 0;
    src_rect.y = 0;
    src_rect.width = disp_width << 16;
    src_rect.height = disp_height << 16;
    dispman_display = vc_dispmanx_display_open(0);
    dispman_update = vc_dispmanx_update_start(0);
    dispman_element = vc_dispmanx_element_add(dispman_update, dispman_display, 0, &dst_rect, 0, &src_rect, 0, 0, 0, 0);
    nativeWindow.element = dispman_element;
    nativeWindow.width = disp_width;
    nativeWindow.height = disp_height;
    vc_dispmanx_update_submit_sync(dispman_update);
    EGLSurface surf = eglCreateWindowSurface(disp, config, &nativeWindow, ((void *)0));
    eglMakeCurrent(disp, surf, surf, ctx);
    glBindFramebuffer(0x8D40, 0);
    glClearColor(1.0f, 0.0f, 0.0f, 1.0f);
    glClear(0x00004000);
    glFlush();
    glFinish();
    eglSwapBuffers(disp, surf);
}

canonical_original_code:
void initializeGLES()
{
    bcm_host_init();
    unsigned int disp_width; unsigned int disp_height;
    int ret = graphics_get_display_size(0, &disp_width, &disp_height);
    unsigned int res;
    void *disp = eglGetDisplay(((EGLNativeDisplayType)0));
    res = eglInitialize(disp, ((void *)0), ((void *)0));
    int num_configs;
    void *config;
    int config_attributes[] = {
        0x3024, 8,
        0x3023, 8,
        0x3022, 8,
        0x3021, 8,
        0x3033, 0x0004,
        0x3038
    };
    res = eglChooseConfig(disp, config_attributes, &config, 1, &num_configs);
    res = eglBindAPI(0x30A0);
    int context_attributes[] = {
        0x3098, 2,
        0x3038
    };
    void *ctx = eglCreateContext(disp, config, ((EGLContext)0), context_attributes);
    static struct EGL_DISPMANX_WINDOW_T nativeWindow;
    unsigned int dispman_element;
    unsigned int dispman_display;
    unsigned int dispman_update;
    struct tag_VC_RECT_T dst_rect;
    struct tag_VC_RECT_T src_rect;
    dst_rect.x = 0;
    dst_rect.y = 0;
    dst_rect.width = disp_width;
    dst_rect.height = disp_height;
    src_rect.x = 0;
    src_rect.y = 0;
    src_rect.width = disp_width << 16;
    src_rect.height = disp_height << 16;
    dispman_display = vc_dispmanx_display_open(0);
    dispman_update = vc_dispmanx_update_start(0);
    dispman_element = vc_dispmanx_element_add(dispman_update, dispman_display, 0, &dst_rect, 0, &src_rect, 0, 0, 0, 0);
    nativeWindow.element = dispman_element;
    nativeWindow.width = disp_width;
    nativeWindow.height = disp_height;
    vc_dispmanx_update_submit_sync(dispman_update);
    void *surf = eglCreateWindowSurface(disp, config, &nativeWindow, ((void *)0));
    eglMakeCurrent(disp, surf, surf, ctx);
    glBindFramebuffer(0x8D40, 0);
    glClearColor(1.0f, 0.0f, 0.0f, 1.0f);
    glClear(0x00004000);
    glFlush();
    glFinish();
    eglSwapBuffers(disp, surf);
}

variable_types: ret int

variable_types:
res
unsigned int

variable_types:
disp
void *

variable_types:
config
void *

variable_types:
ctx
void *

variable_types: struct EGL_DISPMANX_WINDOW_T { unsigned int element; int width; int height; }

variable_types: struct tag_VC_RECT_T { int x; int y; int width; int height; }

variable_types:
surf
void *


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
initializeGLES(argc, argv, envp);
getchar();
puts("Hello World!");
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
func0(argc, argv, envp);
getchar();
puts("Hello World!");
return 0;
}

original_code:
int main()
{
    initializeGLES();
    getchar();
    printf("Hello World!\n");
    return 0;
}


init

repo: maykondeykon/trabalhoArvore

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

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

original_code:
Arv* init (void){
    return ((void *)0);
}

canonical_original_code:
struct arv *init(){
    return ((void *)0);
}

return_type: struct arv { int info; struct arv *esq; struct arv *dir; } *


vazia

decompiled_code:
int __fastcall vazia(__int64 a1)
{
int result; // eax

if ( !a1 )
result = printf("vazio");
return result;
}

canonical_decompiled_code:
int __fastcall func1(__int64 a1)
{
int result; // eax

if ( !a1 )
result = printf("vazio");
return result;
}

original_code:
int vazia(Arv* a){
    if(a == ((void *)0)){
        printf("vazio");
    }
}

canonical_original_code:
int vazia(struct arv *a){
    if(a == ((void *)0)){
        printf("vazio");
    }
}

variable_types: struct arv { int info; struct arv *esq; struct arv *dir; } *


imprime

decompiled_code:
int __fastcall imprime(unsigned int *a1)
{
unsigned int *v1; // rbx
int result; // eax

if ( a1 )
{
v1 = a1;
do
{
imprime(*((_QWORD *)v1 + 1));
result = printf("%d\n", *v1);
v1 = (unsigned int *)*((_QWORD *)v1 + 2);
}
while ( v1 );
}
return result;
}

canonical_decompiled_code:
int __fastcall func2(unsigned int *a1)
{
unsigned int *v1; // rbx
int result; // eax

if ( a1 )
{
v1 = a1;
do
{
func2(*((_QWORD *)v1 + 1));
result = printf("%d\n", *v1);
v1 = (unsigned int *)*((_QWORD *)v1 + 2);
}
while ( v1 );
}
return result;
}

original_code:
void imprime (Arv* a){
    if (a != ((void *)0)) {
        imprime(a->esq);
        printf("%d\n",a->info);
        imprime(a->dir);
    }
}

canonical_original_code:
void imprime(struct arv *a){
    if (a != ((void *)0)) {
        imprime(a->esq);
        printf("%d\n",a->info);
        imprime(a->dir);
    }
}

user_defined_types: struct arv { int info; struct arv *esq; struct arv *dir; }


busca

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

for ( result = a1; result; result = *(_QWORD *)(result + 16) )
{
while ( *(_DWORD *)result > a2 )
{
result = *(_QWORD *)(result + 8);
if ( !result )
return result;
}
if ( *(_DWORD *)result >= a2 )
break;
}
return result;
}

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

for ( result = a1; result; result = *(_QWORD *)(result + 16) )
{
while ( *(_DWORD *)result > a2 )
{
result = *(_QWORD *)(result + 8);
if ( !result )
return result;
}
if ( *(_DWORD *)result >= a2 )
break;
}
return result;
}

original_code:
Arv* busca (Arv* r, int v){
    if (r == ((void *)0)) return ((void *)0);
    else if (r->info > v) return busca (r->esq, v);
    else if (r->info < v) return busca (r->dir, v);
    else return r;
}

canonical_original_code:
struct arv *busca(struct arv *r, int v){
    if (r == ((void *)0)) return ((void *)0);
    else if (r->info > v) return busca (r->esq, v);
    else if (r->info < v) return busca (r->dir, v);
    else return r;
}

variable_types:
r
struct arv *

variable_types: v int


repo: mayth/tiny-c-c

original_code:
void Pool_init(Pool *self, void *buf, size_t size, size_t alignment)
{
 BlockHeader *p;
 self->align_size = alignment;
 self->header_size = (((sizeof(BlockHeader)) + ((self->align_size) - 1)) & (~((self->align_size) - 1)));
 p = (BlockHeader *) buf;
 self->list_term.size = 0;
 self->list_term.occupied = 1;
 self->list_term.magic = ~0x17 & 0xFF;
 self->list_term.next = p;
 self->list_term.prev = p;
 p->size = ((size) & (~((self->align_size) - 1)));
 p->occupied = 0;
 p->magic = 0x17;
 p->next = &self->list_term;
 p->prev = &self->list_term;
 self->loop_p = &self->list_term;
 self->init_flag = self;
}

canonical_original_code:
void Pool_init(struct Pool *self, void *buf, unsigned long size, unsigned long alignment)
{
 struct BlockHeader *p;
 self->align_size = alignment;
 self->header_size = (((sizeof(BlockHeader)) + ((self->align_size) - 1)) & (~((self->align_size) - 1)));
 p = (struct BlockHeader *) buf;
 self->list_term.size = 0;
 self->list_term.occupied = 1;
 self->list_term.magic = ~0x17 & 0xFF;
 self->list_term.next = p;
 self->list_term.prev = p;
 p->size = ((size) & (~((self->align_size) - 1)));
 p->occupied = 0;
 p->magic = 0x17;
 p->next = &self->list_term;
 p->prev = &self->list_term;
 self->loop_p = &self->list_term;
 self->init_flag = self;
}

variable_types: struct Pool { struct BlockHeader { struct BlockHeader *prev; struct BlockHeader *next; unsigned long size; unsigned char occupied; unsigned char magic; } list_term; struct BlockHeader *loop_p; struct Pool *init_flag; unsigned long align_size; unsigned long header_size; } *

variable_types:
buf
void *

variable_types:
size
unsigned long

variable_types:
alignment
unsigned long

variable_types: struct BlockHeader { struct BlockHeader *prev; struct BlockHeader *next; unsigned long size; unsigned char occupied; unsigned char magic; } *

user_defined_types: struct Pool { struct BlockHeader list_term; struct BlockHeader *loop_p; struct Pool *init_flag; unsigned long align_size; unsigned long header_size; }


original_code:
void *Pool_malloc(Pool *self, size_t size)
{
 BlockHeader *p;
 BlockHeader *s;
 size_t alloc_block_size = ((((self->header_size) + size) + ((self->align_size) - 1)) & (~((self->align_size) - 1)));
 if (self->init_flag != self) {
  ;
  ((void) sizeof ((0) ? 1 : 0), __extension__ ({ if (0) ; else __assert_fail ("0", "Pool.c", 131, __extension__ __PRETTY_FUNCTION__); }));
  return 0;
 }
 for (p = self->loop_p->next; p != self->loop_p; p = p->next) {
  if (!p->occupied && p->size >= alloc_block_size) {
   if (p->size >= alloc_block_size + (self->header_size) + ((self->align_size)*4)) {
    s = (BlockHeader *) ((char *) p + alloc_block_size);
    s->size = p->size - alloc_block_size;
    s->occupied = 0;
    s->magic = 0x17;
    p->size = alloc_block_size;
    s->next = p->next;
    s->prev = p;
    p->next->prev = s;
    p->next = s;
   }
   p->occupied = 1;
   self->loop_p = p;
   return (char *) p + (self->header_size);
  }
 }
 ;
 return 0;
}

canonical_original_code:
void *Pool_malloc(struct Pool *self, unsigned long size)
{
 struct BlockHeader *p;
 struct BlockHeader *s;
 unsigned long alloc_block_size = ((((self->header_size) + size) + ((self->align_size) - 1)) & (~((self->align_size) - 1)));
 if (self->init_flag != self) {
  ;
  ((void) sizeof ((0) ? 1 : 0), __extension__ ({ if (0) ; else __assert_fail ("0", "Pool.c", 131, __extension__ __PRETTY_FUNCTION__); }));
  return 0;
 }
 for (p = self->loop_p->next; p != self->loop_p; p = p->next) {
  if (!p->occupied && p->size >= alloc_block_size) {
   if (p->size >= alloc_block_size + (self->header_size) + ((self->align_size)*4)) {
    s = (struct BlockHeader *) ((char *) p + alloc_block_size);
    s->size = p->size - alloc_block_size;
    s->occupied = 0;
    s->magic = 0x17;
    p->size = alloc_block_size;
    s->next = p->next;
    s->prev = p;
    p->next->prev = s;
    p->next = s;
   }
   p->occupied = 1;
   self->loop_p = p;
   return (char *) p + (self->header_size);
  }
 }
 ;
 return 0;
}

return_type: void *

user_defined_types: struct BlockHeader { struct BlockHeader *prev; struct BlockHeader *next; unsigned long size; unsigned char occupied; unsigned char magic; }


original_code:
void *Pool_realloc(Pool *self, void *ptr, size_t newsize)
{
 size_t i;
 BlockHeader *p;
 BlockHeader *s;
 size_t new_alloc_block_size;
 if (self->init_flag != self) {
  ;
  ((void) sizeof ((0) ? 1 : 0), __extension__ ({ if (0) ; else __assert_fail ("0", "Pool.c", 205, __extension__ __PRETTY_FUNCTION__); }));
  return 0;
 }
 if (!ptr) {
  return Pool_malloc(self, newsize);
 }
 if (!newsize) {
  Pool_free(self, ptr);
  return 0;
 }
 p = (BlockHeader *) ((char *) ptr - (self->header_size));
 if (p->magic != 0x17 || !p->occupied) {
  ;
  ((void) sizeof ((0) ? 1 : 0), __extension__ ({ if (0) ; else __assert_fail ("0", "Pool.c", 230, __extension__ __PRETTY_FUNCTION__); }));
  return 0;
 }
 new_alloc_block_size = ((((self->header_size) + newsize) + ((self->align_size) - 1)) & (~((self->align_size) - 1)));
 if (p->size >= new_alloc_block_size) {
  if (p->size >= 2 * new_alloc_block_size && new_alloc_block_size >= (self->header_size) + ((self->align_size)*4)) {
   s = (BlockHeader *) ((char *) p + new_alloc_block_size);
   s->occupied = 0;
   s->magic = 0x17;
   s->prev = p;
   if (p->next->occupied) {
    s->size = p->size - new_alloc_block_size;
    s->next = p->next;
    p->next->prev = s;
   } else {
    if (self->loop_p == p->next) {
     self->loop_p = p->next->next;
    }
    s->size = p->size - new_alloc_block_size + p->next->size;
    s->next = p->next->next;
    p->next->next->prev = s;
   }
   p->size = new_alloc_block_size;
   p->next = s;
  }
  return ptr;
 }
 if (p->next->occupied || p->size + p->next->size < new_alloc_block_size) {
  void *newptr = Pool_malloc(self, newsize);
  if (!newptr) {
   ;
   return 0;
  }
  for (i = 0;
    i < p->size - (self->header_size);
    i++) {
   ((char *) newptr)[i] = ((char *) ptr)[i];
  }
  Pool_free(self, ptr);
  return newptr;
 }
 if (self->loop_p == p->next) {
  self->loop_p = p->next->next;
 }
 if (p->size + p->next->size >= new_alloc_block_size + (self->header_size) + ((self->align_size)*4)) {
  BlockHeader tmp = *p->next;
  s = (BlockHeader *) ((char *) p + new_alloc_block_size);
  s->size = p->size + p->next->size - new_alloc_block_size;
  s->occupied = 0;
  s->magic = 0x17;
  s->prev = p;
  s->next = tmp.next;
  p->size = new_alloc_block_size;
  tmp.next->prev = s;
  p->next = s;
 } else {
  p->size = p->size + p->next->size;
  p->next->next->prev = p;
  p->next = p->next->next;
 }
 return ptr;
}

canonical_original_code:
void *Pool_realloc(struct Pool *self, void *ptr, unsigned long newsize)
{
 unsigned long i;
 struct BlockHeader *p;
 struct BlockHeader *s;
 unsigned long new_alloc_block_size;
 if (self->init_flag != self) {
  ;
  ((void) sizeof ((0) ? 1 : 0), __extension__ ({ if (0) ; else __assert_fail ("0", "Pool.c", 205, __extension__ __PRETTY_FUNCTION__); }));
  return 0;
 }
 if (!ptr) {
  return Pool_malloc(self, newsize);
 }
 if (!newsize) {
  Pool_free(self, ptr);
  return 0;
 }
 p = (struct BlockHeader *) ((char *) ptr - (self->header_size));
 if (p->magic != 0x17 || !p->occupied) {
  ;
  ((void) sizeof ((0) ? 1 : 0), __extension__ ({ if (0) ; else __assert_fail ("0", "Pool.c", 230, __extension__ __PRETTY_FUNCTION__); }));
  return 0;
 }
 new_alloc_block_size = ((((self->header_size) + newsize) + ((self->align_size) - 1)) & (~((self->align_size) - 1)));
 if (p->size >= new_alloc_block_size) {
  if (p->size >= 2 * new_alloc_block_size && new_alloc_block_size >= (self->header_size) + ((self->align_size)*4)) {
   s = (struct BlockHeader *) ((char *) p + new_alloc_block_size);
   s->occupied = 0;
   s->magic = 0x17;
   s->prev = p;
   if (p->next->occupied) {
    s->size = p->size - new_alloc_block_size;
    s->next = p->next;
    p->next->prev = s;
   } else {
    if (self->loop_p == p->next) {
     self->loop_p = p->next->next;
    }
    s->size = p->size - new_alloc_block_size + p->next->size;
    s->next = p->next->next;
    p->next->next->prev = s;
   }
   p->size = new_alloc_block_size;
   p->next = s;
  }
  return ptr;
 }
 if (p->next->occupied || p->size + p->next->size < new_alloc_block_size) {
  void *newptr = Pool_malloc(self, newsize);
  if (!newptr) {
   ;
   return 0;
  }
  for (i = 0;
    i < p->size - (self->header_size);
    i++) {
   ((char *) newptr)[i] = ((char *) ptr)[i];
  }
  Pool_free(self, ptr);
  return newptr;
 }
 if (self->loop_p == p->next) {
  self->loop_p = p->next->next;
 }
 if (p->size + p->next->size >= new_alloc_block_size + (self->header_size) + ((self->align_size)*4)) {
  struct BlockHeader tmp = *p->next;
  s = (struct BlockHeader *) ((char *) p + new_alloc_block_size);
  s->size = p->size + p->next->size - new_alloc_block_size;
  s->occupied = 0;
  s->magic = 0x17;
  s->prev = p;
  s->next = tmp.next;
  p->size = new_alloc_block_size;
  tmp.next->prev = s;
  p->next = s;
 } else {
  p->size = p->size + p->next->size;
  p->next->next->prev = p;
  p->next = p->next->next;
 }
 return ptr;
}

variable_types:
ptr
void *

variable_types:
newsize
unsigned long

variable_types:
i
unsigned long

variable_types:
newptr
void *

variable_types: struct BlockHeader { struct BlockHeader *prev; struct BlockHeader *next; unsigned long size; unsigned char occupied; unsigned char magic; }


decompiled_code:
void *Stack_alloc()
{
return malloc(0x10uLL);
}

canonical_decompiled_code:
void *func0()
{
return malloc(0x10uLL);
}

original_code:
static Stack *Stack_alloc() {
  return (Stack *)malloc(sizeof(Stack));
}

canonical_original_code:
static struct Stack *Stack_alloc() {
  return (struct Stack *)malloc(sizeof(Stack));
}

return_type: struct Stack { struct stack_node_t { struct stack_node_t *next; void *value; } *head; unsigned long size; } *

user_defined_types: struct Stack { struct stack_node_t *head; unsigned long size; }


decompiled_code:
void *StackIter_alloc()
{
return malloc(0x18uLL);
}

canonical_decompiled_code:
void *func1()
{
return malloc(0x18uLL);
}

original_code:
static StackIterator *StackIter_alloc() {
  return (StackIterator *)malloc(sizeof(StackIterator));
}

canonical_original_code:
static struct StackIterator *StackIter_alloc() {
  return (struct StackIterator *)malloc(sizeof(StackIterator));
}

return_type: struct StackIterator { struct Stack { struct stack_node_t { struct stack_node_t *next; void *value; } *head; unsigned long size; } *stack; struct stack_node_t *current; enum stack_iteration_state_t { SIST_UNKNOWN=0, SIST_BEFORE=1, SIST_RUNNING=2, SIST_AFTER=3 } state; } *

user_defined_types: struct StackIterator { struct Stack *stack; struct stack_node_t *current; enum stack_iteration_state_t state; }


decompiled_code:
_QWORD *Stack_new()
{
_QWORD *result; // rax

result = Stack_alloc();
if ( result )
{
*result = 0LL;
result[1] = 0LL;
}
return result;
}

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

result = func0();
if ( result )
{
*result = 0LL;
result[1] = 0LL;
}
return result;
}

original_code:
Stack *Stack_new() {
  Stack *p = Stack_alloc();
  if (!p) {
    return ((void *)0);
  }
  p->head = ((void *)0);
  p->size = 0;
  return p;
}

canonical_original_code:
struct Stack *Stack_new() {
  struct Stack *p = Stack_alloc();
  if (!p) {
    return ((void *)0);
  }
  p->head = ((void *)0);
  p->size = 0;
  return p;
}

variable_types: struct Stack { struct stack_node_t { struct stack_node_t *next; void *value; } *head; unsigned long size; } *


decompiled_code:
void __fastcall Stack_delete(void *a1)
{
if ( a1 )
free(a1);
}

canonical_decompiled_code:
void __fastcall func3(void *a1)
{
if ( a1 )
free(a1);
}

original_code:
void Stack_delete(Stack *stack) {
  if (stack) {
    stack->head = ((void *)0);
    stack->size = -1;
    free(stack);
  }
}

canonical_original_code:
void Stack_delete(struct Stack *stack) {
  if (stack) {
    stack->head = ((void *)0);
    stack->size = -1;
    free(stack);
  }
}

user_defined_types: struct stack_node_t { struct stack_node_t *next; void *value; }


decompiled_code:
__int64 __fastcall Stack_size(__int64 a1)
{
if ( !a1 )
_assert_fail("stack != NULL", "stack.c", 0x1Cu, "Stack_size");
return *(_QWORD *)(a1 + 8);
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1)
{
if ( !a1 )
_assert_fail("stack != NULL", "stack.c", 0x1Cu, "Stack_size");
return *(_QWORD *)(a1 + 8);
}

original_code:
inline unsigned long Stack_size(Stack *stack) {
  ((stack != ((void *)0)) ? (void) (0) : __assert_fail ("stack != NULL", "stack.c", 28, __extension__ __PRETTY_FUNCTION__));
  return stack->size;
}

canonical_original_code:
inline unsigned long Stack_size(struct Stack *stack) {
  ((stack != ((void *)0)) ? (void) (0) : __assert_fail ("stack != NULL", "stack.c", 28, __extension__ __PRETTY_FUNCTION__));
  return stack->size;
}

return_type: unsigned long


decompiled_code:
bool __fastcall Stack_isEmpty(__int64 a1)
{
if ( !a1 )
_assert_fail("stack != NULL", "stack.c", 0x21u, "Stack_isEmpty");
return *(_QWORD *)(a1 + 8) == 0LL;
}

canonical_decompiled_code:
bool __fastcall func5(__int64 a1)
{
if ( !a1 )
_assert_fail("stack != NULL", "stack.c", 0x21u, "Stack_isEmpty");
return *(_QWORD *)(a1 + 8) == 0LL;
}

original_code:
inline _Bool Stack_isEmpty(Stack *stack) {
  ((stack != ((void *)0)) ? (void) (0) : __assert_fail ("stack != NULL", "stack.c", 33, __extension__ __PRETTY_FUNCTION__));
  return stack->size == 0;
}

canonical_original_code:
inline _Bool Stack_isEmpty(struct Stack *stack) {
  ((stack != ((void *)0)) ? (void) (0) : __assert_fail ("stack != NULL", "stack.c", 33, __extension__ __PRETTY_FUNCTION__));
  return stack->size == 0;
}


decompiled_code:
__int64 __fastcall Stack_pop(__int64 a1)
{
__int64 *v1; // rax
__int64 v2; // rdx
__int64 result; // rax

if ( !a1 )
_assert_fail("stack != NULL", "stack.c", 0x2Eu, "Stack_pop");
if ( !Stack_size(a1) )
_assert_fail("Stack_size(stack) > 0", "stack.c", 0x2Fu, "Stack_pop");
v1 = *(__int64 **)a1;
v2 = **(_QWORD **)a1;
--*(_QWORD *)(a1 + 8);
result = v1[1];
*(_QWORD *)a1 = v2;
return result;
}

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

if ( !a1 )
_assert_fail("stack != NULL", "stack.c", 0x2Eu, "Stack_pop");
if ( !func4(a1) )
_assert_fail("Stack_size(stack) > 0", "stack.c", 0x2Fu, "Stack_pop");
v1 = *(__int64 **)a1;
v2 = **(_QWORD **)a1;
--*(_QWORD *)(a1 + 8);
result = v1[1];
*(_QWORD *)a1 = v2;
return result;
}

original_code:
void *Stack_pop(Stack *stack) {
  ((stack != ((void *)0)) ? (void) (0) : __assert_fail ("stack != NULL", "stack.c", 46, __extension__ __PRETTY_FUNCTION__));
  ((Stack_size(stack) > 0) ? (void) (0) : __assert_fail ("Stack_size(stack) > 0", "stack.c", 47, __extension__ __PRETTY_FUNCTION__));
  StackNode *p = stack->head;
  stack->head = p->next;
  --stack->size;
  return p->value;
}

canonical_original_code:
void *Stack_pop(struct Stack *stack) {
  ((stack != ((void *)0)) ? (void) (0) : __assert_fail ("stack != NULL", "stack.c", 46, __extension__ __PRETTY_FUNCTION__));
  ((Stack_size(stack) > 0) ? (void) (0) : __assert_fail ("Stack_size(stack) > 0", "stack.c", 47, __extension__ __PRETTY_FUNCTION__));
  struct stack_node_t *p = stack->head;
  stack->head = p->next;
  --stack->size;
  return p->value;
}

variable_types: struct stack_node_t { struct stack_node_t *next; void *value; } *


decompiled_code:
// attributes: thunk
void __fastcall StackNode_delete(void *a1)
{
Stack_delete(a1);
}

canonical_decompiled_code:
void __fastcall func7(void *a1)
{
func3(a1);
}

original_code:
void StackNode_delete(StackNode *node) {
  if (node) {
    node->next = ((void *)0);
    node->value = ((void *)0);
    free(node);
  }
}

canonical_original_code:
void StackNode_delete(struct stack_node_t *node) {
  if (node) {
    node->next = ((void *)0);
    node->value = ((void *)0);
    free(node);
  }
}


decompiled_code:
// attributes: thunk
void __fastcall StackIter_delete(void *a1)
{
Stack_delete(a1);
}

canonical_decompiled_code:
void __fastcall func8(void *a1)
{
func3(a1);
}

original_code:
void StackIter_delete(StackIterator *iter) {
  if (iter) {
    iter->stack = ((void *)0);
    iter->current = ((void *)0);
    iter->state = SIST_UNKNOWN;
    free(iter);
  }
}

canonical_original_code:
void StackIter_delete(struct StackIterator *iter) {
  if (iter) {
    iter->stack = ((void *)0);
    iter->current = ((void *)0);
    iter->state = SIST_UNKNOWN;
    free(iter);
  }
}

variable_types: struct StackIterator { struct Stack { struct stack_node_t { struct stack_node_t *next; void *value; } *head; unsigned long size; } *stack; struct stack_node_t *current; enum stack_iteration_state_t { SIST_UNKNOWN=0, SIST_BEFORE=1, SIST_RUNNING=2, SIST_AFTER=3 } state; } *


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

if ( !a1 )
_assert_fail("iter != NULL", "stack.c", 0x6Bu, "StackIter_current");
result = 0LL;
if ( *(_DWORD *)(a1 + 16) == 2 )
result = *(_QWORD *)(*(_QWORD *)(a1 + 8) + 8LL);
return result;
}

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

if ( !a1 )
_assert_fail("iter != NULL", "stack.c", 0x6Bu, "StackIter_current");
result = 0LL;
if ( *(_DWORD *)(a1 + 16) == 2 )
result = *(_QWORD *)(*(_QWORD *)(a1 + 8) + 8LL);
return result;
}

original_code:
void *StackIter_current(StackIterator *iter) {
  ((iter != ((void *)0)) ? (void) (0) : __assert_fail ("iter != NULL", "stack.c", 107, __extension__ __PRETTY_FUNCTION__));
  if (iter->state == SIST_RUNNING) {
    return iter->current->value;
  } else {
    return ((void *)0);
  }
}

canonical_original_code:
void *StackIter_current(struct StackIterator *iter) {
  ((iter != ((void *)0)) ? (void) (0) : __assert_fail ("iter != NULL", "stack.c", 107, __extension__ __PRETTY_FUNCTION__));
  if (iter->state == SIST_RUNNING) {
    return iter->current->value;
  } else {
    return ((void *)0);
  }
}

user_defined_types: enum stack_iteration_state_t { SIST_UNKNOWN=0, SIST_BEFORE=1, SIST_RUNNING=2, SIST_AFTER=3 }


decompiled_code:
__int64 __fastcall StackIter_moveNext(__int64 ***a1)
{
int v1; // eax
__int64 result; // rax
__int64 *v3; // rax
__int64 *v4; // rax

if ( !a1 )
_assert_fail("iter != NULL", "stack.c", 0x74u, "StackIter_moveNext");
v1 = *((_DWORD *)a1 + 4);
switch ( v1 )
{
case 2:
v4 = *a1[1];
if ( !v4 )
{
a1[1] = 0LL;
*((_DWORD *)a1 + 4) = 3;
return 0LL;
}
a1[1] = (__int64 **)v4;
result = 1LL;
break;
case 3:
return 0LL;
case 1:
v3 = **a1;
if ( !v3 )
{
*((_DWORD *)a1 + 4) = 3;
return 0LL;
}
a1[1] = (__int64 **)v3;
*((_DWORD *)a1 + 4) = 2;
result = 1LL;
break;
default:
StackIter_moveNext_cold();
}
return result;
}

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

if ( !a1 )
_assert_fail("iter != NULL", "stack.c", 0x74u, "StackIter_moveNext");
v1 = *((_DWORD *)a1 + 4);
switch ( v1 )
{
case 2:
v4 = *a1[1];
if ( !v4 )
{
a1[1] = 0LL;
*((_DWORD *)a1 + 4) = 3;
return 0LL;
}
a1[1] = (__int64 **)v4;
result = 1LL;
break;
case 3:
return 0LL;
case 1:
v3 = **a1;
if ( !v3 )
{
*((_DWORD *)a1 + 4) = 3;
return 0LL;
}
a1[1] = (__int64 **)v3;
*((_DWORD *)a1 + 4) = 2;
result = 1LL;
break;
default:
func11();
}
return result;
}

original_code:
_Bool StackIter_moveNext(StackIterator *iter) {
    ((iter != ((void *)0)) ? (void) (0) : __assert_fail ("iter != NULL", "stack.c", 116, __extension__ __PRETTY_FUNCTION__));
    switch (iter->state) {
        case SIST_BEFORE:
            if (iter->stack->head) {
                iter->current = iter->stack->head;
                iter->state = SIST_RUNNING;
                return 1;
            } else {
                iter->state = SIST_AFTER;
                return 0;
            }
        case SIST_RUNNING:
            if (iter->current->next) {
                iter->current = iter->current->next;
                return 1;
            } else {
                iter->current = ((void *)0);
                iter->state = SIST_AFTER;
                return 0;
            }
        case SIST_AFTER:
            return 0;
        default:
            abort();
    }
}

canonical_original_code:
_Bool StackIter_moveNext(struct StackIterator *iter) {
    ((iter != ((void *)0)) ? (void) (0) : __assert_fail ("iter != NULL", "stack.c", 116, __extension__ __PRETTY_FUNCTION__));
    switch (iter->state) {
        case SIST_BEFORE:
            if (iter->stack->head) {
                iter->current = iter->stack->head;
                iter->state = SIST_RUNNING;
                return 1;
            } else {
                iter->state = SIST_AFTER;
                return 0;
            }
        case SIST_RUNNING:
            if (iter->current->next) {
                iter->current = iter->current->next;
                return 1;
            } else {
                iter->current = ((void *)0);
                iter->state = SIST_AFTER;
                return 0;
            }
        case SIST_AFTER:
            return 0;
        default:
            abort();
    }
}


repo: mayurva/DFS

decompiled_code:
int __fastcall print_msg(__int64 a1)
{
int result; // eax

result = *(_DWORD *)(a1 + 8);
switch ( result )
{
case 3:
return printf(
"OPEN_REQ: path is %s flags %d\n",
*(const char **)(a1 + 16),
*(unsigned int *)(*(_QWORD *)(a1 + 16) + 512LL));
case 9:
return printf("GETATTR_REQ: path is %s\n", *(const char **)(a1 + 16));
case 1:
result = printf("MAKE_DIR_REQ: path is %s\n", *(const char **)(a1 + 16));
break;
}
return result;
}

canonical_decompiled_code:
int __fastcall func1(__int64 a1)
{
int result; // eax

result = *(_DWORD *)(a1 + 8);
switch ( result )
{
case 3:
return printf(
"OPEN_REQ: path is %s flags %d\n",
*(const char **)(a1 + 16),
*(unsigned int *)(*(_QWORD *)(a1 + 16) + 512LL));
case 9:
return printf("GETATTR_REQ: path is %s\n", *(const char **)(a1 + 16));
case 1:
result = printf("MAKE_DIR_REQ: path is %s\n", *(const char **)(a1 + 16));
break;
}
return result;
}

original_code:
void print_msg(dfs_msg *msg)
{
 switch(msg->msg_type)
 {
         case HEARTBEAT:
   break;
         case MAKE_DIR_REQ:
   printf("MAKE_DIR_REQ: path is %s\n",((mkdir_req*)msg->data)->path);
   break;
         case MAKE_DIR_RESP:
   break;
         case OPEN_REQ:
   printf("OPEN_REQ: path is %s flags %d\n",((open_req*)msg->data)->path, ((open_req*)msg->data)->flags);
   break;
  case OPEN_RESP:
   break;
         case CREATE_REQ:
   break;
  case CREATE_RESP:
   break;
  case GETATTR_REQ:
   printf("GETATTR_REQ: path is %s\n",((char*)msg->data));
   break;
  case GETATTR_RESP:
   break;
  case READDIR_REQ:
   break;
  case READDIR_RESP:
   break;
  case READ_REQ:
   break;
  case READ_RESP:
   break;
  case READ_DATA_REQ:
   break;
  case READ_DATA_RESP:
   break;
  case WRITE_REQ:
   break;
  case WRITE_RESP:
   break;
  case WRITE_DATA_REQ:
   break;
  case WRITE_DATA_RESP:
   break;
 }
}

canonical_original_code:
void print_msg(struct dfs_msg_ *msg)
{
 switch(msg->msg_type)
 {
         case HEARTBEAT:
   break;
         case MAKE_DIR_REQ:
   printf("MAKE_DIR_REQ: path is %s\n",((struct mkdir_req_ *)msg->data)->path);
   break;
         case MAKE_DIR_RESP:
   break;
         case OPEN_REQ:
   printf("OPEN_REQ: path is %s flags %d\n",((struct open_req_ *)msg->data)->path, ((struct open_req_ *)msg->data)->flags);
   break;
  case OPEN_RESP:
   break;
         case CREATE_REQ:
   break;
  case CREATE_RESP:
   break;
  case GETATTR_REQ:
   printf("GETATTR_REQ: path is %s\n",((char *)msg->data));
   break;
  case GETATTR_RESP:
   break;
  case READDIR_REQ:
   break;
  case READDIR_RESP:
   break;
  case READ_REQ:
   break;
  case READ_RESP:
   break;
  case READ_DATA_REQ:
   break;
  case READ_DATA_RESP:
   break;
  case WRITE_REQ:
   break;
  case WRITE_RESP:
   break;
  case WRITE_DATA_REQ:
   break;
  case WRITE_DATA_RESP:
   break;
 }
}

variable_types: struct dfs_msg_ { int seq; int status; int msg_type; int len; void *data; } *

user_defined_types: struct mkdir_req_ { char path[-1]; unsigned int mode; }

user_defined_types: struct open_req_ { char path[-1]; int flags; }


getRandom

decompiled_code:
__int64 __fastcall getRandom(int a1, int a2)
{
struct timeval v3; // [rsp+0h] [rbp-28h] BYREF

gettimeofday(&v3, 0LL);
srand(LODWORD(v3.tv_sec) + LODWORD(v3.tv_usec));
return (unsigned int)(rand() % (a2 - a1) + a1);
}

canonical_decompiled_code:
__int64 __fastcall func2(int a1, int a2)
{
struct timeval v3; // [rsp+0h] [rbp-28h] BYREF

gettimeofday(&v3, 0LL);
srand(LODWORD(v3.tv_sec) + LODWORD(v3.tv_usec));
return (unsigned int)(rand() % (a2 - a1) + a1);
}

original_code:
int getRandom(int lower,int upper)
{
 struct timeval tv;
 int seed;
 gettimeofday(&tv,((void *)0));
 seed = tv.tv_sec+tv.tv_usec;
 srand(seed);
 return ((rand()%(upper-lower))+lower);
}

canonical_original_code:
int getRandom(int lower, int upper)
{
 struct timeval tv;
 int seed;
 gettimeofday(&tv,((void *)0));
 seed = tv.tv_sec+tv.tv_usec;
 srand(seed);
 return ((rand()%(upper-lower))+lower);
}

variable_types: lower int

variable_types: upper int

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

variable_types: seed int


populateIp

decompiled_code:
__int64 __fastcall populateIp(char *dest, char *name)
{
struct hostent *v2; // rax
char *v3; // rax

v2 = gethostbyname(name);
if ( !v2 )
return 0xFFFFFFFFLL;
v3 = inet_ntoa((struct in_addr)(*(struct in_addr **)v2->h_addr_list)->s_addr);
strcpy(dest, v3);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func4(char *dest, char *name)
{
struct hostent *v2; // rax
char *v3; // rax

v2 = gethostbyname(name);
if ( !v2 )
return 0xFFFFFFFFLL;
v3 = inet_ntoa((struct in_addr)(*(struct in_addr **)v2->h_addr_list)->s_addr);
strcpy(dest, v3);
return 0LL;
}

original_code:
int populateIp(host *h,char *hostname)
{
 struct hostent *lh = gethostbyname(hostname);
 if(lh){
  strcpy(h->ip_addr,inet_ntoa( *( struct in_addr*)( lh -> h_addr_list[0])));
  return 0;
 }
 return -1;
}

canonical_original_code:
int populateIp(struct host_ *h, char *hostname)
{
 struct hostent *lh = gethostbyname(hostname);
 if(lh){
  strcpy(h->ip_addr,inet_ntoa( *( struct in_addr *)( lh -> h_addr_list[0])));
  return 0;
 }
 return -1;
}

variable_types: struct host_ { char ip_addr[128]; int port; } *

variable_types:
hostname
char *

variable_types: struct hostent { char *h_name; char **h_aliases; int h_addrtype; int h_length; char **h_addr_list; } *


decompiled_code:
void __fastcall free_msg(void *ptr)
{
free(**((void ***)ptr + 2));
free(*((void **)ptr + 2));
free(ptr);
}

canonical_decompiled_code:
void __fastcall func10(void *ptr)
{
free(**((void ***)ptr + 2));
free(*((void **)ptr + 2));
free(ptr);
}

original_code:
void free_msg(struct msghdr *msg)
{
        free(msg->msg_iov[0].iov_base);
        free(msg->msg_iov);
        free(msg);
}

variable_types: struct msghdr { void *msg_name; unsigned int msg_namelen; struct iovec { void *iov_base; unsigned long iov_len; } *msg_iov; unsigned long msg_iovlen; void *msg_control; unsigned long msg_controllen; int msg_flags; } *

user_defined_types: struct msghdr { void *msg_name; unsigned int msg_namelen; struct iovec *msg_iov; unsigned long msg_iovlen; void *msg_control; unsigned long msg_controllen; int msg_flags; }


nullQueue

decompiled_code:
_BOOL8 __fastcall nullQueue(__int64 a1)
{
return a1 == 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func0(__int64 a1)
{
return a1 == 0;
}

original_code:
int nullQueue(queue q)
{
 if(q.head == ((void *)0)) return 1;
 return 0;
}

canonical_original_code:
int nullQueue(struct queue_ q)
{
 if(q.head == ((void *)0)) return 1;
 return 0;
}

variable_types: struct queue_ { struct Mythread_ { int threadId; int yieldFlag; int blocked; int parentBlocked; struct ucontext_t { unsigned long uc_flags; struct ucontext_t *uc_link; struct stack_t { void *ss_sp; int ss_flags; unsigned long ss_size; } uc_stack; struct mcontext_t { long long gregs[23]; struct _libc_fpstate { unsigned short cwd; unsigned short swd; unsigned short ftw; unsigned short fop; unsigned long rip; unsigned long rdp; unsigned int mxcsr; unsigned int mxcr_mask; struct _libc_fpxreg { unsigned short significand[4]; unsigned short exponent; unsigned short __glibc_reserved1[3]; } _st[8]; struct _libc_xmmreg { unsigned int element[4]; } _xmm[16]; unsigned int __glibc_reserved1[24]; } *fpregs; unsigned long long __reserved1[8]; } uc_mcontext; struct __sigset_t { unsigned long __val[-1]; } uc_sigmask; struct _libc_fpstate __fpregs_mem; unsigned long long __ssp[4]; } *thread; struct Mythread_ *next; struct Mythread_ *childList; struct Mythread_ *sibling; struct Mythread_ *parentptr; } *head; }

user_defined_types: struct queue_ { struct Mythread_ *head; }

user_defined_types: struct Mythread_ { int threadId; int yieldFlag; int blocked; int parentBlocked; struct ucontext_t *thread; struct Mythread_ *next; struct Mythread_ *childList; struct Mythread_ *sibling; struct Mythread_ *parentptr; }

user_defined_types: struct ucontext_t { unsigned long uc_flags; struct ucontext_t *uc_link; struct stack_t uc_stack; struct mcontext_t uc_mcontext; struct __sigset_t uc_sigmask; struct _libc_fpstate __fpregs_mem; unsigned long long __ssp[4]; }

user_defined_types: struct mcontext_t { long long gregs[23]; struct _libc_fpstate *fpregs; unsigned long long __reserved1[8]; }

user_defined_types: struct _libc_fpstate { unsigned short cwd; unsigned short swd; unsigned short ftw; unsigned short fop; unsigned long rip; unsigned long rdp; unsigned int mxcsr; unsigned int mxcr_mask; struct _libc_fpxreg _st[8]; struct _libc_xmmreg _xmm[16]; unsigned int __glibc_reserved1[24]; }


addToQueue

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

if ( *a1 )
{
result = a1[1];
*(_QWORD *)(result + 24) = a2;
a1[1] = a2;
}
else
{
a1[1] = a2;
*a1 = a2;
}
*(_QWORD *)(a2 + 24) = 0LL;
return result;
}

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

if ( *a1 )
{
result = a1[1];
*(_QWORD *)(result + 24) = a2;
a1[1] = a2;
}
else
{
a1[1] = a2;
*a1 = a2;
}
*(_QWORD *)(a2 + 24) = 0LL;
return result;
}

original_code:
void addToQueue(queue *q, Mythread *ptr)
{
 if(q->head == ((void *)0))
 {
  q->head = q-> tail = ptr;
 }
 else
 {
  q->tail->next = ptr;
  q->tail = ptr;
 }
 ptr -> next = ((void *)0);
}

canonical_original_code:
void addToQueue(struct queue_ *q, struct Mythread_ *ptr)
{
 if(q->head == ((void *)0))
 {
  q->head = q-> tail = ptr;
 }
 else
 {
  q->tail->next = ptr;
  q->tail = ptr;
 }
 ptr -> next = ((void *)0);
}

variable_types: struct queue_ { struct Mythread_ { int threadId; int yieldFlag; int blocked; int parentBlocked; struct ucontext_t { unsigned long uc_flags; struct ucontext_t *uc_link; struct stack_t { void *ss_sp; int ss_flags; unsigned long ss_size; } uc_stack; struct mcontext_t { long long gregs[23]; struct _libc_fpstate { unsigned short cwd; unsigned short swd; unsigned short ftw; unsigned short fop; unsigned long rip; unsigned long rdp; unsigned int mxcsr; unsigned int mxcr_mask; struct _libc_fpxreg { unsigned short significand[4]; unsigned short exponent; unsigned short __glibc_reserved1[3]; } _st[8]; struct _libc_xmmreg { unsigned int element[4]; } _xmm[16]; unsigned int __glibc_reserved1[24]; } *fpregs; unsigned long long __reserved1[8]; } uc_mcontext; struct __sigset_t { unsigned long __val[-1]; } uc_sigmask; struct _libc_fpstate __fpregs_mem; unsigned long long __ssp[4]; } *thread; struct Mythread_ *next; struct Mythread_ *childList; struct Mythread_ *sibling; struct Mythread_ *parentptr; } *head; } *

variable_types:
ptr
struct Mythread_ *


remFromQueue

decompiled_code:
__int64 __fastcall remFromQueue(__int64 *a1)
{
__int64 result; // rax
__int64 v2; // rdx

result = *a1;
if ( *a1 )
{
v2 = *(_QWORD *)(result + 24);
if ( v2 )
{
*a1 = v2;
}
else
{
a1[1] = 0LL;
*a1 = 0LL;
}
*(_DWORD *)(result + 4) = 0;
}
return result;
}

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

result = *a1;
if ( *a1 )
{
v2 = *(_QWORD *)(result + 24);
if ( v2 )
{
*a1 = v2;
}
else
{
a1[1] = 0LL;
*a1 = 0LL;
}
*(_DWORD *)(result + 4) = 0;
}
return result;
}

original_code:
Mythread* remFromQueue(queue *q)
{
 Mythread *ptr;
 ptr = q -> head;
 if(q -> head!=((void *)0))
 {
  if(q->head->next == ((void *)0)) q->head = q -> tail = ((void *)0);
  else q->head = q -> head -> next;
  ptr -> yieldFlag = 0;
 }
 return ptr;
}

canonical_original_code:
struct Mythread_ *remFromQueue(struct queue_ *q)
{
 struct Mythread_ *ptr;
 ptr = q -> head;
 if(q -> head!=((void *)0))
 {
  if(q->head->next == ((void *)0)) q->head = q -> tail = ((void *)0);
  else q->head = q -> head -> next;
  ptr -> yieldFlag = 0;
 }
 return ptr;
}

variable_types: struct queue_ { struct Mythread_ *head; } *

variable_types: struct Mythread_ { int threadId; int yieldFlag; int blocked; int parentBlocked; struct ucontext_t { unsigned long uc_flags; struct ucontext_t *uc_link; struct stack_t { void *ss_sp; int ss_flags; unsigned long ss_size; } uc_stack; struct mcontext_t { long long gregs[23]; struct _libc_fpstate { unsigned short cwd; unsigned short swd; unsigned short ftw; unsigned short fop; unsigned long rip; unsigned long rdp; unsigned int mxcsr; unsigned int mxcr_mask; struct _libc_fpxreg { unsigned short significand[4]; unsigned short exponent; unsigned short __glibc_reserved1[3]; } _st[8]; struct _libc_xmmreg { unsigned int element[4]; } _xmm[16]; unsigned int __glibc_reserved1[24]; } *fpregs; unsigned long long __reserved1[8]; } uc_mcontext; struct __sigset_t { unsigned long __val[-1]; } uc_sigmask; struct _libc_fpstate __fpregs_mem; unsigned long long __ssp[4]; } *thread; struct Mythread_ *next; struct Mythread_ *childList; struct Mythread_ *sibling; struct Mythread_ *parentptr; } *


printQueue

decompiled_code:
int __fastcall printQueue(unsigned int *a1)
{
unsigned int *v1; // rbx

v1 = a1;
printf("Queue is:");
if ( a1 )
{
do
{
printf("\tThread id: %d, Yield Flag: %d", *v1, v1[1]);
v1 = (unsigned int *)*((_QWORD *)v1 + 3);
}
while ( v1 );
}
return putchar(10);
}

canonical_decompiled_code:
int __fastcall func3(unsigned int *a1)
{
unsigned int *v1; // rbx

v1 = a1;
printf("Queue is:");
if ( a1 )
{
do
{
printf("\tThread id: %d, Yield Flag: %d", *v1, v1[1]);
v1 = (unsigned int *)*((_QWORD *)v1 + 3);
}
while ( v1 );
}
return putchar(10);
}

original_code:
void printQueue(queue q)
{
 Mythread *ptr;
 ptr = q.head;
 printf("Queue is:");
 while(ptr)
 {
  printf("\tThread id: %d, Yield Flag: %d",ptr->threadId,ptr->yieldFlag);
  ptr = ptr -> next;
 }
 printf("\n");
}

canonical_original_code:
void printQueue(struct queue_ q)
{
 struct Mythread_ *ptr;
 ptr = q.head;
 printf("Queue is:");
 while(ptr)
 {
  printf("\tThread id: %d, Yield Flag: %d",ptr->threadId,ptr->yieldFlag);
  ptr = ptr -> next;
 }
 printf("\n");
}

user_defined_types: struct stack_t { void *ss_sp; int ss_flags; unsigned long ss_size; }

user_defined_types: struct __sigset_t { unsigned long __val[-1]; }

user_defined_types: struct _libc_fpxreg { unsigned short significand[4]; unsigned short exponent; unsigned short __glibc_reserved1[3]; }

user_defined_types: struct _libc_xmmreg { unsigned int element[4]; }


addChild

decompiled_code:
void __fastcall addChild(__int64 a1)
{
__int64 v1; // rax
__int64 v2; // rdx

if ( a1 )
{
v1 = *((_QWORD *)currThread + 4);
if ( v1 )
{
do
{
v2 = v1;
v1 = *(_QWORD *)(v1 + 40);
}
while ( v1 );
*(_QWORD *)(v2 + 40) = a1;
}
else
{
*((_QWORD *)currThread + 4) = a1;
}
}
}

original_code:
void addChild(Mythread *t)
{
 if(t != ((void *)0))
 {
  if(currThread -> childList == ((void *)0)) currThread -> childList = t;
  else
  {
   Mythread *ptr = currThread -> childList;
   while(ptr -> sibling != ((void *)0))
    ptr = ptr -> sibling;
   ptr -> sibling = t;
  }
 }
}

canonical_original_code:
void addChild(struct Mythread_ *t)
{
 if(t != ((void *)0))
 {
  if(currThread -> childList == ((void *)0)) currThread -> childList = t;
  else
  {
   struct Mythread_ *ptr = currThread -> childList;
   while(ptr -> sibling != ((void *)0))
    ptr = ptr -> sibling;
   ptr -> sibling = t;
  }
 }
}


MyThreadCreate

decompiled_code:
void *__fastcall MyThreadCreate(void (*a1)(void), __int64 a2)
{
ucontext_t *v2; // rbp
void *v3; // rax
int v4; // edx
void *v5; // rdx
void *v7; // [rsp+8h] [rbp-20h]

v7 = malloc(0x38uLL);
if ( v7
&& (v2 = (ucontext_t *)malloc(0x3C8uLL), (*((_QWORD *)v7 + 2) = v2) != 0LL)
&& (v3 = malloc(0x2000uLL), (sizeArr = v3) != 0LL) )
{
v4 = id;
v2->uc_stack.ss_sp = v3;
v2->uc_link = 0LL;
*(_DWORD *)v7 = v4;
id = v4 + 1;
v5 = currThread;
*((_QWORD *)v7 + 5) = 0LL;
*((_QWORD *)v7 + 4) = 0LL;
*((_QWORD *)v7 + 6) = v5;
*((_DWORD *)v7 + 1) = 0;
*((_QWORD *)v7 + 1) = 0LL;
v2->uc_stack.ss_size = 0x2000LL;
getcontext(v2);
makecontext(*((ucontext_t **)v7 + 2), a1, 1, a2);
addToQueue(&readyQueue, v7);
addChild((__int64)v7);
}
else
{
perror("ERROR:Not enough memory to create a Thread.. No thread created\n");
}
return v7;
}

canonical_decompiled_code:
void *__fastcall func1(void (*a1)(void), __int64 a2)
{
ucontext_t *v2; // rbp
void *v3; // rax
int v4; // edx
void *v5; // rdx
void *v7; // [rsp+8h] [rbp-20h]

v7 = malloc(0x38uLL);
if ( v7
&& (v2 = (ucontext_t *)malloc(0x3C8uLL), (*((_QWORD *)v7 + 2) = v2) != 0LL)
&& (v3 = malloc(0x2000uLL), (sizeArr = v3) != 0LL) )
{
v4 = id;
v2->uc_stack.ss_sp = v3;
v2->uc_link = 0LL;
*(_DWORD *)v7 = v4;
id = v4 + 1;
v5 = currThread;
*((_QWORD *)v7 + 5) = 0LL;
*((_QWORD *)v7 + 4) = 0LL;
*((_QWORD *)v7 + 6) = v5;
*((_DWORD *)v7 + 1) = 0;
*((_QWORD *)v7 + 1) = 0LL;
v2->uc_stack.ss_size = 0x2000LL;
getcontext(v2);
makecontext(*((ucontext_t **)v7 + 2), a1, 1, a2);
addToQueue(&readyQueue, v7);
func0((__int64)v7);
}
else
{
perror("ERROR:Not enough memory to create a Thread.. No thread created\n");
}
return v7;
}

original_code:
MyThread MyThreadCreate(void (*start_funct)(void *),void *args)
{
 Mythread *t;
 t = (Mythread*) malloc(sizeof(Mythread));
 if(t == ((void *)0)) perror("ERROR:Not enough memory to create a Thread.. No thread created\n");
 else
 {
  t -> thread = malloc(sizeof(ucontext_t));
  if(t->thread == ((void *)0)) perror("ERROR:Not enough memory to create a Thread.. No thread created\n");
  else
  {
   sizeArr = malloc(8<<10);
   if(sizeArr == ((void *)0)) perror("ERROR:Not enough memory to create a Thread.. No thread created\n");
   else
   {
    t -> threadId = id;
    id++;
    t -> yieldFlag = 0;
    t -> childList = t -> sibling = ((void *)0);
    t -> parentptr = currThread;
    t -> blocked = 0;
    t -> parentBlocked = 0;
    t -> thread -> uc_link = ((void *)0);
    t -> thread -> uc_stack.ss_sp = sizeArr;
    t -> thread -> uc_stack.ss_size = 8<<10;
    getcontext(t -> thread);
    makecontext(t -> thread,(void(*)(void)) start_funct,1,args);
    addToQueue(&readyQueue,t);
    addChild(t);
   }
  }
 }
 return t;
}

canonical_original_code:
void *MyThreadCreate(void (*start_funct)(void *), void *args)
{
 struct Mythread_ *t;
 t = (struct Mythread_ *) malloc(sizeof(Mythread));
 if(t == ((void *)0)) perror("ERROR:Not enough memory to create a Thread.. No thread created\n");
 else
 {
  t -> thread = malloc(sizeof(ucontext_t));
  if(t->thread == ((void *)0)) perror("ERROR:Not enough memory to create a Thread.. No thread created\n");
  else
  {
   sizeArr = malloc(8<<10);
   if(sizeArr == ((void *)0)) perror("ERROR:Not enough memory to create a Thread.. No thread created\n");
   else
   {
    t -> threadId = id;
    id++;
    t -> yieldFlag = 0;
    t -> childList = t -> sibling = ((void *)0);
    t -> parentptr = currThread;
    t -> blocked = 0;
    t -> parentBlocked = 0;
    t -> thread -> uc_link = ((void *)0);
    t -> thread -> uc_stack.ss_sp = sizeArr;
    t -> thread -> uc_stack.ss_size = 8<<10;
    getcontext(t -> thread);
    makecontext(t -> thread,(void (*)()) start_funct,1,args);
    addToQueue(&readyQueue,t);
    addChild(t);
   }
  }
 }
 return t;
}

variable_types:
args
void *


MyThreadYield

decompiled_code:
int MyThreadYield()
{
ucontext_t **v0; // rax
int result; // eax
__int64 v2; // rax
const ucontext_t *v3; // rdi
ucontext_t **v4; // [rsp+8h] [rbp-10h]

v0 = (ucontext_t **)currThread;
*((_DWORD *)currThread + 1) = 1;
v4 = v0;
getcontext(v0[2]);
result = *((_DWORD *)currThread + 1);
if ( result )
{
addToQueue(&readyQueue, v4);
v2 = remFromQueue(&readyQueue);
if ( v2 )
{
*(_DWORD *)(v2 + 4) = 0;
v3 = *(const ucontext_t **)(v2 + 16);
currThread = (void *)v2;
result = setcontext(v3);
}
else
{
result = setcontext(mainPrg);
}
}
return result;
}

canonical_decompiled_code:
int func2()
{
ucontext_t **v0; // rax
int result; // eax
__int64 v2; // rax
const ucontext_t *v3; // rdi
ucontext_t **v4; // [rsp+8h] [rbp-10h]

v0 = (ucontext_t **)currThread;
*((_DWORD *)currThread + 1) = 1;
v4 = v0;
getcontext(v0[2]);
result = *((_DWORD *)currThread + 1);
if ( result )
{
addToQueue(&readyQueue, v4);
v2 = remFromQueue(&readyQueue);
if ( v2 )
{
*(_DWORD *)(v2 + 4) = 0;
v3 = *(const ucontext_t **)(v2 + 16);
currThread = (void *)v2;
result = setcontext(v3);
}
else
{
result = setcontext(mainPrg);
}
}
return result;
}

original_code:
void MyThreadYield(void)
{
 Mythread *t;
 currThread-> yieldFlag = 1;
 t = currThread;
 getcontext(t->thread);
 if(currThread -> yieldFlag)
 {
  addToQueue(&readyQueue,t);
  t = remFromQueue(&readyQueue);
  if(t == ((void *)0))
  {
   setcontext(mainPrg);
   return;
  }
  t -> yieldFlag = 0;
  currThread = t;
  setcontext(t->thread);
 }
 else
 {
  return;
 }
}

canonical_original_code:
void MyThreadYield()
{
 struct Mythread_ *t;
 currThread-> yieldFlag = 1;
 t = currThread;
 getcontext(t->thread);
 if(currThread -> yieldFlag)
 {
  addToQueue(&readyQueue,t);
  t = remFromQueue(&readyQueue);
  if(t == ((void *)0))
  {
   setcontext(mainPrg);
   return;
  }
  t -> yieldFlag = 0;
  currThread = t;
  setcontext(t->thread);
 }
 else
 {
  return;
 }
}


deleteChild

decompiled_code:
void deleteChild()
{
_DWORD *v0; // rdi
__int64 v1; // rsi
__int64 v2; // rax
__int64 v3; // rcx
int v4; // eax
bool v5; // zf

v0 = currThread;
v1 = *((_QWORD *)currThread + 6);
if ( v1 )
{
v2 = *(_QWORD *)(v1 + 32);
if ( v2 )
{
if ( *(_DWORD *)v2 == *(_DWORD *)currThread )
{
*(_QWORD *)(v1 + 32) = *(_QWORD *)(v2 + 40);
}
else
{
while ( 1 )
{
v3 = v2;
v2 = *(_QWORD *)(v2 + 40);
if ( !v2 )
break;
if ( *(_DWORD *)currThread == *(_DWORD *)v2 )
{
v5 = *((_DWORD *)currThread + 3) == 1;
*(_QWORD *)(v3 + 40) = *(_QWORD *)(v2 + 40);
if ( !v5 )
return;
goto LABEL_10;
}
}
}
if ( v0[3] == 1 )
{
LABEL_10:
v4 = *(_DWORD *)(v1 + 8) - 1;
*(_DWORD *)(v1 + 8) = v4;
if ( v4 <= 0 )
addToQueue(&readyQueue, v1);
}
}
}
}

original_code:
void deleteChild()
{
 Mythread *temp;
 Mythread *t = currThread -> parentptr;
 if(t != ((void *)0))
 {
  temp = t -> childList;
  if(temp == ((void *)0)) return;
  if(temp -> threadId == currThread -> threadId) t -> childList = temp -> sibling;
  else
   while(temp -> sibling != ((void *)0))
   {
    if(temp -> sibling -> threadId == currThread -> threadId)
    {
     temp -> sibling = temp -> sibling -> sibling;
     break;
    }
    temp = temp -> sibling;
   }
  if(currThread->parentBlocked == 1)
  {
   temp = currThread -> parentptr;
   temp -> blocked = temp -> blocked -1;
   if(temp -> blocked <= 0)
    addToQueue(&readyQueue,temp);
  }
 }
}

canonical_original_code:
void deleteChild()
{
 struct Mythread_ *temp;
 struct Mythread_ *t = currThread -> parentptr;
 if(t != ((void *)0))
 {
  temp = t -> childList;
  if(temp == ((void *)0)) return;
  if(temp -> threadId == currThread -> threadId) t -> childList = temp -> sibling;
  else
   while(temp -> sibling != ((void *)0))
   {
    if(temp -> sibling -> threadId == currThread -> threadId)
    {
     temp -> sibling = temp -> sibling -> sibling;
     break;
    }
    temp = temp -> sibling;
   }
  if(currThread->parentBlocked == 1)
  {
   temp = currThread -> parentptr;
   temp -> blocked = temp -> blocked -1;
   if(temp -> blocked <= 0)
    addToQueue(&readyQueue,temp);
  }
 }
}


MyThreadJoin

decompiled_code:
int __fastcall MyThreadJoin(int *a1)
{
void *v1; // rcx
__int64 v2; // rax
int v3; // edx
ucontext_t *v4; // rdi
__int64 v6; // rax
const ucontext_t *v7; // rdi

if ( !a1 )
return -1;
v1 = currThread;
v2 = *((_QWORD *)currThread + 4);
if ( !v2 )
return -1;
while ( 1 )
{
v3 = *a1;
*(_DWORD *)v2 = *a1;
if ( v3 )
break;
v2 = *(_QWORD *)(v2 + 40);
if ( !v2 )
return -1;
}
++*((_DWORD *)v1 + 2);
v4 = (ucontext_t *)*((_QWORD *)v1 + 2);
*(_DWORD *)(v2 + 12) = 1;
*((_DWORD *)v1 + 1) = 1;
getcontext(v4);
if ( *((_DWORD *)currThread + 1) != 1 )
return 0;
v6 = remFromQueue(&readyQueue);
if ( v6 )
{
*(_DWORD *)(v6 + 4) = 0;
v7 = *(const ucontext_t **)(v6 + 16);
currThread = (void *)v6;
setcontext(v7);
return 0;
}
return setcontext(mainPrg);
}

canonical_decompiled_code:
int __fastcall func4(int *a1)
{
void *v1; // rcx
__int64 v2; // rax
int v3; // edx
ucontext_t *v4; // rdi
__int64 v6; // rax
const ucontext_t *v7; // rdi

if ( !a1 )
return -1;
v1 = currThread;
v2 = *((_QWORD *)currThread + 4);
if ( !v2 )
return -1;
while ( 1 )
{
v3 = *a1;
*(_DWORD *)v2 = *a1;
if ( v3 )
break;
v2 = *(_QWORD *)(v2 + 40);
if ( !v2 )
return -1;
}
++*((_DWORD *)v1 + 2);
v4 = (ucontext_t *)*((_QWORD *)v1 + 2);
*(_DWORD *)(v2 + 12) = 1;
*((_DWORD *)v1 + 1) = 1;
getcontext(v4);
if ( *((_DWORD *)currThread + 1) != 1 )
return 0;
v6 = remFromQueue(&readyQueue);
if ( v6 )
{
*(_DWORD *)(v6 + 4) = 0;
v7 = *(const ucontext_t **)(v6 + 16);
currThread = (void *)v6;
setcontext(v7);
return 0;
}
return setcontext(mainPrg);
}

original_code:
int MyThreadJoin(MyThread thread)
{
 int flag = -1;
 if(thread!=((void *)0))
 {
  Mythread *t = currThread -> childList;
  if(t!=((void *)0))
  {
   do
   {
    if(t->threadId = ((Mythread* ) thread) -> threadId)
    {
     currThread->blocked = currThread->blocked+1;
     t -> parentBlocked = 1;
     flag = 0;
     break;
    }
    t = t->sibling;
   }
   while(t!=((void *)0));
  }
  if(!flag)
  {
   currThread -> yieldFlag = 1;
   getcontext(currThread -> thread);
   if(currThread -> yieldFlag == 1)
   {
    t = (Mythread*) remFromQueue(&readyQueue);
    if(t == ((void *)0))
    {
     setcontext(mainPrg);
     return;
    }
    t -> yieldFlag = 0;
    currThread = t;
    setcontext(t->thread);
   }
  }
 }
 return flag;
}

canonical_original_code:
int MyThreadJoin(void *thread)
{
 int flag = -1;
 if(thread!=((void *)0))
 {
  struct Mythread_ *t = currThread -> childList;
  if(t!=((void *)0))
  {
   do
   {
    if(t->threadId = ((struct Mythread_ * ) thread) -> threadId)
    {
     currThread->blocked = currThread->blocked+1;
     t -> parentBlocked = 1;
     flag = 0;
     break;
    }
    t = t->sibling;
   }
   while(t!=((void *)0));
  }
  if(!flag)
  {
   currThread -> yieldFlag = 1;
   getcontext(currThread -> thread);
   if(currThread -> yieldFlag == 1)
   {
    t = (struct Mythread_ *) remFromQueue(&readyQueue);
    if(t == ((void *)0))
    {
     setcontext(mainPrg);
     return;
    }
    t -> yieldFlag = 0;
    currThread = t;
    setcontext(t->thread);
   }
  }
 }
 return flag;
}

variable_types:
thread
void *

variable_types: flag int


MyThreadJoinAll

decompiled_code:
int MyThreadJoinAll()
{
void *v0; // rsi
__int64 v1; // rax
int v2; // edx
int v3; // ecx
int result; // eax
__int64 v5; // rax
const ucontext_t *v6; // rdi

v0 = currThread;
v1 = *((_QWORD *)currThread + 4);
if ( v1 )
{
v2 = *((_DWORD *)currThread + 2) + 1;
do
{
*(_DWORD *)(v1 + 12) = 1;
v1 = *(_QWORD *)(v1 + 40);
v3 = v2++;
}
while ( v1 );
*((_DWORD *)v0 + 2) = v3;
}
*((_DWORD *)v0 + 1) = 1;
getcontext(*((ucontext_t **)v0 + 2));
result = (int)currThread;
if ( *((_DWORD *)currThread + 1) == 1 )
{
v5 = remFromQueue(&readyQueue);
if ( v5 )
{
*(_DWORD *)(v5 + 4) = 0;
v6 = *(const ucontext_t **)(v5 + 16);
currThread = (void *)v5;
result = setcontext(v6);
}
else
{
result = setcontext(mainPrg);
}
}
return result;
}

canonical_decompiled_code:
int func5()
{
void *v0; // rsi
__int64 v1; // rax
int v2; // edx
int v3; // ecx
int result; // eax
__int64 v5; // rax
const ucontext_t *v6; // rdi

v0 = currThread;
v1 = *((_QWORD *)currThread + 4);
if ( v1 )
{
v2 = *((_DWORD *)currThread + 2) + 1;
do
{
*(_DWORD *)(v1 + 12) = 1;
v1 = *(_QWORD *)(v1 + 40);
v3 = v2++;
}
while ( v1 );
*((_DWORD *)v0 + 2) = v3;
}
*((_DWORD *)v0 + 1) = 1;
getcontext(*((ucontext_t **)v0 + 2));
result = (int)currThread;
if ( *((_DWORD *)currThread + 1) == 1 )
{
v5 = remFromQueue(&readyQueue);
if ( v5 )
{
*(_DWORD *)(v5 + 4) = 0;
v6 = *(const ucontext_t **)(v5 + 16);
currThread = (void *)v5;
result = setcontext(v6);
}
else
{
result = setcontext(mainPrg);
}
}
return result;
}

original_code:
void MyThreadJoinAll(void)
{
 Mythread *t = currThread -> childList;
 if(t!=((void *)0))
 {
  do
  {
   currThread->blocked = currThread->blocked+1;
   t -> parentBlocked = 1;
   t = t->sibling;
  }
  while(t!=((void *)0));
 }
 currThread -> yieldFlag = 1;
 getcontext(currThread -> thread);
 if(currThread -> yieldFlag == 1)
 {
  t = (Mythread*) remFromQueue(&readyQueue);
  if(t == ((void *)0))
  {
   setcontext(mainPrg);
   return;
  }
  t -> yieldFlag = 0;
  currThread = t;
  setcontext(t->thread);
 }
}

canonical_original_code:
void MyThreadJoinAll()
{
 struct Mythread_ *t = currThread -> childList;
 if(t!=((void *)0))
 {
  do
  {
   currThread->blocked = currThread->blocked+1;
   t -> parentBlocked = 1;
   t = t->sibling;
  }
  while(t!=((void *)0));
 }
 currThread -> yieldFlag = 1;
 getcontext(currThread -> thread);
 if(currThread -> yieldFlag == 1)
 {
  t = (struct Mythread_ *) remFromQueue(&readyQueue);
  if(t == ((void *)0))
  {
   setcontext(mainPrg);
   return;
  }
  t -> yieldFlag = 0;
  currThread = t;
  setcontext(t->thread);
 }
}


MyThreadExit

decompiled_code:
int MyThreadExit()
{
_QWORD *v0; // rdx
__int64 i; // rax
__int64 v2; // rax
const ucontext_t *v3; // rdi

deleteChild();
v0 = currThread;
for ( i = *((_QWORD *)currThread + 4); i; i = *(_QWORD *)(i + 40) )
*(_QWORD *)(i + 48) = 0LL;
free(*(void **)(v0[2] + 16LL));
free(*((void **)currThread + 2));
free(currThread);
v2 = remFromQueue(&readyQueue);
if ( !v2 )
return setcontext(mainPrg);
*(_DWORD *)(v2 + 4) = 0;
v3 = *(const ucontext_t **)(v2 + 16);
currThread = (void *)v2;
return setcontext(v3);
}

canonical_decompiled_code:
int func6()
{
_QWORD *v0; // rdx
__int64 i; // rax
__int64 v2; // rax
const ucontext_t *v3; // rdi

func3();
v0 = currThread;
for ( i = *((_QWORD *)currThread + 4); i; i = *(_QWORD *)(i + 40) )
*(_QWORD *)(i + 48) = 0LL;
free(*(void **)(v0[2] + 16LL));
free(*((void **)currThread + 2));
free(currThread);
v2 = remFromQueue(&readyQueue);
if ( !v2 )
return setcontext(mainPrg);
*(_DWORD *)(v2 + 4) = 0;
v3 = *(const ucontext_t **)(v2 + 16);
currThread = (void *)v2;
return setcontext(v3);
}

original_code:
void MyThreadExit(void)
{
  Mythread *t;
  deleteChild();
  t = currThread->childList;
  while(t!=((void *)0))
  {
   t->parentptr = ((void *)0);
   t = t -> sibling;
  }
  free(currThread -> thread -> uc_stack.ss_sp);
  free(currThread -> thread);
  free(currThread);
  t = (Mythread*) remFromQueue(&readyQueue);
  if(t == ((void *)0))
  {
   setcontext(mainPrg);
   return;
  }
  t -> yieldFlag = 0;
  currThread = t;
  setcontext(t->thread);
}

canonical_original_code:
void MyThreadExit()
{
  struct Mythread_ *t;
  deleteChild();
  t = currThread->childList;
  while(t!=((void *)0))
  {
   t->parentptr = ((void *)0);
   t = t -> sibling;
  }
  free(currThread -> thread -> uc_stack.ss_sp);
  free(currThread -> thread);
  free(currThread);
  t = (struct Mythread_ *) remFromQueue(&readyQueue);
  if(t == ((void *)0))
  {
   setcontext(mainPrg);
   return;
  }
  t -> yieldFlag = 0;
  currThread = t;
  setcontext(t->thread);
}


MySemaphoreSignal

original_code:
void MySemaphoreSignal(MySemaphore sem)
{
 if(sem != ((void *)0))
 {
  Mysemaphore *semptr = (Mysemaphore*)sem;
  if(semptr -> destroyed == 0)
  {
   semptr -> value++;
   semptr -> in_use--;
   if(semptr -> value > 0)
   {
    if(semptr -> head != ((void *)0))
    {
     Mythread *t;
     MysemNode *sn;
     sn = semptr -> head;
     if(semptr->head->next == ((void *)0)) semptr->head = semptr -> tail = ((void *)0);
     else semptr->head = semptr -> head -> next;
     t = sn -> thread;
     free(sn);
     t -> blocked = t -> blocked -1;
     if(t -> blocked <= 0)
      addToQueue(&readyQueue,t);
    }
   }
  }
 }
}

canonical_original_code:
void MySemaphoreSignal(void *sem)
{
 if(sem != ((void *)0))
 {
  struct Mysemaphore_ *semptr = (Mysemaphore*)sem;
  if(semptr -> destroyed == 0)
  {
   semptr -> value++;
   semptr -> in_use--;
   if(semptr -> value > 0)
   {
    if(semptr -> head != ((void *)0))
    {
     struct Mythread_ *t;
     struct MysemNode_ *sn;
     sn = semptr -> head;
     if(semptr->head->next == ((void *)0)) semptr->head = semptr -> tail = ((void *)0);
     else semptr->head = semptr -> head -> next;
     t = sn -> thread;
     free(sn);
     t -> blocked = t -> blocked -1;
     if(t -> blocked <= 0)
      addToQueue(&readyQueue,t);
    }
   }
  }
 }
}

variable_types:
sem
void *

variable_types: struct Mysemaphore_ { int value; int destroyed; int in_use; struct MysemNode_ { struct Mythread_ { int threadId; int yieldFlag; int blocked; int parentBlocked; struct ucontext_t { unsigned long uc_flags; struct ucontext_t *uc_link; struct stack_t { void *ss_sp; int ss_flags; unsigned long ss_size; } uc_stack; struct mcontext_t { long long gregs[23]; struct _libc_fpstate { unsigned short cwd; unsigned short swd; unsigned short ftw; unsigned short fop; unsigned long rip; unsigned long rdp; unsigned int mxcsr; unsigned int mxcr_mask; struct _libc_fpxreg { unsigned short significand[4]; unsigned short exponent; unsigned short __glibc_reserved1[3]; } _st[8]; struct _libc_xmmreg { unsigned int element[4]; } _xmm[16]; unsigned int __glibc_reserved1[24]; } *fpregs; unsigned long long __reserved1[8]; } uc_mcontext; struct __sigset_t { unsigned long __val[-1]; } uc_sigmask; struct _libc_fpstate __fpregs_mem; unsigned long long __ssp[4]; } *thread; struct Mythread_ *next; struct Mythread_ *childList; struct Mythread_ *sibling; struct Mythread_ *parentptr; } *thread; struct MysemNode_ *next; } *head; } *

user_defined_types: struct Mysemaphore_ { int value; int destroyed; int in_use; struct MysemNode_ *head; }

user_defined_types: struct MysemNode_ { struct Mythread_ *thread; struct MysemNode_ *next; }