decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
Display *v3; // rax
Display *v4; // rbx
int v5; // er12
char *v6; // rax
char *v8; // rax
const char *v9; // rsi
__int64 v10; // r11
int v11; // eax
__int64 v12; // r13
__int64 v13; // r8
__int64 v14; // rcx
__int64 v15; // r9
__int64 v16; // r13
unsigned int v17; // er14
__int64 v18; // rax
char *v19; // rax
__int64 v20; // [rsp-10h] [rbp-90h]
unsigned int v21; // [rsp+Ch] [rbp-74h]
unsigned int v22; // [rsp+18h] [rbp-68h] BYREF
unsigned int v23; // [rsp+1Ch] [rbp-64h] BYREF
unsigned int v24; // [rsp+20h] [rbp-60h] BYREF
unsigned int v25; // [rsp+24h] [rbp-5Ch] BYREF
unsigned int v26; // [rsp+28h] [rbp-58h] BYREF
unsigned int v27; // [rsp+2Ch] [rbp-54h] BYREF
unsigned int v28; // [rsp+30h] [rbp-50h] BYREF
char v29[4]; // [rsp+34h] [rbp-4Ch] BYREF
void *v30; // [rsp+38h] [rbp-48h] BYREF
void *v31; // [rsp+40h] [rbp-40h] BYREF
void *v32[7]; // [rsp+48h] [rbp-38h] BYREF

v3 = XOpenDisplay(0LL);
if ( v3 )
{
v4 = v3;
GetNvXScreen_isra_0((__int64)v3);
v5 = XNVCTRLQueryVersion(v4, &v22, &v23);
if ( v5 == 1 )
{
putchar(10);
v8 = XDisplayName(0LL);
printf("Using NV-CONTROL extension %d.%d on %s\n", v22, v23, v8);
putchar(10);
puts("Server System Information:");
putchar(10);
if ( (unsigned int)XNVCTRLQueryTargetCount(v4, 1LL, &v24) )
{
printf(" number of GPUs: %d\n", v24);
if ( !(unsigned int)XNVCTRLQueryTargetCount(v4, 0LL, &v25) )
goto LABEL_27;
printf(" number of X Screens: %d\n", v25);
if ( !(unsigned int)((__int64 (__fastcall *)(Display *, __int64, _QWORD, _QWORD, __int64, void **, char *))XNVCTRLQueryTargetBinaryData)(
v4,
1LL,
0LL,
0LL,
14LL,
&v30,
v29) )
{
fwrite("Failed to query number of display devices\n", 1uLL, 0x2AuLL, stderr);
return v5;
}
printf(" number of display devices: %d (", *(unsigned int *)v30);
print_display_device_target_indices((int *)v30);
puts(")");
XFree(v30);
if ( (unsigned int)XNVCTRLQueryTargetCount(v4, 2LL, &v26) )
{
printf(" number of Frame Lock Devices: %d\n", v26);
if ( (unsigned int)XNVCTRLQueryTargetCount(v4, 5LL, &v27) )
{
printf(" number of Cooler Devices: %d\n", v27);
if ( (unsigned int)XNVCTRLQueryTargetCount(v4, 6LL, &v28) )
{
printf(" number of Thermal Sensor Devices: %d\n", v28);
v21 = 0;
LABEL_12:
if ( (int)v24 <= (int)v21 )
{
v5 = 0;
}
else
{
puts("\n");
printf("GPU %d information:\n", v21);
if ( (unsigned int)XNVCTRLQueryTargetStringAttribute(v4, 1LL, v21, 0LL, 0LL, &v31) )
{
printf(" Product Name : %s\n", (const char *)v31);
XFree(v31);
v31 = 0LL;
v9 = "Unknown";
if ( (unsigned int)XNVCTRLQueryTargetStringAttribute(v4, 1LL, v21, 0LL, 52LL, &v31) )
v9 = (const char *)v31;
printf(" GPU UUID : %s\n", v9);
XFree(v31);
v31 = 0LL;
v11 = XNVCTRLQueryTargetBinaryData(v4, 1LL, v21, 0LL, 10LL, &v30, v29, v10);
v12 = v20;
if ( v11 )
{
printf(" Coolers on GPU : ");
print_cooler_target_indices((int *)v30);
XFree(v30);
putchar(10);
if ( (unsigned int)XNVCTRLQueryTargetBinaryData(v4, 1LL, v21, 0LL, 12LL, &v30, v29, v13) )
{
printf(" Thermal Sensors on GPU : ");
print_thermal_sensor_target_indices((int *)v30);
XFree(v30);
putchar(10);
if ( (unsigned int)XNVCTRLQueryTargetBinaryData(v4, 1LL, v21, 0LL, 15LL, v32, v29, v14) )
{
printf(" Connected Display Devices : ");
print_display_device_target_indices((int *)v32[0]);
XFree(v32[0]);
putchar(10);
if ( (unsigned int)XNVCTRLQueryTargetBinaryData(v4, 1LL, v21, 0LL, 7LL, &v30, v29, v12) )
{
printf(" Framelock Devices : ");
print_framelock_target_indices((int *)v30);
XFree(v30);
putchar(10);
if ( (unsigned int)XNVCTRLQueryTargetBinaryData(v4, 1LL, v21, 0LL, 3LL, &v30, v29, v15) )
{
v16 = 0LL;
printf(" Number of X Screens on GPU %d : %d\n", v21, *(unsigned int *)v30);
while ( 1 )
{
if ( *(_DWORD *)v30 < (int)v16 + 1 )
{
XFree(v30);
++v21;
goto LABEL_12;
}
++v16;
v17 = *((_DWORD *)v30 + v16);
putchar(10);
printf(" X Screen %d information:\n", v17);
if ( !(unsigned int)XNVCTRLQueryTargetBinaryData(v4, 0LL, v17, 0LL, 18LL, v32, v29, v17) )
break;
printf(" Assigned Display Devices : ");
print_display_device_target_indices((int *)v32[0]);
XFree(v32[0]);
LODWORD(v18) = putchar(10);
if ( !(unsigned int)XNVCTRLQueryTargetBinaryData(v4, 0LL, v17, 0LL, 17LL, v32, v29, v18) )
break;
printf(" Enabled Display Devices : ");
print_display_device_target_indices((int *)v32[0]);
XFree(v32[0]);
putchar(10);
}
fwrite("Failed to query assigned displays\n", 1uLL, 0x22uLL, stderr);
}
else
{
fwrite("Failed to query list of X Screens\n", 1uLL, 0x22uLL, stderr);
}
}
else
{
fwrite("Failed to query framelock devices\n", 1uLL, 0x22uLL, stderr);
}
}
else
{
fwrite("Failed to query connected displays\n", 1uLL, 0x23uLL, stderr);
}
}
else
{
fwrite("Failed to query connected thermal sensors\n", 1uLL, 0x2AuLL, stderr);
}
}
else
{
fwrite("Failed to query connected coolers\n", 1uLL, 0x22uLL, stderr);
}
}
else
{
fwrite("Failed to query gpu product name\n", 1uLL, 0x21uLL, stderr);
}
}
}
else
{
fwrite("Failed to query number of Thermal Sensors\n", 1uLL, 0x2AuLL, stderr);
}
}
else
{
fwrite("Failed to query number of Coolers\n", 1uLL, 0x22uLL, stderr);
}
}
else
{
LABEL_27:
fwrite("Failed to query number of xscreens\n", 1uLL, 0x23uLL, stderr);
}
}
else
{
fwrite("Failed to query number of gpus\n", 1uLL, 0x1FuLL, stderr);
}
}
else
{
v5 = 1;
v6 = XDisplayName(0LL);
fprintf(stderr, "The NV-CONTROL X extension does not exist on '%s'.\n", v6);
}
}
else
{
v5 = 1;
v19 = XDisplayName(0LL);
fprintf(stderr, "Cannot open display '%s'.\n", v19);
}
return v5;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
Display *v3; // rax
Display *v4; // rbx
int v5; // er12
char *v6; // rax
char *v8; // rax
const char *v9; // rsi
__int64 v10; // r11
int v11; // eax
__int64 v12; // r13
__int64 v13; // r8
__int64 v14; // rcx
__int64 v15; // r9
__int64 v16; // r13
unsigned int v17; // er14
__int64 v18; // rax
char *v19; // rax
__int64 v20; // [rsp-10h] [rbp-90h]
unsigned int v21; // [rsp+Ch] [rbp-74h]
unsigned int v22; // [rsp+18h] [rbp-68h] BYREF
unsigned int v23; // [rsp+1Ch] [rbp-64h] BYREF
unsigned int v24; // [rsp+20h] [rbp-60h] BYREF
unsigned int v25; // [rsp+24h] [rbp-5Ch] BYREF
unsigned int v26; // [rsp+28h] [rbp-58h] BYREF
unsigned int v27; // [rsp+2Ch] [rbp-54h] BYREF
unsigned int v28; // [rsp+30h] [rbp-50h] BYREF
char v29[4]; // [rsp+34h] [rbp-4Ch] BYREF
void *v30; // [rsp+38h] [rbp-48h] BYREF
void *v31; // [rsp+40h] [rbp-40h] BYREF
void *v32[7]; // [rsp+48h] [rbp-38h] BYREF

v3 = XOpenDisplay(0LL);
if ( v3 )
{
v4 = v3;
func5((__int64)v3);
v5 = XNVCTRLQueryVersion(v4, &v22, &v23);
if ( v5 == 1 )
{
putchar(10);
v8 = XDisplayName(0LL);
printf("Using NV-CONTROL extension %d.%d on %s\n", v22, v23, v8);
putchar(10);
puts("Server System Information:");
putchar(10);
if ( (unsigned int)XNVCTRLQueryTargetCount(v4, 1LL, &v24) )
{
printf(" number of GPUs: %d\n", v24);
if ( !(unsigned int)XNVCTRLQueryTargetCount(v4, 0LL, &v25) )
goto LABEL_27;
printf(" number of X Screens: %d\n", v25);
if ( !(unsigned int)((__int64 (__fastcall *)(Display *, __int64, _QWORD, _QWORD, __int64, void **, char *))XNVCTRLQueryTargetBinaryData)(
v4,
1LL,
0LL,
0LL,
14LL,
&v30,
v29) )
{
fwrite("Failed to query number of display devices\n", 1uLL, 0x2AuLL, stderr);
return v5;
}
printf(" number of display devices: %d (", *(unsigned int *)v30);
func4((int *)v30);
puts(")");
XFree(v30);
if ( (unsigned int)XNVCTRLQueryTargetCount(v4, 2LL, &v26) )
{
printf(" number of Frame Lock Devices: %d\n", v26);
if ( (unsigned int)XNVCTRLQueryTargetCount(v4, 5LL, &v27) )
{
printf(" number of Cooler Devices: %d\n", v27);
if ( (unsigned int)XNVCTRLQueryTargetCount(v4, 6LL, &v28) )
{
printf(" number of Thermal Sensor Devices: %d\n", v28);
v21 = 0;
LABEL_12:
if ( (int)v24 <= (int)v21 )
{
v5 = 0;
}
else
{
puts("\n");
printf("GPU %d information:\n", v21);
if ( (unsigned int)XNVCTRLQueryTargetStringAttribute(v4, 1LL, v21, 0LL, 0LL, &v31) )
{
printf(" Product Name : %s\n", (const char *)v31);
XFree(v31);
v31 = 0LL;
v9 = "Unknown";
if ( (unsigned int)XNVCTRLQueryTargetStringAttribute(v4, 1LL, v21, 0LL, 52LL, &v31) )
v9 = (const char *)v31;
printf(" GPU UUID : %s\n", v9);
XFree(v31);
v31 = 0LL;
v11 = XNVCTRLQueryTargetBinaryData(v4, 1LL, v21, 0LL, 10LL, &v30, v29, v10);
v12 = v20;
if ( v11 )
{
printf(" Coolers on GPU : ");
func1((int *)v30);
XFree(v30);
putchar(10);
if ( (unsigned int)XNVCTRLQueryTargetBinaryData(v4, 1LL, v21, 0LL, 12LL, &v30, v29, v13) )
{
printf(" Thermal Sensors on GPU : ");
func2((int *)v30);
XFree(v30);
putchar(10);
if ( (unsigned int)XNVCTRLQueryTargetBinaryData(v4, 1LL, v21, 0LL, 15LL, v32, v29, v14) )
{
printf(" Connected Display Devices : ");
func4((int *)v32[0]);
XFree(v32[0]);
putchar(10);
if ( (unsigned int)XNVCTRLQueryTargetBinaryData(v4, 1LL, v21, 0LL, 7LL, &v30, v29, v12) )
{
printf(" Framelock Devices : ");
func3((int *)v30);
XFree(v30);
putchar(10);
if ( (unsigned int)XNVCTRLQueryTargetBinaryData(v4, 1LL, v21, 0LL, 3LL, &v30, v29, v15) )
{
v16 = 0LL;
printf(" Number of X Screens on GPU %d : %d\n", v21, *(unsigned int *)v30);
while ( 1 )
{
if ( *(_DWORD *)v30 < (int)v16 + 1 )
{
XFree(v30);
++v21;
goto LABEL_12;
}
++v16;
v17 = *((_DWORD *)v30 + v16);
putchar(10);
printf(" X Screen %d information:\n", v17);
if ( !(unsigned int)XNVCTRLQueryTargetBinaryData(v4, 0LL, v17, 0LL, 18LL, v32, v29, v17) )
break;
printf(" Assigned Display Devices : ");
func4((int *)v32[0]);
XFree(v32[0]);
LODWORD(v18) = putchar(10);
if ( !(unsigned int)XNVCTRLQueryTargetBinaryData(v4, 0LL, v17, 0LL, 17LL, v32, v29, v18) )
break;
printf(" Enabled Display Devices : ");
func4((int *)v32[0]);
XFree(v32[0]);
putchar(10);
}
fwrite("Failed to query assigned displays\n", 1uLL, 0x22uLL, stderr);
}
else
{
fwrite("Failed to query list of X Screens\n", 1uLL, 0x22uLL, stderr);
}
}
else
{
fwrite("Failed to query framelock devices\n", 1uLL, 0x22uLL, stderr);
}
}
else
{
fwrite("Failed to query connected displays\n", 1uLL, 0x23uLL, stderr);
}
}
else
{
fwrite("Failed to query connected thermal sensors\n", 1uLL, 0x2AuLL, stderr);
}
}
else
{
fwrite("Failed to query connected coolers\n", 1uLL, 0x22uLL, stderr);
}
}
else
{
fwrite("Failed to query gpu product name\n", 1uLL, 0x21uLL, stderr);
}
}
}
else
{
fwrite("Failed to query number of Thermal Sensors\n", 1uLL, 0x2AuLL, stderr);
}
}
else
{
fwrite("Failed to query number of Coolers\n", 1uLL, 0x22uLL, stderr);
}
}
else
{
LABEL_27:
fwrite("Failed to query number of xscreens\n", 1uLL, 0x23uLL, stderr);
}
}
else
{
fwrite("Failed to query number of gpus\n", 1uLL, 0x1FuLL, stderr);
}
}
else
{
v5 = 1;
v6 = XDisplayName(0LL);
fprintf(stderr, "The NV-CONTROL X extension does not exist on '%s'.\n", v6);
}
}
else
{
v5 = 1;
v19 = XDisplayName(0LL);
fprintf(stderr, "Cannot open display '%s'.\n", v19);
}
return v5;
}


prependRoot

repo: NVIDIA/nvidia-settings

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 *


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

a1[2] = 16LL;
a1[1] = 0LL;
v1 = (_BYTE *)jsonp_malloc(16LL);
*a1 = v1;
if ( !v1 )
return 0xFFFFFFFFLL;
*v1 = 0;
return 0LL;
}

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

a1[2] = 16LL;
a1[1] = 0LL;
v1 = (_BYTE *)jsonp_malloc(16LL);
*a1 = v1;
if ( !v1 )
return 0xFFFFFFFFLL;
*v1 = 0;
return 0LL;
}

original_code:
int strbuffer_init(strbuffer_t *strbuff)
{
    strbuff->size = 16;
    strbuff->length = 0;
    strbuff->value = jsonp_malloc(strbuff->size);
    if(!strbuff->value)
        return -1;
    strbuff->value[0] = '\0';
    return 0;
}

canonical_original_code:
int strbuffer_init(struct strbuffer_t *strbuff)
{
    strbuff->size = 16;
    strbuff->length = 0;
    strbuff->value = jsonp_malloc(strbuff->size);
    if(!strbuff->value)
        return -1;
    strbuff->value[0] = '\0';
    return 0;
}

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

return_type: int


decompiled_code:
__int64 __fastcall strbuffer_value(__int64 a1)
{
return *(_QWORD *)a1;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
return *(_QWORD *)a1;
}

original_code:
const char *strbuffer_value(const strbuffer_t *strbuff)
{
    return strbuff->value;
}

canonical_original_code:
char *strbuffer_value(struct strbuffer_t *strbuff)
{
    return strbuff->value;
}

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


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

result = *a1;
*a1 = 0LL;
return result;
}

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

result = *a1;
*a1 = 0LL;
return result;
}

original_code:
char *strbuffer_steal_value(strbuffer_t *strbuff)
{
    char *result = strbuff->value;
    strbuff->value = ((void *)0);
    return result;
}

canonical_original_code:
char *strbuffer_steal_value(struct strbuffer_t *strbuff)
{
    char *result = strbuff->value;
    strbuff->value = ((void *)0);
    return result;
}

variable_types:
result
char *


decompiled_code:
__int64 __fastcall strbuffer_append_bytes(_QWORD *a1, const void *a2, size_t a3)
{
__int64 v5; // rdx
unsigned __int64 v6; // rdi
unsigned __int64 v7; // r14
unsigned __int64 v8; // rdx
char *v9; // rax
char *v10; // r13
_BYTE *v11; // rax
size_t v12; // r12

v5 = a1[2];
v6 = a1[1];
if ( v5 - v6 > a3 )
{
v10 = (char *)*a1;
goto LABEL_9;
}
if ( a3 != -1LL && v5 >= 0 && v6 <= -2LL - a3 )
{
v7 = v6 + a3 + 1;
v8 = 2 * v5;
if ( v7 < v8 )
v7 = v8;
v9 = (char *)jsonp_malloc(v7);
v10 = v9;
if ( v9 )
{
memcpy(v9, (const void *)*a1, a1[1]);
jsonp_free(*a1);
*a1 = v10;
v6 = a1[1];
a1[2] = v7;
LABEL_9:
memcpy(&v10[v6], a2, a3);
v11 = (_BYTE *)*a1;
v12 = a1[1] + a3;
a1[1] = v12;
v11[v12] = 0;
return 0LL;
}
}
return 0xFFFFFFFFLL;
}

original_code:
int strbuffer_append_bytes(strbuffer_t *strbuff, const char *data, size_t size)
{
    if(size >= strbuff->size - strbuff->length)
    {
        size_t new_size;
        char *new_value;
        if (strbuff->size > ((size_t)-1) / 2
            || size > ((size_t)-1) - 1
            || strbuff->length > ((size_t)-1) - 1 - size)
            return -1;
        new_size = ((strbuff->size * 2) > (strbuff->length + size + 1) ? (strbuff->size * 2) : (strbuff->length + size + 1));
        new_value = jsonp_malloc(new_size);
        if(!new_value)
            return -1;
        memcpy(new_value, strbuff->value, strbuff->length);
        jsonp_free(strbuff->value);
        strbuff->value = new_value;
        strbuff->size = new_size;
    }
    memcpy(strbuff->value + strbuff->length, data, size);
    strbuff->length += size;
    strbuff->value[strbuff->length] = '\0';
    return 0;
}

canonical_original_code:
int strbuffer_append_bytes(struct strbuffer_t *strbuff, char *data, unsigned long size)
{
    if(size >= strbuff->size - strbuff->length)
    {
        unsigned long new_size;
        char *new_value;
        if (strbuff->size > ((unsigned long)-1) / 2
            || size > ((unsigned long)-1) - 1
            || strbuff->length > ((unsigned long)-1) - 1 - size)
            return -1;
        new_size = ((strbuff->size * 2) > (strbuff->length + size + 1) ? (strbuff->size * 2) : (strbuff->length + size + 1));
        new_value = jsonp_malloc(new_size);
        if(!new_value)
            return -1;
        memcpy(new_value, strbuff->value, strbuff->length);
        jsonp_free(strbuff->value);
        strbuff->value = new_value;
        strbuff->size = new_size;
    }
    memcpy(strbuff->value + strbuff->length, data, size);
    strbuff->length += size;
    strbuff->value[strbuff->length] = '\0';
    return 0;
}

variable_types:
data
char *

variable_types:
size
unsigned long


decompiled_code:
__int64 __fastcall strbuffer_append_byte(_QWORD *a1, char a2)
{
char v3[4]; // [rsp+Ch] [rbp-4h] BYREF

v3[0] = a2;
return strbuffer_append_bytes(a1, v3, 1uLL);
}

canonical_decompiled_code:
__int64 __fastcall func5(_QWORD *a1, char a2)
{
char v3[4]; // [rsp+Ch] [rbp-4h] BYREF

v3[0] = a2;
return func4(a1, v3, 1uLL);
}

original_code:
int strbuffer_append_byte(strbuffer_t *strbuff, char byte)
{
    return strbuffer_append_bytes(strbuff, &byte, 1);
}

canonical_original_code:
int strbuffer_append_byte(struct strbuffer_t *strbuff, char byte)
{
    return strbuffer_append_bytes(strbuff, &byte, 1);
}

variable_types: byte char


decompiled_code:
__int64 __fastcall strbuffer_pop(_QWORD *a1)
{
__int64 v1; // rax
unsigned int v2; // er8
__int64 v3; // rax
_BYTE *v4; // rax

v1 = a1[1];
v2 = 0;
if ( v1 )
{
v3 = v1 - 1;
a1[1] = v3;
v4 = (_BYTE *)(*a1 + v3);
v2 = (unsigned __int8)*v4;
*v4 = 0;
}
return v2;
}

original_code:
char strbuffer_pop(strbuffer_t *strbuff)
{
    if(strbuff->length > 0) {
        char c = strbuff->value[--strbuff->length];
        strbuff->value[strbuff->length] = '\0';
        return c;
    }
    else
        return '\0';
}

canonical_original_code:
char strbuffer_pop(struct strbuffer_t *strbuff)
{
    if(strbuff->length > 0) {
        char c = strbuff->value[--strbuff->length];
        strbuff->value[strbuff->length] = '\0';
        return c;
    }
    else
        return '\0';
}

variable_types: c char

return_type: char


matrixMult

original_code:
void matrixMult(float a[16], const float b[16])
{
    int i, j, k;
    float aa[16];
    memcpy(aa, a, sizeof(aa));
    memset(a, 0, 16 * sizeof(float));
    for (j = 0; j < 4; j++) {
        for (i = 0; i < 4; i++) {
            for (k = 0; k < 4; k++) {
                a[4 * j + i] += aa[4 * j + k] * b[4 * k + i];
            }
        }
    }
}

canonical_original_code:
void matrixMult(float a[16], float b[16])
{
    int i; int j; int k;
    float aa[16];
    memcpy(aa, a, sizeof(aa));
    memset(a, 0, 16 * sizeof(float));
    for (j = 0; j < 4; j++) {
        for (i = 0; i < 4; i++) {
            for (k = 0; k < 4; k++) {
                a[4 * j + i] += aa[4 * j + k] * b[4 * k + i];
            }
        }
    }
}

variable_types:
a
float [16]

variable_types:
b
float [16]

variable_types: i int

variable_types: j int

variable_types: k int

variable_types:
aa
float [16]

return_type: void


matrixTranspose

decompiled_code:
int *__fastcall matrixTranspose(int *a1)
{
int *v1; // r9
int *v2; // r8
int v3; // esi
int *v4; // rcx
int *result; // rax
int *v6; // rdx
int v7; // xmm0_4
int v8; // xmm1_4

v1 = a1 + 4;
v2 = a1 + 1;
v3 = 1;
v4 = a1 + 5;
do
{
result = v2;
v6 = v1;
do
{
v7 = *v6;
v8 = *result;
result += 4;
*v6++ = v8;
*(result - 4) = v7;
}
while ( result != v4 );
++v3;
v1 += 4;
++v2;
v4 += 5;
}
while ( v3 != 4 );
return result;
}

canonical_decompiled_code:
int *__fastcall func1(int *a1)
{
int *v1; // r9
int *v2; // r8
int v3; // esi
int *v4; // rcx
int *result; // rax
int *v6; // rdx
int v7; // xmm0_4
int v8; // xmm1_4

v1 = a1 + 4;
v2 = a1 + 1;
v3 = 1;
v4 = a1 + 5;
do
{
result = v2;
v6 = v1;
do
{
v7 = *v6;
v8 = *result;
result += 4;
*v6++ = v8;
*(result - 4) = v7;
}
while ( result != v4 );
++v3;
v1 += 4;
++v2;
v4 += 5;
}
while ( v3 != 4 );
return result;
}

original_code:
void matrixTranspose(float m[16])
{
    int i, j;
    float tmp;
    for (j = 0; j < 4; ++j) {
        for (i = 0; i < j; ++i) {
            tmp = m[4 * j + i];
            m[4 * j + i] = m[4 * i + j];
            m[4 * i + j] = tmp;
        }
    }
}

canonical_original_code:
void matrixTranspose(float m[16])
{
    int i; int j;
    float tmp;
    for (j = 0; j < 4; ++j) {
        for (i = 0; i < j; ++i) {
            tmp = m[4 * j + i];
            m[4 * j + i] = m[4 * i + j];
            m[4 * i + j] = tmp;
        }
    }
}

variable_types:
m
float [16]

variable_types: tmp float


genZeroMatrix

decompiled_code:
void __fastcall genZeroMatrix(_OWORD *a1)
{
*a1 = 0LL;
a1[1] = 0LL;
a1[2] = 0LL;
a1[3] = 0LL;
}

original_code:
void genZeroMatrix(float matrix[16])
{
    memset(matrix, 0, 16 * sizeof(float));
}

variable_types:
matrix
float [16]


genTranslateMatrix

decompiled_code:
void __fastcall genTranslateMatrix(float *a1, float a2, float a3, float a4)
{
genIdentityMatrix((__int64)a1);
a1[12] = a2;
a1[13] = a3;
a1[14] = a4;
}

canonical_decompiled_code:
void __fastcall func4(float *a1, float a2, float a3, float a4)
{
func3((__int64)a1);
a1[12] = a2;
a1[13] = a3;
a1[14] = a4;
}

original_code:
void genTranslateMatrix(float x, float y, float z, float matrix[16])
{
    genIdentityMatrix(matrix);
    matrix[12] = x;
    matrix[13] = y;
    matrix[14] = z;
}

variable_types: x float

variable_types: y float

variable_types: z float


genRotateMatrixX

decompiled_code:
void __fastcall genRotateMatrixX(float *a1, float a2)
{
float v2; // [rsp+0h] [rbp-20h]
float v3; // [rsp+4h] [rbp-1Ch]
float cosx; // [rsp+8h] [rbp-18h] BYREF
float sinx[3]; // [rsp+Ch] [rbp-14h] BYREF

sincosf(a2, sinx, &cosx);
v2 = cosx;
v3 = sinx[0];
genIdentityMatrix((__int64)a1);
a1[5] = v2;
a1[9] = v3;
*((_DWORD *)a1 + 6) = LODWORD(v3) ^ LC2;
a1[10] = v2;
}

canonical_decompiled_code:
void __fastcall func5(float *a1, float a2)
{
float v2; // [rsp+0h] [rbp-20h]
float v3; // [rsp+4h] [rbp-1Ch]
float cosx; // [rsp+8h] [rbp-18h] BYREF
float sinx[3]; // [rsp+Ch] [rbp-14h] BYREF

sincosf(a2, sinx, &cosx);
v2 = cosx;
v3 = sinx[0];
func3((__int64)a1);
a1[5] = v2;
a1[9] = v3;
*((_DWORD *)a1 + 6) = LODWORD(v3) ^ LC2;
a1[10] = v2;
}

original_code:
void genRotateMatrixX(float radians, float matrix[16])
{
    genIdentityMatrix(matrix);
    matrix[5] = cosf(radians);
    matrix[6] = -1 * sinf(radians);
    matrix[9] = sinf(radians);
    matrix[10] = cosf(radians);
}

variable_types: radians float


genRotateMatrixY

decompiled_code:
void __fastcall genRotateMatrixY(float *a1, float a2)
{
float v2; // [rsp+0h] [rbp-20h]
float v3; // [rsp+4h] [rbp-1Ch]
float cosx; // [rsp+8h] [rbp-18h] BYREF
float sinx[3]; // [rsp+Ch] [rbp-14h] BYREF

sincosf(a2, sinx, &cosx);
v2 = cosx;
v3 = sinx[0];
genIdentityMatrix((__int64)a1);
*a1 = v2;
a1[8] = v3;
*((_DWORD *)a1 + 2) = LODWORD(v3) ^ LC2;
a1[10] = v2;
}

