// File: /workspace/github_cpp_makefile_star2_O1/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
testb $0x40, 0x10c(%rdi)
je 0x224e7
callq 0x8190
xorl %edi, %edi
movl %eax, %esi
callq 0x88c0
andb $-0x41, 0x10c(%rbx)
movq 0x148(%rbx), %rdi
callq 0x239d6
movb $0x0, 0x190(%rbx)
cmpb $0x2, 0x2d(%rbx)
sete %al
movl 0x10c(%rbx), %ecx
testb $0x2, %cl
sete %bpl
andb %al, %bpl
je 0x22576
leaq 0x118(%rbx), %rax
movq 0x118(%rbx), %rcx
cmpq %rax, %rcx
je 0x22560
movq 0x18(%rcx), %rdx
cmpb $0x3, 0x2c(%rdx)
jne 0x2255b
testb $0x10, 0x10c(%rdx)
je 0x2255b
movq 0x148(%rdx), %rsi
cmpq $0x0, 0x200(%rdx)
setne %r8b
movq 0x40(%rsi), %rdi
cmpq %rdx, %rdi
sete %r9b
orb %r8b, %r9b
jne 0x2255b
movq %rdi, 0x200(%rdx)
movq %rdx, 0x40(%rsi)
movq (%rcx), %rcx
jmp 0x22515
movb $0x0, 0x2c(%rbx)
testb %bpl, %bpl
je 0x225db
movq %rbx, %rdi
callq 0x22856
jmp 0x2261a
leaq 0x130(%rbx), %r14
movq 0x130(%rbx), %r15
cmpq %r14, %r15
je 0x22507
movq 0x10(%r15), %r12
movl 0x14(%r12), %eax
testl %eax, %eax
je 0x225d6
cmpl $0x3, %eax
jne 0x225a7
cmpb $0x0, 0x10(%r12)
jne 0x225d6
cmpb $0x1, 0x10(%r12)
jne 0x225be
movb $0x0, 0x10(%r12)
movq (%r12), %rdi
callq 0x22700
cmpb $0x1, 0x11(%r12)
jne 0x225d6
movb $0x0, 0x11(%r12)
movq %rbx, %rdi
xorl %esi, %esi
callq 0x22740
movq (%r15), %r15
jmp 0x22584
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x20(%rax)
movl 0x10c(%rbx), %eax
btl $0x8, %eax
jb 0x22605
cmpl $0x0, 0x110(%rbx)
jne 0x2261a
movq 0x148(%rbx), %rax
decl 0x8(%rax)
jmp 0x2261a
andl $0xfffffeff, %eax       # imm = 0xFFFFFEFF
movl %eax, 0x10c(%rbx)
movq %rbx, %rdi
xorl %esi, %esi
callq 0x22740
testb $-0x80, 0x10d(%rbx)
jne 0x2267f
movq 0x8(%rbx), %rdi
callq 0x2e913
testb $0x4, 0x2f(%rbx)
jne 0x22650
cmpl $0x6, 0x1c4(%rbx)
jne 0x2267f
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x50(%rax)
shrq $0x20, %rax
setne %al
orb %al, %bpl
jne 0x2267f
cmpq $0x0, 0x1d0(%rbx)
je 0x2267f
movq 0x148(%rbx), %rdi
cmpb $0x1, 0x28(%rdi)
jne 0x2267f
leaq 0x1c8(%rbx), %r14
movq (%r14), %rsi
movq (%rdi), %rax
callq *0x10(%rax)
movq %rax, %rdi
callq 0x228ae
movq 0x160(%rbx), %r14
testq %r14, %r14
je 0x226a1
movq 0x8(%r14), %rdi
movq (%rdi), %rax
movq %rbx, %rsi
movl $0x1, %edx
callq *(%rax)
movq (%r14), %r14
jmp 0x22686
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
cmpl $0x3, %edx
jne 0x226c8
movq %rax, %rdi
callq 0x8210
leaq 0x20(%rax), %rdx
movq %r14, %rdi
movq %rax, %rsi
callq 0x22903
jmp 0x226dd
cmpl $0x2, %edx
jne 0x226e4
movq %rax, %rdi
callq 0x8210
movq %r14, %rdi
callq 0x228d9
callq 0x8a50
jmp 0x2267f
movq %rax, %rdi
callq 0xb8be