// File: /workspace/github_cpp_makefile_star2_O2/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 $0x38, %rsp
movq %rsi, 0x18(%rsp)
movq %rdi, %r14
leaq 0x1f0(%rdi), %rax
movq %rax, 0x8(%rsp)
movq 0x18(%rdi), %rax
movq 0x18(%rax), %rax
movq %rax, 0x10(%rsp)
pushq $0x3
popq %rbx
xorl %r15d, %r15d
callq 0x68f5d
movq %rax, (%rsp)
pushq $0x1
popq %rbp
xorl %r13d, %r13d
movq 0x218(%r14), %rax
cmpq %rax, %r13
jae 0x1be1c0
movq 0x208(%r14), %r12
xorl %edx, %edx
movq %r13, %rsi
subq %r12, %rsi
setb %dl
cmovbq %r13, %rsi
movq 0x8(%rsp), %rdi
callq 0x1ba426
testq %rax, %rax
je 0x1be16b
xorl %ecx, %ecx
cmpl $0x0, 0x18(%rax)
jns 0x1be16d
movl %ebp, %ecx
cmpq %r12, %r13
jae 0x1be17f
movq 0x30(%r14), %rax
movq 0x48(%rax), %rax
movl (%rax,%rbx,8), %edx
jmp 0x1be196
movq 0x18(%r14), %rax
imulq $-0x28, %r12, %rdx
addq 0x10(%rax), %rdx
movl (%r15,%rdx), %edx
movl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
andl %eax, %edx
movq (%rsp), %r12
movq %r12, %rdi
movl %r13d, %esi
callq 0x69316
movq 0x20(%r12), %rax
movb $0x0, 0x4(%rax,%r13,8)
incq %r13
addq $0xb, %rbx
addq $0x28, %r15
jmp 0x1be12e
xorl %r13d, %r13d
cmpq %rax, %r13
jae 0x1be4d1
movq 0x208(%r14), %rax
xorl %edx, %edx
cmpq %rax, %r13
setb %dl
movl $0x0, %ecx
cmovaeq %rax, %rcx
movq %r13, %rsi
subq %rcx, %rsi
movq 0x8(%rsp), %rdi
callq 0x1ba426
testq %rax, %rax
je 0x1be337
movq %rax, %rbp
cmpl $0x0, 0x18(%rax)
js 0x1be337
imulq $0x58, %r13, %rbx
xorl %r15d, %r15d
xorl %r12d, %r12d
cmpq 0x8(%rbp), %r12
jae 0x1be328
movq (%rbp), %rdi
cmpb $0x3f, 0x24(%rdi,%r15)
ja 0x1be31c
movq 0x208(%r14), %rsi
movq %r13, %rax
subq %rsi, %rax
jae 0x1be24b
movq 0x30(%r14), %rax
movq 0x48(%rax), %rax
movl 0x18(%rax,%rbx), %edx
jmp 0x1be261
movq 0x18(%r14), %rcx
movq 0x10(%rcx), %rcx
imulq $0x28, %rax, %rax
movl (%rcx,%rax), %edx
movl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
andl %eax, %edx
addq %r15, %rdi
movl (%rdi), %eax
movq %rax, %rcx
subq %rsi, %rcx
jae 0x1be281
movq 0x30(%r14), %rcx
movq 0x48(%rcx), %rcx
imulq $0x58, %rax, %r8
movl 0x18(%rcx,%r8), %r9d
jmp 0x1be299
movq 0x18(%r14), %r8
movq 0x10(%r8), %r8
imulq $0x28, %rcx, %rcx
movl (%r8,%rcx), %r9d
movl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
andl %ecx, %r9d
pushq $0x1
popq %rcx
cmpq %rsi, %r13
jae 0x1be2ba
movq 0x1d0(%r14), %rcx
movq %r13, %r8
shlq $0x5, %r8
movl 0x18(%rcx,%r8), %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
pushq $0x1
popq %r8
cmpq %rsi, %rax
jae 0x1be2dd
movq 0x1d0(%r14), %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 %r13, %r9
leaq 0x28(%rsp), %r10
pushq %r10
pushq 0x28(%rsp)
pushq %rax
callq 0x1bb0f9
addq $0x20, %rsp
testl %eax, %eax
js 0x1be31c
movq (%rsp), %rdi
callq 0x1ab555
movups 0x20(%rsp), %xmm0
movups %xmm0, (%rax)
movq 0x30(%rsp), %rcx
movq %rcx, 0x10(%rax)
incq %r12
addq $0x28, %r15
jmp 0x1be214
movq 0x208(%r14), %rbp
movq %r13, %rax
subq %rbp, %rax
jae 0x1be346
incq %r13
movq 0x218(%r14), %rax
jmp 0x1be1c3
movq 0x10(%rsp), %rdx
movq 0x8(%rdx), %rcx
movq 0x28(%rdx), %rdx
shlq $0x4, %rax
movq (%rdx,%rax), %rax
movl %eax, %edx
shrq $0x20, %rax
imulq $0x18, %rdx, %rbx
imulq $0x18, %rax, %rax
leaq (%rcx,%rax), %r15
addq $0xc, %r15
xorl %r12d, %r12d
cmpq %r12, %rbx
je 0x1be408
cmpl $0x0, (%r15,%r12)
js 0x1be3ff
movl -0x4(%r15,%r12), %esi
shrl %esi
addq %rbp, %rsi
movabsq $0x7fffffffffffffff, %rax # imm = 0x7FFFFFFFFFFFFFFF
andq %rax, %rsi
xorl %edx, %edx
cmpq %rbp, %rsi
setb %dl
movl $0x0, %eax
cmovaeq %rbp, %rax
subq %rax, %rsi
movq 0x8(%rsp), %rdi
callq 0x1ba426
testq %rax, %rax
je 0x1be3ff
cmpl $0x0, 0x18(%rax)
js 0x1be3ff
leaq (%r15,%r12), %rbp
addq $-0xc, %rbp
movq (%rsp), %rdi
callq 0x1ab555
movq 0x10(%rbp), %rcx
movq %rcx, 0x10(%rax)
movups (%rbp), %xmm0
movups %xmm0, (%rax)
movq 0x208(%r14), %rbp
movq %rbp, %rcx
shlq $0x21, %rcx
addq %rcx, (%rax)
leal (,%rbp,2), %ecx
addl %ecx, 0x8(%rax)
addq $0x18, %r12
jmp 0x1be374
movq %r13, %rax
subq %rbp, %rax
shlq $0x4, %rax
movq 0x10(%rsp), %rdx
movq 0x8(%rdx), %rcx
movq 0x28(%rdx), %rdx
movq 0x8(%rdx,%rax), %rax
movl %eax, %edx
shrq $0x20, %rax
imulq $0x18, %rdx, %rbx
imulq $0x18, %rax, %rax
leaq (%rcx,%rax), %r15
addq $0xc, %r15
xorl %r12d, %r12d
cmpq %r12, %rbx
je 0x1be337
cmpl $0x0, (%r15,%r12)
js 0x1be4c8
movl -0x4(%r15,%r12), %esi
shrl %esi
addq %rbp, %rsi
movabsq $0x7fffffffffffffff, %rax # imm = 0x7FFFFFFFFFFFFFFF
andq %rax, %rsi
xorl %edx, %edx
cmpq %rbp, %rsi
setb %dl
movl $0x0, %eax
cmovaeq %rbp, %rax
subq %rax, %rsi
movq 0x8(%rsp), %rdi
callq 0x1ba426
testq %rax, %rax
je 0x1be4c8
cmpl $0x0, 0x18(%rax)
js 0x1be4c8
leaq (%r15,%r12), %rbp
addq $-0xc, %rbp
movq (%rsp), %rdi
callq 0x1ab555
movq 0x10(%rbp), %rcx
movq %rcx, 0x10(%rax)
movups (%rbp), %xmm0
movups %xmm0, (%rax)
movq 0x208(%r14), %rbp
movq %rbp, %rcx
shlq $0x21, %rcx
addq %rcx, (%rax)
leal (,%rbp,2), %ecx
addl %ecx, 0x8(%rax)
addq $0x18, %r12
jmp 0x1be43d
movq (%rsp), %rbx
movq %rbx, %rdi
callq 0x694eb
movl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
andl 0x14(%rbx), %eax
movl %eax, 0x18(%rbx)
movq %rbx, %rax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq