#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 *, size_t, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ stderr;
char *file_get(char *filename, char *data, size_t size) {
  FILE *fp;
  fp = fopen(filename, "r");
  if (!fp) {
    perror(filename);
    return NULL;
  }
  if (!fgets(data, size, fp)) {
    fprintf(stderr, "Cannot read %s\n", filename);
    return NULL;
  }
  fclose(fp);
  return data;
}


x86 assembly (clang, -O0):
<file_get>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe91(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1199 <file_get+0x49>
mov    -0x10(%rbp),%rdi
call   1070 <perror@plt>
movq   $0x0,-0x8(%rbp)
jmp    11ea <file_get+0x9a>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x28(%rbp),%rdx
call   1040 <fgets@plt>
cmp    $0x0,%eax
jne    11d9 <file_get+0x89>
mov    0x2e26(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xe3b(%rip),%rsi
call   1050 <fprintf@plt>
movq   $0x0,-0x8(%rbp)
jmp    11ea <file_get+0x9a>
mov    -0x28(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<file_get>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r12
mov    %rsi,%r15
mov    %rdi,%r14
lea    0xe98(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     11bb <file_get+0x6b>
mov    %rax,%rbx
mov    %r15,%rdi
mov    %r12,%rsi
mov    %rax,%rdx
call   1040 <fgets@plt>
test   %eax,%eax
je     1191 <file_get+0x41>
mov    %rbx,%rdi
call   1030 <fclose@plt>
jmp    11ac <file_get+0x5c>
mov    0x2e48(%rip),%rax
mov    (%rax),%edi
lea    0xe61(%rip),%rsi
mov    %r14,%rdx
call   1050 <fprintf@plt>
xor    %r15d,%r15d
mov    %r15,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
mov    %r14,%rdi
call   1070 <perror@plt>
jmp    11a9 <file_get+0x59>

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

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.1 = [16 x i8] c"Cannot read %s\0A\00"
define i8* @file_get(i8* %0, i8* %1, i64 %2) {
%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 %6, label %8
6: ; preds = %3
%7 = tail call i32 @perror(i8* %0)
br label %16
8: ; preds = %3
%9 = tail call i32 @fgets(i8* %1, i64 %2, i32* %4)
%10 = icmp eq i32 %9, 0
br i1 %10, label %11, label %14
11: ; preds = %8
%12 = load i32, i32* @stderr
%13 = tail call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i8* %0)
br label %16
14: ; preds = %8
%15 = tail call i32 @fclose(i32* %4)
br label %16
16: ; preds = %14, %11, %6
%17 = phi i8* [ %1, %14 ], [ null, %11 ], [ null, %6 ]
ret i8* %17
}