// File: /workspace/github_cpp_makefile_star2_O2/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 0x289a
movq %rsi, %rbx
pushq $0x1
popq %r13
leaq -0x80(%rbp), %r14
cmpl $0x6, %r13d
jg 0x28ba
movslq %r13d, %r12
movq (%rbx,%r12,8), %rsi
cmpb $0x2d, (%rsi)
jne 0x28ba
movq %r14, %rdi
leaq -0x38(%rbp), %rdx
callq 0x2a98
movq %r14, %rdi
leaq 0x284d(%rip), %rsi      # 0x5058
callq 0x2ad3
leaq 0x69f9(%rip), %r15      # 0x9210
testb %al, %al
jne 0x284f
movq %r14, %rdi
leaq 0x2837(%rip), %rsi      # 0x505c
callq 0x2ad3
leaq 0x69e7(%rip), %r15      # 0x9218
testb %al, %al
jne 0x284f
movq %r14, %rdi
leaq 0x2821(%rip), %rsi      # 0x5060
callq 0x2ad3
leaq 0x69d5(%rip), %r15      # 0x9220
testb %al, %al
je 0x2871
incl %r13d
movq 0x8(%rbx,%r12,8), %rdi
callq 0x2220
movsd %xmm0, (%r15)
incl %r13d
movq %r14, %rdi
callq 0x20c0
jmp 0x27db
movq 0x6758(%rip), %rdi      # 0x8fd0
leaq 0x27e5(%rip), %rsi      # 0x5064
callq 0x21a0
movq (%rbx,%r12,8), %rsi
movq %rax, %rdi
callq 0x21a0
movq %rax, %rdi
callq 0x20d0
jmp 0x2861
pushq $0x1
popq %rbx
leaq 0x27fb(%rip), %rdi      # 0x509f
callq 0x2280
leaq 0x2864(%rip), %rdi      # 0x5114
callq 0x2280
jmp 0x2a5e
leaq -0x78(%rbp), %r12
andl $0x0, (%r12)
andq $0x0, 0x8(%r12)
movq %r12, 0x10(%r12)
movq %r12, 0x18(%r12)
andq $0x0, 0x20(%r12)
xorpd %xmm2, %xmm2
pushq $0x1
popq %rbx
leaq -0x80(%rbp), %r14
leaq -0x38(%rbp), %r15
movsd %xmm2, -0x38(%rbp)
movsd 0x272b(%rip), %xmm0     # 0x5020
ucomisd %xmm2, %xmm0
jb 0x29dd
xorpd %xmm1, %xmm1
movsd 0x272d(%rip), %xmm0     # 0x5038
ucomisd %xmm1, %xmm0
movsd -0x38(%rbp), %xmm2
jbe 0x29d0
movsd %xmm1, -0x40(%rbp)
movsd 0x68f1(%rip), %xmm0     # 0x9218
movsd %xmm0, -0x30(%rbp)
movsd 0x68ec(%rip), %xmm0     # 0x9220
movsd %xmm0, -0x50(%rbp)
movsd 0x68cf(%rip), %xmm1     # 0x9210
addsd 0x26df(%rip), %xmm1     # 0x5028
movsd 0x26bf(%rip), %xmm0     # 0x5010
divsd %xmm0, %xmm1
movsd %xmm2, -0x48(%rbp)
callq 0x22e0
movapd %xmm0, %xmm3
movl %ebx, %edi
movsd -0x48(%rbp), %xmm0
movsd -0x30(%rbp), %xmm1
movsd -0x50(%rbp), %xmm2
callq 0x24d3
movsd %xmm0, -0x30(%rbp)
movsd 0x691a(%rip), %xmm0     # 0x92a0
mulsd 0x689a(%rip), %xmm0     # 0x9228
movsd -0x30(%rbp), %xmm1
ucomisd %xmm0, %xmm1
jb 0x29b4
movq %r14, %rdi
movq %r15, %rsi
callq 0x2ae4
movsd (%rax), %xmm0
addsd 0x2698(%rip), %xmm0     # 0x5048
movsd %xmm0, (%rax)
movsd -0x30(%rbp), %xmm0
callq 0x279b
movsd -0x40(%rbp), %xmm1
addsd 0x267d(%rip), %xmm1     # 0x5048
jmp 0x2903
addsd 0x2668(%rip), %xmm2     # 0x5040
jmp 0x28e8
movq -0x68(%rbp), %r15
movq 0x65e8(%rip), %rbx      # 0x8fd0
leaq 0x2fb1(%rip), %r14      # 0x59a0
cmpq %r12, %r15
je 0x2a53
movsd 0x20(%r15), %xmm0
movq %rbx, %rdi
callq 0x22a0
movq %rax, %rdi
movq %r14, %rsi
callq 0x21a0
movsd 0x28(%r15), %xmm0
divsd 0x261d(%rip), %xmm0     # 0x5038
movq %rax, %rdi
callq 0x22a0
movq %rax, %rdi
movq %r14, %rsi
callq 0x21a0
movq %rax, %rdi
movsd 0x2617(%rip), %xmm0     # 0x5050
callq 0x22a0
movq %rax, %rdi
callq 0x20d0
movq %r15, %rdi
callq 0x21f0
movq %rax, %r15
jmp 0x29ef
leaq -0x80(%rbp), %rdi
callq 0x2b48
xorl %ebx, %ebx
movl %ebx, %eax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
leaq -0x80(%rbp), %rdi
callq 0x20c0
jmp 0x2a90
movq %rax, %rbx
jmp 0x2a90
jmp 0x2a84
movq %rax, %rbx
leaq -0x80(%rbp), %rdi
callq 0x2b48
movq %rbx, %rdi
callq 0x22f0