// File: /workspace/github_c_makefile_star2_O3/gplessis[P]dotdeb-redis/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, 0x8(%rsp)
movq %rdi, %r14
callq 0x2ffce
movq %rax, %r13
leaq 0xb878c(%rip), %r12     # 0x1018a8
cmpl $0x0, 0x754(%r12)
je 0x49132
leaq 0x2965f(%rip), %rax     # 0x7278d
movq %rax, 0x20(%r14)
leaq 0x7998e(%rip), %rdx     # 0xc2ac7
xorl %r15d, %r15d
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 0x47a98
cmpl $-0x1, %eax
je 0x4939c
movq %r14, %rdi
callq 0x4906e
cmpl $-0x1, %eax
je 0x49399
movl 0x610(%r12), %eax
testl %eax, %eax
jle 0x4931f
movq 0x28(%r12), %rbx
xorl %edx, %edx
movq %r13, 0x28(%rsp)
movq %rdx, %r12
shlq $0x6, %r12
movq (%rbx,%r12), %rdi
movq 0x28(%rdi), %rcx
addq 0x48(%rdi), %rcx
je 0x49310
movq %rdx, 0x20(%rsp)
callq 0x2efe5
testq %rax, %rax
je 0x493d4
movq %rax, %r15
movb $-0x2, 0x10(%rsp)
movl $0x1, %edx
movq %r14, %rdi
leaq 0x10(%rsp), %rsi
callq 0x47a98
cmpl $-0x1, %eax
je 0x4939c
movq %r14, %rdi
movq 0x20(%rsp), %rsi
callq 0x47cfe
cmpl $-0x1, %eax
je 0x4939c
addq %r12, %rbx
movq (%rbx), %rax
movq 0x8(%rbx), %rcx
movq 0x28(%rax), %rdx
movq %rdx, 0x30(%rsp)
movq 0x48(%rcx), %r13
addq 0x28(%rcx), %r13
movq 0x48(%rax), %rbp
movq %r13, %rax
shrq $0x20, %rax
negq %rax
movl $0x0, %r12d
sbbl %r12d, %r12d
movb $-0x5, 0x10(%rsp)
movl $0x1, %edx
movq %r14, %rdi
leaq 0x10(%rsp), %rsi
callq 0x47a98
cmpl $-0x1, %eax
je 0x4939c
addq 0x30(%rsp), %rbp
movq %rbp, %rax
shrq $0x20, %rax
negq %rax
movl $0x0, %esi
sbbl %esi, %esi
orl %ebp, %esi
movq %r14, %rdi
callq 0x47cfe
cmpl $-0x1, %eax
je 0x4939c
orl %r13d, %r12d
movq %r14, %rdi
movl %r12d, %esi
callq 0x47cfe
cmpl $-0x1, %eax
movq 0x8(%rsp), %r12
je 0x493a1
movq 0x28(%rsp), %r13
movq %r15, %rdi
callq 0x2f015
testq %rax, %rax
je 0x492f2
movq (%rax), %rcx
movq 0x8(%rax), %r12
movabsq $0x100000000, %rax      # imm = 0x100000000
movq %rax, 0x10(%rsp)
movq %rcx, 0x18(%rsp)
movq %rbx, %rdi
leaq 0x10(%rsp), %rbp
movq %rbp, %rsi
callq 0x4302f
movq %r14, %rdi
movq %rbp, %rsi
movq %r12, %rdx
movq %rax, %rcx
movq %r13, %r8
callq 0x48ebc
cmpl $-0x1, %eax
jne 0x4929c
jmp 0x4939c
movq %r15, %rdi
callq 0x2f0dd
leaq 0xb85a7(%rip), %rax     # 0x1018a8
movq 0x28(%rax), %rbx
movl 0x610(%rax), %eax
movq 0x20(%rsp), %rdx
incq %rdx
movslq %eax, %rcx
cmpq %rcx, %rdx
jl 0x4919b
leaq 0x10(%rsp), %rbx
movb $-0x1, (%rbx)
movl $0x1, %edx
movq %r14, %rdi
movq %rbx, %rsi
callq 0x47a98
cmpl $-0x1, %eax
je 0x49399
movq 0x28(%r14), %rax
movq %rax, 0x10(%rsp)
movl $0x8, %r13d
xorl %r15d, %r15d
movq 0x20(%r14), %rax
movq 0x38(%r14), %rcx
cmpq %r13, %rcx
movq %r13, %r12
cmovbq %rcx, %r12
testq %rcx, %rcx
cmoveq %r13, %r12
testq %rax, %rax
je 0x49377
movq %r14, %rdi
movq %rbx, %rsi
movq %r12, %rdx
callq *%rax
movq %r14, %rdi
movq %rbx, %rsi
movq %r12, %rdx
callq *0x8(%r14)
testq %rax, %rax
je 0x4939c
addq %r12, %rbx
addq %r12, 0x30(%r14)
subq %r12, %r13
jne 0x4934e
xorl %ebx, %ebx
jmp 0x493c3
xorl %r15d, %r15d
movq 0x8(%rsp), %r12
testq %r12, %r12
je 0x493b1
callq 0x26880
movl (%rax), %eax
movl %eax, (%r12)
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
testq %r15, %r15
je 0x493c3
movq %r15, %rdi
callq 0x2f0dd
movl %ebx, %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
jmp 0x493c3