// File: 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
movq %rsp, %rbp
subq $0x50, %rsp
movb %dl, %al
movb %sil, %cl
movq %rdi, -0x8(%rbp)
andb $0x1, %cl
movb %cl, -0x9(%rbp)
andb $0x1, %al
movb %al, -0xa(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x40(%rbp)
movb $0x1, -0xb(%rbp)
addq $0x130, %rax            # imm = 0x130
movq %rax, -0x18(%rbp)
movq -0x18(%rbp), %rdi
callq 0x304d0
movq %rax, -0x20(%rbp)
movq -0x18(%rbp), %rdi
callq 0x30530
movq %rax, -0x28(%rbp)
leaq -0x20(%rbp), %rdi
leaq -0x28(%rbp), %rsi
callq 0x30500
testb $0x1, %al
jne 0x4d9a2
jmp 0x4db93
leaq -0x20(%rbp), %rdi
callq 0x30590
movq (%rax), %rax
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rdi
callq 0x4e1f0
movb %al, -0x41(%rbp)
jmp 0x4d9c0
movb -0x41(%rbp), %al
testb $0x1, %al
jne 0x4d9cc
jmp 0x4db39
movq -0x30(%rbp), %rdi
callq 0x30420
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rdi
callq 0x4e5b0
testb $0x1, %al
jne 0x4d9ea
movb $0x0, -0xb(%rbp)
movq -0x40(%rbp), %rax
testb $0x1, 0x190(%rax)
je 0x4da25
movq -0x40(%rbp), %rax
cmpb $0x0, 0x2d(%rax)
jne 0x4da1a
movq -0x38(%rbp), %rax
movl $0x2, 0x1c4(%rax)
movq -0x38(%rbp), %rdi
callq 0x4d730
jmp 0x4da23
movq -0x38(%rbp), %rdi
callq 0x4d750
jmp 0x4da25
movq -0x38(%rbp), %rdi
callq 0x2f0d0
cmpb $0x0, %al
je 0x4db37
movq -0x40(%rbp), %rax
cmpb $0x0, 0x2d(%rax)
jne 0x4dac6
movq -0x38(%rbp), %rax
cmpb $0x0, 0x2d(%rax)
je 0x4dac4
movq -0x38(%rbp), %rax
movb $0x0, 0x2d(%rax)
movq -0x38(%rbp), %rax
movl 0x10c(%rax), %eax
shrl $0x8, %eax
andl $0x1, %eax
testl $0x1, %eax
je 0x4da94
movq -0x38(%rbp), %rax
movl 0x10c(%rax), %ecx
andl $0xfffffeff, %ecx       # imm = 0xFFFFFEFF
orl $0x0, %ecx
movl %ecx, 0x10c(%rax)
movq -0x38(%rbp), %rdi
movl $0x1, %esi
callq 0x4c070
movq -0x40(%rbp), %rax
movq -0x38(%rbp), %rcx
movl 0x10c(%rcx), %edx
andl $0xffffdfff, %edx       # imm = 0xFFFFDFFF
orl $0x2000, %edx           # imm = 0x2000
movl %edx, 0x10c(%rcx)
movq 0x148(%rax), %rdi
movq -0x38(%rbp), %rsi
callq 0x4e320
jmp 0x4db35
testb $0x1, -0xa(%rbp)
je 0x4db33
movq -0x38(%rbp), %rdi
callq 0x2f0d0
cmpb $0x3, %al
je 0x4db33
movq -0x40(%rbp), %rax
movq -0x38(%rbp), %rcx
movl $0x1, 0x1c4(%rcx)
movq -0x38(%rbp), %rcx
movl 0x10c(%rcx), %edx
andl $0xfffbffff, %edx       # imm = 0xFFFBFFFF
orl $0x40000, %edx          # imm = 0x40000
movl %edx, 0x10c(%rcx)
movq -0x38(%rbp), %rcx
movl 0x10c(%rcx), %edx
andl $0xffffdfff, %edx       # imm = 0xFFFFDFFF
orl $0x2000, %edx           # imm = 0x2000
movl %edx, 0x10c(%rcx)
movq 0x148(%rax), %rdi
movq -0x38(%rbp), %rsi
callq 0x4e320
jmp 0x4db35
jmp 0x4db37
jmp 0x4db83
testb $0x1, -0x9(%rbp)
jne 0x4db81
movq -0x30(%rbp), %rax
testb $0x1, 0x10(%rax)
je 0x4db62
movq -0x30(%rbp), %rax
movb $0x0, 0x10(%rax)
movq -0x30(%rbp), %rdi
callq 0x30420
movq %rax, %rdi
callq 0x4c010
movq -0x30(%rbp), %rax
testb $0x1, 0x11(%rax)
je 0x4db7f
movq -0x40(%rbp), %rdi
movq -0x30(%rbp), %rax
movb $0x0, 0x11(%rax)
xorl %esi, %esi
callq 0x4c070
jmp 0x4db81
jmp 0x4db83
jmp 0x4db85
leaq -0x20(%rbp), %rdi
callq 0x306a0
jmp 0x4d98c
movb -0xb(%rbp), %al
andb $0x1, %al
addq $0x50, %rsp
popq %rbp
retq
movq %rax, %rdi
callq 0xfa30
nopw %cs:(%rax,%rax)