#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 */
char *filemode(mode_t mode, char buff[10]) {
  int i = 0, shift, masked;
  for (i = shift = 0; i < 3; i++, shift = i * 3) {
    masked = mode & (07 << shift);
    buff[shift + 0] = (02 << shift) & masked ? 'r' : '-';
    buff[shift + 1] = (04 << shift) & masked ? 'w' : '-';
    buff[shift + 2] = (01 << shift) & masked ? 'x' : '-';
  }
  return buff;
}


x86 assembly (clang, -O0):
<filemode>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x14(%rbp)
cmpl   $0x3,-0x14(%rbp)
jge    11e0 <filemode+0xe0>
mov    -0x4(%rbp),%eax
mov    -0x18(%rbp),%ecx
mov    $0x7,%edx
shl    %cl,%edx
mov    %edx,%ecx
and    %ecx,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%ecx
mov    $0x2,%edx
shl    %cl,%edx
and    -0x1c(%rbp),%edx
mov    $0x2d,%eax
mov    $0x72,%ecx
cmp    $0x0,%edx
cmovne %ecx,%eax
mov    %al,%dl
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%ecx
add    $0x0,%ecx
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x18(%rbp),%ecx
mov    $0x4,%edx
shl    %cl,%edx
and    -0x1c(%rbp),%edx
mov    $0x2d,%eax
mov    $0x77,%ecx
cmp    $0x0,%edx
cmovne %ecx,%eax
mov    %al,%dl
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x18(%rbp),%ecx
mov    $0x1,%edx
shl    %cl,%edx
and    -0x1c(%rbp),%edx
mov    $0x2d,%eax
mov    $0x78,%ecx
cmp    $0x0,%edx
cmovne %ecx,%eax
mov    %al,%dl
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%ecx
add    $0x2,%ecx
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
imul   $0x3,-0x14(%rbp),%eax
mov    %eax,-0x18(%rbp)
jmp    1120 <filemode+0x20>
mov    -0x10(%rbp),%rax
pop    %rbp
ret

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

LLVM IR (-O0):
define i8* @filemode(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32 %0, i32* %3
store i8* %1, i8** %4
store i32 0, i32* %5
store i32 0, i32* %6
store i32 0, i32* %5
br label %8
8: ; preds = %55, %2
%9 = load i32, i32* %5
%10 = icmp slt i32 %9, 3
br i1 %10, label %11, label %60
11: ; preds = %8
%12 = load i32, i32* %3
%13 = load i32, i32* %6
%14 = shl i32 7, %13
%15 = and i32 %12, %14
store i32 %15, i32* %7
%16 = load i32, i32* %6
%17 = shl i32 2, %16
%18 = load i32, i32* %7
%19 = and i32 %17, %18
%20 = icmp ne i32 %19, 0
%21 = zext i1 %20 to i64
%22 = select i1 %20, i32 114, i32 45
%23 = trunc i32 %22 to i8
%24 = load i8*, i8** %4
%25 = load i32, i32* %6
%26 = add nsw i32 %25, 0
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds i8, i8* %24, i64 %27
store i8 %23, i8* %28
%29 = load i32, i32* %6
%30 = shl i32 4, %29
%31 = load i32, i32* %7
%32 = and i32 %30, %31
%33 = icmp ne i32 %32, 0
%34 = zext i1 %33 to i64
%35 = select i1 %33, i32 119, i32 45
%36 = trunc i32 %35 to i8
%37 = load i8*, i8** %4
%38 = load i32, i32* %6
%39 = add nsw i32 %38, 1
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds i8, i8* %37, i64 %40
store i8 %36, i8* %41
%42 = load i32, i32* %6
%43 = shl i32 1, %42
%44 = load i32, i32* %7
%45 = and i32 %43, %44
%46 = icmp ne i32 %45, 0
%47 = zext i1 %46 to i64
%48 = select i1 %46, i32 120, i32 45
%49 = trunc i32 %48 to i8
%50 = load i8*, i8** %4
%51 = load i32, i32* %6
%52 = add nsw i32 %51, 2
%53 = sext i32 %52 to i64
%54 = getelementptr inbounds i8, i8* %50, i64 %53
store i8 %49, i8* %54
br label %55
55: ; preds = %11
%56 = load i32, i32* %5
%57 = add nsw i32 %56, 1
store i32 %57, i32* %5
%58 = load i32, i32* %5
%59 = mul nsw i32 %58, 3
store i32 %59, i32* %6
br label %8
60: ; preds = %8
%61 = load i8*, i8** %4
ret i8* %61
}

LLVM IR (-O2):
define i8* @filemode(i32 %0, i8* returned writeonly %1) {
%3 = and i32 %0, 2
%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 64, i32 256, i32 128, i32 8, i32 32, i32 16, i32 1, i32 4>
%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
ret i8* %1
}