// File: /workspace/github_cpp_makefile_star2_O2/chhylp123[P]hifiasm/gfa_ut.cpp
// Function: gen_ul_pat_seq(uc_block_t*, path_dp_t*, all_ul_t*, unsigned long, asg_t*, unsigned int, unsigned int, unsigned long*)
int64_t gen_ul_pat_seq(uc_block_t *a, path_dp_t *b, all_ul_t *ul, uint64_t idx, asg_t *g, uint32_t v, uint32_t is_backward, uint64_t *rl)
{
    uint32_t m = 0, pv, ai, pi; uint64_t *t, l = 0, tt, s, e; b->pat.n = 0; b->pat_cor.n = 0;
    if(is_backward) {
        for (ai = idx, l = 0; ai != (uint32_t)-1; ai = a[ai].pidx) {
            pv = (((uint32_t)(a[ai].hid))<<1)|((uint32_t)(a[ai].rev)); pv^=1;
            if((a[ai].pidx != (uint32_t)-1) && (!ulg_len_check(g, pv, &(a[ai])))) break;
            if((b->pat.n > 0) && (!ulg_len_check(g, pv^1, &(a[ai])))) break;
            if(pv == v) m++;
            kv_pushp(uint64_t, b->pat, &t); 
            update_l_coord(g, l, pv, &(a[ai]), &s, &e);
            kv_push(uint64_t, b->pat_cor, ((s<<32)|e));
            (*t) = pv; (*t) |= (l<<32);

            if(a[ai].pidx != (uint32_t)-1) l += a[ai].pdis;
            else l += g->seq[pv>>1].len;
        }
    } else {
        for (ai = idx, pi = 0; ai != (uint32_t)-1; ai = a[ai].aidx) {
            pv = (((uint32_t)(a[ai].hid))<<1)|((uint32_t)(a[ai].rev));
            if((a[ai].aidx != (uint32_t)-1) && (!ulg_len_check(g, pv, &(a[ai])))) break;
            if((pi > 0) && (!ulg_len_check(g, pv^1, &(a[ai])))) break;
            l = ai; pi++;
        }

        ai = l;
        kv_resize(uint64_t, b->pat, pi); b->pat.n = pi; 
        kv_resize(uint64_t, b->pat_cor, pi); b->pat_cor.n = pi; 
        for (l = 0; ai != (uint32_t)-1 && ai >= idx; ai = a[ai].pidx) {
            pv = (((uint32_t)(a[ai].hid))<<1)|((uint32_t)(a[ai].rev));
            pi--; if(pv == v) m++;
            b->pat.a[pi] = pv; b->pat.a[pi] |= (l<<32); 
            update_l_coord(g, l, pv, &(a[ai]), &s, &e);
            b->pat_cor.a[pi] = ((s<<32)|e);
            if(a[ai].pidx != (uint32_t)-1 && a[ai].pidx >= idx) l += a[ai].pdis;
            else l += g->seq[pv>>1].len;
        }
        assert(pi == 0);
        
        for (ai = 0; ai < b->pat.n; ai++) {
            tt = (b->pat.a[ai]>>32) + g->seq[((uint32_t)b->pat.a[ai])>>1].len;
            // if(l < tt) {
            //     fprintf(stderr, "\n[M::%s::] ai::%u, b->pat.n::%u, l::%lu, tt::%lu, beg::%lu\n", 
            //     __func__, ai, (uint32_t)b->pat.n, l, tt, (b->pat.a[ai]>>32));
            // }
            assert(l >= tt);
            tt = l - tt;
            b->pat.a[ai] = (uint32_t)b->pat.a[ai];
            b->pat.a[ai] += (tt<<32);
        }
    }
    (*rl) = l;

    assert(m > 0);
    return m;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movl %r9d, 0x24(%rsp)
movq %rsi, %rbx
andq $0x0, 0x18(%rsi)
andq $0x0, 0x30(%rsi)
movq %rdi, 0x40(%rsp)
cmpl $0x0, 0xa0(%rsp)
movq %r8, 0x10(%rsp)
je 0x1b0482
xorl %r15d, %r15d
xorl %r9d, %r9d
cmpl $-0x1, %ecx
je 0x1b0754
movl %ecx, %eax
imulq $0x24, %rax, %rax
movq 0x40(%rsp), %rdx
leaq (%rdx,%rax), %rbp
movl (%rdx,%rax), %esi
movl 0x20(%rdx,%rax), %ecx
shrl $0x5, %ecx
andl $0x1, %ecx
movq %rsi, 0x30(%rsp)
leal (%rcx,%rsi,2), %r14d
movl %r14d, %r13d
xorl $0x1, %r13d
cmpl $-0x1, 0x14(%rdx,%rax)
movq %r9, %r12
je 0x1b0348
movq 0x10(%rsp), %rdi
movl %r13d, %esi
movq %rbp, %rdx
callq 0x1b01be
movq %r12, %r9
testq %rax, %rax
je 0x1b0754
movq %r15, 0x18(%rsp)
movq 0x18(%rbx), %r15
testq %r15, %r15
je 0x1b0372
movq 0x10(%rsp), %rdi
movl %r14d, %esi
movq %rbp, %rdx
callq 0x1b01be
movq %r12, %r9
testq %rax, %rax
je 0x1b074f
cmpl 0x24(%rsp), %r13d
sete %al
movq 0x28(%rbx), %r14
cmpq 0x20(%rbx), %r15
movb %al, 0x28(%rsp)
jne 0x1b03b4
leaq (%r15,%r15), %rsi
testq %r15, %r15
pushq $0x2
popq %rax
cmoveq %rax, %rsi
movq %rsi, 0x20(%rbx)
shlq $0x3, %rsi
movq %r14, %rdi
callq 0x2370
movq %r12, %r9
movq %rax, %r14
movq %rax, 0x28(%rbx)
movq 0x18(%rbx), %r15
leaq 0x1(%r15), %rax
movq %rax, 0x18(%rbx)
movq 0x10(%rsp), %rdi
movq %r9, %rsi
movl %r13d, %edx
movq %rbp, %rcx
leaq 0x50(%rsp), %r8
leaq 0x48(%rsp), %r9
callq 0x1b0267
movq 0x30(%rbx), %rcx
movq 0x40(%rbx), %rax
cmpq 0x38(%rbx), %rcx
jne 0x1b040d
leaq (%rcx,%rcx), %rsi
testq %rcx, %rcx
pushq $0x2
popq %rcx
cmoveq %rcx, %rsi
movq %rsi, 0x38(%rbx)
shlq $0x3, %rsi
movq %rax, %rdi
callq 0x2370
movq %rax, 0x40(%rbx)
movq 0x30(%rbx), %rcx
xorl %edi, %edi
movb 0x28(%rsp), %r8b
movq 0x50(%rsp), %rdx
shlq $0x20, %rdx
orq 0x48(%rsp), %rdx
leaq 0x1(%rcx), %rsi
movq %rsi, 0x30(%rbx)
movq %rdx, (%rax,%rcx,8)
movl %r13d, %eax
movq %r12, %r9
movq %r12, %rcx
shlq $0x20, %rcx
orq %rax, %rcx
movq %rcx, (%r14,%r15,8)
movl 0x14(%rbp), %ecx
cmpl $-0x1, %ecx
je 0x1b044f
movl 0x18(%rbp), %eax
jmp 0x1b046d
movq 0x10(%rsp), %rax
movq 0x20(%rax), %rax
movq 0x30(%rsp), %rdx
andl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
movl (%rax,%rdx,8), %eax
movl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
andl %edx, %eax
movq 0x18(%rsp), %r15
movb %r8b, %dil
addl %edi, %r15d
movl %eax, %eax
addq %rax, %r9
jmp 0x1b02ed
movq %rbx, 0x38(%rsp)
xorl %r12d, %r12d
movq %rcx, 0x58(%rsp)
movl %ecx, %ebx
xorl %r15d, %r15d
movl %r15d, %r13d
movl %r12d, %edi
cmpl $-0x1, %ebx
je 0x1b050a
movl %ebx, %r15d
movl %ebx, %eax
imulq $0x24, %rax, %rax
movq 0x40(%rsp), %rsi
leaq (%rsi,%rax), %r14
movl 0x20(%rsi,%rax), %ecx
shrl $0x5, %ecx
andl $0x1, %ecx
movl (%rsi,%rax), %edx
movl 0x1c(%rsi,%rax), %ebx
leal (%rcx,%rdx,2), %ebp
cmpl $-0x1, %ebx
je 0x1b04e4
movl %edi, %r12d
movq 0x10(%rsp), %rdi
movl %ebp, %esi
movq %r14, %rdx
callq 0x1b01be
movl %r12d, %edi
testq %rax, %rax
je 0x1b050a
movl %edi, %r12d
subl $0x1, %r12d
jb 0x1b0494
xorl $0x1, %ebp
movq %r14, %rdx
movl %edi, %r14d
movq 0x10(%rsp), %rdi
movl %ebp, %esi
callq 0x1b01be
movl %r14d, %edi
testq %rax, %rax
jne 0x1b0494
movl %edi, %r14d
negl %r14d
movq 0x38(%rsp), %r12
cmpq %r14, 0x20(%r12)
jae 0x1b0575
leaq -0x1(%r14), %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, 0x20(%r12)
movl %edi, %ebx
movq 0x28(%r12), %rdi
leaq 0x8(,%rcx,8), %rsi
callq 0x2370
movl %ebx, %edi
movq %rax, 0x28(%r12)
movq %r14, 0x18(%r12)
cmpq %r14, 0x38(%r12)
jae 0x1b05da
leaq -0x1(%r14), %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, 0x38(%r12)
movl %edi, %ebx
movq 0x40(%r12), %rdi
leaq 0x8(,%rcx,8), %rsi
callq 0x2370
movl %ebx, %edi
movq %rax, 0x40(%r12)
notl %edi
movq %r14, 0x30(%r12)
xorl %r15d, %r15d
xorl %r9d, %r9d
movq 0x58(%rsp), %rdx
movq 0x40(%rsp), %rbx
movq 0x10(%rsp), %r14
cmpl $-0x1, %r13d
je 0x1b06f4
movl %r13d, %eax
cmpq %rdx, %rax
jb 0x1b06f4
movq %r15, 0x18(%rsp)
imulq $0x24, %rax, %r13
leaq (%rbx,%r13), %rcx
movl (%rbx,%r13), %ebp
movl 0x20(%rbx,%r13), %eax
shrl $0x5, %eax
andl $0x1, %eax
leal (%rax,%rbp,2), %edx
xorl %r15d, %r15d
cmpl 0x24(%rsp), %edx
sete 0xf(%rsp)
movq 0x28(%r12), %rax
movl %edi, 0x30(%rsp)
movl %edi, %r12d
movq %r9, %rsi
shlq $0x20, %rsi
orq %rdx, %rsi
movq %rsi, (%rax,%r12,8)
movq %r14, %rdi
movq %r9, 0x28(%rsp)
movq %r9, %rsi
movq %rcx, 0x60(%rsp)
leaq 0x50(%rsp), %r8
leaq 0x48(%rsp), %r9
callq 0x1b0267
movq 0x58(%rsp), %rdx
movq 0x50(%rsp), %rax
shlq $0x20, %rax
orq 0x48(%rsp), %rax
movq 0x38(%rsp), %rcx
movq 0x40(%rcx), %rcx
movq %rax, (%rcx,%r12,8)
movl 0x14(%rbx,%r13), %r13d
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmpq %rax, %r13
sete %al
cmpq %rdx, %r13
setb %cl
orb %al, %cl
je 0x1b06c0
movq 0x20(%r14), %rax
andl $0x7fffffff, %ebp       # imm = 0x7FFFFFFF
movl (%rax,%rbp,8), %eax
movl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
andl %ecx, %eax
jmp 0x1b06c8
movq 0x60(%rsp), %rax
movl 0x18(%rax), %eax
movb 0xf(%rsp), %cl
movb %cl, %r15b
movq 0x18(%rsp), %rcx
addl %r15d, %ecx
movq %rcx, %r15
movl %eax, %eax
movq 0x28(%rsp), %r9
addq %rax, %r9
movl 0x30(%rsp), %edi
decl %edi
movq 0x38(%rsp), %r12
jmp 0x1b05f6
cmpl $-0x1, %edi
jne 0x1b07b4
xorl %eax, %eax
movl %eax, %eax
cmpq %rax, 0x18(%r12)
jbe 0x1b0754
movq 0x28(%r12), %rcx
movq (%rcx,%rax,8), %rdx
movq %rdx, %rdi
shrq $0x20, %rdi
movq 0x10(%rsp), %rsi
movq 0x20(%rsi), %rsi
movl %edx, %r8d
shrl %r8d
movl (%rsi,%r8,8), %esi
andl $0x7fffffff, %esi       # imm = 0x7FFFFFFF
addq %rdi, %rsi
cmpq %rsi, %r9
jb 0x1b0776
movl %r9d, %edi
subl %esi, %edi
movl %edx, %edx
shlq $0x20, %rdi
orq %rdx, %rdi
movq %rdi, (%rcx,%rax,8)
incl %eax
jmp 0x1b06ff
movq 0x18(%rsp), %r15
movq 0xa8(%rsp), %rax
movq %r9, (%rax)
testl %r15d, %r15d
je 0x1b0795
movl %r15d, %eax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x476e3(%rip), %rdi     # 0x1f7e60
leaq 0x46d55(%rip), %rsi     # 0x1f74d9
leaq 0x47664(%rip), %rcx     # 0x1f7def
movl $0xd8c, %edx            # imm = 0xD8C
callq 0x2110
leaq 0x4b7b0(%rip), %rdi     # 0x1fbf4c
leaq 0x46d36(%rip), %rsi     # 0x1f74d9
leaq 0x47645(%rip), %rcx     # 0x1f7def
movl $0xd94, %edx            # imm = 0xD94
callq 0x2110
leaq 0x4762c(%rip), %rdi     # 0x1f7de7
leaq 0x46d17(%rip), %rsi     # 0x1f74d9
leaq 0x47626(%rip), %rcx     # 0x1f7def
movl $0xd84, %edx            # imm = 0xD84
callq 0x2110