// File: /workspace/github_c_makefile_star2_O1/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 0x222794(%rip), %rsi    # 0x39a890
movl $0x18, %edi
movl $0x3e, %edx
callq 0x1092b2
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 0x17814e
callq 0x17060
movl (%rax), %edi
callq 0x17240
leaq 0x22276e(%rip), %rsi    # 0x39a8aa
movq %r14, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0x1019cf
jmp 0x178273
movq %rsp, %rdi
callq 0x179f0
testl %eax, %eax
je 0x17817f
callq 0x17060
movl (%rax), %edi
callq 0x17240
leaq 0x22275b(%rip), %rsi    # 0x39a8c8
movq %r14, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0x1019cf
jmp 0x178261
movl (%rsp), %edi
leaq 0x1ebd40(%rip), %rsi    # 0x363ec9
callq 0x17860
movq %rax, (%rbx)
testq %rax, %rax
je 0x1781db
movl 0xc(%rsp), %edi
leaq 0x224890(%rip), %rsi    # 0x39ca31
callq 0x17860
movq %rax, 0x8(%rbx)
testq %rax, %rax
je 0x1781fd
callq 0x171d0
movl %eax, 0x10(%rbx)
cmpl $-0x1, %eax
je 0x17821f
testl %eax, %eax
je 0x17829a
movl 0x4(%rsp), %edi
callq 0x17fc0
movl 0x8(%rsp), %edi
callq 0x17fc0
jmp 0x178289
callq 0x17060
movl (%rax), %edi
callq 0x17240
leaq 0x2226f9(%rip), %rsi    # 0x39a8e7
movq %r14, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0x1019cf
jmp 0x178250
callq 0x17060
movl (%rax), %edi
callq 0x17240
leaq 0x222705(%rip), %rsi    # 0x39a915
movq %r14, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0x1019cf
jmp 0x178248
callq 0x17060
movl (%rax), %edi
callq 0x17240
leaq 0x222710(%rip), %rsi    # 0x39a942
movq %r14, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0x1019cf
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 0x222616(%rip), %rsi    # 0x39a890
movq %rbx, %rdi
movl $0x82, %edx
callq 0x109670
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 0x1782c3
xorl %esi, %esi
callq 0x17750
movl 0x8(%rsp), %edi
callq 0x17fc0
movl 0x4(%rsp), %edi
cmpl $0x1, %edi
je 0x1782df
movl $0x1, %esi
callq 0x17750
movl 0x4(%rsp), %edi
callq 0x17fc0
movq %r13, %rdi
movq %r12, %rsi
movq %r15, %rdx
callq 0x17d50
leaq 0x222661(%rip), %rdi    # 0x39a955
callq 0x17690
callq 0x17060
movl (%rax), %edi
callq 0x17240
movq %rax, %rdi
callq 0x17690
movl $0x7f, %edi
callq 0x17940