// File: /workspace/github_c_makefile_star2_O2/msteveb[P]autosetup/./jimsh0.c
// Function: Jim_WaitCommand
static int Jim_WaitCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
    struct WaitInfoTable *table = Jim_CmdPrivData(interp);
    int nohang = 0;
    long pid;
    phandle_t phandle;
    int status;
    Jim_Obj *errCodeObj;


    if (argc == 1) {
        JimReapDetachedPids(table);
        return JIM_OK;
    }

    if (argc > 1 && Jim_CompareStringImmediate(interp, argv[1], "-nohang")) {
        nohang = 1;
    }
    if (argc != nohang + 2) {
        Jim_WrongNumArgs(interp, 1, argv, "?-nohang? ?pid?");
        return JIM_ERR;
    }
    if (Jim_GetLong(interp, argv[nohang + 1], &pid) != JIM_OK) {
        return JIM_ERR;
    }


    phandle = JimWaitPid(pid, &status, nohang ? WNOHANG : 0);
    if (phandle == JIM_BAD_PHANDLE) {
        pid = -1;
    }
#ifndef __MINGW32__
    else if (pid < 0) {
        pid = phandle;
    }
#endif

    errCodeObj = JimMakeErrorCode(interp, pid, status, NULL);

    if (phandle != JIM_BAD_PHANDLE && (WIFEXITED(status) || WIFSIGNALED(status))) {

        JimWaitRemove(table, phandle);
    }
    Jim_SetResult(interp, errCodeObj);
    return JIM_OK;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq 0x1b8(%rdi), %rbx
cmpl $0x1, %esi
jne 0x9b08
testq %rbx, %rbx
je 0x9bff
movq (%rbx), %r13
movl 0xc(%rbx), %r15d
pushq $0x1
popq %r12
xorl %r14d, %r14d
testl %r15d, %r15d
jle 0x9bff
testb $0x2, 0x8(%r13)
je 0x9adf
movl (%r13), %edi
leaq -0x38(%rbp), %rsi
movl %r12d, %edx
callq 0x6420
testl %eax, %eax
jle 0x9adf
decl 0xc(%rbx)
jmp 0x9aff
movslq %r14d, %rax
imulq $0xc, %rax, %rax
addq (%rbx), %rax
cmpq %rax, %r13
je 0x9afc
movl 0x8(%r13), %ecx
movl %ecx, 0x8(%rax)
movq (%r13), %rcx
movq %rcx, (%rax)
incl %r14d
addq $0xc, %r13
decl %r15d
jmp 0x9ab6
movq %rdx, %r12
movl %esi, %r13d
movq %rdi, %r14
xorl %r15d, %r15d
cmpl $0x2, %esi
jl 0x9b30
movq 0x8(%r12), %rsi
leaq 0x1df0f(%rip), %rdx     # 0x27a34
movq %r14, %rdi
callq 0x7223
movl %eax, %r15d
movl %r15d, %eax
orl $0x2, %eax
cmpl %r13d, %eax
jne 0x9b5b
movl %r15d, %eax
movq 0x8(%r12,%rax,8), %rsi
leaq -0x38(%rbp), %rdx
movq %r14, %rdi
callq 0xc8cb
testl %eax, %eax
je 0x9b77
pushq $0x1
popq %rbx
jmp 0x9c01
leaq 0x1deda(%rip), %rcx     # 0x27a3c
pushq $0x1
popq %rbx
movq %r14, %rdi
movl %ebx, %esi
movq %r12, %rdx
callq 0x72a5
jmp 0x9c01
movq -0x38(%rbp), %r12
leaq -0x30(%rbp), %r13
movl %r12d, %edi
movq %r13, %rsi
movl %r15d, %edx
callq 0x6420
testq %r12, %r12
movl %eax, -0x2c(%rbp)
movslq %eax, %r15
cmovsq %r15, %r12
cmpl $-0x1, %r15d
pushq $-0x1
popq %rsi
cmovneq %r12, %rsi
movl (%r13), %edx
movq %r14, %rdi
xorl %ecx, %ecx
callq 0x14ea4
movq %rax, %r12
cmpl $-0x1, %r15d
je 0x9bde
movl -0x30(%rbp), %eax
andl $0x7f, %eax
je 0x9bd3
shll $0x18, %eax
addl $0x1000000, %eax        # imm = 0x1000000
cmpl $0x2000000, %eax        # imm = 0x2000000
jl 0x9bde
movq %rbx, %rdi
movl -0x2c(%rbp), %esi
callq 0x14e42
incl 0x10(%r12)
movq (%r14), %rsi
movl 0x10(%rsi), %eax
leal -0x1(%rax), %ecx
movl %ecx, 0x10(%rsi)
cmpl $0x1, %eax
jg 0x9bfc
movq %r14, %rdi
callq 0x73bf
movq %r12, (%r14)
xorl %ebx, %ebx
movl %ebx, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq