#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*/ buf;

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ close(int);
int open(char const *, int /*<<< orphan*/);
int read(int, char *, int);
char *get_acpi_file(const char *file) {
  int fd;
  int end;
  static char buf[1024];
  fd = open(file, O_RDONLY);
  if (fd == -1)
    return NULL;
  end = read(fd, buf, sizeof(buf));
  buf[end - 1] = '\0';
  close(fd);
  return buf;
}


x86 assembly (clang, -O0):
<get_acpi_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2ea1(%rip),%rax
mov    (%rax),%esi
call   1050 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    1168 <get_acpi_file+0x38>
movq   $0x0,-0x8(%rbp)
jmp    11a6 <get_acpi_file+0x76>
mov    -0x14(%rbp),%edi
lea    0x2ede(%rip),%rsi
mov    $0x400,%edx
call   1040 <read@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
sub    $0x1,%eax
movslq %eax,%rcx
lea    0x2ec1(%rip),%rax
movb   $0x0,(%rax,%rcx,1)
mov    -0x14(%rbp),%edi
call   1030 <close@plt>
lea    0x2eae(%rip),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_acpi_file>:
push   %rbp
push   %rbx
push   %rax
mov    0x2eae(%rip),%rax
mov    (%rax),%esi
call   1050 <open@plt>
cmp    $0xffffffff,%eax
je     116e <get_acpi_file+0x3e>
mov    %eax,%ebp
lea    0x2f01(%rip),%rbx
mov    %eax,%edi
mov    %rbx,%rsi
mov    $0x400,%edx
call   1040 <read@plt>
cltq
movb   $0x0,-0x1(%rax,%rbx,1)
mov    %ebp,%edi
call   1030 <close@plt>
jmp    1170 <get_acpi_file+0x40>
xor    %ebx,%ebx
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@get_acpi_file.buf = internal global [1024 x i8] zeroinitializer
@O_RDONLY = global i32 0
define i8* @get_acpi_file(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
store i8* %0, i8** %3
%6 = load i8*, i8** %3
%7 = load i32, i32* @O_RDONLY
%8 = call i32 @open(i8* %6, i32 %7)
store i32 %8, i32* %4
%9 = load i32, i32* %4
%10 = icmp eq i32 %9, -1
br i1 %10, label %11, label %12
11: ; preds = %1
store i8* null, i8** %2
br label %21
12: ; preds = %1
%13 = load i32, i32* %4
%14 = call i32 @read(i32 %13, i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @get_acpi_file.buf, i64 0, i64 0), i32 1024)
store i32 %14, i32* %5
%15 = load i32, i32* %5
%16 = sub nsw i32 %15, 1
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds [1024 x i8], [1024 x i8]* @get_acpi_file.buf, i64 0, i64 %17
store i8 0, i8* %18
%19 = load i32, i32* %4
%20 = call i32 @close(i32 %19)
store i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @get_acpi_file.buf, i64 0, i64 0), i8** %2
br label %21
21: ; preds = %12, %11
%22 = load i8*, i8** %2
ret i8* %22
}

LLVM IR (-O2):
@get_acpi_file.buf = internal global [1024 x i8] zeroinitializer
@O_RDONLY = global i32 0
define i8* @get_acpi_file(i8* nocapture %0) {
%2 = load i32, i32* @O_RDONLY
%3 = tail call i32 @open(i8* %0, i32 %2)
%4 = icmp eq i32 %3, -1
br i1 %4, label %11, label %5
5: ; preds = %1
%6 = tail call i32 @read(i32 %3, i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @get_acpi_file.buf, i64 0, i64 0), i32 1024)
%7 = add nsw i32 %6, -1
%8 = sext i32 %7 to i64
%9 = getelementptr inbounds [1024 x i8], [1024 x i8]* @get_acpi_file.buf, i64 0, i64 %8
store i8 0, i8* %9
%10 = tail call i32 @close(i32 %3)
br label %11
11: ; preds = %1, %5
%12 = phi i8* [ getelementptr inbounds ([1024 x i8], [1024 x i8]* @get_acpi_file.buf, i64 0, i64 0), %5 ], [ null, %1 ]
ret i8* %12
}