original_code:
static void test_loop(uint16_t a, uint8_t r, int quick)
{
    int s = 8 * (r <= 6 ? r : 6);
    uint64_t b = (uint64_t)1 << s;
    uint64_t goal = ((uint64_t)a << s);
    uint64_t bail = goal + 1;
    uint64_t crappy = b;
    uint64_t ptot = 0;
    uint64_t pmin = 0xffffffffffffffff;
    uint64_t pmax = 0;
    uint64_t npmin = 0;
    uint64_t npmax = 0;
    uint64_t dups = 0;
    uint64_t np1 = 0;
    uint64_t loops = 0;
    uint64_t p;
    uint64_t x = 0;
    int stop = 0, overrun = 0;
    uint16_t c = 0;
    if (b <= 0x10000000)
        quick = 0;
    if (quick)
    {
        b = 0x10000000;
        goal = a * b;
        bail = b + 1;
        crappy = b;
    }
    if (period(a, a - 1, -1LL, r, 2) == 1)
        np1++, ptot++;
    for (c = 0; c < a; c++)
    {
        putchar('.');
        fflush(stdout);
        for (x = 0; x < b; x++)
        {
            p = period(a, c, x, r, bail);
            switch (p)
            {
            case 0:
                dups++;
                if (loops == 0)
                    stop = 1;
                break;
            case 1:
                np1++;
                if (np1 > 2)
                    stop = 1;
                break;
            default:
                if (p == bail && !quick)
                {
                    overrun = 1;
                    p = 0;
                    stop = 1;
                }
                else
                {
                    printf("x=0x%llx, c=0x%x, p%s%llu (0x%llx)\n", x, c, p == bail ? ">=" : "=", p, p);
                    loops++;
                    if (pmin > p) pmin = p, npmin = 0;
                    if (pmax < p) pmax = p, npmax = 0;
                    if (pmin == p) npmin++;
                    if (pmax == p) npmax++;
                    if (p <= crappy)
                        stop = 1;
                }
            }
            ptot += p;
            if (ptot >= goal)
                stop = 1;
            if (stop)
                break;
        }
        if (stop)
            break;
    }
    printf("\nStopped at x=0x%llx, c=0x%x\n", x, c);
    if (ptot >= goal)
        printf("Met coverage requirement (0x%llx >= 0x%llx)\n", ptot, goal);
    printf("a=0x%x, r=%d, %llux p=1, "
            "%llux pmin=%llu (0x%llx), "
            "%llux pmax=%llu (0x%llx) "
            "goal %s\n",
            a, r, np1,
            npmin, pmin, pmin,
            npmax, pmax, pmax,
            ptot >= goal ? "met" : "missed");
    printf("loops=%llu, dups=%llu\n", loops, dups);
    if (overrun > 0)
        printf("!!! Bailed out because test overran\n");
    if (dups != 0 && loops == 0)
        printf("!!! Bailed out for collapsing to zero\n");
    if (np1 > 2)
        printf("!!! Bailed out with too many p=1\n");
    if (pmin <= crappy)
        printf("!!! Bailed out because pmin=0x%llx is crappy\n", pmin);
}

canonical_original_code:
static void test_loop(unsigned short a, unsigned char r, int quick)
{
    int s = 8 * (r <= 6 ? r : 6);
    unsigned long b = (uint64_t)1 << s;
    unsigned long goal = ((uint64_t)a << s);
    unsigned long bail = goal + 1;
    unsigned long crappy = b;
    unsigned long ptot = 0;
    unsigned long pmin = 0xffffffffffffffff;
    unsigned long pmax = 0;
    unsigned long npmin = 0;
    unsigned long npmax = 0;
    unsigned long dups = 0;
    unsigned long np1 = 0;
    unsigned long loops = 0;
    unsigned long p;
    unsigned long x = 0;
    int stop = 0; int overrun = 0;
    unsigned short c = 0;
    if (b <= 0x10000000)
        quick = 0;
    if (quick)
    {
        b = 0x10000000;
        goal = a * b;
        bail = b + 1;
        crappy = b;
    }
    if (period(a, a - 1, -1LL, r, 2) == 1)
        np1++, ptot++;
    for (c = 0; c < a; c++)
    {
        putchar('.');
        fflush(stdout);
        for (x = 0; x < b; x++)
        {
            p = period(a, c, x, r, bail);
            switch (p)
            {
            case 0:
                dups++;
                if (loops == 0)
                    stop = 1;
                break;
            case 1:
                np1++;
                if (np1 > 2)
                    stop = 1;
                break;
            default:
                if (p == bail && !quick)
                {
                    overrun = 1;
                    p = 0;
                    stop = 1;
                }
                else
                {
                    printf("x=0x%llx, c=0x%x, p%s%llu (0x%llx)\n", x, c, p == bail ? ">=" : "=", p, p);
                    loops++;
                    if (pmin > p) pmin = p, npmin = 0;
                    if (pmax < p) pmax = p, npmax = 0;
                    if (pmin == p) npmin++;
                    if (pmax == p) npmax++;
                    if (p <= crappy)
                        stop = 1;
                }
            }
            ptot += p;
            if (ptot >= goal)
                stop = 1;
            if (stop)
                break;
        }
        if (stop)
            break;
    }
    printf("\nStopped at x=0x%llx, c=0x%x\n", x, c);
    if (ptot >= goal)
        printf("Met coverage requirement (0x%llx >= 0x%llx)\n", ptot, goal);
    printf("a=0x%x, r=%d, %llux p=1, "
            "%llux pmin=%llu (0x%llx), "
            "%llux pmax=%llu (0x%llx) "
            "goal %s\n",
            a, r, np1,
            npmin, pmin, pmin,
            npmax, pmax, pmax,
            ptot >= goal ? "met" : "missed");
    printf("loops=%llu, dups=%llu\n", loops, dups);
    if (overrun > 0)
        printf("!!! Bailed out because test overran\n");
    if (dups != 0 && loops == 0)
        printf("!!! Bailed out for collapsing to zero\n");
    if (np1 > 2)
        printf("!!! Bailed out with too many p=1\n");
    if (pmin <= crappy)
        printf("!!! Bailed out because pmin=0x%llx is crappy\n", pmin);
}

variable_types:
b
unsigned long

variable_types:
goal
unsigned long

variable_types:
bail
unsigned long

variable_types:
crappy
unsigned long

variable_types:
ptot
unsigned long

variable_types:
pmin
unsigned long

variable_types:
pmax
unsigned long

variable_types:
npmin
unsigned long

variable_types:
npmax
unsigned long

variable_types:
dups
unsigned long

variable_types:
loops
unsigned long

variable_types: stop int

variable_types: overrun int


getpasswd

repo: shaardie/onetimepad

decompiled_code:
__int64 __fastcall getpasswd(__int64 a1, const char *a2)
{
struct termios v3; // [rsp+0h] [rbp-98h] BYREF
struct termios termios_p; // [rsp+40h] [rbp-58h] BYREF

tcgetattr(0, &termios_p);
*(__m128i *)&v3.c_iflag = _mm_loadu_si128((const __m128i *)&termios_p);
*(__m128i *)&v3.c_line = _mm_loadu_si128((const __m128i *)&termios_p.c_line);
*(__m128i *)&v3.c_cc[15] = _mm_loadu_si128((const __m128i *)&termios_p.c_cc[15]);
*(_QWORD *)&v3.c_cc[31] = *(_QWORD *)&termios_p.c_cc[31];
v3.c_ospeed = termios_p.c_ospeed;
v3.c_lflag &= 0xFFFFF387;
tcsetattr(0, 0, &v3);
if ( a2 )
{
printf(a2);
_isoc99_scanf("%1023s", a1);
tcsetattr(0, 0, &termios_p);
putchar(10);
}
else
{
_isoc99_scanf("%1023s", a1);
tcsetattr(0, 0, &termios_p);
}
return a1;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, const char *a2)
{
struct termios v3; // [rsp+0h] [rbp-98h] BYREF
struct termios termios_p; // [rsp+40h] [rbp-58h] BYREF

tcgetattr(0, &termios_p);
*(__m128i *)&v3.c_iflag = _mm_loadu_si128((const __m128i *)&termios_p);
*(__m128i *)&v3.c_line = _mm_loadu_si128((const __m128i *)&termios_p.c_line);
*(__m128i *)&v3.c_cc[15] = _mm_loadu_si128((const __m128i *)&termios_p.c_cc[15]);
*(_QWORD *)&v3.c_cc[31] = *(_QWORD *)&termios_p.c_cc[31];
v3.c_ospeed = termios_p.c_ospeed;
v3.c_lflag &= 0xFFFFF387;
tcsetattr(0, 0, &v3);
if ( a2 )
{
printf(a2);
_isoc99_scanf("%1023s", a1);
tcsetattr(0, 0, &termios_p);
putchar(10);
}
else
{
_isoc99_scanf("%1023s", a1);
tcsetattr(0, 0, &termios_p);
}
return a1;
}

original_code:
char * getpasswd( char * passwd, char * msg ) {
 struct termios old_opts, new_opts;
 tcgetattr( 0, &old_opts );
 memcpy( &new_opts, &old_opts, sizeof( struct termios ) );
 new_opts.c_lflag &= ~( 0000010 | 0000020 | 0000040 | 0000100 | 0002000 | 0004000 );
 tcsetattr( 0, 0, &new_opts );
 if (msg)
  printf( msg );
 scanf( "%1023s", passwd );
 tcsetattr( 0, 0, &old_opts );
 if (msg)
  printf( "\n" );
 return passwd;
}

canonical_original_code:
char *getpasswd(char *passwd, char *msg) {
 struct termios old_opts; struct termios new_opts;
 tcgetattr( 0, &old_opts );
 memcpy( &new_opts, &old_opts, sizeof( struct termios ) );
 new_opts.c_lflag &= ~( 0000010 | 0000020 | 0000040 | 0000100 | 0002000 | 0004000 );
 tcsetattr( 0, 0, &new_opts );
 if (msg)
  printf( msg );
 scanf( "%1023s", passwd );
 tcsetattr( 0, 0, &old_opts );
 if (msg)
  printf( "\n" );
 return passwd;
}

variable_types:
passwd
char *

variable_types:
msg
char *

variable_types: struct termios { unsigned int c_iflag; unsigned int c_oflag; unsigned int c_cflag; unsigned int c_lflag; unsigned char c_line; unsigned char c_cc[32]; unsigned int c_ispeed; unsigned int c_ospeed; }

return_type: char *


getkey

decompiled_code:
void *__fastcall getkey(void **a1, _QWORD *a2, const char *a3)
{
size_t v4; // rax
char v6[1048]; // [rsp+0h] [rbp-418h] BYREF

if ( !*a2 )
{
puts("Generating salt");
*a2 = gcry_random_bytes(8LL, 1LL);
}
*a1 = malloc(0x20uLL);
getpasswd((__int64)v6, a3);
v4 = strlen(v6);
gcry_kdf_derive(v6, v4, 19LL, 10LL, *a2, 8LL, 10LL, 32LL, *a1);
return *a1;
}

canonical_decompiled_code:
void *__fastcall func1(void **a1, _QWORD *a2, const char *a3)
{
size_t v4; // rax
char v6[1048]; // [rsp+0h] [rbp-418h] BYREF

if ( !*a2 )
{
puts("Generating salt");
*a2 = gcry_random_bytes(8LL, 1LL);
}
*a1 = malloc(0x20uLL);
func0((__int64)v6, a3);
v4 = strlen(v6);
gcry_kdf_derive(v6, v4, 19LL, 10LL, *a2, 8LL, 10LL, 32LL, *a1);
return *a1;
}

original_code:
char * getkey(char ** key, void ** salt, char * msg) {
 char passphrase[1024];
 if (!*salt) {
  printf("Generating salt\n");
  *salt = gcry_random_bytes( 8, GCRY_STRONG_RANDOM );
 }
 *key = (char *) malloc(32 * sizeof(char));
 getpasswd( passphrase, msg );
 gcry_kdf_derive( passphrase, strlen(passphrase), GCRY_KDF_ITERSALTED_S2K,
   GCRY_MD_SHA512, *salt, 8, 10, 32, *key );
 return *key;
}

canonical_original_code:
char *getkey(char **key, void **salt, char *msg) {
 char passphrase[1024];
 if (!*salt) {
  printf("Generating salt\n");
  *salt = gcry_random_bytes( 8, GCRY_STRONG_RANDOM );
 }
 *key = (char *) malloc(32 * sizeof(char));
 getpasswd( passphrase, msg );
 gcry_kdf_derive( passphrase, strlen(passphrase), GCRY_KDF_ITERSALTED_S2K,
   GCRY_MD_SHA512, *salt, 8, 10, 32, *key );
 return *key;
}

variable_types:
key
char **

variable_types:
salt
void **

variable_types:
passphrase
char [1024]


