original_code:
int skip_list_delete (skip_list_t* skip_list, int key)
{
    skip_list_t* update_node[20];
    skip_list_t* node = skip_list;
    int i = skip_list->level;
    for(; i>=0; --i)
    {
        while (node->forward[i]!= ((void *)0) && key> node->forward[i]->key)
        {
            node= node->forward[i];
        }
        update_node[i]= node;
    }
    node = node->forward[0] == ((void *)0) ? node: node->forward[0];
    if (key == node->key)
    {
        for (i = 0; i <= skip_list->level; ++i)
        {
            if (update_node[i]->forward[i] != node)
            {
                break;
            }
            update_node[i]->forward[i] = node->forward[i];
        }
        free(node);
        return 0;
    }
    else
    {
        return 1;
    }
}

canonical_original_code:
int skip_list_delete(struct skip_list_struct *skip_list, int key)
{
    struct skip_list_struct *update_node[20];
    struct skip_list_struct *node = skip_list;
    int i = skip_list->level;
    for(; i>=0; --i)
    {
        while (node->forward[i]!= ((void *)0) && key> node->forward[i]->key)
        {
            node= node->forward[i];
        }
        update_node[i]= node;
    }
    node = node->forward[0] == ((void *)0) ? node: node->forward[0];
    if (key == node->key)
    {
        for (i = 0; i <= skip_list->level; ++i)
        {
            if (update_node[i]->forward[i] != node)
            {
                break;
            }
            update_node[i]->forward[i] = node->forward[i];
        }
        free(node);
        return 0;
    }
    else
    {
        return 1;
    }
}

variable_types: struct skip_list_struct { int key; int value; int level; struct skip_list_struct *forward[20]; } *

variable_types: i int


decompiled_code:
__int64 __fastcall skip_list_search(_DWORD *a1, int a2)
{
int v2; // ecx
_DWORD *v3; // rax
__int64 result; // rax
_DWORD *v5; // rax

v2 = a1[2];
if ( v2 >= 0 )
{
do
{
v5 = a1;
do
{
a1 = v5;
v5 = *(_DWORD **)&v5[2 * v2 + 4];
}
while ( v5 && *v5 < a2 );
--v2;
}
while ( v2 != -1 );
}
v3 = (_DWORD *)*((_QWORD *)a1 + 2);
if ( !v3 )
v3 = a1;
if ( *v3 == a2 )
result = (unsigned int)v3[1];
else
result = 0x80000000LL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func10(_DWORD *a1, int a2)
{
int v2; // ecx
_DWORD *v3; // rax
__int64 result; // rax
_DWORD *v5; // rax

v2 = a1[2];
if ( v2 >= 0 )
{
do
{
v5 = a1;
do
{
a1 = v5;
v5 = *(_DWORD **)&v5[2 * v2 + 4];
}
while ( v5 && *v5 < a2 );
--v2;
}
while ( v2 != -1 );
}
v3 = (_DWORD *)*((_QWORD *)a1 + 2);
if ( !v3 )
v3 = a1;
if ( *v3 == a2 )
result = (unsigned int)v3[1];
else
result = 0x80000000LL;
return result;
}

original_code:
int skip_list_search (skip_list_t* skip_list, int key)
{
    skip_list_t *node = skip_list;
    int level = node->level;
    int i = level;
    for (; i>= 0; --i)
    {
        while (node->forward[i] != ((void *)0) && key > node->forward[i]->key)
        {
            node = node->forward[i];
        }
    }
    node = node->forward[0] == ((void *)0) ? node : node->forward[0];
    if (key == node->key)
    {
        return node->value;
    }
    else
    {
        return (-0x7fffffff - 1);
    }
}

canonical_original_code:
int skip_list_search(struct skip_list_struct *skip_list, int key)
{
    struct skip_list_struct *node = skip_list;
    int level = node->level;
    int i = level;
    for (; i>= 0; --i)
    {
        while (node->forward[i] != ((void *)0) && key > node->forward[i]->key)
        {
            node = node->forward[i];
        }
    }
    node = node->forward[0] == ((void *)0) ? node : node->forward[0];
    if (key == node->key)
    {
        return node->value;
    }
    else
    {
        return (-0x7fffffff - 1);
    }
}

variable_types: key int

variable_types: level int

return_type: int

user_defined_types: struct skip_list_struct { int key; int value; int level; struct skip_list_struct *forward[20]; }


decompiled_code:
void __fastcall free_skip_list(void *ptr)
{
_QWORD *v2; // rbx
void *v3; // rdi

v2 = (_QWORD *)*((_QWORD *)ptr + 2);
while ( v2 )
{
v3 = v2;
v2 = (_QWORD *)v2[2];
free(v3);
}
free(ptr);
}

canonical_decompiled_code:
void __fastcall func12(void *ptr)
{
_QWORD *v2; // rbx
void *v3; // rdi

v2 = (_QWORD *)*((_QWORD *)ptr + 2);
while ( v2 )
{
v3 = v2;
v2 = (_QWORD *)v2[2];
free(v3);
}
free(ptr);
}

original_code:
int free_skip_list (skip_list_t* skip_list)
{
    skip_list_t *node = skip_list->forward[0];
    skip_list_t *next_node;
    while (node != ((void *)0))
    {
        next_node = node->forward[0];
        free(node);
        node = next_node;
    }
    free(skip_list);
}

canonical_original_code:
int free_skip_list(struct skip_list_struct *skip_list)
{
    struct skip_list_struct *node = skip_list->forward[0];
    struct skip_list_struct *next_node;
    while (node != ((void *)0))
    {
        next_node = node->forward[0];
        free(node);
        node = next_node;
    }
    free(skip_list);
}


decompiled_code:
int __fastcall print_skip_list(__int64 a1)
{
__int64 i; // r12
int result; // eax
unsigned int *v3; // rbx

for ( i = 0LL; i != 20; ++i )
{
v3 = *(unsigned int **)(a1 + 8 * i + 16);
printf("Level[%d]: ", (unsigned int)i);
for ( ; v3; v3 = *(unsigned int **)&v3[2 * (int)i + 4] )
printf("%d -> ", *v3);
result = puts("NULL");
}
return result;
}

canonical_decompiled_code:
int __fastcall func11(__int64 a1)
{
__int64 i; // r12
int result; // eax
unsigned int *v3; // rbx

for ( i = 0LL; i != 20; ++i )
{
v3 = *(unsigned int **)(a1 + 8 * i + 16);
printf("Level[%d]: ", (unsigned int)i);
for ( ; v3; v3 = *(unsigned int **)&v3[2 * (int)i + 4] )
printf("%d -> ", *v3);
result = puts("NULL");
}
return result;
}

original_code:
int print_skip_list (skip_list_t *skip_list)
{
    skip_list_t *node;
    int i = 0;
    for(; i < 20; ++i)
    {
        node = skip_list->forward[i];
        printf("Level[%d]: ", i);
        while(node != ((void *)0))
        {
            printf("%d -> ", node->key);
            node = node->forward[i];
        }
        printf("NULL\n");
    }
}

canonical_original_code:
int print_skip_list(struct skip_list_struct *skip_list)
{
    struct skip_list_struct *node;
    int i = 0;
    for(; i < 20; ++i)
    {
        node = skip_list->forward[i];
        printf("Level[%d]: ", i);
        while(node != ((void *)0))
        {
            printf("%d -> ", node->key);
            node = node->forward[i];
        }
        printf("NULL\n");
    }
}


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // eax
_DWORD *v4; // rbp
int i; // ebx
int v6; // er12
unsigned int v7; // ebx
unsigned int v8; // eax
int v9; // er12
unsigned int v10; // ebx
int v11; // eax
const char *v12; // rdx
int v13; // er12
int j; // ebx
float v15; // xmm0_4
int v16; // er12
int v17; // eax
float v18; // xmm0_4

v3 = time(0LL);
srand(v3);
puts("#### Function Test ####");
puts("== Init Skip List ==");
v4 = init_skip_list_node(19, 0x80000000, 0x80000000);
for ( i = 0; i != 20; ++i )
skip_list_write((__int64)v4, i, i);
puts("== Print Skip List ==");
print_skip_list((__int64)v4);
puts("== Search Key ==");
v6 = 20;
do
{
v7 = rand() % 25;
v8 = skip_list_search(v4, v7);
printf("Search [%d]: %d\n", v7, v8);
--v6;
}
while ( v6 );
puts("== Delete Key ==");
v9 = 20;
do
{
v10 = rand() % 25;
v11 = skip_list_delete(v4, v10);
v12 = "SUCCESS";
if ( v11 )
v12 = "NO FOUND";
printf("Delete [%d]: %s\n", v10, v12);
--v9;
}
while ( v9 );
puts("== Print Skip List ==");
print_skip_list((__int64)v4);
puts("#### Performance Test ####");
printf("== Insert 10^6 Items (%d Level) ==\n", 20LL);
v13 = clock();
for ( j = 0; j != 1000000; ++j )
skip_list_write((__int64)v4, j, j);
v15 = (double)(int)(clock() - v13) / 1000000.0 * 1000.0;
printf("Time: %f ms, Speed: %f Node/s\n", v15, (float)((float)(1000000.0 / v15) * 1000.0));
printf("== Search 10^6 Items (%d Level) ==\n", 20LL);
v16 = clock();
do
{
v17 = rand();
skip_list_search(v4, v17 % 1000000);
--j;
}
while ( j );
v18 = (double)(int)(clock() - v16) / 1000000.0 * 1000.0;
printf("Time: %f ms, Speed: %f Node/s\n", v18, (float)((float)(1000000.0 / v18) * 1000.0));
puts("#### Clear Memory ####");
free_skip_list(v4);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // eax
_DWORD *v4; // rbp
int i; // ebx
int v6; // er12
unsigned int v7; // ebx
unsigned int v8; // eax
int v9; // er12
unsigned int v10; // ebx
int v11; // eax
const char *v12; // rdx
int v13; // er12
int j; // ebx
float v15; // xmm0_4
int v16; // er12
int v17; // eax
float v18; // xmm0_4

v3 = time(0LL);
srand(v3);
puts("#### Function Test ####");
puts("== Init Skip List ==");
v4 = init_skip_list_node(19, 0x80000000, 0x80000000);
for ( i = 0; i != 20; ++i )
func8((__int64)v4, i, i);
puts("== Print Skip List ==");
func11((__int64)v4);
puts("== Search Key ==");
v6 = 20;
do
{
v7 = rand() % 25;
v8 = func10(v4, v7);
printf("Search [%d]: %d\n", v7, v8);
--v6;
}
while ( v6 );
puts("== Delete Key ==");
v9 = 20;
do
{
v10 = rand() % 25;
v11 = func9(v4, v10);
v12 = "SUCCESS";
if ( v11 )
v12 = "NO FOUND";
printf("Delete [%d]: %s\n", v10, v12);
--v9;
}
while ( v9 );
puts("== Print Skip List ==");
func11((__int64)v4);
puts("#### Performance Test ####");
printf("== Insert 10^6 Items (%d Level) ==\n", 20LL);
v13 = clock();
for ( j = 0; j != 1000000; ++j )
func8((__int64)v4, j, j);
v15 = (double)(int)(clock() - v13) / 1000000.0 * 1000.0;
printf("Time: %f ms, Speed: %f Node/s\n", v15, (float)((float)(1000000.0 / v15) * 1000.0));
printf("== Search 10^6 Items (%d Level) ==\n", 20LL);
v16 = clock();
do
{
v17 = rand();
func10(v4, v17 % 1000000);
--j;
}
while ( j );
v18 = (double)(int)(clock() - v16) / 1000000.0 * 1000.0;
printf("Time: %f ms, Speed: %f Node/s\n", v18, (float)((float)(1000000.0 / v18) * 1000.0));
puts("#### Clear Memory ####");
func12(v4);
return 0;
}

original_code:
int main(int argc, char *argv[])
{
    srand((unsigned)time(0));
    int count = 0;
    int i = 0;
    printf("#### Function Test ####\n");
    count = 20;
    printf("== Init Skip List ==\n");
    skip_list_t *skip_list = init_skip_list_node(20 -1, (-0x7fffffff - 1), (-0x7fffffff - 1));
    for (i = 0; i<count; ++i)
    {
        skip_list_write(skip_list, i, i);
    }
    printf("== Print Skip List ==\n");
    print_skip_list(skip_list);
    printf("== Search Key ==\n");
    for(i = 0; i<count; ++i)
    {
        int key = rand()%(count+5);
        printf("Search [%d]: %d\n", key, skip_list_search(skip_list, key));
    }
    printf("== Delete Key ==\n");
    for(i = 0; i < count; ++i)
    {
        int key = rand()%(count+5);
        printf("Delete [%d]: %s\n",key,skip_list_delete(skip_list, key) ? "NO FOUND" : "SUCCESS");
    }
    printf("== Print Skip List ==\n");
    print_skip_list(skip_list);
    printf("#### Performance Test ####\n");
    clock_t start, finish;
    float time = 0;
    count = 1000000;
    printf("== Insert 10^6 Items (%d Level) ==\n", 20);
    start = clock();
    for(i = 0; i < count; ++i)
    {
        skip_list_write(skip_list, i, i);
    }
    finish = clock();
    time = (double)(finish-start)/((__clock_t) 1000000)*1000;
    printf ("Time: %f ms, Speed: %f Node/s\n", time, count/time*1000);
    printf("== Search 10^6 Items (%d Level) ==\n", 20);
    start = clock();
    for(i = 0; i<count; ++i)
    {
        skip_list_search(skip_list, rand()%count);
    }
    finish = clock();
    time = (double)(finish-start)/((__clock_t) 1000000)*1000;
    printf ("Time: %f ms, Speed: %f Node/s\n", time, count/time*1000);
    printf("#### Clear Memory ####\n");
    free_skip_list(skip_list);
    return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
    srand((unsigned int)time(0));
    int count = 0;
    int i = 0;
    printf("#### Function Test ####\n");
    count = 20;
    printf("== Init Skip List ==\n");
    struct skip_list_struct *skip_list = init_skip_list_node(20 -1, (-0x7fffffff - 1), (-0x7fffffff - 1));
    for (i = 0; i<count; ++i)
    {
        skip_list_write(skip_list, i, i);
    }
    printf("== Print Skip List ==\n");
    print_skip_list(skip_list);
    printf("== Search Key ==\n");
    for(i = 0; i<count; ++i)
    {
        int key = rand()%(count+5);
        printf("Search [%d]: %d\n", key, skip_list_search(skip_list, key));
    }
    printf("== Delete Key ==\n");
    for(i = 0; i < count; ++i)
    {
        int key = rand()%(count+5);
        printf("Delete [%d]: %s\n",key,skip_list_delete(skip_list, key) ? "NO FOUND" : "SUCCESS");
    }
    printf("== Print Skip List ==\n");
    print_skip_list(skip_list);
    printf("#### Performance Test ####\n");
    long start; long finish;
    float time = 0;
    count = 1000000;
    printf("== Insert 10^6 Items (%d Level) ==\n", 20);
    start = clock();
    for(i = 0; i < count; ++i)
    {
        skip_list_write(skip_list, i, i);
    }
    finish = clock();
    time = (double)(finish-start)/((long) 1000000)*1000;
    printf ("Time: %f ms, Speed: %f Node/s\n", time, count/time*1000);
    printf("== Search 10^6 Items (%d Level) ==\n", 20);
    start = clock();
    for(i = 0; i<count; ++i)
    {
        skip_list_search(skip_list, rand()%count);
    }
    finish = clock();
    time = (double)(finish-start)/((long) 1000000)*1000;
    printf ("Time: %f ms, Speed: %f Node/s\n", time, count/time*1000);
    printf("#### Clear Memory ####\n");
    free_skip_list(skip_list);
    return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: count int

variable_types: start long

variable_types: finish long

variable_types: time float


repo: NVIDIA/nvidia-settings

decompiled_code:
__int64 update_scf_depth()
{
return 1LL;
}

canonical_decompiled_code:
__int64 func0()
{
return 1LL;
}

original_code:
int update_scf_depth(int depth)
{
    return 1;
}

variable_types: depth int


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
gen_manpage_opts_helper(&_options, argv, envp);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
func8(&_options, argv, envp);
return 0;
}

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:
int __fastcall print_option(const char **a1)
{
const char *v2; // rsi
const unsigned __int16 **v3; // rax
__int64 v4; // rsi
int v5; // eax
char *v6; // rbx
int v7; // er14
int v8; // edx
int v9; // er13
const char *v10; // rbx
int v11; // er12
const __int32_t *v12; // rsi
__int64 v13; // rax
__int64 v14; // rdx
char v15; // di
int v17; // [rsp+Ch] [rbp-74h]
char dest[112]; // [rsp+10h] [rbp-70h] BYREF

if ( (*((_BYTE *)a1 + 12) & 0xE) != 0 )
{
v2 = a1[2];
if ( v2 )
{
strcpy(dest, v2);
}
else
{
v10 = *a1;
v11 = strlen(*a1);
if ( v11 > 0 )
{
v12 = *__ctype_toupper_loc();
v13 = 0LL;
do
{
dest[v13] = v12[v10[v13]];
v14 = v13++;
}
while ( v14 != v11 - 1 );
}
dest[v11] = 0;
}
}
printf(".TP\n.BI \"");
v3 = __ctype_b_loc();
v4 = *((unsigned int *)a1 + 2);
if ( ((*v3)[(int)v4] & 0x400) != 0 )
{
printf("\\-%c", v4);
if ( (*((_BYTE *)a1 + 12) & 0xE) != 0 )
printf(" \" \"%s\" \"", dest);
printf(", ");
}
printf("\\-\\-%s", *a1);
if ( (*((_BYTE *)a1 + 12) & 0xE) != 0 )
{
printf("=\" \"%s", dest);
if ( (*((_BYTE *)a1 + 12) & 0x11) != 0 )
printf("\" \"");
}
v5 = *((_DWORD *)a1 + 3);
if ( (v5 & 0xF) == 1 || (v5 & 0x10) != 0 )
printf(", \\-\\-no\\-%s", *a1);
puts("\"");
v6 = (char *)a1[3];
if ( v6 )
{
v7 = 0;
v8 = 1;
v17 = 0;
v9 = 0;
while ( 1 )
{
v15 = *v6;
if ( !*v6 )
return putchar(10);
if ( v15 > 46 )
{
if ( v15 != 94 )
goto LABEL_34;
if ( v9 )
putchar(10);
else
printf("\n.B ");
v8 = v9;
v17 = v9;
v9 ^= 1u;
}
else
{
if ( v15 <= 9 )
{
LABEL_34:
putchar(v15);
v8 = 0;
v17 = 0;
goto LABEL_35;
}
switch ( v15 )
{
case 10:
putchar(10);
v8 = 1;
v17 = 0;
break;
case 32:
if ( !v17 )
{
putchar(32);
v8 = 0;
}
break;
case 38:
if ( v7 )
putchar(10);
else
printf("\n.I ");
v8 = v7;
v17 = v7;
v7 ^= 1u;
break;
case 39:
if ( v8 )
{
fprintf(
stderr,
"Error: *roff can't start a line with '''. If you started a line with ''' in the description of the '%s' "
"option, please add some text at the beginning of the sentence, so that a valid manpage can be generated.\n",
*a1);
exit(1);
}
goto LABEL_34;
case 45:
printf("\\-");
v8 = 0;
v17 = 0;
break;
case 46:
if ( v8 )
{
fprintf(
stderr,
"Error: *roff can't start a line with '.' If you used '&' or '^' to format text in the description of the"
" '%s' option, please add some text before the end of the sentence, so that a valid manpage can be generated.\n",
*a1);
exit(1);
}
goto LABEL_34;
default:
goto LABEL_34;
}
}
LABEL_35:
++v6;
}
}
return putchar(10);
}

canonical_decompiled_code:
int __fastcall func7(const char **a1)
{
const char *v2; // rsi
const unsigned __int16 **v3; // rax
__int64 v4; // rsi
int v5; // eax
char *v6; // rbx
int v7; // er14
int v8; // edx
int v9; // er13
const char *v10; // rbx
int v11; // er12
const __int32_t *v12; // rsi
__int64 v13; // rax
__int64 v14; // rdx
char v15; // di
int v17; // [rsp+Ch] [rbp-74h]
char dest[112]; // [rsp+10h] [rbp-70h] BYREF

if ( (*((_BYTE *)a1 + 12) & 0xE) != 0 )
{
v2 = a1[2];
if ( v2 )
{
strcpy(dest, v2);
}
else
{
v10 = *a1;
v11 = strlen(*a1);
if ( v11 > 0 )
{
v12 = *__ctype_toupper_loc();
v13 = 0LL;
do
{
dest[v13] = v12[v10[v13]];
v14 = v13++;
}
while ( v14 != v11 - 1 );
}
dest[v11] = 0;
}
}
printf(".TP\n.BI \"");
v3 = __ctype_b_loc();
v4 = *((unsigned int *)a1 + 2);
if ( ((*v3)[(int)v4] & 0x400) != 0 )
{
printf("\\-%c", v4);
if ( (*((_BYTE *)a1 + 12) & 0xE) != 0 )
printf(" \" \"%s\" \"", dest);
printf(", ");
}
printf("\\-\\-%s", *a1);
if ( (*((_BYTE *)a1 + 12) & 0xE) != 0 )
{
printf("=\" \"%s", dest);
if ( (*((_BYTE *)a1 + 12) & 0x11) != 0 )
printf("\" \"");
}
v5 = *((_DWORD *)a1 + 3);
if ( (v5 & 0xF) == 1 || (v5 & 0x10) != 0 )
printf(", \\-\\-no\\-%s", *a1);
puts("\"");
v6 = (char *)a1[3];
if ( v6 )
{
v7 = 0;
v8 = 1;
v17 = 0;
v9 = 0;
while ( 1 )
{
v15 = *v6;
if ( !*v6 )
return putchar(10);
if ( v15 > 46 )
{
if ( v15 != 94 )
goto LABEL_34;
if ( v9 )
putchar(10);
else
printf("\n.B ");
v8 = v9;
v17 = v9;
v9 ^= 1u;
}
else
{
if ( v15 <= 9 )
{
LABEL_34:
putchar(v15);
v8 = 0;
v17 = 0;
goto LABEL_35;
}
switch ( v15 )
{
case 10:
putchar(10);
v8 = 1;
v17 = 0;
break;
case 32:
if ( !v17 )
{
putchar(32);
v8 = 0;
}
break;
case 38:
if ( v7 )
putchar(10);
else
printf("\n.I ");
v8 = v7;
v17 = v7;
v7 ^= 1u;
break;
case 39:
if ( v8 )
{
fprintf(
stderr,
"Error: *roff can't start a line with '''. If you started a line with ''' in the description of the '%s' "
"option, please add some text at the beginning of the sentence, so that a valid manpage can be generated.\n",
*a1);
exit(1);
}
goto LABEL_34;
case 45:
printf("\\-");
v8 = 0;
v17 = 0;
break;
case 46:
if ( v8 )
{
fprintf(
stderr,
"Error: *roff can't start a line with '.' If you used '&' or '^' to format text in the description of the"
" '%s' option, please add some text before the end of the sentence, so that a valid manpage can be generated.\n",
*a1);
exit(1);
}
goto LABEL_34;
default:
goto LABEL_34;
}
}
LABEL_35:
++v6;
}
}
return putchar(10);
}

original_code:
static void print_option(const NVGetoptOption *o)
{
    char scratch[64];
    const char *s;
    int j, len;
    int italics, bold, omitWhiteSpace, firstchar;
    if (o->flags & (0x0002 | 0x0004 | 0x0008)) {
        if (o->arg_name) {
            strcpy(scratch, o->arg_name);
        } else {
            len = strlen(o->name);
            for (j = 0; j < len; j++) scratch[j] = toupper(o->name[j]);
            scratch[len] = '\0';
        }
    }
    printf(".TP\n.BI \"");
    if (((*__ctype_b_loc ())[(int) ((o->val))] & (unsigned short int) _ISalpha)) {
        printf("\\-%c", o->val);
        if (o->flags & (0x0002 | 0x0004 | 0x0008)) {
            printf(" \" \"%s\" \"", scratch);
        }
        printf(", ");
    }
    printf("\\-\\-%s", o->name);
    if (o->flags & (0x0002 | 0x0004 | 0x0008)) {
        printf("=\" \"%s", scratch);
        if ((o->flags & 0x0001) ||
            (o->flags & 0x0010)) {
            printf("\" \"");
        }
    }
    if (((o->flags & 0x0001) &&
         !(o->flags & (0x0002 | 0x0004 | 0x0008))) ||
        (o->flags & 0x0010)) {
        printf(", \\-\\-no\\-%s", o->name);
    }
    printf("\"\n");
    italics = 0;
    bold = 0;
    omitWhiteSpace = 0;
    firstchar = 1;
    for (s = o->description; s && *s; s++) {
        switch (*s) {
          case '&':
              if (italics) {
                  printf("\n");
              } else {
                  printf("\n.I ");
              }
              omitWhiteSpace = italics;
              firstchar = italics;
              italics = !italics;
              break;
          case '^':
              if (bold) {
                  printf("\n");
              } else {
                  printf("\n.B ");
              }
              omitWhiteSpace = bold;
              firstchar = bold;
              bold = !bold;
              break;
          case '-':
              printf("\\-");
              omitWhiteSpace = 0;
              firstchar = 0;
              break;
          case ' ':
              if (!omitWhiteSpace) {
                  printf(" ");
                  firstchar = 0;
              }
              break;
          case '\n':
              printf("\n");
              omitWhiteSpace = 0;
              firstchar = 1;
              break;
          case '.':
              if (firstchar) {
                  fprintf(stderr, "Error: *roff can't start a line with '.' "
                          "If you used '&' or '^' to format text in the "
                          "description of the '%s' option, please add some "
                          "text before the end of the sentence, so that a "
                          "valid manpage can be generated.\n", o->name);
                  exit(1);
              }
          case '\'':
              if (firstchar) {
                  fprintf(stderr, "Error: *roff can't start a line with '\''. "
                          "If you started a line with '\'' in the description "
                          "of the '%s' option, please add some text at the "
                          "beginning of the sentence, so that a valid manpage "
                          "can be generated.\n", o->name);
                  exit(1);
              }
          default:
              printf("%c", *s);
              omitWhiteSpace = 0;
              firstchar = 0;
              break;
        }
    }
    printf("\n");
}

canonical_original_code:
static void print_option(struct NVGetoptOption *o)
{
    char scratch[64];
    char *s;
    int j; int len;
    int italics; int bold; int omitWhiteSpace; int firstchar;
    if (o->flags & (0x0002 | 0x0004 | 0x0008)) {
        if (o->arg_name) {
            strcpy(scratch, o->arg_name);
        } else {
            len = strlen(o->name);
            for (j = 0; j < len; j++) scratch[j] = toupper(o->name[j]);
            scratch[len] = '\0';
        }
    }
    printf(".TP\n.BI \"");
    if (((*__ctype_b_loc ())[(int) ((o->val))] & (unsigned short) _ISalpha)) {
        printf("\\-%c", o->val);
        if (o->flags & (0x0002 | 0x0004 | 0x0008)) {
            printf(" \" \"%s\" \"", scratch);
        }
        printf(", ");
    }
    printf("\\-\\-%s", o->name);
    if (o->flags & (0x0002 | 0x0004 | 0x0008)) {
        printf("=\" \"%s", scratch);
        if ((o->flags & 0x0001) ||
            (o->flags & 0x0010)) {
            printf("\" \"");
        }
    }
    if (((o->flags & 0x0001) &&
         !(o->flags & (0x0002 | 0x0004 | 0x0008))) ||
        (o->flags & 0x0010)) {
        printf(", \\-\\-no\\-%s", o->name);
    }
    printf("\"\n");
    italics = 0;
    bold = 0;
    omitWhiteSpace = 0;
    firstchar = 1;
    for (s = o->description; s && *s; s++) {
        switch (*s) {
          case '&':
              if (italics) {
                  printf("\n");
              } else {
                  printf("\n.I ");
              }
              omitWhiteSpace = italics;
              firstchar = italics;
              italics = !italics;
              break;
          case '^':
              if (bold) {
                  printf("\n");
              } else {
                  printf("\n.B ");
              }
              omitWhiteSpace = bold;
              firstchar = bold;
              bold = !bold;
              break;
          case '-':
              printf("\\-");
              omitWhiteSpace = 0;
              firstchar = 0;
              break;
          case ' ':
              if (!omitWhiteSpace) {
                  printf(" ");
                  firstchar = 0;
              }
              break;
          case '\n':
              printf("\n");
              omitWhiteSpace = 0;
              firstchar = 1;
              break;
          case '.':
              if (firstchar) {
                  fprintf(stderr, "Error: *roff can't start a line with '.' "
                          "If you used '&' or '^' to format text in the "
                          "description of the '%s' option, please add some "
                          "text before the end of the sentence, so that a "
                          "valid manpage can be generated.\n", o->name);
                  exit(1);
              }
          case '\'':
              if (firstchar) {
                  fprintf(stderr, "Error: *roff can't start a line with '\''. "
                          "If you started a line with '\'' in the description "
                          "of the '%s' option, please add some text at the "
                          "beginning of the sentence, so that a valid manpage "
                          "can be generated.\n", o->name);
                  exit(1);
              }
          default:
              printf("%c", *s);
              omitWhiteSpace = 0;
              firstchar = 0;
              break;
        }
    }
    printf("\n");
}

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

variable_types:
scratch
char [64]

variable_types:
s
char *

variable_types: j int

variable_types: len int

variable_types: italics int

variable_types: bold int

variable_types: omitWhiteSpace int

variable_types: firstchar int

return_type: void


decompiled_code:
int __fastcall gen_manpage_opts_helper(const char **a1)
{
const char **v1; // r12
int result; // eax
const char **v3; // rbx
int v4; // er13

v1 = a1;
result = puts(".SH OPTIONS");
if ( *a1 )
{
v3 = a1;
v4 = 0;
do
{
if ( v3[3] )
{
if ( (*((_BYTE *)v3 + 12) & 0x40) != 0 )
result = print_option(v3);
else
v4 = 1;
}
v3 += 4;
}
while ( *v3 );
if ( v4 )
{
result = puts(".SH \"ADVANCED OPTIONS\"");
if ( *a1 )
{
do
{
if ( v1[3] )
{
if ( (*((_BYTE *)v1 + 12) & 0x40) == 0 )
result = print_option(v1);
}
v1 += 4;
}
while ( *v1 );
}
}
}
return result;
}

canonical_decompiled_code:
int __fastcall func8(const char **a1)
{
const char **v1; // r12
int result; // eax
const char **v3; // rbx
int v4; // er13

v1 = a1;
result = puts(".SH OPTIONS");
if ( *a1 )
{
v3 = a1;
v4 = 0;
do
{
if ( v3[3] )
{
if ( (*((_BYTE *)v3 + 12) & 0x40) != 0 )
result = func7(v3);
else
v4 = 1;
}
v3 += 4;
}
while ( *v3 );
if ( v4 )
{
result = puts(".SH \"ADVANCED OPTIONS\"");
if ( *a1 )
{
do
{
if ( v1[3] )
{
if ( (*((_BYTE *)v1 + 12) & 0x40) == 0 )
result = func7(v1);
}
v1 += 4;
}
while ( *v1 );
}
}
}
return result;
}

original_code:
void gen_manpage_opts_helper(const NVGetoptOption *options)
{
    int i;
    int has_advanced_options = 0;
    printf(".SH OPTIONS\n");
    for (i = 0; options[i].name; i++) {
        const NVGetoptOption *o = &options[i];
        if (!o->description) {
            continue;
        }
        if (!(o->flags & 0x0040)) {
            has_advanced_options = 1;
            continue;
        }
        print_option(o);
    }
    if (has_advanced_options) {
        printf(".SH \"ADVANCED OPTIONS\"\n");
        for (i = 0; options[i].name; i++) {
            const NVGetoptOption *o = &options[i];
            if (!o->description) {
                continue;
            }
            if (o->flags & 0x0040) {
                continue;
            }
            print_option(o);
        }
    }
}

canonical_original_code:
void gen_manpage_opts_helper(struct NVGetoptOption *options)
{
    int i;
    int has_advanced_options = 0;
    printf(".SH OPTIONS\n");
    for (i = 0; options[i].name; i++) {
        struct NVGetoptOption *o = &options[i];
        if (!o->description) {
            continue;
        }
        if (!(o->flags & 0x0040)) {
            has_advanced_options = 1;
            continue;
        }
        print_option(o);
    }
    if (has_advanced_options) {
        printf(".SH \"ADVANCED OPTIONS\"\n");
        for (i = 0; options[i].name; i++) {
            struct NVGetoptOption *o = &options[i];
            if (!o->description) {
                continue;
            }
            if (o->flags & 0x0040) {
                continue;
            }
            print_option(o);
        }
    }
}

variable_types: i int

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


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

if ( !_libGL )
_libGL = (void *)nvalloc(120LL);
v0 = (void **)_libGL;
if ( *(_QWORD *)_libGL )
{
++*((_DWORD *)_libGL + 2);
return 1LL;
}
*v0 = dlopen("libGL.so.1", 1);
v2 = _libGL;
if ( *(_QWORD *)_libGL )
{
dlerror();
v2[2] = dlsym((void *)*v2, "glGetString");
v3 = dlerror();
if ( !v3 )
{
dlerror();
v2[3] = dlsym((void *)*v2, "glXQueryExtension");
v3 = dlerror();
if ( !v3 )
{
dlerror();
v2[4] = dlsym((void *)*v2, "glXQueryServerString");
v3 = dlerror();
if ( !v3 )
{
dlerror();
v2[5] = dlsym((void *)*v2, "glXGetClientString");
v3 = dlerror();
if ( !v3 )
{
dlerror();
v2[6] = dlsym((void *)*v2, "glXQueryExtensionsString");
v3 = dlerror();
if ( !v3 )
{
dlerror();
v2[7] = dlsym((void *)*v2, "glXIsDirect");
v3 = dlerror();
if ( !v3 )
{
dlerror();
v2[8] = dlsym((void *)*v2, "glXMakeCurrent");
v3 = dlerror();
if ( !v3 )
{
dlerror();
v2[9] = dlsym((void *)*v2, "glXCreateContext");
v3 = dlerror();
if ( !v3 )
{
dlerror();
v2[10] = dlsym((void *)*v2, "glXDestroyContext");
v3 = dlerror();
if ( !v3 )
{
dlerror();
v2[11] = dlsym((void *)*v2, "glXChooseVisual");
v3 = dlerror();
if ( !v3 )
{
dlerror();
v2[12] = dlsym((void *)*v2, "glXGetFBConfigs");
v3 = dlerror();
if ( !v3 )
{
dlerror();
v2[13] = dlsym((void *)*v2, "glXGetFBConfigAttrib");
v3 = dlerror();
if ( !v3 )
{
dlerror();
v2[14] = dlsym((void *)*v2, "glXGetVisualFromFBConfig");
v3 = dlerror();
if ( !v3 )
{
++*((_DWORD *)v2 + 2);
return 1LL;
}
}
}
}
}
}
}
}
}
}
}
}
}
LABEL_8:
nv_error_msg("libGL setup error : %s\n", v3);
v2 = _libGL;
result = 0LL;
if ( !_libGL )
return result;
goto LABEL_11;
}
v3 = dlerror();
if ( v3 )
goto LABEL_8;
LABEL_11:
if ( *v2 )
{
dlclose((void *)*v2);
*(_QWORD *)_libGL = 0LL;
}
free(_libGL);
_libGL = 0LL;
return 0LL;
}

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

if ( !_libGL )
_libGL = (void *)nvalloc(120LL);
v0 = (void **)_libGL;
if ( *(_QWORD *)_libGL )
{
++*((_DWORD *)_libGL + 2);
return 1LL;
}
*v0 = dlopen("libGL.so.1", 1);
v2 = _libGL;
if ( *(_QWORD *)_libGL )
{
dlerror();
v2[2] = dlsym((void *)*v2, "glGetString");
v3 = dlerror();
if ( !v3 )
{
dlerror();
v2[3] = dlsym((void *)*v2, "glXQueryExtension");
v3 = dlerror();
if ( !v3 )
{
dlerror();
v2[4] = dlsym((void *)*v2, "glXQueryServerString");
v3 = dlerror();
if ( !v3 )
{
dlerror();
v2[5] = dlsym((void *)*v2, "glXGetClientString");
v3 = dlerror();
if ( !v3 )
{
dlerror();
v2[6] = dlsym((void *)*v2, "glXQueryExtensionsString");
v3 = dlerror();
if ( !v3 )
{
dlerror();
v2[7] = dlsym((void *)*v2, "glXIsDirect");
v3 = dlerror();
if ( !v3 )
{
dlerror();
v2[8] = dlsym((void *)*v2, "glXMakeCurrent");
v3 = dlerror();
if ( !v3 )
{
dlerror();
v2[9] = dlsym((void *)*v2, "glXCreateContext");
v3 = dlerror();
if ( !v3 )
{
dlerror();
v2[10] = dlsym((void *)*v2, "glXDestroyContext");
v3 = dlerror();
if ( !v3 )
{
dlerror();
v2[11] = dlsym((void *)*v2, "glXChooseVisual");
v3 = dlerror();
if ( !v3 )
{
dlerror();
v2[12] = dlsym((void *)*v2, "glXGetFBConfigs");
v3 = dlerror();
if ( !v3 )
{
dlerror();
v2[13] = dlsym((void *)*v2, "glXGetFBConfigAttrib");
v3 = dlerror();
if ( !v3 )
{
dlerror();
v2[14] = dlsym((void *)*v2, "glXGetVisualFromFBConfig");
v3 = dlerror();
if ( !v3 )
{
++*((_DWORD *)v2 + 2);
return 1LL;
}
}
}
}
}
}
}
}
}
}
}
}
}
LABEL_8:
nv_error_msg("libGL setup error : %s\n", v3);
v2 = _libGL;
result = 0LL;
if ( !_libGL )
return result;
goto LABEL_11;
}
v3 = dlerror();
if ( v3 )
goto LABEL_8;
LABEL_11:
if ( *v2 )
{
dlclose((void *)*v2);
*(_QWORD *)_libGL = 0LL;
}
free(_libGL);
_libGL = 0LL;
return 0LL;
}

original_code:
static int open_libgl(void)
{
    const char *error_str = ((void *)0);
    if ( !__libGL ) {
        __libGL = nvalloc(sizeof(__libGLInfo));
    }
    if ( __libGL->handle ) {
        __libGL->ref_count++;
        return 1;
    }
    __libGL->handle = dlopen("libGL.so.1", 0x00001);
    if ( !__libGL->handle ) {
        error_str = dlerror();
        goto fail;
    }
    __libGL->glGetString =
        ({ dlerror(); dlsym(__libGL->handle, "glGetString"); });
    if ((error_str = dlerror()) != ((void *)0)) goto fail;
    __libGL->glXQueryExtension =
        ({ dlerror(); dlsym(__libGL->handle, "glXQueryExtension"); });
    if ((error_str = dlerror()) != ((void *)0)) goto fail;
    __libGL->glXQueryServerString =
        ({ dlerror(); dlsym(__libGL->handle, "glXQueryServerString"); });
    if ((error_str = dlerror()) != ((void *)0)) goto fail;
    __libGL->glXGetClientString =
        ({ dlerror(); dlsym(__libGL->handle, "glXGetClientString"); });
    if ((error_str = dlerror()) != ((void *)0)) goto fail;
    __libGL->glXQueryExtensionsString =
        ({ dlerror(); dlsym(__libGL->handle, "glXQueryExtensionsString"); });
    if ((error_str = dlerror()) != ((void *)0)) goto fail;
    __libGL->glXIsDirect =
        ({ dlerror(); dlsym(__libGL->handle, "glXIsDirect"); });
    if ((error_str = dlerror()) != ((void *)0)) goto fail;
    __libGL->glXMakeCurrent =
        ({ dlerror(); dlsym(__libGL->handle, "glXMakeCurrent"); });
    if ((error_str = dlerror()) != ((void *)0)) goto fail;
    __libGL->glXCreateContext =
        ({ dlerror(); dlsym(__libGL->handle, "glXCreateContext"); });
    if ((error_str = dlerror()) != ((void *)0)) goto fail;
    __libGL->glXDestroyContext =
        ({ dlerror(); dlsym(__libGL->handle, "glXDestroyContext"); });
    if ((error_str = dlerror()) != ((void *)0)) goto fail;
    __libGL->glXChooseVisual =
        ({ dlerror(); dlsym(__libGL->handle, "glXChooseVisual"); });
    if ((error_str = dlerror()) != ((void *)0)) goto fail;
    __libGL->glXGetFBConfigs =
        ({ dlerror(); dlsym(__libGL->handle, "glXGetFBConfigs"); });
    if ((error_str = dlerror()) != ((void *)0)) goto fail;
    __libGL->glXGetFBConfigAttrib =
        ({ dlerror(); dlsym(__libGL->handle, "glXGetFBConfigAttrib"); });
    if ((error_str = dlerror()) != ((void *)0)) goto fail;
    __libGL->glXGetVisualFromFBConfig =
        ({ dlerror(); dlsym(__libGL->handle, "glXGetVisualFromFBConfig"); });
    if ((error_str = dlerror()) != ((void *)0)) goto fail;
    __libGL->ref_count++;
    return 1;
 fail:
    if ( error_str ) {
        nv_error_msg("libGL setup error : %s\n", error_str);
    }
    if ( __libGL ) {
        if ( __libGL->handle ) {
            dlclose(__libGL->handle);
            __libGL->handle = ((void *)0);
        }
        free(__libGL);
        __libGL = ((void *)0);
    }
    return 0;
}

canonical_original_code:
static int open_libgl()
{
    char *error_str = ((void *)0);
    if ( !__libGL ) {
        __libGL = nvalloc(sizeof(__libGLInfo));
    }
    if ( __libGL->handle ) {
        __libGL->ref_count++;
        return 1;
    }
    __libGL->handle = dlopen("libGL.so.1", 0x00001);
    if ( !__libGL->handle ) {
        error_str = dlerror();
        goto fail;
    }
    __libGL->glGetString =
        ({ dlerror(); dlsym(__libGL->handle, "glGetString"); });
    if ((error_str = dlerror()) != ((void *)0)) goto fail;
    __libGL->glXQueryExtension =
        ({ dlerror(); dlsym(__libGL->handle, "glXQueryExtension"); });
    if ((error_str = dlerror()) != ((void *)0)) goto fail;
    __libGL->glXQueryServerString =
        ({ dlerror(); dlsym(__libGL->handle, "glXQueryServerString"); });
    if ((error_str = dlerror()) != ((void *)0)) goto fail;
    __libGL->glXGetClientString =
        ({ dlerror(); dlsym(__libGL->handle, "glXGetClientString"); });
    if ((error_str = dlerror()) != ((void *)0)) goto fail;
    __libGL->glXQueryExtensionsString =
        ({ dlerror(); dlsym(__libGL->handle, "glXQueryExtensionsString"); });
    if ((error_str = dlerror()) != ((void *)0)) goto fail;
    __libGL->glXIsDirect =
        ({ dlerror(); dlsym(__libGL->handle, "glXIsDirect"); });
    if ((error_str = dlerror()) != ((void *)0)) goto fail;
    __libGL->glXMakeCurrent =
        ({ dlerror(); dlsym(__libGL->handle, "glXMakeCurrent"); });
    if ((error_str = dlerror()) != ((void *)0)) goto fail;
    __libGL->glXCreateContext =
        ({ dlerror(); dlsym(__libGL->handle, "glXCreateContext"); });
    if ((error_str = dlerror()) != ((void *)0)) goto fail;
    __libGL->glXDestroyContext =
        ({ dlerror(); dlsym(__libGL->handle, "glXDestroyContext"); });
    if ((error_str = dlerror()) != ((void *)0)) goto fail;
    __libGL->glXChooseVisual =
        ({ dlerror(); dlsym(__libGL->handle, "glXChooseVisual"); });
    if ((error_str = dlerror()) != ((void *)0)) goto fail;
    __libGL->glXGetFBConfigs =
        ({ dlerror(); dlsym(__libGL->handle, "glXGetFBConfigs"); });
    if ((error_str = dlerror()) != ((void *)0)) goto fail;
    __libGL->glXGetFBConfigAttrib =
        ({ dlerror(); dlsym(__libGL->handle, "glXGetFBConfigAttrib"); });
    if ((error_str = dlerror()) != ((void *)0)) goto fail;
    __libGL->glXGetVisualFromFBConfig =
        ({ dlerror(); dlsym(__libGL->handle, "glXGetVisualFromFBConfig"); });
    if ((error_str = dlerror()) != ((void *)0)) goto fail;
    __libGL->ref_count++;
    return 1;
 fail:
    if ( error_str ) {
        nv_error_msg("libGL setup error : %s\n", error_str);
    }
    if ( __libGL ) {
        if ( __libGL->handle ) {
            dlclose(__libGL->handle);
            __libGL->handle = ((void *)0);
        }
        free(__libGL);
        __libGL = ((void *)0);
    }
    return 0;
}


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

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

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

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

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

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


decompiled_code:
int __fastcall print_target_indices(const char *a1, int *a2)
{
__int64 v2; // rbx
int result; // eax

v2 = 1LL;
if ( *a2 > 0 )
{
while ( 1 )
{
result = printf("%s-%d", a1, (unsigned int)a2[v2++]);
if ( *a2 < (int)v2 )
break;
printf(", ");
}
}
return result;
}

canonical_decompiled_code:
int __fastcall func0(const char *a1, int *a2)
{
__int64 v2; // rbx
int result; // eax

v2 = 1LL;
if ( *a2 > 0 )
{
while ( 1 )
{
result = printf("%s-%d", a1, (unsigned int)a2[v2++]);
if ( *a2 < (int)v2 )
break;
printf(", ");
}
}
return result;
}

original_code:
static void print_target_indices(const char *prefix, const int *pData)
{
    int i, first = 1;
    for (i = 1; i <= pData[0]; i++) {
        if (!first) {
            printf(", ");
        }
        first = 0;
        printf("%s-%d", prefix, pData[i]);
    }
}

canonical_original_code:
static void print_target_indices(char *prefix, int *pData)
{
    int i; int first = 1;
    for (i = 1; i <= pData[0]; i++) {
        if (!first) {
            printf(", ");
        }
        first = 0;
        printf("%s-%d", prefix, pData[i]);
    }
}

variable_types:
prefix
char *

variable_types:
pData
int *

variable_types: first int


decompiled_code:
int __fastcall print_cooler_target_indices(int *a1)
{
return print_target_indices("COOLER", a1);
}

canonical_decompiled_code:
int __fastcall func1(int *a1)
{
return func0("COOLER", a1);
}

original_code:
static void print_cooler_target_indices(const int *pData)
{
    print_target_indices("COOLER", pData);
}

canonical_original_code:
static void print_cooler_target_indices(int *pData)
{
    print_target_indices("COOLER", pData);
}


decompiled_code:
int __fastcall print_thermal_sensor_target_indices(int *a1)
{
return print_target_indices("THERMAL-SENSOR", a1);
}

canonical_decompiled_code:
int __fastcall func2(int *a1)
{
return func0("THERMAL-SENSOR", a1);
}

original_code:
static void print_thermal_sensor_target_indices(const int *pData)
{
    print_target_indices("THERMAL-SENSOR", pData);
}

canonical_original_code:
static void print_thermal_sensor_target_indices(int *pData)
{
    print_target_indices("THERMAL-SENSOR", pData);
}


decompiled_code:
int __fastcall print_framelock_target_indices(int *a1)
{
return print_target_indices("FRAMELOCK", a1);
}

canonical_decompiled_code:
int __fastcall func3(int *a1)
{
return func0("FRAMELOCK", a1);
}

original_code:
static void print_framelock_target_indices(const int *pData)
{
    print_target_indices("FRAMELOCK", pData);
}

canonical_original_code:
static void print_framelock_target_indices(int *pData)
{
    print_target_indices("FRAMELOCK", pData);
}


decompiled_code:
int __fastcall print_display_device_target_indices(int *a1)
{
return print_target_indices("DPY", a1);
}

canonical_decompiled_code:
int __fastcall func4(int *a1)
{
return func0("DPY", a1);
}

original_code:
static void print_display_device_target_indices(const int *pData)
{
    print_target_indices("DPY", pData);
}

canonical_original_code:
static void print_display_device_target_indices(int *pData)
{
    print_target_indices("DPY", pData);
}


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
char *v9; // rax
unsigned int i; // er15
const char *v11; // rsi
__int64 v12; // r13
unsigned int v13; // er14
void *v14; // [rsp+0h] [rbp-70h] BYREF
void *v15; // [rsp+8h] [rbp-68h] BYREF
char v16[4]; // [rsp+14h] [rbp-5Ch] BYREF
void *v17; // [rsp+18h] [rbp-58h] BYREF
unsigned int v18; // [rsp+24h] [rbp-4Ch] BYREF
unsigned int v19; // [rsp+28h] [rbp-48h] BYREF
unsigned int v20; // [rsp+2Ch] [rbp-44h] BYREF
unsigned int v21; // [rsp+30h] [rbp-40h] BYREF
unsigned int v22; // [rsp+34h] [rbp-3Ch] BYREF
unsigned int v23; // [rsp+38h] [rbp-38h] BYREF
unsigned int v24[13]; // [rsp+3Ch] [rbp-34h] BYREF

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

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
Display *v3; // rax
Display *v4; // rbx
int v5; // er12
char *v6; // rax
char *v8; // rax
char *v9; // rax
unsigned int i; // er15
const char *v11; // rsi
__int64 v12; // r13
unsigned int v13; // er14
void *v14; // [rsp+0h] [rbp-70h] BYREF
void *v15; // [rsp+8h] [rbp-68h] BYREF
char v16[4]; // [rsp+14h] [rbp-5Ch] BYREF
void *v17; // [rsp+18h] [rbp-58h] BYREF
unsigned int v18; // [rsp+24h] [rbp-4Ch] BYREF
unsigned int v19; // [rsp+28h] [rbp-48h] BYREF
unsigned int v20; // [rsp+2Ch] [rbp-44h] BYREF
unsigned int v21; // [rsp+30h] [rbp-40h] BYREF
unsigned int v22; // [rsp+34h] [rbp-3Ch] BYREF
unsigned int v23; // [rsp+38h] [rbp-38h] BYREF
unsigned int v24[13]; // [rsp+3Ch] [rbp-34h] BYREF

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


prependRoot

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

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

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

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

variable_types:
pathname
char *

return_type: char *


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; } *


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 v4; // rax
unsigned __int64 v5; // rdx
unsigned __int64 v6; // r14
unsigned __int64 v7; // rax
void *v8; // rax
void *v9; // r15
size_t v10; // r12

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

