// File: davmac314[P]dinit/src/../dasynq/include/dasynq.h
// Function: dasynq::v2::event_loop<dasynq::null_mutex, dasynq::v2::default_traits<dasynq::null_mutex>>::register_fd(dasynq::v2::dprivate::base_bidi_fd_watcher*, int, int, bool)
void register_fd(base_bidi_fd_watcher *callback, int fd, int eventmask, bool emulate = false)
    {
        std::lock_guard<mutex_t> guard(loop_mech.lock);

        loop_mech.prepare_watcher(callback);
        try {
            loop_mech.prepare_watcher(&callback->out_watcher);
            try {
                bool do_interrupt = false;
                if (backend_traits_t::has_separate_rw_fd_watches) {
                    int r = loop_mech.add_bidi_fd_watch(fd, callback, eventmask | ONE_SHOT, emulate);
                    if (r & IN_EVENTS) {
                        callback->emulatefd = true;
                        if (eventmask & IN_EVENTS) {
                            callback->watch_flags &= ~IN_EVENTS;
                            requeue_watcher(callback);
                        }
                    }
                    else if ((eventmask & IN_EVENTS) && backend_traits_t::interrupt_after_fd_add) {
                        do_interrupt = true;
                    }

                    if (r & OUT_EVENTS) {
                        callback->out_watcher.emulatefd = true;
                        if (eventmask & OUT_EVENTS) {
                            callback->watch_flags &= ~OUT_EVENTS;
                            requeue_watcher(&callback->out_watcher);
                        }
                    }
                    else if ((eventmask & OUT_EVENTS) && backend_traits_t::interrupt_after_fd_add) {
                        do_interrupt = true;
                    }
                }
                else {
                    if (! loop_mech.add_fd_watch(fd, callback, eventmask | ONE_SHOT, true, emulate)) {
                        callback->emulatefd = true;
                        callback->out_watcher.emulatefd = true;
                        if (eventmask & IN_EVENTS) {
                            callback->watch_flags &= ~IN_EVENTS;
                            requeue_watcher(callback);
                        }
                        if (eventmask & OUT_EVENTS) {
                            callback->watch_flags &= ~OUT_EVENTS;
                            requeue_watcher(&callback->out_watcher);
                        }
                    }
                    else if (backend_traits_t::interrupt_after_fd_add) {
                        do_interrupt = true;
                    }
                }

                if (do_interrupt) {
                    interrupt_if_necessary();
                }
            }
            catch (...) {
                loop_mech.release_watcher(&callback->out_watcher);
                throw;
            }
        }
        catch (...) {
            loop_mech.release_watcher(callback);
            throw;
        }
    }

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movb %r8b, %al
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
movl %ecx, -0x18(%rbp)
andb $0x1, %al
movb %al, -0x19(%rbp)
movq -0x8(%rbp), %rsi
movq %rsi, -0x40(%rbp)
addq $0x28, %rsi
leaq -0x28(%rbp), %rdi
callq 0x11d10
movq -0x40(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x13850
jmp 0x13682
movq -0x40(%rbp), %rdi
movq -0x10(%rbp), %rsi
addq $0x28, %rsi
callq 0x13850
jmp 0x13695
movq -0x40(%rbp), %rdi
movb $0x0, -0x35(%rbp)
movl -0x14(%rbp), %esi
movq -0x10(%rbp), %rdx
movl -0x18(%rbp), %ecx
orl $0x8, %ecx
movzbl -0x19(%rbp), %r9d
andl $0x1, %r9d
movl $0x1, %r8d
callq 0x13880
movb %al, -0x41(%rbp)
jmp 0x136c3
movb -0x41(%rbp), %al
testb $0x1, %al
jne 0x13794
jmp 0x136d0
movq -0x10(%rbp), %rax
movb 0xc(%rax), %cl
andb $-0x5, %cl
orb $0x4, %cl
movb %cl, 0xc(%rax)
movq -0x10(%rbp), %rax
movb 0x34(%rax), %cl
andb $-0x5, %cl
orb $0x4, %cl
movb %cl, 0x34(%rax)
movl -0x18(%rbp), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x13769
movq -0x40(%rbp), %rdi
movq -0x10(%rbp), %rax
movl 0x20(%rax), %ecx
andl $-0x2, %ecx
movl %ecx, 0x20(%rax)
movq -0x10(%rbp), %rsi
callq 0x11f40
jmp 0x13769
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
jmp 0x13803
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
jmp 0x137c0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
movq -0x30(%rbp), %rdi
callq 0xa240
movq -0x40(%rbp), %rdi
movq -0x10(%rbp), %rsi
addq $0x28, %rsi
callq 0x12ea0
callq 0xaaf0
jmp 0x1381d
movl -0x18(%rbp), %eax
andl $0x2, %eax
cmpl $0x0, %eax
je 0x13792
movq -0x40(%rbp), %rdi
movq -0x10(%rbp), %rax
movl 0x20(%rax), %ecx
andl $-0x3, %ecx
movl %ecx, 0x20(%rax)
movq -0x10(%rbp), %rsi
addq $0x28, %rsi
callq 0x11f40
jmp 0x13796
jmp 0x13796
testb $0x1, -0x35(%rbp)
je 0x137a9
movq -0x40(%rbp), %rdi
callq 0x11fc0
jmp 0x137a7
jmp 0x137a9
jmp 0x137dd
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
callq 0xac30
jmp 0x137be
jmp 0x137c0
movq -0x30(%rbp), %rdi
callq 0xa240
movq -0x40(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x12ea0
callq 0xaaf0
jmp 0x1381d
jmp 0x137f4
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
callq 0xac30
jmp 0x137f2
jmp 0x13803
leaq -0x28(%rbp), %rdi
callq 0x11ec0
addq $0x50, %rsp
popq %rbp
retq
leaq -0x28(%rbp), %rdi
callq 0x11ec0
movq -0x30(%rbp), %rdi
callq 0xacc0
movq %rax, %rdi
callq 0xfa30
nopl (%rax)