// File: chhylp123[P]hifiasm/Overlaps.cpp
// Function: set_r_het_flag(ma_ug_t*, asg_t*, ma_sub_t*, ma_hit_t_alloc*, R_to_U*, unsigned char*)
void set_r_het_flag(ma_ug_t *ug, asg_t *sg, ma_sub_t* coverage_cut, ma_hit_t_alloc* sources, R_to_U* ruIndex, uint8_t* is_r_het)
{
    uint64_t m, dip_thre_max, dip_thres;
    uint8_t* primary_flag = (uint8_t*)calloc(sg->n_seq, sizeof(uint8_t));

    if(asm_opt.hom_global_coverage_set)
    {
        dip_thre_max = asm_opt.hom_global_coverage;
    }
    else
    {
        dip_thre_max = ((double)asm_opt.hom_global_coverage)/((double)HOM_PEAK_RATE);
    }
    // dip_thre_max *= 0.75;
    dip_thre_max = (double)(dip_thre_max) - (((double)(dip_thre_max)*0.5)/asm_opt.polyploidy);

    // fprintf(stderr, "dip_thre_max: %lu\n", dip_thre_max);
            
    for (m = 0; m < ug->g->n_seq; m++)
    {
        dip_thres = dip_thre_max;
        ///if(ug->u.a[m].n <= dip_thre_max) dip_thres = dip_thre_max * 1.1;
        set_ug_coverage_aggressive(ug, m, sg, coverage_cut, sources, ruIndex, primary_flag, is_r_het, dip_thres);
    }
    free(primary_flag); 
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x70, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
movq %r9, -0x30(%rbp)
movq -0x10(%rbp), %rax
movl 0x14(%rax), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movl %eax, %eax
movl %eax, %edi
movl $0x1, %esi
callq 0x2140
movq %rax, -0x50(%rbp)
leaq 0x2c8733(%rip), %rax    # 0x3c47f8
cmpl $0x0, 0x148(%rax)
je 0xfc0e2
leaq 0x2c8723(%rip), %rax    # 0x3c47f8
movslq 0x144(%rax), %rax
movq %rax, -0x40(%rbp)
jmp 0xfc127
leaq 0x2c870f(%rip), %rax    # 0x3c47f8
cvtsi2sdl 0x144(%rax), %xmm0
movsd 0x28a747(%rip), %xmm1   # 0x386840
divsd %xmm1, %xmm0
movaps %xmm0, %xmm1
cvttsd2si %xmm1, %rax
movq %rax, %rdx
sarq $0x3f, %rdx
movsd 0x285ee4(%rip), %xmm1   # 0x381ff8
subsd %xmm1, %xmm0
cvttsd2si %xmm0, %rcx
andq %rdx, %rcx
orq %rcx, %rax
movq %rax, -0x40(%rbp)
movaps 0x285ee2(%rip), %xmm1   # 0x382010
movq -0x40(%rbp), %xmm0
punpckldq %xmm1, %xmm0    # xmm0 = xmm0[0],xmm1[0],xmm0[1],xmm1[1]
movapd 0x285ee1(%rip), %xmm1   # 0x382020
subpd %xmm1, %xmm0
movaps %xmm0, %xmm1
unpckhpd %xmm0, %xmm0            # xmm0 = xmm0[1,1]
addsd %xmm1, %xmm0
movsd 0x28a6fa(%rip), %xmm2   # 0x386850
movaps %xmm0, %xmm1
mulsd %xmm2, %xmm1
leaq 0x2c8694(%rip), %rax    # 0x3c47f8
cvtsi2sdl 0x1bc(%rax), %xmm2
divsd %xmm2, %xmm1
addsd %xmm1, %xmm0
movaps %xmm0, %xmm1
cvttsd2si %xmm1, %rax
movq %rax, %rdx
sarq $0x3f, %rdx
movsd 0x285e6d(%rip), %xmm1   # 0x381ff8
subsd %xmm1, %xmm0
cvttsd2si %xmm0, %rcx
andq %rdx, %rcx
orq %rcx, %rax
movq %rax, -0x40(%rbp)
movq $0x0, -0x38(%rbp)
movq -0x38(%rbp), %rax
movq -0x8(%rbp), %rcx
movq 0x18(%rcx), %rcx
movl 0x14(%rcx), %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
movl %ecx, %ecx
cmpq %rcx, %rax
jae 0xfc211
movq -0x40(%rbp), %rax
movq %rax, -0x48(%rbp)
movq -0x8(%rbp), %rdi
movq -0x38(%rbp), %rax
movl %eax, %esi
movq -0x10(%rbp), %rdx
movq -0x18(%rbp), %rcx
movq -0x20(%rbp), %r8
movq -0x28(%rbp), %r9
movq -0x50(%rbp), %r11
movq -0x30(%rbp), %r10
movq -0x48(%rbp), %rax
movq %r11, (%rsp)
movq %r10, 0x8(%rsp)
movq %rax, 0x10(%rsp)
callq 0xfb8d0
movq -0x38(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
jmp 0xfc1a6
movq -0x50(%rbp), %rdi
callq 0x2210
addq $0x70, %rsp
popq %rbp
retq