// 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_secondary_rearm(dasynq::v2::dprivate::base_bidi_fd_watcher*, dasynq::v2::dprivate::base_watcher*, dasynq::rearm)
rearm process_secondary_rearm(base_bidi_fd_watcher * bdfw, base_watcher * outw, rearm rearm_type) noexcept
    {
        bool emulatedfd = outw->emulatefd;

        // Called with lock held
        if (emulatedfd) {
            if (rearm_type == rearm::REMOVE) {
                bdfw->write_removed = 1;
                bdfw->watch_flags &= ~OUT_EVENTS;
                rearm_type = bdfw->read_removed ? rearm::REMOVE : rearm::NOOP;
            }
            else if (rearm_type == rearm::DISARM) {
                bdfw->watch_flags &= ~OUT_EVENTS;
            }
            else if (rearm_type == rearm::REARM) {
                bdfw->watch_flags &= ~OUT_EVENTS;
                rearm_type = rearm::REQUEUE;
            }
            else if (rearm_type == rearm::NOOP) {
                if (bdfw->watch_flags & OUT_EVENTS) {
                    bdfw->watch_flags &= ~OUT_EVENTS;
                    rearm_type = rearm::REQUEUE;
                }
            }
            return rearm_type;
        }
        else if (rearm_type == rearm::REMOVE) {
            bdfw->write_removed = 1;

            if (backend_traits_t::has_separate_rw_fd_watches) {
                bdfw->watch_flags &= ~OUT_EVENTS;
                loop_mech.remove_fd_watch_nolock(bdfw->watch_fd, OUT_EVENTS);
                return bdfw->read_removed ? rearm::REMOVE : rearm::NOOP;
            }
            else {
                if (! bdfw->read_removed) {
                    if (bdfw->watch_flags & OUT_EVENTS) {
                        bdfw->watch_flags &= ~OUT_EVENTS;
                        set_fd_enabled_nolock(bdfw, bdfw->watch_fd, bdfw->watch_flags, true);
                    }
                    return rearm::NOOP;
                }
                else {
                    // both removed: actually remove
                    loop_mech.remove_fd_watch_nolock(bdfw->watch_fd, 0 /* not used */);
                    return rearm::REMOVE;
                }
            }
        }
        else if (rearm_type == rearm::DISARM) {
            bdfw->watch_flags &= ~OUT_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 {
                loop_mech.disable_fd_watch_nolock(bdfw->watch_fd, OUT_EVENTS);
            }
        }
        else if (rearm_type == rearm::REARM) {
            bdfw->watch_flags |= OUT_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, OUT_EVENTS | ONE_SHOT, true);
            }
        }
        return rearm_type;
    }

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movl %ecx, -0x24(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x38(%rbp)
movq -0x20(%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, -0x25(%rbp)
testb $0x1, -0x25(%rbp)
je 0x13134
cmpl $0x3, -0x24(%rbp)
jne 0x130c7
movq -0x18(%rbp), %rax
movb 0x48(%rax), %cl
andb $-0x3, %cl
orb $0x2, %cl
movb %cl, 0x48(%rax)
movq -0x18(%rbp), %rax
movl 0x20(%rax), %ecx
andl $-0x3, %ecx
movl %ecx, 0x20(%rax)
movq -0x18(%rbp), %rax
movb 0x48(%rax), %al
andb $0x1, %al
movzbl %al, %edx
movl $0x2, %eax
movl $0x3, %ecx
cmpl $0x0, %edx
cmovnel %ecx, %eax
movl %eax, -0x24(%rbp)
jmp 0x13129
cmpl $0x1, -0x24(%rbp)
jne 0x130dc
movq -0x18(%rbp), %rax
movl 0x20(%rax), %ecx
andl $-0x3, %ecx
movl %ecx, 0x20(%rax)
jmp 0x13127
cmpl $0x0, -0x24(%rbp)
jne 0x130f8
movq -0x18(%rbp), %rax
movl 0x20(%rax), %ecx
andl $-0x3, %ecx
movl %ecx, 0x20(%rax)
movl $0x5, -0x24(%rbp)
jmp 0x13125
cmpl $0x2, -0x24(%rbp)
jne 0x13123
movq -0x18(%rbp), %rax
movl 0x20(%rax), %eax
andl $0x2, %eax
cmpl $0x0, %eax
je 0x13121
movq -0x18(%rbp), %rax
movl 0x20(%rax), %ecx
andl $-0x3, %ecx
movl %ecx, 0x20(%rax)
movl $0x5, -0x24(%rbp)
jmp 0x13123
jmp 0x13125
jmp 0x13127
jmp 0x13129
movl -0x24(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x1324e
cmpl $0x3, -0x24(%rbp)
jne 0x131c6
movq -0x18(%rbp), %rax
movb 0x48(%rax), %cl
andb $-0x3, %cl
orb $0x2, %cl
movb %cl, 0x48(%rax)
movq -0x18(%rbp), %rax
movb 0x48(%rax), %al
andb $0x1, %al
movzbl %al, %eax
cmpl $0x0, %eax
jne 0x131a8
movq -0x18(%rbp), %rax
movl 0x20(%rax), %eax
andl $0x2, %eax
cmpl $0x0, %eax
je 0x1319c
movq -0x38(%rbp), %rdi
movq -0x18(%rbp), %rax
movl 0x20(%rax), %ecx
andl $-0x3, %ecx
movl %ecx, 0x20(%rax)
movq -0x18(%rbp), %rsi
movq -0x18(%rbp), %rax
movl 0x1c(%rax), %edx
movq -0x18(%rbp), %rax
movl 0x20(%rax), %ecx
movl $0x1, %r8d
callq 0x11e60
movl $0x2, -0x4(%rbp)
jmp 0x1324e
movq -0x38(%rbp), %rdi
movq -0x18(%rbp), %rax
movl 0x1c(%rax), %esi
xorl %edx, %edx
callq 0x12dd0
movl $0x3, -0x4(%rbp)
jmp 0x1324e
cmpl $0x1, -0x24(%rbp)
jne 0x13205
movq -0x38(%rbp), %rdi
movq -0x18(%rbp), %rax
movl 0x20(%rax), %ecx
andl $-0x3, %ecx
movl %ecx, 0x20(%rax)
movq -0x18(%rbp), %rax
movl 0x20(%rax), %eax
movl %eax, -0x2c(%rbp)
movq -0x18(%rbp), %rsi
movq -0x18(%rbp), %rax
movl 0x1c(%rax), %edx
movl -0x2c(%rbp), %ecx
andl $0x3, %ecx
movl $0x1, %r8d
callq 0x11e60
jmp 0x13244
cmpl $0x0, -0x24(%rbp)
jne 0x13242
movq -0x38(%rbp), %rdi
movq -0x18(%rbp), %rax
movl 0x20(%rax), %ecx
orl $0x2, %ecx
movl %ecx, 0x20(%rax)
movq -0x18(%rbp), %rax
movl 0x20(%rax), %eax
movl %eax, -0x30(%rbp)
movq -0x18(%rbp), %rsi
movq -0x18(%rbp), %rax
movl 0x1c(%rax), %edx
movl -0x30(%rbp), %ecx
andl $0x3, %ecx
movl $0x1, %r8d
callq 0x11e60
jmp 0x13244
jmp 0x13246
jmp 0x13248
movl -0x24(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x40, %rsp
popq %rbp
retq
nopw (%rax,%rax)