// File: /workspace/github_c_makefile_star2_O2/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 %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1018, %rsp           # imm = 0x1018
movq %rcx, %rbx
movq %rsi, %r14
movq %rdi, %r15
testq %rdx, %rdx
je 0x7421
movq %rdx, %r12
orb $0x20, 0x17304(%rip)    # 0x1e6f4
cmpb $0x2d, (%rdx)
jne 0x7401
cmpb $0x0, 0x1(%r12)
je 0x7571
pushq $0x41
popq %rsi
movq %r12, %rdi
movl $0x1b6, %edx            # imm = 0x1B6
xorl %eax, %eax
callq 0x69f0
movl %eax, 0x16137(%rip)     # 0x1d550
testl %eax, %eax
js 0x7580
testq %r15, %r15
je 0x74fd
pushq $0x2
popq %rsi
movq %r15, %rdi
xorl %eax, %eax
callq 0x69f0
movl %eax, 0x172db(%rip)     # 0x1e718
testl %eax, %eax
js 0x75c0
movl %eax, %edi
xorl %esi, %esi
callq 0x6080
leaq 0x1611b(%rip), %rax     # 0x1d570
movq (%rax), %r15
movq %r15, %rdi
callq 0x63b0
cmpq $0x1000, %rax           # imm = 0x1000
jae 0x75e0
movq %rax, %r14
leaq 0x10(%rsp), %rdi
movq %r15, %rsi
movq %rax, %rdx
callq 0x69d0
leaq (%rsp,%r14), %r12
addq $0x10, %r12
movl $0x1000, %r13d          # imm = 0x1000
subq %r14, %r13
testq %rbx, %rbx
je 0x74dc
movq (%rbx), %r14
testq %r14, %r14
je 0x74dc
movq %r14, %rdi
callq 0x63b0
movq %rax, %r15
leaq -0x1(%r13), %rax
cmpq %rax, %r15
ja 0x75b2
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
addq $0x8, %rbx
jmp 0x7490
movb $0x0, (%r12)
leaq 0x10(%rsp), %rdi
callq 0x6240
testl %eax, %eax
je 0x7559
leaq 0xa250(%rip), %rdi      # 0x11746
callq 0x6950
jmp 0x7559
leaq 0xc(%rsp), %rdi
leaq 0x8(%rsp), %rsi
xorl %edx, %edx
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0x64e0
testl %eax, %eax
js 0x75e9
callq 0x68d0
movl %eax, 0x171f6(%rip)     # 0x1e71c
testl %eax, %eax
je 0x75fe
cmpl $-0x1, %eax
je 0x7665
movl 0x8(%rsp), %edi
callq 0x6110
movl 0xc(%rsp), %eax
movl %eax, 0x171ce(%rip)     # 0x1e718
leaq 0x2af(%rip), %rsi       # 0x7800
pushq $0x11
popq %rdi
callq 0x6070
movl 0x171b9(%rip), %eax     # 0x1e718
addq $0x1018, %rsp           # imm = 0x1018
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl $0x1, 0x15fd5(%rip)     # 0x1d550
jmp 0x7421
movq 0x15a69(%rip), %rax     # 0x1cff0
movq (%rax), %r13
callq 0x6620
movl (%rax), %edi
callq 0x64b0
leaq 0xa037(%rip), %rsi      # 0x115d4
movq %r13, %rdi
movq %r12, %rdx
movq %rax, %rcx
xorl %eax, %eax
callq 0x6970
jmp 0x7421
leaq 0xa16d(%rip), %rdi      # 0x11726
xorl %eax, %eax
callq 0x6c0a
callq 0x6620
movl (%rax), %edi
callq 0x64b0
leaq 0xa016(%rip), %rdi      # 0x115e9
movq %r15, %rsi
movq %rax, %rdx
xorl %eax, %eax
callq 0x6c0a
leaq 0xa124(%rip), %rdi      # 0x1170b
jmp 0x75b9
callq 0x6620
movl (%rax), %edi
callq 0x64b0
leaq 0xa008(%rip), %rdi      # 0x11604
jmp 0x7678
movl 0x15f4c(%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
pushq $0x1
popq %rsi
callq 0x6080
movl 0x8(%rsp), %edi
pushq $0x2
popq %rsi
callq 0x6080
movl 0x8(%rsp), %edi
movl $0x540e, %esi           # imm = 0x540E
xorl %edx, %edx
xorl %eax, %eax
callq 0x6120
testl %eax, %eax
jns 0x7682
callq 0x6620
movl (%rax), %edi
callq 0x64b0
leaq 0x9fc5(%rip), %rdi      # 0x11628
jmp 0x7678
callq 0x6620
movl (%rax), %edi
callq 0x64b0
leaq 0x9fa0(%rip), %rdi      # 0x11618
movq %rax, %rsi
xorl %eax, %eax
callq 0x6c0a
movl 0x8(%rsp), %edi
cmpl $0x3, %edi
jl 0x7690
callq 0x6110
callq 0x6620
movq %rax, %r12
andl $0x0, (%rax)
callq 0x67a0
movl %eax, %edi
callq 0x6320
testq %rax, %rax
jne 0x76c0
movl (%r12), %edi
testl %edi, %edi
jne 0x771b
leaq 0xa0ac(%rip), %rdi      # 0x11767
jmp 0x75b9
movq %rax, %r15
leaq 0xa0ab(%rip), %rdi      # 0x11775
callq 0x65e0
movq %rax, %r12
testq %rax, %rax
jne 0x76e5
movq 0x28(%r15), %rax
cmpb $0x0, (%rax)
cmovneq %rax, %r14
movq %r14, %r12
testq %rbx, %rbx
jne 0x772c
leaq 0x193b7(%rip), %rax     # 0x20aa8
movq (%rax), %rax
leaq 0x193a5(%rip), %rcx     # 0x20aa0
movq (%rcx), %r14
testq %r14, %r14
cmoveq %r12, %r14
testq %rax, %rax
cmovneq %rax, %r14
leaq 0x10(%rsp), %rbx
movq %r14, (%rbx)
andq $0x0, 0x8(%rbx)
jmp 0x772f
callq 0x64b0
leaq 0xa032(%rip), %rdi      # 0x11759
jmp 0x7678
movq (%rbx), %r14
leaq 0xa045(%rip), %rdi      # 0x1177b
callq 0x6870
leaq 0xa041(%rip), %rdi      # 0x11783
callq 0x6870
leaq 0xa03b(%rip), %rdi      # 0x11789
callq 0x6870
movq (%r15), %rsi
leaq 0xa034(%rip), %rdi      # 0x11791
pushq $0x1
popq %rbp
movl %ebp, %edx
callq 0x65d0
movq (%r15), %rsi
leaq 0xa028(%rip), %rdi      # 0x11799
movl %ebp, %edx
callq 0x65d0
leaq 0x9ff6(%rip), %rdi      # 0x11775
movq %r12, %rsi
movl %ebp, %edx
callq 0x65d0
movq 0x20(%r15), %rsi
leaq 0xa00a(%rip), %rdi      # 0x1179e
movl %ebp, %edx
callq 0x65d0
leaq 0x15df6(%rip), %rax     # 0x1d598
movq (%rax), %rsi
leaq 0x9ff7(%rip), %rdi      # 0x117a3
movl %ebp, %edx
callq 0x65d0
pushq $0x11
popq %rdi
xorl %esi, %esi
callq 0x6070
movl %ebp, %edi
xorl %esi, %esi
callq 0x6070
pushq $0x2
popq %rdi
xorl %esi, %esi
callq 0x6070
pushq $0x3
popq %rdi
xorl %esi, %esi
callq 0x6070
pushq $0xf
popq %rdi
xorl %esi, %esi
callq 0x6070
pushq $0xe
popq %rdi
xorl %esi, %esi
callq 0x6070
movq %r14, %rdi
movq %rbx, %rsi
callq 0x6190
movl %ebp, %edi
callq 0x6260