// File: /workspace/github_c_makefile_star2_O2/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 0x490f5
movl %eax, %r12d
movl (%rbx), %eax
shrl $0x4, %eax
andl $0xf, %eax
cmpl $0x7, %eax
je 0x553c5
cmpl $0x5, %eax
jne 0x554c1
movq 0x8(%rbx), %r15
movq %r15, %rdi
xorl %esi, %esi
callq 0x35aca
movq %rax, 0x20(%rsp)
testq %rax, %rax
je 0x554db
movq %rax, %rbx
movq %r15, %rdi
movq %rax, %rsi
callq 0x35b60
movq %rax, 0x18(%rsp)
testq %rax, %rax
je 0x554f0
xorl %r13d, %r13d
leaq 0x28(%rsp), %rbp
testq %rbx, %rbx
je 0x5548b
movq %rbx, %rdi
leaq 0x30(%rsp), %rsi
leaq 0xc(%rsp), %rdx
movq %rbp, %rcx
callq 0x35be8
testl %eax, %eax
je 0x554a1
movq 0x18(%rsp), %rdi
callq 0x48535
movsd %xmm0, (%rsp)
testq %r13, %r13
jne 0x55352
cmpq $0x40, %r12
pushq $0x40
popq %rax
cmovlq %r12, %rax
leal 0x2(,%rax,2), %edx
movq %r14, %rdi
pushq $0x2a
popq %rsi
callq 0x66bc1
testq %rax, %rax
je 0x5547d
movq %r14, %rdi
leaq 0x61746(%rip), %rsi     # 0xb6a72
pushq $0x4
popq %rdx
callq 0x66c85
testq %rax, %rax
je 0x5547d
movq %r14, %rdi
movq 0x10(%rsp), %rsi
callq 0x54ef3
testl %eax, %eax
je 0x5547d
movq %r14, %rdi
movsd (%rsp), %xmm0
callq 0x66d1d
testq %rax, %rax
je 0x5547d
movq 0x30(%rsp), %rsi
testq %rsi, %rsi
je 0x55380
movl 0xc(%rsp), %edx
movq %r14, %rdi
callq 0x66c85
jmp 0x5538d
movq 0x28(%rsp), %rsi
movq %r14, %rdi
callq 0x66ced
testq %rax, %rax
je 0x5547d
movq %r15, %rdi
leaq 0x20(%rsp), %rsi
leaq 0x18(%rsp), %rdx
callq 0x486f3
incq %r13
cmpq $0x40, %r13
movl $0x0, %eax
cmoveq %rax, %r13
decq %r12
movq 0x20(%rsp), %rbx
jmp 0x552c2
movq 0x8(%rbx), %rax
movq (%rax), %rdi
callq 0x2a99f
movq %rax, (%rsp)
xorl %ebp, %ebp
movq (%rsp), %rdi
callq 0x2a9d3
testq %rax, %rax
je 0x55482
movq (%rax), %r13
movq 0x8(%rax), %rbx
testq %rbp, %rbp
jne 0x55442
cmpq $0x40, %r12
pushq $0x40
popq %rax
cmovlq %r12, %rax
leal 0x2(,%rax,2), %edx
movq %r14, %rdi
pushq $0x2a
popq %rsi
callq 0x66bc1
xorl %r15d, %r15d
testq %rax, %rax
je 0x5548f
movq %r14, %rdi
leaq 0x6164e(%rip), %rsi     # 0xb6a72
pushq $0x4
popq %rdx
callq 0x66c85
testq %rax, %rax
je 0x5548f
movq %r14, %rdi
movq 0x10(%rsp), %rsi
callq 0x54ef3
testl %eax, %eax
je 0x5548f
movsd (%rbx), %xmm0
movq %r14, %rdi
callq 0x66d1d
xorl %r15d, %r15d
testq %rax, %rax
je 0x5548f
movq %r14, %rdi
movq %r13, %rsi
callq 0x54ef3
testl %eax, %eax
je 0x5548f
incq %rbp
cmpq $0x40, %rbp
movl $0x0, %eax
cmoveq %rax, %rbp
decq %r12
jmp 0x553d7
xorl %r15d, %r15d
jmp 0x5548f
movq (%rsp), %rdi
callq 0x2aa94
pushq $0x1
popq %r15
movl %r15d, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x615a8(%rip), %rdi     # 0xb6a50
leaq 0x60db8(%rip), %rsi     # 0xb6267
movl $0x386, %edx            # imm = 0x386
callq 0x57ac8
pushq $0x1
popq %rdi
callq 0x263c0
leaq 0x615af(%rip), %rdi     # 0xb6a77
leaq 0x60d98(%rip), %rsi     # 0xb6267
movl $0x3b3, %edx            # imm = 0x3B3
callq 0x57b45
jmp 0x554b9
leaq 0x5f6f9(%rip), %rdi     # 0xb4bdb
leaq 0x60d7e(%rip), %rsi     # 0xb6267
movl $0x381, %edx            # imm = 0x381
jmp 0x554b4
leaq 0x5fa0b(%rip), %rdi     # 0xb4f02
leaq 0x60d69(%rip), %rsi     # 0xb6267
movl $0x383, %edx            # imm = 0x383
jmp 0x554b4