// File: 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
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%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, -0x28(%rbp)
movl $0x1, %edi
movl $0x50, %esi
callq 0x2140
movq %rax, -0x30(%rbp)
movq -0x10(%rbp), %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x8(%rbp), %rcx
movq -0x30(%rbp), %rax
movq %rcx, (%rax)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rax
movl 0x14(%rax), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movl %eax, %eax
movl %eax, %edi
shlq $0x3, %rdi
callq 0x2270
movq %rax, %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x30(%rbp), %rax
movq $0x0, 0x20(%rax)
movq -0x30(%rbp), %rax
movq $0x0, 0x18(%rax)
movq -0x30(%rbp), %rax
movq $0x0, 0x28(%rax)
movq $0x0, -0x20(%rbp)
movq -0x20(%rbp), %rax
movq -0x30(%rbp), %rcx
movq (%rcx), %rcx
cmpq (%rcx), %rax
jae 0x10809a
movq -0x30(%rbp), %rax
movq 0x18(%rax), %rdx
movq -0x30(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x20(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movq -0x30(%rbp), %rax
movq (%rax), %rax
movq 0x10(%rax), %rax
imulq $0x28, -0x20(%rbp), %rcx
addq %rcx, %rax
movl 0x10(%rax), %eax
movl %eax, %ecx
movq -0x30(%rbp), %rax
addq 0x18(%rax), %rcx
movq %rcx, 0x18(%rax)
movq -0x20(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x20(%rbp)
jmp 0x108040
movq -0x30(%rbp), %rax
movq 0x18(%rax), %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x20(%rax)
movq -0x30(%rbp), %rax
movq 0x18(%rax), %rdi
shlq $0x3, %rdi
callq 0x2270
movq %rax, %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x28(%rax)
movq $0x0, -0x20(%rbp)
movq -0x20(%rbp), %rax
movq -0x30(%rbp), %rcx
movq (%rcx), %rcx
cmpq (%rcx), %rax
jae 0x108124
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdx
movq -0x28(%rbp), %rcx
movq -0x20(%rbp), %r8
movq -0x30(%rbp), %rax
movq 0x28(%rax), %r9
movq -0x30(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x20(%rbp), %r10
movq (%rax,%r10,8), %rax
shlq $0x3, %rax
addq %rax, %r9
callq 0x107b50
movq -0x20(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x20(%rbp)
jmp 0x1080ce
movq -0x28(%rbp), %rdi
callq 0x2210
leaq 0x2bc6c4(%rip), %rax    # 0x3c47f8
cmpl $0x0, 0x148(%rax)
je 0x108151
leaq 0x2bc6b4(%rip), %rax    # 0x3c47f8
movslq 0x144(%rax), %rax
movq %rax, -0x38(%rbp)
jmp 0x108196
leaq 0x2bc6a0(%rip), %rax    # 0x3c47f8
cvtsi2sdl 0x144(%rax), %xmm0
movsd 0x27e6d8(%rip), %xmm1   # 0x386840
divsd %xmm1, %xmm0
movaps %xmm0, %xmm1
cvttsd2si %xmm1, %rax
movq %rax, %rdx
sarq $0x3f, %rdx
movsd 0x279e75(%rip), %xmm1   # 0x381ff8
subsd %xmm1, %xmm0
cvttsd2si %xmm0, %rcx
andq %rdx, %rcx
orq %rcx, %rax
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rax
leaq 0x2bc657(%rip), %rcx    # 0x3c47f8
movq %rcx, -0x50(%rbp)
movslq 0x1bc(%rcx), %rcx
xorl %edx, %edx
divq %rcx
movq %rax, %rcx
movq -0x50(%rbp), %rax
movq %rcx, -0x40(%rbp)
movq -0x38(%rbp), %xmm1
movaps 0x279e48(%rip), %xmm6   # 0x382010
punpckldq %xmm6, %xmm1    # xmm1 = xmm1[0],xmm6[0],xmm1[1],xmm6[1]
movapd 0x279e4c(%rip), %xmm3   # 0x382020
subpd %xmm3, %xmm1
movaps %xmm1, %xmm0
unpckhpd %xmm1, %xmm1            # xmm1 = xmm1[1,1]
addsd %xmm0, %xmm1
movq -0x40(%rbp), %xmm0
punpckldq %xmm6, %xmm0    # xmm0 = xmm0[0],xmm6[0],xmm0[1],xmm6[1]
subpd %xmm3, %xmm0
movaps %xmm0, %xmm2
unpckhpd %xmm0, %xmm0            # xmm0 = xmm0[1,1]
addsd %xmm2, %xmm0
cvtsi2sdl 0x1bc(%rax), %xmm2
movsd 0x27a035(%rip), %xmm5   # 0x382240
mulsd %xmm5, %xmm2
movsd 0x27a059(%rip), %xmm4   # 0x382270
addsd %xmm4, %xmm2
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movaps %xmm0, %xmm1
cvttsd2si %xmm1, %rcx
movq %rcx, %rsi
sarq $0x3f, %rsi
movsd 0x279dbe(%rip), %xmm1   # 0x381ff8
subsd %xmm1, %xmm0
cvttsd2si %xmm0, %rdx
andq %rsi, %rdx
orq %rdx, %rcx
movq %rcx, -0x48(%rbp)
movq -0x48(%rbp), %rdx
movq -0x30(%rbp), %rcx
movq %rdx, 0x38(%rcx)
movq -0x40(%rbp), %rcx
movl 0x1bc(%rax), %eax
decl %eax
movslq %eax, %rsi
movq %rcx, %rdx
imulq %rsi, %rdx
movq %rdx, %xmm2
punpckldq %xmm6, %xmm2    # xmm2 = xmm2[0],xmm6[0],xmm2[1],xmm6[1]
subpd %xmm3, %xmm2
movaps %xmm2, %xmm0
unpckhpd %xmm2, %xmm2            # xmm2 = xmm2[1,1]
addsd %xmm0, %xmm2
movq %rcx, %xmm0
punpckldq %xmm6, %xmm0    # xmm0 = xmm0[0],xmm6[0],xmm0[1],xmm6[1]
subpd %xmm3, %xmm0
movaps %xmm0, %xmm3
unpckhpd %xmm0, %xmm0            # xmm0 = xmm0[1,1]
addsd %xmm3, %xmm0
cvtsi2sd %eax, %xmm3
mulsd %xmm5, %xmm3
addsd %xmm4, %xmm3
mulsd %xmm3, %xmm0
addsd %xmm2, %xmm0
movaps %xmm0, %xmm2
cvttsd2si %xmm2, %rcx
movq %rcx, %rdx
sarq $0x3f, %rdx
subsd %xmm1, %xmm0
cvttsd2si %xmm0, %rax
andq %rdx, %rax
orq %rax, %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x30(%rax)
movq -0x38(%rbp), %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x40(%rax)
movq -0x40(%rbp), %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x48(%rax)
movq -0x30(%rbp), %rax
addq $0x50, %rsp
popq %rbp
retq
nopl (%rax,%rax)