// File: /workspace/github_cpp_makefile_star2_O3/chhylp123[P]hifiasm/gfa_ut.cpp
// Function: gen_ug_integer_seq_on_fly(ul_resolve_t*, unsigned long*, unsigned long, asg64_v*)
uint64_t gen_ug_integer_seq_on_fly(ul_resolve_t *uidx, uint64_t *u_a, uint64_t u_n, asg64_v *res)
{
    ul2ul_idx_t *idx = &(uidx->uovl); ma_ug_t *raw = uidx->l1_ug;
    uint64_t k, rn = res->n, nn, u_rev, uv, uw, bv, bw, is_bv_ul, is_bw_ul, x; int64_t z, zn;
    ma_ug_t *iug = idx->i_ug; uinfo_srt_warp_t *seq; ul2ul_t *m;
    for (k = 0; k < u_n; k++) {
        seq = &(idx->cc.iug_a[u_a[k]>>1]); u_rev = u_a[k]&1;
        // if(u_n == 6 && u_a[0] == 37683 && u_a[5] == 45894) {
        //     fprintf(stderr, "\n[M::%s::] k::%lu, u_a[k]>>1::%lu, u_a[k]&1::%lu\n", __func__, k, u_a[k]>>1, u_a[k]&1);
        //     for (z = 0, zn = seq->n; z < zn; z++) {
        //         fprintf(stderr, "[M::%s::] v>>1::%u, v&1::%u\n", __func__, seq->a[z].v>>1, seq->a[z].v&1);
        //     }
        // }
        if(k > 0) {
            uv = u_a[k-1]; uw = u_a[k];
            bv = iug->u.a[uv>>1].a[((uv&1)?(0):(iug->u.a[uv>>1].n-1))]>>32; if(uv&1) bv ^= 1; //pre
            bw = iug->u.a[uw>>1].a[((uw&1)?(iug->u.a[uw>>1].n-1):(0))]>>32; if(uw&1) bw ^= 1; //current
            is_bv_ul = ulg_type((*idx), (bv>>1)); is_bw_ul = ulg_type((*idx), (bw>>1)); 
            if(is_bw_ul) {
                m = get_ul_spec_ovlp(idx, bv>>1, bw>>1);
                assert(m && (!m->is_del));
                nn = res->n + seq->n - (m->te_k - m->ts_k); 
                kv_resize(uint64_t, *res, nn); 
                nn = m->te_k - m->ts_k; ///skipped length
                zn = seq->n; 
                // fprintf(stderr, "[M::%s::] bv>>1::%lu, bv&1::%lu, bw>>1::%lu, bw&1::%lu, m->qs_k::%u, m->qe_k::%u, m->ts_k::%u, m->te_k::%u\n", __func__, 
                // bv>>1, bv&1, bw>>1, bw&1, m->qs_k, m->qe_k, m->ts_k, m->te_k);
                if(!u_rev) {
                    ///debug
                    for (z = 0; z < ((int64_t)nn); z++) {
                        // if(res->a[res->n-nn+z] != seq->a[z].v) {
                        //     fprintf(stderr, "****[M::%s::] k::%lu, z::%ld, nn::%lu, res->n::%u, res->v>>1::%lu, res->v&1::%lu, seq->a[z].v>>1::%u, seq->a[z].v&1::%u\n", 
                        //     __func__, k, z, nn, (uint32_t)res->n, res->a[res->n-nn+z]>>1, res->a[res->n-nn+z]&1, seq->a[z].v>>1, seq->a[z].v&1);
                        // }
                        assert(res->a[res->n-nn+z] == seq->a[z].v);
                    }

                    for (z = nn; z < zn; z++) {
                        res->a[res->n++] = seq->a[z].v;
                    }
                } else {
                    ///debug
                    for (z = zn - 1; z >= zn - ((int64_t)nn); z--) {
                        // fprintf(stderr, "[M::%s::z->%ld::idx->%ld] nn::%lu, zn::%ld, res->n::%ld, res>>1::%lu, res&1::%lu, seq>>1::%u, seq&1::%u\n", 
                        // __func__, z, (int64_t)(res->n-nn+(zn-1-z)), nn, zn, (int64_t)(res->n), res->a[res->n-nn+(zn-1-z)]>>1, res->a[res->n-nn+(zn-1-z)]&1, seq->a[z].v>>1, seq->a[z].v&1);
                        assert(res->a[res->n-nn+(zn-1-z)] == (seq->a[z].v^1));
                    }

                    for (z = zn - 1 - ((int64_t)nn); z >= 0; z--) {
                        res->a[res->n++] = seq->a[z].v^1;
                    }
                }
            } else {
                x = ulg_id(uidx->uovl, (bw>>1)); x <<= 1; x += (bw&1);
                if(!is_bv_ul) {///if previous ul is also a raw utg node
                    assert(get_specfic_edge(raw->g, res->a[res->n-1], x));
                } else {
                    // assert(((res->a[res->n-1].v) == x));
                    if(((res->a[res->n-1]) == x)) {
                        res->n--;
                    } else {
                        assert(get_specfic_edge(raw->g, res->a[res->n-1], x));
                    }
                }
                nn = res->n + seq->n; zn = seq->n;
                kv_resize(uint64_t, *res, nn);
                if(!u_rev) {
                    for (z = 0; z < zn; z++) {
                        res->a[res->n++] = seq->a[z].v;
                    }
                } else {
                    for (z = zn - 1; z >= 0; z--) {
                        res->a[res->n++] = seq->a[z].v^1;
                    }
                }
            }
        } else {
            nn = res->n + seq->n; zn = seq->n;
            kv_resize(uint64_t, *res, nn);
            if(!u_rev) {
                for (z = 0; z < zn; z++) {
                    // fprintf(stderr, ">+<[M::%s::res->n->%ld] a>>1::%u, a&1::%u\n", 
                    //     __func__, (int64_t)res->n, seq->a[z].v>>1, seq->a[z].v&1);
                    res->a[res->n++] = seq->a[z].v;
                }
            } else {
                for (z = zn - 1; z >= 0; z--) {
                    // fprintf(stderr, ">-<[M::%s::res->n->%ld] a>>1::%u, a&1::%u\n", 
                    //     __func__, (int64_t)res->n, seq->a[z].v>>1, (seq->a[z].v^1)&1);
                    res->a[res->n++] = seq->a[z].v^1;
                }
            }
        }
    }
    
    return res->n - rn;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rcx, %rbx
movq (%rcx), %rcx
movq %rcx, %rax
testq %rdx, %rdx
je 0x20ea51
movq %rdx, %r12
movq %rsi, %r10
movq %rdi, %r11
movq %rcx, 0x28(%rsp)
movq 0x230(%rdi), %rax
movq %rax, 0x30(%rsp)
movq 0x18(%rdi), %rax
movq %rax, 0x18(%rsp)
xorl %r13d, %r13d
movq %rsi, 0x10(%rsp)
movq %rdi, 0x8(%rsp)
movq %rdx, 0x20(%rsp)
movq (%r10,%r13,8), %r14
movq %r14, %rdx
shrq %rdx
leaq (%rdx,%rdx,2), %rbp
shlq $0x3, %rbp
addq 0x260(%r11), %rbp
testq %r13, %r13
je 0x20e510
movq -0x8(%r10,%r13,8), %rsi
movq 0x30(%rsp), %rax
movq 0x10(%rax), %rax
movq %rsi, %rcx
shrq %rcx
leaq (%rcx,%rcx,4), %rcx
testb $0x1, %sil
jne 0x20e5b4
leaq (%rax,%rcx,8), %rsi
movl 0x10(%rsi), %esi
decl %esi
jmp 0x20e5b6
movq (%rbp), %r15
movq (%rbx), %rax
addq %r15, %rax
cmpq %rax, 0x8(%rbx)
jae 0x20e57b
decq %rax
movq %rax, %rcx
shrq %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x2, %rax
orq %rcx, %rax
movq %rax, %rcx
shrq $0x4, %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x8, %rax
orq %rcx, %rax
movq %rax, %rcx
shrq $0x10, %rcx
orq %rax, %rcx
leaq 0x1(%rcx), %rax
movq %rax, 0x8(%rbx)
movq 0x10(%rbx), %rdi
leaq 0x8(,%rcx,8), %rsi
callq 0x2370
movq 0x8(%rsp), %r11
movq 0x10(%rsp), %r10
movq %rax, 0x10(%rbx)
testb $0x1, %r14b
jne 0x20e83b
testq %r15, %r15
jle 0x20e9c1
movq 0x10(%rbp), %rax
movq 0x10(%rbx), %rcx
movl (%rax), %edx
movq (%rbx), %rsi
leaq 0x1(%rsi), %rdi
movq %rdi, (%rbx)
movq %rdx, (%rcx,%rsi,8)
addq $0x10, %rax
decq %r15
jne 0x20e596
jmp 0x20e9c1
xorl %esi, %esi
leaq (%rdx,%rdx,4), %rdx
testb $0x1, %r14b
jne 0x20e5c4
xorl %edi, %edi
jmp 0x20e5cd
leaq (%rax,%rdx,8), %rdi
movl 0x10(%rdi), %edi
decl %edi
movq 0x18(%rax,%rcx,8), %rcx
movq (%rcx,%rsi,8), %rcx
shrq $0x21, %rcx
movq 0x18(%rax,%rdx,8), %rax
movq (%rax,%rdi,8), %rdx
movq 0x208(%r11), %rsi
movq %rdx, %rax
shrq $0x21, %rax
movq %rax, %rdi
subq %rsi, %rdi
jae 0x20e652
movq 0x220(%r11), %rdx
movl (%rdx,%rcx,4), %ecx
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
cmpq %rdx, %rcx
je 0x20ea63
movq 0x1f0(%r11), %rdx
shlq $0x5, %rcx
movl 0x1c(%rdx,%rcx), %esi
testq %rsi, %rsi
je 0x20ea63
addq %rcx, %rdx
movq (%rdx), %r15
shlq $0x3, %rsi
leaq (%rsi,%rsi,4), %rcx
xorl %r12d, %r12d
cmpl (%r15,%r12), %eax
je 0x20e720
addq $0x28, %r12
cmpq %r12, %rcx
jne 0x20e63a
jmp 0x20ea63
shrq $0x20, %rdx
xorl %r14d, %edx
andl $0x1, %edx
leaq (%rdx,%rdi,2), %rdx
cmpq %rsi, %rcx
jae 0x20e881
movq (%rbx), %rcx
movq 0x10(%rbx), %rax
movq -0x8(%rax,%rcx,8), %rdi
cmpq %rdx, %rdi
jne 0x20e9cf
decq %rcx
movq %rcx, (%rbx)
movq (%rbp), %r15
addq %r15, %rcx
cmpq %rcx, 0x8(%rbx)
jae 0x20e6eb
decq %rcx
movq %rcx, %rdx
shrq %rdx
orq %rcx, %rdx
movq %rdx, %rcx
shrq $0x2, %rcx
orq %rdx, %rcx
movq %rcx, %rdx
shrq $0x4, %rdx
orq %rcx, %rdx
movq %rdx, %rcx
shrq $0x8, %rcx
orq %rdx, %rcx
movq %rcx, %rdx
shrq $0x10, %rdx
orq %rcx, %rdx
leaq 0x1(%rdx), %rcx
movq %rcx, 0x8(%rbx)
leaq 0x8(,%rdx,8), %rsi
movq %rax, %rdi
callq 0x2370
movq 0x8(%rsp), %r11
movq 0x10(%rsp), %r10
movq %rax, 0x10(%rbx)
testb $0x1, %r14b
jne 0x20e988
testq %r15, %r15
jle 0x20e9c1
movq 0x10(%rbp), %rcx
movl (%rcx), %edx
movq (%rbx), %rsi
leaq 0x1(%rsi), %rdi
movq %rdi, (%rbx)
movq %rdx, (%rax,%rsi,8)
addq $0x10, %rcx
decq %r15
jne 0x20e702
jmp 0x20e9c1
testb $0x40, 0x24(%r15,%r12)
jne 0x20ea63
movq (%rbp), %rax
movq (%rbx), %rdi
addq %rax, %rdi
movl 0x1c(%r15,%r12), %edx
movl 0x20(%r15,%r12), %esi
movl %esi, %ecx
subl %edx, %ecx
subq %rcx, %rdi
cmpq %rdi, 0x8(%rbx)
jae 0x20e7ba
decq %rdi
movq %rdi, %rax
shrq %rax
orq %rdi, %rax
movq %rax, %rcx
shrq $0x2, %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x4, %rax
orq %rcx, %rax
movq %rax, %rcx
shrq $0x8, %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x10, %rax
orq %rcx, %rax
leaq 0x1(%rax), %rcx
movq %rcx, 0x8(%rbx)
movq 0x10(%rbx), %rdi
leaq 0x8(,%rax,8), %rsi
callq 0x2370
movq 0x8(%rsp), %r11
movq 0x10(%rsp), %r10
movq %rax, 0x10(%rbx)
movl 0x1c(%r15,%r12), %edx
movl 0x20(%r15,%r12), %esi
movq (%rbp), %rax
movl %esi, %ecx
subl %edx, %ecx
testb $0x1, %r14b
jne 0x20e8ee
cmpl %edx, %esi
movq 0x20(%rsp), %r12
je 0x20e808
movq (%rbx), %rdx
subq %rcx, %rdx
shlq $0x3, %rdx
addq 0x10(%rbx), %rdx
movq 0x10(%rbp), %rsi
cmpq $0x1, %rcx
movq %rcx, %rdi
adcq $0x0, %rdi
shlq $0x3, %rdi
xorl %r8d, %r8d
movl (%rsi,%r8,2), %r9d
cmpq %r9, (%rdx,%r8)
jne 0x20eaa1
addq $0x8, %r8
cmpq %r8, %rdi
jne 0x20e7f1
subq %rcx, %rax
jle 0x20e9c1
movq 0x10(%rbx), %rdx
shlq $0x4, %rcx
addq 0x10(%rbp), %rcx
movl (%rcx), %esi
movq (%rbx), %rdi
leaq 0x1(%rdi), %r8
movq %r8, (%rbx)
movq %rsi, (%rdx,%rdi,8)
addq $0x10, %rcx
decq %rax
jne 0x20e81d
jmp 0x20e9c1
testq %r15, %r15
jle 0x20e9c1
movq 0x10(%rbp), %rdx
movq 0x10(%rbx), %rax
leaq 0x1(%r15), %rcx
shlq $0x4, %r15
addq %r15, %rdx
addq $-0x10, %rdx
movl (%rdx), %esi
xorq $0x1, %rsi
movq (%rbx), %rdi
leaq 0x1(%rdi), %r8
movq %r8, (%rbx)
movq %rsi, (%rax,%rdi,8)
decq %rcx
addq $-0x10, %rdx
cmpq $0x1, %rcx
ja 0x20e85b
jmp 0x20e9c1
movq 0x18(%rsp), %rax
movq 0x18(%rax), %rsi
movq (%rbx), %rcx
movq 0x10(%rbx), %rax
movl -0x8(%rax,%rcx,8), %edi
movq 0x28(%rsi), %r8
movq (%r8,%rdi,8), %rdi
movq %rdi, %r8
movl $0xffffffff, %r9d       # imm = 0xFFFFFFFF
andq %r9, %r8
je 0x20ea82
movq 0x8(%rsi), %r9
shrq $0x20, %rdi
shlq $0x3, %r8
leaq (%r8,%r8,2), %rsi
leaq (%rdi,%rdi,2), %rdi
leaq (%r9,%rdi,8), %rdi
addq $0xc, %rdi
xorl %r8d, %r8d
cmpl $0x0, (%rdi,%r8)
js 0x20e8e0
cmpl %edx, -0x4(%rdi,%r8)
je 0x20e684
addq $0x18, %r8
cmpq %r8, %rsi
jne 0x20e8ce
jmp 0x20ea82
cmpl %edx, %esi
movq 0x20(%rsp), %r12
je 0x20e940
movq %rax, %rdx
subq %rcx, %rdx
movq (%rbx), %rsi
subq %rcx, %rsi
shlq $0x3, %rsi
addq 0x10(%rbx), %rsi
movq 0x10(%rbp), %rdi
movq %rax, %r8
shlq $0x4, %r8
addq %r8, %rdi
addq $-0x10, %rdi
movq %rax, %r8
movl (%rdi), %r9d
xorq $0x1, %r9
cmpq %r9, (%rsi)
jne 0x20eac0
decq %r8
addq $-0x10, %rdi
addq $0x8, %rsi
cmpq %rdx, %r8
jg 0x20e920
leaq -0x1(%rax), %rdx
cmpq %rcx, %rdx
js 0x20e9c1
movq 0x10(%rbp), %rdi
movq 0x10(%rbx), %rdx
movq %rcx, %rsi
subq %rax, %rsi
shlq $0x4, %rax
shlq $0x4, %rcx
subq %rcx, %rax
addq %rdi, %rax
addq $-0x10, %rax
movl (%rax), %ecx
xorq $0x1, %rcx
movq (%rbx), %rdi
leaq 0x1(%rdi), %r8
movq %r8, (%rbx)
movq %rcx, (%rdx,%rdi,8)
addq $-0x10, %rax
incq %rsi
jne 0x20e969
jmp 0x20e9c1
testq %r15, %r15
jle 0x20e9c1
movq 0x10(%rbp), %rdx
leaq 0x1(%r15), %rcx
shlq $0x4, %r15
addq %r15, %rdx
addq $-0x10, %rdx
movl (%rdx), %esi
xorq $0x1, %rsi
movq (%rbx), %rdi
leaq 0x1(%rdi), %r8
movq %r8, (%rbx)
movq %rsi, (%rax,%rdi,8)
decq %rcx
addq $-0x10, %rdx
cmpq $0x1, %rcx
ja 0x20e9a0
incq %r13
cmpq %r12, %r13
jne 0x20e4c2
jmp 0x20ea49
movq 0x18(%rsp), %rsi
movq 0x18(%rsi), %rsi
movq 0x28(%rsi), %r8
movl %edi, %edi
movq (%r8,%rdi,8), %rdi
movq %rdi, %r8
movl $0xffffffff, %r9d       # imm = 0xFFFFFFFF
andq %r9, %r8
je 0x20ea2a
movq 0x8(%rsi), %r9
shrq $0x20, %rdi
shlq $0x3, %r8
leaq (%r8,%r8,2), %rsi
leaq (%rdi,%rdi,2), %rdi
leaq (%r9,%rdi,8), %rdi
addq $0xc, %rdi
xorl %r8d, %r8d
cmpl $0x0, (%rdi,%r8)
js 0x20ea21
cmpl %edx, -0x4(%rdi,%r8)
je 0x20e684
addq $0x18, %r8
cmpq %r8, %rsi
jne 0x20ea0f
leaq 0x395f0(%rip), %rdi     # 0x248021
leaq 0x36bd1(%rip), %rsi     # 0x245609
leaq 0x3953d(%rip), %rcx     # 0x247f7c
movl $0x2430, %edx           # imm = 0x2430
callq 0x2110
movq (%rbx), %rax
movq 0x28(%rsp), %rcx
subq %rcx, %rax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x39500(%rip), %rdi     # 0x247f6a
leaq 0x36b98(%rip), %rsi     # 0x245609
leaq 0x39504(%rip), %rcx     # 0x247f7c
movl $0x2407, %edx           # imm = 0x2407
callq 0x2110
leaq 0x39598(%rip), %rdi     # 0x248021
leaq 0x36b79(%rip), %rsi     # 0x245609
leaq 0x394e5(%rip), %rcx     # 0x247f7c
movl $0x242a, %edx           # imm = 0x242A
callq 0x2110
leaq 0x39528(%rip), %rdi     # 0x247fd0
leaq 0x36b5a(%rip), %rsi     # 0x245609
leaq 0x394c6(%rip), %rcx     # 0x247f7c
movl $0x2415, %edx           # imm = 0x2415
callq 0x2110
leaq 0x3952c(%rip), %rdi     # 0x247ff3
leaq 0x36b3b(%rip), %rsi     # 0x245609
leaq 0x394a7(%rip), %rcx     # 0x247f7c
movl $0x2420, %edx           # imm = 0x2420
callq 0x2110