// File: /workspace/github_cpp_makefile_star2_O1/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), %r12
movq %r12, -0x10(%r12)
leaq 0x27fec(%rip), %rsi     # 0x3363d
leaq 0x28035(%rip), %rdx     # 0x3368d
leaq 0x170(%rsp), %rdi
callq 0xd022
movq 0x38974(%rip), %rax     # 0x43fe0
movl (%rax), %edx
movl %edx, %ecx
shrl %ecx
leaq 0xd0(%rsp), %rdi
leaq 0x170(%rsp), %rsi
callq 0x8470
movq 0x170(%rsp), %rdi
cmpq %r12, %rdi
je 0xb699
callq 0x8350
leaq 0xd0(%rsp), %rdi
callq 0x86a0
leaq 0x170(%rsp), %rdi
movq %rax, (%rdi)
leaq 0x27fd6(%rip), %rsi     # 0x3368e
leaq 0x27fd4(%rip), %rdx     # 0x33693
callq 0x8530
movq %rax, %r14
xorl %edi, %edi
callq 0x10fbf
leaq 0x27fd3(%rip), %rsi     # 0x336a8
leaq 0x27fd0(%rip), %rcx     # 0x336ac
movq %r14, %rdi
movq %rax, %rdx
callq 0x8580
movq %rax, %r14
xorl %edi, %edi
callq 0x11c21
leaq 0x2800f(%rip), %rsi     # 0x33707
leaq 0x2800d(%rip), %rcx     # 0x3370c
movq %r14, %rdi
movq %rax, %rdx
callq 0x8580
movq %rax, %r14
xorl %edi, %edi
callq 0x11c21
leaq 0x418(%rsp), %rsi
movl $0xa, (%rsi)
movq %rax, %rdi
callq 0xc204
leaq 0x2802b(%rip), %rsi     # 0x3375c
leaq 0x2802d(%rip), %rcx     # 0x33765
movq %r14, %rdi
movq %rax, %rdx
callq 0x8580
leaq 0x280dc(%rip), %rsi     # 0x33826
leaq 0x280db(%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 0xc303
leaq 0x170(%rsp), %rdi
leaq 0x378(%rsp), %rsi
xorl %edx, %edx
callq 0x85e0
leaq 0x170(%rsp), %rdi
callq 0xcd66
leaq 0x150(%rsp), %rdi
callq 0xc3fe
leaq 0x378(%rsp), %rdi
callq 0x85b0
leaq 0x170(%rsp), %rdi
movq %r12, (%rdi)
leaq 0x27f75(%rip), %rsi     # 0x3375c
leaq 0x27f76(%rip), %rdx     # 0x33764
callq 0xd022
leaq 0x378(%rsp), %rdi
leaq 0x170(%rsp), %rsi
callq 0x8050
movq %rax, %rdi
callq 0x14d45
movl (%rax), %r13d
movq 0x170(%rsp), %rdi
cmpq %r12, %rdi
je 0xb825
callq 0x8350
cmpl $0x1, %r13d
jg 0xb859
movq 0x386f6(%rip), %rdi     # 0x43f28
leaq 0x2800b(%rip), %rsi     # 0x33844
movl $0x80, %edx
callq 0x86e0
movq 0x3876e(%rip), %rdi     # 0x43fb8
leaq 0x170(%rsp), %rsi
callq 0x8030
jmp 0xb88b
cmpl $0x2, %r13d
jne 0xb895
movq 0x386c2(%rip), %rdi     # 0x43f28
leaq 0x28058(%rip), %rsi     # 0x338c5
movl $0x7e, %edx
callq 0x86e0
movq 0x3873a(%rip), %rdi     # 0x43fb8
leaq 0x170(%rsp), %rsi
callq 0x8030
movl $0x2, %ebx
jmp 0xb948
leaq 0xc0(%rsp), %rbp
movq %rbp, -0x10(%rbp)
movq $0x0, -0x8(%rbp)
movb $0x0, (%rbp)
leaq 0x170(%rsp), %rdi
movq %r12, (%rdi)
leaq 0x27dcf(%rip), %rsi     # 0x3368e
leaq 0x27dcc(%rip), %rdx     # 0x33692
callq 0xd022
leaq 0x388(%rsp), %rbx
leaq 0x170(%rsp), %rsi
movq %rbx, %rdi
callq 0x1511e
movq %rax, %r14
leaq 0x390(%rsp), %r15
movq 0x170(%rsp), %rdi
cmpq %r12, %rdi
je 0xb900
callq 0x8350
cmpq %r15, %r14
je 0xb9fe
movq 0x38618(%rip), %rdi     # 0x43f28
leaq 0xd0(%rsp), %rsi
callq 0x8340
leaq 0x297bf(%rip), %rsi     # 0x350e3
movl $0x1, %edx
movq %rax, %rdi
callq 0x86e0
movq 0xb0(%rsp), %rdi
cmpq %rbp, %rdi
je 0xb943
callq 0x8350
movl $0x1, %ebx
movq 0x38619(%rip), %rax     # 0x43f68
addq $0x10, %rax
leaq 0x3e8(%rsp), %rdi
movq %rax, -0x70(%rdi)
callq 0xce16
leaq 0x3b8(%rsp), %rdi
callq 0xce96
leaq 0x388(%rsp), %rdi
callq 0xcef2
leaq 0x138(%rsp), %r14
movq %r14, %rdi
callq 0xcfaa
movq -0x28(%r14), %rdi
testq %rdi, %rdi
je 0xb9c4
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 0xcfe6
movq -0x28(%r14), %rdi
leaq 0xe0(%rsp), %rax
cmpq %rax, %rdi
je 0xb9ea
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 %r12, (%rdi)
leaq 0x27c98(%rip), %rsi     # 0x336a8
leaq 0x27c94(%rip), %rdx     # 0x336ab
callq 0xd022
leaq 0x170(%rsp), %rsi
movq %rbx, %rdi
callq 0x1511e
movq %rax, %r14
movq 0x170(%rsp), %rdi
cmpq %r12, %rdi
je 0xba41
callq 0x8350
cmpq %r15, %r14
jne 0xbb7c
leaq 0x170(%rsp), %rdi
movq %r12, (%rdi)
leaq 0x27cab(%rip), %rsi     # 0x33707
leaq 0x27ca8(%rip), %rdx     # 0x3370b
callq 0xd022
leaq 0x170(%rsp), %rsi
movq %rbx, %rdi
callq 0x1511e
movq %rax, 0x8(%rsp)
movq 0x170(%rsp), %rdi
cmpq %r12, %rdi
je 0xba8f
callq 0x8350
cmpq %r15, 0x8(%rsp)
jne 0xbbe2
movq 0x384d7(%rip), %rdi     # 0x43f78
leaq 0x27e9c(%rip), %rsi     # 0x33944
movl $0xd, %edx
callq 0x86e0
movq 0x384ff(%rip), %rdi     # 0x43fb8
leaq 0x4(%rsp), %rsi
callq 0x8840
leaq 0x170(%rsp), %rdi
movq %r12, (%rdi)
leaq 0x27d51(%rip), %rsi     # 0x33826
leaq 0x27d4f(%rip), %rdx     # 0x3382b
callq 0xd022
leaq 0x170(%rsp), %rsi
movq %rbx, %rdi
callq 0x1511e
movq %rax, 0x38(%rsp)
movq 0x170(%rsp), %rdi
cmpq %r12, %rdi
je 0xbb08
callq 0x8350
leaq 0x28(%rsp), %rax
movq %rax, -0x10(%rax)
movq $0x0, -0x8(%rax)
movb $0x0, (%rax)
leaq 0x27b85(%rip), %rsi     # 0x336a8
leaq 0x170(%rsp), %rdi
movl $0x8, %edx
callq 0x8070
cmpq %r15, %r14
jne 0xbc3e
movq 0x170(%rsp), %rax
movq -0x18(%rax), %rax
cmpl $0x0, 0x190(%rsp,%rax)
jne 0xbdf0
leaq 0x170(%rsp), %rdi
leaq 0x18(%rsp), %rsi
callq 0x8290
leaq 0x170(%rsp), %rdi
callq 0x8410
jmp 0xbc50
leaq 0x170(%rsp), %rdi
movq %r12, (%rdi)
leaq 0x27b1a(%rip), %rsi     # 0x336a8
leaq 0x27b16(%rip), %rdx     # 0x336ab
callq 0xd022
leaq 0x378(%rsp), %rdi
leaq 0x170(%rsp), %rsi
callq 0x8050
movq %rax, %rdi
callq 0x151a7
leaq 0xb0(%rsp), %rdi
movq %rax, %rsi
callq 0x8810
movq 0x170(%rsp), %rdi
cmpq %r12, %rdi
je 0xba4a
callq 0x8350
jmp 0xba4a
leaq 0x170(%rsp), %rdi
movq %r12, (%rdi)
leaq 0x27b13(%rip), %rsi     # 0x33707
leaq 0x27b10(%rip), %rdx     # 0x3370b
callq 0xd022
leaq 0x378(%rsp), %rdi
leaq 0x170(%rsp), %rsi
callq 0x8050
movq %rax, %rdi
callq 0x14d45
movl (%rax), %eax
movl %eax, 0x4(%rsp)
movq 0x170(%rsp), %rdi
cmpq %r12, %rdi
je 0xbac3
callq 0x8350
jmp 0xbac3
leaq 0x18(%rsp), %rdi
leaq 0xb0(%rsp), %rsi
callq 0x8810
leaq 0x48(%rsp), %rax
movq %r13, (%rax)
leaq 0x70(%rsp), %rbx
leaq 0x418(%rsp), %r12
leaq 0x90(%rsp), %r13
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 0xabd2
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 %rbx, %rdi
callq 0xc58e
movq %r12, %rdi
movsd 0x8(%rsp), %xmm0
movsd 0x10(%rsp), %xmm1
movq %rbx, %rsi
callq 0x91ae
movq 0x70(%rsp), %rdi
leaq 0x80(%rsp), %rax
cmpq %rax, %rdi
je 0xbcf7
callq 0x8350
movl 0x4(%rsp), %r14d
movq %r13, %rdi
movq %r12, %rsi
callq 0x979a
movl %r14d, %edi
movq %r13, %rsi
callq 0xb337
movq 0x90(%rsp), %rdi
leaq 0xa0(%rsp), %rax
cmpq %rax, %rdi
je 0xbd2c
callq 0x8350
cmpq %r15, 0x38(%rsp)
jne 0xbde1
leaq 0x40(%rsp), %rdi
callq 0x8750
movq 0x38230(%rip), %rdi     # 0x43f78
movq %rax, %rsi
callq 0x83b0
movq %rax, %rdi
movsd 0x8(%rsp), %xmm0
callq 0x8520
movq %rax, %r14
movl $0x1, %edx
movq %rax, %rdi
leaq 0x29360(%rip), %rsi     # 0x350d0
callq 0x86e0
movq %r14, %rdi
movsd 0x10(%rsp), %xmm0
callq 0x8520
movq %rax, %r14
movl $0x1, %edx
movq %rax, %rdi
leaq 0x2933b(%rip), %rsi     # 0x350d0
callq 0x86e0
movl $0x1, %edx
movq %r14, %rdi
leaq 0x29327(%rip), %rsi     # 0x350d0
callq 0x86e0
leaq 0x50(%rsp), %rdi
movq %r12, %rsi
callq 0x979a
movq 0x50(%rsp), %rsi
movq 0x58(%rsp), %rdx
movq %r14, %rdi
callq 0x86e0
movq 0x50(%rsp), %rdi
leaq 0x60(%rsp), %rax
cmpq %rax, %rdi
je 0xbde1
callq 0x8350
leaq 0x48(%rsp), %rdi
callq 0xc435
jmp 0xbc6d
movq 0x38131(%rip), %rdi     # 0x43f28
leaq 0x27b54(%rip), %rsi     # 0x33952
movl $0xc, %edx
callq 0x86e0
movq 0x381a9(%rip), %rdi     # 0x43fb8
leaq 0x18(%rsp), %rsi
callq 0x8290
leaq 0x27888(%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 0xbc50
movq %rax, %rbx
movq 0x50(%rsp), %rdi
leaq 0x60(%rsp), %rax
jmp 0xbeb2
jmp 0xbec2
movq %rax, %rbx
leaq 0x418(%rsp), %rdi
callq 0x8550
jmp 0xbec5
jmp 0xbec2
movq %rax, %rbx
movq 0x90(%rsp), %rdi
leaq 0xa0(%rsp), %rax
jmp 0xbeb2
movq %rax, %rbx
movq 0x70(%rsp), %rdi
leaq 0x80(%rsp), %rax
cmpq %rax, %rdi
je 0xbec5
callq 0x8350
jmp 0xbec5
jmp 0xbec2
jmp 0xbec2
movq %rax, %rbx
leaq 0x170(%rsp), %rdi
callq 0x8060
jmp 0xbed7
movq %rax, %rbx
movq 0x18(%rsp), %rdi
leaq 0x28(%rsp), %rax
cmpq %rax, %rdi
jne 0xbf0e
jmp 0xbf1c
jmp 0xbefe
jmp 0xbf19
jmp 0xbefe
jmp 0xbf19
jmp 0xbf19
jmp 0xbefe
jmp 0xbefe
jmp 0xbf19
jmp 0xbf19
jmp 0xbefe
jmp 0xbf19
movq %rax, %rbx
movq 0x170(%rsp), %rdi
cmpq %r12, %rdi
je 0xbf1c
callq 0x8350
jmp 0xbf1c
jmp 0xbf31
jmp 0xbf19
movq %rax, %rbx
movq 0xb0(%rsp), %rdi
cmpq %rbp, %rdi
jne 0xbf88
jmp 0xbf8d
jmp 0xbf31
jmp 0xbf31
jmp 0xbf31
movq %rax, %rbx
jmp 0xbf8d
movq %rax, %rbx
leaq 0x170(%rsp), %rdi
callq 0xcd66
jmp 0xbf4b
movq %rax, %rbx
leaq 0x150(%rsp), %rdi
callq 0xc3fe
jmp 0xbf8d
jmp 0xbf9e
movq %rax, %rbx
movq 0x170(%rsp), %rdi
cmpq %r12, %rdi
je 0xbfae
callq 0x8350
jmp 0xbfae
movq %rax, %rbx
jmp 0xbfae
movq %rax, %rbx
movq 0x170(%rsp), %rdi
cmpq %r12, %rdi
je 0xbf8d
callq 0x8350
leaq 0x378(%rsp), %rdi
callq 0xc470
jmp 0xbfa1
jmp 0xbf9e
movq %rax, %rbx
leaq 0xd0(%rsp), %rdi
callq 0xc4a2
movq %rbx, %rdi
callq 0x8440