// File: /workspace/github_c_makefile_star2_O0/nilyang[P]redis-tdd-annotation/src/t_zset.c
// Function: zzlInsertAt
unsigned char *zzlInsertAt(unsigned char *zl, unsigned char *eptr, robj *ele, double score) {
    unsigned char *sptr;
    char scorebuf[128];
    int scorelen;
    size_t offset;

    // 计算分值的字节长度
    redisAssertWithInfo(NULL,ele,sdsEncodedObject(ele));
    scorelen = d2string(scorebuf,sizeof(scorebuf),score);

    // 插入到表尾，或者空表
    if (eptr == NULL) {
        // | member-1 | score-1 | member-2 | score-2 | ... | member-N | score-N |
        // 先推入元素
        zl = ziplistPush(zl,ele->ptr,sdslen(ele->ptr),ZIPLIST_TAIL);
        // 后推入分值
        zl = ziplistPush(zl,(unsigned char*)scorebuf,scorelen,ZIPLIST_TAIL);

    // 插入到某个节点的前面
    } else {
        /* Keep offset relative to zl, as it might be re-allocated. */
        // 插入成员
        offset = eptr-zl;
        zl = ziplistInsert(zl,eptr,ele->ptr,sdslen(ele->ptr));
        eptr = zl+offset;

        /* Insert score after the element. */
        // 将分值插入在成员之后
        redisAssertWithInfo(NULL,ele,(sptr = ziplistNext(zl,eptr)) != NULL);
        zl = ziplistInsert(zl,sptr,(unsigned char*)scorebuf,scorelen);
    }

    return zl;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xf0, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movsd %xmm0, -0x20(%rbp)
movq -0x18(%rbp), %rax
movl (%rax), %eax
shrl $0x4, %eax
andl $0xf, %eax
cmpl $0x0, %eax
je 0x4fb3e
movq -0x18(%rbp), %rax
movl (%rax), %eax
shrl $0x4, %eax
andl $0xf, %eax
cmpl $0x8, %eax
jne 0x4fb40
jmp 0x4fb6b
movq -0x18(%rbp), %rsi
xorl %eax, %eax
movl %eax, %edi
leaq 0x93805(%rip), %rdx     # 0xe3354
leaq 0x93738(%rip), %rcx     # 0xe328e
movl $0x573, %r8d            # imm = 0x573
callq 0x648b0
movl $0x1, %edi
callq 0x1f3b0
leaq -0xb0(%rbp), %rdi
movsd -0x20(%rbp), %xmm0
movl $0x80, %esi
callq 0x39a70
movl %eax, -0xb4(%rbp)
cmpq $0x0, -0x10(%rbp)
jne 0x4fbf7
movq -0x8(%rbp), %rax
movq %rax, -0xd0(%rbp)
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0xc8(%rbp)
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rdi
callq 0x4cfd0
movq -0xd0(%rbp), %rdi
movq -0xc8(%rbp), %rsi
movl %eax, %edx
movl $0x1, %ecx
callq 0x32a60
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rdi
leaq -0xb0(%rbp), %rsi
movl -0xb4(%rbp), %edx
movl $0x1, %ecx
callq 0x32a60
movq %rax, -0x8(%rbp)
jmp 0x4fccc
movq -0x10(%rbp), %rax
movq -0x8(%rbp), %rcx
subq %rcx, %rax
movq %rax, -0xc0(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0xe8(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0xe0(%rbp)
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0xd8(%rbp)
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rdi
callq 0x4cfd0
movq -0xe8(%rbp), %rdi
movq -0xe0(%rbp), %rsi
movq -0xd8(%rbp), %rdx
movl %eax, %ecx
callq 0x336c0
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq -0xc0(%rbp), %rax
movq %rax, -0x10(%rbp)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x33330
movq %rax, -0x28(%rbp)
cmpq $0x0, %rax
je 0x4fc83
jmp 0x4fcae
movq -0x18(%rbp), %rsi
xorl %eax, %eax
movl %eax, %edi
leaq 0x936d8(%rip), %rdx     # 0xe336a
leaq 0x935f5(%rip), %rcx     # 0xe328e
movl $0x588, %r8d            # imm = 0x588
callq 0x648b0
movl $0x1, %edi
callq 0x1f3b0
movq -0x8(%rbp), %rdi
movq -0x28(%rbp), %rsi
leaq -0xb0(%rbp), %rdx
movl -0xb4(%rbp), %ecx
callq 0x336c0
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0xf0, %rsp
popq %rbp
retq
nopl (%rax)