#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*/ S_ISBLK(int /*<<< orphan*/);
int /*<<< orphan*/ S_ISCHR(int /*<<< orphan*/);
int /*<<< orphan*/ S_ISDIR(int /*<<< orphan*/);
int /*<<< orphan*/ S_ISFIFO(int /*<<< orphan*/);
int /*<<< orphan*/ S_ISLNK(int /*<<< orphan*/);
int /*<<< orphan*/ S_ISREG(int /*<<< orphan*/);
int /*<<< orphan*/ S_ISSOCK(int /*<<< orphan*/);
int errno;
int /*<<< orphan*/ error(int, int, char *, int);
int check_type(struct stat file, const char *const *parms, int parm_pos) {
  char type = (char)*parms[parm_pos + 1];
  switch (type) {
  case 'b':
    if (S_ISBLK(file.st_mode)) {
      return 1;
    } else {
      return 0;
    }
    break;
  case 'c':
    if (S_ISCHR(file.st_mode)) {
      return 1;
    } else {
      return 0;
    }
    break;
  case 'd':
    if (S_ISDIR(file.st_mode)) {
      return 1;
    } else {
      return 0;
    }
    break;
  case 'p':
    if (S_ISFIFO(file.st_mode)) {
      return 1;
    } else {
      return 0;
    }
    break;
  case 'f':
    if (S_ISREG(file.st_mode)) {
      return 1;
    } else {
      return 0;
    }
    break;
  case 'l':
    if (S_ISLNK(file.st_mode)) {
      return 1;
    } else {
      return 0;
    }
    break;
  case 's':
    if (S_ISSOCK(file.st_mode)) {
      return 1;
    } else {
      return 0;
    }
    break;
  default:
    error(1, 1, "%d", errno);
    return 0;
  }
}


x86 assembly (clang, -O0):
<check_type>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    0x8(%rax,%rcx,8),%rax
mov    (%rax),%al
mov    %al,-0x15(%rbp)
movsbl -0x15(%rbp),%eax
add    $0xffffff9e,%eax
mov    %eax,%ecx
mov    %rcx,-0x20(%rbp)
sub    $0x11,%eax
ja     12ed <check_type+0x16d>
mov    -0x20(%rbp),%rax
lea    0xe3b(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x8(%rbp),%edi
call   1090 <S_ISBLK@plt>
cmp    $0x0,%eax
je     11eb <check_type+0x6b>
movl   $0x1,-0x4(%rbp)
jmp    1310 <check_type+0x190>
movl   $0x0,-0x4(%rbp)
jmp    1310 <check_type+0x190>
mov    -0x8(%rbp),%edi
call   1080 <S_ISCHR@plt>
cmp    $0x0,%eax
je     1214 <check_type+0x94>
movl   $0x1,-0x4(%rbp)
jmp    1310 <check_type+0x190>
movl   $0x0,-0x4(%rbp)
jmp    1310 <check_type+0x190>
mov    -0x8(%rbp),%edi
call   1060 <S_ISDIR@plt>
cmp    $0x0,%eax
je     123d <check_type+0xbd>
movl   $0x1,-0x4(%rbp)
jmp    1310 <check_type+0x190>
movl   $0x0,-0x4(%rbp)
jmp    1310 <check_type+0x190>
mov    -0x8(%rbp),%edi
call   1040 <S_ISFIFO@plt>
cmp    $0x0,%eax
je     1266 <check_type+0xe6>
movl   $0x1,-0x4(%rbp)
jmp    1310 <check_type+0x190>
movl   $0x0,-0x4(%rbp)
jmp    1310 <check_type+0x190>
mov    -0x8(%rbp),%edi
call   1070 <S_ISREG@plt>
cmp    $0x0,%eax
je     128f <check_type+0x10f>
movl   $0x1,-0x4(%rbp)
jmp    1310 <check_type+0x190>
movl   $0x0,-0x4(%rbp)
jmp    1310 <check_type+0x190>
mov    -0x8(%rbp),%edi
call   1030 <S_ISLNK@plt>
cmp    $0x0,%eax
je     12b8 <check_type+0x138>
movl   $0x1,-0x4(%rbp)
jmp    1310 <check_type+0x190>
movl   $0x0,-0x4(%rbp)
jmp    1310 <check_type+0x190>
mov    -0x8(%rbp),%edi
call   1050 <S_ISSOCK@plt>
cmp    $0x0,%eax
je     12e1 <check_type+0x161>
movl   $0x1,-0x4(%rbp)
jmp    1310 <check_type+0x190>
movl   $0x0,-0x4(%rbp)
jmp    1310 <check_type+0x190>
mov    0x2cec(%rip),%rax
mov    (%rax),%ecx
mov    $0x1,%esi
lea    0xd46(%rip),%rdx
mov    %esi,%edi
call   10a0 <error@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<check_type>:
push   %rax
movslq %edx,%rax
mov    0x8(%rsi,%rax,8),%rax
movsbl (%rax),%eax
add    $0xffffff9e,%eax
cmp    $0x11,%eax
ja     11b9 <check_type+0x39>
lea    0xe65(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
call   1090 <S_ISBLK@plt>
jmp    11f6 <check_type+0x76>
call   1080 <S_ISCHR@plt>
jmp    11f6 <check_type+0x76>
call   1060 <S_ISDIR@plt>
jmp    11f6 <check_type+0x76>
mov    0x2e20(%rip),%rax
mov    (%rax),%ecx
lea    0xe7f(%rip),%rdx
mov    $0x1,%edi
mov    $0x1,%esi
call   10a0 <error@plt>
xor    %eax,%eax
jmp    11fb <check_type+0x7b>
call   1070 <S_ISREG@plt>
jmp    11f6 <check_type+0x76>
call   1040 <S_ISFIFO@plt>
jmp    11f6 <check_type+0x76>
call   1050 <S_ISSOCK@plt>
jmp    11f6 <check_type+0x76>
call   1030 <S_ISLNK@plt>
test   %eax,%eax
setne  %al
movzbl %al,%eax
pop    %rcx
ret

LLVM IR (-O0):
%struct.stat = type { i32 }
@.str = [3 x i8] c"%d\00"
@errno = global i32 0
define i32 @check_type(i32 %0, i8** %1, i32 %2) {
%4 = alloca i32
%5 = alloca %struct.stat
%6 = alloca i8**
%7 = alloca i32
%8 = alloca i8
%9 = getelementptr inbounds %struct.stat, %struct.stat* %5, i32 0, i32 0
store i32 %0, i32* %9
store i8** %1, i8*** %6
store i32 %2, i32* %7
%10 = load i8**, i8*** %6
%11 = load i32, i32* %7
%12 = add nsw i32 %11, 1
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds i8*, i8** %10, i64 %13
%15 = load i8*, i8** %14
%16 = load i8, i8* %15
store i8 %16, i8* %8
%17 = load i8, i8* %8
%18 = sext i8 %17 to i32
switch i32 %18, label %68 [
i32 98, label %19
i32 99, label %26
i32 100, label %33
i32 112, label %40
i32 102, label %47
i32 108, label %54
i32 115, label %61
]
19: ; preds = %3
%20 = getelementptr inbounds %struct.stat, %struct.stat* %5, i32 0, i32 0
%21 = load i32, i32* %20
%22 = call i32 @S_ISBLK(i32 %21)
%23 = icmp ne i32 %22, 0
br i1 %23, label %24, label %25
24: ; preds = %19
store i32 1, i32* %4
br label %71
25: ; preds = %19
store i32 0, i32* %4
br label %71
26: ; preds = %3
%27 = getelementptr inbounds %struct.stat, %struct.stat* %5, i32 0, i32 0
%28 = load i32, i32* %27
%29 = call i32 @S_ISCHR(i32 %28)
%30 = icmp ne i32 %29, 0
br i1 %30, label %31, label %32
31: ; preds = %26
store i32 1, i32* %4
br label %71
32: ; preds = %26
store i32 0, i32* %4
br label %71
33: ; preds = %3
%34 = getelementptr inbounds %struct.stat, %struct.stat* %5, i32 0, i32 0
%35 = load i32, i32* %34
%36 = call i32 @S_ISDIR(i32 %35)
%37 = icmp ne i32 %36, 0
br i1 %37, label %38, label %39
38: ; preds = %33
store i32 1, i32* %4
br label %71
39: ; preds = %33
store i32 0, i32* %4
br label %71
40: ; preds = %3
%41 = getelementptr inbounds %struct.stat, %struct.stat* %5, i32 0, i32 0
%42 = load i32, i32* %41
%43 = call i32 @S_ISFIFO(i32 %42)
%44 = icmp ne i32 %43, 0
br i1 %44, label %45, label %46
45: ; preds = %40
store i32 1, i32* %4
br label %71
46: ; preds = %40
store i32 0, i32* %4
br label %71
47: ; preds = %3
%48 = getelementptr inbounds %struct.stat, %struct.stat* %5, i32 0, i32 0
%49 = load i32, i32* %48
%50 = call i32 @S_ISREG(i32 %49)
%51 = icmp ne i32 %50, 0
br i1 %51, label %52, label %53
52: ; preds = %47
store i32 1, i32* %4
br label %71
53: ; preds = %47
store i32 0, i32* %4
br label %71
54: ; preds = %3
%55 = getelementptr inbounds %struct.stat, %struct.stat* %5, i32 0, i32 0
%56 = load i32, i32* %55
%57 = call i32 @S_ISLNK(i32 %56)
%58 = icmp ne i32 %57, 0
br i1 %58, label %59, label %60
59: ; preds = %54
store i32 1, i32* %4
br label %71
60: ; preds = %54
store i32 0, i32* %4
br label %71
61: ; preds = %3
%62 = getelementptr inbounds %struct.stat, %struct.stat* %5, i32 0, i32 0
%63 = load i32, i32* %62
%64 = call i32 @S_ISSOCK(i32 %63)
%65 = icmp ne i32 %64, 0
br i1 %65, label %66, label %67
66: ; preds = %61
store i32 1, i32* %4
br label %71
67: ; preds = %61
store i32 0, i32* %4
br label %71
68: ; preds = %3
%69 = load i32, i32* @errno
%70 = call i32 @error(i32 1, i32 1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %69)
store i32 0, i32* %4
br label %71
71: ; preds = %68, %67, %66, %60, %59, %53, %52, %46, %45, %39, %38, %32, %31, %25, %24
%72 = load i32, i32* %4
ret i32 %72
}

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
@errno = global i32 0
define i32 @check_type(i32 %0, i8** nocapture %1, i32 %2) {
%4 = add nsw i32 %2, 1
%5 = sext i32 %4 to i64
%6 = getelementptr inbounds i8*, i8** %1, i64 %5
%7 = load i8*, i8** %6
%8 = load i8, i8* %7
%9 = sext i8 %8 to i32
switch i32 %9, label %31 [
i32 98, label %10
i32 99, label %13
i32 100, label %16
i32 112, label %19
i32 102, label %22
i32 108, label %25
i32 115, label %28
]
10: ; preds = %3
%11 = tail call i32 @S_ISBLK(i32 %0)
%12 = icmp ne i32 %11, 0
br label %34
13: ; preds = %3
%14 = tail call i32 @S_ISCHR(i32 %0)
%15 = icmp ne i32 %14, 0
br label %34
16: ; preds = %3
%17 = tail call i32 @S_ISDIR(i32 %0)
%18 = icmp ne i32 %17, 0
br label %34
19: ; preds = %3
%20 = tail call i32 @S_ISFIFO(i32 %0)
%21 = icmp ne i32 %20, 0
br label %34
22: ; preds = %3
%23 = tail call i32 @S_ISREG(i32 %0)
%24 = icmp ne i32 %23, 0
br label %34
25: ; preds = %3
%26 = tail call i32 @S_ISLNK(i32 %0)
%27 = icmp ne i32 %26, 0
br label %34
28: ; preds = %3
%29 = tail call i32 @S_ISSOCK(i32 %0)
%30 = icmp ne i32 %29, 0
br label %34
31: ; preds = %3
%32 = load i32, i32* @errno
%33 = tail call i32 @error(i32 1, i32 1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %32)
br label %34
34: ; preds = %28, %25, %22, %19, %16, %13, %10, %31
%35 = phi i1 [ false, %31 ], [ %12, %10 ], [ %15, %13 ], [ %18, %16 ], [ %21, %19 ], [ %24, %22 ], [ %27, %25 ], [ %30, %28 ]
%36 = zext i1 %35 to i32
ret i32 %36
}