repo: andytwmvp/rpi-gpio-demo

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char **v3; // rbx
char *v4; // r13
unsigned int v5; // ebp
int v6; // eax
bool v7; // cf
bool v8; // zf
const char *v9; // rdi
__int64 v10; // rcx
const char **v12; // r12
unsigned int v13; // er12
int v14; // eax

v3 = argv;
if ( (unsigned int)(argc - 3) > 1 )
goto LABEL_16;
v4 = (char *)argv[1];
v5 = parse_gpio_pin(argv[2], argv, envp);
if ( argc == 4 )
{
v12 = (const char **)argv[3];
if ( !strcmp("pullup", (const char *)v12) )
{
v13 = 2;
}
else
{
argv = v12;
v13 = 1;
if ( strcmp("pulldown", (const char *)argv) )
goto LABEL_16;
}
v14 = strcmp(v4, "export");
v7 = 0;
v8 = v14 == 0;
if ( !v14 )
{
write_pin_to_path(&unk_4021EE, v5);
allow_access_by_user(v5, "direction");
allow_access_by_user(v5, "value");
allow_access_by_user(v5, "active_low");
allow_access_by_user(v5, "edge");
set_pullupdown(v5, v13);
return 0;
}
}
else
{
v6 = strcmp(v4, "export");
v7 = 0;
v8 = v6 == 0;
if ( !v6 )
{
write_pin_to_path(&unk_4021EE, v5);
allow_access_by_user(v5, "direction");
allow_access_by_user(v5, "value");
allow_access_by_user(v5, "active_low");
allow_access_by_user(v5, "edge");
return 0;
}
}
v9 = "unexport";
v10 = 9LL;
argv = (const char **)v4;
do
{
if ( !v10 )
break;
v7 = *(_BYTE *)argv < *v9;
v8 = *(_BYTE *)argv == *v9;
argv = (const char **)((char *)argv + 1);
++v9;
--v10;
}
while ( v8 );
if ( (!v7 && !v8) != v7 )
LABEL_16:
usage_error_isra_0(*v3, argv, envp);
write_pin_to_path(&unk_4021D5, v5);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char **v3; // rbx
char *v4; // r13
unsigned int v5; // ebp
int v6; // eax
bool v7; // cf
bool v8; // zf
const char *v9; // rdi
__int64 v10; // rcx
const char **v12; // r12
unsigned int v13; // er12
int v14; // eax

v3 = argv;
if ( (unsigned int)(argc - 3) > 1 )
goto LABEL_16;
v4 = (char *)argv[1];
v5 = func7(argv[2], argv, envp);
if ( argc == 4 )
{
v12 = (const char **)argv[3];
if ( !strcmp("pullup", (const char *)v12) )
{
v13 = 2;
}
else
{
argv = v12;
v13 = 1;
if ( strcmp("pulldown", (const char *)argv) )
goto LABEL_16;
}
v14 = strcmp(v4, "export");
v7 = 0;
v8 = v14 == 0;
if ( !v14 )
{
func10(&unk_4021EE, v5);
func8(v5, "direction");
func8(v5, "value");
func8(v5, "active_low");
func8(v5, "edge");
func9(v5, v13);
return 0;
}
}
else
{
v6 = strcmp(v4, "export");
v7 = 0;
v8 = v6 == 0;
if ( !v6 )
{
func10(&unk_4021EE, v5);
func8(v5, "direction");
func8(v5, "value");
func8(v5, "active_low");
func8(v5, "edge");
return 0;
}
}
v9 = "unexport";
v10 = 9LL;
argv = (const char **)v4;
do
{
if ( !v10 )
break;
v7 = *(_BYTE *)argv < *v9;
v8 = *(_BYTE *)argv == *v9;
argv = (const char **)((char *)argv + 1);
++v9;
--v10;
}
while ( v8 );
if ( (!v7 && !v8) != v7 )
LABEL_16:
func11(*v3, argv, envp);
func10(&unk_4021D5, v5);
return 0;
}

original_code:
int main(int argc, char **argv) {
  int pullupdown = -1;
  if (argc != 3 && argc != 4) {
    usage_error(argv);
  }
  const char *command = argv[1];
  const char *pin_str = argv[2];
  unsigned int pin = parse_gpio_pin(pin_str);
  if (argc == 4) {
    if (strcmp("pullup", argv[3]) == 0)
      pullupdown = 2;
    else if (strcmp("pulldown", argv[3]) == 0)
      pullupdown = 1;
    else {
      usage_error(argv);
    }
  }
  if (strcmp(command, "export") == 0) {
    write_pin_to_path(("/sys/class/gpio/" "export"), pin);
    allow_access_by_user(pin, "direction");
    allow_access_by_user(pin, "value");
    allow_access_by_user(pin, "active_low");
    allow_access_by_user(pin, "edge");
    if (pullupdown != -1) {
      set_pullupdown(pin, pullupdown);
    }
  }
  else if (strcmp(command, "unexport") == 0) {
    write_pin_to_path(("/sys/class/gpio/" "unexport"), pin);
  }
  else {
    usage_error(argv);
  }
  return 0;
}

canonical_original_code:
int main(int argc, char **argv) {
  int pullupdown = -1;
  if (argc != 3 && argc != 4) {
    usage_error(argv);
  }
  char *command = argv[1];
  char *pin_str = argv[2];
  unsigned int pin = parse_gpio_pin(pin_str);
  if (argc == 4) {
    if (strcmp("pullup", argv[3]) == 0)
      pullupdown = 2;
    else if (strcmp("pulldown", argv[3]) == 0)
      pullupdown = 1;
    else {
      usage_error(argv);
    }
  }
  if (strcmp(command, "export") == 0) {
    write_pin_to_path(("/sys/class/gpio/" "export"), pin);
    allow_access_by_user(pin, "direction");
    allow_access_by_user(pin, "value");
    allow_access_by_user(pin, "active_low");
    allow_access_by_user(pin, "edge");
    if (pullupdown != -1) {
      set_pullupdown(pin, pullupdown);
    }
  }
  else if (strcmp(command, "unexport") == 0) {
    write_pin_to_path(("/sys/class/gpio/" "unexport"), pin);
  }
  else {
    usage_error(argv);
  }
  return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types: pullupdown int

variable_types:
command
char *

variable_types:
pin
unsigned int


decompiled_code:
unsigned __int64 __fastcall parse_gpio_pin(const char *a1)
{
unsigned __int64 result; // rax
char *endptr; // [rsp+8h] [rbp-10h] BYREF

if ( !*a1 )
{
error(2, 0, "empty string given for GPIO pin number");
goto LABEL_5;
}
result = strtoul(a1, &endptr, 0);
if ( *endptr )
{
LABEL_5:
error(2, 0, "%s is not a valid GPIO pin number", a1);
result = allow_access_by_user(2LL, 0LL);
}
return result;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func7(const char *a1)
{
unsigned __int64 result; // rax
char *endptr; // [rsp+8h] [rbp-10h] BYREF

if ( !*a1 )
{
error(2, 0, "empty string given for GPIO pin number");
goto LABEL_5;
}
result = strtoul(a1, &endptr, 0);
if ( *endptr )
{
LABEL_5:
error(2, 0, "%s is not a valid GPIO pin number", a1);
result = func8(2LL, 0LL);
}
return result;
}

original_code:
static unsigned int parse_gpio_pin(const char *pin_str) {
  char *endp;
  unsigned int pin;
  if (pin_str[0] == '\0') {
    error(2, 0, "empty string given for GPIO pin number");
  }
  pin = strtoul(pin_str, &endp, 0);
  if (*endp != '\0') {
    error(2, 0, "%s is not a valid GPIO pin number", pin_str);
  }
  return pin;
}

canonical_original_code:
static unsigned int parse_gpio_pin(char *pin_str) {
  char *endp;
  unsigned int pin;
  if (pin_str[0] == '\0') {
    error(2, 0, "empty string given for GPIO pin number");
  }
  pin = strtoul(pin_str, &endp, 0);
  if (*endp != '\0') {
    error(2, 0, "%s is not a valid GPIO pin number", pin_str);
  }
  return pin;
}

variable_types:
endp
char *

return_type: unsigned int


decompiled_code:
int __fastcall allow_access_by_user(unsigned int a1, const char *a2)
{
__gid_t v2; // er12
__uid_t v3; // eax
int result; // eax
int *v5; // rax
__int64 v6; // rsi
char v7[4104]; // [rsp+0h] [rbp-1008h] BYREF

if ( snprintf(v7, 0x1000uLL, "/sys/devices/virtual/gpio/gpio%u/%s", a1, a2) > 4095 )
{
error(7, 0, "path of GPIO pin is too long!");
goto LABEL_6;
}
v2 = getgid();
v3 = getuid();
if ( chown(v7, v3, v2) )
{
LABEL_7:
v6 = (unsigned int)*__errno_location();
error(5, v6, "failed to change group ownership of %s", v7);
return set_pullupdown(5LL, v6);
}
result = chmod(v7, 0x180u);
if ( result )
{
LABEL_6:
v5 = __errno_location();
error(6, *v5, "failed to set permissions of %s", v7);
goto LABEL_7;
}
return result;
}

canonical_decompiled_code:
int __fastcall func8(unsigned int a1, const char *a2)
{
__gid_t v2; // er12
__uid_t v3; // eax
int result; // eax
int *v5; // rax
__int64 v6; // rsi
char v7[4104]; // [rsp+0h] [rbp-1008h] BYREF

if ( snprintf(v7, 0x1000uLL, "/sys/devices/virtual/gpio/gpio%u/%s", a1, a2) > 4095 )
{
error(7, 0, "path of GPIO pin is too long!");
goto LABEL_6;
}
v2 = getgid();
v3 = getuid();
if ( chown(v7, v3, v2) )
{
LABEL_7:
v6 = (unsigned int)*__errno_location();
error(5, v6, "failed to change group ownership of %s", v7);
return func9(5LL, v6);
}
result = chmod(v7, 0x180u);
if ( result )
{
LABEL_6:
v5 = __errno_location();
error(6, *v5, "failed to set permissions of %s", v7);
goto LABEL_7;
}
return result;
}

original_code:
static void allow_access_by_user(unsigned int pin, const char *filename) {
  char path[4096];
  int size = snprintf(path, 4096, "/sys/devices/virtual/gpio/gpio%u/%s", pin, filename);
  if (size >= 4096) {
    error(7, 0, "path of GPIO pin is too long!");
  }
  if (chown(path, getuid(), getgid()) != 0) {
    error(5, (*__errno_location ()), "failed to change group ownership of %s", path);
  }
  if (chmod(path, 0400|0200) != 0) {
    error(6, (*__errno_location ()), "failed to set permissions of %s", path);
  }
}

canonical_original_code:
static void allow_access_by_user(unsigned int pin, char *filename) {
  char path[4096];
  int size = snprintf(path, 4096, "/sys/devices/virtual/gpio/gpio%u/%s", pin, filename);
  if (size >= 4096) {
    error(7, 0, "path of GPIO pin is too long!");
  }
  if (chown(path, getuid(), getgid()) != 0) {
    error(5, (*__errno_location ()), "failed to change group ownership of %s", path);
  }
  if (chmod(path, 0400|0200) != 0) {
    error(6, (*__errno_location ()), "failed to set permissions of %s", path);
  }
}

variable_types:
filename
char *

variable_types:
path
char [4096]

variable_types: size int

return_type: void


decompiled_code:
int __fastcall set_pullupdown(int a1, int a2)
{
int v2; // eax
int v3; // er12
_DWORD *v4; // rax
_DWORD *v5; // rbp
_DWORD *v6; // r13
int *v8; // rax
char *v9; // rax
int *v10; // rax
char *v11; // rax

v2 = open("/dev/mem", 1052674);
if ( v2 < 0 )
{
v8 = __errno_location();
v9 = strerror(*v8);
fprintf(_bss_start, "could not open /dev/mem: %s\n", v9);
exit(-1);
}
v3 = v2;
v4 = mmap(0LL, 0x1000uLL, 3, 1, v2, 538968064LL);
v5 = v4;
if ( v4 == (_DWORD *)-1LL )
{
v10 = __errno_location();
v11 = strerror(*v10);
fprintf(_bss_start, "could not map GPIO region: %s\n", v11);
close(v3);
exit(-1);
}
v4[37] = a2;
usleep(0x64u);
v6 = &v5[((a1 >> 5) & 1) + 38];
*v6 = 1 << a1;
usleep(0x64u);
v5[37] = 0;
*v6 = 0;
munmap(v5, 0x1000uLL);
return close(v3);
}

canonical_decompiled_code:
int __fastcall func9(int a1, int a2)
{
int v2; // eax
int v3; // er12
_DWORD *v4; // rax
_DWORD *v5; // rbp
_DWORD *v6; // r13
int *v8; // rax
char *v9; // rax
int *v10; // rax
char *v11; // rax

v2 = open("/dev/mem", 1052674);
if ( v2 < 0 )
{
v8 = __errno_location();
v9 = strerror(*v8);
fprintf(_bss_start, "could not open /dev/mem: %s\n", v9);
exit(-1);
}
v3 = v2;
v4 = mmap(0LL, 0x1000uLL, 3, 1, v2, 538968064LL);
v5 = v4;
if ( v4 == (_DWORD *)-1LL )
{
v10 = __errno_location();
v11 = strerror(*v10);
fprintf(_bss_start, "could not map GPIO region: %s\n", v11);
close(v3);
exit(-1);
}
v4[37] = a2;
usleep(0x64u);
v6 = &v5[((a1 >> 5) & 1) + 38];
*v6 = 1 << a1;
usleep(0x64u);
v5[37] = 0;
*v6 = 0;
munmap(v5, 0x1000uLL);
return close(v3);
}

original_code:
static void set_pullupdown(int pin, int direction) {
    volatile uint32_t* gpio;
    int fd = open("/dev/mem", 02|04010000);
    if (fd < 0) {
        fprintf(stderr, "could not open /dev/mem: %s\n", strerror((*__errno_location ())));
        exit(-1);
    }
    gpio = (volatile uint32_t*) mmap(((void *)0), 4096, 0x1|0x2, 0x01, fd, 0x20200000);
    if (gpio == ((void *) -1)) {
        fprintf(stderr, "could not map GPIO region: %s\n", strerror((*__errno_location ())));
        close(fd);
        exit(-1);
    }
    gpio[37] = direction;
    usleep(100);
    gpio[38 +(((pin) & 32) >> 5)] = (1 << ((pin) & 31));
    usleep(100);
    gpio[37] = 0;
    gpio[38 +(((pin) & 32) >> 5)] = 0;
    munmap((char*)gpio, 4096);
    close(fd);
}

canonical_original_code:
static void set_pullupdown(int pin, int direction) {
    unsigned int *gpio;
    int fd = open("/dev/mem", 02|04010000);
    if (fd < 0) {
        fprintf(stderr, "could not open /dev/mem: %s\n", strerror((*__errno_location ())));
        exit(-1);
    }
    gpio = (unsigned int *) mmap(((void *)0), 4096, 0x1|0x2, 0x01, fd, 0x20200000);
    if (gpio == ((void *) -1)) {
        fprintf(stderr, "could not map GPIO region: %s\n", strerror((*__errno_location ())));
        close(fd);
        exit(-1);
    }
    gpio[37] = direction;
    usleep(100);
    gpio[38 +(((pin) & 32) >> 5)] = (1 << ((pin) & 31));
    usleep(100);
    gpio[37] = 0;
    gpio[38 +(((pin) & 32) >> 5)] = 0;
    munmap((char *)gpio, 4096);
    close(fd);
}

variable_types: pin int

variable_types: direction int

variable_types:
gpio
unsigned int *

variable_types: fd int


repo: andywarduk/LEDs

decompiled_code:
__int64 get_gpio_revision()
{
unsigned int v0; // er12
const char *v1; // rax
char *v2; // rbp
_BOOL4 v4; // er12
unsigned int v5; // [rsp+Ch] [rbp-1Ch]

v0 = 0;
v1 = (const char *)get_cpuinfo_revision();
if ( v1 )
{
v2 = (char *)v1;
if ( strlen(v1) > 3 && (unsigned int)__isoc99_sscanf() )
{
printf("cpuinfo revision bits: %x\n", v5);
if ( v5 > 5 )
{
if ( v5 > 9 )
v4 = v5 - 13 > 2;
else
v4 = v5 == 6;
v0 = v4 + 2;
}
else if ( v5 > 3 )
{
v0 = 2;
}
else
{
v0 = v5 - 2 < 2 ? 1 : 3;
}
}
else
{
v0 = 0;
}
free(v2);
}
return v0;
}

canonical_decompiled_code:
__int64 func8()
{
unsigned int v0; // er12
const char *v1; // rax
char *v2; // rbp
_BOOL4 v4; // er12
unsigned int v5; // [rsp+Ch] [rbp-1Ch]

v0 = 0;
v1 = (const char *)func7();
if ( v1 )
{
v2 = (char *)v1;
if ( strlen(v1) > 3 && (unsigned int)__isoc99_sscanf() )
{
printf("cpuinfo revision bits: %x\n", v5);
if ( v5 > 5 )
{
if ( v5 > 9 )
v4 = v5 - 13 > 2;
else
v4 = v5 == 6;
v0 = v4 + 2;
}
else if ( v5 > 3 )
{
v0 = 2;
}
else
{
v0 = v5 - 2 < 2 ? 1 : 3;
}
}
else
{
v0 = 0;
}
free(v2);
}
return v0;
}

original_code:
static int get_gpio_revision(void)
{
    int rev = 0;
    char *full_revision;
    unsigned revision;
    full_revision = get_cpuinfo_revision();
    if (full_revision != ((void *)0)) {
        if (strlen(full_revision) >= 4 && sscanf(full_revision + strlen(full_revision) - 4, "%x", &revision)) {
            printf("cpuinfo revision bits: %x\n", revision);
            switch (revision) {
                case 0x0002:
                case 0x0003:
                    rev = 1;
                    break;
                case 0x0004:
                case 0x0005:
                case 0x0007:
                case 0x0008:
                case 0x0009:
                case 0x000d:
                case 0x000e:
                case 0x000f:
                    rev = 2;
                    break;
                default:
                    rev = 3;
                    break;
            }
        }
        free(full_revision);
    }
    return rev;
}

canonical_original_code:
static int get_gpio_revision()
{
    int rev = 0;
    char *full_revision;
    unsigned int revision;
    full_revision = get_cpuinfo_revision();
    if (full_revision != ((void *)0)) {
        if (strlen(full_revision) >= 4 && sscanf(full_revision + strlen(full_revision) - 4, "%x", &revision)) {
            printf("cpuinfo revision bits: %x\n", revision);
            switch (revision) {
                case 0x0002:
                case 0x0003:
                    rev = 1;
                    break;
                case 0x0004:
                case 0x0005:
                case 0x0007:
                case 0x0008:
                case 0x0009:
                case 0x000d:
                case 0x000e:
                case 0x000f:
                    rev = 2;
                    break;
                default:
                    rev = 3;
                    break;
            }
        }
        free(full_revision);
    }
    return rev;
}

variable_types: rev int

variable_types:
revision
unsigned int

return_type: int


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

result = get_dt_ranges_constprop_0(4LL);
if ( (_DWORD)result )
{
if ( (_DWORD)result == -1 )
result = 0x20000000LL;
}
else
{
result = get_dt_ranges_constprop_0(8LL);
if ( (_DWORD)result == -1 )
result = 0x20000000LL;
}
return result;
}

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

result = func9(4LL);
if ( (_DWORD)result )
{
if ( (_DWORD)result == -1 )
result = 0x20000000LL;
}
else
{
result = func9(8LL);
if ( (_DWORD)result == -1 )
result = 0x20000000LL;
}
return result;
}

original_code:
unsigned bcm_host_get_peripheral_address()
{
   unsigned address = get_dt_ranges("/proc/device-tree/soc/ranges", 4);
   if (address == 0)
      address = get_dt_ranges("/proc/device-tree/soc/ranges", 8);
   return address == (unsigned) ~0 ? 0x20000000 : address;
}

canonical_original_code:
unsigned int bcm_host_get_peripheral_address()
{
   unsigned int address = get_dt_ranges("/proc/device-tree/soc/ranges", 4);
   if (address == 0)
      address = get_dt_ranges("/proc/device-tree/soc/ranges", 8);
   return address == (unsigned int) ~0 ? 0x20000000 : address;
}

variable_types:
address
unsigned int


decompiled_code:
__int64 bcm_host_get_peripheral_size()
{
int v0; // eax
__int64 result; // rax

v0 = get_dt_ranges_constprop_0(4LL);
result = get_dt_ranges_constprop_0(v0 == 0 ? 12 : 8);
if ( (_DWORD)result == -1 )
result = 0x1000000LL;
return result;
}

canonical_decompiled_code:
__int64 func11()
{
int v0; // eax
__int64 result; // rax

v0 = func9(4LL);
result = func9(v0 == 0 ? 12 : 8);
if ( (_DWORD)result == -1 )
result = 0x1000000LL;
return result;
}

original_code:
unsigned bcm_host_get_peripheral_size()
{
   unsigned address = get_dt_ranges("/proc/device-tree/soc/ranges", 4);
   address = get_dt_ranges("/proc/device-tree/soc/ranges", (address == 0) ? 12 : 8);
   return address == (unsigned) ~0 ? 0x01000000 : address;
}

canonical_original_code:
unsigned int bcm_host_get_peripheral_size()
{
   unsigned int address = get_dt_ranges("/proc/device-tree/soc/ranges", 4);
   address = get_dt_ranges("/proc/device-tree/soc/ranges", (address == 0) ? 12 : 8);
   return address == (unsigned int) ~0 ? 0x01000000 : address;
}


decompiled_code:
__int64 gpio_setup()
{
unsigned int v0; // eax
__int64 result; // rax
__int64 v2; // rdx
unsigned int v3; // ebx
unsigned int v4; // eax
__int64 v5; // rsi
unsigned int v6; // ebx
int v7; // eax
int v8; // ebp
void *v9; // rax
void *v10; // rbx

v0 = get_gpio_revision();
switch ( v0 )
{
case 2u:
v2 = 26LL;
gpio_pinmap = &gpio_pinmap_r2;
gpio_pins = 27;
break;
case 3u:
v2 = 40LL;
gpio_pinmap = &gpio_pinmap_r3;
gpio_pins = 41;
break;
case 1u:
v2 = 26LL;
gpio_pinmap = &gpio_pinmap_r1;
gpio_pins = 27;
break;
default:
puts("Unable to get GPIO revision");
return 0LL;
}
printf("Running on Raspberry pi GPIO revision %d (%d pins)\n", v0, v2);
v3 = bcm_host_get_peripheral_address();
v4 = bcm_host_get_peripheral_size();
v5 = v3;
v6 = v3 + 0x200000;
printf("Peripheral base 0x%x, length 0x%x\n", v5, v4);
printf("GPIO base 0x%x\n", v6);
v7 = open("/dev/mem", 1052674);
v8 = v7;
if ( v7 < 0 )
{
perror("Unable to open /dev/mem");
result = 0LL;
}
else
{
v9 = mmap(0LL, 0x1000uLL, 3, 1, v7, v6);
v10 = v9;
if ( v9 == (void *)-1LL )
{
perror("mmap error");
result = 0LL;
}
else
{
printf("GPIO mapped to address 0x%lx\n", v9);
close(v8);
gpio = v10;
result = 1LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 func12()
{
unsigned int v0; // eax
__int64 result; // rax
__int64 v2; // rdx
unsigned int v3; // ebx
unsigned int v4; // eax
__int64 v5; // rsi
unsigned int v6; // ebx
int v7; // eax
int v8; // ebp
void *v9; // rax
void *v10; // rbx

v0 = func8();
switch ( v0 )
{
case 2u:
v2 = 26LL;
gpio_pinmap = &gpio_pinmap_r2;
gpio_pins = 27;
break;
case 3u:
v2 = 40LL;
gpio_pinmap = &gpio_pinmap_r3;
gpio_pins = 41;
break;
case 1u:
v2 = 26LL;
gpio_pinmap = &gpio_pinmap_r1;
gpio_pins = 27;
break;
default:
puts("Unable to get GPIO revision");
return 0LL;
}
printf("Running on Raspberry pi GPIO revision %d (%d pins)\n", v0, v2);
v3 = func10();
v4 = func11();
v5 = v3;
v6 = v3 + 0x200000;
printf("Peripheral base 0x%x, length 0x%x\n", v5, v4);
printf("GPIO base 0x%x\n", v6);
v7 = open("/dev/mem", 1052674);
v8 = v7;
if ( v7 < 0 )
{
perror("Unable to open /dev/mem");
result = 0LL;
}
else
{
v9 = mmap(0LL, 0x1000uLL, 3, 1, v7, v6);
v10 = v9;
if ( v9 == (void *)-1LL )
{
perror("mmap error");
result = 0LL;
}
else
{
printf("GPIO mapped to address 0x%lx\n", v9);
close(v8);
gpio = v10;
result = 1LL;
}
}
return result;
}

original_code:
int gpio_setup()
{
    int mem_fd;
    void *gpio_map = ((void *)0);
    int rpi_revision = 0;
    unsigned peripheral_base;
    unsigned peripheral_len;
    unsigned gpio_base;
    rpi_revision = get_gpio_revision();
    switch (rpi_revision) {
    case 1:
        gpio_pinmap = gpio_pinmap_r1;
        gpio_pins = sizeof(gpio_pinmap_r1) / sizeof(gpio_pinmap_r1[0]);
        break;
    case 2:
        gpio_pinmap = gpio_pinmap_r2;
        gpio_pins = sizeof(gpio_pinmap_r2) / sizeof(gpio_pinmap_r2[0]);
        break;
    case 3:
        gpio_pinmap = gpio_pinmap_r3;
        gpio_pins = sizeof(gpio_pinmap_r3) / sizeof(gpio_pinmap_r3[0]);
        break;
    default:
        printf("Unable to get GPIO revision\n");
        return 0;
    }
    printf("Running on Raspberry pi GPIO revision %d (%d pins)\n", rpi_revision, gpio_pins - 1);
    peripheral_base = bcm_host_get_peripheral_address();
    peripheral_len = bcm_host_get_peripheral_size();
    printf("Peripheral base 0x%x, length 0x%x\n", peripheral_base, peripheral_len);
    gpio_base = peripheral_base + 0x200000;
    printf("GPIO base 0x%x\n", gpio_base);
    if ((mem_fd = open("/dev/mem", 02 | 04010000)) < 0) {
        perror("Unable to open /dev/mem");
        return 0;
    }
    gpio_map = mmap(
                    ((void *)0),
                    4 * 1024,
                    0x1 | 0x2,
                    0x01,
                    mem_fd,
                    gpio_base
                    );
    if (gpio_map == ((void *) -1)) {
        perror("mmap error");
        return 0;
    }
    printf("GPIO mapped to address 0x%lx\n", (unsigned long) gpio_map);
    close(mem_fd);
    gpio = (volatile unsigned *) gpio_map;
    return 1;
}

canonical_original_code:
int gpio_setup()
{
    int mem_fd;
    void *gpio_map = ((void *)0);
    int rpi_revision = 0;
    unsigned int peripheral_base;
    unsigned int peripheral_len;
    unsigned int gpio_base;
    rpi_revision = get_gpio_revision();
    switch (rpi_revision) {
    case 1:
        gpio_pinmap = gpio_pinmap_r1;
        gpio_pins = sizeof(gpio_pinmap_r1) / sizeof(gpio_pinmap_r1[0]);
        break;
    case 2:
        gpio_pinmap = gpio_pinmap_r2;
        gpio_pins = sizeof(gpio_pinmap_r2) / sizeof(gpio_pinmap_r2[0]);
        break;
    case 3:
        gpio_pinmap = gpio_pinmap_r3;
        gpio_pins = sizeof(gpio_pinmap_r3) / sizeof(gpio_pinmap_r3[0]);
        break;
    default:
        printf("Unable to get GPIO revision\n");
        return 0;
    }
    printf("Running on Raspberry pi GPIO revision %d (%d pins)\n", rpi_revision, gpio_pins - 1);
    peripheral_base = bcm_host_get_peripheral_address();
    peripheral_len = bcm_host_get_peripheral_size();
    printf("Peripheral base 0x%x, length 0x%x\n", peripheral_base, peripheral_len);
    gpio_base = peripheral_base + 0x200000;
    printf("GPIO base 0x%x\n", gpio_base);
    if ((mem_fd = open("/dev/mem", 02 | 04010000)) < 0) {
        perror("Unable to open /dev/mem");
        return 0;
    }
    gpio_map = mmap(
                    ((void *)0),
                    4 * 1024,
                    0x1 | 0x2,
                    0x01,
                    mem_fd,
                    gpio_base
                    );
    if (gpio_map == ((void *) -1)) {
        perror("mmap error");
        return 0;
    }
    printf("GPIO mapped to address 0x%lx\n", (unsigned long) gpio_map);
    close(mem_fd);
    gpio = (unsigned int *) gpio_map;
    return 1;
}


decompiled_code:
int __fastcall dump_reg(int a1, const char *a2, unsigned int a3)
{
unsigned int v4; // ebx
unsigned int v5; // er13
bool v6; // cf

v4 = 31;
v5 = *(_DWORD *)(gpio + 4LL * a1);
fprintf(stdout, " GP%-7s : 0x%08x : ", a2, v5);
do
{
while ( 1 )
{
if ( (v5 & (1 << v4)) != 0 )
putc(49, stdout);
else
putc(48, stdout);
if ( a3 && !(v4 % a3) )
break;
v6 = v4-- == 0;
if ( v6 )
return fputc(10, stdout);
}
putc(32, stdout);
v6 = v4-- == 0;
}
while ( !v6 );
return fputc(10, stdout);
}

canonical_decompiled_code:
int __fastcall func13(int a1, const char *a2, unsigned int a3)
{
unsigned int v4; // ebx
unsigned int v5; // er13
bool v6; // cf

v4 = 31;
v5 = *(_DWORD *)(gpio + 4LL * a1);
fprintf(stdout, " GP%-7s : 0x%08x : ", a2, v5);
do
{
while ( 1 )
{
if ( (v5 & (1 << v4)) != 0 )
putc(49, stdout);
else
putc(48, stdout);
if ( a3 && !(v4 % a3) )
break;
v6 = v4-- == 0;
if ( v6 )
return fputc(10, stdout);
}
putc(32, stdout);
v6 = v4-- == 0;
}
while ( !v6 );
return fputc(10, stdout);
}

original_code:
void dump_reg(int offset, char *name, unsigned bitmod) {
    unsigned value;
    value = *(gpio + offset);
    fprintf(stdout, "  GP%-7s : 0x%08x : ", name, value);
    for (int bit = 31; bit >= 0; bit--) {
        if (value & (1 << bit)) {
            putc('1', stdout);
        } else {
            putc('0', stdout);
        }
        if (bitmod && (bit % bitmod) == 0) {
            putc(' ', stdout);
        }
    }
    fputs("\n", stdout);
}

canonical_original_code:
void dump_reg(int offset, char *name, unsigned int bitmod) {
    unsigned int value;
    value = *(gpio + offset);
    fprintf(stdout, "  GP%-7s : 0x%08x : ", name, value);
    for (int bit = 31; bit >= 0; bit--) {
        if (value & (1 << bit)) {
            putc('1', stdout);
        } else {
            putc('0', stdout);
        }
        if (bitmod && (bit % bitmod) == 0) {
            putc(' ', stdout);
        }
    }
    fputs("\n", stdout);
}

variable_types: offset int

variable_types:
name
char *

variable_types:
bitmod
unsigned int

variable_types:
value
unsigned int

variable_types: bit int


decompiled_code:
int __fastcall dump_regn(int a1, unsigned int a2, const char *a3, unsigned int a4)
{
char v6[72]; // [rsp+0h] [rbp-48h] BYREF

sprintf(v6, "%s%d", a3, a2);
return dump_reg(a2 + a1, v6, a4);
}

canonical_decompiled_code:
int __fastcall func14(int a1, unsigned int a2, const char *a3, unsigned int a4)
{
char v6[72]; // [rsp+0h] [rbp-48h] BYREF

sprintf(v6, "%s%d", a3, a2);
return func13(a2 + a1, v6, a4);
}

original_code:
void dump_regn(int offset, int reg, char *name, unsigned bitmod) {
    char fullname[32];
    sprintf(fullname, "%s%d", name, reg);
    dump_reg(offset + reg, fullname, bitmod);
}

canonical_original_code:
void dump_regn(int offset, int reg, char *name, unsigned int bitmod) {
    char fullname[32];
    sprintf(fullname, "%s%d", name, reg);
    dump_reg(offset + reg, fullname, bitmod);
}

variable_types: reg int

variable_types:
fullname
char [32]


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

if ( gpio_pins <= 1u )
return 0xFFFFFFFFLL;
result = 1LL;
while ( *(_DWORD *)(gpio_pinmap + 4 * result) != a1 )
{
if ( ++result == gpio_pins )
return 0xFFFFFFFFLL;
}
return result;
}

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

if ( gpio_pins <= 1u )
return 0xFFFFFFFFLL;
result = 1LL;
while ( *(_DWORD *)(gpio_pinmap + 4 * result) != a1 )
{
if ( ++result == gpio_pins )
return 0xFFFFFFFFLL;
}
return result;
}

original_code:
int find_pin(int gpio) {
    for (unsigned i = 1; i < gpio_pins; i++) {
        if (gpio_pinmap[i] == gpio) return i;
    }
    return -1;
}

canonical_original_code:
int find_pin(int gpio) {
    for (unsigned int i = 1; i < gpio_pins; i++) {
        if (gpio_pinmap[i] == gpio) return i;
    }
    return -1;
}

variable_types: gpio int

variable_types:
i
unsigned int


main

canonical_name: main

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

if ( !(unsigned int)gpio_setup(argc, argv, envp) )
exit(-1);
v3 = 0;
puts("Register dump:");
do
dump_regn(0LL, v3++, "FSEL", 3LL);
while ( v3 != 6 );
v4 = 0;
dump_regn(13LL, 0LL, "LEV", 4LL);
dump_regn(13LL, 1LL, "LEV", 4LL);
dump_regn(16LL, 0LL, "EDS", 4LL);
dump_regn(16LL, 1LL, "EDS", 4LL);
dump_regn(19LL, 0LL, "REN", 4LL);
dump_regn(19LL, 1LL, "REN", 4LL);
dump_regn(22LL, 0LL, "FEN", 4LL);
dump_regn(22LL, 1LL, "FEN", 4LL);
dump_regn(25LL, 0LL, "HEN", 4LL);
dump_regn(25LL, 1LL, "HEN", 4LL);
dump_regn(28LL, 0LL, "LEN", 4LL);
dump_regn(28LL, 1LL, "LEN", 4LL);
dump_regn(31LL, 0LL, "AREN", 4LL);
dump_regn(31LL, 1LL, "AREN", 4LL);
dump_regn(34LL, 0LL, "AFEN", 4LL);
dump_regn(34LL, 1LL, "AFEN", 4LL);
dump_reg(37LL, "PUD", 4LL);
dump_regn(38LL, 0LL, "PUDCLK", 4LL);
dump_regn(38LL, 1LL, "PUDCLK", 4LL);
do
{
printf("GPIO %2d: ", v4);
v5 = find_pin(v4);
if ( v5 >= 0 )
printf("pin %d, ", (unsigned int)v5);
v6 = (*(_DWORD *)(gpio + 4LL * (v4 / 0xA)) & (unsigned int)(7 << (3 * (v4 % 0xA)))) >> (3 * (v4 % 0xA));
printf("mode %d, ", v6);
switch ( v6 )
{
case 0u:
printf("input");
break;
case 1u:
printf("output");
break;
case 2u:
printf("alt function 5");
break;
case 3u:
printf("alt function 4");
break;
case 4u:
printf("alt function 0");
break;
case 5u:
printf("alt function 1");
break;
case 6u:
printf("alt function 2");
break;
case 7u:
printf("alt function 3");
break;
default:
break;
}
v7 = v4;
v8 = (int)v4 >> 5;
v9 = 1 << v4++;
printf(", level %d ", (*(_DWORD *)(gpio + 4LL * (v8 + 13)) & (unsigned int)v9) >> v7);
putchar(10);
}
while ( v4 != 54 );
return 0;
}

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

