// File: /workspace/github_c_makefile_star2_O0/odknt[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 < 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 $0x60, %rsp
movq %rdi, -0x8(%rbp)
leaq -0x10(%rbp), %rdi
callq 0x64f0
cmpl $-0x1, %eax
jne 0x929f
jmp 0x94b2
callq 0x6920
movl %eax, %ecx
movl %ecx, -0x40(%rbp)
subl $-0x1, %eax
je 0x92b9
jmp 0x92b0
movl -0x40(%rbp), %eax
testl %eax, %eax
je 0x92ce
jmp 0x9333
movl -0x10(%rbp), %edi
callq 0x60f0
movl -0xc(%rbp), %edi
callq 0x60f0
jmp 0x94b2
movl -0x10(%rbp), %edi
xorl %esi, %esi
callq 0x6070
movl -0x10(%rbp), %edi
callq 0x60f0
movl -0xc(%rbp), %edi
callq 0x60f0
movq -0x8(%rbp), %rax
movq (%rax), %rax
movq (%rax), %rdi
movq -0x8(%rbp), %rax
movq (%rax), %rsi
callq 0x6190
movq 0xfceb(%rip), %rax      # 0x18ff0
movq (%rax), %rdi
movq -0x8(%rbp), %rax
movq (%rax), %rax
movq (%rax), %rdx
leaq 0xb622(%rip), %rsi      # 0x1493b
movb $0x0, %al
callq 0x69d0
leaq 0xb8ef(%rip), %rdi      # 0x14c16
callq 0x69a0
xorl %edi, %edi
callq 0x61b0
movl -0x10(%rbp), %edi
callq 0x60f0
movl $0xd, %edi
movl $0x1, %esi
callq 0x6060
movq %rax, -0x20(%rbp)
movl $0x0, -0x3c(%rbp)
movl $0x0, -0x38(%rbp)
movl -0x38(%rbp), %eax
cmpl 0x12e7b(%rip), %eax     # 0x1c1e0
jge 0x9482
movq 0x12e76(%rip), %rax     # 0x1c1e8
movslq -0x38(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x28(%rbp)
movl -0x38(%rbp), %edi
callq 0x77f0
addl $0x1, %eax
cmpl 0x12e55(%rip), %eax     # 0x1c1e4
jge 0x93a1
movl -0x38(%rbp), %edi
callq 0x77f0
addl $0x1, %eax
movl %eax, -0x44(%rbp)
jmp 0x93aa
movl 0x12e3d(%rip), %eax     # 0x1c1e4
movl %eax, -0x44(%rbp)
movl -0x44(%rbp), %eax
subl $0x1, %eax
movl %eax, -0x34(%rbp)
cmpl $0x0, -0x34(%rbp)
jge 0x93be
jmp 0x9482
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 0x9424
movl -0xc(%rbp), %eax
movl %eax, -0x54(%rbp)
leaq -0x14(%rbp), %rax
movq %rax, -0x50(%rbp)
movq -0x28(%rbp), %rax
movl (%rax), %edi
leaq -0x14(%rbp), %rsi
callq 0x6d70
movl -0x54(%rbp), %edi
movq -0x50(%rbp), %rsi
movq %rax, %rdx
callq 0x94c0
cmpq $0x0, %rax
jge 0x9414
jmp 0x9424
jmp 0x9416
movq -0x28(%rbp), %rax
addq $0x10, %rax
movq %rax, -0x28(%rbp)
jmp 0x93d6
movq 0x12dbd(%rip), %rax     # 0x1c1e8
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 0x9451
jmp 0x9474
movl -0xc(%rbp), %edi
leaq 0xb4ac(%rip), %rsi      # 0x14907
movl $0x1, %edx
callq 0x94c0
cmpq $0x0, %rax
jge 0x946d
jmp 0x9482
movl $0x0, -0x3c(%rbp)
movl -0x38(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
jmp 0x935c
cmpl $0x0, -0x3c(%rbp)
je 0x949c
movl -0xc(%rbp), %edi
leaq 0xb475(%rip), %rsi      # 0x14907
movl $0x1, %edx
callq 0x94c0
movl -0xc(%rbp), %edi
callq 0x60f0
movq -0x20(%rbp), %rsi
movl $0xd, %edi
callq 0x6060
addq $0x60, %rsp
popq %rbp
retq
nopl (%rax,%rax)