// File: /workspace/github_cpp_makefile_star2_O1/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 $0x28, %rsp
movq %rdx, %r15
movq %rsi, %r13
movq %rdi, %r12
movl 0x14(%rsi), %edi
movl $0x7fffffff, %ebx       # imm = 0x7FFFFFFF
andq %rbx, %rdi
movl $0x1, %esi
callq 0x2120
movq %rax, 0x10(%rsp)
movl $0x1, %edi
movl $0x50, %esi
callq 0x2120
movq %rax, %r14
movq %r13, 0x8(%rax)
movq %r12, (%rax)
movq 0x18(%r12), %rax
movl 0x14(%rax), %edi
andq %rbx, %rdi
shlq $0x3, %rdi
callq 0x2280
movq %rax, 0x10(%r14)
xorps %xmm0, %xmm0
movups %xmm0, 0x18(%r14)
movq $0x0, 0x28(%r14)
movq (%r12), %r9
testq %r9, %r9
je 0xc61b8
movq %r14, %rcx
addq $0x18, %rcx
movq 0x10(%r12), %rdx
movq (%rcx), %rsi
addq $0x10, %rdx
xorl %edi, %edi
movq %rsi, %r8
movq %rsi, (%rax,%rdi,8)
movl (%rdx), %esi
addq %r8, %rsi
incq %rdi
addq $0x28, %rdx
cmpq %rdi, %r9
jne 0xc619d
movq %rsi, (%rcx)
movq 0x18(%r14), %rdi
movq %rdi, 0x20(%r14)
shlq $0x3, %rdi
movq %r12, 0x8(%rsp)
movq %rax, 0x20(%rsp)
callq 0x2280
movq 0x8(%rsp), %rdi
movq %r14, 0x18(%rsp)
movq %rax, 0x28(%r14)
movq %r13, %r12
movq %r15, %r13
movq (%rdi), %r15
testq %r15, %r15
movq 0x10(%rsp), %rbp
je 0xc6225
movq %rax, %rbx
xorl %r14d, %r14d
movq 0x20(%rsp), %rax
movq (%rax,%r14,8), %rax
leaq (%rbx,%rax,8), %r9
movq %r12, %rsi
movq %r13, %rdx
movq %rbp, %rcx
movq %r14, %r8
callq 0xc5df7
movq 0x8(%rsp), %rdi
incq %r14
cmpq %r14, %r15
jne 0xc61fa
movq %rbp, %rdi
callq 0x2220
leaq 0x1c4524(%rip), %rax    # 0x28a758
movslq 0x144(%rax), %rdx
cvtsi2sd %edx, %xmm1
divsd 0x163921(%rip), %xmm1   # 0x229b68
movsd 0x15f019(%rip), %xmm0   # 0x225268
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
movq %rcx, %xmm3
movq 0x15efaf(%rip), %xmm1   # 0x225240
punpckldq %xmm1, %xmm3    # xmm3 = xmm3[0],xmm1[0],xmm3[1],xmm1[1]
movapd 0x15efb3(%rip), %xmm2   # 0x225250
subpd %xmm2, %xmm3
movapd %xmm3, %xmm6
unpckhpd %xmm3, %xmm6            # xmm6 = xmm6[1],xmm3[1]
addsd %xmm3, %xmm6
movq %rax, %xmm4
punpckldq %xmm1, %xmm4    # xmm4 = xmm4[0],xmm1[0],xmm4[1],xmm1[1]
subpd %xmm2, %xmm4
movapd %xmm4, %xmm3
unpckhpd %xmm4, %xmm3            # xmm3 = xmm3[1],xmm4[1]
addsd %xmm4, %xmm3
cvtsi2sd %esi, %xmm7
movsd 0x15f1f6(%rip), %xmm4   # 0x2254c8
mulsd %xmm4, %xmm7
movsd 0x15f212(%rip), %xmm5   # 0x2254f0
addsd %xmm5, %xmm7
mulsd %xmm3, %xmm7
addsd %xmm6, %xmm7
cvttsd2si %xmm7, %rdi
movq %rdi, %r8
subsd %xmm0, %xmm7
cvttsd2si %xmm7, %rdx
sarq $0x3f, %r8
andq %r8, %rdx
orq %rdi, %rdx
decq %rsi
xorps %xmm6, %xmm6
cvtsi2sd %esi, %xmm6
imulq %rax, %rsi
movq %rsi, %xmm7
punpckldq %xmm1, %xmm7    # xmm7 = xmm7[0],xmm1[0],xmm7[1],xmm1[1]
subpd %xmm2, %xmm7
movapd %xmm7, %xmm1
unpckhpd %xmm7, %xmm1            # xmm1 = xmm1[1],xmm7[1]
addsd %xmm7, %xmm1
mulsd %xmm4, %xmm6
addsd %xmm5, %xmm6
mulsd %xmm3, %xmm6
addsd %xmm1, %xmm6
cvttsd2si %xmm6, %rsi
movq 0x18(%rsp), %r8
movq %rdx, 0x38(%r8)
movq %rsi, %rdx
sarq $0x3f, %rdx
subsd %xmm0, %xmm6
cvttsd2si %xmm6, %rdi
andq %rdx, %rdi
orq %rsi, %rdi
movq %rdi, 0x30(%r8)
movq %rcx, 0x40(%r8)
movq %rax, 0x48(%r8)
movq %r8, %rax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq