// File: /workspace/github_c_makefile_star2_O1/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 0xa21c
xorl %r13d, %r13d
testq %rbx, %rbx
je 0xa33f
movl 0xc(%rbx), %r15d
testl %r15d, %r15d
jle 0xa33f
movq (%rbx), %r12
incl %r15d
xorl %r13d, %r13d
leaq -0x34(%rbp), %r14
testb $0x2, 0x8(%r12)
je 0xa1e5
movl (%r12), %edi
movq %r14, %rsi
movl $0x1, %edx
callq 0x6420
testl %eax, %eax
jle 0xa1e5
decl 0xc(%rbx)
jmp 0xa20a
movslq %r13d, %rax
leaq (%rax,%rax,2), %rax
shlq $0x2, %rax
addq (%rbx), %rax
cmpq %rax, %r12
je 0xa207
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 0xa1c3
jmp 0xa33c
movq %rdx, %r12
movl %esi, %r13d
movq %rdi, %r14
xorl %r15d, %r15d
cmpl $0x2, %esi
jl 0xa244
movq 0x8(%r12), %rsi
leaq 0x22809(%rip), %rdx     # 0x2ca42
movq %r14, %rdi
callq 0x73d6
movl %eax, %r15d
movl %r15d, %eax
orl $0x2, %eax
cmpl %r13d, %eax
jne 0xa27d
movl %r15d, %eax
movq 0x8(%r12,%rax,8), %r12
leaq 0x2c082(%rip), %rax     # 0x362e0
cmpq %rax, 0x8(%r12)
je 0xa29f
movq %r14, %rdi
movq %r12, %rsi
movl $0x1, %edx
callq 0xd6d7
testl %eax, %eax
je 0xa29f
xorl %eax, %eax
jmp 0xa2a6
leaq 0x227c6(%rip), %rcx     # 0x2ca4a
movl $0x1, %r13d
movq %r14, %rdi
movl $0x1, %esi
movq %r12, %rdx
callq 0x7454
jmp 0xa33f
movq 0x18(%r12), %r12
movb $0x1, %al
movl $0x1, %r13d
testb %al, %al
je 0xa33f
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
movq $-0x1, %rsi
cmovneq %r12, %rsi
movl (%r13), %edx
movq %r14, %rdi
xorl %ecx, %ecx
callq 0x171e3
movq %rax, %r12
cmpl $-0x1, %r15d
je 0xa31b
movl -0x30(%rbp), %eax
andl $0x7f, %eax
je 0xa310
shll $0x18, %eax
addl $0x1000000, %eax        # imm = 0x1000000
cmpl $0x2000000, %eax        # imm = 0x2000000
jl 0xa31b
movq %rbx, %rdi
movl -0x2c(%rbp), %esi
callq 0x17193
incl 0x10(%r12)
movq (%r14), %rsi
movl 0x10(%rsi), %eax
leal -0x1(%rax), %ecx
movl %ecx, 0x10(%rsi)
cmpl $0x1, %eax
jg 0xa339
movq %r14, %rdi
callq 0x759a
movq %r12, (%r14)
xorl %r13d, %r13d
movl %r13d, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq