// File: /workspace/github_c_makefile_star2_O0/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
subq $0x50, %rsp
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movq %rdx, -0x20(%rbp)
movq -0x10(%rbp), %rax
movq 0x1b8(%rax), %rax
movq %rax, -0x28(%rbp)
movl $0x0, -0x2c(%rbp)
cmpl $0x1, -0x14(%rbp)
jne 0xb224
movq -0x28(%rbp), %rdi
callq 0x1c490
movl $0x0, -0x4(%rbp)
jmp 0xb388
cmpl $0x1, -0x14(%rbp)
jle 0xb24e
movq -0x10(%rbp), %rdi
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rsi
leaq 0x30b69(%rip), %rdx     # 0x3bda6
callq 0x77a0
cmpl $0x0, %eax
je 0xb24e
movl $0x1, -0x2c(%rbp)
movl -0x14(%rbp), %eax
movl -0x2c(%rbp), %ecx
addl $0x2, %ecx
cmpl %ecx, %eax
je 0xb280
movq -0x10(%rbp), %rdi
movq -0x20(%rbp), %rdx
movl $0x1, %esi
leaq 0x30b3f(%rip), %rcx     # 0x3bdae
callq 0x7880
movl $0x1, -0x4(%rbp)
jmp 0xb388
movq -0x10(%rbp), %rdi
movq -0x20(%rbp), %rax
movl -0x2c(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rsi
leaq -0x38(%rbp), %rdx
callq 0xf4d0
cmpl $0x0, %eax
je 0xb2af
movl $0x1, -0x4(%rbp)
jmp 0xb388
movq -0x38(%rbp), %rax
movl %eax, %edi
movl -0x2c(%rbp), %ecx
xorl %edx, %edx
movl $0x1, %eax
cmpl $0x0, %ecx
cmovnel %eax, %edx
leaq -0x40(%rbp), %rsi
callq 0x6430
movl %eax, -0x3c(%rbp)
cmpl $-0x1, -0x3c(%rbp)
jne 0xb2e1
movq $-0x1, -0x38(%rbp)
jmp 0xb2f2
cmpq $0x0, -0x38(%rbp)
jge 0xb2f0
movslq -0x3c(%rbp), %rax
movq %rax, -0x38(%rbp)
jmp 0xb2f2
movq -0x10(%rbp), %rdi
movq -0x38(%rbp), %rsi
movl -0x40(%rbp), %edx
xorl %eax, %eax
movl %eax, %ecx
callq 0x1c160
movq %rax, -0x48(%rbp)
cmpl $-0x1, -0x3c(%rbp)
je 0xb33a
movl -0x40(%rbp), %eax
andl $0x7f, %eax
cmpl $0x0, %eax
je 0xb32e
movl -0x40(%rbp), %eax
andl $0x7f, %eax
addl $0x1, %eax
movsbl %al, %eax
sarl %eax
cmpl $0x0, %eax
jle 0xb33a
movq -0x28(%rbp), %rdi
movl -0x3c(%rbp), %esi
callq 0x1c0a0
jmp 0xb33c
movq -0x48(%rbp), %rax
movq %rax, -0x50(%rbp)
movq -0x50(%rbp), %rax
movl 0x10(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x10(%rax)
movq -0x10(%rbp), %rax
movq (%rax), %rcx
movl 0x10(%rcx), %eax
addl $-0x1, %eax
movl %eax, 0x10(%rcx)
cmpl $0x0, %eax
jg 0xb376
movq -0x10(%rbp), %rdi
movq -0x10(%rbp), %rax
movq (%rax), %rsi
callq 0x7a10
movq -0x50(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, (%rax)
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x50, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)