// File: /workspace/github_cpp_makefile_star2_O2/chhylp123[P]hifiasm/Overlaps.cpp
// Function: chain_origin_trans_uid_c_bubble(unsigned int, buf_t*, buf_t*, ma_ug_t*, hap_cov_t*)
void chain_origin_trans_uid_c_bubble(uint32_t query, buf_t *target, buf_t *idx, ma_ug_t *ug, hap_cov_t *cov)
{
    if(target->b.n == 0) return;
    uint32_t qs, qe, ts, te, i, v, ovlp;
    qs = idx->a[query].d; qe = qs + ug->g->seq[query>>1].len;
    uint64_t qlen = ug->g->seq[query>>1].len, tlen;
    cov->u_buffer.a.n = cov->tailIndex.a.n = 0;

    ///uint32_t i_n = cov->t_ch->k_trans.n;
    for (i = 0; i < target->b.n; ++i)
    {
        v = target->b.a[i];
        if(v < query) continue; //avoid dup
        ts = idx->a[v].d; te = ts + ug->g->seq[v>>1].len; tlen = ug->g->seq[v>>1].len;
        ovlp = ((MIN(qe, te) > MAX(qs, ts))? (MIN(qe, te) - MAX(qs, ts)) : 0);
        if(ovlp == 0) continue;
        chain_origin_trans_uid_by_distance(cov, cov->read_g, &query, 1, MAX(qs, ts) - qs, &qlen, 
                                                    &v, 1, MAX(qs, ts) - ts, &tlen, ug, RC_0, -1024, __func__);
    }
    // fprintf(stderr, "\nocc: %u\n", (uint32_t)(cov->t_ch->k_trans.n - i_n));
    // for (i = i_n; i < cov->t_ch->k_trans.n; i++)
    // {
    //     fprintf(stderr, "s-utg%.6ul\t%u\t%u\td-utg%.6ul\t%u\t%u\trev(%u)\n", 
    //     cov->t_ch->k_trans.a[i].qn+1, cov->t_ch->k_trans.a[i].qs, cov->t_ch->k_trans.a[i].qe, 
    //     cov->t_ch->k_trans.a[i].tn+1, cov->t_ch->k_trans.a[i].ts, cov->t_ch->k_trans.a[i].te, 
    //     cov->t_ch->k_trans.a[i].rev);
    // }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movl %edi, 0x8(%rsp)
movq 0x38(%rsi), %rax
testq %rax, %rax
je 0xa55eb
movq %r8, %r9
movq %rcx, %r13
movq %rsi, %rbx
movq (%rdx), %rcx
movl %edi, %esi
imulq $0x1c, %rsi, %rsi
movl 0x4(%rcx,%rsi), %ebp
movq 0x18(%r13), %rcx
movq 0x20(%rcx), %rcx
shrl %edi
movl (%rcx,%rdi,8), %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
leaq 0x20(%rsp), %rsi
movq %rcx, (%rsi)
andq $0x0, 0x60(%r8)
andq $0x0, 0x40(%r8)
leal (%rcx,%rbp), %r12d
xorl %r15d, %r15d
movq %rbx, 0x10(%rsp)
movl %r15d, %r15d
cmpq %r15, %rax
jbe 0xa55eb
movq 0x48(%rbx), %rcx
movl (%rcx,%r15,4), %edi
movl %edi, 0xc(%rsp)
cmpl 0x8(%rsp), %edi
jb 0xa55e3
movq (%rdx), %rcx
imulq $0x1c, %rdi, %rsi
movl 0x4(%rcx,%rsi), %ecx
movq 0x18(%r13), %rsi
movq 0x20(%rsi), %rsi
shrl %edi
movl (%rsi,%rdi,8), %edi
andl $0x7fffffff, %edi       # imm = 0x7FFFFFFF
leal (%rdi,%rcx), %esi
movq %rdi, 0x18(%rsp)
movl %r12d, %edi
cmpl %esi, %r12d
jb 0xa5579
movl %esi, %edi
movl %ebp, %r10d
cmpl %ecx, %ebp
ja 0xa5583
movl %ecx, %r10d
cmpl %r10d, %edi
jbe 0xa55e3
movq 0x30(%r9), %rsi
movq %rdx, %rbx
movl %r10d, %r8d
subl %ebp, %r8d
subl %ecx, %r10d
subq $0x10, %rsp
movq %r9, %rdi
leaq 0x18(%rsp), %rdx
pushq $0x1
popq %rcx
movq %r9, %r14
leaq 0x30(%rsp), %r9
movsd 0x1426a1(%rip), %xmm0   # 0x1e7c58
pushq $0x0
pushq %r13
leaq 0x38(%rsp), %rax
pushq %rax
pushq %r10
pushq $0x1
leaq 0x44(%rsp), %rax
pushq %rax
callq 0x82297
movq %r14, %r9
movq %rbx, %rdx
movq 0x50(%rsp), %rbx
addq $0x40, %rsp
movq 0x38(%rbx), %rax
incl %r15d
jmp 0xa5527
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq