#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;
};
typedef int /*<<< orphan*/ dev_name;
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
int major(int /*<<< orphan*/);
int minor(int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ snprintf(char *, int, char *, char const *);
scalar_t__ stat(char *, struct stat *);
int is_scsi_disk(const char *name) {
  char dev_name[100];
  struct stat st;
  snprintf(dev_name, sizeof(dev_name), "/dev/%s", name);
  if (stat(dev_name, &st) < 0) {
    char buf[100];
    snprintf(buf, sizeof(buf), "stat(%s):", dev_name);
    perror(buf);
    return 0;
  }
  return (major(st.st_rdev) == 8) && (minor(st.st_rdev) % 16 == 0);
}


x86 assembly (clang, -O0):
<is_scsi_disk>:
push   %rbp
mov    %rsp,%rbp
sub    $0x100,%rsp
mov    %rdi,-0x10(%rbp)
lea    -0x80(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    $0x64,%esi
lea    0xe8d(%rip),%rdx
call   1040 <snprintf@plt>
lea    -0x80(%rbp),%rdi
lea    -0x88(%rbp),%rsi
call   1060 <stat@plt>
cmp    $0x0,%rax
jge    11c6 <is_scsi_disk+0x76>
lea    -0xf0(%rbp),%rdi
lea    -0x80(%rbp),%rcx
mov    $0x64,%esi
lea    0xe5f(%rip),%rdx
call   1040 <snprintf@plt>
lea    -0xf0(%rbp),%rdi
call   1070 <perror@plt>
movl   $0x0,-0x4(%rbp)
jmp    1211 <is_scsi_disk+0xc1>
mov    -0x88(%rbp),%edi
call   1050 <major@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0x8,%ecx
mov    %al,-0xf1(%rbp)
jne    1203 <is_scsi_disk+0xb3>
mov    -0x88(%rbp),%edi
call   1030 <minor@plt>
mov    $0x10,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
sete   %al
mov    %al,-0xf1(%rbp)
mov    -0xf1(%rbp),%al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x100,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<is_scsi_disk>:
push   %rbx
sub    $0xf0,%rsp
mov    %rdi,%rcx
lea    0xe9e(%rip),%rdx
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x64,%esi
call   1040 <snprintf@plt>
lea    0x8(%rsp),%rsi
mov    %rbx,%rdi
call   1060 <stat@plt>
test   %rax,%rax
js     11b4 <is_scsi_disk+0x64>
mov    0x8(%rsp),%edi
call   1050 <major@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0x8,%ecx
jne    11ab <is_scsi_disk+0x5b>
mov    0x8(%rsp),%edi
call   1030 <minor@plt>
mov    %eax,%ecx
xor    %eax,%eax
test   $0xf,%cl
sete   %al
add    $0xf0,%rsp
pop    %rbx
ret
lea    0xe4d(%rip),%rdx
lea    0x80(%rsp),%rbx
lea    0x10(%rsp),%rcx
mov    %rbx,%rdi
mov    $0x64,%esi
call   1040 <snprintf@plt>
mov    %rbx,%rdi
call   1070 <perror@plt>
xor    %eax,%eax
jmp    11ab <is_scsi_disk+0x5b>

LLVM IR (-O0):
%struct.stat = type { i32 }
@.str = [8 x i8] c"/dev/%s\00"
@.str.1 = [10 x i8] c"stat(%s):\00"
define i32 @is_scsi_disk(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca [100 x i8]
%5 = alloca %struct.stat
%6 = alloca [100 x i8]
store i8* %0, i8** %3
%7 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%8 = load i8*, i8** %3
%9 = call i32 @snprintf(i8* %7, i32 100, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* %8)
%10 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%11 = call i64 @stat(i8* %10, %struct.stat* %5)
%12 = icmp slt i64 %11, 0
br i1 %12, label %13, label %19
13: ; preds = %1
%14 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
%15 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%16 = call i32 @snprintf(i8* %14, i32 100, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8* %15)
%17 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
%18 = call i32 @perror(i8* %17)
store i32 0, i32* %2
br label %33
19: ; preds = %1
%20 = getelementptr inbounds %struct.stat, %struct.stat* %5, i32 0, i32 0
%21 = load i32, i32* %20
%22 = call i32 @major(i32 %21)
%23 = icmp eq i32 %22, 8
br i1 %23, label %24, label %30
24: ; preds = %19
%25 = getelementptr inbounds %struct.stat, %struct.stat* %5, i32 0, i32 0
%26 = load i32, i32* %25
%27 = call i32 @minor(i32 %26)
%28 = srem i32 %27, 16
%29 = icmp eq i32 %28, 0
br label %30
30: ; preds = %24, %19
%31 = phi i1 [ false, %19 ], [ %29, %24 ]
%32 = zext i1 %31 to i32
store i32 %32, i32* %2
br label %33
33: ; preds = %30, %13
%34 = load i32, i32* %2
ret i32 %34
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@.str = [8 x i8] c"/dev/%s\00"
@.str.1 = [10 x i8] c"stat(%s):\00"
define i32 @is_scsi_disk(i8* %0) {
%2 = alloca [100 x i8]
%3 = alloca %struct.stat
%4 = alloca [100 x i8]
%5 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%6 = bitcast %struct.stat* %3 to i8*
%7 = call i32 @snprintf(i8* %5, i32 100, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* %0)
%8 = call i64 @stat(i8* %5, %struct.stat* %3)
%9 = icmp slt i64 %8, 0
br i1 %9, label %10, label %14
10: ; preds = %1
%11 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%12 = call i32 @snprintf(i8* %11, i32 100, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8* %5)
%13 = call i32 @perror(i8* %11)
br label %25
14: ; preds = %1
%15 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 0
%16 = load i32, i32* %15
%17 = call i32 @major(i32 %16)
%18 = icmp eq i32 %17, 8
br i1 %18, label %19, label %25
19: ; preds = %14
%20 = load i32, i32* %15
%21 = call i32 @minor(i32 %20)
%22 = and i32 %21, 15
%23 = icmp eq i32 %22, 0
%24 = zext i1 %23 to i32
br label %25
25: ; preds = %14, %19, %10
%26 = phi i32 [ 0, %10 ], [ 0, %14 ], [ %24, %19 ]
ret i32 %26
}