#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*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char const *);
int /*<<< orphan*/ stdout;
int main(void) {
  static const char filename[] = "output.txt";
  FILE *file = fopen(filename, "r");
  if (file != NULL) {
    char line[128];
    while (fgets(line, sizeof line, file) != NULL) {
      fputs(line, stdout);
    }
    fclose(file);
  } else {
    perror(filename);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe97(%rip),%rdi
lea    0xe9b(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     11d0 <main+0x80>
jmp    1189 <main+0x39>
lea    -0x90(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    $0x80,%esi
call   1050 <fgets@plt>
cmp    $0x0,%rax
je     11c2 <main+0x72>
lea    -0x90(%rbp),%rdi
mov    0x2e2a(%rip),%rax
mov    (%rax),%esi
call   1040 <fputs@plt>
jmp    1189 <main+0x39>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
jmp    11dc <main+0x8c>
lea    0xe29(%rip),%rdi
call   1070 <perror@plt>
xor    %eax,%eax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x80,%rsp
lea    0xe9d(%rip),%rdi
lea    0xea1(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     11d7 <main+0x87>
mov    %rax,%r14
mov    %rsp,%rdi
mov    $0x80,%esi
mov    %rax,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
je     11c0 <main+0x70>
mov    0x2e4d(%rip),%r15
mov    %rsp,%rbx
cs nopw 0x0(%rax,%rax,1)
mov    (%r15),%esi
mov    %rbx,%rdi
call   1040 <fputs@plt>
mov    %rbx,%rdi
mov    $0x80,%esi
mov    %r14,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
jne    11a0 <main+0x50>
mov    %r14,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x80,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
lea    0xe22(%rip),%rdi
call   1070 <perror@plt>
jmp    11c8 <main+0x78>

LLVM IR (-O0):
@main.filename = internal constant [11 x i8] c"output.txt\00"
@.str = [2 x i8] c"r\00"
@stdout = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca [128 x i8]
store i32 0, i32* %1
%4 = call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @main.filename, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %4, i32** %2
%5 = load i32*, i32** %2
%6 = icmp ne i32* %5, null
br i1 %6, label %7, label %20
7: ; preds = %0
br label %8
8: ; preds = %13, %7
%9 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 0
%10 = load i32*, i32** %2
%11 = call i32* @fgets(i8* %9, i32 128, i32* %10)
%12 = icmp ne i32* %11, null
br i1 %12, label %13, label %17
13: ; preds = %8
%14 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 0
%15 = load i32, i32* @stdout
%16 = call i32 @fputs(i8* %14, i32 %15)
br label %8
17: ; preds = %8
%18 = load i32*, i32** %2
%19 = call i32 @fclose(i32* %18)
br label %22
20: ; preds = %0
%21 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @main.filename, i64 0, i64 0))
br label %22
22: ; preds = %20, %17
ret i32 0
}

LLVM IR (-O2):
@main.filename = internal constant [11 x i8] c"output.txt\00"
@.str = [2 x i8] c"r\00"
@stdout = global i32 0
define i32 @main() {
%1 = alloca [128 x i8]
%2 = tail call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @main.filename, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%3 = icmp eq i32* %2, null
br i1 %3, label %15, label %4
4: ; preds = %0
%5 = getelementptr inbounds [128 x i8], [128 x i8]* %1, i64 0, i64 0
%6 = call i32* @fgets(i8* %5, i32 128, i32* %2)
%7 = icmp eq i32* %6, null
br i1 %7, label %13, label %8
8: ; preds = %4, %8
%9 = load i32, i32* @stdout
%10 = call i32 @fputs(i8* %5, i32 %9)
%11 = call i32* @fgets(i8* %5, i32 128, i32* %2)
%12 = icmp eq i32* %11, null
br i1 %12, label %13, label %8
13: ; preds = %8, %4
%14 = call i32 @fclose(i32* %2)
br label %17
15: ; preds = %0
%16 = tail call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @main.filename, i64 0, i64 0))
br label %17
17: ; preds = %15, %13
ret i32 0
}