decompiled_code:
_BOOL8 __fastcall server_sprawdzil(caddr_t resp, struct sockaddr_in *raddr)
{
if ( !gethostbyaddr(&raddr->sin_addr, 4u, raddr->sin_family) )
inet_ntoa(raddr->sin_addr);
if ( *(_DWORD *)resp )
{
if ( *(_DWORD *)resp == 1 )
++received;
}
else
{
res = 0;
++received;
}
return received == relevant;
}

canonical_decompiled_code:
_BOOL8 __fastcall func8(caddr_t resp, struct sockaddr_in *raddr)
{
if ( !gethostbyaddr(&raddr->sin_addr, 4u, raddr->sin_family) )
inet_ntoa(raddr->sin_addr);
if ( *(_DWORD *)resp )
{
if ( *(_DWORD *)resp == 1 )
++received;
}
else
{
res = 0;
++received;
}
return received == relevant;
}

original_code:
int server_sprawdzil(int *ans, struct sockaddr_in *raddr)
{
  struct hostent *h;
  char *hostname;
  h = gethostbyaddr((char *)&(raddr->sin_addr),
      sizeof(struct in_addr),raddr->sin_family);
  if (h)
    hostname = h->h_name;
  else
    hostname = inet_ntoa(raddr->sin_addr);
  ;
  if (*ans == 0) {
    res = 0;
    received++;
  } else if (*ans == 1)
    received++;
  if (received == relevant)
    return 1;
  return 0;
}

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

variable_types:
hostname
char *


repo: mmakowski/cs-mimuw

decompiled_code:
__int64 __fastcall server_active(caddr_t resp, struct sockaddr_in *raddr)
{
struct hostent *v3; // rax
char *v4; // rbp
size_t v5; // rax
char *v6; // rax
char *v7; // rbx
int v8; // eax

if ( !*(_DWORD *)resp )
return 0LL;
v3 = gethostbyaddr(&raddr->sin_addr, 4u, raddr->sin_family);
if ( v3 )
v4 = v3->h_name;
else
v4 = inet_ntoa(raddr->sin_addr);
v5 = strlen(v4);
v6 = (char *)malloc(v5 + 1);
v7 = v6;
if ( !v6 )
exit(1);
strcpy(v6, v4);
v8 = count;
if ( count <= 99 )
(&servers)[count] = v7;
count = v8 + 1;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func9(caddr_t resp, struct sockaddr_in *raddr)
{
struct hostent *v3; // rax
char *v4; // rbp
size_t v5; // rax
char *v6; // rax
char *v7; // rbx
int v8; // eax

if ( !*(_DWORD *)resp )
return 0LL;
v3 = gethostbyaddr(&raddr->sin_addr, 4u, raddr->sin_family);
if ( v3 )
v4 = v3->h_name;
else
v4 = inet_ntoa(raddr->sin_addr);
v5 = strlen(v4);
v6 = (char *)malloc(v5 + 1);
v7 = v6;
if ( !v6 )
exit(1);
strcpy(v6, v4);
v8 = count;
if ( count <= 99 )
(&servers)[count] = v7;
count = v8 + 1;
return 0LL;
}

original_code:
int server_active(int *ans, struct sockaddr_in *raddr)
{
  struct hostent *h;
  char *hostname, *hcpy;
  if (*ans) {
    h = gethostbyaddr((char *)&(raddr->sin_addr),
        sizeof(struct in_addr),raddr->sin_family);
    if (h)
      hostname = h->h_name;
    else
      hostname = inet_ntoa(raddr->sin_addr);
    if ((hcpy = malloc(strlen(hostname) + 1)) == 0)
      exit(1);
    strcpy(hcpy, hostname);
    if (count < 100)
      servers[count] = hcpy;
    count++;
    ;
  }
  return 0;
}

canonical_original_code:
int server_active(int *ans, struct sockaddr_in *raddr)
{
  struct hostent *h;
  char *hostname; char *hcpy;
  if (*ans) {
    h = gethostbyaddr((char *)&(raddr->sin_addr),
        sizeof(struct in_addr),raddr->sin_family);
    if (h)
      hostname = h->h_name;
    else
      hostname = inet_ntoa(raddr->sin_addr);
    if ((hcpy = malloc(strlen(hostname) + 1)) == 0)
      exit(1);
    strcpy(hcpy, hostname);
    if (count < 100)
      servers[count] = hcpy;
    count++;
    ;
  }
  return 0;
}

variable_types:
ans
int *

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

variable_types:
hcpy
char *

return_type: int

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

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


decompiled_code:
__int64 find_servers()
{
count = 0;
clnt_broadcast(0x32112300uLL, 1uLL, 3uLL, xdr_str, my_name, (xdrproc_t)xdr_int, ans_1, (resultproc_t)server_active);
return (unsigned int)count;
}

canonical_decompiled_code:
__int64 func10()
{
count = 0;
clnt_broadcast(0x32112300uLL, 1uLL, 3uLL, xdr_str, my_name, (xdrproc_t)xdr_int, ans_1, (resultproc_t)server_active);
return (unsigned int)count;
}

original_code:
int find_servers()
{
  static int ans = 0;
  enum clnt_stat clnt_stat;
  count = 0;
  clnt_stat = clnt_broadcast(((u_long)0x32112300), ((u_long)1),
        ((u_long)3), (xdrproc_t) xdr_str, my_name, (xdrproc_t) xdr_int,
        (char *)&ans, (resultproc_t)server_active);
  return count;
}

canonical_original_code:
int find_servers()
{
  static int ans = 0;
  enum clnt_stat clnt_stat;
  count = 0;
  clnt_stat = clnt_broadcast(((unsigned long)0x32112300), ((unsigned long)1),
        ((unsigned long)3), (int (*)(struct XDR *, void *, ...)) xdr_str, my_name, (int (*)(struct XDR *, void *, ...)) xdr_int,
        (char *)&ans, (int (*)(char *__resp, struct sockaddr_in *__raddr))server_active);
  return count;
}

variable_types: ans int

variable_types: enum clnt_stat { RPC_SUCCESS=0, RPC_CANTENCODEARGS=1, RPC_CANTDECODERES=2, RPC_CANTSEND=3, RPC_CANTRECV=4, RPC_TIMEDOUT=5, RPC_VERSMISMATCH=6, RPC_AUTHERROR=7, RPC_PROGUNAVAIL=8, RPC_PROGVERSMISMATCH=9, RPC_PROCUNAVAIL=10, RPC_CANTDECODEARGS=11, RPC_SYSTEMERROR=12, RPC_NOBROADCAST=21, RPC_UNKNOWNHOST=13, RPC_UNKNOWNPROTO=17, RPC_UNKNOWNADDR=19, RPC_RPCBFAILURE=14, RPC_PROGNOTREGISTERED=15, RPC_N2AXLATEFAILURE=22, RPC_FAILED=16, RPC_INTR=18, RPC_TLIERROR=20, RPC_UDERROR=23, RPC_INPROGRESS=24, RPC_STALERACHANDLE=25 }

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:
enum clnt_stat close_session()
{
return clnt_broadcast(
0x32112300uLL,
1uLL,
4uLL,
xdr_str,
my_name,
(xdrproc_t)xdr_void,
0LL,
(resultproc_t)server_closing);
}

canonical_decompiled_code:
enum clnt_stat func11()
{
return clnt_broadcast(
0x32112300uLL,
1uLL,
4uLL,
xdr_str,
my_name,
(xdrproc_t)xdr_void,
0LL,
(resultproc_t)server_closing);
}

original_code:
void close_session()
{
  enum clnt_stat clnt_stat;
  clnt_stat = clnt_broadcast(((u_long)0x32112300), ((u_long)1),
        ((u_long)4), (xdrproc_t) xdr_str, my_name, (xdrproc_t) xdr_void,
        0, (resultproc_t)server_closing);
}

canonical_original_code:
void close_session()
{
  enum clnt_stat clnt_stat;
  clnt_stat = clnt_broadcast(((unsigned long)0x32112300), ((unsigned long)1),
        ((unsigned long)4), (int (*)(struct XDR *, void *, ...)) xdr_str, my_name, (int (*)(struct XDR *, void *, ...)) xdr_void,
        0, (int (*)(char *__resp, struct sockaddr_in *__raddr))server_closing);
}

return_type: void

user_defined_types: enum clnt_stat { RPC_SUCCESS=0, RPC_CANTENCODEARGS=1, RPC_CANTDECODERES=2, RPC_CANTSEND=3, RPC_CANTRECV=4, RPC_TIMEDOUT=5, RPC_VERSMISMATCH=6, RPC_AUTHERROR=7, RPC_PROGUNAVAIL=8, RPC_PROGVERSMISMATCH=9, RPC_PROCUNAVAIL=10, RPC_CANTDECODEARGS=11, RPC_SYSTEMERROR=12, RPC_NOBROADCAST=21, RPC_UNKNOWNHOST=13, RPC_UNKNOWNPROTO=17, RPC_UNKNOWNADDR=19, RPC_RPCBFAILURE=14, RPC_PROGNOTREGISTERED=15, RPC_N2AXLATEFAILURE=22, RPC_FAILED=16, RPC_INTR=18, RPC_TLIERROR=20, RPC_UDERROR=23, RPC_INPROGRESS=24, RPC_STALERACHANDLE=25 }


original_code:
char is_prime(int i)
{
  static int ans = -1;
  char chrq[sizeof(int) + 256];
  received = 0;
  res = 1;
  memcpy(chrq, &i, sizeof(int));
  memcpy(chrq + sizeof(int), my_name, 256);
  clnt_broadcast(((u_long)0x32112300), ((u_long)1),
   ((u_long)2), (xdrproc_t) xdr_check_req, chrq, (xdrproc_t) xdr_int,
   (char *)&ans, (resultproc_t)server_sprawdzil);
  return res;
}

canonical_original_code:
char is_prime(int i)
{
  static int ans = -1;
  char chrq[-1];
  received = 0;
  res = 1;
  memcpy(chrq, &i, sizeof(int));
  memcpy(chrq + sizeof(int), my_name, 256);
  clnt_broadcast(((unsigned long)0x32112300), ((unsigned long)1),
   ((unsigned long)2), (int (*)(struct XDR *, void *, ...)) xdr_check_req, chrq, (int (*)(struct XDR *, void *, ...)) xdr_int,
   (char *)&ans, (int (*)(char *__resp, struct sockaddr_in *__raddr))server_sprawdzil);
  return res;
}

variable_types: i int

variable_types:
chrq
char [-1]

return_type: char


decompiled_code:
int __fastcall set_divider(int a1)
{
int result; // eax
char in[4]; // [rsp+Ch] [rbp-Ch] BYREF

*(_DWORD *)in = a1;
result = callrpc(
(&servers)[relevant],
0x32112300uLL,
1uLL,
1uLL,
(const xdrproc_t)xdr_int,
in,
(const xdrproc_t)xdr_void,
0LL);
if ( result )
exit(1);
++relevant;
return result;
}

canonical_decompiled_code:
int __fastcall func13(int a1)
{
int result; // eax
char in[4]; // [rsp+Ch] [rbp-Ch] BYREF

*(_DWORD *)in = a1;
result = callrpc(
(&servers)[relevant],
0x32112300uLL,
1uLL,
1uLL,
(const xdrproc_t)xdr_int,
in,
(const xdrproc_t)xdr_void,
0LL);
if ( result )
exit(1);
++relevant;
return result;
}

original_code:
void set_divider(int d)
{
  ;
  if (callrpc(servers[relevant], ((u_long)0x32112300), ((u_long)1), ((u_long)1),
       (xdrproc_t) xdr_int, (char *)&d, (xdrproc_t) xdr_void, 0) != 0)
    exit(1);
  relevant++;
}

canonical_original_code:
void set_divider(int d)
{
  ;
  if (callrpc(servers[relevant], ((unsigned long)0x32112300), ((unsigned long)1), ((unsigned long)1),
       (int (*)(struct XDR *, void *, ...)) xdr_int, (char *)&d, (int (*)(struct XDR *, void *, ...)) xdr_void, 0) != 0)
    exit(1);
  relevant++;
}

variable_types: d int


decompiled_code:
_BOOL8 __fastcall xdr_str(XDR *a1, void *a2)
{
return xdr_vector(a1, (char *)a2, 0x100u, 1u, (xdrproc_t)xdr_char) != 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func14(XDR *a1, void *a2)
{
return xdr_vector(a1, (char *)a2, 0x100u, 1u, (xdrproc_t)xdr_char) != 0;
}

original_code:
bool_t xdr_str(XDR *xdrs, char *str)
{
  if (!xdr_vector(xdrs, str, 256, sizeof(char), (xdrproc_t) xdr_char))
    return (0);
  return (1);
}

canonical_original_code:
int xdr_str(struct XDR *xdrs, char *str)
{
  if (!xdr_vector(xdrs, str, 256, sizeof(char), (int (*)(struct XDR *, void *, ...)) xdr_char))
    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:
str
char *


decompiled_code:
_BOOL8 __fastcall xdr_check_req(XDR *a1, void *a2)
{
return xdr_vector(a1, (char *)a2, 0x104u, 1u, (xdrproc_t)xdr_char) != 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func15(XDR *a1, void *a2)
{
return xdr_vector(a1, (char *)a2, 0x104u, 1u, (xdrproc_t)xdr_char) != 0;
}

original_code:
bool_t xdr_check_req(XDR *xdrs, char *chrq)
{
  if (!xdr_vector(xdrs, chrq, 256 + sizeof(int), sizeof(char), (xdrproc_t) xdr_char))
    return (0);
  return (1);
}

canonical_original_code:
int xdr_check_req(struct XDR *xdrs, char *chrq)
{
  if (!xdr_vector(xdrs, chrq, 256 + sizeof(int), sizeof(char), (int (*)(struct XDR *, void *, ...)) xdr_char))
    return (0);
  return (1);
}

variable_types:
chrq
char *


wczytanieDanych

decompiled_code:
__int64 __fastcall wczytanieDanych(_QWORD *a1, int *a2, int *a3, __int64 a4)
{
void *v5; // rax
__int64 result; // rax
__int64 v7; // rbx
_QWORD *v8; // r14
void *v9; // rax

_isoc99_scanf("%d, %d, %d\n", a2, a3, a4);
if ( *a2 <= 0 )
{
fwrite("Nieprawidlowa liczba danych wejsciowych (musi byc >= 1)\n", 1uLL, 0x38uLL, stderr);
result = 0LL;
}
else if ( *a3 <= 1 )
{
fwrite("Nieprawidlowa dlugosc liczby (musi byc >= 2)\n", 1uLL, 0x2DuLL, stderr);
result = 0LL;
}
else
{
v5 = calloc(*a2, 8uLL);
*a1 = v5;
if ( !v5 )
syserr("calloc");
result = (unsigned int)*a2;
if ( (int)result > 0 )
{
v7 = 0LL;
while ( 1 )
{
v8 = (_QWORD *)(*a1 + 8 * v7);
v9 = malloc(*a3 + 1);
*v8 = v9;
if ( !v9 )
syserr("malloc");
_isoc99_scanf("%s\n", *(_QWORD *)(*a1 + 8 * v7));
if ( strlen(*(const char **)(*a1 + 8 * v7)) != *a3 )
break;
result = (unsigned int)*a2;
if ( (int)result <= (int)++v7 )
return result;
}
fprintf(stderr, "Bledna dlugosc liczby wejsciowej (%d liczba z kolei)\n", (unsigned int)(v7 + 1));
result = 0LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(_QWORD *a1, int *a2, int *a3, __int64 a4)
{
void *v5; // rax
__int64 result; // rax
__int64 v7; // rbx
_QWORD *v8; // r14
void *v9; // rax

_isoc99_scanf("%d, %d, %d\n", a2, a3, a4);
if ( *a2 <= 0 )
{
fwrite("Nieprawidlowa liczba danych wejsciowych (musi byc >= 1)\n", 1uLL, 0x38uLL, stderr);
result = 0LL;
}
else if ( *a3 <= 1 )
{
fwrite("Nieprawidlowa dlugosc liczby (musi byc >= 2)\n", 1uLL, 0x2DuLL, stderr);
result = 0LL;
}
else
{
v5 = calloc(*a2, 8uLL);
*a1 = v5;
if ( !v5 )
syserr("calloc");
result = (unsigned int)*a2;
if ( (int)result > 0 )
{
v7 = 0LL;
while ( 1 )
{
v8 = (_QWORD *)(*a1 + 8 * v7);
v9 = malloc(*a3 + 1);
*v8 = v9;
if ( !v9 )
syserr("malloc");
_isoc99_scanf("%s\n", *(_QWORD *)(*a1 + 8 * v7));
if ( strlen(*(const char **)(*a1 + 8 * v7)) != *a3 )
break;
result = (unsigned int)*a2;
if ( (int)result <= (int)++v7 )
return result;
}
fprintf(stderr, "Bledna dlugosc liczby wejsciowej (%d liczba z kolei)\n", (unsigned int)(v7 + 1));
result = 0LL;
}
}
return result;
}

original_code:
int wczytanieDanych(char ***liczba, int *ileLiczb, int *dlugoscLiczby, int *dlugoscKom)
{
  int i;
  scanf("%d, %d, %d\n", ileLiczb, dlugoscLiczby, dlugoscKom);
  if (*ileLiczb < 1) {
    fprintf(stderr, "Nieprawidlowa liczba danych wejsciowych (musi byc >= 1)\n");
    return 0;
  }
  if (*dlugoscLiczby < 2) {
    fprintf(stderr, "Nieprawidlowa dlugosc liczby (musi byc >= 2)\n");
    return 0;
  }
  if ((*liczba = calloc(*ileLiczb, sizeof(char*))) == 0)
    syserr("calloc");
  for (i = 0; i < *ileLiczb; i++) {
    if (((*liczba)[i] = malloc(*dlugoscLiczby + 1)) == 0)
      syserr("malloc");
    scanf("%s\n", (*liczba)[i]);
    if (strlen((*liczba)[i]) != *dlugoscLiczby) {
      fprintf(stderr, "Bledna dlugosc liczby wejsciowej (%d liczba z kolei)\n", i + 1);
      return 0;
    }
  }
  return *ileLiczb;
}

canonical_original_code:
int wczytanieDanych(char ***liczba, int *ileLiczb, int *dlugoscLiczby, int *dlugoscKom)
{
  int i;
  scanf("%d, %d, %d\n", ileLiczb, dlugoscLiczby, dlugoscKom);
  if (*ileLiczb < 1) {
    fprintf(stderr, "Nieprawidlowa liczba danych wejsciowych (musi byc >= 1)\n");
    return 0;
  }
  if (*dlugoscLiczby < 2) {
    fprintf(stderr, "Nieprawidlowa dlugosc liczby (musi byc >= 2)\n");
    return 0;
  }
  if ((*liczba = calloc(*ileLiczb, sizeof(char *))) == 0)
    syserr("calloc");
  for (i = 0; i < *ileLiczb; i++) {
    if (((*liczba)[i] = malloc(*dlugoscLiczby + 1)) == 0)
      syserr("malloc");
    scanf("%s\n", (*liczba)[i]);
    if (strlen((*liczba)[i]) != *dlugoscLiczby) {
      fprintf(stderr, "Bledna dlugosc liczby wejsciowej (%d liczba z kolei)\n", i + 1);
      return 0;
    }
  }
  return *ileLiczb;
}

variable_types:
liczba
char ***

variable_types:
ileLiczb
int *

variable_types:
dlugoscLiczby
int *

variable_types:
dlugoscKom
int *


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // ebx
unsigned int v4; // er12
unsigned int v5; // ebp
unsigned int v6; // er13
__time_t v7; // rsi
__suseconds_t v8; // rdx
struct timeval v10; // [rsp+0h] [rbp-68h] BYREF
struct timeval tv; // [rsp+10h] [rbp-58h] BYREF
unsigned int v12; // [rsp+2Ch] [rbp-3Ch] BYREF
unsigned int v13; // [rsp+30h] [rbp-38h] BYREF
unsigned int v14; // [rsp+34h] [rbp-34h] BYREF
__int64 v15[6]; // [rsp+38h] [rbp-30h] BYREF

v3 = msgget(1234, 1920);
if ( v3 == -1 )
syserr("msgget (kolSys)");
v4 = msgget(1235, 1920);
if ( v4 == -1 )
syserr("msgget (kolCyfry)");
v5 = semget(1236, 1, 1920);
if ( v5 == -1 )
syserr("semget (semStart)");
wczytanieDanych(v15, (int *)&v14, (int *)&v13, (__int64)&v12);
v6 = v13 + (int)(v14 - 1) / 10 + 1;
sp_uruchomienieProcesow(v6, v3, v5, v13, v14, v12, v15[0]);
if ( gettimeofday(&tv, 0LL) )
syserr("gettimeofday");
sp_startObliczen(v5);
sp_czekanieNaKoniec(v6, v3);
if ( gettimeofday(&v10, 0LL) )
syserr("gettimeofday");
v7 = v10.tv_sec - tv.tv_sec;
v8 = v10.tv_usec - tv.tv_usec;
if ( v10.tv_usec - tv.tv_usec < 0 )
{
--v7;
v8 += 1000000LL;
}
printf("czas: %ld.%06ld s\n", v7, v8);
sp_zebranieWynikow(v6, v14, v4, v3);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // ebx
unsigned int v4; // er12
unsigned int v5; // ebp
unsigned int v6; // er13
__time_t v7; // rsi
__suseconds_t v8; // rdx
struct timeval v10; // [rsp+0h] [rbp-68h] BYREF
struct timeval tv; // [rsp+10h] [rbp-58h] BYREF
unsigned int v12; // [rsp+2Ch] [rbp-3Ch] BYREF
unsigned int v13; // [rsp+30h] [rbp-38h] BYREF
unsigned int v14; // [rsp+34h] [rbp-34h] BYREF
__int64 v15[6]; // [rsp+38h] [rbp-30h] BYREF

v3 = msgget(1234, 1920);
if ( v3 == -1 )
syserr("msgget (kolSys)");
v4 = msgget(1235, 1920);
if ( v4 == -1 )
syserr("msgget (kolCyfry)");
v5 = semget(1236, 1, 1920);
if ( v5 == -1 )
syserr("semget (semStart)");
func0(v15, (int *)&v14, (int *)&v13, (__int64)&v12);
v6 = v13 + (int)(v14 - 1) / 10 + 1;
sp_uruchomienieProcesow(v6, v3, v5, v13, v14, v12, v15[0]);
if ( gettimeofday(&tv, 0LL) )
syserr("gettimeofday");
sp_startObliczen(v5);
sp_czekanieNaKoniec(v6, v3);
if ( gettimeofday(&v10, 0LL) )
syserr("gettimeofday");
v7 = v10.tv_sec - tv.tv_sec;
v8 = v10.tv_usec - tv.tv_usec;
if ( v10.tv_usec - tv.tv_usec < 0 )
{
--v7;
v8 += 1000000LL;
}
printf("czas: %ld.%06ld s\n", v7, v8);
sp_zebranieWynikow(v6, v14, v4, v3);
return 0;
}

original_code:
int main()
{
  char **liczby;
  int ileLiczb, dlugoscLiczby, ileProcesow, dlugoscKom;
  struct timeval tvStart, tvKoniec;
  long sec, usec;
  int kolSys, kolCyfry; int semStart;
  if ((kolSys = msgget(1234L, 0600 | 01000 | 02000)) == -1)syserr("msgget (kolSys)");if ((kolCyfry = msgget(1235L, 0600 | 01000 | 02000)) == -1)syserr("msgget (kolCyfry)");if ((semStart = semget(1236L, 1, 0600 | 01000 | 02000)) == -1)syserr("semget (semStart)");
  wczytanieDanych(&liczby, &ileLiczb, &dlugoscLiczby, &dlugoscKom);
  ileProcesow = dlugoscLiczby + (ileLiczb - 1) / 10 + 1;
  sp_uruchomienieProcesow(ileProcesow, kolSys, semStart, dlugoscLiczby, ileLiczb, dlugoscKom, liczby);
  if (gettimeofday(&tvStart, 0) != 0)
    syserr("gettimeofday");
  sp_startObliczen(semStart);
  sp_czekanieNaKoniec(ileProcesow, kolSys);
  if (gettimeofday(&tvKoniec, 0) != 0)
    syserr("gettimeofday");
  sec = tvKoniec.tv_sec - tvStart.tv_sec;
  usec = tvKoniec.tv_usec - tvStart.tv_usec;
  if (usec < 0) {
    sec--;
    usec += 1000000;
  }
  printf("czas: %ld.%06ld s\n", sec, usec);
  sp_zebranieWynikow(ileProcesow, ileLiczb, kolCyfry, kolSys);
  return 0;
}

canonical_original_code:
int main()
{
  char **liczby;
  int ileLiczb; int dlugoscLiczby; int ileProcesow; int dlugoscKom;
  struct timeval tvStart; struct timeval tvKoniec;
  long sec; long usec;
  int kolSys; int kolCyfry; int semStart;
  if ((kolSys = msgget(1234L, 0600 | 01000 | 02000)) == -1)syserr("msgget (kolSys)");if ((kolCyfry = msgget(1235L, 0600 | 01000 | 02000)) == -1)syserr("msgget (kolCyfry)");if ((semStart = semget(1236L, 1, 0600 | 01000 | 02000)) == -1)syserr("semget (semStart)");
  wczytanieDanych(&liczby, &ileLiczb, &dlugoscLiczby, &dlugoscKom);
  ileProcesow = dlugoscLiczby + (ileLiczb - 1) / 10 + 1;
  sp_uruchomienieProcesow(ileProcesow, kolSys, semStart, dlugoscLiczby, ileLiczb, dlugoscKom, liczby);
  if (gettimeofday(&tvStart, 0) != 0)
    syserr("gettimeofday");
  sp_startObliczen(semStart);
  sp_czekanieNaKoniec(ileProcesow, kolSys);
  if (gettimeofday(&tvKoniec, 0) != 0)
    syserr("gettimeofday");
  sec = tvKoniec.tv_sec - tvStart.tv_sec;
  usec = tvKoniec.tv_usec - tvStart.tv_usec;
  if (usec < 0) {
    sec--;
    usec += 1000000;
  }
  printf("czas: %ld.%06ld s\n", sec, usec);
  sp_zebranieWynikow(ileProcesow, ileLiczb, kolCyfry, kolSys);
  return 0;
}

variable_types:
liczby
char **

variable_types: ileLiczb int

variable_types: dlugoscLiczby int

variable_types: ileProcesow int

variable_types: dlugoscKom int

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

variable_types: sec long

variable_types: usec long

variable_types: kolSys int

variable_types: kolCyfry int

variable_types: semStart int


start

decompiled_code:
// positive sp value has been detected, the output may be wrong!
void __fastcall __noreturn start(__int64 a1, __int64 a2, void (*a3)(void))
{
__int64 v3; // rax
int v4; // esi
__int64 v5; // [rsp-8h] [rbp-8h] BYREF
char *retaddr; // [rsp+0h] [rbp+0h] BYREF

v4 = v5;
v5 = v3;
_libc_start_main(
(int (__fastcall *)(int, char **, char **))main,
v4,
&retaddr,
_libc_csu_init,
_libc_csu_fini,
a3,
&v5);
__halt();
}

canonical_decompiled_code:
void __fastcall __noreturn func1(__int64 a1, __int64 a2, void (*a3)(void))
{
__int64 v3; // rax
int v4; // esi
__int64 v5; // [rsp-8h] [rbp-8h] BYREF
char *retaddr; // [rsp+0h] [rbp+0h] BYREF

v4 = v5;
v5 = v3;
_libc_start_main(
(int (__fastcall *)(int, char **, char **))main,
v4,
&retaddr,
_libc_csu_init,
_libc_csu_fini,
a3,
&v5);
__halt();
}

original_code:
void start()
{
  write(all, "start", 5);
}


decompiled_code:
_BOOL8 __fastcall xdr_str(XDR *a1, char *a2)
{
return xdr_vector(a1, a2, 0x100u, 1u, (xdrproc_t)xdr_char) != 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func7(XDR *a1, char *a2)
{
return xdr_vector(a1, a2, 0x100u, 1u, (xdrproc_t)xdr_char) != 0;
}

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:
str
char *


decompiled_code:
_BOOL8 __fastcall xdr_check_req(XDR *a1, char *a2)
{
return xdr_vector(a1, a2, 0x104u, 1u, (xdrproc_t)xdr_char) != 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func8(XDR *a1, char *a2)
{
return xdr_vector(a1, a2, 0x104u, 1u, (xdrproc_t)xdr_char) != 0;
}

variable_types:
chrq
char *


decompiled_code:
__int64 __fastcall ustaw_dzielnik_svc(int *a1)
{
liczba = *a1;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func9(int *a1)
{
liczba = *a1;
return 0LL;
}

original_code:
char *ustaw_dzielnik_svc(char *l)
{
  liczba = *((int *)l);
  ;
  return 0;
}

variable_types:
l
char *

return_type: char *


decompiled_code:
int *__fastcall zglos_sie_svc(char *src)
{
int *result; // rax
size_t v3; // rax
char *v4; // rdi

if ( sesja )
{
r_1 = 0;
result = &r_1;
}
else
{
v3 = strlen(src);
v4 = (char *)malloc(v3 + 1);
host = v4;
if ( !v4 )
exit(1);
strcpy(v4, src);
sesja = 1;
r_1 = 1;
result = &r_1;
}
return result;
}

canonical_decompiled_code:
int *__fastcall func10(char *src)
{
int *result; // rax
size_t v3; // rax
char *v4; // rdi

if ( sesja )
{
r_1 = 0;
result = &r_1;
}
else
{
v3 = strlen(src);
v4 = (char *)malloc(v3 + 1);
host = v4;
if ( !v4 )
exit(1);
strcpy(v4, src);
sesja = 1;
r_1 = 1;
result = &r_1;
}
return result;
}

original_code:
char *zglos_sie_svc(char *a)
{
  static int r;
  if (!sesja) {
    ;
    if ((host = malloc(strlen(a) + 1)) == 0)
      exit(1);
    strcpy(host, a);
    sesja = 1;
    r = 1;
  } else
    r = 0;
  return (char *)&r;
}

variable_types:
a
char *

variable_types: r int


decompiled_code:
int *__fastcall sprawdz_liczbe_svc(__int64 a1)
{
int v1; // ebx
int v2; // ebp
int *result; // rax

if ( sesja )
{
v1 = liczba;
if ( liczba == -1 || (v2 = *(_DWORD *)a1, max_spr >= *(_DWORD *)a1) )
{
r_0 = -1;
}
else if ( !strcmp((const char *)(a1 + 4), host) )
{
max_spr = v2;
r_0 = v2 % v1 != 0;
}
else
{
r_0 = -1;
}
result = &r_0;
}
else
{
r_0 = -1;
result = &r_0;
}
return result;
}

canonical_decompiled_code:
int *__fastcall func11(__int64 a1)
{
int v1; // ebx
int v2; // ebp
int *result; // rax

if ( sesja )
{
v1 = liczba;
if ( liczba == -1 || (v2 = *(_DWORD *)a1, max_spr >= *(_DWORD *)a1) )
{
r_0 = -1;
}
else if ( !strcmp((const char *)(a1 + 4), host) )
{
max_spr = v2;
r_0 = v2 % v1 != 0;
}
else
{
r_0 = -1;
}
result = &r_0;
}
else
{
r_0 = -1;
result = &r_0;
}
return result;
}

original_code:
char *sprawdz_liczbe_svc(char *l)
{
  static int r;
  char *sess = l + sizeof(int);
  int li = *((int *)l);
  ;
  ;
  if (!sesja || liczba == -1 || li <= max_spr)
    r = -1;
  else if (strcmp(sess, host) != 0)
    r = -1;
  else {
    max_spr = li;
    if (li % liczba == 0)
      r = 0;
    else
      r = 1;
  }
  return (char *)&r;
}

variable_types:
sess
char *

variable_types: li int


decompiled_code:
__int64 __fastcall koniec_sesji_svc(const char *a1)
{
char *v1; // rbx

v1 = host;
if ( !strcmp(a1, host) )
{
free(v1);
liczba = -1;
sesja = 0;
max_spr = 0;
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func12(const char *a1)
{
char *v1; // rbx

v1 = host;
if ( !strcmp(a1, host) )
{
free(v1);
liczba = -1;
sesja = 0;
max_spr = 0;
}
return 0LL;
}

original_code:
char *koniec_sesji_svc(char *a)
{
  if (strcmp(a, host) == 0) {
    ;
    free(host);
    liczba = -1;
    sesja = 0;
    max_spr = 0;
  }
  return 0;
}


main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
pmap_unset(0x32112300uLL, 1uLL);
registerrpc();
registerrpc();
registerrpc();
registerrpc();
svc_run();
exit(1);
}

original_code:
int main()
{
  unsigned char c;
  char *msg;
  ar = open("/dev/all_read", 00);
  aw = open("/dev/all_write", 01);
  ur = open("/dev/user_read", 00);
  uw = open("/dev/user_write", 01);
  all = open("/proc/komunikaty/all", 01);
  user = open("/proc/komunikaty/user", 01);
  do {
    printf("\nZarzadzanie kolejkami komunikatow\n\n");
    printf("\t[1] odebranie prywatnego komunikatu\n");
    printf("\t[2] wyslanie prywatnego komunikatu\n");
    printf("\t[3] zmiana adresata prywatnego komunikatu\n");
    printf("\t[4] odebranie publicznego komunikatu\n");
    printf("\t[5] wyslanie publicznego komunikatu\n");
    printf("\t-----------------------------------------\n");
    if (all != -1) {
      printf("\t[r] uruchomienie systemu kolejek\n");
      printf("\t[s] zatrzymanie systemu kolejek\n");
      printf("\t[c] czyszczenie wszystkich kolejek\n");
      printf("\t[l] ustawienie rozmiaru kolejek\n");
      printf("\t[a] dodanie uzytkownika\n");
      printf("\t[d] usuniecie uzytkownika\n");
      printf("\t-----------------------------------------\n");
    }
    printf("\t[q] koniec\n\n> ");
    c = getchar(); getchar();
    switch (c) {
    case '1':
      read_user();
      break;
    case '2':
      msg = getstr("podaj komunikat: ");
      write_user(msg, strlen(msg));
      break;
    case '3':
      set_dest(getint("podaj uid adresata: "));
      break;
    case '4':
      read_all();
      break;
    case '5':
      msg = getstr("podaj komunikat: ");
      write_all(msg, strlen(msg));
      break;
    default:
      if (all != -1) {
 switch (c) {
 case 'r':
   start();
   break;
 case 's':
   stop();
   break;
 case 'c':
   clean();
   break;
 case 'l':
   set_size(getint("podaj rozmiar kolejki: "));
   break;
 case 'a':
   add_user(getint("podaj uid uzytkownika: "));
   break;
 case 'd':
   del_user(getint("podaj uid uzytkownika: "));
   break;
 default:
 }
      }
    }
  } while (c != 'q');
  close(ar);
  close(aw);
  close(ur);
  close(uw);
  return 0;
}

variable_types:
c
unsigned char

variable_types:
msg
char *


suma

decompiled_code:
__int64 __fastcall suma(const char *a1, __int64 a2)
{
__int64 result; // rax
__int64 v3; // rcx
int v4; // edx

result = (unsigned int)strlen(a1) - 1;
if ( (int)result >= 0 )
{
v3 = (int)result;
LODWORD(result) = 0;
do
{
v4 = result + a1[v3] + *(char *)(a2 + v3) - 96;
*(_BYTE *)(a2 + v3) = v4 % 10 + 48;
result = v4 > 9;
--v3;
}
while ( (int)v3 >= 0 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(const char *a1, __int64 a2)
{
__int64 result; // rax
__int64 v3; // rcx
int v4; // edx

result = (unsigned int)strlen(a1) - 1;
if ( (int)result >= 0 )
{
v3 = (int)result;
LODWORD(result) = 0;
do
{
v4 = result + a1[v3] + *(char *)(a2 + v3) - 96;
*(_BYTE *)(a2 + v3) = v4 % 10 + 48;
result = v4 > 9;
--v3;
}
while ( (int)v3 >= 0 );
}
return result;
}

original_code:
void suma(char *zrodlo, char *cel)
{
  int i, p, t;
  i = strlen(zrodlo) - 1;
  p = 0;
  for (; i >= 0; i--) {
    t = zrodlo[i] + cel[i] - 96 + p;
    cel[i] = (char)(t % 10 + 48);
    p = (t >= 10) ? 1 : 0;
  }
}

canonical_original_code:
void suma(char *zrodlo, char *cel)
{
  int i; int p; int t;
  i = strlen(zrodlo) - 1;
  p = 0;
  for (; i >= 0; i--) {
    t = zrodlo[i] + cel[i] - 96 + p;
    cel[i] = (char)(t % 10 + 48);
    p = (t >= 10) ? 1 : 0;
  }
}

variable_types:
zrodlo
char *

variable_types:
cel
char *

variable_types: i int

variable_types: p int

variable_types: t int


decompiled_code:
ssize_t __fastcall report_error(void *buf)
{
size_t v1; // rax

v1 = strlen((const char *)buf);
return write(2, buf, v1);
}

canonical_decompiled_code:
ssize_t __fastcall func0(void *buf)
{
size_t v1; // rax

v1 = strlen((const char *)buf);
return write(2, buf, v1);
}

original_code:
void report_error(char* errmsg)
{
  write(2, errmsg, strlen(errmsg));
}

canonical_original_code:
void report_error(char *errmsg)
{
  write(2, errmsg, strlen(errmsg));
}

variable_types:
errmsg
char *


repo: mmalecki/env

decompiled_code:
__int64 __fastcall env__find(__int64 a1, const char *a2)
{
__int64 v3; // rbx
size_t v4; // r13
unsigned int v5; // er14
const char *v6; // rsi

v3 = 0LL;
v4 = (unsigned int)strlen(a2);
while ( 1 )
{
v5 = v3;
v6 = *(const char **)(a1 + 8 * v3);
if ( !v6 )
break;
++v3;
if ( !strncmp(a2, v6, v4) )
return v5;
}
return (unsigned int)-1;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, const char *a2)
{
__int64 v3; // rbx
size_t v4; // r13
unsigned int v5; // er14
const char *v6; // rsi

v3 = 0LL;
v4 = (unsigned int)strlen(a2);
while ( 1 )
{
v5 = v3;
v6 = *(const char **)(a1 + 8 * v3);
if ( !v6 )
break;
++v3;
if ( !strncmp(a2, v6, v4) )
return v5;
}
return (unsigned int)-1;
}

original_code:
int env__find(char** env, char* name) {
  int i = 0;
  char* pair;
  unsigned int name_length = strlen(name);
  while ((pair = env[i++]) != ((void *)0)) {
    if (strncmp(name, pair, name_length) == 0) {
      return i - 1;
    }
  }
  return -1;
}

canonical_original_code:
int env__find(char **env, char *name) {
  int i = 0;
  char *pair;
  unsigned int name_length = strlen(name);
  while ((pair = env[i++]) != ((void *)0)) {
    if (strncmp(name, pair, name_length) == 0) {
      return i - 1;
    }
  }
  return -1;
}

variable_types:
env
char **

variable_types:
name
char *

variable_types:
pair
char *


decompiled_code:
char *__fastcall env__cat(char *dest, const char *a2, const char *a3)
{
*dest = 0;
strcat(dest, a2);
*(_WORD *)&dest[strlen(dest)] = 61;
return strcat(dest, a3);
}

canonical_decompiled_code:
char *__fastcall func1(char *dest, const char *a2, const char *a3)
{
*dest = 0;
strcat(dest, a2);
*(_WORD *)&dest[strlen(dest)] = 61;
return strcat(dest, a3);
}

original_code:
void env__cat(char* dest, char* name, char* value) {
  dest[0] = '\0';
  strcat(dest, name);
  strcat(dest, "=");
  strcat(dest, value);
}

canonical_original_code:
void env__cat(char *dest, char *name, char *value) {
  dest[0] = '\0';
  strcat(dest, name);
  strcat(dest, "=");
  strcat(dest, value);
}

variable_types:
dest
char *

variable_types:
value
char *


decompiled_code:
__int64 __fastcall env_length(__int64 a1)
{
unsigned int v1; // eax
unsigned int v2; // edx

v1 = 0;
do
v2 = v1++;
while ( *(_QWORD *)(a1 + 8LL * v2) );
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
unsigned int v1; // eax
unsigned int v2; // edx

v1 = 0;
do
v2 = v1++;
while ( *(_QWORD *)(a1 + 8LL * v2) );
return v2;
}

original_code:
unsigned int env_length(char** env) {
  unsigned int i = 0;
  while (env[i++] != ((void *)0));
  return i - 1;
}

canonical_original_code:
unsigned int env_length(char **env) {
  unsigned int i = 0;
  while (env[i++] != ((void *)0));
  return i - 1;
}

variable_types:
i
unsigned int

return_type: unsigned int


decompiled_code:
char *__fastcall env_get(__int64 a1, const char *a2)
{
int v2; // ebx
int v3; // eax
const char *v4; // r13
size_t v5; // r12
char *v6; // rbp

v2 = strlen(a2);
v3 = env__find(a1, a2);
if ( v3 == -1 )
return 0LL;
v4 = *(const char **)(a1 + 8LL * v3);
v5 = (unsigned int)strlen(v4) - v2;
v6 = (char *)malloc(v5);
strncpy(v6, &v4[v2 + 1], v5);
return v6;
}

canonical_decompiled_code:
char *__fastcall func3(__int64 a1, const char *a2)
{
int v2; // ebx
int v3; // eax
const char *v4; // r13
size_t v5; // r12
char *v6; // rbp

v2 = strlen(a2);
v3 = func0(a1, a2);
if ( v3 == -1 )
return 0LL;
v4 = *(const char **)(a1 + 8LL * v3);
v5 = (unsigned int)strlen(v4) - v2;
v6 = (char *)malloc(v5);
strncpy(v6, &v4[v2 + 1], v5);
return v6;
}

original_code:
char* env_get(char** env, char* name) {
  int index;
  char* pair;
  char* result;
  unsigned int name_length, value_length;
  name_length = strlen(name);
  if ((index = env__find(env, name)) == -1)
    return ((void *)0);
  pair = env[index];
  value_length = strlen(pair) - name_length;
  result = malloc(value_length);
  strncpy(result, pair + name_length + 1, value_length);
  return result;
}

canonical_original_code:
char *env_get(char **env, char *name) {
  int index;
  char *pair;
  char *result;
  unsigned int name_length; unsigned int value_length;
  name_length = strlen(name);
  if ((index = env__find(env, name)) == -1)
    return ((void *)0);
  pair = env[index];
  value_length = strlen(pair) - name_length;
  result = malloc(value_length);
  strncpy(result, pair + name_length + 1, value_length);
  return result;
}

variable_types: index int

variable_types:
result
char *


decompiled_code:
void __fastcall env_free(void *ptr)
{
void *v2; // rdi
char *v3; // rbx

if ( ptr )
{
v2 = *(void **)ptr;
if ( v2 )
{
v3 = (char *)ptr + 8;
do
{
free(v2);
v3 += 8;
v2 = (void *)*((_QWORD *)v3 - 1);
}
while ( v2 );
}
free(ptr);
}
}

canonical_decompiled_code:
void __fastcall func5(void *ptr)
{
void *v2; // rdi
char *v3; // rbx

if ( ptr )
{
v2 = *(void **)ptr;
if ( v2 )
{
v3 = (char *)ptr + 8;
do
{
free(v2);
v3 += 8;
v2 = (void *)*((_QWORD *)v3 - 1);
}
while ( v2 );
}
free(ptr);
}
}

original_code:
void env_free(char** env) {
  char* s;
  int i = 0;
  if (env == ((void *)0)) {
    return;
  }
  while ((s = env[i++]) != ((void *)0)) {
    free(s);
  }
  free(env);
}

canonical_original_code:
void env_free(char **env) {
  char *s;
  int i = 0;
  if (env == ((void *)0)) {
    return;
  }
  while ((s = env[i++]) != ((void *)0)) {
    free(s);
  }
  free(env);
}

variable_types:
s
char *


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // ebx
__int64 v5; // [rsp+0h] [rbp-28h] BYREF
void *ptr; // [rsp+8h] [rbp-20h] BYREF
size_t v7; // [rsp+10h] [rbp-18h] BYREF
size_t v8[2]; // [rsp+18h] [rbp-10h] BYREF

ptr = 0LL;
v5 = 0LL;
if ( argc == 2 )
{
if ( (unsigned int)mapInit(&v5, argv, envp) )
__assert_fail("rc == 0", "map_test.c", 0x22u, "main");
if ( (unsigned int)mapPrint(v5) )
__assert_fail("rc == 0", "map_test.c", 0x26u, "main");
if ( (unsigned int)mapLoad(v5, argv[1]) )
__assert_fail("rc == 0", "map_test.c", 0x2Au, "main");
if ( (unsigned int)mapPrint(v5) )
__assert_fail("rc == 0", "map_test.c", 0x2Eu, "main");
if ( (unsigned int)mapHeight(v5, &v7) )
__assert_fail("rc == 0", "map_test.c", 0x32u, "main");
if ( (unsigned int)mapWidth(v5, v8) )
__assert_fail("rc == 0", "map_test.c", 0x36u, "main");
v3 = mapName(v5, &ptr);
if ( v3 )
__assert_fail("rc == 0", "map_test.c", 0x3Au, "main");
printf("map hxW: %zu x %zu name: %s\n", v7, v8[0], (const char *)ptr);
free(ptr);
}
else
{
printf("usage: %s <map file to test>\n", *argv);
v3 = -1;
}
return v3;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // ebx
__int64 v5; // [rsp+0h] [rbp-28h] BYREF
void *ptr; // [rsp+8h] [rbp-20h] BYREF
size_t v7; // [rsp+10h] [rbp-18h] BYREF
size_t v8[2]; // [rsp+18h] [rbp-10h] BYREF

ptr = 0LL;
v5 = 0LL;
if ( argc == 2 )
{
if ( (unsigned int)func11(&v5, argv, envp) )
__assert_fail("rc == 0", "map_test.c", 0x22u, "main");
if ( (unsigned int)func13(v5) )
__assert_fail("rc == 0", "map_test.c", 0x26u, "main");
if ( (unsigned int)func7(v5, argv[1]) )
__assert_fail("rc == 0", "map_test.c", 0x2Au, "main");
if ( (unsigned int)func13(v5) )
__assert_fail("rc == 0", "map_test.c", 0x2Eu, "main");
if ( (unsigned int)func16(v5, &v7) )
__assert_fail("rc == 0", "map_test.c", 0x32u, "main");
if ( (unsigned int)func15(v5, v8) )
__assert_fail("rc == 0", "map_test.c", 0x36u, "main");
v3 = func17(v5, &ptr);
if ( v3 )
__assert_fail("rc == 0", "map_test.c", 0x3Au, "main");
printf("map hxW: %zu x %zu name: %s\n", v7, v8[0], (const char *)ptr);
free(ptr);
}
else
{
printf("usage: %s <map file to test>\n", *argv);
v3 = -1;
}
return v3;
}

original_code:
int main( int argc, char *argv[] )
{
 uint32_t debug = 0 ;
 int i;
 int rc = 0;
 for( i = 0; i < argc; ++i ){
  if ( strcmp( argv[i], "-d" ) )
   debug = 1 ;
 }
 rc = interfaceLoop(argv[1] , debug);
 if ( rc != 0 ){
  printf("interfaceLoop returned in error number: %d\n", rc);
  fflush(stdout);
  return -1 ;
 }
 return 0 ;
}

canonical_original_code:
int main(int argc, char *argv[])
{
 unsigned int debug = 0;
 int i;
 int rc = 0;
 for( i = 0; i < argc; ++i ){
  if ( strcmp( argv[i], "-d" ) )
   debug = 1 ;
 }
 rc = interfaceLoop(argv[1] , debug);
 if ( rc != 0 ){
  printf("interfaceLoop returned in error number: %d\n", rc);
  fflush(stdout);
  return -1 ;
 }
 return 0 ;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types:
debug
unsigned int

variable_types: rc int


mapIsInitted

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

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

original_code:
int mapIsInitted( map m )
{
 return ( ( m == ((void *)0) ) ? 0 : 1 );
}

canonical_original_code:
int mapIsInitted(struct map_s *m)
{
 return ( ( m == ((void *)0) ) ? 0 : 1 );
}

variable_types: struct map_s { char *name; char **theMap; unsigned long width; unsigned long height; unsigned long nameLen; } *


mapZeroizeFree

decompiled_code:
__int64 __fastcall mapZeroizeFree(__int64 a1)
{
unsigned __int64 v1; // rbx
__int64 result; // rax

if ( a1 )
{
free(*(void **)a1);
*(_QWORD *)(a1 + 32) = 0LL;
*(_QWORD *)a1 = 0LL;
if ( *(_QWORD *)(a1 + 24) )
{
v1 = 0LL;
do
free(*(void **)(*(_QWORD *)(a1 + 8) + 8 * v1++));
while ( *(_QWORD *)(a1 + 24) > v1 );
}
free(*(void **)(a1 + 8));
*(_QWORD *)(a1 + 8) = 0LL;
*(_QWORD *)(a1 + 24) = 0LL;
*(_QWORD *)(a1 + 16) = 0LL;
result = 0LL;
}
else
{
printf("ERROR:%s:%d:mapFreeInternals(): was passed a null ptr\n", "map.c", 169LL);
fflush(_bss_start);
result = 0xFFFFFFFFLL;
}
return result;
}

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

if ( a1 )
{
free(*(void **)a1);
*(_QWORD *)(a1 + 32) = 0LL;
*(_QWORD *)a1 = 0LL;
if ( *(_QWORD *)(a1 + 24) )
{
v1 = 0LL;
do
free(*(void **)(*(_QWORD *)(a1 + 8) + 8 * v1++));
while ( *(_QWORD *)(a1 + 24) > v1 );
}
free(*(void **)(a1 + 8));
*(_QWORD *)(a1 + 8) = 0LL;
*(_QWORD *)(a1 + 24) = 0LL;
*(_QWORD *)(a1 + 16) = 0LL;
result = 0LL;
}
else
{
printf("ERROR:%s:%d:mapFreeInternals(): was passed a null ptr\n", "map.c", 169LL);
fflush(_bss_start);
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
int mapZeroizeFree( map m )
{
 size_t i;
 if( m == ((void *)0) ) {
  printf("ERROR:%s:%d:mapFreeInternals(): "
         "was passed a null ptr\n",
         "map.c", 169) ;
  fflush(stdout);
  return -1;
 }
 free( (m->name) ) ;
 (m->nameLen) = 0 ;
 (m->name) = ((void *)0) ;
 for( i = 0; i < (m->height) ; ++i ) {
  free( (m->theMap) [i] ) ;
 }
 free( (m->theMap) ) ;
 (m->theMap) = ((void *)0) ;
 (m->height) = 0 ;
 (m->width) = 0 ;
 return 0 ;
}

canonical_original_code:
int mapZeroizeFree(struct map_s *m)
{
 unsigned long i;
 if( m == ((void *)0) ) {
  printf("ERROR:%s:%d:mapFreeInternals(): "
         "was passed a null ptr\n",
         "map.c", 169) ;
  fflush(stdout);
  return -1;
 }
 free( (m->name) ) ;
 (m->nameLen) = 0 ;
 (m->name) = ((void *)0) ;
 for( i = 0; i < (m->height) ; ++i ) {
  free( (m->theMap) [i] ) ;
 }
 free( (m->theMap) ) ;
 (m->theMap) = ((void *)0) ;
 (m->height) = 0 ;
 (m->width) = 0 ;
 return 0 ;
}

variable_types:
i
unsigned long

user_defined_types: struct map_s { char *name; char **theMap; unsigned long width; unsigned long height; unsigned long nameLen; }


mapZeroize

decompiled_code:
__int64 __fastcall mapZeroize(_QWORD *a1)
{
__int64 result; // rax

if ( a1 )
{
a1[2] = 0LL;
a1[3] = 0LL;
a1[4] = 0LL;
result = 0LL;
}
else
{
printf("ERROR:%s:%d:mapZeroize(): was passed a null ptr\n", "map.c", 200LL);
fflush(_bss_start);
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func10(_QWORD *a1)
{
__int64 result; // rax

if ( a1 )
{
a1[2] = 0LL;
a1[3] = 0LL;
a1[4] = 0LL;
result = 0LL;
}
else
{
printf("ERROR:%s:%d:mapZeroize(): was passed a null ptr\n", "map.c", 200LL);
fflush(_bss_start);
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
int mapZeroize( map m )
{
 if( m == ((void *)0) ) {
  printf("ERROR:%s:%d:mapZeroize(): was passed a null ptr\n",
         "map.c", 200 ) ;
  fflush( stdout ) ;
  return -1 ;
 }
 (m->width) = 0 ;
 (m->height) = 0 ;
 (m->nameLen) = 0 ;
 return 0;
}

canonical_original_code:
int mapZeroize(struct map_s *m)
{
 if( m == ((void *)0) ) {
  printf("ERROR:%s:%d:mapZeroize(): was passed a null ptr\n",
         "map.c", 200 ) ;
  fflush( stdout ) ;
  return -1 ;
 }
 (m->width) = 0 ;
 (m->height) = 0 ;
 (m->nameLen) = 0 ;
 return 0;
}


mapInit

decompiled_code:
__int64 __fastcall mapInit(const void **a1)
{
_QWORD *v1; // rax
__int64 result; // rax

if ( a1 )
{
v1 = malloc(0x28uLL);
*a1 = v1;
result = mapZeroize(v1);
if ( (_DWORD)result )
{
printf("ERROR:%s:%d:mapInit(): mapZeroize() failed m=%p\n", "map.c", 112LL, *a1);
result = 0LL;
}
}
else
{
printf("ERROR:%s:%d:mapInit(): was passed a NULL ptr\n", "map.c", 99LL);
fflush(_bss_start);
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func11(const void **a1)
{
_QWORD *v1; // rax
__int64 result; // rax

if ( a1 )
{
v1 = malloc(0x28uLL);
*a1 = v1;
result = func10(v1);
if ( (_DWORD)result )
{
printf("ERROR:%s:%d:mapInit(): mapZeroize() failed m=%p\n", "map.c", 112LL, *a1);
result = 0LL;
}
}
else
{
printf("ERROR:%s:%d:mapInit(): was passed a NULL ptr\n", "map.c", 99LL);
fflush(_bss_start);
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
int mapInit( map *m )
{
 int rc;
 if( m == ((void *)0) )
 {
  printf("ERROR:%s:%d:mapInit(): was passed a NULL ptr\n",
         "map.c", 99);
  fflush(stdout);
  return -1;
 }
 *m = ( (map) malloc( sizeof( map_s ) ) ) ;
 rc = mapZeroize( *m ) ;
 if( rc != 0 ) {
  printf("ERROR:%s:%d:mapInit(): mapZeroize() failed m=%p\n",
         "map.c", 112, (void *) *m);
 }
 return 0;
}

canonical_original_code:
int mapInit(struct map_s **m)
{
 int rc;
 if( m == ((void *)0) )
 {
  printf("ERROR:%s:%d:mapInit(): was passed a NULL ptr\n",
         "map.c", 99);
  fflush(stdout);
  return -1;
 }
 *m = ( (struct map_s *) malloc( sizeof( map_s ) ) ) ;
 rc = mapZeroize( *m ) ;
 if( rc != 0 ) {
  printf("ERROR:%s:%d:mapInit(): mapZeroize() failed m=%p\n",
         "map.c", 112, (void *) *m);
 }
 return 0;
}

variable_types: struct map_s { char *name; char **theMap; unsigned long width; unsigned long height; unsigned long nameLen; } **


mapDelete

decompiled_code:
__int64 __fastcall mapDelete(void *ptr)
{
unsigned int v1; // eax
unsigned int v2; // ebx
unsigned int v3; // eax

if ( ptr )
{
v1 = mapZeroizeFree((__int64)ptr);
v2 = v1;
if ( v1 )
{
printf("ERROR:%s:%d:mapDelete(): mapFreeInternals failed rc=%d, m=%p \n", "map.c", 141LL, v1, ptr);
fflush(_bss_start);
}
else
{
v3 = mapZeroize(ptr);
v2 = v3;
if ( v3 )
printf("ERROR:%s:%d:mapDelete(): mapZeroize failed rc=%d, m=%p. \n", "map.c", 152LL, v3, ptr);
else
free(ptr);
}
}
else
{
printf("WARNING:%s:%d:mapDelete(): was passed a NULL ptr.doing nothing.\n", "map.c", 130LL);
fflush(_bss_start);
v2 = 1;
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func12(void *ptr)
{
unsigned int v1; // eax
unsigned int v2; // ebx
unsigned int v3; // eax

if ( ptr )
{
v1 = func9((__int64)ptr);
v2 = v1;
if ( v1 )
{
printf("ERROR:%s:%d:mapDelete(): mapFreeInternals failed rc=%d, m=%p \n", "map.c", 141LL, v1, ptr);
fflush(_bss_start);
}
else
{
v3 = func10(ptr);
v2 = v3;
if ( v3 )
printf("ERROR:%s:%d:mapDelete(): mapZeroize failed rc=%d, m=%p. \n", "map.c", 152LL, v3, ptr);
else
free(ptr);
}
}
else
{
printf("WARNING:%s:%d:mapDelete(): was passed a NULL ptr.doing nothing.\n", "map.c", 130LL);
fflush(_bss_start);
v2 = 1;
}
return v2;
}

original_code:
int mapDelete( map m )
{
 int rc;
 if( m == ((void *)0) ) {
  printf("WARNING:%s:%d:mapDelete(): was passed a NULL ptr."
         "doing nothing.\n",
         "map.c", 130 ) ;
  fflush(stdout);
  return 1;
 }
 rc = mapZeroizeFree( m ) ;
 if( rc != 0 ) {
  printf("ERROR:%s:%d:mapDelete(): "
         "mapFreeInternals failed rc=%d, m=%p \n",
         "map.c", 141, rc, (void *) m ) ;
  fflush(stdout);
  return rc;
 }
 rc = mapZeroize( m ) ;
 if( rc != 0 ) {
  printf("ERROR:%s:%d:mapDelete(): "
         "mapZeroize failed rc=%d, m=%p. \n",
         "map.c", 152, rc, (void *) m ) ;
  return rc;
 }
 free( m ) ;
 return 0;
}

canonical_original_code:
int mapDelete(struct map_s *m)
{
 int rc;
 if( m == ((void *)0) ) {
  printf("WARNING:%s:%d:mapDelete(): was passed a NULL ptr."
         "doing nothing.\n",
         "map.c", 130 ) ;
  fflush(stdout);
  return 1;
 }
 rc = mapZeroizeFree( m ) ;
 if( rc != 0 ) {
  printf("ERROR:%s:%d:mapDelete(): "
         "mapFreeInternals failed rc=%d, m=%p \n",
         "map.c", 141, rc, (void *) m ) ;
  fflush(stdout);
  return rc;
 }
 rc = mapZeroize( m ) ;
 if( rc != 0 ) {
  printf("ERROR:%s:%d:mapDelete(): "
         "mapZeroize failed rc=%d, m=%p. \n",
         "map.c", 152, rc, (void *) m ) ;
  return rc;
 }
 free( m ) ;
 return 0;
}


mapPrint

decompiled_code:
__int64 __fastcall mapPrint(__int64 a1)
{
unsigned __int64 v1; // rbx
__int64 result; // rax

if ( a1 )
{
printf("name: %s\n", *(const char **)a1);
printf("Height: %zd Width: %zd\n", *(_QWORD *)(a1 + 24), *(_QWORD *)(a1 + 16));
if ( *(_QWORD *)(a1 + 24) )
{
v1 = 0LL;
do
puts(*(const char **)(*(_QWORD *)(a1 + 8) + 8 * v1++));
while ( *(_QWORD *)(a1 + 24) > v1 );
result = 0LL;
}
else
{
result = 0LL;
}
}
else
{
printf("ERROR:%s:%d:mapPrint(): passed a null pointer\n", "map.c", 220LL);
fflush(_bss_start);
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func13(__int64 a1)
{
unsigned __int64 v1; // rbx
__int64 result; // rax

if ( a1 )
{
printf("name: %s\n", *(const char **)a1);
printf("Height: %zd Width: %zd\n", *(_QWORD *)(a1 + 24), *(_QWORD *)(a1 + 16));
if ( *(_QWORD *)(a1 + 24) )
{
v1 = 0LL;
do
puts(*(const char **)(*(_QWORD *)(a1 + 8) + 8 * v1++));
while ( *(_QWORD *)(a1 + 24) > v1 );
result = 0LL;
}
else
{
result = 0LL;
}
}
else
{
printf("ERROR:%s:%d:mapPrint(): passed a null pointer\n", "map.c", 220LL);
fflush(_bss_start);
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
int mapPrint( map m )
{
 size_t i;
 if( m == ((void *)0) ) {
  printf("ERROR:%s:%d:mapPrint(): passed a null pointer\n",
         "map.c", 220 ) ;
  fflush(stdout);
  return -1;
 }
 printf("name: %s\n", (m->name) ) ;
 printf("Height: %zd Width: %zd\n", (m->height), (m->width) ) ;
 for( i = 0; i < (m->height) ; ++i ) {
  printf("%s\n", (m->theMap)[i] ) ;
 }
 return 0;
}

canonical_original_code:
int mapPrint(struct map_s *m)
{
 unsigned long i;
 if( m == ((void *)0) ) {
  printf("ERROR:%s:%d:mapPrint(): passed a null pointer\n",
         "map.c", 220 ) ;
  fflush(stdout);
  return -1;
 }
 printf("name: %s\n", (m->name) ) ;
 printf("Height: %zd Width: %zd\n", (m->height), (m->width) ) ;
 for( i = 0; i < (m->height) ; ++i ) {
  printf("%s\n", (m->theMap)[i] ) ;
 }
 return 0;
}


mapNameLen

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

if ( a1 )
{
*a2 = *(_QWORD *)(a1 + 32);
result = 0LL;
}
else
{
printf("%s:%d:mapNameLen(): passed a null ptr\n", "map.c", 242LL);
fflush(_bss_start);
result = 0xFFFFFFFFLL;
}
return result;
}

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

if ( a1 )
{
*a2 = *(_QWORD *)(a1 + 32);
result = 0LL;
}
else
{
printf("%s:%d:mapNameLen(): passed a null ptr\n", "map.c", 242LL);
fflush(_bss_start);
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
int mapNameLen( map m, size_t *nameLen )
{
 if( m == ((void *)0))
 {
  printf("%s:%d:mapNameLen(): passed a null ptr\n",
         "map.c", 242);
  fflush(stdout);
  return -1;
 }
 *nameLen = (m->nameLen);
 return 0;
}

canonical_original_code:
int mapNameLen(struct map_s *m, unsigned long *nameLen)
{
 if( m == ((void *)0))
 {
  printf("%s:%d:mapNameLen(): passed a null ptr\n",
         "map.c", 242);
  fflush(stdout);
  return -1;
 }
 *nameLen = (m->nameLen);
 return 0;
}

variable_types:
nameLen
unsigned long *


mapWidth

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

if ( a1 )
{
*a2 = *(_QWORD *)(a1 + 16);
result = 0LL;
}
else
{
printf("%s:%d:mapNameLen(): passed a null ptr\n", "map.c", 257LL);
fflush(_bss_start);
result = 0xFFFFFFFFLL;
}
return result;
}

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

if ( a1 )
{
*a2 = *(_QWORD *)(a1 + 16);
result = 0LL;
}
else
{
printf("%s:%d:mapNameLen(): passed a null ptr\n", "map.c", 257LL);
fflush(_bss_start);
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
int mapWidth( map m, size_t *w )
{
 if( m == ((void *)0))
 {
  printf("%s:%d:mapNameLen(): passed a null ptr\n",
         "map.c", 257);
  fflush(stdout);
  return -1;
 }
 *w = (m->width);
 return 0;
}

canonical_original_code:
int mapWidth(struct map_s *m, unsigned long *w)
{
 if( m == ((void *)0))
 {
  printf("%s:%d:mapNameLen(): passed a null ptr\n",
         "map.c", 257);
  fflush(stdout);
  return -1;
 }
 *w = (m->width);
 return 0;
}

variable_types:
w
unsigned long *


mapHeight

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

if ( a1 )
{
*a2 = *(_QWORD *)(a1 + 24);
result = 0LL;
}
else
{
printf("%s:%d:mapNameLen(): passed a null ptr\n", "map.c", 272LL);
fflush(_bss_start);
result = 0xFFFFFFFFLL;
}
return result;
}

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

if ( a1 )
{
*a2 = *(_QWORD *)(a1 + 24);
result = 0LL;
}
else
{
printf("%s:%d:mapNameLen(): passed a null ptr\n", "map.c", 272LL);
fflush(_bss_start);
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
int mapHeight( map m, size_t *h )
{
 if( m == ((void *)0))
 {
  printf("%s:%d:mapNameLen(): passed a null ptr\n",
         "map.c", 272);
  fflush(stdout);
  return -1;
 }
 *h = (m->height);
 return 0;
}

canonical_original_code:
int mapHeight(struct map_s *m, unsigned long *h)
{
 if( m == ((void *)0))
 {
  printf("%s:%d:mapNameLen(): passed a null ptr\n",
         "map.c", 272);
  fflush(stdout);
  return -1;
 }
 *h = (m->height);
 return 0;
}

variable_types:
h
unsigned long *


mapName

decompiled_code:
__int64 __fastcall mapName(__int64 a1, char **a2)
{
char *v2; // rax
__int64 result; // rax

if ( a1 && a2 )
{
v2 = (char *)malloc(*(_QWORD *)(a1 + 32));
*a2 = v2;
strcpy(v2, *(const char **)a1);
result = 0LL;
}
else
{
printf("%s:%d:mapNameLen(): passed a null ptr m=%p, str_ptr=%p\n", "map.c", 288LL, (const void *)a1, a2);
fflush(_bss_start);
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func17(__int64 a1, char **a2)
{
char *v2; // rax
__int64 result; // rax

if ( a1 && a2 )
{
v2 = (char *)malloc(*(_QWORD *)(a1 + 32));
*a2 = v2;
strcpy(v2, *(const char **)a1);
result = 0LL;
}
else
{
printf("%s:%d:mapNameLen(): passed a null ptr m=%p, str_ptr=%p\n", "map.c", 288LL, (const void *)a1, a2);
fflush(_bss_start);
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
int mapName( map m, char **str_ptr )
{
 if( m == ((void *)0) || str_ptr == ((void *)0) )
 {
  printf("%s:%d:mapNameLen(): passed a null ptr "
         "m=%p, str_ptr=%p\n",
         "map.c", 288, (void *) m, (void *) str_ptr ) ;
  fflush(stdout);
  return -1;
 }
 *str_ptr = malloc(sizeof(char) * (m->nameLen) ) ;
 strcpy( *str_ptr, (m->name) ) ;
 return 0;
}

canonical_original_code:
int mapName(struct map_s *m, char **str_ptr)
{
 if( m == ((void *)0) || str_ptr == ((void *)0) )
 {
  printf("%s:%d:mapNameLen(): passed a null ptr "
         "m=%p, str_ptr=%p\n",
         "map.c", 288, (void *) m, (void *) str_ptr ) ;
  fflush(stdout);
  return -1;
 }
 *str_ptr = malloc(sizeof(char) * (m->nameLen) ) ;
 strcpy( *str_ptr, (m->name) ) ;
 return 0;
}


mapCopy

decompiled_code:
__int64 __fastcall mapCopy(char **a1, const char **a2)
{
__int64 result; // rax

if ( a2 && a1 )
{
strcpy(*a1, *a2);
result = 0LL;
}
else
{
printf("%s:%d:mapNameLen(): passed a null ptr: dest=%p, src=%p\n", "map.c", 306LL, a1, a2);
fflush(_bss_start);
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func18(char **a1, const char **a2)
{
__int64 result; // rax

if ( a2 && a1 )
{
strcpy(*a1, *a2);
result = 0LL;
}
else
{
printf("%s:%d:mapNameLen(): passed a null ptr: dest=%p, src=%p\n", "map.c", 306LL, a1, a2);
fflush(_bss_start);
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
int mapCopy( map dest, map src )
{
 if( src == ((void *)0) || dest == ((void *)0))
 {
  printf("%s:%d:mapNameLen(): passed a null ptr: "
         "dest=%p, src=%p\n",
         "map.c", 306, (void *) dest, (void *) src );
  fflush(stdout);
  return -1;
 }
 strcpy( (dest->name), (src->name) );
 return 0;
}

canonical_original_code:
int mapCopy(struct map_s *dest, struct map_s *src)
{
 if( src == ((void *)0) || dest == ((void *)0))
 {
  printf("%s:%d:mapNameLen(): passed a null ptr: "
         "dest=%p, src=%p\n",
         "map.c", 306, (void *) dest, (void *) src );
  fflush(stdout);
  return -1;
 }
 strcpy( (dest->name), (src->name) );
 return 0;
}

variable_types:
src
struct map_s *


inputToWords

decompiled_code:
__int64 __fastcall inputToWords(_BYTE **a1, int a2)
{
_BYTE *v2; // rbx
_BYTE *v3; // r13
int v4; // edx
int v5; // er12
unsigned int v6; // ebp

if ( a2 <= 0 )
return 0;
v2 = *a1;
v3 = &(*a1)[a2 - 1];
v4 = 0;
v5 = 0;
v6 = 0;
while ( 1 )
{
if ( v5 )
goto LABEL_12;
if ( *v2 == 32 )
goto LABEL_6;
if ( (int)++v6 > 9 )
break;
a1[v6] = malloc(0x2000uLL);
v4 = 0;
LABEL_12:
if ( *v2 == 32 )
{
a1[v6][v4] = 0;
v5 = 0;
}
else
{
a1[v6][v4++] = *v2;
v5 = 1;
}
LABEL_6:
if ( v3 == v2 )
return v6;
++v2;
}
printf("TOO MANY WORDS, LIMIT IS %d", 10LL);
return v6;
}

canonical_decompiled_code:
__int64 __fastcall func0(_BYTE **a1, int a2)
{
_BYTE *v2; // rbx
_BYTE *v3; // r13
int v4; // edx
int v5; // er12
unsigned int v6; // ebp

if ( a2 <= 0 )
return 0;
v2 = *a1;
v3 = &(*a1)[a2 - 1];
v4 = 0;
v5 = 0;
v6 = 0;
while ( 1 )
{
if ( v5 )
goto LABEL_12;
if ( *v2 == 32 )
goto LABEL_6;
if ( (int)++v6 > 9 )
break;
a1[v6] = malloc(0x2000uLL);
v4 = 0;
LABEL_12:
if ( *v2 == 32 )
{
a1[v6][v4] = 0;
v5 = 0;
}
else
{
a1[v6][v4++] = *v2;
v5 = 1;
}
LABEL_6:
if ( v3 == v2 )
return v6;
++v2;
}
printf("TOO MANY WORDS, LIMIT IS %d", 10LL);
return v6;
}

original_code:
int inputToWords( char *buffers[], int inputLength )
{
 int i, wordCount = 0, wordState = 0, letterCount = 0;
 char *input, *temp;
 temp = malloc( sizeof ( int ) * 8192 ) ;
 input = buffers[0] ;
 for ( i = 0; i < inputLength ; i++ )
 {
  if ( wordState == 0 ){
   if ( input[i] != ' ' ){
    wordState = 1 ;
    letterCount = 0 ;
    wordCount++ ;
    if (wordCount >= 10){
     printf( "TOO MANY WORDS, LIMIT IS %d",
      10 ) ;
     return wordCount ;
    }
    buffers[wordCount] =
     malloc( sizeof (char) * 8192 ) ;
   }
  }
  if ( wordState == 1 ){
   if ( input[i] == ' ' ){
    buffers[wordCount][letterCount] = '\0';
    wordState = 0 ;
   } else {
    buffers[wordCount][letterCount] = input[i];
    letterCount++ ;
   }
  }
 }
 free( temp ) ;
 return wordCount ;
}

canonical_original_code:
int inputToWords(char *buffers[], int inputLength)
{
 int i; int wordCount = 0; int wordState = 0; int letterCount = 0;
 char *input; char *temp;
 temp = malloc( sizeof ( int ) * 8192 ) ;
 input = buffers[0] ;
 for ( i = 0; i < inputLength ; i++ )
 {
  if ( wordState == 0 ){
   if ( input[i] != ' ' ){
    wordState = 1 ;
    letterCount = 0 ;
    wordCount++ ;
    if (wordCount >= 10){
     printf( "TOO MANY WORDS, LIMIT IS %d",
      10 ) ;
     return wordCount ;
    }
    buffers[wordCount] =
     malloc( sizeof (char) * 8192 ) ;
   }
  }
  if ( wordState == 1 ){
   if ( input[i] == ' ' ){
    buffers[wordCount][letterCount] = '\0';
    wordState = 0 ;
   } else {
    buffers[wordCount][letterCount] = input[i];
    letterCount++ ;
   }
  }
 }
 free( temp ) ;
 return wordCount ;
}

variable_types:
buffers
char *[]

variable_types: inputLength int

variable_types: i int

variable_types: wordCount int

variable_types: wordState int

variable_types: letterCount int

variable_types:
input
char *

variable_types:
temp
char *


upperString

decompiled_code:
__int64 __fastcall upperString(char *a1)
{
char *v1; // rbp
char v2; // bl
const __int32_t **v3; // rdx

if ( !a1 )
return 0xFFFFFFFFLL;
v1 = a1;
v2 = *a1;
if ( !*a1 )
return 0LL;
v3 = _ctype_toupper_loc();
do
{
*v1++ = (*v3)[v2];
v2 = *v1;
}
while ( *v1 );
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(char *a1)
{
char *v1; // rbp
char v2; // bl
const __int32_t **v3; // rdx

if ( !a1 )
return 0xFFFFFFFFLL;
v1 = a1;
v2 = *a1;
if ( !*a1 )
return 0LL;
v3 = _ctype_toupper_loc();
do
{
*v1++ = (*v3)[v2];
v2 = *v1;
}
while ( *v1 );
return 0LL;
}

original_code:
int upperString( char buffer[] )
{
 int i;
 if(buffer == ((void *)0))
  return -1;
 for ( i = 0 ; buffer[i] != '\0' ; i++ )
  buffer[i] = (char) toupper( buffer[i] );
 return 0;
}

canonical_original_code:
int upperString(char buffer[])
{
 int i;
 if(buffer == ((void *)0))
  return -1;
 for ( i = 0 ; buffer[i] != '\0' ; i++ )
  buffer[i] = (char) toupper( buffer[i] );
 return 0;
}

variable_types:
buffer
char []


getInput

decompiled_code:
__int64 getInput()
{
char *v0; // rax
size_t v1; // rbx
char *v2; // rax
unsigned __int64 v3; // rbp
unsigned __int64 i; // rbx
unsigned int v5; // er12
unsigned __int64 j; // rbx
bool v8; // zf
char *s; // [rsp+0h] [rbp-68h] BYREF
char *s1; // [rsp+8h] [rbp-60h]
const char *v11; // [rsp+10h] [rbp-58h]

v0 = (char *)malloc(0x2000uLL);
s = v0;
if ( !v0 )
return (unsigned int)-2;
fgets(v0, 0x2000, stdin);
v1 = strlen(s);
printf("DEBUG DATA: main input buffer: %s\nbuffer length: %lu \n\n", s, v1);
if ( v1 )
{
v2 = &s[v1 - 1];
if ( *v2 == 10 )
*v2 = 0;
}
v3 = (int)inputToWords(&s, v1);
printf("number of words = %zu\n\n", v3);
if ( !v3 )
return 666;
for ( i = 1LL; i <= v3; ++i )
{
upperString((&s)[i]);
printf("word %d: %s\n", i, (&s)[i]);
}
if ( v3 == 1 )
{
v8 = strcmp(s1, "Q") == 0;
v5 = !v8;
if ( !v8 )
{
v8 = strcmp(s1, "QUIT") == 0;
v5 = !v8;
if ( !v8 )
{
v5 = 1;
if ( strcmp(s1, "W") )
{
if ( strcmp(s1, "FORWARD") )
{
v5 = 2;
if ( strcmp(s1, "S") )
{
if ( strcmp(s1, "BACKWARD") )
{
v5 = 3;
if ( strcmp(s1, "A") )
{
if ( strcmp(s1, "LEFT") )
{
v5 = 4;
if ( strcmp(s1, "D") )
v5 = strcmp(s1, "RIGHT") == 0 ? 4 : 666;
}
}
}
}
}
}
}
}
}
else
{
v5 = 666;
if ( v3 == 2 )
{
v5 = 5;
if ( strcmp(s1, "T") )
{
if ( strcmp(s1, "TAKE") )
{
v5 = 6;
if ( strcmp(s1, "E") )
{
if ( strcmp(s1, "TALK") )
{
if ( !strcmp(s1, "SWAG") || !strcmp(s1, "BASED") || (v5 = 666, !strcmp(s1, "LIL")) )
{
v5 = 7;
if ( strcmp(v11, "B") && strcmp(v11, "GOD") )
v5 = strcmp(v11, "MONEY") == 0 ? 7 : 666;
}
}
}
}
}
}
}
for ( j = 0LL; j < v3; ++j )
free((&s)[j]);
return v5;
}

canonical_decompiled_code:
__int64 func2()
{
char *v0; // rax
size_t v1; // rbx
char *v2; // rax
unsigned __int64 v3; // rbp
unsigned __int64 i; // rbx
unsigned int v5; // er12
unsigned __int64 j; // rbx
bool v8; // zf
char *s; // [rsp+0h] [rbp-68h] BYREF
char *s1; // [rsp+8h] [rbp-60h]
const char *v11; // [rsp+10h] [rbp-58h]

v0 = (char *)malloc(0x2000uLL);
s = v0;
if ( !v0 )
return (unsigned int)-2;
fgets(v0, 0x2000, stdin);
v1 = strlen(s);
printf("DEBUG DATA: main input buffer: %s\nbuffer length: %lu \n\n", s, v1);
if ( v1 )
{
v2 = &s[v1 - 1];
if ( *v2 == 10 )
*v2 = 0;
}
v3 = (int)func0(&s, v1);
printf("number of words = %zu\n\n", v3);
if ( !v3 )
return 666;
for ( i = 1LL; i <= v3; ++i )
{
func1((&s)[i]);
printf("word %d: %s\n", i, (&s)[i]);
}
if ( v3 == 1 )
{
v8 = strcmp(s1, "Q") == 0;
v5 = !v8;
if ( !v8 )
{
v8 = strcmp(s1, "QUIT") == 0;
v5 = !v8;
if ( !v8 )
{
v5 = 1;
if ( strcmp(s1, "W") )
{
if ( strcmp(s1, "FORWARD") )
{
v5 = 2;
if ( strcmp(s1, "S") )
{
if ( strcmp(s1, "BACKWARD") )
{
v5 = 3;
if ( strcmp(s1, "A") )
{
if ( strcmp(s1, "LEFT") )
{
v5 = 4;
if ( strcmp(s1, "D") )
v5 = strcmp(s1, "RIGHT") == 0 ? 4 : 666;
}
}
}
}
}
}
}
}
}
else
{
v5 = 666;
if ( v3 == 2 )
{
v5 = 5;
if ( strcmp(s1, "T") )
{
if ( strcmp(s1, "TAKE") )
{
v5 = 6;
if ( strcmp(s1, "E") )
{
if ( strcmp(s1, "TALK") )
{
if ( !strcmp(s1, "SWAG") || !strcmp(s1, "BASED") || (v5 = 666, !strcmp(s1, "LIL")) )
{
v5 = 7;
if ( strcmp(v11, "B") && strcmp(v11, "GOD") )
v5 = strcmp(v11, "MONEY") == 0 ? 7 : 666;
}
}
}
}
}
}
}
for ( j = 0LL; j < v3; ++j )
free((&s)[j]);
return v5;
}

original_code:
int getInput( int *item )
{
 int returnCode = -1 ;
 size_t i;
 size_t numWords;
 size_t buffLength;
 char *buffers[10] ;
 buffers[0] = malloc( sizeof (char) * 8192 ) ;
 if (buffers[0] == ((void *)0)) return -2;
 fgets( buffers[0] , 8192 , stdin ) ;
 buffLength = strlen( buffers[0] ) ;
 printf( "DEBUG DATA: main input buffer: %s\nbuffer length: %lu \n\n",
  buffers[0], buffLength ) ;
 if (( buffLength > 0)
  && ( buffers[0][buffLength-1] == '\n'))
       buffers[0][buffLength-1] = '\0';
 numWords = inputToWords( buffers, buffLength );
 printf("number of words = %zu\n\n", numWords);
 for ( i = 1 ; i <= numWords ; i++ ){
  upperString(buffers[i]);
  printf("word %d: %s\n", i, buffers[i]);
 }
 if (numWords == 1) {
  if (!(strncmp(buffers[1], "Q", 8192))
      || !(strncmp(buffers[1], "QUIT", 8192)))
  {
   returnCode = 0 ;
  } else if
     ( !(strncmp(buffers[1], "W", 8192))
    || !(strncmp(buffers[1], "FORWARD", 8192)))
  {
   returnCode = 1 ;
  } else if
     ( !(strncmp(buffers[1], "S", 8192))
    || !(strncmp(buffers[1], "BACKWARD", 8192)))
  {
   returnCode = 2 ;
  } else if
     ( !(strncmp(buffers[1], "A", 8192))
    || !(strncmp(buffers[1], "LEFT", 8192)))
  {
   returnCode = 3 ;
  } else if
     ( !(strncmp(buffers[1], "D", 8192))
    || !(strncmp(buffers[1], "RIGHT", 8192)))
  {
   returnCode = 4;
  } else {
   returnCode = 666;
  }
 } else if (numWords == 2) {
  if ( !(strncmp(buffers[1], "T", 8192))
    || !(strncmp(buffers[1], "TAKE", 8192)))
  {
   returnCode = 5 ;
  } else if
     ( !(strncmp(buffers[1], "E", 8192))
    || !(strncmp(buffers[1], "TALK", 8192)))
  {
   returnCode = 6 ;
  } else if
     (( !(strncmp(buffers[1], "SWAG", 8192))
    || !(strncmp(buffers[1], "BASED", 8192))
    || !(strncmp(buffers[1], "LIL", 8192)))
  && ((!(strncmp(buffers[2], "B", 8192))
    || !(strncmp(buffers[2], "GOD", 8192))
    || !(strncmp(buffers[2], "MONEY", 8192)))))
  {
   returnCode = 7 ;
  } else {
   returnCode = 666 ;
  }
 } else {
  returnCode = 666;
 }
 for ( i = 0 ; i < numWords ; i++ )
  free( buffers[i] ) ;
 return returnCode ;
}

canonical_original_code:
int getInput(int *item)
{
 int returnCode = -1;
 unsigned long i;
 unsigned long numWords;
 unsigned long buffLength;
 char *buffers[10];
 buffers[0] = malloc( sizeof (char) * 8192 ) ;
 if (buffers[0] == ((void *)0)) return -2;
 fgets( buffers[0] , 8192 , stdin ) ;
 buffLength = strlen( buffers[0] ) ;
 printf( "DEBUG DATA: main input buffer: %s\nbuffer length: %lu \n\n",
  buffers[0], buffLength ) ;
 if (( buffLength > 0)
  && ( buffers[0][buffLength-1] == '\n'))
       buffers[0][buffLength-1] = '\0';
 numWords = inputToWords( buffers, buffLength );
 printf("number of words = %zu\n\n", numWords);
 for ( i = 1 ; i <= numWords ; i++ ){
  upperString(buffers[i]);
  printf("word %d: %s\n", i, buffers[i]);
 }
 if (numWords == 1) {
  if (!(strncmp(buffers[1], "Q", 8192))
      || !(strncmp(buffers[1], "QUIT", 8192)))
  {
   returnCode = 0 ;
  } else if
     ( !(strncmp(buffers[1], "W", 8192))
    || !(strncmp(buffers[1], "FORWARD", 8192)))
  {
   returnCode = 1 ;
  } else if
     ( !(strncmp(buffers[1], "S", 8192))
    || !(strncmp(buffers[1], "BACKWARD", 8192)))
  {
   returnCode = 2 ;
  } else if
     ( !(strncmp(buffers[1], "A", 8192))
    || !(strncmp(buffers[1], "LEFT", 8192)))
  {
   returnCode = 3 ;
  } else if
     ( !(strncmp(buffers[1], "D", 8192))
    || !(strncmp(buffers[1], "RIGHT", 8192)))
  {
   returnCode = 4;
  } else {
   returnCode = 666;
  }
 } else if (numWords == 2) {
  if ( !(strncmp(buffers[1], "T", 8192))
    || !(strncmp(buffers[1], "TAKE", 8192)))
  {
   returnCode = 5 ;
  } else if
     ( !(strncmp(buffers[1], "E", 8192))
    || !(strncmp(buffers[1], "TALK", 8192)))
  {
   returnCode = 6 ;
  } else if
     (( !(strncmp(buffers[1], "SWAG", 8192))
    || !(strncmp(buffers[1], "BASED", 8192))
    || !(strncmp(buffers[1], "LIL", 8192)))
  && ((!(strncmp(buffers[2], "B", 8192))
    || !(strncmp(buffers[2], "GOD", 8192))
    || !(strncmp(buffers[2], "MONEY", 8192)))))
  {
   returnCode = 7 ;
  } else {
   returnCode = 666 ;
  }
 } else {
  returnCode = 666;
 }
 for ( i = 0 ; i < numWords ; i++ )
  free( buffers[i] ) ;
 return returnCode ;
}

variable_types:
item
int *

variable_types: returnCode int

variable_types:
numWords
unsigned long

variable_types:
buffLength
unsigned long

variable_types:
buffers
char *[10]


interfaceLoop

decompiled_code:
__int64 interfaceLoop()
{
int v0; // eax
char v2[12]; // [rsp+Ch] [rbp-Ch] BYREF

while ( 1 )
{
v0 = getInput(v2);
if ( !v0 )
break;
if ( v0 > 7 )
{
if ( v0 == 666 )
puts("input not recognized");
else
LABEL_14:
printf("shouldnt have gotten here. default case line %d", 69LL);
}
else
{
if ( v0 <= 0 )
goto LABEL_14;
switch ( v0 )
{
case 1:
puts("GO FORWARD");
break;
case 2:
puts("GO BACKWARD");
break;
case 3:
puts("GO LEFT");
break;
case 4:
puts("GO RIGHT");
break;
case 5:
puts("TAKING SOMETHING");
break;
case 6:
puts("TALKING THE TALK");
break;
case 7:
puts("SWAG TO THE #YOLO INFINITY");
break;
default:
goto LABEL_14;
}
}
}
puts("GAME ENDED BY USER\n\n");
return 0LL;
}

canonical_decompiled_code:
__int64 func3()
{
int v0; // eax
char v2[12]; // [rsp+Ch] [rbp-Ch] BYREF

while ( 1 )
{
v0 = func2(v2);
if ( !v0 )
break;
if ( v0 > 7 )
{
if ( v0 == 666 )
puts("input not recognized");
else
LABEL_14:
printf("shouldnt have gotten here. default case line %d", 69LL);
}
else
{
if ( v0 <= 0 )
goto LABEL_14;
switch ( v0 )
{
case 1:
puts("GO FORWARD");
break;
case 2:
puts("GO BACKWARD");
break;
case 3:
puts("GO LEFT");
break;
case 4:
puts("GO RIGHT");
break;
case 5:
puts("TAKING SOMETHING");
break;
case 6:
puts("TALKING THE TALK");
break;
case 7:
puts("SWAG TO THE #YOLO INFINITY");
break;
default:
goto LABEL_14;
}
}
}
puts("GAME ENDED BY USER\n\n");
return 0LL;
}

original_code:
int interfaceLoop()
{
 int inputCode, itemCode;
 while ( ( inputCode = getInput(&itemCode) ) )
 {
  switch ( inputCode ) {
  case 1:
   printf( "GO FORWARD\n" ) ;
   break;
  case 2:
   printf( "GO BACKWARD\n" ) ;
   break;
  case 3:
   printf( "GO LEFT\n" ) ;
   break;
  case 4:
   printf( "GO RIGHT\n" ) ;
   break;
  case 5:
   printf( "TAKING SOMETHING\n" ) ;
   break;
  case 6:
   printf( "TALKING THE TALK\n" ) ;
   break;
  case 7:
   printf( "SWAG TO THE #YOLO INFINITY\n" ) ;
   break;
  case 666:
   printf("input not recognized\n");
   break;
  default:
   printf("shouldnt have gotten here. "
          "default case line %d", 69);
  }
 }
 printf( "GAME ENDED BY USER\n\n\n" );
 return 0 ;
}

canonical_original_code:
int interfaceLoop()
{
 int inputCode; int itemCode;
 while ( ( inputCode = getInput(&itemCode) ) )
 {
  switch ( inputCode ) {
  case 1:
   printf( "GO FORWARD\n" ) ;
   break;
  case 2:
   printf( "GO BACKWARD\n" ) ;
   break;
  case 3:
   printf( "GO LEFT\n" ) ;
   break;
  case 4:
   printf( "GO RIGHT\n" ) ;
   break;
  case 5:
   printf( "TAKING SOMETHING\n" ) ;
   break;
  case 6:
   printf( "TALKING THE TALK\n" ) ;
   break;
  case 7:
   printf( "SWAG TO THE #YOLO INFINITY\n" ) ;
   break;
  case 666:
   printf("input not recognized\n");
   break;
  default:
   printf("shouldnt have gotten here. "
          "default case line %d", 69);
  }
 }
 printf( "GAME ENDED BY USER\n\n\n" );
 return 0 ;
}

variable_types: inputCode int

variable_types: itemCode int


decompiled_code:
int __fastcall default_com_err_proc(const char *a1, __int64 a2, const char *a3, void *a4)
{
FILE *v7; // r13
const char *v8; // rax

if ( a1 )
{
fputs(a1, stderr);
fwrite(&unk_1A1, 1uLL, 2uLL, stderr);
}
if ( a2 )
{
v7 = stderr;
v8 = (const char *)error_message(a2);
fputs(v8, v7);
fputc(32, stderr);
}
if ( a3 )
vfprintf(stderr, a3, a4);
fwrite(&unk_1A4, 1uLL, 2uLL, stderr);
return fflush(stderr);
}

canonical_decompiled_code:
int __fastcall func0(const char *a1, __int64 a2, const char *a3, void *a4)
{
FILE *v7; // r13
const char *v8; // rax

if ( a1 )
{
fputs(a1, stderr);
fwrite(&unk_1A1, 1uLL, 2uLL, stderr);
}
if ( a2 )
{
v7 = stderr;
v8 = (const char *)error_message(a2);
fputs(v8, v7);
fputc(32, stderr);
}
if ( a3 )
vfprintf(stderr, a3, a4);
fwrite(&unk_1A4, 1uLL, 2uLL, stderr);
return fflush(stderr);
}

original_code:
static void
default_com_err_proc (const char *whoami, errcode_t code, const
        char *fmt, va_list args)
{
    if (whoami) {
 fputs(whoami, stderr);
 fputs(": ", stderr);
    }
    if (code) {
 fputs(error_message(code), stderr);
 fputs(" ", stderr);
    }
    if (fmt) {
        vfprintf (stderr, fmt, args);
    }
    fputs("\r\n", stderr);
    fflush(stderr);
}

canonical_original_code:
static void default_com_err_proc(char *whoami, long code, char *fmt, __builtin_va_list args)
{
    if (whoami) {
 fputs(whoami, stderr);
 fputs(": ", stderr);
    }
    if (code) {
 fputs(error_message(code), stderr);
 fputs(" ", stderr);
    }
    if (fmt) {
        vfprintf (stderr, fmt, args);
    }
    fputs("\r\n", stderr);
    fflush(stderr);
}

variable_types:
whoami
char *

variable_types: code long

variable_types:
fmt
char *


decompiled_code:
__int64 com_err_va()
{
return com_err_hook();
}

canonical_decompiled_code:
__int64 func1()
{
return com_err_hook();
}

original_code:
void com_err_va (const char *whoami, errcode_t code, const char *fmt,
   va_list args)
{
    (*com_err_hook) (whoami, code, fmt, args);
}

canonical_original_code:
void com_err_va(char *whoami, long code, char *fmt, __builtin_va_list args)
{
    (*com_err_hook) (whoami, code, fmt, args);
}


decompiled_code:
__int64 com_err(__int64 a1, __int64 a2, __int64 a3, ...)
{
gcc_va_list va; // [rsp+8h] [rbp-D0h] BYREF

if ( !com_err_hook )
com_err_hook = (__int64 (*)(void))default_com_err_proc;
va_start(va, a3);
return com_err_va(a1, a2, a3, va);
}

canonical_decompiled_code:
__int64 func2(__int64 a1, __int64 a2, __int64 a3, ...)
{
gcc_va_list va; // [rsp+8h] [rbp-D0h] BYREF

if ( !com_err_hook )
com_err_hook = (__int64 (*)(void))default_com_err_proc;
va_start(va, a3);
return func1(a1, a2, a3, va);
}

original_code:
void com_err (const char *whoami,
       errcode_t code,
       const char *fmt, ...)
{
    va_list pvar;
    if (!com_err_hook)
 com_err_hook = default_com_err_proc;
    __builtin_va_start(pvar,fmt);
    com_err_va (whoami, code, fmt, pvar);
    __builtin_va_end(pvar);
}

canonical_original_code:
void com_err(char *whoami, long code, char *fmt, ...)
{
    __builtin_va_list pvar;
    if (!com_err_hook)
 com_err_hook = default_com_err_proc;
    __builtin_va_start(pvar,fmt);
    com_err_va (whoami, code, fmt, pvar);
    __builtin_va_end(pvar);
}


decompiled_code:
void init_debug()
{
char *v0; // rax
char *v1; // rax

if ( (debug_mask & 0x8000) == 0 )
{
v0 = getenv("COMERR_DEBUG");
if ( v0 )
debug_mask = strtoul(v0, 0LL, 0);
v1 = safe_getenv("COMERR_DEBUG_FILE");
if ( v1 )
debug_f = fopen(v1, "a");
if ( !debug_f )
{
debug_f = fopen("/dev/tty", "a");
if ( !debug_f )
debug_mask = 0;
}
debug_mask |= 0x8000u;
}
}

canonical_decompiled_code:
void func1()
{
char *v0; // rax
char *v1; // rax

if ( (debug_mask & 0x8000) == 0 )
{
v0 = getenv("COMERR_DEBUG");
if ( v0 )
debug_mask = strtoul(v0, 0LL, 0);
v1 = func0("COMERR_DEBUG_FILE");
if ( v1 )
debug_f = fopen(v1, "a");
if ( !debug_f )
{
debug_f = fopen("/dev/tty", "a");
if ( !debug_f )
debug_mask = 0;
}
debug_mask |= 0x8000u;
}
}

original_code:
static void init_debug(void)
{
 char *dstr;
 char *fn;
 if (debug_mask & 0x8000)
  return;
 dstr = getenv("COMERR_DEBUG");
 if (dstr)
  debug_mask = strtoul(dstr, 0, 0);
 fn = safe_getenv("COMERR_DEBUG_FILE");
 if (fn)
  debug_f = fopen(fn, "a");
 if (!debug_f)
  debug_f = fopen("/dev/tty", "a");
 if (!debug_f)
  debug_mask = 0;
 debug_mask |= 0x8000;
}

canonical_original_code:
static void init_debug()
{
 char *dstr;
 char *fn;
 if (debug_mask & 0x8000)
  return;
 dstr = getenv("COMERR_DEBUG");
 if (dstr)
  debug_mask = strtoul(dstr, 0, 0);
 fn = safe_getenv("COMERR_DEBUG_FILE");
 if (fn)
  debug_f = fopen(fn, "a");
 if (!debug_f)
  debug_f = fopen("/dev/tty", "a");
 if (!debug_f)
  debug_mask = 0;
 debug_mask |= 0x8000;
}

variable_types:
dstr
char *

variable_types:
fn
char *


decompiled_code:
char *__fastcall error_message(__int64 a1)
{
int v1; // ebx
unsigned __int64 v2; // rdi
_QWORD *v3; // rax
__int64 v4; // rdx
_QWORD *v5; // rax
__int64 v6; // rdx
const char *v7; // rax
char *v8; // rax
char *v9; // rcx
char *result; // rax

v1 = (unsigned __int8)a1;
v2 = a1 & 0xFFFFFFFFFFFFFF00LL;
if ( v2 )
{
v3 = (_QWORD *)et_list;
if ( et_list )
{
while ( 1 )
{
v4 = v3[1];
if ( *(_QWORD *)(v4 + 8) == v2 )
break;
v3 = (_QWORD *)*v3;
if ( !v3 )
goto LABEL_5;
}
if ( *(_DWORD *)(v4 + 16) > v1 )
return *(char **)(*(_QWORD *)v4 + 8LL * v1);
}
else
{
LABEL_5:
v5 = et_dynamic_list;
if ( et_dynamic_list )
{
while ( 1 )
{
v6 = v5[1];
if ( *(_QWORD *)(v6 + 8) == v2 )
break;
v5 = (_QWORD *)*v5;
if ( !v5 )
goto LABEL_8;
}
if ( *(_DWORD *)(v6 + 16) > v1 )
return *(char **)(*(_QWORD *)v6 + 8LL * v1);
}
}
LABEL_8:
strcpy(buffer, "Unknown code ");
v7 = (const char *)error_table_name();
strcat(buffer, v7);
*(_WORD *)&buffer[strlen(buffer)] = 32;
LABEL_9:
if ( buffer[0] )
{
v8 = buffer;
do
++v8;
while ( *v8 );
}
else
{
v8 = buffer;
}
if ( v1 <= 99 )
{
if ( v1 <= 9 )
goto LABEL_15;
v9 = v8;
}
else
{
v9 = v8 + 1;
*v8 = v1 / 100 + 48;
v1 %= 100;
}
v8 = v9 + 1;
*v9 = v1 / 10 + 48;
v1 %= 10;
LABEL_15:
*(_WORD *)v8 = (unsigned __int8)(v1 + 48);
return buffer;
}
result = strerror(v1);
if ( !result )
{
strcpy(buffer, "Unknown code ");
goto LABEL_9;
}
return result;
}

canonical_decompiled_code:
char *__fastcall func2(__int64 a1)
{
int v1; // ebx
unsigned __int64 v2; // rdi
_QWORD *v3; // rax
__int64 v4; // rdx
_QWORD *v5; // rax
__int64 v6; // rdx
const char *v7; // rax
char *v8; // rax
char *v9; // rcx
char *result; // rax

v1 = (unsigned __int8)a1;
v2 = a1 & 0xFFFFFFFFFFFFFF00LL;
if ( v2 )
{
v3 = (_QWORD *)et_list;
if ( et_list )
{
while ( 1 )
{
v4 = v3[1];
if ( *(_QWORD *)(v4 + 8) == v2 )
break;
v3 = (_QWORD *)*v3;
if ( !v3 )
goto LABEL_5;
}
if ( *(_DWORD *)(v4 + 16) > v1 )
return *(char **)(*(_QWORD *)v4 + 8LL * v1);
}
else
{
LABEL_5:
v5 = et_dynamic_list;
if ( et_dynamic_list )
{
while ( 1 )
{
v6 = v5[1];
if ( *(_QWORD *)(v6 + 8) == v2 )
break;
v5 = (_QWORD *)*v5;
if ( !v5 )
goto LABEL_8;
}
if ( *(_DWORD *)(v6 + 16) > v1 )
return *(char **)(*(_QWORD *)v6 + 8LL * v1);
}
}
LABEL_8:
strcpy(buffer, "Unknown code ");
v7 = (const char *)error_table_name();
strcat(buffer, v7);
*(_WORD *)&buffer[strlen(buffer)] = 32;
LABEL_9:
if ( buffer[0] )
{
v8 = buffer;
do
++v8;
while ( *v8 );
}
else
{
v8 = buffer;
}
if ( v1 <= 99 )
{
if ( v1 <= 9 )
goto LABEL_15;
v9 = v8;
}
else
{
v9 = v8 + 1;
*v8 = v1 / 100 + 48;
v1 %= 100;
}
v8 = v9 + 1;
*v9 = v1 / 10 + 48;
v1 %= 10;
LABEL_15:
*(_WORD *)v8 = (unsigned __int8)(v1 + 48);
return buffer;
}
result = strerror(v1);
if ( !result )
{
strcpy(buffer, "Unknown code ");
goto LABEL_9;
}
return result;
}

original_code:
const char * error_message (errcode_t code)
{
    int offset;
    struct et_list *et;
    errcode_t table_num;
    int started = 0;
    char *cp;
    offset = (int) (code & ((1<<8)-1));
    table_num = code - offset;
    if (!table_num) {
 cp = strerror(offset);
 if (cp)
     return(cp);
 else
     goto oops;
    }
    for (et = _et_list; et; et = et->next) {
 if (et->table->base == table_num) {
     if (et->table->n_msgs <= offset)
  goto oops;
     return(et->table->msgs[offset]);
 }
    }
    for (et = _et_dynamic_list; et; et = et->next) {
 if (et->table->base == table_num) {
     if (et->table->n_msgs <= offset)
  goto oops;
     return(et->table->msgs[offset]);
 }
    }
oops:
    strcpy (buffer, "Unknown code ");
    if (table_num) {
 strcat (buffer, error_table_name (table_num));
 strcat (buffer, " ");
    }
    for (cp = buffer; *cp; cp++)
 ;
    if (offset >= 100) {
 *cp++ = '0' + offset / 100;
 offset %= 100;
 started++;
    }
    if (started || offset >= 10) {
 *cp++ = '0' + offset / 10;
 offset %= 10;
    }
    *cp++ = '0' + offset;
    *cp = '\0';
    return(buffer);
}

canonical_original_code:
char *error_message(long code)
{
    int offset;
    struct et_list *et;
    long table_num;
    int started = 0;
    char *cp;
    offset = (int) (code & ((1<<8)-1));
    table_num = code - offset;
    if (!table_num) {
 cp = strerror(offset);
 if (cp)
     return(cp);
 else
     goto oops;
    }
    for (et = _et_list; et; et = et->next) {
 if (et->table->base == table_num) {
     if (et->table->n_msgs <= offset)
  goto oops;
     return(et->table->msgs[offset]);
 }
    }
    for (et = _et_dynamic_list; et; et = et->next) {
 if (et->table->base == table_num) {
     if (et->table->n_msgs <= offset)
  goto oops;
     return(et->table->msgs[offset]);
 }
    }
oops:
    strcpy (buffer, "Unknown code ");
    if (table_num) {
 strcat (buffer, error_table_name (table_num));
 strcat (buffer, " ");
    }
    for (cp = buffer; *cp; cp++)
 ;
    if (offset >= 100) {
 *cp++ = '0' + offset / 100;
 offset %= 100;
 started++;
    }
    if (started || offset >= 10) {
 *cp++ = '0' + offset / 10;
 offset %= 10;
    }
    *cp++ = '0' + offset;
    *cp = '\0';
    return(buffer);
}

variable_types: offset int

variable_types: struct et_list { struct et_list *next; struct error_table { char **msgs; long base; int n_msgs; } *table; } *

variable_types: started int

variable_types:
cp
char *

user_defined_types: struct et_list { struct et_list *next; struct error_table *table; }


decompiled_code:
__int64 __fastcall add_error_table(_QWORD *a1)
{
_QWORD *v1; // rax
__int64 result; // rax
const char *v3; // rax

v1 = malloc(0x10uLL);
if ( !v1 )
return 12LL;
v1[1] = a1;
*v1 = et_dynamic_list;
et_dynamic_list = v1;
init_debug();
result = 0LL;
if ( (debug_mask & 1) != 0 )
{
v3 = (const char *)error_table_name(a1[1]);
fprintf(debug_f, "add_error_table: %s (0x%p)\n", v3, a1);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(_QWORD *a1)
{
_QWORD *v1; // rax
__int64 result; // rax
const char *v3; // rax

v1 = malloc(0x10uLL);
if ( !v1 )
return 12LL;
v1[1] = a1;
*v1 = et_dynamic_list;
et_dynamic_list = v1;
func1();
result = 0LL;
if ( (debug_mask & 1) != 0 )
{
v3 = (const char *)error_table_name(a1[1]);
fprintf(debug_f, "add_error_table: %s (0x%p)\n", v3, a1);
result = 0LL;
}
return result;
}

original_code:
errcode_t add_error_table(const struct error_table * et)
{
 struct et_list *el;
 if (!(el = (struct et_list *) malloc(sizeof(struct et_list))))
  return 12;
 el->table = et;
 el->next = _et_dynamic_list;
 _et_dynamic_list = el;
 init_debug();
 if (debug_mask & 0x0001)
  fprintf(debug_f, "add_error_table: %s (0x%p)\n",
   error_table_name(et->base),
   (const void *) et);
 return 0;
}

canonical_original_code:
long add_error_table(struct error_table *et)
{
 struct et_list *el;
 if (!(el = (struct et_list *) malloc(sizeof(struct et_list))))
  return 12;
 el->table = et;
 el->next = _et_dynamic_list;
 _et_dynamic_list = el;
 init_debug();
 if (debug_mask & 0x0001)
  fprintf(debug_f, "add_error_table: %s (0x%p)\n",
   error_table_name(et->base),
   (void *) et);
 return 0;
}

variable_types: struct error_table { char **msgs; long base; int n_msgs; } *

return_type: long


decompiled_code:
__int64 __fastcall remove_error_table(_QWORD *a1)
{
_QWORD *v1; // rbx
_QWORD *v2; // rdx
__int64 result; // rax
const char *v4; // rax
const char *v5; // rax

v1 = et_dynamic_list;
init_debug();
if ( v1 )
{
v2 = 0LL;
while ( *(_QWORD *)(v1[1] + 8LL) != a1[1] )
{
v2 = v1;
if ( !*v1 )
goto LABEL_6;
v1 = (_QWORD *)*v1;
}
if ( v2 )
*v2 = *v1;
else
et_dynamic_list = (void *)*v1;
free(v1);
result = 0LL;
if ( (debug_mask & 1) != 0 )
{
v4 = (const char *)error_table_name(a1[1]);
fprintf(debug_f, "remove_error_table: %s (0x%p)\n", v4, a1);
result = 0LL;
}
}
else
{
LABEL_6:
result = 2LL;
if ( (debug_mask & 1) != 0 )
{
v5 = (const char *)error_table_name(a1[1]);
fprintf(debug_f, "remove_error_table FAILED: %s (0x%p)\n", v5, a1);
result = 2LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(_QWORD *a1)
{
_QWORD *v1; // rbx
_QWORD *v2; // rdx
__int64 result; // rax
const char *v4; // rax
const char *v5; // rax

v1 = et_dynamic_list;
func1();
if ( v1 )
{
v2 = 0LL;
while ( *(_QWORD *)(v1[1] + 8LL) != a1[1] )
{
v2 = v1;
if ( !*v1 )
goto LABEL_6;
v1 = (_QWORD *)*v1;
}
if ( v2 )
*v2 = *v1;
else
et_dynamic_list = (void *)*v1;
free(v1);
result = 0LL;
if ( (debug_mask & 1) != 0 )
{
v4 = (const char *)error_table_name(a1[1]);
fprintf(debug_f, "remove_error_table: %s (0x%p)\n", v4, a1);
result = 0LL;
}
}
else
{
LABEL_6:
result = 2LL;
if ( (debug_mask & 1) != 0 )
{
v5 = (const char *)error_table_name(a1[1]);
fprintf(debug_f, "remove_error_table FAILED: %s (0x%p)\n", v5, a1);
result = 2LL;
}
}
return result;
}

original_code:
errcode_t remove_error_table(const struct error_table * et)
{
 struct et_list *el = _et_dynamic_list;
 struct et_list *el2 = 0;
 init_debug();
 while (el) {
  if (el->table->base == et->base) {
   if (el2)
    el2->next = el->next;
   else
    _et_dynamic_list = el->next;
   (void) free(el);
   if (debug_mask & 0x0001)
    fprintf(debug_f,
     "remove_error_table: %s (0x%p)\n",
     error_table_name(et->base),
     (const void *) et);
   return 0;
  }
  el2 = el;
  el = el->next;
 }
 if (debug_mask & 0x0001)
  fprintf(debug_f, "remove_error_table FAILED: %s (0x%p)\n",
   error_table_name(et->base),
   (const void *) et);
 return 2;
}

canonical_original_code:
long remove_error_table(struct error_table *et)
{
 struct et_list *el = _et_dynamic_list;
 struct et_list *el2 = 0;
 init_debug();
 while (el) {
  if (el->table->base == et->base) {
   if (el2)
    el2->next = el->next;
   else
    _et_dynamic_list = el->next;
   (void) free(el);
   if (debug_mask & 0x0001)
    fprintf(debug_f,
     "remove_error_table: %s (0x%p)\n",
     error_table_name(et->base),
     (void *) et);
   return 0;
  }
  el2 = el;
  el = el->next;
 }
 if (debug_mask & 0x0001)
  fprintf(debug_f, "remove_error_table FAILED: %s (0x%p)\n",
   error_table_name(et->base),
   (void *) et);
 return 2;
}

user_defined_types: struct error_table { char **msgs; long base; int n_msgs; }


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

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

original_code:
void
add_to_error_table(struct et_list *new_table)
{
 add_error_table(new_table->table);
}


getversion

decompiled_code:
__int64 getversion()
{
errno = -7776;
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 func0()
{
errno = -7776;
return 0xFFFFFFFFLL;
}

original_code:
int getversion (int fd, unsigned long * version)
{
 extern int errno;
 errno = -7776;
 return -1;
}

canonical_original_code:
int getversion(int fd, unsigned long *version)
{
 extern int errno;
 errno = -7776;
 return -1;
}

variable_types: fd int

variable_types:
version
unsigned long *

variable_types: errno int


original_code:
static void e2p_unpack_uuid(void *in, struct uuid *uu)
{
 __u8 *ptr = in;
 __u32 tmp;
 tmp = *ptr++;
 tmp = (tmp << 8) | *ptr++;
 tmp = (tmp << 8) | *ptr++;
 tmp = (tmp << 8) | *ptr++;
 uu->time_low = tmp;
 tmp = *ptr++;
 tmp = (tmp << 8) | *ptr++;
 uu->time_mid = tmp;
 tmp = *ptr++;
 tmp = (tmp << 8) | *ptr++;
 uu->time_hi_and_version = tmp;
 tmp = *ptr++;
 tmp = (tmp << 8) | *ptr++;
 uu->clock_seq = tmp;
 memcpy(uu->node, ptr, 6);
}

canonical_original_code:
static void e2p_unpack_uuid(void *in, struct uuid *uu)
{
 unsigned char *ptr = in;
 unsigned int tmp;
 tmp = *ptr++;
 tmp = (tmp << 8) | *ptr++;
 tmp = (tmp << 8) | *ptr++;
 tmp = (tmp << 8) | *ptr++;
 uu->time_low = tmp;
 tmp = *ptr++;
 tmp = (tmp << 8) | *ptr++;
 uu->time_mid = tmp;
 tmp = *ptr++;
 tmp = (tmp << 8) | *ptr++;
 uu->time_hi_and_version = tmp;
 tmp = *ptr++;
 tmp = (tmp << 8) | *ptr++;
 uu->clock_seq = tmp;
 memcpy(uu->node, ptr, 6);
}

variable_types:
in
void *

variable_types: struct uuid { unsigned int time_low; unsigned short time_mid; unsigned short time_hi_and_version; unsigned short clock_seq; unsigned char node[6]; } *

variable_types:
ptr
unsigned char *

variable_types:
tmp
unsigned int


decompiled_code:
__int64 __fastcall e2p_is_null_uuid(_BYTE *a1)
{
_BYTE *v1; // rax

v1 = a1 + 16;
while ( !*a1++ )
{
if ( a1 == v1 )
return 1LL;
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(_BYTE *a1)
{
_BYTE *v1; // rax

v1 = a1 + 16;
while ( !*a1++ )
{
if ( a1 == v1 )
return 1LL;
}
return 0LL;
}

original_code:
int e2p_is_null_uuid(void *uu)
{
 __u8 *cp;
 int i;
 for (i=0, cp = uu; i < 16; i++)
  if (*cp++)
   return 0;
 return 1;
}

canonical_original_code:
int e2p_is_null_uuid(void *uu)
{
 unsigned char *cp;
 int i;
 for (i=0, cp = uu; i < 16; i++)
  if (*cp++)
   return 0;
 return 1;
}

variable_types:
uu
void *

variable_types:
cp
unsigned char *

variable_types: i int


decompiled_code:
int __fastcall e2p_uuid_to_str(unsigned __int8 *a1, char *a2)
{
unsigned int v3; // [rsp+0h] [rbp-18h] BYREF
unsigned __int16 v4; // [rsp+4h] [rbp-14h]
unsigned __int16 v5; // [rsp+6h] [rbp-12h]
__int16 v6; // [rsp+8h] [rbp-10h]
unsigned __int8 v7; // [rsp+Ah] [rbp-Eh]
unsigned __int8 v8; // [rsp+Bh] [rbp-Dh]
unsigned __int8 v9; // [rsp+Ch] [rbp-Ch]
unsigned __int8 v10; // [rsp+Dh] [rbp-Bh]
unsigned __int8 v11; // [rsp+Eh] [rbp-Ah]
unsigned __int8 v12; // [rsp+Fh] [rbp-9h]

e2p_unpack_uuid(a1, (__int64)&v3);
return sprintf(
a2,
"%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x",
v3,
v4,
v5,
HIBYTE(v6),
(unsigned __int8)v6,
v7,
v8,
v9,
v10,
v11,
v12);
}

canonical_decompiled_code:
int __fastcall func2(unsigned __int8 *a1, char *a2)
{
unsigned int v3; // [rsp+0h] [rbp-18h] BYREF
unsigned __int16 v4; // [rsp+4h] [rbp-14h]
unsigned __int16 v5; // [rsp+6h] [rbp-12h]
__int16 v6; // [rsp+8h] [rbp-10h]
unsigned __int8 v7; // [rsp+Ah] [rbp-Eh]
unsigned __int8 v8; // [rsp+Bh] [rbp-Dh]
unsigned __int8 v9; // [rsp+Ch] [rbp-Ch]
unsigned __int8 v10; // [rsp+Dh] [rbp-Bh]
unsigned __int8 v11; // [rsp+Eh] [rbp-Ah]
unsigned __int8 v12; // [rsp+Fh] [rbp-9h]

func0(a1, (__int64)&v3);
return sprintf(
a2,
"%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x",
v3,
v4,
v5,
HIBYTE(v6),
(unsigned __int8)v6,
v7,
v8,
v9,
v10,
v11,
v12);
}

original_code:
void e2p_uuid_to_str(void *uu, char *out)
{
 struct uuid uuid;
 e2p_unpack_uuid(uu, &uuid);
 sprintf(out,
  "%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x",
  uuid.time_low, uuid.time_mid, uuid.time_hi_and_version,
  uuid.clock_seq >> 8, uuid.clock_seq & 0xFF,
  uuid.node[0], uuid.node[1], uuid.node[2],
  uuid.node[3], uuid.node[4], uuid.node[5]);
}

variable_types:
out
char *

variable_types: struct uuid { unsigned int time_low; unsigned short time_mid; unsigned short time_hi_and_version; unsigned short clock_seq; unsigned char node[6]; }


decompiled_code:
const char *__fastcall e2p_uuid2str(unsigned __int8 *a1)
{
int v1; // edx
const char *result; // rax

v1 = e2p_is_null_uuid(a1);
result = "<none>";
if ( !v1 )
{
e2p_uuid_to_str(a1, buf_0);
result = buf_0;
}
return result;
}

canonical_decompiled_code:
const char *__fastcall func3(unsigned __int8 *a1)
{
int v1; // edx
const char *result; // rax

v1 = func1(a1);
result = "<none>";
if ( !v1 )
{
func2(a1, buf_0);
result = buf_0;
}
return result;
}

original_code:
const char *e2p_uuid2str(void *uu)
{
 static char buf[80];
 if (e2p_is_null_uuid(uu))
  return "<none>";
 e2p_uuid_to_str(uu, buf);
 return buf;
}

variable_types:
buf
char [80]


decompiled_code:
void **__fastcall initialize_ext2_error_table_r(void **a1)
{
void **result; // rax
void **v2; // rbx

result = (void **)*a1;
v2 = a1;
if ( *a1 )
{
while ( *(char ***)result[1] != text )
{
if ( !*result )
{
v2 = result;
goto LABEL_7;
}
result = (void **)*result;
}
}
else
{
LABEL_7:
result = (void **)malloc(0x10uLL);
if ( result )
{
LABEL_8:
result[1] = &et_ext2_error_table;
*result = 0LL;
*v2 = result;
return result;
}
if ( !qword_88 )
{
result = (void **)&link;
goto LABEL_8;
}
}
return result;
}

canonical_decompiled_code:
void **__fastcall func0(void **a1)
{
void **result; // rax
void **v2; // rbx

result = (void **)*a1;
v2 = a1;
if ( *a1 )
{
while ( *(char ***)result[1] != text )
{
if ( !*result )
{
v2 = result;
goto LABEL_7;
}
result = (void **)*result;
}
}
else
{
LABEL_7:
result = (void **)malloc(0x10uLL);
if ( result )
{
LABEL_8:
result[1] = &et_ext2_error_table;
*result = 0LL;
*v2 = result;
return result;
}
if ( !qword_88 )
{
result = (void **)&link;
goto LABEL_8;
}
}
return result;
}

original_code:
void initialize_ext2_error_table_r(struct et_list **list)
{
    struct et_list *et, **end;
    for (end = list, et = *list; et; end = &et->next, et = et->next)
        if (et->table->msgs == text)
            return;
    et = malloc(sizeof(struct et_list));
    if (et == 0) {
        if (!link.table)
            et = &link;
        else
            return;
    }
    et->table = &et_ext2_error_table;
    et->next = 0;
    *end = et;
}

canonical_original_code:
void initialize_ext2_error_table_r(struct et_list **list)
{
    struct et_list *et; struct et_list **end;
    for (end = list, et = *list; et; end = &et->next, et = et->next)
        if (et->table->msgs == text)
            return;
    et = malloc(sizeof(struct et_list));
    if (et == 0) {
        if (!link.table)
            et = &link;
        else
            return;
    }
    et->table = &et_ext2_error_table;
    et->next = 0;
    *end = et;
}

variable_types: struct et_list { struct et_list *next; struct error_table { char **msgs; long base; int n_msgs; } *table; } **


decompiled_code:
void **initialize_ext2_error_table()
{
return initialize_ext2_error_table_r(&et_list);
}

canonical_decompiled_code:
void **func1()
{
return func0(&et_list);
}

original_code:
void initialize_ext2_error_table(void) {
    initialize_ext2_error_table_r(&_et_list);
}

canonical_original_code:
void initialize_ext2_error_table() {
    initialize_ext2_error_table_r(&_et_list);
}


decompiled_code:
char *__fastcall e2p_hash2string(unsigned int a1)
{
char *v1; // rdx
char *v2; // rax
char *result; // rax

v1 = s2;
if ( s2 )
{
v2 = (char *)&hash_list;
while ( *(_DWORD *)v2 != a1 )
{
v2 += 16;
v1 = (char *)*((_QWORD *)v2 + 1);
if ( !v1 )
goto LABEL_5;
}
result = v1;
}
else
{
LABEL_5:
sprintf(buf_0, "HASHALG_%d", a1);
result = buf_0;
}
return result;
}

canonical_decompiled_code:
char *__fastcall func0(unsigned int a1)
{
char *v1; // rdx
char *v2; // rax
char *result; // rax

v1 = s2;
if ( s2 )
{
v2 = (char *)&hash_list;
while ( *(_DWORD *)v2 != a1 )
{
v2 += 16;
v1 = (char *)*((_QWORD *)v2 + 1);
if ( !v1 )
goto LABEL_5;
}
result = v1;
}
else
{
LABEL_5:
sprintf(buf_0, "HASHALG_%d", a1);
result = buf_0;
}
return result;
}

original_code:
const char *e2p_hash2string(int num)
{
 struct hash *p;
 static char buf[20];
 for (p = hash_list; p->string; p++) {
  if (num == p->num)
   return p->string;
 }
 sprintf(buf, "HASHALG_%d", num);
 return buf;
}

variable_types: num int

variable_types: struct hash { int num; char *string; } *

variable_types:
buf
char [20]


decompiled_code:
__int64 __fastcall e2p_string2hash(char *s1)
{
const char *v1; // rsi
unsigned int *v2; // rbx
__int64 result; // rax
char *endptr; // [rsp+8h] [rbp-20h] BYREF

v1 = s2;
if ( s2 )
{
v2 = (unsigned int *)&hash_list;
while ( strcasecmp(s1, v1) )
{
v2 += 4;
v1 = (const char *)*((_QWORD *)v2 + 1);
if ( !v1 )
goto LABEL_5;
}
result = *v2;
}
else
{
LABEL_5:
if ( !strncasecmp(s1, "HASHALG_", 8uLL) )
{
if ( s1[8] )
{
result = strtol(s1 + 8, &endptr, 10);
if ( (unsigned int)result > 0xFF )
{
result = 0xFFFFFFFFLL;
}
else if ( *endptr )
{
result = 0xFFFFFFFFLL;
}
}
else
{
result = 0xFFFFFFFFLL;
}
}
else
{
result = 0xFFFFFFFFLL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(char *s1)
{
const char *v1; // rsi
unsigned int *v2; // rbx
__int64 result; // rax
char *endptr; // [rsp+8h] [rbp-20h] BYREF

v1 = s2;
if ( s2 )
{
v2 = (unsigned int *)&hash_list;
while ( strcasecmp(s1, v1) )
{
v2 += 4;
v1 = (const char *)*((_QWORD *)v2 + 1);
if ( !v1 )
goto LABEL_5;
}
result = *v2;
}
else
{
LABEL_5:
if ( !strncasecmp(s1, "HASHALG_", 8uLL) )
{
if ( s1[8] )
{
result = strtol(s1 + 8, &endptr, 10);
if ( (unsigned int)result > 0xFF )
{
result = 0xFFFFFFFFLL;
}
else if ( *endptr )
{
result = 0xFFFFFFFFLL;
}
}
else
{
result = 0xFFFFFFFFLL;
}
}
else
{
result = 0xFFFFFFFFLL;
}
}
return result;
}

original_code:
int e2p_string2hash(char *string)
{
 struct hash *p;
 char *eptr;
 int num;
 for (p = hash_list; p->string; p++) {
  if (!strcasecmp(string, p->string)) {
   return p->num;
  }
 }
 if (strncasecmp(string, "HASHALG_", 8))
  return -1;
 if (string[8] == 0)
  return -1;
 num = strtol(string+8, &eptr, 10);
 if (num > 255 || num < 0)
  return -1;
 if (*eptr)
  return -1;
 return num;
}

variable_types:
string
char *

variable_types:
eptr
char *


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

v1 = s2;
if ( s2 )
{
v2 = (char *)&mntopt_list;
while ( *(_DWORD *)v2 != a1 )
{
v2 += 16;
v1 = (char *)*((_QWORD *)v2 + 1);
if ( !v1 )
goto LABEL_5;
}
result = v1;
}
else
{
LABEL_5:
v3 = a1 >> 1;
if ( v3 )
{
LODWORD(v4) = 0;
do
{
v4 = (unsigned int)(v4 + 1);
v3 >>= 1;
}
while ( v3 );
}
else
{
v4 = 0LL;
}
sprintf(buf_0, "MNTOPT_%d", v4);
result = buf_0;
}
return result;
}

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

v1 = s2;
if ( s2 )
{
v2 = (char *)&mntopt_list;
while ( *(_DWORD *)v2 != a1 )
{
v2 += 16;
v1 = (char *)*((_QWORD *)v2 + 1);
if ( !v1 )
goto LABEL_5;
}
result = v1;
}
else
{
LABEL_5:
v3 = a1 >> 1;
if ( v3 )
{
LODWORD(v4) = 0;
do
{
v4 = (unsigned int)(v4 + 1);
v3 >>= 1;
}
while ( v3 );
}
else
{
v4 = 0LL;
}
sprintf(buf_0, "MNTOPT_%d", v4);
result = buf_0;
}
return result;
}

original_code:
const char *e2p_mntopt2string(unsigned int mask)
{
 struct mntopt *f;
 static char buf[20];
 int fnum;
 for (f = mntopt_list; f->string; f++) {
  if (mask == f->mask)
   return f->string;
 }
 for (fnum = 0; mask >>= 1; fnum++);
 sprintf(buf, "MNTOPT_%d", fnum);
 return buf;
}

variable_types:
mask
unsigned int

variable_types: struct mntopt { unsigned int mask; char *string; } *

variable_types: fnum int


decompiled_code:
__int64 __fastcall e2p_string2mntopt(char *s1, _DWORD *a2)
{
const char *v3; // rsi
char *v4; // rbp
unsigned int v5; // ebx
unsigned int v7; // eax
char *endptr; // [rsp+8h] [rbp-30h] BYREF

v3 = s2;
if ( s2 )
{
v4 = (char *)&mntopt_list;
while ( 1 )
{
v5 = strcasecmp(s1, v3);
if ( !v5 )
break;
v4 += 16;
v3 = (const char *)*((_QWORD *)v4 + 1);
if ( !v3 )
goto LABEL_5;
}
*a2 = *(_DWORD *)v4;
}
else
{
LABEL_5:
v5 = strncasecmp(s1, "MNTOPT_", 8uLL);
if ( v5 )
{
v5 = 1;
}
else if ( s1[8] )
{
v7 = strtol(s1 + 8, &endptr, 10);
if ( v7 > 0x20 )
{
v5 = 1;
}
else if ( *endptr )
{
v5 = 1;
}
else
{
*a2 = 1 << v7;
}
}
else
{
v5 = 1;
}
}
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func1(char *s1, _DWORD *a2)
{
const char *v3; // rsi
char *v4; // rbp
unsigned int v5; // ebx
unsigned int v7; // eax
char *endptr; // [rsp+8h] [rbp-30h] BYREF

v3 = s2;
if ( s2 )
{
v4 = (char *)&mntopt_list;
while ( 1 )
{
v5 = strcasecmp(s1, v3);
if ( !v5 )
break;
v4 += 16;
v3 = (const char *)*((_QWORD *)v4 + 1);
if ( !v3 )
goto LABEL_5;
}
*a2 = *(_DWORD *)v4;
}
else
{
LABEL_5:
v5 = strncasecmp(s1, "MNTOPT_", 8uLL);
if ( v5 )
{
v5 = 1;
}
else if ( s1[8] )
{
v7 = strtol(s1 + 8, &endptr, 10);
if ( v7 > 0x20 )
{
v5 = 1;
}
else if ( *endptr )
{
v5 = 1;
}
else
{
*a2 = 1 << v7;
}
}
else
{
v5 = 1;
}
}
return v5;
}

original_code:
int e2p_string2mntopt(char *string, unsigned int *mask)
{
 struct mntopt *f;
 char *eptr;
 int num;
 for (f = mntopt_list; f->string; f++) {
  if (!strcasecmp(string, f->string)) {
   *mask = f->mask;
   return 0;
  }
 }
 if (strncasecmp(string, "MNTOPT_", 8))
  return 1;
 if (string[8] == 0)
  return 1;
 num = strtol(string+8, &eptr, 10);
 if (num > 32 || num < 0)
  return 1;
 if (*eptr)
  return 1;
 *mask = 1 << num;
 return 0;
}

variable_types:
mask
unsigned int *

user_defined_types: struct mntopt { unsigned int mask; char *string; }