// File: gualtieromalde[P]owmread/owmread.C
// Function: getWeather(double, double, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>)
Weather getWeather(double lon, double lat, std::string myKey)
{
    
	
    Weather weather;
    const std::string url = getUrl(lon,lat,myKey);
    CURL* curl = curl_easy_init();

    // Set remote URL.
    curl_easy_setopt(curl, CURLOPT_URL, url.c_str());
    curl_easy_setopt(curl, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
    curl_easy_setopt(curl, CURLOPT_TIMEOUT, 10);
    curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
    long httpCode(0);
    std::string httpData;
    curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteCallback);
    curl_easy_setopt(curl, CURLOPT_WRITEDATA, &httpData);
    curl_easy_perform(curl);
    curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &httpCode);
    curl_easy_cleanup(curl);

    if (httpCode != CURLE_HTTP_RETURNED_ERROR)
    {

        Json::Value jsonData;
        Json::Reader jsonReader;
	std::string err;
        if ( jsonReader.parse(httpData, jsonData)   ) 
        {

   	    weather.temperature = jsonData["main"]["temp"].asDouble() - kel_to_c;
            weather.pressure = jsonData["main"]["pressure"].asDouble();
	    /// set default pressure for absurd values
	    if(weather.pressure < 800 || weather.pressure > 1200) weather.pressure = 1013;
	    weather.relhum = jsonData["main"]["humidity"].asDouble();
	    weather.dewpoint = getDewPoint(weather.temperature, weather.relhum);

	    weather.wind.speed = jsonData["wind"]["speed"].asDouble() * ms_to_kt;
	    weather.wind.gust = jsonData["wind"]["gust"].asDouble() * ms_to_kt;
	    weather.wind.deg = jsonData["wind"]["deg"].asDouble();

	    weather.visibility = jsonData["visibility"].asInt();
	    if(weather.visibility>9999) weather.visibility=9999;

	    weather.cloudiness = jsonData["clouds"]["all"].asInt();
	    weather.code = jsonData["weather"][0]["id"].asInt();
	    //...
	    return weather;
        }
        else
        {
            std::cerr << "Could not parse HTTP data as JSON" << std::endl;
            return Weather(1);
       	} 
    }
    else
    {
        std::cerr << "Couldn't get from " << url << " - exiting" << std::endl;
        return Weather(0);
    }
}

// Assembly:
subq $0x388, %rsp            # imm = 0x388
movq %rsi, 0x120(%rsp)
movq %rdi, 0x110(%rsp)
movq %rdi, 0x118(%rsp)
movsd %xmm0, 0x380(%rsp)
movsd %xmm1, 0x378(%rsp)
movq %rsi, 0x370(%rsp)
leaq 0x320(%rsp), %rdi
callq 0xece0
movq 0x120(%rsp), %rsi
movsd 0x380(%rsp), %xmm0
movsd %xmm0, 0x128(%rsp)
movsd 0x378(%rsp), %xmm0
movsd %xmm0, 0x130(%rsp)
leaq 0x2e0(%rsp), %rdi
movq %rdi, 0x138(%rsp)
callq 0xa190
movsd 0x128(%rsp), %xmm0
movsd 0x130(%rsp), %xmm1
movq 0x138(%rsp), %rsi
leaq 0x300(%rsp), %rdi
callq 0xaf80
jmp 0xb4a0
leaq 0x2e0(%rsp), %rdi
callq 0xac68
callq 0xaa10
movq %rax, 0x108(%rsp)
jmp 0xb4bc
movq 0x108(%rsp), %rax
movq %rax, 0x2c8(%rsp)
movq 0x2c8(%rsp), %rax
movq %rax, 0x100(%rsp)
leaq 0x300(%rsp), %rdi
callq 0xa180
movq 0x100(%rsp), %rdi
movq %rax, %rdx
xorl %eax, %eax
movl $0x2712, %esi           # imm = 0x2712
callq 0xa8b0
jmp 0xb502
movq 0x2c8(%rsp), %rdi
xorl %eax, %eax
movl $0x71, %esi
movl $0x1, %edx
callq 0xa8b0
jmp 0xb51d
movq 0x2c8(%rsp), %rdi
xorl %eax, %eax
movl $0xd, %esi
movl $0xa, %edx
callq 0xa8b0
jmp 0xb538
movq 0x2c8(%rsp), %rdi
xorl %eax, %eax
movl $0x34, %esi
movl $0x1, %edx
callq 0xa8b0
jmp 0xb553
movq $0x0, 0x2c0(%rsp)
leaq 0x2a0(%rsp), %rdi
callq 0xa390
movq 0x2c8(%rsp), %rdi
leaq 0x6e5(%rip), %rdx       # 0xbc60
xorl %eax, %eax
movl $0x4e2b, %esi           # imm = 0x4E2B
callq 0xa8b0
jmp 0xb589
movq 0x2c8(%rsp), %rdi
xorl %eax, %eax
movl $0x2711, %esi           # imm = 0x2711
leaq 0x2a0(%rsp), %rdx
callq 0xa8b0
jmp 0xb5a7
movq 0x2c8(%rsp), %rdi
callq 0xa6d0
jmp 0xb5b6
movq 0x2c8(%rsp), %rdi
xorl %eax, %eax
movl $0x200002, %esi         # imm = 0x200002
leaq 0x2c0(%rsp), %rdx
callq 0xa9e0
jmp 0xb5d4
movq 0x2c8(%rsp), %rdi
callq 0xa1c0
jmp 0xb5e3
cmpq $0x16, 0x2c0(%rsp)
je 0xbb88
leaq 0x278(%rsp), %rdi
xorl %esi, %esi
callq 0x39080
jmp 0xb603
leaq 0x168(%rsp), %rdi
callq 0x2e210
jmp 0xb612
leaq 0x148(%rsp), %rdi
callq 0xa390
leaq 0x168(%rsp), %rdi
leaq 0x2a0(%rsp), %rsi
leaq 0x278(%rsp), %rdx
movl $0x1, %ecx
callq 0x2fe00
movb %al, 0xff(%rsp)
jmp 0xb64a
movb 0xff(%rsp), %al
testb $0x1, %al
jne 0xb65a
jmp 0xbafe
leaq 0x3aebe(%rip), %rsi     # 0x4651f
leaq 0x278(%rsp), %rdi
callq 0x3cca0
movq %rax, 0xf0(%rsp)
jmp 0xb678
movq 0xf0(%rsp), %rdi
leaq 0x3ae9d(%rip), %rsi     # 0x46524
callq 0x3cca0
movq %rax, 0xe8(%rsp)
jmp 0xb696
movq 0xe8(%rsp), %rdi
callq 0x37290
movsd %xmm0, 0xe0(%rsp)
jmp 0xb6ae
movsd 0xe0(%rsp), %xmm0
movsd 0x3a959(%rip), %xmm1    # 0x46018
addsd %xmm1, %xmm0
movsd %xmm0, 0x320(%rsp)
leaq 0x3ae4c(%rip), %rsi     # 0x4651f
leaq 0x278(%rsp), %rdi
callq 0x3cca0
movq %rax, 0xd8(%rsp)
jmp 0xb6ea
movq 0xd8(%rsp), %rdi
leaq 0x3ae30(%rip), %rsi     # 0x46529
callq 0x3cca0
movq %rax, 0xd0(%rsp)
jmp 0xb708
movq 0xd0(%rsp), %rdi
callq 0x37290
movsd %xmm0, 0xc8(%rsp)
jmp 0xb720
movsd 0xc8(%rsp), %xmm0
movsd %xmm0, 0x360(%rsp)
movsd 0x3a8e6(%rip), %xmm0    # 0x46020
ucomisd 0x360(%rsp), %xmm0
ja 0xb760
movsd 0x360(%rsp), %xmm0
movsd 0x3a8d2(%rip), %xmm1    # 0x46028
ucomisd %xmm1, %xmm0
jbe 0xb81a
movsd 0x3a8c8(%rip), %xmm0    # 0x46030
movsd %xmm0, 0x360(%rsp)
jmp 0xb81a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x2d8(%rsp)
movl %eax, 0x2d4(%rsp)
leaq 0x2e0(%rsp), %rdi
callq 0xac68
jmp 0xbc44
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x2d8(%rsp)
movl %eax, 0x2d4(%rsp)
jmp 0xbc37
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x2d8(%rsp)
movl %eax, 0x2d4(%rsp)
jmp 0xbc2a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x2d8(%rsp)
movl %eax, 0x2d4(%rsp)
jmp 0xbb76
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x2d8(%rsp)
movl %eax, 0x2d4(%rsp)
leaq 0x148(%rsp), %rdi
callq 0xac68
leaq 0x168(%rsp), %rdi
callq 0xed10
jmp 0xbb76
leaq 0x3acfe(%rip), %rsi     # 0x4651f
leaq 0x278(%rsp), %rdi
callq 0x3cca0
movq %rax, 0xc0(%rsp)
jmp 0xb838
movq 0xc0(%rsp), %rdi
leaq 0x3aceb(%rip), %rsi     # 0x46532
callq 0x3cca0
movq %rax, 0xb8(%rsp)
jmp 0xb856
movq 0xb8(%rsp), %rdi
callq 0x37290
movsd %xmm0, 0xb0(%rsp)
jmp 0xb86e
movsd 0xb0(%rsp), %xmm0
movsd %xmm0, 0x330(%rsp)
movsd 0x320(%rsp), %xmm0
movsd 0x330(%rsp), %xmm1
callq 0xaf40
movsd %xmm0, 0x328(%rsp)
leaq 0x3ac94(%rip), %rsi     # 0x4653b
leaq 0x278(%rsp), %rdi
callq 0x3cca0
movq %rax, 0xa8(%rsp)
jmp 0xb8be
movq 0xa8(%rsp), %rdi
leaq 0x3ac73(%rip), %rsi     # 0x46540
callq 0x3cca0
movq %rax, 0xa0(%rsp)
jmp 0xb8dc
movq 0xa0(%rsp), %rdi
callq 0x37290
movsd %xmm0, 0x98(%rsp)
jmp 0xb8f4
movsd 0x98(%rsp), %xmm0
movsd 0x3a733(%rip), %xmm1    # 0x46038
mulsd %xmm1, %xmm0
movsd %xmm0, 0x348(%rsp)
leaq 0x3ac22(%rip), %rsi     # 0x4653b
leaq 0x278(%rsp), %rdi
callq 0x3cca0
movq %rax, 0x90(%rsp)
jmp 0xb930
movq 0x90(%rsp), %rdi
leaq 0x3ac07(%rip), %rsi     # 0x46546
callq 0x3cca0
movq %rax, 0x88(%rsp)
jmp 0xb94e
movq 0x88(%rsp), %rdi
callq 0x37290
movsd %xmm0, 0x80(%rsp)
jmp 0xb966
movsd 0x80(%rsp), %xmm0
movsd 0x3a6c1(%rip), %xmm1    # 0x46038
mulsd %xmm1, %xmm0
movsd %xmm0, 0x358(%rsp)
leaq 0x3abb0(%rip), %rsi     # 0x4653b
leaq 0x278(%rsp), %rdi
callq 0x3cca0
movq %rax, 0x78(%rsp)
jmp 0xb99f
movq 0x78(%rsp), %rdi
leaq 0x3ad17(%rip), %rsi     # 0x466c2
callq 0x3cca0
movq %rax, 0x70(%rsp)
jmp 0xb9b7
movq 0x70(%rsp), %rdi
callq 0x37290
movsd %xmm0, 0x68(%rsp)
jmp 0xb9c9
movsd 0x68(%rsp), %xmm0
cvttsd2si %xmm0, %eax
movl %eax, 0x350(%rsp)
leaq 0x3ab6a(%rip), %rsi     # 0x4654b
leaq 0x278(%rsp), %rdi
callq 0x3cca0
movq %rax, 0x60(%rsp)
jmp 0xb9f5
movq 0x60(%rsp), %rdi
callq 0x379f0
movl %eax, 0x5c(%rsp)
jmp 0xba05
movl 0x5c(%rsp), %eax
movl %eax, 0x338(%rsp)
cmpl $0x270f, 0x338(%rsp) # imm = 0x270F
jle 0xba28
movl $0x270f, 0x338(%rsp) # imm = 0x270F
leaq 0x3ab27(%rip), %rsi     # 0x46556
leaq 0x278(%rsp), %rdi
callq 0x3cca0
movq %rax, 0x50(%rsp)
jmp 0xba43
movq 0x50(%rsp), %rdi
leaq 0x3ab0e(%rip), %rsi     # 0x4655d
callq 0x3cca0
movq %rax, 0x48(%rsp)
jmp 0xba5b
movq 0x48(%rsp), %rdi
callq 0x379f0
movl %eax, 0x44(%rsp)
jmp 0xba6b
movl 0x44(%rsp), %eax
movl %eax, 0x33c(%rsp)
leaq 0x3aae4(%rip), %rsi     # 0x46561
leaq 0x278(%rsp), %rdi
callq 0x3cca0
movq %rax, 0x38(%rsp)
jmp 0xba91
movq 0x38(%rsp), %rdi
xorl %esi, %esi
callq 0x3c270
movq %rax, 0x30(%rsp)
jmp 0xbaa4
movq 0x30(%rsp), %rdi
leaq 0x3af95(%rip), %rsi     # 0x46a45
callq 0x3cca0
movq %rax, 0x28(%rsp)
jmp 0xbabc
movq 0x28(%rsp), %rdi
callq 0x379f0
movl %eax, 0x24(%rsp)
jmp 0xbacc
movq 0x110(%rsp), %rdi
movl 0x24(%rsp), %eax
movl %eax, 0x340(%rsp)
leaq 0x320(%rsp), %rsi
movl $0x50, %edx
callq 0xa0e0
movl $0x1, 0x144(%rsp)
jmp 0xbb4a
movq 0x514cb(%rip), %rdi     # 0x5cfd0
leaq 0x3aa5d(%rip), %rsi     # 0x46569
callq 0xa5d0
movq %rax, 0x18(%rsp)
jmp 0xbb18
movq 0x18(%rsp), %rdi
movq 0x51494(%rip), %rsi     # 0x5cfb8
callq 0xaa80
jmp 0xbb2b
movq 0x110(%rsp), %rdi
movl $0x1, %esi
callq 0xecf0
jmp 0xbb3f
movl $0x1, 0x144(%rsp)
leaq 0x148(%rsp), %rdi
callq 0xac68
leaq 0x168(%rsp), %rdi
callq 0xed10
leaq 0x278(%rsp), %rdi
callq 0x3a5a0
jmp 0xbc00
leaq 0x278(%rsp), %rdi
callq 0x3a5a0
jmp 0xbc2a
movq 0x51441(%rip), %rdi     # 0x5cfd0
leaq 0x3a9f5(%rip), %rsi     # 0x4658b
callq 0xa5d0
movq %rax, 0x10(%rsp)
jmp 0xbba2
movq 0x10(%rsp), %rdi
leaq 0x300(%rsp), %rsi
callq 0xa330
movq %rax, 0x8(%rsp)
jmp 0xbbbb
movq 0x8(%rsp), %rdi
leaq 0x3a9d7(%rip), %rsi     # 0x4659e
callq 0xa5d0
movq %rax, (%rsp)
jmp 0xbbd2
movq (%rsp), %rdi
movq 0x513db(%rip), %rsi     # 0x5cfb8
callq 0xaa80
jmp 0xbbe4
movq 0x110(%rsp), %rdi
xorl %esi, %esi
callq 0xecf0
jmp 0xbbf5
movl $0x1, 0x144(%rsp)
leaq 0x2a0(%rsp), %rdi
callq 0xac68
leaq 0x300(%rsp), %rdi
callq 0xac68
movq 0x118(%rsp), %rax
addq $0x388, %rsp            # imm = 0x388
retq
leaq 0x2a0(%rsp), %rdi
callq 0xac68
leaq 0x300(%rsp), %rdi
callq 0xac68
movq 0x2d8(%rsp), %rdi
callq 0xa670
nopw %cs:(%rax,%rax)