// File: /workspace/github_cpp_makefile_star2_O1/amukherj[P]concurrencyts/./future.h
// Function: concurrencyts::future<std::vector<std::iterator_traits<__gnu_cxx::__normal_iterator<concurrencyts::future<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>>*, std::vector<concurrencyts::future<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>>, std::allocator<concurrencyts::future<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>>>>>>::value_type, std::allocator<std::iterator_traits<__gnu_cxx::__normal_iterator<concurrencyts::future<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>>*, std::vector<concurrencyts::future<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>>, std::allocator<concurrencyts::future<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>>>>>>::value_type>>> concurrencyts::when_all<__gnu_cxx::__normal_iterator<concurrencyts::future<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>>*, std::vector<concurrencyts::future<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>>, std::allocator<concurrencyts::future<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>>>>>>(__gnu_cxx::__normal_iterator<concurrencyts::future<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>>*, std::vector<concurrencyts::future<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>>, std::allocator<concurrencyts::future<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>>>>>, __gnu_cxx::__normal_iterator<concurrencyts::future<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>>*, std::vector<concurrencyts::future<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>>, std::allocator<concurrencyts::future<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>>>>>)
auto when_all(InputIt begin, InputIt end)
  -> future<std::vector<typename std::iterator_traits<InputIt>::value_type>> {
  using ret_type = typename std::iterator_traits<InputIt>::value_type;
  promise<std::vector<ret_type>> prom;
  auto fut = prom.get_future();

  if (begin != end) {
    begin->wait();
    (begin + 1)->wait();
  }

  std::thread t([begin, end](promise<std::vector<ret_type>> prom) {
    try {
      std::vector<ret_type> result;
      begin->wait();
      (begin + 1)->wait();
      for (auto it = begin; it != end; ++it) {
        it->wait();
        result.emplace_back(std::move(*it));
      }
      prom.set(std::move(result));
      std::this_thread::sleep_for(std::chrono::seconds(5));
    } catch(std::exception& e) {
      prom.set_exception(e);
    }
  }, std::move(prom));
  t.detach();

  return fut;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rdx, %r14
movq %rsi, %r15
movq %rdi, %rbx
xorl %eax, %eax
leaq 0x8(%rsp), %r12
movq %rax, (%r12)
movl $0x98, %edi
callq 0x31a0
movq %rax, %r13
movabsq $0x100000001, %rax      # imm = 0x100000001
movq %rax, 0x8(%r13)
leaq 0x87ef(%rip), %rax      # 0xec40
movq %rax, (%r13)
leaq 0x10(%r13), %rbp
movq %rbp, %rdi
callq 0x3200
xorl %eax, %eax
movq %rax, 0x60(%r13)
xorps %xmm0, %xmm0
movups %xmm0, 0x50(%r13)
movups %xmm0, 0x40(%r13)
movw $0x0, 0x80(%r13)
movups %xmm0, 0x88(%r13)
movq %r13, 0x8(%r12)
movq %rbp, (%r12)
movq %rbx, %rdi
movq %r12, %rsi
callq 0x7236
cmpq %r14, %r15
je 0x64b0
movq (%r15), %rdi
callq 0x73f8
movq 0x10(%r15), %rdi
callq 0x73f8
leaq 0x18(%rsp), %rsi
movq %r15, (%rsi)
movq %r14, 0x8(%rsi)
movq %rsp, %rdi
leaq 0x8(%rsp), %rdx
callq 0x728e
movq %rsp, %rdi
callq 0x3270
cmpq $0x0, (%rsp)
jne 0x6504
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x64e7
callq 0x6854
movq %rbx, %rax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x6509
jmp 0x6509
cmpq $0x0, (%rsp)
je 0x6509
callq 0x3050
movq %rax, %r14
movq 0x8(%rbx), %rdi
testq %rdi, %rdi
je 0x651f
callq 0x6854
jmp 0x651f
movq %rax, %r14
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x652e
callq 0x6854
movq %r14, %rdi
callq 0x3280