// File: /workspace/github_cpp_makefile_star2_O2/chhylp123[P]hifiasm/hic.cpp
// Function: get_trans_weight_advance(ha_ug_index const*, unsigned long, trans_idx*)
inline double get_trans_weight_advance(const ha_ug_index* idx, uint64_t x, trans_idx* dis)
{
    long double rate = 0;

    ///if(x == (uint64_t)-1) x = dis->med;
    if(x != (uint64_t)-1)
    {
        if(x < dis->max)
        {
            uint64_t i;
            for (i = 0; i < dis->n; i++)
            {
                if(x < dis->a[i].end && x >= dis->a[i].beg) break;
            }
            if(i < dis->n)
            {
                rate = ((double)(dis->a[i].cnt_1))/((double)(dis->a[i].cnt_0 + dis->a[i].cnt_1));
            }
            else
            {
                rate = get_trans(idx, x);
            } 
        }
        else
        {
            rate = get_trans(idx, x);
        }
    }
    else
    {
        // rate = 0.2;
        rate = 0.4;
    }

    
    if(rate < 0) rate = 0;
    rate += OFFSET_RATE;
    if(rate > 0.5) rate = 0.5;
    rate -= OFFSET_SECOND_RATE; //[OFFSET_RATE - OFFSET_SECOND_RATE, 0.5 - OFFSET_SECOND_RATE]

    long double w = logl((1/rate)-1)*SCALL;
    if(w < OFFSET_RATE_MIN_W) w = OFFSET_RATE_MIN_W;
    if(w > OFFSET_RATE_MAX_W) w = OFFSET_RATE_MAX_W;
    return w;
}

// Assembly:
subq $0x48, %rsp
fldl 0xc1e50(%rip)           # 0x1e3510
cmpq $-0x1, %rsi
je 0x1217de
fstp %st(0)
cmpq %rsi, 0x18(%rdx)
jbe 0x1216fa
movq 0x8(%rdx), %rcx
pushq $0x20
popq %rax
subq $0x1, %rcx
jb 0x121746
movq (%rdx), %r8
cmpq %rsi, -0x18(%r8,%rax)
jbe 0x1216f4
cmpq %rsi, -0x20(%r8,%rax)
jbe 0x121785
addq $0x28, %rax
jmp 0x1216d9
fldt 0x80(%rdi)
movq %rsi, 0x40(%rsp)
xorl %eax, %eax
testq %rsi, %rsi
sets %al
fildll 0x40(%rsp)
leaq 0xcba10(%rip), %rcx     # 0x1ed128
fadds (%rcx,%rax,4)
fldt 0xa0(%rdi)
fdivrp %st, %st(1)
fmulp %st, %st(1)
fldt 0x90(%rdi)
faddp %st, %st(1)
fstpl 0x38(%rsp)
movsd 0x38(%rsp), %xmm0
movsd %xmm0, 0x30(%rsp)
fldl 0x30(%rsp)
jmp 0x1217de
fldt 0x80(%rdi)
movq %rsi, 0x28(%rsp)
xorl %eax, %eax
testq %rsi, %rsi
sets %al
fildll 0x28(%rsp)
leaq 0xcb9c4(%rip), %rcx     # 0x1ed128
fadds (%rcx,%rax,4)
fldt 0xa0(%rdi)
fdivrp %st, %st(1)
fmulp %st, %st(1)
fldt 0x90(%rdi)
faddp %st, %st(1)
fstpl 0x20(%rsp)
movsd 0x20(%rsp), %xmm0
jmp 0x1217d4
movq (%r8,%rax), %rcx
movq %rcx, %xmm1
movq 0xc1ada(%rip), %xmm2    # 0x1e3270
punpckldq %xmm2, %xmm1    # xmm1 = xmm1[0],xmm2[0],xmm1[1],xmm2[1]
movapd 0xc1ade(%rip), %xmm3    # 0x1e3280
subpd %xmm3, %xmm1
movapd %xmm1, %xmm0
unpckhpd %xmm1, %xmm0            # xmm0 = xmm0[1],xmm1[1]
addq -0x8(%r8,%rax), %rcx
addsd %xmm1, %xmm0
movq %rcx, %xmm1
punpckldq %xmm2, %xmm1    # xmm1 = xmm1[0],xmm2[0],xmm1[1],xmm2[1]
subpd %xmm3, %xmm1
movapd %xmm1, %xmm2
unpckhpd %xmm1, %xmm2            # xmm2 = xmm2[1],xmm1[1]
addsd %xmm1, %xmm2
divsd %xmm2, %xmm0
movsd %xmm0, 0x18(%rsp)
fldl 0x18(%rsp)
fldz
fucomi %st(1), %st
fxch %st(1)
fcmovnbe %st(1), %st
fstp %st(1)
faddl 0xcb8c2(%rip)           # 0x1ed0b0
flds 0xcb970(%rip)           # 0x1ed164
fxch %st(1)
fucomi %st(1), %st
fcmovnbe %st(1), %st
fstp %st(1)
faddl 0xcb92e(%rip)           # 0x1ed130
fld1
fdiv %st, %st(1)
fchs
faddp %st, %st(1)
fstpt (%rsp)
callq 0x20b0
fmuls 0xcb950(%rip)           # 0x1ed168
fldl 0xcb91a(%rip)           # 0x1ed138
fucomi %st(1), %st
fxch %st(1)
fcmovnbe %st(1), %st
fstp %st(1)
fldl 0xcb914(%rip)           # 0x1ed140
fxch %st(1)
fucomi %st(1), %st
fcmovnbe %st(1), %st
fstp %st(1)
fstpl 0x10(%rsp)
movsd 0x10(%rsp), %xmm0
addq $0x48, %rsp
retq