// File: /workspace/github_cpp_makefile_star2_O3/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 %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x30, %rsp
movq %rdx, %r14
movq %rsi, %r15
movq %rdi, %rbx
movl $0x98, %edi
callq 0x31a0
movq %rax, %r12
movabsq $0x100000001, %rax      # imm = 0x100000001
movq %rax, 0x8(%r12)
leaq 0x7983(%rip), %rax      # 0xdc40
movq %rax, (%r12)
leaq 0x10(%r12), %r13
movq %r13, %rdi
callq 0x3200
xorps %xmm0, %xmm0
movups %xmm0, 0x50(%r12)
movups %xmm0, 0x40(%r12)
movq $0x0, 0x60(%r12)
movw $0x0, 0x80(%r12)
movups %xmm0, 0x88(%r12)
leaq 0x10(%rsp), %rsi
movq %r12, 0x8(%rsi)
movq %r13, (%rsi)
movq %rbx, %rdi
callq 0x7084
cmpq %r14, %r15
je 0x6324
movq (%r15), %rdi
callq 0x7224
movq 0x10(%r15), %rdi
callq 0x7224
leaq 0x20(%rsp), %rsi
movq %r15, (%rsi)
movq %r14, 0x8(%rsi)
leaq 0x8(%rsp), %rdi
leaq 0x10(%rsp), %rdx
callq 0x70dc
leaq 0x8(%rsp), %rdi
callq 0x3270
cmpq $0x0, 0x8(%rsp)
jne 0x637d
movq 0x18(%rsp), %rdi
testq %rdi, %rdi
je 0x6360
callq 0x66d0
movq %rbx, %rax
addq $0x30, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq
jmp 0x6382
jmp 0x6382
cmpq $0x0, 0x8(%rsp)
je 0x6382
callq 0x3050
movq %rax, %r14
movq 0x8(%rbx), %rdi
testq %rdi, %rdi
je 0x6398
callq 0x66d0
jmp 0x6398
movq %rax, %r14
movq 0x18(%rsp), %rdi
testq %rdi, %rdi
je 0x63a7
callq 0x66d0
movq %r14, %rdi
callq 0x3280
nop