// File: /workspace/github_cpp_makefile_star2_O3/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 $0x78, %rsp
movq %rdi, %rbx
leaq 0x10(%rdi), %r15
leaq 0x98(%rdi), %r14
leaq 0x68(%rdi), %rbp
leaq 0x38(%rdi), %r12
leaq 0x38(%rsp), %r13
movq %r15, 0x50(%rsp)
movq %rbp, 0x48(%rsp)
movq %r15, 0x38(%rsp)
movb $0x0, 0x40(%rsp)
movq %r13, %rdi
callq 0x1b4ea
movb $0x1, 0x40(%rsp)
cmpb $0x0, 0x8(%rbx)
jne 0x1c409
movq 0x98(%rbx), %rax
cmpq 0xa0(%rbx), %rax
je 0x1c3dd
callq 0x2b360
movq (%r14), %rdx
cmpq (%rdx), %rax
jge 0x1c455
cmpb $0x1, 0x9(%rbx)
jne 0x1c3ea
movq %r12, %rdi
movq %r13, %rsi
callq 0x2e5d0
jmp 0x1c3b4
movb $0x1, 0x9(%rbx)
movq %rbp, %rdi
movq %r13, %rsi
callq 0x1cb84
cmpb $0x0, 0x9(%rbx)
je 0x1c4f1
movb $0x0, 0x9(%rbx)
jmp 0x1c3b4
xorps %xmm0, %xmm0
movaps %xmm0, 0x20(%rsp)
movaps %xmm0, 0x10(%rsp)
movq %r13, %rdi
callq 0x1b4d4
cmpq $0x0, 0x20(%rsp)
je 0x1c4e2
leaq 0x10(%rsp), %rdi
callq *0x28(%rsp)
movq 0x20(%rsp), %rax
testq %rax, %rax
je 0x1c39d
leaq 0x10(%rsp), %rdi
movq %rdi, %rsi
movl $0x3, %edx
callq *%rax
jmp 0x1c39d
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 0x1c48d
movups 0x10(%rdx), %xmm0
addq $0x20, %rdx
movaps %xmm0, 0x10(%rsp)
movq %rax, 0x20(%rsp)
movups %xmm1, (%rdx)
movq %rax, 0x30(%rsp)
movq %r14, %rdi
callq 0x1c6ec
movq 0x98(%rbx), %r15
movq 0xa0(%rbx), %rbp
movb 0x9(%rbx), %al
movb %al, 0xf(%rsp)
movq %r13, %rdi
callq 0x1b490
cmpq %rbp, %r15
movq 0x50(%rsp), %r15
movq 0x48(%rsp), %rbp
je 0x1c416
testb $0x1, 0xf(%rsp)
jne 0x1c416
movq %r12, %rdi
callq 0x2e5f0
jmp 0x1c416
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0xb3569(%rip), %rsi     # 0xcfa61
leaq 0x58(%rsp), %rdi
movl $0x4b, %edx
movl $0x3, %ecx
callq 0x2003c
movq 0x70(%rsp), %rdi
leaq 0xb355c(%rip), %rsi     # 0xcfa74
movl $0xd, %edx
callq 0x8b8f0
movq 0x70(%rsp), %rdi
leaq 0xb7d9d(%rip), %rsi     # 0xd42cb
movl $0x2, %edx
callq 0x8b8f0
jmp 0x1c584
jmp 0x1c53c
movq %rax, %rbx
cmpq $0x0, 0x30(%rsp)
je 0x1c593
leaq 0x10(%rsp), %rdi
movq %rdi, %rsi
movl $0x3, %edx
callq *0x30(%rsp)
jmp 0x1c593
jmp 0x1c57c
jmp 0x1c57c
movq %rax, %rbx
movq 0x20(%rsp), %rax
testq %rax, %rax
je 0x1c59d
leaq 0x10(%rsp), %rdi
movq %rdi, %rsi
movl $0x3, %edx
callq *%rax
jmp 0x1c59d
movq %rax, %rdi
callq 0x18a37
leaq 0x58(%rsp), %rdi
callq 0x18a24
jmp 0x1c590
movq %rax, %rbx
leaq 0x38(%rsp), %rdi
callq 0x1b4d4
movq %rbx, %rdi
callq 0xcc750
nop