// File: /workspace/github_c_makefile_star2_O1/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, 0x18(%rsp)
movq %rdi, %r14
movq %rdx, %rdi
callq 0x3ea49
movl %eax, %r12d
movl (%rbx), %eax
shrl $0x4, %eax
andl $0xf, %eax
cmpl $0x7, %eax
je 0x4aad2
cmpl $0x5, %eax
jne 0x4abee
movq 0x8(%rbx), %r15
movq %r15, %rdi
xorl %esi, %esi
callq 0x2bff5
movq %rax, 0x8(%rsp)
testq %rax, %rax
je 0x4ac08
movq %r15, %rdi
movq %rax, %rsi
callq 0x2c2b3
movq %rax, 0x20(%rsp)
testq %rax, %rax
je 0x4ac1d
movq 0x8(%rsp), %rdi
testq %rdi, %rdi
je 0x4abb4
xorl %ebx, %ebx
leaq 0x14(%rsp), %r13
leaq 0x28(%rsp), %rbp
leaq 0x30(%rsp), %rsi
movq %r13, %rdx
movq %rbp, %rcx
callq 0x2c351
testl %eax, %eax
je 0x4abcc
movq 0x20(%rsp), %rdi
callq 0x3ddbd
movsd %xmm0, (%rsp)
testq %rbx, %rbx
jne 0x4aa56
cmpq $0x40, %r12
movl $0x40, %eax
cmovlq %r12, %rax
leal 0x2(,%rax,2), %edx
movq %r14, %rdi
movl $0x2a, %esi
callq 0x58eae
testq %rax, %rax
je 0x4abbb
movl $0x4, %edx
movq %r14, %rdi
leaq 0x50108(%rip), %rsi     # 0x9ab3b
callq 0x58f52
testq %rax, %rax
je 0x4abbb
movq %r14, %rdi
movq 0x18(%rsp), %rsi
callq 0x4a4c3
testl %eax, %eax
je 0x4abbb
movq %r14, %rdi
movsd (%rsp), %xmm0
callq 0x5909b
testq %rax, %rax
je 0x4abbb
movq 0x30(%rsp), %rsi
testq %rsi, %rsi
je 0x4aa84
movl 0x14(%rsp), %edx
movq %r14, %rdi
callq 0x58f52
jmp 0x4aa91
movq 0x28(%rsp), %rsi
movq %r14, %rdi
callq 0x59069
testq %rax, %rax
je 0x4abbb
movq %r15, %rdi
leaq 0x8(%rsp), %rsi
leaq 0x20(%rsp), %rdx
callq 0x3df7d
incq %rbx
cmpq $0x40, %rbx
movl $0x0, %eax
cmoveq %rax, %rbx
decq %r12
movq 0x8(%rsp), %rdi
testq %rdi, %rdi
jne 0x4a9ce
jmp 0x4abb4
movq 0x8(%rbx), %rax
movq (%rax), %rdi
callq 0x228b5
movq %rax, (%rsp)
xorl %ebp, %ebp
movq (%rsp), %rdi
callq 0x22913
movq %rax, %r13
testq %rax, %rax
je 0x4aba4
movq (%r13), %rbx
movq 0x8(%r13), %r15
testq %rbp, %rbp
je 0x4ab42
movsd (%r15), %xmm0
movq %r14, %rdi
callq 0x5909b
testq %rax, %rax
je 0x4ab3e
movq %r14, %rdi
movq %rbx, %rsi
callq 0x4a4c3
testl %eax, %eax
je 0x4ab3e
incq %rbp
cmpq $0x40, %rbp
movl $0x0, %eax
cmoveq %rax, %rbp
decq %r12
movb $0x1, %al
jmp 0x4ab9a
xorl %eax, %eax
jmp 0x4ab9a
cmpq $0x40, %r12
movl $0x40, %eax
cmovlq %r12, %rax
leal 0x2(,%rax,2), %edx
movq %r14, %rdi
movl $0x2a, %esi
callq 0x58eae
testq %rax, %rax
je 0x4ab96
movl $0x4, %edx
movq %r14, %rdi
leaq 0x4ffc4(%rip), %rsi     # 0x9ab3b
callq 0x58f52
testq %rax, %rax
je 0x4ab96
movq %r14, %rdi
movq 0x18(%rsp), %rsi
callq 0x4a4c3
testl %eax, %eax
jne 0x4ab06
xorl %eax, %eax
xorl %ebp, %ebp
testb %al, %al
jne 0x4aae4
jmp 0x4abad
movq (%rsp), %rdi
callq 0x229b9
xorl %eax, %eax
testq %r13, %r13
jne 0x4abbd
movl $0x1, %eax
jmp 0x4abbd
xorl %eax, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x4ff46(%rip), %rdi     # 0x9ab19
leaq 0x4fa2f(%rip), %rsi     # 0x9a609
movl $0x49f, %edx            # imm = 0x49F
callq 0x4d037
movl $0x1, %edi
callq 0x1f3b0
leaq 0x4ff4b(%rip), %rdi     # 0x9ab40
leaq 0x4fa0d(%rip), %rsi     # 0x9a609
movl $0x4cc, %edx            # imm = 0x4CC
callq 0x4d0e5
jmp 0x4abe4
leaq 0x4e630(%rip), %rdi     # 0x9923f
leaq 0x4f9f3(%rip), %rsi     # 0x9a609
movl $0x49a, %edx            # imm = 0x49A
jmp 0x4abdf
leaq 0x4e8d8(%rip), %rdi     # 0x994fc
leaq 0x4f9de(%rip), %rsi     # 0x9a609
movl $0x49c, %edx            # imm = 0x49C
jmp 0x4abdf