// File: /workspace/github_cpp_makefile_star2_O1/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, 0x8(%rsp)
movq 0x8(%rsi), %rdx
testq %rdx, %rdx
je 0x999e
movl 0x8(%rdx), %eax
testl %eax, %eax
je 0x999c
leal 0x1(%rax), %ecx
lock
cmpxchgl %ecx, 0x8(%rdx)
jne 0x998c
jmp 0x999e
xorl %edx, %edx
testq %rdx, %rdx
je 0x99ad
movl 0x8(%rdx), %eax
testl %eax, %eax
sete %al
jmp 0x99af
movb $0x1, %al
testb %al, %al
movq %rdx, (%rsp)
jne 0x99bc
movq (%r15), %rsi
jmp 0x99be
xorl %esi, %esi
movq (%rsi), %rax
leaq 0x48(%rsp), %r13
movq %r13, %rdi
callq *(%rax)
movq 0x48(%rsp), %r14
cmpq %r13, %r14
je 0x9aea
movq 0x8(%rsp), %rax
addq $0x8, %rax
movq %rax, 0x40(%rsp)
movq %r13, %r12
movq 0x10(%r14), %rax
rolq $0x20, %rax
movl $0x0, 0x18(%rsp)
movq %rax, 0x10(%rsp)
movq (%r15), %rbp
movq 0x8(%r15), %rbx
testq %rbx, %rbx
je 0x9a20
movq 0xc57e(%rip), %rax      # 0x15f90
cmpb $0x0, (%rax)
je 0x9a1c
incl 0xc(%rbx)
jmp 0x9a20
lock
incl 0xc(%rbx)
movq 0x40(%rsp), %rdi
leaq 0x14(%rsp), %rsi
callq 0x9f02
movq %rax, %r13
xorps %xmm0, %xmm0
movaps %xmm0, 0x30(%rsp)
movaps %xmm0, 0x20(%rsp)
movl $0x18, %edi
callq 0x5390
movq 0x8(%rsp), %rcx
movq %rcx, (%rax)
movq %rbp, 0x8(%rax)
movq %rbx, 0x10(%rax)
movq %rax, 0x20(%rsp)
leaq 0x355(%rip), %rdx       # 0x9dba
movq %rdx, 0x38(%rsp)
leaq 0x3cb(%rip), %rcx       # 0x9e3c
movq %rcx, 0x30(%rsp)
movaps 0x20(%rsp), %xmm0
movaps %xmm0, 0x60(%rsp)
movups (%r13), %xmm1
movaps %xmm1, 0x20(%rsp)
movups %xmm0, (%r13)
movq 0x10(%r13), %rax
movq %rax, 0x30(%rsp)
movq %rcx, 0x10(%r13)
movq 0x18(%r13), %rcx
movq %rcx, 0x38(%rsp)
movq %rdx, 0x18(%r13)
testq %rax, %rax
je 0x9abd
leaq 0x20(%rsp), %rdi
movq %rdi, %rsi
movl $0x3, %edx
callq *%rax
movq 0x8(%rsp), %rax
movl (%rax), %edi
movl 0x14(%rsp), %edx
movl $0x1, %esi
leaq 0x10(%rsp), %rcx
callq 0x5080
testl %eax, %eax
js 0x9b26
movq %r12, %r13
movq (%r14), %r14
cmpq %r12, %r14
jne 0x99e7
movq 0x48(%rsp), %rdi
cmpq %r13, %rdi
je 0x9b09
movq (%rdi), %rbx
movl $0x18, %esi
callq 0x5070
movq %rbx, %rdi
cmpq %r13, %rbx
jne 0x9af4
movq (%rsp), %rdi
testq %rdi, %rdi
je 0x9b17
callq 0x65e2
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 0x5a25(%rip), %rsi      # 0xf55f
movq %rax, %rdi
callq 0x50d0
movq 0xc44f(%rip), %rsi      # 0x15f98
movq 0xc490(%rip), %rdx      # 0x15fe0
movq %rbx, %rdi
callq 0x51c0
movq %rax, %r15
jmp 0x9bb4
movq %rax, %r15
jmp 0x9b95
movq %rax, %r15
movq %rbx, %rdi
callq 0x55f0
jmp 0x9b95
movq %rax, %rdi
callq 0x6156
movq %rax, %r15
testq %rbx, %rbx
je 0x9b95
leaq 0x60(%rsp), %r14
movq %rbx, %rdi
movq %r15, %rsi
movq %r14, %rcx
callq 0x56e5
movq (%r14), %r15
movq 0x48(%rsp), %rdi
cmpq %r12, %rdi
je 0x9bb4
movq (%rdi), %rbx
movl $0x18, %esi
callq 0x5070
movq %rbx, %rdi
cmpq %r12, %rbx
jne 0x9b9f
cmpq $0x0, (%rsp)
je 0x9bc4
movq (%rsp), %rdi
callq 0x65e2
movq %r15, %rdi
callq 0x5200