// File: /workspace/github_c_makefile_star2_O3/gplessis[P]dotdeb-redis/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 0x51ce1
movl %esi, %ebp
movq %rdi, %r13
cmpl $0x7, %eax
je 0x51c45
cmpl $0x5, %eax
jne 0x51d35
cmpl $0x7, %ebp
jne 0x51d4a
movq %r13, (%rsp)
movq 0x8(%r13), %r15
movl $0x10, %edi
callq 0x382d1
movq %rax, %r14
leaq 0xaf2af(%rip), %rdi     # 0x100de0
xorl %esi, %esi
callq 0x2e68c
movq %rax, (%r14)
callq 0x4fe06
movq %rax, 0x8(%r14)
movq %r15, %rdi
xorl %esi, %esi
callq 0x3b680
movq %rax, 0x18(%rsp)
testq %rax, %rax
je 0x51d79
movq %rax, %r13
movq %r15, %rdi
movq %rax, %rsi
callq 0x3b745
movq %rax, 0x10(%rsp)
testq %rax, %rax
je 0x51d95
leaq 0x28(%rsp), %rbp
leaq 0x18(%rsp), %rbx
leaq 0x10(%rsp), %r12
movq 0x10(%rsp), %rdi
callq 0x50d7b
movsd %xmm0, 0x20(%rsp)
movq %r13, %rdi
leaq 0x30(%rsp), %rsi
leaq 0xc(%rsp), %rdx
movq %rbp, %rcx
callq 0x3b7cf
testl %eax, %eax
je 0x51cf0
movq 0x30(%rsp), %rdi
testq %rdi, %rdi
je 0x51bc9
movl 0xc(%rsp), %esi
callq 0x40744
jmp 0x51bd3
movq 0x28(%rsp), %rdi
callq 0x40753
movq %rax, %r13
movq 0x8(%r14), %rdi
movsd 0x20(%rsp), %xmm0
movq %rax, %rsi
callq 0x4feda
movq (%r14), %rdi
leaq 0x8(%rax), %rdx
movq %r13, %rsi
callq 0x2e9b8
testl %eax, %eax
jne 0x51d0c
movq %r13, %rdi
callq 0x407a8
movq %r15, %rdi
movq %rbx, %rsi
movq %r12, %rdx
callq 0x50f41
movq 0x18(%rsp), %r13
testq %r13, %r13
jne 0x51b87
movq (%rsp), %rbx
movq 0x8(%rbx), %rdi
callq 0x38413
movq %r14, 0x8(%rbx)
movl $0xffffff0f, %eax       # imm = 0xFFFFFF0F
andl (%rbx), %eax
orl $0x70, %eax
movl %eax, (%rbx)
jmp 0x51ce1
callq 0x3ae98
cmpl $0x5, %ebp
jne 0x51d5f
movq %rax, %rbx
movq 0x8(%r13), %r14
movq (%r14), %rdi
callq 0x2eef3
movq 0x8(%r14), %rax
movq (%rax), %rdi
movq 0x18(%rdi), %r15
callq 0x38413
movq 0x8(%r14), %rdi
callq 0x38413
testq %r15, %r15
je 0x51cc5
movq (%r15), %rdi
callq 0x41026
movq %rax, %r12
movsd 0x8(%r15), %xmm0
movq %rbx, %rdi
xorl %esi, %esi
movq %rax, %rdx
callq 0x5167c
movq %rax, %rbx
movq %r12, %rdi
callq 0x40c8f
movq (%r15), %rdi
movq 0x18(%r15), %r12
callq 0x40c8f
movq %r15, %rdi
callq 0x38413
movq %r12, %r15
testq %r12, %r12
jne 0x51c80
movq %r14, %rdi
callq 0x38413
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 0x71a16(%rip), %rdx     # 0xc370d
leaq 0x719d8(%rip), %rcx     # 0xc36d6
xorl %edi, %edi
movq (%rsp), %rsi
movl $0x461, %r8d            # imm = 0x461
jmp 0x51d26
leaq 0x71adf(%rip), %rdx     # 0xc37f2
leaq 0x719bc(%rip), %rcx     # 0xc36d6
xorl %edi, %edi
movq (%rsp), %rsi
movl $0x469, %r8d            # imm = 0x469
callq 0x627c3
movl $0x1, %edi
callq 0x263c0
leaq 0x6ef8a(%rip), %rdi     # 0xc0cc6
leaq 0x71993(%rip), %rsi     # 0xc36d6
movl $0x48d, %edx            # imm = 0x48D
jmp 0x51d72
leaq 0x71a87(%rip), %rdi     # 0xc37d8
leaq 0x7197e(%rip), %rsi     # 0xc36d6
movl $0x454, %edx            # imm = 0x454
jmp 0x51d72
leaq 0x71a72(%rip), %rdi     # 0xc37d8
leaq 0x71969(%rip), %rsi     # 0xc36d6
movl $0x475, %edx            # imm = 0x475
callq 0x619b4
jmp 0x51d2b
leaq 0x719df(%rip), %rdx     # 0xc375f
leaq 0x7194f(%rip), %rcx     # 0xc36d6
xorl %edi, %edi
movq (%rsp), %rsi
movl $0x45b, %r8d            # imm = 0x45B
jmp 0x51d26
leaq 0x71cea(%rip), %rdx     # 0xc3a86
leaq 0x71933(%rip), %rcx     # 0xc36d6
xorl %edi, %edi
movq (%rsp), %rsi
movl $0x45d, %r8d            # imm = 0x45D
jmp 0x51d26