// File: /workspace/github_cpp_makefile_star2_O3/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 0x92e4
movq %r12, %rdi
callq 0x96be
movq %rax, %r13
movq %r12, %rdi
callq 0x9734
testq %r13, %r13
je 0x8c90
incq (%r15)
cmpl $0x3, 0x8(%r15)
jne 0x8caa
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 0x8dce
movl $0x0, -0x2c(%rbp)
movq 0x10(%r15), %rax
testq %rax, %rax
je 0x8c82
xorl %ecx, %ecx
leaq -0x2c(%rbp), %r13
cmpb $0x1, (%r12,%rcx)
jne 0x8c75
movq 0x8(%r14), %rsi
cmpq 0x10(%r14), %rsi
je 0x8c66
movl %ecx, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x8(%r14)
jmp 0x8c75
movq %r14, %rdi
movq %r13, %rdx
callq 0x9056
movq 0x10(%r15), %rax
movl -0x2c(%rbp), %ecx
incl %ecx
movl %ecx, -0x2c(%rbp)
cmpq %rcx, %rax
ja 0x8c49
movq %r12, %rdi
callq 0x5340
movq -0x38(%rbp), %r12
jmp 0x8cbb
movq %r12, %rdi
callq 0x9340
movl $0x40, %esi
movq %r12, %rdi
callq 0x5290
xorl %r14d, %r14d
jmp 0x8cd8
movq %r15, %rdi
movq %rax, %rsi
movq %r13, %rdx
callq 0x8e84
movq %rax, %r14
movq %r12, %rdi
callq 0x9394
movq %r12, %rdi
callq 0x9340
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 0x8d5e
movq %r15, %rdi
callq 0x50e0
movq %rax, %rbx
movq 0x62ac(%rip), %rdi      # 0xefb0
leaq 0x2a1f(%rip), %rsi      # 0xb72a
movl $0x19, %edx
callq 0x52c0
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x10(%rax)
movq 0x628b(%rip), %rdi      # 0xefb0
movq %rax, %rsi
callq 0x5270
movq %rax, %rdi
callq 0x5100
callq 0x5460
xorl %r14d, %r14d
jmp 0x8cbb
movq %rax, %r15
callq 0x5460
jmp 0x8d5e
jmp 0x8d66
movq %rax, %r15
movl $0x40, %esi
movq %r12, %rdi
callq 0x5290
movq %r15, %rdi
callq 0x54e0
movq %rax, %r15
cmpl $0x1, %edx
jne 0x8d5e
movq %r15, %rdi
callq 0x50e0
movq %rax, %rbx
movq 0x6230(%rip), %rdi      # 0xefb0
leaq 0x29a3(%rip), %rsi      # 0xb72a
movl $0x19, %edx
callq 0x52c0
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x10(%rax)
movq 0x620f(%rip), %rdi      # 0xefb0
movq %rax, %rsi
callq 0x5270
movq %rax, %rdi
callq 0x5100
callq 0x5460
jmp 0x8c8a
movq %rax, %r15
callq 0x5460
jmp 0x8d5e
movq %rax, %rdi
callq 0x7007
nop