// File: /workspace/github_cpp_makefile_star2_O3/chhylp123[P]hifiasm/gfa_ut.cpp
// Function: filter_sg_by_ug(asg_t*, ma_ug_t*, ug_opt_t*)
void filter_sg_by_ug(asg_t *rg, ma_ug_t *ug, ug_opt_t *uopt)
{
    uint32_t i, m, v, w, nv, n_vx, vx, wx; int32_t r;
    asg_arc_t *av = NULL; ma_utg_t *u = NULL; asg_arc_t *p, t;
    n_vx = rg->n_seq; rg->n_arc = 0;
    for (v = 0; v < n_vx; v++) rg->seq[v].del = (!!1);

    for (i = 0; i < ug->g->n_seq; ++i) {
        ug->g->seq[i].c = PRIMARY_LABLE;;
        if(ug->g->seq[i].del) continue;
        u = &(ug->u.a[i]);
        for (m = 0; m < u->n; m++) rg->seq[u->a[m]>>33].del = (!!0);
        for (m = 0; (m + 1) < u->n; m++) {
            v = u->a[m]>>32; w = u->a[m+1]>>32;
            r = gen_spec_edge(rg, uopt, v, w, &t);
            assert(r >= 0); p = asg_arc_pushp(rg); *p = t;

            r = gen_spec_edge(rg, uopt, w^1, v^1, &t);
            assert(r >= 0); p = asg_arc_pushp(rg); *p = t;
        }


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

            r = gen_spec_edge(rg, uopt, vx, wx, &t);
            assert(r >= 0); p = asg_arc_pushp(rg); *p = t;

            // r = gen_spec_edge(rg, uopt, wx^1, vx^1, &t);
            // assert(r >= 0); p = asg_arc_pushp(rg); *p = t;
        }

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

            r = gen_spec_edge(rg, uopt, vx, wx, &t);
            assert(r >= 0); p = asg_arc_pushp(rg); *p = t;

            // r = gen_spec_edge(rg, uopt, wx^1, vx^1, &t);
            // assert(r >= 0); p = asg_arc_pushp(rg); *p = t;
        }

        if(u->circ) {
            v = w = i<<1;
            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));
            r = gen_spec_edge(rg, uopt, vx, wx, &t);
            assert(r >= 0); p = asg_arc_pushp(rg); *p = t;

            v = w = (i<<1)^1;
            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));
            r = gen_spec_edge(rg, uopt, vx, wx, &t);
            assert(r >= 0); p = asg_arc_pushp(rg); *p = t;
        }
    }

    free(rg->idx);
    rg->idx = 0;
    rg->is_srt = 0;
    asg_cleanup(rg);
    asg_symm(rg);


    /*******************************for debug************************************/
    // ma_ug_t *dbg = ma_ug_gen(rg);
    // for (i = 0; i < dbg->g->n_seq; ++i) dbg->g->seq[i].c = PRIMARY_LABLE;  
    // cmp_untig_graph(dbg, ug);
    /*******************************for debug************************************/
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rdx, 0x10(%rsp)
movq %rsi, 0x8(%rsp)
movq %rdi, %rbx
movl 0x14(%rdi), %eax
andl $0x80000000, 0x4(%rdi)  # imm = 0x80000000
andq $0x7fffffff, %rax       # imm = 0x7FFFFFFF
je 0x1f9799
xorl %ecx, %ecx
movq 0x20(%rbx), %rdx
orl $0x80000000, (%rdx,%rcx,8) # imm = 0x80000000
incq %rcx
cmpq %rcx, %rax
jne 0x1f9786
movq 0x8(%rsp), %rax
movq 0x18(%rax), %rax
testl $0x7fffffff, 0x14(%rax) # imm = 0x7FFFFFFF
je 0x1f9d41
xorl %r14d, %r14d
movq 0x20(%rax), %rax
movb $0x0, 0x4(%rax,%r14,8)
cmpl $0x0, (%rax,%r14,8)
js 0x1f9d23
movq 0x8(%rsp), %rax
movq 0x10(%rax), %rax
movq %r14, 0x30(%rsp)
leaq (%r14,%r14,4), %r12
leaq (%rax,%r12,8), %r15
cmpl $0x0, 0x10(%r15)
je 0x1f9961
xorl %eax, %eax
movq 0x20(%rbx), %rcx
movq 0x18(%r15), %rdx
movq (%rdx,%rax,8), %rdx
shrq $0x21, %rdx
andl $0x7fffffff, (%rcx,%rdx,8) # imm = 0x7FFFFFFF
incq %rax
movl 0x10(%r15), %ecx
cmpq %rcx, %rax
jb 0x1f97ea
cmpl $0x2, %ecx
jb 0x1f9961
movl $0x1, %r14d
movq 0x18(%r15), %rax
movl -0x4(%rax,%r14,8), %ebp
movl 0x4(%rax,%r14,8), %r13d
movq %rbx, %rdi
movq 0x10(%rsp), %rsi
movl %ebp, %edx
movl %r13d, %ecx
leaq 0x18(%rsp), %r8
callq 0x1f94d8
testl %eax, %eax
js 0x1f9dd1
movl 0x4(%rbx), %edx
movl %edx, %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
cmpl (%rbx), %ecx
jne 0x1f9889
leal (%rcx,%rcx), %eax
testl %ecx, %ecx
movl $0x10, %ecx
cmovel %ecx, %eax
movl %eax, (%rbx)
movq 0x8(%rbx), %rdi
shlq $0x3, %rax
leaq (%rax,%rax,2), %rsi
callq 0x2370
movq %rax, 0x8(%rbx)
movl 0x4(%rbx), %edx
movl %edx, %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
jmp 0x1f988d
movq 0x8(%rbx), %rax
leal 0x1(%rdx), %esi
andl $0x7fffffff, %esi       # imm = 0x7FFFFFFF
andl $0x80000000, %edx       # imm = 0x80000000
orl %esi, %edx
movl %edx, 0x4(%rbx)
movl %ecx, %ecx
leaq (%rcx,%rcx,2), %rcx
movq 0x28(%rsp), %rdx
movq %rdx, 0x10(%rax,%rcx,8)
movups 0x18(%rsp), %xmm0
movups %xmm0, (%rax,%rcx,8)
xorl $0x1, %r13d
xorl $0x1, %ebp
movq %rbx, %rdi
movq 0x10(%rsp), %rsi
movl %r13d, %edx
movl %ebp, %ecx
leaq 0x18(%rsp), %r8
callq 0x1f94d8
testl %eax, %eax
js 0x1f9db2
movl 0x4(%rbx), %edx
movl %edx, %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
cmpl (%rbx), %ecx
jne 0x1f9920
leal (%rcx,%rcx), %eax
testl %ecx, %ecx
movl $0x10, %ecx
cmovel %ecx, %eax
movl %eax, (%rbx)
movq 0x8(%rbx), %rdi
shlq $0x3, %rax
leaq (%rax,%rax,2), %rsi
callq 0x2370
movq %rax, 0x8(%rbx)
movl 0x4(%rbx), %edx
movl %edx, %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
jmp 0x1f9924
movq 0x8(%rbx), %rax
leal 0x1(%rdx), %esi
andl $0x7fffffff, %esi       # imm = 0x7FFFFFFF
andl $0x80000000, %edx       # imm = 0x80000000
orl %esi, %edx
movl %edx, 0x4(%rbx)
movl %ecx, %ecx
leaq (%rcx,%rcx,2), %rcx
movq 0x28(%rsp), %rdx
movq %rdx, 0x10(%rax,%rcx,8)
movups 0x18(%rsp), %xmm0
movups %xmm0, (%rax,%rcx,8)
incq %r14
movl 0x10(%r15), %eax
cmpq %rax, %r14
jb 0x1f981c
movq 0x8(%rsp), %rax
movq 0x18(%rax), %rcx
movq 0x8(%rcx), %rax
movq 0x28(%rcx), %rcx
movq 0x30(%rsp), %rsi
movq %rsi, %rdx
shlq $0x4, %rdx
movq (%rcx,%rdx), %rdx
testl %edx, %edx
je 0x1f9aaa
movq %rdx, %rcx
shrq $0x20, %rcx
movl %edx, %edx
leaq (%rcx,%rcx,2), %rcx
leaq (%rax,%rcx,8), %r14
addq $0xc, %r14
shlq $0x3, %rdx
leaq (%rdx,%rdx,2), %r13
xorl %ebp, %ebp
cmpl $0x0, (%r14,%rbp)
js 0x1f9a87
movl -0x4(%r14,%rbp), %edx
movq 0x8(%rsp), %rax
movq 0x10(%rax), %rax
movl %edx, %ecx
shrl %ecx
leaq (%rcx,%rcx,4), %rcx
testb $0x1, %dl
jne 0x1f99d9
movq 0x18(%rax,%rcx,8), %rcx
movl 0x4(%rcx), %ecx
jmp 0x1f99ec
movq 0x18(%rax,%rcx,8), %rdx
movl 0x10(%rax,%rcx,8), %ecx
decl %ecx
movl 0x4(%rdx,%rcx,8), %ecx
xorq $0x1, %rcx
movq 0x18(%rax,%r12,8), %rdx
movl 0x10(%rax,%r12,8), %eax
decl %eax
movl 0x4(%rdx,%rax,8), %edx
movq %rbx, %rdi
movq 0x10(%rsp), %rsi
leaq 0x18(%rsp), %r8
callq 0x1f94d8
testl %eax, %eax
js 0x1f9d74
movl 0x4(%rbx), %edx
movl %edx, %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
cmpl (%rbx), %ecx
jne 0x1f9a56
leal (%rcx,%rcx), %eax
testl %ecx, %ecx
movl $0x10, %ecx
cmovel %ecx, %eax
movl %eax, (%rbx)
movq 0x8(%rbx), %rdi
shlq $0x3, %rax
leaq (%rax,%rax,2), %rsi
callq 0x2370
movq %rax, 0x8(%rbx)
movl 0x4(%rbx), %edx
movl %edx, %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
jmp 0x1f9a5a
movq 0x8(%rbx), %rax
leal 0x1(%rdx), %esi
andl $0x7fffffff, %esi       # imm = 0x7FFFFFFF
andl $0x80000000, %edx       # imm = 0x80000000
orl %esi, %edx
movl %edx, 0x4(%rbx)
movl %ecx, %ecx
leaq (%rcx,%rcx,2), %rcx
movq 0x28(%rsp), %rdx
movq %rdx, 0x10(%rax,%rcx,8)
movups 0x18(%rsp), %xmm0
movups %xmm0, (%rax,%rcx,8)
addq $0x18, %rbp
cmpq %rbp, %r13
jne 0x1f99a9
movq 0x8(%rsp), %rax
movq 0x18(%rax), %rcx
movq 0x8(%rcx), %rax
movq 0x28(%rcx), %rcx
movq 0x30(%rsp), %rsi
leaq (%rsi,%rsi), %rdx
movq 0x8(%rcx,%rdx,8), %rcx
testl %ecx, %ecx
je 0x1f9bc0
movq %rcx, %rdx
shrq $0x20, %rdx
movl %ecx, %ecx
leaq (%rdx,%rdx,2), %rdx
leaq (%rax,%rdx,8), %r14
addq $0xc, %r14
shlq $0x3, %rcx
leaq (%rcx,%rcx,2), %r13
xorl %ebp, %ebp
cmpl $0x0, (%r14,%rbp)
js 0x1f9bb3
movl -0x4(%r14,%rbp), %edx
movq 0x8(%rsp), %rax
movq 0x10(%rax), %rax
movl %edx, %ecx
shrl %ecx
leaq (%rcx,%rcx,4), %rcx
testb $0x1, %dl
jne 0x1f9b0a
movq 0x18(%rax,%rcx,8), %rcx
movl 0x4(%rcx), %ecx
jmp 0x1f9b1d
movq 0x18(%rax,%rcx,8), %rdx
movl 0x10(%rax,%rcx,8), %ecx
decl %ecx
movl 0x4(%rdx,%rcx,8), %ecx
xorq $0x1, %rcx
movq 0x18(%rax,%r12,8), %rax
movl 0x4(%rax), %edx
xorl $0x1, %edx
movq %rbx, %rdi
movq 0x10(%rsp), %rsi
leaq 0x18(%rsp), %r8
callq 0x1f94d8
testl %eax, %eax
js 0x1f9d93
movl 0x4(%rbx), %edx
movl %edx, %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
cmpl (%rbx), %ecx
jne 0x1f9b82
leal (%rcx,%rcx), %eax
testl %ecx, %ecx
movl $0x10, %ecx
cmovel %ecx, %eax
movl %eax, (%rbx)
movq 0x8(%rbx), %rdi
shlq $0x3, %rax
leaq (%rax,%rax,2), %rsi
callq 0x2370
movq %rax, 0x8(%rbx)
movl 0x4(%rbx), %edx
movl %edx, %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
jmp 0x1f9b86
movq 0x8(%rbx), %rax
leal 0x1(%rdx), %esi
andl $0x7fffffff, %esi       # imm = 0x7FFFFFFF
andl $0x80000000, %edx       # imm = 0x80000000
orl %esi, %edx
movl %edx, 0x4(%rbx)
movl %ecx, %ecx
leaq (%rcx,%rcx,2), %rcx
movq 0x28(%rsp), %rdx
movq %rdx, 0x10(%rax,%rcx,8)
movups 0x18(%rsp), %xmm0
movups %xmm0, (%rax,%rcx,8)
addq $0x18, %rbp
cmpq %rbp, %r13
jne 0x1f9ada
cmpl $0x0, (%r15)
movq 0x30(%rsp), %r14
jns 0x1f9d23
movq 0x8(%rsp), %rax
movq 0x10(%rax), %rax
movq 0x18(%rax,%r12,8), %rcx
movl 0x10(%rax,%r12,8), %eax
decl %eax
movl 0x4(%rcx,%rax,8), %edx
movl 0x4(%rcx), %ecx
movq %rbx, %rdi
movq 0x10(%rsp), %rsi
leaq 0x18(%rsp), %r8
callq 0x1f94d8
testl %eax, %eax
js 0x1f9df0
movl 0x4(%rbx), %edx
movl %edx, %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
cmpl (%rbx), %ecx
jne 0x1f9c45
leal (%rcx,%rcx), %eax
testl %ecx, %ecx
movl $0x10, %ecx
cmovel %ecx, %eax
movl %eax, (%rbx)
movq 0x8(%rbx), %rdi
shlq $0x3, %rax
leaq (%rax,%rax,2), %rsi
callq 0x2370
movq %rax, 0x8(%rbx)
movl 0x4(%rbx), %edx
movl %edx, %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
jmp 0x1f9c49
movq 0x8(%rbx), %rax
leal 0x1(%rdx), %esi
andl $0x7fffffff, %esi       # imm = 0x7FFFFFFF
andl $0x80000000, %edx       # imm = 0x80000000
orl %esi, %edx
movl %edx, 0x4(%rbx)
movl %ecx, %ecx
leaq (%rcx,%rcx,2), %rcx
movq 0x28(%rsp), %rdx
movq %rdx, 0x10(%rax,%rcx,8)
movups 0x18(%rsp), %xmm0
movups %xmm0, (%rax,%rcx,8)
movq 0x8(%rsp), %rax
movq 0x10(%rax), %rax
movq 0x18(%rax,%r12,8), %rcx
movl 0x4(%rcx), %edx
xorl $0x1, %edx
movl 0x10(%rax,%r12,8), %eax
decl %eax
movl 0x4(%rcx,%rax,8), %ecx
xorl $0x1, %ecx
movq %rbx, %rdi
movq 0x10(%rsp), %rsi
leaq 0x18(%rsp), %r8
callq 0x1f94d8
testl %eax, %eax
js 0x1f9e0f
movl 0x4(%rbx), %edx
movl %edx, %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
cmpl (%rbx), %ecx
jne 0x1f9cf2
leal (%rcx,%rcx), %eax
testl %ecx, %ecx
movl $0x10, %ecx
cmovel %ecx, %eax
movl %eax, (%rbx)
movq 0x8(%rbx), %rdi
shlq $0x3, %rax
leaq (%rax,%rax,2), %rsi
callq 0x2370
movq %rax, 0x8(%rbx)
movl 0x4(%rbx), %edx
movl %edx, %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
jmp 0x1f9cf6
movq 0x8(%rbx), %rax
leal 0x1(%rdx), %esi
andl $0x7fffffff, %esi       # imm = 0x7FFFFFFF
andl $0x80000000, %edx       # imm = 0x80000000
orl %esi, %edx
movl %edx, 0x4(%rbx)
movl %ecx, %ecx
leaq (%rcx,%rcx,2), %rcx
movq 0x28(%rsp), %rdx
movq %rdx, 0x10(%rax,%rcx,8)
movups 0x18(%rsp), %xmm0
movups %xmm0, (%rax,%rcx,8)
incq %r14
movq 0x8(%rsp), %rax
movq 0x18(%rax), %rax
movl 0x14(%rax), %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
cmpq %rcx, %r14
jb 0x1f97b2
movq 0x28(%rbx), %rdi
callq 0x2220
movq $0x0, 0x28(%rbx)
andb $0x7f, 0x7(%rbx)
movq %rbx, %rdi
callq 0xa0a7d
movq %rbx, %rdi
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xa0c1e
leaq 0x39f0f(%rip), %rdi     # 0x233c8a
leaq 0x4b887(%rip), %rsi     # 0x245609
leaq 0x4bf21(%rip), %rcx     # 0x245caa
movl $0xb3f, %edx            # imm = 0xB3F
callq 0x2110
leaq 0x39ef0(%rip), %rdi     # 0x233c8a
leaq 0x4b868(%rip), %rsi     # 0x245609
leaq 0x4bf02(%rip), %rcx     # 0x245caa
movl $0xb4d, %edx            # imm = 0xB4D
callq 0x2110
leaq 0x39ed1(%rip), %rdi     # 0x233c8a
leaq 0x4b849(%rip), %rsi     # 0x245609
leaq 0x4bee3(%rip), %rcx     # 0x245caa
movl $0xb33, %edx            # imm = 0xB33
callq 0x2110
leaq 0x39eb2(%rip), %rdi     # 0x233c8a
leaq 0x4b82a(%rip), %rsi     # 0x245609
leaq 0x4bec4(%rip), %rcx     # 0x245caa
movl $0xb30, %edx            # imm = 0xB30
callq 0x2110
leaq 0x39e93(%rip), %rdi     # 0x233c8a
leaq 0x4b80b(%rip), %rsi     # 0x245609
leaq 0x4bea5(%rip), %rcx     # 0x245caa
movl $0xb58, %edx            # imm = 0xB58
callq 0x2110
leaq 0x39e74(%rip), %rdi     # 0x233c8a
leaq 0x4b7ec(%rip), %rsi     # 0x245609
leaq 0x4be86(%rip), %rcx     # 0x245caa
movl $0xb5e, %edx            # imm = 0xB5E
callq 0x2110