canonical_decompiled_code:
void __fastcall func6(float *a1, float a2)
{
float v2; // [rsp+0h] [rbp-20h]
float v3; // [rsp+4h] [rbp-1Ch]
float cosx; // [rsp+8h] [rbp-18h] BYREF
float sinx[3]; // [rsp+Ch] [rbp-14h] BYREF

sincosf(a2, sinx, &cosx);
v2 = cosx;
v3 = sinx[0];
func3((__int64)a1);
*a1 = v2;
a1[8] = v3;
*((_DWORD *)a1 + 2) = LODWORD(v3) ^ LC2;
a1[10] = v2;
}

original_code:
void genRotateMatrixY(float radians, float matrix[16])
{
    genIdentityMatrix(matrix);
    matrix[0] = cosf(radians);
    matrix[2] = -1 * sinf(radians);
    matrix[8] = sinf(radians);
    matrix[10] = cosf(radians);
}


genRotateMatrixZ

decompiled_code:
void __fastcall genRotateMatrixZ(float *a1, float a2)
{
float v2; // [rsp+0h] [rbp-20h]
float v3; // [rsp+4h] [rbp-1Ch]
float cosx; // [rsp+8h] [rbp-18h] BYREF
float sinx[3]; // [rsp+Ch] [rbp-14h] BYREF

sincosf(a2, sinx, &cosx);
v2 = cosx;
v3 = sinx[0];
genIdentityMatrix((__int64)a1);
a1[1] = v3;
*a1 = v2;
*((_DWORD *)a1 + 4) = LODWORD(v3) ^ LC2;
a1[5] = v2;
}

canonical_decompiled_code:
void __fastcall func7(float *a1, float a2)
{
float v2; // [rsp+0h] [rbp-20h]
float v3; // [rsp+4h] [rbp-1Ch]
float cosx; // [rsp+8h] [rbp-18h] BYREF
float sinx[3]; // [rsp+Ch] [rbp-14h] BYREF

sincosf(a2, sinx, &cosx);
v2 = cosx;
v3 = sinx[0];
func3((__int64)a1);
a1[1] = v3;
*a1 = v2;
*((_DWORD *)a1 + 4) = LODWORD(v3) ^ LC2;
a1[5] = v2;
}

original_code:
void genRotateMatrixZ(float radians, float matrix[16])
{
    genIdentityMatrix(matrix);
    matrix[0] = cosf(radians);
    matrix[1] = sinf(radians);
    matrix[4] = -1 * sinf(radians);
    matrix[5] = cosf(radians);
}


genPerspectiveMatrix

decompiled_code:
void __fastcall genPerspectiveMatrix(__int64 a1, float a2, float a3, float a4, float a5)
{
float v5; // [rsp+8h] [rbp-18h]

v5 = 1.0 / tanf(a2 * 0.5);
genZeroMatrix((_OWORD *)a1);
*(_DWORD *)(a1 + 56) = -1082130432;
*(float *)(a1 + 20) = v5;
*(float *)a1 = v5 / a3;
*(float *)(a1 + 40) = (float)(a5 + a4) / (float)(a4 - a5);
*(float *)(a1 + 44) = (float)((float)(a5 + a5) * a4) / (float)(a4 - a5);
}

original_code:
void genPerspectiveMatrix(float fovY,
                          float aspect,
                          float zNear,
                          float zFar,
                          float matrix[16])
{
    float f;
    f = 1 / tanf(fovY / 2);
    genZeroMatrix(matrix);
    matrix[0] = f / aspect;
    matrix[5] = f;
    matrix[10] = (zFar + zNear) / (zNear - zFar);
    matrix[11] = 2 * zFar * zNear / (zNear - zFar);
    matrix[14] = -1;
}

variable_types: fovY float

variable_types: aspect float

variable_types: zNear float

variable_types: zFar float

variable_types: f float


decompiled_code:
int __fastcall print_usage(const char **a1)
{
puts("Usage:");
printf("%s [-d <dpy>] [-a] [-c] [-b] [-s]\n", *a1);
putchar(10);
puts("-d <dpy>: X server display to connect to");
puts("-a: Listen for attribute availability events");
puts("-c: Listen for attribute changed events");
puts("-b: Listen for binary attribute changed events");
puts("-s: Listen for string attribute changed events");
putchar(10);
return puts("By default (i.e., if none of -a, -c, -b, or -s are requested),\nall event types are enabled.");
}

canonical_decompiled_code:
int __fastcall func0(const char **a1)
{
puts("Usage:");
printf("%s [-d <dpy>] [-a] [-c] [-b] [-s]\n", *a1);
putchar(10);
puts("-d <dpy>: X server display to connect to");
puts("-a: Listen for attribute availability events");
puts("-c: Listen for attribute changed events");
puts("-b: Listen for binary attribute changed events");
puts("-s: Listen for string attribute changed events");
putchar(10);
return puts("By default (i.e., if none of -a, -c, -b, or -s are requested),\nall event types are enabled.");
}

original_code:
static void print_usage(char **argv)
{
    printf("Usage:\n");
    printf("%s [-d <dpy>] [-a] [-c] [-b] [-s]\n", argv[0]);
    printf("\n");
    printf("-d <dpy>: X server display to connect to\n");
    printf("-a: Listen for attribute availability events\n");
    printf("-c: Listen for attribute changed events\n");
    printf("-b: Listen for binary attribute changed events\n");
    printf("-s: Listen for string attribute changed events\n");
    printf("\n");
    printf("By default (i.e., if none of -a, -c, -b, or -s are requested),\n"
           "all event types are enabled.\n");
}

variable_types:
argv
char **


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

switch ( a1 )
{
case 0u:
result = "X Screen";
break;
case 1u:
result = "GPU";
break;
case 2u:
result = "Frame Lock";
break;
case 5u:
result = "Cooler";
break;
case 6u:
result = "Thermal Sensor";
break;
case 7u:
result = "3D Vision Pro Transceiver";
break;
case 8u:
result = "Display";
break;
default:
snprintf(unknown_1, 0x18uLL, "Unknown (%d)", a1);
result = unknown_1;
break;
}
return result;
}

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

switch ( a1 )
{
case 0u:
result = "X Screen";
break;
case 1u:
result = "GPU";
break;
case 2u:
result = "Frame Lock";
break;
case 5u:
result = "Cooler";
break;
case 6u:
result = "Thermal Sensor";
break;
case 7u:
result = "3D Vision Pro Transceiver";
break;
case 8u:
result = "Display";
break;
default:
snprintf(unknown_1, 0x18uLL, "Unknown (%d)", a1);
result = unknown_1;
break;
}
return result;
}

original_code:
static const char *target2str(int n)
{
    static char unknown[24];
    switch (n) {
    case 0:
        return "X Screen";
    case 1:
        return "GPU";
    case 8:
        return "Display";
    case 2:
        return "Frame Lock";
    case 5:
        return "Cooler";
    case 6:
        return "Thermal Sensor";
    case 7:
        return "3D Vision Pro Transceiver";
    default:
        snprintf(unknown, 24, "Unknown (%d)", n);
        return unknown;
    }
}

canonical_original_code:
static char *target2str(int n)
{
    static char unknown[24];
    switch (n) {
    case 0:
        return "X Screen";
    case 1:
        return "GPU";
    case 8:
        return "Display";
    case 2:
        return "Frame Lock";
    case 5:
        return "Cooler";
    case 6:
        return "Thermal Sensor";
    case 7:
        return "3D Vision Pro Transceiver";
    default:
        snprintf(unknown, 24, "Unknown (%d)", n);
        return unknown;
    }
}

variable_types: n int

variable_types:
unknown
char [24]


decompiled_code:
char *__fastcall targetTypeAndId2Str(unsigned int a1, unsigned int a2)
{
const char *v2; // rax

v2 = target2str(a1);
snprintf(tmp_0, 0x100uLL, "%s-%-3d", v2, a2);
return tmp_0;
}

canonical_decompiled_code:
char *__fastcall func2(unsigned int a1, unsigned int a2)
{
const char *v2; // rax

v2 = func1(a1);
snprintf(tmp_0, 0x100uLL, "%s-%-3d", v2, a2);
return tmp_0;
}

original_code:
static const char *targetTypeAndId2Str(int targetType, int targetId)
{
    static char tmp[256];
    snprintf(tmp, sizeof(tmp), "%s-%-3d", target2str(targetType), targetId);
    return tmp;
}

canonical_original_code:
static char *targetTypeAndId2Str(int targetType, int targetId)
{
    static char tmp[256];
    snprintf(tmp, sizeof(tmp), "%s-%-3d", target2str(targetType), targetId);
    return tmp;
}

variable_types: targetType int

variable_types: targetId int

variable_types:
tmp
char [256]


decompiled_code:
char *__fastcall attr2str(int a1)
{
char *result; // rax
char *i; // rbx
const char *j; // r12
size_t v4; // r13
char *v5; // rax
char *v6; // r12

result = off_208;
if ( off_208 )
{
for ( i = (char *)&attr_table; *(_DWORD *)i != a1; i += 24 )
{
result = (char *)*((_QWORD *)i + 4);
if ( !result )
return result;
}
j = (const char *)*((_QWORD *)i + 2);
if ( !j )
{
v4 = 0LL;
v5 = strdup(result + 8);
*((_QWORD *)i + 2) = v5;
for ( j = v5; v4 < strlen(j); j = (const char *)*((_QWORD *)i + 2) )
{
v6 = (char *)&j[v4++];
*v6 = (*_ctype_tolower_loc())[*v6];
}
}
result = (char *)j;
}
return result;
}

canonical_decompiled_code:
char *__fastcall func3(int a1)
{
char *result; // rax
char *i; // rbx
const char *j; // r12
size_t v4; // r13
char *v5; // rax
char *v6; // r12

result = off_208;
if ( off_208 )
{
for ( i = (char *)&attr_table; *(_DWORD *)i != a1; i += 24 )
{
result = (char *)*((_QWORD *)i + 4);
if ( !result )
return result;
}
j = (const char *)*((_QWORD *)i + 2);
if ( !j )
{
v4 = 0LL;
v5 = strdup(result + 8);
*((_QWORD *)i + 2) = v5;
for ( j = v5; v4 < strlen(j); j = (const char *)*((_QWORD *)i + 2) )
{
v6 = (char *)&j[v4++];
*v6 = (*_ctype_tolower_loc())[*v6];
}
}
result = (char *)j;
}
return result;
}

original_code:
static const char *attr2str(int n)
{
    AttrEntry *entry;
    entry = attr_table;
    while (entry->str) {
        if (entry->num == n) {
            if (!entry->name) {
                int len;
                entry->name = strdup(entry->str + 8);
                for (len = 0; len < strlen(entry->name); len++) {
                    entry->name[len] = tolower(entry->name[len]);
                }
            }
            return entry->name;
        }
        entry++;
    }
    return ((void *)0);
}

canonical_original_code:
static char *attr2str(int n)
{
    struct AttrEntry *entry;
    entry = attr_table;
    while (entry->str) {
        if (entry->num == n) {
            if (!entry->name) {
                int len;
                entry->name = strdup(entry->str + 8);
                for (len = 0; len < strlen(entry->name); len++) {
                    entry->name[len] = tolower(entry->name[len]);
                }
            }
            return entry->name;
        }
        entry++;
    }
    return ((void *)0);
}

variable_types: struct AttrEntry { int num; char *str; char *name; } *

variable_types: len int


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int *v3; // rbx
int v4; // eax
__int128 *v6; // rax
Display *v7; // rax
Display *v8; // r14
__int64 v9; // r8
unsigned int *v10; // r12
int v11; // er13
__int64 v12; // rsi
__int64 v13; // r13
__int64 v14; // rax
unsigned int v15; // er12
int v16; // er15
__int128 *v17; // r13
unsigned int v18; // er11
__int64 v19; // rsi
int v20; // eax
unsigned int v21; // edi
const char *v22; // rax
int v23; // edi
char *v24; // rax
const char *v25; // rax
char *v26; // rax
__int64 v27; // r13
const char *v28; // r12
char *v29; // rax
char *v30; // rax
__int64 v31; // r13
const char *v32; // r12
char *v33; // rax
char *v34; // rax
const char *v35; // r13
char *v36; // rax
const char *v37; // r12
char *v38; // rax
char *v39; // rax
char *v40; // rax
char *v41; // rax
char *v42; // rax
char *v43; // r12
const char *v44; // rax
char *v45; // [rsp-1E0h] [rbp-1E8h]
unsigned int v46; // [rsp-1D8h] [rbp-1E0h]
unsigned int v47; // [rsp-1D4h] [rbp-1DCh]
__int64 v48; // [rsp-1D0h] [rbp-1D8h]
const char *v49; // [rsp-1C8h] [rbp-1D0h]
unsigned int v50; // [rsp-1C8h] [rbp-1D0h]
int v51; // [rsp-1B8h] [rbp-1C0h] BYREF
int v52; // [rsp-1B4h] [rbp-1BCh] BYREF
__int128 v53; // [rsp-1B0h] [rbp-1B8h] BYREF
__int64 v54; // [rsp-1A0h] [rbp-1A8h]
const char *v55; // [rsp-198h] [rbp-1A0h]
__int64 v56; // [rsp-190h] [rbp-198h]
const char *v57; // [rsp-188h] [rbp-190h]
__int64 v58; // [rsp-180h] [rbp-188h]
const char *v59; // [rsp-178h] [rbp-180h]
_QWORD v60[2]; // [rsp-170h] [rbp-178h] BYREF
_OWORD v61[7]; // [rsp-160h] [rbp-168h] BYREF
XEvent v62; // [rsp-F0h] [rbp-F8h] BYREF

v3 = (unsigned int *)v61;
v54 = 0LL;
memset(v61, 0, sizeof(v61));
v56 = 0LL;
v58 = 0LL;
LODWORD(v61[1]) = 1;
LODWORD(v61[2]) = 8;
LODWORD(v61[3]) = 2;
LODWORD(v61[4]) = 5;
LODWORD(v61[5]) = 6;
LODWORD(v61[6]) = 7;
v60[0] = 0LL;
v55 = "TARGET_ATTRIBUTE_CHANGED_EVENT";
v57 = "TARGET_ATTRIBUTE_AVAILABILITY_CHANGED_EVENT";
v59 = "TARGET_STRING_ATTRIBUTE_CHANGED_EVENT";
v60[1] = "TARGET_BINARY_ATTRIBUTE_CHANGED_EVENT";
v45 = 0LL;
v53 = 0LL;
while ( 2 )
{
v4 = getopt(argc, (char *const *)argv, "d:acbsh");
if ( v4 >= 0 )
{
switch ( v4 )
{
case '?':
fprintf(stderr, "%s: Unknown argument '%c'\n", *argv, (unsigned int)optopt);
goto LABEL_5;
case 'a':
LODWORD(v56) = 1;
continue;
case 'b':
LODWORD(v60[0]) = 1;
continue;
case 'c':
LODWORD(v54) = 1;
continue;
case 'd':
v45 = optarg;
continue;
case 'h':
LABEL_5:
print_usage(argv);
return 1;
case 's':
LODWORD(v58) = 1;
continue;
default:
continue;
}
}
break;
}
v6 = &v53;
while ( !*((_DWORD *)v6 + 4) )
{
if ( ++v6 == (__int128 *)v60 )
{
LODWORD(v54) = 1;
LODWORD(v56) = 1;
LODWORD(v58) = 1;
LODWORD(v60[0]) = 1;
break;
}
}
v7 = XOpenDisplay(v45);
v8 = v7;
if ( v7 )
{
if ( (unsigned int)XNVCTRLQueryExtension(v7, &v51, &v52) == 1 )
{
v10 = (unsigned int *)v61;
v11 = 0;
while ( 1 )
{
v12 = *v10;
if ( (_DWORD)v12 == 8 )
{
if ( (unsigned int)XNVCTRLQueryTargetBinaryData(v8, 0LL, 0LL, 0LL, 14LL, v10 + 2, v10 + 1, v9) != 1 )
{
LABEL_60:
v43 = XDisplayName(v45);
v44 = target2str(v61[v11]);
fprintf(stderr, "Failed to query %s target count on '%s'.\n", v44, v43);
return 1;
}
v10[1] = **((_DWORD **)v10 + 1);
}
else if ( (unsigned int)XNVCTRLQueryTargetCount(v8, v12, v10 + 1) != 1 )
{
goto LABEL_60;
}
++v11;
v10 += 4;
if ( v11 == 7 )
{
puts("Registering to receive events...");
fflush(stdout);
v47 = 0;
v46 = 0;
while ( 1 )
{
v13 = 0LL;
if ( (int)v3[1] > 0 )
{
do
{
v14 = *((_QWORD *)v3 + 1);
v15 = v13;
v48 = v13 + 1;
if ( v14 )
v15 = *(_DWORD *)(v14 + 4 * (v13 + 1));
v16 = 2;
v17 = &v53;
v18 = 1;
if ( (_DWORD)v54 )
{
v19 = *v3;
LABEL_35:
if ( !(_DWORD)v19 )
{
v50 = v18;
if ( !(unsigned int)XNVCTRLIsNvScreen(v8, v15) )
{
v40 = XDisplayName(v45);
printf("- The NV-CONTROL X not available on X screen %d of '%s'.\n", v46, v40);
goto LABEL_33;
}
if ( (unsigned int)XNVCtrlSelectNotify(v8, v15, 0LL, 1LL) != 1 )
{
v24 = XDisplayName(v45);
printf("- Unable to register to receive NV-CONTROLevents on '%s'.\n", v24);
goto LABEL_33;
}
printf("+ Listening on X screen %d for ATTRIBUTE_CHANGED_EVENTs.\n", v15);
++v47;
v19 = *v3;
v18 = v50;
}
goto LABEL_30;
}
LABEL_32:
while ( v16 != 5 )
{
LABEL_33:
while ( 1 )
{
v23 = *((_DWORD *)v17 + 8);
++v16;
++v17;
v18 = v16 - 1;
if ( !v23 )
break;
v19 = *v3;
if ( v16 == 2 )
goto LABEL_35;
LABEL_30:
v20 = XNVCtrlSelectTargetNotify(v8, v19, v15, v18, 1LL);
v21 = *v3;
v49 = (const char *)*((_QWORD *)v17 + 3);
if ( v20 != 1 )
{
v22 = target2str(v21);
printf("- Unable to register on %s %d for %ss.\n", v22, v15, v49);
goto LABEL_32;
}
v25 = target2str(v21);
printf("+ Listening on %s %d for %ss.\n", v25, v15, v49);
++v47;
if ( v16 == 5 )
goto LABEL_40;
}
}
LABEL_40:
v13 = v48;
}
while ( (int)v3[1] > (int)v48 );
}
++v46;
v3 += 4;
if ( v46 == 7 )
{
putchar(10);
printf("Listening on %d sources for NV-CONTROL X Events...\n", v47);
while ( 1 )
{
while ( 1 )
{
while ( 1 )
{
while ( 1 )
{
XNextEvent(v8, &v62);
if ( v62.type != v51 )
break;
v26 = targetTypeAndId2Str(0, v62.xcookie.cookie);
v27 = (unsigned int)v62.xexpose.height;
v28 = v26;
v29 = attr2str(v62.xexpose.width);
printf(
"ATTRIBUTE_CHANGED_EVENTS: Target: %15s Display Mask: 0x%08x Attribute: (%3"
"d) %-32s Value: %d (0x%08x)\n",
v28,
(unsigned int)v62.xfocus.detail,
(unsigned int)v62.xexpose.width,
v29,
(unsigned int)v27,
v27);
}
if ( v62.type != v51 + 1 )
break;
v30 = targetTypeAndId2Str(v62.xcookie.cookie, v62.xfocus.detail);
v31 = (unsigned int)v62.xexpose.count;
v32 = v30;
v33 = attr2str(v62.xexpose.height);
printf(
"TARGET_ATTRIBUTE_CHANGED_EVENT: Target: %15s Display Mask: 0x%08x Attribute: (%3d)"
" %-32s Value: %d (0x%08x)\n",
v32,
(unsigned int)v62.xexpose.width,
(unsigned int)v62.xexpose.height,
v33,
(unsigned int)v31,
v31);
}
if ( v62.type == v51 + 2 )
break;
if ( v62.type == v51 + 3 )
{
v39 = targetTypeAndId2Str(v62.xcookie.cookie, v62.xfocus.detail);
printf(
"TARGET_STRING_ATTRIBUTE_CHANGED_EVENT: Target: %15s Display Mask: 0x%08x Attribute: %3d\n",
v39,
(unsigned int)v62.xexpose.width,
(unsigned int)v62.xexpose.height);
}
else if ( v62.type == v51 + 4 )
{
v34 = targetTypeAndId2Str(v62.xcookie.cookie, v62.xfocus.detail);
printf(
"TARGET_BINARY_ATTRIBUTE_CHANGED_EVENT: Target: %15s Display Mask: 0x%08x Attribute: %3d\n",
v34,
(unsigned int)v62.xexpose.width,
(unsigned int)v62.xexpose.height);
}
else
{
printf("ERROR: unrecognized event type %d\n", (unsigned int)v62.type);
}
}
v35 = "No";
v36 = targetTypeAndId2Str(v62.xcookie.cookie, v62.xfocus.detail);
if ( v62.xgraphicsexpose.major_code )
v35 = "Yes";
v37 = v36;
v38 = attr2str(v62.xexpose.height);
printf(
"TARGET_ATTRIBUTE_AVAILABILITY_CHANGED_EVENT: Target: %15s Display Mask: 0x%08x Attribute: (%3d) %-3"
"2s Available: %s\n",
v37,
(unsigned int)v62.xexpose.width,
(unsigned int)v62.xexpose.height,
v38,
v35);
}
}
}
}
}
}
v41 = XDisplayName(v45);
fprintf(stderr, "The NV-CONTROL X extension does not exist on '%s'.\n", v41);
}
else
{
v42 = XDisplayName(v45);
fprintf(stderr, "Cannot open display '%s'.\n", v42);
}
return 1;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int *v3; // rbx
int v4; // eax
__int128 *v6; // rax
Display *v7; // rax
Display *v8; // r14
__int64 v9; // r8
unsigned int *v10; // r12
int v11; // er13
__int64 v12; // rsi
__int64 v13; // r13
__int64 v14; // rax
unsigned int v15; // er12
int v16; // er15
__int128 *v17; // r13
unsigned int v18; // er11
__int64 v19; // rsi
int v20; // eax
unsigned int v21; // edi
const char *v22; // rax
int v23; // edi
char *v24; // rax
const char *v25; // rax
char *v26; // rax
__int64 v27; // r13
const char *v28; // r12
char *v29; // rax
char *v30; // rax
__int64 v31; // r13
const char *v32; // r12
char *v33; // rax
char *v34; // rax
const char *v35; // r13
char *v36; // rax
const char *v37; // r12
char *v38; // rax
char *v39; // rax
char *v40; // rax
char *v41; // rax
char *v42; // rax
char *v43; // r12
const char *v44; // rax
char *v45; // [rsp-1E0h] [rbp-1E8h]
unsigned int v46; // [rsp-1D8h] [rbp-1E0h]
unsigned int v47; // [rsp-1D4h] [rbp-1DCh]
__int64 v48; // [rsp-1D0h] [rbp-1D8h]
const char *v49; // [rsp-1C8h] [rbp-1D0h]
unsigned int v50; // [rsp-1C8h] [rbp-1D0h]
int v51; // [rsp-1B8h] [rbp-1C0h] BYREF
int v52; // [rsp-1B4h] [rbp-1BCh] BYREF
__int128 v53; // [rsp-1B0h] [rbp-1B8h] BYREF
__int64 v54; // [rsp-1A0h] [rbp-1A8h]
const char *v55; // [rsp-198h] [rbp-1A0h]
__int64 v56; // [rsp-190h] [rbp-198h]
const char *v57; // [rsp-188h] [rbp-190h]
__int64 v58; // [rsp-180h] [rbp-188h]
const char *v59; // [rsp-178h] [rbp-180h]
_QWORD v60[2]; // [rsp-170h] [rbp-178h] BYREF
_OWORD v61[7]; // [rsp-160h] [rbp-168h] BYREF
XEvent v62; // [rsp-F0h] [rbp-F8h] BYREF

