// File: /workspace/github_cpp_makefile_star2_O3/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 0x5e44(%rip), %rdi      # 0xa320
leaq 0x5ead(%rip), %rsi      # 0xa390
callq 0x5676
leaq -0x230(%rbp), %rdi
callq 0x3480
movq 0x5ad5(%rip), %rdi      # 0x9fd0
leaq 0x2d85(%rip), %rsi      # 0x7287
movl $0x22, %edx
callq 0x3330
movq 0x5e5d(%rip), %rsi      # 0xa370
movq 0x5e5e(%rip), %rdx      # 0xa378
movq 0x5aaf(%rip), %rdi      # 0x9fd0
callq 0x3330
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x32f0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x3030
movq %rax, %rdi
callq 0x3200
callq 0x33a0
movq %rax, -0x30(%rbp)
leaq 0x5e10(%rip), %rsi      # 0xa370
leaq -0x230(%rbp), %rdi
movl $0x10, %edx
callq 0x3170
leaq 0x5d80(%rip), %r14      # 0xa2f8
leaq -0x230(%rbp), %r15
leaq 0x2d29(%rip), %r12      # 0x72af
leaq 0x2d25(%rip), %r13      # 0x72b2
movq (%r14), %r14
testq %r14, %r14
je 0x45ee
movl $0x4, %edx
movq %r15, %rdi
leaq 0x2d06(%rip), %rsi      # 0x72aa
callq 0x3330
movq 0x8(%r14), %rsi
movq 0x10(%r14), %rdx
movq %r15, %rdi
callq 0x3330
movq %rax, %rbx
movl $0x2, %edx
movq %rax, %rdi
movq %r12, %rsi
callq 0x3330
movq 0x28(%r14), %rsi
movq 0x30(%r14), %rdx
movq %rbx, %rdi
callq 0x3330
movl $0x2, %edx
movq %rax, %rdi
movq %r13, %rsi
callq 0x3330
jmp 0x458d
cmpq $0x0, 0x5d62(%rip)      # 0xa358
je 0x463e
leaq 0x2cb6(%rip), %rsi      # 0x72b5
leaq -0x230(%rbp), %rdi
movl $0x7, %edx
callq 0x3330
movq 0x5d39(%rip), %rsi      # 0xa350
movq 0x5d3a(%rip), %rdx      # 0xa358
leaq -0x230(%rbp), %rdi
callq 0x3330
leaq 0x2b82(%rip), %rsi      # 0x71b3
movl $0x1, %edx
movq %rax, %rdi
callq 0x3330
leaq -0x230(%rbp), %rdi
callq 0x3200
leaq -0x230(%rbp), %rdi
callq 0x33e0
callq 0x33a0
movq %rax, %rbx
movq 0x596b(%rip), %rdi      # 0x9fd0
leaq 0x2c51(%rip), %rsi      # 0x72bd
movl $0x1f, %edx
callq 0x3330
subq -0x30(%rbp), %rbx
movabsq $0x431bde82d7b634db, %rcx # imm = 0x431BDE82D7B634DB
movq %rbx, %rax
imulq %rcx
movq %rdx, %rsi
shrq $0x3f, %rsi
sarq $0x12, %rdx
addq %rdx, %rsi
movq 0x5931(%rip), %rdi      # 0x9fd0
callq 0x32d0
movq %rax, %rbx
leaq 0x2b93(%rip), %rsi      # 0x7241
movl $0x3, %edx
movq %rax, %rdi
callq 0x3330
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x32f0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x3030
movq %rax, %rdi
callq 0x3200
leaq 0x5ca7(%rip), %rdi      # 0xa390
callq 0x3230
leaq 0x5c2b(%rip), %rdi      # 0xa320
callq 0x3230
movq 0x58c7(%rip), %rax      # 0x9fc8
movq (%rax), %rcx
movq 0x18(%rax), %rax
leaq -0x228(%rbp), %rdi
movq %rcx, -0x8(%rdi)
movq -0x18(%rcx), %rcx
movq %rax, -0x230(%rbp,%rcx)
callq 0x3260
leaq -0x138(%rbp), %rdi
callq 0x3100
addq $0x208, %rsp            # imm = 0x208
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x474a
jmp 0x474a
jmp 0x474a
jmp 0x474a
movq %rax, %rbx
leaq -0x230(%rbp), %rdi
callq 0x3420
movq %rbx, %rdi
callq 0x34a0