// File: /workspace/github_cpp_makefile_star2_O1/JohnPapad[P]Mini-Search-Engine/minisearch.cpp
// Function: parse_docs(char**, _IO_FILE*)
bool parse_docs(char **docs, FILE * fp)
{// storing docfile's lines into docs array - checking docfile for errors
    char * line = NULL;
    size_t len = 0;
    ssize_t nchars;
    int line_index = 0;

    while ((nchars = getline(&line, &len, fp)) != -1)
    {
        if ( line[nchars - 1] == '\n')
        { // removing newline character from string
            line[nchars - 1] = '\0';
            nchars--;
        }

        char *content;
        char *line_id_str = strtok_r(line, " \t", &content);

        if(line_id_str == NULL)
        { // checking if there is a line id
            cout<<"-! ERROR line is empty (without id) !-"<<endl;
            free(line);
            return 1;
        }

        int line_id = strtol(line_id_str, NULL, 10);

        if(is_number(line_id_str) == 1)
        { //checking if line id is a number
            if(line_id != line_index)
            { //checking if indexing is correct
                cout<<"-! ERROR at line indexing !-"<<endl;
                free(line);
                return 1;
            }
        }
        else
        {
            cout<<"-! ERROR line id is not a number !-"<<endl;
            free(line);
            return 1;
        }

        docs[line_index] = (char *) malloc((strlen(content) + 1) * sizeof(char));  //plus one for \0
        strcpy(docs[line_index], content);  //storing docfile's line into doc array
        line_index++;
    }

    free(line);
    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rsi, %rbx
movq %rdi, 0x10(%rsp)
xorl %r12d, %r12d
leaq 0x8(%rsp), %rax
movq %r12, (%rax)
leaq 0x20(%rsp), %rax
movq %r12, (%rax)
movq 0x526c(%rip), %r14      # 0x7fd0
leaq 0x8(%rsp), %rdi
leaq 0x20(%rsp), %rsi
movq %rbx, %rdx
callq 0x2160
movq %rax, %r13
movq 0x8(%rsp), %rdi
cmpq $-0x1, %rax
je 0x2eb4
cmpb $0xa, -0x1(%rdi,%r13)
jne 0x2d96
movb $0x0, -0x1(%rdi,%r13)
movq 0x8(%rsp), %rdi
leaq 0x2496(%rip), %rsi      # 0x5238
leaq 0x18(%rsp), %rdx
callq 0x2280
testq %rax, %rax
je 0x2e41
movq %rax, %r15
movq %rax, %rdi
xorl %esi, %esi
movl $0xa, %edx
callq 0x21a0
movq %rax, %rbp
movq %r15, %rdi
callq 0x2050
testq %rax, %rax
sete %cl
je 0x2e04
movsbl (%r15), %edx
addl $-0x30, %edx
cmpl $0x9, %edx
ja 0x2e04
movl $0x1, %edx
movl %edx, %edx
cmpq %rdx, %rax
setbe %cl
jbe 0x2e04
movsbl (%r15,%rdx), %esi
addl $-0x30, %esi
incl %edx
cmpl $0xa, %esi
jb 0x2deb
testb %cl, %cl
je 0x2e52
cmpl %ebp, %r12d
jne 0x2e63
movq 0x18(%rsp), %r15
movq %r15, %rdi
callq 0x2050
leaq 0x1(%rax), %rdi
callq 0x2170
movslq %r12d, %rcx
movq 0x10(%rsp), %rdx
movq %rax, (%rdx,%rcx,8)
movq %rax, %rdi
movq %r15, %rsi
callq 0x20c0
incl %r12d
movb $0x1, %al
jmp 0x2eaa
movl $0x26, %edx
movq %r14, %rdi
leaq 0x23eb(%rip), %rsi      # 0x523b
jmp 0x2e72
movl $0x23, %edx
movq %r14, %rdi
leaq 0x241e(%rip), %rsi      # 0x527f
jmp 0x2e72
movl $0x1c, %edx
movq %r14, %rdi
leaq 0x23f0(%rip), %rsi      # 0x5262
callq 0x2120
movq (%r14), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x20d0
movsbl %al, %esi
movq %r14, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x20a0
movq 0x8(%rsp), %rdi
callq 0x2140
xorl %eax, %eax
testb %al, %al
jne 0x2d64
jmp 0x2eb9
callq 0x2140
cmpq $-0x1, %r13
setne %al
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq