// File: /workspace/github_cpp_makefile_star2_O2/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 $0x58, %rsp
movq %rdx, %r8
movq %rsi, %r15
movq %rdi, %rbx
movl 0x14(%rdi), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
andl $0x80000000, 0x4(%rdi)  # imm = 0x80000000
xorl %ecx, %ecx
cmpq %rcx, %rax
je 0x1adeb9
movq 0x20(%rbx), %rdx
orl $0x80000000, (%rdx,%rcx,8) # imm = 0x80000000
incq %rcx
jmp 0x1adea4
xorl %r12d, %r12d
leaq 0x10(%rsp), %r14
movq %r8, 0x28(%rsp)
movq %r15, 0x8(%rsp)
movq %rbx, 0x38(%rsp)
movq 0x18(%r15), %rax
movl 0x14(%rax), %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
cmpq %rcx, %r12
jae 0x1ae261
movq 0x20(%rax), %rax
movb $0x0, 0x4(%rax,%r12,8)
cmpl $0x0, (%rax,%r12,8)
js 0x1ae259
movq %r12, 0x30(%rsp)
imulq $0x28, %r12, %r12
movq 0x10(%r15), %rsi
addq %r12, %rsi
xorl %ecx, %ecx
movl 0x10(%rsi), %eax
cmpq %rax, %rcx
jae 0x1adf31
movq 0x20(%rbx), %rax
movq 0x18(%rsi), %rdx
movq (%rdx,%rcx,8), %rdx
shrq $0x21, %rdx
andl $0x7fffffff, (%rax,%rdx,8) # imm = 0x7FFFFFFF
incq %rcx
jmp 0x1adf0d
pushq $0x1
popq %r15
movq %r12, 0x40(%rsp)
movq %rsi, 0x48(%rsp)
movl %eax, %eax
cmpq %rax, %r15
jae 0x1adfee
movq 0x18(%rsi), %rax
movl -0x4(%rax,%r15,8), %ebp
movl 0x4(%rax,%r15,8), %r13d
movq 0x38(%rsp), %rbx
movq %rbx, %rdi
movq %r8, %rsi
movl %ebp, %edx
movl %r13d, %ecx
movq %r8, %r12
movq %r14, %r8
callq 0x1add8b
testl %eax, %eax
js 0x1ae291
movq %rbx, %rdi
callq 0x1ab555
movups 0x10(%rsp), %xmm0
movups %xmm0, (%rax)
movq 0x20(%rsp), %rcx
movq %rcx, 0x10(%rax)
xorl $0x1, %r13d
xorl $0x1, %ebp
movq %rbx, %rdi
movq %r12, %rsi
movl %r13d, %edx
movl %ebp, %ecx
movq %r14, %r8
callq 0x1add8b
testl %eax, %eax
js 0x1ae2b0
movq %rbx, %rdi
callq 0x1ab555
movq 0x20(%rsp), %rcx
movq %rcx, 0x10(%rax)
movups 0x10(%rsp), %xmm0
movups %xmm0, (%rax)
movq 0x48(%rsp), %rsi
movl 0x10(%rsi), %eax
incq %r15
leaq 0x10(%rsp), %r14
movq 0x28(%rsp), %r8
movq 0x40(%rsp), %r12
jmp 0x1adf3f
movq 0x30(%rsp), %rdx
leaq (%rdx,%rdx), %rax
movq %rax, 0x50(%rsp)
movq 0x8(%rsp), %rax
movq 0x18(%rax), %rax
movq 0x8(%rax), %rcx
movq 0x28(%rax), %rax
shlq $0x4, %rdx
movq (%rax,%rdx), %rax
movl %eax, %edx
shrq $0x20, %rax
imulq $0x18, %rdx, %rbp
imulq $0x18, %rax, %rax
leaq (%rcx,%rax), %r13
addq $0xc, %r13
xorl %r15d, %r15d
movq 0x38(%rsp), %rbx
cmpq %r15, %rbp
je 0x1ae0d2
cmpl $0x0, (%r13,%r15)
js 0x1ae0c9
movl -0x4(%r13,%r15), %edx
movq 0x8(%rsp), %rax
movq 0x10(%rax), %rax
movl %edx, %ecx
shrl %ecx
imulq $0x28, %rcx, %rcx
testb $0x1, %dl
jne 0x1ae06d
movq 0x18(%rax,%rcx), %rcx
movl 0x4(%rcx), %ecx
jmp 0x1ae080
movq 0x18(%rax,%rcx), %rdx
movl 0x10(%rax,%rcx), %ecx
decl %ecx
movl 0x4(%rdx,%rcx,8), %ecx
xorq $0x1, %rcx
movq 0x18(%rax,%r12), %rdx
movl 0x10(%rax,%r12), %eax
decl %eax
movl 0x4(%rdx,%rax,8), %edx
movq %rbx, %rdi
movq %r8, %rsi
movq %r14, %r8
callq 0x1add8b
testl %eax, %eax
js 0x1ae2cf
movq %rbx, %rdi
callq 0x1ab555
movups 0x10(%rsp), %xmm0
movups %xmm0, (%rax)
movq 0x20(%rsp), %rcx
movq %rcx, 0x10(%rax)
leaq 0x10(%rsp), %r14
movq 0x28(%rsp), %r8
addq $0x18, %r15
jmp 0x1ae033
movq 0x8(%rsp), %rax
movq 0x18(%rax), %rax
movq 0x8(%rax), %rcx
movq 0x28(%rax), %rax
movq 0x50(%rsp), %rdx
movq 0x8(%rax,%rdx,8), %rax
movl %eax, %edx
shrq $0x20, %rax
imulq $0x18, %rdx, %r13
imulq $0x18, %rax, %rax
leaq (%rcx,%rax), %rbp
addq $0xc, %rbp
xorl %r15d, %r15d
cmpq %r15, %r13
je 0x1ae19c
cmpl $0x0, (%rbp,%r15)
js 0x1ae193
movl -0x4(%rbp,%r15), %edx
movq 0x8(%rsp), %rax
movq 0x10(%rax), %rax
movl %edx, %ecx
shrl %ecx
imulq $0x28, %rcx, %rcx
testb $0x1, %dl
jne 0x1ae13c
movq 0x18(%rax,%rcx), %rcx
movl 0x4(%rcx), %ecx
jmp 0x1ae14f
movq 0x18(%rax,%rcx), %rdx
movl 0x10(%rax,%rcx), %ecx
decl %ecx
movl 0x4(%rdx,%rcx,8), %ecx
xorq $0x1, %rcx
movq 0x18(%rax,%r12), %rax
movl 0x4(%rax), %edx
xorl $0x1, %edx
movq %rbx, %rdi
movq %r8, %rsi
movq %r14, %r8
callq 0x1add8b
testl %eax, %eax
js 0x1ae2ee
movq %rbx, %rdi
callq 0x1ab555
movups 0x10(%rsp), %xmm0
movups %xmm0, (%rax)
movq 0x20(%rsp), %rcx
movq %rcx, 0x10(%rax)
leaq 0x10(%rsp), %r14
movq 0x28(%rsp), %r8
addq $0x18, %r15
jmp 0x1ae106
movq 0x48(%rsp), %rax
cmpl $0x0, (%rax)
movq 0x8(%rsp), %r15
movq 0x30(%rsp), %r12
jns 0x1ae259
movq 0x10(%r15), %rax
movq 0x40(%rsp), %rbp
movq 0x18(%rax,%rbp), %rcx
movl 0x10(%rax,%rbp), %eax
decl %eax
movl 0x4(%rcx,%rax,8), %edx
movl 0x4(%rcx), %ecx
movq %rbx, %rdi
movq %r8, %rsi
movq %r14, %r13
movq %r8, %r14
movq %r13, %r8
callq 0x1add8b
testl %eax, %eax
js 0x1ae32c
movq %rbx, %rdi
callq 0x1ab555
movups 0x10(%rsp), %xmm0
movups %xmm0, (%rax)
movq 0x20(%rsp), %rcx
movq %rcx, 0x10(%rax)
movq 0x10(%r15), %rax
movq 0x18(%rax,%rbp), %rcx
movl 0x4(%rcx), %edx
xorl $0x1, %edx
movl 0x10(%rax,%rbp), %eax
decl %eax
movl 0x4(%rcx,%rax,8), %ecx
xorl $0x1, %ecx
movq %rbx, %rdi
movq %r14, %rsi
movq %r13, %r8
callq 0x1add8b
testl %eax, %eax
js 0x1ae30d
movq %rbx, %rdi
callq 0x1ab555
movups 0x10(%rsp), %xmm0
movups %xmm0, (%rax)
movq 0x20(%rsp), %rcx
movq %rcx, 0x10(%rax)
leaq 0x10(%rsp), %r14
movq 0x28(%rsp), %r8
incq %r12
jmp 0x1aded0
movq 0x28(%rbx), %rdi
callq 0x2220
andq $0x0, 0x28(%rbx)
andb $0x7f, 0x7(%rbx)
movq %rbx, %rdi
callq 0x694eb
movq %rbx, %rdi
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x69638
leaq 0x37942(%rip), %rdi     # 0x1e5bda
leaq 0x4923a(%rip), %rsi     # 0x1f74d9
leaq 0x498d4(%rip), %rcx     # 0x1f7b7a
movl $0xb30, %edx            # imm = 0xB30
callq 0x2110
leaq 0x37923(%rip), %rdi     # 0x1e5bda
leaq 0x4921b(%rip), %rsi     # 0x1f74d9
leaq 0x498b5(%rip), %rcx     # 0x1f7b7a
movl $0xb33, %edx            # imm = 0xB33
callq 0x2110
leaq 0x37904(%rip), %rdi     # 0x1e5bda
leaq 0x491fc(%rip), %rsi     # 0x1f74d9
leaq 0x49896(%rip), %rcx     # 0x1f7b7a
movl $0xb3f, %edx            # imm = 0xB3F
callq 0x2110
leaq 0x378e5(%rip), %rdi     # 0x1e5bda
leaq 0x491dd(%rip), %rsi     # 0x1f74d9
leaq 0x49877(%rip), %rcx     # 0x1f7b7a
movl $0xb4d, %edx            # imm = 0xB4D
callq 0x2110
leaq 0x378c6(%rip), %rdi     # 0x1e5bda
leaq 0x491be(%rip), %rsi     # 0x1f74d9
leaq 0x49858(%rip), %rcx     # 0x1f7b7a
movl $0xb5e, %edx            # imm = 0xB5E
callq 0x2110
leaq 0x378a7(%rip), %rdi     # 0x1e5bda
leaq 0x4919f(%rip), %rsi     # 0x1f74d9
leaq 0x49839(%rip), %rcx     # 0x1f7b7a
movl $0xb58, %edx            # imm = 0xB58
callq 0x2110