#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 ENOTBLK;
int /*<<< orphan*/ S_ISCHR(int /*<<< orphan*/);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int fstat(int, struct stat *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ stderr;
void nvme_verify_chr(int fd) {
  static struct stat nvme_stat;
  int err = fstat(fd, &nvme_stat);
  if (err < 0) {
    perror("fstat");
    exit(err);
  }
  if (!S_ISCHR(nvme_stat.st_mode)) {
    fprintf(stderr, "Error: requesting reset on non-controller handle\n");
    exit(ENOTBLK);
  }
}


x86 assembly (clang, -O0):
<nvme_verify_chr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%edi
lea    0x2ee7(%rip),%rsi
call   1070 <fstat@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jge    118b <nvme_verify_chr+0x3b>
lea    0xe82(%rip),%rdi
call   1050 <perror@plt>
mov    -0x8(%rbp),%edi
call   1060 <exit@plt>
mov    0x2ebb(%rip),%edi
call   1040 <S_ISCHR@plt>
cmp    $0x0,%eax
jne    11c2 <nvme_verify_chr+0x72>
mov    0x2e3a(%rip),%rax
mov    (%rax),%edi
lea    0xe57(%rip),%rsi
call   1030 <fprintf@plt>
mov    0x2e1d(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<nvme_verify_chr>:
push   %rbx
lea    0x2ef4(%rip),%rsi
call   1070 <fstat@plt>
test   %eax,%eax
js     1172 <nvme_verify_chr+0x22>
mov    0x2ee5(%rip),%edi
call   1040 <S_ISCHR@plt>
test   %eax,%eax
je     1187 <nvme_verify_chr+0x37>
pop    %rbx
ret
mov    %eax,%ebx
lea    0xe85(%rip),%rdi
call   1050 <perror@plt>
mov    %ebx,%edi
call   1060 <exit@plt>
mov    0x2e52(%rip),%rax
mov    (%rax),%edi
lea    0xe6f(%rip),%rsi
call   1030 <fprintf@plt>
mov    0x2e35(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>

LLVM IR (-O0):
%struct.stat = type { i32 }
@nvme_verify_chr.nvme_stat = internal global %struct.stat zeroinitializer
@.str = [6 x i8] c"fstat\00"
@stderr = global i32 0
@.str.1 = [50 x i8] c"Error: requesting reset on non-controller handle\0A\00"
@ENOTBLK = global i32 0
define void @nvme_verify_chr(i32 %0) {
%2 = alloca i32
%3 = alloca i32
store i32 %0, i32* %2
%4 = load i32, i32* %2
%5 = call i32 @fstat(i32 %4, %struct.stat* @nvme_verify_chr.nvme_stat)
store i32 %5, i32* %3
%6 = load i32, i32* %3
%7 = icmp slt i32 %6, 0
br i1 %7, label %8, label %12
8: ; preds = %1
%9 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%10 = load i32, i32* %3
%11 = call i32 @exit(i32 %10)
unreachable
12: ; preds = %1
%13 = load i32, i32* getelementptr inbounds (%struct.stat, %struct.stat* @nvme_verify_chr.nvme_stat, i32 0, i32 0)
%14 = call i32 @S_ISCHR(i32 %13)
%15 = icmp ne i32 %14, 0
br i1 %15, label %21, label %16
16: ; preds = %12
%17 = load i32, i32* @stderr
%18 = call i32 @fprintf(i32 %17, i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.1, i64 0, i64 0))
%19 = load i32, i32* @ENOTBLK
%20 = call i32 @exit(i32 %19)
unreachable
21: ; preds = %12
ret void
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@nvme_verify_chr.nvme_stat = internal global %struct.stat zeroinitializer
@.str = [6 x i8] c"fstat\00"
@stderr = global i32 0
@.str.1 = [50 x i8] c"Error: requesting reset on non-controller handle\0A\00"
@ENOTBLK = global i32 0
define void @nvme_verify_chr(i32 %0) {
%2 = tail call i32 @fstat(i32 %0, %struct.stat* @nvme_verify_chr.nvme_stat)
%3 = icmp slt i32 %2, 0
br i1 %3, label %4, label %7
4: ; preds = %1
%5 = tail call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%6 = tail call i32 @exit(i32 %2)
unreachable
7: ; preds = %1
%8 = load i32, i32* getelementptr inbounds (%struct.stat, %struct.stat* @nvme_verify_chr.nvme_stat, i64 0, i32 0)
%9 = tail call i32 @S_ISCHR(i32 %8)
%10 = icmp eq i32 %9, 0
br i1 %10, label %11, label %16
11: ; preds = %7
%12 = load i32, i32* @stderr
%13 = tail call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.1, i64 0, i64 0))
%14 = load i32, i32* @ENOTBLK
%15 = tail call i32 @exit(i32 %14)
unreachable
16: ; preds = %7
ret void
}