// File: /workspace/github_cpp_makefile_star2_O2/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 0x6d16(%rip), %xmm0     # 0x9200
divsd 0x2b16(%rip), %xmm0     # 0x5008
mulsd %xmm3, %xmm1
mulsd %xmm2, %xmm1
mulsd %xmm0, %xmm0
mulsd %xmm1, %xmm0
divsd 0x6cfe(%rip), %xmm0     # 0x9208
movsd %xmm0, -0x30(%rbp)
xorpd %xmm2, %xmm2
ucomisd %xmm2, %xmm4
movsd 0x6ca9(%rip), %xmm0     # 0x91c8
movsd %xmm4, -0x18(%rbp)
jbe 0x2560
ucomisd %xmm4, %xmm0
jb 0x2560
movsd 0x6c7c(%rip), %xmm0     # 0x91b0
mulsd 0x2ad4(%rip), %xmm0     # 0x5010
movsd %xmm0, -0x10(%rbp)
movapd %xmm4, %xmm0
callq 0x20e0
movsd -0x18(%rbp), %xmm4
movapd %xmm0, %xmm2
mulsd -0x10(%rbp), %xmm2
movsd 0x6c68(%rip), %xmm0     # 0x91c8
ucomisd %xmm0, %xmm4
movsd 0x6c64(%rip), %xmm1     # 0x91d0
jbe 0x25e0
ucomisd %xmm4, %xmm1
jb 0x25e0
movsd 0x2a94(%rip), %xmm2     # 0x5010
movsd %xmm2, -0x10(%rbp)
movsd 0x6c27(%rip), %xmm1     # 0x91b0
mulsd %xmm2, %xmm1
movsd %xmm1, -0x20(%rbp)
callq 0x20e0
movsd -0x10(%rbp), %xmm1
mulsd 0x6c14(%rip), %xmm1     # 0x91b8
movsd %xmm1, -0x10(%rbp)
movsd %xmm0, -0x28(%rbp)
movsd -0x18(%rbp), %xmm0
divsd 0x6c0d(%rip), %xmm0     # 0x91c8
callq 0x20e0
movsd -0x28(%rbp), %xmm2
movsd -0x18(%rbp), %xmm4
mulsd -0x10(%rbp), %xmm0
mulsd -0x20(%rbp), %xmm2
addsd %xmm0, %xmm2
movsd 0x6bf0(%rip), %xmm1     # 0x91d0
ucomisd %xmm1, %xmm4
jbe 0x268e
movsd 0x2a1e(%rip), %xmm0     # 0x5010
movsd %xmm0, -0x10(%rbp)
movsd 0x6bb1(%rip), %xmm1     # 0x91b0
mulsd %xmm0, %xmm1
movsd %xmm1, -0x28(%rbp)
movsd 0x6bb8(%rip), %xmm0     # 0x91c8
callq 0x20e0
movsd %xmm0, -0x20(%rbp)
movsd 0x6b96(%rip), %xmm0     # 0x91b8
mulsd 0x29e6(%rip), %xmm0     # 0x5010
movsd %xmm0, -0x38(%rbp)
movsd 0x6b99(%rip), %xmm0     # 0x91d0
divsd 0x6b89(%rip), %xmm0     # 0x91c8
callq 0x20e0
mulsd -0x38(%rbp), %xmm0
movsd -0x20(%rbp), %xmm2
mulsd -0x28(%rbp), %xmm2
movsd -0x10(%rbp), %xmm1
mulsd 0x6b60(%rip), %xmm1     # 0x91c0
movsd %xmm1, -0x10(%rbp)
addsd %xmm0, %xmm2
movsd %xmm2, -0x20(%rbp)
movsd -0x18(%rbp), %xmm0
divsd 0x6b55(%rip), %xmm0     # 0x91d0
callq 0x20e0
movapd %xmm0, %xmm2
mulsd -0x10(%rbp), %xmm2
addsd -0x20(%rbp), %xmm2
divsd 0x2982(%rip), %xmm2     # 0x5018
movsd 0x2972(%rip), %xmm0     # 0x5010
movapd %xmm2, %xmm1
callq 0x22e0
movsd -0x30(%rbp), %xmm1
mulsd %xmm0, %xmm1
movapd %xmm1, %xmm0
testb %bl, %bl
je 0x2756
movsd %xmm0, -0x30(%rbp)
movsd 0x6b27(%rip), %xmm0     # 0x91f0
movsd 0x6b27(%rip), %xmm1     # 0x91f8
movsd -0x18(%rbp), %xmm2
ucomisd %xmm2, %xmm1
leaq 0x6b07(%rip), %rax      # 0x91e8
leaq 0x6af8(%rip), %rcx      # 0x91e0
cmovbq %rax, %rcx
ucomisd %xmm2, %xmm0
leaq 0x6ae1(%rip), %rax      # 0x91d8
cmovbq %rcx, %rax
movsd (%rax), %xmm0
movsd %xmm0, -0x18(%rbp)
callq 0x22d0
movsd -0x18(%rbp), %xmm2
cvttsd2si %xmm0, %rsi
movl %esi, %eax
cvtsi2sd %rax, %xmm0
ucomisd %xmm0, %xmm2
movsd -0x30(%rbp), %xmm0
divsd %xmm2, %xmm0
leaq -0x58(%rbp), %rbx
movq %rbx, %rdi
jne 0x2741
jp 0x2741
callq 0x3056
movq %rbx, %rdi
callq 0x307c
jmp 0x2756
movapd %xmm0, %xmm1
movapd %xmm2, %xmm0
callq 0x30f4
movq %rbx, %rdi
callq 0x311c
addq $0x58, %rsp
popq %rbx
popq %rbp
retq