#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_FAILURE;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ stderr;
void printFile() {
  FILE *fp = fopen("mmap.temp", "r");
  char buf[100];
  if (fgets(buf, 100, fp) == NULL) {
    fprintf(stderr, "fgets() error\n");
    exit(EXIT_FAILURE);
  }
  printf("file actually contains contains: %s\n", buf);
  fclose(fp);
}


x86 assembly (clang, -O0):
<printFile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
lea    0xe91(%rip),%rdi
lea    0xe94(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x8(%rbp)
lea    -0x70(%rbp),%rdi
mov    -0x8(%rbp),%rdx
mov    $0x64,%esi
call   1050 <fgets@plt>
cmp    $0x0,%rax
jne    11be <printFile+0x5e>
mov    0x2e3e(%rip),%rax
mov    (%rax),%edi
lea    0xe61(%rip),%rsi
call   1060 <fprintf@plt>
mov    0x2e21(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
lea    -0x70(%rbp),%rsi
lea    0xe52(%rip),%rdi
call   1040 <printf@plt>
mov    -0x8(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<printFile>:
push   %rbx
sub    $0x70,%rsp
lea    0xe94(%rip),%rdi
lea    0xe97(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,%rbx
mov    %rsp,%rdi
mov    $0x64,%esi
mov    %rax,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
je     11ad <printFile+0x4d>
lea    0xe84(%rip),%rdi
mov    %rsp,%rsi
call   1040 <printf@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
add    $0x70,%rsp
pop    %rbx
ret
mov    0x2e2c(%rip),%rax
mov    (%rax),%edi
lea    0xe4f(%rip),%rsi
call   1060 <fprintf@plt>
mov    0x2e0f(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [10 x i8] c"mmap.temp\00"
@.str.1 = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.2 = [15 x i8] c"fgets() error\0A\00"
@EXIT_FAILURE = global i32 0
@.str.3 = [37 x i8] c"file actually contains contains: %s\0A\00"
define void @printFile() {
%1 = alloca i32*
%2 = alloca [100 x i8]
%3 = call i32* @fopen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %3, i32** %1
%4 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%5 = load i32*, i32** %1
%6 = call i32* @fgets(i8* %4, i32 100, i32* %5)
%7 = icmp eq i32* %6, null
br i1 %7, label %8, label %13
8: ; preds = %0
%9 = load i32, i32* @stderr
%10 = call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
%11 = load i32, i32* @EXIT_FAILURE
%12 = call i32 @exit(i32 %11)
unreachable
13: ; preds = %0
%14 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%15 = call i32 @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.3, i64 0, i64 0), i8* %14)
%16 = load i32*, i32** %1
%17 = call i32 @fclose(i32* %16)
ret void
}

LLVM IR (-O2):
@.str = [10 x i8] c"mmap.temp\00"
@.str.1 = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.2 = [15 x i8] c"fgets() error\0A\00"
@EXIT_FAILURE = global i32 0
@.str.3 = [37 x i8] c"file actually contains contains: %s\0A\00"
define void @printFile() {
%1 = alloca [100 x i8]
%2 = tail call i32* @fopen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%3 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 0
%4 = call i32* @fgets(i8* %3, i32 100, i32* %2)
%5 = icmp eq i32* %4, null
br i1 %5, label %6, label %11
6: ; preds = %0
%7 = load i32, i32* @stderr
%8 = call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
%9 = load i32, i32* @EXIT_FAILURE
%10 = call i32 @exit(i32 %9)
unreachable
11: ; preds = %0
%12 = call i32 @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.3, i64 0, i64 0), i8* %3)
%13 = call i32 @fclose(i32* %2)
ret void
}