// File: /workspace/github_c_makefile_star2_O3/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 0x22170c(%rip), %rsi    # 0x391470
movl $0x18, %edi
movl $0x3e, %edx
callq 0x104226
movq %rax, %rbx
xorps %xmm0, %xmm0
movups %xmm0, (%rax)
movl $0xffffffff, 0x10(%rax) # imm = 0xFFFFFFFF
leaq 0x8(%rsp), %rdi
callq 0x179f0
testl %eax, %eax
je 0x16fdb6
callq 0x17060
movl (%rax), %edi
callq 0x17240
leaq 0x2216e6(%rip), %rsi    # 0x39148a
movq %r14, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0xfcb67
jmp 0x16fedb
movq %rsp, %rdi
callq 0x179f0
testl %eax, %eax
je 0x16fde7
callq 0x17060
movl (%rax), %edi
callq 0x17240
leaq 0x2216d3(%rip), %rsi    # 0x3914a8
movq %r14, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0xfcb67
jmp 0x16fec9
movl (%rsp), %edi
leaq 0x1eb064(%rip), %rsi    # 0x35ae55
callq 0x17860
movq %rax, (%rbx)
testq %rax, %rax
je 0x16fe43
movl 0xc(%rsp), %edi
leaq 0x2237ac(%rip), %rsi    # 0x3935b5
callq 0x17860
movq %rax, 0x8(%rbx)
testq %rax, %rax
je 0x16fe65
callq 0x171d0
movl %eax, 0x10(%rbx)
cmpl $-0x1, %eax
je 0x16fe87
testl %eax, %eax
je 0x16ff02
movl 0x4(%rsp), %edi
callq 0x17fc0
movl 0x8(%rsp), %edi
callq 0x17fc0
jmp 0x16fef1
callq 0x17060
movl (%rax), %edi
callq 0x17240
leaq 0x221671(%rip), %rsi    # 0x3914c7
movq %r14, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0xfcb67
jmp 0x16feb8
callq 0x17060
movl (%rax), %edi
callq 0x17240
leaq 0x22167d(%rip), %rsi    # 0x3914f5
movq %r14, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0xfcb67
jmp 0x16feb0
callq 0x17060
movl (%rax), %edi
callq 0x17240
leaq 0x221688(%rip), %rsi    # 0x391522
movq %r14, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0xfcb67
movq 0x8(%rbx), %rdi
callq 0x17800
movq (%rbx), %rdi
callq 0x17800
movl 0x4(%rsp), %edi
callq 0x17fc0
movl (%rsp), %edi
callq 0x17fc0
movl 0xc(%rsp), %edi
callq 0x17fc0
movl 0x8(%rsp), %edi
callq 0x17fc0
leaq 0x22158e(%rip), %rsi    # 0x391470
movq %rbx, %rdi
movl $0x82, %edx
callq 0x1045eb
xorl %ebx, %ebx
movq %rbx, %rax
addq $0x10, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq
movl (%rsp), %edi
callq 0x17fc0
movl 0xc(%rsp), %edi
callq 0x17fc0
movl 0x8(%rsp), %edi
testl %edi, %edi
je 0x16ff2b
xorl %esi, %esi
callq 0x17750
movl 0x8(%rsp), %edi
callq 0x17fc0
movl 0x4(%rsp), %edi
cmpl $0x1, %edi
je 0x16ff47
movl $0x1, %esi
callq 0x17750
movl 0x4(%rsp), %edi
callq 0x17fc0
movq %r13, %rdi
movq %r12, %rsi
movq %r15, %rdx
callq 0x17d50
leaq 0x2215d9(%rip), %rdi    # 0x391535
callq 0x17690
callq 0x17060
movl (%rax), %edi
callq 0x17240
movq %rax, %rdi
callq 0x17690
movl $0x7f, %edi
callq 0x17940