// File: chhylp123[P]hifiasm/hic.cpp
// Function: get_unitig_het_arb(ma_ug_t*, unsigned int, unsigned char*, kv_u_trans_t*, unsigned int, unsigned int, unsigned int, unsigned int)
uint32_t get_unitig_het_arb(ma_ug_t* ug, uint32_t uid, uint8_t *r_het_flag, kv_u_trans_t *ref, uint32_t m_het_occ,
uint32_t m_het_label, uint32_t p_het_label, uint32_t n_het_label)
{
    if(ref && ref->idx.n > 0 && u_trans_n(*ref, uid) > 0) return m_het_label;
    ma_utg_t *u = &(ug->u.a[uid]);
    uint32_t k, rId;
    uint32_t het_occ, hom_occ;
    for (k = 0, het_occ = hom_occ = 0; k < u->n; k++)
    {
        rId = u->a[k]>>33;
        if((r_het_flag[rId] & P_HET)) return m_het_label;
        if((r_het_flag[rId] & C_HET) || (r_het_flag[rId] & P_HET))
        {
            het_occ++;
        }
        else
        {
            hom_occ++;
        }
    }

    if((het_occ+hom_occ) == 0) return n_het_label; ///hom
    if((het_occ > ((het_occ+hom_occ)*0.8)) && ((het_occ+hom_occ) > m_het_occ)) return m_het_label; ///must het
    if(het_occ >= hom_occ) return p_het_label; ///potential het
    return n_het_label; ///hom
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
movl 0x18(%rbp), %eax
movl 0x10(%rbp), %eax
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movl %r8d, -0x2c(%rbp)
movl %r9d, -0x30(%rbp)
cmpq $0x0, -0x28(%rbp)
je 0x1c5a92
movq -0x28(%rbp), %rax
cmpq $0x0, 0x18(%rax)
jbe 0x1c5a92
movq -0x28(%rbp), %rax
movq 0x28(%rax), %rax
movl -0x14(%rbp), %ecx
movq (%rax,%rcx,8), %rax
cmpl $0x0, %eax
jbe 0x1c5a92
movl -0x30(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x1c5bab
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x14(%rbp), %ecx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x38(%rbp)
movl $0x0, -0x3c(%rbp)
movl $0x0, -0x48(%rbp)
movl $0x0, -0x44(%rbp)
movl -0x3c(%rbp), %eax
movq -0x38(%rbp), %rcx
cmpl 0x10(%rcx), %eax
jae 0x1c5b47
movq -0x38(%rbp), %rax
movq 0x18(%rax), %rax
movl -0x3c(%rbp), %ecx
movq (%rax,%rcx,8), %rax
shrq $0x21, %rax
movl %eax, -0x40(%rbp)
movq -0x20(%rbp), %rax
movl -0x40(%rbp), %ecx
movzbl (%rax,%rcx), %eax
andl $0x2, %eax
cmpl $0x0, %eax
je 0x1c5afd
movl -0x30(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x1c5bab
movq -0x20(%rbp), %rax
movl -0x40(%rbp), %ecx
movzbl (%rax,%rcx), %eax
andl $0x1, %eax
cmpl $0x0, %eax
jne 0x1c5b23
movq -0x20(%rbp), %rax
movl -0x40(%rbp), %ecx
movzbl (%rax,%rcx), %eax
andl $0x2, %eax
cmpl $0x0, %eax
je 0x1c5b2e
movl -0x44(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x44(%rbp)
jmp 0x1c5b37
movl -0x48(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x48(%rbp)
jmp 0x1c5b39
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0x1c5abd
movl -0x44(%rbp), %eax
addl -0x48(%rbp), %eax
cmpl $0x0, %eax
jne 0x1c5b5a
movl 0x18(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x1c5bab
movl -0x44(%rbp), %eax
movl %eax, %ecx
movl %ecx, %eax
cvtsi2sd %rcx, %xmm0
movl -0x48(%rbp), %ecx
addl %ecx, %eax
cvtsi2sd %rax, %xmm1
movsd 0x1bc6b8(%rip), %xmm2   # 0x382230
mulsd %xmm2, %xmm1
ucomisd %xmm1, %xmm0
jbe 0x1c5b95
movl -0x44(%rbp), %eax
addl -0x48(%rbp), %eax
cmpl -0x2c(%rbp), %eax
jbe 0x1c5b95
movl -0x30(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x1c5bab
movl -0x44(%rbp), %eax
cmpl -0x48(%rbp), %eax
jb 0x1c5ba5
movl 0x10(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x1c5bab
movl 0x18(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
popq %rbp
retq