// File: /workspace/github_cpp_makefile_star2_O3/sergiosvieira[P]ptd2ns2/ptd2ns2.cc
// Function: main
int main(int argc, char** argv) {

	if (argc != 7) {
		printf(
				"USAGE: it generates reception probability for certain transmit power, transmit antenna gain and receive antenna gain\n");
		printf(
				"SYNOPSIS: ptd2ns2 -Pt <transmit-power> -Gt <transmit-antenna-gain> -Gr <receive-antenna-gain>\n");
		return 1;
	}

	int optind = 1;
	// decode arguments
	while ((optind < argc) && (argv[optind][0] == '-')) {
		string sw = argv[optind];
		if (sw == "-Pt") {
			optind++;
			Pt = atof(argv[optind]);
		} else if (sw == "-Gt") {
			optind++;
			Gt = atof(argv[optind]);
		} else if (sw == "-Gr") {
			optind++;
			Gr = atof(argv[optind]);
		} else {
			cout << "Unknown switch: " << argv[optind] << endl;
		}
		optind++;
	}

	typedef std::map<double, unsigned int> rxPowerMapType;
	typedef std::map<double, double> p_reception_type;

	double step = 100.0;
	double total = 10000.0;
	double max = 1000.0;

	p_reception_type p_reception;

	for (double distance = 0.0; distance <= max; distance += step) {

		for (double i = 0; i < total; i++) {

			double Pr_ = GetPr(true, distance, Gt, Gr, DBmtoW(Pt));

			if (Pr_ >= m_ratio * noise_floor) {
				p_reception[distance]++;
			}

			double round = dround(WtoDBm(Pr_), 1.0);

			//printf("Pt(DBm): %.6f Pr(W): %.6f Round(Pr(DBm)):%f\n", Pt, DBmtoW(Pt), round);
		}
	}

	for (p_reception_type::const_iterator i = p_reception.begin(); i
			!= p_reception.end(); ++i) {
		std::cout << (double) i->first << " " << (double) i->second / total
				<< " " << 0.05 << std::endl;
	}

	return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
cmpl $0x7, %edi
jne 0x2d51
movq %rsi, %rbx
movl $0x1, %r12d
leaq -0x78(%rbp), %r14
movslq %r12d, %r15
movq (%rbx,%r15,8), %rsi
cmpb $0x2d, (%rsi)
jne 0x2b88
movq %r14, %rdi
leaq -0x38(%rbp), %rdx
callq 0x2db6
movq %r14, %rdi
leaq 0x35e2(%rip), %rsi      # 0x6058
callq 0x2090
leaq 0x778e(%rip), %r13      # 0xa210
testl %eax, %eax
je 0x2af7
movq %r14, %rdi
leaq 0x35cc(%rip), %rsi      # 0x605c
callq 0x2090
leaq 0x777c(%rip), %r13      # 0xa218
testl %eax, %eax
je 0x2af7
movq %r14, %rdi
leaq 0x35b6(%rip), %rsi      # 0x6060
callq 0x2090
leaq 0x776a(%rip), %r13      # 0xa220
testl %eax, %eax
je 0x2af7
movl $0x10, %edx
movq 0x750a(%rip), %rdi      # 0x9fd0
leaq 0x3597(%rip), %rsi      # 0x6064
callq 0x21d0
movq (%rbx,%r15,8), %r15
testq %r15, %r15
je 0x2b0d
movq %r15, %rdi
callq 0x20b0
movq 0x74e6(%rip), %rdi      # 0x9fd0
movq %r15, %rsi
movq %rax, %rdx
callq 0x21d0
jmp 0x2b2b
leal 0x1(%r15), %r12d
movq 0x8(%rbx,%r15,8), %rdi
callq 0x2210
movsd %xmm0, (%r13)
jmp 0x2b5d
movq 0x74bc(%rip), %rcx      # 0x9fd0
movq (%rcx), %rax
movq -0x18(%rax), %rax
leaq (%rcx,%rax), %rdi
movl 0x20(%rcx,%rax), %esi
orl $0x1, %esi
callq 0x22d0
movq 0x749e(%rip), %rcx      # 0x9fd0
movq (%rcx), %rax
movq -0x18(%rax), %rdi
addq %rcx, %rdi
movl $0xa, %esi
callq 0x2170
movsbl %al, %esi
movq 0x7480(%rip), %rdi      # 0x9fd0
callq 0x2040
movq %rax, %rdi
callq 0x20f0
movq -0x78(%rbp), %rdi
leaq -0x68(%rbp), %rax
cmpq %rax, %rdi
je 0x2b76
movq -0x68(%rbp), %rsi
incq %rsi
callq 0x21b0
leal 0x1(%r12), %eax
cmpl $0x6, %r12d
movl %eax, %r12d
jl 0x2a50
leaq -0x70(%rbp), %r13
movl $0x0, (%r13)
xorl %r15d, %r15d
movq %r15, 0x8(%r13)
movq %r13, 0x10(%r13)
movq %r13, 0x18(%r13)
movq %r15, 0x20(%r13)
leaq -0x38(%rbp), %rbx
movq %r15, (%rbx)
leaq -0x78(%rbp), %r14
movsd -0x38(%rbp), %xmm0
movsd %xmm0, -0x30(%rbp)
movsd 0x7654(%rip), %xmm0     # 0xa218
movsd %xmm0, -0x48(%rbp)
movsd 0x764f(%rip), %xmm0     # 0xa220
movsd %xmm0, -0x40(%rbp)
movsd 0x7632(%rip), %xmm1     # 0xa210
addsd 0x3442(%rip), %xmm1     # 0x6028
movsd 0x3422(%rip), %xmm0     # 0x6010
divsd %xmm0, %xmm1
callq 0x22e0
movapd %xmm0, %xmm3
movl $0x1, %edi
movsd -0x30(%rbp), %xmm0
movsd -0x48(%rbp), %xmm1
movsd -0x40(%rbp), %xmm2
callq 0x2743
movsd %xmm0, -0x30(%rbp)
movsd 0x767f(%rip), %xmm0     # 0xa2a0
mulsd 0x75ff(%rip), %xmm0     # 0xa228
movsd -0x30(%rbp), %xmm1
ucomisd %xmm0, %xmm1
jb 0x2c4f
movq %r14, %rdi
movq %rbx, %rsi
callq 0x2df4
movsd (%rax), %xmm0
addsd 0x33ed(%rip), %xmm0     # 0x6038
movsd %xmm0, (%rax)
movsd -0x30(%rbp), %xmm0
callq 0x20c0
incl %r15d
cmpl $0x2710, %r15d          # imm = 0x2710
jne 0x2bb2
movsd -0x38(%rbp), %xmm0
addsd 0x33ca(%rip), %xmm0     # 0x6040
movsd %xmm0, -0x38(%rbp)
movsd 0x339d(%rip), %xmm1     # 0x6020
ucomisd %xmm0, %xmm1
movl $0x0, %r15d
jae 0x2bb2
movq -0x60(%rbp), %rbx
cmpq %r13, %rbx
je 0x2d44
movq 0x7329(%rip), %r14      # 0x9fd0
leaq 0x3cf2(%rip), %r15      # 0x69a0
movsd 0x20(%rbx), %xmm0
movq %r14, %rdi
callq 0x2290
movq %rax, %r12
movl $0x1, %edx
movq %rax, %rdi
movq %r15, %rsi
callq 0x21d0
movsd 0x28(%rbx), %xmm0
divsd 0x336d(%rip), %xmm0     # 0x6048
movq %r12, %rdi
callq 0x2290
movq %rax, %r12
movl $0x1, %edx
movq %rax, %rdi
movq %r15, %rsi
callq 0x21d0
movq %r12, %rdi
movsd 0x334f(%rip), %xmm0     # 0x6050
callq 0x2290
movq %rax, %r12
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r12, %rdi
movl $0xa, %esi
callq 0x2170
movsbl %al, %esi
movq %r12, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x20f0
movq %rbx, %rdi
callq 0x21e0
movq %rax, %rbx
cmpq %r13, %rax
jne 0x2cae
leaq -0x78(%rbp), %rdi
callq 0x2e72
xorl %eax, %eax
jmp 0x2d6e
leaq 0x3347(%rip), %rdi      # 0x609f
callq 0x2270
leaq 0x33b0(%rip), %rdi      # 0x6114
callq 0x2270
movl $0x1, %eax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
jmp 0x2dae
movq %rax, %rbx
movq -0x78(%rbp), %rdi
leaq -0x68(%rbp), %rax
cmpq %rax, %rdi
je 0x2dae
movq -0x68(%rbp), %rsi
incq %rsi
callq 0x21b0
jmp 0x2dae
jmp 0x2da2
movq %rax, %rbx
leaq -0x78(%rbp), %rdi
callq 0x2e72
movq %rbx, %rdi
callq 0x22f0