// File: /workspace/github_cpp_makefile_star2_O2/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x208, %rsp            # imm = 0x208
leaq 0x527b(%rip), %rdi      # 0x92f0
leaq 0x52e4(%rip), %rsi      # 0x9360
callq 0x4c7b
leaq -0x230(%rbp), %rdi
callq 0x3430
movq 0x4f34(%rip), %rdi      # 0x8fc8
leaq 0x21ec(%rip), %rsi      # 0x6287
callq 0x32e0
leaq 0x5299(%rip), %rsi      # 0x9340
movq %rax, %rdi
callq 0x3270
movq %rax, %rdi
callq 0x3180
callq 0x3380
movq %rax, -0x30(%rbp)
leaq 0x5279(%rip), %rsi      # 0x9340
leaq -0x230(%rbp), %rdi
pushq $0x10
popq %rdx
callq 0x3170
leaq 0x51eb(%rip), %rbx      # 0x92c8
leaq 0x21c6(%rip), %r14      # 0x62aa
leaq -0x230(%rbp), %r15
leaq 0x21bd(%rip), %r12      # 0x62af
leaq 0x21b9(%rip), %r13      # 0x62b2
movq (%rbx), %rbx
testq %rbx, %rbx
je 0x413c
movq %r15, %rdi
movq %r14, %rsi
callq 0x32e0
leaq 0x8(%rbx), %rsi
movq %rax, %rdi
callq 0x3270
movq %rax, %rdi
movq %r12, %rsi
callq 0x32e0
leaq 0x28(%rbx), %rsi
movq %rax, %rdi
callq 0x3270
movq %rax, %rdi
movq %r13, %rsi
callq 0x32e0
jmp 0x40f9
cmpq $0x0, 0x51e4(%rip)      # 0x9328
je 0x4177
leaq 0x2168(%rip), %rsi      # 0x62b5
leaq -0x230(%rbp), %rdi
callq 0x32e0
leaq 0x51c0(%rip), %rsi      # 0x9320
movq %rax, %rdi
callq 0x3270
leaq 0x2044(%rip), %rsi      # 0x61b3
movq %rax, %rdi
callq 0x32e0
leaq -0x230(%rbp), %rdi
callq 0x3210
leaq -0x230(%rbp), %rdi
callq 0x33b0
callq 0x3380
movq %rax, %r14
movq 0x4e2a(%rip), %rdi      # 0x8fc8
leaq 0x2118(%rip), %rsi      # 0x62bd
callq 0x32e0
movq %rax, %rdi
subq -0x30(%rbp), %r14
movl $0xf4240, %ecx          # imm = 0xF4240
movq %r14, %rax
cqto
idivq %rcx
movq %rax, %rsi
callq 0x32c0
leaq 0x2074(%rip), %rsi      # 0x6241
movq %rax, %rdi
callq 0x32e0
movq %rax, %rdi
callq 0x3180
leaq 0x517c(%rip), %rdi      # 0x9360
callq 0x3230
leaq 0x5100(%rip), %rdi      # 0x92f0
callq 0x3230
leaq -0x230(%rbp), %rdi
callq 0x33f0
addq $0x208, %rsp            # imm = 0x208
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x421b
jmp 0x421b
jmp 0x421b
jmp 0x421b
movq %rax, %rbx
leaq -0x230(%rbp), %rdi
callq 0x33f0
movq %rbx, %rdi
callq 0x3450