// File: /workspace/github_c_makefile_star2_O2/nilyang[P]redis-tdd-annotation/src/aof.c
// Function: rewriteSortedSetObject
int rewriteSortedSetObject(rio *r, robj *key, robj *o) {
    long long count = 0, items = zsetLength(o);

    if (o->encoding == REDIS_ENCODING_ZIPLIST) {
        unsigned char *zl = o->ptr;
        unsigned char *eptr, *sptr;
        unsigned char *vstr;
        unsigned int vlen;
        long long vll;
        double score;

        eptr = ziplistIndex(zl,0);
        redisAssert(eptr != NULL);
        sptr = ziplistNext(zl,eptr);
        redisAssert(sptr != NULL);

        while (eptr != NULL) {
            redisAssert(ziplistGet(eptr,&vstr,&vlen,&vll));
            score = zzlGetScore(sptr);

            if (count == 0) {
                int cmd_items = (items > REDIS_AOF_REWRITE_ITEMS_PER_CMD) ?
                    REDIS_AOF_REWRITE_ITEMS_PER_CMD : items;

                if (rioWriteBulkCount(r,'*',2+cmd_items*2) == 0) return 0;
                if (rioWriteBulkString(r,"ZADD",4) == 0) return 0;
                if (rioWriteBulkObject(r,key) == 0) return 0;
            }
            if (rioWriteBulkDouble(r,score) == 0) return 0;
            if (vstr != NULL) {
                if (rioWriteBulkString(r,(char*)vstr,vlen) == 0) return 0;
            } else {
                if (rioWriteBulkLongLong(r,vll) == 0) return 0;
            }
            zzlNext(zl,&eptr,&sptr);
            if (++count == REDIS_AOF_REWRITE_ITEMS_PER_CMD) count = 0;
            items--;
        }
    } else if (o->encoding == REDIS_ENCODING_SKIPLIST) {
        zset *zs = o->ptr;
        dictIterator *di = dictGetIterator(zs->dict);
        dictEntry *de;

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

            if (count == 0) {
                int cmd_items = (items > REDIS_AOF_REWRITE_ITEMS_PER_CMD) ?
                    REDIS_AOF_REWRITE_ITEMS_PER_CMD : items;

                if (rioWriteBulkCount(r,'*',2+cmd_items*2) == 0) return 0;
                if (rioWriteBulkString(r,"ZADD",4) == 0) return 0;
                if (rioWriteBulkObject(r,key) == 0) return 0;
            }
            if (rioWriteBulkDouble(r,*score) == 0) return 0;
            if (rioWriteBulkObject(r,eleobj) == 0) return 0;
            if (++count == REDIS_AOF_REWRITE_ITEMS_PER_CMD) count = 0;
            items--;
        }
        dictReleaseIterator(di);
    } else {
        redisPanic("Unknown sorted zset encoding");
    }
    return 1;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rdx, %rbx
