// File: /workspace/github_cpp_makefile_star2_O3/davmac314[P]dinit/src/service.cc
// Function: service_record::stopped()
void service_record::stopped() noexcept
{
    if (have_console) {
        bp_sys::tcsetpgrp(0, bp_sys::getpgrp());
        release_console();
    }

    force_stop = false;

    // If we are to re-start, restarting should have been set true and desired_state should be STARTED.
    // (A restart could be cancelled via a separately issued stop, including via a shutdown).
    bool will_restart = desired_state == service_state_t::STARTED && !pinned_stopped;

    // If we won't restart, break soft dependencies now
    if (!will_restart) {
        for (auto dept : dependents) {
            if (!dept->is_hard()) {
                // waits-for or soft dependency:
                if (dept->waiting_on) {
                    dept->waiting_on = false;
                    dept->get_from()->dependency_started();
                }
                if (dept->holding_acq) {
                    dept->holding_acq = false;
                    // release without issuing stop, since we're called only when this
                    // service is already stopped/stopping:
                    release(false);
                }
            }
        }
    }

    for (auto & dependency : depends_on) {
        // we signal dependencies in case they are waiting for us to stop:
        dependency.get_to()->dependent_stopped();
    }

    service_state = service_state_t::STOPPED;

    if (will_restart) {
        // Desired state is "started".
        initiate_start();
    }
    else {
        becoming_inactive();

        if (start_explicit) {
            // If we were explicitly started, our required_by count must be at least 1. Use
            // release() to correctly release, mark inactive and release dependencies.
            start_explicit = false;
            release(false);
        }
        else if (required_by == 0) {
            // This can only be the case if we didn't have start_explicit, since required_by would
            // otherwise by non-zero. Since our release(s) above were with state != STOPPED, we now
            // must mark inactive (i.e. it won't have been done as part of the release).
            services->service_inactive(this);
        }
    }

    // Start failure will have been logged already, only log if we are stopped for other reasons:
    if (!start_failed) {
        log_service_stopped(service_name);

        // If this service chains to another, start the chained service now, if:
        // - this service self-terminated (rather than being stopped),
        // - ... successfully (i.e. exit code 0)
        // - this service won't restart, and
        // - a shutdown isn't in progress
        if ((onstart_flags.always_chain || (did_finish(stop_reason)
                && get_exit_status().did_exit_clean() && !will_restart))
                && !start_on_completion.empty() && !services->is_shutting_down()) {
            try {
                auto chain_to = services->load_service(start_on_completion.c_str());
                chain_to->start();
            }
            catch (service_load_exc &sle) {
                log(loglevel_t::ERROR, "Couldn't chain to service ", start_on_completion, ": ",
                        "couldn't load ", sle.service_name, ": ", sle.exc_description);
            }
            catch (std::bad_alloc &bae) {
                log(loglevel_t::ERROR, "Couldn't chain to service ", start_on_completion,
                        ": Out of memory");
            }
        }
    }
    notify_listeners(service_event_t::STOPPED);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
movq %rdi, %rbx
movl 0x10c(%rdi), %eax
testb $0x40, %al
je 0x227ce
callq 0x8190
xorl %edi, %edi
movl %eax, %esi
callq 0x88c0
andb $-0x41, 0x10c(%rbx)
movq 0x148(%rbx), %rdi
callq 0x23cd2
movl 0x10c(%rbx), %eax
movb $0x0, 0x190(%rbx)
cmpb $0x2, 0x2d(%rbx)
sete %cl
testb $0x2, %al
sete %bpl
andb %cl, %bpl
je 0x22856
leaq 0x118(%rbx), %rax
movq 0x118(%rbx), %rcx
cmpq %rax, %rcx
je 0x22840
movq 0x18(%rcx), %rdx
cmpb $0x3, 0x2c(%rdx)
jne 0x2283b
testb $0x10, 0x10c(%rdx)
je 0x2283b
movq 0x148(%rdx), %rsi
cmpq $0x0, 0x200(%rdx)
setne %r8b
movq 0x40(%rsi), %rdi
cmpq %rdx, %rdi
sete %r9b
orb %r8b, %r9b
jne 0x2283b
movq %rdi, 0x200(%rdx)
movq %rdx, 0x40(%rsi)
movq (%rcx), %rcx
jmp 0x227f5
movb $0x0, 0x2c(%rbx)
testb %bpl, %bpl
je 0x228bf
movq %rbx, %rdi
callq 0x22b3a
jmp 0x228fe
leaq 0x130(%rbx), %r14
movq 0x130(%rbx), %r15
cmpq %r14, %r15
je 0x227e7
movq 0x10(%r15), %r12
movl 0x14(%r12), %eax
testl %eax, %eax
je 0x228ba
cmpl $0x3, %eax
jne 0x2288a
movb 0x10(%r12), %al
testb %al, %al
je 0x2288f
jmp 0x228ba
movb 0x10(%r12), %al
testb $0x1, %al
je 0x228a2
movb $0x0, 0x10(%r12)
movq (%r12), %rdi
callq 0x229e4
cmpb $0x1, 0x11(%r12)
jne 0x228ba
movb $0x0, 0x11(%r12)
movq %rbx, %rdi
xorl %esi, %esi
callq 0x22a24
movq (%r15), %r15
jmp 0x22864
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x20(%rax)
movl 0x10c(%rbx), %eax
btl $0x8, %eax
jb 0x228e9
cmpl $0x0, 0x110(%rbx)
jne 0x228fe
movq 0x148(%rbx), %rax
decl 0x8(%rax)
jmp 0x228fe
andl $0xfffffeff, %eax       # imm = 0xFFFFFEFF
movl %eax, 0x10c(%rbx)
movq %rbx, %rdi
xorl %esi, %esi
callq 0x22a24
testb $-0x80, 0x10d(%rbx)
jne 0x22963
movq 0x8(%rbx), %rdi
callq 0x2e700
testb $0x4, 0x2f(%rbx)
jne 0x22934
cmpl $0x6, 0x1c4(%rbx)
jne 0x22963
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x50(%rax)
shrq $0x20, %rax
setne %al
orb %al, %bpl
jne 0x22963
cmpq $0x0, 0x1d0(%rbx)
je 0x22963
movq 0x148(%rbx), %rdi
cmpb $0x1, 0x28(%rdi)
jne 0x22963
leaq 0x1c8(%rbx), %r14
movq (%r14), %rsi
movq (%rdi), %rax
callq *0x10(%rax)
movq %rax, %rdi
callq 0x22b92
movq 0x160(%rbx), %r14
testq %r14, %r14
je 0x22985
movq 0x8(%r14), %rdi
movq (%rdi), %rax
movq %rbx, %rsi
movl $0x1, %edx
callq *(%rax)
movq (%r14), %r14
jmp 0x2296a
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
cmpl $0x3, %edx
jne 0x229ac
movq %rax, %rdi
callq 0x8210
leaq 0x20(%rax), %rdx
movq %r14, %rdi
movq %rax, %rsi
callq 0x22be7
jmp 0x229c1
cmpl $0x2, %edx
jne 0x229c8
movq %rax, %rdi
callq 0x8210
movq %r14, %rdi
callq 0x22bbd
callq 0x8a50
jmp 0x22963
movq %rax, %rdi
callq 0xb74e