// File: /workspace/github_c_makefile_star2_O2/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, %r13
movq %rdi, %r14
callq 0x2b8ae
movq %rax, %r12
leaq 0xb82d4(%rip), %rbp     # 0xf98a8
cmpl $0x0, 0x754(%rbp)
je 0x415e8
leaq 0x25598(%rip), %rax     # 0x66b7c
movq %rax, 0x20(%r14)
leaq 0x72b98(%rip), %rdx     # 0xb4187
xorl %r15d, %r15d
leaq 0x3e(%rsp), %rbx
pushq $0xa
popq %rsi
pushq $0x7
popq %rcx
movq %rbx, %rdi
xorl %eax, %eax
callq 0x26120
pushq $0x9
popq %rdx
movq %r14, %rdi
movq %rbx, %rsi
callq 0x40450
pushq $-0x1
popq %rbx
cmpl $-0x1, %eax
je 0x41806
movq %r14, %rdi
callq 0x4152c
xorl %r15d, %r15d
cmpl $-0x1, %eax
je 0x41806
movq %r12, 0x18(%rsp)
movl 0x610(%rbp), %eax
xorl %edx, %edx
movq %r13, 0x8(%rsp)
movslq %eax, %rcx
cmpq %rcx, %rdx
jge 0x417c6
movq 0x28(%rbp), %rbx
movq %rdx, %r12
shlq $0x6, %r12
movq (%rbx,%r12), %rdi
movq 0x28(%rdi), %rcx
addq 0x48(%rdi), %rcx
je 0x417b4
movq %rdx, 0x10(%rsp)
callq 0x2a9c4
testq %rax, %rax
je 0x41834
movq %rax, %r15
movq %r14, %rdi
movl $0xfe, %esi
callq 0x4043a
cmpl $-0x1, %eax
je 0x41803
movq %r14, %rdi
movq 0x10(%rsp), %rsi
callq 0x40575
cmpl $-0x1, %eax
je 0x41803
addq %r12, %rbx
movq (%rbx), %rax
movq 0x8(%rbx), %rcx
movq 0x28(%rax), %rdx
movq %rdx, 0x20(%rsp)
movq 0x48(%rax), %r13
movq 0x48(%rcx), %r12
addq 0x28(%rcx), %r12
movq %r12, %rax
shrq $0x20, %rax
negq %rax
movl $0x0, %ebp
sbbl %ebp, %ebp
movq %r14, %rdi
movl $0xfb, %esi
callq 0x4043a
cmpl $-0x1, %eax
je 0x417fe
addq 0x20(%rsp), %r13
movq %r13, %rax
shrq $0x20, %rax
negq %rax
movl $0x0, %esi
sbbl %esi, %esi
orl %r13d, %esi
movq %r14, %rdi
callq 0x40575
cmpl $-0x1, %eax
je 0x417fe
orl %r12d, %ebp
movq %r14, %rdi
movl %ebp, %esi
callq 0x40575
cmpl $-0x1, %eax
movq 0x8(%rsp), %r13
je 0x41803
movq 0x18(%rsp), %r12
movq %r15, %rdi
callq 0x2a9d3
testq %rax, %rax
je 0x41795
movq (%rax), %rcx
movq 0x8(%rax), %rbp
movabsq $0x100000000, %rax      # imm = 0x100000000
movq %rax, 0x28(%rsp)
movq %rcx, 0x30(%rsp)
movq %rbx, %rdi
leaq 0x28(%rsp), %r13
movq %r13, %rsi
callq 0x3c0d3
movq %r14, %rdi
movq %r13, %rsi
movq %rbp, %rdx
movq %rax, %rcx
movq %r12, %r8
callq 0x413a1
cmpl $-0x1, %eax
jne 0x41742
jmp 0x417bc
movq %r15, %rdi
callq 0x2aa94
leaq 0xb8104(%rip), %rbp     # 0xf98a8
movl 0x610(%rbp), %eax
movq 0x8(%rsp), %r13
movq 0x10(%rsp), %rdx
incq %rdx
jmp 0x41647
pushq $-0x1
popq %rbx
movq 0x8(%rsp), %r13
jmp 0x41806
movq %r14, %rdi
movl $0xff, %esi
callq 0x4043a
xorl %r15d, %r15d
cmpl $-0x1, %eax
je 0x41803
movq 0x28(%r14), %rax
leaq 0x28(%rsp), %rsi
movq %rax, (%rsi)
pushq $0x8
popq %rdx
movq %r14, %rdi
callq 0x41839
testq %rax, %rax
pushq $-0x1
popq %rbx
je 0x41806
xorl %ebx, %ebx
jmp 0x41823
movq 0x8(%rsp), %r13
pushq $-0x1
popq %rbx
testq %r13, %r13
je 0x41816
callq 0x26880
movl (%rax), %eax
movl %eax, (%r13)
testq %r15, %r15
je 0x41823
movq %r15, %rdi
callq 0x2aa94
movl %ebx, %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
pushq $-0x1
popq %rbx
jmp 0x41823