// File: /workspace/github_cpp_makefile_star2_O2/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 $0x48, %rsp
movl %r9d, 0xc(%rsp)
movq %r8, 0x40(%rsp)
movq %rcx, 0x38(%rsp)
movq %rsi, 0x30(%rsp)
movl 0xa0(%rsp), %r15d
movl 0x98(%rsp), %r13d
movq 0x88(%rsp), %rsi
movq 0x28(%rsi), %rax
movq (%rax,%r15,8), %rax
movl %eax, %ecx
shrq $0x20, %rax
imulq $0x30, %rax, %r14
addq 0x10(%rsi), %r14
imulq $0x30, %rcx, %rax
movq %rax, 0x20(%rsp)
xorl %ebp, %ebp
movq %rdx, 0x18(%rsp)
movq %rdi, 0x10(%rsp)
cmpq %rbp, 0x20(%rsp)
je 0x1189e3
movl 0x14(%r14,%rbp), %eax
cmpl %r13d, %eax
je 0x1189da
movq (%rdx), %rcx
movq 0x80(%rdx), %rsi
movl (%rcx,%rax,4), %eax
incq %rsi
cmpq %rax, %rsi
jb 0x1189da
movq (%rdi), %rax
movq 0x18(%rax), %rax
movq 0x20(%rax), %rax
movl (%rax,%r13,8), %eax
movl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
andl %ecx, %eax
movl (%r14,%rbp), %r10d
movl 0x4(%r14,%rbp), %r11d
subq $0x8, %rsp
movq %rdi, %r12
movq 0x38(%rsp), %rsi
movq 0x40(%rsp), %rcx
movq 0x48(%rsp), %r8
movl 0x14(%rsp), %r9d
movq %r14, %rbx
movq %r13, %r14
movq %r15, %r13
leaq 0x30(%rsp), %r15
pushq %r15
movq %r13, %r15
movq %r14, %r13
movq %rbx, %r14
pushq %r11
pushq %r10
pushq %r15
pushq %rax
pushq $0x0
pushq %r13
callq 0x12197e
movq 0x58(%rsp), %rdx
movq %r12, %rdi
movq 0xd0(%rsp), %rsi
addq $0x40, %rsp
testl %eax, %eax
je 0x1189da
movq 0x80(%rsp), %rcx
movsd (%rcx,%r15,8), %xmm0
unpcklps 0xcaa28(%rip), %xmm0    # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1]
subpd 0xcaa30(%rip), %xmm0    # 0x1e3280
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
movl 0x4(%r14,%rbp), %eax
subl (%r14,%rbp), %eax
cvtsi2sd %rax, %xmm2
addsd %xmm0, %xmm1
movq (%rdi), %rax
movq 0x18(%rax), %rax
movq 0x20(%rax), %rax
movl (%rax,%r15,8), %eax
movl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
andl %edx, %eax
cvtsi2sd %eax, %xmm0
movq (%rcx,%r13,8), %r15
divsd %xmm0, %xmm2
mulsd %xmm1, %xmm2
addsd 0xcacb0(%rip), %xmm2    # 0x1e3548
cvttsd2si %xmm2, %rax
movq %rax, %rcx
sarq $0x3f, %rcx
subsd 0xca9ec(%rip), %xmm2    # 0x1e3298
cvttsd2si %xmm2, %r13
andq %rcx, %r13
orq %rax, %r13
cmpq $0x1, %r13
adcq $0x0, %r13
movq (%rsi), %rax
movq 0x10(%rsi), %rbx
cmpq 0x8(%rsi), %rax
jne 0x1188fc
leaq (%rax,%rax), %rcx
testq %rax, %rax
pushq $0x2
popq %rax
cmoveq %rax, %rcx
movq %rcx, 0x8(%rsi)
imulq $0x30, %rcx, %rsi
movq %rbx, %rdi
callq 0x2370
movq 0x90(%rsp), %rsi
movq %rax, %rbx
movq %rax, 0x10(%rsi)
movq (%rsi), %rax
leaq 0x1(%rax), %rcx
movq %rcx, (%rsi)
imulq $0x30, %rax, %r12
xorpd %xmm0, %xmm0
movupd %xmm0, (%rbx,%r12)
movupd %xmm0, 0x20(%rbx,%r12)
movupd %xmm0, 0x10(%rbx,%r12)
movl 0x98(%rsp), %eax
movl %eax, 0x8(%rbx,%r12)
movl 0x14(%r14,%rbp), %eax
movl %eax, 0x14(%rbx,%r12)
movsd 0x28(%rsp), %xmm0
movsd %xmm0, 0x20(%rbx,%r12)
cmpq %r13, %r15
cmovbq %r15, %r13
movl %r13d, 0x18(%rbx,%r12)
movq (%rsi), %rcx
movq 0x10(%rsi), %rax
cmpq 0x8(%rsi), %rcx
jne 0x118988
leaq (%rcx,%rcx), %rdx
testq %rcx, %rcx
pushq $0x2
popq %rcx
cmoveq %rcx, %rdx
movq %rdx, 0x8(%rsi)
imulq $0x30, %rdx, %rsi
movq %rax, %rdi
callq 0x2370
movq 0x90(%rsp), %rsi
movq %rax, 0x10(%rsi)
movq (%rsi), %rcx
movq 0x10(%rsp), %rdi
addq %r12, %rbx
leaq 0x1(%rcx), %rdx
movq %rdx, (%rsi)
imulq $0x30, %rcx, %rcx
movups (%rbx), %xmm0
movups 0x10(%rbx), %xmm1
movups 0x20(%rbx), %xmm2
movups %xmm2, 0x20(%rax,%rcx)
movups %xmm1, 0x10(%rax,%rcx)
movups %xmm0, (%rax,%rcx)
movl 0x14(%rbx), %edx
movl %edx, 0x8(%rax,%rcx)
movl 0x8(%rbx), %edx
movl %edx, 0x14(%rax,%rcx)
movq 0x18(%rsp), %rdx
movl 0xa0(%rsp), %r12d
movq %r12, %r15
movl 0x98(%rsp), %r13d
addq $0x30, %rbp
jmp 0x118782
cmpl %r15d, %r13d
jne 0x1189f7
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x88(%rsp), %rsi
movq 0x28(%rsi), %rax
movq (%rax,%r13,8), %rax
movl %eax, %ecx
shrq $0x20, %rax
imulq $0x30, %rax, %r14
addq 0x10(%rsi), %r14
imulq $0x30, %rcx, %rax
movq %rax, 0x20(%rsp)
xorl %ebp, %ebp
cmpq %rbp, 0x20(%rsp)
je 0x1189e8
movl 0x14(%r14,%rbp), %eax
cmpl %r15d, %eax
je 0x118c75
movq (%rdx), %rcx
movq 0x80(%rdx), %rsi
movl (%rcx,%rax,4), %eax
incq %rsi
cmpq %rax, %rsi
jb 0x118c75
movl (%r14,%rbp), %eax
movl 0x4(%r14,%rbp), %r10d
movq (%rdi), %rcx
movq 0x18(%rcx), %rcx
movq 0x20(%rcx), %rcx
movl (%rcx,%r15,8), %r11d
movl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
andl %ecx, %r11d
subq $0x8, %rsp
movq %rdi, %r12
movq 0x38(%rsp), %rsi
movq 0x40(%rsp), %rcx
movq 0x48(%rsp), %r8
movl 0x14(%rsp), %r9d
movq %r14, %rbx
movq %r13, %r14
movq %r15, %r13
leaq 0x30(%rsp), %r15
pushq %r15
movq %r13, %r15
movq %r14, %r13
movq %rbx, %r14
pushq %r11
pushq $0x0
pushq %r15
pushq %r10
pushq %rax
pushq %r13
callq 0x12197e
movq 0x58(%rsp), %rdx
movq %r12, %rdi
movq 0xd0(%rsp), %rsi
addq $0x40, %rsp
testl %eax, %eax
je 0x118c75
movq 0x80(%rsp), %rdx
movsd (%rdx,%r13,8), %xmm0
unpcklps 0xca78d(%rip), %xmm0    # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1]
subpd 0xca795(%rip), %xmm0    # 0x1e3280
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
addsd %xmm0, %xmm1
movl 0x4(%r14,%rbp), %eax
subl (%r14,%rbp), %eax
cvtsi2sd %rax, %xmm0
movq (%rdi), %rax
movq 0x18(%rax), %rax
movq 0x20(%rax), %rax
movl (%rax,%r13,8), %eax
movl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
andl %ecx, %eax
cvtsi2sd %eax, %xmm2
divsd %xmm2, %xmm0
mulsd %xmm1, %xmm0
addsd 0xcaa19(%rip), %xmm0    # 0x1e3548
cvttsd2si %xmm0, %rax
movq %rax, %rcx
sarq $0x3f, %rcx
subsd 0xca755(%rip), %xmm0    # 0x1e3298
cvttsd2si %xmm0, %r13
andq %rcx, %r13
orq %rax, %r13
movq (%rdx,%r15,8), %r15
cmpq $0x1, %r13
adcq $0x0, %r13
movq (%rsi), %rax
movq 0x10(%rsi), %rbx
cmpq 0x8(%rsi), %rax
jne 0x118b97
leaq (%rax,%rax), %rcx
testq %rax, %rax
pushq $0x2
popq %rax
cmoveq %rax, %rcx
movq %rcx, 0x8(%rsi)
imulq $0x30, %rcx, %rsi
movq %rbx, %rdi
callq 0x2370
movq 0x90(%rsp), %rsi
movq %rax, %rbx
movq %rax, 0x10(%rsi)
movq (%rsi), %rax
leaq 0x1(%rax), %rcx
movq %rcx, (%rsi)
imulq $0x30, %rax, %r12
xorpd %xmm0, %xmm0
movupd %xmm0, (%rbx,%r12)
movupd %xmm0, 0x20(%rbx,%r12)
movupd %xmm0, 0x10(%rbx,%r12)
movl 0xa0(%rsp), %eax
movl %eax, 0x8(%rbx,%r12)
movl 0x14(%r14,%rbp), %eax
movl %eax, 0x14(%rbx,%r12)
movsd 0x28(%rsp), %xmm0
movsd %xmm0, 0x20(%rbx,%r12)
cmpq %r15, %r13
cmovbq %r13, %r15
movl %r15d, 0x18(%rbx,%r12)
movq (%rsi), %rcx
movq 0x10(%rsi), %rax
cmpq 0x8(%rsi), %rcx
jne 0x118c23
leaq (%rcx,%rcx), %rdx
testq %rcx, %rcx
pushq $0x2
popq %rcx
cmoveq %rcx, %rdx
movq %rdx, 0x8(%rsi)
imulq $0x30, %rdx, %rsi
movq %rax, %rdi
callq 0x2370
movq 0x90(%rsp), %rsi
movq %rax, 0x10(%rsi)
movq (%rsi), %rcx
movq 0x10(%rsp), %rdi
movl 0x98(%rsp), %r13d
addq %r12, %rbx
leaq 0x1(%rcx), %rdx
movq %rdx, (%rsi)
imulq $0x30, %rcx, %rcx
movups (%rbx), %xmm0
movups 0x10(%rbx), %xmm1
movups 0x20(%rbx), %xmm2
movups %xmm2, 0x20(%rax,%rcx)
movups %xmm1, 0x10(%rax,%rcx)
movups %xmm0, (%rax,%rcx)
movl 0x14(%rbx), %edx
movl %edx, 0x8(%rax,%rcx)
movl 0x8(%rbx), %edx
movl %edx, 0x14(%rax,%rcx)
movq 0x18(%rsp), %rdx
movl 0xa0(%rsp), %r12d
movq %r12, %r15
addq $0x30, %rbp
jmp 0x118a20