// File: /workspace/github_cpp_makefile_star2_O3/sergiosvieira[P]ptd2ns2/ptd2ns2.cc
// Function: GetPr(bool, double, double, double, double)
double GetPr(bool use_nakagami_dist_, double dist, double Gt, double Gr,
		double Pt) {
	double d_ref = 1.0;

	// calculate receiving power at reference distance
	double Pr0 = Friis(Pt, Gt, Gr, lambda, L, d_ref);
	// calculate average power loss predicted by empirical loss model in dB
	// according to measurements, 
	// the default settings of gamma, m and d are stored in tcl/lib/ns-default.tcl
	double path_loss_dB = 0.0;

	if (dist > 0 && dist <= d0_gamma) {
		path_loss_dB = 10 * gamma0 * log10(dist / d_ref);
	}
	if (dist > d0_gamma && dist <= d1_gamma) {
		path_loss_dB = 10 * gamma0 * log10(d0_gamma / d_ref) + 10 * gamma1
				* log10(dist / d0_gamma);
	}
	if (dist > d1_gamma) {
		path_loss_dB = 10 * gamma0 * log10(d0_gamma / d_ref) + 10 * gamma1
				* log10(d1_gamma / d0_gamma) + 10 * gamma2 * log10(
				dist / d1_gamma);
	}

	// calculate the receiving power at distance dist
	double Pr = Pr0 * pow(10.0, -path_loss_dB / 10.0);

	if (!use_nakagami_dist_) {
		return Pr;
	} else {
		double m;
		if (dist <= d0_m)
			m = m0;
		else if (dist <= d1_m)
			m = m1;
		else
			m = m2;

		unsigned int int_m = (unsigned int) (floor(m));

		double resultPower;

		if (int_m == m) {
			resultPower = ErlangRandomVariable(Pr / m, int_m).value();
		} else {
			resultPower = GammaRandomVariable(m, Pr / m).value();
		}

		return resultPower;
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %rbx
subq $0x58, %rsp
movapd %xmm0, %xmm4
movl %edi, %ebx
movsd 0x7aa6(%rip), %xmm0     # 0xa200
divsd 0x38a6(%rip), %xmm0     # 0x6008
mulsd %xmm3, %xmm1
mulsd %xmm2, %xmm1
mulsd %xmm0, %xmm0
mulsd %xmm1, %xmm0
divsd 0x7a8e(%rip), %xmm0     # 0xa208
movsd %xmm0, -0x30(%rbp)
xorpd %xmm2, %xmm2
ucomisd %xmm2, %xmm4
movsd 0x7a39(%rip), %xmm0     # 0xa1c8
movsd %xmm4, -0x18(%rbp)
jbe 0x27d0
ucomisd %xmm4, %xmm0
jb 0x27d0
movsd 0x7a0c(%rip), %xmm0     # 0xa1b0
mulsd 0x3864(%rip), %xmm0     # 0x6010
movsd %xmm0, -0x10(%rbp)
movapd %xmm4, %xmm0
callq 0x20c0
movsd -0x18(%rbp), %xmm4
movapd %xmm0, %xmm2
mulsd -0x10(%rbp), %xmm2
movsd 0x79f8(%rip), %xmm0     # 0xa1c8
ucomisd %xmm0, %xmm4
movsd 0x79f4(%rip), %xmm1     # 0xa1d0
jbe 0x2850
ucomisd %xmm4, %xmm1
jb 0x2850
movsd 0x3824(%rip), %xmm2     # 0x6010
movsd %xmm2, -0x10(%rbp)
movsd 0x79b7(%rip), %xmm1     # 0xa1b0
mulsd %xmm2, %xmm1
movsd %xmm1, -0x20(%rbp)
callq 0x20c0
movsd -0x10(%rbp), %xmm1
mulsd 0x79a4(%rip), %xmm1     # 0xa1b8
movsd %xmm1, -0x10(%rbp)
movsd %xmm0, -0x28(%rbp)
movsd -0x18(%rbp), %xmm0
divsd 0x799d(%rip), %xmm0     # 0xa1c8
callq 0x20c0
movsd -0x28(%rbp), %xmm2
movsd -0x18(%rbp), %xmm4
mulsd -0x10(%rbp), %xmm0
mulsd -0x20(%rbp), %xmm2
addsd %xmm0, %xmm2
movsd 0x7980(%rip), %xmm1     # 0xa1d0
ucomisd %xmm1, %xmm4
jbe 0x28fe
movsd 0x37ae(%rip), %xmm0     # 0x6010
movsd %xmm0, -0x10(%rbp)
movsd 0x7941(%rip), %xmm1     # 0xa1b0
mulsd %xmm0, %xmm1
movsd %xmm1, -0x28(%rbp)
movsd 0x7948(%rip), %xmm0     # 0xa1c8
callq 0x20c0
movsd %xmm0, -0x20(%rbp)
movsd 0x7926(%rip), %xmm0     # 0xa1b8
mulsd 0x3776(%rip), %xmm0     # 0x6010
movsd %xmm0, -0x38(%rbp)
movsd 0x7929(%rip), %xmm0     # 0xa1d0
divsd 0x7919(%rip), %xmm0     # 0xa1c8
callq 0x20c0
mulsd -0x38(%rbp), %xmm0
movsd -0x20(%rbp), %xmm2
mulsd -0x28(%rbp), %xmm2
movsd -0x10(%rbp), %xmm1
mulsd 0x78f0(%rip), %xmm1     # 0xa1c0
movsd %xmm1, -0x10(%rbp)
addsd %xmm0, %xmm2
movsd %xmm2, -0x20(%rbp)
movsd -0x18(%rbp), %xmm0
divsd 0x78e5(%rip), %xmm0     # 0xa1d0
callq 0x20c0
movapd %xmm0, %xmm2
mulsd -0x10(%rbp), %xmm2
addsd -0x20(%rbp), %xmm2
divsd 0x3712(%rip), %xmm2     # 0x6018
movsd 0x3702(%rip), %xmm0     # 0x6010
movapd %xmm2, %xmm1
callq 0x22e0
movsd -0x30(%rbp), %xmm1
mulsd %xmm0, %xmm1
movapd %xmm1, %xmm0
testb %bl, %bl
je 0x29c9
movsd %xmm0, -0x30(%rbp)
movsd 0x78b7(%rip), %xmm0     # 0xa1f0
movsd 0x78b7(%rip), %xmm1     # 0xa1f8
movsd -0x18(%rbp), %xmm2
ucomisd %xmm2, %xmm1
leaq 0x7897(%rip), %rax      # 0xa1e8
leaq 0x7888(%rip), %rcx      # 0xa1e0
cmovbq %rax, %rcx
ucomisd %xmm2, %xmm0
leaq 0x7871(%rip), %rax      # 0xa1d8
cmovbq %rcx, %rax
movsd (%rax), %xmm0
movsd %xmm0, -0x18(%rbp)
callq 0x22c0
movsd -0x18(%rbp), %xmm2
cvttsd2si %xmm0, %rsi
movl %esi, %eax
xorps %xmm0, %xmm0
cvtsi2sd %rax, %xmm0
ucomisd %xmm0, %xmm2
movsd -0x30(%rbp), %xmm0
divsd %xmm2, %xmm0
leaq -0x58(%rbp), %rbx
movq %rbx, %rdi
jne 0x29b4
jp 0x29b4
callq 0x3302
movq %rbx, %rdi
callq 0x3328
jmp 0x29c9
movapd %xmm0, %xmm1
movapd %xmm2, %xmm0
callq 0x33ac
movq %rbx, %rdi
callq 0x33d4
addq $0x58, %rsp
popq %rbx
popq %rbp
retq