repo: jezze/xurfaced

decompiled_code:
void xurfaced_signal_term()
{
*((_DWORD *)&xurfaced + 290) = 0;
}

canonical_decompiled_code:
void func0()
{
*((_DWORD *)&xurfaced + 290) = 0;
}

original_code:
static void xurfaced_signal_term(int sig)
{
    xurfaced.running = 0;
}

variable_types: sig int


decompiled_code:
void xurfaced_signal_usr1()
{
__int64 v0; // rax
__int64 v1; // rbx

v0 = xurfaced_menu_init(&xurfaced);
if ( v0 )
{
v1 = v0;
pthread_mutex_lock((pthread_mutex_t *)(unsigned int)((_DWORD)&xurfaced + 1184));
if ( *((_QWORD *)&xurfaced + 164) )
xurfaced_menu_destroy();
*((_QWORD *)&xurfaced + 164) = v1;
pthread_mutex_unlock((pthread_mutex_t *)(unsigned int)((_DWORD)&xurfaced + 1184));
}
}

canonical_decompiled_code:
void func1()
{
__int64 v0; // rax
__int64 v1; // rbx

v0 = xurfaced_menu_init(&xurfaced);
if ( v0 )
{
v1 = v0;
pthread_mutex_lock((pthread_mutex_t *)(unsigned int)((_DWORD)&xurfaced + 1184));
if ( *((_QWORD *)&xurfaced + 164) )
xurfaced_menu_destroy();
*((_QWORD *)&xurfaced + 164) = v1;
pthread_mutex_unlock((pthread_mutex_t *)(unsigned int)((_DWORD)&xurfaced + 1184));
}
}

original_code:
static void xurfaced_signal_usr1(int sig)
{
    struct xurfaced_menu *menu = xurfaced_menu_init(&xurfaced);
    if (!menu)
        return;
    pthread_mutex_lock(&xurfaced.mutexMenu);
    if (xurfaced.menu)
        xurfaced_menu_destroy(xurfaced.menu);
    xurfaced.menu = menu;
    pthread_mutex_unlock(&xurfaced.mutexMenu);
}

variable_types: struct xurfaced_menu { struct xurfaced_menu_option_list { struct xurfaced_menu_option { unsigned int type; char *name; char *description; char *command; struct animation_properties { float translationX; float translationY; float sizeX; float sizeY; float rotationX; float rotationY; float alpha; } animationProperties; struct xurfaced_menu_option *next; struct xurfaced_menu_option *prev; } *head; struct xurfaced_menu_option *current; } *opts; struct animation_properties animationProperties; } *

return_type: void

user_defined_types: struct xurfaced_menu { struct xurfaced_menu_option_list *opts; struct animation_properties animationProperties; }

user_defined_types: struct xurfaced_menu_option_list { struct xurfaced_menu_option *head; struct xurfaced_menu_option *current; }

user_defined_types: struct xurfaced_menu_option { unsigned int type; char *name; char *description; char *command; struct animation_properties animationProperties; struct xurfaced_menu_option *next; struct xurfaced_menu_option *prev; }


decompiled_code:
__pid_t __fastcall xurfaced_execute(void *src, int *a2)
{
size_t v2; // rax
char *v3; // rbx
char *v4; // rax
__pid_t result; // eax
__int64 v6; // rax
_DWORD stat_loc[3]; // [rsp+Ch] [rbp-111Ch] BYREF
char v8; // [rsp+18h] [rbp-1110h] BYREF
char dest[4120]; // [rsp+110h] [rbp-1018h] BYREF

v2 = strlen((const char *)src);
v3 = &v8;
memcpy(dest, src, v2 + 1);
*(_QWORD *)&stat_loc[1] = strtok(dest, " ");
do
{
v3 += 8;
v4 = strtok(0LL, " ");
*((_QWORD *)v3 - 1) = v4;
}
while ( v4 );
result = fork();
if ( result != -1 )
{
if ( !result )
{
getpid();
if ( a2 )
{
close(1);
dup(a2[1]);
close(*a2);
close(a2[1]);
}
v6 = *((_QWORD *)&xurfaced + 144);
if ( *(_QWORD *)v6 )
close(*(_DWORD *)(v6 + 8));
setsid();
execvp(*(const char **)&stat_loc[1], (char *const *)&stat_loc[1]);
exit(1);
}
if ( a2 )
{
close(a2[1]);
result = wait((__WAIT_STATUS)stat_loc);
}
}
return result;
}

canonical_decompiled_code:
__pid_t __fastcall func7(void *src, int *a2)
{
size_t v2; // rax
char *v3; // rbx
char *v4; // rax
__pid_t result; // eax
__int64 v6; // rax
_DWORD stat_loc[3]; // [rsp+Ch] [rbp-111Ch] BYREF
char v8; // [rsp+18h] [rbp-1110h] BYREF
char dest[4120]; // [rsp+110h] [rbp-1018h] BYREF

v2 = strlen((const char *)src);
v3 = &v8;
memcpy(dest, src, v2 + 1);
*(_QWORD *)&stat_loc[1] = strtok(dest, " ");
do
{
v3 += 8;
v4 = strtok(0LL, " ");
*((_QWORD *)v3 - 1) = v4;
}
while ( v4 );
result = fork();
if ( result != -1 )
{
if ( !result )
{
getpid();
if ( a2 )
{
close(1);
dup(a2[1]);
close(*a2);
close(a2[1]);
}
v6 = *((_QWORD *)&xurfaced + 144);
if ( *(_QWORD *)v6 )
close(*(_DWORD *)(v6 + 8));
setsid();
execvp(*(const char **)&stat_loc[1], (char *const *)&stat_loc[1]);
exit(1);
}
if ( a2 )
{
close(a2[1]);
result = wait((__WAIT_STATUS)stat_loc);
}
}
return result;
}

original_code:
void xurfaced_execute(char *command, int pipe[])
{
    char args[4096], *argv[32];
    memcpy(args, command, strlen(command) + 1);
    argv[0] = strtok(args, " ");
    unsigned int i = 0;
    while ((argv[++i] = strtok(0, " ")));
    int pid = fork();
    int pchild;
    if (pid == -1)
        return;
    if (!pid)
    {
        pchild = getpid();
        if (pipe)
        {
            close(1);
            dup(pipe[1]);
            close(pipe[0]);
            close(pipe[1]);
        }
        if (xurfaced.backend->display)
            close(xurfaced.backend->descriptor);
        setsid();
        execvp(argv[0], argv);
        exit(1);
    }
    if (pipe)
    {
        close(pipe[1]);
        int status;
        wait(&status);
    }
}

canonical_original_code:
void xurfaced_execute(char *command, int pipe[])
{
    char args[4096]; char *argv[32];
    memcpy(args, command, strlen(command) + 1);
    argv[0] = strtok(args, " ");
    unsigned int i = 0;
    while ((argv[++i] = strtok(0, " ")));
    int pid = fork();
    int pchild;
    if (pid == -1)
        return;
    if (!pid)
    {
        pchild = getpid();
        if (pipe)
        {
            close(1);
            dup(pipe[1]);
            close(pipe[0]);
            close(pipe[1]);
        }
        if (xurfaced.backend->display)
            close(xurfaced.backend->descriptor);
        setsid();
        execvp(argv[0], argv);
        exit(1);
    }
    if (pipe)
    {
        close(pipe[1]);
        int status;
        wait(&status);
    }
}

variable_types:
command
char *

variable_types:
pipe
int []

variable_types:
args
char [4096]

variable_types:
argv
char *[32]

variable_types:
i
unsigned int

variable_types: pid int

variable_types: pchild int

variable_types: status int


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
xurfaced_init_constprop_0();
xurfaced_run_constprop_0();
xurfaced_destroy_constprop_0(argc, argv);
return 0;
}

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

original_code:
int main(int argc, char *argv[])
{
    xurfaced_init(&xurfaced);
    xurfaced_run(&xurfaced);
    xurfaced_destroy(&xurfaced);
    return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

return_type: int


decompiled_code:
// attributes: thunk
void xurfaced_client_destroy(void *ptr)
{
free(ptr);
}

canonical_decompiled_code:
void func0(void *ptr)
{
free(ptr);
}

original_code:
void xurfaced_client_destroy(struct xurfaced_client *client)
{
    free(client);
}

variable_types: struct xurfaced_client { unsigned long window; unsigned long picture; struct xurfaced_client *next; struct xurfaced_client *prev; } *


decompiled_code:
_QWORD *xurfaced_client_list_create()
{
_QWORD *result; // rax

result = malloc(0x10uLL);
*result = 0LL;
result[1] = 0LL;
return result;
}

canonical_decompiled_code:
_QWORD *func1()
{
_QWORD *result; // rax

result = malloc(0x10uLL);
*result = 0LL;
result[1] = 0LL;
return result;
}

original_code:
struct xurfaced_client_list *xurfaced_client_list_create()
{
    struct xurfaced_client_list *list = malloc(sizeof (struct xurfaced_client_list));
    list->head = 0;
    list->current = 0;
    return list;
}

variable_types: struct xurfaced_client_list { struct xurfaced_client { unsigned long window; unsigned long picture; struct xurfaced_client *next; struct xurfaced_client *prev; } *head; struct xurfaced_client *current; } *

user_defined_types: struct xurfaced_client_list { struct xurfaced_client *head; struct xurfaced_client *current; }


decompiled_code:
void __fastcall xurfaced_client_list_destroy(_QWORD *a1)
{
_QWORD *v2; // rbx
void *v3; // rdi

v2 = (_QWORD *)*a1;
do
{
v3 = v2;
v2 = (_QWORD *)v2[2];
xurfaced_client_destroy(v3);
}
while ( (_QWORD *)*a1 != v2 );
a1[1] = 0LL;
}

canonical_decompiled_code:
void __fastcall func2(_QWORD *a1)
{
_QWORD *v2; // rbx
void *v3; // rdi

v2 = (_QWORD *)*a1;
do
{
v3 = v2;
v2 = (_QWORD *)v2[2];
func0(v3);
}
while ( (_QWORD *)*a1 != v2 );
a1[1] = 0LL;
}

original_code:
void xurfaced_client_list_destroy(struct xurfaced_client_list *list)
{
    struct xurfaced_client *current = list->head;
    do
    {
        struct xurfaced_client *next = current->next;
        xurfaced_client_destroy(current);
        current = next;
    }
    while (current != list->head);
    list->current = 0;
}

user_defined_types: struct xurfaced_client { unsigned long window; unsigned long picture; struct xurfaced_client *next; struct xurfaced_client *prev; }


decompiled_code:
_QWORD *xurfaced_menu_option_create()
{
_QWORD *result; // rax

result = malloc(0x50uLL);
result[1] = 0LL;
result[2] = 0LL;
result[3] = 0LL;
*((_DWORD *)result + 14) = 0;
result[8] = 0LL;
result[9] = 0LL;
return result;
}

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

result = malloc(0x50uLL);
result[1] = 0LL;
result[2] = 0LL;
result[3] = 0LL;
*((_DWORD *)result + 14) = 0;
result[8] = 0LL;
result[9] = 0LL;
return result;
}

original_code:
struct xurfaced_menu_option *xurfaced_menu_option_create()
{
    struct xurfaced_menu_option *option = malloc(sizeof (struct xurfaced_menu_option));
    option->name = 0;
    option->description = 0;
    option->command = 0;
    option->animationProperties.alpha = 0;
    option->next = 0;
    option->prev = 0;
    return option;
}

variable_types: struct xurfaced_menu_option { unsigned int type; char *name; char *description; char *command; struct animation_properties { float translationX; float translationY; float sizeX; float sizeY; float rotationX; float rotationY; float alpha; } animationProperties; struct xurfaced_menu_option *next; struct xurfaced_menu_option *prev; } *


decompiled_code:
void __fastcall xurfaced_menu_option_destroy(void *ptr)
{
free(*((void **)ptr + 1));
free(*((void **)ptr + 2));
free(*((void **)ptr + 3));
free(ptr);
}

canonical_decompiled_code:
void __fastcall func1(void *ptr)
{
free(*((void **)ptr + 1));
free(*((void **)ptr + 2));
free(*((void **)ptr + 3));
free(ptr);
}

original_code:
void xurfaced_menu_option_destroy(struct xurfaced_menu_option *option)
{
    free(option->name);
    free(option->description);
    free(option->command);
    free(option);
}

user_defined_types: struct animation_properties { float translationX; float translationY; float sizeX; float sizeY; float rotationX; float rotationY; float alpha; }


decompiled_code:
_QWORD *xurfaced_menu_option_list_create()
{
_QWORD *result; // rax

result = malloc(0x10uLL);
*result = 0LL;
result[1] = 0LL;
return result;
}

canonical_decompiled_code:
_QWORD *func2()
{
_QWORD *result; // rax

result = malloc(0x10uLL);
*result = 0LL;
result[1] = 0LL;
return result;
}

original_code:
struct xurfaced_menu_option_list *xurfaced_menu_option_list_create()
{
    struct xurfaced_menu_option_list *list = malloc(sizeof (struct xurfaced_menu_option_list));
    list->head = 0;
    list->current = 0;
    return list;
}

variable_types: struct xurfaced_menu_option_list { struct xurfaced_menu_option { unsigned int type; char *name; char *description; char *command; struct animation_properties { float translationX; float translationY; float sizeX; float sizeY; float rotationX; float rotationY; float alpha; } animationProperties; struct xurfaced_menu_option *next; struct xurfaced_menu_option *prev; } *head; struct xurfaced_menu_option *current; } *


decompiled_code:
_QWORD *xurfaced_menu_create()
{
_QWORD *v0; // r12

v0 = malloc(0x28uLL);
*v0 = xurfaced_menu_option_list_create();
return v0;
}

canonical_decompiled_code:
_QWORD *func7()
{
_QWORD *v0; // r12

v0 = malloc(0x28uLL);
*v0 = func2();
return v0;
}

original_code:
struct xurfaced_menu *xurfaced_menu_create()
{
    struct xurfaced_menu *menu = malloc(sizeof (struct xurfaced_menu));
    menu->opts = xurfaced_menu_option_list_create();
    return menu;
}

return_type: struct xurfaced_menu { struct xurfaced_menu_option_list { struct xurfaced_menu_option { unsigned int type; char *name; char *description; char *command; struct animation_properties { float translationX; float translationY; float sizeX; float sizeY; float rotationX; float rotationY; float alpha; } animationProperties; struct xurfaced_menu_option *next; struct xurfaced_menu_option *prev; } *head; struct xurfaced_menu_option *current; } *opts; struct animation_properties animationProperties; } *


decompiled_code:
void __fastcall xurfaced_menu_destroy(void *ptr)
{
xurfaced_menu_option_list_destroy(*(_QWORD **)ptr);
free(*(void **)ptr);
free(ptr);
}

canonical_decompiled_code:
void __fastcall func8(void *ptr)
{
func3(*(_QWORD **)ptr);
free(*(void **)ptr);
free(ptr);
}

original_code:
void xurfaced_menu_destroy(struct xurfaced_menu *menu)
{
    xurfaced_menu_option_list_destroy(menu->opts);
    free(menu->opts);
    free(menu);
}


decompiled_code:
__int64 __fastcall xurfaced_menu_activate(__int64 a1)
{
__int64 result; // rax
_BYTE *v2; // rdi

result = *(_QWORD *)(*(_QWORD *)a1 + 8LL);
v2 = *(_BYTE **)(result + 24);
if ( *v2 )
result = xurfaced_execute(v2, 0LL);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1)
{
__int64 result; // rax
_BYTE *v2; // rdi

result = *(_QWORD *)(*(_QWORD *)a1 + 8LL);
v2 = *(_BYTE **)(result + 24);
if ( *v2 )
result = xurfaced_execute(v2, 0LL);
return result;
}

original_code:
void xurfaced_menu_activate(struct xurfaced_menu *menu)
{
    if (strlen(menu->opts->current->command))
        xurfaced_execute(menu->opts->current->command, 0);
}


decompiled_code:
__int64 __fastcall xurfaced_menu_next(_QWORD **a1, int a2)
{
_QWORD *v2; // rdi
__int64 result; // rax
__int64 v4; // rcx

v2 = *a1;
result = v2[1];
v4 = *(_QWORD *)(*v2 + 72LL);
if ( v4 != result )
{
while ( 1 )
{
result = *(_QWORD *)(result + 64);
if ( !result )
break;
if ( **(_BYTE **)(result + 8) )
{
--a2;
if ( v4 == result || !a2 )
break;
}
}
v2[1] = result;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func10(_QWORD **a1, int a2)
{
_QWORD *v2; // rdi
__int64 result; // rax
__int64 v4; // rcx

v2 = *a1;
result = v2[1];
v4 = *(_QWORD *)(*v2 + 72LL);
if ( v4 != result )
{
while ( 1 )
{
result = *(_QWORD *)(result + 64);
if ( !result )
break;
if ( **(_BYTE **)(result + 8) )
{
--a2;
if ( v4 == result || !a2 )
break;
}
}
v2[1] = result;
}
return result;
}

original_code:
void xurfaced_menu_next(struct xurfaced_menu *menu, unsigned int num)
{
    struct xurfaced_menu_option *option = menu->opts->current;
    if (option == menu->opts->head->prev)
        return;
    while ((option = option->next))
    {
        if (!strlen(option->name))
            continue;
        if (!--num)
            break;
        if (option == menu->opts->head->prev)
            break;
    }
    menu->opts->current = option;
}

variable_types:
num
unsigned int


decompiled_code:
double __fastcall xurfaced_render_convert(unsigned __int8 a1)
{
return (double)a1 / 255.0;
}

canonical_decompiled_code:
double __fastcall func0(unsigned __int8 a1)
{
return (double)a1 / 255.0;
}

original_code:
static double xurfaced_render_convert(unsigned int value)
{
    return (double)(value & 0xFF) / (double)0xFF;
}

variable_types:
value
unsigned int

return_type: double


decompiled_code:
__int64 __fastcall xurfaced_render_blit_background(int a1, int a2)
{
cairo_rectangle(xurfacedRenderCairo, 0.0, 0.0, (double)a1, (double)a2);
cairo_set_source(xurfacedRenderCairo, xurfacedRenderCairoBackgroundPattern);
cairo_fill_preserve(xurfacedRenderCairo);
cairo_set_source_surface(xurfacedRenderCairo, xurfacedRenderCairoBackgroundImage, 0.0);
cairo_fill_preserve(xurfacedRenderCairo);
cairo_set_source_rgba(xurfacedRenderCairo, 0.0, 0.0, 0.0, 0.8);
return cairo_fill(xurfacedRenderCairo);
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1, int a2)
{
cairo_rectangle(xurfacedRenderCairo, 0.0, 0.0, (double)a1, (double)a2);
cairo_set_source(xurfacedRenderCairo, xurfacedRenderCairoBackgroundPattern);
cairo_fill_preserve(xurfacedRenderCairo);
cairo_set_source_surface(xurfacedRenderCairo, xurfacedRenderCairoBackgroundImage, 0.0);
cairo_fill_preserve(xurfacedRenderCairo);
cairo_set_source_rgba(xurfacedRenderCairo, 0.0, 0.0, 0.0, 0.8);
return cairo_fill(xurfacedRenderCairo);
}

original_code:
static void xurfaced_render_blit_background(int width, int height)
{
    cairo_rectangle(xurfacedRenderCairo, 0, 0, width, height);
    cairo_set_source(xurfacedRenderCairo, xurfacedRenderCairoBackgroundPattern);
    cairo_fill_preserve(xurfacedRenderCairo);
    cairo_set_source_surface(xurfacedRenderCairo, xurfacedRenderCairoBackgroundImage, 0, 0);
    cairo_fill_preserve(xurfacedRenderCairo);
    cairo_set_source_rgba(xurfacedRenderCairo, 0.0, 0.0, 0.0, 0.8);
    cairo_fill(xurfacedRenderCairo);
}

variable_types: width int

variable_types: height int


decompiled_code:
void __fastcall limb_litem_destroy(void *ptr, void (__fastcall *a2)(_QWORD))
{
if ( a2 )
a2(*(_QWORD *)ptr);
free(ptr);
}

canonical_decompiled_code:
void __fastcall func0(void *ptr, void (__fastcall *a2)(_QWORD))
{
if ( a2 )
a2(*(_QWORD *)ptr);
free(ptr);
}

original_code:
void limb_litem_destroy(struct limb_litem *item, void (*pre_callback)(void *data))
{
    if (pre_callback)
        pre_callback(item->data);
    free(item);
}

variable_types: struct limb_litem { void *data; struct limb_litem *next; } *


decompiled_code:
__int64 __fastcall limb_llist_count(__int64 *a1)
{
__int64 v1; // rax
unsigned int i; // er8

v1 = *a1;
for ( i = 0; v1; ++i )
v1 = *(_QWORD *)(v1 + 8);
return i;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 *a1)
{
__int64 v1; // rax
unsigned int i; // er8

v1 = *a1;
for ( i = 0; v1; ++i )
v1 = *(_QWORD *)(v1 + 8);
return i;
}

original_code:
unsigned int limb_llist_count(struct limb_llist *list)
{
    struct limb_litem *current;
    unsigned int i = 0;
    for (current = list->head; current; current = current->next)
        i++;
    return i;
}

variable_types: struct limb_llist { struct limb_litem { void *data; struct limb_litem *next; } *head; } *

return_type: unsigned int

user_defined_types: struct limb_llist { struct limb_litem *head; }


decompiled_code:
_QWORD *limb_llist_create()
{
_QWORD *result; // rax

result = malloc(8uLL);
*result = 0LL;
return result;
}

canonical_decompiled_code:
_QWORD *func3()
{
_QWORD *result; // rax

result = malloc(8uLL);
*result = 0LL;
return result;
}

original_code:
struct limb_llist *limb_llist_create()
{
    struct limb_llist *list = (struct limb_llist *)malloc(sizeof (struct limb_llist));
    list->head = 0;
    return list;
}

return_type: struct limb_llist { struct limb_litem { void *data; struct limb_litem *next; } *head; } *


decompiled_code:
// attributes: thunk
void limb_llist_destroy(void *ptr)
{
free(ptr);
}

canonical_decompiled_code:
void func4(void *ptr)
{
free(ptr);
}

original_code:
void limb_llist_destroy(struct limb_llist *list)
{
    free(list);
}

user_defined_types: struct limb_litem { void *data; struct limb_litem *next; }


decompiled_code:
// attributes: thunk
void limb_literator_destroy(void *ptr)
{
limb_llist_destroy(ptr);
}

canonical_decompiled_code:
void func8(void *ptr)
{
func4(ptr);
}

original_code:
void limb_literator_destroy(struct limb_literator *iterator)
{
    free(iterator);
}

variable_types: struct limb_literator { struct limb_llist { struct limb_litem { void *data; struct limb_litem *next; } *head; } *list; struct limb_litem *current; } *

user_defined_types: struct limb_literator { struct limb_llist *list; struct limb_litem *current; }


decompiled_code:
void __fastcall limb_literator_reset(__int64 a1)
{
*(_QWORD *)(a1 + 8) = 0LL;
}

canonical_decompiled_code:
void __fastcall func9(__int64 a1)
{
*(_QWORD *)(a1 + 8) = 0LL;
}

original_code:
void limb_literator_reset(struct limb_literator *iterator)
{
    iterator->current = 0;
}


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
double v3; // xmm0_8
int result; // eax

if ( argc <= 2 )
{
puts("Please supply two strings to compare.");
result = 1;
}
else
{
white_similarity(argv[1], argv[2], envp);
printf("White Similarity for '%s' and '%s' is %f\n", argv[1], argv[2], v3);
result = 0;
}
return result;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
double v3; // xmm0_8
int result; // eax

if ( argc <= 2 )
{
puts("Please supply two strings to compare.");
result = 1;
}
else
{
func10(argv[1], argv[2], envp);
printf("White Similarity for '%s' and '%s' is %f\n", argv[1], argv[2], v3);
result = 0;
}
return result;
}

original_code:
int main(int argc, char *argv[]) {
  double d;
  if (argc < 3) {
    printf("Please supply two strings to compare.\n");
    return 1;
  }
  d = white_similarity(argv[1], argv[2]);
  printf("White Similarity for '%s' and '%s' is %f\n", argv[1], argv[2], d);
  return 0;
}

variable_types: d double


decompiled_code:
void __fastcall remove_pair_at(int a1, __int64 a2, int a3)
{
__int64 v4; // r12
_QWORD *v5; // r14
void *v7; // rdi

v4 = 8LL * a3;
v5 = (_QWORD *)(a2 + v4);
v7 = *(void **)(a2 + v4);
if ( v7 )
free(v7);
*v5 = 0LL;
if ( a3 < a1 )
memmove(v5, (const void *)(a2 + v4 + 8), 8LL * (unsigned int)(a1 - 1 - a3) + 8);
}

canonical_decompiled_code:
void __fastcall func7(int a1, __int64 a2, int a3)
{
__int64 v4; // r12
_QWORD *v5; // r14
void *v7; // rdi

v4 = 8LL * a3;
v5 = (_QWORD *)(a2 + v4);
v7 = *(void **)(a2 + v4);
if ( v7 )
free(v7);
*v5 = 0LL;
if ( a3 < a1 )
memmove(v5, (const void *)(a2 + v4 + 8), 8LL * (unsigned int)(a1 - 1 - a3) + 8);
}

original_code:
void remove_pair_at(int num_pairs, char **pairs, int p) {
  int i = 0;
  if (pairs[p] != ((void *)0)) free(pairs[p]);
  pairs[p] = ((void *)0);
  for (i = p; i < num_pairs; i++) {
    pairs[i] = pairs[i + 1];
  }
}

variable_types:
pairs
char **

variable_types: p int

variable_types: i int


decompiled_code:
__int64 __fastcall get_num_pairs(char *a1)
{
char v1; // al
char *v2; // rdi
unsigned int v3; // er8

v1 = *a1;
if ( !*a1 )
return 0LL;
v2 = a1 + 1;
v3 = 0;
do
{
if ( v1 != 32 )
v3 -= ((*v2 & 0xDF) == 0) - 1;
v1 = *v2++;
}
while ( v1 );
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func8(char *a1)
{
char v1; // al
char *v2; // rdi
unsigned int v3; // er8

v1 = *a1;
if ( !*a1 )
return 0LL;
v2 = a1 + 1;
v3 = 0;
do
{
if ( v1 != 32 )
v3 -= ((*v2 & 0xDF) == 0) - 1;
v1 = *v2++;
}
while ( v1 );
return v3;
}

original_code:
int get_num_pairs(char *str) {
  int i = 0;
  int num_pairs = 0;
  while (str[i] != '\0') {
    if (!((*(str + i) == ' ') || (*(str + i + 1) == ' ') || (*(str + i + 1) == '\0'))) {
      num_pairs++;
    }
    i++;
  }
  return num_pairs;
}

variable_types:
str
char *


decompiled_code:
void __fastcall destroy_letter_pairs(int a1, void **a2)
{
void **v2; // rbx

if ( a1 > 0 )
{
v2 = a2;
do
{
if ( *v2 )
free(*v2);
++v2;
}
while ( v2 != &a2[(unsigned int)(a1 - 1) + 1] );
}
free(a2);
}

canonical_decompiled_code:
void __fastcall func9(int a1, void **a2)
{
void **v2; // rbx

if ( a1 > 0 )
{
v2 = a2;
do
{
if ( *v2 )
free(*v2);
++v2;
}
while ( v2 != &a2[(unsigned int)(a1 - 1) + 1] );
}
free(a2);
}

original_code:
void destroy_letter_pairs(int num_pairs, char **pairs) {
  int i = 0;
  for (i = 0; i < num_pairs; i++) {
    if (pairs[i] != ((void *)0)) free(pairs[i]);
  }
  free(pairs);
}


decompiled_code:
double __fastcall white_similarity(char *a1, char *a2)
{
char *v2; // r13
int v3; // eax
char *v5; // r9
char *v6; // rsi
int v7; // ebp
int v8; // er12
void **v9; // r14
void **v10; // r15
int v11; // ebx
__int64 v12; // rdx
_BYTE *v13; // rax
void **v15; // [rsp+0h] [rbp-48h]
int v16; // [rsp+Ch] [rbp-3Ch]

v2 = a2;
v3 = get_num_pairs(a1);
v6 = v5;
v7 = v3;
v8 = get_num_pairs(a2);
v15 = (void **)letter_pairs(v7, v6);
v9 = (void **)letter_pairs(v8, v2);
v16 = v7 + v8;
if ( v7 <= 0 )
{
v11 = 0;
}
else
{
v10 = v15;
v11 = 0;
do
{
if ( v8 > 0 )
{
v12 = 0LL;
while ( 1 )
{
v13 = v9[v12];
if ( *(_BYTE *)*v10 == *v13 && *((_BYTE *)*v10 + 1) == v13[1] )
break;
if ( v8 == ++v12 )
goto LABEL_9;
}
--v8;
++v11;
remove_pair_at(v8, (__int64)v9, v12);
}
LABEL_9:
++v10;
}
while ( v10 != &v15[(unsigned int)(v7 - 1) + 1] );
}
destroy_letter_pairs(v7, v15);
destroy_letter_pairs(v8, v9);
return ((double)v11 + (double)v11) / (double)v16;
}

original_code:
double white_similarity(char *str1, char *str2) {
  int num_pairs1 = get_num_pairs(str1);
  int num_pairs2 = get_num_pairs(str2);
  char **pairs1 = letter_pairs(num_pairs1, str1);
  char **pairs2 = letter_pairs(num_pairs2, str2);
  int i = 0;
  int j = 0;
  int intersection = 0;
  int sum = num_pairs1 + num_pairs2;
  for (i = 0; i < num_pairs1; i++) {
    for (j = 0; j < num_pairs2; j++) {
      if ((pairs1[i][0] == pairs2[j][0] && pairs1[i][1] == pairs2[j][1])) {
        intersection++;
        num_pairs2--;
        remove_pair_at(num_pairs2, pairs2, j);
        break;
      }
    }
  }
  destroy_letter_pairs(num_pairs1, pairs1);
  destroy_letter_pairs(num_pairs2, pairs2);
  return (2.0 * intersection) / sum;
}

variable_types: j int

variable_types: intersection int

variable_types: sum int


decompiled_code:
__int64 __fastcall ft_save_grid_size(__int64 a1, __int64 a2, int *a3, int *a4)
{
int v6; // eax
__int64 result; // rax

*a3 = ft_atoi(a2);
v6 = ft_atoi(a1);
*a4 = v6;
if ( *a3 <= 6 )
{
ft_putstr(a1);
ft_putendl("\x1B[33m: is not a valable argument\x1B[0m");
ft_putendl("\x1B[33mAt least 7 columns are needed\x1B[0m");
result = 0xFFFFFFFFLL;
}
else if ( v6 <= 5 )
{
ft_putstr(a2);
ft_putendl("\x1B[33m: is not a valable argument\x1B[0m");
ft_putendl("\x1B[33mAt least 6 lines are needed\x1B[0m");
result = 0xFFFFFFFFLL;
}
else
{
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int64 a2, int *a3, int *a4)
{
int v6; // eax
__int64 result; // rax

*a3 = ft_atoi(a2);
v6 = ft_atoi(a1);
*a4 = v6;
if ( *a3 <= 6 )
{
ft_putstr(a1);
ft_putendl("\x1B[33m: is not a valable argument\x1B[0m");
ft_putendl("\x1B[33mAt least 7 columns are needed\x1B[0m");
result = 0xFFFFFFFFLL;
}
else if ( v6 <= 5 )
{
ft_putstr(a2);
ft_putendl("\x1B[33m: is not a valable argument\x1B[0m");
ft_putendl("\x1B[33mAt least 6 lines are needed\x1B[0m");
result = 0xFFFFFFFFLL;
}
else
{
result = 0LL;
}
return result;
}

original_code:
static int ft_save_grid_size(char *s1, char *s2, int *li, int *co)
{
 *li = ft_atoi(s2);
 *co = ft_atoi(s1);
 if (*li < 7)
 {
  ft_putstr(s1);
  ft_putendl("\033[33m: is not a valable argument\033[0m");
  ft_putendl("\033[33mAt least 7 columns are needed\033[0m");
  return (-1);
 }
 if (*co < 6)
 {
  ft_putstr(s2);
  ft_putendl("\033[33m: is not a valable argument\033[0m");
  ft_putendl("\033[33mAt least 6 lines are needed\033[0m");
  return (-1);
 }
 return (0);
}

variable_types:
li
int *

variable_types:
co
int *


original_code:
static int ft_init_grid(char ***grid, int li, int co)
{
 int i;
 int j;
 if (!(*grid = (char **)malloc(sizeof(char *) * (li + 1))))
  return (-1);
 i = 0;
 while (i < li)
 {
  if (!((*grid)[i] = (char *)malloc(sizeof(char) * (co + 1))))
   return (-1);
  j = 0;
  while (j < co)
  {
   (*grid)[i][j] = '.';
   ++j;
  }
  (*grid)[i][co] = '\0';
  ++i;
 }
 (*grid)[li] = ((void *)0);
 return (0);
}

variable_types:
grid
char ***

variable_types: li int

variable_types: co int


decompiled_code:
__int64 __fastcall ft_init_grid_of_choices(_QWORD *a1, int a2)
{
void *v2; // rax

v2 = malloc(4LL * a2);
*a1 = v2;
if ( !v2 )
return 0xFFFFFFFFLL;
if ( a2 > 0 )
memset(v2, 0, 4LL * a2);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(_QWORD *a1, int a2)
{
void *v2; // rax

v2 = malloc(4LL * a2);
*a1 = v2;
if ( !v2 )
return 0xFFFFFFFFLL;
if ( a2 > 0 )
memset(v2, 0, 4LL * a2);
return 0LL;
}

original_code:
static int ft_init_grid_of_choices(int **choices, int li)
{
 int i;
 if (!((*choices) = (int *)malloc(sizeof(int) * li)))
  return (-1);
 i = 0;
 while (i < li)
 {
  (*choices)[i] = 0;
  ++i;
 }
 return (0);
}

variable_types:
choices
int **


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char *v4; // [rsp+0h] [rbp-68h] BYREF
__int64 v5[3]; // [rsp+8h] [rbp-60h] BYREF
_QWORD v6[4]; // [rsp+20h] [rbp-48h] BYREF
_QWORD v7[5]; // [rsp+40h] [rbp-28h] BYREF

if ( (argc & 0xFFFFFFFD) == 1 )
{
if ( argc == 1 )
{
v5[0] = 0x600000007LL;
}
else if ( argc == 3
&& (unsigned int)ft_save_grid_size((__int64)argv[1], (__int64)argv[2], (int *)v5, (int *)v5 + 1) == -1 )
{
return -1;
}
if ( (unsigned int)ft_init_grid(&v4, v5[0], SHIDWORD(v5[0])) != -1
&& (unsigned int)ft_init_grid_of_choices(v6, v5[0]) != -1
&& (unsigned int)ft_init_grid_of_choices(v7, v5[0]) != -1 )
{
return -((unsigned int)ft_play_the_game(&v4, v6, v7) == -1);
}
return -1;
}
ft_putendl("\x1B[33m0 or 2 arguments needed to play\x1B[0m");
return -1;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char *v4; // [rsp+0h] [rbp-68h] BYREF
__int64 v5[3]; // [rsp+8h] [rbp-60h] BYREF
_QWORD v6[4]; // [rsp+20h] [rbp-48h] BYREF
_QWORD v7[5]; // [rsp+40h] [rbp-28h] BYREF

if ( (argc & 0xFFFFFFFD) == 1 )
{
if ( argc == 1 )
{
v5[0] = 0x600000007LL;
}
else if ( argc == 3
&& (unsigned int)func0((__int64)argv[1], (__int64)argv[2], (int *)v5, (int *)v5 + 1) == -1 )
{
return -1;
}
if ( (unsigned int)func1(&v4, v5[0], SHIDWORD(v5[0])) != -1
&& (unsigned int)func2(v6, v5[0]) != -1
&& (unsigned int)func2(v7, v5[0]) != -1 )
{
return -((unsigned int)ft_play_the_game(&v4, v6, v7) == -1);
}
return -1;
}
ft_putendl("\x1B[33m0 or 2 arguments needed to play\x1B[0m");
return -1;
}

original_code:
int main(int ac, char **av)
{
 t_all a;
 t_s me;
 t_s you;
 if (ac != 3 && ac != 1)
 {
  ft_putendl("\033[33m0 or 2 arguments needed to play\033[0m");
  return (-1);
 }
 if (ac == 1)
 {
  a.co = 6;
  a.li = 7;
 }
 if (ac == 3 && ft_save_grid_size(av[1], av[2], &(a.li), &(a.co)) == -1)
  return (-1);
 if (ft_init_grid(&(a.grid), a.li, a.co) == -1)
  return (-1);
 if ((ft_init_grid_of_choices(&(me.choices), a.li) == -1)
  || (ft_init_grid_of_choices(&(you.choices), a.li) == -1))
  return (-1);
 if (ft_play_the_game(&a, &me, &you) == -1)
  return (-1);
 return (0);
}

canonical_original_code:
int main(int ac, char **av)
{
 struct s_all a;
 struct s_s me;
 struct s_s you;
 if (ac != 3 && ac != 1)
 {
  ft_putendl("\033[33m0 or 2 arguments needed to play\033[0m");
  return (-1);
 }
 if (ac == 1)
 {
  a.co = 6;
  a.li = 7;
 }
 if (ac == 3 && ft_save_grid_size(av[1], av[2], &(a.li), &(a.co)) == -1)
  return (-1);
 if (ft_init_grid(&(a.grid), a.li, a.co) == -1)
  return (-1);
 if ((ft_init_grid_of_choices(&(me.choices), a.li) == -1)
  || (ft_init_grid_of_choices(&(you.choices), a.li) == -1))
  return (-1);
 if (ft_play_the_game(&a, &me, &you) == -1)
  return (-1);
 return (0);
}

variable_types: ac int

variable_types:
av
char **

variable_types: struct s_all { char **grid; int li; int co; int i; int j; }

variable_types: struct s_s { int *choices; int *save; char symb1; char symb2; int keep; }


decompiled_code:
__int64 __fastcall ft_bin_to_str(_BYTE *a1)
{
_BYTE *v1; // rax
char v2; // dl
char v3; // cl
int v4; // ecx
__int64 result; // rax

v1 = a1 + 7;
v2 = 0;
v3 = 1;
while ( 1 )
{
if ( *v1 == 49 )
v2 += v3;
v3 *= 2;
if ( v1 == a1 )
break;
--v1;
}
v4 = j_3;
*(_BYTE *)(str + j_3) = v2;
result = (unsigned int)(v4 + 1);
j_3 = v4 + 1;
if ( ++nb_bit == len )
{
*(_BYTE *)(str + (int)result) = 0;
ft_putendl(str);
j_3 = 0;
result = gfree(str);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(_BYTE *a1)
{
_BYTE *v1; // rax
char v2; // dl
char v3; // cl
int v4; // ecx
__int64 result; // rax

v1 = a1 + 7;
v2 = 0;
v3 = 1;
while ( 1 )
{
if ( *v1 == 49 )
v2 += v3;
v3 *= 2;
if ( v1 == a1 )
break;
--v1;
}
v4 = j_3;
*(_BYTE *)(str + j_3) = v2;
result = (unsigned int)(v4 + 1);
j_3 = v4 + 1;
if ( ++nb_bit == len )
{
*(_BYTE *)(str + (int)result) = 0;
func14(str);
j_3 = 0;
result = func17(str);
}
return result;
}

original_code:
void ft_bin_to_str(char *one_byte)
{
 int k;
 int i;
 int c;
 static int j = 0;
 k = 1;
 c = 0;
 i = 8;
 while (--i >= 0)
 {
  if (one_byte[i] == '1')
   c += k;
  k *= 2;
 }
 str[j] = c;
 ++j;
 ++nb_bit;
 if (nb_bit == len)
 {
  str[j] = '\0';
  ft_putendl(str);
  j = 0;
  gfree((void *)str);
 }
}

variable_types: k int

variable_types: c int


decompiled_code:
__int64 __fastcall ft_bin_to_len(_BYTE *a1, __int64 a2)
{
_BYTE *v2; // rax
unsigned int v3; // er12
__int64 v4; // rdx

v2 = a1 + 31;
v3 = 0;
LODWORD(v4) = 1;
while ( 1 )
{
if ( *v2 == 49 )
v3 += v4;
v4 = (unsigned int)(2 * v4);
if ( v2 == a1 )
break;
--v2;
}
ft_putstr("len = ", a2, v4, v2 - 1);
ft_putnbr(v3, a2);
ft_putchar(10LL);
return v3;
}

original_code:
int ft_bin_to_len(char *str_len)
{
 int k;
 int i;
 int c;
 k = 1;
 c = 0;
 i = 32;
 while (--i >= 0)
 {
  if (str_len[i] == '1')
   c += k;
  k *= 2;
 }
 ft_putstr("len = ");
 ft_putnbr(c);
 ft_putchar('\n');
 return (c);
}

variable_types: i int


decompiled_code:
__int64 __fastcall ft_bin_to_pid(_BYTE *a1)
{
_BYTE *v1; // rax
__int64 v2; // rdx
__int64 v3; // rcx
_BYTE *v4; // rsi

v1 = a1 + 31;
v2 = 0LL;
LODWORD(v3) = 1;
while ( 1 )
{
if ( *v1 == 49 )
v2 = (unsigned int)(v2 + v3);
v3 = (unsigned int)(2 * v3);
v4 = v1 - 1;
if ( v1 == a1 )
break;
--v1;
}
pid = v2;
ft_putstr("pid = ", v4, v2, v3);
ft_putnbr((unsigned int)pid, v4);
return ft_putchar(10LL);
}

canonical_decompiled_code:
__int64 __fastcall func9(_BYTE *a1)
{
_BYTE *v1; // rax
__int64 v2; // rdx
__int64 v3; // rcx
_BYTE *v4; // rsi

v1 = a1 + 31;
v2 = 0LL;
LODWORD(v3) = 1;
while ( 1 )
{
if ( *v1 == 49 )
v2 = (unsigned int)(v2 + v3);
v3 = (unsigned int)(2 * v3);
v4 = v1 - 1;
if ( v1 == a1 )
break;
--v1;
}
pid = v2;
func16("pid = ", v4, v2, v3);
func15((unsigned int)pid, v4);
return func13(10LL);
}

original_code:
void ft_bin_to_pid(char *str_pid)
{
 int k;
 int i;
 int c;
 k = 1;
 c = 0;
 i = 32;
 while (--i >= 0)
 {
  if (str_pid[i] == '1')
   c += k;
  k *= 2;
 }
 pid = c;
 ft_putstr("pid = ");
 ft_putnbr(pid);
 ft_putchar('\n');
}


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

v1 = i_2;
if ( a1 == 10 )
{
*((_BYTE *)&one_byte + i_2) = 49;
}
else if ( a1 == 12 )
{
*((_BYTE *)&one_byte + i_2) = 48;
result = (unsigned int)(v1 - 1);
if ( (int)result >= 0 )
goto LABEL_4;
goto LABEL_6;
}
result = (unsigned int)(v1 - 1);
if ( (int)result >= 0 )
{
LABEL_4:
i_2 = result;
return result;
}
LABEL_6:
i_2 = 7;
return ft_bin_to_str(&one_byte);
}

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

v1 = i_2;
if ( a1 == 10 )
{
*((_BYTE *)&one_byte + i_2) = 49;
}
else if ( a1 == 12 )
{
*((_BYTE *)&one_byte + i_2) = 48;
result = (unsigned int)(v1 - 1);
if ( (int)result >= 0 )
goto LABEL_4;
goto LABEL_6;
}
result = (unsigned int)(v1 - 1);
if ( (int)result >= 0 )
{
LABEL_4:
i_2 = result;
return result;
}
LABEL_6:
i_2 = 7;
return func7(&one_byte);
}

original_code:
void ft_signal_str(int sign)
{
 static int i = 7;
 if (sign == 10)
 {
  one_byte[i] = '1';
 }
 else if (sign == 12)
 {
  one_byte[i] = '0';
 }
 --i;
 if (i < 0)
 {
  i = 7;
  ft_bin_to_str(one_byte);
 }
}

variable_types: sign int


decompiled_code:
__int64 __fastcall ft_signal_len(int a1, int *a2)
{
__int64 v2; // rax
bool v3; // sf
__int64 result; // rax

v2 = *a2;
if ( (int)v2 < 0 )
return ft_signal_str(a1);
if ( a1 == 10 )
{
*((_BYTE *)&str_pid + v2) = 49;
LODWORD(v2) = *a2;
LABEL_7:
result = (unsigned int)(v2 - 1);
*a2 = result;
if ( (int)result < 0 )
goto LABEL_5;
return result;
}
if ( a1 != 12 )
goto LABEL_7;
*((_BYTE *)&str_pid + v2) = 48;
v3 = *a2 - 1 < 0;
result = (unsigned int)(*a2 - 1);
*a2 = result;
if ( v3 )
{
LABEL_5:
len = ft_bin_to_len(&str_pid, (__int64)a2);
result = gmalloc(len + 1);
str = result;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func11(int a1, int *a2)
{
__int64 v2; // rax
bool v3; // sf
__int64 result; // rax

v2 = *a2;
if ( (int)v2 < 0 )
return func10(a1);
if ( a1 == 10 )
{
*((_BYTE *)&str_pid + v2) = 49;
LODWORD(v2) = *a2;
LABEL_7:
result = (unsigned int)(v2 - 1);
*a2 = result;
if ( (int)result < 0 )
goto LABEL_5;
return result;
}
if ( a1 != 12 )
goto LABEL_7;
*((_BYTE *)&str_pid + v2) = 48;
v3 = *a2 - 1 < 0;
result = (unsigned int)(*a2 - 1);
*a2 = result;
if ( v3 )
{
LABEL_5:
len = func8(&str_pid, (__int64)a2);
result = func18(len + 1);
str = result;
}
return result;
}

original_code:
void ft_signal_len(int sign, int *j)
{
 if (*j < 0)
  ft_signal_str(sign);
 else
 {
  if (sign == 10)
   str_pid[*j] = '1';
  else if (sign == 12)
   str_pid[*j] = '0';
  --(*j);
  if (*j < 0)
  {
   len = ft_bin_to_len(str_pid);
   str = (char *)gmalloc(sizeof(char) * (len + 1));
  }
 }
}

variable_types:
j
int *


decompiled_code:
void __fastcall ft_signal_pid(int a1)
{
__int64 v1; // rax
int v2; // edx

if ( nb_bit == len && len )
{
j_0 = 31;
v2 = 30;
v1 = 31LL;
nb_bit = 0;
len = 0;
}
else
{
v1 = i_1;
v2 = i_1 - 1;
if ( i_1 < 0 )
{
ft_signal_len(a1, &j_0);
return;
}
}
if ( a1 == 10 )
{
*((_BYTE *)&str_pid + v1) = 49;
LABEL_9:
i_1 = v2;
if ( v2 == -1 )
goto LABEL_7;
return;
}
if ( a1 != 12 )
goto LABEL_9;
*((_BYTE *)&str_pid + v1) = 48;
i_1 = v2;
if ( v2 == -1 )
LABEL_7:
ft_bin_to_pid(&str_pid);
}

original_code:
void ft_signal_pid(int sign)
{
 static int i = 31;
 static int j = 31;
 if (nb_bit == len && len != 0)
 {
  i = 31;
  j = 31;
  nb_bit = 0;
  len = 0;
 }
 if (i < 0)
  ft_signal_len(sign, &j);
 else
 {
  if (sign == 10)
   str_pid[i] = '1';
  else if (sign == 12)
   str_pid[i] = '0';
  --i;
  if (i < 0)
   ft_bin_to_pid(str_pid);
 }
}

variable_types: j int


decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // eax

nb_bit = 0;
len = 0;
v3 = getpid();
ft_putnbr(v3, argv);
ft_putchar(10LL);
one_byte = 0x3030303030303030LL;
str_pid = (__int128)_mm_load_si128((const __m128i *)&xmmword_402020);
xmmword_4040D0 = str_pid;
str_len = str_pid;
xmmword_4040B0 = str_pid;
signal(10, ft_signal_pid);
signal(12, ft_signal_pid);
while ( 1 )
;
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // eax

nb_bit = 0;
len = 0;
v3 = getpid();
func15(v3, argv);
func13(10LL);
one_byte = 0x3030303030303030LL;
str_pid = (__int128)_mm_load_si128((const __m128i *)&xmmword_402020);
xmmword_4040D0 = str_pid;
str_len = str_pid;
xmmword_4040B0 = str_pid;
signal(10, ft_signal_pid);
signal(12, ft_signal_pid);
while ( 1 )
;
}

original_code:
int main(void)
{
 int j;
 nb_bit = 0;
 len = 0;
 ft_putnbr(getpid());
 ft_putchar('\n');
 j = 0;
 while (j < 8)
 {
  one_byte[j] = '0';
  ++j;
 }
 j = 0;
 while (j < 32)
 {
  str_pid[j] = '0';
  ++j;
 }
 j = 0;
 while (j < 32)
 {
  str_len[j] = '0';
  ++j;
 }
 signal(10, ft_signal_pid);
 signal(12, ft_signal_pid);
 while (1)
  ;
 return (0);
}

canonical_original_code:
int main()
{
 int j;
 nb_bit = 0;
 len = 0;
 ft_putnbr(getpid());
 ft_putchar('\n');
 j = 0;
 while (j < 8)
 {
  one_byte[j] = '0';
  ++j;
 }
 j = 0;
 while (j < 32)
 {
  str_pid[j] = '0';
  ++j;
 }
 j = 0;
 while (j < 32)
 {
  str_len[j] = '0';
  ++j;
 }
 signal(10, ft_signal_pid);
 signal(12, ft_signal_pid);
 while (1)
  ;
 return (0);
}


original_code:
double ft_vect_norm(t_v *vect)
{
 return (sqrt(vect->x * vect->x + vect->y * vect->y + vect->z * vect->z));
}

canonical_original_code:
double ft_vect_norm(struct s_v *vect)
{
 return (sqrt(vect->x * vect->x + vect->y * vect->y + vect->z * vect->z));
}

variable_types: struct s_v { double x; double y; double z; } *


original_code:
void ft_normalize_vect(t_v *vect)
{
 double norm;
 norm = ft_vect_norm(vect);
 vect->x *= 1 / norm;
 vect->y *= 1 / norm;
 vect->z *= 1 / norm;
}

canonical_original_code:
void ft_normalize_vect(struct s_v *vect)
{
 double norm;
 norm = ft_vect_norm(vect);
 vect->x *= 1 / norm;
 vect->y *= 1 / norm;
 vect->z *= 1 / norm;
}

variable_types: norm double

user_defined_types: struct s_v { double x; double y; double z; }


decompiled_code:
void __fastcall ft_vect_difference(double *a1, double a2, double a3, double a4, double a5, double a6, double a7, double a8, double a9, double a10, double a11, double a12, double a13, double a14, double a15)
{
*a1 = a10 - a13;
a1[1] = a11 - a14;
a1[2] = a12 - a15;
}

canonical_decompiled_code:
void __fastcall func2(double *a1, double a2, double a3, double a4, double a5, double a6, double a7, double a8, double a9, double a10, double a11, double a12, double a13, double a14, double a15)
{
*a1 = a10 - a13;
a1[1] = a11 - a14;
a1[2] = a12 - a15;
}

original_code:
void ft_vect_difference(t_v *vect, t_v vect1, t_v vect2)
{
 vect->x = vect1.x - vect2.x;
 vect->y = vect1.y - vect2.y;
 vect->z = vect1.z - vect2.z;
}

canonical_original_code:
void ft_vect_difference(struct s_v *vect, struct s_v vect1, struct s_v vect2)
{
 vect->x = vect1.x - vect2.x;
 vect->y = vect1.y - vect2.y;
 vect->z = vect1.z - vect2.z;
}


decompiled_code:
double __fastcall ft_dot_product(double a1, double a2, double a3, double a4, double a5, double a6, double a7, double a8, double a9, double a10, double a11, double a12, double a13, double a14)
{
return a9 * a12 + a10 * a13 + a11 * a14;
}

canonical_decompiled_code:
double __fastcall func3(double a1, double a2, double a3, double a4, double a5, double a6, double a7, double a8, double a9, double a10, double a11, double a12, double a13, double a14)
{
return a9 * a12 + a10 * a13 + a11 * a14;
}

original_code:
double ft_dot_product(t_v vect1, t_v vect2)
{
 return (vect1.x * vect2.x + vect1.y * vect2.y + vect1.z * vect2.z);
}

canonical_original_code:
double ft_dot_product(struct s_v vect1, struct s_v vect2)
{
 return (vect1.x * vect2.x + vect1.y * vect2.y + vect1.z * vect2.z);
}

variable_types: struct s_v { double x; double y; double z; }


original_code:
void ft_cross_product(t_v *vect, t_v *vect1, t_v *vect2)
{
 vect->x = vect1->y * vect2->z - vect1->z * vect2->y;
 vect->y = -(vect1->x * vect2->z - vect1->z * vect2->x);
 vect->z = vect1->x * vect2->y - vect1->y * vect2->x;
}

canonical_original_code:
void ft_cross_product(struct s_v *vect, struct s_v *vect1, struct s_v *vect2)
{
 vect->x = vect1->y * vect2->z - vect1->z * vect2->y;
 vect->y = -(vect1->x * vect2->z - vect1->z * vect2->x);
 vect->z = vect1->x * vect2->y - vect1->y * vect2->x;
}


decompiled_code:
__int64 __fastcall ft_init_basic_env(__int64 *a1)
{
__int64 v1; // rax
__int64 v2; // rax
_QWORD *v3; // r12
__int64 v4; // rbp
char *v5; // rax
_QWORD *v6; // r12
char *v7; // rbp

v1 = gmalloc(16LL);
*a1 = v1;
if ( !v1 )
return 0xFFFFFFFFLL;
v2 = ft_strdup("PATH=/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin");
v3 = (_QWORD *)*a1;
v4 = v2;
*v3 = ft_strjoin(v2, ":/opt/X11/bin:/usr/texbin");
gfree(v4);
v5 = getcwd(0LL, 0LL);
v6 = (_QWORD *)*a1;
v7 = v5;
v6[1] = ft_strjoin("PWD=", v5);
free(v7);
*(_QWORD *)(*a1 + 16) = 0LL;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 *a1)
{
__int64 v1; // rax
__int64 v2; // rax
_QWORD *v3; // r12
__int64 v4; // rbp
char *v5; // rax
_QWORD *v6; // r12
char *v7; // rbp

v1 = gmalloc(16LL);
*a1 = v1;
if ( !v1 )
return 0xFFFFFFFFLL;
v2 = ft_strdup("PATH=/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin");
v3 = (_QWORD *)*a1;
v4 = v2;
*v3 = ft_strjoin(v2, ":/opt/X11/bin:/usr/texbin");
gfree(v4);
v5 = getcwd(0LL, 0LL);
v6 = (_QWORD *)*a1;
v7 = v5;
v6[1] = ft_strjoin("PWD=", v5);
free(v7);
*(_QWORD *)(*a1 + 16) = 0LL;
return 0LL;
}

original_code:
static int ft_init_basic_env(char ***env)
{
 char *buf;
 if (!(*env = (char **)gmalloc(sizeof(char *) * 2)))
  return (-1);
 buf = ft_strdup("PATH=/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin");
 (*env)[0] = ft_strjoin(buf, ":/opt/X11/bin:/usr/texbin");
 gfree(buf);
 buf = ((void *)0);
 buf = getcwd(buf, 0);
 (*env)[1] = ft_strjoin("PWD=", buf);
 free(buf);
 (*env)[2] = ((void *)0);
 return (0);
}

variable_types:
env
char ***

variable_types:
buf
char *


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char **v4; // rdi
__int64 v5; // rdx
__int64 v6; // rcx
__int64 v7; // r8
__int64 v8; // r9
int v9; // er12
__int64 v10; // rdx
__int64 v11; // rcx
__int64 v12; // r8
__int64 v13; // r9
__m128i v15; // [rsp+0h] [rbp-B8h]
__int128 v16; // [rsp+40h] [rbp-78h] BYREF
__int64 v17; // [rsp+50h] [rbp-68h]
__m128i v18; // [rsp+60h] [rbp-58h] BYREF

if ( argc != 1 || !argv || !(unsigned int)ft_check_signal() )
return -1;
v4 = envp;
v17 = ft_copy_ts(envp);
if ( !v17
|| (v4 = envp, !ft_copy_ts(envp))
|| (v4 = envp, *(_QWORD *)&v16 = ft_copy_ts(envp), !(_QWORD)v16)
|| (v4 = (const char **)&v16 + 1, (unsigned int)ft_init_basic_env((__int64 *)&v16 + 1) == -1) )
{
cfree(v4);
return -1;
}
v9 = 0;
v15 = _mm_loadu_si128(&v18);
if ( (unsigned int)ft_init_terminal_mode((char *)&v16 + 8, argv, v5, v6, v7, v8, v15.m128i_i64[0], v15.m128i_i64[1]) != -1 )
v9 = ft_find_the_line_constprop_0((__int64)&v16 + 8, (__int64)argv, v10, v11, v12, v13, v16);
cfree((char *)&v16 + 8);
return v9;
}

original_code:
int main(int ac, char **av, char **env)
{
 t_env e;
 int exit;
 struct termios tattr;
 if (ac != 1 || av == ((void *)0))
  return (-1);
 exit = 0;
 if (!ft_check_signal())
  return (-1);
 if (!(e.envc = ft_copy_ts(env))
  || !(e.env = ft_copy_ts(env)))
 {
  cfree();
  return (-1);
 }
 if (!(e.env = ft_copy_ts(env)) || (ft_init_basic_env(&(e.env_s)) == -1))
 {
  cfree();
  return (-1);
 }
 if (ft_init_terminal_mode(tattr) != -1)
  exit = ft_find_the_line(e, ((void *)0), ((void *)0), ((void *)0));
 cfree();
 return (exit);
}

canonical_original_code:
int main(int ac, char **av, char **env)
{
 struct s_env e;
 int exit;
 struct termios tattr;
 if (ac != 1 || av == ((void *)0))
  return (-1);
 exit = 0;
 if (!ft_check_signal())
  return (-1);
 if (!(e.envc = ft_copy_ts(env))
  || !(e.env = ft_copy_ts(env)))
 {
  cfree();
  return (-1);
 }
 if (!(e.env = ft_copy_ts(env)) || (ft_init_basic_env(&(e.env_s)) == -1))
 {
  cfree();
  return (-1);
 }
 if (ft_init_terminal_mode(tattr) != -1)
  exit = ft_find_the_line(e, ((void *)0), ((void *)0), ((void *)0));
 cfree();
 return (exit);
}

variable_types:
env
char **

variable_types: struct s_env { char **env; char **env_s; char **envc; }

variable_types: exit int

variable_types: struct termios { unsigned int c_iflag; unsigned int c_oflag; unsigned int c_cflag; unsigned int c_lflag; unsigned char c_line; unsigned char c_cc[32]; unsigned int c_ispeed; unsigned int c_ospeed; }


decompiled_code:
__int64 __fastcall ft_find(_BYTE *a1, __int64 a2)
{
_BYTE *v2; // rbx
int v3; // eax
__int64 v4; // rbp
unsigned int v5; // er12

v2 = a1;
v3 = ft_strlen(a2);
if ( !*a1 )
return 0LL;
v4 = v3;
v5 = 0;
do
v5 += ft_strncmp(v2++, a2, v4) == 0;
while ( *v2 );
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func0(_BYTE *a1, __int64 a2)
{
_BYTE *v2; // rbx
int v3; // eax
__int64 v4; // rbp
unsigned int v5; // er12

v2 = a1;
v3 = ft_strlen(a2);
if ( !*a1 )
return 0LL;
v4 = v3;
v5 = 0;
do
v5 += ft_strncmp(v2++, a2, v4) == 0;
while ( *v2 );
return v5;
}

original_code:
int ft_find(char *s1, char *s2)
{
 int i;
 int j;
 int size;
 i = 0;
 j = 0;
 size = ft_strlen(s2);
 while (*(s1 + i))
 {
  if (ft_strncmp(s1 + i, s2, size) == 0)
   ++j;
  ++i;
 }
 return (j);
}

variable_types: size int


original_code:
static void ft_init(t_save *save)
{
 save->cursor = 0;
 save->hist_nb = 0;
 save->copy = ((void *)0);
}

canonical_original_code:
static void ft_init(struct s_save *save)
{
 save->cursor = 0;
 save->hist_nb = 0;
 save->copy = ((void *)0);
}

variable_types: struct s_save { int cursor; int co; int hist_nb; struct s_sl { char c; struct s_sl *next; struct s_sl *prev; } *copy; } *

user_defined_types: struct s_save { int cursor; int co; int hist_nb; struct s_sl *copy; }


decompiled_code:
__int64 __fastcall ft_check(__int64 a1, _QWORD *a2, _DWORD *a3, __int64 a4)
{
unsigned int v6; // er12
unsigned int v8; // er15
int v9; // eax
int v10; // eax
int v11; // eax
int v12; // eax
char v13[2]; // [rsp+8h] [rbp-40h] BYREF
unsigned __int16 v14; // [rsp+Ah] [rbp-3Eh]

ioctl(0, 0x5413uLL, v13);
a3[1] = v14;
if ( (unsigned int)ft_is_key_enter(a1) )
{
*a3 = -1;
v6 = 0;
}
else
{
v6 = 0;
v8 = (*a3 + 4) / a3[1];
v9 = ft_put_or_del_char(a1, a2, a3, a4);
if ( v9 == -1
|| v9
&& ((v10 = ft_little_move(a1, a2, a3, (unsigned int)a3[1]), v10 == -1)
|| v10
&& ((v11 = ft_fast_move(a1, a2, a3), v11 == -1)
|| v11
&& ((v12 = ft_move_in_history(a1, a2, a3, a4), v12 == -1)
|| v12 && (unsigned int)ft_cut_copy_or_paste(a1, a2, a3) == -1))) )
{
v6 = -1;
}
else
{
ft_print(*a2, a3, v8);
}
}
return v6;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, _QWORD *a2, _DWORD *a3, __int64 a4)
{
unsigned int v6; // er12
unsigned int v8; // er15
int v9; // eax
int v10; // eax
int v11; // eax
int v12; // eax
char v13[2]; // [rsp+8h] [rbp-40h] BYREF
unsigned __int16 v14; // [rsp+Ah] [rbp-3Eh]

ioctl(0, 0x5413uLL, v13);
a3[1] = v14;
if ( (unsigned int)ft_is_key_enter(a1) )
{
*a3 = -1;
v6 = 0;
}
else
{
v6 = 0;
v8 = (*a3 + 4) / a3[1];
v9 = ft_put_or_del_char(a1, a2, a3, a4);
if ( v9 == -1
|| v9
&& ((v10 = ft_little_move(a1, a2, a3, (unsigned int)a3[1]), v10 == -1)
|| v10
&& ((v11 = ft_fast_move(a1, a2, a3), v11 == -1)
|| v11
&& ((v12 = ft_move_in_history(a1, a2, a3, a4), v12 == -1)
|| v12 && (unsigned int)ft_cut_copy_or_paste(a1, a2, a3) == -1))) )
{
v6 = -1;
}
else
{
ft_print(*a2, a3, v8);
}
}
return v6;
}

original_code:
static int ft_check(char *buf, t_sl **sl, t_save *save, t_hl **hl)
{
 int go;
 struct winsize w;
 int old_line;
 go = 1;
 ioctl(0, 0x5413, &w);
 save->co = w.ws_col;
 if (ft_is_key_enter(buf))
 {
  save->cursor = -1;
  return (0);
 }
 old_line = (4 + save->cursor) / save->co;
 if (go && (go = ft_put_or_del_char(buf, sl, save, hl)) == -1)
  return (-1);
 if (go && (go = ft_little_move(buf, sl, &(save->cursor), save->co)) == -1)
  return (-1);
 if (go && (go = ft_fast_move(buf, sl, &(save->cursor))) == -1)
  return (-1);
 if (go && (go = ft_move_in_history(buf, sl, save, hl)) == -1)
  return (-1);
 if (go && (go = ft_cut_copy_or_paste(buf, sl, save)) == -1)
  return (-1);
 ft_print(*sl, save, old_line);
 return (0);
}

canonical_original_code:
static int ft_check(char *buf, struct s_sl **sl, struct s_save *save, struct s_hl **hl)
{
 int go;
 struct winsize w;
 int old_line;
 go = 1;
 ioctl(0, 0x5413, &w);
 save->co = w.ws_col;
 if (ft_is_key_enter(buf))
 {
  save->cursor = -1;
  return (0);
 }
 old_line = (4 + save->cursor) / save->co;
 if (go && (go = ft_put_or_del_char(buf, sl, save, hl)) == -1)
  return (-1);
 if (go && (go = ft_little_move(buf, sl, &(save->cursor), save->co)) == -1)
  return (-1);
 if (go && (go = ft_fast_move(buf, sl, &(save->cursor))) == -1)
  return (-1);
 if (go && (go = ft_move_in_history(buf, sl, save, hl)) == -1)
  return (-1);
 if (go && (go = ft_cut_copy_or_paste(buf, sl, save)) == -1)
  return (-1);
 ft_print(*sl, save, old_line);
 return (0);
}

variable_types: struct s_sl { char c; struct s_sl *next; struct s_sl *prev; } **

variable_types: struct s_save { int cursor; int co; int hist_nb; struct s_sl *copy; } *

variable_types: struct s_hl { struct s_sl *hist; struct s_hl *next; struct s_hl *prev; } **

variable_types: go int

variable_types: struct winsize { unsigned short ws_row; unsigned short ws_col; unsigned short ws_xpixel; unsigned short ws_ypixel; }


decompiled_code:
__int64 __fastcall ft_save_cmd_line(__int64 *a1, __int64 a2)
{
__int64 v2; // rax
char buf[7]; // [rsp+9h] [rbp-4Fh] BYREF
__int64 v5; // [rsp+10h] [rbp-48h] BYREF
__int64 v6; // [rsp+18h] [rbp-40h] BYREF
int v7[14]; // [rsp+20h] [rbp-38h] BYREF

v2 = *a1;
v6 = 0LL;
v5 = v2;
ft_init((__int64)v7);
ft_putstr("_$> ");
while ( v7[0] != -1 )
{
ft_bzero(buf, 7LL);
if ( read(0, buf, 6uLL) == -1 || (unsigned int)ft_check((__int64)buf, &v6, v7, (__int64)&v5) == -1 )
return 0xFFFFFFFFLL;
}
v7[0] = ft_slist_len(v6);
ft_print(v6, v7, (unsigned int)((v7[0] + 4) / v7[1]));
if ( (unsigned int)ft_update_history(a1, v6) != -1 )
{
ft_slist_to_ts(a2, &v6);
ft_putchar(10LL);
return 0LL;
}
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 *a1, __int64 a2)
{
__int64 v2; // rax
char buf[7]; // [rsp+9h] [rbp-4Fh] BYREF
__int64 v5; // [rsp+10h] [rbp-48h] BYREF
__int64 v6; // [rsp+18h] [rbp-40h] BYREF
int v7[14]; // [rsp+20h] [rbp-38h] BYREF

v2 = *a1;
v6 = 0LL;
v5 = v2;
func0((__int64)v7);
ft_putstr("_$> ");
while ( v7[0] != -1 )
{
ft_bzero(buf, 7LL);
if ( read(0, buf, 6uLL) == -1 || (unsigned int)func1((__int64)buf, &v6, v7, (__int64)&v5) == -1 )
return 0xFFFFFFFFLL;
}
v7[0] = ft_slist_len(v6);
ft_print(v6, v7, (unsigned int)((v7[0] + 4) / v7[1]));
if ( (unsigned int)ft_update_history(a1, v6) != -1 )
{
ft_slist_to_ts(a2, &v6);
ft_putchar(10LL);
return 0LL;
}
return 0xFFFFFFFFLL;
}

original_code:
int ft_save_cmd_line(t_hl **hl, char **line)
{
 char buf[6 + 1];
 t_hl *move;
 t_save save;
 t_sl *sl;
 sl = ((void *)0);
 move = *hl;
 ft_init(&save);
 ft_putstr("_$> ");
 while (save.cursor != -1)
 {
  ft_bzero(buf, 6 + 1);
  if (read(0, buf, 6) == -1)
   return (-1);
  if (ft_check(buf, &sl, &save, &move) == -1)
   return (-1);
 }
 save.cursor = ft_slist_len(sl);
 ft_print(sl, &save, (4 + save.cursor) / save.co);
 if (ft_update_history(hl, sl) == -1)
  return (-1);
 ft_slist_to_ts(line, &sl);
 ft_putchar('\n');
 return (0);
}

canonical_original_code:
int ft_save_cmd_line(struct s_hl **hl, char **line)
{
 char buf[-1];
 struct s_hl *move;
 struct s_save save;
 struct s_sl *sl;
 sl = ((void *)0);
 move = *hl;
 ft_init(&save);
 ft_putstr("_$> ");
 while (save.cursor != -1)
 {
  ft_bzero(buf, 6 + 1);
  if (read(0, buf, 6) == -1)
   return (-1);
  if (ft_check(buf, &sl, &save, &move) == -1)
   return (-1);
 }
 save.cursor = ft_slist_len(sl);
 ft_print(sl, &save, (4 + save.cursor) / save.co);
 if (ft_update_history(hl, sl) == -1)
  return (-1);
 ft_slist_to_ts(line, &sl);
 ft_putchar('\n');
 return (0);
}

variable_types: struct s_hl { struct s_sl { char c; struct s_sl *next; struct s_sl *prev; } *hist; struct s_hl *next; struct s_hl *prev; } **

variable_types:
line
char **

variable_types:
buf
char [-1]

variable_types: struct s_save { int cursor; int co; int hist_nb; struct s_sl { char c; struct s_sl *next; struct s_sl *prev; } *copy; }

user_defined_types: struct s_hl { struct s_sl *hist; struct s_hl *next; struct s_hl *prev; }


decompiled_code:
__int64 __fastcall ft_check_links(__int64 a1, __int64 a2)
{
__int64 result; // rax
__int64 v3; // r12
__int64 v4; // rbp

result = sf_check_links();
if ( !(_DWORD)result )
{
v3 = ft_get_name(a1, 45LL, 0LL);
if ( (unsigned int)ft_is_str_a_room(v3, *(_QWORD *)(a2 + 40))
&& (gfree(v3), v4 = ft_get_name(a1, 45LL, 1LL), (unsigned int)ft_is_str_a_room(v4, *(_QWORD *)(a2 + 40))) )
{
gfree(v4);
result = 2LL;
}
else
{
ft_putendl_fd("ERROR", 2LL);
result = 4294967291LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int64 a2)
{
__int64 result; // rax
__int64 v3; // r12
__int64 v4; // rbp

result = sf_check_links();
if ( !(_DWORD)result )
{
v3 = ft_get_name(a1, 45LL, 0LL);
if ( (unsigned int)ft_is_str_a_room(v3, *(_QWORD *)(a2 + 40))
&& (gfree(v3), v4 = ft_get_name(a1, 45LL, 1LL), (unsigned int)ft_is_str_a_room(v4, *(_QWORD *)(a2 + 40))) )
{
gfree(v4);
result = 2LL;
}
else
{
ft_putendl_fd("ERROR", 2LL);
result = 4294967291LL;
}
}
return result;
}

original_code:
static int ft_check_links(char *line, t_game *game)
{
 char *name;
 t_room *tmproom;
 int i;
 if ((i = sf_check_links(line, game)))
  return (i);
 name = ft_get_name(line, '-', 0);
 tmproom = game->tmp_room;
 if (ft_is_str_a_room(name, tmproom))
 {
  gfree(name);
  name = ft_get_name(line, '-', 1);
  tmproom = game->tmp_room;
  if (ft_is_str_a_room(name, tmproom))
  {
   gfree(name);
   return (2);
  }
 }
 ft_putendl_fd("ERROR", 2);
 return (-5);
}

canonical_original_code:
static int ft_check_links(char *line, struct s_game *game)
{
 char *name;
 struct s_room *tmproom;
 int i;
 if ((i = sf_check_links(line, game)))
  return (i);
 name = ft_get_name(line, '-', 0);
 tmproom = game->tmp_room;
 if (ft_is_str_a_room(name, tmproom))
 {
  gfree(name);
  name = ft_get_name(line, '-', 1);
  tmproom = game->tmp_room;
  if (ft_is_str_a_room(name, tmproom))
  {
   gfree(name);
   return (2);
  }
 }
 ft_putendl_fd("ERROR", 2);
 return (-5);
}

variable_types:
line
char *

variable_types: struct s_game { int nb_ant; int i_start; int i_end; char *start; char *end; struct s_room { char *name; int coord_x; int coord_y; struct s_link { char *name; struct s_link *prev; struct s_link *next; } *link; struct s_link *tmp_link; struct s_room *next; } *room; struct s_room *tmp_room; } *

variable_types:
name
char *

variable_types: i int

user_defined_types: struct s_game { int nb_ant; int i_start; int i_end; char *start; char *end; struct s_room *room; struct s_room *tmp_room; }

user_defined_types: struct s_room { char *name; int coord_x; int coord_y; struct s_link *link; struct s_link *tmp_link; struct s_room *next; }


decompiled_code:
_BOOL8 __fastcall ft_upper_to_int(_BYTE *a1)
{
_BOOL8 result; // rax
unsigned __int64 v2; // r8

if ( (unsigned __int64)((__int64 (*)(void))ft_strlen)() > 0xA )
return 1LL;
v2 = ft_strlen(a1);
result = 0LL;
if ( v2 > 8 )
{
if ( *a1 == 50 )
return (int)ft_atoi(a1 + 1) > 147483647;
return 1LL;
}
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func2(_BYTE *a1)
{
_BOOL8 result; // rax
unsigned __int64 v2; // r8

if ( (unsigned __int64)((__int64 (*)(void))ft_strlen)() > 0xA )
return 1LL;
v2 = ft_strlen(a1);
result = 0LL;
if ( v2 > 8 )
{
if ( *a1 == 50 )
return (int)ft_atoi(a1 + 1) > 147483647;
return 1LL;
}
return result;
}

original_code:
int ft_upper_to_int(char *line)
{
 int nb;
 nb = 0;
 if (ft_strlen(line) > 10)
  return (1);
 if (ft_strlen(line) < 9)
  return (0);
 else if (line[0] == '2')
 {
  nb = ft_atoi(line + 1);
  if (nb > 147483647)
   return (1);
  else
   return (0);
 }
 else
  return (1);
}

variable_types: nb int


decompiled_code:
__int64 __fastcall ft_check_line(unsigned int a1, _BYTE *a2, __int64 a3)
{
unsigned int v3; // er12
unsigned int v5; // eax
__int64 v6; // [rsp+8h] [rbp-20h]

v3 = a1;
switch ( a1 )
{
case 0u:
if ( *a2 == 45 || ft_upper_to_int(a2) || !(unsigned int)is_number(a2) || *a2 == 48 )
{
ft_putendl_fd("ERROR", 2LL);
cfree("ERROR");
exit(0);
}
return v3;
case 1u:
v6 = a3;
v5 = ft_check_coords_constprop_0(a2);
a3 = v6;
v3 = v5;
if ( v5 != 2 )
return v3;
break;
case 2u:
break;
default:
return v3;
}
return ft_check_links((__int64)a2, a3);
}

canonical_decompiled_code:
__int64 __fastcall func3(unsigned int a1, _BYTE *a2, __int64 a3)
{
unsigned int v3; // er12
unsigned int v5; // eax
__int64 v6; // [rsp+8h] [rbp-20h]

v3 = a1;
switch ( a1 )
{
case 0u:
if ( *a2 == 45 || func2(a2) || !(unsigned int)is_number(a2) || *a2 == 48 )
{
ft_putendl_fd("ERROR", 2LL);
cfree("ERROR");
exit(0);
}
return v3;
case 1u:
v6 = a3;
v5 = func1(a2);
a3 = v6;
v3 = v5;
if ( v5 != 2 )
return v3;
break;
case 2u:
break;
default:
return v3;
}
return func0((__int64)a2, a3);
}

original_code:
int ft_check_line(int index, char *line, t_game *game)
{
 if (index == 0)
 {
  if (*line == '-' || ft_upper_to_int(line) == 1
   || !(is_number(line)) || *line == '0')
  {
   ft_putendl_fd("ERROR", 2);
   cfree();
   exit(0);
  }
  return (0);
 }
 if (index == 1)
  index = ft_check_coords(index, line, game);
 if (index == 2)
  index = ft_check_links(line, game);
 return (index);
}

canonical_original_code:
int ft_check_line(int index, char *line, struct s_game *game)
{
 if (index == 0)
 {
  if (*line == '-' || ft_upper_to_int(line) == 1
   || !(is_number(line)) || *line == '0')
  {
   ft_putendl_fd("ERROR", 2);
   cfree();
   exit(0);
  }
  return (0);
 }
 if (index == 1)
  index = ft_check_coords(index, line, game);
 if (index == 2)
  index = ft_check_links(line, game);
 return (index);
}

variable_types: index int

user_defined_types: struct s_link { char *name; struct s_link *prev; struct s_link *next; }


decompiled_code:
char **__fastcall ft_syst_bin(char **argv, char **envp)
{
const char *v2; // r12
__pid_t v3; // eax
__WAIT_STATUS stat_loc; // [rsp+Ch] [rbp-1Ch] BYREF

v2 = ft_good_path(argv, envp);
if ( !v2 )
return (char **)v2;
v3 = fork();
LODWORD(stat_loc.__uptr) = v3;
if ( v3 <= 0 )
{
if ( !v3 && execve(v2, argv, envp) == -1 )
{
ft_putendl("command not found");
exit(-1);
}
return envp;
}
wait((__WAIT_STATUS)&stat_loc);
return envp;
}

canonical_decompiled_code:
char **__fastcall func2(char **argv, char **envp)
{
const char *v2; // r12
__pid_t v3; // eax
__WAIT_STATUS stat_loc; // [rsp+Ch] [rbp-1Ch] BYREF

v2 = func1(argv, envp);
if ( !v2 )
return (char **)v2;
v3 = fork();
LODWORD(stat_loc.__uptr) = v3;
if ( v3 <= 0 )
{
if ( !v3 && execve(v2, argv, envp) == -1 )
{
ft_putendl("command not found");
exit(-1);
}
return envp;
}
wait((__WAIT_STATUS)&stat_loc);
return envp;
}

original_code:
char **ft_syst_bin(char **all, char **env)
{
 int father;
 char *path;
 if (!(path = ft_good_path(all, env)))
  return (((void *)0));
 if ((father = fork()) > 0)
 {
  wait(&father);
  return (env);
 }
 else if (father == 0)
 {
  if (execve(path, all, env) == -1)
  {
   ft_putendl("command not found");
   exit(-1);
  }
 }
 return (env);
}

variable_types:
all
char **

variable_types:
env
char **

variable_types: father int

variable_types:
path
char *

return_type: char **


decompiled_code:
__int64 __fastcall ft_find_paths_in_env(_QWORD *a1)
{
__int64 v1; // r12
_QWORD *v2; // rbx
__int64 i; // rdi

v2 = a1;
for ( i = *a1; i; ++v2 )
{
if ( !(unsigned int)ft_strncmp(i, "PATH=", 5LL) )
{
v1 = ft_strsplit(*v2 + 5LL, 58LL);
if ( !v1 )
break;
}
i = v2[1];
}
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func0(_QWORD *a1)
{
__int64 v1; // r12
_QWORD *v2; // rbx
__int64 i; // rdi

v2 = a1;
for ( i = *a1; i; ++v2 )
{
if ( !(unsigned int)ft_strncmp(i, "PATH=", 5LL) )
{
v1 = ft_strsplit(*v2 + 5LL, 58LL);
if ( !v1 )
break;
}
i = v2[1];
}
return v1;
}

original_code:
static char **ft_find_paths_in_env(char **env)
{
 int i;
 char **paths;
 i = 0;
 while (env[i])
 {
  if (ft_strncmp(env[i], "PATH=", 5) == 0)
  {
   if (!(paths = ft_strsplit(&env[i][5], ':')))
    return (((void *)0));
  }
  i++;
 }
 return (paths);
}

variable_types:
paths
char **


decompiled_code:
const char *__fastcall ft_good_path(_QWORD *a1, _QWORD *a2)
{
__int64 v2; // rax
_QWORD *v3; // rbx
struct stat *v4; // r13
__int64 v5; // rax
__int64 v6; // rbp
const char *v7; // r12

v2 = ft_find_paths_in_env(a2);
if ( !v2 )
return 0LL;
v3 = (_QWORD *)v2;
v4 = (struct stat *)gmalloc(144LL);
if ( !v4 )
return 0LL;
while ( *v3 )
{
v5 = ft_strlen();
if ( !gmalloc(v5 + 1) )
return 0LL;
v6 = ft_strjoin(*v3, "/");
v7 = (const char *)ft_strjoin(v6, *a1);
gofree(v6);
if ( !lstat(v7, v4) )
return v7;
++v3;
}
return (const char *)*a1;
}

canonical_decompiled_code:
const char *__fastcall func1(_QWORD *a1, _QWORD *a2)
{
__int64 v2; // rax
_QWORD *v3; // rbx
struct stat *v4; // r13
__int64 v5; // rax
__int64 v6; // rbp
const char *v7; // r12

v2 = func0(a2);
if ( !v2 )
return 0LL;
v3 = (_QWORD *)v2;
v4 = (struct stat *)gmalloc(144LL);
if ( !v4 )
return 0LL;
while ( *v3 )
{
v5 = ft_strlen();
if ( !gmalloc(v5 + 1) )
return 0LL;
v6 = ft_strjoin(*v3, "/");
v7 = (const char *)ft_strjoin(v6, *a1);
gofree(v6);
if ( !lstat(v7, v4) )
return v7;
++v3;
}
return (const char *)*a1;
}

original_code:
static char *ft_good_path(char **all, char **env)
{
 int i;
 char *tmp;
 char *str;
 char **paths;
 struct stat *buf;
 if (!(paths = ft_find_paths_in_env(env)))
  return (((void *)0));
 if (!(buf = (struct stat *)gmalloc(sizeof(*buf))))
  return (((void *)0));
 i = 0;
 while (paths[i])
 {
  if (!(str = (char *)gmalloc(sizeof(*str) * ft_strlen(paths[i]) + 1)))
   return (((void *)0));
  tmp = ft_strjoin(paths[i], "/");
  str = ft_strjoin(tmp, all[0]);
  gofree((void *)tmp);
  if (lstat(str, buf) == 0)
   return (str);
  ++i;
 }
 return (all[0]);
}

variable_types:
tmp
char *

variable_types:
str
char *

variable_types: struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; struct timespec { long tv_sec; long tv_nsec; } st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; } *

return_type: char *

user_defined_types: struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; struct timespec st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; }


variable_types: c char

user_defined_types: struct timespec { long tv_sec; long tv_nsec; }


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

v1 = *(_DWORD *)(a1 + 24);
if ( (v1 & 0x1000) != 0 )
{
ft_putchar(112LL);
result = ft_print_rights(a1);
}
else
{
if ( (v1 & 0x2000) != 0 )
{
ft_putchar(99LL);
return ft_print_rights(a1);
}
if ( (v1 & 0x4000) == 0 )
{
if ( (v1 & 0x6000) != 0 )
{
ft_putchar(98LL);
}
else if ( (v1 & 0x8000) != 0 )
{
ft_putchar(45LL);
}
else if ( (v1 & 0xA000) != 0 )
{
ft_putchar(108LL);
}
else if ( (v1 & 0xC000) != 0 )
{
ft_putchar(115LL);
}
return ft_print_rights(a1);
}
ft_putchar(100LL);
result = ft_print_rights(a1);
}
return result;
}

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

v1 = *(_DWORD *)(a1 + 24);
if ( (v1 & 0x1000) != 0 )
{
ft_putchar(112LL);
result = func0(a1);
}
else
{
if ( (v1 & 0x2000) != 0 )
{
ft_putchar(99LL);
return func0(a1);
}
if ( (v1 & 0x4000) == 0 )
{
if ( (v1 & 0x6000) != 0 )
{
ft_putchar(98LL);
}
else if ( (v1 & 0x8000) != 0 )
{
ft_putchar(45LL);
}
else if ( (v1 & 0xA000) != 0 )
{
ft_putchar(108LL);
}
else if ( (v1 & 0xC000) != 0 )
{
ft_putchar(115LL);
}
return func0(a1);
}
ft_putchar(100LL);
result = func0(a1);
}
return result;
}

original_code:
static void ft_print_mode(struct stat *p_stat)
{
 if (0170000 & 0010000 & p_stat->st_mode)
  ft_putchar('p');
 else if (0020000 & p_stat->st_mode)
  ft_putchar('c');
 else if (0040000 & p_stat->st_mode)
  ft_putchar('d');
 else if (0060000 & p_stat->st_mode)
  ft_putchar('b');
 else if (0100000 & p_stat->st_mode)
  ft_putchar('-');
 else if (0120000 & p_stat->st_mode)
  ft_putchar('l');
 else if (0140000 & p_stat->st_mode)
  ft_putchar('s');
 ft_print_rights(p_stat);
}


decompiled_code:
int __fastcall ft_total(__int64 a1, struct stat *a2)
{
__int64 v2; // rbx
__int64 v3; // r12
int result; // eax

v2 = a1;
ft_putstr("total ");
if ( !a1 )
return 0;
v3 = 0LL;
while ( 1 )
{
result = lstat(*(const char **)v2, a2);
if ( result == -1 )
break;
v2 = *(_QWORD *)(v2 + 16);
v3 += a2->st_blocks;
if ( !v2 )
return v3;
}
return result;
}

canonical_decompiled_code:
int __fastcall func2(__int64 a1, struct stat *a2)
{
__int64 v2; // rbx
__int64 v3; // r12
int result; // eax

v2 = a1;
ft_putstr("total ");
if ( !a1 )
return 0;
v3 = 0LL;
while ( 1 )
{
result = lstat(*(const char **)v2, a2);
if ( result == -1 )
break;
v2 = *(_QWORD *)(v2 + 16);
v3 += a2->st_blocks;
if ( !v2 )
return v3;
}
return result;
}

original_code:
static int ft_total(t_ls *list, struct stat *p_stat)
{
 blkcnt_t block_size;
 block_size = 0;
 ft_putstr("total ");
 while (list != ((void *)0))
 {
  if (lstat(list->name, p_stat) == -1)
   return (-1);
  block_size += p_stat->st_blocks;
  list = list->next;
 }
 return (block_size);
}

canonical_original_code:
static int ft_total(struct s_ls *list, struct stat *p_stat)
{
 long block_size;
 block_size = 0;
 ft_putstr("total ");
 while (list != ((void *)0))
 {
  if (lstat(list->name, p_stat) == -1)
   return (-1);
  block_size += p_stat->st_blocks;
  list = list->next;
 }
 return (block_size);
}

variable_types: struct s_ls { char *name; long time; struct s_ls *next; } *


decompiled_code:
__int64 __fastcall ft_ls_l_print_info(__int64 a1)
{
struct passwd *v1; // r12
struct group *v2; // rbp
char *v3; // rax
__int64 v4; // rax

if ( !malloc(0x30uLL) || !malloc(0x20uLL) )
return 0xFFFFFFFFLL;
v1 = getpwuid(*(_DWORD *)(a1 + 28));
v2 = getgrgid(*(_DWORD *)(a1 + 32));
ft_print_mode(a1);
ft_putstr(" ");
ft_putnbr(*(unsigned int *)(a1 + 16));
ft_putchar(9LL);
ft_putstr(v1->pw_name);
ft_putstr(" ");
ft_putstr(v2->gr_name);
ft_putstr(" ");
ft_putnbr(*(unsigned int *)(a1 + 48));
ft_putstr("\t");
v3 = ctime((const time_t *)(a1 + 88));
v4 = ft_strsub(v3, 4LL, 12LL);
ft_putstr(v4);
ft_putstr(" ");
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
struct passwd *v1; // r12
struct group *v2; // rbp
char *v3; // rax
__int64 v4; // rax

if ( !malloc(0x30uLL) || !malloc(0x20uLL) )
return 0xFFFFFFFFLL;
v1 = getpwuid(*(_DWORD *)(a1 + 28));
v2 = getgrgid(*(_DWORD *)(a1 + 32));
func1(a1);
ft_putstr(" ");
ft_putnbr(*(unsigned int *)(a1 + 16));
ft_putchar(9LL);
ft_putstr(v1->pw_name);
ft_putstr(" ");
ft_putstr(v2->gr_name);
ft_putstr(" ");
ft_putnbr(*(unsigned int *)(a1 + 48));
ft_putstr("\t");
v3 = ctime((const time_t *)(a1 + 88));
v4 = ft_strsub(v3, 4LL, 12LL);
ft_putstr(v4);
ft_putstr(" ");
return 1LL;
}

original_code:
static int ft_ls_l_print_info(struct stat *p_stat)
{
 struct passwd *p_pwd;
 struct group *p_group;
 if (!(p_pwd = (struct passwd *)malloc(sizeof(*p_pwd))))
  return (-1);
 if (!(p_group = (struct group *)malloc(sizeof(*p_group))))
  return (-1);
 p_pwd = getpwuid(p_stat->st_uid);
 p_group = getgrgid(p_stat->st_gid);
 ft_print_mode(p_stat);
 ft_putstr("  ");
 ft_putnbr(p_stat->st_nlink);
 ft_putchar('\t');
 ft_putstr(p_pwd->pw_name);
 ft_putstr("  ");
 ft_putstr(p_group->gr_name);
 ft_putstr("  ");
 ft_putnbr(p_stat->st_size);
 ft_putstr("\t");
 ft_putstr(ft_strsub(ctime(&p_stat->st_mtim.tv_sec), 4, 12));
 ft_putstr(" ");
 return (1);
}

variable_types: struct passwd { char *pw_name; char *pw_passwd; unsigned int pw_uid; unsigned int pw_gid; char *pw_gecos; char *pw_dir; char *pw_shell; } *

variable_types: struct group { char *gr_name; char *gr_passwd; unsigned int gr_gid; char **gr_mem; } *


decompiled_code:
__int64 __fastcall ft_ls_l(__int64 a1)
{
const char **v1; // rbx
struct stat *v2; // rax
struct stat *v3; // rbp
unsigned int v4; // eax

v1 = (const char **)a1;
v2 = (struct stat *)malloc(0x90uLL);
if ( !v2 )
return 0xFFFFFFFFLL;
v3 = v2;
v4 = ft_total(a1, v2);
ft_putnbr(v4);
ft_putchar(10LL);
if ( a1 )
{
while ( lstat(*v1, v3) != -1 && (unsigned int)ft_ls_l_print_info((__int64)v3) != -1 )
{
ft_putendl(*v1);
v1 = (const char **)v1[2];
if ( !v1 )
return 1LL;
}
return 0xFFFFFFFFLL;
}
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1)
{
const char **v1; // rbx
struct stat *v2; // rax
struct stat *v3; // rbp
unsigned int v4; // eax

v1 = (const char **)a1;
v2 = (struct stat *)malloc(0x90uLL);
if ( !v2 )
return 0xFFFFFFFFLL;
v3 = v2;
v4 = func2(a1, v2);
ft_putnbr(v4);
ft_putchar(10LL);
if ( a1 )
{
while ( lstat(*v1, v3) != -1 && (unsigned int)func3((__int64)v3) != -1 )
{
ft_putendl(*v1);
v1 = (const char **)v1[2];
if ( !v1 )
return 1LL;
}
return 0xFFFFFFFFLL;
}
return 1LL;
}

original_code:
int ft_ls_l(t_ls *list)
{
 struct stat *p_stat;
 if (!(p_stat = (struct stat *)malloc(sizeof(*p_stat))))
  return (-1);
 ft_putnbr(ft_total(list, p_stat));
 ft_putchar('\n');
 while (list != ((void *)0))
 {
  if (lstat(list->name, p_stat) == -1)
   return (-1);
  if (ft_ls_l_print_info(p_stat) == -1)
   return (-1);
  ft_putendl(list->name);
  list = list->next;
 }
 return (1);
}

canonical_original_code:
int ft_ls_l(struct s_ls *list)
{
 struct stat *p_stat;
 if (!(p_stat = (struct stat *)malloc(sizeof(*p_stat))))
  return (-1);
 ft_putnbr(ft_total(list, p_stat));
 ft_putchar('\n');
 while (list != ((void *)0))
 {
  if (lstat(list->name, p_stat) == -1)
   return (-1);
  if (ft_ls_l_print_info(p_stat) == -1)
   return (-1);
  ft_putendl(list->name);
  list = list->next;
 }
 return (1);
}

user_defined_types: struct s_ls { char *name; long time; struct s_ls *next; }


original_code:
int ft_intersect_a_cylinder(t_r *r, void *data)
{
 t_cyl *cyl;
 t_r new_r;
 t_v coeff;
 cyl = (t_cyl *)data;
 new_r = *r;
 ft_vect_difference(&new_r.o_w, r->o_w, cyl->c);
 ft_find_coeff(&new_r, &coeff, cyl);
 if (ft_nearest_solution(coeff.x, coeff.y, coeff.z, &new_r) == -1)
  return (-1);
 r->t0 = new_r.t0;
 r->t1 = new_r.t1;
 if (r->t1 < 0)
  return (-1);
 if (r->t0 < 0)
  r->t0 = r->t1;
 return (0);
}

canonical_original_code:
int ft_intersect_a_cylinder(struct s_r *r, void *data)
{
 struct s_cyl *cyl;
 struct s_r new_r;
 struct s_v coeff;
 cyl = (struct s_cyl *)data;
 new_r = *r;
 ft_vect_difference(&new_r.o_w, r->o_w, cyl->c);
 ft_find_coeff(&new_r, &coeff, cyl);
 if (ft_nearest_solution(coeff.x, coeff.y, coeff.z, &new_r) == -1)
  return (-1);
 r->t0 = new_r.t0;
 r->t1 = new_r.t1;
 if (r->t1 < 0)
  return (-1);
 if (r->t0 < 0)
  r->t0 = r->t1;
 return (0);
}

variable_types: struct s_r { struct s_v { double x; double y; double z; } o_w; struct s_v d_w; struct s_v p_hit; struct s_v n_hit; double t0; double t1; double tnear; struct s_c { int b; int g; int r; } color; int hit_i; int hit_j; } *

variable_types:
data
void *

variable_types: struct s_cyl { struct s_v { double x; double y; double z; } c; double r; struct s_c { int b; int g; int r; } sf; char flag; } *

user_defined_types: struct s_r { struct s_v o_w; struct s_v d_w; struct s_v p_hit; struct s_v n_hit; double t0; double t1; double tnear; struct s_c color; int hit_i; int hit_j; }

user_defined_types: struct s_cyl { struct s_v c; double r; struct s_c sf; char flag; }


variable_types:
c
struct s_v *

variable_types: struct s_cyl { struct s_v c; double r; struct s_c sf; char flag; } *


decompiled_code:
__int64 __fastcall ft_new_token(__int64 *a1, _QWORD *a2, int a3, int a4)
{
__int64 v5; // rbp
__int64 v6; // rax
__int64 v7; // rbx
__int64 v8; // rax
__int64 result; // rax
__int64 v10; // rdx

v5 = a3;
v6 = gmalloc(32LL);
if ( !v6 )
return 0xFFFFFFFFLL;
v7 = v6;
v8 = ft_strsub(*a2, 0LL, v5);
*(_QWORD *)v7 = v8;
if ( !v8 )
return 0xFFFFFFFFLL;
*a2 += v5;
*(_QWORD *)(v7 + 16) = 0LL;
*(_QWORD *)(v7 + 24) = 0LL;
result = *a1;
*(_DWORD *)(v7 + 8) = a4;
if ( result )
{
do
{
v10 = result;
result = *(_QWORD *)(result + 16);
}
while ( result );
*(_QWORD *)(v7 + 24) = v10;
*(_QWORD *)(v10 + 16) = v7;
}
else
{
*a1 = v7;
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 *a1, _QWORD *a2, int a3, int a4)
{
__int64 v5; // rbp
__int64 v6; // rax
__int64 v7; // rbx
__int64 v8; // rax
__int64 result; // rax
__int64 v10; // rdx

v5 = a3;
v6 = gmalloc(32LL);
if ( !v6 )
return 0xFFFFFFFFLL;
v7 = v6;
v8 = ft_strsub(*a2, 0LL, v5);
*(_QWORD *)v7 = v8;
if ( !v8 )
return 0xFFFFFFFFLL;
*a2 += v5;
*(_QWORD *)(v7 + 16) = 0LL;
*(_QWORD *)(v7 + 24) = 0LL;
result = *a1;
*(_DWORD *)(v7 + 8) = a4;
if ( result )
{
do
{
v10 = result;
result = *(_QWORD *)(result + 16);
}
while ( result );
*(_QWORD *)(v7 + 24) = v10;
*(_QWORD *)(v10 + 16) = v7;
}
else
{
*a1 = v7;
result = 0LL;
}
return result;
}

original_code:
int ft_new_token(t_p **p, char **line, int size, int type)
{
 t_p *new;
 t_p *move;
 if (!(new = (t_p *)gmalloc(sizeof(t_p))))
  return (-1);
 if (!(new->tok = ft_strsub(*line, 0, size)))
  return (-1);
 *line = *line + size;
 new->type = type;
 new->next = ((void *)0);
 new->prev = ((void *)0);
 move = *p;
 if (*p)
 {
  while (move->next)
   move = move->next;
  new->prev = move;
  move->next = new;
 }
 else
  *p = new;
 return (0);
}

canonical_original_code:
int ft_new_token(struct s_p **p, char **line, int size, int type)
{
 struct s_p *new;
 struct s_p *move;
 if (!(new = (struct s_p *)gmalloc(sizeof(t_p))))
  return (-1);
 if (!(new->tok = ft_strsub(*line, 0, size)))
  return (-1);
 *line = *line + size;
 new->type = type;
 new->next = ((void *)0);
 new->prev = ((void *)0);
 move = *p;
 if (*p)
 {
  while (move->next)
   move = move->next;
  new->prev = move;
  move->next = new;
 }
 else
  *p = new;
 return (0);
}

variable_types: struct s_p { char *tok; int type; struct s_p *next; struct s_p *prev; } **

variable_types:
line
char **

variable_types: size int

variable_types: type int


decompiled_code:
__int64 __fastcall ft_differentiate_word_types(__int64 *a1)
{
__int64 result; // rax
__int64 v2; // rdx

for ( result = *a1; result; result = *(_QWORD *)(result + 16) )
{
while ( *(_DWORD *)(result + 8) != 11 )
{
LABEL_3:
result = *(_QWORD *)(result + 16);
if ( !result )
return result;
}
v2 = *(_QWORD *)(result + 24);
if ( !v2 )
{
*(_DWORD *)(result + 8) = 12;
goto LABEL_3;
}
*(_DWORD *)(result + 8) = ((unsigned int)(*(_DWORD *)(v2 + 8) - 8) < 6) + 12;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 *a1)
{
__int64 result; // rax
__int64 v2; // rdx

for ( result = *a1; result; result = *(_QWORD *)(result + 16) )
{
while ( *(_DWORD *)(result + 8) != 11 )
{
LABEL_3:
result = *(_QWORD *)(result + 16);
if ( !result )
return result;
}
v2 = *(_QWORD *)(result + 24);
if ( !v2 )
{
*(_DWORD *)(result + 8) = 12;
goto LABEL_3;
}
*(_DWORD *)(result + 8) = ((unsigned int)(*(_DWORD *)(v2 + 8) - 8) < 6) + 12;
}
return result;
}

original_code:
void ft_differentiate_word_types(t_p **p)
{
 t_p *move;
 move = *p;
 while (move)
 {
  if (move->type == 11)
  {
   if (!move->prev)
    move->type = 12;
   else if (move->prev->type == 11 || move->prev->type == 8
     || move->prev->type == 9 || move->prev->type == 10
     || move->prev->type == 12 || move->prev->type == 13)
    move->type = 13;
   else
    move->type = 12;
  }
  move = move->next;
 }
}

canonical_original_code:
void ft_differentiate_word_types(struct s_p **p)
{
 struct s_p *move;
 move = *p;
 while (move)
 {
  if (move->type == 11)
  {
   if (!move->prev)
    move->type = 12;
   else if (move->prev->type == 11 || move->prev->type == 8
     || move->prev->type == 9 || move->prev->type == 10
     || move->prev->type == 12 || move->prev->type == 13)
    move->type = 13;
   else
    move->type = 12;
  }
  move = move->next;
 }
}

variable_types: struct s_p { char *tok; int type; struct s_p *next; struct s_p *prev; } *


decompiled_code:
__int64 __fastcall ft_clean_list(__int64 *a1)
{
if ( (unsigned int)ft_delete_quotes_and_spaces() == -1
|| (unsigned int)ft_delete_backslashes(a1) == -1
|| (unsigned int)ft_check_wrong_nb_of_pth(*a1) == -1 )
{
return 0xFFFFFFFFLL;
}
ft_differentiate_word_types(a1);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 *a1)
{
if ( (unsigned int)ft_delete_quotes_and_spaces() == -1
|| (unsigned int)ft_delete_backslashes(a1) == -1
|| (unsigned int)ft_check_wrong_nb_of_pth(*a1) == -1 )
{
return 0xFFFFFFFFLL;
}
func1(a1);
return 0LL;
}

original_code:
int ft_clean_list(t_p **p, int ind)
{
 if (ft_delete_quotes_and_spaces(p, ind) == -1)
  return (-1);
 if (ft_delete_backslashes(p) == -1)
  return (-1);
 if (ft_check_wrong_nb_of_pth(*p) == -1)
  return (-1);
 ft_differentiate_word_types(p);
 return (0);
}

canonical_original_code:
int ft_clean_list(struct s_p **p, int ind)
{
 if (ft_delete_quotes_and_spaces(p, ind) == -1)
  return (-1);
 if (ft_delete_backslashes(p) == -1)
  return (-1);
 if (ft_check_wrong_nb_of_pth(*p) == -1)
  return (-1);
 ft_differentiate_word_types(p);
 return (0);
}

variable_types: ind int

user_defined_types: struct s_p { char *tok; int type; struct s_p *next; struct s_p *prev; }


decompiled_code:
__int64 __fastcall ft_lexical_analyzer(__int64 a1, __int64 *a2)
{
int v2; // edx
int v3; // eax
__int64 v5[2]; // [rsp+8h] [rbp-20h] BYREF
int i; // [rsp+18h] [rbp-10h] BYREF
int v7[3]; // [rsp+1Ch] [rbp-Ch] BYREF

v5[0] = a1;
for ( i = 0; *(_BYTE *)v5[0]; a1 = v5[0] )
{
v3 = ft_word_size_before_ope(a1, &i, v7);
if ( v3 )
{
ft_new_token(a2, v5, v3, 11);
if ( !*(_BYTE *)v5[0] )
return (unsigned int)-((unsigned int)ft_clean_list(a2) == -1);
}
else if ( !*(_BYTE *)v5[0] )
{
return (unsigned int)-((unsigned int)ft_clean_list(a2) == -1);
}
if ( (unsigned int)(v7[0] - 5) <= 1 || (v2 = 1, v7[0] == 9) )
v2 = 2;
ft_new_token(a2, v5, v2, v7[0]);
}
return (unsigned int)-((unsigned int)ft_clean_list(a2) == -1);
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, __int64 *a2)
{
int v2; // edx
int v3; // eax
__int64 v5[2]; // [rsp+8h] [rbp-20h] BYREF
int i; // [rsp+18h] [rbp-10h] BYREF
int v7[3]; // [rsp+1Ch] [rbp-Ch] BYREF

v5[0] = a1;
for ( i = 0; *(_BYTE *)v5[0]; a1 = v5[0] )
{
v3 = ft_word_size_before_ope(a1, &i, v7);
if ( v3 )
{
func0(a2, v5, v3, 11);
if ( !*(_BYTE *)v5[0] )
return (unsigned int)-((unsigned int)func2(a2) == -1);
}
else if ( !*(_BYTE *)v5[0] )
{
return (unsigned int)-((unsigned int)func2(a2) == -1);
}
if ( (unsigned int)(v7[0] - 5) <= 1 || (v2 = 1, v7[0] == 9) )
v2 = 2;
func0(a2, v5, v2, v7[0]);
}
return (unsigned int)-((unsigned int)func2(a2) == -1);
}

original_code:
int ft_lexical_analyzer(char *line, t_p **p)
{
 int ind;
 int type;
 int size;
 ind = 0;
 while (*line)
 {
  size = ft_word_size_before_ope(line, &ind, &type);
  if (size != 0)
   ft_new_token(p, &line, size, 11);
  if (!*line)
   break ;
  size = (type == 5 || type == 6 || type == 9) ? 2 : 1;
  ft_new_token(p, &line, size, type);
 }
 if (ft_clean_list(p, ind) == -1)
  return (-1);
 return (0);
}

canonical_original_code:
int ft_lexical_analyzer(char *line, struct s_p **p)
{
 int ind;
 int type;
 int size;
 ind = 0;
 while (*line)
 {
  size = ft_word_size_before_ope(line, &ind, &type);
  if (size != 0)
   ft_new_token(p, &line, size, 11);
  if (!*line)
   break ;
  size = (type == 5 || type == 6 || type == 9) ? 2 : 1;
  ft_new_token(p, &line, size, type);
 }
 if (ft_clean_list(p, ind) == -1)
  return (-1);
 return (0);
}

variable_types:
line
char *


decompiled_code:
__int64 __fastcall ft_grid_is_full(char **a1)
{
char *v1; // rax
char **v2; // rcx
char v3; // dl
char *v4; // rax
__int64 result; // rax

v1 = *a1;
if ( *a1 )
{
v2 = a1 + 1;
while ( 1 )
{
v3 = *v1;
v4 = v1 + 1;
if ( v3 )
break;
LABEL_8:
v1 = *v2++;
if ( !v1 )
goto LABEL_9;
}
while ( v3 != 46 )
{
v3 = *v4++;
if ( !v3 )
goto LABEL_8;
}
result = 0xFFFFFFFFLL;
}
else
{
LABEL_9:
ft_putendl("\n*** DRAW GAME ***\n");
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(char **a1)
{
char *v1; // rax
char **v2; // rcx
char v3; // dl
char *v4; // rax
__int64 result; // rax

v1 = *a1;
if ( *a1 )
{
v2 = a1 + 1;
while ( 1 )
{
v3 = *v1;
v4 = v1 + 1;
if ( v3 )
break;
LABEL_8:
v1 = *v2++;
if ( !v1 )
goto LABEL_9;
}
while ( v3 != 46 )
{
v3 = *v4++;
if ( !v3 )
goto LABEL_8;
}
result = 0xFFFFFFFFLL;
}
else
{
LABEL_9:
ft_putendl("\n*** DRAW GAME ***\n");
result = 0LL;
}
return result;
}

original_code:
static int ft_grid_is_full(char **grid)
{
 int i;
 int j;
 i = 0;
 while (grid[i])
 {
  j = 0;
  while (grid[i][j])
  {
   if (grid[i][j] == '.')
    return (-1);
   ++j;
  }
  ++i;
 }
 ft_putendl("\n***  DRAW GAME  ***\n");
 return (0);
}

variable_types:
grid
char **

variable_types: i int

variable_types: j int


decompiled_code:
__int64 __fastcall ft_init_turn(__int64 a1, __int64 a2)
{
void *v2; // rax
void *v3; // rax
unsigned int v4; // eax
time_t timer; // [rsp+8h] [rbp-20h] BYREF

v2 = malloc(0x10uLL);
*(_QWORD *)(a1 + 8) = v2;
if ( !v2 )
return 0xFFFFFFFFLL;
v3 = malloc(0x10uLL);
*(_QWORD *)(a2 + 8) = v3;
if ( !v3 )
return 0xFFFFFFFFLL;
*(_WORD *)(a1 + 16) = 20312;
*(_WORD *)(a2 + 16) = 22607;
v4 = time(&timer);
srand(v4);
return (unsigned int)(rand() % 2);
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 a2)
{
void *v2; // rax
void *v3; // rax
unsigned int v4; // eax
time_t timer; // [rsp+8h] [rbp-20h] BYREF

v2 = malloc(0x10uLL);
*(_QWORD *)(a1 + 8) = v2;
if ( !v2 )
return 0xFFFFFFFFLL;
v3 = malloc(0x10uLL);
*(_QWORD *)(a2 + 8) = v3;
if ( !v3 )
return 0xFFFFFFFFLL;
*(_WORD *)(a1 + 16) = 20312;
*(_WORD *)(a2 + 16) = 22607;
v4 = time(&timer);
srand(v4);
return (unsigned int)(rand() % 2);
}

original_code:
static int ft_init_turn(t_s *me, t_s *you)
{
 time_t tloc;
 int turn;
 if (!((*me).save = (int *)malloc(sizeof(int) * 4)))
  return (-1);
 if (!((*you).save = (int *)malloc(sizeof(int) * 4)))
  return (-1);
 (*me).symb1 = 'X';
 (*me).symb2 = 'O';
 (*you).symb1 = 'O';
 (*you).symb2 = 'X';
 srand(time(&tloc));
 turn = rand() % 2;
 return (turn);
}

canonical_original_code:
static int ft_init_turn(struct s_s *me, struct s_s *you)
{
 long tloc;
 int turn;
 if (!((*me).save = (int *)malloc(sizeof(int) * 4)))
  return (-1);
 if (!((*you).save = (int *)malloc(sizeof(int) * 4)))
  return (-1);
 (*me).symb1 = 'X';
 (*me).symb2 = 'O';
 (*you).symb1 = 'O';
 (*you).symb2 = 'X';
 srand(time(&tloc));
 turn = rand() % 2;
 return (turn);
}

variable_types: struct s_s { int *choices; int *save; char symb1; char symb2; int keep; } *

variable_types:
you
struct s_s *

variable_types: tloc long

variable_types: turn int


decompiled_code:
__int64 __fastcall ft_play_the_game(__int64 a1, __int64 a2, __int64 a3)
{
int v5; // eax
_BOOL4 v6; // ebp
int v7; // eax
__int64 v8; // rsi
__int64 v9; // rdx

v5 = ft_init_turn(a2, a3);
if ( v5 == -1 )
return 0xFFFFFFFFLL;
v6 = v5;
while ( (unsigned int)ft_won(a2, a3) == -1 && (unsigned int)ft_grid_is_full(*(char ***)a1) == -1 )
{
if ( v6 )
{
ft_update_grid_of_choices(a2, a3);
v8 = *(unsigned __int8 *)(a2 + 16);
ft_play_a_piece_isra_0((_QWORD *)a1, v8, *(_DWORD *)(a2 + 20));
}
else
{
v7 = ft_choose_where_to_play_isra_0(*(_QWORD *)a1, *(_DWORD *)(a1 + 8));
*(_DWORD *)(a3 + 20) = v7;
if ( v7 == -1 )
return 0xFFFFFFFFLL;
v8 = *(unsigned __int8 *)(a3 + 16);
ft_play_a_piece_isra_0((_QWORD *)a1, v8, v7);
}
ft_putendl("\n");
ft_print_grid("\n", v8, v9);
v6 = !v6;
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, __int64 a2, __int64 a3)
{
int v5; // eax
_BOOL4 v6; // ebp
int v7; // eax
__int64 v8; // rsi
__int64 v9; // rdx

v5 = func1(a2, a3);
if ( v5 == -1 )
return 0xFFFFFFFFLL;
v6 = v5;
while ( (unsigned int)ft_won(a2, a3) == -1 && (unsigned int)func0(*(char ***)a1) == -1 )
{
if ( v6 )
{
ft_update_grid_of_choices(a2, a3);
v8 = *(unsigned __int8 *)(a2 + 16);
ft_play_a_piece_isra_0((_QWORD *)a1, v8, *(_DWORD *)(a2 + 20));
}
else
{
v7 = func2(*(_QWORD *)a1, *(_DWORD *)(a1 + 8));
*(_DWORD *)(a3 + 20) = v7;
if ( v7 == -1 )
return 0xFFFFFFFFLL;
v8 = *(unsigned __int8 *)(a3 + 16);
ft_play_a_piece_isra_0((_QWORD *)a1, v8, v7);
}
ft_putendl("\n");
ft_print_grid("\n", v8, v9);
v6 = !v6;
}
return 0LL;
}

original_code:
int ft_play_the_game(t_all *a, t_s *me, t_s *you)
{
 int turn;
 if ((turn = ft_init_turn(me, you)) == -1)
  return (-1);
 while (ft_won(*a, me, you) == -1 && ft_grid_is_full((*a).grid) == -1)
 {
  if (turn == 0)
  {
   if (((*you).keep = ft_choose_where_to_play(*a)) == -1)
    return (-1);
   ft_play_a_piece(a, *you);
  }
  else
  {
   ft_update_grid_of_choices(*a, me, you);
   ft_play_a_piece(a, *me);
  }
  ft_putendl("\n");
  ft_print_grid(*a);
  turn = (turn == 0 ? 1 : 0);
 }
 return (0);
}

canonical_original_code:
int ft_play_the_game(struct s_all *a, struct s_s *me, struct s_s *you)
{
 int turn;
 if ((turn = ft_init_turn(me, you)) == -1)
  return (-1);
 while (ft_won(*a, me, you) == -1 && ft_grid_is_full((*a).grid) == -1)
 {
  if (turn == 0)
  {
   if (((*you).keep = ft_choose_where_to_play(*a)) == -1)
    return (-1);
   ft_play_a_piece(a, *you);
  }
  else
  {
   ft_update_grid_of_choices(*a, me, you);
   ft_play_a_piece(a, *me);
  }
  ft_putendl("\n");
  ft_print_grid(*a);
  turn = (turn == 0 ? 1 : 0);
 }
 return (0);
}

variable_types: struct s_all { char **grid; int li; int co; int i; int j; } *

user_defined_types: struct s_s { int *choices; int *save; char symb1; char symb2; int keep; }


decompiled_code:
void *ft_set_fov_angle()
{
return &fov_0;
}

canonical_decompiled_code:
void *func0()
{
return &fov_0;
}

original_code:
double *ft_set_fov_angle(void)
{
 static double fov = 3.14159265358979323846 * 60 / 180;
 return (&fov);
}

canonical_original_code:
double *ft_set_fov_angle()
{
 static double fov = 3.14159265358979323846 * 60 / 180;
 return (&fov);
}

variable_types: fov double

return_type: double *


original_code:
void ft_init_camera(t_cam *cam)
{
 ft_init_vect(&cam->b.vx, 1, 0, 0);
 ft_init_vect(&cam->b.vy, 0, 1, 0);
 ft_init_vect(&cam->b.vz, 0, 0, 1);
 ft_init_vect(&cam->ro, 0, 0, 0);
 ft_init_vect(&cam->rp, 0, 0, 0);
 ft_init_vect(&cam->trans, 0, 0, 0);
}

canonical_original_code:
void ft_init_camera(struct s_cam *cam)
{
 ft_init_vect(&cam->b.vx, 1, 0, 0);
 ft_init_vect(&cam->b.vy, 0, 1, 0);
 ft_init_vect(&cam->b.vz, 0, 0, 1);
 ft_init_vect(&cam->ro, 0, 0, 0);
 ft_init_vect(&cam->rp, 0, 0, 0);
 ft_init_vect(&cam->trans, 0, 0, 0);
}

variable_types: struct s_cam { struct s_b { struct s_v { double x; double y; double z; } vx; struct s_v vy; struct s_v vz; } b; struct s_v trans; struct s_v ro; struct s_v rp; } *

user_defined_types: struct s_cam { struct s_b b; struct s_v trans; struct s_v ro; struct s_v rp; }

user_defined_types: struct s_b { struct s_v vx; struct s_v vy; struct s_v vz; }


variable_types: struct s_v { double x; double y; double z; } *

variable_types: ratio double


decompiled_code:
__int64 __fastcall ft_a_before_send2(__int64 a1, _DWORD *a2)
{
__int64 v2; // rax
bool v3; // zf

if ( **(_DWORD **)a1 == *a2 )
return 0LL;
while ( 1 )
{
v2 = ft_swap_rr();
v3 = *(_QWORD *)(a1 + 8) == 0LL;
*(_QWORD *)a1 = v2;
if ( v3 && (unsigned int)ft_sort1(v2) == 1 )
break;
ft_putstr("rra ");
if ( **(_DWORD **)a1 == *a2 )
return 0LL;
}
ft_putstr("rra\n");
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, _DWORD *a2)
{
__int64 v2; // rax
bool v3; // zf

if ( **(_DWORD **)a1 == *a2 )
return 0LL;
while ( 1 )
{
v2 = ft_swap_rr();
v3 = *(_QWORD *)(a1 + 8) == 0LL;
*(_QWORD *)a1 = v2;
if ( v3 && (unsigned int)ft_sort1(v2) == 1 )
break;
ft_putstr("rra ");
if ( **(_DWORD **)a1 == *a2 )
return 0LL;
}
ft_putstr("rra\n");
return 1LL;
}

original_code:
static int ft_a_before_send2(t_push *list, t_min *min)
{
 int i;
 i = 0;
 while ((list->a)->nb != min->min)
 {
  list->a = ft_swap_rr(list->a);
  if (!list->b && ft_sort1(list->a) == 1)
  {
   ft_putstr("rra\n");
   return (1);
  }
  else
   ft_putstr("rra ");
 }
 return (0);
}

canonical_original_code:
static int ft_a_before_send2(struct s_push *list, struct s_min *min)
{
 int i;
 i = 0;
 while ((list->a)->nb != min->min)
 {
  list->a = ft_swap_rr(list->a);
  if (!list->b && ft_sort1(list->a) == 1)
  {
   ft_putstr("rra\n");
   return (1);
  }
  else
   ft_putstr("rra ");
 }
 return (0);
}

variable_types: struct s_push { struct s_lst { int nb; struct s_lst *next; } *a; struct s_lst *b; } *

variable_types: struct s_min { int min; int ind_min; } *

user_defined_types: struct s_push { struct s_lst *a; struct s_lst *b; }


decompiled_code:
_BOOL8 __fastcall ft_a_before_send(__int64 *a1, _DWORD *a2)
{
__int64 v2; // rax
bool v3; // zf

if ( a2[1] > (int)ft_count_elem(*a1) / 2 )
return (unsigned int)ft_a_before_send2((__int64)a1, a2) == 1;
while ( *(_DWORD *)*a1 != *a2 )
{
v2 = ft_swap_r();
v3 = a1[1] == 0;
*a1 = v2;
if ( v3 && (unsigned int)ft_sort1(v2) == 1 )
{
ft_putstr("ra\n");
return 1LL;
}
ft_putstr("ra ");
}
return 0LL;
}

canonical_decompiled_code:
_BOOL8 __fastcall func1(__int64 *a1, _DWORD *a2)
{
__int64 v2; // rax
bool v3; // zf

if ( a2[1] > (int)ft_count_elem(*a1) / 2 )
return (unsigned int)func0((__int64)a1, a2) == 1;
while ( *(_DWORD *)*a1 != *a2 )
{
v2 = ft_swap_r();
v3 = a1[1] == 0;
*a1 = v2;
if ( v3 && (unsigned int)ft_sort1(v2) == 1 )
{
ft_putstr("ra\n");
return 1LL;
}
ft_putstr("ra ");
}
return 0LL;
}

original_code:
static int ft_a_before_send(t_push *list, t_min *min)
{
 int i;
 int m;
 m = ft_count_elem(list->a);
 i = 0;
 if (min->ind_min <= m / 2)
 {
  while ((list->a)->nb != min->min)
  {
   list->a = ft_swap_r(list->a);
   if (!list->b && ft_sort1(list->a) == 1)
   {
    ft_putstr("ra\n");
    return (1);
   }
   else
    ft_putstr("ra ");
  }
 }
 else
 {
  if (ft_a_before_send2(list, min) == 1)
   return (1);
 }
 return (0);
}

canonical_original_code:
static int ft_a_before_send(struct s_push *list, struct s_min *min)
{
 int i;
 int m;
 m = ft_count_elem(list->a);
 i = 0;
 if (min->ind_min <= m / 2)
 {
  while ((list->a)->nb != min->min)
  {
   list->a = ft_swap_r(list->a);
   if (!list->b && ft_sort1(list->a) == 1)
   {
    ft_putstr("ra\n");
    return (1);
   }
   else
    ft_putstr("ra ");
  }
 }
 else
 {
  if (ft_a_before_send2(list, min) == 1)
   return (1);
 }
 return (0);
}

variable_types: m int

user_defined_types: struct s_lst { int nb; struct s_lst *next; }


decompiled_code:
__int64 __fastcall ft_put_all_b_in_a(__int64 a1)
{
__int64 v1; // rax
__int64 v2; // rbp

v1 = *(_QWORD *)(a1 + 8);
if ( !v1 )
return 1LL;
v2 = a1;
do
{
while ( *(_QWORD *)(v1 + 8) )
{
v2 = ft_swap_pa(v2);
ft_putstr("pa ");
v1 = *(_QWORD *)(v2 + 8);
if ( !v1 )
return 1LL;
}
v2 = ft_swap_pa(v2);
ft_putstr("pa\n");
v1 = *(_QWORD *)(v2 + 8);
}
while ( v1 );
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
__int64 v1; // rax
__int64 v2; // rbp

v1 = *(_QWORD *)(a1 + 8);
if ( !v1 )
return 1LL;
v2 = a1;
do
{
while ( *(_QWORD *)(v1 + 8) )
{
v2 = ft_swap_pa(v2);
ft_putstr("pa ");
v1 = *(_QWORD *)(v2 + 8);
if ( !v1 )
return 1LL;
}
v2 = ft_swap_pa(v2);
ft_putstr("pa\n");
v1 = *(_QWORD *)(v2 + 8);
}
while ( v1 );
return 1LL;
}

original_code:
static int ft_put_all_b_in_a(t_push *list)
{
 while (list->b)
 {
  if ((list->b)->next)
  {
   list = ft_swap_pa(list);
   ft_putstr("pa ");
  }
  else
  {
   list = ft_swap_pa(list);
   ft_putstr("pa\n");
  }
 }
 return (1);
}

canonical_original_code:
static int ft_put_all_b_in_a(struct s_push *list)
{
 while (list->b)
 {
  if ((list->b)->next)
  {
   list = ft_swap_pa(list);
   ft_putstr("pa ");
  }
  else
  {
   list = ft_swap_pa(list);
   ft_putstr("pa\n");
  }
 }
 return (1);
}


decompiled_code:
__int64 __fastcall ft_change_value_variable(__int64 a1, __int64 a2, _QWORD **a3)
{
__int64 v4; // rbx
__int64 v5; // rax
unsigned int v6; // er12
__int64 v7; // rax

if ( !**a3 )
return (unsigned int)-1;
v4 = 0LL;
while ( 1 )
{
v5 = ft_strlen(a1);
v6 = ft_strncmp((*a3)[v4], a1, v5);
if ( !v6 )
break;
if ( !(*a3)[++v4] )
return (unsigned int)-1;
}
if ( !(*a3)[v4] )
return (unsigned int)-1;
gfree();
if ( a2 )
v7 = ft_strjoin(a1, a2);
else
v7 = ft_strdup(a1);
(*a3)[v4] = v7;
return v6;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int64 a2, _QWORD **a3)
{
__int64 v4; // rbx
__int64 v5; // rax
unsigned int v6; // er12
__int64 v7; // rax

if ( !**a3 )
return (unsigned int)-1;
v4 = 0LL;
while ( 1 )
{
v5 = ft_strlen(a1);
v6 = ft_strncmp((*a3)[v4], a1, v5);
if ( !v6 )
break;
if ( !(*a3)[++v4] )
return (unsigned int)-1;
}
if ( !(*a3)[v4] )
return (unsigned int)-1;
gfree();
if ( a2 )
v7 = ft_strjoin(a1, a2);
else
v7 = ft_strdup(a1);
(*a3)[v4] = v7;
return v6;
}

original_code:
int ft_change_value_variable(char *var, char *val, char ***env)
{
 int i;
 i = 0;
 while ((*env)[i] && ft_strncmp((*env)[i], var, ft_strlen(var)))
  ++i;
 if (!((*env)[i]))
  return (-1);
 gfree((*env)[i]);
 (*env)[i] = val ? ft_strjoin(var, val) : ft_strdup(var);
 return (0);
}

variable_types:
var
char *

variable_types:
val
char *

variable_types:
env
char ***


original_code:
int ft_add_var(char *var, char *val, char ***env)
{
 int i;
 char **new_env;
 char *new_line;
 new_line = ((void *)0);
 i = 0;
 while ((*env)[i])
  ++i;
 if (!(new_env = gmalloc(sizeof(char *) * (i + 2))))
  return (-1);
 i = -1;
 while ((*env)[++i])
  new_env[i] = (char *)c_calls("dup", (void *)(*env)[i]);
 gfree((void *)*env);
 new_line = ft_strjoin(var, "=");
 new_env[i] = val ? ft_strjoin(new_line, val) : ft_strdup(new_line);
 new_env[++i] = ((void *)0);
 gfree(new_line);
 *env = new_env;
 return (0);
}

variable_types: i int


decompiled_code:
__int64 __fastcall ft_replace_or_add(__int64 *a1, __int64 *a2)
{
__int64 *v2; // rax
__int64 v4; // rdi
__int64 v5; // rbp
__int64 v6; // rax
__int64 *v8; // rdx
__int64 v9; // rsi
__int64 v10; // rax

v2 = (__int64 *)a1[2];
v4 = *a1;
if ( v2 )
{
v5 = *v2;
v6 = ft_strjoin(v4, &unk_353);
if ( (unsigned int)ft_change_value_variable(v6, v5, (_QWORD **)a2) != -1 )
return 0LL;
v8 = a2;
v9 = *(_QWORD *)a1[2];
}
else
{
v10 = ft_strjoin(v4, &unk_353);
if ( (unsigned int)ft_change_value_variable(v10, 0LL, (_QWORD **)a2) != -1 )
return 0LL;
v8 = a2;
v9 = 0LL;
}
return (unsigned int)-((unsigned int)ft_add_var(*a1, v9, v8) == -1);
}

original_code:
int ft_replace_or_add(t_p *move, char ***env)
{
 if (move->next)
 {
  if (ft_change_value_variable(ft_strjoin(move->tok, "="),
          move->next->tok, env) == -1)
  {
   if (ft_add_var(move->tok, move->next->tok, env) == -1)
    return (-1);
  }
  return (0);
 }
 else
 {
  if (ft_change_value_variable(ft_strjoin(move->tok, "="),
          ((void *)0), env) == -1)
  {
   if (ft_add_var(move->tok, ((void *)0), env) == -1)
    return (-1);
  }
 }
 return (0);
}

canonical_original_code:
int ft_replace_or_add(struct s_p *move, char ***env)
{
 if (move->next)
 {
  if (ft_change_value_variable(ft_strjoin(move->tok, "="),
          move->next->tok, env) == -1)
  {
   if (ft_add_var(move->tok, move->next->tok, env) == -1)
    return (-1);
  }
  return (0);
 }
 else
 {
  if (ft_change_value_variable(ft_strjoin(move->tok, "="),
          ((void *)0), env) == -1)
  {
   if (ft_add_var(move->tok, ((void *)0), env) == -1)
    return (-1);
  }
 }
 return (0);
}

variable_types: struct s_p { char *tok; int type; struct s_p *next; struct s_p *prev; } *