#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*/ FILE;

/* Variables and functions */
int EOF;
int fclose(int /*<<< orphan*/ *);
scalar_t__ ferror(int /*<<< orphan*/ *);
int fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fputc(int, int /*<<< orphan*/);
int getopt(int, char **, char *);
char *optarg;
float optopt;
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stdout;
int main(int argc, char *argv[]) {
  FILE *instream = NULL;
  char *filepath = NULL;
  char *usage = "printer -f <FILEPATH>";
  int opt;
  while ((opt = getopt(argc, argv, "f:")) != -1) {
    switch (opt) {
    case 'f':
      filepath = optarg;
      break;
    case '?':
      if (optopt == 'f') {
        printf("%s\n", usage);
        return -1;
      } else {
        printf("%s\n", usage);
        return -1;
      }
      break;
    default:
      break;
    }
  }
  instream = fopen(filepath, "r");
  if (instream == NULL) {
    perror("fopen()");
    return -1;
  }
  int c;
  while ((c = fgetc(instream)) != EOF) {
    fputc(c, stdout);
  }
  if (ferror(instream)) {
    printf("Error reading from input stream.\n");
  }
  if (fclose(instream) == EOF) {
    perror("fclose()");
    return -1;
  } else {
    return 0;
  }
}


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)
lea    0xe57(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xe5b(%rip),%rdx
call   10a0 <getopt@plt>
mov    %eax,-0x2c(%rbp)
cmp    $0xffffffff,%eax
je     1270 <main+0xf0>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x34(%rbp)
sub    $0x3f,%eax
je     1208 <main+0x88>
jmp    11e4 <main+0x64>
mov    -0x34(%rbp),%eax
sub    $0x66,%eax
jne    1266 <main+0xe6>
jmp    11f5 <main+0x75>
mov    0x2dfc(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x20(%rbp)
jmp    126b <main+0xeb>
mov    0x2dd1(%rip),%rax
movss  (%rax),%xmm0
movss  0xde5(%rip),%xmm1
ucomiss %xmm1,%xmm0
jne    1248 <main+0xc8>
jp     1248 <main+0xc8>
mov    -0x28(%rbp),%rsi
lea    0xde8(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1335 <main+0x1b5>
mov    -0x28(%rbp),%rsi
lea    0xdca(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1335 <main+0x1b5>
jmp    126b <main+0xeb>
jmp    11b1 <main+0x31>
mov    -0x20(%rbp),%rdi
lea    0xda6(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    12a7 <main+0x127>
lea    0xd8d(%rip),%rdi
call   1090 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1335 <main+0x1b5>
jmp    12ac <main+0x12c>
mov    -0x18(%rbp),%rdi
call   1060 <fgetc@plt>
mov    %eax,-0x30(%rbp)
mov    0x2d19(%rip),%rcx
cmp    (%rcx),%eax
je     12dd <main+0x15d>
mov    -0x30(%rbp),%edi
mov    0x2cf7(%rip),%rax
mov    (%rax),%esi
call   1070 <fputc@plt>
jmp    12ac <main+0x12c>
mov    -0x18(%rbp),%rdi
call   1030 <ferror@plt>
cmp    $0x0,%rax
je     12fe <main+0x17e>
lea    0xd34(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
mov    0x2cca(%rip),%rcx
cmp    (%rcx),%eax
jne    132e <main+0x1ae>
lea    0xd30(%rip),%rdi
call   1090 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1335 <main+0x1b5>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rsi,%rbx
mov    %edi,%ebp
xor    %r14d,%r14d
lea    0xe7f(%rip),%r15
mov    0x2e5a(%rip),%r12
xchg   %ax,%ax
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r15,%rdx
call   10a0 <getopt@plt>
cmp    $0xffffffff,%eax
je     11c6 <main+0x46>
cmp    $0x3f,%eax
je     124a <main+0xca>
cmp    $0x66,%eax
jne    11a0 <main+0x20>
mov    (%r12),%r14
jmp    11a0 <main+0x20>
lea    0xe4c(%rip),%rsi
mov    %r14,%rdi
call   1080 <fopen@plt>
test   %rax,%rax
je     1264 <main+0xe4>
mov    %rax,%rbx
mov    %rax,%rdi
call   1060 <fgetc@plt>
mov    0x2df0(%rip),%r14
cmp    (%r14),%eax
je     1217 <main+0x97>
mov    0x2dd4(%rip),%rbp
nopl   0x0(%rax)
mov    0x0(%rbp),%esi
mov    %eax,%edi
call   1070 <fputc@plt>
mov    %rbx,%rdi
call   1060 <fgetc@plt>
cmp    (%r14),%eax
jne    1200 <main+0x80>
mov    %rbx,%rdi
call   1040 <ferror@plt>
test   %rax,%rax
je     1230 <main+0xb0>
lea    0xe01(%rip),%rdi
call   1030 <puts@plt>
mov    %rbx,%rdi
call   1050 <fclose@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    (%r14),%ecx
jne    125b <main+0xdb>
lea    0xddb(%rip),%rdi
jmp    126b <main+0xeb>
lea    0xdaf(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xdb0(%rip),%rdi
call   1090 <perror@plt>
jmp    1256 <main+0xd6>

LLVM IR (-O0):
@.str = [22 x i8] c"printer -f <FILEPATH>\00"
@.str.1 = [3 x i8] c"f:\00"
@optarg = global i8* null
@optopt = global float 0.000000e+00
@.str.2 = [4 x i8] c"%s\0A\00"
@.str.3 = [2 x i8] c"r\00"
@.str.4 = [8 x i8] c"fopen()\00"
@EOF = global i32 0
@stdout = global i32 0
@.str.5 = [34 x i8] c"Error reading from input stream.\0A\00"
@.str.6 = [9 x i8] c"fclose()\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32* null, i32** %6
store i8* null, i8** %7
store i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8** %8
br label %11
11: ; preds = %30, %2
%12 = load i32, i32* %4
%13 = load i8**, i8*** %5
%14 = call i32 @getopt(i32 %12, i8** %13, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32 %14, i32* %9
%15 = icmp ne i32 %14, -1
br i1 %15, label %16, label %31
16: ; preds = %11
%17 = load i32, i32* %9
switch i32 %17, label %29 [
i32 102, label %18
i32 63, label %20
]
18: ; preds = %16
%19 = load i8*, i8** @optarg
store i8* %19, i8** %7
br label %30
20: ; preds = %16
%21 = load float, float* @optopt
%22 = fcmp oeq float %21, 1.020000e+02
br i1 %22, label %23, label %26
23: ; preds = %20
%24 = load i8*, i8** %8
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %24)
store i32 -1, i32* %3
br label %62
26: ; preds = %20
%27 = load i8*, i8** %8
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %27)
store i32 -1, i32* %3
br label %62
29: ; preds = %16
br label %30
30: ; preds = %29, %18
br label %11
31: ; preds = %11
%32 = load i8*, i8** %7
%33 = call i32* @fopen(i8* %32, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %33, i32** %6
%34 = load i32*, i32** %6
%35 = icmp eq i32* %34, null
br i1 %35, label %36, label %38
36: ; preds = %31
%37 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0))
store i32 -1, i32* %3
br label %62
38: ; preds = %31
br label %39
39: ; preds = %44, %38
%40 = load i32*, i32** %6
%41 = call i32 @fgetc(i32* %40)
store i32 %41, i32* %10
%42 = load i32, i32* @EOF
%43 = icmp ne i32 %41, %42
br i1 %43, label %44, label %48
44: ; preds = %39
%45 = load i32, i32* %10
%46 = load i32, i32* @stdout
%47 = call i32 @fputc(i32 %45, i32 %46)
br label %39
48: ; preds = %39
%49 = load i32*, i32** %6
%50 = call i64 @ferror(i32* %49)
%51 = icmp ne i64 %50, 0
br i1 %51, label %52, label %54
52: ; preds = %48
%53 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.5, i64 0, i64 0))
br label %54
54: ; preds = %52, %48
%55 = load i32*, i32** %6
%56 = call i32 @fclose(i32* %55)
%57 = load i32, i32* @EOF
%58 = icmp eq i32 %56, %57
br i1 %58, label %59, label %61
59: ; preds = %54
%60 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.6, i64 0, i64 0))
store i32 -1, i32* %3
br label %62
61: ; preds = %54
store i32 0, i32* %3
br label %62
62: ; preds = %61, %59, %36, %26, %23
%63 = load i32, i32* %3
ret i32 %63
}

LLVM IR (-O2):
@.str = [22 x i8] c"printer -f <FILEPATH>\00"
@.str.1 = [3 x i8] c"f:\00"
@optarg = global i8* null
@optopt = global float 0.000000e+00
@.str.3 = [2 x i8] c"r\00"
@.str.4 = [8 x i8] c"fopen()\00"
@EOF = global i32 0
@stdout = global i32 0
@.str.6 = [9 x i8] c"fclose()\00"
@str = [33 x i8] c"Error reading from input stream.\00"
define i32 @main(i32 %0, i8** %1) {
br label %3
3: ; preds = %7, %2
%4 = phi i8* [ %8, %7 ], [ null, %2 ]
br label %5
5: ; preds = %3, %5
%6 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
switch i32 %6, label %5 [
i32 -1, label %11
i32 102, label %7
i32 63, label %9
]
7: ; preds = %5
%8 = load i8*, i8** @optarg
br label %3
9: ; preds = %5
%10 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
br label %38
11: ; preds = %5
%12 = tail call i32* @fopen(i8* %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%13 = icmp eq i32* %12, null
br i1 %13, label %18, label %14
14: ; preds = %11
%15 = tail call i32 @fgetc(i32* %12)
%16 = load i32, i32* @EOF
%17 = icmp eq i32 %15, %16
br i1 %17, label %27, label %20
18: ; preds = %11
%19 = tail call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0))
br label %38
20: ; preds = %14, %20
%21 = phi i32 [ %24, %20 ], [ %15, %14 ]
%22 = load i32, i32* @stdout
%23 = tail call i32 @fputc(i32 %21, i32 %22)
%24 = tail call i32 @fgetc(i32* %12)
%25 = load i32, i32* @EOF
%26 = icmp eq i32 %24, %25
br i1 %26, label %27, label %20
27: ; preds = %20, %14
%28 = tail call i64 @ferror(i32* %12)
%29 = icmp eq i64 %28, 0
br i1 %29, label %32, label %30
30: ; preds = %27
%31 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @str, i64 0, i64 0))
br label %32
32: ; preds = %30, %27
%33 = tail call i32 @fclose(i32* %12)
%34 = load i32, i32* @EOF
%35 = icmp eq i32 %33, %34
br i1 %35, label %36, label %38
36: ; preds = %32
%37 = tail call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.6, i64 0, i64 0))
br label %38
38: ; preds = %9, %36, %32, %18
%39 = phi i32 [ -1, %18 ], [ -1, %36 ], [ 0, %32 ], [ -1, %9 ]
ret i32 %39
}