#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 */
char EOF;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
char fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
char *malloc(int);
char *realloc(char *, int);
char *get_file(char *fn) {
  FILE *f;
  char *buf = NULL;
  if ((f = fopen(fn, "r")) != NULL) {
    int bs = 100, i;
    char c;
    buf = malloc(bs);
    i = 0;
    buf[i] = '\0';
    while ((c = fgetc(f)) != EOF) {
      if (i > bs - 2) {
        bs += 100;
        buf = realloc(buf, bs);
      }
      buf[i] = c;
      i++;
      buf[i] = '\0';
    }
    fclose(f);
  }
  return (buf);
}


x86 assembly (clang, -O0):
<get_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
movq   $0x0,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe91(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
je     1224 <get_file+0xd4>
movl   $0x64,-0x1c(%rbp)
mov    -0x1c(%rbp),%edi
call   1050 <malloc@plt>
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x18(%rbp),%rax
movslq -0x20(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x10(%rbp),%rdi
call   1040 <fgetc@plt>
mov    %al,-0x21(%rbp)
movsbl %al,%eax
mov    0x2e2a(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
je     121b <get_file+0xcb>
mov    -0x20(%rbp),%eax
mov    -0x1c(%rbp),%ecx
sub    $0x2,%ecx
cmp    %ecx,%eax
jle    11f3 <get_file+0xa3>
mov    -0x1c(%rbp),%eax
add    $0x64,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%esi
call   1060 <realloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x21(%rbp),%dl
mov    -0x18(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
movslq -0x20(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
jmp    11a8 <get_file+0x58>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x18(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_file>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
lea    0xe9e(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     11a4 <get_file+0x54>
mov    %rax,%r14
mov    $0x64,%r15d
mov    $0x64,%edi
call   1050 <malloc@plt>
mov    %rax,%r12
movb   $0x0,(%rax)
mov    %r14,%rdi
call   1040 <fgetc@plt>
mov    0x2e54(%rip),%r13
cmp    0x0(%r13),%al
jne    11b9 <get_file+0x69>
mov    %r14,%rdi
call   1030 <fclose@plt>
jmp    11a7 <get_file+0x57>
xor    %r12d,%r12d
mov    %r12,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %eax,%ebx
xor    %ebp,%ebp
jmp    11de <get_file+0x8e>
nop
mov    %bl,(%r12,%rbp,1)
movb   $0x0,0x1(%r12,%rbp,1)
add    $0x1,%rbp
mov    %r14,%rdi
call   1040 <fgetc@plt>
mov    %eax,%ebx
cmp    0x0(%r13),%al
je     119a <get_file+0x4a>
lea    -0x2(%r15),%eax
cltq
cmp    %rax,%rbp
jle    11c0 <get_file+0x70>
add    $0x64,%r15d
mov    %r12,%rdi
mov    %r15d,%esi
call   1060 <realloc@plt>
mov    %rax,%r12
jmp    11c0 <get_file+0x70>

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@EOF = global i8 0
define i8* @get_file(i8* %0) {
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8
store i8* %0, i8** %2
store i8* null, i8** %4
%8 = load i8*, i8** %2
%9 = call i32* @fopen(i8* %8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %9, i32** %3
%10 = icmp ne i32* %9, null
br i1 %10, label %11, label %51
11: ; preds = %1
store i32 100, i32* %5
%12 = load i32, i32* %5
%13 = call i8* @malloc(i32 %12)
store i8* %13, i8** %4
store i32 0, i32* %6
%14 = load i8*, i8** %4
%15 = load i32, i32* %6
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds i8, i8* %14, i64 %16
store i8 0, i8* %17
br label %18
18: ; preds = %36, %11
%19 = load i32*, i32** %3
%20 = call signext i8 @fgetc(i32* %19)
store i8 %20, i8* %7
%21 = sext i8 %20 to i32
%22 = load i8, i8* @EOF
%23 = sext i8 %22 to i32
%24 = icmp ne i32 %21, %23
br i1 %24, label %25, label %48
25: ; preds = %18
%26 = load i32, i32* %6
%27 = load i32, i32* %5
%28 = sub nsw i32 %27, 2
%29 = icmp sgt i32 %26, %28
br i1 %29, label %30, label %36
30: ; preds = %25
%31 = load i32, i32* %5
%32 = add nsw i32 %31, 100
store i32 %32, i32* %5
%33 = load i8*, i8** %4
%34 = load i32, i32* %5
%35 = call i8* @realloc(i8* %33, i32 %34)
store i8* %35, i8** %4
br label %36
36: ; preds = %30, %25
%37 = load i8, i8* %7
%38 = load i8*, i8** %4
%39 = load i32, i32* %6
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds i8, i8* %38, i64 %40
store i8 %37, i8* %41
%42 = load i32, i32* %6
%43 = add nsw i32 %42, 1
store i32 %43, i32* %6
%44 = load i8*, i8** %4
%45 = load i32, i32* %6
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds i8, i8* %44, i64 %46
store i8 0, i8* %47
br label %18
48: ; preds = %18
%49 = load i32*, i32** %3
%50 = call i32 @fclose(i32* %49)
br label %51
51: ; preds = %48, %1
%52 = load i8*, i8** %4
ret i8* %52
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@EOF = global i8 0
define i8* @get_file(i8* nocapture %0) {
%2 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%3 = icmp eq i32* %2, null
br i1 %3, label %32, label %4
4: ; preds = %1
%5 = tail call dereferenceable_or_null(100) i8* @malloc(i32 100)
store i8 0, i8* %5
%6 = tail call signext i8 @fgetc(i32* %2)
%7 = load i8, i8* @EOF
%8 = icmp eq i8 %6, %7
br i1 %8, label %29, label %9
9: ; preds = %4, %20
%10 = phi i64 [ %24, %20 ], [ 0, %4 ]
%11 = phi i8 [ %26, %20 ], [ %6, %4 ]
%12 = phi i8* [ %22, %20 ], [ %5, %4 ]
%13 = phi i32 [ %21, %20 ], [ 100, %4 ]
%14 = add nsw i32 %13, -2
%15 = sext i32 %14 to i64
%16 = icmp sgt i64 %10, %15
br i1 %16, label %17, label %20
17: ; preds = %9
%18 = add nsw i32 %13, 100
%19 = tail call i8* @realloc(i8* %12, i32 %18)
br label %20
20: ; preds = %17, %9
%21 = phi i32 [ %18, %17 ], [ %13, %9 ]
%22 = phi i8* [ %19, %17 ], [ %12, %9 ]
%23 = getelementptr inbounds i8, i8* %22, i64 %10
store i8 %11, i8* %23
%24 = add nuw i64 %10, 1
%25 = getelementptr inbounds i8, i8* %22, i64 %24
store i8 0, i8* %25
%26 = tail call signext i8 @fgetc(i32* %2)
%27 = load i8, i8* @EOF
%28 = icmp eq i8 %26, %27
br i1 %28, label %29, label %9
29: ; preds = %20, %4
%30 = phi i8* [ %5, %4 ], [ %22, %20 ]
%31 = tail call i32 @fclose(i32* %2)
br label %32
32: ; preds = %29, %1
%33 = phi i8* [ %30, %29 ], [ null, %1 ]
ret i8* %33
}