// File: /workspace/github_cpp_makefile_star2_O1/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 0x9fccc
movq %rax, %rbx
cmpq $0x0, 0x218(%r15)
je 0x1fee4f
movl $0x3, %r14d
xorl %r13d, %r13d
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
xorl %r12d, %r12d
movq 0x208(%r15), %rax
movq %r12, %rcx
subq %rax, %rcx
cmovbq %r12, %rcx
jb 0x1fedc1
addq 0x208(%r15), %rcx
movq 0x220(%r15), %rdx
movl (%rdx,%rcx,4), %edx
cmpq %rbp, %rdx
je 0x1feddd
shlq $0x5, %rdx
addq 0x1f0(%r15), %rdx
jmp 0x1feddf
xorl %edx, %edx
testq %rdx, %rdx
je 0x1fedec
xorl %ecx, %ecx
cmpl $0x0, 0x18(%rdx)
jns 0x1fedf1
movl $0x1, %ecx
cmpq %rax, %r12
jae 0x1fee04
movq 0x30(%r15), %rax
movq 0x48(%rax), %rax
movl (%rax,%r14,8), %edx
jmp 0x1fee22
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 0xa0115
movq 0x20(%rbx), %rax
movb $0x0, 0x4(%rax,%r12,8)
incq %r12
addq $0x28, %r13
addq $0xb, %r14
cmpq 0x218(%r15), %r12
jb 0x1feda7
cmpq $0x0, 0x218(%r15)
je 0x1ff326
xorl %r12d, %r12d
movq 0x208(%r15), %rcx
cmpq %rcx, %r12
movl $0x0, %edx
cmovaeq %rcx, %rdx
movq %r12, %rax
subq %rdx, %rax
cmpq %rcx, %r12
jb 0x1fee85
addq 0x208(%r15), %rax
movq 0x220(%r15), %rcx
movl (%rcx,%rax,4), %r13d
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmpq %rax, %r13
je 0x1feea7
shlq $0x5, %r13
addq 0x1f0(%r15), %r13
jmp 0x1feeaa
xorl %r13d, %r13d
testq %r13, %r13
je 0x1ff316
cmpl $0x0, 0x18(%r13)
js 0x1ff316
cmpq $0x0, 0x8(%r13)
je 0x1ff039
xorl %r14d, %r14d
xorl %ebp, %ebp
movq (%r13), %rdi
cmpb $0x3f, 0x24(%rdi,%r14)
ja 0x1ff028
movq 0x208(%r15), %rsi
movq %r12, %rax
subq %rsi, %rax
jae 0x1feeff
movq 0x30(%r15), %rax
movq 0x48(%rax), %rax
imulq $0x58, %r12, %rcx
movl 0x18(%rax,%rcx), %edx
jmp 0x1fef15
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 %r14, %rdi
movl (%rdi), %eax
movq %rax, %rcx
subq %rsi, %rcx
jae 0x1fef35
movq 0x30(%r15), %rcx
movq 0x48(%rcx), %rcx
imulq $0x58, %rax, %r8
movl 0x18(%rcx,%r8), %r9d
jmp 0x1fef4d
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 0x1fef76
movq 0x1d0(%r15), %rcx
movq %r12, %r10
shlq $0x5, %r10
movl 0x18(%rcx,%r10), %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
cmpq %rsi, %rax
jae 0x1fef95
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 0x1fbca4
addq $0x20, %rsp
testl %eax, %eax
js 0x1ff028
movl 0x4(%rbx), %ecx
movl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
andl %eax, %ecx
movl (%rbx), %eax
cmpl %eax, %ecx
jne 0x1fefee
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 %rbp
addq $0x28, %r14
cmpq 0x8(%r13), %rbp
jb 0x1feece
movq %r12, %rax
subq 0x208(%r15), %rax
movabsq $0x7fffffffffffffff, %rdi # imm = 0x7FFFFFFFFFFFFFFF
jb 0x1ff316
movq (%rsp), %rcx
movq 0x28(%rcx), %rcx
shlq $0x4, %rax
movq (%rcx,%rax), %rax
movq %rax, %rcx
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
andq %rdx, %rcx
je 0x1ff1af
movq (%rsp), %rdx
movq 0x8(%rdx), %rdx
shrq $0x20, %rax
shlq $0x3, %rcx
leaq (%rcx,%rcx,2), %r14
leaq (%rax,%rax,2), %rax
leaq (%rdx,%rax,8), %r13
addq $0xc, %r13
xorl %ebp, %ebp
cmpl $0x0, (%r13,%rbp)
js 0x1ff1a2
movl -0x4(%r13,%rbp), %ecx
movq 0x208(%r15), %rdx
shrl %ecx
addq %rdx, %rcx
andq %rdi, %rcx
cmpq %rdx, %rcx
movl $0x0, %esi
cmovaeq %rdx, %rsi
movq %rcx, %rax
subq %rsi, %rax
cmpq %rdx, %rcx
jb 0x1ff0d4
addq 0x208(%r15), %rax
movq 0x220(%r15), %rcx
movl (%rcx,%rax,4), %eax
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
cmpq %rcx, %rax
je 0x1ff0f5
shlq $0x5, %rax
addq 0x1f0(%r15), %rax
jmp 0x1ff0f7
xorl %eax, %eax
testq %rax, %rax
je 0x1ff1a2
cmpl $0x0, 0x18(%rax)
js 0x1ff1a2
movl 0x4(%rbx), %ecx
movl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
andl %eax, %ecx
movl (%rbx), %eax
cmpl %eax, %ecx
jne 0x1ff13e
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)
leaq -0xc(,%rbp), %rax
addq %r13, %rax
movq 0x8(%rbx), %rcx
movl 0x4(%rbx), %edx
movl %edx, %esi
andl $0x7fffffff, %esi       # imm = 0x7FFFFFFF
leal 0x1(%rdx), %edi
andl $0x7fffffff, %edi       # imm = 0x7FFFFFFF
andl $0x80000000, %edx       # imm = 0x80000000
orl %edi, %edx
movl %edx, 0x4(%rbx)
leaq (%rsi,%rsi,2), %rdx
movq 0x10(%rax), %rsi
movq %rsi, 0x10(%rcx,%rdx,8)
movups (%rax), %xmm0
movups %xmm0, (%rcx,%rdx,8)
movq 0x208(%r15), %rax
movq %rax, %rsi
shlq $0x21, %rsi
addq %rsi, (%rcx,%rdx,8)
addl %eax, %eax
addl %eax, 0x8(%rcx,%rdx,8)
movabsq $0x7fffffffffffffff, %rdi # imm = 0x7FFFFFFFFFFFFFFF
addq $0x18, %rbp
cmpq %rbp, %r14
jne 0x1ff096
movq %r12, %rax
subq 0x208(%r15), %rax
shlq $0x4, %rax
movq (%rsp), %rcx
movq 0x28(%rcx), %rcx
movq 0x8(%rcx,%rax), %rax
movq %rax, %rcx
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
andq %rdx, %rcx
je 0x1ff316
movq (%rsp), %rdx
movq 0x8(%rdx), %rdx
shrq $0x20, %rax
shlq $0x3, %rcx
leaq (%rcx,%rcx,2), %r14
leaq (%rax,%rax,2), %rax
leaq (%rdx,%rax,8), %r13
addq $0xc, %r13
xorl %ebp, %ebp
cmpl $0x0, (%r13,%rbp)
js 0x1ff309
movl -0x4(%r13,%rbp), %ecx
movq 0x208(%r15), %rdx
shrl %ecx
addq %rdx, %rcx
andq %rdi, %rcx
cmpq %rdx, %rcx
movl $0x0, %esi
cmovaeq %rdx, %rsi
movq %rcx, %rax
subq %rsi, %rax
cmpq %rdx, %rcx
jb 0x1ff23b
addq 0x208(%r15), %rax
movq 0x220(%r15), %rcx
movl (%rcx,%rax,4), %eax
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
cmpq %rcx, %rax
je 0x1ff25c
shlq $0x5, %rax
addq 0x1f0(%r15), %rax
jmp 0x1ff25e
xorl %eax, %eax
testq %rax, %rax
je 0x1ff309
cmpl $0x0, 0x18(%rax)
js 0x1ff309
movl 0x4(%rbx), %ecx
movl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
andl %eax, %ecx
movl (%rbx), %eax
cmpl %eax, %ecx
jne 0x1ff2a5
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)
leaq -0xc(,%rbp), %rax
addq %r13, %rax
movq 0x8(%rbx), %rcx
movl 0x4(%rbx), %edx
movl %edx, %esi
andl $0x7fffffff, %esi       # imm = 0x7FFFFFFF
leal 0x1(%rdx), %edi
andl $0x7fffffff, %edi       # imm = 0x7FFFFFFF
andl $0x80000000, %edx       # imm = 0x80000000
orl %edi, %edx
movl %edx, 0x4(%rbx)
leaq (%rsi,%rsi,2), %rdx
movq 0x10(%rax), %rsi
movq %rsi, 0x10(%rcx,%rdx,8)
movups (%rax), %xmm0
movups %xmm0, (%rcx,%rdx,8)
movq 0x208(%r15), %rax
movq %rax, %rsi
shlq $0x21, %rsi
addq %rsi, (%rcx,%rdx,8)
addl %eax, %eax
addl %eax, 0x8(%rcx,%rdx,8)
movabsq $0x7fffffffffffffff, %rdi # imm = 0x7FFFFFFFFFFFFFFF
addq $0x18, %rbp
cmpq %rbp, %r14
jne 0x1ff1fd
incq %r12
cmpq 0x218(%r15), %r12
jb 0x1fee60
movq %rbx, %rdi
callq 0xa02fa
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