// File: /workspace/github_c_makefile_star2_O1/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 $0x38, %rsp
movq %rdi, %rbx
leaq 0x8(%rsp), %rdi
callq 0x53f0
cmpl $-0x1, %eax
je 0x78fb
callq 0x57e0
movl 0x8(%rsp), %edi
cmpl $-0x1, %eax
je 0x78ed
testl %eax, %eax
je 0x790a
callq 0x50f0
movl $0x1, %esi
movl $0xd, %edi
callq 0x5060
movq %rax, 0x18(%rsp)
xorl %r15d, %r15d
leaq 0x10(%rsp), %r13
xorl %ebx, %ebx
movslq 0x111bc(%rip), %rax     # 0x188f0
movl $0x7d2, %ecx            # imm = 0x7D2
subl %eax, %ecx
movslq %ecx, %rcx
leaq -0x3e80(,%r15,8), %rdx
addq 0x111ab(%rip), %rdx     # 0x188f8
cmpq %rcx, %r15
leaq 0x11199(%rip), %rcx     # 0x188f0
leaq 0x10(%rcx,%r15,8), %rcx
leaq -0x18(%rdx,%rax,8), %rax
movq %rcx, 0x30(%rsp)
cmovleq %rcx, %rax
movq (%rax), %r14
movl %r15d, %edi
callq 0x6098
incl %eax
movl 0x11177(%rip), %ecx     # 0x188f4
cmpl %ecx, %eax
cmovgel %ecx, %eax
testl %eax, %eax
jle 0x78a1
movl %eax, %ecx
decl %ecx
je 0x7891
movl %ecx, 0x14(%rsp)
movq %r15, 0x28(%rsp)
leaq -0x7d0(%r15), %rcx
movq %rcx, 0x20(%rsp)
movl %eax, %r15d
shlq $0x4, %r15
addq %r14, %r15
movl 0xc(%rsp), %ebp
movl (%r14), %edi
movq %r13, %rsi
callq 0x6004
testq %rax, %rax
je 0x77e9
movq %rax, %rbx
movq %rax, %r12
movl %ebp, %edi
movq %r13, %rsi
movq %r12, %rdx
callq 0x5880
testq %rax, %rax
js 0x77ed
addq %rax, %r13
subq %rax, %r12
jne 0x77cd
jmp 0x77f0
movb $0x1, %al
jmp 0x77fb
movq %rax, %rbx
testq %rbx, %rbx
setns %al
leaq 0x10(%rsp), %r13
testb %al, %al
je 0x7808
addq $0x10, %r14
cmpq %r15, %r14
jb 0x77b3
movslq 0x110e1(%rip), %rax     # 0x188f0
movl $0x7d2, %ecx            # imm = 0x7D2
subl %eax, %ecx
movslq %ecx, %rcx
movq 0x20(%rsp), %rdx
shlq $0x3, %rdx
addq 0x110cf(%rip), %rdx     # 0x188f8
movq 0x28(%rsp), %r15
cmpq %rcx, %r15
leaq -0x18(%rdx,%rax,8), %rax
movq 0x30(%rsp), %rcx
cmovgq %rax, %rcx
movq (%rcx), %rax
movl 0x14(%rsp), %ecx
shlq $0x4, %rcx
movzwl 0x4(%rax,%rcx), %ebx
andl $0x200, %ebx            # imm = 0x200
jne 0x7891
movl $0x1, %r12d
movl 0xc(%rsp), %ebp
leaq 0x9def(%rip), %r13      # 0x11657
movl %ebp, %edi
movq %r13, %rsi
movq %r12, %rdx
callq 0x5880
testq %rax, %rax
js 0x7885
subq %rax, %r12
addq %rax, %r13
testq %r12, %r12
jne 0x7868
xorl %ebx, %ebx
testq %rax, %rax
leaq 0x10(%rsp), %r13
js 0x78a1
incq %r15
cmpq $0x7d3, %r15            # imm = 0x7D3
jne 0x772d
testl %ebx, %ebx
je 0x78d3
movl $0x1, %r14d
leaq 0x9da5(%rip), %r15      # 0x11657
movl 0xc(%rsp), %ebp
movl %ebp, %edi
movq %r15, %rsi
movq %r14, %rdx
callq 0x5880
testq %rax, %rax
js 0x78d3
subq %rax, %r14
addq %rax, %r15
testq %r14, %r14
jne 0x78b6
movl 0xc(%rsp), %edi
callq 0x50f0
movl $0xd, %edi
movq 0x18(%rsp), %rsi
callq 0x5060
jmp 0x78fb
callq 0x50f0
movl 0xc(%rsp), %edi
callq 0x50f0
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x8(%rsp), %rsi
movq %rbx, %rdx
callq 0x5a85