// File: /workspace/github_cpp_makefile_star2_O2/chhylp123[P]hifiasm/hic.cpp
// Function: insert_dip_chain(kv_f_chain*, u_trans_t*, double)
void insert_dip_chain(kv_f_chain *x, u_trans_t *p, double LenRate)
{
    uint32_t i;
    uint64_t ovlp = 0, tLen = MIN(x->tov, p->qe-p->qs);
    int64_t dp, old_dp, start = 0;
    f_chain_t *t = NULL;
    double r;
    for (i = 0; i < x->n; i++)
    {
        ovlp += ((MIN(x->a[i].e, p->qe) > MAX(x->a[i].s, p->qs))?
                                        (MIN(x->a[i].e, p->qe) - MAX(x->a[i].s, p->qs)):0);
    }
    if(tLen > 0 && ovlp > tLen*LenRate)
    {
        r = ((double)ovlp)/((double)tLen);
        if(r >= 0.75)
        {
            if(p->nw <= x->tw*0.75) p->del = 1;
        } 
        else
        {
            if(p->nw <= x->tw*0.5) p->del = 1;
        }
    }

    if(!p->del)
    {
        x->tw += p->nw - (((double)ovlp)/((double)(p->qe-p->qs)))*p->nw;   

        kv_push(uint64_t, x->b, p->qs<<1);
        kv_push(uint64_t, x->b, p->qe<<1|1);
        if(x->b.n > 2 && x->b.a[x->b.n-2] < x->b.a[x->b.n-3])
        {
            radix_sort_hc64(x->b.a, x->b.a + x->b.n);
        }
        x->n = 0; x->tov = 0;
        for (i = 0, dp = 0, start = 0; i < x->b.n; ++i) 
        {
            old_dp = dp;
            ///if a[j] is qe
            if (x->b.a[i]&1) 
            {
                --dp;
            }
            else
            {
                ++dp;
            } 


            if (old_dp < 1 && dp >= 1) ///old_dp < dp, b.a[j] is qs
            { 
                ///case 2, a[j] is qs
                start = x->b.a[i]>>1;
            } 
            else if (old_dp >= 1 && dp < 1) ///old_dp > min_dp, b.a[j] is qe
            {
                kv_pushp(f_chain_t, *x, &t);
                t->s = start; t->e = x->b.a[i]>>1;
                x->tov += t->e - t->s;
            }
        }
    }
}

// Assembly:
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
movq %rsi, %r14
movq %rdi, %rbx
movq 0x8(%rdi), %rsi
movq 0x38(%rdi), %rdx
movl (%r14), %ecx
movl 0x4(%r14), %edi
movl %edi, %eax
subl %ecx, %eax
xorl %r8d, %r8d
xorl %r9d, %r9d
movl %r9d, %r9d
cmpq %r9, %rsi
jbe 0x11a1e2
movq (%rbx), %r10
movq %r9, %r11
shlq $0x4, %r11
movq (%r10,%r11), %r15
movq 0x8(%r10,%r11), %r10
cmpq %rdi, %r10
cmovaeq %rdi, %r10
cmpq %rcx, %r15
cmovbeq %rcx, %r15
subq %r15, %r10
movl $0x0, %r11d
cmovaeq %r10, %r11
addq %r11, %r8
incl %r9d
jmp 0x11a1a4
cmpq %rax, %rdx
cmovaeq %rax, %rdx
movq %r8, %xmm1
testq %rdx, %rdx
je 0x11a258
movdqa %xmm1, %xmm4
punpckldq 0xc9071(%rip), %xmm4 # xmm4 = xmm4[0],mem[0],xmm4[1],mem[1]
subpd 0xc9079(%rip), %xmm4    # 0x1e3280
movapd %xmm4, %xmm2
unpckhpd %xmm4, %xmm2            # xmm2 = xmm2[1],xmm4[1]
cvtsi2sd %rdx, %xmm3
addsd %xmm4, %xmm2
mulsd %xmm3, %xmm0
ucomisd %xmm0, %xmm2
jbe 0x11a258
divsd %xmm3, %xmm2
ucomisd 0xc935a(%rip), %xmm2    # 0x1e3588
movsd 0x20(%r14), %xmm0
movsd 0x30(%rbx), %xmm2
jae 0x11a245
mulsd 0xc9305(%rip), %xmm2    # 0x1e3548
jmp 0x11a24d
mulsd 0xc933b(%rip), %xmm2    # 0x1e3588
ucomisd %xmm0, %xmm2
jb 0x11a258
orb $-0x80, 0x28(%r14)
cmpb $0x0, 0x28(%r14)
js 0x11a427
punpckldq 0xc9005(%rip), %xmm1 # xmm1 = xmm1[0],mem[0],xmm1[1],mem[1]
subpd 0xc900d(%rip), %xmm1    # 0x1e3280
movsd 0x20(%r14), %xmm0
movapd %xmm1, %xmm2
unpckhpd %xmm1, %xmm2            # xmm2 = xmm2[1],xmm1[1]
addsd %xmm1, %xmm2
cvtsi2sd %rax, %xmm1
divsd %xmm1, %xmm2
mulsd %xmm0, %xmm2
subsd %xmm2, %xmm0
addsd 0x30(%rbx), %xmm0
movsd %xmm0, 0x30(%rbx)
movq 0x18(%rbx), %rdx
pushq $0x2
popq %r15
cmpq 0x20(%rbx), %rdx
jne 0x11a2d7
leaq (%rdx,%rdx), %rsi
testq %rdx, %rdx
cmoveq %r15, %rsi
movq %rsi, 0x20(%rbx)
movq 0x28(%rbx), %rdi
shlq $0x3, %rsi
callq 0x2370
movq %rax, 0x28(%rbx)
movl (%r14), %ecx
movq 0x18(%rbx), %rdx
jmp 0x11a2db
movq 0x28(%rbx), %rax
addl %ecx, %ecx
leaq 0x1(%rdx), %rsi
movq %rsi, 0x18(%rbx)
movq %rcx, (%rax,%rdx,8)
movq 0x18(%rbx), %rcx
cmpq 0x20(%rbx), %rcx
jne 0x11a316
leaq (%rcx,%rcx), %rsi
testq %rcx, %rcx
cmoveq %r15, %rsi
movq %rsi, 0x20(%rbx)
shlq $0x3, %rsi
movq %rax, %rdi
callq 0x2370
movq %rax, 0x28(%rbx)
movq 0x18(%rbx), %rcx
movl 0x4(%r14), %edx
leal 0x1(,%rdx,2), %edx
leaq 0x1(%rcx), %rsi
movq %rsi, 0x18(%rbx)
movq %rdx, (%rax,%rcx,8)
movq 0x18(%rbx), %rcx
cmpq $0x3, %rcx
jb 0x11a34f
movq -0x10(%rax,%rcx,8), %rdx
cmpq -0x18(%rax,%rcx,8), %rdx
jae 0x11a34f
leaq (%rax,%rcx,8), %rsi
movq %rax, %rdi
callq 0xf116c
andq $0x0, 0x8(%rbx)
andq $0x0, 0x38(%rbx)
xorl %ecx, %ecx
xorl %edx, %edx
xorl %eax, %eax
xorl %r12d, %r12d
xorl %r14d, %r14d
movl %r14d, %r14d
cmpq %r14, 0x18(%rbx)
jbe 0x11a427
movq 0x28(%rbx), %rsi
movq (%rsi,%r14,8), %rdi
movl %edi, %r13d
andl $0x1, %r13d
negq %r13
orq $0x1, %r13
addq %rax, %r13
testq %rax, %rax
setle %r8b
testq %r13, %r13
setg %r9b
andb %r8b, %r9b
cmpb $0x1, %r9b
jne 0x11a3aa
shrq %rdi
movq %rdi, %r12
jmp 0x11a41c
testq %rax, %rax
setg %al
testq %r13, %r13
setle %dil
andb %al, %dil
cmpb $0x1, %dil
jne 0x11a41c
movq (%rbx), %rax
cmpq 0x10(%rbx), %rdx
jne 0x11a3f3
leaq (%rdx,%rdx), %rsi
testq %rdx, %rdx
cmoveq %r15, %rsi
movq %rsi, 0x10(%rbx)
shlq $0x4, %rsi
movq %rax, %rdi
callq 0x2370
movq %rax, (%rbx)
movq 0x8(%rbx), %rdx
movq 0x28(%rbx), %rsi
movq 0x38(%rbx), %rcx
leaq 0x1(%rdx), %rdi
movq %rdi, 0x8(%rbx)
shlq $0x4, %rdx
movq %r12, (%rax,%rdx)
movq (%rsi,%r14,8), %rsi
shrq %rsi
movq %rsi, 0x8(%rax,%rdx)
subq %r12, %rsi
addq %rsi, %rcx
movq %rcx, 0x38(%rbx)
movq %rdi, %rdx
incl %r14d
movq %r13, %rax
jmp 0x11a365
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq