#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 */
#define EOF 128
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ freopen(char *, char *, int /*<<< orphan*/);
int getc(int /*<<< orphan*/);
int getopt(int, char **, char *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ putc(int, int /*<<< orphan*/);
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 *output = 0;
  for (;;) {
    int c = getopt(argc, argv, "o:h");
    if (c == -1)
      break;
    switch (c) {
    case 'o':
      output = optarg;
      break;
    case 'h':
      usage(argv[0]);
      return 0;
    default:
      usage(argv[0]);
      return 1;
    }
  }
  switch (argc - optind) {
  case 0:
    break;
  case 1:
    if (!freopen(argv[optind], "r", stdin)) {
      perror(argv[optind]);
      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;
  }
  for (;;) {
    int c = getc(stdin);
    switch (c) {
    case EOF:
      return 0;
    case '\r':
      continue;
    case '\n':
      putc('\r', stdout);
    default:
      putc(c, stdout);
    }
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xe64(%rip),%rdx
call   1080 <getopt@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0xffffffff,-0x1c(%rbp)
jne    11b3 <main+0x43>
jmp    1220 <main+0xb0>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x24(%rbp)
sub    $0x68,%eax
je     11eb <main+0x7b>
jmp    11c7 <main+0x57>
mov    -0x24(%rbp),%eax
sub    $0x6f,%eax
jne    1203 <main+0x93>
jmp    11d8 <main+0x68>
mov    0x2df9(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x18(%rbp)
jmp    121b <main+0xab>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1060 <usage@plt>
movl   $0x0,-0x4(%rbp)
jmp    13a1 <main+0x231>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1060 <usage@plt>
movl   $0x1,-0x4(%rbp)
jmp    13a1 <main+0x231>
jmp    118e <main+0x1e>
mov    -0x8(%rbp),%eax
mov    0x2d96(%rip),%rcx
mov    (%rcx),%ecx
sub    %ecx,%eax
mov    %eax,-0x28(%rbp)
je     124d <main+0xdd>
jmp    123c <main+0xcc>
mov    -0x28(%rbp),%eax
sub    $0x1,%eax
je     1252 <main+0xe2>
jmp    12aa <main+0x13a>
jmp    12d7 <main+0x167>
mov    -0x10(%rbp),%rax
mov    0x2d63(%rip),%rcx
movslq (%rcx),%rcx
mov    (%rax,%rcx,8),%rdi
mov    0x2d7d(%rip),%rax
mov    (%rax),%edx
lea    0xd90(%rip),%rsi
call   1030 <freopen@plt>
cmp    $0x0,%eax
jne    12a5 <main+0x135>
mov    -0x10(%rbp),%rax
mov    0x2d33(%rip),%rcx
movslq (%rcx),%rcx
mov    (%rax,%rcx,8),%rdi
call   1070 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    13a1 <main+0x231>
jmp    12d7 <main+0x167>
mov    0x2d1f(%rip),%rax
mov    (%rax),%edi
lea    0xd4c(%rip),%rsi
call   1050 <fprintf@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1060 <usage@plt>
movl   $0x1,-0x4(%rbp)
jmp    13a1 <main+0x231>
cmpq   $0x0,-0x18(%rbp)
je     1319 <main+0x1a9>
mov    -0x18(%rbp),%rdi
mov    0x2cdb(%rip),%rax
mov    (%rax),%edx
lea    0xd1f(%rip),%rsi
call   1030 <freopen@plt>
cmp    $0x0,%eax
jne    1319 <main+0x1a9>
mov    -0x18(%rbp),%rdi
call   1070 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    13a1 <main+0x231>
jmp    131e <main+0x1ae>
mov    0x2cc3(%rip),%rax
mov    (%rax),%edi
call   1090 <getc@plt>
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%eax
mov    %eax,-0x2c(%rbp)
sub    $0xa,%eax
je     1378 <main+0x208>
jmp    1343 <main+0x1d3>
mov    -0x2c(%rbp),%eax
sub    $0xd,%eax
je     1373 <main+0x203>
jmp    1354 <main+0x1e4>
mov    -0x2c(%rbp),%eax
sub    $0x80,%eax
jne    138b <main+0x21b>
jmp    1367 <main+0x1f7>
movl   $0x0,-0x4(%rbp)
jmp    13a1 <main+0x231>
jmp    131e <main+0x1ae>
mov    0x2c49(%rip),%rax
mov    (%rax),%esi
mov    $0xd,%edi
call   1040 <putc@plt>
mov    -0x20(%rbp),%edi
mov    0x2c33(%rip),%rax
mov    (%rax),%esi
call   1040 <putc@plt>
jmp    131e <main+0x1ae>
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rsi,%r15
mov    %edi,%ebp
xor    %r14d,%r14d
lea    0xe79(%rip),%rbx
mov    0x2e4a(%rip),%r12
xchg   %ax,%ax
mov    %ebp,%edi
mov    %r15,%rsi
mov    %rbx,%rdx
call   1080 <getopt@plt>
cmp    $0x6f,%eax
jne    11a8 <main+0x38>
mov    (%r12),%r14
jmp    1190 <main+0x20>
cmp    $0xffffffff,%eax
je     11c3 <main+0x53>
cmp    $0x68,%eax
jne    128e <main+0x11e>
mov    (%r15),%rdi
call   1060 <usage@plt>
jmp    1275 <main+0x105>
mov    0x2df6(%rip),%rbx
movslq (%rbx),%rax
sub    %eax,%ebp
je     11fb <main+0x8b>
cmp    $0x1,%ebp
jne    1279 <main+0x109>
mov    (%r15,%rax,8),%rdi
mov    0x2e03(%rip),%rax
mov    (%rax),%edx
lea    0xe16(%rip),%rsi
call   1030 <freopen@plt>
test   %eax,%eax
je     12a4 <main+0x134>
test   %r14,%r14
je     1253 <main+0xe3>
mov    0x2dc1(%rip),%rax
mov    (%rax),%edx
lea    0xe05(%rip),%rsi
mov    %r14,%rdi
call   1030 <freopen@plt>
test   %eax,%eax
jne    1253 <main+0xe3>
mov    %r14,%rdi
jmp    12ab <main+0x13b>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    0x2d91(%rip),%rax
mov    (%rax),%esi
mov    $0xd,%edi
call   1040 <putc@plt>
mov    0x2d7e(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edi
call   1040 <putc@plt>
mov    0x2d8e(%rip),%rax
mov    (%rax),%edi
call   1090 <getc@plt>
mov    %eax,%ebx
cmp    $0xa,%eax
je     1230 <main+0xc0>
cmp    $0xd,%ebx
je     1253 <main+0xe3>
cmp    $0x80,%ebx
jne    1243 <main+0xd3>
xor    %eax,%eax
jmp    129b <main+0x12b>
mov    0x2d50(%rip),%rax
mov    (%rax),%edi
lea    0xd7d(%rip),%rsi
call   1050 <fprintf@plt>
mov    (%r15),%rdi
call   1060 <usage@plt>
mov    $0x1,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
movslq (%rbx),%rax
mov    (%r15,%rax,8),%rdi
call   1070 <perror@plt>
jmp    1296 <main+0x126>

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

LLVM IR (-O2):
@.str = [4 x i8] c"o:h\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 = %12, %2
%4 = phi i8* [ null, %2 ], [ %13, %12 ]
%5 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
switch i32 %5, label %9 [
i32 -1, label %14
i32 111, label %12
i32 104, label %6
]
6: ; preds = %3
%7 = load i8*, i8** %1
%8 = tail call i32 @usage(i8* %7)
br label %54
9: ; preds = %3
%10 = load i8*, i8** %1
%11 = tail call i32 @usage(i8* %10)
br label %54
12: ; preds = %3
%13 = load i8*, i8** @optarg
br label %3
14: ; preds = %3
%15 = load i32, i32* @optind
%16 = sub nsw i32 %0, %15
switch i32 %16, label %30 [
i32 0, label %35
i32 1, label %17
]
17: ; preds = %14
%18 = sext i32 %15 to i64
%19 = getelementptr inbounds i8*, i8** %1, i64 %18
%20 = load i8*, i8** %19
%21 = load i32, i32* @stdin
%22 = tail call i32 @freopen(i8* %20, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i32 %21)
%23 = icmp eq i32 %22, 0
br i1 %23, label %24, label %35
24: ; preds = %17
%25 = load i32, i32* @optind
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds i8*, i8** %1, i64 %26
%28 = load i8*, i8** %27
%29 = tail call i32 @perror(i8* %28)
br label %54
30: ; preds = %14
%31 = load i32, i32* @stderr
%32 = tail call i32 @fprintf(i32 %31, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
%33 = load i8*, i8** %1
%34 = tail call i32 @usage(i8* %33)
br label %54
35: ; preds = %17, %14
%36 = icmp eq i8* %4, null
br i1 %36, label %37, label %38
37: ; preds = %38, %35
br label %44
38: ; preds = %35
%39 = load i32, i32* @stdout
%40 = tail call i32 @freopen(i8* %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0), i32 %39)
%41 = icmp eq i32 %40, 0
br i1 %41, label %42, label %37
42: ; preds = %38
%43 = tail call i32 @perror(i8* %4)
br label %54
44: ; preds = %47, %37
%45 = load i32, i32* @stdin
%46 = tail call i32 @getc(i32 %45)
switch i32 %46, label %51 [
i32 128, label %54
i32 13, label %47
i32 10, label %48
]
47: ; preds = %44, %51
br label %44
48: ; preds = %44
%49 = load i32, i32* @stdout
%50 = tail call i32 @putc(i32 13, i32 %49)
br label %51
51: ; preds = %44, %48
%52 = load i32, i32* @stdout
%53 = tail call i32 @putc(i32 %46, i32 %52)
br label %47
54: ; preds = %44, %6, %9, %42, %30, %24
%55 = phi i32 [ 1, %30 ], [ 1, %42 ], [ 1, %24 ], [ 0, %6 ], [ 1, %9 ], [ 0, %44 ]
ret i32 %55
}