// File: chhylp123[P]hifiasm/hic.cpp
// Function: compress_mapped_pos_debug(ha_ug_index const*, kvec_vote*, unsigned long, unsigned long, unsigned long)
inline void compress_mapped_pos_debug(const ha_ug_index* idx, kvec_vote* buf, uint64_t buf_iter, uint64_t max_i, uint64_t thres)
{
    if(buf_iter >= buf->a.n)
    {
        buf->a.n = buf_iter;
        return;
    }
    uint64_t rev, uID, ref_p, self_p, eLen, tLen, i, max_beg, max_end, cur_beg, cur_end, ovlp, max_eLen;
    uint64_t secondLen = 0, second_i = (uint64_t)-1;
    interpret_pos((ha_ug_index*)idx, &buf->a.a[max_i], &rev, &uID, &ref_p, &self_p, &eLen, &tLen);
    max_end = self_p;
    max_beg = self_p + 1 - tLen;
    max_eLen = eLen;
    for (i = buf_iter; i < buf->a.n; i++)
    {
        if(i == max_i) continue;
        interpret_pos(idx, &buf->a.a[i], &rev, &uID, &ref_p, &self_p, &eLen, &tLen);
        cur_end = self_p;
        cur_beg = self_p + 1 - tLen;
        if(MAX(cur_beg, max_beg) <= MIN(cur_end, max_end))
        {
            ovlp = MIN(cur_end, max_end) - MAX(cur_beg, max_beg) + 1;
            if(ovlp > thres)
            {
                if(eLen >= max_eLen * 0.8)
                {
                    buf->a.n = buf_iter;
                    return;
                }
                continue;
            } 
        }
        if(secondLen < eLen) secondLen = eLen, second_i = i;
    }

    if(second_i == (uint64_t)-1)
    {
        buf->a.a[buf_iter] = buf->a.a[max_i];
        buf->a.n = buf_iter + 1;
    }
    else
    {
        buf->a.a[buf_iter] = buf->a.a[MIN(max_i, second_i)];
        buf->a.a[buf_iter+1] = buf->a.a[MAX(max_i, second_i)];
        buf->a.n = buf_iter + 2;
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x100, %rsp            # imm = 0x100
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
movq -0x18(%rbp), %rax
movq -0x10(%rbp), %rcx
cmpq (%rcx), %rax
jb 0x21418c
movq -0x18(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, (%rax)
jmp 0x214540
movq $0x0, -0x98(%rbp)
movq $-0x1, -0xa0(%rbp)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rsi
movq -0x20(%rbp), %rax
shlq $0x4, %rax
addq %rax, %rsi
leaq -0x30(%rbp), %rdx
leaq -0x38(%rbp), %rcx
leaq -0x40(%rbp), %r8
leaq -0x48(%rbp), %r9
leaq -0x50(%rbp), %r10
leaq -0x58(%rbp), %rax
movq %r10, (%rsp)
movq %rax, 0x8(%rsp)
callq 0x213560
movq -0x48(%rbp), %rax
movq %rax, -0x70(%rbp)
movq -0x48(%rbp), %rax
addq $0x1, %rax
subq -0x58(%rbp), %rax
movq %rax, -0x68(%rbp)
movq -0x50(%rbp), %rax
movq %rax, -0x90(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0x60(%rbp)
movq -0x60(%rbp), %rax
movq -0x10(%rbp), %rcx
cmpq (%rcx), %rax
jae 0x214401
movq -0x60(%rbp), %rax
cmpq -0x20(%rbp), %rax
jne 0x21422a
jmp 0x2143f0
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rsi
movq -0x60(%rbp), %rax
shlq $0x4, %rax
addq %rax, %rsi
leaq -0x30(%rbp), %rdx
leaq -0x38(%rbp), %rcx
leaq -0x40(%rbp), %r8
leaq -0x48(%rbp), %r9
leaq -0x50(%rbp), %r10
leaq -0x58(%rbp), %rax
movq %r10, (%rsp)
movq %rax, 0x8(%rsp)
callq 0x213560
movq -0x48(%rbp), %rax
movq %rax, -0x80(%rbp)
movq -0x48(%rbp), %rax
addq $0x1, %rax
subq -0x58(%rbp), %rax
movq %rax, -0x78(%rbp)
movq -0x78(%rbp), %rax
cmpq -0x68(%rbp), %rax
jb 0x214296
movq -0x78(%rbp), %rax
movq %rax, -0xa8(%rbp)
jmp 0x2142a1
movq -0x68(%rbp), %rax
movq %rax, -0xa8(%rbp)
movq -0xa8(%rbp), %rax
movq %rax, -0xb0(%rbp)
movq -0x80(%rbp), %rax
cmpq -0x70(%rbp), %rax
ja 0x2142c6
movq -0x80(%rbp), %rax
movq %rax, -0xb8(%rbp)
jmp 0x2142d1
movq -0x70(%rbp), %rax
movq %rax, -0xb8(%rbp)
movq -0xb0(%rbp), %rax
movq -0xb8(%rbp), %rcx
cmpq %rcx, %rax
ja 0x2143cb
movq -0x80(%rbp), %rax
cmpq -0x70(%rbp), %rax
ja 0x2142ff
movq -0x80(%rbp), %rax
movq %rax, -0xc0(%rbp)
jmp 0x21430a
movq -0x70(%rbp), %rax
movq %rax, -0xc0(%rbp)
movq -0xc0(%rbp), %rax
movq %rax, -0xc8(%rbp)
movq -0x78(%rbp), %rax
cmpq -0x68(%rbp), %rax
jb 0x21432f
movq -0x78(%rbp), %rax
movq %rax, -0xd0(%rbp)
jmp 0x21433a
movq -0x68(%rbp), %rax
movq %rax, -0xd0(%rbp)
movq -0xc8(%rbp), %rax
movq -0xd0(%rbp), %rcx
subq %rcx, %rax
addq $0x1, %rax
movq %rax, -0x88(%rbp)
movq -0x88(%rbp), %rax
cmpq -0x28(%rbp), %rax
jbe 0x2143c9
movq -0x50(%rbp), %xmm0
movaps 0x16dca1(%rip), %xmm3   # 0x382010
punpckldq %xmm3, %xmm0    # xmm0 = xmm0[0],xmm3[0],xmm0[1],xmm3[1]
movapd 0x16dca5(%rip), %xmm2   # 0x382020
subpd %xmm2, %xmm0
movaps %xmm0, %xmm1
unpckhpd %xmm0, %xmm0            # xmm0 = xmm0[1,1]
addsd %xmm1, %xmm0
movq -0x90(%rbp), %xmm1
punpckldq %xmm3, %xmm1    # xmm1 = xmm1[0],xmm3[0],xmm1[1],xmm3[1]
subpd %xmm2, %xmm1
movaps %xmm1, %xmm2
unpckhpd %xmm1, %xmm1            # xmm1 = xmm1[1,1]
addsd %xmm2, %xmm1
movsd 0x16de83(%rip), %xmm2   # 0x382230
mulsd %xmm2, %xmm1
ucomisd %xmm1, %xmm0
jb 0x2143c7
movq -0x18(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, (%rax)
jmp 0x214540
jmp 0x2143f0
jmp 0x2143cb
movq -0x98(%rbp), %rax
cmpq -0x50(%rbp), %rax
jae 0x2143ee
movq -0x50(%rbp), %rax
movq %rax, -0x98(%rbp)
movq -0x60(%rbp), %rax
movq %rax, -0xa0(%rbp)
jmp 0x2143f0
movq -0x60(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x60(%rbp)
jmp 0x21420a
cmpq $-0x1, -0xa0(%rbp)
jne 0x214453
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rcx
movq -0x20(%rbp), %rax
shlq $0x4, %rax
addq %rax, %rcx
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x18(%rbp), %rdx
shlq $0x4, %rdx
addq %rdx, %rax
movq (%rcx), %rdx
movq %rdx, (%rax)
movq 0x8(%rcx), %rcx
movq %rcx, 0x8(%rax)
movq -0x18(%rbp), %rcx
addq $0x1, %rcx
movq -0x10(%rbp), %rax
movq %rcx, (%rax)
jmp 0x214540
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0xd8(%rbp)
movq -0x20(%rbp), %rax
cmpq -0xa0(%rbp), %rax
ja 0x21447c
movq -0x20(%rbp), %rax
movq %rax, -0xe0(%rbp)
jmp 0x21448a
movq -0xa0(%rbp), %rax
movq %rax, -0xe0(%rbp)
movq -0xd8(%rbp), %rcx
movq -0xe0(%rbp), %rax
shlq $0x4, %rax
addq %rax, %rcx
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x18(%rbp), %rdx
shlq $0x4, %rdx
addq %rdx, %rax
movq (%rcx), %rdx
movq %rdx, (%rax)
movq 0x8(%rcx), %rcx
movq %rcx, 0x8(%rax)
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0xe8(%rbp)
movq -0x20(%rbp), %rax
cmpq -0xa0(%rbp), %rax
jb 0x2144e9
movq -0x20(%rbp), %rax
movq %rax, -0xf0(%rbp)
jmp 0x2144f7
movq -0xa0(%rbp), %rax
movq %rax, -0xf0(%rbp)
movq -0xe8(%rbp), %rcx
movq -0xf0(%rbp), %rax
shlq $0x4, %rax
addq %rax, %rcx
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x18(%rbp), %rdx
addq $0x1, %rdx
shlq $0x4, %rdx
addq %rdx, %rax
movq (%rcx), %rdx
movq %rdx, (%rax)
movq 0x8(%rcx), %rcx
movq %rcx, 0x8(%rax)
movq -0x18(%rbp), %rcx
addq $0x2, %rcx
movq -0x10(%rbp), %rax
movq %rcx, (%rax)
addq $0x100, %rsp            # imm = 0x100
popq %rbp
retq
nopl (%rax)