#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 */
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*/);
char do_get_type(struct stat attr) {
  if (S_ISBLK(attr.st_mode)) {
    return 'b';
  }
  if (S_ISCHR(attr.st_mode)) {
    return 'c';
  }
  if (S_ISDIR(attr.st_mode)) {
    return 'd';
  }
  if (S_ISFIFO(attr.st_mode)) {
    return 'p';
  }
  if (S_ISREG(attr.st_mode)) {
    return 'f';
  }
  if (S_ISLNK(attr.st_mode)) {
    return 'l';
  }
  if (S_ISSOCK(attr.st_mode)) {
    return 's';
  }
  return '?';
}


x86 assembly (clang, -O0):
<do_get_type>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
mov    -0x8(%rbp),%edi
call   1090 <S_ISBLK@plt>
cmp    $0x0,%rax
je     1196 <do_get_type+0x26>
movb   $0x62,-0x1(%rbp)
jmp    123c <do_get_type+0xcc>
mov    -0x8(%rbp),%edi
call   1080 <S_ISCHR@plt>
cmp    $0x0,%rax
je     11b1 <do_get_type+0x41>
movb   $0x63,-0x1(%rbp)
jmp    123c <do_get_type+0xcc>
mov    -0x8(%rbp),%edi
call   1060 <S_ISDIR@plt>
cmp    $0x0,%rax
je     11cc <do_get_type+0x5c>
movb   $0x64,-0x1(%rbp)
jmp    123c <do_get_type+0xcc>
mov    -0x8(%rbp),%edi
call   1040 <S_ISFIFO@plt>
cmp    $0x0,%rax
je     11e7 <do_get_type+0x77>
movb   $0x70,-0x1(%rbp)
jmp    123c <do_get_type+0xcc>
mov    -0x8(%rbp),%edi
call   1070 <S_ISREG@plt>
cmp    $0x0,%rax
je     1202 <do_get_type+0x92>
movb   $0x66,-0x1(%rbp)
jmp    123c <do_get_type+0xcc>
mov    -0x8(%rbp),%edi
call   1030 <S_ISLNK@plt>
cmp    $0x0,%rax
je     121d <do_get_type+0xad>
movb   $0x6c,-0x1(%rbp)
jmp    123c <do_get_type+0xcc>
mov    -0x8(%rbp),%edi
call   1050 <S_ISSOCK@plt>
cmp    $0x0,%rax
je     1238 <do_get_type+0xc8>
movb   $0x73,-0x1(%rbp)
jmp    123c <do_get_type+0xcc>
movb   $0x3f,-0x1(%rbp)
movsbl -0x1(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<do_get_type>:
push   %rbx
mov    %edi,%ebx
call   1090 <S_ISBLK@plt>
mov    %rax,%rcx
mov    $0x62,%al
test   %rcx,%rcx
je     1184 <do_get_type+0x14>
pop    %rbx
ret
mov    %ebx,%edi
call   1080 <S_ISCHR@plt>
mov    %rax,%rcx
mov    $0x63,%al
test   %rcx,%rcx
jne    1182 <do_get_type+0x12>
mov    %ebx,%edi
call   1060 <S_ISDIR@plt>
mov    %rax,%rcx
mov    $0x64,%al
test   %rcx,%rcx
jne    1182 <do_get_type+0x12>
mov    %ebx,%edi
call   1040 <S_ISFIFO@plt>
mov    %rax,%rcx
mov    $0x70,%al
test   %rcx,%rcx
jne    1182 <do_get_type+0x12>
mov    %ebx,%edi
call   1070 <S_ISREG@plt>
mov    %rax,%rcx
mov    $0x66,%al
test   %rcx,%rcx
jne    1182 <do_get_type+0x12>
mov    %ebx,%edi
call   1030 <S_ISLNK@plt>
mov    %rax,%rcx
mov    $0x6c,%al
test   %rcx,%rcx
jne    1182 <do_get_type+0x12>
mov    %ebx,%edi
call   1050 <S_ISSOCK@plt>
test   %rax,%rax
mov    $0x3f,%ecx
mov    $0x73,%eax
cmove  %ecx,%eax
pop    %rbx
ret

LLVM IR (-O0):
%struct.stat = type { i32 }
define signext i8 @do_get_type(i32 %0) {
%2 = alloca i8
%3 = alloca %struct.stat
%4 = getelementptr inbounds %struct.stat, %struct.stat* %3, i32 0, i32 0
store i32 %0, i32* %4
%5 = getelementptr inbounds %struct.stat, %struct.stat* %3, i32 0, i32 0
%6 = load i32, i32* %5
%7 = call i64 @S_ISBLK(i32 %6)
%8 = icmp ne i64 %7, 0
br i1 %8, label %9, label %10
9: ; preds = %1
store i8 98, i8* %2
br label %47
10: ; preds = %1
%11 = getelementptr inbounds %struct.stat, %struct.stat* %3, i32 0, i32 0
%12 = load i32, i32* %11
%13 = call i64 @S_ISCHR(i32 %12)
%14 = icmp ne i64 %13, 0
br i1 %14, label %15, label %16
15: ; preds = %10
store i8 99, i8* %2
br label %47
16: ; preds = %10
%17 = getelementptr inbounds %struct.stat, %struct.stat* %3, i32 0, i32 0
%18 = load i32, i32* %17
%19 = call i64 @S_ISDIR(i32 %18)
%20 = icmp ne i64 %19, 0
br i1 %20, label %21, label %22
21: ; preds = %16
store i8 100, i8* %2
br label %47
22: ; preds = %16
%23 = getelementptr inbounds %struct.stat, %struct.stat* %3, i32 0, i32 0
%24 = load i32, i32* %23
%25 = call i64 @S_ISFIFO(i32 %24)
%26 = icmp ne i64 %25, 0
br i1 %26, label %27, label %28
27: ; preds = %22
store i8 112, i8* %2
br label %47
28: ; preds = %22
%29 = getelementptr inbounds %struct.stat, %struct.stat* %3, i32 0, i32 0
%30 = load i32, i32* %29
%31 = call i64 @S_ISREG(i32 %30)
%32 = icmp ne i64 %31, 0
br i1 %32, label %33, label %34
33: ; preds = %28
store i8 102, i8* %2
br label %47
34: ; preds = %28
%35 = getelementptr inbounds %struct.stat, %struct.stat* %3, i32 0, i32 0
%36 = load i32, i32* %35
%37 = call i64 @S_ISLNK(i32 %36)
%38 = icmp ne i64 %37, 0
br i1 %38, label %39, label %40
39: ; preds = %34
store i8 108, i8* %2
br label %47
40: ; preds = %34
%41 = getelementptr inbounds %struct.stat, %struct.stat* %3, i32 0, i32 0
%42 = load i32, i32* %41
%43 = call i64 @S_ISSOCK(i32 %42)
%44 = icmp ne i64 %43, 0
br i1 %44, label %45, label %46
45: ; preds = %40
store i8 115, i8* %2
br label %47
46: ; preds = %40
store i8 63, i8* %2
br label %47
47: ; preds = %46, %45, %39, %33, %27, %21, %15, %9
%48 = load i8, i8* %2
ret i8 %48
}

LLVM IR (-O2):
define signext i8 @do_get_type(i32 %0) {
%2 = tail call i64 @S_ISBLK(i32 %0)
%3 = icmp eq i64 %2, 0
br i1 %3, label %4, label %23
4: ; preds = %1
%5 = tail call i64 @S_ISCHR(i32 %0)
%6 = icmp eq i64 %5, 0
br i1 %6, label %7, label %23
7: ; preds = %4
%8 = tail call i64 @S_ISDIR(i32 %0)
%9 = icmp eq i64 %8, 0
br i1 %9, label %10, label %23
10: ; preds = %7
%11 = tail call i64 @S_ISFIFO(i32 %0)
%12 = icmp eq i64 %11, 0
br i1 %12, label %13, label %23
13: ; preds = %10
%14 = tail call i64 @S_ISREG(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 63, i8 115
br label %23
23: ; preds = %19, %16, %13, %10, %7, %4, %1
%24 = phi i8 [ 98, %1 ], [ 99, %4 ], [ 100, %7 ], [ 112, %10 ], [ 102, %13 ], [ 108, %16 ], [ %22, %19 ]
ret i8 %24
}