// File: /workspace/github_c_makefile_star2_O1/zhou-yuxin[P]redis-aof-no-cow/src/rdb.c
// Function: rdbSaveRio
int rdbSaveRio(rio *rdb, int *error) {
    dictIterator *di = NULL;
    dictEntry *de;
    char magic[10];
    int j;
    long long now = mstime();
    uint64_t cksum;

    if (server.rdb_checksum)
        rdb->update_cksum = rioGenericUpdateChecksum;
    snprintf(magic,sizeof(magic),"REDIS%04d",RDB_VERSION);
    if (rdbWriteRaw(rdb,magic,9) == -1) goto werr;
    if (rdbSaveInfoAuxFields(rdb) == -1) goto werr;

    for (j = 0; j < server.dbnum; j++) {
        redisDb *db = server.db+j;
        dict *d = db->dict;
        if (dictSize(d) == 0) continue;
        di = dictGetSafeIterator(d);
        if (!di) return C_ERR;

        /* Write the SELECT DB opcode */
        if (rdbSaveType(rdb,RDB_OPCODE_SELECTDB) == -1) goto werr;
        if (rdbSaveLen(rdb,j) == -1) goto werr;

        /* Write the RESIZE DB opcode. We trim the size to UINT32_MAX, which
         * is currently the largest type we are able to represent in RDB sizes.
         * However this does not limit the actual size of the DB to load since
         * these sizes are just hints to resize the hash tables. */
        uint32_t db_size, expires_size;
        db_size = (dictSize(db->dict) <= UINT32_MAX) ?
                                dictSize(db->dict) :
                                UINT32_MAX;
        expires_size = (dictSize(db->expires) <= UINT32_MAX) ?
                                dictSize(db->expires) :
                                UINT32_MAX;
        if (rdbSaveType(rdb,RDB_OPCODE_RESIZEDB) == -1) goto werr;
        if (rdbSaveLen(rdb,db_size) == -1) goto werr;
        if (rdbSaveLen(rdb,expires_size) == -1) goto werr;

        /* Iterate this DB writing every entry */
        while((de = dictNext(di)) != NULL) {
            sds keystr = dictGetKey(de);
            robj key, *o = dictGetVal(de);
            long long expire;

            initStaticStringObject(key,keystr);
            expire = getExpire(db,&key);
            if (rdbSaveKeyValuePair(rdb,&key,o,expire,now) == -1) goto werr;
        }
        dictReleaseIterator(di);
    }
    di = NULL; /* So that we don't release it again on error. */

    /* EOF opcode */
    if (rdbSaveType(rdb,RDB_OPCODE_EOF) == -1) goto werr;

    /* CRC64 checksum. It will be zero if checksum computation is disabled, the
     * loading code skips the check in this case. */
    cksum = rdb->cksum;
    memrev64ifbe(&cksum);
    if (rioWrite(rdb,&cksum,8) == 0) goto werr;
    return C_OK;

werr:
    if (error) *error = errno;
    if (di) dictReleaseIterator(di);
    return C_ERR;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %rsi, %r13
movq %rdi, %r14
callq 0x330c8
movq %rax, 0x30(%rsp)
leaq 0xba202(%rip), %rax     # 0x106858
cmpl $0x0, 0x744(%rax)
je 0x4c66a
leaq 0x29bd7(%rip), %rax     # 0x7623d
movq %rax, 0x20(%r14)
leaq 0x793d6(%rip), %rdx     # 0xc5a47
xorl %r12d, %r12d
leaq 0x3e(%rsp), %rbx
movl $0xa, %esi
movq %rbx, %rdi
movl $0x7, %ecx
xorl %eax, %eax
callq 0x26120
movl $0x9, %edx
movq %r14, %rdi
movq %rbx, %rsi
callq 0x4ad7c
cmpl $-0x1, %eax
je 0x4c933
movq %r14, %rdi
callq 0x4c5a8
cmpl $-0x1, %eax
je 0x4c91a
movq %r13, 0x18(%rsp)
leaq 0xba195(%rip), %rcx     # 0x106858
cmpl $0x0, 0x600(%rcx)
jle 0x4c881
xorl %r13d, %r13d
xorl %r12d, %r12d
movq 0x28(%rcx), %rbx
movq %r13, %r15
shlq $0x6, %r15
movq (%rbx,%r15), %rdi
movq 0x28(%rdi), %rax
movl $0x5, %ebp
addq 0x48(%rdi), %rax
je 0x4c848
callq 0x320e5
testq %rax, %rax
je 0x4c839
movq %rax, %r12
movb $-0x2, 0x8(%rsp)
movl $0x1, %edx
movq %r14, %rdi
leaq 0x8(%rsp), %rsi
callq 0x4ad7c
movl $0x2, %ebp
cmpl $-0x1, %eax
je 0x4c841
movq %r14, %rdi
movl %r13d, %esi
callq 0x4b054
cmpl $-0x1, %eax
je 0x4c841
addq %r15, %rbx
movq (%rbx), %rax
movq 0x8(%rbx), %rcx
movq 0x28(%rax), %rdx
movq %rdx, 0x28(%rsp)
movq 0x48(%rcx), %rdx
addq 0x28(%rcx), %rdx
movq 0x48(%rax), %rax
movq %rax, (%rsp)
movq %rdx, %rax
movq %rdx, 0x20(%rsp)
shrq $0x20, %rax
negq %rax
movl $0x0, %r15d
sbbl %r15d, %r15d
movb $-0x5, 0x8(%rsp)
movl $0x1, %edx
movq %r14, %rdi
leaq 0x8(%rsp), %rsi
callq 0x4ad7c
cmpl $-0x1, %eax
je 0x4c841
movq (%rsp), %rcx
addq 0x28(%rsp), %rcx
movq %rcx, %rax
shrq $0x20, %rax
negq %rax
movl $0x0, %esi
sbbl %esi, %esi
orl %ecx, %esi
movq %r14, %rdi
callq 0x4b054
cmpl $-0x1, %eax
je 0x4c841
orl 0x20(%rsp), %r15d
movq %r14, %rdi
movl %r15d, %esi
callq 0x4b054
cmpl $-0x1, %eax
je 0x4c841
movq %r14, (%rsp)
movq %r12, %rdi
callq 0x32116
testq %rax, %rax
je 0x4c86a
movq (%rax), %rcx
movq 0x8(%rax), %r15
movl $0x1, 0xc(%rsp)
movb $0x0, 0x8(%rsp)
movq %rcx, 0x10(%rsp)
movq %rbx, %rdi
movq %r12, %r14
leaq 0x8(%rsp), %r12
movq %r12, %rsi
callq 0x46484
movq (%rsp), %rdi
movq %r12, %rsi
movq %r14, %r12
movq %r15, %rdx
movq %rax, %rcx
movq 0x30(%rsp), %r8
callq 0x4c3f6
cmpl $-0x1, %eax
jne 0x4c7df
jmp 0x4c874
movl $0x1, %ebp
xorl %r12d, %r12d
leaq 0xba010(%rip), %rcx     # 0x106858
testl %ebp, %ebp
je 0x4c855
cmpl $0x5, %ebp
jne 0x4c91f
incq %r13
movslq 0x600(%rcx), %rax
cmpq %rax, %r13
jl 0x4c6d6
jmp 0x4c881
movq %r12, %rdi
callq 0x321d3
xorl %ebp, %ebp
leaq 0xb9fdd(%rip), %rcx     # 0x106858
movq (%rsp), %r14
jmp 0x4c848
leaq 0x8(%rsp), %rbx
movb $-0x1, (%rbx)
movl $0x1, %edx
movq %r14, %rdi
movq %rbx, %rsi
callq 0x4ad7c
cmpl $-0x1, %eax
je 0x4c92b
movq 0x28(%r14), %rax
movq %rax, 0x8(%rsp)
movl $0x8, %ecx
movq 0x18(%rsp), %r13
testq %rcx, %rcx
je 0x4c966
movq %rcx, %r12
movq 0x20(%r14), %rax
movq 0x38(%r14), %rcx
cmpq %r12, %rcx
movq %r12, %r15
cmovbq %rcx, %r15
testq %rcx, %rcx
cmoveq %r12, %r15
testq %rax, %rax
je 0x4c8ea
movq %r14, %rdi
movq %rbx, %rsi
movq %r15, %rdx
callq *%rax
movq %r14, %rdi
movq %rbx, %rsi
movq %r15, %rdx
callq *0x8(%r14)
testq %rax, %rax
je 0x4c90b
addq %r15, %rbx
movq %r12, %rcx
subq %r15, %rcx
addq %r15, 0x30(%r14)
jmp 0x4c90e
movq %r12, %rcx
testq %rax, %rax
jne 0x4c8b5
xorl %ebx, %ebx
testq %r12, %r12
je 0x4c955
xorl %r12d, %r12d
jmp 0x4c933
cmpl $0x2, %ebp
je 0x4c92e
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
jmp 0x4c955
xorl %r12d, %r12d
movq 0x18(%rsp), %r13
testq %r13, %r13
je 0x4c943
callq 0x26890
movl (%rax), %eax
movl %eax, (%r13)
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
testq %r12, %r12
je 0x4c955
movq %r12, %rdi
callq 0x321d3
movl %ebx, %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
xorl %ebx, %ebx
jmp 0x4c955