// File: /workspace/github_cpp_makefile_star2_O3/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 $0x18, %rsp
movq %rsi, %rbx
movq %rdi, %r14
xorl %eax, %eax
movq %rsp, %rdi
movq %rax, (%rdi)
leaq 0x10(%rsp), %rsi
movq %rax, (%rsi)
movq %rbx, %rdx
callq 0x2160
cmpq $-0x1, %rax
je 0x2e23
xorl %r15d, %r15d
leaq 0x8(%rsp), %r12
movq (%rsp), %rdi
cmpb $0xa, -0x1(%rdi,%rax)
jne 0x2d7e
movb $0x0, -0x1(%rdi,%rax)
movq (%rsp), %rdi
leaq 0x24b3(%rip), %rsi      # 0x5238
movq %r12, %rdx
callq 0x2280
testq %rax, %rax
je 0x2e90
movq %rax, %r13
movq %rax, %rdi
xorl %esi, %esi
movl $0xa, %edx
callq 0x21a0
movq %rax, %rbp
movq %r13, %rdi
callq 0x2050
testq %rax, %rax
je 0x2dd6
movl $0x1, %ecx
xorl %edx, %edx
movsbl (%r13,%rdx), %edx
addl $-0x30, %edx
cmpl $0xa, %edx
jae 0x2e30
movl %ecx, %edx
incl %ecx
cmpq %rdx, %rax
ja 0x2dbf
movl %ebp, %eax
cmpq %rax, %r15
jne 0x2ea5
movq 0x8(%rsp), %r13
movq %r13, %rdi
callq 0x2050
leaq 0x1(%rax), %rdi
callq 0x2170
movq %rax, (%r14,%r15,8)
movq %rax, %rdi
movq %r13, %rsi
callq 0x20c0
incq %r15
movq %rsp, %rdi
leaq 0x10(%rsp), %rsi
movq %rbx, %rdx
callq 0x2160
cmpq $-0x1, %rax
jne 0x2d6a
movq (%rsp), %rdi
callq 0x2140
xorl %eax, %eax
jmp 0x2e81
movq 0x5199(%rip), %rdi      # 0x7fd0
leaq 0x2441(%rip), %rsi      # 0x527f
movl $0x23, %edx
callq 0x2120
movq 0x5181(%rip), %rbx      # 0x7fd0
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x20d0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x20a0
movq (%rsp), %rdi
callq 0x2140
movb $0x1, %al
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x5139(%rip), %rdi      # 0x7fd0
leaq 0x239d(%rip), %rsi      # 0x523b
movl $0x26, %edx
jmp 0x2e43
movq 0x5124(%rip), %rdi      # 0x7fd0
leaq 0x23af(%rip), %rsi      # 0x5262
movl $0x1c, %edx
jmp 0x2e43