// File: chhylp123[P]hifiasm/Hash_Table.cpp
// Function: comput_sc_ch(k_mer_hit const*, k_mer_hit const*, double, double, double, long, long)
inline int32_t comput_sc_ch(const k_mer_hit *ai, const k_mer_hit *aj, double bw_rate, double chn_pen_gap, double chn_pen_skip, int64_t sl, int64_t ol)
{
    ///ai is the suffix of aj
    int32_t dq, dr, dd, dg, q_span, sc; 
    dq = (int64_t)(ai->self_offset) - (int64_t)(aj->self_offset);
    if(dq <= 0) return INT32_MIN;
    dr = (int64_t)(ai->offset) - (int64_t)(aj->offset);
    if(dr <= 0) return INT32_MIN;
    dd = dr > dq? dr - dq : dq - dr;//gap
    if((dd > 16) && (dd > cal_bw(ai, aj, bw_rate, sl, ol))) return INT32_MIN;
    dg = dr < dq? dr : dq;//len
    q_span = ai->cnt&(0xffu); 
    sc = q_span < dg? q_span : dg;
    sc = normal_w(sc, ((int32_t)(ai->cnt>>8)));
    if (dd || (dg > q_span && dg > 0)) {
        double lin_pen, a_pen;
        lin_pen = (chn_pen_gap*(double)dd);
        a_pen = ((double)(sc))*((((double)dd)/((double)dg))/bw_rate);
        if(lin_pen > a_pen) lin_pen = a_pen;
        lin_pen += (chn_pen_skip*(double)dg);
        sc -= (int32_t)lin_pen;
    }
    return sc;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x80, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movsd %xmm0, -0x20(%rbp)
movsd %xmm1, -0x28(%rbp)
movsd %xmm2, -0x30(%rbp)
movq %rdx, -0x38(%rbp)
movq %rcx, -0x40(%rbp)
movq -0x10(%rbp), %rax
movl 0x8(%rax), %eax
movq -0x18(%rbp), %rcx
movl 0x8(%rcx), %ecx
subq %rcx, %rax
movl %eax, -0x44(%rbp)
cmpl $0x0, -0x44(%rbp)
jg 0x2b150
movl $0x80000000, -0x4(%rbp) # imm = 0x80000000
jmp 0x2b2dd
movq -0x10(%rbp), %rax
movl 0x4(%rax), %eax
movq -0x18(%rbp), %rcx
movl 0x4(%rcx), %ecx
subq %rcx, %rax
movl %eax, -0x48(%rbp)
cmpl $0x0, -0x48(%rbp)
jg 0x2b176
movl $0x80000000, -0x4(%rbp) # imm = 0x80000000
jmp 0x2b2dd
movl -0x48(%rbp), %eax
cmpl -0x44(%rbp), %eax
jle 0x2b189
movl -0x48(%rbp), %eax
subl -0x44(%rbp), %eax
movl %eax, -0x6c(%rbp)
jmp 0x2b192
movl -0x44(%rbp), %eax
subl -0x48(%rbp), %eax
movl %eax, -0x6c(%rbp)
movl -0x6c(%rbp), %eax
movl %eax, -0x4c(%rbp)
cmpl $0x10, -0x4c(%rbp)
jle 0x2b1d3
movl -0x4c(%rbp), %eax
movl %eax, -0x70(%rbp)
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
movsd -0x20(%rbp), %xmm0
movq -0x38(%rbp), %rdx
movq -0x40(%rbp), %rcx
callq 0x2b2f0
movl %eax, %ecx
movl -0x70(%rbp), %eax
cmpl %ecx, %eax
jle 0x2b1d3
movl $0x80000000, -0x4(%rbp) # imm = 0x80000000
jmp 0x2b2dd
movl -0x48(%rbp), %eax
cmpl -0x44(%rbp), %eax
jge 0x2b1e3
movl -0x48(%rbp), %eax
movl %eax, -0x74(%rbp)
jmp 0x2b1e9
movl -0x44(%rbp), %eax
movl %eax, -0x74(%rbp)
movl -0x74(%rbp), %eax
movl %eax, -0x50(%rbp)
movq -0x10(%rbp), %rax
movl 0xc(%rax), %eax
andl $0xff, %eax
movl %eax, -0x54(%rbp)
movl -0x54(%rbp), %eax
cmpl -0x50(%rbp), %eax
jge 0x2b20e
movl -0x54(%rbp), %eax
movl %eax, -0x78(%rbp)
jmp 0x2b214
movl -0x50(%rbp), %eax
movl %eax, -0x78(%rbp)
movl -0x78(%rbp), %eax
movl %eax, -0x58(%rbp)
movl -0x58(%rbp), %eax
movq -0x10(%rbp), %rcx
movl 0xc(%rcx), %ecx
shrl $0x8, %ecx
cmpl %ecx, %eax
jl 0x2b240
movl -0x58(%rbp), %eax
movq -0x10(%rbp), %rcx
movl 0xc(%rcx), %ecx
shrl $0x8, %ecx
cltd
idivl %ecx
movl %eax, -0x7c(%rbp)
jmp 0x2b24a
movl $0x1, %eax
movl %eax, -0x7c(%rbp)
jmp 0x2b24a
movl -0x7c(%rbp), %eax
movl %eax, -0x58(%rbp)
cmpl $0x0, -0x4c(%rbp)
jne 0x2b264
movl -0x50(%rbp), %eax
cmpl -0x54(%rbp), %eax
jle 0x2b2d7
cmpl $0x0, -0x50(%rbp)
jle 0x2b2d7
movsd -0x28(%rbp), %xmm0
cvtsi2sdl -0x4c(%rbp), %xmm1
mulsd %xmm1, %xmm0
movsd %xmm0, -0x60(%rbp)
cvtsi2sdl -0x58(%rbp), %xmm0
cvtsi2sdl -0x4c(%rbp), %xmm1
cvtsi2sdl -0x50(%rbp), %xmm2
divsd %xmm2, %xmm1
divsd -0x20(%rbp), %xmm1
mulsd %xmm1, %xmm0
movsd %xmm0, -0x68(%rbp)
movsd -0x60(%rbp), %xmm0
ucomisd -0x68(%rbp), %xmm0
jbe 0x2b2ae
movsd -0x68(%rbp), %xmm0
movsd %xmm0, -0x60(%rbp)
movsd -0x30(%rbp), %xmm0
cvtsi2sdl -0x50(%rbp), %xmm2
movsd -0x60(%rbp), %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x60(%rbp)
cvttsd2si -0x60(%rbp), %ecx
movl -0x58(%rbp), %eax
subl %ecx, %eax
movl %eax, -0x58(%rbp)
movl -0x58(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x80, %rsp
popq %rbp
retq
nopl (%rax)