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

/* Variables and functions */
scalar_t__ SCSI_DISK0_MAJOR;
scalar_t__ SCSI_DISK15_MAJOR;
scalar_t__ SCSI_DISK1_MAJOR;
scalar_t__ SCSI_DISK7_MAJOR;
scalar_t__ SCSI_DISK8_MAJOR;
scalar_t__ S_ISBLK(int /*<<< orphan*/);
scalar_t__ major(int /*<<< orphan*/);
int minor(int /*<<< orphan*/);
scalar_t__ stat(char const *, struct stat *);
int is_sd_device(const char *dev) {
  struct stat st;
  if (stat(dev, &st) < 0) {
    return -1;
  }
  return S_ISBLK(st.st_mode) &&
                 ((major(st.st_rdev)) == SCSI_DISK0_MAJOR ||
                  ((major(st.st_rdev)) >= SCSI_DISK1_MAJOR &&
                   (major(st.st_rdev)) <= SCSI_DISK7_MAJOR) ||
                  ((major(st.st_rdev)) >= SCSI_DISK8_MAJOR &&
                   (major(st.st_rdev)) <= SCSI_DISK15_MAJOR)) &&
                 (minor(st.st_rdev) & 0xf) == 0
             ? 1
             : 0;
}


x86 assembly (clang, -O0):
<is_sd_device>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   1050 <stat@plt>
cmp    $0x0,%rax
jge    116f <is_sd_device+0x2f>
movl   $0xffffffff,-0x4(%rbp)
jmp    1238 <is_sd_device+0xf8>
mov    -0x14(%rbp),%edi
call   1060 <S_ISBLK@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    $0x0,%rcx
mov    %al,-0x19(%rbp)
je     1225 <is_sd_device+0xe5>
mov    -0x18(%rbp),%edi
call   1040 <major@plt>
mov    0x2e50(%rip),%rcx
cmp    (%rcx),%rax
je     1211 <is_sd_device+0xd1>
mov    -0x18(%rbp),%edi
call   1040 <major@plt>
mov    0x2e30(%rip),%rcx
cmp    (%rcx),%rax
jl     11d1 <is_sd_device+0x91>
mov    -0x18(%rbp),%edi
call   1040 <major@plt>
mov    0x2df8(%rip),%rcx
cmp    (%rcx),%rax
jle    1211 <is_sd_device+0xd1>
mov    -0x18(%rbp),%edi
call   1040 <major@plt>
mov    %rax,%rcx
xor    %eax,%eax
mov    0x2de3(%rip),%rdx
cmp    (%rdx),%rcx
mov    %al,-0x19(%rbp)
jl     1225 <is_sd_device+0xe5>
mov    -0x18(%rbp),%edi
call   1040 <major@plt>
mov    %rax,%rcx
xor    %eax,%eax
mov    0x2dd3(%rip),%rdx
cmp    (%rdx),%rcx
mov    %al,-0x19(%rbp)
jg     1225 <is_sd_device+0xe5>
mov    -0x18(%rbp),%edi
call   1030 <minor@plt>
and    $0xf,%eax
cmp    $0x0,%eax
sete   %al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%dl
xor    %eax,%eax
mov    $0x1,%ecx
test   $0x1,%dl
cmovne %ecx,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<is_sd_device>:
push   %rbx
sub    $0x10,%rsp
lea    0x8(%rsp),%rsi
call   1050 <stat@plt>
test   %rax,%rax
js     118b <is_sd_device+0x4b>
mov    0xc(%rsp),%edi
call   1060 <S_ISBLK@plt>
xor    %ebx,%ebx
test   %rax,%rax
je     1190 <is_sd_device+0x50>
mov    0x8(%rsp),%edi
call   1040 <major@plt>
mov    0x2e74(%rip),%rcx
cmp    (%rcx),%rax
jne    1198 <is_sd_device+0x58>
mov    0x8(%rsp),%edi
call   1030 <minor@plt>
xor    %ebx,%ebx
test   $0xf,%al
sete   %bl
jmp    1190 <is_sd_device+0x50>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
ret
mov    0x8(%rsp),%edi
call   1040 <major@plt>
mov    0x2e38(%rip),%rcx
cmp    (%rcx),%rax
jl     11c2 <is_sd_device+0x82>
mov    0x8(%rsp),%edi
call   1040 <major@plt>
mov    0x2e03(%rip),%rcx
cmp    (%rcx),%rax
jle    1179 <is_sd_device+0x39>
mov    0x8(%rsp),%edi
call   1040 <major@plt>
mov    0x2df6(%rip),%rcx
cmp    (%rcx),%rax
jl     1190 <is_sd_device+0x50>
mov    0x8(%rsp),%edi
call   1040 <major@plt>
mov    0x2df1(%rip),%rcx
cmp    (%rcx),%rax
jle    1179 <is_sd_device+0x39>
jmp    1190 <is_sd_device+0x50>

LLVM IR (-O0):
%struct.stat = type { i32, i32 }
@SCSI_DISK0_MAJOR = global i64 0
@SCSI_DISK1_MAJOR = global i64 0
@SCSI_DISK7_MAJOR = global i64 0
@SCSI_DISK8_MAJOR = global i64 0
@SCSI_DISK15_MAJOR = global i64 0
define i32 @is_sd_device(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca %struct.stat
store i8* %0, i8** %3
%5 = load i8*, i8** %3
%6 = call i64 @stat(i8* %5, %struct.stat* %4)
%7 = icmp slt i64 %6, 0
br i1 %7, label %8, label %9
8: ; preds = %1
store i32 -1, i32* %2
br label %54
9: ; preds = %1
%10 = getelementptr inbounds %struct.stat, %struct.stat* %4, i32 0, i32 1
%11 = load i32, i32* %10
%12 = call i64 @S_ISBLK(i32 %11)
%13 = icmp ne i64 %12, 0
br i1 %13, label %14, label %50
14: ; preds = %9
%15 = getelementptr inbounds %struct.stat, %struct.stat* %4, i32 0, i32 0
%16 = load i32, i32* %15
%17 = call i64 @major(i32 %16)
%18 = load i64, i64* @SCSI_DISK0_MAJOR
%19 = icmp eq i64 %17, %18
br i1 %19, label %44, label %20
20: ; preds = %14
%21 = getelementptr inbounds %struct.stat, %struct.stat* %4, i32 0, i32 0
%22 = load i32, i32* %21
%23 = call i64 @major(i32 %22)
%24 = load i64, i64* @SCSI_DISK1_MAJOR
%25 = icmp sge i64 %23, %24
br i1 %25, label %26, label %32
26: ; preds = %20
%27 = getelementptr inbounds %struct.stat, %struct.stat* %4, i32 0, i32 0
%28 = load i32, i32* %27
%29 = call i64 @major(i32 %28)
%30 = load i64, i64* @SCSI_DISK7_MAJOR
%31 = icmp sle i64 %29, %30
br i1 %31, label %44, label %32
32: ; preds = %26, %20
%33 = getelementptr inbounds %struct.stat, %struct.stat* %4, i32 0, i32 0
%34 = load i32, i32* %33
%35 = call i64 @major(i32 %34)
%36 = load i64, i64* @SCSI_DISK8_MAJOR
%37 = icmp sge i64 %35, %36
br i1 %37, label %38, label %50
38: ; preds = %32
%39 = getelementptr inbounds %struct.stat, %struct.stat* %4, i32 0, i32 0
%40 = load i32, i32* %39
%41 = call i64 @major(i32 %40)
%42 = load i64, i64* @SCSI_DISK15_MAJOR
%43 = icmp sle i64 %41, %42
br i1 %43, label %44, label %50
44: ; preds = %38, %26, %14
%45 = getelementptr inbounds %struct.stat, %struct.stat* %4, i32 0, i32 0
%46 = load i32, i32* %45
%47 = call i32 @minor(i32 %46)
%48 = and i32 %47, 15
%49 = icmp eq i32 %48, 0
br label %50
50: ; preds = %44, %38, %32, %9
%51 = phi i1 [ false, %38 ], [ false, %32 ], [ false, %9 ], [ %49, %44 ]
%52 = zext i1 %51 to i64
%53 = select i1 %51, i32 1, i32 0
store i32 %53, i32* %2
br label %54
54: ; preds = %50, %8
%55 = load i32, i32* %2
ret i32 %55
}

LLVM IR (-O2):
%struct.stat = type { i32, i32 }
@SCSI_DISK0_MAJOR = global i64 0
@SCSI_DISK1_MAJOR = global i64 0
@SCSI_DISK7_MAJOR = global i64 0
@SCSI_DISK8_MAJOR = global i64 0
@SCSI_DISK15_MAJOR = global i64 0
define i32 @is_sd_device(i8* %0) {
%2 = alloca %struct.stat
%3 = bitcast %struct.stat* %2 to i8*
%4 = call i64 @stat(i8* %0, %struct.stat* %2)
%5 = icmp slt i64 %4, 0
br i1 %5, label %43, label %6
6: ; preds = %1
%7 = getelementptr inbounds %struct.stat, %struct.stat* %2, i64 0, i32 1
%8 = load i32, i32* %7
%9 = call i64 @S_ISBLK(i32 %8)
%10 = icmp eq i64 %9, 0
br i1 %10, label %43, label %11
11: ; preds = %6
%12 = getelementptr inbounds %struct.stat, %struct.stat* %2, i64 0, i32 0
%13 = load i32, i32* %12
%14 = call i64 @major(i32 %13)
%15 = load i64, i64* @SCSI_DISK0_MAJOR
%16 = icmp eq i64 %14, %15
br i1 %16, label %37, label %17
17: ; preds = %11
%18 = load i32, i32* %12
%19 = call i64 @major(i32 %18)
%20 = load i64, i64* @SCSI_DISK1_MAJOR
%21 = icmp slt i64 %19, %20
br i1 %21, label %27, label %22
22: ; preds = %17
%23 = load i32, i32* %12
%24 = call i64 @major(i32 %23)
%25 = load i64, i64* @SCSI_DISK7_MAJOR
%26 = icmp sgt i64 %24, %25
br i1 %26, label %27, label %37
27: ; preds = %22, %17
%28 = load i32, i32* %12
%29 = call i64 @major(i32 %28)
%30 = load i64, i64* @SCSI_DISK8_MAJOR
%31 = icmp slt i64 %29, %30
br i1 %31, label %43, label %32
32: ; preds = %27
%33 = load i32, i32* %12
%34 = call i64 @major(i32 %33)
%35 = load i64, i64* @SCSI_DISK15_MAJOR
%36 = icmp sgt i64 %34, %35
br i1 %36, label %43, label %37
37: ; preds = %32, %22, %11
%38 = load i32, i32* %12
%39 = call i32 @minor(i32 %38)
%40 = and i32 %39, 15
%41 = icmp eq i32 %40, 0
%42 = zext i1 %41 to i32
br label %43
43: ; preds = %6, %27, %32, %37, %1
%44 = phi i32 [ -1, %1 ], [ 0, %32 ], [ 0, %27 ], [ 0, %6 ], [ %42, %37 ]
ret i32 %44
}