// File: /workspace/github_cpp_makefile_star2_O3/chhylp123[P]hifiasm/hic.cpp
// Function: update_hits(ha_ug_index*, kvec_pe_hit*, unsigned char*)
void update_hits(ha_ug_index* idx, kvec_pe_hit* hits, uint8_t *r_het)
{
    ma_ug_t *ug = idx->ug;
    asg_t *rg = idx->read_g;
    uint32_t k, v, l, offset, l_pos;
    asg_t* nsg = ug->g;
    ma_utg_t *u = NULL;
    mc_interval_t *t = NULL;
    kvec_t(mc_interval_t) p; kv_init(p);
    kvec_t(uint32_t) p_idx; kv_init(p_idx);

    kv_push(uint32_t, p_idx, 0);
    for (v = 0; v < nsg->n_seq; v++)
    {
        u = &(ug->u.a[v]);
        for (k = 1, l = 0, offset = 0, l_pos = 0; k <= u->n; ++k) 
        {   
            if (k == u->n || r_het[u->a[k]>>33] != r_het[u->a[l]>>33])
            {
                if(r_het[u->a[l]>>33] == N_HET)///only keep hom suregions
                {
                    kv_pushp(mc_interval_t, p, &t);
                    t->uID = v;
                    t->hs = r_het[u->a[l]>>33];

                    t->bS = l_pos;
                    t->bE = offset + rg->seq[u->a[k-1]>>33].len - 1;

                    t->nS = l;
                    t->nE = k - 1;
                }
                l = k;
                l_pos = offset + (uint32_t)u->a[k-1];
            }
            offset += (uint32_t)u->a[k-1];
        }
        kv_push(uint32_t, p_idx, p.n);
    }
    

    for (k = 0; k < hits->a.n; ++k)
    {
        hits->a.a[k].id = (uint64_t)-1;
        if(is_hom_map(hits->a.a[k].s, hits->a.a[k].len>>32, p.a, p_idx.a, idx) || 
           is_hom_map(hits->a.a[k].e, (uint32_t)hits->a.a[k].len, p.a, p_idx.a, idx))
        {
            continue;
        }
        hits->a.a[k].id = 0;
    }

    kv_destroy(p); kv_destroy(p_idx);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movq %rdx, 0x8(%rsp)
movq %rsi, 0x30(%rsp)
movq (%rdi), %rax
movq %rdi, 0x10(%rsp)
movq 0x8(%rdi), %rcx
movq %rcx, 0x60(%rsp)
movq %rax, 0x40(%rsp)
movq 0x18(%rax), %rbx
movl $0x8, %edi
callq 0x2280
movl $0x0, (%rax)
movq %rbx, 0x38(%rsp)
testl $0x7fffffff, 0x14(%rbx) # imm = 0x7FFFFFFF
je 0x15fcb7
movl $0x1, %ebx
xorl %r10d, %r10d
movl $0x2, %ecx
movq %rcx, 0x18(%rsp)
xorl %r11d, %r11d
movq $0x0, 0x28(%rsp)
xorl %r15d, %r15d
movq 0x8(%rsp), %r9
movq %rbx, 0x48(%rsp)
movq %rax, 0x20(%rsp)
movq 0x40(%rsp), %rax
movq 0x10(%rax), %rcx
leaq (%r10,%r10,4), %rdx
movl 0x10(%rcx,%rdx,8), %eax
testl %eax, %eax
je 0x15fc55
leaq (%rcx,%rdx,8), %rcx
movq %rcx, 0x50(%rsp)
movq 0x18(%rcx), %rcx
xorl %r12d, %r12d
movl $0x1, %ebx
xorl %ebp, %ebp
xorl %r14d, %r14d
movl %r14d, %r13d
cmpl %eax, %ebx
jne 0x15fb61
movq (%rcx,%r13,8), %rdx
movq %rdx, %rsi
shrq $0x21, %rsi
movb (%r9,%rsi), %sil
jmp 0x15fb88
movl %ebx, %edx
movq (%rcx,%rdx,8), %rdi
shrq $0x21, %rdi
movq (%rcx,%r13,8), %rdx
movq %rdx, %rsi
shrq $0x21, %rsi
movb (%r9,%rsi), %sil
cmpb %sil, (%r9,%rdi)
jne 0x15fb88
leal -0x1(%rbx), %edx
jmp 0x15fc48
testb %sil, %sil
je 0x15fb95
leal -0x1(%rbx), %edx
jmp 0x15fc3e
cmpq 0x28(%rsp), %r11
jne 0x15fbed
leaq (%r11,%r11), %rcx
testq %r11, %r11
movl $0x2, %eax
cmoveq %rax, %rcx
movq %rcx, 0x28(%rsp)
leaq (,%rcx,8), %rax
leaq (%rax,%rax,2), %rsi
movq %r15, %rdi
movq %r10, %r15
movq %r11, 0x58(%rsp)
callq 0x2370
movq 0x58(%rsp), %r11
movq %r15, %r10
movq 0x8(%rsp), %r9
movq %rax, %r15
movq 0x50(%rsp), %rax
movq 0x18(%rax), %rcx
movq (%rcx,%r13,8), %rdx
movl 0x10(%rax), %eax
leaq (%r11,%r11,2), %rsi
incq %r11
movl %r10d, 0x10(%r15,%rsi,8)
shrq $0x21, %rdx
movb (%r9,%rdx), %dl
movb %dl, 0x14(%r15,%rsi,8)
movl %r12d, (%r15,%rsi,8)
movq 0x60(%rsp), %rdx
movq 0x20(%rdx), %rdi
leal -0x1(%rbx), %edx
movq (%rcx,%rdx,8), %r8
shrq $0x21, %r8
movl (%rdi,%r8,8), %edi
movl $0x7fffffff, %r8d       # imm = 0x7FFFFFFF
andl %r8d, %edi
addl %ebp, %edi
decl %edi
movl %edi, 0x4(%r15,%rsi,8)
movl %r14d, 0x8(%r15,%rsi,8)
movl %edx, 0xc(%r15,%rsi,8)
movl (%rcx,%rdx,8), %r12d
addl %ebp, %r12d
movl %ebx, %r14d
addl (%rcx,%rdx,8), %ebp
incl %ebx
cmpl %eax, %ebx
jbe 0x15fb49
movq 0x48(%rsp), %rbx
cmpq 0x18(%rsp), %rbx
jne 0x15fc8f
leaq (%rbx,%rbx), %rax
movq %rax, 0x18(%rsp)
leaq (,%rbx,8), %rsi
movq 0x20(%rsp), %rdi
movq %r10, %r14
movq %r11, %r12
callq 0x2370
movq %r12, %r11
movq %r14, %r10
movq 0x8(%rsp), %r9
jmp 0x15fc94
movq 0x20(%rsp), %rax
movl %r11d, (%rax,%rbx,4)
incq %rbx
incq %r10
movq 0x38(%rsp), %rcx
movl 0x14(%rcx), %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
cmpq %rcx, %r10
jb 0x15fb0c
jmp 0x15fcba
xorl %r15d, %r15d
movq 0x30(%rsp), %rcx
movq (%rcx), %rbx
testq %rbx, %rbx
je 0x15fd34
movq 0x10(%rcx), %r14
addq $0x18, %r14
movl $0x1, %ebp
movq $-0x1, -0x8(%r14)
movq -0x18(%r14), %rdi
movq (%r14), %r12
movq %r12, %rsi
shrq $0x20, %rsi
movq %r15, %rdx
movq %rax, %r13
movq %rax, %rcx
movq 0x10(%rsp), %r8
callq 0x15f9de
testl %eax, %eax
jne 0x15fd24
movq -0x10(%r14), %rdi
movl %r12d, %esi
movq %r15, %rdx
movq %r13, %rcx
movq 0x10(%rsp), %r8
callq 0x15f9de
testl %eax, %eax
jne 0x15fd24
movq $0x0, -0x8(%r14)
movl %ebp, %eax
addq $0x20, %r14
incl %ebp
cmpq %rax, %rbx
movq %r13, %rax
ja 0x15fcd4
movq %r15, %rdi
movq %rax, %rbx
callq 0x2220
movq %rbx, %rdi
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x2220