// File: /workspace/github_c_makefile_star2_O3/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 0x3eadd
movl %eax, %r13d
movl (%rbx), %eax
shrl $0x4, %eax
andl $0xf, %eax
cmpl $0x7, %eax
je 0x4a53b
cmpl $0x5, %eax
jne 0x4a64d
movq 0x8(%rbx), %r15
movq %r15, %rdi
xorl %esi, %esi
callq 0x2c28b
movq %rax, 0x20(%rsp)
testq %rax, %rax
je 0x4a667
movq %rax, %rbx
movq %r15, %rdi
movq %rax, %rsi
callq 0x2c558
movq %rax, 0x18(%rsp)
testq %rax, %rax
je 0x4a67c
xorl %r12d, %r12d
leaq 0x28(%rsp), %rbp
movq %rbx, %rdi
leaq 0x30(%rsp), %rsi
leaq 0xc(%rsp), %rdx
movq %rbp, %rcx
callq 0x2c5f6
testl %eax, %eax
je 0x4a62b
movq 0x18(%rsp), %rdi
callq 0x3ded9
movsd %xmm0, (%rsp)
testq %r12, %r12
jne 0x4a4bf
cmpq $0x40, %r13
movl $0x40, %eax
cmovlq %r13, %rax
leal 0x2(,%rax,2), %edx
movq %r14, %rdi
movl $0x2a, %esi
callq 0x5891c
testq %rax, %rax
je 0x4a618
movl $0x4, %edx
movq %r14, %rdi
leaq 0x506e7(%rip), %rsi     # 0x9ab83
callq 0x589bc
testq %rax, %rax
je 0x4a618
movq %r14, %rdi
movq 0x10(%rsp), %rsi
callq 0x49f3a
testl %eax, %eax
je 0x4a618
movq %r14, %rdi
movsd (%rsp), %xmm0
callq 0x58ae5
testq %rax, %rax
je 0x4a618
movq 0x30(%rsp), %rsi
testq %rsi, %rsi
je 0x4a4ed
movl 0xc(%rsp), %edx
movq %r14, %rdi
callq 0x589bc
jmp 0x4a4fa
movq 0x28(%rsp), %rsi
movq %r14, %rdi
callq 0x58ab3
testq %rax, %rax
je 0x4a618
movq %r15, %rdi
leaq 0x20(%rsp), %rsi
leaq 0x18(%rsp), %rdx
callq 0x3e09f
incq %r12
cmpq $0x40, %r12
movl $0x0, %eax
cmoveq %rax, %r12
decq %r13
movq 0x20(%rsp), %rbx
testq %rbx, %rbx
jne 0x4a432
jmp 0x4a611
movq 0x8(%rbx), %rax
movq (%rax), %rdi
callq 0x22a71
movq %rax, (%rsp)
movq %rax, %rdi
callq 0x22acf
testq %rax, %rax
je 0x4a608
xorl %r15d, %r15d
movq (%rax), %r12
movq 0x8(%rax), %rbx
testq %r15, %r15
jne 0x4a5c1
cmpq $0x40, %r13
movl $0x40, %eax
cmovlq %r13, %rax
leal 0x2(,%rax,2), %edx
movq %r14, %rdi
movl $0x2a, %esi
callq 0x5891c
xorl %ebp, %ebp
testq %rax, %rax
je 0x4a61a
movl $0x4, %edx
movq %r14, %rdi
leaq 0x505dd(%rip), %rsi     # 0x9ab83
callq 0x589bc
testq %rax, %rax
je 0x4a61a
movq %r14, %rdi
movq 0x10(%rsp), %rsi
callq 0x49f3a
testl %eax, %eax
je 0x4a61a
movsd (%rbx), %xmm0
movq %r14, %rdi
callq 0x58ae5
xorl %ebp, %ebp
testq %rax, %rax
je 0x4a61a
movq %r14, %rdi
movq %r12, %rsi
callq 0x49f3a
testl %eax, %eax
je 0x4a61a
incq %r15
cmpq $0x40, %r15
movl $0x0, %eax
cmoveq %rax, %r15
decq %r13
movq (%rsp), %rdi
callq 0x22acf
testq %rax, %rax
jne 0x4a55f
movq (%rsp), %rdi
callq 0x22b86
movl $0x1, %ebp
jmp 0x4a61a
xorl %ebp, %ebp
movl %ebp, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x5052f(%rip), %rdi     # 0x9ab61
leaq 0x50018(%rip), %rsi     # 0x9a651
movl $0x49f, %edx            # imm = 0x49F
callq 0x4ca32
movl $0x1, %edi
callq 0x1f3b0
leaq 0x50534(%rip), %rdi     # 0x9ab88
leaq 0x4fff6(%rip), %rsi     # 0x9a651
movl $0x4cc, %edx            # imm = 0x4CC
callq 0x4cae0
jmp 0x4a643
leaq 0x4ec1a(%rip), %rdi     # 0x99288
leaq 0x4ffdc(%rip), %rsi     # 0x9a651
movl $0x49a, %edx            # imm = 0x49A
jmp 0x4a63e
leaq 0x4eec2(%rip), %rdi     # 0x99545
leaq 0x4ffc7(%rip), %rsi     # 0x9a651
movl $0x49c, %edx            # imm = 0x49C
jmp 0x4a63e