// File: /workspace/github_cpp_makefile_star2_O3/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 0x2451f
leaq 0x510(%rbx), %rsi
movl 0x52c(%rbx), %edx
leaq 0x2252b(%rip), %rdi     # 0x46a30
callq 0xd520
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 0x2458f
leaq 0x11513(%rip), %rsi     # 0x35a4f
movl $0x3, %edi
callq 0x2e412
movq 0x8(%rbx), %rdi
callq 0x2e520
cmpl $0x1, %r14d
jne 0x2455e
leaq 0x11537(%rip), %rdi     # 0x35a93
jmp 0x24565
leaq 0x115d5(%rip), %rdi     # 0x35b3a
callq 0x2e520
leaq 0x1223b(%rip), %rdx     # 0x367ac
leaq 0xc(%rsp), %r14
movl $0xc, %esi
movq %r14, %rdi
movl %ebp, %ecx
xorl %eax, %eax
callq 0x89e0
movq %r14, %rdi
callq 0x2e53c
testb $0x2, 0x4f4(%rbx)
je 0x245ca
movl 0x3fc(%rbx), %edx
leaq 0x3d0(%rbx), %rsi
leaq 0x22484(%rip), %rdi     # 0x46a30
callq 0x25f62
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 0x245eb
leaq 0x5c8(%rbx), %rdi
leaq 0x5cc(%rbx), %rsi
callq 0x2581a
cmpb $0x3, %r15b
je 0x24618
movzbl %r15b, %eax
cmpl $0x1, %eax
jne 0x24662
movl $0x3, 0x1c4(%rbx)
movq %rbx, %rdi
xorl %esi, %esi
movl $0x1, %edx
callq 0x23316
jmp 0x246ab
testb $0x2, 0x4f4(%rbx)
je 0x2463a
movl 0x3fc(%rbx), %edx
leaq 0x3d0(%rbx), %rsi
leaq 0x223fb(%rip), %rdi     # 0x46a30
callq 0x25f62
movl 0x10c(%rbx), %eax
testb $0x10, %al
jne 0x24699
testb %al, %al
js 0x246ab
cmpl $-0x1, 0x504(%rbx)
jne 0x246ab
andb $-0x3, 0x500(%rbx)
movq %rbx, %rdi
callq 0x22792
jmp 0x246ab
cmpb $0x2, %r15b
jne 0x2468f
testb $0x1, 0x10c(%rbx)
je 0x2468f
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x28(%rax)
testb %al, %al
je 0x2468f
movb $0x1, 0x5b8(%rbx)
movq %rbx, %rdi
callq 0x2652c
jmp 0x246b7
movq %rbx, %rdi
callq 0x2716c
jmp 0x246ab
testb $0x2, %al
jne 0x246ab
cmpb $0x2, 0x2d(%rbx)
jne 0x246ab
movq %rbx, %rdi
callq 0x22b3a
movq 0x148(%rbx), %rdi
callq 0xd37e
addq $0x18, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rdi
callq 0xb74e