#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 */
int S_IEXEC;
int S_IREAD;
int S_IWRITE;
char *perm(mode_t mode) {
  int i;
  static char perms[10] = "---------";
  for (i = 0; i < 3; i++) {
    if (mode & (S_IREAD >> i * 3))
      perms[i * 3] = 'r';
    if (mode & (S_IWRITE >> i * 3))
      perms[i * 3 + 1] = 'w';
    if (mode & (S_IEXEC >> i * 3))
      perms[i * 3 + 2] = 'x';
  }
  return (perms);
}


x86 assembly (clang, -O0):
<perm>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
cmpl   $0x3,-0x8(%rbp)
jge    11c4 <perm+0xc4>
mov    -0x4(%rbp),%eax
mov    0x2eae(%rip),%rcx
mov    (%rcx),%edx
imul   $0x3,-0x8(%rbp),%ecx
sar    %cl,%edx
mov    %edx,%ecx
and    %ecx,%eax
cmp    $0x0,%eax
je     1149 <perm+0x49>
imul   $0x3,-0x8(%rbp),%eax
movslq %eax,%rcx
lea    0x2edb(%rip),%rax
movb   $0x72,(%rax,%rcx,1)
mov    -0x4(%rbp),%eax
mov    0x2e95(%rip),%rcx
mov    (%rcx),%edx
imul   $0x3,-0x8(%rbp),%ecx
sar    %cl,%edx
mov    %edx,%ecx
and    %ecx,%eax
cmp    $0x0,%eax
je     117d <perm+0x7d>
imul   $0x3,-0x8(%rbp),%eax
add    $0x1,%eax
movslq %eax,%rcx
lea    0x2ea7(%rip),%rax
movb   $0x77,(%rax,%rcx,1)
mov    -0x4(%rbp),%eax
mov    0x2e51(%rip),%rcx
mov    (%rcx),%edx
imul   $0x3,-0x8(%rbp),%ecx
sar    %cl,%edx
mov    %edx,%ecx
and    %ecx,%eax
cmp    $0x0,%eax
je     11b1 <perm+0xb1>
imul   $0x3,-0x8(%rbp),%eax
add    $0x2,%eax
movslq %eax,%rcx
lea    0x2e73(%rip),%rax
movb   $0x78,(%rax,%rcx,1)
jmp    11b6 <perm+0xb6>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    110e <perm+0xe>
lea    0x2e55(%rip),%rax
pop    %rbp
ret

x86 assembly (clang, -O2):
<perm>:
mov    0x2ec9(%rip),%rax
mov    (%rax),%edx
mov    0x2ed8(%rip),%rax
mov    (%rax),%eax
mov    0x2ebf(%rip),%rcx
test   %edi,%edx
je     1124 <perm+0x24>
movb   $0x72,0x2efc(%rip)
mov    (%rcx),%ecx
test   %edi,%eax
je     1131 <perm+0x31>
movb   $0x77,0x2ef0(%rip)
test   %edi,%ecx
je     113c <perm+0x3c>
movb   $0x78,0x2ee6(%rip)
mov    %edx,%esi
sar    $0x3,%esi
test   %edi,%esi
je     114c <perm+0x4c>
movb   $0x72,0x2ed7(%rip)
mov    %eax,%esi
sar    $0x3,%esi
test   %edi,%esi
je     115c <perm+0x5c>
movb   $0x77,0x2ec8(%rip)
mov    %ecx,%esi
sar    $0x3,%esi
test   %edi,%esi
je     116c <perm+0x6c>
movb   $0x78,0x2eb9(%rip)
sar    $0x6,%edx
test   %edi,%edx
je     117a <perm+0x7a>
movb   $0x72,0x2eac(%rip)
sar    $0x6,%eax
test   %edi,%eax
je     1188 <perm+0x88>
movb   $0x77,0x2e9f(%rip)
sar    $0x6,%ecx
test   %edi,%ecx
je     1196 <perm+0x96>
movb   $0x78,0x2e92(%rip)
lea    0x2e83(%rip),%rax
ret

LLVM IR (-O0):
@perm.perms = internal global [10 x i8] c"---------\00"
@S_IREAD = global i32 0
@S_IWRITE = global i32 0
@S_IEXEC = global i32 0
define i8* @perm(i32 %0) {
%2 = alloca i32
%3 = alloca i32
store i32 %0, i32* %2
store i32 0, i32* %3
br label %4
4: ; preds = %49, %1
%5 = load i32, i32* %3
%6 = icmp slt i32 %5, 3
br i1 %6, label %7, label %52
7: ; preds = %4
%8 = load i32, i32* %2
%9 = load i32, i32* @S_IREAD
%10 = load i32, i32* %3
%11 = mul nsw i32 %10, 3
%12 = ashr i32 %9, %11
%13 = and i32 %8, %12
%14 = icmp ne i32 %13, 0
br i1 %14, label %15, label %20
15: ; preds = %7
%16 = load i32, i32* %3
%17 = mul nsw i32 %16, 3
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds [10 x i8], [10 x i8]* @perm.perms, i64 0, i64 %18
store i8 114, i8* %19
br label %20
20: ; preds = %15, %7
%21 = load i32, i32* %2
%22 = load i32, i32* @S_IWRITE
%23 = load i32, i32* %3
%24 = mul nsw i32 %23, 3
%25 = ashr i32 %22, %24
%26 = and i32 %21, %25
%27 = icmp ne i32 %26, 0
br i1 %27, label %28, label %34
28: ; preds = %20
%29 = load i32, i32* %3
%30 = mul nsw i32 %29, 3
%31 = add nsw i32 %30, 1
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds [10 x i8], [10 x i8]* @perm.perms, i64 0, i64 %32
store i8 119, i8* %33
br label %34
34: ; preds = %28, %20
%35 = load i32, i32* %2
%36 = load i32, i32* @S_IEXEC
%37 = load i32, i32* %3
%38 = mul nsw i32 %37, 3
%39 = ashr i32 %36, %38
%40 = and i32 %35, %39
%41 = icmp ne i32 %40, 0
br i1 %41, label %42, label %48
42: ; preds = %34
%43 = load i32, i32* %3
%44 = mul nsw i32 %43, 3
%45 = add nsw i32 %44, 2
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds [10 x i8], [10 x i8]* @perm.perms, i64 0, i64 %46
store i8 120, i8* %47
br label %48
48: ; preds = %42, %34
br label %49
49: ; preds = %48
%50 = load i32, i32* %3
%51 = add nsw i32 %50, 1
store i32 %51, i32* %3
br label %4
52: ; preds = %4
ret i8* getelementptr inbounds ([10 x i8], [10 x i8]* @perm.perms, i64 0, i64 0)
}

LLVM IR (-O2):
@perm.perms = internal global [10 x i8] c"---------\00"
@S_IREAD = global i32 0
@S_IWRITE = global i32 0
@S_IEXEC = global i32 0
define i8* @perm(i32 %0) {
%2 = load i32, i32* @S_IREAD
%3 = load i32, i32* @S_IWRITE
%4 = load i32, i32* @S_IEXEC
%5 = and i32 %2, %0
%6 = icmp eq i32 %5, 0
br i1 %6, label %8, label %7
7: ; preds = %1
store i8 114, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @perm.perms, i64 0, i64 0)
br label %8
8: ; preds = %7, %1
%9 = and i32 %3, %0
%10 = icmp eq i32 %9, 0
br i1 %10, label %12, label %11
11: ; preds = %8
store i8 119, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @perm.perms, i64 0, i64 1)
br label %12
12: ; preds = %11, %8
%13 = and i32 %4, %0
%14 = icmp eq i32 %13, 0
br i1 %14, label %16, label %15
15: ; preds = %12
store i8 120, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @perm.perms, i64 0, i64 2)
br label %16
16: ; preds = %12, %15
%17 = ashr i32 %2, 3
%18 = and i32 %17, %0
%19 = icmp eq i32 %18, 0
br i1 %19, label %21, label %20
20: ; preds = %16
store i8 114, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @perm.perms, i64 0, i64 3)
br label %21
21: ; preds = %20, %16
%22 = ashr i32 %3, 3
%23 = and i32 %22, %0
%24 = icmp eq i32 %23, 0
br i1 %24, label %26, label %25
25: ; preds = %21
store i8 119, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @perm.perms, i64 0, i64 4)
br label %26
26: ; preds = %25, %21
%27 = ashr i32 %4, 3
%28 = and i32 %27, %0
%29 = icmp eq i32 %28, 0
br i1 %29, label %31, label %30
30: ; preds = %26
store i8 120, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @perm.perms, i64 0, i64 5)
br label %31
31: ; preds = %30, %26
%32 = ashr i32 %2, 6
%33 = and i32 %32, %0
%34 = icmp eq i32 %33, 0
br i1 %34, label %36, label %35
35: ; preds = %31
store i8 114, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @perm.perms, i64 0, i64 6)
br label %36
36: ; preds = %35, %31
%37 = ashr i32 %3, 6
%38 = and i32 %37, %0
%39 = icmp eq i32 %38, 0
br i1 %39, label %41, label %40
40: ; preds = %36
store i8 119, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @perm.perms, i64 0, i64 7)
br label %41
41: ; preds = %40, %36
%42 = ashr i32 %4, 6
%43 = and i32 %42, %0
%44 = icmp eq i32 %43, 0
br i1 %44, label %46, label %45
45: ; preds = %41
store i8 120, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @perm.perms, i64 0, i64 8)
br label %46
46: ; preds = %45, %41
ret i8* getelementptr inbounds ([10 x i8], [10 x i8]* @perm.perms, i64 0, i64 0)
}