// File: /workspace/github_cpp_makefile_star2_O1/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:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rsi, %r14
movq 0x38(%rdi), %rsi
testq %rsi, %rsi
je 0xe130a
cmpq $0x0, 0x38(%r14)
je 0xe130a
movq %r9, %rax
movq %r8, %r15
movl %edx, %ebp
movq %rdi, %r13
movl %ecx, 0x8(%rsp)
movq 0x48(%rdi), %rdi
movq 0x10(%r9), %r8
movq 0x30(%r9), %rcx
subq $0x8, %rsp
movl $0x1, %ebx
movq %r15, %rdx
xorl %r9d, %r9d
pushq %rbx
movq %rax, %r12
callq 0xbb724
addq $0x10, %rsp
movl %eax, %eax
movq %rax, 0x20(%rsp)
movq 0x48(%r14), %rdi
movl 0x38(%r14), %esi
movq 0x10(%r12), %r8
movq %r12, (%rsp)
movq 0x30(%r12), %rcx
subq $0x8, %rsp
movq %r15, %rdx
xorl %r9d, %r9d
pushq %rbx
callq 0xbb724
addq $0x10, %rsp
movl %eax, 0xc(%rsp)
movl %eax, %ecx
movq %rcx, 0x30(%rsp)
movq %r13, 0x10(%rsp)
movq 0x48(%r13), %rsi
movq %r14, 0x18(%rsp)
movq 0x48(%r14), %r12
movq %r15, 0x28(%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, %r13d      # imm = 0xFFFFFFFF
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
movl $0xffffffff, %r14d      # imm = 0xFFFFFFFF
andq %r10, %r11
je 0xe116a
movl (%rsi), %r8d
movl (%r12), %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 %ebx, %ebx
movl (%r10,%rbx), %ecx
testl %ecx, %ecx
js 0xe1161
movl -0x4(%r10,%rbx), %edx
cmpl %r8d, %edx
cmovel %ecx, %ebp
cmpl %r9d, %edx
cmovel %ecx, %r14d
addq $0x18, %rbx
cmpq %rbx, %r11
jne 0xe1147
movl 0x8(%rsp), %ecx
movq (%rdi,%rcx,8), %r8
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
testl %r8d, %r8d
je 0xe121a
movq 0x10(%rsp), %rax
movq 0x38(%rax), %rcx
movl -0x4(%rsi,%rcx,4), %esi
movq 0x18(%rsp), %rax
movq 0x38(%rax), %rcx
movl -0x4(%r12,%rcx,4), %edx
movq %r8, %rcx
shrq $0x20, %rcx
movq 0x20(%rsp), %rdi
movl %r8d, %r8d
leaq (%rcx,%rcx,2), %rcx
leaq (%r15,%rcx,8), %rcx
addq $0xc, %rcx
shlq $0x3, %r8
leaq (%r8,%r8,2), %r8
xorl %eax, %eax
xorl %r10d, %r10d
movl $0xffffffff, %r13d      # imm = 0xFFFFFFFF
movslq (%rcx,%r10), %r11
testq %r11, %r11
js 0xe1211
movl -0x4(%rcx,%r10), %r12d
movl %r12d, %r15d
xorl %esi, %r15d
movl %r11d, %r9d
notl %r9d
addl %edi, %r9d
cmpq %r11, %rdi
cmovbel %eax, %r9d
cmpl $0x1, %r15d
cmovel %r9d, %r13d
xorl %edx, %r12d
cmpl $0x1, %r12d
jne 0xe1211
movl %r11d, %ebx
notl %ebx
movl 0xc(%rsp), %r9d
addl %r9d, %ebx
cmpl %r11d, %r9d
cmovbel %eax, %ebx
addq $0x18, %r10
cmpq %r10, %r8
jne 0xe11c9
cmpl $-0x1, %ebp
je 0xe1319
cmpl $-0x1, %r13d
je 0xe1319
cmpl $-0x1, %r14d
je 0xe1319
cmpl $-0x1, %ebx
je 0xe1319
xorl %eax, %eax
movq (%rsp), %rdi
movq %rax, 0x60(%rdi)
movq %rax, 0x40(%rdi)
cmpq %rax, 0x48(%rdi)
jne 0xe1272
movq $0x1, 0x48(%rdi)
movq 0x50(%rdi), %rdi
movl $0x28, %esi
callq 0x2370
movq (%rsp), %rdi
movq %rax, 0x50(%rdi)
movq $0x1, 0x40(%rdi)
movq 0x50(%rdi), %rax
shlq $0x20, %r13
movl %ebx, %ecx
orq %r13, %rcx
movq %rcx, 0x18(%rax)
cmpq $0x0, 0x68(%rdi)
jne 0xe12b0
movq $0x1, 0x68(%rdi)
movq 0x70(%rdi), %rdi
movl $0x4, %esi
callq 0x2370
movq (%rsp), %rdi
movq %rax, 0x70(%rdi)
movq $0x1, 0x60(%rdi)
movq 0x70(%rdi), %rax
xorl %r10d, %r10d
movl %r10d, (%rax)
movq 0x30(%rdi), %rsi
movq 0x10(%rsp), %rax
movq 0x48(%rax), %rdx
movl 0x38(%rax), %ecx
movq 0x18(%rsp), %rbx
movl 0x38(%rbx), %eax
subq $0x10, %rsp
leaq 0x40(%rsp), %r11
leaq 0x30(%rsp), %r9
movsd 0x148870(%rip), %xmm0   # 0x229b60
movl %ebp, %r8d
pushq %r10
pushq 0x40(%rsp)
pushq %r11
pushq %r14
pushq %rax
pushq 0x48(%rbx)
callq 0xbca10
addq $0x40, %rsp
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x1149a
jmp 0xe1240