// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x1a0, %rsp            # imm = 0x1A0
movq %rdi, -0x10(%rbp)
movl $0x0, -0x184(%rbp)
leaq -0x110(%rbp), %rax
movq %rax, -0x190(%rbp)
callq 0x121d0
movq -0x190(%rbp), %rdi
movl %eax, %ecx
movl $0x100, %esi            # imm = 0x100
leaq 0x6d75e(%rip), %rdx     # 0xa946f
movb $0x0, %al
callq 0x122c0
leaq -0x110(%rbp), %rdi
leaq 0x6a1b9(%rip), %rsi     # 0xa5edf
callq 0x124e0
movq %rax, -0x118(%rbp)
cmpq $0x0, -0x118(%rbp)
jne 0x3bd6a
callq 0x120b0
movl (%rax), %edi
callq 0x12900
movq %rax, %rdx
movl $0x3, %edi
leaq 0x6d724(%rip), %rsi     # 0xa947b
movb $0x0, %al
callq 0x18b10
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x3bee5
movq -0x118(%rbp), %rsi
leaq -0x180(%rbp), %rdi
callq 0x3cc50
leaq -0x180(%rbp), %rdi
leaq -0x184(%rbp), %rsi
callq 0x3b9d0
cmpl $-0x1, %eax
jne 0x3bdb3
movl -0x184(%rbp), %eax
movl %eax, -0x194(%rbp)
callq 0x120b0
movl -0x194(%rbp), %ecx
movl %ecx, (%rax)
jmp 0x3bea4
movq -0x118(%rbp), %rdi
callq 0x125c0
cmpl $-0x1, %eax
jne 0x3bdc9
jmp 0x3bea4
movq -0x118(%rbp), %rdi
callq 0x12540
movl %eax, %edi
callq 0x12720
cmpl $-0x1, %eax
jne 0x3bde6
jmp 0x3bea4
movq -0x118(%rbp), %rdi
callq 0x12200
cmpl $-0x1, %eax
jne 0x3bdfc
jmp 0x3bea4
leaq -0x110(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x12790
cmpl $-0x1, %eax
jne 0x3be4b
callq 0x120b0
movl (%rax), %edi
callq 0x12900
movq %rax, %rdx
movl $0x3, %edi
leaq 0x6d672(%rip), %rsi     # 0xa949e
movb $0x0, %al
callq 0x18b10
leaq -0x110(%rbp), %rdi
callq 0x120d0
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x3bee5
movl $0x2, %edi
leaq 0x6d67e(%rip), %rsi     # 0xa94d5
movb $0x0, %al
callq 0x18b10
leaq 0x83283(%rip), %rax     # 0xbf0e8
movq $0x0, 0x6a0(%rax)
xorl %eax, %eax
movl %eax, %edi
callq 0x12530
movq %rax, %rcx
leaq 0x83265(%rip), %rax     # 0xbf0e8
movq %rcx, 0x6d8(%rax)
leaq 0x83257(%rip), %rax     # 0xbf0e8
movl $0x0, 0x6fc(%rax)
movl $0x0, -0x4(%rbp)
jmp 0x3bee5
callq 0x120b0
movl (%rax), %edi
callq 0x12900
movq %rax, %rdx
movl $0x3, %edi
leaq 0x6d627(%rip), %rsi     # 0xa94e6
movb $0x0, %al
callq 0x18b10
movq -0x118(%rbp), %rdi
callq 0x12200
leaq -0x110(%rbp), %rdi
callq 0x120d0
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
movl -0x4(%rbp), %eax
addq $0x1a0, %rsp            # imm = 0x1A0
popq %rbp
retq
nopw %cs:(%rax,%rax)