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: i int

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-settings

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:
msg
char *

variable_types:
description
char *

variable_types:
tmp
char *

variable_types:
scratch
char [16]

return_type: void


decompiled_code:
__int64 __fastcall dump_indent(char a1, int a2, unsigned int a3, __int64 (__fastcall *a4)(void *, __int64, __int64), __int64 a5)
{
unsigned int v7; // ebx
__int64 result; // rax
int v9; // er12

if ( (a1 & 0x1F) != 0 )
{
v7 = a2 * (a1 & 0x1F);
result = a4(&unk_F03, 1LL, a5);
if ( (_DWORD)result )
{
result = 0xFFFFFFFFLL;
}
else if ( v7 )
{
while ( 1 )
{
v9 = 32;
if ( v7 <= 0x20 )
v9 = v7;
result = a4(" ", v9, a5);
if ( (_DWORD)result )
break;
v7 -= v9;
if ( !v7 )
return result;
}
result = 0xFFFFFFFFLL;
}
}
else
{
result = a3;
if ( a3 )
{
result = 0LL;
if ( (a1 & 0x20) == 0 )
result = a4(&unk_F05, 1LL, a5);
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(char a1, int a2, unsigned int a3, __int64 (__fastcall *a4)(void *, __int64, __int64), __int64 a5)
{
unsigned int v7; // ebx
__int64 result; // rax
int v9; // er12

if ( (a1 & 0x1F) != 0 )
{
v7 = a2 * (a1 & 0x1F);
result = a4(&unk_F03, 1LL, a5);
if ( (_DWORD)result )
{
result = 0xFFFFFFFFLL;
}
else if ( v7 )
{
while ( 1 )
{
v9 = 32;
if ( v7 <= 0x20 )
v9 = v7;
result = a4(" ", v9, a5);
if ( (_DWORD)result )
break;
v7 -= v9;
if ( !v7 )
return result;
}
result = 0xFFFFFFFFLL;
}
}
else
{
result = a3;
if ( a3 )
{
result = 0LL;
if ( (a1 & 0x20) == 0 )
result = a4(&unk_F05, 1LL, a5);
}
}
return result;
}

original_code:
static int dump_indent(size_t flags, int depth, int space, json_dump_callback_t dump, void *data)
{
    if(((flags) & 0x1F) > 0)
    {
        unsigned int ws_count = ((flags) & 0x1F), n_spaces = depth * ws_count;
        if(dump("\n", 1, data))
            return -1;
        while(n_spaces > 0)
        {
            int cur_n = n_spaces < sizeof whitespace - 1 ? n_spaces : sizeof whitespace - 1;
            if(dump(whitespace, cur_n, data))
                return -1;
            n_spaces -= cur_n;
        }
    }
    else if(space && !(flags & 0x20))
    {
        return dump(" ", 1, data);
    }
    return 0;
}

canonical_original_code:
static int dump_indent(unsigned long flags, int depth, int space, int (*dump)(char *buffer, unsigned long size, void *data), void *data)
{
    if(((flags) & 0x1F) > 0)
    {
        unsigned int ws_count = ((flags) & 0x1F); unsigned int n_spaces = depth * ws_count;
        if(dump("\n", 1, data))
            return -1;
        while(n_spaces > 0)
        {
            int cur_n = n_spaces < sizeof whitespace - 1 ? n_spaces : sizeof whitespace - 1;
            if(dump(whitespace, cur_n, data))
                return -1;
            n_spaces -= cur_n;
        }
    }
    else if(space && !(flags & 0x20))
    {
        return dump(" ", 1, data);
    }
    return 0;
}

variable_types:
flags
unsigned long

variable_types: depth int

variable_types: space int

variable_types: int (*)(char *buffer, unsigned long size, void *data)

variable_types:
data
void *

return_type: int


decompiled_code:
__int64 __fastcall dump_to_strbuffer(__int64 a1, __int64 a2, __int64 a3)
{
return strbuffer_append_bytes(a3, a1, a2);
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 a2, __int64 a3)
{
return strbuffer_append_bytes(a3, a1, a2);
}

original_code:
static int dump_to_strbuffer(const char *buffer, size_t size, void *data)
{
    return strbuffer_append_bytes((strbuffer_t *)data, buffer, size);
}

canonical_original_code:
static int dump_to_strbuffer(char *buffer, unsigned long size, void *data)
{
    return strbuffer_append_bytes((struct strbuffer_t *)data, buffer, size);
}

variable_types:
buffer
char *

variable_types:
size
unsigned long

user_defined_types: struct strbuffer_t { char *value; unsigned long length; unsigned long size; }


decompiled_code:
__int64 __fastcall dump_to_buffer(void *src, size_t n, _QWORD *a3)
{
__int64 v4; // rax

v4 = a3[1];
if ( v4 + n <= *a3 )
memcpy((void *)(a3[2] + v4), src, n);
a3[1] += n;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(void *src, size_t n, _QWORD *a3)
{
__int64 v4; // rax

v4 = a3[1];
if ( v4 + n <= *a3 )
memcpy((void *)(a3[2] + v4), src, n);
a3[1] += n;
return 0LL;
}

original_code:
static int dump_to_buffer(const char *buffer, size_t size, void *data)
{
    struct buffer *buf = (struct buffer *)data;
    if(buf->used + size <= buf->size)
        memcpy(&buf->data[buf->used], buffer, size);
    buf->used += size;
    return 0;
}

canonical_original_code:
static int dump_to_buffer(char *buffer, unsigned long size, void *data)
{
    struct buffer *buf = (struct buffer *)data;
    if(buf->used + size <= buf->size)
        memcpy(&buf->data[buf->used], buffer, size);
    buf->used += size;
    return 0;
}

variable_types: struct buffer { unsigned long size; unsigned long used; char *data; } *


decompiled_code:
__int64 __fastcall dump_to_fd(void *buf, size_t n, int *a3)
{
return (unsigned int)-(n != write(*a3, buf, n));
}

canonical_decompiled_code:
__int64 __fastcall func4(void *buf, size_t n, int *a3)
{
return (unsigned int)-(n != write(*a3, buf, n));
}

original_code:
static int dump_to_fd(const char *buffer, size_t size, void *data)
{
    int *dest = (int *)data;
    if(write(*dest, buffer, size) == (ssize_t)size)
        return 0;
    return -1;
}

canonical_original_code:
static int dump_to_fd(char *buffer, unsigned long size, void *data)
{
    int *dest = (int *)data;
    if(write(*dest, buffer, size) == (long)size)
        return 0;
    return -1;
}

variable_types:
dest
int *


decompiled_code:
int __fastcall compare_keys(const void *a1, const void *a2)
{
return strcmp(*(const char **)a1, *(const char **)a2);
}

canonical_decompiled_code:
int __fastcall func5(const void *a1, const void *a2)
{
return strcmp(*(const char **)a1, *(const char **)a2);
}

original_code:
static int compare_keys(const void *key1, const void *key2)
{
    return strcmp(*(const char **)key1, *(const char **)key2);
}

canonical_original_code:
static int compare_keys(void *key1, void *key2)
{
    return strcmp(*(char **)key1, *(char **)key2);
}


original_code:
static int dump_string(const char *str, size_t len, json_dump_callback_t dump, void *data, size_t flags)
{
    const char *pos, *end, *lim;
    int32_t codepoint = 0;
    if(dump("\"", 1, data))
        return -1;
    end = pos = str;
    lim = str + len;
    while(1)
    {
        const char *text;
        char seq[13];
        int length;
        while(end < lim)
        {
            end = utf8_iterate(pos, lim - pos, &codepoint);
            if(!end)
                return -1;
            if(codepoint == '\\' || codepoint == '"' || codepoint < 0x20)
                break;
            if((flags & 0x400) && codepoint == '/')
                break;
            if((flags & 0x40) && codepoint > 0x7F)
                break;
            pos = end;
        }
        if(pos != str) {
            if(dump(str, pos - str, data))
                return -1;
        }
        if(end == pos)
            break;
        length = 2;
        switch(codepoint)
        {
            case '\\': text = "\\\\"; break;
            case '\"': text = "\\\""; break;
            case '\b': text = "\\b"; break;
            case '\f': text = "\\f"; break;
            case '\n': text = "\\n"; break;
            case '\r': text = "\\r"; break;
            case '\t': text = "\\t"; break;
            case '/': text = "\\/"; break;
            default:
            {
                if(codepoint < 0x10000)
                {
                    snprintf(seq, sizeof(seq), "\\u%04X", (unsigned int)codepoint);
                    length = 6;
                }
                else
                {
                    int32_t first, last;
                    codepoint -= 0x10000;
                    first = 0xD800 | ((codepoint & 0xffc00) >> 10);
                    last = 0xDC00 | (codepoint & 0x003ff);
                    snprintf(seq, sizeof(seq), "\\u%04X\\u%04X", (unsigned int)first, (unsigned int)last);
                    length = 12;
                }
                text = seq;
                break;
            }
        }
        if(dump(text, length, data))
            return -1;
        str = pos = end;
    }
    return dump("\"", 1, data);
}

canonical_original_code:
static int dump_string(char *str, unsigned long len, int (*dump)(char *buffer, unsigned long size, void *data), void *data, unsigned long flags)
{
    char *pos; char *end; char *lim;
    int codepoint = 0;
    if(dump("\"", 1, data))
        return -1;
    end = pos = str;
    lim = str + len;
    while(1)
    {
        char *text;
        char seq[13];
        int length;
        while(end < lim)
        {
            end = utf8_iterate(pos, lim - pos, &codepoint);
            if(!end)
                return -1;
            if(codepoint == '\\' || codepoint == '"' || codepoint < 0x20)
                break;
            if((flags & 0x400) && codepoint == '/')
                break;
            if((flags & 0x40) && codepoint > 0x7F)
                break;
            pos = end;
        }
        if(pos != str) {
            if(dump(str, pos - str, data))
                return -1;
        }
        if(end == pos)
            break;
        length = 2;
        switch(codepoint)
        {
            case '\\': text = "\\\\"; break;
            case '\"': text = "\\\""; break;
            case '\b': text = "\\b"; break;
            case '\f': text = "\\f"; break;
            case '\n': text = "\\n"; break;
            case '\r': text = "\\r"; break;
            case '\t': text = "\\t"; break;
            case '/': text = "\\/"; break;
            default:
            {
                if(codepoint < 0x10000)
                {
                    snprintf(seq, sizeof(seq), "\\u%04X", (unsigned int)codepoint);
                    length = 6;
                }
                else
                {
                    int first; int last;
                    codepoint -= 0x10000;
                    first = 0xD800 | ((codepoint & 0xffc00) >> 10);
                    last = 0xDC00 | (codepoint & 0x003ff);
                    snprintf(seq, sizeof(seq), "\\u%04X\\u%04X", (unsigned int)first, (unsigned int)last);
                    length = 12;
                }
                text = seq;
                break;
            }
        }
        if(dump(text, length, data))
            return -1;
        str = pos = end;
    }
    return dump("\"", 1, data);
}

variable_types:
str
char *

variable_types:
len
unsigned long

variable_types:
pos
char *

variable_types:
end
char *

variable_types:
lim
char *

variable_types: codepoint int

variable_types:
text
char *

variable_types:
seq
char [13]

variable_types: length int

variable_types: first int

variable_types: last int


decompiled_code:
__int64 __fastcall json_dumps(_DWORD *a1, __int64 a2)
{
__int64 v2; // r13
__int64 v4; // rax
char v5[64]; // [rsp+0h] [rbp-40h] BYREF

v2 = 0LL;
if ( !(unsigned int)strbuffer_init(v5) )
{
if ( !(unsigned int)json_dump_callback(
a1,
(__int64 (__fastcall *)(void *, __int64, __int64))dump_to_strbuffer,
(__int64)v5,
a2) )
{
v4 = strbuffer_value(v5);
v2 = jsonp_strdup(v4);
}
strbuffer_close(v5);
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func10(_DWORD *a1, __int64 a2)
{
__int64 v2; // r13
__int64 v4; // rax
char v5[64]; // [rsp+0h] [rbp-40h] BYREF

v2 = 0LL;
if ( !(unsigned int)strbuffer_init(v5) )
{
if ( !(unsigned int)func9(
a1,
(__int64 (__fastcall *)(void *, __int64, __int64))dump_to_strbuffer,
(__int64)v5,
a2) )
{
v4 = strbuffer_value(v5);
v2 = jsonp_strdup(v4);
}
strbuffer_close(v5);
}
return v2;
}

original_code:
char *json_dumps(const json_t *json, size_t flags)
{
    strbuffer_t strbuff;
    char *result;
    if(strbuffer_init(&strbuff))
        return ((void *)0);
    if(json_dump_callback(json, dump_to_strbuffer, (void *)&strbuff, flags))
        result = ((void *)0);
    else
        result = jsonp_strdup(strbuffer_value(&strbuff));
    strbuffer_close(&strbuff);
    return result;
}

canonical_original_code:
char *json_dumps(struct json_t *json, unsigned long flags)
{
    struct strbuffer_t strbuff;
    char *result;
    if(strbuffer_init(&strbuff))
        return ((void *)0);
    if(json_dump_callback(json, dump_to_strbuffer, (void *)&strbuff, flags))
        result = ((void *)0);
    else
        result = jsonp_strdup(strbuffer_value(&strbuff));
    strbuffer_close(&strbuff);
    return result;
}

variable_types: struct json_t { enum json_type { JSON_OBJECT=0, JSON_ARRAY=1, JSON_STRING=2, JSON_INTEGER=3, JSON_REAL=4, JSON_TRUE=5, JSON_FALSE=6, JSON_NULL=7 } type; unsigned long refcount; } *

variable_types:
flags
unsigned long

variable_types: struct strbuffer_t { char *value; unsigned long length; unsigned long size; }

variable_types:
result
char *

return_type: char *

user_defined_types: struct json_t { enum json_type type; unsigned long refcount; }


decompiled_code:
__int64 __fastcall json_dumpb(_DWORD *a1, __int64 a2, __int64 a3, __int64 a4)
{
bool v4; // zf
__int64 result; // rax
__int64 v6; // [rsp+0h] [rbp-20h] BYREF
__int64 v7; // [rsp+8h] [rbp-18h]
__int64 v8; // [rsp+10h] [rbp-10h]

v6 = a3;
v7 = 0LL;
v8 = a2;
v4 = (unsigned int)json_dump_callback(
a1,
(__int64 (__fastcall *)(void *, __int64, __int64))dump_to_buffer,
(__int64)&v6,
a4) == 0;
result = 0LL;
if ( v4 )
result = v7;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func11(_DWORD *a1, __int64 a2, __int64 a3, __int64 a4)
{
bool v4; // zf
__int64 result; // rax
__int64 v6; // [rsp+0h] [rbp-20h] BYREF
__int64 v7; // [rsp+8h] [rbp-18h]
__int64 v8; // [rsp+10h] [rbp-10h]

v6 = a3;
v7 = 0LL;
v8 = a2;
v4 = (unsigned int)func9(
a1,
(__int64 (__fastcall *)(void *, __int64, __int64))dump_to_buffer,
(__int64)&v6,
a4) == 0;
result = 0LL;
if ( v4 )
result = v7;
return result;
}

original_code:
size_t json_dumpb(const json_t *json, char *buffer, size_t size, size_t flags)
{
    struct buffer buf = { size, 0, buffer };
    if(json_dump_callback(json, dump_to_buffer, (void *)&buf, flags))
        return 0;
    return buf.used;
}

canonical_original_code:
unsigned long json_dumpb(struct json_t *json, char *buffer, unsigned long size, unsigned long flags)
{
    struct buffer buf = { size, 0, buffer };
    if(json_dump_callback(json, dump_to_buffer, (void *)&buf, flags))
        return 0;
    return buf.used;
}

variable_types:
buffer
char *

variable_types:
size
unsigned long

variable_types: struct buffer { unsigned long size; unsigned long used; char *data; }

return_type: unsigned long

user_defined_types: enum json_type { JSON_OBJECT=0, JSON_ARRAY=1, JSON_STRING=2, JSON_INTEGER=3, JSON_REAL=4, JSON_TRUE=5, JSON_FALSE=6, JSON_NULL=7 }


decompiled_code:
__int64 __fastcall json_dumpfd(_DWORD *a1, int a2, __int64 a3)
{
int v4; // [rsp+Ch] [rbp-4h] BYREF

v4 = a2;
return json_dump_callback(a1, (__int64 (__fastcall *)(void *, __int64, __int64))dump_to_fd, (__int64)&v4, a3);
}

canonical_decompiled_code:
__int64 __fastcall func14(_DWORD *a1, int a2, __int64 a3)
{
int v4; // [rsp+Ch] [rbp-4h] BYREF

v4 = a2;
return func9(a1, (__int64 (__fastcall *)(void *, __int64, __int64))dump_to_fd, (__int64)&v4, a3);
}

original_code:
int json_dumpfd(const json_t *json, int output, size_t flags)
{
    return json_dump_callback(json, dump_to_fd, (void *)&output, flags);
}

canonical_original_code:
int json_dumpfd(struct json_t *json, int output, unsigned long flags)
{
    return json_dump_callback(json, dump_to_fd, (void *)&output, flags);
}

variable_types: output int


decompiled_code:
char *__fastcall to_locale(const char **a1)
{
char *result; // rax
char v2; // r12

result = localeconv()->decimal_point;
v2 = *result;
if ( *result != 46 )
{
result = strchr(*a1, 46);
if ( result )
*result = v2;
}
return result;
}

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

result = localeconv()->decimal_point;
v2 = *result;
if ( *result != 46 )
{
result = strchr(*a1, 46);
if ( result )
*result = v2;
}
return result;
}

original_code:
static void to_locale(strbuffer_t *strbuffer)
{
    const char *point;
    char *pos;
    point = localeconv()->decimal_point;
    if(*point == '.') {
        return;
    }
    pos = strchr(strbuffer->value, '.');
    if(pos)
        *pos = *point;
}

canonical_original_code:
static void to_locale(struct strbuffer_t *strbuffer)
{
    char *point;
    char *pos;
    point = localeconv()->decimal_point;
    if(*point == '.') {
        return;
    }
    pos = strchr(strbuffer->value, '.');
    if(pos)
        *pos = *point;
}

variable_types: struct strbuffer_t { char *value; unsigned long length; unsigned long size; } *

variable_types:
point
char *

variable_types:
pos
char *


decompiled_code:
char *__fastcall from_locale(char *s)
{
char *result; // rax

result = localeconv()->decimal_point;
if ( *result != 46 )
{
result = strchr(s, *result);
if ( result )
*result = 46;
}
return result;
}

canonical_decompiled_code:
char *__fastcall func1(char *s)
{
char *result; // rax

result = localeconv()->decimal_point;
if ( *result != 46 )
{
result = strchr(s, *result);
if ( result )
*result = 46;
}
return result;
}

original_code:
static void from_locale(char *buffer)
{
    const char *point;
    char *pos;
    point = localeconv()->decimal_point;
    if(*point == '.') {
        return;
    }
    pos = strchr(buffer, *point);
    if(pos)
        *pos = '.';
}

canonical_original_code:
static void from_locale(char *buffer)
{
    char *point;
    char *pos;
    point = localeconv()->decimal_point;
    if(*point == '.') {
        return;
    }
    pos = strchr(buffer, *point);
    if(pos)
        *pos = '.';
}


decompiled_code:
__int64 __fastcall jsonp_strtod(__int64 a1, double *a2)
{
int *v2; // r12
double v3; // xmm0_8
char *endptr; // [rsp+8h] [rbp-28h] BYREF

to_locale((const char **)a1);
v2 = _errno_location();
*v2 = 0;
v3 = strtod(*(const char **)a1, &endptr);
if ( endptr != (char *)(*(_QWORD *)a1 + *(_QWORD *)(a1 + 8)) )
_assert_fail("end == strbuffer->value + strbuffer->length", "jansson/strconv.c", 0x4Eu, "jsonp_strtod");
if ( (v3 == INFINITY || v3 == -INFINITY) && *v2 == 34 )
return 0xFFFFFFFFLL;
*a2 = v3;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, double *a2)
{
int *v2; // r12
double v3; // xmm0_8
char *endptr; // [rsp+8h] [rbp-28h] BYREF

func0((const char **)a1);
v2 = _errno_location();
*v2 = 0;
v3 = strtod(*(const char **)a1, &endptr);
if ( endptr != (char *)(*(_QWORD *)a1 + *(_QWORD *)(a1 + 8)) )
_assert_fail("end == strbuffer->value + strbuffer->length", "jansson/strconv.c", 0x4Eu, "jsonp_strtod");
if ( (v3 == INFINITY || v3 == -INFINITY) && *v2 == 34 )
return 0xFFFFFFFFLL;
*a2 = v3;
return 0LL;
}

original_code:
int jsonp_strtod(strbuffer_t *strbuffer, double *out)
{
    double value;
    char *end;
    to_locale(strbuffer);
    (*__errno_location ()) = 0;
    value = strtod(strbuffer->value, &end);
    ((void) sizeof ((end == strbuffer->value + strbuffer->length) ? 1 : 0), __extension__ ({ if (end == strbuffer->value + strbuffer->length) ; else __assert_fail ("end == strbuffer->value + strbuffer->length", "jansson/strconv.c", 78, __extension__ __PRETTY_FUNCTION__); }));
    if((value == __builtin_huge_val() || value == -__builtin_huge_val()) && (*__errno_location ()) == 34) {
        return -1;
    }
    *out = value;
    return 0;
}

canonical_original_code:
int jsonp_strtod(struct strbuffer_t *strbuffer, double *out)
{
    double value;
    char *end;
    to_locale(strbuffer);
    (*__errno_location ()) = 0;
    value = strtod(strbuffer->value, &end);
    ((void) sizeof ((end == strbuffer->value + strbuffer->length) ? 1 : 0), __extension__ ({ if (end == strbuffer->value + strbuffer->length) ; else __assert_fail ("end == strbuffer->value + strbuffer->length", "jansson/strconv.c", 78, __extension__ __PRETTY_FUNCTION__); }));
    if((value == __builtin_huge_val() || value == -__builtin_huge_val()) && (*__errno_location ()) == 34) {
        return -1;
    }
    *out = value;
    return 0;
}

variable_types:
out
double *

variable_types: value double

variable_types:
end
char *


decompiled_code:
__int64 __fastcall jsonp_dtostr(char *s, size_t a2, int a3, double a4)
{
int v4; // ecx
int v5; // eax
__int64 v6; // r12
char *v7; // rax
_BYTE *v8; // rbx
_BYTE *v9; // r14

v4 = a3;
if ( !a3 )
v4 = 17;
v5 = snprintf(s, a2, "%.*g", v4, a4);
if ( v5 < 0 )
return 0xFFFFFFFFLL;
v6 = v5;
if ( a2 <= v5 )
return 0xFFFFFFFFLL;
from_locale(s);
if ( strchr(s, 46) )
goto LABEL_6;
v7 = strchr(s, 101);
if ( v7 )
{
LABEL_7:
v8 = v7 + 2;
if ( v7[1] != 45 )
{
v9 = v7 + 1;
if ( v7[2] != 48 )
{
LABEL_10:
if ( v8 != v9 )
{
memmove(v9, v8, v6 - (v8 - s));
LODWORD(v6) = v6 - ((_DWORD)v8 - (_DWORD)v9);
}
return (unsigned int)v6;
}
do
LABEL_9:
++v8;
while ( *v8 == 48 );
goto LABEL_10;
}
v9 = v7 + 2;
if ( v7[2] == 48 )
goto LABEL_9;
return (unsigned int)v6;
}
if ( v6 + 3 < a2 )
{
s[v6] = 46;
s[v6 + 1] = 48;
v6 += 2LL;
s[v6] = 0;
LABEL_6:
v7 = strchr(s, 101);
if ( !v7 )
return (unsigned int)v6;
goto LABEL_7;
}
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func3(char *s, size_t a2, int a3, double a4)
{
int v4; // ecx
int v5; // eax
__int64 v6; // r12
char *v7; // rax
_BYTE *v8; // rbx
_BYTE *v9; // r14

v4 = a3;
if ( !a3 )
v4 = 17;
v5 = snprintf(s, a2, "%.*g", v4, a4);
if ( v5 < 0 )
return 0xFFFFFFFFLL;
v6 = v5;
if ( a2 <= v5 )
return 0xFFFFFFFFLL;
func1(s);
if ( strchr(s, 46) )
goto LABEL_6;
v7 = strchr(s, 101);
if ( v7 )
{
LABEL_7:
v8 = v7 + 2;
if ( v7[1] != 45 )
{
v9 = v7 + 1;
if ( v7[2] != 48 )
{
LABEL_10:
if ( v8 != v9 )
{
memmove(v9, v8, v6 - (v8 - s));
LODWORD(v6) = v6 - ((_DWORD)v8 - (_DWORD)v9);
}
return (unsigned int)v6;
}
do
LABEL_9:
++v8;
while ( *v8 == 48 );
goto LABEL_10;
}
v9 = v7 + 2;
if ( v7[2] == 48 )
goto LABEL_9;
return (unsigned int)v6;
}
if ( v6 + 3 < a2 )
{
s[v6] = 46;
s[v6 + 1] = 48;
v6 += 2LL;
s[v6] = 0;
LABEL_6:
v7 = strchr(s, 101);
if ( !v7 )
return (unsigned int)v6;
goto LABEL_7;
}
return 0xFFFFFFFFLL;
}

original_code:
int jsonp_dtostr(char *buffer, size_t size, double value, int precision)
{
    int ret;
    char *start, *end;
    size_t length;
    if (precision == 0)
        precision = 17;
    ret = snprintf(buffer, size, "%.*g", precision, value);
    if(ret < 0)
        return -1;
    length = (size_t)ret;
    if(length >= size)
        return -1;
    from_locale(buffer);
    if(strchr(buffer, '.') == ((void *)0) &&
       strchr(buffer, 'e') == ((void *)0))
    {
        if(length + 3 >= size) {
            return -1;
        }
        buffer[length] = '.';
        buffer[length + 1] = '0';
        buffer[length + 2] = '\0';
        length += 2;
    }
    start = strchr(buffer, 'e');
    if(start) {
        start++;
        end = start + 1;
        if(*start == '-')
            start++;
        while(*end == '0')
            end++;
        if(end != start) {
            memmove(start, end, length - (size_t)(end - buffer));
            length -= (size_t)(end - start);
        }
    }
    return (int)length;
}

canonical_original_code:
int jsonp_dtostr(char *buffer, unsigned long size, double value, int precision)
{
    int ret;
    char *start; char *end;
    unsigned long length;
    if (precision == 0)
        precision = 17;
    ret = snprintf(buffer, size, "%.*g", precision, value);
    if(ret < 0)
        return -1;
    length = (unsigned long)ret;
    if(length >= size)
        return -1;
    from_locale(buffer);
    if(strchr(buffer, '.') == ((void *)0) &&
       strchr(buffer, 'e') == ((void *)0))
    {
        if(length + 3 >= size) {
            return -1;
        }
        buffer[length] = '.';
        buffer[length + 1] = '0';
        buffer[length + 2] = '\0';
        length += 2;
    }
    start = strchr(buffer, 'e');
    if(start) {
        start++;
        end = start + 1;
        if(*start == '-')
            start++;
        while(*end == '0')
            end++;
        if(end != start) {
            memmove(start, end, length - (unsigned long)(end - buffer));
            length -= (unsigned long)(end - start);
        }
    }
    return (int)length;
}

variable_types: precision int

variable_types: ret int

variable_types:
start
char *

variable_types:
length
unsigned long


xconfigAlloc

decompiled_code:
void *__fastcall xconfigAlloc(size_t n)
{
void *v1; // rax
int *v3; // rax
char *v4; // rax

v1 = malloc(n);
if ( !v1 )
{
v3 = _errno_location();
v4 = strerror(*v3);
fprintf(stderr, "memory allocation failure (%s)! \n", v4);
exit(1);
}
return memset(v1, 0, n);
}

canonical_decompiled_code:
void *__fastcall func0(size_t n)
{
void *v1; // rax
int *v3; // rax
char *v4; // rax

v1 = malloc(n);
if ( !v1 )
{
v3 = _errno_location();
v4 = strerror(*v3);
fprintf(stderr, "memory allocation failure (%s)! \n", v4);
exit(1);
}
return memset(v1, 0, n);
}

original_code:
void *xconfigAlloc(size_t size)
{
    void *m = malloc(size);
    if (!m) {
        fprintf(stderr, "memory allocation failure (%s)! \n", strerror((*__errno_location ())));
        exit(1);
    }
    memset((char *) m, 0, size);
    return m;
}

canonical_original_code:
void *xconfigAlloc(unsigned long size)
{
    void *m = malloc(size);
    if (!m) {
        fprintf(stderr, "memory allocation failure (%s)! \n", strerror((*__errno_location ())));
        exit(1);
    }
    memset((char *) m, 0, size);
    return m;
}

variable_types:
m
void *

return_type: void *


xconfigStrdup

decompiled_code:
char *__fastcall xconfigStrdup(const char *a1)
{
char *result; // rax
int *v2; // rax
char *v3; // rax

if ( !a1 )
return 0LL;
result = strdup(a1);
if ( !result )
{
v2 = _errno_location();
v3 = strerror(*v2);
fprintf(stderr, "memory allocation failure during strdup (%s)! \n", v3);
exit(1);
}
return result;
}

canonical_decompiled_code:
char *__fastcall func1(const char *a1)
{
char *result; // rax
int *v2; // rax
char *v3; // rax

if ( !a1 )
return 0LL;
result = strdup(a1);
if ( !result )
{
v2 = _errno_location();
v3 = strerror(*v2);
fprintf(stderr, "memory allocation failure during strdup (%s)! \n", v3);
exit(1);
}
return result;
}

original_code:
char *xconfigStrdup(const char *s)
{
    char *m;
    if (!s) return ((void *)0);
    m = strdup(s);
    if (!m) {
        fprintf(stderr, "memory allocation failure during strdup (%s)! \n",
                strerror((*__errno_location ())));
        exit(1);
    }
    return m;
}

canonical_original_code:
char *xconfigStrdup(char *s)
{
    char *m;
    if (!s) return ((void *)0);
    m = strdup(s);
    if (!m) {
        fprintf(stderr, "memory allocation failure during strdup (%s)! \n",
                strerror((*__errno_location ())));
        exit(1);
    }
    return m;
}

variable_types:
s
char *

variable_types:
m
char *


xconfigErrorMsg

decompiled_code:
void xconfigErrorMsg(unsigned int a1, const char *a2, ...)
{
double v2; // xmm0_8
double v3; // xmm1_8
double v4; // xmm2_8
double v5; // xmm3_8
double v6; // xmm6_8
double v7; // xmm7_8
char *v8; // r12
int i; // ebx
int v10; // eax
double v11; // xmm4_8
double v12; // xmm5_8
char *v13; // rbx
double v14; // xmm4_8
double v15; // xmm5_8
char *v16; // rbx
double v17; // xmm4_8
double v18; // xmm5_8
char *v19; // r13
double v20; // xmm4_8
double v21; // xmm5_8
char s[72]; // [rsp+0h] [rbp-140h] BYREF
gcc_va_list arg; // [rsp+48h] [rbp-F8h] BYREF
__int128 v24; // [rsp+90h] [rbp-B0h]
__int128 v25; // [rsp+A0h] [rbp-A0h]
__int128 v26; // [rsp+B0h] [rbp-90h]
__int128 v27; // [rsp+C0h] [rbp-80h]
__int128 v28; // [rsp+D0h] [rbp-70h]
__int128 v29; // [rsp+E0h] [rbp-60h]
__int128 v30; // [rsp+F0h] [rbp-50h]
__int128 v31; // [rsp+100h] [rbp-40h]

va_start(arg, a2);
*(double *)&v24 = va_arg(arg, double);
v2 = *(double *)&v24;
*(double *)&v25 = va_arg(arg, double);
v3 = *(double *)&v25;
*(double *)&v26 = va_arg(arg, double);
v4 = *(double *)&v26;
*(double *)&v27 = va_arg(arg, double);
v5 = *(double *)&v27;
*(double *)&v28 = va_arg(arg, double);
*(double *)&v29 = va_arg(arg, double);
*(double *)&v30 = va_arg(arg, double);
v6 = *(double *)&v30;
*(double *)&v31 = va_arg(arg, double);
v7 = *(double *)&v31;
va_end(arg);
v8 = (char *)xconfigAlloc(0x40uLL);
for ( i = 64; ; v8 = (char *)xconfigAlloc(i) )
{
va_start(arg, a2);
v10 = vsnprintf(v8, i, a2, arg);
if ( v10 >= 0 && i > v10 )
break;
i += 64;
if ( v10 >= 0 )
i = v10 + 1;
free(v8);
}
if ( a1 == 1 )
{
sprintf(s, "%d", configLineNo);
v16 = xconfigStrcat(
"Parse warning on line ",
(__int64)s,
v2,
v3,
v4,
v5,
v20,
v21,
v6,
v7,
" of section ",
configSection,
" in file ",
configPath,
".\n",
0LL);
}
else if ( a1 == 2 )
{
v16 = xconfigStrcat("Data incomplete in file ", configPath, v2, v3, v4, v5, v11, v12, v6, v7, ".\n", 0LL);
}
else
{
if ( a1 )
{
LABEL_10:
v13 = strdup(v8);
xconfigPrint(a1, v13);
free(v8);
free(v13);
return;
}
sprintf(s, "%d", configLineNo);
v16 = xconfigStrcat(
"Parse error on line ",
(__int64)s,
v2,
v3,
v4,
v5,
v14,
v15,
v6,
v7,
" of section ",
configSection,
" in file ",
configPath,
".\n",
0LL);
}
if ( !v16 )
goto LABEL_10;
v19 = xconfigStrcat(v16, (__int64)v8, v2, v3, v4, v5, v17, v18, v6, v7, 0LL);
xconfigPrint(a1, v19);
free(v8);
free(v19);
free(v16);
}

canonical_decompiled_code:
void func3(unsigned int a1, const char *a2, ...)
{
double v2; // xmm0_8
double v3; // xmm1_8
double v4; // xmm2_8
double v5; // xmm3_8
double v6; // xmm6_8
double v7; // xmm7_8
char *v8; // r12
int i; // ebx
int v10; // eax
double v11; // xmm4_8
double v12; // xmm5_8
char *v13; // rbx
double v14; // xmm4_8
double v15; // xmm5_8
char *v16; // rbx
double v17; // xmm4_8
double v18; // xmm5_8
char *v19; // r13
double v20; // xmm4_8
double v21; // xmm5_8
char s[72]; // [rsp+0h] [rbp-140h] BYREF
gcc_va_list arg; // [rsp+48h] [rbp-F8h] BYREF
__int128 v24; // [rsp+90h] [rbp-B0h]
__int128 v25; // [rsp+A0h] [rbp-A0h]
__int128 v26; // [rsp+B0h] [rbp-90h]
__int128 v27; // [rsp+C0h] [rbp-80h]
__int128 v28; // [rsp+D0h] [rbp-70h]
__int128 v29; // [rsp+E0h] [rbp-60h]
__int128 v30; // [rsp+F0h] [rbp-50h]
__int128 v31; // [rsp+100h] [rbp-40h]

va_start(arg, a2);
*(double *)&v24 = va_arg(arg, double);
v2 = *(double *)&v24;
*(double *)&v25 = va_arg(arg, double);
v3 = *(double *)&v25;
*(double *)&v26 = va_arg(arg, double);
v4 = *(double *)&v26;
*(double *)&v27 = va_arg(arg, double);
v5 = *(double *)&v27;
*(double *)&v28 = va_arg(arg, double);
*(double *)&v29 = va_arg(arg, double);
*(double *)&v30 = va_arg(arg, double);
v6 = *(double *)&v30;
*(double *)&v31 = va_arg(arg, double);
v7 = *(double *)&v31;
va_end(arg);
v8 = (char *)func0(0x40uLL);
for ( i = 64; ; v8 = (char *)func0(i) )
{
va_start(arg, a2);
v10 = vsnprintf(v8, i, a2, arg);
if ( v10 >= 0 && i > v10 )
break;
i += 64;
if ( v10 >= 0 )
i = v10 + 1;
free(v8);
}
if ( a1 == 1 )
{
sprintf(s, "%d", configLineNo);
v16 = func2(
"Parse warning on line ",
(__int64)s,
v2,
v3,
v4,
v5,
v20,
v21,
v6,
v7,
" of section ",
configSection,
" in file ",
configPath,
".\n",
0LL);
}
else if ( a1 == 2 )
{
v16 = func2("Data incomplete in file ", configPath, v2, v3, v4, v5, v11, v12, v6, v7, ".\n", 0LL);
}
else
{
if ( a1 )
{
LABEL_10:
v13 = strdup(v8);
xconfigPrint(a1, v13);
free(v8);
free(v13);
return;
}
sprintf(s, "%d", configLineNo);
v16 = func2(
"Parse error on line ",
(__int64)s,
v2,
v3,
v4,
v5,
v14,
v15,
v6,
v7,
" of section ",
configSection,
" in file ",
configPath,
".\n",
0LL);
}
if ( !v16 )
goto LABEL_10;
v19 = func2(v16, (__int64)v8, v2, v3, v4, v5, v17, v18, v6, v7, 0LL);
xconfigPrint(a1, v19);
free(v8);
free(v19);
free(v16);
}

original_code:
void xconfigErrorMsg(MsgType t, char *fmt, ...)
{
    va_list ap;
    int len, current_len = 64;
    char *b, *pre = ((void *)0), *msg;
    char scratch[64];
    b = xconfigAlloc(current_len);
    while (1) {
        __builtin_va_start(ap,fmt);
        len = vsnprintf(b, current_len, fmt, ap);
        __builtin_va_end(ap);
        if ((len > -1) && (len < current_len)) {
            break;
        } else if (len > -1) {
            current_len = len + 1;
        } else {
            current_len += 64;
        }
        free(b);
        b = xconfigAlloc(current_len);
    }
    switch (t) {
    case ParseErrorMsg:
        sprintf(scratch, "%d", configLineNo);
        pre = xconfigStrcat("Parse error on line ", scratch, " of section ",
                         configSection, " in file ", configPath, ".\n", ((void *)0));
        break;
    case ParseWarningMsg:
        sprintf(scratch, "%d", configLineNo);
        pre = xconfigStrcat("Parse warning on line ", scratch, " of section ",
                         configSection, " in file ", configPath, ".\n", ((void *)0));
        break;
    case ValidationErrorMsg:
        pre = xconfigStrcat("Data incomplete in file ", configPath, ".\n", ((void *)0));
        break;
    case InternalErrorMsg: break;
    case WriteErrorMsg: break;
    case WarnMsg: break;
    case ErrorMsg: break;
    case DebugMsg: break;
    case UnknownMsg: break;
    }
    if (pre) {
        msg = xconfigStrcat(pre, b, ((void *)0));
    } else {
        msg = strdup(b);
    }
    xconfigPrint(t, msg);
    free(b);
    free(msg);
    if (pre) free(pre);
}

canonical_original_code:
void xconfigErrorMsg(enum MsgType t, char *fmt, ...)
{
    __builtin_va_list ap;
    int len; int current_len = 64;
    char *b; char *pre = ((void *)0); char *msg;
    char scratch[64];
    b = xconfigAlloc(current_len);
    while (1) {
        __builtin_va_start(ap,fmt);
        len = vsnprintf(b, current_len, fmt, ap);
        __builtin_va_end(ap);
        if ((len > -1) && (len < current_len)) {
            break;
        } else if (len > -1) {
            current_len = len + 1;
        } else {
            current_len += 64;
        }
        free(b);
        b = xconfigAlloc(current_len);
    }
    switch (t) {
    case ParseErrorMsg:
        sprintf(scratch, "%d", configLineNo);
        pre = xconfigStrcat("Parse error on line ", scratch, " of section ",
                         configSection, " in file ", configPath, ".\n", ((void *)0));
        break;
    case ParseWarningMsg:
        sprintf(scratch, "%d", configLineNo);
        pre = xconfigStrcat("Parse warning on line ", scratch, " of section ",
                         configSection, " in file ", configPath, ".\n", ((void *)0));
        break;
    case ValidationErrorMsg:
        pre = xconfigStrcat("Data incomplete in file ", configPath, ".\n", ((void *)0));
        break;
    case InternalErrorMsg: break;
    case WriteErrorMsg: break;
    case WarnMsg: break;
    case ErrorMsg: break;
    case DebugMsg: break;
    case UnknownMsg: break;
    }
    if (pre) {
        msg = xconfigStrcat(pre, b, ((void *)0));
    } else {
        msg = strdup(b);
    }
    xconfigPrint(t, msg);
    free(b);
    free(msg);
    if (pre) free(pre);
}

variable_types: enum MsgType { ParseErrorMsg=0, ParseWarningMsg=1, ValidationErrorMsg=2, InternalErrorMsg=3, WriteErrorMsg=4, WarnMsg=5, ErrorMsg=6, DebugMsg=7, UnknownMsg=8 }

variable_types:
fmt
char *

variable_types: len int

variable_types:
b
char *

variable_types:
pre
char *

variable_types:
msg
char *

variable_types:
scratch
char [64]


decompiled_code:
__int64 open_libegl()
{
void **v0; // rbx
__int64 result; // rax
_QWORD *v2; // rbx
char *v3; // rax

if ( !_libEGL )
_libEGL = (void *)nvalloc(64LL);
v0 = (void **)_libEGL;
if ( *(_QWORD *)_libEGL )
{
++*((_DWORD *)_libEGL + 2);
return 1LL;
}
*v0 = dlopen("libEGL.so.1", 1);
v2 = _libEGL;
if ( *(_QWORD *)_libEGL )
{
dlerror();
v2[2] = dlsym((void *)*v2, "eglInitialize");
v3 = dlerror();
if ( !v3 )
{
dlerror();
v2[3] = dlsym((void *)*v2, "eglTerminate");
v3 = dlerror();
if ( !v3 )
{
dlerror();
v2[4] = dlsym((void *)*v2, "eglGetDisplay");
v3 = dlerror();
if ( !v3 )
{
dlerror();
v2[5] = dlsym((void *)*v2, "eglQueryString");
v3 = dlerror();
if ( !v3 )
{
dlerror();
v2[6] = dlsym((void *)*v2, "eglGetConfigs");
v3 = dlerror();
if ( !v3 )
{
dlerror();
v2[7] = dlsym((void *)*v2, "eglGetConfigAttrib");
v3 = dlerror();
if ( !v3 )
{
++*((_DWORD *)v2 + 2);
return 1LL;
}
}
}
}
}
}
LABEL_8:
nv_error_msg("libEGL setup error : %s\n", v3);
v2 = _libEGL;
result = 0LL;
if ( !_libEGL )
return result;
goto LABEL_11;
}
v3 = dlerror();
if ( v3 )
goto LABEL_8;
LABEL_11:
if ( *v2 )
{
dlclose((void *)*v2);
*(_QWORD *)_libEGL = 0LL;
}
free(_libEGL);
_libEGL = 0LL;
return 0LL;
}

canonical_decompiled_code:
__int64 func0()
{
void **v0; // rbx
__int64 result; // rax
_QWORD *v2; // rbx
char *v3; // rax

if ( !_libEGL )
_libEGL = (void *)nvalloc(64LL);
v0 = (void **)_libEGL;
if ( *(_QWORD *)_libEGL )
{
++*((_DWORD *)_libEGL + 2);
return 1LL;
}
*v0 = dlopen("libEGL.so.1", 1);
v2 = _libEGL;
if ( *(_QWORD *)_libEGL )
{
dlerror();
v2[2] = dlsym((void *)*v2, "eglInitialize");
v3 = dlerror();
if ( !v3 )
{
dlerror();
v2[3] = dlsym((void *)*v2, "eglTerminate");
v3 = dlerror();
if ( !v3 )
{
dlerror();
v2[4] = dlsym((void *)*v2, "eglGetDisplay");
v3 = dlerror();
if ( !v3 )
{
dlerror();
v2[5] = dlsym((void *)*v2, "eglQueryString");
v3 = dlerror();
if ( !v3 )
{
dlerror();
v2[6] = dlsym((void *)*v2, "eglGetConfigs");
v3 = dlerror();
if ( !v3 )
{
dlerror();
v2[7] = dlsym((void *)*v2, "eglGetConfigAttrib");
v3 = dlerror();
if ( !v3 )
{
++*((_DWORD *)v2 + 2);
return 1LL;
}
}
}
}
}
}
LABEL_8:
nv_error_msg("libEGL setup error : %s\n", v3);
v2 = _libEGL;
result = 0LL;
if ( !_libEGL )
return result;
goto LABEL_11;
}
v3 = dlerror();
if ( v3 )
goto LABEL_8;
LABEL_11:
if ( *v2 )
{
dlclose((void *)*v2);
*(_QWORD *)_libEGL = 0LL;
}
free(_libEGL);
_libEGL = 0LL;
return 0LL;
}

original_code:
static int open_libegl(void)
{
    const char *error_str = ((void *)0);
    if ( !__libEGL ) {
        __libEGL = nvalloc(sizeof(__libEGLInfo));
    }
    if ( __libEGL->handle ) {
        __libEGL->ref_count++;
        return 1;
    }
    __libEGL->handle = dlopen("libEGL.so.1", 0x00001);
    if ( !__libEGL->handle ) {
        error_str = dlerror();
        goto fail;
    }
    __libEGL->eglInitialize =
        ({ dlerror(); dlsym(__libEGL->handle, "eglInitialize"); });
    if ((error_str = dlerror()) != ((void *)0)) goto fail;
    __libEGL->eglTerminate =
        ({ dlerror(); dlsym(__libEGL->handle, "eglTerminate"); });
    if ((error_str = dlerror()) != ((void *)0)) goto fail;
    __libEGL->eglGetDisplay =
        ({ dlerror(); dlsym(__libEGL->handle, "eglGetDisplay"); });
    if ((error_str = dlerror()) != ((void *)0)) goto fail;
    __libEGL->eglQueryString =
        ({ dlerror(); dlsym(__libEGL->handle, "eglQueryString"); });
    if ((error_str = dlerror()) != ((void *)0)) goto fail;
    __libEGL->eglGetConfigs =
        ({ dlerror(); dlsym(__libEGL->handle, "eglGetConfigs"); });
    if ((error_str = dlerror()) != ((void *)0)) goto fail;
    __libEGL->eglGetConfigAttrib =
        ({ dlerror(); dlsym(__libEGL->handle, "eglGetConfigAttrib"); });
    if ((error_str = dlerror()) != ((void *)0)) goto fail;
    __libEGL->ref_count++;
    return 1;
 fail:
    if ( error_str ) {
        nv_error_msg("libEGL setup error : %s\n", error_str);
    }
    if ( __libEGL ) {
        if ( __libEGL->handle ) {
            dlclose(__libEGL->handle);
            __libEGL->handle = ((void *)0);
        }
        free(__libEGL);
        __libEGL = ((void *)0);
    }
    return 0;
}

canonical_original_code:
static int open_libegl()
{
    char *error_str = ((void *)0);
    if ( !__libEGL ) {
        __libEGL = nvalloc(sizeof(__libEGLInfo));
    }
    if ( __libEGL->handle ) {
        __libEGL->ref_count++;
        return 1;
    }
    __libEGL->handle = dlopen("libEGL.so.1", 0x00001);
    if ( !__libEGL->handle ) {
        error_str = dlerror();
        goto fail;
    }
    __libEGL->eglInitialize =
        ({ dlerror(); dlsym(__libEGL->handle, "eglInitialize"); });
    if ((error_str = dlerror()) != ((void *)0)) goto fail;
    __libEGL->eglTerminate =
        ({ dlerror(); dlsym(__libEGL->handle, "eglTerminate"); });
    if ((error_str = dlerror()) != ((void *)0)) goto fail;
    __libEGL->eglGetDisplay =
        ({ dlerror(); dlsym(__libEGL->handle, "eglGetDisplay"); });
    if ((error_str = dlerror()) != ((void *)0)) goto fail;
    __libEGL->eglQueryString =
        ({ dlerror(); dlsym(__libEGL->handle, "eglQueryString"); });
    if ((error_str = dlerror()) != ((void *)0)) goto fail;
    __libEGL->eglGetConfigs =
        ({ dlerror(); dlsym(__libEGL->handle, "eglGetConfigs"); });
    if ((error_str = dlerror()) != ((void *)0)) goto fail;
    __libEGL->eglGetConfigAttrib =
        ({ dlerror(); dlsym(__libEGL->handle, "eglGetConfigAttrib"); });
    if ((error_str = dlerror()) != ((void *)0)) goto fail;
    __libEGL->ref_count++;
    return 1;
 fail:
    if ( error_str ) {
        nv_error_msg("libEGL setup error : %s\n", error_str);
    }
    if ( __libEGL ) {
        if ( __libEGL->handle ) {
            dlclose(__libEGL->handle);
            __libEGL->handle = ((void *)0);
        }
        free(__libEGL);
        __libEGL = ((void *)0);
    }
    return 0;
}


decompiled_code:
void *close_libegl()
{
void *result; // rax
int v1; // edx
int v2; // edx

result = _libEGL;
if ( _libEGL )
{
if ( *(_QWORD *)_libEGL )
{
v1 = *((_DWORD *)_libEGL + 2);
if ( v1 )
{
v2 = v1 - 1;
*((_DWORD *)_libEGL + 2) = v2;
if ( !v2 )
result = (void *)sub_1D2();
}
}
}
return result;
}

canonical_decompiled_code:
void *func1()
{
void *result; // rax
int v1; // edx
int v2; // edx

result = _libEGL;
if ( _libEGL )
{
if ( *(_QWORD *)_libEGL )
{
v1 = *((_DWORD *)_libEGL + 2);
if ( v1 )
{
v2 = v1 - 1;
*((_DWORD *)_libEGL + 2) = v2;
if ( !v2 )
result = (void *)sub_1D2();
}
}
}
return result;
}

original_code:
static void close_libegl(void)
{
    if ( __libEGL && __libEGL->handle && __libEGL->ref_count ) {
        __libEGL->ref_count--;
        if ( __libEGL->ref_count == 0 ) {
            dlclose(__libEGL->handle);
            __libEGL->handle = ((void *)0);
            free(__libEGL);
            __libEGL = ((void *)0);
        }
    }
}

canonical_original_code:
static void close_libegl()
{
    if ( __libEGL && __libEGL->handle && __libEGL->ref_count ) {
        __libEGL->ref_count--;
        if ( __libEGL->ref_count == 0 ) {
            dlclose(__libEGL->handle);
            __libEGL->handle = ((void *)0);
            free(__libEGL);
            __libEGL = ((void *)0);
        }
    }
}


decompiled_code:
__int64 open_libxv()
{
void **v0; // rbx
__int64 result; // rax
_QWORD *v2; // rbx
char *v3; // rax

if ( !_libXv )
_libXv = (void *)nvalloc(32LL);
v0 = (void **)_libXv;
if ( *(_QWORD *)_libXv )
{
++*((_DWORD *)_libXv + 2);
return 1LL;
}
*v0 = dlopen("libXv.so.1", 1);
v2 = _libXv;
if ( *(_QWORD *)_libXv )
{
dlerror();
v2[2] = dlsym((void *)*v2, "XvQueryExtension");
v3 = dlerror();
if ( !v3 )
{
dlerror();
v2[3] = dlsym((void *)*v2, "XvQueryAdaptors");
v3 = dlerror();
if ( !v3 )
{
v3 = dlerror();
if ( !v3 )
{
++*((_DWORD *)v2 + 2);
return 1LL;
}
}
}
LABEL_8:
nv_error_msg("libXv setup error : %s\n", v3);
v2 = _libXv;
result = 0LL;
if ( !_libXv )
return result;
goto LABEL_11;
}
v3 = dlerror();
if ( v3 )
goto LABEL_8;
LABEL_11:
if ( *v2 )
{
dlclose((void *)*v2);
*(_QWORD *)_libXv = 0LL;
}
free(_libXv);
_libXv = 0LL;
return 0LL;
}

canonical_decompiled_code:
__int64 func0()
{
void **v0; // rbx
__int64 result; // rax
_QWORD *v2; // rbx
char *v3; // rax

if ( !_libXv )
_libXv = (void *)nvalloc(32LL);
v0 = (void **)_libXv;
if ( *(_QWORD *)_libXv )
{
++*((_DWORD *)_libXv + 2);
return 1LL;
}
*v0 = dlopen("libXv.so.1", 1);
v2 = _libXv;
if ( *(_QWORD *)_libXv )
{
dlerror();
v2[2] = dlsym((void *)*v2, "XvQueryExtension");
v3 = dlerror();
if ( !v3 )
{
dlerror();
v2[3] = dlsym((void *)*v2, "XvQueryAdaptors");
v3 = dlerror();
if ( !v3 )
{
v3 = dlerror();
if ( !v3 )
{
++*((_DWORD *)v2 + 2);
return 1LL;
}
}
}
LABEL_8:
nv_error_msg("libXv setup error : %s\n", v3);
v2 = _libXv;
result = 0LL;
if ( !_libXv )
return result;
goto LABEL_11;
}
v3 = dlerror();
if ( v3 )
goto LABEL_8;
LABEL_11:
if ( *v2 )
{
dlclose((void *)*v2);
*(_QWORD *)_libXv = 0LL;
}
free(_libXv);
_libXv = 0LL;
return 0LL;
}

original_code:
static int open_libxv(void)
{
    const char *error_str = ((void *)0);
    if ( !__libXv ) {
        __libXv = nvalloc(sizeof(__libXvInfo));
    }
    if ( __libXv->handle ) {
        __libXv->ref_count++;
        return 1;
    }
    __libXv->handle = dlopen("libXv.so.1", 0x00001);
    if ( __libXv->handle == ((void *)0) ) {
        error_str = dlerror();
        goto fail;
    }
    __libXv->XvQueryExtension =
        ({ dlerror(); dlsym(__libXv->handle, "XvQueryExtension"); });
    if ((error_str = dlerror()) != ((void *)0)) goto fail;
    __libXv->XvQueryAdaptors =
        ({ dlerror(); dlsym(__libXv->handle, "XvQueryAdaptors"); });
    if ((error_str = dlerror()) != ((void *)0)) goto fail;
    if ((error_str = dlerror()) != ((void *)0)) goto fail;
    __libXv->ref_count++;
    return 1;
 fail:
    if ( error_str ) {
        nv_error_msg("libXv setup error : %s\n", error_str);
    }
    if ( __libXv ) {
        if ( __libXv->handle ) {
            dlclose(__libXv->handle);
            __libXv->handle = ((void *)0);
        }
        free(__libXv);
        __libXv = ((void *)0);
    }
    return 0;
}

canonical_original_code:
static int open_libxv()
{
    char *error_str = ((void *)0);
    if ( !__libXv ) {
        __libXv = nvalloc(sizeof(__libXvInfo));
    }
    if ( __libXv->handle ) {
        __libXv->ref_count++;
        return 1;
    }
    __libXv->handle = dlopen("libXv.so.1", 0x00001);
    if ( __libXv->handle == ((void *)0) ) {
        error_str = dlerror();
        goto fail;
    }
    __libXv->XvQueryExtension =
        ({ dlerror(); dlsym(__libXv->handle, "XvQueryExtension"); });
    if ((error_str = dlerror()) != ((void *)0)) goto fail;
    __libXv->XvQueryAdaptors =
        ({ dlerror(); dlsym(__libXv->handle, "XvQueryAdaptors"); });
    if ((error_str = dlerror()) != ((void *)0)) goto fail;
    if ((error_str = dlerror()) != ((void *)0)) goto fail;
    __libXv->ref_count++;
    return 1;
 fail:
    if ( error_str ) {
        nv_error_msg("libXv setup error : %s\n", error_str);
    }
    if ( __libXv ) {
        if ( __libXv->handle ) {
            dlclose(__libXv->handle);
            __libXv->handle = ((void *)0);
        }
        free(__libXv);
        __libXv = ((void *)0);
    }
    return 0;
}


decompiled_code:
void *close_libxv()
{
void *result; // rax
int v1; // edx
int v2; // edx

result = _libXv;
if ( _libXv )
{
if ( *(_QWORD *)_libXv )
{
v1 = *((_DWORD *)_libXv + 2);
if ( v1 )
{
v2 = v1 - 1;
*((_DWORD *)_libXv + 2) = v2;
if ( !v2 )
result = (void *)sub_150();
}
}
}
return result;
}

canonical_decompiled_code:
void *func1()
{
void *result; // rax
int v1; // edx
int v2; // edx

result = _libXv;
if ( _libXv )
{
if ( *(_QWORD *)_libXv )
{
v1 = *((_DWORD *)_libXv + 2);
if ( v1 )
{
v2 = v1 - 1;
*((_DWORD *)_libXv + 2) = v2;
if ( !v2 )
result = (void *)sub_150();
}
}
}
return result;
}

original_code:
static void close_libxv(void)
{
    if ( __libXv && __libXv->handle && __libXv->ref_count ) {
        __libXv->ref_count--;
        if ( __libXv->ref_count == 0 ) {
            dlclose(__libXv->handle);
            __libXv->handle = ((void *)0);
            free(__libXv);
            __libXv = ((void *)0);
        }
    }
}

canonical_original_code:
static void close_libxv()
{
    if ( __libXv && __libXv->handle && __libXv->ref_count ) {
        __libXv->ref_count--;
        if ( __libXv->ref_count == 0 ) {
            dlclose(__libXv->handle);
            __libXv->handle = ((void *)0);
            free(__libXv);
            __libXv = ((void *)0);
        }
    }
}


decompiled_code:
int do_help()
{
puts("usage:");
puts("-q: query system frame lock information.");
puts("-e: enable frame lock on system.");
puts("-d: disable frame lock on system.");
return putchar(10);
}

canonical_decompiled_code:
int func0()
{
puts("usage:");
puts("-q: query system frame lock information.");
puts("-e: enable frame lock on system.");
puts("-d: disable frame lock on system.");
return putchar(10);
}

original_code:
static void do_help(void)
{
    printf("usage:\n");
    printf("-q: query system frame lock information.\n");
    printf("-e: enable frame lock on system.\n");
    printf("-d: disable frame lock on system.\n");
    printf("\n");
}

canonical_original_code:
static void do_help()
{
    printf("usage:\n");
    printf("-q: query system frame lock information.\n");
    printf("-e: enable frame lock on system.\n");
    printf("-d: disable frame lock on system.\n");
    printf("\n");
}


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
Display *v3; // rax
Display *v4; // r14
int v5; // ebx
char *v6; // rax
char *v8; // rax
char *v9; // rax
const char *v10; // r12
unsigned int v11; // [rsp+8h] [rbp-28h] BYREF
unsigned int v12[9]; // [rsp+Ch] [rbp-24h] BYREF

v3 = XOpenDisplay(0LL);
if ( v3 )
{
v4 = v3;
v5 = XNVCTRLQueryVersion(v3, v12, &v11);
if ( v5 == 1 )
{
v9 = XDisplayName(0LL);
printf("Using NV-CONTROL extension %d.%d on %s\n\n", v12[0], v11, v9);
if ( (int)v12[0] <= 0 || v12[0] == 1 && (int)v11 <= 8 )
{
puts(
"The NV-CONTROL X extension is too old. Version 1.9 or above is required for configuring Frame Lock via target types.");
}
else if ( argc <= 1 || (v10 = argv[1], !strcmp(v10, "-q")) )
{
do_query((__int64)v4);
v5 = 0;
}
else
{
v5 = strcmp(v10, "-e");
if ( v5 )
{
v5 = strcmp(v10, "-d");
if ( v5 )
{
do_help();
v5 = 0;
}
else
{
do_disable(v4);
}
}
else
{
do_enable(v4);
}
}
}
else
{
v6 = XDisplayName(0LL);
printf("The NV-CONTROL X extension does not exist on '%s'.\n", v6);
v5 = 1;
}
}
else
{
v8 = XDisplayName(0LL);
printf("Cannot open display '%s'.\n", v8);
v5 = 1;
}
return v5;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
Display *v3; // rax
Display *v4; // r14
int v5; // ebx
char *v6; // rax
char *v8; // rax
char *v9; // rax
const char *v10; // r12
unsigned int v11; // [rsp+8h] [rbp-28h] BYREF
unsigned int v12[9]; // [rsp+Ch] [rbp-24h] BYREF

v3 = XOpenDisplay(0LL);
if ( v3 )
{
v4 = v3;
v5 = XNVCTRLQueryVersion(v3, v12, &v11);
if ( v5 == 1 )
{
v9 = XDisplayName(0LL);
printf("Using NV-CONTROL extension %d.%d on %s\n\n", v12[0], v11, v9);
if ( (int)v12[0] <= 0 || v12[0] == 1 && (int)v11 <= 8 )
{
puts(
"The NV-CONTROL X extension is too old. Version 1.9 or above is required for configuring Frame Lock via target types.");
}
else if ( argc <= 1 || (v10 = argv[1], !strcmp(v10, "-q")) )
{
func1((__int64)v4);
v5 = 0;
}
else
{
v5 = strcmp(v10, "-e");
if ( v5 )
{
v5 = strcmp(v10, "-d");
if ( v5 )
{
func0();
v5 = 0;
}
else
{
func3(v4);
}
}
else
{
func2(v4);
}
}
}
else
{
v6 = XDisplayName(0LL);
printf("The NV-CONTROL X extension does not exist on '%s'.\n", v6);
v5 = 1;
}
}
else
{
v8 = XDisplayName(0LL);
printf("Cannot open display '%s'.\n", v8);
v5 = 1;
}
return v5;
}

original_code:
int main(void)
{
    gen_manpage_opts_helper(__options);
    return 0;
}

canonical_original_code:
int main()
{
    gen_manpage_opts_helper(__options);
    return 0;
}


GetAttrTypeName

decompiled_code:
const char *__fastcall GetAttrTypeName(int a1)
{
const char *result; // rax

switch ( a1 )
{
case 0:
result = "ATTRIBUTE_TYPE_UNKNOWN";
break;
case 1:
result = "ATTRIBUTE_TYPE_INTEGER";
break;
case 2:
result = "ATTRIBUTE_TYPE_BITMASK";
break;
case 3:
result = "ATTRIBUTE_TYPE_BOOL";
break;
case 4:
result = "ATTRIBUTE_TYPE_RANGE";
break;
case 5:
result = "ATTRIBUTE_TYPE_INT_BITS";
break;
case 6:
result = "ATTRIBUTE_TYPE_64BIT_INTEGER";
break;
case 7:
result = "ATTRIBUTE_TYPE_STRING";
break;
case 8:
result = "ATTRIBUTE_TYPE_BINARY_DATA";
break;
case 9:
result = "ATTRIBUTE_TYPE_STRING_OPERATION";
break;
default:
result = "Invalid Value";
break;
}
return result;
}

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

switch ( a1 )
{
case 0:
result = "ATTRIBUTE_TYPE_UNKNOWN";
break;
case 1:
result = "ATTRIBUTE_TYPE_INTEGER";
break;
case 2:
result = "ATTRIBUTE_TYPE_BITMASK";
break;
case 3:
result = "ATTRIBUTE_TYPE_BOOL";
break;
case 4:
result = "ATTRIBUTE_TYPE_RANGE";
break;
case 5:
result = "ATTRIBUTE_TYPE_INT_BITS";
break;
case 6:
result = "ATTRIBUTE_TYPE_64BIT_INTEGER";
break;
case 7:
result = "ATTRIBUTE_TYPE_STRING";
break;
case 8:
result = "ATTRIBUTE_TYPE_BINARY_DATA";
break;
case 9:
result = "ATTRIBUTE_TYPE_STRING_OPERATION";
break;
default:
result = "Invalid Value";
break;
}
return result;
}

original_code:
static const char *GetAttrTypeName(int value)
{
    switch (value) {
        case (0): return "ATTRIBUTE_TYPE_UNKNOWN";;
        case (1): return "ATTRIBUTE_TYPE_INTEGER";;
        case (2): return "ATTRIBUTE_TYPE_BITMASK";;
        case (3): return "ATTRIBUTE_TYPE_BOOL";;
        case (4): return "ATTRIBUTE_TYPE_RANGE";;
        case (5): return "ATTRIBUTE_TYPE_INT_BITS";;
        case (6): return "ATTRIBUTE_TYPE_64BIT_INTEGER";;
        case (7): return "ATTRIBUTE_TYPE_STRING";;
        case (8): return "ATTRIBUTE_TYPE_BINARY_DATA";;
        case (9): return "ATTRIBUTE_TYPE_STRING_OPERATION";;
    default:
        return "Invalid Value";
    }
}

canonical_original_code:
static char *GetAttrTypeName(int value)
{
    switch (value) {
        case (0): return "ATTRIBUTE_TYPE_UNKNOWN";;
        case (1): return "ATTRIBUTE_TYPE_INTEGER";;
        case (2): return "ATTRIBUTE_TYPE_BITMASK";;
        case (3): return "ATTRIBUTE_TYPE_BOOL";;
        case (4): return "ATTRIBUTE_TYPE_RANGE";;
        case (5): return "ATTRIBUTE_TYPE_INT_BITS";;
        case (6): return "ATTRIBUTE_TYPE_64BIT_INTEGER";;
        case (7): return "ATTRIBUTE_TYPE_STRING";;
        case (8): return "ATTRIBUTE_TYPE_BINARY_DATA";;
        case (9): return "ATTRIBUTE_TYPE_STRING_OPERATION";;
    default:
        return "Invalid Value";
    }
}

variable_types: value int


original_code:
static void print_perms(NVCTRLAttributePermissionsRec *perms)
{
    printf("%c", (perms->permissions & 0x001) ? 'R' : '_');
    printf("%c", (perms->permissions & 0x002) ? 'W' : '_');
    printf("%c", (perms->permissions & 0x004) ? 'D' : '_');
    printf("%c", (perms->permissions & 0x008) ? 'G' : '_');
    printf("%c", (perms->permissions & 0x010) ? 'F' : '_');
    printf("%c", (perms->permissions & 0x020) ? 'X' : '_');
    printf("%c", (perms->permissions & 0x040) ? 'I' : '_');
    printf("%c", (perms->permissions & 0x200) ? 'C' : '_');
    printf("%c", (perms->permissions & 0x400) ? 'T' : '_');
    printf("%c", (perms->permissions & 0x800) ? '3' : '_');
}

canonical_original_code:
static void print_perms(struct _NVCTRLAttributePermissions *perms)
{
    printf("%c", (perms->permissions & 0x001) ? 'R' : '_');
    printf("%c", (perms->permissions & 0x002) ? 'W' : '_');
    printf("%c", (perms->permissions & 0x004) ? 'D' : '_');
    printf("%c", (perms->permissions & 0x008) ? 'G' : '_');
    printf("%c", (perms->permissions & 0x010) ? 'F' : '_');
    printf("%c", (perms->permissions & 0x020) ? 'X' : '_');
    printf("%c", (perms->permissions & 0x040) ? 'I' : '_');
    printf("%c", (perms->permissions & 0x200) ? 'C' : '_');
    printf("%c", (perms->permissions & 0x400) ? 'T' : '_');
    printf("%c", (perms->permissions & 0x800) ? '3' : '_');
}

variable_types: struct _NVCTRLAttributePermissions { int type; unsigned int permissions; } *


decompiled_code:
void __fastcall print_table_entry(int *a1, __int64 a2, const char *a3)
{
const char *v3; // rbx
const char *v4; // rax

v3 = a3;
if ( a1[1] || a3 )
{
printf(" (%3d) [Perms: ", a2);
print_perms((__int64)a1);
printf("] [ ");
v4 = GetAttrTypeName(*a1);
printf("%-32s", v4);
if ( !v3 )
v3 = "Unknown";
printf("] - %s\n", v3);
}
}

canonical_decompiled_code:
void __fastcall func2(int *a1, __int64 a2, const char *a3)
{
const char *v3; // rbx
const char *v4; // rax

v3 = a3;
if ( a1[1] || a3 )
{
printf(" (%3d) [Perms: ", a2);
func1((__int64)a1);
printf("] [ ");
v4 = func0(*a1);
printf("%-32s", v4);
if ( !v3 )
v3 = "Unknown";
printf("] - %s\n", v3);
}
}

original_code:
static void print_table_entry(NVCTRLAttributePermissionsRec *perms,
                              const int index,
                              const char *name)
{
    if ((perms->permissions == 0) && (name == ((void *)0))) {
        return;
    }
    printf("  (%3d) [Perms: ", index);
    print_perms(perms);
    printf("] [ ");
    printf("%-32s", GetAttrTypeName(perms->type));
    printf("] - %s\n", name ? name : "Unknown");
}

canonical_original_code:
static void print_table_entry(struct _NVCTRLAttributePermissions *perms, int index, char *name)
{
    if ((perms->permissions == 0) && (name == ((void *)0))) {
        return;
    }
    printf("  (%3d) [Perms: ", index);
    print_perms(perms);
    printf("] [ ");
    printf("%-32s", GetAttrTypeName(perms->type));
    printf("] - %s\n", name ? name : "Unknown");
}

variable_types: index int

variable_types:
name
char *

user_defined_types: struct _NVCTRLAttributePermissions { int type; unsigned int permissions; }


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
Display *v3; // rax
Display *v4; // r12
int v5; // ebx
char *v6; // rax
char *v8; // rax
char *v9; // rax
int v10; // er13
unsigned int i; // ebx
__int64 j; // rbx
__int64 k; // rbx
__int64 l; // rbx
__int64 m; // rbx
__int64 v16; // [rsp+0h] [rbp-40h] BYREF
void *v17; // [rsp+8h] [rbp-38h] BYREF
unsigned int v18; // [rsp+10h] [rbp-30h] BYREF
unsigned int v19; // [rsp+14h] [rbp-2Ch] BYREF
unsigned int v20; // [rsp+18h] [rbp-28h] BYREF
unsigned int v21[9]; // [rsp+1Ch] [rbp-24h] BYREF

v3 = XOpenDisplay(0LL);
if ( v3 )
{
v4 = v3;
v5 = XNVCTRLQueryExtension(v3, v21, &v20);
if ( v5 == 1 )
{
if ( (unsigned int)XNVCTRLQueryVersion(v4, &v19, &v18) == 1 )
{
puts("NV-CONTROL X extension present");
printf(" version : %d.%d\n", v19, v18);
printf(" event base : %d\n", v21[0]);
printf(" error base : %d\n", v20);
v10 = v4->nscreens;
if ( v10 > 0 )
{
for ( i = 0; i != v10; ++i )
{
if ( (unsigned int)XNVCTRLIsNvScreen(v4, i) )
{
printf("Screen %d supports the NV-CONTROL X extension\n", i);
if ( (unsigned int)XNVCTRLQueryStringAttribute(v4, i, 0LL, 0LL, &v17) )
{
printf(" GPU : %s\n", (const char *)v17);
XFree(v17);
}
if ( (unsigned int)XNVCTRLQueryStringAttribute(v4, i, 0LL, 1LL, &v17) )
{
printf(" VideoBIOS : %s\n", (const char *)v17);
XFree(v17);
}
if ( (unsigned int)XNVCTRLQueryStringAttribute(v4, i, 0LL, 3LL, &v17) )
{
printf(" Driver version : %s\n", (const char *)v17);
XFree(v17);
}
}
}
}
puts("Attributes (Integers):");
for ( j = 0LL; j != 443; ++j )
{
v16 = 0LL;
if ( (unsigned int)XNVCTRLQueryAttributePermissions(v4, (unsigned int)j, &v16) )
print_table_entry((int *)&v16, (unsigned int)j, (const char *)attr_int_table[j]);
}
puts("Attributes (Strings):");
for ( k = 0LL; k != 58; ++k )
{
v16 = 0LL;
if ( (unsigned int)XNVCTRLQueryStringAttributePermissions(v4, (unsigned int)k, &v16) )
print_table_entry((int *)&v16, (unsigned int)k, attr_str_table[k]);
}
puts("Attributes (Binary Data):");
for ( l = 0LL; l != 25; ++l )
{
v16 = 0LL;
if ( (unsigned int)XNVCTRLQueryBinaryDataAttributePermissions(v4, (unsigned int)l, &v16) )
print_table_entry((int *)&v16, (unsigned int)l, attr_bin_table[l]);
}
puts("Attributes (String Operations):");
for ( m = 0LL; m != 6; ++m )
{
v16 = 0LL;
if ( (unsigned int)XNVCTRLQueryStringOperationAttributePermissions(v4, (unsigned int)m, &v16) )
print_table_entry((int *)&v16, (unsigned int)m, attr_strop_table[m]);
}
XCloseDisplay(v4);
v5 = 0;
}
else
{
v9 = XDisplayName(0LL);
fprintf(stderr, "The NV-CONTROL X extension does not exist on '%s'.\n", v9);
}
}
else
{
v6 = XDisplayName(0LL);
fprintf(stderr, "The NV-CONTROL X extension does not exist on '%s'.\n", v6);
v5 = 1;
}
}
else
{
v8 = XDisplayName(0LL);
fprintf(stderr, "Cannot open display '%s'.\n", v8);
v5 = 1;
}
return v5;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
Display *v3; // rax
Display *v4; // r12
int v5; // ebx
char *v6; // rax
char *v8; // rax
char *v9; // rax
int v10; // er13
unsigned int i; // ebx
__int64 j; // rbx
__int64 k; // rbx
__int64 l; // rbx
__int64 m; // rbx
__int64 v16; // [rsp+0h] [rbp-40h] BYREF
void *v17; // [rsp+8h] [rbp-38h] BYREF
unsigned int v18; // [rsp+10h] [rbp-30h] BYREF
unsigned int v19; // [rsp+14h] [rbp-2Ch] BYREF
unsigned int v20; // [rsp+18h] [rbp-28h] BYREF
unsigned int v21[9]; // [rsp+1Ch] [rbp-24h] BYREF

v3 = XOpenDisplay(0LL);
if ( v3 )
{
v4 = v3;
v5 = XNVCTRLQueryExtension(v3, v21, &v20);
if ( v5 == 1 )
{
if ( (unsigned int)XNVCTRLQueryVersion(v4, &v19, &v18) == 1 )
{
puts("NV-CONTROL X extension present");
printf(" version : %d.%d\n", v19, v18);
printf(" event base : %d\n", v21[0]);
printf(" error base : %d\n", v20);
v10 = v4->nscreens;
if ( v10 > 0 )
{
for ( i = 0; i != v10; ++i )
{
if ( (unsigned int)XNVCTRLIsNvScreen(v4, i) )
{
printf("Screen %d supports the NV-CONTROL X extension\n", i);
if ( (unsigned int)XNVCTRLQueryStringAttribute(v4, i, 0LL, 0LL, &v17) )
{
printf(" GPU : %s\n", (const char *)v17);
XFree(v17);
}
if ( (unsigned int)XNVCTRLQueryStringAttribute(v4, i, 0LL, 1LL, &v17) )
{
printf(" VideoBIOS : %s\n", (const char *)v17);
XFree(v17);
}
if ( (unsigned int)XNVCTRLQueryStringAttribute(v4, i, 0LL, 3LL, &v17) )
{
printf(" Driver version : %s\n", (const char *)v17);
XFree(v17);
}
}
}
}
puts("Attributes (Integers):");
for ( j = 0LL; j != 443; ++j )
{
v16 = 0LL;
if ( (unsigned int)XNVCTRLQueryAttributePermissions(v4, (unsigned int)j, &v16) )
func2((int *)&v16, (unsigned int)j, (const char *)attr_int_table[j]);
}
puts("Attributes (Strings):");
for ( k = 0LL; k != 58; ++k )
{
v16 = 0LL;
if ( (unsigned int)XNVCTRLQueryStringAttributePermissions(v4, (unsigned int)k, &v16) )
func2((int *)&v16, (unsigned int)k, attr_str_table[k]);
}
puts("Attributes (Binary Data):");
for ( l = 0LL; l != 25; ++l )
{
v16 = 0LL;
if ( (unsigned int)XNVCTRLQueryBinaryDataAttributePermissions(v4, (unsigned int)l, &v16) )
func2((int *)&v16, (unsigned int)l, attr_bin_table[l]);
}
puts("Attributes (String Operations):");
for ( m = 0LL; m != 6; ++m )
{
v16 = 0LL;
if ( (unsigned int)XNVCTRLQueryStringOperationAttributePermissions(v4, (unsigned int)m, &v16) )
func2((int *)&v16, (unsigned int)m, attr_strop_table[m]);
}
XCloseDisplay(v4);
v5 = 0;
}
else
{
v9 = XDisplayName(0LL);
fprintf(stderr, "The NV-CONTROL X extension does not exist on '%s'.\n", v9);
}
}
else
{
v6 = XDisplayName(0LL);
fprintf(stderr, "The NV-CONTROL X extension does not exist on '%s'.\n", v6);
v5 = 1;
}
}
else
{
v8 = XDisplayName(0LL);
fprintf(stderr, "Cannot open display '%s'.\n", v8);
v5 = 1;
}
return v5;
}