// File: /workspace/github_c_makefile_star2_O1/zhou-yuxin[P]redis-aof-no-cow/src/t_zset.c
// Function: zsetConvert
void zsetConvert(robj *zobj, int encoding) {
    zset *zs;
    zskiplistNode *node, *next;
    robj *ele;
    double score;

    if (zobj->encoding == encoding) return;
    if (zobj->encoding == OBJ_ENCODING_ZIPLIST) {
        unsigned char *zl = zobj->ptr;
        unsigned char *eptr, *sptr;
        unsigned char *vstr;
        unsigned int vlen;
        long long vlong;

        if (encoding != OBJ_ENCODING_SKIPLIST)
            serverPanic("Unknown target encoding");

        zs = zmalloc(sizeof(*zs));
        zs->dict = dictCreate(&zsetDictType,NULL);
        zs->zsl = zslCreate();

        eptr = ziplistIndex(zl,0);
        serverAssertWithInfo(NULL,zobj,eptr != NULL);
        sptr = ziplistNext(zl,eptr);
        serverAssertWithInfo(NULL,zobj,sptr != NULL);

        while (eptr != NULL) {
            score = zzlGetScore(sptr);
            serverAssertWithInfo(NULL,zobj,ziplistGet(eptr,&vstr,&vlen,&vlong));
            if (vstr == NULL)
                ele = createStringObjectFromLongLong(vlong);
            else
                ele = createStringObject((char*)vstr,vlen);

            /* Has incremented refcount since it was just created. */
            node = zslInsert(zs->zsl,score,ele);
            serverAssertWithInfo(NULL,zobj,dictAdd(zs->dict,ele,&node->score) == DICT_OK);
            incrRefCount(ele); /* Added to dictionary. */
            zzlNext(zl,&eptr,&sptr);
        }

        zfree(zobj->ptr);
        zobj->ptr = zs;
        zobj->encoding = OBJ_ENCODING_SKIPLIST;
    } else if (zobj->encoding == OBJ_ENCODING_SKIPLIST) {
        unsigned char *zl = ziplistNew();

        if (encoding != OBJ_ENCODING_ZIPLIST)
            serverPanic("Unknown target encoding");

        /* Approach similar to zslFree(), since we want to free the skiplist at
         * the same time as creating the ziplist. */
        zs = zobj->ptr;
        dictRelease(zs->dict);
        node = zs->zsl->header->level[0].forward;
        zfree(zs->zsl->header);
        zfree(zs->zsl);

        while (node) {
            ele = getDecodedObject(node->obj);
            zl = zzlInsertAt(zl,NULL,ele,node->score);
            decrRefCount(ele);

            next = node->level[0].forward;
            zslFreeNode(node);
            node = next;
        }

        zfree(zs);
        zobj->ptr = zl;
        zobj->encoding = OBJ_ENCODING_ZIPLIST;
    } else {
        serverPanic("Unknown sorted set encoding");
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movl (%rdi), %eax
shrl $0x4, %eax
andl $0xf, %eax
cmpl %esi, %eax
je 0x55409
movl %esi, %ebp
movq %rdi, %r13
cmpl $0x7, %eax
je 0x5536d
cmpl $0x5, %eax
jne 0x5545d
cmpl $0x7, %ebp
jne 0x55472
movq 0x8(%r13), %r15
movl $0x10, %edi
callq 0x3b29d
movq %rax, %r14
leaq 0xb0af6(%rip), %rdi     # 0x105d40
xorl %esi, %esi
callq 0x31774
movq %rax, (%r14)
callq 0x53546
movq %rax, 0x8(%r14)
movq %r15, %rdi
xorl %esi, %esi
callq 0x3ea40
movq %rax, 0x8(%rsp)
testq %rax, %rax
je 0x554a1
movq %r13, (%rsp)
movq %r15, %rdi
movq %rax, %rsi
callq 0x3ead6
movq %rax, 0x18(%rsp)
testq %rax, %rax
je 0x554bc
movq 0x8(%rsp), %r13
testq %r13, %r13
je 0x5534b
leaq 0x28(%rsp), %rbp
leaq 0x8(%rsp), %rbx
leaq 0x18(%rsp), %r12
movq 0x18(%rsp), %rdi
callq 0x54417
movsd %xmm0, 0x20(%rsp)
movq %r13, %rdi
leaq 0x30(%rsp), %rsi
leaq 0x14(%rsp), %rdx
movq %rbp, %rcx
callq 0x3eb60
testl %eax, %eax
je 0x55418
movq 0x30(%rsp), %rdi
testq %rdi, %rdi
je 0x552f1
movl 0x14(%rsp), %esi
callq 0x43ba8
jmp 0x552fb
movq 0x28(%rsp), %rdi
callq 0x43bb7
movq %rax, %r13
movq 0x8(%r14), %rdi
movsd 0x20(%rsp), %xmm0
movq %rax, %rsi
callq 0x5361a
movq (%r14), %rdi
leaq 0x8(%rax), %rdx
movq %r13, %rsi
callq 0x31a95
testl %eax, %eax
jne 0x55434
movq %r13, %rdi
callq 0x43c0c
movq %r15, %rdi
movq %rbx, %rsi
movq %r12, %rdx
callq 0x545d7
movq 0x8(%rsp), %r13
testq %r13, %r13
jne 0x552af
movq (%rsp), %rbx
movq 0x8(%rbx), %rdi
callq 0x3b3df
movq %r14, 0x8(%rbx)
movl $0xffffff0f, %eax       # imm = 0xFFFFFF0F
andl (%rbx), %eax
orl $0x70, %eax
movl %eax, (%rbx)
jmp 0x55409
callq 0x3e2e3
cmpl $0x5, %ebp
jne 0x55487
movq %rax, %rbx
movq 0x8(%r13), %r14
movq (%r14), %rdi
callq 0x31ff3
movq 0x8(%r14), %rax
movq (%rax), %rdi
movq 0x18(%rdi), %r15
callq 0x3b3df
movq 0x8(%r14), %rdi
callq 0x3b3df
testq %r15, %r15
je 0x553ed
movq (%r15), %rdi
callq 0x444b2
movq %rax, %r12
movsd 0x8(%r15), %xmm0
movq %rbx, %rdi
xorl %esi, %esi
movq %rax, %rdx
callq 0x54d54
movq %rax, %rbx
movq %r12, %rdi
callq 0x440f3
movq (%r15), %rdi
movq 0x18(%r15), %r12
callq 0x440f3
movq %r15, %rdi
callq 0x3b3df
movq %r12, %r15
testq %r12, %r12
jne 0x553a8
movq %r14, %rdi
callq 0x3b3df
movq %rbx, 0x8(%r13)
movl $0xffffff0f, %eax       # imm = 0xFFFFFF0F
andl (%r13), %eax
orl $0x50, %eax
movl %eax, (%r13)
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x7126e(%rip), %rdx     # 0xc668d
leaq 0x71230(%rip), %rcx     # 0xc6656
xorl %edi, %edi
movq (%rsp), %rsi
movl $0x461, %r8d            # imm = 0x461
jmp 0x5544e
leaq 0x71337(%rip), %rdx     # 0xc6772
leaq 0x71214(%rip), %rcx     # 0xc6656
xorl %edi, %edi
movq (%rsp), %rsi
movl $0x469, %r8d            # imm = 0x469
callq 0x66380
movl $0x1, %edi
callq 0x263d0
leaq 0x6e812(%rip), %rdi     # 0xc3c76
leaq 0x711eb(%rip), %rsi     # 0xc6656
movl $0x48d, %edx            # imm = 0x48D
jmp 0x5549a
leaq 0x712df(%rip), %rdi     # 0xc6758
leaq 0x711d6(%rip), %rsi     # 0xc6656
movl $0x454, %edx            # imm = 0x454
jmp 0x5549a
leaq 0x712ca(%rip), %rdi     # 0xc6758
leaq 0x711c1(%rip), %rsi     # 0xc6656
movl $0x475, %edx            # imm = 0x475
callq 0x6558d
jmp 0x55453
leaq 0x71237(%rip), %rdx     # 0xc66df
leaq 0x711a7(%rip), %rcx     # 0xc6656
xorl %edi, %edi
movq %r13, %rsi
movl $0x45b, %r8d            # imm = 0x45B
jmp 0x5544e
leaq 0x71543(%rip), %rdx     # 0xc6a06
leaq 0x7118c(%rip), %rcx     # 0xc6656
xorl %edi, %edi
movq (%rsp), %rsi
movl $0x45d, %r8d            # imm = 0x45D
jmp 0x5544e