// File: /workspace/github_cpp_makefile_star2_O1/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
movl $0x7, %r14d
leaq 0x50(%rsp), %rbx
movq %r14, -0x30(%rbx)
xorps %xmm0, %xmm0
movups %xmm0, -0x28(%rbx)
movups %xmm0, -0x18(%rbx)
xorl %ebp, %ebp
movq %rbp, -0x8(%rbx)
movq %rbx, %rdi
callq 0x2100
leaq 0x80(%rsp), %r15
movq %r15, %rdi
callq 0x2100
movq %r14, 0x30(%r15)
movq %rbp, 0x38(%r15)
leaq 0x21c(%rip), %rax       # 0x2530
movq %rax, 0x40(%r15)
leaq 0x29e9(%rip), %r14      # 0x4d08
leaq 0x20(%rsp), %r13
movq %rsp, %r15
leaq 0x8(%rsp), %r12
movq $0x0, (%rsp)
movl $0x18, %edi
callq 0x20d0
movq %r14, (%rax)
movl %ebp, 0x8(%rax)
movq %r13, 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 0x236a
movq (%rdi), %rax
callq *0x8(%rax)
movq %r15, %rdi
callq 0x2160
cmpq $0x0, (%rsp)
jne 0x252a
incl %ebp
cmpl $0xa, %ebp
jne 0x232c
movq $0x0, (%rsp)
movl $0x10, %edi
callq 0x20d0
leaq 0x29ab(%rip), %rcx      # 0x4d48
movq %rcx, (%rax)
movq %r13, 0x8(%rax)
leaq 0x8(%rsp), %rsi
movq %rax, (%rsi)
movq %rsp, %rdi
xorl %edx, %edx
callq 0x20c0
movq 0x8(%rsp), %rdi
testq %rdi, %rdi
je 0x23c6
movq (%rdi), %rax
callq *0x8(%rax)
movq %rsp, %rdi
callq 0x2140
xorl %ebp, %ebp
leaq 0x29b1(%rip), %r14      # 0x4d88
leaq 0x18(%rsp), %r15
leaq 0x8(%rsp), %r12
movq $0x0, 0x18(%rsp)
movl $0x18, %edi
callq 0x20d0
movq %r14, (%rax)
movl %ebp, 0x8(%rax)
movq %r13, 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 0x2420
movq (%rdi), %rax
callq *0x8(%rax)
movq %r15, %rdi
callq 0x2160
cmpq $0x0, 0x18(%rsp)
jne 0x252a
incl %ebp
cmpl $0x9, %ebp
jne 0x23e1
leaq 0x20(%rsp), %rdi
callq 0x26c4
leaq 0x8(%rsp), %r15
movq $0x5, (%r15)
movq $0x0, 0x8(%r15)
movq %r15, %rdi
movq %r15, %rsi
callq 0x2060
cmpl $-0x1, %eax
jne 0x2473
callq 0x2030
cmpl $0x4, (%rax)
je 0x2459
cmpq $0x0, (%rsp)
jne 0x252a
leaq 0x80(%rsp), %rdi
callq 0x2180
movq %rbx, %rdi
callq 0x2180
xorl %eax, %eax
addq $0xc8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x24e5
jmp 0x250a
jmp 0x24d7
jmp 0x24d7
jmp 0x24d7
movq %rax, %r15
movq 0x8(%rsp), %rdi
testq %rdi, %rdi
je 0x24c4
movq (%rdi), %rax
callq *0x8(%rax)
movq $0x0, 0x8(%rsp)
jmp 0x24da
cmpq $0x0, 0x18(%rsp)
jne 0x252a
movq %rax, %r15
cmpq $0x0, (%rsp)
je 0x250d
jmp 0x252a
jmp 0x250a
movq %rax, %r15
movq 0x8(%rsp), %rdi
testq %rdi, %rdi
je 0x24f8
movq (%rdi), %rax
callq *0x8(%rax)
movq $0x0, 0x8(%rsp)
jmp 0x250d
cmpq $0x0, (%rsp)
jne 0x252a
movq %rax, %r15
leaq 0x80(%rsp), %rdi
callq 0x2180
movq %rbx, %rdi
callq 0x2180
movq %r15, %rdi
callq 0x2170
callq 0x2040
nop