// File: /workspace/github_cpp_makefile_star2_O1/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 %r8, %r14
movq %rcx, 0x10(%rsp)
movq %rsi, 0x28(%rsp)
movq $0x0, (%r8)
movl 0x10(%rdx), %r8d
testq %r8, %r8
je 0x21d26b
movq %rdi, %r11
xorl %r15d, %r15d
movq %rdi, 0x8(%rsp)
movq %rdx, 0x30(%rsp)
movq 0x18(%rdx), %rcx
movq (%rcx,%r15,8), %rax
movq %rax, %rbx
shrq $0x21, %rbx
movq 0x208(%r11), %rsi
movq %rbx, %rdi
subq %rsi, %rdi
jae 0x21cde3
movq %rbx, %r9
shlq $0x5, %r9
addq 0x28(%rsp), %r9
xorl %r12d, %r12d
jmp 0x21cdf7
leaq (%rdi,%rdi,4), %r12
shlq $0x3, %r12
movq 0x10(%rsp), %rdi
addq 0x10(%rdi), %r12
xorl %r9d, %r9d
shrq $0x20, %rax
andl $0x1, %eax
testq %r9, %r9
movq %r15, 0x20(%rsp)
je 0x21ce7f
leaq 0x1(%r15), %rsi
cmpq %r8, %rsi
jae 0x21cef3
movq 0x220(%r11), %rdx
movl (%rdx,%rbx,4), %edi
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
cmpq %rdx, %rdi
je 0x21ce5a
movq 0x1f0(%r11), %r8
shlq $0x5, %rdi
movl 0x1c(%r8,%rdi), %edx
testq %rdx, %rdx
je 0x21ce5a
movq 0x8(%rcx,%r15,8), %rsi
shrq $0x21, %rsi
addq %rdi, %r8
movq (%r8), %rcx
cmpl (%rcx), %esi
je 0x21ce5c
addq $0x28, %rcx
decq %rdx
jne 0x21ce4d
xorl %ecx, %ecx
testq %rcx, %rcx
je 0x21d2ba
testb $0x40, 0x24(%rcx)
jne 0x21d2ba
testq %rax, %rax
jne 0x21cf03
movl 0x14(%rcx), %ecx
incl %ecx
jmp 0x21cefe
testq %r12, %r12
je 0x21d251
cmpq %rsi, %rbx
movl $0x0, %edx
cmovaeq %rsi, %rdx
subq %rdx, %rbx
leaq (%rax,%rbx,2), %rbx
movq (%r14), %rax
testq %rax, %rax
je 0x21d121
movq 0x20(%rsp), %rdx
movq -0x8(%rcx,%rdx,8), %rcx
shrq $0x21, %rcx
cmpq %rsi, %rcx
jae 0x21d142
movq 0x10(%r14), %rdi
movq %rax, %rcx
shlq $0x4, %rcx
movl -0x10(%rdi,%rcx), %edx
cmpq %rdx, %rbx
jne 0x21d1a4
addq %rcx, %rdi
movl $0x0, -0xc(%rdi)
movl (%r12), %eax
movl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
andl %ecx, %eax
movl %eax, -0x8(%rdi)
jmp 0x21d251
movl 0x18(%r9), %ecx
movl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
andl %edx, %ecx
xorl %r12d, %r12d
jmp 0x21cf15
movl 0x18(%rcx), %r12d
decl %r12d
movl 0x18(%r9), %ecx
movl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
andl %edx, %ecx
movl %ecx, %ebp
movq 0x10(%r9), %rcx
testq %rax, %rax
jne 0x21cf45
movq 0x30(%r11), %rdx
movq 0x48(%rdx), %rsi
imulq $0x58, %rbx, %rdi
movq (%rcx,%r12,8), %rcx
movl %ecx, %edx
shrq $0x20, %rcx
leaq (%rcx,%rcx,8), %rcx
shlq $0x2, %rcx
addq 0x30(%rsi,%rdi), %rcx
jmp 0x21cf6d
movq 0x30(%r11), %rdx
movq 0x48(%rdx), %rsi
imulq $0x58, %rbx, %rdi
movq -0x8(%rcx,%rbp,8), %rcx
movl %ecx, %edx
shrq $0x20, %rcx
leaq (%rcx,%rcx,8), %rcx
shlq $0x2, %rcx
addq 0x30(%rsi,%rdi), %rcx
xorq $0x1, %rdx
movq (%r14), %rdi
testq %rdi, %rdi
movq %r9, 0x18(%rsp)
je 0x21cfdc
movq 0x10(%r14), %rsi
shlq $0x4, %rdi
cmpl -0x10(%rsi,%rdi), %edx
jne 0x21d2d9
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 0x21d2f8
cmpl %edx, %r8d
cmovbl %r8d, %edx
cmpl %edi, %ecx
cmoval %ecx, %edi
movl %edx, -0xc(%rsi)
movl %edi, -0x8(%rsi)
testq %rax, %rax
movq 0x18(%rsp), %r9
jne 0x21cfd9
incq %r12
jmp 0x21cfdc
decq %rbp
testq %rax, %rax
jne 0x21d085
cmpq %rbp, %r12
jge 0x21d251
movq 0x30(%r11), %rax
movq 0x48(%rax), %rax
imulq $0x58, %rbx, %rcx
movq 0x10(%r9), %rdx
movq (%rdx,%r12,8), %r13
movq %r13, %rdx
shrq $0x20, %rdx
leaq (%rdx,%rdx,8), %r15
shlq $0x2, %r15
addq 0x30(%rax,%rcx), %r15
movq 0x8(%r14), %rax
cmpq %rax, (%r14)
jne 0x21d04e
leaq (%rax,%rax), %rsi
testq %rax, %rax
movl $0x2, %eax
cmoveq %rax, %rsi
movq %rsi, 0x8(%r14)
movq 0x10(%r14), %rdi
shlq $0x4, %rsi
callq 0x2370
movq 0x18(%rsp), %r9
movq 0x8(%rsp), %r11
movq %rax, 0x10(%r14)
movq (%r14), %rax
movq 0x10(%r14), %rcx
leaq 0x1(%rax), %rdx
movq %rdx, (%r14)
shlq $0x4, %rax
movl %r13d, (%rcx,%rax)
movl 0xc(%r15), %edx
movl %edx, 0x4(%rcx,%rax)
movl 0x10(%r15), %edx
movl %edx, 0x8(%rcx,%rax)
incq %r12
cmpq %r12, %rbp
jne 0x21cfee
jmp 0x21d251
cmpq %r12, %rbp
jle 0x21d251
movq 0x30(%r11), %rax
movq 0x48(%rax), %rax
imulq $0x58, %rbx, %rcx
movq 0x10(%r9), %rdx
movq -0x8(%rdx,%rbp,8), %r15
movq %r15, %rdx
shrq $0x20, %rdx
leaq (%rdx,%rdx,8), %r13
shlq $0x2, %r13
addq 0x30(%rax,%rcx), %r13
movq 0x8(%r14), %rax
cmpq %rax, (%r14)
jne 0x21d0ef
leaq (%rax,%rax), %rsi
testq %rax, %rax
movl $0x2, %eax
cmoveq %rax, %rsi
movq %rsi, 0x8(%r14)
movq 0x10(%r14), %rdi
shlq $0x4, %rsi
callq 0x2370
movq 0x18(%rsp), %r9
movq 0x8(%rsp), %r11
movq %rax, 0x10(%r14)
decq %rbp
xorl $0x1, %r15d
movq (%r14), %rax
movq 0x10(%r14), %rcx
leaq 0x1(%rax), %rdx
movq %rdx, (%r14)
shlq $0x4, %rax
movl %r15d, (%rcx,%rax)
movl 0xc(%r13), %edx
movl %edx, 0x4(%rcx,%rax)
movl 0x10(%r13), %edx
movl %edx, 0x8(%rcx,%rax)
jmp 0x21d085
cmpq $0x0, 0x8(%r14)
jne 0x21d225
movq $0x2, 0x8(%r14)
movq 0x10(%r14), %rdi
movl $0x20, %esi
jmp 0x21d217
movq 0x10(%rsp), %rcx
movq 0x18(%rcx), %rsi
movq 0x10(%r14), %rdi
movq %rax, %rcx
shlq $0x4, %rcx
movl -0x10(%rdi,%rcx), %ecx
movq 0x28(%rsi), %rdx
movq (%rdx,%rcx,8), %rdx
movq %rdx, %rcx
movl $0xffffffff, %r8d       # imm = 0xFFFFFFFF
andq %r8, %rcx
je 0x21d317
shrq $0x20, %rdx
leaq (%rdx,%rdx,2), %rdx
shlq $0x3, %rdx
addq 0x8(%rsi), %rdx
cmpl $0x0, 0xc(%rdx)
js 0x21d18f
cmpl %ebx, 0x8(%rdx)
je 0x21d19a
addq $0x18, %rdx
decq %rcx
jne 0x21d184
xorl %edx, %edx
testq %rdx, %rdx
jne 0x21d1f6
jmp 0x21d317
movq 0x10(%rsp), %rcx
movq 0x18(%rcx), %rsi
movq 0x28(%rsi), %rcx
movq (%rcx,%rdx,8), %rdx
movq %rdx, %rcx
movl $0xffffffff, %r8d       # imm = 0xFFFFFFFF
andq %r8, %rcx
je 0x21d336
shrq $0x20, %rdx
leaq (%rdx,%rdx,2), %rdx
shlq $0x3, %rdx
addq 0x8(%rsi), %rdx
cmpl $0x0, 0xc(%rdx)
js 0x21d1e2
cmpl %ebx, 0x8(%rdx)
je 0x21d1ed
addq $0x18, %rdx
decq %rcx
jne 0x21d1d7
xorl %edx, %edx
testq %rdx, %rdx
je 0x21d336
movq 0x8(%r14), %rcx
cmpq %rcx, %rax
jne 0x21d225
leaq (%rcx,%rcx), %rsi
testq %rcx, %rcx
movl $0x2, %eax
cmoveq %rax, %rsi
movq %rsi, 0x8(%r14)
shlq $0x4, %rsi
callq 0x2370
movq 0x8(%rsp), %r11
movq %rax, 0x10(%r14)
movq (%r14), %rax
movq 0x10(%r14), %rcx
leaq 0x1(%rax), %rdx
movq %rdx, (%r14)
shlq $0x4, %rax
movl %ebx, (%rcx,%rax)
movl $0x0, 0x4(%rcx,%rax)
movl (%r12), %edx
movl $0x7fffffff, %esi       # imm = 0x7FFFFFFF
andl %esi, %edx
movl %edx, 0x8(%rcx,%rax)
movq 0x20(%rsp), %r15
incq %r15
movq 0x30(%rsp), %rdx
movl 0x10(%rdx), %r8d
cmpq %r8, %r15
jb 0x21cdb4
movq (%r14), %rbx
testq %rbx, %rbx
je 0x21d2ab
movq 0x10(%r14), %r14
movq 0x10(%rsp), %rax
movq 0x10(%rax), %r15
addq $0xc, %r14
movl -0xc(%r14), %eax
movl -0x8(%r14), %edi
movl -0x4(%r14), %esi
shrl %eax
leaq (%rax,%rax,4), %rax
leaq (%r15,%rax,8), %rdx
callq 0x1f2d50
movl %eax, (%r14)
addq $0x10, %r14
decq %rbx
jne 0x21d284
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x20aaa(%rip), %rdi     # 0x23dd6b
leaq 0x1c05d(%rip), %rsi     # 0x239325
leaq 0x20aae(%rip), %rcx     # 0x23dd7d
movl $0x4066, %edx           # imm = 0x4066
callq 0x2110
leaq 0x20b02(%rip), %rdi     # 0x23dde2
leaq 0x1c03e(%rip), %rsi     # 0x239325
leaq 0x20a8f(%rip), %rcx     # 0x23dd7d
movl $0x4079, %edx           # imm = 0x4079
callq 0x2110
leaq 0x20afd(%rip), %rdi     # 0x23ddfc
leaq 0x1c01f(%rip), %rsi     # 0x239325
leaq 0x20a70(%rip), %rcx     # 0x23dd7d
movl $0x407b, %edx           # imm = 0x407B
callq 0x2110
leaq 0x20ae6(%rip), %rdi     # 0x23de04
leaq 0x1c000(%rip), %rsi     # 0x239325
leaq 0x20a51(%rip), %rcx     # 0x23dd7d
movl $0x4095, %edx           # imm = 0x4095
callq 0x2110
leaq 0x20ac7(%rip), %rdi     # 0x23de04
leaq 0x1bfe1(%rip), %rsi     # 0x239325
leaq 0x20a32(%rip), %rcx     # 0x23dd7d
movl $0x409d, %edx           # imm = 0x409D
callq 0x2110