#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 /*<<< orphan*/ feof(int /*<<< orphan*/ *);
int fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ free(char *);
char *malloc(int);
int /*<<< orphan*/ printf(char *, char);
int main(int argc, char *argv[]) {
  char *buffer;
  FILE *fp;
  fp = fopen(argv[1], "r");
  if (fp == NULL)
    return 1;
  buffer = malloc(sizeof(int));
  while (!feof(fp)) {
    int c = fgetc(fp);
    if (c != EOF)
      printf("%c", (char)c);
  }
  fclose(fp);
  free(buffer);
  return 0;
}


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)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe6b(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11b5 <main+0x45>
movl   $0x1,-0x4(%rbp)
jmp    122f <main+0xbf>
mov    $0x4,%edi
call   1080 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x20(%rbp),%rdi
call   1070 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    11e1 <main+0x71>
jmp    1216 <main+0xa6>
mov    -0x20(%rbp),%rdi
call   1060 <fgetc@plt>
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    0x2df1(%rip),%rcx
cmp    (%rcx),%eax
je     1211 <main+0xa1>
mov    -0x24(%rbp),%eax
lea    0xdf9(%rip),%rdi
movsbl %al,%esi
call   1050 <printf@plt>
jmp    11c3 <main+0x53>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    0x8(%rsi),%rdi
lea    0xe7d(%rip),%rsi
call   1090 <fopen@plt>
test   %rax,%rax
je     11bd <main+0x4d>
mov    %rax,%rbx
mov    $0x4,%edi
call   1080 <malloc@plt>
mov    %rax,%r14
mov    %rbx,%rdi
call   1070 <feof@plt>
test   %eax,%eax
je     11ce <main+0x5e>
mov    %rbx,%rdi
call   1040 <fclose@plt>
mov    %r14,%rdi
call   1030 <free@plt>
xor    %eax,%eax
jmp    11c2 <main+0x52>
mov    $0x1,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
mov    0x2e13(%rip),%r12
lea    0xe26(%rip),%r15
jmp    11ec <main+0x7c>
xchg   %ax,%ax
mov    %rbx,%rdi
call   1070 <feof@plt>
test   %eax,%eax
jne    11a9 <main+0x39>
mov    %rbx,%rdi
call   1060 <fgetc@plt>
cmp    (%r12),%eax
je     11e0 <main+0x70>
movsbl %al,%esi
mov    %r15,%rdi
call   1050 <printf@plt>
jmp    11e0 <main+0x70>

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@EOF = global i32 0
@.str.1 = [3 x i8] c"%c\00"
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
%9 = load i8**, i8*** %5
%10 = getelementptr inbounds i8*, i8** %9, i64 1
%11 = load i8*, i8** %10
%12 = call i32* @fopen(i8* %11, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %12, i32** %7
%13 = load i32*, i32** %7
%14 = icmp eq i32* %13, null
br i1 %14, label %15, label %16
15: ; preds = %2
store i32 1, i32* %3
br label %39
16: ; preds = %2
%17 = call i8* @malloc(i32 4)
store i8* %17, i8** %6
br label %18
18: ; preds = %33, %16
%19 = load i32*, i32** %7
%20 = call i32 @feof(i32* %19)
%21 = icmp ne i32 %20, 0
%22 = xor i1 %21, true
br i1 %22, label %23, label %34
23: ; preds = %18
%24 = load i32*, i32** %7
%25 = call i32 @fgetc(i32* %24)
store i32 %25, i32* %8
%26 = load i32, i32* %8
%27 = load i32, i32* @EOF
%28 = icmp ne i32 %26, %27
br i1 %28, label %29, label %33
29: ; preds = %23
%30 = load i32, i32* %8
%31 = trunc i32 %30 to i8
%32 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8 signext %31)
br label %33
33: ; preds = %29, %23
br label %18
34: ; preds = %18
%35 = load i32*, i32** %7
%36 = call i32 @fclose(i32* %35)
%37 = load i8*, i8** %6
%38 = call i32 @free(i8* %37)
store i32 0, i32* %3
br label %39
39: ; preds = %34, %15
%40 = load i32, i32* %3
ret i32 %40
}

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