// File: 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
movq %rsp, %rbp
subq $0x80, %rsp
movq 0x18(%rbp), %rax
movl 0x10(%rbp), %eax
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
movl %r9d, -0x2c(%rbp)
movl $0x0, -0x30(%rbp)
movq $0x0, -0x50(%rbp)
movq -0x10(%rbp), %rax
movq $0x0, 0x18(%rax)
movq -0x10(%rbp), %rax
movq $0x0, 0x30(%rax)
cmpl $0x0, 0x10(%rbp)
je 0x323464
movq -0x20(%rbp), %rax
movl %eax, -0x38(%rbp)
movq $0x0, -0x50(%rbp)
cmpl $-0x1, -0x38(%rbp)
je 0x32345f
movq -0x8(%rbp), %rax
movl -0x38(%rbp), %ecx
imulq $0x24, %rcx, %rcx
addq %rcx, %rax
movl (%rax), %eax
shll %eax
movq -0x8(%rbp), %rcx
movl -0x38(%rbp), %edx
imulq $0x24, %rdx, %rdx
addq %rdx, %rcx
movb 0x20(%rcx), %cl
shrb $0x5, %cl
andb $0x1, %cl
movzbl %cl, %ecx
orl %ecx, %eax
movl %eax, -0x34(%rbp)
movl -0x34(%rbp), %eax
xorl $0x1, %eax
movl %eax, -0x34(%rbp)
movq -0x8(%rbp), %rax
movl -0x38(%rbp), %ecx
imulq $0x24, %rcx, %rcx
addq %rcx, %rax
cmpl $-0x1, 0x14(%rax)
je 0x323247
movq -0x28(%rbp), %rdi
movl -0x34(%rbp), %esi
movq -0x8(%rbp), %rdx
movl -0x38(%rbp), %eax
imulq $0x24, %rax, %rax
addq %rax, %rdx
callq 0x322f60
cmpq $0x0, %rax
jne 0x323247
jmp 0x32345f
movq -0x10(%rbp), %rax
cmpq $0x0, 0x18(%rax)
jbe 0x32327a
movq -0x28(%rbp), %rdi
movl -0x34(%rbp), %esi
xorl $0x1, %esi
movq -0x8(%rbp), %rdx
movl -0x38(%rbp), %eax
imulq $0x24, %rax, %rax
addq %rax, %rdx
callq 0x322f60
cmpq $0x0, %rax
jne 0x32327a
jmp 0x32345f
movl -0x34(%rbp), %eax
cmpl -0x2c(%rbp), %eax
jne 0x32328b
movl -0x30(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rbp)
jmp 0x32328d
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
movq -0x10(%rbp), %rcx
cmpq 0x20(%rcx), %rax
jne 0x3232f6
movq -0x10(%rbp), %rax
cmpq $0x0, 0x20(%rax)
je 0x3232bb
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rax
shlq %rax
movq %rax, -0x70(%rbp)
jmp 0x3232c6
movl $0x2, %eax
movq %rax, -0x70(%rbp)
jmp 0x3232c6
movq -0x70(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x20(%rax)
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rdi
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rsi
shlq $0x3, %rsi
callq 0x2360
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x28(%rax)
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rax
movq -0x10(%rbp), %rdx
movq 0x18(%rdx), %rcx
movq %rcx, %rsi
addq $0x1, %rsi
movq %rsi, 0x18(%rdx)
shlq $0x3, %rcx
addq %rcx, %rax
movq %rax, -0x48(%rbp)
movq -0x28(%rbp), %rdi
movq -0x50(%rbp), %rsi
movl -0x34(%rbp), %edx
movq -0x8(%rbp), %rcx
movl -0x38(%rbp), %eax
imulq $0x24, %rax, %rax
addq %rax, %rcx
leaq -0x60(%rbp), %r8
leaq -0x68(%rbp), %r9
callq 0x3230a0
movq -0x10(%rbp), %rax
movq 0x30(%rax), %rax
movq -0x10(%rbp), %rcx
cmpq 0x38(%rcx), %rax
jne 0x3233ab
movq -0x10(%rbp), %rax
cmpq $0x0, 0x38(%rax)
je 0x323370
movq -0x10(%rbp), %rax
movq 0x38(%rax), %rax
shlq %rax
movq %rax, -0x78(%rbp)
jmp 0x32337b
movl $0x2, %eax
movq %rax, -0x78(%rbp)
jmp 0x32337b
movq -0x78(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x38(%rax)
movq -0x10(%rbp), %rax
movq 0x40(%rax), %rdi
movq -0x10(%rbp), %rax
movq 0x38(%rax), %rsi
shlq $0x3, %rsi
callq 0x2360
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x40(%rax)
movq -0x60(%rbp), %rdx
shlq $0x20, %rdx
orq -0x68(%rbp), %rdx
movq -0x10(%rbp), %rax
movq 0x40(%rax), %rax
movq -0x10(%rbp), %rsi
movq 0x30(%rsi), %rcx
movq %rcx, %rdi
addq $0x1, %rdi
movq %rdi, 0x30(%rsi)
movq %rdx, (%rax,%rcx,8)
movl -0x34(%rbp), %eax
movl %eax, %ecx
movq -0x48(%rbp), %rax
movq %rcx, (%rax)
movq -0x50(%rbp), %rcx
shlq $0x20, %rcx
movq -0x48(%rbp), %rax
orq (%rax), %rcx
movq %rcx, (%rax)
movq -0x8(%rbp), %rax
movl -0x38(%rbp), %ecx
imulq $0x24, %rcx, %rcx
addq %rcx, %rax
cmpl $-0x1, 0x14(%rax)
je 0x323423
movq -0x8(%rbp), %rax
movl -0x38(%rbp), %ecx
imulq $0x24, %rcx, %rcx
addq %rcx, %rax
movl 0x18(%rax), %eax
addq -0x50(%rbp), %rax
movq %rax, -0x50(%rbp)
jmp 0x323444
movq -0x28(%rbp), %rax
movq 0x20(%rax), %rax
movl -0x34(%rbp), %ecx
shrl %ecx
movl %ecx, %ecx
movl (%rax,%rcx,8), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movl %eax, %eax
addq -0x50(%rbp), %rax
movq %rax, -0x50(%rbp)
jmp 0x323446
movq -0x8(%rbp), %rax
movl -0x38(%rbp), %ecx
imulq $0x24, %rcx, %rcx
addq %rcx, %rax
movl 0x14(%rax), %eax
movl %eax, -0x38(%rbp)
jmp 0x3231ca
jmp 0x323980
movq -0x20(%rbp), %rax
movl %eax, -0x38(%rbp)
movl $0x0, -0x3c(%rbp)
cmpl $-0x1, -0x38(%rbp)
je 0x323537
movq -0x8(%rbp), %rax
movl -0x38(%rbp), %ecx
imulq $0x24, %rcx, %rcx
addq %rcx, %rax
movl (%rax), %eax
shll %eax
movq -0x8(%rbp), %rcx
movl -0x38(%rbp), %edx
imulq $0x24, %rdx, %rdx
addq %rdx, %rcx
movb 0x20(%rcx), %cl
shrb $0x5, %cl
andb $0x1, %cl
movzbl %cl, %ecx
orl %ecx, %eax
movl %eax, -0x34(%rbp)
movq -0x8(%rbp), %rax
movl -0x38(%rbp), %ecx
imulq $0x24, %rcx, %rcx
addq %rcx, %rax
cmpl $-0x1, 0x1c(%rax)
je 0x3234e3
movq -0x28(%rbp), %rdi
movl -0x34(%rbp), %esi
movq -0x8(%rbp), %rdx
movl -0x38(%rbp), %eax
imulq $0x24, %rax, %rax
addq %rax, %rdx
callq 0x322f60
cmpq $0x0, %rax
jne 0x3234e3
jmp 0x323537
cmpl $0x0, -0x3c(%rbp)
jbe 0x32350e
movq -0x28(%rbp), %rdi
movl -0x34(%rbp), %esi
xorl $0x1, %esi
movq -0x8(%rbp), %rdx
movl -0x38(%rbp), %eax
imulq $0x24, %rax, %rax
addq %rax, %rdx
callq 0x322f60
cmpq $0x0, %rax
jne 0x32350e
jmp 0x323537
movl -0x38(%rbp), %eax
movq %rax, -0x50(%rbp)
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
movq -0x8(%rbp), %rax
movl -0x38(%rbp), %ecx
imulq $0x24, %rcx, %rcx
addq %rcx, %rax
movl 0x1c(%rax), %eax
movl %eax, -0x38(%rbp)
jmp 0x323472
movq -0x50(%rbp), %rax
movl %eax, -0x38(%rbp)
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rax
movl -0x3c(%rbp), %ecx
cmpq %rcx, %rax
jae 0x32361a
movl -0x3c(%rbp), %eax
movl %eax, %ecx
movq -0x10(%rbp), %rax
movq %rcx, 0x20(%rax)
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rcx
addq $-0x1, %rcx
movq %rcx, 0x20(%rax)
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rcx
shrq %rcx
movq -0x10(%rbp), %rax
orq 0x20(%rax), %rcx
movq %rcx, 0x20(%rax)
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rcx
shrq $0x2, %rcx
movq -0x10(%rbp), %rax
orq 0x20(%rax), %rcx
movq %rcx, 0x20(%rax)
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rcx
shrq $0x4, %rcx
movq -0x10(%rbp), %rax
orq 0x20(%rax), %rcx
movq %rcx, 0x20(%rax)
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rcx
shrq $0x8, %rcx
movq -0x10(%rbp), %rax
orq 0x20(%rax), %rcx
movq %rcx, 0x20(%rax)
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rcx
shrq $0x10, %rcx
movq -0x10(%rbp), %rax
orq 0x20(%rax), %rcx
movq %rcx, 0x20(%rax)
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rcx
addq $0x1, %rcx
movq %rcx, 0x20(%rax)
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rdi
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rsi
shlq $0x3, %rsi
callq 0x2360
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x28(%rax)
jmp 0x32361c
movl -0x3c(%rbp), %eax
movl %eax, %ecx
movq -0x10(%rbp), %rax
movq %rcx, 0x18(%rax)
movq -0x10(%rbp), %rax
movq 0x38(%rax), %rax
movl -0x3c(%rbp), %ecx
cmpq %rcx, %rax
jae 0x323705
movl -0x3c(%rbp), %eax
movl %eax, %ecx
movq -0x10(%rbp), %rax
movq %rcx, 0x38(%rax)
movq -0x10(%rbp), %rax
movq 0x38(%rax), %rcx
addq $-0x1, %rcx
movq %rcx, 0x38(%rax)
movq -0x10(%rbp), %rax
movq 0x38(%rax), %rcx
shrq %rcx
movq -0x10(%rbp), %rax
orq 0x38(%rax), %rcx
movq %rcx, 0x38(%rax)
movq -0x10(%rbp), %rax
movq 0x38(%rax), %rcx
shrq $0x2, %rcx
movq -0x10(%rbp), %rax
orq 0x38(%rax), %rcx
movq %rcx, 0x38(%rax)
movq -0x10(%rbp), %rax
movq 0x38(%rax), %rcx
shrq $0x4, %rcx
movq -0x10(%rbp), %rax
orq 0x38(%rax), %rcx
movq %rcx, 0x38(%rax)
movq -0x10(%rbp), %rax
movq 0x38(%rax), %rcx
shrq $0x8, %rcx
movq -0x10(%rbp), %rax
orq 0x38(%rax), %rcx
movq %rcx, 0x38(%rax)
movq -0x10(%rbp), %rax
movq 0x38(%rax), %rcx
shrq $0x10, %rcx
movq -0x10(%rbp), %rax
orq 0x38(%rax), %rcx
movq %rcx, 0x38(%rax)
movq -0x10(%rbp), %rax
movq 0x38(%rax), %rcx
addq $0x1, %rcx
movq %rcx, 0x38(%rax)
movq -0x10(%rbp), %rax
movq 0x40(%rax), %rdi
movq -0x10(%rbp), %rax
movq 0x38(%rax), %rsi
shlq $0x3, %rsi
callq 0x2360
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x40(%rax)
jmp 0x323707
movl -0x3c(%rbp), %eax
movl %eax, %ecx
movq -0x10(%rbp), %rax
movq %rcx, 0x30(%rax)
movq $0x0, -0x50(%rbp)
xorl %eax, %eax
cmpl $-0x1, -0x38(%rbp)
movb %al, -0x79(%rbp)
je 0x323734
movl -0x38(%rbp), %eax
cmpq -0x20(%rbp), %rax
setae %al
movb %al, -0x79(%rbp)
movb -0x79(%rbp), %al
testb $0x1, %al
jne 0x323740
jmp 0x32387d
movq -0x8(%rbp), %rax
movl -0x38(%rbp), %ecx
imulq $0x24, %rcx, %rcx
addq %rcx, %rax
movl (%rax), %eax
shll %eax
movq -0x8(%rbp), %rcx
movl -0x38(%rbp), %edx
imulq $0x24, %rdx, %rdx
addq %rdx, %rcx
movb 0x20(%rcx), %cl
shrb $0x5, %cl
andb $0x1, %cl
movzbl %cl, %ecx
orl %ecx, %eax
movl %eax, -0x34(%rbp)
movl -0x3c(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x3c(%rbp)
movl -0x34(%rbp), %eax
cmpl -0x2c(%rbp), %eax
jne 0x32378b
movl -0x30(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rbp)
movl -0x34(%rbp), %eax
movl %eax, %edx
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rax
movl -0x3c(%rbp), %ecx
movq %rdx, (%rax,%rcx,8)
movq -0x50(%rbp), %rdx
shlq $0x20, %rdx
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rax
movl -0x3c(%rbp), %ecx
orq (%rax,%rcx,8), %rdx
movq %rdx, (%rax,%rcx,8)
movq -0x28(%rbp), %rdi
movq -0x50(%rbp), %rsi
movl -0x34(%rbp), %edx
movq -0x8(%rbp), %rcx
movl -0x38(%rbp), %eax
imulq $0x24, %rax, %rax
addq %rax, %rcx
leaq -0x60(%rbp), %r8
leaq -0x68(%rbp), %r9
callq 0x3230a0
movq -0x60(%rbp), %rdx
shlq $0x20, %rdx
orq -0x68(%rbp), %rdx
movq -0x10(%rbp), %rax
movq 0x40(%rax), %rax
movl -0x3c(%rbp), %ecx
movq %rdx, (%rax,%rcx,8)
movq -0x8(%rbp), %rax
movl -0x38(%rbp), %ecx
imulq $0x24, %rcx, %rcx
addq %rcx, %rax
cmpl $-0x1, 0x14(%rax)
je 0x323841
movq -0x8(%rbp), %rax
movl -0x38(%rbp), %ecx
imulq $0x24, %rcx, %rcx
addq %rcx, %rax
movl 0x14(%rax), %eax
cmpq -0x20(%rbp), %rax
jb 0x323841
movq -0x8(%rbp), %rax
movl -0x38(%rbp), %ecx
imulq $0x24, %rcx, %rcx
addq %rcx, %rax
movl 0x18(%rax), %eax
addq -0x50(%rbp), %rax
movq %rax, -0x50(%rbp)
jmp 0x323862
movq -0x28(%rbp), %rax
movq 0x20(%rax), %rax
movl -0x34(%rbp), %ecx
shrl %ecx
movl %ecx, %ecx
movl (%rax,%rcx,8), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movl %eax, %eax
addq -0x50(%rbp), %rax
movq %rax, -0x50(%rbp)
jmp 0x323864
movq -0x8(%rbp), %rax
movl -0x38(%rbp), %ecx
imulq $0x24, %rcx, %rcx
addq %rcx, %rax
movl 0x14(%rax), %eax
movl %eax, -0x38(%rbp)
jmp 0x32371c
cmpl $0x0, -0x3c(%rbp)
jne 0x323885
jmp 0x3238a4
leaq 0x7323b(%rip), %rdi     # 0x396ac7
leaq 0x72926(%rip), %rsi     # 0x3961b9
movl $0xd84, %edx            # imm = 0xD84
leaq 0x73230(%rip), %rcx     # 0x396acf
callq 0x2130
movl $0x0, -0x38(%rbp)
movl -0x38(%rbp), %eax
movq -0x10(%rbp), %rcx
cmpq 0x18(%rcx), %rax
jae 0x32397e
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rax
movl -0x38(%rbp), %ecx
movq (%rax,%rcx,8), %rax
shrq $0x20, %rax
movq -0x28(%rbp), %rcx
movq 0x20(%rcx), %rcx
movq -0x10(%rbp), %rdx
movq 0x28(%rdx), %rdx
movl -0x38(%rbp), %esi
movq (%rdx,%rsi,8), %rdx
shrl %edx
movl %edx, %edx
movl (%rcx,%rdx,8), %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
movl %ecx, %ecx
addq %rcx, %rax
movq %rax, -0x58(%rbp)
movq -0x50(%rbp), %rax
cmpq -0x58(%rbp), %rax
jb 0x323908
jmp 0x323927
leaq 0x73231(%rip), %rdi     # 0x396b40
leaq 0x728a3(%rip), %rsi     # 0x3961b9
movl $0xd8c, %edx            # imm = 0xD8C
leaq 0x731ad(%rip), %rcx     # 0x396acf
callq 0x2130
movq -0x50(%rbp), %rax
subq -0x58(%rbp), %rax
movq %rax, -0x58(%rbp)
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rax
movl -0x38(%rbp), %ecx
movq (%rax,%rcx,8), %rax
movl %eax, %eax
movl %eax, %edx
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rax
movl -0x38(%rbp), %ecx
movq %rdx, (%rax,%rcx,8)
movq -0x58(%rbp), %rdx
shlq $0x20, %rdx
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rax
movl -0x38(%rbp), %ecx
addq (%rax,%rcx,8), %rdx
movq %rdx, (%rax,%rcx,8)
movl -0x38(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
jmp 0x3238ab
jmp 0x323980
movq -0x50(%rbp), %rcx
movq 0x18(%rbp), %rax
movq %rcx, (%rax)
cmpl $0x0, -0x30(%rbp)
jbe 0x323993
jmp 0x3239b2
leaq 0x772e3(%rip), %rdi     # 0x39ac7d
leaq 0x72818(%rip), %rsi     # 0x3961b9
movl $0xd94, %edx            # imm = 0xD94
leaq 0x73122(%rip), %rcx     # 0x396acf
callq 0x2130
movl -0x30(%rbp), %eax
addq $0x80, %rsp
popq %rbp
retq
nop