#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 /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ freopen(char *, char *, int /*<<< orphan*/);
int getopt(int, char **, char *);
int go(int, 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;
  int debug = 0;
  for (;;) {
    int c = getopt(argc, argv, "o:dvh");
    if (c == -1)
      break;
    switch (c) {
    case 'o':
      output = optarg;
      break;
    case 'd':
      debug = 1;
      break;
    case 'v':
      print_version(argv[0]);
      return 0;
    case 'h':
      usage(argv[0]);
      return 0;
    default:
      usage(argv[0]);
      return 1;
    }
  }
  switch (argc - optind) {
  case 0:
    break;
  case 1:
    input = argv[optind];
    if (!freopen(input, "r", stdin)) {
      perror(input);
      return 1;
    }
    break;
  default:
    fprintf(stderr, "Bad arg count\n");
    usage(argv[0]);
    return 1;
  }
  if (output && !freopen(output, "w", stdout)) {
    perror(output);
    return 1;
  }
  return go(debug, 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)
movl   $0x0,-0x24(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xea1(%rip),%rdx
call   1090 <getopt@plt>
mov    %eax,-0x28(%rbp)
cmpl   $0xffffffff,-0x28(%rbp)
jne    11c2 <main+0x52>
jmp    1257 <main+0xe7>
mov    -0x28(%rbp),%eax
add    $0xffffff9c,%eax
mov    %eax,%ecx
mov    %rcx,-0x30(%rbp)
sub    $0x12,%eax
ja     123a <main+0xca>
mov    -0x30(%rbp),%rax
lea    0xe1e(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    0x2de6(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x20(%rbp)
jmp    1252 <main+0xe2>
movl   $0x1,-0x24(%rbp)
jmp    1252 <main+0xe2>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1030 <print_version@plt>
movl   $0x0,-0x4(%rbp)
jmp    1359 <main+0x1e9>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1070 <usage@plt>
movl   $0x0,-0x4(%rbp)
jmp    1359 <main+0x1e9>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1070 <usage@plt>
movl   $0x1,-0x4(%rbp)
jmp    1359 <main+0x1e9>
jmp    119d <main+0x2d>
mov    -0x8(%rbp),%eax
mov    0x2d5f(%rip),%rcx
mov    (%rcx),%ecx
sub    %ecx,%eax
mov    %eax,-0x34(%rbp)
je     1284 <main+0x114>
jmp    1273 <main+0x103>
mov    -0x34(%rbp),%eax
sub    $0x1,%eax
je     1289 <main+0x119>
jmp    12db <main+0x16b>
jmp    1308 <main+0x198>
mov    -0x10(%rbp),%rax
mov    0x2d2c(%rip),%rcx
movslq (%rcx),%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    0x2d3e(%rip),%rax
mov    (%rax),%edx
lea    0xd9f(%rip),%rsi
call   1050 <freopen@plt>
cmp    $0x0,%eax
jne    12d6 <main+0x166>
mov    -0x18(%rbp),%rdi
call   1080 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    1359 <main+0x1e9>
jmp    1308 <main+0x198>
mov    0x2cee(%rip),%rax
mov    (%rax),%edi
lea    0xd69(%rip),%rsi
call   1060 <fprintf@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1070 <usage@plt>
movl   $0x1,-0x4(%rbp)
jmp    1359 <main+0x1e9>
cmpq   $0x0,-0x20(%rbp)
je     134a <main+0x1da>
mov    -0x20(%rbp),%rdi
mov    0x2caa(%rip),%rax
mov    (%rax),%edx
lea    0xd3c(%rip),%rsi
call   1050 <freopen@plt>
cmp    $0x0,%eax
jne    134a <main+0x1da>
mov    -0x20(%rbp),%rdi
call   1080 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    1359 <main+0x1e9>
mov    -0x24(%rbp),%edi
mov    -0x18(%rbp),%rsi
call   1040 <go@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,%r15
mov    %edi,%ebp
xor    %r14d,%r14d
lea    0xe76(%rip),%r12
mov    0x2e47(%rip),%r13
xor    %ebx,%ebx
mov    %ebx,%ecx
cs nopw 0x0(%rax,%rax,1)
nop
mov    %ecx,%ebx
mov    %ebp,%edi
mov    %r15,%rsi
mov    %r12,%rdx
call   1090 <getopt@plt>
mov    $0x1,%ecx
cmp    $0x64,%eax
je     11a0 <main+0x30>
cmp    $0x6e,%eax
jle    11d2 <main+0x62>
cmp    $0x76,%eax
je     11ea <main+0x7a>
cmp    $0x6f,%eax
jne    1283 <main+0x113>
mov    0x0(%r13),%r14
jmp    1193 <main+0x23>
cmp    $0xffffffff,%eax
je     11f9 <main+0x89>
cmp    $0x68,%eax
jne    1283 <main+0x113>
mov    (%r15),%rdi
call   1070 <usage@plt>
jmp    11f2 <main+0x82>
mov    (%r15),%rdi
call   1030 <print_version@plt>
xor    %eax,%eax
jmp    1290 <main+0x120>
mov    0x2dc0(%rip),%rax
movslq (%rax),%rax
sub    %eax,%ebp
je     1233 <main+0xc3>
cmp    $0x1,%ebp
jne    126e <main+0xfe>
mov    (%r15,%rax,8),%rbp
mov    0x2dd1(%rip),%rax
mov    (%rax),%edx
lea    0xde6(%rip),%rsi
mov    %rbp,%rdi
call   1050 <freopen@plt>
test   %eax,%eax
je     12a4 <main+0x134>
test   %r14,%r14
jne    123a <main+0xca>
jmp    1256 <main+0xe6>
xor    %ebp,%ebp
test   %r14,%r14
je     1256 <main+0xe6>
mov    0x2d87(%rip),%rax
mov    (%rax),%edx
lea    0xdcd(%rip),%rsi
mov    %r14,%rdi
call   1050 <freopen@plt>
test   %eax,%eax
je     129f <main+0x12f>
mov    %ebx,%edi
mov    %rbp,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <go@plt>
mov    0x2d5b(%rip),%rax
mov    (%rax),%edi
lea    0xd8a(%rip),%rsi
call   1060 <fprintf@plt>
mov    (%r15),%rdi
call   1070 <usage@plt>
mov    $0x1,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %r14,%rdi
jmp    12a7 <main+0x137>
mov    %rbp,%rdi
call   1080 <perror@plt>
jmp    128b <main+0x11b>

LLVM IR (-O0):
@.str = [6 x i8] c"o:dvh\00"
@optarg = external global i8*
@optind = external global i32
@.str.1 = [2 x i8] c"r\00"
@stdin = global i32 0
@stderr = global i32 0
@.str.2 = [15 x i8] c"Bad arg count\0A\00"
@.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 i32
%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 i32 0, i32* %8
br label %10
10: ; preds = %37, %2
%11 = load i32, i32* %4
%12 = load i8**, i8*** %5
%13 = call i32 @getopt(i32 %11, i8** %12, i8* getelementptr inbounds ([6 x i8], [6 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 %38
17: ; preds = %10
%18 = load i32, i32* %9
switch i32 %18, label %32 [
i32 111, label %19
i32 100, label %21
i32 118, label %22
i32 104, label %27
]
19: ; preds = %17
%20 = load i8*, i8** @optarg
store i8* %20, i8** %7
br label %37
21: ; preds = %17
store i32 1, i32* %8
br label %37
22: ; preds = %17
%23 = load i8**, i8*** %5
%24 = getelementptr inbounds i8*, i8** %23, i64 0
%25 = load i8*, i8** %24
%26 = call i32 @print_version(i8* %25)
store i32 0, i32* %3
br label %79
27: ; preds = %17
%28 = load i8**, i8*** %5
%29 = getelementptr inbounds i8*, i8** %28, i64 0
%30 = load i8*, i8** %29
%31 = call i32 @usage(i8* %30)
store i32 0, i32* %3
br label %79
32: ; preds = %17
%33 = load i8**, i8*** %5
%34 = getelementptr inbounds i8*, i8** %33, i64 0
%35 = load i8*, i8** %34
%36 = call i32 @usage(i8* %35)
store i32 1, i32* %3
br label %79
37: ; preds = %21, %19
br label %10
38: ; preds = %16
%39 = load i32, i32* %4
%40 = load i32, i32* @optind
%41 = sub nsw i32 %39, %40
switch i32 %41, label %57 [
i32 0, label %42
i32 1, label %43
]
42: ; preds = %38
br label %64
43: ; preds = %38
%44 = load i8**, i8*** %5
%45 = load i32, i32* @optind
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds i8*, i8** %44, i64 %46
%48 = load i8*, i8** %47
store i8* %48, i8** %6
%49 = load i8*, i8** %6
%50 = load i32, i32* @stdin
%51 = call i32 @freopen(i8* %49, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i32 %50)
%52 = icmp ne i32 %51, 0
br i1 %52, label %56, label %53
53: ; preds = %43
%54 = load i8*, i8** %6
%55 = call i32 @perror(i8* %54)
store i32 1, i32* %3
br label %79
56: ; preds = %43
br label %64
57: ; preds = %38
%58 = load i32, i32* @stderr
%59 = call i32 @fprintf(i32 %58, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
%60 = load i8**, i8*** %5
%61 = getelementptr inbounds i8*, i8** %60, i64 0
%62 = load i8*, i8** %61
%63 = call i32 @usage(i8* %62)
store i32 1, i32* %3
br label %79
64: ; preds = %56, %42
%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 %79
75: ; preds = %67, %64
%76 = load i32, i32* %8
%77 = load i8*, i8** %6
%78 = call i32 @go(i32 %76, i8* %77)
store i32 %78, i32* %3
br label %79
79: ; preds = %75, %72, %57, %53, %32, %27, %22
%80 = load i32, i32* %3
ret i32 %80
}

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