// File: momohatt[P]seccampDB/database.cpp
// Function: DataBase::DataBase(Scheduler*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>)
DataBase::DataBase(Scheduler* scheduler, string dumpfilename, string logfilename)
  : scheduler_(scheduler),
    dumpfilename_(dumpfilename),
    logfilename_(logfilename)
{
    LOG;
    scheduler_->set_db(this);

    // 前回のDBファイルをメモリに読み出し
    ifstream ifs_dump(dumpfilename);
    string str;

    while (getline(ifs_dump, str)) {
        if (str == "") continue;
        vector<string> fields = words(str);
        if (fields.size() != 2) {
            UNREACHABLE;
            exit(1);
        }
        table[fields[0]].value = stoi(fields[1]);
    }

    ifs_dump.close();

    // (必要なら) crash recovery
    recover();

    fd_log_ = open(logfilename.c_str(), O_WRONLY | O_TRUNC);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x2c0, %rsp            # imm = 0x2C0
movq %rdx, -0x280(%rbp)
movq %rcx, -0x298(%rbp)
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq -0x8(%rbp), %rdi
movq %rdi, -0x288(%rbp)
movq %rdi, %rax
movq %rax, -0x290(%rbp)
xorps %xmm0, %xmm0
movups %xmm0, 0x20(%rdi)
movups %xmm0, 0x10(%rdi)
movups %xmm0, (%rdi)
callq 0xa120
movq -0x288(%rbp), %rdi
movq -0x280(%rbp), %rsi
movq -0x10(%rbp), %rax
movq %rax, 0x30(%rdi)
addq $0x38, %rdi
movq %rdi, -0x278(%rbp)
callq 0x3150
jmp 0x71b9
movq -0x298(%rbp), %rsi
movq -0x290(%rbp), %rdi
addq $0x58, %rdi
movq %rdi, -0x2a0(%rbp)
callq 0x3150
jmp 0x71d9
movq -0x290(%rbp), %rax
movl $0x0, 0x7c(%rax)
leaq 0x1532a(%rip), %rdi     # 0x1c518
leaq 0x15348(%rip), %rsi     # 0x1c53d
xorl %eax, %eax
movl $0xdf, %edx
callq 0x3070
jmp 0x7203
movq -0x290(%rbp), %rsi
movq 0x30(%rsi), %rdi
callq 0xa140
jmp 0x7215
movq -0x280(%rbp), %rsi
leaq -0x238(%rbp), %rdi
movl $0x8, %edx
callq 0x34e0
jmp 0x722f
leaq -0x258(%rbp), %rdi
callq 0x3440
leaq -0x238(%rbp), %rdi
leaq -0x258(%rbp), %rsi
callq 0x30a0
movq %rax, -0x2a8(%rbp)
jmp 0x7257
movq -0x2a8(%rbp), %rdi
movq (%rdi), %rax
movq -0x18(%rax), %rax
addq %rax, %rdi
callq 0x3410
movb %al, -0x2a9(%rbp)
jmp 0x7275
movb -0x2a9(%rbp), %al
testb $0x1, %al
jne 0x7284
jmp 0x73d2
leaq 0x152ec(%rip), %rsi     # 0x1c577
leaq -0x258(%rbp), %rdi
callq 0x42c0
movb %al, -0x2aa(%rbp)
jmp 0x729f
movb -0x2aa(%rbp), %al
testb $0x1, %al
jne 0x72ab
jmp 0x72f1
jmp 0x723b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
jmp 0x7472
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
jmp 0x7466
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
jmp 0x745a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
jmp 0x7442
leaq -0x270(%rbp), %rdi
leaq -0x258(%rbp), %rsi
callq 0x39b0
jmp 0x7306
leaq -0x270(%rbp), %rdi
callq 0x4310
cmpq $0x2, %rax
je 0x7346
movq 0x24cb1(%rip), %rax     # 0x2bfd0
movq (%rax), %rdi
leaq 0x151bf(%rip), %rsi     # 0x1c4e8
leaq 0x1520d(%rip), %rdx     # 0x1c53d
movl $0xea, %ecx
movb $0x0, %al
callq 0x3470
movl $0x1, %edi
callq 0x33f0
leaq -0x270(%rbp), %rdi
movl $0x1, %esi
callq 0x42f0
movq %rax, %rdi
xorl %eax, %eax
movl %eax, %esi
movl $0xa, %edx
callq 0x4330
movl %eax, -0x2b0(%rbp)
jmp 0x7370
xorl %eax, %eax
movl %eax, %esi
leaq -0x270(%rbp), %rdi
callq 0x42f0
movq -0x290(%rbp), %rdi
movq %rax, %rsi
callq 0x96d0
movq %rax, -0x2b8(%rbp)
jmp 0x7398
movq -0x2b8(%rbp), %rax
movl -0x2b0(%rbp), %ecx
movl %ecx, (%rax)
leaq -0x270(%rbp), %rdi
callq 0x41e0
jmp 0x723b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
leaq -0x270(%rbp), %rdi
callq 0x41e0
jmp 0x7442
leaq -0x238(%rbp), %rdi
callq 0x30b0
jmp 0x73e0
movq -0x290(%rbp), %rdi
callq 0x7490
jmp 0x73ee
movq -0x298(%rbp), %rdi
callq 0x3140
movq %rax, %rdi
xorl %eax, %eax
movl $0x201, %esi            # imm = 0x201
callq 0x3260
movl %eax, -0x2bc(%rbp)
jmp 0x7411
movq -0x290(%rbp), %rax
movl -0x2bc(%rbp), %ecx
movl %ecx, 0x78(%rax)
leaq -0x258(%rbp), %rdi
callq 0x35f8
leaq -0x238(%rbp), %rdi
callq 0x30c0
addq $0x2c0, %rsp            # imm = 0x2C0
popq %rbp
retq
leaq -0x258(%rbp), %rdi
callq 0x35f8
leaq -0x238(%rbp), %rdi
callq 0x30c0
movq -0x2a0(%rbp), %rdi
callq 0x35f8
movq -0x278(%rbp), %rdi
callq 0x35f8
movq -0x288(%rbp), %rdi
callq 0xa160
movq -0x28(%rbp), %rdi
callq 0x3540
nopw (%rax,%rax)