// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x80, %rsp
movq %rdi, -0x10(%rbp)
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x18(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0x30(%rbp)
movl $0x0, -0x34(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rax
movq %rax, -0x80(%rbp)
movq -0x18(%rbp), %rdi
callq 0x9e660
movq %rax, %rcx
movq -0x80(%rbp), %rax
addq %rcx, %rax
movq %rax, -0x50(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rax
movzbl 0x4(%rax), %eax
cmpl $0x0, %eax
jne 0x9e422
movl $0x0, -0x4(%rbp)
jmp 0x9e64c
xorl %eax, %eax
movl %eax, %edi
movl $0x3010, %esi           # imm = 0x3010
callq 0x38230
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rax
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rax
movq -0x30(%rbp), %rcx
movq (%rcx), %rdx
movq %rdx, (%rax)
movq 0x8(%rcx), %rcx
movq %rcx, 0x8(%rax)
movq -0x28(%rbp), %rax
movb $0x0, 0x4(%rax)
movq -0x48(%rbp), %rax
addq $0x10, %rax
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rax
cmpq -0x50(%rbp), %rax
jae 0x9e611
movq -0x48(%rbp), %rax
movzbl (%rax), %eax
andl $0xc0, %eax
cmpl $0x0, %eax
jne 0x9e4af
movq -0x48(%rbp), %rax
movzbl (%rax), %eax
andl $0x3f, %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
movl -0x38(%rbp), %eax
addl -0x34(%rbp), %eax
movl %eax, -0x34(%rbp)
movq -0x48(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x48(%rbp)
jmp 0x9e60c
movq -0x48(%rbp), %rax
movzbl (%rax), %eax
andl $0xc0, %eax
cmpl $0x40, %eax
jne 0x9e4f7
movq -0x48(%rbp), %rax
movzbl (%rax), %eax
andl $0x3f, %eax
shll $0x8, %eax
movq -0x48(%rbp), %rcx
movzbl 0x1(%rcx), %ecx
orl %ecx, %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
movl -0x38(%rbp), %eax
addl -0x34(%rbp), %eax
movl %eax, -0x34(%rbp)
movq -0x48(%rbp), %rax
addq $0x2, %rax
movq %rax, -0x48(%rbp)
jmp 0x9e60a
movq -0x48(%rbp), %rax
movzbl (%rax), %eax
andl $0x3, %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
movq -0x48(%rbp), %rax
movzbl (%rax), %eax
sarl $0x2, %eax
andl $0x1f, %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
movl -0x38(%rbp), %eax
movl %eax, %ecx
addl $-0x1, %ecx
movl %ecx, -0x38(%rbp)
cmpl $0x0, %eax
je 0x9e5fe
jmp 0x9e530
movq -0x28(%rbp), %rax
addq $0x10, %rax
movq %rax, -0x58(%rbp)
imull $0x6, -0x34(%rbp), %eax
movl $0x8, %ecx
cltd
idivl %ecx
cltq
movq %rax, -0x60(%rbp)
imull $0x6, -0x34(%rbp), %eax
andl $0x7, %eax
cltq
movq %rax, -0x68(%rbp)
movl $0x8, %eax
subq -0x68(%rbp), %rax
movq %rax, -0x70(%rbp)
movslq -0x3c(%rbp), %rax
movq %rax, -0x78(%rbp)
movq -0x68(%rbp), %rax
movl %eax, %ecx
movl $0x3f, %esi
shll %cl, %esi
xorl $-0x1, %esi
movq -0x58(%rbp), %rax
movq -0x60(%rbp), %rcx
movzbl (%rax,%rcx), %edx
andl %esi, %edx
movb %dl, (%rax,%rcx)
movq -0x78(%rbp), %rsi
movq -0x68(%rbp), %rcx
shlq %cl, %rsi
movq -0x58(%rbp), %rax
movq -0x60(%rbp), %rcx
movzbl (%rax,%rcx), %edx
orq %rsi, %rdx
movb %dl, (%rax,%rcx)
movq -0x70(%rbp), %rax
movl %eax, %ecx
movl $0x3f, %esi
sarl %cl, %esi
xorl $-0x1, %esi
movq -0x58(%rbp), %rax
movq -0x60(%rbp), %rcx
movzbl 0x1(%rax,%rcx), %edx
andl %esi, %edx
movb %dl, 0x1(%rax,%rcx)
movq -0x78(%rbp), %rsi
movq -0x70(%rbp), %rcx
shrq %cl, %rsi
movq -0x58(%rbp), %rax
movq -0x60(%rbp), %rcx
movzbl 0x1(%rax,%rcx), %edx
orq %rsi, %rdx
movb %dl, 0x1(%rax,%rcx)
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0x9e51a
movq -0x48(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x48(%rbp)
jmp 0x9e60c
jmp 0x9e466
cmpl $0x4000, -0x34(%rbp)    # imm = 0x4000
je 0x9e62c
movq -0x20(%rbp), %rdi
callq 0x38620
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x9e64c
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdi
callq 0x38620
movq -0x20(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x8(%rax)
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x80, %rsp
popq %rbp
retq
nopl (%rax,%rax)