#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 *getperms(mode_t mode, char *buf) {
  int i;
  for (i = 0; i < 9; i++) {
    if ((mode >> i) & 1) {
      switch (i % 3) {
      case 0:
        buf[8 - i] = 'x';
        break;
      case 1:
        buf[8 - i] = 'w';
        break;
      case 2:
        buf[8 - i] = 'r';
        break;
      default:
        buf[8 - i] = '-';
        break;
      }
    } else {
      buf[8 - i] = '-';
    }
  }
  buf[9] = 0;
  return buf;
}


x86 assembly (clang, -O0):
<getperms>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
cmpl   $0x9,-0x14(%rbp)
jge    1207 <getperms+0x107>
mov    -0x4(%rbp),%eax
mov    -0x14(%rbp),%ecx
sar    %cl,%eax
and    $0x1,%eax
cmp    $0x0,%eax
je     11e1 <getperms+0xe1>
movslq -0x14(%rbp),%rcx
mov    %ecx,%eax
imul   $0x55555556,%rcx,%rdx
mov    %rdx,%rcx
shr    $0x3f,%rcx
shr    $0x20,%rdx
add    %ecx,%edx
mov    %edx,%ecx
lea    (%rcx,%rcx,2),%ecx
sub    %ecx,%eax
mov    %eax,-0x18(%rbp)
je     1181 <getperms+0x81>
jmp    115f <getperms+0x5f>
mov    -0x18(%rbp),%eax
sub    $0x1,%eax
je     1199 <getperms+0x99>
jmp    1170 <getperms+0x70>
mov    -0x18(%rbp),%eax
sub    $0x2,%eax
je     11b1 <getperms+0xb1>
jmp    11c9 <getperms+0xc9>
mov    -0x10(%rbp),%rax
mov    $0x8,%ecx
sub    -0x14(%rbp),%ecx
movslq %ecx,%rcx
movb   $0x78,(%rax,%rcx,1)
jmp    11dc <getperms+0xdc>
mov    -0x10(%rbp),%rax
mov    $0x8,%ecx
sub    -0x14(%rbp),%ecx
movslq %ecx,%rcx
movb   $0x77,(%rax,%rcx,1)
jmp    11dc <getperms+0xdc>
mov    -0x10(%rbp),%rax
mov    $0x8,%ecx
sub    -0x14(%rbp),%ecx
movslq %ecx,%rcx
movb   $0x72,(%rax,%rcx,1)
jmp    11dc <getperms+0xdc>
mov    -0x10(%rbp),%rax
mov    $0x8,%ecx
sub    -0x14(%rbp),%ecx
movslq %ecx,%rcx
movb   $0x2d,(%rax,%rcx,1)
jmp    11f4 <getperms+0xf4>
mov    -0x10(%rbp),%rax
mov    $0x8,%ecx
sub    -0x14(%rbp),%ecx
movslq %ecx,%rcx
movb   $0x2d,(%rax,%rcx,1)
jmp    11f9 <getperms+0xf9>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1112 <getperms+0x12>
mov    -0x10(%rbp),%rax
movb   $0x0,0x9(%rax)
mov    -0x10(%rbp),%rax
pop    %rbp
ret

x86 assembly (clang, -O2):
<getperms>:
mov    %rsi,%rax
test   $0x1,%dil
mov    $0x2d,%r9d
mov    $0x78,%r8d
mov    $0x78,%esi
cmove  %r9d,%esi
mov    %sil,0x8(%rax)
movd   %edi,%xmm0
pshufd $0x0,%xmm0,%xmm0
movdqa 0xecf(%rip),%xmm1
pand   %xmm0,%xmm1
pand   0xed3(%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,%edx
cmovne %r9d,%edx
mov    $0x77,%edi
mov    %dl,0x7(%rax)
test   $0x40,%sil
mov    $0x72,%edx
cmovne %r9d,%edx
mov    %dl,0x6(%rax)
test   $0x20,%sil
mov    $0x78,%edx
cmovne %r9d,%edx
mov    %dl,0x5(%rax)
test   $0x10,%sil
mov    $0x77,%edx
cmovne %r9d,%edx
mov    $0x72,%ecx
mov    %dl,0x4(%rax)
test   $0x8,%sil
mov    $0x72,%edx
cmovne %r9d,%edx
mov    %dl,0x3(%rax)
test   $0x4,%sil
cmovne %r9d,%r8d
mov    %r8b,0x2(%rax)
test   $0x2,%sil
cmovne %r9d,%edi
mov    %dil,0x1(%rax)
test   $0x1,%sil
cmovne %r9d,%ecx
mov    %cl,(%rax)
movb   $0x0,0x9(%rax)
ret

LLVM IR (-O0):
define i8* @getperms(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 = %50, %2
%7 = load i32, i32* %5
%8 = icmp slt i32 %7, 9
br i1 %8, label %9, label %53
9: ; preds = %6
%10 = load i32, i32* %3
%11 = load i32, i32* %5
%12 = ashr i32 %10, %11
%13 = and i32 %12, 1
%14 = icmp ne i32 %13, 0
br i1 %14, label %15, label %43
15: ; preds = %9
%16 = load i32, i32* %5
%17 = srem i32 %16, 3
switch i32 %17, label %36 [
i32 0, label %18
i32 1, label %24
i32 2, label %30
]
18: ; preds = %15
%19 = load i8*, i8** %4
%20 = load i32, i32* %5
%21 = sub nsw i32 8, %20
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i8, i8* %19, i64 %22
store i8 120, i8* %23
br label %42
24: ; preds = %15
%25 = load i8*, i8** %4
%26 = load i32, i32* %5
%27 = sub nsw i32 8, %26
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i8, i8* %25, i64 %28
store i8 119, i8* %29
br label %42
30: ; preds = %15
%31 = load i8*, i8** %4
%32 = load i32, i32* %5
%33 = sub nsw i32 8, %32
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds i8, i8* %31, i64 %34
store i8 114, i8* %35
br label %42
36: ; preds = %15
%37 = load i8*, i8** %4
%38 = load i32, i32* %5
%39 = sub nsw i32 8, %38
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds i8, i8* %37, i64 %40
store i8 45, i8* %41
br label %42
42: ; preds = %36, %30, %24, %18
br label %49
43: ; preds = %9
%44 = load i8*, i8** %4
%45 = load i32, i32* %5
%46 = sub nsw i32 8, %45
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds i8, i8* %44, i64 %47
store i8 45, i8* %48
br label %49
49: ; preds = %43, %42
br label %50
50: ; preds = %49
%51 = load i32, i32* %5
%52 = add nsw i32 %51, 1
store i32 %52, i32* %5
br label %6
53: ; preds = %6
%54 = load i8*, i8** %4
%55 = getelementptr inbounds i8, i8* %54, i64 9
store i8 0, i8* %55
%56 = load i8*, i8** %4
ret i8* %56
}

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