if ( !(unsigned int)func12(argc, argv, envp) )
exit(-1);
v3 = 0;
puts("Register dump:");
do
func14(0LL, v3++, "FSEL", 3LL);
while ( v3 != 6 );
v4 = 0;
func14(13LL, 0LL, "LEV", 4LL);
func14(13LL, 1LL, "LEV", 4LL);
func14(16LL, 0LL, "EDS", 4LL);
func14(16LL, 1LL, "EDS", 4LL);
func14(19LL, 0LL, "REN", 4LL);
func14(19LL, 1LL, "REN", 4LL);
func14(22LL, 0LL, "FEN", 4LL);
func14(22LL, 1LL, "FEN", 4LL);
func14(25LL, 0LL, "HEN", 4LL);
func14(25LL, 1LL, "HEN", 4LL);
func14(28LL, 0LL, "LEN", 4LL);
func14(28LL, 1LL, "LEN", 4LL);
func14(31LL, 0LL, "AREN", 4LL);
func14(31LL, 1LL, "AREN", 4LL);
func14(34LL, 0LL, "AFEN", 4LL);
func14(34LL, 1LL, "AFEN", 4LL);
func13(37LL, "PUD", 4LL);
func14(38LL, 0LL, "PUDCLK", 4LL);
func14(38LL, 1LL, "PUDCLK", 4LL);
do
{
printf("GPIO %2d: ", v4);
v5 = func15(v4);
if ( v5 >= 0 )
printf("pin %d, ", (unsigned int)v5);
v6 = (*(_DWORD *)(gpio + 4LL * (v4 / 0xA)) & (unsigned int)(7 << (3 * (v4 % 0xA)))) >> (3 * (v4 % 0xA));
printf("mode %d, ", v6);
switch ( v6 )
{
case 0u:
printf("input");
break;
case 1u:
printf("output");
break;
case 2u:
printf("alt function 5");
break;
case 3u:
printf("alt function 4");
break;
case 4u:
printf("alt function 0");
break;
case 5u:
printf("alt function 1");
break;
case 6u:
printf("alt function 2");
break;
case 7u:
printf("alt function 3");
break;
default:
break;
}
v7 = v4;
v8 = (int)v4 >> 5;
v9 = 1 << v4++;
printf(", level %d ", (*(_DWORD *)(gpio + 4LL * (v8 + 13)) & (unsigned int)v9) >> v7);
putchar(10);
}
while ( v4 != 54 );
return 0;
}

original_code:
int main()
{
    int i;
    int mode;
    if (!gpio_setup()) exit(-1);
    printf("Register dump:\n");
    for (i = 0; i < 6; i++) {
        dump_regn(0, i, "FSEL", 3);
    }
    for (i = 0; i < 2; i++) {
        dump_regn(13, i, "LEV", 4);
    }
    for (i = 0; i < 2; i++) {
        dump_regn(16, i, "EDS", 4);
    }
    for (i = 0; i < 2; i++) {
        dump_regn(19, i, "REN", 4);
    }
    for (i = 0; i < 2; i++) {
        dump_regn(22, i, "FEN", 4);
    }
    for (i = 0; i < 2; i++) {
        dump_regn(25, i, "HEN", 4);
    }
    for (i = 0; i < 2; i++) {
        dump_regn(28, i, "LEN", 4);
    }
    for (i = 0; i < 2; i++) {
        dump_regn(31, i, "AREN", 4);
    }
    for (i = 0; i < 2; i++) {
        dump_regn(34, i, "AFEN", 4);
    }
    dump_reg(37, "PUD", 4);
    for (i = 0; i < 2; i++) {
        dump_regn(38, i, "PUDCLK", 4);
    }
    for (i = 0; i < 54; i++) {
        printf("GPIO %2d: ", i);
        int pin = find_pin(i);
        if (pin >=0 ) {
            printf("pin %d, ", pin);
        }
        mode = (((*(gpio + ((i) / 10))) & (7 << (((i) % 10) * 3))) >> (((i) % 10) * 3));
        printf("mode %d, ", mode);
        switch (mode) {
        case 0:
            printf("input");
            break;
        case 1:
            printf("output");
            break;
        case 4:
            printf("alt function 0");
            break;
        case 5:
            printf("alt function 1");
            break;
        case 6:
            printf("alt function 2");
            break;
        case 7:
            printf("alt function 3");
            break;
        case 3:
            printf("alt function 4");
            break;
        case 2:
            printf("alt function 5");
            break;
        }
        printf(", level %d ", (((*(gpio + (13 + ((i) / 32)))) & (1 << ((i) % 32))) >> ((i) % 32)));
        printf("\n");
    }
    return 0;
}

variable_types: i int

variable_types: mode int


usage

decompiled_code:
void __fastcall __noreturn usage(const char *a1)
{
printf("Usage: %s {delay in micro seconds}\n", a1);
exit(-1);
}

canonical_decompiled_code:
void __fastcall __noreturn func0(const char *a1)
{
printf("Usage: %s {delay in micro seconds}\n", a1);
exit(-1);
}

original_code:
void usage(char *prog)
{
    printf("Usage: %s {delay in micro seconds}\n", prog);
    exit(-1);
}

variable_types:
prog
char *


onfor

decompiled_code:
__int64 __fastcall onfor(unsigned int a1, __int64 a2, __int64 a3, __int64 a4, __useconds_t a5)
{
led_on();
usleep(a5);
return led_off(a1);
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned int a1, __int64 a2, __int64 a3, __int64 a4, __useconds_t a5)
{
led_on();
usleep(a5);
return led_off(a1);
}

original_code:
void onfor(int led, int r, int g, int b, useconds_t usecs)
{
    led_on(led, r, g, b);
    usleep(usecs);
    led_off(led);
}

canonical_original_code:
void onfor(int led, int r, int g, int b, unsigned int usecs)
{
    led_on(led, r, g, b);
    usleep(usecs);
    led_off(led);
}

variable_types: led int

variable_types: r int

variable_types: g int

variable_types: b int

variable_types:
usecs
unsigned int


