nvgetopt

original_code:
int nvgetopt(int argc,
             char *argv[],
             const NVGetoptOption *options,
             char **strval,
             int *boolval,
             int *intval,
             double *doubleval,
             int *disable_val)
{
    char *c, *a, *arg, *name = ((void *)0), *argument=((void *)0);
    int i, found = 0;
    int ret = 0;
    int negate = 0;
    int disable = 0;
    int double_dash = 0;
    const NVGetoptOption *o = ((void *)0);
    static int argv_index = 0;
    if (strval) *strval = ((void *)0);
    if (boolval) *boolval = 0;
    if (intval) *intval = 0;
    if (doubleval) *doubleval = 0.0;
    if (disable_val) *disable_val = 0;
    argv_index++;
    if (argv_index >= argc) return -1;
    arg = strdup(argv[argv_index]);
    if ((arg[0] == '-') && (arg[1] == '-')) {
        name = arg + 2;
        double_dash = 1;
    } else if (arg[0] == '-') {
        name = arg + 1;
    } else {
        fprintf(stderr, "%s: invalid option: \"%s\"\n", argv[0], arg);
        goto done;
    }
    c = name;
    while (*c) {
        if (*c == '=') {
            argument = c + 1;
            *c = '\0';
            break;
        }
        c++;
    }
    if (name[0] == '\0') {
        if (double_dash && argument == ((void *)0)) {
            ret = -1;
            goto done;
        }
    } else if (name[1] == '\0') {
        for (i = 0; options[i].name; i++) {
            if (options[i].val == name[0]) {
                o = &options[i];
                break;
            }
        }
    } else {
        for (i = 0; options[i].name; i++) {
            const char *tmpname;
            int tmp_negate;
            if ((options[i].flags & (0x0001 |
                                     0x0010)) &&
                (name[0] == 'n') &&
                (name[1] == 'o') &&
                (name[2] == '-')) {
                tmpname = name + 3;
                tmp_negate = 1;
            } else {
                tmpname = name;
                tmp_negate = 0;
            }
            if (strcmp(tmpname, options[i].name) == 0) {
                o = &options[i];
                negate = tmp_negate;
                break;
            }
        }
    }
    if (!o) {
        for (c = name; *c; c++) {
            found = 0;
            for (i = 0; options[i].name; i++) {
                if (options[i].val == *c) {
                    found = 1;
                    break;
                }
            }
            if (!found) break;
        }
        if (found) {
            for (i = 0; options[i].name; i++) {
                if (options[i].val == name[0]) {
                    if (options[i].flags & (0x0002 | 0x0004 | 0x0008)) break;
                    a = argv[argv_index];
                    if (a[0] == '-') a++;
                    if (a[0] == '-') a++;
                    if (a[0] == '+') a++;
                    while (a[0]) { a[0] = a[1]; a++; }
                    argv_index--;
                    o = &options[i];
                    break;
                }
            }
        }
    }
    if (!o && intval) {
        int appendedInteger = 0;
        if ((name[0] != '\0') && (name[1] != '\0')) {
            char *endptr;
            strtol(name + 1, &endptr, 0);
            if (*endptr == '\0') {
                appendedInteger = 1;
            }
        }
        if (appendedInteger) {
            for (i = 0; options[i].name; i++) {
                if ((options[i].flags & 0x0004) == 0) {
                    continue;
                }
                if (options[i].val == name[0]) {
                    o = &options[i];
                    argument = name + 1;
                    break;
                }
            }
        }
    }
    if (!o) {
        fprintf(stderr, "%s: unrecognized option: \"%s\"\n", argv[0], arg);
        goto done;
    }
    if (o->flags & 0x0001) {
        if (boolval) *boolval = !negate;
    }
    if ((o->flags & 0x0010) && (negate == 1)) {
        disable = 1;
    }
    if ((o->flags & (0x0002 | 0x0004 | 0x0008)) && !disable) {
        if (argument) {
            if (!argument[0]) {
                fprintf(stderr, "%s: option \"%s\" requires an "
                        "argument.\n", argv[0], arg);
                goto done;
            }
        } else {
            if ((o->flags & 0x0020) &&
                ((argv_index == (argc - 1)) ||
                 (argv[argv_index + 1][0] == '-'))) {
                argument = ((void *)0);
                goto argument_processing_done;
            } else {
                argv_index++;
                if (argv_index >= argc) {
                    fprintf(stderr, "%s: option \"%s\" requires an "
                            "argument.\n", argv[0], arg);
                    goto done;
                }
                argument = argv[argv_index];
            }
        }
        if ((o->flags & 0x0004) && (intval)) {
            char *endptr;
            *intval = (int) strtol(argument, &endptr, 0);
            if (*endptr) {
                fprintf(stderr, "%s: \"%s\" is not a valid argument for "
                        "option \"%s\".\n", argv[0], argument, arg);
                goto done;
            }
        } else if ((o->flags & 0x0002) && (strval)) {
            *strval = strdup(argument);
        } else if ((o->flags & 0x0008) && (doubleval)) {
            char *endptr;
            *doubleval = (double) strtod(argument, &endptr);
            if (*endptr) {
                fprintf(stderr, "%s: \"%s\" is not a valid argument for "
                        "option \"%s\".\n", argv[0], argument, arg);
                goto done;
            }
        } else {
            fprintf(stderr, "%s: error while assigning argument for "
                    "option \"%s\".\n", argv[0], arg);
            goto done;
        }
    } else {
        if (argument) {
            fprintf(stderr, "%s: option \"%s\" does not take an argument, but "
                    "was given an argument of \"%s\".\n",
                    argv[0], arg, argument);
            goto done;
        }
    }
 argument_processing_done:
    ret = o->val;
 done:
    if (disable_val) *disable_val = disable;
    free(arg);
    return ret;
}

canonical_original_code:
int nvgetopt(int argc, char *argv[], struct NVGetoptOption *options, char **strval, int *boolval, int *intval, double *doubleval, int *disable_val)
{
    char *c; char *a; char *arg; char *name = ((void *)0); char *argument = ((void *)0);
    int i; int found = 0;
    int ret = 0;
    int negate = 0;
    int disable = 0;
    int double_dash = 0;
    struct NVGetoptOption *o = ((void *)0);
    static int argv_index = 0;
    if (strval) *strval = ((void *)0);
    if (boolval) *boolval = 0;
    if (intval) *intval = 0;
    if (doubleval) *doubleval = 0.0;
    if (disable_val) *disable_val = 0;
    argv_index++;
    if (argv_index >= argc) return -1;
    arg = strdup(argv[argv_index]);
    if ((arg[0] == '-') && (arg[1] == '-')) {
        name = arg + 2;
        double_dash = 1;
    } else if (arg[0] == '-') {
        name = arg + 1;
    } else {
        fprintf(stderr, "%s: invalid option: \"%s\"\n", argv[0], arg);
        goto done;
    }
    c = name;
    while (*c) {
        if (*c == '=') {
            argument = c + 1;
            *c = '\0';
            break;
        }
        c++;
    }
    if (name[0] == '\0') {
        if (double_dash && argument == ((void *)0)) {
            ret = -1;
            goto done;
        }
    } else if (name[1] == '\0') {
        for (i = 0; options[i].name; i++) {
            if (options[i].val == name[0]) {
                o = &options[i];
                break;
            }
        }
    } else {
        for (i = 0; options[i].name; i++) {
            char *tmpname;
            int tmp_negate;
            if ((options[i].flags & (0x0001 |
                                     0x0010)) &&
                (name[0] == 'n') &&
                (name[1] == 'o') &&
                (name[2] == '-')) {
                tmpname = name + 3;
                tmp_negate = 1;
            } else {
                tmpname = name;
                tmp_negate = 0;
            }
            if (strcmp(tmpname, options[i].name) == 0) {
                o = &options[i];
                negate = tmp_negate;
                break;
            }
        }
    }
    if (!o) {
        for (c = name; *c; c++) {
            found = 0;
            for (i = 0; options[i].name; i++) {
                if (options[i].val == *c) {
                    found = 1;
                    break;
                }
            }
            if (!found) break;
        }
        if (found) {
            for (i = 0; options[i].name; i++) {
                if (options[i].val == name[0]) {
                    if (options[i].flags & (0x0002 | 0x0004 | 0x0008)) break;
                    a = argv[argv_index];
                    if (a[0] == '-') a++;
                    if (a[0] == '-') a++;
                    if (a[0] == '+') a++;
                    while (a[0]) { a[0] = a[1]; a++; }
                    argv_index--;
                    o = &options[i];
                    break;
                }
            }
        }
    }
    if (!o && intval) {
        int appendedInteger = 0;
        if ((name[0] != '\0') && (name[1] != '\0')) {
            char *endptr;
            strtol(name + 1, &endptr, 0);
            if (*endptr == '\0') {
                appendedInteger = 1;
            }
        }
        if (appendedInteger) {
            for (i = 0; options[i].name; i++) {
                if ((options[i].flags & 0x0004) == 0) {
                    continue;
                }
                if (options[i].val == name[0]) {
                    o = &options[i];
                    argument = name + 1;
                    break;
                }
            }
        }
    }
    if (!o) {
        fprintf(stderr, "%s: unrecognized option: \"%s\"\n", argv[0], arg);
        goto done;
    }
    if (o->flags & 0x0001) {
        if (boolval) *boolval = !negate;
    }
    if ((o->flags & 0x0010) && (negate == 1)) {
        disable = 1;
    }
    if ((o->flags & (0x0002 | 0x0004 | 0x0008)) && !disable) {
        if (argument) {
            if (!argument[0]) {
                fprintf(stderr, "%s: option \"%s\" requires an "
                        "argument.\n", argv[0], arg);
                goto done;
            }
        } else {
            if ((o->flags & 0x0020) &&
                ((argv_index == (argc - 1)) ||
                 (argv[argv_index + 1][0] == '-'))) {
                argument = ((void *)0);
                goto argument_processing_done;
            } else {
                argv_index++;
                if (argv_index >= argc) {
                    fprintf(stderr, "%s: option \"%s\" requires an "
                            "argument.\n", argv[0], arg);
                    goto done;
                }
                argument = argv[argv_index];
            }
        }
        if ((o->flags & 0x0004) && (intval)) {
            char *endptr;
            *intval = (int) strtol(argument, &endptr, 0);
            if (*endptr) {
                fprintf(stderr, "%s: \"%s\" is not a valid argument for "
                        "option \"%s\".\n", argv[0], argument, arg);
                goto done;
            }
        } else if ((o->flags & 0x0002) && (strval)) {
            *strval = strdup(argument);
        } else if ((o->flags & 0x0008) && (doubleval)) {
            char *endptr;
            *doubleval = (double) strtod(argument, &endptr);
            if (*endptr) {
                fprintf(stderr, "%s: \"%s\" is not a valid argument for "
                        "option \"%s\".\n", argv[0], argument, arg);
                goto done;
            }
        } else {
            fprintf(stderr, "%s: error while assigning argument for "
                    "option \"%s\".\n", argv[0], arg);
            goto done;
        }
    } else {
        if (argument) {
            fprintf(stderr, "%s: option \"%s\" does not take an argument, but "
                    "was given an argument of \"%s\".\n",
                    argv[0], arg, argument);
            goto done;
        }
    }
 argument_processing_done:
    ret = o->val;
 done:
    if (disable_val) *disable_val = disable;
    free(arg);
    return ret;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: struct NVGetoptOption { char *name; int val; unsigned int flags; char *arg_name; char *description; } *

variable_types:
strval
char **

variable_types:
boolval
int *

variable_types:
intval
int *

variable_types:
doubleval
double *

variable_types:
c
char *

variable_types:
a
char *

variable_types:
arg
char *

variable_types:
name
char *

variable_types:
argument
char *

variable_types: found int

variable_types: ret int

variable_types: negate int

variable_types: disable int

variable_types:
tmpname
char *

variable_types: appendedInteger int

variable_types:
endptr
char *


repo: NVIDIA/nvidia-xconfig

original_code:
void nvgetopt_print_help(const NVGetoptOption *options,
                         unsigned int include_mask,
                         nvgetopt_print_help_callback_ptr callback)
{
    const NVGetoptOption *o;
    int i;
    for (i = 0; options[i].name; i++) {
        char *msg = ((void *)0), *arg = ((void *)0), *description = ((void *)0);
        o = &options[i];
        if (!o->description) {
            continue;
        }
        if ((o->flags & include_mask) != include_mask) {
            continue;
        }
        arg = ((void *)0);
        if (o->flags & (0x0002 | 0x0004 | 0x0008)) {
            if (o->arg_name) {
                arg = strdup(o->arg_name);
            } else {
                char *tmp;
                arg = strdup(o->name);
                for (tmp = arg; tmp && *tmp; tmp++) {
                    *tmp = toupper(*tmp);
                }
            }
        }
        msg = ((void *)0);
        if (arg) {
            msg = nvstrcat("--", o->name, "=", arg, ((void *)0));
        } else {
            msg = nvstrcat("--", o->name, ((void *)0));
        }
        if (o->val <= (0x7f * 2 + 1) && o->val >= 0 && ((*__ctype_b_loc ())[(int) ((o->val))] & (unsigned short int) _ISalpha)) {
            char scratch[16];
            char *tmp;
            snprintf(scratch, sizeof(scratch), "%c", o->val);
            if (arg) {
                tmp = nvstrcat("-", scratch, " ", arg, ", ", msg, ((void *)0));
            } else {
                tmp = nvstrcat("-", scratch, ", ", msg, ((void *)0));
            }
            free(msg);
            msg = tmp;
        }
        if (((o->flags & 0x0001) &&
             !(o->flags & (0x0002 | 0x0004 | 0x0008))) ||
            (o->flags & 0x0010)) {
            char *tmp = nvstrcat(msg, ", --no-", o->name, ((void *)0));
            free(msg);
            msg = tmp;
        }
        description = cook_description(o->description);
        callback(msg, description);
        free(msg);
        free(arg);
        free(description);
    }
}

canonical_original_code:
void nvgetopt_print_help(struct NVGetoptOption *options, unsigned int include_mask, void callback(char *name, char *description))
{
    struct NVGetoptOption *o;
    int i;
    for (i = 0; options[i].name; i++) {
        char *msg = ((void *)0); char *arg = ((void *)0); char *description = ((void *)0);
        o = &options[i];
        if (!o->description) {
            continue;
        }
        if ((o->flags & include_mask) != include_mask) {
            continue;
        }
        arg = ((void *)0);
        if (o->flags & (0x0002 | 0x0004 | 0x0008)) {
            if (o->arg_name) {
                arg = strdup(o->arg_name);
            } else {
                char *tmp;
                arg = strdup(o->name);
                for (tmp = arg; tmp && *tmp; tmp++) {
                    *tmp = toupper(*tmp);
                }
            }
        }
        msg = ((void *)0);
        if (arg) {
            msg = nvstrcat("--", o->name, "=", arg, ((void *)0));
        } else {
            msg = nvstrcat("--", o->name, ((void *)0));
        }
        if (o->val <= (0x7f * 2 + 1) && o->val >= 0 && ((*__ctype_b_loc ())[(int) ((o->val))] & (unsigned short) _ISalpha)) {
            char scratch[16];
            char *tmp;
            snprintf(scratch, sizeof(scratch), "%c", o->val);
            if (arg) {
                tmp = nvstrcat("-", scratch, " ", arg, ", ", msg, ((void *)0));
            } else {
                tmp = nvstrcat("-", scratch, ", ", msg, ((void *)0));
            }
            free(msg);
            msg = tmp;
        }
        if (((o->flags & 0x0001) &&
             !(o->flags & (0x0002 | 0x0004 | 0x0008))) ||
            (o->flags & 0x0010)) {
            char *tmp = nvstrcat(msg, ", --no-", o->name, ((void *)0));
            free(msg);
            msg = tmp;
        }
        description = cook_description(o->description);
        callback(msg, description);
        free(msg);
        free(arg);
        free(description);
    }
}

variable_types: struct NVGetoptOption { char *name; int val; unsigned int flags; char *arg_name; char *description; } *

variable_types:
callback
void (char *name, char *description)

variable_types: i int

variable_types:
msg
char *

variable_types:
description
char *

variable_types:
tmp
char *

variable_types:
scratch
char [16]

return_type: void


decompiled_code:
__int64 __fastcall copy_file(const char *a1, const char *a2, unsigned int a3)
{
int v4; // eax
int v5; // ebx
int v6; // er12
unsigned int v7; // er15
int *v9; // rax
char *v10; // rax
int *v11; // rax
char *v12; // rax
int *v13; // rax
char *v14; // rax
int *v15; // rax
char *v16; // rax
int *v17; // rax
char *v18; // rax
void *v19; // r15
int *v20; // rax
char *v21; // rax
int *v22; // rax
char *v23; // rax
int *v24; // rax
char *v25; // rax
int *v26; // rax
char *v27; // rax
void *dest; // [rsp+8h] [rbp-C8h]
struct stat buf; // [rsp+10h] [rbp-C0h] BYREF

v4 = open(a1, 0);
if ( v4 == -1 )
{
v9 = _errno_location();
v10 = strerror(*v9);
nv_error_msg("Unable to open '%s' for copying (%s)", a1, v10);
v7 = 0;
}
else
{
v5 = v4;
v6 = open(a2, 578, a3);
if ( v6 == -1 )
{
v11 = _errno_location();
v12 = strerror(*v11);
nv_error_msg("Unable to create '%s' for copying (%s)", a2, v12);
v7 = 0;
}
else if ( fstat(v5, &buf) == -1 )
{
v13 = _errno_location();
v14 = strerror(*v13);
nv_error_msg("Unable to determine size of '%s' (%s)", a1, v14);
v7 = 0;
}
else
{
v7 = 1;
if ( buf.st_size )
{
if ( lseek(v6, buf.st_size - 1, 0) == -1 )
{
v17 = _errno_location();
v18 = strerror(*v17);
nv_error_msg("Unable to set file size for '%s' (%s)", a2, v18);
v7 = 0;
}
else if ( write(v6, &unk_77F, 1uLL) == 1 )
{
v19 = mmap(0LL, buf.st_size, 1, 1, v5, 0LL);
if ( v19 == (void *)-1LL )
{
v22 = _errno_location();
v23 = strerror(*v22);
nv_error_msg("Unable to map source file '%s' for copying (%s)", a1, v23);
v7 = 0;
}
else
{
dest = mmap(0LL, buf.st_size, 3, 1, v6, 0LL);
if ( dest == (void *)-1LL )
{
v24 = _errno_location();
v25 = strerror(*v24);
nv_error_msg("Unable to map destination file '%s' for copying (%s)", a2, v25);
v7 = 0;
}
else
{
memcpy(dest, v19, buf.st_size);
if ( munmap(v19, buf.st_size) == -1 )
{
v26 = _errno_location();
v27 = strerror(*v26);
nv_error_msg("Unable to unmap source file '%s' after copying (%s)", a1, v27);
v7 = 0;
}
else
{
v7 = 1;
if ( munmap(dest, buf.st_size) == -1 )
{
v20 = _errno_location();
v21 = strerror(*v20);
nv_error_msg("Unable to unmap destination file '%s' after copying (%s)", a2, v21);
v7 = 0;
}
}
}
}
}
else
{
v15 = _errno_location();
v16 = strerror(*v15);
nv_error_msg("Unable to write file size for '%s' (%s)", a2, v16);
v7 = 0;
}
}
}
close(v5);
if ( v6 != -1 )
close(v6);
}
return v7;
}

canonical_decompiled_code:
__int64 __fastcall func0(const char *a1, const char *a2, unsigned int a3)
{
int v4; // eax
int v5; // ebx
int v6; // er12
unsigned int v7; // er15
int *v9; // rax
char *v10; // rax
int *v11; // rax
char *v12; // rax
int *v13; // rax
char *v14; // rax
int *v15; // rax
char *v16; // rax
int *v17; // rax
char *v18; // rax
void *v19; // r15
int *v20; // rax
char *v21; // rax
int *v22; // rax
char *v23; // rax
int *v24; // rax
char *v25; // rax
int *v26; // rax
char *v27; // rax
void *dest; // [rsp+8h] [rbp-C8h]
struct stat buf; // [rsp+10h] [rbp-C0h] BYREF

v4 = open(a1, 0);
if ( v4 == -1 )
{
v9 = _errno_location();
v10 = strerror(*v9);
nv_error_msg("Unable to open '%s' for copying (%s)", a1, v10);
v7 = 0;
}
else
{
v5 = v4;
v6 = open(a2, 578, a3);
if ( v6 == -1 )
{
v11 = _errno_location();
v12 = strerror(*v11);
nv_error_msg("Unable to create '%s' for copying (%s)", a2, v12);
v7 = 0;
}
else if ( fstat(v5, &buf) == -1 )
{
v13 = _errno_location();
v14 = strerror(*v13);
nv_error_msg("Unable to determine size of '%s' (%s)", a1, v14);
v7 = 0;
}
else
{
v7 = 1;
if ( buf.st_size )
{
if ( lseek(v6, buf.st_size - 1, 0) == -1 )
{
v17 = _errno_location();
v18 = strerror(*v17);
nv_error_msg("Unable to set file size for '%s' (%s)", a2, v18);
v7 = 0;
}
else if ( write(v6, &unk_77F, 1uLL) == 1 )
{
v19 = mmap(0LL, buf.st_size, 1, 1, v5, 0LL);
if ( v19 == (void *)-1LL )
{
v22 = _errno_location();
v23 = strerror(*v22);
nv_error_msg("Unable to map source file '%s' for copying (%s)", a1, v23);
v7 = 0;
}
else
{
dest = mmap(0LL, buf.st_size, 3, 1, v6, 0LL);
if ( dest == (void *)-1LL )
{
v24 = _errno_location();
v25 = strerror(*v24);
nv_error_msg("Unable to map destination file '%s' for copying (%s)", a2, v25);
v7 = 0;
}
else
{
memcpy(dest, v19, buf.st_size);
if ( munmap(v19, buf.st_size) == -1 )
{
v26 = _errno_location();
v27 = strerror(*v26);
nv_error_msg("Unable to unmap source file '%s' after copying (%s)", a1, v27);
v7 = 0;
}
else
{
v7 = 1;
if ( munmap(dest, buf.st_size) == -1 )
{
v20 = _errno_location();
v21 = strerror(*v20);
nv_error_msg("Unable to unmap destination file '%s' after copying (%s)", a2, v21);
v7 = 0;
}
}
}
}
}
else
{
v15 = _errno_location();
v16 = strerror(*v15);
nv_error_msg("Unable to write file size for '%s' (%s)", a2, v16);
v7 = 0;
}
}
}
close(v5);
if ( v6 != -1 )
close(v6);
}
return v7;
}

original_code:
int copy_file(const char *srcfile, const char *dstfile, mode_t mode)
{
    int src_fd = -1, dst_fd = -1;
    struct stat stat_buf;
    char *src, *dst;
    int ret = 0;
    if ((src_fd = open(srcfile, 00)) == -1) {
        nv_error_msg("Unable to open '%s' for copying (%s)",
                     srcfile, strerror ((*__errno_location ())));
        goto done;
    }
    if ((dst_fd = open(dstfile, 02 | 0100 | 01000, mode)) == -1) {
        nv_error_msg("Unable to create '%s' for copying (%s)",
                     dstfile, strerror ((*__errno_location ())));
        goto done;
    }
    if (fstat(src_fd, &stat_buf) == -1) {
        nv_error_msg("Unable to determine size of '%s' (%s)",
                     srcfile, strerror ((*__errno_location ())));
        goto done;
    }
    if (stat_buf.st_size == 0) {
        ret = 1;
        goto done;
    }
    if (lseek(dst_fd, stat_buf.st_size - 1, 0) == -1) {
        nv_error_msg("Unable to set file size for '%s' (%s)",
                     dstfile, strerror ((*__errno_location ())));
        goto done;
    }
    if (write(dst_fd, "", 1) != 1) {
        nv_error_msg("Unable to write file size for '%s' (%s)",
                     dstfile, strerror ((*__errno_location ())));
        goto done;
    }
    if ((src = mmap(0, stat_buf.st_size, 0x1,
                    0x01, src_fd, 0)) == (void *) -1) {
        nv_error_msg("Unable to map source file '%s' for "
                     "copying (%s)", srcfile, strerror ((*__errno_location ())));
        goto done;
    }
    if ((dst = mmap(0, stat_buf.st_size, 0x1 | 0x2,
                    0x01, dst_fd, 0)) == (void *) -1) {
        nv_error_msg("Unable to map destination file '%s' for "
                     "copying (%s)", dstfile, strerror ((*__errno_location ())));
        goto done;
    }
    memcpy(dst, src, stat_buf.st_size);
    if (munmap (src, stat_buf.st_size) == -1) {
        nv_error_msg("Unable to unmap source file '%s' after "
                     "copying (%s)", srcfile, strerror ((*__errno_location ())));
        goto done;
    }
    if (munmap (dst, stat_buf.st_size) == -1) {
        nv_error_msg("Unable to unmap destination file '%s' after "
                     "copying (%s)", dstfile, strerror ((*__errno_location ())));
        goto done;
    }
    ret = 1;
 done:
    if (src_fd != -1) close(src_fd);
    if (dst_fd != -1) close(dst_fd);
    return ret;
}

canonical_original_code:
int copy_file(char *srcfile, char *dstfile, unsigned int mode)
{
    int src_fd = -1; int dst_fd = -1;
    struct stat stat_buf;
    char *src; char *dst;
    int ret = 0;
    if ((src_fd = open(srcfile, 00)) == -1) {
        nv_error_msg("Unable to open '%s' for copying (%s)",
                     srcfile, strerror ((*__errno_location ())));
        goto done;
    }
    if ((dst_fd = open(dstfile, 02 | 0100 | 01000, mode)) == -1) {
        nv_error_msg("Unable to create '%s' for copying (%s)",
                     dstfile, strerror ((*__errno_location ())));
        goto done;
    }
    if (fstat(src_fd, &stat_buf) == -1) {
        nv_error_msg("Unable to determine size of '%s' (%s)",
                     srcfile, strerror ((*__errno_location ())));
        goto done;
    }
    if (stat_buf.st_size == 0) {
        ret = 1;
        goto done;
    }
    if (lseek(dst_fd, stat_buf.st_size - 1, 0) == -1) {
        nv_error_msg("Unable to set file size for '%s' (%s)",
                     dstfile, strerror ((*__errno_location ())));
        goto done;
    }
    if (write(dst_fd, "", 1) != 1) {
        nv_error_msg("Unable to write file size for '%s' (%s)",
                     dstfile, strerror ((*__errno_location ())));
        goto done;
    }
    if ((src = mmap(0, stat_buf.st_size, 0x1,
                    0x01, src_fd, 0)) == (void *) -1) {
        nv_error_msg("Unable to map source file '%s' for "
                     "copying (%s)", srcfile, strerror ((*__errno_location ())));
        goto done;
    }
    if ((dst = mmap(0, stat_buf.st_size, 0x1 | 0x2,
                    0x01, dst_fd, 0)) == (void *) -1) {
        nv_error_msg("Unable to map destination file '%s' for "
                     "copying (%s)", dstfile, strerror ((*__errno_location ())));
        goto done;
    }
    memcpy(dst, src, stat_buf.st_size);
    if (munmap (src, stat_buf.st_size) == -1) {
        nv_error_msg("Unable to unmap source file '%s' after "
                     "copying (%s)", srcfile, strerror ((*__errno_location ())));
        goto done;
    }
    if (munmap (dst, stat_buf.st_size) == -1) {
        nv_error_msg("Unable to unmap destination file '%s' after "
                     "copying (%s)", dstfile, strerror ((*__errno_location ())));
        goto done;
    }
    ret = 1;
 done:
    if (src_fd != -1) close(src_fd);
    if (dst_fd != -1) close(dst_fd);
    return ret;
}

variable_types:
srcfile
char *

variable_types:
dstfile
char *

variable_types:
mode
unsigned int

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

variable_types:
src
char *

variable_types:
dst
char *

return_type: int

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


prependRoot

decompiled_code:
__int64 __fastcall prependRoot(__int64 a1)
{
return a1;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
return a1;
}

original_code:
static char *
prependRoot (char *pathname)
{
    return pathname;
}

canonical_original_code:
static char *prependRoot(char *pathname)
{
    return pathname;
}

variable_types:
pathname
char *

return_type: char *


original_code:
int add_elem_in_list_with_pos(t_elem *elem_to_add)
{
  int counter;
  t_elem *elem_to_use;
  counter = 0;
  if ((elem_to_use = g_str->list_of_elems) == ((void *)0))
    return (-1);
  while (elem_to_use->next != ((void *)0))
    {
      elem_to_use = elem_to_use->next;
      counter = counter + 1;
    }
  if ((elem_to_add = my_sbrk(sizeof(*elem_to_add))) == (void*)-1)
    return (-1);
  elem_to_add->ptr_free = 0;
  elem_to_add->nbr_of_elem = counter + 1;
  elem_to_add->next = ((void *)0);
  elem_to_add->prev = elem_to_use;
  if (elem_to_use == g_str->list_of_elems)
    {
      g_str->list_of_elems->next = elem_to_add;
      printf("%p\n", g_str->list_of_elems->next);
    }
  else
    elem_to_use->next = elem_to_add;
  g_str->nb_of_elems = g_str->nb_of_elems + 1;
  return (0);
}

canonical_original_code:
int add_elem_in_list_with_pos(struct s_elem *elem_to_add)
{
  int counter;
  struct s_elem *elem_to_use;
  counter = 0;
  if ((elem_to_use = g_str->list_of_elems) == ((void *)0))
    return (-1);
  while (elem_to_use->next != ((void *)0))
    {
      elem_to_use = elem_to_use->next;
      counter = counter + 1;
    }
  if ((elem_to_add = my_sbrk(sizeof(*elem_to_add))) == (void *)-1)
    return (-1);
  elem_to_add->ptr_free = 0;
  elem_to_add->nbr_of_elem = counter + 1;
  elem_to_add->next = ((void *)0);
  elem_to_add->prev = elem_to_use;
  if (elem_to_use == g_str->list_of_elems)
    {
      g_str->list_of_elems->next = elem_to_add;
      printf("%p\n", g_str->list_of_elems->next);
    }
  else
    elem_to_use->next = elem_to_add;
  g_str->nb_of_elems = g_str->nb_of_elems + 1;
  return (0);
}

variable_types: struct s_elem { unsigned long size; int ptr_free; int nbr_of_elem; void *ptr_of_elem; struct s_elem *next; struct s_elem *prev; } *

variable_types: counter int


decompiled_code:
__int64 __fastcall add_elem_in_list(int a1)
{
__int64 *v1; // rbp
__int64 v2; // rax
_QWORD *v3; // rax
_DWORD *v4; // rax

if ( a1 )
return add_elem_in_list_with_pos(0LL);
v1 = g_str;
v2 = my_sbrk(40LL);
*v1 = v2;
if ( v2 == -1 )
return 0xFFFFFFFFLL;
v3 = g_str;
*(_QWORD *)(*g_str + 24LL) = 0LL;
*(_QWORD *)(*v3 + 32LL) = 0LL;
*(_QWORD *)*v3 = 0LL;
v4 = g_str;
*(_DWORD *)(*g_str + 12LL) = 0;
*(_DWORD *)(*(_QWORD *)v4 + 8LL) = 0;
v4[2] = 1;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1)
{
__int64 *v1; // rbp
__int64 v2; // rax
_QWORD *v3; // rax
_DWORD *v4; // rax

if ( a1 )
return func0(0LL);
v1 = g_str;
v2 = my_sbrk(40LL);
*v1 = v2;
if ( v2 == -1 )
return 0xFFFFFFFFLL;
v3 = g_str;
*(_QWORD *)(*g_str + 24LL) = 0LL;
*(_QWORD *)(*v3 + 32LL) = 0LL;
*(_QWORD *)*v3 = 0LL;
v4 = g_str;
*(_DWORD *)(*g_str + 12LL) = 0;
*(_DWORD *)(*(_QWORD *)v4 + 8LL) = 0;
v4[2] = 1;
return 0LL;
}

original_code:
int add_elem_in_list(int elem_position)
{
  t_elem *elem_to_add;
  elem_to_add = ((void *)0);
  if (elem_position == 0)
    {
      if ((g_str->list_of_elems = my_sbrk(sizeof(*g_str->list_of_elems))) == (void*)-1)
 return (-1);
      g_str->list_of_elems->next = ((void *)0);
      g_str->list_of_elems->prev = ((void *)0);
      g_str->list_of_elems->size = 0;
      g_str->list_of_elems->nbr_of_elem = 0;
      g_str->list_of_elems->ptr_free = 0;
      g_str->nb_of_elems = 1;
    }
  else
    return (add_elem_in_list_with_pos(elem_to_add));
  return (0);
}

canonical_original_code:
int add_elem_in_list(int elem_position)
{
  struct s_elem *elem_to_add;
  elem_to_add = ((void *)0);
  if (elem_position == 0)
    {
      if ((g_str->list_of_elems = my_sbrk(sizeof(*g_str->list_of_elems))) == (void *)-1)
 return (-1);
      g_str->list_of_elems->next = ((void *)0);
      g_str->list_of_elems->prev = ((void *)0);
      g_str->list_of_elems->size = 0;
      g_str->list_of_elems->nbr_of_elem = 0;
      g_str->list_of_elems->ptr_free = 0;
      g_str->nb_of_elems = 1;
    }
  else
    return (add_elem_in_list_with_pos(elem_to_add));
  return (0);
}

user_defined_types: struct s_elem { unsigned long size; int ptr_free; int nbr_of_elem; void *ptr_of_elem; struct s_elem *next; struct s_elem *prev; }


original_code:
t_elem *find_elem_in_list(int elem_position)
{
  int counter;
  t_elem *elem_to_use;
  if ((elem_to_use = g_str->list_of_elems) == ((void *)0))
    return (((void *)0));
  counter = 0;
  while (elem_to_use->next != ((void *)0) && counter < elem_position)
    {
      elem_to_use = elem_to_use->next;
      counter = counter + 1;
    }
  if (elem_to_use != ((void *)0) && counter == elem_position)
    return (elem_to_use);
  return (((void *)0));
}

canonical_original_code:
struct s_elem *find_elem_in_list(int elem_position)
{
  int counter;
  struct s_elem *elem_to_use;
  if ((elem_to_use = g_str->list_of_elems) == ((void *)0))
    return (((void *)0));
  counter = 0;
  while (elem_to_use->next != ((void *)0) && counter < elem_position)
    {
      elem_to_use = elem_to_use->next;
      counter = counter + 1;
    }
  if (elem_to_use != ((void *)0) && counter == elem_position)
    return (elem_to_use);
  return (((void *)0));
}

return_type: struct s_elem { unsigned long size; int ptr_free; int nbr_of_elem; void *ptr_of_elem; struct s_elem *next; struct s_elem *prev; } *


original_code:
t_elem *fill_elem(void *ptr_of_elem_to_set,
      t_elem *elem_to_fill, size_t size_to_set)
{
  if (ptr_of_elem_to_set == (void*)-1)
      return (((void *)0));
  if (elem_to_fill == ((void *)0))
    return (((void *)0));
  elem_to_fill->size = size_to_set;
  elem_to_fill->ptr_free = 0;
  elem_to_fill->ptr_of_elem = ptr_of_elem_to_set;
  return (elem_to_fill);
}

canonical_original_code:
struct s_elem *fill_elem(void *ptr_of_elem_to_set, struct s_elem *elem_to_fill, unsigned long size_to_set)
{
  if (ptr_of_elem_to_set == (void *)-1)
      return (((void *)0));
  if (elem_to_fill == ((void *)0))
    return (((void *)0));
  elem_to_fill->size = size_to_set;
  elem_to_fill->ptr_free = 0;
  elem_to_fill->ptr_of_elem = ptr_of_elem_to_set;
  return (elem_to_fill);
}


decompiled_code:
int show_list_of_elems()
{
__int64 v0; // rbx
int i; // ebp
int result; // eax

v0 = *g_str;
if ( !*g_str )
return -1;
for ( i = 0; *((_DWORD *)g_str + 2) > i; ++i )
{
result = printf(
"Adresse du pointeur : %p .\nTaille du pointeur : %lu .\n",
*(const void **)(v0 + 16),
*(_QWORD *)v0);
if ( result == -1 )
return result;
result = printf(
"Si le pointeur est free : %d .\nPlace de l'element : %d .\n",
*(unsigned int *)(v0 + 8),
*(unsigned int *)(v0 + 12));
if ( result == -1 )
return result;
v0 = *(_QWORD *)(v0 + 24);
if ( !v0 )
return 0;
}
return 0;
}

canonical_decompiled_code:
int func4()
{
__int64 v0; // rbx
int i; // ebp
int result; // eax

v0 = *g_str;
if ( !*g_str )
return -1;
for ( i = 0; *((_DWORD *)g_str + 2) > i; ++i )
{
result = printf(
"Adresse du pointeur : %p .\nTaille du pointeur : %lu .\n",
*(const void **)(v0 + 16),
*(_QWORD *)v0);
if ( result == -1 )
return result;
result = printf(
"Si le pointeur est free : %d .\nPlace de l'element : %d .\n",
*(unsigned int *)(v0 + 8),
*(unsigned int *)(v0 + 12));
if ( result == -1 )
return result;
v0 = *(_QWORD *)(v0 + 24);
if ( !v0 )
return 0;
}
return 0;
}

original_code:
int show_list_of_elems()
{
  int counter;
  t_elem *elem_to_use;
  counter = 0;
  if ((elem_to_use = g_str->list_of_elems) == ((void *)0))
    return (-1);
  while (elem_to_use != ((void *)0) && counter < g_str->nb_of_elems)
    {
      if (printf("Adresse du pointeur : %p .\nTaille du pointeur : %lu .\n",
   elem_to_use->ptr_of_elem, elem_to_use->size) == -1
   || printf("Si le pointeur est free : %d .\nPlace de l'element : %d .\n",
      elem_to_use->ptr_free, elem_to_use->nbr_of_elem) == -1)
    return (-1);
      elem_to_use = elem_to_use->next;
      counter = counter + 1;
    }
  return (0);
}

canonical_original_code:
int show_list_of_elems()
{
  int counter;
  struct s_elem *elem_to_use;
  counter = 0;
  if ((elem_to_use = g_str->list_of_elems) == ((void *)0))
    return (-1);
  while (elem_to_use != ((void *)0) && counter < g_str->nb_of_elems)
    {
      if (printf("Adresse du pointeur : %p .\nTaille du pointeur : %lu .\n",
   elem_to_use->ptr_of_elem, elem_to_use->size) == -1
   || printf("Si le pointeur est free : %d .\nPlace de l'element : %d .\n",
      elem_to_use->ptr_free, elem_to_use->nbr_of_elem) == -1)
    return (-1);
      elem_to_use = elem_to_use->next;
      counter = counter + 1;
    }
  return (0);
}


decompiled_code:
__int64 init_malloc()
{
_QWORD *v0; // rbx
void *v1; // rax

g_str = sbrk(40LL);
*g_str = 0LL;
v0 = g_str;
*((_DWORD *)g_str + 2) = 0;
*((_DWORD *)v0 + 3) = 0;
*((_DWORD *)v0 + 4) = getpagesize();
v1 = sbrk(0LL);
v0[3] = v1;
if ( v1 == (void *)-1LL )
return 0xFFFFFFFFLL;
g_str[4] = g_str[3];
return 0LL;
}

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

g_str = sbrk(40LL);
*g_str = 0LL;
v0 = g_str;
*((_DWORD *)g_str + 2) = 0;
*((_DWORD *)v0 + 3) = 0;
*((_DWORD *)v0 + 4) = getpagesize();
v1 = sbrk(0LL);
v0[3] = v1;
if ( v1 == (void *)-1LL )
return 0xFFFFFFFFLL;
g_str[4] = g_str[3];
return 0LL;
}

original_code:
int init_malloc()
{
  g_str = sbrk(sizeof(*g_str));
  g_str->list_of_elems = ((void *)0);
  g_str->nb_of_elems = 0;
  g_str->nb_of_pages = 0;
  g_str->pages_size = getpagesize();
  if ((g_str->begin_process_break_limit = sbrk(0)) == (void*)-1)
    return (-1);
  g_str->allocated_memory = g_str->begin_process_break_limit;
  return (0);
}

canonical_original_code:
int init_malloc()
{
  g_str = sbrk(sizeof(*g_str));
  g_str->list_of_elems = ((void *)0);
  g_str->nb_of_elems = 0;
  g_str->nb_of_pages = 0;
  g_str->pages_size = getpagesize();
  if ((g_str->begin_process_break_limit = sbrk(0)) == (void *)-1)
    return (-1);
  g_str->allocated_memory = g_str->begin_process_break_limit;
  return (0);
}


original_code:
void *my_sbrk(intptr_t increment)
{
  unsigned long local_mem_counter;
  void *ptr_to_allocate;
  unsigned long counter;
  int pages_counter;
  pages_counter = 0;
  g_str->allocated_memory = g_str->allocated_memory + (unsigned long)increment;
  local_mem_counter = (g_str->allocated_memory - g_str->begin_process_break_limit);
  counter = 0;
  while (counter < local_mem_counter)
    {
      counter = counter + g_str->pages_size;
      pages_counter = pages_counter + 1;
    }
  if ((pages_counter - g_str->nb_of_pages) > 0)
    {
      if ((sbrk((pages_counter - g_str->nb_of_pages) * g_str->pages_size)) == (void*)-1)
 return ((void*)-1);
    }
  g_str->nb_of_pages = pages_counter;
  ptr_to_allocate = g_str->allocated_memory - (unsigned long)increment;
  if (((unsigned long)g_str->allocated_memory % 4) != 0)
    g_str->allocated_memory = g_str->allocated_memory +
      (4 - ((unsigned long)g_str->allocated_memory % 4));
  return (ptr_to_allocate);
}

canonical_original_code:
void *my_sbrk(long increment)
{
  unsigned long local_mem_counter;
  void *ptr_to_allocate;
  unsigned long counter;
  int pages_counter;
  pages_counter = 0;
  g_str->allocated_memory = g_str->allocated_memory + (unsigned long)increment;
  local_mem_counter = (g_str->allocated_memory - g_str->begin_process_break_limit);
  counter = 0;
  while (counter < local_mem_counter)
    {
      counter = counter + g_str->pages_size;
      pages_counter = pages_counter + 1;
    }
  if ((pages_counter - g_str->nb_of_pages) > 0)
    {
      if ((sbrk((pages_counter - g_str->nb_of_pages) * g_str->pages_size)) == (void *)-1)
 return ((void *)-1);
    }
  g_str->nb_of_pages = pages_counter;
  ptr_to_allocate = g_str->allocated_memory - (unsigned long)increment;
  if (((unsigned long)g_str->allocated_memory % 4) != 0)
    g_str->allocated_memory = g_str->allocated_memory +
      (4 - ((unsigned long)g_str->allocated_memory % 4));
  return (ptr_to_allocate);
}

variable_types: increment long

variable_types:
counter
unsigned long

return_type: void *


decompiled_code:
__int64 __fastcall ret_free_good_elem(unsigned __int64 a1)
{
__int64 result; // rax
int v2; // edx

result = *g_str;
if ( *g_str )
{
v2 = 0;
while ( *((_DWORD *)g_str + 2) > v2 )
{
if ( *(_DWORD *)(result + 8) != 1 || *(_QWORD *)result < a1 )
{
result = *(_QWORD *)(result + 24);
++v2;
if ( result )
continue;
}
return result;
}
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(unsigned __int64 a1)
{
__int64 result; // rax
int v2; // edx

result = *g_str;
if ( *g_str )
{
v2 = 0;
while ( *((_DWORD *)g_str + 2) > v2 )
{
if ( *(_DWORD *)(result + 8) != 1 || *(_QWORD *)result < a1 )
{
result = *(_QWORD *)(result + 24);
++v2;
if ( result )
continue;
}
return result;
}
result = 0LL;
}
return result;
}

original_code:
t_elem *ret_free_good_elem(size_t size)
{
  int counter;
  t_elem *elem_to_use;
  elem_to_use = ((void *)0);
  if ((elem_to_use = g_str->list_of_elems) == ((void *)0))
    return (((void *)0));
  counter = 0;
  while (elem_to_use != ((void *)0) && counter < g_str->nb_of_elems)
    {
      if (elem_to_use->ptr_free == 1)
 if (size <= elem_to_use->size)
   return (elem_to_use);
      elem_to_use = elem_to_use->next;
      counter = counter + 1;
    }
  return (((void *)0));
}

canonical_original_code:
struct s_elem *ret_free_good_elem(unsigned long size)
{
  int counter;
  struct s_elem *elem_to_use;
  elem_to_use = ((void *)0);
  if ((elem_to_use = g_str->list_of_elems) == ((void *)0))
    return (((void *)0));
  counter = 0;
  while (elem_to_use != ((void *)0) && counter < g_str->nb_of_elems)
    {
      if (elem_to_use->ptr_free == 1)
 if (size <= elem_to_use->size)
   return (elem_to_use);
      elem_to_use = elem_to_use->next;
      counter = counter + 1;
    }
  return (((void *)0));
}

variable_types:
size
unsigned long


decompiled_code:
__int64 __fastcall ret_metadata_of_ptr(__int64 a1)
{
*(_DWORD *)(a1 - 32) = 1;
return a1 - 40;
}

original_code:
t_elem *ret_metadata_of_ptr(void *ptr_to_use)
{
  t_elem *elem_to_ret;
  elem_to_ret = ptr_to_use - (sizeof(*elem_to_ret));
  elem_to_ret->ptr_free = 1;
  return (elem_to_ret);
}

canonical_original_code:
struct s_elem *ret_metadata_of_ptr(void *ptr_to_use)
{
  struct s_elem *elem_to_ret;
  elem_to_ret = ptr_to_use - (sizeof(*elem_to_ret));
  elem_to_ret->ptr_free = 1;
  return (elem_to_ret);
}


decompiled_code:
__int64 __fastcall fusion_of_ptr(_QWORD *a1, _QWORD *a2)
{
__int64 v2; // rax
__int64 result; // rax

*a1 += *a2 + 40LL;
v2 = a2[3];
a1[3] = v2;
if ( v2 )
*(_QWORD *)(v2 + 32) = a1;
result = g_str;
--*(_DWORD *)(g_str + 8LL);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(_QWORD *a1, _QWORD *a2)
{
__int64 v2; // rax
__int64 result; // rax

*a1 += *a2 + 40LL;
v2 = a2[3];
a1[3] = v2;
if ( v2 )
*(_QWORD *)(v2 + 32) = a1;
result = g_str;
--*(_DWORD *)(g_str + 8LL);
return result;
}

original_code:
void fusion_of_ptr(t_elem *elem_first, t_elem *elem_sec)
{
  elem_first->size = elem_first->size + sizeof(*elem_sec) + elem_sec->size;
  if (elem_sec == ((void *)0))
    elem_first->next = ((void *)0);
  else
    elem_first->next = elem_sec->next;
  if (elem_first != ((void *)0) && elem_first->next != ((void *)0))
    elem_first->next->prev = elem_first;
  g_str->nb_of_elems = g_str->nb_of_elems - 1;
}

canonical_original_code:
void fusion_of_ptr(struct s_elem *elem_first, struct s_elem *elem_sec)
{
  elem_first->size = elem_first->size + sizeof(*elem_sec) + elem_sec->size;
  if (elem_sec == ((void *)0))
    elem_first->next = ((void *)0);
  else
    elem_first->next = elem_sec->next;
  if (elem_first != ((void *)0) && elem_first->next != ((void *)0))
    elem_first->next->prev = elem_first;
  g_str->nb_of_elems = g_str->nb_of_elems - 1;
}


decompiled_code:
__int64 __fastcall fusion_of_datas(__int64 a1)
{
__int64 v1; // rsi
__int64 v2; // rbp
__int64 result; // rax

*(_DWORD *)(a1 + 8) = 1;
v1 = *(_QWORD *)(a1 + 24);
v2 = *(_QWORD *)(a1 + 32);
if ( v1 && *(_DWORD *)(v1 + 8) == 1 )
result = fusion_of_ptr((_QWORD *)a1, (_QWORD *)v1);
if ( v2 )
{
if ( *(_DWORD *)(v2 + 8) == 1 )
result = fusion_of_ptr((_QWORD *)v2, (_QWORD *)a1);
}
return result;
}

original_code:
void fusion_of_datas(t_elem *elem_to_use)
{
  t_elem *next;
  t_elem *prev;
  elem_to_use->ptr_free = 1;
  next = elem_to_use->next;
  prev = elem_to_use->prev;
  if (elem_to_use != ((void *)0))
    {
      if (next != ((void *)0) && next->ptr_free == 1)
 fusion_of_ptr(elem_to_use, next);
      if (prev != ((void *)0) && prev->ptr_free == 1)
 fusion_of_ptr(prev, elem_to_use);
    }
}

canonical_original_code:
void fusion_of_datas(struct s_elem *elem_to_use)
{
  struct s_elem *next;
  struct s_elem *prev;
  elem_to_use->ptr_free = 1;
  next = elem_to_use->next;
  prev = elem_to_use->prev;
  if (elem_to_use != ((void *)0))
    {
      if (next != ((void *)0) && next->ptr_free == 1)
 fusion_of_ptr(elem_to_use, next);
      if (prev != ((void *)0) && prev->ptr_free == 1)
 fusion_of_ptr(prev, elem_to_use);
    }
}


free

decompiled_code:
void __fastcall free(__int64 a1)
{
__int64 v1; // rax

if ( a1 )
{
v1 = ret_metadata_of_ptr(a1);
fusion_of_datas(v1);
}
}

canonical_decompiled_code:
void __fastcall func3(__int64 a1)
{
__int64 v1; // rax

if ( a1 )
{
v1 = func0(a1);
func2(v1);
}
}

original_code:
void free(void *ptr)
{
  t_elem *elem_to_use;
  if (ptr != ((void *)0))
    {
      elem_to_use = ret_metadata_of_ptr(ptr);
      fusion_of_datas(elem_to_use);
    }
}

canonical_original_code:
void free(void *ptr)
{
  struct s_elem *elem_to_use;
  if (ptr != ((void *)0))
    {
      elem_to_use = ret_metadata_of_ptr(ptr);
      fusion_of_datas(elem_to_use);
    }
}

variable_types:
ptr
void *


original_code:
t_elem *refill_elem(void *ptr_of_elem_to_set, void *ptr_to_use,
                             t_elem *elem_to_fill, size_t size_to_set)
{
  if (ptr_of_elem_to_set == (void*)-1)
    return (((void *)0));
  elem_to_fill->size = size_to_set;
  elem_to_fill->ptr_free = 0;
  if (memcpy(ptr_of_elem_to_set, ptr_to_use, sizeof(*ptr_to_use)) == ((void *)0))
    return (((void *)0));
  elem_to_fill->ptr_of_elem = ptr_of_elem_to_set;
  return (elem_to_fill);
}

canonical_original_code:
struct s_elem *refill_elem(void *ptr_of_elem_to_set, void *ptr_to_use, struct s_elem *elem_to_fill, unsigned long size_to_set)
{
  if (ptr_of_elem_to_set == (void *)-1)
    return (((void *)0));
  elem_to_fill->size = size_to_set;
  elem_to_fill->ptr_free = 0;
  if (memcpy(ptr_of_elem_to_set, ptr_to_use, sizeof(*ptr_to_use)) == ((void *)0))
    return (((void *)0));
  elem_to_fill->ptr_of_elem = ptr_of_elem_to_set;
  return (elem_to_fill);
}


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

if ( (unsigned int)add_elem_in_list(*(unsigned int *)(g_str + 8LL)) == -1 )
return 0LL;
result = my_sbrk(a2);
if ( result == -1 )
result = 0LL;
return result;
}

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

if ( (unsigned int)add_elem_in_list(*(unsigned int *)(g_str + 8LL)) == -1 )
return 0LL;
result = my_sbrk(a2);
if ( result == -1 )
result = 0LL;
return result;
}

original_code:
void *check_add_elem_and_sbrk(void *ptr_to_ret, size_t size)
{
  if (add_elem_in_list(g_str->nb_of_elems) == -1)
    return (((void *)0));
 if ((ptr_to_ret = my_sbrk(size)) == (void*)-1)
    return (((void *)0));
  return (ptr_to_ret);
}

canonical_original_code:
void *check_add_elem_and_sbrk(void *ptr_to_ret, unsigned long size)
{
  if (add_elem_in_list(g_str->nb_of_elems) == -1)
    return (((void *)0));
 if ((ptr_to_ret = my_sbrk(size)) == (void *)-1)
    return (((void *)0));
  return (ptr_to_ret);
}


repo: Nanolat/c-callstack

decompiled_code:
__int64 so_topless_ranking_server()
{
puts("If you love me, you are in trouble, as I am married.");
fprintf(stderr, "Error(code:%d) at : %s (%s:%d)\n", 0xFFFFFFFFLL, "so_topless_ranking_server", "sample.c", 23LL);
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 func7()
{
puts("If you love me, you are in trouble, as I am married.");
fprintf(stderr, "Error(code:%d) at : %s (%s:%d)\n", 0xFFFFFFFFLL, "so_topless_ranking_server", "sample.c", 23LL);
return 0xFFFFFFFFLL;
}

original_code:
int so_topless_ranking_server() {
    printf("If you love me, you are in trouble, as I am married.\n");
    if ( 1 == 1 )
        { if ((-1)) { fprintf( stderr, "Error(code:%d) at : %s (%s:%d)\n", (-1), __FUNCTION__, "sample.c", 23); } return (-1); };
    { if ((0)) { fprintf( stderr, "Error(code:%d) at : %s (%s:%d)\n", (0), __FUNCTION__, "sample.c", 25); } return (0); };
}


decompiled_code:
__int64 nanolat_database()
{
unsigned int v0; // eax
unsigned int v1; // ebx

v0 = so_topless_ranking_server();
v1 = v0;
if ( v0 )
fprintf(stderr, "Error(code:%d) at : %s (%s:%d)\n", v0, "nanolat_database", "sample.c", 31LL);
return v1;
}

canonical_decompiled_code:
__int64 func8()
{
unsigned int v0; // eax
unsigned int v1; // ebx

v0 = func7();
v1 = v0;
if ( v0 )
fprintf(stderr, "Error(code:%d) at : %s (%s:%d)\n", v0, "nanolat_database", "sample.c", 31LL);
return v1;
}

original_code:
int nanolat_database()
{
    int ret = so_topless_ranking_server();
    if (ret) { if ((ret)) { fprintf( stderr, "Error(code:%d) at : %s (%s:%d)\n", (ret), __FUNCTION__, "sample.c", 31); } return (ret); };
    { if ((0)) { fprintf( stderr, "Error(code:%d) at : %s (%s:%d)\n", (0), __FUNCTION__, "sample.c", 33); } return (0); };
}

variable_types: ret int


decompiled_code:
__int64 nanolat_message_queue()
{
unsigned int v0; // eax
unsigned int v1; // ebx

v0 = nanolat_database();
v1 = v0;
if ( v0 )
fprintf(stderr, "Error(code:%d) at : %s (%s:%d)\n", v0, "nanolat_message_queue", "sample.c", 39LL);
return v1;
}

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

v0 = func8();
v1 = v0;
if ( v0 )
fprintf(stderr, "Error(code:%d) at : %s (%s:%d)\n", v0, "nanolat_message_queue", "sample.c", 39LL);
return v1;
}

original_code:
int nanolat_message_queue()
{
    int ret = nanolat_database();
    if (ret) { if ((ret)) { fprintf( stderr, "Error(code:%d) at : %s (%s:%d)\n", (ret), __FUNCTION__, "sample.c", 39); } return (ret); };
    { if ((0)) { fprintf( stderr, "Error(code:%d) at : %s (%s:%d)\n", (0), __FUNCTION__, "sample.c", 41); } return (0); };
}


main

canonical_name: main

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

v3 = nanolat_message_queue(argc, argv, envp);
v4 = v3;
if ( v3 )
fprintf(stderr, "Error(code:%d) at : %s (%s:%d)\n", v3, "main", "sample.c", 47LL);
return v4;
}

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

v3 = func9(argc, argv, envp);
v4 = v3;
if ( v3 )
fprintf(stderr, "Error(code:%d) at : %s (%s:%d)\n", v3, "main", "sample.c", 47LL);
return v4;
}

original_code:
int main(int argc, char * argv[]) {
    int ret = nanolat_message_queue();
    if (ret) { if ((ret)) { fprintf( stderr, "Error(code:%d) at : %s (%s:%d)\n", (ret), __FUNCTION__, "sample.c", 47); } return (ret); };
    { if ((0)) { fprintf( stderr, "Error(code:%d) at : %s (%s:%d)\n", (0), __FUNCTION__, "sample.c", 49); } return (0); };
}

canonical_original_code:
int main(int argc, char *argv[]) {
    int ret = nanolat_message_queue();
    if (ret) { if ((ret)) { fprintf( stderr, "Error(code:%d) at : %s (%s:%d)\n", (ret), __FUNCTION__, "sample.c", 47); } return (ret); };
    { if ((0)) { fprintf( stderr, "Error(code:%d) at : %s (%s:%d)\n", (0), __FUNCTION__, "sample.c", 49); } return (0); };
}

variable_types: argc int

variable_types:
argv
char *[]


blur

repo: NatTuck/cakemark

original_code:
void
blur(byte* im0, size_t ww, size_t hh, int sigma)
{
    int rr = 3 * sigma;
    double *bvec = malloc((2 * rr + 1) * sizeof(double));
    double bsum = 0.0;
    for (int kk = -rr; kk <= rr; ++kk) {
        int ii = kk + rr;
        bvec[ii] = gauss(kk, 0.0, sigma);
        bsum += bvec[ii];
    }
    for (int ii = 0; ii < 2 * rr + 1; ++ii) {
        bvec[ii] *= 1.0 / bsum;
    }
    byte* im1 = malloc(ww * hh * sizeof(byte));
    for (int ii = 0; ii < hh; ++ii) {
        for (int jj = 0; jj < ww; ++jj) {
            double p1 = 0.0;
            for (int kk = -rr; kk <= rr; ++kk) {
                int jj0 = clamp(jj + kk, 0, ww - 1);
                p1 += bvec[kk + rr] * im0[ww*ii + jj0];
            }
            im1[ww*ii + jj] = clamp(round(p1), 0, 255);
        }
    }
    for (int jj = 0; jj < ww; ++jj) {
        for (int ii = 0; ii < hh; ++ii) {
            double p0 = 0.0;
            for (int kk = -rr; kk <= rr; ++kk) {
                int ii0 = clamp(ii + kk, 0, hh - 1);
                p0 += bvec[kk + rr] * im1[ww*ii0 + jj];
            }
            im0[ww*ii + jj] = clamp(round(p0), 0, 255);
        }
    }
    free(im1);
    free(bvec);
}

