// File: xocoder[P]m_kcptun/vendor/m_net/src/mnet_core.c
// Function: evt_del(s_mchann*, int)
static int
_evt_del(chann_t *n, int set) {
   mnet_t *ss = _gmnet();
   struct s_event *chg = &ss->chg;
   if ( _evt_check_expand(chg) ) {
      mevent_t *kev = chg->array;
      memset(kev, 0, sizeof(mevent_t));
#if (MNET_OS_MACOX || MNET_OS_FreeBSD)
      kev->ident = n->fd;
      if (set == MNET_SET_READ) {
         kev->filter = EVFILT_READ;
      } else if (set == MNET_SET_WRITE) {
         kev->filter = EVFILT_WRITE;         
      }
      kev->flags = EV_DELETE;
      kev->udata = (void*)n;
      if (kevent(ss->kq, chg->array, 1, NULL, 0, NULL) < 0) {
         mm_log(n, MNET_LOG_ERR, "kq fail to delete fd:%d filter %x, errno %d:%s\n",
                n->fd, kev->filter, errno, strerror(errno));
         return 0;
      }
#else
      uint32_t events = 0;
      kev->data.ptr = (void*)n;
      if (set == MNET_SET_READ) {
         events = n->epoll_events & ~EPOLLIN;
      } else if (set == MNET_SET_WRITE) {
         events = n->epoll_events & ~EPOLLOUT;
      }
      kev->events = events;
      if (epoll_ctl(ss->kq, events ? EPOLL_CTL_MOD : EPOLL_CTL_DEL, n->fd, kev) < 0) {
         mm_log(n, MNET_LOG_ERR, "epoll fail to add fd:%d filter %x, errno %d, %s\n",
                n->fd, n->epoll_events, errno, strerror(errno));
         return 0;
      }
      n->epoll_events = events;
#endif
      mm_log(n, MNET_LOG_VERBOSE, "del chann:%p fd:%d events\n", n, n->fd);
      return 1;
   }
   return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
callq 0x67b0
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rax
addq $0x18, %rax
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rdi
callq 0x8c90
cmpl $0x0, %eax
je 0x7b57
movq -0x28(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rdi
xorl %esi, %esi
movl $0xc, %edx
callq 0x31c0
movl $0x0, -0x34(%rbp)
movq -0x10(%rbp), %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x4(%rax)
cmpl $0x0, -0x14(%rbp)
jne 0x7a6d
movq -0x10(%rbp), %rax
movl 0x88(%rax), %eax
andl $-0x2, %eax
movl %eax, -0x34(%rbp)
jmp 0x7a85
cmpl $0x1, -0x14(%rbp)
jne 0x7a83
movq -0x10(%rbp), %rax
movl 0x88(%rax), %eax
andl $-0x5, %eax
movl %eax, -0x34(%rbp)
jmp 0x7a85
movl -0x34(%rbp), %ecx
movq -0x30(%rbp), %rax
movl %ecx, (%rax)
movq -0x20(%rbp), %rax
movl 0x10(%rax), %edi
movl -0x34(%rbp), %ecx
movl $0x2, %esi
movl $0x3, %eax
cmpl $0x0, %ecx
cmovnel %eax, %esi
movq -0x10(%rbp), %rax
movl (%rax), %edx
movq -0x30(%rbp), %rcx
callq 0x3450
cmpl $0x0, %eax
jge 0x7b1f
movq -0x10(%rbp), %rax
movq %rax, -0x48(%rbp)
movq -0x10(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x40(%rbp)
movq -0x10(%rbp), %rax
movl 0x88(%rax), %eax
movl %eax, -0x3c(%rbp)
callq 0x3040
movl (%rax), %eax
movl %eax, -0x38(%rbp)
callq 0x3040
movl (%rax), %edi
callq 0x3110
movq -0x48(%rbp), %rdi
movl -0x40(%rbp), %ecx
movl -0x3c(%rbp), %r8d
movl -0x38(%rbp), %r9d
movl $0x1, %esi
leaq 0xb97c(%rip), %rdx      # 0x13487
movq %rax, (%rsp)
movb $0x0, %al
callq 0x6c30
movl $0x0, -0x4(%rbp)
jmp 0x7b5e
movl -0x34(%rbp), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x88(%rax)
movq -0x10(%rbp), %rdi
movq -0x10(%rbp), %rcx
movq -0x10(%rbp), %rax
movl (%rax), %r8d
movl $0x3, %esi
leaq 0xb971(%rip), %rdx      # 0x134b8
movb $0x0, %al
callq 0x6c30
movl $0x1, -0x4(%rbp)
jmp 0x7b5e
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x50, %rsp
popq %rbp
retq
nopw (%rax,%rax)