// File: 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
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %rbx
subq $0xa8, %rsp
movq %rdi, -0x20(%rbp)
movq %rsi, -0x28(%rbp)
movl %edx, -0x2c(%rbp)
movl %ecx, -0x30(%rbp)
movq %r8, -0x38(%rbp)
movq %r9, -0x40(%rbp)
movq -0x20(%rbp), %rax
cmpq $0x0, 0x38(%rax)
je 0x134c3c
movq -0x28(%rbp), %rax
cmpq $0x0, 0x38(%rax)
jne 0x134c41
jmp 0x135252
movq $0x0, -0x48(%rbp)
movl $0xffffffff, -0x68(%rbp) # imm = 0xFFFFFFFF
movl $0xffffffff, -0x64(%rbp) # imm = 0xFFFFFFFF
movl $0xffffffff, -0x60(%rbp) # imm = 0xFFFFFFFF
movl $0xffffffff, -0x5c(%rbp) # imm = 0xFFFFFFFF
movq -0x20(%rbp), %rax
movq 0x48(%rax), %rdi
movq -0x20(%rbp), %rax
movq 0x38(%rax), %rax
movl %eax, %esi
movq -0x38(%rbp), %rdx
movq -0x40(%rbp), %rax
movq 0x30(%rax), %rcx
movq -0x40(%rbp), %rax
movq 0x10(%rax), %r8
xorl %r9d, %r9d
movl $0x1, (%rsp)
callq 0xf7330
movl %eax, %eax
movq %rax, -0x70(%rbp)
movq -0x28(%rbp), %rax
movq 0x48(%rax), %rdi
movq -0x28(%rbp), %rax
movq 0x38(%rax), %rax
movl %eax, %esi
movq -0x38(%rbp), %rdx
movq -0x40(%rbp), %rax
movq 0x30(%rax), %rcx
movq -0x40(%rbp), %rax
movq 0x10(%rax), %r8
xorl %r9d, %r9d
movl $0x1, (%rsp)
callq 0xf7330
movl %eax, %eax
movq %rax, -0x78(%rbp)
movq -0x20(%rbp), %rax
movq 0x48(%rax), %rax
movl (%rax), %eax
movl %eax, -0x4c(%rbp)
movq -0x28(%rbp), %rax
movq 0x48(%rax), %rax
movl (%rax), %eax
movl %eax, -0x50(%rbp)
movq -0x38(%rbp), %rax
movq 0x18(%rax), %rax
movq 0x8(%rax), %rax
movq -0x38(%rbp), %rcx
movq 0x18(%rcx), %rcx
movq 0x28(%rcx), %rcx
movl -0x2c(%rbp), %edx
movq (%rcx,%rdx,8), %rcx
shrq $0x20, %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x48(%rbp)
movq -0x38(%rbp), %rax
movq 0x18(%rax), %rax
movq 0x28(%rax), %rax
movl -0x2c(%rbp), %ecx
movq (%rax,%rcx,8), %rax
movl %eax, -0x54(%rbp)
movl $0x0, -0x58(%rbp)
movl -0x58(%rbp), %eax
cmpl -0x54(%rbp), %eax
jae 0x134dd5
movq -0x48(%rbp), %rax
movl -0x58(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl 0xc(%rax), %eax
shrl $0x1f, %eax
cmpl $0x0, %eax
je 0x134d67
jmp 0x134dc7
movq -0x48(%rbp), %rax
movl -0x58(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl 0x8(%rax), %eax
cmpl -0x4c(%rbp), %eax
jne 0x134d96
movq -0x48(%rbp), %rax
movl -0x58(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl 0xc(%rax), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movl %eax, -0x5c(%rbp)
movq -0x48(%rbp), %rax
movl -0x58(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl 0x8(%rax), %eax
cmpl -0x50(%rbp), %eax
jne 0x134dc5
movq -0x48(%rbp), %rax
movl -0x58(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl 0xc(%rax), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movl %eax, -0x64(%rbp)
jmp 0x134dc7
movl -0x58(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x58(%rbp)
jmp 0x134d40
movq -0x20(%rbp), %rax
movq 0x48(%rax), %rax
movq -0x20(%rbp), %rcx
movq 0x38(%rcx), %rcx
subq $0x1, %rcx
movl (%rax,%rcx,4), %eax
xorl $0x1, %eax
movl %eax, -0x4c(%rbp)
movq -0x28(%rbp), %rax
movq 0x48(%rax), %rax
movq -0x28(%rbp), %rcx
movq 0x38(%rcx), %rcx
subq $0x1, %rcx
movl (%rax,%rcx,4), %eax
xorl $0x1, %eax
movl %eax, -0x50(%rbp)
movq -0x38(%rbp), %rax
movq 0x18(%rax), %rax
movq 0x8(%rax), %rax
movq -0x38(%rbp), %rcx
movq 0x18(%rcx), %rcx
movq 0x28(%rcx), %rcx
movl -0x30(%rbp), %edx
movq (%rcx,%rdx,8), %rcx
shrq $0x20, %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x48(%rbp)
movq -0x38(%rbp), %rax
movq 0x18(%rax), %rax
movq 0x28(%rax), %rax
movl -0x30(%rbp), %ecx
movq (%rax,%rcx,8), %rax
movl %eax, -0x54(%rbp)
movl $0x0, -0x58(%rbp)
movl -0x58(%rbp), %eax
cmpl -0x54(%rbp), %eax
jae 0x134f7f
movq -0x48(%rbp), %rax
movl -0x58(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl 0xc(%rax), %eax
shrl $0x1f, %eax
cmpl $0x0, %eax
je 0x134e84
jmp 0x134f71
movq -0x48(%rbp), %rax
movl -0x58(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl 0x8(%rax), %eax
cmpl -0x4c(%rbp), %eax
jne 0x134ef5
movq -0x70(%rbp), %rax
movq -0x48(%rbp), %rcx
movl -0x58(%rbp), %edx
imulq $0x18, %rdx, %rdx
addq %rdx, %rcx
movl 0xc(%rcx), %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
movl %ecx, %ecx
cmpq %rcx, %rax
jbe 0x134ee6
movq -0x70(%rbp), %rax
movq -0x48(%rbp), %rcx
movl -0x58(%rbp), %edx
imulq $0x18, %rdx, %rdx
addq %rdx, %rcx
movl 0xc(%rcx), %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
movl %ecx, %ecx
subq %rcx, %rax
subq $0x1, %rax
movq %rax, -0x80(%rbp)
jmp 0x134eee
xorl %eax, %eax
movq %rax, -0x80(%rbp)
jmp 0x134eee
movq -0x80(%rbp), %rax
movl %eax, -0x60(%rbp)
movq -0x48(%rbp), %rax
movl -0x58(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl 0x8(%rax), %eax
cmpl -0x50(%rbp), %eax
jne 0x134f6f
movq -0x78(%rbp), %rax
movq -0x48(%rbp), %rcx
movl -0x58(%rbp), %edx
imulq $0x18, %rdx, %rdx
addq %rdx, %rcx
movl 0xc(%rcx), %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
movl %ecx, %ecx
cmpq %rcx, %rax
jbe 0x134f5a
movq -0x78(%rbp), %rax
movq -0x48(%rbp), %rcx
movl -0x58(%rbp), %edx
imulq $0x18, %rdx, %rdx
addq %rdx, %rcx
movl 0xc(%rcx), %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
movl %ecx, %ecx
subq %rcx, %rax
subq $0x1, %rax
movq %rax, -0x88(%rbp)
jmp 0x134f65
xorl %eax, %eax
movq %rax, -0x88(%rbp)
jmp 0x134f65
movq -0x88(%rbp), %rax
movl %eax, -0x68(%rbp)
jmp 0x134f71
movl -0x58(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x58(%rbp)
jmp 0x134e5a
cmpl $-0x1, -0x5c(%rbp)
je 0x134f97
cmpl $-0x1, -0x60(%rbp)
je 0x134f97
cmpl $-0x1, -0x64(%rbp)
je 0x134f97
cmpl $-0x1, -0x68(%rbp)
jne 0x134faf
movq 0x28f042(%rip), %rax    # 0x3c3fe0
movq (%rax), %rdi
leaq 0x253b0a(%rip), %rsi    # 0x388ab2
movb $0x0, %al
callq 0x22a0
movq -0x40(%rbp), %rax
movq $0x0, 0x60(%rax)
movq -0x40(%rbp), %rax
movq $0x0, 0x40(%rax)
movq -0x40(%rbp), %rax
cmpq $0x1, 0x48(%rax)
jae 0x13509a
movq -0x40(%rbp), %rax
movq $0x1, 0x48(%rax)
movq -0x40(%rbp), %rax
movq 0x48(%rax), %rcx
addq $-0x1, %rcx
movq %rcx, 0x48(%rax)
movq -0x40(%rbp), %rax
movq 0x48(%rax), %rcx
shrq %rcx
movq -0x40(%rbp), %rax
orq 0x48(%rax), %rcx
movq %rcx, 0x48(%rax)
movq -0x40(%rbp), %rax
movq 0x48(%rax), %rcx
shrq $0x2, %rcx
movq -0x40(%rbp), %rax
orq 0x48(%rax), %rcx
movq %rcx, 0x48(%rax)
movq -0x40(%rbp), %rax
movq 0x48(%rax), %rcx
shrq $0x4, %rcx
movq -0x40(%rbp), %rax
orq 0x48(%rax), %rcx
movq %rcx, 0x48(%rax)
movq -0x40(%rbp), %rax
movq 0x48(%rax), %rcx
shrq $0x8, %rcx
movq -0x40(%rbp), %rax
orq 0x48(%rax), %rcx
movq %rcx, 0x48(%rax)
movq -0x40(%rbp), %rax
movq 0x48(%rax), %rcx
shrq $0x10, %rcx
movq -0x40(%rbp), %rax
orq 0x48(%rax), %rcx
movq %rcx, 0x48(%rax)
movq -0x40(%rbp), %rax
movq 0x48(%rax), %rcx
addq $0x1, %rcx
movq %rcx, 0x48(%rax)
movq -0x40(%rbp), %rax
movq 0x50(%rax), %rdi
movq -0x40(%rbp), %rax
imulq $0x28, 0x48(%rax), %rsi
callq 0x2360
movq %rax, %rcx
movq -0x40(%rbp), %rax
movq %rcx, 0x50(%rax)
jmp 0x13509c
movq -0x40(%rbp), %rax
movq $0x1, 0x40(%rax)
movl -0x60(%rbp), %eax
movl %eax, %ecx
movq -0x40(%rbp), %rax
movq 0x50(%rax), %rax
movq %rcx, 0x18(%rax)
movq -0x40(%rbp), %rax
movq 0x50(%rax), %rax
movq 0x18(%rax), %rcx
shlq $0x20, %rcx
movq %rcx, 0x18(%rax)
movl -0x68(%rbp), %eax
movl %eax, %ecx
movq -0x40(%rbp), %rax
movq 0x50(%rax), %rax
orq 0x18(%rax), %rcx
movq %rcx, 0x18(%rax)
movq -0x40(%rbp), %rax
cmpq $0x1, 0x68(%rax)
jae 0x1351b8
movq -0x40(%rbp), %rax
movq $0x1, 0x68(%rax)
movq -0x40(%rbp), %rax
movq 0x68(%rax), %rcx
addq $-0x1, %rcx
movq %rcx, 0x68(%rax)
movq -0x40(%rbp), %rax
movq 0x68(%rax), %rcx
shrq %rcx
movq -0x40(%rbp), %rax
orq 0x68(%rax), %rcx
movq %rcx, 0x68(%rax)
movq -0x40(%rbp), %rax
movq 0x68(%rax), %rcx
shrq $0x2, %rcx
movq -0x40(%rbp), %rax
orq 0x68(%rax), %rcx
movq %rcx, 0x68(%rax)
movq -0x40(%rbp), %rax
movq 0x68(%rax), %rcx
shrq $0x4, %rcx
movq -0x40(%rbp), %rax
orq 0x68(%rax), %rcx
movq %rcx, 0x68(%rax)
movq -0x40(%rbp), %rax
movq 0x68(%rax), %rcx
shrq $0x8, %rcx
movq -0x40(%rbp), %rax
orq 0x68(%rax), %rcx
movq %rcx, 0x68(%rax)
movq -0x40(%rbp), %rax
movq 0x68(%rax), %rcx
shrq $0x10, %rcx
movq -0x40(%rbp), %rax
orq 0x68(%rax), %rcx
movq %rcx, 0x68(%rax)
movq -0x40(%rbp), %rax
movq 0x68(%rax), %rcx
addq $0x1, %rcx
movq %rcx, 0x68(%rax)
movq -0x40(%rbp), %rax
movq 0x70(%rax), %rdi
movq -0x40(%rbp), %rax
movq 0x68(%rax), %rsi
shlq $0x2, %rsi
callq 0x2360
movq %rax, %rcx
movq -0x40(%rbp), %rax
movq %rcx, 0x70(%rax)
jmp 0x1351ba
movq -0x40(%rbp), %rax
movq $0x1, 0x60(%rax)
movq -0x40(%rbp), %rax
movq 0x70(%rax), %rax
movl $0x0, (%rax)
movq -0x40(%rbp), %rdi
movq -0x40(%rbp), %rax
movq 0x30(%rax), %rsi
movq -0x20(%rbp), %rax
movq 0x48(%rax), %rdx
movq -0x20(%rbp), %rax
movq 0x38(%rax), %rax
movl %eax, %ecx
movl -0x5c(%rbp), %r8d
movq -0x28(%rbp), %rax
movq 0x48(%rax), %r15
movq -0x28(%rbp), %rax
movq 0x38(%rax), %rax
movl %eax, %r14d
movl -0x64(%rbp), %ebx
movq -0x38(%rbp), %r10
leaq -0x70(%rbp), %r9
leaq -0x78(%rbp), %r11
xorl %eax, %eax
movsd 0x251616(%rip), %xmm0   # 0x386838
leaq 0x253899(%rip), %rax    # 0x388ac2
movq %r15, (%rsp)
movl %r14d, 0x8(%rsp)
movl %ebx, 0x10(%rsp)
movq %r11, 0x18(%rsp)
movq %r10, 0x20(%rsp)
movl $0x0, 0x28(%rsp)
movq %rax, 0x30(%rsp)
callq 0xf9a10
addq $0xa8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq