// File: /workspace/github_c_makefile_star2_O1/erikdubbelboer[P]discnt/src/ddb.c
// Function: ddbSave
int ddbSave(char *filename) {
    char tmpfile[256];
    FILE *fp;
    rio ddb;
    int error = 0;

    snprintf(tmpfile,256,"temp-%d.ddb", (int) getpid());
    fp = fopen(tmpfile,"w");
    if (!fp) {
        serverLog(LL_WARNING, "Failed opening .ddb for saving: %s",
            strerror(errno));
        return C_ERR;
    }

    rioInitWithFile(&ddb,fp);
    if (ddbSaveRio(&ddb,&error) == C_ERR) {
        errno = error;
        goto werr;
    }

    /* Make sure data will not remain on the OS's output buffers */
    if (fflush(fp) == EOF) goto werr;
    if (fsync(fileno(fp)) == -1) goto werr;
    if (fclose(fp) == EOF) goto werr;

    /* Use RENAME to make sure the DB file is changed atomically only
     * if the generate DB file is ok. */
    if (rename(tmpfile,filename) == -1) {
        serverLog(LL_WARNING,"Error moving temp DB file on the final destination: %s", strerror(errno));
        unlink(tmpfile);
        return C_ERR;
    }
    serverLog(LL_NOTICE,"DB saved on disk");
    server.dirty = 0;
    server.lastsave = time(NULL);
    server.lastbgsave_status = C_OK;
    return C_OK;

werr:
    serverLog(LL_WARNING,"Write error saving DB on disk: %s", strerror(errno));
    fclose(fp);
    unlink(tmpfile);
    return C_ERR;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %rbx
subq $0x178, %rsp            # imm = 0x178
movq %rdi, %r14
movl $0x0, 0xc(%rsp)
callq 0x121f0
leaq 0x25ac7(%rip), %rdx     # 0x58af7
leaq 0x10(%rsp), %rbx
movl $0x100, %esi            # imm = 0x100
movq %rbx, %rdi
movl %eax, %ecx
xorl %eax, %eax
callq 0x122d0
leaq 0x2246c(%rip), %rsi     # 0x554b9
movq %rbx, %rdi
callq 0x12500
testq %rax, %rax
je 0x3311c
movq %rax, %rbx
leaq 0x110(%rsp), %r15
movq %r15, %rdi
movq %rax, %rsi
callq 0x33b9e
leaq 0xc(%rsp), %rsi
movq %r15, %rdi
callq 0x32e20
cmpl $-0x1, %eax
je 0x33140
movq %rbx, %rdi
callq 0x125e0
cmpl $-0x1, %eax
je 0x3314b
movq %rbx, %rdi
callq 0x12560
movl %eax, %edi
callq 0x12740
cmpl $-0x1, %eax
je 0x3314b
movq %rbx, %rdi
callq 0x12220
cmpl $-0x1, %eax
je 0x3314b
leaq 0x10(%rsp), %rdi
movq %r14, %rsi
callq 0x127b0
cmpl $-0x1, %eax
je 0x33194
leaq 0x25a7c(%rip), %rsi     # 0x58b5d
xorl %ebx, %ebx
movl $0x2, %edi
xorl %eax, %eax
callq 0x19fb1
leaq 0x3bf92(%rip), %r14     # 0x6f088
movq $0x0, 0x6a0(%r14)
xorl %edi, %edi
callq 0x12550
movq %rax, 0x6d8(%r14)
movl $0x0, 0x6fc(%r14)
jmp 0x33184
callq 0x120d0
movl (%rax), %edi
callq 0x128f0
leaq 0x259d4(%rip), %rsi     # 0x58b03
movl $0x3, %edi
movq %rax, %rdx
xorl %eax, %eax
callq 0x19fb1
jmp 0x3317f
movl 0xc(%rsp), %ebp
callq 0x120d0
movl %ebp, (%rax)
callq 0x120d0
movl (%rax), %edi
callq 0x128f0
leaq 0x25a10(%rip), %rsi     # 0x58b6e
movl $0x3, %edi
movq %rax, %rdx
xorl %eax, %eax
callq 0x19fb1
movq %rbx, %rdi
callq 0x12220
leaq 0x10(%rsp), %rdi
callq 0x120f0
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
movl %ebx, %eax
addq $0x178, %rsp            # imm = 0x178
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
callq 0x120d0
movl (%rax), %edi
callq 0x128f0
leaq 0x2597f(%rip), %rsi     # 0x58b26
movl $0x3, %edi
movq %rax, %rdx
xorl %eax, %eax
callq 0x19fb1
jmp 0x33175