// File: /workspace/github_cpp_makefile_star2_O3/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, 0x8(%rsp)
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, (%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)
movq (%r12), %rbx
testq %rbx, %rbx
je 0xc6f55
movq %r12, %rbp
movq 0x10(%r12), %rsi
addq $0x10, %rsi
xorl %edi, %edi
xorl %ecx, %ecx
movq %rdi, %rdx
movq %rdi, (%rax,%rcx,8)
movl (%rsi), %edi
addq %rdx, %rdi
incq %rcx
addq $0x28, %rsi
cmpq %rcx, %rbx
jne 0xc6f34
movq %rax, %r15
movq %rdi, 0x18(%r14)
jmp 0xc6f5d
movq %rax, %r15
movq %r12, %rbp
xorl %edi, %edi
movq %rdi, 0x20(%r14)
shlq $0x3, %rdi
callq 0x2280
movq %r14, 0x10(%rsp)
movq %rax, 0x28(%r14)
testq %rbx, %rbx
movq 0x8(%rsp), %rdx
movq (%rsp), %r12
je 0xc6fcb
movq %rbp, %rdi
xorl %r14d, %r14d
movq %rbx, 0x20(%rsp)
movq %r15, 0x18(%rsp)
movq (%r15,%r14,8), %rsi
leaq (%rax,%rsi,8), %r9
movq %rdi, %rbx
movq %r13, %rsi
movq %rdx, %rbp
movq %rax, %r15
movq %r12, %rcx
movq %r14, %r8
callq 0xc6b9a
movq %rbx, %rdi
movq 0x20(%rsp), %rbx
movq %rbp, %rdx
movq %r15, %rax
movq 0x18(%rsp), %r15
incq %r14
cmpq %r14, %rbx
jne 0xc6f91
movq %r12, %rdi
callq 0x2220
leaq 0x1ce77e(%rip), %rax    # 0x295758
movslq 0x144(%rax), %rdx
cvtsi2sd %edx, %xmm1
divsd 0x16ed73(%rip), %xmm1   # 0x235d60
movsd 0x16a313(%rip), %xmm0   # 0x231308
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 0x16a22c(%rip), %xmm1 # xmm1 = xmm1[0],mem[0],xmm1[1],mem[1]
subpd 0x16a234(%rip), %xmm1   # 0x231290
punpckldq %xmm2, %xmm3    # xmm3 = xmm3[0],xmm2[0],xmm3[1],xmm2[1]
movdqa 0x16ec28(%rip), %xmm2   # 0x235c90
pand %xmm4, %xmm2
por 0x16ec0c(%rip), %xmm2   # 0x235c80
psrlq $0x20, %xmm4
por 0x16ec1f(%rip), %xmm4   # 0x235ca0
subpd 0x16ec27(%rip), %xmm4   # 0x235cb0
cvtdq2pd %xmm3, %xmm3
mulpd 0x16ec2b(%rip), %xmm3   # 0x235cc0
addpd %xmm2, %xmm4
addpd 0x16ec2f(%rip), %xmm3   # 0x235cd0
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 0x10(%rsp), %rdx
movdqu %xmm2, 0x30(%rdx)
movq %rcx, 0x40(%rdx)
movq %rax, 0x48(%rdx)
movq %rdx, %rax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq