// File: /workspace/github_cpp_makefile_star2_O3/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 0xe26a1
cmpq $0x0, 0x38(%rax)
je 0xe26a1
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %r9, %r12
movq %r8, %r15
movl %edx, %ebp
movq %rdi, %rbx
movl %ecx, 0x8(%rsp)
movq 0x48(%rdi), %rdi
movq 0x10(%r9), %r8
movq 0x30(%r9), %rcx
subq $0x8, %rsp
movl $0x1, %r10d
movq %r15, %rdx
xorl %r9d, %r9d
pushq %r10
movq %rax, %r14
callq 0xbc79b
addq $0x10, %rsp
movl %eax, %r13d
movl %eax, %eax
movq %rax, 0x40(%rsp)
movq 0x48(%r14), %rdi
movl 0x38(%r14), %esi
movq 0x10(%r12), %r8
movq %r12, 0x30(%rsp)
movq 0x30(%r12), %rcx
subq $0x8, %rsp
movq %r15, %rdx
xorl %r9d, %r9d
movl $0x1, %eax
pushq %rax
callq 0xbc79b
addq $0x10, %rsp
movl %eax, 0x14(%rsp)
movl %eax, %ecx
movq %rcx, 0x38(%rsp)
movq %rbx, 0x20(%rsp)
movq 0x48(%rbx), %rsi
movq %r14, 0x28(%rsp)
movq 0x48(%r14), %rax
movq %r15, 0x18(%rsp)
movq 0x18(%r15), %rcx
movq 0x8(%rcx), %r15
movq 0x28(%rcx), %rdi
movl %ebp, %ecx
movq (%rdi,%rcx,8), %r10
movl $0xffffffff, %r11d      # imm = 0xFFFFFFFF
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
movl $0xffffffff, %r14d      # imm = 0xFFFFFFFF
andq %r10, %r11
je 0xe24e7
movl (%rsi), %r8d
movl (%rax), %r9d
shrq $0x20, %r10
leaq (%r10,%r10,2), %rcx
leaq (%r15,%rcx,8), %r10
addq $0xc, %r10
shlq $0x3, %r11
leaq (%r11,%r11,2), %r11
movl $0xffffffff, %r14d      # imm = 0xFFFFFFFF
xorl %r12d, %r12d
movl (%r10,%r12), %ecx
testl %ecx, %ecx
js 0xe24de
movl -0x4(%r10,%r12), %edx
cmpl %r8d, %edx
cmovel %ecx, %ebp
cmpl %r9d, %edx
cmovel %ecx, %r14d
addq $0x18, %r12
cmpq %r12, %r11
jne 0xe24c4
movq %rax, %rdx
movl 0x8(%rsp), %ecx
movq (%rdi,%rcx,8), %rdi
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
testl %edi, %edi
movq %r14, 0x8(%rsp)
je 0xe259b
movq 0x20(%rsp), %rcx
movq 0x38(%rcx), %rcx
movl -0x4(%rsi,%rcx,4), %esi
movq 0x28(%rsp), %rcx
movq 0x38(%rcx), %rcx
movl -0x4(%rdx,%rcx,4), %edx
movq %rdi, %rcx
shrq $0x20, %rcx
movl %edi, %edi
leaq (%rcx,%rcx,2), %rcx
leaq (%r15,%rcx,8), %rcx
addq $0xc, %rcx
shlq $0x3, %rdi
leaq (%rdi,%rdi,2), %rdi
xorl %r8d, %r8d
xorl %r9d, %r9d
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
movl (%rcx,%r9), %r10d
testl %r10d, %r10d
js 0xe2592
movl -0x4(%rcx,%r9), %r15d
movl %r15d, %r12d
xorl %esi, %r12d
movl %r10d, %r11d
notl %r11d
leal (%r11,%r13), %r14d
cmpl %r10d, %r13d
cmovbel %r8d, %r14d
cmpl $0x1, %r12d
cmovel %r14d, %ebx
xorl %edx, %r15d
cmpl $0x1, %r15d
jne 0xe258d
movl 0x14(%rsp), %eax
addl %eax, %r11d
cmpl %r10d, %eax
cmovbel %r8d, %r11d
movl %r11d, %eax
movq 0x8(%rsp), %r14
addq $0x18, %r9
cmpq %r9, %rdi
jne 0xe2546
cmpl $-0x1, %ebp
movq 0x30(%rsp), %r15
movl %eax, %r12d
je 0xe26a2
cmpl $-0x1, %ebx
je 0xe26a2
cmpl $-0x1, %r14d
je 0xe26a2
cmpl $-0x1, %r12d
je 0xe26a2
xorl %eax, %eax
movq %rax, 0x60(%r15)
movq %rax, 0x40(%r15)
cmpq %rax, 0x48(%r15)
je 0xe25df
movq 0x50(%r15), %rax
jmp 0xe25f9
movq $0x1, 0x48(%r15)
movq 0x50(%r15), %rdi
movl $0x28, %esi
callq 0x2370
movq %rax, 0x50(%r15)
movq 0x18(%rsp), %r14
movq $0x1, 0x40(%r15)
shlq $0x20, %rbx
movl %r12d, %ecx
orq %rbx, %rcx
movq %rcx, 0x18(%rax)
cmpq $0x0, 0x68(%r15)
je 0xe2621
movq 0x70(%r15), %rax
jmp 0xe263b
movq $0x1, 0x68(%r15)
movq 0x70(%r15), %rdi
movl $0x4, %esi
callq 0x2370
movq %rax, 0x70(%r15)
movq $0x1, 0x60(%r15)
xorl %r10d, %r10d
movl %r10d, (%rax)
movq 0x30(%r15), %rsi
movq 0x20(%rsp), %rax
movq 0x48(%rax), %rdx
movl 0x38(%rax), %ecx
movq 0x28(%rsp), %rbx
movl 0x38(%rbx), %eax
subq $0x10, %rsp
leaq 0x48(%rsp), %r11
leaq 0x50(%rsp), %r9
movsd 0x1536e1(%rip), %xmm0   # 0x235d58
movq %r15, %rdi
movl %ebp, %r8d
pushq %r10
pushq %r14
pushq %r11
pushq 0x30(%rsp)
pushq %rax
pushq 0x48(%rbx)
callq 0xbdac5
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x112e9
jmp 0xe25c9