// File: /workspace/github_cpp_makefile_star2_O1/olahol[P]cpp-csp/examples/select.cpp
// Function: main
int main() {
  csp::Scheduler scheduler;
  csp::Channel<int> ch1, ch2;

  scheduler.spawn([&]() {
    std::chrono::milliseconds dura(100);
    for (;;) {
      int n = csp::select(ch2, ch1);
      std::cout << "got chan " << n << std::endl;
      switch (n) {
        case 0:
          ch2.get();
          std::cout << "exit" << std::endl;
          return;
        case 1:
          ch1.get();
          std::this_thread::sleep_for(dura);
          break;
      }
    }
  });

  scheduler.spawn([&]() {
    std::chrono::milliseconds dura(10);
    std::this_thread::sleep_for(dura);
    ch2.put(2);
  });

  ch1.put(1);
  ch1.put(1);
  ch1.put(1);
  ch1.put(1);

  std::cout << "join" << std::endl;
  scheduler.join();
}

// Assembly:
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x190, %rsp            # imm = 0x190
xorps %xmm0, %xmm0
movaps %xmm0, 0x10(%rsp)
movq $0x0, 0x20(%rsp)
leaq 0x30(%rsp), %r12
movaps %xmm0, 0x40(%r12)
movaps %xmm0, 0x30(%r12)
movaps %xmm0, 0x20(%r12)
movaps %xmm0, 0x10(%r12)
movaps %xmm0, (%r12)
movq %r12, %rdi
xorl %esi, %esi
callq 0x2a36
leaq 0xb0(%rsp), %rbx
movl $0x0, -0x30(%rbx)
xorps %xmm0, %xmm0
movups %xmm0, -0x28(%rbx)
movups %xmm0, -0x18(%rbx)
movq $0x0, -0x8(%rbx)
movq %rbx, %rdi
callq 0x2160
leaq 0xe0(%rsp), %r15
xorps %xmm0, %xmm0
movaps %xmm0, 0x40(%r15)
movaps %xmm0, 0x30(%r15)
movaps %xmm0, 0x20(%r15)
movaps %xmm0, 0x10(%r15)
movaps %xmm0, (%r15)
movq %r15, %rdi
xorl %esi, %esi
callq 0x2a36
leaq 0x160(%rsp), %r14
movl $0x0, -0x30(%r14)
xorps %xmm0, %xmm0
movups %xmm0, -0x28(%r14)
movups %xmm0, -0x18(%r14)
movq $0x0, -0x8(%r14)
movq %r14, %rdi
callq 0x2160
movl $0x8, %edi
callq 0x2130
movq %rax, %r13
movq $0x0, (%rax)
movl $0x18, %edi
callq 0x2130
leaq 0x38f6(%rip), %rcx      # 0x5d48
movq %rcx, (%rax)
movq %r15, 0x8(%rax)
movq %r12, 0x10(%rax)
leaq 0x8(%rsp), %rsi
movq %rax, (%rsi)
movq %r13, %rdi
xorl %edx, %edx
callq 0x2110
movq 0x8(%rsp), %rdi
testq %rdi, %rdi
je 0x247f
movq (%rdi), %rax
callq *0x8(%rax)
leaq 0x28(%rsp), %rsi
movq %r13, (%rsi)
leaq 0x10(%rsp), %rdi
callq 0x2bac
movl $0x8, %edi
callq 0x2130
movq %rax, %r12
movq $0x0, (%rax)
movl $0x10, %edi
callq 0x2130
leaq 0x38d2(%rip), %rcx      # 0x5d88
movq %rcx, (%rax)
movq %r15, 0x8(%rax)
leaq 0x8(%rsp), %rsi
movq %rax, (%rsi)
movq %r12, %rdi
xorl %edx, %edx
callq 0x2110
movq 0x8(%rsp), %rdi
testq %rdi, %rdi
je 0x24df
movq (%rdi), %rax
callq *0x8(%rax)
leaq 0x28(%rsp), %rsi
movq %r12, (%rsi)
leaq 0x10(%rsp), %rdi
callq 0x2bac
leaq 0x30(%rsp), %rdi
movl $0x1, %esi
callq 0x28a2
leaq 0x30(%rsp), %rdi
movl $0x1, %esi
callq 0x28a2
leaq 0x30(%rsp), %rdi
movl $0x1, %esi
callq 0x28a2
leaq 0x30(%rsp), %rdi
movl $0x1, %esi
callq 0x28a2
movq 0x3aa4(%rip), %r15      # 0x5fd8
leaq 0x1ac9(%rip), %rsi      # 0x4004
movl $0x4, %edx
movq %r15, %rdi
callq 0x2150
movq (%r15), %rax
addq -0x18(%rax), %r15
movq %r15, %rdi
movl $0xa, %esi
callq 0x2120
movsbl %al, %esi
movq 0x3a72(%rip), %rdi      # 0x5fd8
callq 0x2030
movq %rax, %rdi
callq 0x20d0
movq 0x10(%rsp), %r15
movq 0x18(%rsp), %r12
cmpq %r12, %r15
je 0x2596
movq (%r15), %rdi
cmpq $0x0, (%rdi)
je 0x2590
callq 0x21d0
addq $0x8, %r15
jmp 0x257d
movq %r14, %rdi
callq 0x2200
leaq 0xe0(%rsp), %rdi
callq 0x29e6
movq %rbx, %rdi
callq 0x2200
leaq 0x30(%rsp), %rdi
callq 0x29e6
leaq 0x10(%rsp), %rdi
callq 0x2984
xorl %eax, %eax
addq $0x190, %rsp            # imm = 0x190
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq
movq %rax, %r15
movq 0x8(%rsp), %rdi
testq %rdi, %rdi
je 0x25ed
movq (%rdi), %rax
callq *0x8(%rax)
movq $0x0, 0x8(%rsp)
jmp 0x25fb
movq %rax, %r15
movl $0x8, %esi
movq %r12, %rdi
jmp 0x262e
movq %rax, %r15
movq 0x8(%rsp), %rdi
testq %rdi, %rdi
je 0x2618
movq (%rdi), %rax
callq *0x8(%rax)
movq $0x0, 0x8(%rsp)
jmp 0x2626
movq %rax, %r15
movl $0x8, %esi
movq %r13, %rdi
callq 0x2140
jmp 0x2644
movq %rax, %r15
jmp 0x2659
movq %rax, %r15
jmp 0x266b
jmp 0x2641
movq %rax, %r15
movq %r14, %rdi
callq 0x2200
leaq 0xe0(%rsp), %rdi
callq 0x29e6
movq %rbx, %rdi
callq 0x2200
leaq 0x30(%rsp), %rdi
callq 0x29e6
leaq 0x10(%rsp), %rdi
callq 0x2984
movq %r15, %rdi
callq 0x21f0
nop