// File: AutomataLab[P]JSONSki/src/RecordLoader.cpp
// Function: RecordLoader::loadSingleRecord(char*)
Record* RecordLoader::loadSingleRecord(char* file_path) {
    unsigned long size;
    FILE* fp = fopen (file_path,"rb");
    if (fp == NULL) {
        return NULL;
    }
    fseek (fp, 0, SEEK_END);
    size = ftell(fp);
    rewind(fp);
    void* p;
    if (posix_memalign(&p, 64, (size + MAX_PAD)*sizeof(char)) != 0) {
        cout<<"Fail to allocate memory space for input record."<<endl;
    }
    char* record_text = (char*) p;
    size_t load_size = fread (record_text, 1, size, fp);
    if (load_size == 0) {
        cout<<"Fail to load the input record into memory"<<endl;
    }
    int remain = 64 - (size % 64);
    int counter = 0;
    // pad the input data where its size can be divided by 64
    while (counter < remain)
    {
        record_text[size+counter] = 'd';
        counter++;
    }
    record_text[size+counter]='\0';
    fclose(fp);
    // only one single record
    Record* record = new Record();
    record->text = record_text;
    record->rec_start_pos = 0;
    record->rec_length = strlen(record_text);
    return record;
}

// Assembly:
subq $0x68, %rsp
movq %rdi, 0x58(%rsp)
movq 0x58(%rsp), %rdi
leaq 0xa089c(%rip), %rsi     # 0x103041
callq 0x13240
movq %rax, 0x48(%rsp)
cmpq $0x0, 0x48(%rsp)
jne 0x627c5
movq $0x0, 0x60(%rsp)
jmp 0x6296c
movq 0x48(%rsp), %rdi
xorl %eax, %eax
movl %eax, %esi
movl $0x2, %edx
callq 0x131a0
movq 0x48(%rsp), %rdi
callq 0x130f0
movq %rax, 0x50(%rsp)
movq 0x48(%rsp), %rdi
callq 0x13470
movq 0x50(%rsp), %rdx
addq $0x40, %rdx
shlq $0x0, %rdx
leaq 0x40(%rsp), %rdi
movl $0x40, %esi
callq 0x13130
cmpl $0x0, %eax
je 0x62834
leaq 0xdbc67(%rip), %rdi     # 0x13e480
leaq 0xa0824(%rip), %rsi     # 0x103044
callq 0xccb00
movq %rax, %rdi
leaq 0x69bb1(%rip), %rsi     # 0xcc3e0
callq 0xcb5f0
movq 0x40(%rsp), %rax
movq %rax, 0x38(%rsp)
movq 0x38(%rsp), %rdi
movq 0x50(%rsp), %rdx
movq 0x48(%rsp), %rcx
movl $0x1, %esi
callq 0x13520
movq %rax, 0x30(%rsp)
cmpq $0x0, 0x30(%rsp)
jne 0x62886
leaq 0xdbc15(%rip), %rdi     # 0x13e480
leaq 0xa0802(%rip), %rsi     # 0x103074
callq 0xccb00
movq %rax, %rdi
leaq 0x69b5f(%rip), %rsi     # 0xcc3e0
callq 0xcb5f0
movq 0x50(%rsp), %rcx
andq $0x3f, %rcx
movl $0x40, %eax
subq %rcx, %rax
movl %eax, 0x2c(%rsp)
movl $0x0, 0x28(%rsp)
movl 0x28(%rsp), %eax
cmpl 0x2c(%rsp), %eax
jge 0x628d0
movq 0x38(%rsp), %rax
movq 0x50(%rsp), %rcx
movslq 0x28(%rsp), %rdx
addq %rdx, %rcx
movb $0x64, (%rax,%rcx)
movl 0x28(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x28(%rsp)
jmp 0x628a3
movq 0x38(%rsp), %rax
movq 0x50(%rsp), %rcx
movslq 0x28(%rsp), %rdx
addq %rdx, %rcx
movb $0x0, (%rax,%rcx)
movq 0x48(%rsp), %rdi
callq 0x13600
movl $0x20, %edi
callq 0x647b0
movq %rax, %rdi
movq %rdi, %rax
movq %rax, 0x8(%rsp)
callq 0x62d90
jmp 0x6290c
movq 0x8(%rsp), %rax
movq %rax, 0x20(%rsp)
movq 0x38(%rsp), %rcx
movq 0x20(%rsp), %rax
movq %rcx, (%rax)
movq 0x20(%rsp), %rax
movq $0x0, 0x8(%rax)
movq 0x38(%rsp), %rdi
callq 0x13370
movq %rax, %rcx
movq 0x20(%rsp), %rax
movq %rcx, 0x10(%rax)
movq 0x20(%rsp), %rax
movq %rax, 0x60(%rsp)
jmp 0x6296c
movq 0x8(%rsp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x18(%rsp)
movl %eax, 0x14(%rsp)
callq 0x63910
jmp 0x62976
movq 0x60(%rsp), %rax
addq $0x68, %rsp
retq
movq 0x18(%rsp), %rdi
callq 0x13710