// File: /workspace/github_c_makefile_star2_O3/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 %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
movq %rdi, %rbx
movq 0x8(%rdi), %r15
movzbl -0x1(%r15), %r12d
movl %r12d, %ecx
andl $0x7, %ecx
xorl %eax, %eax
cmpl $0x4, %ecx
ja 0x7d2c7
leaq 0x5064e(%rip), %rdx     # 0xcd8ec
movslq (%rdx,%rcx,4), %rcx
addq %rdx, %rcx
jmpq *%rcx
shrl $0x3, %r12d
jmp 0x7d2ca
movq -0x11(%r15), %r12
jmp 0x7d2ca
movzwl -0x5(%r15), %r12d
jmp 0x7d2ca
movl -0x9(%r15), %r12d
jmp 0x7d2ca
movzbl -0x3(%r15), %r12d
jmp 0x7d2ca
xorl %r12d, %r12d
cmpb $0x0, 0x4(%r15)
je 0x7d3f3
xorl %r13d, %r13d
movl $0x3010, %esi           # imm = 0x3010
xorl %edi, %edi
callq 0x36178
movq %rax, %r14
movups (%r15), %xmm0
movups %xmm0, (%rax)
movb $0x0, 0x4(%rax)
cmpq $0x11, %r12
jl 0x7d3e6
addq %r15, %r12
addq $0x10, %r15
movzbl (%r15), %edx
movl %edx, %eax
andl $-0x40, %eax
cmpl $0x40, %eax
je 0x7d320
testl %eax, %eax
jne 0x7d33e
addl %edx, %r13d
incl %r13d
jmp 0x7d3bb
andl $0x3f, %edx
shll $0x8, %edx
movzbl 0x1(%r15), %eax
addl %edx, %r13d
addl %eax, %r13d
incl %r13d
movl $0x2, %eax
jmp 0x7d3c0
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 0x7d35c
subl %r8d, %r13d
movl $0x1, %eax
addq %rax, %r15
cmpq %r12, %r15
jb 0x7d303
cmpl $0x4000, %r13d          # imm = 0x4000
jne 0x7d3e6
movq 0x8(%rbx), %rdi
callq 0x36330
movq %r14, 0x8(%rbx)
xorl %eax, %eax
jmp 0x7d3f3
movq %r14, %rdi
callq 0x36330
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq