// File: /workspace/github_cpp_makefile_star2_O3/HQarroum[P]thread-pool/examples/working-with-functors/main.cpp
// Function: main
int main() {
  // Producer and consumer thread pools.
  thread::pool::pool_t pool_of_consumers(5);

  // Counting the start time.
  auto start = std::chrono::high_resolution_clock::now();

  // Creating the callable.
  auto callable = thread::pool::bind(pool_of_consumers, static_void_function);

  // Scheduling the producers.
  for (size_t i = 0; i < work_to_spawn; ++i) {
    auto result = callable(i);
    assert(result.get() == (int) (i + 1));
  }
  
  // Waiting for the consumers to complete.
  while (count < work_to_spawn)
    std::this_thread::sleep_for(std::chrono::milliseconds(100));

  // Measuring and dumping the elapsed time.
  auto end = std::chrono::high_resolution_clock::now();
  std::chrono::duration<double, std::milli> diff = end - start;
  std::cout << "Elasped time : " << diff.count() << " ms" << std::endl;

  return (0);
}

// Assembly:
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x2f0, %rsp            # imm = 0x2F0
leaq 0x58(%rsp), %r14
movl $0x5, %esi
movq %r14, %rdi
callq 0x387e
callq 0x3050
movq %rax, %rbx
leaq 0x8(%rsp), %rsi
movq $0x0, 0x8(%rsi)
leaq -0x4a(%rip), %rax       # 0x360c
movq %rax, (%rsi)
leaq 0x1ab0(%rip), %rax      # 0x5110
movq %rax, 0x18(%rsi)
leaq 0x1aad(%rip), %rax      # 0x5118
movq %rax, 0x10(%rsi)
leaq 0x30(%rsp), %rdi
callq 0x513a
movq %r14, 0x50(%rsp)
movq 0x18(%rsp), %rax
testq %rax, %rax
je 0x3697
leaq 0x8(%rsp), %rdi
movq %rdi, %rsi
movl $0x3, %edx
callq *%rax
xorl %r13d, %r13d
leaq 0x8(%rsp), %r14
leaq 0x30(%rsp), %r15
leaq 0x28(%rsp), %r12
movq %r13, 0x28(%rsp)
movq 0x50(%rsp), %rsi
movq %r14, %rdi
movq %r15, %rdx
movq %r12, %rcx
callq 0x5198
movq %r14, %rdi
callq 0x3946
incq %r13
cmpl %eax, %r13d
jne 0x37ec
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x36e4
callq 0x3a0c
cmpq $0x3e8, %r13            # imm = 0x3E8
jne 0x36a9
movq 0x9b34(%rip), %rax      # 0xd228
cmpq $0x3e7, %rax            # imm = 0x3E7
ja 0x373c
leaq 0x8(%rsp), %r14
movq $0x0, 0x8(%rsp)
movq $0x5f5e100, 0x10(%rsp)  # imm = 0x5F5E100
movq %r14, %rdi
movq %r14, %rsi
callq 0x30b0
cmpl $-0x1, %eax
jne 0x372d
callq 0x3040
cmpl $0x4, (%rax)
je 0x3713
movq 0x9af4(%rip), %rax      # 0xd228
cmpq $0x3e8, %rax            # imm = 0x3E8
jb 0x3701
callq 0x3050
movq %rax, %r14
movq 0x986d(%rip), %rdi      # 0xcfb8
leaq 0x49a0(%rip), %rsi      # 0x80f2
movl $0xf, %edx
callq 0x32a0
subq %rbx, %r14
cvtsi2sd %r14, %xmm0
divsd 0x489c(%rip), %xmm0     # 0x8008
movq 0x9845(%rip), %rdi      # 0xcfb8
callq 0x3320
movq %rax, %rbx
leaq 0x4980(%rip), %rsi      # 0x8102
movl $0x3, %edx
movq %rax, %rdi
callq 0x32a0
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x3240
movsbl %al, %esi
movq %rbx, %rdi
callq 0x3030
movq %rax, %rdi
callq 0x3180
movq 0x40(%rsp), %rax
testq %rax, %rax
je 0x37cf
leaq 0x30(%rsp), %rdi
movq %rdi, %rsi
movl $0x3, %edx
callq *%rax
leaq 0x58(%rsp), %rdi
callq 0x3992
xorl %eax, %eax
addq $0x2f0, %rsp            # imm = 0x2F0
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq
leaq 0x48cd(%rip), %rdi      # 0x80c0
leaq 0x48e4(%rip), %rsi      # 0x80de
leaq 0x48e6(%rip), %rcx      # 0x80e7
movl $0x2a, %edx
callq 0x3160
jmp 0x3875
jmp 0x3875
movq %rax, %rbx
movq 0x18(%rsp), %rax
testq %rax, %rax
je 0x3863
leaq 0x8(%rsp), %rdi
movq %rdi, %rsi
movl $0x3, %edx
callq *%rax
jmp 0x3863
jmp 0x3875
jmp 0x3847
jmp 0x3847
movq %rax, %rbx
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x384a
callq 0x3a0c
jmp 0x384a
movq %rax, %rbx
movq 0x40(%rsp), %rax
testq %rax, %rax
je 0x3863
leaq 0x30(%rsp), %rdi
movq %rdi, %rsi
movl $0x3, %edx
callq *%rax
leaq 0x58(%rsp), %rdi
callq 0x3992
movq %rbx, %rdi
callq 0x33a0
movq %rax, %rdi
callq 0x3a7b
nop