decompiled_code:
void *get_addr()
{
int v0; // eax
void *result; // rax

v0 = shmget(4662, 0x1004uLL, 950);
if ( v0 < 0 )
{
perror("shmget");
result = 0LL;
}
else
{
result = shmat(v0, 0LL, 0);
if ( result == (void *)-1LL )
{
perror("shmat");
result = 0LL;
}
}
return result;
}

canonical_decompiled_code:
void *func7()
{
int v0; // eax
void *result; // rax

v0 = shmget(4662, 0x1004uLL, 950);
if ( v0 < 0 )
{
perror("shmget");
result = 0LL;
}
else
{
result = shmat(v0, 0LL, 0);
if ( result == (void *)-1LL )
{
perror("shmat");
result = 0LL;
}
}
return result;
}

original_code:
static Shared_use_st* get_addr()
{
    void *shm = ((void *)0);
    int shmid;
    shmid = shmget((key_t)0x1236, sizeof(Shared_use_st), 0666|01000);
    if (shmid < 0) {perror("shmget");return ((void *)0);}
    shm = shmat(shmid, 0, 0);
    if(shm == (void*)-1){perror("shmat");return ((void *)0);};
    return (struct shared_use_st*)shm;
}

canonical_original_code:
static struct shared_use_st *get_addr()
{
    void *shm = ((void *)0);
    int shmid;
    shmid = shmget((int)0x1236, sizeof(Shared_use_st), 0666|01000);
    if (shmid < 0) {perror("shmget");return ((void *)0);}
    shm = shmat(shmid, 0, 0);
    if(shm == (void *)-1){perror("shmat");return ((void *)0);};
    return (struct shared_use_st *)shm;
}

variable_types:
shm
void *

variable_types: shmid int

return_type: struct shared_use_st { int size; char text[4096]; } *


decompiled_code:
void __fastcall untach_addr(const void *a1)
{
if ( shmdt(a1) == -1 )
perror("shmdt");
}

canonical_decompiled_code:
void __fastcall func8(const void *a1)
{
if ( shmdt(a1) == -1 )
perror("shmdt");
}

original_code:
static void untach_addr(Shared_use_st* addr)
{
    if(shmdt((void*)addr) == -1)
    {
 perror("shmdt");
    }
}

canonical_original_code:
static void untach_addr(struct shared_use_st *addr)
{
    if(shmdt((void *)addr) == -1)
    {
 perror("shmdt");
    }
}

variable_types: struct shared_use_st { int size; char text[4096]; } *

return_type: void


decompiled_code:
__int64 __fastcall copy_from_share_mem(_QWORD *a1)
{
_QWORD *v1; // rax

v1 = get_addr();
if ( !v1 )
return 0xFFFFFFFFLL;
*a1 = *v1;
*(_QWORD *)((char *)a1 + 4092) = *(_QWORD *)((char *)v1 + 4092);
qmemcpy(
(void *)((unsigned __int64)(a1 + 1) & 0xFFFFFFFFFFFFFFF8LL),
(const void *)((char *)v1 - ((char *)a1 - ((unsigned __int64)(a1 + 1) & 0xFFFFFFFFFFFFFFF8LL))),
8LL * (((unsigned int)a1 - (((_DWORD)a1 + 8) & 0xFFFFFFF8) + 4100) >> 3));
untach_addr(v1);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func9(_QWORD *a1)
{
_QWORD *v1; // rax

v1 = func7();
if ( !v1 )
return 0xFFFFFFFFLL;
*a1 = *v1;
*(_QWORD *)((char *)a1 + 4092) = *(_QWORD *)((char *)v1 + 4092);
qmemcpy(
(void *)((unsigned __int64)(a1 + 1) & 0xFFFFFFFFFFFFFFF8LL),
(const void *)((char *)v1 - ((char *)a1 - ((unsigned __int64)(a1 + 1) & 0xFFFFFFFFFFFFFFF8LL))),
8LL * (((unsigned int)a1 - (((_DWORD)a1 + 8) & 0xFFFFFFF8) + 4100) >> 3));
func8(v1);
return 0LL;
}

original_code:
static int copy_from_share_mem(Shared_use_st* st)
{
    struct shared_use_st *shared;
    shared=get_addr();
    if (shared == ((void *)0)) return -1;
    memcpy((void*)st,(void*)shared,sizeof(Shared_use_st));
    untach_addr(shared);
    return 0;
}

canonical_original_code:
static int copy_from_share_mem(struct shared_use_st *st)
{
    struct shared_use_st *shared;
    shared=get_addr();
    if (shared == ((void *)0)) return -1;
    memcpy((void *)st,(void *)shared,sizeof(Shared_use_st));
    untach_addr(shared);
    return 0;
}

return_type: int

user_defined_types: struct shared_use_st { int size; char text[4096]; }


decompiled_code:
int __fastcall copy_to_clip_baord(const char *a1)
{
char v2[1032]; // [rsp+0h] [rbp-408h] BYREF

printf("\x1B[35m%s:copyed\n\x1B[m", a1);
snprintf(v2, 0x400uLL, "echo \"%s\" | xclip -selection clipboard", a1);
return system(v2);
}

canonical_decompiled_code:
int __fastcall func10(const char *a1)
{
char v2[1032]; // [rsp+0h] [rbp-408h] BYREF

printf("\x1B[35m%s:copyed\n\x1B[m", a1);
snprintf(v2, 0x400uLL, "echo \"%s\" | xclip -selection clipboard", a1);
return system(v2);
}

original_code:
static void copy_to_clip_baord(const char* str)
{
    char cmd[1024];
    printf("\033[35m""%s:copyed\n""\033[m",str);
    snprintf(cmd,sizeof(cmd),"echo \"%s\" | xclip -selection clipboard",str);
    system(cmd);
}

canonical_original_code:
static void copy_to_clip_baord(char *str)
{
    char cmd[1024];
    printf("\033[35m""%s:copyed\n""\033[m",str);
    snprintf(cmd,sizeof(cmd),"echo \"%s\" | xclip -selection clipboard",str);
    system(cmd);
}

variable_types:
str
char *

variable_types:
cmd
char [1024]


main

canonical_name: main

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

if ( (int)pollRead_constprop_0(argc, argv, envp) > 0 )
{
write_to_mem_isra_0();
}
else if ( argc == 1 )
{
read_from_mem_isra_0(1LL);
return 0;
}
if ( argc > 1 )
{
v4 = atoi(argv[1]);
read_from_mem_isra_0(v4);
}
return 0;
}

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

if ( (int)func11(argc, argv, envp) > 0 )
{
func14();
}
else if ( argc == 1 )
{
func12(1LL);
return 0;
}
if ( argc > 1 )
{
v4 = atoi(argv[1]);
func12(v4);
}
return 0;
}

original_code:
int main(int argc,char* argv[])
{
    int isHaveData=0;
    if (pollRead(0,1) > 0){
 isHaveData=1;
 write_to_mem();
     }
    if ( !isHaveData && argc == 1){
 read_from_mem(1);
 return 0;
    }
    if (argc > 1){
 read_from_mem(atoi(argv[1]));
    }
    return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
    int isHaveData = 0;
    if (pollRead(0,1) > 0){
 isHaveData=1;
 write_to_mem();
     }
    if ( !isHaveData && argc == 1){
 read_from_mem(1);
 return 0;
    }
    if (argc > 1){
 read_from_mem(atoi(argv[1]));
    }
    return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: isHaveData int


repo: aep/confine

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char *v3; // r12
const char *v4; // r13
size_t v5; // rax
void *v6; // rax
const char *v7; // rbp
__uid_t v8; // eax
__gid_t v9; // eax
int result; // eax

if ( argc <= 2 )
{
fprintf(stderr, "usage: %s /path/to/allow someprogram someargs\n", *argv);
result = 3;
}
else
{
v3 = (char *)malloc(0x7D0uLL);
getcwd(v3, 0x7D0uLL);
if ( unshare(0x20000) )
perror("unshare");
if ( mount("/", "/", 0LL, 0x44000uLL, 0LL) )
perror("make private");
if ( mount("/", "/root", 0LL, 0x45001uLL, 0LL) )
perror("bind /");
if ( mount("/", "/root", 0LL, 0x45021uLL, 0LL) )
perror("bind /");
v4 = argv[1];
v5 = strlen(v4);
v6 = malloc(v5 + 6);
*(_DWORD *)v6 = 1869574703;
v7 = (const char *)v6;
*((_WORD *)v6 + 2) = 12148;
strcpy((char *)v6 + 6, v4);
if ( mount(v4, v7, 0LL, 0x41000uLL, 0LL) )
perror("bind ");
chroot("/root");
v8 = getuid();
seteuid(v8);
v9 = getgid();
setegid(v9);
chdir(v3);
execvp(argv[2], (char *const *)argv + 3);
result = 0;
}
return result;
}

original_code:
int main(int argc, char **argv)
{
    if (argc < 3) {
        fprintf(stderr, "usage: %s /path/to/allow someprogram someargs\n", argv[0]);
        return 3;
    }
    char *pwd = malloc (2000);
    getcwd(pwd, 2000);
    int r = unshare(0x00020000);
    if (r != 0)
        perror("unshare");
    r = mount("/","/", 0, MS_PRIVATE | MS_REC, 0);
    if (r != 0)
        perror("make private");
    r = mount("/", "/root", 0, MS_BIND | MS_RDONLY | MS_REC | MS_PRIVATE , 0);
    if (r != 0)
        perror("bind /");
    r = mount("/", "/root", 0, MS_BIND | MS_RDONLY | MS_REC | MS_PRIVATE | MS_REMOUNT, 0);
    if (r != 0)
        perror("bind /");
    char *m = malloc(strlen("/root/") + strlen(argv[1]));
    strcpy(m, "/root/");
    strcat(m, argv[1]);
    r = mount(argv[1], m, 0, MS_BIND | MS_PRIVATE, 0);
    if (r != 0)
        perror("bind ");
    chroot ("/root");
    seteuid(getuid());
    setegid(getgid());
    chdir(pwd);
    execvp(argv[2] , argv + 3);
}

variable_types:
argv
char **

variable_types:
pwd
char *

variable_types: r int

variable_types:
m
char *


repo: aerospike/act

decompiled_code:
void *__fastcall run_zero(void *a1)
{
unsigned __int64 v1; // r13
unsigned __int64 v2; // rbp
__off64_t v3; // rbx
int v4; // eax
unsigned int v5; // er12
unsigned __int64 v6; // rbx

v1 = g_blocks_per_zero_thread;
v2 = 0LL;
v3 = (g_blocks_per_zero_thread * (unsigned int)a1) << 17;
if ( (_DWORD)a1 == 7
&& (v1 = g_extra_blocks_to_zero + g_blocks_per_zero_thread,
v2 = 1LL,
(unsigned __int64)(g_extra_blocks_to_zero + g_blocks_per_zero_thread) > 0x63) )
{
v2 = v1 / 0x64;
v4 = fd_get();
v5 = v4;
if ( v4 == -1 )
goto LABEL_16;
}
else
{
v4 = fd_get();
v5 = v4;
if ( v4 == -1 )
{
LABEL_16:
printf("ERROR: open in zero thread %u\n", (unsigned int)a1);
return 0LL;
}
}
if ( v3 == lseek64(v4, v3, 0) )
{
v6 = 0LL;
if ( v1 )
{
while ( (unsigned __int8)write_all(v5, g_p_zero_buffer, 0x20000LL) )
{
if ( !v2 || v6 % v2 )
{
if ( v1 == ++v6 )
goto LABEL_11;
}
else
{
++v6;
putchar(46);
fflush(stdout);
if ( v1 == v6 )
goto LABEL_11;
}
}
printf("ERROR: write in zero thread %u\n", (unsigned int)a1);
if ( !v2 )
{
LABEL_12:
if ( (_DWORD)a1 != 7 )
{
LABEL_13:
close(v5);
return 0LL;
}
LABEL_20:
if ( !(unsigned __int8)write_all(v5, g_p_zero_buffer, g_extra_bytes_to_zero) )
printf("ERROR: write in zero thread %u\n", 7LL);
goto LABEL_13;
}
}
else
{
LABEL_11:
if ( !v2 )
goto LABEL_12;
}
putchar(10);
if ( (_DWORD)a1 != 7 )
goto LABEL_13;
goto LABEL_20;
}
printf("ERROR: seek in zero thread %u\n", (unsigned int)a1);
close(v5);
return 0LL;
}

canonical_decompiled_code:
void *__fastcall func1(void *a1)
{
unsigned __int64 v1; // r13
unsigned __int64 v2; // rbp
__off64_t v3; // rbx
int v4; // eax
unsigned int v5; // er12
unsigned __int64 v6; // rbx

v1 = g_blocks_per_zero_thread;
v2 = 0LL;
v3 = (g_blocks_per_zero_thread * (unsigned int)a1) << 17;
if ( (_DWORD)a1 == 7
&& (v1 = g_extra_blocks_to_zero + g_blocks_per_zero_thread,
v2 = 1LL,
(unsigned __int64)(g_extra_blocks_to_zero + g_blocks_per_zero_thread) > 0x63) )
{
v2 = v1 / 0x64;
v4 = func0();
v5 = v4;
if ( v4 == -1 )
goto LABEL_16;
}
else
{
v4 = func0();
v5 = v4;
if ( v4 == -1 )
{
LABEL_16:
printf("ERROR: open in zero thread %u\n", (unsigned int)a1);
return 0LL;
}
}
if ( v3 == lseek64(v4, v3, 0) )
{
v6 = 0LL;
if ( v1 )
{
while ( (unsigned __int8)write_all(v5, g_p_zero_buffer, 0x20000LL) )
{
if ( !v2 || v6 % v2 )
{
if ( v1 == ++v6 )
goto LABEL_11;
}
else
{
++v6;
putchar(46);
fflush(stdout);
if ( v1 == v6 )
goto LABEL_11;
}
}
printf("ERROR: write in zero thread %u\n", (unsigned int)a1);
if ( !v2 )
{
LABEL_12:
if ( (_DWORD)a1 != 7 )
{
LABEL_13:
close(v5);
return 0LL;
}
LABEL_20:
if ( !(unsigned __int8)write_all(v5, g_p_zero_buffer, g_extra_bytes_to_zero) )
printf("ERROR: write in zero thread %u\n", 7LL);
goto LABEL_13;
}
}
else
{
LABEL_11:
if ( !v2 )
goto LABEL_12;
}
putchar(10);
if ( (_DWORD)a1 != 7 )
goto LABEL_13;
goto LABEL_20;
}
printf("ERROR: seek in zero thread %u\n", (unsigned int)a1);
close(v5);
return 0LL;
}

original_code:
static void*
run_zero(void* pv_n)
{
 uint32_t n = (uint32_t)(uint64_t)pv_n;
 uint64_t offset = n * g_blocks_per_zero_thread * (1024 * 128);
 uint64_t blocks_to_zero = g_blocks_per_zero_thread;
 uint64_t progress_blocks = 0;
 _Bool last_thread = n + 1 == 8;
 if (last_thread) {
  blocks_to_zero += g_extra_blocks_to_zero;
  progress_blocks = blocks_to_zero / 100;
  if (! progress_blocks) {
   progress_blocks = 1;
  }
 }
 int fd = fd_get();
 if (fd == -1) {
  printf("ERROR: open in zero thread %" "u" "\n", n);
  return ((void *)0);
 }
 if (lseek(fd, offset, 0) != offset) {
  printf("ERROR: seek in zero thread %" "u" "\n", n);
  close(fd);
  return ((void *)0);
 }
 for (uint64_t b = 0; b < blocks_to_zero; b++) {
  if (! write_all(fd, g_p_zero_buffer, (1024 * 128))) {
   printf("ERROR: write in zero thread %" "u" "\n", n);
   break;
  }
  if (progress_blocks && ! (b % progress_blocks)) {
   printf(".");
   fflush(stdout);
  }
 }
 if (progress_blocks) {
  printf("\n");
 }
 if (last_thread) {
  if (! write_all(fd, g_p_zero_buffer, g_extra_bytes_to_zero)) {
   printf("ERROR: write in zero thread %" "u" "\n", n);
  }
 }
 close(fd);
 return ((void *)0);
}

canonical_original_code:
static void *run_zero(void *pv_n)
{
 unsigned int n = (uint32_t)(uint64_t)pv_n;
 unsigned long offset = n * g_blocks_per_zero_thread * (1024 * 128);
 unsigned long blocks_to_zero = g_blocks_per_zero_thread;
 unsigned long progress_blocks = 0;
 _Bool last_thread = n + 1 == 8;
 if (last_thread) {
  blocks_to_zero += g_extra_blocks_to_zero;
  progress_blocks = blocks_to_zero / 100;
  if (! progress_blocks) {
   progress_blocks = 1;
  }
 }
 int fd = fd_get();
 if (fd == -1) {
  printf("ERROR: open in zero thread %" "u" "\n", n);
  return ((void *)0);
 }
 if (lseek(fd, offset, 0) != offset) {
  printf("ERROR: seek in zero thread %" "u" "\n", n);
  close(fd);
  return ((void *)0);
 }
 for (unsigned long b = 0; b < blocks_to_zero; b++) {
  if (! write_all(fd, g_p_zero_buffer, (1024 * 128))) {
   printf("ERROR: write in zero thread %" "u" "\n", n);
   break;
  }
  if (progress_blocks && ! (b % progress_blocks)) {
   printf(".");
   fflush(stdout);
  }
 }
 if (progress_blocks) {
  printf("\n");
 }
 if (last_thread) {
  if (! write_all(fd, g_p_zero_buffer, g_extra_bytes_to_zero)) {
   printf("ERROR: write in zero thread %" "u" "\n", n);
  }
 }
 close(fd);
 return ((void *)0);
}

variable_types:
n
unsigned int

variable_types:
offset
unsigned long

variable_types: fd int

variable_types:
b
unsigned long

return_type: void *


