decompiled_code:
__int64 __fastcall mkdir1(int a1, __int64 a2)
{
__int64 result; // rax

if ( a1 != 2 )
{
puts("Usage: mkdir V6-directory");
exit(-1);
}
if ( curr_fd == -1 )
{
perror("disk doesn't exist!\n");
exit(-1);
}
if ( (unsigned int)find_directory_in_directory(*(_QWORD *)(a2 + 8), &root2) == -1 )
{
make_directory_in_directory(*(_QWORD *)(a2 + 8), &root2);
result = 0LL;
}
else
{
printf("Diretory %s exists! Can't override an existing file\n", *(const char **)(a2 + 8));
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(int a1, __int64 a2)
{
__int64 result; // rax

if ( a1 != 2 )
{
puts("Usage: mkdir V6-directory");
exit(-1);
}
if ( curr_fd == -1 )
{
perror("disk doesn't exist!\n");
exit(-1);
}
if ( (unsigned int)find_directory_in_directory(*(_QWORD *)(a2 + 8), &root2) == -1 )
{
make_directory_in_directory(*(_QWORD *)(a2 + 8), &root2);
result = 0LL;
}
else
{
printf("Diretory %s exists! Can't override an existing file\n", *(const char **)(a2 + 8));
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
int mkdir1 (int argc, char** argv) {
    char* dir_name;
    if(argc != 2) {
         printf("Usage: mkdir V6-directory\n");
         exit(-1);
    }
    if (curr_fd == -1) {
         perror("disk doesn't exist!\n");
         exit(-1);
    }
    int curr_inode_number = find_directory_in_directory(argv[1], &root2);
    if (curr_inode_number != -1) {
        printf("Diretory %s exists! Can't override an existing file\n", argv[1]);
        return -1;
    }
    dir_name = argv[1];
    make_directory_in_directory(dir_name, &root2);
    return 0;
}

canonical_original_code:
int mkdir1(int argc, char **argv) {
    char *dir_name;
    if(argc != 2) {
         printf("Usage: mkdir V6-directory\n");
         exit(-1);
    }
    if (curr_fd == -1) {
         perror("disk doesn't exist!\n");
         exit(-1);
    }
    int curr_inode_number = find_directory_in_directory(argv[1], &root2);
    if (curr_inode_number != -1) {
        printf("Diretory %s exists! Can't override an existing file\n", argv[1]);
        return -1;
    }
    dir_name = argv[1];
    make_directory_in_directory(dir_name, &root2);
    return 0;
}


ls

repo: Blizzardking/FileSystem

decompiled_code:
__int64 __fastcall ls(int a1)
{
int v1; // eax
__int64 v2; // rbp
__int64 v3; // rbx
__int64 v4; // rbx
void *ptr; // [rsp+8h] [rbp-20h] BYREF

if ( a1 != 1 )
{
puts("Usage: ls");
exit(-1);
}
if ( curr_fd == -1 )
{
perror("disk doesn't exist!\n");
exit(-1);
}
v1 = list_directory(&ptr, &root2);
if ( v1 <= 0 )
{
putchar(10);
}
else
{
v2 = 8LL * (unsigned int)v1;
v3 = 0LL;
do
{
printf("%s\t", *(const char **)((char *)ptr + v3));
v3 += 8LL;
}
while ( v3 != v2 );
putchar(10);
v4 = 0LL;
do
{
free(*(void **)((char *)ptr + v4));
v4 += 8LL;
}
while ( v4 != v2 );
}
free(ptr);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func4(int a1)
{
int v1; // eax
__int64 v2; // rbp
__int64 v3; // rbx
__int64 v4; // rbx
void *ptr; // [rsp+8h] [rbp-20h] BYREF

if ( a1 != 1 )
{
puts("Usage: ls");
exit(-1);
}
if ( curr_fd == -1 )
{
perror("disk doesn't exist!\n");
exit(-1);
}
v1 = list_directory(&ptr, &root2);
if ( v1 <= 0 )
{
putchar(10);
}
else
{
v2 = 8LL * (unsigned int)v1;
v3 = 0LL;
do
{
printf("%s\t", *(const char **)((char *)ptr + v3));
v3 += 8LL;
}
while ( v3 != v2 );
putchar(10);
v4 = 0LL;
do
{
free(*(void **)((char *)ptr + v4));
v4 += 8LL;
}
while ( v4 != v2 );
}
free(ptr);
return 0LL;
}

original_code:
int ls(int argc, char** argv) {
    char** all_files_in_curr_diretory;
    if(argc != 1) {
         printf("Usage: ls\n");
         exit(-1);
    }
    if (curr_fd == -1) {
         perror("disk doesn't exist!\n");
         exit(-1);
    }
    int file_count = list_directory(&all_files_in_curr_diretory,&root2);
    int i;
    for(i = 0; i < file_count; i++) {
        printf("%s\t",all_files_in_curr_diretory[i]);
    }
    printf("\n");
    for (i = 0; i < file_count; ++i)
    {
        free(all_files_in_curr_diretory[i]);
    }
    free(all_files_in_curr_diretory);
    return 0;
}

canonical_original_code:
int ls(int argc, char **argv) {
    char **all_files_in_curr_diretory;
    if(argc != 1) {
         printf("Usage: ls\n");
         exit(-1);
    }
    if (curr_fd == -1) {
         perror("disk doesn't exist!\n");
         exit(-1);
    }
    int file_count = list_directory(&all_files_in_curr_diretory,&root2);
    int i;
    for(i = 0; i < file_count; i++) {
        printf("%s\t",all_files_in_curr_diretory[i]);
    }
    printf("\n");
    for (i = 0; i < file_count; ++i)
    {
        free(all_files_in_curr_diretory[i]);
    }
    free(all_files_in_curr_diretory);
    return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types: i int

return_type: int


repo: BlurryRoots/Lq

decompiled_code:
char *__fastcall lexer_state_to_string(int a1)
{
char *result; // rax

switch ( a1 )
{
case 0:
result = IDLE_STRING;
break;
case 1:
result = READ_SYMBOL_STRING;
break;
case 2:
result = READ_COMMENT_STRING;
break;
case 3:
result = READ_STRING_STRING;
break;
case 4:
result = READ_NUMBER_STRING;
break;
case 5:
result = LEXER_SUCCESS_STRING;
break;
case 6:
result = LEXER_ERROR_STRING;
break;
default:
result = UNKNOWN_STRING;
break;
}
return result;
}

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

switch ( a1 )
{
case 0:
result = IDLE_STRING;
break;
case 1:
result = READ_SYMBOL_STRING;
break;
case 2:
result = READ_COMMENT_STRING;
break;
case 3:
result = READ_STRING_STRING;
break;
case 4:
result = READ_NUMBER_STRING;
break;
case 5:
result = LEXER_SUCCESS_STRING;
break;
case 6:
result = LEXER_ERROR_STRING;
break;
default:
result = UNKNOWN_STRING;
break;
}
return result;
}

original_code:
const char*
lexer_state_to_string( lexer_state someState )
{
    switch( someState )
    {
        case IDLE:
            return IDLE_STRING;
        break;
        case READ_SYMBOL:
            return READ_SYMBOL_STRING;
        break;
        case READ_STRING:
            return READ_STRING_STRING;
        break;
        case READ_COMMENT:
            return READ_COMMENT_STRING;
        break;
        case READ_NUMBER:
            return READ_NUMBER_STRING;
        break;
        case LEXER_SUCCESS:
            return LEXER_SUCCESS_STRING;
        break;
        case LEXER_ERROR:
            return LEXER_ERROR_STRING;
        break;
        default:
            return UNKNOWN_STRING;
        break;
    }
}

canonical_original_code:
char *lexer_state_to_string(enum lexer_state someState)
{
    switch( someState )
    {
        case IDLE:
            return IDLE_STRING;
        break;
        case READ_SYMBOL:
            return READ_SYMBOL_STRING;
        break;
        case READ_STRING:
            return READ_STRING_STRING;
        break;
        case READ_COMMENT:
            return READ_COMMENT_STRING;
        break;
        case READ_NUMBER:
            return READ_NUMBER_STRING;
        break;
        case LEXER_SUCCESS:
            return LEXER_SUCCESS_STRING;
        break;
        case LEXER_ERROR:
            return LEXER_ERROR_STRING;
        break;
        default:
            return UNKNOWN_STRING;
        break;
    }
}

variable_types: enum lexer_state { IDLE=0, READ_SYMBOL=1, READ_COMMENT=2, READ_STRING=3, READ_NUMBER=4, LEXER_SUCCESS=5, LEXER_ERROR=6 }

return_type: char *


decompiled_code:
__int64 __fastcall lexer_reset(__m128i *a1)
{
__int64 result; // rax
__m128i v2; // [rsp+0h] [rbp-28h] BYREF
__m128i v3; // [rsp+10h] [rbp-18h] BYREF

result = 0LL;
if ( a1 )
{
string_free(a1[1].m128i_i64[1]);
a1[1].m128i_i64[1] = 0LL;
token_list_free(a1);
lexer_create(&v2);
*a1 = _mm_loadu_si128(&v2);
a1[1] = _mm_loadu_si128(&v3);
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__m128i *a1)
{
__int64 result; // rax
__m128i v2; // [rsp+0h] [rbp-28h] BYREF
__m128i v3; // [rsp+10h] [rbp-18h] BYREF

result = 0LL;
if ( a1 )
{
string_free(a1[1].m128i_i64[1]);
a1[1].m128i_i64[1] = 0LL;
token_list_free(a1);
lexer_create(&v2);
*a1 = _mm_loadu_si128(&v2);
a1[1] = _mm_loadu_si128(&v3);
result = 1LL;
}
return result;
}

original_code:
int
lexer_reset( lexer_t* someLexer )
{
    if( ! someLexer )
    {
        return 0;
    }
    string_free( someLexer->errorMessage );
    someLexer->errorMessage = ((void *)0);
    token_list_free( & someLexer->tokenlist );
    *someLexer = lexer_create();
    return 1;
}

canonical_original_code:
int lexer_reset(struct lexer_t *someLexer)
{
    if( ! someLexer )
    {
        return 0;
    }
    string_free( someLexer->errorMessage );
    someLexer->errorMessage = ((void *)0);
    token_list_free( & someLexer->tokenlist );
    *someLexer = lexer_create();
    return 1;
}

variable_types: struct lexer_t { struct token_list_t { struct token_t { struct string_t { int *data; unsigned long length; unsigned long capacity; } *symbol; enum token_type { SYMBOL=0, STRING=1, NUMBER=2, LIST_BEGIN=3, LIST_END=4, QUOTE=5 } type; unsigned long line; unsigned long column; } *tokens; unsigned long size; } tokenlist; enum lexer_state { IDLE=0, READ_SYMBOL=1, READ_COMMENT=2, READ_STRING=3, READ_NUMBER=4, LEXER_SUCCESS=5, LEXER_ERROR=6 } state; struct string_t *errorMessage; } *

user_defined_types: struct lexer_t { struct token_list_t tokenlist; enum lexer_state state; struct string_t *errorMessage; }

user_defined_types: struct token_list_t { struct token_t *tokens; unsigned long size; }

user_defined_types: struct token_t { struct string_t *symbol; enum token_type type; unsigned long line; unsigned long column; }


original_code:
int
lexer_scan( lexer_t* someLexer, const string_t* someScript )
{
    size_t iterator, line, column;
    string_t* buffer;
    token_type typeBuffer;
    wchar_t c;
    if( ! someLexer )
    {
        return 0;
    }
    if( someScript->length == 0 )
    {
        someLexer->state = LEXER_SUCCESS;
    }
    iterator = 0;
    line = column = 0;
    buffer = string_new();
    while( 1 )
    {
        c = someScript->data[iterator];
        ++column;
        if( someLexer->state == IDLE )
        {
            if( ((c == L' ') || (c == L'\t') || (c == L'\n')) )
            {
                if( (c == L'\n') )
                {
                    column = 0;
                    ++line;
                }
                goto LABEL_continue;
            }
            if( (c == L';') )
            {
                someLexer->state = READ_COMMENT;
                goto LABEL_continue;
            }
            if( (c >= L'0' && c <= L'9') )
            {
                someLexer->state = READ_NUMBER;
                string_append( buffer, c );
                goto LABEL_continue;
            }
            if( (c == L'(')
             || (c == L')') )
            {
                someLexer->state = IDLE;
                string_append( buffer, c );
                typeBuffer =
                    ((c == L'(')
                        ? LIST_BEGIN
                        : LIST_END);
                goto LABEL_append_token;
            }
            if( (c == L'\'') )
            {
                someLexer->state = IDLE;
                string_append( buffer, c );
                typeBuffer = QUOTE;
                goto LABEL_append_token;
            }
            if( (c >= L'!' && c <= L'~') || (c >= L'¡' && c <= L'ÿ') )
            {
                someLexer->state = READ_SYMBOL;
                string_append( buffer, c );
            }
            goto LABEL_continue;
        }
        if( someLexer->state == READ_COMMENT )
        {
            if( (c == L'\n') )
            {
                someLexer->state = IDLE;
            }
            goto LABEL_continue;
        }
        if( someLexer->state == READ_STRING )
        {
            if( (c == L'"') )
            {
                someLexer->state = IDLE;
                typeBuffer = STRING;
                goto LABEL_append_token;
            }
            string_append( buffer, c );
            goto LABEL_continue;
        }
        if( someLexer->state == READ_SYMBOL )
        {
            static int finalize = 0;
            if( (c == L';') )
            {
                someLexer->state = READ_COMMENT;
                finalize = 1;
            }
            else if( (c == L'"') )
            {
                someLexer->state = READ_STRING;
                finalize = 1;
            }
            else if( ((c == L' ') || (c == L'\t') || (c == L'\n')) )
            {
                someLexer->state = IDLE;
                finalize = 1;
            }
            else if( (c == L'(')
                  || (c == L')') )
            {
                token_list_append(
                    & someLexer->tokenlist,
                    buffer,
                    SYMBOL,
                    line,
                    column
                );
                string_free( buffer );
                buffer = string_new();
                someLexer->state = IDLE;
                string_append( buffer, c );
                typeBuffer =
                    ((c == L'(')
                        ? LIST_BEGIN
                        : LIST_END);
                goto LABEL_append_token;
            }
            else if( (c == L'\'') )
            {
                token_list_append(
                    & someLexer->tokenlist,
                    buffer,
                    NUMBER,
                    line,
                    column
                );
                string_free( buffer );
                buffer = string_new();
                someLexer->state = IDLE;
                string_append( buffer, c );
                typeBuffer = QUOTE;
                goto LABEL_append_token;
            }
            if( finalize )
            {
                finalize = 0;
                typeBuffer = SYMBOL;
                goto LABEL_append_token;
            }
            string_append( buffer, c );
            goto LABEL_continue;
        }
        if( someLexer->state == READ_NUMBER )
        {
            static int finalize = 0;
            static int hadDecimalPoint = 0;
            if( ((c == L' ') || (c == L'\t') || (c == L'\n')) )
            {
                someLexer->state = IDLE;
                finalize = 1;
            }
            else if( (c == L';') )
            {
                someLexer->state = READ_COMMENT;
                finalize = 1;
            }
            else if( (c == L'"') )
            {
                someLexer->state = READ_STRING;
                finalize = 1;
            }
            else if( (c == L'(')
                  || (c == L')') )
            {
                finalize = 0;
                hadDecimalPoint = 0;
                token_list_append(
                    & someLexer->tokenlist,
                    buffer,
                    NUMBER,
                    line,
                    column
                );
                string_free( buffer );
                buffer = string_new();
                someLexer->state = IDLE;
                string_append( buffer, c );
                typeBuffer =
                    ((c == L'(')
                        ? LIST_BEGIN
                        : LIST_END);
                goto LABEL_append_token;
            }
            else if( (c == L'\'') )
            {
                finalize = 0;
                hadDecimalPoint = 0;
                token_list_append(
                    & someLexer->tokenlist,
                    buffer,
                    NUMBER,
                    line,
                    column
                );
                string_free( buffer );
                buffer = string_new();
                someLexer->state = IDLE;
                string_append( buffer, c );
                typeBuffer = QUOTE;
                goto LABEL_append_token;
            }
            else if( (c == L'.') )
            {
                if( hadDecimalPoint )
                {
                    someLexer->state = LEXER_ERROR;
                    string_copy_cstr(
                        someLexer->errorMessage,
                        L"Error: while reading number -> second decimal point!"
                    );
                }
                else
                {
                    hadDecimalPoint = 1;
                    string_append( buffer, c );
                }
                goto LABEL_continue;
            }
            else if( (c >= L'0' && c <= L'9') )
            {
                string_append( buffer, c );
                goto LABEL_continue;
            }
            else if( (c >= L'!' && c <= L'~') || (c >= L'¡' && c <= L'ÿ') )
            {
                someLexer->state = LEXER_ERROR;
                string_copy_cstr(
                    someLexer->errorMessage,
                    L"Error: while reading number -> found symbol!"
                );
                goto LABEL_continue;
            }
            if( finalize )
            {
                finalize = 0;
                hadDecimalPoint = 0;
                someLexer->state = IDLE;
                typeBuffer = NUMBER;
                goto LABEL_append_token;
            }
            goto LABEL_continue;
        }
LABEL_append_token:
        token_list_append(
            & someLexer->tokenlist,
            buffer,
            typeBuffer,
            line,
            column
        );
        string_free( buffer );
        buffer = string_new();
LABEL_continue:
        if( someLexer->state == LEXER_ERROR )
        {
            break;
        }
        if( c == '\0' || iterator >= someScript->length )
        {
            if( someLexer->state == READ_STRING )
            {
                string_copy_cstr(
                    someLexer->errorMessage,
                    L"Error: while reading string -> unexpected end of file!"
                );
                someLexer->state = LEXER_ERROR;
                break;
            }
            if( buffer->length > 0 )
            {
                if( someLexer->state == READ_SYMBOL )
                {
                    typeBuffer = SYMBOL;
                    goto LABEL_append_token;
                }
                else if( someLexer->state == READ_NUMBER )
                {
                    typeBuffer = NUMBER;
                    goto LABEL_append_token;
                }
            }
            someLexer->state = LEXER_SUCCESS;
            break;
        }
        else
        {
            ++iterator;
        }
    }
    string_free( buffer );
    return someLexer->state == LEXER_SUCCESS;
}

canonical_original_code:
int lexer_scan(struct lexer_t *someLexer, struct string_t *someScript)
{
    unsigned long iterator; unsigned long line; unsigned long column;
    struct string_t *buffer;
    enum token_type typeBuffer;
    int c;
    if( ! someLexer )
    {
        return 0;
    }
    if( someScript->length == 0 )
    {
        someLexer->state = LEXER_SUCCESS;
    }
    iterator = 0;
    line = column = 0;
    buffer = string_new();
    while( 1 )
    {
        c = someScript->data[iterator];
        ++column;
        if( someLexer->state == IDLE )
        {
            if( ((c == L' ') || (c == L'\t') || (c == L'\n')) )
            {
                if( (c == L'\n') )
                {
                    column = 0;
                    ++line;
                }
                goto LABEL_continue;
            }
            if( (c == L';') )
            {
                someLexer->state = READ_COMMENT;
                goto LABEL_continue;
            }
            if( (c >= L'0' && c <= L'9') )
            {
                someLexer->state = READ_NUMBER;
                string_append( buffer, c );
                goto LABEL_continue;
            }
            if( (c == L'(')
             || (c == L')') )
            {
                someLexer->state = IDLE;
                string_append( buffer, c );
                typeBuffer =
                    ((c == L'(')
                        ? LIST_BEGIN
                        : LIST_END);
                goto LABEL_append_token;
            }
            if( (c == L'\'') )
            {
                someLexer->state = IDLE;
                string_append( buffer, c );
                typeBuffer = QUOTE;
                goto LABEL_append_token;
            }
            if( (c >= L'!' && c <= L'~') || (c >= L'¡' && c <= L'ÿ') )
            {
                someLexer->state = READ_SYMBOL;
                string_append( buffer, c );
            }
            goto LABEL_continue;
        }
        if( someLexer->state == READ_COMMENT )
        {
            if( (c == L'\n') )
            {
                someLexer->state = IDLE;
            }
            goto LABEL_continue;
        }
        if( someLexer->state == READ_STRING )
        {
            if( (c == L'"') )
            {
                someLexer->state = IDLE;
                typeBuffer = STRING;
                goto LABEL_append_token;
            }
            string_append( buffer, c );
            goto LABEL_continue;
        }
        if( someLexer->state == READ_SYMBOL )
        {
            static int finalize = 0;
            if( (c == L';') )
            {
                someLexer->state = READ_COMMENT;
                finalize = 1;
            }
            else if( (c == L'"') )
            {
                someLexer->state = READ_STRING;
                finalize = 1;
            }
            else if( ((c == L' ') || (c == L'\t') || (c == L'\n')) )
            {
                someLexer->state = IDLE;
                finalize = 1;
            }
            else if( (c == L'(')
                  || (c == L')') )
            {
                token_list_append(
                    & someLexer->tokenlist,
                    buffer,
                    SYMBOL,
                    line,
                    column
                );
                string_free( buffer );
                buffer = string_new();
                someLexer->state = IDLE;
                string_append( buffer, c );
                typeBuffer =
                    ((c == L'(')
                        ? LIST_BEGIN
                        : LIST_END);
                goto LABEL_append_token;
            }
            else if( (c == L'\'') )
            {
                token_list_append(
                    & someLexer->tokenlist,
                    buffer,
                    NUMBER,
                    line,
                    column
                );
                string_free( buffer );
                buffer = string_new();
                someLexer->state = IDLE;
                string_append( buffer, c );
                typeBuffer = QUOTE;
                goto LABEL_append_token;
            }
            if( finalize )
            {
                finalize = 0;
                typeBuffer = SYMBOL;
                goto LABEL_append_token;
            }
            string_append( buffer, c );
            goto LABEL_continue;
        }
        if( someLexer->state == READ_NUMBER )
        {
            static int finalize = 0;
            static int hadDecimalPoint = 0;
            if( ((c == L' ') || (c == L'\t') || (c == L'\n')) )
            {
                someLexer->state = IDLE;
                finalize = 1;
            }
            else if( (c == L';') )
            {
                someLexer->state = READ_COMMENT;
                finalize = 1;
            }
            else if( (c == L'"') )
            {
                someLexer->state = READ_STRING;
                finalize = 1;
            }
            else if( (c == L'(')
                  || (c == L')') )
            {
                finalize = 0;
                hadDecimalPoint = 0;
                token_list_append(
                    & someLexer->tokenlist,
                    buffer,
                    NUMBER,
                    line,
                    column
                );
                string_free( buffer );
                buffer = string_new();
                someLexer->state = IDLE;
                string_append( buffer, c );
                typeBuffer =
                    ((c == L'(')
                        ? LIST_BEGIN
                        : LIST_END);
                goto LABEL_append_token;
            }
            else if( (c == L'\'') )
            {
                finalize = 0;
                hadDecimalPoint = 0;
                token_list_append(
                    & someLexer->tokenlist,
                    buffer,
                    NUMBER,
                    line,
                    column
                );
                string_free( buffer );
                buffer = string_new();
                someLexer->state = IDLE;
                string_append( buffer, c );
                typeBuffer = QUOTE;
                goto LABEL_append_token;
            }
            else if( (c == L'.') )
            {
                if( hadDecimalPoint )
                {
                    someLexer->state = LEXER_ERROR;
                    string_copy_cstr(
                        someLexer->errorMessage,
                        L"Error: while reading number -> second decimal point!"
                    );
                }
                else
                {
                    hadDecimalPoint = 1;
                    string_append( buffer, c );
                }
                goto LABEL_continue;
            }
            else if( (c >= L'0' && c <= L'9') )
            {
                string_append( buffer, c );
                goto LABEL_continue;
            }
            else if( (c >= L'!' && c <= L'~') || (c >= L'¡' && c <= L'ÿ') )
            {
                someLexer->state = LEXER_ERROR;
                string_copy_cstr(
                    someLexer->errorMessage,
                    L"Error: while reading number -> found symbol!"
                );
                goto LABEL_continue;
            }
            if( finalize )
            {
                finalize = 0;
                hadDecimalPoint = 0;
                someLexer->state = IDLE;
                typeBuffer = NUMBER;
                goto LABEL_append_token;
            }
            goto LABEL_continue;
        }
LABEL_append_token:
        token_list_append(
            & someLexer->tokenlist,
            buffer,
            typeBuffer,
            line,
            column
        );
        string_free( buffer );
        buffer = string_new();
LABEL_continue:
        if( someLexer->state == LEXER_ERROR )
        {
            break;
        }
        if( c == '\0' || iterator >= someScript->length )
        {
            if( someLexer->state == READ_STRING )
            {
                string_copy_cstr(
                    someLexer->errorMessage,
                    L"Error: while reading string -> unexpected end of file!"
                );
                someLexer->state = LEXER_ERROR;
                break;
            }
            if( buffer->length > 0 )
            {
                if( someLexer->state == READ_SYMBOL )
                {
                    typeBuffer = SYMBOL;
                    goto LABEL_append_token;
                }
                else if( someLexer->state == READ_NUMBER )
                {
                    typeBuffer = NUMBER;
                    goto LABEL_append_token;
                }
            }
            someLexer->state = LEXER_SUCCESS;
            break;
        }
        else
        {
            ++iterator;
        }
    }
    string_free( buffer );
    return someLexer->state == LEXER_SUCCESS;
}

variable_types:
someScript
struct string_t *

variable_types:
iterator
unsigned long

variable_types:
line
unsigned long

variable_types:
column
unsigned long

variable_types: struct string_t { int *data; unsigned long length; unsigned long capacity; } *

variable_types: enum token_type { SYMBOL=0, STRING=1, NUMBER=2, LIST_BEGIN=3, LIST_END=4, QUOTE=5 }

variable_types: c int

variable_types: finalize int

variable_types: hadDecimalPoint int

user_defined_types: enum lexer_state { IDLE=0, READ_SYMBOL=1, READ_COMMENT=2, READ_STRING=3, READ_NUMBER=4, LEXER_SUCCESS=5, LEXER_ERROR=6 }


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

if ( a1 )
{
string_free(*(_QWORD *)(a1 + 24));
result = token_list_free(a1);
}
return result;
}

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

if ( a1 )
{
string_free(*(_QWORD *)(a1 + 24));
result = token_list_free(a1);
}
return result;
}

original_code:
void
lexer_free( lexer_t* someLexer )
{
    if( ! someLexer )
    {
        return;
    }
    string_free( someLexer->errorMessage );
    token_list_free( & someLexer->tokenlist );
}

canonical_original_code:
void lexer_free(struct lexer_t *someLexer)
{
    if( ! someLexer )
    {
        return;
    }
    string_free( someLexer->errorMessage );
    token_list_free( & someLexer->tokenlist );
}

return_type: void

user_defined_types: enum token_type { SYMBOL=0, STRING=1, NUMBER=2, LIST_BEGIN=3, LIST_END=4, QUOTE=5 }

user_defined_types: struct string_t { int *data; unsigned long length; unsigned long capacity; }


decompiled_code:
void __fastcall token_list_free(__int64 a1)
{
unsigned __int64 v1; // rbx

if ( a1 && *(_QWORD *)a1 )
{
if ( *(_QWORD *)(a1 + 8) )
{
v1 = 0LL;
do
token_free((_QWORD *)(*(_QWORD *)a1 + 32 * v1++));
while ( *(_QWORD *)(a1 + 8) > v1 );
}
free(*(void **)a1);
*(_QWORD *)a1 = 0LL;
*(_QWORD *)(a1 + 8) = 0LL;
}
}

original_code:
void
token_list_free( token_list_t* someList )
{
    size_t i;
    if( ! someList || ! someList->tokens )
    {
        return;
    }
    for( i = 0; i < someList->size; ++i )
    {
        token_free( & (someList->tokens[i]) );
    }
    free( someList->tokens );
    someList->tokens = ((void *)0);
    someList->size = 0;
}

canonical_original_code:
void token_list_free(struct token_list_t *someList)
{
    unsigned long i;
    if( ! someList || ! someList->tokens )
    {
        return;
    }
    for( i = 0; i < someList->size; ++i )
    {
        token_free( & (someList->tokens[i]) );
    }
    free( someList->tokens );
    someList->tokens = ((void *)0);
    someList->size = 0;
}

variable_types: struct token_list_t { struct token_t { struct string_t { int *data; unsigned long length; unsigned long capacity; } *symbol; enum token_type { SYMBOL=0, STRING=1, NUMBER=2, LIST_BEGIN=3, LIST_END=4, QUOTE=5 } type; unsigned long line; unsigned long column; } *tokens; unsigned long size; } *

variable_types:
i
unsigned long


decompiled_code:
__int64 __fastcall token_list_init(_QWORD *a1)
{
__int64 result; // rax

result = 0LL;
if ( a1 )
{
token_list_free((__int64)a1);
*a1 = 0LL;
a1[1] = 0LL;
result = 1LL;
}
return result;
}

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

result = 0LL;
if ( a1 )
{
func1((__int64)a1);
*a1 = 0LL;
a1[1] = 0LL;
result = 1LL;
}
return result;
}

original_code:
int
token_list_init( token_list_t* someList )
{
    if( ! someList )
    {
        return 0;
    }
    token_list_free( someList );
    someList->tokens = ((void *)0);
    someList->size = 0;
    return 1;
}

canonical_original_code:
int token_list_init(struct token_list_t *someList)
{
    if( ! someList )
    {
        return 0;
    }
    token_list_free( someList );
    someList->tokens = ((void *)0);
    someList->size = 0;
    return 1;
}


original_code:
int
token_list_append(
    token_list_t* someList,
    const string_t* someSymbol,
    token_type someType,
    size_t someLine,
    size_t someColumn )
{
    size_t i;
    token_t* oldOnes;
    token_t t;
    if( ! someList->tokens )
    {
        someList->tokens = calloc(
            1,
            sizeof( token_t )
        );
    }
    else
    {
        oldOnes = someList->tokens;
        someList->tokens = calloc(
            someList->size + 1,
            sizeof( token_t )
        );
        if( ! someList->tokens )
        {
            someList->tokens = oldOnes;
            return 0;
        }
        for( i = 0; i < someList->size; ++i )
        {
            someList->tokens[i].type = oldOnes[i].type;
            someList->tokens[i].line = oldOnes[i].line;
            someList->tokens[i].column = oldOnes[i].column;
            someList->tokens[i].symbol = string_new();
            string_copy( someList->tokens[i].symbol,
                         oldOnes[i].symbol );
            token_free( & oldOnes[i] );
        }
        free( oldOnes );
    }
    someList->tokens[someList->size].symbol = string_new();
    if( someList->tokens[someList->size].symbol == ((void *)0)
     || ! string_copy(
            someList->tokens[someList->size].symbol,
            someSymbol ) )
    {
        return 0;
    }
    someList->tokens[someList->size].type = someType;
    someList->tokens[someList->size].line = someLine;
    someList->tokens[someList->size].column = someColumn;
    ++someList->size;
    return 1;
}

canonical_original_code:
int token_list_append(struct token_list_t *someList, struct string_t *someSymbol, enum token_type someType, unsigned long someLine, unsigned long someColumn)
{
    unsigned long i;
    struct token_t *oldOnes;
    struct token_t t;
    if( ! someList->tokens )
    {
        someList->tokens = calloc(
            1,
            sizeof( token_t )
        );
    }
    else
    {
        oldOnes = someList->tokens;
        someList->tokens = calloc(
            someList->size + 1,
            sizeof( token_t )
        );
        if( ! someList->tokens )
        {
            someList->tokens = oldOnes;
            return 0;
        }
        for( i = 0; i < someList->size; ++i )
        {
            someList->tokens[i].type = oldOnes[i].type;
            someList->tokens[i].line = oldOnes[i].line;
            someList->tokens[i].column = oldOnes[i].column;
            someList->tokens[i].symbol = string_new();
            string_copy( someList->tokens[i].symbol,
                         oldOnes[i].symbol );
            token_free( & oldOnes[i] );
        }
        free( oldOnes );
    }
    someList->tokens[someList->size].symbol = string_new();
    if( someList->tokens[someList->size].symbol == ((void *)0)
     || ! string_copy(
            someList->tokens[someList->size].symbol,
            someSymbol ) )
    {
        return 0;
    }
    someList->tokens[someList->size].type = someType;
    someList->tokens[someList->size].line = someLine;
    someList->tokens[someList->size].column = someColumn;
    ++someList->size;
    return 1;
}

variable_types:
someSymbol
struct string_t *

variable_types:
someLine
unsigned long

variable_types:
someColumn
unsigned long

variable_types: struct token_t { struct string_t { int *data; unsigned long length; unsigned long capacity; } *symbol; enum token_type { SYMBOL=0, STRING=1, NUMBER=2, LIST_BEGIN=3, LIST_END=4, QUOTE=5 } type; unsigned long line; unsigned long column; } *


decompiled_code:
int __fastcall token_list_print(_QWORD *a1)
{
unsigned __int64 v1; // rbx
int result; // eax

if ( a1[1] )
{
v1 = 0LL;
do
{
result = wprintf(U"i: %i v: %ls\n", v1, **(_QWORD **)(*a1 + 32 * v1));
++v1;
}
while ( a1[1] > v1 );
}
return result;
}

canonical_decompiled_code:
int __fastcall func4(_QWORD *a1)
{
unsigned __int64 v1; // rbx
int result; // eax

if ( a1[1] )
{
v1 = 0LL;
do
{
result = wprintf(U"i: %i v: %ls\n", v1, **(_QWORD **)(*a1 + 32 * v1));
++v1;
}
while ( a1[1] > v1 );
}
return result;
}

original_code:
void
token_list_print( const token_list_t* someList )
{
    size_t i, j;
    for( i = 0; i < someList->size; ++i )
    {
        wprintf(
            L"i: %i v: %ls\n",
            i,
            someList->tokens[i].symbol->data
        );
    }
}

canonical_original_code:
void token_list_print(struct token_list_t *someList)
{
    unsigned long i; unsigned long j;
    for( i = 0; i < someList->size; ++i )
    {
        wprintf(
            L"i: %i v: %ls\n",
            i,
            someList->tokens[i].symbol->data
        );
    }
}

variable_types:
j
unsigned long


decompiled_code:
void __fastcall parse_tree_element_free(void *a1)
{
unsigned __int64 v1; // rbp

if ( a1 )
{
*(_DWORD *)a1 = -1;
if ( *((_QWORD *)a1 + 3) )
{
if ( *((_QWORD *)a1 + 4) )
{
v1 = 0LL;
do
parse_tree_element_free(*(_QWORD *)(*((_QWORD *)a1 + 3) + 8 * v1++));
while ( *((_QWORD *)a1 + 4) > v1 );
}
free(*((void **)a1 + 3));
}
free(a1);
}
}

original_code:
void
parse_tree_element_free( parse_tree_element_t* someElement )
{
    size_t i;
    if( someElement == ((void *)0) )
    {
        return;
    }
    someElement->type = -1;
    if( someElement->parameters != ((void *)0) )
    {
        for( i = 0; i < someElement->parameterCount; ++i )
        {
            parse_tree_element_free( someElement->parameters[i] );
        }
        free( someElement->parameters );
        someElement->parameterCount = 0;
    }
    free( someElement );
}

canonical_original_code:
void parse_tree_element_free(struct parse_tree_element_t *someElement)
{
    unsigned long i;
    if( someElement == ((void *)0) )
    {
        return;
    }
    someElement->type = -1;
    if( someElement->parameters != ((void *)0) )
    {
        for( i = 0; i < someElement->parameterCount; ++i )
        {
            parse_tree_element_free( someElement->parameters[i] );
        }
        free( someElement->parameters );
        someElement->parameterCount = 0;
    }
    free( someElement );
}

variable_types: struct parse_tree_element_t { enum expression_type { EXP_LIST=0, EXP_KEYWORD=1, EXP_QUOTED=2, EXP_VARIABLE=3, EXP_STRING=4, EXP_NUMBER=5 } type; union { struct string_t { int *data; unsigned long length; unsigned long capacity; } *str; double num; } value; struct parse_tree_element_t *parent; struct parse_tree_element_t **parameters; unsigned long parameterCount; } *

user_defined_types: struct parse_tree_element_t { enum expression_type type; union { struct string_t *str; double num; } value; struct parse_tree_element_t *parent; struct parse_tree_element_t **parameters; unsigned long parameterCount; }


decompiled_code:
__int64 __fastcall parse_tree_element_add_parameter(__int64 a1, __int64 a2)
{
void *v3; // rdi
_QWORD *v4; // rax
__int64 result; // rax

v3 = *(void **)(a1 + 24);
if ( v3 )
{
v4 = realloc(v3, 8LL * *(_QWORD *)(a1 + 32) + 8);
if ( v4 )
{
LABEL_3:
*(_QWORD *)(a2 + 16) = a1;
*(_QWORD *)(a1 + 24) = v4;
v4[(*(_QWORD *)(a1 + 32))++] = a2;
return 1LL;
}
result = 0LL;
}
else
{
*(_QWORD *)(a1 + 32) = 0LL;
v4 = malloc(8uLL);
if ( v4 )
goto LABEL_3;
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 a2)
{
void *v3; // rdi
_QWORD *v4; // rax
__int64 result; // rax

v3 = *(void **)(a1 + 24);
if ( v3 )
{
v4 = realloc(v3, 8LL * *(_QWORD *)(a1 + 32) + 8);
if ( v4 )
{
LABEL_3:
*(_QWORD *)(a2 + 16) = a1;
*(_QWORD *)(a1 + 24) = v4;
v4[(*(_QWORD *)(a1 + 32))++] = a2;
return 1LL;
}
result = 0LL;
}
else
{
*(_QWORD *)(a1 + 32) = 0LL;
v4 = malloc(8uLL);
if ( v4 )
goto LABEL_3;
result = 0LL;
}
return result;
}

original_code:
int
parse_tree_element_add_parameter( parse_tree_element_t* someElement,
                                  parse_tree_element_t* someParameter )
{
    parse_tree_element_t** buffer = ((void *)0);
    if( someElement->parameters == ((void *)0) )
    {
        someElement->parameterCount = 0;
        buffer = malloc( sizeof( parse_tree_element_t * ) );
        if( buffer == ((void *)0) )
        {
            return 0;
        }
    }
    else
    {
        buffer = realloc(
            someElement->parameters,
            (someElement->parameterCount + 1) * sizeof( parse_tree_element_t * )
        );
        if( buffer == ((void *)0) )
        {
            return 0;
        }
    }
    someParameter->parent = someElement;
    someElement->parameters = buffer;
    someElement->parameters[someElement->parameterCount] = someParameter;
    someElement->parameterCount += 1;
    return 1;
}

canonical_original_code:
int parse_tree_element_add_parameter(struct parse_tree_element_t *someElement, struct parse_tree_element_t *someParameter)
{
    struct parse_tree_element_t **buffer = ((void *)0);
    if( someElement->parameters == ((void *)0) )
    {
        someElement->parameterCount = 0;
        buffer = malloc( sizeof( struct parse_tree_element_t * ) );
        if( buffer == ((void *)0) )
        {
            return 0;
        }
    }
    else
    {
        buffer = realloc(
            someElement->parameters,
            (someElement->parameterCount + 1) * sizeof( struct parse_tree_element_t * )
        );
        if( buffer == ((void *)0) )
        {
            return 0;
        }
    }
    someParameter->parent = someElement;
    someElement->parameters = buffer;
    someElement->parameters[someElement->parameterCount] = someParameter;
    someElement->parameterCount += 1;
    return 1;
}

variable_types:
someParameter
struct parse_tree_element_t *

variable_types: struct parse_tree_element_t { enum expression_type { EXP_LIST=0, EXP_KEYWORD=1, EXP_QUOTED=2, EXP_VARIABLE=3, EXP_STRING=4, EXP_NUMBER=5 } type; union { struct string_t { int *data; unsigned long length; unsigned long capacity; } *str; double num; } value; struct parse_tree_element_t *parent; struct parse_tree_element_t **parameters; unsigned long parameterCount; } **


decompiled_code:
int __fastcall parse_tree_element_print(__int64 a1)
{
unsigned __int64 v1; // rbp
int result; // eax

switch ( *(_DWORD *)a1 )
{
case 0:
fwprintf(stdout, U"list(");
if ( *(_QWORD *)(a1 + 32) )
{
v1 = 0LL;
do
{
parse_tree_element_print(*(_QWORD *)(*(_QWORD *)(a1 + 24) + 8 * v1));
if ( *(_QWORD *)(a1 + 32) - 1LL > v1 )
fwprintf(stdout, U" ");
++v1;
}
while ( *(_QWORD *)(a1 + 32) > v1 );
}
result = fwprintf(stdout, U")");
break;
case 1:
result = fwprintf(stdout, U"keyword(%ls)", **(_QWORD **)(a1 + 8));
break;
case 2:
fwprintf(stdout, U"quote(");
parse_tree_element_print(**(_QWORD **)(a1 + 24));
result = fwprintf(stdout, U")");
break;
case 3:
result = fwprintf(stdout, U"variable(%ls)", **(_QWORD **)(a1 + 8));
break;
case 4:
result = fwprintf(stdout, U"string(%ls)", **(_QWORD **)(a1 + 8));
break;
case 5:
result = fwprintf(stdout, U"number(%f)", *(double *)(a1 + 8));
break;
default:
result = fwprintf(stderr, U"Unkown element type!\n");
break;
}
return result;
}

canonical_decompiled_code:
int __fastcall func2(__int64 a1)
{
unsigned __int64 v1; // rbp
int result; // eax

switch ( *(_DWORD *)a1 )
{
case 0:
fwprintf(stdout, U"list(");
if ( *(_QWORD *)(a1 + 32) )
{
v1 = 0LL;
do
{
func2(*(_QWORD *)(*(_QWORD *)(a1 + 24) + 8 * v1));
if ( *(_QWORD *)(a1 + 32) - 1LL > v1 )
fwprintf(stdout, U" ");
++v1;
}
while ( *(_QWORD *)(a1 + 32) > v1 );
}
result = fwprintf(stdout, U")");
break;
case 1:
result = fwprintf(stdout, U"keyword(%ls)", **(_QWORD **)(a1 + 8));
break;
case 2:
fwprintf(stdout, U"quote(");
func2(**(_QWORD **)(a1 + 24));
result = fwprintf(stdout, U")");
break;
case 3:
result = fwprintf(stdout, U"variable(%ls)", **(_QWORD **)(a1 + 8));
break;
case 4:
result = fwprintf(stdout, U"string(%ls)", **(_QWORD **)(a1 + 8));
break;
case 5:
result = fwprintf(stdout, U"number(%f)", *(double *)(a1 + 8));
break;
default:
result = fwprintf(stderr, U"Unkown element type!\n");
break;
}
return result;
}

original_code:
void
parse_tree_element_print (parse_tree_element_t* element) {
    size_t i;
    switch (element->type) {
        case EXP_LIST:
            fwprintf (stdout, L"list(");
            for (i = 0; i < element->parameterCount; ++i) {
                parse_tree_element_print (element->parameters[i]);
                if (i < (element->parameterCount - 1)) {
                    fwprintf (stdout, L" ");
                }
            }
            fwprintf (stdout, L")");
            break;
        case EXP_KEYWORD:
            fwprintf (stdout, L"keyword(%ls)", element->value.str->data);
            break;
        case EXP_QUOTED:
            fwprintf (stdout, L"quote(");
            parse_tree_element_print (element->parameters[0]);
            fwprintf (stdout, L")");
            break;
        case EXP_VARIABLE:
            fwprintf (stdout, L"variable(%ls)", element->value.str->data);
            break;
        case EXP_STRING:
            fwprintf (stdout, L"string(%ls)", element->value.str->data);
            break;
        case EXP_NUMBER:
            fwprintf (stdout, L"number(%f)", element->value.num);
            break;
        default:
            fwprintf (stderr, L"Unkown element type!\n");
    }
}

canonical_original_code:
void parse_tree_element_print(struct parse_tree_element_t *element) {
    unsigned long i;
    switch (element->type) {
        case EXP_LIST:
            fwprintf (stdout, L"list(");
            for (i = 0; i < element->parameterCount; ++i) {
                parse_tree_element_print (element->parameters[i]);
                if (i < (element->parameterCount - 1)) {
                    fwprintf (stdout, L" ");
                }
            }
            fwprintf (stdout, L")");
            break;
        case EXP_KEYWORD:
            fwprintf (stdout, L"keyword(%ls)", element->value.str->data);
            break;
        case EXP_QUOTED:
            fwprintf (stdout, L"quote(");
            parse_tree_element_print (element->parameters[0]);
            fwprintf (stdout, L")");
            break;
        case EXP_VARIABLE:
            fwprintf (stdout, L"variable(%ls)", element->value.str->data);
            break;
        case EXP_STRING:
            fwprintf (stdout, L"string(%ls)", element->value.str->data);
            break;
        case EXP_NUMBER:
            fwprintf (stdout, L"number(%f)", element->value.num);
            break;
        default:
            fwprintf (stderr, L"Unkown element type!\n");
    }
}

user_defined_types: enum expression_type { EXP_LIST=0, EXP_KEYWORD=1, EXP_QUOTED=2, EXP_VARIABLE=3, EXP_STRING=4, EXP_NUMBER=5 }


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

result = 0LL;
if ( a1 <= 0xA )
result = (__int64)*(&LqKeywordValues + (int)a1);
return result;
}

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

result = 0LL;
if ( a1 <= 0xA )
result = (__int64)*(&LqKeywordValues + (int)a1);
return result;
}

original_code:
const wchar_t*
keywords_get_value( int someKey )
{
    if( someKey >= 0 && someKey < 11 )
    {
        return LqKeywordValues[someKey];
    }
    return ((void *)0);
}

canonical_original_code:
int *keywords_get_value(int someKey)
{
    if( someKey >= 0 && someKey < 11 )
    {
        return LqKeywordValues[someKey];
    }
    return ((void *)0);
}

variable_types: someKey int

return_type: int *


decompiled_code:
__int64 __fastcall keywords_get_key(wchar_t *s2)
{
__int64 v1; // rbx

v1 = 0LL;
while ( wcscmp((const wchar_t *)*(&LqKeywordValues + v1), s2) )
{
if ( ++v1 == 11 )
return 0xFFFFFFFFLL;
}
return (unsigned int)v1;
}

canonical_decompiled_code:
__int64 __fastcall func1(wchar_t *s2)
{
__int64 v1; // rbx

v1 = 0LL;
while ( wcscmp((const wchar_t *)*(&LqKeywordValues + v1), s2) )
{
if ( ++v1 == 11 )
return 0xFFFFFFFFLL;
}
return (unsigned int)v1;
}

original_code:
int
keywords_get_key( const wchar_t* someValue )
{
    size_t i, l;
    int r = -1;
    for( i = 0; i < 11; ++i )
    {
        l = wcslen( LqKeywordValues[i] );
        if( wcscmp( LqKeywordValues[i], someValue ) == 0 )
        {
            r = i;
            break;
        }
    }
    return r;
}

canonical_original_code:
int keywords_get_key(int *someValue)
{
    unsigned long i; unsigned long l;
    int r = -1;
    for( i = 0; i < 11; ++i )
    {
        l = wcslen( LqKeywordValues[i] );
        if( wcscmp( LqKeywordValues[i], someValue ) == 0 )
        {
            r = i;
            break;
        }
    }
    return r;
}

variable_types:
someValue
int *

variable_types:
l
unsigned long

variable_types: r int


decompiled_code:
__int64 __fastcall mmu_read(unsigned __int16 a1)
{
return *(unsigned __int8 *)(MEMORY + a1);
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned __int16 a1)
{
return *(unsigned __int8 *)(MEMORY + a1);
}

original_code:
static uint8_t mmu_read(uint16_t addr) {
    uint16_t val = MEMORY[addr];
    return val;
}

canonical_original_code:
static unsigned char mmu_read(unsigned short addr) {
    unsigned short val = MEMORY[addr];
    return val;
}

variable_types:
addr
unsigned short

variable_types:
val
unsigned short

return_type: unsigned char


decompiled_code:
__int64 __fastcall mmu_write(unsigned __int16 a1, char a2)
{
__int64 result; // rax

result = MEMORY;
*(_BYTE *)(MEMORY + a1) = a2;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned __int16 a1, char a2)
{
__int64 result; // rax

result = MEMORY;
*(_BYTE *)(MEMORY + a1) = a2;
return result;
}

original_code:
static void mmu_write(uint16_t addr, uint8_t val) {
    MEMORY[addr] = val;
}

canonical_original_code:
static void mmu_write(unsigned short addr, unsigned char val) {
    MEMORY[addr] = val;
}

variable_types:
val
unsigned char


dump

canonical_original_code:
static void dump(struct Intel8080 *cpu) {
    unsigned char flags = *cpu->F;
    printf("  (F) %c %c %c %c %c\n",
                (flags & 128) ? 'S' : '-', (flags & 64) ? 'Z' : '-',
                (flags & 16) ? 'A' : '-', (flags & 4) ? 'P' : '-',
                (flags & 1) ? 'C' : '-' );
    printf("  (A)   %03d (PSW) %05d  (OP)  %-5s\n",
           *cpu->A, *cpu->PSW, INTEL_8080_OP_CODE_NAMES[cpu->instruction]);
    printf("  (B)   %03d   (C)   %03d  (BC)  %05d\n",
           *cpu->B, *cpu->C, *cpu->BC);
    printf("  (D)   %03d   (E)   %03d  (DE)  %05d\n",
           *cpu->D, *cpu->E, *cpu->DE);
    printf("  (H)   %03d   (L)   %03d  (HL)  %05d\n",
           *cpu->H, *cpu->L, *cpu->HL);
    printf(" (SP) %05d  (PC) %05d\n", *cpu->SP, *cpu->PC);
    printf("(CYC) %17lu\n\n", cpu->cycle_count);
}

variable_types: struct Intel8080 { unsigned char reg[12]; unsigned char *A; unsigned char *F; unsigned short *PSW; unsigned char *B; unsigned char *C; unsigned short *BC; unsigned char *D; unsigned char *E; unsigned short *DE; unsigned char *H; unsigned char *L; unsigned short *HL; unsigned short *SP; unsigned short *PC; unsigned long cycle_count; unsigned char instruction; unsigned short *stack_top; unsigned char ime; unsigned char halt; unsigned long (*exec)(struct Intel8080 *cpu, unsigned long cycles); void (*reset)(struct Intel8080 *cpu); void (*destroy)(struct Intel8080 **cpu); unsigned char (*read_mem)(unsigned short addr); void (*write_mem)(unsigned short addr, unsigned char val); } *

variable_types:
flags
unsigned char


now

decompiled_code:
unsigned __int64 now()
{
double v0; // xmm0_8
unsigned __int64 result; // rax
struct timeval v2; // [rsp+0h] [rbp-18h] BYREF

gettimeofday(&v2, 0LL);
v0 = (double)SLODWORD(v2.tv_usec) / 1000.0 + (double)(1000 * LODWORD(v2.tv_sec)) + 0.5;
if ( v0 >= 9.223372036854776e18 )
result = (unsigned int)(int)(v0 - 9.223372036854776e18) ^ 0x8000000000000000LL;
else
result = (unsigned int)(int)v0;
return result;
}

canonical_decompiled_code:
unsigned __int64 func3()
{
double v0; // xmm0_8
unsigned __int64 result; // rax
struct timeval v2; // [rsp+0h] [rbp-18h] BYREF

gettimeofday(&v2, 0LL);
v0 = (double)SLODWORD(v2.tv_usec) / 1000.0 + (double)(1000 * LODWORD(v2.tv_sec)) + 0.5;
if ( v0 >= 9.223372036854776e18 )
result = (unsigned int)(int)(v0 - 9.223372036854776e18) ^ 0x8000000000000000LL;
else
result = (unsigned int)(int)v0;
return result;
}

original_code:
static unsigned long now() {
    struct timeval t;
    gettimeofday(&t, ((void *)0));
    return ((t.tv_sec) * 1000 + t.tv_usec / 1000.0) + 0.5;
}

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

return_type: unsigned long


emulate

decompiled_code:
void __noreturn emulate()
{
__int64 v0; // r13
unsigned __int64 v1; // rbp
int v2; // er14
__int64 i; // r12
double v4; // xmm0_8
unsigned __int64 v5; // rbx
int v6; // ebx
__int16 v7[21]; // [rsp+Eh] [rbp-2Ah] BYREF

v7[0] = -1;
v0 = cpu_create(mmu_read, mmu_write, v7);
v1 = now();
v2 = 0;
for ( i = 0LL; ; i = 0LL )
{
do
{
v5 = now() - v1;
v1 = now();
i += (*(__int64 (__fastcall **)(__int64, unsigned __int64))(v0 + 160))(v0, 2000 * v5);
usleep(0x2710u);
v6 = v2 + v5;
v2 = v6;
}
while ( v6 <= 999 );
if ( i < 0 )
v4 = (double)(int)(i & 1 | ((unsigned __int64)i >> 1)) + (double)(int)(i & 1 | ((unsigned __int64)i >> 1));
else
v4 = (double)(int)i;
printf("Clocking at %.2f Mhz\n\n", v4 / 1000000.0);
dump(v0);
v2 = v6 - 1000;
}
}

original_code:
static void emulate() {
    uint16_t top = 65535;
    Intel8080 *cpu = cpu_create(&mmu_read, &mmu_write, &top);
    unsigned int clock = 2;
    unsigned long last = now(), cycles = 0;
    int second = 0;
    for(;;) {
        unsigned long taken = now() - last;
        last = now();
        cycles += cpu->exec(cpu, clock * 1000 * taken);
        usleep(10000);
        second += taken;
        if (second >= 1000) {
            printf("Clocking at %.2f Mhz\n\n", (double)cycles / 1000000);
            dump(cpu);
            cycles = 0;
            second -= 1000;
        }
    }
    cpu->destroy(&cpu);
}

canonical_original_code:
static void emulate() {
    unsigned short top = 65535;
    struct Intel8080 *cpu = cpu_create(&mmu_read, &mmu_write, &top);
    unsigned int clock = 2;
    unsigned long last = now(); unsigned long cycles = 0;
    int second = 0;
    for(;;) {
        unsigned long taken = now() - last;
        last = now();
        cycles += cpu->exec(cpu, clock * 1000 * taken);
        usleep(10000);
        second += taken;
        if (second >= 1000) {
            printf("Clocking at %.2f Mhz\n\n", (double)cycles / 1000000);
            dump(cpu);
            cycles = 0;
            second -= 1000;
        }
    }
    cpu->destroy(&cpu);
}

variable_types:
top
unsigned short

variable_types:
clock
unsigned int

variable_types:
last
unsigned long

variable_types:
cycles
unsigned long

variable_types: second int

variable_types:
taken
unsigned long

user_defined_types: struct Intel8080 { unsigned char reg[12]; unsigned char *A; unsigned char *F; unsigned short *PSW; unsigned char *B; unsigned char *C; unsigned short *BC; unsigned char *D; unsigned char *E; unsigned short *DE; unsigned char *H; unsigned char *L; unsigned short *HL; unsigned short *SP; unsigned short *PC; unsigned long cycle_count; unsigned char instruction; unsigned short *stack_top; unsigned char ime; unsigned char halt; unsigned long (*exec)(struct Intel8080 *cpu, unsigned long cycles); void (*reset)(struct Intel8080 *cpu); void (*destroy)(struct Intel8080 **cpu); unsigned char (*read_mem)(unsigned short addr); void (*write_mem)(unsigned short addr, unsigned char val); }


main

canonical_name: main

original_code:
int main() {
    MEMORY = calloc(65536, sizeof(uint8_t));
    uint8_t TEST[65536] = {
        CALL, 100, 0,
        JMP, 0, 0,
        HLT,
        NOP,
    };
    uint8_t LOOP[25] = {
        MVI_A, 128,
        CPI, 0,
        JZ, 111, 0,
        DCR_A,
        JMP, 102, 0,
        INR_B,
        RET
    };
    memcpy(MEMORY, TEST, sizeof(TEST));
    memcpy(MEMORY + 100, LOOP, sizeof(LOOP));
    emulate();
    free(MEMORY);
    return 0;
}

canonical_original_code:
int main() {
    MEMORY = calloc(65536, sizeof(unsigned char));
    unsigned char TEST[65536] = {
        CALL, 100, 0,
        JMP, 0, 0,
        HLT,
        NOP,
    };
    unsigned char LOOP[25] = {
        MVI_A, 128,
        CPI, 0,
        JZ, 111, 0,
        DCR_A,
        JMP, 102, 0,
        INR_B,
        RET
    };
    memcpy(MEMORY, TEST, sizeof(TEST));
    memcpy(MEMORY + 100, LOOP, sizeof(LOOP));
    emulate();
    free(MEMORY);
    return 0;
}

variable_types:
TEST
unsigned char [65536]

variable_types:
LOOP
unsigned char [25]


repo: Boregard/FBoot-Linux

decompiled_code:
__int64 __fastcall get_baudid(void *a1)
{
__int64 v1; // rax

v1 = 0LL;
while ( *(&baudrates + 2 * v1) != a1 )
{
if ( ++v1 == 18 )
return 0LL;
}
return (unsigned int)dword_668[4 * (int)v1];
}

canonical_decompiled_code:
__int64 __fastcall func0(void *a1)
{
__int64 v1; // rax

v1 = 0LL;
while ( *(&baudrates + 2 * v1) != a1 )
{
if ( ++v1 == 18 )
return 0LL;
}
return (unsigned int)dword_668[4 * (int)v1];
}

original_code:
speed_t get_baudid (unsigned long baud)
{
    int i;
    speed_t baudid = 0000000;
    for(i = 0; i < (sizeof (baudrates) / sizeof (baudInfo_t)); i++)
    {
        if (baudrates[i].value == baud)
        {
            baudid = baudrates[i].constval;
            break;
        }
    }
    return (baudid);
}

canonical_original_code:
unsigned int get_baudid(unsigned long baud)
{
    int i;
    unsigned int baudid = 0000000;
    for(i = 0; i < (sizeof (baudrates) / sizeof (baudInfo_t)); i++)
    {
        if (baudrates[i].value == baud)
        {
            baudid = baudrates[i].constval;
            break;
        }
    }
    return (baudid);
}

variable_types:
baud
unsigned long

variable_types: i int

variable_types:
baudid
unsigned int

return_type: unsigned int


decompiled_code:
unsigned __int64 __fastcall get_bytetime(int a1)
{
__int64 v1; // rax

v1 = 0LL;
while ( dword_668[4 * v1] != a1 )
{
if ( ++v1 == 18 )
return 0LL;
}
return 0x989680 / (unsigned __int64)*(&baudrates + 2 * (int)v1) + 1;
}

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

v1 = 0LL;
while ( dword_668[4 * v1] != a1 )
{
if ( ++v1 == 18 )
return 0LL;
}
return 0x989680 / (unsigned __int64)*(&baudrates + 2 * (int)v1) + 1;
}

original_code:
long get_bytetime (speed_t baudid)
{
    int i;
    long btime = 0;
    for(i = 0; i < (sizeof (baudrates) / sizeof (baudInfo_t)); i++)
    {
        if (baudrates[i].constval == baudid)
        {
            btime = (1000000L * 10L / baudrates[i].value) + 1;
            break;
        }
    }
    return (btime);
}

canonical_original_code:
long get_bytetime(unsigned int baudid)
{
    int i;
    long btime = 0;
    for(i = 0; i < (sizeof (baudrates) / sizeof (baudInfo_t)); i++)
    {
        if (baudrates[i].constval == baudid)
        {
            btime = (1000000L * 10L / baudrates[i].value) + 1;
            break;
        }
    }
    return (btime);
}

variable_types: btime long

return_type: long


decompiled_code:
void com_localecho()
{
sendCount = 1;
}

canonical_decompiled_code:
void func2()
{
sendCount = 1;
}

original_code:
void com_localecho ()
{
    sendCount = 1;
}

canonical_original_code:
void com_localecho()
{
    sendCount = 1;
}


decompiled_code:
_BOOL8 __fastcall get_device_status(int a1)
{
_BOOL8 result; // rax
struct termios v2; // [rsp-48h] [rbp-48h] BYREF

result = 0LL;
if ( a1 >= 0 )
result = tcgetattr(a1, &v2) == 0;
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func3(int a1)
{
_BOOL8 result; // rax
struct termios v2; // [rsp-48h] [rbp-48h] BYREF

result = 0LL;
if ( a1 >= 0 )
result = tcgetattr(a1, &v2) == 0;
return result;
}

original_code:
int get_device_status(int fd)
{
    struct termios t;
    if (fd < 0)
        return 0;
    return !tcgetattr(fd, &t);
}

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 com_open(const char *a1, speed_t a2, int a3)
{
int v4; // eax
unsigned int v5; // ebx
struct termios v7; // [rsp+0h] [rbp-58h] BYREF

v4 = open(a1, 2306);
v5 = v4;
if ( v4 >= 0 )
{
tcgetattr(v4, &oldtio);
*(_QWORD *)&v7.c_iflag = 5LL;
*(_QWORD *)&v7.c_cflag = 2224LL;
*(_QWORD *)&v7.c_line = 0LL;
*(_QWORD *)&v7.c_cc[7] = 0LL;
*(_QWORD *)&v7.c_cc[15] = 0LL;
*(_QWORD *)&v7.c_cc[23] = 0LL;
*(_QWORD *)&v7.c_cc[31] = 0LL;
v7.c_ospeed = 0;
cfmakeraw(&v7);
*(_WORD *)&v7.c_cc[5] = 0;
cfsetispeed(&v7, a2);
cfsetospeed(&v7, a2);
tcflush(v5, 2);
tcsetattr(v5, 0, &v7);
sendCount = 0;
if ( a3 )
bytetime = get_bytetime(a2) * a3;
else
bytetime = 0LL;
}
return v5;
}

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

v4 = open(a1, 2306);
v5 = v4;
if ( v4 >= 0 )
{
tcgetattr(v4, &oldtio);
*(_QWORD *)&v7.c_iflag = 5LL;
*(_QWORD *)&v7.c_cflag = 2224LL;
*(_QWORD *)&v7.c_line = 0LL;
*(_QWORD *)&v7.c_cc[7] = 0LL;
*(_QWORD *)&v7.c_cc[15] = 0LL;
*(_QWORD *)&v7.c_cc[23] = 0LL;
*(_QWORD *)&v7.c_cc[31] = 0LL;
v7.c_ospeed = 0;
cfmakeraw(&v7);
*(_WORD *)&v7.c_cc[5] = 0;
cfsetispeed(&v7, a2);
cfsetospeed(&v7, a2);
tcflush(v5, 2);
tcsetattr(v5, 0, &v7);
sendCount = 0;
if ( a3 )
bytetime = func1(a2) * a3;
else
bytetime = 0LL;
}
return v5;
}

original_code:
int com_open (const char * device, speed_t baud, int wait_bytetime)
{
    struct termios newtio;
    int fd;
    fd = open(device, 02 | 0400 | 04000);
    if (fd < 0)
    {
        return fd;
    }
    tcgetattr(fd, &oldtio);
    memset(&newtio, 0x00 , sizeof(newtio));
    newtio.c_cflag = 0000060 | 0004000 | 0000200;
    newtio.c_iflag = 0000004 | 0000001;
    newtio.c_oflag = 0;
    newtio.c_lflag = 0;
    cfmakeraw(&newtio);
    newtio.c_cc[5] = 0;
    newtio.c_cc[6] = 0;
    cfsetispeed(&newtio, baud);
    cfsetospeed(&newtio, baud);
    tcflush(fd, 2);
    tcsetattr(fd, 0, &newtio);
    sendCount = 0;
    if (wait_bytetime)
    {
        bytetime = get_bytetime (baud) * wait_bytetime;
    }
    else
    {
        bytetime = 0;
    }
    return fd;
}

canonical_original_code:
int com_open(char *device, unsigned int baud, int wait_bytetime)
{
    struct termios newtio;
    int fd;
    fd = open(device, 02 | 0400 | 04000);
    if (fd < 0)
    {
        return fd;
    }
    tcgetattr(fd, &oldtio);
    memset(&newtio, 0x00 , sizeof(newtio));
    newtio.c_cflag = 0000060 | 0004000 | 0000200;
    newtio.c_iflag = 0000004 | 0000001;
    newtio.c_oflag = 0;
    newtio.c_lflag = 0;
    cfmakeraw(&newtio);
    newtio.c_cc[5] = 0;
    newtio.c_cc[6] = 0;
    cfsetispeed(&newtio, baud);
    cfsetospeed(&newtio, baud);
    tcflush(fd, 2);
    tcsetattr(fd, 0, &newtio);
    sendCount = 0;
    if (wait_bytetime)
    {
        bytetime = get_bytetime (baud) * wait_bytetime;
    }
    else
    {
        bytetime = 0;
    }
    return fd;
}

variable_types:
device
char *

variable_types:
baud
unsigned int

user_defined_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:
void __fastcall com_set_dtr(int fd, char a2)
{
int v2; // eax
int v3[7]; // [rsp+Ch] [rbp-1Ch] BYREF

if ( ioctl(fd, 0x5415uLL, v3) < 0 )
{
perror("ERROR: could not reset, getting V24 line status failed");
}
else
{
if ( a2 )
v2 = v3[0] | 2;
else
v2 = v3[0] & 0xFFFFFFFD;
v3[0] = v2;
if ( ioctl(fd, 0x5418uLL, v3) < 0 )
perror("ERROR: could not reset, setting V24 line status failed");
}
}

canonical_decompiled_code:
void __fastcall func5(int fd, char a2)
{
int v2; // eax
int v3[7]; // [rsp+Ch] [rbp-1Ch] BYREF

if ( ioctl(fd, 0x5415uLL, v3) < 0 )
{
perror("ERROR: could not reset, getting V24 line status failed");
}
else
{
if ( a2 )
v2 = v3[0] | 2;
else
v2 = v3[0] & 0xFFFFFFFD;
v3[0] = v2;
if ( ioctl(fd, 0x5418uLL, v3) < 0 )
perror("ERROR: could not reset, setting V24 line status failed");
}
}

original_code:
void com_set_dtr(int fd, unsigned char on)
{
    int flags;
    if (ioctl (fd, 0x5415, &flags) < 0)
    {
        perror ("ERROR: could not reset, getting V24 line status failed");
        return;
    }
    if (on)
    {
        flags |= 0x002;
    }
    else
    {
        flags &= ~0x002;
    }
    if (ioctl (fd, 0x5418, &flags) < 0)
    {
        perror ("ERROR: could not reset, setting V24 line status failed");
    }
}

variable_types:
on
unsigned char

variable_types: flags int


decompiled_code:
void __fastcall com_toggle_dtr(int fd)
{
int v1; // eax
int v2[3]; // [rsp+Ch] [rbp-Ch] BYREF

if ( ioctl(fd, 0x5415uLL, v2) < 0 )
{
perror("ERROR: could not reset, getting V24 line status failed");
}
else
{
v1 = v2[0] | 2;
if ( (v2[0] & 2) != 0 )
v1 = v2[0] & 0xFFFFFFFD;
v2[0] = v1;
if ( ioctl(fd, 0x5418uLL, v2) < 0 )
perror("ERROR: could not reset, setting V24 line status failed");
}
}

canonical_decompiled_code:
void __fastcall func6(int fd)
{
int v1; // eax
int v2[3]; // [rsp+Ch] [rbp-Ch] BYREF

if ( ioctl(fd, 0x5415uLL, v2) < 0 )
{
perror("ERROR: could not reset, getting V24 line status failed");
}
else
{
v1 = v2[0] | 2;
if ( (v2[0] & 2) != 0 )
v1 = v2[0] & 0xFFFFFFFD;
v2[0] = v1;
if ( ioctl(fd, 0x5418uLL, v2) < 0 )
perror("ERROR: could not reset, setting V24 line status failed");
}
}

original_code:
void com_toggle_dtr(int fd)
{
    int flags;
    if (ioctl (fd, 0x5415, &flags) < 0)
    {
        perror ("ERROR: could not reset, getting V24 line status failed");
        return;
    }
    if (flags & 0x002)
    {
        flags &= ~0x002;
    }
    else
    {
        flags |= 0x002;
    }
    if (ioctl (fd, 0x5418, &flags) < 0)
    {
        perror ("ERROR: could not reset, setting V24 line status failed");
    }
}


decompiled_code:
int __fastcall com_drain(int fd)
{
int *v1; // rax

if ( bytetime )
{
LODWORD(v1) = usleep(waitcount * bytetime);
waitcount = 0;
}
else
{
do
{
LODWORD(v1) = tcdrain(fd);
if ( (int)v1 >= 0 )
break;
v1 = _errno_location();
}
while ( *v1 == 4 );
}
return (int)v1;
}

canonical_decompiled_code:
int __fastcall func7(int fd)
{
int *v1; // rax

if ( bytetime )
{
LODWORD(v1) = usleep(waitcount * bytetime);
waitcount = 0;
}
else
{
do
{
LODWORD(v1) = tcdrain(fd);
if ( (int)v1 >= 0 )
break;
v1 = _errno_location();
}
while ( *v1 == 4 );
}
return (int)v1;
}

original_code:
void com_drain (int fd)
{
    if (bytetime)
    {
        usleep (bytetime * waitcount);
        waitcount = 0;
    }
    else
    {
        while ((tcdrain(fd) < 0) && ((*__errno_location ()) == 4));
    }
}

canonical_original_code:
void com_drain(int fd)
{
    if (bytetime)
    {
        usleep (bytetime * waitcount);
        waitcount = 0;
    }
    else
    {
        while ((tcdrain(fd) < 0) && ((*__errno_location ()) == 4));
    }
}


decompiled_code:
int __fastcall com_close(int fd)
{
com_drain(fd);
tcsetattr(fd, 0, &oldtio);
return close(fd);
}

canonical_decompiled_code:
int __fastcall func8(int fd)
{
func7(fd);
tcsetattr(fd, 0, &oldtio);
return close(fd);
}

original_code:
void com_close(int fd)
{
    com_drain(fd);
    tcsetattr(fd, 0, &oldtio);
    close(fd);
}


decompiled_code:
__int64 __fastcall com_getc(int fd, int a2)
{
clock_t v2; // rbp
char buf[25]; // [rsp+Fh] [rbp-19h] BYREF

v2 = times(&theTimes_1);
if ( !ticks_0 )
ticks_0 = sysconf(2) / 10;
while ( get_device_status(fd) )
{
if ( read(fd, buf, 1uLL) == 1 )
{
if ( sendCount <= 1 )
return (unsigned __int8)buf[0];
--sendCount;
v2 = times(&theTimes_1);
}
if ( (times(&theTimes_1) - v2) / ticks_0 >= a2 )
return 0xFFFFFFFFLL;
}
return 4294967294LL;
}

canonical_decompiled_code:
__int64 __fastcall func9(int fd, int a2)
{
clock_t v2; // rbp
char buf[25]; // [rsp+Fh] [rbp-19h] BYREF

v2 = times(&theTimes_1);
if ( !ticks_0 )
ticks_0 = sysconf(2) / 10;
while ( func3(fd) )
{
if ( read(fd, buf, 1uLL) == 1 )
{
if ( sendCount <= 1 )
return (unsigned __int8)buf[0];
--sendCount;
v2 = times(&theTimes_1);
}
if ( (times(&theTimes_1) - v2) / ticks_0 >= a2 )
return 0xFFFFFFFFLL;
}
return 4294967294LL;
}

original_code:
int com_getc(int fd,
             int timeout)
{
    static long ticks = 0;
    static struct tms theTimes;
    char c;
    clock_t t = times (&theTimes);
    if (ticks == 0)
        ticks = sysconf(_SC_CLK_TCK) / 10;
    do
    {
        if (!get_device_status(fd))
        {
            return -2;
        }
        if (read(fd, &c, 1) == 1)
        {
            if (sendCount > 1)
            {
                sendCount--;
                t = times (&theTimes);
                continue;
            }
            return (unsigned char)c;
        }
    } while ( ((times (&theTimes) - t )/ticks) < timeout );
    return -1;
}

canonical_original_code:
int com_getc(int fd, int timeout)
{
    static long ticks = 0;
    static struct tms theTimes;
    char c;
    long t = times (&theTimes);
    if (ticks == 0)
        ticks = sysconf(_SC_CLK_TCK) / 10;
    do
    {
        if (!get_device_status(fd))
        {
            return -2;
        }
        if (read(fd, &c, 1) == 1)
        {
            if (sendCount > 1)
            {
                sendCount--;
                t = times (&theTimes);
                continue;
            }
            return (unsigned char)c;
        }
    } while ( ((times (&theTimes) - t )/ticks) < timeout );
    return -1;
}

variable_types: timeout int

variable_types: ticks long

variable_types: struct tms { long tms_utime; long tms_stime; long tms_cutime; long tms_cstime; }

variable_types: c char

variable_types: t long


decompiled_code:
__int64 __fastcall com_read(int fd, void *buf, size_t nbytes)
{
int v4; // er13

while ( get_device_status(fd) )
{
v4 = read(fd, buf, nbytes);
if ( v4 >= 0 || *_errno_location() != 4 )
return (unsigned int)v4;
}
puts("\nDevice disconnected!");
return (unsigned int)-1;
}

canonical_decompiled_code:
__int64 __fastcall func10(int fd, void *buf, size_t nbytes)
{
int v4; // er13

while ( func3(fd) )
{
v4 = read(fd, buf, nbytes);
if ( v4 >= 0 || *_errno_location() != 4 )
return (unsigned int)v4;
}
puts("\nDevice disconnected!");
return (unsigned int)-1;
}

original_code:
int com_read (int fd,
              char *pszIn,
              size_t tLen)
{
    int iNrRead;
    do {
        if (!get_device_status(fd))
        {
            printf ("\nDevice disconnected!\n");
            return -1;
        }
        iNrRead = read (fd, pszIn, tLen);
    } while ((iNrRead < 0) && ((*__errno_location ()) == 4));
    return (iNrRead);
}

canonical_original_code:
int com_read(int fd, char *pszIn, unsigned long tLen)
{
    int iNrRead;
    do {
        if (!get_device_status(fd))
        {
            printf ("\nDevice disconnected!\n");
            return -1;
        }
        iNrRead = read (fd, pszIn, tLen);
    } while ((iNrRead < 0) && ((*__errno_location ()) == 4));
    return (iNrRead);
}

variable_types:
pszIn
char *

variable_types:
tLen
unsigned long

variable_types: iNrRead int


decompiled_code:
__int64 __fastcall calc_crc(unsigned __int8 a1)
{
unsigned int v1; // edi
__int64 result; // rax
unsigned int v3; // edx
int v4; // edi

v1 = crc ^ a1;
LODWORD(result) = 8;
do
{
v3 = v1 >> 1;
v4 = v1 & 1;
if ( v4 )
v4 = 40961;
v1 = v3 ^ v4;
result = (unsigned int)(result - 1);
}
while ( (_DWORD)result );
crc = v1;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func11(unsigned __int8 a1)
{
unsigned int v1; // edi
__int64 result; // rax
unsigned int v3; // edx
int v4; // edi

v1 = crc ^ a1;
LODWORD(result) = 8;
do
{
v3 = v1 >> 1;
v4 = v1 & 1;
if ( v4 )
v4 = 40961;
v1 = v3 ^ v4;
result = (unsigned int)(result - 1);
}
while ( (_DWORD)result );
crc = v1;
return result;
}

original_code:
void calc_crc(unsigned char d)
{
    int i;
    crc ^= d;
    for( i = 8; i; i-- )
    {
        crc = (crc >> 1) ^ ((crc & 1) ? 0xA001 : 0 );
    }
}

variable_types:
d
unsigned char

variable_types: i int


decompiled_code:
__int64 __fastcall com_putc_fast(int fd, unsigned __int8 a2)
{
unsigned __int8 buf[12]; // [rsp+Ch] [rbp-Ch] BYREF

buf[0] = a2;
if ( sendCount )
{
if ( sendCount > 1 )
com_getc(fd, 0);
++sendCount;
}
++waitcount;
while ( write(fd, buf, 1uLL) < 0 && *_errno_location() == 4 )
;
return calc_crc(buf[0]);
}

canonical_decompiled_code:
__int64 __fastcall func12(int fd, unsigned __int8 a2)
{
unsigned __int8 buf[12]; // [rsp+Ch] [rbp-Ch] BYREF

buf[0] = a2;
if ( sendCount )
{
if ( sendCount > 1 )
func9(fd, 0);
++sendCount;
}
++waitcount;
while ( write(fd, buf, 1uLL) < 0 && *_errno_location() == 4 )
;
return func11(buf[0]);
}

original_code:
void com_putc_fast(int fd,
                   unsigned char c)
{
    if (sendCount)
    {
        if (sendCount > 1)
            com_getc(fd, 0);
        sendCount++;
    }
    waitcount++;
    while ((write(fd, &c, 1) < 0) && ((*__errno_location ()) == 4));
    calc_crc( c );
}

variable_types:
c
unsigned char


decompiled_code:
__int64 __fastcall com_putc(int fd, unsigned __int8 a2)
{
com_drain(fd);
return com_putc_fast(fd, a2);
}

canonical_decompiled_code:
__int64 __fastcall func13(int fd, unsigned __int8 a2)
{
func7(fd);
return func12(fd, a2);
}

original_code:
void com_putc(int fd, unsigned char c)
{
    com_drain(fd);
    com_putc_fast (fd, c);
}

variable_types: fd int


sendcommand

decompiled_code:
int __fastcall sendcommand(int fd, unsigned __int8 a2)
{
sendCount = sendCount != 0;
com_putc(fd, 0xA5u);
com_putc(fd, a2);
return com_drain(fd);
}

canonical_decompiled_code:
int __fastcall func14(int fd, unsigned __int8 a2)
{
sendCount = sendCount != 0;
func13(fd, 0xA5u);
func13(fd, a2);
return func7(fd);
}

original_code:
void sendcommand(int fd, unsigned char c)
{
    if (sendCount)
        sendCount = 1;
    com_putc(fd, 0xA5);
    com_putc(fd, c);
    com_drain(fd);
}


decompiled_code:
char *__fastcall sba_crsm_alloc(__int64 a1, unsigned int a2, unsigned int a3, unsigned int a4)
{
char *v6; // rax
__int64 v7; // rdx
char *v8; // rax
char *result; // rax

*(_DWORD *)a1 = a2;
*(_DWORD *)(a1 + 4) = a3;
*(_DWORD *)(a1 + 8) = a4;
v6 = (char *)malloc(4LL * (int)(a2 + 2 * a4 + 1));
*(_QWORD *)(a1 + 16) = v6;
if ( !v6 )
{
fprintf(stderr, "SBA: memory allocation request failed in sba_crsm_alloc() [nr=%d, nc=%d, nnz=%d]\n", a2, a3, a4);
exit(1);
}
v7 = 4LL * (int)a4;
v8 = &v6[v7];
*(_QWORD *)(a1 + 24) = v8;
result = &v8[v7];
*(_QWORD *)(a1 + 32) = result;
return result;
}

canonical_decompiled_code:
char *__fastcall func0(__int64 a1, unsigned int a2, unsigned int a3, unsigned int a4)
{
char *v6; // rax
__int64 v7; // rdx
char *v8; // rax
char *result; // rax

*(_DWORD *)a1 = a2;
*(_DWORD *)(a1 + 4) = a3;
*(_DWORD *)(a1 + 8) = a4;
v6 = (char *)malloc(4LL * (int)(a2 + 2 * a4 + 1));
*(_QWORD *)(a1 + 16) = v6;
if ( !v6 )
{
fprintf(stderr, "SBA: memory allocation request failed in sba_crsm_alloc() [nr=%d, nc=%d, nnz=%d]\n", a2, a3, a4);
exit(1);
}
v7 = 4LL * (int)a4;
v8 = &v6[v7];
*(_QWORD *)(a1 + 24) = v8;
result = &v8[v7];
*(_QWORD *)(a1 + 32) = result;
return result;
}

original_code:
void sba_crsm_alloc(struct sba_crsm *sm, int nr, int nc, int nnz)
{
int msz;
  sm->nr=nr;
  sm->nc=nc;
  sm->nnz=nnz;
  msz=2*nnz+nr+1;
  sm->val=(int *)malloc(msz*sizeof(int));
  if(!sm->val){
    fprintf(stderr, "SBA: memory allocation request failed in sba_crsm_alloc() [nr=%d, nc=%d, nnz=%d]\n", nr, nc, nnz);
    exit(1);
  }
  sm->colidx=sm->val+nnz;
  sm->rowptr=sm->colidx+nnz;
}

variable_types: struct sba_crsm { int nr; int nnz; int *val; int *colidx; int *rowptr; } *

variable_types: nr int

variable_types: nc int

variable_types: nnz int

variable_types: msz int


original_code:
void sba_crsm_free(struct sba_crsm *sm)
{
  sm->nr=sm->nc=sm->nnz=-1;
  free(sm->val);
  sm->val=sm->colidx=sm->rowptr=((void *)0);
}

user_defined_types: struct sba_crsm { int nr; int nnz; int *val; int *colidx; int *rowptr; }


decompiled_code:
__int64 __fastcall sba_crsm_elmidx(__int64 a1, int a2, int a3)
{
__int64 v5; // rdx
__int64 v6; // rax
int v7; // esi
int v8; // ecx
__int64 v9; // r10
__int64 result; // rax

v5 = *(_QWORD *)(a1 + 32);
v6 = a2;
v7 = *(_DWORD *)(v5 + 4LL * a2);
v8 = *(_DWORD *)(v5 + 4 * v6 + 4) - 1;
if ( v7 > v8 )
return 0xFFFFFFFFLL;
v9 = *(_QWORD *)(a1 + 24);
do
{
result = (unsigned int)((v7 + v8) >> 1);
if ( a3 - *(_DWORD *)(v9 + 4LL * (int)result) < 0 )
{
v8 = result - 1;
}
else
{
if ( a3 - *(_DWORD *)(v9 + 4LL * (int)result) <= 0 )
return result;
v7 = result + 1;
}
}
while ( v7 <= v8 );
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, int a2, int a3)
{
__int64 v5; // rdx
__int64 v6; // rax
int v7; // esi
int v8; // ecx
__int64 v9; // r10
__int64 result; // rax

v5 = *(_QWORD *)(a1 + 32);
v6 = a2;
v7 = *(_DWORD *)(v5 + 4LL * a2);
v8 = *(_DWORD *)(v5 + 4 * v6 + 4) - 1;
if ( v7 > v8 )
return 0xFFFFFFFFLL;
v9 = *(_QWORD *)(a1 + 24);
do
{
result = (unsigned int)((v7 + v8) >> 1);
if ( a3 - *(_DWORD *)(v9 + 4LL * (int)result) < 0 )
{
v8 = result - 1;
}
else
{
if ( a3 - *(_DWORD *)(v9 + 4LL * (int)result) <= 0 )
return result;
v7 = result + 1;
}
}
while ( v7 <= v8 );
return 0xFFFFFFFFLL;
}

original_code:
int sba_crsm_elmidx(struct sba_crsm *sm, int i, int j)
{
register int low, high, mid, diff;
  low=sm->rowptr[i];
  high=sm->rowptr[i+1]-1;
  while(low<=high){
    mid=(low+high)>>1;
    diff=j-sm->colidx[mid];
    if(diff<0)
      high=mid-1;
    else if(diff>0)
      low=mid+1;
    else
      return mid;
  }
  return -1;
}

canonical_original_code:
int sba_crsm_elmidx(struct sba_crsm *sm, int i, int j)
{
register int low; register int high; register int mid; register int diff;
  low=sm->rowptr[i];
  high=sm->rowptr[i+1]-1;
  while(low<=high){
    mid=(low+high)>>1;
    diff=j-sm->colidx[mid];
    if(diff<0)
      high=mid-1;
    else if(diff>0)
      low=mid+1;
    else
      return mid;
  }
  return -1;
}

variable_types: j int

variable_types: low int

variable_types: high int

variable_types: mid int

variable_types: diff int


decompiled_code:
__int64 __fastcall sba_crsm_elmidxp(__int64 a1, int a2, int a3, int a4, unsigned int a5)
{
int v8; // edx
int v9; // esi
int v10; // er9
__int64 v11; // r10
__int64 result; // rax

v8 = a3 - a4;
if ( v8 <= 0 )
{
result = a5;
if ( !v8 )
return result;
v9 = *(_DWORD *)(*(_QWORD *)(a1 + 32) + 4LL * a2);
v10 = a5 - 1;
}
else
{
v9 = a5 + 1;
v10 = *(_DWORD *)(*(_QWORD *)(a1 + 32) + 4LL * a2 + 4) - 1;
}
if ( v9 > v10 )
return 0xFFFFFFFFLL;
v11 = *(_QWORD *)(a1 + 24);
do
{
result = (unsigned int)((v9 + v10) >> 1);
if ( a3 - *(_DWORD *)(v11 + 4LL * (int)result) < 0 )
{
v10 = result - 1;
}
else
{
if ( a3 - *(_DWORD *)(v11 + 4LL * (int)result) <= 0 )
return result;
v9 = result + 1;
}
}
while ( v10 >= v9 );
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, int a2, int a3, int a4, unsigned int a5)
{
int v8; // edx
int v9; // esi
int v10; // er9
__int64 v11; // r10
__int64 result; // rax

v8 = a3 - a4;
if ( v8 <= 0 )
{
result = a5;
if ( !v8 )
return result;
v9 = *(_DWORD *)(*(_QWORD *)(a1 + 32) + 4LL * a2);
v10 = a5 - 1;
}
else
{
v9 = a5 + 1;
v10 = *(_DWORD *)(*(_QWORD *)(a1 + 32) + 4LL * a2 + 4) - 1;
}
if ( v9 > v10 )
return 0xFFFFFFFFLL;
v11 = *(_QWORD *)(a1 + 24);
do
{
result = (unsigned int)((v9 + v10) >> 1);
if ( a3 - *(_DWORD *)(v11 + 4LL * (int)result) < 0 )
{
v10 = result - 1;
}
else
{
if ( a3 - *(_DWORD *)(v11 + 4LL * (int)result) <= 0 )
return result;
v9 = result + 1;
}
}
while ( v10 >= v9 );
return 0xFFFFFFFFLL;
}

original_code:
int sba_crsm_elmidxp(struct sba_crsm *sm, int i, int j, int jp, int jpidx)
{
register int low, high, mid, diff;
  diff=j-jp;
  if(diff>0){
    low=jpidx+1;
    high=sm->rowptr[i+1]-1;
  }
  else if(diff==0)
    return jpidx;
  else{
    low=sm->rowptr[i];
    high=jpidx-1;
  }
  while(low<=high){
    mid=(low+high)>>1;
    diff=j-sm->colidx[mid];
    if(diff<0)
      high=mid-1;
    else if(diff>0)
      low=mid+1;
    else
      return mid;
  }
  return -1;
}

canonical_original_code:
int sba_crsm_elmidxp(struct sba_crsm *sm, int i, int j, int jp, int jpidx)
{
register int low; register int high; register int mid; register int diff;
  diff=j-jp;
  if(diff>0){
    low=jpidx+1;
    high=sm->rowptr[i+1]-1;
  }
  else if(diff==0)
    return jpidx;
  else{
    low=sm->rowptr[i];
    high=jpidx-1;
  }
  while(low<=high){
    mid=(low+high)>>1;
    diff=j-sm->colidx[mid];
    if(diff<0)
      high=mid-1;
    else if(diff>0)
      low=mid+1;
    else
      return mid;
  }
  return -1;
}

variable_types: jp int

variable_types: jpidx int


original_code:
int sba_crsm_row_elmidxs(struct sba_crsm *sm, int i, int *vidxs, int *jidxs)
{
register int j, k;
  for(j=sm->rowptr[i], k=0; j<sm->rowptr[i+1]; ++j, ++k){
    vidxs[k]=j;
    jidxs[k]=sm->colidx[j];
  }
  return k;
}

canonical_original_code:
int sba_crsm_row_elmidxs(struct sba_crsm *sm, int i, int *vidxs, int *jidxs)
{
register int j; register int k;
  for(j=sm->rowptr[i], k=0; j<sm->rowptr[i+1]; ++j, ++k){
    vidxs[k]=j;
    jidxs[k]=sm->colidx[j];
  }
  return k;
}

variable_types:
vidxs
int *

variable_types:
jidxs
int *

variable_types: k int


original_code:
int sba_crsm_col_elmidxs(struct sba_crsm *sm, int j, int *vidxs, int *iidxs)
{
register int *nextrowptr=sm->rowptr+1;
register int i, l;
register int low, high, mid, diff;
  for(i=l=0; i<sm->nr; ++i){
    low=sm->rowptr[i];
    high=nextrowptr[i]-1;
    while(low<=high){
      mid=(low+high)>>1;
      diff=j-sm->colidx[mid];
      if(diff<0)
        high=mid-1;
      else if(diff>0)
        low=mid+1;
      else{
        vidxs[l]=mid;
        iidxs[l++]=i;
        break;
      }
    }
  }
  return l;
}

canonical_original_code:
int sba_crsm_col_elmidxs(struct sba_crsm *sm, int j, int *vidxs, int *iidxs)
{
register int *nextrowptr = sm->rowptr+1;
register int i; register int l;
register int low; register int high; register int mid; register int diff;
  for(i=l=0; i<sm->nr; ++i){
    low=sm->rowptr[i];
    high=nextrowptr[i]-1;
    while(low<=high){
      mid=(low+high)>>1;
      diff=j-sm->colidx[mid];
      if(diff<0)
        high=mid-1;
      else if(diff>0)
        low=mid+1;
      else{
        vidxs[l]=mid;
        iidxs[l++]=i;
        break;
      }
    }
  }
  return l;
}

variable_types:
iidxs
int *

variable_types:
nextrowptr
int *

variable_types: i int

variable_types: l int


repo: BucOder/passgenc

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

result = number_option == 0 ? 78 : 88;
if ( !special_char_option )
result = number_option == 0 ? 51 : 61;
if ( !uppercase_option )
result = (unsigned int)(result - 26);
if ( !lowercase_option )
result = (unsigned int)(result - 26);
return result;
}

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

result = number_option == 0 ? 78 : 88;
if ( !special_char_option )
result = number_option == 0 ? 51 : 61;
if ( !uppercase_option )
result = (unsigned int)(result - 26);
if ( !lowercase_option )
result = (unsigned int)(result - 26);
return result;
}

original_code:
int calcul_number_of_char() {
    int number = 88;
    if(!number_option)
        number -= 10;
    if(!special_char_option)
        number -= 27;
    if(!uppercase_option)
        number -= 26;
    if(!lowercase_option)
        number -= 26;
    return number;
}

variable_types: number int


decompiled_code:
__int64 __fastcall is_password_include_lowercase(char *a1)
{
int v1; // ebp
const unsigned __int16 *v2; // rcx
char *v3; // rax
char *v4; // rdi

v1 = password_length;
if ( password_length <= 0 )
return 0LL;
v2 = *__ctype_b_loc();
v3 = a1;
v4 = &a1[v1 - 1];
while ( (v2[*v3] & 0x200) == 0 )
{
if ( v3 == v4 )
return 0LL;
++v3;
}
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func8(char *a1)
{
int v1; // ebp
const unsigned __int16 *v2; // rcx
char *v3; // rax
char *v4; // rdi

v1 = password_length;
if ( password_length <= 0 )
return 0LL;
v2 = *__ctype_b_loc();
v3 = a1;
v4 = &a1[v1 - 1];
while ( (v2[*v3] & 0x200) == 0 )
{
if ( v3 == v4 )
return 0LL;
++v3;
}
return 1LL;
}

original_code:
int is_password_include_lowercase(char* password) {
    int i;
    for(i=0;i<password_length;i++) {
        if(((*__ctype_b_loc ())[(int) ((password[i]))] & (unsigned short int) _ISlower))
            return 1;
    }
    return 0;
}

canonical_original_code:
int is_password_include_lowercase(char *password) {
    int i;
    for(i=0;i<password_length;i++) {
        if(((*__ctype_b_loc ())[(int) ((password[i]))] & (unsigned short) _ISlower))
            return 1;
    }
    return 0;
}

variable_types:
password
char *


decompiled_code:
__int64 __fastcall is_password_include_uppercase(char *a1)
{
int v1; // ebp
const unsigned __int16 *v2; // rcx
char *v3; // rax
char *v4; // rdi

v1 = password_length;
if ( password_length <= 0 )
return 0LL;
v2 = *__ctype_b_loc();
v3 = a1;
v4 = &a1[v1 - 1];
while ( (v2[*v3] & 0x100) == 0 )
{
if ( v3 == v4 )
return 0LL;
++v3;
}
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func9(char *a1)
{
int v1; // ebp
const unsigned __int16 *v2; // rcx
char *v3; // rax
char *v4; // rdi

v1 = password_length;
if ( password_length <= 0 )
return 0LL;
v2 = *__ctype_b_loc();
v3 = a1;
v4 = &a1[v1 - 1];
while ( (v2[*v3] & 0x100) == 0 )
{
if ( v3 == v4 )
return 0LL;
++v3;
}
return 1LL;
}

original_code:
int is_password_include_uppercase(char* password) {
    int i;
    for(i=0;i<password_length;i++) {
        if(((*__ctype_b_loc ())[(int) ((password[i]))] & (unsigned short int) _ISupper))
            return 1;
    }
    return 0;
}

canonical_original_code:
int is_password_include_uppercase(char *password) {
    int i;
    for(i=0;i<password_length;i++) {
        if(((*__ctype_b_loc ())[(int) ((password[i]))] & (unsigned short) _ISupper))
            return 1;
    }
    return 0;
}


decompiled_code:
__int64 __fastcall is_password_include_special_char(char *a1)
{
int v1; // ebp
const unsigned __int16 *v2; // rcx
char *v3; // rax
char *v4; // rdi

v1 = password_length;
if ( password_length <= 0 )
return 0LL;
v2 = *__ctype_b_loc();
v3 = a1;
v4 = &a1[v1 - 1];
while ( (v2[*v3] & 4) == 0 )
{
if ( v3 == v4 )
return 0LL;
++v3;
}
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func10(char *a1)
{
int v1; // ebp
const unsigned __int16 *v2; // rcx
char *v3; // rax
char *v4; // rdi

v1 = password_length;
if ( password_length <= 0 )
return 0LL;
v2 = *__ctype_b_loc();
v3 = a1;
v4 = &a1[v1 - 1];
while ( (v2[*v3] & 4) == 0 )
{
if ( v3 == v4 )
return 0LL;
++v3;
}
return 1LL;
}

original_code:
int is_password_include_special_char(char* password) {
    int i;
    for(i=0;i<password_length;i++) {
        if(((*__ctype_b_loc ())[(int) ((password[i]))] & (unsigned short int) _ISpunct))
            return 1;
    }
    return 0;
}

canonical_original_code:
int is_password_include_special_char(char *password) {
    int i;
    for(i=0;i<password_length;i++) {
        if(((*__ctype_b_loc ())[(int) ((password[i]))] & (unsigned short) _ISpunct))
            return 1;
    }
    return 0;
}


decompiled_code:
__int64 __fastcall is_password_include_number(char *a1)
{
int v1; // ebp
const unsigned __int16 *v2; // rcx
char *v3; // rax
char *v4; // rdi

v1 = password_length;
if ( password_length <= 0 )
return 0LL;
v2 = *__ctype_b_loc();
v3 = a1;
v4 = &a1[v1 - 1];
while ( (v2[*v3] & 0x800) == 0 )
{
if ( v3 == v4 )
return 0LL;
++v3;
}
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func11(char *a1)
{
int v1; // ebp
const unsigned __int16 *v2; // rcx
char *v3; // rax
char *v4; // rdi

v1 = password_length;
if ( password_length <= 0 )
return 0LL;
v2 = *__ctype_b_loc();
v3 = a1;
v4 = &a1[v1 - 1];
while ( (v2[*v3] & 0x800) == 0 )
{
if ( v3 == v4 )
return 0LL;
++v3;
}
return 1LL;
}

original_code:
int is_password_include_number(char* password) {
    int i;
    for(i=0;i<password_length;i++) {
        if(((*__ctype_b_loc ())[(int) ((password[i]))] & (unsigned short int) _ISdigit))
            return 1;
    }
    return 0;
}

canonical_original_code:
int is_password_include_number(char *password) {
    int i;
    for(i=0;i<password_length;i++) {
        if(((*__ctype_b_loc ())[(int) ((password[i]))] & (unsigned short) _ISdigit))
            return 1;
    }
    return 0;
}


decompiled_code:
__int64 __fastcall is_approve_password(char *a1)
{
__int64 result; // rax

if ( !number_option || (result = is_password_include_number(a1), (_DWORD)result) )
{
if ( !special_char_option || (result = is_password_include_special_char(a1), (_DWORD)result) )
{
if ( !uppercase_option || (result = is_password_include_uppercase(a1), (_DWORD)result) )
{
result = 1LL;
if ( lowercase_option )
result = (unsigned int)is_password_include_lowercase(a1) != 0;
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func12(char *a1)
{
__int64 result; // rax

if ( !number_option || (result = func11(a1), (_DWORD)result) )
{
if ( !special_char_option || (result = func10(a1), (_DWORD)result) )
{
if ( !uppercase_option || (result = func9(a1), (_DWORD)result) )
{
result = 1LL;
if ( lowercase_option )
result = (unsigned int)func8(a1) != 0;
}
}
}
return result;
}

original_code:
int is_approve_password(char* password) {
    if(number_option)
            if(!is_password_include_number(password))
                    return 0;
    if(special_char_option)
            if(!is_password_include_special_char(password))
                    return 0;
    if(uppercase_option)
            if(!is_password_include_uppercase(password))
                    return 0;
    if(lowercase_option)
            if(!is_password_include_lowercase(password))
                    return 0;
    return 1;
}

canonical_original_code:
int is_approve_password(char *password) {
    if(number_option)
            if(!is_password_include_number(password))
                    return 0;
    if(special_char_option)
            if(!is_password_include_special_char(password))
                    return 0;
    if(uppercase_option)
            if(!is_password_include_uppercase(password))
                    return 0;
    if(lowercase_option)
            if(!is_password_include_lowercase(password))
                    return 0;
    return 1;
}


decompiled_code:
int __fastcall print_password(char *a1)
{
char v2; // di
char *v3; // rbx

v2 = *a1;
if ( v2 )
{
v3 = a1 + 1;
do
{
putchar(v2);
v2 = *v3++;
}
while ( v2 );
}
return putchar(10);
}

canonical_decompiled_code:
int __fastcall func13(char *a1)
{
char v2; // di
char *v3; // rbx

v2 = *a1;
if ( v2 )
{
v3 = a1 + 1;
do
{
putchar(v2);
v2 = *v3++;
}
while ( v2 );
}
return putchar(10);
}

original_code:
void print_password(char* str) {
    int i = 0;
    while(str[i]) {
        printf("%c",str[i]);
        i++;
    }
    printf("\n");
}

canonical_original_code:
void print_password(char *str) {
    int i = 0;
    while(str[i]) {
        printf("%c",str[i]);
        i++;
    }
    printf("\n");
}

variable_types:
str
char *


swap

decompiled_code:
__int64 __fastcall swap(__int64 a1, int a2, int a3)
{
_BYTE *v3; // rsi
__int64 result; // rax
_BYTE *v5; // rdi

v3 = (_BYTE *)(a1 + a2);
result = (unsigned __int8)*v3;
v5 = (_BYTE *)(a3 + a1);
*v3 = *v5;
*v5 = result;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func18(__int64 a1, int a2, int a3)
{
_BYTE *v3; // rsi
__int64 result; // rax
_BYTE *v5; // rdi

v3 = (_BYTE *)(a1 + a2);
result = (unsigned __int8)*v3;
v5 = (_BYTE *)(a3 + a1);
*v3 = *v5;
*v5 = result;
return result;
}

original_code:
void swap(char* tab, int a, int b) {
    char tmp;
    tmp = tab[a];
    tab[a]= tab[b];
    tab[b] = tmp;
}

canonical_original_code:
void swap(char *tab, int a, int b) {
    char tmp;
    tmp = tab[a];
    tab[a]= tab[b];
    tab[b] = tmp;
}

variable_types:
tab
char *

variable_types: a int

variable_types: b int

variable_types: tmp char


decompiled_code:
void __fastcall shuffle_tab(__int64 a1)
{
int v1; // ebx
int v2; // eax

if ( number_of_char > 0 )
{
v1 = 0;
do
{
v2 = rand();
swap(a1, v1++, v2 % number_of_char);
}
while ( number_of_char > v1 );
}
}

canonical_decompiled_code:
void __fastcall func19(__int64 a1)
{
int v1; // ebx
int v2; // eax

if ( number_of_char > 0 )
{
v1 = 0;
do
{
v2 = rand();
func18(a1, v1++, v2 % number_of_char);
}
while ( number_of_char > v1 );
}
}

original_code:
void shuffle_tab(char* tab) {
    int i;
    int random_number;
    for(i=0;i<number_of_char;i++) {
        random_number = rand()%number_of_char;
        swap(tab, i, random_number);
    }
}

canonical_original_code:
void shuffle_tab(char *tab) {
    int i;
    int random_number;
    for(i=0;i<number_of_char;i++) {
        random_number = rand()%number_of_char;
        swap(tab, i, random_number);
    }
}


decompiled_code:
void __fastcall init_tab_of_char(__int64 a1)
{
int v1; // esi

v1 = number_option;
if ( number_option )
v1 = add_number(a1, 0);
if ( special_char_option )
v1 = add_special_char(a1, v1);
if ( uppercase_option )
v1 = add_uppercase(a1, v1);
if ( lowercase_option )
add_lowercase(a1, v1);
shuffle_tab(a1);
}

canonical_decompiled_code:
void __fastcall func20(__int64 a1)
{
int v1; // esi

v1 = number_option;
if ( number_option )
v1 = func14(a1, 0);
if ( special_char_option )
v1 = func15(a1, v1);
if ( uppercase_option )
v1 = func16(a1, v1);
if ( lowercase_option )
func17(a1, v1);
func19(a1);
}

original_code:
void init_tab_of_char(char* tab) {
    int offset = 0;
    if(number_option)
        offset = add_number(tab, offset);
    if(special_char_option)
        offset = add_special_char(tab, offset);
    if(uppercase_option)
        offset = add_uppercase(tab, offset);
    if(lowercase_option)
        offset = add_lowercase(tab, offset);
    shuffle_tab(tab);
}

canonical_original_code:
void init_tab_of_char(char *tab) {
    int offset = 0;
    if(number_option)
        offset = add_number(tab, offset);
    if(special_char_option)
        offset = add_special_char(tab, offset);
    if(uppercase_option)
        offset = add_uppercase(tab, offset);
    if(lowercase_option)
        offset = add_lowercase(tab, offset);
    shuffle_tab(tab);
}

variable_types: offset int


error

decompiled_code:
void __noreturn error()
{
fwrite("Error with param !\n", 1uLL, 0x13uLL, stderr);
exit(1);
}

canonical_decompiled_code:
void __noreturn func21()
{
fwrite("Error with param !\n", 1uLL, 0x13uLL, stderr);
exit(1);
}

original_code:
void error() {
    fprintf(stderr, "Error with param !\n");
    exit(1);
}


decompiled_code:
char __fastcall parse_options(const char *a1)
{
bool v1; // cf
bool v2; // zf
const char *v4; // rdi
__int64 v5; // rcx
const char *v6; // rsi
char result; // al
_BYTE *i; // rsi

v4 = "-a";
v5 = 3LL;
v6 = a1;
do
{
if ( !v5 )
break;
v1 = *v6 < (unsigned int)*v4;
v2 = *v6++ == *v4++;
--v5;
}
while ( v2 );
result = (!v1 && !v2) - v1;
if ( result )
{
result = a1[1];
for ( i = a1 + 2; result; result = *(i - 1) )
{
if ( result == 115 )
{
special_char_option = 1;
}
else if ( result > 115 )
{
if ( result != 117 )
goto LABEL_18;
uppercase_option = 1;
}
else if ( result == 108 )
{
lowercase_option = 1;
}
else
{
if ( result != 110 )
LABEL_18:
error(v4, i, a1);
number_option = 1;
}
++i;
}
}
else
{
number_option = 1;
special_char_option = 1;
uppercase_option = 1;
lowercase_option = 1;
}
return result;
}

canonical_decompiled_code:
char __fastcall func22(const char *a1)
{
bool v1; // cf
bool v2; // zf
const char *v4; // rdi
__int64 v5; // rcx
const char *v6; // rsi
char result; // al
_BYTE *i; // rsi

v4 = "-a";
v5 = 3LL;
v6 = a1;
do
{
if ( !v5 )
break;
v1 = *v6 < (unsigned int)*v4;
v2 = *v6++ == *v4++;
--v5;
}
while ( v2 );
result = (!v1 && !v2) - v1;
if ( result )
{
result = a1[1];
for ( i = a1 + 2; result; result = *(i - 1) )
{
if ( result == 115 )
{
special_char_option = 1;
}
else if ( result > 115 )
{
if ( result != 117 )
goto LABEL_18;
uppercase_option = 1;
}
else if ( result == 108 )
{
lowercase_option = 1;
}
else
{
if ( result != 110 )
LABEL_18:
func21(v4, i, a1);
number_option = 1;
}
++i;
}
}
else
{
number_option = 1;
special_char_option = 1;
uppercase_option = 1;
lowercase_option = 1;
}
return result;
}

original_code:
void parse_options(char* options) {
    int k = 1;
    if(!strcmp(options, "-a")) {
        number_option = 1;
        special_char_option = 1;
        uppercase_option = 1;
        lowercase_option = 1;
        return;
    }
    while(options[k] != '\0') {
        switch(options[k]) {
            case 'n': number_option = 1;
                        break;
            case 's': special_char_option = 1;
                        break;
            case 'u': uppercase_option = 1;
                        break;
            case 'l': lowercase_option = 1;
                        break;
            default: error();
        }
        k++;
    }
}

canonical_original_code:
void parse_options(char *options) {
    int k = 1;
    if(!strcmp(options, "-a")) {
        number_option = 1;
        special_char_option = 1;
        uppercase_option = 1;
        lowercase_option = 1;
        return;
    }
    while(options[k] != '\0') {
        switch(options[k]) {
            case 'n': number_option = 1;
                        break;
            case 's': special_char_option = 1;
                        break;
            case 'u': uppercase_option = 1;
                        break;
            case 'l': lowercase_option = 1;
                        break;
            default: error();
        }
        k++;
    }
}

variable_types:
options
char *


decompiled_code:
__int64 __fastcall parse_arg(__int64 a1, __int64 a2, __int64 a3)
{
const char *v3; // rbp
const char *v4; // rdi
__int64 v5; // rdx
int v6; // ebx
__int64 result; // rax

if ( (_DWORD)a1 != 3 )
error(a1, a2, a3);
v3 = *(const char **)(a2 + 8);
if ( *v3 != 45 )
error(a1, a2, a3);
v4 = *(const char **)(a2 + 16);
v6 = atoi(v4);
if ( (unsigned int)(v6 - 4) > 0xFB )
error(v4, a2, v5);
parse_options(v3);
password_length = v6;
result = lowercase_option | uppercase_option | special_char_option | (unsigned int)number_option;
if ( !(lowercase_option | uppercase_option | special_char_option | number_option) )
number_option = 1;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func23(__int64 a1, __int64 a2, __int64 a3)
{
const char *v3; // rbp
const char *v4; // rdi
__int64 v5; // rdx
int v6; // ebx
__int64 result; // rax

if ( (_DWORD)a1 != 3 )
func21(a1, a2, a3);
v3 = *(const char **)(a2 + 8);
if ( *v3 != 45 )
func21(a1, a2, a3);
v4 = *(const char **)(a2 + 16);
v6 = atoi(v4);
if ( (unsigned int)(v6 - 4) > 0xFB )
func21(v4, a2, v5);
func22(v3);
password_length = v6;
result = lowercase_option | uppercase_option | special_char_option | (unsigned int)number_option;
if ( !(lowercase_option | uppercase_option | special_char_option | number_option) )
number_option = 1;
return result;
}

original_code:
void parse_arg(int argc, char* argv[]) {
    if(argc != 3)
        error();
    if(argv[1][0] != '-')
        error();
    int length_param = atoi(argv[2]);
    if(length_param < 4 || length_param > 255)
        error();
    parse_options(argv[1]);
    password_length = length_param;
    if(!number_option && !special_char_option && !uppercase_option && !lowercase_option)
        number_option = 1;
}

canonical_original_code:
void parse_arg(int argc, char *argv[]) {
    if(argc != 3)
        error();
    if(argv[1][0] != '-')
        error();
    int length_param = atoi(argv[2]);
    if(length_param < 4 || length_param > 255)
        error();
    parse_options(argv[1]);
    password_length = length_param;
    if(!number_option && !special_char_option && !uppercase_option && !lowercase_option)
        number_option = 1;
}

variable_types: argc int

variable_types:
argv
char *[]