// File: /workspace/github_cpp_makefile_star2_O2/davmac314[P]dinit/src/../dasynq/include/dasynq.h
// Function: dasynq::v2::event_loop<dasynq::null_mutex, dasynq::v2::default_traits<dasynq::null_mutex>>::process_primary_rearm(dasynq::v2::dprivate::base_bidi_fd_watcher*, dasynq::rearm)
rearm process_primary_rearm(base_bidi_fd_watcher * bdfw, rearm rearm_type) noexcept
    {
        bool emulatedfd = static_cast<base_watcher *>(bdfw)->emulatefd;

        // Called with lock held
        if (rearm_type == rearm::REMOVE) {
            bdfw->read_removed = 1;

            if (backend_traits_t::has_separate_rw_fd_watches) {
                bdfw->watch_flags &= ~IN_EVENTS;
                if (! emulatedfd) {
                    loop_mech.remove_fd_watch_nolock(bdfw->watch_fd, IN_EVENTS);
                }
                return bdfw->write_removed ? rearm::REMOVE : rearm::NOOP;
            }
            else {
                if (! bdfw->write_removed) {
                    if (bdfw->watch_flags & IN_EVENTS) {
                        bdfw->watch_flags &= ~IN_EVENTS;
                        if (! emulatedfd) {
                            set_fd_enabled_nolock(bdfw, bdfw->watch_fd, bdfw->watch_flags,
                                    bdfw->watch_flags != 0);
                        }
                    }
                    return rearm::NOOP;
                }
                else {
                    // both removed: actually remove
                    if (! emulatedfd) {
                        loop_mech.remove_fd_watch_nolock(bdfw->watch_fd, 0 /* not used */);
                    }
                    return rearm::REMOVE;
                }
            }
        }
        else if (rearm_type == rearm::DISARM) {
            bdfw->watch_flags &= ~IN_EVENTS;

            if (! emulatedfd) {
                if (! backend_traits_t::has_separate_rw_fd_watches) {
                    int watch_flags = bdfw->watch_flags  & (IN_EVENTS | OUT_EVENTS);
                    set_fd_enabled_nolock(bdfw, bdfw->watch_fd, watch_flags, watch_flags != 0);
                }
                else {
                    loop_mech.disable_fd_watch_nolock(bdfw->watch_fd, IN_EVENTS);
                }
            }
        }
        else if (rearm_type == rearm::REARM) {
            if (! emulatedfd) {
                bdfw->watch_flags |= IN_EVENTS;
                if (! backend_traits_t::has_separate_rw_fd_watches) {
                    int watch_flags = bdfw->watch_flags;
                    set_fd_enabled_nolock(bdfw, bdfw->watch_fd,
                            watch_flags & (IN_EVENTS | OUT_EVENTS), true);
                }
                else {
                    set_fd_enabled_nolock(bdfw, bdfw->watch_fd, IN_EVENTS, true);
                }
            }
            else {
                bdfw->watch_flags &= ~IN_EVENTS;
                rearm_type = rearm::REQUEUE;
            }
        }
        else if (rearm_type == rearm::NOOP) {
            if (bdfw->emulatefd) {
                if (bdfw->watch_flags & IN_EVENTS) {
                    bdfw->watch_flags &= ~IN_EVENTS;
                    rearm_type = rearm::REQUEUE;
                }
            }
        }
        return rearm_type;
    }

// Assembly:
pushq %rbx
movl %edx, %ebx
cmpl $0x3, %edx
ja 0xbf1e
movq %rsi, %rax
movb 0xc(%rsi), %dl
movl %ebx, %ecx
leaq 0x211a5(%rip), %rsi     # 0x2d004
movslq (%rsi,%rcx,4), %rcx
addq %rsi, %rcx
jmpq *%rcx
movl 0x20(%rax), %ecx
testb $0x4, %dl
jne 0xbea2
orl $0x1, %ecx
movl %ecx, 0x20(%rax)
movl 0x1c(%rax), %esi
andl $0x3, %ecx
orl $0x8, %ecx
movq %rax, %rdx
callq 0xbdde
xorl %ebx, %ebx
jmp 0xbf1e
pushq $0x2
popq %rbx
testb $0x4, %dl
je 0xbf1e
movl 0x20(%rax), %ecx
testb $0x1, %cl
je 0xbf1e
andl $-0x2, %ecx
movl %ecx, 0x20(%rax)
pushq $0x5
popq %rbx
jmp 0xbf1e
movb 0x48(%rax), %cl
movl %ecx, %esi
orb $0x1, %sil
movb %sil, 0x48(%rax)
testb $0x2, %cl
jne 0xbf0c
movl 0x20(%rax), %ecx
pushq $0x2
popq %rbx
testb $0x1, %cl
je 0xbf1e
andl $-0x2, %ecx
movl %ecx, 0x20(%rax)
testb $0x4, %dl
jne 0xbf1e
movl 0x1c(%rax), %edx
xorl %r8d, %r8d
testl %ecx, %ecx
setne %r8b
jmp 0xbf02
movl 0x20(%rax), %ecx
movl %ecx, %esi
andl $-0x2, %esi
movl %esi, 0x20(%rax)
pushq $0x1
popq %rbx
testb $0x4, %dl
jne 0xbf1e
andl $0x2, %ecx
movl 0x1c(%rax), %edx
movl %ecx, %r8d
shrl %r8d
movq %rax, %rsi
callq 0xba8a
jmp 0xbf1e
pushq $0x3
popq %rbx
testb $0x4, %dl
jne 0xbf1e
movl 0x1c(%rax), %esi
xorl %edx, %edx
callq 0xbf22
movl %ebx, %eax
popq %rbx
retq