decompiled_code:
__int64 discover_num_blocks()
{
int v0; // eax
int v1; // ebp
__int64 result; // rax
unsigned __int64 v3; // [rsp+8h] [rbp-10h] BYREF

v0 = fd_get();
if ( v0 == -1 )
{
printf("ERROR: opening device %s\n", g_device_name);
result = 0LL;
}
else
{
v1 = v0;
v3 = 0LL;
ioctl(v0, 0x80081272uLL, &v3);
close(v1);
g_extra_bytes_to_zero = v3 & 0x1FFFF;
g_blocks_per_zero_thread = v3 >> 20;
g_blocks_per_salt_thread = v3 >> 20;
g_extra_blocks_to_zero = (v3 >> 17) & 7;
g_extra_blocks_to_salt = (v3 >> 17) & 7;
printf("%s size = %lu bytes, %lu large blocks\n", g_device_name, v3, v3 >> 17);
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 func2()
{
int v0; // eax
int v1; // ebp
__int64 result; // rax
unsigned __int64 v3; // [rsp+8h] [rbp-10h] BYREF

v0 = func0();
if ( v0 == -1 )
{
printf("ERROR: opening device %s\n", g_device_name);
result = 0LL;
}
else
{
v1 = v0;
v3 = 0LL;
ioctl(v0, 0x80081272uLL, &v3);
close(v1);
g_extra_bytes_to_zero = v3 & 0x1FFFF;
g_blocks_per_zero_thread = v3 >> 20;
g_blocks_per_salt_thread = v3 >> 20;
g_extra_blocks_to_zero = (v3 >> 17) & 7;
g_extra_blocks_to_salt = (v3 >> 17) & 7;
printf("%s size = %lu bytes, %lu large blocks\n", g_device_name, v3, v3 >> 17);
result = 1LL;
}
return result;
}

original_code:
static _Bool
discover_num_blocks()
{
 int fd = fd_get();
 if (fd == -1) {
  printf("ERROR: opening device %s\n", g_device_name);
  return 0;
 }
 uint64_t device_bytes = 0;
 ioctl(fd, (((2U) << (((0 +8)+8)+14)) | (((0x12)) << (0 +8)) | (((114)) << 0) | ((((sizeof(size_t)))) << ((0 +8)+8))), &device_bytes);
 close(fd);
 g_num_large_blocks = device_bytes / (1024 * 128);
 g_extra_bytes_to_zero = device_bytes % (1024 * 128);
 g_blocks_per_zero_thread = g_num_large_blocks / 8;
 g_blocks_per_salt_thread = g_num_large_blocks / 8;
 g_extra_blocks_to_zero = g_num_large_blocks % 8;
 g_extra_blocks_to_salt = g_num_large_blocks % 8;
 printf("%s size = %" "l" "u" " bytes, %" "l" "u" " large blocks\n",
   g_device_name, device_bytes, g_num_large_blocks);
 return 1;
}

canonical_original_code:
static _Bool discover_num_blocks()
{
 int fd = fd_get();
 if (fd == -1) {
  printf("ERROR: opening device %s\n", g_device_name);
  return 0;
 }
 unsigned long device_bytes = 0;
 ioctl(fd, (((2U) << (((0 +8)+8)+14)) | (((0x12)) << (0 +8)) | (((114)) << 0) | ((((sizeof(unsigned long)))) << ((0 +8)+8))), &device_bytes);
 close(fd);
 g_num_large_blocks = device_bytes / (1024 * 128);
 g_extra_bytes_to_zero = device_bytes % (1024 * 128);
 g_blocks_per_zero_thread = g_num_large_blocks / 8;
 g_blocks_per_salt_thread = g_num_large_blocks / 8;
 g_extra_blocks_to_zero = g_num_large_blocks % 8;
 g_extra_blocks_to_salt = g_num_large_blocks % 8;
 printf("%s size = %" "l" "u" " bytes, %" "l" "u" " large blocks\n",
   g_device_name, device_bytes, g_num_large_blocks);
 return 1;
}


decompiled_code:
__int64 create_zero_buffer()
{
void *v0; // rax
__int64 result; // rax

v0 = act_valloc_constprop_0();
g_p_zero_buffer = v0;
if ( v0 )
{
memset(v0, 0, 0x20000uLL);
result = 1LL;
}
else
{
puts("ERROR: zero buffer act_valloc()");
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 func4()
{
void *v0; // rax
__int64 result; // rax

v0 = func3();
g_p_zero_buffer = v0;
if ( v0 )
{
memset(v0, 0, 0x20000uLL);
result = 1LL;
}
else
{
puts("ERROR: zero buffer act_valloc()");
result = 0LL;
}
return result;
}

original_code:
static _Bool
create_zero_buffer()
{
 g_p_zero_buffer = act_valloc((1024 * 128));
 if (! g_p_zero_buffer) {
  printf("ERROR: zero buffer act_valloc()\n");
  return 0;
 }
 memset(g_p_zero_buffer, 0, (1024 * 128));
 return 1;
}


decompiled_code:
void *__fastcall run_salt(void *a1)
{
unsigned __int64 v1; // r12
__int64 v2; // rbx
unsigned __int64 v3; // r14
void *v4; // rbp
unsigned int v5; // er13
unsigned __int64 v6; // rbx

v1 = 0LL;
rand_seed_thread();
v2 = g_blocks_per_salt_thread;
v3 = g_blocks_per_salt_thread;
if ( (_DWORD)a1 == 7
&& (v3 = g_extra_blocks_to_salt + g_blocks_per_salt_thread,
v1 = 1LL,
(unsigned __int64)(g_extra_blocks_to_salt + g_blocks_per_salt_thread) > 0x63) )
{
v1 = v3 / 0x64;
v4 = act_valloc_constprop_0();
if ( !v4 )
goto LABEL_18;
}
else
{
v4 = act_valloc_constprop_0();
if ( !v4 )
{
LABEL_18:
printf("ERROR: valloc in salt thread %u\n", (unsigned int)a1);
return 0LL;
}
}
v5 = fd_get();
if ( v5 == -1 )
{
printf("ERROR: open in salt thread %u\n", (unsigned int)a1);
free(v4);
return 0LL;
}
if ( ((unsigned int)a1 * v2) << 17 != lseek64(v5, ((unsigned int)a1 * v2) << 17, 0) )
{
printf("ERROR: seek in salt thread %u\n", (unsigned int)a1);
close(v5);
free(v4);
return 0LL;
}
v6 = 0LL;
if ( v3 )
{
while ( 1 )
{
rand_fill(v4, 0x20000LL, 100LL);
if ( !(unsigned __int8)write_all(v5, v4, 0x20000LL) )
break;
if ( !v1 || v6 % v1 )
{
if ( v3 == ++v6 )
goto LABEL_12;
}
else
{
++v6;
putchar(46);
fflush(stdout);
if ( v3 == v6 )
goto LABEL_12;
}
}
printf("ERROR: write in salt thread %u\n", (unsigned int)a1);
if ( !v1 )
goto LABEL_13;
goto LABEL_20;
}
LABEL_12:
if ( v1 )
LABEL_20:
putchar(10);
LABEL_13:
close(v5);
free(v4);
return 0LL;
}

canonical_decompiled_code:
void *__fastcall func5(void *a1)
{
unsigned __int64 v1; // r12
__int64 v2; // rbx
unsigned __int64 v3; // r14
void *v4; // rbp
unsigned int v5; // er13
unsigned __int64 v6; // rbx

v1 = 0LL;
rand_seed_thread();
v2 = g_blocks_per_salt_thread;
v3 = g_blocks_per_salt_thread;
if ( (_DWORD)a1 == 7
&& (v3 = g_extra_blocks_to_salt + g_blocks_per_salt_thread,
v1 = 1LL,
(unsigned __int64)(g_extra_blocks_to_salt + g_blocks_per_salt_thread) > 0x63) )
{
v1 = v3 / 0x64;
v4 = func3();
if ( !v4 )
goto LABEL_18;
}
else
{
v4 = func3();
if ( !v4 )
{
LABEL_18:
printf("ERROR: valloc in salt thread %u\n", (unsigned int)a1);
return 0LL;
}
}
v5 = func0();
if ( v5 == -1 )
{
printf("ERROR: open in salt thread %u\n", (unsigned int)a1);
free(v4);
return 0LL;
}
if ( ((unsigned int)a1 * v2) << 17 != lseek64(v5, ((unsigned int)a1 * v2) << 17, 0) )
{
printf("ERROR: seek in salt thread %u\n", (unsigned int)a1);
close(v5);
free(v4);
return 0LL;
}
v6 = 0LL;
if ( v3 )
{
while ( 1 )
{
rand_fill(v4, 0x20000LL, 100LL);
if ( !(unsigned __int8)write_all(v5, v4, 0x20000LL) )
break;
if ( !v1 || v6 % v1 )
{
if ( v3 == ++v6 )
goto LABEL_12;
}
else
{
++v6;
putchar(46);
fflush(stdout);
if ( v3 == v6 )
goto LABEL_12;
}
}
printf("ERROR: write in salt thread %u\n", (unsigned int)a1);
if ( !v1 )
goto LABEL_13;
goto LABEL_20;
}
LABEL_12:
if ( v1 )
LABEL_20:
putchar(10);
LABEL_13:
close(v5);
free(v4);
return 0LL;
}

original_code:
static void*
run_salt(void* pv_n)
{
 rand_seed_thread();
 uint32_t n = (uint32_t)(uint64_t)pv_n;
 uint64_t offset = n * g_blocks_per_salt_thread * (1024 * 128);
 uint64_t blocks_to_salt = g_blocks_per_salt_thread;
 uint64_t progress_blocks = 0;
 _Bool last_thread = n + 1 == 8;
 if (last_thread) {
  blocks_to_salt += g_extra_blocks_to_salt;
  progress_blocks = blocks_to_salt / 100;
  if (! progress_blocks) {
   progress_blocks = 1;
  }
 }
 uint8_t* buf = act_valloc((1024 * 128));
 if (! buf) {
  printf("ERROR: valloc in salt thread %" "u" "\n", n);
  return ((void *)0);
 }
 int fd = fd_get();
 if (fd == -1) {
  printf("ERROR: open in salt thread %" "u" "\n", n);
  free(buf);
  return ((void *)0);
 }
 if (lseek(fd, offset, 0) != offset) {
  printf("ERROR: seek in salt thread %" "u" "\n", n);
  close(fd);
  free(buf);
  return ((void *)0);
 }
 for (uint64_t b = 0; b < blocks_to_salt; b++) {
  rand_fill(buf, (1024 * 128), 100);
  if (! write_all(fd, buf, (1024 * 128))) {
   printf("ERROR: write in salt thread %" "u" "\n", n);
   break;
  }
  if (progress_blocks && ! (b % progress_blocks)) {
   printf(".");
   fflush(stdout);
  }
 }
 if (progress_blocks) {
  printf("\n");
 }
 close(fd);
 free(buf);
 return ((void *)0);
}

canonical_original_code:
static void *run_salt(void *pv_n)
{
 rand_seed_thread();
 unsigned int n = (uint32_t)(uint64_t)pv_n;
 unsigned long offset = n * g_blocks_per_salt_thread * (1024 * 128);
 unsigned long blocks_to_salt = g_blocks_per_salt_thread;
 unsigned long progress_blocks = 0;
 _Bool last_thread = n + 1 == 8;
 if (last_thread) {
  blocks_to_salt += g_extra_blocks_to_salt;
  progress_blocks = blocks_to_salt / 100;
  if (! progress_blocks) {
   progress_blocks = 1;
  }
 }
 unsigned char *buf = act_valloc((1024 * 128));
 if (! buf) {
  printf("ERROR: valloc in salt thread %" "u" "\n", n);
  return ((void *)0);
 }
 int fd = fd_get();
 if (fd == -1) {
  printf("ERROR: open in salt thread %" "u" "\n", n);
  free(buf);
  return ((void *)0);
 }
 if (lseek(fd, offset, 0) != offset) {
  printf("ERROR: seek in salt thread %" "u" "\n", n);
  close(fd);
  free(buf);
  return ((void *)0);
 }
 for (unsigned long b = 0; b < blocks_to_salt; b++) {
  rand_fill(buf, (1024 * 128), 100);
  if (! write_all(fd, buf, (1024 * 128))) {
   printf("ERROR: write in salt thread %" "u" "\n", n);
   break;
  }
  if (progress_blocks && ! (b % progress_blocks)) {
   printf(".");
   fflush(stdout);
  }
 }
 if (progress_blocks) {
  printf("\n");
 }
 close(fd);
 free(buf);
 return ((void *)0);
}

variable_types:
buf
unsigned char *


decompiled_code:
int fd_get()
{
return open64(g_device_name, 16386, 384LL);
}

canonical_decompiled_code:
int func0()
{
return open64(g_device_name, 16386, 384LL);
}

original_code:
static inline int
fd_get()
{
 return open(g_device_name, 040000 | 02, 0400 | 0200);
}


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // r12
size_t v4; // rax
void *v5; // rsp
pthread_t *v6; // rbx
char *v7; // r12
pthread_t *v8; // r13
pthread_t v9; // rdi
pthread_t *v10; // rbx
char *v11; // r12
pthread_t *v12; // r13
pthread_t v13; // rdi
pthread_t newthread[8]; // [rsp+0h] [rbp-A0h] BYREF
pthread_t v16[8]; // [rsp+40h] [rbp-60h] BYREF
__int64 v17; // [rsp+80h] [rbp-20h] BYREF

signal_setup(argc, argv, envp);
if ( argc != 2 )
{
puts("usage: act_prep [device name]");
exit(0);
}
v3 = argv[1];
v4 = strlen(v3);
v5 = alloca(v4 + 1);
memcpy(newthread, v3, v4 + 1);
g_device_name = (char *)newthread;
set_scheduler(newthread, "noop");
if ( !(unsigned __int8)discover_num_blocks()
|| (printf("cleaning device %s\n", g_device_name), !(unsigned __int8)create_zero_buffer()) )
{
LABEL_15:
exit(-1);
}
v6 = newthread;
v7 = 0LL;
v8 = newthread;
do
{
if ( pthread_create(v8, 0LL, run_zero, v7) )
{
printf("ERROR: creating zero thread %u\n", (unsigned int)v7);
goto LABEL_15;
}
++v7;
++v8;
}
while ( v7 != (_BYTE *)&loc_7 + 1 );
do
{
v9 = *v6++;
pthread_join(v9, 0LL);
}
while ( v6 != v16 );
v10 = v16;
v11 = 0LL;
v12 = v16;
free(g_p_zero_buffer);
printf("salting device %s\n", g_device_name);
rand_seed();
do
{
if ( pthread_create(v12, 0LL, run_salt, v11) )
{
printf("ERROR: creating salt thread %u\n", (unsigned int)v11);
exit(-1);
}
++v11;
++v12;
}
while ( v11 != (_BYTE *)&loc_7 + 1 );
do
{
v13 = *v10++;
pthread_join(v13, 0LL);
}
while ( v10 != (pthread_t *)&v17 );
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // r12
size_t v4; // rax
void *v5; // rsp
pthread_t *v6; // rbx
char *v7; // r12
pthread_t *v8; // r13
pthread_t v9; // rdi
pthread_t *v10; // rbx
char *v11; // r12
pthread_t *v12; // r13
pthread_t v13; // rdi
pthread_t newthread[8]; // [rsp+0h] [rbp-A0h] BYREF
pthread_t v16[8]; // [rsp+40h] [rbp-60h] BYREF
__int64 v17; // [rsp+80h] [rbp-20h] BYREF

signal_setup(argc, argv, envp);
if ( argc != 2 )
{
puts("usage: act_prep [device name]");
exit(0);
}
v3 = argv[1];
v4 = strlen(v3);
v5 = alloca(v4 + 1);
memcpy(newthread, v3, v4 + 1);
g_device_name = (char *)newthread;
set_scheduler(newthread, "noop");
if ( !(unsigned __int8)func2()
|| (printf("cleaning device %s\n", g_device_name), !(unsigned __int8)func4()) )
{
LABEL_15:
exit(-1);
}
v6 = newthread;
v7 = 0LL;
v8 = newthread;
do
{
if ( pthread_create(v8, 0LL, run_zero, v7) )
{
printf("ERROR: creating zero thread %u\n", (unsigned int)v7);
goto LABEL_15;
}
++v7;
++v8;
}
while ( v7 != (_BYTE *)&loc_7 + 1 );
do
{
v9 = *v6++;
pthread_join(v9, 0LL);
}
while ( v6 != v16 );
v10 = v16;
v11 = 0LL;
v12 = v16;
free(g_p_zero_buffer);
printf("salting device %s\n", g_device_name);
rand_seed();
do
{
if ( pthread_create(v12, 0LL, run_salt, v11) )
{
printf("ERROR: creating salt thread %u\n", (unsigned int)v11);
exit(-1);
}
++v11;
++v12;
}
while ( v11 != (_BYTE *)&loc_7 + 1 );
do
{
v13 = *v10++;
pthread_join(v13, 0LL);
}
while ( v10 != (pthread_t *)&v17 );
return 0;
}

original_code:
int
main(int argc, char* argv[])
{
 signal_setup();
 if (argc != 2) {
  printf("usage: act_prep [device name]\n");
  exit(0);
 }
 char device_name[strlen(argv[1]) + 1];
 strcpy(device_name, argv[1]);
 g_device_name = device_name;
 set_scheduler(g_device_name, "noop");
 if (! discover_num_blocks()) {
  exit(-1);
 }
 printf("cleaning device %s\n", g_device_name);
 if (! create_zero_buffer()) {
  exit(-1);
 }
 pthread_t zero_threads[8];
 for (uint32_t n = 0; n < 8; n++) {
  if (pthread_create(&zero_threads[n], ((void *)0), run_zero,
    (void*)(uint64_t)n) != 0) {
   printf("ERROR: creating zero thread %" "u" "\n", n);
   exit(-1);
  }
 }
 for (uint32_t n = 0; n < 8; n++) {
  pthread_join(zero_threads[n], ((void *)0));
 }
 free(g_p_zero_buffer);
 printf("salting device %s\n", g_device_name);
 rand_seed();
 pthread_t salt_threads[8];
 for (uint32_t n = 0; n < 8; n++) {
  if (pthread_create(&salt_threads[n], ((void *)0), run_salt,
    (void*)(uint64_t)n) != 0) {
   printf("ERROR: creating salt thread %" "u" "\n", n);
   exit(-1);
  }
 }
 for (uint32_t n = 0; n < 8; n++) {
  pthread_join(salt_threads[n], ((void *)0));
 }
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
 signal_setup();
 if (argc != 2) {
  printf("usage: act_prep [device name]\n");
  exit(0);
 }
 char device_name[-1];
 strcpy(device_name, argv[1]);
 g_device_name = device_name;
 set_scheduler(g_device_name, "noop");
 if (! discover_num_blocks()) {
  exit(-1);
 }
 printf("cleaning device %s\n", g_device_name);
 if (! create_zero_buffer()) {
  exit(-1);
 }
 unsigned long zero_threads[8];
 for (unsigned int n = 0; n < 8; n++) {
  if (pthread_create(&zero_threads[n], ((void *)0), run_zero,
    (void *)(unsigned long)n) != 0) {
   printf("ERROR: creating zero thread %" "u" "\n", n);
   exit(-1);
  }
 }
 for (unsigned int n = 0; n < 8; n++) {
  pthread_join(zero_threads[n], ((void *)0));
 }
 free(g_p_zero_buffer);
 printf("salting device %s\n", g_device_name);
 rand_seed();
 unsigned long salt_threads[8];
 for (unsigned int n = 0; n < 8; n++) {
  if (pthread_create(&salt_threads[n], ((void *)0), run_salt,
    (void *)(unsigned long)n) != 0) {
   printf("ERROR: creating salt thread %" "u" "\n", n);
   exit(-1);
  }
 }
 for (unsigned int n = 0; n < 8; n++) {
  pthread_join(salt_threads[n], ((void *)0));
 }
 return 0;
}


decompiled_code:
__int64 __fastcall read_file(const char *a1, __int64 a2, unsigned __int64 *a3)
{
int v5; // eax
unsigned __int64 v6; // rdx
int v7; // er15
unsigned __int64 v8; // r14
ssize_t v9; // rax
int *v10; // rbx
char *v11; // rax
__int64 result; // rax
int *v13; // rax
int v14; // edi
unsigned int *v15; // rbx
char *v16; // rax
char v17[15]; // [rsp-Eh] [rbp-100h] BYREF

v5 = open64(a1, 0);
if ( v5 < 0 )
{
v13 = _errno_location();
v14 = *v13;
v15 = (unsigned int *)v13;
result = 1LL;
if ( v14 != 2 )
{
v16 = strerror_r(v14, v17, 0xC8uLL);
printf("ERROR: couldn't open file %s for reading: %d '%s'\n", a1, *v15, v16);
result = 2LL;
}
}
else
{
v6 = *a3;
v7 = v5;
v8 = 0LL;
if ( *a3 )
{
while ( 1 )
{
v9 = read(v7, (void *)(a2 + v8), v6 - v8);
if ( v9 < 0 )
break;
if ( v9 )
{
v6 = *a3;
v8 += v9;
if ( *a3 > v8 )
continue;
}
goto LABEL_11;
}
v10 = _errno_location();
v11 = strerror_r(*v10, v17, 0xC8uLL);
printf("ERROR: couldn't read file %s: %d '%s'\n", a1, (unsigned int)*v10, v11);
close(v7);
result = 2LL;
}
else
{
LABEL_11:
close(v7);
if ( *a3 == v8 )
{
printf("ERROR: read buffer too small for file %s\n", a1);
result = 2LL;
}
else
{
*a3 = v8;
result = 0LL;
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(const char *a1, __int64 a2, unsigned __int64 *a3)
{
int v5; // eax
unsigned __int64 v6; // rdx
int v7; // er15
unsigned __int64 v8; // r14
ssize_t v9; // rax
int *v10; // rbx
char *v11; // rax
__int64 result; // rax
int *v13; // rax
int v14; // edi
unsigned int *v15; // rbx
char *v16; // rax
char v17[15]; // [rsp-Eh] [rbp-100h] BYREF

v5 = open64(a1, 0);
if ( v5 < 0 )
{
v13 = _errno_location();
v14 = *v13;
v15 = (unsigned int *)v13;
result = 1LL;
if ( v14 != 2 )
{
v16 = strerror_r(v14, v17, 0xC8uLL);
printf("ERROR: couldn't open file %s for reading: %d '%s'\n", a1, *v15, v16);
result = 2LL;
}
}
else
{
v6 = *a3;
v7 = v5;
v8 = 0LL;
if ( *a3 )
{
while ( 1 )
{
v9 = read(v7, (void *)(a2 + v8), v6 - v8);
if ( v9 < 0 )
break;
if ( v9 )
{
v6 = *a3;
v8 += v9;
if ( *a3 > v8 )
continue;
}
goto LABEL_11;
}
v10 = _errno_location();
v11 = strerror_r(*v10, v17, 0xC8uLL);
printf("ERROR: couldn't read file %s: %d '%s'\n", a1, (unsigned int)*v10, v11);
close(v7);
result = 2LL;
}
else
{
LABEL_11:
close(v7);
if ( *a3 == v8 )
{
printf("ERROR: read buffer too small for file %s\n", a1);
result = 2LL;
}
else
{
*a3 = v8;
result = 0LL;
}
}
}
return result;
}

original_code:
static file_res
read_file(const char* path, void* buf, size_t* limit)
{
 int32_t fd = open(path, 00);
 if (fd < 0) {
  if ((*__errno_location ()) == 2) {
   return FILE_RES_NOT_FOUND;
  }
  printf("ERROR: couldn't open file %s for reading: %d '%s'\n", path,
    (*__errno_location ()), strerror_r((*__errno_location ()), (char*)__builtin_alloca (200), 200));
  return FILE_RES_ERROR;
 }
 size_t total = 0;
 while (total < *limit) {
  ssize_t len = read(fd, (uint8_t*)buf + total, *limit - total);
  if (len < 0) {
   printf("ERROR: couldn't read file %s: %d '%s'\n", path, (*__errno_location ()),
     strerror_r((*__errno_location ()), (char*)__builtin_alloca (200), 200));
   close(fd);
   return FILE_RES_ERROR;
  }
  if (len == 0) {
   break;
  }
  total += (size_t)len;
 }
 close(fd);
 if (total == *limit) {
  printf("ERROR: read buffer too small for file %s\n", path);
  return FILE_RES_ERROR;
 }
 *limit = total;
 return FILE_RES_OK;
}

canonical_original_code:
static enum file_res read_file(char *path, void *buf, unsigned long *limit)
{
 int fd = open(path, 00);
 if (fd < 0) {
  if ((*__errno_location ()) == 2) {
   return FILE_RES_NOT_FOUND;
  }
  printf("ERROR: couldn't open file %s for reading: %d '%s'\n", path,
    (*__errno_location ()), strerror_r((*__errno_location ()), (char *)__builtin_alloca (200), 200));
  return FILE_RES_ERROR;
 }
 unsigned long total = 0;
 while (total < *limit) {
  long len = read(fd, (uint8_t*)buf + total, *limit - total);
  if (len < 0) {
   printf("ERROR: couldn't read file %s: %d '%s'\n", path, (*__errno_location ()),
     strerror_r((*__errno_location ()), (char *)__builtin_alloca (200), 200));
   close(fd);
   return FILE_RES_ERROR;
  }
  if (len == 0) {
   break;
  }
  total += (unsigned long)len;
 }
 close(fd);
 if (total == *limit) {
  printf("ERROR: read buffer too small for file %s\n", path);
  return FILE_RES_ERROR;
 }
 *limit = total;
 return FILE_RES_OK;
}

variable_types:
path
char *

variable_types:
buf
void *

variable_types:
limit
unsigned long *

variable_types:
total
unsigned long

variable_types: len long

return_type: enum file_res { FILE_RES_OK=0, FILE_RES_NOT_FOUND=1, FILE_RES_ERROR=2 }


decompiled_code:
__int64 __fastcall read_index(const char *a1, _WORD *a2)
{
unsigned int v2; // er12
__int64 result; // rax
unsigned __int64 v4; // rax
unsigned __int64 v5; // [rsp+0h] [rbp-98h] BYREF
char *endptr; // [rsp+8h] [rbp-90h] BYREF
char nptr[136]; // [rsp+10h] [rbp-88h] BYREF

v5 = 100LL;
v2 = read_file(a1, (__int64)nptr, &v5);
if ( v2 )
return v2;
*((_BYTE *)&endptr + v5 + 7) = 0;
v4 = strtoul(nptr, &endptr, 10);
if ( *endptr || v4 > 0x3FF )
{
printf("ERROR: invalid index '%s' in %s\n", nptr, a1);
result = 2LL;
}
else
{
*a2 = v4;
result = v2;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(const char *a1, _WORD *a2)
{
unsigned int v2; // er12
__int64 result; // rax
unsigned __int64 v4; // rax
unsigned __int64 v5; // [rsp+0h] [rbp-98h] BYREF
char *endptr; // [rsp+8h] [rbp-90h] BYREF
char nptr[136]; // [rsp+10h] [rbp-88h] BYREF

v5 = 100LL;
v2 = func0(a1, (__int64)nptr, &v5);
if ( v2 )
return v2;
*((_BYTE *)&endptr + v5 + 7) = 0;
v4 = strtoul(nptr, &endptr, 10);
if ( *endptr || v4 > 0x3FF )
{
printf("ERROR: invalid index '%s' in %s\n", nptr, a1);
result = 2LL;
}
else
{
*a2 = v4;
result = v2;
}
return result;
}

original_code:
static file_res
read_index(const char* path, uint16_t* val)
{
 char buf[100];
 size_t limit = sizeof(buf);
 file_res res = read_file(path, buf, &limit);
 if (res != FILE_RES_OK) {
  return res;
 }
 buf[limit - 1] = '\0';
 char* end;
 uint64_t x = strtoul(buf, &end, 10);
 if (*end != '\0' || x >= 1024) {
  printf("ERROR: invalid index '%s' in %s\n", buf, path);
  return FILE_RES_ERROR;
 }
 *val = (uint16_t)x;
 return FILE_RES_OK;
}

canonical_original_code:
static enum file_res read_index(char *path, unsigned short *val)
{
 char buf[100];
 unsigned long limit = sizeof(buf);
 enum file_res res = read_file(path, buf, &limit);
 if (res != FILE_RES_OK) {
  return res;
 }
 buf[limit - 1] = '\0';
 char *end;
 unsigned long x = strtoul(buf, &end, 10);
 if (*end != '\0' || x >= 1024) {
  printf("ERROR: invalid index '%s' in %s\n", buf, path);
  return FILE_RES_ERROR;
 }
 *val = (unsigned short)x;
 return FILE_RES_OK;
}

variable_types:
val
unsigned short *

variable_types:
buf
char [100]

variable_types:
limit
unsigned long

variable_types: enum file_res { FILE_RES_OK=0, FILE_RES_NOT_FOUND=1, FILE_RES_ERROR=2 }

variable_types:
end
char *

variable_types:
x
unsigned long


decompiled_code:
__int64 num_cpus()
{
unsigned int v0; // er12
unsigned __int64 v1; // rbx
int v2; // ebp
unsigned __int64 v3; // rax
char v4; // cl
int v5; // eax
__int16 v7; // [rsp+Eh] [rbp-49Ah] BYREF
__int64 v8[16]; // [rsp+10h] [rbp-498h] BYREF
char s[1048]; // [rsp+90h] [rbp-418h] BYREF

if ( (unsigned int)read_list_constprop_0(v8) )
{
v0 = 0;
puts("ERROR: couldn't read list of online CPUs");
}
else
{
v0 = 0;
v1 = 0LL;
v2 = 0;
do
{
snprintf(s, 0x3E8uLL, "/sys/devices/system/cpu/cpu%hu/topology/physical_package_id", (unsigned int)v1);
v5 = read_index(s, &v7);
if ( v5 == 1 )
{
v0 = (unsigned __int16)v2;
printf("detected %u CPUs\n\n", (unsigned __int16)v2);
return v0;
}
if ( v5 )
{
printf("ERROR: reading OS package index from %s\n", s);
return v0;
}
v3 = v1;
v4 = v1++;
v2 += ((unsigned __int64)v8[v3 >> 6] >> v4) & 1;
}
while ( v1 != 1024 );
v0 = 0;
puts("ERROR: too many CPUs");
}
return v0;
}

canonical_decompiled_code:
__int64 func3()
{
unsigned int v0; // er12
unsigned __int64 v1; // rbx
int v2; // ebp
unsigned __int64 v3; // rax
char v4; // cl
int v5; // eax
__int16 v7; // [rsp+Eh] [rbp-49Ah] BYREF
__int64 v8[16]; // [rsp+10h] [rbp-498h] BYREF
char s[1048]; // [rsp+90h] [rbp-418h] BYREF

if ( (unsigned int)func2(v8) )
{
v0 = 0;
puts("ERROR: couldn't read list of online CPUs");
}
else
{
v0 = 0;
v1 = 0LL;
v2 = 0;
do
{
snprintf(s, 0x3E8uLL, "/sys/devices/system/cpu/cpu%hu/topology/physical_package_id", (unsigned int)v1);
v5 = func1(s, &v7);
if ( v5 == 1 )
{
v0 = (unsigned __int16)v2;
printf("detected %u CPUs\n\n", (unsigned __int16)v2);
return v0;
}
if ( v5 )
{
printf("ERROR: reading OS package index from %s\n", s);
return v0;
}
v3 = v1;
v4 = v1++;
v2 += ((unsigned __int64)v8[v3 >> 6] >> v4) & 1;
}
while ( v1 != 1024 );
v0 = 0;
puts("ERROR: too many CPUs");
}
return v0;
}

original_code:
uint32_t
num_cpus()
{
 cpu_set_t os_cpus_online;
 if (read_list("/sys/devices/system/cpu/online", &os_cpus_online) !=
   FILE_RES_OK) {
  printf("ERROR: couldn't read list of online CPUs\n");
  return 0;
 }
 uint16_t n_cpus = 0;
 uint16_t n_os_cpus;
 for (n_os_cpus = 0; n_os_cpus < 1024; n_os_cpus++) {
  char path[1000];
  snprintf(path, sizeof(path),
    "/sys/devices/system/cpu/cpu%hu/topology/physical_package_id",
    n_os_cpus);
  uint16_t i_os_package;
  file_res res = read_index(path, &i_os_package);
  if (res == FILE_RES_NOT_FOUND) {
   break;
  }
  if (res != FILE_RES_OK) {
   printf("ERROR: reading OS package index from %s\n", path);
   return 0;
  }
  if ((__extension__ ({ size_t __cpu = (n_os_cpus); __cpu / 8 < (sizeof (cpu_set_t)) ? ((((const __cpu_mask *) ((&os_cpus_online)->__bits))[((__cpu) / (8 * sizeof (__cpu_mask)))] & ((__cpu_mask) 1 << ((__cpu) % (8 * sizeof (__cpu_mask)))))) != 0 : 0; }))) {
   n_cpus++;
  }
 }
 if (n_os_cpus == 1024) {
  printf("ERROR: too many CPUs\n");
  return 0;
 }
 printf("detected %" "u" " CPUs\n\n", n_cpus);
 return n_cpus;
}

canonical_original_code:
unsigned int num_cpus()
{
 struct cpu_set_t os_cpus_online;
 if (read_list("/sys/devices/system/cpu/online", &os_cpus_online) !=
   FILE_RES_OK) {
  printf("ERROR: couldn't read list of online CPUs\n");
  return 0;
 }
 unsigned short n_cpus = 0;
 unsigned short n_os_cpus;
 for (n_os_cpus = 0; n_os_cpus < 1024; n_os_cpus++) {
  char path[1000];
  snprintf(path, sizeof(path),
    "/sys/devices/system/cpu/cpu%hu/topology/physical_package_id",
    n_os_cpus);
  unsigned short i_os_package;
  enum file_res res = read_index(path, &i_os_package);
  if (res == FILE_RES_NOT_FOUND) {
   break;
  }
  if (res != FILE_RES_OK) {
   printf("ERROR: reading OS package index from %s\n", path);
   return 0;
  }
  if ((__extension__ ({ unsigned long __cpu = (n_os_cpus); __cpu / 8 < (sizeof (cpu_set_t)) ? ((((unsigned long *) ((&os_cpus_online)->__bits))[((__cpu) / (8 * sizeof (__cpu_mask)))] & ((unsigned long) 1 << ((__cpu) % (8 * sizeof (__cpu_mask)))))) != 0 : 0; }))) {
   n_cpus++;
  }
 }
 if (n_os_cpus == 1024) {
  printf("ERROR: too many CPUs\n");
  return 0;
 }
 printf("detected %" "u" " CPUs\n\n", n_cpus);
 return n_cpus;
}

variable_types: struct cpu_set_t { unsigned long __bits[-1]; }

variable_types:
path
char [1000]

return_type: unsigned int

user_defined_types: enum file_res { FILE_RES_OK=0, FILE_RES_NOT_FOUND=1, FILE_RES_ERROR=2 }


decompiled_code:
int __fastcall parse_device_names(__int64 a1, __int64 a2, _DWORD *a3)
{
char *v4; // rax
const char *v5; // r14
__int64 v6; // r13
size_t v7; // rax
unsigned int v8; // eax
_DWORD *v9; // rcx

while ( 1 )
{
v4 = strtok(0LL, ",; \t\n\r");
v5 = v4;
if ( !v4 )
break;
v6 = (unsigned int)*a3;
if ( v6 == a1 )
{
LODWORD(v4) = puts("ERROR: too many device names");
*a3 = 0;
return (int)v4;
}
v7 = strlen(v4);
if ( v7 - 1 > 0x7E )
{
LODWORD(v4) = printf("ERROR: bad device name '%s'\n", v5);
*a3 = 0;
return (int)v4;
}
v8 = v7 + 1;
v9 = (_DWORD *)(a2 + (v6 << 7));
if ( v8 < 8 )
{
if ( (v8 & 4) != 0 )
{
*v9 = *(_DWORD *)v5;
*(_DWORD *)((char *)v9 + v8 - 4) = *(_DWORD *)&v5[v8 - 4];
}
else if ( v8 )
{
*(_BYTE *)v9 = *v5;
if ( (v8 & 2) != 0 )
*(_WORD *)((char *)v9 + v8 - 2) = *(_WORD *)&v5[v8 - 2];
}
}
else
{
*(_QWORD *)v9 = *(_QWORD *)v5;
*(_QWORD *)((char *)v9 + v8 - 8) = *(_QWORD *)&v5[v8 - 8];
qmemcpy(
(void *)((unsigned __int64)(v9 + 2) & 0xFFFFFFFFFFFFFFF8LL),
(const void *)(v5 - ((const char *)v9 - ((unsigned __int64)(v9 + 2) & 0xFFFFFFFFFFFFFFF8LL))),
8LL * ((v8 + (_DWORD)v9 - (((_DWORD)v9 + 8) & 0xFFFFFFF8)) >> 3));
}
++*a3;
}
return (int)v4;
}

canonical_decompiled_code:
int __fastcall func0(__int64 a1, __int64 a2, _DWORD *a3)
{
char *v4; // rax
const char *v5; // r14
__int64 v6; // r13
size_t v7; // rax
unsigned int v8; // eax
_DWORD *v9; // rcx

while ( 1 )
{
v4 = strtok(0LL, ",; \t\n\r");
v5 = v4;
if ( !v4 )
break;
v6 = (unsigned int)*a3;
if ( v6 == a1 )
{
LODWORD(v4) = puts("ERROR: too many device names");
*a3 = 0;
return (int)v4;
}
v7 = strlen(v4);
if ( v7 - 1 > 0x7E )
{
LODWORD(v4) = printf("ERROR: bad device name '%s'\n", v5);
*a3 = 0;
return (int)v4;
}
v8 = v7 + 1;
v9 = (_DWORD *)(a2 + (v6 << 7));
if ( v8 < 8 )
{
if ( (v8 & 4) != 0 )
{
*v9 = *(_DWORD *)v5;
*(_DWORD *)((char *)v9 + v8 - 4) = *(_DWORD *)&v5[v8 - 4];
}
else if ( v8 )
{
*(_BYTE *)v9 = *v5;
if ( (v8 & 2) != 0 )
*(_WORD *)((char *)v9 + v8 - 2) = *(_WORD *)&v5[v8 - 2];
}
}
else
{
*(_QWORD *)v9 = *(_QWORD *)v5;
*(_QWORD *)((char *)v9 + v8 - 8) = *(_QWORD *)&v5[v8 - 8];
qmemcpy(
(void *)((unsigned __int64)(v9 + 2) & 0xFFFFFFFFFFFFFFF8LL),
(const void *)(v5 - ((const char *)v9 - ((unsigned __int64)(v9 + 2) & 0xFFFFFFFFFFFFFFF8LL))),
8LL * ((v8 + (_DWORD)v9 - (((_DWORD)v9 + 8) & 0xFFFFFFF8)) >> 3));
}
++*a3;
}
return (int)v4;
}

original_code:
void
parse_device_names(size_t max_num_devices, char names[][128],
  uint32_t* p_num_devices)
{
 const char* val;
 while ((val = strtok(((void *)0), ",;" " \t\n\r")) != ((void *)0)) {
  if (*p_num_devices == max_num_devices) {
   printf("ERROR: too many device names\n");
   *p_num_devices = 0;
   return;
  }
  size_t name_len = strlen(val);
  if (name_len == 0 || name_len >= 128) {
   printf("ERROR: bad device name '%s'\n", val);
   *p_num_devices = 0;
   return;
  }
  strcpy(names[*p_num_devices], val);
  (*p_num_devices)++;
 }
}

canonical_original_code:
void parse_device_names(unsigned long max_num_devices, char names[][128], unsigned int *p_num_devices)
{
 char *val;
 while ((val = strtok(((void *)0), ",;" " \t\n\r")) != ((void *)0)) {
  if (*p_num_devices == max_num_devices) {
   printf("ERROR: too many device names\n");
   *p_num_devices = 0;
   return;
  }
  unsigned long name_len = strlen(val);
  if (name_len == 0 || name_len >= 128) {
   printf("ERROR: bad device name '%s'\n", val);
   *p_num_devices = 0;
   return;
  }
  strcpy(names[*p_num_devices], val);
  (*p_num_devices)++;
 }
}

variable_types:
names
char [][128]

variable_types:
val
char *


decompiled_code:
const char *parse_scheduler_mode()
{
char *v0; // rax
const char *result; // rax

v0 = strtok(0LL, " \t\n\r");
if ( v0 )
{
if ( !strcmp(v0, "noop") )
{
result = "noop";
}
else if ( !strcmp(v0, "cfq") )
{
result = "cfq";
}
else
{
printf("ERROR: unknown scheduler mode '%s' - using 'noop'\n", v0);
result = "noop";
}
}
else
{
puts("ERROR: missing scheduler mode - using 'noop'");
result = "noop";
}
return result;
}

canonical_decompiled_code:
const char *func1()
{
char *v0; // rax
const char *result; // rax

v0 = strtok(0LL, " \t\n\r");
if ( v0 )
{
if ( !strcmp(v0, "noop") )
{
result = "noop";
}
else if ( !strcmp(v0, "cfq") )
{
result = "cfq";
}
else
{
printf("ERROR: unknown scheduler mode '%s' - using 'noop'\n", v0);
result = "noop";
}
}
else
{
puts("ERROR: missing scheduler mode - using 'noop'");
result = "noop";
}
return result;
}

original_code:
const char*
parse_scheduler_mode()
{
 const char* val = strtok(((void *)0), " \t\n\r");
 if (val == ((void *)0)) {
  printf("ERROR: missing scheduler mode - using 'noop'\n");
  return "noop";
 }
 for (uint32_t m = 0; m < N_SCHEDULER_MODES; m++) {
  if (strcmp(val, SCHEDULER_MODES[m]) == 0) {
   return SCHEDULER_MODES[m];
  }
 }
 printf("ERROR: unknown scheduler mode '%s' - using 'noop'\n", val);
 return "noop";
}

canonical_original_code:
char *parse_scheduler_mode()
{
 char *val = strtok(((void *)0), " \t\n\r");
 if (val == ((void *)0)) {
  printf("ERROR: missing scheduler mode - using 'noop'\n");
  return "noop";
 }
 for (unsigned int m = 0; m < N_SCHEDULER_MODES; m++) {
  if (strcmp(val, SCHEDULER_MODES[m]) == 0) {
   return SCHEDULER_MODES[m];
  }
 }
 printf("ERROR: unknown scheduler mode '%s' - using 'noop'\n", val);
 return "noop";
}

variable_types:
m
unsigned int

return_type: char *


decompiled_code:
unsigned __int64 parse_uint32()
{
char *v0; // rax
const char *v1; // rbp
unsigned __int64 result; // rax

v0 = strtok(0LL, " \t\n\r");
if ( v0 )
{
v1 = v0;
result = strtoul(v0, 0LL, 10);
if ( result > 0xFFFFFFFF )
{
printf("ERROR: %s overflows unsigned int\n", v1);
result = 0LL;
}
else
{
result = (unsigned int)result;
}
}
else
{
puts("ERROR: missing integer config value");
result = 0LL;
}
return result;
}

canonical_decompiled_code:
unsigned __int64 func2()
{
char *v0; // rax
const char *v1; // rbp
unsigned __int64 result; // rax

v0 = strtok(0LL, " \t\n\r");
if ( v0 )
{
v1 = v0;
result = strtoul(v0, 0LL, 10);
if ( result > 0xFFFFFFFF )
{
printf("ERROR: %s overflows unsigned int\n", v1);
result = 0LL;
}
else
{
result = (unsigned int)result;
}
}
else
{
puts("ERROR: missing integer config value");
result = 0LL;
}
return result;
}

original_code:
uint32_t
parse_uint32()
{
 const char* val = strtok(((void *)0), " \t\n\r");
 if (val == ((void *)0)) {
  printf("ERROR: missing integer config value\n");
  return 0;
 }
 uint64_t u64_val = strtoul(val, ((void *)0), 10);
 if (u64_val > (4294967295U)) {
  printf("ERROR: %s overflows unsigned int\n", val);
  return 0;
 }
 return (uint32_t)u64_val;
}

canonical_original_code:
unsigned int parse_uint32()
{
 char *val = strtok(((void *)0), " \t\n\r");
 if (val == ((void *)0)) {
  printf("ERROR: missing integer config value\n");
  return 0;
 }
 unsigned long u64_val = strtoul(val, ((void *)0), 10);
 if (u64_val > (4294967295U)) {
  printf("ERROR: %s overflows unsigned int\n", val);
  return 0;
 }
 return (unsigned int)u64_val;
}


decompiled_code:
__int64 parse_yes_no()
{
char *v0; // rax
unsigned int v1; // er8

v0 = strtok(0LL, " \t\n\r");
v1 = 0;
if ( v0 )
LOBYTE(v1) = *v0 == 121;
return v1;
}

canonical_decompiled_code:
__int64 func3()
{
char *v0; // rax
unsigned int v1; // er8

v0 = strtok(0LL, " \t\n\r");
v1 = 0;
if ( v0 )
LOBYTE(v1) = *v0 == 121;
return v1;
}

original_code:
_Bool
parse_yes_no()
{
 const char* val = strtok(((void *)0), " \t\n\r");
 return val != ((void *)0) && *val == 'y';
}

canonical_original_code:
_Bool parse_yes_no()
{
 char *val = strtok(((void *)0), " \t\n\r");
 return val != ((void *)0) && *val == 'y';
}


decompiled_code:
int __fastcall set_action(int sig, void (*a2)(int))
{
int result; // eax
struct sigaction v3; // [rsp+0h] [rbp-A8h] BYREF

v3.sa_handler = a2;
memset(&v3.sa_mask, 0, 0x90uLL);
sigemptyset(&v3.sa_mask);
v3.sa_flags = 268435460;
result = sigaction(sig, &v3, 0LL);
if ( result < 0 )
{
printf("ERROR: could not register signal handler for %d\n", (unsigned int)sig);
fflush(stdout);
exit(-1);
}
return result;
}

canonical_decompiled_code:
int __fastcall func0(int sig, void (*a2)(int))
{
int result; // eax
struct sigaction v3; // [rsp+0h] [rbp-A8h] BYREF

v3.sa_handler = a2;
memset(&v3.sa_mask, 0, 0x90uLL);
sigemptyset(&v3.sa_mask);
v3.sa_flags = 268435460;
result = sigaction(sig, &v3, 0LL);
if ( result < 0 )
{
printf("ERROR: could not register signal handler for %d\n", (unsigned int)sig);
fflush(stdout);
exit(-1);
}
return result;
}

original_code:
static void
set_action(int sig_num, action_t act)
{
 struct sigaction sa;
 memset(&sa, 0, sizeof(sa));
 sa.__sigaction_handler.sa_sigaction = act;
 sigemptyset(&sa.sa_mask);
 sa.sa_flags = 0x10000000 | 4;
 if (sigaction(sig_num, &sa, ((void *)0)) < 0) {
  printf("ERROR: could not register signal handler for %d\n", sig_num);
  fflush(stdout);
  _exit(-1);
 }
}

canonical_original_code:
static void set_action(int sig_num, void (*act)(int sig, struct siginfo_t *info, void *ctx))
{
 struct sigaction sa;
 memset(&sa, 0, sizeof(sa));
 sa.__sigaction_handler.sa_sigaction = act;
 sigemptyset(&sa.sa_mask);
 sa.sa_flags = 0x10000000 | 4;
 if (sigaction(sig_num, &sa, ((void *)0)) < 0) {
  printf("ERROR: could not register signal handler for %d\n", sig_num);
  fflush(stdout);
  _exit(-1);
 }
}

variable_types: void (*)(int sig, struct siginfo_t { int si_signo; int si_errno; int si_code; int __pad0; union { int _pad[-1]; struct { int si_pid; unsigned int si_uid; } _kill; struct { int si_tid; int si_overrun; union sigval { int sival_int; void *sival_ptr; } si_sigval; } _timer; struct { int si_pid; unsigned int si_uid; union sigval si_sigval; } _rt; struct { int si_pid; unsigned int si_uid; int si_status; long si_utime; long si_stime; } _sigchld; struct { void *si_addr; short si_addr_lsb; union { struct { void *_lower; void *_upper; } _addr_bnd; unsigned int _pkey; } _bounds; } _sigfault; struct { long si_band; int si_fd; } _sigpoll; struct { void *_call_addr; int _syscall; unsigned int _arch; } _sigsys; } _sifields; } *info, void *ctx)

variable_types: struct sigaction { union { void (*sa_handler)(int); void (*sa_sigaction)(int, struct siginfo_t { int si_signo; int si_errno; int si_code; int __pad0; union { int _pad[-1]; struct { int si_pid; unsigned int si_uid; } _kill; struct { int si_tid; int si_overrun; union sigval { int sival_int; void *sival_ptr; } si_sigval; } _timer; struct { int si_pid; unsigned int si_uid; union sigval si_sigval; } _rt; struct { int si_pid; unsigned int si_uid; int si_status; long si_utime; long si_stime; } _sigchld; struct { void *si_addr; short si_addr_lsb; union { struct { void *_lower; void *_upper; } _addr_bnd; unsigned int _pkey; } _bounds; } _sigfault; struct { long si_band; int si_fd; } _sigpoll; struct { void *_call_addr; int _syscall; unsigned int _arch; } _sigsys; } _sifields; } *, void *); } __sigaction_handler; struct __sigset_t { unsigned long __val[-1]; } sa_mask; int sa_flags; void (*sa_restorer)(); }

user_defined_types: struct sigaction { union { void (*sa_handler)(int); void (*sa_sigaction)(int, struct siginfo_t *, void *); } __sigaction_handler; struct __sigset_t sa_mask; int sa_flags; void (*sa_restorer)(); }

user_defined_types: struct siginfo_t { int si_signo; int si_errno; int si_code; int __pad0; union { int _pad[-1]; struct { int si_pid; unsigned int si_uid; } _kill; struct { int si_tid; int si_overrun; union sigval si_sigval; } _timer; struct { int si_pid; unsigned int si_uid; union sigval si_sigval; } _rt; struct { int si_pid; unsigned int si_uid; int si_status; long si_utime; long si_stime; } _sigchld; struct { void *si_addr; short si_addr_lsb; union { struct { void *_lower; void *_upper; } _addr_bnd; unsigned int _pkey; } _bounds; } _sigfault; struct { long si_band; int si_fd; } _sigpoll; struct { void *_call_addr; int _syscall; unsigned int _arch; } _sigsys; } _sifields; }


decompiled_code:
int __fastcall reraise_signal(int sig)
{
set_handler_constprop_0(sig);
return raise(sig);
}

canonical_decompiled_code:
int __fastcall func2(int sig)
{
func1(sig);
return raise(sig);
}

original_code:
static void
reraise_signal(int sig_num)
{
 set_handler(sig_num, ((__sighandler_t) 0));
 raise(sig_num);
}

canonical_original_code:
static void reraise_signal(int sig_num)
{
 set_handler(sig_num, ((void (*)(int)) 0));
 raise(sig_num);
}


decompiled_code:
int __fastcall act_sig_handle_segv(int sig)
{
int v1; // eax
unsigned int v2; // ebp
void **v3; // r14
int v4; // er15
void **v5; // r13
__int64 v6; // rcx
__int64 v7; // rbx
char **v8; // r13
const char *v9; // rdx
__int64 v10; // rsi
void *v12[50]; // [rsp+0h] [rbp-5B8h] BYREF
char v13[1064]; // [rsp+190h] [rbp-428h] BYREF

puts("SIGSEGV received");
v1 = backtrace(v12, 50);
v2 = v1;
if ( v1 <= 0 )
{
printf("stacktrace: found %d frames:%s offset 0x%lx\n", (unsigned int)v1, v13, &_executable_start);
if ( backtrace_symbols(v12, v2) )
goto LABEL_6;
LABEL_8:
puts("stacktrace: found no symbols");
goto LABEL_6;
}
v3 = v12;
v4 = 0;
v5 = &v12[(unsigned int)(v1 - 1) + 1];
do
{
v6 = (__int64)*v3++;
v4 += snprintf(&v13[v4], 1000LL - v4, " 0x%lx", v6);
}
while ( v3 != v5 );
v7 = 0LL;
printf("stacktrace: found %d frames:%s offset 0x%lx\n", v2, v13, &_executable_start);
v8 = backtrace_symbols(v12, v2);
if ( !v8 )
goto LABEL_8;
do
{
v9 = v8[v7];
v10 = (unsigned int)v7++;
printf("stacktrace: frame %d: %s\n", v10, v9);
}
while ( v2 != v7 );
LABEL_6:
fflush(stdout);
return reraise_signal(sig);
}

canonical_decompiled_code:
int __fastcall func3(int sig)
{
int v1; // eax
unsigned int v2; // ebp
void **v3; // r14
int v4; // er15
void **v5; // r13
__int64 v6; // rcx
__int64 v7; // rbx
char **v8; // r13
const char *v9; // rdx
__int64 v10; // rsi
void *v12[50]; // [rsp+0h] [rbp-5B8h] BYREF
char v13[1064]; // [rsp+190h] [rbp-428h] BYREF

puts("SIGSEGV received");
v1 = backtrace(v12, 50);
v2 = v1;
if ( v1 <= 0 )
{
printf("stacktrace: found %d frames:%s offset 0x%lx\n", (unsigned int)v1, v13, &_executable_start);
if ( backtrace_symbols(v12, v2) )
goto LABEL_6;
LABEL_8:
puts("stacktrace: found no symbols");
goto LABEL_6;
}
v3 = v12;
v4 = 0;
v5 = &v12[(unsigned int)(v1 - 1) + 1];
do
{
v6 = (__int64)*v3++;
v4 += snprintf(&v13[v4], 1000LL - v4, " 0x%lx", v6);
}
while ( v3 != v5 );
v7 = 0LL;
printf("stacktrace: found %d frames:%s offset 0x%lx\n", v2, v13, &_executable_start);
v8 = backtrace_symbols(v12, v2);
if ( !v8 )
goto LABEL_8;
do
{
v9 = v8[v7];
v10 = (unsigned int)v7++;
printf("stacktrace: frame %d: %s\n", v10, v9);
}
while ( v2 != v7 );
LABEL_6:
fflush(stdout);
return func2(sig);
}

original_code:
static void
act_sig_handle_segv(int sig_num, siginfo_t* info, void* ctx)
{
 printf("SIGSEGV received\n");
 do { void* bt[50]; int sz = backtrace(bt, 50); char trace[50 * 20]; int off = 0; for (int i = 0; i < sz; i++) { off += snprintf(trace + off, sizeof(trace) - off, " 0x%lx", (uint64_t)bt[i]); } printf("stacktrace: found %d frames:%s offset 0x%lx\n", sz, trace, (uint64_t)&__executable_start); char** syms = backtrace_symbols(bt, sz); if (syms != ((void *)0)) { for (int i = 0; i < sz; ++i) { printf("stacktrace: frame %d: %s\n", i, syms[i]); } } else { printf("stacktrace: found no symbols\n"); } fflush(stdout); } while (0);;
 reraise_signal(sig_num);
}

canonical_original_code:
static void act_sig_handle_segv(int sig_num, struct siginfo_t *info, void *ctx)
{
 printf("SIGSEGV received\n");
 do { void *bt[50]; int sz = backtrace(bt, 50); char trace[-1]; int off = 0; for (int i = 0; i < sz; i++) { off += snprintf(trace + off, sizeof(trace) - off, " 0x%lx", (unsigned long)bt[i]); } printf("stacktrace: found %d frames:%s offset 0x%lx\n", sz, trace, (unsigned long)&__executable_start); char **syms = backtrace_symbols(bt, sz); if (syms != ((void *)0)) { for (int i = 0; i < sz; ++i) { printf("stacktrace: frame %d: %s\n", i, syms[i]); } } else { printf("stacktrace: found no symbols\n"); } fflush(stdout); } while (0);;
 reraise_signal(sig_num);
}

variable_types: struct siginfo_t { int si_signo; int si_errno; int si_code; int __pad0; union { int _pad[-1]; struct { int si_pid; unsigned int si_uid; } _kill; struct { int si_tid; int si_overrun; union sigval { int sival_int; void *sival_ptr; } si_sigval; } _timer; struct { int si_pid; unsigned int si_uid; union sigval si_sigval; } _rt; struct { int si_pid; unsigned int si_uid; int si_status; long si_utime; long si_stime; } _sigchld; struct { void *si_addr; short si_addr_lsb; union { struct { void *_lower; void *_upper; } _addr_bnd; unsigned int _pkey; } _bounds; } _sigfault; struct { long si_band; int si_fd; } _sigpoll; struct { void *_call_addr; int _syscall; unsigned int _arch; } _sigsys; } _sifields; } *

variable_types:
ctx
void *

variable_types:
bt
void *[50]

variable_types: sz int

variable_types:
trace
char [-1]

variable_types: off int

variable_types: i int

variable_types:
syms
char **


decompiled_code:
int __fastcall act_sig_handle_ill(int sig)
{
int v1; // eax
unsigned int v2; // ebp
void **v3; // r14
int v4; // er15
void **v5; // r13
__int64 v6; // rcx
__int64 v7; // rbx
char **v8; // r13
const char *v9; // rdx
__int64 v10; // rsi
void *v12[50]; // [rsp+0h] [rbp-5B8h] BYREF
char v13[1064]; // [rsp+190h] [rbp-428h] BYREF

puts("SIGILL received");
v1 = backtrace(v12, 50);
v2 = v1;
if ( v1 <= 0 )
{
printf("stacktrace: found %d frames:%s offset 0x%lx\n", (unsigned int)v1, v13, &_executable_start);
if ( backtrace_symbols(v12, v2) )
goto LABEL_6;
LABEL_8:
puts("stacktrace: found no symbols");
goto LABEL_6;
}
v3 = v12;
v4 = 0;
v5 = &v12[(unsigned int)(v1 - 1) + 1];
do
{
v6 = (__int64)*v3++;
v4 += snprintf(&v13[v4], 1000LL - v4, " 0x%lx", v6);
}
while ( v3 != v5 );
v7 = 0LL;
printf("stacktrace: found %d frames:%s offset 0x%lx\n", v2, v13, &_executable_start);
v8 = backtrace_symbols(v12, v2);
if ( !v8 )
goto LABEL_8;
do
{
v9 = v8[v7];
v10 = (unsigned int)v7++;
printf("stacktrace: frame %d: %s\n", v10, v9);
}
while ( v2 != v7 );
LABEL_6:
fflush(stdout);
return reraise_signal(sig);
}

canonical_decompiled_code:
int __fastcall func4(int sig)
{
int v1; // eax
unsigned int v2; // ebp
void **v3; // r14
int v4; // er15
void **v5; // r13
__int64 v6; // rcx
__int64 v7; // rbx
char **v8; // r13
const char *v9; // rdx
__int64 v10; // rsi
void *v12[50]; // [rsp+0h] [rbp-5B8h] BYREF
char v13[1064]; // [rsp+190h] [rbp-428h] BYREF

puts("SIGILL received");
v1 = backtrace(v12, 50);
v2 = v1;
if ( v1 <= 0 )
{
printf("stacktrace: found %d frames:%s offset 0x%lx\n", (unsigned int)v1, v13, &_executable_start);
if ( backtrace_symbols(v12, v2) )
goto LABEL_6;
LABEL_8:
puts("stacktrace: found no symbols");
goto LABEL_6;
}
v3 = v12;
v4 = 0;
v5 = &v12[(unsigned int)(v1 - 1) + 1];
do
{
v6 = (__int64)*v3++;
v4 += snprintf(&v13[v4], 1000LL - v4, " 0x%lx", v6);
}
while ( v3 != v5 );
v7 = 0LL;
printf("stacktrace: found %d frames:%s offset 0x%lx\n", v2, v13, &_executable_start);
v8 = backtrace_symbols(v12, v2);
if ( !v8 )
goto LABEL_8;
do
{
v9 = v8[v7];
v10 = (unsigned int)v7++;
printf("stacktrace: frame %d: %s\n", v10, v9);
}
while ( v2 != v7 );
LABEL_6:
fflush(stdout);
return func2(sig);
}

original_code:
static void
act_sig_handle_ill(int sig_num, siginfo_t* info, void* ctx)
{
 printf("SIGILL received\n");
 do { void* bt[50]; int sz = backtrace(bt, 50); char trace[50 * 20]; int off = 0; for (int i = 0; i < sz; i++) { off += snprintf(trace + off, sizeof(trace) - off, " 0x%lx", (uint64_t)bt[i]); } printf("stacktrace: found %d frames:%s offset 0x%lx\n", sz, trace, (uint64_t)&__executable_start); char** syms = backtrace_symbols(bt, sz); if (syms != ((void *)0)) { for (int i = 0; i < sz; ++i) { printf("stacktrace: frame %d: %s\n", i, syms[i]); } } else { printf("stacktrace: found no symbols\n"); } fflush(stdout); } while (0);;
 reraise_signal(sig_num);
}

canonical_original_code:
static void act_sig_handle_ill(int sig_num, struct siginfo_t *info, void *ctx)
{
 printf("SIGILL received\n");
 do { void *bt[50]; int sz = backtrace(bt, 50); char trace[-1]; int off = 0; for (int i = 0; i < sz; i++) { off += snprintf(trace + off, sizeof(trace) - off, " 0x%lx", (unsigned long)bt[i]); } printf("stacktrace: found %d frames:%s offset 0x%lx\n", sz, trace, (unsigned long)&__executable_start); char **syms = backtrace_symbols(bt, sz); if (syms != ((void *)0)) { for (int i = 0; i < sz; ++i) { printf("stacktrace: frame %d: %s\n", i, syms[i]); } } else { printf("stacktrace: found no symbols\n"); } fflush(stdout); } while (0);;
 reraise_signal(sig_num);
}

user_defined_types: union sigval { int sival_int; void *sival_ptr; }


decompiled_code:
int __fastcall act_sig_handle_fpe(int sig)
{
int v1; // eax
unsigned int v2; // ebp
void **v3; // r14
int v4; // er15
void **v5; // r13
__int64 v6; // rcx
__int64 v7; // rbx
char **v8; // r13
const char *v9; // rdx
__int64 v10; // rsi
void *v12[50]; // [rsp+0h] [rbp-5B8h] BYREF
char v13[1064]; // [rsp+190h] [rbp-428h] BYREF

puts("SIGFPE received");
v1 = backtrace(v12, 50);
v2 = v1;
if ( v1 <= 0 )
{
printf("stacktrace: found %d frames:%s offset 0x%lx\n", (unsigned int)v1, v13, &_executable_start);
if ( backtrace_symbols(v12, v2) )
goto LABEL_6;
LABEL_8:
puts("stacktrace: found no symbols");
goto LABEL_6;
}
v3 = v12;
v4 = 0;
v5 = &v12[(unsigned int)(v1 - 1) + 1];
do
{
v6 = (__int64)*v3++;
v4 += snprintf(&v13[v4], 1000LL - v4, " 0x%lx", v6);
}
while ( v3 != v5 );
v7 = 0LL;
printf("stacktrace: found %d frames:%s offset 0x%lx\n", v2, v13, &_executable_start);
v8 = backtrace_symbols(v12, v2);
if ( !v8 )
goto LABEL_8;
do
{
v9 = v8[v7];
v10 = (unsigned int)v7++;
printf("stacktrace: frame %d: %s\n", v10, v9);
}
while ( v2 != v7 );
LABEL_6:
fflush(stdout);
return reraise_signal(sig);
}

canonical_decompiled_code:
int __fastcall func5(int sig)
{
int v1; // eax
unsigned int v2; // ebp
void **v3; // r14
int v4; // er15
void **v5; // r13
__int64 v6; // rcx
__int64 v7; // rbx
char **v8; // r13
const char *v9; // rdx
__int64 v10; // rsi
void *v12[50]; // [rsp+0h] [rbp-5B8h] BYREF
char v13[1064]; // [rsp+190h] [rbp-428h] BYREF

puts("SIGFPE received");
v1 = backtrace(v12, 50);
v2 = v1;
if ( v1 <= 0 )
{
printf("stacktrace: found %d frames:%s offset 0x%lx\n", (unsigned int)v1, v13, &_executable_start);
if ( backtrace_symbols(v12, v2) )
goto LABEL_6;
LABEL_8:
puts("stacktrace: found no symbols");
goto LABEL_6;
}
v3 = v12;
v4 = 0;
v5 = &v12[(unsigned int)(v1 - 1) + 1];
do
{
v6 = (__int64)*v3++;
v4 += snprintf(&v13[v4], 1000LL - v4, " 0x%lx", v6);
}
while ( v3 != v5 );
v7 = 0LL;
printf("stacktrace: found %d frames:%s offset 0x%lx\n", v2, v13, &_executable_start);
v8 = backtrace_symbols(v12, v2);
if ( !v8 )
goto LABEL_8;
do
{
v9 = v8[v7];
v10 = (unsigned int)v7++;
printf("stacktrace: frame %d: %s\n", v10, v9);
}
while ( v2 != v7 );
LABEL_6:
fflush(stdout);
return func2(sig);
}

original_code:
static void
act_sig_handle_fpe(int sig_num, siginfo_t* info, void* ctx)
{
 printf("SIGFPE received\n");
 do { void* bt[50]; int sz = backtrace(bt, 50); char trace[50 * 20]; int off = 0; for (int i = 0; i < sz; i++) { off += snprintf(trace + off, sizeof(trace) - off, " 0x%lx", (uint64_t)bt[i]); } printf("stacktrace: found %d frames:%s offset 0x%lx\n", sz, trace, (uint64_t)&__executable_start); char** syms = backtrace_symbols(bt, sz); if (syms != ((void *)0)) { for (int i = 0; i < sz; ++i) { printf("stacktrace: frame %d: %s\n", i, syms[i]); } } else { printf("stacktrace: found no symbols\n"); } fflush(stdout); } while (0);;
 reraise_signal(sig_num);
}

canonical_original_code:
static void act_sig_handle_fpe(int sig_num, struct siginfo_t *info, void *ctx)
{
 printf("SIGFPE received\n");
 do { void *bt[50]; int sz = backtrace(bt, 50); char trace[-1]; int off = 0; for (int i = 0; i < sz; i++) { off += snprintf(trace + off, sizeof(trace) - off, " 0x%lx", (unsigned long)bt[i]); } printf("stacktrace: found %d frames:%s offset 0x%lx\n", sz, trace, (unsigned long)&__executable_start); char **syms = backtrace_symbols(bt, sz); if (syms != ((void *)0)) { for (int i = 0; i < sz; ++i) { printf("stacktrace: frame %d: %s\n", i, syms[i]); } } else { printf("stacktrace: found no symbols\n"); } fflush(stdout); } while (0);;
 reraise_signal(sig_num);
}


decompiled_code:
int __fastcall act_sig_handle_bus(int sig)
{
int v1; // eax
unsigned int v2; // ebp
void **v3; // r14
int v4; // er15
void **v5; // r13
__int64 v6; // rcx
__int64 v7; // rbx
char **v8; // r13
const char *v9; // rdx
__int64 v10; // rsi
void *v12[50]; // [rsp+0h] [rbp-5B8h] BYREF
char v13[1064]; // [rsp+190h] [rbp-428h] BYREF

puts("SIGBUS received");
v1 = backtrace(v12, 50);
v2 = v1;
if ( v1 <= 0 )
{
printf("stacktrace: found %d frames:%s offset 0x%lx\n", (unsigned int)v1, v13, &_executable_start);
if ( backtrace_symbols(v12, v2) )
goto LABEL_6;
LABEL_8:
puts("stacktrace: found no symbols");
goto LABEL_6;
}
v3 = v12;
v4 = 0;
v5 = &v12[(unsigned int)(v1 - 1) + 1];
do
{
v6 = (__int64)*v3++;
v4 += snprintf(&v13[v4], 1000LL - v4, " 0x%lx", v6);
}
while ( v3 != v5 );
v7 = 0LL;
printf("stacktrace: found %d frames:%s offset 0x%lx\n", v2, v13, &_executable_start);
v8 = backtrace_symbols(v12, v2);
if ( !v8 )
goto LABEL_8;
do
{
v9 = v8[v7];
v10 = (unsigned int)v7++;
printf("stacktrace: frame %d: %s\n", v10, v9);
}
while ( v2 != v7 );
LABEL_6:
fflush(stdout);
return reraise_signal(sig);
}

canonical_decompiled_code:
int __fastcall func6(int sig)
{
int v1; // eax
unsigned int v2; // ebp
void **v3; // r14
int v4; // er15
void **v5; // r13
__int64 v6; // rcx
__int64 v7; // rbx
char **v8; // r13
const char *v9; // rdx
__int64 v10; // rsi
void *v12[50]; // [rsp+0h] [rbp-5B8h] BYREF
char v13[1064]; // [rsp+190h] [rbp-428h] BYREF

puts("SIGBUS received");
v1 = backtrace(v12, 50);
v2 = v1;
if ( v1 <= 0 )
{
printf("stacktrace: found %d frames:%s offset 0x%lx\n", (unsigned int)v1, v13, &_executable_start);
if ( backtrace_symbols(v12, v2) )
goto LABEL_6;
LABEL_8:
puts("stacktrace: found no symbols");
goto LABEL_6;
}
v3 = v12;
v4 = 0;
v5 = &v12[(unsigned int)(v1 - 1) + 1];
do
{
v6 = (__int64)*v3++;
v4 += snprintf(&v13[v4], 1000LL - v4, " 0x%lx", v6);
}
while ( v3 != v5 );
v7 = 0LL;
printf("stacktrace: found %d frames:%s offset 0x%lx\n", v2, v13, &_executable_start);
v8 = backtrace_symbols(v12, v2);
if ( !v8 )
goto LABEL_8;
do
{
v9 = v8[v7];
v10 = (unsigned int)v7++;
printf("stacktrace: frame %d: %s\n", v10, v9);
}
while ( v2 != v7 );
LABEL_6:
fflush(stdout);
return func2(sig);
}

original_code:
static void
act_sig_handle_bus(int sig_num, siginfo_t* info, void* ctx)
{
 printf("SIGBUS received\n");
 do { void* bt[50]; int sz = backtrace(bt, 50); char trace[50 * 20]; int off = 0; for (int i = 0; i < sz; i++) { off += snprintf(trace + off, sizeof(trace) - off, " 0x%lx", (uint64_t)bt[i]); } printf("stacktrace: found %d frames:%s offset 0x%lx\n", sz, trace, (uint64_t)&__executable_start); char** syms = backtrace_symbols(bt, sz); if (syms != ((void *)0)) { for (int i = 0; i < sz; ++i) { printf("stacktrace: frame %d: %s\n", i, syms[i]); } } else { printf("stacktrace: found no symbols\n"); } fflush(stdout); } while (0);;
 reraise_signal(sig_num);
}

canonical_original_code:
static void act_sig_handle_bus(int sig_num, struct siginfo_t *info, void *ctx)
{
 printf("SIGBUS received\n");
 do { void *bt[50]; int sz = backtrace(bt, 50); char trace[-1]; int off = 0; for (int i = 0; i < sz; i++) { off += snprintf(trace + off, sizeof(trace) - off, " 0x%lx", (unsigned long)bt[i]); } printf("stacktrace: found %d frames:%s offset 0x%lx\n", sz, trace, (unsigned long)&__executable_start); char **syms = backtrace_symbols(bt, sz); if (syms != ((void *)0)) { for (int i = 0; i < sz; ++i) { printf("stacktrace: frame %d: %s\n", i, syms[i]); } } else { printf("stacktrace: found no symbols\n"); } fflush(stdout); } while (0);;
 reraise_signal(sig_num);
}


decompiled_code:
int __fastcall act_sig_handle_abort(int sig)
{
int v1; // eax
unsigned int v2; // ebp
void **v3; // r14
int v4; // er15
void **v5; // r13
__int64 v6; // rcx
__int64 v7; // rbx
char **v8; // r13
const char *v9; // rdx
__int64 v10; // rsi
void *v12[50]; // [rsp+0h] [rbp-5B8h] BYREF
char v13[1064]; // [rsp+190h] [rbp-428h] BYREF

puts("SIGABRT received");
v1 = backtrace(v12, 50);
v2 = v1;
if ( v1 <= 0 )
{
printf("stacktrace: found %d frames:%s offset 0x%lx\n", (unsigned int)v1, v13, &_executable_start);
if ( backtrace_symbols(v12, v2) )
goto LABEL_6;
LABEL_8:
puts("stacktrace: found no symbols");
goto LABEL_6;
}
v3 = v12;
v4 = 0;
v5 = &v12[(unsigned int)(v1 - 1) + 1];
do
{
v6 = (__int64)*v3++;
v4 += snprintf(&v13[v4], 1000LL - v4, " 0x%lx", v6);
}
while ( v3 != v5 );
v7 = 0LL;
printf("stacktrace: found %d frames:%s offset 0x%lx\n", v2, v13, &_executable_start);
v8 = backtrace_symbols(v12, v2);
if ( !v8 )
goto LABEL_8;
do
{
v9 = v8[v7];
v10 = (unsigned int)v7++;
printf("stacktrace: frame %d: %s\n", v10, v9);
}
while ( v2 != v7 );
LABEL_6:
fflush(stdout);
return reraise_signal(sig);
}

canonical_decompiled_code:
int __fastcall func7(int sig)
{
int v1; // eax
unsigned int v2; // ebp
void **v3; // r14
int v4; // er15
void **v5; // r13
__int64 v6; // rcx
__int64 v7; // rbx
char **v8; // r13
const char *v9; // rdx
__int64 v10; // rsi
void *v12[50]; // [rsp+0h] [rbp-5B8h] BYREF
char v13[1064]; // [rsp+190h] [rbp-428h] BYREF

puts("SIGABRT received");
v1 = backtrace(v12, 50);
v2 = v1;
if ( v1 <= 0 )
{
printf("stacktrace: found %d frames:%s offset 0x%lx\n", (unsigned int)v1, v13, &_executable_start);
if ( backtrace_symbols(v12, v2) )
goto LABEL_6;
LABEL_8:
puts("stacktrace: found no symbols");
goto LABEL_6;
}
v3 = v12;
v4 = 0;
v5 = &v12[(unsigned int)(v1 - 1) + 1];
do
{
v6 = (__int64)*v3++;
v4 += snprintf(&v13[v4], 1000LL - v4, " 0x%lx", v6);
}
while ( v3 != v5 );
v7 = 0LL;
printf("stacktrace: found %d frames:%s offset 0x%lx\n", v2, v13, &_executable_start);
v8 = backtrace_symbols(v12, v2);
if ( !v8 )
goto LABEL_8;
do
{
v9 = v8[v7];
v10 = (unsigned int)v7++;
printf("stacktrace: frame %d: %s\n", v10, v9);
}
while ( v2 != v7 );
LABEL_6:
fflush(stdout);
return func2(sig);
}

original_code:
static void
act_sig_handle_abort(int sig_num, siginfo_t* info, void* ctx)
{
 printf("SIGABRT received\n");
 do { void* bt[50]; int sz = backtrace(bt, 50); char trace[50 * 20]; int off = 0; for (int i = 0; i < sz; i++) { off += snprintf(trace + off, sizeof(trace) - off, " 0x%lx", (uint64_t)bt[i]); } printf("stacktrace: found %d frames:%s offset 0x%lx\n", sz, trace, (uint64_t)&__executable_start); char** syms = backtrace_symbols(bt, sz); if (syms != ((void *)0)) { for (int i = 0; i < sz; ++i) { printf("stacktrace: frame %d: %s\n", i, syms[i]); } } else { printf("stacktrace: found no symbols\n"); } fflush(stdout); } while (0);;
 reraise_signal(sig_num);
}

canonical_original_code:
static void act_sig_handle_abort(int sig_num, struct siginfo_t *info, void *ctx)
{
 printf("SIGABRT received\n");
 do { void *bt[50]; int sz = backtrace(bt, 50); char trace[-1]; int off = 0; for (int i = 0; i < sz; i++) { off += snprintf(trace + off, sizeof(trace) - off, " 0x%lx", (unsigned long)bt[i]); } printf("stacktrace: found %d frames:%s offset 0x%lx\n", sz, trace, (unsigned long)&__executable_start); char **syms = backtrace_symbols(bt, sz); if (syms != ((void *)0)) { for (int i = 0; i < sz; ++i) { printf("stacktrace: frame %d: %s\n", i, syms[i]); } } else { printf("stacktrace: found no symbols\n"); } fflush(stdout); } while (0);;
 reraise_signal(sig_num);
}


decompiled_code:
int signal_setup()
{
set_action(6, (void (*)(int))act_sig_handle_abort);
set_action(7, (void (*)(int))act_sig_handle_bus);
set_action(8, (void (*)(int))act_sig_handle_fpe);
set_action(4, (void (*)(int))act_sig_handle_ill);
return set_action(11, (void (*)(int))act_sig_handle_segv);
}

canonical_decompiled_code:
int func8()
{
func0(6, (void (*)(int))act_sig_handle_abort);
func0(7, (void (*)(int))act_sig_handle_bus);
func0(8, (void (*)(int))act_sig_handle_fpe);
func0(4, (void (*)(int))act_sig_handle_ill);
return func0(11, (void (*)(int))act_sig_handle_segv);
}

original_code:
void
signal_setup()
{
 set_action(6, act_sig_handle_abort);
 set_action(7, act_sig_handle_bus);
 set_action(8, act_sig_handle_fpe);
 set_action(4, act_sig_handle_ill);
 set_action(11, act_sig_handle_segv);
}


decompiled_code:
__int64 __fastcall pread_all(int fd, void *buf, size_t nbytes, __off64_t offset)
{
ssize_t v7; // rax

while ( 1 )
{
v7 = pread64(fd, buf, nbytes, offset);
if ( nbytes == v7 )
return 1LL;
if ( v7 < 0 )
return 0LL;
if ( !v7 )
break;
buf = (char *)buf + v7;
offset += v7;
nbytes -= v7;
}
puts("ERROR: pread() returned 0");
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(int fd, void *buf, size_t nbytes, __off64_t offset)
{
ssize_t v7; // rax

while ( 1 )
{
v7 = pread64(fd, buf, nbytes, offset);
if ( nbytes == v7 )
return 1LL;
if ( v7 < 0 )
return 0LL;
if ( !v7 )
break;
buf = (char *)buf + v7;
offset += v7;
nbytes -= v7;
}
puts("ERROR: pread() returned 0");
return 0LL;
}

original_code:
_Bool
pread_all(int fd, void* buf, size_t size, off_t offset)
{
 ssize_t result;
 while ((result = pread(fd, buf, size, offset)) != (ssize_t)size) {
  if (result < 0) {
   return 0;
  }
  if (result == 0) {
   printf("ERROR: pread() returned 0\n");
   return 0;
  }
  buf += result;
  offset += result;
  size -= result;
 }
 return 1;
}

canonical_original_code:
_Bool pread_all(int fd, void *buf, unsigned long size, long offset)
{
 long result;
 while ((result = pread(fd, buf, size, offset)) != (long)size) {
  if (result < 0) {
   return 0;
  }
  if (result == 0) {
   printf("ERROR: pread() returned 0\n");
   return 0;
  }
  buf += result;
  offset += result;
  size -= result;
 }
 return 1;
}

variable_types: fd int

variable_types:
buf
void *

variable_types:
size
unsigned long

variable_types: offset long

variable_types: result long


decompiled_code:
__int64 __fastcall pwrite_all(int fd, void *buf, size_t n, __off64_t offset)
{
ssize_t v7; // rax

while ( 1 )
{
v7 = pwrite64(fd, buf, n, offset);
if ( n == v7 )
return 1LL;
if ( v7 < 0 )
return 0LL;
if ( !v7 )
break;
buf = (char *)buf + v7;
offset += v7;
n -= v7;
}
puts("ERROR: pwrite() returned 0");
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(int fd, void *buf, size_t n, __off64_t offset)
{
ssize_t v7; // rax

while ( 1 )
{
v7 = pwrite64(fd, buf, n, offset);
if ( n == v7 )
return 1LL;
if ( v7 < 0 )
return 0LL;
if ( !v7 )
break;
buf = (char *)buf + v7;
offset += v7;
n -= v7;
}
puts("ERROR: pwrite() returned 0");
return 0LL;
}

original_code:
_Bool
pwrite_all(int fd, const void* buf, size_t size, off_t offset)
{
 ssize_t result;
 while ((result = pwrite(fd, buf, size, offset)) != (ssize_t)size) {
  if (result < 0) {
   return 0;
  }
  if (result == 0) {
   printf("ERROR: pwrite() returned 0\n");
   return 0;
  }
  buf += result;
  offset += result;
  size -= result;
 }
 return 1;
}

canonical_original_code:
_Bool pwrite_all(int fd, void *buf, unsigned long size, long offset)
{
 long result;
 while ((result = pwrite(fd, buf, size, offset)) != (long)size) {
  if (result < 0) {
   return 0;
  }
  if (result == 0) {
   printf("ERROR: pwrite() returned 0\n");
   return 0;
  }
  buf += result;
  offset += result;
  size -= result;
 }
 return 1;
}


decompiled_code:
__int64 __fastcall write_all(int fd, void *buf, size_t n)
{
ssize_t v5; // rax

while ( 1 )
{
v5 = write(fd, buf, n);
if ( n == v5 )
return 1LL;
if ( v5 < 0 )
return 0LL;
if ( !v5 )
break;
buf = (char *)buf + v5;
n -= v5;
}
puts("ERROR: write() returned 0");
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(int fd, void *buf, size_t n)
{
ssize_t v5; // rax

while ( 1 )
{
v5 = write(fd, buf, n);
if ( n == v5 )
return 1LL;
if ( v5 < 0 )
return 0LL;
if ( !v5 )
break;
buf = (char *)buf + v5;
n -= v5;
}
puts("ERROR: write() returned 0");
return 0LL;
}

original_code:
_Bool
write_all(int fd, const void* buf, size_t size)
{
 ssize_t result;
 while ((result = write(fd, buf, size)) != (ssize_t)size) {
  if (result < 0) {
   return 0;
  }
  if (result == 0) {
   printf("ERROR: write() returned 0\n");
   return 0;
  }
  buf += result;
  size -= result;
 }
 return 1;
}

canonical_original_code:
_Bool write_all(int fd, void *buf, unsigned long size)
{
 long result;
 while ((result = write(fd, buf, size)) != (long)size) {
  if (result < 0) {
   return 0;
  }
  if (result == 0) {
   printf("ERROR: write() returned 0\n");
   return 0;
  }
  buf += result;
  size -= result;
 }
 return 1;
}


decompiled_code:
__int64 __fastcall q_resize(unsigned int *a1, unsigned int a2)
{
unsigned int v3; // ebp
size_t v4; // rsi
void *v5; // rax
unsigned int v6; // eax
unsigned int v7; // er13
char *v8; // rax
char *v9; // r14
char *v10; // r15
unsigned int v11; // eax
__int64 result; // rax
__int64 v13; // [rsp+0h] [rbp-48h]

v3 = *a1;
v4 = *((_QWORD *)a1 + 2) * a2;
if ( a1[1] % *a1 )
{
v13 = *((_QWORD *)a1 + 2);
v7 = a1[1] % *a1;
v8 = (char *)malloc(v4);
v9 = v8;
if ( v8 )
{
v10 = (char *)*((_QWORD *)a1 + 8);
memcpy(v8, &v10[v13 * v7], (unsigned int)v13 * (v3 - v7));
memcpy(&v9[(unsigned int)v13 * (v3 - v7)], v10, v13 * v3 - (unsigned int)v13 * (v3 - v7));
free(v10);
v11 = *a1;
*((_QWORD *)a1 + 8) = v9;
a1[1] = 0;
a1[2] = v11;
goto LABEL_6;
}
puts("ERROR: resizing queue (malloc)");
result = 0LL;
}
else
{
v5 = realloc(*((void **)a1 + 8), v4);
*((_QWORD *)a1 + 8) = v5;
if ( v5 )
{
v6 = *a1;
a1[1] = 0;
a1[2] = v6;
LABEL_6:
*a1 = a2;
return 1LL;
}
puts("ERROR: resizing queue (realloc)");
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned int *a1, unsigned int a2)
{
unsigned int v3; // ebp
size_t v4; // rsi
void *v5; // rax
unsigned int v6; // eax
unsigned int v7; // er13
char *v8; // rax
char *v9; // r14
char *v10; // r15
unsigned int v11; // eax
__int64 result; // rax
__int64 v13; // [rsp+0h] [rbp-48h]

v3 = *a1;
v4 = *((_QWORD *)a1 + 2) * a2;
if ( a1[1] % *a1 )
{
v13 = *((_QWORD *)a1 + 2);
v7 = a1[1] % *a1;
v8 = (char *)malloc(v4);
v9 = v8;
if ( v8 )
{
v10 = (char *)*((_QWORD *)a1 + 8);
memcpy(v8, &v10[v13 * v7], (unsigned int)v13 * (v3 - v7));
memcpy(&v9[(unsigned int)v13 * (v3 - v7)], v10, v13 * v3 - (unsigned int)v13 * (v3 - v7));
free(v10);
v11 = *a1;
*((_QWORD *)a1 + 8) = v9;
a1[1] = 0;
a1[2] = v11;
goto LABEL_6;
}
puts("ERROR: resizing queue (malloc)");
result = 0LL;
}
else
{
v5 = realloc(*((void **)a1 + 8), v4);
*((_QWORD *)a1 + 8) = v5;
if ( v5 )
{
v6 = *a1;
a1[1] = 0;
a1[2] = v6;
LABEL_6:
*a1 = a2;
return 1LL;
}
puts("ERROR: resizing queue (realloc)");
result = 0LL;
}
return result;
}

original_code:
static _Bool
q_resize(queue* q, uint32_t new_sz)
{
 if (q->read_offset % q->alloc_sz == 0) {
  q->elements = realloc(q->elements, new_sz * q->ele_size);
  if (q->elements == ((void *)0)) {
   printf("ERROR: resizing queue (realloc)\n");
   return 0;
  }
  q->read_offset = 0;
  q->write_offset = q->alloc_sz;
 }
 else {
  uint8_t* new_q = malloc(new_sz * q->ele_size);
  if (new_q == ((void *)0)) {
   printf("ERROR: resizing queue (malloc)\n");
   return 0;
  }
  uint32_t end_size =
    (q->alloc_sz - (q->read_offset % q->alloc_sz)) * q->ele_size;
  memcpy(&new_q[0], (&q->elements[(q->read_offset % q->alloc_sz) * q->ele_size]), end_size);
  memcpy(&new_q[end_size], &q->elements[0],
    (q->alloc_sz * q->ele_size) - end_size);
  free(q->elements);
  q->elements = new_q;
  q->write_offset = q->alloc_sz;
  q->read_offset = 0;
 }
 q->alloc_sz = new_sz;
 return 1;
}

canonical_original_code:
static _Bool q_resize(struct queue_s *q, unsigned int new_sz)
{
 if (q->read_offset % q->alloc_sz == 0) {
  q->elements = realloc(q->elements, new_sz * q->ele_size);
  if (q->elements == ((void *)0)) {
   printf("ERROR: resizing queue (realloc)\n");
   return 0;
  }
  q->read_offset = 0;
  q->write_offset = q->alloc_sz;
 }
 else {
  unsigned char *new_q = malloc(new_sz * q->ele_size);
  if (new_q == ((void *)0)) {
   printf("ERROR: resizing queue (malloc)\n");
   return 0;
  }
  unsigned int end_size = (q->alloc_sz - (q->read_offset % q->alloc_sz)) * q->ele_size;
  memcpy(&new_q[0], (&q->elements[(q->read_offset % q->alloc_sz) * q->ele_size]), end_size);
  memcpy(&new_q[end_size], &q->elements[0],
    (q->alloc_sz * q->ele_size) - end_size);
  free(q->elements);
  q->elements = new_q;
  q->write_offset = q->alloc_sz;
  q->read_offset = 0;
 }
 q->alloc_sz = new_sz;
 return 1;
}

variable_types: struct queue_s { unsigned int alloc_sz; unsigned int read_offset; unsigned int write_offset; unsigned long ele_size; union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } lock; unsigned char *elements; } *

user_defined_types: struct queue_s { unsigned int alloc_sz; unsigned int read_offset; unsigned int write_offset; unsigned long ele_size; union pthread_mutex_t lock; unsigned char *elements; }

user_defined_types: union pthread_mutex_t { struct __pthread_mutex_s __data; char __size[40]; long __align; }

user_defined_types: struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list __list; }


decompiled_code:
char *__fastcall queue_create(__int64 a1)
{
char *v1; // r12
void *v2; // rax
void *v4; // rdi
void *v5; // rdi

v1 = (char *)malloc(0x48uLL);
if ( v1 )
{
v2 = malloc(a1 << 16);
*((_QWORD *)v1 + 8) = v2;
if ( v2 )
{
*(_QWORD *)v1 = 0x10000LL;
*((_DWORD *)v1 + 2) = 0;
*((_QWORD *)v1 + 2) = a1;
if ( pthread_mutex_init((pthread_mutex_t *)(v1 + 24), 0LL) )
{
puts("ERROR: creating queue (mutex init)");
free(*((void **)v1 + 8));
v4 = v1;
v1 = 0LL;
free(v4);
}
}
else
{
puts("ERROR: creating queue (malloc)");
v5 = v1;
v1 = 0LL;
free(v5);
}
}
else
{
puts("ERROR: creating queue (malloc)");
}
return v1;
}

canonical_decompiled_code:
char *__fastcall func2(__int64 a1)
{
char *v1; // r12
void *v2; // rax
void *v4; // rdi
void *v5; // rdi

v1 = (char *)malloc(0x48uLL);
if ( v1 )
{
v2 = malloc(a1 << 16);
*((_QWORD *)v1 + 8) = v2;
if ( v2 )
{
*(_QWORD *)v1 = 0x10000LL;
*((_DWORD *)v1 + 2) = 0;
*((_QWORD *)v1 + 2) = a1;
if ( pthread_mutex_init((pthread_mutex_t *)(v1 + 24), 0LL) )
{
puts("ERROR: creating queue (mutex init)");
free(*((void **)v1 + 8));
v4 = v1;
v1 = 0LL;
free(v4);
}
}
else
{
puts("ERROR: creating queue (malloc)");
v5 = v1;
v1 = 0LL;
free(v5);
}
}
else
{
puts("ERROR: creating queue (malloc)");
}
return v1;
}

original_code:
queue*
queue_create(size_t ele_size)
{
 queue* q = malloc( sizeof(queue));
 if (q == ((void *)0)) {
  printf("ERROR: creating queue (malloc)\n");
  return ((void *)0);
 }
 q->elements = malloc((64 * 1024) * ele_size);
 if (q->elements == ((void *)0)) {
  printf("ERROR: creating queue (malloc)\n");
  free(q);
  return ((void *)0);
 }
 q->alloc_sz = (64 * 1024);
 q->write_offset = q->read_offset = 0;
 q->ele_size = ele_size;
 if (pthread_mutex_init(&q->lock, ((void *)0)) != 0) {
  printf("ERROR: creating queue (mutex init)\n");
  free(q->elements);
  free(q);
  return ((void *)0);
 }
 return q;
}

canonical_original_code:
struct queue_s *queue_create(unsigned long ele_size)
{
 struct queue_s *q = malloc( sizeof(queue));
 if (q == ((void *)0)) {
  printf("ERROR: creating queue (malloc)\n");
  return ((void *)0);
 }
 q->elements = malloc((64 * 1024) * ele_size);
 if (q->elements == ((void *)0)) {
  printf("ERROR: creating queue (malloc)\n");
  free(q);
  return ((void *)0);
 }
 q->alloc_sz = (64 * 1024);
 q->write_offset = q->read_offset = 0;
 q->ele_size = ele_size;
 if (pthread_mutex_init(&q->lock, ((void *)0)) != 0) {
  printf("ERROR: creating queue (mutex init)\n");
  free(q->elements);
  free(q);
  return ((void *)0);
 }
 return q;
}

return_type: struct queue_s { unsigned int alloc_sz; unsigned int read_offset; unsigned int write_offset; unsigned long ele_size; union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } lock; unsigned char *elements; } *


decompiled_code:
void __fastcall queue_destroy(void *ptr)
{
pthread_mutex_destroy((pthread_mutex_t *)((char *)ptr + 24));
free(*((void **)ptr + 8));
free(ptr);
}

canonical_decompiled_code:
void __fastcall func3(void *ptr)
{
pthread_mutex_destroy((pthread_mutex_t *)((char *)ptr + 24));
free(*((void **)ptr + 8));
free(ptr);
}

original_code:
void
queue_destroy(queue* q)
{
 pthread_mutex_destroy(&q->lock);
 free(q->elements);
 free(q);
}

canonical_original_code:
void queue_destroy(struct queue_s *q)
{
 pthread_mutex_destroy(&q->lock);
 free(q->elements);
 free(q);
}

user_defined_types: struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; }


decompiled_code:
__int64 __fastcall queue_sz(__int64 a1)
{
unsigned int v1; // er12

pthread_mutex_lock((pthread_mutex_t *)(a1 + 24));
v1 = *(_DWORD *)(a1 + 8) - *(_DWORD *)(a1 + 4);
pthread_mutex_unlock((pthread_mutex_t *)(a1 + 24));
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1)
{
unsigned int v1; // er12

pthread_mutex_lock((pthread_mutex_t *)(a1 + 24));
v1 = *(_DWORD *)(a1 + 8) - *(_DWORD *)(a1 + 4);
pthread_mutex_unlock((pthread_mutex_t *)(a1 + 24));
return v1;
}

original_code:
uint32_t
queue_sz(queue* q)
{
 pthread_mutex_lock(&q->lock);
 uint32_t rv = (q->write_offset - q->read_offset);
 pthread_mutex_unlock(&q->lock);
 return rv;
}

canonical_original_code:
unsigned int queue_sz(struct queue_s *q)
{
 pthread_mutex_lock(&q->lock);
 unsigned int rv = (q->write_offset - q->read_offset);
 pthread_mutex_unlock(&q->lock);
 return rv;
}

variable_types:
rv
unsigned int


decompiled_code:
__int64 __fastcall queue_push(__int64 a1, const void *a2)
{
pthread_mutex_t *v2; // r13
unsigned int v4; // eax
unsigned int v5; // esi
int v6; // eax
unsigned int v7; // er14

v2 = (pthread_mutex_t *)(a1 + 24);
pthread_mutex_lock((pthread_mutex_t *)(a1 + 24));
v4 = *(_DWORD *)(a1 + 8);
v5 = *(_DWORD *)a1;
if ( v4 - *(_DWORD *)(a1 + 4) == *(_DWORD *)a1 )
{
v7 = q_resize((unsigned int *)a1, 2 * v5);
if ( !(_BYTE)v7 )
{
pthread_mutex_unlock(v2);
return v7;
}
v4 = *(_DWORD *)(a1 + 8);
v5 = *(_DWORD *)a1;
}
memcpy((void *)(*(_QWORD *)(a1 + 16) * (v4 % v5) + *(_QWORD *)(a1 + 64)), a2, *(_QWORD *)(a1 + 16));
v6 = *(_DWORD *)(a1 + 8) + 1;
*(_DWORD *)(a1 + 8) = v6;
if ( (v6 & 0xC0000000) != 0 )
q_unwrap((_DWORD *)a1);
v7 = 1;
pthread_mutex_unlock(v2);
return v7;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, const void *a2)
{
pthread_mutex_t *v2; // r13
unsigned int v4; // eax
unsigned int v5; // esi
int v6; // eax
unsigned int v7; // er14

v2 = (pthread_mutex_t *)(a1 + 24);
pthread_mutex_lock((pthread_mutex_t *)(a1 + 24));
v4 = *(_DWORD *)(a1 + 8);
v5 = *(_DWORD *)a1;
if ( v4 - *(_DWORD *)(a1 + 4) == *(_DWORD *)a1 )
{
v7 = func1((unsigned int *)a1, 2 * v5);
if ( !(_BYTE)v7 )
{
pthread_mutex_unlock(v2);
return v7;
}
v4 = *(_DWORD *)(a1 + 8);
v5 = *(_DWORD *)a1;
}
memcpy((void *)(*(_QWORD *)(a1 + 16) * (v4 % v5) + *(_QWORD *)(a1 + 64)), a2, *(_QWORD *)(a1 + 16));
v6 = *(_DWORD *)(a1 + 8) + 1;
*(_DWORD *)(a1 + 8) = v6;
if ( (v6 & 0xC0000000) != 0 )
func0((_DWORD *)a1);
v7 = 1;
pthread_mutex_unlock(v2);
return v7;
}

original_code:
_Bool
queue_push(queue* q, const void* ele_ptr)
{
 pthread_mutex_lock(&q->lock);
 if ((q->write_offset - q->read_offset) == q->alloc_sz) {
  if (! q_resize(q, q->alloc_sz * 2)) {
   pthread_mutex_unlock(&q->lock);
   return 0;
  }
 }
 memcpy((&q->elements[(q->write_offset % q->alloc_sz) * q->ele_size]), ele_ptr, q->ele_size);
 q->write_offset++;
 if ((q->write_offset & 0xC0000000) != 0) {
  q_unwrap(q);
 }
 pthread_mutex_unlock(&q->lock);
 return 1;
}

canonical_original_code:
_Bool queue_push(struct queue_s *q, void *ele_ptr)
{
 pthread_mutex_lock(&q->lock);
 if ((q->write_offset - q->read_offset) == q->alloc_sz) {
  if (! q_resize(q, q->alloc_sz * 2)) {
   pthread_mutex_unlock(&q->lock);
   return 0;
  }
 }
 memcpy((&q->elements[(q->write_offset % q->alloc_sz) * q->ele_size]), ele_ptr, q->ele_size);
 q->write_offset++;
 if ((q->write_offset & 0xC0000000) != 0) {
  q_unwrap(q);
 }
 pthread_mutex_unlock(&q->lock);
 return 1;
}


decompiled_code:
__int64 __fastcall queue_pop(__int64 a1, void *a2)
{
pthread_mutex_t *v2; // r12
unsigned int v3; // eax
int v4; // eax
__int64 result; // rax

v2 = (pthread_mutex_t *)(a1 + 24);
pthread_mutex_lock((pthread_mutex_t *)(a1 + 24));
v3 = *(_DWORD *)(a1 + 4);
if ( *(_DWORD *)(a1 + 8) == v3 )
{
pthread_mutex_unlock(v2);
result = 0LL;
}
else
{
memcpy(a2, (const void *)(*(_QWORD *)(a1 + 64) + *(_QWORD *)(a1 + 16) * (v3 % *(_DWORD *)a1)), *(_QWORD *)(a1 + 16));
v4 = *(_DWORD *)(a1 + 4) + 1;
*(_DWORD *)(a1 + 4) = v4;
if ( v4 == *(_DWORD *)(a1 + 8) )
*(_QWORD *)(a1 + 4) = 0LL;
pthread_mutex_unlock(v2);
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, void *a2)
{
pthread_mutex_t *v2; // r12
unsigned int v3; // eax
int v4; // eax
__int64 result; // rax

v2 = (pthread_mutex_t *)(a1 + 24);
pthread_mutex_lock((pthread_mutex_t *)(a1 + 24));
v3 = *(_DWORD *)(a1 + 4);
if ( *(_DWORD *)(a1 + 8) == v3 )
{
pthread_mutex_unlock(v2);
result = 0LL;
}
else
{
memcpy(a2, (const void *)(*(_QWORD *)(a1 + 64) + *(_QWORD *)(a1 + 16) * (v3 % *(_DWORD *)a1)), *(_QWORD *)(a1 + 16));
v4 = *(_DWORD *)(a1 + 4) + 1;
*(_DWORD *)(a1 + 4) = v4;
if ( v4 == *(_DWORD *)(a1 + 8) )
*(_QWORD *)(a1 + 4) = 0LL;
pthread_mutex_unlock(v2);
result = 1LL;
}
return result;
}

original_code:
_Bool
queue_pop(queue* q, void* ele_ptr)
{
 pthread_mutex_lock(&q->lock);
 if ((q->write_offset == q->read_offset)) {
  pthread_mutex_unlock(&q->lock);
  return 0;
 }
 memcpy(ele_ptr, (&q->elements[(q->read_offset % q->alloc_sz) * q->ele_size]), q->ele_size);
 q->read_offset++;
 if (q->read_offset == q->write_offset) {
  q->read_offset = q->write_offset = 0;
 }
 pthread_mutex_unlock(&q->lock);
 return 1;
}

canonical_original_code:
_Bool queue_pop(struct queue_s *q, void *ele_ptr)
{
 pthread_mutex_lock(&q->lock);
 if ((q->write_offset == q->read_offset)) {
  pthread_mutex_unlock(&q->lock);
  return 0;
 }
 memcpy(ele_ptr, (&q->elements[(q->read_offset % q->alloc_sz) * q->ele_size]), q->ele_size);
 q->read_offset++;
 if (q->read_offset == q->write_offset) {
  q->read_offset = q->write_offset = 0;
 }
 pthread_mutex_unlock(&q->lock);
 return 1;
}


msb

decompiled_code:
__int64 __fastcall msb(unsigned __int64 a1)
{
int v1; // edx
unsigned __int64 i; // rax

v1 = 0;
for ( i = a1 >> 8; i; i >>= 8 )
{
v1 += 8;
a1 = i;
}
return (unsigned int)(v1 + BYTE_MSB[a1]);
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned __int64 a1)
{
int v1; // edx
unsigned __int64 i; // rax

v1 = 0;
for ( i = a1 >> 8; i; i >>= 8 )
{
v1 += 8;
a1 = i;
}
return (unsigned int)(v1 + BYTE_MSB[a1]);
}

original_code:
static int
msb(uint64_t n)
{
 int shift = 0;
 while (1) {
  uint64_t n_div_256 = n >> 8;
  if (n_div_256 == 0) {
   return shift + (int)BYTE_MSB[n];
  }
  n = n_div_256;
  shift += 8;
 }
 printf("ERROR: msb calculation\n");
 return -1;
}

canonical_original_code:
static int msb(unsigned long n)
{
 int shift = 0;
 while (1) {
  unsigned long n_div_256 = n >> 8;
  if (n_div_256 == 0) {
   return shift + (int)BYTE_MSB[n];
  }
  n = n_div_256;
  shift += 8;
 }
 printf("ERROR: msb calculation\n");
 return -1;
}

variable_types:
n
unsigned long

variable_types: shift int


decompiled_code:
int __fastcall histogram_dump(__int64 a1, const char *a2)
{
__int64 *v2; // rcx
__int64 v3; // rax
__int64 v4; // r8
unsigned int v5; // ebp
__int64 v6; // rbx
__int64 v7; // rdx
int result; // eax
char v9; // r13
int v10; // er12
__int64 v11; // rcx
char v12[776]; // [rsp+0h] [rbp-308h] BYREF

v2 = (__int64 *)(a1 + 8);
v3 = 0LL;
v4 = 0LL;
v5 = 0;
LODWORD(v6) = 65;
do
{
v7 = *v2;
*(_QWORD *)&v12[8 * v3 + 208] = *v2;
if ( v7 )
{
v5 = v3;
if ( (unsigned int)v6 > (unsigned int)v3 )
LODWORD(v6) = v3;
v4 += v7;
}
++v3;
++v2;
}
while ( v3 != 65 );
v12[0] = 0;
result = printf("%s (%lu total)\n", a2, v4);
if ( (unsigned int)v6 <= v5 )
{
v6 = (unsigned int)v6;
v9 = 0;
v10 = 0;
do
{
v11 = *(_QWORD *)&v12[8 * v6 + 208];
if ( v11 )
{
v10 += sprintf(&v12[v10], " (%02u: %010lu)", (unsigned int)v6, v11);
result = v9 & 3;
if ( result == 3 )
{
v10 = 0;
result = puts(v12);
v12[0] = 0;
}
++v9;
}
++v6;
}
while ( v5 >= (unsigned int)v6 );
if ( v10 )
result = puts(v12);
}
return result;
}

original_code:
void
histogram_dump(histogram* h, const char* tag)
{
 uint64_t counts[(1 + 64)];
 uint32_t i = (1 + 64);
 uint32_t j = 0;
 uint64_t total = 0;
 for (uint32_t b = 0; b < (1 + 64); b++) {
  counts[b] = __atomic_load_n(&h->counts[b], 0);
  if (counts[b] != 0) {
   if (i > b) {
    i = b;
   }
   j = b;
   total += counts[b];
  }
 }
 char buf[200];
 int pos = 0;
 uint32_t k = 0;
 buf[0] = '\0';
 printf("%s (%" "l" "u" " total)\n", tag, total);
 for ( ; i <= j; i++) {
  if (counts[i] == 0) {
   continue;
  }
  pos += sprintf(buf + pos, " (%02u: %010" "l" "u" ")", i, counts[i]);
  if ((k & 3) == 3) {
   printf("%s\n", buf);
   pos = 0;
   buf[0] = '\0';
  }
  k++;
 }
 if (pos > 0) {
  printf("%s\n", buf);
 }
}

canonical_original_code:
void histogram_dump(struct histogram_s *h, char *tag)
{
 unsigned long counts[-1];
 unsigned int i = (1 + 64);
 unsigned int j = 0;
 unsigned long total = 0;
 for (unsigned int b = 0; b < (1 + 64); b++) {
  counts[b] = __atomic_load_n(&h->counts[b], 0);
  if (counts[b] != 0) {
   if (i > b) {
    i = b;
   }
   j = b;
   total += counts[b];
  }
 }
 char buf[200];
 int pos = 0;
 unsigned int k = 0;
 buf[0] = '\0';
 printf("%s (%" "l" "u" " total)\n", tag, total);
 for ( ; i <= j; i++) {
  if (counts[i] == 0) {
   continue;
  }
  pos += sprintf(buf + pos, " (%02u: %010" "l" "u" ")", i, counts[i]);
  if ((k & 3) == 3) {
   printf("%s\n", buf);
   pos = 0;
   buf[0] = '\0';
  }
  k++;
 }
 if (pos > 0) {
  printf("%s\n", buf);
 }
}

variable_types: struct histogram_s { unsigned int time_div; unsigned long counts[-1]; } *

variable_types:
tag
char *

variable_types:
counts
unsigned long [-1]

variable_types:
i
unsigned int

variable_types:
j
unsigned int

variable_types:
total
unsigned long

variable_types:
b
unsigned int

variable_types:
buf
char [200]

variable_types: pos int

variable_types:
k
unsigned int


decompiled_code:
unsigned __int64 __fastcall histogram_insert_data_point(unsigned int *a1, unsigned __int64 a2)
{
unsigned __int64 result; // rax
unsigned __int64 v3; // rsi
__int64 v5; // rdx

result = a2;
v3 = *a1;
v5 = 8LL;
if ( v3 <= result )
{
result = (int)msb(result / v3);
v5 = 8LL * (int)result + 8;
}
_InterlockedAdd64((volatile signed __int64 *)((char *)a1 + v5), 1uLL);
return result;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func2(unsigned int *a1, unsigned __int64 a2)
{
unsigned __int64 result; // rax
unsigned __int64 v3; // rsi
__int64 v5; // rdx

result = a2;
v3 = *a1;
v5 = 8LL;
if ( v3 <= result )
{
result = (int)func0(result / v3);
v5 = 8LL * (int)result + 8;
}
_InterlockedAdd64((volatile signed __int64 *)((char *)a1 + v5), 1uLL);
return result;
}

original_code:
void
histogram_insert_data_point(histogram* h, uint64_t delta_ns)
{
 uint64_t delta_t = delta_ns / h->time_div;
 int bucket = 0;
 if (delta_t != 0) {
  bucket = msb(delta_t);
 }
 __atomic_fetch_add(&h->counts[bucket], 1, 0);
}

canonical_original_code:
void histogram_insert_data_point(struct histogram_s *h, unsigned long delta_ns)
{
 unsigned long delta_t = delta_ns / h->time_div;
 int bucket = 0;
 if (delta_t != 0) {
  bucket = msb(delta_t);
 }
 __atomic_fetch_add(&h->counts[bucket], 1, 0);
}

variable_types: bucket int

user_defined_types: struct histogram_s { unsigned int time_div; unsigned long counts[-1]; }


decompiled_code:
bool __fastcall is_power_of_2(int a1)
{
return (a1 & (a1 - 1)) == 0;
}

canonical_decompiled_code:
bool __fastcall func0(int a1)
{
return (a1 & (a1 - 1)) == 0;
}

original_code:
static inline _Bool
is_power_of_2(uint32_t value)
{
 return (value & (value - 1)) == 0;
}

canonical_original_code:
static inline _Bool is_power_of_2(unsigned int value)
{
 return (value & (value - 1)) == 0;
}

variable_types:
value
unsigned int


decompiled_code:
__int64 __fastcall round_up_to_rblock(int a1)
{
return (a1 + 15) & 0xFFFFFFF0;
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1)
{
return (a1 + 15) & 0xFFFFFFF0;
}

original_code:
static inline uint32_t
round_up_to_rblock(uint32_t size)
{
 return (size + (16 - 1)) & -16;
}

canonical_original_code:
static inline unsigned int round_up_to_rblock(unsigned int size)
{
 return (size + (16 - 1)) & -16;
}

variable_types:
size
unsigned int


decompiled_code:
int __fastcall configuration_error(const char *a1)
{
return printf("ERROR: invalid or missing configuration of '%s'\n", a1);
}

canonical_decompiled_code:
int __fastcall func2(const char *a1)
{
return printf("ERROR: invalid or missing configuration of '%s'\n", a1);
}

original_code:
static inline void
configuration_error(const char* tag)
{
 printf("ERROR: invalid or missing configuration of '%s'\n", tag);
}

canonical_original_code:
static inline void configuration_error(char *tag)
{
 printf("ERROR: invalid or missing configuration of '%s'\n", tag);
}


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

v0 = tl_seed0;
tl_seed0 = tl_seed1;
tl_seed1 ^= ((v0 ^ (unsigned __int64)(v0 << 23)) >> 17) ^ v0 ^ (v0 << 23) ^ ((unsigned __int64)tl_seed1 >> 26);
return tl_seed0 + tl_seed1;
}

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

v0 = tl_seed0;
tl_seed0 = tl_seed1;
tl_seed1 ^= ((v0 ^ (unsigned __int64)(v0 << 23)) >> 17) ^ v0 ^ (v0 << 23) ^ ((unsigned __int64)tl_seed1 >> 26);
return tl_seed0 + tl_seed1;
}

original_code:
static inline uint64_t
xorshift128plus()
{
 uint64_t s1 = tl_seed0;
 uint64_t s0 = tl_seed1;
 tl_seed0 = s0;
 s1 ^= s1 << 23;
 tl_seed1 = s1 ^ s0 ^ (s1 >> 17) ^ (s0 >> 26);
 return tl_seed1 + s0;
}

canonical_original_code:
static inline unsigned long xorshift128plus()
{
 unsigned long s1 = tl_seed0;
 unsigned long s0 = tl_seed1;
 tl_seed0 = s0;
 s1 ^= s1 << 23;
 tl_seed1 = s1 ^ s0 ^ (s1 >> 17) ^ (s0 >> 26);
 return tl_seed1 + s0;
}

return_type: unsigned long


decompiled_code:
void rand_seed()
{
unsigned int v0; // eax

v0 = time(0LL);
srand(v0);
}

canonical_decompiled_code:
void func1()
{
unsigned int v0; // eax

v0 = time(0LL);
srand(v0);
}

original_code:
void
rand_seed()
{
 srand(time(((void *)0)));
}


decompiled_code:
__int64 rand_seed_thread()
{
__int64 v0; // rbx
__int64 v1; // rbx
__int64 result; // rax

v0 = (unsigned int)rand();
__writefsqword((unsigned int)&tl_seed0, rand() | (unsigned __int64)(v0 << 32));
v1 = (unsigned int)rand();
result = rand();
__writefsqword((unsigned int)&tl_seed1, (int)result | (unsigned __int64)(v1 << 32));
return result;
}

canonical_decompiled_code:
__int64 func2()
{
__int64 v0; // rbx
__int64 v1; // rbx
__int64 result; // rax

v0 = (unsigned int)rand();
__writefsqword((unsigned int)&tl_seed0, rand() | (unsigned __int64)(v0 << 32));
v1 = (unsigned int)rand();
result = rand();
__writefsqword((unsigned int)&tl_seed1, (int)result | (unsigned __int64)(v1 << 32));
return result;
}

original_code:
void
rand_seed_thread()
{
 tl_seed0 = ((uint64_t)rand() << 32) | (uint64_t)rand();
 tl_seed1 = ((uint64_t)rand() << 32) | (uint64_t)rand();
}

canonical_original_code:
void rand_seed_thread()
{
 tl_seed0 = ((unsigned long)rand() << 32) | (unsigned long)rand();
 tl_seed1 = ((unsigned long)rand() << 32) | (unsigned long)rand();
}


decompiled_code:
__int64 rand_32()
{
return xorshift128plus();
}

canonical_decompiled_code:
__int64 func3()
{
return func0();
}

original_code:
uint32_t
rand_32()
{
 return (uint32_t)xorshift128plus();
}

canonical_original_code:
unsigned int rand_32()
{
 return (unsigned int)xorshift128plus();
}


decompiled_code:
__int64 rand_64()
{
return xorshift128plus();
}

canonical_decompiled_code:
__int64 func4()
{
return func0();
}

original_code:
uint64_t
rand_64()
{
 return xorshift128plus();
}

canonical_original_code:
unsigned long rand_64()
{
 return xorshift128plus();
}


canonical_decompiled_code:
int __fastcall func0(const char *a1)
{
return printf("ERROR: invalid or missing configuration of '%s'\n", a1);
}