#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 fill_buf(char *, size_t, int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *);
int open(char const *, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
ssize_t get_key(const char *keyfile, char *keybuf, size_t size) {
  int fd = 0;
  size_t count = 0, this_read = 0;
  if ((fd = open(keyfile, O_RDONLY)) == -1) {
    fprintf(stderr, "Unable to open keyfile: %s\n", keyfile);
    return -1;
  }
  return fill_buf(keybuf, size, fd);
}


x86 assembly (clang, -O0):
<get_key>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
movq   $0x0,-0x30(%rbp)
movq   $0x0,-0x38(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2e82(%rip),%rax
mov    (%rax),%esi
call   1050 <open@plt>
mov    %eax,-0x24(%rbp)
cmp    $0xffffffff,%eax
jne    119e <get_key+0x6e>
mov    0x2e58(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xe73(%rip),%rsi
call   1030 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11b1 <get_key+0x81>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x24(%rbp),%edx
call   1040 <fill_buf@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_key>:
push   %r15
push   %r14
push   %rbx
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%rbx
mov    0x2ea3(%rip),%rax
mov    (%rax),%esi
call   1050 <open@plt>
cmp    $0xffffffff,%eax
je     1163 <get_key+0x33>
mov    %r15,%rdi
mov    %r14,%rsi
mov    %eax,%edx
pop    %rbx
pop    %r14
pop    %r15
jmp    1040 <fill_buf@plt>
mov    0x2e6e(%rip),%rax
mov    (%rax),%edi
lea    0xe8d(%rip),%rsi
mov    %rbx,%rdx
call   1030 <fprintf@plt>
mov    $0xffffffff,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@O_RDONLY = global i32 0
@stderr = global i32 0
@.str = [28 x i8] c"Unable to open keyfile: %s\0A\00"
define i32 @get_key(i8* %0, i8* %1, i64 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i32
%9 = alloca i64
%10 = alloca i64
store i8* %0, i8** %5
store i8* %1, i8** %6
store i64 %2, i64* %7
store i32 0, i32* %8
store i64 0, i64* %9
store i64 0, i64* %10
%11 = load i8*, i8** %5
%12 = load i32, i32* @O_RDONLY
%13 = call i32 @open(i8* %11, i32 %12)
store i32 %13, i32* %8
%14 = icmp eq i32 %13, -1
br i1 %14, label %15, label %19
15: ; preds = %3
%16 = load i32, i32* @stderr
%17 = load i8*, i8** %5
%18 = call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i8* %17)
store i32 -1, i32* %4
br label %24
19: ; preds = %3
%20 = load i8*, i8** %6
%21 = load i64, i64* %7
%22 = load i32, i32* %8
%23 = call i32 @fill_buf(i8* %20, i64 %21, i32 %22)
store i32 %23, i32* %4
br label %24
24: ; preds = %19, %15
%25 = load i32, i32* %4
ret i32 %25
}

LLVM IR (-O2):
@O_RDONLY = global i32 0
@stderr = global i32 0
@.str = [28 x i8] c"Unable to open keyfile: %s\0A\00"
define i32 @get_key(i8* %0, i8* %1, i64 %2) {
%4 = load i32, i32* @O_RDONLY
%5 = tail call i32 @open(i8* %0, i32 %4)
%6 = icmp eq i32 %5, -1
br i1 %6, label %7, label %10
7: ; preds = %3
%8 = load i32, i32* @stderr
%9 = tail call i32 @fprintf(i32 %8, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i8* %0)
br label %12
10: ; preds = %3
%11 = tail call i32 @fill_buf(i8* %1, i64 %2, i32 %5)
br label %12
12: ; preds = %10, %7
%13 = phi i32 [ -1, %7 ], [ %11, %10 ]
ret i32 %13
}