decompiled_code:
__int64 __fastcall init_actions(__int64 a1)
{
const char **v1; // rbp
size_t v2; // rax
char *v3; // rbx
void *v4; // rbp
void (__fastcall *v5)(_QWORD, __int64); // rax
char *v7; // rax

v1 = (const char **)actions;
if ( !actions )
return 0LL;
while ( 1 )
{
v2 = strlen(v1[1]);
v3 = (char *)calloc(v2 + 12, 1uLL);
strcpy(v3, "actions/");
strcat(v3, v1[1]);
*(_DWORD *)&v3[strlen(v3)] = 7303982;
v4 = dlopen(v3, 2);
if ( !v4 )
break;
free(v3);
v5 = (void (__fastcall *)(_QWORD, __int64))dlsym(v4, "setup_action");
v5(*(_QWORD *)actions, a1);
v1 = (const char **)*((_QWORD *)actions + 2);
free_ail(actions);
actions = v1;
if ( !v1 )
return 0LL;
}
v7 = dlerror();
printf("error in dlopen(%s)\n%s\n", v3, v7);
free(v3);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
const char **v1; // rbp
size_t v2; // rax
char *v3; // rbx
void *v4; // rbp
void (__fastcall *v5)(_QWORD, __int64); // rax
char *v7; // rax

v1 = (const char **)actions;
if ( !actions )
return 0LL;
while ( 1 )
{
v2 = strlen(v1[1]);
v3 = (char *)calloc(v2 + 12, 1uLL);
strcpy(v3, "actions/");
strcat(v3, v1[1]);
*(_DWORD *)&v3[strlen(v3)] = 7303982;
v4 = dlopen(v3, 2);
if ( !v4 )
break;
free(v3);
v5 = (void (__fastcall *)(_QWORD, __int64))dlsym(v4, "setup_action");
v5(*(_QWORD *)actions, a1);
v1 = (const char **)*((_QWORD *)actions + 2);
func0(actions);
actions = v1;
if ( !v1 )
return 0LL;
}
v7 = dlerror();
printf("error in dlopen(%s)\n%s\n", v3, v7);
free(v3);
return 1LL;
}

original_code:
short init_actions(temp_point *tree) {
 ail *next;
 char *str;
 void *libhandle;
 void *(*fptr)(line_list*, temp_point*);
 while (actions != ((void *)0)) {
  str = calloc(strlen(actions->action)+12, sizeof(char));
  strcpy(str, "actions/");
  strcat(str, actions->action);
  strcat(str, ".so");
  libhandle = dlopen(str, 0x00002);
  if (!libhandle) {
   printf("error in dlopen(%s)\n%s\n", str, dlerror());
   free(str);
   return 1;
  }
  free(str);
  fptr = dlsym(libhandle, "setup_action");
  fptr(actions->ll, tree);
  next = actions->next;
  free_ail(actions);
  actions = next;
 }
 return 0;
}

canonical_original_code:
short init_actions(struct temp_point *tree) {
 struct ail *next;
 char *str;
 void *libhandle;
 void *(*fptr)(struct line_list *, struct temp_point *);
 while (actions != ((void *)0)) {
  str = calloc(strlen(actions->action)+12, sizeof(char));
  strcpy(str, "actions/");
  strcat(str, actions->action);
  strcat(str, ".so");
  libhandle = dlopen(str, 0x00002);
  if (!libhandle) {
   printf("error in dlopen(%s)\n%s\n", str, dlerror());
   free(str);
   return 1;
  }
  free(str);
  fptr = dlsym(libhandle, "setup_action");
  fptr(actions->ll, tree);
  next = actions->next;
  free_ail(actions);
  actions = next;
 }
 return 0;
}

variable_types: struct temp_point { char *pt_id; float mass; float damping; float *position; unsigned int no_springs; struct point { float *x; unsigned short connections; float b; } *fast; struct temp_point *left; } *

user_defined_types: struct line_list { char *str; unsigned int lineno; struct line_list *next; }


repo: foolswood/Physyn

decompiled_code:
void __fastcall get_dimensions(_QWORD **a1)
{
_QWORD *i; // rbp
_QWORD *v2; // r13
const char *v3; // rax
char *v4; // rbx
__int64 v5; // rax
_QWORD *v6; // r13
int v7[11]; // [rsp+Ch] [rbp-2Ch] BYREF

for ( i = *a1; i; i = (_QWORD *)i[2] )
{
v7[0] = 0;
v3 = (const char *)get_word(*i, v7);
v4 = (char *)v3;
if ( v3 )
{
if ( !strcmp(v3, "dimensions")
&& (unsigned int)_isoc99_sscanf(*i + (unsigned int)v7[0], "%i", v7)
&& (unsigned __int16)set_dimensions((unsigned int)v7[0]) )
{
v5 = i[3];
if ( v5 )
{
v6 = (_QWORD *)i[2];
*(_QWORD *)(v5 + 16) = v6;
v6[3] = i[3];
free((void *)*i);
free(i);
i = v6;
}
else
{
v2 = (_QWORD *)i[2];
*a1 = v2;
free((void *)*i);
free(i);
if ( !v2 )
return;
i = v2;
}
}
free(v4);
}
}
}

canonical_decompiled_code:
void __fastcall func0(_QWORD **a1)
{
_QWORD *i; // rbp
_QWORD *v2; // r13
const char *v3; // rax
char *v4; // rbx
__int64 v5; // rax
_QWORD *v6; // r13
int v7[11]; // [rsp+Ch] [rbp-2Ch] BYREF

for ( i = *a1; i; i = (_QWORD *)i[2] )
{
v7[0] = 0;
v3 = (const char *)get_word(*i, v7);
v4 = (char *)v3;
if ( v3 )
{
if ( !strcmp(v3, "dimensions")
&& (unsigned int)_isoc99_sscanf(*i + (unsigned int)v7[0], "%i", v7)
&& (unsigned __int16)set_dimensions((unsigned int)v7[0]) )
{
v5 = i[3];
if ( v5 )
{
v6 = (_QWORD *)i[2];
*(_QWORD *)(v5 + 16) = v6;
v6[3] = i[3];
free((void *)*i);
free(i);
i = v6;
}
else
{
v2 = (_QWORD *)i[2];
*a1 = v2;
free((void *)*i);
free(i);
if ( !v2 )
return;
i = v2;
}
}
free(v4);
}
}
}

original_code:
void get_dimensions(line_list **hd) {
 unsigned int i;
 char *str;
 line_list *nxt, *head = *hd;
 while (head != ((void *)0)) {
  i = 0;
  str = get_word(head->str, &i);
  if (str != ((void *)0)) {
   if (!strcmp(str, "dimensions")) {
    if (sscanf((head->str)+i, "%i", &i)) {
     if (set_dimensions(i)) {
      if (head->prev == ((void *)0)) {
       *hd = nxt = head->next;
      }
      else {
       (head->prev)->next = head->next;
       nxt = head->next;
       (nxt)->prev = head->prev;
      }
      free((char*) head->str);
      free(head);
      head = nxt;
      if (head == ((void *)0))
       break;
     }
    }
   }
   free(str);
  }
  head = head->next;
 }
}

canonical_original_code:
void get_dimensions(struct line_list **hd) {
 unsigned int i;
 char *str;
 struct line_list *nxt; struct line_list *head = *hd;
 while (head != ((void *)0)) {
  i = 0;
  str = get_word(head->str, &i);
  if (str != ((void *)0)) {
   if (!strcmp(str, "dimensions")) {
    if (sscanf((head->str)+i, "%i", &i)) {
     if (set_dimensions(i)) {
      if (head->prev == ((void *)0)) {
       *hd = nxt = head->next;
      }
      else {
       (head->prev)->next = head->next;
       nxt = head->next;
       (nxt)->prev = head->prev;
      }
      free((char *) head->str);
      free(head);
      head = nxt;
      if (head == ((void *)0))
       break;
     }
    }
   }
   free(str);
  }
  head = head->next;
 }
}

variable_types: struct line_list { char *str; unsigned int lineno; struct line_list *next; } **

variable_types:
i
unsigned int

variable_types:
str
char *

return_type: void


decompiled_code:
__int64 __fastcall pts_sp(__int64 a1, _QWORD *a2, __int64 *a3)
{
const unsigned __int16 **v4; // rbx
unsigned int v5; // er15
void *v6; // rbp
char *v7; // r12
__int64 v8; // r13
char *v9; // rbp
void *v10; // r12
__int64 v12; // rbp
__int64 v13; // rdi
char v14; // al
__int64 v15; // rbp
__int64 v16; // r12
__int64 v17[2]; // [rsp+8h] [rbp-60h] BYREF
__int64 v18; // [rsp+18h] [rbp-50h] BYREF
float v19; // [rsp+24h] [rbp-44h] BYREF
float v20; // [rsp+28h] [rbp-40h] BYREF
int v21[15]; // [rsp+2Ch] [rbp-3Ch] BYREF

v17[0] = a1;
v4 = _ctype_b_loc();
v5 = 0;
while ( 1 )
{
if ( ((*v4)[*(char *)(*(_QWORD *)v17[0] + 1LL)] & 0x2000) == 0 )
goto LABEL_23;
v21[0] = 2;
v13 = *(_QWORD *)v17[0];
v14 = **(_BYTE **)v17[0];
if ( v14 == 112 )
{
v9 = (char *)get_word(v13, v21);
if ( !v9 )
{
printf("line %i: point unamed\n", *(unsigned int *)(v17[0] + 8));
return 0;
}
v10 = (void *)read_vector(*(_QWORD *)v17[0], v21);
if ( !v10 )
{
printf("invalid vector declaration for point %s\n", v9);
free(v9);
return 0;
}
if ( (unsigned int)_isoc99_sscanf(*(_QWORD *)v17[0] + (unsigned int)v21[0], "%f %f", &v20, &v19) != 2 )
{
printf("invalid value for mass or damping for point %s\n", v9);
free(v9);
free(v10);
return 0;
}
if ( !(unsigned __int16)add_point(a2, v9, v10, v20, v19) )
{
printf("multiple definitions of point %s\n", v9);
free(v9);
free(v10);
return 0;
}
free(v9);
free(v10);
++v5;
goto LABEL_23;
}
if ( v14 <= 112 )
{
if ( v14 == 97 )
{
v12 = get_word(v13, v21);
v18 = 0LL;
extract_curly_braces(v17, &v18, v21);
register_action(v12, v18);
}
else if ( v14 == 99 )
{
v15 = get_word(v13, v21);
v16 = get_word(*(_QWORD *)v17[0], v21);
v18 = 0LL;
extract_curly_braces(v17, &v18, v21);
register_capture(v15, v16, v18);
}
goto LABEL_23;
}
if ( v14 == 115 )
break;
LABEL_23:
v17[0] = *(_QWORD *)(v17[0] + 16);
if ( !v17[0] )
return v5;
}
v6 = (void *)get_word(v13, v21);
if ( !v6 )
{
puts("spring startpoint undefined");
return 0;
}
v7 = (char *)get_word(*(_QWORD *)v17[0], v21);
if ( !v7 )
{
puts("spring endpoint undefined");
free(v6);
return 0;
}
if ( (unsigned int)_isoc99_sscanf(*(_QWORD *)v17[0] + (unsigned int)v21[0], "%f %f", &v20, &v19) != 2 )
{
printf("invalid value for mass or damping for spring between %s and %s\n", (const char *)v6, v7);
free(v6);
free(v7);
return 0;
}
v8 = add_spring(*a2, *a3, v6, v7, v20, v19);
if ( v8 )
{
free(v6);
free(v7);
*a3 = v8;
goto LABEL_23;
}
printf(
"one or both of the points %s and %s doesn't exist at the point of the spring definition\n",
(const char *)v6,
v7);
free(v6);
free(v7);
return 0;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, _QWORD *a2, __int64 *a3)
{
const unsigned __int16 **v4; // rbx
unsigned int v5; // er15
void *v6; // rbp
char *v7; // r12
__int64 v8; // r13
char *v9; // rbp
void *v10; // r12
__int64 v12; // rbp
__int64 v13; // rdi
char v14; // al
__int64 v15; // rbp
__int64 v16; // r12
__int64 v17[2]; // [rsp+8h] [rbp-60h] BYREF
__int64 v18; // [rsp+18h] [rbp-50h] BYREF
float v19; // [rsp+24h] [rbp-44h] BYREF
float v20; // [rsp+28h] [rbp-40h] BYREF
int v21[15]; // [rsp+2Ch] [rbp-3Ch] BYREF

v17[0] = a1;
v4 = _ctype_b_loc();
v5 = 0;
while ( 1 )
{
if ( ((*v4)[*(char *)(*(_QWORD *)v17[0] + 1LL)] & 0x2000) == 0 )
goto LABEL_23;
v21[0] = 2;
v13 = *(_QWORD *)v17[0];
v14 = **(_BYTE **)v17[0];
if ( v14 == 112 )
{
v9 = (char *)get_word(v13, v21);
if ( !v9 )
{
printf("line %i: point unamed\n", *(unsigned int *)(v17[0] + 8));
return 0;
}
v10 = (void *)read_vector(*(_QWORD *)v17[0], v21);
if ( !v10 )
{
printf("invalid vector declaration for point %s\n", v9);
free(v9);
return 0;
}
if ( (unsigned int)_isoc99_sscanf(*(_QWORD *)v17[0] + (unsigned int)v21[0], "%f %f", &v20, &v19) != 2 )
{
printf("invalid value for mass or damping for point %s\n", v9);
free(v9);
free(v10);
return 0;
}
if ( !(unsigned __int16)add_point(a2, v9, v10, v20, v19) )
{
printf("multiple definitions of point %s\n", v9);
free(v9);
free(v10);
return 0;
}
free(v9);
free(v10);
++v5;
goto LABEL_23;
}
if ( v14 <= 112 )
{
if ( v14 == 97 )
{
v12 = get_word(v13, v21);
v18 = 0LL;
extract_curly_braces(v17, &v18, v21);
register_action(v12, v18);
}
else if ( v14 == 99 )
{
v15 = get_word(v13, v21);
v16 = get_word(*(_QWORD *)v17[0], v21);
v18 = 0LL;
extract_curly_braces(v17, &v18, v21);
register_capture(v15, v16, v18);
}
goto LABEL_23;
}
if ( v14 == 115 )
break;
LABEL_23:
v17[0] = *(_QWORD *)(v17[0] + 16);
if ( !v17[0] )
return v5;
}
v6 = (void *)get_word(v13, v21);
if ( !v6 )
{
puts("spring startpoint undefined");
return 0;
}
v7 = (char *)get_word(*(_QWORD *)v17[0], v21);
if ( !v7 )
{
puts("spring endpoint undefined");
free(v6);
return 0;
}
if ( (unsigned int)_isoc99_sscanf(*(_QWORD *)v17[0] + (unsigned int)v21[0], "%f %f", &v20, &v19) != 2 )
{
printf("invalid value for mass or damping for spring between %s and %s\n", (const char *)v6, v7);
free(v6);
free(v7);
return 0;
}
v8 = add_spring(*a2, *a3, v6, v7, v20, v19);
if ( v8 )
{
free(v6);
free(v7);
*a3 = v8;
goto LABEL_23;
}
printf(
"one or both of the points %s and %s doesn't exist at the point of the spring definition\n",
(const char *)v6,
v7);
free(v6);
free(v7);
return 0;
}

original_code:
unsigned int pts_sp(line_list *head, temp_point **tree, temp_spring **sp) {
 unsigned int i, no_nodes;
 char *str, *str2;
 vector v;
 temp_spring *next_spring;
 float mass, damping;
 line_list *device_parameters;
 no_nodes = 0;
 do {
  if (((*__ctype_b_loc ())[(int) ((head->str[1]))] & (unsigned short int) _ISspace)) {
   i = 2;
   switch (head->str[0]) {
    case 'p':
     str = get_word(head->str, &i);
     if (str == ((void *)0)) {
      printf("line %i: point unamed\n", head->lineno);
      return 0;
     }
     v = read_vector(head->str, &i);
     if (v == ((void *)0)) {
      printf("invalid vector declaration for point %s\n", str);
      free(str);
      return 0;
     }
     if (sscanf((head->str)+i, "%f %f", &mass, &damping) != 2) {
      printf("invalid value for mass or damping for point %s\n", str);
      free(str);
      free(v);
      return 0;
     }
     if (!add_point(tree, str, mass, damping, v)) {
      printf("multiple definitions of point %s\n", str);
      free(str);
      free(v);
      return 0;
     }
     free(str);
     free(v);
     no_nodes++;
     break;
    case 's':
     str = get_word(head->str, &i);
     if (str == ((void *)0)) {
      printf("spring startpoint undefined\n");
      free(str);
      return 0;
     }
     str2 = get_word(head->str, &i);
     if (str2 == ((void *)0)) {
      printf("spring endpoint undefined\n");
      free(str);
      free(str2);
      return 0;
     }
     if (sscanf((head->str)+i, "%f %f", &mass, &damping) != 2) {
      printf("invalid value for mass or damping for spring between %s and %s\n", str, str2);
      free(str);
      free(str2);
      return 0;
     }
     next_spring = add_spring(*tree, *sp, str, str2, mass, damping);
     if (next_spring == ((void *)0)) {
      printf("one or both of the points %s and %s doesn't exist at the point of the spring definition\n", str, str2);
      free(str);
      free(str2);
      return 0;
     }
     free(str);
     free(str2);
     *sp = next_spring;
     break;
    case 'c':
     str = get_word(head->str, &i);
     str2 = get_word(head->str, &i);
     device_parameters = ((void *)0);
     extract_curly_braces(&head, &device_parameters, &i);
     register_capture(str, str2, device_parameters);
     break;
    case 'a':
     str = get_word(head->str, &i);
     device_parameters = ((void *)0);
     extract_curly_braces(&head, &device_parameters, &i);
     register_action(str, device_parameters);
   }
  }
  head = head->next;
 } while (head != ((void *)0));
 return no_nodes;
}

canonical_original_code:
unsigned int pts_sp(struct line_list *head, struct temp_point **tree, struct temp_spring **sp) {
 unsigned int i; unsigned int no_nodes;
 char *str; char *str2;
 float *v;
 struct temp_spring *next_spring;
 float mass; float damping;
 struct line_list *device_parameters;
 no_nodes = 0;
 do {
  if (((*__ctype_b_loc ())[(int) ((head->str[1]))] & (unsigned short) _ISspace)) {
   i = 2;
   switch (head->str[0]) {
    case 'p':
     str = get_word(head->str, &i);
     if (str == ((void *)0)) {
      printf("line %i: point unamed\n", head->lineno);
      return 0;
     }
     v = read_vector(head->str, &i);
     if (v == ((void *)0)) {
      printf("invalid vector declaration for point %s\n", str);
      free(str);
      return 0;
     }
     if (sscanf((head->str)+i, "%f %f", &mass, &damping) != 2) {
      printf("invalid value for mass or damping for point %s\n", str);
      free(str);
      free(v);
      return 0;
     }
     if (!add_point(tree, str, mass, damping, v)) {
      printf("multiple definitions of point %s\n", str);
      free(str);
      free(v);
      return 0;
     }
     free(str);
     free(v);
     no_nodes++;
     break;
    case 's':
     str = get_word(head->str, &i);
     if (str == ((void *)0)) {
      printf("spring startpoint undefined\n");
      free(str);
      return 0;
     }
     str2 = get_word(head->str, &i);
     if (str2 == ((void *)0)) {
      printf("spring endpoint undefined\n");
      free(str);
      free(str2);
      return 0;
     }
     if (sscanf((head->str)+i, "%f %f", &mass, &damping) != 2) {
      printf("invalid value for mass or damping for spring between %s and %s\n", str, str2);
      free(str);
      free(str2);
      return 0;
     }
     next_spring = add_spring(*tree, *sp, str, str2, mass, damping);
     if (next_spring == ((void *)0)) {
      printf("one or both of the points %s and %s doesn't exist at the point of the spring definition\n", str, str2);
      free(str);
      free(str2);
      return 0;
     }
     free(str);
     free(str2);
     *sp = next_spring;
     break;
    case 'c':
     str = get_word(head->str, &i);
     str2 = get_word(head->str, &i);
     device_parameters = ((void *)0);
     extract_curly_braces(&head, &device_parameters, &i);
     register_capture(str, str2, device_parameters);
     break;
    case 'a':
     str = get_word(head->str, &i);
     device_parameters = ((void *)0);
     extract_curly_braces(&head, &device_parameters, &i);
     register_action(str, device_parameters);
   }
  }
  head = head->next;
 } while (head != ((void *)0));
 return no_nodes;
}

variable_types: struct line_list { char *str; unsigned int lineno; struct line_list *next; } *

variable_types: struct temp_point { char *pt_id; float mass; float damping; float *position; unsigned int no_springs; struct point { float *x; unsigned short connections; float b; } *fast; struct temp_point *left; } **

variable_types: struct temp_spring { struct temp_point *a; unsigned int connection_no_a; struct temp_point *b; unsigned int connection_no_b; float restlength; float k; struct temp_spring *next; } **

variable_types:
v
float *

variable_types: struct temp_spring { struct temp_point { char *pt_id; float mass; float damping; float *position; unsigned int no_springs; struct point { float *x; unsigned short connections; float b; } *fast; struct temp_point *left; } *a; unsigned int connection_no_a; struct temp_point *b; unsigned int connection_no_b; float restlength; float k; struct temp_spring *next; } *

variable_types: mass float

variable_types: damping float

return_type: unsigned int

user_defined_types: struct temp_point { char *pt_id; float mass; float damping; float *position; unsigned int no_springs; struct point *fast; struct temp_point *left; }


decompiled_code:
__int64 get_out()
{
return Vdot();
}

canonical_decompiled_code:
__int64 func6()
{
return Vdot();
}

original_code:
float get_out(void* ptr) {
 mic const *m = ptr;
 return Vdot(m->pv, m->dv);
}

canonical_original_code:
float get_out(void *ptr) {
 struct mic *m = ptr;
 return Vdot(m->pv, m->dv);
}

variable_types:
ptr
void *

variable_types:
m
struct mic { float *pv; float *dv; } *

return_type: float


decompiled_code:
void __fastcall free_data(void *ptr)
{
free(*((void **)ptr + 1));
free(ptr);
}

canonical_decompiled_code:
void __fastcall func7(void *ptr)
{
free(*((void **)ptr + 1));
free(ptr);
}

original_code:
void free_data(void* ptr) {
 mic *m = ptr;
 free(m->dv);
 free(m);
}

canonical_original_code:
void free_data(void *ptr) {
 struct mic *m = ptr;
 free(m->dv);
 free(m);
}


decompiled_code:
void __fastcall do_actions(int a1)
{
unsigned __int16 (__fastcall **v1)(_QWORD); // rbx
unsigned __int16 (__fastcall **v2)(_QWORD); // rbp
__int64 v3; // r12
unsigned __int16 (__fastcall *v4)(_QWORD); // rax
_QWORD *v5; // rdi
unsigned __int16 (__fastcall *v6)(_QWORD); // rax

v1 = (unsigned __int16 (__fastcall **)(_QWORD))acting[a1];
if ( v1 )
{
v2 = 0LL;
v3 = a1;
do
{
if ( (*v1)(v1[1]) )
{
if ( v2 )
{
v2[3] = v1[3];
v6 = v1[2];
if ( v6 )
v6(v1[1]);
free(v1);
v1 = (unsigned __int16 (__fastcall **)(_QWORD))v2[3];
}
else
{
v4 = v1[2];
if ( v4 )
v4(v1[1]);
v5 = (_QWORD *)acting[v3];
v1 = (unsigned __int16 (__fastcall **)(_QWORD))v5[3];
free(v5);
acting[v3] = (__int64)v1;
}
}
else
{
v2 = v1;
v1 = (unsigned __int16 (__fastcall **)(_QWORD))v1[3];
}
}
while ( v1 );
}
}

canonical_decompiled_code:
void __fastcall func0(int a1)
{
unsigned __int16 (__fastcall **v1)(_QWORD); // rbx
unsigned __int16 (__fastcall **v2)(_QWORD); // rbp
__int64 v3; // r12
unsigned __int16 (__fastcall *v4)(_QWORD); // rax
_QWORD *v5; // rdi
unsigned __int16 (__fastcall *v6)(_QWORD); // rax

v1 = (unsigned __int16 (__fastcall **)(_QWORD))acting[a1];
if ( v1 )
{
v2 = 0LL;
v3 = a1;
do
{
if ( (*v1)(v1[1]) )
{
if ( v2 )
{
v2[3] = v1[3];
v6 = v1[2];
if ( v6 )
v6(v1[1]);
free(v1);
v1 = (unsigned __int16 (__fastcall **)(_QWORD))v2[3];
}
else
{
v4 = v1[2];
if ( v4 )
v4(v1[1]);
v5 = (_QWORD *)acting[v3];
v1 = (unsigned __int16 (__fastcall **)(_QWORD))v5[3];
free(v5);
acting[v3] = (__int64)v1;
}
}
else
{
v2 = v1;
v1 = (unsigned __int16 (__fastcall **)(_QWORD))v1[3];
}
}
while ( v1 );
}
}

original_code:
void do_actions(int when) {
 actionlist *active, *prev;
 active = acting[when];
 prev = ((void *)0);
 unsigned short rval;
 while (active != ((void *)0)) {
  rval = (active->act)((void*) active->data);
  if (rval) {
   if (prev == ((void *)0)) {
    if (active->free_data != ((void *)0))
     (active->free_data)((void*) active->data);
    active = (acting[when])->next;
    free(acting[when]);
    acting[when] = active;
   } else {
    prev->next = active->next;
    if (active->free_data != ((void *)0))
     (active->free_data)((void*) active->data);
    free(active);
    active = prev->next;
   }
  } else {
   prev = active;
   active = active->next;
  }
 }
}

canonical_original_code:
void do_actions(int when) {
 struct actionlist *active; struct actionlist *prev;
 active = acting[when];
 prev = ((void *)0);
 unsigned short rval;
 while (active != ((void *)0)) {
  rval = (active->act)((void *) active->data);
  if (rval) {
   if (prev == ((void *)0)) {
    if (active->free_data != ((void *)0))
     (active->free_data)((void *) active->data);
    active = (acting[when])->next;
    free(acting[when]);
    acting[when] = active;
   } else {
    prev->next = active->next;
    if (active->free_data != ((void *)0))
     (active->free_data)((void *) active->data);
    free(active);
    active = prev->next;
   }
  } else {
   prev = active;
   active = active->next;
  }
 }
}

variable_types: when int

variable_types: struct actionlist { unsigned short (*act)(void *); void *data; void (*free_data)(void *); struct actionlist *next; } *

variable_types:
rval
unsigned short


decompiled_code:
__int64 __fastcall note_id(_BYTE *a1)
{
int v1; // ebx
char v2; // al
unsigned __int16 v3; // ax

switch ( *a1 )
{
case 'A':
v1 = 9;
break;
case 'B':
v1 = 11;
break;
case 'C':
v1 = 0;
break;
case 'D':
v1 = 2;
break;
case 'E':
v1 = 4;
break;
case 'F':
v1 = 5;
break;
case 'G':
v1 = 7;
break;
default:
v1 = 9;
break;
}
v2 = a1[1];
if ( v2 == 35 )
{
++v1;
v3 = 2;
}
else if ( v2 == 98 )
{
--v1;
v3 = 2;
}
else
{
v3 = 1;
}
return (unsigned int)(v1 + 12 * atoi(&a1[v3]));
}

canonical_decompiled_code:
__int64 __fastcall func0(_BYTE *a1)
{
int v1; // ebx
char v2; // al
unsigned __int16 v3; // ax

switch ( *a1 )
{
case 'A':
v1 = 9;
break;
case 'B':
v1 = 11;
break;
case 'C':
v1 = 0;
break;
case 'D':
v1 = 2;
break;
case 'E':
v1 = 4;
break;
case 'F':
v1 = 5;
break;
case 'G':
v1 = 7;
break;
default:
v1 = 9;
break;
}
v2 = a1[1];
if ( v2 == 35 )
{
++v1;
v3 = 2;
}
else if ( v2 == 98 )
{
--v1;
v3 = 2;
}
else
{
v3 = 1;
}
return (unsigned int)(v1 + 12 * atoi(&a1[v3]));
}

original_code:
unsigned short note_id(char *note_id) {
 unsigned short id, octave, offset;
 switch (*note_id) {
  case 'C':
   id = 0;
   break;
  case 'D':
   id = 2;
   break;
  case 'E':
   id = 4;
   break;
  case 'F':
   id = 5;
   break;
  case 'G':
   id = 7;
   break;
  case 'A':
   id = 9;
   break;
  case 'B':
   id = 11;
   break;
  default:
   id = 9;
   break;
 }
 switch (*(note_id+sizeof(char))) {
  case '#':
   id++;
   offset = 2;
   break;
  case 'b':
   id--;
   offset = 2;
   break;
  default:
   offset = 1;
   break;
 }
 octave = atoi(note_id + (offset*sizeof(char)));
 return id + (12*octave);
}

canonical_original_code:
unsigned short note_id(char *note_id) {
 unsigned short id; unsigned short octave; unsigned short offset;
 switch (*note_id) {
  case 'C':
   id = 0;
   break;
  case 'D':
   id = 2;
   break;
  case 'E':
   id = 4;
   break;
  case 'F':
   id = 5;
   break;
  case 'G':
   id = 7;
   break;
  case 'A':
   id = 9;
   break;
  case 'B':
   id = 11;
   break;
  default:
   id = 9;
   break;
 }
 switch (*(note_id+sizeof(char))) {
  case '#':
   id++;
   offset = 2;
   break;
  case 'b':
   id--;
   offset = 2;
   break;
  default:
   offset = 1;
   break;
 }
 octave = atoi(note_id + (offset*sizeof(char)));
 return id + (12*octave);
}

variable_types:
id
unsigned short

variable_types:
octave
unsigned short

variable_types:
offset
unsigned short

return_type: unsigned short


llfree

decompiled_code:
void __fastcall llfree(void *ptr)
{
void **v1; // rbx
void **v2; // rbp

v1 = (void **)ptr;
if ( ptr )
{
do
{
v2 = v1;
v1 = (void **)v1[2];
free(*v2);
free(v2);
}
while ( v1 );
}
}

canonical_decompiled_code:
void __fastcall func0(void *ptr)
{
void **v1; // rbx
void **v2; // rbp

v1 = (void **)ptr;
if ( ptr )
{
do
{
v2 = v1;
v1 = (void **)v1[2];
free(*v2);
free(v2);
}
while ( v1 );
}
}

original_code:
void llfree(line_list *head) {
 line_list *next;
 while (head != ((void *)0)) {
  next = head->next;
  free((char*) head->str);
  free(head);
  head = next;
 }
}

canonical_original_code:
void llfree(struct line_list *head) {
 struct line_list *next;
 while (head != ((void *)0)) {
  next = head->next;
  free((char *) head->str);
  free(head);
  head = next;
 }
}


decompiled_code:
__int64 __fastcall midi_handler(__int64 a1, __int64 a2)
{
unsigned __int16 v2; // bx
__int64 result; // rax

if ( !n_handlers )
return 0LL;
v2 = 0;
while ( 1 )
{
result = (*((__int64 (__fastcall **)(__int64, __int64, _QWORD))handlers + v2))(
a1,
a2,
*((_QWORD *)handler_data + v2));
if ( (_WORD)result )
break;
if ( (unsigned __int16)n_handlers <= ++v2 )
return result;
}
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int64 a2)
{
unsigned __int16 v2; // bx
__int64 result; // rax

if ( !n_handlers )
return 0LL;
v2 = 0;
while ( 1 )
{
result = (*((__int64 (__fastcall **)(__int64, __int64, _QWORD))handlers + v2))(
a1,
a2,
*((_QWORD *)handler_data + v2));
if ( (_WORD)result )
break;
if ( (unsigned __int16)n_handlers <= ++v2 )
return result;
}
return 1LL;
}

original_code:
static short midi_handler(unsigned char *event, size_t size) {
 unsigned short n;
 for (n=0; n<n_handlers; n++)
  if ( (*(handlers[n]))(event, size, handler_data[n]) != 0)
   return 1;
 return 0;
}

canonical_original_code:
static short midi_handler(unsigned char *event, unsigned long size) {
 unsigned short n;
 for (n=0; n<n_handlers; n++)
  if ( (*(handlers[n]))(event, size, handler_data[n]) != 0)
   return 1;
 return 0;
}

variable_types:
event
unsigned char *

variable_types:
size
unsigned long

variable_types:
n
unsigned short

return_type: short


main

canonical_name: main

repo: forero/CLARA-monoproc

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
ThisProc = 0;
SizeProc = 1;
mts_seed32(&RND_MT_State, All[1339], envp);
ReadParameters(argv[1]);
if ( All[1305] || *(_OWORD *)&All[1306] != 0LL )
TestAll();
if ( All[1303] | All[1304] | All[1302] | All[1301] )
PropagateAll();
return 0;
}

original_code:
int main(int argc, char **argv)
{
  ThisProc = 0;
  SizeProc = 1;
  mts_seed32(&(RND_MT_State), All.RandomSeed + ThisProc);
  ReadParameters(argv[1]);
  if(All.TestParallelVel || All.TestParallelVelFast || All.TestFirstScatter ||
      All.TestRND || All.TestPerpVel){
      TestAll();
  }
  if(All.NeufeldSlab || All.NeufeldCube || All.ExpandingSphere || All.SimulationCube){
      PropagateAll();
  }
  return 0;
}

variable_types: argc int

variable_types:
argv
char **

return_type: int


LyaTau

original_code:
double LyaTau(void)
{
    double tau;
    double tmp;
    tmp = RandFloatUnit();
    tau = -log(tmp);
    return tau;
}

canonical_original_code:
double LyaTau()
{
    double tau;
    double tmp;
    tmp = RandFloatUnit();
    tau = -log(tmp);
    return tau;
}

variable_types: tau double

variable_types: tmp double

return_type: double


LyaH

variable_types: x double

variable_types: a double

variable_types: z double

variable_types: P double

variable_types: q double

variable_types: H double


LyaCrossSection

original_code:
double LyaCrossSection(double x, double a){
    double sigma;
    double nu_doppler;
    nu_doppler = 9.936E7/(2.0*a);
    sigma = 0.4162*sqrt(3.14159265)*(4.8032E-10*4.8032E-10)/(9.109382616E-28*2.9979e+10*nu_doppler);
    sigma = sigma*LyaH(x,a);
    return sigma;
}

variable_types: sigma double


original_code:
void cross_product(double *vec_1, double *vec_2, double *result){
    result[0] = vec_1[1]*vec_2[2] - vec_1[2]*vec_2[1];
    result[1] = vec_1[2]*vec_2[0] - vec_1[0]*vec_2[2];
    result[2] = vec_1[0]*vec_2[1] - vec_1[1]*vec_2[0];
}

variable_types:
result
double *


normalize

decompiled_code:
void __fastcall normalize(double *a1)
{
double v1; // xmm0_8
double v2; // xmm0_8

v1 = COERCE_DOUBLE(point_product((__int64)a1, (__int64)a1));
if ( v1 < 0.0 )
v2 = sqrt(v1);
else
v2 = sqrt(v1);
*a1 = *a1 / v2;
a1[1] = a1[1] / v2;
a1[2] = a1[2] / v2;
}

canonical_decompiled_code:
void __fastcall func1(double *a1)
{
double v1; // xmm0_8
double v2; // xmm0_8

v1 = COERCE_DOUBLE(point_product((__int64)a1, (__int64)a1));
if ( v1 < 0.0 )
v2 = sqrt(v1);
else
v2 = sqrt(v1);
*a1 = *a1 / v2;
a1[1] = a1[1] / v2;
a1[2] = a1[2] / v2;
}

original_code:
void normalize(double *vec){
    double norm;
    int i;
    norm = 0.0;
    norm = point_product(vec, vec);
    norm = sqrt(norm);
    for(i=0;i<3;i++){
        vec[i] = vec[i]/norm;
    }
}

variable_types:
vec
double *

variable_types: norm double

variable_types: i int


repo: forgotenn/bash

decompiled_code:
_BOOL8 __fastcall good_char(char a1)
{
return (unsigned __int8)(a1 - 32) <= 0x5Eu;
}

canonical_decompiled_code:
_BOOL8 __fastcall func7(char a1)
{
return (unsigned __int8)(a1 - 32) <= 0x5Eu;
}

original_code:
int good_char(char c)
{
    return (c >= 32 && c != 127);
}

variable_types: c char


equal

decompiled_code:
__int64 __fastcall equal(__int64 a1)
{
__int64 v1; // rax

if ( change_len <= 0 )
return 1LL;
v1 = 0LL;
while ( *(_BYTE *)(a1 + v1) == *(_BYTE *)(change + v1) )
{
if ( ++v1 == change_len )
return 1LL;
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1)
{
__int64 v1; // rax

if ( change_len <= 0 )
return 1LL;
v1 = 0LL;
while ( *(_BYTE *)(a1 + v1) == *(_BYTE *)(change + v1) )
{
if ( ++v1 == change_len )
return 1LL;
}
return 0LL;
}

original_code:
int equal(char* s)
{
    int i;
    for (i = 0; i < change_len; i++)
        if (s[i] != change[i])
            return 0;
    return 1;
}

canonical_original_code:
int equal(char *s)
{
    int i;
    for (i = 0; i < change_len; i++)
        if (s[i] != change[i])
            return 0;
    return 1;
}

variable_types:
s
char *


modify

decompiled_code:
__int64 __fastcall modify(__int64 a1, unsigned int a2)
{
unsigned int v2; // ebp
__int64 v3; // rbx

v2 = a2;
if ( (int)(a2 - change_len) > 0 )
{
v3 = 0LL;
do
{
if ( (unsigned int)equal(v3 + a1) )
{
*(_BYTE *)(a1 + v3) = 10;
memmove((void *)(a1 + 1 + v3), (const void *)(a1 + v3 + change_len), (int)(v2 - v3 - change_len));
v2 = v2 - change_len + 1;
}
++v3;
}
while ( (int)(v2 - change_len) > (int)v3 );
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1, unsigned int a2)
{
unsigned int v2; // ebp
__int64 v3; // rbx

v2 = a2;
if ( (int)(a2 - change_len) > 0 )
{
v3 = 0LL;
do
{
if ( (unsigned int)func8(v3 + a1) )
{
*(_BYTE *)(a1 + v3) = 10;
memmove((void *)(a1 + 1 + v3), (const void *)(a1 + v3 + change_len), (int)(v2 - v3 - change_len));
v2 = v2 - change_len + 1;
}
++v3;
}
while ( (int)(v2 - change_len) > (int)v3 );
}
return v2;
}

original_code:
int modify(char* s, int len)
{
    int i;
    for (i = 0; i < len - change_len; i++)
    {
        if (equal(s + i))
        {
            s[i] = '\n';
            memmove(s + i + 1, s + change_len + i, len - i - change_len);
            len -= (change_len - 1);
        }
    }
    return len;
}

canonical_original_code:
int modify(char *s, int len)
{
    int i;
    for (i = 0; i < len - change_len; i++)
    {
        if (equal(s + i))
        {
            s[i] = '\n';
            memmove(s + i + 1, s + change_len + i, len - i - change_len);
            len -= (change_len - 1);
        }
    }
    return len;
}

variable_types: len int


main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
int v3; // eax
int v4; // ebp
__int64 v5; // rbx
int v6; // er12
char v7; // r12
int v8; // eax
int v9; // ebx

change = (__int64)argv[1];
change_len = strlen((const char *)change);
buf = malloc(0x64uLL);
good = malloc(0x64uLL);
buf_size = 0;
good_size = 0;
while ( 1 )
{
v3 = read(0, (char *)buf + buf_size, 100 - buf_size);
if ( v3 > 0 )
buf_size += v3;
if ( buf_size > 0 )
{
v4 = good_size;
if ( good_size > 99 )
{
v6 = 0;
}
else
{
v5 = 0LL;
do
{
v7 = *((_BYTE *)buf + v5);
if ( good_char(v7) )
{
*((_BYTE *)good + v4) = v7;
++good_size;
}
v6 = v5 + 1;
v4 = good_size;
if ( good_size > 99 )
break;
++v5;
}
while ( buf_size > (int)v5 );
}
memmove(buf, (char *)buf + v6, buf_size - v6);
buf_size -= v6;
}
if ( good_size >= change_len )
good_size = modify((__int64)good, good_size);
if ( good_size > change_len )
{
v8 = write(1, good, good_size - change_len);
v9 = v8;
if ( v8 > 0 )
{
memmove(good, (char *)good + v8, good_size - v8);
good_size -= v9;
}
}
}
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
int v3; // eax
int v4; // ebp
__int64 v5; // rbx
int v6; // er12
char v7; // r12
int v8; // eax
int v9; // ebx

change = (__int64)argv[1];
change_len = strlen((const char *)change);
buf = malloc(0x64uLL);
good = malloc(0x64uLL);
buf_size = 0;
good_size = 0;
while ( 1 )
{
v3 = read(0, (char *)buf + buf_size, 100 - buf_size);
if ( v3 > 0 )
buf_size += v3;
if ( buf_size > 0 )
{
v4 = good_size;
if ( good_size > 99 )
{
v6 = 0;
}
else
{
v5 = 0LL;
do
{
v7 = *((_BYTE *)buf + v5);
if ( func7(v7) )
{
*((_BYTE *)good + v4) = v7;
++good_size;
}
v6 = v5 + 1;
v4 = good_size;
if ( good_size > 99 )
break;
++v5;
}
while ( buf_size > (int)v5 );
}
memmove(buf, (char *)buf + v6, buf_size - v6);
buf_size -= v6;
}
if ( good_size >= change_len )
good_size = func9((__int64)good, good_size);
if ( good_size > change_len )
{
v8 = write(1, good, good_size - change_len);
v9 = v8;
if ( v8 > 0 )
{
memmove(good, (char *)good + v8, good_size - v8);
good_size -= v9;
}
}
}
}

original_code:
int main(int argc, char** argv)
{
    change = argv[1];
    change_len = strlen(change);
    buf = malloc(BUFSIZE);
    good = malloc(BUFSIZE);
    buf_size = 0;
    good_size = 0;
    while(1)
    {
        int tmp = read(0, buf + buf_size, BUFSIZE - buf_size);
        if (tmp > 0)
            buf_size += tmp;
        if (buf_size > 0)
        {
            int i = 0;
            while (good_size < BUFSIZE && i < buf_size)
            {
                if (good_char(buf[i]))
                {
                    good[good_size] = buf[i];
                    good_size++;
                }
                i++;
            }
            memmove(buf, buf + i, buf_size - i);
            buf_size -= i;
        }
        if (good_size >= change_len)
            good_size = modify(good, good_size);
        if (good_size > change_len)
        {
            tmp = write(1, good, good_size - change_len);
            if (tmp > 0)
            {
                memmove(good, good + tmp, good_size - tmp);
                good_size -= tmp;
            }
        }
    }
    return 0;
}

canonical_original_code:
int main(int argc, char **argv)
{
    change = argv[1];
    change_len = strlen(change);
    buf = malloc(BUFSIZE);
    good = malloc(BUFSIZE);
    buf_size = 0;
    good_size = 0;
    while(1)
    {
        int tmp = read(0, buf + buf_size, BUFSIZE - buf_size);
        if (tmp > 0)
            buf_size += tmp;
        if (buf_size > 0)
        {
            int i = 0;
            while (good_size < BUFSIZE && i < buf_size)
            {
                if (good_char(buf[i]))
                {
                    good[good_size] = buf[i];
                    good_size++;
                }
                i++;
            }
            memmove(buf, buf + i, buf_size - i);
            buf_size -= i;
        }
        if (good_size >= change_len)
            good_size = modify(good, good_size);
        if (good_size > change_len)
        {
            tmp = write(1, good, good_size - change_len);
            if (tmp > 0)
            {
                memmove(good, good + tmp, good_size - tmp);
                good_size -= tmp;
            }
        }
    }
    return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types: tmp int


openlog

decompiled_code:
__int16 __fastcall openlog(char *cp, __int16 a2)
{
__int16 result; // ax

puts("123");
sockfd = socket(2, 2, 0);
servaddr = 2;
*((_DWORD *)&servaddr + 1) = inet_addr(cp);
result = _bswap_16(a2);
*((_WORD *)&servaddr + 1) = result;
return result;
}

canonical_decompiled_code:
__int16 __fastcall func7(char *cp, __int16 a2)
{
__int16 result; // ax

puts("123");
sockfd = socket(2, 2, 0);
servaddr = 2;
*((_DWORD *)&servaddr + 1) = inet_addr(cp);
result = func6(a2);
*((_WORD *)&servaddr + 1) = result;
return result;
}

original_code:
void openlog(const char* ident, int option, int facility)
{
    printf("123\n");
    sockfd=socket(2,SOCK_DGRAM,0);
    servaddr.sin_family = 2;
    servaddr.sin_addr.s_addr=inet_addr(ident);
    servaddr.sin_port=htons(option);
}

canonical_original_code:
void openlog(char *ident, int option, int facility)
{
    printf("123\n");
    sockfd=socket(2,SOCK_DGRAM,0);
    servaddr.sin_family = 2;
    servaddr.sin_addr.s_addr=inet_addr(ident);
    servaddr.sin_port=htons(option);
}

variable_types:
ident
char *

variable_types: option int

variable_types: facility int


syslog

decompiled_code:
ssize_t syslog(__int64 a1, const char *a2, ...)
{
int v2; // eax
gcc_va_list arg; // [rsp+8h] [rbp-27F0h] BYREF
char s[10000]; // [rsp+20h] [rbp-27D8h] BYREF

va_start(arg, a2);
puts("123");
v2 = vsprintf(s, a2, arg);
return sendto(sockfd, s, v2, 0, &servaddr, 0x10u);
}

canonical_decompiled_code:
ssize_t func8(__int64 a1, const char *a2, ...)
{
int v2; // eax
gcc_va_list arg; // [rsp+8h] [rbp-27F0h] BYREF
char s[10000]; // [rsp+20h] [rbp-27D8h] BYREF

va_start(arg, a2);
puts("123");
v2 = vsprintf(s, a2, arg);
return sendto(sockfd, s, v2, 0, &servaddr, 0x10u);
}

original_code:
void syslog(int priority, const char *format, ...)
{
    printf("123\n");
    char sendline[10000];
    va_list vl;
    __builtin_va_start(vl,format);
    int len = vsprintf(sendline, format, vl);
    __builtin_va_end(vl);
    sendto(sockfd,sendline, len, 0,
            (struct sockaddr *)&servaddr,sizeof(servaddr));
}

canonical_original_code:
void syslog(int priority, char *format, ...)
{
    printf("123\n");
    char sendline[10000];
    __builtin_va_list vl;
    __builtin_va_start(vl,format);
    int len = vsprintf(sendline, format, vl);
    __builtin_va_end(vl);
    sendto(sockfd,sendline, len, 0,
            (struct sockaddr *)&servaddr,sizeof(servaddr));
}

variable_types: priority int

variable_types:
format
char *

variable_types:
sendline
char [10000]

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


closelog

decompiled_code:
int closelog()
{
return close(sockfd);
}

canonical_decompiled_code:
int func9()
{
return close(sockfd);
}

original_code:
void closelog(void)
{
    close(sockfd);
}

canonical_original_code:
void closelog()
{
    close(sockfd);
}


tokenizer

repo: formica-multiuso/freecopter-control

decompiled_code:
__int64 __fastcall tokenizer(char *a1)
{
unsigned int v1; // ebx
int v2; // ebp
char *v4; // rax
char delim[2]; // [rsp+Eh] [rbp-1Ah] BYREF

strcpy(delim, ":");
v1 = 0;
v2 = 0;
if ( strtok(a1, delim) )
{
while ( 1 )
{
v4 = strtok(0LL, delim);
if ( !v4 )
break;
if ( v1 <= 0xC )
imu_data[v2++] = atoi(v4);
++v1;
}
}
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func7(char *a1)
{
unsigned int v1; // ebx
int v2; // ebp
char *v4; // rax
char delim[2]; // [rsp+Eh] [rbp-1Ah] BYREF

strcpy(delim, ":");
v1 = 0;
v2 = 0;
if ( strtok(a1, delim) )
{
while ( 1 )
{
v4 = strtok(0LL, delim);
if ( !v4 )
break;
if ( v1 <= 0xC )
imu_data[v2++] = atoi(v4);
++v1;
}
}
return 1LL;
}

original_code:
int tokenizer(char *s)
{
 char dels[] = ":";
 int i=0;
        int j=0;
 char *p;
 for(p=strtok(s,dels); p!=((void *)0); p=strtok(((void *)0),dels))
 {
  if(j>0 && j<14)
   imu_data[i++] = atoi(p);
  j++;
 }
 return 1;
}

canonical_original_code:
int tokenizer(char *s)
{
 char dels[] = ":";
 int i = 0;
        int j = 0;
 char *p;
 for(p=strtok(s,dels); p!=((void *)0); p=strtok(((void *)0),dels))
 {
  if(j>0 && j<14)
   imu_data[i++] = atoi(p);
  j++;
 }
 return 1;
}

variable_types:
dels
char []

variable_types: j int

variable_types:
p
char *


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // ebx
int v4; // er12
int v5; // ebp
char v7[95]; // [rsp+0h] [rbp-78h] BYREF
char buf[25]; // [rsp+5Fh] [rbp-19h] BYREF

if ( argc > 1 )
{
v3 = open(argv[1], 1052928, envp);
if ( v3 == -1 )
perror("open_port: Unable to open the file descriptor");
v4 = 0;
v5 = 0;
while ( 1 )
{
while ( 1 )
{
if ( !read(v3, buf, 1uLL) )
return 0;
if ( !v5 )
break;
if ( buf[0] != 69 )
goto LABEL_8;
v7[86] = 0;
tokenizer(v7);
printf(
"Roll:%10f,Pitch:%10f,Yaw:%10f\n",
COERCE_FLOAT((dword_404088 << 11) | dword_40408C | (dword_404084 << 23) | (imu_data[0] << 31)),
COERCE_FLOAT((dword_404098 << 11) | dword_40409C | (dword_404094 << 23) | (dword_404090 << 31)),
COERCE_FLOAT((dword_4040A8 << 11) | dword_4040AC | (dword_4040A4 << 23) | (dword_4040A0 << 31)));
v4 = 0;
v5 = 0;
}
if ( buf[0] == 83 )
{
LABEL_8:
v7[v4++] = buf[0];
v5 = 1;
}
}
}
puts("Insert device parameter: /dev/ttyXXX");
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // ebx
int v4; // er12
int v5; // ebp
char v7[95]; // [rsp+0h] [rbp-78h] BYREF
char buf[25]; // [rsp+5Fh] [rbp-19h] BYREF

if ( argc > 1 )
{
v3 = open(argv[1], 1052928, envp);
if ( v3 == -1 )
perror("open_port: Unable to open the file descriptor");
v4 = 0;
v5 = 0;
while ( 1 )
{
while ( 1 )
{
if ( !read(v3, buf, 1uLL) )
return 0;
if ( !v5 )
break;
if ( buf[0] != 69 )
goto LABEL_8;
v7[86] = 0;
func7(v7);
printf(
"Roll:%10f,Pitch:%10f,Yaw:%10f\n",
COERCE_FLOAT((dword_404088 << 11) | dword_40408C | (dword_404084 << 23) | (imu_data[0] << 31)),
COERCE_FLOAT((dword_404098 << 11) | dword_40409C | (dword_404094 << 23) | (dword_404090 << 31)),
COERCE_FLOAT((dword_4040A8 << 11) | dword_4040AC | (dword_4040A4 << 23) | (dword_4040A0 << 31)));
v4 = 0;
v5 = 0;
}
if ( buf[0] == 83 )
{
LABEL_8:
v7[v4++] = buf[0];
v5 = 1;
}
}
}
puts("Insert device parameter: /dev/ttyXXX");
return 0;
}

original_code:
int main(int argc, char *argv[])
{
 char s;
 int serialfd,n;
 uint32_t tRoll,tPitch,tYaw;
 float Roll,Pitch,Yaw;
 char dels[] = ":";
 char packet[87];
 int packet_flag = 0;
 int i = 0;
 int j = 0;
 int k = 0;
 if(argc<2)
 {
  printf("Insert device parameter: /dev/ttyXXX\n");
  return 0;
 }
 serialfd = open(argv[1], 00 | 0400 | 04010000);
 if (serialfd == -1)
 {
  perror("open_port: Unable to open the file descriptor");
 }
 while(read(serialfd, &s, 1))
 {
  if((packet_flag == 0) && (s == 'S'))
  {
   packet_flag = 1;
  }
  else if((packet_flag == 1) && (s == 'E'))
  {
   packet_flag = 0;
   i = 0;
   packet[86] = '\0';
   tokenizer(packet);
   tRoll = (uint32_t)((imu_data[0] << 31) | (imu_data[1] << 23) | (imu_data[2] << 11) | imu_data[3]);
   tPitch = (uint32_t)((imu_data[4] << 31) | (imu_data[5] << 23) | (imu_data[6] << 11) | imu_data[7]);
   tYaw = (uint32_t)((imu_data[8] << 31) | (imu_data[9] << 23) | (imu_data[10] << 11) | imu_data[11]);
   Roll = (*(float*)&tRoll);
   Pitch = (*(float*)&tPitch);
   Yaw = (*(float*)&tYaw);
   printf("Roll:%10f,Pitch:%10f,Yaw:%10f\n",Roll,Pitch,Yaw);
  }
  if(packet_flag == 1)
   packet[i++] = s;
 }
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
 char s;
 int serialfd; int n;
 unsigned int tRoll; unsigned int tPitch; unsigned int tYaw;
 float Roll; float Pitch; float Yaw;
 char dels[] = ":";
 char packet[87];
 int packet_flag = 0;
 int i = 0;
 int j = 0;
 int k = 0;
 if(argc<2)
 {
  printf("Insert device parameter: /dev/ttyXXX\n");
  return 0;
 }
 serialfd = open(argv[1], 00 | 0400 | 04010000);
 if (serialfd == -1)
 {
  perror("open_port: Unable to open the file descriptor");
 }
 while(read(serialfd, &s, 1))
 {
  if((packet_flag == 0) && (s == 'S'))
  {
   packet_flag = 1;
  }
  else if((packet_flag == 1) && (s == 'E'))
  {
   packet_flag = 0;
   i = 0;
   packet[86] = '\0';
   tokenizer(packet);
   tRoll = (unsigned int)((imu_data[0] << 31) | (imu_data[1] << 23) | (imu_data[2] << 11) | imu_data[3]);
   tPitch = (unsigned int)((imu_data[4] << 31) | (imu_data[5] << 23) | (imu_data[6] << 11) | imu_data[7]);
   tYaw = (unsigned int)((imu_data[8] << 31) | (imu_data[9] << 23) | (imu_data[10] << 11) | imu_data[11]);
   Roll = (*(float *)&tRoll);
   Pitch = (*(float *)&tPitch);
   Yaw = (*(float *)&tYaw);
   printf("Roll:%10f,Pitch:%10f,Yaw:%10f\n",Roll,Pitch,Yaw);
  }
  if(packet_flag == 1)
   packet[i++] = s;
 }
 return 0;
}

variable_types:
argv
char *[]

variable_types: s char

variable_types: serialfd int

variable_types: n int

variable_types:
tRoll
unsigned int

variable_types:
tPitch
unsigned int

variable_types:
tYaw
unsigned int

variable_types: Roll float

variable_types: Pitch float

variable_types: Yaw float

variable_types:
packet
char [87]

variable_types: k int


equals

decompiled_code:
__int64 __fastcall equals(char *filename, char *a2)
{
unsigned int v2; // er12
struct stat v4; // [rsp+0h] [rbp-138h] BYREF
struct stat v5; // [rsp+90h] [rbp-A8h] BYREF

syslog(5, "(!!) confronto tra %s %s", filename, a2);
v2 = 1;
if ( !(unsigned int)stat(filename, &v5) )
{
v2 = stat(a2, &v4);
if ( v2 )
{
v2 = 1;
}
else if ( (v5.st_mode & 0x8000) == 0 )
{
if ( (v5.st_mode & 0x4000) != 0 )
{
if ( (v4.st_mode & 0x8000) != 0 )
{
printf(aS, a2, filename);
}
else
{
v2 = 1;
if ( (v4.st_mode & 0x4000) != 0 )
v2 = recursiveDirectory(a2, filename);
}
}
else
{
v2 = 1;
}
}
else if ( (v4.st_mode & 0x8000) != 0 )
{
v2 = confrontafile(filename, a2) != 0;
}
else if ( (v4.st_mode & 0x4000) != 0 )
{
printf(aS, filename, a2);
}
else
{
v2 = 1;
}
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func8(char *filename, char *a2)
{
unsigned int v2; // er12
struct stat v4; // [rsp+0h] [rbp-138h] BYREF
struct stat v5; // [rsp+90h] [rbp-A8h] BYREF

syslog(5, "(!!) confronto tra %s %s", filename, a2);
v2 = 1;
if ( !(unsigned int)func13(filename, &v5) )
{
v2 = func13(a2, &v4);
if ( v2 )
{
v2 = 1;
}
else if ( (v5.st_mode & 0x8000) == 0 )
{
if ( (v5.st_mode & 0x4000) != 0 )
{
if ( (v4.st_mode & 0x8000) != 0 )
{
printf(aS, a2, filename);
}
else
{
v2 = 1;
if ( (v4.st_mode & 0x4000) != 0 )
v2 = func9(a2, filename);
}
}
else
{
v2 = 1;
}
}
else if ( (v4.st_mode & 0x8000) != 0 )
{
v2 = func7(filename, a2) != 0;
}
else if ( (v4.st_mode & 0x4000) != 0 )
{
printf(aS, filename, a2);
}
else
{
v2 = 1;
}
}
return v2;
}

original_code:
int equals(char * patha, char * pathb) {
    syslog(5, "(!!) confronto tra %s %s", patha, pathb);
    int retval = 1;
    struct stat a, b;
    if (stat(patha, &a) == 0 && stat(pathb, &b) == 0) {
        if (a.st_mode & 0100000) {
            if (b.st_mode & 0100000) {
                if (confrontafile(patha, pathb)) {
                    return 1;
                } else {
                    return 0;
                }
            } else if (b.st_mode & 0040000) {
                printf("%s è un file mentre %s è una cartella\n", patha, pathb);
                return 0;
            }
        } else if (a.st_mode & 0040000) {
            if (b.st_mode & 0100000) {
                printf("%s è un file mentre %s è una cartella\n", pathb, patha);
                return 0;
            } else if (b.st_mode & 0040000) {
                return recursiveDirectory(pathb, patha);
            }
        }
    }
    return retval;
}

canonical_original_code:
int equals(char *patha, char *pathb) {
    syslog(5, "(!!) confronto tra %s %s", patha, pathb);
    int retval = 1;
    struct stat a; struct stat b;
    if (stat(patha, &a) == 0 && stat(pathb, &b) == 0) {
        if (a.st_mode & 0100000) {
            if (b.st_mode & 0100000) {
                if (confrontafile(patha, pathb)) {
                    return 1;
                } else {
                    return 0;
                }
            } else if (b.st_mode & 0040000) {
                printf("%s è un file mentre %s è una cartella\n", patha, pathb);
                return 0;
            }
        } else if (a.st_mode & 0040000) {
            if (b.st_mode & 0100000) {
                printf("%s è un file mentre %s è una cartella\n", pathb, patha);
                return 0;
            } else if (b.st_mode & 0040000) {
                return recursiveDirectory(pathb, patha);
            }
        }
    }
    return retval;
}

variable_types:
patha
char *

variable_types:
pathb
char *

variable_types: retval int

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


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char **v3; // rbx
int result; // eax
FILE *v5; // rdi
FILE *v6; // rdi
char v7[1008]; // [rsp+0h] [rbp-A08h] BYREF
char resolved[1008]; // [rsp+3F0h] [rbp-618h] BYREF
char s[32]; // [rsp+7E0h] [rbp-228h] BYREF
char v10[480]; // [rsp+800h] [rbp-208h] BYREF

strcpy(s, "(II) impostazioni inserite :");
memset(v10, 0, sizeof(v10));
openlog("plive", 1, 40);
if ( argc > 0 )
{
v3 = argv;
do
{
*(_WORD *)&s[strlen(s)] = 32;
strcat(s, *v3++);
}
while ( v3 != &argv[(unsigned int)(argc - 1) + 1] );
}
*(_WORD *)&s[strlen(s)] = 10;
syslog(5, "%s", s);
if ( argc == 3 )
{
v5 = fopen(argv[1], "r");
if ( v5 )
{
fclose(v5);
v6 = fopen(argv[2], "r");
if ( v6 )
{
fclose(v6);
realpath(argv[1], resolved);
realpath(argv[2], v7);
result = equals(resolved, v7) == 0;
}
else
{
syslog(3, "File/directory %s non trovato", argv[2]);
printf("File/directory %s non trovato \n", argv[2]);
result = 1;
}
}
else
{
syslog(3, "(EE) File/directory %s non trovato", argv[1]);
printf("File/directory %s non trovato \n", argv[1]);
result = 1;
}
}
else
{
syslog(3, "(EE) Wrong command -- usage : ./equals <path A> <path B> \n");
puts("Wrong command -- usage : ./equals <path A> <path B> ");
result = 1;
}
return result;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char **v3; // rbx
int result; // eax
FILE *v5; // rdi
FILE *v6; // rdi
char v7[1008]; // [rsp+0h] [rbp-A08h] BYREF
char resolved[1008]; // [rsp+3F0h] [rbp-618h] BYREF
char s[32]; // [rsp+7E0h] [rbp-228h] BYREF
char v10[480]; // [rsp+800h] [rbp-208h] BYREF

strcpy(s, "(II) impostazioni inserite :");
memset(v10, 0, sizeof(v10));
openlog("plive", 1, 40);
if ( argc > 0 )
{
v3 = argv;
do
{
*(_WORD *)&s[strlen(s)] = 32;
strcat(s, *v3++);
}
while ( v3 != &argv[(unsigned int)(argc - 1) + 1] );
}
*(_WORD *)&s[strlen(s)] = 10;
syslog(5, "%s", s);
if ( argc == 3 )
{
v5 = fopen(argv[1], "r");
if ( v5 )
{
fclose(v5);
v6 = fopen(argv[2], "r");
if ( v6 )
{
fclose(v6);
realpath(argv[1], resolved);
realpath(argv[2], v7);
result = func8(resolved, v7) == 0;
}
else
{
syslog(3, "File/directory %s non trovato", argv[2]);
printf("File/directory %s non trovato \n", argv[2]);
result = 1;
}
}
else
{
syslog(3, "(EE) File/directory %s non trovato", argv[1]);
printf("File/directory %s non trovato \n", argv[1]);
result = 1;
}
}
else
{
syslog(3, "(EE) Wrong command -- usage : ./equals <path A> <path B> \n");
puts("Wrong command -- usage : ./equals <path A> <path B> ");
result = 1;
}
return result;
}

original_code:
int main(int argc, char **argv) {
    int c;
    int error = -1;
    int i;
    int nflag;
    char temp[512]="(II) impostazioni inserite :";
    openlog("plive", 0x04 || 0x01, (5<<3));
    for (i = 0; i < argc; i += 1) {
        strcat(temp, " ");
        strcat(temp, argv[i]);
    }
    strcat(temp, "\n");
    syslog(5, "%s", temp);
    while ((c = getopt(argc, argv, "n:")) != -1) {
        switch (c) {
            case 'n':
                num_vis = atoi(optarg);
                break;
            default:
                syslog(5, "(EE) opzione non riconosciuta\n");
                exit(0);
        }
    }
    initscr();
    pthread_create(&mainthread, ((void *)0), &controllocaratteri, ((void *)0));
    pthread_create(&mthread, ((void *)0), &printProc, ((void *)0));
    pthread_join(mthread, ((void *)0));
    pthread_join(mainthread, ((void *)0));
    return 0;
}

canonical_original_code:
int main(int argc, char **argv) {
    int c;
    int error = -1;
    int i;
    int nflag;
    char temp[512] = "(II) impostazioni inserite :";
    openlog("plive", 0x04 || 0x01, (5<<3));
    for (i = 0; i < argc; i += 1) {
        strcat(temp, " ");
        strcat(temp, argv[i]);
    }
    strcat(temp, "\n");
    syslog(5, "%s", temp);
    while ((c = getopt(argc, argv, "n:")) != -1) {
        switch (c) {
            case 'n':
                num_vis = atoi(optarg);
                break;
            default:
                syslog(5, "(EE) opzione non riconosciuta\n");
                exit(0);
        }
    }
    initscr();
    pthread_create(&mainthread, ((void *)0), &controllocaratteri, ((void *)0));
    pthread_create(&mthread, ((void *)0), &printProc, ((void *)0));
    pthread_join(mthread, ((void *)0));
    pthread_join(mainthread, ((void *)0));
    return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types: c int

variable_types: error int

variable_types: i int

variable_types: nflag int

variable_types:
temp
char [512]


recursiveDirectory

decompiled_code:
_BOOL8 __fastcall recursiveDirectory(char *dir, char *a2)
{
int v2; // er12
int v3; // er14
bool v4; // al
bool v5; // dl
int v6; // ebp
int v7; // ebx
struct dirent **v8; // r15
_BOOL4 v10; // [rsp+10h] [rbp-258h]
int v11; // [rsp+14h] [rbp-254h]
char s2[256]; // [rsp+20h] [rbp-248h] BYREF
char dest[256]; // [rsp+120h] [rbp-148h] BYREF
struct dirent **v14; // [rsp+220h] [rbp-48h] BYREF
struct dirent **namelist; // [rsp+228h] [rbp-40h] BYREF

syslog(5, "(!!) controllo delle due cartelle %s %s", dir, a2);
v2 = scandir(dir, &namelist, 0LL, alphasort);
v3 = scandir(a2, &v14, 0LL, alphasort);
v4 = v2 > 2;
v5 = v3 > 2;
if ( v2 > 2 || v3 > 2 )
{
v6 = 2;
v7 = 2;
v10 = 1;
while ( 1 )
{
if ( v4 && v5 )
{
strcpy(dest, namelist[v7]->d_name);
v8 = &v14[v6];
strcpy(s2, (*v8)->d_name);
v11 = strcmp(dest, s2);
sprintf(s2, "%s/%s", a2, (*v8)->d_name);
sprintf(dest, "%s/%s", dir, namelist[v7]->d_name);
if ( !v11 )
{
++v7;
++v6;
if ( v10 )
v10 = equals(dest, s2) != 0;
goto LABEL_7;
}
if ( v11 > 0 )
goto LABEL_6;
}
else
{
if ( v2 == v7 )
{
sprintf(s2, "%s/%s", a2, v14[v6]->d_name);
LABEL_6:
++v6;
printf("l'elemento %s non e' presente in %s\n", s2, dir);
v10 = 0;
goto LABEL_7;
}
sprintf(dest, "%s/%s", dir, namelist[v7]->d_name);
}
++v7;
printf("l'elemento %s non e' presente in %s\n", dest, a2);
v10 = 0;
LABEL_7:
v4 = v7 < v2;
v5 = v3 > v6;
if ( v7 >= v2 && v3 <= v6 )
return v10;
}
}
return 1;
}

canonical_decompiled_code:
_BOOL8 __fastcall func9(char *dir, char *a2)
{
int v2; // er12
int v3; // er14
bool v4; // al
bool v5; // dl
int v6; // ebp
int v7; // ebx
struct dirent **v8; // r15
_BOOL4 v10; // [rsp+10h] [rbp-258h]
int v11; // [rsp+14h] [rbp-254h]
char s2[256]; // [rsp+20h] [rbp-248h] BYREF
char dest[256]; // [rsp+120h] [rbp-148h] BYREF
struct dirent **v14; // [rsp+220h] [rbp-48h] BYREF
struct dirent **namelist; // [rsp+228h] [rbp-40h] BYREF

syslog(5, "(!!) controllo delle due cartelle %s %s", dir, a2);
v2 = scandir(dir, &namelist, 0LL, alphasort);
v3 = scandir(a2, &v14, 0LL, alphasort);
v4 = v2 > 2;
v5 = v3 > 2;
if ( v2 > 2 || v3 > 2 )
{
v6 = 2;
v7 = 2;
v10 = 1;
while ( 1 )
{
if ( v4 && v5 )
{
strcpy(dest, namelist[v7]->d_name);
v8 = &v14[v6];
strcpy(s2, (*v8)->d_name);
v11 = strcmp(dest, s2);
sprintf(s2, "%s/%s", a2, (*v8)->d_name);
sprintf(dest, "%s/%s", dir, namelist[v7]->d_name);
if ( !v11 )
{
++v7;
++v6;
if ( v10 )
v10 = func8(dest, s2) != 0;
goto LABEL_7;
}
if ( v11 > 0 )
goto LABEL_6;
}
else
{
if ( v2 == v7 )
{
sprintf(s2, "%s/%s", a2, v14[v6]->d_name);
LABEL_6:
++v6;
printf("l'elemento %s non e' presente in %s\n", s2, dir);
v10 = 0;
goto LABEL_7;
}
sprintf(dest, "%s/%s", dir, namelist[v7]->d_name);
}
++v7;
printf("l'elemento %s non e' presente in %s\n", dest, a2);
v10 = 0;
LABEL_7:
v4 = v7 < v2;
v5 = v3 > v6;
if ( v7 >= v2 && v3 <= v6 )
return v10;
}
}
return 1;
}

original_code:
int recursiveDirectory(char * patha, char * pathb) {
    syslog(5, "(!!) controllo delle due cartelle %s %s", patha, pathb);
    struct dirent **drnt1;
    struct dirent **drnt2;
    int retval = 1;
    int n1 = 0, n2 = 0;
    int i, j;
    char tmp1[256], tmp2[256];
    n1 = scandir(patha, &drnt1, 0, alphasort);
    n2 = scandir(pathb, &drnt2, 0, alphasort);
    j = 2;
    for (i = 2; i < n1 || j < n2;) {
        int cmp;
        if (i < n1 && j < n2) {
            strcpy(tmp1, drnt1[i]->d_name);
            strcpy(tmp2, drnt2[j]->d_name);
            cmp = strcmp(tmp1, tmp2);
            sprintf(tmp2, "%s/%s", pathb, drnt2[j]->d_name);
            sprintf(tmp1, "%s/%s", patha, drnt1[i]->d_name);
        } else if (i == n1) {
            sprintf(tmp2, "%s/%s", pathb, drnt2[j]->d_name);
            cmp = 1;
        } else {
            sprintf(tmp1, "%s/%s", patha, drnt1[i]->d_name);
            cmp = -1;
        }
        if (cmp == 0) {
            i++;
            j++;
            retval = retval && equals(tmp1, tmp2);
        } else if (cmp > 0) {
            j++;
            retval = 0;
            printf("l'elemento %s non e\' presente in %s\n", tmp2, patha);
        } else {
            i++;
            retval = 0;
            printf("l'elemento %s non e\' presente in %s\n", tmp1, pathb);
        }
    }
    return retval;
}

canonical_original_code:
int recursiveDirectory(char *patha, char *pathb) {
    syslog(5, "(!!) controllo delle due cartelle %s %s", patha, pathb);
    struct dirent **drnt1;
    struct dirent **drnt2;
    int retval = 1;
    int n1 = 0; int n2 = 0;
    int i; int j;
    char tmp1[256]; char tmp2[256];
    n1 = scandir(patha, &drnt1, 0, alphasort);
    n2 = scandir(pathb, &drnt2, 0, alphasort);
    j = 2;
    for (i = 2; i < n1 || j < n2;) {
        int cmp;
        if (i < n1 && j < n2) {
            strcpy(tmp1, drnt1[i]->d_name);
            strcpy(tmp2, drnt2[j]->d_name);
            cmp = strcmp(tmp1, tmp2);
            sprintf(tmp2, "%s/%s", pathb, drnt2[j]->d_name);
            sprintf(tmp1, "%s/%s", patha, drnt1[i]->d_name);
        } else if (i == n1) {
            sprintf(tmp2, "%s/%s", pathb, drnt2[j]->d_name);
            cmp = 1;
        } else {
            sprintf(tmp1, "%s/%s", patha, drnt1[i]->d_name);
            cmp = -1;
        }
        if (cmp == 0) {
            i++;
            j++;
            retval = retval && equals(tmp1, tmp2);
        } else if (cmp > 0) {
            j++;
            retval = 0;
            printf("l'elemento %s non e\' presente in %s\n", tmp2, patha);
        } else {
            i++;
            retval = 0;
            printf("l'elemento %s non e\' presente in %s\n", tmp1, pathb);
        }
    }
    return retval;
}

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

variable_types: j int

variable_types: cmp int


getTime

decompiled_code:
char *getTime()
{
struct tm *v0; // rax
time_t timer; // [rsp+8h] [rbp-10h] BYREF

time(&timer);
v0 = localtime(&timer);
return asctime(v0);
}

canonical_decompiled_code:
char *func10()
{
struct tm *v0; // rax
time_t timer; // [rsp+8h] [rbp-10h] BYREF

time(&timer);
v0 = localtime(&timer);
return asctime(v0);
}

original_code:
char* getTime() {
    time_t rawtime;
    struct tm * timeinfo;
    time(&rawtime);
    timeinfo = localtime(&rawtime);
    return asctime(timeinfo);
}

canonical_original_code:
char *getTime() {
    long rawtime;
    struct tm *timeinfo;
    time(&rawtime);
    timeinfo = localtime(&rawtime);
    return asctime(timeinfo);
}

variable_types: rawtime long

variable_types: struct tm { int tm_sec; int tm_min; int tm_hour; int tm_mday; int tm_mon; int tm_year; int tm_wday; int tm_yday; int tm_isdst; long tm_gmtoff; char *tm_zone; } *

return_type: char *


dumpparts

repo: foxbow/fbfstools

decompiled_code:
int __fastcall dumpparts(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, char a7, int a8, char a9, int a10, char a11)
{
printf("pre: >%s<\n", &a7);
printf("dat: >%s<\n", &a9);
return printf("pos: >%s<\n", &a11);
}

canonical_decompiled_code:
int __fastcall func0(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, char a7, int a8, char a9, int a10, char a11)
{
printf("pre: >%s<\n", &a7);
printf("dat: >%s<\n", &a9);
return printf("pos: >%s<\n", &a11);
}

original_code:
void dumpparts( struct fparts parts ) {
 printf("pre: >%s<\n", parts.prefix );
 printf("dat: >%s<\n", parts.date );
 printf("pos: >%s<\n", parts.postfix );
}

canonical_original_code:
void dumpparts(struct fparts parts) {
 printf("pre: >%s<\n", parts.prefix );
 printf("dat: >%s<\n", parts.date );
 printf("pos: >%s<\n", parts.postfix );
}

variable_types: struct fparts { char prefix[16]; char date[16]; char postfix[16]; }


splitname

original_code:
void splitname( const char *fname, struct fparts *parts ){
 int cnt=0;
 int pos=0;
 int state=0;
 if( ((void *)0) == fname ) {
  fail("splitname arg", fname, 131 );
 }
 parts->prefix[0]=0;
 parts->date[0]=0;
 parts->postfix[0]=0;
 for( cnt=0; cnt < strlen( fname ); cnt ++ ) {
  switch( state ) {
  case 0:
   if( ((*__ctype_b_loc ())[(int) ((fname[cnt]))] & (unsigned short int) _ISdigit) ) {
    state=1;
    parts->prefix[pos]=0;
    pos=0;
    parts->date[pos]=fname[cnt];
   } else {
    parts->prefix[pos]=fname[cnt];
   }
  break;
  case 1:
   if( !((*__ctype_b_loc ())[(int) ((fname[cnt]))] & (unsigned short int) _ISdigit) ) {
    state=2;
    parts->date[pos]=0;
    pos=0;
    parts->postfix[pos]=fname[cnt];
   } else {
    parts->date[pos]=fname[cnt];
   }
  break;
  case 2:
   parts->postfix[pos]=fname[cnt];
  break;
  default:
   fail("splitname state", fname, state );
  break;
  }
  pos++;
 }
 switch(state){
 case 0: parts->prefix[pos]=0;
 break;
 case 1: parts->date[pos]=0;
 break;
 case 2: parts->postfix[pos]=0;
 break;
 default:
  fail("splitname final", fname, state );
 break;
 }
}

canonical_original_code:
void splitname(char *fname, struct fparts *parts){
 int cnt = 0;
 int pos = 0;
 int state = 0;
 if( ((void *)0) == fname ) {
  fail("splitname arg", fname, 131 );
 }
 parts->prefix[0]=0;
 parts->date[0]=0;
 parts->postfix[0]=0;
 for( cnt=0; cnt < strlen( fname ); cnt ++ ) {
  switch( state ) {
  case 0:
   if( ((*__ctype_b_loc ())[(int) ((fname[cnt]))] & (unsigned short) _ISdigit) ) {
    state=1;
    parts->prefix[pos]=0;
    pos=0;
    parts->date[pos]=fname[cnt];
   } else {
    parts->prefix[pos]=fname[cnt];
   }
  break;
  case 1:
   if( !((*__ctype_b_loc ())[(int) ((fname[cnt]))] & (unsigned short) _ISdigit) ) {
    state=2;
    parts->date[pos]=0;
    pos=0;
    parts->postfix[pos]=fname[cnt];
   } else {
    parts->date[pos]=fname[cnt];
   }
  break;
  case 2:
   parts->postfix[pos]=fname[cnt];
  break;
  default:
   fail("splitname state", fname, state );
  break;
  }
  pos++;
 }
 switch(state){
 case 0: parts->prefix[pos]=0;
 break;
 case 1: parts->date[pos]=0;
 break;
 case 2: parts->postfix[pos]=0;
 break;
 default:
  fail("splitname final", fname, state );
 break;
 }
}

variable_types:
fname
char *

variable_types: struct fparts { char prefix[16]; char date[16]; char postfix[16]; } *

variable_types: cnt int

variable_types: pos int

variable_types: state int


joinname

decompiled_code:
char *__fastcall joinname(char *dest, int a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, char src, int a8, char a9, int a10, char a11)
{
strncpy(dest, &src, a2);
strncat(dest, &a9, a2);
return strncat(dest, &a11, a2);
}

canonical_decompiled_code:
char *__fastcall func2(char *dest, int a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, char src, int a8, char a9, int a10, char a11)
{
strncpy(dest, &src, a2);
strncat(dest, &a9, a2);
return strncat(dest, &a11, a2);
}

original_code:
char *joinname( const struct fparts parts, char *name, int len ) {
 strncpy( name, parts.prefix, len );
 strncat( name, parts.date, len );
 strncat( name, parts.postfix, len );
 return name;
}

canonical_original_code:
char *joinname(struct fparts parts, char *name, int len) {
 strncpy( name, parts.prefix, len );
 strncat( name, parts.date, len );
 strncat( name, parts.postfix, len );
 return name;
}

variable_types:
name
char *

variable_types: len int

user_defined_types: struct fparts { char prefix[16]; char date[16]; char postfix[16]; }


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
if ( argc == 1 )
traverse(".");
else
traverse(argv[1]);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
if ( argc == 1 )
func3(".");
else
func3(argv[1]);
return 0;
}

original_code:
int main( int argc, char **argv ) {
 if( argc == 1 ) {
  traverse( "." );
 } else {
  traverse( argv[1] );
 }
 return 0;
}

canonical_original_code:
int main(int argc, char **argv) {
 if( argc == 1 ) {
  traverse( "." );
 } else {
  traverse( argv[1] );
 }
 return 0;
}

variable_types: argc int

variable_types:
argv
char **


genPLName

decompiled_code:
char *__fastcall genPLName(char *dest, __int64 a2)
{
size_t v2; // rax

genPathName(dest, a2, 256LL);
if ( strlen(dest) <= 1 )
strcpy(dest, "playlist");
v2 = strlen(dest);
return strncat(dest, ".m3u", 256 - v2);
}

canonical_decompiled_code:
char *__fastcall func0(char *dest, __int64 a2)
{
size_t v2; // rax

genPathName(dest, a2, 256LL);
if ( strlen(dest) <= 1 )
strcpy(dest, "playlist");
v2 = strlen(dest);
return strncat(dest, ".m3u", 256 - v2);
}

original_code:
char *genPLName( char *plname, const char *cd ){
 genPathName( plname, cd, 256 );
 if( strlen(plname) < 2 ) {
  strcpy( plname, "playlist" );
 }
 strncat( plname, ".m3u", 256 -strlen( plname ) );
 return plname;
}

canonical_original_code:
char *genPLName(char *plname, char *cd){
 genPathName( plname, cd, 256 );
 if( strlen(plname) < 2 ) {
  strcpy( plname, "playlist" );
 }
 strncat( plname, ".m3u", 256 -strlen( plname ) );
 return plname;
}

variable_types:
plname
char *

variable_types:
cd
char *


main

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
if ( argc == 1 )
func1(".");
else
func1(argv[1]);
return 0;
}


freekb

decompiled_code:
unsigned __int64 __fastcall freekb(const char *a1)
{
int *v2; // rax
struct statvfs v3; // [rsp+0h] [rbp-78h] BYREF

if ( !statvfs(a1, &v3) )
return (v3.f_bsize * v3.f_bavail) >> 10;
v2 = _errno_location();
fail("Couldn't get free space for ", a1, (unsigned int)*v2);
return 0LL;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func0(const char *a1)
{
int *v2; // rax
struct statvfs v3; // [rsp+0h] [rbp-78h] BYREF

if ( !statvfs(a1, &v3) )
return (v3.f_bsize * v3.f_bavail) >> 10;
v2 = _errno_location();
fail("Couldn't get free space for ", a1, (unsigned int)*v2);
return 0LL;
}

original_code:
long freekb(const char * part) {
 struct statvfs buf;
 if (0 == statvfs(part, &buf))
  return (buf.f_bavail*buf.f_bsize)/1024;
 else
  fail( "Couldn't get free space for ", part, (*__errno_location ()) );
 return 0;
}

canonical_original_code:
long freekb(char *part) {
 struct statvfs buf;
 if (0 == statvfs(part, &buf))
  return (buf.f_bavail*buf.f_bsize)/1024;
 else
  fail( "Couldn't get free space for ", part, (*__errno_location ()) );
 return 0;
}

variable_types:
part
char *

variable_types: struct statvfs { unsigned long f_bsize; unsigned long f_frsize; unsigned long f_blocks; unsigned long f_bfree; unsigned long f_bavail; unsigned long f_files; unsigned long f_ffree; unsigned long f_favail; unsigned long f_fsid; unsigned long f_flag; unsigned long f_namemax; int __f_spare[6]; }

return_type: long


writePlaylist

original_code:
void writePlaylist( struct entry_t *list, long int maxlen, const char* target ){
 struct entry_t *base;
 int i, cnt=1, no=0;
 long int size=512;
 long int maxsize=freekb( target );
 if( 0 == maxlen ) size=maxsize;
 else if ( maxsize < maxlen ) maxlen=maxsize;
 while( list->prev != ((void *)0) ){
  list=list->prev;
  cnt++;
 }
 base=list;
 if ( getVerbosity() > 2 ) printf("Found %i titles\n", cnt);
 for(i=cnt; i>0; i--){
  int j, pos;
  list=base;
  pos=(rand()%i);
  for(j=1; j<=pos; j++){
   list=list->next;
  }
  if ( ( list->size < 15*1024 ) && ( list->size > 1024 ) ) {
   if( 0 == maxlen ){
    if( list->size < size ){
     copy( list, target, no );
     no++;
     size=freekb( target );
     if( getVerbosity() > 0 ) printf("[%3li%%]\n", 100-((100*size)/maxsize));
    }
   }else{
    size=size+list->size;
    if ( size < maxlen ) {
     copy( list, target, no );
     no++;
     if( getVerbosity() ) printf("[%3li%%]\n", (100*size)/maxlen);
    }
   }
  }
  if(list->prev != ((void *)0)){
   list->prev->next=list->next;
  }
  if(list->next != ((void *)0)){
   list->next->prev=list->prev;
  }
  if(list==base) base=list->next;
  free(list);
 }
}

canonical_original_code:
void writePlaylist(struct entry_t *list, long maxlen, char *target){
 struct entry_t *base;
 int i; int cnt = 1; int no = 0;
 long size = 512;
 long maxsize = freekb( target );
 if( 0 == maxlen ) size=maxsize;
 else if ( maxsize < maxlen ) maxlen=maxsize;
 while( list->prev != ((void *)0) ){
  list=list->prev;
  cnt++;
 }
 base=list;
 if ( getVerbosity() > 2 ) printf("Found %i titles\n", cnt);
 for(i=cnt; i>0; i--){
  int j; int pos;
  list=base;
  pos=(rand()%i);
  for(j=1; j<=pos; j++){
   list=list->next;
  }
  if ( ( list->size < 15*1024 ) && ( list->size > 1024 ) ) {
   if( 0 == maxlen ){
    if( list->size < size ){
     copy( list, target, no );
     no++;
     size=freekb( target );
     if( getVerbosity() > 0 ) printf("[%3li%%]\n", 100-((100*size)/maxsize));
    }
   }else{
    size=size+list->size;
    if ( size < maxlen ) {
     copy( list, target, no );
     no++;
     if( getVerbosity() ) printf("[%3li%%]\n", (100*size)/maxlen);
    }
   }
  }
  if(list->prev != ((void *)0)){
   list->prev->next=list->next;
  }
  if(list->next != ((void *)0)){
   list->next->prev=list->prev;
  }
  if(list==base) base=list->next;
  free(list);
 }
}

variable_types: struct entry_t { struct entry_t *prev; unsigned long key; char path[256]; char name[256]; char display[256]; unsigned long size; char artist[256]; int rating; char title[256]; char album[256]; int length; unsigned long played; struct entry_t *next; } *

variable_types: maxlen long

variable_types:
target
char *

variable_types: i int

variable_types: no int

variable_types: size long

variable_types: maxsize long

variable_types: j int


usage

decompiled_code:
void __fastcall __noreturn usage(const char *a1)
{
printf("%s - copy music onto a player\n", a1);
printf(
"Usage: %s [-s <sourcedir>] [-t <tagetdir>] [-m <megabytes>] [-n] [-l <path to blacklist>] [-v <verbosity>]\n",
a1);
puts("-s <path> : set path to directory with music [current dir]");
printf("-t <path> : set path to target directory/device [%s]\n", "player/");
puts("-m <num> : Size of target dir (0=all) [0]");
puts("-n : Do not clean target dir [off]");
puts("-l <file> : Blacklist of names to exclude [unset]");
puts("-v <num> : Verbosity (0=quiet, 1=process, 2=1+wait for enter, 3=2+verbose output) [1]");
exit(0);
}

canonical_decompiled_code:
void __fastcall __noreturn func4(const char *a1)
{
printf("%s - copy music onto a player\n", a1);
printf(
"Usage: %s [-s <sourcedir>] [-t <tagetdir>] [-m <megabytes>] [-n] [-l <path to blacklist>] [-v <verbosity>]\n",
a1);
puts("-s <path> : set path to directory with music [current dir]");
printf("-t <path> : set path to target directory/device [%s]\n", "player/");
puts("-m <num> : Size of target dir (0=all) [0]");
puts("-n : Do not clean target dir [off]");
puts("-l <file> : Blacklist of names to exclude [unset]");
puts("-v <num> : Verbosity (0=quiet, 1=process, 2=1+wait for enter, 3=2+verbose output) [1]");
exit(0);
}

original_code:
void usage( char *progname ){
 printf( "%s - copy music onto a player\n", progname );
 printf( "Usage: %s [-s <sourcedir>] [-t <tagetdir>] [-m <megabytes>] [-n] [-l <path to blacklist>] [-v <verbosity>]\n", progname );
 printf( "-s <path> : set path to directory with music [current dir]\n" );
 printf( "-t <path> : set path to target directory/device [%s]\n", "player/" );
 printf( "-m <num>  : Size of target dir (0=all) [0]\n" );
 printf( "-n        : Do not clean target dir [off]\n" );
 printf( "-l <file> : Blacklist of names to exclude [unset]\n" );
 printf( "-v <num>  : Verbosity (0=quiet, 1=process, 2=1+wait for enter, 3=2+verbose output) [1]\n" );
 exit(0);
}

canonical_original_code:
void usage(char *progname){
 printf( "%s - copy music onto a player\n", progname );
 printf( "Usage: %s [-s <sourcedir>] [-t <tagetdir>] [-m <megabytes>] [-n] [-l <path to blacklist>] [-v <verbosity>]\n", progname );
 printf( "-s <path> : set path to directory with music [current dir]\n" );
 printf( "-t <path> : set path to target directory/device [%s]\n", "player/" );
 printf( "-m <num>  : Size of target dir (0=all) [0]\n" );
 printf( "-n        : Do not clean target dir [off]\n" );
 printf( "-l <file> : Blacklist of names to exclude [unset]\n" );
 printf( "-v <num>  : Verbosity (0=quiet, 1=process, 2=1+wait for enter, 3=2+verbose output) [1]\n" );
 exit(0);
}

variable_types:
progname
char *


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // eax
int v4; // er12
int v5; // er13
int *v6; // rax
size_t v7; // rax
char v8; // al
unsigned int v9; // eax
unsigned __int64 v10; // rbx
_QWORD **v11; // rbx
char v13[256]; // [rsp+0h] [rbp-328h] BYREF
char dest[8]; // [rsp+100h] [rbp-228h] BYREF
char v15; // [rsp+1FFh] [rbp-129h]
char buf[296]; // [rsp+200h] [rbp-128h] BYREF

v3 = time(0LL);
srand(v3);
if ( !getcwd(buf, 0x100uLL) )
{
v6 = _errno_location();
fail("Could not get current dir!", &unk_B29, (unsigned int)*v6);
}
strcpy(dest, "player/");
v4 = 0;
v5 = -1;
while ( 1 )
{
v8 = getopt(argc, (char *const *)argv, "s:t:m:nb:v:");
if ( v8 == -1 )
break;
switch ( v8 )
{
case 'b':
strcpy(v13, optarg);
loadBlacklist(v13);
break;
case 'm':
v4 = atoi(optarg) << 10;
break;
case 'n':
v5 = 0;
break;
case 's':
strcpy(buf, optarg);
v7 = strlen(buf);
if ( v7 == 2 && buf[1] == 58 )
{
sprintf(buf, "%s/", buf);
}
else if ( *(&v15 + v7) == 47 )
{
*(&v15 + v7) = 0;
}
break;
case 't':
strcpy(dest, optarg);
if ( v13[strlen(dest) + 255] != 47 )
sprintf(dest, "%s/", dest);
break;
case 'v':
v9 = atoi(optarg);
setVerbosity(v9);
break;
default:
usage(*argv);
}
}
if ( (int)getVerbosity() > 0 )
{
printf("Source: %s\n", buf);
printf("Target: %s\n", dest);
if ( v4 )
printf("Size : %i MB\n", (unsigned int)(v4 / 1024));
else
puts("Filling all space on target");
printf("Using MP3 files between %i and %i MB\n", 1LL, 15LL);
if ( v13[0] )
printf("Using %s as blacklist\n", v13);
if ( !v5 )
puts("Keeping existing files");
puts("Press enter to continue or CTRL-C to stop.");
fflush(stdout);
while ( getc(stdin) != 10 )
;
}
if ( v5 )
{
if ( (unsigned int)getVerbosity() )
printf("Cleaning %s\n", dest);
clean(dest);
if ( (unsigned int)getVerbosity() )
{
puts("OK");
fflush(stdout);
}
}
v10 = freekb(dest);
if ( v4 )
{
if ( (int)getVerbosity() > 1 )
printf("Space on device: %liM\n", v10 >> 10);
}
else if ( (unsigned int)getVerbosity() )
{
printf("Size: %li MB\n", v10 >> 10);
}
if ( (unsigned int)getVerbosity() )
printf("Scanning %s for mp3 files ..\n", buf);
fflush(stdout);
v11 = (_QWORD **)recurse(buf, 0LL);
if ( (unsigned int)getVerbosity() )
{
puts("OK");
fflush(stdout);
}
if ( v11 )
{
writePlaylist(v11, v4, dest);
}
else if ( (unsigned int)getVerbosity() )
{
printf("No music found in %s\n", buf);
}
if ( (unsigned int)getVerbosity() )
{
puts("Done.");
fflush(stdout);
}
if ( (int)getVerbosity() > 1 )
{
while ( getc(stdin) != 10 )
;
}
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // eax
int v4; // er12
int v5; // er13
int *v6; // rax
size_t v7; // rax
char v8; // al
unsigned int v9; // eax
unsigned __int64 v10; // rbx
_QWORD **v11; // rbx
char v13[256]; // [rsp+0h] [rbp-328h] BYREF
char dest[8]; // [rsp+100h] [rbp-228h] BYREF
char v15; // [rsp+1FFh] [rbp-129h]
char buf[296]; // [rsp+200h] [rbp-128h] BYREF

v3 = time(0LL);
srand(v3);
if ( !getcwd(buf, 0x100uLL) )
{
v6 = _errno_location();
fail("Could not get current dir!", &unk_B29, (unsigned int)*v6);
}
strcpy(dest, "player/");
v4 = 0;
v5 = -1;
while ( 1 )
{
v8 = getopt(argc, (char *const *)argv, "s:t:m:nb:v:");
if ( v8 == -1 )
break;
switch ( v8 )
{
case 'b':
strcpy(v13, optarg);
loadBlacklist(v13);
break;
case 'm':
v4 = atoi(optarg) << 10;
break;
case 'n':
v5 = 0;
break;
case 's':
strcpy(buf, optarg);
v7 = strlen(buf);
if ( v7 == 2 && buf[1] == 58 )
{
sprintf(buf, "%s/", buf);
}
else if ( *(&v15 + v7) == 47 )
{
*(&v15 + v7) = 0;
}
break;
case 't':
strcpy(dest, optarg);
if ( v13[strlen(dest) + 255] != 47 )
sprintf(dest, "%s/", dest);
break;
case 'v':
v9 = atoi(optarg);
setVerbosity(v9);
break;
default:
func4(*argv);
}
}
if ( (int)getVerbosity() > 0 )
{
printf("Source: %s\n", buf);
printf("Target: %s\n", dest);
if ( v4 )
printf("Size : %i MB\n", (unsigned int)(v4 / 1024));
else
puts("Filling all space on target");
printf("Using MP3 files between %i and %i MB\n", 1LL, 15LL);
if ( v13[0] )
printf("Using %s as blacklist\n", v13);
if ( !v5 )
puts("Keeping existing files");
puts("Press enter to continue or CTRL-C to stop.");
fflush(stdout);
while ( getc(stdin) != 10 )
;
}
if ( v5 )
{
if ( (unsigned int)getVerbosity() )
printf("Cleaning %s\n", dest);
func1(dest);
if ( (unsigned int)getVerbosity() )
{
puts("OK");
fflush(stdout);
}
}
v10 = func0(dest);
if ( v4 )
{
if ( (int)getVerbosity() > 1 )
printf("Space on device: %liM\n", v10 >> 10);
}
else if ( (unsigned int)getVerbosity() )
{
printf("Size: %li MB\n", v10 >> 10);
}
if ( (unsigned int)getVerbosity() )
printf("Scanning %s for mp3 files ..\n", buf);
fflush(stdout);
v11 = (_QWORD **)recurse(buf, 0LL);
if ( (unsigned int)getVerbosity() )
{
puts("OK");
fflush(stdout);
}
if ( v11 )
{
func3(v11, v4, dest);
}
else if ( (unsigned int)getVerbosity() )
{
printf("No music found in %s\n", buf);
}
if ( (unsigned int)getVerbosity() )
{
puts("Done.");
fflush(stdout);
}
if ( (int)getVerbosity() > 1 )
{
while ( getc(stdin) != 10 )
;
}
return 0;
}

original_code:
int main( int argc, char **argv ){
 unsigned long free;
 int delete=-1;
 struct entry_t *list;
 char curdir[256];
 char target[256];
 char blname[256];
 char c;
 int mbsize=0;
 srand((unsigned int)time(((void *)0)));
 if( ((void *)0) == getcwd( curdir, 256 ) )
  fail( "Could not get current dir!", "", (*__errno_location ()) );
 strcpy( target, "player/" );
 while( ( c = getopt( argc, argv, "s:t:m:nb:v:" ) ) != -1 ) {
  switch( c ) {
  case 's':
   strcpy( curdir, optarg );
   if( ( strlen(curdir) == 2 ) && ( curdir[1] == ':' ) )
    sprintf( curdir, "%s/", curdir );
   else if ( curdir[ strlen( curdir ) -1 ] == '/' )
    curdir[ strlen( curdir ) -1 ] = 0;
   break;
  case 't':
   strcpy( target, optarg );
   if ( target[ strlen( target ) -1 ] != '/' )
    sprintf( target, "%s/", target );
   break;
  case 'm':
   mbsize = atoi( optarg )*1024;
   break;
  case 'b':
   strcpy( blname, optarg );
   loadBlacklist( blname );
   break;
  case 'v':
   setVerbosity(atoi( optarg ));
   break;
  case 'n':
   delete = 0;
   break;
  default:
   usage( argv[0] );
   break;
  }
 }
 if( getVerbosity() > 0 ){
  printf( "Source: %s\n", curdir );
  printf( "Target: %s\n", target );
  if( 0 == mbsize )
   printf( "Filling all space on target\n" );
  else
   printf( "Size  : %i MB\n", mbsize/1024 );
  printf( "Using MP3 files between %i and %i MB\n", 1024/1024, 15*1024/1024 );
  if( 0 != blname[0] )
   printf( "Using %s as blacklist\n", blname );
  if(!delete)
   printf( "Keeping existing files\n" );
  printf( "Press enter to continue or CTRL-C to stop.\n" );
  fflush( stdout );
  while(getc(stdin)!=10);
 }
 if(delete){
  if( getVerbosity() ) printf( "Cleaning %s\n", target );
  clean( target );
  if( getVerbosity() ) {
   printf( "OK\n" );
   fflush( stdout );
  }
 }
 free=freekb( target );
 if ( 0 == mbsize ){
  if( getVerbosity() ) printf( "Size: %li MB\n", free/1024 );
 } else if ( getVerbosity() > 1)
  printf( "Space on device: %liM\n", free/1024 );
 if( getVerbosity() ) printf("Scanning %s for mp3 files ..\n", curdir );
 fflush( stdout );
 list = recurse( curdir, ((void *)0) );
 if( getVerbosity() ){
  printf( "OK\n");
  fflush( stdout );
 }
 if(list == ((void *)0)){
  if( getVerbosity() ) printf ("No music found in %s\n", curdir );
 }else{
  writePlaylist( list, mbsize, target );
 }
 if( getVerbosity() ){
  printf("Done.\n");
  fflush( stdout );
 }
 if( getVerbosity() > 1 ) while(getc(stdin)!=10);
 return 0;
}

canonical_original_code:
int main(int argc, char **argv){
 unsigned long free;
 int delete = -1;
 struct entry_t *list;
 char curdir[256];
 char target[256];
 char blname[256];
 char c;
 int mbsize = 0;
 srand((unsigned int)time(((void *)0)));
 if( ((void *)0) == getcwd( curdir, 256 ) )
  fail( "Could not get current dir!", "", (*__errno_location ()) );
 strcpy( target, "player/" );
 while( ( c = getopt( argc, argv, "s:t:m:nb:v:" ) ) != -1 ) {
  switch( c ) {
  case 's':
   strcpy( curdir, optarg );
   if( ( strlen(curdir) == 2 ) && ( curdir[1] == ':' ) )
    sprintf( curdir, "%s/", curdir );
   else if ( curdir[ strlen( curdir ) -1 ] == '/' )
    curdir[ strlen( curdir ) -1 ] = 0;
   break;
  case 't':
   strcpy( target, optarg );
   if ( target[ strlen( target ) -1 ] != '/' )
    sprintf( target, "%s/", target );
   break;
  case 'm':
   mbsize = atoi( optarg )*1024;
   break;
  case 'b':
   strcpy( blname, optarg );
   loadBlacklist( blname );
   break;
  case 'v':
   setVerbosity(atoi( optarg ));
   break;
  case 'n':
   delete = 0;
   break;
  default:
   usage( argv[0] );
   break;
  }
 }
 if( getVerbosity() > 0 ){
  printf( "Source: %s\n", curdir );
  printf( "Target: %s\n", target );
  if( 0 == mbsize )
   printf( "Filling all space on target\n" );
  else
   printf( "Size  : %i MB\n", mbsize/1024 );
  printf( "Using MP3 files between %i and %i MB\n", 1024/1024, 15*1024/1024 );
  if( 0 != blname[0] )
   printf( "Using %s as blacklist\n", blname );
  if(!delete)
   printf( "Keeping existing files\n" );
  printf( "Press enter to continue or CTRL-C to stop.\n" );
  fflush( stdout );
  while(getc(stdin)!=10);
 }
 if(delete){
  if( getVerbosity() ) printf( "Cleaning %s\n", target );
  clean( target );
  if( getVerbosity() ) {
   printf( "OK\n" );
   fflush( stdout );
  }
 }
 free=freekb( target );
 if ( 0 == mbsize ){
  if( getVerbosity() ) printf( "Size: %li MB\n", free/1024 );
 } else if ( getVerbosity() > 1)
  printf( "Space on device: %liM\n", free/1024 );
 if( getVerbosity() ) printf("Scanning %s for mp3 files ..\n", curdir );
 fflush( stdout );
 list = recurse( curdir, ((void *)0) );
 if( getVerbosity() ){
  printf( "OK\n");
  fflush( stdout );
 }
 if(list == ((void *)0)){
  if( getVerbosity() ) printf ("No music found in %s\n", curdir );
 }else{
  writePlaylist( list, mbsize, target );
 }
 if( getVerbosity() ){
  printf("Done.\n");
  fflush( stdout );
 }
 if( getVerbosity() > 1 ) while(getc(stdin)!=10);
 return 0;
}

variable_types:
free
unsigned long

variable_types: delete int

variable_types:
curdir
char [256]

variable_types:
target
char [256]

variable_types:
blname
char [256]

variable_types: c char

variable_types: mbsize int

user_defined_types: struct entry_t { struct entry_t *prev; unsigned long key; char path[256]; char name[256]; char display[256]; unsigned long size; char artist[256]; int rating; char title[256]; char album[256]; int length; unsigned long played; struct entry_t *next; }


remtitle

decompiled_code:
int __fastcall remtitle(__int64 a1)
{
char v2[264]; // [rsp+0h] [rbp-108h] BYREF

sprintf(v2, "%s/%s", (const char *)(a1 + 16), (const char *)(a1 + 272));
printf("Deleting %s!\n", v2);
removeTitle(a1);
return remove(v2);
}

canonical_decompiled_code:
int __fastcall func1(__int64 a1)
{
char v2[264]; // [rsp+0h] [rbp-108h] BYREF

sprintf(v2, "%s/%s", (const char *)(a1 + 16), (const char *)(a1 + 272));
printf("Deleting %s!\n", v2);
removeTitle(a1);
return remove(v2);
}

original_code:
int remtitle( struct entry_t *title ){
 char path[ 256 ];
 sprintf( path, "%s/%s", title->path, title->name );
 printf("Deleting %s!\n", path );
 removeTitle( title );
 return remove( path ) ;
}

canonical_original_code:
int remtitle(struct entry_t *title){
 char path[256];
 sprintf( path, "%s/%s", title->path, title->name );
 printf("Deleting %s!\n", path );
 removeTitle( title );
 return remove( path ) ;
}

variable_types:
path
char [256]


usage

decompiled_code:
void __fastcall __noreturn usage(const char *a1)
{
printf("%s - find and remove duplicate music files\n", a1);
printf("Usage: %s [-s <sourcedir>] [-t <trigger>] [-r <range>]\n", a1);
puts("-s <path> : set path to directory with music [current dir]");
printf("-r <range> : file size range for similarity [%i]k\n", 10LL);
printf("-t <trigger> : triggervalue for filename similarity [%i]%%\n", 90LL);
exit(0);
}

canonical_decompiled_code:
void __fastcall __noreturn func0(const char *a1)
{
printf("%s - find and remove duplicate music files\n", a1);
printf("Usage: %s [-s <sourcedir>] [-t <trigger>] [-r <range>]\n", a1);
puts("-s <path> : set path to directory with music [current dir]");
printf("-r <range> : file size range for similarity [%i]k\n", 10LL);
printf("-t <trigger> : triggervalue for filename similarity [%i]%%\n", 90LL);
exit(0);
}

original_code:
void usage( char *progname ){
 printf( "%s - find and remove duplicate music files\n", progname );
 printf( "Usage: %s [-s <sourcedir>] [-t <trigger>] [-r <range>]\n", progname );
 printf( "-s <path>    : set path to directory with music [current dir]\n" );
 printf( "-r <range>   : file size range for similarity [%i]k\n", 10 );
 printf( "-t <trigger> : triggervalue for filename similarity [%i]%%\n", 90 );
 exit(0);
}

canonical_original_code:
void usage(char *progname){
 printf( "%s - find and remove duplicate music files\n", progname );
 printf( "Usage: %s [-s <sourcedir>] [-t <trigger>] [-r <range>]\n", progname );
 printf( "-s <path>    : set path to directory with music [current dir]\n" );
 printf( "-r <range>   : file size range for similarity [%i]k\n", 10 );
 printf( "-t <trigger> : triggervalue for filename similarity [%i]%%\n", 90 );
 exit(0);
}


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // er13
int *v4; // rax
size_t v5; // rax
char v6; // al
char *v7; // rsi
void **v8; // rbx
void **v9; // rbp
__int64 v10; // rbx
void **v12; // r12
unsigned int v13; // eax
__int64 v14; // rdx
void **v15; // r12
unsigned int v16; // er12
unsigned int v17; // eax
void **v18; // rbx
int v19; // [rsp+Ch] [rbp-13Ch]
char buf[312]; // [rsp+10h] [rbp-138h] BYREF

if ( !getcwd(buf, 0x100uLL) )
{
v4 = _errno_location();
fail("Could not get current directory!", &unk_627, (unsigned int)*v4);
}
v3 = 10;
v19 = 90;
while ( 1 )
{
v6 = getopt(argc, (char *const *)argv, "s:t:r:");
if ( v6 == -1 )
break;
switch ( v6 )
{
case 's':
strcpy(buf, optarg);
v5 = strlen(buf);
if ( v5 == 2 && buf[1] == 58 )
{
sprintf(buf, "%s/", buf);
}
else if ( *((_BYTE *)&v19 + v5 + 3) == 47 )
{
*((_BYTE *)&v19 + v5 + 3) = 0;
}
break;
case 't':
v19 = atoi(optarg);
break;
case 'r':
v3 = atoi(optarg);
break;
default:
usage(*argv);
}
}
printf("Source: %s\n", buf);
printf("Range: %i KB, Triggervalue: %i\n", (unsigned int)v3, (unsigned int)v19);
printf("Press enter to continue or CTRL-C to stop.");
fflush(stdout);
while ( getc(stdin) != 10 )
;
v7 = 0LL;
v8 = (void **)recurse(buf, 0LL);
puts("Done scanning");
fflush(stdout);
if ( !v8 )
{
v7 = buf;
fail("No music found at ", buf, 0LL);
}
do
{
v9 = v8;
v8 = (void **)*v8;
}
while ( v8 );
v10 = (__int64)v9[197];
if ( v10 )
{
while ( 1 )
{
v14 = (unsigned int)((int)((unsigned int)v9[98] - *(_DWORD *)(v10 + 784)) >> 31);
if ( (int)((v14 ^ ((unsigned int)v9[98] - *(_DWORD *)(v10 + 784))) - v14) < v3 )
{
v7 = (char *)(v10 + 272);
v16 = fncmp(v9 + 34, v10 + 272);
if ( v19 <= (int)v16 )
{
printf("(1) %s/%s\n", (const char *)v9 + 16, (const char *)v9 + 272);
printf("(2) %s/%s\n", (const char *)(v10 + 16), (const char *)(v10 + 272));
v7 = (char *)v16;
printf("(%i/%i) Delete (1/2) or keep? ", v16, abs32((unsigned int)v9[98] - *(_DWORD *)(v10 + 784)));
fflush(stdout);
v17 = getchar();
v14 = v17;
if ( (_BYTE)v17 != 10 )
{
do
{
if ( (_BYTE)v14 == 49 )
{
v12 = (void **)*v9;
if ( *v9 )
{
if ( remtitle((__int64)v9) )
{
v7 = (char *)(v9 + 34);
fail("Could not delete file!", v9 + 34, 0xFFFFFFFFLL);
}
v9 = v12;
}
else
{
v7 = (char *)&unk_627;
fail("Sorry, can't delete first title in list...", &unk_627, 0xFFFFFFFFLL);
}
}
else if ( (_BYTE)v14 == 50 )
{
v15 = *(void ***)v10;
if ( remtitle(v10) )
{
v7 = (char *)(v10 + 272);
fail("Could not delete file!", v10 + 272, 0xFFFFFFFFLL);
}
if ( v15 == v9 )
v15 = (void **)v9[197];
v10 = (__int64)v15;
if ( !v15 )
v10 = (__int64)v9;
}
v13 = getchar();
v14 = v13;
}
while ( (_BYTE)v13 != 10 );
}
}
}
v10 = *(_QWORD *)(v10 + 1576);
if ( !v10 )
{
v18 = (void **)v9[197];
if ( v18 )
{
free(*v18);
*v18 = 0LL;
v9 = v18;
}
activity("Checking", v7, v14);
v10 = (__int64)v9[197];
if ( !v10 )
break;
}
}
}
free(v9);
puts("Done.");
fflush(stdout);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // er13
int *v4; // rax
size_t v5; // rax
char v6; // al
char *v7; // rsi
void **v8; // rbx
void **v9; // rbp
__int64 v10; // rbx
void **v12; // r12
unsigned int v13; // eax
__int64 v14; // rdx
void **v15; // r12
unsigned int v16; // er12
unsigned int v17; // eax
void **v18; // rbx
int v19; // [rsp+Ch] [rbp-13Ch]
char buf[312]; // [rsp+10h] [rbp-138h] BYREF

if ( !getcwd(buf, 0x100uLL) )
{
v4 = _errno_location();
fail("Could not get current directory!", &unk_627, (unsigned int)*v4);
}
v3 = 10;
v19 = 90;
while ( 1 )
{
v6 = getopt(argc, (char *const *)argv, "s:t:r:");
if ( v6 == -1 )
break;
switch ( v6 )
{
case 's':
strcpy(buf, optarg);
v5 = strlen(buf);
if ( v5 == 2 && buf[1] == 58 )
{
sprintf(buf, "%s/", buf);
}
else if ( *((_BYTE *)&v19 + v5 + 3) == 47 )
{
*((_BYTE *)&v19 + v5 + 3) = 0;
}
break;
case 't':
v19 = atoi(optarg);
break;
case 'r':
v3 = atoi(optarg);
break;
default:
func0(*argv);
}
}
printf("Source: %s\n", buf);
printf("Range: %i KB, Triggervalue: %i\n", (unsigned int)v3, (unsigned int)v19);
printf("Press enter to continue or CTRL-C to stop.");
fflush(stdout);
while ( getc(stdin) != 10 )
;
v7 = 0LL;
v8 = (void **)recurse(buf, 0LL);
puts("Done scanning");
fflush(stdout);
if ( !v8 )
{
v7 = buf;
fail("No music found at ", buf, 0LL);
}
do
{
v9 = v8;
v8 = (void **)*v8;
}
while ( v8 );
v10 = (__int64)v9[197];
if ( v10 )
{
while ( 1 )
{
v14 = (unsigned int)((int)((unsigned int)v9[98] - *(_DWORD *)(v10 + 784)) >> 31);
if ( (int)((v14 ^ ((unsigned int)v9[98] - *(_DWORD *)(v10 + 784))) - v14) < v3 )
{
v7 = (char *)(v10 + 272);
v16 = fncmp(v9 + 34, v10 + 272);
if ( v19 <= (int)v16 )
{
printf("(1) %s/%s\n", (const char *)v9 + 16, (const char *)v9 + 272);
printf("(2) %s/%s\n", (const char *)(v10 + 16), (const char *)(v10 + 272));
v7 = (char *)v16;
printf("(%i/%i) Delete (1/2) or keep? ", v16, abs32((unsigned int)v9[98] - *(_DWORD *)(v10 + 784)));
fflush(stdout);
v17 = getchar();
v14 = v17;
if ( (_BYTE)v17 != 10 )
{
do
{
if ( (_BYTE)v14 == 49 )
{
v12 = (void **)*v9;
if ( *v9 )
{
if ( func1((__int64)v9) )
{
v7 = (char *)(v9 + 34);
fail("Could not delete file!", v9 + 34, 0xFFFFFFFFLL);
}
v9 = v12;
}
else
{
v7 = (char *)&unk_627;
fail("Sorry, can't delete first title in list...", &unk_627, 0xFFFFFFFFLL);
}
}
else if ( (_BYTE)v14 == 50 )
{
v15 = *(void ***)v10;
if ( func1(v10) )
{
v7 = (char *)(v10 + 272);
fail("Could not delete file!", v10 + 272, 0xFFFFFFFFLL);
}
if ( v15 == v9 )
v15 = (void **)v9[197];
v10 = (__int64)v15;
if ( !v15 )
v10 = (__int64)v9;
}
v13 = getchar();
v14 = v13;
}
while ( (_BYTE)v13 != 10 );
}
}
}
v10 = *(_QWORD *)(v10 + 1576);
if ( !v10 )
{
v18 = (void **)v9[197];
if ( v18 )
{
free(*v18);
*v18 = 0LL;
v9 = v18;
}
activity("Checking", v7, v14);
v10 = (__int64)v9[197];
if ( !v10 )
break;
}
}
}
free(v9);
puts("Done.");
fflush(stdout);
return 0;
}

original_code:
int main( int argc, char **argv ){
 int result=0;
 int trigger=90;
 int range=10;
 char curdir[256];
 char c;
 struct entry_t *runner, *buff;
 struct entry_t *root=((void *)0);
 if( ((void *)0) == getcwd( curdir, 256 ) )
  fail( "Could not get current directory!", "", (*__errno_location ()));
 while( ( c = getopt( argc, argv, "s:t:r:" ) ) != -1 ) {
  switch( c ) {
  case 's':
   strcpy( curdir, optarg );
   if( ( strlen(curdir) == 2 ) && ( curdir[1] == ':' ) )
    sprintf( curdir, "%s/", curdir );
   else if ( curdir[ strlen( curdir ) -1 ] == '/' )
    curdir[ strlen( curdir ) -1 ] = 0;
   break;
  case 't':
   trigger = atoi( optarg );
   break;
  case 'r':
   range = atoi( optarg );
   break;
  default:
   usage( argv[0] );
   break;
  }
 }
 printf( "Source: %s\n", curdir );
 printf( "Range: %i KB, Triggervalue: %i\n", range, trigger );
 printf( "Press enter to continue or CTRL-C to stop." );
 fflush( stdout );
 while(getc(stdin)!=10);
 root=recurse( curdir, root );
 printf("Done scanning\n");
 fflush( stdout );
 if( ((void *)0) == root ) fail( "No music found at ", curdir, 0 );
 while(((void *)0) != root->prev) root=root->prev;
 while( ((void *)0) != root->next ){
  runner=root->next;
  while( ((void *)0) != runner ){
   if( abs( root->size - runner->size ) < range ){
    result=fncmp( root->name, runner->name );
    if( result >= trigger ){
     printf( "(1) %s/%s\n", root->path, root->name );
     printf( "(2) %s/%s\n", runner->path, runner->name );
     printf( "(%i/%i) Delete (1/2) or keep? ", result, abs( root->size - runner->size ) ); fflush(stdout);
     c=getchar();
     while(c!=10){
      switch(c){
      case '1':
       if( root->prev == ((void *)0) ) fail( "Sorry, can't delete first title in list...", "", -1 );
       else{
        buff=root->prev;
        if(remtitle( root )) fail( "Could not delete file!", root->name, -1 );
        root=buff;
       }
       break;
      case '2':
       buff=runner->prev;
       if(remtitle( runner )) fail( "Could not delete file!", runner->name, -1 );
       runner=buff;
       if( runner == root ) runner=runner->next;
       if( runner == ((void *)0) ) runner=root;
       break;
      }
      c=getchar();
     }
    }
   }
   runner=runner->next;
  }
  if( root->next != ((void *)0) ){
   root=root->next;
   free( root->prev );
   root->prev=((void *)0);
  }
  activity("Checking");
 }
 free( root );
 printf("Done.\n");
 fflush( stdout );
 return 0;
}

canonical_original_code:
int main(int argc, char **argv){
 int result = 0;
 int trigger = 90;
 int range = 10;
 char curdir[256];
 char c;
 struct entry_t *runner; struct entry_t *buff;
 struct entry_t *root = ((void *)0);
 if( ((void *)0) == getcwd( curdir, 256 ) )
  fail( "Could not get current directory!", "", (*__errno_location ()));
 while( ( c = getopt( argc, argv, "s:t:r:" ) ) != -1 ) {
  switch( c ) {
  case 's':
   strcpy( curdir, optarg );
   if( ( strlen(curdir) == 2 ) && ( curdir[1] == ':' ) )
    sprintf( curdir, "%s/", curdir );
   else if ( curdir[ strlen( curdir ) -1 ] == '/' )
    curdir[ strlen( curdir ) -1 ] = 0;
   break;
  case 't':
   trigger = atoi( optarg );
   break;
  case 'r':
   range = atoi( optarg );
   break;
  default:
   usage( argv[0] );
   break;
  }
 }
 printf( "Source: %s\n", curdir );
 printf( "Range: %i KB, Triggervalue: %i\n", range, trigger );
 printf( "Press enter to continue or CTRL-C to stop." );
 fflush( stdout );
 while(getc(stdin)!=10);
 root=recurse( curdir, root );
 printf("Done scanning\n");
 fflush( stdout );
 if( ((void *)0) == root ) fail( "No music found at ", curdir, 0 );
 while(((void *)0) != root->prev) root=root->prev;
 while( ((void *)0) != root->next ){
  runner=root->next;
  while( ((void *)0) != runner ){
   if( abs( root->size - runner->size ) < range ){
    result=fncmp( root->name, runner->name );
    if( result >= trigger ){
     printf( "(1) %s/%s\n", root->path, root->name );
     printf( "(2) %s/%s\n", runner->path, runner->name );
     printf( "(%i/%i) Delete (1/2) or keep? ", result, abs( root->size - runner->size ) ); fflush(stdout);
     c=getchar();
     while(c!=10){
      switch(c){
      case '1':
       if( root->prev == ((void *)0) ) fail( "Sorry, can't delete first title in list...", "", -1 );
       else{
        buff=root->prev;
        if(remtitle( root )) fail( "Could not delete file!", root->name, -1 );
        root=buff;
       }
       break;
      case '2':
       buff=runner->prev;
       if(remtitle( runner )) fail( "Could not delete file!", runner->name, -1 );
       runner=buff;
       if( runner == root ) runner=runner->next;
       if( runner == ((void *)0) ) runner=root;
       break;
      }
      c=getchar();
     }
    }
   }
   runner=runner->next;
  }
  if( root->next != ((void *)0) ){
   root=root->next;
   free( root->prev );
   root->prev=((void *)0);
  }
  activity("Checking");
 }
 free( root );
 printf("Done.\n");
 fflush( stdout );
 return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types: result int

variable_types: trigger int

variable_types: range int

variable_types: struct entry_t { struct entry_t *prev; unsigned long key; char path[256]; char name[256]; char display[256]; unsigned long size; char artist[256]; int rating; char title[256]; char album[256]; int length; unsigned long played; struct entry_t *next; } *