// File: /workspace/github_cpp_makefile_star2_O2/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), %rdx
cmpq $0x2, %rdx
jl 0x1b09a3
movq 0xa0(%rbx), %rax
cmpl %ecx, (%rax)
jne 0x1b09a3
cmpl %ebp, 0x8(%rax)
jne 0x1b09a3
movq -0x8(%rax,%rdx,8), %rcx
movq %rcx, %r12
shrq $0x20, %r12
cvtsi2sd %r12, %xmm0
movq %r15, %xmm1
punpckldq 0x329f1(%rip), %xmm1 # xmm1 = xmm1[0],mem[0],xmm1[1],mem[1]
subpd 0x329f9(%rip), %xmm1    # 0x1e3280
movapd %xmm1, %xmm2
unpckhpd %xmm1, %xmm2            # xmm2 = xmm2[1],xmm1[1]
movsd (%rsp), %xmm3
addsd 0x32a04(%rip), %xmm3    # 0x1e32a0
addsd %xmm1, %xmm2
mulsd %xmm2, %xmm3
movsd %xmm3, (%rsp)
ucomisd %xmm3, %xmm0
jae 0x1b0b56
movl %ecx, %r13d
xorq $0x1, %r13
shlq $0x5, %r13
addq 0x10(%rbx), %r13
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
movl (%r13), %r13d
cmpq %rbp, %r13
je 0x1b0ba2
movq %r13, %r15
xorq $0x1, %r15
movq 0x90(%rbx), %rcx
movl -0x8(%rax,%rcx,8), %esi
movq %r14, %rdi
movl %r15d, %edx
callq 0x1b07d3
cmpl $-0x1, %eax
je 0x1b0bd0
movl %eax, %eax
addq %rax, %r12
movq %r12, %xmm0
punpckldq 0x32964(%rip), %xmm0 # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1]
subpd 0x3296c(%rip), %xmm0    # 0x1e3280
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
addsd %xmm0, %xmm1
ucomisd (%rsp), %xmm1
jae 0x1b0ba2
movq 0xe8(%rbx), %rax
movb $0x1, (%rax,%r15)
movq 0x90(%rbx), %rcx
movq 0xa0(%rbx), %rax
cmpq 0x98(%rbx), %rcx
jne 0x1b097d
leaq (%rcx,%rcx), %rsi
testq %rcx, %rcx
pushq $0x2
popq %rcx
cmoveq %rcx, %rsi
movq %rsi, 0x98(%rbx)
shlq $0x3, %rsi
movq %rax, %rdi
callq 0x2370
movq %rax, 0xa0(%rbx)
movq 0x90(%rbx), %rcx
movq %r12, %rdx
shlq $0x20, %rdx
orq %r15, %rdx
leaq 0x1(%rcx), %rsi
movq %rsi, 0x90(%rbx)
movq %rdx, (%rax,%rcx,8)
shlq $0x5, %r13
addq 0x10(%rbx), %r13
jmp 0x1b08c7
andq $0x0, 0x90(%rbx)
xorl %eax, %eax
testq %rdx, %rdx
cmovleq %rax, %rdx
cmpq %rax, %rdx
je 0x1b09d3
movq 0xa0(%rbx), %rsi
movq 0xe8(%rbx), %rdi
movl (%rsi,%rax,8), %esi
movb $0x0, (%rdi,%rsi)
incq %rax
jmp 0x1b09b4
movl %ecx, %r13d
movq 0x90(%rbx), %rcx
movq 0xa0(%rbx), %rax
pushq $0x2
popq %r12
cmpq 0x98(%rbx), %rcx
jne 0x1b0a1d
leaq (%rcx,%rcx), %rsi
testq %rcx, %rcx
cmoveq %r12, %rsi
movq %rsi, 0x98(%rbx)
shlq $0x3, %rsi
movq %rax, %rdi
callq 0x2370
movq %rax, 0xa0(%rbx)
movq 0x90(%rbx), %rcx
leaq 0x1(%rcx), %rdx
movq %rdx, 0x90(%rbx)
movq %r13, (%rax,%rcx,8)
movq 0xe8(%rbx), %rax
movb $0x1, (%rax,%r13)
movq %r15, %xmm0
punpckldq 0x3282b(%rip), %xmm0 # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1]
xorl $0x1, %ebp
subpd 0x32830(%rip), %xmm0    # 0x1e3280
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
addsd %xmm0, %xmm1
movsd (%rsp), %xmm0
addsd 0x32837(%rip), %xmm0    # 0x1e32a0
mulsd %xmm1, %xmm0
movsd %xmm0, (%rsp)
xorl %r13d, %r13d
cmpl $-0x1, %ebp
je 0x1b0ba2
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 0x1b07d3
cmpl $-0x1, %eax
je 0x1b0bb1
movl %eax, %eax
addq %rax, %r13
movq %r13, %xmm0
punpckldq 0x327b1(%rip), %xmm0 # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1]
subpd 0x327b9(%rip), %xmm0    # 0x1e3280
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
addsd %xmm0, %xmm1
ucomisd (%rsp), %xmm1
jae 0x1b0ba2
movq 0xe8(%rbx), %rax
movb $0x1, (%rax,%r15)
movq 0x90(%rbx), %rcx
movq 0xa0(%rbx), %rax
cmpq 0x98(%rbx), %rcx
jne 0x1b0b2d
leaq (%rcx,%rcx), %rsi
testq %rcx, %rcx
cmoveq %r12, %rsi
movq %rsi, 0x98(%rbx)
shlq $0x3, %rsi
movq %rax, %rdi
callq 0x2370
movq %rax, 0xa0(%rbx)
movq 0x90(%rbx), %rcx
movq %r13, %rdx
shlq $0x20, %rdx
orq %r15, %rdx
leaq 0x1(%rcx), %rsi
movq %rsi, 0x90(%rbx)
movq %rdx, (%rax,%rcx,8)
movq 0x10(%rbx), %rax
shlq $0x5, %rbp
movl (%rax,%rbp), %ebp
jmp 0x1b0a75
decq %rdx
pushq $-0x1
popq %rax
movsd (%rsp), %xmm1
testq %rdx, %rdx
js 0x1b0b98
movq 0xa0(%rbx), %rcx
movq (%rcx,%rdx,8), %rcx
movq %rcx, %rsi
shrq $0x20, %rsi
cvtsi2sd %rsi, %xmm0
ucomisd %xmm0, %xmm1
ja 0x1b0b95
movq 0xe8(%rbx), %rsi
movl %ecx, %ecx
movb $0x0, (%rsi,%rcx)
decq %rdx
jmp 0x1b0b61
movq %rdx, %rax
incq %rax
movq %rax, 0x90(%rbx)
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x472b0(%rip), %rdi     # 0x1f7e68
leaq 0x4691a(%rip), %rsi     # 0x1f74d9
leaq 0x472b8(%rip), %rcx     # 0x1f7e7e
movl $0xdc3, %edx            # imm = 0xDC3
callq 0x2110
leaq 0x47291(%rip), %rdi     # 0x1f7e68
leaq 0x468fb(%rip), %rsi     # 0x1f74d9
leaq 0x47299(%rip), %rcx     # 0x1f7e7e
movl $0xdb3, %edx            # imm = 0xDB3
callq 0x2110