// File: 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
subq $0x160, %rsp            # imm = 0x160
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
cmpl $0x7, -0x8(%rbp)
je 0x3c97
leaq 0x63da(%rip), %rdi      # 0xa050
movb $0x0, %al
callq 0x3040
leaq 0x6442(%rip), %rdi      # 0xa0c6
movb $0x0, %al
callq 0x3040
movl $0x1, -0x4(%rbp)
jmp 0x41ba
movl $0x1, -0x14(%rbp)
movl -0x14(%rbp), %ecx
xorl %eax, %eax
cmpl -0x8(%rbp), %ecx
movb %al, -0xd9(%rbp)
jge 0x3cc9
movq -0x10(%rbp), %rax
movslq -0x14(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movsbl (%rax), %eax
cmpl $0x2d, %eax
sete %al
movb %al, -0xd9(%rbp)
movb -0xd9(%rbp), %al
testb $0x1, %al
jne 0x3cd8
jmp 0x3e9e
movq -0x10(%rbp), %rax
movslq -0x14(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0xf0(%rbp)
leaq -0x39(%rbp), %rdi
movq %rdi, -0xe8(%rbp)
callq 0x3350
movq -0xf0(%rbp), %rsi
movq -0xe8(%rbp), %rdx
leaq -0x38(%rbp), %rdi
callq 0x4260
jmp 0x3d14
leaq -0x39(%rbp), %rdi
callq 0x3240
leaq 0x6401(%rip), %rsi      # 0xa125
leaq -0x38(%rbp), %rdi
callq 0x4310
movb %al, -0xf1(%rbp)
jmp 0x3d35
movb -0xf1(%rbp), %al
testb $0x1, %al
jne 0x3d41
jmp 0x3d9c
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
movq -0x10(%rbp), %rax
movslq -0x14(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
callq 0x32b0
movsd %xmm0, 0xb4dd(%rip)     # 0xf240
jmp 0x3e87
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x39(%rbp), %rdi
callq 0x3240
jmp 0x41c6
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x38(%rbp), %rdi
callq 0x3110
jmp 0x41c6
leaq 0x6386(%rip), %rsi      # 0xa129
leaq -0x38(%rbp), %rdi
callq 0x4310
movb %al, -0xf2(%rbp)
jmp 0x3db4
movb -0xf2(%rbp), %al
testb $0x1, %al
jne 0x3dc0
jmp 0x3de7
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
movq -0x10(%rbp), %rax
movslq -0x14(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
callq 0x32b0
movsd %xmm0, 0xb466(%rip)     # 0xf248
jmp 0x3e85
leaq 0x633f(%rip), %rsi      # 0xa12d
leaq -0x38(%rbp), %rdi
callq 0x4310
movb %al, -0xf3(%rbp)
jmp 0x3dff
movb -0xf3(%rbp), %al
testb $0x1, %al
jne 0x3e0b
jmp 0x3e2f
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
movq -0x10(%rbp), %rax
movslq -0x14(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
callq 0x32b0
movsd %xmm0, 0xb423(%rip)     # 0xf250
jmp 0x3e83
movq 0xb19a(%rip), %rdi      # 0xefd0
leaq 0x62f4(%rip), %rsi      # 0xa131
callq 0x31d0
movq %rax, -0x100(%rbp)
jmp 0x3e4b
movq -0x100(%rbp), %rdi
movq -0x10(%rbp), %rax
movslq -0x14(%rbp), %rcx
movq (%rax,%rcx,8), %rsi
callq 0x31d0
movq %rax, -0x108(%rbp)
jmp 0x3e6c
movq -0x108(%rbp), %rdi
movq 0xb146(%rip), %rsi      # 0xefc0
callq 0x3220
jmp 0x3e81
jmp 0x3e83
jmp 0x3e85
jmp 0x3e87
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
leaq -0x38(%rbp), %rdi
callq 0x3110
jmp 0x3c9e
movsd 0x6192(%rip), %xmm0     # 0xa038
movsd %xmm0, -0x58(%rbp)
movsd 0x617d(%rip), %xmm0     # 0xa030
movsd %xmm0, -0x60(%rbp)
movsd 0x6160(%rip), %xmm0     # 0xa020
movsd %xmm0, -0x68(%rbp)
leaq -0x98(%rbp), %rdi
callq 0x4340
xorps %xmm0, %xmm0
movsd %xmm0, -0xa0(%rbp)
movsd -0xa0(%rbp), %xmm1
movsd -0x68(%rbp), %xmm0
ucomisd %xmm1, %xmm0
jb 0x406e
xorps %xmm0, %xmm0
movsd %xmm0, -0xa8(%rbp)
movsd -0xa8(%rbp), %xmm1
movsd -0x60(%rbp), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x4052
movsd -0xa0(%rbp), %xmm0
movsd %xmm0, -0x118(%rbp)
movsd 0xb31b(%rip), %xmm0     # 0xf248
movsd %xmm0, -0x128(%rbp)
movsd 0xb313(%rip), %xmm0     # 0xf250
movsd %xmm0, -0x120(%rbp)
movsd 0xb2f3(%rip), %xmm0     # 0xf240
callq 0x3bd0
movsd -0x128(%rbp), %xmm1
movsd -0x120(%rbp), %xmm2
movaps %xmm0, %xmm3
movsd -0x118(%rbp), %xmm0
movl $0x1, %edi
callq 0x37d0
movsd %xmm0, -0x110(%rbp)
jmp 0x3f81
movsd -0x110(%rbp), %xmm0
movsd %xmm0, -0xb0(%rbp)
movsd -0xb0(%rbp), %xmm0
movsd 0xb52f(%rip), %xmm1     # 0xf4d0
mulsd 0xb2af(%rip), %xmm1     # 0xf258
ucomisd %xmm1, %xmm0
jb 0x4001
leaq -0x98(%rbp), %rdi
leaq -0xa0(%rbp), %rsi
callq 0x4360
movq %rax, -0x130(%rbp)
jmp 0x3fcb
movq -0x130(%rbp), %rax
movsd 0x6036(%rip), %xmm0     # 0xa010
addsd (%rax), %xmm0
movsd %xmm0, (%rax)
jmp 0x4001
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x98(%rbp), %rdi
callq 0x4540
jmp 0x41c6
movsd -0xb0(%rbp), %xmm0
callq 0x3c10
movsd 0x5ffa(%rip), %xmm1     # 0xa010
callq 0x41d0
movsd %xmm0, -0x138(%rbp)
jmp 0x4025
movsd -0x138(%rbp), %xmm0
movsd %xmm0, -0xb8(%rbp)
movsd 0x5fd3(%rip), %xmm0     # 0xa010
addsd -0xa8(%rbp), %xmm0
movsd %xmm0, -0xa8(%rbp)
jmp 0x3efe
jmp 0x4054
movsd -0x58(%rbp), %xmm0
addsd -0xa0(%rbp), %xmm0
movsd %xmm0, -0xa0(%rbp)
jmp 0x3edc
leaq -0x98(%rbp), %rdi
callq 0x4440
movq %rax, -0xc8(%rbp)
leaq -0xc0(%rbp), %rdi
leaq -0xc8(%rbp), %rsi
callq 0x4470
leaq -0x98(%rbp), %rdi
callq 0x44c0
movq %rax, -0xd8(%rbp)
leaq -0xd0(%rbp), %rdi
leaq -0xd8(%rbp), %rsi
callq 0x4470
leaq -0xc0(%rbp), %rdi
leaq -0xd0(%rbp), %rsi
callq 0x4490
testb $0x1, %al
jne 0x40d6
jmp 0x41a7
leaq -0xc0(%rbp), %rdi
callq 0x44f0
movsd (%rax), %xmm0
movq 0xaee3(%rip), %rdi      # 0xefd0
callq 0x3380
movq %rax, -0x140(%rbp)
jmp 0x40fb
movq -0x140(%rbp), %rdi
leaq 0x6435(%rip), %rsi      # 0xa53e
callq 0x31d0
movq %rax, -0x148(%rbp)
jmp 0x4117
leaq -0xc0(%rbp), %rdi
callq 0x44f0
movq -0x148(%rbp), %rdi
movsd 0x8(%rax), %xmm0
movsd -0x60(%rbp), %xmm1
divsd %xmm1, %xmm0
callq 0x3380
movq %rax, -0x150(%rbp)
jmp 0x4146
movq -0x150(%rbp), %rdi
leaq 0x63ea(%rip), %rsi      # 0xa53e
callq 0x31d0
movq %rax, -0x158(%rbp)
jmp 0x4162
movq -0x158(%rbp), %rdi
movsd 0x5ecf(%rip), %xmm0     # 0xa040
callq 0x3380
movq %rax, -0x160(%rbp)
jmp 0x417f
movq -0x160(%rbp), %rdi
movq 0xae33(%rip), %rsi      # 0xefc0
callq 0x3220
jmp 0x4194
jmp 0x4196
leaq -0xc0(%rbp), %rdi
callq 0x4510
jmp 0x4094
movl $0x0, -0x4(%rbp)
leaq -0x98(%rbp), %rdi
callq 0x4540
movl -0x4(%rbp), %eax
addq $0x160, %rsp            # imm = 0x160
popq %rbp
retq
movq -0x48(%rbp), %rdi
callq 0x3340
nop