// File: /workspace/github_cpp_makefile_star2_O1/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
pushq %rax
movq %rdx, %r14
movq %rsi, %r15
callq 0xc815c
movq %rax, %rbp
movq %r15, %rax
orq %r14, %rax
je 0xd9dc9
movq 0x18(%rbp), %rax
testl $0x7fffffff, 0x14(%rax) # imm = 0x7FFFFFFF
je 0xd9ac7
xorl %ecx, %ecx
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 0xd9aab
movq %rbp, (%rsp)
testl $0x7fffffff, 0x4(%rax)  # imm = 0x7FFFFFFF
je 0xd9afb
movl $0xc, %ecx
xorl %edx, %edx
movq 0x8(%rax), %rsi
orl $0x80000000, (%rsi,%rcx) # imm = 0x80000000
incq %rdx
movl 0x4(%rax), %esi
andl $0x7fffffff, %esi       # imm = 0x7FFFFFFF
addq $0x18, %rcx
cmpq %rsi, %rdx
jb 0xd9adb
testq %r15, %r15
je 0xd9c5e
cmpq $0x0, 0x8(%r15)
je 0xd9c5e
xorl %ecx, %ecx
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
movq (%r15), %rsi
imulq $0x58, %rcx, %rdi
cmpq $0x0, 0x20(%rsi,%rdi)
je 0xd9c52
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 0xd9b6f
movl %r9d, %r10d
movq %r8, %r11
movq 0x20(%rax), %rbx
movl (%r11), %r12d
andl $0x7fffffff, (%rbx,%r12,8) # imm = 0x7FFFFFFF
addq $0x24, %r11
decq %r10
jne 0xd9b57
cmpl $0x2, %r9d
jb 0xd9c47
movl %r9d, %r9d
movl $0x1, %r10d
leaq (%r10,%r10,8), %rbx
movl -0x24(%r8,%rbx,4), %r11d
movl -0x4(%r8,%rbx,4), %r12d
shrl $0x5, %r12d
andl $0x1, %r12d
leal (%r12,%r11,2), %r11d
movl (%r8,%rbx,4), %r12d
movl 0x20(%r8,%rbx,4), %ebx
shrl $0x5, %ebx
andl $0x1, %ebx
leal (%rbx,%r12,2), %r12d
movq 0x28(%rax), %rbx
movq (%rbx,%r11,8), %rbx
movq %rbx, %r13
andq %rdx, %r13
je 0xd9bf0
movq 0x8(%rax), %rbp
shrq $0x20, %rbx
shlq $0x3, %r13
leaq (%r13,%r13,2), %r13
leaq (%rbx,%rbx,2), %rbx
leaq 0xc(%rbp,%rbx,8), %rbp
xorl %ebx, %ebx
cmpl %r12d, -0x4(%rbp,%rbx)
jne 0xd9be7
andb $0x7f, 0x3(%rbp,%rbx)
addq $0x18, %rbx
cmpq %rbx, %r13
jne 0xd9bdb
xorl $0x1, %r12d
movq 0x28(%rax), %rbx
movq (%rbx,%r12,8), %rbx
movq %rbx, %r12
andq %rdx, %r12
je 0xd9c3b
movq 0x8(%rax), %r13
shrq $0x20, %rbx
shlq $0x3, %r12
leaq (%r12,%r12,2), %r12
leaq (%rbx,%rbx,2), %rbx
leaq 0xc(%r13,%rbx,8), %r13
xorl %ebp, %ebp
movl -0x4(%r13,%rbp), %ebx
xorl %r11d, %ebx
cmpl $0x1, %ebx
jne 0xd9c32
andb $0x7f, 0x3(%r13,%rbp)
addq $0x18, %rbp
cmpq %rbp, %r12
jne 0xd9c1f
incq %r10
cmpq %r9, %r10
jne 0xd9b82
incl %edi
cmpq %rdi, (%rsi)
ja 0xd9b32
incl %ecx
cmpq %rcx, 0x8(%r15)
ja 0xd9b16
testq %r14, %r14
movq (%rsp), %rbp
je 0xd9dc9
cmpq $0x0, 0x8(%r14)
je 0xd9dc9
xorl %ecx, %ecx
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
movq (%r14), %rsi
imulq $0x58, %rcx, %rdi
cmpq $0x0, 0x20(%rsi,%rdi)
je 0xd9dbd
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 0xd9cd6
movl %r9d, %r10d
movq %r8, %r11
movq 0x20(%rax), %rbx
movl (%r11), %r15d
andl $0x7fffffff, (%rbx,%r15,8) # imm = 0x7FFFFFFF
addq $0x24, %r11
decq %r10
jne 0xd9cbe
cmpl $0x2, %r9d
jb 0xd9db2
movl %r9d, %r9d
movl $0x1, %r10d
leaq (%r10,%r10,8), %rbx
movl -0x24(%r8,%rbx,4), %r11d
movl -0x4(%r8,%rbx,4), %r15d
shrl $0x5, %r15d
andl $0x1, %r15d
leal (%r15,%r11,2), %r11d
movl (%r8,%rbx,4), %r15d
movl 0x20(%r8,%rbx,4), %ebx
shrl $0x5, %ebx
andl $0x1, %ebx
leal (%rbx,%r15,2), %r15d
movq 0x28(%rax), %rbx
movq (%rbx,%r11,8), %rbx
movq %rbx, %r12
andq %rdx, %r12
je 0xd9d57
movq 0x8(%rax), %r13
shrq $0x20, %rbx
shlq $0x3, %r12
leaq (%r12,%r12,2), %r12
leaq (%rbx,%rbx,2), %rbx
leaq 0xc(%r13,%rbx,8), %r13
xorl %ebx, %ebx
cmpl %r15d, -0x4(%r13,%rbx)
jne 0xd9d4e
andb $0x7f, 0x3(%r13,%rbx)
addq $0x18, %rbx
cmpq %rbx, %r12
jne 0xd9d41
xorl $0x1, %r15d
movq 0x28(%rax), %rbx
movq (%rbx,%r15,8), %rbx
movq %rbx, %r15
andq %rdx, %r15
je 0xd9da6
movq 0x8(%rax), %r12
shrq $0x20, %rbx
shlq $0x3, %r15
leaq (%r15,%r15,2), %r15
leaq (%rbx,%rbx,2), %rbx
leaq (%r12,%rbx,8), %r12
addq $0xc, %r12
xorl %r13d, %r13d
movl -0x4(%r12,%r13), %ebx
xorl %r11d, %ebx
cmpl $0x1, %ebx
jne 0xd9d9d
andb $0x7f, 0x3(%r12,%r13)
addq $0x18, %r13
cmpq %r13, %r15
jne 0xd9d8a
incq %r10
cmpq %r9, %r10
jne 0xd9ce9
incl %edi
cmpq %rdi, (%rsi)
ja 0xd9c99
incl %ecx
cmpq %rcx, 0x8(%r14)
ja 0xd9c7d
movq 0x18(%rbp), %r14
testl $0x7fffffff, 0x14(%r14) # imm = 0x7FFFFFFF
je 0xd9ee9
xorl %r15d, %r15d
movl $0xffffffff, %r12d      # imm = 0xFFFFFFFF
xorl %r13d, %r13d
movq 0x20(%r14), %rax
movl (%rax,%r13,8), %ecx
testl %ecx, %ecx
jns 0xd9ed4
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 0xd9e91
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 0xd9e89
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 0xd9e80
orb $-0x80, 0x3(%r10,%r11)
addq $0x18, %r11
cmpq %r11, %r9
jne 0xd9e6e
incq %r8
cmpq %rsi, %r8
jne 0xd9e2c
leaq 0x1(%rcx), %rdx
testq %rcx, %rcx
movq %rdx, %rcx
je 0xd9e05
movq 0x10(%rbp), %rax
leaq (,%r13,4), %rcx
addq %r13, %rcx
cmpl $0x0, 0xc(%rax,%rcx,8)
je 0xd9ed4
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 0xd9de7
movq %r14, %rdi
callq 0xa02fa
movq %rbp, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq