// File: /workspace/github_c_makefile_star2_O1/mcaimi[P]st/st.c
// Function: ttynew
int
ttynew(char *line, char *cmd, char *out, char **args)
{
  int m, s;

  if (out) {
    term.mode |= MODE_PRINT;
    iofd = (!strcmp(out, "-")) ?
        1 : open(out, O_WRONLY | O_CREAT, 0666);
    if (iofd < 0) {
      fprintf(stderr, "Error opening %s:%s\n",
        out, strerror(errno));
    }
  }

  if (line) {
    if ((cmdfd = open(line, O_RDWR)) < 0)
      die("open line '%s' failed: %s\n", line, strerror(errno));
    dup2(cmdfd, 0);
    stty(args);
    return cmdfd;
  }

  /* seems to work fine on linux, openbsd and freebsd */
  if (openpty(&m, &s, NULL, NULL, NULL) < 0)
    die("openpty failed: %s\n", strerror(errno));

  switch (pid = fork()) {
  case -1:
    die("fork failed %s\n", strerror(errno));
    break;
  case 0:
    close(iofd);
    close(m);
    setsid(); /* create a new process group */
    dup2(s, 0);
    dup2(s, 1);
    dup2(s, 2);
    if (ioctl(s, TIOCSCTTY, NULL) < 0)
      die("ioctl TIOCSCTTY failed: %s\n", strerror(errno));
    if (s > 2)
      close(s);
#ifdef __OpenBSD__
    if (pledge("stdio getpw proc exec ps rpath wpath tty", NULL) == -1)
      die("Failed to execute pledge() system call.\n");
#endif
    execsh(cmd, args);
    break;
  default:
#ifdef __OpenBSD__
    if (pledge("stdio getpw proc exec ps rpath wpath tty", NULL) == -1)
      die("Failed to execute pledge() system call\n");
#endif
    close(s);
    cmdfd = m;
    signal(SIGCHLD, sigchld);
    break;
  }
  return cmdfd;
}

// Assembly:
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1010, %rsp           # imm = 0x1010
movq %rcx, %rbx
movq %rsi, %r14
movq %rdi, %r15
testq %rdx, %rdx
je 0x79bf
movq %rdx, %r12
orb $0x20, 0x16d71(%rip)    # 0x1e6f4
leaq 0xac4a(%rip), %rsi      # 0x125d4
movq %rdx, %rdi
callq 0x66e0
testl %eax, %eax
je 0x79ac
movq %r12, %rdi
movl $0x41, %esi
movl $0x1b6, %edx            # imm = 0x1B6
xorl %eax, %eax
callq 0x69f0
jmp 0x79b1
movl $0x1, %eax
movl %eax, 0x15b99(%rip)     # 0x1d550
testl %eax, %eax
js 0x7b20
testq %r15, %r15
je 0x7aab
movq %r15, %rdi
movl $0x2, %esi
xorl %eax, %eax
callq 0x69f0
movl %eax, 0x16d3b(%rip)     # 0x1e718
testl %eax, %eax
js 0x7b3b
movl 0x16d2d(%rip), %edi     # 0x1e718
xorl %esi, %esi
callq 0x6080
leaq 0x15b77(%rip), %rax     # 0x1d570
movq (%rax), %r14
movq %r14, %rdi
callq 0x63b0
cmpq $0x1000, %rax           # imm = 0x1000
jae 0x7b5b
movq %rax, %r15
leaq 0x10(%rsp), %rdi
movq %r14, %rsi
movq %rax, %rdx
callq 0x69d0
leaq (%rsp,%r15), %r12
addq $0x10, %r12
testq %rbx, %rbx
je 0x7a8a
movq (%rbx), %r14
testq %r14, %r14
je 0x7a8a
movl $0x1000, %r13d          # imm = 0x1000
subq %r15, %r13
addq $0x8, %rbx
movq %r14, %rdi
callq 0x63b0
movq %rax, %r15
leaq -0x1(%r13), %rax
cmpq %rax, %r15
ja 0x7b2d
leaq 0x1(%r12), %rdi
movb $0x20, (%r12)
movq %r14, %rsi
movq %r15, %rdx
callq 0x69d0
addq %r15, %r12
incq %r12
notq %r15
addq %r15, %r13
movq (%rbx), %r14
addq $0x8, %rbx
testq %r14, %r14
jne 0x7a45
movb $0x0, (%r12)
leaq 0x10(%rsp), %rdi
callq 0x6240
testl %eax, %eax
je 0x7b09
leaq 0xaca4(%rip), %rdi      # 0x12748
callq 0x6950
jmp 0x7b09
leaq 0xc(%rsp), %rdi
leaq 0x8(%rsp), %rsi
xorl %edx, %edx
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0x64e0
testl %eax, %eax
js 0x7b64
callq 0x68d0
movl %eax, 0x16c48(%rip)     # 0x1e71c
testl %eax, %eax
je 0x7b79
cmpl $-0x1, %eax
je 0x7be4
movl 0x8(%rsp), %edi
callq 0x6110
movl 0xc(%rsp), %eax
movl %eax, 0x16c20(%rip)     # 0x1e718
leaq 0x2a5(%rip), %rsi       # 0x7da4
movl $0x11, %edi
callq 0x6070
movl 0x16c09(%rip), %eax     # 0x1e718
addq $0x1010, %rsp           # imm = 0x1010
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq
movq %r12, %rdi
callq 0x6c67
jmp 0x79bf
leaq 0xabf4(%rip), %rdi      # 0x12728
xorl %eax, %eax
callq 0x714f
callq 0x6620
movl (%rax), %edi
callq 0x64b0
leaq 0xaa9d(%rip), %rdi      # 0x125eb
movq %r15, %rsi
movq %rax, %rdx
xorl %eax, %eax
callq 0x714f
leaq 0xabab(%rip), %rdi      # 0x1270d
jmp 0x7b34
callq 0x6620
movl (%rax), %edi
callq 0x64b0
leaq 0xaa8f(%rip), %rdi      # 0x12606
jmp 0x7bf7
movl 0x159d1(%rip), %edi     # 0x1d550
callq 0x6110
movl 0xc(%rsp), %edi
callq 0x6110
callq 0x60e0
movl 0x8(%rsp), %edi
xorl %esi, %esi
callq 0x6080
movl 0x8(%rsp), %edi
movl $0x1, %esi
callq 0x6080
movl 0x8(%rsp), %edi
movl $0x2, %esi
callq 0x6080
movl 0x8(%rsp), %edi
movl $0x540e, %esi           # imm = 0x540E
xorl %edx, %edx
xorl %eax, %eax
callq 0x6120
testl %eax, %eax
jns 0x7c01
callq 0x6620
movl (%rax), %edi
callq 0x64b0
leaq 0xaa48(%rip), %rdi      # 0x1262a
jmp 0x7bf7
callq 0x6620
movl (%rax), %edi
callq 0x64b0
leaq 0xaa23(%rip), %rdi      # 0x1261a
movq %rax, %rsi
xorl %eax, %eax
callq 0x714f
movl 0x8(%rsp), %edi
cmpl $0x3, %edi
jl 0x7c0f
callq 0x6110
callq 0x6620
movq %rax, %r12
movl $0x0, (%rax)
callq 0x67b0
movl %eax, %edi
callq 0x6320
testq %rax, %rax
jne 0x7c42
movl (%r12), %edi
testl %edi, %edi
jne 0x7c8e
leaq 0xab2c(%rip), %rdi      # 0x12769
jmp 0x7b34
movq %rax, %r15
leaq 0xab2b(%rip), %rdi      # 0x12777
callq 0x65e0
movq %rax, %r12
testq %rax, %rax
jne 0x7c67
movq 0x28(%r15), %rax
cmpb $0x0, (%rax)
cmovneq %rax, %r14
movq %r14, %r12
testq %rbx, %rbx
jne 0x7c9f
leaq 0x18e35(%rip), %rax     # 0x20aa8
movq (%rax), %r14
testq %r14, %r14
jne 0x7ca2
leaq 0x18e1e(%rip), %rax     # 0x20aa0
movq (%rax), %r14
testq %r14, %r14
cmoveq %r12, %r14
jmp 0x7ca2
callq 0x64b0
leaq 0xaac1(%rip), %rdi      # 0x1275b
jmp 0x7bf7
movq (%rbx), %r14
testq %rbx, %rbx
jne 0x7cb7
leaq 0x10(%rsp), %rbx
movq %r14, (%rbx)
movq $0x0, 0x8(%rbx)
leaq 0xaabf(%rip), %rdi      # 0x1277d
callq 0x6870
leaq 0xaabb(%rip), %rdi      # 0x12785
callq 0x6870
leaq 0xaab5(%rip), %rdi      # 0x1278b
callq 0x6870
movq (%r15), %rsi
leaq 0xaaae(%rip), %rdi      # 0x12793
movl $0x1, %edx
callq 0x65d0
movq (%r15), %rsi
leaq 0xaaa2(%rip), %rdi      # 0x1279b
movl $0x1, %edx
callq 0x65d0
leaq 0xaa6d(%rip), %rdi      # 0x12777
movq %r12, %rsi
movl $0x1, %edx
callq 0x65d0
movq 0x20(%r15), %rsi
leaq 0xaa7e(%rip), %rdi      # 0x127a0
movl $0x1, %edx
callq 0x65d0
leaq 0x15865(%rip), %rax     # 0x1d598
movq (%rax), %rsi
leaq 0xaa68(%rip), %rdi      # 0x127a5
movl $0x1, %edx
callq 0x65d0
movl $0x11, %edi
xorl %esi, %esi
callq 0x6070
movl $0x1, %edi
xorl %esi, %esi
callq 0x6070
movl $0x2, %edi
xorl %esi, %esi
callq 0x6070
movl $0x3, %edi
xorl %esi, %esi
callq 0x6070
movl $0xf, %edi
xorl %esi, %esi
callq 0x6070
movl $0xe, %edi
xorl %esi, %esi
callq 0x6070
movq %r14, %rdi
movq %rbx, %rsi
callq 0x6190
movl $0x1, %edi
callq 0x6260