#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 /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ printf(char *, ...);
int main(int argc, char *argv[]) {
  if (argc != 2) {
    printf("usage: %s filename\n", argv[0]);
  } else {
    FILE *file = fopen(argv[1], "r");
    if (file == 0) {
      printf("Could not open file\n");
    } else {
      int x;
      while ((x = fgetc(file)) != EOF) {
        printf("%c", x);
      }
      fclose(file);
    }
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     117a <main+0x3a>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe92(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    11f4 <main+0xb4>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe8b(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11b0 <main+0x70>
lea    0xe72(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    11ef <main+0xaf>
jmp    11b5 <main+0x75>
mov    -0x18(%rbp),%rdi
call   1050 <fgetc@plt>
mov    %eax,-0x1c(%rbp)
mov    0x2e20(%rip),%rcx
cmp    (%rcx),%eax
je     11e6 <main+0xa6>
mov    -0x1c(%rbp),%esi
lea    0xe51(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    11b5 <main+0x75>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
jmp    11f4 <main+0xb4>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
cmp    $0x2,%edi
jne    11be <main+0x5e>
mov    0x8(%rsi),%rdi
lea    0xea0(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     11d1 <main+0x71>
mov    %rax,%rbx
mov    %rax,%rdi
call   1070 <fgetc@plt>
mov    0x2e58(%rip),%r14
cmp    (%r14),%eax
je     11b4 <main+0x54>
cs nopw 0x0(%rax,%rax,1)
nop
mov    %eax,%edi
call   1030 <putchar@plt>
mov    %rbx,%rdi
call   1070 <fgetc@plt>
cmp    (%r14),%eax
jne    11a0 <main+0x40>
mov    %rbx,%rdi
call   1050 <fclose@plt>
jmp    11dd <main+0x7d>
mov    (%rsi),%rsi
lea    0xe38(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
jmp    11dd <main+0x7d>
lea    0xe3e(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [20 x i8] c"usage: %s filename\0A\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [21 x i8] c"Could not open file\0A\00"
@EOF = global i32 0
@.str.3 = [3 x i8] c"%c\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i32, i32* %4
%9 = icmp ne i32 %8, 2
br i1 %9, label %10, label %15
10: ; preds = %2
%11 = load i8**, i8*** %5
%12 = getelementptr inbounds i8*, i8** %11, i64 0
%13 = load i8*, i8** %12
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* %13)
br label %37
15: ; preds = %2
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 1
%18 = load i8*, i8** %17
%19 = call i32* @fopen(i8* %18, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %19, i32** %6
%20 = load i32*, i32** %6
%21 = icmp eq i32* %20, null
br i1 %21, label %22, label %24
22: ; preds = %15
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
br label %36
24: ; preds = %15
br label %25
25: ; preds = %30, %24
%26 = load i32*, i32** %6
%27 = call i32 @fgetc(i32* %26)
store i32 %27, i32* %7
%28 = load i32, i32* @EOF
%29 = icmp ne i32 %27, %28
br i1 %29, label %30, label %33
30: ; preds = %25
%31 = load i32, i32* %7
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32 %31)
br label %25
33: ; preds = %25
%34 = load i32*, i32** %6
%35 = call i32 @fclose(i32* %34)
br label %36
36: ; preds = %33, %22
br label %37
37: ; preds = %36, %10
%38 = load i32, i32* %3
ret i32 %38
}

LLVM IR (-O2):
@.str = [20 x i8] c"usage: %s filename\0A\00"
@.str.1 = [2 x i8] c"r\00"
@EOF = global i32 0
@str = [20 x i8] c"Could not open file\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 2
br i1 %3, label %7, label %4
4: ; preds = %2
%5 = load i8*, i8** %1
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* %5)
br label %26
7: ; preds = %2
%8 = getelementptr inbounds i8*, i8** %1, i64 1
%9 = load i8*, i8** %8
%10 = tail call i32* @fopen(i8* %9, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%11 = icmp eq i32* %10, null
br i1 %11, label %16, label %12
12: ; preds = %7
%13 = tail call i32 @fgetc(i32* %10)
%14 = load i32, i32* @EOF
%15 = icmp eq i32 %13, %14
br i1 %15, label %24, label %18
16: ; preds = %7
%17 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str, i64 0, i64 0))
br label %26
18: ; preds = %12, %18
%19 = phi i32 [ %21, %18 ], [ %13, %12 ]
%20 = tail call i32 @putchar(i32 %19)
%21 = tail call i32 @fgetc(i32* %10)
%22 = load i32, i32* @EOF
%23 = icmp eq i32 %21, %22
br i1 %23, label %24, label %18
24: ; preds = %18, %12
%25 = tail call i32 @fclose(i32* %10)
br label %26
26: ; preds = %16, %24, %4
ret i32 0
}