// File: /workspace/github_cpp_makefile_star2_O3/Themaister[P]umusd/eventhandler.cpp
// Function: EventHandler::add(std::weak_ptr<EventHandled>)
void EventHandler::add(std::weak_ptr<EventHandled> handler)
{
   auto fd_ptr = handler.lock();

   for (auto fd : fd_ptr->pollfds())
   {
      struct epoll_event event{};
      event.events = fd.events;
      event.data.fd = fd.fd;

      cb_map[event.data.fd] = [this, handler]() {
         if (auto tmp = handler.lock())
            tmp->handle(*this);
      };

      if (epoll_ctl(epfd, EPOLL_CTL_ADD, event.data.fd, &event) < 0)
         throw std::runtime_error("Failed to add epoll fd to list.\n");
   }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x78, %rsp
movq %rsi, %r15
movq %rdi, %r12
movq 0x8(%rsi), %rdx
movl 0x8(%rdx), %eax
leal 0x1(%rax), %ecx
lock
cmpxchgl %ecx, 0x8(%rdx)
jne 0x9c31
movq %rdx, 0x18(%rsp)
movl 0x8(%rdx), %eax
movq (%r15), %rsi
movq (%rsi), %rax
leaq 0x28(%rsp), %r14
movq %r14, %rdi
callq *(%rax)
movq 0x28(%rsp), %r13
cmpq %r14, %r13
je 0x9d5f
leaq 0x8(%r12), %rax
movq %rax, 0x20(%rsp)
movl $0x0, 0x10(%rsp)
movq 0x10(%r13), %xmm0
pshufd $0xe1, %xmm0, %xmm0     # xmm0 = xmm0[1,0,2,3]
movq %xmm0, 0x8(%rsp)
movq (%r15), %rbp
movq 0x8(%r15), %rbx
testq %rbx, %rbx
je 0x9ca5
movq 0xc2f9(%rip), %rax      # 0x15f90
cmpb $0x0, (%rax)
je 0x9ca1
incl 0xc(%rbx)
jmp 0x9ca5
lock
incl 0xc(%rbx)
movq 0x20(%rsp), %rdi
leaq 0xc(%rsp), %rsi
callq 0xa15a
movq %rax, %r14
movq $0x0, 0x48(%rsp)
movl $0x18, %edi
callq 0x5390
movq %r12, (%rax)
movq %rbp, 0x8(%rax)
movq %rbx, 0x10(%rax)
movq %rax, 0x40(%rsp)
movaps 0x40(%rsp), %xmm0
movaps %xmm0, 0x60(%rsp)
movups (%r14), %xmm1
movaps %xmm1, 0x40(%rsp)
movups %xmm0, (%r14)
movq 0x10(%r14), %rax
movq %rax, 0x50(%rsp)
leaq 0x399(%rip), %rcx       # 0xa09a
movq %rcx, 0x10(%r14)
movq 0x18(%r14), %rcx
movq %rcx, 0x58(%rsp)
leaq 0x317(%rip), %rcx       # 0xa02c
movq %rcx, 0x18(%r14)
testq %rax, %rax
je 0x9d2d
leaq 0x40(%rsp), %rdi
movq %rdi, %rsi
movl $0x3, %edx
callq *%rax
movl (%r12), %edi
movl 0xc(%rsp), %edx
movl $0x1, %esi
leaq 0x8(%rsp), %rcx
callq 0x5080
testl %eax, %eax
leaq 0x28(%rsp), %r14
js 0x9d96
movq (%r13), %r13
cmpq %r14, %r13
jne 0x9c6b
movq 0x28(%rsp), %r13
cmpq %r14, %r13
je 0x9d7d
movq (%r13), %rbx
movl $0x18, %esi
movq %r13, %rdi
callq 0x5070
movq %rbx, %r13
cmpq %r14, %rbx
jne 0x9d64
movq 0x18(%rsp), %rdi
callq 0x69c2
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl $0x10, %edi
callq 0x5420
movq %rax, %rbx
leaq 0x5815(%rip), %rsi      # 0xf5bf
movq %rax, %rdi
callq 0x50d0
movq 0xc1df(%rip), %rsi      # 0x15f98
movq 0xc220(%rip), %rdx      # 0x15fe0
movq %rbx, %rdi
callq 0x51c0
movq %rax, %r15
jmp 0x9e29
movq %rax, %r15
jmp 0x9e05
movq %rax, %r15
movq %rbx, %rdi
callq 0x55f0
jmp 0x9e05
movq %rax, %rdi
callq 0x6406
movq %rax, %r15
testq %rbx, %rbx
je 0x9e05
leaq 0x60(%rsp), %r14
movq %rbx, %rdi
movq %r15, %rsi
movq %r14, %rcx
callq 0x56e5
movq (%r14), %r15
movq 0x28(%rsp), %rdi
leaq 0x28(%rsp), %r14
cmpq %r14, %rdi
je 0x9e29
movq (%rdi), %rbx
movl $0x18, %esi
callq 0x5070
movq %rbx, %rdi
cmpq %r14, %rbx
jne 0x9e14
movq 0x18(%rsp), %rdi
callq 0x69c2
movq %r15, %rdi
callq 0x5200
nop