#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 */
int emit(char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ freopen(char *, char *, int /*<<< orphan*/);
int getopt(int, char **, char *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ print_version(char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ stdout;
int /*<<< orphan*/ usage(char *);
int main(int argc, char *argv[]) {
  extern char *optarg;
  extern int optind;
  char *input = NULL;
  char *output = NULL;
  char *name = NULL;
  for (;;) {
    int c = getopt(argc, argv, "n:o:vh");
    if (c == -1)
      break;
    switch (c) {
    case 'n':
      name = optarg;
      break;
    case 'o':
      output = optarg;
      break;
    case 'v':
      print_version(argv[0]);
      return 0;
    case 'h':
      usage(argv[0]);
      return 0;
    default:
      usage(argv[0]);
      return 1;
    }
  }
  if (argc != optind + 1) {
    fprintf(stderr, "Bad arg count\n");
    usage(argv[0]);
    return 1;
  }
  input = argv[optind];
  if (!freopen(input, "rb", stdin)) {
    perror(input);
    return 1;
  }
  if (output && !freopen(output, "w", stdout)) {
    perror(output);
    return 1;
  }
  return emit(name ? name : input);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xe90(%rip),%rdx
call   1080 <getopt@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0xffffffff,-0x2c(%rbp)
jne    11c3 <main+0x53>
jmp    125f <main+0xef>
mov    -0x2c(%rbp),%eax
add    $0xffffff98,%eax
mov    %eax,%ecx
mov    %rcx,-0x38(%rbp)
sub    $0xe,%eax
ja     1242 <main+0xd2>
mov    -0x38(%rbp),%rax
lea    0xe1d(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    0x2de5(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x28(%rbp)
jmp    125a <main+0xea>
mov    0x2dd2(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x20(%rbp)
jmp    125a <main+0xea>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1030 <print_version@plt>
movl   $0x0,-0x4(%rbp)
jmp    135e <main+0x1ee>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1060 <usage@plt>
movl   $0x0,-0x4(%rbp)
jmp    135e <main+0x1ee>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1060 <usage@plt>
movl   $0x1,-0x4(%rbp)
jmp    135e <main+0x1ee>
jmp    119e <main+0x2e>
mov    -0x8(%rbp),%eax
mov    0x2d57(%rip),%rcx
mov    (%rcx),%ecx
add    $0x1,%ecx
cmp    %ecx,%eax
je     12a3 <main+0x133>
mov    0x2d53(%rip),%rax
mov    (%rax),%edi
lea    0xdbd(%rip),%rsi
call   1050 <fprintf@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1060 <usage@plt>
movl   $0x1,-0x4(%rbp)
jmp    135e <main+0x1ee>
mov    -0x10(%rbp),%rax
mov    0x2d12(%rip),%rcx
movslq (%rcx),%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    0x2d24(%rip),%rax
mov    (%rax),%edx
lea    0xd85(%rip),%rsi
call   1040 <freopen@plt>
cmp    $0x0,%eax
jne    12f0 <main+0x180>
mov    -0x18(%rbp),%rdi
call   1070 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    135e <main+0x1ee>
cmpq   $0x0,-0x20(%rbp)
je     1332 <main+0x1c2>
mov    -0x20(%rbp),%rdi
mov    0x2cc2(%rip),%rax
mov    (%rax),%edx
lea    0xd46(%rip),%rsi
call   1040 <freopen@plt>
cmp    $0x0,%eax
jne    1332 <main+0x1c2>
mov    -0x20(%rbp),%rdi
call   1070 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    135e <main+0x1ee>
cmpq   $0x0,-0x28(%rbp)
je     134a <main+0x1da>
mov    -0x28(%rbp),%rax
mov    %rax,-0x40(%rbp)
jmp    1352 <main+0x1e2>
mov    -0x18(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rdi
call   1090 <emit@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %edi,%ebp
xor    %r14d,%r14d
lea    0xe76(%rip),%r15
mov    0x2e47(%rip),%r13
xor    %r12d,%r12d
jmp    11a4 <main+0x34>
cs nopw 0x0(%rax,%rax,1)
mov    0x0(%r13),%r12
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r15,%rdx
call   1080 <getopt@plt>
cmp    $0x6e,%eax
je     11a0 <main+0x30>
jle    11c3 <main+0x53>
cmp    $0x6f,%eax
jne    11db <main+0x6b>
mov    0x0(%r13),%r14
jmp    11a4 <main+0x34>
cmp    $0xffffffff,%eax
je     11f3 <main+0x83>
cmp    $0x68,%eax
jne    1277 <main+0x107>
mov    (%rbx),%rdi
call   1060 <usage@plt>
jmp    11ec <main+0x7c>
cmp    $0x76,%eax
jne    1277 <main+0x107>
mov    (%rbx),%rdi
call   1030 <print_version@plt>
xor    %eax,%eax
jmp    1284 <main+0x114>
mov    0x2dc6(%rip),%rax
movslq (%rax),%rax
lea    0x1(%rax),%ecx
cmp    %ebp,%ecx
jne    1262 <main+0xf2>
mov    (%rbx,%rax,8),%rbx
mov    0x2dd9(%rip),%rax
mov    (%rax),%edx
lea    0xdfe(%rip),%rsi
mov    %rbx,%rdi
call   1040 <freopen@plt>
test   %eax,%eax
je     1293 <main+0x123>
test   %r14,%r14
je     1245 <main+0xd5>
mov    0x2d98(%rip),%rax
mov    (%rax),%edx
lea    0xde0(%rip),%rsi
mov    %r14,%rdi
call   1040 <freopen@plt>
test   %eax,%eax
je     1298 <main+0x128>
test   %r12,%r12
cmovne %r12,%rbx
mov    %rbx,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1090 <emit@plt>
mov    0x2d67(%rip),%rax
mov    (%rax),%edi
lea    0xd95(%rip),%rsi
call   1050 <fprintf@plt>
mov    (%rbx),%rdi
call   1060 <usage@plt>
mov    $0x1,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %rbx,%rdi
jmp    129b <main+0x12b>
mov    %r14,%rdi
call   1070 <perror@plt>
jmp    127f <main+0x10f>

LLVM IR (-O0):
@.str = [7 x i8] c"n:o:vh\00"
@optarg = external global i8*
@optind = external global i32
@stderr = global i32 0
@.str.1 = [15 x i8] c"Bad arg count\0A\00"
@.str.2 = [3 x i8] c"rb\00"
@stdin = global i32 0
@.str.3 = [2 x i8] c"w\00"
@stdout = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* null, i8** %6
store i8* null, i8** %7
store i8* null, i8** %8
br label %10
10: ; preds = %38, %2
%11 = load i32, i32* %4
%12 = load i8**, i8*** %5
%13 = call i32 @getopt(i32 %11, i8** %12, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
store i32 %13, i32* %9
%14 = load i32, i32* %9
%15 = icmp eq i32 %14, -1
br i1 %15, label %16, label %17
16: ; preds = %10
br label %39
17: ; preds = %10
%18 = load i32, i32* %9
switch i32 %18, label %33 [
i32 110, label %19
i32 111, label %21
i32 118, label %23
i32 104, label %28
]
19: ; preds = %17
%20 = load i8*, i8** @optarg
store i8* %20, i8** %8
br label %38
21: ; preds = %17
%22 = load i8*, i8** @optarg
store i8* %22, i8** %7
br label %38
23: ; preds = %17
%24 = load i8**, i8*** %5
%25 = getelementptr inbounds i8*, i8** %24, i64 0
%26 = load i8*, i8** %25
%27 = call i32 @print_version(i8* %26)
store i32 0, i32* %3
br label %85
28: ; preds = %17
%29 = load i8**, i8*** %5
%30 = getelementptr inbounds i8*, i8** %29, i64 0
%31 = load i8*, i8** %30
%32 = call i32 @usage(i8* %31)
store i32 0, i32* %3
br label %85
33: ; preds = %17
%34 = load i8**, i8*** %5
%35 = getelementptr inbounds i8*, i8** %34, i64 0
%36 = load i8*, i8** %35
%37 = call i32 @usage(i8* %36)
store i32 1, i32* %3
br label %85
38: ; preds = %21, %19
br label %10
39: ; preds = %16
%40 = load i32, i32* %4
%41 = load i32, i32* @optind
%42 = add nsw i32 %41, 1
%43 = icmp ne i32 %40, %42
br i1 %43, label %44, label %51
44: ; preds = %39
%45 = load i32, i32* @stderr
%46 = call i32 @fprintf(i32 %45, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
%47 = load i8**, i8*** %5
%48 = getelementptr inbounds i8*, i8** %47, i64 0
%49 = load i8*, i8** %48
%50 = call i32 @usage(i8* %49)
store i32 1, i32* %3
br label %85
51: ; preds = %39
%52 = load i8**, i8*** %5
%53 = load i32, i32* @optind
%54 = sext i32 %53 to i64
%55 = getelementptr inbounds i8*, i8** %52, i64 %54
%56 = load i8*, i8** %55
store i8* %56, i8** %6
%57 = load i8*, i8** %6
%58 = load i32, i32* @stdin
%59 = call i32 @freopen(i8* %57, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 %58)
%60 = icmp ne i32 %59, 0
br i1 %60, label %64, label %61
61: ; preds = %51
%62 = load i8*, i8** %6
%63 = call i32 @perror(i8* %62)
store i32 1, i32* %3
br label %85
64: ; preds = %51
%65 = load i8*, i8** %7
%66 = icmp ne i8* %65, null
br i1 %66, label %67, label %75
67: ; preds = %64
%68 = load i8*, i8** %7
%69 = load i32, i32* @stdout
%70 = call i32 @freopen(i8* %68, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0), i32 %69)
%71 = icmp ne i32 %70, 0
br i1 %71, label %75, label %72
72: ; preds = %67
%73 = load i8*, i8** %7
%74 = call i32 @perror(i8* %73)
store i32 1, i32* %3
br label %85
75: ; preds = %67, %64
%76 = load i8*, i8** %8
%77 = icmp ne i8* %76, null
br i1 %77, label %78, label %80
78: ; preds = %75
%79 = load i8*, i8** %8
br label %82
80: ; preds = %75
%81 = load i8*, i8** %6
br label %82
82: ; preds = %80, %78
%83 = phi i8* [ %79, %78 ], [ %81, %80 ]
%84 = call i32 @emit(i8* %83)
store i32 %84, i32* %3
br label %85
85: ; preds = %82, %72, %61, %44, %33, %28, %23
%86 = load i32, i32* %3
ret i32 %86
}

LLVM IR (-O2):
@.str = [7 x i8] c"n:o:vh\00"
@optarg = external global i8*
@optind = external global i32
@stderr = global i32 0
@.str.1 = [15 x i8] c"Bad arg count\0A\00"
@.str.2 = [3 x i8] c"rb\00"
@stdin = global i32 0
@.str.3 = [2 x i8] c"w\00"
@stdout = global i32 0
define i32 @main(i32 %0, i8** %1) {
br label %3
3: ; preds = %11, %2
%4 = phi i8* [ %12, %11 ], [ null, %2 ]
%5 = phi i8* [ %7, %11 ], [ null, %2 ]
br label %6
6: ; preds = %3, %9
%7 = phi i8* [ %10, %9 ], [ %5, %3 ]
%8 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
switch i32 %8, label %19 [
i32 -1, label %22
i32 110, label %9
i32 111, label %11
i32 118, label %13
i32 104, label %16
]
9: ; preds = %6
%10 = load i8*, i8** @optarg
br label %6
11: ; preds = %6
%12 = load i8*, i8** @optarg
br label %3
13: ; preds = %6
%14 = load i8*, i8** %1
%15 = tail call i32 @print_version(i8* %14)
br label %52
16: ; preds = %6
%17 = load i8*, i8** %1
%18 = tail call i32 @usage(i8* %17)
br label %52
19: ; preds = %6
%20 = load i8*, i8** %1
%21 = tail call i32 @usage(i8* %20)
br label %52
22: ; preds = %6
%23 = load i32, i32* @optind
%24 = add nsw i32 %23, 1
%25 = icmp eq i32 %24, %0
br i1 %25, label %31, label %26
26: ; preds = %22
%27 = load i32, i32* @stderr
%28 = tail call i32 @fprintf(i32 %27, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
%29 = load i8*, i8** %1
%30 = tail call i32 @usage(i8* %29)
br label %52
31: ; preds = %22
%32 = sext i32 %23 to i64
%33 = getelementptr inbounds i8*, i8** %1, i64 %32
%34 = load i8*, i8** %33
%35 = load i32, i32* @stdin
%36 = tail call i32 @freopen(i8* %34, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 %35)
%37 = icmp eq i32 %36, 0
br i1 %37, label %38, label %40
38: ; preds = %31
%39 = tail call i32 @perror(i8* %34)
br label %52
40: ; preds = %31
%41 = icmp eq i8* %4, null
br i1 %41, label %48, label %42
42: ; preds = %40
%43 = load i32, i32* @stdout
%44 = tail call i32 @freopen(i8* %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0), i32 %43)
%45 = icmp eq i32 %44, 0
br i1 %45, label %46, label %48
46: ; preds = %42
%47 = tail call i32 @perror(i8* %4)
br label %52
48: ; preds = %42, %40
%49 = icmp eq i8* %7, null
%50 = select i1 %49, i8* %34, i8* %7
%51 = tail call i32 @emit(i8* %50)
br label %52
52: ; preds = %13, %16, %19, %48, %46, %38, %26
%53 = phi i32 [ 1, %26 ], [ %51, %48 ], [ 1, %46 ], [ 1, %38 ], [ 0, %13 ], [ 0, %16 ], [ 1, %19 ]
ret i32 %53
}