// File: /workspace/github_c_makefile_star2_O1/bhk[P]tooltree/monoglot/./xpio_c.c
// Function: xpio__spawn
static int xpio__spawn(lua_State *L)
{
   const char *path = luaL_checkstring(L, 1);
   luaL_checktype(L, 2, LUA_TTABLE);
   luaL_checktype(L, 3, LUA_TTABLE);
   luaL_checktype(L, 4, LUA_TTABLE);

   pid_t pid = fork();
   if (pid) {
      XPProc *pproc = xpproc_new(L);
      pproc->pid = pid;
      return 1;
   }

   // exec

   // reset signals

   // TODO: what about reversing SIG_IGN for SIGPIPE?
   sigset_t sigmask;
   sigemptyset(&sigmask);
   BAIL_IF(sigprocmask(SIG_SETMASK, &sigmask, NULL));

   // perform file actions

   int fdFrom, fdTo, ndx;
   for (ndx = 1; xpio_getAction(L, 4, ndx, &fdFrom, &fdTo); ++ndx) {
      if (fdFrom >= 0) {
         if (fdFrom != fdTo) {
            dup2(fdFrom, fdTo);
         }
         // make granted FDs blocking
         (void) setNonBlocking(fdTo, 0);
      } else {
         close(fdTo);
      }
   }

   char **argv = readStringArray(L, 2);
   char **envp = readStringArray(L, 3);

   execve(path, argv, envp);

 bail:
   exit(127);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xa8, %rsp
movq %rdi, %rbx
movl $0x1, %esi
xorl %edx, %edx
callq 0x7b05
movq %rax, %r14
movq %rbx, %rdi
movl $0x2, %esi
movl $0x5, %edx
callq 0x7b95
movq %rbx, %rdi
movl $0x3, %esi
movl $0x5, %edx
callq 0x7b95
movq %rbx, %rdi
movl $0x4, %esi
movl $0x5, %edx
callq 0x7b95
callq 0x3430
testl %eax, %eax
je 0x4156
movl %eax, %ebp
leaq 0x12f9c(%rip), %rdx     # 0x17028
movl $0x10, %esi
movq %rbx, %rdi
callq 0x43db
movq %rax, %rbx
movq $0x0, 0x8(%rax)
movq 0x1c1a5(%rip), %rax     # 0x20250
movq %rax, (%rbx)
movq %rbx, 0x1c19b(%rip)     # 0x20250
leaq 0x10(%rsp), %rdi
movl $0x98, %edx
xorl %esi, %esi
callq 0x31a0
cmpb $0x0, 0x1c18b(%rip)     # 0x20258
jne 0x4127
movb $0x1, 0x1c182(%rip)     # 0x20258
leaq 0x504(%rip), %rax       # 0x45e1
movq %rax, 0x10(%rsp)
movl $0x10000000, 0x98(%rsp) # imm = 0x10000000
leaq 0x1c14c(%rip), %rdi     # 0x20240
callq 0x31d0
testl %eax, %eax
jne 0x4141
movl 0x1c13d(%rip), %edi     # 0x20240
movl $0x1, %esi
callq 0x4389
cmpl $-0x1, %eax
je 0x4148
leaq 0x10(%rsp), %rsi
movl $0x11, %edi
xorl %edx, %edx
callq 0x3090
testl %eax, %eax
jne 0x414f
movl %ebp, 0x8(%rbx)
movl $0x1, %eax
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x3470
jmp 0x4127
callq 0x34df
jmp 0x4127
callq 0x34a7
jmp 0x4127
leaq 0x10(%rsp), %r15
movq %r15, %rdi
callq 0x3260
movl $0x2, %edi
movq %r15, %rsi
xorl %edx, %edx
callq 0x3030
testl %eax, %eax
jne 0x428c
movl $0x1, %ebp
leaq 0xc(%rsp), %r15
movq %rbx, %rdi
movl $0x4, %esi
movl %ebp, %edx
callq 0x66f1
movq %rbx, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x5e35
movq %rbx, %rdi
cmpl $0x5, %eax
jne 0x4221
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
movl $0x1, %edx
callq 0x66f1
movq %rbx, %rdi
movl $0xfffffffe, %esi       # imm = 0xFFFFFFFE
movl $0x2, %edx
callq 0x66f1
movq %rbx, %rdi
movl $0xfffffffe, %esi       # imm = 0xFFFFFFFE
movq %r15, %rdx
callq 0x60c9
cmpl $0x1, 0xc(%rsp)
movl $0x0, %r12d
sbbl %r12d, %r12d
orl %eax, %r12d
movq %rbx, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
movq %r15, %rdx
callq 0x60c9
cmpl $0x1, 0xc(%rsp)
movl $0x0, %r13d
sbbl %r13d, %r13d
orl %eax, %r13d
movq %rbx, %rdi
movl $0xfffffffc, %esi       # imm = 0xFFFFFFFC
callq 0x5c43
cmpl $-0x1, %r12d
sete %al
jmp 0x422d
movl $0xfffffffe, %esi       # imm = 0xFFFFFFFE
callq 0x5c43
movb $0x1, %al
testb %al, %al
jne 0x4261
testl %r13d, %r13d
js 0x4252
cmpl %r12d, %r13d
je 0x4246
movl %r13d, %edi
movl %r12d, %esi
callq 0x3150
movl %r12d, %edi
xorl %esi, %esi
callq 0x4389
jmp 0x425a
movl %r12d, %edi
callq 0x31c0
incl %ebp
jmp 0x4184
movq %rbx, %rdi
movl $0x2, %esi
callq 0x453f
movq %rax, %r15
movq %rbx, %rdi
movl $0x3, %esi
callq 0x453f
movq %r14, %rdi
movq %r15, %rsi
movq %rax, %rdx
callq 0x3210
movl $0x7f, %edi
callq 0x33c0