// File: /workspace/github_cpp_makefile_star2_O1/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 0x5e32(%rip), %rdi      # 0xa320
leaq 0x5e9b(%rip), %rsi      # 0xa390
callq 0x569e
leaq -0x230(%rbp), %rdi
callq 0x3480
movq 0x5ac3(%rip), %rdi      # 0x9fd0
leaq 0x2d73(%rip), %rsi      # 0x7287
movl $0x22, %edx
callq 0x3330
movq 0x5e4b(%rip), %rsi      # 0xa370
movq 0x5e4c(%rip), %rdx      # 0xa378
movq 0x5a9d(%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 0x5dfe(%rip), %rsi      # 0xa370
leaq -0x230(%rbp), %rdi
movl $0x10, %edx
callq 0x3170
leaq 0x5d6e(%rip), %r14      # 0xa2f8
leaq -0x230(%rbp), %r15
leaq 0x2d17(%rip), %r12      # 0x72af
leaq 0x2d13(%rip), %r13      # 0x72b2
movq (%r14), %r14
testq %r14, %r14
je 0x4600
movl $0x4, %edx
movq %r15, %rdi
leaq 0x2cf4(%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 0x459f
cmpq $0x0, 0x5d50(%rip)      # 0xa358
je 0x4650
leaq 0x2ca4(%rip), %rsi      # 0x72b5
leaq -0x230(%rbp), %rdi
movl $0x7, %edx
callq 0x3330
movq 0x5d27(%rip), %rsi      # 0xa350
movq 0x5d28(%rip), %rdx      # 0xa358
leaq -0x230(%rbp), %rdi
callq 0x3330
leaq 0x2b70(%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 0x5959(%rip), %rdi      # 0x9fd0
leaq 0x2c3f(%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 0x591f(%rip), %rdi      # 0x9fd0
callq 0x32d0
movq %rax, %rbx
leaq 0x2b81(%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 0x5c95(%rip), %rdi      # 0xa390
callq 0x3230
leaq 0x5c19(%rip), %rdi      # 0xa320
callq 0x3230
movq 0x58b5(%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 0x475c
jmp 0x475c
jmp 0x475c
jmp 0x475c
movq %rax, %rbx
leaq -0x230(%rbp), %rdi
callq 0x3420
movq %rbx, %rdi
callq 0x34a0