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

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ close(int);
int open_file(char *, char *, int /*<<< orphan*/);
int read_from_fd(int, char *, size_t);
int read_from_file(char *prefix, char *path, char *buf, size_t count) {
  int fd;
  int rv;
  fd = open_file(prefix, path, O_RDONLY);
  if (fd < 0)
    return fd;
  rv = read_from_fd(fd, buf, count);
  close(fd);
  return rv;
}


x86 assembly (clang, -O0):
<read_from_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    0x2e91(%rip),%rax
mov    (%rax),%edx
call   1030 <open_file@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
jge    1176 <read_from_file+0x46>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1197 <read_from_file+0x67>
mov    -0x2c(%rbp),%edi
mov    -0x20(%rbp),%rsi
mov    -0x28(%rbp),%rdx
call   1050 <read_from_fd@plt>
mov    %eax,-0x30(%rbp)
mov    -0x2c(%rbp),%edi
call   1040 <close@plt>
mov    -0x30(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_from_file>:
push   %rbp
push   %r14
push   %rbx
mov    %rcx,%r14
mov    %rdx,%rbx
mov    0x2ea7(%rip),%rax
mov    (%rax),%edx
call   1030 <open_file@plt>
mov    %eax,%ebp
test   %eax,%eax
js     1168 <read_from_file+0x38>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r14,%rdx
call   1050 <read_from_fd@plt>
mov    %eax,%ebx
mov    %ebp,%edi
call   1040 <close@plt>
mov    %ebx,%eax
jmp    116a <read_from_file+0x3a>
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@O_RDONLY = global i32 0
define i32 @read_from_file(i8* %0, i8* %1, i8* %2, i64 %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i64
%10 = alloca i32
%11 = alloca i32
store i8* %0, i8** %6
store i8* %1, i8** %7
store i8* %2, i8** %8
store i64 %3, i64* %9
%12 = load i8*, i8** %6
%13 = load i8*, i8** %7
%14 = load i32, i32* @O_RDONLY
%15 = call i32 @open_file(i8* %12, i8* %13, i32 %14)
store i32 %15, i32* %10
%16 = load i32, i32* %10
%17 = icmp slt i32 %16, 0
br i1 %17, label %18, label %20
18: ; preds = %4
%19 = load i32, i32* %10
store i32 %19, i32* %5
br label %28
20: ; preds = %4
%21 = load i32, i32* %10
%22 = load i8*, i8** %8
%23 = load i64, i64* %9
%24 = call i32 @read_from_fd(i32 %21, i8* %22, i64 %23)
store i32 %24, i32* %11
%25 = load i32, i32* %10
%26 = call i32 @close(i32 %25)
%27 = load i32, i32* %11
store i32 %27, i32* %5
br label %28
28: ; preds = %20, %18
%29 = load i32, i32* %5
ret i32 %29
}

LLVM IR (-O2):
@O_RDONLY = global i32 0
define i32 @read_from_file(i8* %0, i8* %1, i8* %2, i64 %3) {
%5 = load i32, i32* @O_RDONLY
%6 = tail call i32 @open_file(i8* %0, i8* %1, i32 %5)
%7 = icmp slt i32 %6, 0
br i1 %7, label %11, label %8
8: ; preds = %4
%9 = tail call i32 @read_from_fd(i32 %6, i8* %2, i64 %3)
%10 = tail call i32 @close(i32 %6)
br label %11
11: ; preds = %4, %8
%12 = phi i32 [ %9, %8 ], [ %6, %4 ]
ret i32 %12
}