decompiled_code:
int __fastcall read_string(char *s1)
{
int result; // eax

_fpurge(stdin);
*s1 = -1;
gets(s1);
result = strcasecmp(s1, "sair");
if ( !result )
{
puts("Finalizando o programa a pedido do usuario.");
exit(0);
}
return result;
}

canonical_decompiled_code:
int __fastcall func0(char *s1)
{
int result; // eax

_fpurge(stdin);
*s1 = -1;
gets(s1);
result = strcasecmp(s1, "sair");
if ( !result )
{
puts("Finalizando o programa a pedido do usuario.");
exit(0);
}
return result;
}

original_code:
char * read_string(char *str) {
    __fpurge(stdin);
    *str = -1;
    gets(str);
    if (!strcasecmp(str, "sair")) {
        printf("Finalizando o programa a pedido do usuario.\n");
        exit(0);
    }
}

canonical_original_code:
char *read_string(char *str) {
    __fpurge(stdin);
    *str = -1;
    gets(str);
    if (!strcasecmp(str, "sair")) {
        printf("Finalizando o programa a pedido do usuario.\n");
        exit(0);
    }
}


repo: samirfor/samirforshell

decompiled_code:
_BYTE *input_malloc()
{
_BYTE *result; // rax

result = malloc(0xC8uLL);
if ( !result )
{
printf("%s: ERRO FATAL -> Nao foi possivel alocar memoria.\n", "strings.c");
exit(1);
}
*result = 0;
return result;
}

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

result = malloc(0xC8uLL);
if ( !result )
{
printf("%s: ERRO FATAL -> Nao foi possivel alocar memoria.\n", "strings.c");
exit(1);
}
*result = 0;
return result;
}

original_code:
char * input_malloc() {
    char *input = malloc(200 * sizeof (char));
    if (!input) {
        printf("%s: ERRO FATAL -> Nao foi possivel alocar memoria.\n", "strings.c");
        exit(1);
    }
    strcpy(input, "");
    return input;
}

canonical_original_code:
char *input_malloc() {
    char *input = malloc(200 * sizeof (char));
    if (!input) {
        printf("%s: ERRO FATAL -> Nao foi possivel alocar memoria.\n", "strings.c");
        exit(1);
    }
    strcpy(input, "");
    return input;
}

variable_types:
input
char *

return_type: char *


decompiled_code:
_BOOL8 __fastcall be_sure(char *s1)
{
char v1; // al

do
{
printf("Digite [s] para confirmar ou [n] abortar: ");
read_string(s1);
v1 = *s1 & 0xDF;
}
while ( v1 != 78 && v1 != 83 );
return v1 == 83;
}

canonical_decompiled_code:
_BOOL8 __fastcall func2(char *s1)
{
char v1; // al

do
{
printf("Digite [s] para confirmar ou [n] abortar: ");
func0(s1);
v1 = *s1 & 0xDF;
}
while ( v1 != 78 && v1 != 83 );
return v1 == 83;
}

original_code:
int be_sure(char *input) {
    do {
        printf("Digite [s] para confirmar ou [n] abortar: ");
        read_string(input);
    } while (*input != 's' && *input != 'n' && *input != 'S' && *input != 'N');
    if (*input == 's' || *input == 'S') {
        return 1;
    } else {
        return 0;
    }
}

return_type: int


decompiled_code:
_BOOL8 __fastcall input_overflow(char *s, char *a2)
{
size_t v2; // rbx

v2 = strlen(a2);
return v2 > strlen(s);
}

canonical_decompiled_code:
_BOOL8 __fastcall func3(char *s, char *a2)
{
size_t v2; // rbx

v2 = strlen(a2);
return v2 > strlen(s);
}

original_code:
int input_overflow(char *string, char *input) {
    if (strlen(input) > strlen(string))
        return 1;
    else
        return 0;
}

variable_types:
string
char *


readLine

decompiled_code:
char *readLine()
{
char *lineptr; // [rsp+8h] [rbp-10h] BYREF

lineptr = 0LL;
read = getline(&lineptr, &lineLen, fp);
if ( read == -1 )
exit(0);
++lineNum;
return lineptr;
}

canonical_decompiled_code:
char *func0()
{
char *lineptr; // [rsp+8h] [rbp-10h] BYREF

lineptr = 0LL;
read = getline(&lineptr, &lineLen, fp);
if ( read == -1 )
exit(0);
++lineNum;
return lineptr;
}

original_code:
char *readLine() {
    char *line = ((void *)0);
    read = getline(&line, &lineLen, fp);
    if (read == -1)
        exit(0);
    lineNum++;
    return line;
}

variable_types:
line
char *


decompiled_code:
void *__fastcall str_replace(char *src, char *needle, char *s)
{
char *v3; // r12
char *v4; // rbx
size_t v5; // r14
char *v6; // rbx
__int64 v7; // rbp
size_t v8; // rbx
char *v9; // rax
char *v10; // rax
char *v11; // r13
signed __int64 v12; // rbp
char *v13; // r13
char *v14; // rax
char *v15; // rbx
size_t v17; // [rsp+8h] [rbp-50h]
void *v19; // [rsp+18h] [rbp-40h]

v3 = src;
v4 = s;
v17 = strlen(needle);
v5 = strlen(v4);
v6 = src;
v7 = 0LL;
if ( v17 == v5 )
{
v8 = strlen(src);
}
else
{
while ( 1 )
{
v9 = strstr(v6, needle);
if ( !v9 )
break;
++v7;
v6 = &v9[v17];
}
v8 = strlen(v6) + (v5 - v17) * v7 + v6 - src;
}
v10 = (char *)malloc(v8 + 1);
v19 = v10;
if ( v10 )
{
v11 = v10;
while ( 1 )
{
v14 = strstr(v3, needle);
v15 = v14;
if ( !v14 )
break;
v12 = v14 - v3;
memcpy(v11, v3, v14 - v3);
v13 = &v11[v12];
memcpy(v13, s, v5);
v11 = &v13[v5];
v3 = &v15[v17];
}
strcpy(v11, v3);
}
return v19;
}

canonical_decompiled_code:
void *__fastcall func1(char *src, char *needle, char *s)
{
char *v3; // r12
char *v4; // rbx
size_t v5; // r14
char *v6; // rbx
__int64 v7; // rbp
size_t v8; // rbx
char *v9; // rax
char *v10; // rax
char *v11; // r13
signed __int64 v12; // rbp
char *v13; // r13
char *v14; // rax
char *v15; // rbx
size_t v17; // [rsp+8h] [rbp-50h]
void *v19; // [rsp+18h] [rbp-40h]

v3 = src;
v4 = s;
v17 = strlen(needle);
v5 = strlen(v4);
v6 = src;
v7 = 0LL;
if ( v17 == v5 )
{
v8 = strlen(src);
}
else
{
while ( 1 )
{
v9 = strstr(v6, needle);
if ( !v9 )
break;
++v7;
v6 = &v9[v17];
}
v8 = strlen(v6) + (v5 - v17) * v7 + v6 - src;
}
v10 = (char *)malloc(v8 + 1);
v19 = v10;
if ( v10 )
{
v11 = v10;
while ( 1 )
{
v14 = strstr(v3, needle);
v15 = v14;
if ( !v14 )
break;
v12 = v14 - v3;
memcpy(v11, v3, v14 - v3);
v13 = &v11[v12];
memcpy(v13, s, v5);
v11 = &v13[v5];
v3 = &v15[v17];
}
strcpy(v11, v3);
}
return v19;
}

original_code:
char *str_replace(char *str, char *old, char *new) {
    char *ret, *r;
    const char *p, *q;
    size_t oldlen = strlen(old);
    size_t count, retlen, newlen = strlen(new);
    if (oldlen != newlen) {
        for (count = 0, p = str; (q = strstr(p, old)) != ((void *)0); p = q + oldlen)
            count++;
        retlen = p - str + strlen(p) + count * (newlen - oldlen);
    } else
        retlen = strlen(str);
    if ((ret = malloc(retlen + 1)) == ((void *)0))
        return ((void *)0);
    for (r = ret, p = str; (q = strstr(p, old)) != ((void *)0); p = q + oldlen) {
        ptrdiff_t l = q - p;
        memcpy(r, p, l);
        r += l;
        memcpy(r, new, newlen);
        r += newlen;
    }
    strcpy(r, p);
    return ret;
}

canonical_original_code:
char *str_replace(char *str, char *old, char *new) {
    char *ret; char *r;
    char *p; char *q;
    unsigned long oldlen = strlen(old);
    unsigned long count; unsigned long retlen; unsigned long newlen = strlen(new);
    if (oldlen != newlen) {
        for (count = 0, p = str; (q = strstr(p, old)) != ((void *)0); p = q + oldlen)
            count++;
        retlen = p - str + strlen(p) + count * (newlen - oldlen);
    } else
        retlen = strlen(str);
    if ((ret = malloc(retlen + 1)) == ((void *)0))
        return ((void *)0);
    for (r = ret, p = str; (q = strstr(p, old)) != ((void *)0); p = q + oldlen) {
        long l = q - p;
        memcpy(r, p, l);
        r += l;
        memcpy(r, new, newlen);
        r += newlen;
    }
    strcpy(r, p);
    return ret;
}

variable_types:
str
char *

variable_types:
old
char *

variable_types:
new
char *

variable_types:
ret
char *

variable_types:
r
char *

variable_types:
p
char *

variable_types:
q
char *

variable_types:
oldlen
unsigned long

variable_types:
count
unsigned long

variable_types:
retlen
unsigned long

variable_types:
newlen
unsigned long

variable_types: l long


decompiled_code:
__int64 __fastcall binary_decimal(int a1)
{
int v1; // ebp
int v2; // er12
int v3; // er13
int v4; // ebx

v1 = a1;
if ( a1 )
{
v2 = 0;
v3 = 0;
do
{
v4 = v1 % 10;
v1 /= 10;
v3 = (int)((double)v4 * pow(2.0, (double)v2++) + (double)v3);
}
while ( v1 );
}
else
{
v3 = 0;
}
return (unsigned int)v3;
}

canonical_decompiled_code:
__int64 __fastcall func2(int a1)
{
int v1; // ebp
int v2; // er12
int v3; // er13
int v4; // ebx

v1 = a1;
if ( a1 )
{
v2 = 0;
v3 = 0;
do
{
v4 = v1 % 10;
v1 /= 10;
v3 = (int)((double)v4 * pow(2.0, (double)v2++) + (double)v3);
}
while ( v1 );
}
else
{
v3 = 0;
}
return (unsigned int)v3;
}

original_code:
int binary_decimal(int n) {
    int decimal = 0, i = 0, rem;
    while (n != 0) {
        rem = n % 10;
        n /= 10;
        decimal += rem * pow(2, i);
        ++i;
    }
    return decimal;
}

canonical_original_code:
int binary_decimal(int n) {
    int decimal = 0; int i = 0; int rem;
    while (n != 0) {
        rem = n % 10;
        n /= 10;
        decimal += rem * pow(2, i);
        ++i;
    }
    return decimal;
}

variable_types: n int

variable_types: decimal int

variable_types: i int

variable_types: rem int


parseInt

decompiled_code:
__int64 __fastcall parseInt(char *a1)
{
char *v1; // rax
const char *v2; // rax
int v3; // eax

v1 = (char *)str_replace(a1, ".", "0");
v2 = (const char *)str_replace(v1, "_", "1");
v3 = atoi(v2);
return binary_decimal(v3);
}

canonical_decompiled_code:
__int64 __fastcall func3(char *a1)
{
char *v1; // rax
const char *v2; // rax
int v3; // eax

v1 = (char *)func1(a1, ".", "0");
v2 = (const char *)func1(v1, "_", "1");
v3 = atoi(v2);
return func2(v3);
}

original_code:
int parseInt(char *token) {
    char *semiMorse = str_replace(token, ".", "0");
    char *binary = str_replace(semiMorse, "_", "1");
    int bin = atoi(binary);
    return binary_decimal(bin);
}

variable_types:
token
char *

variable_types:
semiMorse
char *

variable_types:
binary
char *

variable_types: bin int


jumpLine

decompiled_code:
void jumpLine()
{
char *v0; // rax
int v1; // ebx
char *lineptr; // [rsp+8h] [rbp-10h] BYREF

lineptr = 0LL;
v0 = strtok(0LL, " ");
v1 = parseInt(v0) - 1;
rewind(fp);
lineNum = 0;
if ( v1 )
{
do
{
read = getline(&lineptr, &lineLen, fp);
if ( read == -1 )
{
puts("Error: Line not found.");
exit(2);
}
++lineNum;
}
while ( lineNum != v1 );
}
}

canonical_decompiled_code:
void func4()
{
char *v0; // rax
int v1; // ebx
char *lineptr; // [rsp+8h] [rbp-10h] BYREF

lineptr = 0LL;
v0 = strtok(0LL, " ");
v1 = func3(v0) - 1;
rewind(fp);
lineNum = 0;
if ( v1 )
{
do
{
read = getline(&lineptr, &lineLen, fp);
if ( read == -1 )
{
puts("Error: Line not found.");
exit(2);
}
++lineNum;
}
while ( lineNum != v1 );
}
}

original_code:
void jumpLine(char *token) {
    char *line = ((void *)0);
    token = strtok(((void *)0), " ");
    int data = parseInt(token);
    data--;
    rewind(fp);
    lineNum = 0;
    while (lineNum != data) {
        read = getline(&line, &lineLen, fp);
        if (read == -1) {
            printf("Error: Line not found.\n");
            exit(2);
        }
        lineNum++;
    }
}

variable_types:
line
char *

variable_types: data int

return_type: void


main

canonical_name: main

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

if ( argc > 1 )
{
initStacks(argc, argv, envp);
openFile(argv[1]);
while ( 1 )
{
v3 = readLine();
parseTokens(v3);
}
}
puts("Error! No input file specified.");
exit(1);
}

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

if ( argc > 1 )
{
initStacks(argc, argv, envp);
openFile(argv[1]);
while ( 1 )
{
v3 = func0();
func5(v3);
}
}
puts("Error! No input file specified.");
exit(1);
}

original_code:
int main(int argc, char *argv[]) {
    if (argc <= 1) {
        printf("Error! No input file specified.\n");
        exit(1);
    } else {
        initStacks();
        openFile(argv[1]);
        while (1) {
            parseTokens(readLine());
        }
    }
}

variable_types: argc int

variable_types:
argv
char *[]


initStacks

decompiled_code:
void initStacks()
{
intTop = 0LL;
charTop = 0LL;
}

canonical_decompiled_code:
void func0()
{
intTop = 0LL;
charTop = 0LL;
}

original_code:
void initStacks() {
    intTop = ((void *)0);
    charTop = ((void *)0);
}


popInt

decompiled_code:
__int64 popInt()
{
void *v0; // rdi
unsigned int v1; // ebx

v0 = intTop;
v1 = *(_DWORD *)intTop;
intTop = (void *)*((_QWORD *)intTop + 1);
free(v0);
return v1;
}

canonical_decompiled_code:
__int64 func1()
{
void *v0; // rdi
unsigned int v1; // ebx

v0 = intTop;
v1 = *(_DWORD *)intTop;
intTop = (void *)*((_QWORD *)intTop + 1);
free(v0);
return v1;
}

original_code:
int popInt() {
    struct intNode *var = intTop;
    int data;
    if (var == intTop) {
        data = intTop->data;
        intTop = intTop->next;
        free(var);
    } else
        printf("Error: Empty Integer Stack.\n");
    return data;
}

variable_types: struct intNode { int data; struct intNode *next; } *


peekInt

decompiled_code:
__int64 peekInt()
{
unsigned int v0; // ebx

v0 = popInt();
pushInt(v0);
return v0;
}

canonical_decompiled_code:
__int64 func2()
{
unsigned int v0; // ebx

v0 = func1();
pushInt(v0);
return v0;
}

original_code:
int peekInt() {
    int data = popInt();
    pushInt(data);
    return data;
}


popChar

decompiled_code:
__int64 popChar()
{
void *v0; // rdi
unsigned int v1; // ebx

v0 = charTop;
v1 = *(unsigned __int8 *)charTop;
charTop = (void *)*((_QWORD *)charTop + 1);
free(v0);
return v1;
}

canonical_decompiled_code:
__int64 func3()
{
void *v0; // rdi
unsigned int v1; // ebx

v0 = charTop;
v1 = *(unsigned __int8 *)charTop;
charTop = (void *)*((_QWORD *)charTop + 1);
free(v0);
return v1;
}

original_code:
char popChar() {
    struct charNode *var = charTop;
    char data;
    if (var == charTop) {
        data = charTop->data;
        charTop = charTop->next;
        free(var);
    } else
        printf("Error: Empty Integer Stack.\n");
    return data;
}

variable_types: struct charNode { char data; struct charNode *next; } *

variable_types: data char

return_type: char


peekChar

decompiled_code:
__int64 peekChar()
{
unsigned int v0; // ebx

v0 = popChar();
pushChar(v0);
return v0;
}

canonical_decompiled_code:
__int64 func4()
{
unsigned int v0; // ebx

v0 = func3();
pushChar(v0);
return v0;
}

original_code:
char peekChar() {
    int data = popChar();
    pushChar(data);
    return data;
}


repo: sapht/saphtunes

decompiled_code:
const char **__fastcall song_resolve_slug(char *s2)
{
int v1; // eax
const char ***v2; // rbx
__int64 v3; // r13
const char **v4; // rbp

v1 = *(_DWORD *)(st + 8LL);
if ( v1 <= 0 )
return 0LL;
v2 = (const char ***)*st;
v3 = *st + 8LL * (unsigned int)(v1 - 1) + 8;
while ( 1 )
{
v4 = *v2;
if ( !strcmp(**v2, s2) )
break;
if ( ++v2 == (const char ***)v3 )
return 0LL;
}
return v4;
}

canonical_decompiled_code:
const char **__fastcall func0(char *s2)
{
int v1; // eax
const char ***v2; // rbx
__int64 v3; // r13
const char **v4; // rbp

v1 = *(_DWORD *)(st + 8LL);
if ( v1 <= 0 )
return 0LL;
v2 = (const char ***)*st;
v3 = *st + 8LL * (unsigned int)(v1 - 1) + 8;
while ( 1 )
{
v4 = *v2;
if ( !strcmp(**v2, s2) )
break;
if ( ++v2 == (const char ***)v3 )
return 0LL;
}
return v4;
}

original_code:
struct song *
song_resolve_slug(char* song_slug) {
    for(int i=0; i<_st.songs->len; i++) {
        if (strcmp(_st.songs->e[i]->slug, song_slug) == 0) {
            return _st.songs->e[i];
        }
    }
    return 0;
}

canonical_original_code:
struct song *song_resolve_slug(char *song_slug) {
    for(int i = 0; i<_st.songs->len; i++) {
        if (strcmp(_st.songs->e[i]->slug, song_slug) == 0) {
            return _st.songs->e[i];
        }
    }
    return 0;
}

return_type: struct song { char *slug; int render_path_len; struct git_repo { char *origin; } git; struct song_render_stat { int nullspace; } render_stat; } *

user_defined_types: struct song { char *slug; int render_path_len; struct git_repo git; struct song_render_stat render_stat; }


decompiled_code:
__int64 __fastcall song_print_metadata(const char **a1)
{
if ( a1 )
{
puts("asd");
printf("%p\n", a1);
puts(a1[1]);
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(const char **a1)
{
if ( a1 )
{
puts("asd");
printf("%p\n", a1);
puts(a1[1]);
}
return 0LL;
}

original_code:
int
song_print_metadata(struct song *e) {
    if (e == 0) {
        return 0;
    }
    printf("%s\n", "asd");
    printf("%p\n", e);
    printf("%s\n", e->path);
    return 0;
    for(int i=0; i<_st.albums->len; i++) {
        for(int j=0; j<_st.albums->e[i]->songs.len; j++) {
            if (_st.albums->e[i]->songs.e[j] == e) {
                printf("\t%s", _st.albums->e[i]->slug);
            }
        }
    }
    putchar('\n');
    return 1;
}

canonical_original_code:
int song_print_metadata(struct song *e) {
    if (e == 0) {
        return 0;
    }
    printf("%s\n", "asd");
    printf("%p\n", e);
    printf("%s\n", e->path);
    return 0;
    for(int i = 0; i<_st.albums->len; i++) {
        for(int j = 0; j<_st.albums->e[i]->songs.len; j++) {
            if (_st.albums->e[i]->songs.e[j] == e) {
                printf("\t%s", _st.albums->e[i]->slug);
            }
        }
    }
    putchar('\n');
    return 1;
}

variable_types: struct song { char *slug; int render_path_len; struct git_repo { char *origin; } git; struct song_render_stat { int nullspace; } render_stat; } *

variable_types: j int


decompiled_code:
__int64 __fastcall song_find_by_pathname(char *s1, __int64 **a2)
{
const char *v2; // rbp
size_t v3; // rax
int v4; // eax
__int64 v5; // rbp
int v6; // eax
__int64 *v7; // rbx
__int64 v8; // r13

v2 = (const char *)st[34819];
v3 = strlen(v2);
v4 = strncmp(s1, v2, v3);
v5 = 0LL;
if ( !v4 )
{
v6 = *((_DWORD *)a2 + 2);
if ( v6 <= 0 )
{
v5 = 0LL;
}
else
{
v7 = *a2;
v8 = (__int64)&(*a2)[(unsigned int)(v6 - 1) + 1];
while ( 1 )
{
v5 = *v7;
if ( !strcmp(s1, *(const char **)(*v7 + 8)) )
break;
if ( ++v7 == (__int64 *)v8 )
return 0LL;
}
}
}
return v5;
}

original_code:
struct song *
song_find_by_pathname(char *pathname, struct song_list *song_list) {
    if( 0 == strncmp(pathname, _st.p.song_dir, strlen(_st.p.song_dir))) {
        for (int i=0; i<song_list->len; i++) {
            if (0 == strcmp(pathname, song_list->e[i]->path)) {
                return song_list->e[i];
            }
        }
    }
    return 0;
}

canonical_original_code:
struct song *song_find_by_pathname(char *pathname, struct song_list *song_list) {
    if( 0 == strncmp(pathname, _st.p.song_dir, strlen(_st.p.song_dir))) {
        for (int i = 0; i<song_list->len; i++) {
            if (0 == strcmp(pathname, song_list->e[i]->path)) {
                return song_list->e[i];
            }
        }
    }
    return 0;
}

variable_types:
pathname
char *

variable_types: struct song_list { struct song **e; int len; } *

user_defined_types: struct song_render_stat { int nullspace; }


decompiled_code:
void song_list_normalize_renders()
{
;
}

canonical_decompiled_code:
void func5()
{
;
}

original_code:
void
song_list_normalize_renders(struct song_list *song_list, char *normalize_prg)
{
}

variable_types: struct song_list { struct song { char *slug; int render_path_len; struct git_repo { char *origin; } git; struct song_render_stat { int nullspace; } render_stat; } **e; int len; } *

user_defined_types: struct song_list { struct song **e; int len; }


decompiled_code:
int __fastcall song_render_print(unsigned int *a1)
{
return printf("dur\tnull\tclip\n%d\t%d\t%d\n", *a1, a1[1], a1[2]);
}

canonical_decompiled_code:
int __fastcall func6(unsigned int *a1)
{
return printf("dur\tnull\tclip\n%d\t%d\t%d\n", *a1, a1[1], a1[2]);
}

original_code:
void
song_render_print(struct song_render_stat *stat) {
    printf("dur\tnull\tclip\n%d\t%d\t%d\n",
        stat->nullspace,
        stat->clipping,
        stat->duration);
}

variable_types: struct song_render_stat { int nullspace; } *


decompiled_code:
const char **__fastcall song_create(__int64 a1, const char *a2)
{
const char **v2; // rbx
const char *v3; // rbp
char *v4; // rax
int v5; // edx

v2 = (const char **)malloc(0x58uLL);
if ( !(unsigned int)git_load_generic(v2 + 5, a1, a2) )
{
printf("Could not load %s\n", a2);
exit(1);
}
*v2 = a2;
git_load_status(v2 + 5);
v3 = v2[7];
v2[1] = v3;
v2[3] = (const char *)malloc(0x100uLL);
v4 = (char *)malloc(0x100uLL);
v2[2] = v4;
sprintf(v4, "%s/%s.wav", v3, *v2);
*((_DWORD *)v2 + 8) = strlen(v2[2]);
sprintf((char *)v2[3], "%s/%s.reason", v2[1], *v2);
*((_DWORD *)v2 + 9) = strlen(v2[3]);
v2[9] = (const char *)song_render_analyze((char *)v2[2]);
*((_DWORD *)v2 + 20) = v5;
return v2;
}

canonical_decompiled_code:
const char **__fastcall func8(__int64 a1, const char *a2)
{
const char **v2; // rbx
const char *v3; // rbp
char *v4; // rax
int v5; // edx

v2 = (const char **)malloc(0x58uLL);
if ( !(unsigned int)git_load_generic(v2 + 5, a1, a2) )
{
printf("Could not load %s\n", a2);
exit(1);
}
*v2 = a2;
git_load_status(v2 + 5);
v3 = v2[7];
v2[1] = v3;
v2[3] = (const char *)malloc(0x100uLL);
v4 = (char *)malloc(0x100uLL);
v2[2] = v4;
sprintf(v4, "%s/%s.wav", v3, *v2);
*((_DWORD *)v2 + 8) = strlen(v2[2]);
sprintf((char *)v2[3], "%s/%s.reason", v2[1], *v2);
*((_DWORD *)v2 + 9) = strlen(v2[3]);
v2[9] = (const char *)func7((char *)v2[2]);
*((_DWORD *)v2 + 20) = v5;
return v2;
}

original_code:
struct song *
song_create(char *root, char *name)
{
    struct song *r = malloc(sizeof(struct song));
    int could_load = git_load_generic(&r->git, root, name);
    if(!could_load) {
        printf("Could not load %s\n", name);
        exit(1);
    }
    r->slug = name;
    git_load_status(&r->git);
    r->path = r->git.path;
    r->project_path = malloc(256 * sizeof(char));
    r->render_path = malloc(256 * sizeof(char));
    sprintf(r->render_path, "%s/%s.wav", r->path, r->slug);
    r->render_path_len = strlen(r->render_path);
    sprintf(r->project_path, "%s/%s.reason", r->path, r->slug);
    r->project_path_len = strlen(r->project_path);
    r->render_stat = song_render_analyze(r->render_path);
    return r;
}

canonical_original_code:
struct song *song_create(char *root, char *name)
{
    struct song *r = malloc(sizeof(struct song));
    int could_load = git_load_generic(&r->git, root, name);
    if(!could_load) {
        printf("Could not load %s\n", name);
        exit(1);
    }
    r->slug = name;
    git_load_status(&r->git);
    r->path = r->git.path;
    r->project_path = malloc(256 * sizeof(char));
    r->render_path = malloc(256 * sizeof(char));
    sprintf(r->render_path, "%s/%s.wav", r->path, r->slug);
    r->render_path_len = strlen(r->render_path);
    sprintf(r->project_path, "%s/%s.reason", r->path, r->slug);
    r->project_path_len = strlen(r->project_path);
    r->render_stat = song_render_analyze(r->render_path);
    return r;
}

variable_types:
root
char *

variable_types:
name
char *


decompiled_code:
__int64 __fastcall songs_load_dir(__int64 a1, __int64 a2)
{
__int64 v2; // r15
int v3; // edx
int v4; // er12
__int64 v5; // r12
__int64 v6; // rbx
__int64 v7; // rbp
const char ***v8; // r13

v2 = dir_read_all(a1, &dir_filter_is_dir);
v4 = v3;
*(_QWORD *)a2 = malloc(0x4000uLL);
*(_DWORD *)(a2 + 8) = v4;
if ( v4 > 0 )
{
v5 = 8LL * (unsigned int)v4;
v6 = 0LL;
v7 = 0LL;
do
{
v8 = (const char ***)(*(_QWORD *)a2 + v6);
*v8 = song_create(a1, (const char *)(v7 + v2 + 19));
v7 += 280LL;
v6 += 8LL;
}
while ( v6 != v5 );
}
return *(unsigned int *)(a2 + 8);
}

original_code:
int
songs_load_dir(char* dir, struct song_list *song_list) {
    struct dirent_list files = dir_read_all(dir, dir_filter_is_dir);
    song_list->e = malloc(2048 * sizeof(void*));
    song_list->len = files.len;
    for(int i=0; i<files.len; i++) {
        song_list->e[i] = song_create(
                dir,
                files.e[i].d_name);
    }
    return song_list->len;
}

canonical_original_code:
int songs_load_dir(char *dir, struct song_list *song_list) {
    struct dirent_list files = dir_read_all(dir, dir_filter_is_dir);
    song_list->e = malloc(2048 * sizeof(void *));
    song_list->len = files.len;
    for(int i = 0; i<files.len; i++) {
        song_list->e[i] = song_create(
                dir,
                files.e[i].d_name);
    }
    return song_list->len;
}

variable_types:
dir
char *

variable_types: struct dirent_list { struct dirent { unsigned long d_ino; long d_off; unsigned short d_reclen; unsigned char d_type; char d_name[256]; } *e; int len; }

variable_types: i int

user_defined_types: struct dirent_list { struct dirent *e; int len; }


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

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

original_code:
int
song_repos_not_cloned(char *git_dir,
                      struct song_list *song_list,
                      char **not_cloned)
{
    return 0;
}


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

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

original_code:
int dir_filter_none(struct dirent *dp) {
    return 1;
}

variable_types: struct dirent { unsigned long d_ino; long d_off; unsigned short d_reclen; unsigned char d_type; char d_name[256]; } *


decompiled_code:
_BOOL8 __fastcall dir_filter_is_dir(__int64 a1)
{
return *(_BYTE *)(a1 + 18) == 4;
}

canonical_decompiled_code:
_BOOL8 __fastcall func1(__int64 a1)
{
return *(_BYTE *)(a1 + 18) == 4;
}

original_code:
int dir_filter_is_dir(struct dirent *dp) {
    return DT_DIR==dp->d_type;
}

user_defined_types: struct dirent { unsigned long d_ino; long d_off; unsigned short d_reclen; unsigned char d_type; char d_name[256]; }


decompiled_code:
_BOOL8 __fastcall dir_filter_is_symlink(__int64 a1)
{
return *(_BYTE *)(a1 + 18) == 10;
}

canonical_decompiled_code:
_BOOL8 __fastcall func2(__int64 a1)
{
return *(_BYTE *)(a1 + 18) == 10;
}

original_code:
int dir_filter_is_symlink(struct dirent *dp) {
    return DT_LNK==dp->d_type;
}


decompiled_code:
__int64 __fastcall dp_name_parse_order(char *a1)
{
char v1; // dl
__int64 result; // rax

v1 = *a1;
for ( result = 0LL; (unsigned __int8)(*a1 - 48) <= 9u; v1 = *a1 )
{
result = (unsigned int)(v1 + 10 * result - 48);
++a1;
}
if ( v1 != 46 )
result = 0LL;
return result;
}

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

v1 = *a1;
for ( result = 0LL; (unsigned __int8)(*a1 - 48) <= 9u; v1 = *a1 )
{
result = (unsigned int)(v1 + 10 * result - 48);
++a1;
}
if ( v1 != 46 )
result = 0LL;
return result;
}

original_code:
int dp_name_parse_order(char *str) {
    int pos = 0;
    char *s = str;
    for(;;s++) {
        if(*s >= '0' && *s <= '9') {
            pos *= 10;
            pos += *s - '0';
            continue;
        } else if(*s == '.') {
            break;
        }
        return 0;
    }
    return pos;
}

variable_types:
str
char *

variable_types: pos int

variable_types:
s
char *


decompiled_code:
__int64 __fastcall dp_cmp(const void *a1, const void *a2)
{
int v2; // ebp
int v3; // eax
unsigned int v4; // edx

v2 = dp_name_parse_order((char *)a1 + 19);
v3 = dp_name_parse_order((char *)a2 + 19);
if ( !v2 || !v3 )
return 0;
v4 = 1;
if ( v2 <= v3 )
v4 = -(v2 < v3);
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func4(const void *a1, const void *a2)
{
int v2; // ebp
int v3; // eax
unsigned int v4; // edx

v2 = func3((char *)a1 + 19);
v3 = func3((char *)a2 + 19);
if ( !v2 || !v3 )
return 0;
v4 = 1;
if ( v2 <= v3 )
v4 = -(v2 < v3);
return v4;
}

original_code:
int dp_cmp(struct dirent *dp1, struct dirent *dp2) {
    int o1, o2;
    o1 = dp_name_parse_order(dp1->d_name);
    o2 = dp_name_parse_order(dp2->d_name);
    if(o1 && o2) {
        if(o1 > o2) {
            return 1;
        }
        if(o1 < o2) {
            return -1;
        }
        return 0;
    }
    return 0;
}

canonical_original_code:
int dp_cmp(struct dirent *dp1, struct dirent *dp2) {
    int o1; int o2;
    o1 = dp_name_parse_order(dp1->d_name);
    o2 = dp_name_parse_order(dp2->d_name);
    if(o1 && o2) {
        if(o1 > o2) {
            return 1;
        }
        if(o1 < o2) {
            return -1;
        }
        return 0;
    }
    return 0;
}


decompiled_code:
void __fastcall dirent_list_sort(__int64 a1)
{
qsort(*(void **)a1, *(int *)(a1 + 8), 0x118uLL, (__compar_fn_t)dp_cmp);
}

canonical_decompiled_code:
void __fastcall func5(__int64 a1)
{
qsort(*(void **)a1, *(int *)(a1 + 8), 0x118uLL, (__compar_fn_t)dp_cmp);
}

original_code:
void dirent_list_sort(struct dirent_list *dl) {
    qsort( dl->e,
            dl->len,
            sizeof(struct dirent),
            dp_cmp);
}

variable_types: struct dirent_list { struct dirent { unsigned long d_ino; long d_off; unsigned short d_reclen; unsigned char d_type; char d_name[256]; } *e; int len; } *


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

result = malloc(0x118000uLL);
*(_QWORD *)a1 = result;
*(_DWORD *)(a1 + 8) = 0;
return result;
}

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

result = malloc(0x118000uLL);
*(_QWORD *)a1 = result;
*(_DWORD *)(a1 + 8) = 0;
return result;
}

original_code:
void
dirent_list_init(struct dirent_list *r)
{
    r->e = malloc(4096 * sizeof(struct dirent));
    r->len = 0;
}


decompiled_code:
void __fastcall dirent_list_free(void *ptr)
{
free(*(void **)ptr);
free(ptr);
}

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

original_code:
void
dirent_list_free(struct dirent_list *dl)
{
    free(dl->e);
    free(dl);
}


decompiled_code:
__time_t __fastcall get_mtime(const char *a1)
{
bool v1; // zf
__time_t result; // rax
struct stat v3; // [rsp+0h] [rbp-98h] BYREF

v1 = stat(a1, &v3) == -1;
result = 0LL;
if ( !v1 )
result = v3.st_mtim.tv_sec;
return result;
}

canonical_decompiled_code:
__time_t __fastcall func9(const char *a1)
{
bool v1; // zf
__time_t result; // rax
struct stat v3; // [rsp+0h] [rbp-98h] BYREF

v1 = stat(a1, &v3) == -1;
result = 0LL;
if ( !v1 )
result = v3.st_mtim.tv_sec;
return result;
}

original_code:
time_t get_mtime(const char *path)
{
    struct stat statbuf;
    if (stat(path, &statbuf) == -1) {
        return 0;
    }
    return statbuf.st_mtim.tv_sec;
}

canonical_original_code:
long get_mtime(char *path)
{
    struct stat statbuf;
    if (stat(path, &statbuf) == -1) {
        return 0;
    }
    return statbuf.st_mtim.tv_sec;
}

variable_types:
path
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: long

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


decompiled_code:
__int64 __fastcall load_data(int a1)
{
char *v1; // rax
char *v2; // rax
char *v3; // rax
char *v4; // rax
char *v5; // rax
char *v6; // rax
void *v7; // rbx
__int64 result; // rax

v1 = getenv("SAPHTUNE_SONG_DIR");
*(&st + 34819) = (__int64)v1;
if ( !v1 )
goto LABEL_12;
v2 = getenv("SAPHTUNE_PLAYLIST_DIR");
*(&st + 34821) = (__int64)v2;
if ( !v2 )
goto LABEL_12;
v3 = getenv("SAPHTUNE_ALBUM_DIR");
*(&st + 34820) = (__int64)v3;
if ( !v3 )
goto LABEL_12;
v4 = getenv("SAPHTUNE_GIT_SONG_DIR");
*(&st + 34822) = (__int64)v4;
if ( v4
&& (v5 = getenv("SAPHTUNE_CACHE_FILE"), (*(&st + 34824) = (__int64)v5) != 0)
&& (v6 = getenv("SAPHTUNE_GIT_ALBUM_DIR"), (*(&st + 34823) = (__int64)v6) != 0) )
{
if ( a1 )
cache_load(*(&st + 34824));
v7 = malloc(0x10uLL);
st = (__int64)v7;
*(&st + 1) = (__int64)malloc(0x10uLL);
result = songs_load_dir(*(&st + 34819), v7);
if ( (_DWORD)result )
{
result = album_load_dir(*(&st + 34820), *(&st + 1));
if ( (_DWORD)result )
result = (unsigned int)album_list_match_songs(*(&st + 1), st) != 0;
}
}
else
{
LABEL_12:
fwrite("Could not load paths from env\n", 1uLL, 0x1EuLL, stderr);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1)
{
char *v1; // rax
char *v2; // rax
char *v3; // rax
char *v4; // rax
char *v5; // rax
char *v6; // rax
void *v7; // rbx
__int64 result; // rax

v1 = getenv("SAPHTUNE_SONG_DIR");
*(&st + 34819) = (__int64)v1;
if ( !v1 )
goto LABEL_12;
v2 = getenv("SAPHTUNE_PLAYLIST_DIR");
*(&st + 34821) = (__int64)v2;
if ( !v2 )
goto LABEL_12;
v3 = getenv("SAPHTUNE_ALBUM_DIR");
*(&st + 34820) = (__int64)v3;
if ( !v3 )
goto LABEL_12;
v4 = getenv("SAPHTUNE_GIT_SONG_DIR");
*(&st + 34822) = (__int64)v4;
if ( v4
&& (v5 = getenv("SAPHTUNE_CACHE_FILE"), (*(&st + 34824) = (__int64)v5) != 0)
&& (v6 = getenv("SAPHTUNE_GIT_ALBUM_DIR"), (*(&st + 34823) = (__int64)v6) != 0) )
{
if ( a1 )
cache_load(*(&st + 34824));
v7 = malloc(0x10uLL);
st = (__int64)v7;
*(&st + 1) = (__int64)malloc(0x10uLL);
result = songs_load_dir(*(&st + 34819), v7);
if ( (_DWORD)result )
{
result = album_load_dir(*(&st + 34820), *(&st + 1));
if ( (_DWORD)result )
result = (unsigned int)album_list_match_songs(*(&st + 1), st) != 0;
}
}
else
{
LABEL_12:
fwrite("Could not load paths from env\n", 1uLL, 0x1EuLL, stderr);
result = 0LL;
}
return result;
}

original_code:
static int load_data(int use_cache) {
    if ((_st.p.song_dir = getenv("SAPHTUNE_SONG_DIR")) == ((void *)0) ||
        (_st.p.playlist_dir = getenv("SAPHTUNE_PLAYLIST_DIR")) == ((void *)0) ||
        (_st.p.album_dir = getenv("SAPHTUNE_ALBUM_DIR")) == ((void *)0) ||
        (_st.p.song_git_dir = getenv("SAPHTUNE_GIT_SONG_DIR")) == ((void *)0) ||
        (_st.p.cache = getenv("SAPHTUNE_CACHE_FILE")) == ((void *)0) ||
        (_st.p.album_git_dir = getenv("SAPHTUNE_GIT_ALBUM_DIR")) == ((void *)0)) {
        fprintf(stderr, "Could not load paths from env\n");
        return 0;
    }
    if(use_cache) {
        cache_load(_st.p.cache);
    }
    _st.songs = malloc(sizeof(struct song_list));
    _st.albums = malloc(sizeof(struct song_list));
    if(0==songs_load_dir(_st.p.song_dir, _st.songs)) return 0;
    if(0==album_load_dir(_st.p.album_dir, _st.albums)) return 0;
    if(0==album_list_match_songs(_st.albums, _st.songs)) return 0;
    return 1;
}


decompiled_code:
__int64 render_analyze()
{
int v0; // edx
__int64 v2; // [rsp+4h] [rbp-14h] BYREF
int v3; // [rsp+Ch] [rbp-Ch]

v2 = song_render_analyze();
v3 = v0;
song_render_print(&v2);
return 0LL;
}

canonical_decompiled_code:
__int64 func1()
{
int v0; // edx
__int64 v2; // [rsp+4h] [rbp-14h] BYREF
int v3; // [rsp+Ch] [rbp-Ch]

v2 = song_render_analyze();
v3 = v0;
song_render_print(&v2);
return 0LL;
}

original_code:
static int render_analyze(char *render_path) {
 struct song_render_stat s = song_render_analyze(render_path);
 song_render_print(&s);
 return 0;
}

variable_types: struct song_render_stat { int nullspace; }


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

result = load_data(1);
if ( !(_DWORD)result )
{
fwrite("Could not create song/album lists\n", 1uLL, 0x22uLL, stderr);
exit(1);
}
return result;
}

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

result = func0(1);
if ( !(_DWORD)result )
{
fwrite("Could not create song/album lists\n", 1uLL, 0x22uLL, stderr);
exit(1);
}
return result;
}

original_code:
void need_data() {
    if(!load_data(1)) {
        fprintf(stderr, "Could not create song/album lists\n");
        exit(1);
    }
}


decompiled_code:
__int64 data_available()
{
return cache_dump(*(&st + 34824));
}

canonical_decompiled_code:
__int64 func3()
{
return cache_dump(*(&st + 34824));
}

original_code:
void data_available() {
 cache_dump(_st.p.cache);
}


decompiled_code:
__int64 print_nullspaced()
{
_QWORD *v0; // rax
__int64 v1; // rbx
__int64 v2; // rax

need_data();
v0 = (_QWORD *)st;
if ( *(int *)(st + 8) > 0 )
{
v1 = 0LL;
do
{
v2 = *(_QWORD *)(*v0 + 8 * v1);
if ( *(_DWORD *)(v2 + 72) )
puts(*(const char **)v2);
v0 = (_QWORD *)st;
++v1;
}
while ( *(_DWORD *)(st + 8) > (int)v1 );
}
data_available();
return 0LL;
}

original_code:
static int print_nullspaced() {
 need_data();
 for(int i=0; i<_st.songs->len; i++) {
  if(_st.songs->e[i]->render_stat.nullspace) {
   printf("%s\n", _st.songs->e[i]->slug);
  }
 }
 data_available();
 return 0;
}

canonical_original_code:
static int print_nullspaced() {
 need_data();
 for(int i = 0; i<_st.songs->len; i++) {
  if(_st.songs->e[i]->render_stat.nullspace) {
   printf("%s\n", _st.songs->e[i]->slug);
  }
 }
 data_available();
 return 0;
}


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // ebx
int v4; // eax
__int64 v5; // rax
unsigned int v6; // eax
_QWORD *v7; // rax
__int64 v8; // rbp
size_t i; // rbx
const char *v10; // r13
char v11; // di
__int64 v12; // rax
const char **v13; // rbp
int v14; // eax
const char **v15; // rbx
__int64 v16; // rbp
char *v17; // rbx
char v19; // dl
__int64 v20; // rbx
char **argva; // [rsp+0h] [rbp-98h] BYREF
int argca; // [rsp+Ch] [rbp-8Ch] BYREF
char shortopts[16]; // [rsp+10h] [rbp-88h] BYREF
const char *v24; // [rsp+20h] [rbp-78h]
const char *v25; // [rsp+28h] [rbp-70h]
const char *v26; // [rsp+30h] [rbp-68h]
const char *v27; // [rsp+38h] [rbp-60h]
const char *v28; // [rsp+40h] [rbp-58h]
const char *v29; // [rsp+48h] [rbp-50h]
const char *v30; // [rsp+50h] [rbp-48h]
const char *v31; // [rsp+58h] [rbp-40h]
const char *v32; // [rsp+60h] [rbp-38h]
__int64 v33; // [rsp+68h] [rbp-30h]

argca = argc;
argva = (char **)argv;
strcpy(shortopts, "oapsdlgnr");
v24 = " Print orphans";
v25 = " [file] Analyze render";
v26 = " [file] Print song meta";
v27 = " Print git status";
v28 = " Print displaced songs";
v29 = " Write playlist files";
v30 = " Open GUI";
v31 = " List nullspaced songs";
v32 = " Recache";
v33 = 0LL;
v3 = -1;
while ( 1 )
{
v4 = getopt(argca, argva, shortopts);
if ( v4 == -1 )
break;
switch ( v4 )
{
case 'a':
v3 = render_analyze(argva[2]);
break;
case 'd':
need_data();
data_available();
v13 = (const char **)malloc(0x4000uLL);
v14 = song_repos_not_cloned(*(&st + 34822), st, v13);
v3 = 0;
if ( v14 > 0 )
{
v15 = v13;
v16 = (__int64)&v13[(unsigned int)(v14 - 1) + 1];
do
puts(*v15++);
while ( v15 != (const char **)v16 );
v3 = 0;
}
break;
case 'g':
need_data();
data_available();
v3 = ui_main(&argca, &argva);
break;
case 'l':
need_data();
puts("album.m3u");
v17 = (char *)malloc(0x1000uLL);
sprintf(v17, "%s/album.m3u", (const char *)*(&st + 34821));
album_list_make_m3u(*(&st + 1), v17);
puts("songs.m3u");
sprintf(v17, "%s/songs.m3u", (const char *)*(&st + 34821));
song_list_make_m3u(st, v17);
free(v17);
data_available();
v3 = 0;
break;
case 'n':
v3 = print_nullspaced();
break;
case 'o':
need_data();
data_available();
v5 = album_list_find_exclusions(*(&st + 1), st);
song_list_print(v5, 0LL);
v3 = 0;
break;
case 'p':
need_data();
data_available();
v6 = song_resolve_slug(argva[2]);
v3 = song_print_metadata(v6);
break;
case 'r':
load_data(0);
data_available();
puts((const char *)*(&st + 34824));
v3 = 0;
break;
case 's':
need_data();
data_available();
puts("slug\tstat");
v7 = (_QWORD *)st;
if ( *(int *)(st + 8) <= 0 )
{
v3 = 0;
}
else
{
v8 = 0LL;
do
{
v12 = *(_QWORD *)(*v7 + 8 * v8);
if ( **(_BYTE **)(v12 + 64) )
{
puts(*(const char **)v12);
putchar(9);
for ( i = 0LL; ; ++i )
{
v10 = *(const char **)(*(_QWORD *)(*(_QWORD *)st + 8 * v8) + 64LL);
if ( strlen(v10) - 1 <= i )
break;
v11 = v10[i];
if ( v11 == 10 )
{
putchar(10);
putchar(9);
}
else
{
putchar(v11);
}
}
putchar(10);
}
v7 = (_QWORD *)st;
++v8;
}
while ( *(_DWORD *)(st + 8) > (int)v8 );
v3 = 0;
}
break;
default:
continue;
}
}
if ( v3 == -1 )
{
fwrite("Usage:\n", 1uLL, 7uLL, stderr);
v19 = shortopts[0];
if ( shortopts[0] )
{
v20 = 1LL;
do
{
fprintf(stderr, "\t-%c%s\n", (unsigned int)v19, *(const char **)&shortopts[8 * v20++ + 8]);
v19 = *((_BYTE *)&argca + v20 + 3);
}
while ( v19 );
v3 = 1;
}
else
{
v3 = 1;
}
}
return v3;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // ebx
int v4; // eax
__int64 v5; // rax
unsigned int v6; // eax
_QWORD *v7; // rax
__int64 v8; // rbp
size_t i; // rbx
const char *v10; // r13
char v11; // di
__int64 v12; // rax
const char **v13; // rbp
int v14; // eax
const char **v15; // rbx
__int64 v16; // rbp
char *v17; // rbx
char v19; // dl
__int64 v20; // rbx
char **argva; // [rsp+0h] [rbp-98h] BYREF
int argca; // [rsp+Ch] [rbp-8Ch] BYREF
char shortopts[16]; // [rsp+10h] [rbp-88h] BYREF
const char *v24; // [rsp+20h] [rbp-78h]
const char *v25; // [rsp+28h] [rbp-70h]
const char *v26; // [rsp+30h] [rbp-68h]
const char *v27; // [rsp+38h] [rbp-60h]
const char *v28; // [rsp+40h] [rbp-58h]
const char *v29; // [rsp+48h] [rbp-50h]
const char *v30; // [rsp+50h] [rbp-48h]
const char *v31; // [rsp+58h] [rbp-40h]
const char *v32; // [rsp+60h] [rbp-38h]
__int64 v33; // [rsp+68h] [rbp-30h]

argca = argc;
argva = (char **)argv;
strcpy(shortopts, "oapsdlgnr");
v24 = " Print orphans";
v25 = " [file] Analyze render";
v26 = " [file] Print song meta";
v27 = " Print git status";
v28 = " Print displaced songs";
v29 = " Write playlist files";
v30 = " Open GUI";
v31 = " List nullspaced songs";
v32 = " Recache";
v33 = 0LL;
v3 = -1;
while ( 1 )
{
v4 = getopt(argca, argva, shortopts);
if ( v4 == -1 )
break;
switch ( v4 )
{
case 'a':
v3 = func1(argva[2]);
break;
case 'd':
func2();
func3();
v13 = (const char **)malloc(0x4000uLL);
v14 = song_repos_not_cloned(*(&st + 34822), st, v13);
v3 = 0;
if ( v14 > 0 )
{
v15 = v13;
v16 = (__int64)&v13[(unsigned int)(v14 - 1) + 1];
do
puts(*v15++);
while ( v15 != (const char **)v16 );
v3 = 0;
}
break;
case 'g':
func2();
func3();
v3 = ui_main(&argca, &argva);
break;
case 'l':
func2();
puts("album.m3u");
v17 = (char *)malloc(0x1000uLL);
sprintf(v17, "%s/album.m3u", (const char *)*(&st + 34821));
album_list_make_m3u(*(&st + 1), v17);
puts("songs.m3u");
sprintf(v17, "%s/songs.m3u", (const char *)*(&st + 34821));
song_list_make_m3u(st, v17);
free(v17);
func3();
v3 = 0;
break;
case 'n':
v3 = func4();
break;
case 'o':
func2();
func3();
v5 = album_list_find_exclusions(*(&st + 1), st);
song_list_print(v5, 0LL);
v3 = 0;
break;
case 'p':
func2();
func3();
v6 = song_resolve_slug(argva[2]);
v3 = song_print_metadata(v6);
break;
case 'r':
func0(0);
func3();
puts((const char *)*(&st + 34824));
v3 = 0;
break;
case 's':
func2();
func3();
puts("slug\tstat");
v7 = (_QWORD *)st;
if ( *(int *)(st + 8) <= 0 )
{
v3 = 0;
}
else
{
v8 = 0LL;
do
{
v12 = *(_QWORD *)(*v7 + 8 * v8);
if ( **(_BYTE **)(v12 + 64) )
{
puts(*(const char **)v12);
putchar(9);
for ( i = 0LL; ; ++i )
{
v10 = *(const char **)(*(_QWORD *)(*(_QWORD *)st + 8 * v8) + 64LL);
if ( strlen(v10) - 1 <= i )
break;
v11 = v10[i];
if ( v11 == 10 )
{
putchar(10);
putchar(9);
}
else
{
putchar(v11);
}
}
putchar(10);
}
v7 = (_QWORD *)st;
++v8;
}
while ( *(_DWORD *)(st + 8) > (int)v8 );
v3 = 0;
}
break;
default:
continue;
}
}
if ( v3 == -1 )
{
fwrite("Usage:\n", 1uLL, 7uLL, stderr);
v19 = shortopts[0];
if ( shortopts[0] )
{
v20 = 1LL;
do
{
fprintf(stderr, "\t-%c%s\n", (unsigned int)v19, *(const char **)&shortopts[8 * v20++ + 8]);
v19 = *((_BYTE *)&argca + v20 + 3);
}
while ( v19 );
v3 = 1;
}
else
{
v3 = 1;
}
}
return v3;
}

original_code:
int main(int argc, char** argv) {
    int opts;
 int retval = -1;
 struct {
  char list[10];
  char* desc[10];
 } o = {
  "oapsdlgnr", {
   "         Print orphans",
   " [file]  Analyze render",
   " [file]  Print song meta",
   "         Print git status",
   "         Print displaced songs",
   "         Write playlist files",
   "         Open GUI",
   "         List nullspaced songs",
   "         Recache",
   0
  }
 };
 void *tmp;
    while( -1 != (opts = getopt(argc, argv, o.list))) {
        switch(opts) {
  case 'n':
   retval = print_nullspaced();
   break;
        case 'o':
            need_data();
   data_available();
            song_list_print(album_list_find_exclusions(_st.albums, _st.songs), 0);
            retval = 0;
   break;
        case 'a':
            retval = render_analyze(argv[2]);
   break;
        case 'p':
            need_data();
            data_available();
            retval = song_print_metadata(song_resolve_slug(argv[2]));
   break;
        case 's':
            need_data();
   data_available();
   printf("slug\tstat\n");
            for(int i=0; i<_st.songs->len; i++) {
                if(0 != strcmp("", _st.songs->e[i]->git.status)) {
                    printf("%s\n", _st.songs->e[i]->slug);
                    putchar('\t');
                    for (int j=0; j<strlen(_st.songs->e[i]->git.status) - 1; j++) {
                        if (_st.songs->e[i]->git.status[j] == '\n') {
                            putchar('\n');
                            putchar('\t');
                        } else {
                            putchar(_st.songs->e[i]->git.status[j]);
                        }
                    }
                    putchar('\n');
                }
            }
            retval = 0;
   break;
        case 'd':
            need_data();
            data_available();
            int num_not_cloned = 0;
            char** not_cloned = malloc(sizeof(void*) * 2048);
            num_not_cloned = song_repos_not_cloned(
    _st.p.song_git_dir,
    _st.songs,
    not_cloned
   );
            if (num_not_cloned > 0) {
                for (int i=0; i<num_not_cloned; i++) {
                    printf("%s\n", not_cloned[i]);
                }
            }
            retval = 0;
   break;
        case 'l':
            need_data();
            printf("album.m3u\n");
   tmp = malloc(4096);
            sprintf( (char*) tmp, "%s/album.m3u", _st.p.playlist_dir);
   album_list_make_m3u(_st.albums, (char*) tmp);
            printf("songs.m3u\n");
            sprintf( (char*) tmp, "%s/songs.m3u", _st.p.playlist_dir);
   song_list_make_m3u(_st.songs, (char*) tmp);
   free(tmp);
            data_available();
            retval = 0;
   break;
        case 'g':
            need_data();
            data_available();
            retval = ui_main(&argc, &argv);
   break;
        case 'r':
            load_data(0);
            data_available();
            printf("%s\n", _st.p.cache);
            retval = 0;
   break;
  }
    }
 if(retval != -1) {
  return retval;
 }
 fprintf(stderr, "Usage:\n");
 for(int i=0; o.list[i] != 0; i++) {
  fprintf(stderr, "\t-%c%s\n", o.list[i], o.desc[i]);
 }
 return 1;
}

canonical_original_code:
int main(int argc, char **argv) {
    int opts;
 int retval = -1;
 struct { char list[10]; char *desc[10]; } o = {
  "oapsdlgnr", {
   "         Print orphans",
   " [file]  Analyze render",
   " [file]  Print song meta",
   "         Print git status",
   "         Print displaced songs",
   "         Write playlist files",
   "         Open GUI",
   "         List nullspaced songs",
   "         Recache",
   0
  }
 };
 void *tmp;
    while( -1 != (opts = getopt(argc, argv, o.list))) {
        switch(opts) {
  case 'n':
   retval = print_nullspaced();
   break;
        case 'o':
            need_data();
   data_available();
            song_list_print(album_list_find_exclusions(_st.albums, _st.songs), 0);
            retval = 0;
   break;
        case 'a':
            retval = render_analyze(argv[2]);
   break;
        case 'p':
            need_data();
            data_available();
            retval = song_print_metadata(song_resolve_slug(argv[2]));
   break;
        case 's':
            need_data();
   data_available();
   printf("slug\tstat\n");
            for(int i = 0; i<_st.songs->len; i++) {
                if(0 != strcmp("", _st.songs->e[i]->git.status)) {
                    printf("%s\n", _st.songs->e[i]->slug);
                    putchar('\t');
                    for (int j = 0; j<strlen(_st.songs->e[i]->git.status) - 1; j++) {
                        if (_st.songs->e[i]->git.status[j] == '\n') {
                            putchar('\n');
                            putchar('\t');
                        } else {
                            putchar(_st.songs->e[i]->git.status[j]);
                        }
                    }
                    putchar('\n');
                }
            }
            retval = 0;
   break;
        case 'd':
            need_data();
            data_available();
            int num_not_cloned = 0;
            char **not_cloned = malloc(sizeof(void*) * 2048);
            num_not_cloned = song_repos_not_cloned(
    _st.p.song_git_dir,
    _st.songs,
    not_cloned
   );
            if (num_not_cloned > 0) {
                for (int i = 0; i<num_not_cloned; i++) {
                    printf("%s\n", not_cloned[i]);
                }
            }
            retval = 0;
   break;
        case 'l':
            need_data();
            printf("album.m3u\n");
   tmp = malloc(4096);
            sprintf( (char *) tmp, "%s/album.m3u", _st.p.playlist_dir);
   album_list_make_m3u(_st.albums, (char *) tmp);
            printf("songs.m3u\n");
            sprintf( (char *) tmp, "%s/songs.m3u", _st.p.playlist_dir);
   song_list_make_m3u(_st.songs, (char *) tmp);
   free(tmp);
            data_available();
            retval = 0;
   break;
        case 'g':
            need_data();
            data_available();
            retval = ui_main(&argc, &argv);
   break;
        case 'r':
            load_data(0);
            data_available();
            printf("%s\n", _st.p.cache);
            retval = 0;
   break;
  }
    }
 if(retval != -1) {
  return retval;
 }
 fprintf(stderr, "Usage:\n");
 for(int i = 0; o.list[i] != 0; i++) {
  fprintf(stderr, "\t-%c%s\n", o.list[i], o.desc[i]);
 }
 return 1;
}

variable_types: argc int

variable_types:
argv
char **

variable_types: opts int

variable_types: retval int

variable_types:
tmp
void *

variable_types: j int


decompiled_code:
__int64 __fastcall git_load_generic(_QWORD *a1, const char *a2, const char *a3)
{
char *v4; // rax
char *v5; // rax

v4 = (char *)malloc(0xFFuLL);
a1[2] = v4;
sprintf(v4, "%s/%s", a2, a3);
v5 = (char *)malloc(0xFFuLL);
a1[1] = v5;
sprintf(v5, "%s/.git/config", (const char *)a1[2]);
a1[3] = 0LL;
return git_load_config((__int64)a1);
}

canonical_decompiled_code:
__int64 __fastcall func2(_QWORD *a1, const char *a2, const char *a3)
{
char *v4; // rax
char *v5; // rax

v4 = (char *)malloc(0xFFuLL);
a1[2] = v4;
sprintf(v4, "%s/%s", a2, a3);
v5 = (char *)malloc(0xFFuLL);
a1[1] = v5;
sprintf(v5, "%s/.git/config", (const char *)a1[2]);
a1[3] = 0LL;
return func1((__int64)a1);
}

original_code:
int
git_load_generic(struct git_repo *repo,
                 char *root,
                 char *name)
{
    repo->path = malloc(255 * sizeof(char));
    sprintf(repo->path, "%s/%s", root, name);
    repo->config_path = malloc(255 * sizeof(char));
    sprintf(repo->config_path, "%s/.git/config", repo->path);
    repo->status = 0;
    return git_load_config(repo);
}

variable_types:
repo
struct git_repo { char *origin; } *

variable_types:
root
char *

variable_types:
name
char *


canonical_original_code:
unsigned int hash_fn(void *data, unsigned int len)
{
    unsigned int h; unsigned int x;
    char *dd = (char*)data;
    for (h = x = 0; x<len; x++) {
        h += dd[x];
        h += (h << 10);
        h ^= (h >> 6);
    }
    h += (h << 3);
    h ^= (h >> 11);
    h += (h << 15);
    return h;
}

variable_types:
data
void *

variable_types:
len
unsigned int

variable_types:
h
unsigned int

variable_types:
x
unsigned int

variable_types:
dd
char *

return_type: unsigned int


decompiled_code:
__int64 __fastcall cache_get(void *s2, int a2)
{
signed int v2; // ebp
__int64 v3; // rbx

v2 = strlen((const char *)s2);
v3 = *(_QWORD *)&st[2 * (hash_fn((char *)s2, v2) & 0x7FF) + 65542];
if ( v3 )
{
while ( *(_DWORD *)(v3 + 8) != v2 || memcmp(*(const void **)v3, s2, v2) )
{
v3 = *(_QWORD *)(v3 + 24);
if ( !v3 )
return v3;
}
v3 = *(_QWORD *)(v3 + 16);
if ( *(_DWORD *)(v3 + 8) < a2 )
v3 = 0LL;
}
return v3;
}

original_code:
void *
cache_get(char *id, int ts) {
    int id_len = strlen(id);
    uint32_t hash_offset = hash_fn(id, id_len) & 2047;
    struct hash *e = _st.cachetable[hash_offset];
    if(e) {
        do {
            if ( id_len == e->key_len
              && !memcmp(e->key, id, id_len)) {
                if(ts <= e->value->timestamp) {
                    return e->value;
                } else {
                  return 0;
                }
            }
        } while((e = e->next));
    }
    return 0;
}

canonical_original_code:
void *cache_get(char *id, int ts) {
    int id_len = strlen(id);
    unsigned int hash_offset = hash_fn(id, id_len) & 2047;
    struct hash *e = _st.cachetable[hash_offset];
    if(e) {
        do {
            if ( id_len == e->key_len
              && !memcmp(e->key, id, id_len)) {
                if(ts <= e->value->timestamp) {
                    return e->value;
                } else {
                  return 0;
                }
            }
        } while((e = e->next));
    }
    return 0;
}

variable_types:
id
char *

variable_types: ts int

variable_types: struct hash { char *key; int key_len; struct cache_entry { int key_len; int value_len; int timestamp; char *key; void *value; } *value; struct hash *next; } *

return_type: void *

user_defined_types: struct hash { char *key; int key_len; struct cache_entry *value; struct hash *next; }


decompiled_code:
char *__fastcall song_format_duration(int a1)
{
char *v1; // rbp

v1 = (char *)calloc(8uLL, 1uLL);
sprintf(v1, "%2d:%02d", (unsigned int)(a1 / 60), (unsigned int)(a1 % 60));
return v1;
}

canonical_decompiled_code:
char *__fastcall func0(int a1)
{
char *v1; // rbp

v1 = (char *)calloc(8uLL, 1uLL);
sprintf(v1, "%2d:%02d", (unsigned int)(a1 / 60), (unsigned int)(a1 % 60));
return v1;
}

original_code:
char *
song_format_duration(int duration)
{
 char *retval = calloc(8, sizeof(char));
 sprintf(retval, "%2d:%02d",
  (duration/60),
  (duration%60)
 );
 return retval;
}

canonical_original_code:
char *song_format_duration(int duration)
{
 char *retval = calloc(8, sizeof(char));
 sprintf(retval, "%2d:%02d",
  (duration/60),
  (duration%60)
 );
 return retval;
}

variable_types: duration int

variable_types:
retval
char *


repo: sas/blctl

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // er13
int v4; // er12
__int64 v5; // rdx
unsigned int v6; // er13
int v7; // ebx
const char *v8; // r15
int v9; // ebp
void *v11; // [rsp+0h] [rbp-48h] BYREF
char *ptr; // [rsp+8h] [rbp-40h] BYREF

if ( argc <= 1 )
usage_exit(1, *argv);
if ( chdir("/sys/class") == -1 )
err(1, "%s", "/sys/class");
validate_device((char *)argv[1]);
if ( argc <= 2 )
usage_exit(1, *argv);
asprintf(&ptr, "%s/brightness", argv[1]);
asprintf((char **)&v11, "%s/max_brightness", argv[1]);
v3 = read_val(ptr);
v4 = read_val(v11);
v5 = (unsigned int)((100 * v3) >> 31);
LODWORD(v5) = 100 * v3 % v4;
v6 = 100 * v3 / v4;
v7 = v6;
v8 = argv[2];
if ( !strcmp(v8, "up") )
{
v9 = v6 + 10;
}
else if ( !strcmp(argv[2], "down") )
{
v9 = v6 - 10;
}
else if ( !strcmp(v8, "get") )
{
printf("current level for %s: %d%%\n", argv[1], v6);
v9 = v6;
}
else
{
if ( strcmp(v8, "set") )
usage_exit(1, *argv);
if ( argc <= 3 )
usage_exit(1, *argv);
v9 = strtoul(argv[3], 0LL, 0);
}
if ( v9 > 100 )
v9 = 100;
if ( v9 < 0 )
v9 = 0;
if ( v9 != v6 )
{
do
{
v7 = v7 + 2 * (v9 > v7) - 1;
write_val(ptr, (unsigned int)(v7 * v4 / 100), v5);
millisleep(20LL);
}
while ( v9 != v7 );
}
free(v11);
free(ptr);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // er13
int v4; // er12
__int64 v5; // rdx
unsigned int v6; // er13
int v7; // ebx
const char *v8; // r15
int v9; // ebp
void *v11; // [rsp+0h] [rbp-48h] BYREF
char *ptr; // [rsp+8h] [rbp-40h] BYREF

if ( argc <= 1 )
func8(1, *argv);
if ( chdir("/sys/class") == -1 )
err(1, "%s", "/sys/class");
func7((char *)argv[1]);
if ( argc <= 2 )
func8(1, *argv);
asprintf(&ptr, "%s/brightness", argv[1]);
asprintf((char **)&v11, "%s/max_brightness", argv[1]);
v3 = func9(ptr);
v4 = func9(v11);
v5 = (unsigned int)((100 * v3) >> 31);
LODWORD(v5) = 100 * v3 % v4;
v6 = 100 * v3 / v4;
v7 = v6;
v8 = argv[2];
if ( !strcmp(v8, "up") )
{
v9 = v6 + 10;
}
else if ( !strcmp(argv[2], "down") )
{
v9 = v6 - 10;
}
else if ( !strcmp(v8, "get") )
{
printf("current level for %s: %d%%\n", argv[1], v6);
v9 = v6;
}
else
{
if ( strcmp(v8, "set") )
func8(1, *argv);
if ( argc <= 3 )
func8(1, *argv);
v9 = strtoul(argv[3], 0LL, 0);
}
if ( v9 > 100 )
v9 = 100;
if ( v9 < 0 )
v9 = 0;
if ( v9 != v6 )
{
do
{
v7 = v7 + 2 * (v9 > v7) - 1;
func10(ptr, (unsigned int)(v7 * v4 / 100), v5);
func11(20LL);
}
while ( v9 != v7 );
}
free(v11);
free(ptr);
return 0;
}

original_code:
int main(int argc, const char **argv)
{
  char *cur_path;
  char *max_path;
  int cur_level;
  int max_level;
  int cur_perc;
  int new_perc;
  do { if (argc < 1 + 1) usage_exit(1, argv[0]); } while (0);
  if (chdir("/sys/class") == -1)
    err(1, "%s", "/sys/class");
  validate_device(argv[1]);
  do { if (argc < 2 + 1) usage_exit(1, argv[0]); } while (0);
  asprintf(&cur_path, "%s/brightness", argv[1]);
  asprintf(&max_path, "%s/max_brightness", argv[1]);
  cur_level = read_val(cur_path);
  max_level = read_val(max_path);
  cur_perc = cur_level * 100 / max_level;
  if (strcmp(argv[2], "up") == 0) {
    new_perc = cur_perc + 10;
  } else if (strcmp(argv[2], "down") == 0) {
    new_perc = cur_perc - 10;
  } else if (strcmp(argv[2], "get") == 0) {
    printf("current level for %s: %d%%\n", argv[1], cur_perc);
    new_perc = cur_perc;
  } else if (strcmp(argv[2], "set") == 0) {
    do { if (argc < 3 + 1) usage_exit(1, argv[0]); } while (0);
    new_perc = strtoul(argv[3], ((void *)0), 0);
  } else {
    usage_exit(1, argv[0]);
  }
  if (new_perc < 0)
    new_perc = 0;
  if (new_perc > 100)
    new_perc = 100;
  while (cur_perc != new_perc) {
    cur_perc += cur_perc < new_perc ? 1 : -1;
    write_val(cur_path, cur_perc * max_level / 100);
    millisleep(20);
  }
  free(max_path);
  free(cur_path);
  return 0;
}

canonical_original_code:
int main(int argc, char **argv)
{
  char *cur_path;
  char *max_path;
  int cur_level;
  int max_level;
  int cur_perc;
  int new_perc;
  do { if (argc < 1 + 1) usage_exit(1, argv[0]); } while (0);
  if (chdir("/sys/class") == -1)
    err(1, "%s", "/sys/class");
  validate_device(argv[1]);
  do { if (argc < 2 + 1) usage_exit(1, argv[0]); } while (0);
  asprintf(&cur_path, "%s/brightness", argv[1]);
  asprintf(&max_path, "%s/max_brightness", argv[1]);
  cur_level = read_val(cur_path);
  max_level = read_val(max_path);
  cur_perc = cur_level * 100 / max_level;
  if (strcmp(argv[2], "up") == 0) {
    new_perc = cur_perc + 10;
  } else if (strcmp(argv[2], "down") == 0) {
    new_perc = cur_perc - 10;
  } else if (strcmp(argv[2], "get") == 0) {
    printf("current level for %s: %d%%\n", argv[1], cur_perc);
    new_perc = cur_perc;
  } else if (strcmp(argv[2], "set") == 0) {
    do { if (argc < 3 + 1) usage_exit(1, argv[0]); } while (0);
    new_perc = strtoul(argv[3], ((void *)0), 0);
  } else {
    usage_exit(1, argv[0]);
  }
  if (new_perc < 0)
    new_perc = 0;
  if (new_perc > 100)
    new_perc = 100;
  while (cur_perc != new_perc) {
    cur_perc += cur_perc < new_perc ? 1 : -1;
    write_val(cur_path, cur_perc * max_level / 100);
    millisleep(20);
  }
  free(max_path);
  free(cur_path);
  return 0;
}

variable_types: argc int

variable_types:
argv
char **


millisleep

decompiled_code:
int __fastcall millisleep(int a1)
{
struct timespec v2; // [rsp+0h] [rbp-18h] BYREF

v2.tv_sec = 0LL;
v2.tv_nsec = (unsigned int)(1000000 * a1);
return nanosleep(&v2, 0LL);
}

canonical_decompiled_code:
int __fastcall func11(int a1)
{
struct timespec v2; // [rsp+0h] [rbp-18h] BYREF

v2.tv_sec = 0LL;
v2.tv_nsec = (unsigned int)(1000000 * a1);
return nanosleep(&v2, 0LL);
}

original_code:
void millisleep(unsigned int ms)
{
  struct timespec ts = {
    .tv_sec = 0,
    .tv_nsec = 1000000 * ms,
  };
  nanosleep(&ts, ((void *)0));
}

variable_types:
ms
unsigned int

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


repo: schoentoon/tlibs

decompiled_code:
void __fastcall bst_teardown_leaf(_QWORD *a1, void (__fastcall *a2)(_QWORD))
{
if ( a1 )
{
bst_teardown_leaf(a1[1]);
bst_teardown_leaf(a1[2]);
if ( a2 )
a2(*a1);
}
free(a1);
}

canonical_decompiled_code:
void __fastcall func0(_QWORD *a1, void (__fastcall *a2)(_QWORD))
{
if ( a1 )
{
func0(a1[1]);
func0(a1[2]);
if ( a2 )
a2(*a1);
}
free(a1);
}

original_code:
static void bst_teardown_leaf(struct bst_leaf* leaf, teardown_function shovel) {
  if (leaf) {
    bst_teardown_leaf(leaf->left, shovel);
    bst_teardown_leaf(leaf->right, shovel);
    if (shovel)
      shovel(leaf->ptr);
  };
  free(leaf);
}

canonical_original_code:
static void bst_teardown_leaf(struct bst_leaf *leaf, void shovel(void *ptr)) {
  if (leaf) {
    bst_teardown_leaf(leaf->left, shovel);
    bst_teardown_leaf(leaf->right, shovel);
    if (shovel)
      shovel(leaf->ptr);
  };
  free(leaf);
}

variable_types: struct bst_leaf { void *ptr; struct bst_leaf *left; struct bst_leaf *right; } *

variable_types:
shovel
void (void *ptr)


decompiled_code:
__int64 __fastcall bst_grow_leaf(_QWORD *a1, __int64 a2, __int64 (__fastcall *a3)(_QWORD, __int64))
{
__int64 result; // rax
_QWORD *v5; // r12
__int64 *v6; // rax

result = 0LL;
if ( a3 )
{
v5 = malloc(0x18uLL);
v5[1] = 0LL;
v5[2] = 0LL;
*v5 = a2;
v6 = bst_tree_search(a1, a2, a3);
if ( *v6 )
{
free(v5);
result = 0LL;
}
else
{
*v6 = (__int64)v5;
result = 1LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(_QWORD *a1, __int64 a2, __int64 (__fastcall *a3)(_QWORD, __int64))
{
__int64 result; // rax
_QWORD *v5; // r12
__int64 *v6; // rax

result = 0LL;
if ( a3 )
{
v5 = malloc(0x18uLL);
v5[1] = 0LL;
v5[2] = 0LL;
*v5 = a2;
v6 = bst_tree_search(a1, a2, a3);
if ( *v6 )
{
free(v5);
result = 0LL;
}
else
{
*v6 = (__int64)v5;
result = 1LL;
}
}
return result;
}

original_code:
int bst_grow_leaf(bst_roots* root, void* ptr, bst_comparator comparator) {
  if (!comparator)
    return 0;
  struct bst_leaf* tmp_leaf = malloc(sizeof(struct bst_leaf));
  memset(tmp_leaf, 0, sizeof(struct bst_leaf));
  tmp_leaf->ptr = ptr;
  struct bst_leaf** leaf = bst_tree_search(root, ptr, comparator);
  if (!*leaf) {
    *leaf = tmp_leaf;
    return 1;
  }
  free(tmp_leaf);
  return 0;
}

canonical_original_code:
int bst_grow_leaf(struct bst_leaf *root, void *ptr, int comparator(void *ptr1, void *ptr2)) {
  if (!comparator)
    return 0;
  struct bst_leaf *tmp_leaf = malloc(sizeof(struct bst_leaf));
  memset(tmp_leaf, 0, sizeof(struct bst_leaf));
  tmp_leaf->ptr = ptr;
  struct bst_leaf **leaf = bst_tree_search(root, ptr, comparator);
  if (!*leaf) {
    *leaf = tmp_leaf;
    return 1;
  }
  free(tmp_leaf);
  return 0;
}

variable_types:
ptr
void *

variable_types:
comparator
int (void *ptr1, void *ptr2)

variable_types: struct bst_leaf { void *ptr; struct bst_leaf *left; struct bst_leaf *right; } **


decompiled_code:
__int64 __fastcall bst_count_leaves(__int64 a1)
{
unsigned int v1; // ebp

if ( !a1 )
return 0;
v1 = 1;
if ( *(_QWORD *)(a1 + 8) )
v1 = bst_count_leaves() + 1;
if ( *(_QWORD *)(a1 + 16) )
v1 += bst_count_leaves();
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
unsigned int v1; // ebp

if ( !a1 )
return 0;
v1 = 1;
if ( *(_QWORD *)(a1 + 8) )
v1 = func2() + 1;
if ( *(_QWORD *)(a1 + 16) )
v1 += func2();
return v1;
}

original_code:
unsigned int bst_count_leaves(bst_roots* root) {
  if (!root)
    return 0;
  unsigned int result = 1;
  if (root->left)
    result += bst_count_leaves(root->left);
  if (root->right)
    result += bst_count_leaves(root->right);
  return result;
}

canonical_original_code:
unsigned int bst_count_leaves(struct bst_leaf *root) {
  if (!root)
    return 0;
  unsigned int result = 1;
  if (root->left)
    result += bst_count_leaves(root->left);
  if (root->right)
    result += bst_count_leaves(root->right);
  return result;
}

variable_types:
result
unsigned int

user_defined_types: struct bst_leaf { void *ptr; struct bst_leaf *left; struct bst_leaf *right; }


decompiled_code:
__int64 __fastcall bst_for_each(_QWORD *a1, void (__fastcall *a2)(_QWORD))
{
__int64 result; // rax

if ( a1 )
{
a2(*a1);
bst_for_each(a1[1], a2);
result = bst_for_each(a1[2], a2);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(_QWORD *a1, void (__fastcall *a2)(_QWORD))
{
__int64 result; // rax

if ( a1 )
{
a2(*a1);
func3(a1[1], a2);
result = func3(a1[2], a2);
}
return result;
}

original_code:
void bst_for_each(bst_roots* root, bst_function function) {
  if (root) {
    function(root->ptr);
    bst_for_each(root->left, function);
    bst_for_each(root->right, function);
  };
}

canonical_original_code:
void bst_for_each(struct bst_leaf *root, void function(void *ptr)) {
  if (root) {
    function(root->ptr);
    bst_for_each(root->left, function);
    bst_for_each(root->right, function);
  };
}

variable_types:
function
void (void *ptr)


decompiled_code:
void __fastcall bst_dig_up_tree(void *ptr, void (__fastcall *a2)(_QWORD))
{
if ( ptr )
{
bst_teardown_leaf(*((_QWORD **)ptr + 1), a2);
bst_teardown_leaf(*((_QWORD **)ptr + 2), a2);
}
if ( a2 )
a2(*(_QWORD *)ptr);
free(ptr);
}

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

original_code:
void bst_dig_up_tree(bst_roots* roots, teardown_function shovel) {
  if (roots) {
    bst_teardown_leaf(roots->left, shovel);
    bst_teardown_leaf(roots->right, shovel);
  };
  if (shovel)
    shovel(roots->ptr);
  free(roots);
}

canonical_original_code:
void bst_dig_up_tree(struct bst_leaf *roots, void shovel(void *ptr)) {
  if (roots) {
    bst_teardown_leaf(roots->left, shovel);
    bst_teardown_leaf(roots->right, shovel);
  };
  if (shovel)
    shovel(roots->ptr);
  free(roots);
}


decompiled_code:
__int64 __fastcall sll_append(_QWORD *a1, __int64 a2)
{
__int64 v2; // rbp
__int64 v3; // rax
__int64 result; // rax
_QWORD *v5; // rax

if ( *a1 )
{
v2 = a1[1];
*(_QWORD *)(v2 + 8) = new_sll_node(a2);
v3 = *(_QWORD *)(a1[1] + 8LL);
if ( v3 )
{
a1[1] = v3;
result = 1LL;
}
else
{
result = 0LL;
}
}
else
{
v5 = new_sll_node(a2);
*a1 = v5;
if ( v5 )
{
a1[1] = v5;
result = 1LL;
}
else
{
result = 0LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(_QWORD *a1, __int64 a2)
{
__int64 v2; // rbp
__int64 v3; // rax
__int64 result; // rax
_QWORD *v5; // rax

if ( *a1 )
{
v2 = a1[1];
*(_QWORD *)(v2 + 8) = new_sll_node(a2);
v3 = *(_QWORD *)(a1[1] + 8LL);
if ( v3 )
{
a1[1] = v3;
result = 1LL;
}
else
{
result = 0LL;
}
}
else
{
v5 = new_sll_node(a2);
*a1 = v5;
if ( v5 )
{
a1[1] = v5;
result = 1LL;
}
else
{
result = 0LL;
}
}
return result;
}

original_code:
int sll_append(singly_linked_list* sll, void* ptr) {
  if (sll->first) {
    sll->last->next = new_sll_node(ptr);
    if (!sll->last->next)
      return 0;
    sll->last = sll->last->next;
  } else {
    sll->first = new_sll_node(ptr);
    if (!sll->first)
      return 0;
    sll->last = sll->first;
  }
  return 1;
}

canonical_original_code:
int sll_append(struct singly_linked_list *sll, void *ptr) {
  if (sll->first) {
    sll->last->next = new_sll_node(ptr);
    if (!sll->last->next)
      return 0;
    sll->last = sll->last->next;
  } else {
    sll->first = new_sll_node(ptr);
    if (!sll->first)
      return 0;
    sll->last = sll->first;
  }
  return 1;
}

variable_types: struct singly_linked_list { struct sll_node { void *ptr; struct sll_node *next; } *first; struct sll_node *last; unsigned int count; } *

user_defined_types: struct singly_linked_list { struct sll_node *first; struct sll_node *last; unsigned int count; }


decompiled_code:
__int64 __fastcall sll_for_each(_QWORD *a1, __int64 (__fastcall *a2)(_QWORD))
{
_QWORD *v2; // rbx
__int64 result; // rax

if ( !a2 )
return 1LL;
v2 = (_QWORD *)*a1;
if ( !*a1 )
return 0LL;
do
{
result = a2(*v2);
if ( (_DWORD)result )
break;
v2 = (_QWORD *)v2[1];
}
while ( v2 );
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(_QWORD *a1, __int64 (__fastcall *a2)(_QWORD))
{
_QWORD *v2; // rbx
__int64 result; // rax

if ( !a2 )
return 1LL;
v2 = (_QWORD *)*a1;
if ( !*a1 )
return 0LL;
do
{
result = a2(*v2);
if ( (_DWORD)result )
break;
v2 = (_QWORD *)v2[1];
}
while ( v2 );
return result;
}

original_code:
int sll_for_each(singly_linked_list* sll, int callback(void*)) {
  if (!callback)
    return 1;
  int res = 0;
  struct sll_node* node = sll->first;
  while (node) {
    res = callback(node->ptr);
    if (res)
      return res;
    node = node->next;
  };
  return res;
}

canonical_original_code:
int sll_for_each(struct singly_linked_list *sll, int callback(void *)) {
  if (!callback)
    return 1;
  int res = 0;
  struct sll_node *node = sll->first;
  while (node) {
    res = callback(node->ptr);
    if (res)
      return res;
    node = node->next;
  };
  return res;
}

variable_types:
callback
int (void *)

variable_types: res int

variable_types: struct sll_node { void *ptr; struct sll_node *next; } *


decompiled_code:
void __fastcall sll_teardown(void *ptr, void (__fastcall *a2)(_QWORD))
{
_QWORD *v2; // rbx
_QWORD *v3; // rbp

v2 = *(_QWORD **)ptr;
if ( *(_QWORD *)ptr )
{
while ( 1 )
{
if ( a2 )
a2(*v2);
v3 = (_QWORD *)v2[1];
free(v2);
if ( !v3 )
break;
v2 = v3;
}
}
free(ptr);
}

canonical_decompiled_code:
void __fastcall func2(void *ptr, void (__fastcall *a2)(_QWORD))
{
_QWORD *v2; // rbx
_QWORD *v3; // rbp

v2 = *(_QWORD **)ptr;
if ( *(_QWORD *)ptr )
{
while ( 1 )
{
if ( a2 )
a2(*v2);
v3 = (_QWORD *)v2[1];
free(v2);
if ( !v3 )
break;
v2 = v3;
}
}
free(ptr);
}

original_code:
void sll_teardown(singly_linked_list* sll, void teardown_ptr(void*)) {
  struct sll_node* node = sll->first;
  while (node) {
    if (teardown_ptr)
      teardown_ptr(node->ptr);
    struct sll_node* next = node->next;
    free(node);
    node = next;
  };
  free(sll);
}

canonical_original_code:
void sll_teardown(struct singly_linked_list *sll, void teardown_ptr(void *)) {
  struct sll_node *node = sll->first;
  while (node) {
    if (teardown_ptr)
      teardown_ptr(node->ptr);
    struct sll_node *next = node->next;
    free(node);
    node = next;
  };
  free(sll);
}

user_defined_types: struct sll_node { void *ptr; struct sll_node *next; }


decompiled_code:
__int64 __fastcall sll_count_list(__int64 *a1)
{
__int64 v1; // rax
unsigned int v2; // edx

v1 = *a1;
if ( !*a1 )
return 0;
v2 = 0;
do
{
++v2;
v1 = *(_QWORD *)(v1 + 8);
}
while ( v1 );
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 *a1)
{
__int64 v1; // rax
unsigned int v2; // edx

v1 = *a1;
if ( !*a1 )
return 0;
v2 = 0;
do
{
++v2;
v1 = *(_QWORD *)(v1 + 8);
}
while ( v1 );
return v2;
}

original_code:
unsigned int sll_count_list(singly_linked_list* sll) {
  unsigned int i = 0;
  struct sll_node* node = sll->first;
  while (node) {
    i++;
    node = node->next;
  };
  return i;
}

canonical_original_code:
unsigned int sll_count_list(struct singly_linked_list *sll) {
  unsigned int i = 0;
  struct sll_node *node = sll->first;
  while (node) {
    i++;
    node = node->next;
  };
  return i;
}

variable_types:
i
unsigned int


decompiled_code:
__int64 __fastcall sll_remove_item_at(__int64 a1, __int64 a2, void (__fastcall *a3)(_QWORD))
{
_QWORD *v4; // rbx
int v5; // eax
_QWORD *v6; // rdx

if ( (_DWORD)a2 )
{
v4 = *(_QWORD **)a1;
v5 = 1;
do
{
v6 = v4;
v4 = (_QWORD *)v4[1];
if ( !v4 )
return 0LL;
++v5;
}
while ( (_DWORD)a2 != v5 );
v6[1] = v4[1];
if ( a3 )
a3(*v4);
}
else
{
v4 = *(_QWORD **)a1;
*(_QWORD *)a1 = *(_QWORD *)(*(_QWORD *)a1 + 8LL);
if ( a3 )
((void (__fastcall *)(_QWORD, __int64, void (__fastcall *)(_QWORD), void (__fastcall *)(_QWORD)))a3)(
*v4,
a2,
a3,
a3);
}
free(v4);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, __int64 a2, void (__fastcall *a3)(_QWORD))
{
_QWORD *v4; // rbx
int v5; // eax
_QWORD *v6; // rdx

if ( (_DWORD)a2 )
{
v4 = *(_QWORD **)a1;
v5 = 1;
do
{
v6 = v4;
v4 = (_QWORD *)v4[1];
if ( !v4 )
return 0LL;
++v5;
}
while ( (_DWORD)a2 != v5 );
v6[1] = v4[1];
if ( a3 )
a3(*v4);
}
else
{
v4 = *(_QWORD **)a1;
*(_QWORD *)a1 = *(_QWORD *)(*(_QWORD *)a1 + 8LL);
if ( a3 )
((void (__fastcall *)(_QWORD, __int64, void (__fastcall *)(_QWORD), void (__fastcall *)(_QWORD)))a3)(
*v4,
a2,
a3,
a3);
}
free(v4);
return 1LL;
}

original_code:
int sll_remove_item_at(singly_linked_list* sll, unsigned int item, void teardown_ptr(void*)) {
  if (item == 0) {
    struct sll_node* to_remove = sll->first;
    sll->first = sll->first->next;
    if (teardown_ptr)
      teardown_ptr(to_remove->ptr);
    free(to_remove);
    return 1;
  } else {
    struct sll_node* n = sll->first;
    unsigned int i = 1;
    while (n->next) {
      if (++i == item) {
        struct sll_node* m = n->next;
        n->next = n->next->next;
        if (teardown_ptr)
          teardown_ptr(m->ptr);
        free(m);
        return 1;
      };
      n = n->next;
    };
  };
  return 0;
}

canonical_original_code:
int sll_remove_item_at(struct singly_linked_list *sll, unsigned int item, void teardown_ptr(void *)) {
  if (item == 0) {
    struct sll_node *to_remove = sll->first;
    sll->first = sll->first->next;
    if (teardown_ptr)
      teardown_ptr(to_remove->ptr);
    free(to_remove);
    return 1;
  } else {
    struct sll_node *n = sll->first;
    unsigned int i = 1;
    while (n->next) {
      if (++i == item) {
        struct sll_node *m = n->next;
        n->next = n->next->next;
        if (teardown_ptr)
          teardown_ptr(m->ptr);
        free(m);
        return 1;
      };
      n = n->next;
    };
  };
  return 0;
}

variable_types:
item
unsigned int


decompiled_code:
__int64 __fastcall sll_remove_item(_QWORD **a1, __int64 a2, void (__fastcall *a3)(_QWORD))
{
_QWORD *v3; // rbx
_QWORD *v4; // rax

v3 = *a1;
if ( **a1 == a2 )
{
*a1 = (_QWORD *)v3[1];
if ( a3 )
a3(*v3);
}
else
{
do
{
v4 = v3;
v3 = (_QWORD *)v3[1];
if ( !v3 )
return 0LL;
}
while ( *v3 != a2 );
v4[1] = v3[1];
if ( a3 )
a3(*v3);
}
free(v3);
return 1LL;
}

original_code:
int sll_remove_item(singly_linked_list* sll, void* ptr, void teardown_ptr(void*)) {
  struct sll_node* node = sll->first;
  if (node->ptr == ptr) {
    sll->first = sll->first->next;
    if (teardown_ptr)
      teardown_ptr(node->ptr);
    free(node);
    return 1;
  } else {
    while (node->next) {
      if (node->next->ptr == ptr) {
        struct sll_node* to_free = node->next;
        node->next = node->next->next;
        if (teardown_ptr)
          teardown_ptr(to_free->ptr);
        free(to_free);
        return 1;
      };
      node = node->next;
    };
  };
  return 0;
}

canonical_original_code:
int sll_remove_item(struct singly_linked_list *sll, void *ptr, void teardown_ptr(void *)) {
  struct sll_node *node = sll->first;
  if (node->ptr == ptr) {
    sll->first = sll->first->next;
    if (teardown_ptr)
      teardown_ptr(node->ptr);
    free(node);
    return 1;
  } else {
    while (node->next) {
      if (node->next->ptr == ptr) {
        struct sll_node *to_free = node->next;
        node->next = node->next->next;
        if (teardown_ptr)
          teardown_ptr(to_free->ptr);
        free(to_free);
        return 1;
      };
      node = node->next;
    };
  };
  return 0;
}


repo: shenkin/lifesim

decompiled_code:
char *init_display()
{
unsigned int v0; // ebx
char *result; // rax

v0 = strlen(display_pro) + 1;
result = (char *)malloc(v0);
display = result;
if ( v0 >= 8 )
{
*(_QWORD *)&result[v0 - 8] = *(_QWORD *)((char *)&unk_404078 + v0);
qmemcpy(result, display_pro, 8LL * ((v0 - 1) >> 3));
}
else if ( (v0 & 4) != 0 )
{
*(_DWORD *)result = *(_DWORD *)display_pro;
*(_DWORD *)&result[v0 - 4] = *(_DWORD *)((char *)&unk_40407C + v0);
}
else if ( v0 )
{
*result = display_pro[0];
if ( (v0 & 2) != 0 )
*(_WORD *)&result[v0 - 2] = *(__int16 *)((char *)&word_40407E + v0);
}
return result;
}

canonical_decompiled_code:
char *func20()
{
unsigned int v0; // ebx
char *result; // rax

v0 = strlen(display_pro) + 1;
result = (char *)malloc(v0);
display = result;
if ( v0 >= 8 )
{
*(_QWORD *)&result[v0 - 8] = *(_QWORD *)((char *)&unk_404078 + v0);
qmemcpy(result, display_pro, 8LL * ((v0 - 1) >> 3));
}
else if ( (v0 & 4) != 0 )
{
*(_DWORD *)result = *(_DWORD *)display_pro;
*(_DWORD *)&result[v0 - 4] = *(_DWORD *)((char *)&unk_40407C + v0);
}
else if ( v0 )
{
*result = display_pro[0];
if ( (v0 & 2) != 0 )
*(_WORD *)&result[v0 - 2] = *(__int16 *)((char *)&word_40407E + v0);
}
return result;
}

original_code:
void init_display() {
    Uint len = strlen( display_pro );
    display = malloc( len + 1 );
    memcpy( display, display_pro, len+1 );
}

canonical_original_code:
void init_display() {
    unsigned int len = strlen( display_pro );
    display = malloc( len + 1 );
    memcpy( display, display_pro, len+1 );
}

variable_types:
len
unsigned int


decompiled_code:
void init_display_pro()
{
char v0; // dl
char *v1; // rax

v0 = display_pro[0];
if ( display_pro[0] )
{
v1 = display_pro;
do
{
if ( v0 == 66 )
*v1 = 92;
v0 = *++v1;
}
while ( *v1 );
}
}

canonical_decompiled_code:
void func21()
{
char v0; // dl
char *v1; // rax

v0 = display_pro[0];
if ( display_pro[0] )
{
v1 = display_pro;
do
{
if ( v0 == 66 )
*v1 = 92;
v0 = *++v1;
}
while ( *v1 );
}
}

original_code:
void init_display_pro() {
    for( char *p=display_pro; *p!='\0'; ++p ) {
        Uint offset = p - display_pro;
        if( *p == 'B' ) {
            *p = '\\';
        }
    }
}

canonical_original_code:
void init_display_pro() {
    for( char *p = display_pro; *p!='\0'; ++p ) {
        unsigned int offset = p - display_pro;
        if( *p == 'B' ) {
            *p = '\\';
        }
    }
}

variable_types:
p
char *

variable_types:
offset
unsigned int


decompiled_code:
size_t len_display()
{
return strlen(display);
}

canonical_decompiled_code:
size_t func22()
{
return strlen(display);
}

original_code:
Uint len_display( void ) {
    return strlen( display );
}

canonical_original_code:
unsigned int len_display() {
    return strlen( display );
}


decompiled_code:
void init_display_position()
{
int v0; // esi
char v1; // dl
char *v2; // rax
int v3; // ecx

v0 = (int)display;
v1 = *display;
if ( *display )
{
v2 = display;
v3 = 0;
do
{
if ( v1 == 120 )
display_position[v3++] = (_DWORD)v2 - v0;
v1 = *++v2;
}
while ( *v2 );
}
}

canonical_decompiled_code:
void func23()
{
int v0; // esi
char v1; // dl
char *v2; // rax
int v3; // ecx

v0 = (int)display;
v1 = *display;
if ( *display )
{
v2 = display;
v3 = 0;
do
{
if ( v1 == 120 )
display_position[v3++] = (_DWORD)v2 - v0;
v1 = *++v2;
}
while ( *v2 );
}
}

original_code:
void init_display_position() {
    Uint inode = 0;
    for( char *p=display; *p!='\0'; ++p ) {
        Uint offset = p - display;
        if( *p == 'x' ) {
            display_position[ inode ] = offset;
            inode += 1;
        }
    }
}

canonical_original_code:
void init_display_position() {
    unsigned int inode = 0;
    for( char *p = display; *p!='\0'; ++p ) {
        unsigned int offset = p - display;
        if( *p == 'x' ) {
            display_position[ inode ] = offset;
            inode += 1;
        }
    }
}

variable_types:
inode
unsigned int


decompiled_code:
__int64 __fastcall set_display(__int64 a1)
{
char *v1; // rsi
__int64 result; // rax

v1 = display;
for ( result = 0LL; result != 54; ++result )
v1[display_position[result]] = display_chars[*(unsigned int *)(a1 + result * 4)];
return result * 4;
}

canonical_decompiled_code:
__int64 __fastcall func24(__int64 a1)
{
char *v1; // rsi
__int64 result; // rax

v1 = display;
for ( result = 0LL; result != 54; ++result )
v1[display_position[result]] = display_chars[*(unsigned int *)(a1 + result * 4)];
return result * 4;
}

original_code:
void set_display( Uint state[54] ){
    for( Uint inode=0; inode<54; ++inode ) {
        Uint istate = state[ inode ];
        char c = display_chars[ istate ];
        Uint ipos = display_position[ inode ];
        display[ ipos ] = c;
    }
}

canonical_original_code:
void set_display(unsigned int state[54]){
    for( unsigned int inode = 0; inode<54; ++inode ) {
        unsigned int istate = state[ inode ];
        char c = display_chars[ istate ];
        unsigned int ipos = display_position[ inode ];
        display[ ipos ] = c;
    }
}

variable_types:
state
unsigned int [54]

variable_types:
istate
unsigned int

variable_types: c char

variable_types:
ipos
unsigned int


decompiled_code:
char *get_display()
{
return display;
}

canonical_decompiled_code:
char *func25()
{
return display;
}

original_code:
char *get_display() {
    return display;
}

canonical_original_code:
char *get_display() {
    return display;
}


decompiled_code:
__int64 __fastcall show_node_neighbors(unsigned int a1)
{
char v1; // r12
char v2; // bp
char *v3; // rsi
__int64 result; // rax
unsigned int v5; // edx

v1 = display_chars[0];
v2 = byte_404551;
init_display();
v3 = display;
display[display_position[a1]] = v1;
for ( result = 1LL; result != 5; ++result )
{
v5 = nodes[5 * a1 + result];
if ( v5 <= 0x35 )
v3[display_position[v5]] = v2;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func26(unsigned int a1)
{
char v1; // r12
char v2; // bp
char *v3; // rsi
__int64 result; // rax
unsigned int v5; // edx

v1 = display_chars[0];
v2 = byte_404551;
func20();
v3 = display;
display[display_position[a1]] = v1;
for ( result = 1LL; result != 5; ++result )
{
v5 = nodes[5 * a1 + result];
if ( v5 <= 0x35 )
v3[display_position[v5]] = v2;
}
return result;
}

original_code:
void show_node_neighbors( Uint inode ) {
    char cinode = display_chars[ 0 ];
    char cnnode = display_chars[ 1 ];
    init_display();
    Uint inode_pos = display_position[ inode ];
    display[ inode_pos ] = cinode;
    for( Uint jneigh=0; jneigh<4; jneigh+=1 ) {
        Uint nnode = nodes[ inode ].neighbors[ jneigh ];
        if( nnode < 54 ){
            Uint nnode_pos = display_position[ nnode ];
            display[ nnode_pos ] = cnnode;
        }
    }
}

canonical_original_code:
void show_node_neighbors(unsigned int inode) {
    char cinode = display_chars[ 0 ];
    char cnnode = display_chars[ 1 ];
    init_display();
    unsigned int inode_pos = display_position[ inode ];
    display[ inode_pos ] = cinode;
    for( unsigned int jneigh = 0; jneigh<4; jneigh+=1 ) {
        unsigned int nnode = nodes[ inode ].neighbors[ jneigh ];
        if( nnode < 54 ){
            unsigned int nnode_pos = display_position[ nnode ];
            display[ nnode_pos ] = cnnode;
        }
    }
}

variable_types: cinode char

variable_types: cnnode char

variable_types:
jneigh
unsigned int

variable_types:
nnode
unsigned int


makelist

repo: skorks/c-linked-list

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

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

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

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

original_code:
List * makelist(){
  List * list = malloc(sizeof(List));
  if (!list) {
    return ((void *)0);
  }
  list->head = ((void *)0);
  return list;
}

canonical_original_code:
struct list *makelist(){
  struct list *list = malloc(sizeof(List));
  if (!list) {
    return ((void *)0);
  }
  list->head = ((void *)0);
  return list;
}

variable_types: struct list { struct node { int data; struct node *next; } *head; } *


display

decompiled_code:
int __fastcall display(unsigned int **a1)
{
unsigned int *i; // rbx
int result; // eax

for ( i = *a1; i; i = (unsigned int *)*((_QWORD *)i + 1) )
result = printf("%d\n", *i);
return result;
}

canonical_decompiled_code:
int __fastcall func1(unsigned int **a1)
{
unsigned int *i; // rbx
int result; // eax

for ( i = *a1; i; i = (unsigned int *)*((_QWORD *)i + 1) )
result = printf("%d\n", *i);
return result;
}

original_code:
void display(List * list) {
  Node * current = list->head;
  if(list->head == ((void *)0))
    return;
  for(; current != ((void *)0); current = current->next) {
    printf("%d\n", current->data);
  }
}

canonical_original_code:
void display(struct list *list) {
  struct node *current = list->head;
  if(list->head == ((void *)0))
    return;
  for(; current != ((void *)0); current = current->next) {
    printf("%d\n", current->data);
  }
}

variable_types: struct node { int data; struct node *next; } *


delete

original_code:
void delete(int data, List * list){
  Node * current = list->head;
  Node * previous = current;
  while(current != ((void *)0)){
    if(current->data == data){
      previous->next = current->next;
      if(current == list->head)
        list->head = current->next;
      free(current);
      return;
    }
    previous = current;
    current = current->next;
  }
}

canonical_original_code:
void delete(int data, struct list *list){
  struct node *current = list->head;
  struct node *previous = current;
  while(current != ((void *)0)){
    if(current->data == data){
      previous->next = current->next;
      if(current == list->head)
        list->head = current->next;
      free(current);
      return;
    }
    previous = current;
    current = current->next;
  }
}

variable_types: data int

user_defined_types: struct node { int data; struct node *next; }


destroy

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

v2 = *(_QWORD **)ptr;
if ( *(_QWORD *)ptr )
{
do
{
v3 = v2;
v2 = (_QWORD *)v2[1];
free(v3);
}
while ( v2 );
}
free(ptr);
}

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

v2 = *(_QWORD **)ptr;
if ( *(_QWORD *)ptr )
{
do
{
v3 = v2;
v2 = (_QWORD *)v2[1];
free(v3);
}
while ( v2 );
}
free(ptr);
}

original_code:
void destroy(List * list){
  Node * current = list->head;
  Node * next = current;
  while(current != ((void *)0)){
    next = current->next;
    free(current);
    current = next;
  }
  free(list);
}

canonical_original_code:
void destroy(struct list *list){
  struct node *current = list->head;
  struct node *next = current;
  while(current != ((void *)0)){
    next = current->next;
    free(current);
    current = next;
  }
  free(list);
}


logperror

repo: spe-ciellt/sertest

decompiled_code:
void __fastcall logperror(const char *a1)
{
perror(a1);
}

canonical_decompiled_code:
void __fastcall func7(const char *a1)
{
perror(a1);
}

original_code:
static void
logperror(char *s)
{
    perror(s);
}

variable_types:
s
char *


decompiled_code:
__int64 __fastcall open_serial(const char *a1, speed_t a2)
{
int v2; // eax
unsigned int v3; // ebx
struct termios v5; // [rsp+0h] [rbp-58h] BYREF

v2 = open(a1, 258);
if ( v2 < 0 )
{
logperror("open serial device");
v3 = -1;
}
else
{
v3 = v2;
if ( tcgetattr(v2, &v5) < 0 )
{
logperror("tcgetattr");
v3 = -1;
}
else if ( cfsetispeed(&v5, a2) < 0 )
{
logperror("cfsetispeed ");
v3 = -1;
}
else if ( cfsetospeed(&v5, a2) < 0 )
{
logperror("cfsetospeed ");
v3 = -1;
}
else
{
v5.c_iflag &= 0xFFFFFA14;
v5.c_oflag &= 0xFFFFFFFA;
v5.c_lflag &= 0xFFFF7FB4;
v5.c_cflag = v5.c_cflag & 0xFFFFFECF | 0x30;
if ( tcsetattr(v3, 0, &v5) < 0 )
{
logperror("tcsetattr");
v3 = -1;
}
}
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func8(const char *a1, speed_t a2)
{
int v2; // eax
unsigned int v3; // ebx
struct termios v5; // [rsp+0h] [rbp-58h] BYREF

v2 = open(a1, 258);
if ( v2 < 0 )
{
func7("open serial device");
v3 = -1;
}
else
{
v3 = v2;
if ( tcgetattr(v2, &v5) < 0 )
{
func7("tcgetattr");
v3 = -1;
}
else if ( cfsetispeed(&v5, a2) < 0 )
{
func7("cfsetispeed ");
v3 = -1;
}
else if ( cfsetospeed(&v5, a2) < 0 )
{
func7("cfsetospeed ");
v3 = -1;
}
else
{
v5.c_iflag &= 0xFFFFFA14;
v5.c_oflag &= 0xFFFFFFFA;
v5.c_lflag &= 0xFFFF7FB4;
v5.c_cflag = v5.c_cflag & 0xFFFFFECF | 0x30;
if ( tcsetattr(v3, 0, &v5) < 0 )
{
func7("tcsetattr");
v3 = -1;
}
}
}
return v3;
}

original_code:
static int
open_serial(const char *device, int speed)
{
    int fd;
    struct termios termios;
    if ((fd = open(device, 02 | 0400)) < 0) {
 logperror("open serial device");
 return -1;
    }
    if (tcgetattr(fd, &termios) < 0) {
 logperror("tcgetattr");
 return -1;
    }
    if (cfsetispeed(&termios, speed) < 0) {
 logperror("cfsetispeed ");
 return -1;
    }
    if (cfsetospeed(&termios, speed) < 0) {
 logperror("cfsetospeed ");
 return -1;
    }
    termios.c_iflag &= ~(0000001 | 0000002 | 0000010 | 0000040
                         | 0000100 | 0000200 | 0000400 | 0002000);
    termios.c_oflag &= ~(0000004 | 0000001);
    termios.c_lflag &= ~(0000010 | 0000100 | 0000002 | 0000001 | 0100000);
    termios.c_cflag &= ~(0000060 | 0000400);
    termios.c_cflag |= 0000060;
    if (tcsetattr(fd, 0, &termios) < 0) {
 logperror("tcsetattr");
 return -1;
    }
    return fd;
}

canonical_original_code:
static int open_serial(char *device, int speed)
{
    int fd;
    struct termios termios;
    if ((fd = open(device, 02 | 0400)) < 0) {
 logperror("open serial device");
 return -1;
    }
    if (tcgetattr(fd, &termios) < 0) {
 logperror("tcgetattr");
 return -1;
    }
    if (cfsetispeed(&termios, speed) < 0) {
 logperror("cfsetispeed ");
 return -1;
    }
    if (cfsetospeed(&termios, speed) < 0) {
 logperror("cfsetospeed ");
 return -1;
    }
    termios.c_iflag &= ~(0000001 | 0000002 | 0000010 | 0000040
                         | 0000100 | 0000200 | 0000400 | 0002000);
    termios.c_oflag &= ~(0000004 | 0000001);
    termios.c_lflag &= ~(0000010 | 0000100 | 0000002 | 0000001 | 0100000);
    termios.c_cflag &= ~(0000060 | 0000400);
    termios.c_cflag |= 0000060;
    if (tcsetattr(fd, 0, &termios) < 0) {
 logperror("tcsetattr");
 return -1;
    }
    return fd;
}

variable_types:
device
char *

variable_types: speed int

variable_types: fd 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 send_teststring(int fd)
{
const char *v1; // rbx
__int64 result; // rax
char buf[25]; // [rsp+Fh] [rbp-19h] BYREF

v1 = "nly carrige \n return in the middle";
LOBYTE(result) = 111;
do
{
buf[0] = result;
write(fd, buf, 1uLL);
result = *(unsigned __int8 *)v1++;
}
while ( (_BYTE)result );
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(int fd)
{
const char *v1; // rbx
__int64 result; // rax
char buf[25]; // [rsp+Fh] [rbp-19h] BYREF

v1 = "nly carrige \n return in the middle";
LOBYTE(result) = 111;
do
{
buf[0] = result;
write(fd, buf, 1uLL);
result = *(unsigned __int8 *)v1++;
}
while ( (_BYTE)result );
return result;
}

original_code:
static void
send_teststring(int fd)
{
    int i;
    char out;
    for (i = 0; teststring[i] != 0; i++) {
        out = teststring[i];
        write(fd, &out, sizeof(out));
    }
}

variable_types: i int

variable_types: out char


decompiled_code:
__int64 __fastcall receive_teststring(int fd)
{
int v1; // eax
unsigned int v2; // ebp
char buf; // [rsp+Fh] [rbp-A9h] BYREF
struct timeval timeout; // [rsp+10h] [rbp-A8h] BYREF
fd_set readfds; // [rsp+20h] [rbp-98h] BYREF

buf = 0;
memset(&readfds, 0, sizeof(readfds));
readfds.fds_bits[fd / 64] |= 1LL << (fd % 64);
timeout.tv_sec = 1LL;
timeout.tv_usec = 0LL;
v1 = select(fd + 1, &readfds, 0LL, 0LL, &timeout);
if ( v1 == 1 )
{
if ( (unsigned int)read(fd, &buf, 1uLL) != 1 )
fwrite("read uneven number of read data", 1uLL, 0x1FuLL, stderr);
if ( ((*__ctype_b_loc())[buf] & 0x4000) != 0 )
putchar(buf);
else
printf("[%d]", (unsigned int)buf);
v2 = 0;
}
else
{
v2 = v1;
if ( v1 )
{
if ( v1 == -1 )
{
perror("select");
}
else
{
fwrite("Unknown return value from read select.\n", 1uLL, 0x27uLL, stderr);
v2 = -1;
}
}
else
{
v2 = -2;
}
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func10(int fd)
{
int v1; // eax
unsigned int v2; // ebp
char buf; // [rsp+Fh] [rbp-A9h] BYREF
struct timeval timeout; // [rsp+10h] [rbp-A8h] BYREF
fd_set readfds; // [rsp+20h] [rbp-98h] BYREF

buf = 0;
memset(&readfds, 0, sizeof(readfds));
readfds.fds_bits[fd / 64] |= 1LL << (fd % 64);
timeout.tv_sec = 1LL;
timeout.tv_usec = 0LL;
v1 = select(fd + 1, &readfds, 0LL, 0LL, &timeout);
if ( v1 == 1 )
{
if ( (unsigned int)read(fd, &buf, 1uLL) != 1 )
fwrite("read uneven number of read data", 1uLL, 0x1FuLL, stderr);
if ( ((*__ctype_b_loc())[buf] & 0x4000) != 0 )
putchar(buf);
else
printf("[%d]", (unsigned int)buf);
v2 = 0;
}
else
{
v2 = v1;
if ( v1 )
{
if ( v1 == -1 )
{
perror("select");
}
else
{
fwrite("Unknown return value from read select.\n", 1uLL, 0x27uLL, stderr);
v2 = -1;
}
}
else
{
v2 = -2;
}
}
return v2;
}

original_code:
static int
receive_teststring(int fd)
{
    fd_set rfds;
    struct timeval timeout;
    int nuf_fd;
    int nuf_read = 0;
    char buffer = 0;
    do { int __d0, __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&rfds)->__fds_bits)[0]) : "memory"); } while (0);
    ((void) (((&rfds)->__fds_bits)[((fd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((fd) % (8 * (int) sizeof (__fd_mask)))))));
    timeout.tv_sec = 1;
    timeout.tv_usec = 0;
    nuf_fd = select(fd + 1, &rfds, ((void *)0), ((void *)0), &timeout);
    if (nuf_fd == 1) {
    } else if (nuf_fd == 0) {
        return -2;
    } else if (nuf_fd == -1) {
        perror("select");
        return -1;
    } else {
        fprintf(stderr, "Unknown return value from read select.\n");
        return -1;
    }
    nuf_read = read(fd, (void *)&buffer, sizeof(buffer));
    if (nuf_read != sizeof(buffer)) {
        fprintf(stderr, "read uneven number of read data");
    }
    if (((*__ctype_b_loc ())[(int) ((buffer))] & (unsigned short int) _ISprint)) {
        printf("%c", buffer);
    } else {
        printf("[%d]", buffer);
    }
    return 0;
}

canonical_original_code:
static int receive_teststring(int fd)
{
    struct fd_set rfds;
    struct timeval timeout;
    int nuf_fd;
    int nuf_read = 0;
    char buffer = 0;
    do { int __d0; int __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&rfds)->__fds_bits)[0]) : "memory"); } while (0);
    ((void) (((&rfds)->__fds_bits)[((fd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((fd) % (8 * (int) sizeof (__fd_mask)))))));
    timeout.tv_sec = 1;
    timeout.tv_usec = 0;
    nuf_fd = select(fd + 1, &rfds, ((void *)0), ((void *)0), &timeout);
    if (nuf_fd == 1) {
    } else if (nuf_fd == 0) {
        return -2;
    } else if (nuf_fd == -1) {
        perror("select");
        return -1;
    } else {
        fprintf(stderr, "Unknown return value from read select.\n");
        return -1;
    }
    nuf_read = read(fd, (void *)&buffer, sizeof(buffer));
    if (nuf_read != sizeof(buffer)) {
        fprintf(stderr, "read uneven number of read data");
    }
    if (((*__ctype_b_loc ())[(int) ((buffer))] & (unsigned short) _ISprint)) {
        printf("%c", buffer);
    } else {
        printf("[%d]", buffer);
    }
    return 0;
}

variable_types:
rfds
struct fd_set { long __fds_bits[-1]; }

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

variable_types: buffer char


decompiled_code:
__int64 string2speed()
{
int v0; // eax
int v1; // edx
__int64 result; // rax

v0 = atoi(optarg);
if ( v0 == 9600 )
return 13LL;
v1 = v0;
if ( v0 <= 9600 )
{
result = 11LL;
if ( v1 != 2400 )
{
if ( v1 <= 2400 )
{
result = 9LL;
if ( v1 != 1200 )
{
result = 0xFFFFFFFFLL;
if ( v1 == 1800 )
result = 10LL;
}
}
else
{
result = 0xFFFFFFFFLL;
if ( v1 == 4800 )
result = 12LL;
}
}
}
else
{
result = 4097LL;
if ( v1 != 57600 )
{
if ( v1 <= 57600 )
{
result = 14LL;
if ( v1 != 19200 )
{
result = 0xFFFFFFFFLL;
if ( v1 == 38400 )
result = 15LL;
}
}
else
{
result = 0xFFFFFFFFLL;
if ( v1 == 115200 )
result = 4098LL;
}
}
}
return result;
}

canonical_decompiled_code:
__int64 func11()
{
int v0; // eax
int v1; // edx
__int64 result; // rax

v0 = atoi(optarg);
if ( v0 == 9600 )
return 13LL;
v1 = v0;
if ( v0 <= 9600 )
{
result = 11LL;
if ( v1 != 2400 )
{
if ( v1 <= 2400 )
{
result = 9LL;
if ( v1 != 1200 )
{
result = 0xFFFFFFFFLL;
if ( v1 == 1800 )
result = 10LL;
}
}
else
{
result = 0xFFFFFFFFLL;
if ( v1 == 4800 )
result = 12LL;
}
}
}
else
{
result = 4097LL;
if ( v1 != 57600 )
{
if ( v1 <= 57600 )
{
result = 14LL;
if ( v1 != 19200 )
{
result = 0xFFFFFFFFLL;
if ( v1 == 38400 )
result = 15LL;
}
}
else
{
result = 0xFFFFFFFFLL;
if ( v1 == 115200 )
result = 4098LL;
}
}
}
return result;
}

original_code:
int
string2speed(char *speed)
{
    int serialspeed = 0;
    switch (atoi(optarg)) {
    case 1200:
        serialspeed = 0000011;
        break;
    case 1800:
        serialspeed = 0000012;
        break;
    case 2400:
        serialspeed = 0000013;
        break;
    case 4800:
        serialspeed = 0000014;
        break;
    case 9600:
        serialspeed = 0000015;
        break;
    case 19200:
        serialspeed = 0000016;
        break;
    case 38400:
        serialspeed = 0000017;
        break;
    case 57600:
        serialspeed = 0010001;
        break;
    case 115200:
        serialspeed = 0010002;
        break;
    default:
        serialspeed = -1;
    }
    return serialspeed;
}

variable_types:
speed
char *

variable_types: serialspeed int


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // r12
const char *v4; // rbx
signed int v5; // ebp
int v6; // eax
int v7; // ebx

v3 = "/dev/ttyUSB0";
if ( argc > 1 )
v3 = argv[1];
if ( argc <= 2 )
{
v5 = 4098;
}
else
{
v4 = argv[2];
v5 = string2speed(v4, argv, envp);
if ( v5 < 0 )
{
fprintf(stderr, "No such serial speed %s\n", v4);
exit(0);
}
}
v6 = open_serial(v3, v5);
v7 = v6;
if ( v6 < 0 )
{
fprintf(stderr, "Failed to open serial port %s at speed %d\n", v3, (unsigned int)v5);
exit(0);
}
send_teststring(v6);
while ( !(unsigned int)receive_teststring(v7) )
;
close(v7);
putchar(10);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // r12
const char *v4; // rbx
signed int v5; // ebp
int v6; // eax
int v7; // ebx

v3 = "/dev/ttyUSB0";
if ( argc > 1 )
v3 = argv[1];
if ( argc <= 2 )
{
v5 = 4098;
}
else
{
v4 = argv[2];
v5 = func11(v4, argv, envp);
if ( v5 < 0 )
{
fprintf(stderr, "No such serial speed %s\n", v4);
exit(0);
}
}
v6 = func8(v3, v5);
v7 = v6;
if ( v6 < 0 )
{
fprintf(stderr, "Failed to open serial port %s at speed %d\n", v3, (unsigned int)v5);
exit(0);
}
func9(v6);
while ( !(unsigned int)func10(v7) )
;
close(v7);
putchar(10);
return 0;
}

original_code:
int
main(int argc, char *argv[])
{
    int fd = 0;
    char *device = (char *)default_serialdevice;
    int speed = default_serialspeed;
    if (argc >= 2) {
        device = argv[1];
    }
    if (argc >= 3) {
        speed = string2speed(argv[2]);
    }
    if (speed < 0) {
        fprintf(stderr, "No such serial speed %s\n", argv[2]);
        exit(0);
    }
    if ((fd = open_serial(device, speed)) < 0) {
        fprintf(stderr, "Failed to open serial port %s at speed %d\n",
                device, speed);
        exit(0);
    }
    send_teststring(fd);
    while (receive_teststring(fd) == 0);
    close(fd);
    printf("\n");
    return 0;
}

variable_types: argc int

variable_types:
argv
char *[]