// File: /workspace/github_cpp_makefile_star2_O3/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 $0x58, %rsp
movq %r8, 0x48(%rsp)
movq %rcx, %r14
movq %rsi, %r13
movq %rdi, %r15
xorl %r12d, %r12d
movq %r12, (%rcx)
leaq 0x18(%rsp), %rdi
movq %r12, (%rdi)
movl 0x8(%r15), %esi
movl (%r15), %ebx
movl 0x4(%r15), %ebp
movq %rdx, 0x50(%rsp)
movq %rdx, (%rsp)
leaq 0x20(%rsp), %r8
movq %rbx, %rdx
movq %rbp, %rcx
movq %r13, %r9
callq 0x178c02
testl %eax, %eax
je 0x17905d
movl $0x2, %r12d
movl %ebp, %edx
subl %ebx, %edx
movl 0xc(%r15), %ecx
movl 0x10(%r15), %eax
movl %eax, %esi
subl %ecx, %esi
testb $0x40, 0x28(%r15)
xorps %xmm0, %xmm0
cvtsi2sd %rdx, %xmm0
xorps %xmm1, %xmm1
cvtsi2sd %rsi, %xmm1
jne 0x178f85
movl 0x28(%rsp), %edx
subl %ebx, %edx
xorps %xmm2, %xmm2
cvtsi2sd %rdx, %xmm2
divsd %xmm0, %xmm2
mulsd %xmm1, %xmm2
cvttsd2si %xmm2, %rdx
addl %edx, %ecx
movl %ecx, 0x3c(%rsp)
subl 0x2c(%rsp), %ebp
jmp 0x178faa
subl 0x2c(%rsp), %ebp
xorps %xmm2, %xmm2
cvtsi2sd %rbp, %xmm2
divsd %xmm0, %xmm2
mulsd %xmm1, %xmm2
cvttsd2si %xmm2, %rdx
addl %edx, %ecx
movl %ecx, 0x3c(%rsp)
movl 0x28(%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, 0x40(%rsp)
movq (%r14), %rcx
movq 0x10(%r14), %rax
cmpq 0x8(%r14), %rcx
jne 0x178ffa
leaq (%rcx,%rcx), %rdx
testq %rcx, %rcx
cmoveq %r12, %rdx
movq %rdx, 0x8(%r14)
shlq $0x3, %rdx
leaq (%rdx,%rdx,4), %rsi
movq %rax, %rdi
callq 0x2370
movq %rax, 0x10(%r14)
movq (%r14), %rcx
leaq 0x1(%rcx), %rdx
movq %rdx, (%r14)
leaq (%rcx,%rcx,4), %rcx
movq 0x40(%rsp), %rdx
movq %rdx, 0x20(%rax,%rcx,8)
movupd 0x20(%rsp), %xmm0
movupd 0x30(%rsp), %xmm1
movupd %xmm1, 0x10(%rax,%rcx,8)
movupd %xmm0, (%rax,%rcx,8)
movl 0x8(%r15), %esi
movl (%r15), %ebx
movl 0x4(%r15), %ebp
movq 0x50(%rsp), %rax
movq %rax, (%rsp)
leaq 0x18(%rsp), %rdi
movq %rbx, %rdx
movq %rbp, %rcx
leaq 0x20(%rsp), %r8
movq %r13, %r9
callq 0x178c02
testl %eax, %eax
jne 0x178f37
movq (%r14), %r12
leaq 0x18(%rsp), %rdi
movq $0x0, (%rdi)
movl 0x14(%r15), %esi
movl 0xc(%r15), %edx
movl 0x10(%r15), %ecx
movq 0x50(%rsp), %rbx
movq %rbx, (%rsp)
leaq 0x20(%rsp), %r8
movq %r13, %r9
callq 0x178c02
movq %r12, %rcx
testl %eax, %eax
je 0x1790ed
leaq 0x20(%rsp), %rbp
movl 0x28(%rsp), %edi
movl 0x2c(%rsp), %esi
movl 0x20(%rsp), %edx
movl 0x24(%rsp), %ecx
movl 0x30(%rsp), %r8d
movl 0x28(%r15), %eax
shrl $0x6, %eax
andl $0x1, %eax
movl %eax, 0x8(%rsp)
movl %r12d, (%rsp)
movq %r14, %r9
callq 0x178cb5
movl 0x14(%r15), %esi
movl 0xc(%r15), %edx
movl 0x10(%r15), %ecx
movq %rbx, (%rsp)
leaq 0x18(%rsp), %rdi
movq %rbp, %r8
movq %r13, %r9
callq 0x178c02
testl %eax, %eax
jne 0x179097
movq (%r14), %rcx
cmpq %rcx, %r12
movq 0x48(%rsp), %r9
jae 0x179251
leaq (,%r12,8), %rax
leaq (%rax,%rax,4), %rbx
movl $0x2, %r13d
movq 0x10(%r14), %rbp
movl 0x4(%rbp,%rbx), %eax
cmpl (%rbp,%rbx), %eax
jbe 0x179241
movl 0x18(%rbp,%rbx), %eax
cmpl 0x14(%rbp,%rbx), %eax
jbe 0x179241
movq (%r9), %rcx
movq 0x10(%r9), %rax
cmpq 0x8(%r9), %rcx
jne 0x179165
leaq (%rcx,%rcx), %rdx
testq %rcx, %rcx
cmoveq %r13, %rdx
movq %rdx, 0x8(%r9)
shlq $0x4, %rdx
leaq (%rdx,%rdx,2), %rsi
movq %rax, %rdi
callq 0x2370
movq 0x48(%rsp), %r9
movq %rax, 0x10(%r9)
movq (%r9), %rcx
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)
movq (%rbp,%rbx), %xmm0
movl 0x24(%rbp,%rbx), %edx
movl %edx, 0x14(%rax,%rcx)
movq 0x10(%rbp,%rbx), %xmm1
pshufd $0x55, %xmm0, %xmm2     # xmm2 = xmm0[1,1,1,1]
psubd %xmm0, %xmm2
punpcklqdq %xmm1, %xmm0    # xmm0 = xmm0[0],xmm1[0]
pshufd $0x55, %xmm1, %xmm1     # xmm1 = xmm1[1,1,1,1]
movd %xmm1, %edx
movdqu %xmm0, (%rax,%rcx)
movl 0x18(%rbp,%rbx), %esi
movl %esi, 0x10(%rax,%rcx)
movd %xmm2, %edi
xorps %xmm0, %xmm0
cvtsi2sd %rdi, %xmm0
movl 0x4(%r15), %edi
movl 0x10(%r15), %r8d
subl (%r15), %edi
xorps %xmm1, %xmm1
cvtsi2sd %rdi, %xmm1
divsd %xmm1, %xmm0
movsd 0x20(%r15), %xmm1
mulsd %xmm1, %xmm0
subl %edx, %esi
xorps %xmm2, %xmm2
cvtsi2sd %rsi, %xmm2
subl 0xc(%r15), %r8d
cvtsi2sd %r8, %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)
movq (%r14), %rcx
incq %r12
addq $0x28, %rbx
cmpq %rcx, %r12
jb 0x17910d
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq