// File: /workspace/github_c_makefile_star2_O2/gplessis[P]dotdeb-redis/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 C_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 C_ERR;
    }

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

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rdi, %rbx
movq 0x8(%rdi), %r14
movq %r14, %rdi
callq 0x70863
cmpb $0x0, 0x4(%r14)
je 0x70845
movq %rbx, 0x10(%rsp)
addq %r14, %rax
movq %rax, 0x8(%rsp)
xorl %r13d, %r13d
movl $0x3010, %esi           # imm = 0x3010
xorl %edi, %edi
callq 0x31018
movq 0x8(%rsp), %rcx
movq %rax, %r12
movups (%r14), %xmm0
movups %xmm0, (%rax)
movb $0x0, 0x4(%rax)
addq $0x10, %r14
pushq $0x1
popq %rdx
pushq $0x8
popq %r9
pushq $0x3f
popq %r10
pushq $-0x40
popq %r15
cmpq %rcx, %r14
jae 0x7082a
movzbl (%r14), %r8d
movl %r8d, %eax
andl $-0x40, %eax
cmpl $0x40, %eax
je 0x7078e
testl %eax, %eax
jne 0x707a9
addl %r8d, %r13d
incl %r13d
movq %rdx, %rax
jmp 0x70822
andl $0x3f, %r8d
shll $0x8, %r8d
movzbl 0x1(%r14), %eax
addl %r8d, %r13d
addl %eax, %r13d
incl %r13d
pushq $0x2
popq %rax
jmp 0x70822
movl %r8d, %ebx
notl %ebx
shrl $0x2, %r8d
andl $0x1f, %r8d
incq %r8
orl $-0x4, %ebx
imull $0x6, %r13d, %esi
xorl %edi, %edi
cmpl %edi, %ebx
je 0x70814
movl %esi, %eax
cltd
idivl %r9d
movslq %eax, %rdx
movl %esi, %ecx
andb $0x6, %cl
movl %r10d, %eax
shll %cl, %eax
notb %al
andb 0x10(%r12,%rdx), %al
movq %r8, %rbp
shlq %cl, %rbp
orb %al, %bpl
movb $0x8, %al
subb %cl, %al
movl %r15d, %r11d
movl %eax, %ecx
sarl %cl, %r11d
movb %bpl, 0x10(%r12,%rdx)
andb 0x11(%r12,%rdx), %r11b
movq %r8, %rbp
shrq %cl, %rbp
orb %r11b, %bpl
movb %bpl, 0x11(%r12,%rdx)
decl %edi
addl $0x6, %esi
jmp 0x707c2
subl %edi, %r13d
pushq $0x1
popq %rdx
movq %rdx, %rax
movq 0x8(%rsp), %rcx
addq %rax, %r14
jmp 0x70764
cmpl $0x4000, %r13d          # imm = 0x4000
jne 0x70849
movq 0x10(%rsp), %rbx
movq 0x8(%rbx), %rdi
callq 0x311c8
movq %r12, 0x8(%rbx)
xorl %eax, %eax
jmp 0x70854
movq %r12, %rdi
callq 0x311c8
pushq $-0x1
popq %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq