// File: /workspace/github_cpp_makefile_star2_O3/chhylp123[P]hifiasm/Overlaps.cpp
// Function: gen_clean_ug(ma_ug_t*, scaf_res_t*, scaf_res_t*)
ma_ug_t *gen_clean_ug(ma_ug_t *ref, 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) {
        for (i = 0; i < ug->g->n_seq; i++) ug->g->seq[i].del = 1;
        for (i = 0; i < ug->g->n_arc; i++) 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;

                        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;

                        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 $0x18, %rsp
movq %rdx, %rbx
movq %rsi, %r12
callq 0xc8eab
movq %rax, %rbp
movq 0x18(%rax), %r14
movq %r12, %rax
movq %rbx, 0x8(%rsp)
orq %rbx, %rax
je 0xdb232
testl $0x7fffffff, 0x14(%r14) # imm = 0x7FFFFFFF
je 0xdaf04
xorl %eax, %eax
movq 0x20(%r14), %rcx
orl $0x80000000, (%rcx,%rax,8) # imm = 0x80000000
incq %rax
movl 0x14(%r14), %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
cmpq %rcx, %rax
jb 0xdaee7
testl $0x7fffffff, 0x4(%r14)  # imm = 0x7FFFFFFF
je 0xdaf36
movl $0xc, %eax
xorl %ecx, %ecx
movq 0x8(%r14), %rdx
orl $0x80000000, (%rdx,%rax) # imm = 0x80000000
incq %rcx
movl 0x4(%r14), %edx
andl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
addq $0x18, %rax
cmpq %rdx, %rcx
jb 0xdaf15
testq %r12, %r12
je 0xdb0ae
movq 0x8(%r12), %rdx
testq %rdx, %rdx
je 0xdb0ae
xorl %eax, %eax
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
movq %rbp, 0x10(%rsp)
movq (%r12), %rsi
imulq $0x58, %rax, %rdi
cmpq $0x0, 0x20(%rsi,%rdi)
je 0xdb0a3
leaq (%rsi,%rdi), %rdx
addq $0x20, %rdx
xorl %esi, %esi
movq 0x10(%rdx), %rdi
leaq (%rsi,%rsi,8), %r8
movl 0xc(%rdi,%r8,4), %r9d
movl 0x10(%rdi,%r8,4), %r8d
leaq (%r9,%r9,8), %r10
leaq (%rdi,%r10,4), %rdi
subl %r9d, %r8d
je 0xdafb4
movl %r8d, %r9d
movq %rdi, %r10
movq 0x20(%r14), %r11
movl (%r10), %ebx
andl $0x7fffffff, (%r11,%rbx,8) # imm = 0x7FFFFFFF
addq $0x24, %r10
decq %r9
jne 0xdaf9c
cmpl $0x2, %r8d
jb 0xdb08e
movl %r8d, %r8d
movl $0x1, %r9d
leaq (%r9,%r9,8), %r11
movl -0x24(%rdi,%r11,4), %r10d
movl -0x4(%rdi,%r11,4), %ebx
shrl $0x5, %ebx
andl $0x1, %ebx
leal (%rbx,%r10,2), %r10d
movl (%rdi,%r11,4), %ebx
movl 0x20(%rdi,%r11,4), %r11d
shrl $0x5, %r11d
andl $0x1, %r11d
leal (%r11,%rbx,2), %r11d
movq 0x8(%r14), %r13
movq 0x28(%r14), %rbp
movq (%rbp,%r10,8), %r15
movq %r15, %rbx
andq %rcx, %rbx
je 0xdb03e
shrq $0x20, %r15
shlq $0x3, %rbx
leaq (%rbx,%rbx,2), %rbp
leaq (%r15,%r15,2), %rbx
leaq 0xc(%r13,%rbx,8), %r13
xorl %ebx, %ebx
cmpl %r11d, -0x4(%r13,%rbx)
jne 0xdb02d
andb $0x7f, 0x3(%r13,%rbx)
addq $0x18, %rbx
cmpq %rbx, %rbp
jne 0xdb020
movq 0x8(%r14), %r13
movq 0x28(%r14), %rbp
xorl $0x1, %r11d
movq (%rbp,%r11,8), %rbx
movq %rbx, %r11
andq %rcx, %r11
je 0xdb082
shrq $0x20, %rbx
shlq $0x3, %r11
leaq (%r11,%r11,2), %r11
leaq (%rbx,%rbx,2), %rbx
leaq 0xc(%r13,%rbx,8), %r13
xorl %ebp, %ebp
movl -0x4(%r13,%rbp), %ebx
xorl %r10d, %ebx
cmpl $0x1, %ebx
jne 0xdb079
andb $0x7f, 0x3(%r13,%rbp)
addq $0x18, %rbp
cmpq %rbp, %r11
jne 0xdb066
incq %r9
cmpq %r8, %r9
jne 0xdafc7
incl %esi
cmpq %rsi, (%rdx)
ja 0xdaf77
movq 0x8(%r12), %rdx
movq 0x10(%rsp), %rbp
incl %eax
cmpq %rax, %rdx
ja 0xdaf59
cmpq $0x0, 0x8(%rsp)
je 0xdb232
movq 0x8(%rsp), %rax
movq 0x8(%rax), %rdx
testq %rdx, %rdx
je 0xdb232
xorl %eax, %eax
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
movq 0x8(%rsp), %rsi
movq (%rsi), %rsi
imulq $0x58, %rax, %rdi
cmpq $0x0, 0x20(%rsi,%rdi)
je 0xdb227
leaq (%rsi,%rdi), %rdx
addq $0x20, %rdx
xorl %esi, %esi
movq 0x10(%rdx), %rdi
leaq (%rsi,%rsi,8), %r8
movl 0xc(%rdi,%r8,4), %r9d
movl 0x10(%rdi,%r8,4), %r8d
leaq (%r9,%r9,8), %r10
leaq (%rdi,%r10,4), %rdi
subl %r9d, %r8d
je 0xdb132
movl %r8d, %r9d
movq %rdi, %r10
movq 0x20(%r14), %r11
movl (%r10), %ebx
andl $0x7fffffff, (%r11,%rbx,8) # imm = 0x7FFFFFFF
addq $0x24, %r10
decq %r9
jne 0xdb11a
cmpl $0x2, %r8d
jb 0xdb213
movl %r8d, %r8d
movl $0x1, %r9d
leaq (%r9,%r9,8), %r11
movl -0x24(%rdi,%r11,4), %r10d
movl -0x4(%rdi,%r11,4), %ebx
shrl $0x5, %ebx
andl $0x1, %ebx
leal (%rbx,%r10,2), %r10d
movl (%rdi,%r11,4), %ebx
movl 0x20(%rdi,%r11,4), %r11d
shrl $0x5, %r11d
andl $0x1, %r11d
leal (%r11,%rbx,2), %r11d
movq 0x8(%r14), %r12
movq 0x28(%r14), %r13
movq (%r13,%r10,8), %rbx
movq %rbx, %r15
andq %rcx, %r15
je 0xdb1bf
shrq $0x20, %rbx
shlq $0x3, %r15
leaq (%r15,%r15,2), %r13
leaq (%rbx,%rbx,2), %rbx
leaq (%r12,%rbx,8), %r12
addq $0xc, %r12
xorl %ebx, %ebx
cmpl %r11d, -0x4(%r12,%rbx)
jne 0xdb1ae
andb $0x7f, 0x3(%r12,%rbx)
addq $0x18, %rbx
cmpq %rbx, %r13
jne 0xdb1a1
movq 0x8(%r14), %r12
movq 0x28(%r14), %r13
xorl $0x1, %r11d
movq (%r13,%r11,8), %rbx
movq %rbx, %r11
andq %rcx, %r11
je 0xdb207
shrq $0x20, %rbx
shlq $0x3, %r11
leaq (%r11,%r11,2), %r11
leaq (%rbx,%rbx,2), %rbx
leaq (%r12,%rbx,8), %r12
addq $0xc, %r12
xorl %r13d, %r13d
movl -0x4(%r12,%r13), %ebx
xorl %r10d, %ebx
cmpl $0x1, %ebx
jne 0xdb1fe
andb $0x7f, 0x3(%r12,%r13)
addq $0x18, %r13
cmpq %r13, %r11
jne 0xdb1eb
incq %r9
cmpq %r8, %r9
jne 0xdb145
incl %esi
cmpq %rsi, (%rdx)
ja 0xdb0f5
movq 0x8(%rsp), %rdx
movq 0x8(%rdx), %rdx
incl %eax
cmpq %rax, %rdx
ja 0xdb0d3
testl $0x7fffffff, 0x14(%r14) # imm = 0x7FFFFFFF
je 0xdb34d
xorl %r15d, %r15d
movl $0xffffffff, %r12d      # imm = 0xFFFFFFFF
xorl %r13d, %r13d
movq 0x20(%r14), %rax
cmpl $0x0, (%rax,%r13,8)
jns 0xdb338
leaq (,%r13,2), %rax
movb $0x1, %cl
xorl %edx, %edx
orq %rax, %rdx
movq 0x28(%r14), %rsi
movq (%rsi,%rdx,8), %rdi
movq %rdi, %rsi
andq %r12, %rsi
je 0xdb2f2
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 0xdb2ea
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 0xdb2e1
orb $-0x80, 0x3(%r10,%r11)
addq $0x18, %r11
cmpq %r11, %r9
jne 0xdb2cf
incq %r8
cmpq %rsi, %r8
jne 0xdb28d
movl $0x1, %edx
testb $0x1, %cl
movl $0x0, %ecx
jne 0xdb267
movq 0x10(%rbp), %rax
leaq (,%r13,4), %rcx
addq %r13, %rcx
cmpl $0x0, 0xc(%rax,%rcx,8)
je 0xdb338
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 0xdb24c
movq %r14, %rdi
callq 0xa0a7d
movq %rbp, %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq