// File: MITRECND[P]snugglefish/src/nGramBase.cpp
// Function: snugglefish::nGramBase::nGramBase(unsigned int, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>)
nGramBase::nGramBase( uint32_t ngramLength, string indexFileName)
    {

    if(ngramLength == 3 || ngramLength == 4){
        this->ngramLength = ngramLength;
        this->maxNgram = (uint64_t) (1) << (8*ngramLength);
    }
    else {
        throw std::runtime_error("Ngram len must be 3 or 4");
    }



    size_t pos;
    string baseFileName = indexFileName;
    // Check to see if the index file ends with any of the extentions we use
    // And if so, remove them to get the base filename
    pos = baseFileName.rfind( NGRAM_FILE_EXTENSION );
    // Make sure that it is at the end of the string
    if(pos == (baseFileName.size() - 6)){
        baseFileName = baseFileName.substr(0, pos);
    } else{
        pos = baseFileName.rfind( INDEX_FILE_EXTENSION );
        if(pos == (baseFileName.size() - 6)){
            baseFileName = baseFileName.substr(0, pos);
        } else{
            pos = baseFileName.rfind( FILEID_FILE_EXTENSION );
            if(pos == (baseFileName.size() - 6)){
            baseFileName = baseFileName.substr(0, pos);
            }
        }
    }


    this->baseFileName = baseFileName;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x100, %rsp            # imm = 0x100
movq %rdx, -0xc8(%rbp)
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movq %rdx, -0x18(%rbp)
movq -0x8(%rbp), %rdi
movq %rdi, -0xc0(%rbp)
addq $0x8, %rdi
movq %rdi, -0xb8(%rbp)
callq 0xe470
cmpl $0x3, -0xc(%rbp)
je 0x12494
cmpl $0x4, -0xc(%rbp)
jne 0x124ba
movq -0xc0(%rbp), %rax
movl -0xc(%rbp), %ecx
movb %cl, 0x28(%rax)
movl -0xc(%rbp), %ecx
shll $0x3, %ecx
movl %ecx, %ecx
movl $0x1, %edx
shlq %cl, %rdx
movq %rdx, %rcx
movq %rcx, 0x30(%rax)
jmp 0x1252c
movl $0x10, %edi
callq 0xe170
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0xd0(%rbp)
leaq 0x81fb(%rip), %rsi      # 0x1a6d3
callq 0xe100
jmp 0x124df
movq -0xd0(%rbp), %rdi
movq 0xeb03(%rip), %rsi      # 0x20ff0
movq 0xeab4(%rip), %rdx      # 0x20fa8
callq 0xe5b0
jmp 0x12732
movq -0xd0(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
callq 0xe230
jmp 0x1271d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
jmp 0x1271d
movq -0xc8(%rbp), %rsi
leaq -0x50(%rbp), %rdi
callq 0xe130
jmp 0x1253e
leaq 0x81a7(%rip), %rsi      # 0x1a6ec
leaq -0x50(%rbp), %rdi
movq $-0x1, %rdx
callq 0xe5a0
movq %rax, -0xd8(%rbp)
jmp 0x1255e
movq -0xd8(%rbp), %rax
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rax
movq %rax, -0xe0(%rbp)
leaq -0x50(%rbp), %rdi
callq 0xe210
movq %rax, %rcx
movq -0xe0(%rbp), %rax
subq $0x6, %rcx
cmpq %rcx, %rax
jne 0x125dc
movq -0x30(%rbp), %rcx
xorl %eax, %eax
movl %eax, %edx
leaq -0x70(%rbp), %rdi
leaq -0x50(%rbp), %rsi
callq 0xe320
jmp 0x125a7
leaq -0x50(%rbp), %rdi
leaq -0x70(%rbp), %rsi
callq 0xe3e0
leaq -0x70(%rbp), %rdi
callq 0xe1d0
jmp 0x126f5
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
leaq -0x50(%rbp), %rdi
callq 0xe1d0
jmp 0x1271d
leaq 0x8110(%rip), %rsi      # 0x1a6f3
leaq -0x50(%rbp), %rdi
movq $-0x1, %rdx
callq 0xe5a0
movq %rax, -0xe8(%rbp)
jmp 0x125fc
movq -0xe8(%rbp), %rax
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rax
movq %rax, -0xf0(%rbp)
leaq -0x50(%rbp), %rdi
callq 0xe210
movq %rax, %rcx
movq -0xf0(%rbp), %rax
subq $0x6, %rcx
cmpq %rcx, %rax
jne 0x12669
movq -0x30(%rbp), %rcx
xorl %eax, %eax
movl %eax, %edx
leaq -0x90(%rbp), %rdi
leaq -0x50(%rbp), %rsi
callq 0xe320
jmp 0x12648
leaq -0x50(%rbp), %rdi
leaq -0x90(%rbp), %rsi
callq 0xe3e0
leaq -0x90(%rbp), %rdi
callq 0xe1d0
jmp 0x126f3
leaq 0x808a(%rip), %rsi      # 0x1a6fa
leaq -0x50(%rbp), %rdi
movq $-0x1, %rdx
callq 0xe5a0
movq %rax, -0xf8(%rbp)
jmp 0x12689
movq -0xf8(%rbp), %rax
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rax
movq %rax, -0x100(%rbp)
leaq -0x50(%rbp), %rdi
callq 0xe210
movq %rax, %rcx
movq -0x100(%rbp), %rax
subq $0x6, %rcx
cmpq %rcx, %rax
jne 0x126f1
movq -0x30(%rbp), %rcx
xorl %eax, %eax
movl %eax, %edx
leaq -0xb0(%rbp), %rdi
leaq -0x50(%rbp), %rsi
callq 0xe320
jmp 0x126d5
leaq -0x50(%rbp), %rdi
leaq -0xb0(%rbp), %rsi
callq 0xe3e0
leaq -0xb0(%rbp), %rdi
callq 0xe1d0
jmp 0x126f3
jmp 0x126f5
movq -0xc0(%rbp), %rdi
addq $0x8, %rdi
leaq -0x50(%rbp), %rsi
callq 0xe040
jmp 0x1270b
leaq -0x50(%rbp), %rdi
callq 0xe1d0
addq $0x100, %rsp            # imm = 0x100
popq %rbp
retq
movq -0xb8(%rbp), %rdi
callq 0xe1d0
movq -0x20(%rbp), %rdi
callq 0xe5d0
nopw %cs:(%rax,%rax)
nopl (%rax)