canonical_decompiled_code:
__int64 __fastcall func4(_QWORD *a1, const void *a2, size_t a3)
{
__int64 v4; // rax
unsigned __int64 v5; // rdx
unsigned __int64 v6; // r14
unsigned __int64 v7; // rax
void *v8; // rax
void *v9; // r15
size_t v10; // r12

v4 = a1[2];
v5 = a1[1];
if ( v4 - v5 > a3 )
goto LABEL_9;
if ( a3 == -1LL || v4 < 0 )
return 0xFFFFFFFFLL;
if ( v5 > -2LL - a3 )
return 0xFFFFFFFFLL;
v6 = v5 + a3 + 1;
v7 = 2 * v4;
if ( v6 < v7 )
v6 = v7;
v8 = (void *)jsonp_malloc(v6);
v9 = v8;
if ( v8 )
{
memcpy(v8, (const void *)*a1, a1[1]);
jsonp_free(*a1);
*a1 = v9;
a1[2] = v6;
LABEL_9:
memcpy((void *)(*a1 + a1[1]), a2, a3);
v10 = a1[1] + a3;
a1[1] = v10;
*(_BYTE *)(*a1 + v10) = 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; // edx
__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: j int

variable_types: k int

variable_types:
aa
float [16]


matrixTranspose

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

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

variable_types:
matrix
float [16]


genTranslateMatrix

decompiled_code:
void __fastcall genTranslateMatrix(_DWORD *a1, __m128i a2, __m128i a3, __m128i a4)
{
genIdentityMatrix((__int64)a1);
a1[12] = _mm_cvtsi128_si32(a2);
a1[13] = _mm_cvtsi128_si32(a3);
a1[14] = _mm_cvtsi128_si32(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; // er12
float v3; // er13
float cosx; // [rsp+8h] [rbp-28h] BYREF
float sinx[9]; // [rsp+Ch] [rbp-24h] BYREF

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

canonical_decompiled_code:
void __fastcall func5(float *a1, float a2)
{
float v2; // er12
float v3; // er13
float cosx; // [rsp+8h] [rbp-28h] BYREF
float sinx[9]; // [rsp+Ch] [rbp-24h] BYREF

sincosf(a2, sinx, &cosx);
v2 = cosx;
v3 = sinx[0];
func3((__int64)a1);
a1[5] = v2;
*((_DWORD *)a1 + 6) = LODWORD(v3) ^ LC1;
a1[9] = v3;
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; // er12
float v3; // er13
float cosx; // [rsp+8h] [rbp-28h] BYREF
float sinx[9]; // [rsp+Ch] [rbp-24h] BYREF

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

canonical_decompiled_code:
void __fastcall func6(float *a1, float a2)
{
float v2; // er12
float v3; // er13
float cosx; // [rsp+8h] [rbp-28h] BYREF
float sinx[9]; // [rsp+Ch] [rbp-24h] BYREF

sincosf(a2, sinx, &cosx);
v2 = cosx;
v3 = sinx[0];
func3((__int64)a1);
*a1 = v2;
*((_DWORD *)a1 + 2) = LODWORD(v3) ^ LC1;
a1[8] = v3;
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; // er13
float v3; // er12
float cosx; // [rsp+8h] [rbp-28h] BYREF
float sinx[9]; // [rsp+Ch] [rbp-24h] BYREF

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

canonical_decompiled_code:
void __fastcall func7(float *a1, float a2)
{
float v2; // er13
float v3; // er12
float cosx; // [rsp+8h] [rbp-28h] BYREF
float sinx[9]; // [rsp+Ch] [rbp-24h] BYREF

sincosf(a2, sinx, &cosx);
v2 = cosx;
v3 = sinx[0];
func3((__int64)a1);
*a1 = v2;
a1[1] = v3;
*((_DWORD *)a1 + 4) = LODWORD(v3) ^ LC1;
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)
{
__m128i v5; // xmm6
float v6; // er12

v5 = (__m128i)(unsigned int)LC0;
*(float *)v5.m128i_i32 = 1.0 / tanf(a2 * 0.5);
v6 = COERCE_FLOAT(_mm_cvtsi128_si32(v5));
genZeroMatrix((_QWORD *)a1);
*(float *)a1 = v6 / a3;
*(float *)(a1 + 20) = v6;
*(float *)(a1 + 40) = (float)(a5 + a4) / (float)(a4 - a5);
*(float *)(a1 + 44) = (float)((float)(a5 + a5) * a4) / (float)(a4 - a5);
*(_DWORD *)(a1 + 56) = -1082130432;
}

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 *v2; // rbx
size_t i; // r13
const char *v4; // r12

result = off_8E8;
if ( off_8E8 )
{
v2 = (char *)&attr_table;
while ( *(_DWORD *)v2 != a1 )
{
v2 += 24;
result = (char *)*((_QWORD *)v2 + 1);
if ( !result )
return result;
}
if ( !*((_QWORD *)v2 + 2) )
{
*((_QWORD *)v2 + 2) = strdup(result + 8);
for ( i = 0LL; ; ++i )
{
v4 = (const char *)*((_QWORD *)v2 + 2);
if ( strlen(v4) <= i )
break;
v4[i] = (*_ctype_tolower_loc())[v4[i]];
}
}
result = (char *)*((_QWORD *)v2 + 2);
}
return result;
}

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

result = off_8E8;
if ( off_8E8 )
{
v2 = (char *)&attr_table;
while ( *(_DWORD *)v2 != a1 )
{
v2 += 24;
result = (char *)*((_QWORD *)v2 + 1);
if ( !result )
return result;
}
if ( !*((_QWORD *)v2 + 2) )
{
*((_QWORD *)v2 + 2) = strdup(result + 8);
for ( i = 0LL; ; ++i )
{
v4 = (const char *)*((_QWORD *)v2 + 2);
if ( strlen(v4) <= i )
break;
v4[i] = (*_ctype_tolower_loc())[v4[i]];
}
}
result = (char *)*((_QWORD *)v2 + 2);
}
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

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // eax
__int64 *v5; // rax
char *v6; // rbx
int i; // er12
char *v8; // rax
char *v9; // rax
__int64 v10; // rsi
char *v11; // rbx
const char *v12; // rax
char *v13; // rax
char *v14; // rax
const char *v15; // r13
const char *v16; // rax
__int64 *v17; // rbx
int j; // er12
const char *v19; // r13
const char *v20; // rax
__int64 v21; // rdx
unsigned int v22; // er14
char *v23; // rbx
__int64 v24; // r12
char *v25; // rax
char *v26; // rbx
__int64 v27; // r12
char *v28; // rax
char *v29; // rbx
const char *v30; // r12
char *v31; // rax
char *v32; // rax
char *v33; // rax
unsigned int *v34; // [rsp+0h] [rbp-1F0h]
unsigned int v35; // [rsp+Ch] [rbp-1E4h]
const char *v36; // [rsp+10h] [rbp-1E0h]
unsigned int v37; // [rsp+18h] [rbp-1D8h]
unsigned int v38; // [rsp+1Ch] [rbp-1D4h]
Display *v39; // [rsp+20h] [rbp-1D0h]
XEvent v40; // [rsp+30h] [rbp-1C0h] BYREF
__int64 v41[2]; // [rsp+F0h] [rbp-100h] BYREF
__int64 v42; // [rsp+100h] [rbp-F0h]
const char *v43; // [rsp+108h] [rbp-E8h]
__int64 v44; // [rsp+110h] [rbp-E0h]
const char *v45; // [rsp+118h] [rbp-D8h]
__int64 v46; // [rsp+120h] [rbp-D0h]
const char *v47; // [rsp+128h] [rbp-C8h]
__int64 v48[2]; // [rsp+130h] [rbp-C0h] BYREF
_OWORD v49[7]; // [rsp+140h] [rbp-B0h] BYREF
char v50[4]; // [rsp+1B8h] [rbp-38h] BYREF
int v51[13]; // [rsp+1BCh] [rbp-34h] BYREF

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

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // eax
__int64 *v5; // rax
char *v6; // rbx
int i; // er12
char *v8; // rax
char *v9; // rax
__int64 v10; // rsi
char *v11; // rbx
const char *v12; // rax
char *v13; // rax
char *v14; // rax
const char *v15; // r13
const char *v16; // rax
__int64 *v17; // rbx
int j; // er12
const char *v19; // r13
const char *v20; // rax
__int64 v21; // rdx
unsigned int v22; // er14
char *v23; // rbx
__int64 v24; // r12
char *v25; // rax
char *v26; // rbx
__int64 v27; // r12
char *v28; // rax
char *v29; // rbx
const char *v30; // r12
char *v31; // rax
char *v32; // rax
char *v33; // rax
unsigned int *v34; // [rsp+0h] [rbp-1F0h]
unsigned int v35; // [rsp+Ch] [rbp-1E4h]
const char *v36; // [rsp+10h] [rbp-1E0h]
unsigned int v37; // [rsp+18h] [rbp-1D8h]
unsigned int v38; // [rsp+1Ch] [rbp-1D4h]
Display *v39; // [rsp+20h] [rbp-1D0h]
XEvent v40; // [rsp+30h] [rbp-1C0h] BYREF
__int64 v41[2]; // [rsp+F0h] [rbp-100h] BYREF
__int64 v42; // [rsp+100h] [rbp-F0h]
const char *v43; // [rsp+108h] [rbp-E8h]
__int64 v44; // [rsp+110h] [rbp-E0h]
const char *v45; // [rsp+118h] [rbp-D8h]
__int64 v46; // [rsp+120h] [rbp-D0h]
const char *v47; // [rsp+128h] [rbp-C8h]
__int64 v48[2]; // [rsp+130h] [rbp-C0h] BYREF
_OWORD v49[7]; // [rsp+140h] [rbp-B0h] BYREF
char v50[4]; // [rsp+1B8h] [rbp-38h] BYREF
int v51[13]; // [rsp+1BCh] [rbp-34h] BYREF

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

v1 = a1;
if ( !a1 )
return 0LL;
v2 = strdup(a1);
if ( v2 )
{
v3 = *a1;
if ( *a1 )
{
v4 = v2;
do
{
if ( v3 != 38 && v3 != 94 )
*v4++ = v3;
v3 = *++v1;
}
while ( *v1 );
}
else
{
v4 = v2;
}
*v4 = 0;
}
return v2;
}

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

v1 = a1;
if ( !a1 )
return 0LL;
v2 = strdup(a1);
if ( v2 )
{
v3 = *a1;
if ( *a1 )
{
v4 = v2;
do
{
if ( v3 != 38 && v3 != 94 )
*v4++ = v3;
v3 = *++v1;
}
while ( *v1 );
}
else
{
v4 = v2;
}
*v4 = 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 *