#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 */
typedef int /*<<< orphan*/ buffer;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int EOF;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int fputs(char *, int /*<<< orphan*/ *);
int getopt(int, char **, char *);
char *optarg;
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ *stdin;
int /*<<< orphan*/ *stdout;
int main(int argc, char **argv) {
  int i, cnt;
  char *infile = NULL;
  char *outfile = NULL;
  FILE *in, *out;
  char buffer[1024];
  while ((i = getopt(argc, argv, "i:o:?")) != EOF) {
    switch (i) {
    case 'i':
      infile = optarg;
      break;
    case 'o':
      outfile = optarg;
      break;
    case '?':
      printf("%s [-i inputfile -o outfile]\n", argv[0]);
      return (0);
    };
  };
  if (infile == NULL) {
    in = stdin;
  } else {
    in = fopen(infile, "r");
    if (in == NULL) {
      printf("Can't open %s\n", infile);
      return (-1);
    }
  }
  if (outfile == NULL) {
    out = stdout;
  } else {
    out = fopen(outfile, "w+");
    if (in == NULL) {
      printf("Can't open %s\n", outfile);
      return (-1);
    }
  }
  cnt = 0;
  while (fgets(buffer, sizeof(buffer), in) != NULL) {
    cnt++;
    if (buffer[0] == '\n')
      continue;
    if (fputs(buffer, out) == EOF) {
      printf("Write error at line:%d\n", cnt);
      return (-1);
    }
  }
  if (infile) {
    fclose(in);
  }
  if (outfile) {
    fclose(out);
  }
  return (0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x450,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xe69(%rip),%rdx
call   1080 <getopt@plt>
mov    %eax,-0x14(%rbp)
mov    0x2e32(%rip),%rcx
cmp    (%rcx),%eax
je     1239 <main+0xd9>
mov    -0x14(%rbp),%eax
mov    %eax,-0x444(%rbp)
sub    $0x3f,%eax
je     1213 <main+0xb3>
jmp    11c5 <main+0x65>
mov    -0x444(%rbp),%eax
sub    $0x69,%eax
je     11ed <main+0x8d>
jmp    11d9 <main+0x79>
mov    -0x444(%rbp),%eax
sub    $0x6f,%eax
je     1200 <main+0xa0>
jmp    1234 <main+0xd4>
mov    0x2e04(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x20(%rbp)
jmp    1234 <main+0xd4>
mov    0x2df1(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x28(%rbp)
jmp    1234 <main+0xd4>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xde5(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    13ad <main+0x24d>
jmp    1189 <main+0x29>
cmpq   $0x0,-0x20(%rbp)
jne    1257 <main+0xf7>
mov    0x2d95(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x30(%rbp)
jmp    1299 <main+0x139>
mov    -0x20(%rbp),%rdi
lea    0xdc2(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    1294 <main+0x134>
mov    -0x20(%rbp),%rsi
lea    0xda5(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    13ad <main+0x24d>
jmp    1299 <main+0x139>
cmpq   $0x0,-0x28(%rbp)
jne    12b7 <main+0x157>
mov    0x2d1d(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x38(%rbp)
jmp    12f9 <main+0x199>
mov    -0x28(%rbp),%rdi
lea    0xd73(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    12f4 <main+0x194>
mov    -0x28(%rbp),%rsi
lea    0xd45(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    13ad <main+0x24d>
jmp    12f9 <main+0x199>
movl   $0x0,-0x18(%rbp)
lea    -0x440(%rbp),%rdi
mov    -0x30(%rbp),%rdx
mov    $0x400,%esi
call   1060 <fgets@plt>
cmp    $0x0,%rax
je     137e <main+0x21e>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
movsbl -0x440(%rbp),%eax
cmp    $0xa,%eax
jne    133d <main+0x1dd>
jmp    1300 <main+0x1a0>
lea    -0x440(%rbp),%rdi
mov    -0x38(%rbp),%rsi
call   1050 <fputs@plt>
mov    0x2c84(%rip),%rcx
cmp    (%rcx),%eax
jne    1379 <main+0x219>
mov    -0x18(%rbp),%esi
lea    0xcd2(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    13ad <main+0x24d>
jmp    1300 <main+0x1a0>
cmpq   $0x0,-0x20(%rbp)
je     1392 <main+0x232>
mov    -0x30(%rbp),%rdi
call   1030 <fclose@plt>
cmpq   $0x0,-0x28(%rbp)
je     13a6 <main+0x246>
mov    -0x38(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x450,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x408,%rsp
mov    %rsi,%rbx
mov    %edi,%ebp
lea    0xe83(%rip),%rdx
call   1080 <getopt@plt>
mov    0x2e4f(%rip),%rcx
cmp    (%rcx),%eax
jne    1195 <main+0x35>
xor    %r14d,%r14d
jmp    121f <main+0xbf>
xor    %r13d,%r13d
mov    0x2e59(%rip),%r14
lea    0xe5a(%rip),%r12
xor    %r15d,%r15d
jmp    11cb <main+0x6b>
nopl   0x0(%rax,%rax,1)
mov    (%r14),%r15
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r12,%rdx
call   1080 <getopt@plt>
mov    0x2e11(%rip),%rcx
cmp    (%rcx),%eax
je     11e5 <main+0x85>
cmp    $0x69,%eax
je     11b0 <main+0x50>
cmp    $0x6f,%eax
je     11e0 <main+0x80>
cmp    $0x3f,%eax
jne    11b3 <main+0x53>
jmp    12e0 <main+0x180>
nop
mov    (%r14),%r13
jmp    11b3 <main+0x53>
test   %r15,%r15
je     121c <main+0xbc>
lea    0xe33(%rip),%rsi
mov    %r15,%rdi
call   1070 <fopen@plt>
test   %rax,%rax
je     12f5 <main+0x195>
mov    %rax,%r12
mov    %r13,%r14
xor    %r13d,%r13d
test   %r14,%r14
jne    1231 <main+0xd1>
mov    0x2db1(%rip),%rax
mov    (%rax),%r15
jmp    124c <main+0xec>
mov    %r13,%r14
mov    0x2dba(%rip),%rax
mov    (%rax),%r12
mov    $0x1,%r13b
test   %r14,%r14
je     1210 <main+0xb0>
lea    0xdfd(%rip),%rsi
mov    %r14,%rdi
call   1070 <fopen@plt>
test   %r12,%r12
je     12d4 <main+0x174>
mov    %rax,%r15
mov    %rsp,%rdi
mov    $0x400,%esi
mov    %r12,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
je     12b6 <main+0x156>
mov    $0x1,%ebp
mov    %rsp,%rbx
jmp    1288 <main+0x128>
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    $0x400,%esi
mov    %r12,%rdx
call   1060 <fgets@plt>
add    $0x1,%ebp
test   %rax,%rax
je     12b6 <main+0x156>
cmpb   $0xa,(%rsp)
je     1270 <main+0x110>
mov    %rbx,%rdi
mov    %r15,%rsi
call   1050 <fputs@plt>
mov    0x2d38(%rip),%rcx
cmp    (%rcx),%eax
jne    1270 <main+0x110>
lea    0xd8d(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    1306 <main+0x1a6>
test   %r13b,%r13b
jne    12c3 <main+0x163>
mov    %r12,%rdi
call   1030 <fclose@plt>
xor    %ebx,%ebx
test   %r14,%r14
je     130b <main+0x1ab>
mov    %r15,%rdi
call   1030 <fclose@plt>
jmp    130b <main+0x1ab>
lea    0xd4b(%rip),%rdi
mov    %r14,%rsi
jmp    12ff <main+0x19f>
mov    (%rbx),%rsi
lea    0xd1c(%rip),%rdi
xor    %ebx,%ebx
xor    %eax,%eax
call   1040 <printf@plt>
jmp    130b <main+0x1ab>
lea    0xd2a(%rip),%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
add    $0x408,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [6 x i8] c"i:o:?\00"
@EOF = global i32 0
@optarg = global i8* null
@.str.1 = [30 x i8] c"%s [-i inputfile -o outfile]\0A\00"
@stdin = global i32* null
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [15 x i8] c"Can't open %s\0A\00"
@stdout = global i32* null
@.str.4 = [3 x i8] c"w+\00"
@.str.5 = [24 x i8] c"Write error at line:%d\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i32*
%11 = alloca i32*
%12 = alloca [1024 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* null, i8** %8
store i8* null, i8** %9
br label %13
13: ; preds = %30, %2
%14 = load i32, i32* %4
%15 = load i8**, i8*** %5
%16 = call i32 @getopt(i32 %14, i8** %15, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
store i32 %16, i32* %6
%17 = load i32, i32* @EOF
%18 = icmp ne i32 %16, %17
br i1 %18, label %19, label %31
19: ; preds = %13
%20 = load i32, i32* %6
switch i32 %20, label %30 [
i32 105, label %21
i32 111, label %23
i32 63, label %25
]
21: ; preds = %19
%22 = load i8*, i8** @optarg
store i8* %22, i8** %8
br label %30
23: ; preds = %19
%24 = load i8*, i8** @optarg
store i8* %24, i8** %9
br label %30
25: ; preds = %19
%26 = load i8**, i8*** %5
%27 = getelementptr inbounds i8*, i8** %26, i64 0
%28 = load i8*, i8** %27
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i8* %28)
store i32 0, i32* %3
br label %96
30: ; preds = %19, %23, %21
br label %13
31: ; preds = %13
%32 = load i8*, i8** %8
%33 = icmp eq i8* %32, null
br i1 %33, label %34, label %36
34: ; preds = %31
%35 = load i32*, i32** @stdin
store i32* %35, i32** %10
br label %45
36: ; preds = %31
%37 = load i8*, i8** %8
%38 = call i32* @fopen(i8* %37, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %38, i32** %10
%39 = load i32*, i32** %10
%40 = icmp eq i32* %39, null
br i1 %40, label %41, label %44
41: ; preds = %36
%42 = load i8*, i8** %8
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i8* %42)
store i32 -1, i32* %3
br label %96
44: ; preds = %36
br label %45
45: ; preds = %44, %34
%46 = load i8*, i8** %9
%47 = icmp eq i8* %46, null
br i1 %47, label %48, label %50
48: ; preds = %45
%49 = load i32*, i32** @stdout
store i32* %49, i32** %11
br label %59
50: ; preds = %45
%51 = load i8*, i8** %9
%52 = call i32* @fopen(i8* %51, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
store i32* %52, i32** %11
%53 = load i32*, i32** %10
%54 = icmp eq i32* %53, null
br i1 %54, label %55, label %58
55: ; preds = %50
%56 = load i8*, i8** %9
%57 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i8* %56)
store i32 -1, i32* %3
br label %96
58: ; preds = %50
br label %59
59: ; preds = %58, %48
store i32 0, i32* %7
br label %60
60: ; preds = %82, %72, %59
%61 = getelementptr inbounds [1024 x i8], [1024 x i8]* %12, i64 0, i64 0
%62 = load i32*, i32** %10
%63 = call i32* @fgets(i8* %61, i32 1024, i32* %62)
%64 = icmp ne i32* %63, null
br i1 %64, label %65, label %83
65: ; preds = %60
%66 = load i32, i32* %7
%67 = add nsw i32 %66, 1
store i32 %67, i32* %7
%68 = getelementptr inbounds [1024 x i8], [1024 x i8]* %12, i64 0, i64 0
%69 = load i8, i8* %68
%70 = sext i8 %69 to i32
%71 = icmp eq i32 %70, 10
br i1 %71, label %72, label %73
72: ; preds = %65
br label %60
73: ; preds = %65
%74 = getelementptr inbounds [1024 x i8], [1024 x i8]* %12, i64 0, i64 0
%75 = load i32*, i32** %11
%76 = call i32 @fputs(i8* %74, i32* %75)
%77 = load i32, i32* @EOF
%78 = icmp eq i32 %76, %77
br i1 %78, label %79, label %82
79: ; preds = %73
%80 = load i32, i32* %7
%81 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.5, i64 0, i64 0), i32 %80)
store i32 -1, i32* %3
br label %96
82: ; preds = %73
br label %60
83: ; preds = %60
%84 = load i8*, i8** %8
%85 = icmp ne i8* %84, null
br i1 %85, label %86, label %89
86: ; preds = %83
%87 = load i32*, i32** %10
%88 = call i32 @fclose(i32* %87)
br label %89
89: ; preds = %86, %83
%90 = load i8*, i8** %9
%91 = icmp ne i8* %90, null
br i1 %91, label %92, label %95
92: ; preds = %89
%93 = load i32*, i32** %11
%94 = call i32 @fclose(i32* %93)
br label %95
95: ; preds = %92, %89
store i32 0, i32* %3
br label %96
96: ; preds = %95, %79, %55, %41, %25
%97 = load i32, i32* %3
ret i32 %97
}

LLVM IR (-O2):
@.str = [6 x i8] c"i:o:?\00"
@EOF = global i32 0
@optarg = global i8* null
@.str.1 = [30 x i8] c"%s [-i inputfile -o outfile]\0A\00"
@stdin = global i32* null
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [15 x i8] c"Can't open %s\0A\00"
@stdout = global i32* null
@.str.4 = [3 x i8] c"w+\00"
@.str.5 = [24 x i8] c"Write error at line:%d\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca [1024 x i8]
%4 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%5 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%6 = load i32, i32* @EOF
%7 = icmp eq i32 %5, %6
br i1 %7, label %27, label %8
8: ; preds = %2, %19
%9 = phi i32 [ %22, %19 ], [ %5, %2 ]
%10 = phi i8* [ %21, %19 ], [ null, %2 ]
%11 = phi i8* [ %20, %19 ], [ null, %2 ]
switch i32 %9, label %19 [
i32 105, label %12
i32 111, label %14
i32 63, label %16
]
12: ; preds = %8
%13 = load i8*, i8** @optarg
br label %19
14: ; preds = %8
%15 = load i8*, i8** @optarg
br label %19
16: ; preds = %8
%17 = load i8*, i8** %1
%18 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i8* %17)
br label %71
19: ; preds = %8, %14, %12
%20 = phi i8* [ %11, %8 ], [ %11, %14 ], [ %13, %12 ]
%21 = phi i8* [ %10, %8 ], [ %15, %14 ], [ %10, %12 ]
%22 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%23 = load i32, i32* @EOF
%24 = icmp eq i32 %22, %23
br i1 %24, label %25, label %8
25: ; preds = %19
%26 = icmp eq i8* %20, null
br i1 %26, label %27, label %30
27: ; preds = %2, %25
%28 = phi i8* [ %21, %25 ], [ null, %2 ]
%29 = load i32*, i32** @stdin
br label %35
30: ; preds = %25
%31 = tail call i32* @fopen(i8* %20, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%32 = icmp eq i32* %31, null
br i1 %32, label %33, label %35
33: ; preds = %30
%34 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i8* %20)
br label %71
35: ; preds = %30, %27
%36 = phi i1 [ true, %27 ], [ false, %30 ]
%37 = phi i8* [ %28, %27 ], [ %21, %30 ]
%38 = phi i32* [ %29, %27 ], [ %31, %30 ]
%39 = icmp eq i8* %37, null
br i1 %39, label %40, label %42
40: ; preds = %35
%41 = load i32*, i32** @stdout
br label %47
42: ; preds = %35
%43 = tail call i32* @fopen(i8* %37, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
%44 = icmp eq i32* %38, null
br i1 %44, label %45, label %47
45: ; preds = %42
%46 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i8* %37)
br label %71
47: ; preds = %42, %40
%48 = phi i32* [ %41, %40 ], [ %43, %42 ]
%49 = call i32* @fgets(i8* %4, i32 1024, i32* %38)
%50 = icmp eq i32* %49, null
br i1 %50, label %65, label %51
51: ; preds = %47, %56
%52 = phi i32 [ %53, %56 ], [ 0, %47 ]
%53 = add nuw nsw i32 %52, 1
%54 = load i8, i8* %4
%55 = icmp eq i8 %54, 10
br i1 %55, label %56, label %59
56: ; preds = %51, %59
%57 = call i32* @fgets(i8* %4, i32 1024, i32* %38)
%58 = icmp eq i32* %57, null
br i1 %58, label %65, label %51
59: ; preds = %51
%60 = call i32 @fputs(i8* %4, i32* %48)
%61 = load i32, i32* @EOF
%62 = icmp eq i32 %60, %61
br i1 %62, label %63, label %56
63: ; preds = %59
%64 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.5, i64 0, i64 0), i32 %53)
br label %71
65: ; preds = %56, %47
br i1 %36, label %68, label %66
66: ; preds = %65
%67 = call i32 @fclose(i32* %38)
br label %68
68: ; preds = %66, %65
br i1 %39, label %71, label %69
69: ; preds = %68
%70 = call i32 @fclose(i32* %48)
br label %71
71: ; preds = %68, %69, %63, %45, %33, %16
%72 = phi i32 [ 0, %16 ], [ -1, %63 ], [ -1, %45 ], [ -1, %33 ], [ 0, %69 ], [ 0, %68 ]
ret i32 %72
}