// File: 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
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, -0x38(%rbp)
movb $0x0, 0x2d(%rax)
movl 0x10c(%rax), %eax
shrl $0x5, %eax
andl $0x1, %eax
testl $0x1, %eax
je 0x4cff1
movq -0x38(%rbp), %rsi
movq 0x148(%rsi), %rdi
callq 0x4e460
movq -0x38(%rbp), %rax
movl 0x10c(%rax), %ecx
andl $-0x21, %ecx
orl $0x0, %ecx
movl %ecx, 0x10c(%rax)
movq -0x38(%rbp), %rax
movl 0x10c(%rax), %eax
shrl $0x8, %eax
andl $0x1, %eax
testl $0x1, %eax
je 0x4d027
movq -0x38(%rbp), %rdi
movl 0x10c(%rdi), %eax
andl $0xfffffeff, %eax       # imm = 0xFFFFFEFF
orl $0x0, %eax
movl %eax, 0x10c(%rdi)
xorl %esi, %esi
callq 0x4c070
movq -0x38(%rbp), %rax
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 0x4d065
jmp 0x4d16e
leaq -0x20(%rbp), %rdi
callq 0x30590
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rax
movq (%rax), %rax
movl 0x14(%rax), %eax
movl %eax, -0x3c(%rbp)
testl %eax, %eax
je 0x4d0ab
jmp 0x4d085
movl -0x3c(%rbp), %eax
decl %eax
subl $0x2, %eax
jb 0x4d10d
jmp 0x4d091
movl -0x3c(%rbp), %eax
subl $0x3, %eax
je 0x4d0ab
jmp 0x4d09b
movl -0x3c(%rbp), %eax
addl $-0x4, %eax
subl $0x2, %eax
jb 0x4d10d
jmp 0x4d13b
movq -0x30(%rbp), %rax
movq (%rax), %rdi
callq 0x30420
cmpb $0x1, 0x2c(%rax)
jne 0x4d10b
movq -0x30(%rbp), %rax
movq (%rax), %rdi
callq 0x30420
movq %rax, %rcx
movq -0x38(%rbp), %rax
movl 0x10c(%rcx), %edx
andl $0xfffff7ff, %edx       # imm = 0xFFFFF7FF
orl $0x800, %edx            # imm = 0x800
movl %edx, 0x10c(%rcx)
movq 0x148(%rax), %rax
movq %rax, -0x48(%rbp)
movq -0x30(%rbp), %rax
movq (%rax), %rdi
callq 0x30420
movq -0x48(%rbp), %rdi
movq %rax, %rsi
callq 0x4e320
jmp 0x4d13b
movq -0x30(%rbp), %rax
movq (%rax), %rax
testb $0x1, 0x10(%rax)
je 0x4d139
movq -0x30(%rbp), %rax
movq (%rax), %rax
movb $0x0, 0x10(%rax)
movq -0x30(%rbp), %rax
movq (%rax), %rdi
callq 0x30420
movq %rax, %rdi
callq 0x4c010
jmp 0x4d13b
movq -0x30(%rbp), %rax
movq (%rax), %rax
testb $0x1, 0x11(%rax)
je 0x4d15e
movq -0x38(%rbp), %rdi
movq -0x30(%rbp), %rax
movq (%rax), %rax
movb $0x0, 0x11(%rax)
xorl %esi, %esi
callq 0x4c070
jmp 0x4d160
leaq -0x20(%rbp), %rdi
callq 0x306a0
jmp 0x4d04f
movq -0x38(%rbp), %rdi
movl 0x10c(%rdi), %eax
andl $0xffff7fff, %eax       # imm = 0xFFFF7FFF
orl $0x8000, %eax           # imm = 0x8000
movl %eax, 0x10c(%rdi)
callq 0x2d420
movq %rax, %rdi
movb -0x9(%rbp), %al
andb $0x1, %al
movzbl %al, %esi
callq 0x4d6f0
movq -0x38(%rbp), %rdi
movl $0x2, %esi
callq 0x4e2a0
movq -0x38(%rbp), %rax
movl 0x10c(%rax), %ecx
andl $-0x5, %ecx
orl $0x0, %ecx
movl %ecx, 0x10c(%rax)
testb $0x1, -0xa(%rbp)
je 0x4d1d0
movq -0x38(%rbp), %rdi
callq 0x4bb20
addq $0x50, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)