// File: jliesch[P]ofxget/ofxget_main.cc
// Function: main
int main(int argc, char** argv) {
  CmdArgStr request_filename('r', "request", "request_file", "Request file name under the requests directory. See investment.txt for an example.");
  CmdArgStr passwords_filename('r', "passwords", "passwords_file", "Optional passwords file. If used, supplies passwords for an institution. See example_passwords.txt. Storing passwords in plain text is not safe. This file should only be used for testing purposes.", CmdArg::isOPT);
  CmdArgInt institution('i', "institution", "institution_id", "Institution id. Chooses which institution to read from institutions.txt.");
  CmdLine cmd(argv[0], &request_filename, &institution, &passwords_filename, nullptr);
  cmd.parse(argc, argv);

  OfxGetContext ofxget;
  string request_template = ofxget.GetRequestTemplate("requests/" + string(request_filename));
  ofxget.AddApp("QuickBooks_2008").AddInstitution(institution)
      .AddRequestTemplate(request_template);
  if (passwords_filename.isFound()) {
    ofxget.AddPasswordsForTest(institution, passwords_filename);
  } else {
    ofxget.AddPasswordsForTest(institution, "passwords.txt");
  }

  vector<string> missing_vars = GetMissingRequestVars(request_template,
                                                      ofxget.vars_map_);
  if (!missing_vars.empty()) {
    cout << "Enter missing account info:" << endl;
  }
  for (const string& missing_var : missing_vars) {
    cout << missing_var << ": " << flush;
    string value;
    cin >> value;
    ofxget.vars_map_[missing_var] = value;
  }

  ofxget.PostRequest();
  if (ofxget.is_error()) {
    cout << "ERROR" << ofxget.error_string() << endl;
  } else {
    cout << "REQUEST" << endl << ofxget.request() << endl;
    cout << "RESPONSE" << endl << endl << ofxget.response() << endl;
  }

  return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x370, %rsp            # imm = 0x370
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rsp, %rax
movq $0x0, (%rax)
leaq 0x1e59(%rip), %rdx      # 0x6a643
leaq 0x7b0f(%rip), %rcx      # 0x70300
leaq 0x7b15(%rip), %r8       # 0x7030d
leaq -0x48(%rbp), %rdi
movl $0x72, %esi
movl %esi, -0x28c(%rbp)
movl $0xa, %r9d
callq 0x3bbe0
movl -0x28c(%rbp), %esi
movq %rsp, %rax
movq $0x0, (%rax)
leaq 0x7b37(%rip), %rdx      # 0x70360
leaq 0x7b3a(%rip), %rcx      # 0x7036a
leaq 0x7b42(%rip), %r8       # 0x70379
leaq -0x80(%rbp), %rdi
movl $0x1, %r9d
callq 0x3bbe0
jmp 0x68848
movq %rsp, %rax
movl $0x0, (%rax)
leaq 0x185f(%rip), %rdx      # 0x6a0b7
leaq 0x7bdf(%rip), %rcx      # 0x7043e
leaq 0x7be7(%rip), %r8       # 0x7044d
leaq -0xc8(%rbp), %rdi
movl $0x69, %esi
movl $0xa, %r9d
callq 0x3b6d0
jmp 0x6887f
movq -0x10(%rbp), %rax
movq (%rax), %rsi
xorl %eax, %eax
movl %eax, %r9d
leaq -0xf0(%rbp), %rdi
leaq -0x48(%rbp), %rdx
leaq -0xc8(%rbp), %rcx
leaq -0x80(%rbp), %r8
callq 0x3f630
jmp 0x688a8
movl -0x8(%rbp), %esi
movq -0x10(%rbp), %rdx
leaq -0xf0(%rbp), %rdi
callq 0x3fb20
jmp 0x688bd
leaq -0x180(%rbp), %rdi
callq 0x8a00
jmp 0x688cb
leaq -0x48(%rbp), %rdi
callq 0x3bd70
movq %rax, -0x298(%rbp)
jmp 0x688dd
leaq -0x1e1(%rbp), %rdi
movq %rdi, -0x2a0(%rbp)
callq 0x7900
movq -0x298(%rbp), %rsi
movq -0x2a0(%rbp), %rdx
leaq -0x1e0(%rbp), %rdi
callq 0x77c0
jmp 0x6890c
leaq 0x7b83(%rip), %rsi      # 0x70496
leaq -0x1c0(%rbp), %rdi
leaq -0x1e0(%rbp), %rdx
callq 0xb590
jmp 0x68928
leaq -0x1a0(%rbp), %rdi
leaq -0x180(%rbp), %rsi
leaq -0x1c0(%rbp), %rdx
callq 0x9a50
jmp 0x68944
leaq -0x1c0(%rbp), %rdi
callq 0x7b98
leaq -0x1e0(%rbp), %rdi
callq 0x7b98
leaq -0x1e1(%rbp), %rdi
callq 0x7b80
leaq -0x209(%rbp), %rdi
movq %rdi, -0x2a8(%rbp)
callq 0x7900
movq -0x2a8(%rbp), %rdx
leaq 0x16de(%rip), %rsi      # 0x6a067
leaq -0x208(%rbp), %rdi
callq 0x77c0
jmp 0x68997
leaq -0x180(%rbp), %rdi
leaq -0x208(%rbp), %rsi
callq 0x8b90
movq %rax, -0x2b0(%rbp)
jmp 0x689b3
leaq -0xc8(%rbp), %rdi
callq 0x3b870
movl %eax, -0x2b4(%rbp)
jmp 0x689c7
movl -0x2b4(%rbp), %esi
movq -0x2b0(%rbp), %rdi
callq 0x8e80
movq %rax, -0x2c0(%rbp)
jmp 0x689e2
movq -0x2c0(%rbp), %rdi
leaq -0x1a0(%rbp), %rsi
callq 0x9d30
jmp 0x689f7
leaq -0x208(%rbp), %rdi
callq 0x7b98
leaq -0x209(%rbp), %rdi
callq 0x7b80
leaq -0x80(%rbp), %rdi
callq 0x3b610
movb %al, -0x2c1(%rbp)
jmp 0x68a20
movb -0x2c1(%rbp), %al
testb $0x1, %al
jne 0x68a2f
jmp 0x68ba5
leaq -0xc8(%rbp), %rdi
callq 0x3b870
movl %eax, -0x2c8(%rbp)
jmp 0x68a43
leaq -0x80(%rbp), %rdi
callq 0x3bd70
movq %rax, -0x2d0(%rbp)
jmp 0x68a55
movq -0x2d0(%rbp), %rdx
movl -0x2c8(%rbp), %esi
leaq -0x180(%rbp), %rdi
callq 0x96c0
jmp 0x68a70
jmp 0x68bd6
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x88(%rbp)
movl %eax, -0x8c(%rbp)
jmp 0x69016
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x88(%rbp)
movl %eax, -0x8c(%rbp)
jmp 0x6900d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x88(%rbp)
movl %eax, -0x8c(%rbp)
jmp 0x69001
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x88(%rbp)
movl %eax, -0x8c(%rbp)
jmp 0x68ff5
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x88(%rbp)
movl %eax, -0x8c(%rbp)
jmp 0x68fe9
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x88(%rbp)
movl %eax, -0x8c(%rbp)
jmp 0x68b3a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x88(%rbp)
movl %eax, -0x8c(%rbp)
jmp 0x68b2e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x88(%rbp)
movl %eax, -0x8c(%rbp)
leaq -0x1c0(%rbp), %rdi
callq 0x7b98
leaq -0x1e0(%rbp), %rdi
callq 0x7b98
leaq -0x1e1(%rbp), %rdi
callq 0x7b80
jmp 0x68fe9
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x88(%rbp)
movl %eax, -0x8c(%rbp)
jmp 0x68b7d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x88(%rbp)
movl %eax, -0x8c(%rbp)
leaq -0x208(%rbp), %rdi
callq 0x7b98
leaq -0x209(%rbp), %rdi
callq 0x7b80
jmp 0x68fdd
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x88(%rbp)
movl %eax, -0x8c(%rbp)
jmp 0x68fdd
leaq -0xc8(%rbp), %rdi
callq 0x3b870
movl %eax, -0x2d4(%rbp)
jmp 0x68bb9
movl -0x2d4(%rbp), %esi
leaq 0x78da(%rip), %rdx      # 0x704a0
leaq -0x180(%rbp), %rdi
callq 0x96c0
jmp 0x68bd4
jmp 0x68bd6
leaq -0x228(%rbp), %rdi
leaq -0x1a0(%rbp), %rsi
leaq -0x180(%rbp), %rdx
callq 0xa8c0
jmp 0x68bf2
leaq -0x228(%rbp), %rdi
callq 0x69030
testb $0x1, %al
jne 0x68c4c
movq 0x2d36f(%rip), %rdi     # 0x95f78
leaq 0x789e(%rip), %rsi      # 0x704ae
callq 0x7590
movq %rax, -0x2e0(%rbp)
jmp 0x68c1e
movq -0x2e0(%rbp), %rdi
movq 0x2d39c(%rip), %rsi     # 0x95fc8
callq 0x7980
jmp 0x68c33
jmp 0x68c4c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x88(%rbp)
movl %eax, -0x8c(%rbp)
jmp 0x68fd1
leaq -0x228(%rbp), %rax
movq %rax, -0x230(%rbp)
movq -0x230(%rbp), %rdi
callq 0xb1f0
movq %rax, -0x238(%rbp)
movq -0x230(%rbp), %rdi
callq 0xb220
movq %rax, -0x240(%rbp)
leaq -0x238(%rbp), %rdi
leaq -0x240(%rbp), %rsi
callq 0xb250
testb $0x1, %al
jne 0x68c9c
jmp 0x68d95
leaq -0x238(%rbp), %rdi
callq 0xb290
movq %rax, -0x248(%rbp)
movq -0x248(%rbp), %rsi
movq 0x2d2bb(%rip), %rdi     # 0x95f78
callq 0x72a0
movq %rax, -0x2e8(%rbp)
jmp 0x68ccb
movq -0x2e8(%rbp), %rdi
leaq 0x183c(%rip), %rsi      # 0x6a515
callq 0x7590
movq %rax, -0x2f0(%rbp)
jmp 0x68ce7
movq -0x2f0(%rbp), %rdi
movq 0x2d28b(%rip), %rsi     # 0x95f80
callq 0x7980
jmp 0x68cfc
leaq -0x268(%rbp), %rdi
movq %rdi, -0x2f8(%rbp)
callq 0x7320
movq -0x2f8(%rbp), %rsi
movq 0x2d29b(%rip), %rdi     # 0x95fb8
callq 0x7410
jmp 0x68d24
movq -0x248(%rbp), %rsi
leaq -0x180(%rbp), %rdi
callq 0xb2b0
movq %rax, -0x300(%rbp)
jmp 0x68d40
movq -0x300(%rbp), %rdi
leaq -0x268(%rbp), %rsi
callq 0x7af0
jmp 0x68d55
leaq -0x268(%rbp), %rdi
callq 0x7b98
leaq -0x238(%rbp), %rdi
callq 0xb390
jmp 0x68c80
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x88(%rbp)
movl %eax, -0x8c(%rbp)
leaq -0x268(%rbp), %rdi
callq 0x7b98
jmp 0x68fd1
leaq -0x180(%rbp), %rdi
callq 0xa110
jmp 0x68da3
leaq -0x180(%rbp), %rdi
callq 0xad10
movb %al, -0x301(%rbp)
jmp 0x68db7
movb -0x301(%rbp), %al
testb $0x1, %al
jne 0x68dc3
jmp 0x68e2a
movq 0x2d1ae(%rip), %rdi     # 0x95f78
leaq 0x76f9(%rip), %rsi      # 0x704ca
callq 0x7590
movq %rax, -0x310(%rbp)
jmp 0x68ddf
leaq -0x180(%rbp), %rdi
callq 0x69070
movq %rax, -0x318(%rbp)
jmp 0x68df4
movq -0x318(%rbp), %rsi
movq -0x310(%rbp), %rdi
callq 0x72a0
movq %rax, -0x320(%rbp)
jmp 0x68e10
movq -0x320(%rbp), %rdi
movq 0x2d1aa(%rip), %rsi     # 0x95fc8
callq 0x7980
jmp 0x68e25
jmp 0x68f70
movq 0x2d147(%rip), %rdi     # 0x95f78
leaq 0x7698(%rip), %rsi      # 0x704d0
callq 0x7590
movq %rax, -0x328(%rbp)
jmp 0x68e46
movq -0x328(%rbp), %rdi
movq 0x2d174(%rip), %rsi     # 0x95fc8
callq 0x7980
movq %rax, -0x330(%rbp)
jmp 0x68e62
leaq -0x288(%rbp), %rdi
leaq -0x180(%rbp), %rsi
callq 0x9d80
jmp 0x68e77
movq -0x330(%rbp), %rdi
leaq -0x288(%rbp), %rsi
callq 0x72a0
movq %rax, -0x338(%rbp)
jmp 0x68e93
movq -0x338(%rbp), %rdi
movq 0x2d127(%rip), %rsi     # 0x95fc8
callq 0x7980
jmp 0x68ea8
leaq -0x288(%rbp), %rdi
callq 0x7b98
movq 0x2d0bd(%rip), %rdi     # 0x95f78
leaq 0x7616(%rip), %rsi      # 0x704d8
callq 0x7590
movq %rax, -0x340(%rbp)
jmp 0x68ed0
movq -0x340(%rbp), %rdi
movq 0x2d0ea(%rip), %rsi     # 0x95fc8
callq 0x7980
movq %rax, -0x348(%rbp)
jmp 0x68eec
movq -0x348(%rbp), %rdi
movq 0x2d0ce(%rip), %rsi     # 0x95fc8
callq 0x7980
movq %rax, -0x350(%rbp)
jmp 0x68f08
leaq -0x180(%rbp), %rdi
callq 0x69090
movq %rax, -0x358(%rbp)
jmp 0x68f1d
movq -0x358(%rbp), %rsi
movq -0x350(%rbp), %rdi
callq 0x72a0
movq %rax, -0x360(%rbp)
jmp 0x68f39
movq -0x360(%rbp), %rdi
movq 0x2d081(%rip), %rsi     # 0x95fc8
callq 0x7980
jmp 0x68f4e
jmp 0x68f70
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x88(%rbp)
movl %eax, -0x8c(%rbp)
leaq -0x288(%rbp), %rdi
callq 0x7b98
jmp 0x68fd1
movl $0x0, -0x4(%rbp)
leaq -0x228(%rbp), %rdi
callq 0xb3b0
leaq -0x1a0(%rbp), %rdi
callq 0x7b98
leaq -0x180(%rbp), %rdi
callq 0x690b0
leaq -0xf0(%rbp), %rdi
callq 0x69100
leaq -0xc8(%rbp), %rdi
callq 0x3b740
leaq -0x80(%rbp), %rdi
callq 0x3bc50
leaq -0x48(%rbp), %rdi
callq 0x3bc50
movl -0x4(%rbp), %eax
addq $0x370, %rsp            # imm = 0x370
popq %rbp
retq
leaq -0x228(%rbp), %rdi
callq 0xb3b0
leaq -0x1a0(%rbp), %rdi
callq 0x7b98
leaq -0x180(%rbp), %rdi
callq 0x690b0
leaq -0xf0(%rbp), %rdi
callq 0x69100
leaq -0xc8(%rbp), %rdi
callq 0x3b740
leaq -0x80(%rbp), %rdi
callq 0x3bc50
leaq -0x48(%rbp), %rdi
callq 0x3bc50
movq -0x88(%rbp), %rdi
callq 0x7610
nopl (%rax,%rax)