canonical_original_code:
void blur(unsigned char *im0, unsigned long ww, unsigned long hh, int sigma)
{
    int rr = 3 * sigma;
    double *bvec = malloc((2 * rr + 1) * sizeof(double));
    double bsum = 0.0;
    for (int kk = -rr; kk <= rr; ++kk) {
        int ii = kk + rr;
        bvec[ii] = gauss(kk, 0.0, sigma);
        bsum += bvec[ii];
    }
    for (int ii = 0; ii < 2 * rr + 1; ++ii) {
        bvec[ii] *= 1.0 / bsum;
    }
    unsigned char *im1 = malloc(ww * hh * sizeof(byte));
    for (int ii = 0; ii < hh; ++ii) {
        for (int jj = 0; jj < ww; ++jj) {
            double p1 = 0.0;
            for (int kk = -rr; kk <= rr; ++kk) {
                int jj0 = clamp(jj + kk, 0, ww - 1);
                p1 += bvec[kk + rr] * im0[ww*ii + jj0];
            }
            im1[ww*ii + jj] = clamp(round(p1), 0, 255);
        }
    }
    for (int jj = 0; jj < ww; ++jj) {
        for (int ii = 0; ii < hh; ++ii) {
            double p0 = 0.0;
            for (int kk = -rr; kk <= rr; ++kk) {
                int ii0 = clamp(ii + kk, 0, hh - 1);
                p0 += bvec[kk + rr] * im1[ww*ii0 + jj];
            }
            im0[ww*ii + jj] = clamp(round(p0), 0, 255);
        }
    }
    free(im1);
    free(bvec);
}

variable_types:
ww
unsigned long

variable_types:
hh
unsigned long

variable_types: sigma int

variable_types: rr int

variable_types:
bvec
double *

variable_types: bsum double

variable_types: kk int

variable_types: ii int

variable_types: jj int


streq

