#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 */
struct stat {
  int /*<<< orphan*/ st_mode;
};

/* Variables and functions */
int /*<<< orphan*/ ENOTBLK;
int /*<<< orphan*/ S_ISBLK(int /*<<< orphan*/);
int /*<<< orphan*/ _IO(char, int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int fstat(int, struct stat *);
int ioctl(int, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int nvme_opal_unlock(int fd) {
  static struct stat nvme_stat;
  int err = fstat(fd, &nvme_stat);
  if (err < 0)
    return err;
  if (!S_ISBLK(nvme_stat.st_mode)) {
    fprintf(stderr, "Error: requesting opal-unlock from non-block device\n");
    exit(ENOTBLK);
  }
  return ioctl(fd, _IO('N', 0X47));
}


x86 assembly (clang, -O0):
<nvme_opal_unlock>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
mov    -0x8(%rbp),%edi
lea    0x2edf(%rip),%rsi
call   1080 <fstat@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jge    1192 <nvme_opal_unlock+0x32>
mov    -0xc(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11eb <nvme_opal_unlock+0x8b>
mov    0x2ebc(%rip),%edi
call   1060 <S_ISBLK@plt>
cmp    $0x0,%eax
jne    11c9 <nvme_opal_unlock+0x69>
mov    0x2e33(%rip),%rax
mov    (%rax),%edi
lea    0xe4a(%rip),%rsi
call   1050 <fprintf@plt>
mov    0x2e16(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
mov    -0x8(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    $0x4e,%edi
mov    $0x47,%esi
call   1030 <_IO@plt>
mov    -0x10(%rbp),%edi
mov    %eax,%esi
call   1040 <ioctl@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<nvme_opal_unlock>:
push   %rbx
mov    %edi,%ebx
lea    0x2eea(%rip),%rsi
call   1080 <fstat@plt>
test   %eax,%eax
js     119b <nvme_opal_unlock+0x3b>
mov    0x2edb(%rip),%edi
call   1060 <S_ISBLK@plt>
test   %eax,%eax
je     119d <nvme_opal_unlock+0x3d>
mov    $0x4e,%edi
mov    $0x47,%esi
call   1030 <_IO@plt>
mov    %ebx,%edi
mov    %eax,%esi
pop    %rbx
jmp    1040 <ioctl@plt>
pop    %rbx
ret
mov    0x2e3c(%rip),%rax
mov    (%rax),%edi
lea    0xe53(%rip),%rsi
call   1050 <fprintf@plt>
mov    0x2e1f(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>

LLVM IR (-O0):
%struct.stat = type { i32 }
@nvme_opal_unlock.nvme_stat = internal global %struct.stat zeroinitializer
@stderr = global i32 0
@.str = [53 x i8] c"Error: requesting opal-unlock from non-block device\0A\00"
@ENOTBLK = global i32 0
define i32 @nvme_opal_unlock(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 %0, i32* %3
%5 = load i32, i32* %3
%6 = call i32 @fstat(i32 %5, %struct.stat* @nvme_opal_unlock.nvme_stat)
store i32 %6, i32* %4
%7 = load i32, i32* %4
%8 = icmp slt i32 %7, 0
br i1 %8, label %9, label %11
9: ; preds = %1
%10 = load i32, i32* %4
store i32 %10, i32* %2
br label %24
11: ; preds = %1
%12 = load i32, i32* getelementptr inbounds (%struct.stat, %struct.stat* @nvme_opal_unlock.nvme_stat, i32 0, i32 0)
%13 = call i32 @S_ISBLK(i32 %12)
%14 = icmp ne i32 %13, 0
br i1 %14, label %20, label %15
15: ; preds = %11
%16 = load i32, i32* @stderr
%17 = call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str, i64 0, i64 0))
%18 = load i32, i32* @ENOTBLK
%19 = call i32 @exit(i32 %18)
unreachable
20: ; preds = %11
%21 = load i32, i32* %3
%22 = call i32 @_IO(i8 signext 78, i32 71)
%23 = call i32 @ioctl(i32 %21, i32 %22)
store i32 %23, i32* %2
br label %24
24: ; preds = %20, %9
%25 = load i32, i32* %2
ret i32 %25
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@nvme_opal_unlock.nvme_stat = internal global %struct.stat zeroinitializer
@stderr = global i32 0
@.str = [53 x i8] c"Error: requesting opal-unlock from non-block device\0A\00"
@ENOTBLK = global i32 0
define i32 @nvme_opal_unlock(i32 %0) {
%2 = tail call i32 @fstat(i32 %0, %struct.stat* @nvme_opal_unlock.nvme_stat)
%3 = icmp slt i32 %2, 0
br i1 %3, label %16, label %4
4: ; preds = %1
%5 = load i32, i32* getelementptr inbounds (%struct.stat, %struct.stat* @nvme_opal_unlock.nvme_stat, i64 0, i32 0)
%6 = tail call i32 @S_ISBLK(i32 %5)
%7 = icmp eq i32 %6, 0
br i1 %7, label %8, label %13
8: ; preds = %4
%9 = load i32, i32* @stderr
%10 = tail call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str, i64 0, i64 0))
%11 = load i32, i32* @ENOTBLK
%12 = tail call i32 @exit(i32 %11)
unreachable
13: ; preds = %4
%14 = tail call i32 @_IO(i8 signext 78, i32 71)
%15 = tail call i32 @ioctl(i32 %0, i32 %14)
br label %16
16: ; preds = %1, %13
%17 = phi i32 [ %15, %13 ], [ %2, %1 ]
ret i32 %17
}