// File: /workspace/github_cpp_makefile_star2_O3/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 0xe27e4
movq %r8, %r9
movq %rcx, %r13
movq %rsi, %rbx
movq (%rdx), %rcx
movl %edi, %r8d
leaq (%r8,%r8,8), %rsi
leaq (%rsi,%rsi,2), %rsi
addq %r8, %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
leal (%rcx,%rbp), %r12d
leaq 0x20(%rsp), %rsi
movq %rcx, (%rsi)
xorl %ecx, %ecx
movq %rcx, 0x60(%r9)
movq %rcx, 0x40(%r9)
movl $0x1, %r15d
movq %rbx, 0x10(%rsp)
movq 0x48(%rbx), %rsi
movl (%rsi,%rcx,4), %edi
movl %edi, 0xc(%rsp)
cmpl 0x8(%rsp), %edi
jb 0xe27d5
movq (%rdx), %rcx
leaq (%rdi,%rdi,8), %rsi
leaq (%rsi,%rsi,2), %rsi
addq %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 0xe2769
movl %esi, %edi
movl %ebp, %r10d
cmpl %ecx, %ebp
ja 0xe2773
movl %ecx, %r10d
cmpl %r10d, %edi
jbe 0xe27d5
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
movl $0x1, %ecx
movq %r9, %r14
leaq 0x30(%rsp), %r9
movsd 0x1535af(%rip), %xmm0   # 0x235d58
pushq $0x0
pushq %r13
leaq 0x38(%rsp), %rax
pushq %rax
pushq %r10
pushq $0x1
leaq 0x44(%rsp), %rax
pushq %rax
callq 0xbdac5
movq %r14, %r9
movq %rbx, %rdx
movq 0x50(%rsp), %rbx
addq $0x40, %rsp
movq 0x38(%rbx), %rax
movl %r15d, %ecx
incl %r15d
cmpq %rcx, %rax
ja 0xe271d
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq