// File: 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
subq $0x100, %rsp            # imm = 0x100
movb %dil, %al
andb $0x1, %al
movb %al, -0x9(%rbp)
movsd %xmm0, -0x18(%rbp)
movsd %xmm1, -0x20(%rbp)
movsd %xmm2, -0x28(%rbp)
movsd %xmm3, -0x30(%rbp)
movsd 0x6811(%rip), %xmm0     # 0xa010
movsd %xmm0, -0x38(%rbp)
movsd -0x30(%rbp), %xmm0
movsd -0x20(%rbp), %xmm1
movsd -0x28(%rbp), %xmm2
movsd 0xba15(%rip), %xmm3     # 0xf230
movsd 0xba15(%rip), %xmm4     # 0xf238
movsd -0x38(%rbp), %xmm5
callq 0x3740
movsd %xmm0, -0x40(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0x48(%rbp)
movsd -0x18(%rbp), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jbe 0x3896
movsd -0x18(%rbp), %xmm1
movsd 0xb9a3(%rip), %xmm0     # 0xf1f8
ucomisd %xmm1, %xmm0
jb 0x3896
movsd 0x67b5(%rip), %xmm0     # 0xa018
mulsd 0xb975(%rip), %xmm0     # 0xf1e0
movsd %xmm0, -0xb0(%rbp)
movsd -0x18(%rbp), %xmm0
divsd -0x38(%rbp), %xmm0
callq 0x30d0
movaps %xmm0, %xmm1
movsd -0xb0(%rbp), %xmm0
mulsd %xmm1, %xmm0
movsd %xmm0, -0x48(%rbp)
movsd -0x18(%rbp), %xmm0
ucomisd 0xb955(%rip), %xmm0     # 0xf1f8
jbe 0x3948
movsd -0x18(%rbp), %xmm1
movsd 0xb94a(%rip), %xmm0     # 0xf200
ucomisd %xmm1, %xmm0
jb 0x3948
movsd 0x6750(%rip), %xmm0     # 0xa018
mulsd 0xb910(%rip), %xmm0     # 0xf1e0
movsd %xmm0, -0xb8(%rbp)
movsd 0xb918(%rip), %xmm0     # 0xf1f8
divsd -0x38(%rbp), %xmm0
callq 0x30d0
movsd %xmm0, -0xc0(%rbp)
movsd 0x671e(%rip), %xmm0     # 0xa018
mulsd 0xb8e6(%rip), %xmm0     # 0xf1e8
movsd %xmm0, -0xc8(%rbp)
movsd -0x18(%rbp), %xmm0
divsd 0xb8e1(%rip), %xmm0     # 0xf1f8
callq 0x30d0
movsd -0xc8(%rbp), %xmm1
movsd -0xc0(%rbp), %xmm2
movaps %xmm0, %xmm3
movsd -0xb8(%rbp), %xmm0
mulsd %xmm3, %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x48(%rbp)
movsd -0x18(%rbp), %xmm0
ucomisd 0xb8ab(%rip), %xmm0     # 0xf200
jbe 0x3a33
movsd 0x66b5(%rip), %xmm0     # 0xa018
mulsd 0xb875(%rip), %xmm0     # 0xf1e0
movsd %xmm0, -0xe0(%rbp)
movsd 0xb87d(%rip), %xmm0     # 0xf1f8
divsd -0x38(%rbp), %xmm0
callq 0x30d0
movsd %xmm0, -0xe8(%rbp)
movsd 0x6683(%rip), %xmm0     # 0xa018
mulsd 0xb84b(%rip), %xmm0     # 0xf1e8
movsd %xmm0, -0xf0(%rbp)
movsd 0xb853(%rip), %xmm0     # 0xf200
divsd 0xb843(%rip), %xmm0     # 0xf1f8
callq 0x30d0
movsd -0xf0(%rbp), %xmm1
movsd -0xe8(%rbp), %xmm2
movaps %xmm0, %xmm3
movsd -0xe0(%rbp), %xmm0
mulsd %xmm3, %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0xd8(%rbp)
movsd 0x6627(%rip), %xmm0     # 0xa018
mulsd 0xb7f7(%rip), %xmm0     # 0xf1f0
movsd %xmm0, -0xd0(%rbp)
movsd -0x18(%rbp), %xmm0
divsd 0xb7f2(%rip), %xmm0     # 0xf200
callq 0x30d0
movsd -0xd8(%rbp), %xmm1
movaps %xmm0, %xmm2
movsd -0xd0(%rbp), %xmm0
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x48(%rbp)
movsd -0x40(%rbp), %xmm0
movsd %xmm0, -0xf8(%rbp)
movsd -0x48(%rbp), %xmm0
movq %xmm0, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm1
movsd 0x65b4(%rip), %xmm0     # 0xa018
divsd %xmm0, %xmm1
movsd 0x65a8(%rip), %xmm0     # 0xa018
callq 0x3330
movaps %xmm0, %xmm1
movsd -0xf8(%rbp), %xmm0
mulsd %xmm1, %xmm0
movsd %xmm0, -0x50(%rbp)
testb $0x1, -0x9(%rbp)
jne 0x3a9e
movsd -0x50(%rbp), %xmm0
movsd %xmm0, -0x8(%rbp)
jmp 0x3b76
movsd -0x18(%rbp), %xmm1
movsd 0xb775(%rip), %xmm0     # 0xf220
ucomisd %xmm1, %xmm0
jb 0x3ac0
movsd 0xb74f(%rip), %xmm0     # 0xf208
movsd %xmm0, -0x58(%rbp)
jmp 0x3af1
movsd -0x18(%rbp), %xmm1
movsd 0xb75b(%rip), %xmm0     # 0xf228
ucomisd %xmm1, %xmm0
jb 0x3ae2
movsd 0xb735(%rip), %xmm0     # 0xf210
movsd %xmm0, -0x58(%rbp)
jmp 0x3aef
movsd 0xb72e(%rip), %xmm0     # 0xf218
movsd %xmm0, -0x58(%rbp)
jmp 0x3af1
movsd -0x58(%rbp), %xmm0
callq 0x3320
cvttsd2si %xmm0, %rax
movl %eax, -0x5c(%rbp)
movl -0x5c(%rbp), %eax
cvtsi2sd %rax, %xmm0
ucomisd -0x58(%rbp), %xmm0
jne 0x3b40
jp 0x3b40
movsd -0x50(%rbp), %xmm0
divsd -0x58(%rbp), %xmm0
movl -0x5c(%rbp), %esi
leaq -0x88(%rbp), %rdi
callq 0x5db0
leaq -0x88(%rbp), %rdi
callq 0x5e00
movsd %xmm0, -0x68(%rbp)
jmp 0x3b6c
movsd -0x58(%rbp), %xmm0
movsd -0x50(%rbp), %xmm1
divsd -0x58(%rbp), %xmm1
leaq -0xa8(%rbp), %rdi
callq 0x5eb0
leaq -0xa8(%rbp), %rdi
callq 0x5f00
movsd %xmm0, -0x68(%rbp)
movsd -0x68(%rbp), %xmm0
movsd %xmm0, -0x8(%rbp)
movsd -0x8(%rbp), %xmm0
addq $0x100, %rsp            # imm = 0x100
popq %rbp
retq
nopw %cs:(%rax,%rax)