decompiled_code:
__int64 __fastcall process_args(int argc, char **argv)
{
__int64 v2; // rax
__int64 v3; // rcx
int v4; // eax
struct option *v5; // rcx
void *v6; // rsp
const char *v7; // r13
_BYTE *v8; // rdx
struct option *v9; // rax
int v10; // eax
__int64 result; // rax
int v12; // eax
int v13; // eax
char *v14; // r14
char *v15; // rax
int v16; // eax
char *v17; // rax
double v18; // xmm0_8
char *v19; // rax
char *v20; // rax
int v21; // eax
_BYTE v22[15]; // [rsp+0h] [rbp-30h] BYREF
char v23; // [rsp+Fh] [rbp-21h] BYREF

memset(&opts, 0, 0x58uLL);
if ( longopts.name )
{
v2 = 1LL;
do
v3 = (int)v2++;
while ( *(_QWORD *)((char *)&loc_57F + 32 * v2 + 1) );
v4 = 2 * v3 + 1;
v5 = &longopts + v3;
v6 = alloca(v4);
v7 = v22;
if ( v5 > &longopts )
{
v8 = v22;
v9 = &longopts;
do
{
while ( 1 )
{
*v8 = v9->val;
if ( v9->has_arg )
break;
++v9;
++v8;
if ( v5 <= v9 )
goto LABEL_9;
}
++v9;
v8[1] = 58;
v8 += 2;
}
while ( v5 > v9 );
}
}
else
{
v7 = &v23;
}
LABEL_9:
while ( 2 )
{
v10 = getopt_long(argc, argv, v7, &longopts, 0LL);
if ( v10 == -1 )
{
result = *((unsigned int *)&opts + 12);
if ( (_DWORD)result )
{
result = *((unsigned int *)&opts + 13);
if ( (_DWORD)result )
{
result = 0LL;
if ( *((double *)&opts + 7) != 0.0 )
{
fwrite("Ignoring specified aspect-ratio\n", 1uLL, 0x20uLL, stderr);
result = 0LL;
}
}
}
}
else
{
switch ( v10 )
{
case 'A':
v21 = atoi(optarg);
*((_DWORD *)&opts + 16) = v21;
if ( (unsigned int)(v21 - 1) <= 7 )
continue;
fprintf(stderr, "anti-alias out of range 1 ~ %d", 8LL);
return 0xFFFFFFFFLL;
case 'L':
v14 = optarg;
opts = strdup(optarg);
if ( opts )
continue;
goto LABEL_19;
case 'P':
v14 = optarg;
v20 = strdup(optarg);
*(&opts + 2) = v20;
if ( v20 )
continue;
goto LABEL_19;
case 'R':
v14 = optarg;
v19 = strdup(optarg);
*(&opts + 9) = v19;
if ( v19 )
continue;
goto LABEL_19;
case 'V':
printf("mdz-%s\n", "0.1.2");
return 0xFFFFFFFFLL;
case 'a':
v18 = atof(optarg);
*((double *)&opts + 7) = v18;
if ( v18 > 0.0 )
continue;
fwrite("aspect-ratio must be above zero", 1uLL, 0x1FuLL, stderr);
return 0xFFFFFFFFLL;
case 'd':
v14 = optarg;
v17 = strdup(optarg);
*(&opts + 4) = v17;
if ( v17 )
continue;
goto LABEL_19;
case 'h':
v16 = atoi(optarg);
*((_DWORD *)&opts + 13) = v16;
if ( (unsigned int)(v16 - 2) <= 0x7FFD )
continue;
fprintf(stderr, "height out of range 1 ~ %d", 0x7FFFLL);
return 0xFFFFFFFFLL;
case 'l':
v14 = optarg;
v15 = strdup(optarg);
*(&opts + 1) = v15;
if ( v15 )
continue;
LABEL_19:
result = oom(*(&longopts.name + 4 * optind), v14);
break;
case 'p':
*((_DWORD *)&opts + 6) = 1;
continue;
case 't':
v13 = atoi(optarg);
*((_DWORD *)&opts + 20) = v13;
if ( (unsigned int)(v13 - 1) <= 0x1FF )
continue;
fprintf(stderr, "thread count out of range 1 ~ %d", 512LL);
result = 0xFFFFFFFFLL;
break;
case 'w':
v12 = atoi(optarg);
*((_DWORD *)&opts + 12) = v12;
if ( (unsigned int)(v12 - 2) <= 0x7FFD )
continue;
fprintf(stderr, "width out of range 1 ~ %d", 0x7FFFLL);
result = 0xFFFFFFFFLL;
break;
default:
show_usage(*argv);
result = 0xFFFFFFFFLL;
break;
}
}
return result;
}
}

canonical_decompiled_code:
__int64 __fastcall func2(int argc, char **argv)
{
__int64 v2; // rax
__int64 v3; // rcx
int v4; // eax
struct option *v5; // rcx
void *v6; // rsp
const char *v7; // r13
_BYTE *v8; // rdx
struct option *v9; // rax
int v10; // eax
__int64 result; // rax
int v12; // eax
int v13; // eax
char *v14; // r14
char *v15; // rax
int v16; // eax
char *v17; // rax
double v18; // xmm0_8
char *v19; // rax
char *v20; // rax
int v21; // eax
_BYTE v22[15]; // [rsp+0h] [rbp-30h] BYREF
char v23; // [rsp+Fh] [rbp-21h] BYREF

memset(&opts, 0, 0x58uLL);
if ( longopts.name )
{
v2 = 1LL;
do
v3 = (int)v2++;
while ( *(_QWORD *)((char *)&loc_57F + 32 * v2 + 1) );
v4 = 2 * v3 + 1;
v5 = &longopts + v3;
v6 = alloca(v4);
v7 = v22;
if ( v5 > &longopts )
{
v8 = v22;
v9 = &longopts;
do
{
while ( 1 )
{
*v8 = v9->val;
if ( v9->has_arg )
break;
++v9;
++v8;
if ( v5 <= v9 )
goto LABEL_9;
}
++v9;
v8[1] = 58;
v8 += 2;
}
while ( v5 > v9 );
}
}
else
{
v7 = &v23;
}
LABEL_9:
while ( 2 )
{
v10 = getopt_long(argc, argv, v7, &longopts, 0LL);
if ( v10 == -1 )
{
result = *((unsigned int *)&opts + 12);
if ( (_DWORD)result )
{
result = *((unsigned int *)&opts + 13);
if ( (_DWORD)result )
{
result = 0LL;
if ( *((double *)&opts + 7) != 0.0 )
{
fwrite("Ignoring specified aspect-ratio\n", 1uLL, 0x20uLL, stderr);
result = 0LL;
}
}
}
}
else
{
switch ( v10 )
{
case 'A':
v21 = atoi(optarg);
*((_DWORD *)&opts + 16) = v21;
if ( (unsigned int)(v21 - 1) <= 7 )
continue;
fprintf(stderr, "anti-alias out of range 1 ~ %d", 8LL);
return 0xFFFFFFFFLL;
case 'L':
v14 = optarg;
opts = strdup(optarg);
if ( opts )
continue;
goto LABEL_19;
case 'P':
v14 = optarg;
v20 = strdup(optarg);
*(&opts + 2) = v20;
if ( v20 )
continue;
goto LABEL_19;
case 'R':
v14 = optarg;
v19 = strdup(optarg);
*(&opts + 9) = v19;
if ( v19 )
continue;
goto LABEL_19;
case 'V':
printf("mdz-%s\n", "0.1.2");
return 0xFFFFFFFFLL;
case 'a':
v18 = atof(optarg);
*((double *)&opts + 7) = v18;
if ( v18 > 0.0 )
continue;
fwrite("aspect-ratio must be above zero", 1uLL, 0x1FuLL, stderr);
return 0xFFFFFFFFLL;
case 'd':
v14 = optarg;
v17 = strdup(optarg);
*(&opts + 4) = v17;
if ( v17 )
continue;
goto LABEL_19;
case 'h':
v16 = atoi(optarg);
*((_DWORD *)&opts + 13) = v16;
if ( (unsigned int)(v16 - 2) <= 0x7FFD )
continue;
fprintf(stderr, "height out of range 1 ~ %d", 0x7FFFLL);
return 0xFFFFFFFFLL;
case 'l':
v14 = optarg;
v15 = strdup(optarg);
*(&opts + 1) = v15;
if ( v15 )
continue;
LABEL_19:
result = func1(*(&longopts.name + 4 * optind), v14);
break;
case 'p':
*((_DWORD *)&opts + 6) = 1;
continue;
case 't':
v13 = atoi(optarg);
*((_DWORD *)&opts + 20) = v13;
if ( (unsigned int)(v13 - 1) <= 0x1FF )
continue;
fprintf(stderr, "thread count out of range 1 ~ %d", 512LL);
result = 0xFFFFFFFFLL;
break;
case 'w':
v12 = atoi(optarg);
*((_DWORD *)&opts + 12) = v12;
if ( (unsigned int)(v12 - 2) <= 0x7FFD )
continue;
fprintf(stderr, "width out of range 1 ~ %d", 0x7FFFLL);
result = 0xFFFFFFFFLL;
break;
default:
func0(*argv);
result = 0xFFFFFFFFLL;
break;
}
}
return result;
}
}

original_code:
int process_args(int argc, char** argv)
{
    memset(&opts, 0, sizeof(options));
    opts.width = 0;
    opts.height = 0;
    opts.aspect = 0;
    opts.antialias = 0;
    int optcount = 0;
    while (longopts[optcount].name)
        ++optcount;
    char shortopts[optcount * 2 + 1];
    char* sop = shortopts;
    struct option * lop = longopts;
    for (; lop < &longopts[optcount]; ++lop)
    {
        *sop++ = lop->val;
        if (lop->has_arg)
            *sop++ = ':';
    }
    for (;;)
    {
        int c = getopt_long(argc, argv, shortopts, longopts, 0);
        if (c == -1)
            break;
        switch(c)
        {
        case 'd':
            opts.dumpfile = strdup(optarg);
            if (!opts.dumpfile)
                return oom(longopts[optind].name, optarg);
            break;
        case 'l':
            if (!(opts.settingsfile = strdup(optarg)))
                return oom(longopts[optind].name, optarg);
            break;
        case 'P':
            if (!(opts.palettefile = strdup(optarg)))
                return oom(longopts[optind].name, optarg);
            break;
        case 'p':
            opts.randompalette = 1;
            break;
        case 'L':
            if (!(opts.logfile = strdup(optarg)))
                return oom(longopts[optind].name, optarg);
            break;
        case 'w':
            opts.width = atoi(optarg);
            if (opts.width < 2 || opts.width > 32767)
            {
                fprintf(stderr, "width out of range 1 ~ %d", 32767);
                return -1;
            }
            break;
        case 'h':
            opts.height = atoi(optarg);
            if (opts.height < 2 || opts.height > 32767)
            {
                fprintf(stderr, "height out of range 1 ~ %d", 32767);
                return -1;
            }
            break;
        case 'a':
            opts.aspect = atof(optarg);
            if (opts.aspect <= 0)
            {
                fprintf(stderr, "aspect-ratio must be above zero");
                return -1;
            }
            break;
        case 'A':
            opts.antialias = atoi(optarg);
            if (opts.antialias < 1 || opts.antialias > 8)
            {
                fprintf(stderr, "anti-alias out of range 1 ~ %d", 8);
                return -1;
            }
            break;
        case 'R':
            if (!(opts.renderfile = strdup(optarg)))
                return oom(longopts[optind].name, optarg);
            break;
        case 't':
            opts.threads = atoi(optarg);
            if (opts.threads < 1 || opts.threads > 512)
            {
                fprintf(stderr, "thread count out of range 1 ~ %d",
                                512);
                return -1;
            }
            break;
        case 'V':
            printf("mdz-%s\n", "0.1.2");
            return -1;
        default:
            show_usage(argv[0]);
            return -1;
        }
    }
    if (opts.width && opts.height && opts.aspect)
        fprintf(stderr, "Ignoring specified aspect-ratio\n");
    return 0;
}

canonical_original_code:
int process_args(int argc, char **argv)
{
    memset(&opts, 0, sizeof(options));
    opts.width = 0;
    opts.height = 0;
    opts.aspect = 0;
    opts.antialias = 0;
    int optcount = 0;
    while (longopts[optcount].name)
        ++optcount;
    char shortopts[-1];
    char *sop = shortopts;
    struct option *lop = longopts;
    for (; lop < &longopts[optcount]; ++lop)
    {
        *sop++ = lop->val;
        if (lop->has_arg)
            *sop++ = ':';
    }
    for (;;)
    {
        int c = getopt_long(argc, argv, shortopts, longopts, 0);
        if (c == -1)
            break;
        switch(c)
        {
        case 'd':
            opts.dumpfile = strdup(optarg);
            if (!opts.dumpfile)
                return oom(longopts[optind].name, optarg);
            break;
        case 'l':
            if (!(opts.settingsfile = strdup(optarg)))
                return oom(longopts[optind].name, optarg);
            break;
        case 'P':
            if (!(opts.palettefile = strdup(optarg)))
                return oom(longopts[optind].name, optarg);
            break;
        case 'p':
            opts.randompalette = 1;
            break;
        case 'L':
            if (!(opts.logfile = strdup(optarg)))
                return oom(longopts[optind].name, optarg);
            break;
        case 'w':
            opts.width = atoi(optarg);
            if (opts.width < 2 || opts.width > 32767)
            {
                fprintf(stderr, "width out of range 1 ~ %d", 32767);
                return -1;
            }
            break;
        case 'h':
            opts.height = atoi(optarg);
            if (opts.height < 2 || opts.height > 32767)
            {
                fprintf(stderr, "height out of range 1 ~ %d", 32767);
                return -1;
            }
            break;
        case 'a':
            opts.aspect = atof(optarg);
            if (opts.aspect <= 0)
            {
                fprintf(stderr, "aspect-ratio must be above zero");
                return -1;
            }
            break;
        case 'A':
            opts.antialias = atoi(optarg);
            if (opts.antialias < 1 || opts.antialias > 8)
            {
                fprintf(stderr, "anti-alias out of range 1 ~ %d", 8);
                return -1;
            }
            break;
        case 'R':
            if (!(opts.renderfile = strdup(optarg)))
                return oom(longopts[optind].name, optarg);
            break;
        case 't':
            opts.threads = atoi(optarg);
            if (opts.threads < 1 || opts.threads > 512)
            {
                fprintf(stderr, "thread count out of range 1 ~ %d",
                                512);
                return -1;
            }
            break;
        case 'V':
            printf("mdz-%s\n", "0.1.2");
            return -1;
        default:
            show_usage(argv[0]);
            return -1;
        }
    }
    if (opts.width && opts.height && opts.aspect)
        fprintf(stderr, "Ignoring specified aspect-ratio\n");
    return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types: optcount int

variable_types:
shortopts
char [-1]

variable_types:
sop
char *

variable_types: struct option { char *name; int has_arg; int *flag; int val; } *

variable_types: c int


repo: jwm-art-net/MDZ

decompiled_code:
void cleanup_opts()
{
void *v0; // rdi
void *v1; // rdi
void *v2; // rdi
void *v3; // rdi
void *v4; // rdi

v0 = opts;
if ( opts )
{
if ( (*(_BYTE *)opts != 45 || *((_BYTE *)opts + 1)) && *(&opts + 5) )
{
fclose((FILE *)*(&opts + 5));
v0 = opts;
}
free(v0);
}
v1 = *(&opts + 1);
if ( v1 )
free(v1);
v2 = *(&opts + 2);
if ( v2 )
free(v2);
v3 = *(&opts + 4);
if ( v3 )
free(v3);
v4 = *(&opts + 9);
if ( v4 )
free(v4);
}

canonical_decompiled_code:
void func3()
{
void *v0; // rdi
void *v1; // rdi
void *v2; // rdi
void *v3; // rdi
void *v4; // rdi

v0 = opts;
if ( opts )
{
if ( (*(_BYTE *)opts != 45 || *((_BYTE *)opts + 1)) && *(&opts + 5) )
{
fclose((FILE *)*(&opts + 5));
v0 = opts;
}
free(v0);
}
v1 = *(&opts + 1);
if ( v1 )
free(v1);
v2 = *(&opts + 2);
if ( v2 )
free(v2);
v3 = *(&opts + 4);
if ( v3 )
free(v3);
v4 = *(&opts + 9);
if ( v4 )
free(v4);
}

original_code:
void cleanup_opts()
{
    if (opts.logfile)
    {
        if (strcmp("-", opts.logfile) != 0)
        {
            if (opts.logfd)
                fclose(opts.logfd);
        }
        free(opts.logfile);
    }
    if (opts.settingsfile)
        free(opts.settingsfile);
    if (opts.palettefile)
        free(opts.palettefile);
    if (opts.dumpfile)
        free(opts.dumpfile);
    if (opts.renderfile)
        free(opts.renderfile);
}

return_type: void


decompiled_code:
char *__fastcall my_mpfr_to_str(__int64 a1)
{
mpfr_snprintf(d0_0, 4096LL, "%.Re", a1);
return strdup(d0_0);
}

canonical_decompiled_code:
char *__fastcall func0(__int64 a1)
{
mpfr_snprintf(d0_0, 4096LL, "%.Re", a1);
return strdup(d0_0);
}

original_code:
char* my_mpfr_to_str(mpfr_t n)
{
    static char d0[4096 + 1];
    mpfr_snprintf(d0, 4096, "%.Re", n);
    return strdup(d0);
}

canonical_original_code:
char *my_mpfr_to_str(struct __mpfr_struct n[1])
{
    static char d0[-1];
    mpfr_snprintf(d0, 4096, "%.Re", n);
    return strdup(d0);
}

variable_types: struct __mpfr_struct { long _mpfr_prec; int _mpfr_sign; long _mpfr_exp; unsigned long *_mpfr_d; } [1]

return_type: char *


decompiled_code:
char *setting_init()
{
char *result; // rax

result = setlocale(1, 0LL);
sysloc = result;
return result;
}

canonical_decompiled_code:
char *func0()
{
char *result; // rax

result = setlocale(1, 0LL);
sysloc = result;
return result;
}

original_code:
void setting_init()
{
    sysloc = setlocale(1, 0);
}


decompiled_code:
void *__fastcall setting_get_str(char *s2, char *s1)
{
char *v2; // rbp
size_t v3; // rbx
size_t v4; // r12
void *v5; // rax

v2 = s2;
if ( !s1 )
goto LABEL_6;
v3 = strlen(s1);
if ( strlen(s2) < v3 + 2 || strncmp(s1, s2, v3) )
return 0LL;
v2 = &s2[v3];
while ( *v2 == 32 )
{
++v2;
LABEL_6:
;
}
v4 = strlen(v2) + 1;
v5 = malloc(v4);
return memcpy(v5, v2, v4);
}

canonical_decompiled_code:
void *__fastcall func1(char *s2, char *s1)
{
char *v2; // rbp
size_t v3; // rbx
size_t v4; // r12
void *v5; // rax

v2 = s2;
if ( !s1 )
goto LABEL_6;
v3 = strlen(s1);
if ( strlen(s2) < v3 + 2 || strncmp(s1, s2, v3) )
return 0LL;
v2 = &s2[v3];
while ( *v2 == 32 )
{
++v2;
LABEL_6:
;
}
v4 = strlen(v2) + 1;
v5 = malloc(v4);
return memcpy(v5, v2, v4);
}

original_code:
char* setting_get_str(const char* buf, const char* name)
{
    const char* opt;
    char* ret = 0;
    size_t nlen = 0;
    size_t olen;
    if (name)
    {
        nlen = strlen(name);
        if (strlen(buf) < nlen + 2 || strncmp(name, buf, nlen))
            return 0;
    }
    opt = buf + nlen;
    while (*opt == ' ')
        ++opt;
    olen = strlen(opt);
    ret = malloc(olen + 1);
    strcpy(ret, opt);
    return ret;
}

canonical_original_code:
char *setting_get_str(char *buf, char *name)
{
    char *opt;
    char *ret = 0;
    unsigned long nlen = 0;
    unsigned long olen;
    if (name)
    {
        nlen = strlen(name);
        if (strlen(buf) < nlen + 2 || strncmp(name, buf, nlen))
            return 0;
    }
    opt = buf + nlen;
    while (*opt == ' ')
        ++opt;
    olen = strlen(opt);
    ret = malloc(olen + 1);
    strcpy(ret, opt);
    return ret;
}

variable_types:
buf
char *

variable_types:
name
char *

variable_types:
opt
char *

variable_types:
ret
char *

variable_types:
nlen
unsigned long

variable_types:
olen
unsigned long


decompiled_code:
__int64 __fastcall setting_get_index(char *s2, char *s1, const char **a3)
{
unsigned int v4; // er13
size_t v5; // rbp
const char *v6; // rsi
char *v7; // rbp
__int64 v8; // r15
char v9; // r14
const char *v10; // r12
const char *v11; // rdx
const char **v12; // rbx

if ( s1 )
{
v4 = 0;
v5 = strlen(s1);
if ( strlen(s2) < v5 + 2 || strncmp(s1, s2, v5) )
return v4;
}
else
{
v5 = 0LL;
}
v6 = *a3;
if ( *a3 )
{
v7 = &s2[v5];
v8 = 0LL;
v9 = *v7;
while ( 1 )
{
v4 = v8;
v10 = v7;
if ( v9 == 32 )
{
do
++v10;
while ( *v10 == 32 );
}
if ( !strcmp(v10, v6) )
break;
v6 = a3[++v8];
if ( !v6 )
goto LABEL_10;
}
}
else
{
v10 = 0LL;
LABEL_10:
fprintf(stderr, "unknown option:%s for %s\n", v10, s1);
fwrite("available options:", 1uLL, 0x12uLL, stderr);
v11 = *a3;
if ( *a3 )
{
v12 = a3 + 1;
do
{
++v12;
fprintf(stderr, "%s ", v11);
v11 = *(v12 - 1);
}
while ( v11 );
}
v4 = -1;
fputc(10, stderr);
}
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func2(char *s2, char *s1, const char **a3)
{
unsigned int v4; // er13
size_t v5; // rbp
const char *v6; // rsi
char *v7; // rbp
__int64 v8; // r15
char v9; // r14
const char *v10; // r12
const char *v11; // rdx
const char **v12; // rbx

if ( s1 )
{
v4 = 0;
v5 = strlen(s1);
if ( strlen(s2) < v5 + 2 || strncmp(s1, s2, v5) )
return v4;
}
else
{
v5 = 0LL;
}
v6 = *a3;
if ( *a3 )
{
v7 = &s2[v5];
v8 = 0LL;
v9 = *v7;
while ( 1 )
{
v4 = v8;
v10 = v7;
if ( v9 == 32 )
{
do
++v10;
while ( *v10 == 32 );
}
if ( !strcmp(v10, v6) )
break;
v6 = a3[++v8];
if ( !v6 )
goto LABEL_10;
}
}
else
{
v10 = 0LL;
LABEL_10:
fprintf(stderr, "unknown option:%s for %s\n", v10, s1);
fwrite("available options:", 1uLL, 0x12uLL, stderr);
v11 = *a3;
if ( *a3 )
{
v12 = a3 + 1;
do
{
++v12;
fprintf(stderr, "%s ", v11);
v11 = *(v12 - 1);
}
while ( v11 );
}
v4 = -1;
fputc(10, stderr);
}
return v4;
}

original_code:
int setting_get_index( const char* buf, const char* name,
                        const char** options)
{
    size_t nlen = 0;
    int i;
    const char* opt = 0;
    if (name)
    {
        nlen = strlen(name);
        if (strlen(buf) < nlen + 2 || strncmp(name, buf, nlen))
            return 0;
    }
    for (i = 0; options[i] != 0; ++i)
    {
        opt = buf + nlen;
        while (*opt == ' ')
            ++opt;
        if (strcmp(opt, options[i]) == 0)
            return i;
    }
    fprintf(stderr, "unknown option:%s for %s\n", opt, name);
    fprintf(stderr, "available options:");
    for (i = 0; options[i] != 0; ++i)
        fprintf(stderr, "%s ", options[i]);
    fprintf(stderr, "\n");
    return -1;
}

canonical_original_code:
int setting_get_index(char *buf, char *name, char **options)
{
    unsigned long nlen = 0;
    int i;
    char *opt = 0;
    if (name)
    {
        nlen = strlen(name);
        if (strlen(buf) < nlen + 2 || strncmp(name, buf, nlen))
            return 0;
    }
    for (i = 0; options[i] != 0; ++i)
    {
        opt = buf + nlen;
        while (*opt == ' ')
            ++opt;
        if (strcmp(opt, options[i]) == 0)
            return i;
    }
    fprintf(stderr, "unknown option:%s for %s\n", opt, name);
    fprintf(stderr, "available options:");
    for (i = 0; options[i] != 0; ++i)
        fprintf(stderr, "%s ", options[i]);
    fprintf(stderr, "\n");
    return -1;
}

variable_types:
options
char **

variable_types: i int

return_type: int


decompiled_code:
__int64 __fastcall setting_get_long(char *s2, char *s1, __int64 *a3, __int64 a4, __int64 a5)
{
char *v8; // rbp
size_t v9; // rbx
int v10; // ebx
__int64 result; // rax
__int64 v12; // rdx

v8 = s2;
if ( s1 )
{
v9 = strlen(s1);
if ( strlen(s2) < v9 + 1 || strncmp(s1, s2, v9) )
return 0LL;
v8 = &s2[v9];
}
setlocale(1, "C");
v10 = _isoc99_sscanf(v8, "%ld", a3);
setlocale(1, sysloc);
if ( v10 != 1 )
return 0LL;
result = 1LL;
if ( a5 | a4 )
{
v12 = *a3;
LOBYTE(result) = *a3 > a5;
LOBYTE(v12) = *a3 < a4;
result = ((unsigned int)v12 | (unsigned int)result) ^ 1;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(char *s2, char *s1, __int64 *a3, __int64 a4, __int64 a5)
{
char *v8; // rbp
size_t v9; // rbx
int v10; // ebx
__int64 result; // rax
__int64 v12; // rdx

v8 = s2;
if ( s1 )
{
v9 = strlen(s1);
if ( strlen(s2) < v9 + 1 || strncmp(s1, s2, v9) )
return 0LL;
v8 = &s2[v9];
}
setlocale(1, "C");
v10 = _isoc99_sscanf(v8, "%ld", a3);
setlocale(1, sysloc);
if ( v10 != 1 )
return 0LL;
result = 1LL;
if ( a5 | a4 )
{
v12 = *a3;
LOBYTE(result) = *a3 > a5;
LOBYTE(v12) = *a3 < a4;
result = ((unsigned int)v12 | (unsigned int)result) ^ 1;
}
return result;
}

original_code:
_Bool setting_get_long( const char* buf, const char* name,
                        long* val, long min, long max)
{
    size_t nlen = 0;
    int r;
    if (name)
    {
        nlen = strlen(name);
        if (strlen(buf) < nlen + 1 || strncmp(name, buf, nlen))
            return 0;
    }
    setlocale(1, "C");
    r = sscanf(buf + nlen, "%ld", val);
    setlocale(1, sysloc);
    if (r != 1)
     return 0;
    if (!min && !max)
        return 1;
    if (*val < min || *val > max)
        return 0;
    return 1;
}

canonical_original_code:
_Bool setting_get_long(char *buf, char *name, long *val, long min, long max)
{
    unsigned long nlen = 0;
    int r;
    if (name)
    {
        nlen = strlen(name);
        if (strlen(buf) < nlen + 1 || strncmp(name, buf, nlen))
            return 0;
    }
    setlocale(1, "C");
    r = sscanf(buf + nlen, "%ld", val);
    setlocale(1, sysloc);
    if (r != 1)
     return 0;
    if (!min && !max)
        return 1;
    if (*val < min || *val > max)
        return 0;
    return 1;
}

variable_types:
val
long *

variable_types: min long

variable_types: max long

variable_types: r int


decompiled_code:
__int64 __fastcall setting_get_version(__int64 a1, _DWORD *a2, _DWORD *a3, _DWORD *a4)
{
int v6; // ebx
__int64 result; // rax
int v8; // [rsp+4h] [rbp-34h] BYREF
int v9; // [rsp+8h] [rbp-30h] BYREF
int v10; // [rsp+Ch] [rbp-2Ch] BYREF

setlocale(1, "C");
v6 = _isoc99_sscanf(a1, "%d.%d.%d", &v8, &v9, &v10);
setlocale(1, sysloc);
result = 0LL;
if ( v6 == 3 )
{
*a2 = v8;
*a3 = v9;
*a4 = v10;
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, _DWORD *a2, _DWORD *a3, _DWORD *a4)
{
int v6; // ebx
__int64 result; // rax
int v8; // [rsp+4h] [rbp-34h] BYREF
int v9; // [rsp+8h] [rbp-30h] BYREF
int v10; // [rsp+Ch] [rbp-2Ch] BYREF

setlocale(1, "C");
v6 = _isoc99_sscanf(a1, "%d.%d.%d", &v8, &v9, &v10);
setlocale(1, sysloc);
result = 0LL;
if ( v6 == 3 )
{
*a2 = v8;
*a3 = v9;
*a4 = v10;
result = 1LL;
}
return result;
}

original_code:
_Bool setting_get_version(const char* buf, int* major,
                                            int* minor,
                                            int* revision)
{
    int r, maj, min, rev;
    setlocale(1, "C");
    r = sscanf(buf, "%d.%d.%d", &maj, &min, &rev);
    setlocale(1, sysloc);
    if (r == 3)
    {
        *major = maj;
        *minor = min;
        *revision = rev;
        return 1;
    }
    return 0;
}

canonical_original_code:
_Bool setting_get_version(char *buf, int *major, int *minor, int *revision)
{
    int r; int maj; int min; int rev;
    setlocale(1, "C");
    r = sscanf(buf, "%d.%d.%d", &maj, &min, &rev);
    setlocale(1, sysloc);
    if (r == 3)
    {
        *major = maj;
        *minor = min;
        *revision = rev;
        return 1;
    }
    return 0;
}

variable_types:
major
int *

variable_types:
minor
int *

variable_types:
revision
int *

variable_types: maj int

variable_types: min int

variable_types: rev int


decompiled_code:
bool __fastcall setting_get_double(char *s2, char *s1, double *a3, double a4, double a5)
{
char *v6; // rbp
size_t v7; // rbx
int v8; // ebx
bool result; // al

v6 = s2;
if ( s1 )
{
v7 = strlen(s1);
if ( strlen(s2) < v7 + 1 || strncmp(s1, s2, v7) )
return 0;
v6 = &s2[v7];
}
setlocale(1, "C");
v8 = _isoc99_sscanf(v6, "%lf", a3);
setlocale(1, sysloc);
if ( v8 != 1 )
return 0;
result = a5 == 0.0 && a4 == 0.0;
if ( !result )
return a4 <= *a3 && *a3 <= a5;
return result;
}

canonical_decompiled_code:
bool __fastcall func5(char *s2, char *s1, double *a3, double a4, double a5)
{
char *v6; // rbp
size_t v7; // rbx
int v8; // ebx
bool result; // al

v6 = s2;
if ( s1 )
{
v7 = strlen(s1);
if ( strlen(s2) < v7 + 1 || strncmp(s1, s2, v7) )
return 0;
v6 = &s2[v7];
}
setlocale(1, "C");
v8 = _isoc99_sscanf(v6, "%lf", a3);
setlocale(1, sysloc);
if ( v8 != 1 )
return 0;
result = a5 == 0.0 && a4 == 0.0;
if ( !result )
return a4 <= *a3 && *a3 <= a5;
return result;
}

original_code:
_Bool setting_get_double( const char* buf, const char* name,
                            double* val, double min, double max)
{
    size_t nlen = 0;
    int r;
    if (name)
    {
        nlen = strlen(name);
        if (strlen(buf) < nlen + 1 || strncmp(name, buf, nlen))
            return 0;
    }
    setlocale(1, "C");
    r = sscanf(buf + nlen, "%lf", val);
    setlocale(1, sysloc);
    if (r != 1)
        return 0;
    if (!min && !max)
        return 1;
    if (*val < min || *val > max)
        return 0;
    return 1;
}

canonical_original_code:
_Bool setting_get_double(char *buf, char *name, double *val, double min, double max)
{
    unsigned long nlen = 0;
    int r;
    if (name)
    {
        nlen = strlen(name);
        if (strlen(buf) < nlen + 1 || strncmp(name, buf, nlen))
            return 0;
    }
    setlocale(1, "C");
    r = sscanf(buf + nlen, "%lf", val);
    setlocale(1, sysloc);
    if (r != 1)
        return 0;
    if (!min && !max)
        return 1;
    if (*val < min || *val > max)
        return 0;
    return 1;
}

variable_types:
buf
char *

variable_types:
name
char *

variable_types:
val
double *

variable_types: min double

variable_types: max double


decompiled_code:
__int64 __fastcall setting_get_mpfr_t(char *s2, char *s1, __int64 a3)
{
unsigned int v3; // er13
char *v5; // rbp
size_t v6; // rbx
int v7; // ebx

v5 = s2;
if ( !s1 )
goto LABEL_5;
v3 = 0;
v6 = strlen(s1);
if ( strlen(s2) >= v6 + 1 && !strncmp(s1, s2, v6) )
{
v5 = &s2[v6];
LABEL_5:
setlocale(1, "C");
v7 = mpfr_set_str(a3, v5, 10LL, 0LL);
setlocale(1, sysloc);
LOBYTE(v3) = v7 == 0;
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func6(char *s2, char *s1, __int64 a3)
{
unsigned int v3; // er13
char *v5; // rbp
size_t v6; // rbx
int v7; // ebx

v5 = s2;
if ( !s1 )
goto LABEL_5;
v3 = 0;
v6 = strlen(s1);
if ( strlen(s2) >= v6 + 1 && !strncmp(s1, s2, v6) )
{
v5 = &s2[v6];
LABEL_5:
setlocale(1, "C");
v7 = mpfr_set_str(a3, v5, 10LL, 0LL);
setlocale(1, sysloc);
LOBYTE(v3) = v7 == 0;
}
return v3;
}

original_code:
_Bool setting_get_mpfr_t(const char* buf, const char* name, mpfr_t val)
{
    size_t nlen = 0;
    int r;
    if (name)
    {
        nlen = strlen(name);
        if (strlen(buf) < nlen + 1 || strncmp(name, buf, nlen))
            return 0;
    }
    setlocale(1, "C");
    r = mpfr_set_str(val, buf + nlen, 10, MPFR_RNDN);
    setlocale(1, sysloc);
    if (r)
        return 0;
    return 1;
}

canonical_original_code:
_Bool setting_get_mpfr_t(char *buf, char *name, struct __mpfr_struct val[1])
{
    unsigned long nlen = 0;
    int r;
    if (name)
    {
        nlen = strlen(name);
        if (strlen(buf) < nlen + 1 || strncmp(name, buf, nlen))
            return 0;
    }
    setlocale(1, "C");
    r = mpfr_set_str(val, buf + nlen, 10, MPFR_RNDN);
    setlocale(1, sysloc);
    if (r)
        return 0;
    return 1;
}

variable_types: struct __mpfr_struct { long _mpfr_prec; int _mpfr_sign; long _mpfr_exp; unsigned long *_mpfr_d; } [1]

variable_types:
nlen
unsigned long


decompiled_code:
__int64 __fastcall frac_generalized_celtic(__int64 a1, long double a2, long double a3, long double a4, long double a5, long double a6, long double a7)
{
__int64 result; // rax
long double v18; // fst2
long double v19; // rt2
long double v20; // fst2
long double v21; // rtt
long double v22; // rt0
long double v23; // fst3
long double v24; // fst6
long double v25; // fst7
long double v26; // fst4

if ( a1 <= 0 )
return 0LL;
result = 1LL;
while ( 1 )
{
v22 = a6;
v23 = a7;
v24 = a2 * (a3 + a3) + a4;
v25 = a5;
v26 = fabs(v23 - v22) + a5;
a6 = v24 * v24;
if ( v24 * v24 + v26 * v26 > 4.0 )
break;
if ( a1 < ++result )
return 0LL;
v18 = v24;
a7 = v26 * v26;
v19 = v18;
v20 = v25;
a2 = v19;
v21 = v20;
a3 = v26;
a5 = v21;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, long double a2, long double a3, long double a4, long double a5, long double a6, long double a7)
{
__int64 result; // rax
long double v18; // fst2
long double v19; // rt2
long double v20; // fst2
long double v21; // rtt
long double v22; // rt0
long double v23; // fst3
long double v24; // fst6
long double v25; // fst7
long double v26; // fst4

if ( a1 <= 0 )
return 0LL;
result = 1LL;
while ( 1 )
{
v22 = a6;
v23 = a7;
v24 = a2 * (a3 + a3) + a4;
v25 = a5;
v26 = fabs(v23 - v22) + a5;
a6 = v24 * v24;
if ( v24 * v24 + v26 * v26 > 4.0 )
break;
if ( a1 < ++result )
return 0LL;
v18 = v24;
a7 = v26 * v26;
v19 = v18;
v20 = v25;
a2 = v19;
v21 = v20;
a3 = v26;
a5 = v21;
}
return result;
}

original_code:
depth_t frac_generalized_celtic(depth_t depth,
                                long double wim, long double wre,
                                long double c_im, long double c_re,
                                long double wim2, long double wre2 )
{
    depth_t wz;
    for (wz = 1; wz <= depth; ++wz)
    {
        wim = 2.0 * wre * wim + c_im;
        wre = fabsl(wre2 - wim2) + c_re;
        wim2 = wim * wim;
        wre2 = wre * wre;
        if (wim2 + wre2 > 4.0F)
            return wz;
    }
    return 0;
}

canonical_original_code:
long frac_generalized_celtic(long depth, long double wim, long double wre, long double c_im, long double c_re, long double wim2, long double wre2)
{
    long wz;
    for (wz = 1; wz <= depth; ++wz)
    {
        wim = 2.0 * wre * wim + c_im;
        wre = fabsl(wre2 - wim2) + c_re;
        wim2 = wim * wim;
        wre2 = wre * wre;
        if (wim2 + wre2 > 4.0F)
            return wz;
    }
    return 0;
}

variable_types: depth long

variable_types:
wim
long double

variable_types:
wre
long double

variable_types: wz long

return_type: long


decompiled_code:
__int64 __fastcall frac_generalized_celtic_mpfr(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, __int64 a7, __int64 a8, __int64 a9)
{
__int64 v11; // r12

if ( a1 <= 0 )
return 0LL;
v11 = 1LL;
while ( 1 )
{
mpfr_mul(a9, a4, a3, 0LL);
mpfr_mul_2si(a9, a9, 1LL, 0LL);
mpfr_add(a3, a9, a5, 0LL);
mpfr_sub(a9, a8, a7, 0LL);
mpfr_set4(a9, a9, 0LL, 1LL);
mpfr_add(a4, a9, a6, 0LL);
mpfr_mul(a7, a3, a3, 0LL);
mpfr_mul(a8, a4, a4, 0LL);
mpfr_add(a9, a7, a8, 0LL);
if ( (unsigned int)mpfr_greater_p(a9, a2) )
break;
if ( a1 < ++v11 )
return 0LL;
}
return v11;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, __int64 a7, __int64 a8, __int64 a9)
{
__int64 v11; // r12

if ( a1 <= 0 )
return 0LL;
v11 = 1LL;
while ( 1 )
{
mpfr_mul(a9, a4, a3, 0LL);
mpfr_mul_2si(a9, a9, 1LL, 0LL);
mpfr_add(a3, a9, a5, 0LL);
mpfr_sub(a9, a8, a7, 0LL);
mpfr_set4(a9, a9, 0LL, 1LL);
mpfr_add(a4, a9, a6, 0LL);
mpfr_mul(a7, a3, a3, 0LL);
mpfr_mul(a8, a4, a4, 0LL);
mpfr_add(a9, a7, a8, 0LL);
if ( (unsigned int)mpfr_greater_p(a9, a2) )
break;
if ( a1 < ++v11 )
return 0LL;
}
return v11;
}

original_code:
depth_t frac_generalized_celtic_mpfr(
                                depth_t depth,
                                mpfr_t bail,
                                mpfr_t wim, mpfr_t wre,
                                mpfr_t c_im, mpfr_t c_re,
                                mpfr_t wim2, mpfr_t wre2, mpfr_t t1)
{
    depth_t wz;
    for (wz = 1; wz <= depth; wz++)
    {
        mpfr_mul( t1, wre, wim, MPFR_RNDN);
        (__builtin_constant_p (2) && (mpfr_long) (2) >= 0 ? (__builtin_constant_p ((mpfr_ulong) (mpfr_long) (2)) && (mpfr_ulong) ((mpfr_ulong) (mpfr_long) (2)) >= 1 && ((mpfr_ulong) ((mpfr_ulong) (mpfr_long) (2)) & ((mpfr_ulong) ((mpfr_ulong) (mpfr_long) (2)) - 1)) == 0 ? mpfr_mul_2si(((t1)), ((t1)), __builtin_ctzl ((mpfr_ulong) (mpfr_long) (2)), ((MPFR_RNDN))) : mpfr_mul_ui (((t1)), ((t1)), ((mpfr_ulong) (mpfr_long) (2)), ((MPFR_RNDN)))) : mpfr_mul_si ((t1), (t1), (2), (MPFR_RNDN)));
        mpfr_add( wim, t1, c_im, MPFR_RNDN);
        mpfr_sub( t1, wre2, wim2, MPFR_RNDN);
        mpfr_set4(t1,t1,MPFR_RNDN,1);
        mpfr_add( wre, t1, c_re, MPFR_RNDN);
        mpfr_mul( wim2, wim, wim, MPFR_RNDN);
        mpfr_mul( wre2, wre, wre, MPFR_RNDN);
        mpfr_add( t1, wim2, wre2, MPFR_RNDN);
        if (mpfr_greater_p(t1, bail))
            return wz;
    }
    return 0;
}

canonical_original_code:
long frac_generalized_celtic_mpfr(long depth, struct __mpfr_struct bail[1], struct __mpfr_struct wim[1], struct __mpfr_struct wre[1], struct __mpfr_struct c_im[1], struct __mpfr_struct c_re[1], struct __mpfr_struct wim2[1], struct __mpfr_struct wre2[1], struct __mpfr_struct t1[1])
{
    long wz;
    for (wz = 1; wz <= depth; wz++)
    {
        mpfr_mul( t1, wre, wim, MPFR_RNDN);
        (__builtin_constant_p (2) && (mpfr_long) (2) >= 0 ? (__builtin_constant_p ((mpfr_ulong) (mpfr_long) (2)) && (mpfr_ulong) ((mpfr_ulong) (mpfr_long) (2)) >= 1 && ((mpfr_ulong) ((mpfr_ulong) (mpfr_long) (2)) & ((mpfr_ulong) ((mpfr_ulong) (mpfr_long) (2)) - 1)) == 0 ? mpfr_mul_2si(((t1)), ((t1)), __builtin_ctzl ((mpfr_ulong) (mpfr_long) (2)), ((MPFR_RNDN))) : mpfr_mul_ui (((t1)), ((t1)), ((mpfr_ulong) (mpfr_long) (2)), ((MPFR_RNDN)))) : mpfr_mul_si ((t1), (t1), (2), (MPFR_RNDN)));
        mpfr_add( wim, t1, c_im, MPFR_RNDN);
        mpfr_sub( t1, wre2, wim2, MPFR_RNDN);
        mpfr_set4(t1,t1,MPFR_RNDN,1);
        mpfr_add( wre, t1, c_re, MPFR_RNDN);
        mpfr_mul( wim2, wim, wim, MPFR_RNDN);
        mpfr_mul( wre2, wre, wre, MPFR_RNDN);
        mpfr_add( t1, wim2, wre2, MPFR_RNDN);
        if (mpfr_greater_p(t1, bail))
            return wz;
    }
    return 0;
}

variable_types:
wim
struct __mpfr_struct [1]

variable_types:
wre
struct __mpfr_struct [1]

user_defined_types: struct __mpfr_struct { long _mpfr_prec; int _mpfr_sign; long _mpfr_exp; unsigned long *_mpfr_d; }


decompiled_code:
__int64 __fastcall frac_generalized_celtic_gmp(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, __int64 a7, __int64 a8, __int64 a9)
{
__int64 v11; // r12

if ( a1 <= 0 )
return 0LL;
v11 = 1LL;
while ( 1 )
{
_gmpf_mul(a9, a4, a3);
_gmpf_mul_ui(a9, a9, 2LL);
_gmpf_add(a3, a9, a5);
_gmpf_sub(a9, a8, a7);
_gmpf_abs(a9, a9);
_gmpf_add(a4, a9, a6);
_gmpf_mul(a7, a3, a3);
_gmpf_mul(a8, a4, a4);
_gmpf_add(a9, a7, a8);
if ( (int)_gmpf_cmp(a9, a2) > 0 )
break;
if ( a1 < ++v11 )
return 0LL;
}
return v11;
}

original_code:
depth_t frac_generalized_celtic_gmp(
                                depth_t depth,
                                mpf_t bail,
                                mpf_t wim, mpf_t wre,
                                mpf_t c_im, mpf_t c_re,
                                mpf_t wim2, mpf_t wre2, mpf_t t1)
{
    depth_t wz;
    for (wz = 1; wz <= depth; wz++)
        {
        __gmpf_mul( t1, wre, wim);
        __gmpf_mul_ui(t1, t1, 2);
        __gmpf_add( wim, t1, c_im);
        __gmpf_sub( t1, wre2, wim2);
        __gmpf_abs( t1, t1);
        __gmpf_add( wre, t1, c_re);
        __gmpf_mul( wim2, wim, wim);
        __gmpf_mul( wre2, wre, wre);
        __gmpf_add( t1, wim2, wre2);
        if (__gmpf_cmp(t1, bail) > 0)
            return wz;
    }
    return 0;
}

canonical_original_code:
long frac_generalized_celtic_gmp(long depth, struct __mpf_struct bail[1], struct __mpf_struct wim[1], struct __mpf_struct wre[1], struct __mpf_struct c_im[1], struct __mpf_struct c_re[1], struct __mpf_struct wim2[1], struct __mpf_struct wre2[1], struct __mpf_struct t1[1])
{
    long wz;
    for (wz = 1; wz <= depth; wz++)
        {
        __gmpf_mul( t1, wre, wim);
        __gmpf_mul_ui(t1, t1, 2);
        __gmpf_add( wim, t1, c_im);
        __gmpf_sub( t1, wre2, wim2);
        __gmpf_abs( t1, t1);
        __gmpf_add( wre, t1, c_re);
        __gmpf_mul( wim2, wim, wim);
        __gmpf_mul( wre2, wre, wre);
        __gmpf_add( t1, wim2, wre2);
        if (__gmpf_cmp(t1, bail) > 0)
            return wz;
    }
    return 0;
}

variable_types: struct __mpf_struct { int _mp_prec; int _mp_size; long _mp_exp; unsigned long *_mp_d; } [1]

variable_types:
wim
struct __mpf_struct [1]

variable_types:
wre
struct __mpf_struct [1]


decompiled_code:
__int64 __fastcall frac_burning_ship(__int64 a1, long double a2, long double a3, long double a4, long double a5, long double a6, long double a7)
{
__int64 result; // rax
long double v17; // fst2
long double v18; // rt2
long double v19; // rtt
long double v20; // fst3
long double v21; // rt0
long double v22; // fst3
long double v23; // fst6
long double v24; // fst7

if ( a1 <= 0 )
return 0LL;
result = 1LL;
while ( 1 )
{
v19 = a6;
v20 = fabs(a2 * a3);
v21 = v20 + v20 + a4;
v22 = a7;
v23 = v21;
v24 = v22 - v19 + a5;
a6 = v21 * v21;
if ( v21 * v21 + v24 * v24 > 4.0 )
break;
if ( a1 < ++result )
return 0LL;
v17 = v23;
a7 = v24 * v24;
v18 = v17;
a3 = v24;
a2 = v18;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, long double a2, long double a3, long double a4, long double a5, long double a6, long double a7)
{
__int64 result; // rax
long double v17; // fst2
long double v18; // rt2
long double v19; // rtt
long double v20; // fst3
long double v21; // rt0
long double v22; // fst3
long double v23; // fst6
long double v24; // fst7

if ( a1 <= 0 )
return 0LL;
result = 1LL;
while ( 1 )
{
v19 = a6;
v20 = fabs(a2 * a3);
v21 = v20 + v20 + a4;
v22 = a7;
v23 = v21;
v24 = v22 - v19 + a5;
a6 = v21 * v21;
if ( v21 * v21 + v24 * v24 > 4.0 )
break;
if ( a1 < ++result )
return 0LL;
v17 = v23;
a7 = v24 * v24;
v18 = v17;
a3 = v24;
a2 = v18;
}
return result;
}

original_code:
depth_t frac_burning_ship( depth_t depth,
                                long double wim, long double wre,
                                long double c_im, long double c_re,
                                long double wim2, long double wre2 )
{
    depth_t wz;
    for (wz = 1; wz <= depth; ++wz)
    {
        wim = 2.0 * fabsl(wre * wim) + c_im;
        wre = wre2 - wim2 + c_re;
        wim2 = wim * wim;
        wre2 = wre * wre;
        if (wim2 + wre2 > 4.0F)
            return wz;
    }
    return 0;
}

canonical_original_code:
long frac_burning_ship(long depth, long double wim, long double wre, long double c_im, long double c_re, long double wim2, long double wre2)
{
    long wz;
    for (wz = 1; wz <= depth; ++wz)
    {
        wim = 2.0 * fabsl(wre * wim) + c_im;
        wre = wre2 - wim2 + c_re;
        wim2 = wim * wim;
        wre2 = wre * wre;
        if (wim2 + wre2 > 4.0F)
            return wz;
    }
    return 0;
}


decompiled_code:
__int64 __fastcall frac_burning_ship_mpfr(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, __int64 a7, __int64 a8, __int64 a9)
{
__int64 v11; // r12

if ( a1 <= 0 )
return 0LL;
v11 = 1LL;
while ( 1 )
{
mpfr_mul(a9, a4, a3, 0LL);
mpfr_set4(a9, a9, 0LL, 1LL);
mpfr_mul_2si(a9, a9, 1LL, 0LL);
mpfr_add(a3, a9, a5, 0LL);
mpfr_sub(a9, a8, a7, 0LL);
mpfr_add(a4, a9, a6, 0LL);
mpfr_mul(a7, a3, a3, 0LL);
mpfr_mul(a8, a4, a4, 0LL);
mpfr_add(a9, a7, a8, 0LL);
if ( (unsigned int)mpfr_greater_p(a9, a2) )
break;
if ( a1 < ++v11 )
return 0LL;
}
return v11;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, __int64 a7, __int64 a8, __int64 a9)
{
__int64 v11; // r12

if ( a1 <= 0 )
return 0LL;
v11 = 1LL;
while ( 1 )
{
mpfr_mul(a9, a4, a3, 0LL);
mpfr_set4(a9, a9, 0LL, 1LL);
mpfr_mul_2si(a9, a9, 1LL, 0LL);
mpfr_add(a3, a9, a5, 0LL);
mpfr_sub(a9, a8, a7, 0LL);
mpfr_add(a4, a9, a6, 0LL);
mpfr_mul(a7, a3, a3, 0LL);
mpfr_mul(a8, a4, a4, 0LL);
mpfr_add(a9, a7, a8, 0LL);
if ( (unsigned int)mpfr_greater_p(a9, a2) )
break;
if ( a1 < ++v11 )
return 0LL;
}
return v11;
}

original_code:
depth_t frac_burning_ship_mpfr(
                                depth_t depth,
                                mpfr_t bail,
                                mpfr_t wim, mpfr_t wre,
                                mpfr_t c_im, mpfr_t c_re,
                                mpfr_t wim2, mpfr_t wre2, mpfr_t t1)
{
    depth_t wz;
    for (wz = 1; wz <= depth; wz++)
    {
        mpfr_mul( t1, wre, wim, MPFR_RNDN);
        mpfr_set4(t1,t1,MPFR_RNDN,1);
        (__builtin_constant_p (2) && (mpfr_long) (2) >= 0 ? (__builtin_constant_p ((mpfr_ulong) (mpfr_long) (2)) && (mpfr_ulong) ((mpfr_ulong) (mpfr_long) (2)) >= 1 && ((mpfr_ulong) ((mpfr_ulong) (mpfr_long) (2)) & ((mpfr_ulong) ((mpfr_ulong) (mpfr_long) (2)) - 1)) == 0 ? mpfr_mul_2si(((t1)), ((t1)), __builtin_ctzl ((mpfr_ulong) (mpfr_long) (2)), ((MPFR_RNDN))) : mpfr_mul_ui (((t1)), ((t1)), ((mpfr_ulong) (mpfr_long) (2)), ((MPFR_RNDN)))) : mpfr_mul_si ((t1), (t1), (2), (MPFR_RNDN)));
        mpfr_add( wim, t1, c_im, MPFR_RNDN);
        mpfr_sub( t1, wre2, wim2, MPFR_RNDN);
        mpfr_add( wre, t1, c_re, MPFR_RNDN);
        mpfr_mul( wim2, wim, wim, MPFR_RNDN);
        mpfr_mul( wre2, wre, wre, MPFR_RNDN);
        mpfr_add( t1, wim2, wre2, MPFR_RNDN);
        if (mpfr_greater_p(t1, bail))
            return wz;
    }
    return 0;
}

canonical_original_code:
long frac_burning_ship_mpfr(long depth, struct __mpfr_struct bail[1], struct __mpfr_struct wim[1], struct __mpfr_struct wre[1], struct __mpfr_struct c_im[1], struct __mpfr_struct c_re[1], struct __mpfr_struct wim2[1], struct __mpfr_struct wre2[1], struct __mpfr_struct t1[1])
{
    long wz;
    for (wz = 1; wz <= depth; wz++)
    {
        mpfr_mul( t1, wre, wim, MPFR_RNDN);
        mpfr_set4(t1,t1,MPFR_RNDN,1);
        (__builtin_constant_p (2) && (mpfr_long) (2) >= 0 ? (__builtin_constant_p ((mpfr_ulong) (mpfr_long) (2)) && (mpfr_ulong) ((mpfr_ulong) (mpfr_long) (2)) >= 1 && ((mpfr_ulong) ((mpfr_ulong) (mpfr_long) (2)) & ((mpfr_ulong) ((mpfr_ulong) (mpfr_long) (2)) - 1)) == 0 ? mpfr_mul_2si(((t1)), ((t1)), __builtin_ctzl ((mpfr_ulong) (mpfr_long) (2)), ((MPFR_RNDN))) : mpfr_mul_ui (((t1)), ((t1)), ((mpfr_ulong) (mpfr_long) (2)), ((MPFR_RNDN)))) : mpfr_mul_si ((t1), (t1), (2), (MPFR_RNDN)));
        mpfr_add( wim, t1, c_im, MPFR_RNDN);
        mpfr_sub( t1, wre2, wim2, MPFR_RNDN);
        mpfr_add( wre, t1, c_re, MPFR_RNDN);
        mpfr_mul( wim2, wim, wim, MPFR_RNDN);
        mpfr_mul( wre2, wre, wre, MPFR_RNDN);
        mpfr_add( t1, wim2, wre2, MPFR_RNDN);
        if (mpfr_greater_p(t1, bail))
            return wz;
    }
    return 0;
}


decompiled_code:
__int64 __fastcall frac_burning_ship_gmp(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, __int64 a7, __int64 a8, __int64 a9)
{
__int64 v11; // r12

if ( a1 <= 0 )
return 0LL;
v11 = 1LL;
while ( 1 )
{
_gmpf_mul(a9, a4, a3);
_gmpf_abs(a9, a9);
_gmpf_mul_ui(a9, a9, 2LL);
_gmpf_add(a3, a9, a5);
_gmpf_sub(a9, a8, a7);
_gmpf_add(a4, a9, a6);
_gmpf_mul(a7, a3, a3);
_gmpf_mul(a8, a4, a4);
_gmpf_add(a9, a7, a8);
if ( (int)_gmpf_cmp(a9, a2) > 0 )
break;
if ( a1 < ++v11 )
return 0LL;
}
return v11;
}

original_code:
depth_t frac_burning_ship_gmp(
                                depth_t depth,
                                mpf_t bail,
                                mpf_t wim, mpf_t wre,
                                mpf_t c_im, mpf_t c_re,
                                mpf_t wim2, mpf_t wre2, mpf_t t1)
{
    depth_t wz;
    for (wz = 1; wz <= depth; wz++)
        {
        __gmpf_mul( t1, wre, wim);
        __gmpf_abs( t1, t1);
        __gmpf_mul_ui(t1, t1, 2);
        __gmpf_add( wim, t1, c_im);
        __gmpf_sub( t1, wre2, wim2);
        __gmpf_add( wre, t1, c_re);
        __gmpf_mul( wim2, wim, wim);
        __gmpf_mul( wre2, wre, wre);
        __gmpf_add( t1, wim2, wre2);
        if (__gmpf_cmp(t1, bail) > 0)
            return wz;
    }
    return 0;
}

canonical_original_code:
long frac_burning_ship_gmp(long depth, struct __mpf_struct bail[1], struct __mpf_struct wim[1], struct __mpf_struct wre[1], struct __mpf_struct c_im[1], struct __mpf_struct c_re[1], struct __mpf_struct wim2[1], struct __mpf_struct wre2[1], struct __mpf_struct t1[1])
{
    long wz;
    for (wz = 1; wz <= depth; wz++)
        {
        __gmpf_mul( t1, wre, wim);
        __gmpf_abs( t1, t1);
        __gmpf_mul_ui(t1, t1, 2);
        __gmpf_add( wim, t1, c_im);
        __gmpf_sub( t1, wre2, wim2);
        __gmpf_add( wre, t1, c_re);
        __gmpf_mul( wim2, wim, wim);
        __gmpf_mul( wre2, wre, wre);
        __gmpf_add( t1, wim2, wre2);
        if (__gmpf_cmp(t1, bail) > 0)
            return wz;
    }
    return 0;
}

user_defined_types: struct __mpf_struct { int _mp_prec; int _mp_size; long _mp_exp; unsigned long *_mp_d; }


decompiled_code:
__int64 start_reposition()
{
stat = (int (*)(const char *, struct stat *))&loc_4;
gui_sensitive_switch_menu(0LL);
zoom_gui_sensitive_zoom_in_button(0LL);
zoom_gui_sensitive_zoom_out_button(0LL);
return zoom_gui_sensitive_zoom_in_1click_button(0LL);
}

canonical_decompiled_code:
__int64 func0()
{
stat = (int (*)(const char *, struct stat *))&loc_4;
gui_sensitive_switch_menu(0LL);
zoom_gui_sensitive_zoom_in_button(0LL);
zoom_gui_sensitive_zoom_out_button(0LL);
return zoom_gui_sensitive_zoom_in_1click_button(0LL);
}

original_code:
void start_reposition(void)
{
    stat.action = STAT_REPOSITIONING;
    stat.reposition_p2 = (0);
    gui_sensitive_switch_menu((0));
    zoom_gui_sensitive_zoom_in_button((0));
    zoom_gui_sensitive_zoom_out_button((0));
    zoom_gui_sensitive_zoom_in_1click_button((0));
}

canonical_original_code:
void start_reposition()
{
    stat.action = STAT_REPOSITIONING;
    stat.reposition_p2 = (0);
    gui_sensitive_switch_menu((0));
    zoom_gui_sensitive_zoom_in_button((0));
    zoom_gui_sensitive_zoom_out_button((0));
    zoom_gui_sensitive_zoom_in_1click_button((0));
}


decompiled_code:
__int64 __fastcall repos_gui_sensitive_reposition_button(unsigned int a1)
{
return gtk_widget_set_sensitive(reposition_button, a1);
}

canonical_decompiled_code:
__int64 __fastcall func4(unsigned int a1)
{
return gtk_widget_set_sensitive(reposition_button, a1);
}

original_code:
void repos_gui_sensitive_reposition_button(gboolean t)
    { gtk_widget_set_sensitive(reposition_button, t); }

canonical_original_code:
void repos_gui_sensitive_reposition_button(int t)
    { gtk_widget_set_sensitive(reposition_button, t); }

variable_types: t int


decompiled_code:
__int64 __fastcall frac_mandel(__int64 a1, long double a2, long double a3, long double a4, long double a5, long double a6, long double a7)
{
__int64 result; // rax
long double v17; // fst2
long double v18; // rt2
long double v19; // rtt
long double v20; // fst3
long double v21; // fst6
long double v22; // fst7

if ( a1 <= 0 )
return 0LL;
result = 1LL;
while ( 1 )
{
v19 = a6;
v20 = a7;
v21 = a2 * (a3 + a3) + a4;
v22 = v20 - v19 + a5;
a6 = v21 * v21;
if ( v21 * v21 + v22 * v22 > 4.0 )
break;
if ( a1 < ++result )
return 0LL;
v17 = v21;
a7 = v22 * v22;
v18 = v17;
a3 = v22;
a2 = v18;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, long double a2, long double a3, long double a4, long double a5, long double a6, long double a7)
{
__int64 result; // rax
long double v17; // fst2
long double v18; // rt2
long double v19; // rtt
long double v20; // fst3
long double v21; // fst6
long double v22; // fst7

if ( a1 <= 0 )
return 0LL;
result = 1LL;
while ( 1 )
{
v19 = a6;
v20 = a7;
v21 = a2 * (a3 + a3) + a4;
v22 = v20 - v19 + a5;
a6 = v21 * v21;
if ( v21 * v21 + v22 * v22 > 4.0 )
break;
if ( a1 < ++result )
return 0LL;
v17 = v21;
a7 = v22 * v22;
v18 = v17;
a3 = v22;
a2 = v18;
}
return result;
}

original_code:
depth_t frac_mandel( depth_t depth,
                                long double wim, long double wre,
                                long double c_im, long double c_re,
                                long double wim2, long double wre2 )
{
    depth_t wz;
    for (wz = 1; wz <= depth; ++wz)
    {
        wim = 2.0 * wre * wim + c_im;
        wre = wre2 - wim2 + c_re;
        wim2 = wim * wim;
        wre2 = wre * wre;
        if (wim2 + wre2 > 4.0F)
            return wz;
    }
    return 0;
}

canonical_original_code:
long frac_mandel(long depth, long double wim, long double wre, long double c_im, long double c_re, long double wim2, long double wre2)
{
    long wz;
    for (wz = 1; wz <= depth; ++wz)
    {
        wim = 2.0 * wre * wim + c_im;
        wre = wre2 - wim2 + c_re;
        wim2 = wim * wim;
        wre2 = wre * wre;
        if (wim2 + wre2 > 4.0F)
            return wz;
    }
    return 0;
}


decompiled_code:
__int64 __fastcall frac_mandel_mpfr(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, __int64 a7, __int64 a8, __int64 a9)
{
__int64 v11; // r13

if ( a1 <= 0 )
return 0LL;
v11 = 1LL;
while ( 1 )
{
mpfr_mul(a9, a4, a3, 0LL);
mpfr_mul_2si(a9, a9, 1LL, 0LL);
mpfr_add(a3, a9, a5, 0LL);
mpfr_sub(a9, a8, a7, 0LL);
mpfr_add(a4, a9, a6, 0LL);
mpfr_mul(a7, a3, a3, 0LL);
mpfr_mul(a8, a4, a4, 0LL);
mpfr_add(a9, a7, a8, 0LL);
if ( (unsigned int)mpfr_greater_p(a9, a2) )
break;
if ( a1 < ++v11 )
return 0LL;
}
return v11;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, __int64 a7, __int64 a8, __int64 a9)
{
__int64 v11; // r13

if ( a1 <= 0 )
return 0LL;
v11 = 1LL;
while ( 1 )
{
mpfr_mul(a9, a4, a3, 0LL);
mpfr_mul_2si(a9, a9, 1LL, 0LL);
mpfr_add(a3, a9, a5, 0LL);
mpfr_sub(a9, a8, a7, 0LL);
mpfr_add(a4, a9, a6, 0LL);
mpfr_mul(a7, a3, a3, 0LL);
mpfr_mul(a8, a4, a4, 0LL);
mpfr_add(a9, a7, a8, 0LL);
if ( (unsigned int)mpfr_greater_p(a9, a2) )
break;
if ( a1 < ++v11 )
return 0LL;
}
return v11;
}

original_code:
depth_t frac_mandel_mpfr(
                                depth_t depth,
                                mpfr_t bail,
                                mpfr_t wim, mpfr_t wre,
                                mpfr_t c_im, mpfr_t c_re,
                                mpfr_t wim2, mpfr_t wre2, mpfr_t t1)
{
    depth_t wz;
    for (wz = 1; wz <= depth; wz++)
    {
        mpfr_mul( t1, wre, wim, MPFR_RNDN);
        (__builtin_constant_p (2) && (mpfr_long) (2) >= 0 ? (__builtin_constant_p ((mpfr_ulong) (mpfr_long) (2)) && (mpfr_ulong) ((mpfr_ulong) (mpfr_long) (2)) >= 1 && ((mpfr_ulong) ((mpfr_ulong) (mpfr_long) (2)) & ((mpfr_ulong) ((mpfr_ulong) (mpfr_long) (2)) - 1)) == 0 ? mpfr_mul_2si(((t1)), ((t1)), __builtin_ctzl ((mpfr_ulong) (mpfr_long) (2)), ((MPFR_RNDN))) : mpfr_mul_ui (((t1)), ((t1)), ((mpfr_ulong) (mpfr_long) (2)), ((MPFR_RNDN)))) : mpfr_mul_si ((t1), (t1), (2), (MPFR_RNDN)));
        mpfr_add( wim, t1, c_im, MPFR_RNDN);
        mpfr_sub( t1, wre2, wim2, MPFR_RNDN);
        mpfr_add( wre, t1, c_re, MPFR_RNDN);
        mpfr_mul( wim2, wim, wim, MPFR_RNDN);
        mpfr_mul( wre2, wre, wre, MPFR_RNDN);
        mpfr_add( t1, wim2, wre2, MPFR_RNDN);
        if (mpfr_greater_p(t1, bail))
            return wz;
    }
    return 0;
}

canonical_original_code:
long frac_mandel_mpfr(long depth, struct __mpfr_struct bail[1], struct __mpfr_struct wim[1], struct __mpfr_struct wre[1], struct __mpfr_struct c_im[1], struct __mpfr_struct c_re[1], struct __mpfr_struct wim2[1], struct __mpfr_struct wre2[1], struct __mpfr_struct t1[1])
{
    long wz;
    for (wz = 1; wz <= depth; wz++)
    {
        mpfr_mul( t1, wre, wim, MPFR_RNDN);
        (__builtin_constant_p (2) && (mpfr_long) (2) >= 0 ? (__builtin_constant_p ((mpfr_ulong) (mpfr_long) (2)) && (mpfr_ulong) ((mpfr_ulong) (mpfr_long) (2)) >= 1 && ((mpfr_ulong) ((mpfr_ulong) (mpfr_long) (2)) & ((mpfr_ulong) ((mpfr_ulong) (mpfr_long) (2)) - 1)) == 0 ? mpfr_mul_2si(((t1)), ((t1)), __builtin_ctzl ((mpfr_ulong) (mpfr_long) (2)), ((MPFR_RNDN))) : mpfr_mul_ui (((t1)), ((t1)), ((mpfr_ulong) (mpfr_long) (2)), ((MPFR_RNDN)))) : mpfr_mul_si ((t1), (t1), (2), (MPFR_RNDN)));
        mpfr_add( wim, t1, c_im, MPFR_RNDN);
        mpfr_sub( t1, wre2, wim2, MPFR_RNDN);
        mpfr_add( wre, t1, c_re, MPFR_RNDN);
        mpfr_mul( wim2, wim, wim, MPFR_RNDN);
        mpfr_mul( wre2, wre, wre, MPFR_RNDN);
        mpfr_add( t1, wim2, wre2, MPFR_RNDN);
        if (mpfr_greater_p(t1, bail))
            return wz;
    }
    return 0;
}


decompiled_code:
__int64 __fastcall frac_mandel_gmp(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, __int64 a7, __int64 a8, __int64 a9)
{
__int64 v11; // r13

if ( a1 <= 0 )
return 0LL;
v11 = 1LL;
while ( 1 )
{
_gmpf_mul(a9, a4, a3);
_gmpf_mul_ui(a9, a9, 2LL);
_gmpf_add(a3, a9, a5);
_gmpf_sub(a9, a8, a7);
_gmpf_add(a4, a9, a6);
_gmpf_mul(a7, a3, a3);
_gmpf_mul(a8, a4, a4);
_gmpf_add(a9, a7, a8);
if ( (int)_gmpf_cmp(a9, a2) > 0 )
break;
if ( a1 < ++v11 )
return 0LL;
}
return v11;
}

original_code:
depth_t frac_mandel_gmp(
                                depth_t depth,
                                mpf_t bail,
                                mpf_t wim, mpf_t wre,
                                mpf_t c_im, mpf_t c_re,
                                mpf_t wim2, mpf_t wre2, mpf_t t1)
{
    depth_t wz;
    for (wz = 1; wz <= depth; wz++)
        {
        __gmpf_mul( t1, wre, wim);
        __gmpf_mul_ui(t1, t1, 2);
        __gmpf_add( wim, t1, c_im);
        __gmpf_sub( t1, wre2, wim2);
        __gmpf_add( wre, t1, c_re);
        __gmpf_mul( wim2, wim, wim);
        __gmpf_mul( wre2, wre, wre);
        __gmpf_add( t1, wim2, wre2);
        if (__gmpf_cmp(t1, bail) > 0)
            return wz;
    }
    return 0;
}

canonical_original_code:
long frac_mandel_gmp(long depth, struct __mpf_struct bail[1], struct __mpf_struct wim[1], struct __mpf_struct wre[1], struct __mpf_struct c_im[1], struct __mpf_struct c_re[1], struct __mpf_struct wim2[1], struct __mpf_struct wre2[1], struct __mpf_struct t1[1])
{
    long wz;
    for (wz = 1; wz <= depth; wz++)
        {
        __gmpf_mul( t1, wre, wim);
        __gmpf_mul_ui(t1, t1, 2);
        __gmpf_add( wim, t1, c_im);
        __gmpf_sub( t1, wre2, wim2);
        __gmpf_add( wre, t1, c_re);
        __gmpf_mul( wim2, wim, wim);
        __gmpf_mul( wre2, wre, wre);
        __gmpf_add( t1, wim2, wre2);
        if (__gmpf_cmp(t1, bail) > 0)
            return wz;
    }
    return 0;
}


decompiled_code:
int __fastcall timer_start(struct timeval *a1)
{
return gettimeofday(a1, 0LL);
}

canonical_decompiled_code:
int __fastcall func0(struct timeval *a1)
{
return gettimeofday(a1, 0LL);
}

original_code:
void timer_start(Timer* t)
{
    gettimeofday(&t->tv_start, 0);
}

canonical_original_code:
void timer_start(struct Timer *t)
{
    gettimeofday(&t->tv_start, 0);
}

variable_types: struct Timer { struct timeval { long tv_sec; long tv_usec; } tv_start; struct timeval tv_end; } *

user_defined_types: struct Timer { struct timeval tv_start; struct timeval tv_end; }


decompiled_code:
int __fastcall timer_stop(struct timeval *a1)
{
return gettimeofday(a1 + 1, 0LL);
}

canonical_decompiled_code:
int __fastcall func1(struct timeval *a1)
{
return gettimeofday(a1 + 1, 0LL);
}

original_code:
void timer_stop(Timer* t)
{
    gettimeofday(&t->tv_end, 0);
}

canonical_original_code:
void timer_stop(struct Timer *t)
{
    gettimeofday(&t->tv_end, 0);
}

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


decompiled_code:
__int64 __fastcall timer_get_elapsed(_QWORD *a1)
{
__int64 v1; // rdx
__int64 result; // rax

v1 = a1[2];
result = a1[3] - a1[1];
if ( *a1 != v1 )
result = (unsigned int)(int)((double)(int)(v1 - *a1) * 1000000.0 + (double)(int)result);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(_QWORD *a1)
{
__int64 v1; // rdx
__int64 result; // rax

v1 = a1[2];
result = a1[3] - a1[1];
if ( *a1 != v1 )
result = (unsigned int)(int)((double)(int)(v1 - *a1) * 1000000.0 + (double)(int)result);
return result;
}

original_code:
long timer_get_elapsed(Timer* t)
{
    if (t->tv_start.tv_sec == t->tv_end.tv_sec)
        return t->tv_end.tv_usec - t->tv_start.tv_usec;
    else
        return (t->tv_end.tv_sec - t->tv_start.tv_sec) *
            1e6 + (t->tv_end.tv_usec - t->tv_start.tv_usec);
}

canonical_original_code:
long timer_get_elapsed(struct Timer *t)
{
    if (t->tv_start.tv_sec == t->tv_end.tv_sec)
        return t->tv_end.tv_usec - t->tv_start.tv_usec;
    else
        return (t->tv_end.tv_sec - t->tv_start.tv_sec) *
            1e6 + (t->tv_end.tv_usec - t->tv_start.tv_usec);
}


decompiled_code:
char *__fastcall buf_tidy(void *src)
{
size_t v1; // rbx
void *v2; // rax
char *v3; // rax
char *v4; // r8
__int64 v5; // rcx

v1 = strlen((const char *)src);
v2 = malloc((int)v1 + 1);
v3 = (char *)memcpy(v2, src, v1 + 1);
v4 = v3;
if ( (int)v1 <= 0 )
return v4;
v5 = (__int64)&v3[(unsigned int)(v1 - 1) + 1];
while ( 1 )
{
while ( *v3 == 9 )
{
*v3++ = 32;
if ( v3 == (char *)v5 )
return v4;
}
if ( *v3 <= 31 )
break;
if ( ++v3 == (char *)v5 )
return v4;
}
*v3 = 0;
return v4;
}

canonical_decompiled_code:
char *__fastcall func0(void *src)
{
size_t v1; // rbx
void *v2; // rax
char *v3; // rax
char *v4; // r8
__int64 v5; // rcx

v1 = strlen((const char *)src);
v2 = malloc((int)v1 + 1);
v3 = (char *)memcpy(v2, src, v1 + 1);
v4 = v3;
if ( (int)v1 <= 0 )
return v4;
v5 = (__int64)&v3[(unsigned int)(v1 - 1) + 1];
while ( 1 )
{
while ( *v3 == 9 )
{
*v3++ = 32;
if ( v3 == (char *)v5 )
return v4;
}
if ( *v3 <= 31 )
break;
if ( ++v3 == (char *)v5 )
return v4;
}
*v3 = 0;
return v4;
}

original_code:
static char* buf_tidy(const char* str)
{
    int i;
    int n = strlen(str);
    char* ret = malloc(n + 1);
    strcpy(ret, str);
    for (i = 0; i < n; ++i)
    {
        if (ret[i] == '\t')
            ret[i] = ' ';
        else if (ret[i] < ' ')
        {
            ret[i] = '\0';
            break;
        }
    }
    return ret;
}

canonical_original_code:
static char *buf_tidy(char *str)
{
    int i;
    int n = strlen(str);
    char *ret = malloc(n + 1);
    strcpy(ret, str);
    for (i = 0; i < n; ++i)
    {
        if (ret[i] == '\t')
            ret[i] = ' ';
        else if (ret[i] < ' ')
        {
            ret[i] = '\0';
            break;
        }
    }
    return ret;
}

variable_types:
str
char *

variable_types: i int

variable_types: n int

variable_types:
ret
char *


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

v0 = ptr;
while ( v0 )
{
v1 = v0;
v0 = (void *)*((_QWORD *)v0 + 5);
free(v1);
}
}

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

v0 = ptr;
while ( v0 )
{
v1 = v0;
v0 = (void *)*((_QWORD *)v0 + 5);
free(v1);
}
}

original_code:
void trans_data_cleanup(void)
{
    xfer* xf = xfers.next;
    while(xf)
    {
        xfer* tmp = xf;
        xf = xf->next;
        free(tmp);
    }
}

canonical_original_code:
void trans_data_cleanup()
{
    struct xfer *xf = xfers.next;
    while(xf)
    {
        struct xfer *tmp = xf;
        xf = xf->next;
        free(tmp);
    }
}

variable_types: struct xfer { int type; char str[-1]; struct xfer *next; } *


decompiled_code:
__int64 __fastcall get_transaction_type(char *s1)
{
const char *v1; // rbx
size_t v2; // rax

v1 = (const char *)ptr;
if ( !s1 || !ptr )
return 0xFFFFFFFFLL;
while ( 1 )
{
v2 = strlen(v1 + 4);
if ( !strncasecmp(s1, v1 + 4, v2) )
break;
v1 = (const char *)*((_QWORD *)v1 + 5);
if ( !v1 )
return 0xFFFFFFFFLL;
}
return *(unsigned int *)v1;
}

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

v1 = (const char *)ptr;
if ( !s1 || !ptr )
return 0xFFFFFFFFLL;
while ( 1 )
{
v2 = strlen(v1 + 4);
if ( !strncasecmp(s1, v1 + 4, v2) )
break;
v1 = (const char *)*((_QWORD *)v1 + 5);
if ( !v1 )
return 0xFFFFFFFFLL;
}
return *(unsigned int *)v1;
}

original_code:
int get_transaction_type(const char* str)
{
    xfer* tr = xfers.next;
    if (!str)
        return TR_ERR;
    while (tr)
    {
        if (strncasecmp(str, tr->str, strlen(tr->str)) == 0)
            return tr->type;
        tr = tr->next;
    }
    return TR_ERR;
}

canonical_original_code:
int get_transaction_type(char *str)
{
    struct xfer *tr = xfers.next;
    if (!str)
        return TR_ERR;
    while (tr)
    {
        if (strncasecmp(str, tr->str, strlen(tr->str)) == 0)
            return tr->type;
        tr = tr->next;
    }
    return TR_ERR;
}

user_defined_types: struct xfer { int type; char str[-1]; struct xfer *next; }


decompiled_code:
int trans_data_init()
{
unsigned int v0; // ebx
_QWORD *v1; // rax
__int64 v2; // rdx

xfers_add_isra_0("Balance carried forward", 35);
xfers_add_isra_0("Bal", 0);
xfers_add_isra_0("Balance brought forward", 0);
xfers_add_isra_0("BROUGHT FORWARD", 0);
xfers_add_isra_0("ATM", 1);
xfers_add_isra_0("CASH WITHDRAWAL", 1);
xfers_add_isra_0("BAC", 2);
xfers_add_isra_0("BGC", 3);
xfers_add_isra_0("BSP", 4);
xfers_add_isra_0("BP", 5);
xfers_add_isra_0("CDM", 6);
xfers_add_isra_0("CASH & DEP MACHINE", 6);
xfers_add_isra_0("CHG", 7);
xfers_add_isra_0("Charge", 7);
xfers_add_isra_0("CHP", 8);
xfers_add_isra_0("CHQ", 9);
xfers_add_isra_0("CIR", 10);
xfers_add_isra_0("CUI", 11);
xfers_add_isra_0("CR", 12);
xfers_add_isra_0("AUTOMATED CREDIT", 12);
xfers_add_isra_0("CWP", 13);
xfers_add_isra_0("DD", 14);
xfers_add_isra_0("D/D", 14);
xfers_add_isra_0("DIRECT DEBIT", 14);
xfers_add_isra_0("DIV", 15);
xfers_add_isra_0("DR", 16);
xfers_add_isra_0("DWP", 17);
xfers_add_isra_0("ERTF", 18);
xfers_add_isra_0("IBP", 19);
xfers_add_isra_0("INT", 20);
v0 = 0;
xfers_add_isra_0("ITL", 21);
xfers_add_isra_0("MAE", 22);
xfers_add_isra_0("NDC", 23);
xfers_add_isra_0("OTR", 24);
xfers_add_isra_0("ONLINE TRANSACTION", 24);
xfers_add_isra_0("POC", 25);
xfers_add_isra_0("POS", 26);
xfers_add_isra_0("DEBIT CARD TRANSACTION", 26);
xfers_add_isra_0("DEBIT CARD", 26);
xfers_add_isra_0("SO", 27);
xfers_add_isra_0("S/O", 27);
xfers_add_isra_0("STANDING ORDER", 27);
xfers_add_isra_0("SBT", 28);
xfers_add_isra_0("TEL", 29);
xfers_add_isra_0("TFR", 30);
xfers_add_isra_0("TLR", 31);
xfers_add_isra_0("VIS", 32);
xfers_add_isra_0("(((", 33);
do
{
while ( 1 )
{
v1 = get_transaction_str(v0);
if ( !v1 )
break;
if ( ++v0 == 34 )
return (int)v1;
}
v2 = v0++;
LODWORD(v1) = fprintf(stderr, "ERROR: string not set for xfer id:%d\n", v2);
}
while ( v0 != 34 );
return (int)v1;
}

canonical_decompiled_code:
int func2()
{
unsigned int v0; // ebx
_QWORD *v1; // rax
__int64 v2; // rdx

xfers_add_isra_0("Balance carried forward", 35);
xfers_add_isra_0("Bal", 0);
xfers_add_isra_0("Balance brought forward", 0);
xfers_add_isra_0("BROUGHT FORWARD", 0);
xfers_add_isra_0("ATM", 1);
xfers_add_isra_0("CASH WITHDRAWAL", 1);
xfers_add_isra_0("BAC", 2);
xfers_add_isra_0("BGC", 3);
xfers_add_isra_0("BSP", 4);
xfers_add_isra_0("BP", 5);
xfers_add_isra_0("CDM", 6);
xfers_add_isra_0("CASH & DEP MACHINE", 6);
xfers_add_isra_0("CHG", 7);
xfers_add_isra_0("Charge", 7);
xfers_add_isra_0("CHP", 8);
xfers_add_isra_0("CHQ", 9);
xfers_add_isra_0("CIR", 10);
xfers_add_isra_0("CUI", 11);
xfers_add_isra_0("CR", 12);
xfers_add_isra_0("AUTOMATED CREDIT", 12);
xfers_add_isra_0("CWP", 13);
xfers_add_isra_0("DD", 14);
xfers_add_isra_0("D/D", 14);
xfers_add_isra_0("DIRECT DEBIT", 14);
xfers_add_isra_0("DIV", 15);
xfers_add_isra_0("DR", 16);
xfers_add_isra_0("DWP", 17);
xfers_add_isra_0("ERTF", 18);
xfers_add_isra_0("IBP", 19);
xfers_add_isra_0("INT", 20);
v0 = 0;
xfers_add_isra_0("ITL", 21);
xfers_add_isra_0("MAE", 22);
xfers_add_isra_0("NDC", 23);
xfers_add_isra_0("OTR", 24);
xfers_add_isra_0("ONLINE TRANSACTION", 24);
xfers_add_isra_0("POC", 25);
xfers_add_isra_0("POS", 26);
xfers_add_isra_0("DEBIT CARD TRANSACTION", 26);
xfers_add_isra_0("DEBIT CARD", 26);
xfers_add_isra_0("SO", 27);
xfers_add_isra_0("S/O", 27);
xfers_add_isra_0("STANDING ORDER", 27);
xfers_add_isra_0("SBT", 28);
xfers_add_isra_0("TEL", 29);
xfers_add_isra_0("TFR", 30);
xfers_add_isra_0("TLR", 31);
xfers_add_isra_0("VIS", 32);
xfers_add_isra_0("(((", 33);
do
{
while ( 1 )
{
v1 = get_transaction_str(v0);
if ( !v1 )
break;
if ( ++v0 == 34 )
return (int)v1;
}
v2 = v0++;
LODWORD(v1) = fprintf(stderr, "ERROR: string not set for xfer id:%d\n", v2);
}
while ( v0 != 34 );
return (int)v1;
}

original_code:
void trans_data_init(void)
{
    xfers_add("Balance carried forward",TR_CLOSING_BALANCE);
    xfers_add("Bal", TR_BALANCE);
    xfers_add("Balance brought forward",TR_BALANCE);
    xfers_add("BROUGHT FORWARD", TR_BALANCE);
    xfers_add("ATM", TR_ATM);
    xfers_add("CASH WITHDRAWAL", TR_ATM);
    xfers_add("BAC", TR_BAC);
    xfers_add("BGC", TR_BGC);
    xfers_add("BSP", TR_BSP);
    xfers_add("BP", TR_BP);
    xfers_add("CDM", TR_CDM);
    xfers_add("CASH & DEP MACHINE", TR_CDM);
    xfers_add("CHG", TR_CHARGE);
    xfers_add("Charge", TR_CHARGE);
    xfers_add("CHP", TR_CHP);
    xfers_add("CHQ", TR_CHQ);
    xfers_add("CIR", TR_CIR);
    xfers_add("CUI", TR_CUI);
    xfers_add("CR", TR_CR);
    xfers_add("AUTOMATED CREDIT", TR_CR);
    xfers_add("CWP", TR_CWP);
    xfers_add("DD", TR_DD);
    xfers_add("D/D", TR_DD);
    xfers_add("DIRECT DEBIT", TR_DD);
    xfers_add("DIV", TR_DIV);
    xfers_add("DR", TR_DR);
    xfers_add("DWP", TR_DWP);
    xfers_add("ERTF", TR_ERTF);
    xfers_add("IBP", TR_IBP);
    xfers_add("INT", TR_INT);
    xfers_add("ITL", TR_ITL);
    xfers_add("MAE", TR_MAE);
    xfers_add("NDC", TR_NDC);
    xfers_add("OTR", TR_OTR);
    xfers_add("ONLINE TRANSACTION", TR_OTR);
    xfers_add("POC", TR_POC);
    xfers_add("POS", TR_POS);
    xfers_add("DEBIT CARD TRANSACTION", TR_POS);
    xfers_add("DEBIT CARD", TR_POS);
    xfers_add("SO", TR_SO);
    xfers_add("S/O", TR_SO);
    xfers_add("STANDING ORDER", TR_SO);
    xfers_add("SBT", TR_SBT);
    xfers_add("TEL", TR_TEL);
    xfers_add("TFR", TR_TFR);
    xfers_add("TLR", TR_TLR);
    xfers_add("VIS", TR_VIS);
    xfers_add("(((", TR_CONTACTLESS);
    {
        int n;
        for (n = TR_BALANCE; n < TR_XXX_LAST_XXX; ++n)
        {
            if (!get_transaction_str(n))
                fprintf(stderr,"ERROR: string not set for xfer id:%d\n",n);
        }
    }
}

canonical_original_code:
void trans_data_init()
{
    xfers_add("Balance carried forward",TR_CLOSING_BALANCE);
    xfers_add("Bal", TR_BALANCE);
    xfers_add("Balance brought forward",TR_BALANCE);
    xfers_add("BROUGHT FORWARD", TR_BALANCE);
    xfers_add("ATM", TR_ATM);
    xfers_add("CASH WITHDRAWAL", TR_ATM);
    xfers_add("BAC", TR_BAC);
    xfers_add("BGC", TR_BGC);
    xfers_add("BSP", TR_BSP);
    xfers_add("BP", TR_BP);
    xfers_add("CDM", TR_CDM);
    xfers_add("CASH & DEP MACHINE", TR_CDM);
    xfers_add("CHG", TR_CHARGE);
    xfers_add("Charge", TR_CHARGE);
    xfers_add("CHP", TR_CHP);
    xfers_add("CHQ", TR_CHQ);
    xfers_add("CIR", TR_CIR);
    xfers_add("CUI", TR_CUI);
    xfers_add("CR", TR_CR);
    xfers_add("AUTOMATED CREDIT", TR_CR);
    xfers_add("CWP", TR_CWP);
    xfers_add("DD", TR_DD);
    xfers_add("D/D", TR_DD);
    xfers_add("DIRECT DEBIT", TR_DD);
    xfers_add("DIV", TR_DIV);
    xfers_add("DR", TR_DR);
    xfers_add("DWP", TR_DWP);
    xfers_add("ERTF", TR_ERTF);
    xfers_add("IBP", TR_IBP);
    xfers_add("INT", TR_INT);
    xfers_add("ITL", TR_ITL);
    xfers_add("MAE", TR_MAE);
    xfers_add("NDC", TR_NDC);
    xfers_add("OTR", TR_OTR);
    xfers_add("ONLINE TRANSACTION", TR_OTR);
    xfers_add("POC", TR_POC);
    xfers_add("POS", TR_POS);
    xfers_add("DEBIT CARD TRANSACTION", TR_POS);
    xfers_add("DEBIT CARD", TR_POS);
    xfers_add("SO", TR_SO);
    xfers_add("S/O", TR_SO);
    xfers_add("STANDING ORDER", TR_SO);
    xfers_add("SBT", TR_SBT);
    xfers_add("TEL", TR_TEL);
    xfers_add("TFR", TR_TFR);
    xfers_add("TLR", TR_TLR);
    xfers_add("VIS", TR_VIS);
    xfers_add("(((", TR_CONTACTLESS);
    {
        int n;
        for (n = TR_BALANCE; n < TR_XXX_LAST_XXX; ++n)
        {
            if (!get_transaction_str(n))
                fprintf(stderr,"ERROR: string not set for xfer id:%d\n",n);
        }
    }
}


original_code:
char* mon_val_brut(const char* str)
{
    char tmp[80];
    char* r = tmp;
    char* w = tmp;
    sscanf(str, "%[+-0123456789,. D]", tmp);
    while (*r != '\0')
    {
        if (*r != ',')
            *w++ = *r;
        ++r;
    }
    *w = *r;
    return strdup(tmp);
}

canonical_original_code:
char *mon_val_brut(char *str)
{
    char tmp[80];
    char *r = tmp;
    char *w = tmp;
    sscanf(str, "%[+-0123456789,. D]", tmp);
    while (*r != '\0')
    {
        if (*r != ',')
            *w++ = *r;
        ++r;
    }
    *w = *r;
    return strdup(tmp);
}

variable_types:
tmp
char [80]

variable_types:
r
char *

variable_types:
w
char *


decompiled_code:
__int64 __fastcall transaction_append(__int64 a1, __int64 a2, __int64 a3)
{
if ( a1 )
{
str_append_n(a1 + 16, a2, 40LL);
str_append_n(a1 + 56, a3, 80LL);
}
return a1;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, __int64 a2, __int64 a3)
{
if ( a1 )
{
str_append_n(a1 + 16, a2, 40LL);
str_append_n(a1 + 56, a3, 80LL);
}
return a1;
}

original_code:
tran*
transaction_append(tran* tr, const char* type_str, const char* descr)
{
    if (!tr)
        return 0;
    str_append_n(tr->type_str, type_str, 40);
    str_append_n(tr->descr, descr, 80);
    return tr;
}

canonical_original_code:
struct transaction *transaction_append(struct transaction *tr, char *type_str, char *descr)
{
    if (!tr)
        return 0;
    str_append_n(tr->type_str, type_str, 40);
    str_append_n(tr->descr, descr, 80);
    return tr;
}

variable_types:
tr
struct transaction *

variable_types:
descr
char *

return_type: struct transaction { int day; int month; int year; int type; char type_str[40]; char descr[80]; int amt; int bal; struct transaction *next; } *


decompiled_code:
__int64 __fastcall month_to_int(char *s2)
{
const char *v2; // rdi
__int64 i; // rbx
int v4; // eax
unsigned int v5; // er8

if ( !s2 )
return 0xFFFFFFFFLL;
v2 = (const char *)&unk_2E3;
for ( i = 1LL; ; ++i )
{
v4 = strcasecmp(v2, s2);
v5 = i;
if ( !v4 )
break;
if ( i == 12 )
return (unsigned int)-1;
v2 = (const char *)*(&months + i);
}
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func0(char *s2)
{
const char *v2; // rdi
__int64 i; // rbx
int v4; // eax
unsigned int v5; // er8

if ( !s2 )
return 0xFFFFFFFFLL;
v2 = (const char *)&unk_2E3;
for ( i = 1LL; ; ++i )
{
v4 = strcasecmp(v2, s2);
v5 = i;
if ( !v4 )
break;
if ( i == 12 )
return (unsigned int)-1;
v2 = (const char *)*(&months + i);
}
return v5;
}

original_code:
int month_to_int(const char* str)
{
    int m;
    if (!str)
        return -1;
    for (m = 0; m < 12; ++m)
        if (strcasecmp(months[m], str) == 0)
            return m + 1;
    return -1;
}

canonical_original_code:
int month_to_int(char *str)
{
    int m;
    if (!str)
        return -1;
    for (m = 0; m < 12; ++m)
        if (strcasecmp(months[m], str) == 0)
            return m + 1;
    return -1;
}

variable_types: m int


decompiled_code:
__int64 __fastcall int_to_month(int a1)
{
unsigned int v1; // edi
__int64 result; // rax

v1 = a1 - 1;
if ( v1 > 0xB )
result = 0LL;
else
result = (__int64)*(&months + (int)v1);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1)
{
unsigned int v1; // edi
__int64 result; // rax

v1 = a1 - 1;
if ( v1 > 0xB )
result = 0LL;
else
result = (__int64)*(&months + (int)v1);
return result;
}

original_code:
const char* int_to_month(int m)
{
    if (m < 1 || m > 12)
        return 0;
    return months[m - 1];
}

canonical_original_code:
char *int_to_month(int m)
{
    if (m < 1 || m > 12)
        return 0;
    return months[m - 1];
}


decompiled_code:
char *__fastcall int_to_month_full(int a1)
{
unsigned int v1; // edi
char *result; // rax

v1 = a1 - 1;
if ( v1 > 0xB )
result = 0LL;
else
result = months_full[v1];
return result;
}

canonical_decompiled_code:
char *__fastcall func2(int a1)
{
unsigned int v1; // edi
char *result; // rax

v1 = a1 - 1;
if ( v1 > 0xB )
result = 0LL;
else
result = months_full[v1];
return result;
}

original_code:
const char* int_to_month_full(int m)
{
    if (m < 1 || m > 12)
        return 0;
    return months_full[m - 1];
}

canonical_original_code:
char *int_to_month_full(int m)
{
    if (m < 1 || m > 12)
        return 0;
    return months_full[m - 1];
}


decompiled_code:
size_t __fastcall str_append_n(const char *a1, const char *a2, int a3)
{
__int64 v3; // r12
size_t v4; // rax
char *v5; // rbp
size_t v6; // r14
size_t result; // rax

v3 = a3;
v4 = strlen(a1);
v5 = (char *)&a1[v4];
if ( a1 < &a1[v4] )
*v5++ = 32;
v6 = strlen(a2);
strncpy(v5, a2, v3 - (v5 - a1));
result = v6;
a1[v3 - 1] = 0;
if ( v3 - (v5 - a1) <= v6 )
result = v3 - (v5 - a1);
return result;
}

canonical_decompiled_code:
size_t __fastcall func4(const char *a1, const char *a2, int a3)
{
__int64 v3; // r12
size_t v4; // rax
char *v5; // rbp
size_t v6; // r14
size_t result; // rax

v3 = a3;
v4 = strlen(a1);
v5 = (char *)&a1[v4];
if ( a1 < &a1[v4] )
*v5++ = 32;
v6 = strlen(a2);
strncpy(v5, a2, v3 - (v5 - a1));
result = v6;
a1[v3 - 1] = 0;
if ( v3 - (v5 - a1) <= v6 )
result = v3 - (v5 - a1);
return result;
}

original_code:
int str_append_n(char* buf, const char* src, int buf_len)
{
    size_t l1, l2;
    char* p = buf;
    p = buf + strlen(buf);
    if (p > buf)
        *p++ = ' ';
    l1 = buf_len - (p - buf);
    l2 = strlen(src);
    strncpy(p, src, l1);
    buf[buf_len - 1] = '\0';
    return (l2 < l1 ? l2 : l1);
}

canonical_original_code:
int str_append_n(char *buf, char *src, int buf_len)
{
    unsigned long l1; unsigned long l2;
    char *p = buf;
    p = buf + strlen(buf);
    if (p > buf)
        *p++ = ' ';
    l1 = buf_len - (p - buf);
    l2 = strlen(src);
    strncpy(p, src, l1);
    buf[buf_len - 1] = '\0';
    return (l2 < l1 ? l2 : l1);
}

variable_types:
buf
char *

variable_types:
src
char *

variable_types:
p
char *


decompiled_code:
char *__fastcall get_filename_ext(const char *a1)
{
char *v1; // rax
char *result; // rax

v1 = strrchr(a1, 46);
if ( v1 && v1[1] )
result = strdup(v1 + 1);
else
result = 0LL;
return result;
}

canonical_decompiled_code:
char *__fastcall func5(const char *a1)
{
char *v1; // rax
char *result; // rax

v1 = strrchr(a1, 46);
if ( v1 && v1[1] )
result = strdup(v1 + 1);
else
result = 0LL;
return result;
}

original_code:
char* get_filename_ext(const char* fname)
{
    const char* d = strrchr(fname, '.');
    if (!d)
        return 0;
    ++d;
    if (*d == '\0')
        return 0;
    return strdup(d);
}

canonical_original_code:
char *get_filename_ext(char *fname)
{
    char *d = strrchr(fname, '.');
    if (!d)
        return 0;
    ++d;
    if (*d == '\0')
        return 0;
    return strdup(d);
}

variable_types:
fname
char *

variable_types:
d
char *


decompiled_code:
void __fastcall text_file_cleanup(void *ptr)
{
void *v1; // rbx
void *v2; // rdi

if ( ptr )
{
v1 = ptr;
do
{
v2 = v1;
v1 = (void *)*((_QWORD *)v1 + 64);
free(v2);
}
while ( v1 );
}
}

canonical_decompiled_code:
void __fastcall func7(void *ptr)
{
void *v1; // rbx
void *v2; // rdi

if ( ptr )
{
v1 = ptr;
do
{
v2 = v1;
v1 = (void *)*((_QWORD *)v1 + 64);
free(v2);
}
while ( v1 );
}
}

original_code:
void text_file_cleanup(txtline* tl)
{
    while(tl)
    {
        txtline* tmp = tl;
        tl = tl->next;
        free(tmp);
    }
}

canonical_original_code:
void text_file_cleanup(struct txtline *tl)
{
    while(tl)
    {
        struct txtline *tmp = tl;
        tl = tl->next;
        free(tmp);
    }
}

variable_types: struct txtline { char buf[512]; struct txtline *next; } *


terminate

decompiled_code:
void __noreturn terminate()
{
gpioTerminate();
fwrite("SIGHUP/SIGTERM received\n", 1uLL, 0x18uLL, errFifo);
fflush(0LL);
fclose(errFifo);
unlink("/dev/pigerr");
exit(0);
}

canonical_decompiled_code:
void __noreturn func0()
{
gpioTerminate();
fwrite("SIGHUP/SIGTERM received\n", 1uLL, 0x18uLL, errFifo);
fflush(0LL);
fclose(errFifo);
unlink("/dev/pigerr");
exit(0);
}

original_code:
void terminate(int signum)
{
   gpioTerminate();
   fprintf(errFifo, "SIGHUP/SIGTERM received\n");
   fflush(((void *)0));
   fclose(errFifo);
   unlink("/dev/pigerr");
   exit(0);
}

variable_types: signum int


usage

decompiled_code:
size_t usage()
{
return fwrite(
"\n"
"Usage: sudo pigpiod [OPTION] ...\n"
" -b value, gpio sample buffer in milliseconds, default 120\n"
" -d value, DMA channel, 0-14, default 14\n"
" -f, disable fifo interface, default enabled\n"
" -k, disable socket interface, default enabled\n"
" -p value, socket port, 1024-32000, default 8888\n"
" -s value, sample rate, 1, 2, 4, 5, 8, or 10, default 5\n"
" -t value, clock peripheral, 0=PWM 1=PCM, default PCM\n"
" -u value, clock source, 0=OSC 1=PLLD, default PLLD\n"
"EXAMPLE\n"
"sudo pigpiod -s 2 -b 200 -f\n"
" Set a sample rate of 2 microseconds with a 200 millisecond\n"
" buffer. Disable the fifo interface.\n"
"\n",
1uLL,
0x29AuLL,
stderr);
}

canonical_decompiled_code:
size_t func1()
{
return fwrite(
"\n"
"Usage: sudo pigpiod [OPTION] ...\n"
" -b value, gpio sample buffer in milliseconds, default 120\n"
" -d value, DMA channel, 0-14, default 14\n"
" -f, disable fifo interface, default enabled\n"
" -k, disable socket interface, default enabled\n"
" -p value, socket port, 1024-32000, default 8888\n"
" -s value, sample rate, 1, 2, 4, 5, 8, or 10, default 5\n"
" -t value, clock peripheral, 0=PWM 1=PCM, default PCM\n"
" -u value, clock source, 0=OSC 1=PLLD, default PLLD\n"
"EXAMPLE\n"
"sudo pigpiod -s 2 -b 200 -f\n"
" Set a sample rate of 2 microseconds with a 200 millisecond\n"
" buffer. Disable the fifo interface.\n"
"\n",
1uLL,
0x29AuLL,
stderr);
}

original_code:
void usage()
{
   fprintf(stderr, "\n" "Usage: sudo pigpiod [OPTION] ...\n" "   -b value, gpio sample buffer in milliseconds, default 120\n" "   -d value, DMA channel, 0-14,                  default 14\n" "   -f,       disable fifo interface,             default enabled\n" "   -k,       disable socket interface,           default enabled\n" "   -p value, socket port, 1024-32000,            default 8888\n" "   -s value, sample rate, 1, 2, 4, 5, 8, or 10,  default 5\n" "   -t value, clock peripheral, 0=PWM 1=PCM,      default PCM\n" "   -u value, clock source, 0=OSC 1=PLLD,         default PLLD\n" "EXAMPLE\n" "sudo pigpiod -s 2 -b 200 -f\n" "  Set a sample rate of 2 microseconds with a 200 millisecond\n" "  buffer.  Disable the fifo interface.\n" "\n");
}


initOpts

decompiled_code:
int __fastcall initOpts(int argc, char **argv)
{
int result; // eax
unsigned int v3; // eax
unsigned int v4; // eax
unsigned int v5; // eax
unsigned int v6; // ecx
unsigned int v7; // eax
unsigned int v8; // eax

while ( 1 )
{
result = getopt(argc, argv, "b:d:fkp:s:t:u:");
if ( result == -1 )
break;
switch ( result )
{
case 'b':
v7 = atoi(optarg);
if ( v7 - 100 > 0x26AC )
cmdFatal("invalid -b option (%d)", v7);
else
bufferSizeMilliseconds = v7;
break;
case 'd':
v8 = atoi(optarg);
if ( v8 > 0xE )
cmdFatal("invalid -d option (%d)", v8);
else
DMAchannelChannel = v8;
break;
case 'f':
ifFlags |= 1u;
break;
case 'k':
ifFlags |= 2u;
break;
case 'p':
v5 = atoi(optarg);
if ( v5 - 1024 > 0x7900 )
cmdFatal("invalid -p option (%d)", v5);
else
socketPort = v5;
break;
case 's':
v6 = atoi(optarg);
if ( v6 <= 0xA && ((1LL << v6) & 0x536) != 0 )
clockMicros = v6;
else
cmdFatal("invalid -s option (%d)", v6);
break;
case 't':
v4 = atoi(optarg);
if ( v4 > 1 )
cmdFatal("invalid -t option (%d)", v4);
else
clockPeripheral = v4;
break;
case 'u':
v3 = atoi(optarg);
if ( v3 > 1 )
cmdFatal("invalid -u option (%d)", v3);
else
clockSource = v3;
break;
default:
usage();
exit(-1);
}
}
return result;
}

canonical_decompiled_code:
int __fastcall func2(int argc, char **argv)
{
int result; // eax
unsigned int v3; // eax
unsigned int v4; // eax
unsigned int v5; // eax
unsigned int v6; // ecx
unsigned int v7; // eax
unsigned int v8; // eax

while ( 1 )
{
result = getopt(argc, argv, "b:d:fkp:s:t:u:");
if ( result == -1 )
break;
switch ( result )
{
case 'b':
v7 = atoi(optarg);
if ( v7 - 100 > 0x26AC )
cmdFatal("invalid -b option (%d)", v7);
else
bufferSizeMilliseconds = v7;
break;
case 'd':
v8 = atoi(optarg);
if ( v8 > 0xE )
cmdFatal("invalid -d option (%d)", v8);
else
DMAchannelChannel = v8;
break;
case 'f':
ifFlags |= 1u;
break;
case 'k':
ifFlags |= 2u;
break;
case 'p':
v5 = atoi(optarg);
if ( v5 - 1024 > 0x7900 )
cmdFatal("invalid -p option (%d)", v5);
else
socketPort = v5;
break;
case 's':
v6 = atoi(optarg);
if ( v6 <= 0xA && ((1LL << v6) & 0x536) != 0 )
clockMicros = v6;
else
cmdFatal("invalid -s option (%d)", v6);
break;
case 't':
v4 = atoi(optarg);
if ( v4 > 1 )
cmdFatal("invalid -t option (%d)", v4);
else
clockPeripheral = v4;
break;
case 'u':
v3 = atoi(optarg);
if ( v3 > 1 )
cmdFatal("invalid -u option (%d)", v3);
else
clockSource = v3;
break;
default:
func1();
exit(-1);
}
}
return result;
}

original_code:
static void initOpts(int argc, char *argv[])
{
   int i, opt;
   while ((opt = getopt(argc, argv, "b:d:fkp:s:t:u:")) != -1)
   {
      i = -1;
      switch (opt)
      {
         case 'b':
            i = atoi(optarg);
            if ((i >= 100) && (i <= 10000))
               bufferSizeMilliseconds = i;
            else cmdFatal("invalid -b option (%d)", i);
            break;
         case 'd':
            i = atoi(optarg);
            if ((i >= 0) && (i <= 14))
               DMAchannelChannel = i;
            else cmdFatal("invalid -d option (%d)", i);
            break;
         case 'f':
            ifFlags |= 1;
            break;
         case 'k':
            ifFlags |= 2;
            break;
         case 'p':
            i = atoi(optarg);
            if ((i >= 1024) && (i <= 32000))
               socketPort = i;
            else cmdFatal("invalid -p option (%d)", i);
            break;
         case 's':
            i = atoi(optarg);
            switch(i)
            {
               case 1:
               case 2:
               case 4:
               case 5:
               case 8:
               case 10:
                  clockMicros = i;
                  break;
               default:
                  cmdFatal("invalid -s option (%d)", i);
                  break;
            }
            break;
         case 't':
            i = atoi(optarg);
            if ((i >= 0) && (i <= 1))
               clockPeripheral = i;
            else cmdFatal("invalid -t option (%d)", i);
            break;
         case 'u':
            i = atoi(optarg);
            if ((i >= 0) && (i <= 1))
               clockSource = i;
            else cmdFatal("invalid -u option (%d)", i);
            break;
        default:
           usage();
           exit(-1);
        }
    }
}

canonical_original_code:
static void initOpts(int argc, char *argv[])
{
   int i; int opt;
   while ((opt = getopt(argc, argv, "b:d:fkp:s:t:u:")) != -1)
   {
      i = -1;
      switch (opt)
      {
         case 'b':
            i = atoi(optarg);
            if ((i >= 100) && (i <= 10000))
               bufferSizeMilliseconds = i;
            else cmdFatal("invalid -b option (%d)", i);
            break;
         case 'd':
            i = atoi(optarg);
            if ((i >= 0) && (i <= 14))
               DMAchannelChannel = i;
            else cmdFatal("invalid -d option (%d)", i);
            break;
         case 'f':
            ifFlags |= 1;
            break;
         case 'k':
            ifFlags |= 2;
            break;
         case 'p':
            i = atoi(optarg);
            if ((i >= 1024) && (i <= 32000))
               socketPort = i;
            else cmdFatal("invalid -p option (%d)", i);
            break;
         case 's':
            i = atoi(optarg);
            switch(i)
            {
               case 1:
               case 2:
               case 4:
               case 5:
               case 8:
               case 10:
                  clockMicros = i;
                  break;
               default:
                  cmdFatal("invalid -s option (%d)", i);
                  break;
            }
            break;
         case 't':
            i = atoi(optarg);
            if ((i >= 0) && (i <= 1))
               clockPeripheral = i;
            else cmdFatal("invalid -t option (%d)", i);
            break;
         case 'u':
            i = atoi(optarg);
            if ((i >= 0) && (i <= 1))
               clockSource = i;
            else cmdFatal("invalid -u option (%d)", i);
            break;
        default:
           usage();
           exit(-1);
        }
    }
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: i int

variable_types: opt int


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__pid_t v3; // eax
int v4; // eax
unsigned int v5; // ebp
int v6; // eax
__int64 v7; // rdx

v3 = fork();
if ( v3 < 0 )
exit(1);
if ( v3 )
exit(0);
umask(0);
if ( setsid() < 0 )
cmdFatal("setsid failed (%m)");
if ( chdir("/") < 0 )
cmdFatal("chdir failed (%m)");
initOpts(argc, (char **)argv);
fclose(stdin);
fclose(stdout);
gpioCfgBufferSize((unsigned int)bufferSizeMilliseconds);
gpioCfgClock((unsigned int)clockMicros, (unsigned int)clockPeripheral, (unsigned int)clockSource);
gpioCfgInterfaces((unsigned int)ifFlags);
gpioCfgDMAchannel((unsigned int)DMAchannelChannel);
gpioCfgSocketPort((unsigned int)socketPort);
if ( (int)gpioInitialise() < 0 )
cmdFatal("Can't initialise pigpio library");
unlink("/dev/pigerr");
mkfifo("/dev/pigerr", 0x1B4u);
if ( chmod("/dev/pigerr", 0x1B4u) < 0 )
cmdFatal("chmod %s failed (%m)", "/dev/pigerr");
errFifo = freopen("/dev/pigerr", "w+", stderr);
if ( errFifo )
{
v4 = fileno(errFifo);
v5 = fcntl(v4, 3, 0LL);
v6 = fileno(errFifo);
v7 = v5;
BYTE1(v7) = BYTE1(v5) | 8;
fcntl(v6, 4, v7);
gpioSetSignalFunc(1LL, terminate);
gpioSetSignalFunc(15LL, terminate);
while ( 1 )
{
sleep(5u);
fflush(errFifo);
}
}
fprintf(stderr, "freopen failed (%m)");
gpioTerminate();
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__pid_t v3; // eax
int v4; // eax
unsigned int v5; // ebp
int v6; // eax
__int64 v7; // rdx

v3 = fork();
if ( v3 < 0 )
exit(1);
if ( v3 )
exit(0);
umask(0);
if ( setsid() < 0 )
cmdFatal("setsid failed (%m)");
if ( chdir("/") < 0 )
cmdFatal("chdir failed (%m)");
func2(argc, (char **)argv);
fclose(stdin);
fclose(stdout);
gpioCfgBufferSize((unsigned int)bufferSizeMilliseconds);
gpioCfgClock((unsigned int)clockMicros, (unsigned int)clockPeripheral, (unsigned int)clockSource);
gpioCfgInterfaces((unsigned int)ifFlags);
gpioCfgDMAchannel((unsigned int)DMAchannelChannel);
gpioCfgSocketPort((unsigned int)socketPort);
if ( (int)gpioInitialise() < 0 )
cmdFatal("Can't initialise pigpio library");
unlink("/dev/pigerr");
mkfifo("/dev/pigerr", 0x1B4u);
if ( chmod("/dev/pigerr", 0x1B4u) < 0 )
cmdFatal("chmod %s failed (%m)", "/dev/pigerr");
errFifo = freopen("/dev/pigerr", "w+", stderr);
if ( errFifo )
{
v4 = fileno(errFifo);
v5 = fcntl(v4, 3, 0LL);
v6 = fileno(errFifo);
v7 = v5;
BYTE1(v7) = BYTE1(v5) | 8;
fcntl(v6, 4, v7);
gpioSetSignalFunc(1LL, terminate);
gpioSetSignalFunc(15LL, terminate);
while ( 1 )
{
sleep(5u);
fflush(errFifo);
}
}
fprintf(stderr, "freopen failed (%m)");
gpioTerminate();
return 0;
}

original_code:
int main(int argc, char **argv)
{
   pid_t pid;
   int flags;
   pid = fork();
   if (pid < 0) { exit(1); }
   if (pid > 0) { exit(0); }
   umask(0);
   if (setsid() < 0) cmdFatal("setsid failed (%m)");
   if ((chdir("/")) < 0) cmdFatal("chdir failed (%m)");
   initOpts(argc, argv);
   fclose(stdin);
   fclose(stdout);
   gpioCfgBufferSize(bufferSizeMilliseconds);
   gpioCfgClock(clockMicros, clockPeripheral, clockSource);
   gpioCfgInterfaces(ifFlags);
   gpioCfgDMAchannel(DMAchannelChannel);
   gpioCfgSocketPort(socketPort);
   if (gpioInitialise()< 0) cmdFatal("Can't initialise pigpio library");
   unlink("/dev/pigerr");
   mkfifo("/dev/pigerr", 0664);
   if (chmod("/dev/pigerr", 0664) < 0)
      cmdFatal("chmod %s failed (%m)", "/dev/pigerr");
   errFifo = freopen("/dev/pigerr", "w+", stderr);
   if (errFifo)
   {
      flags = fcntl(fileno(errFifo), 3, 0);
      fcntl(fileno(errFifo), 4, flags | 04000);
      gpioSetSignalFunc(1, terminate);
      gpioSetSignalFunc(15, terminate);
      while (1)
      {
         sleep(5);
         fflush(errFifo);
      }
   }
   else
   {
      fprintf(stderr, "freopen failed (%m)");
      gpioTerminate();
   }
   return 0;
}

canonical_original_code:
int main(int argc, char **argv)
{
   int pid;
   int flags;
   pid = fork();
   if (pid < 0) { exit(1); }
   if (pid > 0) { exit(0); }
   umask(0);
   if (setsid() < 0) cmdFatal("setsid failed (%m)");
   if ((chdir("/")) < 0) cmdFatal("chdir failed (%m)");
   initOpts(argc, argv);
   fclose(stdin);
   fclose(stdout);
   gpioCfgBufferSize(bufferSizeMilliseconds);
   gpioCfgClock(clockMicros, clockPeripheral, clockSource);
   gpioCfgInterfaces(ifFlags);
   gpioCfgDMAchannel(DMAchannelChannel);
   gpioCfgSocketPort(socketPort);
   if (gpioInitialise()< 0) cmdFatal("Can't initialise pigpio library");
   unlink("/dev/pigerr");
   mkfifo("/dev/pigerr", 0664);
   if (chmod("/dev/pigerr", 0664) < 0)
      cmdFatal("chmod %s failed (%m)", "/dev/pigerr");
   errFifo = freopen("/dev/pigerr", "w+", stderr);
   if (errFifo)
   {
      flags = fcntl(fileno(errFifo), 3, 0);
      fcntl(fileno(errFifo), 4, flags | 04000);
      gpioSetSignalFunc(1, terminate);
      gpioSetSignalFunc(15, terminate);
      while (1)
      {
         sleep(5);
         fflush(errFifo);
      }
   }
   else
   {
      fprintf(stderr, "freopen failed (%m)");
      gpioTerminate();
   }
   return 0;
}

variable_types:
argv
char **

variable_types: pid int

variable_types: flags int


launchpadAlert

decompiled_code:
__int64 __fastcall launchpadAlert(__int64 a1, int a2, int a3)
{
__int64 result; // rax
int v4; // edx
int v5; // eax
unsigned int v6; // ecx

result = (unsigned int)inited_2;
if ( inited_2 )
{
result = (unsigned int)lastTick_1;
lastTick_1 = a3;
if ( !a2 )
{
v4 = a3 - result;
if ( lastPulseLen_0 )
{
v5 = v4 - lastPulseLen_0 + (v4 - lastPulseLen_0 < 0 ? 0x448 : 0);
v6 = 33 - v5;
result = (unsigned int)(v5 - 33);
if ( (int)result < 0 )
result = v6;
++launchpadPulses;
if ( (int)result > 5 )
{
if ( (int)result <= 10 )
{
result = ++launchpad10;
}
else if ( (int)result > 15 )
{
++launchpadOutRange;
launchpadErr = result;
}
else
{
result = ++launchpad15;
}
}
else
{
result = ++launchpad5;
}
}
lastPulseLen_0 = v4;
}
}
else
{
launchpadPulses = 0LL;
lastTick_1 = a3;
launchpad5 = 0LL;
lastPulseLen_0 = 0;
launchpad10 = 0LL;
inited_2 = 1;
launchpad15 = 0LL;
launchpadOutRange = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, int a2, int a3)
{
__int64 result; // rax
int v4; // edx
int v5; // eax
unsigned int v6; // ecx

result = (unsigned int)inited_2;
if ( inited_2 )
{
result = (unsigned int)lastTick_1;
lastTick_1 = a3;
if ( !a2 )
{
v4 = a3 - result;
if ( lastPulseLen_0 )
{
v5 = v4 - lastPulseLen_0 + (v4 - lastPulseLen_0 < 0 ? 0x448 : 0);
v6 = 33 - v5;
result = (unsigned int)(v5 - 33);
if ( (int)result < 0 )
result = v6;
++launchpadPulses;
if ( (int)result > 5 )
{
if ( (int)result <= 10 )
{
result = ++launchpad10;
}
else if ( (int)result > 15 )
{
++launchpadOutRange;
launchpadErr = result;
}
else
{
result = ++launchpad15;
}
}
else
{
result = ++launchpad5;
}
}
lastPulseLen_0 = v4;
}
}
else
{
launchpadPulses = 0LL;
lastTick_1 = a3;
launchpad5 = 0LL;
lastPulseLen_0 = 0;
launchpad10 = 0LL;
inited_2 = 1;
launchpad15 = 0LL;
launchpadOutRange = 0LL;
}
return result;
}

original_code:
void launchpadAlert(int pin, int level, uint32_t tick)
{
   static int inited = 0, lastTick, lastPulseLen;
   int pulseLen, pulseDif;
   if (inited)
   {
      pulseLen = tick - lastTick;
      lastTick = tick;
      if (level==0)
      {
         if (lastPulseLen)
         {
            pulseDif = pulseLen - lastPulseLen;
            if (pulseDif < 0) pulseDif += 1096;
            pulseDif -= 33;
            if (pulseDif < 0) pulseDif = -pulseDif;
            launchpadPulses++;
            if (pulseDif <= 5)
            {
               launchpad5++;
            }
            else if (pulseDif <= 10)
            {
               launchpad10++;
            }
            else if (pulseDif <= 15)
            {
               launchpad15++;
            }
            else
            {
               launchpadOutRange++;
               launchpadErr = pulseDif;
            }
         }
         lastPulseLen = pulseLen;
      }
   }
   else
   {
      lastTick = tick;
      lastPulseLen = 0;
      launchpadPulses = 0;
      launchpad5 = 0;
      launchpad10 = 0;
      launchpad15 = 0;
      launchpadOutRange = 0;
      inited = 1;
   }
}

canonical_original_code:
void launchpadAlert(int pin, int level, unsigned int tick)
{
   static int inited = 0; static int lastTick; static int lastPulseLen;
   int pulseLen; int pulseDif;
   if (inited)
   {
      pulseLen = tick - lastTick;
      lastTick = tick;
      if (level==0)
      {
         if (lastPulseLen)
         {
            pulseDif = pulseLen - lastPulseLen;
            if (pulseDif < 0) pulseDif += 1096;
            pulseDif -= 33;
            if (pulseDif < 0) pulseDif = -pulseDif;
            launchpadPulses++;
            if (pulseDif <= 5)
            {
               launchpad5++;
            }
            else if (pulseDif <= 10)
            {
               launchpad10++;
            }
            else if (pulseDif <= 15)
            {
               launchpad15++;
            }
            else
            {
               launchpadOutRange++;
               launchpadErr = pulseDif;
            }
         }
         lastPulseLen = pulseLen;
      }
   }
   else
   {
      lastTick = tick;
      lastPulseLen = 0;
      launchpadPulses = 0;
      launchpad5 = 0;
      launchpad10 = 0;
      launchpad15 = 0;
      launchpadOutRange = 0;
      inited = 1;
   }
}

variable_types: pin int

variable_types: level int

variable_types:
tick
unsigned int

variable_types: inited int

variable_types: lastTick int

variable_types: lastPulseLen int

variable_types: pulseLen int

variable_types: pulseDif int


LEDlaserTick

decompiled_code:
__int64 LEDlaserTick()
{
__int64 v0; // rdi
__int64 i; // rbx
int v2; // ecx
__int64 result; // rax

v0 = 14LL;
for ( i = 0LL; ; v0 = (unsigned int)gpio_32[i] )
{
gpioPWM(v0, (unsigned int)vals_33[pos_34[i]]);
v2 = pos_34[i];
result = (unsigned int)inc_31[i];
pos_34[i] = v2 + result;
if ( (unsigned int)(v2 + result) > 9 )
{
result = (unsigned int)-(int)result;
pos_34[i] = v2;
inc_31[i] = result;
}
if ( ++i == 4 )
break;
}
return result;
}

canonical_decompiled_code:
__int64 func1()
{
__int64 v0; // rdi
__int64 i; // rbx
int v2; // ecx
__int64 result; // rax

v0 = 14LL;
for ( i = 0LL; ; v0 = (unsigned int)gpio_32[i] )
{
gpioPWM(v0, (unsigned int)vals_33[pos_34[i]]);
v2 = pos_34[i];
result = (unsigned int)inc_31[i];
pos_34[i] = v2 + result;
if ( (unsigned int)(v2 + result) > 9 )
{
result = (unsigned int)-(int)result;
pos_34[i] = v2;
inc_31[i] = result;
}
if ( ++i == 4 )
break;
}
return result;
}

variable_types:
gpio
int [4]

variable_types:
pos
int [4]

variable_types:
inc
int [4]

variable_types:
vals
int []


sonarLDRtick

decompiled_code:
__int64 sonarLDRtick()
{
gpioWrite(24LL, 1LL);
usleep(0x14u);
gpioWrite(24LL, 0LL);
gpioSetMode(25LL, 1LL);
gpioWrite(25LL, 0LL);
usleep(0xC8u);
LDRrechargeTick = gpioTick();
return gpioSetMode(25LL, 0LL);
}

canonical_decompiled_code:
__int64 func2()
{
gpioWrite(24LL, 1LL);
usleep(0x14u);
gpioWrite(24LL, 0LL);
gpioSetMode(25LL, 1LL);
gpioWrite(25LL, 0LL);
usleep(0xC8u);
LDRrechargeTick = gpioTick();
return gpioSetMode(25LL, 0LL);
}

original_code:
void sonarLDRtick(void)
{
   gpioWrite(24, 1);
   usleep(20);
   gpioWrite(24, 0);
   gpioSetMode(25, 1);
   gpioWrite(25, 0);
   usleep(200);
   LDRrechargeTick = gpioTick();
   gpioSetMode(25, 0);
 }

canonical_original_code:
void sonarLDRtick()
{
   gpioWrite(24, 1);
   usleep(20);
   gpioWrite(24, 0);
   gpioSetMode(25, 1);
   gpioWrite(25, 0);
   usleep(200);
   LDRrechargeTick = gpioTick();
   gpioSetMode(25, 0);
 }


selectDevice

decompiled_code:
int __fastcall selectDevice(int a1, unsigned int a2, const char *a3)
{
int result; // eax

result = ioctl(a1, 0x703uLL, a2);
if ( result < 0 )
result = fprintf(stderr, "%s not present\n", a3);
return result;
}

canonical_decompiled_code:
int __fastcall func3(int a1, unsigned int a2, const char *a3)
{
int result; // eax

result = ioctl(a1, 0x703uLL, a2);
if ( result < 0 )
result = fprintf(stderr, "%s not present\n", a3);
return result;
}

original_code:
void selectDevice(int i2c, int addr, char * name)
{
   if (ioctl(i2c, 0x0703, addr) < 0)
   {
      fprintf(stderr, "%s not present\n", name);
   }
}

canonical_original_code:
void selectDevice(int i2c, int addr, char *name)
{
   if (ioctl(i2c, 0x0703, addr) < 0)
   {
      fprintf(stderr, "%s not present\n", name);
   }
}

variable_types: addr int

variable_types:
name
char *


writeToDevice

decompiled_code:
size_t __fastcall writeToDevice(int a1, const void *a2, int a3)
{
__int64 v3; // rbx
size_t result; // rax

v3 = a3;
result = write(a1, a2, a3);
if ( result == v3 )
{
reported_26 = 0;
}
else
{
result = (unsigned int)reported_26;
if ( !reported_26 )
{
result = fwrite("Can't write to device\n", 1uLL, 0x16uLL, stderr);
reported_26 = 1;
}
}
return result;
}

canonical_decompiled_code:
size_t __fastcall func4(int a1, const void *a2, int a3)
{
__int64 v3; // rbx
size_t result; // rax

v3 = a3;
result = write(a1, a2, a3);
if ( result == v3 )
{
reported_26 = 0;
}
else
{
result = (unsigned int)reported_26;
if ( !reported_26 )
{
result = fwrite("Can't write to device\n", 1uLL, 0x16uLL, stderr);
reported_26 = 1;
}
}
return result;
}

original_code:
void writeToDevice(int i2c, char * buf, int len)
{
   static int reported = 0;
   if (write(i2c, buf, len) != len)
   {
      if (!reported)
      {
         fprintf(stderr, "Can't write to device\n");
         reported = 1;
      }
   }
   else reported = 0;
}

canonical_original_code:
void writeToDevice(int i2c, char *buf, int len)
{
   static int reported = 0;
   if (write(i2c, buf, len) != len)
   {
      if (!reported)
      {
         fprintf(stderr, "Can't write to device\n");
         reported = 1;
      }
   }
   else reported = 0;
}

variable_types:
buf
char *

variable_types: len int

variable_types: reported int