movq %rsi, 0x10(%rsp)
movq %rdi, %r14
movq %rdx, %rdi
callq 0x3bc1e
movl %eax, %r12d
movl (%rbx), %eax
shrl $0x4, %eax
andl $0xf, %eax
cmpl $0x7, %eax
je 0x46eed
cmpl $0x5, %eax
jne 0x46fe9
movq 0x8(%rbx), %r15
movq %r15, %rdi
xorl %esi, %esi
callq 0x2abfb
movq %rax, 0x20(%rsp)
testq %rax, %rax
je 0x47003
movq %rax, %rbx
movq %r15, %rdi
movq %rax, %rsi
callq 0x2ae0d
movq %rax, 0x18(%rsp)
testq %rax, %rax
je 0x47018
xorl %r13d, %r13d
leaq 0x28(%rsp), %rbp
testq %rbx, %rbx
je 0x46fb3
movq %rbx, %rdi
leaq 0x30(%rsp), %rsi
leaq 0xc(%rsp), %rdx
movq %rbp, %rcx
callq 0x2aea9
testl %eax, %eax
je 0x46fc9
movq 0x18(%rsp), %rdi
callq 0x3b09e
movsd %xmm0, (%rsp)
testq %r13, %r13
jne 0x46e7a
cmpq $0x40, %r12
pushq $0x40
popq %rax
cmovlq %r12, %rax
leal 0x2(,%rax,2), %edx
movq %r14, %rdi
pushq $0x2a
popq %rsi
callq 0x54281
testq %rax, %rax
je 0x46fa5
movq %r14, %rdi
leaq 0x49cf3(%rip), %rsi     # 0x90b47
pushq $0x4
popq %rdx
callq 0x54345
testq %rax, %rax
je 0x46fa5
movq %r14, %rdi
movq 0x10(%rsp), %rsi
callq 0x46979
testl %eax, %eax
je 0x46fa5
movq %r14, %rdi
movsd (%rsp), %xmm0
callq 0x543dd
testq %rax, %rax
je 0x46fa5
movq 0x30(%rsp), %rsi
testq %rsi, %rsi
je 0x46ea8
movl 0xc(%rsp), %edx
movq %r14, %rdi
callq 0x54345
jmp 0x46eb5
movq 0x28(%rsp), %rsi
movq %r14, %rdi
callq 0x543ad
testq %rax, %rax
je 0x46fa5
movq %r15, %rdi
leaq 0x20(%rsp), %rsi
leaq 0x18(%rsp), %rdx
callq 0x3b25c
incq %r13
cmpq $0x40, %r13
movl $0x0, %eax
cmoveq %rax, %r13
decq %r12
movq 0x20(%rsp), %rbx
jmp 0x46dea
movq 0x8(%rbx), %rax
movq (%rax), %rdi
callq 0x21ef6
movq %rax, (%rsp)
xorl %ebp, %ebp
movq (%rsp), %rdi
callq 0x21f2f
testq %rax, %rax
je 0x46faa
movq (%rax), %r13
movq 0x8(%rax), %rbx
testq %rbp, %rbp
jne 0x46f6a
cmpq $0x40, %r12
pushq $0x40
popq %rax
cmovlq %r12, %rax
leal 0x2(,%rax,2), %edx
movq %r14, %rdi
pushq $0x2a
popq %rsi
callq 0x54281
xorl %r15d, %r15d
testq %rax, %rax
je 0x46fb7
movq %r14, %rdi
leaq 0x49bfb(%rip), %rsi     # 0x90b47
pushq $0x4
popq %rdx
callq 0x54345
testq %rax, %rax
je 0x46fb7
movq %r14, %rdi
movq 0x10(%rsp), %rsi
callq 0x46979
testl %eax, %eax
je 0x46fb7
movsd (%rbx), %xmm0
movq %r14, %rdi
callq 0x543dd
xorl %r15d, %r15d
testq %rax, %rax
je 0x46fb7
movq %r14, %rdi
movq %r13, %rsi
callq 0x46979
testl %eax, %eax
je 0x46fb7
incq %rbp
cmpq $0x40, %rbp
movl $0x0, %eax
cmoveq %rax, %rbp
decq %r12
jmp 0x46eff
xorl %r15d, %r15d
jmp 0x46fb7
movq (%rsp), %rdi
callq 0x21fe6
pushq $0x1
popq %r15
movl %r15d, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x49b55(%rip), %rdi     # 0x90b25
leaq 0x4963e(%rip), %rsi     # 0x90615
movl $0x49f, %edx            # imm = 0x49F
callq 0x4906b
pushq $0x1
popq %rdi
callq 0x1f3b0
leaq 0x49b5c(%rip), %rdi     # 0x90b4c
leaq 0x4961e(%rip), %rsi     # 0x90615
movl $0x4cc, %edx            # imm = 0x4CC
callq 0x490e8
jmp 0x46fe1
leaq 0x48242(%rip), %rdi     # 0x8f24c
leaq 0x49604(%rip), %rsi     # 0x90615
movl $0x49a, %edx            # imm = 0x49A
jmp 0x46fdc
leaq 0x484ea(%rip), %rdi     # 0x8f509
leaq 0x495ef(%rip), %rsi     # 0x90615
movl $0x49c, %edx            # imm = 0x49C
jmp 0x46fdc