// File: 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
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq -0x8(%rbp), %rdi
callq 0x10ba70
movq %rax, -0x20(%rbp)
movq $0x0, -0x40(%rbp)
cmpq $0x0, -0x10(%rbp)
jne 0x126e2b
cmpq $0x0, -0x18(%rbp)
je 0x127278
movl $0x0, -0x24(%rbp)
movl -0x24(%rbp), %eax
movq -0x20(%rbp), %rcx
movq 0x18(%rcx), %rcx
movl 0x14(%rcx), %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
cmpl %ecx, %eax
jae 0x126e76
movq -0x20(%rbp), %rax
movq 0x18(%rax), %rax
movq 0x20(%rax), %rax
movl -0x24(%rbp), %ecx
movl (%rax,%rcx,8), %edx
andl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
orl $0x80000000, %edx       # imm = 0x80000000
movl %edx, (%rax,%rcx,8)
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x126e32
movl $0x0, -0x24(%rbp)
movl -0x24(%rbp), %eax
movq -0x20(%rbp), %rcx
movq 0x18(%rcx), %rcx
movl 0x4(%rcx), %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
cmpl %ecx, %eax
jae 0x126ec8
movq -0x20(%rbp), %rax
movq 0x18(%rax), %rax
movq 0x8(%rax), %rax
movl -0x24(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl 0xc(%rax), %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
orl $0x80000000, %ecx       # imm = 0x80000000
movl %ecx, 0xc(%rax)
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x126e7d
movq -0x10(%rbp), %rax
movq %rax, -0x40(%rbp)
cmpq $0x0, -0x40(%rbp)
je 0x12709f
movl $0x0, -0x24(%rbp)
movl -0x24(%rbp), %eax
movq -0x40(%rbp), %rcx
cmpq 0x8(%rcx), %rax
jae 0x12709d
movq -0x40(%rbp), %rax
movq (%rax), %rax
movl -0x24(%rbp), %ecx
imulq $0x58, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x48(%rbp)
movl $0x0, -0x28(%rbp)
movl -0x28(%rbp), %eax
movq -0x48(%rbp), %rcx
cmpq 0x20(%rcx), %rax
jae 0x12708d
movq -0x48(%rbp), %rax
movq 0x30(%rax), %rax
movq -0x48(%rbp), %rcx
movq 0x30(%rcx), %rcx
movl -0x28(%rbp), %edx
imulq $0x24, %rdx, %rdx
addq %rdx, %rcx
movl 0xc(%rcx), %ecx
imulq $0x24, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x50(%rbp)
movq -0x48(%rbp), %rax
movq 0x30(%rax), %rax
movl -0x28(%rbp), %ecx
imulq $0x24, %rcx, %rcx
addq %rcx, %rax
movl 0x10(%rax), %eax
movq -0x48(%rbp), %rcx
movq 0x30(%rcx), %rcx
movl -0x28(%rbp), %edx
imulq $0x24, %rdx, %rdx
addq %rdx, %rcx
subl 0xc(%rcx), %eax
movl %eax, -0x2c(%rbp)
movl $0x0, -0x30(%rbp)
movl -0x30(%rbp), %eax
cmpl -0x2c(%rbp), %eax
jae 0x126fba
movq -0x20(%rbp), %rax
movq 0x18(%rax), %rax
movq 0x20(%rax), %rax
movq -0x50(%rbp), %rcx
movl -0x30(%rbp), %edx
imulq $0x24, %rdx, %rdx
addq %rdx, %rcx
movl (%rcx), %ecx
movl (%rax,%rcx,8), %edx
andl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
orl $0x0, %edx
movl %edx, (%rax,%rcx,8)
movl -0x30(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rbp)
jmp 0x126f7c
movl $0x1, -0x30(%rbp)
movl -0x30(%rbp), %eax
cmpl -0x2c(%rbp), %eax
jae 0x12707d
movq -0x50(%rbp), %rax
movl -0x30(%rbp), %ecx
subl $0x1, %ecx
movl %ecx, %ecx
imulq $0x24, %rcx, %rcx
addq %rcx, %rax
movl (%rax), %eax
shll %eax
movl %eax, -0x34(%rbp)
movq -0x50(%rbp), %rax
movl -0x30(%rbp), %ecx
subl $0x1, %ecx
movl %ecx, %ecx
imulq $0x24, %rcx, %rcx
addq %rcx, %rax
movb 0x20(%rax), %al
shrb $0x5, %al
andb $0x1, %al
movzbl %al, %eax
orl -0x34(%rbp), %eax
movl %eax, -0x34(%rbp)
movq -0x50(%rbp), %rax
movl -0x30(%rbp), %ecx
imulq $0x24, %rcx, %rcx
addq %rcx, %rax
movl (%rax), %eax
shll %eax
movl %eax, -0x38(%rbp)
movq -0x50(%rbp), %rax
movl -0x30(%rbp), %ecx
imulq $0x24, %rcx, %rcx
addq %rcx, %rax
movb 0x20(%rax), %al
shrb $0x5, %al
andb $0x1, %al
movzbl %al, %eax
orl -0x38(%rbp), %eax
movl %eax, -0x38(%rbp)
movq -0x20(%rbp), %rax
movq 0x18(%rax), %rdi
movl -0x34(%rbp), %esi
movl -0x38(%rbp), %edx
xorl %ecx, %ecx
callq 0xd6530
movq -0x20(%rbp), %rax
movq 0x18(%rax), %rdi
movl -0x38(%rbp), %esi
xorl $0x1, %esi
movl -0x34(%rbp), %edx
xorl $0x1, %edx
xorl %ecx, %ecx
callq 0xd6530
movl -0x30(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rbp)
jmp 0x126fc1
jmp 0x12707f
movl -0x28(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x28(%rbp)
jmp 0x126f0f
jmp 0x12708f
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x126ee2
jmp 0x12709f
movq -0x18(%rbp), %rax
movq %rax, -0x40(%rbp)
cmpq $0x0, -0x40(%rbp)
je 0x127276
movl $0x0, -0x24(%rbp)
movl -0x24(%rbp), %eax
movq -0x40(%rbp), %rcx
cmpq 0x8(%rcx), %rax
jae 0x127274
movq -0x40(%rbp), %rax
movq (%rax), %rax
movl -0x24(%rbp), %ecx
imulq $0x58, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x48(%rbp)
movl $0x0, -0x28(%rbp)
movl -0x28(%rbp), %eax
movq -0x48(%rbp), %rcx
cmpq 0x20(%rcx), %rax
jae 0x127264
movq -0x48(%rbp), %rax
movq 0x30(%rax), %rax
movq -0x48(%rbp), %rcx
movq 0x30(%rcx), %rcx
movl -0x28(%rbp), %edx
imulq $0x24, %rdx, %rdx
addq %rdx, %rcx
movl 0xc(%rcx), %ecx
imulq $0x24, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x50(%rbp)
movq -0x48(%rbp), %rax
movq 0x30(%rax), %rax
movl -0x28(%rbp), %ecx
imulq $0x24, %rcx, %rcx
addq %rcx, %rax
movl 0x10(%rax), %eax
movq -0x48(%rbp), %rcx
movq 0x30(%rcx), %rcx
movl -0x28(%rbp), %edx
imulq $0x24, %rdx, %rdx
addq %rdx, %rcx
subl 0xc(%rcx), %eax
movl %eax, -0x2c(%rbp)
movl $0x0, -0x30(%rbp)
movl -0x30(%rbp), %eax
cmpl -0x2c(%rbp), %eax
jae 0x127191
movq -0x20(%rbp), %rax
movq 0x18(%rax), %rax
movq 0x20(%rax), %rax
movq -0x50(%rbp), %rcx
movl -0x30(%rbp), %edx
imulq $0x24, %rdx, %rdx
addq %rdx, %rcx
movl (%rcx), %ecx
movl (%rax,%rcx,8), %edx
andl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
orl $0x0, %edx
movl %edx, (%rax,%rcx,8)
movl -0x30(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rbp)
jmp 0x127153
movl $0x1, -0x30(%rbp)
movl -0x30(%rbp), %eax
cmpl -0x2c(%rbp), %eax
jae 0x127254
movq -0x50(%rbp), %rax
movl -0x30(%rbp), %ecx
subl $0x1, %ecx
movl %ecx, %ecx
imulq $0x24, %rcx, %rcx
addq %rcx, %rax
movl (%rax), %eax
shll %eax
movl %eax, -0x34(%rbp)
movq -0x50(%rbp), %rax
movl -0x30(%rbp), %ecx
subl $0x1, %ecx
movl %ecx, %ecx
imulq $0x24, %rcx, %rcx
addq %rcx, %rax
movb 0x20(%rax), %al
shrb $0x5, %al
andb $0x1, %al
movzbl %al, %eax
orl -0x34(%rbp), %eax
movl %eax, -0x34(%rbp)
movq -0x50(%rbp), %rax
movl -0x30(%rbp), %ecx
imulq $0x24, %rcx, %rcx
addq %rcx, %rax
movl (%rax), %eax
shll %eax
movl %eax, -0x38(%rbp)
movq -0x50(%rbp), %rax
movl -0x30(%rbp), %ecx
imulq $0x24, %rcx, %rcx
addq %rcx, %rax
movb 0x20(%rax), %al
shrb $0x5, %al
andb $0x1, %al
movzbl %al, %eax
orl -0x38(%rbp), %eax
movl %eax, -0x38(%rbp)
movq -0x20(%rbp), %rax
movq 0x18(%rax), %rdi
movl -0x34(%rbp), %esi
movl -0x38(%rbp), %edx
xorl %ecx, %ecx
callq 0xd6530
movq -0x20(%rbp), %rax
movq 0x18(%rax), %rdi
movl -0x38(%rbp), %esi
xorl $0x1, %esi
movl -0x34(%rbp), %edx
xorl $0x1, %edx
xorl %ecx, %ecx
callq 0xd6530
movl -0x30(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rbp)
jmp 0x127198
jmp 0x127256
movl -0x28(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x28(%rbp)
jmp 0x1270e6
jmp 0x127266
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x1270b9
jmp 0x127276
jmp 0x127278
movl $0x0, -0x24(%rbp)
movl -0x24(%rbp), %eax
movq -0x20(%rbp), %rcx
movq 0x18(%rcx), %rcx
movl 0x14(%rcx), %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
cmpl %ecx, %eax
jae 0x12735a
movq -0x20(%rbp), %rax
movq 0x18(%rax), %rax
movq 0x20(%rax), %rax
movl -0x24(%rbp), %ecx
movl (%rax,%rcx,8), %eax
shrl $0x1f, %eax
cmpl $0x1, %eax
jne 0x12734a
movq -0x20(%rbp), %rax
movq 0x18(%rax), %rdi
movl -0x24(%rbp), %esi
callq 0xd9510
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x24(%rbp), %ecx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
cmpl $0x0, 0xc(%rax)
je 0x127348
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x24(%rbp), %ecx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movl $0x0, 0x10(%rax)
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x24(%rbp), %ecx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movl $0x0, 0xc(%rax)
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x24(%rbp), %ecx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movq 0x18(%rax), %rdi
callq 0x2210
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x24(%rbp), %ecx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movq $0x0, 0x18(%rax)
jmp 0x12734a
jmp 0x12734c
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x12727f
movq -0x20(%rbp), %rax
movq 0x18(%rax), %rdi
callq 0xcdd10
movq -0x20(%rbp), %rax
addq $0x50, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)