// File: /workspace/github_cpp_makefile_star2_O1/chhylp123[P]hifiasm/gfa_ut.cpp
// Function: gen_ref_pat_seq(asg_t*, ubuf_t*, unsigned long, double, unsigned int, unsigned int)
void gen_ref_pat_seq(asg_t *g, ubuf_t *b, uint64_t rul, double diff_rate, uint32_t v, uint32_t w/**, uint32_t is_debug**/)
{
    int64_t ref_n = b->dp.ref.n, k; uint64_t x, l; uint32_t p, arc_l;
    if(ref_n >= 2 && ((uint32_t)b->dp.ref.a[0]) == v && ((uint32_t)b->dp.ref.a[1]) == w) {
        // if(is_debug) fprintf(stderr, "+[M::%s::] ref_n::%ld, rul::%lu\n", __func__, ref_n, rul);
        if((ref_n) > 0 && ((b->dp.ref.a[ref_n-1]>>32) >= (rul*(1.0+diff_rate)))) {
            for (k = ref_n-1; k >= 0; k--) {
                if((b->dp.ref.a[k]>>32) < (rul*(1.0+diff_rate))) break;
                b->dp.g_flt.a[(uint32_t)b->dp.ref.a[k]] = 0;
            }
            ref_n = k + 1; b->dp.ref.n = ref_n;
        } else {
            p = (uint32_t)b->dp.ref.a[ref_n-1]; p ^= 1; p = b->a.a[p].p;
            for (l = b->dp.ref.a[ref_n-1]>>32; p != (uint32_t)-1; p = b->a.a[p].p) {
                x = p^1; arc_l = get_arch_len(g, ((uint32_t)b->dp.ref.a[b->dp.ref.n-1]), x); 
                assert(arc_l != (uint32_t)-1); l += arc_l; 
                if(l >= (rul*(1.0+diff_rate))) break;
                b->dp.g_flt.a[x] = 1; x += (l<<32); kv_push(uint64_t, b->dp.ref, x); 
            }
            ref_n = b->dp.ref.n;
        }
    } else {
        // if(is_debug) fprintf(stderr, "-[M::%s::] ref_n::%ld, rul::%lu\n", __func__, ref_n, rul);
        b->dp.ref.n = 0;
        for (k = 0; k < ref_n; k++) {
            b->dp.g_flt.a[(uint32_t)b->dp.ref.a[k]] = 0;
        }

        x = v; kv_push(uint64_t, b->dp.ref, x); b->dp.g_flt.a[x] = 1;
        for (p = w^1, l = 0; p != (uint32_t)-1; p = b->a.a[p].p) {
            x = p^1; arc_l = get_arch_len(g, ((uint32_t)b->dp.ref.a[b->dp.ref.n-1]), x); 
            assert(arc_l != (uint32_t)-1); l += arc_l; 
            if(l >= (rul*(1.0+diff_rate))) break;
            b->dp.g_flt.a[x] = 1; x += (l<<32); kv_push(uint64_t, b->dp.ref, x); 
        }
        ref_n = b->dp.ref.n;
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movl %r8d, %ebp
movsd %xmm0, (%rsp)
movq %rdx, %r15
movq %rsi, %rbx
movq %rdi, %r14
movq 0x90(%rsi), %rax
cmpq $0x2, %rax
jl 0x1f10e3
movq 0xa0(%rbx), %rdx
cmpl %ecx, (%rdx)
jne 0x1f10e3
cmpl %ebp, 0x8(%rdx)
jne 0x1f10e3
movl -0x4(%rdx,%rax,8), %ecx
xorps %xmm0, %xmm0
cvtsi2sd %rcx, %xmm0
movq %r15, %xmm1
punpckldq 0x342a0(%rip), %xmm1 # xmm1 = xmm1[0],mem[0],xmm1[1],mem[1]
subpd 0x342a8(%rip), %xmm1    # 0x225250
movapd %xmm1, %xmm2
unpckhpd %xmm1, %xmm2            # xmm2 = xmm2[1],xmm1[1]
movsd (%rsp), %xmm3
addsd 0x342b3(%rip), %xmm3    # 0x225270
addsd %xmm1, %xmm2
mulsd %xmm2, %xmm3
movsd %xmm3, (%rsp)
ucomisd %xmm3, %xmm0
jae 0x1f12aa
movq -0x8(%rdx,%rax,8), %r12
movq 0x10(%rbx), %rax
movl %r12d, %ecx
xorq $0x1, %rcx
shlq $0x5, %rcx
movl (%rax,%rcx), %eax
cmpl $-0x1, %eax
je 0x1f12fc
shrq $0x20, %r12
movl $0x2, %r13d
movl %eax, %ebp
movq %rbp, %r15
xorq $0x1, %r15
movq 0x90(%rbx), %rax
movq 0xa0(%rbx), %rcx
movl -0x8(%rcx,%rax,8), %esi
movq %r14, %rdi
movl %r15d, %edx
callq 0x1f0ee9
cmpl $-0x1, %eax
je 0x1f132a
movl %eax, %eax
addq %rax, %r12
movq %r12, %xmm0
punpckldq 0x34201(%rip), %xmm0 # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1]
subpd 0x34209(%rip), %xmm0    # 0x225250
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
addsd %xmm0, %xmm1
ucomisd (%rsp), %xmm1
jae 0x1f12fc
movq 0xe8(%rbx), %rax
movb $0x1, (%rax,%r15)
movq 0x98(%rbx), %rax
cmpq %rax, 0x90(%rbx)
jne 0x1f10a3
leaq (%rax,%rax), %rsi
testq %rax, %rax
cmoveq %r13, %rsi
movq %rsi, 0x98(%rbx)
movq 0xa0(%rbx), %rdi
shlq $0x3, %rsi
callq 0x2370
movq %rax, 0xa0(%rbx)
movq %r12, %rax
shlq $0x20, %rax
orq %r15, %rax
movq 0x90(%rbx), %rcx
movq 0xa0(%rbx), %rdx
leaq 0x1(%rcx), %rsi
movq %rsi, 0x90(%rbx)
movq %rax, (%rdx,%rcx,8)
movq 0x10(%rbx), %rax
shlq $0x5, %rbp
movl (%rax,%rbp), %eax
cmpl $-0x1, %eax
jne 0x1f0ffe
jmp 0x1f12fc
movq $0x0, 0x90(%rbx)
testq %rax, %rax
jle 0x1f1112
xorl %edx, %edx
movq 0xa0(%rbx), %rsi
movq 0xe8(%rbx), %rdi
movl (%rsi,%rdx,8), %esi
movb $0x0, (%rdi,%rsi)
incq %rdx
cmpq %rdx, %rax
jne 0x1f10f5
movl %ecx, %r12d
movq 0x98(%rbx), %rax
cmpq %rax, 0x90(%rbx)
jne 0x1f1153
leaq (%rax,%rax), %rcx
testq %rax, %rax
movl $0x2, %esi
cmovneq %rcx, %rsi
movq %rsi, 0x98(%rbx)
movq 0xa0(%rbx), %rdi
shlq $0x3, %rsi
callq 0x2370
movq %rax, 0xa0(%rbx)
movq 0x90(%rbx), %rax
movq 0xa0(%rbx), %rcx
leaq 0x1(%rax), %rdx
movq %rdx, 0x90(%rbx)
movq %r12, (%rcx,%rax,8)
movq 0xe8(%rbx), %rax
movb $0x1, (%rax,%r12)
cmpl $-0x2, %ebp
je 0x1f12fc
xorl $0x1, %ebp
movq %r15, %xmm0
punpckldq 0x340ab(%rip), %xmm0 # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1]
subpd 0x340b3(%rip), %xmm0    # 0x225250
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
addsd %xmm0, %xmm1
movsd (%rsp), %xmm0
addsd 0x340ba(%rip), %xmm0    # 0x225270
mulsd %xmm1, %xmm0
movsd %xmm0, (%rsp)
xorl %r12d, %r12d
movl $0x2, %r13d
movl %ebp, %ebp
movq %rbp, %r15
xorq $0x1, %r15
movq 0x90(%rbx), %rax
movq 0xa0(%rbx), %rcx
movl -0x8(%rcx,%rax,8), %esi
movq %r14, %rdi
movl %r15d, %edx
callq 0x1f0ee9
cmpl $-0x1, %eax
je 0x1f130b
movl %eax, %eax
addq %rax, %r12
movq %r12, %xmm0
punpckldq 0x34037(%rip), %xmm0 # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1]
subpd 0x3403f(%rip), %xmm0    # 0x225250
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
addsd %xmm0, %xmm1
ucomisd (%rsp), %xmm1
jae 0x1f12fc
movq 0xe8(%rbx), %rax
movb $0x1, (%rax,%r15)
movq 0x98(%rbx), %rax
cmpq %rax, 0x90(%rbx)
jne 0x1f126d
leaq (%rax,%rax), %rsi
testq %rax, %rax
cmoveq %r13, %rsi
movq %rsi, 0x98(%rbx)
movq 0xa0(%rbx), %rdi
shlq $0x3, %rsi
callq 0x2370
movq %rax, 0xa0(%rbx)
movq %r12, %rax
shlq $0x20, %rax
orq %r15, %rax
movq 0x90(%rbx), %rcx
movq 0xa0(%rbx), %rdx
leaq 0x1(%rcx), %rsi
movq %rsi, 0x90(%rbx)
movq %rax, (%rdx,%rcx,8)
movq 0x10(%rbx), %rax
shlq $0x5, %rbp
movl (%rax,%rbp), %ebp
cmpl $-0x1, %ebp
jne 0x1f11c8
jmp 0x1f12fc
decq %rax
movsd (%rsp), %xmm1
movq 0xa0(%rbx), %rcx
movq (%rcx,%rax,8), %rcx
movq %rcx, %rdx
shrq $0x20, %rdx
xorps %xmm0, %xmm0
cvtsi2sd %rdx, %xmm0
ucomisd %xmm0, %xmm1
ja 0x1f12f2
movq 0xe8(%rbx), %rdx
movl %ecx, %ecx
movb $0x0, (%rdx,%rcx)
leaq -0x1(%rax), %rcx
testq %rax, %rax
movq %rcx, %rax
jg 0x1f12b2
movq $-0x1, %rax
incq %rax
movq %rax, 0x90(%rbx)
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x489a2(%rip), %rdi     # 0x239cb4
leaq 0x4800c(%rip), %rsi     # 0x239325
leaq 0x489aa(%rip), %rcx     # 0x239cca
movl $0xdc3, %edx            # imm = 0xDC3
callq 0x2110
leaq 0x48983(%rip), %rdi     # 0x239cb4
leaq 0x47fed(%rip), %rsi     # 0x239325
leaq 0x4898b(%rip), %rcx     # 0x239cca
movl $0xdb3, %edx            # imm = 0xDB3
callq 0x2110