// File: /workspace/github_cpp_makefile_star2_O3/chhylp123[P]hifiasm/gfa_ut.cpp
// Function: gen_raw_ug_seq(ul_resolve_t*, ul_str_t*, ma_utg_t*, ma_ug_t*, uinfo_srt_warp_t*, unsigned long)
void gen_raw_ug_seq(ul_resolve_t *uidx, ul_str_t *str, ma_utg_t *u, ma_ug_t *raw, uinfo_srt_warp_t *res, uint64_t iug_id)
{
    uint64_t k, cd, nd, rev, x, os, oe; uinfo_srt_t *p; ma_utg_t *ru;
    uc_block_t *xi; ul2ul_t *z = NULL; ul_str_t *c_str; int64_t m, cs, ce;
    for (k = 0, res->n = 0; k < u->n; k++) {
        cd = u->a[k]>>33; rev = ((u->a[k]>>32)&1); ru = NULL; c_str = NULL;
        if(ulg_type(uidx->uovl, cd)) c_str = &(str[ulg_id(uidx->uovl, cd)]); ///ul
        else ru = &(raw->u.a[ulg_id(uidx->uovl, cd)]); //ug

        if(c_str) {
            if(k + 1 < u->n) {
                nd = u->a[k+1]>>33;
                z = get_ul_spec_ovlp(&(uidx->uovl), cd, nd);
                assert(z && (!z->is_del));
                if(!rev) {
                    cs = 0; ce = z->qs_k + 1;
                } else {
                    cs = z->qe_k - 1; ce = c_str->cn;
                }
            } else {
                cs = 0; ce = c_str->cn;
            }

            if(!rev) {
                xi = &(uidx->idx->a[cd].bb.a[c_str->a[cs]>>32]);
                x = (uint32_t)c_str->a[cs];
            } else {
                xi = &(uidx->idx->a[cd].bb.a[c_str->a[ce-1]>>32]);
                x = (uint32_t)c_str->a[ce-1]; x ^= 1;
            }

            if(res->n) {
                assert((res->a[res->n-1].v) == x);
                os = MAX(xi->ts, res->a[res->n-1].s); oe = MIN(xi->te, res->a[res->n-1].e);
                assert(oe > os);
                os = MIN(xi->ts, res->a[res->n-1].s); oe = MAX(xi->te, res->a[res->n-1].e);
                res->a[res->n-1].s = os; res->a[res->n-1].e = oe;
                if(!rev) cs++;
                else ce--;
            }

            if(!rev) {
                for (m = cs; m < ce; m++) {
                    xi = &(uidx->idx->a[cd].bb.a[c_str->a[m]>>32]);
                    x = (uint32_t)c_str->a[m];
                    kv_pushp(uinfo_srt_t, *res, &p);
                    p->v = x; p->s = xi->ts; p->e = xi->te;
                }
            } else {
                for (m = ce-1; m >= cs; m--) {
                    xi = &(uidx->idx->a[cd].bb.a[c_str->a[m]>>32]);
                    x = ((uint32_t)c_str->a[m])^1;
                    kv_pushp(uinfo_srt_t, *res, &p);
                    p->v = x; p->s = xi->ts; p->e = xi->te;
                }
            }
        } else if(ru) {
            x = ulg_id(uidx->uovl, cd); x <<= 1; if(rev) x^=1;
            if(res->n) {
                if((!ulg_type(uidx->uovl, (u->a[k-1]>>33)))) {///in previous ul is also a raw utg node
                    assert(get_specfic_edge(raw->g, res->a[res->n-1].v, x));
                    kv_pushp(uinfo_srt_t, *res, &p);
                    p->v = x; p->s = 0; p->e = ru->len;
                } else {
                    // assert(((res->a[res->n-1].v) == x));
                    if(((res->a[res->n-1].v) == x)) {
                        res->a[res->n-1].s = 0; res->a[res->n-1].e = ru->len;
                    } else {
                        assert(get_specfic_edge(raw->g, res->a[res->n-1].v, x));
                        kv_pushp(uinfo_srt_t, *res, &p);
                        p->v = x; p->s = 0; p->e = ru->len;
                    }
                }
            } else {
                kv_pushp(uinfo_srt_t, *res, &p);
                p->v = x; p->s = 0; p->e = ru->len;
            }
        }
    }


    for (k = 0; k < res->n; k++) {
        res->a[k].n = ug_occ_w(res->a[k].s, res->a[k].e, &(raw->u.a[res->a[k].v>>1]));
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rcx, 0x10(%rsp)
movq %rsi, 0x20(%rsp)
movq $0x0, (%r8)
movl 0x10(%rdx), %r9d
testq %r9, %r9
je 0x228b5e
movq %r8, %r14
movq %rdi, %r11
xorl %r12d, %r12d
xorl %esi, %esi
xorl %ebp, %ebp
movq %rdx, 0x28(%rsp)
movq %rdi, 0x8(%rsp)
movq 0x18(%rdx), %rcx
movq (%rcx,%rbp,8), %rax
movq %rax, %r10
shrq $0x21, %r10
shrq $0x20, %rax
andl $0x1, %eax
movq 0x208(%r11), %rdi
movq %r10, %r8
subq %rdi, %r8
movq %rbp, 0x30(%rsp)
jae 0x2286b9
movq 0x20(%rsp), %rdx
testq %rdx, %rdx
je 0x228b0b
movq %r10, %rdi
shlq $0x5, %rdi
addq %rdx, %rdi
leaq 0x1(%rbp), %rsi
cmpq %r9, %rsi
movq %r10, 0x18(%rsp)
movq %rdi, (%rsp)
jae 0x228725
movq 0x220(%r11), %rdx
movl (%rdx,%r10,4), %esi
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
cmpq %rdx, %rsi
je 0x228b6d
movq 0x1f0(%r11), %rdi
shlq $0x5, %rsi
movl 0x1c(%rdi,%rsi), %r8d
testq %r8, %r8
je 0x228b6d
movq 0x8(%rcx,%rbp,8), %rdx
shrq $0x21, %rdx
addq %rsi, %rdi
movq (%rdi), %rcx
shlq $0x3, %r8
leaq (%r8,%r8,4), %rdi
xorl %esi, %esi
cmpl (%rcx,%rsi), %edx
je 0x22873c
addq $0x28, %rsi
cmpq %rsi, %rdi
jne 0x2286a2
jmp 0x228b6d
movq 0x10(%rsp), %rdx
movq 0x10(%rdx), %rdx
testq %rdx, %rdx
je 0x228b0b
leaq (%r8,%r8,4), %r9
leaq (%rdx,%r9,8), %rbx
leaq (%rax,%r8,2), %r15
testq %rsi, %rsi
je 0x228794
movq -0x8(%rcx,%rbp,8), %rax
shrq $0x21, %rax
cmpq %rdi, %rax
jae 0x2287aa
movq 0x10(%r14), %rax
movq %rsi, %rcx
shlq $0x4, %rcx
movl -0x10(%rax,%rcx), %edx
cmpq %rdx, %r15
jne 0x228a1b
addq %rcx, %rax
movl $0x0, -0xc(%rax)
movl (%rbx), %ecx
movl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
andl %edx, %ecx
movl %ecx, -0x8(%rax)
jmp 0x228b0b
movl 0x18(%rdi), %r13d
andl $0x7fffffff, %r13d      # imm = 0x7FFFFFFF
testq %rax, %rax
je 0x22875c
xorl %ebx, %ebx
jmp 0x22882e
testb $0x40, 0x24(%rcx,%rsi)
jne 0x228b6d
testq %rax, %rax
jne 0x228819
movl 0x14(%rcx,%rsi), %r13d
incl %r13d
movq (%rsp), %rdi
testq %r12, %r12
je 0x22897b
movq 0x30(%r11), %rax
movq 0x48(%rax), %rax
imulq $0x58, %r10, %rsi
movq 0x10(%rdi), %rcx
movq (%rcx), %rcx
movl %ecx, %edx
shrq $0x20, %rcx
leaq (%rcx,%rcx,8), %rcx
shlq $0x2, %rcx
addq 0x30(%rax,%rsi), %rcx
movb $0x1, %al
xorl %ebx, %ebx
jmp 0x228865
cmpq $0x0, 0x8(%r14)
movq 0x10(%r14), %rax
je 0x228ac3
xorl %ecx, %ecx
jmp 0x228ae4
movq 0x10(%rsp), %rax
movq 0x18(%rax), %rcx
movq 0x10(%r14), %rax
movq %rsi, %rdx
shlq $0x4, %rdx
movl -0x10(%rax,%rdx), %edx
movq 0x28(%rcx), %rdi
movq (%rdi,%rdx,8), %rdx
movq %rdx, %rdi
movl $0xffffffff, %r8d       # imm = 0xFFFFFFFF
andq %r8, %rdi
je 0x228b8c
movq 0x8(%rcx), %r8
shrq $0x20, %rdx
shlq $0x3, %rdi
leaq (%rdi,%rdi,2), %rcx
leaq (%rdx,%rdx,2), %rdx
leaq (%r8,%rdx,8), %rdx
addq $0xc, %rdx
xorl %edi, %edi
cmpl $0x0, (%rdx,%rdi)
js 0x22880b
cmpl %r15d, -0x4(%rdx,%rdi)
je 0x228a77
addq $0x18, %rdi
cmpq %rdi, %rcx
jne 0x2287fa
jmp 0x228b8c
movl 0x18(%rcx,%rsi), %ebx
decl %ebx
movq (%rsp), %rdi
movl 0x18(%rdi), %r13d
andl $0x7fffffff, %r13d      # imm = 0x7FFFFFFF
testq %r12, %r12
je 0x2288d9
movq 0x30(%r11), %rax
movq 0x48(%rax), %rax
imulq $0x58, %r10, %rsi
movq 0x10(%rdi), %rcx
movq -0x8(%rcx,%r13,8), %rcx
movl %ecx, %edx
shrq $0x20, %rcx
leaq (%rcx,%rcx,8), %rcx
shlq $0x2, %rcx
addq 0x30(%rax,%rsi), %rcx
xorq $0x1, %rdx
xorl %eax, %eax
movq 0x10(%r14), %rsi
movq %r12, %rdi
shlq $0x4, %rdi
cmpl -0x10(%rsi,%rdi), %edx
jne 0x228bca
addq %rdi, %rsi
movl 0xc(%rcx), %r8d
movl 0x10(%rcx), %ecx
movl -0xc(%rsi), %edx
movl -0x8(%rsi), %edi
cmpl %edx, %r8d
movl %edx, %r9d
cmoval %r8d, %r9d
cmpl %edi, %ecx
movl %edi, %r10d
cmovbl %ecx, %r10d
cmpl %r9d, %r10d
jbe 0x228be9
cmpl %edx, %r8d
cmovbl %r8d, %edx
cmpl %edi, %ecx
cmoval %ecx, %edi
movl %edx, -0xc(%rsi)
movl %edi, -0x8(%rsi)
testb %al, %al
je 0x2288cd
incq %rbx
movq 0x18(%rsp), %r10
movq (%rsp), %rdi
jmp 0x22897d
decq %r13
movq 0x18(%rsp), %r10
movq (%rsp), %rdi
cmpq %rbx, %r13
jle 0x228b08
movq 0x10(%r14), %rax
movq %r12, %rcx
movq 0x30(%r11), %rdx
movq 0x48(%rdx), %rdx
imulq $0x58, %r10, %rsi
movq 0x30(%rdx,%rsi), %r15
movq 0x10(%rdi), %rdx
movq -0x8(%rdx,%r13,8), %rbp
cmpq 0x8(%r14), %rcx
jne 0x22893e
leaq (%rcx,%rcx), %rsi
testq %rcx, %rcx
movl $0x2, %ecx
cmoveq %rcx, %rsi
movq %rsi, 0x8(%r14)
shlq $0x4, %rsi
movq %rax, %rdi
callq 0x2370
movq (%rsp), %rdi
movq 0x18(%rsp), %r10
movq 0x8(%rsp), %r11
movq %rax, 0x10(%r14)
movq (%r14), %rcx
decq %r13
movq %rbp, %rdx
shrq $0x20, %rdx
xorl $0x1, %ebp
leaq 0x1(%rcx), %r12
movq %r12, (%r14)
shlq $0x4, %rcx
movl %ebp, (%rax,%rcx)
leaq (%rdx,%rdx,8), %rdx
movq 0xc(%r15,%rdx,4), %rdx
movq %rdx, 0x4(%rax,%rcx)
movq %r12, %rcx
movq %r12, %rsi
cmpq %rbx, %r13
jg 0x2288e9
jmp 0x228b0b
xorl %ebx, %ebx
cmpq %r13, %rbx
jae 0x228b08
movq 0x10(%r14), %rax
movq %r12, %rcx
movq 0x30(%r11), %rdx
movq 0x48(%rdx), %rdx
imulq $0x58, %r10, %rsi
movq 0x30(%rdx,%rsi), %r15
movq 0x10(%rdi), %rdx
movq (%rdx,%rbx,8), %rbp
cmpq 0x8(%r14), %rcx
jne 0x2289e1
leaq (%rcx,%rcx), %rsi
testq %rcx, %rcx
movl $0x2, %ecx
cmoveq %rcx, %rsi
movq %rsi, 0x8(%r14)
shlq $0x4, %rsi
movq %rax, %rdi
callq 0x2370
movq (%rsp), %rdi
movq 0x18(%rsp), %r10
movq 0x8(%rsp), %r11
movq %rax, 0x10(%r14)
movq (%r14), %rcx
movq %rbp, %rdx
shrq $0x20, %rdx
leaq 0x1(%rcx), %r12
movq %r12, (%r14)
shlq $0x4, %rcx
movl %ebp, (%rax,%rcx)
leaq (%rdx,%rdx,8), %rdx
movq 0xc(%r15,%rdx,4), %rdx
movq %rdx, 0x4(%rax,%rcx)
incq %rbx
movq %r12, %rcx
movq %r12, %rsi
cmpq %rbx, %r13
jne 0x22898d
jmp 0x228b0b
movq 0x10(%rsp), %rcx
movq 0x18(%rcx), %rdi
movq 0x28(%rdi), %rcx
movq (%rcx,%rdx,8), %rdx
movq %rdx, %rcx
movl $0xffffffff, %r8d       # imm = 0xFFFFFFFF
andq %r8, %rcx
je 0x228bab
movq 0x8(%rdi), %rdi
shrq $0x20, %rdx
shlq $0x3, %rcx
leaq (%rcx,%rcx,2), %rcx
leaq (%rdx,%rdx,2), %rdx
leaq (%rdi,%rdx,8), %rdx
addq $0xc, %rdx
xorl %edi, %edi
cmpl $0x0, (%rdx,%rdi)
js 0x228a69
cmpl %r15d, -0x4(%rdx,%rdi)
je 0x228a77
addq $0x18, %rdi
cmpq %rdi, %rcx
jne 0x228a5c
jmp 0x228bab
cmpq 0x8(%r14), %rsi
jne 0x228a9d
leaq (%rsi,%rsi), %rcx
movq %rcx, 0x8(%r14)
shlq $0x5, %rsi
movq %rax, %rdi
callq 0x2370
movq 0x8(%rsp), %r11
movq %rax, 0x10(%r14)
movq (%r14), %rsi
leaq 0x1(%rsi), %r12
movq %r12, (%r14)
shlq $0x4, %rsi
movl %r15d, (%rax,%rsi)
movl $0x0, 0x4(%rax,%rsi)
movl (%rbx), %ecx
movl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
andl %edx, %ecx
movl %ecx, 0x8(%rax,%rsi)
jmp 0x228b08
movq $0x2, 0x8(%r14)
movl $0x20, %esi
movq %rax, %rdi
callq 0x2370
movq 0x8(%rsp), %r11
movq %rax, 0x10(%r14)
movq (%r14), %rcx
leaq 0x1(%rcx), %r12
movq %r12, (%r14)
shlq $0x4, %rcx
movl %r15d, (%rax,%rcx)
movl $0x0, 0x4(%rax,%rcx)
movl (%rbx), %edx
movl $0x7fffffff, %esi       # imm = 0x7FFFFFFF
andl %esi, %edx
movl %edx, 0x8(%rax,%rcx)
movq %r12, %rsi
movq 0x30(%rsp), %rbp
incq %rbp
movq 0x28(%rsp), %rdx
movl 0x10(%rdx), %r9d
cmpq %r9, %rbp
jb 0x2285fb
testq %r12, %r12
je 0x228b5e
movq 0x10(%r14), %rbx
movq 0x10(%rsp), %rax
movq 0x10(%rax), %r14
addq $0xc, %rbx
movl -0xc(%rbx), %eax
movl -0x8(%rbx), %edi
movl -0x4(%rbx), %esi
shrl %eax
leaq (%rax,%rax,4), %rax
leaq (%r14,%rax,8), %rdx
callq 0x1fe266
movl %eax, (%rbx)
addq $0x10, %rbx
decq %r12
jne 0x228b3b
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x214db(%rip), %rdi     # 0x24a04f
leaq 0x1ca8e(%rip), %rsi     # 0x245609
leaq 0x214df(%rip), %rcx     # 0x24a061
movl $0x4066, %edx           # imm = 0x4066
callq 0x2110
leaq 0x21555(%rip), %rdi     # 0x24a0e8
leaq 0x1ca6f(%rip), %rsi     # 0x245609
leaq 0x214c0(%rip), %rcx     # 0x24a061
movl $0x4095, %edx           # imm = 0x4095
callq 0x2110
leaq 0x21536(%rip), %rdi     # 0x24a0e8
leaq 0x1ca50(%rip), %rsi     # 0x245609
leaq 0x214a1(%rip), %rcx     # 0x24a061
movl $0x409d, %edx           # imm = 0x409D
callq 0x2110
leaq 0x214f5(%rip), %rdi     # 0x24a0c6
leaq 0x1ca31(%rip), %rsi     # 0x245609
leaq 0x21482(%rip), %rcx     # 0x24a061
movl $0x4079, %edx           # imm = 0x4079
callq 0x2110
leaq 0x214f0(%rip), %rdi     # 0x24a0e0
leaq 0x1ca12(%rip), %rsi     # 0x245609
leaq 0x21463(%rip), %rcx     # 0x24a061
movl $0x407b, %edx           # imm = 0x407B
callq 0x2110