// File: /workspace/github_c_makefile_star2_O3/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
pushq %rax
movq 0x1b8(%rdi), %rbx
cmpl $0x1, %esi
jne 0xa206
xorl %r13d, %r13d
testq %rbx, %rbx
je 0xa324
movl 0xc(%rbx), %r15d
testl %r15d, %r15d
jle 0xa324
movq (%rbx), %r12
incl %r15d
xorl %r13d, %r13d
leaq -0x30(%rbp), %r14
testb $0x2, 0x8(%r12)
je 0xa1cf
movl (%r12), %edi
movq %r14, %rsi
movl $0x1, %edx
callq 0x6420
testl %eax, %eax
jle 0xa1cf
decl 0xc(%rbx)
jmp 0xa1f4
movslq %r13d, %rax
leaq (%rax,%rax,2), %rax
shlq $0x2, %rax
addq (%rbx), %rax
cmpq %rax, %r12
je 0xa1f1
movl 0x8(%r12), %ecx
movl %ecx, 0x8(%rax)
movq (%r12), %rcx
movq %rcx, (%rax)
incl %r13d
addq $0xc, %r12
decl %r15d
cmpl $0x1, %r15d
jg 0xa1ad
jmp 0xa321
movq %rdx, %r12
movl %esi, %r13d
movq %rdi, %r14
xorl %r15d, %r15d
cmpl $0x2, %esi
jl 0xa22e
movq 0x8(%r12), %rsi
leaq 0x217c1(%rip), %rdx     # 0x2b9e4
movq %r14, %rdi
callq 0x73c6
movl %eax, %r15d
movl %r15d, %eax
orl $0x2, %eax
cmpl %r13d, %eax
jne 0xa2cb
movl %r15d, %eax
movq 0x8(%r12,%rax,8), %r12
leaq 0x2b0a4(%rip), %rax     # 0x352f0
cmpq %rax, 0x8(%r12)
je 0xa271
movl $0x1, %r13d
movq %r14, %rdi
movq %r12, %rsi
movl $0x1, %edx
callq 0xd6c3
testl %eax, %eax
jne 0xa324
movq 0x18(%r12), %r13
leaq -0x2c(%rbp), %rsi
movl %r13d, %edi
movl %r15d, %edx
callq 0x6420
cmpl $-0x1, %eax
je 0xa2ea
movl %eax, %r12d
testq %r13, %r13
movslq %eax, %rsi
cmovnsq %r13, %rsi
movl -0x2c(%rbp), %edx
movq %r14, %rdi
xorl %ecx, %ecx
callq 0x16cce
movq %rax, %r15
movl -0x2c(%rbp), %eax
andl $0x7f, %eax
je 0xa2be
shll $0x18, %eax
addl $0x1000000, %eax        # imm = 0x1000000
cmpl $0x2000000, %eax        # imm = 0x2000000
jl 0xa301
movq %rbx, %rdi
movl %r12d, %esi
callq 0x16c79
jmp 0xa301
leaq 0x2171a(%rip), %rcx     # 0x2b9ec
movl $0x1, %r13d
movq %r14, %rdi
movl $0x1, %esi
movq %r12, %rdx
callq 0x7446
jmp 0xa324
movl -0x2c(%rbp), %edx
movq %r14, %rdi
movq $-0x1, %rsi
xorl %ecx, %ecx
callq 0x16cce
movq %rax, %r15
incl 0x10(%r15)
movq (%r14), %rsi
movl 0x10(%rsi), %eax
leal -0x1(%rax), %ecx
movl %ecx, 0x10(%rsi)
cmpl $0x1, %eax
jg 0xa31e
movq %r14, %rdi
callq 0x758c
movq %r15, (%r14)
xorl %r13d, %r13d
movl %r13d, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq