// File: /workspace/github_cpp_makefile_star2_O1/chhylp123[P]hifiasm/hic.cpp
// Function: append_trans_hits(ha_ug_index*, hc_links*, bubble_type*, trans_idx*, pe_hit*, unsigned int, unsigned long*, kv_u_trans_t*, kv_u_trans_t*, unsigned int, unsigned int)
void append_trans_hits(ha_ug_index* idx, hc_links* link, bubble_type* bub, 
trans_idx* dis, pe_hit *hit, uint32_t hit_n, uint64_t *hit_occ, kv_u_trans_t *ref,
kv_u_trans_t *res, uint32_t qn, uint32_t tn)
{
    u_trans_t *r_a = NULL, *p = NULL, *q = NULL;
    uint32_t r_n, i;
    uint64_t occ_q, occ_t;
    double w;

    ///qn -> tn^
    {
        r_a = u_trans_a(*ref, tn);
        r_n = u_trans_n(*ref, tn);
        for (i = 0; i < r_n; i++)
        {
            if(IF_HOM(r_a[i].tn, *bub)) continue;
            if(r_a[i].tn == qn) continue;

            if(!get_trans_interval_weight(idx, link, bub, dis, hit, hit_n, 
            qn, 0, idx->ug->g->seq[qn].len, tn, r_a[i].qs, r_a[i].qe, &w))
            {
                continue;
            } 

            occ_q = hit_occ[qn];
            occ_t = (hit_occ[tn] * ((double)(r_a[i].qe - r_a[i].qs)/(double)(idx->ug->g->seq[tn].len))) + 0.5;
            if(occ_t < 1) occ_t = 1;

            kv_pushp(u_trans_t, *res, &p);
            memset(p, 0, sizeof(u_trans_t));
            p->qn = qn; p->tn = r_a[i].tn;
            p->nw = w/**r_a[i].occ**/;
            p->occ = MIN(occ_q, occ_t);

            kv_pushp(u_trans_t, *res, &q);
            (*q) = (*p); q->qn = p->tn; q->tn = p->qn;
        }
    }

    if(qn == tn) return;

   ///tn -> qn^
    {
        r_a = u_trans_a(*ref, qn);
        r_n = u_trans_n(*ref, qn);
        for (i = 0; i < r_n; i++)
        {
            if(IF_HOM(r_a[i].tn, *bub)) continue;
            if(r_a[i].tn == tn) continue;

            if(!get_trans_interval_weight(idx, link, bub, dis, hit, hit_n, 
            qn, r_a[i].qs, r_a[i].qe, tn, 0, idx->ug->g->seq[tn].len, &w))
            {
                continue;
            } 

            occ_q = (hit_occ[qn] * ((double)(r_a[i].qe - r_a[i].qs)/(double)(idx->ug->g->seq[qn].len))) + 0.5;
            occ_t = hit_occ[tn];
            if(occ_q < 1) occ_q = 1;
            kv_pushp(u_trans_t, *res, &p);
            memset(p, 0, sizeof(u_trans_t));
            p->qn = tn; p->tn = r_a[i].tn;
            p->nw = w/**r_a[i].occ**/;
            p->occ = MIN(occ_q, occ_t);

            kv_pushp(u_trans_t, *res, &q);
            (*q) = (*p); q->qn = p->tn; q->tn = p->qn;
        }
    }
    
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movl %r9d, 0xc(%rsp)
movq %r8, 0x50(%rsp)
movq %rcx, 0x48(%rsp)
movq %rdx, %r15
movq %rsi, 0x40(%rsp)
movq %rdi, %r12
movl 0xb0(%rsp), %ebp
movl 0xa8(%rsp), %r13d
movq 0x98(%rsp), %rax
movq 0x28(%rax), %rax
movq (%rax,%rbp,8), %rax
movl %r13d, %ecx
movq %rcx, 0x10(%rsp)
testl %eax, %eax
movq %rdx, 0x38(%rsp)
movq %rdi, 0x30(%rsp)
je 0x158c7f
movq %rax, %rcx
shrq $0x20, %rcx
leaq (%rcx,%rcx,2), %r14
shlq $0x4, %r14
movq 0x98(%rsp), %rcx
addq 0x10(%rcx), %r14
movl %eax, %eax
shlq $0x4, %rax
leaq (%rax,%rax,2), %rax
movq %rax, 0x20(%rsp)
xorl %ebx, %ebx
movl 0x14(%r14,%rbx), %eax
cmpl %r13d, %eax
je 0x158c70
movq (%r15), %rcx
movq 0x80(%r15), %rdx
movl (%rcx,%rax,4), %eax
incq %rdx
cmpq %rax, %rdx
jb 0x158c70
movq (%r12), %rax
movq 0x18(%rax), %rax
movq 0x20(%rax), %rax
movq 0x10(%rsp), %rcx
movl (%rax,%rcx,8), %eax
movl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
andl %ecx, %eax
movl (%r14,%rbx), %ecx
movq %rcx, 0x18(%rsp)
movl 0x4(%r14,%rbx), %r11d
subq $0x8, %rsp
movq %r12, %rdi
movq 0x48(%rsp), %rsi
movq %r15, %rdx
movq 0x50(%rsp), %rcx
movq 0x58(%rsp), %r8
movl 0x14(%rsp), %r9d
movq %r15, %r10
movq %r14, %r15
movq %r13, %r14
movq %rbp, %r13
movq %r12, %rbp
leaq 0x30(%rsp), %r12
pushq %r12
movq %rbp, %r12
movq %r13, %rbp
movq %r14, %r13
movq %r15, %r14
movq %r10, %r15
pushq %r11
pushq 0x30(%rsp)
pushq %rbp
pushq %rax
pushq $0x0
pushq %r13
callq 0x15f619
addq $0x40, %rsp
testl %eax, %eax
je 0x158c70
movq 0x90(%rsp), %rdx
movsd (%rdx,%rbp,8), %xmm0
unpcklps 0xcc783(%rip), %xmm0    # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1]
subpd 0xcc78b(%rip), %xmm0    # 0x225250
movapd %xmm0, %xmm1
movl 0x4(%r14,%rbx), %eax
subl (%r14,%rbx), %eax
cvtsi2sd %rax, %xmm2
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
movq (%r12), %rax
movq 0x18(%rax), %rax
movq 0x20(%rax), %rax
movl (%rax,%rbp,8), %eax
movl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
andl %ecx, %eax
cvtsi2sd %eax, %xmm3
addsd %xmm0, %xmm1
divsd %xmm3, %xmm2
mulsd %xmm1, %xmm2
addsd 0xcc9e7(%rip), %xmm2    # 0x2254f0
cvttsd2si %xmm2, %rax
movq %rax, %rcx
sarq $0x3f, %rcx
subsd 0xcc74b(%rip), %xmm2    # 0x225268
cvttsd2si %xmm2, %r13
andq %rcx, %r13
orq %rax, %r13
cmpq $0x1, %r13
adcq $0x0, %r13
movq 0x10(%rsp), %rax
movq (%rdx,%rax,8), %r12
movq 0xa0(%rsp), %rdx
movq 0x8(%rdx), %rax
cmpq %rax, (%rdx)
jne 0x158b7b
leaq (%rax,%rax), %rcx
testq %rax, %rax
movl $0x2, %eax
cmoveq %rax, %rcx
movq %rcx, 0x8(%rdx)
movq 0x10(%rdx), %rdi
shlq $0x4, %rcx
leaq (%rcx,%rcx,2), %rsi
callq 0x2370
movq 0xa0(%rsp), %rdx
movq %rax, 0x10(%rdx)
movq (%rdx), %rax
movq 0x10(%rdx), %rbp
leaq 0x1(%rax), %rcx
movq %rcx, (%rdx)
leaq (%rax,%rax,2), %r15
shlq $0x4, %r15
xorpd %xmm0, %xmm0
movupd %xmm0, (%rbp,%r15)
movupd %xmm0, 0x20(%rbp,%r15)
movupd %xmm0, 0x10(%rbp,%r15)
movl 0xa8(%rsp), %eax
movl %eax, 0x8(%rbp,%r15)
movl 0x14(%r14,%rbx), %eax
movl %eax, 0x14(%rbp,%r15)
movsd 0x28(%rsp), %xmm0
movsd %xmm0, 0x20(%rbp,%r15)
cmpq %r13, %r12
cmovbq %r12, %r13
movl %r13d, 0x18(%rbp,%r15)
movq 0x8(%rdx), %rax
cmpq %rax, (%rdx)
jne 0x158c13
leaq (%rax,%rax), %rcx
testq %rax, %rax
movl $0x2, %eax
cmoveq %rax, %rcx
movq %rcx, 0x8(%rdx)
movq 0x10(%rdx), %rdi
shlq $0x4, %rcx
leaq (%rcx,%rcx,2), %rsi
callq 0x2370
movq 0xa0(%rsp), %rdx
movq %rax, 0x10(%rdx)
addq %r15, %rbp
movq (%rdx), %rax
movq 0x10(%rdx), %rcx
movq %rdx, %rsi
leaq 0x1(%rax), %rdx
movq %rdx, (%rsi)
leaq (%rax,%rax,2), %rax
shlq $0x4, %rax
movups (%rbp), %xmm0
movups 0x10(%rbp), %xmm1
movups 0x20(%rbp), %xmm2
movups %xmm2, 0x20(%rcx,%rax)
movups %xmm1, 0x10(%rcx,%rax)
movups %xmm0, (%rcx,%rax)
movl 0x14(%rbp), %edx
movl %edx, 0x8(%rcx,%rax)
movl 0x8(%rbp), %edx
movl %edx, 0x14(%rcx,%rax)
movq 0x38(%rsp), %r15
movq 0x30(%rsp), %r12
movl 0xb0(%rsp), %ebp
movl 0xa8(%rsp), %r13d
addq $0x30, %rbx
cmpq %rbx, 0x20(%rsp)
jne 0x1589f9
cmpl %ebp, %r13d
je 0x158f3c
movq 0x98(%rsp), %rax
movq 0x28(%rax), %rax
movq 0x10(%rsp), %rcx
movq (%rax,%rcx,8), %rax
testl %eax, %eax
je 0x158f3c
movq %rax, %rcx
shrq $0x20, %rcx
leaq (%rcx,%rcx,2), %r14
shlq $0x4, %r14
movq 0x98(%rsp), %rcx
addq 0x10(%rcx), %r14
movl %eax, %eax
shlq $0x4, %rax
leaq (%rax,%rax,2), %rax
movq %rax, 0x20(%rsp)
xorl %ebx, %ebx
movl 0x14(%r14,%rbx), %eax
cmpl %ebp, %eax
je 0x158f2d
movq (%r15), %rcx
movq 0x80(%r15), %rdx
movl (%rcx,%rax,4), %eax
incq %rdx
cmpq %rax, %rdx
jb 0x158f2d
movl (%r14,%rbx), %eax
movq %rax, 0x18(%rsp)
movl 0x4(%r14,%rbx), %r10d
movq (%r12), %rcx
movq 0x18(%rcx), %rcx
movq 0x20(%rcx), %rcx
movl (%rcx,%rbp,8), %r11d
movl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
andl %ecx, %r11d
subq $0x8, %rsp
movq %r12, %rdi
movq 0x48(%rsp), %rsi
movq %r15, %rdx
movq 0x50(%rsp), %rcx
movq 0x58(%rsp), %r8
movl 0x14(%rsp), %r9d
movq %r14, %rax
leaq 0x30(%rsp), %r14
pushq %r14
movq %rax, %r14
pushq %r11
pushq $0x0
pushq %rbp
pushq %r10
pushq 0x48(%rsp)
pushq %r13
callq 0x15f619
addq $0x40, %rsp
testl %eax, %eax
je 0x158f2d
movq 0x90(%rsp), %rdx
movq 0x10(%rsp), %rcx
movsd (%rdx,%rcx,8), %xmm0
unpcklps 0xcc4c1(%rip), %xmm0    # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1]
subpd 0xcc4c9(%rip), %xmm0    # 0x225250
movapd %xmm0, %xmm1
movl 0x4(%r14,%rbx), %eax
subl (%r14,%rbx), %eax
cvtsi2sd %rax, %xmm2
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
movq (%r12), %rax
movq 0x18(%rax), %rax
movq 0x20(%rax), %rax
movl (%rax,%rcx,8), %eax
movl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
andl %ecx, %eax
cvtsi2sd %eax, %xmm3
addsd %xmm0, %xmm1
divsd %xmm3, %xmm2
mulsd %xmm1, %xmm2
addsd 0xcc725(%rip), %xmm2    # 0x2254f0
cvttsd2si %xmm2, %rax
movq %rax, %rcx
sarq $0x3f, %rcx
subsd 0xcc489(%rip), %xmm2    # 0x225268
cvttsd2si %xmm2, %r13
andq %rcx, %r13
orq %rax, %r13
cmpq $0x1, %r13
adcq $0x0, %r13
movq (%rdx,%rbp,8), %r12
movq 0xa0(%rsp), %rdx
movq 0x8(%rdx), %rax
cmpq %rax, (%rdx)
jne 0x158e38
leaq (%rax,%rax), %rcx
testq %rax, %rax
movl $0x2, %eax
cmoveq %rax, %rcx
movq %rcx, 0x8(%rdx)
movq 0x10(%rdx), %rdi
shlq $0x4, %rcx
leaq (%rcx,%rcx,2), %rsi
callq 0x2370
movq 0xa0(%rsp), %rdx
movq %rax, 0x10(%rdx)
movq (%rdx), %rax
movq 0x10(%rdx), %rbp
leaq 0x1(%rax), %rcx
movq %rcx, (%rdx)
leaq (%rax,%rax,2), %r15
shlq $0x4, %r15
xorpd %xmm0, %xmm0
movupd %xmm0, (%rbp,%r15)
movupd %xmm0, 0x20(%rbp,%r15)
movupd %xmm0, 0x10(%rbp,%r15)
movl 0xb0(%rsp), %eax
movl %eax, 0x8(%rbp,%r15)
movl 0x14(%r14,%rbx), %eax
movl %eax, 0x14(%rbp,%r15)
movsd 0x28(%rsp), %xmm0
movsd %xmm0, 0x20(%rbp,%r15)
cmpq %r12, %r13
cmovbq %r13, %r12
movl %r12d, 0x18(%rbp,%r15)
movq 0x8(%rdx), %rax
cmpq %rax, (%rdx)
jne 0x158ed0
leaq (%rax,%rax), %rcx
testq %rax, %rax
movl $0x2, %eax
cmoveq %rax, %rcx
movq %rcx, 0x8(%rdx)
movq 0x10(%rdx), %rdi
shlq $0x4, %rcx
leaq (%rcx,%rcx,2), %rsi
callq 0x2370
movq 0xa0(%rsp), %rdx
movq %rax, 0x10(%rdx)
addq %r15, %rbp
movq (%rdx), %rax
movq 0x10(%rdx), %rcx
movq %rdx, %rsi
leaq 0x1(%rax), %rdx
movq %rdx, (%rsi)
leaq (%rax,%rax,2), %rax
shlq $0x4, %rax
movups (%rbp), %xmm0
movups 0x10(%rbp), %xmm1
movups 0x20(%rbp), %xmm2
movups %xmm2, 0x20(%rcx,%rax)
movups %xmm1, 0x10(%rcx,%rax)
movups %xmm0, (%rcx,%rax)
movl 0x14(%rbp), %edx
movl %edx, 0x8(%rcx,%rax)
movl 0x8(%rbp), %edx
movl %edx, 0x14(%rcx,%rax)
movq 0x38(%rsp), %r15
movq 0x30(%rsp), %r12
movl 0xb0(%rsp), %ebp
movl 0xa8(%rsp), %r13d
addq $0x30, %rbx
cmpq %rbx, 0x20(%rsp)
jne 0x158cd1
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq