#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*/ *fopen(char const *, char *);
int fread(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ free(char *);
char *malloc(int);
char *get_acpi_content(const char *file) {
  FILE *input = NULL;
  char *buf = NULL;
  int read = 0;
  if ((buf = malloc(1024 + 1)) == NULL)
    return NULL;
  if ((input = fopen(file, "r")) == NULL) {
    free(buf);
    return NULL;
  }
  read = fread(buf, 1, 1024, input);
  if (read > 0)
    buf[read - 1] = '\0';
  else
    buf[0] = '\0';
  fclose(input);
  return buf;
}


x86 assembly (clang, -O0):
<get_acpi_content>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    $0x401,%edi
call   1060 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    1198 <get_acpi_content+0x48>
movq   $0x0,-0x8(%rbp)
jmp    121e <get_acpi_content+0xce>
mov    -0x10(%rbp),%rdi
lea    0xe5d(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    11cc <get_acpi_content+0x7c>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x8(%rbp)
jmp    121e <get_acpi_content+0xce>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rcx
mov    $0x1,%esi
mov    $0x400,%edx
call   1040 <fread@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jle    1206 <get_acpi_content+0xb6>
mov    -0x20(%rbp),%rax
mov    -0x24(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
jmp    120d <get_acpi_content+0xbd>
mov    -0x20(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x18(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_acpi_content>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
mov    $0x401,%edi
call   1060 <malloc@plt>
test   %rax,%rax
je     11b5 <get_acpi_content+0x65>
mov    %rax,%rbx
lea    0xe90(%rip),%rsi
mov    %r14,%rdi
call   1070 <fopen@plt>
test   %rax,%rax
je     11ad <get_acpi_content+0x5d>
mov    %rax,%r14
mov    %rbx,%rdi
mov    $0x1,%esi
mov    $0x400,%edx
mov    %rax,%rcx
call   1040 <fread@plt>
lea    -0x1(%rax),%ecx
xor    %edx,%edx
test   %eax,%eax
cmovg  %ecx,%edx
movb   $0x0,(%rbx,%rdx,1)
mov    %r14,%rdi
call   1050 <fclose@plt>
jmp    11b7 <get_acpi_content+0x67>
mov    %rbx,%rdi
call   1030 <free@plt>
xor    %ebx,%ebx
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
define i8* @get_acpi_content(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca i8*
%6 = alloca i32
store i8* %0, i8** %3
store i32* null, i32** %4
store i8* null, i8** %5
store i32 0, i32* %6
%7 = call i8* @malloc(i32 1025)
store i8* %7, i8** %5
%8 = icmp eq i8* %7, null
br i1 %8, label %9, label %10
9: ; preds = %1
store i8* null, i8** %2
br label %36
10: ; preds = %1
%11 = load i8*, i8** %3
%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 = icmp eq i32* %12, null
br i1 %13, label %14, label %17
14: ; preds = %10
%15 = load i8*, i8** %5
%16 = call i32 @free(i8* %15)
store i8* null, i8** %2
br label %36
17: ; preds = %10
%18 = load i8*, i8** %5
%19 = load i32*, i32** %4
%20 = call i32 @fread(i8* %18, i32 1, i32 1024, i32* %19)
store i32 %20, i32* %6
%21 = load i32, i32* %6
%22 = icmp sgt i32 %21, 0
br i1 %22, label %23, label %29
23: ; preds = %17
%24 = load i8*, i8** %5
%25 = load i32, i32* %6
%26 = sub nsw i32 %25, 1
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds i8, i8* %24, i64 %27
store i8 0, i8* %28
br label %32
29: ; preds = %17
%30 = load i8*, i8** %5
%31 = getelementptr inbounds i8, i8* %30, i64 0
store i8 0, i8* %31
br label %32
32: ; preds = %29, %23
%33 = load i32*, i32** %4
%34 = call i32 @fclose(i32* %33)
%35 = load i8*, i8** %5
store i8* %35, i8** %2
br label %36
36: ; preds = %32, %14, %9
%37 = load i8*, i8** %2
ret i8* %37
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
define noalias i8* @get_acpi_content(i8* nocapture %0) {
%2 = tail call dereferenceable_or_null(1025) i8* @malloc(i32 1025)
%3 = icmp eq i8* %2, null
br i1 %3, label %17, label %4
4: ; preds = %1
%5 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%6 = icmp eq i32* %5, null
br i1 %6, label %7, label %9
7: ; preds = %4
%8 = tail call i32 @free(i8* %2)
br label %17
9: ; preds = %4
%10 = tail call i32 @fread(i8* %2, i32 1, i32 1024, i32* %5)
%11 = icmp sgt i32 %10, 0
%12 = add nsw i32 %10, -1
%13 = select i1 %11, i32 %12, i32 0
%14 = zext i32 %13 to i64
%15 = getelementptr i8, i8* %2, i64 %14
store i8 0, i8* %15
%16 = tail call i32 @fclose(i32* %5)
br label %17
17: ; preds = %1, %9, %7
%18 = phi i8* [ null, %7 ], [ %2, %9 ], [ null, %1 ]
ret i8* %18
}