// File: /workspace/github_cpp_makefile_star2_O3/deanturpin[P]curly/curly.cpp
// Function: main
int main() {
  // Construct a CryptoCompare URL: prepend the domain and append the
  // application ID
  const auto application_id = true;
  const auto cc = [&application_id](const std::string &url) {
    return curly("https://min-api.cryptocompare.com/" + url +
                 (application_id
                      ? "&extraParams=https://github.com/deanturpin/curly"
                      : ""));
  };

  // Read all exchange names from a text file
  const auto get_exchanges = []() {
    std::ifstream in("exchanges.txt");
    std::vector<std::string> e;
    std::string name;
    while (in >> name)
      e.push_back(name);

    return e;
  };

  // Report exchange count
  const std::vector<std::string> &stage1_exchanges = get_exchanges();
  std::cout << "# " << stage1_exchanges.size() << " exchanges\n";

  // Fetch prices for each currency
  for (const auto &from_symbol :
       std::vector<std::string>({"BTC", "ETH", "BCH", "LTC", "ETC"})) {
    const std::string to_symbol = "USD";

    // Fetch prices for each exchange
    std::vector<std::pair<double, std::string>> stage1_prices;
    for (const std::string &name : stage1_exchanges) {
      const std::string response = cc("data/price?fsym=" + from_symbol +
                                      "&tsyms=" + to_symbol + "&e=" + name);

      const double price =
          std::strtod(find_token(to_symbol, response).c_str(), NULL);

      // Only store non-zero prices
      if (price > 0.0)
        stage1_prices.push_back({price, name});
    }

    // Sort the prices before calculating the combinations
    std::sort(stage1_prices.begin(), stage1_prices.end());
    std::reverse(stage1_prices.begin(), stage1_prices.end());

    // Calculate average over all exchanges
    const auto average =
        (stage1_prices.empty()
             ? 0.0
             : std::accumulate(
                   stage1_prices.cbegin(), stage1_prices.cend(), 0.0,
                   [](double sum, const auto &p) { return sum += p.first; }) /
                   stage1_prices.size());

    // Print the combined prices
    if (!stage1_prices.empty()) {
      std::cout << std::fixed << std::setprecision(0);
      std::cout << "## " << from_symbol << "-" << to_symbol << " " << average
                << '\n';
      std::cout << "```\n";
      for (const auto &p : stage1_prices)
        std::cout << p.first << '\t' << p.second << '\n';
      std::cout << "```\n";
    }
  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x378, %rsp            # imm = 0x378
leaq 0x3302(%rip), %rsi      # 0x6105
leaq 0x170(%rsp), %rbx
movq %rbx, %rdi
movl $0x8, %edx
callq 0x22b0
xorl %eax, %eax
leaq 0xe0(%rsp), %r14
movq %rax, 0x10(%r14)
xorpd %xmm0, %xmm0
movapd %xmm0, (%r14)
leaq 0x28(%rsp), %rcx
movq %rcx, -0x10(%rcx)
movq %rax, -0x8(%rcx)
movb $0x0, (%rcx)
leaq 0x18(%rsp), %r15
movq %rbx, %rdi
movq %r15, %rsi
callq 0x21d0
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0x2e6a
movq %r14, %rdi
movq %r15, %rsi
callq 0x3ca6
jmp 0x2e44
movq 0x18(%rsp), %rdi
leaq 0x28(%rsp), %rax
cmpq %rax, %rdi
je 0x2e86
movq 0x28(%rsp), %rsi
incq %rsi
callq 0x2180
leaq 0x170(%rsp), %rdi
callq 0x2060
movq 0x613e(%rip), %rdi      # 0x8fd8
leaq 0x325a(%rip), %rsi      # 0x60fb
movl $0x2, %edx
callq 0x21a0
movq 0xe8(%rsp), %rsi
subq 0xe0(%rsp), %rsi
sarq $0x5, %rsi
movq 0x6112(%rip), %rdi      # 0x8fd8
callq 0x20e0
leaq 0x31e7(%rip), %rsi      # 0x60b9
movl $0xb, %edx
movq %rax, %rdi
callq 0x21a0
leaq 0x180(%rsp), %r15
movq %r15, -0x10(%r15)
leaq 0x31d3(%rip), %rsi      # 0x60c5
leaq 0x31cf(%rip), %rdx      # 0x60c8
leaq 0x170(%rsp), %r14
movq %r14, %rdi
callq 0x3fc4
leaq 0x190(%rsp), %r12
leaq 0x1a0(%rsp), %rax
movq %rax, -0x10(%rax)
leaq 0x31a5(%rip), %rsi      # 0x60c9
leaq 0x31a1(%rip), %rdx      # 0x60cc
movq %r12, %rdi
callq 0x3fc4
leaq 0x1b0(%rsp), %r12
leaq 0x1c0(%rsp), %rax
movq %rax, -0x10(%rax)
leaq 0x317f(%rip), %rsi      # 0x60cd
leaq 0x317b(%rip), %rdx      # 0x60d0
movq %r12, %rdi
callq 0x3fc4
leaq 0x1d0(%rsp), %r12
leaq 0x1e0(%rsp), %rax
movq %rax, -0x10(%rax)
leaq 0x3159(%rip), %rsi      # 0x60d1
leaq 0x3155(%rip), %rdx      # 0x60d4
movq %r12, %rdi
callq 0x3fc4
leaq 0x1f0(%rsp), %r12
leaq 0x200(%rsp), %rbx
movq %rbx, -0x10(%rbx)
leaq 0x3133(%rip), %rsi      # 0x60d5
leaq 0x312f(%rip), %rdx      # 0x60d8
movq %r12, %rdi
callq 0x3fc4
leaq 0x148(%rsp), %rdi
leaq 0x170(%rsp), %rsi
leaq 0x18(%rsp), %rcx
movl $0x5, %edx
callq 0x3b34
movq $-0xa0, %r14
movq -0x10(%rbx), %rdi
cmpq %rdi, %rbx
je 0x2feb
movq (%rbx), %rsi
incq %rsi
callq 0x2180
addq $-0x20, %rbx
addq $0x20, %r14
jne 0x2fd7
movq 0x148(%rsp), %r14
movq 0x150(%rsp), %rax
movq %rax, 0x100(%rsp)
cmpq %rax, %r14
je 0x36e2
leaq 0x170(%rsp), %r13
leaq 0xb0(%rsp), %rax
movq %rax, 0xa0(%rsp)
leaq 0xa0(%rsp), %rdi
leaq 0x309c(%rip), %rsi      # 0x60d9
leaq 0x3098(%rip), %rdx      # 0x60dc
callq 0x3fc4
xorpd %xmm0, %xmm0
movapd %xmm0, (%rsp)
movq $0x0, 0x10(%rsp)
movq 0xe0(%rsp), %rbx
movq 0xe8(%rsp), %r12
cmpq %r12, %rbx
je 0x34ca
leaq 0x128(%rsp), %rbp
movq %rbp, %rdi
leaq 0x3057(%rip), %rsi      # 0x60dd
movq %r14, %rdx
callq 0x39c1
movq %rbp, %rdi
leaq 0x3056(%rip), %rsi      # 0x60ee
callq 0x22d0
leaq 0x50(%rsp), %rsi
movq %rsi, 0x40(%rsp)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0x30c5
movq %rdx, 0x40(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x50(%rsp)
jmp 0x30cd
movupd (%rcx), %xmm0
movupd %xmm0, (%rsi)
movq 0x8(%rax), %rdx
movq %rdx, 0x48(%rsp)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
movq 0xa0(%rsp), %rsi
movq 0xa8(%rsp), %rdx
leaq 0x40(%rsp), %rdi
callq 0x2080
leaq 0x70(%rsp), %rsi
movq %rsi, 0x60(%rsp)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0x3127
movq %rdx, 0x60(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x70(%rsp)
jmp 0x312f
movupd (%rcx), %xmm0
movupd %xmm0, (%rsi)
movq 0x8(%rax), %rdx
movq %rdx, 0x68(%rsp)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
leaq 0x60(%rsp), %rdi
leaq 0x2fa3(%rip), %rsi      # 0x60f6
callq 0x22d0
leaq 0x90(%rsp), %rsi
movq %rsi, 0x80(%rsp)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0x318c
movq %rdx, 0x80(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x90(%rsp)
jmp 0x3194
movupd (%rcx), %xmm0
movupd %xmm0, (%rsi)
movq 0x8(%rax), %rdx
movq %rdx, 0x88(%rsp)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
movq (%rbx), %rsi
movq 0x8(%rbx), %rdx
leaq 0x80(%rsp), %rdi
callq 0x2080
leaq 0xd0(%rsp), %rsi
movq %rsi, 0xc0(%rsp)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0x31f7
movq %rdx, 0xc0(%rsp)
movq (%rcx), %rdx
movq %rdx, 0xd0(%rsp)
jmp 0x31ff
movupd (%rcx), %xmm0
movupd %xmm0, (%rsi)
leaq 0x18(%rsp), %rbp
movq 0x8(%rax), %rdx
movq %rdx, 0xc8(%rsp)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
movq %rbp, %rdi
leaq 0x2f04(%rip), %rsi      # 0x612d
leaq 0xc0(%rsp), %rdx
callq 0x39c1
movq %rbp, %rdi
leaq 0x2f10(%rip), %rsi      # 0x6150
callq 0x22d0
movq %r15, 0x170(%rsp)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0x3271
movq %rdx, 0x170(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x180(%rsp)
jmp 0x327a
movupd (%rcx), %xmm0
movupd %xmm0, (%r15)
movq 0x8(%rax), %rdx
movq %rdx, 0x178(%rsp)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
leaq 0x108(%rsp), %rdi
movq %r13, %rsi
movl $0x1, %edx
callq 0x24fc
movq 0x170(%rsp), %rdi
cmpq %r15, %rdi
je 0x32c7
movq 0x180(%rsp), %rsi
incq %rsi
callq 0x2180
movq 0x18(%rsp), %rdi
leaq 0x28(%rsp), %rax
cmpq %rax, %rdi
je 0x32e3
movq 0x28(%rsp), %rsi
incq %rsi
callq 0x2180
movq 0xc0(%rsp), %rdi
leaq 0xd0(%rsp), %rax
cmpq %rax, %rdi
je 0x3308
movq 0xd0(%rsp), %rsi
incq %rsi
callq 0x2180
movq 0x80(%rsp), %rdi
leaq 0x90(%rsp), %rax
cmpq %rax, %rdi
je 0x332d
movq 0x90(%rsp), %rsi
incq %rsi
callq 0x2180
movq 0x60(%rsp), %rdi
leaq 0x70(%rsp), %rax
cmpq %rax, %rdi
je 0x3349
movq 0x70(%rsp), %rsi
incq %rsi
callq 0x2180
movq 0x40(%rsp), %rdi
leaq 0x50(%rsp), %rax
cmpq %rax, %rdi
je 0x3365
movq 0x50(%rsp), %rsi
incq %rsi
callq 0x2180
movq 0x128(%rsp), %rdi
leaq 0x138(%rsp), %rax
cmpq %rax, %rdi
je 0x338a
movq 0x138(%rsp), %rsi
incq %rsi
callq 0x2180
movq %r13, %rdi
leaq 0xa0(%rsp), %rsi
leaq 0x108(%rsp), %rdx
callq 0x2c53
movq 0x170(%rsp), %rdi
xorl %esi, %esi
callq 0x2120
movq 0x170(%rsp), %rdi
cmpq %r15, %rdi
je 0x33da
movq 0x180(%rsp), %rsi
incq %rsi
movsd %xmm0, 0x38(%rsp)
callq 0x2180
movsd 0x38(%rsp), %xmm0
ucomisd 0x2c5e(%rip), %xmm0     # 0x6040
jbe 0x3444
movsd %xmm0, 0x170(%rsp)
leaq 0x188(%rsp), %rax
movq %rax, 0x178(%rsp)
movq (%rbx), %rsi
movq 0x8(%rbx), %rdx
addq %rsi, %rdx
leaq 0x178(%rsp), %rdi
callq 0x3f2e
movq %rsp, %rdi
movq %r13, %rsi
callq 0x42ce
movq 0x178(%rsp), %rdi
leaq 0x188(%rsp), %rax
cmpq %rax, %rdi
je 0x3444
movq 0x188(%rsp), %rsi
incq %rsi
callq 0x2180
movq 0x108(%rsp), %rdi
leaq 0x118(%rsp), %rax
cmpq %rax, %rdi
je 0x3469
movq 0x118(%rsp), %rsi
incq %rsi
callq 0x2180
addq $0x20, %rbx
cmpq %r12, %rbx
jne 0x3074
movq (%rsp), %r12
movq 0x8(%rsp), %rbx
cmpq %rbx, %r12
je 0x34cf
movq %rbx, %rax
subq %r12, %rax
sarq $0x3, %rax
movabsq $-0x3333333333333333, %rcx # imm = 0xCCCCCCCCCCCCCCCD
imulq %rcx, %rax
bsrq %rax, %rdx
xorl $0x3f, %edx
addl %edx, %edx
xorq $0x7e, %rdx
movq %r12, %rdi
movq %rbx, %rsi
callq 0x45ab
movq %r12, %rdi
movq %rbx, %rsi
callq 0x4688
movq (%rsp), %r12
movq 0x8(%rsp), %rbx
jmp 0x34cf
xorl %ebx, %ebx
xorl %r12d, %r12d
movq %r12, %rdi
movq %rbx, %rsi
callq 0x5077
movq (%rsp), %rcx
movq 0x8(%rsp), %rax
cmpq %rax, %rcx
je 0x36a3
xorpd %xmm0, %xmm0
movq %rcx, %rdx
addsd (%rdx), %xmm0
addq $0x28, %rdx
cmpq %rax, %rdx
jne 0x34f3
movsd %xmm0, 0x38(%rsp)
subq %rcx, %rax
sarq $0x3, %rax
movabsq $-0x3333333333333333, %rcx # imm = 0xCCCCCCCCCCCCCCCD
imulq %rcx, %rax
movq %rax, %xmm0
punpckldq 0x2ae8(%rip), %xmm0 # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1]
subpd 0x2af0(%rip), %xmm0     # 0x6020
movapd %xmm0, 0x160(%rsp)
movq 0x5a98(%rip), %rdi      # 0x8fd8
movq (%rdi), %rax
movq -0x18(%rax), %rcx
movl 0x18(%rdi,%rcx), %edx
movl $0xfffffefb, %esi       # imm = 0xFFFFFEFB
andl %esi, %edx
orl $0x4, %edx
movl %edx, 0x18(%rdi,%rcx)
movq -0x18(%rax), %rax
movq $0x0, 0x8(%rdi,%rax)
movl $0x3, %edx
leaq 0x2b88(%rip), %rsi      # 0x60fa
callq 0x21a0
movq (%r14), %rsi
movq 0x8(%r14), %rdx
movq 0x5a53(%rip), %rdi      # 0x8fd8
callq 0x21a0
movq %rax, %rbx
movl $0x1, %edx
movq %rax, %rdi
leaq 0x2b62(%rip), %rsi      # 0x60fe
callq 0x21a0
movq 0xa0(%rsp), %rsi
movq 0xa8(%rsp), %rdx
movq %rbx, %rdi
callq 0x21a0
movq %rax, %rbx
movl $0x1, %edx
movq %rax, %rdi
leaq 0x2b31(%rip), %rsi      # 0x60fc
callq 0x21a0
movapd 0x160(%rsp), %xmm0
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
addsd %xmm0, %xmm1
movsd 0x38(%rsp), %xmm0
divsd %xmm1, %xmm0
movq %rbx, %rdi
callq 0x2250
movb $0xa, 0x170(%rsp)
movl $0x1, %edx
movq %rax, %rdi
movq %r13, %rsi
callq 0x21a0
movl $0x4, %edx
movq 0x59bd(%rip), %rdi      # 0x8fd8
leaq 0x2ade(%rip), %rsi      # 0x6100
callq 0x21a0
movq (%rsp), %rbx
movq 0x8(%rsp), %r12
cmpq %r12, %rbx
je 0x368b
movsd (%rbx), %xmm0
movq 0x5998(%rip), %rdi      # 0x8fd8
callq 0x2250
movb $0x9, 0x170(%rsp)
movl $0x1, %edx
movq %rax, %rdi
movq %r13, %rsi
callq 0x21a0
movq 0x8(%rbx), %rsi
movq 0x10(%rbx), %rdx
movq %rax, %rdi
callq 0x21a0
movb $0xa, 0x170(%rsp)
movl $0x1, %edx
movq %rax, %rdi
movq %r13, %rsi
callq 0x21a0
addq $0x28, %rbx
jmp 0x3630
movl $0x4, %edx
movq 0x5941(%rip), %rdi      # 0x8fd8
leaq 0x2a62(%rip), %rsi      # 0x6100
callq 0x21a0
movq %rsp, %rdi
callq 0x3b7c
movq 0xa0(%rsp), %rdi
leaq 0xb0(%rsp), %rax
cmpq %rax, %rdi
je 0x36d0
movq 0xb0(%rsp), %rsi
incq %rsi
callq 0x2180
addq $0x20, %r14
cmpq 0x100(%rsp), %r14
jne 0x301e
leaq 0x148(%rsp), %rdi
callq 0x3bda
leaq 0xe0(%rsp), %rdi
callq 0x3bda
xorl %eax, %eax
addq $0x378, %rsp            # imm = 0x378
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
leaq 0x210(%rsp), %rdi
leaq 0x170(%rsp), %rsi
callq 0x232a
jmp 0x3962
jmp 0x3733
jmp 0x3733
jmp 0x3733
movq %rax, %rbx
addq $-0x10, %r12
movq -0x10(%r12), %rdi
cmpq %rdi, %r12
je 0x3750
movq (%r12), %rsi
incq %rsi
callq 0x2180
leaq -0x20(%r12), %rax
addq $-0x10, %r12
cmpq %r14, %r12
movq %rax, %r12
jne 0x373a
jmp 0x3962
jmp 0x3768
movq %rax, %rbx
jmp 0x3962
jmp 0x3925
movq %rax, %rbx
jmp 0x3955
movq %rax, %rbx
movq 0x18(%rsp), %rdi
leaq 0x28(%rsp), %rax
cmpq %rax, %rdi
je 0x379c
movq 0x28(%rsp), %rsi
incq %rsi
callq 0x2180
leaq 0xe0(%rsp), %rdi
callq 0x3bda
leaq 0x170(%rsp), %rdi
callq 0x2060
jmp 0x396f
jmp 0x3925
movq %rax, %rbx
jmp 0x37ed
movq %rax, %rbx
movq 0x178(%rsp), %rdi
leaq 0x188(%rsp), %rax
cmpq %rax, %rdi
je 0x37ed
movq 0x188(%rsp), %rsi
incq %rsi
callq 0x2180
movq 0x108(%rsp), %rdi
leaq 0x118(%rsp), %rax
cmpq %rax, %rdi
je 0x3928
movq 0x118(%rsp), %rsi
jmp 0x391b
movq %rax, %rbx
jmp 0x3859
movq %rax, %rbx
jmp 0x383d
movq %rax, %rbx
movq 0x170(%rsp), %rdi
cmpq %r15, %rdi
je 0x383d
movq 0x180(%rsp), %rsi
incq %rsi
callq 0x2180
movq 0x18(%rsp), %rdi
leaq 0x28(%rsp), %rax
cmpq %rax, %rdi
je 0x3859
movq 0x28(%rsp), %rsi
incq %rsi
callq 0x2180
movq 0xc0(%rsp), %rdi
leaq 0xd0(%rsp), %rax
cmpq %rax, %rdi
je 0x38a1
movq 0xd0(%rsp), %rsi
incq %rsi
callq 0x2180
jmp 0x38a1
movq %rax, %rbx
jmp 0x38fe
jmp 0x3925
movq %rax, %rbx
leaq 0x50(%rsp), %r14
jmp 0x38e7
movq %rax, %rbx
leaq 0x50(%rsp), %r14
jmp 0x38cb
movq %rax, %rbx
leaq 0x50(%rsp), %r14
leaq 0x90(%rsp), %rax
movq 0x80(%rsp), %rdi
cmpq %rax, %rdi
je 0x38cb
movq 0x90(%rsp), %rsi
incq %rsi
callq 0x2180
leaq 0x70(%rsp), %rax
movq 0x60(%rsp), %rdi
cmpq %rax, %rdi
je 0x38e7
movq 0x70(%rsp), %rsi
incq %rsi
callq 0x2180
movq 0x40(%rsp), %rdi
cmpq %r14, %rdi
je 0x38fe
movq 0x50(%rsp), %rsi
incq %rsi
callq 0x2180
movq 0x128(%rsp), %rdi
leaq 0x138(%rsp), %rax
cmpq %rax, %rdi
je 0x3928
movq 0x138(%rsp), %rsi
incq %rsi
callq 0x2180
jmp 0x3928
movq %rax, %rbx
movq %rsp, %rdi
callq 0x3b7c
movq 0xa0(%rsp), %rdi
leaq 0xb0(%rsp), %rax
cmpq %rax, %rdi
je 0x3955
movq 0xb0(%rsp), %rsi
incq %rsi
callq 0x2180
leaq 0x148(%rsp), %rdi
callq 0x3bda
leaq 0xe0(%rsp), %rdi
callq 0x3bda
movq %rbx, %rdi
callq 0x2290
nop