// File: /workspace/github_c_makefile_star2_O0/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:
subq $0x68, %rsp
movq %rdi, 0x60(%rsp)
movq %rsi, 0x58(%rsp)
movq %rdx, 0x50(%rsp)
movq %rcx, 0x48(%rsp)
movl $0x0, 0x34(%rsp)
movq $0x0, 0x28(%rsp)
movl $0x18, %edi
leaq 0x39630b(%rip), %rsi    # 0x563c90
movl $0x3e, %edx
callq 0xe80f0
movq %rax, 0x28(%rsp)
movq 0x28(%rsp), %rax
movq $0x0, 0x8(%rax)
movq 0x28(%rsp), %rax
movq $0x0, (%rax)
movq 0x28(%rsp), %rax
movl $0xffffffff, 0x10(%rax) # imm = 0xFFFFFFFF
leaq 0x40(%rsp), %rdi
callq 0x19930
movl %eax, 0x34(%rsp)
cmpl $0x0, %eax
je 0x1cd9f8
movq 0x48(%rsp), %rax
movq %rax, 0x20(%rsp)
callq 0x19060
movl (%rax), %edi
callq 0x19200
movq 0x20(%rsp), %rdi
movq %rax, %rdx
leaq 0x3962b9(%rip), %rsi    # 0x563caa
movb $0x0, %al
callq 0xd88c0
cmpl $0x0, 0x34(%rsp)
jne 0x1cdc64
leaq 0x38(%rsp), %rdi
callq 0x19930
movl %eax, 0x34(%rsp)
cmpl $0x0, %eax
je 0x1cda42
movq 0x48(%rsp), %rax
movq %rax, 0x18(%rsp)
callq 0x19060
movl (%rax), %edi
callq 0x19200
movq 0x18(%rsp), %rdi
movq %rax, %rdx
leaq 0x39628d(%rip), %rsi    # 0x563cc8
movb $0x0, %al
callq 0xd88c0
cmpl $0x0, 0x34(%rsp)
jne 0x1cdc49
movl 0x38(%rsp), %edi
leaq 0x35e582(%rip), %rsi    # 0x52bfda
callq 0x197b0
movq 0x28(%rsp), %rcx
movq %rax, (%rcx)
cmpq $0x0, %rax
jne 0x1cda9f
movq 0x48(%rsp), %rax
movq %rax, 0x10(%rsp)
callq 0x19060
movl (%rax), %edi
callq 0x19200
movq 0x10(%rsp), %rdi
movq %rax, %rdx
leaq 0x396257(%rip), %rsi    # 0x563ce7
movb $0x0, %al
callq 0xd88c0
movl $0xffffffff, 0x34(%rsp) # imm = 0xFFFFFFFF
cmpl $0x0, 0x34(%rsp)
jne 0x1cdc2e
movl 0x44(%rsp), %edi
leaq 0x398410(%rip), %rsi    # 0x565ec5
callq 0x197b0
movq 0x28(%rsp), %rcx
movq %rax, 0x8(%rcx)
cmpq $0x0, %rax
jne 0x1cdafd
movq 0x48(%rsp), %rax
movq %rax, 0x8(%rsp)
callq 0x19060
movl (%rax), %edi
callq 0x19200
movq 0x8(%rsp), %rdi
movq %rax, %rdx
leaq 0x396227(%rip), %rsi    # 0x563d15
movb $0x0, %al
callq 0xd88c0
movl $0xffffffff, 0x34(%rsp) # imm = 0xFFFFFFFF
cmpl $0x0, 0x34(%rsp)
jne 0x1cdc18
callq 0x1cdca0
movq 0x28(%rsp), %rcx
movl %eax, 0x10(%rcx)
cmpl $-0x1, %eax
jne 0x1cdb4c
movq 0x48(%rsp), %rax
movq %rax, (%rsp)
callq 0x19060
movl (%rax), %edi
callq 0x19200
movq (%rsp), %rdi
movq %rax, %rdx
leaq 0x396205(%rip), %rsi    # 0x563d42
movb $0x0, %al
callq 0xd88c0
movl $0xffffffff, 0x34(%rsp) # imm = 0xFFFFFFFF
cmpl $0x0, 0x34(%rsp)
jne 0x1cdc01
movq 0x28(%rsp), %rax
cmpl $0x0, 0x10(%rax)
jne 0x1cdbef
movl 0x38(%rsp), %edi
callq 0x19ec0
movl 0x44(%rsp), %edi
callq 0x19ec0
cmpl $0x0, 0x40(%rsp)
je 0x1cdb93
movl 0x40(%rsp), %edi
xorl %esi, %esi
callq 0x196f0
movl 0x40(%rsp), %edi
callq 0x19ec0
cmpl $0x1, 0x3c(%rsp)
je 0x1cdbb1
movl 0x3c(%rsp), %edi
movl $0x1, %esi
callq 0x196f0
movl 0x3c(%rsp), %edi
callq 0x19ec0
movq 0x60(%rsp), %rdi
movq 0x58(%rsp), %rsi
movq 0x50(%rsp), %rdx
callq 0x19c70
leaq 0x396189(%rip), %rdi    # 0x563d55
callq 0x19640
callq 0x19060
movl (%rax), %edi
callq 0x19200
movq %rax, %rdi
callq 0x19640
movl $0x7f, %edi
callq 0x19890
movl 0x3c(%rsp), %edi
callq 0x19ec0
movl 0x40(%rsp), %edi
callq 0x19ec0
cmpl $0x0, 0x34(%rsp)
je 0x1cdc16
movq 0x28(%rsp), %rax
movq 0x8(%rax), %rdi
callq 0x19780
jmp 0x1cdc18
cmpl $0x0, 0x34(%rsp)
je 0x1cdc2c
movq 0x28(%rsp), %rax
movq (%rax), %rdi
callq 0x19780
jmp 0x1cdc2e
cmpl $0x0, 0x34(%rsp)
je 0x1cdc47
movl 0x3c(%rsp), %edi
callq 0x19ec0
movl 0x38(%rsp), %edi
callq 0x19ec0
jmp 0x1cdc49
cmpl $0x0, 0x34(%rsp)
je 0x1cdc62
movl 0x44(%rsp), %edi
callq 0x19ec0
movl 0x40(%rsp), %edi
callq 0x19ec0
jmp 0x1cdc64
cmpl $0x0, 0x34(%rsp)
je 0x1cdc8a
movq 0x28(%rsp), %rdi
leaq 0x396019(%rip), %rsi    # 0x563c90
movl $0x82, %edx
callq 0xe88c0
movq $0x0, 0x28(%rsp)
movq 0x28(%rsp), %rax
addq $0x68, %rsp
retq
nopw %cs:(%rax,%rax)