// File: /workspace/github_c_makefile_star2_O3/gplessis[P]dotdeb-redis/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, 0x10(%rsp)
movq %rdi, %r14
movq %rdx, %rdi
callq 0x51a88
movl %eax, %r13d
movl (%rbx), %eax
shrl $0x4, %eax
andl $0xf, %eax
cmpl $0x7, %eax
je 0x5ec95
cmpl $0x5, %eax
jne 0x5eda7
movq 0x8(%rbx), %r15
movq %r15, %rdi
xorl %esi, %esi
callq 0x3b680
movq %rax, 0x20(%rsp)
testq %rax, %rax
je 0x5edc1
movq %rax, %rbx
movq %r15, %rdi
movq %rax, %rsi
callq 0x3b745
movq %rax, 0x18(%rsp)
testq %rax, %rax
je 0x5edd6
xorl %r12d, %r12d
leaq 0x28(%rsp), %rbp
movq %rbx, %rdi
leaq 0x30(%rsp), %rsi
leaq 0xc(%rsp), %rdx
movq %rbp, %rcx
callq 0x3b7cf
testl %eax, %eax
je 0x5ed85
movq 0x18(%rsp), %rdi
callq 0x50d7b
movsd %xmm0, (%rsp)
testq %r12, %r12
jne 0x5ec19
cmpq $0x40, %r13
movl $0x40, %eax
cmovlq %r13, %rax
leal 0x2(,%rax,2), %edx
movq %r14, %rdi
movl $0x2a, %esi
callq 0x727d4
testq %rax, %rax
je 0x5ed72
movl $0x4, %edx
movq %r14, %rdi
leaq 0x66b90(%rip), %rsi     # 0xc5786
callq 0x72874
testq %rax, %rax
je 0x5ed72
movq %r14, %rdi
movq 0x10(%rsp), %rsi
callq 0x5e739
testl %eax, %eax
je 0x5ed72
movq %r14, %rdi
movsd (%rsp), %xmm0
callq 0x7299d
testq %rax, %rax
je 0x5ed72
movq 0x30(%rsp), %rsi
testq %rsi, %rsi
je 0x5ec47
movl 0xc(%rsp), %edx
movq %r14, %rdi
callq 0x72874
jmp 0x5ec54
movq 0x28(%rsp), %rsi
movq %r14, %rdi
callq 0x7296b
testq %rax, %rax
je 0x5ed72
movq %r15, %rdi
leaq 0x20(%rsp), %rsi
leaq 0x18(%rsp), %rdx
callq 0x50f41
incq %r12
cmpq $0x40, %r12
movl $0x0, %eax
cmoveq %rax, %r12
decq %r13
movq 0x20(%rsp), %rbx
testq %rbx, %rbx
jne 0x5eb8c
jmp 0x5ed6b
movq 0x8(%rbx), %rax
movq (%rax), %rdi
callq 0x2efbb
movq %rax, (%rsp)
movq %rax, %rdi
callq 0x2f015
testq %rax, %rax
je 0x5ed62
xorl %r15d, %r15d
movq (%rax), %r12
movq 0x8(%rax), %rbx
testq %r15, %r15
jne 0x5ed1b
cmpq $0x40, %r13
movl $0x40, %eax
cmovlq %r13, %rax
leal 0x2(,%rax,2), %edx
movq %r14, %rdi
movl $0x2a, %esi
callq 0x727d4
xorl %ebp, %ebp
testq %rax, %rax
je 0x5ed74
movl $0x4, %edx
movq %r14, %rdi
leaq 0x66a86(%rip), %rsi     # 0xc5786
callq 0x72874
testq %rax, %rax
je 0x5ed74
movq %r14, %rdi
movq 0x10(%rsp), %rsi
callq 0x5e739
testl %eax, %eax
je 0x5ed74
movsd (%rbx), %xmm0
movq %r14, %rdi
callq 0x7299d
xorl %ebp, %ebp
testq %rax, %rax
je 0x5ed74
movq %r14, %rdi
movq %r12, %rsi
callq 0x5e739
testl %eax, %eax
je 0x5ed74
incq %r15
cmpq $0x40, %r15
movl $0x0, %eax
cmoveq %rax, %r15
decq %r13
movq (%rsp), %rdi
callq 0x2f015
testq %rax, %rax
jne 0x5ecb9
movq (%rsp), %rdi
callq 0x2f0dd
movl $0x1, %ebp
jmp 0x5ed74
xorl %ebp, %ebp
movl %ebp, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x669d8(%rip), %rdi     # 0xc5764
leaq 0x661e8(%rip), %rsi     # 0xc4f7b
movl $0x386, %edx            # imm = 0x386
callq 0x61908
movl $0x1, %edi
callq 0x263c0
leaq 0x669dd(%rip), %rdi     # 0xc578b
leaq 0x661c6(%rip), %rsi     # 0xc4f7b
movl $0x3b3, %edx            # imm = 0x3B3
callq 0x619b4
jmp 0x5ed9d
leaq 0x64997(%rip), %rdi     # 0xc375f
leaq 0x661ac(%rip), %rsi     # 0xc4f7b
movl $0x381, %edx            # imm = 0x381
jmp 0x5ed98
leaq 0x64ca9(%rip), %rdi     # 0xc3a86
leaq 0x66197(%rip), %rsi     # 0xc4f7b
movl $0x383, %edx            # imm = 0x383
jmp 0x5ed98