// File: /workspace/github_c_makefile_star2_O0/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 %rbp
movq %rsp, %rbp
subq $0x11e0, %rsp           # imm = 0x11E0
movq %rdi, -0x10(%rbp)
movl $0x0, -0x1184(%rbp)
leaq -0x110(%rbp), %rax
movq %rax, -0x11a0(%rbp)
callq 0x26420
movq -0x11a0(%rbp), %rdi
movl %eax, %ecx
movl $0x100, %esi            # imm = 0x100
leaq 0xe81d9(%rip), %rdx     # 0x13d26a
movb $0x0, %al
callq 0x26120
leaq -0x110(%rbp), %rdi
leaq 0xe675b(%rip), %rsi     # 0x13b801
callq 0x26ae0
movq %rax, -0x1118(%rbp)
cmpq $0x0, -0x1118(%rbp)
jne 0x55157
leaq -0x1110(%rbp), %rdi
movl $0x1000, %esi           # imm = 0x1000
callq 0x26910
movq %rax, -0x1190(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x11a8(%rbp)
cmpq $0x0, -0x1190(%rbp)
je 0x550fd
movq -0x1190(%rbp), %rax
movq %rax, -0x11b0(%rbp)
jmp 0x5510d
leaq 0xe6719(%rip), %rax     # 0x13b81d
movq %rax, -0x11b0(%rbp)
jmp 0x5510d
movq -0x11b0(%rbp), %rax
movq %rax, -0x11b8(%rbp)
callq 0x26880
movl (%rax), %edi
callq 0x26690
movq -0x11a8(%rbp), %rdx
movq -0x11b8(%rbp), %rcx
movq %rax, %r8
movl $0x3, %edi
leaq 0xe8132(%rip), %rsi     # 0x13d276
movb $0x0, %al
callq 0x2fc60
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x55354
movq -0x1118(%rbp), %rsi
leaq -0x1180(%rbp), %rdi
callq 0x8e620
leaq -0x1180(%rbp), %rdi
leaq -0x1184(%rbp), %rsi
callq 0x54b20
cmpl $-0x1, %eax
jne 0x551a0
movl -0x1184(%rbp), %eax
movl %eax, -0x11bc(%rbp)
callq 0x26880
movl -0x11bc(%rbp), %ecx
movl %ecx, (%rax)
jmp 0x55313
movq -0x1118(%rbp), %rdi
callq 0x26cf0
cmpl $-0x1, %eax
jne 0x551b6
jmp 0x55313
movq -0x1118(%rbp), %rdi
callq 0x26070
movl %eax, %edi
callq 0x26610
cmpl $-0x1, %eax
jne 0x551d3
jmp 0x55313
movq -0x1118(%rbp), %rdi
callq 0x26a10
cmpl $-0x1, %eax
jne 0x551e9
jmp 0x55313
leaq -0x110(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x26cb0
cmpl $-0x1, %eax
jne 0x552ba
leaq -0x1110(%rbp), %rdi
movl $0x1000, %esi           # imm = 0x1000
callq 0x26910
movq %rax, -0x1198(%rbp)
leaq -0x110(%rbp), %rax
movq %rax, -0x11d0(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x11c8(%rbp)
cmpq $0x0, -0x1198(%rbp)
je 0x5524d
movq -0x1198(%rbp), %rax
movq %rax, -0x11d8(%rbp)
jmp 0x5525d
leaq 0xe65c9(%rip), %rax     # 0x13b81d
movq %rax, -0x11d8(%rbp)
jmp 0x5525d
movq -0x11d8(%rbp), %rax
movq %rax, -0x11e0(%rbp)
callq 0x26880
movl (%rax), %edi
callq 0x26690
movq -0x11d0(%rbp), %rdx
movq -0x11c8(%rbp), %rcx
movq -0x11e0(%rbp), %r8
movq %rax, %r9
movl $0x3, %edi
leaq 0xe8021(%rip), %rsi     # 0x13d2bc
movb $0x0, %al
callq 0x2fc60
leaq -0x110(%rbp), %rdi
callq 0x263b0
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x55354
movl $0x2, %edi
leaq 0xe804b(%rip), %rsi     # 0x13d311
movb $0x0, %al
callq 0x2fc60
leaq 0x122f04(%rip), %rax    # 0x1781d8
movq $0x0, 0x720(%rax)
xorl %eax, %eax
movl %eax, %edi
callq 0x26ce0
movq %rax, %rcx
leaq 0x122ee6(%rip), %rax    # 0x1781d8
movq %rcx, 0x758(%rax)
leaq 0x122ed8(%rip), %rax    # 0x1781d8
movl $0x0, 0x780(%rax)
movl $0x0, -0x4(%rbp)
jmp 0x55354
callq 0x26880
movl (%rax), %edi
callq 0x26690
movq %rax, %rdx
movl $0x3, %edi
leaq 0xe7ff4(%rip), %rsi     # 0x13d322
movb $0x0, %al
callq 0x2fc60
movq -0x1118(%rbp), %rdi
callq 0x26a10
leaq -0x110(%rbp), %rdi
callq 0x263b0
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
movl -0x4(%rbp), %eax
addq $0x11e0, %rsp           # imm = 0x11E0
popq %rbp
retq