#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*/ get(int /*<<< orphan*/);
char *file_get_contents(const char *filename, char *contents) {
  FILE *fp;
  int c;
  char rb[16];
  fp = fopen(filename, get(0));
  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)
xor    %edi,%edi
call   1050 <get@plt>
mov    -0x48(%rbp),%rdi
mov    %eax,%esi
call   1060 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    118d <file_get_contents+0x4d>
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11d9 <file_get_contents+0x99>
jmp    1192 <file_get_contents+0x52>
mov    -0x20(%rbp),%rdi
call   1040 <fgetc@plt>
mov    %eax,-0x24(%rbp)
mov    0x2e43(%rip),%rcx
cmp    (%rcx),%eax
je     11c8 <file_get_contents+0x88>
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    1192 <file_get_contents+0x52>
mov    -0x20(%rbp),%rdi
call   1030 <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
mov    %rsi,%rbx
mov    %rdi,%r14
xor    %edi,%edi
call   1050 <get@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   1040 <fgetc@plt>
mov    0x2e75(%rip),%r15
cmp    (%r15),%eax
je     1193 <file_get_contents+0x53>
nopl   0x0(%rax,%rax,1)
mov    %al,(%rbx)
add    $0x1,%rbx
mov    %r14,%rdi
call   1040 <fgetc@plt>
cmp    (%r15),%eax
jne    1180 <file_get_contents+0x40>
mov    %r14,%rdi
call   1030 <fclose@plt>
jmp    11a0 <file_get_contents+0x60>
movb   $0x0,(%rbx)
mov    %rbx,%rax
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 = call i32 @get(i32 0)
%11 = call i32* @fopen(i8* %9, i32 %10)
store i32* %11, i32** %6
%12 = load i32*, i32** %6
%13 = icmp eq i32* %12, null
br i1 %13, label %14, label %18
14: ; preds = %2
%15 = load i8*, i8** %5
%16 = getelementptr inbounds i8, i8* %15, i64 0
store i8 0, i8* %16
%17 = load i8*, i8** %5
store i8* %17, i8** %3
br label %33
18: ; preds = %2
br label %19
19: ; preds = %24, %18
%20 = load i32*, i32** %6
%21 = call i32 @fgetc(i32* %20)
store i32 %21, i32* %7
%22 = load i32, i32* @EOF
%23 = icmp ne i32 %21, %22
br i1 %23, label %24, label %29
24: ; preds = %19
%25 = load i32, i32* %7
%26 = trunc i32 %25 to i8
%27 = load i8*, i8** %5
%28 = getelementptr inbounds i8, i8* %27, i32 1
store i8* %28, i8** %5
store i8 %26, i8* %27
br label %19
29: ; preds = %19
%30 = load i32*, i32** %6
%31 = call i32 @fclose(i32* %30)
%32 = load i8*, i8** %5
store i8* %32, i8** %3
br label %33
33: ; preds = %29, %14
%34 = load i8*, i8** %3
ret i8* %34
}

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