// File: /workspace/github_cpp_makefile_star2_O2/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x78, %rsp
movq %r8, 0x38(%rsp)
movq %rdx, %r12
movq %rsi, %r14
cmpq %rdx, (%rsi)
jbe 0x1214ce
movq %rcx, %rax
shlq $0x4, %rcx
movq 0x10(%r14), %rsi
movq %rcx, 0x30(%rsp)
addq %rcx, %rsi
leaq 0x20(%rsp), %rbx
leaq 0x18(%rsp), %r15
leaq 0x58(%rsp), %rdx
leaq 0x50(%rsp), %rcx
leaq 0x48(%rsp), %r8
leaq 0x28(%rsp), %r13
movq %rdi, 0x40(%rsp)
movq %rax, 0x8(%rsp)
movq %r13, %r9
pushq %rbx
pushq %r15
callq 0x120d2b
movq 0x18(%rsp), %rdi
addq $0x10, %rsp
movq (%r13), %rbp
movq (%rbx), %rax
movsd (%r15), %xmm0
unpcklps 0xc1eba(%rip), %xmm0    # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1]
negq %rax
subpd 0xc1ebf(%rip), %xmm0    # 0x1e3280
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
addsd %xmm0, %xmm1
mulsd 0xc212b(%rip), %xmm1    # 0x1e3500
movapd %xmm1, 0x60(%rsp)
leaq (%rax,%rbp), %rbx
incq %rbx
movq %r12, %r13
shlq $0x4, %r13
pushq $-0x1
popq %rax
movq %rax, 0x10(%rsp)
xorl %r15d, %r15d
movq %r12, (%rsp)
cmpq (%r14), %r12
jae 0x1214d3
cmpq %r12, %rdi
je 0x1214c2
movq 0x10(%r14), %rsi
addq %r13, %rsi
movq 0x40(%rsp), %rdi
leaq 0x58(%rsp), %rdx
leaq 0x50(%rsp), %rcx
leaq 0x48(%rsp), %r8
leaq 0x28(%rsp), %r9
leaq 0x20(%rsp), %rax
pushq %rax
leaq 0x20(%rsp), %rax
pushq %rax
callq 0x120d2b
popq %rax
popq %rcx
movq 0x28(%rsp), %rax
movq 0x20(%rsp), %rcx
negq %rcx
addq %rax, %rcx
incq %rcx
cmpq %rbx, %rcx
cmovbeq %rbx, %rcx
cmpq %rbp, %rax
cmovaeq %rbp, %rax
cmpq %rax, %rcx
ja 0x1214a3
subq %rcx, %rax
incq %rax
cmpq 0x38(%rsp), %rax
jbe 0x1214a3
movsd 0x18(%rsp), %xmm0
unpcklps 0xc1df3(%rip), %xmm0    # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1]
subpd 0xc1dfb(%rip), %xmm0    # 0x1e3280
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
addsd %xmm0, %xmm1
ucomisd 0x60(%rsp), %xmm1
movq 0x8(%rsp), %rdi
jb 0x1214c2
jmp 0x12153f
movq 0x18(%rsp), %rax
cmpq %rax, %r15
cmovbeq %rax, %r15
movq 0x10(%rsp), %rax
cmovbq %r12, %rax
movq %rax, 0x10(%rsp)
movq 0x8(%rsp), %rdi
incq %r12
addq $0x10, %r13
jmp 0x1213f8
movq %r12, (%r14)
jmp 0x121546
movq 0x10(%r14), %rax
movq 0x10(%rsp), %rdx
cmpq $-0x1, %rdx
je 0x121520
cmpq %rdi, %rdx
movq %rdi, %rcx
cmovaq %rdx, %rdi
cmovbq %rdx, %rcx
shlq $0x4, %rcx
movq (%rsp), %rsi
movq %rsi, %rdx
shlq $0x4, %rdx
movups (%rax,%rcx), %xmm0
movups %xmm0, (%rax,%rdx)
movq 0x10(%r14), %rax
shlq $0x4, %rdi
movupd (%rax,%rdi), %xmm0
movupd %xmm0, 0x10(%rax,%rdx)
addq $0x2, %rsi
jmp 0x121543
movq (%rsp), %rsi
movq %rsi, %rcx
shlq $0x4, %rcx
movq 0x30(%rsp), %rdx
movupd (%rax,%rdx), %xmm0
movupd %xmm0, (%rax,%rcx)
incq %rsi
jmp 0x121543
movq (%rsp), %rsi
movq %rsi, (%r14)
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq