// File: 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
movq %rsp, %rbp
subq $0xa0, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq -0x8(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x20(%rbp)
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x28(%rbp)
movq -0x20(%rbp), %rax
movq 0x18(%rax), %rax
movq %rax, -0x48(%rbp)
movq $0x0, -0x50(%rbp)
movq $0x0, -0x58(%rbp)
movq $0x0, -0x68(%rbp)
movq $0x0, -0x70(%rbp)
movq $0x0, -0x60(%rbp)
movq $0x0, -0x80(%rbp)
movq $0x0, -0x88(%rbp)
movq $0x0, -0x78(%rbp)
movq -0x88(%rbp), %rax
cmpq -0x80(%rbp), %rax
jne 0x204baf
cmpq $0x0, -0x80(%rbp)
je 0x204b81
movq -0x80(%rbp), %rax
shlq %rax
movq %rax, -0x90(%rbp)
jmp 0x204b8f
movl $0x2, %eax
movq %rax, -0x90(%rbp)
jmp 0x204b8f
movq -0x90(%rbp), %rax
movq %rax, -0x80(%rbp)
movq -0x78(%rbp), %rdi
movq -0x80(%rbp), %rsi
shlq $0x2, %rsi
callq 0x2360
movq %rax, -0x78(%rbp)
movq -0x78(%rbp), %rax
movq -0x88(%rbp), %rcx
movq %rcx, %rdx
addq $0x1, %rdx
movq %rdx, -0x88(%rbp)
movl $0x0, (%rax,%rcx,4)
movl $0x0, -0x30(%rbp)
movl -0x30(%rbp), %eax
movq -0x48(%rbp), %rcx
movl 0x14(%rcx), %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
cmpl %ecx, %eax
jae 0x204e5c
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x30(%rbp), %ecx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x50(%rbp)
movl $0x1, -0x2c(%rbp)
movl $0x0, -0x34(%rbp)
movl $0x0, -0x38(%rbp)
movl $0x0, -0x3c(%rbp)
movl -0x2c(%rbp), %eax
movq -0x50(%rbp), %rcx
cmpl 0x10(%rcx), %eax
ja 0x204dd6
movl -0x2c(%rbp), %eax
movq -0x50(%rbp), %rcx
cmpl 0x10(%rcx), %eax
je 0x204c7a
movq -0x18(%rbp), %rax
movq -0x50(%rbp), %rcx
movq 0x18(%rcx), %rcx
movl -0x2c(%rbp), %edx
movq (%rcx,%rdx,8), %rcx
shrq $0x21, %rcx
movzbl (%rax,%rcx), %eax
movq -0x18(%rbp), %rcx
movq -0x50(%rbp), %rdx
movq 0x18(%rdx), %rdx
movl -0x34(%rbp), %esi
movq (%rdx,%rsi,8), %rdx
shrq $0x21, %rdx
movzbl (%rcx,%rdx), %ecx
cmpl %ecx, %eax
je 0x204dae
movq -0x18(%rbp), %rax
movq -0x50(%rbp), %rcx
movq 0x18(%rcx), %rcx
movl -0x34(%rbp), %edx
movq (%rcx,%rdx,8), %rcx
shrq $0x21, %rcx
movzbl (%rax,%rcx), %eax
cmpl $0x0, %eax
jne 0x204d8c
jmp 0x204ca0
movq -0x70(%rbp), %rax
cmpq -0x68(%rbp), %rax
jne 0x204cec
cmpq $0x0, -0x68(%rbp)
je 0x204cc1
movq -0x68(%rbp), %rax
shlq %rax
movq %rax, -0x98(%rbp)
jmp 0x204ccf
movl $0x2, %eax
movq %rax, -0x98(%rbp)
jmp 0x204ccf
movq -0x98(%rbp), %rax
movq %rax, -0x68(%rbp)
movq -0x60(%rbp), %rdi
imulq $0x18, -0x68(%rbp), %rsi
callq 0x2360
movq %rax, -0x60(%rbp)
movq -0x60(%rbp), %rax
movq -0x70(%rbp), %rcx
movq %rcx, %rdx
addq $0x1, %rdx
movq %rdx, -0x70(%rbp)
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x58(%rbp)
movl -0x30(%rbp), %ecx
movq -0x58(%rbp), %rax
movl %ecx, 0x10(%rax)
movq -0x18(%rbp), %rax
movq -0x50(%rbp), %rcx
movq 0x18(%rcx), %rcx
movl -0x34(%rbp), %edx
movq (%rcx,%rdx,8), %rcx
shrq $0x21, %rcx
movb (%rax,%rcx), %cl
movq -0x58(%rbp), %rax
movb %cl, 0x14(%rax)
movl -0x3c(%rbp), %ecx
movq -0x58(%rbp), %rax
movl %ecx, (%rax)
movl -0x38(%rbp), %ecx
movq -0x28(%rbp), %rax
movq 0x20(%rax), %rax
movq -0x50(%rbp), %rdx
movq 0x18(%rdx), %rdx
movl -0x2c(%rbp), %esi
subl $0x1, %esi
movl %esi, %esi
movq (%rdx,%rsi,8), %rdx
shrq $0x21, %rdx
movl (%rax,%rdx,8), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
addl %eax, %ecx
subl $0x1, %ecx
movq -0x58(%rbp), %rax
movl %ecx, 0x4(%rax)
movl -0x34(%rbp), %ecx
movq -0x58(%rbp), %rax
movl %ecx, 0x8(%rax)
movl -0x2c(%rbp), %ecx
subl $0x1, %ecx
movq -0x58(%rbp), %rax
movl %ecx, 0xc(%rax)
movl -0x2c(%rbp), %eax
movl %eax, -0x34(%rbp)
movl -0x38(%rbp), %eax
movq -0x50(%rbp), %rcx
movq 0x18(%rcx), %rcx
movl -0x2c(%rbp), %edx
subl $0x1, %edx
movl %edx, %edx
movq (%rcx,%rdx,8), %rcx
addl %ecx, %eax
movl %eax, -0x3c(%rbp)
movq -0x50(%rbp), %rax
movq 0x18(%rax), %rax
movl -0x2c(%rbp), %ecx
subl $0x1, %ecx
movl %ecx, %ecx
movq (%rax,%rcx,8), %rax
addl -0x38(%rbp), %eax
movl %eax, -0x38(%rbp)
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x204c20
jmp 0x204dd8
movq -0x88(%rbp), %rax
cmpq -0x80(%rbp), %rax
jne 0x204e2a
cmpq $0x0, -0x80(%rbp)
je 0x204dfc
movq -0x80(%rbp), %rax
shlq %rax
movq %rax, -0xa0(%rbp)
jmp 0x204e0a
movl $0x2, %eax
movq %rax, -0xa0(%rbp)
jmp 0x204e0a
movq -0xa0(%rbp), %rax
movq %rax, -0x80(%rbp)
movq -0x78(%rbp), %rdi
movq -0x80(%rbp), %rsi
shlq $0x2, %rsi
callq 0x2360
movq %rax, -0x78(%rbp)
movq -0x70(%rbp), %rax
movl %eax, %edx
movq -0x78(%rbp), %rax
movq -0x88(%rbp), %rcx
movq %rcx, %rsi
addq $0x1, %rsi
movq %rsi, -0x88(%rbp)
movl %edx, (%rax,%rcx,4)
jmp 0x204e4e
movl -0x30(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rbp)
jmp 0x204bd6
movl $0x0, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
movq -0x10(%rbp), %rcx
cmpq (%rcx), %rax
jae 0x204f42
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x2c(%rbp), %ecx
shlq $0x5, %rcx
addq %rcx, %rax
movq $-0x1, 0x10(%rax)
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x2c(%rbp), %ecx
shlq $0x5, %rcx
addq %rcx, %rax
movq (%rax), %rdi
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x2c(%rbp), %ecx
shlq $0x5, %rcx
addq %rcx, %rax
movq 0x18(%rax), %rax
shrq $0x20, %rax
movl %eax, %esi
movq -0x60(%rbp), %rdx
movq -0x78(%rbp), %rcx
movq -0x8(%rbp), %r8
callq 0x204920
cmpl $0x0, %eax
jne 0x204f18
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x2c(%rbp), %ecx
shlq $0x5, %rcx
addq %rcx, %rax
movq 0x8(%rax), %rdi
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x2c(%rbp), %ecx
shlq $0x5, %rcx
addq %rcx, %rax
movq 0x18(%rax), %rax
movl %eax, %esi
movq -0x60(%rbp), %rdx
movq -0x78(%rbp), %rcx
movq -0x8(%rbp), %r8
callq 0x204920
cmpl $0x0, %eax
je 0x204f1a
jmp 0x204f34
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x2c(%rbp), %ecx
shlq $0x5, %rcx
addq %rcx, %rax
movq $0x0, 0x10(%rax)
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x204e63
movq -0x60(%rbp), %rdi
callq 0x2210
movq -0x78(%rbp), %rdi
callq 0x2210
addq $0xa0, %rsp
popq %rbp
retq
nopl (%rax)