// File: /workspace/github_cpp_makefile_star2_O1/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 $0x18, %rsp
movq %rsi, %rbx
movq %rdi, %r15
movl $0x40, %edi
callq 0x5280
movq %rax, %r12
movl $0x10000000, %edx       # imm = 0x10000000
movq %rax, %rdi
movq %rbx, %rsi
callq 0x92e8
movq %r12, %rdi
callq 0x96c4
movq %rax, %r13
movq %r12, %rdi
callq 0x973a
testq %r13, %r13
je 0x8c9b
incq (%r15)
cmpl $0x3, 0x8(%r15)
jne 0x8ca0
movq %r12, -0x38(%rbp)
movl $0x18, %edi
movq %rax, -0x40(%rbp)
callq 0x5280
movq %rax, %r14
xorps %xmm0, %xmm0
movups %xmm0, (%rax)
movq $0x0, 0x10(%rax)
movq 0x10(%r15), %rbx
movq %rbx, %rdi
callq 0x5030
movq %rax, %r12
movq %rax, %rdi
xorl %esi, %esi
movq %rbx, %rdx
callq 0x5160
movq %r15, %rdi
movq -0x40(%rbp), %rsi
movq %r13, %rdx
movq %r12, %rcx
callq 0x8dc4
movl $0x0, -0x2c(%rbp)
cmpq $0x0, 0x10(%r15)
je 0x8c8d
xorl %eax, %eax
leaq -0x2c(%rbp), %r13
cmpb $0x1, (%r12,%rax)
jne 0x8c7f
movq 0x8(%r14), %rsi
cmpq 0x10(%r14), %rsi
je 0x8c74
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x8(%r14)
jmp 0x8c7f
movq %r14, %rdi
movq %r13, %rdx
callq 0x904c
movl -0x2c(%rbp), %eax
incl %eax
movl %eax, -0x2c(%rbp)
cmpq %rax, 0x10(%r15)
ja 0x8c57
movq %r12, %rdi
callq 0x5340
movq -0x38(%rbp), %r12
jmp 0x8cb1
xorl %r14d, %r14d
jmp 0x8cb9
movq %r15, %rdi
movq %rax, %rsi
movq %r13, %rdx
callq 0x8e7a
movq %rax, %r14
movq %r12, %rdi
callq 0x9398
movq %r12, %rdi
callq 0x9344
movl $0x40, %esi
movq %r12, %rdi
callq 0x5290
movq %r14, %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %r15
cmpl $0x1, %edx
jne 0x8d54
movq %r15, %rdi
callq 0x50e0
movq %rax, %rbx
movq 0x62b6(%rip), %rdi      # 0xefb0
leaq 0x2a29(%rip), %rsi      # 0xb72a
movl $0x19, %edx
callq 0x52c0
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x10(%rax)
movq 0x6295(%rip), %rdi      # 0xefb0
movq %rax, %rsi
callq 0x5270
movq %rax, %rdi
callq 0x5100
callq 0x5460
xorl %r14d, %r14d
jmp 0x8cb1
movq %rax, %r15
callq 0x5460
jmp 0x8d54
jmp 0x8d5c
movq %rax, %r15
movl $0x40, %esi
movq %r12, %rdi
callq 0x5290
movq %r15, %rdi
callq 0x54e0
movq %rax, %r15
cmpl $0x1, %edx
jne 0x8d54
movq %r15, %rdi
callq 0x50e0
movq %rax, %rbx
movq 0x623a(%rip), %rdi      # 0xefb0
leaq 0x29ad(%rip), %rsi      # 0xb72a
movl $0x19, %edx
callq 0x52c0
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x10(%rax)
movq 0x6219(%rip), %rdi      # 0xefb0
movq %rax, %rsi
callq 0x5270
movq %rax, %rdi
callq 0x5100
callq 0x5460
jmp 0x8c95
movq %rax, %r15
callq 0x5460
jmp 0x8d54
movq %rax, %rdi
callq 0x7002
nop