decompiled_code:
__int64 iolib_init()
{
void *v0; // rax
__int64 v1; // rbx
void *v2; // rax

if ( memh )
return 0xFFFFFFFFLL;
PortSet_ptr = (__int64)&p8_PortSet;
*(&PortSet_ptr + 1) = (__int64)&p9_PortSet;
PortIDSet_ptr = (__int64)&p8_PortIDSet;
*(&PortIDSet_ptr + 1) = (__int64)&p9_PortIDSet;
memh = open("/dev/mem", 2);
v0 = mmap(0LL, 0x4000uLL, 3, 1, memh, 1155530752LL);
cm_per_addr = (__int64)v0;
if ( v0 == (void *)-1LL )
return 0xFFFFFFFFLL;
cm_wkup_addr = (__int64)v0 + 1024;
v1 = 0LL;
while ( 1 )
{
v2 = mmap(0LL, 0x1000uLL, 3, 1, memh, *((unsigned int *)&GPIO_AddressOffset + v1));
gpio_addr[v1] = (__int64)v2;
if ( v2 == (void *)-1LL )
break;
if ( ++v1 == 4 )
{
ctrl_addr = (__int64)mmap(0LL, 0x2000uLL, 3, 1, memh, 1155596288LL);
return (unsigned int)-(ctrl_addr == -1);
}
}
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 func0()
{
void *v0; // rax
__int64 v1; // rbx
void *v2; // rax

if ( memh )
return 0xFFFFFFFFLL;
PortSet_ptr = (__int64)&p8_PortSet;
*(&PortSet_ptr + 1) = (__int64)&p9_PortSet;
PortIDSet_ptr = (__int64)&p8_PortIDSet;
*(&PortIDSet_ptr + 1) = (__int64)&p9_PortIDSet;
memh = open("/dev/mem", 2);
v0 = mmap(0LL, 0x4000uLL, 3, 1, memh, 1155530752LL);
cm_per_addr = (__int64)v0;
if ( v0 == (void *)-1LL )
return 0xFFFFFFFFLL;
cm_wkup_addr = (__int64)v0 + 1024;
v1 = 0LL;
while ( 1 )
{
v2 = mmap(0LL, 0x1000uLL, 3, 1, memh, *((unsigned int *)&GPIO_AddressOffset + v1));
gpio_addr[v1] = (__int64)v2;
if ( v2 == (void *)-1LL )
break;
if ( ++v1 == 4 )
{
ctrl_addr = (__int64)mmap(0LL, 0x2000uLL, 3, 1, memh, 1155596288LL);
return (unsigned int)-(ctrl_addr == -1);
}
}
return 0xFFFFFFFFLL;
}

original_code:
int
iolib_init(void)
{
 int i;
 if (memh)
 {
     if (0) printf("iolib_init: memory already mapped?\n");
     return -1;
 }
 PortSet_ptr[0]=(char*)p8_PortSet;
 PortSet_ptr[1]=(char*)p9_PortSet;
 PortIDSet_ptr[0]=(unsigned int*)p8_PortIDSet;
 PortIDSet_ptr[1]=(unsigned int*)p9_PortIDSet;
 memh=open("/dev/mem", 02);
 cm_per_addr = mmap(0, 0x4000, 0x1 | 0x2, 0x01, memh, 0x44e00000);
 if(cm_per_addr == ((void *) -1))
     {
            if (0) printf("iolib_init: CM_PER mmap failure! ,error :%s\n" ,strerror((*__errno_location ())));
            return -1;
 }
 cm_wkup_addr =(void *)cm_per_addr + 0x400 ;
 for (i=0; i<4; i++)
 {
     gpio_addr[i] = mmap(0 ,0x1000 ,0x1 | 0x2 ,0x01 ,memh ,GPIO_AddressOffset[i]);
     if(gpio_addr[i] == ((void *) -1))
     {
  if (0) printf("iolib_init: gpio mmap failure!\n");
      return -1;
     }
 }
 ctrl_addr = mmap(0, 0x2000, 0x1 | 0x2, 0x01, memh, 0x44e10000);
 if(ctrl_addr == ((void *) -1))
 {
     if (0) printf("iolib_init: control module mmap failure!\n");
  return -1;
 }
 return 0;
}

canonical_original_code:
int iolib_init()
{
 int i;
 if (memh)
 {
     if (0) printf("iolib_init: memory already mapped?\n");
     return -1;
 }
 PortSet_ptr[0]=(char *)p8_PortSet;
 PortSet_ptr[1]=(char *)p9_PortSet;
 PortIDSet_ptr[0]=(unsigned int *)p8_PortIDSet;
 PortIDSet_ptr[1]=(unsigned int *)p9_PortIDSet;
 memh=open("/dev/mem", 02);
 cm_per_addr = mmap(0, 0x4000, 0x1 | 0x2, 0x01, memh, 0x44e00000);
 if(cm_per_addr == ((void *) -1))
     {
            if (0) printf("iolib_init: CM_PER mmap failure! ,error :%s\n" ,strerror((*__errno_location ())));
            return -1;
 }
 cm_wkup_addr =(void *)cm_per_addr + 0x400 ;
 for (i=0; i<4; i++)
 {
     gpio_addr[i] = mmap(0 ,0x1000 ,0x1 | 0x2 ,0x01 ,memh ,GPIO_AddressOffset[i]);
     if(gpio_addr[i] == ((void *) -1))
     {
  if (0) printf("iolib_init: gpio mmap failure!\n");
      return -1;
     }
 }
 ctrl_addr = mmap(0, 0x2000, 0x1 | 0x2, 0x01, memh, 0x44e10000);
 if(ctrl_addr == ((void *) -1))
 {
     if (0) printf("iolib_init: control module mmap failure!\n");
  return -1;
 }
 return 0;
}

variable_types: i int

return_type: int


decompiled_code:
__int64 iolib_free()
{
if ( memh )
close(memh);
return 0LL;
}

canonical_decompiled_code:
__int64 func1()
{
if ( memh )
close(memh);
return 0LL;
}

original_code:
int
iolib_free(void)
{
 if (memh!=0)
 {
  close(memh);
 }
 return(0);
}

canonical_original_code:
int iolib_free()
{
 if (memh!=0)
 {
  close(memh);
 }
 return(0);
}


decompiled_code:
__int64 __fastcall iolib_setdir(char a1, char a2, char a3)
{
int v3; // ecx
unsigned int v4; // er8
__int64 v6; // rax

v3 = a1 - 8;
v4 = -1;
if ( (unsigned __int8)(a1 - 8) <= 1u )
{
if ( (unsigned __int8)(a2 - 1) > 0x2Du )
{
v4 = -1;
}
else if ( *(char *)(PortSet_ptr[a1] + a2) >= 0 && memh )
{
v6 = gpio_addr[*(char *)(PortSet_ptr[v3] + a2 - 1)];
if ( a3 == 1 )
{
*(_DWORD *)(v6 + 308) &= ~*(_DWORD *)(PortIDSet_ptr[v3] + 4LL * a2 - 4);
v4 = 0;
}
else
{
v4 = 0;
if ( !a3 )
*(_DWORD *)(v6 + 308) |= *(_DWORD *)(PortIDSet_ptr[v3] + 4LL * a2 - 4);
}
}
else
{
v4 = -1;
}
}
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func2(char a1, char a2, char a3)
{
int v3; // ecx
unsigned int v4; // er8
__int64 v6; // rax

v3 = a1 - 8;
v4 = -1;
if ( (unsigned __int8)(a1 - 8) <= 1u )
{
if ( (unsigned __int8)(a2 - 1) > 0x2Du )
{
v4 = -1;
}
else if ( *(char *)(PortSet_ptr[a1] + a2) >= 0 && memh )
{
v6 = gpio_addr[*(char *)(PortSet_ptr[v3] + a2 - 1)];
if ( a3 == 1 )
{
*(_DWORD *)(v6 + 308) &= ~*(_DWORD *)(PortIDSet_ptr[v3] + 4LL * a2 - 4);
v4 = 0;
}
else
{
v4 = 0;
if ( !a3 )
*(_DWORD *)(v6 + 308) |= *(_DWORD *)(PortIDSet_ptr[v3] + 4LL * a2 - 4);
}
}
else
{
v4 = -1;
}
}
return v4;
}

original_code:
int
iolib_setdir(char port, char pin, char dir)
{
 int i;
 int param_error=0;
 volatile unsigned int* reg;
 int reg_port = port -8;
 int reg_pin = pin -1;
 if (memh==0)
  param_error=1;
 if ((port<8) || (port>9))
  param_error=1;
 if ((pin<1) || (pin>46))
  param_error=1;
 if (PortSet_ptr[port][pin]<0)
  param_error=1;
 if (param_error)
 {
  if (0) printf("iolib_setdir: parameter error!\n");
  return(-1);
 }
 if (0)
  printf("iolib_setdir: PortSet_ptr P%d.%d , %X\n",port ,pin , PortSet_ptr[port-8][pin-1]);
 reg=(void*)gpio_addr[PortSet_ptr[port-8][pin-1]] +0x134;
 if (dir ==1)
 {
  *reg &= ~(PortIDSet_ptr[port-8][pin-1]);
 }
 else if (dir ==0)
 {
  *reg |= PortIDSet_ptr[port-8][pin-1];
 }
 return(0);
}

canonical_original_code:
int iolib_setdir(char port, char pin, char dir)
{
 int i;
 int param_error = 0;
 unsigned int *reg;
 int reg_port = port -8;
 int reg_pin = pin -1;
 if (memh==0)
  param_error=1;
 if ((port<8) || (port>9))
  param_error=1;
 if ((pin<1) || (pin>46))
  param_error=1;
 if (PortSet_ptr[port][pin]<0)
  param_error=1;
 if (param_error)
 {
  if (0) printf("iolib_setdir: parameter error!\n");
  return(-1);
 }
 if (0)
  printf("iolib_setdir: PortSet_ptr P%d.%d , %X\n",port ,pin , PortSet_ptr[port-8][pin-1]);
 reg=(void *)gpio_addr[PortSet_ptr[port-8][pin-1]] +0x134;
 if (dir ==1)
 {
  *reg &= ~(PortIDSet_ptr[port-8][pin-1]);
 }
 else if (dir ==0)
 {
  *reg |= PortIDSet_ptr[port-8][pin-1];
 }
 return(0);
}

variable_types: port char

variable_types: pin char

variable_types: dir char

variable_types:
reg
unsigned int *


decompiled_code:
__int64 __fastcall iolib_delay_ms(int a1)
{
int *v2; // rax
unsigned int v3; // eax
struct timespec v4; // [rsp+0h] [rbp-18h] BYREF

if ( (unsigned int)a1 > 0x3E7 )
{
fwrite("delay_ms error: delay value needs to be less than 999\n", 1uLL, 0x36uLL, stderr);
a1 = 999;
}
v4.tv_nsec = (unsigned int)(int)((double)a1 * 1000000.0);
v4.tv_sec = 0LL;
if ( nanosleep(&v4, 0LL) )
{
v2 = _errno_location();
v3 = (unsigned int)strerror(*v2);
fprintf(stderr, "delay_ms error: %s\n", (const char *)v3);
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(int a1)
{
int *v2; // rax
unsigned int v3; // eax
struct timespec v4; // [rsp+0h] [rbp-18h] BYREF

if ( (unsigned int)a1 > 0x3E7 )
{
fwrite("delay_ms error: delay value needs to be less than 999\n", 1uLL, 0x36uLL, stderr);
a1 = 999;
}
v4.tv_nsec = (unsigned int)(int)((double)a1 * 1000000.0);
v4.tv_sec = 0LL;
if ( nanosleep(&v4, 0LL) )
{
v2 = _errno_location();
v3 = (unsigned int)strerror(*v2);
fprintf(stderr, "delay_ms error: %s\n", (const char *)v3);
}
return 0LL;
}

original_code:
int
iolib_delay_ms(unsigned int msec)
{
 int ret;
 struct timespec a;
 if (msec>999)
 {
  fprintf(stderr, "delay_ms error: delay value needs to be less than 999\n");
  msec=999;
 }
 a.tv_nsec=((long)(msec))*1E6d;
 a.tv_sec=0;
 if ((ret = nanosleep(&a, ((void *)0))) != 0)
 {
  fprintf(stderr, "delay_ms error: %s\n", strerror((*__errno_location ())));
 }
 return(0);
}

variable_types:
msec
unsigned int

variable_types: ret int

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


original_code:
void
BBBIO_sys_GPIO_CLK_status()
{
 volatile unsigned int* reg ;
 unsigned int reg_value =0;
 const char s_GDBLCK[][9]={"FCLK_DIS" ,"FCLK_EN"};
 const char s_IDLEST[][8]={"Func" ,"Trans" ,"Idle" ,"Disable"};
 const char s_MODULEMODE[][8]={"Disable" ,"Reserve" ,"Enable" ,"Reserve"};
 int v_GDBLCK ;
 int v_IDLEST ;
 int v_MODULEMODE ;
 printf("\n******************************************************\n");
 printf("************ GPIO Clock module Information ***********\n");
 printf("******************************************************\n");
 reg =(void*)cm_per_addr + 0x0;
 reg_value = *reg ;
 printf("CM_PER CM_PER_L4LS_CLKSTCTRL : %X\n\n", reg_value );
 reg =(void*)cm_wkup_addr + 0x8 ;
        reg_value = *reg ;
 v_GDBLCK = (reg_value >>18) & 0x01 ;
 v_IDLEST = (reg_value >>16) & 0x02 ;
 v_MODULEMODE = reg_value & 0x02 ;
        printf("CM_WKUP CM_WKUP_GPIO0_CLKCTRL : %X\n", *reg );
        printf("\t[18]    OPTFCLKEN_GPIO_0_GDBCLK : %X (%s)\n", v_GDBLCK ,s_GDBLCK[v_GDBLCK]);
        printf("\t[17-18] IDLEST                  : %X (%s)\n", v_IDLEST ,s_IDLEST[v_IDLEST]);
        printf("\t[0-1]   MODULEMODE              : %X (%s)\n\n", v_MODULEMODE ,s_MODULEMODE[v_MODULEMODE]);
 reg =(void*)cm_per_addr + 0xAC;
 reg_value = *reg ;
        v_GDBLCK = (reg_value >>18) & 0x01 ;
        v_IDLEST = (reg_value >>16) & 0x02 ;
        v_MODULEMODE = reg_value & 0x02 ;
 printf("CM_PER CM_PER_GPIO1_CLKCTRL : %X\n", *reg );
        printf("\t[18]    OPTFCLKEN_GPIO_1_GDBCLK : %X (%s)\n", v_GDBLCK ,s_GDBLCK[v_GDBLCK]);
        printf("\t[17-18] IDLEST                  : %X (%s)\n", v_IDLEST ,s_IDLEST[v_IDLEST]);
        printf("\t[0-1]   MODULEMODE              : %X (%s)\n\n", v_MODULEMODE ,s_MODULEMODE[v_MODULEMODE]);
 reg =(void*)cm_per_addr + 0xB0;
 reg_value = *reg ;
        v_GDBLCK = (reg_value >>18) & 0x01 ;
        v_IDLEST = (reg_value >>16) & 0x02 ;
        v_MODULEMODE = reg_value & 0x02 ;
 printf("CM_PER CM_PER_GPIO2_CLKCTRL : %X\n", *reg );
        printf("\t[18]    OPTFCLKEN_GPIO_2_GDBCLK : %X (%s)\n", v_GDBLCK ,s_GDBLCK[v_GDBLCK]);
        printf("\t[17-18] IDLEST                  : %X (%s)\n", v_IDLEST ,s_IDLEST[v_IDLEST]);
        printf("\t[0-1]   MODULEMODE              : %X (%s)\n\n", v_MODULEMODE ,s_MODULEMODE[v_MODULEMODE]);
 reg =(void*)cm_per_addr + 0xB4;
 reg_value = *reg ;
        v_GDBLCK = (reg_value >>18) & 0x01 ;
        v_IDLEST = (reg_value >>16) & 0x02 ;
        v_MODULEMODE = reg_value & 0x02 ;
 printf("CM_PER CM_PER_GPIO3_CLKCTRL : %X\n", *reg );
        printf("\t[18]    OPTFCLKEN_GPIO_0_GDBCLK : %X (%s)\n", v_GDBLCK ,s_GDBLCK[v_GDBLCK]);
        printf("\t[17-18] IDLEST                  : %X (%s)\n", v_IDLEST ,s_IDLEST[v_IDLEST]);
        printf("\t[0-1]   MODULEMODE              : %X (%s)\n\n", v_MODULEMODE ,s_MODULEMODE[v_MODULEMODE]);
}

canonical_original_code:
void BBBIO_sys_GPIO_CLK_status()
{
 unsigned int *reg;
 unsigned int reg_value = 0;
 char s_GDBLCK[][9] = {"FCLK_DIS" ,"FCLK_EN"};
 char s_IDLEST[][8] = {"Func" ,"Trans" ,"Idle" ,"Disable"};
 char s_MODULEMODE[][8] = {"Disable" ,"Reserve" ,"Enable" ,"Reserve"};
 int v_GDBLCK;
 int v_IDLEST;
 int v_MODULEMODE;
 printf("\n******************************************************\n");
 printf("************ GPIO Clock module Information ***********\n");
 printf("******************************************************\n");
 reg =(void *)cm_per_addr + 0x0;
 reg_value = *reg ;
 printf("CM_PER CM_PER_L4LS_CLKSTCTRL : %X\n\n", reg_value );
 reg =(void *)cm_wkup_addr + 0x8 ;
        reg_value = *reg ;
 v_GDBLCK = (reg_value >>18) & 0x01 ;
 v_IDLEST = (reg_value >>16) & 0x02 ;
 v_MODULEMODE = reg_value & 0x02 ;
        printf("CM_WKUP CM_WKUP_GPIO0_CLKCTRL : %X\n", *reg );
        printf("\t[18]    OPTFCLKEN_GPIO_0_GDBCLK : %X (%s)\n", v_GDBLCK ,s_GDBLCK[v_GDBLCK]);
        printf("\t[17-18] IDLEST                  : %X (%s)\n", v_IDLEST ,s_IDLEST[v_IDLEST]);
        printf("\t[0-1]   MODULEMODE              : %X (%s)\n\n", v_MODULEMODE ,s_MODULEMODE[v_MODULEMODE]);
 reg =(void *)cm_per_addr + 0xAC;
 reg_value = *reg ;
        v_GDBLCK = (reg_value >>18) & 0x01 ;
        v_IDLEST = (reg_value >>16) & 0x02 ;
        v_MODULEMODE = reg_value & 0x02 ;
 printf("CM_PER CM_PER_GPIO1_CLKCTRL : %X\n", *reg );
        printf("\t[18]    OPTFCLKEN_GPIO_1_GDBCLK : %X (%s)\n", v_GDBLCK ,s_GDBLCK[v_GDBLCK]);
        printf("\t[17-18] IDLEST                  : %X (%s)\n", v_IDLEST ,s_IDLEST[v_IDLEST]);
        printf("\t[0-1]   MODULEMODE              : %X (%s)\n\n", v_MODULEMODE ,s_MODULEMODE[v_MODULEMODE]);
 reg =(void *)cm_per_addr + 0xB0;
 reg_value = *reg ;
        v_GDBLCK = (reg_value >>18) & 0x01 ;
        v_IDLEST = (reg_value >>16) & 0x02 ;
        v_MODULEMODE = reg_value & 0x02 ;
 printf("CM_PER CM_PER_GPIO2_CLKCTRL : %X\n", *reg );
        printf("\t[18]    OPTFCLKEN_GPIO_2_GDBCLK : %X (%s)\n", v_GDBLCK ,s_GDBLCK[v_GDBLCK]);
        printf("\t[17-18] IDLEST                  : %X (%s)\n", v_IDLEST ,s_IDLEST[v_IDLEST]);
        printf("\t[0-1]   MODULEMODE              : %X (%s)\n\n", v_MODULEMODE ,s_MODULEMODE[v_MODULEMODE]);
 reg =(void *)cm_per_addr + 0xB4;
 reg_value = *reg ;
        v_GDBLCK = (reg_value >>18) & 0x01 ;
        v_IDLEST = (reg_value >>16) & 0x02 ;
        v_MODULEMODE = reg_value & 0x02 ;
 printf("CM_PER CM_PER_GPIO3_CLKCTRL : %X\n", *reg );
        printf("\t[18]    OPTFCLKEN_GPIO_0_GDBCLK : %X (%s)\n", v_GDBLCK ,s_GDBLCK[v_GDBLCK]);
        printf("\t[17-18] IDLEST                  : %X (%s)\n", v_IDLEST ,s_IDLEST[v_IDLEST]);
        printf("\t[0-1]   MODULEMODE              : %X (%s)\n\n", v_MODULEMODE ,s_MODULEMODE[v_MODULEMODE]);
}

return_type: void


original_code:
void
BBBIO_sys_Expansion_Header_status(unsigned int port)
{
        volatile unsigned int* reg ;
        unsigned int reg_value =0;
 int i ;
 const char extra_status[][12]={ "GND" ,"DC_33V" ,"CDD_5V" ,"SYS_5V" ,"PWR_BUT" ,
            "SYS_RESET" ,"VADC" ,"AIN4" ,"AGND" ,"AIN6" ,"AIN5" ,
            "AIN2" ,"AIN3" ,"AIN0" ,"AIN1" ,"Unknow"};
 const char s_SLEWCTRL[2][5] ={"Fast" ,"Slow"} ;
 const char s_EXACTIVE[2][8] ={"Disable" ,"Enable"} ;
 const char s_PULLTYPESEL[2][9]={"Pulldown" ,"Pullup"};
 const char s_PULLUPEN[2][8] ={"Enable" ,"Disable"} ;
 int v_SLEWCTRL ;
 int v_EXACTIVE ;
 int v_PULLTYPESEL ;
 int v_PULLUPEN ;
 int v_MODE ;
 if ((port<8) || (port>9))
 {
     printf("Expansion_Header only have P8 and P9 ,please check your input port :%d\n",port);
            return ;
 }
 port -=8 ;
        printf("\n******************************************************\n");
        printf("************ Expansion Header Information ************\n");
        printf("******************************************************\n");
 for(i=0 ;i< 46 ; i++)
  {
     if(ExpHeader_MODE0[port][i] &0xF0000000)
     {
  printf("P%d_%2d : \t%s\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t| P%d_%2d\n" ,port+8 ,i+1 ,
       &extra_status[ExpHeader_MODE0[port][i] &0x0f][0] ,
       port+8 ,i+1);
     }
     else
     {
      reg =(void*)ctrl_addr + ExpHeader_MODE0[port][i] ;
             reg_value = *reg ;
  v_SLEWCTRL = reg_value>>6 ;
  v_EXACTIVE = reg_value >>5 &0x01;
  v_PULLTYPESEL = reg_value >>4 & 0x01;
  v_PULLUPEN = reg_value >>3 & 0x01;
  v_MODE =reg_value &0x07;
  printf("P%d_%2d : \tSLEWCTRL %d (%s) \t,RXACTIVE %d (%s)\t,PULLTYPESEL %d (%s) \t,PULLDEN %d (%s) \t,MUXMODE : %d \t| P%d_%2d \n" ,
    port+8 ,i+1 ,
    v_SLEWCTRL ,s_SLEWCTRL[v_SLEWCTRL] ,
    v_EXACTIVE ,s_EXACTIVE[v_EXACTIVE] ,
    v_PULLTYPESEL ,s_PULLTYPESEL[v_PULLTYPESEL] ,
    v_PULLUPEN ,s_PULLUPEN[v_PULLUPEN] ,
    v_MODE ,
    port+8 ,i+1);
     }
 }
}

canonical_original_code:
void BBBIO_sys_Expansion_Header_status(unsigned int port)
{
        unsigned int *reg;
        unsigned int reg_value = 0;
 int i;
 char extra_status[][12] = { "GND" ,"DC_33V" ,"CDD_5V" ,"SYS_5V" ,"PWR_BUT" ,
            "SYS_RESET" ,"VADC" ,"AIN4" ,"AGND" ,"AIN6" ,"AIN5" ,
            "AIN2" ,"AIN3" ,"AIN0" ,"AIN1" ,"Unknow"};
 char s_SLEWCTRL[2][5] = {"Fast" ,"Slow"};
 char s_EXACTIVE[2][8] = {"Disable" ,"Enable"};
 char s_PULLTYPESEL[2][9] = {"Pulldown" ,"Pullup"};
 char s_PULLUPEN[2][8] = {"Enable" ,"Disable"};
 int v_SLEWCTRL;
 int v_EXACTIVE;
 int v_PULLTYPESEL;
 int v_PULLUPEN;
 int v_MODE;
 if ((port<8) || (port>9))
 {
     printf("Expansion_Header only have P8 and P9 ,please check your input port :%d\n",port);
            return ;
 }
 port -=8 ;
        printf("\n******************************************************\n");
        printf("************ Expansion Header Information ************\n");
        printf("******************************************************\n");
 for(i=0 ;i< 46 ; i++)
  {
     if(ExpHeader_MODE0[port][i] &0xF0000000)
     {
  printf("P%d_%2d : \t%s\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t| P%d_%2d\n" ,port+8 ,i+1 ,
       &extra_status[ExpHeader_MODE0[port][i] &0x0f][0] ,
       port+8 ,i+1);
     }
     else
     {
      reg =(void *)ctrl_addr + ExpHeader_MODE0[port][i] ;
             reg_value = *reg ;
  v_SLEWCTRL = reg_value>>6 ;
  v_EXACTIVE = reg_value >>5 &0x01;
  v_PULLTYPESEL = reg_value >>4 & 0x01;
  v_PULLUPEN = reg_value >>3 & 0x01;
  v_MODE =reg_value &0x07;
  printf("P%d_%2d : \tSLEWCTRL %d (%s) \t,RXACTIVE %d (%s)\t,PULLTYPESEL %d (%s) \t,PULLDEN %d (%s) \t,MUXMODE : %d \t| P%d_%2d \n" ,
    port+8 ,i+1 ,
    v_SLEWCTRL ,s_SLEWCTRL[v_SLEWCTRL] ,
    v_EXACTIVE ,s_EXACTIVE[v_EXACTIVE] ,
    v_PULLTYPESEL ,s_PULLTYPESEL[v_PULLTYPESEL] ,
    v_PULLUPEN ,s_PULLUPEN[v_PULLUPEN] ,
    v_MODE ,
    port+8 ,i+1);
     }
 }
}

variable_types:
port
unsigned int


decompiled_code:
__int64 __fastcall BBBIO_sys_Enable_Debouncing(int a1, unsigned int a2, unsigned int a3)
{
int v4; // edx
_BOOL4 v5; // er9
unsigned int v6; // ecx
__int64 result; // rax
__int64 v8; // rax
char v9; // cl
char *v10; // rsi
__int64 v11; // rdi
_DWORD *v12; // rcx
int v13[3]; // [rsp+0h] [rbp-Ch]

v13[0] = 172;
v13[1] = 176;
v13[2] = 180;
v4 = a1 - 8;
v5 = 1;
if ( (unsigned int)(a1 - 8) <= 1 )
v5 = memh == 0;
v6 = a2 - 1;
result = 0xFFFFFFFFLL;
if ( a2 - 1 <= 0x2D )
{
if ( *(char *)(PortSet_ptr[a1] + a2) < 0 )
{
result = 0xFFFFFFFFLL;
}
else if ( v5 || a3 > 0xFF )
{
result = 0xFFFFFFFFLL;
}
else
{
v8 = v6;
v9 = *(_BYTE *)(PortSet_ptr[v4] + v6);
if ( v9 )
{
v12 = (_DWORD *)(cm_per_addr + (unsigned int)v13[v9 - 1]);
*v12 |= 0x40000u;
}
else
{
*(_DWORD *)(cm_wkup_addr + 8) |= 0x40000u;
}
v10 = (char *)(PortSet_ptr[v4] + v8);
v11 = gpio_addr[*v10];
*(_DWORD *)(v11 + 336) |= *(_DWORD *)(PortIDSet_ptr[v4] + 4 * v8);
*(_DWORD *)(gpio_addr[*v10] + 340) = a3;
result = 0LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(int a1, unsigned int a2, unsigned int a3)
{
int v4; // edx
_BOOL4 v5; // er9
unsigned int v6; // ecx
__int64 result; // rax
__int64 v8; // rax
char v9; // cl
char *v10; // rsi
__int64 v11; // rdi
_DWORD *v12; // rcx
int v13[3]; // [rsp+0h] [rbp-Ch]

v13[0] = 172;
v13[1] = 176;
v13[2] = 180;
v4 = a1 - 8;
v5 = 1;
if ( (unsigned int)(a1 - 8) <= 1 )
v5 = memh == 0;
v6 = a2 - 1;
result = 0xFFFFFFFFLL;
if ( a2 - 1 <= 0x2D )
{
if ( *(char *)(PortSet_ptr[a1] + a2) < 0 )
{
result = 0xFFFFFFFFLL;
}
else if ( v5 || a3 > 0xFF )
{
result = 0xFFFFFFFFLL;
}
else
{
v8 = v6;
v9 = *(_BYTE *)(PortSet_ptr[v4] + v6);
if ( v9 )
{
v12 = (_DWORD *)(cm_per_addr + (unsigned int)v13[v9 - 1]);
*v12 |= 0x40000u;
}
else
{
*(_DWORD *)(cm_wkup_addr + 8) |= 0x40000u;
}
v10 = (char *)(PortSet_ptr[v4] + v8);
v11 = gpio_addr[*v10];
*(_DWORD *)(v11 + 336) |= *(_DWORD *)(PortIDSet_ptr[v4] + 4 * v8);
*(_DWORD *)(gpio_addr[*v10] + 340) = a3;
result = 0LL;
}
}
return result;
}

original_code:
int BBBIO_sys_Enable_Debouncing(unsigned int port ,unsigned int pin ,unsigned int GDB_time)
{
 volatile unsigned int* reg;
 int param_error=0;
 const unsigned int GPIO_CLKCTRL[] ={0xAC ,
         0xB0 ,
         0xB4};
        if (memh==0)
            param_error=1;
        if ((port<8) || (port>9))
            param_error=1;
        if ((pin<1) || (pin>46))
            param_error=1;
        if (PortSet_ptr[port][pin]<0)
            param_error=1;
 if(GDB_time <0 || GDB_time >255)
     param_error=1;
        if (param_error)
        {
            if (0) printf("BBBIO_sys_Enable_Debouncing : parameter error!\n");
            return -1 ;
 }
 port -=8 ;
 pin -=1 ;
 if(PortSet_ptr[port][pin]==0)
 {
     reg =(void*)cm_wkup_addr + 0x8;
            *reg |= 1 <<18;
 }
 else
 {
     reg =(void*)cm_per_addr + GPIO_CLKCTRL[PortSet_ptr[port][pin]-1] ;
     *reg |= 1 <<18;
 }
        reg = (void*)gpio_addr[PortSet_ptr[port][pin]] +0x150 ;
 *reg |= PortIDSet_ptr[port][pin] ;
 reg = (void*)gpio_addr[PortSet_ptr[port][pin]] +0x154 ;
 *reg = GDB_time ;
 return 0;
}

canonical_original_code:
int BBBIO_sys_Enable_Debouncing(unsigned int port, unsigned int pin, unsigned int GDB_time)
{
 unsigned int *reg;
 int param_error = 0;
 unsigned int GPIO_CLKCTRL[] = {0xAC ,
         0xB0 ,
         0xB4};
        if (memh==0)
            param_error=1;
        if ((port<8) || (port>9))
            param_error=1;
        if ((pin<1) || (pin>46))
            param_error=1;
        if (PortSet_ptr[port][pin]<0)
            param_error=1;
 if(GDB_time <0 || GDB_time >255)
     param_error=1;
        if (param_error)
        {
            if (0) printf("BBBIO_sys_Enable_Debouncing : parameter error!\n");
            return -1 ;
 }
 port -=8 ;
 pin -=1 ;
 if(PortSet_ptr[port][pin]==0)
 {
     reg =(void *)cm_wkup_addr + 0x8;
            *reg |= 1 <<18;
 }
 else
 {
     reg =(void *)cm_per_addr + GPIO_CLKCTRL[PortSet_ptr[port][pin]-1] ;
     *reg |= 1 <<18;
 }
        reg = (void *)gpio_addr[PortSet_ptr[port][pin]] +0x150 ;
 *reg |= PortIDSet_ptr[port][pin] ;
 reg = (void *)gpio_addr[PortSet_ptr[port][pin]] +0x154 ;
 *reg = GDB_time ;
 return 0;
}

variable_types:
pin
unsigned int


decompiled_code:
__int64 __fastcall BBBIO_sys_Disable_Debouncing(int a1, unsigned int a2, unsigned int a3)
{
int v4; // eax
_BOOL4 v5; // er8
unsigned int v6; // edx
char v7; // si
char *v8; // rsi
__int64 v9; // rdi
__int64 result; // rax
_DWORD *v11; // rsi
int v12[3]; // [rsp+0h] [rbp-Ch]

v12[0] = 172;
v12[1] = 176;
v12[2] = 180;
v4 = a1 - 8;
v5 = 1;
if ( (unsigned int)(a1 - 8) <= 1 )
v5 = memh == 0;
v6 = a2 - 1;
if ( a2 - 1 > 0x2D || *(char *)(PortSet_ptr[a1] + a2) < 0 || v5 || a3 > 0xFF )
return 0xFFFFFFFFLL;
v7 = *(_BYTE *)(PortSet_ptr[v4] + v6);
if ( v7 )
{
v11 = (_DWORD *)(cm_per_addr + (unsigned int)v12[v7 - 1]);
*v11 &= 0xFFF80000;
}
else
{
*(_DWORD *)(cm_wkup_addr + 8) &= 0xFFF80000;
}
v8 = (char *)(PortSet_ptr[v4] + v6);
v9 = gpio_addr[*v8];
*(_DWORD *)(v9 + 336) &= ~*(_DWORD *)(PortIDSet_ptr[v4] + 4LL * v6);
result = gpio_addr[*v8];
*(_DWORD *)(result + 340) = a3;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(int a1, unsigned int a2, unsigned int a3)
{
int v4; // eax
_BOOL4 v5; // er8
unsigned int v6; // edx
char v7; // si
char *v8; // rsi
__int64 v9; // rdi
__int64 result; // rax
_DWORD *v11; // rsi
int v12[3]; // [rsp+0h] [rbp-Ch]

v12[0] = 172;
v12[1] = 176;
v12[2] = 180;
v4 = a1 - 8;
v5 = 1;
if ( (unsigned int)(a1 - 8) <= 1 )
v5 = memh == 0;
v6 = a2 - 1;
if ( a2 - 1 > 0x2D || *(char *)(PortSet_ptr[a1] + a2) < 0 || v5 || a3 > 0xFF )
return 0xFFFFFFFFLL;
v7 = *(_BYTE *)(PortSet_ptr[v4] + v6);
if ( v7 )
{
v11 = (_DWORD *)(cm_per_addr + (unsigned int)v12[v7 - 1]);
*v11 &= 0xFFF80000;
}
else
{
*(_DWORD *)(cm_wkup_addr + 8) &= 0xFFF80000;
}
v8 = (char *)(PortSet_ptr[v4] + v6);
v9 = gpio_addr[*v8];
*(_DWORD *)(v9 + 336) &= ~*(_DWORD *)(PortIDSet_ptr[v4] + 4LL * v6);
result = gpio_addr[*v8];
*(_DWORD *)(result + 340) = a3;
return result;
}

original_code:
int BBBIO_sys_Disable_Debouncing(unsigned int port ,unsigned int pin ,unsigned int GDB_time)
{
        volatile unsigned int* reg;
        int param_error=0;
        const unsigned int GPIO_CLKCTRL[] ={0xAC ,
                                            0xB0 ,
                                            0xB4};
        if (memh==0)
            param_error=1;
        if ((port<8) || (port>9))
            param_error=1;
        if ((pin<1) || (pin>46))
            param_error=1;
        if (PortSet_ptr[port][pin]<0)
            param_error=1;
        if(GDB_time <0 || GDB_time >255)
            param_error=1;
        if (param_error)
        {
            if (0) printf("BBBIO_sys_Disable_Debouncing : parameter error!\n");
            return -1 ;
        }
        port -=8 ;
        pin -=1 ;
        if(PortSet_ptr[port][pin]==0)
        {
            reg =(void*)cm_wkup_addr + 0x8;
            *reg &= ~1 <<18;
        }
        else
        {
            reg =(void*)cm_per_addr + GPIO_CLKCTRL[PortSet_ptr[port][pin]-1] ;
            *reg &= ~1 <<18;
        }
        reg = (void*)gpio_addr[PortSet_ptr[port][pin]] +0x150 ;
        *reg &= ~PortIDSet_ptr[port][pin] ;
       reg = (void *)gpio_addr[PortSet_ptr[port][pin]] +0x154 ;
       *reg = GDB_time ;
}

canonical_original_code:
int BBBIO_sys_Disable_Debouncing(unsigned int port, unsigned int pin, unsigned int GDB_time)
{
        unsigned int *reg;
        int param_error = 0;
        unsigned int GPIO_CLKCTRL[] = {0xAC ,
                                            0xB0 ,
                                            0xB4};
        if (memh==0)
            param_error=1;
        if ((port<8) || (port>9))
            param_error=1;
        if ((pin<1) || (pin>46))
            param_error=1;
        if (PortSet_ptr[port][pin]<0)
            param_error=1;
        if(GDB_time <0 || GDB_time >255)
            param_error=1;
        if (param_error)
        {
            if (0) printf("BBBIO_sys_Disable_Debouncing : parameter error!\n");
            return -1 ;
        }
        port -=8 ;
        pin -=1 ;
        if(PortSet_ptr[port][pin]==0)
        {
            reg =(void *)cm_wkup_addr + 0x8;
            *reg &= ~1 <<18;
        }
        else
        {
            reg =(void *)cm_per_addr + GPIO_CLKCTRL[PortSet_ptr[port][pin]-1] ;
            *reg &= ~1 <<18;
        }
        reg = (void *)gpio_addr[PortSet_ptr[port][pin]] +0x150 ;
        *reg &= ~PortIDSet_ptr[port][pin] ;
       reg = (void *)gpio_addr[PortSet_ptr[port][pin]] +0x154 ;
       *reg = GDB_time ;
}


decompiled_code:
__int64 __fastcall BBBIO_sys_Enable_GPIO(unsigned int a1)
{
__int64 result; // rax

if ( a1 > 3 || !cm_per_addr )
return 0LL;
if ( a1 == 2 )
{
*(_DWORD *)(cm_per_addr + 176) |= 2u;
result = 1LL;
}
else if ( a1 == 3 )
{
*(_DWORD *)(cm_per_addr + 180) |= 2u;
result = 1LL;
}
else
{
if ( a1 )
*(_DWORD *)(cm_per_addr + 172) |= 2u;
else
*(_DWORD *)(cm_wkup_addr + 8) |= 2u;
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(unsigned int a1)
{
__int64 result; // rax

if ( a1 > 3 || !cm_per_addr )
return 0LL;
if ( a1 == 2 )
{
*(_DWORD *)(cm_per_addr + 176) |= 2u;
result = 1LL;
}
else if ( a1 == 3 )
{
*(_DWORD *)(cm_per_addr + 180) |= 2u;
result = 1LL;
}
else
{
if ( a1 )
*(_DWORD *)(cm_per_addr + 172) |= 2u;
else
*(_DWORD *)(cm_wkup_addr + 8) |= 2u;
result = 1LL;
}
return result;
}

original_code:
int BBBIO_sys_Enable_GPIO(unsigned int gpio)
{
 int param_error=0;
 volatile unsigned int* reg;
 if (cm_per_addr==0)
  param_error=1;
 if (gpio <0 || gpio >3)
  param_error=1;
 if (param_error)
 {
  if (0) printf("BBBIO_sys_Enable_GPIO: parameter error!\n");
  return 0;
 }
 switch(gpio)
 {
  case 0 :
  {
   reg =(void*)cm_wkup_addr + 0x8;
   *reg |= 0x2 ;
  }
  break ;
  case 1 :
  {
   reg =(void*)cm_per_addr + 0xAC;
   *reg |= 0x2 ;
  }
  break ;
  case 2 :
  {
   reg =(void*)cm_per_addr + 0xB0;
   *reg |= 0x2 ;
  }
  break ;
  case 3 :
  {
   reg =(void*)cm_per_addr + 0xB4;
   *reg |= 0x2 ;
  }
  break ;
  default :
  {
   return 0 ;
  }
  break ;
 }
 return 1 ;
}

canonical_original_code:
int BBBIO_sys_Enable_GPIO(unsigned int gpio)
{
 int param_error = 0;
 unsigned int *reg;
 if (cm_per_addr==0)
  param_error=1;
 if (gpio <0 || gpio >3)
  param_error=1;
 if (param_error)
 {
  if (0) printf("BBBIO_sys_Enable_GPIO: parameter error!\n");
  return 0;
 }
 switch(gpio)
 {
  case 0 :
  {
   reg =(void *)cm_wkup_addr + 0x8;
   *reg |= 0x2 ;
  }
  break ;
  case 1 :
  {
   reg =(void *)cm_per_addr + 0xAC;
   *reg |= 0x2 ;
  }
  break ;
  case 2 :
  {
   reg =(void *)cm_per_addr + 0xB0;
   *reg |= 0x2 ;
  }
  break ;
  case 3 :
  {
   reg =(void *)cm_per_addr + 0xB4;
   *reg |= 0x2 ;
  }
  break ;
  default :
  {
   return 0 ;
  }
  break ;
 }
 return 1 ;
}

variable_types:
gpio
unsigned int


decompiled_code:
__int64 __fastcall BBBIO_sys_Disable_GPIO(unsigned int a1)
{
__int64 result; // rax

if ( a1 > 3 || !cm_per_addr )
return 0LL;
if ( a1 == 2 )
{
*(_DWORD *)(cm_per_addr + 176) &= 0xFFFFFFFD;
result = 1LL;
}
else if ( a1 == 3 )
{
*(_DWORD *)(cm_per_addr + 180) &= 0xFFFFFFFD;
result = 1LL;
}
else
{
if ( a1 )
*(_DWORD *)(cm_per_addr + 172) &= 0xFFFFFFFD;
else
*(_DWORD *)(cm_wkup_addr + 8) &= 2u;
result = 1LL;
}
return result;
}

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

if ( a1 > 3 || !cm_per_addr )
return 0LL;
if ( a1 == 2 )
{
*(_DWORD *)(cm_per_addr + 176) &= 0xFFFFFFFD;
result = 1LL;
}
else if ( a1 == 3 )
{
*(_DWORD *)(cm_per_addr + 180) &= 0xFFFFFFFD;
result = 1LL;
}
else
{
if ( a1 )
*(_DWORD *)(cm_per_addr + 172) &= 0xFFFFFFFD;
else
*(_DWORD *)(cm_wkup_addr + 8) &= 2u;
result = 1LL;
}
return result;
}

original_code:
int BBBIO_sys_Disable_GPIO(unsigned int gpio)
{
 int param_error=0;
 volatile unsigned int* reg;
 if (cm_per_addr==0)
  param_error=1;
 if (gpio <0 || gpio >3)
  param_error=1;
 if (param_error)
 {
  if (0) printf("BBBIO_sys_Disable_GPIO: parameter error!\n");
  return 0;
 }
 switch(gpio)
 {
  case 0 :
  {
   reg =(void*)cm_wkup_addr + 0x8;
                        *reg &= 0x2 ;
  }
  break ;
  case 1 :
  {
   reg =(void*)cm_per_addr + 0xAC;
   *reg &= ~0x2 ;
  }
  break ;
  case 2 :
  {
   reg =(void*)cm_per_addr + 0xB0;
   *reg &= ~0x2 ;
  }
  break ;
  case 3 :
  {
   reg =(void*)cm_per_addr + 0xB4;
   *reg &= ~0x2 ;
  }
  break ;
  default :
  {
   return 0 ;
  }
  break ;
 }
 return 1 ;
}

canonical_original_code:
int BBBIO_sys_Disable_GPIO(unsigned int gpio)
{
 int param_error = 0;
 unsigned int *reg;
 if (cm_per_addr==0)
  param_error=1;
 if (gpio <0 || gpio >3)
  param_error=1;
 if (param_error)
 {
  if (0) printf("BBBIO_sys_Disable_GPIO: parameter error!\n");
  return 0;
 }
 switch(gpio)
 {
  case 0 :
  {
   reg =(void *)cm_wkup_addr + 0x8;
                        *reg &= 0x2 ;
  }
  break ;
  case 1 :
  {
   reg =(void *)cm_per_addr + 0xAC;
   *reg &= ~0x2 ;
  }
  break ;
  case 2 :
  {
   reg =(void *)cm_per_addr + 0xB0;
   *reg &= ~0x2 ;
  }
  break ;
  case 3 :
  {
   reg =(void *)cm_per_addr + 0xB4;
   *reg &= ~0x2 ;
  }
  break ;
  default :
  {
   return 0 ;
  }
  break ;
 }
 return 1 ;
}


decompiled_code:
__int64 __fastcall BBBIO_GPIO_set_dir(unsigned int a1, int a2, int a3)
{
__int64 result; // rax
__int64 v4; // rax

result = 0xFFFFFFFFLL;
if ( a1 <= 3 )
{
if ( a3 | a2 && memh )
{
v4 = gpio_addr[a1];
*(_DWORD *)(v4 + 308) &= ~a3;
*(_DWORD *)(v4 + 308) |= a2;
result = 0LL;
}
else
{
result = 0xFFFFFFFFLL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func10(unsigned int a1, int a2, int a3)
{
__int64 result; // rax
__int64 v4; // rax

result = 0xFFFFFFFFLL;
if ( a1 <= 3 )
{
if ( a3 | a2 && memh )
{
v4 = gpio_addr[a1];
*(_DWORD *)(v4 + 308) &= ~a3;
*(_DWORD *)(v4 + 308) |= a2;
result = 0LL;
}
else
{
result = 0xFFFFFFFFLL;
}
}
return result;
}

original_code:
int
BBBIO_GPIO_set_dir(unsigned int gpio, unsigned int inset , unsigned int outset)
{
        int i;
        int param_error=0;
        volatile unsigned int* reg;
        if (memh==0)
                param_error=1;
        if (gpio <0 || gpio >3)
                param_error=1;
        if (inset==0 && outset==0)
                param_error=1;
        if (param_error)
        {
                if (0) printf("BBBIO_GPIO_set_dir: parameter error!\n");
                return(-1);
        }
        reg=(void*)gpio_addr[gpio] +0x134;
        *reg &= ~outset ;
        *reg |= inset ;
        return 0;
}

canonical_original_code:
int BBBIO_GPIO_set_dir(unsigned int gpio, unsigned int inset, unsigned int outset)
{
        int i;
        int param_error = 0;
        unsigned int *reg;
        if (memh==0)
                param_error=1;
        if (gpio <0 || gpio >3)
                param_error=1;
        if (inset==0 && outset==0)
                param_error=1;
        if (param_error)
        {
                if (0) printf("BBBIO_GPIO_set_dir: parameter error!\n");
                return(-1);
        }
        reg=(void *)gpio_addr[gpio] +0x134;
        *reg &= ~outset ;
        *reg |= inset ;
        return 0;
}

variable_types:
inset
unsigned int

variable_types:
outset
unsigned int


original_code:
unsigned int
col565(rgb_t* rgb)
{
 unsigned int r,g,b;
 r=(unsigned int) rgb->r;
 g=(unsigned int) rgb->g;
 b=(unsigned int) rgb->b;
  return ((r & 0xF8) << 8) | ((g & 0xFC) << 3) | (b >> 3);
}

canonical_original_code:
unsigned int col565(struct rgb_s *rgb)
{
 unsigned int r; unsigned int g; unsigned int b;
 r=(unsigned int) rgb->r;
 g=(unsigned int) rgb->g;
 b=(unsigned int) rgb->b;
  return ((r & 0xF8) << 8) | ((g & 0xFC) << 3) | (b >> 3);
}

variable_types: struct rgb_s { unsigned char r; unsigned char g; unsigned char b; } *

variable_types:
r
unsigned int

variable_types:
g
unsigned int

variable_types:
b
unsigned int

return_type: unsigned int


repo: shackspace/LOTUS

original_code:
int OTUS_dumpMessageToConsole(const OTUSMsg* msg)
{
    printf("\n\n\n");
    printf("MSG: %0.4x/%0.2x  TS:%0.8x\n",
            msg->magic,
            msg->msgCounter,
            msg->timestamp
            );
    printf("Jog0:%0.4x/%5d  Jog1:%0.2x Jog2:%0.2x Jog3:%0.2x Jog4:%0.2x\n",
            msg->jog0Rot,
            msg->jog0Speed,
            msg->jog1Rot,
            msg->jog2Rot,
            msg->jog3Rot,
            msg->jog4Rot
            );
    printf(" DeckA: G:%0.4x  H:%0.4x M:%0.4x L:%0.4x P:%0.4x  %s\n"
           " DeckB: G:%0.4x  H:%0.4x M:%0.4x L:%0.4x P:%0.4x  %s\n"
           "   XFader:%0.4x     Gain:%0.4x\n",
           msg->rotAGain,
           msg->rotAHigh,
           msg->rotAMid,
           msg->rotALow,
           msg->pitchA,
           msg->status == 0 ? "(active)" : "",
           msg->rotBGain,
           msg->rotBHigh,
           msg->rotBMid,
           msg->rotBLow,
           msg->pitchB,
           msg->status == 0 ? "" : "(active)",
           msg->rotXFader,
           msg->rotMaster
           );
    printf("PAD: X:%0.4x Y:%0.4x\n",
            msg->padX,
            msg->padY
            );
    printf("Buttons: %0.8x  Status: %0.4x\n",
            msg->buttons,
            msg->status
            );
    const int offset = strlen("OTUS_BUTTON_");
    for(OTUSButton* button = OTUSButtonMap; button->name != ((void *)0); ++button)
    {
        if(msg->buttons & button->id)
            printf("%s ",button->name+offset);
    }
    printf("\n");
    return OTUS_ERROR_OK;
}

canonical_original_code:
int OTUS_dumpMessageToConsole(struct OTUSMsg_ *msg)
{
    printf("\n\n\n");
    printf("MSG: %0.4x/%0.2x  TS:%0.8x\n",
            msg->magic,
            msg->msgCounter,
            msg->timestamp
            );
    printf("Jog0:%0.4x/%5d  Jog1:%0.2x Jog2:%0.2x Jog3:%0.2x Jog4:%0.2x\n",
            msg->jog0Rot,
            msg->jog0Speed,
            msg->jog1Rot,
            msg->jog2Rot,
            msg->jog3Rot,
            msg->jog4Rot
            );
    printf(" DeckA: G:%0.4x  H:%0.4x M:%0.4x L:%0.4x P:%0.4x  %s\n"
           " DeckB: G:%0.4x  H:%0.4x M:%0.4x L:%0.4x P:%0.4x  %s\n"
           "   XFader:%0.4x     Gain:%0.4x\n",
           msg->rotAGain,
           msg->rotAHigh,
           msg->rotAMid,
           msg->rotALow,
           msg->pitchA,
           msg->status == 0 ? "(active)" : "",
           msg->rotBGain,
           msg->rotBHigh,
           msg->rotBMid,
           msg->rotBLow,
           msg->pitchB,
           msg->status == 0 ? "" : "(active)",
           msg->rotXFader,
           msg->rotMaster
           );
    printf("PAD: X:%0.4x Y:%0.4x\n",
            msg->padX,
            msg->padY
            );
    printf("Buttons: %0.8x  Status: %0.4x\n",
            msg->buttons,
            msg->status
            );
    int offset = strlen("OTUS_BUTTON_");
    for(struct OTUSButton_ *button = OTUSButtonMap; button->name != ((void *)0); ++button)
    {
        if(msg->buttons & button->id)
            printf("%s ",button->name+offset);
    }
    printf("\n");
    return OTUS_ERROR_OK;
}

variable_types: struct OTUSMsg_ { unsigned short magic; unsigned short jog0Rot; short jog0Speed; unsigned int timestamp; unsigned int _0a_0d_reserved; unsigned char jog2Rot; unsigned char jog4Rot; unsigned char jog3Rot; unsigned char jog1Rot; unsigned short rotAGain; unsigned short rotBGain; unsigned short rotAHigh; unsigned short rotBHigh; unsigned short rotAMid; unsigned short rotBMid; unsigned short rotALow; unsigned short rotBLow; unsigned short rotXFader; unsigned short rotMaster; unsigned short padY; unsigned short padX; unsigned short pitchA; unsigned short pitchB; unsigned int buttons; unsigned char filler; unsigned char msgCounter; unsigned short status; unsigned char _36_reserved; unsigned char _37_reserved; unsigned int _38_3b_reserved; unsigned int _3c_3f_reserved; } *

variable_types: offset int

variable_types: struct OTUSButton_ { unsigned int id; char *name; } *


repo: shadowpho/Lisa

decompiled_code:
__int64 load_lib()
{
char *v1; // rax

test_handle = dlopen(IPC_LIBRARY_PATH, 1);
if ( test_handle )
return 0LL;
v1 = dlerror();
puts(v1);
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 func7()
{
char *v1; // rax

test_handle = dlopen(IPC_LIBRARY_PATH, 1);
if ( test_handle )
return 0LL;
v1 = dlerror();
puts(v1);
return 0xFFFFFFFFLL;
}

original_code:
int load_lib(char* path)
{
    test_handle = dlopen(IPC_LIBRARY_PATH,0x00001|0);
    if(!test_handle)
    {
        printf("%s\n",dlerror());
        return -1;
    }
    return 0;
}

canonical_original_code:
int load_lib(char *path)
{
    test_handle = dlopen(IPC_LIBRARY_PATH,0x00001|0);
    if(!test_handle)
    {
        printf("%s\n",dlerror());
        return -1;
    }
    return 0;
}

variable_types:
path
char *


decompiled_code:
__int64 resolve_syms()
{
char *v0; // rax

IPC_init = (__int64)dlsym(test_handle, "IPC_init");
v0 = dlerror();
dl_error = (__int64)v0;
if ( v0 )
goto LABEL_14;
if ( !IPC_init )
return 0xFFFFFFFFLL;
printf("loaded %s,addr %p\n", "IPC_init", (const void *)IPC_init);
IPC_close = (__int64)dlsym(test_handle, "IPC_close");
v0 = dlerror();
dl_error = (__int64)v0;
if ( v0 )
goto LABEL_14;
if ( !IPC_close )
return 0xFFFFFFFFLL;
printf("loaded %s,addr %p\n", "IPC_close", (const void *)IPC_close);
IPC_peek = (__int64)dlsym(test_handle, "IPC_peek");
v0 = dlerror();
dl_error = (__int64)v0;
if ( v0 )
goto LABEL_14;
if ( !IPC_peek )
return 0xFFFFFFFFLL;
printf("loaded %s,addr %p\n", "IPC_peek", (const void *)IPC_peek);
IPC_recv = (__int64)dlsym(test_handle, "IPC_recv");
v0 = dlerror();
dl_error = (__int64)v0;
if ( v0 )
goto LABEL_14;
if ( !IPC_recv )
return 0xFFFFFFFFLL;
printf("loaded %s,addr %p\n", "IPC_recv", (const void *)IPC_recv);
IPC_send = (__int64)dlsym(test_handle, "IPC_send");
v0 = dlerror();
dl_error = (__int64)v0;
if ( v0 )
goto LABEL_14;
if ( !IPC_send )
return 0xFFFFFFFFLL;
printf("loaded %s,addr %p\n", "IPC_send", (const void *)IPC_send);
get_version = (__int64)dlsym(test_handle, "get_version");
v0 = dlerror();
dl_error = (__int64)v0;
if ( v0 )
{
LABEL_14:
printf("DL_ERROR: %s\n", v0);
return 0xFFFFFFFFLL;
}
if ( !get_version )
return 0xFFFFFFFFLL;
printf("loaded %s,addr %p\n", "get_version", (const void *)get_version);
return 0LL;
}

canonical_decompiled_code:
__int64 func8()
{
char *v0; // rax

IPC_init = (__int64)dlsym(test_handle, "IPC_init");
v0 = dlerror();
dl_error = (__int64)v0;
if ( v0 )
goto LABEL_14;
if ( !IPC_init )
return 0xFFFFFFFFLL;
printf("loaded %s,addr %p\n", "IPC_init", (const void *)IPC_init);
IPC_close = (__int64)dlsym(test_handle, "IPC_close");
v0 = dlerror();
dl_error = (__int64)v0;
if ( v0 )
goto LABEL_14;
if ( !IPC_close )
return 0xFFFFFFFFLL;
printf("loaded %s,addr %p\n", "IPC_close", (const void *)IPC_close);
IPC_peek = (__int64)dlsym(test_handle, "IPC_peek");
v0 = dlerror();
dl_error = (__int64)v0;
if ( v0 )
goto LABEL_14;
if ( !IPC_peek )
return 0xFFFFFFFFLL;
printf("loaded %s,addr %p\n", "IPC_peek", (const void *)IPC_peek);
IPC_recv = (__int64)dlsym(test_handle, "IPC_recv");
v0 = dlerror();
dl_error = (__int64)v0;
if ( v0 )
goto LABEL_14;
if ( !IPC_recv )
return 0xFFFFFFFFLL;
printf("loaded %s,addr %p\n", "IPC_recv", (const void *)IPC_recv);
IPC_send = (__int64)dlsym(test_handle, "IPC_send");
v0 = dlerror();
dl_error = (__int64)v0;
if ( v0 )
goto LABEL_14;
if ( !IPC_send )
return 0xFFFFFFFFLL;
printf("loaded %s,addr %p\n", "IPC_send", (const void *)IPC_send);
get_version = (__int64)dlsym(test_handle, "get_version");
v0 = dlerror();
dl_error = (__int64)v0;
if ( v0 )
{
LABEL_14:
printf("DL_ERROR: %s\n", v0);
return 0xFFFFFFFFLL;
}
if ( !get_version )
return 0xFFFFFFFFLL;
printf("loaded %s,addr %p\n", "get_version", (const void *)get_version);
return 0LL;
}

original_code:
int resolve_syms()
{
    do {(*(int**)(&IPC_init)=dlsym(test_handle,"IPC_init")); dl_error = dlerror(); if(dl_error!=((void *)0)) { printf("DL_ERROR: %s\n",dl_error); return -1; } if(IPC_init==((void *)0)) return -1; printf("loaded %s,addr %p\n","IPC_init",(int*)IPC_init); }while(0);;
    do {(*(int**)(&IPC_close)=dlsym(test_handle,"IPC_close")); dl_error = dlerror(); if(dl_error!=((void *)0)) { printf("DL_ERROR: %s\n",dl_error); return -1; } if(IPC_close==((void *)0)) return -1; printf("loaded %s,addr %p\n","IPC_close",(int*)IPC_close); }while(0);;
    do {(*(int**)(&IPC_peek)=dlsym(test_handle,"IPC_peek")); dl_error = dlerror(); if(dl_error!=((void *)0)) { printf("DL_ERROR: %s\n",dl_error); return -1; } if(IPC_peek==((void *)0)) return -1; printf("loaded %s,addr %p\n","IPC_peek",(int*)IPC_peek); }while(0);;
    do {(*(int**)(&IPC_recv)=dlsym(test_handle,"IPC_recv")); dl_error = dlerror(); if(dl_error!=((void *)0)) { printf("DL_ERROR: %s\n",dl_error); return -1; } if(IPC_recv==((void *)0)) return -1; printf("loaded %s,addr %p\n","IPC_recv",(int*)IPC_recv); }while(0);;
    do {(*(int**)(&IPC_send)=dlsym(test_handle,"IPC_send")); dl_error = dlerror(); if(dl_error!=((void *)0)) { printf("DL_ERROR: %s\n",dl_error); return -1; } if(IPC_send==((void *)0)) return -1; printf("loaded %s,addr %p\n","IPC_send",(int*)IPC_send); }while(0);;
    do {(*(char***)(&get_version)=dlsym(test_handle,"get_version")); dl_error = dlerror(); if(dl_error!=((void *)0)) { printf("DL_ERROR: %s\n",dl_error); return -1; } if(get_version==((void *)0)) return -1; printf("loaded %s,addr %p\n","get_version",(int*)get_version); }while(0);;
    return 0;
}

canonical_original_code:
int resolve_syms()
{
    do {(*(int **)(&IPC_init)=dlsym(test_handle,"IPC_init")); dl_error = dlerror(); if(dl_error!=((void *)0)) { printf("DL_ERROR: %s\n",dl_error); return -1; } if(IPC_init==((void *)0)) return -1; printf("loaded %s,addr %p\n","IPC_init",(int *)IPC_init); }while(0);;
    do {(*(int **)(&IPC_close)=dlsym(test_handle,"IPC_close")); dl_error = dlerror(); if(dl_error!=((void *)0)) { printf("DL_ERROR: %s\n",dl_error); return -1; } if(IPC_close==((void *)0)) return -1; printf("loaded %s,addr %p\n","IPC_close",(int *)IPC_close); }while(0);;
    do {(*(int **)(&IPC_peek)=dlsym(test_handle,"IPC_peek")); dl_error = dlerror(); if(dl_error!=((void *)0)) { printf("DL_ERROR: %s\n",dl_error); return -1; } if(IPC_peek==((void *)0)) return -1; printf("loaded %s,addr %p\n","IPC_peek",(int *)IPC_peek); }while(0);;
    do {(*(int **)(&IPC_recv)=dlsym(test_handle,"IPC_recv")); dl_error = dlerror(); if(dl_error!=((void *)0)) { printf("DL_ERROR: %s\n",dl_error); return -1; } if(IPC_recv==((void *)0)) return -1; printf("loaded %s,addr %p\n","IPC_recv",(int *)IPC_recv); }while(0);;
    do {(*(int **)(&IPC_send)=dlsym(test_handle,"IPC_send")); dl_error = dlerror(); if(dl_error!=((void *)0)) { printf("DL_ERROR: %s\n",dl_error); return -1; } if(IPC_send==((void *)0)) return -1; printf("loaded %s,addr %p\n","IPC_send",(int *)IPC_send); }while(0);;
    do {(*(char ***)(&get_version)=dlsym(test_handle,"get_version")); dl_error = dlerror(); if(dl_error!=((void *)0)) { printf("DL_ERROR: %s\n",dl_error); return -1; } if(get_version==((void *)0)) return -1; printf("loaded %s,addr %p\n","get_version",(int *)get_version); }while(0);;
    return 0;
}


decompiled_code:
__int64 close_lib()
{
unsigned int v0; // ebx

v0 = IPC_close();
dlclose(test_handle);
if ( v0 )
{
perror("closing");
v0 = -1;
}
return v0;
}

canonical_decompiled_code:
__int64 func9()
{
unsigned int v0; // ebx

v0 = IPC_close();
dlclose(test_handle);
if ( v0 )
{
perror("closing");
v0 = -1;
}
return v0;
}

original_code:
int close_lib()
{
    int status = IPC_close();
    dlclose(test_handle);
    if(status!=0) {
        perror("closing");
        return -1;
    }
    return 0;
}

variable_types: status int


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rbx
__int64 v4; // rbx
const char *v5; // rax
__int64 v6; // rbx
__int64 v7; // rbx
__int64 v8; // rbx
__int64 v9; // rbx
__int64 v10; // rbx

v3 = (unsigned int)load_lib(IPC_LIBRARY_PATH, argv, envp);
printf("%s = %d\n", "load library", v3);
if ( (_DWORD)v3 )
{
printf("Error at line: %d, error:\n", 75LL);
perror("load library");
LODWORD(v10) = -1;
}
else
{
v4 = (unsigned int)resolve_syms();
printf("%s = %d\n", "resolve symbols", v4);
if ( (_DWORD)v4 )
{
printf("Error at line: %d, error:\n", 78LL);
perror("resolve symbols");
LODWORD(v10) = -1;
}
else
{
v5 = (const char *)get_version();
printf("Library version tested: %s\n", v5);
v6 = (unsigned int)IPC_init(478LL, 479LL);
printf("%s = %d\n", "init ipc", v6);
if ( (_DWORD)v6 )
{
printf("Error at line: %d, error:\n", 83LL);
perror("init ipc");
LODWORD(v10) = -1;
}
else
{
v7 = (unsigned int)IPC_send(0LL, 0LL, 0LL, 0LL);
printf("%s = %d\n", "send", v7);
if ( (_DWORD)v7 )
{
printf("Error at line: %d, error:\n", 86LL);
perror("send");
LODWORD(v10) = -1;
}
else
{
v8 = (unsigned int)IPC_peek(0LL, 0LL);
printf("%s = %d\n", "peek", v8);
if ( (_DWORD)v8 )
{
printf("Error at line: %d, error:\n", 89LL);
perror("peek");
LODWORD(v10) = -1;
}
else
{
v9 = (unsigned int)IPC_recv(0LL, 0LL);
printf("%s = %d\n", "recv", v9);
if ( (_DWORD)v9 )
{
printf("Error at line: %d, error:\n", 92LL);
perror("recv");
LODWORD(v10) = -1;
}
else
{
v10 = (unsigned int)close_lib();
printf("%s = %d\n", "close lib", v10);
if ( (_DWORD)v10 )
{
printf("Error at line: %d, error:\n", 95LL);
perror("close lib");
LODWORD(v10) = -1;
}
else
{
puts("ALL GOOD!!!");
}
}
}
}
}
}
}
return v10;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rbx
__int64 v4; // rbx
const char *v5; // rax
__int64 v6; // rbx
__int64 v7; // rbx
__int64 v8; // rbx
__int64 v9; // rbx
__int64 v10; // rbx

v3 = (unsigned int)func7(IPC_LIBRARY_PATH, argv, envp);
printf("%s = %d\n", "load library", v3);
if ( (_DWORD)v3 )
{
printf("Error at line: %d, error:\n", 75LL);
perror("load library");
LODWORD(v10) = -1;
}
else
{
v4 = (unsigned int)func8();
printf("%s = %d\n", "resolve symbols", v4);
if ( (_DWORD)v4 )
{
printf("Error at line: %d, error:\n", 78LL);
perror("resolve symbols");
LODWORD(v10) = -1;
}
else
{
v5 = (const char *)get_version();
printf("Library version tested: %s\n", v5);
v6 = (unsigned int)IPC_init(478LL, 479LL);
printf("%s = %d\n", "init ipc", v6);
if ( (_DWORD)v6 )
{
printf("Error at line: %d, error:\n", 83LL);
perror("init ipc");
LODWORD(v10) = -1;
}
else
{
v7 = (unsigned int)IPC_send(0LL, 0LL, 0LL, 0LL);
printf("%s = %d\n", "send", v7);
if ( (_DWORD)v7 )
{
printf("Error at line: %d, error:\n", 86LL);
perror("send");
LODWORD(v10) = -1;
}
else
{
v8 = (unsigned int)IPC_peek(0LL, 0LL);
printf("%s = %d\n", "peek", v8);
if ( (_DWORD)v8 )
{
printf("Error at line: %d, error:\n", 89LL);
perror("peek");
LODWORD(v10) = -1;
}
else
{
v9 = (unsigned int)IPC_recv(0LL, 0LL);
printf("%s = %d\n", "recv", v9);
if ( (_DWORD)v9 )
{
printf("Error at line: %d, error:\n", 92LL);
perror("recv");
LODWORD(v10) = -1;
}
else
{
v10 = (unsigned int)func9();
printf("%s = %d\n", "close lib", v10);
if ( (_DWORD)v10 )
{
printf("Error at line: %d, error:\n", 95LL);
perror("close lib");
LODWORD(v10) = -1;
}
else
{
puts("ALL GOOD!!!");
}
}
}
}
}
}
}
return v10;
}

original_code:
int main(int argv, char* argc[])
{
    int status = load_lib(IPC_LIBRARY_PATH);
    do{ printf("%s = %d\n","load library",status); if((status)!=0){printf("Error at line: %d, error:\n",75);perror("load library");return -1;} }while(0);;
    status = resolve_syms();
    do{ printf("%s = %d\n","resolve symbols",status); if((status)!=0){printf("Error at line: %d, error:\n",78);perror("resolve symbols");return -1;} }while(0);;
    printf("Library version tested: %s\n", get_version());
    status = IPC_init(478,479);
    do{ printf("%s = %d\n","init ipc",status); if((status)!=0){printf("Error at line: %d, error:\n",83);perror("init ipc");return -1;} }while(0);;
    status = IPC_send(0, 0, ((void *)0), 0);
    do{ printf("%s = %d\n","send",status); if((status)!=0){printf("Error at line: %d, error:\n",86);perror("send");return -1;} }while(0);;
    status = IPC_peek(((void *)0), ((void *)0));
    do{ printf("%s = %d\n","peek",status); if((status)!=0){printf("Error at line: %d, error:\n",89);perror("peek");return -1;} }while(0);;
    status = IPC_recv(((void *)0), 0);
    do{ printf("%s = %d\n","recv",status); if((status)!=0){printf("Error at line: %d, error:\n",92);perror("recv");return -1;} }while(0);;
    status = close_lib();
    do{ printf("%s = %d\n","close lib",status); if((status)!=0){printf("Error at line: %d, error:\n",95);perror("close lib");return -1;} }while(0);;
    printf("%s","ALL GOOD!!!\n");
    return 0;
}

canonical_original_code:
int main(int argv, char *argc[])
{
    int status = load_lib(IPC_LIBRARY_PATH);
    do{ printf("%s = %d\n","load library",status); if((status)!=0){printf("Error at line: %d, error:\n",75);perror("load library");return -1;} }while(0);;
    status = resolve_syms();
    do{ printf("%s = %d\n","resolve symbols",status); if((status)!=0){printf("Error at line: %d, error:\n",78);perror("resolve symbols");return -1;} }while(0);;
    printf("Library version tested: %s\n", get_version());
    status = IPC_init(478,479);
    do{ printf("%s = %d\n","init ipc",status); if((status)!=0){printf("Error at line: %d, error:\n",83);perror("init ipc");return -1;} }while(0);;
    status = IPC_send(0, 0, ((void *)0), 0);
    do{ printf("%s = %d\n","send",status); if((status)!=0){printf("Error at line: %d, error:\n",86);perror("send");return -1;} }while(0);;
    status = IPC_peek(((void *)0), ((void *)0));
    do{ printf("%s = %d\n","peek",status); if((status)!=0){printf("Error at line: %d, error:\n",89);perror("peek");return -1;} }while(0);;
    status = IPC_recv(((void *)0), 0);
    do{ printf("%s = %d\n","recv",status); if((status)!=0){printf("Error at line: %d, error:\n",92);perror("recv");return -1;} }while(0);;
    status = close_lib();
    do{ printf("%s = %d\n","close lib",status); if((status)!=0){printf("Error at line: %d, error:\n",95);perror("close lib");return -1;} }while(0);;
    printf("%s","ALL GOOD!!!\n");
    return 0;
}

variable_types: argv int

variable_types:
argc
char *[]


repo: shailikapoor/fusegit

decompiled_code:
__int64 __fastcall hello_proc(__int64 a1, const char *a2, unsigned int a3)
{
printf("key: %d, arg: %s\n", a3, a2);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, const char *a2, unsigned int a3)
{
printf("key: %d, arg: %s\n", a3, a2);
return 1LL;
}

original_code:
int hello_proc(void *data, const char *arg, int key, struct fuse_args *outargs)
{
 printf("key: %d, arg: %s\n", key, arg);
 return 1;
}

canonical_original_code:
int hello_proc(void *data, char *arg, int key, struct fuse_args *outargs)
{
 printf("key: %d, arg: %s\n", key, arg);
 return 1;
}

variable_types:
data
void *

variable_types:
arg
char *

variable_types: key int

variable_types: struct fuse_args { int argc; char **argv; int allocated; } *


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
fuse_opt_parse();
return 0;
}

original_code:
int main(int argc, char *argv[])
{
 struct fuse_args args = { argc, argv, 0 };
 struct fuse_opt opts[] = {
  { "-b ", -1U, 1 },
  { "-r ", -1U, 2 },
  { "-o ", -1U, 3 },
  { ((void *)0), 0, 0 }
 };
 fuse_opt_parse(&args, ((void *)0), opts, hello_proc);
 return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: struct fuse_args { int argc; char **argv; int allocated; }

variable_types: struct fuse_opt { char *templ; unsigned long offset; int value; } []


decompiled_code:
__int64 fg_access()
{
debug_print("FG_ACCESS");
return 4294967258LL;
}

canonical_decompiled_code:
__int64 func0()
{
debug_print("FG_ACCESS");
return 4294967258LL;
}

original_code:
static int fg_access(const char *path, int mask)
{
 debug_print("FG_ACCESS");
        return -38;
}

canonical_original_code:
static int fg_access(char *path, int mask)
{
 debug_print("FG_ACCESS");
        return -38;
}

variable_types: mask int


decompiled_code:
__int64 fg_statfs()
{
debug_print("FG_STATFS");
return 4294967258LL;
}

canonical_decompiled_code:
__int64 func1()
{
debug_print("FG_STATFS");
return 4294967258LL;
}

original_code:
static int fg_statfs(const char *path, struct statvfs *stbuf)
{
 debug_print("FG_STATFS");
        return -38;
}

canonical_original_code:
static int fg_statfs(char *path, struct statvfs *stbuf)
{
 debug_print("FG_STATFS");
        return -38;
}

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


decompiled_code:
__int64 fg_symlink()
{
debug_print("FG_SYMLINK");
return 4294967258LL;
}

canonical_decompiled_code:
__int64 func2()
{
debug_print("FG_SYMLINK");
return 4294967258LL;
}

original_code:
static int fg_symlink(const char *from, const char *to)
{
 debug_print("FG_SYMLINK");
        return -38;
}

canonical_original_code:
static int fg_symlink(char *from, char *to)
{
 debug_print("FG_SYMLINK");
        return -38;
}

variable_types:
from
char *

variable_types:
to
char *


decompiled_code:
__int64 fg_mknod()
{
debug_print("FG_MKNOD");
return 4294967258LL;
}

canonical_decompiled_code:
__int64 func3()
{
debug_print("FG_MKNOD");
return 4294967258LL;
}

original_code:
static int fg_mknod(const char *path, mode_t mode, dev_t rdev)
{
 debug_print("FG_MKNOD");
        return -38;
}

canonical_original_code:
static int fg_mknod(char *path, unsigned int mode, unsigned long rdev)
{
 debug_print("FG_MKNOD");
        return -38;
}

variable_types:
mode
unsigned int

variable_types:
rdev
unsigned long


decompiled_code:
__int64 fg_readlink()
{
debug_print("FG_READLINK");
return 4294967258LL;
}

canonical_decompiled_code:
__int64 func4()
{
debug_print("FG_READLINK");
return 4294967258LL;
}

original_code:
static int fg_readlink(const char *path, char *buf, size_t size)
{
 debug_print("FG_READLINK");
        return -38;
}

canonical_original_code:
static int fg_readlink(char *path, char *buf, unsigned long size)
{
 debug_print("FG_READLINK");
        return -38;
}

variable_types:
path
char *

variable_types:
buf
char *

variable_types:
size
unsigned long


decompiled_code:
__int64 __fastcall fg_utimens(__int64 a1, __int64 a2)
{
debug_print("FG_UTIMENS");
return (unsigned int)((int)repo_update_time_ns(a1, a2) >> 31);
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, __int64 a2)
{
debug_print("FG_UTIMENS");
return (unsigned int)((int)repo_update_time_ns(a1, a2) >> 31);
}

original_code:
static int fg_utimens(const char *path, const struct timespec ts[2])
{
 debug_print("FG_UTIMENS");
 int r;
 if ((r = repo_update_time_ns(path, ts)) < 0)
  return -1;
        return 0;
}

canonical_original_code:
static int fg_utimens(char *path, struct timespec ts[2])
{
 debug_print("FG_UTIMENS");
 int r;
 if ((r = repo_update_time_ns(path, ts)) < 0)
  return -1;
        return 0;
}

variable_types: struct timespec { long tv_sec; long tv_nsec; } [2]

variable_types: r int


decompiled_code:
__int64 __fastcall fg_create(__int64 a1, unsigned int a2, __int64 a3)
{
debug_print("FG_CREATE");
return (unsigned int)((int)repo_create_file(a1, a2, a3 + 24) >> 31);
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, unsigned int a2, __int64 a3)
{
debug_print("FG_CREATE");
return (unsigned int)((int)repo_create_file(a1, a2, a3 + 24) >> 31);
}

original_code:
static int fg_create(const char *path, mode_t mode, struct fuse_file_info *fi)
{
 debug_print("FG_CREATE");
 int r;
 if ((r = repo_create_file(path, mode, &fi->fh)) < 0)
  return -1;
 return 0;
}

canonical_original_code:
static int fg_create(char *path, unsigned int mode, struct fuse_file_info *fi)
{
 debug_print("FG_CREATE");
 int r;
 if ((r = repo_create_file(path, mode, &fi->fh)) < 0)
  return -1;
 return 0;
}

variable_types: struct fuse_file_info { int flags; unsigned long fh_old; int writepage; unsigned int direct_io; unsigned int keep_cache; unsigned int flush; unsigned int nonseekable; unsigned int flock_release; unsigned int padding; unsigned long fh; unsigned long lock_owner; } *


decompiled_code:
__int64 __fastcall fg_readdir(__int64 a1, __int64 a2, void (__fastcall *a3)(__int64, const char *, _QWORD, _QWORD))
{
unsigned int v5; // ebx
__int64 v6; // rsi
unsigned int v7; // er13
__int64 v8; // rbx
int v10; // [rsp+4h] [rbp-434h] BYREF
void *ptr; // [rsp+8h] [rbp-430h] BYREF
__int64 v12[2]; // [rsp+10h] [rbp-428h] BYREF
char v13[1008]; // [rsp+20h] [rbp-418h] BYREF

debug_print("FG_READDIR");
v12[0] = 0LL;
v12[1] = 0LL;
memset(v13, 0, sizeof(v13));
v5 = 0;
while ( 1 )
{
v6 = v5++;
if ( !(unsigned int)get_next_component(a1, v6, v12) )
break;
if ( !(unsigned int)repo_path_exists(v12) )
return (unsigned int)-2;
}
v7 = repo_is_file(v12);
if ( v7 )
return (unsigned int)-2;
if ( (int)repo_get_children(&ptr, &v10, a1) < 0 )
return (unsigned int)-2;
a3(a2, ".", 0LL, 0LL);
a3(a2, "..", 0LL, 0LL);
if ( v10 > 0 )
{
v8 = 0LL;
do
a3(a2, *((const char **)ptr + 3 * v8++), 0LL, 0LL);
while ( v10 > (int)v8 );
}
free(ptr);
return v7;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, __int64 a2, void (__fastcall *a3)(__int64, const char *, _QWORD, _QWORD))
{
unsigned int v5; // ebx
__int64 v6; // rsi
unsigned int v7; // er13
__int64 v8; // rbx
int v10; // [rsp+4h] [rbp-434h] BYREF
void *ptr; // [rsp+8h] [rbp-430h] BYREF
__int64 v12[2]; // [rsp+10h] [rbp-428h] BYREF
char v13[1008]; // [rsp+20h] [rbp-418h] BYREF

debug_print("FG_READDIR");
v12[0] = 0LL;
v12[1] = 0LL;
memset(v13, 0, sizeof(v13));
v5 = 0;
while ( 1 )
{
v6 = v5++;
if ( !(unsigned int)get_next_component(a1, v6, v12) )
break;
if ( !(unsigned int)repo_path_exists(v12) )
return (unsigned int)-2;
}
v7 = repo_is_file(v12);
if ( v7 )
return (unsigned int)-2;
if ( (int)repo_get_children(&ptr, &v10, a1) < 0 )
return (unsigned int)-2;
a3(a2, ".", 0LL, 0LL);
a3(a2, "..", 0LL, 0LL);
if ( v10 > 0 )
{
v8 = 0LL;
do
a3(a2, *((const char **)ptr + 3 * v8++), 0LL, 0LL);
while ( v10 > (int)v8 );
}
free(ptr);
return v7;
}

original_code:
static int fg_readdir(const char *path, void *buf, fuse_fill_dir_t filler,
                         off_t offset, struct fuse_file_info *fi)
{
 debug_print("FG_READDIR");
 char name[1024] = "";
 int hier = 0;
 struct repo_file_node *children;
 int children_count;
 int i, r;
 while (get_next_component(path, hier++, name)) {
  if (!repo_path_exists(name))
   return -2;
 }
 if (repo_is_file(name))
  return -2;
 if ((r = repo_get_children(&children, &children_count, path)) < 0)
  return -2;
 filler(buf, ".", ((void *)0), 0);
 filler(buf, "..", ((void *)0), 0);
 for (i=0; i<children_count; i++) {
  filler(buf, children[i].name, ((void *)0), 0);
 }
 free(children);
        return 0;
}

canonical_original_code:
static int fg_readdir(char *path, void *buf, int (*filler)(void *buf, char *name, struct stat *stbuf, long off), long offset, struct fuse_file_info *fi)
{
 debug_print("FG_READDIR");
 char name[1024] = "";
 int hier = 0;
 struct repo_file_node *children;
 int children_count;
 int i; int r;
 while (get_next_component(path, hier++, name)) {
  if (!repo_path_exists(name))
   return -2;
 }
 if (repo_is_file(name))
  return -2;
 if ((r = repo_get_children(&children, &children_count, path)) < 0)
  return -2;
 filler(buf, ".", ((void *)0), 0);
 filler(buf, "..", ((void *)0), 0);
 for (i=0; i<children_count; i++) {
  filler(buf, children[i].name, ((void *)0), 0);
 }
 free(children);
        return 0;
}

variable_types:
buf
void *

variable_types: int (*)(void *buf, char *name, struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; struct timespec { long tv_sec; long tv_nsec; } st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; } *stbuf, long off)

variable_types: offset long

variable_types:
name
char [1024]

variable_types: hier int

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

variable_types: i int

user_defined_types: struct fuse_file_info { int flags; unsigned long fh_old; int writepage; unsigned int direct_io; unsigned int keep_cache; unsigned int flush; unsigned int nonseekable; unsigned int flock_release; unsigned int padding; unsigned long fh; unsigned long lock_owner; }

user_defined_types: struct repo_file_node { char *name; char *path; struct stat *stbuf; }

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


decompiled_code:
__int64 __fastcall fg_fsync(__int64 a1, unsigned int a2, __int64 a3)
{
debug_print("FG_FSYNC : metadata?%d", a2 == 0);
return ((int)repo_fsync(a1, *(_QWORD *)(a3 + 24), a2) >> 31) & 0xFFFFFFBD;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1, unsigned int a2, __int64 a3)
{
debug_print("FG_FSYNC : metadata?%d", a2 == 0);
return ((int)repo_fsync(a1, *(_QWORD *)(a3 + 24), a2) >> 31) & 0xFFFFFFBD;
}

original_code:
static int fg_fsync(const char *path, int isdatasync,
                       struct fuse_file_info *fi)
{
 debug_print("FG_FSYNC : metadata?%d", isdatasync?0:1);
 int r;
 if ((r = repo_fsync(path, fi->fh, isdatasync)) < 0)
  return -67;
        return 0;
}

canonical_original_code:
static int fg_fsync(char *path, int isdatasync, struct fuse_file_info *fi)
{
 debug_print("FG_FSYNC : metadata?%d", isdatasync?0:1);
 int r;
 if ((r = repo_fsync(path, fi->fh, isdatasync)) < 0)
  return -67;
        return 0;
}

variable_types: isdatasync int


decompiled_code:
__int64 __fastcall fg_release(__int64 a1, __int64 a2)
{
debug_print("FG_RELEASE");
return ((int)repo_release(a1, *(_QWORD *)(a2 + 24)) >> 31) & 0xFFFFFFBD;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1, __int64 a2)
{
debug_print("FG_RELEASE");
return ((int)repo_release(a1, *(_QWORD *)(a2 + 24)) >> 31) & 0xFFFFFFBD;
}

original_code:
static int fg_release(const char *path, struct fuse_file_info *fi)
{
 debug_print("FG_RELEASE");
 int r;
 if ((r = repo_release(path, fi->fh)) < 0)
  return -67;
        return 0;
}

canonical_original_code:
static int fg_release(char *path, struct fuse_file_info *fi)
{
 debug_print("FG_RELEASE");
 int r;
 if ((r = repo_release(path, fi->fh)) < 0)
  return -67;
        return 0;
}


decompiled_code:
__int64 __fastcall fg_flush(__int64 a1, __int64 a2)
{
debug_print("FG_FLUSH");
return ((int)repo_flush(a1, *(_QWORD *)(a2 + 24)) >> 31) & 0xFFFFFFBD;
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1, __int64 a2)
{
debug_print("FG_FLUSH");
return ((int)repo_flush(a1, *(_QWORD *)(a2 + 24)) >> 31) & 0xFFFFFFBD;
}

original_code:
static int fg_flush(const char *path, struct fuse_file_info *fi)
{
 debug_print("FG_FLUSH");
 int r;
 if ((r = repo_flush(path, fi->fh)) < 0)
  return -67;
 return 0;
}

canonical_original_code:
static int fg_flush(char *path, struct fuse_file_info *fi)
{
 debug_print("FG_FLUSH");
 int r;
 if ((r = repo_flush(path, fi->fh)) < 0)
  return -67;
 return 0;
}


decompiled_code:
__int64 __fastcall fg_write(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5)
{
debug_print("FG_WRITE");
return repo_write(a1, a2, a3, a4, *(_QWORD *)(a5 + 24));
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5)
{
debug_print("FG_WRITE");
return repo_write(a1, a2, a3, a4, *(_QWORD *)(a5 + 24));
}

original_code:
static int fg_write(const char *path, const char *buf, size_t size,
                       off_t offset, struct fuse_file_info *fi)
{
 debug_print("FG_WRITE");
        return repo_write(path, buf, size, offset, fi->fh);
}

canonical_original_code:
static int fg_write(char *path, char *buf, unsigned long size, long offset, struct fuse_file_info *fi)
{
 debug_print("FG_WRITE");
        return repo_write(path, buf, size, offset, fi->fh);
}


decompiled_code:
__int64 __fastcall fg_read(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5)
{
debug_print("FG_READ");
return repo_read(a1, a2, a3, a4, *(_QWORD *)(a5 + 24));
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5)
{
debug_print("FG_READ");
return repo_read(a1, a2, a3, a4, *(_QWORD *)(a5 + 24));
}

original_code:
static int fg_read(const char *path, char *buf, size_t size, off_t offset,
                      struct fuse_file_info *fi)
{
 debug_print("FG_READ");
 return repo_read(path, buf, size, offset, fi->fh);
}

canonical_original_code:
static int fg_read(char *path, char *buf, unsigned long size, long offset, struct fuse_file_info *fi)
{
 debug_print("FG_READ");
 return repo_read(path, buf, size, offset, fi->fh);
}


decompiled_code:
__int64 __fastcall fg_open(__int64 a1, __int64 a2)
{
debug_print("FG_OPEN");
return ((int)repo_open(a1, a2 + 24) >> 31) & 0xFFFFFFBD;
}

canonical_decompiled_code:
__int64 __fastcall func13(__int64 a1, __int64 a2)
{
debug_print("FG_OPEN");
return ((int)repo_open(a1, a2 + 24) >> 31) & 0xFFFFFFBD;
}

original_code:
static int fg_open(const char *path, struct fuse_file_info *fi)
{
 debug_print("FG_OPEN");
 int r;
 if ((r = repo_open(path, &fi->fh)) < 0)
  return -67;
 return 0;
}

canonical_original_code:
static int fg_open(char *path, struct fuse_file_info *fi)
{
 debug_print("FG_OPEN");
 int r;
 if ((r = repo_open(path, &fi->fh)) < 0)
  return -67;
 return 0;
}


decompiled_code:
__int64 __fastcall fg_truncate(__int64 a1, __int64 a2)
{
debug_print("FG_TRUNCATE");
return ((int)repo_truncate(a1, a2) >> 31) & 0xFFFFFFFE;
}

canonical_decompiled_code:
__int64 __fastcall func14(__int64 a1, __int64 a2)
{
debug_print("FG_TRUNCATE");
return ((int)repo_truncate(a1, a2) >> 31) & 0xFFFFFFFE;
}

original_code:
static int fg_truncate(const char *path, off_t size)
{
 debug_print("FG_TRUNCATE");
 int r;
 if ((r = repo_truncate(path, size)) < 0)
  return -2;
        return 0;
}

canonical_original_code:
static int fg_truncate(char *path, long size)
{
 debug_print("FG_TRUNCATE");
 int r;
 if ((r = repo_truncate(path, size)) < 0)
  return -2;
        return 0;
}

variable_types: size long


decompiled_code:
__int64 __fastcall fg_chown(__int64 a1, unsigned int a2, unsigned int a3)
{
debug_print("FG_CHOWN");
return ((int)repo_chown(a1, a2, a3) >> 31) & 0xFFFFFFBD;
}

canonical_decompiled_code:
__int64 __fastcall func15(__int64 a1, unsigned int a2, unsigned int a3)
{
debug_print("FG_CHOWN");
return ((int)repo_chown(a1, a2, a3) >> 31) & 0xFFFFFFBD;
}

original_code:
static int fg_chown(const char *path, uid_t uid, gid_t gid)
{
 debug_print("FG_CHOWN");
 int r;
 if ((r = repo_chown(path, uid, gid)) < 0)
  return -67;
        return 0;
}

canonical_original_code:
static int fg_chown(char *path, unsigned int uid, unsigned int gid)
{
 debug_print("FG_CHOWN");
 int r;
 if ((r = repo_chown(path, uid, gid)) < 0)
  return -67;
        return 0;
}

variable_types:
uid
unsigned int

variable_types:
gid
unsigned int


decompiled_code:
__int64 __fastcall fg_chmod(__int64 a1, unsigned int a2)
{
debug_print("FG_CHMOD");
return ((int)repo_chmod(a1, a2) >> 31) & 0xFFFFFFBD;
}

canonical_decompiled_code:
__int64 __fastcall func16(__int64 a1, unsigned int a2)
{
debug_print("FG_CHMOD");
return ((int)repo_chmod(a1, a2) >> 31) & 0xFFFFFFBD;
}

original_code:
static int fg_chmod(const char *path, mode_t mode)
{
 debug_print("FG_CHMOD");
 int r;
 if ((r = repo_chmod(path, mode)) < 0)
  return -67;
        return 0;
}

canonical_original_code:
static int fg_chmod(char *path, unsigned int mode)
{
 debug_print("FG_CHMOD");
 int r;
 if ((r = repo_chmod(path, mode)) < 0)
  return -67;
        return 0;
}

variable_types:
path
char *

variable_types:
mode
unsigned int


decompiled_code:
__int64 __fastcall fg_link(__int64 a1, __int64 a2)
{
int v2; // eax
unsigned int v3; // edx

debug_print("FG_LINK");
v2 = repo_link(a1, a2);
v3 = 0;
if ( v2 < 0 )
{
v3 = -67;
if ( v2 == -1 )
v3 = -2;
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func17(__int64 a1, __int64 a2)
{
int v2; // eax
unsigned int v3; // edx

debug_print("FG_LINK");
v2 = repo_link(a1, a2);
v3 = 0;
if ( v2 < 0 )
{
v3 = -67;
if ( v2 == -1 )
v3 = -2;
}
return v3;
}

original_code:
static int fg_link(const char *from, const char *to)
{
 debug_print("FG_LINK");
 int r;
 if ((r = repo_link(from, to)) < 0) {
  switch(r) {
  case -1:
   return -2;
  case -3:
   return -67;
  }
  return -67;
 }
 return 0;
}

canonical_original_code:
static int fg_link(char *from, char *to)
{
 debug_print("FG_LINK");
 int r;
 if ((r = repo_link(from, to)) < 0) {
  switch(r) {
  case -1:
   return -2;
  case -3:
   return -67;
  }
  return -67;
 }
 return 0;
}

variable_types:
from
char *

variable_types:
to
char *


decompiled_code:
__int64 __fastcall fg_rename(__int64 a1, __int64 a2)
{
__int64 result; // rax

debug_print("FG_RENAME");
if ( (unsigned int)repo_is_dir(a1) )
result = (unsigned int)((int)repo_rename_dir(a1, a2) >> 31);
else
result = (unsigned int)((int)repo_rename_file(a1, a2) >> 31);
return result;
}

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

debug_print("FG_RENAME");
if ( (unsigned int)repo_is_dir(a1) )
result = (unsigned int)((int)repo_rename_dir(a1, a2) >> 31);
else
result = (unsigned int)((int)repo_rename_file(a1, a2) >> 31);
return result;
}

original_code:
static int fg_rename(const char *from, const char *to)
{
 debug_print("FG_RENAME");
 int r;
 if (repo_is_dir(from)) {
  if ((r = repo_rename_dir(from, to)) < 0)
   return -1;
 } else {
  if ((r = repo_rename_file(from, to)) < 0)
   return -1;
 }
        return 0;
}

canonical_original_code:
static int fg_rename(char *from, char *to)
{
 debug_print("FG_RENAME");
 int r;
 if (repo_is_dir(from)) {
  if ((r = repo_rename_dir(from, to)) < 0)
   return -1;
 } else {
  if ((r = repo_rename_file(from, to)) < 0)
   return -1;
 }
        return 0;
}

variable_types: r int


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

debug_print("FG_RMDIR");
v1 = repo_rmdir(a1);
v2 = 0;
if ( v1 < 0 )
{
v2 = -2;
if ( v1 == -2 )
v2 = -39;
}
return v2;
}

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

debug_print("FG_RMDIR");
v1 = repo_rmdir(a1);
v2 = 0;
if ( v1 < 0 )
{
v2 = -2;
if ( v1 == -2 )
v2 = -39;
}
return v2;
}

original_code:
static int fg_rmdir(const char *path)
{
 debug_print("FG_RMDIR");
 int r;
 if ((r = repo_rmdir(path)) < 0) {
  switch(r) {
  case -1:
   return -2;
  case -2:
   return -39;
  }
  return -2;
 }
        return 0;
}

canonical_original_code:
static int fg_rmdir(char *path)
{
 debug_print("FG_RMDIR");
 int r;
 if ((r = repo_rmdir(path)) < 0) {
  switch(r) {
  case -1:
   return -2;
  case -2:
   return -39;
  }
  return -2;
 }
        return 0;
}


decompiled_code:
__int64 __fastcall fg_unlink(__int64 a1)
{
debug_print("FG_UNLINK");
return ((int)repo_unlink(a1) >> 31) & 0xFFFFFFBD;
}

canonical_decompiled_code:
__int64 __fastcall func20(__int64 a1)
{
debug_print("FG_UNLINK");
return ((int)repo_unlink(a1) >> 31) & 0xFFFFFFBD;
}

original_code:
static int fg_unlink(const char *path)
{
 debug_print("FG_UNLINK");
 int r;
 if ((r = repo_unlink(path)) < 0)
  return -67;
        return 0;
}

canonical_original_code:
static int fg_unlink(char *path)
{
 debug_print("FG_UNLINK");
 int r;
 if ((r = repo_unlink(path)) < 0)
  return -67;
        return 0;
}


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

v2 = a2;
debug_print("FG_MKDIR");
BYTE1(v2) = BYTE1(a2) | 0x40;
return ((int)repo_mkdir(a1, v2) >> 31) & 0xFFFFFFFE;
}

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

v2 = a2;
debug_print("FG_MKDIR");
BYTE1(v2) = BYTE1(a2) | 0x40;
return ((int)repo_mkdir(a1, v2) >> 31) & 0xFFFFFFFE;
}

original_code:
static int fg_mkdir(const char *path, mode_t mode)
{
 debug_print("FG_MKDIR");
 int r;
 if ((r = repo_mkdir(path, mode|0040000)) < 0)
  return -2;
        return 0;
}

canonical_original_code:
static int fg_mkdir(char *path, unsigned int mode)
{
 debug_print("FG_MKDIR");
 int r;
 if ((r = repo_mkdir(path, mode|0040000)) < 0)
  return -2;
        return 0;
}


decompiled_code:
__int64 __fastcall fg_getattr(const char *a1, __int64 a2)
{
unsigned int v3; // ebp
bool v4; // zf
const char *v5; // rdi

debug_print("FG_GETATTR");
debug_print("checking if path exists: %s", a1);
if ( !(unsigned int)repo_path_exists(a1) )
return (unsigned int)-2;
debug_print("getting attribute of %s", a1);
v3 = repo_is_dir(a1);
if ( v3 )
return ((int)repo_dir_stat(a1, a2) >> 31) & 0xFFFFFFFE;
v4 = strcmp("/", a1) == 0;
v5 = "/";
if ( !v4 )
v5 = a1;
if ( (int)repo_stat(v5, a2) < 0 )
return (unsigned int)-2;
print_file_stats(a1, a2);
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func22(const char *a1, __int64 a2)
{
unsigned int v3; // ebp
bool v4; // zf
const char *v5; // rdi

debug_print("FG_GETATTR");
debug_print("checking if path exists: %s", a1);
if ( !(unsigned int)repo_path_exists(a1) )
return (unsigned int)-2;
debug_print("getting attribute of %s", a1);
v3 = repo_is_dir(a1);
if ( v3 )
return ((int)repo_dir_stat(a1, a2) >> 31) & 0xFFFFFFFE;
v4 = strcmp("/", a1) == 0;
v5 = "/";
if ( !v4 )
v5 = a1;
if ( (int)repo_stat(v5, a2) < 0 )
return (unsigned int)-2;
print_file_stats(a1, a2);
return v3;
}

original_code:
static int fg_getattr(const char *path, struct stat *stbuf)
{
 debug_print("FG_GETATTR");
 int r;
 debug_print("checking if path exists: %s", path);
 if (!repo_path_exists(path))
  return -2;
 debug_print("getting attribute of %s", path);
 if ((r = repo_is_dir(path))) {
  if ((r = repo_dir_stat(path, stbuf)) < 0)
   return -2;
  return 0;
 }
 if ((r = repo_stat(strcmp("/", path) ? path : "/", stbuf)) < 0)
  return -2;
 print_file_stats(path, stbuf);
        return 0;
}

canonical_original_code:
static int fg_getattr(char *path, struct stat *stbuf)
{
 debug_print("FG_GETATTR");
 int r;
 debug_print("checking if path exists: %s", path);
 if (!repo_path_exists(path))
  return -2;
 debug_print("getting attribute of %s", path);
 if ((r = repo_is_dir(path))) {
  if ((r = repo_dir_stat(path, stbuf)) < 0)
   return -2;
  return 0;
 }
 if ((r = repo_stat(strcmp("/", path) ? path : "/", stbuf)) < 0)
  return -2;
 print_file_stats(path, stbuf);
        return 0;
}

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


decompiled_code:
__int64 __fastcall fg_fuse_main(int a1, __int64 a2)
{
__int64 i; // rbx

if ( a1 > 0 )
{
for ( i = 0LL; i != a1; ++i )
debug_print("arg %d: %s", (unsigned int)i, *(const char **)(a2 + 8 * i));
}
return fuse_main_real((unsigned int)a1, a2, &fg_oper, 360LL, 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func23(int a1, __int64 a2)
{
__int64 i; // rbx

if ( a1 > 0 )
{
for ( i = 0LL; i != a1; ++i )
debug_print("arg %d: %s", (unsigned int)i, *(const char **)(a2 + 8 * i));
}
return fuse_main_real((unsigned int)a1, a2, &fg_oper, 360LL, 0LL);
}

original_code:
int
fg_fuse_main(int argc, char *argv[])
{
 int i;
 for (i=0; i<argc; i++) {
  debug_print("arg %d: %s", i, argv[i]);
 }
        return fuse_main_real(argc, argv, &fg_oper, sizeof(*(&fg_oper)), ((void *)0));
}

variable_types: argc int

variable_types:
argv
char *[]


decompiled_code:
int debug_print(char *format, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-10E0h] BYREF
char s[4112]; // [rsp+20h] [rbp-10C8h] BYREF

va_start(arg, format);
vsnprintf(s, 0x1000uLL, format, arg);
s[strlen(s) + 1] = 0;
s[strlen(s)] = 10;
return fputs(s, stdout);
}

canonical_decompiled_code:
int func0(char *format, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-10E0h] BYREF
char s[4112]; // [rsp+20h] [rbp-10C8h] BYREF

va_start(arg, format);
vsnprintf(s, 0x1000uLL, format, arg);
s[strlen(s) + 1] = 0;
s[strlen(s)] = 10;
return fputs(s, stdout);
}

original_code:
void debug_print(char *msg, ...)
{
 char buf[4096 +2];
 va_list argp;
        __builtin_va_start(argp,msg);
 vsnprintf(buf, 4096, msg, argp);
 __builtin_va_end(argp);
 buf[strlen(buf)+1] = '\0';
 buf[strlen(buf)] = '\n';
 fprintf(stdout, "%s", buf);
}

canonical_original_code:
void debug_print(char *msg, ...)
{
 char buf[-1];
 __builtin_va_list argp;
        __builtin_va_start(argp,msg);
 vsnprintf(buf, 4096, msg, argp);
 __builtin_va_end(argp);
 buf[strlen(buf)+1] = '\0';
 buf[strlen(buf)] = '\n';
 fprintf(stdout, "%s", buf);
}

variable_types:
msg
char *

variable_types:
buf
char [-1]


decompiled_code:
_BOOL8 __fastcall is_substr(const char *a1, const char *a2)
{
return strstr(a1, a2) != 0LL;
}

canonical_decompiled_code:
_BOOL8 __fastcall func1(const char *a1, const char *a2)
{
return strstr(a1, a2) != 0LL;
}

original_code:
int is_substr(const char *str, const char *sub)
{
 return strstr(str, sub) ? 1 : 0;
}

canonical_original_code:
int is_substr(char *str, char *sub)
{
 return strstr(str, sub) ? 1 : 0;
}

variable_types:
str
char *

variable_types:
sub
char *


decompiled_code:
__int64 __fastcall get_parent_path(char *src, char *s)
{
char *v2; // rbp
int v3; // er12
int v4; // edx
__int64 result; // rax

if ( src )
strcpy(s, src);
v2 = rindex(s, 47);
v3 = strlen(s);
v2[1] = 0;
v4 = strlen(s);
result = 0LL;
if ( v3 == v4 )
{
if ( !strcmp(s, "/") )
{
result = 0xFFFFFFFFLL;
}
else
{
*v2 = 0;
rindex(s, 47)[1] = 0;
result = 0LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(char *src, char *s)
{
char *v2; // rbp
int v3; // er12
int v4; // edx
__int64 result; // rax

if ( src )
strcpy(s, src);
v2 = rindex(s, 47);
v3 = strlen(s);
v2[1] = 0;
v4 = strlen(s);
result = 0LL;
if ( v3 == v4 )
{
if ( !strcmp(s, "/") )
{
result = 0xFFFFFFFFLL;
}
else
{
*v2 = 0;
rindex(s, 47)[1] = 0;
result = 0LL;
}
}
return result;
}

original_code:
int get_parent_path(const char *path, char *parent)
{
 char *tmp;
 int old_len;
 int new_len;
 if (path)
  strcpy(parent, path);
 tmp = rindex(parent, '/');
 old_len = strlen(parent);
 *(tmp+1) = '\0';
 new_len = strlen(parent);
 if ((old_len == new_len) && (strcmp(parent, "/") == 0))
  return -1;
 if (old_len == new_len) {
  *tmp = '\0';
  tmp = rindex(parent, '/');
  *(tmp+1) = '\0';
 }
 return 0;
}

canonical_original_code:
int get_parent_path(char *path, char *parent)
{
 char *tmp;
 int old_len;
 int new_len;
 if (path)
  strcpy(parent, path);
 tmp = rindex(parent, '/');
 old_len = strlen(parent);
 *(tmp+1) = '\0';
 new_len = strlen(parent);
 if ((old_len == new_len) && (strcmp(parent, "/") == 0))
  return -1;
 if (old_len == new_len) {
  *tmp = '\0';
  tmp = rindex(parent, '/');
  *(tmp+1) = '\0';
 }
 return 0;
}

variable_types:
parent
char *

variable_types:
tmp
char *


decompiled_code:
__int64 __fastcall get_last_component(char *src, char *s)
{
char *v2; // rax
char *v3; // rbx

if ( *src != 47 )
return 0xFFFFFFFFLL;
strcpy(s, src);
while ( 1 )
{
v2 = rindex(s, 47);
v3 = v2;
if ( !v2 )
break;
if ( strlen(v2) != 1 )
{
strcpy(s, v3 + 1);
return 0LL;
}
*v3 = 0;
}
*s = 0;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(char *src, char *s)
{
char *v2; // rax
char *v3; // rbx

if ( *src != 47 )
return 0xFFFFFFFFLL;
strcpy(s, src);
while ( 1 )
{
v2 = rindex(s, 47);
v3 = v2;
if ( !v2 )
break;
if ( strlen(v2) != 1 )
{
strcpy(s, v3 + 1);
return 0LL;
}
*v3 = 0;
}
*s = 0;
return 0LL;
}

original_code:
int get_last_component(const char *path, char *name)
{
 if (*path != '/')
  return -1;
 char *dummy = ((void *)0);
 strcpy(name, path);
 do {
  if (dummy)
   dummy[0] = '\0';
  dummy = rindex(name, '/');
 } while (dummy && strlen(dummy) == 1);
 if (dummy)
  strcpy(name, dummy+1);
 else
  *name = '\0';
 return 0;
}

canonical_original_code:
int get_last_component(char *path, char *name)
{
 if (*path != '/')
  return -1;
 char *dummy = ((void *)0);
 strcpy(name, path);
 do {
  if (dummy)
   dummy[0] = '\0';
  dummy = rindex(name, '/');
 } while (dummy && strlen(dummy) == 1);
 if (dummy)
  strcpy(name, dummy+1);
 else
  *name = '\0';
 return 0;
}

variable_types:
name
char *

variable_types:
dummy
char *


decompiled_code:
__int64 __fastcall get_next_component(char *src, int a2, char *a3)
{
int v4; // er13
char *v5; // rax
int i; // ebx
unsigned int v7; // edx

v4 = strlen(a3);
strcpy(a3, src);
v5 = index(a3, 47);
for ( i = 0; i < a2; ++i )
{
v5 = index(v5 + 1, 47);
if ( !v5 )
return v4 != strlen(a3);
}
v7 = 1;
if ( *v5 == 47 )
v5[1] = 0;
return v7;
}

canonical_decompiled_code:
__int64 __fastcall func4(char *src, int a2, char *a3)
{
int v4; // er13
char *v5; // rax
int i; // ebx
unsigned int v7; // edx

v4 = strlen(a3);
strcpy(a3, src);
v5 = index(a3, 47);
for ( i = 0; i < a2; ++i )
{
v5 = index(v5 + 1, 47);
if ( !v5 )
return v4 != strlen(a3);
}
v7 = 1;
if ( *v5 == 47 )
v5[1] = 0;
return v7;
}

original_code:
int get_next_component(const char *path, int hier, char *name)
{
 char *ind;
 int len = strlen(name);
 int count = 0;
 strcpy(name, path);
 ind = index(name, '/');
 while (count < hier) {
  count++;
  ind++;
  ind = index(ind, '/');
  if (ind == ((void *)0)) {
   if (len == strlen(name))
    return 0;
   else
    return 1;
  }
 }
 if (*ind == '/')
  *(ind+1) = '\0';
 return 1;
}

canonical_original_code:
int get_next_component(char *path, int hier, char *name)
{
 char *ind;
 int len = strlen(name);
 int count = 0;
 strcpy(name, path);
 ind = index(name, '/');
 while (count < hier) {
  count++;
  ind++;
  ind = index(ind, '/');
  if (ind == ((void *)0)) {
   if (len == strlen(name))
    return 0;
   else
    return 1;
  }
 }
 if (*ind == '/')
  *(ind+1) = '\0';
 return 1;
}

variable_types: hier int

variable_types:
ind
char *

variable_types: len int

variable_types: count int


decompiled_code:
int __fastcall print_file_stats(const char *a1, unsigned int *a2)
{
debug_print("***PRINT STAT : %s", a1);
debug_print("\tdev=%x", *a2);
debug_print("\tino=%x", a2[2]);
debug_print("\tmode=%x", a2[6]);
debug_print("\tnlink=%x", a2[4]);
debug_print("\tuid=%x", a2[7]);
debug_print("\tgid=%x", a2[8]);
debug_print("\tsize=%x", a2[12]);
debug_print("\tmtime=%x", a2[22]);
debug_print("\tctime=%x", *((_QWORD *)a2 + 13));
return debug_print("***PRINT STAT OVER\n");
}

canonical_decompiled_code:
int __fastcall func5(const char *a1, unsigned int *a2)
{
func0("***PRINT STAT : %s", a1);
func0("\tdev=%x", *a2);
func0("\tino=%x", a2[2]);
func0("\tmode=%x", a2[6]);
func0("\tnlink=%x", a2[4]);
func0("\tuid=%x", a2[7]);
func0("\tgid=%x", a2[8]);
func0("\tsize=%x", a2[12]);
func0("\tmtime=%x", a2[22]);
func0("\tctime=%x", *((_QWORD *)a2 + 13));
return func0("***PRINT STAT OVER\n");
}

original_code:
void print_file_stats(const char *path, struct stat *stbuf)
{
 debug_print("***PRINT STAT : %s", path);
 debug_print("\tdev=%x", (unsigned int)stbuf->st_dev);
 debug_print("\tino=%x", (unsigned int)stbuf->st_ino);
 debug_print("\tmode=%x", (unsigned int)stbuf->st_mode);
 debug_print("\tnlink=%x", (unsigned int)stbuf->st_nlink);
 debug_print("\tuid=%x", (unsigned int)stbuf->st_uid);
 debug_print("\tgid=%x", (unsigned int)stbuf->st_gid);
 debug_print("\tsize=%x", (unsigned int)stbuf->st_size);
 debug_print("\tmtime=%x", (unsigned int)stbuf->st_mtim.tv_sec);
 debug_print("\tctime=%x", (unsigned int)stbuf->st_ctim.tv_sec);
 debug_print("***PRINT STAT OVER\n");
}

canonical_original_code:
void print_file_stats(char *path, struct stat *stbuf)
{
 debug_print("***PRINT STAT : %s", path);
 debug_print("\tdev=%x", (unsigned int)stbuf->st_dev);
 debug_print("\tino=%x", (unsigned int)stbuf->st_ino);
 debug_print("\tmode=%x", (unsigned int)stbuf->st_mode);
 debug_print("\tnlink=%x", (unsigned int)stbuf->st_nlink);
 debug_print("\tuid=%x", (unsigned int)stbuf->st_uid);
 debug_print("\tgid=%x", (unsigned int)stbuf->st_gid);
 debug_print("\tsize=%x", (unsigned int)stbuf->st_size);
 debug_print("\tmtime=%x", (unsigned int)stbuf->st_mtim.tv_sec);
 debug_print("\tctime=%x", (unsigned int)stbuf->st_ctim.tv_sec);
 debug_print("***PRINT STAT OVER\n");
}

variable_types:
path
char *

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


repo: shanepelletier/ZolkVM

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
perror("test.zasm");
return 0;
}

original_code:
int main(int argc, char *argv[])
{
  int testprogram[1] = {0x20210005};
  printf(testprogram[1]);
 return 0;
}

variable_types:
testprogram
int [1]