// File: /workspace/github_cpp_makefile_star2_O2/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 $0x38, %rsp
movq %rdx, %rbx
movq %rsi, %r14
callq 0x8c99a
movq %r14, %rcx
movq %rax, 0x30(%rsp)
movq 0x18(%rax), %r14
movq %rcx, %rax
orq %rbx, %rax
je 0x9de05
movq %rcx, 0x28(%rsp)
movq %rbx, 0x8(%rsp)
xorl %eax, %eax
movl 0x14(%r14), %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
cmpq %rcx, %rax
jae 0x9dbcb
movq 0x20(%r14), %rcx
orl $0x80000000, (%rcx,%rax,8) # imm = 0x80000000
incq %rax
jmp 0x9dbac
pushq $0xc
popq %rax
xorl %ecx, %ecx
movl 0x4(%r14), %edx
andl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
cmpq %rdx, %rcx
jae 0x9dbf3
movq 0x8(%r14), %rdx
orl $0x80000000, (%rdx,%rax) # imm = 0x80000000
incq %rcx
addq $0x18, %rax
jmp 0x9dbd0
movq 0x28(%rsp), %rcx
testq %rcx, %rcx
movq 0x8(%rsp), %rax
je 0x9dd06
xorl %edx, %edx
movl %edx, %edx
cmpq %rdx, 0x8(%rcx)
jbe 0x9dd06
movq (%rcx), %rax
imulq $0x58, %rdx, %rcx
addq %rcx, %rax
addq $0x20, %rax
xorl %ecx, %ecx
movq %rdx, 0x18(%rsp)
movq %rax, 0x10(%rsp)
movl %ecx, %ecx
cmpq %rcx, (%rax)
jbe 0x9dcf5
movq 0x10(%rax), %rax
movq %rcx, 0x20(%rsp)
imulq $0x24, %rcx, %rcx
movl 0xc(%rax,%rcx), %esi
movl 0x10(%rax,%rcx), %r15d
imulq $0x24, %rsi, %rcx
leaq (%rax,%rcx), %rdx
subl %esi, %r15d
imulq $0x24, %r15, %rsi
xorl %edi, %edi
cmpq %rdi, %rsi
je 0x9dc7b
movq 0x20(%r14), %r8
movl (%rdx,%rdi), %r9d
andl $0x7fffffff, (%r8,%r9,8) # imm = 0x7FFFFFFF
addq $0x24, %rdi
jmp 0x9dc60
leaq (%rax,%rcx), %r12
addq $0x44, %r12
pushq $0x1
popq %rbx
cmpq %r15, %rbx
jae 0x9dcdf
movl -0x44(%r12), %eax
movl -0x24(%r12), %ecx
shrl $0x5, %ecx
andl $0x1, %ecx
leal (%rcx,%rax,2), %ebp
movl -0x20(%r12), %eax
movl (%r12), %ecx
shrl $0x5, %ecx
andl $0x1, %ecx
leal (%rcx,%rax,2), %r13d
movq %r14, %rdi
movl %ebp, %esi
movl %r13d, %edx
xorl %ecx, %ecx
callq 0x6db50
xorl $0x1, %r13d
xorl $0x1, %ebp
movq %r14, %rdi
movl %r13d, %esi
movl %ebp, %edx
xorl %ecx, %ecx
callq 0x6db50
incq %rbx
addq $0x24, %r12
jmp 0x9dc86
movq 0x20(%rsp), %rcx
incl %ecx
movq 0x18(%rsp), %rdx
movq 0x10(%rsp), %rax
jmp 0x9dc2e
incl %edx
movq 0x8(%rsp), %rax
movq 0x28(%rsp), %rcx
jmp 0x9dc08
testq %rax, %rax
je 0x9de05
xorl %ecx, %ecx
movl %ecx, %ecx
cmpq %rcx, 0x8(%rax)
jbe 0x9de05
movq (%rax), %rax
movq %rcx, 0x10(%rsp)
imulq $0x58, %rcx, %rcx
addq %rcx, %rax
addq $0x20, %rax
xorl %ecx, %ecx
movq %rax, 0x18(%rsp)
movl %ecx, %ecx
cmpq %rcx, (%rax)
jbe 0x9ddf4
movq 0x10(%rax), %rax
movq %rcx, 0x20(%rsp)
imulq $0x24, %rcx, %rcx
movl 0xc(%rax,%rcx), %esi
movl 0x10(%rax,%rcx), %ebx
imulq $0x24, %rsi, %rcx
leaq (%rax,%rcx), %rdx
subl %esi, %ebx
imulq $0x24, %rbx, %rsi
xorl %edi, %edi
cmpq %rdi, %rsi
je 0x9dd82
movq 0x20(%r14), %r8
movl (%rdx,%rdi), %r9d
andl $0x7fffffff, (%r8,%r9,8) # imm = 0x7FFFFFFF
addq $0x24, %rdi
jmp 0x9dd67
leaq (%rax,%rcx), %r15
addq $0x44, %r15
pushq $0x1
popq %r13
cmpq %rbx, %r13
jae 0x9dde3
movl -0x44(%r15), %eax
movl -0x24(%r15), %ecx
shrl $0x5, %ecx
andl $0x1, %ecx
leal (%rcx,%rax,2), %ebp
movl -0x20(%r15), %eax
movl (%r15), %ecx
shrl $0x5, %ecx
andl $0x1, %ecx
leal (%rcx,%rax,2), %r12d
movq %r14, %rdi
movl %ebp, %esi
movl %r12d, %edx
xorl %ecx, %ecx
callq 0x6db50
xorl $0x1, %r12d
xorl $0x1, %ebp
movq %r14, %rdi
movl %r12d, %esi
movl %ebp, %edx
xorl %ecx, %ecx
callq 0x6db50
incq %r13
addq $0x24, %r15
jmp 0x9dd8e
movq 0x20(%rsp), %rcx
incl %ecx
movq 0x18(%rsp), %rax
jmp 0x9dd37
movq 0x10(%rsp), %rcx
incl %ecx
movq 0x8(%rsp), %rax
jmp 0x9dd11
pushq $0x3
popq %rbx
xorl %r15d, %r15d
movl 0x14(%r14), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
cmpq %rax, %r15
jae 0x9de5d
movq 0x20(%r14), %rax
cmpl $0x0, (%rax,%r15,8)
jns 0x9de54
movq %r14, %rdi
movl %r15d, %esi
callq 0x6f8da
movq 0x30(%rsp), %rax
movq 0x10(%rax), %r12
cmpl $0x0, -0xc(%r12,%rbx,8)
je 0x9de54
andq $0x0, -0xc(%r12,%rbx,8)
movq (%r12,%rbx,8), %rdi
callq 0x2220
andq $0x0, (%r12,%rbx,8)
incq %r15
addq $0x5, %rbx
jmp 0x9de0b
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