// File: /workspace/github_cpp_makefile_star2_O2/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 $0x10, %rsp
cmpl $-0x1, 0x504(%rdi)
jne 0x20af9
movq %rdi, %rbx
testb $0x2, 0x500(%rdi)
jne 0x20af9
testb $-0x80, 0x10c(%rbx)
jne 0x20af9
cmpl $-0x1, 0x4d8(%rbx)
je 0x20a5b
cmpq $0x0, 0x238(%rbx)
je 0x20a87
leaq 0x240(%rbx), %rsi
movq %rbx, %rdi
callq 0x20b00
testb %al, %al
jne 0x20ab8
movl 0x194(%rbx), %eax
testl %eax, %eax
pushq $0x9
popq %rsi
cmovnel %eax, %esi
jmp 0x20a91
movb $0x0, 0x5b8(%rbx)
testb $0x1, 0x4f4(%rbx)
je 0x20aab
leaq 0x3b0(%rbx), %rdi
leaq 0x24fb7(%rip), %rsi     # 0x45a30
callq 0x20f92
andb $-0x2, 0x4f4(%rbx)
jmp 0x20aab
movl 0x194(%rbx), %esi
testl %esi, %esi
je 0x20a99
movq %rbx, %rdi
callq 0x22e4c
cmpl $-0x1, 0x504(%rbx)
jne 0x20ab8
testb $0x8, 0x4f4(%rbx)
jne 0x20ab8
movq %rbx, %rdi
addq $0x10, %rsp
popq %rbx
jmp 0x1e30a
orb $0x2, 0x500(%rbx)
movq 0x488(%rbx), %rax
movq 0x490(%rbx), %rcx
movq %rax, %rdx
orq %rcx, %rdx
je 0x20af9
leaq 0x3b0(%rbx), %rdi
movq %rsp, %rdx
movq %rax, (%rdx)
movq %rcx, 0x8(%rdx)
leaq 0x24f43(%rip), %rsi     # 0x45a30
callq 0xd186
orb $0x2, 0x4f4(%rbx)
addq $0x10, %rsp
popq %rbx
retq
nop