decompiled_code:
__int64 __fastcall get_pin(unsigned int a1, const char *a2)
{
unsigned int v2; // er12

v2 = *(_DWORD *)(gpio_pinmap + 4LL * (int)a1);
printf("Header pin %d (%s) is GPIO %d\n", a1, a2, v2);
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func14(unsigned int a1, const char *a2)
{
unsigned int v2; // er12

v2 = *(_DWORD *)(gpio_pinmap + 4LL * (int)a1);
printf("Header pin %d (%s) is GPIO %d\n", a1, a2, v2);
return v2;
}

original_code:
static int get_pin(int hdr_num, char *desc)
{
    int gpio_num;
    gpio_num = gpio_pinmap[hdr_num];
    printf("Header pin %d (%s) is GPIO %d\n", hdr_num, desc, gpio_num);
    return gpio_num;
}

variable_types:
desc
char *


setRT

decompiled_code:
void setRT()
{
struct sched_param param; // [rsp+Ch] [rbp-Ch] BYREF

param.__sched_priority = sched_get_priority_max(1);
if ( sched_setscheduler(0, 1, &param) )
perror("Unable to elevate to real time scheduling");
}

canonical_decompiled_code:
void func15()
{
struct sched_param param; // [rsp+Ch] [rbp-Ch] BYREF

param.__sched_priority = sched_get_priority_max(1);
if ( sched_setscheduler(0, 1, &param) )
perror("Unable to elevate to real time scheduling");
}

original_code:
static void setRT()
{
    int scheduler = 1;
    struct sched_param schedparam;
    memset(&schedparam, 0, sizeof (struct sched_param));
    schedparam.sched_priority = sched_get_priority_max(scheduler);
    if (sched_setscheduler(0, scheduler, &schedparam) != 0) {
        perror("Unable to elevate to real time scheduling");
    }
}

variable_types: scheduler int

variable_types: struct sched_param { int sched_priority; }


decompiled_code:
__int64 led_init()
{
__int64 result; // rax
int *v1; // r13
int v2; // eax
int *v3; // r10
int *v4; // r8
int *v5; // r8
__int64 v6; // rsi
int v7; // ecx
int v8; // eax

result = gpio_setup();
if ( (_DWORD)result )
{
redpin = get_pin(0xBu, "Red");
greenpin = get_pin(0xDu, "Green");
bluepin = get_pin(0xFu, "Blue");
v1 = ledpins;
ledpins[0] = get_pin(7u, "LED 5");
ledpins[1] = get_pin(0x16u, "LED 4");
ledpins[2] = get_pin(0x12u, "LED 3");
ledpins[3] = get_pin(0x10u, "LED 2");
v2 = get_pin(0xCu, "LED 1");
v3 = ledpins;
ledpins[4] = v2;
do
setup_pin(*v3);
while ( v3 != v4 );
setup_pin(redpin);
setup_pin(greenpin);
setup_pin(bluepin);
v6 = gpio;
do
{
v7 = *v1;
v8 = *v1 + 31;
if ( *v1 >= 0 )
v8 = *v1;
++v1;
*(_DWORD *)(v6 + 4LL * ((v8 >> 5) + 7)) = 1 << (v7 % 32);
}
while ( v1 != v5 );
setRT();
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 func16()
{
__int64 result; // rax
int *v1; // r13
int v2; // eax
int *v3; // r10
int *v4; // r8
int *v5; // r8
__int64 v6; // rsi
int v7; // ecx
int v8; // eax

result = func12();
if ( (_DWORD)result )
{
redpin = func14(0xBu, "Red");
greenpin = func14(0xDu, "Green");
bluepin = func14(0xFu, "Blue");
v1 = ledpins;
ledpins[0] = func14(7u, "LED 5");
ledpins[1] = func14(0x16u, "LED 4");
ledpins[2] = func14(0x12u, "LED 3");
ledpins[3] = func14(0x10u, "LED 2");
v2 = func14(0xCu, "LED 1");
v3 = ledpins;
ledpins[4] = v2;
do
func13(*v3);
while ( v3 != v4 );
func13(redpin);
func13(greenpin);
func13(bluepin);
v6 = gpio;
do
{
v7 = *v1;
v8 = *v1 + 31;
if ( *v1 >= 0 )
v8 = *v1;
++v1;
*(_DWORD *)(v6 + 4LL * ((v8 >> 5) + 7)) = 1 << (v7 % 32);
}
while ( v1 != v5 );
func15();
result = 1LL;
}
return result;
}

original_code:
int led_init()
{
    unsigned int i;
    if (!gpio_setup()) return 0;
    redpin = get_pin(11, "Red");
    greenpin = get_pin(13, "Green");
    bluepin = get_pin(15, "Blue");
    ledpins[0] = get_pin(7, "LED 5");
    ledpins[1] = get_pin(22, "LED 4");
    ledpins[2] = get_pin(18, "LED 3");
    ledpins[3] = get_pin(16, "LED 2");
    ledpins[4] = get_pin(12, "LED 1");
    for (i = 0; i < sizeof (ledpins) / sizeof (int); i++) {
        setup_pin(ledpins[i]);
    }
    setup_pin(redpin);
    setup_pin(greenpin);
    setup_pin(bluepin);
    for (i = 0; i < sizeof (ledpins) / sizeof (int); i++) {
        ((*(gpio + (7 + ((ledpins[i]) / 32)))) = (1 << ((ledpins[i]) % 32)));
    }
    setRT();
    return 1;
}


main

repo: angmouzakitis/stegtool

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
void *v3; // rbp
char v4; // al
__int64 v6; // r12
int v7; // ebp
char v8; // al
char *v9; // rbx
char *v10; // rbp
int v11; // edi
__int64 v12; // r12
char v13; // al
char v14[9]; // [rsp+8h] [rbp-2730h] BYREF
char v15[10023]; // [rsp+11h] [rbp-2727h] BYREF

if ( argc == 1 )
usage(argc, argv, envp);
puts("What encryption method ? plain/xor");
__isoc99_scanf();
v3 = (void *)copy_to_mem(argv[1], v14);
set_headers(v3);
v4 = argv[1][2];
if ( v4 == 100 )
{
if ( v14[0] == 112 )
{
v12 = 1LL;
while ( 1 )
{
v7 = v12;
v13 = decrypt_bits((unsigned int)v12);
v14[v12++ + 8] = v13;
if ( !v13 )
break;
printf("MAIN : To ch einai %d kai %c\n", (unsigned int)v13, (unsigned int)v13);
}
v9 = v15;
}
else
{
if ( v14[0] != 120 )
{
printf("ERROR SWITCH DEFAULT , NO SUCH ENCRYPTION METHOD ... QUITING");
return 0;
}
v6 = 1LL;
while ( 1 )
{
v7 = v6;
v8 = decrypt_bits((unsigned int)v6);
v14[v6++ + 8] = v8;
if ( !v8 )
break;
printf("MAIN : To ch einai %d kai %c\n", (unsigned int)v8, (unsigned int)v8);
}
v9 = v15;
makeXOR(v15);
}
printf("\n\nHIDDEN MESSAGE FOUND : ");
v10 = &v15[v7 - 1 + 1];
do
{
v11 = *v9++;
putchar(v11);
}
while ( v9 != v10 );
putchar(10);
}
else if ( v4 == 101 )
{
printf("MAIN : Text to hide : %s\n\n", argv[2]);
puts("______________________________________________________\n\n");
if ( v14[0] != 112 )
{
if ( v14[0] != 120 )
{
LABEL_6:
save_file(v3);
return 0;
}
argv[2] = (const char *)makeXOR(argv[2]);
}
encrypt_bits(v3, argv[2]);
goto LABEL_6;
}
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
void *v3; // rbp
char v4; // al
__int64 v6; // r12
int v7; // ebp
char v8; // al
char *v9; // rbx
char *v10; // rbp
int v11; // edi
__int64 v12; // r12
char v13; // al
char v14[9]; // [rsp+8h] [rbp-2730h] BYREF
char v15[10023]; // [rsp+11h] [rbp-2727h] BYREF

if ( argc == 1 )
func7(argc, argv, envp);
puts("What encryption method ? plain/xor");
__isoc99_scanf();
v3 = (void *)func15(argv[1], v14);
func16(v3);
v4 = argv[1][2];
if ( v4 == 100 )
{
if ( v14[0] == 112 )
{
v12 = 1LL;
while ( 1 )
{
v7 = v12;
v13 = func11((unsigned int)v12);
v14[v12++ + 8] = v13;
if ( !v13 )
break;
printf("MAIN : To ch einai %d kai %c\n", (unsigned int)v13, (unsigned int)v13);
}
v9 = v15;
}
else
{
if ( v14[0] != 120 )
{
printf("ERROR SWITCH DEFAULT , NO SUCH ENCRYPTION METHOD ... QUITING");
return 0;
}
v6 = 1LL;
while ( 1 )
{
v7 = v6;
v8 = func11((unsigned int)v6);
v14[v6++ + 8] = v8;
if ( !v8 )
break;
printf("MAIN : To ch einai %d kai %c\n", (unsigned int)v8, (unsigned int)v8);
}
v9 = v15;
func8(v15);
}
printf("\n\nHIDDEN MESSAGE FOUND : ");
v10 = &v15[v7 - 1 + 1];
do
{
v11 = *v9++;
putchar(v11);
}
while ( v9 != v10 );
putchar(10);
}
else if ( v4 == 101 )
{
printf("MAIN : Text to hide : %s\n\n", argv[2]);
puts("______________________________________________________\n\n");
if ( v14[0] != 112 )
{
if ( v14[0] != 120 )
{
LABEL_6:
func17(v3);
return 0;
}
argv[2] = (const char *)func8(argv[2]);
}
func14(v3, argv[2]);
goto LABEL_6;
}
return 0;
}

original_code:
int main(int argc, char *argv[])
{
 uint8_t *ptr;
 int8_t *action, ch[10000], encryption[8];
 int i = 0, j;
 int8_t *decryptptr;
 decryptptr = (int8_t *) malloc(sizeof(int8_t) * 10000);
 if (argc == 1)
  usage();
 printf("What encryption method ? plain/xor\n");
 scanf("%s", encryption);
 ptr = copy_to_mem(argv[1]);
 set_headers(ptr);
 switch (argv[1][2]) {
 case 'e' :
  printf("MAIN : Text to hide : %s\n\n", argv[2]);
  printf("______________________________________________________\n\n\n");
  switch (encryption[0]) {
  case 'x' :
   argv[2] = makeXOR(argv[2]);
  case 'p' :
   encrypt_bits(ptr, argv[2]);
   break;
  }
  save_file(ptr);
  break;
 case 'd' :
  switch (encryption[0]) {
  case 'p' :
   for (i = 1; ch[i] = decrypt_bits(i); i++)
    printf("MAIN : To ch einai %d kai %c\n", ch[i], ch[i]);
   break;
  case 'x' :
   for (i = 1; ch[i] = decrypt_bits(i); i++)
    printf("MAIN : To ch einai %d kai %c\n", ch[i], ch[i]);
   decryptptr = &ch[1];
   decryptptr = makeXOR(decryptptr);
   break;
  default:
   printf("ERROR SWITCH DEFAULT , NO SUCH ENCRYPTION METHOD ... QUITING");
   return 0;
  }
  printf("\n\nHIDDEN MESSAGE FOUND : ");
  for (j = 1; j <= i; j++)
   printf("%c", ch[j]);
  printf("\n");
 }
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
 unsigned char *ptr;
 char *action; char ch[10000]; char encryption[8];
 int i = 0; int j;
 char *decryptptr;
 decryptptr = (char *) malloc(sizeof(char) * 10000);
 if (argc == 1)
  usage();
 printf("What encryption method ? plain/xor\n");
 scanf("%s", encryption);
 ptr = copy_to_mem(argv[1]);
 set_headers(ptr);
 switch (argv[1][2]) {
 case 'e' :
  printf("MAIN : Text to hide : %s\n\n", argv[2]);
  printf("______________________________________________________\n\n\n");
  switch (encryption[0]) {
  case 'x' :
   argv[2] = makeXOR(argv[2]);
  case 'p' :
   encrypt_bits(ptr, argv[2]);
   break;
  }
  save_file(ptr);
  break;
 case 'd' :
  switch (encryption[0]) {
  case 'p' :
   for (i = 1; ch[i] = decrypt_bits(i); i++)
    printf("MAIN : To ch einai %d kai %c\n", ch[i], ch[i]);
   break;
  case 'x' :
   for (i = 1; ch[i] = decrypt_bits(i); i++)
    printf("MAIN : To ch einai %d kai %c\n", ch[i], ch[i]);
   decryptptr = &ch[1];
   decryptptr = makeXOR(decryptptr);
   break;
  default:
   printf("ERROR SWITCH DEFAULT , NO SUCH ENCRYPTION METHOD ... QUITING");
   return 0;
  }
  printf("\n\nHIDDEN MESSAGE FOUND : ");
  for (j = 1; j <= i; j++)
   printf("%c", ch[j]);
  printf("\n");
 }
 return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types:
ptr
unsigned char *

variable_types:
action
char *

variable_types:
encryption
char [8]

variable_types: j int

variable_types:
decryptptr
char *


usage

decompiled_code:
void __noreturn usage()
{
puts("Give some arguments\nUSAGE: stegtool.exe <--encrypt|--decrypt> <TextToCrypt>");
exit(1);
}

canonical_decompiled_code:
void __noreturn func7()
{
puts("Give some arguments\nUSAGE: stegtool.exe <--encrypt|--decrypt> <TextToCrypt>");
exit(1);
}

original_code:
void usage()
{
 printf("Give some arguments\nUSAGE: stegtool.exe <--encrypt|--decrypt> <TextToCrypt>\n");
 exit(1);
}


power

decompiled_code:
__int64 __fastcall power(int a1)
{
unsigned int v1; // er8
int i; // eax

v1 = 1;
if ( a1 > 0 )
{
for ( i = 0; i != a1; ++i )
v1 *= 2;
}
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func9(int a1)
{
unsigned int v1; // er8
int i; // eax

v1 = 1;
if ( a1 > 0 )
{
for ( i = 0; i != a1; ++i )
v1 *= 2;
}
return v1;
}

original_code:
int power(int n)
{
 int i, p = 1;
 for (i = 0; i < n; i++) p *= 2;
 return p;
}

canonical_original_code:
int power(int n)
{
 int i; int p = 1;
 for (i = 0; i < n; i++) p *= 2;
 return p;
}

variable_types: n int

variable_types: i int

variable_types: p int


original_code:
int8_t bit2char(int8_t *ptr)
{
 int i, y = 7;
 int8_t ret = 0;
 for (i = 0;i < 8; i++) {
  if (ptr[y] & 1)
   ret += power(i);
  y--;
 }
 return ret;
}

canonical_original_code:
char bit2char(char *ptr)
{
 int i; int y = 7;
 char ret = 0;
 for (i = 0;i < 8; i++) {
  if (ptr[y] & 1)
   ret += power(i);
  y--;
 }
 return ret;
}

variable_types:
ptr
char *

variable_types: y int

variable_types: ret char

return_type: char


decompiled_code:
__int64 __fastcall decrypt_bits(int a1)
{
return bit2char(qword_4041C8 + 8 * a1 - 8);
}

canonical_decompiled_code:
__int64 __fastcall func11(int a1)
{
return func10(qword_4041C8 + 8 * a1 - 8);
}

original_code:
int8_t decrypt_bits(int i)
{
 uint8_t *ptr, ret;
 ptr = header.offset;
 ptr += (i-1) * 8;
 ret = bit2char(ptr);
 return ret;
}

canonical_original_code:
char decrypt_bits(int i)
{
 unsigned char *ptr; unsigned char ret;
 ptr = header.offset;
 ptr += (i-1) * 8;
 ret = bit2char(ptr);
 return ret;
}

variable_types:
ret
unsigned char


decompiled_code:
int __fastcall char2bit(char a1)
{
char *v1; // rdx
char v2; // cl
char v3; // al
char *v4; // rax
char v5; // al
char v7[7]; // [rsp+8h] [rbp-10h] BYREF
char v8; // [rsp+Fh] [rbp-9h] BYREF

v1 = &v8;
do
{
v2 = (unsigned __int8)a1 >> 7;
v3 = a1 + ((unsigned __int8)a1 >> 7);
a1 >>= 1;
*v1 = (v3 & 1) - v2;
v4 = v1--;
}
while ( v4 != v7 );
putchar(10);
v5 = bit2char((__int64)v7);
return printf("einai %d\n", (unsigned int)v5);
}

canonical_decompiled_code:
int __fastcall func12(char a1)
{
char *v1; // rdx
char v2; // cl
char v3; // al
char *v4; // rax
char v5; // al
char v7[7]; // [rsp+8h] [rbp-10h] BYREF
char v8; // [rsp+Fh] [rbp-9h] BYREF

v1 = &v8;
do
{
v2 = (unsigned __int8)a1 >> 7;
v3 = a1 + ((unsigned __int8)a1 >> 7);
a1 >>= 1;
*v1 = (v3 & 1) - v2;
v4 = v1--;
}
while ( v4 != v7 );
putchar(10);
v5 = func10((__int64)v7);
return printf("einai %d\n", (unsigned int)v5);
}

original_code:
void char2bit(int8_t c)
{
 int8_t i, bytes[8];
 for (i = 7; i >= 0; i--) {
  bytes[i] = c%2;
  c = c >> 1;
 }
 putchar('\n');
 printf("einai %d\n", bit2char(bytes));
}

canonical_original_code:
void char2bit(char c)
{
 char i; char bytes[8];
 for (i = 7; i >= 0; i--) {
  bytes[i] = c%2;
  c = c >> 1;
 }
 putchar('\n');
 printf("einai %d\n", bit2char(bytes));
}

variable_types: c char

variable_types: i char

variable_types:
bytes
char [8]


GetNextCharacter

decompiled_code:
unsigned __int8 *__fastcall GetNextCharacter(unsigned __int8 *a1, int a2)
{
unsigned __int8 *v2; // rbp
int v3; // ebx
unsigned __int8 *v4; // rdx
int v5; // ecx
char v6; // kr00_1
unsigned __int8 *v7; // rax
__int64 v8; // rsi

v2 = a1;
v3 = a2;
printf("GETNEXTCHARACTER : Character %c ", (unsigned int)(char)a2);
v4 = a1 + 7;
do
{
v5 = v3;
LOBYTE(v5) = (unsigned __int8)v3 >> 7;
*v4 = (char)v3 % 2;
v6 = v3;
v3 += v5;
v7 = v4--;
LOBYTE(v3) = v6 / 2;
}
while ( v7 != a1 );
do
{
v8 = *v2++;
printf("%d", v8);
}
while ( v2 != a1 + 8 );
putchar(10);
return a1;
}

canonical_decompiled_code:
unsigned __int8 *__fastcall func13(unsigned __int8 *a1, int a2)
{
unsigned __int8 *v2; // rbp
int v3; // ebx
unsigned __int8 *v4; // rdx
int v5; // ecx
char v6; // kr00_1
unsigned __int8 *v7; // rax
__int64 v8; // rsi

v2 = a1;
v3 = a2;
printf("GETNEXTCHARACTER : Character %c ", (unsigned int)(char)a2);
v4 = a1 + 7;
do
{
v5 = v3;
LOBYTE(v5) = (unsigned __int8)v3 >> 7;
*v4 = (char)v3 % 2;
v6 = v3;
v3 += v5;
v7 = v4--;
LOBYTE(v3) = v6 / 2;
}
while ( v7 != a1 );
do
{
v8 = *v2++;
printf("%d", v8);
}
while ( v2 != a1 + 8 );
putchar(10);
return a1;
}

original_code:
uint8_t *GetNextCharacter(uint8_t text[], int8_t ch)
{
 int i;
 printf("GETNEXTCHARACTER : Character %c ", ch);
 for (i = 7;i >= 0;i--) {
  text[i] = ch % 2;
  ch /= 2;
 }
 for (i = 0; i < 8; i++)
  printf("%d", text[i]);
 putchar('\n');
 return text;
}

canonical_original_code:
unsigned char *GetNextCharacter(unsigned char text[], char ch)
{
 int i;
 printf("GETNEXTCHARACTER : Character %c ", ch);
 for (i = 7;i >= 0;i--) {
  text[i] = ch % 2;
  ch /= 2;
 }
 for (i = 0; i < 8; i++)
  printf("%d", text[i]);
 putchar('\n');
 return text;
}

variable_types:
text
unsigned char []

variable_types: ch char

return_type: unsigned char *


decompiled_code:
int __fastcall encrypt_bits(__int64 a1, _BYTE *a2)
{
unsigned __int8 *v3; // rax
int v4; // esi
_BYTE *v5; // rbx
unsigned __int8 *v6; // rdi
unsigned __int8 v7; // r12
__int64 i; // rax
char v9; // dl
__int64 v10; // rsi
_BYTE *v11; // rax

v3 = (unsigned __int8 *)malloc(8uLL);
v4 = (char)*a2;
v5 = (_BYTE *)qword_4041C8;
if ( *a2 )
{
v6 = v3;
v7 = 0;
do
{
++v7;
v6 = GetNextCharacter(v6, v4);
for ( i = 0LL; i != 8; ++i )
{
while ( 1 )
{
v9 = v5[i];
if ( v6[i] )
break;
v5[i++] = v9 & 0xFE;
if ( i == 8 )
goto LABEL_7;
}
v5[i] = v9 | 1;
}
LABEL_7:
v5 += 8;
v4 = (char)a2[v7];
}
while ( a2[v7] );
v10 = v7;
}
else
{
v10 = 0LL;
}
v11 = v5 + 8;
do
*v5++ &= 0xFEu;
while ( v11 != v5 );
return printf("\nCHANGEBITS : Changed successfully %d bits\n", v10);
}

canonical_decompiled_code:
int __fastcall func14(__int64 a1, _BYTE *a2)
{
unsigned __int8 *v3; // rax
int v4; // esi
_BYTE *v5; // rbx
unsigned __int8 *v6; // rdi
unsigned __int8 v7; // r12
__int64 i; // rax
char v9; // dl
__int64 v10; // rsi
_BYTE *v11; // rax

v3 = (unsigned __int8 *)malloc(8uLL);
v4 = (char)*a2;
v5 = (_BYTE *)qword_4041C8;
if ( *a2 )
{
v6 = v3;
v7 = 0;
do
{
++v7;
v6 = func13(v6, v4);
for ( i = 0LL; i != 8; ++i )
{
while ( 1 )
{
v9 = v5[i];
if ( v6[i] )
break;
v5[i++] = v9 & 0xFE;
if ( i == 8 )
goto LABEL_7;
}
v5[i] = v9 | 1;
}
LABEL_7:
v5 += 8;
v4 = (char)a2[v7];
}
while ( a2[v7] );
v10 = v7;
}
else
{
v10 = 0LL;
}
v11 = v5 + 8;
do
*v5++ &= 0xFEu;
while ( v11 != v5 );
return printf("\nCHANGEBITS : Changed successfully %d bits\n", v10);
}

original_code:
void encrypt_bits(uint8_t *ptr, int8_t TextToCrypt[])
{
 int i = 0;
 uint8_t *bytes, poschar = 0;
 bytes = (uint8_t *) malloc(8);
 ptr = header.offset;
 while (TextToCrypt[poschar]) {
  bytes = GetNextCharacter(bytes, TextToCrypt[poschar]);
  poschar++;
  for (i = 0; i < 8; i++) {
   if (bytes[i] == 0)
    ptr[i] &=0xFE;
   else
    ptr[i] |=0x01;
  }
  ptr += 8;
 }
 for (i = 0; i < 8; i++)
  ptr[i] &= 0xFE;
 printf("\nCHANGEBITS : Changed successfully %d bits\n", poschar);
}

canonical_original_code:
void encrypt_bits(unsigned char *ptr, char TextToCrypt[])
{
 int i = 0;
 unsigned char *bytes; unsigned char poschar = 0;
 bytes = (unsigned char *) malloc(8);
 ptr = header.offset;
 while (TextToCrypt[poschar]) {
  bytes = GetNextCharacter(bytes, TextToCrypt[poschar]);
  poschar++;
  for (i = 0; i < 8; i++) {
   if (bytes[i] == 0)
    ptr[i] &=0xFE;
   else
    ptr[i] |=0x01;
  }
  ptr += 8;
 }
 for (i = 0; i < 8; i++)
  ptr[i] &= 0xFE;
 printf("\nCHANGEBITS : Changed successfully %d bits\n", poschar);
}

variable_types:
ptr
unsigned char *

variable_types:
TextToCrypt
char []

variable_types:
bytes
unsigned char *

variable_types:
poschar
unsigned char


decompiled_code:
__int64 __fastcall set_headers(unsigned __int8 *a1)
{
__int64 result; // rax

dword_4041C4 = header + 10 - *a1;
dword_4041D0 = a1[22];
dword_4041D4 = a1[18];
result = a1[10];
qword_4041C8 = (__int64)&a1[result];
return result;
}

canonical_decompiled_code:
__int64 __fastcall func16(unsigned __int8 *a1)
{
__int64 result; // rax

dword_4041C4 = header + 10 - *a1;
dword_4041D0 = a1[22];
dword_4041D4 = a1[18];
result = a1[10];
qword_4041C8 = (__int64)&a1[result];
return result;
}

original_code:
void set_headers(uint8_t *ptr)
{
 header.rawsize = header.fullsize - *ptr + 0x0a;
 header.height = ptr[0x16];
 header.width = ptr[0x12];
 header.offset = &ptr[ptr[0x0a]];
}

canonical_original_code:
void set_headers(unsigned char *ptr)
{
 header.rawsize = header.fullsize - *ptr + 0x0a;
 header.height = ptr[0x16];
 header.width = ptr[0x12];
 header.offset = &ptr[ptr[0x0a]];
}


repo: aniketpansare/Process-Hibernation

decompiled_code:
void __fastcall sig_handler(unsigned int a1)
{
printf("Got signal %d!\n", a1);
}

canonical_decompiled_code:
void __fastcall func7(unsigned int a1)
{
printf("Got signal %d!\n", a1);
}

original_code:
void sig_handler(int sig) {
 printf("Got signal %d!\n", sig);
}

variable_types: sig int


main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
signal(10, sig_handler);
signal(12, sig_handler);
while ( 1 )
{
raise(10);
sleep(2u);
raise(12);
sleep(2u);
}
}

original_code:
int main() {
 signal(10, sig_handler);
 signal(12, sig_handler);
 for(;;) {
  raise(10);
  sleep(2);
  raise(12);
  sleep(2);
 }
 return 0;
}


decompiled_code:
__int64 __fastcall set_last_pid(int a1)
{
__int64 v1; // rax
__off64_t v2; // r12
int v3; // eax
int v4; // ebp
int buf[7]; // [rsp+Ch] [rbp-1Ch] BYREF

buf[0] = a1;
v1 = get_last_pid_location();
if ( !v1 )
return 0xFFFFFFFFLL;
v2 = v1;
v3 = open("/dev/kmem", 2);
v4 = v3;
if ( v3 == -1 || lseek64(v3, v2, 0) == -1 || write(v4, buf, 4uLL) == -1 )
return 0xFFFFFFFFLL;
close(v4);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func8(int a1)
{
__int64 v1; // rax
__off64_t v2; // r12
int v3; // eax
int v4; // ebp
int buf[7]; // [rsp+Ch] [rbp-1Ch] BYREF

buf[0] = a1;
v1 = func7();
if ( !v1 )
return 0xFFFFFFFFLL;
v2 = v1;
v3 = open("/dev/kmem", 2);
v4 = v3;
if ( v3 == -1 || lseek64(v3, v2, 0) == -1 || write(v4, buf, 4uLL) == -1 )
return 0xFFFFFFFFLL;
close(v4);
return 0LL;
}

original_code:
int set_last_pid(int pid)
{
 int fd;
 off64_t last_pid_loc;
 last_pid_loc = get_last_pid_location();
 if (!last_pid_loc)
  return -1;
 fd = open("/dev/kmem", 02|0);
 if (fd == -1)
  return -1;
 if (lseek64(fd, last_pid_loc, 0) == -1)
  return -1;
 if (write(fd, &pid, sizeof(pid)) == -1)
  return -1;
 close(fd);
 return 0;
}

canonical_original_code:
int set_last_pid(int pid)
{
 int fd;
 long last_pid_loc;
 last_pid_loc = get_last_pid_location();
 if (!last_pid_loc)
  return -1;
 fd = open("/dev/kmem", 02|0);
 if (fd == -1)
  return -1;
 if (lseek64(fd, last_pid_loc, 0) == -1)
  return -1;
 if (write(fd, &pid, sizeof(pid)) == -1)
  return -1;
 close(fd);
 return 0;
}

variable_types: pid int

variable_types: fd int


decompiled_code:
__int64 get_last_pid()
{
int v0; // ebp
__off64_t v1; // rax
unsigned int buf[3]; // [rsp+Ch] [rbp-Ch] BYREF

if ( !get_last_pid_location() )
return 0xFFFFFFFFLL;
v0 = open("/dev/kmem", 0);
if ( v0 == -1 )
return 0xFFFFFFFFLL;
v1 = get_last_pid_location();
if ( lseek64(v0, v1, 0) == -1 || read(v0, buf, 4uLL) == -1 )
return 0xFFFFFFFFLL;
close(v0);
return buf[0];
}

canonical_decompiled_code:
__int64 func9()
{
int v0; // ebp
__off64_t v1; // rax
unsigned int buf[3]; // [rsp+Ch] [rbp-Ch] BYREF

if ( !func7() )
return 0xFFFFFFFFLL;
v0 = open("/dev/kmem", 0);
if ( v0 == -1 )
return 0xFFFFFFFFLL;
v1 = func7();
if ( lseek64(v0, v1, 0) == -1 || read(v0, buf, 4uLL) == -1 )
return 0xFFFFFFFFLL;
close(v0);
return buf[0];
}

original_code:
int get_last_pid()
{
 int fd, last_pid;
 off64_t last_pid_loc;
 last_pid_loc = get_last_pid_location();
 if (!last_pid_loc)
  return -1;
 fd = open("/dev/kmem", 00|0);
 if (fd == -1)
  return -1;
 if (lseek64(fd, (off64_t)get_last_pid_location(), 0) == -1)
  return -1;
 if (read(fd, &last_pid, sizeof(last_pid)) == -1)
  return -1;
 close(fd);
 return last_pid;
}

canonical_original_code:
int get_last_pid()
{
 int fd; int last_pid;
 long last_pid_loc;
 last_pid_loc = get_last_pid_location();
 if (!last_pid_loc)
  return -1;
 fd = open("/dev/kmem", 00|0);
 if (fd == -1)
  return -1;
 if (lseek64(fd, (long)get_last_pid_location(), 0) == -1)
  return -1;
 if (read(fd, &last_pid, sizeof(last_pid)) == -1)
  return -1;
 close(fd);
 return last_pid;
}


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // er12
int v5; // eax
char *endptr; // [rsp+8h] [rbp-20h] BYREF

if ( argc != 3 )
goto LABEL_3;
if ( strcmp(*argv, "farewell") )
goto LABEL_3;
v3 = strcmp(argv[1], "kitty");
if ( v3 )
goto LABEL_3;
if ( geteuid() )
return 3;
v5 = strtol(argv[2], &endptr, 10);
if ( *endptr )
{
LABEL_3:
v3 = 1;
fwrite("This program is a helper for CryoPID and should not be called directly.\n", 1uLL, 0x48uLL, stderr);
}
else if ( (unsigned int)set_last_pid((unsigned int)(v5 - 1)) == -1 )
{
v3 = 2;
perror("set_last_pid");
}
return v3;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // er12
int v5; // eax
char *endptr; // [rsp+8h] [rbp-20h] BYREF

if ( argc != 3 )
goto LABEL_3;
if ( strcmp(*argv, "farewell") )
goto LABEL_3;
v3 = strcmp(argv[1], "kitty");
if ( v3 )
goto LABEL_3;
if ( geteuid() )
return 3;
v5 = strtol(argv[2], &endptr, 10);
if ( *endptr )
{
LABEL_3:
v3 = 1;
fwrite("This program is a helper for CryoPID and should not be called directly.\n", 1uLL, 0x48uLL, stderr);
}
else if ( (unsigned int)func8((unsigned int)(v5 - 1)) == -1 )
{
v3 = 2;
perror("set_last_pid");
}
return v3;
}

original_code:
int main(int argc, char **argv)
{
 int want_pid;
 if (argc == 3 && strcmp(argv[0], "farewell") == 0 &&
   strcmp(argv[1], "kitty") == 0) {
  char *endptr;
  if (geteuid() != 0)
   return 3;
  want_pid = strtol(argv[2], &endptr, 10);
  if (*endptr == '\0') {
   if (set_last_pid(want_pid-1) == -1) {
    perror("set_last_pid");
    return 2;
   }
   return 0;
  }
 }
 fprintf(stderr, "This program is a helper for CryoPID and should not be called directly.\n");
 return 1;
}

variable_types: argc int

variable_types:
argv
char **

variable_types:
endptr
char *


d

decompiled_code:
int d()
{
puts("meep");
return fflush(_bss_start);
}

canonical_decompiled_code:
int func7()
{
puts("meep");
return fflush(_bss_start);
}

original_code:
void d() {
    int k = 0;
foo:
    k = k + 1;
    if(k < 0x20000000)
        goto foo;
    printf("meep\n");
    fflush(stdout);
}

variable_types: k int


c

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

if ( a1 )
result = d();
return result;
}

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

if ( a1 )
result = func7();
return result;
}

original_code: void c(int z) { if(z)d(); }

canonical_original_code: void c(int z) { if(z)d(); }

variable_types: z int


b

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

if ( a1 )
result = c(a1);
return result;
}

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

