// File: /workspace/github_cpp_makefile_star2_O1/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, %r14
movq %rsi, 0x8(%rsp)
movq %rdi, %rbx
movl 0x14(%rdi), %eax
andl $0x80000000, 0x4(%rdi)  # imm = 0x80000000
andq $0x7fffffff, %rax       # imm = 0x7FFFFFFF
je 0x1ee47b
xorl %ecx, %ecx
movq 0x20(%rbx), %rdx
orl $0x80000000, (%rdx,%rcx,8) # imm = 0x80000000
incq %rcx
cmpq %rcx, %rax
jne 0x1ee468
movq 0x8(%rsp), %rax
movq 0x18(%rax), %rax
testl $0x7fffffff, 0x14(%rax) # imm = 0x7FFFFFFF
je 0x1eea15
xorl %r15d, %r15d
movq 0x20(%rax), %rax
movb $0x0, 0x4(%rax,%r15,8)
cmpl $0x0, (%rax,%r15,8)
js 0x1ee9f7
movq 0x8(%rsp), %rax
movq 0x10(%rax), %rax
movq %r15, 0x30(%rsp)
leaq (%r15,%r15,4), %rcx
movq %rcx, 0x28(%rsp)
leaq (%rax,%rcx,8), %r15
cmpl $0x0, 0x10(%r15)
je 0x1ee4f0
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 0x1ee4cd
cmpl $0x2, 0x10(%r15)
jb 0x1ee63c
movl $0x1, %r12d
movq 0x18(%r15), %rax
movl -0x4(%rax,%r12,8), %ebp
movl 0x4(%rax,%r12,8), %r13d
movq %rbx, %rdi
movq %r14, %rsi
movl %ebp, %edx
movl %r13d, %ecx
leaq 0x10(%rsp), %r8
callq 0x1ee341
testl %eax, %eax
js 0x1eea48
movl 0x4(%rbx), %ecx
movl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
andl %eax, %ecx
movl (%rbx), %eax
cmpl %eax, %ecx
jne 0x1ee560
leal (%rax,%rax), %ecx
testl %eax, %eax
movl $0x10, %eax
cmovel %eax, %ecx
movl %ecx, (%rbx)
movq 0x8(%rbx), %rdi
shlq $0x3, %rcx
leaq (%rcx,%rcx,2), %rsi
callq 0x2370
movq %rax, 0x8(%rbx)
movq 0x8(%rbx), %rax
movl 0x4(%rbx), %ecx
movl %ecx, %edx
andl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
leal 0x1(%rcx), %esi
andl $0x7fffffff, %esi       # imm = 0x7FFFFFFF
andl $0x80000000, %ecx       # imm = 0x80000000
orl %esi, %ecx
movl %ecx, 0x4(%rbx)
leaq (%rdx,%rdx,2), %rcx
movq 0x20(%rsp), %rdx
movq %rdx, 0x10(%rax,%rcx,8)
movups 0x10(%rsp), %xmm0
movups %xmm0, (%rax,%rcx,8)
xorl $0x1, %r13d
xorl $0x1, %ebp
movq %rbx, %rdi
movq %r14, %rsi
movl %r13d, %edx
movl %ebp, %ecx
leaq 0x10(%rsp), %r8
callq 0x1ee341
testl %eax, %eax
js 0x1eea67
movl 0x4(%rbx), %ecx
movl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
andl %eax, %ecx
movl (%rbx), %eax
cmpl %eax, %ecx
jne 0x1ee5f2
leal (%rax,%rax), %ecx
testl %eax, %eax
movl $0x10, %eax
cmovel %eax, %ecx
movl %ecx, (%rbx)
movq 0x8(%rbx), %rdi
shlq $0x3, %rcx
leaq (%rcx,%rcx,2), %rsi
callq 0x2370
movq %rax, 0x8(%rbx)
movq 0x8(%rbx), %rax
movl 0x4(%rbx), %ecx
movl %ecx, %edx
andl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
leal 0x1(%rcx), %esi
andl $0x7fffffff, %esi       # imm = 0x7FFFFFFF
andl $0x80000000, %ecx       # imm = 0x80000000
orl %esi, %ecx
movl %ecx, 0x4(%rbx)
leaq (%rdx,%rdx,2), %rcx
movq 0x20(%rsp), %rdx
movq %rdx, 0x10(%rax,%rcx,8)
movups 0x10(%rsp), %xmm0
movups %xmm0, (%rax,%rcx,8)
incq %r12
movl 0x10(%r15), %eax
cmpq %rax, %r12
jb 0x1ee501
movq 0x8(%rsp), %rax
movq 0x18(%rax), %rcx
movq 0x28(%rcx), %rax
movq 0x30(%rsp), %rdx
shlq $0x4, %rdx
movq (%rax,%rdx), %rax
testl %eax, %eax
je 0x1ee76b
movq 0x8(%rcx), %rcx
movq %rax, %rdx
shrq $0x20, %rdx
movl %eax, %eax
leaq (%rdx,%rdx,2), %rdx
leaq (%rcx,%rdx,8), %r12
addq $0xc, %r12
shlq $0x3, %rax
leaq (%rax,%rax,2), %r13
xorl %ebp, %ebp
cmpl $0x0, (%r12,%rbp)
js 0x1ee75e
movl -0x4(%r12,%rbp), %edx
movq 0x8(%rsp), %rax
movq 0x10(%rax), %rax
movl %edx, %ecx
shrl %ecx
leaq (%rcx,%rcx,4), %rcx
testb $0x1, %dl
jne 0x1ee6b1
movq 0x18(%rax,%rcx,8), %rcx
movl 0x4(%rcx), %ecx
jmp 0x1ee6c4
movq 0x18(%rax,%rcx,8), %rdx
movl 0x10(%rax,%rcx,8), %ecx
decl %ecx
movl 0x4(%rdx,%rcx,8), %ecx
xorq $0x1, %rcx
movq 0x28(%rsp), %rsi
movq 0x18(%rax,%rsi,8), %rdx
movl 0x10(%rax,%rsi,8), %eax
decl %eax
movl 0x4(%rdx,%rax,8), %edx
movq %rbx, %rdi
movq %r14, %rsi
leaq 0x10(%rsp), %r8
callq 0x1ee341
testl %eax, %eax
js 0x1eea86
movl 0x4(%rbx), %ecx
movl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
andl %eax, %ecx
movl (%rbx), %eax
cmpl %eax, %ecx
jne 0x1ee724
leal (%rax,%rax), %ecx
testl %eax, %eax
movl $0x10, %eax
cmovel %eax, %ecx
movl %ecx, (%rbx)
movq 0x8(%rbx), %rdi
shlq $0x3, %rcx
leaq (%rcx,%rcx,2), %rsi
callq 0x2370
movq %rax, 0x8(%rbx)
movq 0x8(%rbx), %rax
movl 0x4(%rbx), %ecx
movl %ecx, %edx
andl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
leal 0x1(%rcx), %esi
andl $0x7fffffff, %esi       # imm = 0x7FFFFFFF
andl $0x80000000, %ecx       # imm = 0x80000000
orl %esi, %ecx
movl %ecx, 0x4(%rbx)
leaq (%rdx,%rdx,2), %rcx
movq 0x20(%rsp), %rdx
movq %rdx, 0x10(%rax,%rcx,8)
movups 0x10(%rsp), %xmm0
movups %xmm0, (%rax,%rcx,8)
addq $0x18, %rbp
cmpq %rbp, %r13
jne 0x1ee681
movq 0x30(%rsp), %rax
addq %rax, %rax
movq 0x8(%rsp), %rcx
movq 0x18(%rcx), %rcx
movq 0x28(%rcx), %rdx
movq 0x8(%rdx,%rax,8), %rax
testl %eax, %eax
je 0x1ee896
movq 0x8(%rcx), %rcx
movq %rax, %rdx
shrq $0x20, %rdx
movl %eax, %eax
leaq (%rdx,%rdx,2), %rdx
leaq (%rcx,%rdx,8), %r12
addq $0xc, %r12
shlq $0x3, %rax
leaq (%rax,%rax,2), %r13
xorl %ebp, %ebp
cmpl $0x0, (%r12,%rbp)
js 0x1ee889
movl -0x4(%r12,%rbp), %edx
movq 0x8(%rsp), %rax
movq 0x10(%rax), %rax
movl %edx, %ecx
shrl %ecx
leaq (%rcx,%rcx,4), %rcx
testb $0x1, %dl
jne 0x1ee7e0
movq 0x18(%rax,%rcx,8), %rcx
movl 0x4(%rcx), %ecx
jmp 0x1ee7f3
movq 0x18(%rax,%rcx,8), %rdx
movl 0x10(%rax,%rcx,8), %ecx
decl %ecx
movl 0x4(%rdx,%rcx,8), %ecx
xorq $0x1, %rcx
movq 0x28(%rsp), %rdx
movq 0x18(%rax,%rdx,8), %rax
movl 0x4(%rax), %edx
xorl $0x1, %edx
movq %rbx, %rdi
movq %r14, %rsi
leaq 0x10(%rsp), %r8
callq 0x1ee341
testl %eax, %eax
js 0x1eeaa5
movl 0x4(%rbx), %ecx
movl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
andl %eax, %ecx
movl (%rbx), %eax
cmpl %eax, %ecx
jne 0x1ee84f
leal (%rax,%rax), %ecx
testl %eax, %eax
movl $0x10, %eax
cmovel %eax, %ecx
movl %ecx, (%rbx)
movq 0x8(%rbx), %rdi
shlq $0x3, %rcx
leaq (%rcx,%rcx,2), %rsi
callq 0x2370
movq %rax, 0x8(%rbx)
movq 0x8(%rbx), %rax
movl 0x4(%rbx), %ecx
movl %ecx, %edx
andl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
leal 0x1(%rcx), %esi
andl $0x7fffffff, %esi       # imm = 0x7FFFFFFF
andl $0x80000000, %ecx       # imm = 0x80000000
orl %esi, %ecx
movl %ecx, 0x4(%rbx)
leaq (%rdx,%rdx,2), %rcx
movq 0x20(%rsp), %rdx
movq %rdx, 0x10(%rax,%rcx,8)
movups 0x10(%rsp), %xmm0
movups %xmm0, (%rax,%rcx,8)
addq $0x18, %rbp
cmpq %rbp, %r13
jne 0x1ee7b0
cmpl $0x0, (%r15)
movq 0x30(%rsp), %r15
jns 0x1ee9f7
movq 0x8(%rsp), %rax
movq 0x10(%rax), %rax
movq 0x28(%rsp), %rdx
movq 0x18(%rax,%rdx,8), %rcx
movl 0x10(%rax,%rdx,8), %eax
decl %eax
movl 0x4(%rcx,%rax,8), %edx
movl 0x4(%rcx), %ecx
movq %rbx, %rdi
movq %r14, %rsi
leaq 0x10(%rsp), %r8
callq 0x1ee341
testl %eax, %eax
js 0x1eeac4
movl 0x4(%rbx), %ecx
movl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
andl %eax, %ecx
movl (%rbx), %eax
cmpl %eax, %ecx
jne 0x1ee911
leal (%rax,%rax), %ecx
testl %eax, %eax
movl $0x10, %eax
cmovel %eax, %ecx
movl %ecx, (%rbx)
movq 0x8(%rbx), %rdi
shlq $0x3, %rcx
leaq (%rcx,%rcx,2), %rsi
callq 0x2370
movq %rax, 0x8(%rbx)
movq 0x8(%rbx), %rax
movl 0x4(%rbx), %ecx
movl %ecx, %edx
andl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
leal 0x1(%rcx), %esi
andl $0x7fffffff, %esi       # imm = 0x7FFFFFFF
andl $0x80000000, %ecx       # imm = 0x80000000
orl %esi, %ecx
movl %ecx, 0x4(%rbx)
leaq (%rdx,%rdx,2), %rcx
movq 0x20(%rsp), %rdx
movq %rdx, 0x10(%rax,%rcx,8)
movups 0x10(%rsp), %xmm0
movups %xmm0, (%rax,%rcx,8)
movq 0x8(%rsp), %rax
movq 0x10(%rax), %rax
movq 0x28(%rsp), %rsi
movq 0x18(%rax,%rsi,8), %rcx
movl 0x4(%rcx), %edx
xorl $0x1, %edx
movl 0x10(%rax,%rsi,8), %eax
decl %eax
movl 0x4(%rcx,%rax,8), %ecx
xorl $0x1, %ecx
movq %rbx, %rdi
movq %r14, %rsi
leaq 0x10(%rsp), %r8
callq 0x1ee341
testl %eax, %eax
js 0x1eeae3
movl 0x4(%rbx), %ecx
movl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
andl %eax, %ecx
movl (%rbx), %eax
cmpl %eax, %ecx
jne 0x1ee9bd
leal (%rax,%rax), %ecx
testl %eax, %eax
movl $0x10, %eax
cmovel %eax, %ecx
movl %ecx, (%rbx)
movq 0x8(%rbx), %rdi
shlq $0x3, %rcx
leaq (%rcx,%rcx,2), %rsi
callq 0x2370
movq %rax, 0x8(%rbx)
movq 0x8(%rbx), %rax
movl 0x4(%rbx), %ecx
movl %ecx, %edx
andl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
leal 0x1(%rcx), %esi
andl $0x7fffffff, %esi       # imm = 0x7FFFFFFF
andl $0x80000000, %ecx       # imm = 0x80000000
orl %esi, %ecx
movl %ecx, 0x4(%rbx)
leaq (%rdx,%rdx,2), %rcx
movq 0x20(%rsp), %rdx
movq %rdx, 0x10(%rax,%rcx,8)
movups 0x10(%rsp), %xmm0
movups %xmm0, (%rax,%rcx,8)
incq %r15
movq 0x8(%rsp), %rax
movq 0x18(%rax), %rax
movl 0x14(%rax), %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
cmpq %rcx, %r15
jb 0x1ee494
movq 0x28(%rbx), %rdi
callq 0x2220
movq $0x0, 0x28(%rbx)
andb $0x7f, 0x7(%rbx)
movq %rbx, %rdi
callq 0xa02fa
movq %rbx, %rdi
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xa047e
leaq 0x3912b(%rip), %rdi     # 0x227b7a
leaq 0x4a8cf(%rip), %rsi     # 0x239325
leaq 0x4af69(%rip), %rcx     # 0x2399c6
movl $0xb30, %edx            # imm = 0xB30
callq 0x2110
leaq 0x3910c(%rip), %rdi     # 0x227b7a
leaq 0x4a8b0(%rip), %rsi     # 0x239325
leaq 0x4af4a(%rip), %rcx     # 0x2399c6
movl $0xb33, %edx            # imm = 0xB33
callq 0x2110
leaq 0x390ed(%rip), %rdi     # 0x227b7a
leaq 0x4a891(%rip), %rsi     # 0x239325
leaq 0x4af2b(%rip), %rcx     # 0x2399c6
movl $0xb3f, %edx            # imm = 0xB3F
callq 0x2110
leaq 0x390ce(%rip), %rdi     # 0x227b7a
leaq 0x4a872(%rip), %rsi     # 0x239325
leaq 0x4af0c(%rip), %rcx     # 0x2399c6
movl $0xb4d, %edx            # imm = 0xB4D
callq 0x2110
leaq 0x390af(%rip), %rdi     # 0x227b7a
leaq 0x4a853(%rip), %rsi     # 0x239325
leaq 0x4aeed(%rip), %rcx     # 0x2399c6
movl $0xb58, %edx            # imm = 0xB58
callq 0x2110
leaq 0x39090(%rip), %rdi     # 0x227b7a
leaq 0x4a834(%rip), %rsi     # 0x239325
leaq 0x4aece(%rip), %rcx     # 0x2399c6
movl $0xb5e, %edx            # imm = 0xB5E
callq 0x2110