// File: 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 %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movl %edx, -0x1c(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x30(%rbp)
movq -0x18(%rbp), %rax
movb 0xc(%rax), %al
shrb $0x2, %al
andb $0x1, %al
movzbl %al, %eax
cmpl $0x0, %eax
setne %al
andb $0x1, %al
movb %al, -0x1d(%rbp)
cmpl $0x3, -0x1c(%rbp)
jne 0x12cc4
movq -0x18(%rbp), %rax
movb 0x48(%rax), %cl
andb $-0x2, %cl
orb $0x1, %cl
movb %cl, 0x48(%rax)
movq -0x18(%rbp), %rax
movb 0x48(%rax), %al
shrb %al
andb $0x1, %al
movzbl %al, %eax
cmpl $0x0, %eax
jne 0x12ca0
movq -0x18(%rbp), %rax
movl 0x20(%rax), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x12c94
movq -0x18(%rbp), %rax
movl 0x20(%rax), %ecx
andl $-0x2, %ecx
movl %ecx, 0x20(%rax)
testb $0x1, -0x1d(%rbp)
jne 0x12c92
movq -0x30(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x18(%rbp), %rax
movl 0x1c(%rax), %edx
movq -0x18(%rbp), %rax
movl 0x20(%rax), %ecx
movq -0x18(%rbp), %rax
cmpl $0x0, 0x20(%rax)
setne %al
movzbl %al, %r8d
andl $0x1, %r8d
callq 0x11e60
jmp 0x12c94
movl $0x2, -0x4(%rbp)
jmp 0x12dbd
testb $0x1, -0x1d(%rbp)
jne 0x12cb8
movq -0x30(%rbp), %rdi
movq -0x18(%rbp), %rax
movl 0x1c(%rax), %esi
xorl %edx, %edx
callq 0x12dd0
movl $0x3, -0x4(%rbp)
jmp 0x12dbd
cmpl $0x1, -0x1c(%rbp)
jne 0x12d15
movq -0x18(%rbp), %rax
movl 0x20(%rax), %ecx
andl $-0x2, %ecx
movl %ecx, 0x20(%rax)
testb $0x1, -0x1d(%rbp)
jne 0x12d10
movq -0x30(%rbp), %rdi
movq -0x18(%rbp), %rax
movl 0x20(%rax), %eax
andl $0x3, %eax
movl %eax, -0x24(%rbp)
movq -0x18(%rbp), %rsi
movq -0x18(%rbp), %rax
movl 0x1c(%rax), %edx
movl -0x24(%rbp), %ecx
cmpl $0x0, -0x24(%rbp)
setne %al
movzbl %al, %r8d
andl $0x1, %r8d
callq 0x11e60
jmp 0x12db5
cmpl $0x0, -0x1c(%rbp)
jne 0x12d70
testb $0x1, -0x1d(%rbp)
jne 0x12d5a
movq -0x30(%rbp), %rdi
movq -0x18(%rbp), %rax
movl 0x20(%rax), %ecx
orl $0x1, %ecx
movl %ecx, 0x20(%rax)
movq -0x18(%rbp), %rax
movl 0x20(%rax), %eax
movl %eax, -0x28(%rbp)
movq -0x18(%rbp), %rsi
movq -0x18(%rbp), %rax
movl 0x1c(%rax), %edx
movl -0x28(%rbp), %ecx
andl $0x3, %ecx
movl $0x1, %r8d
callq 0x11e60
jmp 0x12d6e
movq -0x18(%rbp), %rax
movl 0x20(%rax), %ecx
andl $-0x2, %ecx
movl %ecx, 0x20(%rax)
movl $0x5, -0x1c(%rbp)
jmp 0x12db3
cmpl $0x2, -0x1c(%rbp)
jne 0x12db1
movq -0x18(%rbp), %rax
movb 0xc(%rax), %al
shrb $0x2, %al
andb $0x1, %al
movzbl %al, %eax
cmpl $0x0, %eax
je 0x12daf
movq -0x18(%rbp), %rax
movl 0x20(%rax), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x12dad
movq -0x18(%rbp), %rax
movl 0x20(%rax), %ecx
andl $-0x2, %ecx
movl %ecx, 0x20(%rax)
movl $0x5, -0x1c(%rbp)
jmp 0x12daf
jmp 0x12db1
jmp 0x12db3
jmp 0x12db5
jmp 0x12db7
movl -0x1c(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x30, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)