// File: /workspace/github_cpp_makefile_star2_O2/davmac314[P]dinit/src/service.cc
// Function: service_record::stop_dependents(bool, bool)
bool service_record::stop_dependents(bool for_restart, bool restart_deps) noexcept
{
    // We are in either STARTED or STARTING states.
    bool all_deps_stopped = true;
    for (auto dept : dependents) {
        if (dept->is_hard()) {
            service_record *dep_from = dept->get_from();

            if (!dep_from->is_fundamentally_stopped()) {
                // Note we check *first* since if the dependent service is not stopped,
                // 1. We will issue a stop to it shortly and
                // 2. It will notify us when stopped, at which point the stop_check_dependents()
                //    check is run anyway.
                all_deps_stopped = false;
            }

            if (force_stop) {
                // If this service is to be forcefully stopped, dependents must also be.
                if (desired_state == service_state_t::STOPPED) {
                    // If our target state was forced to STOPPED, this is a failure
                    dep_from->stop_reason = stopped_reason_t::DEPFAILED;
                    dep_from->unrecoverable_stop();
                }
                else {
                    dep_from->forced_stop();
                }
            }

            if (dep_from->get_state() != service_state_t::STOPPED) {
                if (desired_state == service_state_t::STOPPED) {
                    if (dep_from->desired_state != service_state_t::STOPPED) {
                        // if we don't want to restart, don't restart dependent
                        dep_from->desired_state = service_state_t::STOPPED;
                        if (dep_from->start_explicit) {
                            dep_from->start_explicit = false;
                            dep_from->release(true);
                        }
                        dep_from->prop_stop = true;
                        services->add_prop_queue(dep_from);
                    }
                }
                else if (restart_deps && dep_from->get_state() != service_state_t::STOPPING) {
                    // restart dependent and propagate restart to all their hard dependents.
                    dep_from->stop_reason = stopped_reason_t::DEPRESTART;
                    dep_from->in_user_restart = true;
                    dep_from->prop_stop = true;
                    services->add_prop_queue(dep_from);
                }
            }
        }
        // Note that soft dependencies are retained if restarting, but otherwise
        // they are broken.
        else if (!for_restart) {
            if (dept->waiting_on) {
                // Note, milestone which is still waiting is considered a hard dependency and
                // is handled above. This is therefore a true soft dependency, and we can just
                // break the dependency link.
                dept->waiting_on = false;
                dept->get_from()->dependency_started();
            }
            if (dept->holding_acq) {
                dept->holding_acq = false;
                release(false);
            }
        }
    }

    return all_deps_stopped;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movl %esi, 0x4(%rsp)
movq %rdi, %r14
leaq 0x130(%rdi), %rbp
movb $0x1, %r15b
xorb $0x1, %dl
movl %edx, (%rsp)
movq %rbp, %rbx
movq (%rbx), %rbx
cmpq %rbp, %rbx
je 0x1f38d
movq 0x10(%rbx), %r12
movl 0x14(%r12), %eax
testl %eax, %eax
je 0x1f24d
cmpl $0x3, %eax
jne 0x1f277
cmpb $0x1, 0x10(%r12)
jne 0x1f277
movq (%r12), %r13
movq %r13, %rdi
callq 0x1f600
movl %eax, %r12d
cmpb $0x1, 0x190(%r14)
jne 0x1f2c5
cmpb $0x0, 0x2d(%r14)
je 0x1f2b2
movq %r13, %rdi
callq 0x1f0d2
jmp 0x1f2c5
cmpb $0x0, 0x4(%rsp)
jne 0x1f227
cmpb $0x1, 0x10(%r12)
jne 0x1f295
movb $0x0, 0x10(%r12)
movq (%r12), %rdi
callq 0x1e54e
cmpb $0x1, 0x11(%r12)
jne 0x1f227
movb $0x0, 0x11(%r12)
movq %r14, %rdi
xorl %esi, %esi
callq 0x1e58e
jmp 0x1f227
movl $0x2, 0x1c4(%r13)
movq %r13, %rdi
callq 0x1f0c8
andb %r15b, %r12b
movb 0x2c(%r13), %al
movl %r12d, %r15d
testb %al, %al
je 0x1f227
cmpb $0x0, 0x2d(%r14)
je 0x1f307
cmpb $0x3, %al
sete %al
orb (%rsp), %al
movl %r12d, %r15d
jne 0x1f227
movl $0x1, 0x1c4(%r13)
orl $0x42000, 0x10c(%r13) # imm = 0x42000
jmp 0x1f351
cmpb $0x0, 0x2d(%r13)
movl %r12d, %r15d
je 0x1f227
movb $0x0, 0x2d(%r13)
movl 0x10c(%r13), %eax
btl $0x8, %eax
jae 0x1f345
andl $0xfffffeff, %eax       # imm = 0xFFFFFEFF
movl %eax, 0x10c(%r13)
movq %r13, %rdi
pushq $0x1
popq %rsi
callq 0x1e58e
movl 0x10c(%r13), %eax
orl $0x2000, %eax           # imm = 0x2000
movl %eax, 0x10c(%r13)
movq 0x148(%r14), %rax
cmpq $0x0, 0x1f8(%r13)
setne %dl
movq 0x38(%rax), %rcx
cmpq %r13, %rcx
sete %sil
orb %dl, %sil
movl %r12d, %r15d
jne 0x1f227
movq %rcx, 0x1f8(%r13)
movq %r13, 0x38(%rax)
movl %r12d, %r15d
jmp 0x1f227
andb $0x1, %r15b
movl %r15d, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop