// File: /workspace/github_c_makefile_star2_O1/zhou-yuxin[P]redis-aof-no-cow/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 0x26430
leaq 0x78e9d(%rip), %rdx     # 0xc5a57
leaq 0x10(%rsp), %r14
movl $0x100, %esi            # imm = 0x100
movq %r14, %rdi
movl %eax, %ecx
xorl %eax, %eax
callq 0x26120
leaq 0x771a0(%rip), %rsi     # 0xc3d77
movq %r14, %rdi
callq 0x26af0
testq %rax, %rax
je 0x4cca9
movq %rax, %r14
leaq 0x118(%rsp), %r15
movq %r15, %rdi
movq %rax, %rsi
callq 0x76172
leaq 0xc(%rsp), %rsi
movq %r15, %rdi
callq 0x4c631
cmpl $-0x1, %eax
je 0x4ccf3
movq %r14, %rdi
callq 0x26cf0
cmpl $-0x1, %eax
je 0x4ccfe
movq %r14, %rdi
callq 0x26070
movl %eax, %edi
callq 0x26610
cmpl $-0x1, %eax
je 0x4ccfe
movq %r14, %rdi
callq 0x26a20
cmpl $-0x1, %eax
je 0x4ccfe
leaq 0x10(%rsp), %rdi
movq %rbx, %rsi
callq 0x26cb0
cmpl $-0x1, %eax
je 0x4cd46
leaq 0x78e93(%rip), %rsi     # 0xc5afe
xorl %ebx, %ebx
movl $0x2, %edi
xorl %eax, %eax
callq 0x32ea6
leaq 0xb9bd8(%rip), %r14     # 0x106858
movq $0x0, 0x710(%r14)
xorl %edi, %edi
callq 0x26ce0
movq %rax, 0x748(%r14)
movl $0x0, 0x770(%r14)
jmp 0x4cd37
leaq 0x180(%rsp), %rdi
movl $0x1000, %esi           # imm = 0x1000
callq 0x26920
testq %rax, %rax
leaq 0x770ce(%rip), %r14     # 0xc3d93
cmovneq %rax, %r14
callq 0x26890
movl (%rax), %edi
callq 0x26690
leaq 0x78d87(%rip), %rsi     # 0xc5a63
movl $0x3, %edi
movq %rbx, %rdx
movq %r14, %rcx
movq %rax, %r8
xorl %eax, %eax
callq 0x32ea6
jmp 0x4cd32
movl 0xc(%rsp), %ebx
callq 0x26890
movl %ebx, (%rax)
callq 0x26890
movl (%rax), %edi
callq 0x26690
leaq 0x78dfe(%rip), %rsi     # 0xc5b0f
movl $0x3, %edi
movq %rax, %rdx
xorl %eax, %eax
callq 0x32ea6
movq %r14, %rdi
callq 0x26a20
leaq 0x10(%rsp), %rdi
callq 0x263c0
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 0x26920
testq %rax, %rax
leaq 0x77031(%rip), %r14     # 0xc3d93
cmovneq %rax, %r14
callq 0x26890
movl (%rax), %edi
callq 0x26690
leaq 0x78d30(%rip), %rsi     # 0xc5aa9
leaq 0x10(%rsp), %r15
movl $0x3, %edi
movq %r15, %rdx
movq %rbx, %rcx
movq %r14, %r8
movq %rax, %r9
xorl %eax, %eax
callq 0x32ea6
movq %r15, %rdi
jmp 0x4cd2d