// File: Lartu[P]coraldb/source/checkpoint.cpp
// Function: save_datafile()
void save_datafile()
{
    //TODO compress checkpoint data
    std::lock(global_db_mutex, checkpoint_file_mutex);
    std::ofstream db_file;
    std::cout << "CoralDB: Performing checkpoint to " << global_filename << std::endl;
    std::chrono::steady_clock::time_point begin = std::chrono::steady_clock::now();
    db_file.open(global_filename);
    // Here we just use \n because we are going to load the values with getline
    for (auto &it : global_db)
    {
        db_file << "SET " << it.first << " \"" << it.second << "\"\n";
    }
    if (!database_key.empty())
    {
        db_file << "SETKEY " << database_key << "\n";
    }
    db_file.flush();
    db_file.close();
    std::chrono::steady_clock::time_point end = std::chrono::steady_clock::now();
    std::cout << "CoralDB: Checkpoint performed: " << std::chrono::duration_cast<std::chrono::milliseconds>(end - begin).count() << " ms" << std::endl;
    checkpoint_file_mutex.unlock();
    global_db_mutex.unlock();
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x2c0, %rsp            # imm = 0x2C0
leaq 0xc81e(%rip), %rdi      # 0x11360
leaq 0xc887(%rip), %rsi      # 0x113d0
callq 0x64c0
leaq -0x200(%rbp), %rdi
callq 0x34e0
movq 0xc467(%rip), %rdi      # 0x10fc8
leaq 0x6702(%rip), %rsi      # 0xb26a
callq 0x3300
movq %rax, -0x258(%rbp)
jmp 0x4b76
movq -0x258(%rbp), %rdi
leaq 0xc82c(%rip), %rsi      # 0x113b0
callq 0x32a0
movq %rax, -0x260(%rbp)
jmp 0x4b92
movq -0x260(%rbp), %rdi
movq 0xc408(%rip), %rsi      # 0x10fa8
callq 0x3320
jmp 0x4ba7
callq 0x33e0
movq %rax, -0x218(%rbp)
leaq 0xc7f6(%rip), %rsi      # 0x113b0
leaq -0x200(%rbp), %rdi
movl $0x10, %edx
callq 0x31b0
jmp 0x4bcd
leaq 0xc754(%rip), %rax      # 0x11328
movq %rax, -0x220(%rbp)
leaq 0xc746(%rip), %rdi      # 0x11328
callq 0x6560
movq %rax, -0x228(%rbp)
leaq 0xc733(%rip), %rdi      # 0x11328
callq 0x6010
movq %rax, -0x230(%rbp)
leaq -0x228(%rbp), %rdi
leaq -0x230(%rbp), %rsi
callq 0x6110
testb $0x1, %al
jne 0x4c1d
jmp 0x4cef
leaq -0x228(%rbp), %rdi
callq 0x6590
movq %rax, -0x238(%rbp)
leaq 0x6656(%rip), %rsi      # 0xb28d
leaq -0x200(%rbp), %rdi
callq 0x3300
movq %rax, -0x268(%rbp)
jmp 0x4c4c
movq -0x268(%rbp), %rdi
movq -0x238(%rbp), %rsi
callq 0x32a0
movq %rax, -0x270(%rbp)
jmp 0x4c68
movq -0x270(%rbp), %rdi
leaq 0x661c(%rip), %rsi      # 0xb292
callq 0x3300
movq %rax, -0x278(%rbp)
jmp 0x4c84
movq -0x278(%rbp), %rdi
movq -0x238(%rbp), %rsi
addq $0x20, %rsi
callq 0x32a0
movq %rax, -0x280(%rbp)
jmp 0x4ca4
movq -0x280(%rbp), %rdi
leaq 0x65e3(%rip), %rsi      # 0xb295
callq 0x3300
jmp 0x4cb9
jmp 0x4cbb
leaq -0x228(%rbp), %rdi
callq 0x65c0
jmp 0x4c01
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x208(%rbp)
movl %eax, -0x20c(%rbp)
leaq -0x200(%rbp), %rdi
callq 0x3480
jmp 0x4e72
leaq 0xc69a(%rip), %rdi      # 0x11390
callq 0x34d0
testb $0x1, %al
jne 0x4d4e
leaq 0x6592(%rip), %rsi      # 0xb298
leaq -0x200(%rbp), %rdi
callq 0x3300
movq %rax, -0x288(%rbp)
jmp 0x4d1b
movq -0x288(%rbp), %rdi
leaq 0xc667(%rip), %rsi      # 0x11390
callq 0x32a0
movq %rax, -0x290(%rbp)
jmp 0x4d37
movq -0x290(%rbp), %rdi
leaq 0x6451(%rip), %rsi      # 0xb196
callq 0x3300
jmp 0x4d4c
jmp 0x4d4e
leaq -0x200(%rbp), %rdi
callq 0x3240
jmp 0x4d5c
leaq -0x200(%rbp), %rdi
callq 0x3440
jmp 0x4d6a
callq 0x33e0
movq %rax, -0x240(%rbp)
movq 0xc24b(%rip), %rdi      # 0x10fc8
leaq 0x651c(%rip), %rsi      # 0xb2a0
callq 0x3300
movq %rax, -0x298(%rbp)
jmp 0x4d92
leaq -0x240(%rbp), %rdi
leaq -0x218(%rbp), %rsi
callq 0x6450
movq %rax, -0x2a0(%rbp)
jmp 0x4dae
movq -0x2a0(%rbp), %rax
movq %rax, -0x250(%rbp)
leaq -0x250(%rbp), %rdi
callq 0x6420
movq %rax, -0x2a8(%rbp)
jmp 0x4dd1
movq -0x2a8(%rbp), %rax
movq %rax, -0x248(%rbp)
leaq -0x248(%rbp), %rdi
callq 0x64a0
movq %rax, -0x2b0(%rbp)
jmp 0x4df4
movq -0x2b0(%rbp), %rsi
movq -0x298(%rbp), %rdi
callq 0x3530
movq %rax, -0x2b8(%rbp)
jmp 0x4e10
movq -0x2b8(%rbp), %rdi
leaq 0x6406(%rip), %rsi      # 0xb224
callq 0x3300
movq %rax, -0x2c0(%rbp)
jmp 0x4e2c
movq -0x2c0(%rbp), %rdi
movq 0xc16e(%rip), %rsi      # 0x10fa8
callq 0x3320
jmp 0x4e41
leaq 0xc588(%rip), %rdi      # 0x113d0
callq 0x60c0
jmp 0x4e4f
leaq 0xc50a(%rip), %rdi      # 0x11360
callq 0x60c0
jmp 0x4e5d
leaq -0x200(%rbp), %rdi
callq 0x3480
addq $0x2c0, %rsp            # imm = 0x2C0
popq %rbp
retq
movq -0x208(%rbp), %rdi
callq 0x3500
nop