#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_IRGRP 136
#define S_IROTH 135
#define S_IRUSR 134
#define S_IWGRP 133
#define S_IWOTH 132
#define S_IWUSR 131
#define S_IXGRP 130
#define S_IXOTH 129
#define S_IXUSR 128
void compute_access(mode_t mode, char *access_str) {
  static int access[] = {S_IRUSR, S_IWUSR, S_IXUSR, S_IRGRP, S_IWGRP,
                         S_IXGRP, S_IROTH, S_IWOTH, S_IXOTH};
  static char rwx[] = {'r', 'w', 'x'};
  unsigned int i;
  for (i = 0; i < 9; ++i) {
    if (access[i] & mode) {
      access_str[i] = rwx[i % 3];
    } else {
      access_str[i] = '-';
    }
  }
  access_str[9] = '\0';
}


x86 assembly (clang, -O0):
<compute_access>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
cmpl   $0x9,-0x14(%rbp)
jae    117e <compute_access+0x7e>
mov    -0x14(%rbp),%eax
mov    %eax,%ecx
lea    0x2f08(%rip),%rax
mov    (%rax,%rcx,4),%eax
and    -0x4(%rbp),%eax
cmp    $0x0,%eax
je     1160 <compute_access+0x60>
mov    -0x14(%rbp),%eax
mov    $0x3,%ecx
xor    %edx,%edx
div    %ecx
mov    %edx,%eax
mov    %eax,%ecx
lea    0x2f06(%rip),%rax
mov    (%rax,%rcx,1),%dl
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
mov    %dl,(%rax,%rcx,1)
jmp    116b <compute_access+0x6b>
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
movb   $0x2d,(%rax,%rcx,1)
jmp    1170 <compute_access+0x70>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1112 <compute_access+0x12>
mov    -0x10(%rbp),%rax
movb   $0x0,0x9(%rax)
pop    %rbp
ret

x86 assembly (clang, -O2):
<compute_access>:
test   $0x86,%dil
mov    $0x2d,%r9d
mov    $0x72,%r8d
mov    $0x72,%edx
cmove  %r9d,%edx
mov    %dl,(%rsi)
movd   %edi,%xmm0
pshufd $0x0,%xmm0,%xmm0
movdqa 0xed4(%rip),%xmm1
pand   %xmm0,%xmm1
pand   0xed8(%rip),%xmm0
pxor   %xmm2,%xmm2
pcmpeqd %xmm2,%xmm0
pcmpeqd %xmm2,%xmm1
packssdw %xmm0,%xmm1
packsswb %xmm1,%xmm1
pmovmskb %xmm1,%edx
test   $0x80,%dl
mov    $0x77,%ecx
cmovne %r9d,%ecx
mov    $0x77,%edi
mov    %cl,0x1(%rsi)
test   $0x40,%dl
mov    $0x78,%ecx
cmovne %r9d,%ecx
mov    %cl,0x2(%rsi)
test   $0x20,%dl
mov    $0x72,%ecx
cmovne %r9d,%ecx
mov    %cl,0x3(%rsi)
test   $0x10,%dl
mov    $0x77,%ecx
cmovne %r9d,%ecx
mov    $0x78,%eax
mov    %cl,0x4(%rsi)
test   $0x8,%dl
mov    $0x78,%ecx
cmovne %r9d,%ecx
mov    %cl,0x5(%rsi)
test   $0x4,%dl
cmovne %r9d,%r8d
mov    %r8b,0x6(%rsi)
test   $0x2,%dl
cmovne %r9d,%edi
mov    %dil,0x7(%rsi)
test   $0x1,%dl
cmovne %r9d,%eax
mov    %al,0x8(%rsi)
movb   $0x0,0x9(%rsi)
ret

LLVM IR (-O0):
@compute_access.access = internal global [9 x i32] [i32 134, i32 131, i32 128, i32 136, i32 133, i32 130, i32 135, i32 132, i32 129]
@compute_access.rwx = internal global [3 x i8] c"rwx"
define void @compute_access(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
store i32 %0, i32* %3
store i8* %1, i8** %4
store i32 0, i32* %5
br label %6
6: ; preds = %33, %2
%7 = load i32, i32* %5
%8 = icmp ult i32 %7, 9
br i1 %8, label %9, label %36
9: ; preds = %6
%10 = load i32, i32* %5
%11 = zext i32 %10 to i64
%12 = getelementptr inbounds [9 x i32], [9 x i32]* @compute_access.access, i64 0, i64 %11
%13 = load i32, i32* %12
%14 = load i32, i32* %3
%15 = and i32 %13, %14
%16 = icmp ne i32 %15, 0
br i1 %16, label %17, label %27
17: ; preds = %9
%18 = load i32, i32* %5
%19 = urem i32 %18, 3
%20 = zext i32 %19 to i64
%21 = getelementptr inbounds [3 x i8], [3 x i8]* @compute_access.rwx, i64 0, i64 %20
%22 = load i8, i8* %21
%23 = load i8*, i8** %4
%24 = load i32, i32* %5
%25 = zext i32 %24 to i64
%26 = getelementptr inbounds i8, i8* %23, i64 %25
store i8 %22, i8* %26
br label %32
27: ; preds = %9
%28 = load i8*, i8** %4
%29 = load i32, i32* %5
%30 = zext i32 %29 to i64
%31 = getelementptr inbounds i8, i8* %28, i64 %30
store i8 45, i8* %31
br label %32
32: ; preds = %27, %17
br label %33
33: ; preds = %32
%34 = load i32, i32* %5
%35 = add i32 %34, 1
store i32 %35, i32* %5
br label %6
36: ; preds = %6
%37 = load i8*, i8** %4
%38 = getelementptr inbounds i8, i8* %37, i64 9
store i8 0, i8* %38
ret void
}

LLVM IR (-O2):
define void @compute_access(i32 %0, i8* nocapture writeonly %1) {
%3 = and i32 %0, 134
%4 = icmp eq i32 %3, 0
%5 = select i1 %4, i8 45, i8 114
store i8 %5, i8* %1
%6 = insertelement <8 x i32> poison, i32 %0, i64 0
%7 = shufflevector <8 x i32> %6, <8 x i32> poison, <8 x i32> zeroinitializer
%8 = and <8 x i32> %7, <i32 129, i32 132, i32 135, i32 130, i32 133, i32 136, i32 128, i32 131>
%9 = icmp eq <8 x i32> %8, zeroinitializer
%10 = extractelement <8 x i1> %9, i64 7
%11 = select i1 %10, i8 45, i8 119
%12 = getelementptr inbounds i8, i8* %1, i64 1
store i8 %11, i8* %12
%13 = extractelement <8 x i1> %9, i64 6
%14 = select i1 %13, i8 45, i8 120
%15 = getelementptr inbounds i8, i8* %1, i64 2
store i8 %14, i8* %15
%16 = extractelement <8 x i1> %9, i64 5
%17 = select i1 %16, i8 45, i8 114
%18 = getelementptr inbounds i8, i8* %1, i64 3
store i8 %17, i8* %18
%19 = extractelement <8 x i1> %9, i64 4
%20 = select i1 %19, i8 45, i8 119
%21 = getelementptr inbounds i8, i8* %1, i64 4
store i8 %20, i8* %21
%22 = extractelement <8 x i1> %9, i64 3
%23 = select i1 %22, i8 45, i8 120
%24 = getelementptr inbounds i8, i8* %1, i64 5
store i8 %23, i8* %24
%25 = extractelement <8 x i1> %9, i64 2
%26 = select i1 %25, i8 45, i8 114
%27 = getelementptr inbounds i8, i8* %1, i64 6
store i8 %26, i8* %27
%28 = extractelement <8 x i1> %9, i64 1
%29 = select i1 %28, i8 45, i8 119
%30 = getelementptr inbounds i8, i8* %1, i64 7
store i8 %29, i8* %30
%31 = extractelement <8 x i1> %9, i64 0
%32 = select i1 %31, i8 45, i8 120
%33 = getelementptr inbounds i8, i8* %1, i64 8
store i8 %32, i8* %33
%34 = getelementptr inbounds i8, i8* %1, i64 9
store i8 0, i8* %34
ret void
}