// File: /workspace/github_c_makefile_star2_O2/anachronic[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(((char **)arg->v)[0], (char **)arg->v);
		fprintf(stderr, "st: execvp %s\n", ((char **)arg->v)[0]);
		perror("failed");
		exit(0);
	}

	close(to[0]);
	/* ignore sigpipe for now, in case child exists early */
	oldsigpipe = signal(SIGPIPE, SIG_IGN);
	newline = 0;
	for (n = 0; n <= HISTSIZE + 2; n++) {
		bp = TLINE_HIST(n);
		lastpos = MIN(tlinehistlen(n) + 1, term.col) - 1;
		if (lastpos < 0)
			break;
        if (lastpos == 0)
            continue;
		end = &bp[lastpos + 1];
		for (; bp < end; ++bp)
			if (xwrite(to[1], buf, utf8encode(bp->u, buf)) < 0)
				break;
		if ((newline = TLINE_HIST(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 $0x28, %rsp
movq %rdi, %rbx
leaq 0x4(%rsp), %rdi
callq 0x53f0
cmpl $-0x1, %eax
je 0x7252
callq 0x57d0
movl 0x4(%rsp), %edi
cmpl $-0x1, %eax
je 0x7215
testl %eax, %eax
je 0x7261
callq 0x50f0
pushq $0xd
popq %rdi
pushq $0x1
popq %rsi
callq 0x5060
movq %rax, 0x10(%rsp)
xorl %r15d, %r15d
leaq 0x24(%rsp), %r12
xorl %ebp, %ebp
cmpq $0x7d3, %r15            # imm = 0x7D3
je 0x7225
movslq 0x117e1(%rip), %rax     # 0x188f0
movl $0x7d2, %ecx            # imm = 0x7D2
subl %eax, %ecx
movslq %ecx, %rcx
leaq -0x3e80(,%r15,8), %rdx
addq 0x117d0(%rip), %rdx     # 0x188f8
cmpq %rcx, %r15
leaq 0x117be(%rip), %rcx     # 0x188f0
leaq 0x10(%rcx,%r15,8), %r13
leaq -0x18(%rdx,%rax,8), %rax
cmovleq %r13, %rax
movq (%rax), %r14
movl %r15d, %edi
callq 0x5c06
incl %eax
movl 0x117a1(%rip), %ecx     # 0x188f4
cmpl %ecx, %eax
cmovgel %ecx, %eax
testl %eax, %eax
jle 0x7225
movl %eax, %ecx
decl %ecx
je 0x720d
movl %ecx, 0xc(%rsp)
leaq -0x7d0(%r15), %rcx
movq %rcx, 0x18(%rsp)
movl %eax, %ebx
shlq $0x4, %rbx
addq %r14, %rbx
cmpq %rbx, %r14
jae 0x71ad
movl 0x8(%rsp), %ebp
movl (%r14), %edi
movq %r12, %rsi
callq 0x5b32
movl %ebp, %edi
movq %r12, %rsi
movq %rax, %rdx
callq 0x72b6
addq $0x10, %r14
testq %rax, %rax
jns 0x7183
movslq 0x1173c(%rip), %rax     # 0x188f0
movl $0x7d2, %ecx            # imm = 0x7D2
subl %eax, %ecx
movslq %ecx, %rcx
movq 0x18(%rsp), %rdx
shlq $0x3, %rdx
addq 0x1172a(%rip), %rdx     # 0x188f8
cmpq %rcx, %r15
leaq -0x18(%rdx,%rax,8), %rax
cmovgq %rax, %r13
movq (%r13), %rax
movl 0xc(%rsp), %ecx
shlq $0x4, %rcx
movzwl 0x4(%rax,%rcx), %ebp
andl $0x200, %ebp            # imm = 0x200
jne 0x720d
movl 0x8(%rsp), %edi
leaq 0x9457(%rip), %rsi      # 0x10655
pushq $0x1
popq %rdx
callq 0x72b6
xorl %ebp, %ebp
testq %rax, %rax
js 0x723c
incq %r15
jmp 0x70fb
callq 0x50f0
movl 0x8(%rsp), %edi
callq 0x50f0
jmp 0x7252
testl %ebp, %ebp
je 0x723c
movl 0x8(%rsp), %edi
leaq 0x9421(%rip), %rsi      # 0x10655
pushq $0x1
popq %rdx
callq 0x72b6
movl 0x8(%rsp), %edi
callq 0x50f0
pushq $0xd
popq %rdi
movq 0x10(%rsp), %rsi
callq 0x5060
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
xorl %esi, %esi
callq 0x5070
movl 0x4(%rsp), %edi
callq 0x50f0
movl 0x8(%rsp), %edi
callq 0x50f0
movq (%rbx), %rsi
movq (%rsi), %rdi
callq 0x5180
movq 0x10d64(%rip), %rax     # 0x17ff0
movq (%rax), %rdi
movq (%rbx), %rax
movq (%rax), %rdx
leaq 0x93d9(%rip), %rsi      # 0x10675
xorl %eax, %eax
callq 0x5850
leaq 0x9655(%rip), %rdi      # 0x108ff
callq 0x5830
xorl %edi, %edi
callq 0x5190