#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 EOF;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, int /*<<< orphan*/);
int /*<<< orphan*/ genrb(char *);
char *file_get_contents(const char *filename, char *contents) {
  FILE *fp;
  int c;
  char rb[16];
  fp = fopen(filename, genrb(rb));
  if (fp == NULL) {
    contents[0] = '\0';
    return contents;
  }
  while ((c = fgetc(fp)) != EOF) {
    *contents++ = (char)c;
  }
  fclose(fp);
  return contents;
}


x86 assembly (clang, -O0):
<file_get_contents>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x48(%rbp)
lea    -0x40(%rbp),%rdi
call   1030 <genrb@plt>
mov    -0x48(%rbp),%rdi
mov    %eax,%esi
call   1060 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    118f <file_get_contents+0x4f>
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11db <file_get_contents+0x9b>
jmp    1194 <file_get_contents+0x54>
mov    -0x20(%rbp),%rdi
call   1050 <fgetc@plt>
mov    %eax,-0x24(%rbp)
mov    0x2e41(%rip),%rcx
cmp    (%rcx),%eax
je     11ca <file_get_contents+0x8a>
mov    -0x24(%rbp),%eax
mov    %al,%cl
mov    -0x18(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x18(%rbp)
mov    %cl,(%rax)
jmp    1194 <file_get_contents+0x54>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<file_get_contents>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbx
mov    %rdi,%r14
mov    %rsp,%rdi
call   1030 <genrb@plt>
mov    %r14,%rdi
mov    %eax,%esi
call   1060 <fopen@plt>
test   %rax,%rax
je     119d <file_get_contents+0x5d>
mov    %rax,%r14
mov    %rax,%rdi
call   1050 <fgetc@plt>
mov    0x2e70(%rip),%r15
cmp    (%r15),%eax
je     1193 <file_get_contents+0x53>
nopl   (%rax)
mov    %al,(%rbx)
add    $0x1,%rbx
mov    %r14,%rdi
call   1050 <fgetc@plt>
cmp    (%r15),%eax
jne    1180 <file_get_contents+0x40>
mov    %r14,%rdi
call   1040 <fclose@plt>
jmp    11a0 <file_get_contents+0x60>
movb   $0x0,(%rbx)
mov    %rbx,%rax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@EOF = global i32 0
define i8* @file_get_contents(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32*
%7 = alloca i32
%8 = alloca [16 x i8]
store i8* %0, i8** %4
store i8* %1, i8** %5
%9 = load i8*, i8** %4
%10 = getelementptr inbounds [16 x i8], [16 x i8]* %8, i64 0, i64 0
%11 = call i32 @genrb(i8* %10)
%12 = call i32* @fopen(i8* %9, i32 %11)
store i32* %12, i32** %6
%13 = load i32*, i32** %6
%14 = icmp eq i32* %13, null
br i1 %14, label %15, label %19
15: ; preds = %2
%16 = load i8*, i8** %5
%17 = getelementptr inbounds i8, i8* %16, i64 0
store i8 0, i8* %17
%18 = load i8*, i8** %5
store i8* %18, i8** %3
br label %34
19: ; preds = %2
br label %20
20: ; preds = %25, %19
%21 = load i32*, i32** %6
%22 = call i32 @fgetc(i32* %21)
store i32 %22, i32* %7
%23 = load i32, i32* @EOF
%24 = icmp ne i32 %22, %23
br i1 %24, label %25, label %30
25: ; preds = %20
%26 = load i32, i32* %7
%27 = trunc i32 %26 to i8
%28 = load i8*, i8** %5
%29 = getelementptr inbounds i8, i8* %28, i32 1
store i8* %29, i8** %5
store i8 %27, i8* %28
br label %20
30: ; preds = %20
%31 = load i32*, i32** %6
%32 = call i32 @fclose(i32* %31)
%33 = load i8*, i8** %5
store i8* %33, i8** %3
br label %34
34: ; preds = %30, %15
%35 = load i8*, i8** %3
ret i8* %35
}

LLVM IR (-O2):
@EOF = global i32 0
define i8* @file_get_contents(i8* %0, i8* writeonly %1) {
%3 = alloca [16 x i8]
%4 = getelementptr inbounds [16 x i8], [16 x i8]* %3, i64 0, i64 0
%5 = call i32 @genrb(i8* %4)
%6 = call i32* @fopen(i8* %0, i32 %5)
%7 = icmp eq i32* %6, null
br i1 %7, label %12, label %8
8: ; preds = %2
%9 = call i32 @fgetc(i32* %6)
%10 = load i32, i32* @EOF
%11 = icmp eq i32 %9, %10
br i1 %11, label %21, label %13
12: ; preds = %2
store i8 0, i8* %1
br label %24
13: ; preds = %8, %13
%14 = phi i32 [ %18, %13 ], [ %9, %8 ]
%15 = phi i8* [ %17, %13 ], [ %1, %8 ]
%16 = trunc i32 %14 to i8
%17 = getelementptr inbounds i8, i8* %15, i64 1
store i8 %16, i8* %15
%18 = call i32 @fgetc(i32* %6)
%19 = load i32, i32* @EOF
%20 = icmp eq i32 %18, %19
br i1 %20, label %21, label %13
21: ; preds = %13, %8
%22 = phi i8* [ %1, %8 ], [ %17, %13 ]
%23 = call i32 @fclose(i32* %6)
br label %24
24: ; preds = %21, %12
%25 = phi i8* [ %1, %12 ], [ %22, %21 ]
ret i8* %25
}