// File: /workspace/github_cpp_makefile_star2_O1/chhylp123[P]hifiasm/gfa_ut.cpp
// Function: gen_ul_seq(ul_resolve_t*, unsigned long, asgc8_v*)
void gen_ul_seq(ul_resolve_t *uidx, uint64_t iug_id, asgc8_v * res)
{
    ul2ul_idx_t *idx = &(uidx->uovl); ma_ug_t *raw = uidx->l1_ug; uint64_t k, m, s, e, ol, rev, Ns;
    uinfo_srt_warp_t *seq = &(idx->cc.iug_a[iug_id]); ma_utg_t *ru; asg_arc_t *z; 
    for (k = res->n = 0; k < seq->n; k++) {
        s = seq->a[k].s; e = seq->a[k].e; rev = seq->a[k].v&1; 
        ru = &(raw->u.a[seq->a[k].v>>1]); Ns = 0;
        if(k + 1 < seq->n) {
            z = get_specfic_edge(raw->g, seq->a[k].v, seq->a[k+1].v);
            if(z) {
                ol = z->ol;
                if(!rev) {
                    // assert(seq->a[k].e == ru->len);
                    e = (ru->len > ol)?(ru->len-ol):(0);
                } else {
                    // assert(seq->a[k].s == 0);
                    s = ol;
                }
            } else {
                Ns = 50;
            }
        }
        if(s < e) {
            kv_resize(char, (*res), res->n + e - s);
            retrieve_u_seq(NULL, res->a + res->n, ru, rev, (rev)?(ru->len-e):(s), e - s, NULL);
            res->n += e - s;
        }

        if(Ns) {
            kv_resize(char, (*res), res->n + Ns);
            for (m = 0; m < Ns; m++) res->a[res->n++] = 'N';
        }        
    }
    
    kv_push(char, *res, '\0');    
    // fprintf(stderr, "[M::%s::iug_id->%lu] # u->len::%u, # res->n::%u, # strlen(res->a)::%u\n", 
    // __func__, iug_id, idx->i_ug->u.a[iug_id].len, (uint32_t)res->n, (uint32_t)strlen(res->a));
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rdx, %rbx
movq 0x18(%rdi), %r14
movq 0x260(%rdi), %rcx
leaq (%rsi,%rsi,2), %rdx
movq $0x0, (%rbx)
movq (%rcx,%rdx,8), %rax
testq %rax, %rax
je 0x1ff5dd
leaq (%rcx,%rdx,8), %r9
xorl %r10d, %r10d
movq %r14, 0x28(%rsp)
movq %r9, 0x20(%rsp)
movq 0x10(%r9), %rcx
movq %r10, %rsi
shlq $0x4, %rsi
movl (%rcx,%rsi), %edx
movl 0x4(%rcx,%rsi), %r8d
movl 0x8(%rcx,%rsi), %r11d
movl %edx, %ebp
andl $0x1, %ebp
movl %edx, %esi
shrl %esi
leaq (%rsi,%rsi,4), %r15
shlq $0x3, %r15
addq 0x10(%r14), %r15
incq %r10
cmpq %rax, %r10
jae 0x1ff449
movq 0x18(%r14), %rsi
movq 0x28(%rsi), %rax
movq (%rax,%rdx,8), %rax
movq %rax, %rdx
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
andq %rdi, %rdx
je 0x1ff410
movq %r10, %rdi
shlq $0x4, %rdi
movl (%rcx,%rdi), %ecx
shrq $0x20, %rax
leaq (%rax,%rax,2), %rax
shlq $0x3, %rax
addq 0x8(%rsi), %rax
cmpl $0x0, 0xc(%rax)
js 0x1ff407
cmpl %ecx, 0x8(%rax)
je 0x1ff412
addq $0x18, %rax
decq %rdx
jne 0x1ff3fc
xorl %eax, %eax
testq %rax, %rax
je 0x1ff45a
movl 0xc(%rax), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movb $0x1, %sil
testl %ebp, %ebp
jne 0x1ff46b
movl (%r15), %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
movq %rcx, %r11
subq %rax, %r11
xorl %edx, %edx
cmpl %eax, %ecx
movl $0x0, %eax
movq %rax, 0x10(%rsp)
cmovbeq %rdx, %r11
jmp 0x1ff455
movb $0x1, %sil
movq $0x0, 0x10(%rsp)
xorl %r13d, %r13d
jmp 0x1ff47a
movl $0x32, %r13d
movb $0x1, %al
movq %rax, 0x10(%rsp)
xorl %esi, %esi
jmp 0x1ff47a
movq $0x0, 0x10(%rsp)
xorl %r13d, %r13d
movq %rax, %r8
movq %r11, %r12
subq %r8, %r12
jbe 0x1ff53e
movl %esi, 0x1c(%rsp)
movq %r10, 0x30(%rsp)
movq (%rbx), %rax
addq %r12, %rax
cmpq %rax, 0x8(%rbx)
jae 0x1ff4f7
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, %rsi
shrq $0x10, %rsi
orq %rax, %rsi
incq %rsi
movq %rsi, 0x8(%rbx)
movq 0x10(%rbx), %rdi
movl %ebp, 0x18(%rsp)
movq %r8, %rbp
movq %r11, %r14
callq 0x2370
movq %r14, %r11
movq %rbp, %r8
movl 0x18(%rsp), %ebp
movq %rax, 0x10(%rbx)
movq 0x10(%rbx), %rsi
addq (%rbx), %rsi
testl %ebp, %ebp
je 0x1ff50f
movl (%r15), %r8d
andl $0x7fffffff, %r8d       # imm = 0x7FFFFFFF
subq %r11, %r8
movq $0x0, (%rsp)
movzbl %bpl, %ecx
xorl %edi, %edi
movq %r15, %rdx
movq %r12, %r9
callq 0x36b0d
addq %r12, (%rbx)
movq 0x28(%rsp), %r14
movq 0x20(%rsp), %r9
movq 0x30(%rsp), %r10
movl 0x1c(%rsp), %esi
testb %sil, %sil
jne 0x1ff5d1
movq (%rbx), %rax
addq %r13, %rax
cmpq %rax, 0x8(%rbx)
jae 0x1ff5ab
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, %rsi
shrq $0x10, %rsi
orq %rax, %rsi
incq %rsi
movq %rsi, 0x8(%rbx)
movq 0x10(%rbx), %rdi
movq %r10, %r14
callq 0x2370
movq %r14, %r10
movq 0x20(%rsp), %r9
movq 0x28(%rsp), %r14
movq %rax, 0x10(%rbx)
cmpb $0x0, 0x10(%rsp)
je 0x1ff5d1
cmpq $0x1, %r13
adcq $0x0, %r13
movq (%rbx), %rax
movq 0x10(%rbx), %rcx
leaq 0x1(%rax), %rdx
movq %rdx, (%rbx)
movb $0x4e, (%rcx,%rax)
decq %r13
jne 0x1ff5ba
movq (%r9), %rax
cmpq %rax, %r10
jb 0x1ff390
movq 0x8(%rbx), %rax
cmpq %rax, (%rbx)
jne 0x1ff607
leaq (%rax,%rax), %rcx
testq %rax, %rax
movl $0x2, %esi
cmovneq %rcx, %rsi
movq %rsi, 0x8(%rbx)
movq 0x10(%rbx), %rdi
callq 0x2370
movq %rax, 0x10(%rbx)
movq (%rbx), %rax
movq 0x10(%rbx), %rcx
leaq 0x1(%rax), %rdx
movq %rdx, (%rbx)
movb $0x0, (%rcx,%rax)
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq