// File: /workspace/github_cpp_makefile_star2_O2/chhylp123[P]hifiasm/Overlaps.cpp
// Function: clean_sg_by_utg(asg_t*, ma_ug_t*)
void clean_sg_by_utg(asg_t *sg, ma_ug_t *ug)
{
    uint32_t i, v, n_vx, w, k, m, nv, vx, wx;
    asg_arc_t *av = NULL;
    ma_utg_t *u = NULL; 
    
    n_vx = sg->n_seq<<1;
    for (v = 0; v < n_vx; v++)
    {
        nv = asg_arc_n(sg, v);
        av = asg_arc_a(sg, v);
        for (m = 0; m < nv; m++) av[m].del = (!!1);
    }
    
    for (i = 0; i < ug->g->n_seq; ++i) 
    {
        if(ug->g->seq[i].del) continue;
        u = &(ug->u.a[i]);
        if(ug->g->seq[i].c == ALTER_LABLE)
        {
            for (k = 0; k < u->n; k++)
            {
                asg_seq_del(sg, u->a[k]>>33);
            }
        }
        else
        {
            for (k = 0; (k + 1) < u->n; k++)
            {
                v = u->a[k]>>32; w = u->a[k+1]>>32;

                asg_arc_del(sg, v, w, 0);
                asg_arc_del(sg, w^1, v^1, 0);
            }

            v = i<<1;
            nv = asg_arc_n(ug->g, v); av = asg_arc_a(ug->g, v);
            for (k = 0; k < nv; k++)
            {
                if(av[k].del) continue;
                w = av[k].v;

                vx = (v&1?((ug->u.a[v>>1].a[0]>>32)^1):(ug->u.a[v>>1].a[ug->u.a[v>>1].n-1]>>32));
                wx = (w&1?((ug->u.a[w>>1].a[ug->u.a[w>>1].n-1]>>32)^1):(ug->u.a[w>>1].a[0]>>32));
                asg_arc_del(sg, vx, wx, 0); asg_arc_del(sg, wx^1, vx^1, 0);
            }

            v = (i<<1)+1;
            nv = asg_arc_n(ug->g, v); av = asg_arc_a(ug->g, v);
            for (k = 0; k < nv; k++)
            {
                if(av[k].del) continue;
                w = av[k].v;

                vx = (v&1?((ug->u.a[v>>1].a[0]>>32)^1):(ug->u.a[v>>1].a[ug->u.a[v>>1].n-1]>>32));
                wx = (w&1?((ug->u.a[w>>1].a[ug->u.a[w>>1].n-1]>>32)^1):(ug->u.a[w>>1].a[0]>>32));
                asg_arc_del(sg, vx, wx, 0); asg_arc_del(sg, wx^1, vx^1, 0);
            }
        }         
    }
    asg_cleanup(sg);


    /*******************************for debug************************************/
    // ma_ug_t *dbg = ma_ug_gen(sg);
    // for (i = 0; i < ug->g->n_seq; ++i) 
    // {
    //     if(ug->g->seq[i].del) continue;
    //     if(ug->g->seq[i].c == ALTER_LABLE)
    //     {
    //         asg_seq_del(ug->g, i);
    //     }
    // }
    // for (i = 0; i < dbg->g->n_seq; ++i) 
    // {
    //     dbg->g->seq[v].c = PRIMARY_LABLE;
    //     EvaluateLen(dbg->u, v) = dbg->u.a[v].n;
    // }
    // cmp_untig_graph(dbg, ug);
    /*******************************for debug************************************/
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rsi, 0x8(%rsp)
movq %rdi, %rbx
movl 0x14(%rdi), %eax
addl %eax, %eax
xorl %ecx, %ecx
cmpq %rax, %rcx
je 0xc00bb
movq 0x8(%rbx), %rsi
movq 0x28(%rbx), %rdx
movq (%rdx,%rcx,8), %rdx
movl %edx, %edi
movq %rdx, %r8
shrq $0x20, %r8
imulq $0x18, %rdi, %rdx
imulq $0x18, %r8, %rdi
addq %rdi, %rsi
addq $0xc, %rsi
xorl %edi, %edi
cmpq %rdi, %rdx
je 0xc00b6
orb $-0x80, 0x3(%rsi,%rdi)
addq $0x18, %rdi
jmp 0xc00a6
incq %rcx
jmp 0xc007b
xorl %edx, %edx
movq 0x8(%rsp), %rax
movq 0x18(%rax), %rax
movl 0x14(%rax), %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
cmpq %rcx, %rdx
jae 0xc0308
movq 0x20(%rax), %rax
movq %rdx, 0x10(%rsp)
cmpl $0x0, (%rax,%rdx,8)
js 0xc02fb
movq 0x10(%rsp), %r13
imulq $0x28, %r13, %rdx
movq 0x8(%rsp), %rcx
movq 0x10(%rcx), %r14
movq %rdx, 0x18(%rsp)
addq %rdx, %r14
cmpb $0x1, 0x4(%rax,%r13,8)
jne 0xc0136
xorl %r15d, %r15d
movl 0x10(%r14), %eax
cmpq %rax, %r15
jae 0xc02fb
movq 0x18(%r14), %rax
movq (%rax,%r15,8), %rsi
shrq $0x21, %rsi
movq %rbx, %rdi
callq 0x6f8da
incq %r15
jmp 0xc0110
pushq $0x1
popq %r12
movl 0x10(%r14), %eax
cmpq %rax, %r12
jae 0xc017b
movq 0x18(%r14), %rax
movl -0x4(%rax,%r12,8), %ebp
movl 0x4(%rax,%r12,8), %r15d
movq %rbx, %rdi
movl %ebp, %esi
movl %r15d, %edx
xorl %ecx, %ecx
callq 0x6db50
xorl $0x1, %r15d
xorl $0x1, %ebp
movq %rbx, %rdi
movl %r15d, %esi
movl %ebp, %edx
xorl %ecx, %ecx
callq 0x6db50
incq %r12
jmp 0xc013a
leaq (,%r13,2), %rax
movq %rax, 0x20(%rsp)
movq 0x8(%rsp), %rax
movq 0x18(%rax), %rax
movq 0x8(%rax), %rcx
movq 0x28(%rax), %rax
movq %r13, %rdx
shlq $0x4, %rdx
movq (%rax,%rdx), %rax
movl %eax, %edx
shrq $0x20, %rax
imulq $0x18, %rdx, %r12
imulq $0x18, %rax, %rax
leaq (%rcx,%rax), %r14
addq $0xc, %r14
xorl %r13d, %r13d
cmpq %r13, %r12
je 0xc0249
cmpl $0x0, (%r14,%r13)
js 0xc0240
movl -0x4(%r14,%r13), %edx
movq 0x8(%rsp), %rax
movq 0x10(%rax), %rax
movl %edx, %ecx
shrl %ecx
imulq $0x28, %rcx, %rcx
testb $0x1, %dl
jne 0xc01f3
movq 0x18(%rax,%rcx), %rcx
movl 0x4(%rcx), %r15d
jmp 0xc0207
movq 0x18(%rax,%rcx), %rdx
movl 0x10(%rax,%rcx), %ecx
decl %ecx
movl 0x4(%rdx,%rcx,8), %r15d
xorq $0x1, %r15
movq 0x18(%rsp), %rdx
movq 0x18(%rax,%rdx), %rcx
movl 0x10(%rax,%rdx), %eax
decl %eax
movl 0x4(%rcx,%rax,8), %ebp
movq %rbx, %rdi
movl %ebp, %esi
movl %r15d, %edx
xorl %ecx, %ecx
callq 0x6db50
xorl $0x1, %r15d
xorl $0x1, %ebp
movq %rbx, %rdi
movl %r15d, %esi
movl %ebp, %edx
xorl %ecx, %ecx
callq 0x6db50
addq $0x18, %r13
jmp 0xc01bd
movq 0x8(%rsp), %rax
movq 0x18(%rax), %rax
movq 0x8(%rax), %rcx
movq 0x28(%rax), %rax
movq 0x20(%rsp), %rdx
movq 0x8(%rax,%rdx,8), %rax
movl %eax, %edx
shrq $0x20, %rax
imulq $0x18, %rdx, %r14
imulq $0x18, %rax, %rax
leaq (%rcx,%rax), %r12
addq $0xc, %r12
xorl %r13d, %r13d
cmpq %r13, %r14
je 0xc02fb
cmpl $0x0, (%r12,%r13)
js 0xc02f5
movl -0x4(%r12,%r13), %edx
movq 0x8(%rsp), %rax
movq 0x10(%rax), %rax
movl %edx, %ecx
shrl %ecx
imulq $0x28, %rcx, %rcx
testb $0x1, %dl
jne 0xc02af
movq 0x18(%rax,%rcx), %rcx
movl 0x4(%rcx), %r15d
jmp 0xc02c3
movq 0x18(%rax,%rcx), %rdx
movl 0x10(%rax,%rcx), %ecx
decl %ecx
movl 0x4(%rdx,%rcx,8), %r15d
xorq $0x1, %r15
movq 0x18(%rsp), %rcx
movq 0x18(%rax,%rcx), %rax
movl 0x4(%rax), %ebp
movl %ebp, %esi
xorl $0x1, %esi
movq %rbx, %rdi
movl %r15d, %edx
xorl %ecx, %ecx
callq 0x6db50
xorl $0x1, %r15d
movq %rbx, %rdi
movl %r15d, %esi
movl %ebp, %edx
xorl %ecx, %ecx
callq 0x6db50
addq $0x18, %r13
jmp 0xc027d
movq 0x10(%rsp), %rdx
incq %rdx
jmp 0xc00bd
movq %rbx, %rdi
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x694eb