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

/* Variables and functions */
#define S_IFBLK 131
#define S_IFCHR 130
#define S_IFDIR 129
#define S_IFLNK 128
int S_IFMT;
scalar_t__ S_ISFIFO(int);
scalar_t__ S_ISSOCK(int);
char mode2c(mode_t t) {
  switch (t & S_IFMT) {
  case S_IFBLK:
    return 'b';
  case S_IFCHR:
    return 'c';
  case S_IFDIR:
    return 'd';
  case S_IFLNK:
    return 'l';
  }
  if (S_ISFIFO(t))
    return 'f';
  if (S_ISSOCK(t))
    return 's';
  return '-';
}


x86 assembly (clang, -O0):
<mode2c>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
mov    -0x8(%rbp),%eax
mov    0x2eab(%rip),%rcx
mov    (%rcx),%ecx
and    %ecx,%eax
add    $0xffffff80,%eax
mov    %eax,%ecx
mov    %rcx,-0x10(%rbp)
sub    $0x3,%eax
ja     1183 <mode2c+0x63>
mov    -0x10(%rbp),%rax
lea    0xeaa(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
movb   $0x62,-0x1(%rbp)
jmp    11bd <mode2c+0x9d>
movb   $0x63,-0x1(%rbp)
jmp    11bd <mode2c+0x9d>
movb   $0x64,-0x1(%rbp)
jmp    11bd <mode2c+0x9d>
movb   $0x6c,-0x1(%rbp)
jmp    11bd <mode2c+0x9d>
mov    -0x8(%rbp),%edi
call   1030 <S_ISFIFO@plt>
cmp    $0x0,%rax
je     119e <mode2c+0x7e>
movb   $0x66,-0x1(%rbp)
jmp    11bd <mode2c+0x9d>
mov    -0x8(%rbp),%edi
call   1040 <S_ISSOCK@plt>
cmp    $0x0,%rax
je     11b9 <mode2c+0x99>
movb   $0x73,-0x1(%rbp)
jmp    11bd <mode2c+0x9d>
movb   $0x2d,-0x1(%rbp)
movsbl -0x1(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mode2c>:
push   %rbx
mov    0x2eb8(%rip),%rax
mov    (%rax),%ecx
and    %edi,%ecx
add    $0xffffff80,%ecx
cmp    $0x4,%ecx
jae    1140 <mode2c+0x20>
shl    $0x3,%ecx
mov    $0x6263646c,%eax
shr    %cl,%eax
pop    %rbx
ret
mov    %edi,%ebx
call   1030 <S_ISFIFO@plt>
mov    %rax,%rcx
mov    $0x66,%al
test   %rcx,%rcx
jne    113e <mode2c+0x1e>
mov    %ebx,%edi
call   1040 <S_ISSOCK@plt>
test   %rax,%rax
mov    $0x2d,%ecx
mov    $0x73,%eax
cmove  %ecx,%eax
pop    %rbx
ret

LLVM IR (-O0):
@S_IFMT = global i32 0
define signext i8 @mode2c(i32 %0) {
%2 = alloca i8
%3 = alloca i32
store i32 %0, i32* %3
%4 = load i32, i32* %3
%5 = load i32, i32* @S_IFMT
%6 = and i32 %4, %5
switch i32 %6, label %11 [
i32 131, label %7
i32 130, label %8
i32 129, label %9
i32 128, label %10
]
7: ; preds = %1
store i8 98, i8* %2
br label %22
8: ; preds = %1
store i8 99, i8* %2
br label %22
9: ; preds = %1
store i8 100, i8* %2
br label %22
10: ; preds = %1
store i8 108, i8* %2
br label %22
11: ; preds = %1
%12 = load i32, i32* %3
%13 = call i64 @S_ISFIFO(i32 %12)
%14 = icmp ne i64 %13, 0
br i1 %14, label %15, label %16
15: ; preds = %11
store i8 102, i8* %2
br label %22
16: ; preds = %11
%17 = load i32, i32* %3
%18 = call i64 @S_ISSOCK(i32 %17)
%19 = icmp ne i64 %18, 0
br i1 %19, label %20, label %21
20: ; preds = %16
store i8 115, i8* %2
br label %22
21: ; preds = %16
store i8 45, i8* %2
br label %22
22: ; preds = %21, %20, %15, %10, %9, %8, %7
%23 = load i8, i8* %2
ret i8 %23
}

LLVM IR (-O2):
@S_IFMT = global i32 0
define signext i8 @mode2c(i32 %0) {
%2 = load i32, i32* @S_IFMT
%3 = and i32 %2, %0
%4 = add i32 %3, -128
%5 = icmp ult i32 %4, 4
br i1 %5, label %13, label %6
6: ; preds = %1
%7 = tail call i64 @S_ISFIFO(i32 %0)
%8 = icmp eq i64 %7, 0
br i1 %8, label %9, label %17
9: ; preds = %6
%10 = tail call i64 @S_ISSOCK(i32 %0)
%11 = icmp eq i64 %10, 0
%12 = select i1 %11, i8 45, i8 115
br label %17
13: ; preds = %1
%14 = shl i32 %4, 3
%15 = lshr i32 1650680940, %14
%16 = trunc i32 %15 to i8
br label %17
17: ; preds = %13, %9, %6
%18 = phi i8 [ 102, %6 ], [ %12, %9 ], [ %16, %13 ]
ret i8 %18
}