decompiled_code:
void mu_free()
{
_QWORD *v0; // rbx
void *v1; // rdi

v0 = fails;
if ( fails )
{
do
{
v1 = v0;
v0 = (_QWORD *)*v0;
free(v1);
}
while ( v0 );
}
}

canonical_decompiled_code:
void func1()
{
_QWORD *v0; // rbx
void *v1; // rdi

v0 = fails;
if ( fails )
{
do
{
v1 = v0;
v0 = (_QWORD *)*v0;
free(v1);
}
while ( v0 );
}
}

original_code:
void mu_free() {
    struct failure *old, *current;
    old = current = fails;
    while (current) {
        old = current;
        current = current->next;
        free(old);
    }
}

canonical_original_code:
void mu_free() {
    struct failure *old; struct failure *current;
    old = current = fails;
    while (current) {
        old = current;
        current = current->next;
        free(old);
    }
}

user_defined_types: struct failure { struct failure *next; char *msg; }


repo: nacx/circus

decompiled_code:
__int64 run_all_tests()
{
test_version();
test_hashtable();
test_binding();
test_utils();
test_codes();
test_events();
test_network();
test_listener();
test_irc();
return test_dispatcher();
}

canonical_decompiled_code:
__int64 func0()
{
test_version();
test_hashtable();
test_binding();
test_utils();
test_codes();
test_events();
test_network();
test_listener();
test_irc();
return test_dispatcher();
}

original_code:
void run_all_tests() {
    do { (void)0; test_version(); } while (0);
    do { (void)0; test_hashtable(); } while (0);
    do { (void)0; test_binding(); } while (0);
    do { (void)0; test_utils(); } while (0);
    do { (void)0; test_codes(); } while (0);
    do { (void)0; test_events(); } while (0);
    do { (void)0; test_network(); } while (0);
    do { (void)0; test_listener(); } while (0);
    do { (void)0; test_irc(); } while (0);
    do { (void)0; test_dispatcher(); } while (0);
}

return_type: void


decompiled_code:
__int64 disable_stdout()
{
unsigned int v0; // er12
int v1; // ebp

fflush(stdout);
v0 = dup(1);
v1 = open("/dev/null", 1);
dup2(v1, 1);
close(v1);
return v0;
}

canonical_decompiled_code:
__int64 func1()
{
unsigned int v0; // er12
int v1; // ebp

fflush(stdout);
v0 = dup(1);
v1 = open("/dev/null", 1);
dup2(v1, 1);
close(v1);
return v0;
}

original_code:
int disable_stdout() {
    int original, quiet;
    fflush(stdout);
    original = dup(1);
    quiet = open("/dev/null", 01);
    dup2(quiet, 1);
    close(quiet);
    return original;
}

canonical_original_code:
int disable_stdout() {
    int original; int quiet;
    fflush(stdout);
    original = dup(1);
    quiet = open("/dev/null", 01);
    dup2(quiet, 1);
    close(quiet);
    return original;
}

variable_types: original int

variable_types: quiet int

return_type: int


decompiled_code:
int __fastcall enable_stdout(int fd)
{
fflush(stdout);
dup2(fd, 1);
return close(fd);
}

canonical_decompiled_code:
int __fastcall func2(int fd)
{
fflush(stdout);
dup2(fd, 1);
return close(fd);
}

original_code:
void enable_stdout(int original) {
    fflush(stdout);
    dup2(original, 1);
    close(original);
}


welcome

decompiled_code:
char __fastcall welcome(__int64 a1)
{
const char *v1; // r8
bool v2; // zf
char result; // al
char v4[40]; // [rsp+0h] [rbp-28h] BYREF

v1 = *(const char **)(a1 + 8);
v2 = strcmp(v1, "circus-bot") == 0;
result = !v2;
if ( !v2 )
{
snprintf(v4, 0x1EuLL, "Welcome %s", v1);
result = irc_message(*(_QWORD *)(a1 + 32), v4);
}
return result;
}

canonical_decompiled_code:
char __fastcall func0(__int64 a1)
{
const char *v1; // r8
bool v2; // zf
char result; // al
char v4[40]; // [rsp+0h] [rbp-28h] BYREF

v1 = *(const char **)(a1 + 8);
v2 = strcmp(v1, "circus-bot") == 0;
result = !v2;
if ( !v2 )
{
snprintf(v4, 0x1EuLL, "Welcome %s", v1);
result = irc_message(*(_QWORD *)(a1 + 32), v4);
}
return result;
}

original_code:
void welcome(JoinEvent* event) {
    char msg[30];
    if ((strcmp(event->user.nick,"circus-bot") != 0)) {
        snprintf(msg, 30, "Welcome %s", event->user.nick);
        irc_message(event->channel, msg);
    }
}

canonical_original_code:
void welcome(struct JoinEvent *event) {
    char msg[30];
    if ((strcmp(event->user.nick,"circus-bot") != 0)) {
        snprintf(msg, 30, "Welcome %s", event->user.nick);
        irc_message(event->channel, msg);
    }
}

variable_types: struct JoinEvent { struct timeval { long tv_sec; long tv_usec; } *timestamp; struct UserInfo { char *nick; char *user; char *server; } user; char *channel; } *

variable_types:
msg
char [30]

user_defined_types: struct JoinEvent { struct timeval *timestamp; struct UserInfo user; char *channel; }


decompiled_code:
__int64 __fastcall give_op(__int64 a1)
{
return irc_op(*(_QWORD *)(a1 + 40), *(_QWORD *)(a1 + 8));
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
return irc_op(*(_QWORD *)(a1 + 40), *(_QWORD *)(a1 + 8));
}

original_code:
void give_op(MessageEvent* event) {
    irc_op(event->to, event->user.nick);
}

canonical_original_code:
void give_op(struct MessageEvent *event) {
    irc_op(event->to, event->user.nick);
}

variable_types: struct MessageEvent { struct timeval { long tv_sec; long tv_usec; } *timestamp; struct UserInfo { char *nick; char *user; char *server; } user; int is_channel; char *to; char *message; } *

user_defined_types: struct MessageEvent { struct timeval *timestamp; struct UserInfo user; int is_channel; char *to; char *message; }


disable

decompiled_code:
__int64 disable()
{
irc_unbind_event("JOIN");
return irc_unbind_command("!op");
}

canonical_decompiled_code:
__int64 func2()
{
irc_unbind_event("JOIN");
return irc_unbind_command("!op");
}

original_code:
void disable(MessageEvent* event) {
    irc_unbind_event("JOIN");
    irc_unbind_command("!op");
}

canonical_original_code:
void disable(struct MessageEvent *event) {
    irc_unbind_event("JOIN");
    irc_unbind_command("!op");
}

user_defined_types: struct UserInfo { char *nick; char *user; char *server; }

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


enable

decompiled_code:
__int64 enable()
{
irc_bind_event("JOIN", welcome);
return irc_bind_command("!op", give_op);
}

canonical_decompiled_code:
__int64 func3()
{
irc_bind_event("JOIN", welcome);
return irc_bind_command("!op", give_op);
}

original_code:
void enable(MessageEvent* event) {
    irc_bind_event("JOIN", (Callback) welcome);
    irc_bind_command("!op", (Callback) give_op);
}

canonical_original_code:
void enable(struct MessageEvent *event) {
    irc_bind_event("JOIN", (void (*)()) welcome);
    irc_bind_command("!op", (void (*)()) give_op);
}


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

if ( !*lib_name )
return mu_fail("test_version_values: lib_name is not set");
if ( !*lib_version )
return mu_fail("test_version_values: lib_version is not set");
if ( !*git_revision )
return mu_fail("test_version_values: git_revision is not set");
if ( !*build_platform )
return mu_fail("test_version_values: build_platform is not set");
result = build_date;
if ( !*build_date )
result = mu_fail("test_version_values: build_date is not set");
return result;
}

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

if ( !*lib_name )
return mu_fail("test_version_values: lib_name is not set");
if ( !*lib_version )
return mu_fail("test_version_values: lib_version is not set");
if ( !*git_revision )
return mu_fail("test_version_values: git_revision is not set");
if ( !*build_platform )
return mu_fail("test_version_values: build_platform is not set");
result = build_date;
if ( !*build_date )
result = mu_fail("test_version_values: build_date is not set");
return result;
}

original_code:
void test_version_values() {
    do { if (!(strlen(lib_name) > 0)) { mu_fail("test_version_values: lib_name is not set"); return; } } while (0);
    do { if (!(strlen(lib_version) > 0)) { mu_fail("test_version_values: lib_version is not set"); return; } } while (0);
    do { if (!(strlen(git_revision) > 0)) { mu_fail("test_version_values: git_revision is not set"); return; } } while (0);
    do { if (!(strlen(build_platform) > 0)) { mu_fail("test_version_values: build_platform is not set"); return; } } while (0);
    do { if (!(strlen(build_date) > 0)) { mu_fail("test_version_values: build_date is not set"); return; } } while (0);
}


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

result = test_version_values();
++tests_run;
return result;
}

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

result = func0();
++tests_run;
return result;
}

original_code:
void test_version() {
    do { (void)0; test_version_values(); tests_run++; } while (0);
}


decompiled_code:
__time_t __fastcall on_event(__int64 a1)
{
__time_t result; // rax
double v2; // xmm0_8
struct timeval v3; // [rsp+0h] [rbp-18h] BYREF

gettimeofday(&v3, 0LL);
result = 1000000 * (v3.tv_sec - **(_QWORD **)a1) + LODWORD(v3.tv_usec) - *(_DWORD *)(*(_QWORD *)a1 + 8LL);
v2 = (double)(int)result;
if ( *(double *)&avg_sec > 0.0 )
v2 = (v2 + *(double *)&avg_sec) * 0.5;
++evt_total;
*(double *)&avg_sec = v2 / 1000000.0;
return result;
}

canonical_decompiled_code:
__time_t __fastcall func0(__int64 a1)
{
__time_t result; // rax
double v2; // xmm0_8
struct timeval v3; // [rsp+0h] [rbp-18h] BYREF

gettimeofday(&v3, 0LL);
result = 1000000 * (v3.tv_sec - **(_QWORD **)a1) + LODWORD(v3.tv_usec) - *(_DWORD *)(*(_QWORD *)a1 + 8LL);
v2 = (double)(int)result;
if ( *(double *)&avg_sec > 0.0 )
v2 = (v2 + *(double *)&avg_sec) * 0.5;
++evt_total;
*(double *)&avg_sec = v2 / 1000000.0;
return result;
}

original_code:
void on_event(GenericEvent* event) {
    struct timeval current_time;
    long int avg;
    gettimeofday(&current_time, ((void *)0));
    avg = (current_time.tv_sec - event->timestamp->tv_sec) * 1000000 + ((int) current_time.tv_usec - (int) event->timestamp->tv_usec);
    avg_sec = (avg_sec > 0 ? (avg_sec + avg) / (double) 2 : avg) / 1000000;
    evt_total++;
}

canonical_original_code:
void on_event(struct GenericEvent *event) {
    struct timeval current_time;
    long avg;
    gettimeofday(&current_time, ((void *)0));
    avg = (current_time.tv_sec - event->timestamp->tv_sec) * 1000000 + ((int) current_time.tv_usec - (int) event->timestamp->tv_usec);
    avg_sec = (avg_sec > 0 ? (avg_sec + avg) / (double) 2 : avg) / 1000000;
    evt_total++;
}

variable_types: struct GenericEvent { struct timeval { long tv_sec; long tv_usec; } *timestamp; char *code; int num_params; char *params[15]; char *message; } *

variable_types: avg long

user_defined_types: struct GenericEvent { struct timeval *timestamp; char *code; int num_params; char *params[15]; char *message; }


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rbx
__int64 v4; // rax
int v5; // ebx
__int64 v7; // [rsp+8h] [rbp-C0h]
struct timeval tv; // [rsp+10h] [rbp-B8h] BYREF
struct timeval v9; // [rsp+20h] [rbp-A8h] BYREF
__int64 v10; // [rsp+48h] [rbp-80h]
__int128 v11; // [rsp+50h] [rbp-78h]
__int128 v12; // [rsp+60h] [rbp-68h]
__int128 v13; // [rsp+70h] [rbp-58h]
int v14; // [rsp+80h] [rbp-48h]

if ( argc != 2 )
{
printf("Usage: %s <num_events>\n", *argv);
exit(1);
}
v3 = strtol(argv[1], 0LL, 0);
bnd_bind("ALL", on_event);
dsp_start();
printf("Starting benchmark with %ld events\n", v3);
gettimeofday(&tv, 0LL);
if ( v3 > 0 )
{
v4 = 0LL;
do
{
v7 = v4;
strcpy((char *)&v9, ":nick!~user@server MODE #test +inm\r\n");
v10 = 0LL;
v14 = 0;
v11 = 0LL;
v12 = 0LL;
v13 = 0LL;
lst_handle(&v9);
v4 = v7 + 1;
}
while ( v3 != v7 + 1 );
}
while ( evt_total < v3 )
poll(0LL, 0LL, 10);
gettimeofday(&v9, 0LL);
v5 = 1000000 * (LODWORD(v9.tv_sec) - LODWORD(tv.tv_sec)) + LODWORD(v9.tv_usec) - LODWORD(tv.tv_usec);
dsp_shutdown();
bnd_destroy();
printf(" Run time (secs): %f\n", (double)v5 / 1000000.0);
printf(" Processed events: %ld\n", evt_total);
printf(" Process time per event (secs): %f\n", *(double *)&avg_sec);
return 0;
}

original_code:
int main(int argc, char **argv) {
    long int i, evt_max, el_usec;
    struct timeval start, end;
    if (argc != 2) {
        printf("Usage: %s <num_events>\n", argv[0]);
        exit(1);
    }
    evt_max = strtol(argv[1], ((void *)0), 0);
    bnd_bind("ALL", (Callback) on_event);
    dsp_start();
    printf("Starting benchmark with %ld events\n", evt_max);
    gettimeofday(&start, ((void *)0));
    for (i = 0; i < evt_max; i++) {
        char event[100] = ":nick!~user@server MODE #test +inm\r\n";
        lst_handle(event);
    }
    while (evt_total < evt_max) {
        poll(0, 0, 10);
    }
    gettimeofday(&end, ((void *)0));
    el_usec = (end.tv_sec - start.tv_sec) * 1000000 + ((int) end.tv_usec - (int) start.tv_usec);
    dsp_shutdown();
    bnd_destroy();
    printf("  Run time (secs): %f\n", el_usec / (double) 1000000);
    printf("  Processed events: %ld\n", evt_total);
    printf("  Process time per event (secs): %f\n", avg_sec);
    return 0;
}

canonical_original_code:
int main(int argc, char **argv) {
    long i; long evt_max; long el_usec;
    struct timeval start; struct timeval end;
    if (argc != 2) {
        printf("Usage: %s <num_events>\n", argv[0]);
        exit(1);
    }
    evt_max = strtol(argv[1], ((void *)0), 0);
    bnd_bind("ALL", (void (*)()) on_event);
    dsp_start();
    printf("Starting benchmark with %ld events\n", evt_max);
    gettimeofday(&start, ((void *)0));
    for (i = 0; i < evt_max; i++) {
        char event[100] = ":nick!~user@server MODE #test +inm\r\n";
        lst_handle(event);
    }
    while (evt_total < evt_max) {
        poll(0, 0, 10);
    }
    gettimeofday(&end, ((void *)0));
    el_usec = (end.tv_sec - start.tv_sec) * 1000000 + ((int) end.tv_usec - (int) start.tv_usec);
    dsp_shutdown();
    bnd_destroy();
    printf("  Run time (secs): %f\n", el_usec / (double) 1000000);
    printf("  Processed events: %ld\n", evt_total);
    printf("  Process time per event (secs): %f\n", avg_sec);
    return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types: i long

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

variable_types:
event
char [100]


decompiled_code:
int debug_printf(char *format, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

va_start(arg, format);
return vfprintf(stderr, format, arg);
}

canonical_decompiled_code:
int func0(char *format, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

va_start(arg, format);
return vfprintf(stderr, format, arg);
}

original_code:
void debug_printf(char *fmt, ...) {
    va_list ap;
    __builtin_va_start(ap,fmt);
    vfprintf(stderr, fmt, ap);
    __builtin_va_end(ap);
}

canonical_original_code:
void debug_printf(char *fmt, ...) {
    __builtin_va_list ap;
    __builtin_va_start(ap,fmt);
    vfprintf(stderr, fmt, ap);
    __builtin_va_end(ap);
}

variable_types:
fmt
char *


decompiled_code:
void __fastcall __noreturn on_nick_in_use(__int64 a1)
{
printf("Nick %s is already in use\n", *(const char **)(a1 + 32));
irc_quit("Bye");
irc_disconnect();
exit(1);
}

canonical_decompiled_code:
void __fastcall __noreturn func0(__int64 a1)
{
printf("Nick %s is already in use\n", *(const char **)(a1 + 32));
irc_quit("Bye");
irc_disconnect();
exit(1);
}

original_code:
void on_nick_in_use(ErrorEvent* event) {
    printf("Nick %s is already in use\n", event->params[1]);
    irc_quit("Bye");
    irc_disconnect();
    exit(1);
}

canonical_original_code:
void on_nick_in_use(struct ErrorEvent *event) {
    printf("Nick %s is already in use\n", event->params[1]);
    irc_quit("Bye");
    irc_disconnect();
    exit(1);
}

variable_types: struct ErrorEvent { struct timeval { long tv_sec; long tv_usec; } *timestamp; char *code; int num_params; char *params[15]; char *message; } *

user_defined_types: struct ErrorEvent { struct timeval *timestamp; char *code; int num_params; char *params[15]; char *message; }


logtwo

repo: naegelejd/duneOS

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

result = 0LL;
if ( a1 > 1 )
{
do
{
a1 >>= 1;
result = (unsigned int)(result + 1);
}
while ( a1 != 1 );
}
return result;
}

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

result = 0LL;
if ( a1 > 1 )
{
do
{
a1 >>= 1;
result = (unsigned int)(result + 1);
}
while ( a1 != 1 );
}
return result;
}

original_code:
static unsigned int logtwo(unsigned int num)
{
    unsigned int p = 0;
    while (num > 1) {
        p++;
        num /= 2;
    }
    return p;
}

variable_types:
num
unsigned int

variable_types:
p
unsigned int

return_type: unsigned int


original_code:
static void populate_superblock(struct ext2_superblock *sb,
        long image_size, long block_size)
{
    unsigned int usable_blocks = (unsigned int)(image_size / block_size);
    sb->s_blocks_count = usable_blocks;
    sb->s_r_blocks_count = usable_blocks / 32;
    sb->s_first_data_block = block_size / EXT2_SUPERBLOCK_LOCATION;
    sb->s_log_block_size = logtwo(block_size / 1024);
    sb->s_log_frag_size = sb->s_log_block_size;
    sb->s_blocks_per_group = 8 * block_size;
    sb->s_frags_per_group = 0;
    sb->s_inodes_per_group = 8 * block_size;
    unsigned int num_block_groups = sb->s_blocks_count / sb->s_blocks_per_group;
    unsigned int block_group_descr_table_size = num_block_groups *
            sizeof(struct ext2_block_group_descr);
    unsigned int block_group_size = sb->s_blocks_per_group * block_size;
    do { printf("Number of blocks: %u\n", sb->s_blocks_count); } while (0);
    do { printf("Number of block groups: %u\n", num_block_groups); } while (0);
    do { printf("Size of block group descriptor table: %u\n", block_group_descr_table_size); } while (0);
    do { printf("Size of block group: %u\n", block_group_size); } while (0);
    sb->s_inodes_count = sb->s_inodes_per_group * num_block_groups;
    sb->s_free_blocks_count = sb->s_blocks_count;
    sb->s_free_inodes_count = sb->s_inodes_count - (
            EXT2_GOOD_OLD_FIRST_INO * num_block_groups);
    sb->s_mtime = 0;
    sb->s_wtime = 0;
    sb->s_mnt_count = 0;
    sb->s_max_mnt_count = 32;
    sb->s_magic = EXT2_SUPER_MAGIC;
    sb->s_state = EXT2_VALID_FS;
    sb->s_errors = EXT2_ERRORS_PANIC;
    sb->s_minor_rev_level = 0;
    sb->s_lastcheck = 0;
    sb->s_checkinterval = 60 * 60 * 24 * 64;
    sb->s_creator_os = EXT2_OS_LINUX;
    sb->s_rev_level = 0;
    sb->s_def_resuid = EXT2_DEF_RESUID;
    sb->s_first_ino = EXT2_GOOD_OLD_FIRST_INO;
    sb->s_inode_size = EXT2_GOOD_OLD_INODE_SIZE;
    sb->s_block_group_nr = sb->s_first_data_block;
    sb->s_feature_compat = 0;
    sb->s_feature_incompat = 0;
    sb->s_feature_ro_compat = 0;
    uint32_t *s_uuid = &sb->s_uuid[0];
    *s_uuid++ = (uint32_t)random();
    *s_uuid++ = (uint32_t)random();
    *s_uuid++ = (uint32_t)random();
    *s_uuid = (uint32_t)random();
    memset(sb->s_volume_name, 0, 16);
    memset(sb->s_last_mounted, 0, 64);
    sb->s_algo_bitmap = EXT2_GZIP_ALG;
    sb->s_prealloc_blocks = 0;
    sb->s_prealloc_dir_blocks = 0;
    memset(sb->s_journal_uuid, 0, sizeof(sb->s_journal_uuid));
    sb->s_journal_inum = 0;
    sb->s_journal_dev = 0;
    sb->s_last_orphan = 0;
    uint32_t *s_hash_seed = &sb->s_hash_seed[0];
    *s_hash_seed++ = (uint32_t)random();
    *s_hash_seed++ = (uint32_t)random();
    *s_hash_seed++ = (uint32_t)random();
    *s_hash_seed = (uint32_t)random();
    sb->s_def_hash_version = 0;
    sb->s_default_mount_options = 0;
    sb->s_first_meta_bg = 0;
}

canonical_original_code:
static void populate_superblock(struct ext2_superblock *sb, long image_size, long block_size)
{
    unsigned int usable_blocks = (unsigned int)(image_size / block_size);
    sb->s_blocks_count = usable_blocks;
    sb->s_r_blocks_count = usable_blocks / 32;
    sb->s_first_data_block = block_size / EXT2_SUPERBLOCK_LOCATION;
    sb->s_log_block_size = logtwo(block_size / 1024);
    sb->s_log_frag_size = sb->s_log_block_size;
    sb->s_blocks_per_group = 8 * block_size;
    sb->s_frags_per_group = 0;
    sb->s_inodes_per_group = 8 * block_size;
    unsigned int num_block_groups = sb->s_blocks_count / sb->s_blocks_per_group;
    unsigned int block_group_descr_table_size = num_block_groups *
            sizeof(struct ext2_block_group_descr);
    unsigned int block_group_size = sb->s_blocks_per_group * block_size;
    do { printf("Number of blocks: %u\n", sb->s_blocks_count); } while (0);
    do { printf("Number of block groups: %u\n", num_block_groups); } while (0);
    do { printf("Size of block group descriptor table: %u\n", block_group_descr_table_size); } while (0);
    do { printf("Size of block group: %u\n", block_group_size); } while (0);
    sb->s_inodes_count = sb->s_inodes_per_group * num_block_groups;
    sb->s_free_blocks_count = sb->s_blocks_count;
    sb->s_free_inodes_count = sb->s_inodes_count - (
            EXT2_GOOD_OLD_FIRST_INO * num_block_groups);
    sb->s_mtime = 0;
    sb->s_wtime = 0;
    sb->s_mnt_count = 0;
    sb->s_max_mnt_count = 32;
    sb->s_magic = EXT2_SUPER_MAGIC;
    sb->s_state = EXT2_VALID_FS;
    sb->s_errors = EXT2_ERRORS_PANIC;
    sb->s_minor_rev_level = 0;
    sb->s_lastcheck = 0;
    sb->s_checkinterval = 60 * 60 * 24 * 64;
    sb->s_creator_os = EXT2_OS_LINUX;
    sb->s_rev_level = 0;
    sb->s_def_resuid = EXT2_DEF_RESUID;
    sb->s_first_ino = EXT2_GOOD_OLD_FIRST_INO;
    sb->s_inode_size = EXT2_GOOD_OLD_INODE_SIZE;
    sb->s_block_group_nr = sb->s_first_data_block;
    sb->s_feature_compat = 0;
    sb->s_feature_incompat = 0;
    sb->s_feature_ro_compat = 0;
    unsigned int *s_uuid = &sb->s_uuid[0];
    *s_uuid++ = (unsigned int)random();
    *s_uuid++ = (unsigned int)random();
    *s_uuid++ = (unsigned int)random();
    *s_uuid = (unsigned int)random();
    memset(sb->s_volume_name, 0, 16);
    memset(sb->s_last_mounted, 0, 64);
    sb->s_algo_bitmap = EXT2_GZIP_ALG;
    sb->s_prealloc_blocks = 0;
    sb->s_prealloc_dir_blocks = 0;
    memset(sb->s_journal_uuid, 0, sizeof(sb->s_journal_uuid));
    sb->s_journal_inum = 0;
    sb->s_journal_dev = 0;
    sb->s_last_orphan = 0;
    unsigned int *s_hash_seed = &sb->s_hash_seed[0];
    *s_hash_seed++ = (unsigned int)random();
    *s_hash_seed++ = (unsigned int)random();
    *s_hash_seed++ = (unsigned int)random();
    *s_hash_seed = (unsigned int)random();
    sb->s_def_hash_version = 0;
    sb->s_default_mount_options = 0;
    sb->s_first_meta_bg = 0;
}

variable_types: struct ext2_superblock { unsigned int s_inodes_count; unsigned int s_blocks_count; unsigned int s_r_blocks_count; unsigned int s_free_blocks_count; unsigned int s_free_inodes_count; unsigned int s_first_data_block; unsigned int s_log_block_size; int s_log_frag_size; unsigned int s_blocks_per_group; unsigned int s_frags_per_group; unsigned int s_inodes_per_group; unsigned int s_mtime; unsigned int s_wtime; unsigned short s_mnt_count; unsigned short s_max_mnt_count; unsigned short s_magic; unsigned short s_state; unsigned short s_errors; unsigned short s_minor_rev_level; unsigned int s_lastcheck; unsigned int s_checkinterval; unsigned int s_creator_os; unsigned int s_rev_level; unsigned short s_def_resuid; unsigned short s_def_resgid; unsigned int s_first_ino; unsigned short s_inode_size; unsigned short s_block_group_nr; unsigned int s_feature_compat; unsigned int s_feature_incompat; unsigned int s_feature_ro_compat; unsigned int s_uuid[4]; char s_volume_name[16]; char s_last_mounted[64]; unsigned int s_algo_bitmap; unsigned char s_prealloc_blocks; unsigned char s_prealloc_dir_blocks; unsigned char alignment[2]; unsigned int s_journal_uuid[4]; unsigned int s_journal_inum; unsigned int s_journal_dev; unsigned int s_last_orphan; unsigned int s_hash_seed[4]; unsigned char s_def_hash_version; unsigned char reserved[3]; unsigned int s_default_mount_options; unsigned int s_first_meta_bg; unsigned char unused[760]; } *


repo: naftaliharris/markovian

decompiled_code:
__int64 random64()
{
__int64 v0; // rbx

v0 = random() << 32;
return v0 | random();
}

canonical_decompiled_code:
__int64 func7()
{
__int64 v0; // rbx

v0 = random() << 32;
return v0 | random();
}

original_code:
uint64_t random64(void)
{
    uint64_t result = random();
    result = result << 32;
    result |= random();
    return (result);
}

canonical_original_code:
unsigned long random64()
{
    unsigned long result = random();
    result = result << 32;
    result |= random();
    return (result);
}

variable_types:
result
unsigned long

return_type: unsigned long


main

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

v3 = 9;
v4 = (char *)malloc(0x100000uLL);
initstate(0x40A4A42u, v4, 0x100000uLL);
fwrite("// hashrands.h\n// random numbers to use in hashing\n\n", 1uLL, 0x34uLL, _bss_start);
fwrite("#define WKingHash Hash[0]\n", 1uLL, 0x1BuLL, _bss_start);
fwrite("#define BKingHash Hash[1]\n", 1uLL, 0x1BuLL, _bss_start);
fwrite("#define WQueensHash Hash[2]\n", 1uLL, 0x1FuLL, _bss_start);
fwrite("#define BQueensHash Hash[3]\n", 1uLL, 0x1FuLL, _bss_start);
fwrite("#define WRooksHash Hash[4]\n", 1uLL, 0x1BuLL, _bss_start);
fwrite("#define BRooksHash Hash[5]\n", 1uLL, 0x1BuLL, _bss_start);
fwrite("#define WBishopsHash Hash[6]\n", 1uLL, 0x1FuLL, _bss_start);
fwrite("#define BBishopsHash Hash[7]\n", 1uLL, 0x1FuLL, _bss_start);
fwrite("#define WKnightsHash Hash[8]\n", 1uLL, 0x1FuLL, _bss_start);
fwrite("#define BKnightsHash Hash[9]\n", 1uLL, 0x1FuLL, _bss_start);
fwrite("#define WPawnsHash Hash[10]\n", 1uLL, 0x1CuLL, _bss_start);
fwrite("#define BPawnsHash Hash[11]\n", 1uLL, 0x1CuLL, _bss_start);
fputc(10, _bss_start);
fwrite("uint64_t ToMoveHash[2] = {\n", 1uLL, 0x1BuLL, _bss_start);
v5 = random64();
fprintf(_bss_start, "0x%llx,\n", v5);
v6 = random64();
fprintf(_bss_start, "0x%llx,\n", v6);
fwrite("};\n\n", 1uLL, 4uLL, _bss_start);
fwrite("uint64_t EPHash[9] = {\n", 1uLL, 0x17uLL, _bss_start);
do
{
v7 = random64();
fprintf(_bss_start, "0x%llx,\n", v7);
--v3;
}
while ( v3 );
v8 = 16;
fwrite("};\n\n", 1uLL, 4uLL, _bss_start);
fwrite("uint64_t CastlingHash[16] = {\n", 1uLL, 0x1EuLL, _bss_start);
do
{
v9 = random64();
fprintf(_bss_start, "0x%llx,\n", v9);
--v8;
}
while ( v8 );
v10 = 12;
fwrite("};\n\n", 1uLL, 4uLL, _bss_start);
fwrite("uint64_t Hash[12][64] = {\n", 1uLL, 0x1AuLL, _bss_start);
do
{
v11 = 64;
fwrite("{\n", 1uLL, 2uLL, _bss_start);
do
{
v12 = random64();
fprintf(_bss_start, "0x%llx,\n", v12);
--v11;
}
while ( v11 );
fwrite("},\n", 1uLL, 3uLL, _bss_start);
--v10;
}
while ( v10 );
fwrite("};\n\n", 1uLL, 4uLL, _bss_start);
return 0;
}

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

v3 = 9;
v4 = (char *)malloc(0x100000uLL);
initstate(0x40A4A42u, v4, 0x100000uLL);
fwrite("// hashrands.h\n// random numbers to use in hashing\n\n", 1uLL, 0x34uLL, _bss_start);
fwrite("#define WKingHash Hash[0]\n", 1uLL, 0x1BuLL, _bss_start);
fwrite("#define BKingHash Hash[1]\n", 1uLL, 0x1BuLL, _bss_start);
fwrite("#define WQueensHash Hash[2]\n", 1uLL, 0x1FuLL, _bss_start);
fwrite("#define BQueensHash Hash[3]\n", 1uLL, 0x1FuLL, _bss_start);
fwrite("#define WRooksHash Hash[4]\n", 1uLL, 0x1BuLL, _bss_start);
fwrite("#define BRooksHash Hash[5]\n", 1uLL, 0x1BuLL, _bss_start);
fwrite("#define WBishopsHash Hash[6]\n", 1uLL, 0x1FuLL, _bss_start);
fwrite("#define BBishopsHash Hash[7]\n", 1uLL, 0x1FuLL, _bss_start);
fwrite("#define WKnightsHash Hash[8]\n", 1uLL, 0x1FuLL, _bss_start);
fwrite("#define BKnightsHash Hash[9]\n", 1uLL, 0x1FuLL, _bss_start);
fwrite("#define WPawnsHash Hash[10]\n", 1uLL, 0x1CuLL, _bss_start);
fwrite("#define BPawnsHash Hash[11]\n", 1uLL, 0x1CuLL, _bss_start);
fputc(10, _bss_start);
fwrite("uint64_t ToMoveHash[2] = {\n", 1uLL, 0x1BuLL, _bss_start);
v5 = func7();
fprintf(_bss_start, "0x%llx,\n", v5);
v6 = func7();
fprintf(_bss_start, "0x%llx,\n", v6);
fwrite("};\n\n", 1uLL, 4uLL, _bss_start);
fwrite("uint64_t EPHash[9] = {\n", 1uLL, 0x17uLL, _bss_start);
do
{
v7 = func7();
fprintf(_bss_start, "0x%llx,\n", v7);
--v3;
}
while ( v3 );
v8 = 16;
fwrite("};\n\n", 1uLL, 4uLL, _bss_start);
fwrite("uint64_t CastlingHash[16] = {\n", 1uLL, 0x1EuLL, _bss_start);
do
{
v9 = func7();
fprintf(_bss_start, "0x%llx,\n", v9);
--v8;
}
while ( v8 );
v10 = 12;
fwrite("};\n\n", 1uLL, 4uLL, _bss_start);
fwrite("uint64_t Hash[12][64] = {\n", 1uLL, 0x1AuLL, _bss_start);
do
{
v11 = 64;
fwrite("{\n", 1uLL, 2uLL, _bss_start);
do
{
v12 = func7();
fprintf(_bss_start, "0x%llx,\n", v12);
--v11;
}
while ( v11 );
fwrite("},\n", 1uLL, 3uLL, _bss_start);
--v10;
}
while ( v10 );
fwrite("};\n\n", 1uLL, 4uLL, _bss_start);
return 0;
}

original_code:
int main(void)
{
    char *states = malloc(1024 * 1024);
    initstate(67783234, states, 1024 * 1024);
    fprintf(stdout, "// hashrands.h\n// random numbers to use in hashing\n\n");
    fprintf(stdout, "#define WKingHash  Hash[0]\n");
    fprintf(stdout, "#define BKingHash  Hash[1]\n");
    fprintf(stdout, "#define WQueensHash    Hash[2]\n");
    fprintf(stdout, "#define BQueensHash    Hash[3]\n");
    fprintf(stdout, "#define WRooksHash Hash[4]\n");
    fprintf(stdout, "#define BRooksHash Hash[5]\n");
    fprintf(stdout, "#define WBishopsHash   Hash[6]\n");
    fprintf(stdout, "#define BBishopsHash   Hash[7]\n");
    fprintf(stdout, "#define WKnightsHash   Hash[8]\n");
    fprintf(stdout, "#define BKnightsHash   Hash[9]\n");
    fprintf(stdout, "#define WPawnsHash Hash[10]\n");
    fprintf(stdout, "#define BPawnsHash Hash[11]\n");
    fprintf(stdout, "\n");
    fprintf(stdout, "uint64_t ToMoveHash[2] = {\n");
    for (int i = 0; i < 2; i++) {
        fprintf(stdout, "0x%llx,\n", random64());
    }
    fprintf(stdout, "};\n\n");
    fprintf(stdout, "uint64_t EPHash[9] = {\n");
    for (int i = 0; i < 9; i++) {
        fprintf(stdout, "0x%llx,\n", random64());
    }
    fprintf(stdout, "};\n\n");
    fprintf(stdout, "uint64_t CastlingHash[16] = {\n");
    for (int i = 0; i < 16; i++) {
        fprintf(stdout, "0x%llx,\n", random64());
    }
    fprintf(stdout, "};\n\n");
    fprintf(stdout, "uint64_t Hash[12][64] = {\n");
    for (int i = 0; i < 12; i++) {
        fprintf(stdout, "{\n");
        for (int j = 0; j < 64; j++) {
            fprintf(stdout, "0x%llx,\n", random64());
        }
        fprintf(stdout, "},\n");
    }
    fprintf(stdout, "};\n\n");
    return (0);
}

canonical_original_code:
int main()
{
    char *states = malloc(1024 * 1024);
    initstate(67783234, states, 1024 * 1024);
    fprintf(stdout, "// hashrands.h\n// random numbers to use in hashing\n\n");
    fprintf(stdout, "#define WKingHash  Hash[0]\n");
    fprintf(stdout, "#define BKingHash  Hash[1]\n");
    fprintf(stdout, "#define WQueensHash    Hash[2]\n");
    fprintf(stdout, "#define BQueensHash    Hash[3]\n");
    fprintf(stdout, "#define WRooksHash Hash[4]\n");
    fprintf(stdout, "#define BRooksHash Hash[5]\n");
    fprintf(stdout, "#define WBishopsHash   Hash[6]\n");
    fprintf(stdout, "#define BBishopsHash   Hash[7]\n");
    fprintf(stdout, "#define WKnightsHash   Hash[8]\n");
    fprintf(stdout, "#define BKnightsHash   Hash[9]\n");
    fprintf(stdout, "#define WPawnsHash Hash[10]\n");
    fprintf(stdout, "#define BPawnsHash Hash[11]\n");
    fprintf(stdout, "\n");
    fprintf(stdout, "uint64_t ToMoveHash[2] = {\n");
    for (int i = 0; i < 2; i++) {
        fprintf(stdout, "0x%llx,\n", random64());
    }
    fprintf(stdout, "};\n\n");
    fprintf(stdout, "uint64_t EPHash[9] = {\n");
    for (int i = 0; i < 9; i++) {
        fprintf(stdout, "0x%llx,\n", random64());
    }
    fprintf(stdout, "};\n\n");
    fprintf(stdout, "uint64_t CastlingHash[16] = {\n");
    for (int i = 0; i < 16; i++) {
        fprintf(stdout, "0x%llx,\n", random64());
    }
    fprintf(stdout, "};\n\n");
    fprintf(stdout, "uint64_t Hash[12][64] = {\n");
    for (int i = 0; i < 12; i++) {
        fprintf(stdout, "{\n");
        for (int j = 0; j < 64; j++) {
            fprintf(stdout, "0x%llx,\n", random64());
        }
        fprintf(stdout, "},\n");
    }
    fprintf(stdout, "};\n\n");
    return (0);
}

variable_types:
states
char *

variable_types: i int

variable_types: j int


repo: namelessjon/librabin

decompiled_code:
void __fastcall rabin_splitter_free(void *ptr)
{
void *v2; // rdi

if ( ptr )
{
v2 = (void *)*((_QWORD *)ptr + 360);
if ( v2 )
free(v2);
free(ptr);
}
}

canonical_decompiled_code:
void __fastcall func6(void *ptr)
{
void *v2; // rdi

if ( ptr )
{
v2 = (void *)*((_QWORD *)ptr + 360);
if ( v2 )
free(v2);
free(ptr);
}
}

original_code:
void rabin_splitter_free(rabin_splitter_t * splitter) {
    if (splitter) {
        if (splitter->buffer) {
            free(splitter->buffer);
            splitter->buffer = ((void *)0);
        }
        free(splitter);
        splitter = ((void *)0);
    }
}

canonical_original_code:
void rabin_splitter_free(struct rabin_splitter_t *splitter) {
    if (splitter) {
        if (splitter->buffer) {
            free(splitter->buffer);
            splitter->buffer = ((void *)0);
        }
        free(splitter);
        splitter = ((void *)0);
    }
}

variable_types: struct rabin_splitter_t { unsigned long long prime; unsigned long window_size; unsigned long min_blk_sz; unsigned long avg_blk_sz; unsigned long max_blk_sz; unsigned long long blk_sz; unsigned long long fingerprint; unsigned long long polynomial_map[256]; struct rabin_node_t { unsigned long long value; struct rabin_node_t *next; } cycle[48]; struct rabin_node_t *curr; unsigned char *buffer; } *

user_defined_types: struct rabin_splitter_t { unsigned long long prime; unsigned long window_size; unsigned long min_blk_sz; unsigned long avg_blk_sz; unsigned long max_blk_sz; unsigned long long blk_sz; unsigned long long fingerprint; unsigned long long polynomial_map[256]; struct rabin_node_t cycle[48]; struct rabin_node_t *curr; unsigned char *buffer; }


original_code:
int rabin_split_file(rabin_splitter_t * rsp,
                     int fileno,
                     rsp_chunk_callback cb,
                     void *userdata) {
    int ch;
    int i = 0, nread = 0;
    unsigned char input_buffer[(32768)];
    if ((!rsp)||(!cb))
        return 1;
    while ((nread = read(fileno, input_buffer, (32768)))) {
        for (i = 0; i < nread; i++) {
            ch = input_buffer[i];
            rsp->buffer[rsp->blk_sz] = ch;
            rsp->fingerprint *= rsp->prime;
            rsp->fingerprint += ch;
            rsp->fingerprint -= rsp->polynomial_map[rsp->curr->value];
            rsp->curr->value = ch;
            rsp->curr = rsp->curr->next;
            rsp->blk_sz++;
            if ((rsp->blk_sz > rsp->min_blk_sz)) {
                if (((rsp->fingerprint & rsp->avg_blk_sz) == 1) || (rsp->blk_sz >= rsp->max_blk_sz)) {
                    (*cb)(rsp->blk_sz, rsp->buffer, userdata);
                    rsp->blk_sz = 0;
                }
            }
        }
    }
    if (rsp->blk_sz != 0)
        (*cb)(rsp->blk_sz, rsp->buffer, userdata);
    return 0;
}

canonical_original_code:
int rabin_split_file(struct rabin_splitter_t *rsp, int fileno, void (*cb)(unsigned long long blk_sz, unsigned char *chunk, void *userdata), void *userdata) {
    int ch;
    int i = 0; int nread = 0;
    unsigned char input_buffer[-1];
    if ((!rsp)||(!cb))
        return 1;
    while ((nread = read(fileno, input_buffer, (32768)))) {
        for (i = 0; i < nread; i++) {
            ch = input_buffer[i];
            rsp->buffer[rsp->blk_sz] = ch;
            rsp->fingerprint *= rsp->prime;
            rsp->fingerprint += ch;
            rsp->fingerprint -= rsp->polynomial_map[rsp->curr->value];
            rsp->curr->value = ch;
            rsp->curr = rsp->curr->next;
            rsp->blk_sz++;
            if ((rsp->blk_sz > rsp->min_blk_sz)) {
                if (((rsp->fingerprint & rsp->avg_blk_sz) == 1) || (rsp->blk_sz >= rsp->max_blk_sz)) {
                    (*cb)(rsp->blk_sz, rsp->buffer, userdata);
                    rsp->blk_sz = 0;
                }
            }
        }
    }
    if (rsp->blk_sz != 0)
        (*cb)(rsp->blk_sz, rsp->buffer, userdata);
    return 0;
}

variable_types: fileno int

variable_types: void (*)(unsigned long long blk_sz, unsigned char *chunk, void *userdata)

variable_types:
userdata
void *

variable_types: ch int

variable_types: nread int

user_defined_types: struct rabin_node_t { unsigned long long value; struct rabin_node_t *next; }


alsaOutClose

repo: nanase/EasyAlsa

decompiled_code:
// attributes: thunk
__int64 alsaOutClose()
{
return snd_pcm_close();
}

canonical_decompiled_code:
__int64 func7()
{
return snd_pcm_close();
}

original_code:
int32_t alsaOutClose(void *handle) {
  return snd_pcm_close(handle);
}

canonical_original_code:
int alsaOutClose(void *handle) {
  return snd_pcm_close(handle);
}

variable_types:
handle
void *


alsaOutSetParams

decompiled_code:
__int64 alsaOutSetParams()
{
return snd_pcm_set_params();
}

canonical_decompiled_code:
__int64 func8()
{
return snd_pcm_set_params();
}

original_code:
int32_t alsaOutSetParams(void *handle,
        alsaPcmFormat_t format,
        uint32_t channels,
        uint32_t rate,
        uint32_t latency) {
  return snd_pcm_set_params(handle,
          (snd_pcm_format_t) format,
          SND_PCM_ACCESS_RW_INTERLEAVED,
          channels,
          rate,
          1,
          latency);
}

canonical_original_code:
int alsaOutSetParams(void *handle, enum _alsaPcmFormat_t format, unsigned int channels, unsigned int rate, unsigned int latency) {
  return snd_pcm_set_params(handle,
          (enum _snd_pcm_format) format,
          SND_PCM_ACCESS_RW_INTERLEAVED,
          channels,
          rate,
          1,
          latency);
}

variable_types: enum _alsaPcmFormat_t { ALSA_PCM_FORMAT_UNKNOWN=-1, ALSA_PCM_FORMAT_S8=0, ALSA_PCM_FORMAT_U8=1, ALSA_PCM_FORMAT_S16_LE=2, ALSA_PCM_FORMAT_S16_BE=3, ALSA_PCM_FORMAT_U16_LE=4, ALSA_PCM_FORMAT_U16_BE=5, ALSA_PCM_FORMAT_S24_LE=6, ALSA_PCM_FORMAT_S24_BE=7, ALSA_PCM_FORMAT_U24_LE=8, ALSA_PCM_FORMAT_U24_BE=9, ALSA_PCM_FORMAT_S32_LE=10, ALSA_PCM_FORMAT_S32_BE=11, ALSA_PCM_FORMAT_U32_LE=12, ALSA_PCM_FORMAT_U32_BE=13, ALSA_PCM_FORMAT_FLOAT_LE=14, ALSA_PCM_FORMAT_FLOAT_BE=15, ALSA_PCM_FORMAT_FLOAT64_LE=16, ALSA_PCM_FORMAT_FLOAT64_BE=17, ALSA_PCM_FORMAT_IEC958_SUBFRAME_LE=18, ALSA_PCM_FORMAT_IEC958_SUBFRAME_BE=19, ALSA_PCM_FORMAT_MU_LAW=20, ALSA_PCM_FORMAT_A_LAW=21, ALSA_PCM_FORMAT_IMA_ADPCM=22, ALSA_PCM_FORMAT_MPEG=23, ALSA_PCM_FORMAT_GSM=24, ALSA_PCM_FORMAT_SPECIAL=31, ALSA_PCM_FORMAT_S24_3LE=32, ALSA_PCM_FORMAT_S24_3BE=33, ALSA_PCM_FORMAT_U24_3LE=34, ALSA_PCM_FORMAT_U24_3BE=35, ALSA_PCM_FORMAT_S20_3LE=36, ALSA_PCM_FORMAT_S20_3BE=37, ALSA_PCM_FORMAT_U20_3LE=38, ALSA_PCM_FORMAT_U20_3BE=39, ALSA_PCM_FORMAT_S18_3LE=40, ALSA_PCM_FORMAT_S18_3BE=41, ALSA_PCM_FORMAT_U18_3LE=42, ALSA_PCM_FORMAT_U18_3BE=43, ALSA_PCM_FORMAT_G723_24=44, ALSA_PCM_FORMAT_G723_24_1B=45, ALSA_PCM_FORMAT_G723_40=46, ALSA_PCM_FORMAT_G723_40_1B=47, ALSA_PCM_FORMAT_DSD_U8=48, ALSA_PCM_FORMAT_DSD_U16_LE=49, ALSA_PCM_FORMAT_LAST=expr, ALSA_PCM_FORMAT_S16=expr, ALSA_PCM_FORMAT_U16=expr, ALSA_PCM_FORMAT_S24=expr, ALSA_PCM_FORMAT_U24=expr, ALSA_PCM_FORMAT_S32=expr, ALSA_PCM_FORMAT_U32=expr, ALSA_PCM_FORMAT_FLOAT=expr, ALSA_PCM_FORMAT_FLOAT64=expr, ALSA_PCM_FORMAT_IEC958_SUBFRAME=expr }

variable_types:
channels
unsigned int

variable_types:
rate
unsigned int

variable_types:
latency
unsigned int

user_defined_types: enum _snd_pcm_format { SND_PCM_FORMAT_UNKNOWN=-1, SND_PCM_FORMAT_S8=0, SND_PCM_FORMAT_U8=1, SND_PCM_FORMAT_S16_LE=2, SND_PCM_FORMAT_S16_BE=3, SND_PCM_FORMAT_U16_LE=4, SND_PCM_FORMAT_U16_BE=5, SND_PCM_FORMAT_S24_LE=6, SND_PCM_FORMAT_S24_BE=7, SND_PCM_FORMAT_U24_LE=8, SND_PCM_FORMAT_U24_BE=9, SND_PCM_FORMAT_S32_LE=10, SND_PCM_FORMAT_S32_BE=11, SND_PCM_FORMAT_U32_LE=12, SND_PCM_FORMAT_U32_BE=13, SND_PCM_FORMAT_FLOAT_LE=14, SND_PCM_FORMAT_FLOAT_BE=15, SND_PCM_FORMAT_FLOAT64_LE=16, SND_PCM_FORMAT_FLOAT64_BE=17, SND_PCM_FORMAT_IEC958_SUBFRAME_LE=18, SND_PCM_FORMAT_IEC958_SUBFRAME_BE=19, SND_PCM_FORMAT_MU_LAW=20, SND_PCM_FORMAT_A_LAW=21, SND_PCM_FORMAT_IMA_ADPCM=22, SND_PCM_FORMAT_MPEG=23, SND_PCM_FORMAT_GSM=24, SND_PCM_FORMAT_S20_LE=25, SND_PCM_FORMAT_S20_BE=26, SND_PCM_FORMAT_U20_LE=27, SND_PCM_FORMAT_U20_BE=28, SND_PCM_FORMAT_SPECIAL=31, SND_PCM_FORMAT_S24_3LE=32, SND_PCM_FORMAT_S24_3BE=33, SND_PCM_FORMAT_U24_3LE=34, SND_PCM_FORMAT_U24_3BE=35, SND_PCM_FORMAT_S20_3LE=36, SND_PCM_FORMAT_S20_3BE=37, SND_PCM_FORMAT_U20_3LE=38, SND_PCM_FORMAT_U20_3BE=39, SND_PCM_FORMAT_S18_3LE=40, SND_PCM_FORMAT_S18_3BE=41, SND_PCM_FORMAT_U18_3LE=42, SND_PCM_FORMAT_U18_3BE=43, SND_PCM_FORMAT_G723_24=44, SND_PCM_FORMAT_G723_24_1B=45, SND_PCM_FORMAT_G723_40=46, SND_PCM_FORMAT_G723_40_1B=47, SND_PCM_FORMAT_DSD_U8=48, SND_PCM_FORMAT_DSD_U16_LE=49, SND_PCM_FORMAT_DSD_U32_LE=50, SND_PCM_FORMAT_DSD_U16_BE=51, SND_PCM_FORMAT_DSD_U32_BE=52, SND_PCM_FORMAT_LAST=expr, SND_PCM_FORMAT_S16=expr, SND_PCM_FORMAT_U16=expr, SND_PCM_FORMAT_S24=expr, SND_PCM_FORMAT_U24=expr, SND_PCM_FORMAT_S32=expr, SND_PCM_FORMAT_U32=expr, SND_PCM_FORMAT_FLOAT=expr, SND_PCM_FORMAT_FLOAT64=expr, SND_PCM_FORMAT_IEC958_SUBFRAME=expr, SND_PCM_FORMAT_S20=expr, SND_PCM_FORMAT_U20=expr }


alsaOutWrite

decompiled_code:
__int64 alsaOutWrite()
{
return snd_pcm_writei();
}

canonical_decompiled_code:
__int64 func9()
{
return snd_pcm_writei();
}

original_code:
int32_t alsaOutWrite(void *handle, const void *buffer, uint32_t size) {
  return snd_pcm_writei(handle, buffer, size);
}

canonical_original_code:
int alsaOutWrite(void *handle, void *buffer, unsigned int size) {
  return snd_pcm_writei(handle, buffer, size);
}

variable_types:
buffer
void *

variable_types:
size
unsigned int


alsaOutRecover

decompiled_code:
__int64 alsaOutRecover()
{
return snd_pcm_recover();
}

canonical_decompiled_code:
__int64 func10()
{
return snd_pcm_recover();
}

original_code:
int32_t alsaOutRecover(void *handle, int32_t error) {
  return snd_pcm_recover(handle, error, 1);
}

canonical_original_code:
int alsaOutRecover(void *handle, int error) {
  return snd_pcm_recover(handle, error, 1);
}

variable_types: error int


alsaOutRecoverDebug

decompiled_code:
// attributes: thunk
__int64 alsaOutRecoverDebug()
{
return snd_pcm_recover();
}

canonical_decompiled_code:
__int64 func11()
{
return snd_pcm_recover();
}

original_code:
int32_t alsaOutRecoverDebug(void *handle, int32_t error, int32_t silent) {
  return snd_pcm_recover(handle, error, silent);
}

canonical_original_code:
int alsaOutRecoverDebug(void *handle, int error, int silent) {
  return snd_pcm_recover(handle, error, silent);
}

variable_types: silent int


alsaOutStart

decompiled_code:
// attributes: thunk
__int64 alsaOutStart()
{
return snd_pcm_start();
}

canonical_decompiled_code:
__int64 func12()
{
return snd_pcm_start();
}

original_code:
int32_t alsaOutStart(void *handle) {
  return snd_pcm_start(handle);
}

canonical_original_code:
int alsaOutStart(void *handle) {
  return snd_pcm_start(handle);
}


alsaOutPause

decompiled_code:
// attributes: thunk
__int64 alsaOutPause()
{
return snd_pcm_pause();
}

canonical_decompiled_code:
__int64 func13()
{
return snd_pcm_pause();
}

original_code:
int32_t alsaOutPause(void *handle, int32_t enable) {
  return snd_pcm_pause(handle, enable);
}

canonical_original_code:
int alsaOutPause(void *handle, int enable) {
  return snd_pcm_pause(handle, enable);
}

variable_types: enable int


alsaOutResume

decompiled_code:
// attributes: thunk
__int64 alsaOutResume()
{
return snd_pcm_resume();
}

canonical_decompiled_code:
__int64 func14()
{
return snd_pcm_resume();
}

original_code:
int32_t alsaOutResume(void *handle) {
  return snd_pcm_resume(handle);
}

canonical_original_code:
int alsaOutResume(void *handle) {
  return snd_pcm_resume(handle);
}


alsaOutDrop

decompiled_code:
// attributes: thunk
__int64 alsaOutDrop()
{
return snd_pcm_drop();
}

canonical_decompiled_code:
__int64 func15()
{
return snd_pcm_drop();
}

original_code:
int32_t alsaOutDrop(void *handle) {
  return snd_pcm_drop(handle);
}

canonical_original_code:
int alsaOutDrop(void *handle) {
  return snd_pcm_drop(handle);
}


alsaOutDrain

decompiled_code:
// attributes: thunk
__int64 alsaOutDrain()
{
return snd_pcm_drain();
}

canonical_decompiled_code:
__int64 func16()
{
return snd_pcm_drain();
}

original_code:
int32_t alsaOutDrain(void *handle) {
  return snd_pcm_drain(handle);
}

canonical_original_code:
int alsaOutDrain(void *handle) {
  return snd_pcm_drain(handle);
}


alsaOutReset

decompiled_code:
// attributes: thunk
__int64 alsaOutReset()
{
return snd_pcm_reset();
}

canonical_decompiled_code:
__int64 func17()
{
return snd_pcm_reset();
}

original_code:
int32_t alsaOutReset(void *handle) {
  return snd_pcm_reset(handle);
}

canonical_original_code:
int alsaOutReset(void *handle) {
  return snd_pcm_reset(handle);
}


alsaOutWait

decompiled_code:
// attributes: thunk
__int64 alsaOutWait()
{
return snd_pcm_wait();
}

canonical_decompiled_code:
__int64 func19()
{
return snd_pcm_wait();
}

original_code:
int32_t alsaOutWait(void *handle, int32_t timeout) {
  return snd_pcm_wait(handle, timeout);
}

canonical_original_code:
int alsaOutWait(void *handle, int timeout) {
  return snd_pcm_wait(handle, timeout);
}

variable_types: timeout int


alsaErrorString

decompiled_code:
// attributes: thunk
__int64 alsaErrorString()
{
return snd_strerror();
}

canonical_decompiled_code:
__int64 func20()
{
return snd_strerror();
}

original_code:
const char *alsaErrorString(int32_t errornum) {
  return snd_strerror(errornum);
}

canonical_original_code:
char *alsaErrorString(int errornum) {
  return snd_strerror(errornum);
}

variable_types: errornum int

return_type: char *


repo: nanley/glawn

decompiled_code:
__int64 __fastcall curl_callback(__int64 a1, __int64 a2, __int64 a3, __int64 a4)
{
return g_strlcpy(a4, a1, 160LL);
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int64 a2, __int64 a3, __int64 a4)
{
return g_strlcpy(a4, a1, 160LL);
}

original_code:
size_t curl_callback (void *buffer, size_t size, size_t nmemb, void *userp)
{
 return g_strlcpy ((char *)userp, (char *)buffer, 160);
}

canonical_original_code:
unsigned long curl_callback(void *buffer, unsigned long size, unsigned long nmemb, void *userp)
{
 return g_strlcpy ((char *)userp, (char *)buffer, 160);
}

variable_types:
size
unsigned long

variable_types:
nmemb
unsigned long

variable_types:
userp
void *


decompiled_code:
__int64 quit_glawn()
{
save_settings();
curl_easy_cleanup(curl);
g_free(buffer);
g_mutex_unlock(GTK_Mutex);
g_mutex_free(GTK_Mutex);
return gtk_main_quit();
}

canonical_decompiled_code:
__int64 func3()
{
save_settings();
curl_easy_cleanup(curl);
g_free(buffer);
g_mutex_unlock(GTK_Mutex);
g_mutex_free(GTK_Mutex);
return gtk_main_quit();
}

original_code:
void quit_glawn ()
{
 save_settings();
 curl_easy_cleanup (curl);
 g_free (buffer);
 g_mutex_unlock(GTK_Mutex);
 g_mutex_free(GTK_Mutex);
 gtk_main_quit ();
}

canonical_original_code:
void quit_glawn()
{
 save_settings();
 curl_easy_cleanup (curl);
 g_free (buffer);
 g_mutex_unlock(GTK_Mutex);
 g_mutex_free(GTK_Mutex);
 gtk_main_quit ();
}


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

if ( GTK_Mutex )
g_assertion_message_expr(0LL, "callbacks.c", 68LL, "init_mutex", "GTK_Mutex == NULL");
result = g_mutex_new();
GTK_Mutex = result;
return result;
}

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

if ( GTK_Mutex )
g_assertion_message_expr(0LL, "callbacks.c", 68LL, "init_mutex", "GTK_Mutex == NULL");
result = g_mutex_new();
GTK_Mutex = result;
return result;
}

original_code:
void init_mutex() {
 do { if (GTK_Mutex == ((void *)0)) ; else g_assertion_message_expr (((gchar*) 0), "callbacks.c", 68, ((const char*) (__func__)), "GTK_Mutex == NULL"); } while (0);
 GTK_Mutex = g_mutex_new();
}

canonical_original_code:
void init_mutex() {
 do { if (GTK_Mutex == ((void *)0)) ; else g_assertion_message_expr (((char *) 0), "callbacks.c", 68, ((char *) (__func__)), "GTK_Mutex == NULL"); } while (0);
 GTK_Mutex = g_mutex_new();
}


decompiled_code:
__int64 init_check_status()
{
int v0; // er8
__int64 result; // rax

v0 = g_mutex_trylock(GTK_Mutex);
result = 1LL;
if ( v0 )
{
update_gui(4LL);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 func5()
{
int v0; // er8
__int64 result; // rax

v0 = g_mutex_trylock(GTK_Mutex);
result = 1LL;
if ( v0 )
{
update_gui(4LL);
result = 0LL;
}
return result;
}

original_code:
int init_check_status() {
 if (g_mutex_trylock(GTK_Mutex)) {
  update_gui (CHECK_STAT_END);
  return (0);
 }
 return (!(0));
}


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

settings = g_key_file_new();
result = g_key_file_load_from_file(settings, "./config/settings.ini", 1LL, 0LL);
if ( !(_DWORD)result )
{
fprintf(stderr, "Can't find settings file: %s\n", "./config/settings.ini");
exit(1);
}
return result;
}

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

settings = g_key_file_new();
result = g_key_file_load_from_file(settings, "./config/settings.ini", 1LL, 0LL);
if ( !(_DWORD)result )
{
fprintf(stderr, "Can't find settings file: %s\n", "./config/settings.ini");
exit(1);
}
return result;
}

original_code:
void load_settings ()
{
 settings = g_key_file_new();
 if (!g_key_file_load_from_file(settings, "./config/settings.ini", G_KEY_FILE_KEEP_COMMENTS, ((void *)0))) {
  fprintf(stderr, "Can't find settings file: %s\n", "./config/settings.ini");
  exit(1);
 }
}

canonical_original_code:
void load_settings()
{
 settings = g_key_file_new();
 if (!g_key_file_load_from_file(settings, "./config/settings.ini", G_KEY_FILE_KEEP_COMMENTS, ((void *)0))) {
  fprintf(stderr, "Can't find settings file: %s\n", "./config/settings.ini");
  exit(1);
 }
}


decompiled_code:
__int64 save_settings()
{
__int64 v0; // rax
__int64 v1; // rax
unsigned int v2; // eax
__int64 v3; // rax

v0 = gtk_toggle_button_get_type();
v1 = g_type_check_instance_cast(data[4], v0);
v2 = gtk_toggle_button_get_active(v1);
g_key_file_set_integer(settings, "config", "current", v2);
v3 = g_key_file_to_data(settings, 0LL, 0LL);
g_file_set_contents("./config/settings.ini", v3, -1LL, 0LL);
return g_key_file_free(settings);
}

canonical_decompiled_code:
__int64 func1()
{
__int64 v0; // rax
__int64 v1; // rax
unsigned int v2; // eax
__int64 v3; // rax

v0 = gtk_toggle_button_get_type();
v1 = g_type_check_instance_cast(data[4], v0);
v2 = gtk_toggle_button_get_active(v1);
g_key_file_set_integer(settings, "config", "current", v2);
v3 = g_key_file_to_data(settings, 0LL, 0LL);
g_file_set_contents("./config/settings.ini", v3, -1LL, 0LL);
return g_key_file_free(settings);
}

original_code:
void save_settings ()
{
 int index = gtk_toggle_button_get_active (((((GtkToggleButton*) g_type_check_instance_cast ((GTypeInstance*) ((data.locCBox)), ((gtk_toggle_button_get_type ())))))));
 g_key_file_set_integer(settings, "config", "current", index);
 gchar *settings_data = g_key_file_to_data(settings, ((void *)0), ((void *)0));
 g_file_set_contents ("./config/settings.ini", settings_data, -1, ((void *)0));
 g_key_file_free(settings);
}

canonical_original_code:
void save_settings()
{
 int index = gtk_toggle_button_get_active (((((GtkToggleButton*) g_type_check_instance_cast ((GTypeInstance*) ((data.locCBox)), ((gtk_toggle_button_get_type ())))))));
 g_key_file_set_integer(settings, "config", "current", index);
 char *settings_data = g_key_file_to_data(settings, ((void *)0), ((void *)0));
 g_file_set_contents ("./config/settings.ini", settings_data, -1, ((void *)0));
 g_key_file_free(settings);
}

variable_types: index int


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

v0 = gtk_toggle_button_get_type();
v1 = g_type_check_instance_cast(data[4], v0);
return locs_0[(int)gtk_toggle_button_get_active(v1)];
}

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

v0 = gtk_toggle_button_get_type();
v1 = g_type_check_instance_cast(data[4], v0);
return locs_0[(int)gtk_toggle_button_get_active(v1)];
}

original_code:
gchar *get_url ()
{
 static gchar *locs[] = {
  "https://auth.lawn.gatech.edu/",
  "https://mower.georgiatech-metz.fr/"
 };
 int index = gtk_toggle_button_get_active (((((GtkToggleButton*) g_type_check_instance_cast ((GTypeInstance*) ((data.locCBox)), ((gtk_toggle_button_get_type ())))))));
 return locs[index];
}

canonical_original_code:
char *get_url()
{
 static char *locs[] = {
  "https://auth.lawn.gatech.edu/",
  "https://mower.georgiatech-metz.fr/"
 };
 int index = gtk_toggle_button_get_active (((((GtkToggleButton*) g_type_check_instance_cast ((GTypeInstance*) ((data.locCBox)), ((gtk_toggle_button_get_type ())))))));
 return locs[index];
}

variable_types:
locs
char *[]


decompiled_code:
__int64 get_url_index()
{
return g_key_file_get_integer(settings, "config", "current", 0LL);
}

canonical_decompiled_code:
__int64 func3()
{
return g_key_file_get_integer(settings, "config", "current", 0LL);
}

original_code:
int get_url_index ()
{
 return g_key_file_get_integer(settings, "config", "current", ((void *)0));
}

canonical_original_code:
int get_url_index()
{
 return g_key_file_get_integer(settings, "config", "current", ((void *)0));
}


decompiled_code:
__int64 __fastcall update_cmd(const char *a1)
{
__int64 result; // rax
const char *v2; // rax

if ( curl_return )
{
v2 = (const char *)curl_easy_strerror();
g_printf("libcurl output: %s\n", v2);
result = g_printf("%s: No reply received\n\n", a1);
}
else
{
g_printf("libcurl output: :)\n");
result = g_printf("%s: %s\n\n", a1, buffer);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(const char *a1)
{
__int64 result; // rax
const char *v2; // rax

if ( curl_return )
{
v2 = (const char *)curl_easy_strerror();
g_printf("libcurl output: %s\n", v2);
result = g_printf("%s: No reply received\n\n", a1);
}
else
{
g_printf("libcurl output: :)\n");
result = g_printf("%s: %s\n\n", a1, buffer);
}
return result;
}

original_code:
void update_cmd (char *custom)
{
 if (curl_return == CURLE_OK) {
  g_printf ("libcurl output: :)\n");
  g_printf ("%s: %s\n\n", custom, buffer);
 } else {
  g_printf ("libcurl output: %s\n", curl_easy_strerror (curl_return));
  g_printf ("%s: No reply received\n\n", custom);
 }
}

canonical_original_code:
void update_cmd(char *custom)
{
 if (curl_return == CURLE_OK) {
  g_printf ("libcurl output: :)\n");
  g_printf ("%s: %s\n\n", custom, buffer);
 } else {
  g_printf ("libcurl output: %s\n", curl_easy_strerror (curl_return));
  g_printf ("%s: No reply received\n\n", custom);
 }
}

variable_types:
custom
char *


repo: nanoant/mjpeg

variable_types:
h
unsigned int

variable_types: version int


decompiled_code:
__int64 __fastcall mp3samplerate(unsigned int a1)
{
int v1; // ecx
int v2; // edx

v1 = 0;
v2 = (a1 >> 19) & 3;
if ( v2 != 3 )
v1 = (v2 != 2) + 1;
return (unsigned int)samplerates[3 * ((a1 >> 10) & 3) + v1];
}

canonical_decompiled_code:
__int64 __fastcall func3(unsigned int a1)
{
int v1; // ecx
int v2; // edx

v1 = 0;
v2 = (a1 >> 19) & 3;
if ( v2 != 3 )
v1 = (v2 != 2) + 1;
return (unsigned int)samplerates[3 * ((a1 >> 10) & 3) + v1];
}

original_code:
int mp3samplerate(mp3header_t h) {
 int index = 2;
 int version = (((h) & 0x180000) >> 19);
 if(version == 3) {
  index = 0;
 } else if(version == 2) {
  index = 1;
 }
 return samplerates[index + (((h) & 0xC00) >> 10) * 3];
}

canonical_original_code:
int mp3samplerate(unsigned int h) {
 int index = 2;
 int version = (((h) & 0x180000) >> 19);
 if(version == 3) {
  index = 0;
 } else if(version == 2) {
  index = 1;
 }
 return samplerates[index + (((h) & 0xC00) >> 10) * 3];
}


decompiled_code:
__int64 __fastcall mp3framesize(unsigned int a1)
{
int v1; // esi
unsigned int v2; // er8
int v3; // ecx
unsigned int v4; // er8
int v5; // edi
__int64 result; // rax

v1 = mp3bitrate(a1);
v3 = mp3samplerate(v2);
v5 = (v4 >> 9) & 1;
if ( ((v4 ^ 0x60000) & 0x60000) != 0 )
result = (unsigned int)(v5 + 144000 * v1 / v3);
else
result = (unsigned int)(4 * (v5 + 12000 * v1 / v3));
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(unsigned int a1)
{
int v1; // esi
unsigned int v2; // er8
int v3; // ecx
unsigned int v4; // er8
int v5; // edi
__int64 result; // rax

v1 = func2(a1);
v3 = func3(v2);
v5 = (v4 >> 9) & 1;
if ( ((v4 ^ 0x60000) & 0x60000) != 0 )
result = (unsigned int)(v5 + 144000 * v1 / v3);
else
result = (unsigned int)(4 * (v5 + 12000 * v1 / v3));
return result;
}

canonical_original_code:
unsigned long mp3framesize(unsigned int h) {
 if((((h) & 0x60000) >> 17) == 3) {
  return (12000 * mp3bitrate(h) / mp3samplerate(h) + (((h) & 0x200) >> 9)) * 4;
 }
 return 144000 * mp3bitrate(h) / mp3samplerate(h) + (((h) & 0x200) >> 9);
}


decompiled_code:
double __fastcall mp3framelength(unsigned int a1)
{
return 1152.0 / (double)(int)mp3samplerate(a1);
}

canonical_decompiled_code:
double __fastcall func5(unsigned int a1)
{
return 1152.0 / (double)(int)func3(a1);
}

original_code:
double mp3framelength(mp3header_t h) {
 return 1152.0 / (double)mp3samplerate(h);
}

canonical_original_code:
double mp3framelength(unsigned int h) {
 return 1152.0 / (double)mp3samplerate(h);
}

return_type: double


fourcc

decompiled_code:
char *__fastcall fourcc(int a1)
{
int v1; // eax
__int64 v2; // rdx

v1 = (rot_1 + 1) % 8;
v2 = 5LL * v1;
rot_1 = v1 + 1;
byte_324[v2] = 0;
*(int *)((char *)&sfcc_0 + v2) = a1;
return (char *)&sfcc_0 + v2;
}

original_code:
const char *fourcc(FOURCC fcc) {
 static char sfcc[8][5];
 static int rot = -1;
 rot = (rot + 1) % 8;
 sfcc[rot][4] = 0;
 *(FOURCC *)sfcc[rot] = fcc;
 return sfcc[rot++];
}

canonical_original_code:
char *fourcc(unsigned int fcc) {
 static char sfcc[8][5];
 static int rot = -1;
 rot = (rot + 1) % 8;
 sfcc[rot][4] = 0;
 *(unsigned int *)sfcc[rot] = fcc;
 return sfcc[rot++];
}

variable_types:
fcc
unsigned int

variable_types:
sfcc
char [8][5]

variable_types: rot int


main

repo: nanocad-lab/vipzone-memallocator

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // eax
int v4; // er12
__int64 v6; // r14
signed int v7; // ebx
char v8; // al
char v9; // al
char v10; // al
__int64 v11; // rbp
unsigned __int64 v12; // r13
__int64 v13; // r14
void *v14; // rax
double v15; // xmm3_8
double v16; // xmm1_8
double v17; // xmm2_8
_QWORD *v18; // r14
unsigned int v19; // er12
int i; // ebx
_QWORD **v21; // rdx
_QWORD *v22; // rax
void **v23; // rbx
void *v24; // rdi
_QWORD *v25; // rsi
__int64 v26; // rcx
__int64 v27; // rdx
_QWORD *v28; // rax
__int64 v29; // rcx
_QWORD *v30; // rax
_QWORD *v31; // rdx
void **k; // rbx
void *v33; // rdi
_QWORD **v34; // rsi
_QWORD *v35; // rdx
int v36; // er15
__int64 j; // r14
__int64 v38; // r9
__int64 v39; // r15
__int64 v40; // rax
__int64 v41; // rax
__int64 v42; // r15
__int64 v43; // rsi
__int64 v44; // rax
int v45; // eax
_QWORD *v46; // r15
__int64 v47; // r14
int v48; // eax
__int64 v49; // [rsp-8h] [rbp-70h]
int v50; // [rsp+4h] [rbp-64h]
int v51; // [rsp+8h] [rbp-60h]
int v52; // [rsp+Ch] [rbp-5Ch]
int v53; // [rsp+10h] [rbp-58h]
__int64 v54; // [rsp+10h] [rbp-58h]
int v55; // [rsp+18h] [rbp-50h]
__int64 v56; // [rsp+18h] [rbp-50h]
__int64 v57; // [rsp+20h] [rbp-48h]
double v58; // [rsp+28h] [rbp-40h]

v3 = time(0LL);
srand(v3);
if ( argc != 7 )
{
v4 = 1;
fwrite(
"Invalid number of arguments: (1) Amount of memory to hog in MB, (2) Number of sleep seconds between iterations, (3"
") Allocator to use (M[malloc], m[mmap], V[vip_malloc], v[vip_mmap]), (4) Access pattern (n[sequential], s[staggere"
"d], r[random]), (5) Write or read (w[write], r[read]) (6) Number of iterations\n",
1uLL,
0x133uLL,
stderr);
return v4;
}
v6 = atol(argv[1]);
printf("will alloc = %lu MB\n", v6);
v7 = atol(argv[2]);
if ( v7 < 0 )
{
v7 = 0;
fwrite("Sleep time was < 0s, setting to 0s.\n", 1uLL, 0x24uLL, stderr);
}
printf("sleep time = %d s\n", (unsigned int)v7);
v8 = *argv[3];
switch ( v8 )
{
case 'v':
v4 = 3;
puts("allocator = vip_mmap");
break;
case 'm':
v4 = 1;
puts("allocator = mmap");
break;
case 'M':
v4 = 0;
puts("allocator = malloc");
break;
case 'V':
v4 = 2;
puts("allocator = vip_malloc");
break;
default:
v4 = 1;
fwrite("Bad allocator choice\n", 1uLL, 0x15uLL, stderr);
return v4;
}
v9 = *argv[4];
switch ( v9 )
{
case 's':
puts("access pattern = staggered");
v50 = 0;
v52 = 1;
break;
case 'r':
puts("access pattern = random");
printf("RAND_MAX = %d\n", 0x7FFFFFFFLL);
v50 = 1;
v52 = 0;
break;
case 'n':
puts("access pattern = sequential");
v50 = 0;
v52 = 0;
break;
default:
v4 = 1;
fwrite("Bad access pattern flag\n", 1uLL, 0x18uLL, stderr);
return v4;
}
v10 = *argv[5];
if ( v10 == 119 )
{
puts("access mode = write");
v53 = 1;
}
else
{
if ( v10 != 114 )
{
v4 = 1;
fwrite("Bad write/read input\n", 1uLL, 0x15uLL, stderr);
return v4;
}
puts("access mode = read");
v53 = 0;
}
v51 = atoi(argv[6]);
if ( v51 <= 0 )
{
fwrite("Number of iterations was < 1, setting to 1\n", 1uLL, 0x2BuLL, stderr);
v51 = 1;
}
printf("num iterations = %d\n", (unsigned int)v51);
puts("\n==============================\n");
if ( v4 != 2 )
{
if ( v4 == 3 )
{
puts("Getting memory pointer array using vip_mmap with vip_flags READ/HI...");
v42 = syscall(312LL, 0LL, 0x2000000LL, 35LL, 34LL, 0xFFFFFFFFLL, 0LL, argv);
v11 = v42;
if ( v42 == -1 )
{
v4 = 1;
puts("Error: Could not allocate page array using vip_mmap (READ/HI). Terminating.");
perror("Failure reason");
return v4;
}
v12 = 0LL;
printf(
"sizeof(val) == %lu\nsizeof(page_array) == %lu\nsizeof(*(page_array)) == %lu\nsizeof(**page_array) == %lu\n",
8LL,
8LL,
8LL,
8LL);
v43 = 4096LL;
printf("PAGE_SIZE == %lu\nwordsPerPage == %lu\n", 4096LL, 512LL);
puts("\n==============================\n");
puts("Hogging memory using vip_mmap with flags WRITE/HI...");
do
{
if ( ((v6 << 8) & 0xFFFFFFFFFFFFFLL) == v12 )
break;
v49 = v43;
v43 = 0LL;
v44 = syscall(312LL, 0LL, 4096LL, 51LL, 34LL, 0xFFFFFFFFLL, 0LL, v49);
*(_QWORD *)(v42 + 8 * v12) = v44;
if ( v44 == -1 )
break;
++v12;
}
while ( v12 != 0x400000 );
v15 = *(double *)&LC29;
v16 = (double)(int)v12;
if ( *(_QWORD *)(v42 + 8 * v12) != -1LL )
goto LABEL_29;
v58 = (double)(int)v12;
v57 = LC29;
v56 = LC30;
printf("Error: Failed to vip_mmap page number %lu, at %0.2f MB.\n", v12, v16 * 4096.0 * 0.00000095367431640625);
}
else
{
if ( v4 != 1 )
{
puts("Getting memory pointer array using malloc...");
v11 = (__int64)malloc(0x2000000uLL);
if ( !v11 )
{
v4 = 1;
puts("Error: Could not allocate page array using malloc. Terminating.");
perror("Failure reason");
return v4;
}
v12 = 0LL;
printf(
"sizeof(val) == %lu\nsizeof(page_array) == %lu\nsizeof(*(page_array)) == %lu\nsizeof(**page_array) == %lu\n",
8LL,
8LL,
8LL,
8LL);
v13 = (v6 << 8) & 0xFFFFFFFFFFFFFLL;
printf("PAGE_SIZE == %lu\nwordsPerPage == %lu\n", 4096LL, 512LL);
puts("\n==============================\n");
puts("Hogging memory using malloc...");
while ( v13 != v12 )
{
v14 = malloc(0x1000uLL);
*(_QWORD *)(v11 + 8 * v12) = v14;
if ( !v14 )
{
v57 = LC29;
v56 = LC30;
v58 = (double)(int)v12;
printf(
"Error: Failed to malloc page number %lu, at %0.2f MB.\n",
v12,
(double)(int)v12 * 4096.0 * 0.00000095367431640625);
goto LABEL_84;
}
if ( ++v12 == 0x400000 )
goto LABEL_28;
}
goto LABEL_28;
}
puts("Getting memory pointer array using mmap...");
v39 = syscall(9LL, 0LL, 0x2000000LL, 3LL, 34LL, 0xFFFFFFFFLL, 0LL, v38);
v11 = v39;
if ( v39 == -1 )
{
puts("Error: Could not allocate page array using mmap. Terminating.");
perror("Failure reason");
return v4;
}
v12 = 0LL;
printf(
"sizeof(val) == %lu\nsizeof(page_array) == %lu\nsizeof(*(page_array)) == %lu\nsizeof(**page_array) == %lu\n",
8LL,
8LL,
8LL,
8LL);
printf("PAGE_SIZE == %lu\nwordsPerPage == %lu\n", 4096LL, 512LL);
puts("\n==============================\n");
LODWORD(v40) = puts("Hogging memory using mmap...");
do
{
if ( ((v6 << 8) & 0xFFFFFFFFFFFFFLL) == v12 )
break;
v41 = syscall(9LL, 0LL, 4096LL, 3LL, 34LL, 0xFFFFFFFFLL, 0LL, v40);
*(_QWORD *)(v39 + 8 * v12) = v41;
v40 = v41 + 1;
if ( !v40 )
break;
++v12;
}
while ( v12 != 0x400000 );
v15 = *(double *)&LC29;
v16 = (double)(int)v12;
if ( *(_QWORD *)(v39 + 8 * v12) != -1LL )
goto LABEL_29;
v58 = (double)(int)v12;
v57 = LC29;
v56 = LC30;
printf("Error: Failed to mmap page number %lu, at %0.2f MB.\n", v12, v16 * 4096.0 * 0.00000095367431640625);
}
LABEL_84:
perror("Failure reason");
v17 = *(double *)&v56;
v15 = *(double *)&v57;
v16 = v58;
goto LABEL_30;
}
puts("Getting memory pointer array using vip_malloc with vip_flags READ/HI...");
v45 = vip_malloc(0x2000000LL, 32LL);
v11 = v45;
if ( !v45 )
{
v4 = 1;
puts("Error: Could not allocate page array using vip_malloc (READ/HI). Terminating.");
perror("Failure reason");
return v4;
}
v46 = (_QWORD *)v45;
v12 = 0LL;
v47 = (v6 << 8) & 0xFFFFFFFFFFFFFLL;
printf(
"sizeof(val) == %lu\nsizeof(page_array) == %lu\nsizeof(*(page_array)) == %lu\nsizeof(**page_array) == %lu\n",
8LL,
8LL,
8LL,
8LL);
printf("PAGE_SIZE == %lu\nwordsPerPage == %lu\n", 4096LL, 512LL);
puts("\n==============================\n");
puts("Hogging memory using vip_malloc...");
while ( v47 != v12 )
{
v48 = vip_malloc(4096LL, 32LL);
*v46 = v48;
if ( !v48 )
{
v57 = LC29;
v56 = LC30;
v58 = (double)(int)v12;
printf(
"Error: Failed to vip_malloc page number %lu, at %0.2f MB.\n",
v12,
(double)(int)v12 * 4096.0 * 0.00000095367431640625);
goto LABEL_84;
}
++v12;
++v46;
if ( v12 == 0x400000 )
break;
}
LABEL_28:
v15 = *(double *)&LC29;
v16 = (double)(int)v12;
LABEL_29:
v17 = *(double *)&LC30;
LABEL_30:
printf(
"We allocated %lu pages == %lu KB == %0.2f MB == %0.2f GB. Done.\n",
v12,
(4 * v12) & 0x3FFFFFFFFFFFFFLL,
v17 * (v16 * v15),
v16 * v15 * 9.313225746154785e-10);
puts("\n==============================\n");
if ( v53 )
{
v18 = (_QWORD *)(v11 + 8 * v12);
printf("Writing pattern: 0x%X %X\n", 0xFFFFFFFFLL, 0xFFFFFFFFLL);
v55 = v4;
v19 = v7;
for ( i = v53; i <= v51; ++i )
{
if ( v50 )
{
v29 = 0LL;
if ( v12 )
{
do
{
v54 = v29;
v30 = *(_QWORD **)(v11 + 8 * (rand() % v12));
v31 = v30 + 512;
do
*v30++ = -1LL;
while ( v31 != v30 );
v29 = v54 + 1;
}
while ( v12 != v54 + 1 );
}
}
else if ( v52 )
{
v25 = (_QWORD *)v11;
if ( v12 )
{
do
{
v26 = 0LL;
v27 = *v25 + 4096LL;
do
{
v28 = (_QWORD *)(v27 - 4096);
do
{
*v28 = -1LL;
v28 += 4;
}
while ( (_QWORD *)v27 != v28 );
++v26;
v27 += 8LL;
}
while ( v26 != 4 );
++v25;
}
while ( v18 != v25 );
}
}
else
{
v21 = (_QWORD **)v11;
if ( v12 )
{
do
{
v22 = *v21++;
*v22 = -1LL;
v22[511] = -1LL;
memset(
(void *)((unsigned __int64)(v22 + 1) & 0xFFFFFFFFFFFFFFF8LL),
0xFFu,
8LL * (((unsigned int)v22 - (((_DWORD)v22 + 8) & 0xFFFFFFF8) + 4096) >> 3));
}
while ( v18 != v21 );
}
}
printf("Finished write iteration %d\n", (unsigned int)i);
if ( v19 )
sleep(v19);
}
v4 = v55;
}
else
{
printf("Initializing memory with pattern: 0x%X %X\n", 0xFFFFFFFFLL, 0xFFFFFFFFLL);
v34 = (_QWORD **)v11;
while ( v34 != (_QWORD **)(v11 + 8 * v12) )
{
v35 = *v34++;
*v35 = -1LL;
v35[511] = -1LL;
memset(
(void *)((unsigned __int64)(v35 + 1) & 0xFFFFFFFFFFFFFFF8LL),
0xFFu,
8LL * (((unsigned int)v35 - (((_DWORD)v35 + 8) & 0xFFFFFFF8) + 4096) >> 3));
}
v36 = 1;
puts("Reading...");
do
{
if ( v50 && v12 )
{
for ( j = 0LL; j != v12; ++j )
rand();
}
printf("Finished read iteration %d\n", (unsigned int)v36);
if ( v7 )
sleep(v7);
++v36;
}
while ( v51 >= v36 );
}
puts("Freeing memory...");
if ( (unsigned int)(v4 - 1) <= 1 )
{
for ( k = (void **)v11; (void **)(v11 + 8 * v12) != k; ++k )
{
v33 = *k;
munmap(v33, 0x1000uLL);
}
munmap((void *)v11, 0x400000uLL);
}
else
{
if ( v12 )
{
v23 = (void **)v11;
do
{
v24 = *v23++;
free(v24);
}
while ( (void **)(v11 + 8 * v12) != v23 );
}
free((void *)v11);
}
v4 = 0;
puts("Done.");
return v4;
}

original_code:
int main(const int argc, const char *argv[]) {
 unsigned long MB_to_alloc = 0;
 unsigned long page = 0;
 unsigned long total_pages = 0;
 unsigned long val = 0;
 unsigned long word = 0;
 unsigned long **page_array = ((void *)0);
 int allocator_choice = 0;
 int stagger = 0;
 int staggerFlag = 0;
 int randomFlag = 0;
 unsigned long pageCount = 0;
 unsigned long wordsPerPage = 4096/sizeof(val);
 int writeFlag = 0;
 int sleepTime = 0;
 int numIters = 0;
 int iter = 1;
 srand(time(((void *)0)));
 if (argc != 7) {
  fprintf(stderr, "Invalid number of arguments: (1) Amount of memory to hog in MB, (2) Number of sleep seconds between iterations, (3) Allocator to use (M[malloc], m[mmap], V[vip_malloc], v[vip_mmap]), (4) Access pattern (n[sequential], s[staggered], r[random]), (5) Write or read (w[write], r[read]) (6) Number of iterations\n");
  return 1;
 }
 MB_to_alloc = (unsigned long) atol(argv[1]);
 printf("will alloc = %lu MB\n", MB_to_alloc);
 sleepTime = (int) atol(argv[2]);
 if (sleepTime < 0) {
  fprintf(stderr, "Sleep time was < 0s, setting to 0s.\n");
  sleepTime = 0;
 }
 printf("sleep time = %d s\n", sleepTime);
 if (argv[3][0] == 'v') {
  allocator_choice = 3;
  printf("allocator = vip_mmap\n");
 } else if (argv[3][0] == 'm') {
  allocator_choice = 1;
  printf("allocator = mmap\n");
 } else if (argv[3][0] == 'M') {
  allocator_choice = 0;
  printf("allocator = malloc\n");
 } else if (argv[3][0] == 'V' ) {
  allocator_choice = 2;
  printf("allocator = vip_malloc\n");
 } else {
  fprintf(stderr, "Bad allocator choice\n");
  return 1;
 }
 if (argv[4][0] == 's') {
  staggerFlag = 1;
  printf("access pattern = staggered\n");
 } else if (argv[4][0] == 'r') {
  randomFlag = 1;
  printf("access pattern = random\n");
  printf("RAND_MAX = %d\n", 2147483647);
 } else if (argv[4][0] == 'n') {
  printf("access pattern = sequential\n");
  randomFlag = 0;
  staggerFlag = 0;
 } else {
  fprintf(stderr, "Bad access pattern flag\n");
  return 1;
 }
 if (argv[5][0] == 'w') {
  writeFlag = 1;
  printf("access mode = write\n");
 } else if (argv[5][0] == 'r') {
  writeFlag = 0;
  printf("access mode = read\n");
 } else {
  fprintf(stderr, "Bad write/read input\n");
  return 1;
 }
 numIters = (int)atoi(argv[6]);
 if (numIters < 1) {
  fprintf(stderr, "Number of iterations was < 1, setting to 1\n");
  numIters = 1;
 }
 printf("num iterations = %d\n", numIters);
 printf("\n==============================\n\n");
 val = 0xFFFFFFFFFFFFFFFF;
 if (allocator_choice == 2) {
  printf("Getting memory pointer array using vip_malloc with vip_flags READ/HI...\n");
  if (!(page_array = vip_malloc(4194304*sizeof(unsigned long *), 0x0000 | 0x0020))) {
   printf("Error: Could not allocate page array using vip_malloc (READ/HI). Terminating.\n");
   perror("Failure reason");
   return 1;
  }
  } else if (allocator_choice == 3) {
  printf("Getting memory pointer array using vip_mmap with vip_flags READ/HI...\n");
  page_array = (unsigned long **) syscall(312, ((void *)0), 4194304*sizeof(unsigned long *), (0x1 | 0x2 | 0x0000 | 0x0020), (0x20 | 0x02), -1, 0);
  if (page_array == ((void *) -1)) {
   printf("Error: Could not allocate page array using vip_mmap (READ/HI). Terminating.\n");
   perror("Failure reason");
   return 1;
  }
 } else if (allocator_choice == 1) {
  printf("Getting memory pointer array using mmap...\n");
  page_array = (unsigned long **) syscall(9, ((void *)0), 4194304*sizeof(unsigned long *), (0x1 | 0x2), (0x20 | 0x02), -1, 0);
  if (page_array == ((void *) -1)) {
   printf("Error: Could not allocate page array using mmap. Terminating.\n");
   perror("Failure reason");
   return 1;
  }
 } else {
  printf("Getting memory pointer array using malloc...\n");
  if (!(page_array = malloc(4194304*sizeof(unsigned long *)))) {
   printf("Error: Could not allocate page array using malloc. Terminating.\n");
   perror("Failure reason");
   return 1;
  }
 }
 printf("sizeof(val) == %lu\nsizeof(page_array) == %lu\nsizeof(*(page_array)) == %lu\nsizeof(**page_array) == %lu\n", sizeof(val), sizeof(page_array), sizeof(*page_array), sizeof(**page_array));
 printf("PAGE_SIZE == %lu\nwordsPerPage == %lu\n", (unsigned long) 4096, (unsigned long) wordsPerPage);
 printf("\n==============================\n\n");
 if (allocator_choice == 2) {
  printf("Hogging memory using vip_malloc...\n");
  while ((page < 4194304) && (page < MB_to_alloc*1024*1024/4096)) {
   *(page_array+page) = vip_malloc(4096, 0x0000 | 0x0020);
   if (*(page_array+page) == ((void *)0)) {
    printf("Error: Failed to vip_malloc page number %lu, at %0.2f MB.\n", page, (double)page*4096/(1024*1024));
    perror("Failure reason");
    break;
   }
   page++;
  }
 } else if (allocator_choice == 3) {
  printf("Hogging memory using vip_mmap with flags WRITE/HI...\n");
  while ((page < 4194304) && (page < MB_to_alloc*1024*1024/4096) && (*(page_array+page) = (unsigned long *) syscall(312, ((void *)0), 4096, (0x1 | 0x2 | 0x0010 | 0x0020), (0x20 | 0x02), -1, 0)) != ((void *) -1))
   page++;
  if (*(page_array+page) == ((void *) -1)) {
   printf("Error: Failed to vip_mmap page number %lu, at %0.2f MB.\n", page, (double)page*4096/(1024*1024));
   perror("Failure reason");
  }
 } else if (allocator_choice == 1) {
  printf("Hogging memory using mmap...\n");
  while ((page < 4194304) && (page < MB_to_alloc*1024*1024/4096) && (*(page_array+page) = (unsigned long *) syscall(9, ((void *)0), 4096, (0x1 | 0x2), (0x20 | 0x02), -1, 0)) != ((void *) -1))
   page++;
  if (*(page_array+page) == ((void *) -1)) {
   printf("Error: Failed to mmap page number %lu, at %0.2f MB.\n", page, (double)page*4096/(1024*1024));
   perror("Failure reason");
  }
 } else {
  printf("Hogging memory using malloc...\n");
  while ((page < 4194304) && (page < MB_to_alloc*1024*1024/4096)) {
   *(page_array+page) = malloc(4096);
   if (*(page_array+page) == ((void *)0)) {
    printf("Error: Failed to malloc page number %lu, at %0.2f MB.\n", page, (double)page*4096/(1024*1024));
    perror("Failure reason");
    break;
   }
   page++;
  }
 }
 total_pages = page;
 printf("We allocated %lu pages == %lu KB == %0.2f MB == %0.2f GB. Done.\n", total_pages, total_pages*4096/1024, (double)total_pages*4096/(1024*1024), (double)total_pages*4096/(1024*1024*1024));
 printf("\n==============================\n\n");
 if (writeFlag) {
  printf("Writing pattern: 0x%X %X\n", (unsigned int) (val>>32), (unsigned int) val);
  for (iter = 1; iter <= numIters; iter++) {
   if (randomFlag) {
    for (pageCount = 0; pageCount < total_pages; pageCount++) {
     page = rand() % total_pages;
     for (word = 0; word < wordsPerPage; word++) {
      *(*(page_array+page)+word) = val;
     }
    }
   }
   else if (staggerFlag) {
    for (page = 0; page < total_pages; page++) {
     for (stagger = 0; stagger < 4; stagger++)
      for (word = 0; word < wordsPerPage; word=word+4) {
       *(*(page_array+page)+stagger+word) = val;
      }
    }
   }
   else {
    for (page = 0; page < total_pages; page++)
     for (word = 0; word < wordsPerPage; word++) {
      *(*(page_array+page)+word) = val;
     }
   }
   printf("Finished write iteration %d\n", iter);
   if (sleepTime > 0)
    sleep(sleepTime);
  }
 }
 else {
  printf("Initializing memory with pattern: 0x%X %X\n", (unsigned int) (val>>32), (unsigned int) val);
  for (page = 0; page < total_pages; page++)
   for (word = 0; word < wordsPerPage; word++)
    *(*(page_array+page)+word) = val;
  printf("Reading...\n");
  for (iter = 1; iter <= numIters; iter++) {
   if (randomFlag) {
    for (pageCount = 0; pageCount < total_pages; pageCount++) {
     page = rand() % total_pages;
     for (word = 0; word < wordsPerPage; word++) {
      val = *(*(page_array+page)+word);
     }
    }
   }
   else if (staggerFlag) {
    for (page = 0; page < total_pages; page++) {
     for (stagger = 0; stagger < 4; stagger++)
      for (word = 0; word < wordsPerPage; word=word+4) {
       val = *(*(page_array+page)+stagger+word);
       }
    }
   }
   else {
    for (page = 0; page < total_pages; page++)
     for (word = 0; word < wordsPerPage; word++) {
      val = *(*(page_array+page)+word);
     }
   }
   printf("Finished read iteration %d\n", iter);
   if (sleepTime > 0)
    sleep(sleepTime);
  }
 }
 printf("Freeing memory...\n");
 if (allocator_choice == 1 || allocator_choice == 2) {
  for (page = 0; page < total_pages; page++)
   munmap(*(page_array+page), 4096);
  munmap(page_array, 4194304);
 } else {
  for (page = 0; page < total_pages; page++)
   free(*(page_array+page));
  free(page_array);
 }
 printf("Done.\n");
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[]) {
 unsigned long MB_to_alloc = 0;
 unsigned long page = 0;
 unsigned long total_pages = 0;
 unsigned long val = 0;
 unsigned long word = 0;
 unsigned long **page_array = ((void *)0);
 int allocator_choice = 0;
 int stagger = 0;
 int staggerFlag = 0;
 int randomFlag = 0;
 unsigned long pageCount = 0;
 unsigned long wordsPerPage = 4096/sizeof(val);
 int writeFlag = 0;
 int sleepTime = 0;
 int numIters = 0;
 int iter = 1;
 srand(time(((void *)0)));
 if (argc != 7) {
  fprintf(stderr, "Invalid number of arguments: (1) Amount of memory to hog in MB, (2) Number of sleep seconds between iterations, (3) Allocator to use (M[malloc], m[mmap], V[vip_malloc], v[vip_mmap]), (4) Access pattern (n[sequential], s[staggered], r[random]), (5) Write or read (w[write], r[read]) (6) Number of iterations\n");
  return 1;
 }
 MB_to_alloc = (unsigned long) atol(argv[1]);
 printf("will alloc = %lu MB\n", MB_to_alloc);
 sleepTime = (int) atol(argv[2]);
 if (sleepTime < 0) {
  fprintf(stderr, "Sleep time was < 0s, setting to 0s.\n");
  sleepTime = 0;
 }
 printf("sleep time = %d s\n", sleepTime);
 if (argv[3][0] == 'v') {
  allocator_choice = 3;
  printf("allocator = vip_mmap\n");
 } else if (argv[3][0] == 'm') {
  allocator_choice = 1;
  printf("allocator = mmap\n");
 } else if (argv[3][0] == 'M') {
  allocator_choice = 0;
  printf("allocator = malloc\n");
 } else if (argv[3][0] == 'V' ) {
  allocator_choice = 2;
  printf("allocator = vip_malloc\n");
 } else {
  fprintf(stderr, "Bad allocator choice\n");
  return 1;
 }
 if (argv[4][0] == 's') {
  staggerFlag = 1;
  printf("access pattern = staggered\n");
 } else if (argv[4][0] == 'r') {
  randomFlag = 1;
  printf("access pattern = random\n");
  printf("RAND_MAX = %d\n", 2147483647);
 } else if (argv[4][0] == 'n') {
  printf("access pattern = sequential\n");
  randomFlag = 0;
  staggerFlag = 0;
 } else {
  fprintf(stderr, "Bad access pattern flag\n");
  return 1;
 }
 if (argv[5][0] == 'w') {
  writeFlag = 1;
  printf("access mode = write\n");
 } else if (argv[5][0] == 'r') {
  writeFlag = 0;
  printf("access mode = read\n");
 } else {
  fprintf(stderr, "Bad write/read input\n");
  return 1;
 }
 numIters = (int)atoi(argv[6]);
 if (numIters < 1) {
  fprintf(stderr, "Number of iterations was < 1, setting to 1\n");
  numIters = 1;
 }
 printf("num iterations = %d\n", numIters);
 printf("\n==============================\n\n");
 val = 0xFFFFFFFFFFFFFFFF;
 if (allocator_choice == 2) {
  printf("Getting memory pointer array using vip_malloc with vip_flags READ/HI...\n");
  if (!(page_array = vip_malloc(4194304*sizeof(unsigned long *), 0x0000 | 0x0020))) {
   printf("Error: Could not allocate page array using vip_malloc (READ/HI). Terminating.\n");
   perror("Failure reason");
   return 1;
  }
  } else if (allocator_choice == 3) {
  printf("Getting memory pointer array using vip_mmap with vip_flags READ/HI...\n");
  page_array = (unsigned long **) syscall(312, ((void *)0), 4194304*sizeof(unsigned long *), (0x1 | 0x2 | 0x0000 | 0x0020), (0x20 | 0x02), -1, 0);
  if (page_array == ((void *) -1)) {
   printf("Error: Could not allocate page array using vip_mmap (READ/HI). Terminating.\n");
   perror("Failure reason");
   return 1;
  }
 } else if (allocator_choice == 1) {
  printf("Getting memory pointer array using mmap...\n");
  page_array = (unsigned long **) syscall(9, ((void *)0), 4194304*sizeof(unsigned long *), (0x1 | 0x2), (0x20 | 0x02), -1, 0);
  if (page_array == ((void *) -1)) {
   printf("Error: Could not allocate page array using mmap. Terminating.\n");
   perror("Failure reason");
   return 1;
  }
 } else {
  printf("Getting memory pointer array using malloc...\n");
  if (!(page_array = malloc(4194304*sizeof(unsigned long *)))) {
   printf("Error: Could not allocate page array using malloc. Terminating.\n");
   perror("Failure reason");
   return 1;
  }
 }
 printf("sizeof(val) == %lu\nsizeof(page_array) == %lu\nsizeof(*(page_array)) == %lu\nsizeof(**page_array) == %lu\n", sizeof(val), sizeof(page_array), sizeof(*page_array), sizeof(**page_array));
 printf("PAGE_SIZE == %lu\nwordsPerPage == %lu\n", (unsigned long) 4096, (unsigned long) wordsPerPage);
 printf("\n==============================\n\n");
 if (allocator_choice == 2) {
  printf("Hogging memory using vip_malloc...\n");
  while ((page < 4194304) && (page < MB_to_alloc*1024*1024/4096)) {
   *(page_array+page) = vip_malloc(4096, 0x0000 | 0x0020);
   if (*(page_array+page) == ((void *)0)) {
    printf("Error: Failed to vip_malloc page number %lu, at %0.2f MB.\n", page, (double)page*4096/(1024*1024));
    perror("Failure reason");
    break;
   }
   page++;
  }
 } else if (allocator_choice == 3) {
  printf("Hogging memory using vip_mmap with flags WRITE/HI...\n");
  while ((page < 4194304) && (page < MB_to_alloc*1024*1024/4096) && (*(page_array+page) = (unsigned long *) syscall(312, ((void *)0), 4096, (0x1 | 0x2 | 0x0010 | 0x0020), (0x20 | 0x02), -1, 0)) != ((void *) -1))
   page++;
  if (*(page_array+page) == ((void *) -1)) {
   printf("Error: Failed to vip_mmap page number %lu, at %0.2f MB.\n", page, (double)page*4096/(1024*1024));
   perror("Failure reason");
  }
 } else if (allocator_choice == 1) {
  printf("Hogging memory using mmap...\n");
  while ((page < 4194304) && (page < MB_to_alloc*1024*1024/4096) && (*(page_array+page) = (unsigned long *) syscall(9, ((void *)0), 4096, (0x1 | 0x2), (0x20 | 0x02), -1, 0)) != ((void *) -1))
   page++;
  if (*(page_array+page) == ((void *) -1)) {
   printf("Error: Failed to mmap page number %lu, at %0.2f MB.\n", page, (double)page*4096/(1024*1024));
   perror("Failure reason");
  }
 } else {
  printf("Hogging memory using malloc...\n");
  while ((page < 4194304) && (page < MB_to_alloc*1024*1024/4096)) {
   *(page_array+page) = malloc(4096);
   if (*(page_array+page) == ((void *)0)) {
    printf("Error: Failed to malloc page number %lu, at %0.2f MB.\n", page, (double)page*4096/(1024*1024));
    perror("Failure reason");
    break;
   }
   page++;
  }
 }
 total_pages = page;
 printf("We allocated %lu pages == %lu KB == %0.2f MB == %0.2f GB. Done.\n", total_pages, total_pages*4096/1024, (double)total_pages*4096/(1024*1024), (double)total_pages*4096/(1024*1024*1024));
 printf("\n==============================\n\n");
 if (writeFlag) {
  printf("Writing pattern: 0x%X %X\n", (unsigned int) (val>>32), (unsigned int) val);
  for (iter = 1; iter <= numIters; iter++) {
   if (randomFlag) {
    for (pageCount = 0; pageCount < total_pages; pageCount++) {
     page = rand() % total_pages;
     for (word = 0; word < wordsPerPage; word++) {
      *(*(page_array+page)+word) = val;
     }
    }
   }
   else if (staggerFlag) {
    for (page = 0; page < total_pages; page++) {
     for (stagger = 0; stagger < 4; stagger++)
      for (word = 0; word < wordsPerPage; word=word+4) {
       *(*(page_array+page)+stagger+word) = val;
      }
    }
   }
   else {
    for (page = 0; page < total_pages; page++)
     for (word = 0; word < wordsPerPage; word++) {
      *(*(page_array+page)+word) = val;
     }
   }
   printf("Finished write iteration %d\n", iter);
   if (sleepTime > 0)
    sleep(sleepTime);
  }
 }
 else {
  printf("Initializing memory with pattern: 0x%X %X\n", (unsigned int) (val>>32), (unsigned int) val);
  for (page = 0; page < total_pages; page++)
   for (word = 0; word < wordsPerPage; word++)
    *(*(page_array+page)+word) = val;
  printf("Reading...\n");
  for (iter = 1; iter <= numIters; iter++) {
   if (randomFlag) {
    for (pageCount = 0; pageCount < total_pages; pageCount++) {
     page = rand() % total_pages;
     for (word = 0; word < wordsPerPage; word++) {
      val = *(*(page_array+page)+word);
     }
    }
   }
   else if (staggerFlag) {
    for (page = 0; page < total_pages; page++) {
     for (stagger = 0; stagger < 4; stagger++)
      for (word = 0; word < wordsPerPage; word=word+4) {
       val = *(*(page_array+page)+stagger+word);
       }
    }
   }
   else {
    for (page = 0; page < total_pages; page++)
     for (word = 0; word < wordsPerPage; word++) {
      val = *(*(page_array+page)+word);
     }
   }
   printf("Finished read iteration %d\n", iter);
   if (sleepTime > 0)
    sleep(sleepTime);
  }
 }
 printf("Freeing memory...\n");
 if (allocator_choice == 1 || allocator_choice == 2) {
  for (page = 0; page < total_pages; page++)
   munmap(*(page_array+page), 4096);
  munmap(page_array, 4194304);
 } else {
  for (page = 0; page < total_pages; page++)
   free(*(page_array+page));
  free(page_array);
 }
 printf("Done.\n");
 return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types:
page
unsigned long

variable_types:
val
unsigned long

variable_types:
word
unsigned long

variable_types: stagger int

variable_types: staggerFlag int

variable_types: randomFlag int

variable_types:
pageCount
unsigned long

variable_types:
wordsPerPage
unsigned long

variable_types: writeFlag int

variable_types: sleepTime int

variable_types: numIters int

variable_types: iter int


repo: nanpuyue/openwrt-extra

decompiled_code:
__int64 __fastcall mb_num_chars(char a1)
{
if ( (a1 & 0xE0) == 0xC0 )
return 2LL;
if ( (a1 & 0xF0) == 0xE0 )
return 3LL;
if ( (a1 & 0xF8) == 0xF0 )
return 4LL;
if ( (a1 & 0xFC) == 0xF8 )
return 5LL;
return 5 * (unsigned int)((a1 & 0xFE) == 0xFC) + 1;
}

canonical_decompiled_code:
__int64 __fastcall func0(char a1)
{
if ( (a1 & 0xE0) == 0xC0 )
return 2LL;
if ( (a1 & 0xF0) == 0xE0 )
return 3LL;
if ( (a1 & 0xF8) == 0xF0 )
return 4LL;
if ( (a1 & 0xFC) == 0xF8 )
return 5LL;
return 5 * (unsigned int)((a1 & 0xFE) == 0xFC) + 1;
}

original_code:
static inline int mb_num_chars(unsigned char c)
{
 if ((c & 0xE0) == 0xC0)
  return 2;
 else if ((c & 0xF0) == 0xE0)
  return 3;
 else if ((c & 0xF8) == 0xF0)
  return 4;
 else if ((c & 0xFC) == 0xF8)
  return 5;
 else if ((c & 0xFE) == 0xFC)
  return 6;
 return 1;
}

variable_types:
c
unsigned char


decompiled_code:
_BOOL8 __fastcall mb_is_cont(char a1)
{
return (unsigned __int8)(a1 + 0x80) <= 0x3Fu;
}

canonical_decompiled_code:
_BOOL8 __fastcall func1(char a1)
{
return (unsigned __int8)(a1 + 0x80) <= 0x3Fu;
}

original_code:
static inline int mb_is_cont(unsigned char c)
{
 return ((c >= 0x80) && (c <= 0xBF));
}


variable_types:
s
unsigned char *

variable_types: n int


decompiled_code:
_BOOL8 __fastcall mb_is_surrogate(_BYTE *a1, int a2)
{
_BOOL8 result; // rax

result = 0LL;
if ( a2 == 3 && *a1 == 0xED )
result = (unsigned __int8)(a1[1] + 96) <= 0x1Fu;
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func3(_BYTE *a1, int a2)
{
_BOOL8 result; // rax

result = 0LL;
if ( a2 == 3 && *a1 == 0xED )
result = (unsigned __int8)(a1[1] + 96) <= 0x1Fu;
return result;
}

original_code:
static inline int mb_is_surrogate(unsigned char *s, int n)
{
 return ((n == 3) && (*s == 0xED) && (*(s+1) >= 0xA0) && (*(s+1) <= 0xBF));
}


decompiled_code:
_BOOL8 __fastcall mb_is_illegal(_BYTE *a1, int a2)
{
_BOOL8 result; // rax

result = 0LL;
if ( a2 == 3 && *a1 == 0xEF && a1[1] == 0xBF )
result = (unsigned __int8)(a1[2] + 66) <= 1u;
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func4(_BYTE *a1, int a2)
{
_BOOL8 result; // rax

result = 0LL;
if ( a2 == 3 && *a1 == 0xEF && a1[1] == 0xBF )
result = (unsigned __int8)(a1[2] + 66) <= 1u;
return result;
}

original_code:
static inline int mb_is_illegal(unsigned char *s, int n)
{
 return ((n == 3) && (*s == 0xEF) && (*(s+1) == 0xBF) &&
   (*(s+2) >= 0xBE) && (*(s+2) <= 0xBF));
}


original_code:
int buf_grow(struct template_buffer *buf, int size)
{
 unsigned int off = (buf->dptr - buf->data);
 char *data;
 if (size <= 0)
  size = 1024;
 data = realloc(buf->data, buf->size + size);
 if (data != ((void *)0))
 {
  buf->data = data;
  buf->dptr = data + off;
  buf->size += size;
  return buf->size;
 }
 return 0;
}

variable_types: struct template_buffer { char *data; char *dptr; unsigned int size; unsigned int fill; } *

variable_types: size int

variable_types:
off
unsigned int

variable_types:
data
char *


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

if ( (unsigned int)(*(_DWORD *)(a1 + 20) + 1) < *(_DWORD *)(a1 + 16) || (result = buf_grow(a1, 0), (_DWORD)result) )
{
v2 = *(_BYTE **)(a1 + 8);
*(_QWORD *)(a1 + 8) = v2 + 1;
*v2 = a2;
**(_BYTE **)(a1 + 8) = 0;
result = 1LL;
++*(_DWORD *)(a1 + 20);
}
return result;
}

original_code:
int buf_putchar(struct template_buffer *buf, char c)
{
 if( ((buf->fill + 1) >= buf->size) && !buf_grow(buf, 0) )
  return 0;
 *(buf->dptr++) = c;
 *(buf->dptr) = 0;
 buf->fill++;
 return 1;
}

variable_types: c char

user_defined_types: struct template_buffer { char *data; char *dptr; unsigned int size; unsigned int fill; }


decompiled_code:
__int64 __fastcall buf_append(__int64 a1, const void *a2, unsigned int a3)
{
__int64 result; // rax
_BYTE *v5; // r12

if ( a3 + 1 + *(_DWORD *)(a1 + 20) < *(_DWORD *)(a1 + 16) || (result = buf_grow(a1, a3 + 1), (_DWORD)result) )
{
memcpy(*(void **)(a1 + 8), a2, (int)a3);
v5 = (_BYTE *)(*(_QWORD *)(a1 + 8) + (int)a3);
*(_DWORD *)(a1 + 20) += a3;
result = a3;
*(_QWORD *)(a1 + 8) = v5;
*v5 = 0;
}
return result;
}

original_code:
int buf_append(struct template_buffer *buf, const char *s, int len)
{
 if ((buf->fill + len + 1) >= buf->size)
 {
  if (!buf_grow(buf, len + 1))
   return 0;
 }
 memcpy(buf->dptr, s, len);
 buf->fill += len;
 buf->dptr += len;
 *(buf->dptr) = 0;
 return len;
}

canonical_original_code:
int buf_append(struct template_buffer *buf, char *s, int len)
{
 if ((buf->fill + len + 1) >= buf->size)
 {
  if (!buf_grow(buf, len + 1))
   return 0;
 }
 memcpy(buf->dptr, s, len);
 buf->fill += len;
 buf->dptr += len;
 *(buf->dptr) = 0;
 return len;
}

variable_types:
s
char *

variable_types: len int


decompiled_code:
__int64 __fastcall buf_length(__int64 a1)
{
return *(unsigned int *)(a1 + 20);
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1)
{
return *(unsigned int *)(a1 + 20);
}

original_code:
int buf_length(struct template_buffer *buf)
{
 return buf->fill;
}


decompiled_code:
__int64 __fastcall buf_destroy(__int64 *a1)
{
__int64 v1; // r12

v1 = *a1;
free(a1);
return v1;
}

original_code:
char * buf_destroy(struct template_buffer *buf)
{
 char *data = buf->data;
 free(buf);
 return data;
}

canonical_original_code:
char *buf_destroy(struct template_buffer *buf)
{
 char *data = buf->data;
 free(buf);
 return data;
}


striptags

decompiled_code:
__int64 __fastcall striptags(unsigned __int8 *a1, unsigned int a2)
{
unsigned __int8 *v2; // rbx
unsigned __int64 v3; // r12
__int64 *v4; // r14
__int64 v5; // r15
__int64 v6; // r13
const unsigned __int16 *v7; // rax
__int64 v8; // rcx
unsigned __int64 v9; // rbp
int v10; // eax
unsigned __int8 *v12; // rbp
const unsigned __int16 **v13; // rax
__int64 v14; // rdx
unsigned __int8 v15; // [rsp+Fh] [rbp-49h]
char s[64]; // [rsp+18h] [rbp-40h] BYREF

v2 = a1;
v3 = (unsigned __int64)&a1[a2];
v4 = buf_init(a2);
if ( (unsigned __int64)a1 < v3 )
{
v5 = 0x500000C400000000LL;
v6 = 32LL;
while ( 1 )
{
v9 = *v2;
if ( (_BYTE)v9 == 60 )
{
if ( v3 <= (unsigned __int64)(v2 + 2) )
{
v7 = *_ctype_b_loc();
}
else if ( v2[1] == 47 || (v15 = v2[1], v7 = *_ctype_b_loc(), (v7[v15] & 0x400) != 0) )
{
v12 = v2;
if ( v3 > (unsigned __int64)v2 )
{
while ( (unsigned __int8 *)v3 != ++v12 )
{
if ( *v12 == 62 )
{
v13 = _ctype_b_loc();
v14 = (unsigned __int8)v6;
v2 = v12;
v6 = 32LL;
if ( ((*v13)[v14] & 0x2000) == 0 )
buf_putchar((__int64)v4, 32);
goto LABEL_8;
}
}
}
goto LABEL_8;
}
v8 = 60LL;
if ( (*((_BYTE *)v7 + 121) & 0x20) == 0 )
{
LABEL_14:
v10 = snprintf(s, 8uLL, "&#%i;", v8);
buf_append((__int64)v4, s, v10);
goto LABEL_7;
}
LABEL_15:
if ( (v7[v6] & 0x2000) == 0 )
{
buf_putchar((__int64)v4, v9);
LOBYTE(v9) = *v2;
}
++v2;
v6 = (unsigned __int8)v9;
if ( v3 <= (unsigned __int64)v2 )
return buf_destroy(v4);
}
else
{
v7 = *_ctype_b_loc();
if ( (v7[(unsigned __int8)v9] & 0x2000) != 0 )
goto LABEL_15;
if ( (unsigned __int8)v9 <= 0x3Eu )
{
v8 = (unsigned __int8)v9;
if ( _bittest64(&v5, v9) )
goto LABEL_14;
}
buf_putchar((__int64)v4, v9);
LABEL_7:
v6 = *v2;
LABEL_8:
if ( v3 <= (unsigned __int64)++v2 )
return buf_destroy(v4);
}
}
}
return buf_destroy(v4);
}

original_code:
char * striptags(const char *s, unsigned int l)
{
 struct template_buffer *buf = buf_init(l);
 unsigned char *ptr = (unsigned char *)s;
 unsigned char *end = ptr + l;
 unsigned char *tag;
 unsigned char prev;
 char esq[8];
 int esl;
 for (prev = ' '; ptr < end; ptr++)
 {
  if ((*ptr == '<') && ((ptr + 2) < end) &&
   ((*(ptr + 1) == '/') || ((*__ctype_b_loc ())[(int) ((*(ptr + 1)))] & (unsigned short int) _ISalpha)))
  {
   for (tag = ptr; tag < end; tag++)
   {
    if (*tag == '>')
    {
     if (!((*__ctype_b_loc ())[(int) ((prev))] & (unsigned short int) _ISspace))
      buf_putchar(buf, ' ');
     ptr = tag;
     prev = ' ';
     break;
    }
   }
  }
  else if (((*__ctype_b_loc ())[(int) ((*ptr))] & (unsigned short int) _ISspace))
  {
   if (!((*__ctype_b_loc ())[(int) ((prev))] & (unsigned short int) _ISspace))
    buf_putchar(buf, *ptr);
   prev = *ptr;
  }
  else
  {
   switch(*ptr)
   {
    case '"':
    case '\'':
    case '<':
    case '>':
    case '&':
     esl = snprintf(esq, sizeof(esq), "&#%i;", *ptr);
     buf_append(buf, esq, esl);
     break;
    default:
     buf_putchar(buf, *ptr);
     break;
   }
   prev = *ptr;
  }
 }
 return buf_destroy(buf);
}

canonical_original_code:
char *striptags(char *s, unsigned int l)
{
 struct template_buffer *buf = buf_init(l);
 unsigned char *ptr = (unsigned char *)s;
 unsigned char *end = ptr + l;
 unsigned char *tag;
 unsigned char prev;
 char esq[8];
 int esl;
 for (prev = ' '; ptr < end; ptr++)
 {
  if ((*ptr == '<') && ((ptr + 2) < end) &&
   ((*(ptr + 1) == '/') || ((*__ctype_b_loc ())[(int) ((*(ptr + 1)))] & (unsigned short) _ISalpha)))
  {
   for (tag = ptr; tag < end; tag++)
   {
    if (*tag == '>')
    {
     if (!((*__ctype_b_loc ())[(int) ((prev))] & (unsigned short) _ISspace))
      buf_putchar(buf, ' ');
     ptr = tag;
     prev = ' ';
     break;
    }
   }
  }
  else if (((*__ctype_b_loc ())[(int) ((*ptr))] & (unsigned short) _ISspace))
  {
   if (!((*__ctype_b_loc ())[(int) ((prev))] & (unsigned short) _ISspace))
    buf_putchar(buf, *ptr);
   prev = *ptr;
  }
  else
  {
   switch(*ptr)
   {
    case '"':
    case '\'':
    case '<':
    case '>':
    case '&':
     esl = snprintf(esq, sizeof(esq), "&#%i;", *ptr);
     buf_append(buf, esq, esl);
     break;
    default:
     buf_putchar(buf, *ptr);
     break;
   }
   prev = *ptr;
  }
 }
 return buf_destroy(buf);
}

variable_types:
l
unsigned int

variable_types:
ptr
unsigned char *

variable_types:
end
unsigned char *

variable_types:
tag
unsigned char *

variable_types:
prev
unsigned char

variable_types:
esq
char [8]

variable_types: esl int


decompiled_code:
void __fastcall luastr_escape(__int64 a1, char *a2, int a3, int a4)
{
char *v4; // rbx
char *i; // r14
unsigned int v7; // esi
int v8; // eax
char s[48]; // [rsp+8h] [rbp-30h] BYREF

v4 = &a2[a3];
if ( a2 < v4 )
{
for ( i = a2; i != v4; ++i )
{
while ( 1 )
{
v7 = *i;
if ( *i > 39 )
break;
if ( (char)v7 > 37 )
goto LABEL_15;
if ( (_BYTE)v7 == 10 )
{
buf_append(a1, "\\n", 2u);
goto LABEL_8;
}
if ( (_BYTE)v7 == 34 )
{
if ( a4 )
buf_append(a1, """, 5u);
else
buf_append(a1, "\\\"", 2u);
goto LABEL_8;
}
LABEL_12:
++i;
buf_putchar(a1, v7);
if ( i == v4 )
return;
}
if ( (_BYTE)v7 == 92 )
{
buf_append(a1, "\\\\", 2u);
continue;
}
if ( (char)v7 > 92 || (*i & 0xFD) != 60 )
goto LABEL_12;
LABEL_15:
if ( !a4 )
goto LABEL_12;
v8 = snprintf(s, 8uLL, "&#%i;", v7);
buf_append(a1, s, v8);
LABEL_8:
;
}
}
}

canonical_decompiled_code:
void __fastcall func12(__int64 a1, char *a2, int a3, int a4)
{
char *v4; // rbx
char *i; // r14
unsigned int v7; // esi
int v8; // eax
char s[48]; // [rsp+8h] [rbp-30h] BYREF

v4 = &a2[a3];
if ( a2 < v4 )
{
for ( i = a2; i != v4; ++i )
{
while ( 1 )
{
v7 = *i;
if ( *i > 39 )
break;
if ( (char)v7 > 37 )
goto LABEL_15;
if ( (_BYTE)v7 == 10 )
{
func7(a1, "\\n", 2u);
goto LABEL_8;
}
if ( (_BYTE)v7 == 34 )
{
if ( a4 )
func7(a1, """, 5u);
else
func7(a1, "\\\"", 2u);
goto LABEL_8;
}
LABEL_12:
++i;
func6(a1, v7);
if ( i == v4 )
return;
}
if ( (_BYTE)v7 == 92 )
{
func7(a1, "\\\\", 2u);
continue;
}
if ( (char)v7 > 92 || (*i & 0xFD) != 60 )
goto LABEL_12;
LABEL_15:
if ( !a4 )
goto LABEL_12;
v8 = snprintf(s, 8uLL, "&#%i;", v7);
func7(a1, s, v8);
LABEL_8:
;
}
}
}

original_code:
void luastr_escape(struct template_buffer *out, const char *s, unsigned int l,
       int escape_xml)
{
 int esl;
 char esq[8];
 char *ptr;
 for (ptr = (char *)s; ptr < (s + l); ptr++)
 {
  switch (*ptr)
  {
  case '\\':
   buf_append(out, "\\\\", 2);
   break;
  case '"':
   if (escape_xml)
    buf_append(out, """, 5);
   else
    buf_append(out, "\\\"", 2);
   break;
  case '\n':
   buf_append(out, "\\n", 2);
   break;
  case '\'':
  case '&':
  case '<':
  case '>':
   if (escape_xml)
   {
    esl = snprintf(esq, sizeof(esq), "&#%i;", *ptr);
    buf_append(out, esq, esl);
    break;
   }
  default:
   buf_putchar(out, *ptr);
  }
 }
}

canonical_original_code:
void luastr_escape(struct template_buffer *out, char *s, unsigned int l, int escape_xml)
{
 int esl;
 char esq[8];
 char *ptr;
 for (ptr = (char *)s; ptr < (s + l); ptr++)
 {
  switch (*ptr)
  {
  case '\\':
   buf_append(out, "\\\\", 2);
   break;
  case '"':
   if (escape_xml)
    buf_append(out, """, 5);
   else
    buf_append(out, "\\\"", 2);
   break;
  case '\n':
   buf_append(out, "\\n", 2);
   break;
  case '\'':
  case '&':
  case '<':
  case '>':
   if (escape_xml)
   {
    esl = snprintf(esq, sizeof(esq), "&#%i;", *ptr);
    buf_append(out, esq, esl);
    break;
   }
  default:
   buf_putchar(out, *ptr);
  }
 }
}

variable_types:
ptr
char *


decompiled_code:
void __fastcall luastr_translate(__int64 a1, char *a2, unsigned int a3, int a4)
{
int v6; // eax
int v7; // [rsp+4h] [rbp-34h] BYREF
char *v8; // [rsp+8h] [rbp-30h] BYREF

v6 = lmo_translate(a2, a3, &v8, &v7);
if ( v6 == -1 )
{
luastr_escape(a1, a2, a3, a4);
}
else if ( !v6 )
{
luastr_escape(a1, v8, v7, a4);
}
}

canonical_decompiled_code:
void __fastcall func13(__int64 a1, char *a2, unsigned int a3, int a4)
{
int v6; // eax
int v7; // [rsp+4h] [rbp-34h] BYREF
char *v8; // [rsp+8h] [rbp-30h] BYREF

v6 = lmo_translate(a2, a3, &v8, &v7);
if ( v6 == -1 )
{
func12(a1, a2, a3, a4);
}
else if ( !v6 )
{
func12(a1, v8, v7, a4);
}
}

original_code:
void luastr_translate(struct template_buffer *out, const char *s, unsigned int l,
       int escape_xml)
{
 char *tr;
 int trlen;
 switch (lmo_translate(s, l, &tr, &trlen))
 {
  case 0:
   luastr_escape(out, tr, trlen, escape_xml);
   break;
  case -1:
   luastr_escape(out, s, l, escape_xml);
   break;
  default:
   break;
 }
}

canonical_original_code:
void luastr_translate(struct template_buffer *out, char *s, unsigned int l, int escape_xml)
{
 char *tr;
 int trlen;
 switch (lmo_translate(s, l, &tr, &trlen))
 {
  case 0:
   luastr_escape(out, tr, trlen, escape_xml);
   break;
  case -1:
   luastr_escape(out, s, l, escape_xml);
   break;
  default:
   break;
 }
}

variable_types:
tr
char *

variable_types: trlen int