// File: /workspace/github_cpp_makefile_star2_O1/romkatv[P]hcproxy/src/thread_pool.cc
// Function: hcproxy::ThreadPool::Loop(unsigned long)
void ThreadPool::Loop(size_t tid) {
  auto Next = [&]() -> std::function<void()> {
    std::unique_lock<std::mutex> lock(mutex_);
    while (true) {
      if (exit_) return nullptr;
      if (work_.empty()) {
        cv_.wait(lock);
        continue;
      }
      Time now = Clock::now();
      const Work& top = work_.top();
      if (top.t <= now) {
        std::function<void()> res = std::move(top.f);
        work_.pop();
        bool notify = !work_.empty() && !have_sleeper_;
        lock.unlock();
        if (notify) cv_.notify_one();
        return res;
      }
      if (have_sleeper_) {
        cv_.wait(lock);
        continue;
      }
      have_sleeper_ = true;
      sleeper_cv_.wait_until(lock, top.t);
      CHECK(have_sleeper_);
      have_sleeper_ = false;
    }
  };
  while (std::function<void()> f = Next()) f();
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movq %rdi, %rbx
leaq 0x10(%rdi), %rax
movq %rax, 0x38(%rsp)
leaq 0x98(%rdi), %r12
leaq 0x38(%rdi), %r14
leaq 0x68(%rdi), %rax
movq %rax, 0x40(%rsp)
movq %r12, 0x30(%rsp)
movq 0x38(%rsp), %rax
movq %rax, (%rsp)
movb $0x0, 0x8(%rsp)
movq %rsp, %rdi
callq 0x1b5f0
movb $0x1, 0x8(%rsp)
cmpb $0x0, 0x8(%rbx)
jne 0x1c5b8
movq 0x98(%rbx), %rax
cmpq 0xa0(%rbx), %rax
je 0x1c509
callq 0x2b520
movq (%r12), %rdx
cmpq (%rdx), %rax
jge 0x1c516
cmpb $0x1, 0x9(%rbx)
jne 0x1c58f
movq %r14, %rdi
movq %rsp, %rsi
callq 0x2e790
movl $0x2, %ebp
jmp 0x1c5ac
movq %r14, %rdi
movq %rsp, %rsi
callq 0x2e790
jmp 0x1c4c2
xorps %xmm1, %xmm1
movaps %xmm1, 0x10(%rsp)
movq $0x0, 0x20(%rsp)
movq 0x28(%rdx), %rax
movq %rax, 0x28(%rsp)
movq 0x20(%rdx), %rax
testq %rax, %rax
je 0x1c54e
movups 0x10(%rdx), %xmm0
addq $0x20, %rdx
movaps %xmm0, 0x10(%rsp)
movq %rax, 0x20(%rsp)
movups %xmm1, (%rdx)
movq %r12, %rdi
callq 0x1c812
movq 0x98(%rbx), %r13
movq 0xa0(%rbx), %r15
movb 0x9(%rbx), %r12b
movq %rsp, %rdi
callq 0x1b596
movl $0x1, %ebp
cmpq %r15, %r13
je 0x1c588
testb $0x1, %r12b
jne 0x1c588
movq %r14, %rdi
callq 0x2e7b0
movq 0x30(%rsp), %r12
jmp 0x1c5ac
movb $0x1, 0x9(%rbx)
movq 0x40(%rsp), %rdi
movq %rsp, %rsi
callq 0x1ccb6
cmpb $0x0, 0x9(%rbx)
je 0x1c611
movb $0x0, 0x9(%rbx)
xorl %ebp, %ebp
testb $0x1, %bpl
je 0x1c4c2
jmp 0x1c5c5
xorps %xmm0, %xmm0
movaps %xmm0, 0x20(%rsp)
movaps %xmm0, 0x10(%rsp)
movq %rsp, %rdi
callq 0x1b5da
movq 0x20(%rsp), %rbp
testq %rbp, %rbp
je 0x1c5e0
leaq 0x10(%rsp), %rdi
callq *0x28(%rsp)
movq 0x20(%rsp), %rax
testq %rax, %rax
je 0x1c5f9
leaq 0x10(%rsp), %rdi
movq %rdi, %rsi
movl $0x3, %edx
callq *%rax
testq %rbp, %rbp
jne 0x1c4a7
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0xb3459(%rip), %rsi     # 0xcfa71
leaq 0x48(%rsp), %rdi
movl $0x4b, %edx
movl $0x3, %ecx
callq 0x2019c
movq 0x60(%rsp), %rdi
leaq 0xb344c(%rip), %rsi     # 0xcfa84
movl $0xd, %edx
callq 0x8bab0
movq 0x60(%rsp), %rdi
leaq 0xb7cbd(%rip), %rsi     # 0xd430b
movl $0x2, %edx
callq 0x8bab0
jmp 0x1c67c
movq %rax, %rbx
movq 0x20(%rsp), %rax
testq %rax, %rax
je 0x1c6b3
leaq 0x10(%rsp), %rdi
movq %rdi, %rsi
movl $0x3, %edx
callq *%rax
jmp 0x1c6b3
jmp 0x1c6bb
jmp 0x1c6bb
leaq 0x48(%rsp), %rdi
callq 0x18aaa
jmp 0x1c688
movq %rax, %rbx
jmp 0x1c6ab
jmp 0x1c68f
movq %rax, %rbx
movq 0x20(%rsp), %rax
testq %rax, %rax
je 0x1c6ab
leaq 0x10(%rsp), %rdi
movq %rdi, %rsi
movl $0x3, %edx
callq *%rax
movq %rsp, %rdi
callq 0x1b5da
movq %rbx, %rdi
callq 0xcc900
movq %rax, %rdi
callq 0x18abd
nop