#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 */

/* Variables and functions */
int /*<<< orphan*/ printf(char *);
int print_permissions(int mode) {
  int temp, i, type;
  type = mode >> 12;
  switch (type) {
  case 1:
    printf("f");
    break;
  case 2:
    printf("c");
    break;
  case 4:
    printf("d");
    break;
  case 6:
    printf("b");
    break;
  case 8:
    printf("-");
    break;
  case 10:
    printf("l");
    break;
  case 12:
    printf("s");
    break;
  default:
    printf("?");
  }
  temp = mode & 0x1ff;
  for (i = 6; i >= 0; i -= 3) {
    if (temp & (0x4 << i))
      printf("r");
    else
      printf("-");
    if (temp & (0x2 << i))
      printf("w");
    else
      printf("-");
    if (temp & (0x1 << i))
      printf("x");
    else
      printf("-");
  }
  return 0;
}


x86 assembly (clang, -O0):
<print_permissions>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%eax
sar    $0xc,%eax
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,%ecx
mov    %rcx,-0x18(%rbp)
sub    $0xb,%eax
ja     11c4 <print_permissions+0xb4>
mov    -0x18(%rbp),%rax
lea    0xebc(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
lea    0xedc(%rip),%rdi
call   1030 <printf@plt>
jmp    11d0 <print_permissions+0xc0>
lea    0xecd(%rip),%rdi
call   1030 <printf@plt>
jmp    11d0 <print_permissions+0xc0>
lea    0xebe(%rip),%rdi
call   1030 <printf@plt>
jmp    11d0 <print_permissions+0xc0>
lea    0xeaf(%rip),%rdi
call   1030 <printf@plt>
jmp    11d0 <print_permissions+0xc0>
lea    0xea0(%rip),%rdi
call   1030 <printf@plt>
jmp    11d0 <print_permissions+0xc0>
lea    0xe91(%rip),%rdi
call   1030 <printf@plt>
jmp    11d0 <print_permissions+0xc0>
lea    0xe82(%rip),%rdi
call   1030 <printf@plt>
jmp    11d0 <print_permissions+0xc0>
lea    0xe73(%rip),%rdi
call   1030 <printf@plt>
mov    -0x4(%rbp),%eax
and    $0x1ff,%eax
mov    %eax,-0x8(%rbp)
movl   $0x6,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jl     12a4 <print_permissions+0x194>
mov    -0x8(%rbp),%eax
mov    -0xc(%rbp),%ecx
mov    $0x4,%edx
shl    %cl,%edx
mov    %edx,%ecx
and    %ecx,%eax
cmp    $0x0,%eax
je     1217 <print_permissions+0x107>
lea    0xe33(%rip),%rdi
call   1030 <printf@plt>
jmp    1223 <print_permissions+0x113>
lea    0xe1a(%rip),%rdi
call   1030 <printf@plt>
mov    -0x8(%rbp),%eax
mov    -0xc(%rbp),%ecx
mov    $0x2,%edx
shl    %cl,%edx
mov    %edx,%ecx
and    %ecx,%eax
cmp    $0x0,%eax
je     124e <print_permissions+0x13e>
lea    0xdfe(%rip),%rdi
call   1030 <printf@plt>
jmp    125a <print_permissions+0x14a>
lea    0xde3(%rip),%rdi
call   1030 <printf@plt>
mov    -0x8(%rbp),%eax
mov    -0xc(%rbp),%ecx
mov    $0x1,%edx
shl    %cl,%edx
mov    %edx,%ecx
and    %ecx,%eax
cmp    $0x0,%eax
je     1285 <print_permissions+0x175>
lea    0xdc9(%rip),%rdi
call   1030 <printf@plt>
jmp    1291 <print_permissions+0x181>
lea    0xdac(%rip),%rdi
call   1030 <printf@plt>
jmp    1296 <print_permissions+0x186>
mov    -0xc(%rbp),%eax
sub    $0x3,%eax
mov    %eax,-0xc(%rbp)
jmp    11e2 <print_permissions+0xd2>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_permissions>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %edi,%ebx
mov    %edi,%eax
sar    $0xc,%eax
add    $0xffffffff,%eax
mov    $0x3f,%edi
cmp    $0xb,%eax
ja     1138 <print_permissions+0x28>
cltq
lea    0xeeb(%rip),%rcx
mov    (%rcx,%rax,4),%edi
call   1030 <putchar@plt>
test   $0x100,%ebx
mov    $0x2d,%r15d
mov    $0x72,%r14d
mov    $0x72,%edi
cmove  %r15d,%edi
call   1030 <putchar@plt>
movd   %ebx,%xmm0
pshufd $0x0,%xmm0,%xmm0
movdqa 0xe92(%rip),%xmm1
pand   %xmm0,%xmm1
pand   0xe96(%rip),%xmm0
pxor   %xmm2,%xmm2
pcmpeqd %xmm2,%xmm0
pcmpeqd %xmm2,%xmm1
packssdw %xmm0,%xmm1
packsswb %xmm1,%xmm1
pmovmskb %xmm1,%ebp
test   $0x80,%bpl
mov    $0x77,%r12d
mov    $0x77,%edi
cmovne %r15d,%edi
call   1030 <putchar@plt>
test   $0x40,%bpl
mov    $0x78,%ebx
mov    $0x78,%edi
cmovne %r15d,%edi
call   1030 <putchar@plt>
test   $0x20,%bpl
mov    $0x72,%edi
cmovne %r15d,%edi
call   1030 <putchar@plt>
test   $0x10,%bpl
mov    $0x77,%edi
cmovne %r15d,%edi
call   1030 <putchar@plt>
test   $0x8,%bpl
mov    $0x78,%edi
cmovne %r15d,%edi
call   1030 <putchar@plt>
test   $0x4,%bpl
cmovne %r15d,%r14d
mov    %r14d,%edi
call   1030 <putchar@plt>
test   $0x2,%bpl
cmovne %r15d,%r12d
mov    %r12d,%edi
call   1030 <putchar@plt>
test   $0x1,%bpl
cmovne %r15d,%ebx
mov    %ebx,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"f\00"
@.str.1 = [2 x i8] c"c\00"
@.str.2 = [2 x i8] c"d\00"
@.str.3 = [2 x i8] c"b\00"
@.str.4 = [2 x i8] c"-\00"
@.str.5 = [2 x i8] c"l\00"
@.str.6 = [2 x i8] c"s\00"
@.str.7 = [2 x i8] c"?\00"
@.str.8 = [2 x i8] c"r\00"
@.str.9 = [2 x i8] c"w\00"
@.str.10 = [2 x i8] c"x\00"
define i32 @print_permissions(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 %0, i32* %2
%6 = load i32, i32* %2
%7 = ashr i32 %6, 12
store i32 %7, i32* %5
%8 = load i32, i32* %5
switch i32 %8, label %23 [
i32 1, label %9
i32 2, label %11
i32 4, label %13
i32 6, label %15
i32 8, label %17
i32 10, label %19
i32 12, label %21
]
9: ; preds = %1
%10 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
br label %25
11: ; preds = %1
%12 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %25
13: ; preds = %1
%14 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
br label %25
15: ; preds = %1
%16 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
br label %25
17: ; preds = %1
%18 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
br label %25
19: ; preds = %1
%20 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
br label %25
21: ; preds = %1
%22 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
br label %25
23: ; preds = %1
%24 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0))
br label %25
25: ; preds = %23, %21, %19, %17, %15, %13, %11, %9
%26 = load i32, i32* %2
%27 = and i32 %26, 511
store i32 %27, i32* %3
store i32 6, i32* %4
br label %28
28: ; preds = %62, %25
%29 = load i32, i32* %4
%30 = icmp sge i32 %29, 0
br i1 %30, label %31, label %65
31: ; preds = %28
%32 = load i32, i32* %3
%33 = load i32, i32* %4
%34 = shl i32 4, %33
%35 = and i32 %32, %34
%36 = icmp ne i32 %35, 0
br i1 %36, label %37, label %39
37: ; preds = %31
%38 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.8, i64 0, i64 0))
br label %41
39: ; preds = %31
%40 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
br label %41
41: ; preds = %39, %37
%42 = load i32, i32* %3
%43 = load i32, i32* %4
%44 = shl i32 2, %43
%45 = and i32 %42, %44
%46 = icmp ne i32 %45, 0
br i1 %46, label %47, label %49
47: ; preds = %41
%48 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.9, i64 0, i64 0))
br label %51
49: ; preds = %41
%50 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
br label %51
51: ; preds = %49, %47
%52 = load i32, i32* %3
%53 = load i32, i32* %4
%54 = shl i32 1, %53
%55 = and i32 %52, %54
%56 = icmp ne i32 %55, 0
br i1 %56, label %57, label %59
57: ; preds = %51
%58 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.10, i64 0, i64 0))
br label %61
59: ; preds = %51
%60 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
br label %61
61: ; preds = %59, %57
br label %62
62: ; preds = %61
%63 = load i32, i32* %4
%64 = sub nsw i32 %63, 3
store i32 %64, i32* %4
br label %28
65: ; preds = %28
ret i32 0
}

LLVM IR (-O2):
@switch.table.print_permissions = [12 x i32] [i32 102, i32 99, i32 63, i32 100, i32 63, i32 98, i32 63, i32 45, i32 63, i32 108, i32 63, i32 115]
define i32 @print_permissions(i32 %0) {
%2 = ashr i32 %0, 12
%3 = add nsw i32 %2, -1
%4 = icmp ult i32 %3, 12
br i1 %4, label %5, label %9
5: ; preds = %1
%6 = sext i32 %3 to i64
%7 = getelementptr inbounds [12 x i32], [12 x i32]* @switch.table.print_permissions, i64 0, i64 %6
%8 = load i32, i32* %7
br label %9
9: ; preds = %1, %5
%10 = phi i32 [ %8, %5 ], [ 63, %1 ]
%11 = tail call i32 @putchar(i32 %10)
%12 = and i32 %0, 256
%13 = icmp eq i32 %12, 0
%14 = select i1 %13, i32 45, i32 114
%15 = tail call i32 @putchar(i32 %14)
%16 = insertelement <8 x i32> poison, i32 %0, i64 0
%17 = shufflevector <8 x i32> %16, <8 x i32> poison, <8 x i32> zeroinitializer
%18 = and <8 x i32> %17, <i32 1, i32 2, i32 4, i32 8, i32 16, i32 32, i32 64, i32 128>
%19 = icmp eq <8 x i32> %18, zeroinitializer
%20 = extractelement <8 x i1> %19, i64 7
%21 = select i1 %20, i32 45, i32 119
%22 = tail call i32 @putchar(i32 %21)
%23 = extractelement <8 x i1> %19, i64 6
%24 = select i1 %23, i32 45, i32 120
%25 = tail call i32 @putchar(i32 %24)
%26 = extractelement <8 x i1> %19, i64 5
%27 = select i1 %26, i32 45, i32 114
%28 = tail call i32 @putchar(i32 %27)
%29 = extractelement <8 x i1> %19, i64 4
%30 = select i1 %29, i32 45, i32 119
%31 = tail call i32 @putchar(i32 %30)
%32 = extractelement <8 x i1> %19, i64 3
%33 = select i1 %32, i32 45, i32 120
%34 = tail call i32 @putchar(i32 %33)
%35 = extractelement <8 x i1> %19, i64 2
%36 = select i1 %35, i32 45, i32 114
%37 = tail call i32 @putchar(i32 %36)
%38 = extractelement <8 x i1> %19, i64 1
%39 = select i1 %38, i32 45, i32 119
%40 = tail call i32 @putchar(i32 %39)
%41 = extractelement <8 x i1> %19, i64 0
%42 = select i1 %41, i32 45, i32 120
%43 = tail call i32 @putchar(i32 %42)
ret i32 0
}