v3 = (unsigned int *)v61;
v54 = 0LL;
memset(v61, 0, sizeof(v61));
v56 = 0LL;
v58 = 0LL;
LODWORD(v61[1]) = 1;
LODWORD(v61[2]) = 8;
LODWORD(v61[3]) = 2;
LODWORD(v61[4]) = 5;
LODWORD(v61[5]) = 6;
LODWORD(v61[6]) = 7;
v60[0] = 0LL;
v55 = "TARGET_ATTRIBUTE_CHANGED_EVENT";
v57 = "TARGET_ATTRIBUTE_AVAILABILITY_CHANGED_EVENT";
v59 = "TARGET_STRING_ATTRIBUTE_CHANGED_EVENT";
v60[1] = "TARGET_BINARY_ATTRIBUTE_CHANGED_EVENT";
v45 = 0LL;
v53 = 0LL;
while ( 2 )
{
v4 = getopt(argc, (char *const *)argv, "d:acbsh");
if ( v4 >= 0 )
{
switch ( v4 )
{
case '?':
fprintf(stderr, "%s: Unknown argument '%c'\n", *argv, (unsigned int)optopt);
goto LABEL_5;
case 'a':
LODWORD(v56) = 1;
continue;
case 'b':
LODWORD(v60[0]) = 1;
continue;
case 'c':
LODWORD(v54) = 1;
continue;
case 'd':
v45 = optarg;
continue;
case 'h':
LABEL_5:
func0(argv);
return 1;
case 's':
LODWORD(v58) = 1;
continue;
default:
continue;
}
}
break;
}
v6 = &v53;
while ( !*((_DWORD *)v6 + 4) )
{
if ( ++v6 == (__int128 *)v60 )
{
LODWORD(v54) = 1;
LODWORD(v56) = 1;
LODWORD(v58) = 1;
LODWORD(v60[0]) = 1;
break;
}
}
v7 = XOpenDisplay(v45);
v8 = v7;
if ( v7 )
{
if ( (unsigned int)XNVCTRLQueryExtension(v7, &v51, &v52) == 1 )
{
v10 = (unsigned int *)v61;
v11 = 0;
while ( 1 )
{
v12 = *v10;
if ( (_DWORD)v12 == 8 )
{
if ( (unsigned int)XNVCTRLQueryTargetBinaryData(v8, 0LL, 0LL, 0LL, 14LL, v10 + 2, v10 + 1, v9) != 1 )
{
LABEL_60:
v43 = XDisplayName(v45);
v44 = func1(v61[v11]);
fprintf(stderr, "Failed to query %s target count on '%s'.\n", v44, v43);
return 1;
}
v10[1] = **((_DWORD **)v10 + 1);
}
else if ( (unsigned int)XNVCTRLQueryTargetCount(v8, v12, v10 + 1) != 1 )
{
goto LABEL_60;
}
++v11;
v10 += 4;
if ( v11 == 7 )
{
puts("Registering to receive events...");
fflush(stdout);
v47 = 0;
v46 = 0;
while ( 1 )
{
v13 = 0LL;
if ( (int)v3[1] > 0 )
{
do
{
v14 = *((_QWORD *)v3 + 1);
v15 = v13;
v48 = v13 + 1;
if ( v14 )
v15 = *(_DWORD *)(v14 + 4 * (v13 + 1));
v16 = 2;
v17 = &v53;
v18 = 1;
if ( (_DWORD)v54 )
{
v19 = *v3;
LABEL_35:
if ( !(_DWORD)v19 )
{
v50 = v18;
if ( !(unsigned int)XNVCTRLIsNvScreen(v8, v15) )
{
v40 = XDisplayName(v45);
printf("- The NV-CONTROL X not available on X screen %d of '%s'.\n", v46, v40);
goto LABEL_33;
}
if ( (unsigned int)XNVCtrlSelectNotify(v8, v15, 0LL, 1LL) != 1 )
{
v24 = XDisplayName(v45);
printf("- Unable to register to receive NV-CONTROLevents on '%s'.\n", v24);
goto LABEL_33;
}
printf("+ Listening on X screen %d for ATTRIBUTE_CHANGED_EVENTs.\n", v15);
++v47;
v19 = *v3;
v18 = v50;
}
goto LABEL_30;
}
LABEL_32:
while ( v16 != 5 )
{
LABEL_33:
while ( 1 )
{
v23 = *((_DWORD *)v17 + 8);
++v16;
++v17;
v18 = v16 - 1;
if ( !v23 )
break;
v19 = *v3;
if ( v16 == 2 )
goto LABEL_35;
LABEL_30:
v20 = XNVCtrlSelectTargetNotify(v8, v19, v15, v18, 1LL);
v21 = *v3;
v49 = (const char *)*((_QWORD *)v17 + 3);
if ( v20 != 1 )
{
v22 = func1(v21);
printf("- Unable to register on %s %d for %ss.\n", v22, v15, v49);
goto LABEL_32;
}
v25 = func1(v21);
printf("+ Listening on %s %d for %ss.\n", v25, v15, v49);
++v47;
if ( v16 == 5 )
goto LABEL_40;
}
}
LABEL_40:
v13 = v48;
}
while ( (int)v3[1] > (int)v48 );
}
++v46;
v3 += 4;
if ( v46 == 7 )
{
putchar(10);
printf("Listening on %d sources for NV-CONTROL X Events...\n", v47);
while ( 1 )
{
while ( 1 )
{
while ( 1 )
{
while ( 1 )
{
XNextEvent(v8, &v62);
if ( v62.type != v51 )
break;
v26 = func2(0, v62.xcookie.cookie);
v27 = (unsigned int)v62.xexpose.height;
v28 = v26;
v29 = func3(v62.xexpose.width);
printf(
"ATTRIBUTE_CHANGED_EVENTS: Target: %15s Display Mask: 0x%08x Attribute: (%3"
"d) %-32s Value: %d (0x%08x)\n",
v28,
(unsigned int)v62.xfocus.detail,
(unsigned int)v62.xexpose.width,
v29,
(unsigned int)v27,
v27);
}
if ( v62.type != v51 + 1 )
break;
v30 = func2(v62.xcookie.cookie, v62.xfocus.detail);
v31 = (unsigned int)v62.xexpose.count;
v32 = v30;
v33 = func3(v62.xexpose.height);
printf(
"TARGET_ATTRIBUTE_CHANGED_EVENT: Target: %15s Display Mask: 0x%08x Attribute: (%3d)"
" %-32s Value: %d (0x%08x)\n",
v32,
(unsigned int)v62.xexpose.width,
(unsigned int)v62.xexpose.height,
v33,
(unsigned int)v31,
v31);
}
if ( v62.type == v51 + 2 )
break;
if ( v62.type == v51 + 3 )
{
v39 = func2(v62.xcookie.cookie, v62.xfocus.detail);
printf(
"TARGET_STRING_ATTRIBUTE_CHANGED_EVENT: Target: %15s Display Mask: 0x%08x Attribute: %3d\n",
v39,
(unsigned int)v62.xexpose.width,
(unsigned int)v62.xexpose.height);
}
else if ( v62.type == v51 + 4 )
{
v34 = func2(v62.xcookie.cookie, v62.xfocus.detail);
printf(
"TARGET_BINARY_ATTRIBUTE_CHANGED_EVENT: Target: %15s Display Mask: 0x%08x Attribute: %3d\n",
v34,
(unsigned int)v62.xexpose.width,
(unsigned int)v62.xexpose.height);
}
else
{
printf("ERROR: unrecognized event type %d\n", (unsigned int)v62.type);
}
}
v35 = "No";
v36 = func2(v62.xcookie.cookie, v62.xfocus.detail);
if ( v62.xgraphicsexpose.major_code )
v35 = "Yes";
v37 = v36;
v38 = func3(v62.xexpose.height);
printf(
"TARGET_ATTRIBUTE_AVAILABILITY_CHANGED_EVENT: Target: %15s Display Mask: 0x%08x Attribute: (%3d) %-3"
"2s Available: %s\n",
v37,
(unsigned int)v62.xexpose.width,
(unsigned int)v62.xexpose.height,
v38,
v35);
}
}
}
}
}
}
v41 = XDisplayName(v45);
fprintf(stderr, "The NV-CONTROL X extension does not exist on '%s'.\n", v41);
}
else
{
v42 = XDisplayName(v45);
fprintf(stderr, "Cannot open display '%s'.\n", v42);
}
return 1;
}

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

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


