// File: cybozu[P]yrmcds/cybozu/reactor.cpp
// Function: cybozu::reactor::remove_resource(int)
void reactor::remove_resource(int fd) {
    resource_map::iterator it = m_resources.find(fd);
    if( it == m_resources.end() ) {
        dump_stack();
        throw std::logic_error("bug in remove_resource");
    }
    auto res = it->second.get();
    m_garbage.emplace_back( std::move(it->second) );
    m_resources.erase(it);
    if( epoll_ctl(m_fd, EPOLL_CTL_DEL, fd, NULL) == -1 )
        throw_unix_error(errno, "epoll_ctl(EPOLL_CTL_DEL)");
    m_readables.erase(std::remove(m_readables.begin(), m_readables.end(), fd),
                      m_readables.end());

    if( ! res->try_close() ) {
        logger::debug() << "failed to close fd (will be closed later): " << fd;
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xc0, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movq -0x8(%rbp), %rdi
movq %rdi, -0x98(%rbp)
addq $0x8, %rdi
leaq -0xc(%rbp), %rsi
callq 0xfd20
movq -0x98(%rbp), %rdi
movq %rax, -0x18(%rbp)
addq $0x8, %rdi
callq 0xfd80
movq %rax, -0x20(%rbp)
leaq -0x18(%rbp), %rdi
leaq -0x20(%rbp), %rsi
callq 0xfd50
testb $0x1, %al
jne 0xf095
jmp 0xf0f6
callq 0x16af0
movl $0x10, %edi
callq 0x82f0
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0xa0(%rbp)
leaq 0x6b29f(%rip), %rsi     # 0x7a357
callq 0x89a0
jmp 0xf0bf
movq -0xa0(%rbp), %rdi
movq 0x9fef3(%rip), %rsi     # 0xaefc0
movq 0x9feac(%rip), %rdx     # 0xaef80
callq 0x8b70
movq -0xa0(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
callq 0x8490
jmp 0xf2a7
leaq -0x18(%rbp), %rdi
callq 0xfdb0
movq %rax, %rdi
addq $0x8, %rdi
callq 0xfde0
movq %rax, %rcx
movq -0x98(%rbp), %rax
movq %rcx, -0x38(%rbp)
addq $0xa8, %rax
movq %rax, -0xa8(%rbp)
leaq -0x18(%rbp), %rdi
callq 0xfdb0
movq -0xa8(%rbp), %rdi
movq %rax, %rsi
addq $0x8, %rsi
callq 0xfe10
movq -0x98(%rbp), %rdi
addq $0x8, %rdi
movq -0x18(%rbp), %rax
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rsi
callq 0xfe90
movq %rax, %rcx
movq -0x98(%rbp), %rax
movq %rcx, -0x48(%rbp)
movl (%rax), %edi
movl -0xc(%rbp), %edx
movl $0x2, %esi
xorl %eax, %eax
movl %eax, %ecx
callq 0x8910
cmpl $-0x1, %eax
jne 0xf197
callq 0x8050
movl (%rax), %edi
leaq 0x6b1dc(%rip), %rsi     # 0x7a36e
callq 0xa320
movq -0x98(%rbp), %rdi
movq %rdi, %rax
addq $0x40, %rax
movq %rax, -0xb0(%rbp)
addq $0x40, %rdi
callq 0xffb0
movq -0x98(%rbp), %rdi
movq %rax, -0x60(%rbp)
addq $0x40, %rdi
callq 0xffe0
movq %rax, -0x68(%rbp)
movq -0x60(%rbp), %rdi
movq -0x68(%rbp), %rsi
leaq -0xc(%rbp), %rdx
callq 0xff60
movq %rax, -0x58(%rbp)
leaq -0x50(%rbp), %rdi
leaq -0x58(%rbp), %rsi
callq 0x10010
movq -0x98(%rbp), %rdi
addq $0x40, %rdi
callq 0xffe0
movq %rax, -0x78(%rbp)
leaq -0x70(%rbp), %rdi
leaq -0x78(%rbp), %rsi
callq 0x10010
movq -0xb0(%rbp), %rdi
movq -0x50(%rbp), %rsi
movq -0x70(%rbp), %rdx
callq 0xfed0
movq %rax, -0x80(%rbp)
movq -0x38(%rbp), %rdi
callq 0x10050
testb $0x1, %al
jne 0xf29e
leaq -0x90(%rbp), %rdi
movq %rdi, -0xc0(%rbp)
callq 0xded0
movq -0xc0(%rbp), %rdi
leaq 0x6b131(%rip), %rsi     # 0x7a387
callq 0x100f0
movq %rax, -0xb8(%rbp)
jmp 0xf264
movq -0xb8(%rbp), %rdi
leaq -0xc(%rbp), %rsi
callq 0xdff0
jmp 0xf276
leaq -0x90(%rbp), %rdi
callq 0xa770
jmp 0xf29e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
leaq -0x90(%rbp), %rdi
callq 0xa770
jmp 0xf2a7
addq $0xc0, %rsp
popq %rbp
retq
movq -0x28(%rbp), %rdi
callq 0x8bc0