decompiled_code:
_BOOL8 __fastcall streq(const char *a1, const char *a2)
{
return strcmp(a1, a2) == 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func0(const char *a1, const char *a2)
{
return strcmp(a1, a2) == 0;
}

original_code:
int
streq(const char* aa, const char* bb)
{
    return strcmp(aa, bb) == 0;
}

canonical_original_code:
int streq(char *aa, char *bb)
{
    return strcmp(aa, bb) == 0;
}

variable_types:
aa
char *

variable_types:
bb
char *


lstrdup

decompiled_code:
__int64 __fastcall lstrdup(const char *a1)
{
size_t v1; // r12
__int64 v2; // rbx

v1 = strlen(a1) + 1;
v2 = GC_malloc_atomic(v1);
strlcpy(v2, a1, v1);
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func1(const char *a1)
{
size_t v1; // r12
__int64 v2; // rbx

v1 = strlen(a1) + 1;
v2 = GC_malloc_atomic(v1);
strlcpy(v2, a1, v1);
return v2;
}

original_code:
char*
lstrdup(const char* aa)
{
    size_t size = strlen(aa) + 1;
    char* bb = (char*) GC_malloc_atomic(size);
    strlcpy(bb, aa, size);
    return bb;
}

canonical_original_code:
char *lstrdup(char *aa)
{
    unsigned long size = strlen(aa) + 1;
    char *bb = (char*) GC_malloc_atomic(size);
    strlcpy(bb, aa, size);
    return bb;
}


lsprintf

decompiled_code:
char *lsprintf(char *format, ...)
{
size_t v1; // rbx
char *v2; // rbp
__m128i v4; // [rsp+0h] [rbp-108h] BYREF
void *v5; // [rsp+10h] [rbp-F8h]
gcc_va_list arg; // [rsp+18h] [rbp-F0h] BYREF

va_start(arg, format);
v4 = _mm_loadu_si128((const __m128i *)arg);
v5 = arg[0].reg_save_area;
v1 = vsnprintf(0LL, 0LL, format, arg) + 1;
v2 = (char *)GC_malloc_atomic(v1);
vsnprintf(v2, v1, format, &v4);
return v2;
}

canonical_decompiled_code:
char *func2(char *format, ...)
{
size_t v1; // rbx
char *v2; // rbp
__m128i v4; // [rsp+0h] [rbp-108h] BYREF
void *v5; // [rsp+10h] [rbp-F8h]
gcc_va_list arg; // [rsp+18h] [rbp-F0h] BYREF

va_start(arg, format);
v4 = _mm_loadu_si128((const __m128i *)arg);
v5 = arg[0].reg_save_area;
v1 = vsnprintf(0LL, 0LL, format, arg) + 1;
v2 = (char *)GC_malloc_atomic(v1);
vsnprintf(v2, v1, format, &v4);
return v2;
}

original_code:
char*
lsprintf(const char* fmt, ...)
{
    va_list ap1;
    va_list ap2;
    __builtin_va_start(ap1,fmt);
    __builtin_va_copy(ap2,ap1);
    int size = 1 + vsnprintf(0, 0, fmt, ap1);
    char* outp = (char*) GC_malloc_atomic(size);
    vsnprintf(outp, size, fmt, ap2);
    __builtin_va_end(ap1);
    __builtin_va_end(ap2);
    return outp;
}

canonical_original_code:
char *lsprintf(char *fmt, ...)
{
    __builtin_va_list ap1;
    __builtin_va_list ap2;
    __builtin_va_start(ap1,fmt);
    __builtin_va_copy(ap2,ap1);
    int size = 1 + vsnprintf(0, 0, fmt, ap1);
    char *outp = (char*) GC_malloc_atomic(size);
    vsnprintf(outp, size, fmt, ap2);
    __builtin_va_end(ap1);
    __builtin_va_end(ap2);
    return outp;
}

variable_types:
fmt
char *

variable_types: size int

variable_types:
outp
char *


lchomp

decompiled_code:
const char *__fastcall lchomp(const char *a1)
{
const char *v1; // rbx
__int64 v2; // rax
const char *v3; // rdx
__int64 v4; // rax

v1 = (const char *)lstrdup(a1);
v2 = (int)(strlen(v1) - 1);
v3 = &v1[v2];
if ( v1[v2] == 10 )
{
v4 = (__int64)&v1[v2 - 1];
do
{
*v3 = 0;
v3 = (const char *)v4--;
}
while ( *(_BYTE *)(v4 + 1) == 10 );
}
return v1;
}

canonical_decompiled_code:
const char *__fastcall func4(const char *a1)
{
const char *v1; // rbx
__int64 v2; // rax
const char *v3; // rdx
__int64 v4; // rax

v1 = (const char *)func1(a1);
v2 = (int)(strlen(v1) - 1);
v3 = &v1[v2];
if ( v1[v2] == 10 )
{
v4 = (__int64)&v1[v2 - 1];
do
{
*v3 = 0;
v3 = (const char *)v4--;
}
while ( *(_BYTE *)(v4 + 1) == 10 );
}
return v1;
}

original_code:
char*
lchomp(const char* ss)
{
    char* yy = lstrdup(ss);
    int nn = strlen(yy);
    int ii = nn - 1;
    while (yy[ii] == '\n') {
        yy[ii] = '\0';
        ii -= 1;
    }
    return yy;
}

canonical_original_code:
char *lchomp(char *ss)
{
    char *yy = lstrdup(ss);
    int nn = strlen(yy);
    int ii = nn - 1;
    while (yy[ii] == '\n') {
        yy[ii] = '\0';
        ii -= 1;
    }
    return yy;
}

variable_types:
ss
char *

variable_types:
yy
char *

variable_types: nn int


lstripc

decompiled_code:
__int64 __fastcall lstripc(char a1, const char *a2)
{
void *v2; // rsp
size_t v3; // rbx
int v4; // er13
char v5; // al
char v7[15]; // [rsp+0h] [rbp-30h] BYREF

v2 = alloca(strlen(a2) + 10);
v3 = 0LL;
v4 = 0;
while ( strlen(a2) > v3 )
{
v5 = a2[v3];
if ( v5 != a1 )
v7[v4++] = v5;
++v3;
}
v7[v4] = 0;
return lstrdup(v7);
}

canonical_decompiled_code:
__int64 __fastcall func5(char a1, const char *a2)
{
void *v2; // rsp
size_t v3; // rbx
int v4; // er13
char v5; // al
char v7[15]; // [rsp+0h] [rbp-30h] BYREF

v2 = alloca(strlen(a2) + 10);
v3 = 0LL;
v4 = 0;
while ( strlen(a2) > v3 )
{
v5 = a2[v3];
if ( v5 != a1 )
v7[v4++] = v5;
++v3;
}
v7[v4] = 0;
return func1(v7);
}

original_code:
char*
lstripc(const char cc, const char* ss)
{
    char* yy = __builtin_alloca (strlen(ss) + 2);
    int jj = 0;
    for (int ii = 0; ii < strlen(ss); ++ii) {
        if (ss[ii] != cc) {
            yy[jj] = ss[ii];
            jj += 1;
        }
    }
    yy[jj] = 0;
    return lstrdup(yy);
}

canonical_original_code:
char *lstripc(char cc, char *ss)
{
    char *yy = __builtin_alloca (strlen(ss) + 2);
    int jj = 0;
    for (int ii = 0; ii < strlen(ss); ++ii) {
        if (ss[ii] != cc) {
            yy[jj] = ss[ii];
            jj += 1;
        }
    }
    yy[jj] = 0;
    return lstrdup(yy);
}

variable_types: cc char


lmemcpy

decompiled_code:
void *__fastcall lmemcpy(void *src, size_t n)
{
void *v2; // rax

v2 = (void *)GC_malloc(n);
return memcpy(v2, src, n);
}

canonical_decompiled_code:
void *__fastcall func6(void *src, size_t n)
{
void *v2; // rax

v2 = (void *)GC_malloc(n);
return memcpy(v2, src, n);
}

original_code:
void*
lmemcpy(void* src, size_t n)
{
    void* dest = GC_malloc(n);
    memcpy(dest, src, n);
    return dest;
}

canonical_original_code:
void *lmemcpy(void *src, unsigned long n)
{
    void *dest = GC_malloc(n);
    memcpy(dest, src, n);
    return dest;
}

variable_types:
src
void *

variable_types:
n
unsigned long

variable_types:
dest
void *


lslurp

decompiled_code:
__int64 __fastcall lslurp(char *a1)
{
__int64 v2; // [rsp+8h] [rbp-10h] BYREF

return lslurpb(a1, &v2);
}

canonical_decompiled_code:
__int64 __fastcall func9(char *a1)
{
__int64 v2; // [rsp+8h] [rbp-10h] BYREF

return func8(a1, &v2);
}

original_code:
char*
lslurp(const char* filename)
{
    size_t ignored;
    return (char*) lslurpb(filename, &ignored);
}

canonical_original_code:
char *lslurp(char *filename)
{
    unsigned long ignored;
    return (char *) lslurpb(filename, &ignored);
}

variable_types:
filename
char *

variable_types:
ignored
unsigned long


decompiled_code:
__int64 __fastcall lstrvec_alloc(int a1)
{
__int64 v1; // rbp

v1 = GC_malloc(16LL);
*(_DWORD *)v1 = a1;
if ( a1 )
*(_QWORD *)(v1 + 8) = GC_malloc(8LL * a1);
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func10(int a1)
{
__int64 v1; // rbp

v1 = GC_malloc(16LL);
*(_DWORD *)v1 = a1;
if ( a1 )
*(_QWORD *)(v1 + 8) = GC_malloc(8LL * a1);
return v1;
}

original_code:
lstrvec*
lstrvec_alloc(int size)
{
    lstrvec* vec = GC_malloc(sizeof(lstrvec));
    vec->size = size;
    if (size != 0)
        vec->xs = GC_malloc(size * sizeof(char*));
    return vec;
}

canonical_original_code:
struct lstrvec *lstrvec_alloc(int size)
{
    struct lstrvec *vec = GC_malloc(sizeof(lstrvec));
    vec->size = size;
    if (size != 0)
        vec->xs = GC_malloc(size * sizeof(char *));
    return vec;
}

variable_types: struct lstrvec { int size; char **xs; } *


decompiled_code:
__int64 __fastcall lstrvec_size(unsigned int *a1)
{
return *a1;
}

canonical_decompiled_code:
__int64 __fastcall func11(unsigned int *a1)
{
return *a1;
}

original_code:
int
lstrvec_size(lstrvec* vec)
{
    return vec->size;
}

canonical_original_code:
int lstrvec_size(struct lstrvec *vec)
{
    return vec->size;
}


decompiled_code:
__int64 __fastcall lstrvec_get(unsigned int *a1, int a2)
{
if ( a2 < 0 || (int)*a1 <= a2 )
{
fprintf(stderr, "lstrvec: Out of bounds get(%d) (size = %d).\n", (unsigned int)a2, *a1);
abort();
}
return lstrdup(*(const char **)(*((_QWORD *)a1 + 1) + 8LL * a2));
}

canonical_decompiled_code:
__int64 __fastcall func12(unsigned int *a1, int a2)
{
if ( a2 < 0 || (int)*a1 <= a2 )
{
fprintf(stderr, "lstrvec: Out of bounds get(%d) (size = %d).\n", (unsigned int)a2, *a1);
abort();
}
return func1(*(const char **)(*((_QWORD *)a1 + 1) + 8LL * a2));
}

original_code:
char*
lstrvec_get(lstrvec* vec, int ii)
{
    if (ii < 0 || ii > vec->size - 1) {
        fprintf(stderr, "lstrvec: Out of bounds get(%d) (size = %d).\n",
                ii, vec->size);
        abort();
    }
    return lstrdup(vec->xs[ii]);
}

canonical_original_code:
char *lstrvec_get(struct lstrvec *vec, int ii)
{
    if (ii < 0 || ii > vec->size - 1) {
        fprintf(stderr, "lstrvec: Out of bounds get(%d) (size = %d).\n",
                ii, vec->size);
        abort();
    }
    return lstrdup(vec->xs[ii]);
}

variable_types: ii int


decompiled_code:
__int64 __fastcall lstrvec_set(unsigned int *a1, int a2, const char *a3)
{
__int64 *v3; // rbx
__int64 result; // rax

if ( a2 < 0 || (int)*a1 <= a2 )
{
fprintf(stderr, "lstrvec: Out of bounds get(%d) (size = %d).\n", (unsigned int)a2, *a1);
abort();
}
v3 = (__int64 *)(*((_QWORD *)a1 + 1) + 8LL * a2);
result = lstrdup(a3);
*v3 = result;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func13(unsigned int *a1, int a2, const char *a3)
{
__int64 *v3; // rbx
__int64 result; // rax

if ( a2 < 0 || (int)*a1 <= a2 )
{
fprintf(stderr, "lstrvec: Out of bounds get(%d) (size = %d).\n", (unsigned int)a2, *a1);
abort();
}
v3 = (__int64 *)(*((_QWORD *)a1 + 1) + 8LL * a2);
result = func1(a3);
*v3 = result;
return result;
}

original_code:
void
lstrvec_set(lstrvec* vec, int ii, char* vv)
{
    if (ii < 0 || ii > vec->size - 1) {
        fprintf(stderr, "lstrvec: Out of bounds get(%d) (size = %d).\n",
                ii, vec->size);
        abort();
    }
    vec->xs[ii] = lstrdup(vv);
}

canonical_original_code:
void lstrvec_set(struct lstrvec *vec, int ii, char *vv)
{
    if (ii < 0 || ii > vec->size - 1) {
        fprintf(stderr, "lstrvec: Out of bounds get(%d) (size = %d).\n",
                ii, vec->size);
        abort();
    }
    vec->xs[ii] = lstrdup(vv);
}

variable_types:
vv
char *


decompiled_code:
_BOOL8 __fastcall lstrvec_contains(__int64 a1, const char *a2)
{
__int64 v2; // rbx
_BOOL8 result; // rax

if ( *(int *)a1 <= 0 )
return 0LL;
v2 = 0LL;
while ( 1 )
{
result = streq(a2, *(const char **)(*(_QWORD *)(a1 + 8) + 8 * v2));
if ( result )
break;
if ( *(_DWORD *)a1 <= (int)++v2 )
return result;
}
return 1LL;
}

canonical_decompiled_code:
_BOOL8 __fastcall func14(__int64 a1, const char *a2)
{
__int64 v2; // rbx
_BOOL8 result; // rax

if ( *(int *)a1 <= 0 )
return 0LL;
v2 = 0LL;
while ( 1 )
{
result = func0(a2, *(const char **)(*(_QWORD *)(a1 + 8) + 8 * v2));
if ( result )
break;
if ( *(_DWORD *)a1 <= (int)++v2 )
return result;
}
return 1LL;
}

original_code:
int
lstrvec_contains(lstrvec* vec, const char* ss)
{
    int ii;
    for (ii = 0; ii < vec->size; ++ii) {
        if (streq(ss, vec->xs[ii]))
            return 1;
    }
    return 0;
}

canonical_original_code:
int lstrvec_contains(struct lstrvec *vec, char *ss)
{
    int ii;
    for (ii = 0; ii < vec->size; ++ii) {
        if (streq(ss, vec->xs[ii]))
            return 1;
    }
    return 0;
}


lwords

decompiled_code:
unsigned int *__fastcall lwords(const char *a1)
{
const char *v1; // rbx
int v2; // eax
int v3; // er8
int v4; // er12
int j; // edx
const char *v6; // rcx
const char *v7; // rsi
__int64 v8; // rax
int v9; // edi
unsigned int *v10; // r13
int i; // ebp
const char *v12; // rax

v1 = (const char *)lstrdup(a1);
v2 = strlen(v1);
if ( v2 <= 0 )
{
v10 = (unsigned int *)lstrvec_alloc(1);
v4 = 0;
LABEL_10:
for ( i = 0; i <= v4; ++i )
{
v12 = (const char *)lstrdup(v1);
lstrvec_set(v10, i, v12);
for ( v1 += strlen(v1); !*v1; ++v1 )
;
}
return v10;
}
v3 = v2;
v4 = 0;
for ( j = 0; j < v3; ++j )
{
v6 = &v1[j];
if ( *v6 == 32 )
{
*v6 = 0;
++v4;
v7 = &v1[j + 1];
if ( *v7 == 32 )
{
v8 = 0LL;
v9 = j + 1;
do
{
j = v9 + v8;
v7[v8++] = 0;
}
while ( v6[v8 + 1] == 32 );
}
}
}
v10 = (unsigned int *)lstrvec_alloc(v4 + 1);
if ( v4 >= 0 )
goto LABEL_10;
return v10;
}

canonical_decompiled_code:
unsigned int *__fastcall func15(const char *a1)
{
const char *v1; // rbx
int v2; // eax
int v3; // er8
int v4; // er12
int j; // edx
const char *v6; // rcx
const char *v7; // rsi
__int64 v8; // rax
int v9; // edi
unsigned int *v10; // r13
int i; // ebp
const char *v12; // rax

v1 = (const char *)func1(a1);
v2 = strlen(v1);
if ( v2 <= 0 )
{
v10 = (unsigned int *)func10(1);
v4 = 0;
LABEL_10:
for ( i = 0; i <= v4; ++i )
{
v12 = (const char *)func1(v1);
func13(v10, i, v12);
for ( v1 += strlen(v1); !*v1; ++v1 )
;
}
return v10;
}
v3 = v2;
v4 = 0;
for ( j = 0; j < v3; ++j )
{
v6 = &v1[j];
if ( *v6 == 32 )
{
*v6 = 0;
++v4;
v7 = &v1[j + 1];
if ( *v7 == 32 )
{
v8 = 0LL;
v9 = j + 1;
do
{
j = v9 + v8;
v7[v8++] = 0;
}
while ( v6[v8 + 1] == 32 );
}
}
}
v10 = (unsigned int *)func10(v4 + 1);
if ( v4 >= 0 )
goto LABEL_10;
return v10;
}

original_code:
lstrvec*
lwords(const char* ss)
{
    char* aa = lstrdup(ss);
    int ii, jj;
    int nn = strlen(aa);
    int spaces = 0;
    lstrvec* xs;
    for (ii = 0; ii < nn; ++ii) {
        if (aa[ii] == ' ') {
            aa[ii] = '\0';
            spaces += 1;
            while (aa[ii + 1] == ' ') {
                ii += 1;
                aa[ii] = '\0';
            }
        }
    }
    xs = lstrvec_alloc(spaces + 1);
    for (ii = 0; ii < spaces + 1; ++ii) {
        lstrvec_set(xs, ii, lstrdup(aa));
        aa += strlen(aa);
        while(aa[0] == '\0')
            aa += 1;
    }
    return xs;
}

canonical_original_code:
struct lstrvec *lwords(char *ss)
{
    char *aa = lstrdup(ss);
    int ii; int jj;
    int nn = strlen(aa);
    int spaces = 0;
    struct lstrvec *xs;
    for (ii = 0; ii < nn; ++ii) {
        if (aa[ii] == ' ') {
            aa[ii] = '\0';
            spaces += 1;
            while (aa[ii + 1] == ' ') {
                ii += 1;
                aa[ii] = '\0';
            }
        }
    }
    xs = lstrvec_alloc(spaces + 1);
    for (ii = 0; ii < spaces + 1; ++ii) {
        lstrvec_set(xs, ii, lstrdup(aa));
        aa += strlen(aa);
        while(aa[0] == '\0')
            aa += 1;
    }
    return xs;
}

variable_types:
aa
char *

variable_types: jj int

variable_types: spaces int

return_type: struct lstrvec { int size; char **xs; } *


lsplitc

decompiled_code:
unsigned int *__fastcall lsplitc(char a1, const char *a2)
{
const char *v2; // rbx
int v3; // eax
int v4; // edx
const char *v5; // rax
__int64 v6; // rdx
int v7; // er12
unsigned int *v8; // r13
int i; // ebp
const char *v10; // rax

v2 = (const char *)lstrdup(a2);
v3 = strlen(v2);
if ( v3 <= 0 )
{
v8 = (unsigned int *)lstrvec_alloc(1);
v7 = 1;
LABEL_7:
for ( i = 0; i < v7; ++i )
{
v10 = (const char *)lstrdup(v2);
lstrvec_set(v8, i, v10);
for ( v2 += strlen(v2); !*v2; ++v2 )
;
}
return v8;
}
v4 = v3;
v5 = v2;
v6 = (__int64)&v2[v4 - 1 + 1];
v7 = 1;
do
{
if ( *v5 == a1 )
{
*v5 = 0;
++v7;
}
++v5;
}
while ( v5 != (const char *)v6 );
v8 = (unsigned int *)lstrvec_alloc(v7);
if ( v7 > 0 )
goto LABEL_7;
return v8;
}

canonical_decompiled_code:
unsigned int *__fastcall func16(char a1, const char *a2)
{
const char *v2; // rbx
int v3; // eax
int v4; // edx
const char *v5; // rax
__int64 v6; // rdx
int v7; // er12
unsigned int *v8; // r13
int i; // ebp
const char *v10; // rax

v2 = (const char *)func1(a2);
v3 = strlen(v2);
if ( v3 <= 0 )
{
v8 = (unsigned int *)func10(1);
v7 = 1;
LABEL_7:
for ( i = 0; i < v7; ++i )
{
v10 = (const char *)func1(v2);
func13(v8, i, v10);
for ( v2 += strlen(v2); !*v2; ++v2 )
;
}
return v8;
}
v4 = v3;
v5 = v2;
v6 = (__int64)&v2[v4 - 1 + 1];
v7 = 1;
do
{
if ( *v5 == a1 )
{
*v5 = 0;
++v7;
}
++v5;
}
while ( v5 != (const char *)v6 );
v8 = (unsigned int *)func10(v7);
if ( v7 > 0 )
goto LABEL_7;
return v8;
}

original_code:
lstrvec*
lsplitc(const char cc, const char* ss)
{
    char* aa = lstrdup(ss);
    int ii, jj;
    int nn = strlen(aa);
    int slots = 1;
    lstrvec* xs;
    for (ii = 0; ii < nn; ++ii) {
        if (aa[ii] == cc) {
            aa[ii] = '\0';
            slots += 1;
        }
    }
    xs = lstrvec_alloc(slots);
    for (ii = 0; ii < slots; ++ii) {
        lstrvec_set(xs, ii, lstrdup(aa));
        aa += strlen(aa);
        while(aa[0] == '\0')
            aa += 1;
    }
    return xs;
}

canonical_original_code:
struct lstrvec *lsplitc(char cc, char *ss)
{
    char *aa = lstrdup(ss);
    int ii; int jj;
    int nn = strlen(aa);
    int slots = 1;
    struct lstrvec *xs;
    for (ii = 0; ii < nn; ++ii) {
        if (aa[ii] == cc) {
            aa[ii] = '\0';
            slots += 1;
        }
    }
    xs = lstrvec_alloc(slots);
    for (ii = 0; ii < slots; ++ii) {
        lstrvec_set(xs, ii, lstrdup(aa));
        aa += strlen(aa);
        while(aa[0] == '\0')
            aa += 1;
    }
    return xs;
}

variable_types: slots int


decompiled_code:
__int64 __fastcall mb_iterate(int a1, int a2, int a3, int a4, int a5, float a6, float a7, float a8)
{
float v8; // xmm6_4
float v9; // xmm5_4
__int64 result; // rax
float v11; // xmm0_4
__int128 v12; // xmm3
float v13; // xmm4_4
__int128 v14; // xmm1
float v15; // xmm2_4

v8 = (float)((float)((float)((float)((float)a4 / (float)a1) * 3.5) - 2.5) / a8) - a6;
v9 = (float)((float)((float)((float)((float)a3 / (float)a2) + (float)((float)a3 / (float)a2)) - 1.0) / a8) - a7;
if ( a5 <= 0 )
return 0LL;
LODWORD(result) = 0;
v11 = 0.0;
LODWORD(v12) = 0;
v13 = 0.0;
v14 = 0LL;
do
{
v15 = *(float *)&v12;
*(float *)&v14 = *(float *)&v14 + v8;
v12 = v14;
*(float *)&v12 = *(float *)&v14 - v13;
v11 = (float)(v11 * (float)(v15 + v15)) + v9;
result = (unsigned int)(result + 1);
v14 = v12;
*(float *)&v14 = *(float *)&v12 * *(float *)&v12;
v13 = v11 * v11;
}
while ( (float)((float)(*(float *)&v12 * *(float *)&v12) + (float)(v11 * v11)) < 4.0 && a5 > (int)result );
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1, int a2, int a3, int a4, int a5, float a6, float a7, float a8)
{
float v8; // xmm6_4
float v9; // xmm5_4
__int64 result; // rax
float v11; // xmm0_4
__int128 v12; // xmm3
float v13; // xmm4_4
__int128 v14; // xmm1
float v15; // xmm2_4

v8 = (float)((float)((float)((float)((float)a4 / (float)a1) * 3.5) - 2.5) / a8) - a6;
v9 = (float)((float)((float)((float)((float)a3 / (float)a2) + (float)((float)a3 / (float)a2)) - 1.0) / a8) - a7;
if ( a5 <= 0 )
return 0LL;
LODWORD(result) = 0;
v11 = 0.0;
LODWORD(v12) = 0;
v13 = 0.0;
v14 = 0LL;
do
{
v15 = *(float *)&v12;
*(float *)&v14 = *(float *)&v14 + v8;
v12 = v14;
*(float *)&v12 = *(float *)&v14 - v13;
v11 = (float)(v11 * (float)(v15 + v15)) + v9;
result = (unsigned int)(result + 1);
v14 = v12;
*(float *)&v14 = *(float *)&v12 * *(float *)&v12;
v13 = v11 * v11;
}
while ( (float)((float)(*(float *)&v12 * *(float *)&v12) + (float)(v11 * v11)) < 4.0 && a5 > (int)result );
return result;
}

original_code:
uint32_t
mb_iterate(int ww, int hh, int ii, int jj, float xc, float yc, float zz, int max)
{
    float x0 = (3.5f * ((float)jj/(float)ww) - 2.5f) / zz - xc;
    float y0 = (2.0f * ((float)ii/(float)hh) - 1.0f) / zz - yc;
    float xx = 0.0f;
    float yy = 0.0f;
    int kk = 0;
    while ((xx * xx + yy * yy < 4.0f) && (kk < max)) {
        float x1 = x0 + xx * xx - yy * yy;
        yy = y0 + 2 * xx * yy;
        xx = x1;
        kk += 1;
    }
    return kk;
}

canonical_original_code:
unsigned int mb_iterate(int ww, int hh, int ii, int jj, float xc, float yc, float zz, int max)
{
    float x0 = (3.5f * ((float)jj/(float)ww) - 2.5f) / zz - xc;
    float y0 = (2.0f * ((float)ii/(float)hh) - 1.0f) / zz - yc;
    float xx = 0.0f;
    float yy = 0.0f;
    int kk = 0;
    while ((xx * xx + yy * yy < 4.0f) && (kk < max)) {
        float x1 = x0 + xx * xx - yy * yy;
        yy = y0 + 2 * xx * yy;
        xx = x1;
        kk += 1;
    }
    return kk;
}

variable_types: ww int

variable_types: hh int

variable_types: xc float

variable_types: yc float

variable_types: zz float

variable_types: max int

variable_types: xx float

variable_types: yy float

variable_types: kk int

return_type: unsigned int


original_code:
void*
mb_job_main(void* info_ptr)
{
    mb_job_info* info = (mb_job_info*)info_ptr;
    for (int ii = info->job; ii < info->hh; ii += 144) {
        for (int jj = 0; jj < info->ww; ++jj) {
            uint32_t iters = mb_iterate(info->ww, info->hh, ii, jj, info->xc,
                    info->yc, info->zz, info->max);
            info->image[ii * info->ww + jj] = iters * (2 << 25) / (info->max + 2);
        }
    }
    return 0;
}

canonical_original_code:
void *mb_job_main(void *info_ptr)
{
    struct mb_job_info *info = (mb_job_info*)info_ptr;
    for (int ii = info->job; ii < info->hh; ii += 144) {
        for (int jj = 0; jj < info->ww; ++jj) {
            unsigned int iters = mb_iterate(info->ww, info->hh, ii, jj, info->xc,
                    info->yc, info->zz, info->max);
            info->image[ii * info->ww + jj] = iters * (2 << 25) / (info->max + 2);
        }
    }
    return 0;
}

variable_types: struct mb_job_info { int job; int ww; int hh; float xc; float yc; float zz; int max; unsigned int *image; } *

variable_types:
iters
unsigned int


mandelbrot

decompiled_code:
int __fastcall mandelbrot(__int64 a1, int a2, int a3, int a4, float a5, float a6, float a7)
{
char *v7; // rbx
pthread_t *v8; // r12
pthread_t *v9; // r13
int i; // ebp
int result; // eax
char arg; // [rsp+20h] [rbp-1B38h] BYREF
pthread_t newthread[144]; // [rsp+16A0h] [rbp-4B8h] BYREF
__int64 v16; // [rsp+1B20h] [rbp-38h] BYREF

printf("mandelbrot at %.04f, %.04f * %.04f\n", a5, a6, a7);
v7 = &arg;
v8 = newthread;
v9 = newthread;
for ( i = 0; i != 144; ++i )
{
*(_DWORD *)v7 = i;
*((_DWORD *)v7 + 1) = a2;
*((_DWORD *)v7 + 2) = a3;
*((float *)v7 + 3) = a5;
*((float *)v7 + 4) = a6;
*((float *)v7 + 5) = a7;
*((_DWORD *)v7 + 6) = a4;
*((_QWORD *)v7 + 4) = a1;
if ( pthread_create(v9, 0LL, mb_job_main, v7) )
_assert_fail("rv == 0", "mandelbrot.c", 0x4Fu, "mandelbrot");
v7 += 40;
++v9;
}
do
{
result = pthread_join(*v8, 0LL);
if ( result )
_assert_fail("rv == 0", "mandelbrot.c", 0x54u, "mandelbrot");
++v8;
}
while ( v8 != (pthread_t *)&v16 );
return result;
}

canonical_decompiled_code:
int __fastcall func2(__int64 a1, int a2, int a3, int a4, float a5, float a6, float a7)
{
char *v7; // rbx
pthread_t *v8; // r12
pthread_t *v9; // r13
int i; // ebp
int result; // eax
char arg; // [rsp+20h] [rbp-1B38h] BYREF
pthread_t newthread[144]; // [rsp+16A0h] [rbp-4B8h] BYREF
__int64 v16; // [rsp+1B20h] [rbp-38h] BYREF

printf("mandelbrot at %.04f, %.04f * %.04f\n", a5, a6, a7);
v7 = &arg;
v8 = newthread;
v9 = newthread;
for ( i = 0; i != 144; ++i )
{
*(_DWORD *)v7 = i;
*((_DWORD *)v7 + 1) = a2;
*((_DWORD *)v7 + 2) = a3;
*((float *)v7 + 3) = a5;
*((float *)v7 + 4) = a6;
*((float *)v7 + 5) = a7;
*((_DWORD *)v7 + 6) = a4;
*((_QWORD *)v7 + 4) = a1;
if ( pthread_create(v9, 0LL, mb_job_main, v7) )
_assert_fail("rv == 0", "mandelbrot.c", 0x4Fu, "mandelbrot");
v7 += 40;
++v9;
}
do
{
result = pthread_join(*v8, 0LL);
if ( result )
_assert_fail("rv == 0", "mandelbrot.c", 0x54u, "mandelbrot");
++v8;
}
while ( v8 != (pthread_t *)&v16 );
return result;
}

original_code:
void
mandelbrot(uint32_t* image, int ww, int hh, float xx, float yy, float zz, int max)
{
    pthread_t jobs[144];
    mb_job_info infos[144];
    int rv, ii;
    printf("mandelbrot at %.04f, %.04f * %.04f\n", xx, yy, zz);
    for (ii = 0; ii < 144; ++ii) {
        infos[ii].job = ii;
        infos[ii].ww = ww;
        infos[ii].hh = hh;
        infos[ii].xc = xx;
        infos[ii].yc = yy;
        infos[ii].zz = zz;
        infos[ii].max = max;
        infos[ii].image = image;
        rv = pthread_create(&(jobs[ii]), 0, mb_job_main, &(infos[ii]));
        ((void) sizeof ((rv == 0) ? 1 : 0), __extension__ ({ if (rv == 0) ; else __assert_fail ("rv == 0", "mandelbrot.c", 79, __extension__ __PRETTY_FUNCTION__); }));
    }
    for (ii = 0; ii < 144; ++ii) {
        rv = pthread_join(jobs[ii], 0);
        ((void) sizeof ((rv == 0) ? 1 : 0), __extension__ ({ if (rv == 0) ; else __assert_fail ("rv == 0", "mandelbrot.c", 84, __extension__ __PRETTY_FUNCTION__); }));
    }
}

canonical_original_code:
void mandelbrot(unsigned int *image, int ww, int hh, float xx, float yy, float zz, int max)
{
    unsigned long jobs[144];
    struct mb_job_info infos[144];
    int rv; int ii;
    printf("mandelbrot at %.04f, %.04f * %.04f\n", xx, yy, zz);
    for (ii = 0; ii < 144; ++ii) {
        infos[ii].job = ii;
        infos[ii].ww = ww;
        infos[ii].hh = hh;
        infos[ii].xc = xx;
        infos[ii].yc = yy;
        infos[ii].zz = zz;
        infos[ii].max = max;
        infos[ii].image = image;
        rv = pthread_create(&(jobs[ii]), 0, mb_job_main, &(infos[ii]));
        ((void) sizeof ((rv == 0) ? 1 : 0), __extension__ ({ if (rv == 0) ; else __assert_fail ("rv == 0", "mandelbrot.c", 79, __extension__ __PRETTY_FUNCTION__); }));
    }
    for (ii = 0; ii < 144; ++ii) {
        rv = pthread_join(jobs[ii], 0);
        ((void) sizeof ((rv == 0) ? 1 : 0), __extension__ ({ if (rv == 0) ; else __assert_fail ("rv == 0", "mandelbrot.c", 84, __extension__ __PRETTY_FUNCTION__); }));
    }
}

variable_types:
image
unsigned int *

variable_types:
jobs
unsigned long [144]

variable_types: struct mb_job_info { int job; int ww; int hh; float xc; float yc; float zz; int max; unsigned int *image; } [144]

variable_types: rv int

variable_types: ii int


decompiled_code:
void __fastcall __noreturn cake_carp(const char *a1, unsigned int a2, const char *a3)
{
fprintf(stderr, "\n carp at %s:%d\n%s\n\n", a1, a2, a3);
fflush(stderr);
fflush(stdout);
abort();
}

canonical_decompiled_code:
void __fastcall __noreturn func0(const char *a1, unsigned int a2, const char *a3)
{
fprintf(stderr, "\n carp at %s:%d\n%s\n\n", a1, a2, a3);
fflush(stderr);
fflush(stdout);
abort();
}

original_code:
void
cake_carp(const char* file, int line, const char* msg)
{
    fprintf(stderr, "\n carp at %s:%d\n%s\n\n", file, line, msg);
    fflush(stderr);
    fflush(stdout);
    abort();
}

canonical_original_code:
void cake_carp(char *file, int line, char *msg)
{
    fprintf(stderr, "\n carp at %s:%d\n%s\n\n", file, line, msg);
    fflush(stderr);
    fflush(stdout);
    abort();
}

variable_types:
file
char *

variable_types: line int

variable_types:
msg
char *


memeq

decompiled_code:
_BOOL8 __fastcall memeq(const void *a1, const void *a2, size_t a3)
{
return memcmp(a1, a2, a3) == 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func1(const void *a1, const void *a2, size_t a3)
{
return memcmp(a1, a2, a3) == 0;
}

original_code:
int
memeq(const void* aa, const void* bb, size_t nn)
{
    return memcmp(aa, bb, nn) == 0;
}

canonical_original_code:
int memeq(void *aa, void *bb, unsigned long nn)
{
    return memcmp(aa, bb, nn) == 0;
}

variable_types:
aa
void *

variable_types:
bb
void *

variable_types:
nn
unsigned long


decompiled_code:
int __fastcall cake_timer_reset(struct timespec *tp)
{
return clock_gettime(4, tp);
}

canonical_decompiled_code:
int __fastcall func1(struct timespec *tp)
{
return clock_gettime(4, tp);
}

original_code:
inline static
void
cake_timer_reset(cake_timer* tt)
{
    cake_timer_init();
    clock_gettime(4, &(tt->ts));
}

canonical_original_code:
inline static void cake_timer_reset(struct cake_timer *tt)
{
    cake_timer_init();
    clock_gettime(4, &(tt->ts));
}

variable_types: struct cake_timer { struct timespec { long tv_sec; long tv_nsec; } ts; } *

user_defined_types: struct cake_timer { struct timespec ts; }


decompiled_code:
double __fastcall cake_timer_read(_QWORD *a1)
{
double v1; // rbx
struct timespec v3; // [rsp+0h] [rbp-18h] BYREF

clock_gettime(4, &v3);
v1 = cake_timer_ts_to_double(a1);
return cake_timer_ts_to_double(&v3) - v1;
}

canonical_decompiled_code:
double __fastcall func2(_QWORD *a1)
{
double v1; // rbx
struct timespec v3; // [rsp+0h] [rbp-18h] BYREF

clock_gettime(4, &v3);
v1 = func0(a1);
return func0(&v3) - v1;
}

original_code:
inline static
double
cake_timer_read(cake_timer* tt)
{
    struct timespec ts1;
    clock_gettime(4, &ts1);
    double ss0 = cake_timer_ts_to_double(&(tt->ts));
    double ss1 = cake_timer_ts_to_double(&ts1);
    return ss1 - ss0;
}

canonical_original_code:
inline static double cake_timer_read(struct cake_timer *tt)
{
    struct timespec ts1;
    clock_gettime(4, &ts1);
    double ss0 = cake_timer_ts_to_double(&(tt->ts));
    double ss1 = cake_timer_ts_to_double(&ts1);
    return ss1 - ss0;
}

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

return_type: double


decompiled_code:
_QWORD *alloc_matrix()
{
_QWORD *v0; // rax
_QWORD *v1; // rcx
_QWORD *v2; // rdx

v0 = malloc(0x80000uLL);
v1 = v0;
v2 = v0 + 0x10000;
do
*v0++ = 0LL;
while ( v0 != v2 );
return v1;
}

canonical_decompiled_code:
_QWORD *func4()
{
_QWORD *v0; // rax
_QWORD *v1; // rcx
_QWORD *v2; // rdx

v0 = malloc(0x80000uLL);
v1 = v0;
v2 = v0 + 0x10000;
do
*v0++ = 0LL;
while ( v0 != v2 );
return v1;
}

original_code:
double*
alloc_matrix()
{
    double* mm = (double*) malloc((256 * 256 * sizeof(double)));
    for (int ii = 0; ii < (256 * 256); ++ii)
        mm[ii] = 0.0;
    return mm;
}

canonical_original_code:
double *alloc_matrix()
{
    double *mm = (double*) malloc((256 * 256 * sizeof(double)));
    for (int ii = 0; ii < (256 * 256); ++ii)
        mm[ii] = 0.0;
    return mm;
}

variable_types:
mm
double *

return_type: double *


decompiled_code:
_QWORD *alloc_identity_matrix()
{
_QWORD *v0; // rax
_QWORD *v1; // rcx
_QWORD *v2; // rdx

v0 = alloc_matrix();
v1 = v0;
v2 = v0 + 65792;
do
{
*v0 = LC2;
v0 += 257;
}
while ( v0 != v2 );
return v1;
}

original_code:
double*
alloc_identity_matrix()
{
    double* mm = alloc_matrix();
    for (int ii = 0; ii < 256; ++ii)
        mm[ii * 256 + ii] = 1.0;
    return mm;
}

canonical_original_code:
double *alloc_identity_matrix()
{
    double *mm = alloc_matrix();
    for (int ii = 0; ii < 256; ++ii)
        mm[ii * 256 + ii] = 1.0;
    return mm;
}


decompiled_code:
double *alloc_random_matrix()
{
double *v0; // r12
double *v1; // rbx

v0 = (double *)alloc_matrix();
v1 = v0;
do
*v1++ = rand48();
while ( v1 != v0 + 0x10000 );
return v0;
}

canonical_decompiled_code:
double *func6()
{
double *v0; // r12
double *v1; // rbx

v0 = (double *)func4();
v1 = v0;
do
*v1++ = func3();
while ( v1 != v0 + 0x10000 );
return v0;
}

original_code:
double*
alloc_random_matrix()
{
    double* mm = alloc_matrix();
    for (int ii = 0; ii < (256 * 256); ++ii)
        mm[ii] = rand48();
    return mm;
}

canonical_original_code:
double *alloc_random_matrix()
{
    double *mm = alloc_matrix();
    for (int ii = 0; ii < (256 * 256); ++ii)
        mm[ii] = rand48();
    return mm;
}


decompiled_code:
__int64 __fastcall matrix_eq(__int64 a1, __int64 a2)
{
__int64 v2; // rax
double v3; // xmm0_8
double v4; // xmm1_8

v2 = 0LL;
while ( 1 )
{
v3 = *(double *)(a1 + 8 * v2);
v4 = *(double *)(a2 + 8 * v2);
if ( v3 != v4 )
break;
if ( ++v2 == 0x10000 )
return 1LL;
}
printf("Error at %d: %.02f != %.02f\n", (unsigned int)v2, v3, v4);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, __int64 a2)
{
__int64 v2; // rax
double v3; // xmm0_8
double v4; // xmm1_8

v2 = 0LL;
while ( 1 )
{
v3 = *(double *)(a1 + 8 * v2);
v4 = *(double *)(a2 + 8 * v2);
if ( v3 != v4 )
break;
if ( ++v2 == 0x10000 )
return 1LL;
}
printf("Error at %d: %.02f != %.02f\n", (unsigned int)v2, v3, v4);
return 0LL;
}

original_code:
int
matrix_eq(double* aa, double* bb)
{
    for (int ii = 0; ii < (256 * 256); ++ii) {
        if (aa[ii] != bb[ii]) {
            printf("Error at %d: %.02f != %.02f\n",
                    ii, aa[ii], bb[ii]);
            return 0;
        }
    }
    return 1;
}

canonical_original_code:
int matrix_eq(double *aa, double *bb)
{
    for (int ii = 0; ii < (256 * 256); ++ii) {
        if (aa[ii] != bb[ii]) {
            printf("Error at %d: %.02f != %.02f\n",
                    ii, aa[ii], bb[ii]);
            return 0;
        }
    }
    return 1;
}

variable_types:
aa
double *

variable_types:
bb
double *


decompiled_code:
double rand48()
{
if ( !seeded_1 )
{
seed_0[2] = getpid();
seeded_1 = 1;
}
return erand48(seed_0);
}

canonical_decompiled_code:
double func3()
{
if ( !seeded_1 )
{
seed_0[2] = getpid();
seeded_1 = 1;
}
return erand48(seed_0);
}

original_code:
double
rand48()
{
    static unsigned short seed[3] = { 50, 461, 0 };
    static int seeded = 0;
    if (seeded == 0) {
        seed[2] = (short)getpid();
        seeded = 1;
    }
    return (double) erand48(seed);
}

variable_types:
seed
unsigned short [3]

variable_types: seeded int


decompiled_code:
int __fastcall print_matrix(__int64 a1)
{
double *v1; // rbp
double *v2; // rbx

v1 = (double *)(a1 + 2048);
do
{
v2 = v1 - 256;
do
printf("%.02f ", *v2++);
while ( v2 != v1 );
putchar(10);
v1 += 256;
}
while ( v1 != (double *)(a1 + 526336) );
return putchar(10);
}

original_code:
void
print_matrix(double* mm)
{
    for (int ii = 0; ii < 256; ++ii) {
        for (int jj = 0; jj < 256; ++jj) {
            printf("%.02f ", mm[ii * 256 + jj]);
        }
        printf("\n");
    }
    printf("\n");
}

canonical_original_code:
void print_matrix(double *mm)
{
    for (int ii = 0; ii < 256; ++ii) {
        for (int jj = 0; jj < 256; ++jj) {
            printf("%.02f ", mm[ii * 256 + jj]);
        }
        printf("\n");
    }
    printf("\n");
}

variable_types: jj int


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // er13
char *v4; // rax
double *v5; // rbp
_QWORD *v6; // r12
_QWORD *v7; // rbx
double v8; // xmm0_8
struct timespec v10[3]; // [rsp+0h] [rbp-38h] BYREF

v3 = 256;
if ( getenv("NUMBER_NOT_USED") )
{
v4 = getenv("NUMBER_NOT_USED");
v3 = atoi(v4);
}
v5 = alloc_random_matrix();
v6 = alloc_identity_matrix();
v7 = alloc_matrix();
cake_timer_reset(v10);
mmul(v7, v6, v5, v3);
v8 = cake_timer_read(v10);
if ( (unsigned int)matrix_eq((__int64)v5, (__int64)v7) )
puts("[cake: OK]\nresult good");
else
puts("result bad =(");
printf("time: %.04f\n", v8);
free(v6);
free(v5);
free(v7);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // er13
char *v4; // rax
double *v5; // rbp
_QWORD *v6; // r12
_QWORD *v7; // rbx
double v8; // xmm0_8
struct timespec v10[3]; // [rsp+0h] [rbp-38h] BYREF

v3 = 256;
if ( getenv("NUMBER_NOT_USED") )
{
v4 = getenv("NUMBER_NOT_USED");
v3 = atoi(v4);
}
v5 = func6();
v6 = func5();
v7 = func4();
func1(v10);
mmul(v7, v6, v5, v3);
v8 = func2(v10);
if ( (unsigned int)func7((__int64)v5, (__int64)v7) )
puts("[cake: OK]\nresult good");
else
puts("result bad =(");
printf("time: %.04f\n", v8);
free(v6);
free(v5);
free(v7);
return 0;
}

original_code:
int
main(int argc, char* argv[])
{
    int nn = 256;
    if (getenv("NUMBER_NOT_USED"))
        nn = atoi(getenv("NUMBER_NOT_USED"));
    double* aa = alloc_random_matrix();
    double* bb = alloc_identity_matrix();
    double* cc = alloc_matrix();
    cake_timer tm;
    cake_timer_reset(&tm);
    mmul(cc, bb, aa, nn);
    double secs = cake_timer_read(&tm);
    if (matrix_eq(aa, cc))
        printf("[cake: OK]\nresult good\n");
    else
        printf("result bad =(\n");
    printf("time: %.04f\n", secs);
    free(bb);
    free(aa);
    free(cc);
    return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
    int nn = 256;
    if (getenv("NUMBER_NOT_USED"))
        nn = atoi(getenv("NUMBER_NOT_USED"));
    double *aa = alloc_random_matrix();
    double *bb = alloc_identity_matrix();
    double *cc = alloc_matrix();
    struct cake_timer tm;
    cake_timer_reset(&tm);
    mmul(cc, bb, aa, nn);
    double secs = cake_timer_read(&tm);
    if (matrix_eq(aa, cc))
        printf("[cake: OK]\nresult good\n");
    else
        printf("result bad =(\n");
    printf("time: %.04f\n", secs);
    free(bb);
    free(aa);
    free(cc);
    return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: nn int

variable_types:
cc
double *

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

variable_types: secs double


decompiled_code:
__int64 __fastcall cache_get(__int64 a1, __int64 a2)
{
_QWORD *v2; // rbx
int i; // ebp

if ( !a2 )
cake_carp("file_hash.c", 39LL, "Why are we looking up a size 0 thing?");
v2 = cache;
for ( i = 0; i != 10; ++i )
{
if ( *v2 == a2 && (unsigned int)memeq(v2[1], a1, a2) )
return cache[3 * i + 2];
v2 += 3;
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int64 a2)
{
_QWORD *v2; // rbx
int i; // ebp

if ( !a2 )
cake_carp("file_hash.c", 39LL, "Why are we looking up a size 0 thing?");
v2 = cache;
for ( i = 0; i != 10; ++i )
{
if ( *v2 == a2 && (unsigned int)memeq(v2[1], a1, a2) )
return cache[3 * i + 2];
v2 += 3;
}
return 0LL;
}

original_code:
static
char*
cache_get(const char* data, size_t size)
{
    if (size == 0)
        cake_carp("file_hash.c", 39, ("Why are we looking up a size 0 thing?"));
    for (int ii = 0; ii < 10; ++ii) {
        if (cache[ii].size != size)
            continue;
        if (memeq(cache[ii].data, data, size))
            return cache[ii].hash;
    }
    return 0;
}

canonical_original_code:
static char *cache_get(char *data, unsigned long size)
{
    if (size == 0)
        cake_carp("file_hash.c", 39, ("Why are we looking up a size 0 thing?"));
    for (int ii = 0; ii < 10; ++ii) {
        if (cache[ii].size != size)
            continue;
        if (memeq(cache[ii].data, data, size))
            return cache[ii].hash;
    }
    return 0;
}

variable_types:
data
char *

variable_types:
size
unsigned long

variable_types: ii int


decompiled_code:
__int64 __fastcall cache_put(void *src, size_t n, __int64 a3)
{
int v3; // ebx
__int64 v4; // r13
__int64 v5; // rbp
void *v6; // rax
__int64 result; // rax

v3 = cache_next;
v4 = cache_next;
v5 = 2LL * cache_next;
cache[3 * cache_next] = n;
v6 = (void *)GC_malloc_atomic(n);
cache[v5 + 1 + v4] = v6;
memcpy(v6, src, n);
cache[v4 + 2 + v5] = lstrdup(a3);
result = (unsigned int)(10 * (++v3 / 10));
cache_next = v3 % 10;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(void *src, size_t n, __int64 a3)
{
int v3; // ebx
__int64 v4; // r13
__int64 v5; // rbp
void *v6; // rax
__int64 result; // rax

v3 = cache_next;
v4 = cache_next;
v5 = 2LL * cache_next;
cache[3 * cache_next] = n;
v6 = (void *)GC_malloc_atomic(n);
cache[v5 + 1 + v4] = v6;
memcpy(v6, src, n);
cache[v4 + 2 + v5] = lstrdup(a3);
result = (unsigned int)(10 * (++v3 / 10));
cache_next = v3 % 10;
return result;
}

original_code:
static
void
cache_put(const char* data, size_t size, const char* hash)
{
    int nn = cache_next;
    cache[nn].size = size;
    cache[nn].data = GC_malloc_atomic(size);
    memcpy(cache[nn].data, data, size);
    cache[nn].hash = lstrdup(hash);
    cache_next = (nn + 1) % 10;
}

canonical_original_code:
static void cache_put(char *data, unsigned long size, char *hash)
{
    int nn = cache_next;
    cache[nn].size = size;
    cache[nn].data = GC_malloc_atomic(size);
    memcpy(cache[nn].data, data, size);
    cache[nn].hash = lstrdup(hash);
    cache_next = (nn + 1) % 10;
}

variable_types:
hash
char *


streq

decompiled_code:
_BOOL8 __fastcall streq(const char *a1, const char *a2)
{
return strcmp(a1, a2) == 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func0(const char *a1, const char *a2)
{
return strcmp(a1, a2) == 0;
}

original_code:
int
streq(const char* aa, const char* bb)
{
    return strcmp(aa, bb) == 0;
}

canonical_original_code:
int streq(char *aa, char *bb)
{
    return strcmp(aa, bb) == 0;
}

variable_types:
aa
char *

variable_types:
bb
char *


carp

decompiled_code:
void __fastcall __noreturn carp(const char *a1)
{
fprintf(stderr, "FATAL: %s\n", a1);
fflush(stderr);
abort();
}

canonical_decompiled_code:
void __fastcall __noreturn func1(const char *a1)
{
fprintf(stderr, "FATAL: %s\n", a1);
fflush(stderr);
abort();
}

original_code:
void
carp(const char* msg)
{
    fprintf(stderr, "FATAL: %s\n", msg);
    fflush(stderr);
    abort();
}

canonical_original_code:
void carp(char *msg)
{
    fprintf(stderr, "FATAL: %s\n", msg);
    fflush(stderr);
    abort();
}

variable_types:
msg
char *


decompiled_code:
void __fastcall free_image(void *ptr)
{
free(*((void **)ptr + 2));
free(ptr);
}

canonical_decompiled_code:
void __fastcall func2(void *ptr)
{
free(*((void **)ptr + 2));
free(ptr);
}

original_code:
void
free_image(image* im)
{
    free(im->data);
    free(im);
}

canonical_original_code:
void free_image(struct image *im)
{
    free(im->data);
    free(im);
}

variable_types: struct image { unsigned long width; unsigned long height; unsigned char *data; } *


original_code:
void
gaussian_blur(image* im0, int sigma)
{
    ((void) sizeof ((sigma > 0) ? 1 : 0), __extension__ ({ if (sigma > 0) ; else __assert_fail ("sigma > 0", "ref_blur.c", 141, __extension__ __PRETTY_FUNCTION__); }));
    size_t ww = im0->width;
    size_t hh = im0->height;
    int rr = 3 * sigma;
    double bvec[2 * rr + 1];
    double bsum = 0.0;
    for (int kk = -rr; kk <= rr; ++kk) {
        int ii = kk + rr;
        bvec[ii] = gauss(kk, 0.0, sigma);
        bsum += bvec[ii];
    }
    for (int ii = 0; ii < 2 * rr + 1; ++ii) {
        bvec[ii] *= 1.0 / bsum;
    }
    image* im1 = alloc_image(ww, hh);
    for (int ii = 0; ii < hh; ++ii) {
        for (int jj = 0; jj < ww; ++jj) {
            double p1 = 0.0;
            for (int kk = -rr; kk <= rr; ++kk) {
                int jj0 = clamp(jj + kk, 0, ww - 1);
                p1 += bvec[kk + rr] * im0->data[ww*ii + jj0];
            }
            im1->data[ww*ii + jj] = clamp(round(p1), 0, 255);
        }
    }
    for (int jj = 0; jj < ww; ++jj) {
        for (int ii = 0; ii < hh; ++ii) {
            double p0 = 0.0;
            for (int kk = -rr; kk <= rr; ++kk) {
                int ii0 = clamp(ii + kk, 0, hh - 1);
                p0 += bvec[kk + rr] * im1->data[ww*ii0 + jj];
            }
            im0->data[ww*ii + jj] = clamp(round(p0), 0, 255);
        }
    }
    free_image(im1);
}

canonical_original_code:
void gaussian_blur(struct image *im0, int sigma)
{
    ((void) sizeof ((sigma > 0) ? 1 : 0), __extension__ ({ if (sigma > 0) ; else __assert_fail ("sigma > 0", "ref_blur.c", 141, __extension__ __PRETTY_FUNCTION__); }));
    unsigned long ww = im0->width;
    unsigned long hh = im0->height;
    int rr = 3 * sigma;
    double bvec[-1];
    double bsum = 0.0;
    for (int kk = -rr; kk <= rr; ++kk) {
        int ii = kk + rr;
        bvec[ii] = gauss(kk, 0.0, sigma);
        bsum += bvec[ii];
    }
    for (int ii = 0; ii < 2 * rr + 1; ++ii) {
        bvec[ii] *= 1.0 / bsum;
    }
    struct image *im1 = alloc_image(ww, hh);
    for (int ii = 0; ii < hh; ++ii) {
        for (int jj = 0; jj < ww; ++jj) {
            double p1 = 0.0;
            for (int kk = -rr; kk <= rr; ++kk) {
                int jj0 = clamp(jj + kk, 0, ww - 1);
                p1 += bvec[kk + rr] * im0->data[ww*ii + jj0];
            }
            im1->data[ww*ii + jj] = clamp(round(p1), 0, 255);
        }
    }
    for (int jj = 0; jj < ww; ++jj) {
        for (int ii = 0; ii < hh; ++ii) {
            double p0 = 0.0;
            for (int kk = -rr; kk <= rr; ++kk) {
                int ii0 = clamp(ii + kk, 0, hh - 1);
                p0 += bvec[kk + rr] * im1->data[ww*ii0 + jj];
            }
            im0->data[ww*ii + jj] = clamp(round(p0), 0, 255);
        }
    }
    free_image(im1);
}

variable_types: sigma int

variable_types:
ww
unsigned long

variable_types:
hh
unsigned long

variable_types: rr int

variable_types:
bvec
double [-1]

variable_types: bsum double

variable_types: kk int

user_defined_types: struct image { unsigned long width; unsigned long height; unsigned char *data; }


main

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

v3 = read_image(INPUT);
gaussian_blur(v3, 20);
write_image(OUTPUT, v3);
free_image(v3);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 *v3; // rbx

v3 = read_image(INPUT);
func6(v3, 20);
func3(OUTPUT, v3);
func2(v3);
return 0;
}

original_code:
int
main(int argc, char* argv[])
{
    image* im = read_image(INPUT);
    gaussian_blur(im, SIGMA);
    write_image(OUTPUT, im);
    free_image(im);
    return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
    struct image *im = read_image(INPUT);
    gaussian_blur(im, SIGMA);
    write_image(OUTPUT, im);
    free_image(im);
    return 0;
}

variable_types: argc int

variable_types:
argv
char *[]