// File: /workspace/github_cpp_makefile_star2_O3/gualtieromalde[P]owmread/owmread.C
// Function: main
int main(int nargs, char ** args)
{
	boost::program_options::options_description desc("owmread reads OpenWeatherMap current weather and feed it to FlightGear. Options:");
	desc.add_options()
    	("help", "produce help message")
    	("key", boost::program_options::value<std::string>(), "set OpenWeatherMap api key (if not specified search from file key, or from standard input)")
    	("port", boost::program_options::value<int>(), "set httpd port to communicate with FlightGear (fgfs must run with --httpd=port)")
	("interval", boost::program_options::value<int>()->default_value(10), "number of seconds between each API call. Default is 10. Note that, for the free OpenWeatherMap account the limit is set to 60 calls/minute and 1M calls/month, so a safe limit is interval>=3 s.")
    	("quiet", "does not display output")
;

	boost::program_options::variables_map vm;
	boost::program_options::store(boost::program_options::parse_command_line(nargs, args, desc), vm);
	boost::program_options::notify(vm);   

	bool ovr_key;
	bool isQuiet;

	int sleep_time =  vm["interval"].as<int>(); 
	if(sleep_time<=1)
	{
		std::clog << "Sleep time <= 1 s. This could generate a number of API calls per minute not allowed in OpenWeatherMap free plan. Continue? y/n: ";
		char yn; std::cin >> yn;
		if(yn!='y' || yn!='Y') return 2;	
	}
	else if(sleep_time<3)
	{
		std::clog << "Sleep time < 3 s. This could generate a number of API calls per month not allowed in OpenWeatherMap free plan. Continue? y/n: ";
		char yn; std::cin >> yn;
		if(yn!='y' || yn!='Y') return 2;	
	}
		


	std::string argKey;

	if(vm.count("help"))
	{
		std::clog << desc <<"\n";
		return 1;
	}

	if(vm.count("key")) 
	{
		ovr_key=true;
	      	argKey = vm["key"].as<std::string>();
	}
	else 
		ovr_key=false;

	int port;
	if(vm.count("port"))
	{
		port=vm["port"].as<int>();
	}
	else
	{
		std::cout << "insert port: ";
		std::cin >> port;
	}

	isQuiet = vm.count("quiet");

	std::string myKey;
	std::ifstream keyFile("key");
	if(!ovr_key && keyFile.good() )
	{
		keyFile >> myKey;
		keyFile.close();
	}
	else if(!ovr_key)
	{
		std::clog << "insert key: ";
		std::cin >> myKey;
		std::ofstream kF("key");
		kF << myKey;
		kF.close();
	}
	else
	{
		myKey =	argKey;
	}
	std::chrono::seconds interval( sleep_time ) ;


	while(true)
	{
		auto now = std::chrono::system_clock::now();
		std::time_t now_time = std::chrono::system_clock::to_time_t(now);
		Coord c =readCoord(port);
		Weather w = getWeather(c.lat, c.lon, myKey);
		setMetar(port, w.makeMetar());
		if(!isQuiet) std::cout << std::ctime(&now_time) <<c.lat << " " << c.lon << " " << " " << w.makeMetar();

		std::this_thread::sleep_for( interval ) ;
	}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x618, %rsp            # imm = 0x618
movq %rsi, %rbx
movl %edi, %ebp
leaq 0x180(%rsp), %r13
movq %r13, -0x10(%r13)
leaq 0x28014(%rip), %rsi     # 0x3363d
leaq 0x2805d(%rip), %rdx     # 0x3368d
leaq 0x170(%rsp), %rdi
callq 0xd074
movq 0x3898c(%rip), %rax     # 0x43fd0
movl (%rax), %edx
movl %edx, %ecx
shrl %ecx
leaq 0xd0(%rsp), %rdi
leaq 0x170(%rsp), %rsi
callq 0x8470
movq 0x170(%rsp), %rdi
cmpq %r13, %rdi
je 0xb671
callq 0x8350
leaq 0xd0(%rsp), %rdi
callq 0x86a0
leaq 0x170(%rsp), %rdi
movq %rax, (%rdi)
leaq 0x27ffe(%rip), %rsi     # 0x3368e
leaq 0x27ffc(%rip), %rdx     # 0x33693
callq 0x8530
movq %rax, %r14
xorl %edi, %edi
callq 0x1118b
leaq 0x27ffb(%rip), %rsi     # 0x336a8
leaq 0x27ff8(%rip), %rcx     # 0x336ac
movq %r14, %rdi
movq %rax, %rdx
callq 0x8580
movq %rax, %r14
xorl %edi, %edi
callq 0x11de5
leaq 0x28037(%rip), %rsi     # 0x33707
leaq 0x28035(%rip), %rcx     # 0x3370c
movq %r14, %rdi
movq %rax, %rdx
callq 0x8580
movq %rax, %r14
xorl %edi, %edi
callq 0x11de5
leaq 0x418(%rsp), %rsi
movl $0xa, (%rsi)
movq %rax, %rdi
callq 0xc1dc
leaq 0x28053(%rip), %rsi     # 0x3375c
leaq 0x28055(%rip), %rcx     # 0x33765
movq %r14, %rdi
movq %rax, %rdx
callq 0x8580
leaq 0x28104(%rip), %rsi     # 0x33826
leaq 0x28103(%rip), %rdx     # 0x3382c
movq %rax, %rdi
callq 0x8530
leaq 0x378(%rsp), %rdi
callq 0x80e0
xorps %xmm0, %xmm0
leaq 0x150(%rsp), %r9
movaps %xmm0, (%r9)
movaps %xmm0, 0x10(%r9)
leaq 0x170(%rsp), %rdi
leaq 0xd0(%rsp), %rcx
movl %ebp, %esi
movq %rbx, %rdx
xorl %r8d, %r8d
callq 0xc2d9
leaq 0x170(%rsp), %rdi
leaq 0x378(%rsp), %rsi
xorl %edx, %edx
callq 0x85e0
leaq 0x170(%rsp), %rdi
callq 0xcda6
leaq 0x150(%rsp), %rdi
callq 0xc3d4
leaq 0x378(%rsp), %rdi
callq 0x85b0
leaq 0x170(%rsp), %rdi
movq %r13, (%rdi)
leaq 0x27f9d(%rip), %rsi     # 0x3375c
leaq 0x27f9e(%rip), %rdx     # 0x33764
callq 0xd074
leaq 0x378(%rsp), %rdi
leaq 0x170(%rsp), %rsi
callq 0x8050
movq %rax, %rdi
callq 0x14e95
movl (%rax), %ebp
movq 0x170(%rsp), %rdi
cmpq %r13, %rdi
je 0xb7fc
callq 0x8350
cmpl $0x1, %ebp
jg 0xb82f
movq 0x38710(%rip), %rdi     # 0x43f18
leaq 0x28035(%rip), %rsi     # 0x33844
movl $0x80, %edx
callq 0x86e0
movq 0x38788(%rip), %rdi     # 0x43fa8
leaq 0x170(%rsp), %rsi
callq 0x8030
jmp 0xb860
cmpl $0x2, %ebp
jne 0xb86a
movq 0x386dd(%rip), %rdi     # 0x43f18
leaq 0x28083(%rip), %rsi     # 0x338c5
movl $0x7e, %edx
callq 0x86e0
movq 0x38755(%rip), %rdi     # 0x43fa8
leaq 0x170(%rsp), %rsi
callq 0x8030
movl $0x2, %ebx
jmp 0xb920
leaq 0xc0(%rsp), %r12
movq %r12, -0x10(%r12)
movq $0x0, -0x8(%r12)
movb $0x0, (%r12)
leaq 0x170(%rsp), %rdi
movq %r13, (%rdi)
leaq 0x27df7(%rip), %rsi     # 0x3368e
leaq 0x27df4(%rip), %rdx     # 0x33692
callq 0xd074
leaq 0x388(%rsp), %r14
leaq 0x170(%rsp), %rsi
movq %r14, %rdi
callq 0x15246
movq %rax, %rbx
leaq 0x390(%rsp), %r15
movq 0x170(%rsp), %rdi
cmpq %r13, %rdi
je 0xb8d8
callq 0x8350
cmpq %r15, %rbx
je 0xb9d6
movq 0x38630(%rip), %rdi     # 0x43f18
leaq 0xd0(%rsp), %rsi
callq 0x8340
leaq 0x297e7(%rip), %rsi     # 0x350e3
movl $0x1, %edx
movq %rax, %rdi
callq 0x86e0
movq 0xb0(%rsp), %rdi
cmpq %r12, %rdi
je 0xb91b
callq 0x8350
movl $0x1, %ebx
movq 0x38631(%rip), %rax     # 0x43f58
addq $0x10, %rax
leaq 0x3e8(%rsp), %rdi
movq %rax, -0x70(%rdi)
callq 0xce5c
leaq 0x3b8(%rsp), %rdi
callq 0xcedc
leaq 0x388(%rsp), %rdi
callq 0xcf38
leaq 0x138(%rsp), %r14
movq %r14, %rdi
callq 0xcff0
movq -0x28(%r14), %rdi
testq %rdi, %rdi
je 0xb99c
callq 0x8350
xorl %eax, %eax
movq %rax, 0x110(%rsp)
movl %eax, 0x118(%rsp)
movq %rax, 0x120(%rsp)
movl %eax, 0x128(%rsp)
movq %rax, 0x130(%rsp)
leaq 0xf8(%rsp), %r14
movq %r14, %rdi
callq 0xd032
movq -0x28(%r14), %rdi
leaq 0xe0(%rsp), %rax
cmpq %rax, %rdi
je 0xb9c2
callq 0x8350
movl %ebx, %eax
addq $0x618, %rsp            # imm = 0x618
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x170(%rsp), %rdi
movq %r13, (%rdi)
leaq 0x27cc0(%rip), %rsi     # 0x336a8
leaq 0x27cbc(%rip), %rdx     # 0x336ab
callq 0xd074
leaq 0x170(%rsp), %rsi
movq %r14, %rdi
callq 0x15246
movq %rax, %r15
movq 0x170(%rsp), %rdi
cmpq %r13, %rdi
je 0xba19
callq 0x8350
cmpq %rbx, %r15
jne 0xbb54
leaq 0x170(%rsp), %rdi
movq %r13, (%rdi)
leaq 0x27cd3(%rip), %rsi     # 0x33707
leaq 0x27cd0(%rip), %rdx     # 0x3370b
callq 0xd074
leaq 0x170(%rsp), %rsi
movq %r14, %rdi
callq 0x15246
movq %rax, 0x8(%rsp)
movq 0x170(%rsp), %rdi
cmpq %r13, %rdi
je 0xba67
callq 0x8350
cmpq %rbx, 0x8(%rsp)
jne 0xbbba
movq 0x384ef(%rip), %rdi     # 0x43f68
leaq 0x27ec4(%rip), %rsi     # 0x33944
movl $0xd, %edx
callq 0x86e0
movq 0x38517(%rip), %rdi     # 0x43fa8
leaq 0x4(%rsp), %rsi
callq 0x8840
leaq 0x170(%rsp), %rdi
movq %r13, (%rdi)
leaq 0x27d79(%rip), %rsi     # 0x33826
leaq 0x27d77(%rip), %rdx     # 0x3382b
callq 0xd074
leaq 0x170(%rsp), %rsi
movq %r14, %rdi
callq 0x15246
movq %rax, 0x38(%rsp)
movq 0x170(%rsp), %rdi
cmpq %r13, %rdi
je 0xbae0
callq 0x8350
leaq 0x28(%rsp), %rax
movq %rax, -0x10(%rax)
movq $0x0, -0x8(%rax)
movb $0x0, (%rax)
leaq 0x27bad(%rip), %rsi     # 0x336a8
leaq 0x170(%rsp), %rdi
movl $0x8, %edx
callq 0x8070
cmpq %rbx, %r15
jne 0xbc16
movq 0x170(%rsp), %rax
movq -0x18(%rax), %rax
cmpl $0x0, 0x190(%rsp,%rax)
jne 0xbdc8
leaq 0x170(%rsp), %rdi
leaq 0x18(%rsp), %rsi
callq 0x8290
leaq 0x170(%rsp), %rdi
callq 0x8410
jmp 0xbc28
leaq 0x170(%rsp), %rdi
movq %r13, (%rdi)
leaq 0x27b42(%rip), %rsi     # 0x336a8
leaq 0x27b3e(%rip), %rdx     # 0x336ab
callq 0xd074
leaq 0x378(%rsp), %rdi
leaq 0x170(%rsp), %rsi
callq 0x8050
movq %rax, %rdi
callq 0x152cf
leaq 0xb0(%rsp), %rdi
movq %rax, %rsi
callq 0x8810
movq 0x170(%rsp), %rdi
cmpq %r13, %rdi
je 0xba22
callq 0x8350
jmp 0xba22
leaq 0x170(%rsp), %rdi
movq %r13, (%rdi)
leaq 0x27b3b(%rip), %rsi     # 0x33707
leaq 0x27b38(%rip), %rdx     # 0x3370b
callq 0xd074
leaq 0x378(%rsp), %rdi
leaq 0x170(%rsp), %rsi
callq 0x8050
movq %rax, %rdi
callq 0x14e95
movl (%rax), %eax
movl %eax, 0x4(%rsp)
movq 0x170(%rsp), %rdi
cmpq %r13, %rdi
je 0xba9b
callq 0x8350
jmp 0xba9b
leaq 0x18(%rsp), %rdi
leaq 0xb0(%rsp), %rsi
callq 0x8810
leaq 0x48(%rsp), %rax
movq %rbp, (%rax)
leaq 0x70(%rsp), %r14
leaq 0x418(%rsp), %r13
leaq 0x90(%rsp), %rbp
callq 0x84c0
movabsq $0x112e0be826d694b3, %rcx # imm = 0x112E0BE826D694B3
imulq %rcx
movq %rdx, %rax
shrq $0x3f, %rax
sarq $0x1a, %rdx
addq %rax, %rdx
movq %rdx, 0x40(%rsp)
movl 0x4(%rsp), %edi
callq 0xabab
movsd %xmm0, 0x8(%rsp)
movsd %xmm1, 0x10(%rsp)
leaq 0x80(%rsp), %rax
movq %rax, 0x70(%rsp)
movq 0x18(%rsp), %rsi
movq 0x20(%rsp), %rdx
addq %rsi, %rdx
movq %r14, %rdi
callq 0xc564
movq %r13, %rdi
movsd 0x8(%rsp), %xmm0
movsd 0x10(%rsp), %xmm1
movq %r14, %rsi
callq 0x91ac
movq 0x70(%rsp), %rdi
leaq 0x80(%rsp), %rax
cmpq %rax, %rdi
je 0xbccf
callq 0x8350
movl 0x4(%rsp), %r15d
movq %rbp, %rdi
movq %r13, %rsi
callq 0x9798
movl %r15d, %edi
movq %rbp, %rsi
callq 0xb310
movq 0x90(%rsp), %rdi
leaq 0xa0(%rsp), %rax
cmpq %rax, %rdi
je 0xbd04
callq 0x8350
cmpq %rbx, 0x38(%rsp)
jne 0xbdb9
leaq 0x40(%rsp), %rdi
callq 0x8750
movq 0x38248(%rip), %rdi     # 0x43f68
movq %rax, %rsi
callq 0x83b0
movq %rax, %rdi
movsd 0x8(%rsp), %xmm0
callq 0x8520
movq %rax, %r15
movl $0x1, %edx
movq %rax, %rdi
leaq 0x29388(%rip), %rsi     # 0x350d0
callq 0x86e0
movq %r15, %rdi
movsd 0x10(%rsp), %xmm0
callq 0x8520
movq %rax, %r15
movl $0x1, %edx
movq %rax, %rdi
leaq 0x29363(%rip), %rsi     # 0x350d0
callq 0x86e0
movl $0x1, %edx
movq %r15, %rdi
leaq 0x2934f(%rip), %rsi     # 0x350d0
callq 0x86e0
leaq 0x50(%rsp), %rdi
movq %r13, %rsi
callq 0x9798
movq 0x50(%rsp), %rsi
movq 0x58(%rsp), %rdx
movq %r15, %rdi
callq 0x86e0
movq 0x50(%rsp), %rdi
leaq 0x60(%rsp), %rax
cmpq %rax, %rdi
je 0xbdb9
callq 0x8350
leaq 0x48(%rsp), %rdi
callq 0xc40b
jmp 0xbc45
movq 0x38149(%rip), %rdi     # 0x43f18
leaq 0x27b7c(%rip), %rsi     # 0x33952
movl $0xc, %edx
callq 0x86e0
movq 0x381c1(%rip), %rdi     # 0x43fa8
leaq 0x18(%rsp), %rsi
callq 0x8290
leaq 0x278b0(%rip), %rsi     # 0x336a8
leaq 0x418(%rsp), %rdi
movl $0x10, %edx
callq 0x81d0
movq 0x18(%rsp), %rsi
movq 0x20(%rsp), %rdx
leaq 0x418(%rsp), %rdi
callq 0x86e0
leaq 0x418(%rsp), %rdi
callq 0x8680
leaq 0x418(%rsp), %rdi
callq 0x8550
jmp 0xbc28
movq %rax, %rbx
movq 0x50(%rsp), %rdi
leaq 0x60(%rsp), %rax
jmp 0xbe8a
jmp 0xbe9a
movq %rax, %rbx
leaq 0x418(%rsp), %rdi
callq 0x8550
jmp 0xbe9d
jmp 0xbe9a
movq %rax, %rbx
movq 0x90(%rsp), %rdi
leaq 0xa0(%rsp), %rax
jmp 0xbe8a
movq %rax, %rbx
movq 0x70(%rsp), %rdi
leaq 0x80(%rsp), %rax
cmpq %rax, %rdi
je 0xbe9d
callq 0x8350
jmp 0xbe9d
jmp 0xbe9a
jmp 0xbe9a
movq %rax, %rbx
leaq 0x170(%rsp), %rdi
callq 0x8060
jmp 0xbeaf
movq %rax, %rbx
movq 0x18(%rsp), %rdi
leaq 0x28(%rsp), %rax
cmpq %rax, %rdi
jne 0xbee6
jmp 0xbef4
jmp 0xbed6
jmp 0xbef1
jmp 0xbed6
jmp 0xbef1
jmp 0xbef1
jmp 0xbed6
jmp 0xbed6
jmp 0xbef1
jmp 0xbef1
jmp 0xbed6
jmp 0xbef1
movq %rax, %rbx
movq 0x170(%rsp), %rdi
cmpq %r13, %rdi
je 0xbef4
callq 0x8350
jmp 0xbef4
jmp 0xbf09
jmp 0xbef1
movq %rax, %rbx
movq 0xb0(%rsp), %rdi
cmpq %r12, %rdi
jne 0xbf60
jmp 0xbf65
jmp 0xbf09
jmp 0xbf09
jmp 0xbf09
movq %rax, %rbx
jmp 0xbf65
movq %rax, %rbx
leaq 0x170(%rsp), %rdi
callq 0xcda6
jmp 0xbf23
movq %rax, %rbx
leaq 0x150(%rsp), %rdi
callq 0xc3d4
jmp 0xbf65
jmp 0xbf76
movq %rax, %rbx
movq 0x170(%rsp), %rdi
cmpq %r13, %rdi
je 0xbf86
callq 0x8350
jmp 0xbf86
movq %rax, %rbx
jmp 0xbf86
movq %rax, %rbx
movq 0x170(%rsp), %rdi
cmpq %r13, %rdi
je 0xbf65
callq 0x8350
leaq 0x378(%rsp), %rdi
callq 0xc446
jmp 0xbf79
jmp 0xbf76
movq %rax, %rbx
leaq 0xd0(%rsp), %rdi
callq 0xc478
movq %rbx, %rdi
callq 0x8440