#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 /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ feof(int /*<<< orphan*/ *);
scalar_t__ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ printf(char *, char *);
int output(char *filename) {
  FILE *fp;
  char str[64];
  if ((fp = fopen(filename, "r")) == NULL) {
    printf("Cannot open file %s.\n", filename);
    return 1;
  }
  while (!feof(fp)) {
    if (fgets(str, 128, fp)) {
      printf("%s", str);
    }
  }
  fclose(fp);
  return 0;
}


x86 assembly (clang, -O0):
<output>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe99(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    1196 <output+0x46>
mov    -0x10(%rbp),%rsi
lea    0xe7d(%rip),%rdi
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    11fa <output+0xaa>
jmp    119b <output+0x4b>
mov    -0x18(%rbp),%rdi
call   1060 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    11b9 <output+0x69>
jmp    11ea <output+0x9a>
lea    -0x60(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    $0x80,%esi
call   1050 <fgets@plt>
cmp    $0x0,%rax
je     11e5 <output+0x95>
lea    -0x60(%rbp),%rsi
lea    0xe38(%rip),%rdi
call   1040 <printf@plt>
jmp    119b <output+0x4b>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<output>:
push   %r15
push   %r14
push   %rbx
sub    $0x40,%rsp
mov    %rdi,%r14
lea    0xe9d(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     1188 <output+0x38>
mov    %rax,%rbx
mov    %rax,%rdi
call   1060 <feof@plt>
test   %eax,%eax
je     11a6 <output+0x56>
mov    %rbx,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
jmp    119c <output+0x4c>
lea    0xe73(%rip),%rdi
mov    %r14,%rsi
call   1040 <printf@plt>
mov    $0x1,%eax
add    $0x40,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
mov    %rsp,%r14
lea    0xe68(%rip),%r15
jmp    11cc <output+0x7c>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %rbx,%rdi
call   1060 <feof@plt>
test   %eax,%eax
jne    117c <output+0x2c>
mov    %r14,%rdi
mov    $0x80,%esi
mov    %rbx,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
je     11c0 <output+0x70>
mov    %r15,%rdi
mov    %r14,%rsi
call   1040 <printf@plt>
jmp    11c0 <output+0x70>

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [22 x i8] c"Cannot open file %s.\0A\00"
@.str.2 = [3 x i8] c"%s\00"
define i32 @output(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca [64 x i8]
store i8* %0, i8** %3
%6 = load i8*, i8** %3
%7 = call i32* @fopen(i8* %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %7, i32** %4
%8 = icmp eq i32* %7, null
br i1 %8, label %9, label %12
9: ; preds = %1
%10 = load i8*, i8** %3
%11 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i8* %10)
store i32 1, i32* %2
br label %30
12: ; preds = %1
br label %13
13: ; preds = %26, %12
%14 = load i32*, i32** %4
%15 = call i32 @feof(i32* %14)
%16 = icmp ne i32 %15, 0
%17 = xor i1 %16, true
br i1 %17, label %18, label %27
18: ; preds = %13
%19 = getelementptr inbounds [64 x i8], [64 x i8]* %5, i64 0, i64 0
%20 = load i32*, i32** %4
%21 = call i64 @fgets(i8* %19, i32 128, i32* %20)
%22 = icmp ne i64 %21, 0
br i1 %22, label %23, label %26
23: ; preds = %18
%24 = getelementptr inbounds [64 x i8], [64 x i8]* %5, i64 0, i64 0
%25 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %24)
br label %26
26: ; preds = %23, %18
br label %13
27: ; preds = %13
%28 = load i32*, i32** %4
%29 = call i32 @fclose(i32* %28)
store i32 0, i32* %2
br label %30
30: ; preds = %27, %9
%31 = load i32, i32* %2
ret i32 %31
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [22 x i8] c"Cannot open file %s.\0A\00"
@.str.2 = [3 x i8] c"%s\00"
define i32 @output(i8* %0) {
%2 = alloca [64 x i8]
%3 = getelementptr inbounds [64 x i8], [64 x i8]* %2, i64 0, i64 0
%4 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%5 = icmp eq i32* %4, null
br i1 %5, label %9, label %6
6: ; preds = %1
%7 = call i32 @feof(i32* %4)
%8 = icmp eq i32 %7, 0
br i1 %8, label %11, label %19
9: ; preds = %1
%10 = tail call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i8* %0)
br label %21
11: ; preds = %6, %16
%12 = call i64 @fgets(i8* %3, i32 128, i32* %4)
%13 = icmp eq i64 %12, 0
br i1 %13, label %16, label %14
14: ; preds = %11
%15 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %3)
br label %16
16: ; preds = %14, %11
%17 = call i32 @feof(i32* %4)
%18 = icmp eq i32 %17, 0
br i1 %18, label %11, label %19
19: ; preds = %16, %6
%20 = call i32 @fclose(i32* %4)
br label %21
21: ; preds = %19, %9
%22 = phi i32 [ 1, %9 ], [ 0, %19 ]
ret i32 %22
}