// File: /workspace/github_cpp_makefile_star2_O2/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 $0x48, %rsp
movq %r8, %rbx
movq %rcx, 0x28(%rsp)
movq %rdx, %r12
andq $0x0, (%r8)
leaq 0x1f0(%rdi), %rax
movq %rax, 0x40(%rsp)
xorl %r15d, %r15d
xorl %ebp, %ebp
movq %rdx, 0x30(%rsp)
movq %rsi, 0x10(%rsp)
movq %rdi, 0x8(%rsp)
movl 0x10(%r12), %ecx
cmpq %rcx, %rbp
jae 0x1d90e9
movq 0x18(%r12), %rax
movq (%rax,%rbp,8), %r13
movq %r13, %r9
shrq $0x21, %r9
shrq $0x20, %r13
andl $0x1, %r13d
movq 0x208(%rdi), %rdx
movq %r9, %r8
subq %rdx, %r8
jae 0x1d8d4e
testq %rsi, %rsi
je 0x1d90e1
movq %r9, %r8
shlq $0x5, %r8
addq %rsi, %r8
leaq 0x1(%rbp), %rdx
cmpq %rcx, %rdx
movq %r9, 0x18(%rsp)
movq %r8, 0x20(%rsp)
movq %rbp, 0x38(%rsp)
jae 0x1d8db8
movq 0x8(%rax,%rbp,8), %rdx
shrq $0x21, %rdx
movq 0x40(%rsp), %rdi
movq %r9, %rsi
callq 0x1c16f3
testq %rax, %rax
je 0x1d9133
testb $0x40, 0x24(%rax)
jne 0x1d9133
testq %r13, %r13
movq 0x8(%rsp), %rdi
movq 0x20(%rsp), %r8
jne 0x1d8e44
movl 0x14(%rax), %r14d
incl %r14d
movq 0x18(%rsp), %r9
jmp 0x1d8dc8
movq 0x28(%rsp), %rcx
movq 0x10(%rcx), %r14
testq %r14, %r14
je 0x1d90dc
imulq $0x28, %r8, %rcx
addq %rcx, %r14
leaq (%r13,%r8,2), %r13
testq %r15, %r15
je 0x1d8dfd
movq -0x8(%rax,%rbp,8), %rax
shrq $0x21, %rax
cmpq %rdx, %rax
jae 0x1d8e13
movq 0x10(%rbx), %rax
movq %r15, %rcx
shlq $0x4, %rcx
movl -0x10(%rax,%rcx), %esi
cmpq %rsi, %r13
jne 0x1d9048
addq %rcx, %rax
andl $0x0, -0xc(%rax)
movl (%r14), %ecx
movl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
andl %edx, %ecx
movl %ecx, -0x8(%rax)
jmp 0x1d90dc
movl 0x18(%r8), %r14d
andl $0x7fffffff, %r14d      # imm = 0x7FFFFFFF
testq %r13, %r13
jne 0x1d8e3f
testq %r15, %r15
je 0x1d8fa2
movq 0x30(%rdi), %rax
movq 0x48(%rax), %rax
imulq $0x58, %r9, %rsi
movq 0x10(%r8), %rcx
movq (%rcx), %rcx
movl %ecx, %edx
shrq $0x20, %rcx
imulq $0x24, %rcx, %rcx
addq 0x30(%rax,%rsi), %rcx
movb $0x1, %al
xorl %r13d, %r13d
jmp 0x1d8e8e
cmpq $0x0, 0x8(%rbx)
movq 0x10(%rbx), %rax
je 0x1d909b
xorl %ecx, %ecx
jmp 0x1d90ba
movq 0x28(%rsp), %rax
movq 0x18(%rax), %rdi
movq 0x10(%rbx), %rax
shlq $0x4, %r15
movl -0x10(%rax,%r15), %esi
movl %r13d, %edx
callq 0x1de62d
testq %rax, %rax
jne 0x1d9062
jmp 0x1d9190
xorl %r13d, %r13d
jmp 0x1d8e5b
movl 0x18(%rax), %r13d
decl %r13d
movl 0x18(%r8), %r14d
andl $0x7fffffff, %r14d      # imm = 0x7FFFFFFF
movq 0x18(%rsp), %r9
testq %r15, %r15
je 0x1d8f94
movq 0x30(%rdi), %rax
movq 0x48(%rax), %rax
imulq $0x58, %r9, %rsi
movq 0x10(%r8), %rcx
movq -0x8(%rcx,%r14,8), %rcx
movl %ecx, %edx
shrq $0x20, %rcx
imulq $0x24, %rcx, %rcx
addq 0x30(%rax,%rsi), %rcx
xorq $0x1, %rdx
xorl %eax, %eax
movq 0x10(%rbx), %rsi
movq %r15, %r8
shlq $0x4, %r8
cmpl -0x10(%rsi,%r8), %edx
jne 0x1d9152
addq %r8, %rsi
movl 0xc(%rcx), %r8d
movl 0x10(%rcx), %ecx
movl -0xc(%rsi), %edx
movl -0x8(%rsi), %r11d
cmpl %edx, %r8d
movl %edx, %r9d
cmoval %r8d, %r9d
cmpl %r11d, %ecx
movl %r11d, %r10d
cmovbl %ecx, %r10d
cmpl %r9d, %r10d
jbe 0x1d9171
cmpl %edx, %r8d
cmovbl %r8d, %edx
cmpl %r11d, %ecx
cmoval %ecx, %r11d
movl %edx, -0xc(%rsi)
movl %r11d, -0x8(%rsi)
testb %al, %al
je 0x1d8efd
incq %r13
movq 0x18(%rsp), %r9
movq 0x20(%rsp), %r8
jmp 0x1d902b
decq %r14
movq 0x18(%rsp), %r9
movq 0x20(%rsp), %r8
jmp 0x1d8f94
movq 0x30(%rdi), %rax
movq 0x48(%rax), %rax
imulq $0x58, %r9, %rcx
movq 0x30(%rax,%rcx), %r12
movq 0x10(%r8), %rax
movq -0x8(%rax,%r14,8), %rbp
movq 0x10(%rbx), %rax
cmpq 0x8(%rbx), %r15
jne 0x1d8f67
leaq (%r15,%r15), %rsi
testq %r15, %r15
pushq $0x2
popq %rcx
cmoveq %rcx, %rsi
movq %rsi, 0x8(%rbx)
shlq $0x4, %rsi
movq %rax, %rdi
callq 0x2370
movq 0x20(%rsp), %r8
movq 0x18(%rsp), %r9
movq 0x8(%rsp), %rdi
movq %rax, 0x10(%rbx)
movq (%rbx), %r15
movq %rbp, %rcx
shrq $0x20, %rcx
xorl $0x1, %ebp
leaq 0x1(%r15), %rdx
movq %rdx, (%rbx)
shlq $0x4, %r15
movl %ebp, (%rax,%r15)
imulq $0x24, %rcx, %rcx
movq 0xc(%r12,%rcx), %rcx
movq %rcx, 0x4(%rax,%r15)
decq %r14
movq %rdx, %r15
cmpq %r13, %r14
jg 0x1d8f0f
jmp 0x1d9034
xorl %r13d, %r13d
jmp 0x1d902b
movq 0x30(%rdi), %rax
movq 0x48(%rax), %rax
imulq $0x58, %r9, %rcx
movq 0x30(%rax,%rcx), %r12
movq 0x10(%r8), %rax
movq (%rax,%r13,8), %rbp
movq 0x10(%rbx), %rax
cmpq 0x8(%rbx), %r15
jne 0x1d9001
leaq (%r15,%r15), %rsi
testq %r15, %r15
pushq $0x2
popq %rcx
cmoveq %rcx, %rsi
movq %rsi, 0x8(%rbx)
shlq $0x4, %rsi
movq %rax, %rdi
callq 0x2370
movq 0x20(%rsp), %r8
movq 0x18(%rsp), %r9
movq 0x8(%rsp), %rdi
movq %rax, 0x10(%rbx)
movq (%rbx), %r15
movq %rbp, %rcx
shrq $0x20, %rcx
leaq 0x1(%r15), %rdx
movq %rdx, (%rbx)
shlq $0x4, %r15
movl %ebp, (%rax,%r15)
imulq $0x24, %rcx, %rcx
movq 0xc(%r12,%rcx), %rcx
movq %rcx, 0x4(%rax,%r15)
incq %r13
movq %rdx, %r15
cmpq %r14, %r13
jl 0x1d8faa
movq 0x30(%rsp), %r12
movq 0x10(%rsp), %rsi
movq 0x38(%rsp), %rbp
jmp 0x1d90e1
movq 0x28(%rsp), %rax
movq 0x18(%rax), %rdi
movl %r13d, %edx
callq 0x1de62d
testq %rax, %rax
je 0x1d91af
movq (%rbx), %rcx
movq 0x10(%rbx), %rax
cmpq 0x8(%rbx), %rcx
jne 0x1d9094
leaq (%rcx,%rcx), %rsi
testq %rcx, %rcx
pushq $0x2
popq %rcx
cmoveq %rcx, %rsi
movq %rsi, 0x8(%rbx)
shlq $0x4, %rsi
movq %rax, %rdi
callq 0x2370
movq %rax, 0x10(%rbx)
movq (%rbx), %rcx
movq 0x8(%rsp), %rdi
jmp 0x1d90ba
movq $0x2, 0x8(%rbx)
movq %rax, %rdi
pushq $0x20
popq %rsi
callq 0x2370
movq 0x8(%rsp), %rdi
movq %rax, 0x10(%rbx)
movq (%rbx), %rcx
leaq 0x1(%rcx), %r15
movq %r15, (%rbx)
shlq $0x4, %rcx
movl %r13d, (%rax,%rcx)
andl $0x0, 0x4(%rax,%rcx)
movl (%r14), %edx
movl $0x7fffffff, %esi       # imm = 0x7FFFFFFF
andl %esi, %edx
movl %edx, 0x8(%rax,%rcx)
movq 0x10(%rsp), %rsi
incq %rbp
jmp 0x1d8ca0
pushq $0xc
popq %r14
subq $0x1, %r15
jb 0x1d9124
movq 0x10(%rbx), %r12
movl -0xc(%r12,%r14), %eax
movl -0x8(%r12,%r14), %edi
movl -0x4(%r12,%r14), %esi
shrl %eax
imulq $0x28, %rax, %rdx
movq 0x28(%rsp), %rax
addq 0x10(%rax), %rdx
callq 0x1b2312
movl %eax, (%r12,%r14)
addq $0x10, %r14
jmp 0x1d90ed
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x22ed4(%rip), %rdi     # 0x1fc00e
leaq 0x1e398(%rip), %rsi     # 0x1f74d9
leaq 0x22ed8(%rip), %rcx     # 0x1fc020
movl $0x4066, %edx           # imm = 0x4066
callq 0x2110
leaq 0x22f2c(%rip), %rdi     # 0x1fc085
leaq 0x1e379(%rip), %rsi     # 0x1f74d9
leaq 0x22eb9(%rip), %rcx     # 0x1fc020
movl $0x4079, %edx           # imm = 0x4079
callq 0x2110
leaq 0x22f27(%rip), %rdi     # 0x1fc09f
leaq 0x1e35a(%rip), %rsi     # 0x1f74d9
leaq 0x22e9a(%rip), %rcx     # 0x1fc020
movl $0x407b, %edx           # imm = 0x407B
callq 0x2110
leaq 0x22f10(%rip), %rdi     # 0x1fc0a7
leaq 0x1e33b(%rip), %rsi     # 0x1f74d9
leaq 0x22e7b(%rip), %rcx     # 0x1fc020
movl $0x4095, %edx           # imm = 0x4095
callq 0x2110
leaq 0x22ef1(%rip), %rdi     # 0x1fc0a7
leaq 0x1e31c(%rip), %rsi     # 0x1f74d9
leaq 0x22e5c(%rip), %rcx     # 0x1fc020
movl $0x409d, %edx           # imm = 0x409D
callq 0x2110