// File: /workspace/github_cpp_makefile_star2_O3/davmac314[P]dinit/src/proc-service.cc
// Function: process_service::bring_down()
void process_service::bring_down() noexcept
{
    if (stop_pid != -1 || stop_issued) {
        // waiting for stop command to complete (or for process to die after it has complete);
        // can't do anything here.
        return;
    }
    if (waiting_for_execstat) {
        // The process is still starting. This should be uncommon, but can occur during
        // smooth recovery (or it may mean the stop command process is still starting). We can't
        // do much now; we have to wait until we get the status, and then act appropriately.
        return;
    }
    else if (pid != -1) {
        // The process is still kicking on - must actually kill it.
        if (!stop_command.empty() && !stop_issued) {
            if (start_stop_process(stop_arg_parts)) {
                goto arm_timer;
            }

            // stop-command failed, need to try something else:
            if (term_signal != 0) {
                kill_pg(term_signal);
            }
            else {
                kill_pg(SIGKILL);
            }
        }
        else if (term_signal != 0) {
            // We signal the process group (-pid) rather than just the process as there's less
            // risk then of creating an orphaned process group:
            kill_pg(term_signal);
        }

        if (stop_pid == -1 && !tracking_child) {
            // If we have no way of tracking when the child terminates, assume stopped now
            stopped();
            return;
        }

        arm_timer:

        stop_issued = true; // (don't try again)

        // If there's a stop timeout, arm the timer now:
        if (stop_timeout != time_val(0,0)) {
            process_timer.arm_timer_rel(event_loop, stop_timeout);
            waiting_stopstart_timer = true;
        }

        // The rest is done in handle_exit_status.
    }
    else {
        // The process is already dead (possibly, we are in smooth recovery waiting for timer)
        doing_smooth_recovery = false;
        if (waiting_restart_timer) {
            process_timer.stop_timer(event_loop);
            waiting_restart_timer = false;
        }
        stopped();
    }
}

// Assembly:
pushq %rbx
subq $0x20, %rsp
cmpl $-0x1, 0x504(%rdi)
jne 0x252f5
movq %rdi, %rbx
testb $0x2, 0x500(%rdi)
jne 0x252f5
testb $-0x80, 0x10c(%rbx)
jne 0x252f5
cmpl $-0x1, 0x4d8(%rbx)
je 0x25239
cmpq $0x0, 0x238(%rbx)
je 0x2526b
leaq 0x240(%rbx), %rsi
movq %rbx, %rdi
callq 0x252fc
testb %al, %al
jne 0x2529c
movl 0x194(%rbx), %eax
testl %eax, %eax
movl $0x9, %esi
cmovnel %eax, %esi
jmp 0x25275
movb $0x0, 0x5b8(%rbx)
testb $0x1, 0x4f4(%rbx)
je 0x2528f
movl 0x3fc(%rbx), %edx
leaq 0x3d0(%rbx), %rsi
leaq 0x217d3(%rip), %rdi     # 0x46a30
callq 0x25f62
andb $-0x2, 0x4f4(%rbx)
jmp 0x2528f
movl 0x194(%rbx), %esi
testl %esi, %esi
je 0x2527d
movq %rbx, %rdi
callq 0x27940
cmpl $-0x1, 0x504(%rbx)
jne 0x2529c
testb $0x8, 0x4f4(%rbx)
jne 0x2529c
movq %rbx, %rdi
addq $0x20, %rsp
popq %rbx
jmp 0x22792
orb $0x2, 0x500(%rbx)
movq 0x488(%rbx), %rax
movq 0x490(%rbx), %rdi
movq %rax, %rcx
orq %rdi, %rcx
je 0x252f5
movl 0x3fc(%rbx), %r9d
xorps %xmm0, %xmm0
movq %rsp, %rcx
movaps %xmm0, (%rcx)
leaq 0x3d0(%rbx), %rsi
leaq 0x10(%rsp), %rdx
movq %rax, (%rdx)
movq %rdi, 0x8(%rdx)
leaq 0x2174d(%rip), %rdi     # 0x46a30
movl $0x1, %r8d
callq 0xd65c
orb $0x2, 0x4f4(%rbx)
addq $0x20, %rsp
popq %rbx
retq
nop