// File: /workspace/github_cpp_makefile_star2_O3/chhylp123[P]hifiasm/gfa_ut.cpp
// Function: integer_sg_gen(ul_resolve_t*, unsigned long)
asg_t *integer_sg_gen(ul_resolve_t *uidx, uint64_t min_ovlp)
{
    ul2ul_idx_t *ul2 = &(uidx->uovl); ma_ug_t *ug = uidx->l1_ug; asg_t *raw_g = ug->g; ///uc_block_t *xi; 
    uint64_t i, k, is_del, v, w, nv, z; ul2ul_item_t *o, *ow; int32_t r; asg_arc_t t, *p; asg_arc_t *av;
    // ul_str_t *str;
    asg_t *g = asg_init();
    for (i = 0; i < ul2->tot; i++) {
        is_del = 0;
        o = get_ul_ovlp(ul2, ulg_id(*ul2, i), ulg_type(*ul2, i));
        if((!o) || (o->is_del)) is_del = 1;
        asg_seq_set(g, i, ulg_len(*uidx, i), is_del);
        g->seq[i].c = 0;
    }
    // CALLOC(g->seq_vis, g->n_seq*2);

    for (i = 0; i < ul2->tot; ++i) {
        o = get_ul_ovlp(ul2, ulg_id(*ul2, i), ulg_type(*ul2, i));
        if((!o) || (o->is_del)) continue;
        for (k = 0; k < o->n; k++) {
            if(o->a[k].is_del || o->a[k].is_ct) continue;
            r = integer_hit2arc(&(o->a[k]), ulg_len(*uidx, i), ulg_len(*uidx, o->a[k].hid), 
            ulg_occ(*uidx, i), ulg_occ(*uidx, o->a[k].hid), i, o->a[k].hid, min_ovlp, &t);
            if (r >= 0) {
                p = asg_arc_pushp(g);
                *p = t;
            }
        }
        if(i >= ul2->uln) {///is a node of ug
            v = (i-ul2->uln)<<1;
            nv = asg_arc_n(raw_g, v); av = asg_arc_a(raw_g, v);
            for (z = 0; z < nv; z++) {
                if(av[z].del) continue;
                w = av[z].v + (ul2->uln<<1);
                ow = get_ul_ovlp(ul2, ulg_id(*ul2, (w>>1)), ulg_type(*ul2, (w>>1)));
                if((!ow) || (ow->is_del)) continue;
                p = asg_arc_pushp(g);
                *p = av[z]; p->ul += (((uint64_t)ul2->uln)<<33); p->v += (ul2->uln<<1);
            }

            v = ((i-ul2->uln)<<1)+1;
            nv = asg_arc_n(raw_g, v); av = asg_arc_a(raw_g, v);
            for (z = 0; z < nv; z++) {
                if(av[z].del) continue;
                w = av[z].v + (ul2->uln<<1);
                ow = get_ul_ovlp(ul2, ulg_id(*ul2, (w>>1)), ulg_type(*ul2, (w>>1)));
                if((!ow) || (ow->is_del)) continue;
                p = asg_arc_pushp(g);
                *p = av[z]; p->ul += (((uint64_t)ul2->uln)<<33); p->v += (ul2->uln<<1);
            }
        } 
        // else { ///is a node of ug
        //     str = &(uidx->pstr.str.a[i]);
        //     if(str->cn > 0) {
        //         xi = &(uidx->idx->a[i].bb.a[str->a[0]>>32]); v = ((uint32_t)str->a[0])^1;
        //         ow = get_ul_ovlp(ul2, ulg_id(*ul2, (v>>1)), ulg_type(*ul2, (v>>1)));
        //         if((!ow) || (ow->is_del)) {
        //             nv = asg_arc_n(raw_g, v); av = asg_arc_a(raw_g, v);
        //         }

        //         xi = &(uidx->idx->a[i].bb.a[str->a[str->cn-1]>>32]); v = ((uint32_t)str->a[str->cn-1]);
        //         ow = get_ul_ovlp(ul2, ulg_id(*ul2, (v>>1)), ulg_type(*ul2, (v>>1)));
        //         if((!ow) || (ow->is_del)) {

        //         }
        //     }
        // }
    }
    asg_cleanup(g);
    g->r_seq = g->n_seq;
    // fprintf(stderr, "[M::%s::] # ig nodes::%u, # ig archs::%u\n", __func__, g->n_seq, g->n_arc);
    return g;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rsi, 0x8(%rsp)
movq %rdi, %r15
movq 0x18(%rdi), %rax
movq 0x18(%rax), %rax
movq %rax, (%rsp)
callq 0xa0485
movq %rax, %rbx
cmpq $0x0, 0x218(%r15)
je 0x20aa00
movl $0x3, %r14d
xorl %r13d, %r13d
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
xorl %r12d, %r12d
movq 0x220(%r15), %rax
movl (%rax,%r12,4), %eax
cmpq %rbp, %rax
je 0x20a4ad
movq 0x1f0(%r15), %rdx
testq %rdx, %rdx
je 0x20a4ad
shlq $0x5, %rax
xorl %ecx, %ecx
cmpl $0x0, 0x18(%rdx,%rax)
jns 0x20a4b2
movl $0x1, %ecx
movq 0x208(%r15), %rax
cmpq %rax, %r12
jae 0x20a4cc
movq 0x30(%r15), %rax
movq 0x48(%rax), %rax
movl (%rax,%r14,8), %edx
jmp 0x20a4ea
movq 0x18(%r15), %rdx
movq 0x10(%rdx), %rdx
shlq $0x3, %rax
leaq (%rax,%rax,4), %rax
subq %rax, %rdx
movl (%rdx,%r13), %edx
movl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
andl %eax, %edx
movq %rbx, %rdi
movl %r12d, %esi
callq 0xa0887
movq 0x20(%rbx), %rax
movb $0x0, 0x4(%rax,%r12,8)
incq %r12
movq 0x218(%r15), %rax
addq $0x28, %r13
addq $0xb, %r14
cmpq %rax, %r12
jb 0x20a484
testq %rax, %rax
je 0x20aa00
movq 0x208(%r15), %rax
xorl %r12d, %r12d
movq %rax, %rdx
cmpq %rdx, %r12
movl $0x0, %ecx
cmovaeq %rdx, %rcx
movq %r12, %rsi
subq %rcx, %rsi
addq %rax, %rsi
cmpq %rdx, %r12
cmovaeq %rax, %rdx
cmovbq %r12, %rsi
movq 0x220(%r15), %rcx
movl (%rcx,%rsi,4), %ecx
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
cmpq %rsi, %rcx
je 0x20a9f0
movq 0x1f0(%r15), %rbp
testq %rbp, %rbp
je 0x20a9f0
shlq $0x5, %rcx
addq %rcx, %rbp
cmpl $0x0, 0x18(%rbp)
js 0x20a9f0
cmpq $0x0, 0x8(%rbp)
je 0x20a708
xorl %r13d, %r13d
xorl %r14d, %r14d
movq (%rbp), %rdi
cmpb $0x3f, 0x24(%rdi,%r13)
ja 0x20a6f7
movq 0x208(%r15), %rsi
movq %r12, %rax
subq %rsi, %rax
jae 0x20a5cb
movq 0x30(%r15), %rax
movq 0x48(%rax), %rax
imulq $0x58, %r12, %rcx
movl 0x18(%rax,%rcx), %edx
jmp 0x20a5e1
movq 0x18(%r15), %rcx
movq 0x10(%rcx), %rcx
leaq (%rax,%rax,4), %rax
movl (%rcx,%rax,8), %edx
movl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
andl %eax, %edx
addq %r13, %rdi
movl (%rdi), %eax
movq %rax, %rcx
subq %rsi, %rcx
jae 0x20a601
movq 0x30(%r15), %rcx
movq 0x48(%rcx), %rcx
imulq $0x58, %rax, %r8
movl 0x18(%rcx,%r8), %r9d
jmp 0x20a619
movq 0x18(%r15), %r8
movq 0x10(%r8), %r8
leaq (%rcx,%rcx,4), %rcx
movl (%r8,%rcx,8), %r9d
movl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
andl %ecx, %r9d
movl $0x1, %r8d
movl $0x1, %ecx
cmpq %rsi, %r12
jae 0x20a642
movq 0x1d0(%r15), %rcx
movq %r12, %r10
shlq $0x5, %r10
movl 0x18(%rcx,%r10), %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
cmpq %rsi, %rax
jae 0x20a661
movq 0x1d0(%r15), %rsi
movq %rax, %r8
shlq $0x5, %r8
movl 0x18(%rsi,%r8), %r8d
andl $0x7fffffff, %r8d       # imm = 0x7FFFFFFF
movl %edx, %esi
movl %r9d, %edx
subq $0x8, %rsp
movq %r12, %r9
leaq 0x18(%rsp), %r10
pushq %r10
pushq 0x18(%rsp)
pushq %rax
callq 0x207372
addq $0x20, %rsp
testl %eax, %eax
js 0x20a6f7
movl 0x4(%rbx), %edx
movl %edx, %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
cmpl (%rbx), %ecx
jne 0x20a6c6
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 0x20a6ca
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 0x20(%rsp), %rdx
movq %rdx, 0x10(%rax,%rcx,8)
movups 0x10(%rsp), %xmm0
movups %xmm0, (%rax,%rcx,8)
incq %r14
addq $0x28, %r13
cmpq 0x8(%rbp), %r14
jb 0x20a59a
movq 0x208(%r15), %rcx
movq %r12, %rdx
subq %rcx, %rdx
jb 0x20a9ea
movq (%rsp), %rsi
movq 0x8(%rsi), %rax
movq 0x28(%rsi), %rsi
movq %rdx, %rdi
shlq $0x4, %rdi
movq (%rsi,%rdi), %rdi
movq %rdi, %r8
movl $0xffffffff, %r9d       # imm = 0xFFFFFFFF
andq %r9, %r8
je 0x20a892
shrq $0x20, %rdi
shlq $0x3, %r8
leaq (%r8,%r8,2), %r14
leaq (%rdi,%rdi,2), %rcx
leaq (%rax,%rcx,8), %r13
addq $0xc, %r13
xorl %ebp, %ebp
cmpl $0x0, (%r13,%rbp)
js 0x20a86c
movl -0x4(%r13,%rbp), %eax
shrl %eax
movq 0x208(%r15), %rcx
movq 0x220(%r15), %rdx
addq %rcx, %rax
movabsq $0x7fffffffffffffff, %rsi # imm = 0x7FFFFFFFFFFFFFFF
andq %rsi, %rax
cmpq %rcx, %rax
movl $0x0, %esi
cmovaeq %rcx, %rsi
movq %rax, %rdi
subq %rsi, %rdi
addq %rcx, %rdi
cmpq %rcx, %rax
cmovbq %rax, %rdi
movl (%rdx,%rdi,4), %eax
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
cmpq %rcx, %rax
je 0x20a86c
movq 0x1f0(%r15), %rcx
testq %rcx, %rcx
je 0x20a86c
shlq $0x5, %rax
cmpl $0x0, 0x18(%rcx,%rax)
js 0x20a86c
movl 0x4(%rbx), %edx
movl %edx, %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
cmpl (%rbx), %ecx
jne 0x20a81b
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 0x20a81f
movq 0x8(%rbx), %rax
leaq -0xc(,%rbp), %rsi
addq %r13, %rsi
leal 0x1(%rdx), %edi
andl $0x7fffffff, %edi       # imm = 0x7FFFFFFF
andl $0x80000000, %edx       # imm = 0x80000000
orl %edi, %edx
movl %edx, 0x4(%rbx)
movl %ecx, %ecx
leaq (%rcx,%rcx,2), %rcx
movq 0x10(%rsi), %rdx
movq %rdx, 0x10(%rax,%rcx,8)
movups (%rsi), %xmm0
movups %xmm0, (%rax,%rcx,8)
movq 0x208(%r15), %rdx
movq %rdx, %rsi
shlq $0x21, %rsi
addq %rsi, (%rax,%rcx,8)
addl %edx, %edx
addl %edx, 0x8(%rax,%rcx,8)
addq $0x18, %rbp
cmpq %rbp, %r14
jne 0x20a75e
movq 0x208(%r15), %rcx
movq (%rsp), %rdx
movq 0x8(%rdx), %rax
movq 0x28(%rdx), %rsi
movq %r12, %rdx
subq %rcx, %rdx
shlq $0x4, %rdx
movq 0x8(%rsi,%rdx), %rdx
movq %rdx, %rsi
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
andq %rdi, %rsi
je 0x20a9ea
shrq $0x20, %rdx
shlq $0x3, %rsi
leaq (%rsi,%rsi,2), %r14
leaq (%rdx,%rdx,2), %rdx
leaq (%rax,%rdx,8), %r13
addq $0xc, %r13
xorl %ebp, %ebp
movq %rcx, %rax
cmpl $0x0, (%r13,%rbp)
js 0x20a9d8
movl -0x4(%r13,%rbp), %edx
shrl %edx
addq %rax, %rdx
movabsq $0x7fffffffffffffff, %rsi # imm = 0x7FFFFFFFFFFFFFFF
andq %rsi, %rdx
cmpq %rax, %rdx
jb 0x20a8f6
movq %rax, %rsi
jmp 0x20a8f8
xorl %esi, %esi
movq %rdx, %rdi
subq %rsi, %rdi
addq %rcx, %rdi
cmpq %rax, %rdx
cmovaeq %rcx, %rax
cmovbq %rdx, %rdi
movq 0x220(%r15), %rdx
movl (%rdx,%rdi,4), %edx
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
cmpq %rsi, %rdx
je 0x20a9d8
movq 0x1f0(%r15), %rsi
testq %rsi, %rsi
je 0x20a9d8
shlq $0x5, %rdx
cmpl $0x0, 0x18(%rsi,%rdx)
js 0x20a9d8
movl 0x4(%rbx), %edx
movl %edx, %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
cmpl (%rbx), %ecx
jne 0x20a983
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 0x20a987
movq 0x8(%rbx), %rax
leaq -0xc(,%rbp), %rsi
addq %r13, %rsi
leal 0x1(%rdx), %edi
andl $0x7fffffff, %edi       # imm = 0x7FFFFFFF
andl $0x80000000, %edx       # imm = 0x80000000
orl %edi, %edx
movl %edx, 0x4(%rbx)
movl %ecx, %ecx
leaq (%rcx,%rcx,2), %rdx
movq 0x10(%rsi), %rcx
movq %rcx, 0x10(%rax,%rdx,8)
movups (%rsi), %xmm0
movups %xmm0, (%rax,%rdx,8)
movq 0x208(%r15), %rcx
movq %rcx, %rsi
shlq $0x21, %rsi
addq %rsi, (%rax,%rdx,8)
leal (%rcx,%rcx), %esi
addl %esi, 0x8(%rax,%rdx,8)
movq %rcx, %rax
addq $0x18, %rbp
movq %rax, %rdx
cmpq %rbp, %r14
jne 0x20a8c9
jmp 0x20a9f0
movq %rcx, %rax
movq %rcx, %rdx
incq %r12
cmpq 0x218(%r15), %r12
jb 0x20a530
movq %rbx, %rdi
callq 0xa0a7d
movl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
andl 0x14(%rbx), %eax
movl %eax, 0x18(%rbx)
movq %rbx, %rax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq