#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 */
typedef int /*<<< orphan*/ mode_t;

/* Variables and functions */
unsigned char DT_BLK;
unsigned char DT_CHR;
unsigned char DT_DIR;
unsigned char DT_FIFO;
unsigned char DT_LNK;
unsigned char DT_REG;
unsigned char DT_SOCK;
unsigned char DT_UNKNOWN;
scalar_t__ S_ISBLK(int /*<<< orphan*/);
scalar_t__ S_ISCHR(int /*<<< orphan*/);
scalar_t__ S_ISDIR(int /*<<< orphan*/);
scalar_t__ S_ISFIFO(int /*<<< orphan*/);
scalar_t__ S_ISLNK(int /*<<< orphan*/);
scalar_t__ S_ISREG(int /*<<< orphan*/);
scalar_t__ S_ISSOCK(int /*<<< orphan*/);
unsigned char stat_mode_to_dt_type(mode_t mode) {
  if (S_ISDIR(mode)) {
    return DT_DIR;
  }
  if (S_ISREG(mode)) {
    return DT_REG;
  }
  if (S_ISCHR(mode)) {
    return DT_CHR;
  }
  if (S_ISBLK(mode)) {
    return DT_BLK;
  }
  if (S_ISFIFO(mode)) {
    return DT_FIFO;
  }
  if (S_ISLNK(mode)) {
    return DT_LNK;
  }
  if (S_ISSOCK(mode)) {
    return DT_SOCK;
  }
  return DT_UNKNOWN;
}


x86 assembly (clang, -O0):
<stat_mode_to_dt_type>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
mov    -0x8(%rbp),%edi
call   1060 <S_ISDIR@plt>
cmp    $0x0,%rax
je     119e <stat_mode_to_dt_type+0x2e>
mov    0x2e3c(%rip),%rax
mov    (%rax),%al
mov    %al,-0x1(%rbp)
jmp    127c <stat_mode_to_dt_type+0x10c>
mov    -0x8(%rbp),%edi
call   1070 <S_ISREG@plt>
cmp    $0x0,%rax
je     11c1 <stat_mode_to_dt_type+0x51>
mov    0x2e21(%rip),%rax
mov    (%rax),%al
mov    %al,-0x1(%rbp)
jmp    127c <stat_mode_to_dt_type+0x10c>
mov    -0x8(%rbp),%edi
call   1080 <S_ISCHR@plt>
cmp    $0x0,%rax
je     11e4 <stat_mode_to_dt_type+0x74>
mov    0x2de6(%rip),%rax
mov    (%rax),%al
mov    %al,-0x1(%rbp)
jmp    127c <stat_mode_to_dt_type+0x10c>
mov    -0x8(%rbp),%edi
call   1090 <S_ISBLK@plt>
cmp    $0x0,%rax
je     1207 <stat_mode_to_dt_type+0x97>
mov    0x2dcb(%rip),%rax
mov    (%rax),%al
mov    %al,-0x1(%rbp)
jmp    127c <stat_mode_to_dt_type+0x10c>
mov    -0x8(%rbp),%edi
call   1040 <S_ISFIFO@plt>
cmp    $0x0,%rax
je     122a <stat_mode_to_dt_type+0xba>
mov    0x2d88(%rip),%rax
mov    (%rax),%al
mov    %al,-0x1(%rbp)
jmp    127c <stat_mode_to_dt_type+0x10c>
mov    -0x8(%rbp),%edi
call   1030 <S_ISLNK@plt>
cmp    $0x0,%rax
je     124d <stat_mode_to_dt_type+0xdd>
mov    0x2d75(%rip),%rax
mov    (%rax),%al
mov    %al,-0x1(%rbp)
jmp    127c <stat_mode_to_dt_type+0x10c>
mov    -0x8(%rbp),%edi
call   1050 <S_ISSOCK@plt>
cmp    $0x0,%rax
je     1270 <stat_mode_to_dt_type+0x100>
mov    0x2d3a(%rip),%rax
mov    (%rax),%al
mov    %al,-0x1(%rbp)
jmp    127c <stat_mode_to_dt_type+0x10c>
mov    0x2d71(%rip),%rax
mov    (%rax),%al
mov    %al,-0x1(%rbp)
movzbl -0x1(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<stat_mode_to_dt_type>:
push   %rbx
mov    %edi,%ebx
call   1060 <S_ISDIR@plt>
test   %rax,%rax
je     1189 <stat_mode_to_dt_type+0x19>
mov    0x2e4c(%rip),%rax
jmp    120e <stat_mode_to_dt_type+0x9e>
mov    %ebx,%edi
call   1070 <S_ISREG@plt>
test   %rax,%rax
je     119e <stat_mode_to_dt_type+0x2e>
mov    0x2e3c(%rip),%rax
jmp    120e <stat_mode_to_dt_type+0x9e>
mov    %ebx,%edi
call   1080 <S_ISCHR@plt>
test   %rax,%rax
je     11b3 <stat_mode_to_dt_type+0x43>
mov    0x2e0f(%rip),%rax
jmp    120e <stat_mode_to_dt_type+0x9e>
mov    %ebx,%edi
call   1090 <S_ISBLK@plt>
test   %rax,%rax
je     11c8 <stat_mode_to_dt_type+0x58>
mov    0x2e02(%rip),%rax
jmp    120e <stat_mode_to_dt_type+0x9e>
mov    %ebx,%edi
call   1040 <S_ISFIFO@plt>
test   %rax,%rax
je     11dd <stat_mode_to_dt_type+0x6d>
mov    0x2dcd(%rip),%rax
jmp    120e <stat_mode_to_dt_type+0x9e>
mov    %ebx,%edi
call   1030 <S_ISLNK@plt>
test   %rax,%rax
je     11f2 <stat_mode_to_dt_type+0x82>
mov    0x2dc8(%rip),%rax
jmp    120e <stat_mode_to_dt_type+0x9e>
mov    %ebx,%edi
call   1050 <S_ISSOCK@plt>
test   %rax,%rax
jne    1207 <stat_mode_to_dt_type+0x97>
mov    0x2de3(%rip),%rax
jmp    120e <stat_mode_to_dt_type+0x9e>
mov    0x2d92(%rip),%rax
mov    (%rax),%al
pop    %rbx
ret

LLVM IR (-O0):
@DT_DIR = global i8 0
@DT_REG = global i8 0
@DT_CHR = global i8 0
@DT_BLK = global i8 0
@DT_FIFO = global i8 0
@DT_LNK = global i8 0
@DT_SOCK = global i8 0
@DT_UNKNOWN = global i8 0
define zeroext i8 @stat_mode_to_dt_type(i32 %0) {
%2 = alloca i8
%3 = alloca i32
store i32 %0, i32* %3
%4 = load i32, i32* %3
%5 = call i64 @S_ISDIR(i32 %4)
%6 = icmp ne i64 %5, 0
br i1 %6, label %7, label %9
7: ; preds = %1
%8 = load i8, i8* @DT_DIR
store i8 %8, i8* %2
br label %47
9: ; preds = %1
%10 = load i32, i32* %3
%11 = call i64 @S_ISREG(i32 %10)
%12 = icmp ne i64 %11, 0
br i1 %12, label %13, label %15
13: ; preds = %9
%14 = load i8, i8* @DT_REG
store i8 %14, i8* %2
br label %47
15: ; preds = %9
%16 = load i32, i32* %3
%17 = call i64 @S_ISCHR(i32 %16)
%18 = icmp ne i64 %17, 0
br i1 %18, label %19, label %21
19: ; preds = %15
%20 = load i8, i8* @DT_CHR
store i8 %20, i8* %2
br label %47
21: ; preds = %15
%22 = load i32, i32* %3
%23 = call i64 @S_ISBLK(i32 %22)
%24 = icmp ne i64 %23, 0
br i1 %24, label %25, label %27
25: ; preds = %21
%26 = load i8, i8* @DT_BLK
store i8 %26, i8* %2
br label %47
27: ; preds = %21
%28 = load i32, i32* %3
%29 = call i64 @S_ISFIFO(i32 %28)
%30 = icmp ne i64 %29, 0
br i1 %30, label %31, label %33
31: ; preds = %27
%32 = load i8, i8* @DT_FIFO
store i8 %32, i8* %2
br label %47
33: ; preds = %27
%34 = load i32, i32* %3
%35 = call i64 @S_ISLNK(i32 %34)
%36 = icmp ne i64 %35, 0
br i1 %36, label %37, label %39
37: ; preds = %33
%38 = load i8, i8* @DT_LNK
store i8 %38, i8* %2
br label %47
39: ; preds = %33
%40 = load i32, i32* %3
%41 = call i64 @S_ISSOCK(i32 %40)
%42 = icmp ne i64 %41, 0
br i1 %42, label %43, label %45
43: ; preds = %39
%44 = load i8, i8* @DT_SOCK
store i8 %44, i8* %2
br label %47
45: ; preds = %39
%46 = load i8, i8* @DT_UNKNOWN
store i8 %46, i8* %2
br label %47
47: ; preds = %45, %43, %37, %31, %25, %19, %13, %7
%48 = load i8, i8* %2
ret i8 %48
}

LLVM IR (-O2):
@DT_DIR = global i8 0
@DT_REG = global i8 0
@DT_CHR = global i8 0
@DT_BLK = global i8 0
@DT_FIFO = global i8 0
@DT_LNK = global i8 0
@DT_SOCK = global i8 0
@DT_UNKNOWN = global i8 0
define zeroext i8 @stat_mode_to_dt_type(i32 %0) {
%2 = tail call i64 @S_ISDIR(i32 %0)
%3 = icmp eq i64 %2, 0
br i1 %3, label %4, label %23
4: ; preds = %1
%5 = tail call i64 @S_ISREG(i32 %0)
%6 = icmp eq i64 %5, 0
br i1 %6, label %7, label %23
7: ; preds = %4
%8 = tail call i64 @S_ISCHR(i32 %0)
%9 = icmp eq i64 %8, 0
br i1 %9, label %10, label %23
10: ; preds = %7
%11 = tail call i64 @S_ISBLK(i32 %0)
%12 = icmp eq i64 %11, 0
br i1 %12, label %13, label %23
13: ; preds = %10
%14 = tail call i64 @S_ISFIFO(i32 %0)
%15 = icmp eq i64 %14, 0
br i1 %15, label %16, label %23
16: ; preds = %13
%17 = tail call i64 @S_ISLNK(i32 %0)
%18 = icmp eq i64 %17, 0
br i1 %18, label %19, label %23
19: ; preds = %16
%20 = tail call i64 @S_ISSOCK(i32 %0)
%21 = icmp eq i64 %20, 0
%22 = select i1 %21, i8* @DT_UNKNOWN, i8* @DT_SOCK
br label %23
23: ; preds = %19, %16, %13, %10, %7, %4, %1
%24 = phi i8* [ @DT_DIR, %1 ], [ @DT_REG, %4 ], [ @DT_CHR, %7 ], [ @DT_BLK, %10 ], [ @DT_FIFO, %13 ], [ @DT_LNK, %16 ], [ %22, %19 ]
%25 = load i8, i8* %24
ret i8 %25
}