decompiled_code:
// attributes: thunk
__int64 ctk_init_check()
{
return gtk_init_check();
}

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

original_code:
int ctk_init_check(int *argc, char **argv[])
{
    return gtk_init_check(argc, argv);
}

variable_types:
argc
int *

variable_types:
argv
char **[]


decompiled_code:
// attributes: thunk
__int64 ctk_get_display()
{
return gdk_get_display();
}

canonical_decompiled_code:
__int64 func1()
{
return gdk_get_display();
}

original_code:
char *ctk_get_display(void)
{
    return gdk_get_display();
}

canonical_original_code:
char *ctk_get_display()
{
    return gdk_get_display();
}


decompiled_code:
char *__fastcall cook_description(const char *a1)
{
const char *v1; // rbx
char *v2; // r8
char v3; // al
char *i; // rdx

if ( !a1 )
return 0LL;
v1 = a1;
v2 = strdup(a1);
if ( !v2 )
return 0LL;
v3 = *a1;
for ( i = v2; v3; ++v1 )
{
if ( v3 != 38 && v3 != 94 )
*i++ = v3;
v3 = v1[1];
}
*i = 0;
return v2;
}

canonical_decompiled_code:
char *__fastcall func0(const char *a1)
{
const char *v1; // rbx
char *v2; // r8
char v3; // al
char *i; // rdx

if ( !a1 )
return 0LL;
v1 = a1;
v2 = strdup(a1);
if ( !v2 )
return 0LL;
v3 = *a1;
for ( i = v2; v3; ++v1 )
{
if ( v3 != 38 && v3 != 94 )
*i++ = v3;
v3 = v1[1];
}
*i = 0;
return v2;
}

original_code:
static char *cook_description(const char *description)
{
    const char *src;
    char *s, *dst;
    if (!description) {
        return ((void *)0);
    }
    s = strdup(description);
    if (!s) {
        return ((void *)0);
    }
    for (src = description, dst = s; *src; src++) {
        if ((*src == '&') || (*src == '^')) {
            continue;
        }
        *dst = *src;
        dst++;
    }
    *dst = '\0';
    return s;
}

canonical_original_code:
static char *cook_description(char *description)
{
    char *src;
    char *s; char *dst;
    if (!description) {
        return ((void *)0);
    }
    s = strdup(description);
    if (!s) {
        return ((void *)0);
    }
    for (src = description, dst = s; *src; src++) {
        if ((*src == '&') || (*src == '^')) {
            continue;
        }
        *dst = *src;
        dst++;
    }
    *dst = '\0';
    return s;
}

variable_types:
description
char *

variable_types:
src
char *

variable_types:
s
char *

variable_types:
dst
char *


nvgetopt

decompiled_code:
__int64 __fastcall nvgetopt(int a1, const char **a2, __int64 a3, char **a4, int *a5, _DWORD *a6, double *a7, int *a8)
{
int v9; // eax
const char *v10; // r15
char *v11; // rax
char *v12; // r13
char *v13; // rcx
const char *v14; // rsi
const char *v15; // rdx
int v16; // er15
unsigned int v17; // er12
int v19; // ecx
const char *v20; // r8
const char *v21; // r12
char v22; // al
const char *v23; // rdx
const char *v24; // r11
const char *v25; // rsi
const char *v26; // r15
__int64 v27; // r12
bool v28; // r13
int v29; // er14
const char *v30; // rdi
int v31; // ebx
__int64 v32; // rbx
int v33; // edx
int v34; // edx
const char *v35; // rsi
__int64 v36; // rax
const char *v37; // rcx
const char *v38; // r8
char v39; // al
char v40; // al
int v41; // eax
__int64 v42; // [rsp+0h] [rbp-A0h]
const char *v43; // [rsp+10h] [rbp-90h]
const char *v44; // [rsp+18h] [rbp-88h]
const char *v45; // [rsp+20h] [rbp-80h]
char *v46; // [rsp+28h] [rbp-78h]
int v48; // [rsp+38h] [rbp-68h]
const char *v49; // [rsp+38h] [rbp-68h]
char v50; // [rsp+42h] [rbp-5Eh]
char v51; // [rsp+43h] [rbp-5Dh]
char *endptr[7]; // [rsp+68h] [rbp-38h] BYREF

if ( a4 )
*a4 = 0LL;
if ( a5 )
*a5 = 0;
if ( a6 )
*a6 = 0;
if ( a7 )
*a7 = 0.0;
if ( a8 )
*a8 = 0;
v48 = argv_index_0;
v9 = argv_index_0 + 1;
argv_index_0 = v9;
if ( v9 >= a1 )
return (unsigned int)-1;
v10 = a2[v9];
v11 = strdup(v10);
v12 = v11;
if ( *v11 != 45 )
{
v13 = v11;
v14 = "%s: invalid option: \"%s\"\n";
v15 = *a2;
LABEL_14:
v16 = 0;
v17 = 0;
fprintf(stderr, v14, v15, v13);
goto LABEL_15;
}
v19 = v11[1];
if ( v11[1] == 45 )
{
v19 = v11[2];
v20 = v11 + 2;
if ( !v11[2] )
{
v16 = 0;
v17 = -1;
goto LABEL_15;
}
}
else
{
v20 = v11 + 1;
if ( !(_BYTE)v19 )
goto LABEL_68;
}
v21 = v20;
v22 = v19;
do
{
v23 = v21++;
if ( v22 == 61 )
{
*v23 = 0;
v19 = *v20;
if ( !*v20 )
goto LABEL_68;
v24 = *(const char **)a3;
v51 = v20[1];
if ( v51 )
goto LABEL_26;
LABEL_38:
if ( v24 )
{
v32 = a3;
do
{
if ( (char)v19 == *(_DWORD *)(v32 + 8) )
{
v33 = *(_DWORD *)(v32 + 12);
v16 = 0;
goto LABEL_43;
}
v32 += 32LL;
}
while ( *(_QWORD *)v32 );
LABEL_56:
v34 = *v20;
if ( *v20 )
{
v35 = v20;
do
{
v36 = a3 + 32;
while ( *(_DWORD *)(v36 - 24) != v34 )
{
v36 += 32LL;
if ( !*(_QWORD *)(v36 - 32) )
goto LABEL_66;
}
v34 = *++v35;
}
while ( (_BYTE)v34 );
v32 = a3;
while ( *(_DWORD *)(v32 + 8) != v19 )
{
v32 += 32LL;
if ( !*(_QWORD *)v32 )
goto LABEL_66;
}
v33 = *(_DWORD *)(v32 + 12);
if ( (v33 & 0xE) == 0 )
{
v39 = *v10;
if ( *v10 == 45 )
{
v39 = v10[1];
if ( v39 == 45 )
{
v39 = v10[2];
v10 += 2;
}
else
{
++v10;
}
}
if ( v39 == 43 )
v39 = *++v10;
if ( v39 )
{
do
{
v40 = *++v10;
*((_BYTE *)v10 - 1) = v40;
}
while ( v40 );
v33 = *(_DWORD *)(v32 + 12);
}
v16 = 0;
argv_index_0 = v48;
goto LABEL_43;
}
LABEL_66:
if ( a6 )
{
if ( v51 )
{
v21 = v20 + 1;
v49 = v20;
strtol(v20 + 1, endptr, 0);
if ( !*endptr[0] )
{
if ( *(_QWORD *)a3 )
{
while ( 1 )
{
v33 = *(_DWORD *)(a3 + 12);
if ( (v33 & 4) != 0 && *(_DWORD *)(a3 + 8) == *v49 )
break;
a3 += 32LL;
if ( !*(_QWORD *)a3 )
goto LABEL_68;
}
v32 = a3;
v16 = 0;
goto LABEL_43;
}
}
}
}
}
LABEL_68:
v13 = v12;
v14 = "%s: unrecognized option: \"%s\"\n";
v15 = *a2;
goto LABEL_14;
}
LABEL_104:
if ( *v20 )
goto LABEL_66;
goto LABEL_68;
}
v22 = *v21;
}
while ( *v21 );
v24 = *(const char **)a3;
v21 = 0LL;
v51 = v20[1];
if ( !v51 )
goto LABEL_38;
LABEL_26:
if ( !v24 )
goto LABEL_104;
v46 = v12;
v25 = v24;
v43 = v10;
v26 = v20;
v45 = v21;
v27 = a3;
v44 = v20 + 3;
v50 = v19;
v28 = v51 == 111 && (_BYTE)v19 == 110;
v42 = a3;
while ( 1 )
{
v29 = *(_DWORD *)(v27 + 12);
v30 = v26;
v31 = 0;
if ( (v29 & 0x11) != 0 && v28 )
{
if ( v26[2] == 45 )
v30 = v44;
if ( v26[2] == 45 )
v31 = 1;
}
if ( !strcmp(v30, v25) )
break;
v25 = *(const char **)(v27 + 32);
v27 += 32LL;
if ( !v25 )
{
v20 = v26;
v19 = v50;
v12 = v46;
v10 = v43;
v21 = v45;
a3 = v42;
goto LABEL_56;
}
}
v16 = v31;
v12 = v46;
v32 = v27;
LOBYTE(v33) = v29;
v21 = v45;
LABEL_43:
if ( a5 && (v33 & 1) != 0 )
{
*a5 = v16 ^ 1;
v33 = *(_DWORD *)(v32 + 12);
}
if ( (v33 & 0x10) != 0 )
{
if ( (v33 & 0xE) == 0 || v16 )
goto LABEL_75;
LABEL_48:
if ( v21 )
{
if ( *v21 )
{
LABEL_50:
if ( (v33 & 4) != 0 && a6 )
{
*a6 = strtol(v21, endptr, 0);
v16 = 0;
if ( !*endptr[0] )
goto LABEL_76;
}
else
{
if ( (v33 & 2) != 0 && a4 )
{
*a4 = strdup(v21);
v16 = 0;
goto LABEL_76;
}
if ( (v33 & 8) == 0 || !a7 )
{
v13 = v12;
v14 = "%s: error while assigning argument for option \"%s\".\n";
v15 = *a2;
goto LABEL_14;
}
v16 = 0;
*a7 = strtod(v21, endptr);
if ( !*endptr[0] )
goto LABEL_76;
}
v37 = v21;
v17 = 0;
fprintf(stderr, "%s: \"%s\" is not a valid argument for option \"%s\".\n", *a2, v37, v12);
goto LABEL_15;
}
}
else
{
if ( (v33 & 0x20) != 0 && (a1 - 1 == argv_index_0 || *a2[argv_index_0 + 1] == 45) )
{
v16 = 0;
goto LABEL_76;
}
v41 = argv_index_0 + 1;
argv_index_0 = v41;
if ( v41 < a1 )
{
v21 = a2[v41];
goto LABEL_50;
}
}
v13 = v12;
v14 = "%s: option \"%s\" requires an argument.\n";
v15 = *a2;
goto LABEL_14;
}
v16 = 0;
if ( (v33 & 0xE) != 0 )
goto LABEL_48;
LABEL_75:
if ( v21 )
{
v38 = v21;
v17 = 0;
fprintf(
stderr,
"%s: option \"%s\" does not take an argument, but was given an argument of \"%s\".\n",
*a2,
v12,
v38);
}
else
{
LABEL_76:
v17 = *(_DWORD *)(v32 + 8);
}
LABEL_15:
if ( a8 )
*a8 = v16;
free(v12);
return v17;
}

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 *


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]


decompiled_code:
__int64 __fastcall dump_indent(char a1, int a2, int a3, unsigned int (__fastcall *a4)(const char *, __int64, __int64), __int64 a5)
{
unsigned int v7; // ebx
unsigned int v8; // er12

if ( (a1 & 0x1F) != 0 )
{
v7 = a2 * (a1 & 0x1F);
if ( !a4("\n", 1LL, a5) )
{
if ( !v7 )
return 0LL;
while ( 1 )
{
v8 = 32;
if ( v7 <= 0x20 )
v8 = v7;
if ( a4(" ", v8, a5) )
break;
v7 -= v8;
if ( !v7 )
return 0LL;
}
}
return 0xFFFFFFFFLL;
}
if ( !a3 || (a1 & 0x20) != 0 )
return 0LL;
return ((__int64 (__fastcall *)(void *, __int64, __int64))a4)(&unk_F22, 1LL, a5);
}

canonical_decompiled_code:
__int64 __fastcall func0(char a1, int a2, int a3, unsigned int (__fastcall *a4)(const char *, __int64, __int64), __int64 a5)
{
unsigned int v7; // ebx
unsigned int v8; // er12

if ( (a1 & 0x1F) != 0 )
{
v7 = a2 * (a1 & 0x1F);
if ( !a4("\n", 1LL, a5) )
{
if ( !v7 )
return 0LL;
while ( 1 )
{
v8 = 32;
if ( v7 <= 0x20 )
v8 = v7;
if ( a4(" ", v8, a5) )
break;
v7 -= v8;
if ( !v7 )
return 0LL;
}
}
return 0xFFFFFFFFLL;
}
if ( !a3 || (a1 & 0x20) != 0 )
return 0LL;
return ((__int64 (__fastcall *)(void *, __int64, __int64))a4)(&unk_F22, 1LL, a5);
}

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 *


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


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

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

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

v4 = a3[1];
if ( v4 + n <= *a3 )
{
memcpy((void *)(a3[2] + v4), src, n);
a3[1] += n;
}
else
{
a3[1] = v4 + 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; // r14
__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,
(unsigned int (__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; // r14
__int64 v4; // rax
char v5[64]; // [rsp+0h] [rbp-40h] BYREF

v2 = 0LL;
if ( !(unsigned int)strbuffer_init(v5) )
{
if ( !(unsigned int)func9(
a1,
(unsigned int (__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 *

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;
v8 = a2;
v7 = 0LL;
v4 = (unsigned int)json_dump_callback(
a1,
(unsigned int (__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;
v8 = a2;
v7 = 0LL;
v4 = (unsigned int)func9(
a1,
(unsigned int (__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, (unsigned int (__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, (unsigned int (__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; // rax
int *v3; // r13
double v4; // xmm0_8
char *endptr; // [rsp+8h] [rbp-28h] BYREF

to_locale((const char **)a1);
v2 = _errno_location();
*v2 = 0;
v3 = v2;
v4 = 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 ( (v4 == INFINITY || v4 == -INFINITY) && *v3 == 34 )
return 0xFFFFFFFFLL;
*a2 = v4;
return 0LL;
}

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

func0((const char **)a1);
v2 = _errno_location();
*v2 = 0;
v3 = v2;
v4 = 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 ( (v4 == INFINITY || v4 == -INFINITY) && *v3 == 34 )
return 0xFFFFFFFFLL;
*a2 = v4;
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, unsigned int a3)
{
__int64 v3; // rcx
int v4; // eax
__int64 v5; // r12
char *v6; // rax
char v7; // dl
_BYTE *v8; // rbx
_BYTE *v9; // rcx

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

canonical_decompiled_code:
__int64 __fastcall func3(char *s, size_t a2, unsigned int a3)
{
__int64 v3; // rcx
int v4; // eax
__int64 v5; // r12
char *v6; // rax
char v7; // dl
_BYTE *v8; // rbx
_BYTE *v9; // rcx

v3 = a3;
if ( !a3 )
v3 = 17LL;
v4 = snprintf(s, a2, "%.*g", v3);
if ( v4 >= 0 )
{
v5 = v4;
if ( a2 > v4 )
{
func1(s);
if ( strchr(s, 46) )
goto LABEL_6;
v6 = strchr(s, 101);
if ( v6 )
{
LABEL_7:
v7 = v6[2];
v8 = v6 + 2;
if ( v6[1] != 45 )
{
v9 = v6 + 1;
if ( v7 != 48 )
{
LABEL_10:
if ( v9 != v8 )
LODWORD(v5) = v5 - ((_DWORD)v8 - (unsigned int)memmove(v9, v8, v5 - (v8 - s)));
return (unsigned int)v5;
}
do
LABEL_9:
++v8;
while ( *v8 == 48 );
goto LABEL_10;
}
v9 = v6 + 2;
if ( v7 == 48 )
goto LABEL_9;
return (unsigned int)v5;
}
if ( v5 + 3 < a2 )
{
s[v5] = 46;
s[v5 + 1] = 48;
v5 += 2LL;
s[v5] = 0;
LABEL_6:
v6 = strchr(s, 101);
if ( !v6 )
return (unsigned int)v5;
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 a1)
{
void *result; // rax
int *v2; // rax
char *v3; // rax

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

canonical_decompiled_code:
void *__fastcall func0(size_t a1)
{
void *result; // rax
int *v2; // rax
char *v3; // rax

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

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 *