// File: /workspace/github_cpp_makefile_star2_O2/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 %r14
pushq %rbx
subq $0x10, %rsp
movq %rdi, %rbx
movl 0x4dc(%rdi), %r14d
movb 0x2c(%rdi), %bpl
cmpl $-0x1, 0x4e8(%rdi)
je 0x1fea0
leaq 0x510(%rbx), %rdi
leaq 0x25ba7(%rip), %rsi     # 0x45a30
callq 0xd002
movl 0x4e8(%rbx), %edi
callq 0x8b50
orl $-0x1, 0x4e8(%rbx)
movl 0x4e0(%rbx), %eax
testl %eax, %eax
sete %cl
cmpb $0x3, %bpl
sete %dl
orb %cl, %dl
jne 0x1feda
leaq 0x8(%rbx), %rdi
cmpl $0x1, %r14d
jne 0x1fece
leaq 0xc(%rsp), %rsi
movl %eax, (%rsi)
callq 0x20006
jmp 0x1feda
leaq 0x8(%rsp), %rsi
movl %eax, (%rsi)
callq 0x20042
testb $0x2, 0x4f4(%rbx)
je 0x1ff0b
leaq 0x3b0(%rbx), %rdi
leaq 0x25b3f(%rip), %rsi     # 0x45a30
callq 0x20f92
andb $-0x3, 0x4f4(%rbx)
cmpb $0x2, %bpl
movzbl %bpl, %eax
pushq $0x1
popq %rbp
cmovnel %eax, %ebp
movb 0x5cc(%rbx), %al
orb 0x5c8(%rbx), %al
je 0x1ff2c
leaq 0x5c8(%rbx), %rdi
leaq 0x5cc(%rbx), %rsi
callq 0x21042
cmpb $0x3, %bpl
je 0x1ff57
movzbl %bpl, %eax
cmpl $0x1, %eax
jne 0x1ff9b
movl $0x3, 0x1c4(%rbx)
pushq $0x1
popq %rdx
movq %rbx, %rdi
xorl %esi, %esi
callq 0x1ed2e
jmp 0x1ffea
testb $0x2, 0x4f4(%rbx)
je 0x1ff73
leaq 0x3b0(%rbx), %rdi
leaq 0x25ac2(%rip), %rsi     # 0x45a30
callq 0x20f92
movl 0x10c(%rbx), %eax
testb $0x10, %al
jne 0x1ffd8
testb %al, %al
js 0x1ffea
cmpl $-0x1, 0x504(%rbx)
jne 0x1ffea
andb $-0x3, 0x500(%rbx)
movq %rbx, %rdi
callq 0x1e30a
jmp 0x1ffea
cmpb $0x2, %bpl
jne 0x1ffce
testb $0x1, 0x10c(%rbx)
je 0x1ffce
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x28(%rax)
testb %al, %al
je 0x1ffce
movb $0x1, 0x5b8(%rbx)
movq %rbx, %rdi
addq $0x10, %rsp
popq %rbx
popq %r14
popq %rbp
jmp 0x21c8c
movq %rbx, %rdi
callq 0x227e6
jmp 0x1ffea
testb $0x2, %al
jne 0x1ffea
cmpb $0x2, 0x2d(%rbx)
jne 0x1ffea
movq %rbx, %rdi
callq 0x1e684
movq 0x148(%rbx), %rdi
addq $0x10, %rsp
popq %rbx
popq %r14
popq %rbp
jmp 0xcdd2
movq %rax, %rdi
callq 0xaebb