#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 st_mode;
};

/* Variables and functions */
#define S_IFBLK 134
#define S_IFCHR 133
#define S_IFDIR 132
#define S_IFIFO 131
#define S_IFLNK 130
int S_IFMT;
#define S_IFREG 129
#define S_IFSOCK 128
int stat(char const *, struct stat *);
int isBlockDevice(const char *name) {
  struct stat sb;
  int ret;
  if ((ret = stat(name, &sb)) == -1) {
    return 0;
  }
  switch (sb.st_mode & S_IFMT) {
  case S_IFBLK:
    ret = 1;
    break;
  case S_IFCHR:
    ret = 0;
    break;
  case S_IFDIR:
    ret = 0;
    break;
  case S_IFIFO:
    ret = 0;
    break;
  case S_IFLNK:
    ret = 0;
    break;
  case S_IFREG:
    ret = 2;
    break;
  case S_IFSOCK:
    ret = 0;
    break;
  default:
    ret = 0;
    break;
  }
  return ret;
}


x86 assembly (clang, -O0):
<isBlockDevice>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   1030 <stat@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0xffffffff,%eax
jne    1141 <isBlockDevice+0x31>
movl   $0x0,-0x4(%rbp)
jmp    11d6 <isBlockDevice+0xc6>
mov    -0x18(%rbp),%eax
mov    0x2e95(%rip),%rcx
mov    (%rcx),%ecx
and    %ecx,%eax
add    $0xffffff80,%eax
mov    %eax,%ecx
mov    %rcx,-0x28(%rbp)
sub    $0x6,%eax
ja     11c9 <isBlockDevice+0xb9>
mov    -0x28(%rbp),%rax
lea    0xe94(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
movl   $0x1,-0x1c(%rbp)
jmp    11d0 <isBlockDevice+0xc0>
movl   $0x0,-0x1c(%rbp)
jmp    11d0 <isBlockDevice+0xc0>
movl   $0x0,-0x1c(%rbp)
jmp    11d0 <isBlockDevice+0xc0>
movl   $0x0,-0x1c(%rbp)
jmp    11d0 <isBlockDevice+0xc0>
movl   $0x0,-0x1c(%rbp)
jmp    11d0 <isBlockDevice+0xc0>
movl   $0x2,-0x1c(%rbp)
jmp    11d0 <isBlockDevice+0xc0>
movl   $0x0,-0x1c(%rbp)
jmp    11d0 <isBlockDevice+0xc0>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<isBlockDevice>:
push   %rax
mov    %rsp,%rsi
call   1030 <stat@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0xffffffff,%ecx
je     1143 <isBlockDevice+0x33>
mov    0x2eb7(%rip),%rcx
mov    (%rcx),%ecx
and    (%rsp),%ecx
add    $0xffffff80,%ecx
cmp    $0x6,%ecx
ja     1143 <isBlockDevice+0x33>
movslq %ecx,%rax
lea    0xec0(%rip),%rcx
mov    (%rcx,%rax,4),%eax
pop    %rcx
ret

LLVM IR (-O0):
%struct.stat = type { i32 }
@S_IFMT = global i32 0
define i32 @isBlockDevice(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca %struct.stat
%5 = alloca i32
store i8* %0, i8** %3
%6 = load i8*, i8** %3
%7 = call i32 @stat(i8* %6, %struct.stat* %4)
store i32 %7, i32* %5
%8 = icmp eq i32 %7, -1
br i1 %8, label %9, label %10
9: ; preds = %1
store i32 0, i32* %2
br label %25
10: ; preds = %1
%11 = getelementptr inbounds %struct.stat, %struct.stat* %4, i32 0, i32 0
%12 = load i32, i32* %11
%13 = load i32, i32* @S_IFMT
%14 = and i32 %12, %13
switch i32 %14, label %22 [
i32 134, label %15
i32 133, label %16
i32 132, label %17
i32 131, label %18
i32 130, label %19
i32 129, label %20
i32 128, label %21
]
15: ; preds = %10
store i32 1, i32* %5
br label %23
16: ; preds = %10
store i32 0, i32* %5
br label %23
17: ; preds = %10
store i32 0, i32* %5
br label %23
18: ; preds = %10
store i32 0, i32* %5
br label %23
19: ; preds = %10
store i32 0, i32* %5
br label %23
20: ; preds = %10
store i32 2, i32* %5
br label %23
21: ; preds = %10
store i32 0, i32* %5
br label %23
22: ; preds = %10
store i32 0, i32* %5
br label %23
23: ; preds = %22, %21, %20, %19, %18, %17, %16, %15
%24 = load i32, i32* %5
store i32 %24, i32* %2
br label %25
25: ; preds = %23, %9
%26 = load i32, i32* %2
ret i32 %26
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@S_IFMT = global i32 0
@switch.table.isBlockDevice = [7 x i32] [i32 0, i32 2, i32 0, i32 0, i32 0, i32 0, i32 1]
define i32 @isBlockDevice(i8* nocapture %0) {
%2 = alloca %struct.stat
%3 = bitcast %struct.stat* %2 to i8*
%4 = call i32 @stat(i8* %0, %struct.stat* %2)
%5 = icmp eq i32 %4, -1
br i1 %5, label %17, label %6
6: ; preds = %1
%7 = getelementptr inbounds %struct.stat, %struct.stat* %2, i64 0, i32 0
%8 = load i32, i32* %7
%9 = load i32, i32* @S_IFMT
%10 = and i32 %9, %8
%11 = add i32 %10, -128
%12 = icmp ult i32 %11, 7
br i1 %12, label %13, label %17
13: ; preds = %6
%14 = sext i32 %11 to i64
%15 = getelementptr inbounds [7 x i32], [7 x i32]* @switch.table.isBlockDevice, i64 0, i64 %14
%16 = load i32, i32* %15
br label %17
17: ; preds = %6, %13, %1
%18 = phi i32 [ 0, %1 ], [ %16, %13 ], [ 0, %6 ]
ret i32 %18
}