// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x70, %rsp
movq %rdi, -0x8(%rbp)
leaq -0x10(%rbp), %rdi
callq 0x53f0
cmpl $-0x1, %eax
jne 0x7d4f
jmp 0x7ff3
callq 0x57e0
movl %eax, %ecx
movl %ecx, -0x40(%rbp)
subl $-0x1, %eax
je 0x7d69
jmp 0x7d60
movl -0x40(%rbp), %eax
testl %eax, %eax
je 0x7d7e
jmp 0x7de3
movl -0x10(%rbp), %edi
callq 0x50f0
movl -0xc(%rbp), %edi
callq 0x50f0
jmp 0x7ff3
movl -0x10(%rbp), %edi
xorl %esi, %esi
callq 0x5070
movl -0x10(%rbp), %edi
callq 0x50f0
movl -0xc(%rbp), %edi
callq 0x50f0
movq -0x8(%rbp), %rax
movq (%rax), %rax
movq (%rax), %rdi
movq -0x8(%rbp), %rax
movq (%rax), %rsi
callq 0x5180
movq 0x1223b(%rip), %rax     # 0x19ff0
movq (%rax), %rdi
movq -0x8(%rbp), %rax
movq (%rax), %rax
movq (%rax), %rdx
leaq 0xdb5e(%rip), %rsi      # 0x15927
movb $0x0, %al
callq 0x5850
leaq 0xdddc(%rip), %rdi      # 0x15bb3
callq 0x5830
xorl %edi, %edi
callq 0x5190
movl -0x10(%rbp), %edi
callq 0x50f0
movl $0xd, %edi
movl $0x1, %esi
callq 0x5060
movq %rax, -0x20(%rbp)
movl $0x0, -0x3c(%rbp)
movl $0x0, -0x38(%rbp)
cmpl $0x7d2, -0x38(%rbp)     # imm = 0x7D2
jg 0x7fc3
movl -0x38(%rbp), %eax
movl $0x7d0, %ecx            # imm = 0x7D0
subl 0x150b9(%rip), %ecx     # 0x1cee0
addl $0x2, %ecx
cmpl %ecx, %eax
jg 0x7e44
movslq -0x38(%rbp), %rcx
leaq 0x150a7(%rip), %rax     # 0x1cee0
movq 0x10(%rax,%rcx,8), %rax
movq %rax, -0x48(%rbp)
jmp 0x7e68
movq 0x1509d(%rip), %rax     # 0x1cee8
movl -0x38(%rbp), %ecx
subl $0x7d0, %ecx            # imm = 0x7D0
addl 0x15086(%rip), %ecx     # 0x1cee0
subl $0x3, %ecx
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rax
movq %rax, -0x28(%rbp)
movl -0x38(%rbp), %edi
callq 0x5d70
addl $0x1, %eax
cmpl 0x15063(%rip), %eax     # 0x1cee4
jge 0x7e93
movl -0x38(%rbp), %edi
callq 0x5d70
addl $0x1, %eax
movl %eax, -0x4c(%rbp)
jmp 0x7e9c
movl 0x1504b(%rip), %eax     # 0x1cee4
movl %eax, -0x4c(%rbp)
movl -0x4c(%rbp), %eax
subl $0x1, %eax
movl %eax, -0x34(%rbp)
cmpl $0x0, -0x34(%rbp)
jge 0x7eb0
jmp 0x7fc3
cmpl $0x0, -0x34(%rbp)
jne 0x7ebb
jmp 0x7fb5
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 0x7f21
movl -0xc(%rbp), %eax
movl %eax, -0x5c(%rbp)
leaq -0x14(%rbp), %rax
movq %rax, -0x58(%rbp)
movq -0x28(%rbp), %rax
movl (%rax), %edi
leaq -0x14(%rbp), %rsi
callq 0x5bd0
movl -0x5c(%rbp), %edi
movq -0x58(%rbp), %rsi
movq %rax, %rdx
callq 0x8000
cmpq $0x0, %rax
jge 0x7f11
jmp 0x7f21
jmp 0x7f13
movq -0x28(%rbp), %rax
addq $0x10, %rax
movq %rax, -0x28(%rbp)
jmp 0x7ed3
movl -0x38(%rbp), %eax
movl $0x7d0, %ecx            # imm = 0x7D0
subl 0x14fb1(%rip), %ecx     # 0x1cee0
addl $0x2, %ecx
cmpl %ecx, %eax
jg 0x7f4c
movslq -0x38(%rbp), %rcx
leaq 0x14f9f(%rip), %rax     # 0x1cee0
movq 0x10(%rax,%rcx,8), %rax
movq %rax, -0x68(%rbp)
jmp 0x7f70
movq 0x14f95(%rip), %rax     # 0x1cee8
movl -0x38(%rbp), %ecx
subl $0x7d0, %ecx            # imm = 0x7D0
addl 0x14f7e(%rip), %ecx     # 0x1cee0
subl $0x3, %ecx
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x68(%rbp)
movq -0x68(%rbp), %rax
movslq -0x34(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movzwl 0x4(%rax), %eax
andl $0x200, %eax            # imm = 0x200
movl %eax, -0x3c(%rbp)
cmpl $0x0, %eax
je 0x7f92
jmp 0x7fb5
movl -0xc(%rbp), %edi
leaq 0xd96b(%rip), %rsi      # 0x15907
movl $0x1, %edx
callq 0x8000
cmpq $0x0, %rax
jge 0x7fae
jmp 0x7fc3
movl $0x0, -0x3c(%rbp)
movl -0x38(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
jmp 0x7e0c
cmpl $0x0, -0x3c(%rbp)
je 0x7fdd
movl -0xc(%rbp), %edi
leaq 0xd934(%rip), %rsi      # 0x15907
movl $0x1, %edx
callq 0x8000
movl -0xc(%rbp), %edi
callq 0x50f0
movq -0x20(%rbp), %rsi
movl $0xd, %edi
callq 0x5060
addq $0x70, %rsp
popq %rbp
retq
nopl (%rax)