nofocus

decompiled_code:
void nofocus()
{
__int64 v0; // rdi
xcb_window_t v1; // edx
uint32_t value_list[4]; // [rsp+8h] [rbp-10h] BYREF

if ( !current )
{
LABEL_8:
v1 = w_0;
current = 0LL;
if ( !w_0 )
{
value_list[0] = 1;
w_0 = xcb_generate_id(dpy);
xcb_create_window(dpy, 0, w_0, *(_DWORD *)(screens + 4LL), 0, 0, 1u, 1u, 0, 2u, 0, 0x200u, value_list);
xcb_map_window(dpy, w_0);
v1 = w_0;
}
xcb_set_input_focus(dpy, 1u, v1, 0);
return;
}
setactive((unsigned int *)current, 0);
v0 = *(_QWORD *)(current + 24);
if ( !v0 )
{
LABEL_7:
cmapnofocus(*(_QWORD *)(current + 224));
goto LABEL_8;
}
while ( *(_DWORD *)(v0 + 132) != 1 )
{
v0 = *(_QWORD *)(v0 + 24);
if ( !v0 )
goto LABEL_7;
}
active(v0);
}

canonical_decompiled_code:
void func3()
{
__int64 v0; // rdi
xcb_window_t v1; // edx
uint32_t value_list[4]; // [rsp+8h] [rbp-10h] BYREF

if ( !current )
{
LABEL_8:
v1 = w_0;
current = 0LL;
if ( !w_0 )
{
value_list[0] = 1;
w_0 = xcb_generate_id(dpy);
xcb_create_window(dpy, 0, w_0, *(_DWORD *)(screens + 4LL), 0, 0, 1u, 1u, 0, 2u, 0, 0x200u, value_list);
xcb_map_window(dpy, w_0);
v1 = w_0;
}
xcb_set_input_focus(dpy, 1u, v1, 0);
return;
}
func1((unsigned int *)current, 0);
v0 = *(_QWORD *)(current + 24);
if ( !v0 )
{
LABEL_7:
cmapnofocus(*(_QWORD *)(current + 224));
goto LABEL_8;
}
while ( *(_DWORD *)(v0 + 132) != 1 )
{
v0 = *(_QWORD *)(v0 + 24);
if ( !v0 )
goto LABEL_7;
}
func2(v0);
}

original_code:
void nofocus()
{
    static xcb_window_t w = 0;
    uint32_t mask;
    uint32_t values[2];
    Client *c;
    if (current) {
        setactive(current, 0);
        for (c = current->revert; c; c = c->revert)
            if (((c)->state == XCB_ICCCM_WM_STATE_NORMAL)) {
                active(c);
                return;
            }
        cmapnofocus(current->screen);
    }
    current = 0;
    if (w == 0) {
        mask = XCB_CW_OVERRIDE_REDIRECT;
        values[0] = 1;
        w = xcb_generate_id(dpy);
        xcb_create_window(dpy, 0L, w,
            screens[0].root, 0, 0, 1, 1, 0,
            XCB_WINDOW_CLASS_INPUT_ONLY, 0L,
            mask, values);
        xcb_map_window(dpy, w);
    }
    xcb_set_input_focus(dpy, XCB_INPUT_FOCUS_POINTER_ROOT, w,
                0L);
}

canonical_original_code:
void nofocus()
{
    static unsigned int w = 0;
    unsigned int mask;
    unsigned int values[2];
    struct Client *c;
    if (current) {
        setactive(current, 0);
        for (c = current->revert; c; c = c->revert)
            if (((c)->state == XCB_ICCCM_WM_STATE_NORMAL)) {
                active(c);
                return;
            }
        cmapnofocus(current->screen);
    }
    current = 0;
    if (w == 0) {
        mask = XCB_CW_OVERRIDE_REDIRECT;
        values[0] = 1;
        w = xcb_generate_id(dpy);
        xcb_create_window(dpy, 0L, w,
            screens[0].root, 0, 0, 1, 1, 0,
            XCB_WINDOW_CLASS_INPUT_ONLY, 0L,
            mask, values);
        xcb_map_window(dpy, w);
    }
    xcb_set_input_focus(dpy, XCB_INPUT_FOCUS_POINTER_ROOT, w,
                0L);
}

variable_types:
w
unsigned int

variable_types:
mask
unsigned int


top

decompiled_code:
void __fastcall top(__int64 a1)
{
__int64 v1; // rax
__int64 v2; // rcx
__int64 v3; // rax
__int64 *v4; // rcx

if ( !a1 )
return;
v1 = clients;
if ( !clients )
{
LABEL_7:
fprintf(stderr, "9wm: %x not on client list in top()\n", a1);
return;
}
if ( a1 != clients )
{
while ( 1 )
{
v2 = v1;
v1 = *(_QWORD *)(v1 + 16);
if ( !v1 )
goto LABEL_7;
if ( a1 == v1 )
{
v4 = (__int64 *)(v2 + 16);
goto LABEL_10;
}
}
}
v4 = &clients;
LABEL_10:
*v4 = *(_QWORD *)(a1 + 16);
v3 = clients;
clients = a1;
*(_QWORD *)(a1 + 16) = v3;
}

canonical_decompiled_code:
void __fastcall func4(__int64 a1)
{
__int64 v1; // rax
__int64 v2; // rcx
__int64 v3; // rax
__int64 *v4; // rcx

if ( !a1 )
return;
v1 = clients;
if ( !clients )
{
LABEL_7:
fprintf(stderr, "9wm: %x not on client list in top()\n", a1);
return;
}
if ( a1 != clients )
{
while ( 1 )
{
v2 = v1;
v1 = *(_QWORD *)(v1 + 16);
if ( !v1 )
goto LABEL_7;
if ( a1 == v1 )
{
v4 = (__int64 *)(v2 + 16);
goto LABEL_10;
}
}
}
v4 = &clients;
LABEL_10:
*v4 = *(_QWORD *)(a1 + 16);
v3 = clients;
clients = a1;
*(_QWORD *)(a1 + 16) = v3;
}

original_code:
void top(Client *c)
{
    Client **l, *cc;
    if (!c) {
        ;
        return;
    }
    l = &clients;
    for (cc = *l; cc; cc = *l) {
        if (cc == c) {
            *l = c->next;
            c->next = clients;
            clients = c;
            return;
        }
        l = &cc->next;
    }
    fprintf(stderr, "9wm: %x not on client list in top()\n", c);
}

canonical_original_code:
void top(struct Client *c)
{
    struct Client **l; struct Client *cc;
    if (!c) {
        ;
        return;
    }
    l = &clients;
    for (cc = *l; cc; cc = *l) {
        if (cc == c) {
            *l = c->next;
            c->next = clients;
            clients = c;
            return;
        }
        l = &cc->next;
    }
    fprintf(stderr, "9wm: %x not on client list in top()\n", c);
}

variable_types: struct Client { unsigned int window; unsigned int parent; unsigned int trans; struct Client *next; struct Client *revert; int x; int y; int dx; int dy; int border; struct xcb_size_hints_t { unsigned int flags; int x; int width; int min_width; int max_width; int width_inc; int min_aspect_num; int max_aspect_num; int base_width; unsigned int win_gravity; } size; int min_dx; int min_dy; int state; int init; int reparenting; int is9term; int hold; int proto; char *label; char *instance; char *class; char *name; char *iconname; unsigned int cmap; int ncmapwins; unsigned int *cmapwins; unsigned int *wmcmaps; struct ScreenInfo { int num; unsigned int root; unsigned int menuwin; unsigned int def_cmap; unsigned int gc; unsigned int black; unsigned int white; int min_cmaps; unsigned int target; unsigned int sweep0; unsigned int boxcurs; unsigned int arrow; unsigned int root_pixmap; char display[256]; } *screen; } **

return_type: void

user_defined_types: struct Client { unsigned int window; unsigned int parent; unsigned int trans; struct Client *next; struct Client *revert; int x; int y; int dx; int dy; int border; struct xcb_size_hints_t size; int min_dx; int min_dy; int state; int init; int reparenting; int is9term; int hold; int proto; char *label; char *instance; char *class; char *name; char *iconname; unsigned int cmap; int ncmapwins; unsigned int *cmapwins; unsigned int *wmcmaps; struct ScreenInfo *screen; }


getclient

decompiled_code:
__int64 __fastcall getclient(int a1, int a2)
{
__int64 result; // rax
__int64 v3; // rdx

if ( !a1 )
return 0LL;
if ( getscreen() )
return 0LL;
result = clients;
if ( !clients )
{
LABEL_12:
if ( a2 )
{
result = xalloc(232LL);
v3 = clients;
*(_DWORD *)result = a1;
*(_DWORD *)(result + 132) = 0;
*(_QWORD *)(result + 16) = v3;
clients = result;
return result;
}
return 0LL;
}
while ( *(_DWORD *)result != a1 && *(_DWORD *)(result + 4) != a1 )
{
result = *(_QWORD *)(result + 16);
if ( !result )
goto LABEL_12;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(int a1, int a2)
{
__int64 result; // rax
__int64 v3; // rdx

if ( !a1 )
return 0LL;
if ( getscreen() )
return 0LL;
result = clients;
if ( !clients )
{
LABEL_12:
if ( a2 )
{
result = xalloc(232LL);
v3 = clients;
*(_DWORD *)result = a1;
*(_DWORD *)(result + 132) = 0;
*(_QWORD *)(result + 16) = v3;
clients = result;
return result;
}
return 0LL;
}
while ( *(_DWORD *)result != a1 && *(_DWORD *)(result + 4) != a1 )
{
result = *(_QWORD *)(result + 16);
if ( !result )
goto LABEL_12;
}
return result;
}

original_code:
Client * getclient(xcb_window_t w, int create)
{
    Client *c = ((void *)0);
    if (w == 0 || getscreen(w))
        return 0;
    for (c = clients; c; c = c->next)
        if (c->window == w || c->parent == w)
            return c;
    if (create) {
        c = xalloc(sizeof(Client));
        c->window = w;
        c->state = XCB_ICCCM_WM_STATE_WITHDRAWN;
        c->next = clients;
        clients = c;
    }
    return c;
}

canonical_original_code:
struct Client *getclient(unsigned int w, int create)
{
    struct Client *c = ((void *)0);
    if (w == 0 || getscreen(w))
        return 0;
    for (c = clients; c; c = c->next)
        if (c->window == w || c->parent == w)
            return c;
    if (create) {
        c = xalloc(sizeof(Client));
        c->window = w;
        c->state = XCB_ICCCM_WM_STATE_WITHDRAWN;
        c->next = clients;
        clients = c;
    }
    return c;
}

variable_types: create int

variable_types: struct Client { unsigned int window; unsigned int parent; unsigned int trans; struct Client *next; struct Client *revert; int x; int y; int dx; int dy; int border; struct xcb_size_hints_t { unsigned int flags; int x; int width; int min_width; int max_width; int width_inc; int min_aspect_num; int max_aspect_num; int base_width; unsigned int win_gravity; } size; int min_dx; int min_dy; int state; int init; int reparenting; int is9term; int hold; int proto; char *label; char *instance; char *class; char *name; char *iconname; unsigned int cmap; int ncmapwins; unsigned int *cmapwins; unsigned int *wmcmaps; struct ScreenInfo { int num; unsigned int root; unsigned int menuwin; unsigned int def_cmap; unsigned int gc; unsigned int black; unsigned int white; int min_cmaps; unsigned int target; unsigned int sweep0; unsigned int boxcurs; unsigned int arrow; unsigned int root_pixmap; char display[256]; } *screen; } *


rmclient

decompiled_code:
void __fastcall rmclient(void *ptr)
{
__int64 v1; // rdx
void *v3; // rax
__int64 v4; // rdx
void *v5; // rax
xcb_window_t v6; // esi
bool v7; // zf
void *v8; // rdi
void *v9; // rdi
void *v10; // rdi
void *v11; // rdi
__int64 v12; // rdi

if ( ptr )
{
v1 = current;
if ( current )
{
while ( 1 )
{
v3 = *(void **)(v1 + 24);
if ( !v3 )
break;
if ( v3 == ptr )
{
v3 = (void *)*((_QWORD *)ptr + 3);
*(_QWORD *)(v1 + 24) = v3;
if ( !v3 )
break;
}
v1 = (__int64)v3;
}
}
v4 = clients;
if ( (void *)clients == ptr )
{
v4 = *((_QWORD *)ptr + 2);
clients = v4;
}
if ( v4 )
{
while ( 1 )
{
v5 = *(void **)(v4 + 16);
if ( !v5 )
break;
if ( v5 == ptr )
{
v5 = (void *)*((_QWORD *)ptr + 2);
*(_QWORD *)(v4 + 16) = v5;
if ( !v5 )
break;
}
v4 = (__int64)v5;
}
}
if ( *((_DWORD *)ptr + 33) == 3 )
unhidec(ptr, 0LL);
v6 = *((_DWORD *)ptr + 1);
if ( v6 != *(_DWORD *)(*((_QWORD *)ptr + 28) + 4LL) )
xcb_destroy_window(dpy, v6);
v7 = current == (_QWORD)ptr;
*(_QWORD *)ptr = 0LL;
if ( v7 )
{
v12 = *((_QWORD *)ptr + 3);
current = v12;
if ( v12 )
{
if ( *(_QWORD *)(v12 + 224) != *((_QWORD *)ptr + 28) )
{
cmapnofocus(*((_QWORD *)ptr + 28));
v12 = current;
}
setactive((unsigned int *)v12, 1);
}
else
{
nofocus();
}
}
v8 = (void *)*((_QWORD *)ptr + 21);
if ( v8 )
free(v8);
v9 = (void *)*((_QWORD *)ptr + 22);
if ( v9 )
free(v9);
v10 = (void *)*((_QWORD *)ptr + 23);
if ( v10 )
free(v10);
v11 = (void *)*((_QWORD *)ptr + 24);
if ( v11 )
free(v11);
if ( *((_DWORD *)ptr + 51) )
{
free(*((void **)ptr + 26));
free(*((void **)ptr + 27));
}
free(ptr);
}
}

canonical_decompiled_code:
void __fastcall func6(void *ptr)
{
__int64 v1; // rdx
void *v3; // rax
__int64 v4; // rdx
void *v5; // rax
xcb_window_t v6; // esi
bool v7; // zf
void *v8; // rdi
void *v9; // rdi
void *v10; // rdi
void *v11; // rdi
__int64 v12; // rdi

if ( ptr )
{
v1 = current;
if ( current )
{
while ( 1 )
{
v3 = *(void **)(v1 + 24);
if ( !v3 )
break;
if ( v3 == ptr )
{
v3 = (void *)*((_QWORD *)ptr + 3);
*(_QWORD *)(v1 + 24) = v3;
if ( !v3 )
break;
}
v1 = (__int64)v3;
}
}
v4 = clients;
if ( (void *)clients == ptr )
{
v4 = *((_QWORD *)ptr + 2);
clients = v4;
}
if ( v4 )
{
while ( 1 )
{
v5 = *(void **)(v4 + 16);
if ( !v5 )
break;
if ( v5 == ptr )
{
v5 = (void *)*((_QWORD *)ptr + 2);
*(_QWORD *)(v4 + 16) = v5;
if ( !v5 )
break;
}
v4 = (__int64)v5;
}
}
if ( *((_DWORD *)ptr + 33) == 3 )
unhidec(ptr, 0LL);
v6 = *((_DWORD *)ptr + 1);
if ( v6 != *(_DWORD *)(*((_QWORD *)ptr + 28) + 4LL) )
xcb_destroy_window(dpy, v6);
v7 = current == (_QWORD)ptr;
*(_QWORD *)ptr = 0LL;
if ( v7 )
{
v12 = *((_QWORD *)ptr + 3);
current = v12;
if ( v12 )
{
if ( *(_QWORD *)(v12 + 224) != *((_QWORD *)ptr + 28) )
{
cmapnofocus(*((_QWORD *)ptr + 28));
v12 = current;
}
func1((unsigned int *)v12, 1);
}
else
{
func3();
}
}
v8 = (void *)*((_QWORD *)ptr + 21);
if ( v8 )
free(v8);
v9 = (void *)*((_QWORD *)ptr + 22);
if ( v9 )
free(v9);
v10 = (void *)*((_QWORD *)ptr + 23);
if ( v10 )
free(v10);
v11 = (void *)*((_QWORD *)ptr + 24);
if ( v11 )
free(v11);
if ( *((_DWORD *)ptr + 51) )
{
free(*((void **)ptr + 26));
free(*((void **)ptr + 27));
}
free(ptr);
}
}

original_code:
void rmclient(Client *c)
{
    Client *cc;
    if (!c) {
        ;
        return;
    }
    for (cc = current; cc && cc->revert; cc = cc->revert)
        if (cc->revert == c)
            cc->revert = cc->revert->revert;
    if (c == clients)
        clients = c->next;
    for (cc = clients; cc && cc->next; cc = cc->next)
        if (cc->next == c)
            cc->next = cc->next->next;
    if (((c)->state == XCB_ICCCM_WM_STATE_ICONIC))
        unhidec(c, 0);
    if (c->parent != c->screen->root)
        xcb_destroy_window(dpy, c->parent);
    c->parent = c->window = 0L;
    if (current == c) {
        current = c->revert;
        if (current == 0)
            nofocus();
        else {
            if (current->screen != c->screen)
                cmapnofocus(c->screen);
            setactive(current, 1);
        }
    }
    if (c->instance)
        free(c->instance);
    if (c->class)
        free(c->class);
    if (c->name)
        free(c->name);
    if (c->iconname)
        free(c->iconname);
    if (c->ncmapwins != 0) {
        free((char *)c->cmapwins);
        free((char *)c->wmcmaps);
    }
    memset(c, 0, sizeof(Client));
    free(c);
}

canonical_original_code:
void rmclient(struct Client *c)
{
    struct Client *cc;
    if (!c) {
        ;
        return;
    }
    for (cc = current; cc && cc->revert; cc = cc->revert)
        if (cc->revert == c)
            cc->revert = cc->revert->revert;
    if (c == clients)
        clients = c->next;
    for (cc = clients; cc && cc->next; cc = cc->next)
        if (cc->next == c)
            cc->next = cc->next->next;
    if (((c)->state == XCB_ICCCM_WM_STATE_ICONIC))
        unhidec(c, 0);
    if (c->parent != c->screen->root)
        xcb_destroy_window(dpy, c->parent);
    c->parent = c->window = 0L;
    if (current == c) {
        current = c->revert;
        if (current == 0)
            nofocus();
        else {
            if (current->screen != c->screen)
                cmapnofocus(c->screen);
            setactive(current, 1);
        }
    }
    if (c->instance)
        free(c->instance);
    if (c->class)
        free(c->class);
    if (c->name)
        free(c->name);
    if (c->iconname)
        free(c->iconname);
    if (c->ncmapwins != 0) {
        free((char *)c->cmapwins);
        free((char *)c->wmcmaps);
    }
    memset(c, 0, sizeof(Client));
    free(c);
}

user_defined_types: struct xcb_size_hints_t { unsigned int flags; int x; int width; int min_width; int max_width; int width_inc; int min_aspect_num; int max_aspect_num; int base_width; unsigned int win_gravity; }

user_defined_types: struct ScreenInfo { int num; unsigned int root; unsigned int menuwin; unsigned int def_cmap; unsigned int gc; unsigned int black; unsigned int white; int min_cmaps; unsigned int target; unsigned int sweep0; unsigned int boxcurs; unsigned int arrow; unsigned int root_pixmap; char display[256]; }


repo: jwerle/liburl

decompiled_code:
__int64 __fastcall url_percent_encode_byte(__int64 a1, unsigned __int64 a2, __int64 a3)
{
char v3; // al
char v4; // di
char v6[72]; // [rsp+0h] [rbp-48h] BYREF

v3 = a1;
if ( (_DWORD)a2 == 3 )
{
a3 = (unsigned int)a1;
LOBYTE(a2) = (unsigned __int8)(a1 - 33) > 0x5Du;
if ( (unsigned __int8)(a1 - 34) <= 0x3Eu )
{
a2 = (0x4400000074002003uLL >> ((unsigned __int8)a1 - 34)) & 1 | (unsigned int)a2;
if ( (_BYTE)a2 )
goto LABEL_5;
return url_percent_encode_byte_cold(a1, a2, a3);
}
goto LABEL_11;
}
if ( (int)a2 > 3 )
{
if ( (_DWORD)a2 != 4 )
return url_percent_encode_byte_cold(a1, a2, a3);
a3 = (unsigned int)a1;
LOBYTE(a2) = (unsigned __int8)(a1 - 33) > 0x5Du;
if ( (unsigned __int8)(a1 - 34) <= 0x3Eu )
{
a2 = (0x4400000075002003uLL >> ((unsigned __int8)a1 - 34)) & 1 | (unsigned int)a2;
if ( (_BYTE)a2 )
goto LABEL_5;
return url_percent_encode_byte_cold(a1, a2, a3);
}
LABEL_11:
if ( (_BYTE)a2 )
goto LABEL_5;
return url_percent_encode_byte_cold(a1, a2, a3);
}
if ( (_DWORD)a2 != 1 )
{
if ( (_DWORD)a2 != 2 )
return url_percent_encode_byte_cold(a1, a2, a3);
a3 = (unsigned int)a1;
LOBYTE(a2) = (unsigned __int8)(a1 - 33) > 0x5Du;
if ( (unsigned __int8)(a1 - 34) <= 0x3Eu )
a2 = (0x4000000034000003uLL >> ((unsigned __int8)a1 - 34)) & 1 | (unsigned int)a2;
goto LABEL_11;
}
a3 = (unsigned int)a1;
if ( (unsigned __int8)(a1 - 32) <= 0x5Eu )
return url_percent_encode_byte_cold(a1, a2, a3);
LABEL_5:
v4 = a1 & 0xDF;
if ( (unsigned __int8)(a3 - 65) < 0x3Au )
v3 = v4;
sprintf(v6, "%s%02X", &LC0, (unsigned int)v3);
return (int)strdup(v6);
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, unsigned __int64 a2, __int64 a3)
{
char v3; // al
char v4; // di
char v6[72]; // [rsp+0h] [rbp-48h] BYREF

v3 = a1;
if ( (_DWORD)a2 == 3 )
{
a3 = (unsigned int)a1;
LOBYTE(a2) = (unsigned __int8)(a1 - 33) > 0x5Du;
if ( (unsigned __int8)(a1 - 34) <= 0x3Eu )
{
a2 = (0x4400000074002003uLL >> ((unsigned __int8)a1 - 34)) & 1 | (unsigned int)a2;
if ( (_BYTE)a2 )
goto LABEL_5;
return func2(a1, a2, a3);
}
goto LABEL_11;
}
if ( (int)a2 > 3 )
{
if ( (_DWORD)a2 != 4 )
return func2(a1, a2, a3);
a3 = (unsigned int)a1;
LOBYTE(a2) = (unsigned __int8)(a1 - 33) > 0x5Du;
if ( (unsigned __int8)(a1 - 34) <= 0x3Eu )
{
a2 = (0x4400000075002003uLL >> ((unsigned __int8)a1 - 34)) & 1 | (unsigned int)a2;
if ( (_BYTE)a2 )
goto LABEL_5;
return func2(a1, a2, a3);
}
LABEL_11:
if ( (_BYTE)a2 )
goto LABEL_5;
return func2(a1, a2, a3);
}
if ( (_DWORD)a2 != 1 )
{
if ( (_DWORD)a2 != 2 )
return func2(a1, a2, a3);
a3 = (unsigned int)a1;
LOBYTE(a2) = (unsigned __int8)(a1 - 33) > 0x5Du;
if ( (unsigned __int8)(a1 - 34) <= 0x3Eu )
a2 = (0x4000000034000003uLL >> ((unsigned __int8)a1 - 34)) & 1 | (unsigned int)a2;
goto LABEL_11;
}
a3 = (unsigned int)a1;
if ( (unsigned __int8)(a1 - 32) <= 0x5Eu )
return func2(a1, a2, a3);
LABEL_5:
v4 = a1 & 0xDF;
if ( (unsigned __int8)(a3 - 65) < 0x3Au )
v3 = v4;
sprintf(v6, "%s%02X", &LC0, (unsigned int)v3);
return (int)strdup(v6);
}

variable_types: byte char

variable_types: set int

variable_types:
enc
char [64]

variable_types:
c
char *

return_type: char *


decompiled_code:
__int64 __fastcall url_percent_encode(const char *a1, unsigned int a2)
{
const char *v2; // rbx
int v3; // er13
__int64 v4; // rdx
char *v5; // rbp
__int64 v6; // r13
__int64 v7; // rdi
const char *v8; // rax
signed int v9; // ebx

v2 = a1;
v3 = strlen(a1);
v5 = (char *)malloc(v3);
if ( v3 > 0 )
{
v6 = (__int64)&a1[v3 - 1 + 1];
do
{
v7 = (unsigned int)*v2++;
v8 = (const char *)url_percent_encode_byte(v7, a2, v4);
strcat(v5, v8);
}
while ( v2 != (const char *)v6 );
}
v9 = (unsigned int)strdup(v5);
free(v5);
return v9;
}

canonical_decompiled_code:
__int64 __fastcall func1(const char *a1, unsigned int a2)
{
const char *v2; // rbx
int v3; // er13
__int64 v4; // rdx
char *v5; // rbp
__int64 v6; // r13
__int64 v7; // rdi
const char *v8; // rax
signed int v9; // ebx

v2 = a1;
v3 = strlen(a1);
v5 = (char *)malloc(v3);
if ( v3 > 0 )
{
v6 = (__int64)&a1[v3 - 1 + 1];
do
{
v7 = (unsigned int)*v2++;
v8 = (const char *)func0(v7, a2, v4);
strcat(v5, v8);
}
while ( v2 != (const char *)v6 );
}
v9 = (unsigned int)strdup(v5);
free(v5);
return v9;
}

original_code:
char *
url_percent_encode (char *str, int set) {
  char *ret = ((void *)0);
  char *byte = ((void *)0);
  char *bytes = ((void *)0);
  int len = strlen(str);
  int i = 0;
  bytes = malloc(sizeof(char) * len);
  for (; i < len; ++i) {
    byte = url_percent_encode_byte(str[i], set);
    strcat(bytes, byte);
  }
  ret = strdup(bytes);
  free(bytes);
  return ret;
}

canonical_original_code:
char *url_percent_encode(char *str, int set) {
  char *ret = ((void *)0);
  char *byte = ((void *)0);
  char *bytes = ((void *)0);
  int len = strlen(str);
  int i = 0;
  bytes = malloc(sizeof(char) * len);
  for (; i < len; ++i) {
    byte = url_percent_encode_byte(str[i], set);
    strcat(bytes, byte);
  }
  ret = strdup(bytes);
  free(bytes);
  return ret;
}

variable_types:
str
char *

variable_types:
ret
char *

variable_types:
byte
char *

variable_types:
bytes
char *

variable_types: len int

variable_types: i int


decompiled_code:
_BOOL8 __fastcall is_url_codepoint(char a1)
{
return a1 >= 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func0(char a1)
{
return a1 >= 0;
}

variable_types: c char

return_type: int


decompiled_code:
__int64 __fastcall url_parse_host(char *s)
{
__int64 v1; // rbx
signed int v3; // eax

if ( *s != 91 )
return 0LL;
v1 = (int)strlen(s);
if ( s[v1 - 1] != 93 )
return 0LL;
v3 = (unsigned int)strdup(s);
*(_BYTE *)(v3 + v1) = 0;
return v3 + 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(char *s)
{
__int64 v1; // rbx
signed int v3; // eax

if ( *s != 91 )
return 0LL;
v1 = (int)strlen(s);
if ( s[v1 - 1] != 93 )
return 0LL;
v3 = (unsigned int)strdup(s);
*(_BYTE *)(v3 + v1) = 0;
return v3 + 1LL;
}

original_code:
char *
url_parse_host (const char *url) {
  char *host = ((void *)0);
  char *ret = ((void *)0);
  int l = (int) strlen(url);
  if (((void *)0) == url) {
    return ((void *)0);
  }
  if ('[' == url[0]) {
    if (']' != url[l-1]) {
      return ((void *)0);
    } else {
      ret = strdup(url);
      *ret++;
      ret[l-1] = '\0';
      return ret;
    }
  }
  return ((void *)0);
}

canonical_original_code:
char *url_parse_host(char *url) {
  char *host = ((void *)0);
  char *ret = ((void *)0);
  int l = (int) strlen(url);
  if (((void *)0) == url) {
    return ((void *)0);
  }
  if ('[' == url[0]) {
    if (']' != url[l-1]) {
      return ((void *)0);
    } else {
      ret = strdup(url);
      *ret++;
      ret[l-1] = '\0';
      return ret;
    }
  }
  return ((void *)0);
}

variable_types:
url
char *

variable_types:
host
char *

variable_types: l int


decompiled_code:
void **__fastcall url_relative_scheme(char *s1)
{
void **v1; // r12
size_t v2; // rbp

v1 = &url_relative_schemes;
v2 = strlen(s1);
while ( strncmp(s1, (const char *)*v1, v2) )
{
v1 += 2;
if ( v1 == &url_relative_schemes + 14 )
return 0LL;
}
return v1;
}

canonical_decompiled_code:
void **__fastcall func0(char *s1)
{
void **v1; // r12
size_t v2; // rbp

v1 = &url_relative_schemes;
v2 = strlen(s1);
while ( strncmp(s1, (const char *)*v1, v2) )
{
v1 += 2;
if ( v1 == &url_relative_schemes + 14 )
return 0LL;
}
return v1;
}

original_code:
char **
url_relative_scheme (const char *scheme) {
  int i = 0;
  int len = sizeof(_url_relative_schemes) / sizeof(_url_relative_schemes[0]);
  char **item;
  while (i < len && ((void *)0) != (item = _url_relative_schemes[i++])) {
    if (0 == strncmp(scheme, item[0], strlen(scheme))) {
      return item;
    }
  }
  return ((void *)0);
}

canonical_original_code:
char **url_relative_scheme(char *scheme) {
  int i = 0;
  int len = sizeof(_url_relative_schemes) / sizeof(_url_relative_schemes[0]);
  char **item;
  while (i < len && ((void *)0) != (item = _url_relative_schemes[i++])) {
    if (0 == strncmp(scheme, item[0], strlen(scheme))) {
      return item;
    }
  }
  return ((void *)0);
}

variable_types:
scheme
char *

variable_types:
item
char **

return_type: char **


original_code:
char *
utf8_decode (const char *str) {
  unsigned char buf[4096];
  unsigned char bp = 0;
  unsigned char cp = 0;
  unsigned char lower = 0x80;
  unsigned char upper = 0xBF;
  unsigned int b = 0;
  int i = 0;
  int n = 0;
  int seen = 0;
  int needed = 0;
  while ('\0' != (bp = str[i++])) {
    if ((*__errno_location ()) > 0) {
      return ((void *)0);
    }
    b = (unsigned int) bp;
    if (b == (-1)) {
      if (0 != needed) {
        needed = 0;
        (*__errno_location ()) = UTF8E_EOF_BYTES_NEEDED;
      }
      buf[n++] = (-1);
      continue;
    }
    if (0 == needed) {
      if ((b >= (unsigned int) 0x00 && b <= (unsigned int) 0x7F)) {
        buf[n++] = b;
        continue;
      }
      if (0 == (b >= (unsigned int) 0xC2 && b <= (unsigned int) 0xF4)) {
        (*__errno_location ()) = UTF8E_BYTE_RANGE;
        continue;
      }
      if ((b >= (unsigned int) 0xC2 && b <= (unsigned int) 0xDF)) {
        needed = 1;
        cp = b - 0xC0;
      }
      if ((b >= (unsigned int) 0xE0 && b <= (unsigned int) 0xEF)) {
        if (b == 0xE0) {
          lower = 0xA0;
        } else if (b == 0xED) {
          upper = 0x9F;
        }
        needed = 2;
        cp = b - 0xE0;
      }
      if ((b >= (unsigned int) 0xF0 && b <= (unsigned int) 0xF4)) {
        if (b == 0xF0) {
          lower = 0x90;
        } else if (b == 0xF4) {
          upper = 0x8F;
        }
        needed = 3;
        cp = b - 0xF0;
      }
      cp = cp * pow(64, needed);
      continue;
    }
    if (0 == (b >= (unsigned int) lower && b <= (unsigned int) upper)) {
      cp = 0;
      needed = 0;
      seen = 0;
      bp = str[--i];
      lower = 0x80;
      upper = 0xBF;
      (*__errno_location ()) = UTF8E_BYTE_BOUNDARY_RANGE;
      continue;
    }
    lower = 0x80;
    upper = 0xBF;
    seen++;
    cp += (b - 0x80) * pow(64, needed - seen);
    if (seen != needed) {
      continue;
    }
    buf[n++] = cp;
    cp = 0;
    needed = 0;
    seen = 0;
  }
  buf[n] = '\0';
  return strdup((char *) buf);
}

canonical_original_code:
char *utf8_decode(char *str) {
  unsigned char buf[4096];
  unsigned char bp = 0;
  unsigned char cp = 0;
  unsigned char lower = 0x80;
  unsigned char upper = 0xBF;
  unsigned int b = 0;
  int i = 0;
  int n = 0;
  int seen = 0;
  int needed = 0;
  while ('\0' != (bp = str[i++])) {
    if ((*__errno_location ()) > 0) {
      return ((void *)0);
    }
    b = (unsigned int) bp;
    if (b == (-1)) {
      if (0 != needed) {
        needed = 0;
        (*__errno_location ()) = UTF8E_EOF_BYTES_NEEDED;
      }
      buf[n++] = (-1);
      continue;
    }
    if (0 == needed) {
      if ((b >= (unsigned int) 0x00 && b <= (unsigned int) 0x7F)) {
        buf[n++] = b;
        continue;
      }
      if (0 == (b >= (unsigned int) 0xC2 && b <= (unsigned int) 0xF4)) {
        (*__errno_location ()) = UTF8E_BYTE_RANGE;
        continue;
      }
      if ((b >= (unsigned int) 0xC2 && b <= (unsigned int) 0xDF)) {
        needed = 1;
        cp = b - 0xC0;
      }
      if ((b >= (unsigned int) 0xE0 && b <= (unsigned int) 0xEF)) {
        if (b == 0xE0) {
          lower = 0xA0;
        } else if (b == 0xED) {
          upper = 0x9F;
        }
        needed = 2;
        cp = b - 0xE0;
      }
      if ((b >= (unsigned int) 0xF0 && b <= (unsigned int) 0xF4)) {
        if (b == 0xF0) {
          lower = 0x90;
        } else if (b == 0xF4) {
          upper = 0x8F;
        }
        needed = 3;
        cp = b - 0xF0;
      }
      cp = cp * pow(64, needed);
      continue;
    }
    if (0 == (b >= (unsigned int) lower && b <= (unsigned int) upper)) {
      cp = 0;
      needed = 0;
      seen = 0;
      bp = str[--i];
      lower = 0x80;
      upper = 0xBF;
      (*__errno_location ()) = UTF8E_BYTE_BOUNDARY_RANGE;
      continue;
    }
    lower = 0x80;
    upper = 0xBF;
    seen++;
    cp += (b - 0x80) * pow(64, needed - seen);
    if (seen != needed) {
      continue;
    }
    buf[n++] = cp;
    cp = 0;
    needed = 0;
    seen = 0;
  }
  buf[n] = '\0';
  return strdup((char *) buf);
}

variable_types:
buf
unsigned char [4096]

variable_types:
bp
unsigned char

variable_types:
cp
unsigned char

variable_types:
lower
unsigned char

variable_types:
upper
unsigned char

variable_types:
b
unsigned int

variable_types: n int

variable_types: seen int

variable_types: needed int


original_code:
char *
utf8_encode (const char *str) {
  unsigned char buf[4096];
  unsigned char cp = 0;
  unsigned char b = 0;
  unsigned int c = 0;
  int i = 0;
  int n = 0;
  int count = 0;
  int offset = 0;
  while ('\0' != (cp = (str[i++]))) {
    if ((*__errno_location ()) > 0) {
      return ((void *)0);
    }
    c = (unsigned int) cp;
    if ((c >= (unsigned int) 0xD800 && c <= (unsigned int) 0xDFFF)) {
      (*__errno_location ()) = UTF8E_CODE_POINT_OOB;
      break;
    }
    if ((-1) == c) {
      buf[n++] = (-1);
      break;
    }
    if ((c >= (unsigned int) 0x0000 && c <= (unsigned int) 0x07F)) {
      buf[n++] = c;
      continue;
    }
    if ((c >= (unsigned int) 0x0080 && c <= (unsigned int) 0x07FF)) {
      count = 1;
      offset = 0xC0;
    } else if ((c >= (unsigned int) 0x0800 && c <= (unsigned int) 0xFFFF)) {
      count = 2;
      offset = 0xE0;
    } else if ((c >= (unsigned int) 0x10000 && c <= (unsigned int) 0x10FFFF)) {
      count = 3;
      offset = 0xF0;
    }
    buf[n++] = (c/pow(64, count)) + offset;
    while (count > 0) {
      b = c/pow(64, count - 1);
      buf[n++] = 0x80 + (b % 64);
      count--;
    }
  }
  buf[n] = '\0';
  return strdup((char *)buf);
}

canonical_original_code:
char *utf8_encode(char *str) {
  unsigned char buf[4096];
  unsigned char cp = 0;
  unsigned char b = 0;
  unsigned int c = 0;
  int i = 0;
  int n = 0;
  int count = 0;
  int offset = 0;
  while ('\0' != (cp = (str[i++]))) {
    if ((*__errno_location ()) > 0) {
      return ((void *)0);
    }
    c = (unsigned int) cp;
    if ((c >= (unsigned int) 0xD800 && c <= (unsigned int) 0xDFFF)) {
      (*__errno_location ()) = UTF8E_CODE_POINT_OOB;
      break;
    }
    if ((-1) == c) {
      buf[n++] = (-1);
      break;
    }
    if ((c >= (unsigned int) 0x0000 && c <= (unsigned int) 0x07F)) {
      buf[n++] = c;
      continue;
    }
    if ((c >= (unsigned int) 0x0080 && c <= (unsigned int) 0x07FF)) {
      count = 1;
      offset = 0xC0;
    } else if ((c >= (unsigned int) 0x0800 && c <= (unsigned int) 0xFFFF)) {
      count = 2;
      offset = 0xE0;
    } else if ((c >= (unsigned int) 0x10000 && c <= (unsigned int) 0x10FFFF)) {
      count = 3;
      offset = 0xF0;
    }
    buf[n++] = (c/pow(64, count)) + offset;
    while (count > 0) {
      b = c/pow(64, count - 1);
      buf[n++] = 0x80 + (b % 64);
      count--;
    }
  }
  buf[n] = '\0';
  return strdup((char *)buf);
}

variable_types:
str
char *

variable_types:
b
unsigned char

variable_types:
c
unsigned int

variable_types: count int

variable_types: offset int


repo: jwittkoski/GenericTunerPlugin

decompiled_code:
void *__fastcall alloc_string(void *src)
{
size_t v1; // r12
void *v2; // rax

if ( !src )
return 0LL;
v1 = strlen((const char *)src) + 1;
v2 = malloc(v1);
return memcpy(v2, src, v1);
}

canonical_decompiled_code:
void *__fastcall func1(void *src)
{
size_t v1; // r12
void *v2; // rax

if ( !src )
return 0LL;
v1 = strlen((const char *)src) + 1;
v2 = malloc(v1);
return memcpy(v2, src, v1);
}

original_code:
char *alloc_string(char *str) {
    if ( str == ((void *)0) ) return ((void *)0);
    char *newStr = malloc(strlen(str)+1);
    strcpy((char *)newStr, (const char *)str);
    return newStr;
}

canonical_original_code:
char *alloc_string(char *str) {
    if ( str == ((void *)0) ) return ((void *)0);
    char *newStr = malloc(strlen(str)+1);
    strcpy((char *)newStr, (char *)str);
    return newStr;
}

variable_types:
newStr
char *


NeedCarrierFrequency

decompiled_code:
// attributes: thunk
__int64 NeedCarrierFrequency()
{
return NeedBitrate_localalias();
}

canonical_decompiled_code:
__int64 func3()
{
return func2();
}

original_code:
int NeedCarrierFrequency() {
    return 0;
}


DeviceName

decompiled_code:
const char *DeviceName()
{
return "Generic Tuner";
}

canonical_decompiled_code:
const char *func4()
{
return "Generic Tuner";
}

original_code:
const char* DeviceName() {
    return "Generic Tuner";
}


OpenDevice

decompiled_code:
__int64 __fastcall OpenDevice(double a1)
{
double v1; // xmm0_8

v1 = log(a1);
log(v1);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func5(double a1)
{
double v1; // xmm0_8

v1 = func0(a1);
func0(v1);
return 1LL;
}

original_code:
int OpenDevice(int ComPort) {
    _log(6, "%s, Version %s", "Generic Tuner", "1.4.0");;
    _log(7, "OpenDevice: %d", ComPort);;
    return 1;
}

variable_types: ComPort int


CloseDevice

decompiled_code:
void __fastcall CloseDevice(double x)
{
log(x);
}

canonical_decompiled_code:
void __fastcall func6(double x)
{
func0(x);
}

original_code:
void CloseDevice(int devHandle) {
    _log(7, "CloseDevice: %d", devHandle);;
}

variable_types: devHandle int


FindCarrierFrequency

decompiled_code:
// attributes: thunk
__int64 FindCarrierFrequency()
{
return FindBitRate_localalias();
}

canonical_decompiled_code:
__int64 func8()
{
return func7();
}

original_code:
unsigned long FindCarrierFrequency(int devHandle) {
    return 0;
}

return_type: unsigned long


AddRemote

decompiled_code:
__int64 __fastcall AddRemote(__int64 a1, __int64 *a2)
{
__int64 result; // rax
__int64 v3; // rdx

result = *a2;
if ( *a2 )
{
do
{
v3 = result;
result = *(_QWORD *)(result + 32);
}
while ( result );
*(_QWORD *)(v3 + 32) = a1;
*(_QWORD *)(a1 + 32) = 0LL;
}
else
{
*a2 = a1;
*(_QWORD *)(a1 + 32) = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1, __int64 *a2)
{
__int64 result; // rax
__int64 v3; // rdx

result = *a2;
if ( *a2 )
{
do
{
v3 = result;
result = *(_QWORD *)(result + 32);
}
while ( result );
*(_QWORD *)(v3 + 32) = a1;
*(_QWORD *)(a1 + 32) = 0LL;
}
else
{
*a2 = a1;
*(_QWORD *)(a1 + 32) = 0LL;
}
return result;
}

original_code:
void AddRemote(struct remote *Remote, struct remote **head) {
    struct remote *Temp;
    if (!(*head)) {
        *head = Remote;
        (*head)->next = ((void *)0);
    } else
    {
        Temp = *head;
        while (Temp->next) {
            Temp = Temp->next;
        }
        Temp->next = Remote;
        Remote->next = ((void *)0);
    }
}

variable_types: struct remote { unsigned char *name; unsigned long carrier_freq; unsigned int bit_time; struct command { unsigned char *name; struct pattern { unsigned int bit_length; unsigned int length; char r_flag; unsigned char *bytes; struct pattern *next; } *pattern; struct command *next; } *command; struct remote *next; } *

variable_types:
head
struct remote **

user_defined_types: struct remote { unsigned char *name; unsigned long carrier_freq; unsigned int bit_time; struct command *command; struct remote *next; }

user_defined_types: struct command { unsigned char *name; struct pattern *pattern; struct command *next; }


AddCommand

decompiled_code:
__int64 __fastcall AddCommand(__int64 a1, __int64 *a2)
{
__int64 result; // rax
__int64 v3; // rdx

result = *a2;
if ( *a2 )
{
do
{
v3 = result;
result = *(_QWORD *)(result + 16);
}
while ( result );
*(_QWORD *)(v3 + 16) = a1;
*(_QWORD *)(a1 + 16) = 0LL;
}
else
{
*a2 = a1;
*(_QWORD *)(a1 + 16) = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1, __int64 *a2)
{
__int64 result; // rax
__int64 v3; // rdx

result = *a2;
if ( *a2 )
{
do
{
v3 = result;
result = *(_QWORD *)(result + 16);
}
while ( result );
*(_QWORD *)(v3 + 16) = a1;
*(_QWORD *)(a1 + 16) = 0LL;
}
else
{
*a2 = a1;
*(_QWORD *)(a1 + 16) = 0LL;
}
return result;
}

original_code:
void AddCommand(struct command *Command, struct command **Command_List) {
    struct command *Temp;
    if (!(*Command_List)) {
        (*Command_List) = Command;
        (*Command_List)->next = ((void *)0);
    } else {
        Temp = (*Command_List);
        while (Temp->next) {
            Temp = Temp->next;
        }
        Temp->next = Command;
        Command->next = ((void *)0);
    }
}

variable_types: struct command { unsigned char *name; struct pattern { unsigned int bit_length; unsigned int length; char r_flag; unsigned char *bytes; struct pattern *next; } *pattern; struct command *next; } *


chomp

decompiled_code:
__int64 __fastcall chomp(const char *a1)
{
__int64 result; // rax
const char *v2; // rbx

result = (unsigned int)strlen(a1) - 1;
if ( (int)result >= 0 )
{
result = (int)result;
v2 = &a1[(int)result];
if ( *v2 == 10 )
*v2 = 0;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func11(const char *a1)
{
__int64 result; // rax
const char *v2; // rbx

result = (unsigned int)strlen(a1) - 1;
if ( (int)result >= 0 )
{
result = (int)result;
v2 = &a1[(int)result];
if ( *v2 == 10 )
*v2 = 0;
}
return result;
}

original_code:
void chomp (char* s) {
    int end = strlen(s) - 1;
    if ( end >= 0 && s[end] == '\n' )
        s[end] = '\0';
}

canonical_original_code:
void chomp(char *s) {
    int end = strlen(s) - 1;
    if ( end >= 0 && s[end] == '\n' )
        s[end] = '\0';
}

variable_types:
s
char *

variable_types: end int


InitDevice

decompiled_code:
void __fastcall InitDevice(double x)
{
log(x);
}

canonical_decompiled_code:
void __fastcall func13(double x)
{
func0(x);
}

original_code:
void InitDevice() {
    _log(7, "InitDevice");;
}


RecordCommand

decompiled_code:
__int64 RecordCommand()
{
return 0LL;
}

canonical_decompiled_code:
__int64 func14()
{
return 0LL;
}

original_code:
command* RecordCommand(int devHandle, unsigned char *Name) {
    return 0;
}

canonical_original_code:
struct command *RecordCommand(int devHandle, unsigned char *Name) {
    return 0;
}

variable_types:
Name
unsigned char *

return_type: struct command { unsigned char *name; struct pattern { unsigned int bit_length; unsigned int length; char r_flag; unsigned char *bytes; struct pattern *next; } *pattern; struct command *next; } *


PlayCommand

decompiled_code:
void __fastcall PlayCommand(double a1, __int64 a2, const char **a3, const char *a4)
{
double v4; // xmm0_8
double v5; // xmm0_8
char v6[1048]; // [rsp-418h] [rbp-418h] BYREF

if ( a3 )
{
snprintf(v6, 0x400uLL, "%s SEND %s %s", "/opt/sagetv/server/gentuner", *a3, a4);
v4 = log(a1);
v5 = log(v4);
system(v6);
log(v5);
}
}

canonical_decompiled_code:
void __fastcall func15(double a1, __int64 a2, const char **a3, const char *a4)
{
double v4; // xmm0_8
double v5; // xmm0_8
char v6[1048]; // [rsp-418h] [rbp-418h] BYREF

if ( a3 )
{
snprintf(v6, 0x400uLL, "%s SEND %s %s", "/opt/sagetv/server/gentuner", *a3, a4);
v4 = func0(a1);
v5 = func0(v4);
system(v6);
func0(v5);
}
}

original_code:
void PlayCommand(int devHandle, remote *remote, unsigned char *name, int tx_repeats) {
    char cmd[1024];
    if ( ! remote ) {
        return;
    }
    snprintf(cmd, sizeof(cmd), "%s SEND %s %s", "/opt/sagetv/server/gentuner", remote->name, name);
    _log(7, "PlayCommand: Using command: %s", cmd);;
    _log(6, "PlayCommand: Remote: %s, Key: %s", remote->name, name);;
    if ( system(cmd) != 0 ) {
        _log(3, "PlayCommand: Failed to execute SEND command: %s", cmd);;
    } else {
        _log(7, "PlayCommand: Executed SEND command without error: %s", cmd);;
    }
}

canonical_original_code:
void PlayCommand(int devHandle, struct remote *remote, unsigned char *name, int tx_repeats) {
    char cmd[1024];
    if ( ! remote ) {
        return;
    }
    snprintf(cmd, sizeof(cmd), "%s SEND %s %s", "/opt/sagetv/server/gentuner", remote->name, name);
    _log(7, "PlayCommand: Using command: %s", cmd);;
    _log(6, "PlayCommand: Remote: %s, Key: %s", remote->name, name);;
    if ( system(cmd) != 0 ) {
        _log(3, "PlayCommand: Failed to execute SEND command: %s", cmd);;
    } else {
        _log(7, "PlayCommand: Executed SEND command without error: %s", cmd);;
    }
}

variable_types:
name
unsigned char *

variable_types:
cmd
char [1024]

user_defined_types: struct pattern { unsigned int bit_length; unsigned int length; char r_flag; unsigned char *bytes; struct pattern *next; }


FreeRemotes

original_code:
void FreeRemotes(remote **head) {
    _log(7, "FreeRemotes");;
    command *Temp_Com;
    remote *Temp_Rem;
    pattern *temp_pat;
    while (*head) {
        Temp_Rem = *head;
        Temp_Com = (*head)->command;
        while (Temp_Com) {
            (*head)->command = (*head)->command->next;
            temp_pat = Temp_Com->pattern;
            while (temp_pat) {
                Temp_Com->pattern = Temp_Com->pattern->next;
                free(temp_pat->bytes);
                free(temp_pat);
                temp_pat = Temp_Com->pattern;
            }
            free(Temp_Com->name);
            free(Temp_Com);
            Temp_Com = (*head)->command;
        }
        (*head) = (*head)->next;
        free(Temp_Rem->name);
        free(Temp_Rem);
    }
    *head = ((void *)0);
}

canonical_original_code:
void FreeRemotes(struct remote **head) {
    _log(7, "FreeRemotes");;
    struct command *Temp_Com;
    struct remote *Temp_Rem;
    struct pattern *temp_pat;
    while (*head) {
        Temp_Rem = *head;
        Temp_Com = (*head)->command;
        while (Temp_Com) {
            (*head)->command = (*head)->command->next;
            temp_pat = Temp_Com->pattern;
            while (temp_pat) {
                Temp_Com->pattern = Temp_Com->pattern->next;
                free(temp_pat->bytes);
                free(temp_pat);
                temp_pat = Temp_Com->pattern;
            }
            free(Temp_Com->name);
            free(Temp_Com);
            Temp_Com = (*head)->command;
        }
        (*head) = (*head)->next;
        free(Temp_Rem->name);
        free(Temp_Rem);
    }
    *head = ((void *)0);
}

variable_types: struct remote { unsigned char *name; unsigned long carrier_freq; unsigned int bit_time; struct command { unsigned char *name; struct pattern { unsigned int bit_length; unsigned int length; char r_flag; unsigned char *bytes; struct pattern *next; } *pattern; struct command *next; } *command; struct remote *next; } **


DumpRemotes

decompiled_code:
int __fastcall DumpRemotes(__int64 a1)
{
__int64 v1; // r12
__int64 i; // rbx
int result; // eax

if ( a1 )
{
v1 = a1;
do
{
printf("RemoteName: %s\n", *(const char **)v1);
for ( i = *(_QWORD *)(v1 + 24); i; i = *(_QWORD *)(i + 16) )
printf("CmdKey: %s\n", *(const char **)i);
result = putchar(10);
v1 = *(_QWORD *)(v1 + 32);
}
while ( v1 );
}
return result;
}

canonical_decompiled_code:
int __fastcall func17(__int64 a1)
{
__int64 v1; // r12
__int64 i; // rbx
int result; // eax

if ( a1 )
{
v1 = a1;
do
{
printf("RemoteName: %s\n", *(const char **)v1);
for ( i = *(_QWORD *)(v1 + 24); i; i = *(_QWORD *)(i + 16) )
printf("CmdKey: %s\n", *(const char **)i);
result = putchar(10);
v1 = *(_QWORD *)(v1 + 32);
}
while ( v1 );
}
return result;
}

original_code:
void DumpRemotes(remote *head) {
    command *chead = ((void *)0);
    while (head) {
        printf("RemoteName: %s\n", head->name);
        chead = head->command;
        while (chead) {
            printf("CmdKey: %s\n", chead->name);
            chead=chead->next;
        }
        printf("\n");
        head = head->next;
    }
}

canonical_original_code:
void DumpRemotes(struct remote *head) {
    struct command *chead = ((void *)0);
    while (head) {
        printf("RemoteName: %s\n", head->name);
        chead = head->command;
        while (chead) {
            printf("CmdKey: %s\n", chead->name);
            chead=chead->next;
        }
        printf("\n");
        head = head->next;
    }
}


MacroTune

decompiled_code:
double __fastcall MacroTune(double a1, __int64 a2, unsigned int a3)
{
double v3; // xmm0_8
double v4; // xmm0_8
char v6[1048]; // [rsp+0h] [rbp-418h] BYREF

snprintf(v6, 0x400uLL, "%s TUNE %s %d", "/opt/sagetv/server/gentuner", loadedDevName, a3);
v3 = log(a1);
v4 = log(v3);
system(v6);
return log(v4);
}

canonical_decompiled_code:
double __fastcall func19(double a1, __int64 a2, unsigned int a3)
{
double v3; // xmm0_8
double v4; // xmm0_8
char v6[1048]; // [rsp+0h] [rbp-418h] BYREF

snprintf(v6, 0x400uLL, "%s TUNE %s %d", "/opt/sagetv/server/gentuner", loadedDevName, a3);
v3 = func0(a1);
v4 = func0(v3);
system(v6);
return func0(v4);
}

original_code:
void MacroTune(int devHandle, int channel) {
    char cmd[1024];
    snprintf(cmd, sizeof(cmd), "%s TUNE %s %d", "/opt/sagetv/server/gentuner", loadedDevName, channel);
    _log(7, "MacroTune: Using command: %s", cmd);;
    _log(6, "MacroTune: Remote: %s, Channel: %d", loadedDevName, channel);;
    if ( system(cmd) != 0 ) {
        _log(3, "MacroTune: Failed to execute TUNE command: %s", cmd);;
    } else {
        _log(7, "MacroTune: Executed TUNE command without error: %s", cmd);;
    }
}

variable_types: channel int


SetRemoteName

decompiled_code:
char *__fastcall SetRemoteName(char *src)
{
return strncpy(loadedDevName, src, 0x100uLL);
}

canonical_decompiled_code:
char *__fastcall func20(char *src)
{
return strncpy(loadedDevName, src, 0x100uLL);
}

original_code:
void SetRemoteName(char *name) {
    strncpy(loadedDevName, name, sizeof(loadedDevName));
}

variable_types:
name
char *


main

canonical_name: main

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

puts("Test Generic Tuner Plugin");
puts("Open Device");
OpenDevice(1LL, argv);
puts("Creating Test Remote");
v3 = (void *)CreateRemote("testremote");
SetRemoteName("testremote");
if ( (unsigned int)CanMacroTune() )
{
puts("Test Macro Tune");
MacroTune(1LL, 256LL);
}
puts("Playing Command");
PlayCommand(1LL, v3, "ENTER", 1LL);
puts("Freeing Test Remote");
free(v3);
puts("Close Device");
CloseDevice(1LL);
return 0;
}

original_code:
int main(int argc, char *argv[]) {
    printf("Test Generic Tuner Plugin\n");
    printf("Open Device\n");
    OpenDevice(1);
    printf("Creating Test Remote\n");
    remote *rem = CreateRemote((unsigned char *)"testremote");
    SetRemoteName("testremote");
    if (CanMacroTune()) {
        printf("Test Macro Tune\n");
        MacroTune(1, 256);
    }
    printf("Playing Command\n");
    PlayCommand((unsigned int)1, rem, (unsigned char *)"ENTER", 1);
    printf("Freeing Test Remote\n");
    free(rem);
    printf("Close Device\n");
    CloseDevice(1);
    return 0;
}

canonical_original_code:
int main(int argc, char *argv[]) {
    printf("Test Generic Tuner Plugin\n");
    printf("Open Device\n");
    OpenDevice(1);
    printf("Creating Test Remote\n");
    struct remote *rem = CreateRemote((unsigned char *)"testremote");
    SetRemoteName("testremote");
    if (CanMacroTune()) {
        printf("Test Macro Tune\n");
        MacroTune(1, 256);
    }
    printf("Playing Command\n");
    PlayCommand((unsigned int)1, rem, (unsigned char *)"ENTER", 1);
    printf("Freeing Test Remote\n");
    free(rem);
    printf("Close Device\n");
    CloseDevice(1);
    return 0;
}

variable_types: argc int

variable_types:
argv
char *[]


repo: jwm-art-net/MDZ

decompiled_code:
void __fastcall set_last_used(char *s)
{
char *v1; // r12
char *v2; // r12
char *v3; // rax

if ( !s )
return;
v1 = last_used_dir;
if ( !last_used_dir )
goto LABEL_9;
if ( strcmp(last_used_dir, s) )
{
free(v1);
LABEL_9:
v3 = strdup(s);
last_used_dir = dirname(v3);
}
v2 = last_used_filename;
if ( last_used_filename )
{
if ( !strcmp(last_used_filename, s) )
return;
free(v2);
}
last_used_filename_path = strdup(s);
last_used_filename = _xpg_basename((char *)last_used_filename_path);
}

canonical_decompiled_code:
void __fastcall func0(char *s)
{
char *v1; // r12
char *v2; // r12
char *v3; // rax

if ( !s )
return;
v1 = last_used_dir;
if ( !last_used_dir )
goto LABEL_9;
if ( strcmp(last_used_dir, s) )
{
free(v1);
LABEL_9:
v3 = strdup(s);
last_used_dir = dirname(v3);
}
v2 = last_used_filename;
if ( last_used_filename )
{
if ( !strcmp(last_used_filename, s) )
return;
free(v2);
}
last_used_filename_path = strdup(s);
last_used_filename = _xpg_basename((char *)last_used_filename_path);
}

original_code:
static void set_last_used(const char* path)
{
    if (!path)
        return;
    if (last_used_dir && strcmp(last_used_dir, path) != 0) {
        free(last_used_dir);
        last_used_dir = 0;
    }
    if (!last_used_dir) {
        last_used_dir = strdup(path);
        last_used_dir = dirname(last_used_dir);
    }
    if (last_used_filename && strcmp(last_used_filename, path) != 0) {
        free(last_used_filename);
        last_used_filename = 0;
    }
    if (!last_used_filename) {
        last_used_filename_path = strdup(path);
        last_used_filename = __xpg_basename(last_used_filename_path);
    }
}

canonical_original_code:
static void set_last_used(char *path)
{
    if (!path)
        return;
    if (last_used_dir && strcmp(last_used_dir, path) != 0) {
        free(last_used_dir);
        last_used_dir = 0;
    }
    if (!last_used_dir) {
        last_used_dir = strdup(path);
        last_used_dir = dirname(last_used_dir);
    }
    if (last_used_filename && strcmp(last_used_filename, path) != 0) {
        free(last_used_filename);
        last_used_filename = 0;
    }
    if (!last_used_filename) {
        last_used_filename_path = strdup(path);
        last_used_filename = __xpg_basename(last_used_filename_path);
    }
}

variable_types:
path
char *


decompiled_code:
char *my_png_get_last_used_dir()
{
return last_used_dir;
}

canonical_decompiled_code:
char *func2()
{
return last_used_dir;
}

original_code:
const char* my_png_get_last_used_dir(void)
{
    return last_used_dir;
}


decompiled_code:
char *my_png_get_last_used_filename()
{
return last_used_filename;
}

canonical_decompiled_code:
char *func3()
{
return last_used_filename;
}

original_code:
const char* my_png_get_last_used_filename(void)
{
    return last_used_filename;
}


decompiled_code:
void my_png_reset_last_used_filename()
{
if ( last_used_filename_path )
{
free(last_used_filename_path);
last_used_filename_path = 0LL;
last_used_filename = 0LL;
}
}

canonical_decompiled_code:
void func5()
{
if ( last_used_filename_path )
{
free(last_used_filename_path);
last_used_filename_path = 0LL;
last_used_filename = 0LL;
}
}

original_code:
void my_png_reset_last_used_filename(void)
{
    if (last_used_filename_path) {
        free(last_used_filename_path);
        last_used_filename_path = 0;
        last_used_filename = 0;
    }
}

canonical_original_code:
void my_png_reset_last_used_filename()
{
    if (last_used_filename_path) {
        free(last_used_filename_path);
        last_used_filename_path = 0;
        last_used_filename = 0;
    }
}


decompiled_code:
void my_png_cleanup()
{
if ( last_used_dir )
{
free(last_used_dir);
last_used_dir = 0LL;
}
my_png_reset_last_used_filename();
}

canonical_decompiled_code:
void func6()
{
if ( last_used_dir )
{
free(last_used_dir);
last_used_dir = 0LL;
}
func5();
}

original_code:
void my_png_cleanup(void)
{
    if (last_used_dir) {
        free(last_used_dir);
        last_used_dir = 0;
    }
    my_png_reset_last_used_filename();
}

canonical_original_code:
void my_png_cleanup()
{
    if (last_used_dir) {
        free(last_used_dir);
        last_used_dir = 0;
    }
    my_png_reset_last_used_filename();
}


original_code:
void init_misc(void)
{
    if (!opts.width && !opts.height)
    {
        opts.width = img->user_width;
        if (opts.aspect)
            opts.height = img->user_width / opts.aspect;
        else
            opts.height = img->user_height;
    }
    else if (!opts.width)
    {
        if (opts.aspect)
            opts.width = opts.height * opts.aspect;
        else
            opts.width = opts.height * img->aspect;
    }
    else if (!opts.height)
    {
        if (opts.aspect)
            opts.height = opts.width / opts.aspect;
        else
            opts.height = opts.width / img->aspect;
    }
    if (!opts.antialias)
        opts.antialias = 1;
    if (!opts.threads)
    {
        if (!(opts.threads = cpu_count()))
            opts.threads = 2;
    }
    img->thread_count = opts.threads;
    image_info_set(img, opts.width, opts.height, opts.antialias);
    fun_palette.offset = 0;
    fun_palette.stripe = 1;
    fun_palette.spread = 1;
}

canonical_original_code:
void init_misc()
{
    if (!opts.width && !opts.height)
    {
        opts.width = img->user_width;
        if (opts.aspect)
            opts.height = img->user_width / opts.aspect;
        else
            opts.height = img->user_height;
    }
    else if (!opts.width)
    {
        if (opts.aspect)
            opts.width = opts.height * opts.aspect;
        else
            opts.width = opts.height * img->aspect;
    }
    else if (!opts.height)
    {
        if (opts.aspect)
            opts.height = opts.width / opts.aspect;
        else
            opts.height = opts.width / img->aspect;
    }
    if (!opts.antialias)
        opts.antialias = 1;
    if (!opts.threads)
    {
        if (!(opts.threads = cpu_count()))
            opts.threads = 2;
    }
    img->thread_count = opts.threads;
    image_info_set(img, opts.width, opts.height, opts.antialias);
    fun_palette.offset = 0;
    fun_palette.stripe = 1;
    fun_palette.spread = 1;
}


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char *v3; // rax
int v4; // er12
unsigned int v5; // edi
__int64 v6; // rax
__int64 v7; // rdx
const char *v8; // rbp
char *v10; // rax
const char **v11; // [rsp+0h] [rbp-28h] BYREF
int v12[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v3 = (char *)*argv;
v12[0] = argc;
program_name = v3;
v11 = argv;
setting_init(argc, argv, envp);
v4 = process_args((unsigned int)argc, argv);
if ( v4 >= 0 )
{
v5 = time(0LL);
srand(v5);
*((_DWORD *)&rnd_palette + 14) = 1;
*(&rnd_palette + 3) = LC20;
rnd_palette = LC19;
*(&rnd_palette + 4) = LC21;
*(&rnd_palette + 1) = LC19;
*(&rnd_palette + 5) = LC22;
*(&rnd_palette + 2) = LC19;
*(&rnd_palette + 6) = 0x100000000LL;
if ( !(unsigned int)palette_init() )
palette_randomize(&rnd_palette);
v6 = image_info_create(0LL, 0LL);
v7 = (__int64)*(&opts + 4);
img = v6;
*(_QWORD *)(v6 + 376) = &rnd_palette;
if ( v7 )
{
if ( !(unsigned int)image_info_load_all(v6, 3LL) )
{
v4 = -1;
perror("Failed to load dump file\n");
goto LABEL_13;
}
}
else if ( *(&opts + 1) && !(unsigned int)image_info_load_all(v6, 3LL) )
{
v4 = -1;
fprintf(stderr, "Failed to load %s\n", *(&opts + 1));
goto LABEL_13;
}
init_misc();
if ( *(&opts + 2) && !(unsigned int)palette_load() )
{
v4 = -1;
fprintf(stderr, "could not read palette file %s\n", *(&opts + 2));
}
else
{
v8 = opts;
if ( !opts )
goto LABEL_11;
if ( !strcmp("-", opts) )
{
*(&opts + 5) = (char *)stdout;
goto LABEL_11;
}
v10 = (char *)fopen(v8, "w");
*(&opts + 5) = v10;
if ( v10 )
{
LABEL_11:
if ( *(&opts + 9) )
render_to_file(img);
else
gui_init(v12, &v11, img);
goto LABEL_13;
}
v4 = -1;
fprintf(stderr, "could not open logfile %s for writing\n", opts);
}
LABEL_13:
image_info_destroy(img);
image_info_cleanup();
palette_free();
my_png_cleanup();
}
cleanup_opts();
return v4;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char *v3; // rax
int v4; // er12
unsigned int v5; // edi
__int64 v6; // rax
__int64 v7; // rdx
const char *v8; // rbp
char *v10; // rax
const char **v11; // [rsp+0h] [rbp-28h] BYREF
int v12[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v3 = (char *)*argv;
v12[0] = argc;
program_name = v3;
v11 = argv;
setting_init(argc, argv, envp);
v4 = process_args((unsigned int)argc, argv);
if ( v4 >= 0 )
{
v5 = time(0LL);
srand(v5);
*((_DWORD *)&rnd_palette + 14) = 1;
*(&rnd_palette + 3) = LC20;
rnd_palette = LC19;
*(&rnd_palette + 4) = LC21;
*(&rnd_palette + 1) = LC19;
*(&rnd_palette + 5) = LC22;
*(&rnd_palette + 2) = LC19;
*(&rnd_palette + 6) = 0x100000000LL;
if ( !(unsigned int)palette_init() )
palette_randomize(&rnd_palette);
v6 = image_info_create(0LL, 0LL);
v7 = (__int64)*(&opts + 4);
img = v6;
*(_QWORD *)(v6 + 376) = &rnd_palette;
if ( v7 )
{
if ( !(unsigned int)image_info_load_all(v6, 3LL) )
{
v4 = -1;
perror("Failed to load dump file\n");
goto LABEL_13;
}
}
else if ( *(&opts + 1) && !(unsigned int)image_info_load_all(v6, 3LL) )
{
v4 = -1;
fprintf(stderr, "Failed to load %s\n", *(&opts + 1));
goto LABEL_13;
}
func2();
if ( *(&opts + 2) && !(unsigned int)palette_load() )
{
v4 = -1;
fprintf(stderr, "could not read palette file %s\n", *(&opts + 2));
}
else
{
v8 = opts;
if ( !opts )
goto LABEL_11;
if ( !strcmp("-", opts) )
{
*(&opts + 5) = (char *)stdout;
goto LABEL_11;
}
v10 = (char *)fopen(v8, "w");
*(&opts + 5) = v10;
if ( v10 )
{
LABEL_11:
if ( *(&opts + 9) )
render_to_file(img);
else
gui_init(v12, &v11, img);
goto LABEL_13;
}
v4 = -1;
fprintf(stderr, "could not open logfile %s for writing\n", opts);
}
LABEL_13:
image_info_destroy(img);
image_info_cleanup();
palette_free();
my_png_cleanup();
}
cleanup_opts();
return v4;
}

original_code:
int main(int argc, char** argv)
{
    program_name = argv[0];
    setting_init();
    int ret = process_args(argc, argv);
    if (ret < 0)
        goto quit2;
    srand(time(0));
    rnd_palette.r_strength = 1.0;
    rnd_palette.g_strength = 1.0;
    rnd_palette.b_strength = 1.0;
    rnd_palette.r_bands = 0.05;
    rnd_palette.g_bands = 0.08;
    rnd_palette.b_bands = 0.2;
    rnd_palette.offset = 0.0;
    rnd_palette.stripe = 1.0;
    rnd_palette.spread = 1.0;
    if (!palette_init())
        palette_randomize(&rnd_palette);
    img = image_info_create(FAMILY_MANDEL, MANDELBROT);
    img->rnd_pal = &rnd_palette;
    if (opts.dumpfile)
    {
        if (!image_info_load_all(img,
                                MDZ_FRACTAL_SETTINGS | MDZ_PALETTE_DATA,
                                opts.dumpfile))
        {
            perror("Failed to load dump file\n");
            ret = -1;
            goto quit1;
        }
        if (0 && remove(opts.dumpfile) == -1)
        {
            perror("Can't delete temp file");
        }
    }
    else if (opts.settingsfile)
    {
        if (!image_info_load_all(img,
                                MDZ_FRACTAL_SETTINGS | MDZ_PALETTE_DATA,
                                opts.settingsfile))
        {
            fprintf(stderr, "Failed to load %s\n", opts.settingsfile);
            ret = -1;
            goto quit1;
        }
    }
    init_misc();
    if (opts.palettefile)
    {
        if (!palette_load(opts.palettefile))
        {
            fprintf(stderr, "could not read palette file %s\n",
                            opts.palettefile);
            ret = -1;
            goto quit1;
        }
    }
    if (opts.logfile)
    {
        if (strcmp("-", opts.logfile) == 0)
            opts.logfd = stdout;
        else if (!(opts.logfd = fopen(opts.logfile, "w")))
        {
            fprintf(stderr, "could not open logfile %s for writing\n",
                            opts.logfile);
            ret = -1;
            goto quit1;
        }
    }
    if (opts.renderfile)
        render_to_file(img);
    else
        gui_init(&argc, &argv, img);
quit1:
    image_info_destroy(img);
    image_info_cleanup();
    palette_free();
    my_png_cleanup();
quit2:
    cleanup_opts();
    return ret;
}

canonical_original_code:
int main(int argc, char **argv)
{
    program_name = argv[0];
    setting_init();
    int ret = process_args(argc, argv);
    if (ret < 0)
        goto quit2;
    srand(time(0));
    rnd_palette.r_strength = 1.0;
    rnd_palette.g_strength = 1.0;
    rnd_palette.b_strength = 1.0;
    rnd_palette.r_bands = 0.05;
    rnd_palette.g_bands = 0.08;
    rnd_palette.b_bands = 0.2;
    rnd_palette.offset = 0.0;
    rnd_palette.stripe = 1.0;
    rnd_palette.spread = 1.0;
    if (!palette_init())
        palette_randomize(&rnd_palette);
    img = image_info_create(FAMILY_MANDEL, MANDELBROT);
    img->rnd_pal = &rnd_palette;
    if (opts.dumpfile)
    {
        if (!image_info_load_all(img,
                                MDZ_FRACTAL_SETTINGS | MDZ_PALETTE_DATA,
                                opts.dumpfile))
        {
            perror("Failed to load dump file\n");
            ret = -1;
            goto quit1;
        }
        if (0 && remove(opts.dumpfile) == -1)
        {
            perror("Can't delete temp file");
        }
    }
    else if (opts.settingsfile)
    {
        if (!image_info_load_all(img,
                                MDZ_FRACTAL_SETTINGS | MDZ_PALETTE_DATA,
                                opts.settingsfile))
        {
            fprintf(stderr, "Failed to load %s\n", opts.settingsfile);
            ret = -1;
            goto quit1;
        }
    }
    init_misc();
    if (opts.palettefile)
    {
        if (!palette_load(opts.palettefile))
        {
            fprintf(stderr, "could not read palette file %s\n",
                            opts.palettefile);
            ret = -1;
            goto quit1;
        }
    }
    if (opts.logfile)
    {
        if (strcmp("-", opts.logfile) == 0)
            opts.logfd = stdout;
        else if (!(opts.logfd = fopen(opts.logfile, "w")))
        {
            fprintf(stderr, "could not open logfile %s for writing\n",
                            opts.logfile);
            ret = -1;
            goto quit1;
        }
    }
    if (opts.renderfile)
        render_to_file(img);
    else
        gui_init(&argc, &argv, img);
quit1:
    image_info_destroy(img);
    image_info_cleanup();
    palette_free();
    my_png_cleanup();
quit2:
    cleanup_opts();
    return ret;
}

variable_types:
argv
char **

variable_types: ret int


decompiled_code:
__int64 __fastcall zoom_resize(int a1)
{
int v1; // eax
__int64 result; // rax

v1 = *((_DWORD *)&stat + 4) + 4 * a1;
*((_DWORD *)&stat + 4) = v1;
result = (unsigned int)(int)((double)v1 / *(double *)(img + 400LL));
*((_DWORD *)&stat + 5) = result;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1)
{
int v1; // eax
__int64 result; // rax

v1 = *((_DWORD *)&stat + 4) + 4 * a1;
*((_DWORD *)&stat + 4) = v1;
result = (unsigned int)(int)((double)v1 / *(double *)(img + 400LL));
*((_DWORD *)&stat + 5) = result;
return result;
}

original_code:
void zoom_resize(int arg)
{
    stat.z_width += arg * 4;
    stat.z_height = stat.z_width / img->aspect;
}

variable_types: arg int


original_code:
int zoom_is_valid_size(void)
{
    if ((stat.z_width < 4) || (stat.z_width > (img->user_width - 16))
    || (stat.z_height < 4) || (stat.z_height > (img->user_height - 16)))
        return (0);
    else
        return (!(0));
}

canonical_original_code:
int zoom_is_valid_size()
{
    if ((stat.z_width < 4) || (stat.z_width > (img->user_width - 16))
    || (stat.z_height < 4) || (stat.z_height > (img->user_height - 16)))
        return (0);
    else
        return (!(0));
}


decompiled_code:
__int64 __fastcall zoom_gui_sensitive_zoom_in_button(unsigned int a1)
{
return gtk_widget_set_sensitive(zoom_in_button, a1);
}

canonical_decompiled_code:
__int64 __fastcall func3(unsigned int a1)
{
return gtk_widget_set_sensitive(zoom_in_button, a1);
}

original_code:
void zoom_gui_sensitive_zoom_in_button(gboolean t)
    { gtk_widget_set_sensitive(zoom_in_button, t); }

canonical_original_code:
void zoom_gui_sensitive_zoom_in_button(int t)
    { gtk_widget_set_sensitive(zoom_in_button, t); }

variable_types: t int


decompiled_code:
__int64 start_zoom_1click()
{
__int64 v0; // rax
double v1; // xmm0_8

v0 = img;
*((_DWORD *)&stat + 4) = 16;
v1 = 16.0 / *(double *)(v0 + 400);
stat = (int (*)(const char *, struct stat *))(zoom_resize + 3);
*((_DWORD *)&stat + 5) = (int)v1;
zoom_gui_sensitive_zoom_in_button(0);
gui_sensitive_switch_menu(0LL);
return repos_gui_sensitive_reposition_button(0LL);
}

canonical_decompiled_code:
__int64 func4()
{
__int64 v0; // rax
double v1; // xmm0_8

v0 = img;
*((_DWORD *)&stat + 4) = 16;
v1 = 16.0 / *(double *)(v0 + 400);
stat = (int (*)(const char *, struct stat *))(zoom_resize + 3);
*((_DWORD *)&stat + 5) = (int)v1;
func3(0);
gui_sensitive_switch_menu(0LL);
return repos_gui_sensitive_reposition_button(0LL);
}

original_code:
void start_zoom_1click(void)
{
    stat.action = STAT_ZOOMING_1CLICK;
    stat.z_width = 16;
    stat.z_height = stat.z_width / img->aspect;
    stat.reposition_p2 = (0);
    zoom_gui_sensitive_zoom_in_button((0));
    gui_sensitive_switch_menu((0));
    repos_gui_sensitive_reposition_button((0));
}

canonical_original_code:
void start_zoom_1click()
{
    stat.action = STAT_ZOOMING_1CLICK;
    stat.z_width = 16;
    stat.z_height = stat.z_width / img->aspect;
    stat.reposition_p2 = (0);
    zoom_gui_sensitive_zoom_in_button((0));
    gui_sensitive_switch_menu((0));
    repos_gui_sensitive_reposition_button((0));
}


decompiled_code:
__int64 __fastcall zoom_gui_sensitive_zoom_out_button(unsigned int a1)
{
return gtk_widget_set_sensitive(zoom_out_button, a1);
}

canonical_decompiled_code:
__int64 __fastcall func7(unsigned int a1)
{
return gtk_widget_set_sensitive(zoom_out_button, a1);
}

original_code:
void zoom_gui_sensitive_zoom_out_button(gboolean t)
    { gtk_widget_set_sensitive(zoom_out_button, t); }

canonical_original_code:
void zoom_gui_sensitive_zoom_out_button(int t)
    { gtk_widget_set_sensitive(zoom_out_button, t); }


decompiled_code:
__int64 __fastcall zoom_gui_sensitive_zoom_in_1click_button(unsigned int a1)
{
return gtk_widget_set_sensitive(zoom_in_1click_button, a1);
}

canonical_decompiled_code:
__int64 __fastcall func8(unsigned int a1)
{
return gtk_widget_set_sensitive(zoom_in_1click_button, a1);
}

original_code:
void zoom_gui_sensitive_zoom_in_1click_button(gboolean t)
    { gtk_widget_set_sensitive(zoom_in_1click_button, t); }

canonical_original_code:
void zoom_gui_sensitive_zoom_in_1click_button(int t)
    { gtk_widget_set_sensitive(zoom_in_1click_button, t); }


decompiled_code:
__int64 start_zooming()
{
__int64 v0; // rax
double v1; // xmm0_8
int v2; // edx
double v3; // xmm0_8

v0 = img;
LODWORD(stat) = 2;
v1 = (double)*(int *)(img + 392LL) * 0.35;
*(&stat + 1) = 0LL;
v2 = (int)v1;
v3 = (double)(int)v1 / *(double *)(v0 + 400);
*((_DWORD *)&stat + 4) = v2;
*((_DWORD *)&stat + 5) = (int)v3;
zoom_gui_sensitive_zoom_in_1click_button(0);
gui_sensitive_switch_menu(0LL);
repos_gui_sensitive_reposition_button(0LL);
return gdk_gc_set_line_attributes(*(_QWORD *)(*(_QWORD *)(drawing_area + 48LL) + 872LL), 1LL, 0LL, 1LL, 0LL);
}

canonical_decompiled_code:
__int64 func9()
{
__int64 v0; // rax
double v1; // xmm0_8
int v2; // edx
double v3; // xmm0_8

v0 = img;
LODWORD(stat) = 2;
v1 = (double)*(int *)(img + 392LL) * 0.35;
*(&stat + 1) = 0LL;
v2 = (int)v1;
v3 = (double)(int)v1 / *(double *)(v0 + 400);
*((_DWORD *)&stat + 4) = v2;
*((_DWORD *)&stat + 5) = (int)v3;
func8(0);
gui_sensitive_switch_menu(0LL);
repos_gui_sensitive_reposition_button(0LL);
return gdk_gc_set_line_attributes(*(_QWORD *)(*(_QWORD *)(drawing_area + 48LL) + 872LL), 1LL, 0LL, 1LL, 0LL);
}

original_code:
void start_zooming(void)
{
    stat.action = STAT_ZOOMING;
    stat.z_x = 0;
    stat.z_y = 0;
    stat.z_width = .35 * img->user_width;
    stat.z_height = stat.z_width / img->aspect;
    zoom_gui_sensitive_zoom_in_1click_button((0));
    gui_sensitive_switch_menu((0));
    repos_gui_sensitive_reposition_button((0));
    gdk_gc_set_line_attributes(drawing_area->style->white_gc,
            1, GDK_LINE_SOLID, GDK_CAP_BUTT, GDK_JOIN_MITER);
}

canonical_original_code:
void start_zooming()
{
    stat.action = STAT_ZOOMING;
    stat.z_x = 0;
    stat.z_y = 0;
    stat.z_width = .35 * img->user_width;
    stat.z_height = stat.z_width / img->aspect;
    zoom_gui_sensitive_zoom_in_1click_button((0));
    gui_sensitive_switch_menu((0));
    repos_gui_sensitive_reposition_button((0));
    gdk_gc_set_line_attributes(drawing_area->style->white_gc,
            1, GDK_LINE_SOLID, GDK_CAP_BUTT, GDK_JOIN_MITER);
}


decompiled_code:
__int64 zoom_gui_kill_timers()
{
__int64 result; // rax

if ( *((_DWORD *)&stat + 6) != -1 )
result = g_source_remove();
*((_DWORD *)&stat + 6) = -1;
return result;
}

canonical_decompiled_code:
__int64 func11()
{
__int64 result; // rax

if ( *((_DWORD *)&stat + 6) != -1 )
result = g_source_remove();
*((_DWORD *)&stat + 6) = -1;
return result;
}

original_code:
void zoom_gui_kill_timers(void)
{
    if (stat.zoom_timer_id != -1)
        g_source_remove(stat.zoom_timer_id);
    stat.zoom_timer_id = -1;
}

canonical_original_code:
void zoom_gui_kill_timers()
{
    if (stat.zoom_timer_id != -1)
        g_source_remove(stat.zoom_timer_id);
    stat.zoom_timer_id = -1;
}


decompiled_code:
__int64 stop_zooming()
{
LODWORD(stat) = 0;
zoom_gui_kill_timers();
zoom_gui_sensitive_zoom_in_1click_button(1u);
gui_sensitive_switch_menu(1LL);
return repos_gui_sensitive_reposition_button(1LL);
}

canonical_decompiled_code:
__int64 func12()
{
LODWORD(stat) = 0;
func11();
func8(1u);
gui_sensitive_switch_menu(1LL);
return repos_gui_sensitive_reposition_button(1LL);
}

original_code:
void stop_zooming(void)
{
    stat.action = STAT_NORMAL;
    zoom_gui_kill_timers();
    zoom_gui_sensitive_zoom_in_1click_button((!(0)));
    gui_sensitive_switch_menu((!(0)));
    repos_gui_sensitive_reposition_button((!(0)));
}

canonical_original_code:
void stop_zooming()
{
    stat.action = STAT_NORMAL;
    zoom_gui_kill_timers();
    zoom_gui_sensitive_zoom_in_1click_button((!(0)));
    gui_sensitive_switch_menu((!(0)));
    repos_gui_sensitive_reposition_button((!(0)));
}


decompiled_code:
__int64 zoom_gui_draw_zoom_box()
{
gdk_gc_set_function(*(_QWORD *)(*(_QWORD *)(drawing_area + 48LL) + 872LL), 2LL);
gdk_draw_rectangle(
*(_QWORD *)(drawing_area + 80LL),
*(_QWORD *)(*(_QWORD *)(drawing_area + 48LL) + 872LL),
0LL,
(unsigned int)(*((_DWORD *)&stat + 2) - (*((int *)&stat + 4) >> 1)),
(unsigned int)(*((_DWORD *)&stat + 3) - (*((int *)&stat + 5) >> 1)));
return gdk_gc_set_function(*(_QWORD *)(*(_QWORD *)(drawing_area + 48LL) + 872LL), 0LL);
}

canonical_decompiled_code:
__int64 func14()
{
gdk_gc_set_function(*(_QWORD *)(*(_QWORD *)(drawing_area + 48LL) + 872LL), 2LL);
gdk_draw_rectangle(
*(_QWORD *)(drawing_area + 80LL),
*(_QWORD *)(*(_QWORD *)(drawing_area + 48LL) + 872LL),
0LL,
(unsigned int)(*((_DWORD *)&stat + 2) - (*((int *)&stat + 4) >> 1)),
(unsigned int)(*((_DWORD *)&stat + 3) - (*((int *)&stat + 5) >> 1)));
return gdk_gc_set_function(*(_QWORD *)(*(_QWORD *)(drawing_area + 48LL) + 872LL), 0LL);
}

original_code:
void zoom_gui_draw_zoom_box(void)
{
    gdk_gc_set_function(drawing_area->style->white_gc, GDK_XOR);
    gdk_draw_rectangle(
        drawing_area->window, drawing_area->style->white_gc,
        (0), stat.z_x - (stat.z_width >> 1),
                stat.z_y - (stat.z_height >> 1),
                stat.z_width, stat.z_height);
    gdk_gc_set_function(drawing_area->style->white_gc, GDK_COPY);
}

canonical_original_code:
void zoom_gui_draw_zoom_box()
{
    gdk_gc_set_function(drawing_area->style->white_gc, GDK_XOR);
    gdk_draw_rectangle(
        drawing_area->window, drawing_area->style->white_gc,
        (0), stat.z_x - (stat.z_width >> 1),
                stat.z_y - (stat.z_height >> 1),
                stat.z_width, stat.z_height);
    gdk_gc_set_function(drawing_area->style->white_gc, GDK_COPY);
}


decompiled_code:
__int64 __fastcall zoom_callback(int a1)
{
zoom_gui_draw_zoom_box();
zoom_resize(a1);
if ( !zoom_is_valid_size() )
zoom_resize(-a1);
zoom_gui_draw_zoom_box();
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func16(int a1)
{
func14();
func0(a1);
if ( !func1() )
func0(-a1);
func14();
return 1LL;
}

original_code:
gint zoom_callback(int arg)
{
    zoom_gui_draw_zoom_box();
    zoom_resize(arg);
    if (!zoom_is_valid_size())
        zoom_resize(-1*arg);
    zoom_gui_draw_zoom_box();
    return (!(0));
}


decompiled_code:
__int64 __fastcall zoom_gui_process_zooming_click(int a1)
{
zoom_gui_draw_zoom_box();
switch ( a1 )
{
case 1:
zoom_resize(1);
if ( zoom_is_valid_size() )
*((_DWORD *)&stat + 6) = g_timeout_add(25LL, zoom_callback, 2LL);
else
zoom_resize(-1);
break;
case 2:
zoom_in();
break;
case 3:
zoom_resize(-1);
if ( zoom_is_valid_size() )
*((_DWORD *)&stat + 6) = g_timeout_add(25LL, zoom_callback, -2LL);
else
zoom_resize(1);
break;
}
return zoom_gui_draw_zoom_box();
}

canonical_decompiled_code:
__int64 __fastcall func17(int a1)
{
func14();
switch ( a1 )
{
case 1:
func0(1);
if ( func1() )
*((_DWORD *)&stat + 6) = g_timeout_add(25LL, zoom_callback, 2LL);
else
func0(-1);
break;
case 2:
func15();
break;
case 3:
func0(-1);
if ( func1() )
*((_DWORD *)&stat + 6) = g_timeout_add(25LL, zoom_callback, -2LL);
else
func0(1);
break;
}
return func14();
}

original_code:
void zoom_gui_process_zooming_click(int button)
{
    zoom_gui_draw_zoom_box();
    if (button == 1)
    {
        zoom_resize(1);
        if (!zoom_is_valid_size())
            zoom_resize(-1);
        else
            stat.zoom_timer_id = g_timeout_add(25,
                                       (GtkFunction)zoom_callback,
                                       (gpointer)2);
    }
    else if (button == 2)
        zoom_in();
    else if (button == 3)
    {
        zoom_resize(-1);
        if (!zoom_is_valid_size())
            zoom_resize(1);
        else
            stat.zoom_timer_id = g_timeout_add(25,
                                       (GtkFunction)zoom_callback,
                                       (gpointer)-2);
    }
    zoom_gui_draw_zoom_box();
}

canonical_original_code:
void zoom_gui_process_zooming_click(int button)
{
    zoom_gui_draw_zoom_box();
    if (button == 1)
    {
        zoom_resize(1);
        if (!zoom_is_valid_size())
            zoom_resize(-1);
        else
            stat.zoom_timer_id = g_timeout_add(25,
                                       (int (*)(void *data))zoom_callback,
                                       (void *)2);
    }
    else if (button == 2)
        zoom_in();
    else if (button == 3)
    {
        zoom_resize(-1);
        if (!zoom_is_valid_size())
            zoom_resize(1);
        else
            stat.zoom_timer_id = g_timeout_add(25,
                                       (int (*)(void *data))zoom_callback,
                                       (gpointer)-2);
    }
    zoom_gui_draw_zoom_box();
}

variable_types: button int


decompiled_code:
__int64 __fastcall zoom_gui_process_zooming_1click_click(int a1)
{
__int64 result; // rax

if ( *(_BYTE *)(img + 497LL) )
{
result = (unsigned int)(a1 - 1);
if ( (unsigned int)result > 1 )
goto LABEL_3;
return zoom_in();
}
zoom_gui_draw_zoom_box();
result = (unsigned int)(a1 - 1);
if ( (unsigned int)result <= 1 )
return zoom_in();
LABEL_3:
if ( a1 == 3 )
result = stop_zoom_1click();
return result;
}

canonical_decompiled_code:
__int64 __fastcall func18(int a1)
{
__int64 result; // rax

if ( *(_BYTE *)(img + 497LL) )
{
result = (unsigned int)(a1 - 1);
if ( (unsigned int)result > 1 )
goto LABEL_3;
return func15();
}
func14();
result = (unsigned int)(a1 - 1);
if ( (unsigned int)result <= 1 )
return func15();
LABEL_3:
if ( a1 == 3 )
result = func5();
return result;
}

original_code:
void zoom_gui_process_zooming_1click_click(int button)
{
    if (!img->zoom_new_win)
        zoom_gui_draw_zoom_box();
    if (button == 1 || button == 2)
        zoom_in();
    else if (button == 3)
        stop_zoom_1click();
}


decompiled_code:
__int64 __fastcall frac_variant(__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; // rt1
long double v19; // fst4
long double v20; // fst6
long double v21; // fst4
long double v22; // fst2
long double v23; // rt0
long double v24; // fst6
long double v25; // rtt

if ( a1 <= 0 )
return 0LL;
result = 1LL;
while ( 1 )
{
a2 = a2 * (a3 + a3) + a4;
v24 = a7 - a6;
if ( (result & 1) != 0 )
{
v18 = a5;
v19 = v24;
v20 = v18;
v21 = fabs(v19) + v18;
}
else
{
v25 = a5;
v21 = v24 + a5;
v20 = v25;
}
a6 = a2 * a2;
if ( a2 * a2 + v21 * v21 > 4.0 )
break;
if ( a1 < ++result )
return 0LL;
v22 = v20;
a7 = v21 * v21;
v23 = v22;
a3 = v21;
a5 = v23;
}
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; // rt1
long double v19; // fst4
long double v20; // fst6
long double v21; // fst4
long double v22; // fst2
long double v23; // rt0
long double v24; // fst6
long double v25; // rtt

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

original_code:
depth_t frac_variant( 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;
        if (wz % 2)
            wre = fabsl(wre2 - wim2) + c_re;
        else
            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_variant(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;
        if (wz % 2)
            wre = fabsl(wre2 - wim2) + c_re;
        else
            wre = 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_variant_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);
if ( (v11 & 1) != 0 )
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);
if ( (v11 & 1) != 0 )
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_variant_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);
        if (wz % 2)
            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_variant_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);
        if (wz % 2)
            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: struct __mpfr_struct { long _mpfr_prec; int _mpfr_sign; long _mpfr_exp; unsigned long *_mpfr_d; } [1]

variable_types:
wim
struct __mpfr_struct [1]

variable_types:
wre
struct __mpfr_struct [1]


original_code:
depth_t frac_variant_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);
        if (wz % 2)
            __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_variant_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);
        if (wz % 2)
            __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:
int __fastcall show_usage(const char *a1)
{
printf("usage: %s [options]\n", a1);
puts("options:");
puts(" -l, --load-settings [FILE] saved settings file to load");
puts(" -P, --load-palette [FILE] .map palette file to load");
puts(" -p, --random-palette generate a random palette");
puts(" -L, --log-file [FILE] log settings to file");
puts(" -w, --width [n] set image width to n");
puts(" -h, --height [n] set image height to n");
puts(" -a --aspect [n.nnn] set aspect ration to n.nnn");
puts(" -R, --render [FILE] just render an image to file");
puts(" -A, --anti-alias [n] set anti-aliasing factor to n");
puts(" -t, --threads [n] set number of threads to n.");
puts(" -V, --version show version.");
putchar(10);
puts(
"NOTE: Not all combinations of width, height, aspect ratio, and\n"
" settings file make sense. The settings files only store\n"
" the aspect ratio of an image, not it's dimensions.\n"
" Author may have forgotten to update version number.");
putchar(10);
puts("mdz Mandelbrot Deep Zoom");
puts("(c) James W. Morris 2009-2010 http://jwm-art.net/mdz/");
return puts("This software is licensed using the GNU GPLv3\n");
}

canonical_decompiled_code:
int __fastcall func0(const char *a1)
{
printf("usage: %s [options]\n", a1);
puts("options:");
puts(" -l, --load-settings [FILE] saved settings file to load");
puts(" -P, --load-palette [FILE] .map palette file to load");
puts(" -p, --random-palette generate a random palette");
puts(" -L, --log-file [FILE] log settings to file");
puts(" -w, --width [n] set image width to n");
puts(" -h, --height [n] set image height to n");
puts(" -a --aspect [n.nnn] set aspect ration to n.nnn");
puts(" -R, --render [FILE] just render an image to file");
puts(" -A, --anti-alias [n] set anti-aliasing factor to n");
puts(" -t, --threads [n] set number of threads to n.");
puts(" -V, --version show version.");
putchar(10);
puts(
"NOTE: Not all combinations of width, height, aspect ratio, and\n"
" settings file make sense. The settings files only store\n"
" the aspect ratio of an image, not it's dimensions.\n"
" Author may have forgotten to update version number.");
putchar(10);
puts("mdz Mandelbrot Deep Zoom");
puts("(c) James W. Morris 2009-2010 http://jwm-art.net/mdz/");
return puts("This software is licensed using the GNU GPLv3\n");
}

original_code:
void show_usage(char* argvzero)
{
    printf("usage:  %s [options]\n", argvzero);
    printf("options:\n");
    printf("    -l, --load-settings [FILE]  saved settings file to load\n");
    printf("    -P, --load-palette [FILE]   .map palette file to load\n");
    printf("    -p, --random-palette        generate a random palette\n");
    printf("    -L, --log-file [FILE]       log settings to file\n");
    printf("    -w, --width [n]             set image width to n\n");
    printf("    -h, --height [n]            set image height to n\n");
    printf("    -a  --aspect [n.nnn]        set aspect ration to n.nnn\n");
    printf("    -R, --render [FILE]         just render an image to file\n");
    printf("    -A, --anti-alias [n]        set anti-aliasing factor to n\n");
    printf("    -t, --threads [n]           set number of threads to n.\n");
    printf("    -V, --version               show version.\n");
    printf("\n");
    printf("NOTE: Not all combinations of width, height, aspect ratio, and\n"
           "      settings file make sense. The settings files only store\n"
           "      the aspect ratio of an image, not it's dimensions.\n"
           "      Author may have forgotten to update version number.\n");
    printf("\n");
    printf("mdz Mandelbrot Deep Zoom\n");
    printf("(c) James W. Morris 2009-2010 http://jwm-art.net/mdz/\n");
    printf("This software is licensed using the GNU GPLv3\n\n");
}

canonical_original_code:
void show_usage(char *argvzero)
{
    printf("usage:  %s [options]\n", argvzero);
    printf("options:\n");
    printf("    -l, --load-settings [FILE]  saved settings file to load\n");
    printf("    -P, --load-palette [FILE]   .map palette file to load\n");
    printf("    -p, --random-palette        generate a random palette\n");
    printf("    -L, --log-file [FILE]       log settings to file\n");
    printf("    -w, --width [n]             set image width to n\n");
    printf("    -h, --height [n]            set image height to n\n");
    printf("    -a  --aspect [n.nnn]        set aspect ration to n.nnn\n");
    printf("    -R, --render [FILE]         just render an image to file\n");
    printf("    -A, --anti-alias [n]        set anti-aliasing factor to n\n");
    printf("    -t, --threads [n]           set number of threads to n.\n");
    printf("    -V, --version               show version.\n");
    printf("\n");
    printf("NOTE: Not all combinations of width, height, aspect ratio, and\n"
           "      settings file make sense. The settings files only store\n"
           "      the aspect ratio of an image, not it's dimensions.\n"
           "      Author may have forgotten to update version number.\n");
    printf("\n");
    printf("mdz Mandelbrot Deep Zoom\n");
    printf("(c) James W. Morris 2009-2010 http://jwm-art.net/mdz/\n");
    printf("This software is licensed using the GNU GPLv3\n\n");
}

variable_types:
argvzero
char *


oom

decompiled_code:
__int64 __fastcall oom(const char *a1, const char *a2)
{
fprintf(stderr, "out of memory processing %s=%s\naborting command line processing!", a1, a2);
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func1(const char *a1, const char *a2)
{
fprintf(stderr, "out of memory processing %s=%s\naborting command line processing!", a1, a2);
return 0xFFFFFFFFLL;
}

original_code:
int oom(const char* arg, const char* val)
{
    fprintf(stderr, "out of memory processing %s=%s\n"
                    "aborting command line processing!",
                    arg, val);
    return -1;
}

canonical_original_code:
int oom(char *arg, char *val)
{
    fprintf(stderr, "out of memory processing %s=%s\n"
                    "aborting command line processing!",
                    arg, val);
    return -1;
}

variable_types:
arg
char *

variable_types:
val
char *