// File: davmac314[P]dinit/src/proc-service.cc
// Function: ready_notify_watcher::fd_event(dasynq::v2::event_loop<dasynq::null_mutex, dasynq::v2::default_traits<dasynq::null_mutex>>&, int, int)
rearm ready_notify_watcher::fd_event(eventloop_t &, int fd, int flags) noexcept
{
    char buf[128];
    if (service->get_state() == service_state_t::STARTING) {
        // can we actually read anything from the notification pipe?
        int r = bp_sys::read(fd, buf, sizeof(buf));
        if (r > 0) {
            if (service->waiting_stopstart_timer) {
                service->process_timer.stop_timer(event_loop);
                service->waiting_stopstart_timer = false;
            }
            service->started();
        }
        else if (r == 0 || errno != EAGAIN) {
            if (service->waiting_stopstart_timer) {
                service->process_timer.stop_timer(event_loop);
                service->waiting_stopstart_timer = false;
            }
            service->set_state(service_state_t::STOPPING);
            service->failed_to_start(false, false);
            service->bring_down();
        }
        service->services->process_queues();
    }
    else {
        // Just keep consuming data from the pipe:
        int r = bp_sys::read(fd, buf, sizeof(buf));
        if (r == 0) {
            // Process closed write end or terminated
            close(fd);
            service->notification_fd = -1;
            return rearm::DISARM;
        }
    }

    return rearm::REARM;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xc0, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movl %edx, -0x1c(%rbp)
movl %ecx, -0x20(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0xb0(%rbp)
movq 0x28(%rax), %rdi
callq 0x2f0d0
cmpb $0x1, %al
jne 0x4fad1
movl -0x1c(%rbp), %edi
leaq -0xa0(%rbp), %rsi
movl $0x80, %edx
callq 0xaac0
movq %rax, -0xb8(%rbp)
jmp 0x4f992
movq -0xb8(%rbp), %rax
movl %eax, -0xa4(%rbp)
cmpl $0x0, -0xa4(%rbp)
jle 0x4fa11
movq -0xb0(%rbp), %rax
movq 0x28(%rax), %rax
movb 0x4f4(%rax), %al
shrb %al
andb $0x1, %al
testb $0x1, %al
je 0x4f9fc
movq -0xb0(%rbp), %rax
movq 0x28(%rax), %rdi
addq $0x3b0, %rdi            # imm = 0x3B0
leaq 0x59186(%rip), %rsi     # 0xa8b60
callq 0x529f0
movq -0xb0(%rbp), %rax
movq 0x28(%rax), %rax
movb 0x4f4(%rax), %cl
andb $-0x3, %cl
orb $0x0, %cl
movb %cl, 0x4f4(%rax)
movq -0xb0(%rbp), %rax
movq 0x28(%rax), %rdi
callq 0x4d570
jmp 0x4fab8
cmpl $0x0, -0xa4(%rbp)
je 0x4fa28
callq 0xa060
cmpl $0xb, (%rax)
je 0x4fab6
movq -0xb0(%rbp), %rax
movq 0x28(%rax), %rax
movb 0x4f4(%rax), %al
shrb %al
andb $0x1, %al
testb $0x1, %al
je 0x4fa7c
movq -0xb0(%rbp), %rax
movq 0x28(%rax), %rdi
addq $0x3b0, %rdi            # imm = 0x3B0
leaq 0x59106(%rip), %rsi     # 0xa8b60
callq 0x529f0
movq -0xb0(%rbp), %rax
movq 0x28(%rax), %rax
movb 0x4f4(%rax), %cl
andb $-0x3, %cl
orb $0x0, %cl
movb %cl, 0x4f4(%rax)
movq -0xb0(%rbp), %rax
movq 0x28(%rax), %rdi
movl $0x3, %esi
callq 0x52b70
movq -0xb0(%rbp), %rax
movq 0x28(%rax), %rdi
xorl %edx, %edx
movl %edx, %esi
callq 0x4cf90
movq -0xb0(%rbp), %rax
movq 0x28(%rax), %rdi
movq (%rdi), %rax
callq *0x8(%rax)
jmp 0x4fab8
movq -0xb0(%rbp), %rax
movq 0x28(%rax), %rax
movq 0x148(%rax), %rdi
callq 0x173c0
jmp 0x4fb2e
movl -0x1c(%rbp), %edi
leaq -0xa0(%rbp), %rsi
movl $0x80, %edx
callq 0xaac0
movq %rax, -0xc0(%rbp)
jmp 0x4faee
movq -0xc0(%rbp), %rax
movl %eax, -0xa8(%rbp)
cmpl $0x0, -0xa8(%rbp)
jne 0x4fb2c
movl -0x1c(%rbp), %edi
callq 0xad80
jmp 0x4fb0e
movq -0xb0(%rbp), %rax
movq 0x28(%rax), %rax
movl $0xffffffff, 0x4e8(%rax) # imm = 0xFFFFFFFF
movl $0x1, -0x4(%rbp)
jmp 0x4fb35
jmp 0x4fb2e
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0xc0, %rsp
popq %rbp
retq
movq %rax, %rdi
callq 0xfa30
nopl (%rax)