// File: /workspace/github_c_makefile_star2_O0/nilyang[P]redis-tdd-annotation/src/rdb.c
// Function: rdbSaveObject
int rdbSaveObject(rio *rdb, robj *o) {
    int n, nwritten = 0;

    // 保存字符串对象
    if (o->type == REDIS_STRING) {
        /* Save a string value */
        if ((n = rdbSaveStringObject(rdb,o)) == -1) return -1;
        nwritten += n;

    // 保存列表对象
    } else if (o->type == REDIS_LIST) {
        /* Save a list value */
        if (o->encoding == REDIS_ENCODING_ZIPLIST) {
            size_t l = ziplistBlobLen((unsigned char*)o->ptr);

            // 以字符串对象的形式保存整个 ZIPLIST 列表
            if ((n = rdbSaveRawString(rdb,o->ptr,l)) == -1) return -1;
            nwritten += n;
        } else if (o->encoding == REDIS_ENCODING_LINKEDLIST) {
            list *list = o->ptr;
            listIter li;
            listNode *ln;

            if ((n = rdbSaveLen(rdb,listLength(list))) == -1) return -1;
            nwritten += n;

            // 遍历所有列表项
            listRewind(list,&li);
            while((ln = listNext(&li))) {
                robj *eleobj = listNodeValue(ln);
                // 以字符串对象的形式保存列表项
                if ((n = rdbSaveStringObject(rdb,eleobj)) == -1) return -1;
                nwritten += n;
            }
        } else {
            redisPanic("Unknown list encoding");
        }

    // 保存集合对象
    } else if (o->type == REDIS_SET) {
        /* Save a set value */
        if (o->encoding == REDIS_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 == REDIS_ENCODING_INTSET) {
            size_t l = intsetBlobLen((intset*)o->ptr);

            // 以字符串对象的方式保存整个 INTSET 集合
            if ((n = rdbSaveRawString(rdb,o->ptr,l)) == -1) return -1;
            nwritten += n;
        } else {
            redisPanic("Unknown set encoding");
        }

    // 保存有序集对象
    } else if (o->type == REDIS_ZSET) {
        /* Save a sorted set value */
        if (o->encoding == REDIS_ENCODING_ZIPLIST) {
            size_t l = ziplistBlobLen((unsigned char*)o->ptr);

            // 以字符串对象的形式保存整个 ZIPLIST 有序集
            if ((n = rdbSaveRawString(rdb,o->ptr,l)) == -1) return -1;
            nwritten += n;
        } else if (o->encoding == REDIS_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;

                // 成员分值（一个双精度浮点数）会被转换成字符串
                // 然后保存到 rdb 中
                if ((n = rdbSaveDoubleValue(rdb,*score)) == -1) return -1;
                nwritten += n;
            }
            dictReleaseIterator(di);
        } else {
            redisPanic("Unknown sorted set encoding");
        }

    // 保存哈希表
    } else if (o->type == REDIS_HASH) {

        /* Save a hash value */
        if (o->encoding == REDIS_ENCODING_ZIPLIST) {
            size_t l = ziplistBlobLen((unsigned char*)o->ptr);

            // 以字符串对象的形式保存整个 ZIPLIST 哈希表
            if ((n = rdbSaveRawString(rdb,o->ptr,l)) == -1) return -1;
            nwritten += n;

        } else if (o->encoding == REDIS_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 {
            redisPanic("Unknown hash encoding");
        }

    } else {
        redisPanic("Unknown object type");
    }

    return nwritten;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xd0, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movl $0x0, -0x20(%rbp)
movq -0x18(%rbp), %rax
movl (%rax), %eax
andl $0xf, %eax
cmpl $0x0, %eax
jne 0x44227
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x43af0
movl %eax, -0x1c(%rbp)
cmpl $-0x1, %eax
jne 0x44219
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x4484b
movl -0x1c(%rbp), %eax
addl -0x20(%rbp), %eax
movl %eax, -0x20(%rbp)
jmp 0x44845
movq -0x18(%rbp), %rax
movl (%rax), %eax
andl $0xf, %eax
cmpl $0x1, %eax
jne 0x44366
movq -0x18(%rbp), %rax
movl (%rax), %eax
shrl $0x4, %eax
andl $0xf, %eax
cmpl $0x5, %eax
jne 0x44292
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rdi
callq 0x34000
movq %rax, -0x28(%rbp)
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rsi
movq -0x28(%rbp), %rdx
callq 0x438e0
movl %eax, -0x1c(%rbp)
cmpl $-0x1, %eax
jne 0x44284
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x4484b
movl -0x1c(%rbp), %eax
addl -0x20(%rbp), %eax
movl %eax, -0x20(%rbp)
jmp 0x44361
movq -0x18(%rbp), %rax
movl (%rax), %eax
shrl $0x4, %eax
andl $0xf, %eax
cmpl $0x4, %eax
jne 0x4433d
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x30(%rbp)
movq -0x10(%rbp), %rdi
movq -0x30(%rbp), %rax
movq 0x28(%rax), %rax
movl %eax, %esi
callq 0x43150
movl %eax, -0x1c(%rbp)
cmpl $-0x1, %eax
jne 0x442da
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x4484b
movl -0x1c(%rbp), %eax
addl -0x20(%rbp), %eax
movl %eax, -0x20(%rbp)
movq -0x30(%rbp), %rdi
leaq -0x40(%rbp), %rsi
callq 0x202b0
leaq -0x40(%rbp), %rdi
callq 0x20310
movq %rax, -0x48(%rbp)
cmpq $0x0, %rax
je 0x4433b
movq -0x48(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x50(%rbp)
movq -0x10(%rbp), %rdi
movq -0x50(%rbp), %rsi
callq 0x43af0
movl %eax, -0x1c(%rbp)
cmpl $-0x1, %eax
jne 0x44330
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x4484b
movl -0x1c(%rbp), %eax
addl -0x20(%rbp), %eax
movl %eax, -0x20(%rbp)
jmp 0x442f0
jmp 0x4435f
leaq 0x9e808(%rip), %rdi     # 0xe2b4c
leaq 0x9e7b9(%rip), %rsi     # 0xe2b04
movl $0x2f5, %edx            # imm = 0x2F5
callq 0x63d40
movl $0x1, %edi
callq 0x1f3b0
jmp 0x44361
jmp 0x44843
movq -0x18(%rbp), %rax
movl (%rax), %eax
andl $0xf, %eax
cmpl $0x2, %eax
jne 0x444b2
movq -0x18(%rbp), %rax
movl (%rax), %eax
shrl $0x4, %eax
andl $0xf, %eax
cmpl $0x2, %eax
jne 0x44433
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x58(%rbp)
movq -0x58(%rbp), %rdi
callq 0x241d0
movq %rax, -0x60(%rbp)
movq -0x10(%rbp), %rdi
movq -0x58(%rbp), %rax
movq 0x28(%rax), %rax
movq -0x58(%rbp), %rcx
addq 0x48(%rcx), %rax
movl %eax, %esi
callq 0x43150
movl %eax, -0x1c(%rbp)
cmpl $-0x1, %eax
jne 0x443d5
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x4484b
movl -0x1c(%rbp), %eax
addl -0x20(%rbp), %eax
movl %eax, -0x20(%rbp)
movq -0x60(%rbp), %rdi
callq 0x24270
movq %rax, -0x68(%rbp)
cmpq $0x0, %rax
je 0x44428
movq -0x68(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x70(%rbp)
movq -0x10(%rbp), %rdi
movq -0x70(%rbp), %rsi
callq 0x43af0
movl %eax, -0x1c(%rbp)
cmpl $-0x1, %eax
jne 0x4441d
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x4484b
movl -0x1c(%rbp), %eax
addl -0x20(%rbp), %eax
movl %eax, -0x20(%rbp)
jmp 0x443de
movq -0x60(%rbp), %rdi
callq 0x243d0
jmp 0x444ad
movq -0x18(%rbp), %rax
movl (%rax), %eax
shrl $0x4, %eax
andl $0xf, %eax
cmpl $0x6, %eax
jne 0x44489
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rdi
callq 0x67ad0
movq %rax, -0x78(%rbp)
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rsi
movq -0x78(%rbp), %rdx
callq 0x438e0
movl %eax, -0x1c(%rbp)
cmpl $-0x1, %eax
jne 0x4447e
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x4484b
movl -0x1c(%rbp), %eax
addl -0x20(%rbp), %eax
movl %eax, -0x20(%rbp)
jmp 0x444ab
leaq 0x9e6d4(%rip), %rdi     # 0xe2b64
leaq 0x9e66d(%rip), %rsi     # 0xe2b04
movl $0x312, %edx            # imm = 0x312
callq 0x63d40
movl $0x1, %edi
callq 0x1f3b0
jmp 0x444ad
jmp 0x44841
movq -0x18(%rbp), %rax
movl (%rax), %eax
andl $0xf, %eax
cmpl $0x3, %eax
jne 0x44675
movq -0x18(%rbp), %rax
movl (%rax), %eax
shrl $0x4, %eax
andl $0xf, %eax
cmpl $0x5, %eax
jne 0x4451d
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rdi
callq 0x34000
movq %rax, -0x80(%rbp)
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rsi
movq -0x80(%rbp), %rdx
callq 0x438e0
movl %eax, -0x1c(%rbp)
cmpl $-0x1, %eax
jne 0x4450f
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x4484b
movl -0x1c(%rbp), %eax
addl -0x20(%rbp), %eax
movl %eax, -0x20(%rbp)
jmp 0x44670
movq -0x18(%rbp), %rax
movl (%rax), %eax
shrl $0x4, %eax
andl $0xf, %eax
cmpl $0x7, %eax
jne 0x4464c
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x88(%rbp)
movq -0x88(%rbp), %rax
movq (%rax), %rdi
callq 0x241d0
movq %rax, -0x90(%rbp)
movq -0x10(%rbp), %rdi
movq -0x88(%rbp), %rax
movq (%rax), %rax
movq 0x28(%rax), %rax
movq -0x88(%rbp), %rcx
movq (%rcx), %rcx
addq 0x48(%rcx), %rax
movl %eax, %esi
callq 0x43150
movl %eax, -0x1c(%rbp)
cmpl $-0x1, %eax
jne 0x44592
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x4484b
movl -0x1c(%rbp), %eax
addl -0x20(%rbp), %eax
movl %eax, -0x20(%rbp)
movq -0x90(%rbp), %rdi
callq 0x24270
movq %rax, -0x98(%rbp)
cmpq $0x0, %rax
je 0x4463e
movq -0x98(%rbp), %rax
movq (%rax), %rax
movq %rax, -0xa0(%rbp)
movq -0x98(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0xa8(%rbp)
movq -0x10(%rbp), %rdi
movq -0xa0(%rbp), %rsi
callq 0x43af0
movl %eax, -0x1c(%rbp)
cmpl $-0x1, %eax
jne 0x445ff
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x4484b
movl -0x1c(%rbp), %eax
addl -0x20(%rbp), %eax
movl %eax, -0x20(%rbp)
movq -0x10(%rbp), %rdi
movq -0xa8(%rbp), %rax
movsd (%rax), %xmm0
callq 0x43d00
movl %eax, -0x1c(%rbp)
cmpl $-0x1, %eax
jne 0x44630
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x4484b
movl -0x1c(%rbp), %eax
addl -0x20(%rbp), %eax
movl %eax, -0x20(%rbp)
jmp 0x4459b
movq -0x90(%rbp), %rdi
callq 0x243d0
jmp 0x4466e
leaq 0x9ce48(%rip), %rdi     # 0xe149b
leaq 0x9e4aa(%rip), %rsi     # 0xe2b04
movl $0x336, %edx            # imm = 0x336
callq 0x63d40
movl $0x1, %edi
callq 0x1f3b0
jmp 0x44670
jmp 0x4483f
movq -0x18(%rbp), %rax
movl (%rax), %eax
andl $0xf, %eax
cmpl $0x4, %eax
jne 0x4481b
movq -0x18(%rbp), %rax
movl (%rax), %eax
shrl $0x4, %eax
andl $0xf, %eax
cmpl $0x5, %eax
jne 0x446e6
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rdi
callq 0x34000
movq %rax, -0xb0(%rbp)
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rsi
movq -0xb0(%rbp), %rdx
callq 0x438e0
movl %eax, -0x1c(%rbp)
cmpl $-0x1, %eax
jne 0x446d8
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x4484b
movl -0x1c(%rbp), %eax
addl -0x20(%rbp), %eax
movl %eax, -0x20(%rbp)
jmp 0x44819
movq -0x18(%rbp), %rax
movl (%rax), %eax
shrl $0x4, %eax
andl $0xf, %eax
cmpl $0x2, %eax
jne 0x447f5
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rdi
callq 0x241d0
movq %rax, -0xb8(%rbp)
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rax
movq 0x28(%rax), %rax
movq -0x18(%rbp), %rcx
movq 0x8(%rcx), %rcx
addq 0x48(%rcx), %rax
movl %eax, %esi
callq 0x43150
movl %eax, -0x1c(%rbp)
cmpl $-0x1, %eax
jne 0x44746
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x4484b
movl -0x1c(%rbp), %eax
addl -0x20(%rbp), %eax
movl %eax, -0x20(%rbp)
movq -0xb8(%rbp), %rdi
callq 0x24270
movq %rax, -0xc0(%rbp)
cmpq $0x0, %rax
je 0x447e7
movq -0xc0(%rbp), %rax
movq (%rax), %rax
movq %rax, -0xc8(%rbp)
movq -0xc0(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0xd0(%rbp)
movq -0x10(%rbp), %rdi
movq -0xc8(%rbp), %rsi
callq 0x43af0
movl %eax, -0x1c(%rbp)
cmpl $-0x1, %eax
jne 0x447af
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x4484b
movl -0x1c(%rbp), %eax
addl -0x20(%rbp), %eax
movl %eax, -0x20(%rbp)
movq -0x10(%rbp), %rdi
movq -0xd0(%rbp), %rsi
callq 0x43af0
movl %eax, -0x1c(%rbp)
cmpl $-0x1, %eax
jne 0x447d9
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x4484b
movl -0x1c(%rbp), %eax
addl -0x20(%rbp), %eax
movl %eax, -0x20(%rbp)
jmp 0x4474f
movq -0xb8(%rbp), %rdi
callq 0x243d0
jmp 0x44817
leaq 0x9e37f(%rip), %rdi     # 0xe2b7b
leaq 0x9e301(%rip), %rsi     # 0xe2b04
movl $0x359, %edx            # imm = 0x359
callq 0x63d40
movl $0x1, %edi
callq 0x1f3b0
jmp 0x44819
jmp 0x4483d
leaq 0x9ccd9(%rip), %rdi     # 0xe14fb
leaq 0x9e2db(%rip), %rsi     # 0xe2b04
movl $0x35d, %edx            # imm = 0x35D
callq 0x63d40
movl $0x1, %edi
callq 0x1f3b0
jmp 0x4483f
jmp 0x44841
jmp 0x44843
jmp 0x44845
movl -0x20(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0xd0, %rsp
popq %rbp
retq
nopw (%rax,%rax)