// File: 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
movq %rsp, %rbp
subq $0x70, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq $0x0, -0x40(%rbp)
movq $0x0, -0x48(%rbp)
movq -0x8(%rbp), %rax
movl 0x14(%rax), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
shll %eax
movl %eax, -0x1c(%rbp)
movl $0x0, -0x18(%rbp)
movl -0x18(%rbp), %eax
cmpl -0x1c(%rbp), %eax
jae 0x162316
movq -0x8(%rbp), %rax
movq 0x28(%rax), %rax
movl -0x18(%rbp), %ecx
movq (%rax,%rcx,8), %rax
movl %eax, -0x2c(%rbp)
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x8(%rbp), %rcx
movq 0x28(%rcx), %rcx
movl -0x18(%rbp), %edx
movq (%rcx,%rdx,8), %rcx
shrq $0x20, %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x40(%rbp)
movl $0x0, -0x28(%rbp)
movl -0x28(%rbp), %eax
cmpl -0x2c(%rbp), %eax
jae 0x162306
movq -0x40(%rbp), %rax
movl -0x28(%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 -0x28(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x28(%rbp)
jmp 0x1622d3
jmp 0x162308
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
jmp 0x162288
movl $0x0, -0x14(%rbp)
movl -0x14(%rbp), %eax
movq -0x10(%rbp), %rcx
movq 0x18(%rcx), %rcx
movl 0x14(%rcx), %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
cmpl %ecx, %eax
jae 0x1627e9
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
movq 0x20(%rax), %rax
movl -0x14(%rbp), %ecx
movl (%rax,%rcx,8), %eax
shrl $0x1f, %eax
cmpl $0x0, %eax
je 0x162358
jmp 0x1627db
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x14(%rbp), %ecx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x48(%rbp)
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
movq 0x20(%rax), %rax
movl -0x14(%rbp), %ecx
movzbl 0x4(%rax,%rcx,8), %eax
cmpl $0x1, %eax
jne 0x1623c8
movl $0x0, -0x24(%rbp)
movl -0x24(%rbp), %eax
movq -0x48(%rbp), %rcx
cmpl 0x10(%rcx), %eax
jae 0x1623c3
movq -0x8(%rbp), %rdi
movq -0x48(%rbp), %rax
movq 0x18(%rax), %rax
movl -0x24(%rbp), %ecx
movq (%rax,%rcx,8), %rax
shrq $0x21, %rax
movl %eax, %esi
callq 0xd9510
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x16238e
jmp 0x1627d9
movl $0x0, -0x24(%rbp)
movl -0x24(%rbp), %eax
addl $0x1, %eax
movq -0x48(%rbp), %rcx
cmpl 0x10(%rcx), %eax
jae 0x162442
movq -0x48(%rbp), %rax
movq 0x18(%rax), %rax
movl -0x24(%rbp), %ecx
movq (%rax,%rcx,8), %rax
shrq $0x20, %rax
movl %eax, -0x18(%rbp)
movq -0x48(%rbp), %rax
movq 0x18(%rax), %rax
movl -0x24(%rbp), %ecx
addl $0x1, %ecx
movl %ecx, %ecx
movq (%rax,%rcx,8), %rax
shrq $0x20, %rax
movl %eax, -0x20(%rbp)
movq -0x8(%rbp), %rdi
movl -0x18(%rbp), %esi
movl -0x20(%rbp), %edx
xorl %ecx, %ecx
callq 0xd6530
movq -0x8(%rbp), %rdi
movl -0x20(%rbp), %esi
xorl $0x1, %esi
movl -0x18(%rbp), %edx
xorl $0x1, %edx
xorl %ecx, %ecx
callq 0xd6530
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x1623cf
movl -0x14(%rbp), %eax
shll %eax
movl %eax, -0x18(%rbp)
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
movq 0x28(%rax), %rax
movl -0x18(%rbp), %ecx
movq (%rax,%rcx,8), %rax
movl %eax, -0x2c(%rbp)
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
movq 0x8(%rax), %rax
movq -0x10(%rbp), %rcx
movq 0x18(%rcx), %rcx
movq 0x28(%rcx), %rcx
movl -0x18(%rbp), %edx
movq (%rcx,%rdx,8), %rcx
shrq $0x20, %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x40(%rbp)
movl $0x0, -0x24(%rbp)
movl -0x24(%rbp), %eax
cmpl -0x2c(%rbp), %eax
jae 0x16260b
movq -0x40(%rbp), %rax
movl -0x24(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl 0xc(%rax), %eax
shrl $0x1f, %eax
cmpl $0x0, %eax
je 0x1624bf
jmp 0x1625fd
movq -0x40(%rbp), %rax
movl -0x24(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl 0x8(%rax), %eax
movl %eax, -0x20(%rbp)
movl -0x18(%rbp), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x162509
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x18(%rbp), %ecx
shrl %ecx
movl %ecx, %ecx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movq 0x18(%rax), %rax
movq (%rax), %rax
shrq $0x20, %rax
xorq $0x1, %rax
movq %rax, -0x50(%rbp)
jmp 0x16254d
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x18(%rbp), %ecx
shrl %ecx
movl %ecx, %ecx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movq 0x18(%rax), %rax
movq -0x10(%rbp), %rcx
movq 0x10(%rcx), %rcx
movl -0x18(%rbp), %edx
shrl %edx
movl %edx, %edx
imulq $0x28, %rdx, %rdx
addq %rdx, %rcx
movl 0x10(%rcx), %ecx
subl $0x1, %ecx
movl %ecx, %ecx
movq (%rax,%rcx,8), %rax
shrq $0x20, %rax
movq %rax, -0x50(%rbp)
movq -0x50(%rbp), %rax
movl %eax, -0x30(%rbp)
movl -0x20(%rbp), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x1625a9
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x20(%rbp), %ecx
shrl %ecx
movl %ecx, %ecx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movq 0x18(%rax), %rax
movq -0x10(%rbp), %rcx
movq 0x10(%rcx), %rcx
movl -0x20(%rbp), %edx
shrl %edx
movl %edx, %edx
imulq $0x28, %rdx, %rdx
addq %rdx, %rcx
movl 0x10(%rcx), %ecx
subl $0x1, %ecx
movl %ecx, %ecx
movq (%rax,%rcx,8), %rax
shrq $0x20, %rax
xorq $0x1, %rax
movq %rax, -0x58(%rbp)
jmp 0x1625ce
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x20(%rbp), %ecx
shrl %ecx
movl %ecx, %ecx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movq 0x18(%rax), %rax
movq (%rax), %rax
shrq $0x20, %rax
movq %rax, -0x58(%rbp)
movq -0x58(%rbp), %rax
movl %eax, -0x34(%rbp)
movq -0x8(%rbp), %rdi
movl -0x30(%rbp), %esi
movl -0x34(%rbp), %edx
xorl %ecx, %ecx
callq 0xd6530
movq -0x8(%rbp), %rdi
movl -0x34(%rbp), %esi
xorl $0x1, %esi
movl -0x30(%rbp), %edx
xorl $0x1, %edx
xorl %ecx, %ecx
callq 0xd6530
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x162495
movl -0x14(%rbp), %eax
shll %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
movq 0x28(%rax), %rax
movl -0x18(%rbp), %ecx
movq (%rax,%rcx,8), %rax
movl %eax, -0x2c(%rbp)
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
movq 0x8(%rax), %rax
movq -0x10(%rbp), %rcx
movq 0x18(%rcx), %rcx
movq 0x28(%rcx), %rcx
movl -0x18(%rbp), %edx
movq (%rcx,%rdx,8), %rcx
shrq $0x20, %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x40(%rbp)
movl $0x0, -0x24(%rbp)
movl -0x24(%rbp), %eax
cmpl -0x2c(%rbp), %eax
jae 0x1627d7
movq -0x40(%rbp), %rax
movl -0x24(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl 0xc(%rax), %eax
shrl $0x1f, %eax
cmpl $0x0, %eax
je 0x16268b
jmp 0x1627c9
movq -0x40(%rbp), %rax
movl -0x24(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl 0x8(%rax), %eax
movl %eax, -0x20(%rbp)
movl -0x18(%rbp), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x1626d5
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x18(%rbp), %ecx
shrl %ecx
movl %ecx, %ecx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movq 0x18(%rax), %rax
movq (%rax), %rax
shrq $0x20, %rax
xorq $0x1, %rax
movq %rax, -0x60(%rbp)
jmp 0x162719
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x18(%rbp), %ecx
shrl %ecx
movl %ecx, %ecx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movq 0x18(%rax), %rax
movq -0x10(%rbp), %rcx
movq 0x10(%rcx), %rcx
movl -0x18(%rbp), %edx
shrl %edx
movl %edx, %edx
imulq $0x28, %rdx, %rdx
addq %rdx, %rcx
movl 0x10(%rcx), %ecx
subl $0x1, %ecx
movl %ecx, %ecx
movq (%rax,%rcx,8), %rax
shrq $0x20, %rax
movq %rax, -0x60(%rbp)
movq -0x60(%rbp), %rax
movl %eax, -0x30(%rbp)
movl -0x20(%rbp), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x162775
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x20(%rbp), %ecx
shrl %ecx
movl %ecx, %ecx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movq 0x18(%rax), %rax
movq -0x10(%rbp), %rcx
movq 0x10(%rcx), %rcx
movl -0x20(%rbp), %edx
shrl %edx
movl %edx, %edx
imulq $0x28, %rdx, %rdx
addq %rdx, %rcx
movl 0x10(%rcx), %ecx
subl $0x1, %ecx
movl %ecx, %ecx
movq (%rax,%rcx,8), %rax
shrq $0x20, %rax
xorq $0x1, %rax
movq %rax, -0x68(%rbp)
jmp 0x16279a
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x20(%rbp), %ecx
shrl %ecx
movl %ecx, %ecx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movq 0x18(%rax), %rax
movq (%rax), %rax
shrq $0x20, %rax
movq %rax, -0x68(%rbp)
movq -0x68(%rbp), %rax
movl %eax, -0x34(%rbp)
movq -0x8(%rbp), %rdi
movl -0x30(%rbp), %esi
movl -0x34(%rbp), %edx
xorl %ecx, %ecx
callq 0xd6530
movq -0x8(%rbp), %rdi
movl -0x34(%rbp), %esi
xorl $0x1, %esi
movl -0x30(%rbp), %edx
xorl $0x1, %edx
xorl %ecx, %ecx
callq 0xd6530
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x162661
jmp 0x1627d9
jmp 0x1627db
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0x16231d
movq -0x8(%rbp), %rdi
callq 0xcdd10
addq $0x70, %rsp
popq %rbp
retq
nopl (%rax,%rax)