#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 ssize_t;

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ close(int);
int open(char const *, int /*<<< orphan*/);
int read(int, unsigned char *, int);
int /*<<< orphan*/ warn_text_ui(char *);
ssize_t load_file(const char *filename, unsigned char *frame) {
  ssize_t n;
  int fd = open(filename, O_RDONLY);
  if (fd < 0) {
    warn_text_ui("Cannot open");
    return -1;
  }
  n = read(fd, frame, 128);
  if (n < 0) {
    warn_text_ui("Read error");
    return -1;
  }
  close(fd);
  return n;
}


x86 assembly (clang, -O0):
<load_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2e8d(%rip),%rax
mov    (%rax),%esi
call   1060 <open@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
jge    1187 <load_file+0x47>
lea    0xe8a(%rip),%rdi
call   1030 <warn_text_ui@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11cb <load_file+0x8b>
mov    -0x20(%rbp),%edi
mov    -0x18(%rbp),%rsi
mov    $0x80,%edx
call   1050 <read@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    11bd <load_file+0x7d>
lea    0xe60(%rip),%rdi
call   1030 <warn_text_ui@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11cb <load_file+0x8b>
mov    -0x20(%rbp),%edi
call   1040 <close@plt>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<load_file>:
push   %rbp
push   %rbx
push   %rax
mov    %rsi,%rbp
mov    0x2e9b(%rip),%rax
mov    (%rax),%esi
call   1060 <open@plt>
test   %eax,%eax
js     1178 <load_file+0x38>
mov    %eax,%ebx
mov    %eax,%edi
mov    %rbp,%rsi
mov    $0x80,%edx
call   1050 <read@plt>
test   %eax,%eax
js     1181 <load_file+0x41>
mov    %eax,%ebp
mov    %ebx,%edi
call   1040 <close@plt>
jmp    1192 <load_file+0x52>
lea    0xe81(%rip),%rdi
jmp    1188 <load_file+0x48>
lea    0xe84(%rip),%rdi
call   1030 <warn_text_ui@plt>
mov    $0xffffffff,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@O_RDONLY = global i32 0
@.str = [12 x i8] c"Cannot open\00"
@.str.1 = [11 x i8] c"Read error\00"
define i32 @load_file(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
%8 = load i8*, i8** %4
%9 = load i32, i32* @O_RDONLY
%10 = call i32 @open(i8* %8, i32 %9)
store i32 %10, i32* %7
%11 = load i32, i32* %7
%12 = icmp slt i32 %11, 0
br i1 %12, label %13, label %15
13: ; preds = %2
%14 = call i32 @warn_text_ui(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %3
br label %27
15: ; preds = %2
%16 = load i32, i32* %7
%17 = load i8*, i8** %5
%18 = call i32 @read(i32 %16, i8* %17, i32 128)
store i32 %18, i32* %6
%19 = load i32, i32* %6
%20 = icmp slt i32 %19, 0
br i1 %20, label %21, label %23
21: ; preds = %15
%22 = call i32 @warn_text_ui(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %3
br label %27
23: ; preds = %15
%24 = load i32, i32* %7
%25 = call i32 @close(i32 %24)
%26 = load i32, i32* %6
store i32 %26, i32* %3
br label %27
27: ; preds = %23, %21, %13
%28 = load i32, i32* %3
ret i32 %28
}

LLVM IR (-O2):
@O_RDONLY = global i32 0
@.str = [12 x i8] c"Cannot open\00"
@.str.1 = [11 x i8] c"Read error\00"
define i32 @load_file(i8* nocapture %0, i8* nocapture %1) {
%3 = load i32, i32* @O_RDONLY
%4 = tail call i32 @open(i8* %0, i32 %3)
%5 = icmp slt i32 %4, 0
br i1 %5, label %6, label %8
6: ; preds = %2
%7 = tail call i32 @warn_text_ui(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
br label %15
8: ; preds = %2
%9 = tail call i32 @read(i32 %4, i8* %1, i32 128)
%10 = icmp slt i32 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %8
%12 = tail call i32 @warn_text_ui(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
br label %15
13: ; preds = %8
%14 = tail call i32 @close(i32 %4)
br label %15
15: ; preds = %13, %11, %6
%16 = phi i32 [ -1, %6 ], [ -1, %11 ], [ %9, %13 ]
ret i32 %16
}