// File: /workspace/github_cpp_makefile_star2_O1/chhylp123[P]hifiasm/Overlaps.cpp
// Function: gen_shallow_clean_ug(ma_ug_t*, bubble_type*, scaf_res_t*, scaf_res_t*)
ma_ug_t *gen_shallow_clean_ug(ma_ug_t *ref, bubble_type *bu, scaf_res_t *cp0, scaf_res_t *cp1)
{
    ma_ug_t *ug = copy_untig_graph(ref);
    uint32_t i, k, a_n, z, v, w; scaf_res_t *ctg = NULL; ul_vec_t *idx; uc_block_t *a; 
    if(cp0 || cp1) {
        ///just clean bubbles
        for (i = 0; i < ug->g->n_seq; i++) {
            // if(i < bu->f_bub) ug->g->seq[i].del = 1;///no need broken bubble; looks like a bug in scaffolding
            if(bu->index[i] < bu->f_bub) ug->g->seq[i].del = 1;
        }
        for (i = 0; i < ug->g->n_arc; i++) {
            if((bu->index[ug->g->arc[i].ul>>33] < bu->f_bub) || (bu->index[ug->g->arc[i].v>>1] < bu->f_bub)) {///no need broken bubble
                ug->g->arc[i].del = 1;
            }
        }
        
        ctg = cp0;
        if (ctg) {
            for(i = 0; i < ctg->n; i++) {
                idx = &(ctg->a[i]);
                for (k = 0; k < idx->bb.n; k++) {
                    a = idx->bb.a + idx->bb.a[k].ts; a_n = idx->bb.a[k].te - idx->bb.a[k].ts;
                    for (z = 0; z < a_n; z++) ug->g->seq[a[z].hid].del = 0; 
                    for (z = 1; z < a_n; z++) {
                        v = a[z-1].hid<<1; v |= (uint32_t)a[z-1].rev;
                        w = a[z].hid<<1; w |= (uint32_t)a[z].rev;
                        // if(((v>>1) < bu->f_bub) || ((w>>1) < bu->f_bub)) {
                        if((bu->index[(v>>1)] < bu->f_bub) || (bu->index[(w>>1)] < bu->f_bub)) {    
                            asg_arc_del(ug->g, v, w, 0);
                            asg_arc_del(ug->g, w^1, v^1, 0);
                        }
                    }
                }
            }
        }
        
        ctg = cp1;
        if (ctg) {
            for(i = 0; i < ctg->n; i++) {
                idx = &(ctg->a[i]);
                for (k = 0; k < idx->bb.n; k++) {
                    a = idx->bb.a + idx->bb.a[k].ts; a_n = idx->bb.a[k].te - idx->bb.a[k].ts;
                    for (z = 0; z < a_n; z++) ug->g->seq[a[z].hid].del = 0; 
                    for (z = 1; z < a_n; z++) {
                        v = a[z-1].hid<<1; v |= (uint32_t)a[z-1].rev;
                        w = a[z].hid<<1; w |= (uint32_t)a[z].rev;
                        // if(((v>>1) < bu->f_bub) || ((w>>1) < bu->f_bub)) {
                        if((bu->index[(v>>1)] < bu->f_bub) || (bu->index[(w>>1)] < bu->f_bub)) {
                            asg_arc_del(ug->g, v, w, 0);
                            asg_arc_del(ug->g, w^1, v^1, 0);
                        }
                    }
                }
            }
        }
    }
    

    for (i = 0; i < ug->g->n_seq; i++) {
        if(ug->g->seq[i].del == 1) {
            asg_seq_del(ug->g, i);
            if(ug->u.a[i].m!=0) {
                ug->u.a[i].m = ug->u.a[i].n = 0;
                free(ug->u.a[i].a);
                ug->u.a[i].a = NULL;
            }
        }
    }

    asg_cleanup(ug->g);

    return ug;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rcx, %rbx
movq %rdx, %r14
movq %rsi, %r15
callq 0xc815c
movq %rax, 0x10(%rsp)
movq %r14, %rax
orq %rbx, %rax
je 0xda33c
movq 0x10(%rsp), %rax
movq 0x18(%rax), %rax
testl $0x7fffffff, 0x14(%rax) # imm = 0x7FFFFFFF
je 0xd9f6f
xorl %ecx, %ecx
movq (%r15), %rdx
movl (%rdx,%rcx,4), %edx
cmpq %rdx, 0x80(%r15)
jbe 0xd9f5e
movq 0x20(%rax), %rdx
orl $0x80000000, (%rdx,%rcx,8) # imm = 0x80000000
incq %rcx
movl 0x14(%rax), %edx
andl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
cmpq %rdx, %rcx
jb 0xd9f44
testl $0x7fffffff, 0x4(%rax)  # imm = 0x7FFFFFFF
je 0xd9fca
movl $0xc, %ecx
xorl %edx, %edx
movq (%r15), %r8
movq 0x80(%r15), %rdi
movq 0x8(%rax), %rsi
movq -0xc(%rsi,%rcx), %r9
shrq $0x21, %r9
movl (%r8,%r9,4), %r9d
cmpq %r9, %rdi
ja 0xd9fb0
movl -0x4(%rsi,%rcx), %r9d
shrl %r9d
movl (%r8,%r9,4), %r8d
cmpq %r8, %rdi
jbe 0xd9fb5
orb $-0x80, 0x3(%rsi,%rcx)
incq %rdx
movl 0x4(%rax), %esi
andl $0x7fffffff, %esi       # imm = 0x7FFFFFFF
addq $0x18, %rcx
cmpq %rsi, %rdx
jb 0xd9f7f
movq %rbx, 0x18(%rsp)
testq %r14, %r14
je 0xda183
cmpq $0x0, 0x8(%r14)
je 0xda183
xorl %ecx, %ecx
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
movq %r14, 0x20(%rsp)
movq (%r14), %rsi
movq %rcx, 0x8(%rsp)
imulq $0x58, %rcx, %rdi
cmpq $0x0, 0x20(%rsi,%rdi)
je 0xda16d
addq %rdi, %rsi
addq $0x20, %rsi
xorl %edi, %edi
movq 0x10(%rsi), %r8
leaq (%rdi,%rdi,8), %r9
movl 0xc(%r8,%r9,4), %r10d
movl 0x10(%r8,%r9,4), %r9d
leaq (%r10,%r10,8), %r11
leaq (%r8,%r11,4), %r8
subl %r10d, %r9d
je 0xda04d
movl %r9d, %r10d
movq %r8, %r11
movq 0x20(%rax), %rbx
movl (%r11), %r14d
andl $0x7fffffff, (%rbx,%r14,8) # imm = 0x7FFFFFFF
addq $0x24, %r11
decq %r10
jne 0xda035
cmpl $0x2, %r9d
jb 0xda162
movl %r9d, %r9d
movl $0x1, %r10d
leaq (%r10,%r10,8), %r14
movl -0x24(%r8,%r14,4), %ecx
movl -0x4(%r8,%r14,4), %ebx
movl (%r8,%r14,4), %r13d
movl 0x20(%r8,%r14,4), %ebp
movq (%r15), %r12
movq 0x80(%r15), %r14
movl %ecx, %r11d
andl $0x7fffffff, %r11d      # imm = 0x7FFFFFFF
movl (%r12,%r11,4), %r11d
cmpq %r11, %r14
ja 0xda0ab
movl %r13d, %r11d
andl $0x7fffffff, %r11d      # imm = 0x7FFFFFFF
movl (%r12,%r11,4), %r11d
cmpq %r11, %r14
jbe 0xda156
shrl $0x5, %ebx
andl $0x1, %ebx
leal (%rbx,%rcx,2), %r11d
shrl $0x5, %ebp
andl $0x1, %ebp
leal (%rbp,%r13,2), %r13d
movq 0x28(%rax), %rcx
movl %r11d, %ebx
movq (%rcx,%rbx,8), %r14
movq %r14, %rbx
andq %rdx, %rbx
je 0xda108
movq 0x8(%rax), %rcx
shrq $0x20, %r14
shlq $0x3, %rbx
leaq (%rbx,%rbx,2), %rbx
leaq (%r14,%r14,2), %r14
leaq (%rcx,%r14,8), %rbp
addq $0xc, %rbp
xorl %r14d, %r14d
cmpl %r13d, -0x4(%rbp,%r14)
jne 0xda0ff
andb $0x7f, 0x3(%rbp,%r14)
addq $0x18, %r14
cmpq %r14, %rbx
jne 0xda0f2
xorl $0x1, %r13d
movq 0x28(%rax), %rcx
movq (%rcx,%r13,8), %r14
movq %r14, %rbx
andq %rdx, %rbx
je 0xda156
movq 0x8(%rax), %rcx
shrq $0x20, %r14
shlq $0x3, %rbx
leaq (%rbx,%rbx,2), %rbx
leaq (%r14,%r14,2), %r14
leaq (%rcx,%r14,8), %r13
addq $0xc, %r13
xorl %ebp, %ebp
movl -0x4(%r13,%rbp), %ecx
xorl %r11d, %ecx
cmpl $0x1, %ecx
jne 0xda14d
andb $0x7f, 0x3(%r13,%rbp)
addq $0x18, %rbp
cmpq %rbp, %rbx
jne 0xda13a
incq %r10
cmpq %r9, %r10
jne 0xda060
incl %edi
cmpq %rdi, (%rsi)
ja 0xda010
movq 0x8(%rsp), %rcx
incl %ecx
movq 0x20(%rsp), %r14
cmpq %rcx, 0x8(%r14)
ja 0xd9fef
movq 0x18(%rsp), %rcx
testq %rcx, %rcx
je 0xda33c
cmpq $0x0, 0x8(%rcx)
je 0xda33c
xorl %edi, %edi
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
movq (%rcx), %rsi
movq %rdi, 0x8(%rsp)
imulq $0x58, %rdi, %rdi
cmpq $0x0, 0x20(%rsi,%rdi)
je 0xda326
addq %rdi, %rsi
addq $0x20, %rsi
xorl %edi, %edi
movq 0x10(%rsi), %r8
leaq (%rdi,%rdi,8), %r9
movl 0xc(%r8,%r9,4), %r10d
movl 0x10(%r8,%r9,4), %r9d
leaq (%r10,%r10,8), %r11
leaq (%r8,%r11,4), %r8
subl %r10d, %r9d
je 0xda201
movl %r9d, %r10d
movq %r8, %r11
movq 0x20(%rax), %rbx
movl (%r11), %r14d
andl $0x7fffffff, (%rbx,%r14,8) # imm = 0x7FFFFFFF
addq $0x24, %r11
decq %r10
jne 0xda1e9
cmpl $0x2, %r9d
jb 0xda31b
movl %r9d, %r9d
movl $0x1, %r10d
leaq (%r10,%r10,8), %r14
movl -0x24(%r8,%r14,4), %ecx
movl -0x4(%r8,%r14,4), %ebx
movl (%r8,%r14,4), %r12d
movl 0x20(%r8,%r14,4), %r13d
movq (%r15), %rbp
movq 0x80(%r15), %r14
movl %ecx, %r11d
andl $0x7fffffff, %r11d      # imm = 0x7FFFFFFF
movl (%rbp,%r11,4), %r11d
cmpq %r11, %r14
ja 0xda261
movl %r12d, %r11d
andl $0x7fffffff, %r11d      # imm = 0x7FFFFFFF
movl (%rbp,%r11,4), %r11d
cmpq %r11, %r14
jbe 0xda30f
shrl $0x5, %ebx
andl $0x1, %ebx
leal (%rbx,%rcx,2), %r11d
shrl $0x5, %r13d
andl $0x1, %r13d
leal (%r13,%r12,2), %r12d
movq 0x28(%rax), %rcx
movl %r11d, %ebx
movq (%rcx,%rbx,8), %r14
movq %r14, %rbx
andq %rdx, %rbx
je 0xda2c0
movq 0x8(%rax), %rcx
shrq $0x20, %r14
shlq $0x3, %rbx
leaq (%rbx,%rbx,2), %rbx
leaq (%r14,%r14,2), %r14
leaq (%rcx,%r14,8), %r13
addq $0xc, %r13
xorl %r14d, %r14d
cmpl %r12d, -0x4(%r13,%r14)
jne 0xda2b7
andb $0x7f, 0x3(%r13,%r14)
addq $0x18, %r14
cmpq %r14, %rbx
jne 0xda2aa
xorl $0x1, %r12d
movq 0x28(%rax), %rcx
movq (%rcx,%r12,8), %r14
movq %r14, %rbx
andq %rdx, %rbx
je 0xda30f
movq 0x8(%rax), %rcx
shrq $0x20, %r14
shlq $0x3, %rbx
leaq (%rbx,%rbx,2), %rbx
leaq (%r14,%r14,2), %r14
leaq (%rcx,%r14,8), %r12
addq $0xc, %r12
xorl %r13d, %r13d
movl -0x4(%r12,%r13), %ecx
xorl %r11d, %ecx
cmpl $0x1, %ecx
jne 0xda306
andb $0x7f, 0x3(%r12,%r13)
addq $0x18, %r13
cmpq %r13, %rbx
jne 0xda2f3
incq %r10
cmpq %r9, %r10
jne 0xda214
incl %edi
cmpq %rdi, (%rsi)
ja 0xda1c4
movq 0x8(%rsp), %rdi
incl %edi
movq 0x18(%rsp), %rcx
cmpq %rdi, 0x8(%rcx)
ja 0xda1a3
movq 0x10(%rsp), %rbp
movq 0x18(%rbp), %r14
testl $0x7fffffff, 0x14(%r14) # imm = 0x7FFFFFFF
je 0xda461
xorl %r15d, %r15d
movl $0xffffffff, %r12d      # imm = 0xFFFFFFFF
xorl %r13d, %r13d
movq 0x20(%r14), %rax
movl (%rax,%r13,8), %ecx
testl %ecx, %ecx
jns 0xda44c
movl %ecx, (%rax,%r13,8)
leaq (,%r13,2), %rax
xorl %ecx, %ecx
leaq (%rcx,%rax), %rdx
movq 0x28(%r14), %rsi
movq (%rsi,%rdx,8), %rdi
movq %rdi, %rsi
andq %r12, %rsi
je 0xda409
shrq $0x20, %rdi
leaq (%rdi,%rdi,2), %rdi
shlq $0x3, %rdi
addq 0x8(%r14), %rdi
xorl %r8d, %r8d
leaq (%r8,%r8,2), %r9
orb $-0x80, 0xf(%rdi,%r9,8)
movl 0x8(%rdi,%r9,8), %r9d
xorq $0x1, %r9
movq 0x28(%r14), %r10
movq (%r10,%r9,8), %r10
movq %r10, %r9
andq %r12, %r9
je 0xda401
movq 0x8(%r14), %r11
shrq $0x20, %r10
shlq $0x3, %r9
leaq (%r9,%r9,2), %r9
leaq (%r10,%r10,2), %r10
leaq (%r11,%r10,8), %r10
addq $0xc, %r10
xorl %r11d, %r11d
movl -0x4(%r10,%r11), %ebx
xorl %edx, %ebx
cmpl $0x1, %ebx
jne 0xda3f8
orb $-0x80, 0x3(%r10,%r11)
addq $0x18, %r11
cmpq %r11, %r9
jne 0xda3e6
incq %r8
cmpq %rsi, %r8
jne 0xda3a4
leaq 0x1(%rcx), %rdx
testq %rcx, %rcx
movq %rdx, %rcx
je 0xda37d
movq 0x10(%rbp), %rax
leaq (,%r13,4), %rcx
addq %r13, %rcx
cmpl $0x0, 0xc(%rax,%rcx,8)
je 0xda44c
leaq (%rax,%rcx,8), %rbx
movl %r15d, 0x10(%rbx)
movl %r15d, 0xc(%rbx)
movq 0x18(%rbx), %rdi
callq 0x2220
movq $0x0, 0x18(%rbx)
incq %r13
movl 0x14(%r14), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
cmpq %rax, %r13
jb 0xda35f
movq %r14, %rdi
callq 0xa02fa
movq %rbp, %rax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq