// File: /workspace/github_cpp_makefile_star2_O1/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
movq %rsi, -0x8(%rsp)
movl 0x14(%rdi), %eax
addl %eax, %eax
je 0xfeb4b
movl %eax, %eax
xorl %ecx, %ecx
movq 0x28(%rdi), %rdx
movq (%rdx,%rcx,8), %rdx
testl %edx, %edx
je 0xfeb43
movq 0x8(%rdi), %r8
movq %rdx, %r9
shrq $0x20, %r9
movl %edx, %r10d
leaq (%r9,%r9,2), %rdx
leaq (%r8,%rdx,8), %rdx
addq $0xc, %rdx
shlq $0x3, %r10
leaq (%r10,%r10,2), %r8
xorl %r9d, %r9d
orb $-0x80, 0x3(%rdx,%r9)
addq $0x18, %r9
cmpq %r9, %r8
jne 0xfeb34
incq %rcx
cmpq %rax, %rcx
jne 0xfeb03
movq -0x8(%rsp), %rax
movq 0x18(%rax), %rdx
testl $0x7fffffff, 0x14(%rdx) # imm = 0x7FFFFFFF
je 0xfefca
xorl %esi, %esi
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
movq 0x20(%rdx), %r9
cmpl $0x0, (%r9,%rsi,8)
js 0xfefad
movq -0x8(%rsp), %rax
movq 0x10(%rax), %r8
leaq (%rsi,%rsi,4), %rdx
leaq (%r8,%rdx,8), %r8
cmpb $0x1, 0x4(%r9,%rsi,8)
movl 0x10(%r8), %r9d
jne 0xfec77
testl %r9d, %r9d
je 0xfefad
xorl %edx, %edx
movq 0x18(%r8), %r9
movq (%r9,%rdx,8), %r9
shrq $0x21, %r9
movq 0x20(%rdi), %r10
orl $0x80000000, (%r10,%r9,8) # imm = 0x80000000
addl %r9d, %r9d
xorl %r10d, %r10d
leaq (%r10,%r9), %r11
movq 0x28(%rdi), %rbx
movq (%rbx,%r11,8), %r14
movq %r14, %rbx
andq %rcx, %rbx
je 0xfec52
shrq $0x20, %r14
leaq (%r14,%r14,2), %r14
shlq $0x3, %r14
addq 0x8(%rdi), %r14
xorl %r15d, %r15d
leaq (%r15,%r15,2), %r12
orb $-0x80, 0xf(%r14,%r12,8)
movl 0x8(%r14,%r12,8), %r12d
xorq $0x1, %r12
movq 0x28(%rdi), %r13
movq (%r13,%r12,8), %r13
movq %r13, %r12
andq %rcx, %r12
je 0xfec4a
movq 0x8(%rdi), %rbp
shrq $0x20, %r13
shlq $0x3, %r12
leaq (%r12,%r12,2), %r12
leaq (%r13,%r13,2), %r13
leaq 0xc(,%r13,8), %r13
addq %rbp, %r13
xorl %ebp, %ebp
movl -0x4(%r13,%rbp), %eax
xorl %r11d, %eax
cmpl $0x1, %eax
jne 0xfec41
orb $-0x80, 0x3(%r13,%rbp)
addq $0x18, %rbp
cmpq %rbp, %r12
jne 0xfec2e
incq %r15
cmpq %rbx, %r15
jne 0xfebe8
leaq 0x1(%r10), %rax
testq %r10, %r10
movq %rax, %r10
je 0xfebc1
incq %rdx
movl 0x10(%r8), %eax
cmpq %rax, %rdx
jb 0xfeba3
jmp 0xfefad
cmpl $0x2, %r9d
jb 0xfed45
movl $0x1, %r9d
xorl %r10d, %r10d
movq 0x18(%r8), %rax
movq (%rax,%r10,8), %r11
shrq $0x20, %r11
movq (%rax,%r9,8), %rbx
shrq $0x20, %rbx
movq 0x28(%rdi), %rax
movq (%rax,%r11,8), %r15
movq %r15, %r14
andq %rcx, %r14
je 0xfece3
movq 0x8(%rdi), %rax
shrq $0x20, %r15
shlq $0x3, %r14
leaq (%r14,%r14,2), %r14
leaq (%r15,%r15,2), %r15
leaq (%rax,%r15,8), %r15
addq $0xc, %r15
xorl %r12d, %r12d
cmpl %ebx, -0x4(%r15,%r12)
jne 0xfecda
andb $0x7f, 0x3(%r15,%r12)
addq $0x18, %r12
cmpq %r12, %r14
jne 0xfeccd
xorq $0x1, %rbx
movq 0x28(%rdi), %rax
movq (%rax,%rbx,8), %r14
movq %r14, %rbx
andq %rcx, %rbx
je 0xfed32
movq 0x8(%rdi), %rax
shrq $0x20, %r14
shlq $0x3, %rbx
leaq (%rbx,%rbx,2), %rbx
leaq (%r14,%r14,2), %r14
leaq (%rax,%r14,8), %r14
addq $0xc, %r14
xorl %r15d, %r15d
movl -0x4(%r14,%r15), %eax
xorl %r11d, %eax
cmpl $0x1, %eax
jne 0xfed29
andb $0x7f, 0x3(%r14,%r15)
addq $0x18, %r15
cmpq %r15, %rbx
jne 0xfed16
incq %r9
movl 0x10(%r8), %eax
incq %r10
cmpq %rax, %r9
jb 0xfec8a
movq -0x8(%rsp), %rax
movq 0x18(%rax), %r9
movq 0x28(%r9), %rax
movq %rsi, %r8
shlq $0x4, %r8
movq (%rax,%r8), %r10
testl %r10d, %r10d
je 0xfee7e
movq %r10, %rax
shrq $0x20, %rax
leaq (%rax,%rax,2), %r8
shlq $0x3, %r8
addq 0x8(%r9), %r8
movl %r10d, %r9d
xorl %r10d, %r10d
leaq (%r10,%r10,2), %r11
cmpl $0x0, 0xc(%r8,%r11,8)
js 0xfee72
leaq (%r8,%r11,8), %rax
movl 0x8(%rax), %eax
movq -0x8(%rsp), %r11
movq 0x10(%r11), %r11
movl %eax, %ebx
shrl %ebx
leaq (%rbx,%rbx,4), %rbx
testb $0x1, %al
jne 0xfedb5
movq 0x18(%r11,%rbx,8), %rax
movl 0x4(%rax), %ebx
jmp 0xfedc9
movq 0x18(%r11,%rbx,8), %rax
movl 0x10(%r11,%rbx,8), %ebx
decl %ebx
movl 0x4(%rax,%rbx,8), %ebx
xorq $0x1, %rbx
movq 0x18(%r11,%rdx,8), %rax
movl 0x10(%r11,%rdx,8), %r11d
decl %r11d
movq (%rax,%r11,8), %r11
shrq $0x20, %r11
movq 0x28(%rdi), %rax
movq (%rax,%r11,8), %r15
movq %r15, %r14
andq %rcx, %r14
je 0xfee23
movq 0x8(%rdi), %rax
shrq $0x20, %r15
shlq $0x3, %r14
leaq (%r14,%r14,2), %r14
leaq (%r15,%r15,2), %r15
leaq (%rax,%r15,8), %r15
addq $0xc, %r15
xorl %r12d, %r12d
cmpl %ebx, -0x4(%r15,%r12)
jne 0xfee1a
andb $0x7f, 0x3(%r15,%r12)
addq $0x18, %r12
cmpq %r12, %r14
jne 0xfee0d
movq 0x28(%rdi), %rax
xorq $0x1, %rbx
movq (%rax,%rbx,8), %r14
movq %r14, %rbx
andq %rcx, %rbx
je 0xfee72
movq 0x8(%rdi), %rax
shrq $0x20, %r14
shlq $0x3, %rbx
leaq (%rbx,%rbx,2), %rbx
leaq (%r14,%r14,2), %r14
leaq (%rax,%r14,8), %r14
addq $0xc, %r14
xorl %r15d, %r15d
movl -0x4(%r14,%r15), %eax
xorl %r11d, %eax
cmpl $0x1, %eax
jne 0xfee69
andb $0x7f, 0x3(%r14,%r15)
addq $0x18, %r15
cmpq %r15, %rbx
jne 0xfee56
incq %r10
cmpq %r9, %r10
jne 0xfed7f
leaq (%rsi,%rsi), %rax
movq -0x8(%rsp), %r8
movq 0x18(%r8), %r10
movq 0x28(%r10), %r8
movq 0x8(%r8,%rax,8), %r9
testl %r9d, %r9d
je 0xfefad
movq %r9, %rax
shrq $0x20, %rax
leaq (%rax,%rax,2), %r8
shlq $0x3, %r8
addq 0x8(%r10), %r8
movl %r9d, %r9d
xorl %r10d, %r10d
leaq (%r10,%r10,2), %r11
cmpl $0x0, 0xc(%r8,%r11,8)
js 0xfefa1
leaq (%r8,%r11,8), %rax
movl 0x8(%rax), %eax
movq -0x8(%rsp), %r11
movq 0x10(%r11), %r11
movl %eax, %ebx
shrl %ebx
leaq (%rbx,%rbx,4), %rbx
testb $0x1, %al
jne 0xfeeec
movq 0x18(%r11,%rbx,8), %rax
movl 0x4(%rax), %ebx
jmp 0xfef00
movq 0x18(%r11,%rbx,8), %rax
movl 0x10(%r11,%rbx,8), %ebx
decl %ebx
movl 0x4(%rax,%rbx,8), %ebx
xorq $0x1, %rbx
movq 0x18(%r11,%rdx,8), %rax
movq (%rax), %r11
shrq $0x20, %r11
movq %r11, %rax
xorq $0x1, %rax
movq 0x28(%rdi), %r14
movq (%r14,%rax,8), %r15
movq %r15, %r14
andq %rcx, %r14
je 0xfef58
movq 0x8(%rdi), %rax
shrq $0x20, %r15
shlq $0x3, %r14
leaq (%r14,%r14,2), %r14
leaq (%r15,%r15,2), %r15
leaq (%rax,%r15,8), %r15
addq $0xc, %r15
xorl %r12d, %r12d
cmpl %ebx, -0x4(%r15,%r12)
jne 0xfef4f
andb $0x7f, 0x3(%r15,%r12)
addq $0x18, %r12
cmpq %r12, %r14
jne 0xfef42
movq 0x28(%rdi), %rax
xorq $0x1, %rbx
movq (%rax,%rbx,8), %r14
movq %r14, %rbx
andq %rcx, %rbx
je 0xfefa1
movq 0x8(%rdi), %rax
shrq $0x20, %r14
shlq $0x3, %rbx
leaq (%rbx,%rbx,2), %rbx
leaq (%r14,%r14,2), %r14
leaq (%rax,%r14,8), %r14
addq $0xc, %r14
xorl %r15d, %r15d
cmpl %r11d, -0x4(%r14,%r15)
jne 0xfef98
andb $0x7f, 0x3(%r14,%r15)
addq $0x18, %r15
cmpq %r15, %rbx
jne 0xfef8b
incq %r10
cmpq %r9, %r10
jne 0xfeeb6
incq %rsi
movq -0x8(%rsp), %rax
movq 0x18(%rax), %rdx
movl 0x14(%rdx), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
cmpq %rax, %rsi
jb 0xfeb68
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xa02fa