// File: /workspace/github_c_makefile_star2_O0/lh3[P]fermi2/mag.c
// Function: mag_cal_rdist
double mag_cal_rdist(mag_t *g)
{
	magv_v *v = &g->v;
	int j;
	uint64_t *srt;
	double rdist = -1., t;
	int64_t i, sum_n_all, sum_n, sum_l;

	t = cputime();
	srt = calloc(v->n, 8);
	for (i = 0, sum_n_all = 0; i < v->n; ++i) {
		srt[i] = (uint64_t)v->a[i].nsr<<32 | i;
		sum_n_all += v->a[i].nsr;
	}
	ks_introsort_uint64_t(v->n, srt);

	for (j = 0; j < 2; ++j) {
		sum_n = sum_l = 0;
		for (i = v->n - 1; i >= 0; --i) {
			const magv_t *p = &v->a[srt[i]<<32>>32];
			int tmp1, tmp2;
			tmp1 = tmp2 = 0;
			if (p->nei[0].n) ++tmp1, tmp2 += p->nei[0].a[0].y;
			if (p->nei[1].n) ++tmp1, tmp2 += p->nei[1].a[0].y;
			if (tmp1) tmp2 /= tmp1;
			if (rdist > 0.) {
				double A = (p->len - tmp1) / rdist - p->nsr * M_LN2;
				if (A < A_THRES) continue;
			}
			sum_n += p->nsr;
			sum_l += p->len - tmp1;
			if (sum_n >= sum_n_all * 0.5) break;
		}
		rdist = (double)sum_l / sum_n;
	}
	if (fm_verbose >= 3) {
		fprintf(stderr, "[M::%s] average read distance %.3f, computed in %.3f seconds.\n", __func__, rdist, cputime() - t);
		fprintf(stderr, "[M::%s] approximate genome size: %.0f (inaccurate!)\n", __func__, rdist * sum_n_all);
	}

	free(srt);
	return rdist;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x80, %rsp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x10(%rbp)
movsd 0x120f9(%rip), %xmm0    # 0x2cef8
movsd %xmm0, -0x28(%rbp)
callq 0x4cd0
movsd %xmm0, -0x30(%rbp)
movq -0x10(%rbp), %rax
movq (%rax), %rdi
movl $0x8, %esi
callq 0x21a0
movq %rax, -0x20(%rbp)
movq $0x0, -0x38(%rbp)
movq $0x0, -0x40(%rbp)
movq -0x38(%rbp), %rax
movq -0x10(%rbp), %rcx
cmpq (%rcx), %rax
jae 0x1ae92
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
imulq $0x68, -0x38(%rbp), %rcx
addq %rcx, %rax
movslq 0x4(%rax), %rdx
shlq $0x20, %rdx
orq -0x38(%rbp), %rdx
movq -0x20(%rbp), %rax
movq -0x38(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
imulq $0x68, -0x38(%rbp), %rcx
addq %rcx, %rax
movslq 0x4(%rax), %rax
addq -0x40(%rbp), %rax
movq %rax, -0x40(%rbp)
movq -0x38(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
jmp 0x1ae33
movq -0x10(%rbp), %rax
movq (%rax), %rdi
movq -0x20(%rbp), %rsi
callq 0x189a0
movl $0x0, -0x14(%rbp)
cmpl $0x2, -0x14(%rbp)
jge 0x1b059
movq $0x0, -0x50(%rbp)
movq $0x0, -0x48(%rbp)
movq -0x10(%rbp), %rax
movq (%rax), %rax
subq $0x1, %rax
movq %rax, -0x38(%rbp)
cmpq $0x0, -0x38(%rbp)
jl 0x1b036
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x20(%rbp), %rcx
movq -0x38(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
shlq $0x20, %rcx
shrq $0x20, %rcx
imulq $0x68, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x58(%rbp)
movl $0x0, -0x60(%rbp)
movl $0x0, -0x5c(%rbp)
movq -0x58(%rbp), %rax
cmpq $0x0, 0x20(%rax)
je 0x1af3c
movl -0x5c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x5c(%rbp)
movq -0x58(%rbp), %rax
movq 0x30(%rax), %rax
movq 0x8(%rax), %rcx
movslq -0x60(%rbp), %rax
addq %rcx, %rax
movl %eax, -0x60(%rbp)
movq -0x58(%rbp), %rax
cmpq $0x0, 0x38(%rax)
je 0x1af66
movl -0x5c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x5c(%rbp)
movq -0x58(%rbp), %rax
movq 0x48(%rax), %rax
movq 0x8(%rax), %rcx
movslq -0x60(%rbp), %rax
addq %rcx, %rax
movl %eax, -0x60(%rbp)
cmpl $0x0, -0x5c(%rbp)
je 0x1af78
movl -0x5c(%rbp), %ecx
movl -0x60(%rbp), %eax
cltd
idivl %ecx
movl %eax, -0x60(%rbp)
movsd -0x28(%rbp), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jbe 0x1afe0
movq -0x58(%rbp), %rax
movl (%rax), %eax
subl -0x5c(%rbp), %eax
cvtsi2sd %eax, %xmm1
divsd -0x28(%rbp), %xmm1
movq -0x58(%rbp), %rax
cvtsi2sdl 0x4(%rax), %xmm0
movq %xmm0, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm0
movsd 0x11f48(%rip), %xmm2    # 0x2cf08
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x68(%rbp)
movsd 0x11f2b(%rip), %xmm0    # 0x2cf00
ucomisd -0x68(%rbp), %xmm0
jbe 0x1afde
jmp 0x1b025
jmp 0x1afe0
movq -0x58(%rbp), %rax
movslq 0x4(%rax), %rax
addq -0x48(%rbp), %rax
movq %rax, -0x48(%rbp)
movq -0x58(%rbp), %rax
movl (%rax), %eax
subl -0x5c(%rbp), %eax
cltq
addq -0x50(%rbp), %rax
movq %rax, -0x50(%rbp)
cvtsi2sdq -0x48(%rbp), %xmm0
cvtsi2sdq -0x40(%rbp), %xmm1
movsd 0x113b9(%rip), %xmm2    # 0x2c3d0
mulsd %xmm2, %xmm1
ucomisd %xmm1, %xmm0
jb 0x1b023
jmp 0x1b036
jmp 0x1b025
movq -0x38(%rbp), %rax
addq $-0x1, %rax
movq %rax, -0x38(%rbp)
jmp 0x1aed2
cvtsi2sdq -0x50(%rbp), %xmm0
cvtsi2sdq -0x48(%rbp), %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, -0x28(%rbp)
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0x1aea9
leaq 0x18260(%rip), %rax     # 0x332c0
cmpl $0x3, (%rax)
jl 0x1b0d6
movq 0x17f8c(%rip), %rax     # 0x32ff8
movq (%rax), %rax
movq %rax, -0x78(%rbp)
movsd -0x28(%rbp), %xmm0
movsd %xmm0, -0x70(%rbp)
callq 0x4cd0
movq -0x78(%rbp), %rdi
movaps %xmm0, %xmm1
movsd -0x70(%rbp), %xmm0
subsd -0x30(%rbp), %xmm1
leaq 0x122a1(%rip), %rsi     # 0x2d33b
leaq 0x122d9(%rip), %rdx     # 0x2d37a
movb $0x2, %al
callq 0x21d0
movq 0x17f49(%rip), %rax     # 0x32ff8
movq (%rax), %rdi
movsd -0x28(%rbp), %xmm0
cvtsi2sdq -0x40(%rbp), %xmm1
mulsd %xmm1, %xmm0
leaq 0x122c0(%rip), %rsi     # 0x2d388
leaq 0x122ab(%rip), %rdx     # 0x2d37a
movb $0x1, %al
callq 0x21d0
movq -0x20(%rbp), %rdi
callq 0x2040
movsd -0x28(%rbp), %xmm0
addq $0x80, %rsp
popq %rbp
retq
nopl (%rax)