// File: /workspace/github_cpp_makefile_star2_O2/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 $0x38, %rsp
movq %rcx, %rbx
movq %rdx, %r14
movq %rsi, %r12
callq 0x8c99a
movq %r14, %rcx
movq %rax, 0x30(%rsp)
movq 0x18(%rax), %r14
movq %rcx, %rax
orq %rbx, %rax
je 0x9e1c0
movq %rcx, 0x28(%rsp)
movq %rbx, (%rsp)
xorl %eax, %eax
movl 0x14(%r14), %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
cmpq %rcx, %rax
jae 0x9dee8
movq (%r12), %rcx
movl (%rcx,%rax,4), %ecx
cmpq %rcx, 0x80(%r12)
jbe 0x9dee3
movq 0x20(%r14), %rcx
orl $0x80000000, (%rcx,%rax,8) # imm = 0x80000000
incq %rax
jmp 0x9deb8
pushq $0xc
popq %rax
xorl %ecx, %ecx
movl 0x4(%r14), %edx
andl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
cmpq %rdx, %rcx
jae 0x9df3d
movq (%r12), %rdi
movq 0x80(%r12), %rsi
movq 0x8(%r14), %rdx
movq -0xc(%rdx,%rax), %r8
shrq $0x21, %r8
movl (%rdi,%r8,4), %r8d
cmpq %r8, %rsi
ja 0x9df2f
movl -0x4(%rdx,%rax), %r8d
shrl %r8d
movl (%rdi,%r8,4), %edi
cmpq %rdi, %rsi
jbe 0x9df34
orb $-0x80, 0x3(%rdx,%rax)
incq %rcx
addq $0x18, %rax
jmp 0x9deed
movq 0x28(%rsp), %rcx
testq %rcx, %rcx
movq (%rsp), %rax
je 0x9e086
xorl %edx, %edx
movl %edx, %edx
cmpq %rdx, 0x8(%rcx)
jbe 0x9e086
movq (%rcx), %rax
imulq $0x58, %rdx, %rcx
addq %rcx, %rax
addq $0x20, %rax
xorl %ecx, %ecx
movq %rdx, 0x10(%rsp)
movq %rax, 0x8(%rsp)
movl %ecx, %ecx
cmpq %rcx, (%rax)
jbe 0x9e076
movq 0x10(%rax), %rax
movq %rcx, 0x18(%rsp)
imulq $0x24, %rcx, %rcx
movl 0xc(%rax,%rcx), %esi
movl 0x10(%rax,%rcx), %edi
imulq $0x24, %rsi, %rcx
leaq (%rax,%rcx), %rdx
subl %esi, %edi
movq %rdi, 0x20(%rsp)
imulq $0x24, %rdi, %rsi
xorl %edi, %edi
cmpq %rdi, %rsi
je 0x9dfc7
movq 0x20(%r14), %r8
movl (%rdx,%rdi), %r9d
andl $0x7fffffff, (%r8,%r9,8) # imm = 0x7FFFFFFF
addq $0x24, %rdi
jmp 0x9dfac
leaq (%rax,%rcx), %r13
addq $0x44, %r13
pushq $0x1
popq %r15
cmpq 0x20(%rsp), %r15
jae 0x9e060
movl -0x44(%r13), %edx
movl -0x24(%r13), %esi
movl -0x20(%r13), %eax
movl (%r13), %ecx
movq (%r12), %r8
movq 0x80(%r12), %rdi
movl %edx, %r9d
andl $0x7fffffff, %r9d       # imm = 0x7FFFFFFF
movl (%r8,%r9,4), %r9d
cmpq %r9, %rdi
ja 0x9e020
movl %eax, %r9d
andl $0x7fffffff, %r9d       # imm = 0x7FFFFFFF
movl (%r8,%r9,4), %r8d
cmpq %r8, %rdi
jbe 0x9e054
shrl $0x5, %esi
andl $0x1, %esi
leal (%rsi,%rdx,2), %ebp
shrl $0x5, %ecx
andl $0x1, %ecx
leal (%rcx,%rax,2), %ebx
movq %r14, %rdi
movl %ebp, %esi
movl %ebx, %edx
xorl %ecx, %ecx
callq 0x6db50
xorl $0x1, %ebx
xorl $0x1, %ebp
movq %r14, %rdi
movl %ebx, %esi
movl %ebp, %edx
xorl %ecx, %ecx
callq 0x6db50
incq %r15
addq $0x24, %r13
jmp 0x9dfd3
movq 0x18(%rsp), %rcx
incl %ecx
movq 0x10(%rsp), %rdx
movq 0x8(%rsp), %rax
jmp 0x9df77
incl %edx
movq (%rsp), %rax
movq 0x28(%rsp), %rcx
jmp 0x9df51
testq %rax, %rax
je 0x9e1c0
xorl %ecx, %ecx
movl %ecx, %ecx
cmpq %rcx, 0x8(%rax)
jbe 0x9e1c0
movq (%rax), %rax
movq %rcx, 0x8(%rsp)
imulq $0x58, %rcx, %rcx
addq %rcx, %rax
addq $0x20, %rax
xorl %ecx, %ecx
movq %rax, 0x10(%rsp)
movl %ecx, %ecx
cmpq %rcx, (%rax)
jbe 0x9e1b0
movq 0x10(%rax), %rax
movq %rcx, 0x18(%rsp)
imulq $0x24, %rcx, %rcx
movl 0xc(%rax,%rcx), %esi
movl 0x10(%rax,%rcx), %edi
imulq $0x24, %rsi, %rcx
leaq (%rax,%rcx), %rdx
subl %esi, %edi
movq %rdi, 0x20(%rsp)
imulq $0x24, %rdi, %rsi
xorl %edi, %edi
cmpq %rdi, %rsi
je 0x9e107
movq 0x20(%r14), %r8
movl (%rdx,%rdi), %r9d
andl $0x7fffffff, (%r8,%r9,8) # imm = 0x7FFFFFFF
addq $0x24, %rdi
jmp 0x9e0ec
leaq (%rax,%rcx), %r15
addq $0x44, %r15
pushq $0x1
popq %r13
cmpq 0x20(%rsp), %r13
jae 0x9e19f
movl -0x44(%r15), %edx
movl -0x24(%r15), %esi
movl -0x20(%r15), %eax
movl (%r15), %ecx
movq (%r12), %r8
movq 0x80(%r12), %rdi
movl %edx, %r9d
andl $0x7fffffff, %r9d       # imm = 0x7FFFFFFF
movl (%r8,%r9,4), %r9d
cmpq %r9, %rdi
ja 0x9e15f
movl %eax, %r9d
andl $0x7fffffff, %r9d       # imm = 0x7FFFFFFF
movl (%r8,%r9,4), %r8d
cmpq %r8, %rdi
jbe 0x9e193
shrl $0x5, %esi
andl $0x1, %esi
leal (%rsi,%rdx,2), %ebx
shrl $0x5, %ecx
andl $0x1, %ecx
leal (%rcx,%rax,2), %ebp
movq %r14, %rdi
movl %ebx, %esi
movl %ebp, %edx
xorl %ecx, %ecx
callq 0x6db50
xorl $0x1, %ebp
xorl $0x1, %ebx
movq %r14, %rdi
movl %ebp, %esi
movl %ebx, %edx
xorl %ecx, %ecx
callq 0x6db50
incq %r13
addq $0x24, %r15
jmp 0x9e113
movq 0x18(%rsp), %rcx
incl %ecx
movq 0x10(%rsp), %rax
jmp 0x9e0b7
movq 0x8(%rsp), %rcx
incl %ecx
movq (%rsp), %rax
jmp 0x9e091
pushq $0x3
popq %rbx
xorl %r15d, %r15d
movl 0x14(%r14), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
cmpq %rax, %r15
jae 0x9e218
movq 0x20(%r14), %rax
cmpl $0x0, (%rax,%r15,8)
jns 0x9e20f
movq %r14, %rdi
movl %r15d, %esi
callq 0x6f8da
movq 0x30(%rsp), %rax
movq 0x10(%rax), %r12
cmpl $0x0, -0xc(%r12,%rbx,8)
je 0x9e20f
andq $0x0, -0xc(%r12,%rbx,8)
movq (%r12,%rbx,8), %rdi
callq 0x2220
andq $0x0, (%r12,%rbx,8)
incq %r15
addq $0x5, %rbx
jmp 0x9e1c6
movq %r14, %rdi
callq 0x694eb
movq 0x30(%rsp), %rax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq