#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*/ strncpy(char *, char *, int);
void permission_disp(short permissions, char *rtr) {
  int i;
  rtr[9] = '\0';
  for (i = 2; i >= 0; i--) {
    short permissionsId = permissions >> (i * 3) & (short)7;
    char *perm;
    switch (permissionsId) {
    case 7:
      perm = "rwx";
      break;
    case 6:
      perm = "rw-";
      break;
    case 5:
      perm = "r-x";
      break;
    case 4:
      perm = "r--";
      break;
    case 3:
      perm = "-wx";
      break;
    case 2:
      perm = "-w-";
      break;
    case 1:
      perm = "--x";
      break;
    case 0:
      perm = "---";
      break;
    default:
      perm = "???";
    }
    strncpy(rtr, perm, 3);
    rtr += 3;
  }
}


x86 assembly (clang, -O0):
<permission_disp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %di,%ax
mov    %ax,-0x2(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movb   $0x0,0x9(%rax)
movl   $0x2,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jl     122f <permission_disp+0x11f>
movswl -0x2(%rbp),%eax
mov    -0x14(%rbp),%edx
mov    %edx,%ecx
lea    (%rcx,%rcx,2),%ecx
sar    %cl,%eax
and    $0x7,%eax
mov    %ax,-0x16(%rbp)
movswl -0x16(%rbp),%eax
mov    %eax,%ecx
mov    %rcx,-0x28(%rbp)
sub    $0x7,%eax
ja     11f8 <permission_disp+0xe8>
mov    -0x28(%rbp),%rax
lea    0xe91(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
lea    0xea1(%rip),%rax
mov    %rax,-0x20(%rbp)
jmp    1203 <permission_disp+0xf3>
lea    0xe95(%rip),%rax
mov    %rax,-0x20(%rbp)
jmp    1203 <permission_disp+0xf3>
lea    0xe89(%rip),%rax
mov    %rax,-0x20(%rbp)
jmp    1203 <permission_disp+0xf3>
lea    0xe7d(%rip),%rax
mov    %rax,-0x20(%rbp)
jmp    1203 <permission_disp+0xf3>
lea    0xe71(%rip),%rax
mov    %rax,-0x20(%rbp)
jmp    1203 <permission_disp+0xf3>
lea    0xe65(%rip),%rax
mov    %rax,-0x20(%rbp)
jmp    1203 <permission_disp+0xf3>
lea    0xe59(%rip),%rax
mov    %rax,-0x20(%rbp)
jmp    1203 <permission_disp+0xf3>
lea    0xe4d(%rip),%rax
mov    %rax,-0x20(%rbp)
jmp    1203 <permission_disp+0xf3>
lea    0xe41(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    $0x3,%edx
call   1030 <strncpy@plt>
mov    -0x10(%rbp),%rax
add    $0x3,%rax
mov    %rax,-0x10(%rbp)
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
jmp    1132 <permission_disp+0x22>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<permission_disp>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r15
mov    %edi,%r14d
movb   $0x0,0x9(%rsi)
movzwl %r14w,%ebx
mov    %ebx,%eax
shr    $0x6,%eax
and    $0x7,%eax
lea    0x2cab(%rip),%r12
mov    (%r12,%rax,8),%rsi
mov    %r15,%rdi
mov    $0x3,%edx
call   1030 <strncpy@plt>
lea    0x3(%r15),%rdi
shr    $0x3,%ebx
and    $0x7,%ebx
mov    (%r12,%rbx,8),%rsi
mov    $0x3,%edx
call   1030 <strncpy@plt>
and    $0x7,%r14d
mov    (%r12,%r14,8),%rsi
add    $0x6,%r15
mov    %r15,%rdi
mov    $0x3,%edx
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1030 <strncpy@plt>

LLVM IR (-O0):
@.str = [4 x i8] c"rwx\00"
@.str.1 = [4 x i8] c"rw-\00"
@.str.2 = [4 x i8] c"r-x\00"
@.str.3 = [4 x i8] c"r--\00"
@.str.4 = [4 x i8] c"-wx\00"
@.str.5 = [4 x i8] c"-w-\00"
@.str.6 = [4 x i8] c"--x\00"
@.str.7 = [4 x i8] c"---\00"
@.str.8 = [4 x i8] c"???\00"
define void @permission_disp(i16 signext %0, i8* %1) {
%3 = alloca i16
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i16
%7 = alloca i8*
store i16 %0, i16* %3
store i8* %1, i8** %4
%8 = load i8*, i8** %4
%9 = getelementptr inbounds i8, i8* %8, i64 9
store i8 0, i8* %9
store i32 2, i32* %5
br label %10
10: ; preds = %38, %2
%11 = load i32, i32* %5
%12 = icmp sge i32 %11, 0
br i1 %12, label %13, label %41
13: ; preds = %10
%14 = load i16, i16* %3
%15 = sext i16 %14 to i32
%16 = load i32, i32* %5
%17 = mul nsw i32 %16, 3
%18 = ashr i32 %15, %17
%19 = and i32 %18, 7
%20 = trunc i32 %19 to i16
store i16 %20, i16* %6
%21 = load i16, i16* %6
%22 = sext i16 %21 to i32
switch i32 %22, label %31 [
i32 7, label %23
i32 6, label %24
i32 5, label %25
i32 4, label %26
i32 3, label %27
i32 2, label %28
i32 1, label %29
i32 0, label %30
]
23: ; preds = %13
store i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8** %7
br label %32
24: ; preds = %13
store i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8** %7
br label %32
25: ; preds = %13
store i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8** %7
br label %32
26: ; preds = %13
store i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8** %7
br label %32
27: ; preds = %13
store i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8** %7
br label %32
28: ; preds = %13
store i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i8** %7
br label %32
29: ; preds = %13
store i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), i8** %7
br label %32
30: ; preds = %13
store i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.7, i64 0, i64 0), i8** %7
br label %32
31: ; preds = %13
store i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.8, i64 0, i64 0), i8** %7
br label %32
32: ; preds = %31, %30, %29, %28, %27, %26, %25, %24, %23
%33 = load i8*, i8** %4
%34 = load i8*, i8** %7
%35 = call i32 @strncpy(i8* %33, i8* %34, i32 3)
%36 = load i8*, i8** %4
%37 = getelementptr inbounds i8, i8* %36, i64 3
store i8* %37, i8** %4
br label %38
38: ; preds = %32
%39 = load i32, i32* %5
%40 = add nsw i32 %39, -1
store i32 %40, i32* %5
br label %10
41: ; preds = %10
ret void
}

LLVM IR (-O2):
@.str = [4 x i8] c"rwx\00"
@.str.1 = [4 x i8] c"rw-\00"
@.str.2 = [4 x i8] c"r-x\00"
@.str.3 = [4 x i8] c"r--\00"
@.str.4 = [4 x i8] c"-wx\00"
@.str.5 = [4 x i8] c"-w-\00"
@.str.6 = [4 x i8] c"--x\00"
@.str.7 = [4 x i8] c"---\00"
@switch.table.permission_disp.10 = [8 x i8*] [i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.7, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0)]
define void @permission_disp(i16 signext %0, i8* %1) {
%3 = getelementptr inbounds i8, i8* %1, i64 9
store i8 0, i8* %3
%4 = zext i16 %0 to i32
%5 = lshr i32 %4, 6
%6 = and i32 %5, 7
%7 = zext i32 %6 to i64
%8 = getelementptr inbounds [8 x i8*], [8 x i8*]* @switch.table.permission_disp.10, i64 0, i64 %7
%9 = load i8*, i8** %8
%10 = tail call i32 @strncpy(i8* %1, i8* %9, i32 3)
%11 = getelementptr inbounds i8, i8* %1, i64 3
%12 = lshr i32 %4, 3
%13 = and i32 %12, 7
%14 = zext i32 %13 to i64
%15 = getelementptr inbounds [8 x i8*], [8 x i8*]* @switch.table.permission_disp.10, i64 0, i64 %14
%16 = load i8*, i8** %15
%17 = tail call i32 @strncpy(i8* %11, i8* %16, i32 3)
%18 = and i32 %4, 7
%19 = zext i32 %18 to i64
%20 = getelementptr inbounds [8 x i8*], [8 x i8*]* @switch.table.permission_disp.10, i64 0, i64 %19
%21 = load i8*, i8** %20
%22 = getelementptr inbounds i8, i8* %1, i64 6
%23 = tail call i32 @strncpy(i8* %22, i8* %21, i32 3)
ret void
}