// File: /workspace/github_cpp_makefile_star2_O2/amukherj[P]concurrencyts/barrier.cc
// Function: main
int main() {
  std::experimental::flex_barrier barrier(7, []() ->int {
    std::cout << "All threads done\n";
    return -1;
  });

  for (int i = 0; i < 10; ++i) {
    std::thread thr([&, i]() {
      std::this_thread::sleep_for(std::chrono::seconds(5));
      barrier.arrive_and_wait();
      std::cout << "Thread " << i << " done\n";
    });
    thr.detach();
  }

  std::thread thr1([&]() {
    barrier.arrive_and_wait();
    std::cout << "Thread 6 done\n";
  });
  thr1.join();

  for (int i = 0; i < 9; ++i) {
    std::thread thr([&, i]() {
      std::this_thread::sleep_for(std::chrono::seconds(5));
      barrier.arrive_and_wait();
      std::cout << "Thread " << i << " done\n";
    });
    thr.detach();
  }
  barrier.arrive_and_wait();
  std::this_thread::sleep_for(std::chrono::seconds(5));
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xc8, %rsp
leaq 0x20(%rsp), %rbx
pushq $0x7
popq %rsi
movq %rbx, %rdi
callq 0x271e
leaq 0x1d8(%rip), %rax       # 0x24bc
movq %rax, 0xa0(%rbx)
xorl %r13d, %r13d
pushq $0x18
popq %r14
leaq 0x2a0f(%rip), %rbp      # 0x4d08
leaq 0x10(%rsp), %r15
leaq 0x8(%rsp), %r12
cmpl $0xa, %r13d
je 0x2359
andq $0x0, 0x10(%rsp)
movq %r14, %rdi
callq 0x20e0
movq %rbp, (%rax)
movl %r13d, 0x8(%rax)
movq %rbx, 0x10(%rax)
movq %rax, 0x8(%rsp)
movq %r15, %rdi
movq %r12, %rsi
xorl %edx, %edx
callq 0x20c0
movq 0x8(%rsp), %rdi
testq %rdi, %rdi
je 0x2344
movq (%rdi), %rax
callq *0x8(%rax)
movq %r15, %rdi
callq 0x2160
movq %r15, %rdi
callq 0x25e2
incl %r13d
jmp 0x2303
andq $0x0, 0x10(%rsp)
pushq $0x10
popq %rdi
callq 0x20e0
leaq 0x29da(%rip), %rcx      # 0x4d48
movq %rcx, (%rax)
movq %rbx, 0x8(%rax)
leaq 0x8(%rsp), %rsi
movq %rax, (%rsi)
leaq 0x10(%rsp), %rdi
xorl %edx, %edx
callq 0x20c0
movq 0x8(%rsp), %rdi
testq %rdi, %rdi
je 0x2399
movq (%rdi), %rax
callq *0x8(%rax)
leaq 0x10(%rsp), %rdi
callq 0x2140
xorl %r13d, %r13d
pushq $0x18
popq %r14
leaq 0x29d7(%rip), %rbp      # 0x4d88
leaq 0x18(%rsp), %r15
leaq 0x8(%rsp), %r12
cmpl $0x9, %r13d
je 0x2411
andq $0x0, 0x18(%rsp)
movq %r14, %rdi
callq 0x20e0
movq %rbp, (%rax)
movl %r13d, 0x8(%rax)
movq %rbx, 0x10(%rax)
movq %rax, 0x8(%rsp)
movq %r15, %rdi
movq %r12, %rsi
xorl %edx, %edx
callq 0x20c0
movq 0x8(%rsp), %rdi
testq %rdi, %rdi
je 0x23fc
movq (%rdi), %rax
callq *0x8(%rax)
movq %r15, %rdi
callq 0x2160
movq %r15, %rdi
callq 0x25e2
incl %r13d
jmp 0x23bb
leaq 0x20(%rsp), %rdi
callq 0x25f0
leaq 0x8(%rsp), %rdi
movq $0x5, (%rdi)
callq 0x26cb
leaq 0x10(%rsp), %rdi
callq 0x25e2
leaq 0x20(%rsp), %rdi
callq 0x2704
xorl %eax, %eax
addq $0xc8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x249c
jmp 0x2487
jmp 0x2482
jmp 0x249c
jmp 0x249c
movq %rax, %rbx
movq 0x8(%rsp), %rdi
testq %rdi, %rdi
je 0x249f
movq (%rdi), %rax
callq *0x8(%rax)
jmp 0x249f
movq %rax, %rbx
leaq 0x18(%rsp), %rdi
callq 0x25e2
jmp 0x249f
movq %rax, %rbx
jmp 0x24a9
movq %rax, %rbx
movq 0x8(%rsp), %rdi
testq %rdi, %rdi
je 0x24a9
movq (%rdi), %rax
callq *0x8(%rax)
jmp 0x24a9
movq %rax, %rbx
leaq 0x10(%rsp), %rdi
callq 0x25e2
leaq 0x20(%rsp), %rdi
callq 0x2704
movq %rbx, %rdi
callq 0x2170
nop