// File: /workspace/github_cpp_makefile_star2_O1/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, %r14
movq %rsi, 0x28(%rsp)
movq (%rdi), %rax
movq %rdi, 0x10(%rsp)
movq 0x8(%rdi), %rcx
movq %rcx, 0x60(%rsp)
movq %rax, 0x38(%rsp)
movq 0x18(%rax), %rbx
movl $0x8, %edi
callq 0x2280
movq %rax, %r15
movl $0x0, (%rax)
movq %rbx, 0x30(%rsp)
testl $0x7fffffff, 0x14(%rbx) # imm = 0x7FFFFFFF
je 0x159340
movl $0x1, %r12d
xorl %edi, %edi
movl $0x2, %ecx
xorl %r9d, %r9d
xorl %r10d, %r10d
xorl %r8d, %r8d
movq %r14, 0x20(%rsp)
movq %rcx, 0x40(%rsp)
movq %r12, 0x48(%rsp)
movq %r15, 0x18(%rsp)
movq 0x38(%rsp), %rax
movq 0x10(%rax), %rcx
leaq (%rdi,%rdi,4), %rdx
movl 0x10(%rcx,%rdx,8), %eax
testl %eax, %eax
je 0x1592c3
leaq (%rcx,%rdx,8), %rbx
xorl %r15d, %r15d
movl $0x1, %ebp
xorl %r12d, %r12d
xorl %r11d, %r11d
movq %rdi, 0x50(%rsp)
movl %r11d, %r13d
cmpl %eax, %ebp
je 0x1591df
movq 0x18(%rbx), %rax
movl %ebp, %ecx
movq (%rax,%rcx,8), %rcx
shrq $0x21, %rcx
movb (%r14,%rcx), %cl
movq (%rax,%r13,8), %rax
shrq $0x21, %rax
cmpb (%r14,%rax), %cl
je 0x1592ab
movq 0x18(%rbx), %rax
movq (%rax,%r13,8), %rax
shrq $0x21, %rax
cmpb $0x0, (%r14,%rax)
jne 0x15929a
cmpq %r10, %r9
jne 0x159243
leaq (%r10,%r10), %r14
testq %r10, %r10
movl $0x2, %eax
cmoveq %rax, %r14
leaq (,%r14,8), %rax
leaq (%rax,%rax,2), %rsi
movq %r8, %rdi
movq %r9, 0x58(%rsp)
movl %r11d, 0xc(%rsp)
callq 0x2370
movl 0xc(%rsp), %r11d
movq 0x58(%rsp), %r9
movq 0x50(%rsp), %rdi
movq %rax, %r8
movq %r14, %r10
movq 0x20(%rsp), %r14
leaq (%r9,%r9,2), %rax
incq %r9
movl %edi, 0x10(%r8,%rax,8)
movq 0x18(%rbx), %rcx
movq (%rcx,%r13,8), %rdx
shrq $0x21, %rdx
movb (%r14,%rdx), %dl
movb %dl, 0x14(%r8,%rax,8)
movl %r15d, (%r8,%rax,8)
movq 0x60(%rsp), %rdx
movq 0x20(%rdx), %rdx
leal -0x1(%rbp), %esi
movq (%rcx,%rsi,8), %rcx
shrq $0x21, %rcx
movl (%rdx,%rcx,8), %ecx
movl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
andl %edx, %ecx
addl %r12d, %ecx
decl %ecx
movl %ecx, 0x4(%r8,%rax,8)
movl %r11d, 0x8(%r8,%rax,8)
movl %esi, 0xc(%r8,%rax,8)
movq 0x18(%rbx), %rax
leal -0x1(%rbp), %ecx
movl (%rax,%rcx,8), %r15d
addl %r12d, %r15d
movl %ebp, %r11d
movq 0x18(%rbx), %rax
leal -0x1(%rbp), %ecx
addl (%rax,%rcx,8), %r12d
incl %ebp
movl 0x10(%rbx), %eax
cmpl %eax, %ebp
jbe 0x1591b4
movq 0x48(%rsp), %r12
movq 0x40(%rsp), %rcx
cmpq %rcx, %r12
jne 0x159319
leaq (%rcx,%rcx), %rbx
testq %rcx, %rcx
movl $0x2, %eax
cmoveq %rax, %rbx
leaq (,%rbx,4), %rsi
movq %rdi, %r15
movq 0x18(%rsp), %rdi
movq %r8, %r14
movq %r9, %r13
movq %r10, %rbp
callq 0x2370
movq %rbp, %r10
movq %r13, %r9
movq %r15, %rdi
movq %r14, %r8
movq 0x20(%rsp), %r14
movq %rax, %r15
movq %rbx, %rcx
jmp 0x15931e
movq 0x18(%rsp), %r15
movl %r9d, (%r15,%r12,4)
incq %r12
incq %rdi
movq 0x30(%rsp), %rax
movl 0x14(%rax), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
cmpq %rax, %rdi
jb 0x159175
jmp 0x159343
xorl %r8d, %r8d
movq 0x28(%rsp), %rax
movq (%rax), %rbx
testq %rbx, %rbx
je 0x1593bd
movq 0x10(%rax), %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 %r8, %r13
movq %r8, %rdx
movq %r15, %rcx
movq 0x10(%rsp), %r8
callq 0x159055
testl %eax, %eax
jne 0x1593ad
movq -0x10(%r14), %rdi
movl %r12d, %esi
movq %r13, %rdx
movq %r15, %rcx
movq 0x10(%rsp), %r8
callq 0x159055
testl %eax, %eax
jne 0x1593ad
movq $0x0, -0x8(%r14)
movl %ebp, %eax
addq $0x20, %r14
incl %ebp
cmpq %rax, %rbx
movq %r13, %r8
ja 0x15935d
movq %r8, %rdi
callq 0x2220
movq %r15, %rdi
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x2220