#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_RDWR;
int /*<<< orphan*/ errno;
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ strerror(int /*<<< orphan*/);
int /*<<< orphan*/ warnx(char *, char *, ...);
int open_pkey_device(bool verbose) {
  int pkey_fd;
  pkey_fd = open("/dev/pkey", O_RDWR);
  if (pkey_fd < 0) {
    warnx("File '%s:' %s\nEnsure that the 'pkey' kernel module "
          "is loaded",
          "/dev/pkey", strerror(errno));
    return -1;
  }
  do {
    if (verbose)
      warnx("Device '%s' has been opened successfully", "/dev/pkey");
  } while (0);
  return pkey_fd;
}


x86 assembly (clang, -O0):
<open_pkey_device>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
mov    0x2ea6(%rip),%rax
mov    (%rax),%esi
lea    0xeb5(%rip),%rdi
call   1040 <open@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jge    118e <open_pkey_device+0x5e>
mov    0x2e74(%rip),%rax
mov    (%rax),%edi
call   1050 <strerror@plt>
mov    %eax,%edx
lea    0xe96(%rip),%rdi
lea    0xe85(%rip),%rsi
mov    $0x0,%al
call   1030 <warnx@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11bd <open_pkey_device+0x8d>
jmp    1193 <open_pkey_device+0x63>
cmpl   $0x0,-0x8(%rbp)
je     11b2 <open_pkey_device+0x82>
lea    0xea3(%rip),%rdi
lea    0xe55(%rip),%rsi
mov    $0x0,%al
call   1030 <warnx@plt>
jmp    11b7 <open_pkey_device+0x87>
mov    -0xc(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<open_pkey_device>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebp
mov    0x2eac(%rip),%rax
mov    (%rax),%esi
lea    0xebb(%rip),%rdi
call   1040 <open@plt>
test   %eax,%eax
js     116b <open_pkey_device+0x3b>
mov    %eax,%ebx
test   %ebp,%ebp
je     1195 <open_pkey_device+0x65>
lea    0xeec(%rip),%rdi
lea    0xe9e(%rip),%rsi
xor    %eax,%eax
call   1030 <warnx@plt>
jmp    1195 <open_pkey_device+0x65>
mov    0x2e66(%rip),%rax
mov    (%rax),%edi
call   1050 <strerror@plt>
lea    0xe8a(%rip),%rdi
lea    0xe79(%rip),%rsi
mov    %eax,%edx
xor    %eax,%eax
call   1030 <warnx@plt>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [10 x i8] c"/dev/pkey\00"
@O_RDWR = global i32 0
@.str.1 = [61 x i8] c"File '%s:' %s\0AEnsure that the 'pkey' kernel module is loaded\00"
@errno = global i32 0
@.str.2 = [41 x i8] c"Device '%s' has been opened successfully\00"
define i32 @open_pkey_device(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 %0, i32* %3
%5 = load i32, i32* @O_RDWR
%6 = call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %5)
store i32 %6, i32* %4
%7 = load i32, i32* %4
%8 = icmp slt i32 %7, 0
br i1 %8, label %9, label %13
9: ; preds = %1
%10 = load i32, i32* @errno
%11 = call i32 @strerror(i32 %10)
%12 = call i32 (i8*, i8*, ...) @warnx(i8* getelementptr inbounds ([61 x i8], [61 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %11)
store i32 -1, i32* %2
br label %22
13: ; preds = %1
br label %14
14: ; preds = %13
%15 = load i32, i32* %3
%16 = icmp ne i32 %15, 0
br i1 %16, label %17, label %19
17: ; preds = %14
%18 = call i32 (i8*, i8*, ...) @warnx(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
br label %19
19: ; preds = %17, %14
br label %20
20: ; preds = %19
%21 = load i32, i32* %4
store i32 %21, i32* %2
br label %22
22: ; preds = %20, %9
%23 = load i32, i32* %2
ret i32 %23
}

LLVM IR (-O2):
@.str = [10 x i8] c"/dev/pkey\00"
@O_RDWR = global i32 0
@.str.1 = [61 x i8] c"File '%s:' %s\0AEnsure that the 'pkey' kernel module is loaded\00"
@errno = global i32 0
@.str.2 = [41 x i8] c"Device '%s' has been opened successfully\00"
define i32 @open_pkey_device(i32 %0) {
%2 = load i32, i32* @O_RDWR
%3 = tail call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %2)
%4 = icmp slt i32 %3, 0
br i1 %4, label %5, label %9
5: ; preds = %1
%6 = load i32, i32* @errno
%7 = tail call i32 @strerror(i32 %6)
%8 = tail call i32 (i8*, i8*, ...) @warnx(i8* getelementptr inbounds ([61 x i8], [61 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %7)
br label %13
9: ; preds = %1
%10 = icmp eq i32 %0, 0
br i1 %10, label %13, label %11
11: ; preds = %9
%12 = tail call i32 (i8*, i8*, ...) @warnx(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
br label %13
13: ; preds = %9, %11, %5
%14 = phi i32 [ -1, %5 ], [ %3, %11 ], [ %3, %9 ]
ret i32 %14
}