// File: /workspace/github_c_makefile_star2_O2/s3lase[P]v6shell/fd2.c
// Function: main
int
main(int argc, char **argv)
{
	bool eopt;
	int efd, fd, nfd, ofd, opt;
	char *file;

	setmyerrexit(&ut_errexit);
	setmyname(argv[0]);
	setmypid(getpid());

	/*
	 * Set-ID execution is not supported.
	 */
	if (geteuid() != getuid() || getegid() != getgid())
		err(FC_ERR, FMT2S, getmyname(), ERR_SETID);

	/*
	 * File descriptors 0, 1, and 2 must be open.
	 */
	for (fd = 0; fd < 3; fd++)
		if (!fd_isopen(fd))
			err(FC_ERR, "%s: %u: %s\n",
			    getmyname(), (unsigned)fd, strerror(errno));

	ofd = FD1, efd = FD2;
	eopt = false, file = NULL;
	while ((opt = getopt(argc, argv, ":ef:")) != -1)
		switch (opt) {
		case 'e':
			eopt = true;
			break;
		case 'f':
			file = optarg;
			break;
		default:
			usage();
		}
	argc -= optind;
	argv += optind;
	if (argc < 1)
		usage();

	if (file != NULL) {
		if ((nfd = open(file, O_WRONLY|O_APPEND|O_CREAT, 0666)) == -1)
			err(FC_ERR, FMT3S, getmyname(), file, ERR_CREATE);
		if (dup2(nfd, efd) == -1)
			err(FC_ERR, FMT2S, getmyname(), strerror(errno));
		if (eopt && dup2(efd, ofd) == -1)
			err(FC_ERR, FMT2S, getmyname(), strerror(errno));
		(void)close(nfd);
	} else {
		if (eopt)
			ofd = FD2, efd = FD1;
		if (dup2(ofd, efd) == -1)
			err(FC_ERR, FMT2S, getmyname(), strerror(errno));
	}

	/*
	 * Try to execute the specified command.
	 */
	(void)err_pexec(argv[0], argv);
	/*NOTREACHED*/
	return FC_ERR;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x98, %rsp
movq %rsi, %rbx
movl %edi, %ebp
leaq 0x535(%rip), %rdi       # 0x182e
callq 0x17be
movq %rbx, (%rsp)
movq (%rbx), %rdi
callq 0x17cb
callq 0x10b0
movl %eax, %edi
callq 0x181d
callq 0x1110
movl %eax, %r14d
callq 0x10d0
cmpl %eax, %r14d
jne 0x133a
callq 0x1180
movl %eax, %r14d
callq 0x1160
cmpl %eax, %r14d
je 0x135a
callq 0x1799
leaq 0xdee(%rip), %rsi       # 0x2134
leaq 0xdba(%rip), %rcx       # 0x2107
pushq $0x7c
popq %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0x155c
leaq 0x8(%rsp), %r14
leaq 0xdb9(%rip), %r15       # 0x211f
pushq $0x7c
popq %r12
xorl %r13d, %r13d
cmpl $0x3, %r13d
je 0x13b1
movl %r13d, %edi
movq %r14, %rsi
callq 0x11d0
testl %eax, %eax
je 0x13ac
callq 0x1799
movq %rax, %rbx
callq 0x1060
movl (%rax), %edi
callq 0x11c0
movl %r12d, %edi
movq %r15, %rsi
movq %rbx, %rdx
movl %r13d, %ecx
movq %rax, %r8
xorl %eax, %eax
callq 0x155c
incl %r13d
jmp 0x136d
xorl %r14d, %r14d
leaq 0xd70(%rip), %r15       # 0x212b
movq 0x2c16(%rip), %rbx      # 0x3fd8
xorl %r12d, %r12d
movq (%rsp), %r13
movl %ebp, %edi
movq %r13, %rsi
movq %r15, %rdx
callq 0x11a0
cmpl $-0x1, %eax
je 0x13f6
cmpl $0x66, %eax
je 0x13f1
cmpl $0x65, %eax
je 0x13ec
callq 0x1540
jmp 0x13c9
movb $0x1, %r12b
jmp 0x13c9
movq (%rbx), %r14
jmp 0x13c9
movq 0x2bd3(%rip), %rax      # 0x3fd0
movslq (%rax), %r15
cmpl %ebp, %r15d
jl 0x140a
callq 0x1540
testq %r14, %r14
je 0x14d5
movq %r14, %rdi
movl $0x441, %esi            # imm = 0x441
movl $0x1b6, %edx            # imm = 0x1B6
xorl %eax, %eax
callq 0x1190
movl %eax, %ebp
cmpl $-0x1, %eax
jne 0x1451
callq 0x1799
leaq 0xcf6(%rip), %rsi       # 0x2130
leaq 0xcfb(%rip), %r8        # 0x213c
pushq $0x7c
popq %rdi
movq %rax, %rdx
movq %r14, %rcx
xorl %eax, %eax
callq 0x155c
pushq $0x2
popq %rsi
movl %ebp, %edi
callq 0x10e0
cmpl $-0x1, %eax
jne 0x148b
callq 0x1799
movq %rax, %rbx
callq 0x1060
movl (%rax), %edi
callq 0x11c0
leaq 0xcb9(%rip), %rsi       # 0x2134
pushq $0x7c
popq %rdi
movq %rbx, %rdx
movq %rax, %rcx
xorl %eax, %eax
callq 0x155c
testb $0x1, %r12b
je 0x14cc
pushq $0x2
popq %rdi
pushq $0x1
popq %rsi
callq 0x10e0
cmpl $-0x1, %eax
jne 0x14cc
callq 0x1799
movq %rax, %rbx
callq 0x1060
movl (%rax), %edi
callq 0x11c0
leaq 0xc78(%rip), %rsi       # 0x2134
pushq $0x7c
popq %rdi
movq %rbx, %rdx
movq %rax, %rcx
xorl %eax, %eax
callq 0x155c
movl %ebp, %edi
callq 0x1120
jmp 0x1518
movzbl %r12b, %edi
andl $0x1, %edi
pushq $0x2
popq %rsi
subl %edi, %esi
incl %edi
callq 0x10e0
cmpl $-0x1, %eax
jne 0x1518
callq 0x1799
movq %rax, %rbx
callq 0x1060
movl (%rax), %edi
callq 0x11c0
leaq 0xc2c(%rip), %rsi       # 0x2134
pushq $0x7c
popq %rdi
movq %rbx, %rdx
movq %rax, %rcx
xorl %eax, %eax
callq 0x155c
leaq (,%r15,8), %rsi
addq %r13, %rsi
movq (%rsi), %rdi
callq 0x1b38
pushq $0x7c
popq %rax
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq