#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 u_int;

/* 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 /*<<< orphan*/ putchar(char);
void printtype(u_int mode) {
  char type;
  switch (mode & S_IFMT) {
  case S_IFIFO:
    type = 'p';
    break;
  case S_IFCHR:
    type = 'c';
    break;
  case S_IFDIR:
    type = 'd';
    break;
  case S_IFBLK:
    type = 'b';
    break;
  case S_IFLNK:
    type = 'l';
    break;
  case S_IFSOCK:
    type = 's';
    break;
  case S_IFREG:
  default:
    type = '-';
    break;
  }
  putchar(type);
}


x86 assembly (clang, -O0):
<printtype>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%eax
mov    0x2ebb(%rip),%rcx
mov    (%rcx),%ecx
and    %ecx,%eax
add    $0xffffff80,%eax
mov    %eax,%ecx
mov    %rcx,-0x10(%rbp)
sub    $0x6,%eax
ja     118a <printtype+0x7a>
mov    -0x10(%rbp),%rax
lea    0xeba(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
movb   $0x70,-0x5(%rbp)
jmp    118e <printtype+0x7e>
movb   $0x63,-0x5(%rbp)
jmp    118e <printtype+0x7e>
movb   $0x64,-0x5(%rbp)
jmp    118e <printtype+0x7e>
movb   $0x62,-0x5(%rbp)
jmp    118e <printtype+0x7e>
movb   $0x6c,-0x5(%rbp)
jmp    118e <printtype+0x7e>
movb   $0x73,-0x5(%rbp)
jmp    118e <printtype+0x7e>
jmp    118a <printtype+0x7a>
movb   $0x2d,-0x5(%rbp)
movsbl -0x5(%rbp),%edi
call   1030 <putchar@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<printtype>:
mov    0x2ec9(%rip),%rax
and    (%rax),%edi
lea    -0x400(,%rdi,8),%ecx
mov    %edi,%eax
add    $0xffffff80,%eax
movabs $0x626364706c2d73,%rdx
shr    %cl,%rdx
cmp    $0x7,%eax
mov    $0x2d,%eax
cmovb  %edx,%eax
movsbl %al,%edi
jmp    1030 <putchar@plt>

LLVM IR (-O0):
@S_IFMT = global i32 0
define void @printtype(i32 %0) {
%2 = alloca i32
%3 = alloca i8
store i32 %0, i32* %2
%4 = load i32, i32* %2
%5 = load i32, i32* @S_IFMT
%6 = and i32 %4, %5
switch i32 %6, label %14 [
i32 131, label %7
i32 133, label %8
i32 132, label %9
i32 134, label %10
i32 130, label %11
i32 128, label %12
i32 129, label %13
]
7: ; preds = %1
store i8 112, i8* %3
br label %15
8: ; preds = %1
store i8 99, i8* %3
br label %15
9: ; preds = %1
store i8 100, i8* %3
br label %15
10: ; preds = %1
store i8 98, i8* %3
br label %15
11: ; preds = %1
store i8 108, i8* %3
br label %15
12: ; preds = %1
store i8 115, i8* %3
br label %15
13: ; preds = %1
br label %14
14: ; preds = %1, %13
store i8 45, i8* %3
br label %15
15: ; preds = %14, %12, %11, %10, %9, %8, %7
%16 = load i8, i8* %3
%17 = call i32 @putchar(i8 signext %16)
ret void
}

LLVM IR (-O2):
@S_IFMT = global i32 0
define void @printtype(i32 %0) {
%2 = load i32, i32* @S_IFMT
%3 = and i32 %2, %0
%4 = add i32 %3, -128
%5 = icmp ult i32 %4, 7
%6 = zext i32 %4 to i56
%7 = shl nuw nsw i56 %6, 3
%8 = lshr i56 27693830751661427, %7
%9 = trunc i56 %8 to i8
%10 = select i1 %5, i8 %9, i8 45
%11 = tail call i32 @putchar(i8 signext %10)
ret void
}