// File: /workspace/github_c_makefile_star2_O3/gplessis[P]dotdeb-redis/src/rdb.c
// Function: rdbSave
int rdbSave(char *filename) {
    char tmpfile[256];
    char cwd[MAXPATHLEN]; /* Current working dir path for error messages. */
    FILE *fp;
    rio rdb;
    int error = 0;

    snprintf(tmpfile,256,"temp-%d.rdb", (int) getpid());
    fp = fopen(tmpfile,"w");
    if (!fp) {
        char *cwdp = getcwd(cwd,MAXPATHLEN);
        serverLog(LL_WARNING,
            "Failed opening the RDB file %s (in server root dir %s) "
            "for saving: %s",
            filename,
            cwdp ? cwdp : "unknown",
            strerror(errno));
        return C_ERR;
    }

    rioInitWithFile(&rdb,fp);
    if (rdbSaveRio(&rdb,&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) {
        char *cwdp = getcwd(cwd,MAXPATHLEN);
        serverLog(LL_WARNING,
            "Error moving temp DB file %s on the final "
            "destination %s (in server root dir %s): %s",
            tmpfile,
            filename,
            cwdp ? cwdp : "unknown",
            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 %r15
pushq %r14
pushq %rbx
subq $0x1180, %rsp           # imm = 0x1180
movq %rdi, %rbx
movl $0x0, 0xc(%rsp)
callq 0x26420
leaq 0x79521(%rip), %rdx     # 0xc2ad7
leaq 0x10(%rsp), %r14
movl $0x100, %esi            # imm = 0x100
movq %r14, %rdi
movl %eax, %ecx
xorl %eax, %eax
callq 0x26120
leaq 0x777f4(%rip), %rsi     # 0xc0dc7
movq %r14, %rdi
callq 0x26ae0
testq %rax, %rax
je 0x496a5
movq %rax, %r14
leaq 0x118(%rsp), %r15
movq %r15, %rdi
movq %rax, %rsi
callq 0x726c2
leaq 0xc(%rsp), %rsi
movq %r15, %rdi
callq 0x490f7
cmpl $-0x1, %eax
je 0x496ef
movq %r14, %rdi
callq 0x26ce0
cmpl $-0x1, %eax
je 0x496fa
movq %r14, %rdi
callq 0x26070
movl %eax, %edi
callq 0x26600
cmpl $-0x1, %eax
je 0x496fa
movq %r14, %rdi
callq 0x26a10
cmpl $-0x1, %eax
je 0x496fa
leaq 0x10(%rsp), %rdi
movq %rbx, %rsi
callq 0x26ca0
cmpl $-0x1, %eax
je 0x49742
leaq 0x79517(%rip), %rsi     # 0xc2b7e
xorl %ebx, %ebx
movl $0x2, %edi
xorl %eax, %eax
callq 0x2fdad
leaq 0xb822c(%rip), %r14     # 0x1018a8
movq $0x0, 0x720(%r14)
xorl %edi, %edi
callq 0x26cd0
movq %rax, 0x758(%r14)
movl $0x0, 0x780(%r14)
jmp 0x49733
leaq 0x180(%rsp), %rdi
movl $0x1000, %esi           # imm = 0x1000
callq 0x26910
testq %rax, %rax
leaq 0x77722(%rip), %r14     # 0xc0de3
cmovneq %rax, %r14
callq 0x26880
movl (%rax), %edi
callq 0x26680
leaq 0x7940b(%rip), %rsi     # 0xc2ae3
movl $0x3, %edi
movq %rbx, %rdx
movq %r14, %rcx
movq %rax, %r8
xorl %eax, %eax
callq 0x2fdad
jmp 0x4972e
movl 0xc(%rsp), %ebx
callq 0x26880
movl %ebx, (%rax)
callq 0x26880
movl (%rax), %edi
callq 0x26680
leaq 0x79482(%rip), %rsi     # 0xc2b8f
movl $0x3, %edi
movq %rax, %rdx
xorl %eax, %eax
callq 0x2fdad
movq %r14, %rdi
callq 0x26a10
leaq 0x10(%rsp), %rdi
callq 0x263b0
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
movl %ebx, %eax
addq $0x1180, %rsp           # imm = 0x1180
popq %rbx
popq %r14
popq %r15
retq
leaq 0x180(%rsp), %rdi
movl $0x1000, %esi           # imm = 0x1000
callq 0x26910
testq %rax, %rax
leaq 0x77685(%rip), %r14     # 0xc0de3
cmovneq %rax, %r14
callq 0x26880
movl (%rax), %edi
callq 0x26680
leaq 0x793b4(%rip), %rsi     # 0xc2b29
leaq 0x10(%rsp), %r15
movl $0x3, %edi
movq %r15, %rdx
movq %rbx, %rcx
movq %r14, %r8
movq %rax, %r9
xorl %eax, %eax
callq 0x2fdad
movq %r15, %rdi
jmp 0x49729