// File: /workspace/github_cpp_makefile_star2_O2/davmac314[P]dinit/src/service.cc
// Function: service_record::failed_to_start(bool, bool)
void service_record::failed_to_start(bool depfailed, bool immediate_stop) noexcept
{
    desired_state = service_state_t::STOPPED;

    if (waiting_for_console) {
        services->unqueue_console(this);
        waiting_for_console = false;
    }

    if (start_explicit) {
        start_explicit = false;
        release(false);
    }

    // Cancel start of dependents:
    for (auto & dept : dependents) {
        switch (dept->dep_type) {
        case dependency_type::REGULAR:
        case dependency_type::MILESTONE:
            // If REGULAR and STARTED, we can't have failed to start i.e. we must be started, so
            // we don't worry about that case. If MILESTONE and started the dependency is already
            // satisfied so again we don't need to do anything.
            if (dept->get_from()->service_state == service_state_t::STARTING) {
                dept->get_from()->prop_failure = true;
                services->add_prop_queue(dept->get_from());
            }
            break;
        case dependency_type::WAITS_FOR:
        case dependency_type::SOFT:
        case dependency_type::BEFORE:
        case dependency_type::AFTER:
            if (dept->waiting_on) {
                dept->waiting_on = false;
                dept->get_from()->dependency_started();
            }
        }

        // Always release now, so that our desired state will be STOPPED before we call
        // stopped() below (if we do so). Otherwise it may decide to restart us.
        if (dept->holding_acq) {
            dept->holding_acq = false;
            release(false);
        }
    }

    start_failed = true;
    log_service_failed(get_name(), depfailed);
    notify_listeners(service_event_t::FAILEDSTART);
    pinned_started = false;

    if (immediate_stop) {
        stopped();
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movl %edx, %ebp
movl %esi, %r14d
movq %rdi, %rbx
movb $0x0, 0x2d(%rdi)
movl 0x10c(%rdi), %eax
testb $0x20, %al
je 0x1ed6d
movq 0x148(%rbx), %rdi
movq %rbx, %rsi
callq 0x1f5ce
movl 0x10c(%rbx), %eax
andl $-0x21, %eax
movl %eax, 0x10c(%rbx)
btl $0x8, %eax
jae 0x1ed88
andl $0xfffffeff, %eax       # imm = 0xFFFFFEFF
movl %eax, 0x10c(%rbx)
movq %rbx, %rdi
xorl %esi, %esi
callq 0x1e58e
leaq 0x130(%rbx), %r15
pushq $0x36
popq %r12
movq %r15, %r13
movq (%r13), %r13
cmpq %r15, %r13
je 0x1ee2f
movq 0x10(%r13), %rax
movl 0x14(%rax), %ecx
cmpl $0x5, %ecx
ja 0x1ee0e
btl %ecx, %r12d
jae 0x1edc9
cmpb $0x1, 0x10(%rax)
jne 0x1ee0e
movb $0x0, 0x10(%rax)
movq (%rax), %rdi
callq 0x1e54e
jmp 0x1ee0e
movq (%rax), %rax
cmpb $0x1, 0x2c(%rax)
jne 0x1ee0e
orb $0x8, 0x10d(%rax)
movq 0x148(%rbx), %rax
movq 0x10(%r13), %rcx
movq (%rcx), %rcx
cmpq $0x0, 0x1f8(%rcx)
setne %sil
movq 0x38(%rax), %rdx
cmpq %rcx, %rdx
sete %dil
orb %sil, %dil
jne 0x1ee0e
movq %rdx, 0x1f8(%rcx)
movq %rcx, 0x38(%rax)
movq 0x10(%r13), %rax
cmpb $0x1, 0x11(%rax)
jne 0x1ed96
movb $0x0, 0x11(%rax)
movq %rbx, %rdi
xorl %esi, %esi
callq 0x1e58e
jmp 0x1ed96
orb $-0x80, 0x10d(%rbx)
movq 0x8(%rbx), %rdi
movzbl %r14b, %esi
callq 0x2906f
pushq $0x2
popq %rsi
movq %rbx, %rdi
callq 0x1f59e
andb $-0x5, 0x10c(%rbx)
testb %bpl, %bpl
je 0x1ee70
movq %rbx, %rdi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x1e30a
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop