// File: /workspace/github_cpp_makefile_star2_O1/davmac314[P]dinit/src/proc-service.cc
// Function: process_service::handle_exit_status()
void process_service::handle_exit_status() noexcept
{
    bool did_exit = exit_status.did_exit();
    bool was_signalled = exit_status.was_signalled();
    auto current_state = get_state();

    if (notification_fd != -1) {
        readiness_watcher.deregister(event_loop);
        bp_sys::close(notification_fd);
        notification_fd = -1;
    }

    if (!exit_status.did_exit_clean() && current_state != service_state_t::STOPPING) {
        if (did_exit) {
            log(loglevel_t::ERROR, "Service ", get_name(), " process terminated with exit code ",
                    exit_status.get_exit_status());
        }
        else if (was_signalled) {
            log(loglevel_t::ERROR, "Service ", get_name(), " terminated due to signal ",
                    exit_status.get_signal());
        }
    }

    if (waiting_stopstart_timer) {
        process_timer.stop_timer(event_loop);
        waiting_stopstart_timer = false;
        if (current_state == service_state_t::STARTED) {
            // Must have been in smooth recovery and waiting for readiness notification.
            // Treat this the same as if we were STARTING:
            current_state = service_state_t::STARTING;
        }
    }

#if USE_UTMPX
    if (*inittab_id || *inittab_line) {
        clear_utmp_entry(inittab_id, inittab_line);
    }
#endif

    if (current_state == service_state_t::STARTING) {
        // If state is STARTING, we must be waiting for readiness notification; the process has
        // terminated before becoming ready.
        stop_reason = stopped_reason_t::FAILED;
        failed_to_start();
    }
    else if (current_state == service_state_t::STOPPING) {
        // We won't log a non-zero exit status or termination due to signal here -
        // we assume that the process died because we signalled it.
        if (waiting_stopstart_timer) {
            process_timer.stop_timer(event_loop);
        }
        if (!waiting_for_deps) {
            if (stop_pid == -1 && !waiting_for_execstat) {
                stop_issued = false; // reset for next time
                stopped();
            }
        }
        else if (get_target_state() == service_state_t::STARTED && !pinned_stopped) {
            initiate_start();
        }
    }
    else if (smooth_recovery && current_state == service_state_t::STARTED && check_restart()) {
        // unexpected termination, with smooth recovery
        doing_smooth_recovery = true;
        do_smooth_recovery();
        return;
    }
    else {
        handle_unexpected_termination();
    }
    services->process_queues();
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %rbx
subq $0x18, %rsp
movq %rdi, %rbx
movl 0x4dc(%rdi), %r14d
movb 0x2c(%rdi), %r15b
cmpl $-0x1, 0x4e8(%rdi)
je 0x24265
leaq 0x510(%rbx), %rsi
movl 0x52c(%rbx), %edx
leaq 0x227e5(%rip), %rdi     # 0x46a30
callq 0xda6a
movl 0x4e8(%rbx), %edi
callq 0x8b60
movl $0xffffffff, 0x4e8(%rbx) # imm = 0xFFFFFFFF
movl 0x4e0(%rbx), %ebp
testl %ebp, %ebp
sete %al
cmpb $0x3, %r15b
sete %cl
orb %al, %cl
jne 0x242d5
leaq 0x11816(%rip), %rsi     # 0x35a98
movl $0x3, %edi
callq 0x2e63a
movq 0x8(%rbx), %rdi
callq 0x2e73d
cmpl $0x1, %r14d
jne 0x242a4
leaq 0x1183a(%rip), %rdi     # 0x35adc
jmp 0x242ab
leaq 0x118d8(%rip), %rdi     # 0x35b83
callq 0x2e73d
leaq 0x12525(%rip), %rdx     # 0x367dc
leaq 0xc(%rsp), %r14
movl $0xc, %esi
movq %r14, %rdi
movl %ebp, %ecx
xorl %eax, %eax
callq 0x89e0
movq %r14, %rdi
callq 0x2e759
testb $0x2, 0x4f4(%rbx)
je 0x24310
movl 0x3fc(%rbx), %edx
leaq 0x3d0(%rbx), %rsi
leaq 0x2273e(%rip), %rdi     # 0x46a30
callq 0x25df4
andb $-0x3, 0x4f4(%rbx)
cmpb $0x2, %r15b
movzbl %r15b, %eax
movl $0x1, %r15d
cmovnel %eax, %r15d
movb 0x5cc(%rbx), %al
orb 0x5c8(%rbx), %al
je 0x24331
leaq 0x5c8(%rbx), %rdi
leaq 0x5cc(%rbx), %rsi
callq 0x2569a
cmpb $0x3, %r15b
je 0x2435e
movzbl %r15b, %eax
cmpl $0x1, %eax
jne 0x243a8
movl $0x3, 0x1c4(%rbx)
movq %rbx, %rdi
xorl %esi, %esi
movl $0x1, %edx
callq 0x23018
jmp 0x243f1
testb $0x2, 0x4f4(%rbx)
je 0x24380
movl 0x3fc(%rbx), %edx
leaq 0x3d0(%rbx), %rsi
leaq 0x226b5(%rip), %rdi     # 0x46a30
callq 0x25df4
movl 0x10c(%rbx), %eax
testb $0x10, %al
jne 0x243df
testb %al, %al
js 0x243f1
cmpl $-0x1, 0x504(%rbx)
jne 0x243f1
andb $-0x3, 0x500(%rbx)
movq %rbx, %rdi
callq 0x224b2
jmp 0x243f1
cmpb $0x2, %r15b
jne 0x243d5
testb $0x1, 0x10c(%rbx)
je 0x243d5
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x28(%rax)
testb %al, %al
je 0x243d5
movb $0x1, 0x5b8(%rbx)
movq %rbx, %rdi
callq 0x263c8
jmp 0x243fd
movq %rbx, %rdi
callq 0x2710c
jmp 0x243f1
testb $0x2, %al
jne 0x243f1
cmpb $0x2, 0x2d(%rbx)
jne 0x243f1
movq %rbx, %rdi
callq 0x22856
movq 0x148(%rbx), %rdi
callq 0xd8da
addq $0x18, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rdi
callq 0xb8be