// File: jliesch[P]ofxget/ofxhome.cc
// Function: ofxget::ValidateApiKey(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&)
bool ValidateApiKey(const string& api_key) {
    CURL *curl = curl_easy_init();
    if (! curl) {
      throw string("Could not initialize curl");
    }

    char *api_key_output = curl_easy_escape(curl, api_key.c_str(), api_key.size());
    string output = string("api_key=") + api_key_output;
    string response;
#ifdef OFXHOME_DEBUG
    curl_easy_setopt(curl, CURLOPT_URL, "http://localhost/ofxhome/index.php/api/checkApiKey");
#else
    curl_easy_setopt(curl, CURLOPT_URL, "http://www.ofxhome.com/beta/index.php/api/checkApiKey");
#endif
    curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, CurlWriteToString);
    curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void *)&response);
    curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE_LARGE, (long) output.size());
    curl_easy_setopt(curl, CURLOPT_POSTFIELDS, output.c_str());

    CURLcode res = curl_easy_perform(curl);
    if (res != CURLE_OK) {
        throw "Curl error: " + std::to_string(res);
    }

    curl_free(api_key_output);
    curl_easy_cleanup(curl);

    return response == "success";
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x120, %rsp            # imm = 0x120
movq %rdi, -0x8(%rbp)
callq 0x7920
movq %rax, -0x10(%rbp)
cmpq $0x0, -0x10(%rbp)
jne 0x1054c
movb $0x1, -0x25(%rbp)
movl $0x20, %edi
callq 0x7380
movq %rax, -0xd8(%rbp)
movq %rax, -0xe0(%rbp)
leaq -0x11(%rbp), %rdi
movq %rdi, -0xd0(%rbp)
callq 0x78f0
movq -0xd8(%rbp), %rdi
movq -0xd0(%rbp), %rdx
leaq 0x58c63(%rip), %rsi     # 0x69157
callq 0x77b0
jmp 0x104fb
movq -0xe0(%rbp), %rdi
movb $0x0, -0x25(%rbp)
leaq 0x84073(%rip), %rsi     # 0x94580
movq 0x84a8c(%rip), %rdx     # 0x94fa0
callq 0x75e0
jmp 0x10814
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
leaq -0x11(%rbp), %rdi
callq 0x7b70
testb $0x1, -0x25(%rbp)
jne 0x1053b
jmp 0x10547
movq -0xe0(%rbp), %rdi
callq 0x7840
jmp 0x1080b
movq -0x10(%rbp), %rax
movq %rax, -0xf8(%rbp)
movq -0x8(%rbp), %rdi
callq 0x7100
movq %rax, -0xf0(%rbp)
movq -0x8(%rbp), %rdi
callq 0x7290
movq -0xf8(%rbp), %rdi
movq -0xf0(%rbp), %rsi
movl %eax, %edx
callq 0x76d0
movq %rax, -0x30(%rbp)
leaq -0x71(%rbp), %rdi
movq %rdi, -0xe8(%rbp)
callq 0x78f0
movq -0xe8(%rbp), %rdx
leaq 0x59099(%rip), %rsi     # 0x69640
leaq -0x70(%rbp), %rdi
callq 0x77b0
jmp 0x105b2
movq -0x30(%rbp), %rdx
leaq -0x50(%rbp), %rdi
leaq -0x70(%rbp), %rsi
callq 0x10d70
jmp 0x105c5
leaq -0x70(%rbp), %rdi
callq 0x7b88
leaq -0x71(%rbp), %rdi
callq 0x7b70
leaq -0x98(%rbp), %rdi
callq 0x7320
movq -0x10(%rbp), %rdi
leaq 0x590a7(%rip), %rdx     # 0x69695
xorl %eax, %eax
movl $0x2712, %esi           # imm = 0x2712
callq 0x7820
jmp 0x105fc
movq -0x10(%rbp), %rdi
leaq -0x17b7(%rip), %rdx     # 0xee50
xorl %eax, %eax
movl $0x4e2b, %esi           # imm = 0x4E2B
callq 0x7820
jmp 0x10615
movq -0x10(%rbp), %rdi
xorl %eax, %eax
movl $0x2711, %esi           # imm = 0x2711
leaq -0x98(%rbp), %rdx
callq 0x7820
jmp 0x1062e
movq -0x10(%rbp), %rax
movq %rax, -0x100(%rbp)
leaq -0x50(%rbp), %rdi
callq 0x7290
movq -0x100(%rbp), %rdi
movq %rax, %rdx
xorl %eax, %eax
movl $0x75a8, %esi           # imm = 0x75A8
callq 0x7820
jmp 0x1065a
movq -0x10(%rbp), %rax
movq %rax, -0x108(%rbp)
leaq -0x50(%rbp), %rdi
callq 0x7100
movq -0x108(%rbp), %rdi
movq %rax, %rdx
xorl %eax, %eax
movl $0x271f, %esi           # imm = 0x271F
callq 0x7820
jmp 0x10686
movq -0x10(%rbp), %rdi
callq 0x7670
movl %eax, -0x10c(%rbp)
jmp 0x10697
movl -0x10c(%rbp), %eax
movl %eax, -0x9c(%rbp)
cmpl $0x0, -0x9c(%rbp)
je 0x1079f
movb $0x1, -0xc1(%rbp)
movl $0x20, %edi
callq 0x7380
movq %rax, -0x118(%rbp)
movl -0x9c(%rbp), %esi
leaq -0xc0(%rbp), %rdi
callq 0xb000
jmp 0x106dc
movq -0x118(%rbp), %rdi
leaq 0x58ac6(%rip), %rsi     # 0x691b0
leaq -0xc0(%rbp), %rdx
callq 0xb580
jmp 0x106f8
movq -0x118(%rbp), %rdi
movb $0x0, -0xc1(%rbp)
leaq 0x83e73(%rip), %rsi     # 0x94580
movq 0x8488c(%rip), %rdx     # 0x94fa0
callq 0x75e0
jmp 0x10814
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
jmp 0x10741
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
leaq -0x70(%rbp), %rdi
callq 0x7b88
leaq -0x71(%rbp), %rdi
callq 0x7b70
jmp 0x1080b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
jmp 0x107f6
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
jmp 0x10786
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
leaq -0xc0(%rbp), %rdi
callq 0x7b88
testb $0x1, -0xc1(%rbp)
jne 0x10791
jmp 0x1079d
movq -0x118(%rbp), %rdi
callq 0x7840
jmp 0x107f6
movq -0x30(%rbp), %rdi
callq 0x7030
jmp 0x107aa
movq -0x10(%rbp), %rdi
callq 0x7120
jmp 0x107b5
leaq 0x58f0f(%rip), %rsi     # 0x696cb
leaq -0x98(%rbp), %rdi
callq 0x10dc0
movb %al, -0x119(%rbp)
jmp 0x107d0
leaq -0x98(%rbp), %rdi
callq 0x7b88
leaq -0x50(%rbp), %rdi
callq 0x7b88
movb -0x119(%rbp), %al
andb $0x1, %al
addq $0x120, %rsp            # imm = 0x120
popq %rbp
retq
leaq -0x98(%rbp), %rdi
callq 0x7b88
leaq -0x50(%rbp), %rdi
callq 0x7b88
movq -0x20(%rbp), %rdi
callq 0x7600
nopw %cs:(%rax,%rax)
nop