// File: /workspace/github_cpp_makefile_star2_O2/MITRECND[P]snugglefish/src/fileIndexer.cpp
// Function: snugglefish::fileIndexer::processFile(char const*)
vector<uint32_t>* fileIndexer::processFile(const char* fileName){

    vector<uint32_t>* ngramList = 0;
    file* inputFile = new file(fileName);
    size_t fileSize = inputFile->get_size();
    uint8_t* inputFileMap = inputFile->mmap();

    if (!fileSize){
        delete inputFile;
        return NULL;
    } 


    this->filesProcessed++;

    //It is much faster to just use an array that holds a boolean
    //for every element, this requires only ~64MB per file for 3-byte Ngrams
    //but 16GB for 4 byte ngrams, so only do this for 3-byte ngrams
    //and do a map instead for 4-byte
    if(this->ngramLength == 3){
        ngramList = new vector<uint32_t>;
        bool* bngramList = new bool[this->maxNgram]();

        try{
            processNgrams(inputFileMap, fileSize, bngramList);

            for(uint32_t k = 0; k < this->maxNgram; k++){
                if(bngramList[k]){
                    ngramList->push_back(k);
                }
            }
            
            delete[] bngramList;

        } catch(exception &e){
            cout << "Error processing ngrams: "<< e.what() << endl;
        }

    }else{ //ngramLength == 4
        try {
            ngramList = processNgrams(inputFileMap, fileSize);
        } catch(exception &e){
            cout << "Error processing ngrams: " << e.what() << endl;
        }
    }

    inputFile->close();
    delete inputFile;

    return ngramList;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rsi, %rbx
movq %rdi, %r15
pushq $0x40
popq %rdi
callq 0x6280
movq %rax, %r12
movl $0x10000000, %edx       # imm = 0x10000000
movq %rax, %rdi
movq %rbx, %rsi
callq 0x9820
movq %r12, %rdi
callq 0x9bbc
movq %rax, %rbx
movq %r12, %rdi
callq 0x9c30
testq %rbx, %rbx
je 0x917f
incq (%r15)
cmpl $0x3, 0x8(%r15)
jne 0x9197
movq %r12, -0x38(%rbp)
pushq $0x18
popq %rdi
movq %rax, -0x48(%rbp)
callq 0x6280
movq %rax, %r14
xorps %xmm0, %xmm0
movups %xmm0, (%rax)
andq $0x0, 0x10(%rax)
movq 0x10(%r15), %rdi
movq %rdi, -0x40(%rbp)
callq 0x6030
movq %rax, %r12
xorl %r13d, %r13d
movq %rax, %rdi
xorl %esi, %esi
movq -0x40(%rbp), %rdx
callq 0x6170
movq %r15, %rdi
movq -0x48(%rbp), %rsi
movq %rbx, %rdx
movq %r12, %rcx
callq 0x92b6
leaq -0x2c(%rbp), %rbx
movl %r13d, -0x2c(%rbp)
movl %r13d, %eax
cmpq %rax, 0x10(%r15)
jbe 0x91aa
cmpb $0x1, (%r12,%rax)
jne 0x917a
movq %r14, %rdi
movq %rbx, %rsi
callq 0x9496
movl -0x2c(%rbp), %r13d
incl %r13d
jmp 0x9157
movq %r12, %rdi
callq 0x987c
pushq $0x40
popq %rsi
movq %r12, %rdi
callq 0x6290
xorl %r14d, %r14d
jmp 0x91d1
movq %r15, %rdi
movq %rax, %rsi
movq %rbx, %rdx
callq 0x935c
movq %rax, %r14
jmp 0x91b6
movq %r12, %rdi
callq 0x6330
movq -0x38(%rbp), %r12
movq %r12, %rdi
callq 0x98c8
movq %r12, %rdi
callq 0x987c
pushq $0x40
popq %rsi
movq %r12, %rdi
callq 0x6290
movq %r14, %rax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %r15
cmpl $0x1, %edx
jne 0x924c
movq %r15, %rdi
callq 0x60d0
movq %rax, %rbx
movq 0x5db3(%rip), %rdi      # 0xefb0
leaq 0x2526(%rip), %rsi      # 0xb72a
callq 0x6270
movq %rax, %r14
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x10(%rax)
movq %r14, %rdi
movq %rax, %rsi
callq 0x6270
movq %rax, %rdi
callq 0x6110
callq 0x6430
xorl %r14d, %r14d
jmp 0x91b6
movq %rax, %r15
callq 0x6430
jmp 0x924c
jmp 0x9254
movq %rax, %r15
pushq $0x40
popq %rsi
movq %r12, %rdi
callq 0x6290
movq %r15, %rdi
callq 0x64b0
movq %rax, %r15
cmpl $0x1, %edx
jne 0x924c
movq %r15, %rdi
callq 0x60d0
movq %rax, %rbx
movq 0x5d42(%rip), %rdi      # 0xefb0
leaq 0x24b5(%rip), %rsi      # 0xb72a
callq 0x6270
movq %rax, %r15
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x10(%rax)
movq %r15, %rdi
movq %rax, %rsi
callq 0x6270
movq %rax, %rdi
callq 0x6110
callq 0x6430
jmp 0x91b2
movq %rax, %r15
callq 0x6430
jmp 0x924c
movq %rax, %rdi
callq 0x777b
nop