// File: /workspace/github_c_makefile_star2_O1/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 0x555(%rip), %rdi       # 0x184e
callq 0x17dc
movq (%rbx), %rdi
callq 0x17e9
callq 0x10b0
movl %eax, %edi
callq 0x183d
callq 0x1110
movl %eax, %r14d
callq 0x10d0
cmpl %eax, %r14d
jne 0x1336
callq 0x1180
movl %eax, %r14d
callq 0x1160
cmpl %eax, %r14d
je 0x1358
callq 0x17b7
leaq 0xdf2(%rip), %rsi       # 0x2134
leaq 0xdbe(%rip), %rcx       # 0x2107
movl $0x7c, %edi
movq %rax, %rdx
xorl %eax, %eax
callq 0x1570
leaq 0x8(%rsp), %r14
leaq 0xdbb(%rip), %r15       # 0x211f
xorl %r12d, %r12d
movl %r12d, %edi
movq %r14, %rsi
callq 0x11d0
testl %eax, %eax
je 0x13a2
callq 0x17b7
movq %rax, %r13
callq 0x1060
movl (%rax), %edi
callq 0x11c0
movl $0x7c, %edi
movq %r15, %rsi
movq %r13, %rdx
movl %r12d, %ecx
movq %rax, %r8
xorl %eax, %eax
callq 0x1570
incl %r12d
cmpl $0x3, %r12d
jne 0x1367
xorl %r13d, %r13d
leaq 0xd76(%rip), %r15       # 0x212b
leaq 0xd8e(%rip), %r12       # 0x214a
xorl %r14d, %r14d
movl %ebp, %edi
movq %rbx, %rsi
movq %r15, %rdx
callq 0x11a0
cmpl $-0x1, %eax
je 0x1405
cmpl $0x65, %eax
je 0x1400
cmpl $0x66, %eax
je 0x13f4
callq 0x17b7
movl $0x7c, %edi
movq %r12, %rsi
movq %rax, %rdx
xorl %eax, %eax
callq 0x1570
jmp 0x13bf
movq 0x2bdd(%rip), %rax      # 0x3fd8
movq (%rax), %r14
jmp 0x13bf
movb $0x1, %r13b
jmp 0x13bf
movq 0x2bc4(%rip), %rax      # 0x3fd0
movslq (%rax), %r15
cmpl %ebp, %r15d
jl 0x142f
callq 0x17b7
leaq 0xd2a(%rip), %rsi       # 0x214a
movl $0x7c, %edi
movq %rax, %rdx
xorl %eax, %eax
callq 0x1570
testq %r14, %r14
je 0x1506
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 0x1478
callq 0x17b7
leaq 0xcd1(%rip), %rsi       # 0x2130
leaq 0xcd6(%rip), %r8        # 0x213c
movl $0x7c, %edi
movq %rax, %rdx
movq %r14, %rcx
xorl %eax, %eax
callq 0x1570
movl %ebp, %edi
movl $0x2, %esi
callq 0x10e0
cmpl $-0x1, %eax
jne 0x14b6
callq 0x17b7
movq %rax, %r14
callq 0x1060
movl (%rax), %edi
callq 0x11c0
leaq 0xc90(%rip), %rsi       # 0x2134
movl $0x7c, %edi
movq %r14, %rdx
movq %rax, %rcx
xorl %eax, %eax
callq 0x1570
testb $0x1, %r13b
je 0x14fd
movl $0x2, %edi
movl $0x1, %esi
callq 0x10e0
cmpl $-0x1, %eax
jne 0x14fd
callq 0x17b7
movq %rax, %r14
callq 0x1060
movl (%rax), %edi
callq 0x11c0
leaq 0xc49(%rip), %rsi       # 0x2134
movl $0x7c, %edi
movq %r14, %rdx
movq %rax, %rcx
xorl %eax, %eax
callq 0x1570
movl %ebp, %edi
callq 0x1120
jmp 0x154d
movzbl %r13b, %edi
andl $0x1, %edi
movl $0x2, %esi
subl %edi, %esi
incl %edi
callq 0x10e0
cmpl $-0x1, %eax
jne 0x154d
callq 0x17b7
movq %rax, %r14
callq 0x1060
movl (%rax), %edi
callq 0x11c0
leaq 0xbf9(%rip), %rsi       # 0x2134
movl $0x7c, %edi
movq %r14, %rdx
movq %rax, %rcx
xorl %eax, %eax
callq 0x1570
leaq (%rbx,%r15,8), %rsi
movq (%rsi), %rdi
callq 0x1b29
movl $0x7c, %eax
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq