// File: /workspace/github_cpp_makefile_star2_O3/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
subq $0x10, %rsp
movl %ecx, %ebx
testb $0x4, 0xc(%rdx)
jne 0xc86d
testl %ebx, %ebx
je 0xc8c1
cmpl $0x1, %ebx
je 0xc88e
cmpl $0x3, %ebx
jne 0xc94b
movb 0x48(%rsi), %al
movl %eax, %ecx
orb $0x2, %cl
movb %cl, 0x48(%rsi)
testb $0x1, %al
jne 0xc931
movl 0x20(%rsi), %eax
movl $0x2, %ebx
testb $0x2, %al
je 0xc94b
movl %eax, %ecx
andl $-0x3, %ecx
movl %ecx, 0x20(%rsi)
movl 0x1c(%rsi), %edx
leaq 0x4(%rsp), %rcx
movq %rsi, 0x4(%rcx)
andl $0x1, %eax
orl $0x40000000, %eax       # imm = 0x40000000
movl %eax, (%rcx)
movl 0xa0(%rdi), %edi
movl $0x3, %esi
callq 0x8860
jmp 0xc94b
cmpl $0x3, %ebx
ja 0xc94b
movl %ebx, %eax
leaq 0x26795(%rip), %rcx     # 0x33014
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
andb $-0x3, 0x20(%rsi)
jmp 0xc908
movl 0x1c(%rsi), %edx
movl 0x20(%rsi), %eax
movl %eax, %ecx
andl $-0x3, %ecx
movl %ecx, 0x20(%rsi)
andl $0x1, %eax
leaq 0x4(%rsp), %rcx
movq %rsi, 0x4(%rcx)
orl $0x40000000, %eax       # imm = 0x40000000
movl %eax, (%rcx)
movl 0xa0(%rdi), %edi
movl $0x3, %esi
callq 0x8860
jmp 0xc92a
movl 0x1c(%rsi), %edx
movl 0x20(%rsi), %eax
movl %eax, %ecx
orl $0x2, %ecx
movl %ecx, 0x20(%rsi)
leaq 0x4(%rsp), %rcx
movq %rsi, 0x4(%rcx)
andl $0x1, %eax
orl $0x40000004, %eax       # imm = 0x40000004
movl %eax, (%rcx)
movl 0xa0(%rdi), %edi
movl $0x3, %esi
callq 0x8860
xorl %ebx, %ebx
jmp 0xc94b
movl 0x20(%rsi), %eax
movl $0x2, %ebx
testb $0x2, %al
je 0xc94b
andl $-0x3, %eax
movl %eax, 0x20(%rsi)
movl $0x5, %ebx
jmp 0xc94b
movzbl 0x48(%rsi), %ebx
movl %ebx, %eax
orb $0x2, %al
movb %al, 0x48(%rsi)
andb $-0x3, 0x20(%rsi)
andl $0x1, %ebx
orl $0x2, %ebx
jmp 0xc94b
andb $-0x3, 0x20(%rsi)
movl $0x1, %ebx
jmp 0xc94b
movl 0x1c(%rsi), %edx
movl 0xa0(%rdi), %edi
movl $0x2, %esi
xorl %ecx, %ecx
callq 0x8860
movl $0x3, %ebx
movl %ebx, %eax
addq $0x10, %rsp
popq %rbx
retq
nop