// 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_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 0xbfc8
testl %ebx, %ebx
je 0xc007
cmpl $0x1, %ebx
je 0xbfe9
cmpl $0x3, %ebx
jne 0xc068
movb 0x48(%rax), %cl
movl %ecx, %edx
orb $0x2, %dl
movb %dl, 0x48(%rax)
testb $0x1, %cl
jne 0xc051
movl 0x20(%rax), %ecx
pushq $0x2
popq %rbx
testb $0x2, %cl
je 0xc068
andl $-0x3, %ecx
movl %ecx, 0x20(%rax)
movl 0x1c(%rax), %esi
orl $0x8, %ecx
movq %rax, %rdx
callq 0xbdde
jmp 0xc068
cmpl $0x3, %ebx
ja 0xc068
movl %ebx, %ecx
leaq 0x2103a(%rip), %rdx     # 0x2d014
movslq (%rdx,%rcx,4), %rcx
addq %rdx, %rcx
jmpq *%rcx
andb $-0x3, 0x20(%rax)
jmp 0xc065
movl 0x1c(%rax), %esi
movl 0x20(%rax), %ecx
movl %ecx, %edx
andl $-0x3, %edx
movl %edx, 0x20(%rax)
andl $0x1, %ecx
orl $0x8, %ecx
movq %rax, %rdx
callq 0xbdde
jmp 0xc04d
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 0xbdde
xorl %ebx, %ebx
jmp 0xc068
movl 0x20(%rax), %ecx
testb $0x2, %cl
jne 0xc05f
pushq $0x2
jmp 0xc067
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 0xc068
andb $-0x3, 0x20(%rax)
pushq $0x1
jmp 0xc067
movl 0x1c(%rax), %esi
xorl %edx, %edx
callq 0xbf22
pushq $0x3
jmp 0xc067
andl $-0x3, %ecx
movl %ecx, 0x20(%rax)
pushq $0x5
popq %rbx
movl %ebx, %eax
popq %rbx
retq