// File: /workspace/github_cpp_makefile_star2_O1/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
movsd 0x7af8(%rip), %xmm0     # 0xa200
divsd 0x38f8(%rip), %xmm0     # 0x6008
mulsd %xmm3, %xmm1
mulsd %xmm2, %xmm1
mulsd %xmm0, %xmm0
mulsd %xmm1, %xmm0
divsd 0x7ae0(%rip), %xmm0     # 0xa208
movsd %xmm0, -0x30(%rbp)
movl %edi, %ebx
xorpd %xmm2, %xmm2
ucomisd %xmm2, %xmm4
movsd %xmm4, -0x18(%rbp)
jbe 0x2778
movsd 0x7a82(%rip), %xmm0     # 0xa1c8
ucomisd %xmm4, %xmm0
jb 0x2778
movsd 0x7a5c(%rip), %xmm0     # 0xa1b0
mulsd 0x38b4(%rip), %xmm0     # 0x6010
movsd %xmm0, -0x10(%rbp)
movapd %xmm4, %xmm0
callq 0x20c0
movsd -0x18(%rbp), %xmm4
movapd %xmm0, %xmm2
mulsd -0x10(%rbp), %xmm2
movsd 0x7a48(%rip), %xmm0     # 0xa1c8
ucomisd %xmm0, %xmm4
jbe 0x27f8
movsd 0x7a42(%rip), %xmm1     # 0xa1d0
ucomisd %xmm4, %xmm1
jb 0x27f8
movsd 0x3874(%rip), %xmm2     # 0x6010
movsd %xmm2, -0x10(%rbp)
movsd 0x7a07(%rip), %xmm1     # 0xa1b0
mulsd %xmm2, %xmm1
movsd %xmm1, -0x20(%rbp)
callq 0x20c0
movsd -0x10(%rbp), %xmm1
mulsd 0x79f4(%rip), %xmm1     # 0xa1b8
movsd %xmm1, -0x10(%rbp)
movsd %xmm0, -0x28(%rbp)
movsd -0x18(%rbp), %xmm0
divsd 0x79ed(%rip), %xmm0     # 0xa1c8
callq 0x20c0
movsd -0x28(%rbp), %xmm2
movsd -0x18(%rbp), %xmm4
mulsd -0x10(%rbp), %xmm0
mulsd -0x20(%rbp), %xmm2
addsd %xmm0, %xmm2
ucomisd 0x79d0(%rip), %xmm4     # 0xa1d0
jbe 0x28aa
movsd 0x3802(%rip), %xmm0     # 0x6010
movsd %xmm0, -0x10(%rbp)
movsd 0x7995(%rip), %xmm1     # 0xa1b0
mulsd %xmm0, %xmm1
movsd %xmm1, -0x28(%rbp)
movsd 0x799c(%rip), %xmm0     # 0xa1c8
callq 0x20c0
movsd %xmm0, -0x20(%rbp)
movsd 0x797a(%rip), %xmm0     # 0xa1b8
mulsd 0x37ca(%rip), %xmm0     # 0x6010
movsd %xmm0, -0x38(%rbp)
movsd 0x797d(%rip), %xmm0     # 0xa1d0
divsd 0x796d(%rip), %xmm0     # 0xa1c8
callq 0x20c0
mulsd -0x38(%rbp), %xmm0
movsd -0x20(%rbp), %xmm2
mulsd -0x28(%rbp), %xmm2
movsd -0x10(%rbp), %xmm1
mulsd 0x7944(%rip), %xmm1     # 0xa1c0
movsd %xmm1, -0x10(%rbp)
addsd %xmm0, %xmm2
movsd %xmm2, -0x20(%rbp)
movsd -0x18(%rbp), %xmm0
divsd 0x7939(%rip), %xmm0     # 0xa1d0
callq 0x20c0
movapd %xmm0, %xmm2
mulsd -0x10(%rbp), %xmm2
addsd -0x20(%rbp), %xmm2
divsd 0x3766(%rip), %xmm2     # 0x6018
movsd 0x3756(%rip), %xmm0     # 0x6010
movapd %xmm2, %xmm1
callq 0x22e0
movsd -0x30(%rbp), %xmm1
mulsd %xmm0, %xmm1
movapd %xmm1, %xmm0
testb %bl, %bl
je 0x2975
movsd %xmm0, -0x30(%rbp)
movsd 0x790b(%rip), %xmm0     # 0xa1f0
movsd 0x790b(%rip), %xmm1     # 0xa1f8
movsd -0x18(%rbp), %xmm2
ucomisd %xmm2, %xmm1
leaq 0x78eb(%rip), %rax      # 0xa1e8
leaq 0x78dc(%rip), %rcx      # 0xa1e0
cmovbq %rax, %rcx
ucomisd %xmm2, %xmm0
leaq 0x78c5(%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 0x2960
jp 0x2960
callq 0x32ec
movq %rbx, %rdi
callq 0x331c
jmp 0x2975
movapd %xmm0, %xmm1
movapd %xmm2, %xmm0
callq 0x33aa
movq %rbx, %rdi
callq 0x33dc
addq $0x58, %rsp
popq %rbx
popq %rbp
retq