#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 errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int fread(char *, int, size_t, int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
int read_file(FILE *fp, char *buff, size_t buff_sz, size_t *out_bytes) {
  int ret;
  ret = fread(buff, 1, buff_sz, fp);
  if (ret < 0) {
    fprintf(stderr, "Can't read data from file\n");
    return -errno;
  }
  *out_bytes = (size_t)ret;
  return 0;
}


x86 assembly (clang, -O0):
<read_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    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rdx
mov    -0x10(%rbp),%rcx
mov    $0x1,%esi
call   1030 <fread@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
jge    1183 <read_file+0x63>
mov    0x2e7e(%rip),%rax
mov    (%rax),%edi
lea    0xe95(%rip),%rsi
call   1040 <fprintf@plt>
xor    %eax,%eax
mov    0x2e5f(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x4(%rbp)
jmp    1195 <read_file+0x75>
movslq -0x2c(%rbp),%rcx
mov    -0x28(%rbp),%rax
mov    %rcx,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_file>:
push   %rbx
mov    %rcx,%rbx
mov    %rdi,%rcx
mov    %rsi,%rdi
mov    $0x1,%esi
call   1030 <fread@plt>
test   %eax,%eax
js     1141 <read_file+0x21>
mov    %eax,%eax
mov    %rax,(%rbx)
xor    %eax,%eax
pop    %rbx
ret
mov    0x2e98(%rip),%rax
mov    (%rax),%edi
lea    0xeaf(%rip),%rsi
call   1040 <fprintf@plt>
mov    0x2e7b(%rip),%rcx
xor    %eax,%eax
sub    (%rcx),%eax
pop    %rbx
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [27 x i8] c"Can't read data from file\0A\00"
@errno = global i32 0
define i32 @read_file(i32* %0, i8* %1, i64 %2, i64* %3) {
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i8*
%8 = alloca i64
%9 = alloca i64*
%10 = alloca i32
store i32* %0, i32** %6
store i8* %1, i8** %7
store i64 %2, i64* %8
store i64* %3, i64** %9
%11 = load i8*, i8** %7
%12 = load i64, i64* %8
%13 = load i32*, i32** %6
%14 = call i32 @fread(i8* %11, i32 1, i64 %12, i32* %13)
store i32 %14, i32* %10
%15 = load i32, i32* %10
%16 = icmp slt i32 %15, 0
br i1 %16, label %17, label %22
17: ; preds = %4
%18 = load i32, i32* @stderr
%19 = call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
%20 = load i32, i32* @errno
%21 = sub nsw i32 0, %20
store i32 %21, i32* %5
br label %26
22: ; preds = %4
%23 = load i32, i32* %10
%24 = sext i32 %23 to i64
%25 = load i64*, i64** %9
store i64 %24, i64* %25
store i32 0, i32* %5
br label %26
26: ; preds = %22, %17
%27 = load i32, i32* %5
ret i32 %27
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [27 x i8] c"Can't read data from file\0A\00"
@errno = global i32 0
define i32 @read_file(i32* nocapture %0, i8* nocapture %1, i64 %2, i64* nocapture writeonly %3) {
%5 = tail call i32 @fread(i8* %1, i32 1, i64 %2, i32* %0)
%6 = icmp slt i32 %5, 0
br i1 %6, label %7, label %12
7: ; preds = %4
%8 = load i32, i32* @stderr
%9 = tail call i32 @fprintf(i32 %8, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
%10 = load i32, i32* @errno
%11 = sub nsw i32 0, %10
br label %14
12: ; preds = %4
%13 = zext i32 %5 to i64
store i64 %13, i64* %3
br label %14
14: ; preds = %12, %7
%15 = phi i32 [ %11, %7 ], [ 0, %12 ]
ret i32 %15
}