// File: /workspace/github_cpp_makefile_star2_O2/MITRECND[P]snugglefish/src/indexSet.cpp
// Function: snugglefish::indexSet::create(unsigned int)
void indexSet::create(ngram_t_numfiles nFiles){
    if (indexFile || nGramFile){//Already opened?
        throw runtime_error("Error opening index or ngram file");
    }

    //Create the Files
    //First create the filenames
    string indexFileName, nGramFileName;
    indexFileName = nGramFileName = this->fileBase;
    char number_string[FILE_NUM_BUFFER_SIZE];
    snprintf(number_string, FILE_NUM_BUFFER_SIZE, FILE_NUM_SPRINTF_STRING, this->count);

    indexFileName.append(INDEX_FILE_EXTENSION).append(number_string);
    nGramFileName.append(NGRAM_FILE_EXTENSION).append(number_string);

    this->indexFile = new file(indexFileName.c_str());
    this->nGramFile = new file(nGramFileName.c_str());

    if(indexFile->exists() || nGramFile->exists()){ //Already exist?
       throw runtime_error("index file or ngram file already exists"); 
    }

    indexFile->create();
    nGramFile->create();

    
    this->endian_check = ENDIAN_CHECK;
    this->version = VERSION;

    //Write standard header
    indexFile->write((uint8_t*) (&(this->endian_check)), ENDIAN_CHECK_FIELD);
    indexFile->write((uint8_t*) (&(this->version)), VERSION_FIELD);
    indexFile->write((uint8_t*) (&(this->ngramLength)), NGRAM_SIZE_FIELD);
    indexFile->write((uint8_t*) (&nFiles), INDEX_HEADER_NUM_FILES_FIELD);

    offset = 0; //Offset in the ngramfile

    writable = true;

}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r14
pushq %rbx
subq $0x70, %rsp
movl %esi, -0x14(%rbp)
cmpq $0x0, (%rdi)
jne 0xa294
movq %rdi, %rbx
cmpq $0x0, 0x8(%rdi)
jne 0xa294
leaq -0x48(%rbp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
leaq -0x28(%rbp), %rcx
movq %rcx, -0x10(%rcx)
andq $0x0, -0x8(%rcx)
xorl %edx, %edx
movb %dl, (%rax)
movb %dl, (%rcx)
leaq 0x28(%rbx), %rsi
leaq -0x38(%rbp), %rdi
callq 0x6150
leaq -0x58(%rbp), %rdi
leaq -0x38(%rbp), %rsi
callq 0x6150
movl 0x58(%rbx), %ecx
leaq 0x173e(%rip), %rdx      # 0xb8a6
leaq -0x80(%rbp), %rdi
pushq $0x1e
popq %rsi
xorl %eax, %eax
callq 0x6400
leaq 0x1576(%rip), %rsi      # 0xb6f3
leaq -0x58(%rbp), %rdi
callq 0x6510
leaq -0x80(%rbp), %rsi
movq %rax, %rdi
callq 0x6510
leaq 0x1553(%rip), %rsi      # 0xb6ec
leaq -0x38(%rbp), %rdi
callq 0x6510
leaq -0x80(%rbp), %rsi
movq %rax, %rdi
callq 0x6510
pushq $0x40
popq %rdi
callq 0x6280
movq %rax, %r14
movq -0x58(%rbp), %rsi
movl $0x10000000, %edx       # imm = 0x10000000
movq %rax, %rdi
callq 0x9820
movq %r14, (%rbx)
pushq $0x40
popq %rdi
callq 0x6280
movq %rax, %r14
movq -0x38(%rbp), %rsi
movl $0x10000000, %edx       # imm = 0x10000000
movq %rax, %rdi
callq 0x9820
movq %r14, 0x8(%rbx)
movq (%rbx), %rdi
callq 0x9fb4
testb %al, %al
jne 0xa2c4
movq 0x8(%rbx), %rdi
callq 0x9fb4
testb %al, %al
jne 0xa2c4
movq (%rbx), %rdi
movl $0x1ed, %esi            # imm = 0x1ED
callq 0x99c2
movq 0x8(%rbx), %rdi
movl $0x1ed, %esi            # imm = 0x1ED
callq 0x99c2
leaq 0x4c(%rbx), %rsi
movl $0x1234567, 0x4c(%rbx)  # imm = 0x1234567
movb $0x1, 0x50(%rbx)
movq (%rbx), %rdi
pushq $0x4
popq %rdx
callq 0x9e0c
leaq 0x50(%rbx), %rsi
movq (%rbx), %rdi
pushq $0x1
popq %rdx
callq 0x9e0c
movq (%rbx), %rdi
leaq 0x51(%rbx), %rsi
pushq $0x1
popq %rdx
callq 0x9e0c
movq (%rbx), %rdi
leaq -0x14(%rbp), %rsi
pushq $0x4
popq %rdx
callq 0x9e0c
andq $0x0, 0x60(%rbx)
movb $0x1, 0x48(%rbx)
leaq -0x38(%rbp), %rdi
callq 0x60f0
leaq -0x58(%rbp), %rdi
callq 0x60f0
addq $0x70, %rsp
popq %rbx
popq %r14
popq %rbp
retq
pushq $0x10
popq %rdi
callq 0x6120
movq %rax, %r14
leaq 0x15de(%rip), %rsi      # 0xb884
movq %rax, %rdi
callq 0x60c0
movq 0x4d3b(%rip), %rsi      # 0xeff0
movq 0x4cec(%rip), %rdx      # 0xefa8
movq %r14, %rdi
callq 0x6480
pushq $0x10
popq %rdi
callq 0x6120
movq %rax, %r14
leaq 0x15d5(%rip), %rsi      # 0xb8ab
movq %rax, %rdi
callq 0x60c0
movq 0x4d0b(%rip), %rsi      # 0xeff0
movq 0x4cbc(%rip), %rdx      # 0xefa8
movq %r14, %rdi
callq 0x6480
movq %rax, %rbx
movq %r14, %rdi
callq 0x61d0
jmp 0xa325
jmp 0xa303
movq %rax, %rbx
pushq $0x40
popq %rsi
movq %r14, %rdi
callq 0x6290
jmp 0xa325
movq %rax, %rbx
movq %r14, %rdi
callq 0x61d0
jmp 0xa337
jmp 0xa322
movq %rax, %rbx
leaq -0x38(%rbp), %rdi
callq 0x60f0
leaq -0x58(%rbp), %rdi
callq 0x60f0
movq %rbx, %rdi
callq 0x64b0
nop