// File: /workspace/github_c_makefile_star2_O1/nilyang[P]redis-tdd-annotation/src/hyperloglog.c
// Function: hllSparseToDense
int hllSparseToDense(robj *o) {
    sds sparse = o->ptr, dense;
    struct hllhdr *hdr, *oldhdr = (struct hllhdr*)sparse;
    int idx = 0, runlen, regval;
    uint8_t *p = (uint8_t*)sparse, *end = p+sdslen(sparse);

    /* If the representation is already the right one return ASAP. */
    hdr = (struct hllhdr*) sparse;
    if (hdr->encoding == HLL_DENSE) return REDIS_OK;

    /* Create a string of the right size filled with zero bytes.
     * Note that the cached cardinality is set to 0 as a side effect
     * that is exactly the cardinality of an empty HLL. */
    dense = sdsnewlen(NULL,HLL_DENSE_SIZE);
    hdr = (struct hllhdr*) dense;
    *hdr = *oldhdr; /* This will copy the magic and cached cardinality. */
    hdr->encoding = HLL_DENSE;

    /* Now read the sparse representation and set non-zero registers
     * accordingly. */
    p += HLL_HDR_SIZE;
    while(p < end) {
        if (HLL_SPARSE_IS_ZERO(p)) {
            runlen = HLL_SPARSE_ZERO_LEN(p);
            idx += runlen;
            p++;
        } else if (HLL_SPARSE_IS_XZERO(p)) {
            runlen = HLL_SPARSE_XZERO_LEN(p);
            idx += runlen;
            p += 2;
        } else {
            runlen = HLL_SPARSE_VAL_LEN(p);
            regval = HLL_SPARSE_VAL_VALUE(p);
            while(runlen--) {
                HLL_DENSE_SET_REGISTER(hdr->registers,idx,regval);
                idx++;
            }
            p++;
        }
    }

    /* If the sparse representation was valid, we expect to find idx
     * set to HLL_REGISTERS. */
    if (idx != HLL_REGISTERS) {
        sdsfree(dense);
        return REDIS_ERR;
    }

    /* Free the old representation and set the new one. */
    sdsfree(o->ptr);
    o->ptr = dense;
    return REDIS_OK;
}

// Assembly:
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
movq 0x8(%rdi), %r15
cmpb $0x0, 0x4(%r15)
je 0x61503
movq %rdi, %rbx
movslq -0x8(%r15), %r12
xorl %r13d, %r13d
movl $0x3010, %esi           # imm = 0x3010
xorl %edi, %edi
callq 0x28148
movq %rax, %r14
movups (%r15), %xmm0
movups %xmm0, (%rax)
movb $0x0, 0x4(%rax)
cmpl $0x11, %r12d
jl 0x61507
addq %r15, %r12
addq $0x10, %r15
movzbl (%r15), %edx
movl %edx, %eax
andl $-0x40, %eax
cmpl $0x40, %eax
je 0x61441
testl %eax, %eax
jne 0x6145f
addl %edx, %r13d
incl %r13d
jmp 0x614dc
andl $0x3f, %edx
shll $0x8, %edx
movzbl 0x1(%r15), %eax
addl %edx, %r13d
addl %eax, %r13d
incl %r13d
movl $0x2, %eax
jmp 0x614e1
movl %edx, %esi
notl %esi
shrl $0x2, %edx
andl $0x1f, %edx
incq %rdx
leal (,%r13,2), %eax
leal (%rax,%rax,2), %edi
orl $-0x4, %esi
xorl %r8d, %r8d
leal 0x7(%rdi), %eax
testl %edi, %edi
cmovnsl %edi, %eax
sarl $0x3, %eax
movslq %eax, %r9
movl %edi, %ecx
andb $0x6, %cl
movl $0x3f, %eax
shll %cl, %eax
notb %al
andb 0x10(%r14,%r9), %al
movq %rdx, %r10
shlq %cl, %r10
orb %al, %r10b
movb %r10b, 0x10(%r14,%r9)
movb $0x8, %al
subb %cl, %al
movl $0xffffffc0, %r10d      # imm = 0xFFFFFFC0
movl %eax, %ecx
sarl %cl, %r10d
andb 0x11(%r14,%r9), %r10b
movq %rdx, %r11
shrq %cl, %r11
orb %r10b, %r11b
movb %r11b, 0x11(%r14,%r9)
addl $0x6, %edi
decl %r8d
cmpl %r8d, %esi
jne 0x6147d
subl %r8d, %r13d
movl $0x1, %eax
addq %rax, %r15
cmpq %r12, %r15
jb 0x61424
cmpl $0x4000, %r13d          # imm = 0x4000
jne 0x61507
movq 0x8(%rbx), %rdi
callq 0x28204
movq %r14, 0x8(%rbx)
xorl %eax, %eax
jmp 0x61514
movq %r14, %rdi
callq 0x28204
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq