// File: /workspace/github_cpp_makefile_star2_O3/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, 0x48(%rsp)
movq %rcx, 0x40(%rsp)
movq %rsi, 0x38(%rsp)
movq %rdi, %r14
movl 0xb0(%rsp), %r12d
movl 0xa8(%rsp), %r13d
movq 0x98(%rsp), %rax
movq 0x28(%rax), %rax
movq (%rax,%r12,8), %rax
movl %r13d, %ecx
movq %rcx, 0x18(%rsp)
testl %eax, %eax
movq %rdx, 0x20(%rsp)
movq %rdi, 0x10(%rsp)
je 0x15f5fe
movq %rax, %rcx
shrq $0x20, %rcx
leaq (%rcx,%rcx,2), %r15
shlq $0x4, %r15
movq 0x98(%rsp), %rcx
addq 0x10(%rcx), %r15
movl %eax, %eax
shlq $0x4, %rax
leaq (%rax,%rax,2), %rax
movq %rax, 0x28(%rsp)
xorl %ebp, %ebp
movl 0x14(%r15,%rbp), %eax
cmpl %r13d, %eax
je 0x15f5ef
movq (%rdx), %rcx
movq 0x80(%rdx), %rsi
movl (%rcx,%rax,4), %eax
incq %rsi
cmpq %rax, %rsi
jb 0x15f5ef
movq (%r14), %rax
movq 0x18(%rax), %rax
movq 0x20(%rax), %rax
movq 0x18(%rsp), %rcx
movl (%rax,%rcx,8), %eax
movl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
andl %ecx, %eax
movl (%r15,%rbp), %r10d
movl 0x4(%r15,%rbp), %r11d
subq $0x8, %rsp
movq %r14, %rdi
movq 0x40(%rsp), %rsi
movq 0x48(%rsp), %rcx
movq 0x50(%rsp), %r8
movl 0x14(%rsp), %r9d
movq %r15, %rbx
movq %r12, %r15
movq %r13, %r12
movq %r14, %r13
leaq 0x38(%rsp), %r14
pushq %r14
movq %r13, %r14
movq %r12, %r13
movq %r15, %r12
movq %rbx, %r15
pushq %r11
pushq %r10
pushq %r12
pushq %rax
pushq $0x0
pushq %r13
callq 0x165fa6
movq 0x60(%rsp), %rdx
movq 0xe0(%rsp), %rsi
addq $0x40, %rsp
testl %eax, %eax
je 0x15f5ef
movq 0x90(%rsp), %rcx
movsd (%rcx,%r12,8), %xmm0
unpcklps 0xd1e3c(%rip), %xmm0    # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1]
subpd 0xd1e44(%rip), %xmm0    # 0x231290
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
movl 0x4(%r15,%rbp), %eax
subl (%r15,%rbp), %eax
cvtsi2sd %rax, %xmm2
addsd %xmm0, %xmm1
movq (%r14), %rax
movq 0x18(%rax), %rax
movq 0x20(%rax), %rax
movl (%rax,%r12,8), %eax
movl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
andl %edx, %eax
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
movq 0x18(%rsp), %rax
movq (%rcx,%rax,8), %r14
divsd %xmm0, %xmm2
mulsd %xmm1, %xmm2
addsd 0xd2154(%rip), %xmm2    # 0x2315f0
cvttsd2si %xmm2, %rax
movq %rax, %rcx
sarq $0x3f, %rcx
subsd 0xd1e58(%rip), %xmm2    # 0x231308
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 0x15f506
leaq (%rax,%rax), %rcx
testq %rax, %rax
movl $0x2, %eax
cmoveq %rax, %rcx
movq %rcx, 0x8(%rsi)
shlq $0x4, %rcx
leaq (%rcx,%rcx,2), %rsi
movq %rbx, %rdi
callq 0x2370
movq 0xa0(%rsp), %rsi
movq %rax, %rbx
movq %rax, 0x10(%rsi)
movq (%rsi), %rax
leaq 0x1(%rax), %rcx
movq %rcx, (%rsi)
leaq (%rax,%rax,2), %r12
shlq $0x4, %r12
xorpd %xmm0, %xmm0
movupd %xmm0, (%rbx,%r12)
movupd %xmm0, 0x20(%rbx,%r12)
movupd %xmm0, 0x10(%rbx,%r12)
movl 0xa8(%rsp), %eax
movl %eax, 0x8(%rbx,%r12)
movl 0x14(%r15,%rbp), %eax
movl %eax, 0x14(%rbx,%r12)
movsd 0x30(%rsp), %xmm0
movsd %xmm0, 0x20(%rbx,%r12)
cmpq %r13, %r14
cmovbq %r14, %r13
movl %r13d, 0x18(%rbx,%r12)
movq (%rsi), %rcx
movq 0x10(%rsi), %rax
cmpq 0x8(%rsi), %rcx
jne 0x15f59c
leaq (%rcx,%rcx), %rdx
testq %rcx, %rcx
movl $0x2, %ecx
cmoveq %rcx, %rdx
movq %rdx, 0x8(%rsi)
shlq $0x4, %rdx
leaq (%rdx,%rdx,2), %rsi
movq %rax, %rdi
callq 0x2370
movq 0xa0(%rsp), %rsi
movq %rax, 0x10(%rsi)
movq (%rsi), %rcx
movq 0x10(%rsp), %r14
addq %r12, %rbx
leaq 0x1(%rcx), %rdx
movq %rdx, (%rsi)
leaq (%rcx,%rcx,2), %rcx
shlq $0x4, %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 0x20(%rsp), %rdx
movl 0xb0(%rsp), %r12d
movl 0xa8(%rsp), %r13d
addq $0x30, %rbp
cmpq %rbp, 0x28(%rsp)
jne 0x15f382
cmpl %r12d, %r13d
je 0x15f8c1
movq 0x98(%rsp), %rax
movq 0x28(%rax), %rax
movq 0x18(%rsp), %rcx
movq (%rax,%rcx,8), %rax
testl %eax, %eax
je 0x15f8c1
movq %rax, %rcx
shrq $0x20, %rcx
leaq (%rcx,%rcx,2), %r15
shlq $0x4, %r15
movq 0x98(%rsp), %rcx
addq 0x10(%rcx), %r15
movl %eax, %eax
shlq $0x4, %rax
leaq (%rax,%rax,2), %rax
movq %rax, 0x28(%rsp)
xorl %ebp, %ebp
movl $0x7fffffff, %edi       # imm = 0x7FFFFFFF
movq %r15, 0x50(%rsp)
movl 0x14(%r15,%rbp), %eax
cmpl %r12d, %eax
je 0x15f8b2
movq (%rdx), %rcx
movq 0x80(%rdx), %rsi
movl (%rcx,%rax,4), %eax
incq %rsi
cmpq %rax, %rsi
jb 0x15f8b2
movl (%r15,%rbp), %eax
movl 0x4(%r15,%rbp), %r10d
movq (%r14), %rcx
movq 0x18(%rcx), %rcx
movq 0x20(%rcx), %rcx
movl (%rcx,%r12,8), %r11d
andl %edi, %r11d
subq $0x8, %rsp
movq %r14, %rdi
movq 0x40(%rsp), %rsi
movq 0x48(%rsp), %rcx
movq %rdx, %r15
movq 0x50(%rsp), %r8
movl 0x14(%rsp), %r9d
leaq 0x38(%rsp), %rbx
pushq %rbx
pushq %r11
pushq $0x0
pushq %r12
pushq %r10
pushq %rax
pushq %r13
callq 0x165fa6
movl $0x7fffffff, %edi       # imm = 0x7FFFFFFF
movq %r15, %rdx
movq 0x90(%rsp), %r15
movq 0xe0(%rsp), %rsi
addq $0x40, %rsp
testl %eax, %eax
je 0x15f8b2
movq 0x90(%rsp), %rdx
movq 0x18(%rsp), %rcx
movsd (%rdx,%rcx,8), %xmm0
unpcklps 0xd1b73(%rip), %xmm0    # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1]
subpd 0xd1b7b(%rip), %xmm0    # 0x231290
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
addsd %xmm0, %xmm1
movl 0x4(%r15,%rbp), %eax
subl (%r15,%rbp), %eax
xorps %xmm0, %xmm0
cvtsi2sd %rax, %xmm0
movq (%r14), %rax
movq 0x18(%rax), %rax
movq 0x20(%rax), %rax
movl (%rax,%rcx,8), %eax
andl %edi, %eax
cvtsi2sd %eax, %xmm2
divsd %xmm2, %xmm0
mulsd %xmm1, %xmm0
addsd 0xd1e9a(%rip), %xmm0    # 0x2315f0
cvttsd2si %xmm0, %rax
movq %rax, %rcx
sarq $0x3f, %rcx
subsd 0xd1b9e(%rip), %xmm0    # 0x231308
cvttsd2si %xmm0, %r13
andq %rcx, %r13
orq %rax, %r13
movq (%rdx,%r12,8), %r14
cmpq $0x1, %r13
adcq $0x0, %r13
movq (%rsi), %rax
movq 0x10(%rsi), %rbx
cmpq 0x8(%rsi), %rax
jne 0x15f7c4
leaq (%rax,%rax), %rcx
testq %rax, %rax
movl $0x2, %eax
cmoveq %rax, %rcx
movq %rcx, 0x8(%rsi)
shlq $0x4, %rcx
leaq (%rcx,%rcx,2), %rsi
movq %rbx, %rdi
callq 0x2370
movq 0xa0(%rsp), %rsi
movq %rax, %rbx
movq %rax, 0x10(%rsi)
movq (%rsi), %rax
leaq 0x1(%rax), %rcx
movq %rcx, (%rsi)
leaq (%rax,%rax,2), %r12
shlq $0x4, %r12
xorpd %xmm0, %xmm0
movupd %xmm0, (%rbx,%r12)
movupd %xmm0, 0x20(%rbx,%r12)
movupd %xmm0, 0x10(%rbx,%r12)
movl 0xb0(%rsp), %eax
movl %eax, 0x8(%rbx,%r12)
movl 0x14(%r15,%rbp), %eax
movl %eax, 0x14(%rbx,%r12)
movsd 0x30(%rsp), %xmm0
movsd %xmm0, 0x20(%rbx,%r12)
cmpq %r14, %r13
cmovbq %r13, %r14
movl %r14d, 0x18(%rbx,%r12)
movq (%rsi), %rcx
movq 0x10(%rsi), %rax
cmpq 0x8(%rsi), %rcx
jne 0x15f85a
leaq (%rcx,%rcx), %rdx
testq %rcx, %rcx
movl $0x2, %ecx
cmoveq %rcx, %rdx
movq %rdx, 0x8(%rsi)
shlq $0x4, %rdx
leaq (%rdx,%rdx,2), %rsi
movq %rax, %rdi
callq 0x2370
movq 0xa0(%rsp), %rsi
movq %rax, 0x10(%rsi)
movq (%rsi), %rcx
movq 0x10(%rsp), %r14
movl 0xa8(%rsp), %r13d
addq %r12, %rbx
leaq 0x1(%rcx), %rdx
movq %rdx, (%rsi)
leaq (%rcx,%rcx,2), %rcx
shlq $0x4, %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 0x20(%rsp), %rdx
movl 0xb0(%rsp), %r12d
movl $0x7fffffff, %edi       # imm = 0x7FFFFFFF
addq $0x30, %rbp
cmpq %rbp, 0x28(%rsp)
jne 0x15f65a
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq