// File: /workspace/github_c_makefile_star2_O2/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
andl $0x0, 0xc(%rsp)
callq 0x26420
leaq 0x72806(%rip), %rdx     # 0xb4197
leaq 0x10(%rsp), %r14
movl $0x100, %esi            # imm = 0x100
movq %r14, %rdi
movl %eax, %ecx
xorl %eax, %eax
callq 0x26120
leaq 0x70cf1(%rip), %rsi     # 0xb269f
movq %r14, %rdi
callq 0x26ae0
testq %rax, %rax
je 0x41a78
movq %rax, %r14
leaq 0x118(%rsp), %r15
movq %r15, %rdi
movq %rax, %rsi
callq 0x66ab5
leaq 0xc(%rsp), %rsi
movq %r15, %rdi
callq 0x415b1
cmpl $-0x1, %eax
je 0x41ac0
movq %r14, %rdi
callq 0x26ce0
cmpl $-0x1, %eax
je 0x41acb
movq %r14, %rdi
callq 0x26070
movl %eax, %edi
callq 0x26600
cmpl $-0x1, %eax
je 0x41acb
movq %r14, %rdi
callq 0x26a10
cmpl $-0x1, %eax
je 0x41acb
leaq 0x10(%rsp), %rdi
movq %rbx, %rsi
callq 0x26ca0
cmpl $-0x1, %eax
je 0x41b0f
leaq 0x727fc(%rip), %rsi     # 0xb423e
xorl %ebx, %ebx
pushq $0x2
popq %rdi
xorl %eax, %eax
callq 0x2b699
leaq 0xb7e53(%rip), %r14     # 0xf98a8
andq $0x0, 0x720(%r14)
xorl %edi, %edi
callq 0x26cd0
movq %rax, 0x758(%r14)
andl $0x0, 0x780(%r14)
jmp 0x41b00
leaq 0x180(%rsp), %rdi
movl $0x1000, %esi           # imm = 0x1000
callq 0x26910
testq %rax, %rax
leaq 0x70c27(%rip), %r14     # 0xb26bb
cmovneq %rax, %r14
callq 0x26880
movl (%rax), %edi
callq 0x26680
leaq 0x726f8(%rip), %rsi     # 0xb41a3
pushq $0x3
popq %rdi
movq %rbx, %rdx
movq %r14, %rcx
movq %rax, %r8
xorl %eax, %eax
callq 0x2b699
jmp 0x41afd
movl 0xc(%rsp), %ebx
callq 0x26880
movl %ebx, (%rax)
callq 0x26880
movl (%rax), %edi
callq 0x26680
leaq 0x72771(%rip), %rsi     # 0xb424f
pushq $0x3
popq %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0x2b699
movq %r14, %rdi
callq 0x26a10
leaq 0x10(%rsp), %rdi
callq 0x263b0
pushq $-0x1
popq %rbx
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 0x70b90(%rip), %r14     # 0xb26bb
cmovneq %rax, %r14
callq 0x26880
movl (%rax), %edi
callq 0x26680
leaq 0x726a7(%rip), %rsi     # 0xb41e9
pushq $0x3
popq %rdi
leaq 0x10(%rsp), %r15
movq %r15, %rdx
movq %rbx, %rcx
movq %r14, %r8
movq %rax, %r9
xorl %eax, %eax
callq 0x2b699
movq %r15, %rdi
jmp 0x41af8