// File: /workspace/github_cpp_makefile_star2_O3/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 0x1fc6a5
movq 0xa0(%rbx), %rax
cmpl %ecx, (%rax)
jne 0x1fc6ba
cmpl %ebp, 0x8(%rax)
jne 0x1fc6ba
movq -0x8(%rax,%rdx,8), %rcx
movq %rcx, %r12
shrq $0x20, %r12
xorps %xmm0, %xmm0
cvtsi2sd %r12, %xmm0
movq %r15, %xmm1
punpckldq 0x34d09(%rip), %xmm1 # xmm1 = xmm1[0],mem[0],xmm1[1],mem[1]
subpd 0x34d11(%rip), %xmm1    # 0x231290
movapd %xmm1, %xmm2
unpckhpd %xmm1, %xmm2            # xmm2 = xmm2[1],xmm1[1]
movsd (%rsp), %xmm3
addsd 0x34d7c(%rip), %xmm3    # 0x231310
addsd %xmm1, %xmm2
mulsd %xmm2, %xmm3
movsd %xmm3, (%rsp)
ucomisd %xmm3, %xmm0
jae 0x1fc87a
movq 0x10(%rbx), %rdx
movl %ecx, %ecx
xorq $0x1, %rcx
shlq $0x5, %rcx
movl (%rdx,%rcx), %ecx
cmpl $-0x1, %ecx
je 0x1fc8cc
movl $0x2, %r13d
movl %ecx, %ebp
movq %rbp, %r15
xorq $0x1, %r15
movq 0x90(%rbx), %rcx
movl -0x8(%rax,%rcx,8), %esi
movq %r14, %rdi
movl %r15d, %edx
callq 0x1fc4b8
cmpl $-0x1, %eax
je 0x1fc8fa
movl %eax, %eax
addq %rax, %r12
movq %r12, %xmm0
punpckldq 0x34c7b(%rip), %xmm0 # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1]
subpd 0x34c83(%rip), %xmm0    # 0x231290
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
addsd %xmm0, %xmm1
ucomisd (%rsp), %xmm1
jae 0x1fc8cc
movq 0xe8(%rbx), %rax
movb $0x1, (%rax,%r15)
movq 0x90(%rbx), %rcx
movq 0xa0(%rbx), %rax
cmpq 0x98(%rbx), %rcx
jne 0x1fc673
leaq (%rcx,%rcx), %rsi
testq %rcx, %rcx
cmoveq %r13, %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)
movq 0x10(%rbx), %rcx
shlq $0x5, %rbp
movl (%rcx,%rbp), %ecx
cmpl $-0x1, %ecx
jne 0x1fc5cb
jmp 0x1fc8cc
movq $0x0, 0x90(%rbx)
cmpq $0x1, %rdx
je 0x1fc6c5
xorl %edx, %edx
jmp 0x1fc6eb
movq $0x0, 0x90(%rbx)
xorl %eax, %eax
movq 0xa0(%rbx), %rsi
movq 0xe8(%rbx), %rdi
movl (%rsi,%rax,8), %esi
movb $0x0, (%rdi,%rsi)
incq %rax
cmpq %rax, %rdx
jne 0x1fc6c7
movq 0x90(%rbx), %rdx
movl %ecx, %r12d
cmpq 0x98(%rbx), %rdx
jne 0x1fc72e
leaq (%rdx,%rdx), %rax
testq %rdx, %rdx
movl $0x2, %esi
cmovneq %rax, %rsi
movq %rsi, 0x98(%rbx)
movq 0xa0(%rbx), %rdi
shlq $0x3, %rsi
callq 0x2370
movq %rax, 0xa0(%rbx)
movq 0x90(%rbx), %rdx
jmp 0x1fc735
movq 0xa0(%rbx), %rax
leaq 0x1(%rdx), %rcx
movq %rcx, 0x90(%rbx)
movq %r12, (%rax,%rdx,8)
movq 0xe8(%rbx), %rax
movb $0x1, (%rax,%r12)
cmpl $-0x2, %ebp
je 0x1fc8cc
movq %r15, %xmm0
punpckldq 0x34b1a(%rip), %xmm0 # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1]
subpd 0x34b22(%rip), %xmm0    # 0x231290
xorl $0x1, %ebp
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
addsd %xmm0, %xmm1
movsd (%rsp), %xmm0
addsd 0x34b86(%rip), %xmm0    # 0x231310
mulsd %xmm1, %xmm0
movsd %xmm0, (%rsp)
movq 0xa0(%rbx), %rax
xorl %r12d, %r12d
movl $0x2, %r13d
movl %ebp, %ebp
movq %rbp, %r15
xorq $0x1, %r15
movq 0x90(%rbx), %rcx
movl -0x8(%rax,%rcx,8), %esi
movq %r14, %rdi
movl %r15d, %edx
callq 0x1fc4b8
cmpl $-0x1, %eax
je 0x1fc8db
movl %eax, %eax
addq %rax, %r12
movq %r12, %xmm0
punpckldq 0x34aa3(%rip), %xmm0 # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1]
subpd 0x34aab(%rip), %xmm0    # 0x231290
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
addsd %xmm0, %xmm1
ucomisd (%rsp), %xmm1
jae 0x1fc8cc
movq 0xe8(%rbx), %rax
movb $0x1, (%rax,%r15)
movq 0x90(%rbx), %rcx
movq 0xa0(%rbx), %rax
cmpq 0x98(%rbx), %rcx
jne 0x1fc84b
leaq (%rcx,%rcx), %rsi
testq %rcx, %rcx
cmoveq %r13, %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)
movq 0x10(%rbx), %rcx
shlq $0x5, %rbp
movl (%rcx,%rbp), %ebp
cmpl $-0x1, %ebp
jne 0x1fc7a3
jmp 0x1fc8cc
decq %rdx
movsd (%rsp), %xmm1
movq 0xa0(%rbx), %rax
movq (%rax,%rdx,8), %rax
movq %rax, %rcx
shrq $0x20, %rcx
xorps %xmm0, %xmm0
cvtsi2sd %rcx, %xmm0
ucomisd %xmm0, %xmm1
ja 0x1fc8c2
movq 0xe8(%rbx), %rcx
movl %eax, %eax
movb $0x0, (%rcx,%rax)
leaq -0x1(%rdx), %rax
testq %rdx, %rdx
movq %rax, %rdx
jg 0x1fc882
movq $-0x1, %rdx
incq %rdx
movq %rdx, 0x90(%rbx)
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x496b6(%rip), %rdi     # 0x245f98
leaq 0x48d20(%rip), %rsi     # 0x245609
leaq 0x496be(%rip), %rcx     # 0x245fae
movl $0xdc3, %edx            # imm = 0xDC3
callq 0x2110
leaq 0x49697(%rip), %rdi     # 0x245f98
leaq 0x48d01(%rip), %rsi     # 0x245609
leaq 0x4969f(%rip), %rcx     # 0x245fae
movl $0xdb3, %edx            # imm = 0xDB3
callq 0x2110