if ( a1 )
result = func8(a1);
return result;
}

original_code: void b(int z) { if(z)c(z); }

canonical_original_code: void b(int z) { if(z)c(z); }


a

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

if ( a1 )
result = b(a1);
return result;
}

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

if ( a1 )
result = func9(a1);
return result;
}

original_code: void a(int z) { if(z)b(z); }

canonical_original_code: void a(int z) { if(z)b(z); }


main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
a(0LL, argv, envp);
b(0LL);
c(0LL);
d();
puts("moo");
fflush(_bss_start);
exit(42);
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
func10(0LL, argv, envp);
func9(0LL);
func8(0LL);
func7();
puts("moo");
fflush(_bss_start);
exit(42);
}

original_code:
int main() {
    int j = 0;
    a(0);
    b(0);
    c(0);
    d();
    printf("moo\n");
    fflush(stdout);
    exit(42);
 return 0;
}

variable_types: j int


decompiled_code:
__pid_t __fastcall fork2(unsigned int a1)
{
int v1; // ebp
int *v2; // rax
int *v3; // rbx
__pid_t result; // eax
int stat_loc; // [rsp+Ch] [rbp-3Ch] BYREF
char *argv[7]; // [rsp+10h] [rbp-38h] BYREF

v1 = kill(a1, 0);
v2 = _errno_location();
v3 = v2;
if ( v1 != -1 || *v2 != 3 )
{
*v2 = 17;
return -1;
}
result = fork();
if ( result != -1 )
{
if ( !result )
{
result = waitpid(0, &stat_loc, 0);
if ( result == -1 )
return result;
if ( (stat_loc & 0x7F) != 0 )
return -1;
result = BYTE1(stat_loc);
if ( BYTE1(stat_loc) == 3 )
{
*v3 = 1;
return -1;
}
if ( ((stat_loc >> 8) & 0xFC) != 0 )
{
if ( BYTE1(stat_loc) == 50 )
{
fwrite("Could not find fork2_helper\n", 1uLL, 0x1CuLL, stderr);
*v3 = 2;
return -1;
}
}
else
{
if ( !BYTE1(stat_loc) )
return result;
if ( BYTE1(stat_loc) == 2 )
{
*v3 = 6;
return -1;
}
}
}
argv[0] = "farewell";
argv[1] = "kitty";
argv[2] = "XXXXXXXXXX";
argv[3] = 0LL;
snprintf("XXXXXXXXXX", 0xAuLL, "%d", a1);
execve("fork2_helper", argv, environ);
perror("execve");
exit(50);
}
return result;
}

canonical_decompiled_code:
__pid_t __fastcall func0(unsigned int a1)
{
int v1; // ebp
int *v2; // rax
int *v3; // rbx
__pid_t result; // eax
int stat_loc; // [rsp+Ch] [rbp-3Ch] BYREF
char *argv[7]; // [rsp+10h] [rbp-38h] BYREF

v1 = kill(a1, 0);
v2 = _errno_location();
v3 = v2;
if ( v1 != -1 || *v2 != 3 )
{
*v2 = 17;
return -1;
}
result = fork();
if ( result != -1 )
{
if ( !result )
{
result = waitpid(0, &stat_loc, 0);
if ( result == -1 )
return result;
if ( (stat_loc & 0x7F) != 0 )
return -1;
result = BYTE1(stat_loc);
if ( BYTE1(stat_loc) == 3 )
{
*v3 = 1;
return -1;
}
if ( ((stat_loc >> 8) & 0xFC) != 0 )
{
if ( BYTE1(stat_loc) == 50 )
{
fwrite("Could not find fork2_helper\n", 1uLL, 0x1CuLL, stderr);
*v3 = 2;
return -1;
}
}
else
{
if ( !BYTE1(stat_loc) )
return result;
if ( BYTE1(stat_loc) == 2 )
{
*v3 = 6;
return -1;
}
}
}
argv[0] = "farewell";
argv[1] = "kitty";
argv[2] = "XXXXXXXXXX";
argv[3] = 0LL;
snprintf("XXXXXXXXXX", 0xAuLL, "%d", a1);
execve("fork2_helper", argv, environ);
perror("execve");
exit(50);
}
return result;
}

original_code:
int fork2(pid_t pid)
{
 extern char** environ;
 pid_t helper_pid;
 int status;
 if (kill(pid, 0) != -1 || (*__errno_location ()) != 3) {
  (*__errno_location ()) = 17;
  return -1;
 }
 switch (helper_pid = fork()) {
  case -1:
   return -1;
  case 0:
   if (waitpid(helper_pid, &status, 0) == -1)
    return -1;
   if ((((status) & 0x7f) == 0)) {
    switch ((((status) & 0xff00) >> 8)) {
     case 0:
      return 0;
     case 2:
      (*__errno_location ()) = 6;
      return -1;
     case 3:
      (*__errno_location ()) = 1;
      return -1;
     case 50:
      fprintf(stderr, "Could not find fork2_helper\n");
      (*__errno_location ()) = 2;
      return -1;
    }
   } else
    return -1;
  default:
   {
    char *argv[] = {"farewell", "kitty", "XXXXXXXXXX", ((void *)0)};
    snprintf(argv[2], 10, "%d", pid);
    execve("fork2_helper", argv, environ);
    perror("execve");
    _exit(50);
   }
 }
 return fork();
}

canonical_original_code:
int fork2(int pid)
{
 extern char **environ;
 int helper_pid;
 int status;
 if (kill(pid, 0) != -1 || (*__errno_location ()) != 3) {
  (*__errno_location ()) = 17;
  return -1;
 }
 switch (helper_pid = fork()) {
  case -1:
   return -1;
  case 0:
   if (waitpid(helper_pid, &status, 0) == -1)
    return -1;
   if ((((status) & 0x7f) == 0)) {
    switch ((((status) & 0xff00) >> 8)) {
     case 0:
      return 0;
     case 2:
      (*__errno_location ()) = 6;
      return -1;
     case 3:
      (*__errno_location ()) = 1;
      return -1;
     case 50:
      fprintf(stderr, "Could not find fork2_helper\n");
      (*__errno_location ()) = 2;
      return -1;
    }
   } else
    return -1;
  default:
   {
    char *argv[] = {"farewell", "kitty", "XXXXXXXXXX", ((void *)0)};
    snprintf(argv[2], 10, "%d", pid);
    execve("fork2_helper", argv, environ);
    perror("execve");
    _exit(50);
   }
 }
 return fork();
}

variable_types:
environ
char **

variable_types: status int

variable_types:
argv
char *[]


decompiled_code:
void *gimme_some_memory()
{
return malloc(0x100000uLL);
}

canonical_decompiled_code:
void *func7()
{
return malloc(0x100000uLL);
}

original_code:
void* gimme_some_memory() {
 return malloc((1024*1024));
}

canonical_original_code:
void *gimme_some_memory() {
 return malloc((1024*1024));
}

return_type: void *


decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
int v3; // ebx
__int64 v4; // r12
__int64 v5; // rdx
__int64 v6; // rbp

v3 = 0;
v4 = gimme_some_memory(argc, argv, envp);
v6 = gimme_some_memory(argc, argv, v5);
fill_in(v4);
fill_in(v6);
while ( 1 )
{
do
{
play_with(v4, v6, (unsigned int)v3);
printf("Loop done, offset = %d\n", (unsigned int)v3++);
sleep(1u);
}
while ( v3 < 257 );
v3 = 0;
}
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
int v3; // ebx
__int64 v4; // r12
__int64 v5; // rdx
__int64 v6; // rbp

v3 = 0;
v4 = func7(argc, argv, envp);
v6 = func7(argc, argv, v5);
func8(v4);
func8(v6);
while ( 1 )
{
do
{
func9(v4, v6, (unsigned int)v3);
printf("Loop done, offset = %d\n", (unsigned int)v3++);
sleep(1u);
}
while ( v3 < 257 );
v3 = 0;
}
}

original_code:
int main() {
 unsigned char *mem1, *mem2;
 int offset;
 mem1 = (unsigned char*)gimme_some_memory();
 mem2 = (unsigned char*)gimme_some_memory();
 fill_in(mem1);
 fill_in(mem2);
 offset = 0;
 do {
        int j;
  play_with(mem1, mem2, offset);
        printf("Loop done, offset = %d\n", offset);
  sleep(1);
  offset++;
  if (offset > 256) offset = 0;
 } while(1);
 return 0;
}

canonical_original_code:
int main() {
 unsigned char *mem1; unsigned char *mem2;
 int offset;
 mem1 = (unsigned char *)gimme_some_memory();
 mem2 = (unsigned char *)gimme_some_memory();
 fill_in(mem1);
 fill_in(mem2);
 offset = 0;
 do {
        int j;
  play_with(mem1, mem2, offset);
        printf("Loop done, offset = %d\n", offset);
  sleep(1);
  offset++;
  if (offset > 256) offset = 0;
 } while(1);
 return 0;
}

variable_types: offset int


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // rbp
char **v4; // rbx
const char **v5; // r13
_DWORD *v6; // r12
__int64 v7; // rdx
const char *v8; // rbp
const char *v9; // r12
__int64 v11; // [rsp+0h] [rbp-38h] BYREF
unsigned int *v12; // [rsp+8h] [rbp-30h] BYREF

v3 = "10.10.1.0";
v4 = elems_0;
v5 = (const char **)elems_0;
v11 = 0LL;
do
{
++v5;
v6 = malloc(4uLL);
v7 = (unsigned int)strlen(v3) + 10;
*v6 = v7;
printf("\n Insert %s = %d at %p\n", v3, v7, v6);
critbit0_insert(&v11, v3, v6);
v3 = *v5;
}
while ( *v5 );
v8 = "10.10.255.0";
v9 = "10.10.1.0";
while ( 1 )
{
if ( (unsigned int)critbit0_contains(&v11, v9, &v12) )
printf("\n Contains: %s %lx, > %d\n", v9, v12, *v12);
++v4;
if ( !v8 )
break;
v9 = v8;
v8 = v4[1];
}
critbit0_allprefixed(&v11, "", cbk, 0LL);
critbit0_clear(&v11);
puts("\n");
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // rbp
char **v4; // rbx
const char **v5; // r13
_DWORD *v6; // r12
__int64 v7; // rdx
const char *v8; // rbp
const char *v9; // r12
__int64 v11; // [rsp+0h] [rbp-38h] BYREF
unsigned int *v12; // [rsp+8h] [rbp-30h] BYREF

v3 = "10.10.1.0";
v4 = elems_0;
v5 = (const char **)elems_0;
v11 = 0LL;
do
{
++v5;
v6 = malloc(4uLL);
v7 = (unsigned int)strlen(v3) + 10;
*v6 = v7;
printf("\n Insert %s = %d at %p\n", v3, v7, v6);
func10(&v11, v3, v6);
v3 = *v5;
}
while ( *v5 );
v8 = "10.10.255.0";
v9 = "10.10.1.0";
while ( 1 )
{
if ( (unsigned int)func9(&v11, v9, &v12) )
printf("\n Contains: %s %lx, > %d\n", v9, v12, *v12);
++v4;
if ( !v8 )
break;
v9 = v8;
v8 = v4[1];
}
func13(&v11, "", cbk, 0LL);
func12(&v11);
puts("\n");
return 0;
}

original_code:
int main()
{
    critbit0_tree tree = { 0 };
    int *v;
    int i;
    static const char *elems[] =
       { "10.10.1.0", "10.10.255.0", "10.10.12.0", ((void *)0)};
    for (i = 0; elems[i]; ++i) {
        v = malloc(sizeof(int));
        *v = 10+strlen(elems[i]);
        printf ("\n Insert %s = %d at %p\n", elems[i], *v, v );
 critbit0_insert(&tree, elems[i], v);
    }
    int x;
    uintptr_t p;
    for (i = 0; elems[i]; ++i) {
        if (critbit0_contains(&tree, elems[i], &p)) {
            x = *(int*)p;
            printf ("\n Contains: %s %""l" "x"", > %d\n",elems[i], p, x);
        }
    }
    critbit0_allprefixed(&tree, "", cbk, ((void *)0));
    critbit0_clear(&tree);
    printf ("\n\n");
    return 0;
}

canonical_original_code:
int main()
{
    struct critbit0_tree tree = { 0 };
    int *v;
    int i;
    static char *elems[] = { "10.10.1.0", "10.10.255.0", "10.10.12.0", ((void *)0)};
    for (i = 0; elems[i]; ++i) {
        v = malloc(sizeof(int));
        *v = 10+strlen(elems[i]);
        printf ("\n Insert %s = %d at %p\n", elems[i], *v, v );
 critbit0_insert(&tree, elems[i], v);
    }
    int x;
    unsigned long p;
    for (i = 0; elems[i]; ++i) {
        if (critbit0_contains(&tree, elems[i], &p)) {
            x = *(int *)p;
            printf ("\n Contains: %s %""l" "x"", > %d\n",elems[i], p, x);
        }
    }
    critbit0_allprefixed(&tree, "", cbk, ((void *)0));
    critbit0_clear(&tree);
    printf ("\n\n");
    return 0;
}

variable_types:
tree
struct critbit0_tree { void *root; }

variable_types:
v
int *

variable_types: i int

variable_types:
elems
char *[]

variable_types: x int

variable_types:
p
unsigned long


decompiled_code:
__int64 __fastcall allprefixed_traverse(__int64 a1, __int64 (__fastcall *a2)(__int64, __int64), __int64 a3)
{
int v3; // eax
__int64 result; // rax

if ( (a1 & 1) == 0 )
return a2(a1, a3);
v3 = allprefixed_traverse(*(_QWORD *)(a1 - 1));
if ( !v3 )
return 0LL;
if ( v3 != 1 )
return 0xFFFFFFFFLL;
result = allprefixed_traverse(*(_QWORD *)(a1 + 7));
if ( !(_DWORD)result )
return 0LL;
if ( (_DWORD)result != 1 )
return 0xFFFFFFFFLL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, __int64 (__fastcall *a2)(__int64, __int64), __int64 a3)
{
int v3; // eax
__int64 result; // rax

if ( (a1 & 1) == 0 )
return a2(a1, a3);
v3 = func7(*(_QWORD *)(a1 - 1));
if ( !v3 )
return 0LL;
if ( v3 != 1 )
return 0xFFFFFFFFLL;
result = func7(*(_QWORD *)(a1 + 7));
if ( !(_DWORD)result )
return 0LL;
if ( (_DWORD)result != 1 )
return 0xFFFFFFFFLL;
return result;
}

original_code:
static int
allprefixed_traverse (uint8_t * top,
        int (*handle) (const char *, void *), void *arg)
{
    if (1 & (intptr_t) top) {
        int direction;
        critbit0_node *q = (void *) (top - 1);
        for (direction = 0; direction < 2; ++direction)
            switch (allprefixed_traverse (q->child[direction], handle, arg)) {
                case 1:
                    break;
                case 0:
                    return 0;
                default:
                    return -1;
            }
        return 1;
    }
  return handle ((const char *) top, arg);
}

canonical_original_code:
static int allprefixed_traverse(unsigned char *top, int (*handle)(char *, void *), void *arg)
{
    if (1 & (long) top) {
        int direction;
        struct critbit0_node *q = (void *) (top - 1);
        for (direction = 0; direction < 2; ++direction)
            switch (allprefixed_traverse (q->child[direction], handle, arg)) {
                case 1:
                    break;
                case 0:
                    return 0;
                default:
                    return -1;
            }
        return 1;
    }
  return handle ((char *) top, arg);
}

variable_types:
top
unsigned char *

variable_types:
handle
int (*)(char *, void *)

variable_types:
arg
void *

variable_types: direction int

variable_types: struct critbit0_node { void *child[2]; unsigned int byte; unsigned char otherbits; } *


traverse

decompiled_code:
void __fastcall traverse(__int64 a1)
{
if ( (a1 & 1) != 0 )
{
traverse(*(_QWORD *)(a1 - 1));
traverse(*(_QWORD *)(a1 + 7));
free((void *)(a1 - 1));
}
else
{
free((void *)a1);
}
}

original_code:
static void
traverse (void *top)
{
    uint8_t *p = top;
    if (1 & (intptr_t) p) {
        critbit0_node *q = (void *) (p - 1);
        traverse (q->child[0]);
        traverse (q->child[1]);
        free (q);
    } else {
        free (p);
    }
}

canonical_original_code:
static void traverse(void *top)
{
    unsigned char *p = top;
    if (1 & (long) p) {
        struct critbit0_node *q = (void *) (p - 1);
        traverse (q->child[0]);
        traverse (q->child[1]);
        free (q);
    } else {
        free (p);
    }
}

variable_types:
top
void *

variable_types:
p
unsigned char *

user_defined_types: struct critbit0_node { void *child[2]; unsigned int byte; unsigned char otherbits; }


decompiled_code:
__int64 __fastcall critbit0_contains(__int64 *a1, const char *a2, _QWORD *a3)
{
__int64 v3; // rbp
size_t i; // r12
size_t v6; // rdx
char v7; // al
int v8; // er8
__int64 result; // rax

v3 = *a1;
if ( !*a1 )
return 0LL;
for ( i = strlen(a2);
(v3 & 1) != 0;
v3 = *(_QWORD *)(v3 + 8LL * (((unsigned __int8)(*(_BYTE *)(v3 + 19) | v7) + 1) >> 8) - 1) )
{
v6 = *(unsigned int *)(v3 + 15);
v7 = 0;
if ( v6 < i )
v7 = a2[v6];
}
v8 = strcmp(a2, (const char *)v3);
result = 0LL;
if ( !v8 )
{
*a3 = *(_QWORD *)(v3 + i + 1);
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 *a1, const char *a2, _QWORD *a3)
{
__int64 v3; // rbp
size_t i; // r12
size_t v6; // rdx
char v7; // al
int v8; // er8
__int64 result; // rax

v3 = *a1;
if ( !*a1 )
return 0LL;
for ( i = strlen(a2);
(v3 & 1) != 0;
v3 = *(_QWORD *)(v3 + 8LL * (((unsigned __int8)(*(_BYTE *)(v3 + 19) | v7) + 1) >> 8) - 1) )
{
v6 = *(unsigned int *)(v3 + 15);
v7 = 0;
if ( v6 < i )
v7 = a2[v6];
}
v8 = strcmp(a2, (const char *)v3);
result = 0LL;
if ( !v8 )
{
*a3 = *(_QWORD *)(v3 + i + 1);
result = 1LL;
}
return result;
}

original_code:
int
critbit0_contains (critbit0_tree * t, const char *u, void *opq)
{
  const uint8_t *ubytes = (void *) u;
  const size_t ulen = strlen (u);
  uint8_t *p = t->root;
  if (!p)
    return 0;
  while (1 & (intptr_t) p) {
      critbit0_node *q = (void *) (p - 1);
      uint8_t c = 0;
      if (q->byte < ulen)
          c = ubytes[q->byte];
      const int direction = (1 + (q->otherbits | c)) >> 8;
      p = q->child[direction];
  }
  if (0 == strcmp (u, (const char *) p)) {
      memcpy(opq, p + ulen + 1, sizeof(void*));
      return 1;
  }
  return 0;
}

canonical_original_code:
int critbit0_contains(struct critbit0_tree *t, char *u, void *opq)
{
  unsigned char *ubytes = (void *) u;
  unsigned long ulen = strlen (u);
  unsigned char *p = t->root;
  if (!p)
    return 0;
  while (1 & (long) p) {
      struct critbit0_node *q = (void *) (p - 1);
      unsigned char c = 0;
      if (q->byte < ulen)
          c = ubytes[q->byte];
      int direction = (1 + (q->otherbits | c)) >> 8;
      p = q->child[direction];
  }
  if (0 == strcmp (u, (char *) p)) {
      memcpy(opq, p + ulen + 1, sizeof(void *));
      return 1;
  }
  return 0;
}

variable_types:
t
struct critbit0_tree { void *root; } *

variable_types:
u
char *

variable_types:
opq
void *

variable_types:
ubytes
unsigned char *

variable_types:
ulen
unsigned long

variable_types:
c
unsigned char


original_code:
int
critbit0_insert (critbit0_tree * t, const char *u, void *opq)
{
  const uint8_t *const ubytes = (void *) u;
  const size_t ulen = strlen (u);
  uint8_t *p = t->root;
  if (!p) {
      char *x;
      if (posix_memalign ((void **) &x, sizeof (void *), ulen + 1 + sizeof (void*)))
          return 0 ;
      memcpy (x, u, ulen + 1);
      memcpy (x + ulen + 1, &opq, sizeof(void*));
      t->root = x;
      return 2;
  }
  while (1 & (intptr_t) p) {
      critbit0_node *q = (void *) (p - 1);
      uint8_t c = 0;
      if (q->byte < ulen)
          c = ubytes[q->byte];
      const int direction = (1 + (q->otherbits | c)) >> 8;
      p = q->child[direction];
  }
  uint32_t newbyte;
  uint32_t newotherbits;
  for (newbyte = 0; newbyte < ulen; ++newbyte) {
      if (p[newbyte] != ubytes[newbyte]) {
          newotherbits = p[newbyte] ^ ubytes[newbyte];
          goto different_byte_found;
      }
  }
  if (p[newbyte] != 0) {
      newotherbits = p[newbyte];
      goto different_byte_found;
  }
  return 1;
different_byte_found:
  newotherbits |= newotherbits >> 1;
  newotherbits |= newotherbits >> 2;
  newotherbits |= newotherbits >> 4;
  newotherbits = (newotherbits & ~(newotherbits >> 1)) ^ 255;
  uint8_t c = p[newbyte];
  int newdirection = (1 + (newotherbits | c)) >> 8;
  critbit0_node *newnode;
  if (posix_memalign
      ((void **) &newnode, sizeof (void *), sizeof (critbit0_node)))
    return 0;
  char *x;
  if (posix_memalign ((void **) &x, sizeof (void *), ulen + 1 + sizeof(void*))) {
      free (newnode);
      return 0;
  }
  memcpy (x, ubytes, ulen + 1);
  memcpy (x + ulen + 1, &opq, sizeof(void*));
  newnode->byte = newbyte;
  newnode->otherbits = newotherbits;
  newnode->child[1 - newdirection] = x;
  void **wherep = &t->root;
  for (;;) {
      uint8_t *p = *wherep;
      if (!(1 & (intptr_t) p))
          break;
      critbit0_node *q = (void *) (p - 1);
      if (q->byte > newbyte)
          break;
      if (q->byte == newbyte && q->otherbits > newotherbits)
          break;
      uint8_t c = 0;
      if (q->byte < ulen)
          c = ubytes[q->byte];
      const int direction = (1 + (q->otherbits | c)) >> 8;
      wherep = q->child + direction;
  }
  newnode->child[newdirection] = *wherep;
  *wherep = (void *) (1 + (char *) newnode);
  return 2;
}

canonical_original_code:
int critbit0_insert(struct critbit0_tree *t, char *u, void *opq)
{
  unsigned char *ubytes = (void *) u;
  unsigned long ulen = strlen (u);
  unsigned char *p = t->root;
  if (!p) {
      char *x;
      if (posix_memalign ((void **) &x, sizeof (void *), ulen + 1 + sizeof (void *)))
          return 0 ;
      memcpy (x, u, ulen + 1);
      memcpy (x + ulen + 1, &opq, sizeof(void *));
      t->root = x;
      return 2;
  }
  while (1 & (long) p) {
      struct critbit0_node *q = (void *) (p - 1);
      unsigned char c = 0;
      if (q->byte < ulen)
          c = ubytes[q->byte];
      int direction = (1 + (q->otherbits | c)) >> 8;
      p = q->child[direction];
  }
  unsigned int newbyte;
  unsigned int newotherbits;
  for (newbyte = 0; newbyte < ulen; ++newbyte) {
      if (p[newbyte] != ubytes[newbyte]) {
          newotherbits = p[newbyte] ^ ubytes[newbyte];
          goto different_byte_found;
      }
  }
  if (p[newbyte] != 0) {
      newotherbits = p[newbyte];
      goto different_byte_found;
  }
  return 1;
different_byte_found:
  newotherbits |= newotherbits >> 1;
  newotherbits |= newotherbits >> 2;
  newotherbits |= newotherbits >> 4;
  newotherbits = (newotherbits & ~(newotherbits >> 1)) ^ 255;
  unsigned char c = p[newbyte];
  int newdirection = (1 + (newotherbits | c)) >> 8;
  struct critbit0_node *newnode;
  if (posix_memalign
      ((void **) &newnode, sizeof (void *), sizeof (critbit0_node)))
    return 0;
  char *x;
  if (posix_memalign ((void **) &x, sizeof (void *), ulen + 1 + sizeof(void *))) {
      free (newnode);
      return 0;
  }
  memcpy (x, ubytes, ulen + 1);
  memcpy (x + ulen + 1, &opq, sizeof(void *));
  newnode->byte = newbyte;
  newnode->otherbits = newotherbits;
  newnode->child[1 - newdirection] = x;
  void **wherep = &t->root;
  for (;;) {
      unsigned char *p = *wherep;
      if (!(1 & (long) p))
          break;
      struct critbit0_node *q = (void *) (p - 1);
      if (q->byte > newbyte)
          break;
      if (q->byte == newbyte && q->otherbits > newotherbits)
          break;
      unsigned char c = 0;
      if (q->byte < ulen)
          c = ubytes[q->byte];
      int direction = (1 + (q->otherbits | c)) >> 8;
      wherep = q->child + direction;
  }
  newnode->child[newdirection] = *wherep;
  *wherep = (void *) (1 + (char *) newnode);
  return 2;
}

variable_types:
x
char *

variable_types:
newbyte
unsigned int

variable_types:
newotherbits
unsigned int

variable_types: newdirection int

variable_types:
wherep
void **


decompiled_code:
__int64 __fastcall critbit0_delete(char *a1, const char *a2, _QWORD *a3)
{
char *v3; // r14
char *v4; // r12
size_t v5; // r15
size_t v6; // rdx
char v7; // al
int v8; // ebx
const char **v9; // rax
char *v10; // r13
int v11; // er9
__int64 result; // rax
int v13; // er8

v3 = a1;
v4 = *(char **)a1;
if ( !*(_QWORD *)a1 )
return 0LL;
v5 = strlen(a2);
if ( ((unsigned __int8)v4 & 1) != 0 )
{
while ( 1 )
{
v6 = *(unsigned int *)(v4 + 15);
v7 = 0;
if ( v6 < v5 )
v7 = a2[v6];
v8 = ((unsigned __int8)(v4[19] | v7) + 1) >> 8;
v9 = (const char **)&v4[8 * v8 - 1];
v10 = (char *)*v9;
if ( ((unsigned __int8)*v9 & 1) == 0 )
break;
v3 = &v4[8 * v8 - 1];
v4 = (char *)*v9;
}
v11 = strcmp(a2, *v9);
result = 0LL;
if ( !v11 )
{
*a3 = *(_QWORD *)&v10[v5 + 1];
free(v10);
*(_QWORD *)v3 = *(_QWORD *)&v4[8 * (1 - v8) - 1];
free(v4 - 1);
result = 1LL;
}
}
else
{
v13 = strcmp(a2, v4);
result = 0LL;
if ( !v13 )
{
*a3 = *(_QWORD *)&v4[v5 + 1];
free(v4);
*(_QWORD *)a1 = 0LL;
result = 1LL;
}
}
return result;
}

original_code:
int
critbit0_delete (critbit0_tree * t, const char *u, void *opq)
{
  const uint8_t *ubytes = (void *) u;
  const size_t ulen = strlen (u);
  uint8_t *p = t->root;
  void **wherep = &t->root;
  void **whereq = 0;
  critbit0_node *q = 0;
  int direction = 0;
  if (!p)
    return 0;
  while (1 & (intptr_t) p) {
      whereq = wherep;
      q = (void *) (p - 1);
      uint8_t c = 0;
      if (q->byte < ulen)
          c = ubytes[q->byte];
      direction = (1 + (q->otherbits | c)) >> 8;
      wherep = q->child + direction;
      p = *wherep;
  }
  if (0 != strcmp (u, (const char *) p))
    return 0;
  memcpy(opq, p + ulen + 1, sizeof(void*));
  free (p);
  if (!whereq) {
      t->root = 0;
      return 1;
  }
  *whereq = q->child[1 - direction];
  free (q);
  return 1;
}

canonical_original_code:
int critbit0_delete(struct critbit0_tree *t, char *u, void *opq)
{
  unsigned char *ubytes = (void *) u;
  unsigned long ulen = strlen (u);
  unsigned char *p = t->root;
  void **wherep = &t->root;
  void **whereq = 0;
  struct critbit0_node *q = 0;
  int direction = 0;
  if (!p)
    return 0;
  while (1 & (long) p) {
      whereq = wherep;
      q = (void *) (p - 1);
      unsigned char c = 0;
      if (q->byte < ulen)
          c = ubytes[q->byte];
      direction = (1 + (q->otherbits | c)) >> 8;
      wherep = q->child + direction;
      p = *wherep;
  }
  if (0 != strcmp (u, (char *) p))
    return 0;
  memcpy(opq, p + ulen + 1, sizeof(void *));
  free (p);
  if (!whereq) {
      t->root = 0;
      return 1;
  }
  *whereq = q->child[1 - direction];
  free (q);
  return 1;
}

variable_types:
whereq
void **


decompiled_code:
void __fastcall critbit0_clear(__int64 *a1)
{
__int64 v2; // rdi

v2 = *a1;
if ( v2 )
traverse(v2);
*a1 = 0LL;
}

canonical_decompiled_code:
void __fastcall func12(__int64 *a1)
{
__int64 v2; // rdi

v2 = *a1;
if ( v2 )
func8(v2);
*a1 = 0LL;
}

original_code:
void
critbit0_clear (critbit0_tree * t)
{
  if (t->root)
    traverse (t->root);
  t->root = ((void *)0);
}

canonical_original_code:
void critbit0_clear(struct critbit0_tree *t)
{
  if (t->root)
    traverse (t->root);
  t->root = ((void *)0);
}


decompiled_code:
__int64 __fastcall critbit0_allprefixed(__int64 *a1, const char *a2, __int64 (__fastcall *a3)(__int64, __int64), __int64 a4)
{
__int64 v4; // r13
__int64 v7; // rdi
size_t v8; // rdx
size_t v9; // rcx
int v10; // eax
__int64 v11; // rax

v4 = *a1;
if ( !*a1 )
return 1LL;
v7 = *a1;
v8 = strlen(a2);
while ( (v4 & 1) != 0 )
{
while ( 1 )
{
v9 = *(unsigned int *)(v4 + 15);
v10 = *(unsigned __int8 *)(v4 + 19);
if ( v9 >= v8 )
break;
v4 = *(_QWORD *)(v4 + 8LL * (((unsigned __int8)(a2[v9] | v10) + 1) >> 8) - 1);
v7 = v4;
if ( (v4 & 1) == 0 )
goto LABEL_6;
}
v4 = *(_QWORD *)(v4 + 8LL * ((v10 + 1) >> 8) - 1);
}
LABEL_6:
if ( v8 )
{
v11 = 0LL;
while ( *(_BYTE *)(v4 + v11) == a2[v11] )
{
if ( v8 == ++v11 )
return allprefixed_traverse(v7, a3, a4);
}
return 1LL;
}
return allprefixed_traverse(v7, a3, a4);
}

original_code:
int
critbit0_allprefixed (critbit0_tree * t, const char *prefix,
        int (*handle) (const char *, void *), void *arg)
{
  const uint8_t *ubytes = (void *) prefix;
  const size_t ulen = strlen (prefix);
  uint8_t *p = t->root;
  uint8_t *top = p;
  if (!p)
    return 1;
  while (1 & (intptr_t) p) {
      critbit0_node *q = (void *) (p - 1);
      uint8_t c = 0;
      if (q->byte < ulen)
          c = ubytes[q->byte];
      const int direction = (1 + (q->otherbits | c)) >> 8;
      p = q->child[direction];
      if (q->byte < ulen)
          top = p;
  }
  size_t i;
  for (i = 0; i < ulen; ++i) {
      if (p[i] != ubytes[i])
          return 1;
  }
  return allprefixed_traverse (top, handle, arg);
}

canonical_original_code:
int critbit0_allprefixed(struct critbit0_tree *t, char *prefix, int (*handle)(char *, void *), void *arg)
{
  unsigned char *ubytes = (void *) prefix;
  unsigned long ulen = strlen (prefix);
  unsigned char *p = t->root;
  unsigned char *top = p;
  if (!p)
    return 1;
  while (1 & (long) p) {
      struct critbit0_node *q = (void *) (p - 1);
      unsigned char c = 0;
      if (q->byte < ulen)
          c = ubytes[q->byte];
      int direction = (1 + (q->otherbits | c)) >> 8;
      p = q->child[direction];
      if (q->byte < ulen)
          top = p;
  }
  unsigned long i;
  for (i = 0; i < ulen; ++i) {
      if (p[i] != ubytes[i])
          return 1;
  }
  return allprefixed_traverse (top, handle, arg);
}

variable_types:
prefix
char *

variable_types:
handle
int (*)(char *, void *)

variable_types:
arg
void *

variable_types:
top
unsigned char *

variable_types:
i
unsigned long


cbk

decompiled_code:
__int64 __fastcall cbk(const char *a1)
{
unsigned int *v1; // r12

v1 = *(unsigned int **)&a1[strlen(a1) + 1];
printf("\n ToFree PTRs: p [%s], %p, =%d=", a1, v1, *v1);
free(v1);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func14(const char *a1)
{
unsigned int *v1; // r12

v1 = *(unsigned int **)&a1[strlen(a1) + 1];
printf("\n ToFree PTRs: p [%s], %p, =%d=", a1, v1, *v1);
free(v1);
return 1LL;
}

original_code:
int cbk (const char *e, void *p)
{
    int *v;
    memcpy(&v, e+strlen(e)+1, sizeof(void*));
    printf ("\n ToFree PTRs: p [%s], %p, =%d=", e, (v) , *v);
    free(v);
    return 1;
}

canonical_original_code:
int cbk(char *e, void *p)
{
    int *v;
    memcpy(&v, e+strlen(e)+1, sizeof(void *));
    printf ("\n ToFree PTRs: p [%s], %p, =%d=", e, (v) , *v);
    free(v);
    return 1;
}

variable_types:
e
char *

variable_types:
p
void *

variable_types:
v
int *


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rax
__int64 v4; // rbp

if ( !(unsigned int)CU_initialize_registry(argc, argv, envp) )
{
v3 = CU_add_suite("Suite_UTIL", &init_suite_UTIL, &clean_suite_UTIL);
v4 = v3;
if ( v3
&& CU_add_test(v3, "test of type_c_to_composite()", &type_c_to_composite_test)
&& CU_add_test(v4, "test of type_c_from_str()", &type_c_from_str_test)
&& CU_add_test(v4, "test of type_c_to_str()", &type_c_to_str_test)
&& CU_add_test(v4, "test of type_composite_from_str()", &type_composite_from_str_test)
&& CU_add_test(v4, "test of type_composite_to_str()", &type_composite_to_str_test)
&& CU_add_test(v4, "test of function_header()", &function_header_test)
&& CU_add_test(v4, "test of function_set_name()", &function_set_name_test)
&& CU_add_test(v4, "test of parameter_declaration_set()", &parameter_declaration_set_test)
&& CU_add_test(v4, "test of function_var()", &function_var_test)
&& CU_add_test(v4, "test of init_declarator_set()", &init_declarator_set_test)
&& CU_add_test(v4, "test of function_add_command()", &function_add_command_test)
&& CU_add_test(v4, "test of function_code()", &function_code_test)
&& CU_add_test(v4, "test of function_get_var()", &function_get_var_test)
&& CU_add_test(v4, "test of function_copy_var()", &function_copy_var_test)
&& CU_add_test(v4, "test of unique_label_name()", &unique_label_name_test)
&& CU_add_test(v4, "test of unique_var_name()", &unique_var_name_test)
&& CU_add_test(v4, "test of function_get_type()", &function_get_type_test)
&& CU_add_test(v4, "test of implicit_cast_type()", &implicit_cast_type_test) )
{
CU_basic_set_mode(2LL);
CU_basic_run_tests();
}
CU_cleanup_registry();
}
return CU_get_error();
}

original_code:
int main(int argc, char **argv)
{
 CU_pSuite psuite = ((void *)0);
 if (CU_initialize_registry() != CUE_SUCCESS)
  return CU_get_error();
 psuite = CU_add_suite("Suite_UTIL", init_suite_UTIL, clean_suite_UTIL);
 if (psuite == ((void *)0))
 {
  CU_cleanup_registry();
  return CU_get_error();
 }
 if((CU_add_test(psuite, "test of type_c_to_composite()", type_c_to_composite_test) == ((void *)0)))
 {
  CU_cleanup_registry();
  return CU_get_error();
 }
 if((CU_add_test(psuite, "test of type_c_from_str()", type_c_from_str_test) == ((void *)0)))
 {
  CU_cleanup_registry();
  return CU_get_error();
 }
 if((CU_add_test(psuite, "test of type_c_to_str()", type_c_to_str_test) == ((void *)0)))
 {
  CU_cleanup_registry();
  return CU_get_error();
 }
 if((CU_add_test(psuite, "test of type_composite_from_str()", type_composite_from_str_test) == ((void *)0)))
 {
  CU_cleanup_registry();
  return CU_get_error();
 }
 if((CU_add_test(psuite, "test of type_composite_to_str()", type_composite_to_str_test) == ((void *)0)))
 {
  CU_cleanup_registry();
  return CU_get_error();
 }
 if((CU_add_test(psuite, "test of function_header()", function_header_test) == ((void *)0)))
 {
  CU_cleanup_registry();
  return CU_get_error();
 }
 if((CU_add_test(psuite, "test of function_set_name()", function_set_name_test) == ((void *)0)))
 {
  CU_cleanup_registry();
  return CU_get_error();
 }
 if((CU_add_test(psuite, "test of  parameter_declaration_set()", parameter_declaration_set_test) == ((void *)0)))
 {
  CU_cleanup_registry();
  return CU_get_error();
 }
 if((CU_add_test(psuite, "test of  function_var()", function_var_test) == ((void *)0)))
 {
  CU_cleanup_registry();
  return CU_get_error();
 }
 if((CU_add_test(psuite, "test of  init_declarator_set()", init_declarator_set_test) == ((void *)0)))
 {
  CU_cleanup_registry();
  return CU_get_error();
 }
 if((CU_add_test(psuite, "test of  function_add_command()", function_add_command_test) == ((void *)0)))
 {
  CU_cleanup_registry();
  return CU_get_error();
 }
 if((CU_add_test(psuite, "test of  function_code()", function_code_test) == ((void *)0)))
 {
  CU_cleanup_registry();
  return CU_get_error();
 }
 if((CU_add_test(psuite, "test of  function_get_var()", function_get_var_test) == ((void *)0)))
 {
  CU_cleanup_registry();
  return CU_get_error();
 }
 if((CU_add_test(psuite, "test of  function_copy_var()", function_copy_var_test) == ((void *)0)))
 {
  CU_cleanup_registry();
  return CU_get_error();
 }
 if((CU_add_test(psuite, "test of  unique_label_name()", unique_label_name_test) == ((void *)0)))
 {
  CU_cleanup_registry();
  return CU_get_error();
 }
 if((CU_add_test(psuite, "test of  unique_var_name()", unique_var_name_test) == ((void *)0)))
 {
  CU_cleanup_registry();
  return CU_get_error();
 }
 if((CU_add_test(psuite, "test of  function_get_type()", function_get_type_test) == ((void *)0)))
 {
  CU_cleanup_registry();
  return CU_get_error();
 }
 if((CU_add_test(psuite, "test of  implicit_cast_type()", implicit_cast_type_test) == ((void *)0)))
 {
  CU_cleanup_registry();
  return CU_get_error();
 }
 CU_basic_set_mode(CU_BRM_VERBOSE);
 CU_basic_run_tests();
 CU_cleanup_registry();
 return CU_get_error();
}

canonical_original_code:
int main(int argc, char **argv)
{
 struct CU_Suite *psuite = ((void *)0);
 if (CU_initialize_registry() != CUE_SUCCESS)
  return CU_get_error();
 psuite = CU_add_suite("Suite_UTIL", init_suite_UTIL, clean_suite_UTIL);
 if (psuite == ((void *)0))
 {
  CU_cleanup_registry();
  return CU_get_error();
 }
 if((CU_add_test(psuite, "test of type_c_to_composite()", type_c_to_composite_test) == ((void *)0)))
 {
  CU_cleanup_registry();
  return CU_get_error();
 }
 if((CU_add_test(psuite, "test of type_c_from_str()", type_c_from_str_test) == ((void *)0)))
 {
  CU_cleanup_registry();
  return CU_get_error();
 }
 if((CU_add_test(psuite, "test of type_c_to_str()", type_c_to_str_test) == ((void *)0)))
 {
  CU_cleanup_registry();
  return CU_get_error();
 }
 if((CU_add_test(psuite, "test of type_composite_from_str()", type_composite_from_str_test) == ((void *)0)))
 {
  CU_cleanup_registry();
  return CU_get_error();
 }
 if((CU_add_test(psuite, "test of type_composite_to_str()", type_composite_to_str_test) == ((void *)0)))
 {
  CU_cleanup_registry();
  return CU_get_error();
 }
 if((CU_add_test(psuite, "test of function_header()", function_header_test) == ((void *)0)))
 {
  CU_cleanup_registry();
  return CU_get_error();
 }
 if((CU_add_test(psuite, "test of function_set_name()", function_set_name_test) == ((void *)0)))
 {
  CU_cleanup_registry();
  return CU_get_error();
 }
 if((CU_add_test(psuite, "test of  parameter_declaration_set()", parameter_declaration_set_test) == ((void *)0)))
 {
  CU_cleanup_registry();
  return CU_get_error();
 }
 if((CU_add_test(psuite, "test of  function_var()", function_var_test) == ((void *)0)))
 {
  CU_cleanup_registry();
  return CU_get_error();
 }
 if((CU_add_test(psuite, "test of  init_declarator_set()", init_declarator_set_test) == ((void *)0)))
 {
  CU_cleanup_registry();
  return CU_get_error();
 }
 if((CU_add_test(psuite, "test of  function_add_command()", function_add_command_test) == ((void *)0)))
 {
  CU_cleanup_registry();
  return CU_get_error();
 }
 if((CU_add_test(psuite, "test of  function_code()", function_code_test) == ((void *)0)))
 {
  CU_cleanup_registry();
  return CU_get_error();
 }
 if((CU_add_test(psuite, "test of  function_get_var()", function_get_var_test) == ((void *)0)))
 {
  CU_cleanup_registry();
  return CU_get_error();
 }
 if((CU_add_test(psuite, "test of  function_copy_var()", function_copy_var_test) == ((void *)0)))
 {
  CU_cleanup_registry();
  return CU_get_error();
 }
 if((CU_add_test(psuite, "test of  unique_label_name()", unique_label_name_test) == ((void *)0)))
 {
  CU_cleanup_registry();
  return CU_get_error();
 }
 if((CU_add_test(psuite, "test of  unique_var_name()", unique_var_name_test) == ((void *)0)))
 {
  CU_cleanup_registry();
  return CU_get_error();
 }
 if((CU_add_test(psuite, "test of  function_get_type()", function_get_type_test) == ((void *)0)))
 {
  CU_cleanup_registry();
  return CU_get_error();
 }
 if((CU_add_test(psuite, "test of  implicit_cast_type()", implicit_cast_type_test) == ((void *)0)))
 {
  CU_cleanup_registry();
  return CU_get_error();
 }
 CU_basic_set_mode(CU_BRM_VERBOSE);
 CU_basic_run_tests();
 CU_cleanup_registry();
 return CU_get_error();
}

variable_types: argc int

variable_types:
argv
char **

variable_types: struct CU_Suite { char *pName; int fActive; struct CU_Test { char *pName; int fActive; void (*pTestFunc)(); struct __jmp_buf_tag { long __jmpbuf[8]; int __mask_was_saved; struct __sigset_t { unsigned long __val[-1]; } __saved_mask; } (*pJumpBuf)[1]; struct CU_Test *pNext; struct CU_Test *pPrev; } *pTest; int (*pInitializeFunc)(); int (*pCleanupFunc)(); void (*pSetUpFunc)(); void (*pTearDownFunc)(); unsigned int uiNumberOfTests; struct CU_Suite *pNext; struct CU_Suite *pPrev; unsigned int uiNumberOfTestsFailed; unsigned int uiNumberOfTestsSuccess; } *

user_defined_types: struct CU_Suite { char *pName; int fActive; struct CU_Test *pTest; int (*pInitializeFunc)(); int (*pCleanupFunc)(); void (*pSetUpFunc)(); void (*pTearDownFunc)(); unsigned int uiNumberOfTests; struct CU_Suite *pNext; struct CU_Suite *pPrev; unsigned int uiNumberOfTestsFailed; unsigned int uiNumberOfTestsSuccess; }

user_defined_types: struct CU_Test { char *pName; int fActive; void (*pTestFunc)(); struct __jmp_buf_tag (*pJumpBuf)[1]; struct CU_Test *pNext; struct CU_Test *pPrev; }

user_defined_types: struct __jmp_buf_tag { long __jmpbuf[8]; int __mask_was_saved; struct __sigset_t __saved_mask; }


BuildOneTwoThree

repo: ankitC/rev

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

v1[0] = 0LL;
Push(v1, 3);
Push(v1, 2);
Push(v1, 1);
return v1[0];
}

