// File: /workspace/github_cpp_makefile_star2_O2/chhylp123[P]hifiasm/Overlaps.cpp
// Function: gen_ug_rid_cov_t(ma_ug_t*, asg_t*, ma_hit_t_alloc*)
ug_rid_cov_t* gen_ug_rid_cov_t(ma_ug_t *ug, asg_t *rg, ma_hit_t_alloc *src)
{
	uint64_t k; uint8_t *ff; CALLOC(ff, rg->n_seq);
	ug_rid_cov_t *p; CALLOC(p, 1); 
	p->rg = rg; p->ug = ug;
	MALLOC(p->idx, ug->g->n_seq);
	p->cov.n = p->cov.m = 0; p->cov.a = NULL;
	for (k = 0; k < p->ug->u.n; k++) {
		p->idx[k] = p->cov.n; p->cov.n += p->ug->u.a[k].n;
	}
	p->cov.m = p->cov.n; MALLOC(p->cov.a, p->cov.n);
	for (k = 0; k < p->ug->u.n; k++) {
		fill_cov_arr(ug, rg, src, ff, k, p->cov.a+p->idx[k]);
	}
    free(ff);

    uint64_t hom_cov, het_cov, hom_cut; 
    if(asm_opt.hom_global_coverage_set) {
        hom_cov = asm_opt.hom_global_coverage;
    } else {
        hom_cov = ((double)asm_opt.hom_global_coverage)/((double)HOM_PEAK_RATE);
    }
    het_cov = hom_cov/asm_opt.polyploidy;
    hom_cut = hom_cov + (het_cov*(0.5+(((double)asm_opt.polyploidy)*0.05)));
    p->hom_max = hom_cut; 
    p->hom_min = (het_cov*(asm_opt.polyploidy-1)) + (het_cov*(0.5+(((double)(asm_opt.polyploidy-1))*0.05)));
    p->hom_cov = hom_cov; p->het_cov = het_cov;
	return p;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rdx, 0x10(%rsp)
movq %rsi, %r15
movq %rdi, %r12
movl 0x14(%rsi), %edi
movl $0x7fffffff, %r14d      # imm = 0x7FFFFFFF
andq %r14, %rdi
pushq $0x1
popq %rbx
movq %rbx, %rsi
callq 0x2120
movq %rax, (%rsp)
pushq $0x50
popq %rsi
movq %rbx, %rdi
callq 0x2120
movq %rax, %rbx
movq %r15, %r13
movq %r15, 0x8(%rax)
movq %r12, (%rax)
movq 0x18(%r12), %rax
movl 0x14(%rax), %edi
andq %r14, %rdi
shlq $0x3, %rdi
callq 0x2280
movq %rax, %rbp
movq %rax, 0x10(%rbx)
movq (%r12), %r15
pushq $0x2
popq %rax
xorl %edi, %edi
xorl %ecx, %ecx
cmpq %rcx, %r15
je 0x8aa52
movq %rdi, (%rbp,%rcx,8)
movq 0x10(%r12), %rdx
movl (%rdx,%rax,8), %edx
addq %rdx, %rdi
movq %rdi, 0x18(%rbx)
incq %rcx
addq $0x5, %rax
jmp 0x8aa30
movq %rdi, 0x20(%rbx)
shlq $0x3, %rdi
callq 0x2280
movq %rbx, %rcx
movq %rax, %rbx
movq %rcx, 0x8(%rsp)
movq %rax, 0x28(%rcx)
xorl %r14d, %r14d
cmpq %r14, %r15
je 0x8aa9b
movq (%rbp,%r14,8), %rax
leaq (%rbx,%rax,8), %r9
movq %r12, %rdi
movq %r13, %rsi
movq 0x10(%rsp), %rdx
movq (%rsp), %rcx
movq %r14, %r8
callq 0x8a6f0
incq %r14
jmp 0x8aa71
movq (%rsp), %rdi
callq 0x2220
leaq 0x1c8cad(%rip), %rax    # 0x253758
movslq 0x144(%rax), %rdx
cvtsi2sd %edx, %xmm1
divsd 0x15d1a2(%rip), %xmm1   # 0x1e7c60
movsd 0x1587d2(%rip), %xmm0   # 0x1e3298
cvttsd2si %xmm1, %rsi
subsd %xmm0, %xmm1
cvttsd2si %xmm1, %rdi
movq %rsi, %rcx
sarq $0x3f, %rcx
andq %rdi, %rcx
orq %rsi, %rcx
cmpl $0x0, 0x148(%rax)
cmovneq %rdx, %rcx
movslq 0x1bc(%rax), %rsi
movq %rcx, %rax
xorl %edx, %edx
divq %rsi
movd %esi, %xmm2
decq %rsi
movd %esi, %xmm3
imulq %rax, %rsi
movq %rcx, %xmm1
movq %rsi, %xmm4
punpcklqdq %xmm1, %xmm4    # xmm4 = xmm4[0],xmm1[0]
movq %rax, %xmm1
punpckldq 0x15874b(%rip), %xmm1 # xmm1 = xmm1[0],mem[0],xmm1[1],mem[1]
subpd 0x158753(%rip), %xmm1   # 0x1e3280
punpckldq %xmm2, %xmm3    # xmm3 = xmm3[0],xmm2[0],xmm3[1],xmm2[1]
movdqa 0x15d0a7(%rip), %xmm2   # 0x1e7be0
pand %xmm4, %xmm2
por 0x15d08b(%rip), %xmm2   # 0x1e7bd0
psrlq $0x20, %xmm4
por 0x15d09e(%rip), %xmm4   # 0x1e7bf0
subpd 0x15d0a6(%rip), %xmm4   # 0x1e7c00
cvtdq2pd %xmm3, %xmm3
mulpd 0x15d0aa(%rip), %xmm3   # 0x1e7c10
addpd %xmm2, %xmm4
addpd 0x15d0ae(%rip), %xmm3   # 0x1e7c20
movapd %xmm1, %xmm2
unpcklpd %xmm1, %xmm2            # xmm2 = xmm2[0],xmm1[0]
unpckhpd %xmm1, %xmm1            # xmm1 = xmm1[1,1]
addpd %xmm2, %xmm1
mulpd %xmm3, %xmm1
addpd %xmm4, %xmm1
cvttsd2si %xmm1, %rdx
movq %rdx, %rsi
movapd %xmm1, %xmm2
subsd %xmm0, %xmm2
cvttsd2si %xmm2, %rdi
sarq $0x3f, %rsi
andq %rsi, %rdi
orq %rdx, %rdi
movq %rdi, %xmm2
unpckhpd %xmm1, %xmm1            # xmm1 = xmm1[1,1]
cvttsd2si %xmm1, %rdx
movq %rdx, %rsi
sarq $0x3f, %rsi
subsd %xmm0, %xmm1
cvttsd2si %xmm1, %rdi
andq %rsi, %rdi
orq %rdx, %rdi
movq %rdi, %xmm0
punpcklqdq %xmm0, %xmm2    # xmm2 = xmm2[0],xmm0[0]
movq 0x8(%rsp), %rdx
movdqu %xmm2, 0x30(%rdx)
movq %rcx, 0x40(%rdx)
movq %rax, 0x48(%rdx)
movq %rdx, %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq