// File: /workspace/github_cpp_makefile_star2_O2/chhylp123[P]hifiasm/Overlaps.cpp
// Function: chain_origin_trans_uid_s_bubble(buf_t*, buf_t*, unsigned int, unsigned int, ma_ug_t*, hap_cov_t*)
void chain_origin_trans_uid_s_bubble(buf_t *pri, buf_t* aux, uint32_t beg, uint32_t sink, ma_ug_t *ug, hap_cov_t *cov)
{
    if(pri->b.n == 0 || aux->b.n == 0) return;
    asg_arc_t *av = NULL;
    uint32_t pri_v, aux_v, nv, i, priBeg, priEnd, auxBeg, auxEnd;
    uint64_t pri_len, aux_len;

    priBeg = priEnd = auxBeg = auxEnd = (uint32_t)-1;
    pri_len = set_utg_offset(pri->b.a, pri->b.n, ug, cov->read_g, cov->pos_idx, 0, 1);
    aux_len = set_utg_offset(aux->b.a, aux->b.n, ug, cov->read_g, cov->pos_idx, 0, 1);

    pri_v = pri->b.a[0]; aux_v = aux->b.a[0];
    av = asg_arc_a(ug->g, beg);
    nv = asg_arc_n(ug->g, beg);
    for (i = 0; i < nv; ++i)
    {
        if(av[i].del) continue;
        if(av[i].v == pri_v) priBeg = av[i].ol;
        if(av[i].v == aux_v) auxBeg = av[i].ol;
    }

    pri_v = pri->b.a[pri->b.n-1]^1; aux_v = aux->b.a[aux->b.n-1]^1;
    av = asg_arc_a(ug->g, sink);
    nv = asg_arc_n(ug->g, sink);
    for (i = 0; i < nv; ++i)
    {
        if(av[i].del) continue;
        if(av[i].v == pri_v) priEnd = ((pri_len > av[i].ol)? (pri_len - av[i].ol - 1) : 0);
        if(av[i].v == aux_v) auxEnd = ((aux_len > av[i].ol)? (aux_len - av[i].ol - 1) : 0);
    }
    ///[priBeg, priEnd) && [auxBeg, auxEnd)
    if(priBeg == (uint32_t)-1 || priEnd == (uint32_t)-1 || auxBeg == (uint32_t)-1 || auxEnd == (uint32_t)-1)
    {
        fprintf(stderr, "ERROR-s_bubble\n");
    }

    cov->u_buffer.a.n = cov->tailIndex.a.n = 0;

    kv_resize(asg_arc_t_offset, cov->u_buffer.a, 1);
    cov->u_buffer.a.n = 1;
    cov->u_buffer.a.a[0].Off = priEnd;
    cov->u_buffer.a.a[0].Off <<= 32;
    cov->u_buffer.a.a[0].Off |= auxEnd;

    kv_resize(int32_t, cov->tailIndex.a, 1);
    cov->tailIndex.a.n = 1;
    cov->tailIndex.a.a[0] = 0;

    // uint32_t i_n = cov->t_ch->k_trans.n;

    chain_origin_trans_uid_by_distance(cov, cov->read_g, pri->b.a, pri->b.n, priBeg, &pri_len, aux->b.a, aux->b.n, auxBeg, &aux_len, 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:
movq %rsi, %rax
movq 0x38(%rdi), %rsi
testq %rsi, %rsi
je 0xa549f
cmpq $0x0, 0x38(%rax)
je 0xa549f
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %r9, %r13
movq %r8, %r12
movl %edx, %ebp
movq %rdi, %r14
movl %ecx, (%rsp)
movq 0x48(%rdi), %rdi
movq 0x10(%r9), %r8
movq 0x30(%r9), %rcx
subq $0x8, %rsp
pushq $0x1
popq %r10
xorl %ebx, %ebx
movq %r12, %rdx
xorl %r9d, %r9d
pushq %r10
movq %rax, %r15
callq 0x80ffc
popq %rcx
popq %rdx
movq %r13, %rcx
movl %eax, %r13d
movl %eax, %eax
movq %rax, 0x30(%rsp)
movq 0x48(%r15), %rdi
movl 0x38(%r15), %esi
movq 0x10(%rcx), %r8
movq %rcx, 0x18(%rsp)
movq 0x30(%rcx), %rcx
subq $0x8, %rsp
movq %r12, %rdx
xorl %r9d, %r9d
pushq $0x1
popq %rax
pushq %rax
callq 0x80ffc
popq %rcx
popq %rdx
movl %eax, 0x4(%rsp)
movl %eax, %ecx
movq %rcx, 0x28(%rsp)
movq %r14, 0x8(%rsp)
movq 0x48(%r14), %rcx
movl (%rcx), %r8d
movq %r15, 0x10(%rsp)
movq 0x48(%r15), %rdx
movl (%rdx), %r9d
movq %r12, 0x20(%rsp)
movq 0x18(%r12), %rdi
movq 0x8(%rdi), %rax
movq 0x28(%rdi), %rdi
movl %ebp, %r10d
movq (%rdi,%r10,8), %r10
movl %r10d, %r11d
movq %r10, %r14
shrq $0x20, %r14
imulq $0x18, %r11, %r10
imulq $0x18, %r14, %r11
addq %rax, %r11
addq $0xc, %r11
pushq $-0x1
popq %rbp
movl %ebp, %r15d
cmpq %rbx, %r10
je 0xa5302
movl (%r11,%rbx), %r12d
testl %r12d, %r12d
js 0xa52fc
movl -0x4(%r11,%rbx), %esi
cmpl %r8d, %esi
cmovel %r12d, %ebp
cmpl %r9d, %esi
cmovel %r12d, %r15d
addq $0x18, %rbx
jmp 0xa52db
movq 0x8(%rsp), %rsi
movq 0x38(%rsi), %rsi
movl -0x4(%rcx,%rsi,4), %ecx
movq 0x10(%rsp), %rsi
movq 0x38(%rsi), %rsi
movl -0x4(%rdx,%rsi,4), %edx
movl (%rsp), %esi
movq (%rdi,%rsi,8), %rsi
movl %esi, %edi
shrq $0x20, %rsi
imulq $0x18, %rdi, %rdi
imulq $0x18, %rsi, %rsi
addq %rax, %rsi
addq $0xc, %rsi
pushq $-0x1
popq %rbx
xorl %eax, %eax
xorl %r9d, %r9d
movl %ebx, (%rsp)
cmpq %r9, %rdi
je 0xa53a3
movl (%rsi,%r9), %r10d
testl %r10d, %r10d
js 0xa539d
movl %ebp, %r8d
movq %r15, %rbp
movl -0x4(%rsi,%r9), %r15d
movl %r15d, %r12d
xorl %ecx, %r12d
movl %r10d, %r11d
notl %r11d
leal (%r11,%r13), %r14d
cmpl %r10d, %r13d
cmovbel %eax, %r14d
cmpl $0x1, %r12d
cmovel %r14d, %ebx
xorl %edx, %r15d
cmpl $0x1, %r15d
jne 0xa5397
movl 0x4(%rsp), %r14d
addl %r14d, %r11d
cmpl %r10d, %r14d
cmovbel %eax, %r11d
movl %r11d, (%rsp)
movq %rbp, %r15
movl %r8d, %ebp
addq $0x18, %r9
jmp 0xa5343
cmpl $-0x1, %ebp
movl (%rsp), %r12d
je 0xa54a0
cmpl $-0x1, %ebx
je 0xa54a0
cmpl $-0x1, %r15d
je 0xa54a0
cmpl $-0x1, %r12d
je 0xa54a0
movq 0x18(%rsp), %r14
andq $0x0, 0x60(%r14)
andq $0x0, 0x40(%r14)
xorl %eax, %eax
cmpq %rax, 0x48(%r14)
je 0xa53ea
movq 0x50(%r14), %rax
jmp 0xa5402
movq $0x1, 0x48(%r14)
movq 0x50(%r14), %rdi
pushq $0x28
popq %rsi
callq 0x2370
movq %rax, 0x50(%r14)
movq $0x1, 0x40(%r14)
shlq $0x20, %rbx
movl %r12d, %ecx
orq %rbx, %rcx
movq %rcx, 0x18(%rax)
cmpq $0x0, 0x68(%r14)
je 0xa5425
movq 0x70(%r14), %rax
jmp 0xa543d
movq $0x1, 0x68(%r14)
movq 0x70(%r14), %rdi
pushq $0x4
popq %rsi
callq 0x2370
movq %rax, 0x70(%r14)
movq $0x1, 0x60(%r14)
andl $0x0, (%rax)
movq 0x30(%r14), %rsi
movq 0x8(%rsp), %rax
movq 0x48(%rax), %rdx
movl 0x38(%rax), %ecx
movq 0x10(%rsp), %r11
movl 0x38(%r11), %eax
subq $0x10, %rsp
leaq 0x38(%rsp), %r10
leaq 0x40(%rsp), %r9
movsd 0x1427e1(%rip), %xmm0   # 0x1e7c58
movq %r14, %rdi
movl %ebp, %r8d
pushq $0x0
pushq 0x38(%rsp)
pushq %r10
pushq %r15
pushq %rax
pushq 0x48(%r11)
callq 0x82297
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x1adb39(%rip), %rax    # 0x252fe0
movq (%rax), %rcx
leaq 0x144916(%rip), %rdi    # 0x1e9dc7
pushq $0xf
popq %rsi
pushq $0x1
popq %rdx
callq 0x2410
jmp 0xa53cd