// File: /workspace/github_cpp_makefile_star2_O1/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 %rbx
movl %ecx, %ebx
movq %rsi, %rax
testb $0x4, 0xc(%rdx)
jne 0xca16
testl %ebx, %ebx
je 0xca4a
cmpl $0x1, %ebx
je 0xca37
cmpl $0x3, %ebx
jne 0xcabd
movb 0x48(%rax), %cl
movl %ecx, %edx
orb $0x2, %dl
movb %dl, 0x48(%rax)
testb $0x1, %cl
jne 0xcaa3
movl 0x20(%rax), %ecx
movl $0x2, %ebx
testb $0x2, %cl
je 0xcabd
andl $-0x3, %ecx
movl %ecx, 0x20(%rax)
movl 0x1c(%rax), %esi
jmp 0xca59
cmpl $0x3, %ebx
ja 0xcabd
movl %ebx, %ecx
leaq 0x26608(%rip), %rdx     # 0x33030
movslq (%rdx,%rcx,4), %rcx
addq %rdx, %rcx
jmpq *%rcx
andb $-0x3, 0x20(%rax)
jmp 0xca79
movl 0x1c(%rax), %esi
movl 0x20(%rax), %ecx
movl %ecx, %edx
andl $-0x3, %edx
movl %edx, 0x20(%rax)
andl $0x1, %ecx
jmp 0xca59
movl 0x1c(%rax), %esi
movl 0x20(%rax), %ecx
orl $0x2, %ecx
movl %ecx, 0x20(%rax)
andl $0x3, %ecx
orl $0x8, %ecx
movq %rax, %rdx
callq 0xc7ec
jmp 0xcabd
movl 0x20(%rax), %ecx
movl $0x2, %ebx
testb $0x2, %cl
je 0xcabd
andl $-0x3, %ecx
movl %ecx, 0x20(%rax)
movl $0x5, %ebx
jmp 0xcabd
movzbl 0x48(%rax), %ebx
movl %ebx, %ecx
orb $0x2, %cl
movb %cl, 0x48(%rax)
andb $-0x3, 0x20(%rax)
andl $0x1, %ebx
orl $0x2, %ebx
jmp 0xcabd
andb $-0x3, 0x20(%rax)
movl $0x1, %ebx
jmp 0xcabd
movl 0x1c(%rax), %edx
movl 0xa0(%rdi), %edi
movl $0x2, %esi
xorl %ecx, %ecx
callq 0x8860
movl $0x3, %ebx
movl %ebx, %eax
popq %rbx
retq
nop