// File: /workspace/github_c_makefile_star2_O1/zhou-yuxin[P]redis-aof-no-cow/src/aof.c
// Function: rewriteSortedSetObject
int rewriteSortedSetObject(rio *r, robj *key, robj *o) {
    long long count = 0, items = zsetLength(o);

    if (o->encoding == OBJ_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);
        serverAssert(eptr != NULL);
        sptr = ziplistNext(zl,eptr);
        serverAssert(sptr != NULL);

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

            if (count == 0) {
                int cmd_items = (items > AOF_REWRITE_ITEMS_PER_CMD) ?
                    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 == AOF_REWRITE_ITEMS_PER_CMD) count = 0;
            items--;
        }
    } else if (o->encoding == OBJ_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 > AOF_REWRITE_ITEMS_PER_CMD) ?
                    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 == AOF_REWRITE_ITEMS_PER_CMD) count = 0;
            items--;
        }
        dictReleaseIterator(di);
    } else {
        serverPanic("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 0x551a5
movl %eax, %r12d
movl (%rbx), %eax
shrl $0x4, %eax
andl $0xf, %eax
cmpl $0x7, %eax
je 0x627c9
cmpl $0x5, %eax
jne 0x628e5
movq 0x8(%rbx), %r15
movq %r15, %rdi
xorl %esi, %esi
callq 0x3ea40
movq %rax, 0x8(%rsp)
testq %rax, %rax
je 0x628ff
movq %r15, %rdi
movq %rax, %rsi
callq 0x3ead6
movq %rax, 0x20(%rsp)
testq %rax, %rax
je 0x62914
movq 0x8(%rsp), %rdi
testq %rdi, %rdi
je 0x628ab
xorl %ebx, %ebx
leaq 0x14(%rsp), %r13
leaq 0x28(%rsp), %rbp
leaq 0x30(%rsp), %rsi
movq %r13, %rdx
movq %rbp, %rcx
callq 0x3eb60
testl %eax, %eax
je 0x628c3
movq 0x20(%rsp), %rdi
callq 0x54417
movsd %xmm0, (%rsp)
testq %rbx, %rbx
jne 0x6274d
cmpq $0x40, %r12
movl $0x40, %eax
cmovlq %r12, %rax
leal 0x2(,%rax,2), %edx
movq %r14, %rdi
movl $0x2a, %esi
callq 0x76284
testq %rax, %rax
je 0x628b2
movl $0x4, %edx
movq %r14, %rdi
leaq 0x65fdb(%rip), %rsi     # 0xc8705
callq 0x76328
testq %rax, %rax
je 0x628b2
movq %r14, %rdi
movq 0x18(%rsp), %rsi
callq 0x6225d
testl %eax, %eax
je 0x628b2
movq %r14, %rdi
movsd (%rsp), %xmm0
callq 0x76471
testq %rax, %rax
je 0x628b2
movq 0x30(%rsp), %rsi
testq %rsi, %rsi
je 0x6277b
movl 0x14(%rsp), %edx
movq %r14, %rdi
callq 0x76328
jmp 0x62788
movq 0x28(%rsp), %rsi
movq %r14, %rdi
callq 0x7643f
testq %rax, %rax
je 0x628b2
movq %r15, %rdi
leaq 0x8(%rsp), %rsi
leaq 0x20(%rsp), %rdx
callq 0x545d7
incq %rbx
cmpq $0x40, %rbx
movl $0x0, %eax
cmoveq %rax, %rbx
decq %r12
movq 0x8(%rsp), %rdi
testq %rdi, %rdi
jne 0x626c5
jmp 0x628ab
movq 0x8(%rbx), %rax
movq (%rax), %rdi
callq 0x320bb
movq %rax, (%rsp)
xorl %ebp, %ebp
movq (%rsp), %rdi
callq 0x32116
movq %rax, %r13
testq %rax, %rax
je 0x6289b
movq (%r13), %rbx
movq 0x8(%r13), %r15
testq %rbp, %rbp
je 0x62839
movsd (%r15), %xmm0
movq %r14, %rdi
callq 0x76471
testq %rax, %rax
je 0x62835
movq %r14, %rdi
movq %rbx, %rsi
callq 0x6225d
testl %eax, %eax
je 0x62835
incq %rbp
cmpq $0x40, %rbp
movl $0x0, %eax
cmoveq %rax, %rbp
decq %r12
movb $0x1, %al
jmp 0x62891
xorl %eax, %eax
jmp 0x62891
cmpq $0x40, %r12
movl $0x40, %eax
cmovlq %r12, %rax
leal 0x2(,%rax,2), %edx
movq %r14, %rdi
movl $0x2a, %esi
callq 0x76284
testq %rax, %rax
je 0x6288d
movl $0x4, %edx
movq %r14, %rdi
leaq 0x65e97(%rip), %rsi     # 0xc8705
callq 0x76328
testq %rax, %rax
je 0x6288d
movq %r14, %rdi
movq 0x18(%rsp), %rsi
callq 0x6225d
testl %eax, %eax
jne 0x627fd
xorl %eax, %eax
xorl %ebp, %ebp
testb %al, %al
jne 0x627db
jmp 0x628a4
movq (%rsp), %rdi
callq 0x321d3
xorl %eax, %eax
testq %r13, %r13
jne 0x628b4
movl $0x1, %eax
jmp 0x628b4
xorl %eax, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x65e19(%rip), %rdi     # 0xc86e3
leaq 0x6563e(%rip), %rsi     # 0xc7f0f
movl $0x3af, %edx            # imm = 0x3AF
callq 0x654e1
movl $0x1, %edi
callq 0x263d0
leaq 0x65e1e(%rip), %rdi     # 0xc870a
leaq 0x6561c(%rip), %rsi     # 0xc7f0f
movl $0x3dc, %edx            # imm = 0x3DC
callq 0x6558d
jmp 0x628db
leaq 0x63dd9(%rip), %rdi     # 0xc66df
leaq 0x65602(%rip), %rsi     # 0xc7f0f
movl $0x3aa, %edx            # imm = 0x3AA
jmp 0x628d6
leaq 0x640eb(%rip), %rdi     # 0xc6a06
leaq 0x655ed(%rip), %rsi     # 0xc7f0f
movl $0x3ac, %edx            # imm = 0x3AC
jmp 0x628d6