// File: /workspace/github_cpp_makefile_star2_O3/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 0x102ea3
movl %eax, %eax
xorl %ecx, %ecx
movq 0x28(%rdi), %rdx
movq (%rdx,%rcx,8), %rdx
testl %edx, %edx
je 0x102e9b
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 0x102e8c
incq %rcx
cmpq %rax, %rcx
jne 0x102e5b
movq -0x8(%rsp), %rax
movq 0x18(%rax), %r9
testl $0x7fffffff, 0x14(%r9)  # imm = 0x7FFFFFFF
je 0x103341
xorl %esi, %esi
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
movq 0x20(%r9), %r10
cmpl $0x0, (%r10,%rsi,8)
js 0x103323
movq -0x8(%rsp), %rax
movq 0x10(%rax), %r8
leaq (%rsi,%rsi,4), %rdx
leaq (%r8,%rdx,8), %r8
cmpb $0x1, 0x4(%r10,%rsi,8)
movl 0x10(%r8), %r10d
jne 0x102fd8
testl %r10d, %r10d
je 0x103323
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
movb $0x1, %r10b
xorl %r11d, %r11d
orq %r9, %r11
movq 0x28(%rdi), %rbx
movq (%rbx,%r11,8), %r14
movq %r14, %rbx
andq %rcx, %rbx
je 0x102fad
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 0x102fa5
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 0x102f9c
orb $-0x80, 0x3(%r13,%rbp)
addq $0x18, %rbp
cmpq %rbp, %r12
jne 0x102f89
incq %r15
cmpq %rbx, %r15
jne 0x102f43
movl $0x1, %r11d
testb $0x1, %r10b
movl $0x0, %r10d
jne 0x102f1d
incq %rdx
movl 0x10(%r8), %eax
cmpq %rax, %rdx
jb 0x102efc
jmp 0x103323
cmpl $0x2, %r10d
jb 0x1030b6
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 0x8(%rdi), %r14
movq 0x28(%rdi), %r15
movq (%r15,%r11,8), %r12
movq %r12, %r13
andq %rcx, %r13
je 0x103053
shrq $0x20, %r12
shlq $0x3, %r13
leaq (,%r13,2), %r15
addq %r13, %r15
leaq (%r12,%r12,2), %rax
leaq (%r14,%rax,8), %r14
addq $0xc, %r14
xorl %r12d, %r12d
cmpl %ebx, -0x4(%r14,%r12)
jne 0x103042
andb $0x7f, 0x3(%r14,%r12)
addq $0x18, %r12
cmpq %r12, %r15
jne 0x103035
movq 0x8(%rdi), %r14
movq 0x28(%rdi), %r15
xorq $0x1, %rbx
movq (%r15,%rbx,8), %r15
movq %r15, %rbx
andq %rcx, %rbx
je 0x10309a
shrq $0x20, %r15
shlq $0x3, %rbx
leaq (%rbx,%rbx,2), %rbx
leaq (%r15,%r15,2), %rax
leaq (%r14,%rax,8), %r14
addq $0xc, %r14
xorl %r15d, %r15d
movl -0x4(%r14,%r15), %eax
xorl %r11d, %eax
cmpl $0x1, %eax
jne 0x103091
andb $0x7f, 0x3(%r14,%r15)
addq $0x18, %r15
cmpq %r15, %rbx
jne 0x10307e
incq %r9
movl 0x10(%r8), %eax
incq %r10
cmpq %rax, %r9
jb 0x102feb
movq -0x8(%rsp), %rax
movq 0x18(%rax), %r9
movq 0x8(%r9), %r8
movq 0x28(%r9), %r9
movq %rsi, %rax
shlq $0x4, %rax
movq (%r9,%rax), %r10
testl %r10d, %r10d
je 0x1031fe
movq %r10, %rax
shrq $0x20, %rax
leaq (%rax,%rax,2), %rax
leaq (%r8,%rax,8), %r8
movl %r10d, %r9d
xorl %r10d, %r10d
leaq (%r10,%r10,2), %r11
cmpl $0x0, 0xc(%r8,%r11,8)
js 0x1031e1
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 0x10311d
movq 0x18(%r11,%rbx,8), %rax
movl 0x4(%rax), %ebx
jmp 0x103131
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 0x8(%rdi), %r14
movq 0x28(%rdi), %r15
movq (%r15,%r11,8), %r12
movq %r12, %r13
andq %rcx, %r13
je 0x10319a
shrq $0x20, %r12
shlq $0x3, %r13
leaq (,%r13,2), %r15
addq %r13, %r15
leaq (%r12,%r12,2), %rax
leaq (%r14,%rax,8), %r14
addq $0xc, %r14
xorl %r12d, %r12d
cmpl %ebx, -0x4(%r14,%r12)
jne 0x103189
andb $0x7f, 0x3(%r14,%r12)
addq $0x18, %r12
cmpq %r12, %r15
jne 0x10317c
movq 0x8(%rdi), %r14
movq 0x28(%rdi), %r15
xorq $0x1, %rbx
movq (%r15,%rbx,8), %r15
movq %r15, %rbx
andq %rcx, %rbx
je 0x1031e1
shrq $0x20, %r15
shlq $0x3, %rbx
leaq (%rbx,%rbx,2), %rbx
leaq (%r15,%r15,2), %rax
leaq (%r14,%rax,8), %r14
addq $0xc, %r14
xorl %r15d, %r15d
movl -0x4(%r14,%r15), %eax
xorl %r11d, %eax
cmpl $0x1, %eax
jne 0x1031d8
andb $0x7f, 0x3(%r14,%r15)
addq $0x18, %r15
cmpq %r15, %rbx
jne 0x1031c5
incq %r10
cmpq %r9, %r10
jne 0x1030e7
movq -0x8(%rsp), %rax
movq 0x18(%rax), %rax
movq 0x8(%rax), %r8
movq 0x28(%rax), %r9
leaq (%rsi,%rsi), %rax
movq 0x8(%r9,%rax,8), %r9
testl %r9d, %r9d
je 0x103323
movq %r9, %rax
shrq $0x20, %rax
leaq (%rax,%rax,2), %rax
leaq (%r8,%rax,8), %r8
movl %r9d, %r9d
xorl %r10d, %r10d
leaq (%r10,%r10,2), %r11
cmpl $0x0, 0xc(%r8,%r11,8)
js 0x103317
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 0x10325b
movq 0x18(%r11,%rbx,8), %rax
movl 0x4(%rax), %ebx
jmp 0x10326f
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 0x8(%rdi), %r14
movq 0x28(%rdi), %r15
movq (%r15,%rax,8), %r12
movq %r12, %r13
andq %rcx, %r13
je 0x1032d6
shrq $0x20, %r12
shlq $0x3, %r13
leaq (,%r13,2), %r15
addq %r13, %r15
leaq (%r12,%r12,2), %rax
leaq (%r14,%rax,8), %r14
addq $0xc, %r14
xorl %r12d, %r12d
cmpl %ebx, -0x4(%r14,%r12)
jne 0x1032c5
andb $0x7f, 0x3(%r14,%r12)
addq $0x18, %r12
cmpq %r12, %r15
jne 0x1032b8
movq 0x8(%rdi), %r14
movq 0x28(%rdi), %r15
xorq $0x1, %rbx
movq (%r15,%rbx,8), %r15
movq %r15, %rbx
andq %rcx, %rbx
je 0x103317
shrq $0x20, %r15
shlq $0x3, %rbx
leaq (%rbx,%rbx,2), %rbx
leaq (%r15,%r15,2), %rax
leaq (%r14,%rax,8), %r14
addq $0xc, %r14
xorl %r15d, %r15d
cmpl %r11d, -0x4(%r14,%r15)
jne 0x10330e
andb $0x7f, 0x3(%r14,%r15)
addq $0x18, %r15
cmpq %r15, %rbx
jne 0x103301
incq %r10
cmpq %r9, %r10
jne 0x103225
incq %rsi
movq -0x8(%rsp), %rax
movq 0x18(%rax), %r9
movl 0x14(%r9), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
cmpq %rax, %rsi
jb 0x102ec1
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xa0a7d