main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // eax

SDL_Init(32LL, argv, envp);
screen = SDL_SetVideoMode(1280LL, 720LL, 32LL, 1LL);
LABEL_2:
generateWorld();
while ( !exitMainLoop )
{
SDL_WaitEvent(&event);
if ( event != 12 )
{
if ( event != 2 )
continue;
v3 = *((_DWORD *)&event + 2);
if ( v3 == 103 )
goto LABEL_2;
if ( v3 != 113 )
continue;
}
exitMainLoop = 1;
break;
}
jesuisdegue = 1;
if ( (unsigned int)registerrpc(536875093LL, 1LL, 1LL, proc_dist, &xdr_game_data) )
{
fwrite("Echec de l'enregistrement\n", 1uLL, 0x1AuLL, stderr);
exit(1);
}
svc_run();
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // eax

SDL_Init(32LL, argv, envp);
screen = SDL_SetVideoMode(1280LL, 720LL, 32LL, 1LL);
LABEL_2:
func3();
while ( !exitMainLoop )
{
SDL_WaitEvent(&event);
if ( event != 12 )
{
if ( event != 2 )
continue;
v3 = *((_DWORD *)&event + 2);
if ( v3 == 103 )
goto LABEL_2;
if ( v3 != 113 )
continue;
}
exitMainLoop = 1;
break;
}
jesuisdegue = 1;
if ( (unsigned int)registerrpc(536875093LL, 1LL, 1LL, proc_dist, &xdr_game_data) )
{
fwrite("Echec de l'enregistrement\n", 1uLL, 0x1AuLL, stderr);
exit(1);
}
svc_run();
return 0;
}

original_code:
int main(void)
{
  bool_t stat;
  SDL_Init(0x00000020);
  screen = SDL_SetVideoMode(1280, 720, 32, 0x00000001);
  generateWorld();
  while( exitMainLoop == 0 ){
    SDL_WaitEvent(&event);
    if (event.type == SDL_QUIT)
      exitMainLoop = 1;
    else if (event.type == SDL_KEYDOWN)
      {
 if (event.key.keysym.sym == SDLK_g)
   generateWorld();
 else if (event.key.keysym.sym == SDLK_q)
   {
     exitMainLoop = 1;
   }
      }
  }
  jesuisdegue = 1;
  stat = registerrpc(0x20001055
         ,1
         ,1
         ,proc_dist
         ,(xdrproc_t)xdr_game_data
         ,(xdrproc_t)xdr_game_data
         );
  if (stat != 0)
    {
      fprintf(stderr,"Echec de l'enregistrement\n");
      exit(1);
    }
  svc_run();
  return 0;
}

canonical_original_code:
int main()
{
  int stat;
  SDL_Init(0x00000020);
  screen = SDL_SetVideoMode(1280, 720, 32, 0x00000001);
  generateWorld();
  while( exitMainLoop == 0 ){
    SDL_WaitEvent(&event);
    if (event.type == SDL_QUIT)
      exitMainLoop = 1;
    else if (event.type == SDL_KEYDOWN)
      {
 if (event.key.keysym.sym == SDLK_g)
   generateWorld();
 else if (event.key.keysym.sym == SDLK_q)
   {
     exitMainLoop = 1;
   }
      }
  }
  jesuisdegue = 1;
  stat = registerrpc(0x20001055
         ,1
         ,1
         ,proc_dist
         ,(int (*)(struct XDR *, void *, ...))xdr_game_data
         ,(int (*)(struct XDR *, void *, ...))xdr_game_data
         );
  if (stat != 0)
    {
      fprintf(stderr,"Echec de l'enregistrement\n");
      exit(1);
    }
  svc_run();
  return 0;
}

variable_types: stat int

user_defined_types: struct XDR { enum xdr_op x_op; struct xdr_ops *x_ops; char *x_public; char *x_private; char *x_base; unsigned int x_handy; }

user_defined_types: enum xdr_op { XDR_ENCODE=0, XDR_DECODE=1, XDR_FREE=2 }

user_defined_types: struct xdr_ops { int (*x_getlong)(struct XDR *__xdrs, long *__lp); int (*x_putlong)(struct XDR *__xdrs, long *__lp); int (*x_getbytes)(struct XDR *__xdrs, char *__addr, unsigned int __len); int (*x_putbytes)(struct XDR *__xdrs, char *__addr, unsigned int __len); unsigned int (*x_getpostn)(struct XDR *__xdrs); int (*x_setpostn)(struct XDR *__xdrs, unsigned int __pos); int *(*x_inline)(struct XDR *__xdrs, unsigned int __len); void (*x_destroy)(struct XDR *__xdrs); int (*x_getint32)(struct XDR *__xdrs, int *__ip); int (*x_putint32)(struct XDR *__xdrs, int *__ip); }


decompiled_code:
bool_t __fastcall xdr_dot2d(XDR *xdrs, int *a2)
{
bool_t result; // eax

result = xdr_int(xdrs, a2);
if ( result )
result = xdr_int(xdrs, a2 + 1) != 0;
return result;
}

canonical_decompiled_code:
bool_t __fastcall func0(XDR *xdrs, int *a2)
{
bool_t result; // eax

result = xdr_int(xdrs, a2);
if ( result )
result = xdr_int(xdrs, a2 + 1) != 0;
return result;
}

original_code:
bool_t xdr_dot2d(XDR *xdrs, t_dot2d *t)
{
  if (!xdr_int(xdrs, &t->x)) return 0;
  if (!xdr_int(xdrs, &t->y)) return 0;
  return 1;
}

canonical_original_code:
int xdr_dot2d(struct XDR *xdrs, struct s_dot2d *t)
{
  if (!xdr_int(xdrs, &t->x)) return 0;
  if (!xdr_int(xdrs, &t->y)) return 0;
  return 1;
}

variable_types: struct XDR { enum xdr_op { XDR_ENCODE=0, XDR_DECODE=1, XDR_FREE=2 } x_op; struct xdr_ops { int (*x_getlong)(struct XDR *__xdrs, long *__lp); int (*x_putlong)(struct XDR *__xdrs, long *__lp); int (*x_getbytes)(struct XDR *__xdrs, char *__addr, unsigned int __len); int (*x_putbytes)(struct XDR *__xdrs, char *__addr, unsigned int __len); unsigned int (*x_getpostn)(struct XDR *__xdrs); int (*x_setpostn)(struct XDR *__xdrs, unsigned int __pos); int *(*x_inline)(struct XDR *__xdrs, unsigned int __len); void (*x_destroy)(struct XDR *__xdrs); int (*x_getint32)(struct XDR *__xdrs, int *__ip); int (*x_putint32)(struct XDR *__xdrs, int *__ip); } *x_ops; char *x_public; char *x_private; char *x_base; unsigned int x_handy; } *

variable_types:
t
struct s_dot2d { int x; int y; } *

return_type: int


decompiled_code:
_BOOL8 __fastcall xdr_obstacle(XDR *a1, void *a2)
{
_BOOL8 result; // rax

if ( xdr_int(a1, (int *)a2) && xdr_dot2d(a1, (int *)a2 + 1) )
result = xdr_dot2d(a1, (int *)a2 + 3) != 0;
else
result = 0LL;
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func1(XDR *a1, void *a2)
{
_BOOL8 result; // rax

if ( xdr_int(a1, (int *)a2) && func0(a1, (int *)a2 + 1) )
result = func0(a1, (int *)a2 + 3) != 0;
else
result = 0LL;
return result;
}

original_code:
bool_t xdr_obstacle(XDR *xdrs, t_xdr_obstacle *t)
{
  if (!xdr_int(xdrs, &t->obsRadius)) return 0;
  if (!xdr_dot2d(xdrs, &t->obsSource)) return 0;
  if (!xdr_dot2d(xdrs, &t->obsCenter)) return 0;
  return 1;
}

canonical_original_code:
int xdr_obstacle(struct XDR *xdrs, struct s_xdr_obstacle *t)
{
  if (!xdr_int(xdrs, &t->obsRadius)) return 0;
  if (!xdr_dot2d(xdrs, &t->obsSource)) return 0;
  if (!xdr_dot2d(xdrs, &t->obsCenter)) return 0;
  return 1;
}

variable_types: struct s_xdr_obstacle { int obsRadius; struct s_dot2d { int x; int y; } obsSource; struct s_dot2d obsCenter; } *

user_defined_types: struct s_xdr_obstacle { int obsRadius; struct s_dot2d obsSource; struct s_dot2d obsCenter; }


decompiled_code:
_BOOL8 __fastcall xdr_door(XDR *xdrs, int *a2)
{
_BOOL8 result; // rax

if ( xdr_int(xdrs, a2) && xdr_int(xdrs, a2 + 1) && xdr_dot2d(xdrs, a2 + 2) )
result = xdr_dot2d(xdrs, a2 + 4) != 0;
else
result = 0LL;
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func2(XDR *xdrs, int *a2)
{
_BOOL8 result; // rax

if ( xdr_int(xdrs, a2) && xdr_int(xdrs, a2 + 1) && func0(xdrs, a2 + 2) )
result = func0(xdrs, a2 + 4) != 0;
else
result = 0LL;
return result;
}

original_code:
bool_t xdr_door(XDR *xdrs, t_xdr_door *t)
{
  if (!xdr_int(xdrs, &t->doorHeight)) return 0;
  if (!xdr_int(xdrs, &t->doorWidth)) return 0;
  if (!xdr_dot2d(xdrs, &t->doorSource)) return 0;
  if (!xdr_dot2d(xdrs, &t->doorCenter)) return 0;
  return 1;
}

canonical_original_code:
int xdr_door(struct XDR *xdrs, struct s_xdr_door *t)
{
  if (!xdr_int(xdrs, &t->doorHeight)) return 0;
  if (!xdr_int(xdrs, &t->doorWidth)) return 0;
  if (!xdr_dot2d(xdrs, &t->doorSource)) return 0;
  if (!xdr_dot2d(xdrs, &t->doorCenter)) return 0;
  return 1;
}

variable_types: struct s_xdr_door { int doorHeight; int doorWidth; struct s_dot2d { int x; int y; } doorSource; struct s_dot2d doorCenter; } *

user_defined_types: struct s_xdr_door { int doorHeight; int doorWidth; struct s_dot2d doorSource; struct s_dot2d doorCenter; }


decompiled_code:
_BOOL8 __fastcall xdr_person(XDR *xdrs, u_int *sizep)
{
if ( !xdr_int(xdrs, (int *)sizep) || !xdr_int(xdrs, (int *)sizep + 1) )
return 0LL;
if ( jesuisdegue == 1 )
*((_QWORD *)sizep + 1) = malloc(4LL * (int)*sizep);
return xdr_array(xdrs, (caddr_t *)sizep + 1, sizep, 0xBB8u, 4u, (xdrproc_t)&xdr_int) != 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func3(XDR *xdrs, u_int *sizep)
{
if ( !xdr_int(xdrs, (int *)sizep) || !xdr_int(xdrs, (int *)sizep + 1) )
return 0LL;
if ( jesuisdegue == 1 )
*((_QWORD *)sizep + 1) = malloc(4LL * (int)*sizep);
return xdr_array(xdrs, (caddr_t *)sizep + 1, sizep, 0xBB8u, 4u, (xdrproc_t)&xdr_int) != 0;
}

original_code:
bool_t xdr_person(XDR *xdrs, t_person *t)
{
  if (!xdr_int(xdrs, &t->current)) return 0;
  if (!xdr_int(xdrs, &t->mark)) return 0;
  if(jesuisdegue == 1)
    t->path = malloc(t->current*sizeof(int));
  if (!xdr_array(xdrs
   ,(char**)&t->path
   ,&t->current
   ,3000
   ,sizeof (int)
   ,(xdrproc_t)xdr_int))
    return 0;
  return 1;
}

canonical_original_code:
int xdr_person(struct XDR *xdrs, struct s_person *t)
{
  if (!xdr_int(xdrs, &t->current)) return 0;
  if (!xdr_int(xdrs, &t->mark)) return 0;
  if(jesuisdegue == 1)
    t->path = malloc(t->current*sizeof(int));
  if (!xdr_array(xdrs
   ,(char **)&t->path
   ,&t->current
   ,3000
   ,sizeof (int)
   ,(int (*)(struct XDR *, void *, ...))xdr_int))
    return 0;
  return 1;
}

variable_types: struct s_person { int current; int mark; enum e_direction { Left=0, Right=1, Up=2, Down=3, UpLeft=4, DownLeft=5, UpRight=6, DownRight=7 } *path; } *

user_defined_types: struct s_person { int current; int mark; enum e_direction *path; }


decompiled_code:
_BOOL8 __fastcall xdr_game_data(XDR *xdrs, __int64 a2)
{
_BOOL8 result; // rax
int v3; // edx

if ( !xdr_int(xdrs, (int *)a2) || !xdr_int(xdrs, (int *)(a2 + 4)) || !xdr_int(xdrs, (int *)(a2 + 8)) )
return 0LL;
v3 = *(_DWORD *)a2;
result = 1LL;
if ( !*(_DWORD *)a2 )
return result;
if ( v3 != 1 )
{
if ( (unsigned int)(v3 - 2) <= 1 )
result = xdr_person(xdrs, (u_int *)(a2 + 48));
return result;
}
if ( !xdr_door(xdrs, (int *)(a2 + 12)) )
return 0LL;
if ( !*(_QWORD *)(a2 + 40) )
*(_QWORD *)(a2 + 40) = malloc(20LL * *(int *)(a2 + 8));
return xdr_array(xdrs, (caddr_t *)(a2 + 40), (u_int *)(a2 + 8), 0xFu, 0x14u, (xdrproc_t)xdr_obstacle) != 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func4(XDR *xdrs, __int64 a2)
{
_BOOL8 result; // rax
int v3; // edx

if ( !xdr_int(xdrs, (int *)a2) || !xdr_int(xdrs, (int *)(a2 + 4)) || !xdr_int(xdrs, (int *)(a2 + 8)) )
return 0LL;
v3 = *(_DWORD *)a2;
result = 1LL;
if ( !*(_DWORD *)a2 )
return result;
if ( v3 != 1 )
{
if ( (unsigned int)(v3 - 2) <= 1 )
result = func3(xdrs, (u_int *)(a2 + 48));
return result;
}
if ( !func2(xdrs, (int *)(a2 + 12)) )
return 0LL;
if ( !*(_QWORD *)(a2 + 40) )
*(_QWORD *)(a2 + 40) = malloc(20LL * *(int *)(a2 + 8));
return xdr_array(xdrs, (caddr_t *)(a2 + 40), (u_int *)(a2 + 8), 0xFu, 0x14u, (xdrproc_t)xdr_obstacle) != 0;
}

original_code:
bool_t xdr_game_data(XDR *xdrs, t_game_data *t)
{
  if (!xdr_int(xdrs, &t->flag)) return 0;
  if (!xdr_int(xdrs, &t->idClient)) return 0;
  if (!xdr_int(xdrs, &t->size)) return 0;
  if (t->flag == 0)
    {
      return 1;
    }
  else if (t->flag == 1)
    {
      if(!xdr_door(xdrs, &t->door)) return 0;
      if(t->tabObs == ((void *)0))
  t->tabObs = malloc(t->size*(sizeof (struct s_xdr_obstacle)));
      if (!xdr_array(xdrs
       ,(char**)&t->tabObs
       ,&t->size
       ,15
       ,sizeof (struct s_xdr_obstacle)
       ,(xdrproc_t)xdr_obstacle))
 return 0;
    }
  else if(t->flag==2 || t->flag==3)
    {
      if(!xdr_person(xdrs, &t->person)) return 0;
    }
  return 1;
}

canonical_original_code:
int xdr_game_data(struct XDR *xdrs, struct s_game_data *t)
{
  if (!xdr_int(xdrs, &t->flag)) return 0;
  if (!xdr_int(xdrs, &t->idClient)) return 0;
  if (!xdr_int(xdrs, &t->size)) return 0;
  if (t->flag == 0)
    {
      return 1;
    }
  else if (t->flag == 1)
    {
      if(!xdr_door(xdrs, &t->door)) return 0;
      if(t->tabObs == ((void *)0))
  t->tabObs = malloc(t->size*(sizeof (struct s_xdr_obstacle)));
      if (!xdr_array(xdrs
       ,(char **)&t->tabObs
       ,&t->size
       ,15
       ,sizeof (struct s_xdr_obstacle)
       ,(int (*)(struct XDR *, void *, ...))xdr_obstacle))
 return 0;
    }
  else if(t->flag==2 || t->flag==3)
    {
      if(!xdr_person(xdrs, &t->person)) return 0;
    }
  return 1;
}

variable_types: struct s_game_data { int flag; int idClient; int size; struct s_xdr_door { int doorHeight; int doorWidth; struct s_dot2d { int x; int y; } doorSource; struct s_dot2d doorCenter; } door; struct s_xdr_obstacle { int obsRadius; struct s_dot2d obsSource; struct s_dot2d obsCenter; } *tabObs; struct s_person { int current; int mark; enum e_direction { Left=0, Right=1, Up=2, Down=3, UpLeft=4, DownLeft=5, UpRight=6, DownRight=7 } *path; } person; } *

user_defined_types: struct s_game_data { int flag; int idClient; int size; struct s_xdr_door door; struct s_xdr_obstacle *tabObs; struct s_person person; }


distance

decompiled_code:
void __fastcall distance(int a1, int a2, int a3, int a4)
{
double v4; // xmm0_8

v4 = (double)(a4 - a2) * (double)(a4 - a2) + (double)(a3 - a1) * (double)(a3 - a1);
if ( v4 < 0.0 )
sqrt(v4);
}

canonical_decompiled_code:
void __fastcall func0(int a1, int a2, int a3, int a4)
{
double v4; // xmm0_8

v4 = (double)(a4 - a2) * (double)(a4 - a2) + (double)(a3 - a1) * (double)(a3 - a1);
if ( v4 < 0.0 )
sqrt(v4);
}

original_code:
double distance(int x1, int y1, int x2, int y2)
{
  return sqrt( pow( x2 - x1, 2 ) + pow( y2 - y1, 2 ) );
}

return_type: double


foo

decompiled_code:
__int64 __fastcall foo(_DWORD *a1, _DWORD *a2)
{
return (unsigned int)(*a2 * *a1);
}

canonical_decompiled_code:
__int64 __fastcall func7(_DWORD *a1, _DWORD *a2)
{
return (unsigned int)(*a2 * *a1);
}

original_code:
int foo(int *a, int *b) {
 return (*a)*(*b);
}

variable_types:
a
int *

variable_types:
b
int *


bar

decompiled_code:
__int64 __fastcall bar(_DWORD *a1, _DWORD *a2)
{
return (unsigned int)(*a1 - *a2);
}

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

original_code:
int bar(int *a, int *b) {
 return (*a)-(*b);
}


baz

decompiled_code:
__int64 __fastcall baz(_DWORD *a1, _DWORD *a2)
{
return (unsigned int)(*a1 + *a2);
}

canonical_decompiled_code:
__int64 __fastcall func9(_DWORD *a1, _DWORD *a2)
{
return (unsigned int)(*a1 + *a2);
}

original_code:
int baz(int *a, int *b) {
 return (*a)+(*b);
}


work

decompiled_code:
__int64 __fastcall work(_DWORD *a1, _DWORD *a2)
{
_DWORD *v2; // rdx
_DWORD *v3; // rsi
_DWORD *v4; // r8
int v5; // eax
int v6; // edx

foo(a1, a2);
v3 = v2;
bar(a1, v2);
v5 = baz(v4, v3);
return (unsigned int)(v6 * v5);
}

canonical_decompiled_code:
__int64 __fastcall func10(_DWORD *a1, _DWORD *a2)
{
_DWORD *v2; // rdx
_DWORD *v3; // rsi
_DWORD *v4; // r8
int v5; // eax
int v6; // edx

func7(a1, a2);
v3 = v2;
func8(a1, v2);
v5 = func9(v4, v3);
return (unsigned int)(v6 * v5);
}

original_code:
int work(int *a, int *b, int *c) {
 return foo(a,b)*bar(a,c)*baz(b,c);
}

variable_types:
c
int *


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // eax
int v5; // [rsp+8h] [rbp-10h] BYREF
int v6[3]; // [rsp+Ch] [rbp-Ch] BYREF

v5 = 1;
v6[0] = 2;
v3 = work(&v5, v6, 0LL);
printf("res = %d\n", v3);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // eax
int v5; // [rsp+8h] [rbp-10h] BYREF
int v6[3]; // [rsp+Ch] [rbp-Ch] BYREF

v5 = 1;
v6[0] = 2;
v3 = func10(&v5, v6, 0LL);
printf("res = %d\n", v3);
return 0;
}

original_code:
int main() {
 int a, b, c;
 a = 1;
 b = 2;
 c = 3;
 int *x, *y,* z;
 x = &a;
 y = &b;
 z = 0;
 int res = work(x, y, z);
 printf("res = %d\n", res);
 return 0;
}

canonical_original_code:
int main() {
 int a; int b; int c;
 a = 1;
 b = 2;
 c = 3;
 int *x; int *y; int *z;
 x = &a;
 y = &b;
 z = 0;
 int res = work(x, y, z);
 printf("res = %d\n", res);
 return 0;
}

variable_types: a int

variable_types: b int

variable_types: c int

variable_types:
x
int *

variable_types:
y
int *

variable_types:
z
int *

variable_types: res int


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // eax
unsigned __int8 v5; // [rsp+Fh] [rbp-9h]

v3 = API_ControlBuzzer();
printf("result:%02x buffer:%02x\n", v3, v5);
return 0;
}

original_code:
int main()
{
 unsigned char buffer;
 int result;
 result = API_ControlBuzzer(0x0a,0x0a,&buffer);
 printf("result:%02x buffer:%02x\n",result,buffer);
 return 0;
}

variable_types:
buffer
unsigned char

variable_types: result int


repo: SingingBush/armpit

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

puts("\nStarting ARMpit...\n");
while ( 1 )
{
v3 = getopt(argc, (char *const *)argv, "f:vh");
if ( v3 == -1 )
break;
if ( v3 == 104 )
{
displayUsage();
exit(0);
}
if ( v3 > 104 )
{
if ( v3 == 118 )
VERBOSE = 1;
}
else
{
if ( v3 == 63 )
{
displayUsage();
exit(1);
}
if ( v3 == 102 )
{
fileName = (__int64)optarg;
file = (__int64)fopen(optarg, "r");
if ( file )
{
puts("\n\tAT THIS TIME INPUT FILES ARE UNSUPPORTED\n");
exit(1);
}
printf("Error opening %s\n", (const char *)fileName);
exit(1);
}
}
}
v4 = "true";
if ( !VERBOSE )
v4 = "false";
printf("Verbose Logging: %s\n", v4);
v5 = (const char *)fileName;
if ( !fileName )
v5 = "none";
v6 = 0;
printf("Input File: %s\n\n", v5);
init();
v7 = *(_DWORD *)PROGRAM_COUNTER;
while ( (int)v6 < v7 )
{
v8 = (unsigned int)fetchInstruction();
if ( (unsigned __int8)shouldExecute(v8) )
{
v9 = getInstructionType((unsigned int)v8);
if ( v9 == 2 )
{
doDataTransfer();
}
else if ( v9 > 2 )
{
if ( v9 == 3 )
doInterupt();
}
else if ( v9 )
{
doBranch();
}
else
{
doDataProcessing((unsigned int)v8);
}
}
else if ( VERBOSE )
{
printf("\tInstruction %i skipped!\n", v6);
}
++v6;
puts("\nPress Enter key to continue");
getchar();
}
puts("\nExiting program\n");
exit(0);
}

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

puts("\nStarting ARMpit...\n");
while ( 1 )
{
v3 = getopt(argc, (char *const *)argv, "f:vh");
if ( v3 == -1 )
break;
if ( v3 == 104 )
{
func7();
exit(0);
}
if ( v3 > 104 )
{
if ( v3 == 118 )
VERBOSE = 1;
}
else
{
if ( v3 == 63 )
{
func7();
exit(1);
}
if ( v3 == 102 )
{
fileName = (__int64)optarg;
file = (__int64)fopen(optarg, "r");
if ( file )
{
puts("\n\tAT THIS TIME INPUT FILES ARE UNSUPPORTED\n");
exit(1);
}
printf("Error opening %s\n", (const char *)fileName);
exit(1);
}
}
}
v4 = "true";
if ( !VERBOSE )
v4 = "false";
printf("Verbose Logging: %s\n", v4);
v5 = (const char *)fileName;
if ( !fileName )
v5 = "none";
v6 = 0;
printf("Input File: %s\n\n", v5);
func8();
v7 = *(_DWORD *)PROGRAM_COUNTER;
while ( (int)v6 < v7 )
{
v8 = (unsigned int)func9();
if ( (unsigned __int8)func16(v8) )
{
v9 = func10((unsigned int)v8);
if ( v9 == 2 )
{
func21();
}
else if ( v9 > 2 )
{
if ( v9 == 3 )
func22();
}
else if ( v9 )
{
func20();
}
else
{
func19((unsigned int)v8);
}
}
else if ( VERBOSE )
{
printf("\tInstruction %i skipped!\n", v6);
}
++v6;
puts("\nPress Enter key to continue");
getchar();
}
puts("\nExiting program\n");
exit(0);
}

original_code:
int main(int argc, char *argv[]) {
    printf("\nStarting ARMpit...\n\n");
    int opt = getopt( argc, argv, optString );
    while( opt != -1 ) {
        switch( opt ) {
            case 'f':
                fileName = optarg;
                file = fopen(fileName, "r");
                if(file == ((void *)0)) {
                    printf("Error opening %s\n", fileName);
                    exit(1);
                }
                printf("\n\tAT THIS TIME INPUT FILES ARE UNSUPPORTED\n\n");
                exit(1);
                break;
            case 'v':
                VERBOSE = 1;
                break;
            case 'h':
                displayUsage();
                exit(0);
                break;
            case '?':
                displayUsage();
                exit(1);
                break;
        }
        opt = getopt( argc, argv, optString );
    }
    printf("Verbose Logging: %s\n", VERBOSE? "true" : "false");
    printf("Input File: %s\n\n", fileName? fileName : "none");
    init();
    INSTRUCTION instruction;
    int amountOfInstructions = *PROGRAM_COUNTER;
    for(int counter = 0; counter < amountOfInstructions; counter++) {
        instruction = fetchInstruction();
        if(shouldExecute(instruction)) {
            InstructionType type = getInstructionType(instruction);
            switch(type) {
                case ALU:
                    doDataProcessing(instruction);
                    break;
                case BRANCH:
                    doBranch();
                    break;
                case DATA_TRANSFER:
                    doDataTransfer();
                    break;
                case INTERUPT:
                    doInterupt();
                    break;
            }
        } else {
            if(VERBOSE) {
                printf("\tInstruction %i skipped!\n", counter);
            }
        }
        printf("\nPress Enter key to continue\n");
        getchar();
    }
    printf("\nExiting program\n\n");
    exit(0);
}

canonical_original_code:
int main(int argc, char *argv[]) {
    printf("\nStarting ARMpit...\n\n");
    int opt = getopt( argc, argv, optString );
    while( opt != -1 ) {
        switch( opt ) {
            case 'f':
                fileName = optarg;
                file = fopen(fileName, "r");
                if(file == ((void *)0)) {
                    printf("Error opening %s\n", fileName);
                    exit(1);
                }
                printf("\n\tAT THIS TIME INPUT FILES ARE UNSUPPORTED\n\n");
                exit(1);
                break;
            case 'v':
                VERBOSE = 1;
                break;
            case 'h':
                displayUsage();
                exit(0);
                break;
            case '?':
                displayUsage();
                exit(1);
                break;
        }
        opt = getopt( argc, argv, optString );
    }
    printf("Verbose Logging: %s\n", VERBOSE? "true" : "false");
    printf("Input File: %s\n\n", fileName? fileName : "none");
    init();
    union INSTRUCTION instruction;
    int amountOfInstructions = *PROGRAM_COUNTER;
    for(int counter = 0; counter < amountOfInstructions; counter++) {
        instruction = fetchInstruction();
        if(shouldExecute(instruction)) {
            enum InstructionType type = getInstructionType(instruction);
            switch(type) {
                case ALU:
                    doDataProcessing(instruction);
                    break;
                case BRANCH:
                    doBranch();
                    break;
                case DATA_TRANSFER:
                    doDataTransfer();
                    break;
                case INTERUPT:
                    doInterupt();
                    break;
            }
        } else {
            if(VERBOSE) {
                printf("\tInstruction %i skipped!\n", counter);
            }
        }
        printf("\nPress Enter key to continue\n");
        getchar();
    }
    printf("\nExiting program\n\n");
    exit(0);
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: opt int

variable_types: union INSTRUCTION { unsigned int data32; unsigned char byte[4]; }

variable_types: amountOfInstructions int

variable_types: counter int

variable_types: enum InstructionType { ALU=0, BRANCH=1, DATA_TRANSFER=2, INTERUPT=3 }


displayUsage

decompiled_code:
int displayUsage()
{
return puts(USAGE);
}

canonical_decompiled_code:
int func7()
{
return puts(USAGE);
}

original_code:
void displayUsage() {
 puts(USAGE);
}

canonical_original_code:
void displayUsage() {
 puts(USAGE);
}

return_type: void


init

decompiled_code:
_DWORD *init()
{
STATUS_REGISTER = 0;
*(_DWORD *)LINK_REGISTER = 0;
*(_DWORD *)STACK_POINTER = 0;
*(_DWORD *)PROGRAM_COUNTER = 0;
loadInstruction(0xE3A00001);
loadInstruction(0xF0000000);
loadInstruction(0xE4000000);
loadInstruction(0xE8000000);
loadInstruction(0xEF000000);
loadInstruction(0xE3F3FA02);
loadInstruction(0xE0802001);
return loadInstruction(0xE2822001);
}

canonical_decompiled_code:
_DWORD *func8()
{
STATUS_REGISTER = 0;
*(_DWORD *)LINK_REGISTER = 0;
*(_DWORD *)STACK_POINTER = 0;
*(_DWORD *)PROGRAM_COUNTER = 0;
loadInstruction(0xE3A00001);
loadInstruction(0xF0000000);
loadInstruction(0xE4000000);
loadInstruction(0xE8000000);
loadInstruction(0xEF000000);
loadInstruction(0xE3F3FA02);
loadInstruction(0xE0802001);
return loadInstruction(0xE2822001);
}

original_code:
void init() {
    STATUS_REGISTER = 0;
    *LINK_REGISTER = 0;
    *STACK_POINTER = 0;
    *PROGRAM_COUNTER = 0;
    INSTRUCTION instruction;
    instruction.data32 = 0xE3A00001;
    loadInstruction(instruction);
    instruction.data32 = 0xF0000000;
    loadInstruction(instruction);
    instruction.data32 = 0xE4000000;
    loadInstruction(instruction);
    instruction.data32 = 0xE8000000;
    loadInstruction(instruction);
    instruction.data32 = 0xEF000000;
    loadInstruction(instruction);
    instruction.data32 = 0xE3f3fa02;
    loadInstruction(instruction);
    instruction.data32 = 0xE0802001;
    loadInstruction(instruction);
    instruction.data32 = 0xE2822001;
    loadInstruction(instruction);
}

canonical_original_code:
void init() {
    STATUS_REGISTER = 0;
    *LINK_REGISTER = 0;
    *STACK_POINTER = 0;
    *PROGRAM_COUNTER = 0;
    union INSTRUCTION instruction;
    instruction.data32 = 0xE3A00001;
    loadInstruction(instruction);
    instruction.data32 = 0xF0000000;
    loadInstruction(instruction);
    instruction.data32 = 0xE4000000;
    loadInstruction(instruction);
    instruction.data32 = 0xE8000000;
    loadInstruction(instruction);
    instruction.data32 = 0xEF000000;
    loadInstruction(instruction);
    instruction.data32 = 0xE3f3fa02;
    loadInstruction(instruction);
    instruction.data32 = 0xE0802001;
    loadInstruction(instruction);
    instruction.data32 = 0xE2822001;
    loadInstruction(instruction);
}

user_defined_types: union INSTRUCTION { unsigned int data32; unsigned char byte[4]; }


fetchInstruction

decompiled_code:
__int64 fetchInstruction()
{
__int64 v0; // rdx
unsigned int v1; // er12

v0 = (unsigned int)(*(_DWORD *)PROGRAM_COUNTER - 1);
*(_DWORD *)PROGRAM_COUNTER = v0;
v1 = memory[v0];
printf("\n\tFetching instruction: %04X from position %i\n", v1, v0);
return v1;
}

canonical_decompiled_code:
__int64 func9()
{
__int64 v0; // rdx
unsigned int v1; // er12

v0 = (unsigned int)(*(_DWORD *)PROGRAM_COUNTER - 1);
*(_DWORD *)PROGRAM_COUNTER = v0;
v1 = memory[v0];
printf("\n\tFetching instruction: %04X from position %i\n", v1, v0);
return v1;
}

original_code:
INSTRUCTION fetchInstruction() {
    if(PROGRAM_COUNTER > 0)
        (*PROGRAM_COUNTER)--;
    INSTRUCTION instruction = memory[*PROGRAM_COUNTER];
    printf("\n\tFetching instruction: %04X from position %i\n", instruction.data32, *PROGRAM_COUNTER);
    return instruction;
}

canonical_original_code:
union INSTRUCTION fetchInstruction() {
    if(PROGRAM_COUNTER > 0)
        (*PROGRAM_COUNTER)--;
    union INSTRUCTION instruction = memory[*PROGRAM_COUNTER];
    printf("\n\tFetching instruction: %04X from position %i\n", instruction.data32, *PROGRAM_COUNTER);
    return instruction;
}

return_type: union INSTRUCTION { unsigned int data32; unsigned char byte[4]; }


getInstructionType

decompiled_code:
__int64 __fastcall getInstructionType(unsigned int a1)
{
unsigned int v1; // edi
__int64 v2; // rax
const char *v3; // rdx

v1 = a1 >> 26;
if ( VERBOSE )
{
v2 = (v1 & 3) - 1;
v3 = "ALU";
if ( (unsigned int)v2 <= 2 )
v3 = (const char *)*(&CSWTCH_46 + v2);
printf("\tInstruction is type %d:\t%s\n", v1 & 3, v3);
}
return v1 & 3;
}

canonical_decompiled_code:
__int64 __fastcall func10(unsigned int a1)
{
unsigned int v1; // edi
__int64 v2; // rax
const char *v3; // rdx

v1 = a1 >> 26;
if ( VERBOSE )
{
v2 = (v1 & 3) - 1;
v3 = "ALU";
if ( (unsigned int)v2 <= 2 )
v3 = (const char *)*(&CSWTCH_46 + v2);
printf("\tInstruction is type %d:\t%s\n", v1 & 3, v3);
}
return v1 & 3;
}

original_code:
InstructionType getInstructionType(INSTRUCTION instruction) {
    InstructionType type;
    type = (instruction.data32 >> 26) & 0X3;
    if(VERBOSE) {
        char *typeName;
        switch(type) {
            case ALU: typeName = "ALU"; break;
            case BRANCH: typeName = "Branch"; break;
            case DATA_TRANSFER: typeName = "Data Transfer"; break;
            case INTERUPT: typeName = "Interupt"; break;
        }
        printf("\tInstruction is type %d:\t%s\n", type, typeName);
    }
    return type;
}

canonical_original_code:
enum InstructionType getInstructionType(union INSTRUCTION instruction) {
    enum InstructionType type;
    type = (instruction.data32 >> 26) & 0X3;
    if(VERBOSE) {
        char *typeName;
        switch(type) {
            case ALU: typeName = "ALU"; break;
            case BRANCH: typeName = "Branch"; break;
            case DATA_TRANSFER: typeName = "Data Transfer"; break;
            case INTERUPT: typeName = "Interupt"; break;
        }
        printf("\tInstruction is type %d:\t%s\n", type, typeName);
    }
    return type;
}

variable_types:
typeName
char *

return_type: enum InstructionType { ALU=0, BRANCH=1, DATA_TRANSFER=2, INTERUPT=3 }


isImmediateValue

decompiled_code:
__int64 __fastcall isImmediateValue(unsigned int a1)
{
unsigned int v1; // edi
const char *v2; // rsi

v1 = a1 >> 25;
v2 = "not set" + 4;
if ( (v1 & 1) == 0 )
v2 = "not set";
printf("\tImmediate Bit:\t%s \n", v2);
return v1 & 1;
}

canonical_decompiled_code:
__int64 __fastcall func11(unsigned int a1)
{
unsigned int v1; // edi
const char *v2; // rsi

v1 = a1 >> 25;
v2 = "not set" + 4;
if ( (v1 & 1) == 0 )
v2 = "not set";
printf("\tImmediate Bit:\t%s \n", v2);
return v1 & 1;
}

original_code:
_Bool isImmediateValue(INSTRUCTION instruction) {
    _Bool immediate = (instruction.data32 >> 25) & 0X1;
    printf("\tImmediate Bit:\t%s \n", immediate? "set" : "not set");
    return immediate;
}

canonical_original_code:
_Bool isImmediateValue(union INSTRUCTION instruction) {
    _Bool immediate = (instruction.data32 >> 25) & 0X1;
    printf("\tImmediate Bit:\t%s \n", immediate? "set" : "not set");
    return immediate;
}


statusBitSet

decompiled_code:
__int64 __fastcall statusBitSet(unsigned int a1)
{
unsigned int v1; // edi
const char *v2; // rsi

v1 = a1 >> 20;
v2 = "not set" + 4;
if ( (v1 & 1) == 0 )
v2 = "not set";
printf("\tStatus Bit:\t%s \n", v2);
return v1 & 1;
}

canonical_decompiled_code:
__int64 __fastcall func12(unsigned int a1)
{
unsigned int v1; // edi
const char *v2; // rsi

v1 = a1 >> 20;
v2 = "not set" + 4;
if ( (v1 & 1) == 0 )
v2 = "not set";
printf("\tStatus Bit:\t%s \n", v2);
return v1 & 1;
}

original_code:
_Bool statusBitSet(INSTRUCTION instruction) {
    _Bool updateStatus = (instruction.data32 >> 20) & 0X1;
    printf("\tStatus Bit:\t%s \n", updateStatus? "set" : "not set");
    return updateStatus;
}

canonical_original_code:
_Bool statusBitSet(union INSTRUCTION instruction) {
    _Bool updateStatus = (instruction.data32 >> 20) & 0X1;
    printf("\tStatus Bit:\t%s \n", updateStatus? "set" : "not set");
    return updateStatus;
}


getRegister

decompiled_code:
__int64 __fastcall getRegister(unsigned int a1, char a2)
{
unsigned int v2; // ebx

v2 = (a1 >> a2) & 0xF;
printf("\tRegister:\t%i \n", v2);
return (unsigned int)registers[v2];
}

canonical_decompiled_code:
__int64 __fastcall func13(unsigned int a1, char a2)
{
unsigned int v2; // ebx

v2 = (a1 >> a2) & 0xF;
printf("\tRegister:\t%i \n", v2);
return (unsigned int)registers[v2];
}

original_code:
REGISTER getRegister(INSTRUCTION instruction, int shiftAmount) {
    int regNo = (instruction.data32 >> shiftAmount) & 0Xf;
    printf("\tRegister:\t%i \n", regNo);
    return registers[regNo];
}

canonical_original_code:
unsigned int getRegister(union INSTRUCTION instruction, int shiftAmount) {
    int regNo = (instruction.data32 >> shiftAmount) & 0Xf;
    printf("\tRegister:\t%i \n", regNo);
    return registers[regNo];
}

variable_types: shiftAmount int

variable_types: regNo int

return_type: unsigned int


isSet

decompiled_code:
__int64 __fastcall isSet(char a1)
{
return (unsigned __int8)(a1 & STATUS_REGISTER);
}

canonical_decompiled_code:
__int64 __fastcall func14(char a1)
{
return (unsigned __int8)(a1 & STATUS_REGISTER);
}

original_code:
int isSet(int flag) {
    return (STATUS_REGISTER & flag);
}

variable_types: flag int


isClear

decompiled_code:
__int64 __fastcall isClear(int a1)
{
return a1 & ~(unsigned __int8)STATUS_REGISTER;
}

canonical_decompiled_code:
__int64 __fastcall func15(int a1)
{
return a1 & ~(unsigned __int8)STATUS_REGISTER;
}

original_code:
int isClear(int flag) {
    return ((~STATUS_REGISTER) & flag);
}


shouldExecute

decompiled_code:
__int64 __fastcall shouldExecute(unsigned int a1)
{
unsigned int v1; // er12
unsigned int v2; // ecx
__int64 v3; // rdx
const char *v4; // rsi
char v6; // cl

v2 = (unsigned __int8)VERBOSE;
v3 = a1;
if ( a1 <= 0xEFFFFFFF )
{
switch ( a1 >> 28 )
{
case 0u:
goto LABEL_13;
case 1u:
goto LABEL_23;
case 2u:
LOBYTE(v1) = (unsigned int)isSet(32) != 0;
goto LABEL_14;
case 3u:
LOBYTE(v1) = (unsigned int)isClear(32) != 0;
goto LABEL_14;
case 4u:
LOBYTE(v1) = (unsigned int)isSet(128) != 0;
goto LABEL_14;
case 5u:
LOBYTE(v1) = (unsigned int)isClear(128) != 0;
goto LABEL_14;
case 6u:
goto LABEL_19;
case 7u:
LOBYTE(v1) = (unsigned int)isClear(16) != 0;
goto LABEL_14;
case 8u:
if ( !(unsigned int)isSet(32) )
goto LABEL_4;
goto LABEL_23;
case 9u:
if ( !(unsigned int)isClear(32) )
goto LABEL_4;
goto LABEL_13;
case 0xAu:
if ( (unsigned int)isClear(128) && (unsigned int)isClear(16) )
goto LABEL_10;
if ( !(unsigned int)isSet(128) )
goto LABEL_4;
goto LABEL_19;
case 0xBu:
if ( (unsigned int)isSet(128) && (unsigned int)isClear(16) )
goto LABEL_10;
if ( !(unsigned int)isClear(128) )
goto LABEL_4;
LABEL_19:
LOBYTE(v1) = (unsigned int)isSet(16) != 0;
goto LABEL_14;
case 0xCu:
if ( (unsigned int)isClear(128) && (unsigned int)isClear(16) && (unsigned int)isClear(64) )
goto LABEL_10;
if ( !(unsigned int)isSet(128) || !(unsigned int)isSet(16) )
goto LABEL_4;
LABEL_23:
LOBYTE(v1) = (unsigned int)isClear(64) != 0;
LABEL_14:
if ( !v6 )
return v1;
v4 = "false";
if ( (_BYTE)v1 )
v4 = "true";
break;
case 0xDu:
if ( (unsigned int)isSet(128) && (unsigned int)isClear(16)
|| (unsigned int)isClear(128) && (unsigned int)isSet(16) )
{
goto LABEL_10;
}
LABEL_13:
LOBYTE(v1) = (unsigned int)isSet(64) != 0;
goto LABEL_14;
case 0xEu:
LABEL_10:
v1 = 1;
if ( !(_BYTE)v2 )
return v1;
v1 = v2;
v4 = "true";
goto LABEL_6;
}
goto LABEL_6;
}
LABEL_4:
v1 = 0;
if ( (_BYTE)v2 )
{
v4 = "false";
LABEL_6:
printf("\tshould execute?: %s - %04X\n", v4, v3);
}
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func16(unsigned int a1)
{
unsigned int v1; // er12
unsigned int v2; // ecx
__int64 v3; // rdx
const char *v4; // rsi
char v6; // cl

v2 = (unsigned __int8)VERBOSE;
v3 = a1;
if ( a1 <= 0xEFFFFFFF )
{
switch ( a1 >> 28 )
{
case 0u:
goto LABEL_13;
case 1u:
goto LABEL_23;
case 2u:
LOBYTE(v1) = (unsigned int)func14(32) != 0;
goto LABEL_14;
case 3u:
LOBYTE(v1) = (unsigned int)func15(32) != 0;
goto LABEL_14;
case 4u:
LOBYTE(v1) = (unsigned int)func14(128) != 0;
goto LABEL_14;
case 5u:
LOBYTE(v1) = (unsigned int)func15(128) != 0;
goto LABEL_14;
case 6u:
goto LABEL_19;
case 7u:
LOBYTE(v1) = (unsigned int)func15(16) != 0;
goto LABEL_14;
case 8u:
if ( !(unsigned int)func14(32) )
goto LABEL_4;
goto LABEL_23;
case 9u:
if ( !(unsigned int)func15(32) )
goto LABEL_4;
goto LABEL_13;
case 0xAu:
if ( (unsigned int)func15(128) && (unsigned int)func15(16) )
goto LABEL_10;
if ( !(unsigned int)func14(128) )
goto LABEL_4;
goto LABEL_19;
case 0xBu:
if ( (unsigned int)func14(128) && (unsigned int)func15(16) )
goto LABEL_10;
if ( !(unsigned int)func15(128) )
goto LABEL_4;
LABEL_19:
LOBYTE(v1) = (unsigned int)func14(16) != 0;
goto LABEL_14;
case 0xCu:
if ( (unsigned int)func15(128) && (unsigned int)func15(16) && (unsigned int)func15(64) )
goto LABEL_10;
if ( !(unsigned int)func14(128) || !(unsigned int)func14(16) )
goto LABEL_4;
LABEL_23:
LOBYTE(v1) = (unsigned int)func15(64) != 0;
LABEL_14:
if ( !v6 )
return v1;
v4 = "false";
if ( (_BYTE)v1 )
v4 = "true";
break;
case 0xDu:
if ( (unsigned int)func14(128) && (unsigned int)func15(16)
|| (unsigned int)func15(128) && (unsigned int)func14(16) )
{
goto LABEL_10;
}
LABEL_13:
LOBYTE(v1) = (unsigned int)func14(64) != 0;
goto LABEL_14;
case 0xEu:
LABEL_10:
v1 = 1;
if ( !(_BYTE)v2 )
return v1;
v1 = v2;
v4 = "true";
goto LABEL_6;
}
goto LABEL_6;
}
LABEL_4:
v1 = 0;
if ( (_BYTE)v2 )
{
v4 = "false";
LABEL_6:
printf("\tshould execute?: %s - %04X\n", v4, v3);
}
return v1;
}

original_code:
_Bool shouldExecute(INSTRUCTION instruction) {
    _Bool execute = 0;
    int conditionCode = instruction.data32 >> (28);
    switch (conditionCode) {
        case (0x0):
            execute = isSet((1<<6));
            break;
        case (0x1):
            execute = isClear((1<<6));
            break;
        case (0x2):
            execute = isSet((1<<5));
            break;
        case (0x3):
            execute = isClear((1<<5));
            break;
        case (0x4):
            execute = isSet((1<<7));
            break;
        case (0x5):
            execute = isClear((1<<7));
            break;
        case (0x6):
            execute = isSet((1<<4));
            break;
        case (0x7):
            execute = isClear((1<<4));
            break;
        case (0x8):
            execute = ( isSet((1<<5)) && isClear((1<<6)) );
            break;
        case (0x9):
            execute = ( isClear((1<<5)) && isSet((1<<6)) );
            break;
        case (0xa):
            execute = ( isClear((1<<7)) && isClear((1<<4)) ) || ( isSet((1<<7)) && isSet((1<<4)) );
            break;
        case (0xb):
            execute = ( isSet((1<<7)) && isClear((1<<4)) ) || ( isClear((1<<7)) && isSet((1<<4)) );
            break;
        case (0xc):
            execute = ( isClear((1<<7)) && isClear((1<<4)) && isClear((1<<6)) ) || ( isSet((1<<7)) && isSet((1<<4)) && isClear((1<<6)));
            break;
        case (0xd):
            execute = ( isSet((1<<7)) && isClear((1<<4)) ) || ( isClear((1<<7)) && isSet((1<<4)) ) || isSet((1<<6));
            break;
        case (0xe):
            execute = 1;
            break;
        case (0xf):
            execute = 0;
            break;
    }
    if(VERBOSE) {
        printf("\tshould execute?: %s - %04X\n", execute? "true" : "false", instruction.data32);
    }
    return execute;
}

canonical_original_code:
_Bool shouldExecute(union INSTRUCTION instruction) {
    _Bool execute = 0;
    int conditionCode = instruction.data32 >> (28);
    switch (conditionCode) {
        case (0x0):
            execute = isSet((1<<6));
            break;
        case (0x1):
            execute = isClear((1<<6));
            break;
        case (0x2):
            execute = isSet((1<<5));
            break;
        case (0x3):
            execute = isClear((1<<5));
            break;
        case (0x4):
            execute = isSet((1<<7));
            break;
        case (0x5):
            execute = isClear((1<<7));
            break;
        case (0x6):
            execute = isSet((1<<4));
            break;
        case (0x7):
            execute = isClear((1<<4));
            break;
        case (0x8):
            execute = ( isSet((1<<5)) && isClear((1<<6)) );
            break;
        case (0x9):
            execute = ( isClear((1<<5)) && isSet((1<<6)) );
            break;
        case (0xa):
            execute = ( isClear((1<<7)) && isClear((1<<4)) ) || ( isSet((1<<7)) && isSet((1<<4)) );
            break;
        case (0xb):
            execute = ( isSet((1<<7)) && isClear((1<<4)) ) || ( isClear((1<<7)) && isSet((1<<4)) );
            break;
        case (0xc):
            execute = ( isClear((1<<7)) && isClear((1<<4)) && isClear((1<<6)) ) || ( isSet((1<<7)) && isSet((1<<4)) && isClear((1<<6)));
            break;
        case (0xd):
            execute = ( isSet((1<<7)) && isClear((1<<4)) ) || ( isClear((1<<7)) && isSet((1<<4)) ) || isSet((1<<6));
            break;
        case (0xe):
            execute = 1;
            break;
        case (0xf):
            execute = 0;
            break;
    }
    if(VERBOSE) {
        printf("\tshould execute?: %s - %04X\n", execute? "true" : "false", instruction.data32);
    }
    return execute;
}

variable_types: conditionCode int


setFlag

decompiled_code:
void __fastcall setFlag(char a1)
{
STATUS_REGISTER |= a1;
}

canonical_decompiled_code:
void __fastcall func17(char a1)
{
STATUS_REGISTER |= a1;
}

original_code:
void setFlag(int flag) {
    STATUS_REGISTER = STATUS_REGISTER | flag;
}


clearFlag

decompiled_code:
void __fastcall clearFlag(char a1)
{
STATUS_REGISTER &= ~a1;
}

canonical_decompiled_code:
void __fastcall func18(char a1)
{
STATUS_REGISTER &= ~a1;
}

original_code:
void clearFlag(int flag) {
    STATUS_REGISTER = STATUS_REGISTER & (~flag);
}


doDataProcessing

decompiled_code:
int __fastcall doDataProcessing(unsigned int a1)
{
int result; // eax

puts("\tData Processing...");
isImmediateValue(a1);
statusBitSet(a1);
getRegister(a1, 16);
getRegister(a1, 12);
printf("\tOp Code:\t%i\n", (a1 >> 21) & 0xF);
switch ( (a1 >> 21) & 0xF )
{
case 0u:
result = puts("\tProcessing AND function");
break;
case 1u:
result = puts("\tProcessing Exclusive-OR function");
break;
case 2u:
result = puts("\tProcessing SUB function");
break;
case 3u:
result = puts("\tProcessing RSB function");
break;
case 4u:
result = puts("\tProcessing ADD function");
break;
case 5u:
result = puts("\tProcessing ADC function");
break;
case 6u:
result = puts("\tProcessing SBC function");
break;
case 7u:
result = puts("\tProcessing RSC function");
break;
case 8u:
result = puts("\tProcessing TST function");
break;
case 9u:
result = puts("\tProcessing TEQ function");
break;
case 0xAu:
result = puts("\tProcessing Compare function");
break;
case 0xBu:
result = puts("\tProcessing CMN function");
break;
case 0xCu:
result = puts("\tProcessing ORR function");
break;
case 0xDu:
result = puts("\tProcessing MOV function");
break;
case 0xEu:
result = puts("\tProcessing BIC function");
break;
case 0xFu:
result = puts("\tProcessing MVN function");
break;
}
return result;
}

canonical_decompiled_code:
int __fastcall func19(unsigned int a1)
{
int result; // eax

puts("\tData Processing...");
func11(a1);
func12(a1);
func13(a1, 16);
func13(a1, 12);
printf("\tOp Code:\t%i\n", (a1 >> 21) & 0xF);
switch ( (a1 >> 21) & 0xF )
{
case 0u:
result = puts("\tProcessing AND function");
break;
case 1u:
result = puts("\tProcessing Exclusive-OR function");
break;
case 2u:
result = puts("\tProcessing SUB function");
break;
case 3u:
result = puts("\tProcessing RSB function");
break;
case 4u:
result = puts("\tProcessing ADD function");
break;
case 5u:
result = puts("\tProcessing ADC function");
break;
case 6u:
result = puts("\tProcessing SBC function");
break;
case 7u:
result = puts("\tProcessing RSC function");
break;
case 8u:
result = puts("\tProcessing TST function");
break;
case 9u:
result = puts("\tProcessing TEQ function");
break;
case 0xAu:
result = puts("\tProcessing Compare function");
break;
case 0xBu:
result = puts("\tProcessing CMN function");
break;
case 0xCu:
result = puts("\tProcessing ORR function");
break;
case 0xDu:
result = puts("\tProcessing MOV function");
break;
case 0xEu:
result = puts("\tProcessing BIC function");
break;
case 0xFu:
result = puts("\tProcessing MVN function");
break;
}
return result;
}

original_code:
void doDataProcessing(INSTRUCTION instruction) {
    printf("\tData Processing...\n");
    _Bool immediate = isImmediateValue(instruction);
    _Bool updateStatus = statusBitSet(instruction);
    REGISTER regN = getRegister(instruction, 16);
    REGISTER regDest = getRegister(instruction, 12);
    int opCode = (instruction.data32 >> (21)) & 0Xf;
    printf("\tOp Code:\t%i\n", opCode);
    switch (opCode) {
        case (0x0):
            printf("\tProcessing AND function\n");
            break;
        case (0x1):
            printf("\tProcessing Exclusive-OR function\n");
            break;
        case (0x2):
            printf("\tProcessing SUB function\n");
            break;
        case (0x3):
            printf("\tProcessing RSB function\n");
            break;
        case (0x4):
            printf("\tProcessing ADD function\n");
            break;
        case (0x5):
            printf("\tProcessing ADC function\n");
            break;
        case (0x6):
            printf("\tProcessing SBC function\n");
            break;
        case (0x7):
            printf("\tProcessing RSC function\n");
            break;
        case (0x8):
            printf("\tProcessing TST function\n");
            break;
        case (0x9):
            printf("\tProcessing TEQ function\n");
            break;
        case (0xa):
            printf("\tProcessing Compare function\n");
            break;
        case (0xb):
            printf("\tProcessing CMN function\n");
            break;
        case (0xc):
            printf("\tProcessing ORR function\n");
            break;
        case (0xd):
            printf("\tProcessing MOV function\n");
            break;
        case (0xe):
            printf("\tProcessing BIC function\n");
            break;
        case (0xf):
            printf("\tProcessing MVN function\n");
            break;
    }
}

canonical_original_code:
void doDataProcessing(union INSTRUCTION instruction) {
    printf("\tData Processing...\n");
    _Bool immediate = isImmediateValue(instruction);
    _Bool updateStatus = statusBitSet(instruction);
    unsigned int regN = getRegister(instruction, 16);
    unsigned int regDest = getRegister(instruction, 12);
    int opCode = (instruction.data32 >> (21)) & 0Xf;
    printf("\tOp Code:\t%i\n", opCode);
    switch (opCode) {
        case (0x0):
            printf("\tProcessing AND function\n");
            break;
        case (0x1):
            printf("\tProcessing Exclusive-OR function\n");
            break;
        case (0x2):
            printf("\tProcessing SUB function\n");
            break;
        case (0x3):
            printf("\tProcessing RSB function\n");
            break;
        case (0x4):
            printf("\tProcessing ADD function\n");
            break;
        case (0x5):
            printf("\tProcessing ADC function\n");
            break;
        case (0x6):
            printf("\tProcessing SBC function\n");
            break;
        case (0x7):
            printf("\tProcessing RSC function\n");
            break;
        case (0x8):
            printf("\tProcessing TST function\n");
            break;
        case (0x9):
            printf("\tProcessing TEQ function\n");
            break;
        case (0xa):
            printf("\tProcessing Compare function\n");
            break;
        case (0xb):
            printf("\tProcessing CMN function\n");
            break;
        case (0xc):
            printf("\tProcessing ORR function\n");
            break;
        case (0xd):
            printf("\tProcessing MOV function\n");
            break;
        case (0xe):
            printf("\tProcessing BIC function\n");
            break;
        case (0xf):
            printf("\tProcessing MVN function\n");
            break;
    }
}

variable_types:
regN
unsigned int

variable_types:
regDest
unsigned int

variable_types: opCode int


doBranch

decompiled_code:
int doBranch()
{
return puts("\tBranch");
}

canonical_decompiled_code:
int func20()
{
return puts("\tBranch");
}

original_code:
void doBranch() {
    printf("\tBranch\n");
}


doDataTransfer

decompiled_code:
int doDataTransfer()
{
return puts("\tData Transfer");
}

canonical_decompiled_code:
int func21()
{
return puts("\tData Transfer");
}

original_code:
void doDataTransfer() {
    printf("\tData Transfer\n");
}


doInterupt

decompiled_code:
int doInterupt()
{
return puts("\tInterupt");
}

canonical_decompiled_code:
int func22()
{
return puts("\tInterupt");
}

original_code:
void doInterupt() {
    printf("\tInterupt\n");
}


main

repo: SirAnthony/flmnt

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // eax
int v4; // ebx
int result; // eax
const char **v6; // [rsp+0h] [rbp-1E8h] BYREF
int v7; // [rsp+Ch] [rbp-1DCh] BYREF
char v8[472]; // [rsp+10h] [rbp-1D8h] BYREF

v7 = argc;
v6 = argv;
log_init("/var/log/flmnt.log", argv, envp);
v3 = ipc_select_role();
if ( v3 < 0 || (v4 = v3, (int)device_init_from_env(v8) < 0) )
{
log_close();
result = 1;
}
else
{
if ( v4 )
{
ipc_register_device(v8);
ipc_finalize(1LL);
}
else
{
mount_init();
tray_init(&v7, &v6);
ipc_register_device(v8);
ipc_finalize(1LL);
tray_run();
mount_clean();
ipc_finalize(0LL);
}
log_close();
result = 0;
}
return result;
}

original_code:
int main(int argc, char **argv) {
 struct Device device;
 int role;
 log_init("/var/log/flmnt.log");
 role = ipc_select_role();
 if( role < 0 ){
  log_close();
  return 1;
 }
 if( device_init_from_env( &device ) < 0 ){
  log_close();
  return 1;
 }
 if( role == IPC_SERVER ){
  mount_init();
  tray_init( &argc, &argv );
 }
 ipc_register_device( &device );
 ipc_finalize( IPC_CLIENT );
 if( role == IPC_SERVER ){
  tray_run();
  mount_clean();
  ipc_finalize( IPC_SERVER );
 }
 log_close();
 return 0;
}

variable_types:
argv
char **

variable_types: struct Device { char name[32]; char fstype[32]; char source[128]; char target[128]; char options[128]; short mounted; int id; }

variable_types: role int


decompiled_code:
int __fastcall log_handler(__int64 a1, __int64 a2, const char *a3)
{
if ( !log_file )
return printf("Rerouted to console: %s\n", a3);
fseek(log_file, 0LL, 2);
fprintf(log_file, "%s\n", a3);
return fflush(log_file);
}

canonical_decompiled_code:
int __fastcall func0(__int64 a1, __int64 a2, const char *a3)
{
if ( !log_file )
return printf("Rerouted to console: %s\n", a3);
fseek(log_file, 0LL, 2);
fprintf(log_file, "%s\n", a3);
return fflush(log_file);
}

original_code:
static void log_handler(const gchar *log_domain, GLogLevelFlags log_level,
  const gchar *message, gpointer user_data)
{
 if (!log_file) {
  printf("Rerouted to console: %s\n", message);
  return;
 }
 fseek(log_file, 0, 2);
 fprintf(log_file, "%s\n", message);
 fflush(log_file);
}

canonical_original_code:
static void log_handler(char *log_domain, enum GLogLevelFlags log_level, char *message, void *user_data)
{
 if (!log_file) {
  printf("Rerouted to console: %s\n", message);
  return;
 }
 fseek(log_file, 0, 2);
 fprintf(log_file, "%s\n", message);
 fflush(log_file);
}

variable_types: enum GLogLevelFlags { G_LOG_FLAG_RECURSION=expr, G_LOG_FLAG_FATAL=expr, G_LOG_LEVEL_ERROR=expr, G_LOG_LEVEL_CRITICAL=expr, G_LOG_LEVEL_WARNING=expr, G_LOG_LEVEL_MESSAGE=expr, G_LOG_LEVEL_INFO=expr, G_LOG_LEVEL_DEBUG=expr, G_LOG_LEVEL_MASK=expr }

variable_types:
message
char *


decompiled_code:
__int64 log_close()
{
__int64 result; // rax

if ( log_file )
{
fclose(log_file);
result = g_log_remove_handler(0LL, (unsigned int)log_handler_id);
log_file = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 func1()
{
__int64 result; // rax

if ( log_file )
{
fclose(log_file);
result = g_log_remove_handler(0LL, (unsigned int)log_handler_id);
log_file = 0LL;
}
return result;
}

original_code:
void log_close()
{
 if (!log_file)
  return;
 fclose(log_file);
 g_log_remove_handler(((void *)0), log_handler_id);
 log_file = ((void *)0);
}


decompiled_code:
__int64 __fastcall log_init(char *filename)
{
__int64 result; // rax
int *v2; // rbp
char *v3; // rax

if ( log_file )
log_close();
log_file = fopen(filename, "a");
if ( !log_file )
{
v2 = _errno_location();
v3 = strerror(*v2);
g_log(0LL, 16LL, "Cannot open log file: fopen returns status %i: %s", (unsigned int)*v2, v3);
}
result = g_log_set_handler(0LL, 0xFFFFFFFFLL, log_handler, 0LL);
log_handler_id = result;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(char *filename)
{
__int64 result; // rax
int *v2; // rbp
char *v3; // rax

if ( log_file )
func1();
log_file = fopen(filename, "a");
if ( !log_file )
{
v2 = _errno_location();
v3 = strerror(*v2);
g_log(0LL, 16LL, "Cannot open log file: fopen returns status %i: %s", (unsigned int)*v2, v3);
}
result = g_log_set_handler(0LL, 0xFFFFFFFFLL, log_handler, 0LL);
log_handler_id = result;
return result;
}

original_code:
void log_init(const char *path)
{
 if (log_file)
  log_close();
 log_file = fopen(path, "a");
 if (!log_file)
  g_log (((gchar*) 0), G_LOG_LEVEL_WARNING, "Cannot open log file: fopen returns status %i: %s", (*__errno_location ()), strerror((*__errno_location ())));
 log_handler_id = g_log_set_handler(((void *)0), G_LOG_LEVEL_MASK |
      G_LOG_FLAG_FATAL | G_LOG_FLAG_RECURSION,
      log_handler, ((void *)0) );
}

canonical_original_code:
void log_init(char *path)
{
 if (log_file)
  log_close();
 log_file = fopen(path, "a");
 if (!log_file)
  g_log (((char *) 0), G_LOG_LEVEL_WARNING, "Cannot open log file: fopen returns status %i: %s", (*__errno_location ()), strerror((*__errno_location ())));
 log_handler_id = g_log_set_handler(((void *)0), G_LOG_LEVEL_MASK |
      G_LOG_FLAG_FATAL | G_LOG_FLAG_RECURSION,
      log_handler, ((void *)0) );
}

variable_types:
path
char *


decompiled_code:
__int64 __fastcall create_dir(char *path)
{
__int64 result; // rax
int *v2; // rax
__int64 v3; // rcx
int *v4; // rbx
char *v5; // r12
char *v6; // rax
struct stat v7; // [rsp+0h] [rbp-A8h] BYREF

if ( stat(path, &v7) )
{
v2 = _errno_location();
v3 = (unsigned int)*v2;
v4 = v2;
if ( (_DWORD)v3 == 2 )
{
v5 = strdup(path);
dirname(v5);
free(v5);
if ( !mkdir(path, 0x1C0u) )
return 0LL;
v6 = strerror(*v4);
g_log(0LL, 16LL, "mkdir failed: %i: %s", (unsigned int)*v4, v6);
result = 3LL;
}
else
{
g_log(0LL, 16LL, "Stat failed: %i", v3);
result = 2LL;
}
}
else
{
if ( (v7.st_mode & 0x4000) != 0 )
return 0LL;
g_log(0LL, 16LL, "Cannot create %s: exists", path);
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(char *path)
{
__int64 result; // rax
int *v2; // rax
__int64 v3; // rcx
int *v4; // rbx
char *v5; // r12
char *v6; // rax
struct stat v7; // [rsp+0h] [rbp-A8h] BYREF

if ( stat(path, &v7) )
{
v2 = _errno_location();
v3 = (unsigned int)*v2;
v4 = v2;
if ( (_DWORD)v3 == 2 )
{
v5 = strdup(path);
dirname(v5);
free(v5);
if ( !mkdir(path, 0x1C0u) )
return 0LL;
v6 = strerror(*v4);
g_log(0LL, 16LL, "mkdir failed: %i: %s", (unsigned int)*v4, v6);
result = 3LL;
}
else
{
g_log(0LL, 16LL, "Stat failed: %i", v3);
result = 2LL;
}
}
else
{
if ( (v7.st_mode & 0x4000) != 0 )
return 0LL;
g_log(0LL, 16LL, "Cannot create %s: exists", path);
result = 1LL;
}
return result;
}

original_code:
int create_dir(const char* path)
{
 struct stat sb;
 const char* before;
 char* path_copy;
 int status;
 if (!stat(path, &sb)){
  if (sb.st_mode & 0040000)
   return CREATE_PATH_SUCCESS;
  g_log (((gchar*) 0), G_LOG_LEVEL_WARNING, "Cannot create %s: exists", path);
  return CREATE_PATH_EXISTS;
 }
 if ((*__errno_location ()) != 2) {
  g_log (((gchar*) 0), G_LOG_LEVEL_WARNING, "Stat failed: %i", (*__errno_location ()));
  return CREATE_PATH_STAT_FAILED;
 }
 path_copy = strdup(path);
 before = dirname(path_copy);
 if (!strcmp(before, ".") || !strcmp(before, "..") ||
   !strcmp(before, before)){
  status = CREATE_PATH_SUCCESS;
 } else {
  status = create_dir(before);
 }
 free(path_copy);
 if (status == CREATE_PATH_SUCCESS){
  if (mkdir(path, (0400|0200|0100)) != 0){
   g_log (((gchar*) 0), G_LOG_LEVEL_WARNING, "mkdir failed: %i: %s", (*__errno_location ()), strerror((*__errno_location ())));
   return CREATE_PATH_MKDIR_FAILED;
  }
 }
 return CREATE_PATH_SUCCESS;
}

canonical_original_code:
int create_dir(char *path)
{
 struct stat sb;
 char *before;
 char *path_copy;
 int status;
 if (!stat(path, &sb)){
  if (sb.st_mode & 0040000)
   return CREATE_PATH_SUCCESS;
  g_log (((char *) 0), G_LOG_LEVEL_WARNING, "Cannot create %s: exists", path);
  return CREATE_PATH_EXISTS;
 }
 if ((*__errno_location ()) != 2) {
  g_log (((char *) 0), G_LOG_LEVEL_WARNING, "Stat failed: %i", (*__errno_location ()));
  return CREATE_PATH_STAT_FAILED;
 }
 path_copy = strdup(path);
 before = dirname(path_copy);
 if (!strcmp(before, ".") || !strcmp(before, "..") ||
   !strcmp(before, before)){
  status = CREATE_PATH_SUCCESS;
 } else {
  status = create_dir(before);
 }
 free(path_copy);
 if (status == CREATE_PATH_SUCCESS){
  if (mkdir(path, (0400|0200|0100)) != 0){
   g_log (((char *) 0), G_LOG_LEVEL_WARNING, "mkdir failed: %i: %s", (*__errno_location ()), strerror((*__errno_location ())));
   return CREATE_PATH_MKDIR_FAILED;
  }
 }
 return CREATE_PATH_SUCCESS;
}

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

variable_types:
before
char *

variable_types: status int

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


decompiled_code:
__int64 tray_widget_get_type_once()
{
__int64 v0; // rax

v0 = g_intern_static_string("TrayWidget");
return g_type_register_static_simple(80LL, v0, 152LL, tray_widget_class_intern_init, 24LL, tray_widget_init, 0LL);
}

canonical_decompiled_code:
__int64 func1()
{
__int64 v0; // rax

v0 = g_intern_static_string("TrayWidget");
return g_type_register_static_simple(80LL, v0, 152LL, tray_widget_class_intern_init, 24LL, tray_widget_init, 0LL);
}

original_code: __attribute__((noinline)) static GType tray_widget_get_type_once (void) { GType g_define_type_id = g_type_register_static_simple (((GType) ((20) << (2))), g_intern_static_string ("TrayWidget"), sizeof (TrayWidgetClass), (GClassInitFunc)(void (*)(void)) tray_widget_class_intern_init, sizeof (TrayWidget), (GInstanceInitFunc)(void (*)(void)) tray_widget_init, (GTypeFlags) 0); { {{};} } return g_define_type_id; }

canonical_original_code: static unsigned long tray_widget_get_type_once() { unsigned long g_define_type_id = g_type_register_static_simple (((GType) ((20) << (2))), g_intern_static_string ("TrayWidget"), sizeof (TrayWidgetClass), (GClassInitFunc)(void (*)(void)) tray_widget_class_intern_init, sizeof (TrayWidget), (GInstanceInitFunc)(void (*)(void)) tray_widget_init, (GTypeFlags) 0); { {{};} } return g_define_type_id; }

return_type: unsigned long


decompiled_code:
__int64 tray_widget_get_type()
{
__int64 v1; // rax

if ( g_define_type_id__volatile_1 )
return g_define_type_id__volatile_1;
if ( (unsigned int)g_once_init_enter(&g_define_type_id__volatile_1) )
{
v1 = tray_widget_get_type_once();
g_once_init_leave(&g_define_type_id__volatile_1, v1);
}
return g_define_type_id__volatile_1;
}

canonical_decompiled_code:
__int64 func12()
{
__int64 v1; // rax

if ( g_define_type_id__volatile_1 )
return g_define_type_id__volatile_1;
if ( (unsigned int)g_once_init_enter(&g_define_type_id__volatile_1) )
{
v1 = func1();
g_once_init_leave(&g_define_type_id__volatile_1, v1);
}
return g_define_type_id__volatile_1;
}

original_code: GType tray_widget_get_type (void) { static volatile gsize g_define_type_id__volatile = 0; if ((__extension__ ({ typedef char _GStaticAssertCompileTimeAssertion_1[(sizeof *(&g_define_type_id__volatile) == sizeof (gpointer)) ? 1 : -1] __attribute__((__unused__)); (void) (0 ? (gpointer) *(&g_define_type_id__volatile) : 0); (!(__extension__ ({ typedef char _GStaticAssertCompileTimeAssertion_2[(sizeof *(&g_define_type_id__volatile) == sizeof (gpointer)) ? 1 : -1] __attribute__((__unused__)); guint64 gapg_temp = __atomic_load_8 ((&g_define_type_id__volatile), 5); (gpointer) gapg_temp; })) && g_once_init_enter (&g_define_type_id__volatile)); }))) { GType g_define_type_id = tray_widget_get_type_once (); (__extension__ ({ typedef char _GStaticAssertCompileTimeAssertion_3[(sizeof *(&g_define_type_id__volatile) == sizeof (gpointer)) ? 1 : -1] __attribute__((__unused__)); (void) (0 ? *(&g_define_type_id__volatile) = (g_define_type_id) : 0); g_once_init_leave ((&g_define_type_id__volatile), (gsize) (g_define_type_id)); })); } return g_define_type_id__volatile; }

canonical_original_code: unsigned long tray_widget_get_type() { static unsigned long g_define_type_id__volatile = 0; if ((__extension__ ({ typedef char _GStaticAssertCompileTimeAssertion_1[(sizeof *(&g_define_type_id__volatile) == sizeof (gpointer)) ? 1 : -1] __attribute__((__unused__)); (void) (0 ? (gpointer) *(&g_define_type_id__volatile) : 0); (!(__extension__ ({ typedef char _GStaticAssertCompileTimeAssertion_2[(sizeof *(&g_define_type_id__volatile) == sizeof (gpointer)) ? 1 : -1] __attribute__((__unused__)); unsigned long gapg_temp = __atomic_load_8 ((&g_define_type_id__volatile), 5); (void *) gapg_temp; })) && g_once_init_enter (&g_define_type_id__volatile)); }))) { unsigned long g_define_type_id = tray_widget_get_type_once (); (__extension__ ({ typedef char _GStaticAssertCompileTimeAssertion_3[(sizeof *(&g_define_type_id__volatile) == sizeof (gpointer)) ? 1 : -1] __attribute__((__unused__)); (void) (0 ? *(&g_define_type_id__volatile) = (g_define_type_id) : 0); g_once_init_leave ((&g_define_type_id__volatile), (gsize) (g_define_type_id)); })); } return g_define_type_id__volatile; }


decompiled_code:
__int64 __fastcall tray_init(__int64 a1, __int64 a2)
{
__int64 v2; // rax

g_log(0LL, 128LL, "Launching tray icon.");
gtk_init(a1, a2);
v2 = tray_widget_get_type();
tray_widget = g_object_new(v2, 0LL);
devices = g_hash_table_new_full(&g_int_hash, &g_int_equal, &free, 0LL);
tray_create_icon_isra_0();
g_signal_connect_data(tray_widget, "device-mounted", tray_item_add, 0LL, 0LL, 0LL);
g_signal_connect_data(tray_widget, "device-unmounted", tray_item_remove, 0LL, 0LL, 0LL);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func13(__int64 a1, __int64 a2)
{
__int64 v2; // rax

g_log(0LL, 128LL, "Launching tray icon.");
gtk_init(a1, a2);
v2 = func12();
tray_widget = g_object_new(v2, 0LL);
devices = g_hash_table_new_full(&g_int_hash, &g_int_equal, &free, 0LL);
func11();
g_signal_connect_data(tray_widget, "device-mounted", tray_item_add, 0LL, 0LL, 0LL);
g_signal_connect_data(tray_widget, "device-unmounted", tray_item_remove, 0LL, 0LL, 0LL);
return 0LL;
}

original_code:
int tray_init( int *argc, char ***argv )
{
 g_log (((gchar*) 0), G_LOG_LEVEL_DEBUG, "Launching tray icon.");
 gtk_init( argc, argv );
 tray_widget = g_object_new((tray_widget_get_type()), ((void *)0));
 devices = g_hash_table_new_full(g_int_hash, g_int_equal, free, ((void *)0));
 tray_create_icon( );
 g_signal_connect_data ((tray_widget), ("device-mounted"), (((GCallback) (tray_item_add))), (((void *)0)), ((void *)0), (GConnectFlags) 0);
 g_signal_connect_data ((tray_widget), ("device-unmounted"), (((GCallback) (tray_item_remove))), (((void *)0)), ((void *)0), (GConnectFlags) 0);
 return 0;
}

canonical_original_code:
int tray_init(int *argc, char ***argv)
{
 g_log (((char *) 0), G_LOG_LEVEL_DEBUG, "Launching tray icon.");
 gtk_init( argc, argv );
 tray_widget = g_object_new((tray_widget_get_type()), ((void *)0));
 devices = g_hash_table_new_full(g_int_hash, g_int_equal, free, ((void *)0));
 tray_create_icon( );
 g_signal_connect_data ((tray_widget), ("device-mounted"), (((GCallback) (tray_item_add))), (((void *)0)), ((void *)0), (enum GConnectFlags) 0);
 g_signal_connect_data ((tray_widget), ("device-unmounted"), (((GCallback) (tray_item_remove))), (((void *)0)), ((void *)0), (enum GConnectFlags) 0);
 return 0;
}

variable_types:
argc
int *

variable_types:
argv
char ***

user_defined_types: enum GConnectFlags { G_CONNECT_AFTER=expr, G_CONNECT_SWAPPED=expr }


decompiled_code:
__int64 tray_run()
{
gtk_main();
g_hash_table_destroy(devices);
return 0LL;
}

canonical_decompiled_code:
__int64 func14()
{
gtk_main();
g_hash_table_destroy(devices);
return 0LL;
}

original_code:
int tray_run()
{
 gtk_main();
 g_hash_table_destroy(devices);
 return 0;
}


decompiled_code:
__int64 tray_signal_emit(const char *a1, ...)
{
unsigned int v2; // [rsp+4h] [rbp-D4h] BYREF
gcc_va_list va; // [rsp+8h] [rbp-D0h] BYREF

if ( !tray_widget )
return g_return_if_fail_warning(0LL, "tray_signal_emit", "tray_widget != NULL");
if ( !(unsigned int)g_signal_parse_name(a1, **(_QWORD **)tray_widget, &v2, 0LL, 0LL) )
return g_log(0LL, 16LL, "%s: signal '%s' not found", "src/tray.c:217", a1);
va_start(va, a1);
return g_signal_emit_valist(tray_widget, v2, 0LL, va);
}

canonical_decompiled_code:
__int64 func15(const char *a1, ...)
{
unsigned int v2; // [rsp+4h] [rbp-D4h] BYREF
gcc_va_list va; // [rsp+8h] [rbp-D0h] BYREF

if ( !tray_widget )
return g_return_if_fail_warning(0LL, "tray_signal_emit", "tray_widget != NULL");
if ( !(unsigned int)g_signal_parse_name(a1, **(_QWORD **)tray_widget, &v2, 0LL, 0LL) )
return g_log(0LL, 16LL, "%s: signal '%s' not found", "src/tray.c:217", a1);
va_start(va, a1);
return g_signal_emit_valist(tray_widget, v2, 0LL, va);
}

original_code:
void tray_signal_emit(const char *name, ...)
{
 guint signal_id;
 do{ if (tray_widget != ((void *)0)) { } else { g_return_if_fail_warning (((gchar*) 0), ((const char*) (__func__)), "tray_widget != NULL"); return; }; }while (0);
 if (g_signal_parse_name(name, ((((GTypeClass*) (((GTypeInstance*) (tray_widget))->g_class))->g_type)), &signal_id, ((void *)0), (0))) {
  va_list var_args;
  __builtin_va_start(var_args,name);
  g_signal_emit_valist(tray_widget, signal_id, 0, var_args);
  __builtin_va_end(var_args);
 } else
  g_log (((gchar*) 0), G_LOG_LEVEL_WARNING, "%s: signal '%s' not found", "src/tray.c" ":" "217", name);
}

canonical_original_code:
void tray_signal_emit(char *name, ...)
{
 unsigned int signal_id;
 do{ if (tray_widget != ((void *)0)) { } else { g_return_if_fail_warning (((char *) 0), ((char *) (__func__)), "tray_widget != NULL"); return; }; }while (0);
 if (g_signal_parse_name(name, ((((struct _GTypeClass *) (((struct _GTypeInstance *) (tray_widget))->g_class))->g_type)), &signal_id, ((void *)0), (0))) {
  __builtin_va_list var_args;
  __builtin_va_start(var_args,name);
  g_signal_emit_valist(tray_widget, signal_id, 0, var_args);
  __builtin_va_end(var_args);
 } else
  g_log (((char *) 0), G_LOG_LEVEL_WARNING, "%s: signal '%s' not found", "src/tray.c" ":" "217", name);
}

variable_types:
name
char *

user_defined_types: struct _GTypeClass { unsigned long g_type; }

user_defined_types: struct _GTypeInstance { struct _GTypeClass *g_class; }


decompiled_code:
__int64 __fastcall init_fifo(int *a1)
{
unsigned int v1; // er12
int *v2; // rax
unsigned int *v3; // rbp
int v4; // eax
char *v6; // rax

if ( mkfifo(fifo_file, 0x180u) == -1 )
{
v1 = -1;
v2 = _errno_location();
v3 = (unsigned int *)v2;
if ( *v2 != 17 )
{
v6 = strerror(*v2);
g_log(0LL, 16LL, "Error %i occured in fifo init: %s", *v3, v6);
return v1;
}
v1 = 1;
v4 = open(fifo_file, 2049);
}
else
{
v1 = 0;
v4 = open(fifo_file, 2048);
}
*a1 = v4;
if ( v4 == -1 )
v1 = -2;
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func0(int *a1)
{
unsigned int v1; // er12
int *v2; // rax
unsigned int *v3; // rbp
int v4; // eax
char *v6; // rax

if ( mkfifo(fifo_file, 0x180u) == -1 )
{
v1 = -1;
v2 = _errno_location();
v3 = (unsigned int *)v2;
if ( *v2 != 17 )
{
v6 = strerror(*v2);
g_log(0LL, 16LL, "Error %i occured in fifo init: %s", *v3, v6);
return v1;
}
v1 = 1;
v4 = open(fifo_file, 2049);
}
else
{
v1 = 0;
v4 = open(fifo_file, 2048);
}
*a1 = v4;
if ( v4 == -1 )
v1 = -2;
return v1;
}

original_code:
static int init_fifo( int* socket )
{
 int status = IPC_SERVER;
 int flag = 00 | 04000;
 if( mkfifo( fifo_file, 0600 ) == -1 ){
  if( (*__errno_location ()) != 17 ){
   g_log (((gchar*) 0), G_LOG_LEVEL_WARNING, "Error %i occured in fifo init: %s", (*__errno_location ()), strerror((*__errno_location ())));
   return -1;
  }
  status = IPC_CLIENT;
  flag = 01 | 04000;
 }
 *socket = open( fifo_file, flag );
 if( *socket == -1 )
  return -2;
 return status;
}

canonical_original_code:
static int init_fifo(int *socket)
{
 int status = IPC_SERVER;
 int flag = 00 | 04000;
 if( mkfifo( fifo_file, 0600 ) == -1 ){
  if( (*__errno_location ()) != 17 ){
   g_log (((char *) 0), G_LOG_LEVEL_WARNING, "Error %i occured in fifo init: %s", (*__errno_location ()), strerror((*__errno_location ())));
   return -1;
  }
  status = IPC_CLIENT;
  flag = 01 | 04000;
 }
 *socket = open( fifo_file, flag );
 if( *socket == -1 )
  return -2;
 return status;
}

variable_types:
socket
int *

variable_types: flag int


decompiled_code:
__int64 ipc_role_client_init()
{
__int64 v1; // [rsp+8h] [rbp-10h] BYREF

v1 = 0LL;
client_channel = g_io_channel_unix_new();
g_io_channel_set_encoding(client_channel, 0LL, &v1);
if ( !v1 )
return 0LL;
g_log(0LL, 16LL, "Error %s occured while encoding setup.", *(const char **)(v1 + 8));
ipc_close_channel(server_channel);
return 4294967294LL;
}

canonical_decompiled_code:
__int64 func3()
{
__int64 v1; // [rsp+8h] [rbp-10h] BYREF

v1 = 0LL;
client_channel = g_io_channel_unix_new();
g_io_channel_set_encoding(client_channel, 0LL, &v1);
if ( !v1 )
return 0LL;
g_log(0LL, 16LL, "Error %s occured while encoding setup.", *(const char **)(v1 + 8));
func2(server_channel);
return 4294967294LL;
}

original_code:
static int ipc_role_client_init( int socket )
{
 GError* error = ((void *)0);
 client_channel = g_io_channel_unix_new( socket );
 g_io_channel_set_encoding( client_channel, ((void *)0), &error );
 if( error ){
  g_log (((gchar*) 0), G_LOG_LEVEL_WARNING, "Error %s occured while encoding setup.", error->message);
  ipc_close_channel(server_channel);
  return -2;
 }
 return 0;
}

canonical_original_code:
static int ipc_role_client_init(int socket)
{
 struct _GError *error = ((void *)0);
 client_channel = g_io_channel_unix_new( socket );
 g_io_channel_set_encoding( client_channel, ((void *)0), &error );
 if( error ){
  g_log (((char *) 0), G_LOG_LEVEL_WARNING, "Error %s occured while encoding setup.", error->message);
  ipc_close_channel(server_channel);
  return -2;
 }
 return 0;
}

variable_types: socket int

variable_types: struct _GError { unsigned int domain; int code; char *message; } *


decompiled_code:
__int64 __fastcall ipc_role_server_init(unsigned int a1)
{
unsigned int v1; // eax
unsigned int v2; // er12
int *v4; // rax
char *v5; // rax
__int64 v6; // [rsp+8h] [rbp-10h] BYREF

v6 = 0LL;
g_log(0LL, 32LL, "Starting mount server.");
server_channel = g_io_channel_unix_new(a1);
g_io_channel_set_encoding(server_channel, 0LL, &v6);
if ( v6 )
{
v2 = -2;
g_log(0LL, 16LL, "Error %s occured while encoding setup.", *(const char **)(v6 + 8));
ipc_close_channel(server_channel);
}
else
{
g_io_add_watch(server_channel, 3LL, fifo_read, 0LL);
v1 = open(fifo_file, 2049);
v2 = v1;
if ( v1 == -1 )
{
v4 = _errno_location();
v5 = strerror(*v4);
g_log(0LL, 16LL, "Error occured while open client socket: %s", v5);
}
else
{
v2 = ipc_role_client_init(v1);
}
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func4(unsigned int a1)
{
unsigned int v1; // eax
unsigned int v2; // er12
int *v4; // rax
char *v5; // rax
__int64 v6; // [rsp+8h] [rbp-10h] BYREF

v6 = 0LL;
g_log(0LL, 32LL, "Starting mount server.");
server_channel = g_io_channel_unix_new(a1);
g_io_channel_set_encoding(server_channel, 0LL, &v6);
if ( v6 )
{
v2 = -2;
g_log(0LL, 16LL, "Error %s occured while encoding setup.", *(const char **)(v6 + 8));
func2(server_channel);
}
else
{
g_io_add_watch(server_channel, 3LL, fifo_read, 0LL);
v1 = open(fifo_file, 2049);
v2 = v1;
if ( v1 == -1 )
{
v4 = _errno_location();
v5 = strerror(*v4);
g_log(0LL, 16LL, "Error occured while open client socket: %s", v5);
}
else
{
v2 = func3(v1);
}
}
return v2;
}

original_code:
static int ipc_role_server_init( int socket )
{
 GError* error = ((void *)0);
 int client_socket;
 g_log (((gchar*) 0), G_LOG_LEVEL_MESSAGE, "Starting mount server.");
 server_channel = g_io_channel_unix_new( socket );
 g_io_channel_set_encoding( server_channel, ((void *)0), &error );
 if( error ){
  g_log (((gchar*) 0), G_LOG_LEVEL_WARNING, "Error %s occured while encoding setup.", error->message);
  ipc_close_channel(server_channel);
  return -2;
 }
 g_io_add_watch( server_channel, G_IO_IN | G_IO_PRI, fifo_read, ((void *)0) );
 client_socket = open( fifo_file, 01 | 04000 );
 if( client_socket == -1 ){
  g_log (((gchar*) 0), G_LOG_LEVEL_WARNING, "Error occured while open client socket: %s", strerror( (*__errno_location ())));
  return -1;
 }
 return ipc_role_client_init( client_socket );
}

canonical_original_code:
static int ipc_role_server_init(int socket)
{
 struct _GError *error = ((void *)0);
 int client_socket;
 g_log (((char *) 0), G_LOG_LEVEL_MESSAGE, "Starting mount server.");
 server_channel = g_io_channel_unix_new( socket );
 g_io_channel_set_encoding( server_channel, ((void *)0), &error );
 if( error ){
  g_log (((char *) 0), G_LOG_LEVEL_WARNING, "Error %s occured while encoding setup.", error->message);
  ipc_close_channel(server_channel);
  return -2;
 }
 g_io_add_watch( server_channel, G_IO_IN | G_IO_PRI, fifo_read, ((void *)0) );
 client_socket = open( fifo_file, 01 | 04000 );
 if( client_socket == -1 ){
  g_log (((char *) 0), G_LOG_LEVEL_WARNING, "Error occured while open client socket: %s", strerror( (*__errno_location ())));
  return -1;
 }
 return ipc_role_client_init( client_socket );
}

user_defined_types: struct _GError { unsigned int domain; int code; char *message; }


decompiled_code:
__int64 ipc_client_finalize()
{
return ipc_close_channel(client_channel);
}

canonical_decompiled_code:
__int64 func5()
{
return func2(client_channel);
}

original_code:
static int ipc_client_finalize( )
{
 return ipc_close_channel( client_channel );
}

canonical_original_code:
static int ipc_client_finalize()
{
 return ipc_close_channel( client_channel );
}


decompiled_code:
__int64 ipc_server_finalize()
{
unsigned int v0; // er12

v0 = ipc_close_channel(server_channel);
g_log(0LL, 32LL, "Closing mount server.");
unlink(fifo_file);
return v0;
}

canonical_decompiled_code:
__int64 func6()
{
unsigned int v0; // er12

v0 = func2(server_channel);
g_log(0LL, 32LL, "Closing mount server.");
unlink(fifo_file);
return v0;
}

original_code:
static int ipc_server_finalize( )
{
 int ret = ipc_close_channel( server_channel );
 g_log (((gchar*) 0), G_LOG_LEVEL_MESSAGE, "Closing mount server.");
 unlink( fifo_file );
 return ret;
}

canonical_original_code:
static int ipc_server_finalize()
{
 int ret = ipc_close_channel( server_channel );
 g_log (((char *) 0), G_LOG_LEVEL_MESSAGE, "Closing mount server.");
 unlink( fifo_file );
 return ret;
}

variable_types: ret int


decompiled_code:
__int64 ipc_select_role()
{
unsigned int v0; // eax
unsigned int v1; // er12
int *v2; // rax
char *v3; // rax
unsigned int v5[3]; // [rsp+Ch] [rbp-Ch] BYREF

v0 = init_fifo((int *)v5);
v1 = v0;
if ( v0 )
{
if ( v0 == 1 )
{
if ( (int)ipc_role_client_init(v5[0]) < 0 )
{
v1 = -1;
ipc_client_finalize();
}
}
else
{
v2 = _errno_location();
v3 = strerror(*v2);
g_log(0LL, 16LL, "Error occured in role selection: %s", v3);
}
}
else if ( (int)ipc_role_server_init(v5[0]) < 0 )
{
v1 = -1;
ipc_server_finalize();
}
return v1;
}

canonical_decompiled_code:
__int64 func7()
{
unsigned int v0; // eax
unsigned int v1; // er12
int *v2; // rax
char *v3; // rax
unsigned int v5[3]; // [rsp+Ch] [rbp-Ch] BYREF

v0 = func0((int *)v5);
v1 = v0;
if ( v0 )
{
if ( v0 == 1 )
{
if ( (int)func3(v5[0]) < 0 )
{
v1 = -1;
func5();
}
}
else
{
v2 = _errno_location();
v3 = strerror(*v2);
g_log(0LL, 16LL, "Error occured in role selection: %s", v3);
}
}
else if ( (int)func4(v5[0]) < 0 )
{
v1 = -1;
func6();
}
return v1;
}

original_code:
int ipc_select_role( )
{
 int socket;
 int role;
 role = init_fifo( &socket );
 switch( role ){
  case IPC_SERVER:
   if (ipc_role_server_init(socket) < 0){
    ipc_server_finalize();
    return -1;
   }
   break;
  case IPC_CLIENT:
   if (ipc_role_client_init(socket) < 0){
    ipc_client_finalize();
    return -1;
   }
   break;
  default:
   g_log (((gchar*) 0), G_LOG_LEVEL_WARNING, "Error occured in role selection: %s", strerror((*__errno_location ())));
   break;
 }
 return role;
}

canonical_original_code:
int ipc_select_role()
{
 int socket;
 int role;
 role = init_fifo( &socket );
 switch( role ){
  case IPC_SERVER:
   if (ipc_role_server_init(socket) < 0){
    ipc_server_finalize();
    return -1;
   }
   break;
  case IPC_CLIENT:
   if (ipc_role_client_init(socket) < 0){
    ipc_client_finalize();
    return -1;
   }
   break;
  default:
   g_log (((char *) 0), G_LOG_LEVEL_WARNING, "Error occured in role selection: %s", strerror((*__errno_location ())));
   break;
 }
 return role;
}


decompiled_code:
__int64 __fastcall ipc_register_device(__int64 a1)
{
__int64 v2; // [rsp+0h] [rbp-18h] BYREF
char v3[16]; // [rsp+8h] [rbp-10h] BYREF

v2 = 0LL;
if ( !a1 || !client_channel )
return 0xFFFFFFFFLL;
g_log(0LL, 32LL, "Registering device %s.", (const char *)(a1 + 64));
g_io_channel_write_chars(client_channel, a1, 456LL, v3, &v2);
if ( !v2 )
return 0LL;
g_log(0LL, 16LL, "Error %s occured while data transfer.", *(const char **)(v2 + 8));
return 4294967294LL;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1)
{
__int64 v2; // [rsp+0h] [rbp-18h] BYREF
char v3[16]; // [rsp+8h] [rbp-10h] BYREF

v2 = 0LL;
if ( !a1 || !client_channel )
return 0xFFFFFFFFLL;
g_log(0LL, 32LL, "Registering device %s.", (const char *)(a1 + 64));
g_io_channel_write_chars(client_channel, a1, 456LL, v3, &v2);
if ( !v2 )
return 0LL;
g_log(0LL, 16LL, "Error %s occured while data transfer.", *(const char **)(v2 + 8));
return 4294967294LL;
}

original_code:
int ipc_register_device( struct Device* device )
{
 GError* error = ((void *)0);
 gsize device_size, written;
 const gchar* dev_ptr;
 if( !device || !client_channel )
  return -1;
 dev_ptr = (const gchar*)device;
 device_size = sizeof(struct Device);
 g_log (((gchar*) 0), G_LOG_LEVEL_MESSAGE, "Registering device %s.", device->source);
 g_io_channel_write_chars( client_channel, dev_ptr, device_size, &written, &error);
 if( error ){
  g_log (((gchar*) 0), G_LOG_LEVEL_WARNING, "Error %s occured while data transfer.", error->message);
  return -2;
 }
 return 0;
}

canonical_original_code:
int ipc_register_device(struct Device *device)
{
 struct _GError *error = ((void *)0);
 unsigned long device_size; unsigned long written;
 char *dev_ptr;
 if( !device || !client_channel )
  return -1;
 dev_ptr = (char *)device;
 device_size = sizeof(struct Device);
 g_log (((char *) 0), G_LOG_LEVEL_MESSAGE, "Registering device %s.", device->source);
 g_io_channel_write_chars( client_channel, dev_ptr, device_size, &written, &error);
 if( error ){
  g_log (((char *) 0), G_LOG_LEVEL_WARNING, "Error %s occured while data transfer.", error->message);
  return -2;
 }
 return 0;
}

variable_types: struct Device { char name[32]; char fstype[32]; char source[128]; char target[128]; char options[128]; short mounted; int id; } *

variable_types:
written
unsigned long


decompiled_code:
__int64 __fastcall ipc_finalize(int a1)
{
if ( !a1 )
return ipc_server_finalize();
if ( a1 == 1 )
return ipc_client_finalize();
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func9(int a1)
{
if ( !a1 )
return func6();
if ( a1 == 1 )
return func5();
return 0LL;
}

original_code:
int ipc_finalize( int role )
{
 int ret;
 switch( role ){
  case IPC_CLIENT:
   ret = ipc_client_finalize();
   break;
  case IPC_SERVER:
   ret = ipc_server_finalize();
   break;
 }
 return ret;
}

canonical_original_code:
int ipc_finalize(int role)
{
 int ret;
 switch( role ){
  case IPC_CLIENT:
   ret = ipc_client_finalize();
   break;
  case IPC_SERVER:
   ret = ipc_server_finalize();
   break;
 }
 return ret;
}

variable_types: role int


decompiled_code:
__int64 __fastcall mount_remove_item(__int64 a1)
{
__int64 result; // rax
int *v2; // rax
int *v3; // rax

g_log(0LL, 32LL, "Unmounting device %s.", (const char *)(a1 + 64));
if ( umount((const char *)(a1 + 64)) < 0 )
{
v2 = _errno_location();
result = g_log(0LL, 16LL, "Error while unmounting: %i.", (unsigned int)*v2);
}
else
{
if ( unlink((const char *)(a1 + 192)) < 0 )
{
v3 = _errno_location();
g_log(0LL, 16LL, "Unlink failed: %i.", (unsigned int)*v3);
}
*(_WORD *)(a1 + 448) = 0;
tray_signal_emit("device-unmounted", a1);
result = device_free(a1);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
__int64 result; // rax
int *v2; // rax
int *v3; // rax

g_log(0LL, 32LL, "Unmounting device %s.", (const char *)(a1 + 64));
if ( umount((const char *)(a1 + 64)) < 0 )
{
v2 = _errno_location();
result = g_log(0LL, 16LL, "Error while unmounting: %i.", (unsigned int)*v2);
}
else
{
if ( unlink((const char *)(a1 + 192)) < 0 )
{
v3 = _errno_location();
g_log(0LL, 16LL, "Unlink failed: %i.", (unsigned int)*v3);
}
*(_WORD *)(a1 + 448) = 0;
tray_signal_emit("device-unmounted", a1);
result = device_free(a1);
}
return result;
}

original_code:
static void mount_remove_item(struct Device* ditem)
{
 int status;
 g_log (((gchar*) 0), G_LOG_LEVEL_MESSAGE, "Unmounting device %s.", ditem->source);
 status = umount(ditem->source);
 if (status < 0){
  g_log (((gchar*) 0), G_LOG_LEVEL_WARNING, "Error while unmounting: %i.", (*__errno_location ()));
  return;
 }
 status = unlink(ditem->target);
 if (status < 0)
  g_log (((gchar*) 0), G_LOG_LEVEL_WARNING, "Unlink failed: %i.", (*__errno_location ()));
 ditem->mounted = 0;
 tray_signal_emit("device-unmounted", ditem);
 device_free(ditem);
}

canonical_original_code:
static void mount_remove_item(struct Device *ditem)
{
 int status;
 g_log (((char *) 0), G_LOG_LEVEL_MESSAGE, "Unmounting device %s.", ditem->source);
 status = umount(ditem->source);
 if (status < 0){
  g_log (((char *) 0), G_LOG_LEVEL_WARNING, "Error while unmounting: %i.", (*__errno_location ()));
  return;
 }
 status = unlink(ditem->target);
 if (status < 0)
  g_log (((char *) 0), G_LOG_LEVEL_WARNING, "Unlink failed: %i.", (*__errno_location ()));
 ditem->mounted = 0;
 tray_signal_emit("device-unmounted", ditem);
 device_free(ditem);
}

user_defined_types: struct Device { char name[32]; char fstype[32]; char source[128]; char target[128]; char options[128]; short mounted; int id; }


decompiled_code:
__int64 __fastcall mount_add_item(__int64 a1)
{
const char *v1; // rsi
__int64 v2; // rcx
const char *v4; // rdi
bool v5; // cf
bool v6; // zf
__int64 result; // rax
int v8; // eax
__int64 v9; // [rsp+6h] [rbp-422h] BYREF
char s[1048]; // [rsp+10h] [rbp-418h] BYREF

v1 = (const char *)(a1 + 32);
v2 = 5LL;
v4 = "ntfs";
v5 = 0;
v6 = 0;
do
{
if ( !v2 )
break;
v5 = *v1 < (unsigned int)*v4;
v6 = *v1++ == *v4++;
--v2;
}
while ( v6 );
if ( (!v5 && !v6) == v5 )
v9 = 0x67332D7366746ELL;
else
strcpy((char *)&v9, "auto");
result = create_dir(a1 + 192, v1);
if ( !(_DWORD)result )
{
sprintf(
s,
"mount -t%s %s %s -O %s",
(const char *)&v9,
(const char *)(a1 + 64),
(const char *)(a1 + 192),
(const char *)(a1 + 320));
v8 = system(s);
if ( v8 > 0 )
{
result = g_log(0LL, 16LL, "Mount returns status %i for %s.", (unsigned int)v8, (const char *)(a1 + 64));
}
else
{
*(_WORD *)(a1 + 448) = 1;
result = tray_signal_emit("device-mounted", a1);
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
const char *v1; // rsi
__int64 v2; // rcx
const char *v4; // rdi
bool v5; // cf
bool v6; // zf
__int64 result; // rax
int v8; // eax
__int64 v9; // [rsp+6h] [rbp-422h] BYREF
char s[1048]; // [rsp+10h] [rbp-418h] BYREF

v1 = (const char *)(a1 + 32);
v2 = 5LL;
v4 = "ntfs";
v5 = 0;
v6 = 0;
do
{
if ( !v2 )
break;
v5 = *v1 < (unsigned int)*v4;
v6 = *v1++ == *v4++;
--v2;
}
while ( v6 );
if ( (!v5 && !v6) == v5 )
v9 = 0x67332D7366746ELL;
else
strcpy((char *)&v9, "auto");
result = create_dir(a1 + 192, v1);
if ( !(_DWORD)result )
{
sprintf(
s,
"mount -t%s %s %s -O %s",
(const char *)&v9,
(const char *)(a1 + 64),
(const char *)(a1 + 192),
(const char *)(a1 + 320));
v8 = system(s);
if ( v8 > 0 )
{
result = g_log(0LL, 16LL, "Mount returns status %i for %s.", (unsigned int)v8, (const char *)(a1 + 64));
}
else
{
*(_WORD *)(a1 + 448) = 1;
result = tray_signal_emit("device-mounted", a1);
}
}
return result;
}

original_code:
static void mount_add_item(struct Device* ditem)
{
 char cmd[1024];
 char driver[10];
 int status;
 if (strcmp(ditem->fstype, "ntfs") == 0)
  sprintf(&driver[0], "ntfs-3g");
 else
  sprintf(&driver[0], "auto");
 status = create_dir(ditem->target);
 if (status != CREATE_PATH_SUCCESS)
  return;
 sprintf(&cmd[0], "mount -t%s %s %s -O %s", driver,
   ditem->source, ditem->target, ditem->options);
 status = system(cmd);
 if (status > 0){
  g_log (((gchar*) 0), G_LOG_LEVEL_WARNING, "Mount returns status %i for %s.", status, ditem->source);
  return;
 }
 ditem->mounted = 1;
 tray_signal_emit("device-mounted", ditem);
}

canonical_original_code:
static void mount_add_item(struct Device *ditem)
{
 char cmd[1024];
 char driver[10];
 int status;
 if (strcmp(ditem->fstype, "ntfs") == 0)
  sprintf(&driver[0], "ntfs-3g");
 else
  sprintf(&driver[0], "auto");
 status = create_dir(ditem->target);
 if (status != CREATE_PATH_SUCCESS)
  return;
 sprintf(&cmd[0], "mount -t%s %s %s -O %s", driver,
   ditem->source, ditem->target, ditem->options);
 status = system(cmd);
 if (status > 0){
  g_log (((char *) 0), G_LOG_LEVEL_WARNING, "Mount returns status %i for %s.", status, ditem->source);
  return;
 }
 ditem->mounted = 1;
 tray_signal_emit("device-mounted", ditem);
}

variable_types:
cmd
char [1024]

variable_types:
driver
char [10]


decompiled_code:
__int64 mount_init()
{
__int64 result; // rax

result = g_array_new(0LL, 0LL, 8LL);
attached_devices = result;
return result;
}

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

result = g_array_new(0LL, 0LL, 8LL);
attached_devices = result;
return result;
}

original_code:
void mount_init()
{
 attached_devices = g_array_new((0), (0), sizeof(struct Device*));
}

canonical_original_code:
void mount_init()
{
 attached_devices = g_array_new((0), (0), sizeof(struct Device *));
}


decompiled_code:
__int64 mount_clean()
{
_QWORD *v0; // rdi
__int64 v1; // rbx
__int64 v2; // rdi

v0 = (_QWORD *)attached_devices;
if ( *(_DWORD *)(attached_devices + 8) )
{
v1 = 0LL;
do
{
v2 = *(_QWORD *)(*v0 + 8 * v1++);
mount_remove_item(v2);
v0 = (_QWORD *)attached_devices;
}
while ( *(_DWORD *)(attached_devices + 8) > (unsigned int)v1 );
}
return g_array_free(v0, 0LL);
}

canonical_decompiled_code:
__int64 func3()
{
_QWORD *v0; // rdi
__int64 v1; // rbx
__int64 v2; // rdi

v0 = (_QWORD *)attached_devices;
if ( *(_DWORD *)(attached_devices + 8) )
{
v1 = 0LL;
do
{
v2 = *(_QWORD *)(*v0 + 8 * v1++);
func0(v2);
v0 = (_QWORD *)attached_devices;
}
while ( *(_DWORD *)(attached_devices + 8) > (unsigned int)v1 );
}
return g_array_free(v0, 0LL);
}

original_code:
void mount_clean()
{
 int index;
 struct Device* ditem;
 for (index = 0; index < attached_devices->len; ++index) {
  ditem = (((struct Device**) (void *) (attached_devices)->data) [(index)]) ;
  mount_remove_item( ditem );
 }
 g_array_free(attached_devices, (0));
}

canonical_original_code:
void mount_clean()
{
 int index;
 struct Device *ditem;
 for (index = 0; index < attached_devices->len; ++index) {
  ditem = (((struct Device **) (void *) (attached_devices)->data) [(index)]) ;
  mount_remove_item( ditem );
 }
 g_array_free(attached_devices, (0));
}

variable_types: index int


decompiled_code:
__int64 __fastcall mount_add_device(__int64 a1)
{
__int64 result; // rax
int v2; // eax
__int64 v3; // rdi
__int64 v4; // [rsp+8h] [rbp-10h] BYREF

result = 0LL;
v4 = a1;
if ( a1 )
{
g_log(0LL, 32LL, "Mounting device %s.", (const char *)(a1 + 64));
v2 = last_device_id;
v3 = attached_devices;
++last_device_id;
*(_DWORD *)(v4 + 452) = v2;
g_array_append_vals(v3, &v4, 1LL);
mount_add_item(v4);
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1)
{
__int64 result; // rax
int v2; // eax
__int64 v3; // rdi
__int64 v4; // [rsp+8h] [rbp-10h] BYREF

result = 0LL;
v4 = a1;
if ( a1 )
{
g_log(0LL, 32LL, "Mounting device %s.", (const char *)(a1 + 64));
v2 = last_device_id;
v3 = attached_devices;
++last_device_id;
*(_DWORD *)(v4 + 452) = v2;
g_array_append_vals(v3, &v4, 1LL);
func1(v4);
result = 1LL;
}
return result;
}

original_code:
int mount_add_device(struct Device* device)
{
 if (!device)
  return 0;
 g_log (((gchar*) 0), G_LOG_LEVEL_MESSAGE, "Mounting device %s.", device->source);
 device->id = last_device_id++;
 g_array_append_vals (attached_devices, &(device), 1);
 mount_add_item(device);
 return 1;
}

canonical_original_code:
int mount_add_device(struct Device *device)
{
 if (!device)
  return 0;
 g_log (((char *) 0), G_LOG_LEVEL_MESSAGE, "Mounting device %s.", device->source);
 device->id = last_device_id++;
 g_array_append_vals (attached_devices, &(device), 1);
 mount_add_item(device);
 return 1;
}


decompiled_code:
__int64 __fastcall mount_remove_device(__int64 a1)
{
int v1; // edx
__int64 v2; // rsi
__int64 *v3; // rax
__int64 v4; // rbp
__int64 result; // rax

if ( !a1 )
return 0LL;
v1 = *(_DWORD *)(attached_devices + 8);
if ( !v1 )
return 0LL;
v2 = 0LL;
v3 = *(__int64 **)attached_devices;
do
{
v4 = *v3;
if ( a1 == *v3 )
goto LABEL_6;
v2 = (unsigned int)(v2 + 1);
++v3;
}
while ( (_DWORD)v2 != v1 );
result = 0LL;
if ( v4 )
{
LABEL_6:
g_array_remove_index(attached_devices, v2);
mount_remove_item(v4);
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1)
{
int v1; // edx
__int64 v2; // rsi
__int64 *v3; // rax
__int64 v4; // rbp
__int64 result; // rax

if ( !a1 )
return 0LL;
v1 = *(_DWORD *)(attached_devices + 8);
if ( !v1 )
return 0LL;
v2 = 0LL;
v3 = *(__int64 **)attached_devices;
do
{
v4 = *v3;
if ( a1 == *v3 )
goto LABEL_6;
v2 = (unsigned int)(v2 + 1);
++v3;
}
while ( (_DWORD)v2 != v1 );
result = 0LL;
if ( v4 )
{
LABEL_6:
g_array_remove_index(attached_devices, v2);
func0(v4);
result = 1LL;
}
return result;
}

original_code:
int mount_remove_device(struct Device* device)
{
 int index;
 struct Device* ditem;
 if( !device )
  return 0;
 ditem = ((void *)0);
 for( index = 0; index < attached_devices->len; ++index ){
  ditem = (((struct Device**) (void *) (attached_devices)->data) [(index)]) ;
  if( ditem == device )
   break;
 }
 if( !ditem )
  return 0;
 g_array_remove_index( attached_devices, index );
 mount_remove_item( ditem );
 return 1;
}

canonical_original_code:
int mount_remove_device(struct Device *device)
{
 int index;
 struct Device *ditem;
 if( !device )
  return 0;
 ditem = ((void *)0);
 for( index = 0; index < attached_devices->len; ++index ){
  ditem = (((struct Device **) (void *) (attached_devices)->data) [(index)]) ;
  if( ditem == device )
   break;
 }
 if( !ditem )
  return 0;
 g_array_remove_index( attached_devices, index );
 mount_remove_item( ditem );
 return 1;
}


decompiled_code:
__int64 __fastcall copy_env(char *dest, char *name, size_t n)
{
char *v4; // rsi

if ( !dest )
return 0xFFFFFFFFLL;
*dest = 0;
v4 = getenv(name);
if ( !v4 )
return 0xFFFFFFFFLL;
strncpy(dest, v4, n);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(char *dest, char *name, size_t n)
{
char *v4; // rsi

if ( !dest )
return 0xFFFFFFFFLL;
*dest = 0;
v4 = getenv(name);
if ( !v4 )
return 0xFFFFFFFFLL;
strncpy(dest, v4, n);
return 0LL;
}

original_code:
static int copy_env(char* dst, const char* name, size_t size)
{
 char* env_str;
 if (!dst)
  return -1;
 dst[0] = '\0';
 env_str = getenv(name);
 if (!env_str)
  return -1;
 strncpy(dst, env_str, size);
 return 0;
}

canonical_original_code:
static int copy_env(char *dst, char *name, unsigned long size)
{
 char *env_str;
 if (!dst)
  return -1;
 dst[0] = '\0';
 env_str = getenv(name);
 if (!env_str)
  return -1;
 strncpy(dst, env_str, size);
 return 0;
}

variable_types:
dst
char *

variable_types:
size
unsigned long


decompiled_code:
__int64 __fastcall device_init_from_data(_QWORD **a1, _QWORD *a2)
{
_QWORD *v2; // rax
_BYTE *v3; // rdi
signed __int64 v4; // rax
char *v5; // rsi
__int64 v6; // rcx
__int64 result; // rax

if ( !a2 )
return 0xFFFFFFFFLL;
v2 = *a1;
if ( !*a1 )
{
v2 = malloc(0x1C8uLL);
*a1 = v2;
}
v3 = (_BYTE *)((unsigned __int64)(v2 + 1) & 0xFFFFFFFFFFFFFFF8LL);
*v2 = *a2;
v2[56] = a2[56];
v4 = (char *)v2 - v3;
v5 = (char *)a2 - v4;
v6 = (unsigned int)(v4 + 456) >> 3;
result = 0LL;
qmemcpy(v3, v5, 8 * v6);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(_QWORD **a1, _QWORD *a2)
{
_QWORD *v2; // rax
_BYTE *v3; // rdi
signed __int64 v4; // rax
char *v5; // rsi
__int64 v6; // rcx
__int64 result; // rax

if ( !a2 )
return 0xFFFFFFFFLL;
v2 = *a1;
if ( !*a1 )
{
v2 = malloc(0x1C8uLL);
*a1 = v2;
}
v3 = (_BYTE *)((unsigned __int64)(v2 + 1) & 0xFFFFFFFFFFFFFFF8LL);
*v2 = *a2;
v2[56] = a2[56];
v4 = (char *)v2 - v3;
v5 = (char *)a2 - v4;
v6 = (unsigned int)(v4 + 456) >> 3;
result = 0LL;
qmemcpy(v3, v5, 8 * v6);
return result;
}

original_code:
int device_init_from_data(struct Device** tgt, char* data)
{
 if (!data)
  return -1;
 if (!*tgt)
  *tgt = malloc(DEVICE_SIZE);
 memcpy(*tgt, data, DEVICE_SIZE);
 return 0;
}

canonical_original_code:
int device_init_from_data(struct Device **tgt, char *data)
{
 if (!data)
  return -1;
 if (!*tgt)
  *tgt = malloc(DEVICE_SIZE);
 memcpy(*tgt, data, DEVICE_SIZE);
 return 0;
}

variable_types: struct Device { char name[32]; char fstype[32]; char source[128]; char target[128]; char options[128]; short mounted; int id; } **

variable_types:
data
char *


decompiled_code:
__int64 __fastcall device_init_from_env(char *dest)
{
char *v1; // rbp
char *v2; // r12
int v3; // eax
__int64 result; // rax

if ( (int)copy_env(dest + 64, "mount_device", 0x80uLL) < 0 )
{
g_log(0LL, 16LL, "Device not specified. Exit.");
result = 0xFFFFFFFFLL;
}
else if ( (int)copy_env(dest + 32, "mount_fstype", 0x20uLL) < 0 )
{
g_log(0LL, 16LL, "Device filesystem type not specified. Exit.");
result = 4294967294LL;
}
else
{
v1 = strdup(dest + 64);
v2 = _xpg_basename(v1);
v3 = copy_env(dest, "mount_name", 0x20uLL);
if ( !dest || v3 < 0 )
strncpy(dest, v2, 0x20uLL);
if ( (int)copy_env(dest + 192, "mount_target", 0x80uLL) < 0 )
snprintf(dest + 192, 0x80uLL, DEFAULT_TARGET, v2);
if ( (int)copy_env(dest + 320, "mount_options", 0x80uLL) < 0 )
strncpy(dest + 320, DEFAULT_OPTS, 0x80uLL);
*((_DWORD *)dest + 113) = -1;
*((_WORD *)dest + 224) = 0;
free(v1);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(char *dest)
{
char *v1; // rbp
char *v2; // r12
int v3; // eax
__int64 result; // rax

if ( (int)func0(dest + 64, "mount_device", 0x80uLL) < 0 )
{
g_log(0LL, 16LL, "Device not specified. Exit.");
result = 0xFFFFFFFFLL;
}
else if ( (int)func0(dest + 32, "mount_fstype", 0x20uLL) < 0 )
{
g_log(0LL, 16LL, "Device filesystem type not specified. Exit.");
result = 4294967294LL;
}
else
{
v1 = strdup(dest + 64);
v2 = _xpg_basename(v1);
v3 = func0(dest, "mount_name", 0x20uLL);
if ( !dest || v3 < 0 )
strncpy(dest, v2, 0x20uLL);
if ( (int)func0(dest + 192, "mount_target", 0x80uLL) < 0 )
snprintf(dest + 192, 0x80uLL, DEFAULT_TARGET, v2);
if ( (int)func0(dest + 320, "mount_options", 0x80uLL) < 0 )
strncpy(dest + 320, DEFAULT_OPTS, 0x80uLL);
*((_DWORD *)dest + 113) = -1;
*((_WORD *)dest + 224) = 0;
free(v1);
result = 0LL;
}
return result;
}

original_code:
int device_init_from_env(struct Device* ditem)
{
 char* base;
 char* source;
 if (copy_env(ditem->source, "mount_device", 128) < 0 ||
   ditem->source == '\0') {
  g_log (((gchar*) 0), G_LOG_LEVEL_WARNING, "Device not specified. Exit.");
  return -1;
 }
 if (copy_env(ditem->fstype, "mount_fstype", 32) < 0 ||
   ditem->fstype == '\0') {
  g_log (((gchar*) 0), G_LOG_LEVEL_WARNING, "Device filesystem type not specified. Exit.");
  return -2;
 }
 source = strdup(ditem->source);
 base = __xpg_basename(source);
 if (copy_env(ditem->name, "mount_name", 32) < 0 ||
   ditem->name == '\0')
  strncpy(ditem->name, base, 32);
 if (copy_env(ditem->target, "mount_target", 128) < 0 ||
   ditem->target == '\0')
  snprintf(ditem->target, 128, DEFAULT_TARGET, base);
 if (copy_env(ditem->options, "mount_options", 128) < 0 ||
   ditem->options == '\0')
  strncpy(ditem->options, DEFAULT_OPTS, 128);
 ditem->mounted = 0;
 ditem->id = -1;
 free(source);
 return 0;
}

canonical_original_code:
int device_init_from_env(struct Device *ditem)
{
 char *base;
 char *source;
 if (copy_env(ditem->source, "mount_device", 128) < 0 ||
   ditem->source == '\0') {
  g_log (((char *) 0), G_LOG_LEVEL_WARNING, "Device not specified. Exit.");
  return -1;
 }
 if (copy_env(ditem->fstype, "mount_fstype", 32) < 0 ||
   ditem->fstype == '\0') {
  g_log (((char *) 0), G_LOG_LEVEL_WARNING, "Device filesystem type not specified. Exit.");
  return -2;
 }
 source = strdup(ditem->source);
 base = __xpg_basename(source);
 if (copy_env(ditem->name, "mount_name", 32) < 0 ||
   ditem->name == '\0')
  strncpy(ditem->name, base, 32);
 if (copy_env(ditem->target, "mount_target", 128) < 0 ||
   ditem->target == '\0')
  snprintf(ditem->target, 128, DEFAULT_TARGET, base);
 if (copy_env(ditem->options, "mount_options", 128) < 0 ||
   ditem->options == '\0')
  strncpy(ditem->options, DEFAULT_OPTS, 128);
 ditem->mounted = 0;
 ditem->id = -1;
 free(source);
 return 0;
}

variable_types:
base
char *

variable_types:
source
char *


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

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

original_code:
void device_free( struct Device* tgt )
{
 if( !tgt )
  return;
 free( tgt );
}

canonical_original_code:
void device_free(struct Device *tgt)
{
 if( !tgt )
  return;
 free( tgt );
}