// File: chhylp123[P]hifiasm/rcut.cpp
// Function: init_mc_gg_status(ma_ug_t*, asg_t*, ma_sub_t*, ma_hit_t_alloc*, R_to_U*, unsigned long, unsigned short)
kv_gg_status *init_mc_gg_status(ma_ug_t *ug, asg_t *read_g, ma_sub_t* coverage_cut, 
ma_hit_t_alloc* sources, R_to_U* ruIndex, uint64_t t_cov, uint16_t hapN)
{
	fprintf(stderr, "t_cov-%lu\n", t_cov);
	uint64_t *covs = NULL, i, k, k_i, c = t_cov/hapN, c_min, c_max; 
	uint32_t len[2];
	uint8_t *vis = NULL; CALLOC(vis, read_g->n_seq);
	kv_gg_status *p = NULL; 
	CALLOC(covs, hapN);
	for (i = 0; i < hapN; i++)
	{
		c_min = ((i+1)*c) - (0.6*c);
		c_max = ((i+1)*c) + (0.6*c);
		if(i == 0) c_min = 0;
		if(i == hapN) c_max = (uint32_t)-1;
		covs[i] = (c_max<<32)|c_min; 
	}
	CALLOC(p, 1);
	p->n = p->m = ug->u.n;
	CALLOC(p->a, p->n);
	for (i = 0; i < p->n; i++)
	{
		c = get_utg_cov(ug, i, read_g, coverage_cut, sources, ruIndex, vis);
		p->a[i].h[0] = p->a[i].h[1] = (uint16_t)-1; p->a[i].s = 0; k_i = 0;
		p->a[i].hw[0] = 1; p->a[i].hw[1] = 0; p->a[i].hc = 0;
		for (k = 0; k < hapN; k++)
		{
			c_min = (uint32_t)covs[k]; c_max = covs[k]>>32;
			if(c < c_min || c >= c_max) continue;
			p->a[i].h[k_i++] = k + 1;
		}
		if(p->a[i].h[1] == (uint16_t)-1) continue;
		
		len[0] = (c >= (p->a[i].h[0]*(t_cov/hapN))? 
							c - (p->a[i].h[0]*(t_cov/hapN)) : (p->a[i].h[0]*(t_cov/hapN)) - c);
		len[1] = (c >= (p->a[i].h[1]*(t_cov/hapN))? 
							c - (p->a[i].h[1]*(t_cov/hapN)) : (p->a[i].h[1]*(t_cov/hapN)) - c);
		if(len[0] > len[1])
		{
			k_i = p->a[i].h[0];
			p->a[i].h[0] = p->a[i].h[1];
			p->a[i].h[1] = k_i;

			k_i = len[0];
			len[0] = len[1];
			len[1] = k_i;
		}
		
		p->a[i].hw[0] = (double)len[1]/(double)(len[0]+len[1]);
		p->a[i].hw[1] = (double)len[0]/(double)(len[0]+len[1]);
	}
	free(covs); free(vis);
	return p;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xd0, %rsp
movw 0x10(%rbp), %ax
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 0x19c142(%rip), %rax    # 0x3c3fe0
movq (%rax), %rdi
movq -0x30(%rbp), %rdx
leaq 0x166127(%rip), %rsi    # 0x38dfd3
movb $0x0, %al
callq 0x22a0
movq $0x0, -0x38(%rbp)
movq -0x30(%rbp), %rax
movzwl 0x10(%rbp), %ecx
xorl %edx, %edx
divq %rcx
movq %rax, -0x58(%rbp)
movq $0x0, -0x78(%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, -0x78(%rbp)
movq $0x0, -0x80(%rbp)
movzwl 0x10(%rbp), %eax
movl %eax, %edi
movl $0x8, %esi
callq 0x2140
movq %rax, -0x38(%rbp)
movq $0x0, -0x40(%rbp)
movq -0x40(%rbp), %rax
movzwl 0x10(%rbp), %ecx
cmpq %rcx, %rax
jae 0x22806e
movq -0x40(%rbp), %rcx
incq %rcx
movq -0x58(%rbp), %rax
imulq %rax, %rcx
movq %rcx, %xmm1
movaps 0x15a0ce(%rip), %xmm4   # 0x382010
punpckldq %xmm4, %xmm1    # xmm1 = xmm1[0],xmm4[0],xmm1[1],xmm4[1]
movapd 0x15a0d2(%rip), %xmm3   # 0x382020
subpd %xmm3, %xmm1
movaps %xmm1, %xmm0
unpckhpd %xmm1, %xmm1            # xmm1 = xmm1[1,1]
addsd %xmm0, %xmm1
movq %rax, %xmm0
punpckldq %xmm4, %xmm0    # xmm0 = xmm0[0],xmm4[0],xmm0[1],xmm4[1]
subpd %xmm3, %xmm0
movaps %xmm0, %xmm2
unpckhpd %xmm0, %xmm0            # xmm0 = xmm0[1,1]
addsd %xmm2, %xmm0
movsd 0x16596b(%rip), %xmm2   # 0x38d8e8
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movaps %xmm0, %xmm1
cvttsd2si %xmm1, %rax
movq %rax, %rdx
sarq $0x3f, %rdx
movsd 0x15a05c(%rip), %xmm1   # 0x381ff8
subsd %xmm1, %xmm0
cvttsd2si %xmm0, %rcx
andq %rdx, %rcx
orq %rcx, %rax
movq %rax, -0x60(%rbp)
movq -0x40(%rbp), %rcx
incq %rcx
movq -0x58(%rbp), %rax
imulq %rax, %rcx
movq %rcx, %xmm2
punpckldq %xmm4, %xmm2    # xmm2 = xmm2[0],xmm4[0],xmm2[1],xmm4[1]
subpd %xmm3, %xmm2
movaps %xmm2, %xmm0
unpckhpd %xmm2, %xmm2            # xmm2 = xmm2[1,1]
addsd %xmm0, %xmm2
movq %rax, %xmm0
punpckldq %xmm4, %xmm0    # xmm0 = xmm0[0],xmm4[0],xmm0[1],xmm4[1]
subpd %xmm3, %xmm0
movaps %xmm0, %xmm3
unpckhpd %xmm0, %xmm0            # xmm0 = xmm0[1,1]
addsd %xmm3, %xmm0
movsd 0x15a21a(%rip), %xmm3   # 0x382210
mulsd %xmm3, %xmm0
addsd %xmm2, %xmm0
movaps %xmm0, %xmm2
cvttsd2si %xmm2, %rax
movq %rax, %rdx
sarq $0x3f, %rdx
subsd %xmm1, %xmm0
cvttsd2si %xmm0, %rcx
andq %rdx, %rcx
orq %rcx, %rax
movq %rax, -0x68(%rbp)
cmpq $0x0, -0x40(%rbp)
jne 0x22802f
movq $0x0, -0x60(%rbp)
movq -0x40(%rbp), %rax
movzwl 0x10(%rbp), %ecx
cmpq %rcx, %rax
jne 0x228045
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movq %rax, -0x68(%rbp)
movq -0x68(%rbp), %rdx
shlq $0x20, %rdx
orq -0x60(%rbp), %rdx
movq -0x38(%rbp), %rax
movq -0x40(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movq -0x40(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x40(%rbp)
jmp 0x227f16
movl $0x1, %edi
movl $0x18, %esi
callq 0x2140
movq %rax, -0x80(%rbp)
movq -0x8(%rbp), %rax
movq (%rax), %rcx
movq -0x80(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x80(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x80(%rbp), %rax
movq 0x8(%rax), %rdi
movl $0x20, %esi
callq 0x2140
movq %rax, %rcx
movq -0x80(%rbp), %rax
movq %rcx, (%rax)
movq $0x0, -0x40(%rbp)
movq -0x40(%rbp), %rax
movq -0x80(%rbp), %rcx
cmpq 0x8(%rcx), %rax
jae 0x2284fb
movq -0x8(%rbp), %rdi
movq -0x40(%rbp), %rax
movl %eax, %esi
movq -0x10(%rbp), %rdx
movq -0x18(%rbp), %rcx
movq -0x20(%rbp), %r8
movq -0x28(%rbp), %r9
movq -0x78(%rbp), %rax
movq %rax, (%rsp)
callq 0x110970
movq %rax, -0x58(%rbp)
movq -0x80(%rbp), %rax
movq (%rax), %rax
movq -0x40(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movw $0xffff, 0x6(%rax)      # imm = 0xFFFF
movq -0x80(%rbp), %rax
movq (%rax), %rax
movq -0x40(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movw $0xffff, 0x4(%rax)      # imm = 0xFFFF
movq -0x80(%rbp), %rax
movq (%rax), %rax
movq -0x40(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movl $0x0, (%rax)
movq $0x0, -0x50(%rbp)
movq -0x80(%rbp), %rax
movq (%rax), %rax
movq -0x40(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movsd 0x159e9d(%rip), %xmm0   # 0x382000
movsd %xmm0, 0x10(%rax)
movq -0x80(%rbp), %rax
movq (%rax), %rax
movq -0x40(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
xorps %xmm0, %xmm0
movsd %xmm0, 0x18(%rax)
movq -0x80(%rbp), %rax
movq (%rax), %rax
movq -0x40(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movw $0x0, 0x8(%rax)
movq $0x0, -0x48(%rbp)
movq -0x48(%rbp), %rax
movzwl 0x10(%rbp), %ecx
cmpq %rcx, %rax
jae 0x22822d
movq -0x38(%rbp), %rax
movq -0x48(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movl %eax, %eax
movq %rax, -0x60(%rbp)
movq -0x38(%rbp), %rax
movq -0x48(%rbp), %rcx
movq (%rax,%rcx,8), %rax
shrq $0x20, %rax
movq %rax, -0x68(%rbp)
movq -0x58(%rbp), %rax
cmpq -0x60(%rbp), %rax
jb 0x2281e9
movq -0x58(%rbp), %rax
cmpq -0x68(%rbp), %rax
jb 0x2281eb
jmp 0x22821c
movq -0x48(%rbp), %rax
addq $0x1, %rax
movw %ax, %dx
movq -0x80(%rbp), %rax
movq (%rax), %rax
movq -0x40(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movq -0x50(%rbp), %rcx
movq %rcx, %rsi
addq $0x1, %rsi
movq %rsi, -0x50(%rbp)
movw %dx, 0x4(%rax,%rcx,2)
movq -0x48(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x48(%rbp)
jmp 0x2281a2
movq -0x80(%rbp), %rax
movq (%rax), %rax
movq -0x40(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movzwl 0x6(%rax), %eax
cmpl $0xffff, %eax           # imm = 0xFFFF
jne 0x22824f
jmp 0x2284ea
movq -0x58(%rbp), %rax
movq %rax, -0x88(%rbp)
movq -0x80(%rbp), %rax
movq (%rax), %rax
movq -0x40(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movzwl 0x4(%rax), %eax
movl %eax, %ecx
movq -0x30(%rbp), %rax
movzwl 0x10(%rbp), %edx
movl %edx, %esi
xorl %edx, %edx
divq %rsi
movq %rax, %rdx
movq -0x88(%rbp), %rax
imulq %rdx, %rcx
cmpq %rcx, %rax
jb 0x2282e0
movq -0x58(%rbp), %rax
movq %rax, -0x98(%rbp)
movq -0x80(%rbp), %rax
movq (%rax), %rax
movq -0x40(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movzwl 0x4(%rax), %eax
movl %eax, %ecx
movq -0x30(%rbp), %rax
movzwl 0x10(%rbp), %edx
movl %edx, %esi
xorl %edx, %edx
divq %rsi
movq %rax, %rdx
movq -0x98(%rbp), %rax
imulq %rdx, %rcx
subq %rcx, %rax
movq %rax, -0x90(%rbp)
jmp 0x228323
movq -0x80(%rbp), %rax
movq (%rax), %rax
movq -0x40(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movzwl 0x4(%rax), %eax
movq %rax, -0xa0(%rbp)
movq -0x30(%rbp), %rax
movzwl 0x10(%rbp), %ecx
xorl %edx, %edx
divq %rcx
movq %rax, %rcx
movq -0xa0(%rbp), %rax
imulq %rcx, %rax
subq -0x58(%rbp), %rax
movq %rax, -0x90(%rbp)
movq -0x90(%rbp), %rax
movl %eax, -0x70(%rbp)
movq -0x58(%rbp), %rax
movq %rax, -0xa8(%rbp)
movq -0x80(%rbp), %rax
movq (%rax), %rax
movq -0x40(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movzwl 0x6(%rax), %eax
movl %eax, %ecx
movq -0x30(%rbp), %rax
movzwl 0x10(%rbp), %edx
movl %edx, %esi
xorl %edx, %edx
divq %rsi
movq %rax, %rdx
movq -0xa8(%rbp), %rax
imulq %rdx, %rcx
cmpq %rcx, %rax
jb 0x2283be
movq -0x58(%rbp), %rax
movq %rax, -0xb8(%rbp)
movq -0x80(%rbp), %rax
movq (%rax), %rax
movq -0x40(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movzwl 0x6(%rax), %eax
movl %eax, %ecx
movq -0x30(%rbp), %rax
movzwl 0x10(%rbp), %edx
movl %edx, %esi
xorl %edx, %edx
divq %rsi
movq %rax, %rdx
movq -0xb8(%rbp), %rax
imulq %rdx, %rcx
subq %rcx, %rax
movq %rax, -0xb0(%rbp)
jmp 0x228401
movq -0x80(%rbp), %rax
movq (%rax), %rax
movq -0x40(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movzwl 0x6(%rax), %eax
movq %rax, -0xc0(%rbp)
movq -0x30(%rbp), %rax
movzwl 0x10(%rbp), %ecx
xorl %edx, %edx
divq %rcx
movq %rax, %rcx
movq -0xc0(%rbp), %rax
imulq %rcx, %rax
subq -0x58(%rbp), %rax
movq %rax, -0xb0(%rbp)
movq -0xb0(%rbp), %rax
movl %eax, -0x6c(%rbp)
movl -0x70(%rbp), %eax
cmpl -0x6c(%rbp), %eax
jbe 0x22848a
movq -0x80(%rbp), %rax
movq (%rax), %rax
movq -0x40(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movzwl 0x4(%rax), %eax
movq %rax, -0x50(%rbp)
movq -0x80(%rbp), %rax
movq (%rax), %rax
movq -0x40(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movw 0x6(%rax), %cx
movq -0x80(%rbp), %rax
movq (%rax), %rax
movq -0x40(%rbp), %rdx
shlq $0x5, %rdx
addq %rdx, %rax
movw %cx, 0x4(%rax)
movq -0x50(%rbp), %rax
movw %ax, %cx
movq -0x80(%rbp), %rax
movq (%rax), %rax
movq -0x40(%rbp), %rdx
shlq $0x5, %rdx
addq %rdx, %rax
movw %cx, 0x6(%rax)
movl -0x70(%rbp), %eax
movq %rax, -0x50(%rbp)
movl -0x6c(%rbp), %eax
movl %eax, -0x70(%rbp)
movq -0x50(%rbp), %rax
movl %eax, -0x6c(%rbp)
movl -0x70(%rbp), %eax
movl -0x6c(%rbp), %ecx
movl %ecx, %edx
movl %edx, %ecx
cvtsi2sd %rdx, %xmm0
addl %ecx, %eax
cvtsi2sd %rax, %xmm1
divsd %xmm1, %xmm0
movq -0x80(%rbp), %rax
movq (%rax), %rax
movq -0x40(%rbp), %rcx
shlq $0x5, %rcx
movsd %xmm0, 0x10(%rax,%rcx)
movl -0x70(%rbp), %eax
movl -0x6c(%rbp), %ecx
movl %eax, %edx
movl %edx, %eax
cvtsi2sd %rdx, %xmm0
addl %ecx, %eax
cvtsi2sd %rax, %xmm1
divsd %xmm1, %xmm0
movq -0x80(%rbp), %rax
movq (%rax), %rax
movq -0x40(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movsd %xmm0, 0x18(%rax)
movq -0x40(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x40(%rbp)
jmp 0x2280bc
movq -0x38(%rbp), %rdi
callq 0x2210
movq -0x78(%rbp), %rdi
callq 0x2210
movq -0x80(%rbp), %rax
addq $0xd0, %rsp
popq %rbp
retq
nopw (%rax,%rax)