// File: /workspace/github_cpp_makefile_star2_O1/chhylp123[P]hifiasm/horder.cpp
// Function: extract_novlp(u_trans_t*, h_covs*, unsigned long*, kv_u_trans_hit_t*, kv_u_trans_t*)
void extract_novlp(u_trans_t *e, h_covs *join, uint64_t *idx, kv_u_trans_hit_t *kv, kv_u_trans_t *n_trans)
{
    uint64_t i, bn; 
    u_trans_hit_t hit, *kh = NULL;
    u_trans_t *kt = NULL;
    kv->n = 0;

    i = 0;
    while (get_switch_ovlp_hits(&i, e->qn, e->qs, e->qe, &hit, join, idx)) //get [qScur, qEcur), [qSpre, qEpre)
    {
        if(e->rev == 0)
        {
            hit.tScur = e->ts + get_offset_adjust(hit.qScur-e->qs, e->qe-e->qs, e->te-e->ts);  
            hit.tEcur = e->te - get_offset_adjust(e->qe-hit.qEcur, e->qe-e->qs, e->te-e->ts); 
        }
        else
        {
            hit.tScur = e->ts + get_offset_adjust(e->qe-hit.qEcur, e->qe-e->qs, e->te-e->ts); 
            hit.tEcur = e->te - get_offset_adjust(hit.qScur-e->qs, e->qe-e->qs, e->te-e->ts);  
        }
        
        kv_push(u_trans_hit_t, *kv, hit);
    }
    bn = kv->n;

    i = 0;
    while (get_switch_ovlp_hits(&i, e->tn, e->ts, e->te, &hit, join, idx))
    {
        extract_switch_sub(hit.qScur, hit.qEcur, hit.qSpre, hit.qEpre, hit.qn, kv, bn, e->rev);
    }
    
    double x_score, y_score;
    for (i = bn; i < kv->n; i++)
    {
        kh = &(kv->a[i]);
        if(kh->qEpre <= kh->qSpre) continue;
        if(kh->tEpre <= kh->tSpre) continue;
        kv_pushp(u_trans_t, *n_trans, &kt);

        kt->f = e->f; kt->rev = e->rev; kt->del = 0; 
        kt->qn = kh->qn; kt->qs = kh->qSpre; kt->qe = kh->qEpre;
        kt->tn = kh->tn; kt->ts = kh->tSpre; kt->te = kh->tEpre;

        x_score = ((double)(kt->qe-kt->qs)/(double)(e->qe-e->qs))*e->nw;
        y_score = ((double)(kt->te-kt->ts)/(double)(e->te-e->ts))*e->nw;
        kt->nw = MIN(x_score, y_score);
        kt->occ = 0;

        // if(kv->n - bn > 1)
        // {
        //     fprintf(stderr, "-kt-utg%.6ul\tqs(%u)\tqe(%u)\tt-utg%.6ul\tts(%u)\tte(%u)\trev(%u)\tw(%f)\tf(%u)\n", 
        //         kt->qn+1, kt->qs, kt->qe, kt->tn+1, kt->ts, kt->te, kt->rev, kt->nw, kt->f);
        // }
        
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %r8, 0x40(%rsp)
movq %rcx, %r14
movq %rdx, %r12
movq %rsi, %r13
movq %rdi, %r15
xorl %eax, %eax
movq %rax, (%rcx)
leaq 0x10(%rsp), %rdi
movq %rax, (%rdi)
movl 0x8(%r15), %esi
movl (%r15), %ebx
movl 0x4(%r15), %ebp
movq %rdx, (%rsp)
leaq 0x18(%rsp), %r8
movq %rbx, %rdx
movq %rbp, %rcx
movq %r13, %r9
callq 0x172045
testl %eax, %eax
je 0x1724a8
movl %ebp, %eax
subl %ebx, %eax
testb $0x40, 0x28(%r15)
xorps %xmm0, %xmm0
cvtsi2sd %rax, %xmm0
jne 0x1723c9
movl 0x20(%rsp), %ecx
subl %ebx, %ecx
movl 0xc(%r15), %edx
movl 0x10(%r15), %eax
movl %eax, %esi
subl %edx, %esi
xorps %xmm2, %xmm2
cvtsi2sd %rcx, %xmm2
xorps %xmm1, %xmm1
cvtsi2sd %rsi, %xmm1
divsd %xmm0, %xmm2
mulsd %xmm1, %xmm2
cvttsd2si %xmm2, %rcx
addl %edx, %ecx
movl %ecx, 0x34(%rsp)
subl 0x24(%rsp), %ebp
jmp 0x172402
subl 0x24(%rsp), %ebp
movl 0xc(%r15), %ecx
movl 0x10(%r15), %eax
movl %eax, %edx
subl %ecx, %edx
xorps %xmm2, %xmm2
cvtsi2sd %rbp, %xmm2
xorps %xmm1, %xmm1
cvtsi2sd %rdx, %xmm1
divsd %xmm0, %xmm2
mulsd %xmm1, %xmm2
cvttsd2si %xmm2, %rdx
addl %ecx, %edx
movl %edx, 0x34(%rsp)
movl 0x20(%rsp), %ebp
subl %ebx, %ebp
movl %ebp, %ecx
xorps %xmm2, %xmm2
cvtsi2sd %rcx, %xmm2
divsd %xmm0, %xmm2
mulsd %xmm1, %xmm2
cvttsd2si %xmm2, %rcx
subl %ecx, %eax
movl %eax, 0x38(%rsp)
movq 0x8(%r14), %rax
cmpq %rax, (%r14)
jne 0x172451
leaq (%rax,%rax), %rcx
testq %rax, %rax
movl $0x2, %eax
cmoveq %rax, %rcx
movq %rcx, 0x8(%r14)
movq 0x10(%r14), %rdi
shlq $0x3, %rcx
leaq (%rcx,%rcx,4), %rsi
callq 0x2370
movq %rax, 0x10(%r14)
movq (%r14), %rax
movq 0x10(%r14), %rcx
leaq 0x1(%rax), %rdx
movq %rdx, (%r14)
leaq (%rax,%rax,4), %rax
movq 0x38(%rsp), %rdx
movq %rdx, 0x20(%rcx,%rax,8)
movupd 0x18(%rsp), %xmm0
movupd 0x28(%rsp), %xmm1
movupd %xmm1, 0x10(%rcx,%rax,8)
movupd %xmm0, (%rcx,%rax,8)
movl 0x8(%r15), %esi
movl (%r15), %ebx
movl 0x4(%r15), %ebp
movq %r12, (%rsp)
leaq 0x10(%rsp), %rdi
movq %rbx, %rdx
movq %rbp, %rcx
leaq 0x18(%rsp), %r8
jmp 0x17236b
movq (%r14), %rbx
leaq 0x10(%rsp), %rdi
movq $0x0, (%rdi)
movl 0x14(%r15), %esi
movl 0xc(%r15), %edx
movl 0x10(%r15), %ecx
movq %r12, (%rsp)
leaq 0x18(%rsp), %r8
movq %r13, %r9
callq 0x172045
testl %eax, %eax
je 0x17252f
leaq 0x18(%rsp), %rbp
movl 0x20(%rsp), %edi
movl 0x24(%rsp), %esi
movl 0x18(%rsp), %edx
movl 0x1c(%rsp), %ecx
movl 0x28(%rsp), %r8d
movl 0x28(%r15), %eax
shrl $0x6, %eax
andl $0x1, %eax
movl %eax, 0x8(%rsp)
movl %ebx, (%rsp)
movq %r14, %r9
callq 0x1720f8
movl 0x14(%r15), %esi
movl 0xc(%r15), %edx
movl 0x10(%r15), %ecx
movq %r12, (%rsp)
leaq 0x10(%rsp), %rdi
movq %rbp, %r8
movq %r13, %r9
callq 0x172045
testl %eax, %eax
jne 0x1724dd
cmpq (%r14), %rbx
movq 0x40(%rsp), %r9
jae 0x172693
leaq (,%rbx,8), %rax
leaq (%rax,%rax,4), %r12
movl $0x2, %r13d
movq 0x10(%r14), %rbp
movl 0x4(%rbp,%r12), %eax
cmpl (%rbp,%r12), %eax
jbe 0x172683
movl 0x18(%rbp,%r12), %eax
cmpl 0x14(%rbp,%r12), %eax
jbe 0x172683
movq 0x8(%r9), %rax
cmpq %rax, (%r9)
jne 0x1725a5
leaq (%rax,%rax), %rcx
testq %rax, %rax
cmoveq %r13, %rcx
movq %rcx, 0x8(%r9)
movq 0x10(%r9), %rdi
shlq $0x4, %rcx
leaq (%rcx,%rcx,2), %rsi
callq 0x2370
movq 0x40(%rsp), %r9
movq %rax, 0x10(%r9)
movq (%r9), %rcx
movq 0x10(%r9), %rax
leaq 0x1(%rcx), %rdx
movq %rdx, (%r9)
leaq (%rcx,%rcx,2), %rcx
shlq $0x4, %rcx
movb 0x28(%r15), %dl
andb $0x3f, %dl
movb 0x28(%rax,%rcx), %sil
andb $-0x40, %sil
orb %dl, %sil
movb %sil, 0x28(%rax,%rcx)
movb 0x28(%r15), %sil
andb $0x40, %sil
orb %dl, %sil
movb %sil, 0x28(%rax,%rcx)
movl 0x10(%rbp,%r12), %edx
movl %edx, 0x8(%rax,%rcx)
movl (%rbp,%r12), %edx
movl %edx, (%rax,%rcx)
movl 0x4(%rbp,%r12), %esi
movl %esi, 0x4(%rax,%rcx)
movl 0x24(%rbp,%r12), %edi
movl %edi, 0x14(%rax,%rcx)
movl 0x14(%rbp,%r12), %edi
movl %edi, 0xc(%rax,%rcx)
movl 0x18(%rbp,%r12), %r8d
movl %r8d, 0x10(%rax,%rcx)
subl %edx, %esi
xorps %xmm0, %xmm0
cvtsi2sd %rsi, %xmm0
movl 0x4(%r15), %edx
subl (%r15), %edx
xorps %xmm1, %xmm1
cvtsi2sd %rdx, %xmm1
movl 0x10(%r15), %edx
divsd %xmm1, %xmm0
movsd 0x20(%r15), %xmm1
subl %edi, %r8d
xorps %xmm2, %xmm2
cvtsi2sd %r8, %xmm2
subl 0xc(%r15), %edx
mulsd %xmm1, %xmm0
cvtsi2sd %rdx, %xmm3
divsd %xmm3, %xmm2
mulsd %xmm1, %xmm2
movapd %xmm0, %xmm1
cmplesd %xmm2, %xmm1
andpd %xmm1, %xmm0
andnpd %xmm2, %xmm1
orpd %xmm0, %xmm1
movlpd %xmm1, 0x20(%rax,%rcx)
movl $0x0, 0x18(%rax,%rcx)
incq %rbx
addq $0x28, %r12
cmpq (%r14), %rbx
jb 0x17254f
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq