fatal

decompiled_code:
void __noreturn fatal(int a1, const char *a2, ...)
{
gcc_va_list va; // [rsp+8h] [rbp-D0h] BYREF

va_start(va, a2);
do_error(a1, a2, va);
abort();
}

canonical_decompiled_code:
void __noreturn func4(int a1, const char *a2, ...)
{
gcc_va_list va; // [rsp+8h] [rbp-D0h] BYREF

va_start(va, a2);
func0(a1, a2, va);
abort();
}

original_code:
void
fatal(int use_errno, const char *fmt, ...)
{
    va_list ap;
    __builtin_va_start(ap,fmt);
    do_error(use_errno, fmt, ap);
    __builtin_va_end(ap);
    abort();
    exit(1);
}

canonical_original_code:
void fatal(int use_errno, char *fmt, ...)
{
    __builtin_va_list ap;
    __builtin_va_start(ap,fmt);
    do_error(use_errno, fmt, ap);
    __builtin_va_end(ap);
    abort();
    exit(1);
}


repo: antonis-m/Parallel-Processing-Systems

decompiled_code:
int __fastcall timer_start(struct timeval *a1)
{
int result; // eax

result = gettimeofday(a1 + 1, 0LL);
if ( result < 0 )
{
perror("gettimeofday failed");
exit(1);
}
return result;
}

canonical_decompiled_code:
int __fastcall func1(struct timeval *a1)
{
int result; // eax

result = gettimeofday(a1 + 1, 0LL);
if ( result < 0 )
{
perror("gettimeofday failed");
exit(1);
}
return result;
}

original_code:
void timer_start(xtimer_t *timer)
{
    if (gettimeofday(&timer->timestamp, ((void *)0)) < 0) {
        perror("gettimeofday failed");
        exit(1);
    }
}

canonical_original_code:
void timer_start(struct xtimer *timer)
{
    if (gettimeofday(&timer->timestamp, ((void *)0)) < 0) {
        perror("gettimeofday failed");
        exit(1);
    }
}

variable_types: struct xtimer { struct timeval { long tv_sec; long tv_usec; } elapsed_time; struct timeval timestamp; } *

return_type: void

user_defined_types: struct xtimer { struct timeval elapsed_time; struct timeval timestamp; }


decompiled_code:
__int64 __fastcall timer_stop(_QWORD *a1)
{
__time_t v1; // rdx
__suseconds_t v2; // rax
__time_t v3; // rdx
__int64 result; // rax
struct timeval v5; // [rsp+0h] [rbp-18h] BYREF

if ( gettimeofday(&v5, 0LL) < 0 )
{
perror("gettimeofday failed");
exit(1);
}
v1 = v5.tv_sec - a1[2];
v2 = v5.tv_usec - a1[3];
if ( v2 < 0 )
{
--v1;
v2 += 1000000LL;
}
v3 = *a1 + v1;
*a1 = v3;
result = a1[1] + v2;
a1[1] = result;
if ( result > 999999 )
{
*a1 = v3 + 1;
result -= 1000000LL;
a1[1] = result;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(_QWORD *a1)
{
__time_t v1; // rdx
__suseconds_t v2; // rax
__time_t v3; // rdx
__int64 result; // rax
struct timeval v5; // [rsp+0h] [rbp-18h] BYREF

if ( gettimeofday(&v5, 0LL) < 0 )
{
perror("gettimeofday failed");
exit(1);
}
v1 = v5.tv_sec - a1[2];
v2 = v5.tv_usec - a1[3];
if ( v2 < 0 )
{
--v1;
v2 += 1000000LL;
}
v3 = *a1 + v1;
*a1 = v3;
result = a1[1] + v2;
a1[1] = result;
if ( result > 999999 )
{
*a1 = v3 + 1;
result -= 1000000LL;
a1[1] = result;
}
return result;
}

original_code:
void timer_stop(xtimer_t *timer)
{
    struct timeval t_stop;
    struct timeval t_interval;
    if (gettimeofday(&t_stop, ((void *)0)) < 0) {
        perror("gettimeofday failed");
        exit(1);
    }
    do { (&t_interval)->tv_sec = (&t_stop)->tv_sec - (&timer->timestamp)->tv_sec; (&t_interval)->tv_usec = (&t_stop)->tv_usec - (&timer->timestamp)->tv_usec; if ((&t_interval)->tv_usec < 0) { --(&t_interval)->tv_sec; (&t_interval)->tv_usec += 1000000; } } while (0);
    do { (&timer->elapsed_time)->tv_sec = (&timer->elapsed_time)->tv_sec + (&t_interval)->tv_sec; (&timer->elapsed_time)->tv_usec = (&timer->elapsed_time)->tv_usec + (&t_interval)->tv_usec; if ((&timer->elapsed_time)->tv_usec >= 1000000) { ++(&timer->elapsed_time)->tv_sec; (&timer->elapsed_time)->tv_usec -= 1000000; } } while (0);
}

canonical_original_code:
void timer_stop(struct xtimer *timer)
{
    struct timeval t_stop;
    struct timeval t_interval;
    if (gettimeofday(&t_stop, ((void *)0)) < 0) {
        perror("gettimeofday failed");
        exit(1);
    }
    do { (&t_interval)->tv_sec = (&t_stop)->tv_sec - (&timer->timestamp)->tv_sec; (&t_interval)->tv_usec = (&t_stop)->tv_usec - (&timer->timestamp)->tv_usec; if ((&t_interval)->tv_usec < 0) { --(&t_interval)->tv_sec; (&t_interval)->tv_usec += 1000000; } } while (0);
    do { (&timer->elapsed_time)->tv_sec = (&timer->elapsed_time)->tv_sec + (&t_interval)->tv_sec; (&timer->elapsed_time)->tv_usec = (&timer->elapsed_time)->tv_usec + (&t_interval)->tv_usec; if ((&timer->elapsed_time)->tv_usec >= 1000000) { ++(&timer->elapsed_time)->tv_sec; (&timer->elapsed_time)->tv_usec -= 1000000; } } while (0);
}

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


decompiled_code:
double __fastcall timer_elapsed_time(_QWORD *a1)
{
return (double)(int)a1[1] / 1000000.0 + (double)(int)*a1;
}

canonical_decompiled_code:
double __fastcall func3(_QWORD *a1)
{
return (double)(int)a1[1] / 1000000.0 + (double)(int)*a1;
}

original_code:
double timer_elapsed_time(xtimer_t *timer)
{
    return (timer->elapsed_time.tv_sec +
            timer->elapsed_time.tv_usec / (double) 1000000L);
}

canonical_original_code:
double timer_elapsed_time(struct xtimer *timer)
{
    return (timer->elapsed_time.tv_sec +
            timer->elapsed_time.tv_usec / (double) 1000000L);
}

return_type: double

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


decompiled_code:
void __fastcall free2D(void *ptr, int a2)
{
_QWORD *v2; // rax

if ( a2 > 1 )
{
v2 = (char *)ptr + 8;
do
*v2++ = 0LL;
while ( v2 != (_QWORD *)((char *)ptr + 8 * (unsigned int)(a2 - 2) + 16) );
}
free(*(void **)ptr);
free(ptr);
}

canonical_decompiled_code:
void __fastcall func7(void *ptr, int a2)
{
_QWORD *v2; // rax

if ( a2 > 1 )
{
v2 = (char *)ptr + 8;
do
*v2++ = 0LL;
while ( v2 != (_QWORD *)((char *)ptr + 8 * (unsigned int)(a2 - 2) + 16) );
}
free(*(void **)ptr);
free(ptr);
}

original_code:
void free2D(double ** a, int X, int Y) {
    int i;
    if (X>1) {
        for (i=1;i<X;i++)
            a[i]=((void *)0);
    }
    free(a[0]);
    free(a);
}

canonical_original_code:
void free2D(double **a, int X, int Y) {
    int i;
    if (X>1) {
        for (i=1;i<X;i++)
            a[i]=((void *)0);
    }
    free(a[0]);
    free(a);
}

variable_types:
a
double **

variable_types: X int

variable_types: Y int

variable_types: i int


variable_types: j int


decompiled_code:
int __fastcall print2D(_QWORD *a1, int a2, int a3)
{
_QWORD *v4; // rbp
__int64 v5; // r12
__int64 v6; // rbx
int result; // eax

if ( a2 > 0 )
{
v4 = a1;
v5 = 8LL * (unsigned int)(a3 - 1) + 8;
do
{
v6 = 0LL;
if ( a3 > 0 )
{
do
{
printf("%lf ", *(double *)(*v4 + v6));
v6 += 8LL;
}
while ( v6 != v5 );
}
result = putchar(10);
++v4;
}
while ( v4 != &a1[(unsigned int)(a2 - 1) + 1] );
}
return result;
}

canonical_decompiled_code:
int __fastcall func9(_QWORD *a1, int a2, int a3)
{
_QWORD *v4; // rbp
__int64 v5; // r12
__int64 v6; // rbx
int result; // eax

if ( a2 > 0 )
{
v4 = a1;
v5 = 8LL * (unsigned int)(a3 - 1) + 8;
do
{
v6 = 0LL;
if ( a3 > 0 )
{
do
{
printf("%lf ", *(double *)(*v4 + v6));
v6 += 8LL;
}
while ( v6 != v5 );
}
result = putchar(10);
++v4;
}
while ( v4 != &a1[(unsigned int)(a2 - 1) + 1] );
}
return result;
}

original_code:
void print2D(double ** a, int X, int Y) {
    int i,j;
    for (i=0;i<X;i++) {
        for (j=0;j<Y;j++)
            printf("%lf ",a[i][j]);
        printf("\n");
    }
}

canonical_original_code:
void print2D(double **a, int X, int Y) {
    int i; int j;
    for (i=0;i<X;i++) {
        for (j=0;j<Y;j++)
            printf("%lf ",a[i][j]);
        printf("\n");
    }
}


decompiled_code:
void **__fastcall copy_2d(void **a1, const void **a2, __int64 a3, __int64 a4, __int64 a5)
{
memcpy(*a1, *a2, a5 * a4 * a3);
return a1;
}

canonical_decompiled_code:
void **__fastcall func0(void **a1, const void **a2, __int64 a3, __int64 a4, __int64 a5)
{
memcpy(*a1, *a2, a5 * a4 * a3);
return a1;
}

original_code:
void **copy_2d(void **dst, const void **src, size_t n, size_t m, size_t size)
{
    memcpy(dst[0], src[0], n*m*size);
    return dst;
}

canonical_original_code:
void **copy_2d(void **dst, void **src, unsigned long n, unsigned long m, unsigned long size)
{
    memcpy(dst[0], src[0], n*m*size);
    return dst;
}

variable_types:
dst
void **

variable_types:
src
void **

variable_types:
n
unsigned long

variable_types:
m
unsigned long

variable_types:
size
unsigned long

return_type: void **


decompiled_code:
void __fastcall free_2d(void *ptr)
{
free(*(void **)ptr);
free(ptr);
}

canonical_decompiled_code:
void __fastcall func1(void *ptr)
{
free(*(void **)ptr);
free(ptr);
}

original_code:
void free_2d(void **array)
{
    free(array[0]);
    free(array);
}

variable_types:
array
void **


repo: antonis-m/oslab

decompiled_code:
void __fastcall toupper_buf(_BYTE *a1, __int64 a2)
{
const __int32_t **v3; // rdi
_BYTE *v4; // rax
_BYTE *v5; // rsi

if ( a2 )
{
v3 = __ctype_toupper_loc();
v4 = a1;
v5 = &a1[a2];
do
{
*v4 = (*v3)[(char)*v4];
++v4;
}
while ( v4 != v5 );
}
}

canonical_decompiled_code:
void __fastcall func9(_BYTE *a1, __int64 a2)
{
const __int32_t **v3; // rdi
_BYTE *v4; // rax
_BYTE *v5; // rsi

if ( a2 )
{
v3 = __ctype_toupper_loc();
v4 = a1;
v5 = &a1[a2];
do
{
*v4 = (*v3)[(char)*v4];
++v4;
}
while ( v4 != v5 );
}
}

original_code:
void toupper_buf(char *buf, size_t n)
{
 size_t i;
 for (i = 0; i < n; i++)
  buf[i] = toupper(buf[i]);
}

canonical_original_code:
void toupper_buf(char *buf, unsigned long n)
{
 unsigned long i;
 for (i = 0; i < n; i++)
  buf[i] = toupper(buf[i]);
}

variable_types:
buf
char *

variable_types:
i
unsigned long


decompiled_code:
ssize_t __fastcall insist_write(int fd, void *buf, size_t n)
{
size_t v3; // r13
size_t v5; // rbx
ssize_t result; // rax

v3 = n;
if ( !n )
return v3;
v5 = n;
while ( 1 )
{
result = write(fd, buf, v5);
if ( result < 0 )
break;
buf = (char *)buf + result;
v5 -= result;
if ( !v5 )
return v3;
}
return result;
}

canonical_decompiled_code:
ssize_t __fastcall func10(int fd, void *buf, size_t n)
{
size_t v3; // r13
size_t v5; // rbx
ssize_t result; // rax

v3 = n;
if ( !n )
return v3;
v5 = n;
while ( 1 )
{
result = write(fd, buf, v5);
if ( result < 0 )
break;
buf = (char *)buf + result;
v5 -= result;
if ( !v5 )
return v3;
}
return result;
}

original_code:
ssize_t insist_write(int fd, const void *buf, size_t cnt)
{
 ssize_t ret;
 size_t orig_cnt = cnt;
 while (cnt > 0) {
         ret = write(fd, buf, cnt);
         if (ret < 0)
                 return ret;
         buf += ret;
         cnt -= ret;
 }
 return orig_cnt;
}

canonical_original_code:
long insist_write(int fd, void *buf, unsigned long cnt)
{
 long ret;
 unsigned long orig_cnt = cnt;
 while (cnt > 0) {
         ret = write(fd, buf, cnt);
         if (ret < 0)
                 return ret;
         buf += ret;
         cnt -= ret;
 }
 return orig_cnt;
}

variable_types: fd int

variable_types:
buf
void *

variable_types:
cnt
unsigned long

variable_types: ret long

return_type: long


main

canonical_name: main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
int v3; // eax
int v4; // er12
int v5; // ebp
unsigned __int16 v6; // ax
__int64 v7; // rax
size_t v8; // rbx
struct sockaddr v9; // [rsp+0h] [rbp-B8h] BYREF
socklen_t addr_len; // [rsp+1Ch] [rbp-9Ch] BYREF
char buf[16]; // [rsp+20h] [rbp-98h] BYREF
char v12[136]; // [rsp+30h] [rbp-88h] BYREF

signal(13, (__sighandler_t)1);
v3 = socket(2, 1, 0);
if ( v3 < 0 )
{
perror("socket");
exit(1);
}
v4 = v3;
fwrite("Created TCP socket\n", 1uLL, 0x13uLL, stderr);
*(_DWORD *)&v9.sa_data[10] = 0;
v9.sa_family = 2;
*(_WORD *)v9.sa_data = _bswap_16(35001);
*(_QWORD *)&v9.sa_data[2] = (unsigned int)_bswap_32(0);
if ( bind(v4, &v9, 0x10u) < 0 )
{
perror("bind");
exit(1);
}
fprintf(stderr, "Bound TCP socket to port %d\n", 35001LL);
if ( listen(v4, 5) < 0 )
{
perror("listen");
exit(1);
}
while ( 1 )
{
fwrite("Waiting for an incoming connection...\n", 1uLL, 0x26uLL, stderr);
addr_len = 16;
v5 = accept(v4, &v9, &addr_len);
if ( v5 < 0 )
{
perror("accept");
exit(1);
}
if ( !inet_ntop(2, &v9.sa_data[2], buf, 0x10u) )
{
perror("could not format IP address");
exit(1);
}
v6 = _bswap_16(*(__int16 *)v9.sa_data);
fprintf(stderr, "Incoming connection from %s:%d\n", buf, v6);
while ( 1 )
{
v7 = read(v5, v12, 0x64uLL);
v8 = v7;
if ( v7 <= 0 )
break;
toupper_buf(v12, v7);
if ( insist_write(v5, v12, v8) != v8 )
{
perror("write to remote peer failed");
goto LABEL_11;
}
}
if ( v7 < 0 )
perror("read from remote peer failed");
else
fwrite("Peer went away\n", 1uLL, 0xFuLL, stderr);
LABEL_11:
if ( close(v5) < 0 )
perror("close");
}
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
int v3; // eax
int v4; // er12
int v5; // ebp
unsigned __int16 v6; // ax
__int64 v7; // rax
size_t v8; // rbx
struct sockaddr v9; // [rsp+0h] [rbp-B8h] BYREF
socklen_t addr_len; // [rsp+1Ch] [rbp-9Ch] BYREF
char buf[16]; // [rsp+20h] [rbp-98h] BYREF
char v12[136]; // [rsp+30h] [rbp-88h] BYREF

signal(13, (__sighandler_t)1);
v3 = socket(2, 1, 0);
if ( v3 < 0 )
{
perror("socket");
exit(1);
}
v4 = v3;
fwrite("Created TCP socket\n", 1uLL, 0x13uLL, stderr);
*(_DWORD *)&v9.sa_data[10] = 0;
v9.sa_family = 2;
*(_WORD *)v9.sa_data = func8(35001);
*(_QWORD *)&v9.sa_data[2] = (unsigned int)func7(0);
if ( bind(v4, &v9, 0x10u) < 0 )
{
perror("bind");
exit(1);
}
fprintf(stderr, "Bound TCP socket to port %d\n", 35001LL);
if ( listen(v4, 5) < 0 )
{
perror("listen");
exit(1);
}
while ( 1 )
{
fwrite("Waiting for an incoming connection...\n", 1uLL, 0x26uLL, stderr);
addr_len = 16;
v5 = accept(v4, &v9, &addr_len);
if ( v5 < 0 )
{
perror("accept");
exit(1);
}
if ( !inet_ntop(2, &v9.sa_data[2], buf, 0x10u) )
{
perror("could not format IP address");
exit(1);
}
v6 = func8(*(__int16 *)v9.sa_data);
fprintf(stderr, "Incoming connection from %s:%d\n", buf, v6);
while ( 1 )
{
v7 = read(v5, v12, 0x64uLL);
v8 = v7;
if ( v7 <= 0 )
break;
func9(v12, v7);
if ( func10(v5, v12, v8) != v8 )
{
perror("write to remote peer failed");
goto LABEL_11;
}
}
if ( v7 < 0 )
perror("read from remote peer failed");
else
fwrite("Peer went away\n", 1uLL, 0xFuLL, stderr);
LABEL_11:
if ( close(v5) < 0 )
perror("close");
}
}

original_code:
int main(void)
{
 char buf[100];
 char addrstr[16];
 int sd, newsd;
 ssize_t n;
 socklen_t len;
 struct sockaddr_in sa;
 signal(13, ((__sighandler_t) 1));
 if ((sd = socket(2, SOCK_STREAM, 0)) < 0) {
  perror("socket");
  exit(1);
 }
 fprintf(stderr, "Created TCP socket\n");
 memset(&sa, 0, sizeof(sa));
 sa.sin_family = 2;
 sa.sin_port = htons(35001);
 sa.sin_addr.s_addr = htonl(((in_addr_t) 0x00000000));
 if (bind(sd, (struct sockaddr *)&sa, sizeof(sa)) < 0) {
  perror("bind");
  exit(1);
 }
 fprintf(stderr, "Bound TCP socket to port %d\n", 35001);
 if (listen(sd, 5) < 0) {
  perror("listen");
  exit(1);
 }
 for (;;) {
  fprintf(stderr, "Waiting for an incoming connection...\n");
  len = sizeof(struct sockaddr_in);
  if ((newsd = accept(sd, (struct sockaddr *)&sa, &len)) < 0) {
   perror("accept");
   exit(1);
  }
  if (!inet_ntop(2, &sa.sin_addr, addrstr, sizeof(addrstr))) {
   perror("could not format IP address");
   exit(1);
  }
  fprintf(stderr, "Incoming connection from %s:%d\n",
   addrstr, ntohs(sa.sin_port));
  for (;;) {
   n = read(newsd, buf, sizeof(buf));
   if (n <= 0) {
    if (n < 0)
     perror("read from remote peer failed");
    else
     fprintf(stderr, "Peer went away\n");
    break;
   }
   toupper_buf(buf, n);
   if (insist_write(newsd, buf, n) != n) {
    perror("write to remote peer failed");
    break;
   }
  }
  if (close(newsd) < 0)
   perror("close");
 }
 return 1;
}

canonical_original_code:
int main()
{
 char buf[100];
 char addrstr[16];
 int sd; int newsd;
 long n;
 unsigned int len;
 struct sockaddr_in sa;
 signal(13, ((void (*)(int)) 1));
 if ((sd = socket(2, SOCK_STREAM, 0)) < 0) {
  perror("socket");
  exit(1);
 }
 fprintf(stderr, "Created TCP socket\n");
 memset(&sa, 0, sizeof(sa));
 sa.sin_family = 2;
 sa.sin_port = htons(35001);
 sa.sin_addr.s_addr = htonl(((unsigned int) 0x00000000));
 if (bind(sd, (struct sockaddr *)&sa, sizeof(sa)) < 0) {
  perror("bind");
  exit(1);
 }
 fprintf(stderr, "Bound TCP socket to port %d\n", 35001);
 if (listen(sd, 5) < 0) {
  perror("listen");
  exit(1);
 }
 for (;;) {
  fprintf(stderr, "Waiting for an incoming connection...\n");
  len = sizeof(struct sockaddr_in);
  if ((newsd = accept(sd, (struct sockaddr *)&sa, &len)) < 0) {
   perror("accept");
   exit(1);
  }
  if (!inet_ntop(2, &sa.sin_addr, addrstr, sizeof(addrstr))) {
   perror("could not format IP address");
   exit(1);
  }
  fprintf(stderr, "Incoming connection from %s:%d\n",
   addrstr, ntohs(sa.sin_port));
  for (;;) {
   n = read(newsd, buf, sizeof(buf));
   if (n <= 0) {
    if (n < 0)
     perror("read from remote peer failed");
    else
     fprintf(stderr, "Peer went away\n");
    break;
   }
   toupper_buf(buf, n);
   if (insist_write(newsd, buf, n) != n) {
    perror("write to remote peer failed");
    break;
   }
  }
  if (close(newsd) < 0)
   perror("close");
 }
 return 1;
}

variable_types:
buf
char [100]

variable_types:
addrstr
char [16]

variable_types: sd int

variable_types: newsd int

variable_types: n long

variable_types:
len
unsigned 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]; }

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 sockaddr { unsigned short sa_family; char sa_data[14]; }


decompiled_code:
__int64 __fastcall uint16_to_batt(unsigned __int16 a1)
{
double v1; // xmm0_8

v1 = 0.0;
if ( a1 )
v1 = 1023.0 / (double)a1 * 1.223;
return (unsigned int)(int)(v1 * 1000.0);
}

canonical_decompiled_code:
__int64 __fastcall func7(unsigned __int16 a1)
{
double v1; // xmm0_8

v1 = 0.0;
if ( a1 )
v1 = 1023.0 / (double)a1 * 1.223;
return (unsigned int)(int)(v1 * 1000.0);
}

original_code:
long uint16_to_batt(uint16_t value)
{
 double d;
 if (value != 0)
  d = 1.223 * (1023.0 / value);
 else
  d = -0;
 return (long)(d * 1000);
}

canonical_original_code:
long uint16_to_batt(unsigned short value)
{
 double d;
 if (value != 0)
  d = 1.223 * (1023.0 / value);
 else
  d = -0;
 return (long)(d * 1000);
}

variable_types:
value
unsigned short

variable_types: d double


decompiled_code:
__int64 __fastcall uint16_to_light(unsigned __int16 a1)
{
return (unsigned int)(int)((double)a1 * 5000000.0 / 65535.0);
}

canonical_decompiled_code:
__int64 __fastcall func8(unsigned __int16 a1)
{
return (unsigned int)(int)((double)a1 * 5000000.0 / 65535.0);
}

original_code:
long uint16_to_light(uint16_t value)
{
 return (long) (value * 5000000.0 / 65535);
}

canonical_original_code:
long uint16_to_light(unsigned short value)
{
 return (long) (value * 5000000.0 / 65535);
}


original_code:
long uint16_to_temp(uint16_t value)
{
 long l;
 double R1 = 10000.0;
 double ADC_FS = 1023.0;
 double Rth, Kelvin_Inv;
 double a = 0.001010024F;
 double b = 0.000242127F;
 double c = 0.000000146F;
 double res;
 Rth = (R1 * (ADC_FS - (double)value)) / (double)value;
 Kelvin_Inv = a + b * log(Rth) + c * pow(log(Rth), 3);
 res = (1.0 / Kelvin_Inv) - 272.15;
 l = (long)(res * 1000);
 return (l < -272150) ? -272150 : l;
}

canonical_original_code:
long uint16_to_temp(unsigned short value)
{
 long l;
 double R1 = 10000.0;
 double ADC_FS = 1023.0;
 double Rth; double Kelvin_Inv;
 double a = 0.001010024F;
 double b = 0.000242127F;
 double c = 0.000000146F;
 double res;
 Rth = (R1 * (ADC_FS - (double)value)) / (double)value;
 Kelvin_Inv = a + b * log(Rth) + c * pow(log(Rth), 3);
 res = (1.0 / Kelvin_Inv) - 272.15;
 l = (long)(res * 1000);
 return (l < -272150) ? -272150 : l;
}

variable_types: l long

variable_types: Rth double

variable_types: a double

variable_types: b double

variable_types: c double

variable_types: res double


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // r12
__int64 v4; // rbp
__int64 v5; // rbx
__int64 v6; // rax
int v7; // ebx
__int64 v8; // r13
__int64 v9; // r12
__int64 v10; // rbp
__int64 v11; // rax
__int64 v12; // r12
__int64 v13; // rbp
__int64 v14; // rbx
__int64 v15; // rax
int v16; // ebx
__int64 v17; // r13
__int64 v18; // r12
__int64 v19; // rbp
__int64 v20; // rax
__int64 v21; // r12
__int64 v22; // rbp
__int64 v23; // rbx
__int64 v24; // rax
int v25; // ebx
__int64 v26; // r13
__int64 v27; // r12
__int64 v28; // rbp
__int64 v29; // rax

fprintf(
_bss_start,
"/*\n"
" * lunix-tables.h\n"
" *\n"
" * Machine-generated file. DO NOT EDIT.\n"
" * See %s instead.\n"
" *\n"
" * Instead of doing floating-point in kernelspace,\n"
" * use the following lookup tables to convert 16-bit\n"
" * raw measurements to floating point values.\n"
" */\n"
"\n"
"long lookup_temperature[65536] = {\n",
"mk_lookup_tables.c");
v3 = uint16_to_temp(3u);
v4 = uint16_to_temp(2u);
v5 = uint16_to_temp(1u);
v6 = uint16_to_temp(0);
fprintf(_bss_start, "\t%ld, %ld, %ld, %ld", v6, v5, v4, v3);
v7 = 0;
do
{
fwrite(",\n", 1uLL, 2uLL, _bss_start);
v7 += 4;
v8 = uint16_to_temp((unsigned __int16)v7 + 3);
v9 = uint16_to_temp((unsigned __int16)v7 + 2);
v10 = uint16_to_temp((unsigned __int16)v7 + 1);
v11 = uint16_to_temp(v7);
fprintf(_bss_start, "\t%ld, %ld, %ld, %ld", v11, v10, v9, v8);
}
while ( v7 != 65532 );
fputc(10, _bss_start);
fwrite("};\n\nlong lookup_voltage[65536] = {\n", 1uLL, 0x23uLL, _bss_start);
v12 = uint16_to_batt(3u);
v13 = uint16_to_batt(2u);
v14 = uint16_to_batt(1u);
v15 = uint16_to_batt(0);
fprintf(_bss_start, "\t%ld, %ld, %ld, %ld", v15, v14, v13, v12);
v16 = 0;
do
{
fwrite(",\n", 1uLL, 2uLL, _bss_start);
v16 += 4;
v17 = uint16_to_batt((unsigned __int16)v16 + 3);
v18 = uint16_to_batt((unsigned __int16)v16 + 2);
v19 = uint16_to_batt((unsigned __int16)v16 + 1);
v20 = uint16_to_batt(v16);
fprintf(_bss_start, "\t%ld, %ld, %ld, %ld", v20, v19, v18, v17);
}
while ( v16 != 65532 );
fputc(10, _bss_start);
fwrite("};\n\nlong lookup_light[65536] = {\n", 1uLL, 0x21uLL, _bss_start);
v21 = uint16_to_light(3u);
v22 = uint16_to_light(2u);
v23 = uint16_to_light(1u);
v24 = uint16_to_light(0);
fprintf(_bss_start, "\t%ld, %ld, %ld, %ld", v24, v23, v22, v21);
v25 = 0;
do
{
fwrite(",\n", 1uLL, 2uLL, _bss_start);
v25 += 4;
v26 = uint16_to_light((unsigned __int16)v25 + 3);
v27 = uint16_to_light((unsigned __int16)v25 + 2);
v28 = uint16_to_light((unsigned __int16)v25 + 1);
v29 = uint16_to_light(v25);
fprintf(_bss_start, "\t%ld, %ld, %ld, %ld", v29, v28, v27, v26);
}
while ( v25 != 65532 );
fputc(10, _bss_start);
fwrite("};\n\n", 1uLL, 4uLL, _bss_start);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // r12
__int64 v4; // rbp
__int64 v5; // rbx
__int64 v6; // rax
int v7; // ebx
__int64 v8; // r13
__int64 v9; // r12
__int64 v10; // rbp
__int64 v11; // rax
__int64 v12; // r12
__int64 v13; // rbp
__int64 v14; // rbx
__int64 v15; // rax
int v16; // ebx
__int64 v17; // r13
__int64 v18; // r12
__int64 v19; // rbp
__int64 v20; // rax
__int64 v21; // r12
__int64 v22; // rbp
__int64 v23; // rbx
__int64 v24; // rax
int v25; // ebx
__int64 v26; // r13
__int64 v27; // r12
__int64 v28; // rbp
__int64 v29; // rax

fprintf(
_bss_start,
"/*\n"
" * lunix-tables.h\n"
" *\n"
" * Machine-generated file. DO NOT EDIT.\n"
" * See %s instead.\n"
" *\n"
" * Instead of doing floating-point in kernelspace,\n"
" * use the following lookup tables to convert 16-bit\n"
" * raw measurements to floating point values.\n"
" */\n"
"\n"
"long lookup_temperature[65536] = {\n",
"mk_lookup_tables.c");
v3 = func9(3u);
v4 = func9(2u);
v5 = func9(1u);
v6 = func9(0);
fprintf(_bss_start, "\t%ld, %ld, %ld, %ld", v6, v5, v4, v3);
v7 = 0;
do
{
fwrite(",\n", 1uLL, 2uLL, _bss_start);
v7 += 4;
v8 = func9((unsigned __int16)v7 + 3);
v9 = func9((unsigned __int16)v7 + 2);
v10 = func9((unsigned __int16)v7 + 1);
v11 = func9(v7);
fprintf(_bss_start, "\t%ld, %ld, %ld, %ld", v11, v10, v9, v8);
}
while ( v7 != 65532 );
fputc(10, _bss_start);
fwrite("};\n\nlong lookup_voltage[65536] = {\n", 1uLL, 0x23uLL, _bss_start);
v12 = func7(3u);
v13 = func7(2u);
v14 = func7(1u);
v15 = func7(0);
fprintf(_bss_start, "\t%ld, %ld, %ld, %ld", v15, v14, v13, v12);
v16 = 0;
do
{
fwrite(",\n", 1uLL, 2uLL, _bss_start);
v16 += 4;
v17 = func7((unsigned __int16)v16 + 3);
v18 = func7((unsigned __int16)v16 + 2);
v19 = func7((unsigned __int16)v16 + 1);
v20 = func7(v16);
fprintf(_bss_start, "\t%ld, %ld, %ld, %ld", v20, v19, v18, v17);
}
while ( v16 != 65532 );
fputc(10, _bss_start);
fwrite("};\n\nlong lookup_light[65536] = {\n", 1uLL, 0x21uLL, _bss_start);
v21 = func8(3u);
v22 = func8(2u);
v23 = func8(1u);
v24 = func8(0);
fprintf(_bss_start, "\t%ld, %ld, %ld, %ld", v24, v23, v22, v21);
v25 = 0;
do
{
fwrite(",\n", 1uLL, 2uLL, _bss_start);
v25 += 4;
v26 = func8((unsigned __int16)v25 + 3);
v27 = func8((unsigned __int16)v25 + 2);
v28 = func8((unsigned __int16)v25 + 1);
v29 = func8(v25);
fprintf(_bss_start, "\t%ld, %ld, %ld, %ld", v29, v28, v27, v26);
}
while ( v25 != 65532 );
fputc(10, _bss_start);
fwrite("};\n\n", 1uLL, 4uLL, _bss_start);
return 0;
}

original_code:
int main(void)
{
 unsigned int i;
 fprintf(stdout,
  "/*\n"
  " * lunix-tables.h\n"
  " *\n"
  " * Machine-generated file. DO NOT EDIT.\n"
  " * See %s instead.\n"
  " *\n"
  " * Instead of doing floating-point in kernelspace,\n"
  " * use the following lookup tables to convert 16-bit\n"
  " * raw measurements to floating point values.\n"
  " */\n"
  "\n"
  "long lookup_temperature[65536] = {\n", "mk_lookup_tables.c");
 for (i = 0; i <= 0xFFFC; i += 4) {
  fprintf(stdout, "\t%ld, %ld, %ld, %ld",
   uint16_to_temp(i), uint16_to_temp(i+1),
   uint16_to_temp(i+2), uint16_to_temp(i+3));
  fprintf(stdout, (i != 0xFFFC) ? ",\n" : "\n");
 }
 fprintf(stdout, "};\n\n"
  "long lookup_voltage[65536] = {\n");
 for (i = 0; i <= 0xFFFC; i += 4) {
  fprintf(stdout, "\t%ld, %ld, %ld, %ld",
   uint16_to_batt(i), uint16_to_batt(i+1),
   uint16_to_batt(i+2), uint16_to_batt(i+3));
  fprintf(stdout, (i != 0xFFFC) ? ",\n" : "\n");
 }
 fprintf(stdout, "};\n\n"
  "long lookup_light[65536] = {\n");
 for (i = 0; i <= 0xFFFC; i += 4) {
  fprintf(stdout, "\t%ld, %ld, %ld, %ld",
   uint16_to_light(i), uint16_to_light(i+1),
   uint16_to_light(i+2), uint16_to_light(i+3));
  fprintf(stdout, (i != 0xFFFC) ? ",\n" : "\n");
 }
 fprintf(stdout, "};\n\n");
 return 0;
}

canonical_original_code:
int main()
{
 unsigned int i;
 fprintf(stdout,
  "/*\n"
  " * lunix-tables.h\n"
  " *\n"
  " * Machine-generated file. DO NOT EDIT.\n"
  " * See %s instead.\n"
  " *\n"
  " * Instead of doing floating-point in kernelspace,\n"
  " * use the following lookup tables to convert 16-bit\n"
  " * raw measurements to floating point values.\n"
  " */\n"
  "\n"
  "long lookup_temperature[65536] = {\n", "mk_lookup_tables.c");
 for (i = 0; i <= 0xFFFC; i += 4) {
  fprintf(stdout, "\t%ld, %ld, %ld, %ld",
   uint16_to_temp(i), uint16_to_temp(i+1),
   uint16_to_temp(i+2), uint16_to_temp(i+3));
  fprintf(stdout, (i != 0xFFFC) ? ",\n" : "\n");
 }
 fprintf(stdout, "};\n\n"
  "long lookup_voltage[65536] = {\n");
 for (i = 0; i <= 0xFFFC; i += 4) {
  fprintf(stdout, "\t%ld, %ld, %ld, %ld",
   uint16_to_batt(i), uint16_to_batt(i+1),
   uint16_to_batt(i+2), uint16_to_batt(i+3));
  fprintf(stdout, (i != 0xFFFC) ? ",\n" : "\n");
 }
 fprintf(stdout, "};\n\n"
  "long lookup_light[65536] = {\n");
 for (i = 0; i <= 0xFFFC; i += 4) {
  fprintf(stdout, "\t%ld, %ld, %ld, %ld",
   uint16_to_light(i), uint16_to_light(i+1),
   uint16_to_light(i+2), uint16_to_light(i+3));
  fprintf(stdout, (i != 0xFFFC) ? ",\n" : "\n");
 }
 fprintf(stdout, "};\n\n");
 return 0;
}

variable_types:
i
unsigned int


decompiled_code:
__int64 __fastcall fill_urandom_buff(void *buf)
{
int v1; // eax
unsigned int v2; // ebx
unsigned int v3; // ebp

v1 = open("/dev/urandom", 0);
v2 = v1;
if ( v1 >= 0 )
{
v3 = read(v1, buf, 0x100uLL);
close(v2);
v2 = v3;
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func7(void *buf)
{
int v1; // eax
unsigned int v2; // ebx
unsigned int v3; // ebp

v1 = open("/dev/urandom", 0);
v2 = v1;
if ( v1 >= 0 )
{
v3 = read(v1, buf, 0x100uLL);
close(v2);
v2 = v3;
}
return v2;
}

original_code:
int fill_urandom_buff(char in[256]){
 int crypto_fd = open("/dev/urandom", 00);
 int ret = -1;
 if (crypto_fd < 0) return crypto_fd;
 ret = read(crypto_fd, (void *)in, 256);
 close(crypto_fd);
 return ret;
}

variable_types:
in
char [256]

variable_types: ret int


decompiled_code:
int __fastcall test_crypto(int fd)
{
char *v1; // rbx
char *v2; // rbx
char *v3; // rbx
int result; // eax
_BYTE v5[256]; // [rsp+0h] [rbp-3A8h] BYREF
char v6[256]; // [rsp+100h] [rbp-2A8h] BYREF
char s2[256]; // [rsp+200h] [rbp-1A8h] BYREF
char v8[16]; // [rsp+300h] [rbp-A8h] BYREF
char v9; // [rsp+310h] [rbp-98h] BYREF
__int64 v10; // [rsp+330h] [rbp-78h] BYREF
__int64 v11; // [rsp+338h] [rbp-70h]
char *v12; // [rsp+340h] [rbp-68h]
char *v13; // [rsp+348h] [rbp-60h]
__int64 v14; // [rsp+350h] [rbp-58h]
char *v15; // [rsp+358h] [rbp-50h]
__int64 v16; // [rsp+360h] [rbp-48h] BYREF
__int64 v17; // [rsp+368h] [rbp-40h]
char *v18; // [rsp+370h] [rbp-38h]
__int64 v19; // [rsp+378h] [rbp-30h]
__int64 v20; // [rsp+380h] [rbp-28h]
__int64 v21[4]; // [rsp+388h] [rbp-20h] BYREF

v16 = 0LL;
v17 = 0LL;
v18 = 0LL;
v19 = 0LL;
v20 = 0LL;
v21[0] = 0LL;
v10 = 0LL;
v11 = 0LL;
v12 = 0LL;
v13 = 0LL;
v14 = 0LL;
v15 = 0LL;
if ( (int)fill_urandom_buff(v5) < 0 )
{
puts("error @filling urandom data");
result = 1;
}
else
{
printf("\ninput data:");
v1 = v5;
do
printf("%x", (unsigned int)*v1++);
while ( v1 != v6 );
putchar(10);
LODWORD(v16) = 11;
LODWORD(v17) = 24;
v18 = &v9;
if ( ioctl(fd, 0xC0306366uLL, &v16) )
{
perror("ioctl(CIOCGSESSION)");
result = 1;
}
else
{
LODWORD(v10) = v21[0];
LODWORD(v11) = 256;
v12 = v5;
v13 = v6;
v15 = v8;
WORD2(v10) = 0;
printf("\nencrypted data:");
if ( ioctl(fd, 0xC0306368uLL, &v10) )
goto LABEL_17;
v2 = v6;
do
printf("%x", (unsigned int)*v2++);
while ( v2 != s2 );
putchar(10);
v12 = v6;
v13 = s2;
WORD2(v10) = 1;
if ( ioctl(fd, 0xC0306368uLL, &v10) )
{
LABEL_17:
perror("ioctl(CIOCCRYPT)");
result = 1;
}
else
{
printf("\ndecrypted data:");
v3 = s2;
do
printf("%x", (unsigned int)*v3++);
while ( v3 != v8 );
putchar(10);
if ( !memcmp(v5, s2, 0x100uLL) )
{
puts("\nTest passed");
result = ioctl(fd, 0x40046367uLL, v21);
if ( result )
{
perror("ioctl(CIOCFSESSION)");
result = 1;
}
}
else
{
fwrite("\nFAIL: Decrypted data are different from the input data.\n", 1uLL, 0x39uLL, _bss_start);
result = 1;
}
}
}
}
return result;
}

canonical_decompiled_code:
int __fastcall func8(int fd)
{
char *v1; // rbx
char *v2; // rbx
char *v3; // rbx
int result; // eax
_BYTE v5[256]; // [rsp+0h] [rbp-3A8h] BYREF
char v6[256]; // [rsp+100h] [rbp-2A8h] BYREF
char s2[256]; // [rsp+200h] [rbp-1A8h] BYREF
char v8[16]; // [rsp+300h] [rbp-A8h] BYREF
char v9; // [rsp+310h] [rbp-98h] BYREF
__int64 v10; // [rsp+330h] [rbp-78h] BYREF
__int64 v11; // [rsp+338h] [rbp-70h]
char *v12; // [rsp+340h] [rbp-68h]
char *v13; // [rsp+348h] [rbp-60h]
__int64 v14; // [rsp+350h] [rbp-58h]
char *v15; // [rsp+358h] [rbp-50h]
__int64 v16; // [rsp+360h] [rbp-48h] BYREF
__int64 v17; // [rsp+368h] [rbp-40h]
char *v18; // [rsp+370h] [rbp-38h]
__int64 v19; // [rsp+378h] [rbp-30h]
__int64 v20; // [rsp+380h] [rbp-28h]
__int64 v21[4]; // [rsp+388h] [rbp-20h] BYREF

v16 = 0LL;
v17 = 0LL;
v18 = 0LL;
v19 = 0LL;
v20 = 0LL;
v21[0] = 0LL;
v10 = 0LL;
v11 = 0LL;
v12 = 0LL;
v13 = 0LL;
v14 = 0LL;
v15 = 0LL;
if ( (int)func7(v5) < 0 )
{
puts("error @filling urandom data");
result = 1;
}
else
{
printf("\ninput data:");
v1 = v5;
do
printf("%x", (unsigned int)*v1++);
while ( v1 != v6 );
putchar(10);
LODWORD(v16) = 11;
LODWORD(v17) = 24;
v18 = &v9;
if ( ioctl(fd, 0xC0306366uLL, &v16) )
{
perror("ioctl(CIOCGSESSION)");
result = 1;
}
else
{
LODWORD(v10) = v21[0];
LODWORD(v11) = 256;
v12 = v5;
v13 = v6;
v15 = v8;
WORD2(v10) = 0;
printf("\nencrypted data:");
if ( ioctl(fd, 0xC0306368uLL, &v10) )
goto LABEL_17;
v2 = v6;
do
printf("%x", (unsigned int)*v2++);
while ( v2 != s2 );
putchar(10);
v12 = v6;
v13 = s2;
WORD2(v10) = 1;
if ( ioctl(fd, 0xC0306368uLL, &v10) )
{
LABEL_17:
perror("ioctl(CIOCCRYPT)");
result = 1;
}
else
{
printf("\ndecrypted data:");
v3 = s2;
do
printf("%x", (unsigned int)*v3++);
while ( v3 != v8 );
putchar(10);
if ( !memcmp(v5, s2, 0x100uLL) )
{
puts("\nTest passed");
result = ioctl(fd, 0x40046367uLL, v21);
if ( result )
{
perror("ioctl(CIOCFSESSION)");
result = 1;
}
}
else
{
fwrite("\nFAIL: Decrypted data are different from the input data.\n", 1uLL, 0x39uLL, _bss_start);
result = 1;
}
}
}
}
return result;
}

original_code:
static int test_crypto(int cfd)
{
 int i = -1;
        struct session_op sess;
        struct crypt_op cryp;
        struct {
                char in[256],
                        encrypted[256],
                        decrypted[256],
                        iv[16],
                        key[24];
        } data;
        memset(&sess, 0, sizeof(sess));
        memset(&cryp, 0, sizeof(cryp));
 if (fill_urandom_buff(data.in) < 0) {
  printf("error @filling urandom data\n");
  return 1;
 }
 printf("\ninput data:");
 for (i = 0; i < 256; i++) {
  printf("%x", data.in[i]);
 }
 printf("\n");
        sess.cipher = CRYPTO_AES_CBC;
        sess.keylen = 24;
        sess.key = (__u8 *)data.key;
        if (ioctl(cfd, (((2U|1U) << (((0 +8)+8)+14)) | ((('c')) << (0 +8)) | (((102)) << 0) | ((((sizeof(struct session_op)))) << ((0 +8)+8))), &sess)) {
                perror("ioctl(CIOCGSESSION)");
                return 1;
        }
        cryp.ses = sess.ses;
        cryp.len = sizeof(data.in);
        cryp.src = (__u8 *)data.in;
        cryp.dst = (__u8 *)data.encrypted;
        cryp.iv = (__u8 *)data.iv;
        cryp.op = 0;
 printf("\nencrypted data:");
        if (ioctl(cfd, (((2U|1U) << (((0 +8)+8)+14)) | ((('c')) << (0 +8)) | (((104)) << 0) | ((((sizeof(struct crypt_op)))) << ((0 +8)+8))), &cryp)) {
                perror("ioctl(CIOCCRYPT)");
                return 1;
        }
 for (i = 0; i < 256; i++) {
  printf("%x", data.encrypted[i]);
 }
 printf("\n");
        cryp.src = (__u8 *)data.encrypted;
        cryp.dst = (__u8 *)data.decrypted;
        cryp.op = 1;
        if (ioctl(cfd, (((2U|1U) << (((0 +8)+8)+14)) | ((('c')) << (0 +8)) | (((104)) << 0) | ((((sizeof(struct crypt_op)))) << ((0 +8)+8))), &cryp)) {
                perror("ioctl(CIOCCRYPT)");
                return 1;
        }
 printf("\ndecrypted data:");
 for (i = 0; i < 256; i++) {
  printf("%x", data.decrypted[i]);
 }
 printf("\n");
        if (memcmp(data.in, data.decrypted, sizeof(data.in)) != 0) {
                fprintf(stderr,
                        "\nFAIL: Decrypted data are different from the input data.\n");
                return 1;
        } else
                printf("\nTest passed\n");
        if (ioctl(cfd, (((1U) << (((0 +8)+8)+14)) | ((('c')) << (0 +8)) | (((103)) << 0) | ((((sizeof(__u32)))) << ((0 +8)+8))), &sess.ses)) {
                perror("ioctl(CIOCFSESSION)");
                return 1;
        }
        return 0;
}

canonical_original_code:
static int test_crypto(int cfd)
{
 int i = -1;
        struct session_op sess;
        struct crypt_op cryp;
        struct { char in[256]; } data;
        memset(&sess, 0, sizeof(sess));
        memset(&cryp, 0, sizeof(cryp));
 if (fill_urandom_buff(data.in) < 0) {
  printf("error @filling urandom data\n");
  return 1;
 }
 printf("\ninput data:");
 for (i = 0; i < 256; i++) {
  printf("%x", data.in[i]);
 }
 printf("\n");
        sess.cipher = CRYPTO_AES_CBC;
        sess.keylen = 24;
        sess.key = (unsigned char *)data.key;
        if (ioctl(cfd, (((2U|1U) << (((0 +8)+8)+14)) | ((('c')) << (0 +8)) | (((102)) << 0) | ((((sizeof(struct session_op)))) << ((0 +8)+8))), &sess)) {
                perror("ioctl(CIOCGSESSION)");
                return 1;
        }
        cryp.ses = sess.ses;
        cryp.len = sizeof(data.in);
        cryp.src = (unsigned char *)data.in;
        cryp.dst = (unsigned char *)data.encrypted;
        cryp.iv = (unsigned char *)data.iv;
        cryp.op = 0;
 printf("\nencrypted data:");
        if (ioctl(cfd, (((2U|1U) << (((0 +8)+8)+14)) | ((('c')) << (0 +8)) | (((104)) << 0) | ((((sizeof(struct crypt_op)))) << ((0 +8)+8))), &cryp)) {
                perror("ioctl(CIOCCRYPT)");
                return 1;
        }
 for (i = 0; i < 256; i++) {
  printf("%x", data.encrypted[i]);
 }
 printf("\n");
        cryp.src = (unsigned char *)data.encrypted;
        cryp.dst = (unsigned char *)data.decrypted;
        cryp.op = 1;
        if (ioctl(cfd, (((2U|1U) << (((0 +8)+8)+14)) | ((('c')) << (0 +8)) | (((104)) << 0) | ((((sizeof(struct crypt_op)))) << ((0 +8)+8))), &cryp)) {
                perror("ioctl(CIOCCRYPT)");
                return 1;
        }
 printf("\ndecrypted data:");
 for (i = 0; i < 256; i++) {
  printf("%x", data.decrypted[i]);
 }
 printf("\n");
        if (memcmp(data.in, data.decrypted, sizeof(data.in)) != 0) {
                fprintf(stderr,
                        "\nFAIL: Decrypted data are different from the input data.\n");
                return 1;
        } else
                printf("\nTest passed\n");
        if (ioctl(cfd, (((1U) << (((0 +8)+8)+14)) | ((('c')) << (0 +8)) | (((103)) << 0) | ((((sizeof(__u32)))) << ((0 +8)+8))), &sess.ses)) {
                perror("ioctl(CIOCFSESSION)");
                return 1;
        }
        return 0;
}

variable_types: cfd int

variable_types: i int

variable_types: struct session_op { unsigned int cipher; unsigned int mac; unsigned int keylen; unsigned char *key; unsigned int mackeylen; unsigned char *mackey; unsigned int ses; }

variable_types: struct crypt_op { unsigned int ses; unsigned short op; unsigned short flags; unsigned int len; unsigned char *src; unsigned char *dst; unsigned char *mac; unsigned char *iv; }

variable_types:
data
struct { char in[256]; }


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // rbx
int v4; // eax
int v5; // ebp
int v6; // edx
int result; // eax
char v8[136]; // [rsp+0h] [rbp-88h] BYREF

v3 = argv[1];
if ( !v3 )
v3 = "/dev/crypto";
v4 = open(v3, 2, 0LL);
if ( v4 < 0 )
{
sprintf(v8, "open %s", v3);
perror(v8);
result = 1;
}
else
{
v5 = v4;
v6 = test_crypto(v4);
result = 1;
if ( !v6 )
{
result = close(v5);
if ( result )
{
perror("close(fd)");
result = 1;
}
}
}
return result;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // rbx
int v4; // eax
int v5; // ebp
int v6; // edx
int result; // eax
char v8[136]; // [rsp+0h] [rbp-88h] BYREF

v3 = argv[1];
if ( !v3 )
v3 = "/dev/crypto";
v4 = open(v3, 2, 0LL);
if ( v4 < 0 )
{
sprintf(v8, "open %s", v3);
perror(v8);
result = 1;
}
else
{
v5 = v4;
v6 = func8(v4);
result = 1;
if ( !v6 )
{
result = close(v5);
if ( result )
{
perror("close(fd)");
result = 1;
}
}
}
return result;
}

original_code:
int main(int argc, char **argv)
{
        int fd = -1;
  char *filename;
  char error_str[100];
  filename = (argv[1] == ((void *)0)) ? "/dev/crypto" : argv[1];
        fd = open(filename, 02, 0);
        if (fd < 0) {
                sprintf(error_str, "open %s", filename);
                perror(error_str);
                return 1;
        }
        if (test_crypto(fd)){
                return 1;
 }
        if (close(fd)) {
                perror("close(fd)");
                return 1;
        }
        return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types: fd int

variable_types:
filename
char *


repo: anttisalonen/lvm

decompiled_code:
__int64 __fastcall get_two_nums(const char *a1, _DWORD *a2, _DWORD *a3)
{
__int64 result; // rax
char *endptr[4]; // [rsp+8h] [rbp-20h] BYREF

*a2 = strtol(a1, endptr, 0);
result = 0LL;
if ( *endptr[0] == 32 )
{
*a3 = strtol(endptr[0], endptr, 0);
result = (*endptr[0] == 10) | (unsigned __int8)(*endptr[0] == 0);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(const char *a1, _DWORD *a2, _DWORD *a3)
{
__int64 result; // rax
char *endptr[4]; // [rsp+8h] [rbp-20h] BYREF

*a2 = strtol(a1, endptr, 0);
result = 0LL;
if ( *endptr[0] == 32 )
{
*a3 = strtol(endptr[0], endptr, 0);
result = (*endptr[0] == 10) | (unsigned __int8)(*endptr[0] == 0);
}
return result;
}

original_code:
long int get_two_nums(const char *buf, int *a, int *b)
{
 char *endptr;
 *a = strtol(buf, &endptr, 0);
 if(*endptr && *endptr == ' ') {
  *b = strtol(endptr, &endptr, 0);
  return !(*endptr && *endptr != '\n');
 }
 else {
  return 0;
 }
}

canonical_original_code:
long get_two_nums(char *buf, int *a, int *b)
{
 char *endptr;
 *a = strtol(buf, &endptr, 0);
 if(*endptr && *endptr == ' ') {
  *b = strtol(endptr, &endptr, 0);
  return !(*endptr && *endptr != '\n');
 }
 else {
  return 0;
 }
}

variable_types:
buf
char *

variable_types:
a
int *

variable_types:
b
int *

variable_types:
endptr
char *


getnum

decompiled_code:
__int64 __fastcall getnum(const char *a1, int *a2)
{
__int64 result; // rax
int v3; // edx
char *endptr; // [rsp+8h] [rbp-10h] BYREF

result = strtol(a1, &endptr, 0);
if ( !*endptr || *endptr == 10 )
{
v3 = 1;
}
else
{
v3 = 0;
result = 0LL;
}
*a2 = v3;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(const char *a1, int *a2)
{
__int64 result; // rax
int v3; // edx
char *endptr; // [rsp+8h] [rbp-10h] BYREF

result = strtol(a1, &endptr, 0);
if ( !*endptr || *endptr == 10 )
{
v3 = 1;
}
else
{
v3 = 0;
result = 0LL;
}
*a2 = v3;
return result;
}

original_code:
long int getnum(const char *buf, int *succ)
{
 char *endptr;
 long int val = strtol(buf, &endptr, 0);
 if(*endptr && *endptr != '\n') {
  *succ = 0;
  return 0;
 }
 else {
  *succ = 1;
  return val;
 }
}

canonical_original_code:
long getnum(char *buf, int *succ)
{
 char *endptr;
 long val = strtol(buf, &endptr, 0);
 if(*endptr && *endptr != '\n') {
  *succ = 0;
  return 0;
 }
 else {
  *succ = 1;
  return val;
 }
}

variable_types:
succ
int *

variable_types: val long


original_code:
void num_to_be(long int val, int bytes, char *buf)
{
 char v = 0;
 if(val < 0) {
  v = 0x80;
  val = -val;
 }
 v |= (val & 0x7f);
 sprintf(buf, "%c", v);
 int i;
 val >>= 7;
 for(i = 1; i < bytes; i++) {
  v = val & 0xff;
  buf[i] = v;
  val >>= 8;
 }
}

canonical_original_code:
void num_to_be(long val, int bytes, char *buf)
{
 char v = 0;
 if(val < 0) {
  v = 0x80;
  val = -val;
 }
 v |= (val & 0x7f);
 sprintf(buf, "%c", v);
 int i;
 val >>= 7;
 for(i = 1; i < bytes; i++) {
  v = val & 0xff;
  buf[i] = v;
  val >>= 8;
 }
}

variable_types: bytes int

variable_types: v char


decompiled_code:
int __fastcall int_to_be(__int64 a1, char *a2)
{
return num_to_be(a1, 4, a2);
}

canonical_decompiled_code:
int __fastcall func3(__int64 a1, char *a2)
{
return func2(a1, 4, a2);
}

original_code:
void int_to_be(long int val, char *buf)
{
 num_to_be(val, 4, buf);
}

canonical_original_code:
void int_to_be(long val, char *buf)
{
 num_to_be(val, 4, buf);
}


decompiled_code:
int __fastcall output_char(char a1)
{
int result; // eax
int v2; // edx

if ( interactive )
{
if ( interactive_bufferpos > 1000 )
{
result = fwrite("Buffer full\n", 1uLL, 0xCuLL, stderr);
}
else
{
result = sprintf(&interactive_buffer[interactive_bufferpos], "%c", (unsigned int)a1);
++interactive_bufferpos;
}
}
else
{
result = output_buffer_offset++;
v2 = output_buffer_offset;
output_buffer[result] = a1;
++current_addr;
if ( v2 > 1023 )
{
fwrite("Output buffer full\n", 1uLL, 0x13uLL, stderr);
exit(1);
}
}
return result;
}

canonical_decompiled_code:
int __fastcall func4(char a1)
{
int result; // eax
int v2; // edx

if ( interactive )
{
if ( interactive_bufferpos > 1000 )
{
result = fwrite("Buffer full\n", 1uLL, 0xCuLL, stderr);
}
else
{
result = sprintf(&interactive_buffer[interactive_bufferpos], "%c", (unsigned int)a1);
++interactive_bufferpos;
}
}
else
{
result = output_buffer_offset++;
v2 = output_buffer_offset;
output_buffer[result] = a1;
++current_addr;
if ( v2 > 1023 )
{
fwrite("Output buffer full\n", 1uLL, 0x13uLL, stderr);
exit(1);
}
}
return result;
}

original_code:
void output_char(char ch)
{
 if(interactive) {
  if(interactive_bufferpos > 1000) {
   fprintf(stderr, "Buffer full\n");
   return;
  }
  interactive_bufferpos += sprintf(interactive_buffer + interactive_bufferpos,
    "%c", ch);
 }
 else {
  output_buffer[output_buffer_offset++] = ch;
  current_addr++;
  if(output_buffer_offset >= 1024) {
   fprintf(stderr, "Output buffer full\n");
   exit(1);
  }
 }
}

variable_types: ch char


decompiled_code:
int __fastcall output_header(char a1)
{
return putc(a1, stdout);
}

canonical_decompiled_code:
int __fastcall func5(char a1)
{
return putc(a1, stdout);
}

original_code:
void output_header(char ch)
{
 putc(ch, stdout);
}


decompiled_code:
const unsigned __int16 *__fastcall output_until_space(char *a1, int a2)
{
const unsigned __int16 **v3; // rbp
char v4; // di
const unsigned __int16 *result; // rax

v3 = _ctype_b_loc();
while ( 1 )
{
v4 = *a1;
result = *v3;
if ( ((*v3)[*a1] & 0x2000) != 0 || !v4 )
break;
if ( a2 )
output_header(v4);
else
output_char(v4);
++a1;
}
return result;
}

canonical_decompiled_code:
const unsigned __int16 *__fastcall func6(char *a1, int a2)
{
const unsigned __int16 **v3; // rbp
char v4; // di
const unsigned __int16 *result; // rax

v3 = _ctype_b_loc();
while ( 1 )
{
v4 = *a1;
result = *v3;
if ( ((*v3)[*a1] & 0x2000) != 0 || !v4 )
break;
if ( a2 )
func5(v4);
else
func4(v4);
++a1;
}
return result;
}

original_code:
void output_until_space(const char *str, int header)
{
 while(!((*__ctype_b_loc ())[(int) ((*str))] & (unsigned short int) _ISspace) && *str != '\0') {
  if(!header)
   output_char(*str);
  else
   output_header(*str);
  str++;
 }
}

canonical_original_code:
void output_until_space(char *str, int header)
{
 while(!((*__ctype_b_loc ())[(int) ((*str))] & (unsigned short) _ISspace) && *str != '\0') {
  if(!header)
   output_char(*str);
  else
   output_header(*str);
  str++;
 }
}

variable_types:
str
char *

variable_types: header int


decompiled_code:
int output_version()
{
return output_header(0);
}

canonical_decompiled_code:
int func7()
{
return func5(0);
}

original_code:
void output_version(void)
{
 output_header(0x00);
}

canonical_original_code:
void output_version()
{
 output_header(0x00);
}


decompiled_code:
int output_magic()
{
output_header(108);
output_header(83);
output_header(46);
return output_header(70);
}

original_code:
void output_magic(void)
{
 output_header(0x6c);
 output_header(0x53);
 output_header(0x2e);
 output_header(0x46);
}

canonical_original_code:
void output_magic()
{
 output_header(0x6c);
 output_header(0x53);
 output_header(0x2e);
 output_header(0x46);
}


decompiled_code:
int __fastcall output_nums(char a1, int a2, int a3)
{
char v5; // [rsp+Ch] [rbp-1Ch] BYREF
char v6; // [rsp+Dh] [rbp-1Bh]

output_char(a1);
num_to_be(a2, 2, &v5);
output_char(v5);
output_char(v6);
num_to_be(a3, 2, &v5);
output_char(v5);
return output_char(v6);
}

canonical_decompiled_code:
int __fastcall func9(char a1, int a2, int a3)
{
char v5; // [rsp+Ch] [rbp-1Ch] BYREF
char v6; // [rsp+Dh] [rbp-1Bh]

func4(a1);
func2(a2, 2, &v5);
func4(v5);
func4(v6);
func2(a3, 2, &v5);
func4(v5);
return func4(v6);
}

original_code:
void output_nums(char opcode, int a, int b)
{
 char buf[4];
 int i;
 output_char(opcode);
 num_to_be(a, 2, buf);
 for(i = 0; i < 2; i++)
  output_char(buf[i]);
 num_to_be(b, 2, buf);
 for(i = 0; i < 2; i++)
  output_char(buf[i]);
}

variable_types: opcode char

variable_types: a int

variable_types: b int

variable_types:
buf
char [4]

variable_types: i int


decompiled_code:
int __fastcall output_be(__int64 a1)
{
char *v1; // rbx
int result; // eax
char v3[4]; // [rsp+Ch] [rbp-1Ch] BYREF
char v4; // [rsp+10h] [rbp-18h] BYREF

int_to_be(a1, v3);
v1 = v3;
do
result = output_char(*v1++);
while ( v1 != &v4 );
return result;
}

canonical_decompiled_code:
int __fastcall func10(__int64 a1)
{
char *v1; // rbx
int result; // eax
char v3[4]; // [rsp+Ch] [rbp-1Ch] BYREF
char v4; // [rsp+10h] [rbp-18h] BYREF

func3(a1, v3);
v1 = v3;
do
result = func4(*v1++);
while ( v1 != &v4 );
return result;
}

original_code:
void output_be(long int num)
{
 char buf[4];
 int i;
 int_to_be(num, buf);
 for(i = 0; i < 4; i++) {
  output_char(buf[i]);
 }
}

canonical_original_code:
void output_be(long num)
{
 char buf[4];
 int i;
 int_to_be(num, buf);
 for(i = 0; i < 4; i++) {
  output_char(buf[i]);
 }
}

variable_types: num long


decompiled_code:
int __fastcall output_num(char a1, __int64 a2)
{
output_char(a1);
return output_be(a2);
}

canonical_decompiled_code:
int __fastcall func11(char a1, __int64 a2)
{
func4(a1);
return func10(a2);
}

original_code:
void output_num(char opcode, long int num)
{
 output_char(opcode);
 output_be(num);
}

canonical_original_code:
void output_num(char opcode, long num)
{
 output_char(opcode);
 output_be(num);
}


decompiled_code:
int __fastcall output_to_label(char a1, int a2)
{
label_offsets[a2] = output_buffer_offset;
return output_num(a1, 0LL);
}

canonical_decompiled_code:
int __fastcall func12(char a1, int a2)
{
label_offsets[a2] = output_buffer_offset;
return func11(a1, 0LL);
}

original_code:
void output_to_label(char opcode, int label_index)
{
 label_offsets[label_index] = output_buffer_offset;
 output_num(opcode, 0);
}


output

decompiled_code:
int __fastcall output(char a1)
{
return output_char(a1);
}

canonical_decompiled_code:
int __fastcall func13(char a1)
{
return func4(a1);
}

original_code:
void output(char opcode)
{
 output_char(opcode);
}


decompiled_code:
int sync_output()
{
int v0; // ebp
__int64 i; // rbx
int v2; // edi
int result; // eax
__int64 j; // rbx

v0 = output_buffer_offset;
for ( i = 0LL; i != 26; ++i )
{
v2 = labels[i];
if ( v2 )
{
output_buffer_offset = label_offsets[i] + 1;
result = output_be(v2);
current_addr -= 4;
}
}
if ( v0 > 0 )
{
for ( j = 0LL; j != v0; result = fputc(output_buffer[j++], stdout) )
;
}
output_buffer_offset = 0;
return result;
}

canonical_decompiled_code:
int func14()
{
int v0; // ebp
__int64 i; // rbx
int v2; // edi
int result; // eax
__int64 j; // rbx

v0 = output_buffer_offset;
for ( i = 0LL; i != 26; ++i )
{
v2 = labels[i];
if ( v2 )
{
output_buffer_offset = label_offsets[i] + 1;
result = func10(v2);
current_addr -= 4;
}
}
if ( v0 > 0 )
{
for ( j = 0LL; j != v0; result = fputc(output_buffer[j++], stdout) )
;
}
output_buffer_offset = 0;
return result;
}

original_code:
void sync_output(void)
{
 int i;
 int bufsize = output_buffer_offset;
 for(i = 0; i < 26; i++) {
  if(labels[i] != 0) {
   output_buffer_offset = label_offsets[i] + 1;
   output_be(labels[i]);
   current_addr -= 4;
  }
 }
 for(i = 0; i < bufsize; i++) {
  fprintf(stdout, "%c", output_buffer[i]);
 }
 output_buffer_offset = 0;
}

canonical_original_code:
void sync_output()
{
 int i;
 int bufsize = output_buffer_offset;
 for(i = 0; i < 26; i++) {
  if(labels[i] != 0) {
   output_buffer_offset = label_offsets[i] + 1;
   output_be(labels[i]);
   current_addr -= 4;
  }
 }
 for(i = 0; i < bufsize; i++) {
  fprintf(stdout, "%c", output_buffer[i]);
 }
 output_buffer_offset = 0;
}

variable_types: bufsize int


funend

decompiled_code:
__int64 __fastcall funend(char a1, int a2)
{
if ( a2 )
{
output(a1);
sync_output();
}
else
{
fwrite("?\n", 1uLL, 2uLL, stderr);
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func15(char a1, int a2)
{
if ( a2 )
{
func13(a1);
func14();
}
else
{
fwrite("?\n", 1uLL, 2uLL, stderr);
}
return 0LL;
}

original_code:
int funend(char opcode, int fundef)
{
 if(fundef) {
  fundef = 0;
  output(opcode);
  sync_output();
 }
 else {
  fprintf(stderr, "?\n");
 }
 return fundef;
}

variable_types: fundef int


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

result = 0LL;
memset(labels, 0, 0x68uLL);
memset(label_offsets, 0, 0x68uLL);
return result;
}

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

result = 0LL;
memset(labels, 0, 0x68uLL);
memset(label_offsets, 0, 0x68uLL);
return result;
}

original_code:
void reset_labels(void)
{
 memset(labels, 0x00, sizeof(labels));
 memset(label_offsets, 0x00, sizeof(label_offsets));
}

canonical_original_code:
void reset_labels()
{
 memset(labels, 0x00, sizeof(labels));
 memset(label_offsets, 0x00, sizeof(label_offsets));
}


decompiled_code:
__int64 __fastcall output_offset(char *s1, char *s, char a3)
{
int v4; // ebp
int v5; // edx
__int64 result; // rax
const char *v7; // rbx
__int64 v8; // rax
int v9; // [rsp+Ch] [rbp-4Ch] BYREF
char sa[72]; // [rsp+10h] [rbp-48h] BYREF

v4 = strlen(s);
snprintf(sa, 0x13uLL, "%s ", s);
sa[19] = 0;
v5 = strncmp(s1, sa, v4 + 1);
result = 0LL;
if ( !v5 )
{
v7 = &s1[v4 + 1];
v8 = getnum(v7, &v9);
if ( v9 )
{
output_num(a3, v8);
}
else if ( (unsigned __int8)(*v7 - 97) > 0x19u )
{
fwrite("?\n", 1uLL, 2uLL, stderr);
}
else
{
output_to_label(a3, *v7 - 97);
}
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func17(char *s1, char *s, char a3)
{
int v4; // ebp
int v5; // edx
__int64 result; // rax
const char *v7; // rbx
__int64 v8; // rax
int v9; // [rsp+Ch] [rbp-4Ch] BYREF
char sa[72]; // [rsp+10h] [rbp-48h] BYREF

v4 = strlen(s);
snprintf(sa, 0x13uLL, "%s ", s);
sa[19] = 0;
v5 = strncmp(s1, sa, v4 + 1);
result = 0LL;
if ( !v5 )
{
v7 = &s1[v4 + 1];
v8 = func1(v7, &v9);
if ( v9 )
{
func11(a3, v8);
}
else if ( (unsigned __int8)(*v7 - 97) > 0x19u )
{
fwrite("?\n", 1uLL, 2uLL, stderr);
}
else
{
func12(a3, *v7 - 97);
}
result = 1LL;
}
return result;
}

original_code:
int output_offset(const char *buf, const char *mnemonic,
  int opcode)
{
 char mn_buf[20];
 int mlen = strlen(mnemonic);
 snprintf(mn_buf, 19, "%s ", mnemonic);
 mn_buf[19] = '\0';
 if(!strncmp(buf, mn_buf, mlen + 1)) {
  int succ;
  long int parsed_num = getnum(buf + mlen + 1, &succ);
  if(!succ) {
   if(buf[mlen + 1] >= 'a' && buf[mlen + 1] <= 'z') {
    output_to_label(opcode, buf[mlen + 1] - 'a');
   }
   else {
    fprintf(stderr, "?\n");
   }
  }
  else {
   output_num(opcode, parsed_num);
  }
  return 1;
 }
 else
  return 0;
}

canonical_original_code:
int output_offset(char *buf, char *mnemonic, int opcode)
{
 char mn_buf[20];
 int mlen = strlen(mnemonic);
 snprintf(mn_buf, 19, "%s ", mnemonic);
 mn_buf[19] = '\0';
 if(!strncmp(buf, mn_buf, mlen + 1)) {
  int succ;
  long parsed_num = getnum(buf + mlen + 1, &succ);
  if(!succ) {
   if(buf[mlen + 1] >= 'a' && buf[mlen + 1] <= 'z') {
    output_to_label(opcode, buf[mlen + 1] - 'a');
   }
   else {
    fprintf(stderr, "?\n");
   }
  }
  else {
   output_num(opcode, parsed_num);
  }
  return 1;
 }
 else
  return 0;
}

variable_types:
buf
char *

variable_types:
mnemonic
char *

variable_types: opcode int

variable_types: mlen int

variable_types: succ int


decompiled_code:
__int64 __fastcall handle_ffidef(const char *a1)
{
int v1; // eax
int v2; // er13
char *v3; // rbp
__int64 v4; // rbx
int v5; // er12
__int64 v6; // rax
char *v7; // rdx
int v8; // er14
bool v9; // dl
__int64 v10; // rbx
char *endptr; // [rsp+8h] [rbp-40h] BYREF
__int64 v13[7]; // [rsp+10h] [rbp-38h]

v13[0] = 0LL;
v13[1] = 0LL;
v1 = strtol(a1, &endptr, 0);
if ( endptr == a1 )
return 0LL;
v2 = v1;
if ( !v1 )
return 0LL;
v3 = (char *)(a1 + 1);
v4 = 1LL;
do
{
v5 = v4 - 1;
v6 = strtol(v3, &endptr, 0);
v7 = endptr;
if ( endptr == v3 )
return 0LL;
*((_BYTE *)&endptr + v4 + 7) = v6;
v3 = v7 + 1;
v8 = v4;
if ( v4 == 15 )
break;
v9 = (_DWORD)v4++ == 0;
}
while ( v6 != 0 || v9 );
output_nums(84, v2, LOBYTE(v13[0]));
if ( v8 > 1 )
{
v10 = 1LL;
do
{
output_char(*((_BYTE *)v13 + v10));
if ( v5 <= (int)v10 )
output_char(0);
else
output_char(*((_BYTE *)v13 + v10 + 1));
if ( v8 <= (int)v10 + 2 )
output_char(0);
else
output_char(*((_BYTE *)v13 + v10 + 2));
if ( v8 <= (int)v10 + 3 )
output_char(0);
else
output_char(*((_BYTE *)v13 + v10 + 3));
v10 += 4LL;
}
while ( v8 > (int)v10 );
}
output_until_space(v3, 0);
sync_output();
reset_labels();
return 1LL;
}

original_code:
int handle_ffidef(const char *buf)
{
 int parsed_funnum;
 unsigned char types[16];
 int i = 0, j = 0;
 long int val;
 const char *numptr = buf;
 memset(types, 0x00, sizeof(types));
 char *endptr;
 parsed_funnum = strtol(numptr, &endptr, 0);
 if(endptr == numptr || !parsed_funnum)
  return 0;
 numptr++;
 do {
  val = strtol(numptr, &endptr, 0);
  if(endptr == numptr)
   return 0;
  types[i] = val;
  numptr = endptr + 1;
  i++;
 } while(i < sizeof(types) - 1 && (!i || val != 0));
 output_nums(0x54, parsed_funnum, types[0]);
 for(j = 1; j < i; j += 4) {
  output_char(types[j]);
  if(j + 1 < i)
   output_char(types[j + 1]);
  else
   output_char(0);
  if(j + 2 < i)
   output_char(types[j + 2]);
  else
   output_char(0);
  if(j + 3 < i)
   output_char(types[j + 3]);
  else
   output_char(0);
 }
 output_until_space(numptr, 0);
 sync_output();
 reset_labels();
 return 1;
}

canonical_original_code:
int handle_ffidef(char *buf)
{
 int parsed_funnum;
 unsigned char types[16];
 int i = 0; int j = 0;
 long val;
 char *numptr = buf;
 memset(types, 0x00, sizeof(types));
 char *endptr;
 parsed_funnum = strtol(numptr, &endptr, 0);
 if(endptr == numptr || !parsed_funnum)
  return 0;
 numptr++;
 do {
  val = strtol(numptr, &endptr, 0);
  if(endptr == numptr)
   return 0;
  types[i] = val;
  numptr = endptr + 1;
  i++;
 } while(i < sizeof(types) - 1 && (!i || val != 0));
 output_nums(0x54, parsed_funnum, types[0]);
 for(j = 1; j < i; j += 4) {
  output_char(types[j]);
  if(j + 1 < i)
   output_char(types[j + 1]);
  else
   output_char(0);
  if(j + 2 < i)
   output_char(types[j + 2]);
  else
   output_char(0);
  if(j + 3 < i)
   output_char(types[j + 3]);
  else
   output_char(0);
 }
 output_until_space(numptr, 0);
 sync_output();
 reset_labels();
 return 1;
}

variable_types:
types
unsigned char [16]

variable_types: j int

variable_types: val long

variable_types:
numptr
char *

variable_types:
endptr
char *


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v4; // rdi
__int64 v5; // rdx
__int64 v6; // rbx
int v7; // eax
int v8; // ebp
char *v9; // rax
__int64 v10; // rsi
__int64 v11; // rsi
__int64 v12; // rdx
__int64 v13; // rsi
char v14; // r12
__int64 v15; // rsi
__int64 v16; // rsi
int v18; // [rsp+8h] [rbp-420h] BYREF
unsigned int v19; // [rsp+Ch] [rbp-41Ch] BYREF
char s; // [rsp+10h] [rbp-418h] BYREF
char v21[4]; // [rsp+11h] [rbp-417h] BYREF
char v22[2]; // [rsp+15h] [rbp-413h] BYREF
char v23; // [rsp+17h] [rbp-411h] BYREF
char v24[1040]; // [rsp+18h] [rbp-410h] BYREF

if ( argc <= 1 )
{
interactive = 0;
reset_labels(argc, argv, envp);
output_magic();
output_version();
}
else
{
v4 = argv[1];
if ( !strncmp(v4, "-i", 2uLL) )
{
interactive = 1;
reset_labels(v4, "-i", v5);
goto LABEL_7;
}
interactive = 0;
reset_labels(v4, "-i", v5);
output_magic();
output_version();
v6 = 2LL;
do
{
output_until_space((char *)argv[v6 - 1], 1);
output_header(32);
v7 = v6++;
}
while ( v7 <= 15 && argc > v7 );
}
output_header(0);
LABEL_7:
v8 = 0;
while ( 1 )
{
if ( interactive )
{
printf(">>> ");
fflush(stdout);
}
v9 = fgets(&s, 1024, stdin);
if ( !interactive && !v9 )
return 0;
if ( s == 58 )
{
if ( (unsigned __int8)(v21[0] - 97) <= 0x19u )
labels[v21[0] - 97] = current_addr;
}
else if ( !memcmp(&s, "ADD", 3uLL) )
{
output(32);
}
else if ( !memcmp(&s, "SUB", 3uLL) )
{
output(33);
}
else if ( !memcmp(&s, "MUL", 3uLL) )
{
output(34);
}
else if ( !memcmp(&s, "DIV", 3uLL) )
{
output(35);
}
else if ( !memcmp(&s, "LT", 2uLL) )
{
output(36);
}
else if ( !memcmp(&s, "LE", 2uLL) )
{
output(37);
}
else if ( !memcmp(&s, "EQ", 2uLL) )
{
output(38);
}
else if ( !memcmp(&s, "DUP", 3uLL) )
{
output(64);
}
else if ( !strncmp(&s, "DROP", 4uLL) )
{
output(65);
}
else if ( !strncmp(&s, "NOP", 3uLL) )
{
output(66);
}
else if ( !strncmp(&s, "SWAP", 4uLL) )
{
output(67);
}
else if ( !strncmp(&s, "NEW", 3uLL) )
{
output(71);
}
else if ( !strncmp(&s, "RSTORE", 6uLL) )
{
output(72);
}
else if ( !strncmp(&s, "RLOAD", 4uLL) )
{
output(73);
}
else if ( !strncmp(&s, "END_THUNK", 9uLL) )
{
output(83);
}
else if ( !(unsigned int)output_offset(&s, "BR", 51)
&& !(unsigned int)output_offset(&s, "BRNZ", 52)
&& !(unsigned int)output_offset(&s, "THUNK", 82) )
{
if ( !strncmp(&s, "FUNCALL ", 8uLL) )
{
v10 = getnum(v24, (int *)&v19);
if ( !v19 )
goto LABEL_78;
output_num(50, v10);
}
else if ( !strncmp(&s, "FUNPCALL", 8uLL) )
{
output(80);
}
else if ( !strncmp(&s, "FUNDEF ", 7uLL) )
{
if ( v8 || (v8 = get_two_nums(&v23, &v18, &v19)) == 0 )
{
LABEL_78:
fwrite("?\n", 1uLL, 2uLL, stderr);
}
else
{
v11 = v19;
output_nums(48, v19, v18);
reset_labels(48LL, v11, v12);
v8 = 1;
}
}
else if ( !strncmp(&s, "FUNEND", 6uLL) )
{
v8 = funend(49, v8);
}
else if ( !strncmp(&s, "RET0", 4uLL) )
{
v8 = funend(69, v8);
}
else if ( !strncmp(&s, "RET1", 4uLL) )
{
v8 = funend(70, v8);
}
else if ( !strncmp(&s, "LOAD ", 5uLL) )
{
v13 = getnum(v22, (int *)&v19);
if ( !v19 )
goto LABEL_78;
output_num(68, v13);
}
else if ( !strncmp(&s, "FFIDEF ", 7uLL) )
{
if ( v8 )
goto LABEL_78;
if ( !(unsigned int)handle_ffidef(&v23) )
{
fwrite("FFIDEF?\n", 1uLL, 8uLL, stderr);
v8 = 0;
}
}
else
{
v14 = s;
if ( s == 102 )
{
v16 = getnum(v21, (int *)&v19);
if ( !v19 )
goto LABEL_78;
output_num(81, v16);
}
else if ( s == 45 || ((*_ctype_b_loc())[v14] & 0x800) != 0 )
{
v15 = getnum(&s, (int *)&v19);
if ( !v19 )
goto LABEL_78;
output_num(31, v15);
}
else if ( interactive && !strncmp(&s, "run", 3uLL) )
{
parse_buffer(interactive_buffer, (unsigned int)interactive_bufferpos);
}
else if ( v14 )
{
goto LABEL_78;
}
}
}
}
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v4; // rdi
__int64 v5; // rdx
__int64 v6; // rbx
int v7; // eax
int v8; // ebp
char *v9; // rax
__int64 v10; // rsi
__int64 v11; // rsi
__int64 v12; // rdx
__int64 v13; // rsi
char v14; // r12
__int64 v15; // rsi
__int64 v16; // rsi
int v18; // [rsp+8h] [rbp-420h] BYREF
unsigned int v19; // [rsp+Ch] [rbp-41Ch] BYREF
char s; // [rsp+10h] [rbp-418h] BYREF
char v21[4]; // [rsp+11h] [rbp-417h] BYREF
char v22[2]; // [rsp+15h] [rbp-413h] BYREF
char v23; // [rsp+17h] [rbp-411h] BYREF
char v24[1040]; // [rsp+18h] [rbp-410h] BYREF

if ( argc <= 1 )
{
interactive = 0;
func16(argc, argv, envp);
func8();
func7();
}
else
{
v4 = argv[1];
if ( !strncmp(v4, "-i", 2uLL) )
{
interactive = 1;
func16(v4, "-i", v5);
goto LABEL_7;
}
interactive = 0;
func16(v4, "-i", v5);
func8();
func7();
v6 = 2LL;
do
{
func6((char *)argv[v6 - 1], 1);
func5(32);
v7 = v6++;
}
while ( v7 <= 15 && argc > v7 );
}
func5(0);
LABEL_7:
v8 = 0;
while ( 1 )
{
if ( interactive )
{
printf(">>> ");
fflush(stdout);
}
v9 = fgets(&s, 1024, stdin);
if ( !interactive && !v9 )
return 0;
if ( s == 58 )
{
if ( (unsigned __int8)(v21[0] - 97) <= 0x19u )
labels[v21[0] - 97] = current_addr;
}
else if ( !memcmp(&s, "ADD", 3uLL) )
{
func13(32);
}
else if ( !memcmp(&s, "SUB", 3uLL) )
{
func13(33);
}
else if ( !memcmp(&s, "MUL", 3uLL) )
{
func13(34);
}
else if ( !memcmp(&s, "DIV", 3uLL) )
{
func13(35);
}
else if ( !memcmp(&s, "LT", 2uLL) )
{
func13(36);
}
else if ( !memcmp(&s, "LE", 2uLL) )
{
func13(37);
}
else if ( !memcmp(&s, "EQ", 2uLL) )
{
func13(38);
}
else if ( !memcmp(&s, "DUP", 3uLL) )
{
func13(64);
}
else if ( !strncmp(&s, "DROP", 4uLL) )
{
func13(65);
}
else if ( !strncmp(&s, "NOP", 3uLL) )
{
func13(66);
}
else if ( !strncmp(&s, "SWAP", 4uLL) )
{
func13(67);
}
else if ( !strncmp(&s, "NEW", 3uLL) )
{
func13(71);
}
else if ( !strncmp(&s, "RSTORE", 6uLL) )
{
func13(72);
}
else if ( !strncmp(&s, "RLOAD", 4uLL) )
{
func13(73);
}
else if ( !strncmp(&s, "END_THUNK", 9uLL) )
{
func13(83);
}
else if ( !(unsigned int)func17(&s, "BR", 51)
&& !(unsigned int)func17(&s, "BRNZ", 52)
&& !(unsigned int)func17(&s, "THUNK", 82) )
{
if ( !strncmp(&s, "FUNCALL ", 8uLL) )
{
v10 = func1(v24, (int *)&v19);
if ( !v19 )
goto LABEL_78;
func11(50, v10);
}
else if ( !strncmp(&s, "FUNPCALL", 8uLL) )
{
func13(80);
}
else if ( !strncmp(&s, "FUNDEF ", 7uLL) )
{
if ( v8 || (v8 = func0(&v23, &v18, &v19)) == 0 )
{
LABEL_78:
fwrite("?\n", 1uLL, 2uLL, stderr);
}
else
{
v11 = v19;
func9(48, v19, v18);
func16(48LL, v11, v12);
v8 = 1;
}
}
else if ( !strncmp(&s, "FUNEND", 6uLL) )
{
v8 = func15(49, v8);
}
else if ( !strncmp(&s, "RET0", 4uLL) )
{
v8 = func15(69, v8);
}
else if ( !strncmp(&s, "RET1", 4uLL) )
{
v8 = func15(70, v8);
}
else if ( !strncmp(&s, "LOAD ", 5uLL) )
{
v13 = func1(v22, (int *)&v19);
if ( !v19 )
goto LABEL_78;
func11(68, v13);
}
else if ( !strncmp(&s, "FFIDEF ", 7uLL) )
{
if ( v8 )
goto LABEL_78;
if ( !(unsigned int)func18(&v23) )
{
fwrite("FFIDEF?\n", 1uLL, 8uLL, stderr);
v8 = 0;
}
}
else
{
v14 = s;
if ( s == 102 )
{
v16 = func1(v21, (int *)&v19);
if ( !v19 )
goto LABEL_78;
func11(81, v16);
}
else if ( s == 45 || ((*_ctype_b_loc())[v14] & 0x800) != 0 )
{
v15 = func1(&s, (int *)&v19);
if ( !v19 )
goto LABEL_78;
func11(31, v15);
}
else if ( interactive && !strncmp(&s, "run", 3uLL) )
{
parse_buffer(interactive_buffer, (unsigned int)interactive_bufferpos);
}
else if ( v14 )
{
goto LABEL_78;
}
}
}
}
}

original_code:
int main(int argc, char **argv)
{
 char buf[1024];
 int fundef = 0;
 interactive = argc > 1 && !strncmp(argv[1], "-i", 2);
 reset_labels();
 if(!interactive) {
  int lib_index = 1;
  output_magic();
  output_version();
  for(lib_index = 1; lib_index < 16 && lib_index < argc;
    lib_index++) {
   output_until_space(argv[lib_index], 1);
   output_header(' ');
  }
  output_header('\0');
 }
 while(1) {
  int emptyline;
  if(interactive) {
   printf(">>> ");
   fflush(stdout);
  }
  emptyline = (fgets(buf, 1024, stdin) == ((void *)0));
  if(!interactive && emptyline)
   break;
  if(buf[0] == ':') {
   if(buf[1] >= 'a' && buf[1] <= 'z') {
    labels[buf[1] - 'a'] = current_addr;
   }
  }
  else if(!strncmp(buf, "ADD", 3)) {
   output(0x20);
  }
  else if(!strncmp(buf, "SUB", 3)) {
   output(0x21);
  }
  else if(!strncmp(buf, "MUL", 3)) {
   output(0x22);
  }
  else if(!strncmp(buf, "DIV", 3)) {
   output(0x23);
  }
  else if(!strncmp(buf, "LT", 2)) {
   output(0x24);
  }
  else if(!strncmp(buf, "LE", 2)) {
   output(0x25);
  }
  else if(!strncmp(buf, "EQ", 2)) {
   output(0x26);
  }
  else if(!strncmp(buf, "DUP", 3)) {
   output(0x40);
  }
  else if(!strncmp(buf, "DROP", 4)) {
   output(0x41);
  }
  else if(!strncmp(buf, "NOP", 3)) {
   output(0x42);
  }
  else if(!strncmp(buf, "SWAP", 4)) {
   output(0x43);
  }
  else if(!strncmp(buf, "NEW", 3)) {
   output(0x47);
  }
  else if(!strncmp(buf, "RSTORE", 6)) {
   output(0x48);
  }
  else if(!strncmp(buf, "RLOAD", 4)) {
   output(0x49);
  }
  else if(!strncmp(buf, "END_THUNK", 9)) {
   output(0x53);
  }
  else if(output_offset(buf, "BR", 0x33));
  else if(output_offset(buf, "BRNZ", 0x34));
  else if(output_offset(buf, "THUNK", 0x52));
  else if(!strncmp(buf, "FUNCALL ", 8)) {
   int succ;
   long int parsed_num = getnum(buf + 8, &succ);
   if(!succ)
    fprintf(stderr, "?\n");
   else {
    output_num(0x32, parsed_num);
   }
  }
  else if(!strncmp(buf, "FUNPCALL", 8)) {
   output(0x50);
  }
  else if(!strncmp(buf, "FUNDEF ", 7)) {
   if(fundef) {
    fprintf(stderr, "?\n");
   }
   else {
    int parsed_funnum, parsed_params;
    int succ = get_two_nums(buf + 7, &parsed_funnum, &parsed_params);
    if(!succ)
     fprintf(stderr, "?\n");
    else {
     output_nums(0x30, parsed_params, parsed_funnum);
     fundef = 1;
     reset_labels();
    }
   }
  }
  else if(!strncmp(buf, "FUNEND", 6)) {
   fundef = funend(0x31, fundef);
  }
  else if(!strncmp(buf, "RET0", 4)) {
   fundef = funend(0x45, fundef);
  }
  else if(!strncmp(buf, "RET1", 4)) {
   fundef = funend(0x46, fundef);
  }
  else if(!strncmp(buf, "LOAD ", 5)) {
   int succ;
   long int parsed_num = getnum(buf + 5, &succ);
   if(!succ)
    fprintf(stderr, "?\n");
   else
    output_num(0x44, parsed_num);
  }
  else if(!strncmp(buf, "FFIDEF ", 7)) {
   if(fundef) {
    fprintf(stderr, "?\n");
   }
   else {
    int succ = handle_ffidef(buf + 7);
    if(!succ) {
     fprintf(stderr, "FFIDEF?\n");
    }
   }
  }
  else if(buf[0] == 'f') {
   int succ;
   long int parsed_num = getnum(buf + 1, &succ);
   if(!succ)
    fprintf(stderr, "?\n");
   else
    output_num(0x51, parsed_num);
  }
  else if(buf[0] == '-' || ((*__ctype_b_loc ())[(int) ((buf[0]))] & (unsigned short int) _ISdigit)) {
   int succ;
   long int parsed_num = getnum(buf, &succ);
   if(!succ)
    fprintf(stderr, "?\n");
   else
    output_num(0x1f, parsed_num);
  }
  else if(interactive && !strncmp(buf, "run", 3)) {
   parse_buffer(interactive_buffer,
     interactive_bufferpos);
  }
  else if(buf[0]) {
   fprintf(stderr, "?\n");
  }
 }
 return 0;
}

canonical_original_code:
int main(int argc, char **argv)
{
 char buf[1024];
 int fundef = 0;
 interactive = argc > 1 && !strncmp(argv[1], "-i", 2);
 reset_labels();
 if(!interactive) {
  int lib_index = 1;
  output_magic();
  output_version();
  for(lib_index = 1; lib_index < 16 && lib_index < argc;
    lib_index++) {
   output_until_space(argv[lib_index], 1);
   output_header(' ');
  }
  output_header('\0');
 }
 while(1) {
  int emptyline;
  if(interactive) {
   printf(">>> ");
   fflush(stdout);
  }
  emptyline = (fgets(buf, 1024, stdin) == ((void *)0));
  if(!interactive && emptyline)
   break;
  if(buf[0] == ':') {
   if(buf[1] >= 'a' && buf[1] <= 'z') {
    labels[buf[1] - 'a'] = current_addr;
   }
  }
  else if(!strncmp(buf, "ADD", 3)) {
   output(0x20);
  }
  else if(!strncmp(buf, "SUB", 3)) {
   output(0x21);
  }
  else if(!strncmp(buf, "MUL", 3)) {
   output(0x22);
  }
  else if(!strncmp(buf, "DIV", 3)) {
   output(0x23);
  }
  else if(!strncmp(buf, "LT", 2)) {
   output(0x24);
  }
  else if(!strncmp(buf, "LE", 2)) {
   output(0x25);
  }
  else if(!strncmp(buf, "EQ", 2)) {
   output(0x26);
  }
  else if(!strncmp(buf, "DUP", 3)) {
   output(0x40);
  }
  else if(!strncmp(buf, "DROP", 4)) {
   output(0x41);
  }
  else if(!strncmp(buf, "NOP", 3)) {
   output(0x42);
  }
  else if(!strncmp(buf, "SWAP", 4)) {
   output(0x43);
  }
  else if(!strncmp(buf, "NEW", 3)) {
   output(0x47);
  }
  else if(!strncmp(buf, "RSTORE", 6)) {
   output(0x48);
  }
  else if(!strncmp(buf, "RLOAD", 4)) {
   output(0x49);
  }
  else if(!strncmp(buf, "END_THUNK", 9)) {
   output(0x53);
  }
  else if(output_offset(buf, "BR", 0x33));
  else if(output_offset(buf, "BRNZ", 0x34));
  else if(output_offset(buf, "THUNK", 0x52));
  else if(!strncmp(buf, "FUNCALL ", 8)) {
   int succ;
   long parsed_num = getnum(buf + 8, &succ);
   if(!succ)
    fprintf(stderr, "?\n");
   else {
    output_num(0x32, parsed_num);
   }
  }
  else if(!strncmp(buf, "FUNPCALL", 8)) {
   output(0x50);
  }
  else if(!strncmp(buf, "FUNDEF ", 7)) {
   if(fundef) {
    fprintf(stderr, "?\n");
   }
   else {
    int parsed_funnum; int parsed_params;
    int succ = get_two_nums(buf + 7, &parsed_funnum, &parsed_params);
    if(!succ)
     fprintf(stderr, "?\n");
    else {
     output_nums(0x30, parsed_params, parsed_funnum);
     fundef = 1;
     reset_labels();
    }
   }
  }
  else if(!strncmp(buf, "FUNEND", 6)) {
   fundef = funend(0x31, fundef);
  }
  else if(!strncmp(buf, "RET0", 4)) {
   fundef = funend(0x45, fundef);
  }
  else if(!strncmp(buf, "RET1", 4)) {
   fundef = funend(0x46, fundef);
  }
  else if(!strncmp(buf, "LOAD ", 5)) {
   int succ;
   long parsed_num = getnum(buf + 5, &succ);
   if(!succ)
    fprintf(stderr, "?\n");
   else
    output_num(0x44, parsed_num);
  }
  else if(!strncmp(buf, "FFIDEF ", 7)) {
   if(fundef) {
    fprintf(stderr, "?\n");
   }
   else {
    int succ = handle_ffidef(buf + 7);
    if(!succ) {
     fprintf(stderr, "FFIDEF?\n");
    }
   }
  }
  else if(buf[0] == 'f') {
   int succ;
   long parsed_num = getnum(buf + 1, &succ);
   if(!succ)
    fprintf(stderr, "?\n");
   else
    output_num(0x51, parsed_num);
  }
  else if(buf[0] == '-' || ((*__ctype_b_loc ())[(int) ((buf[0]))] & (unsigned short) _ISdigit)) {
   int succ;
   long parsed_num = getnum(buf, &succ);
   if(!succ)
    fprintf(stderr, "?\n");
   else
    output_num(0x1f, parsed_num);
  }
  else if(interactive && !strncmp(buf, "run", 3)) {
   parse_buffer(interactive_buffer,
     interactive_bufferpos);
  }
  else if(buf[0]) {
   fprintf(stderr, "?\n");
  }
 }
 return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types:
buf
char [1024]

variable_types: emptyline int


usage

decompiled_code:
size_t __fastcall usage(const char *a1)
{
fprintf(stderr, "Usage: %s <filename>\n", a1);
return fwrite("\tsimple stack machine\n", 1uLL, 0x16uLL, stderr);
}

canonical_decompiled_code:
size_t __fastcall func0(const char *a1)
{
fprintf(stderr, "Usage: %s <filename>\n", a1);
return fwrite("\tsimple stack machine\n", 1uLL, 0x16uLL, stderr);
}

original_code:
void usage(const char *pn)
{
 fprintf(stderr, "Usage: %s <filename>\n",
   pn);
 fprintf(stderr, "\tsimple stack machine\n");
}

canonical_original_code:
void usage(char *pn)
{
 fprintf(stderr, "Usage: %s <filename>\n",
   pn);
 fprintf(stderr, "\tsimple stack machine\n");
}

variable_types:
pn
char *


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
if ( argc == 2 )
return parse_file(argv[1]);
usage(*argv);
return 1;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
if ( argc == 2 )
return parse_file(argv[1]);
func0(*argv);
return 1;
}

original_code:
int main(int argc, char **argv)
{
 if(argc != 2) {
  usage(argv[0]);
  return 1;
 }
 return parse_file(argv[1]);
}


repo: anyc/pmtools

decompiled_code:
int __fastcall acpi_table_print(__int64 a1, const void *a2)
{
int result; // eax

if ( a1 )
result = printf(
"ACPI: %.4s (v%3.3d %6.6s %8.8s 0x%08x %.4s 0x%08x) @ 0x%p\n",
(const char *)a1,
*(unsigned __int8 *)(a1 + 8),
(const char *)(a1 + 10),
(const char *)(a1 + 16),
*(unsigned int *)(a1 + 24),
(const char *)(a1 + 28),
*(unsigned int *)(a1 + 32),
a2);
return result;
}

canonical_decompiled_code:
int __fastcall func8(__int64 a1, const void *a2)
{
int result; // eax

if ( a1 )
result = printf(
"ACPI: %.4s (v%3.3d %6.6s %8.8s 0x%08x %.4s 0x%08x) @ 0x%p\n",
(const char *)a1,
*(unsigned __int8 *)(a1 + 8),
(const char *)(a1 + 10),
(const char *)(a1 + 16),
*(unsigned int *)(a1 + 24),
(const char *)(a1 + 28),
*(unsigned int *)(a1 + 32),
a2);
return result;
}

original_code:
void
acpi_table_print (
 struct acpi_table_header *header,
 unsigned long phys_addr)
{
 char *name = ((void *)0);
 if (!header)
  return;
  name = header->signature;
 printf("" "ACPI: " "%.4s (v%3.3d %6.6s %8.8s 0x%08x %.4s 0x%08x) @ 0x%p\n",
  name, header->revision, header->oem_id,
  header->oem_table_id, header->oem_revision,
  header->asl_compiler_id, header->asl_compiler_revision,
  (void *) phys_addr);
}

canonical_original_code:
void acpi_table_print(struct acpi_table_header *header, unsigned long phys_addr)
{
 char *name = ((void *)0);
 if (!header)
  return;
  name = header->signature;
 printf("" "ACPI: " "%.4s (v%3.3d %6.6s %8.8s 0x%08x %.4s 0x%08x) @ 0x%p\n",
  name, header->revision, header->oem_id,
  header->oem_table_id, header->oem_revision,
  header->asl_compiler_id, header->asl_compiler_revision,
  (void *) phys_addr);
}

variable_types: struct acpi_table_header { char signature[4]; unsigned int length; unsigned char revision; unsigned char checksum; char oem_id[6]; char oem_table_id[8]; unsigned int oem_revision; char asl_compiler_id[4]; unsigned int asl_compiler_revision; } *

variable_types:
name
char *


repo: aodinokov/expos

decompiled_code:
__int64 __fastcall elf_hash(unsigned __int8 *a1)
{
unsigned __int8 v1; // dl
unsigned __int8 *v2; // rdi
__int64 result; // rax
unsigned __int8 v4; // dl

v1 = *a1;
v2 = a1 + 1;
result = v1;
if ( !v1 )
return 0LL;
while ( 1 )
{
v4 = *v2;
if ( !*v2 )
break;
++v2;
result = v4 + 16 * result;
if ( (result & 0xF0000000) != 0 )
result ^= (unsigned int)result & 0xF0000000 | ((unsigned __int64)((unsigned int)result & 0xF0000000) >> 24);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned __int8 *a1)
{
unsigned __int8 v1; // dl
unsigned __int8 *v2; // rdi
__int64 result; // rax
unsigned __int8 v4; // dl

v1 = *a1;
v2 = a1 + 1;
result = v1;
if ( !v1 )
return 0LL;
while ( 1 )
{
v4 = *v2;
if ( !*v2 )
break;
++v2;
result = v4 + 16 * result;
if ( (result & 0xF0000000) != 0 )
result ^= (unsigned int)result & 0xF0000000 | ((unsigned __int64)((unsigned int)result & 0xF0000000) >> 24);
}
return result;
}

original_code:
unsigned long
elf_hash(const unsigned char *name) {
    unsigned long hash = 0;
    unsigned long tmp;
    while (*name) {
 hash = (hash << 4) + (unsigned char)*name++;
 if ((tmp = hash & 0xf0000000)) {
     hash ^= tmp | (tmp >> 24);
 }
    }
    return hash;
}

canonical_original_code:
unsigned long elf_hash(unsigned char *name) {
    unsigned long hash = 0;
    unsigned long tmp;
    while (*name) {
 hash = (hash << 4) + (unsigned char)*name++;
 if ((tmp = hash & 0xf0000000)) {
     hash ^= tmp | (tmp >> 24);
 }
    }
    return hash;
}

variable_types:
name
unsigned char *

variable_types:
hash
unsigned long

variable_types:
tmp
unsigned long

return_type: unsigned long


original_code:
int
gelf_update_shdr(Elf_Scn *scn, GElf_Shdr *src) {
    if (!scn || !src) {
 return 0;
    }
    do{}while(0);
    do{}while(0);
    do{}while(0);
    if (scn->s_elf->e_class == 2) {
 scn->s_uhdr.u_shdr64 = *src;
    }
    else if (scn->s_elf->e_class == 1) {
 Elf32_Shdr *dst = &scn->s_uhdr.u_shdr32;
 do { if (sizeof((dst)->sh_name) < sizeof((src)->sh_name) && (Elf32_Word)(src)->sh_name != (src)->sh_name) { (_elf_errno = (ERROR_BADVALUE)); return (0); } (dst)->sh_name = (Elf32_Word)(src)->sh_name; } while (0);
 do { if (sizeof((dst)->sh_type) < sizeof((src)->sh_type) && (Elf32_Word)(src)->sh_type != (src)->sh_type) { (_elf_errno = (ERROR_BADVALUE)); return (0); } (dst)->sh_type = (Elf32_Word)(src)->sh_type; } while (0);
 do { if (sizeof((dst)->sh_flags) < sizeof((src)->sh_flags) && (Elf32_Word)(src)->sh_flags != (src)->sh_flags) { (_elf_errno = (ERROR_BADVALUE)); return (0); } (dst)->sh_flags = (Elf32_Word)(src)->sh_flags; } while (0);
 do { if (sizeof((dst)->sh_addr) < sizeof((src)->sh_addr) && (Elf32_Addr)(src)->sh_addr != (src)->sh_addr) { (_elf_errno = (ERROR_BADVALUE)); return (0); } (dst)->sh_addr = (Elf32_Addr)(src)->sh_addr; } while (0);
 do { if (sizeof((dst)->sh_offset) < sizeof((src)->sh_offset) && (Elf32_Off)(src)->sh_offset != (src)->sh_offset) { (_elf_errno = (ERROR_BADVALUE)); return (0); } (dst)->sh_offset = (Elf32_Off)(src)->sh_offset; } while (0);
 do { if (sizeof((dst)->sh_size) < sizeof((src)->sh_size) && (Elf32_Word)(src)->sh_size != (src)->sh_size) { (_elf_errno = (ERROR_BADVALUE)); return (0); } (dst)->sh_size = (Elf32_Word)(src)->sh_size; } while (0);
 do { if (sizeof((dst)->sh_link) < sizeof((src)->sh_link) && (Elf32_Word)(src)->sh_link != (src)->sh_link) { (_elf_errno = (ERROR_BADVALUE)); return (0); } (dst)->sh_link = (Elf32_Word)(src)->sh_link; } while (0);
 do { if (sizeof((dst)->sh_info) < sizeof((src)->sh_info) && (Elf32_Word)(src)->sh_info != (src)->sh_info) { (_elf_errno = (ERROR_BADVALUE)); return (0); } (dst)->sh_info = (Elf32_Word)(src)->sh_info; } while (0);
 do { if (sizeof((dst)->sh_addralign) < sizeof((src)->sh_addralign) && (Elf32_Word)(src)->sh_addralign != (src)->sh_addralign) { (_elf_errno = (ERROR_BADVALUE)); return (0); } (dst)->sh_addralign = (Elf32_Word)(src)->sh_addralign; } while (0);
 do { if (sizeof((dst)->sh_entsize) < sizeof((src)->sh_entsize) && (Elf32_Word)(src)->sh_entsize != (src)->sh_entsize) { (_elf_errno = (ERROR_BADVALUE)); return (0); } (dst)->sh_entsize = (Elf32_Word)(src)->sh_entsize; } while (0);
    }
    else {
 if (((scn->s_elf->e_class) >= 1 && (scn->s_elf->e_class) <= 2)) {
     (_elf_errno = (ERROR_UNIMPLEMENTED));
 }
 else {
     (_elf_errno = (ERROR_UNKNOWN_CLASS));
 }
 return 0;
    }
    return 1;
}

canonical_original_code:
int gelf_update_shdr(struct Elf_Scn *scn, struct Elf64_Shdr *src) {
    if (!scn || !src) {
 return 0;
    }
    do{}while(0);
    do{}while(0);
    do{}while(0);
    if (scn->s_elf->e_class == 2) {
 scn->s_uhdr.u_shdr64 = *src;
    }
    else if (scn->s_elf->e_class == 1) {
 struct Elf32_Shdr *dst = &scn->s_uhdr.u_shdr32;
 do { if (sizeof((dst)->sh_name) < sizeof((src)->sh_name) && (Elf32_Word)(src)->sh_name != (src)->sh_name) { (_elf_errno = (ERROR_BADVALUE)); return (0); } (dst)->sh_name = (Elf32_Word)(src)->sh_name; } while (0);
 do { if (sizeof((dst)->sh_type) < sizeof((src)->sh_type) && (Elf32_Word)(src)->sh_type != (src)->sh_type) { (_elf_errno = (ERROR_BADVALUE)); return (0); } (dst)->sh_type = (Elf32_Word)(src)->sh_type; } while (0);
 do { if (sizeof((dst)->sh_flags) < sizeof((src)->sh_flags) && (Elf32_Word)(src)->sh_flags != (src)->sh_flags) { (_elf_errno = (ERROR_BADVALUE)); return (0); } (dst)->sh_flags = (Elf32_Word)(src)->sh_flags; } while (0);
 do { if (sizeof((dst)->sh_addr) < sizeof((src)->sh_addr) && (Elf32_Addr)(src)->sh_addr != (src)->sh_addr) { (_elf_errno = (ERROR_BADVALUE)); return (0); } (dst)->sh_addr = (Elf32_Addr)(src)->sh_addr; } while (0);
 do { if (sizeof((dst)->sh_offset) < sizeof((src)->sh_offset) && (Elf32_Off)(src)->sh_offset != (src)->sh_offset) { (_elf_errno = (ERROR_BADVALUE)); return (0); } (dst)->sh_offset = (Elf32_Off)(src)->sh_offset; } while (0);
 do { if (sizeof((dst)->sh_size) < sizeof((src)->sh_size) && (Elf32_Word)(src)->sh_size != (src)->sh_size) { (_elf_errno = (ERROR_BADVALUE)); return (0); } (dst)->sh_size = (Elf32_Word)(src)->sh_size; } while (0);
 do { if (sizeof((dst)->sh_link) < sizeof((src)->sh_link) && (Elf32_Word)(src)->sh_link != (src)->sh_link) { (_elf_errno = (ERROR_BADVALUE)); return (0); } (dst)->sh_link = (Elf32_Word)(src)->sh_link; } while (0);
 do { if (sizeof((dst)->sh_info) < sizeof((src)->sh_info) && (Elf32_Word)(src)->sh_info != (src)->sh_info) { (_elf_errno = (ERROR_BADVALUE)); return (0); } (dst)->sh_info = (Elf32_Word)(src)->sh_info; } while (0);
 do { if (sizeof((dst)->sh_addralign) < sizeof((src)->sh_addralign) && (Elf32_Word)(src)->sh_addralign != (src)->sh_addralign) { (_elf_errno = (ERROR_BADVALUE)); return (0); } (dst)->sh_addralign = (Elf32_Word)(src)->sh_addralign; } while (0);
 do { if (sizeof((dst)->sh_entsize) < sizeof((src)->sh_entsize) && (Elf32_Word)(src)->sh_entsize != (src)->sh_entsize) { (_elf_errno = (ERROR_BADVALUE)); return (0); } (dst)->sh_entsize = (Elf32_Word)(src)->sh_entsize; } while (0);
    }
    else {
 if (((scn->s_elf->e_class) >= 1 && (scn->s_elf->e_class) <= 2)) {
     (_elf_errno = (ERROR_UNIMPLEMENTED));
 }
 else {
     (_elf_errno = (ERROR_UNKNOWN_CLASS));
 }
 return 0;
    }
    return 1;
}

variable_types: struct Elf_Scn { struct Elf_Scn *s_link; struct Elf { unsigned long e_size; unsigned long e_dsize; enum Elf_Kind { ELF_K_NONE=0, ELF_K_AR=1, ELF_K_COFF=2, ELF_K_ELF=3, ELF_K_NUM=4 } e_kind; char *e_data; char *e_rawdata; unsigned long e_idlen; int e_fd; unsigned int e_count; struct Elf *e_parent; unsigned long e_next; unsigned long e_base; struct Elf *e_link; struct Elf_Arhdr { char *ar_name; long ar_date; long ar_uid; long ar_gid; unsigned long ar_mode; long ar_size; char *ar_rawname; } *e_arhdr; unsigned long e_off; struct Elf *e_members; char *e_symtab; unsigned long e_symlen; char *e_strtab; unsigned long e_strlen; unsigned int e_class; unsigned int e_encoding; unsigned int e_version; char *e_ehdr; char *e_phdr; unsigned long e_phnum; struct Elf_Scn *e_scn_1; struct Elf_Scn *e_scn_n; unsigned int e_elf_flags; unsigned int e_ehdr_flags; unsigned int e_phdr_flags; unsigned int e_readable; unsigned int e_writable; unsigned int e_disabled; unsigned int e_cooked; unsigned int e_free_syms; unsigned int e_unmap_data; unsigned int e_memory; long e_magic; } *s_elf; unsigned long s_index; unsigned int s_scn_flags; unsigned int s_shdr_flags; struct Scn_Data { struct Elf_Data { void *d_buf; enum Elf_Type { ELF_T_BYTE=0, ELF_T_ADDR=1, ELF_T_DYN=2, ELF_T_EHDR=3, ELF_T_HALF=4, ELF_T_OFF=5, ELF_T_PHDR=6, ELF_T_RELA=7, ELF_T_REL=8, ELF_T_SHDR=9, ELF_T_SWORD=10, ELF_T_SYM=11, ELF_T_WORD=12, ELF_T_SXWORD=13, ELF_T_XWORD=14, ELF_T_VDEF=15, ELF_T_VNEED=16, ELF_T_NUM=17 } d_type; unsigned long d_size; long d_off; unsigned long d_align; unsigned int d_version; } sd_data; struct Scn_Data *sd_link; struct Elf_Scn *sd_scn; char *sd_memdata; unsigned int sd_data_flags; unsigned int sd_freeme; unsigned int sd_free_data; long sd_magic; } *s_data_1; struct Scn_Data *s_data_n; struct Scn_Data *s_rawdata; unsigned int s_type; unsigned long s_offset; unsigned long s_size; unsigned int s_freeme; union { struct Elf64_Shdr { unsigned int sh_name; unsigned int sh_type; unsigned long sh_flags; unsigned long sh_addr; unsigned long sh_offset; unsigned long sh_size; unsigned int sh_link; unsigned int sh_info; unsigned long sh_addralign; unsigned long sh_entsize; } u_shdr64; struct Elf32_Shdr { unsigned int sh_name; unsigned int sh_type; unsigned int sh_flags; unsigned int sh_addr; unsigned int sh_offset; unsigned int sh_size; unsigned int sh_link; unsigned int sh_info; unsigned int sh_addralign; unsigned int sh_entsize; } u_shdr32; } s_uhdr; long s_magic; } *

variable_types:
src
struct Elf64_Shdr *

variable_types: struct Elf32_Shdr { unsigned int sh_name; unsigned int sh_type; unsigned int sh_flags; unsigned int sh_addr; unsigned int sh_offset; unsigned int sh_size; unsigned int sh_link; unsigned int sh_info; unsigned int sh_addralign; unsigned int sh_entsize; } *

user_defined_types: struct Elf_Scn { struct Elf_Scn *s_link; struct Elf *s_elf; unsigned long s_index; unsigned int s_scn_flags; unsigned int s_shdr_flags; struct Scn_Data *s_data_1; struct Scn_Data *s_data_n; struct Scn_Data *s_rawdata; unsigned int s_type; unsigned long s_offset; unsigned long s_size; unsigned int s_freeme; union { struct Elf64_Shdr u_shdr64; struct Elf32_Shdr u_shdr32; } s_uhdr; long s_magic; }

user_defined_types: struct Elf { unsigned long e_size; unsigned long e_dsize; enum Elf_Kind e_kind; char *e_data; char *e_rawdata; unsigned long e_idlen; int e_fd; unsigned int e_count; struct Elf *e_parent; unsigned long e_next; unsigned long e_base; struct Elf *e_link; struct Elf_Arhdr *e_arhdr; unsigned long e_off; struct Elf *e_members; char *e_symtab; unsigned long e_symlen; char *e_strtab; unsigned long e_strlen; unsigned int e_class; unsigned int e_encoding; unsigned int e_version; char *e_ehdr; char *e_phdr; unsigned long e_phnum; struct Elf_Scn *e_scn_1; struct Elf_Scn *e_scn_n; unsigned int e_elf_flags; unsigned int e_ehdr_flags; unsigned int e_phdr_flags; unsigned int e_readable; unsigned int e_writable; unsigned int e_disabled; unsigned int e_cooked; unsigned int e_free_syms; unsigned int e_unmap_data; unsigned int e_memory; long e_magic; }

user_defined_types: struct Scn_Data { struct Elf_Data sd_data; struct Scn_Data *sd_link; struct Elf_Scn *sd_scn; char *sd_memdata; unsigned int sd_data_flags; unsigned int sd_freeme; unsigned int sd_free_data; long sd_magic; }

user_defined_types: struct Elf_Data { void *d_buf; enum Elf_Type d_type; unsigned long d_size; long d_off; unsigned long d_align; unsigned int d_version; }


parse

decompiled_code:
__int64 __fastcall parse(int argc, char **argv)
{
int v2; // eax
__int64 result; // rax
int v4; // eax
struct option v5; // [rsp+0h] [rbp-108h] BYREF
const char *v6; // [rsp+20h] [rbp-E8h]
int v7; // [rsp+28h] [rbp-E0h]
__int64 v8; // [rsp+30h] [rbp-D8h]
int v9; // [rsp+38h] [rbp-D0h]
const char *v10; // [rsp+40h] [rbp-C8h]
int v11; // [rsp+48h] [rbp-C0h]
__int64 v12; // [rsp+50h] [rbp-B8h]
int v13; // [rsp+58h] [rbp-B0h]
const char *v14; // [rsp+60h] [rbp-A8h]
int v15; // [rsp+68h] [rbp-A0h]
__int64 v16; // [rsp+70h] [rbp-98h]
int v17; // [rsp+78h] [rbp-90h]
const char *v18; // [rsp+80h] [rbp-88h]
int v19; // [rsp+88h] [rbp-80h]
__int64 v20; // [rsp+90h] [rbp-78h]
int v21; // [rsp+98h] [rbp-70h]
const char *v22; // [rsp+A0h] [rbp-68h]
int v23; // [rsp+A8h] [rbp-60h]
__int64 v24; // [rsp+B0h] [rbp-58h]
int v25; // [rsp+B8h] [rbp-50h]
__int64 v26; // [rsp+C0h] [rbp-48h]
int v27; // [rsp+C8h] [rbp-40h]
__int64 v28; // [rsp+D0h] [rbp-38h]
int v29; // [rsp+D8h] [rbp-30h]
int longind[7]; // [rsp+ECh] [rbp-1Ch] BYREF

v5.name = "help";
v5.has_arg = 0;
v5.flag = 0LL;
v5.val = 104;
v6 = "list";
v7 = 0;
v8 = 0LL;
v9 = 108;
v10 = "pid";
v11 = 1;
v12 = 0LL;
v13 = 112;
v14 = "module";
v15 = 1;
v16 = 0LL;
v17 = 100;
v18 = "group";
v19 = 1;
v20 = 0LL;
v21 = 103;
v22 = "mask";
v23 = 1;
v24 = 0LL;
v25 = 109;
v26 = 0LL;
v27 = 0;
v28 = 0LL;
v29 = 0;
while ( 2 )
{
v2 = getopt_long(argc, argv, "hlp:d:g:m:", &v5, longind);
if ( v2 == -1 )
{
result = 0LL;
if ( optind < argc )
{
printf("Unknown parameter: ");
while ( 1 )
{
v4 = optind;
if ( optind >= argc )
break;
++optind;
printf("%s ", argv[v4]);
}
putchar(10);
result = 1LL;
}
}
else
{
switch ( v2 )
{
case 'd':
module = optarg;
continue;
case 'g':
group = optarg;
continue;
case 'l':
list = 1;
continue;
case 'm':
mask = (__int64)optarg;
continue;
case 'p':
pid = optarg;
continue;
default:
show_help((__int64)*argv);
result = 0xFFFFFFFFLL;
break;
}
}
break;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func10(int argc, char **argv)
{
int v2; // eax
__int64 result; // rax
int v4; // eax
struct option v5; // [rsp+0h] [rbp-108h] BYREF
const char *v6; // [rsp+20h] [rbp-E8h]
int v7; // [rsp+28h] [rbp-E0h]
__int64 v8; // [rsp+30h] [rbp-D8h]
int v9; // [rsp+38h] [rbp-D0h]
const char *v10; // [rsp+40h] [rbp-C8h]
int v11; // [rsp+48h] [rbp-C0h]
__int64 v12; // [rsp+50h] [rbp-B8h]
int v13; // [rsp+58h] [rbp-B0h]
const char *v14; // [rsp+60h] [rbp-A8h]
int v15; // [rsp+68h] [rbp-A0h]
__int64 v16; // [rsp+70h] [rbp-98h]
int v17; // [rsp+78h] [rbp-90h]
const char *v18; // [rsp+80h] [rbp-88h]
int v19; // [rsp+88h] [rbp-80h]
__int64 v20; // [rsp+90h] [rbp-78h]
int v21; // [rsp+98h] [rbp-70h]
const char *v22; // [rsp+A0h] [rbp-68h]
int v23; // [rsp+A8h] [rbp-60h]
__int64 v24; // [rsp+B0h] [rbp-58h]
int v25; // [rsp+B8h] [rbp-50h]
__int64 v26; // [rsp+C0h] [rbp-48h]
int v27; // [rsp+C8h] [rbp-40h]
__int64 v28; // [rsp+D0h] [rbp-38h]
int v29; // [rsp+D8h] [rbp-30h]
int longind[7]; // [rsp+ECh] [rbp-1Ch] BYREF

v5.name = "help";
v5.has_arg = 0;
v5.flag = 0LL;
v5.val = 104;
v6 = "list";
v7 = 0;
v8 = 0LL;
v9 = 108;
v10 = "pid";
v11 = 1;
v12 = 0LL;
v13 = 112;
v14 = "module";
v15 = 1;
v16 = 0LL;
v17 = 100;
v18 = "group";
v19 = 1;
v20 = 0LL;
v21 = 103;
v22 = "mask";
v23 = 1;
v24 = 0LL;
v25 = 109;
v26 = 0LL;
v27 = 0;
v28 = 0LL;
v29 = 0;
while ( 2 )
{
v2 = getopt_long(argc, argv, "hlp:d:g:m:", &v5, longind);
if ( v2 == -1 )
{
result = 0LL;
if ( optind < argc )
{
printf("Unknown parameter: ");
while ( 1 )
{
v4 = optind;
if ( optind >= argc )
break;
++optind;
printf("%s ", argv[v4]);
}
putchar(10);
result = 1LL;
}
}
else
{
switch ( v2 )
{
case 'd':
module = optarg;
continue;
case 'g':
group = optarg;
continue;
case 'l':
list = 1;
continue;
case 'm':
mask = (__int64)optarg;
continue;
case 'p':
pid = optarg;
continue;
default:
func9((__int64)*argv);
result = 0xFFFFFFFFLL;
break;
}
}
break;
}
return result;
}

original_code:
static int parse(int argc, char **argv) {
 int rez;
 int option_index;
 const char* short_options = "hlp:d:g:m:";
 const struct option long_options[] =
 {
  {"help",0,((void *)0),'h'},
  {"list",0,((void *)0),'l'},
  {"pid",1,((void *)0),'p'},
  {"module",1,((void *)0),'d'},
  {"group",1,((void *)0),'g'},
  {"mask",1,((void *)0),'m'},
  {((void *)0),0,((void *)0),0}
 };
 while ((rez=getopt_long(argc, argv, short_options,
   long_options,&option_index))!=-1){
  switch(rez){
   case 'l':{
    list = 1;
    break;
   }
   case 'p': pid = optarg; break;
   case 'd': module = optarg; break;
   case 'g': group = optarg; break;
   case 'm': mask = optarg; break;
   case 'h':
   default:
    _show_help(argv[0]);
    return -1;
  }
 }
 if (optind < argc) {
  printf("Unknown parameter: ");
  while (optind < argc)
   printf ("%s ", argv[optind++]);
  printf ("\n");
  return 1;
 }
 return 0;
}

canonical_original_code:
static int parse(int argc, char **argv) {
 int rez;
 int option_index;
 char *short_options = "hlp:d:g:m:";
 struct option long_options[] = {
  {"help",0,((void *)0),'h'},
  {"list",0,((void *)0),'l'},
  {"pid",1,((void *)0),'p'},
  {"module",1,((void *)0),'d'},
  {"group",1,((void *)0),'g'},
  {"mask",1,((void *)0),'m'},
  {((void *)0),0,((void *)0),0}
 };
 while ((rez=getopt_long(argc, argv, short_options,
   long_options,&option_index))!=-1){
  switch(rez){
   case 'l':{
    list = 1;
    break;
   }
   case 'p': pid = optarg; break;
   case 'd': module = optarg; break;
   case 'g': group = optarg; break;
   case 'm': mask = optarg; break;
   case 'h':
   default:
    _show_help(argv[0]);
    return -1;
  }
 }
 if (optind < argc) {
  printf("Unknown parameter: ");
  while (optind < argc)
   printf ("%s ", argv[optind++]);
  printf ("\n");
  return 1;
 }
 return 0;
}

variable_types: rez int

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


main

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

if ( argc == 1 )
{
show_help((__int64)*argv);
return 1;
}
v3 = parse(argc, (char **)argv);
result = 1;
if ( !v3 )
{
result = list;
if ( list )
{
if ( pid || module || group || mask )
{
puts("Invalid usage of --list");
return 1;
}
}
else if ( module || group )
{
if ( !pid )
{
puts("Invalid usage of --module or --group without --pid");
return 1;
}
if ( !mask )
return showPid();
goto LABEL_18;
}
if ( !mask )
{
if ( !pid )
{
if ( list )
result = showlist();
return result;
}
return showPid();
}
LABEL_18:
result = setMask();
}
return result;
}

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

if ( argc == 1 )
{
func9((__int64)*argv);
return 1;
}
v3 = func10(argc, (char **)argv);
result = 1;
if ( !v3 )
{
result = list;
if ( list )
{
if ( pid || module || group || mask )
{
puts("Invalid usage of --list");
return 1;
}
}
else if ( module || group )
{
if ( !pid )
{
puts("Invalid usage of --module or --group without --pid");
return 1;
}
if ( !mask )
return func12();
goto LABEL_18;
}
if ( !mask )
{
if ( !pid )
{
if ( list )
result = func11();
return result;
}
return func12();
}
LABEL_18:
result = func13();
}
return result;
}

original_code:
int main(int argc, char **argv) {
 if (argc == 1) {
  _show_help(argv[0]);
  return 1;
 }
 if (parse(argc, argv)!=0)
  return 1;
 if(list && (pid || module || group || mask)) {
  printf("Invalid usage of --list\n");
  return 1;
 }
 if ((module || group) && !pid) {
  printf("Invalid usage of --module or --group without --pid\n");
  return 1;
 }
 if (mask)
  return _setMask();
 if (pid)
  return _showPid();
 if (list)
  return _showlist();
 return 0;
}


xread

decompiled_code:
__int64 __fastcall xread(int fd, __int64 a2, unsigned __int64 a3)
{
unsigned __int64 v4; // rbx
int v5; // eax
int v6; // eax

if ( !a3 )
return 0LL;
v4 = 0LL;
while ( 1 )
{
v6 = read(fd, (void *)(a2 + v4), a3 - v4);
if ( !v6 )
return 0xFFFFFFFFLL;
if ( v6 == -1LL )
break;
v4 += v6;
LABEL_5:
if ( v4 >= a3 )
return 0LL;
}
v5 = *_errno_location();
if ( v5 == 11 || v5 == 4 )
goto LABEL_5;
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func0(int fd, __int64 a2, unsigned __int64 a3)
{
unsigned __int64 v4; // rbx
int v5; // eax
int v6; // eax

if ( !a3 )
return 0LL;
v4 = 0LL;
while ( 1 )
{
v6 = read(fd, (void *)(a2 + v4), a3 - v4);
if ( !v6 )
return 0xFFFFFFFFLL;
if ( v6 == -1LL )
break;
v4 += v6;
LABEL_5:
if ( v4 >= a3 )
return 0LL;
}
v5 = *_errno_location();
if ( v5 == 11 || v5 == 4 )
goto LABEL_5;
return 0xFFFFFFFFLL;
}

original_code:
static int
xread(int fd, char *buffer, size_t len) {
    size_t done = 0;
    size_t n;
    while (done < len) {
 n = read(fd, buffer + done, len - done);
 if (n == 0) {
     return -1;
 }
 else if (n != (size_t)-1) {
     done += n;
 }
 else if ((*__errno_location ()) != 11 && (*__errno_location ()) != 4) {
     return -1;
 }
    }
    return 0;
}

canonical_original_code:
static int xread(int fd, char *buffer, unsigned long len) {
    unsigned long done = 0;
    unsigned long n;
    while (done < len) {
 n = read(fd, buffer + done, len - done);
 if (n == 0) {
     return -1;
 }
 else if (n != (unsigned long)-1) {
     done += n;
 }
 else if ((*__errno_location ()) != 11 && (*__errno_location ()) != 4) {
     return -1;
 }
    }
    return 0;
}

variable_types: fd int

variable_types:
buffer
char *

variable_types:
len
unsigned long

variable_types:
done
unsigned long

variable_types:
n
unsigned long