original_code:
struct node* BuildOneTwoThree()
{
 struct node* head = ((void *)0);
 Push(&head, 3);
 Push(&head, 2);
 Push(&head, 1);
 return(head);
}

canonical_original_code:
struct node *BuildOneTwoThree()
{
 struct node *head = ((void *)0);
 Push(&head, 3);
 Push(&head, 2);
 Push(&head, 1);
 return(head);
}

variable_types: struct node { int data; struct node *next; } *


decompiled_code:
__int64 __fastcall list_length(__int64 a1)
{
__int64 result; // rax

for ( result = 0LL; a1; result = (unsigned int)(result + 1) )
a1 = *(_QWORD *)(a1 + 8);
return result;
}

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

for ( result = 0LL; a1; result = (unsigned int)(result + 1) )
a1 = *(_QWORD *)(a1 + 8);
return result;
}

original_code:
int list_length(struct node* head)
{
 int count = 0;
 struct node* current = head;
 while(current!=((void *)0))
 {
  count++;
  current = current->next;
 }
 return count;
}

canonical_original_code:
int list_length(struct node *head)
{
 int count = 0;
 struct node *current = head;
 while(current!=((void *)0))
 {
  count++;
  current = current->next;
 }
 return count;
}

variable_types: count int

user_defined_types: struct node { int data; struct node *next; }


decompiled_code:
int __fastcall print_list(unsigned int *a1)
{
unsigned int *v1; // rbx

if ( !a1 )
return puts("List is empty!");
v1 = a1;
do
{
printf("%d\t", *v1);
v1 = (unsigned int *)*((_QWORD *)v1 + 1);
}
while ( v1 );
return putchar(10);
}

canonical_decompiled_code:
int __fastcall func9(unsigned int *a1)
{
unsigned int *v1; // rbx

if ( !a1 )
return puts("List is empty!");
v1 = a1;
do
{
printf("%d\t", *v1);
v1 = (unsigned int *)*((_QWORD *)v1 + 1);
}
while ( v1 );
return putchar(10);
}

original_code:
void print_list(struct node* head)
{
 if( head == ((void *)0) )
  printf("List is empty!\n");
 else
 {
  struct node* current = head;
  while(current!=((void *)0))
  {
   printf("%d\t", current->data);
   current = current->next;
  }
  printf("\n");
 }
}

canonical_original_code:
void print_list(struct node *head)
{
 if( head == ((void *)0) )
  printf("List is empty!\n");
 else
 {
  struct node *current = head;
  while(current!=((void *)0))
  {
   printf("%d\t", current->data);
   current = current->next;
  }
  printf("\n");
 }
}