// File: /workspace/github_c_makefile_star2_O0/gplessis[P]dotdeb-redis/src/hyperloglog.c
// Function: hllSparseSum
double hllSparseSum(uint8_t *sparse, int sparselen, double *PE, int *ezp, int *invalid) {
    double E = 0;
    int ez = 0, idx = 0, runlen, regval;
    uint8_t *end = sparse+sparselen, *p = sparse;

    while(p < end) {
        if (HLL_SPARSE_IS_ZERO(p)) {
            runlen = HLL_SPARSE_ZERO_LEN(p);
            idx += runlen;
            ez += runlen;
            /* Increment E at the end of the loop. */
            p++;
        } else if (HLL_SPARSE_IS_XZERO(p)) {
            runlen = HLL_SPARSE_XZERO_LEN(p);
            idx += runlen;
            ez += runlen;
            /* Increment E at the end of the loop. */
            p += 2;
        } else {
            runlen = HLL_SPARSE_VAL_LEN(p);
            regval = HLL_SPARSE_VAL_VALUE(p);
            idx += runlen;
            E += PE[regval]*runlen;
            p++;
        }
    }
    if (idx != HLL_REGISTERS && invalid) *invalid = 1;
    E += ez; /* Add 2^0 'ez' times. */
    *ezp = ez;
    return E;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0x30(%rbp)
movl $0x0, -0x34(%rbp)
movl $0x0, -0x38(%rbp)
movq -0x8(%rbp), %rax
movslq -0xc(%rbp), %rcx
addq %rcx, %rax
movq %rax, -0x48(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x50(%rbp)
movq -0x50(%rbp), %rax
cmpq -0x48(%rbp), %rax
jae 0x9f167
movq -0x50(%rbp), %rax
movzbl (%rax), %eax
andl $0xc0, %eax
cmpl $0x0, %eax
jne 0x9f0b6
movq -0x50(%rbp), %rax
movzbl (%rax), %eax
andl $0x3f, %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
movl -0x3c(%rbp), %eax
addl -0x38(%rbp), %eax
movl %eax, -0x38(%rbp)
movl -0x3c(%rbp), %eax
addl -0x34(%rbp), %eax
movl %eax, -0x34(%rbp)
movq -0x50(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x50(%rbp)
jmp 0x9f162
movq -0x50(%rbp), %rax
movzbl (%rax), %eax
andl $0xc0, %eax
cmpl $0x40, %eax
jne 0x9f104
movq -0x50(%rbp), %rax
movzbl (%rax), %eax
andl $0x3f, %eax
shll $0x8, %eax
movq -0x50(%rbp), %rcx
movzbl 0x1(%rcx), %ecx
orl %ecx, %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
movl -0x3c(%rbp), %eax
addl -0x38(%rbp), %eax
movl %eax, -0x38(%rbp)
movl -0x3c(%rbp), %eax
addl -0x34(%rbp), %eax
movl %eax, -0x34(%rbp)
movq -0x50(%rbp), %rax
addq $0x2, %rax
movq %rax, -0x50(%rbp)
jmp 0x9f160
movq -0x50(%rbp), %rax
movzbl (%rax), %eax
andl $0x3, %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
movq -0x50(%rbp), %rax
movzbl (%rax), %eax
sarl $0x2, %eax
andl $0x1f, %eax
addl $0x1, %eax
movl %eax, -0x40(%rbp)
movl -0x3c(%rbp), %eax
addl -0x38(%rbp), %eax
movl %eax, -0x38(%rbp)
movq -0x18(%rbp), %rax
movslq -0x40(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm0
cvtsi2sdl -0x3c(%rbp), %xmm2
movsd -0x30(%rbp), %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x30(%rbp)
movq -0x50(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x50(%rbp)
jmp 0x9f162
jmp 0x9f064
cmpl $0x4000, -0x38(%rbp)    # imm = 0x4000
je 0x9f181
cmpq $0x0, -0x28(%rbp)
je 0x9f181
movq -0x28(%rbp), %rax
movl $0x1, (%rax)
cvtsi2sdl -0x34(%rbp), %xmm0
addsd -0x30(%rbp), %xmm0
movsd %xmm0, -0x30(%rbp)
movl -0x34(%rbp), %ecx
movq -0x20(%rbp), %rax
movl %ecx, (%rax)
movsd -0x30(%rbp), %xmm0
popq %rbp
retq