// File: /workspace/github_cpp_makefile_star2_O2/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
andq $0x0, (%rcx)
leaq 0x10(%rsp), %rax
andq $0x0, (%rax)
movq %rsi, %r13
movq %rdi, %r15
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
movq %r13, %r9
callq 0x134dee
testl %eax, %eax
je 0x1351c6
movl %ebp, %edx
subl %ebx, %edx
movl 0xc(%r15), %ecx
movl 0x10(%r15), %eax
movl %eax, %esi
subl %ecx, %esi
testb $0x40, 0x28(%r15)
cvtsi2sd %rdx, %xmm0
cvtsi2sd %rsi, %xmm1
jne 0x135127
movl 0x20(%rsp), %edx
subl %ebx, %edx
cvtsi2sd %rdx, %xmm2
divsd %xmm0, %xmm2
mulsd %xmm1, %xmm2
cvttsd2si %xmm2, %rdx
addl %edx, %ecx
movl %ecx, 0x34(%rsp)
subl 0x24(%rsp), %ebp
jmp 0x135149
subl 0x24(%rsp), %ebp
cvtsi2sd %rbp, %xmm2
divsd %xmm0, %xmm2
mulsd %xmm1, %xmm2
cvttsd2si %xmm2, %rdx
addl %edx, %ecx
movl %ecx, 0x34(%rsp)
movl 0x20(%rsp), %ebp
subl %ebx, %ebp
movl %ebp, %ecx
cvtsi2sd %rcx, %xmm2
divsd %xmm0, %xmm2
mulsd %xmm1, %xmm2
cvttsd2si %xmm2, %rcx
subl %ecx, %eax
movl %eax, 0x38(%rsp)
movq (%r14), %rcx
movq 0x10(%r14), %rax
cmpq 0x8(%r14), %rcx
jne 0x135195
leaq (%rcx,%rcx), %rdx
testq %rcx, %rcx
pushq $0x2
popq %rcx
cmoveq %rcx, %rdx
movq %rdx, 0x8(%r14)
imulq $0x28, %rdx, %rsi
movq %rax, %rdi
callq 0x2370
movq %rax, 0x10(%r14)
movq (%r14), %rcx
leaq 0x1(%rcx), %rdx
movq %rdx, (%r14)
imulq $0x28, %rcx, %rcx
movq 0x38(%rsp), %rdx
movq %rdx, 0x20(%rax,%rcx)
movupd 0x18(%rsp), %xmm0
movupd 0x28(%rsp), %xmm1
movupd %xmm1, 0x10(%rax,%rcx)
movupd %xmm0, (%rax,%rcx)
jmp 0x1350b3
movq (%r14), %rbx
leaq 0x10(%rsp), %rax
andq $0x0, (%rax)
leaq 0x18(%rsp), %rbp
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 0x134dee
testl %eax, %eax
je 0x13522b
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 0x134e92
jmp 0x1351d7
imulq $0x28, %rbx, %r12
movq 0x40(%rsp), %rbp
cmpq (%r14), %rbx
jae 0x13536f
movq 0x10(%r14), %r13
movl 0x4(%r13,%r12), %eax
cmpl (%r13,%r12), %eax
jbe 0x135363
movl 0x18(%r13,%r12), %eax
cmpl 0x14(%r13,%r12), %eax
jbe 0x135363
movq (%rbp), %rcx
movq 0x10(%rbp), %rax
cmpq 0x8(%rbp), %rcx
jne 0x135295
leaq (%rcx,%rcx), %rdx
testq %rcx, %rcx
pushq $0x2
popq %rcx
cmoveq %rcx, %rdx
movq %rdx, 0x8(%rbp)
imulq $0x30, %rdx, %rsi
movq %rax, %rdi
callq 0x2370
movq %rax, 0x10(%rbp)
movq (%rbp), %rcx
leaq 0x1(%rcx), %rdx
movq %rdx, (%rbp)
imulq $0x30, %rcx, %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 (%r13,%r12), %xmm0
movl 0x24(%r13,%r12), %edx
movl %edx, 0x14(%rax,%rcx)
movq 0x10(%r13,%r12), %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(%r13,%r12), %esi
movd %xmm2, %edi
cvtsi2sd %rdi, %xmm0
movl %esi, 0x10(%rax,%rcx)
movl 0x4(%r15), %edi
subl (%r15), %edi
movl 0x10(%r15), %r8d
cvtsi2sd %rdi, %xmm1
divsd %xmm1, %xmm0
movsd 0x20(%r15), %xmm1
subl %edx, %esi
cvtsi2sd %rsi, %xmm2
subl 0xc(%r15), %r8d
cvtsi2sd %r8, %xmm3
mulsd %xmm1, %xmm0
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)
andl $0x0, 0x18(%rax,%rcx)
incq %rbx
addq $0x28, %r12
jmp 0x135234
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq