// File: /workspace/github_c_makefile_star2_O0/System-Glitch[P]ESGILinter-C/src/fileloader.c
// Function: file_loader
void file_loader(arraylist_t *e/*, arraylist_t *files*/, arraylist_t *real_file, char *filename){

    if(strlen(filename) <= 0) return;
    unsigned int length;
    unsigned int i;
    unsigned int j;
    unsigned int index;
    int tempo;
    int init;
    char *line;
    char *tmp = NULL;
    char *tmp2 = NULL;
    char *tmp_line;
    char *res;
    char *for_loop = NULL;
    char *real;
    char c;
    int real_line;
    int last_real_line;
    line_t *l;
    int line_counter;
    int counter;
    int start_for;
    int literal;
    //int include_fold;
    unsigned int realloc_count = 1;
    size_t start_buffer;
    size_t file_length;
    size_t for_loop_length;
    int start_array;
    int array_length;
    FILE *src;

    src = fopen(filename,"rb");

    if(src == NULL){
        return;
    }

    length = file_row_number(src);
    /*
     * Memory allocation
     */

    line = malloc(sizeof(char) * 1048);
    tmp_line = malloc(sizeof(char) * 1048);
    tmp_line[0] = '\0';

    /*
     * Load the array
     */

    line_counter = 0;
    real_line = 0;
    last_real_line = 0;
    start_for = 0;
    literal = 0;
    start_array = 0;
    array_length = 0;
    start_buffer = 0;
    //include_fold = 0;

    for(i = 0; i < length; i++){
        tempo = 0;
        counter = 0;
        init = 0;
        line_counter++;
        if(!fgets(line, 1048, src)) {
            printf("%s[ERROR]%s %s%s\n", COLOR_RED, COLOR_YELLOW, strerror(errno), FORMAT_RESET);
            exit(EXIT_FAILURE);
        }

        /*if(strstr(line, "#include \"") == line){
            int first_index = strindexof(line, '"');
            int last_index = strlastindexof(line, '"');
            tmp2 = strsubstr(line, first_index+1, last_index-first_index-1);
            last_index = strlastindexof(tmp2, '/');
            if(last_index != -1){
                tmp = strsubstr(tmp2, last_index+1, strlen(tmp2) - last_index);
                include_fold = 1;
                free(tmp2);
                tmp2 = NULL;
            }
            for(size_t k = 0; k < files->size; k++){
                if(include_fold){
                    if(strstr(files->array[k], tmp) != NULL){
                        file_loader(e, files, real_file, files->array[k]);
                        start_buffer = real_file->size;
                    }
                }else{
                    if(strstr(files->array[k], tmp2) != NULL){
                        file_loader(e, files, real_file, files->array[k]);
                        start_buffer = real_file->size;
                    }
                }
            }
            if(tmp != NULL) {
                free(tmp);
                tmp = NULL;
            }else{
                free(tmp2);
                tmp2 = NULL;
            }
            continue;
        }*/

        real = malloc(sizeof(char) * 1048);
        strcpy(real, line);
        arraylist_add(real_file, real);

        for_loop = strstr(line, "for");
        if(for_loop != NULL){
            for_loop += 3;
            index = 0;
            start_for = 1;
            for_loop_length = strlen(for_loop);
            while(is_whitespace(c = for_loop[index]) && index < for_loop_length) { index++; };
            if(for_loop[index] == '(') start_for = 1;
        }

        file_length = strlen(line);
        for(j = 0; j < file_length ; j++){
            if(line[j] == '"' && literal == 1){
                literal = 0;
            }else if(line[j] == '"' && literal == 0){
                literal = 1;
            }
            if(line[j] == '=' && start_array == 0){
                index = j+1;
                while(is_whitespace(c = line[index]) && index < file_length) { index++; };
                if(line[index] == '{'){
                    start_array = 1;
                    continue;
                }
            }
            if(start_array == 1 && line[j] == '{'){
                array_length++;
                continue;
            }
            if(start_array == 1 && line[j] == '}'){
                array_length--;
                if(array_length == 0) start_array = 0;
                continue;
            }


            if(((line[j] == ';' && start_for == 0) || (line[j] == '{' && start_array == 0) || (line[j] == '}' && start_array == 0)) && literal != 1 ){
                if(!check_quotes(line, line + j, file_length)) {
                    l = malloc(sizeof(line_t));
                    l->source = strduplicate(filename);
                    l->start_line_in_buffer = start_buffer+last_real_line;
                    l->start_real_line = last_real_line;
                    last_real_line = real_line + 1;

                    if(strlen(tmp_line) != 0){
                        l->line = strduplicate(tmp_line);
                        tmp = strsubstr(line, tempo, j+1);
                        tmp2 = strconcat(l->line, tmp);
                        free(l->line);
                        free(tmp);
                        l->line = tmp2;
                        tmp_line[0] = '\0';
                    }else{
                        if(!init){
                            l->line = strsubstr(line, tempo, j+1);
                        }else{
                            l->line = strsubstr(line, tempo, j-init);
                        }
                    }
                    arraylist_add(e, l);
                    tempo = j+1;
                    counter++;
                    init = j;
                    if(start_for == 1 && line[j] == '{')
                        start_for = 0;
                }
            }
            if(line[j] == '\n' || (j < file_length && line[j] == '\r' && line[j+1] == '\n')){
                real_line = i + 1;
            }
        }

        if(!counter){
            if(strlen(tmp_line) + strlen(line) >= 1048)
                tmp_line = realloc(tmp_line, sizeof(char) * 1048 * ++realloc_count);
            strcat(tmp_line, line);
        }else if(counter && tempo){
            res = strsubstr(line, tempo, strlen(line));
            strcat(tmp_line, res);
            free(res);
        }
    }


    /*
     * Free the memory
     */
    fclose(src);
    free(line);
    free(tmp_line);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xe0, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq -0x18(%rbp), %rdi
callq 0x2090
cmpq $0x0, %rax
ja 0x234b
jmp 0x2a1c
movq $0x0, -0x40(%rbp)
movq $0x0, -0x48(%rbp)
movq $0x0, -0x60(%rbp)
movl $0x1, -0x94(%rbp)
movq -0x18(%rbp), %rdi
leaq 0x10c8c(%rip), %rsi     # 0x13004
callq 0x2130
movq %rax, -0xc0(%rbp)
cmpq $0x0, -0xc0(%rbp)
jne 0x2393
jmp 0x2a1c
movq -0xc0(%rbp), %rdi
callq 0x22a0
movl %eax, -0x1c(%rbp)
movl $0x418, %edi            # imm = 0x418
callq 0x2110
movq %rax, -0x38(%rbp)
movl $0x418, %edi            # imm = 0x418
callq 0x2110
movq %rax, -0x50(%rbp)
movq -0x50(%rbp), %rax
movb $0x0, (%rax)
movl $0x0, -0x84(%rbp)
movl $0x0, -0x70(%rbp)
movl $0x0, -0x74(%rbp)
movl $0x0, -0x8c(%rbp)
movl $0x0, -0x90(%rbp)
movl $0x0, -0xb4(%rbp)
movl $0x0, -0xb8(%rbp)
movq $0x0, -0xa0(%rbp)
movl $0x0, -0x20(%rbp)
movl -0x20(%rbp), %eax
cmpl -0x1c(%rbp), %eax
jae 0x29fe
movl $0x0, -0x2c(%rbp)
movl $0x0, -0x88(%rbp)
movl $0x0, -0x30(%rbp)
movl -0x84(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x84(%rbp)
movq -0x38(%rbp), %rdi
movq -0xc0(%rbp), %rdx
movl $0x418, %esi            # imm = 0x418
callq 0x20e0
cmpq $0x0, %rax
jne 0x24a1
callq 0x2040
movl (%rax), %edi
callq 0x2180
movq %rax, %rcx
leaq 0x10b8c(%rip), %rdi     # 0x13007
leaq 0x10b97(%rip), %rsi     # 0x13019
leaq 0x10b96(%rip), %rdx     # 0x1301f
leaq 0x10b95(%rip), %r8      # 0x13025
movb $0x0, %al
callq 0x20b0
movl $0x1, %edi
callq 0x2170
movl $0x418, %edi            # imm = 0x418
callq 0x2110
movq %rax, -0x68(%rbp)
movq -0x68(%rbp), %rdi
movq -0x38(%rbp), %rsi
callq 0x2060
movq -0x10(%rbp), %rdi
movq -0x68(%rbp), %rsi
callq 0x8730
movq -0x38(%rbp), %rdi
leaq 0x10b56(%rip), %rsi     # 0x1302a
callq 0x2190
movq %rax, -0x60(%rbp)
cmpq $0x0, -0x60(%rbp)
je 0x2580
movq -0x60(%rbp), %rax
addq $0x3, %rax
movq %rax, -0x60(%rbp)
movl $0x0, -0x28(%rbp)
movl $0x1, -0x8c(%rbp)
movq -0x60(%rbp), %rdi
callq 0x2090
movq %rax, -0xb0(%rbp)
movq -0x60(%rbp), %rax
movl -0x28(%rbp), %ecx
movb (%rax,%rcx), %al
movb %al, -0x69(%rbp)
movsbl %al, %edi
callq 0xa7d0
movsbl %al, %ecx
xorl %eax, %eax
cmpl $0x0, %ecx
movb %al, -0xc1(%rbp)
je 0x254d
movl -0x28(%rbp), %eax
cmpq -0xb0(%rbp), %rax
setb %al
movb %al, -0xc1(%rbp)
movb -0xc1(%rbp), %al
testb $0x1, %al
jne 0x2559
jmp 0x2564
movl -0x28(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x28(%rbp)
jmp 0x2515
movq -0x60(%rbp), %rax
movl -0x28(%rbp), %ecx
movsbl (%rax,%rcx), %eax
cmpl $0x28, %eax
jne 0x257e
movl $0x1, -0x8c(%rbp)
jmp 0x2580
movq -0x38(%rbp), %rdi
callq 0x2090
movq %rax, -0xa8(%rbp)
movl $0x0, -0x24(%rbp)
movl -0x24(%rbp), %eax
cmpq -0xa8(%rbp), %rax
jae 0x2927
movq -0x38(%rbp), %rax
movl -0x24(%rbp), %ecx
movsbl (%rax,%rcx), %eax
cmpl $0x22, %eax
jne 0x25cc
cmpl $0x1, -0x90(%rbp)
jne 0x25cc
movl $0x0, -0x90(%rbp)
jmp 0x25f1
movq -0x38(%rbp), %rax
movl -0x24(%rbp), %ecx
movsbl (%rax,%rcx), %eax
cmpl $0x22, %eax
jne 0x25ef
cmpl $0x0, -0x90(%rbp)
jne 0x25ef
movl $0x1, -0x90(%rbp)
jmp 0x25f1
movq -0x38(%rbp), %rax
movl -0x24(%rbp), %ecx
movsbl (%rax,%rcx), %eax
cmpl $0x3d, %eax
jne 0x2687
cmpl $0x0, -0xb4(%rbp)
jne 0x2687
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x28(%rbp)
movq -0x38(%rbp), %rax
movl -0x28(%rbp), %ecx
movb (%rax,%rcx), %al
movb %al, -0x69(%rbp)
movsbl %al, %edi
callq 0xa7d0
movsbl %al, %ecx
xorl %eax, %eax
cmpl $0x0, %ecx
movb %al, -0xc2(%rbp)
je 0x264f
movl -0x28(%rbp), %eax
cmpq -0xa8(%rbp), %rax
setb %al
movb %al, -0xc2(%rbp)
movb -0xc2(%rbp), %al
testb $0x1, %al
jne 0x265b
jmp 0x2666
movl -0x28(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x28(%rbp)
jmp 0x2617
movq -0x38(%rbp), %rax
movl -0x28(%rbp), %ecx
movsbl (%rax,%rcx), %eax
cmpl $0x7b, %eax
jne 0x2685
movl $0x1, -0xb4(%rbp)
jmp 0x2919
jmp 0x2687
cmpl $0x1, -0xb4(%rbp)
jne 0x26b4
movq -0x38(%rbp), %rax
movl -0x24(%rbp), %ecx
movsbl (%rax,%rcx), %eax
cmpl $0x7b, %eax
jne 0x26b4
movl -0xb8(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xb8(%rbp)
jmp 0x2919
cmpl $0x1, -0xb4(%rbp)
jne 0x26f4
movq -0x38(%rbp), %rax
movl -0x24(%rbp), %ecx
movsbl (%rax,%rcx), %eax
cmpl $0x7d, %eax
jne 0x26f4
movl -0xb8(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0xb8(%rbp)
cmpl $0x0, -0xb8(%rbp)
jne 0x26ef
movl $0x0, -0xb4(%rbp)
jmp 0x2919
movq -0x38(%rbp), %rax
movl -0x24(%rbp), %ecx
movsbl (%rax,%rcx), %eax
cmpl $0x3b, %eax
jne 0x270d
cmpl $0x0, -0x8c(%rbp)
je 0x2747
movq -0x38(%rbp), %rax
movl -0x24(%rbp), %ecx
movsbl (%rax,%rcx), %eax
cmpl $0x7b, %eax
jne 0x2726
cmpl $0x0, -0xb4(%rbp)
je 0x2747
movq -0x38(%rbp), %rax
movl -0x24(%rbp), %ecx
movsbl (%rax,%rcx), %eax
cmpl $0x7d, %eax
jne 0x28cd
cmpl $0x0, -0xb4(%rbp)
jne 0x28cd
cmpl $0x1, -0x90(%rbp)
je 0x28cd
movq -0x38(%rbp), %rdi
movq -0x38(%rbp), %rsi
movl -0x24(%rbp), %eax
addq %rax, %rsi
movq -0xa8(%rbp), %rax
movl %eax, %edx
callq 0xae60
cmpb $0x0, %al
jne 0x28cb
movl $0x18, %edi
callq 0x2110
movq %rax, -0x80(%rbp)
movq -0x18(%rbp), %rdi
callq 0xa550
movq %rax, %rcx
movq -0x80(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0xa0(%rbp), %rax
movslq -0x74(%rbp), %rcx
addq %rcx, %rax
movl %eax, %ecx
movq -0x80(%rbp), %rax
movl %ecx, 0x14(%rax)
movl -0x74(%rbp), %ecx
movq -0x80(%rbp), %rax
movl %ecx, 0x10(%rax)
movl -0x70(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x74(%rbp)
movq -0x50(%rbp), %rdi
callq 0x2090
cmpq $0x0, %rax
je 0x2839
movq -0x50(%rbp), %rdi
callq 0xa550
movq %rax, %rcx
movq -0x80(%rbp), %rax
movq %rcx, (%rax)
movq -0x38(%rbp), %rdi
movl -0x2c(%rbp), %esi
movl -0x24(%rbp), %edx
addl $0x1, %edx
callq 0xa5e0
movq %rax, -0x40(%rbp)
movq -0x80(%rbp), %rax
movq (%rax), %rdi
movq -0x40(%rbp), %rsi
callq 0xa9b0
movq %rax, -0x48(%rbp)
movq -0x80(%rbp), %rax
movq (%rax), %rdi
callq 0x2030
movq -0x40(%rbp), %rdi
callq 0x2030
movq -0x48(%rbp), %rcx
movq -0x80(%rbp), %rax
movq %rcx, (%rax)
movq -0x50(%rbp), %rax
movb $0x0, (%rax)
jmp 0x287b
cmpl $0x0, -0x30(%rbp)
jne 0x285d
movq -0x38(%rbp), %rdi
movl -0x2c(%rbp), %esi
movl -0x24(%rbp), %edx
addl $0x1, %edx
callq 0xa5e0
movq %rax, %rcx
movq -0x80(%rbp), %rax
movq %rcx, (%rax)
jmp 0x2879
movq -0x38(%rbp), %rdi
movl -0x2c(%rbp), %esi
movl -0x24(%rbp), %edx
subl -0x30(%rbp), %edx
callq 0xa5e0
movq %rax, %rcx
movq -0x80(%rbp), %rax
movq %rcx, (%rax)
jmp 0x287b
movq -0x8(%rbp), %rdi
movq -0x80(%rbp), %rsi
callq 0x8730
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
movl -0x88(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x88(%rbp)
movl -0x24(%rbp), %eax
movl %eax, -0x30(%rbp)
cmpl $0x1, -0x8c(%rbp)
jne 0x28c9
movq -0x38(%rbp), %rax
movl -0x24(%rbp), %ecx
movsbl (%rax,%rcx), %eax
cmpl $0x7b, %eax
jne 0x28c9
movl $0x0, -0x8c(%rbp)
jmp 0x28cb
jmp 0x28cd
movq -0x38(%rbp), %rax
movl -0x24(%rbp), %ecx
movsbl (%rax,%rcx), %eax
cmpl $0xa, %eax
je 0x290e
movl -0x24(%rbp), %eax
cmpq -0xa8(%rbp), %rax
jae 0x2917
movq -0x38(%rbp), %rax
movl -0x24(%rbp), %ecx
movsbl (%rax,%rcx), %eax
cmpl $0xd, %eax
jne 0x2917
movq -0x38(%rbp), %rax
movl -0x24(%rbp), %ecx
addl $0x1, %ecx
movl %ecx, %ecx
movsbl (%rax,%rcx), %eax
cmpl $0xa, %eax
jne 0x2917
movl -0x20(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x70(%rbp)
jmp 0x2919
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x2597
cmpl $0x0, -0x88(%rbp)
jne 0x2992
movq -0x50(%rbp), %rdi
callq 0x2090
movq %rax, -0xd0(%rbp)
movq -0x38(%rbp), %rdi
callq 0x2090
movq %rax, %rcx
movq -0xd0(%rbp), %rax
addq %rcx, %rax
cmpq $0x418, %rax            # imm = 0x418
jb 0x2983
movq -0x50(%rbp), %rdi
movl -0x94(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x94(%rbp)
movl %eax, %eax
imulq $0x418, %rax, %rsi      # imm = 0x418
callq 0x2120
movq %rax, -0x50(%rbp)
movq -0x50(%rbp), %rdi
movq -0x38(%rbp), %rsi
callq 0x2150
jmp 0x29ee
cmpl $0x0, -0x88(%rbp)
je 0x29ec
cmpl $0x0, -0x2c(%rbp)
je 0x29ec
movq -0x38(%rbp), %rax
movq %rax, -0xe0(%rbp)
movl -0x2c(%rbp), %eax
movl %eax, -0xd4(%rbp)
movq -0x38(%rbp), %rdi
callq 0x2090
movq -0xe0(%rbp), %rdi
movl -0xd4(%rbp), %esi
movl %eax, %edx
callq 0xa5e0
movq %rax, -0x58(%rbp)
movq -0x50(%rbp), %rdi
movq -0x58(%rbp), %rsi
callq 0x2150
movq -0x58(%rbp), %rdi
callq 0x2030
jmp 0x29ee
jmp 0x29f0
movl -0x20(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x20(%rbp)
jmp 0x2417
movq -0xc0(%rbp), %rdi
callq 0x2070
movq -0x38(%rbp), %rdi
callq 0x2030
movq -0x50(%rbp), %rdi
callq 0x2030
addq $0xe0, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)