// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x80, %rsp
movq %rdi, -0x8(%rbp)
leaq -0x10(%rbp), %rdi
callq 0x6440
cmpl $-0x1, %eax
jne 0x93f2
jmp 0x9631
callq 0x68e0
movl %eax, %ecx
movl %ecx, -0x64(%rbp)
subl $-0x1, %eax
je 0x940f
jmp 0x9403
movl -0x64(%rbp), %eax
testl %eax, %eax
je 0x9424
jmp 0x94b2
movl -0x10(%rbp), %edi
callq 0x6110
movl -0xc(%rbp), %edi
callq 0x6110
jmp 0x9631
movl -0x10(%rbp), %edi
xorl %esi, %esi
callq 0x6080
movl -0x10(%rbp), %edi
callq 0x6110
movl -0xc(%rbp), %edi
callq 0x6110
leaq 0x16353(%rip), %rax     # 0x1f798
movq (%rax), %rdi
leaq 0x16349(%rip), %rax     # 0x1f798
movq (%rax), %rax
movq %rax, -0x60(%rbp)
leaq 0xd4a0(%rip), %rax      # 0x168fd
movq %rax, -0x58(%rbp)
movq -0x8(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x50(%rbp)
movq $0x0, -0x48(%rbp)
leaq -0x60(%rbp), %rsi
callq 0x6190
movq 0x15b6c(%rip), %rax     # 0x1eff0
movq (%rax), %rdi
movq -0x8(%rbp), %rax
movq (%rax), %rax
movq (%rax), %rdx
leaq 0xd468(%rip), %rsi      # 0x16900
movb $0x0, %al
callq 0x6970
leaq 0xd71b(%rip), %rdi      # 0x16bc1
callq 0x6950
xorl %edi, %edi
callq 0x61b0
movl -0x10(%rbp), %edi
callq 0x6110
movl $0xd, %edi
movl $0x1, %esi
callq 0x6070
movq %rax, -0x20(%rbp)
movl $0x0, -0x3c(%rbp)
movl $0x0, -0x38(%rbp)
movl -0x38(%rbp), %eax
cmpl 0x18f74(%rip), %eax     # 0x22458
jge 0x9601
movq 0x18f6f(%rip), %rax     # 0x22460
movslq -0x38(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x28(%rbp)
movl -0x38(%rbp), %edi
callq 0x7860
addl $0x1, %eax
cmpl 0x18f4e(%rip), %eax     # 0x2245c
jge 0x9520
movl -0x38(%rbp), %edi
callq 0x7860
addl $0x1, %eax
movl %eax, -0x68(%rbp)
jmp 0x9529
movl 0x18f36(%rip), %eax     # 0x2245c
movl %eax, -0x68(%rbp)
movl -0x68(%rbp), %eax
subl $0x1, %eax
movl %eax, -0x34(%rbp)
cmpl $0x0, -0x34(%rbp)
jge 0x953d
jmp 0x9601
movq -0x28(%rbp), %rax
movl -0x34(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq %rax, -0x30(%rbp)
movq -0x28(%rbp), %rax
cmpq -0x30(%rbp), %rax
jae 0x95a3
movl -0xc(%rbp), %eax
movl %eax, -0x74(%rbp)
leaq -0x14(%rbp), %rax
movq %rax, -0x70(%rbp)
movq -0x28(%rbp), %rax
movl (%rax), %edi
leaq -0x14(%rbp), %rsi
callq 0x6da0
movl -0x74(%rbp), %edi
movq -0x70(%rbp), %rsi
movq %rax, %rdx
callq 0x9640
cmpq $0x0, %rax
jge 0x9593
jmp 0x95a3
jmp 0x9595
movq -0x28(%rbp), %rax
addq $0x10, %rax
movq %rax, -0x28(%rbp)
jmp 0x9555
movq 0x18eb6(%rip), %rax     # 0x22460
movslq -0x38(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x34(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movzwl 0x4(%rax), %eax
andl $0x100, %eax            # imm = 0x100
movl %eax, -0x3c(%rbp)
cmpl $0x0, %eax
je 0x95d0
jmp 0x95f3
movl -0xc(%rbp), %edi
leaq 0xd2ef(%rip), %rsi      # 0x168c9
movl $0x1, %edx
callq 0x9640
cmpq $0x0, %rax
jge 0x95ec
jmp 0x9601
movl $0x0, -0x3c(%rbp)
movl -0x38(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
jmp 0x94db
cmpl $0x0, -0x3c(%rbp)
je 0x961b
movl -0xc(%rbp), %edi
leaq 0xd2b8(%rip), %rsi      # 0x168c9
movl $0x1, %edx
callq 0x9640
movl -0xc(%rbp), %edi
callq 0x6110
movq -0x20(%rbp), %rsi
movl $0xd, %edi
callq 0x6070
addq $0x80, %rsp
popq %rbp
retq
nopw (%rax,%rax)