// File: chhylp123[P]hifiasm/Overlaps.cpp
// Function: bub_pop_merge(ma_ug_t*, ma_ug_t*, unsigned int, unsigned int, unsigned long, buf_t*, unsigned int, unsigned int, hap_cov_t*, unsigned int, utg_trans_t*, kvec_asg_arc_t_warp*, ma_hit_t_alloc*, ma_sub_t*, int, int, int, unsigned int*)
uint32_t bub_pop_merge(ma_ug_t *raw_ug, ma_ug_t *new_ug, uint32_t v0, uint32_t v1, uint64_t max_dist, buf_t *b, 
uint32_t positive_flag, uint32_t negative_flag, hap_cov_t *cov, uint32_t is_update_chain, utg_trans_t *o, kvec_asg_arc_t_warp *ae, 
ma_hit_t_alloc* src, ma_sub_t *sub, int32_t max_hang, int32_t min_ovlp, int32_t gap_fuzz, uint32_t *n_insert)
{
    ///do not pop bubble within new_ug; 
    uint32_t is_pop = asg_bub_pop1_primary_trio(new_ug->g, new_ug, v0, max_dist, b, positive_flag, negative_flag, 0, NULL, NULL, cov, is_update_chain, 1/**0**/, o);
    assert(is_pop); assert(b->S.a[0] == v1);

    ///b->S.a[0] is the sink of this bubble
    uint32_t i, v, qn, tn, tmp_c, u; asg_arc_t *a;
    asg_t *g = raw_ug->g; tmp_c = g->seq[b->S.a[0]>>1].c;
    
    ///assert(b->S.n == 1);
    ///first remove all nodes in this bubble
    for (i = 0; i < b->b.n; ++i) g->seq[b->b.a[i]>>1].c = ALTER_LABLE;
    

    ///v is the sink of this bubble
    v = b->S.a[0];
    ///recover node
    do {
        u = b->a[v].p; // u->v
        /****************************may have hap bugs********************************/
        ////g->seq[v>>1].c = PRIMARY_LABLE;
        g->seq[v>>1].c = HAP_LABLE;
        /****************************may have hap bugs********************************/
        v = u;
    } while (v != v0);
    ///especially for unitig graph, don't label beg and sink node of a bubble as HAP_LABLE
    ///since in unitig graph, a node may consist of a lot of reads
    g->seq[b->S.a[0]>>1].c = tmp_c;

    ///remove all edges (self/reverse for each edge) in this bubble
    for (i = 0; i < b->e.n; ++i) {
        a = &(new_ug->g->arc[b->e.a[i]]);///note:: new_ug->g here
        qn = a->ul>>33;
        tn = a->v>>1;
        if(g->seq[qn].c == ALTER_LABLE && g->seq[tn].c == ALTER_LABLE) continue;
        ///remove this edge self
        asg_arc_del(g, a->ul>>32, a->v, 1);
        ///remove the reverse direction
        asg_arc_del(g, a->v^1, a->ul>>32^1, 1);
    }

    ///v is the sink of this bubble
    v = b->S.a[0];
    ///recover node
    do {
        u = b->a[v].p; // u->v
        g->seq[v>>1].del = 0;
        asg_arc_rest(g, new_ug->g, u, v, raw_ug, ae, src, sub, max_hang, min_ovlp, gap_fuzz, n_insert);
        v = u;
    } while (v != v0);
    return is_pop;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %rbx
subq $0x98, %rsp
movq 0x68(%rbp), %rax
movl 0x60(%rbp), %eax
movl 0x58(%rbp), %eax
movl 0x50(%rbp), %eax
movq 0x48(%rbp), %rax
movq 0x40(%rbp), %rax
movq 0x38(%rbp), %rax
movq 0x30(%rbp), %rax
movl 0x28(%rbp), %eax
movq 0x20(%rbp), %rax
movl 0x18(%rbp), %eax
movl 0x10(%rbp), %eax
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 -0x28(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x28(%rbp), %rsi
movl -0x2c(%rbp), %edx
movq -0x38(%rbp), %rcx
movq -0x40(%rbp), %r8
movl 0x10(%rbp), %r9d
movl 0x18(%rbp), %ebx
movq 0x20(%rbp), %r11
movl 0x28(%rbp), %r10d
movq 0x30(%rbp), %rax
xorl %r14d, %r14d
xorl %r14d, %r14d
movl %ebx, (%rsp)
movl $0x0, 0x8(%rsp)
movq $0x0, 0x10(%rsp)
movq $0x0, 0x18(%rsp)
movq %r11, 0x20(%rsp)
movl %r10d, 0x28(%rsp)
movl $0x1, 0x30(%rsp)
movq %rax, 0x38(%rsp)
callq 0xfe040
movl %eax, -0x44(%rbp)
cmpl $0x0, -0x44(%rbp)
je 0x13cde4
jmp 0x13ce03
leaq 0x24bed8(%rip), %rdi    # 0x388cc3
leaq 0x249acb(%rip), %rsi    # 0x3868bd
movl $0x67c7, %edx           # imm = 0x67C7
leaq 0x24becc(%rip), %rcx    # 0x388cca
callq 0x2130
movq -0x40(%rbp), %rax
movq 0x18(%rax), %rax
movl (%rax), %eax
cmpl -0x30(%rbp), %eax
jne 0x13ce14
jmp 0x13ce33
leaq 0x24bf99(%rip), %rdi    # 0x388db4
leaq 0x249a9b(%rip), %rsi    # 0x3868bd
movl $0x67c7, %edx           # imm = 0x67C7
leaq 0x24be9c(%rip), %rcx    # 0x388cca
callq 0x2130
movq -0x20(%rbp), %rax
movq 0x18(%rax), %rax
movq %rax, -0x70(%rbp)
movq -0x70(%rbp), %rax
movq 0x20(%rax), %rax
movq -0x40(%rbp), %rcx
movq 0x18(%rcx), %rcx
movl (%rcx), %ecx
shrl %ecx
movl %ecx, %ecx
movzbl 0x4(%rax,%rcx,8), %eax
movl %eax, -0x58(%rbp)
movl $0x0, -0x48(%rbp)
movl -0x48(%rbp), %eax
movq -0x40(%rbp), %rcx
cmpq 0x38(%rcx), %rax
jae 0x13ce9b
movq -0x70(%rbp), %rax
movq 0x20(%rax), %rax
movq -0x40(%rbp), %rcx
movq 0x48(%rcx), %rcx
movl -0x48(%rbp), %edx
movl (%rcx,%rdx,4), %ecx
shrl %ecx
movl %ecx, %ecx
movb $0x1, 0x4(%rax,%rcx,8)
movl -0x48(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x48(%rbp)
jmp 0x13ce64
movq -0x40(%rbp), %rax
movq 0x18(%rax), %rax
movl (%rax), %eax
movl %eax, -0x4c(%rbp)
movq -0x40(%rbp), %rax
movq (%rax), %rax
movl -0x4c(%rbp), %ecx
imulq $0x1c, %rcx, %rcx
addq %rcx, %rax
movl (%rax), %eax
movl %eax, -0x5c(%rbp)
movq -0x70(%rbp), %rax
movq 0x20(%rax), %rax
movl -0x4c(%rbp), %ecx
shrl %ecx
movl %ecx, %ecx
movb $0x2, 0x4(%rax,%rcx,8)
movl -0x5c(%rbp), %eax
movl %eax, -0x4c(%rbp)
movl -0x4c(%rbp), %eax
cmpl -0x2c(%rbp), %eax
jne 0x13cea8
movl -0x58(%rbp), %eax
movb %al, %dl
movq -0x70(%rbp), %rax
movq 0x20(%rax), %rax
movq -0x40(%rbp), %rcx
movq 0x18(%rcx), %rcx
movl (%rcx), %ecx
shrl %ecx
movl %ecx, %ecx
movb %dl, 0x4(%rax,%rcx,8)
movl $0x0, -0x48(%rbp)
movl -0x48(%rbp), %eax
movq -0x40(%rbp), %rcx
cmpq 0x50(%rcx), %rax
jae 0x13cfdb
movq -0x28(%rbp), %rax
movq 0x18(%rax), %rax
movq 0x8(%rax), %rax
movq -0x40(%rbp), %rcx
movq 0x60(%rcx), %rcx
movl -0x48(%rbp), %edx
movl (%rcx,%rdx,4), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x68(%rbp)
movq -0x68(%rbp), %rax
movq (%rax), %rax
shrq $0x21, %rax
movl %eax, -0x50(%rbp)
movq -0x68(%rbp), %rax
movl 0x8(%rax), %eax
shrl %eax
movl %eax, -0x54(%rbp)
movq -0x70(%rbp), %rax
movq 0x20(%rax), %rax
movl -0x50(%rbp), %ecx
movzbl 0x4(%rax,%rcx,8), %eax
cmpl $0x1, %eax
jne 0x13cf82
movq -0x70(%rbp), %rax
movq 0x20(%rax), %rax
movl -0x54(%rbp), %ecx
movzbl 0x4(%rax,%rcx,8), %eax
cmpl $0x1, %eax
jne 0x13cf82
jmp 0x13cfcd
movq -0x70(%rbp), %rdi
movq -0x68(%rbp), %rax
movq (%rax), %rax
shrq $0x20, %rax
movl %eax, %esi
movq -0x68(%rbp), %rax
movl 0x8(%rax), %edx
movl $0x1, %ecx
callq 0xd6530
movq -0x70(%rbp), %rdi
movq -0x68(%rbp), %rax
movl 0x8(%rax), %esi
xorl $0x1, %esi
movq -0x68(%rbp), %rax
movq (%rax), %rax
shrq $0x20, %rax
xorq $0x1, %rax
movl %eax, %edx
movl $0x1, %ecx
callq 0xd6530
movl -0x48(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x48(%rbp)
jmp 0x13cf06
movq -0x40(%rbp), %rax
movq 0x18(%rax), %rax
movl (%rax), %eax
movl %eax, -0x4c(%rbp)
movq -0x40(%rbp), %rax
movq (%rax), %rax
movl -0x4c(%rbp), %ecx
imulq $0x1c, %rcx, %rcx
addq %rcx, %rax
movl (%rax), %eax
movl %eax, -0x5c(%rbp)
movq -0x70(%rbp), %rax
movq 0x20(%rax), %rax
movl -0x4c(%rbp), %ecx
shrl %ecx
movl %ecx, %ecx
movl (%rax,%rcx,8), %edx
andl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
orl $0x0, %edx
movl %edx, (%rax,%rcx,8)
movq -0x70(%rbp), %rdi
movq -0x28(%rbp), %rax
movq 0x18(%rax), %rsi
movl -0x5c(%rbp), %edx
movl -0x4c(%rbp), %ecx
movq -0x20(%rbp), %r8
movq 0x38(%rbp), %r9
movq 0x40(%rbp), %r15
movq 0x48(%rbp), %r14
movl 0x50(%rbp), %ebx
movl 0x58(%rbp), %r11d
movl 0x60(%rbp), %r10d
movq 0x68(%rbp), %rax
movq %r15, (%rsp)
movq %r14, 0x8(%rsp)
movl %ebx, 0x10(%rsp)
movl %r11d, 0x18(%rsp)
movl %r10d, 0x20(%rsp)
movq %rax, 0x28(%rsp)
callq 0x13d0a0
movl -0x5c(%rbp), %eax
movl %eax, -0x4c(%rbp)
movl -0x4c(%rbp), %eax
cmpl -0x2c(%rbp), %eax
jne 0x13cfe8
movl -0x44(%rbp), %eax
addq $0x98, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
nopw %cs:(%rax,%rax)