// File: 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
movq %rsp, %rbp
pushq %r14
pushq %rbx
subq $0xd0, %rsp
movl %edi, -0x14(%rbp)
movq %rsi, -0x20(%rbp)
movq %rdx, -0x28(%rbp)
movq %rcx, -0x30(%rbp)
movq %r8, -0x38(%rbp)
movq -0x20(%rbp), %rax
cmpq $0x0, 0x38(%rax)
jne 0x135291
jmp 0x135516
movq -0x28(%rbp), %rax
movq (%rax), %rax
movl -0x14(%rbp), %ecx
imulq $0x1c, %rcx, %rcx
addq %rcx, %rax
movl 0x4(%rax), %eax
movl %eax, -0x3c(%rbp)
movl -0x3c(%rbp), %eax
movq -0x30(%rbp), %rcx
movq 0x18(%rcx), %rcx
movq 0x20(%rcx), %rcx
movl -0x14(%rbp), %edx
shrl %edx
movl %edx, %edx
movl (%rcx,%rdx,8), %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
addl %ecx, %eax
movl %eax, -0x40(%rbp)
movq -0x30(%rbp), %rax
movq 0x18(%rax), %rax
movq 0x20(%rax), %rax
movl -0x14(%rbp), %ecx
shrl %ecx
movl %ecx, %ecx
movl (%rax,%rcx,8), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movl %eax, %eax
movq %rax, -0x60(%rbp)
movq -0x38(%rbp), %rax
movq $0x0, 0x60(%rax)
movq -0x38(%rbp), %rax
movq $0x0, 0x40(%rax)
movl $0x0, -0x4c(%rbp)
movl -0x4c(%rbp), %eax
movq -0x20(%rbp), %rcx
cmpq 0x38(%rcx), %rax
jae 0x135516
movq -0x20(%rbp), %rax
movq 0x48(%rax), %rax
movl -0x4c(%rbp), %ecx
movl (%rax,%rcx,4), %eax
movl %eax, -0x50(%rbp)
movl -0x50(%rbp), %eax
cmpl -0x14(%rbp), %eax
jae 0x13533b
jmp 0x135508
movq -0x28(%rbp), %rax
movq (%rax), %rax
movl -0x50(%rbp), %ecx
imulq $0x1c, %rcx, %rcx
addq %rcx, %rax
movl 0x4(%rax), %eax
movl %eax, -0x44(%rbp)
movl -0x44(%rbp), %eax
movq -0x30(%rbp), %rcx
movq 0x18(%rcx), %rcx
movq 0x20(%rcx), %rcx
movl -0x50(%rbp), %edx
shrl %edx
movl %edx, %edx
movl (%rcx,%rdx,8), %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
addl %ecx, %eax
movl %eax, -0x48(%rbp)
movq -0x30(%rbp), %rax
movq 0x18(%rax), %rax
movq 0x20(%rax), %rax
movl -0x50(%rbp), %ecx
shrl %ecx
movl %ecx, %ecx
movl (%rax,%rcx,8), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movl %eax, %eax
movq %rax, -0x68(%rbp)
movl -0x40(%rbp), %eax
cmpl -0x48(%rbp), %eax
ja 0x1353a7
movl -0x40(%rbp), %eax
movl %eax, -0x6c(%rbp)
jmp 0x1353ad
movl -0x48(%rbp), %eax
movl %eax, -0x6c(%rbp)
movl -0x6c(%rbp), %eax
movl %eax, -0x70(%rbp)
movl -0x3c(%rbp), %eax
cmpl -0x44(%rbp), %eax
jb 0x1353c3
movl -0x3c(%rbp), %eax
movl %eax, -0x74(%rbp)
jmp 0x1353c9
movl -0x44(%rbp), %eax
movl %eax, -0x74(%rbp)
movl -0x70(%rbp), %eax
movl -0x74(%rbp), %ecx
cmpl %ecx, %eax
jbe 0x135415
movl -0x40(%rbp), %eax
cmpl -0x48(%rbp), %eax
ja 0x1353e3
movl -0x40(%rbp), %eax
movl %eax, -0x78(%rbp)
jmp 0x1353e9
movl -0x48(%rbp), %eax
movl %eax, -0x78(%rbp)
movl -0x78(%rbp), %eax
movl %eax, -0x7c(%rbp)
movl -0x3c(%rbp), %eax
cmpl -0x44(%rbp), %eax
jb 0x1353ff
movl -0x3c(%rbp), %eax
movl %eax, -0x80(%rbp)
jmp 0x135405
movl -0x44(%rbp), %eax
movl %eax, -0x80(%rbp)
movl -0x7c(%rbp), %eax
movl -0x80(%rbp), %ecx
subl %ecx, %eax
movl %eax, -0x84(%rbp)
jmp 0x13541f
xorl %eax, %eax
movl %eax, -0x84(%rbp)
jmp 0x13541f
movl -0x84(%rbp), %eax
movl %eax, -0x54(%rbp)
cmpl $0x0, -0x54(%rbp)
jne 0x135433
jmp 0x135508
movq -0x38(%rbp), %rax
movq %rax, -0x98(%rbp)
movq -0x38(%rbp), %rax
movq 0x30(%rax), %rax
movq %rax, -0x90(%rbp)
movl -0x3c(%rbp), %eax
cmpl -0x44(%rbp), %eax
jb 0x135460
movl -0x3c(%rbp), %eax
movl %eax, -0x9c(%rbp)
jmp 0x135469
movl -0x44(%rbp), %eax
movl %eax, -0x9c(%rbp)
movl -0x9c(%rbp), %eax
subl -0x3c(%rbp), %eax
movl %eax, -0xa0(%rbp)
movl -0x3c(%rbp), %eax
cmpl -0x44(%rbp), %eax
jb 0x13548b
movl -0x3c(%rbp), %eax
movl %eax, -0xa4(%rbp)
jmp 0x135494
movl -0x44(%rbp), %eax
movl %eax, -0xa4(%rbp)
movl -0xa0(%rbp), %r8d
movq -0x90(%rbp), %rsi
movq -0x98(%rbp), %rdi
movl -0xa4(%rbp), %ebx
subl -0x44(%rbp), %ebx
movq -0x30(%rbp), %r10
leaq -0x14(%rbp), %rdx
movl $0x1, %ecx
leaq -0x60(%rbp), %r9
leaq -0x50(%rbp), %r14
leaq -0x68(%rbp), %r11
xorl %eax, %eax
movsd 0x251363(%rip), %xmm0   # 0x386838
leaq 0x253606(%rip), %rax    # 0x388ae2
movq %r14, (%rsp)
movl $0x1, 0x8(%rsp)
movl %ebx, 0x10(%rsp)
movq %r11, 0x18(%rsp)
movq %r10, 0x20(%rsp)
movl $0x0, 0x28(%rsp)
movq %rax, 0x30(%rsp)
callq 0xf9a10
movl -0x4c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4c(%rbp)
jmp 0x13530c
addq $0xd0, %rsp
popq %rbx
popq %r14
popq %rbp
retq
nopw %cs:(%rax,%rax)