#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*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ printf(char *, char *);
int main() {
  char line[256];
  char *filename = "fox.txt";
  FILE *f;
  f = fopen(filename, "r");
  if (f == NULL) {
    printf("file does not exists! (%s)\n", filename);
    exit(1);
  }
  while (fgets(line, 256, f) != NULL) {
    printf("%s", line);
  }
  fclose(f);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x120,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe97(%rip),%rax
mov    %rax,-0x118(%rbp)
mov    -0x118(%rbp),%rdi
lea    0xe8a(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x120(%rbp)
cmpq   $0x0,-0x120(%rbp)
jne    11b5 <main+0x65>
mov    -0x118(%rbp),%rsi
lea    0xe64(%rip),%rdi
call   1040 <printf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
jmp    11ba <main+0x6a>
lea    -0x110(%rbp),%rdi
mov    -0x120(%rbp),%rdx
mov    $0x100,%esi
call   1050 <fgets@plt>
cmp    $0x0,%rax
je     11f4 <main+0xa4>
lea    -0x110(%rbp),%rsi
lea    0xe3c(%rip),%rdi
call   1040 <printf@plt>
jmp    11ba <main+0x6a>
mov    -0x120(%rbp),%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x120,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x100,%rsp
lea    0xe9d(%rip),%rdi
lea    0xe9e(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     11d7 <main+0x87>
mov    %rax,%r15
mov    %rsp,%rdi
mov    $0x100,%esi
mov    %rax,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
je     11c0 <main+0x70>
lea    0xe93(%rip),%r14
mov    %rsp,%rbx
cs nopw 0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    %rbx,%rsi
call   1040 <printf@plt>
mov    %rbx,%rdi
mov    $0x100,%esi
mov    %r15,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
jne    11a0 <main+0x50>
mov    %r15,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x100,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
lea    0xe2c(%rip),%rdi
lea    0xe1b(%rip),%rsi
call   1040 <printf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [8 x i8] c"fox.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [28 x i8] c"file does not exists! (%s)\0A\00"
@.str.3 = [3 x i8] c"%s\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [256 x i8]
%3 = alloca i8*
%4 = alloca i32*
store i32 0, i32* %1
store i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8** %3
%5 = load i8*, i8** %3
%6 = call i32* @fopen(i8* %5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %6, i32** %4
%7 = load i32*, i32** %4
%8 = icmp eq i32* %7, null
br i1 %8, label %9, label %13
9: ; preds = %0
%10 = load i8*, i8** %3
%11 = call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0), i8* %10)
%12 = call i32 @exit(i32 1)
unreachable
13: ; preds = %0
br label %14
14: ; preds = %19, %13
%15 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%16 = load i32*, i32** %4
%17 = call i32* @fgets(i8* %15, i32 256, i32* %16)
%18 = icmp ne i32* %17, null
br i1 %18, label %19, label %22
19: ; preds = %14
%20 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%21 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %20)
br label %14
22: ; preds = %14
%23 = load i32*, i32** %4
%24 = call i32 @fclose(i32* %23)
ret i32 0
}

LLVM IR (-O2):
@.str = [8 x i8] c"fox.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [28 x i8] c"file does not exists! (%s)\0A\00"
@.str.3 = [3 x i8] c"%s\00"
define i32 @main() {
%1 = alloca [256 x i8]
%2 = getelementptr inbounds [256 x i8], [256 x i8]* %1, i64 0, i64 0
%3 = tail call i32* @fopen(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %8, label %5
5: ; preds = %0
%6 = call i32* @fgets(i8* %2, i32 256, i32* %3)
%7 = icmp eq i32* %6, null
br i1 %7, label %15, label %11
8: ; preds = %0
%9 = tail call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%10 = tail call i32 @exit(i32 1)
unreachable
11: ; preds = %5, %11
%12 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %2)
%13 = call i32* @fgets(i8* %2, i32 256, i32* %3)
%14 = icmp eq i32* %13, null
br i1 %14, label %15, label %11
15: ; preds = %11, %5
%16 = call i32 @fclose(i32* %3)
ret i32 0
}