// File: /workspace/github_cpp_makefile_star2_O2/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, %rbx
movq %rsi, 0x10(%rsp)
movq (%rdi), %rax
movq %rdi, 0x18(%rsp)
movq 0x8(%rdi), %rcx
movq %rcx, 0x60(%rsp)
movq %rax, 0x30(%rsp)
movq 0x18(%rax), %rax
movq %rax, 0x38(%rsp)
pushq $0x8
popq %rdi
callq 0x2280
movq %rax, %rbp
andl $0x0, (%rax)
pushq $0x1
popq %r15
pushq $0x2
popq %rcx
xorl %r9d, %r9d
xorl %r8d, %r8d
xorl %r11d, %r11d
xorl %r10d, %r10d
movq %rbx, 0x28(%rsp)
movq 0x38(%rsp), %rax
movl 0x14(%rax), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
cmpq %rax, %r9
jae 0x11972e
movq %rcx, 0x40(%rsp)
movq %r15, 0x48(%rsp)
movq %rbp, 0x20(%rsp)
imulq $0x28, %r9, %rdi
movq 0x30(%rsp), %rax
addq 0x10(%rax), %rdi
xorl %ebp, %ebp
xorl %r14d, %r14d
xorl %r13d, %r13d
pushq $0x1
popq %rax
movl %eax, %r15d
movq %r9, 0x50(%rsp)
movq %rdi, 0x8(%rsp)
cmpl 0x10(%rdi), %r15d
ja 0x1196c5
movq 0x18(%rdi), %rax
movl %ebp, %r12d
jne 0x1195e1
movq (%rax,%r12,8), %rcx
movq %rcx, %rdx
shrq $0x21, %rdx
movb (%rbx,%rdx), %dl
jmp 0x119608
movl %r15d, %ecx
movq (%rax,%rcx,8), %rsi
shrq $0x21, %rsi
movq (%rax,%r12,8), %rcx
movq %rcx, %rdx
shrq $0x21, %rdx
movb (%rbx,%rdx), %dl
cmpb %dl, (%rbx,%rsi)
jne 0x119608
leal -0x1(%r15), %ecx
jmp 0x1196b9
testb %dl, %dl
je 0x119615
leal -0x1(%r15), %ecx
jmp 0x1196af
cmpq %r11, %r10
jne 0x11965b
leaq (%r11,%r11), %rbx
testq %r11, %r11
pushq $0x2
popq %rax
cmoveq %rax, %rbx
imulq $0x18, %rbx, %rsi
movq %r8, %rdi
movq %r10, 0x58(%rsp)
callq 0x2370
movq 0x58(%rsp), %r10
movq 0x50(%rsp), %r9
movq %rax, %r8
movq 0x8(%rsp), %rax
movq 0x18(%rax), %rax
movq (%rax,%r12,8), %rcx
movq %rbx, %r11
movq 0x28(%rsp), %rbx
imulq $0x18, %r10, %rdx
incq %r10
movl %r9d, 0x10(%r8,%rdx)
shrq $0x21, %rcx
movb (%rbx,%rcx), %cl
movb %cl, 0x14(%r8,%rdx)
movl %r13d, (%r8,%rdx)
movq 0x60(%rsp), %rcx
movq 0x20(%rcx), %rsi
leal -0x1(%r15), %ecx
movq (%rax,%rcx,8), %rdi
shrq $0x21, %rdi
movl (%rsi,%rdi,8), %esi
movl $0x7fffffff, %edi       # imm = 0x7FFFFFFF
andl %edi, %esi
addl %r14d, %esi
decl %esi
movl %esi, 0x4(%r8,%rdx)
movl %ebp, 0x8(%r8,%rdx)
movl %ecx, 0xc(%r8,%rdx)
movq 0x8(%rsp), %rdi
movl (%rax,%rcx,8), %r13d
addl %r14d, %r13d
movl %r15d, %ebp
addl (%rax,%rcx,8), %r14d
incl %r15d
jmp 0x1195be
movq 0x48(%rsp), %r15
movq 0x40(%rsp), %rcx
cmpq %rcx, %r15
jne 0x119719
leaq (%rcx,%rcx), %rbx
testq %rcx, %rcx
pushq $0x2
popq %rax
cmoveq %rax, %rbx
leaq (,%rbx,4), %rsi
movq 0x20(%rsp), %rdi
movq %r8, %r14
movq %r9, %r12
movq %r10, %r13
movq %r11, %rbp
callq 0x2370
movq %rbp, %r11
movq %r13, %r10
movq %r12, %r9
movq %r14, %r8
movq %rax, %rbp
movq %rbx, %rcx
movq 0x28(%rsp), %rbx
jmp 0x11971e
movq 0x20(%rsp), %rbp
movl %r10d, (%rbp,%r15,4)
incq %r15
incq %r9
jmp 0x119574
movq 0x10(%rsp), %rax
movq (%rax), %rax
movq %rax, 0x8(%rsp)
xorl %r14d, %r14d
movl %r14d, %r14d
cmpq %r14, 0x8(%rsp)
jbe 0x1197b8
movq 0x10(%rsp), %rax
movq 0x10(%rax), %r15
movq %r14, %r12
shlq $0x5, %r12
orq $-0x1, 0x10(%r15,%r12)
movq (%r15,%r12), %rdi
movq 0x18(%r15,%r12), %r13
movq %r13, %rsi
shrq $0x20, %rsi
movq %r8, %rbx
movq %r8, %rdx
movq %rbp, %rcx
movq 0x18(%rsp), %r8
callq 0x119452
testl %eax, %eax
jne 0x1197b0
leaq (%r15,%r12), %rax
movq 0x8(%rax), %rdi
movl %r13d, %esi
movq %rbx, %rdx
movq %rbp, %rcx
movq 0x18(%rsp), %r8
callq 0x119452
testl %eax, %eax
jne 0x1197b0
leaq (%r15,%r12), %rax
addq $0x10, %rax
andq $0x0, (%rax)
incl %r14d
movq %rbx, %r8
jmp 0x11973e
movq %r8, %rdi
callq 0x2220
movq %rbp, %rdi
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x2220