// File: /workspace/github_cpp_makefile_star2_O1/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 0x2cfd
movq %rsi, %rbx
movl $0x1, %r12d
leaq -0x78(%rbp), %r14
movslq %r12d, %r15
movq (%rbx,%r15,8), %rsi
cmpb $0x2d, (%rsi)
jne 0x2b34
movq %r14, %rdi
leaq -0x38(%rbp), %rdx
callq 0x2d62
movq %r14, %rdi
leaq 0x3636(%rip), %rsi      # 0x6058
callq 0x2090
leaq 0x77e2(%rip), %r13      # 0xa210
testl %eax, %eax
je 0x2aa3
movq %r14, %rdi
leaq 0x3620(%rip), %rsi      # 0x605c
callq 0x2090
leaq 0x77d0(%rip), %r13      # 0xa218
testl %eax, %eax
je 0x2aa3
movq %r14, %rdi
leaq 0x360a(%rip), %rsi      # 0x6060
callq 0x2090
leaq 0x77be(%rip), %r13      # 0xa220
testl %eax, %eax
je 0x2aa3
movl $0x10, %edx
movq 0x755e(%rip), %rdi      # 0x9fd0
leaq 0x35eb(%rip), %rsi      # 0x6064
callq 0x21d0
movq (%rbx,%r15,8), %r15
testq %r15, %r15
je 0x2ab9
movq %r15, %rdi
callq 0x20b0
movq 0x753a(%rip), %rdi      # 0x9fd0
movq %r15, %rsi
movq %rax, %rdx
callq 0x21d0
jmp 0x2ad7
leal 0x1(%r15), %r12d
movq 0x8(%rbx,%r15,8), %rdi
callq 0x2210
movsd %xmm0, (%r13)
jmp 0x2b09
movq 0x7510(%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 0x74f2(%rip), %rcx      # 0x9fd0
movq (%rcx), %rax
movq -0x18(%rax), %rdi
addq %rcx, %rdi
movl $0xa, %esi
callq 0x2170
movsbl %al, %esi
movq 0x74d4(%rip), %rdi      # 0x9fd0
callq 0x2040
movq %rax, %rdi
callq 0x20f0
movq -0x78(%rbp), %rdi
leaq -0x68(%rbp), %rax
cmpq %rax, %rdi
je 0x2b22
movq -0x68(%rbp), %rsi
incq %rsi
callq 0x21b0
leal 0x1(%r12), %eax
cmpl $0x6, %r12d
movl %eax, %r12d
jl 0x29fc
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 0x76a8(%rip), %xmm0     # 0xa218
movsd %xmm0, -0x48(%rbp)
movsd 0x76a3(%rip), %xmm0     # 0xa220
movsd %xmm0, -0x40(%rbp)
movsd 0x7686(%rip), %xmm1     # 0xa210
addsd 0x3496(%rip), %xmm1     # 0x6028
movsd 0x3476(%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 0x26f3
movsd %xmm0, -0x30(%rbp)
movsd 0x76d3(%rip), %xmm0     # 0xa2a0
mulsd 0x7653(%rip), %xmm0     # 0xa228
movsd -0x30(%rbp), %xmm1
ucomisd %xmm0, %xmm1
jb 0x2bfb
movq %r14, %rdi
movq %rbx, %rsi
callq 0x2da0
movsd (%rax), %xmm0
addsd 0x3441(%rip), %xmm0     # 0x6038
movsd %xmm0, (%rax)
movsd -0x30(%rbp), %xmm0
callq 0x20c0
incl %r15d
cmpl $0x2710, %r15d          # imm = 0x2710
jne 0x2b5e
movsd -0x38(%rbp), %xmm0
addsd 0x341e(%rip), %xmm0     # 0x6040
movsd %xmm0, -0x38(%rbp)
movsd 0x33f1(%rip), %xmm1     # 0x6020
ucomisd %xmm0, %xmm1
movl $0x0, %r15d
jae 0x2b5e
movq -0x60(%rbp), %rbx
cmpq %r13, %rbx
je 0x2cf0
movq 0x737d(%rip), %r14      # 0x9fd0
leaq 0x3d46(%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 0x33c1(%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 0x33a3(%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 0x2c5a
leaq -0x78(%rbp), %rdi
callq 0x2e1c
xorl %eax, %eax
jmp 0x2d1a
leaq 0x339b(%rip), %rdi      # 0x609f
callq 0x2270
leaq 0x3404(%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 0x2d5a
movq %rax, %rbx
movq -0x78(%rbp), %rdi
leaq -0x68(%rbp), %rax
cmpq %rax, %rdi
je 0x2d5a
movq -0x68(%rbp), %rsi
incq %rsi
callq 0x21b0
jmp 0x2d5a
jmp 0x2d4e
movq %rax, %rbx
leaq -0x78(%rbp), %rdi
callq 0x2e1c
movq %rbx, %rdi
callq 0x22f0