// File: /workspace/github_c_makefile_star2_O1/mcaimi[P]st/st.c
// Function: externalpipe
void
externalpipe(const Arg *arg)
{
  int to[2];
  char buf[UTF_SIZ];
  void (*oldsigpipe)(int);
  Glyph *bp, *end;
  int lastpos, n, newline;

  if (pipe(to) == -1)
    return;

  switch (fork()) {
    case -1:
      close(to[0]);
      close(to[1]);
      return;
    case 0:
      dup2(to[0], STDIN_FILENO);
      close(to[0]);
      close(to[1]);
      execvp(shell, (char *const []) {
        shell,
        "-c",
        (char *)arg->v,
        0
      });

      fprintf(stderr, "st: execvp %s ", ((char **)arg->v)[0]);
      perror("failed");
      exit(0);
  }

  close(to[0]);

  /* ignore sigpipe for now, in case child exits early */
  oldsigpipe = signal(SIGPIPE, SIG_IGN);
  newline = 0;
  for (n = 0; n < term.row; n++) {
    bp = term.line[n];
    lastpos = MIN(tlinelen(n) + 1, term.col) - 1;
    if (lastpos < 0)
      break;
    end = &bp[lastpos + 1];
    for (; bp < end; ++bp)
      if (xwrite(to[1], buf, utf8encode(bp->u, buf)) < 0)
        break;
    if ((newline = term.line[n][lastpos].mode & ATTR_WRAP))
      continue;
    if (xwrite(to[1], "\n", 1) < 0)
      break;
    newline = 0;
  }
  if (newline)
    (void)xwrite(to[1], "\n", 1);
  close(to[1]);
  /* restore */
  signal(SIGPIPE, oldsigpipe);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %rdi, %rbx
leaq 0x4(%rsp), %rdi
callq 0x6440
cmpl $-0x1, %eax
je 0x8e53
callq 0x68d0
movl 0x4(%rsp), %edi
cmpl $-0x1, %eax
je 0x8e45
testl %eax, %eax
je 0x8e62
callq 0x6110
movl $0x1, %esi
movl $0xd, %edi
callq 0x6070
movq %rax, %rbx
cmpl $0x0, 0x159cd(%rip)     # 0x1e698
jle 0x8e2d
xorl %edi, %edi
callq 0x7892
incl %eax
movl 0x159bc(%rip), %ecx     # 0x1e69c
cmpl %ecx, %eax
cmovgel %ecx, %eax
testl %eax, %eax
jle 0x8e2d
movq %rbx, 0x10(%rsp)
xorl %r14d, %r14d
leaq 0xc(%rsp), %r13
movq 0x1599f(%rip), %rcx     # 0x1e6a0
movq %r14, 0x20(%rsp)
movq (%rcx,%r14,8), %r14
movl %eax, %eax
shlq $0x4, %rax
movq %rax, 0x18(%rsp)
leaq (%r14,%rax), %r15
movl 0x8(%rsp), %ebp
movl (%r14), %edi
movq %r13, %rsi
callq 0x723d
testq %rax, %rax
je 0x8d4f
movq %rax, %rbx
movq %rax, %r12
movl %ebp, %edi
movq %r13, %rsi
movq %r12, %rdx
callq 0x6990
testq %rax, %rax
js 0x8d53
addq %rax, %r13
subq %rax, %r12
jne 0x8d33
jmp 0x8d56
movb $0x1, %al
jmp 0x8d61
movq %rax, %rbx
testq %rbx, %rbx
setns %al
leaq 0xc(%rsp), %r13
testb %al, %al
je 0x8d6e
addq $0x10, %r14
cmpq %r15, %r14
jb 0x8d19
movq 0x1592b(%rip), %rax     # 0x1e6a0
movq 0x20(%rsp), %r14
movq (%rax,%r14,8), %rax
movq 0x18(%rsp), %rcx
movzwl -0xc(%rax,%rcx), %ebx
andl $0x100, %ebx            # imm = 0x100
jne 0x8dca
movl $0x1, %r12d
movl 0x8(%rsp), %ebp
leaq 0x98d8(%rip), %r13      # 0x12679
movl %ebp, %edi
movq %r13, %rsi
movq %r12, %rdx
callq 0x6990
testq %rax, %rax
js 0x8dbe
subq %rax, %r12
addq %rax, %r13
testq %r12, %r12
jne 0x8da1
xorl %ebx, %ebx
testq %rax, %rax
leaq 0xc(%rsp), %r13
js 0x8df6
incq %r14
movslq 0x158c4(%rip), %rax     # 0x1e698
cmpq %rax, %r14
jge 0x8df6
movl %r14d, %edi
callq 0x7892
incl %eax
movl 0x158b3(%rip), %ecx     # 0x1e69c
cmpl %ecx, %eax
cmovgel %ecx, %eax
testl %eax, %eax
jg 0x8cfa
testl %ebx, %ebx
movq 0x10(%rsp), %rbx
je 0x8e2d
movl $0x1, %r14d
leaq 0x986d(%rip), %r15      # 0x12679
movl 0x8(%rsp), %ebp
movl %ebp, %edi
movq %r15, %rsi
movq %r14, %rdx
callq 0x6990
testq %rax, %rax
js 0x8e2d
subq %rax, %r14
addq %rax, %r15
testq %r14, %r14
jne 0x8e10
movl 0x8(%rsp), %edi
callq 0x6110
movl $0xd, %edi
movq %rbx, %rsi
callq 0x6070
jmp 0x8e53
callq 0x6110
movl 0x8(%rsp), %edi
callq 0x6110
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x4(%rsp), %rsi
leaq 0x28(%rsp), %rdx
movq %rbx, %rcx
callq 0x6ced