// File: /workspace/github_c_makefile_star2_O1/zhou-yuxin[P]redis-aof-no-cow/src/rdb.c
// Function: rdbSaveObject
ssize_t rdbSaveObject(rio *rdb, robj *o) {
    ssize_t n = 0, nwritten = 0;

    if (o->type == OBJ_STRING) {
        /* Save a string value */
        if ((n = rdbSaveStringObject(rdb,o)) == -1) return -1;
        nwritten += n;
    } else if (o->type == OBJ_LIST) {
        /* Save a list value */
        if (o->encoding == OBJ_ENCODING_QUICKLIST) {
            quicklist *ql = o->ptr;
            quicklistNode *node = ql->head;

            if ((n = rdbSaveLen(rdb,ql->len)) == -1) return -1;
            nwritten += n;

            do {
                if (quicklistNodeIsCompressed(node)) {
                    void *data;
                    size_t compress_len = quicklistGetLzf(node, &data);
                    if ((n = rdbSaveLzfBlob(rdb,data,compress_len,node->sz)) == -1) return -1;
                    nwritten += n;
                } else {
                    if ((n = rdbSaveRawString(rdb,node->zl,node->sz)) == -1) return -1;
                    nwritten += n;
                }
            } while ((node = node->next));
        } else {
            serverPanic("Unknown list encoding");
        }
    } else if (o->type == OBJ_SET) {
        /* Save a set value */
        if (o->encoding == OBJ_ENCODING_HT) {
            dict *set = o->ptr;
            dictIterator *di = dictGetIterator(set);
            dictEntry *de;

            if ((n = rdbSaveLen(rdb,dictSize(set))) == -1) return -1;
            nwritten += n;

            while((de = dictNext(di)) != NULL) {
                robj *eleobj = dictGetKey(de);
                if ((n = rdbSaveStringObject(rdb,eleobj)) == -1) return -1;
                nwritten += n;
            }
            dictReleaseIterator(di);
        } else if (o->encoding == OBJ_ENCODING_INTSET) {
            size_t l = intsetBlobLen((intset*)o->ptr);

            if ((n = rdbSaveRawString(rdb,o->ptr,l)) == -1) return -1;
            nwritten += n;
        } else {
            serverPanic("Unknown set encoding");
        }
    } else if (o->type == OBJ_ZSET) {
        /* Save a sorted set value */
        if (o->encoding == OBJ_ENCODING_ZIPLIST) {
            size_t l = ziplistBlobLen((unsigned char*)o->ptr);

            if ((n = rdbSaveRawString(rdb,o->ptr,l)) == -1) return -1;
            nwritten += n;
        } else if (o->encoding == OBJ_ENCODING_SKIPLIST) {
            zset *zs = o->ptr;
            dictIterator *di = dictGetIterator(zs->dict);
            dictEntry *de;

            if ((n = rdbSaveLen(rdb,dictSize(zs->dict))) == -1) return -1;
            nwritten += n;

            while((de = dictNext(di)) != NULL) {
                robj *eleobj = dictGetKey(de);
                double *score = dictGetVal(de);

                if ((n = rdbSaveStringObject(rdb,eleobj)) == -1) return -1;
                nwritten += n;
                if ((n = rdbSaveDoubleValue(rdb,*score)) == -1) return -1;
                nwritten += n;
            }
            dictReleaseIterator(di);
        } else {
            serverPanic("Unknown sorted set encoding");
        }
    } else if (o->type == OBJ_HASH) {
        /* Save a hash value */
        if (o->encoding == OBJ_ENCODING_ZIPLIST) {
            size_t l = ziplistBlobLen((unsigned char*)o->ptr);

            if ((n = rdbSaveRawString(rdb,o->ptr,l)) == -1) return -1;
            nwritten += n;

        } else if (o->encoding == OBJ_ENCODING_HT) {
            dictIterator *di = dictGetIterator(o->ptr);
            dictEntry *de;

            if ((n = rdbSaveLen(rdb,dictSize((dict*)o->ptr))) == -1) return -1;
            nwritten += n;

            while((de = dictNext(di)) != NULL) {
                robj *key = dictGetKey(de);
                robj *val = dictGetVal(de);

                if ((n = rdbSaveStringObject(rdb,key)) == -1) return -1;
                nwritten += n;
                if ((n = rdbSaveStringObject(rdb,val)) == -1) return -1;
                nwritten += n;
            }
            dictReleaseIterator(di);

        } else {
            serverPanic("Unknown hash encoding");
        }

    } else {
        serverPanic("Unknown object type");
    }
    return nwritten;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x10, %rsp
movl (%rsi), %eax
movl %eax, %ecx
andl $0xf, %ecx
cmpl $0x4, %ecx
ja 0x4c36c
movq %rsi, %r14
movq %rdi, %rbx
leaq 0x79722(%rip), %rdx     # 0xc5784
movslq (%rdx,%rcx,4), %rcx
addq %rdx, %rcx
jmpq *%rcx
movq %rbx, %rdi
movq %r14, %rsi
callq 0x4ba8a
cmpl $-0x1, %eax
je 0x4c2a7
movslq %eax, %r12
jmp 0x4c347
shrl $0x4, %eax
andl $0xf, %eax
cmpl $0x2, %eax
je 0x4c206
cmpl $0x5, %eax
je 0x4c14c
leaq 0x7995b(%rip), %rdi     # 0xc5a01
leaq 0x798e1(%rip), %rsi     # 0xc598e
movl $0x2a8, %edx            # imm = 0x2A8
jmp 0x4c3a9
shrl $0x4, %eax
andl $0xf, %eax
cmpl $0x6, %eax
je 0x4c27e
cmpl $0x2, %eax
jne 0x4c381
movq 0x8(%r14), %r15
movq %r15, %rdi
callq 0x320bb
movq %rax, %r14
movl 0x48(%r15), %esi
addl 0x28(%r15), %esi
movq %rbx, %rdi
callq 0x4b054
cmpl $-0x1, %eax
je 0x4c326
movslq %eax, %r12
movq %r14, %rdi
callq 0x32116
testq %rax, %rax
je 0x4c32d
movq (%rax), %rsi
movq %rbx, %rdi
callq 0x4ba8a
xorl %ecx, %ecx
movl $0x0, %edx
cmpl $-0x1, %eax
je 0x4c124
movl %eax, %edx
movslq %edx, %rdx
addq %rdx, %r12
cmpl $-0x1, %eax
jne 0x4c0fa
jmp 0x4c33c
shrl $0x4, %eax
andl $0xf, %eax
cmpl $0x7, %eax
je 0x4c2b3
cmpl $0x5, %eax
jne 0x4c396
movq 0x8(%r14), %rdi
callq 0x3ef6d
jmp 0x4c287
andl $0xf0, %eax
cmpl $0x90, %eax
jne 0x4c357
movq 0x8(%r14), %rax
movq (%rax), %r14
movl 0x18(%rax), %esi
movq %rbx, %rdi
callq 0x4b054
cmpl $-0x1, %eax
je 0x4c326
movslq %eax, %r12
movl $0x30000, %ebp          # imm = 0x30000
leaq 0x8(%rsp), %r15
movl 0x1c(%r14), %eax
andl %ebp, %eax
cmpl $0x20000, %eax          # imm = 0x20000
jne 0x4c1db
movq %r14, %rdi
movq %r15, %rsi
callq 0x2e976
movq 0x8(%rsp), %rsi
movl 0x18(%r14), %ecx
movq %rbx, %rdi
movq %rax, %rdx
callq 0x4b5ef
xorl %ecx, %ecx
cmpq $-0x1, %rax
movl $0x0, %edx
cmovneq %rax, %rdx
addq %rdx, %r12
cmpq $-0x1, %rax
jne 0x4c1f8
jmp 0x4c33c
movq 0x10(%r14), %rsi
movl 0x18(%r14), %edx
movq %rbx, %rdi
callq 0x4b8a5
cmpq $-0x1, %rax
je 0x4c322
addq %rax, %r12
movq 0x8(%r14), %r14
testq %r14, %r14
jne 0x4c192
jmp 0x4c33a
movq 0x8(%r14), %rdi
callq 0x320bb
movq %rax, %r15
movq 0x8(%r14), %rax
movl 0x48(%rax), %esi
addl 0x28(%rax), %esi
movq %rbx, %rdi
callq 0x4b054
cmpl $-0x1, %eax
je 0x4c326
movslq %eax, %r12
movq %r15, %rdi
callq 0x32116
testq %rax, %rax
je 0x4c332
movq (%rax), %rsi
movq 0x8(%rax), %r14
movq %rbx, %rdi
callq 0x4ba8a
cmpl $-0x1, %eax
je 0x4c273
cltq
addq %rax, %r12
movq %rbx, %rdi
movq %r14, %rsi
callq 0x4ba8a
cmpl $-0x1, %eax
je 0x4c273
cltq
addq %rax, %r12
movb $0x1, %al
jmp 0x4c275
xorl %eax, %eax
testb %al, %al
jne 0x4c230
jmp 0x4c322
movq 0x8(%r14), %rdi
callq 0x68a72
movq 0x8(%r14), %rsi
movq %rbx, %rdi
movq %rax, %rdx
callq 0x4b8a5
xorl %r12d, %r12d
cmpq $-0x1, %rax
cmovneq %rax, %r12
jne 0x4c347
movq $-0x1, %rax
jmp 0x4c34a
movq 0x8(%r14), %r15
movq (%r15), %rdi
callq 0x320bb
movq %rax, %r14
movq (%r15), %rax
movl 0x48(%rax), %esi
addl 0x28(%rax), %esi
movq %rbx, %rdi
callq 0x4b054
cmpl $-0x1, %eax
je 0x4c326
movslq %eax, %r12
movq %r14, %rdi
callq 0x32116
testq %rax, %rax
je 0x4c32d
movq (%rax), %rsi
movq 0x8(%rax), %r15
movq %rbx, %rdi
callq 0x4ba8a
cmpl $-0x1, %eax
je 0x4c31c
cltq
addq %rax, %r12
movsd (%r15), %xmm0
movq %rbx, %rdi
callq 0x4bce0
cmpl $-0x1, %eax
je 0x4c31c
cltq
addq %rax, %r12
movb $0x1, %al
jmp 0x4c31e
xorl %eax, %eax
testb %al, %al
jne 0x4c2db
xorl %ecx, %ecx
jmp 0x4c33c
xorl %ecx, %ecx
xorl %r12d, %r12d
jmp 0x4c33c
movq %r14, %rdi
jmp 0x4c335
movq %r15, %rdi
callq 0x321d3
movb $0x1, %cl
movq $-0x1, %rax
testb %cl, %cl
je 0x4c34a
movq %r12, %rax
addq $0x10, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
leaq 0x79674(%rip), %rdi     # 0xc59d2
leaq 0x79629(%rip), %rsi     # 0xc598e
movl $0x257, %edx            # imm = 0x257
jmp 0x4c3a9
leaq 0x77963(%rip), %rdi     # 0xc3cd6
leaq 0x79614(%rip), %rsi     # 0xc598e
movl $0x2ac, %edx            # imm = 0x2AC
jmp 0x4c3a9
leaq 0x79662(%rip), %rdi     # 0xc59ea
leaq 0x795ff(%rip), %rsi     # 0xc598e
movl $0x26f, %edx            # imm = 0x26F
jmp 0x4c3a9
leaq 0x778d9(%rip), %rdi     # 0xc3c76
leaq 0x795ea(%rip), %rsi     # 0xc598e
movl $0x28b, %edx            # imm = 0x28B
callq 0x6558d
movl $0x1, %edi
callq 0x263d0