// File: /workspace/github_c_makefile_star2_O2/genometools[P]genometools/src/extended/safe_popen.c
// Function: gt_safe_popen
GtSafePipe *gt_safe_popen(GT_WIN32_UNUSED const char *path,
                          GT_WIN32_UNUSED char *const argv[],
                          GT_WIN32_UNUSED char *const envp[],
                          GtError *err) {
#ifndef _WIN32
  int stdin_pipe[2], stdout_pipe[2], had_err = 0;
  GtSafePipe *p = NULL;

  p = gt_malloc(sizeof(*p));
  p->read_fd = p->write_fd = NULL;
  p->child_pid = (pid_t) -1;

  if ((had_err = pipe(stdin_pipe))) {
    gt_error_set(err, "could not open stdin pipe: %s", strerror(errno));
  }
  if (!had_err) {
    if ((had_err = pipe(stdout_pipe))) {
      gt_error_set(err, "could not open stdout pipe: %s", strerror(errno));
    }
    if (!had_err) {
      if (!(p->read_fd = fdopen(stdout_pipe[0], "r"))) {
        gt_error_set(err, "could not open stdout_pipe[0] for reading: %s",
                     strerror(errno));
        had_err = -1;
      }
      if (!had_err) {
        if (!(p->write_fd = fdopen(stdin_pipe[1], "w"))) {
          gt_error_set(err, "could not open stdin_pipe[1] for writing: %s",
                       strerror(errno));
          had_err = -1;
        }
        if (!had_err) {
          if ((p->child_pid = safe_fork()) == (pid_t) -1) {
            gt_error_set(err, "could not fork: %s", strerror(errno));
            had_err = -1;
          }
          if (!had_err) {
            if (!p->child_pid) {
              /* this is the child process */
              (void) close(stdout_pipe[0]);
              (void) close(stdin_pipe[1]);
              if (stdin_pipe[0] != 0) {
                (void) dup2(stdin_pipe[0], 0);
                (void) close(stdin_pipe[0]);
              }
              if (stdout_pipe[1] != 1) {
                (void) dup2(stdout_pipe[1], 1);
                (void) close(stdout_pipe[1]);
              }
              (void) execve(path, argv, envp);
              perror("could not execute external program: ");
              perror(strerror(errno));
              exit(127);
            }
            (void) close(stdout_pipe[1]);
            (void) close(stdin_pipe[0]);
          }
          if (had_err) {
            (void) fclose(p->write_fd);
          }
        }
        if (had_err) {
          (void) fclose(p->read_fd);
        }
      }
      if (had_err) {
        (void) close(stdout_pipe[1]);
        (void) close(stdout_pipe[0]);
      }
    }
    if (had_err) {
      (void) close(stdin_pipe[1]);
      (void) close(stdin_pipe[0]);
    }
  }
  if (had_err) {
    gt_free(p);
    p = NULL;
  }
  return p;
#else
  gt_error_set(err, "Function gt_safe_popen not implemented for windows yet");
  return NULL;
#endif
}

// Assembly:
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x10, %rsp
movq %rcx, %r14
movq %rdx, %r15
movq %rsi, %r12
movq %rdi, %r13
leaq 0x21eec4(%rip), %rsi    # 0x3317b0
pushq $0x18
popq %rdi
pushq $0x3e
popq %rdx
callq 0x93160
movq %rax, %rbx
xorps %xmm0, %xmm0
movups %xmm0, (%rax)
orl $-0x1, 0x10(%rax)
leaq 0x8(%rsp), %rdi
callq 0x17990
testl %eax, %eax
je 0x112937
callq 0x17060
movl (%rax), %edi
callq 0x17220
leaq 0x21eea5(%rip), %rsi    # 0x3317ca
movq %r14, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0x89dbb
jmp 0x112a5c
movq %rsp, %rdi
callq 0x17990
testl %eax, %eax
je 0x112968
callq 0x17060
movl (%rax), %edi
callq 0x17220
leaq 0x21ee92(%rip), %rsi    # 0x3317e8
movq %r14, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0x89dbb
jmp 0x112a4a
movl (%rsp), %edi
leaq 0x1e84bb(%rip), %rsi    # 0x2fae2d
callq 0x17810
movq %rax, (%rbx)
testq %rax, %rax
je 0x1129c4
movl 0xc(%rsp), %edi
leaq 0x220f84(%rip), %rsi    # 0x33390e
callq 0x17810
movq %rax, 0x8(%rbx)
testq %rax, %rax
je 0x1129e6
callq 0x171b0
movl %eax, 0x10(%rbx)
cmpl $-0x1, %eax
je 0x112a08
testl %eax, %eax
je 0x112a83
movl 0x4(%rsp), %edi
callq 0x17f20
movl 0x8(%rsp), %edi
callq 0x17f20
jmp 0x112a72
callq 0x17060
movl (%rax), %edi
callq 0x17220
leaq 0x21ee30(%rip), %rsi    # 0x331807
movq %r14, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0x89dbb
jmp 0x112a39
callq 0x17060
movl (%rax), %edi
callq 0x17220
leaq 0x21ee3c(%rip), %rsi    # 0x331835
movq %r14, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0x89dbb
jmp 0x112a31
callq 0x17060
movl (%rax), %edi
callq 0x17220
leaq 0x21ee47(%rip), %rsi    # 0x331862
movq %r14, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0x89dbb
movq 0x8(%rbx), %rdi
callq 0x177c0
movq (%rbx), %rdi
callq 0x177c0
movl 0x4(%rsp), %edi
callq 0x17f20
movl (%rsp), %edi
callq 0x17f20
movl 0xc(%rsp), %edi
callq 0x17f20
movl 0x8(%rsp), %edi
callq 0x17f20
leaq 0x21ed4d(%rip), %rsi    # 0x3317b0
movq %rbx, %rdi
movl $0x82, %edx
callq 0x936f9
xorl %ebx, %ebx
movq %rbx, %rax
addq $0x10, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq
movl (%rsp), %edi
callq 0x17f20
movl 0xc(%rsp), %edi
callq 0x17f20
movl 0x8(%rsp), %edi
testl %edi, %edi
je 0x112aac
xorl %esi, %esi
callq 0x17720
movl 0x8(%rsp), %edi
callq 0x17f20
movl 0x4(%rsp), %edi
cmpl $0x1, %edi
je 0x112ac6
pushq $0x1
popq %rsi
callq 0x17720
movl 0x4(%rsp), %edi
callq 0x17f20
movq %r13, %rdi
movq %r12, %rsi
movq %r15, %rdx
callq 0x17cd0
leaq 0x21ed9a(%rip), %rdi    # 0x331875
callq 0x17660
callq 0x17060
movl (%rax), %edi
callq 0x17220
movq %rax, %rdi
callq 0x17660
pushq $0x7f
popq %rdi
callq 0x178f0