#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */

/* Variables and functions */
scalar_t__ ENOENT;
int /*<<< orphan*/ SIGHUP;
int /*<<< orphan*/ SIG_IGN;
int /*<<< orphan*/ STDERR_FILENO;
int /*<<< orphan*/ STDOUT_FILENO;
int /*<<< orphan*/ dofile();
int dup2(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ err(int, char *, char *);
scalar_t__ errno;
int /*<<< orphan*/ execvp(char *, char **);
int getopt(int, char **, char *);
scalar_t__ isatty(int /*<<< orphan*/);
scalar_t__ optind;
int /*<<< orphan*/ signal(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ usage();
int main(int argc, char *argv[]) {
  int exit_status;
  while (getopt(argc, argv, "") != -1)
    usage();
  argc -= optind;
  argv += optind;
  if (argc < 1)
    usage();
  if (isatty(STDOUT_FILENO))
    dofile();
  if (isatty(STDERR_FILENO) && dup2(STDOUT_FILENO, STDERR_FILENO) == -1)
    err(127, "%s", argv[0]);
  (void)signal(SIGHUP, SIG_IGN);
  execvp(*argv, argv);
  exit_status = (errno == ENOENT) ? 127 : 126;
  err(exit_status, "%s", argv[0]);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xe5e(%rip),%rdx
call   1090 <getopt@plt>
cmp    $0xffffffff,%eax
je     11be <main+0x3e>
mov    $0x0,%al
call   1080 <usage@plt>
jmp    1196 <main+0x16>
mov    0x2e13(%rip),%rax
mov    (%rax),%rcx
movslq -0x8(%rbp),%rax
sub    %rcx,%rax
mov    %eax,-0x8(%rbp)
mov    0x2dff(%rip),%rax
mov    (%rax),%rax
shl    $0x3,%rax
add    -0x10(%rbp),%rax
mov    %rax,-0x10(%rbp)
cmpl   $0x1,-0x8(%rbp)
jge    11f9 <main+0x79>
mov    $0x0,%al
call   1080 <usage@plt>
mov    0x2de8(%rip),%rax
mov    (%rax),%edi
call   1040 <isatty@plt>
cmp    $0x0,%rax
je     1218 <main+0x98>
mov    $0x0,%al
call   1030 <dofile@plt>
mov    0x2d99(%rip),%rax
mov    (%rax),%edi
call   1040 <isatty@plt>
cmp    $0x0,%rax
je     1268 <main+0xe8>
mov    0x2db1(%rip),%rax
mov    (%rax),%edi
mov    0x2d78(%rip),%rax
mov    (%rax),%esi
call   1050 <dup2@plt>
cmp    $0xffffffff,%eax
jne    1268 <main+0xe8>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
mov    $0x7f,%edi
lea    0xd9d(%rip),%rsi
call   1070 <err@plt>
mov    0x2d81(%rip),%rax
mov    (%rax),%edi
mov    0x2d58(%rip),%rax
mov    (%rax),%esi
call   1060 <signal@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
mov    -0x10(%rbp),%rsi
call   10a0 <execvp@plt>
mov    0x2d2a(%rip),%rax
mov    (%rax),%rdx
mov    0x2d08(%rip),%rax
mov    (%rax),%rsi
mov    $0x7e,%eax
mov    $0x7f,%ecx
cmp    %rsi,%rdx
cmove  %ecx,%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xd39(%rip),%rsi
call   1070 <err@plt>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %edi,%ebp
lea    0xe6f(%rip),%rdx
call   1090 <getopt@plt>
cmp    $0xffffffff,%eax
je     11c9 <main+0x49>
lea    0xe5e(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
xor    %eax,%eax
call   1080 <usage@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r14,%rdx
call   1090 <getopt@plt>
cmp    $0xffffffff,%eax
jne    11b0 <main+0x30>
mov    0x2e08(%rip),%rax
mov    (%rax),%r14
sub    %r14d,%ebp
test   %ebp,%ebp
jg     11e1 <main+0x61>
xor    %eax,%eax
call   1080 <usage@plt>
mov    0x2e00(%rip),%r15
mov    (%r15),%edi
call   1040 <isatty@plt>
test   %rax,%rax
je     11fc <main+0x7c>
xor    %eax,%eax
call   1030 <dofile@plt>
lea    (%rbx,%r14,8),%rbx
mov    0x2db1(%rip),%rbp
mov    0x0(%rbp),%edi
call   1040 <isatty@plt>
test   %rax,%rax
je     1238 <main+0xb8>
mov    (%r15),%edi
mov    0x0(%rbp),%esi
call   1050 <dup2@plt>
cmp    $0xffffffff,%eax
jne    1238 <main+0xb8>
mov    (%rbx),%rdx
lea    0xdd2(%rip),%rsi
mov    $0x7f,%edi
call   1070 <err@plt>
mov    0x2db1(%rip),%rax
mov    (%rax),%edi
mov    0x2d88(%rip),%rax
mov    (%rax),%esi
call   1060 <signal@plt>
mov    (%rbx),%rdi
mov    %rbx,%rsi
call   10a0 <execvp@plt>
mov    0x2d5f(%rip),%rax
mov    (%rax),%rax
mov    0x2d3d(%rip),%rcx
xor    %edi,%edi
cmp    (%rcx),%rax
sete   %dil
or     $0x7e,%edi
mov    (%rbx),%rdx
lea    0xd7f(%rip),%rsi
call   1070 <err@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [1 x i8] zeroinitializer
@optind = global i64 0
@STDOUT_FILENO = global i32 0
@STDERR_FILENO = global i32 0
@.str.1 = [3 x i8] c"%s\00"
@SIGHUP = global i32 0
@SIG_IGN = global i32 0
@errno = global i64 0
@ENOENT = global i64 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
br label %7
7: ; preds = %12, %2
%8 = load i32, i32* %4
%9 = load i8**, i8*** %5
%10 = call i32 @getopt(i32 %8, i8** %9, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
%11 = icmp ne i32 %10, -1
br i1 %11, label %12, label %14
12: ; preds = %7
%13 = call i32 (...) @usage()
br label %7
14: ; preds = %7
%15 = load i64, i64* @optind
%16 = load i32, i32* %4
%17 = sext i32 %16 to i64
%18 = sub nsw i64 %17, %15
%19 = trunc i64 %18 to i32
store i32 %19, i32* %4
%20 = load i64, i64* @optind
%21 = load i8**, i8*** %5
%22 = getelementptr inbounds i8*, i8** %21, i64 %20
store i8** %22, i8*** %5
%23 = load i32, i32* %4
%24 = icmp slt i32 %23, 1
br i1 %24, label %25, label %27
25: ; preds = %14
%26 = call i32 (...) @usage()
br label %27
27: ; preds = %25, %14
%28 = load i32, i32* @STDOUT_FILENO
%29 = call i64 @isatty(i32 %28)
%30 = icmp ne i64 %29, 0
br i1 %30, label %31, label %33
31: ; preds = %27
%32 = call i32 (...) @dofile()
br label %33
33: ; preds = %31, %27
%34 = load i32, i32* @STDERR_FILENO
%35 = call i64 @isatty(i32 %34)
%36 = icmp ne i64 %35, 0
br i1 %36, label %37, label %47
37: ; preds = %33
%38 = load i32, i32* @STDOUT_FILENO
%39 = load i32, i32* @STDERR_FILENO
%40 = call i32 @dup2(i32 %38, i32 %39)
%41 = icmp eq i32 %40, -1
br i1 %41, label %42, label %47
42: ; preds = %37
%43 = load i8**, i8*** %5
%44 = getelementptr inbounds i8*, i8** %43, i64 0
%45 = load i8*, i8** %44
%46 = call i32 @err(i32 127, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %45)
br label %47
47: ; preds = %42, %37, %33
%48 = load i32, i32* @SIGHUP
%49 = load i32, i32* @SIG_IGN
%50 = call i32 @signal(i32 %48, i32 %49)
%51 = load i8**, i8*** %5
%52 = load i8*, i8** %51
%53 = load i8**, i8*** %5
%54 = call i32 @execvp(i8* %52, i8** %53)
%55 = load i64, i64* @errno
%56 = load i64, i64* @ENOENT
%57 = icmp eq i64 %55, %56
%58 = zext i1 %57 to i64
%59 = select i1 %57, i32 127, i32 126
store i32 %59, i32* %6
%60 = load i32, i32* %6
%61 = load i8**, i8*** %5
%62 = getelementptr inbounds i8*, i8** %61, i64 0
%63 = load i8*, i8** %62
%64 = call i32 @err(i32 %60, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %63)
%65 = load i32, i32* %3
ret i32 %65
}

LLVM IR (-O2):
@.str = [1 x i8] zeroinitializer
@optind = global i64 0
@STDOUT_FILENO = global i32 0
@STDERR_FILENO = global i32 0
@.str.1 = [3 x i8] c"%s\00"
@SIGHUP = global i32 0
@SIG_IGN = global i32 0
@errno = global i64 0
@ENOENT = global i64 0
define i32 @main(i32 %0, i8** %1) {
%3 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i32 %3, -1
br i1 %4, label %9, label %5
5: ; preds = %2, %5
%6 = tail call i32 (...) @usage()
%7 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
%8 = icmp eq i32 %7, -1
br i1 %8, label %9, label %5
9: ; preds = %5, %2
%10 = load i64, i64* @optind
%11 = trunc i64 %10 to i32
%12 = sub i32 %0, %11
%13 = getelementptr inbounds i8*, i8** %1, i64 %10
%14 = icmp slt i32 %12, 1
br i1 %14, label %15, label %17
15: ; preds = %9
%16 = tail call i32 (...) @usage()
br label %17
17: ; preds = %15, %9
%18 = load i32, i32* @STDOUT_FILENO
%19 = tail call i64 @isatty(i32 %18)
%20 = icmp eq i64 %19, 0
br i1 %20, label %23, label %21
21: ; preds = %17
%22 = tail call i32 (...) @dofile()
br label %23
23: ; preds = %21, %17
%24 = load i32, i32* @STDERR_FILENO
%25 = tail call i64 @isatty(i32 %24)
%26 = icmp eq i64 %25, 0
br i1 %26, label %35, label %27
27: ; preds = %23
%28 = load i32, i32* @STDOUT_FILENO
%29 = load i32, i32* @STDERR_FILENO
%30 = tail call i32 @dup2(i32 %28, i32 %29)
%31 = icmp eq i32 %30, -1
br i1 %31, label %32, label %35
32: ; preds = %27
%33 = load i8*, i8** %13
%34 = tail call i32 @err(i32 127, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %33)
br label %35
35: ; preds = %32, %27, %23
%36 = load i32, i32* @SIGHUP
%37 = load i32, i32* @SIG_IGN
%38 = tail call i32 @signal(i32 %36, i32 %37)
%39 = load i8*, i8** %13
%40 = tail call i32 @execvp(i8* %39, i8** %13)
%41 = load i64, i64* @errno
%42 = load i64, i64* @ENOENT
%43 = icmp eq i64 %41, %42
%44 = select i1 %43, i32 127, i32 126
%45 = load i8*, i8** %13
%46 = tail call i32 @err(i32 %44, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %45)
ret i32 0
}