#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*/ error(int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ fscanf(int /*<<< orphan*/ *, char *, char *);
char *malloc(int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char *);
char *file_to_string(char *read_file) {
  char *buffer;
  FILE *file;
  buffer = malloc(100 * sizeof(char));
  if (buffer == NULL) {
    error(1);
  }
  file = fopen(read_file, "r");
  if (file == NULL) {
    perror("Error");
    free(buffer);
    exit(1);
  } else {
    fscanf(file, "%s", buffer);
    printf("CONTENT: %s\n", buffer);
    fclose(file);
  }
  return buffer;
}


x86 assembly (clang, -O0):
<file_to_string>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    $0x64,%edi
call   1070 <malloc@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11bf <file_to_string+0x2f>
mov    $0x1,%edi
call   1080 <error@plt>
mov    -0x8(%rbp),%rdi
lea    0xe3a(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11fd <file_to_string+0x6d>
lea    0xe1b(%rip),%rdi
call   10a0 <perror@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    0xdfa(%rip),%rsi
call   1060 <fscanf@plt>
mov    -0x10(%rbp),%rsi
lea    0xded(%rip),%rdi
call   1050 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<file_to_string>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r14
mov    $0x64,%edi
call   1070 <malloc@plt>
mov    %rax,%r15
test   %rax,%rax
jne    11b4 <file_to_string+0x24>
mov    $0x1,%edi
call   1080 <error@plt>
lea    0xe49(%rip),%rsi
mov    %r14,%rdi
call   1090 <fopen@plt>
test   %rax,%rax
je     11fd <file_to_string+0x6d>
mov    %rax,%rbx
lea    0xe34(%rip),%rsi
mov    %rax,%rdi
mov    %r15,%rdx
call   1060 <fscanf@plt>
lea    0xe25(%rip),%rdi
mov    %r15,%rsi
call   1050 <printf@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
mov    %r15,%rax
pop    %rbx
pop    %r14
pop    %r15
ret
lea    0xdfc(%rip),%rdi
call   10a0 <perror@plt>
mov    %r15,%rdi
call   1030 <free@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [6 x i8] c"Error\00"
@.str.2 = [3 x i8] c"%s\00"
@.str.3 = [13 x i8] c"CONTENT: %s\0A\00"
define i8* @file_to_string(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i32*
store i8* %0, i8** %2
%5 = call i8* @malloc(i32 100)
store i8* %5, i8** %3
%6 = load i8*, i8** %3
%7 = icmp eq i8* %6, null
br i1 %7, label %8, label %10
8: ; preds = %1
%9 = call i32 @error(i32 1)
br label %10
10: ; preds = %8, %1
%11 = load i8*, i8** %2
%12 = call i32* @fopen(i8* %11, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %12, i32** %4
%13 = load i32*, i32** %4
%14 = icmp eq i32* %13, null
br i1 %14, label %15, label %20
15: ; preds = %10
%16 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%17 = load i8*, i8** %3
%18 = call i32 @free(i8* %17)
%19 = call i32 @exit(i32 1)
unreachable
20: ; preds = %10
%21 = load i32*, i32** %4
%22 = load i8*, i8** %3
%23 = call i32 @fscanf(i32* %21, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %22)
%24 = load i8*, i8** %3
%25 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), i8* %24)
%26 = load i32*, i32** %4
%27 = call i32 @fclose(i32* %26)
br label %28
28: ; preds = %20
%29 = load i8*, i8** %3
ret i8* %29
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [6 x i8] c"Error\00"
@.str.2 = [3 x i8] c"%s\00"
@.str.3 = [13 x i8] c"CONTENT: %s\0A\00"
define i8* @file_to_string(i8* nocapture %0) {
%2 = tail call dereferenceable_or_null(100) i8* @malloc(i32 100)
%3 = icmp eq i8* %2, null
br i1 %3, label %4, label %6
4: ; preds = %1
%5 = tail call i32 @error(i32 1)
br label %6
6: ; preds = %4, %1
%7 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%8 = icmp eq i32* %7, null
br i1 %8, label %9, label %13
9: ; preds = %6
%10 = tail call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%11 = tail call i32 @free(i8* %2)
%12 = tail call i32 @exit(i32 1)
unreachable
13: ; preds = %6
%14 = tail call i32 @fscanf(i32* %7, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %2)
%15 = tail call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), i8* %2)
%16 = tail call i32 @fclose(i32* %7)
ret i8* %2
}