#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 */
unsigned short S_ISGID;
unsigned short S_ISUID;
unsigned short S_ISVTX;
char *pperm(unsigned short mode) {
  unsigned short m;
  static char buf[16];
  char *bp;
  char *lschars = "xwrxwrxwr";
  char *cp;
  int i;
  for (i = 0, cp = lschars, m = mode, bp = &buf[8]; i < 9;
       i++, cp++, m >>= 1, bp--) {
    if (m & 1)
      *bp = *cp;
    else
      *bp = '-';
  }
  buf[9] = '\0';
  if (mode & S_ISUID) {
    if (buf[2] == 'x')
      buf[2] = 's';
    else
      buf[2] = 'S';
  }
  if (mode & S_ISGID) {
    if (buf[5] == 'x')
      buf[5] = 's';
    else
      buf[5] = 'S';
  }
  if (mode & S_ISVTX) {
    if (buf[8] == 'x')
      buf[8] = 't';
    else
      buf[8] = 'T';
  }
  return &buf[0];
}


x86 assembly (clang, -O0):
<pperm>:
push   %rbp
mov    %rsp,%rbp
mov    %di,%ax
mov    %ax,-0x2(%rbp)
lea    0xeee(%rip),%rax
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x2(%rbp),%ax
mov    %ax,-0x4(%rbp)
lea    0x2efc(%rip),%rax
add    $0x8,%rax
mov    %rax,-0x10(%rbp)
cmpl   $0x9,-0x24(%rbp)
jge    11a4 <pperm+0xa4>
movzwl -0x4(%rbp),%eax
and    $0x1,%eax
cmp    $0x0,%eax
je     1167 <pperm+0x67>
mov    -0x20(%rbp),%rax
mov    (%rax),%cl
mov    -0x10(%rbp),%rax
mov    %cl,(%rax)
jmp    116e <pperm+0x6e>
mov    -0x10(%rbp),%rax
movb   $0x2d,(%rax)
jmp    1173 <pperm+0x73>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
movzwl -0x4(%rbp),%eax
sar    $0x1,%eax
mov    %ax,-0x4(%rbp)
mov    -0x10(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x10(%rbp)
jmp    113c <pperm+0x3c>
movb   $0x0,0x2e8e(%rip)
movzwl -0x2(%rbp),%eax
mov    0x2e2a(%rip),%rcx
movzwl (%rcx),%ecx
and    %ecx,%eax
cmp    $0x0,%eax
je     11ec <pperm+0xec>
movsbl 0x2e67(%rip),%eax
cmp    $0x78,%eax
jne    11e0 <pperm+0xe0>
movb   $0x73,0x2e57(%rip)
jmp    11e7 <pperm+0xe7>
movb   $0x53,0x2e4b(%rip)
jmp    11ec <pperm+0xec>
movzwl -0x2(%rbp),%eax
mov    0x2dd9(%rip),%rcx
movzwl (%rcx),%ecx
and    %ecx,%eax
cmp    $0x0,%eax
je     122d <pperm+0x12d>
movsbl 0x2e29(%rip),%eax
cmp    $0x78,%eax
jne    1221 <pperm+0x121>
movb   $0x73,0x2e19(%rip)
jmp    1228 <pperm+0x128>
movb   $0x53,0x2e0d(%rip)
jmp    122d <pperm+0x12d>
movzwl -0x2(%rbp),%eax
mov    0x2db0(%rip),%rcx
movzwl (%rcx),%ecx
and    %ecx,%eax
cmp    $0x0,%eax
je     126e <pperm+0x16e>
movsbl 0x2deb(%rip),%eax
cmp    $0x78,%eax
jne    1262 <pperm+0x162>
movb   $0x74,0x2ddb(%rip)
jmp    1269 <pperm+0x169>
movb   $0x54,0x2dcf(%rip)
jmp    126e <pperm+0x16e>
lea    0x2dbb(%rip),%rax
pop    %rbp
ret

x86 assembly (clang, -O2):
<pperm>:
test   $0x1,%dil
mov    $0x2d,%eax
mov    $0x78,%r8d
mov    $0x78,%edx
cmove  %eax,%edx
mov    %dl,0x2f1b(%rip)
test   $0x2,%dil
mov    $0x77,%edx
mov    $0x77,%esi
cmove  %eax,%esi
mov    %sil,0x2f02(%rip)
test   $0x4,%dil
mov    $0x72,%esi
cmove  %eax,%esi
mov    %sil,0x2eee(%rip)
test   $0x8,%dil
mov    $0x78,%esi
cmove  %eax,%esi
mov    $0x72,%ecx
mov    %sil,0x2ed5(%rip)
test   $0x10,%dil
mov    $0x77,%esi
cmove  %eax,%esi
mov    %sil,0x2ec1(%rip)
test   $0x20,%dil
mov    $0x72,%esi
cmove  %eax,%esi
mov    %sil,0x2ead(%rip)
test   $0x40,%dil
cmove  %eax,%r8d
mov    %r8b,0x2e9d(%rip)
test   $0x80,%dil
cmove  %eax,%edx
mov    %dl,0x2e8f(%rip)
test   $0x100,%edi
cmove  %eax,%ecx
mov    %cl,0x2e7f(%rip)
movb   $0x0,0x2e81(%rip)
mov    0x2e21(%rip),%rax
test   %di,(%rax)
je     11d6 <pperm+0xd6>
movzbl %dil,%eax
shr    $0x6,%eax
shl    $0x5,%al
or     $0x53,%al
mov    %al,0x2e5c(%rip)
mov    0x2df3(%rip),%rax
test   %di,(%rax)
je     11f1 <pperm+0xf1>
mov    %edi,%eax
and    $0x8,%al
shl    $0x2,%al
or     $0x53,%al
mov    %al,0x2e44(%rip)
mov    0x2df0(%rip),%rax
test   %di,(%rax)
je     1210 <pperm+0x110>
and    $0x1,%dil
shl    $0x5,%dil
or     $0x54,%dil
mov    %dil,0x2e28(%rip)
lea    0x2e19(%rip),%rax
ret

LLVM IR (-O0):
@pperm.buf = internal global [16 x i8] zeroinitializer
@.str = [10 x i8] c"xwrxwrxwr\00"
@S_ISUID = global i16 0
@S_ISGID = global i16 0
@S_ISVTX = global i16 0
define i8* @pperm(i16 zeroext %0) {
%2 = alloca i16
%3 = alloca i16
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
store i16 %0, i16* %2
store i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8** %5
store i32 0, i32* %7
%8 = load i8*, i8** %5
store i8* %8, i8** %6
%9 = load i16, i16* %2
store i16 %9, i16* %3
store i8* getelementptr inbounds ([16 x i8], [16 x i8]* @pperm.buf, i64 0, i64 8), i8** %4
br label %10
10: ; preds = %25, %1
%11 = load i32, i32* %7
%12 = icmp slt i32 %11, 9
br i1 %12, label %13, label %36
13: ; preds = %10
%14 = load i16, i16* %3
%15 = zext i16 %14 to i32
%16 = and i32 %15, 1
%17 = icmp ne i32 %16, 0
br i1 %17, label %18, label %22
18: ; preds = %13
%19 = load i8*, i8** %6
%20 = load i8, i8* %19
%21 = load i8*, i8** %4
store i8 %20, i8* %21
br label %24
22: ; preds = %13
%23 = load i8*, i8** %4
store i8 45, i8* %23
br label %24
24: ; preds = %22, %18
br label %25
25: ; preds = %24
%26 = load i32, i32* %7
%27 = add nsw i32 %26, 1
store i32 %27, i32* %7
%28 = load i8*, i8** %6
%29 = getelementptr inbounds i8, i8* %28, i32 1
store i8* %29, i8** %6
%30 = load i16, i16* %3
%31 = zext i16 %30 to i32
%32 = ashr i32 %31, 1
%33 = trunc i32 %32 to i16
store i16 %33, i16* %3
%34 = load i8*, i8** %4
%35 = getelementptr inbounds i8, i8* %34, i32 -1
store i8* %35, i8** %4
br label %10
36: ; preds = %10
store i8 0, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @pperm.buf, i64 0, i64 9)
%37 = load i16, i16* %2
%38 = zext i16 %37 to i32
%39 = load i16, i16* @S_ISUID
%40 = zext i16 %39 to i32
%41 = and i32 %38, %40
%42 = icmp ne i32 %41, 0
br i1 %42, label %43, label %50
43: ; preds = %36
%44 = load i8, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @pperm.buf, i64 0, i64 2)
%45 = sext i8 %44 to i32
%46 = icmp eq i32 %45, 120
br i1 %46, label %47, label %48
47: ; preds = %43
store i8 115, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @pperm.buf, i64 0, i64 2)
br label %49
48: ; preds = %43
store i8 83, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @pperm.buf, i64 0, i64 2)
br label %49
49: ; preds = %48, %47
br label %50
50: ; preds = %49, %36
%51 = load i16, i16* %2
%52 = zext i16 %51 to i32
%53 = load i16, i16* @S_ISGID
%54 = zext i16 %53 to i32
%55 = and i32 %52, %54
%56 = icmp ne i32 %55, 0
br i1 %56, label %57, label %64
57: ; preds = %50
%58 = load i8, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @pperm.buf, i64 0, i64 5)
%59 = sext i8 %58 to i32
%60 = icmp eq i32 %59, 120
br i1 %60, label %61, label %62
61: ; preds = %57
store i8 115, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @pperm.buf, i64 0, i64 5)
br label %63
62: ; preds = %57
store i8 83, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @pperm.buf, i64 0, i64 5)
br label %63
63: ; preds = %62, %61
br label %64
64: ; preds = %63, %50
%65 = load i16, i16* %2
%66 = zext i16 %65 to i32
%67 = load i16, i16* @S_ISVTX
%68 = zext i16 %67 to i32
%69 = and i32 %66, %68
%70 = icmp ne i32 %69, 0
br i1 %70, label %71, label %78
71: ; preds = %64
%72 = load i8, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @pperm.buf, i64 0, i64 8)
%73 = sext i8 %72 to i32
%74 = icmp eq i32 %73, 120
br i1 %74, label %75, label %76
75: ; preds = %71
store i8 116, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @pperm.buf, i64 0, i64 8)
br label %77
76: ; preds = %71
store i8 84, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @pperm.buf, i64 0, i64 8)
br label %77
77: ; preds = %76, %75
br label %78
78: ; preds = %77, %64
ret i8* getelementptr inbounds ([16 x i8], [16 x i8]* @pperm.buf, i64 0, i64 0)
}

LLVM IR (-O2):
@pperm.buf = internal global [16 x i8] zeroinitializer
@S_ISUID = global i16 0
@S_ISGID = global i16 0
@S_ISVTX = global i16 0
define i8* @pperm(i16 zeroext %0) {
%2 = and i16 %0, 1
%3 = icmp eq i16 %2, 0
%4 = select i1 %3, i8 45, i8 120
store i8 %4, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @pperm.buf, i64 0, i64 8)
%5 = and i16 %0, 2
%6 = icmp eq i16 %5, 0
%7 = select i1 %6, i8 45, i8 119
store i8 %7, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @pperm.buf, i64 0, i64 7)
%8 = and i16 %0, 4
%9 = icmp eq i16 %8, 0
%10 = select i1 %9, i8 45, i8 114
store i8 %10, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @pperm.buf, i64 0, i64 6)
%11 = and i16 %0, 8
%12 = icmp eq i16 %11, 0
%13 = select i1 %12, i8 45, i8 120
store i8 %13, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @pperm.buf, i64 0, i64 5)
%14 = and i16 %0, 16
%15 = icmp eq i16 %14, 0
%16 = select i1 %15, i8 45, i8 119
store i8 %16, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @pperm.buf, i64 0, i64 4)
%17 = and i16 %0, 32
%18 = icmp eq i16 %17, 0
%19 = select i1 %18, i8 45, i8 114
store i8 %19, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @pperm.buf, i64 0, i64 3)
%20 = and i16 %0, 64
%21 = icmp eq i16 %20, 0
%22 = select i1 %21, i8 45, i8 120
store i8 %22, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @pperm.buf, i64 0, i64 2)
%23 = and i16 %0, 128
%24 = icmp eq i16 %23, 0
%25 = select i1 %24, i8 45, i8 119
store i8 %25, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @pperm.buf, i64 0, i64 1)
%26 = and i16 %0, 256
%27 = icmp eq i16 %26, 0
%28 = select i1 %27, i8 45, i8 114
store i8 %28, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @pperm.buf, i64 0, i64 0)
store i8 0, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @pperm.buf, i64 0, i64 9)
%29 = load i16, i16* @S_ISUID
%30 = and i16 %29, %0
%31 = icmp eq i16 %30, 0
br i1 %31, label %34, label %32
32: ; preds = %1
%33 = select i1 %21, i8 83, i8 115
store i8 %33, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @pperm.buf, i64 0, i64 2)
br label %34
34: ; preds = %32, %1
%35 = load i16, i16* @S_ISGID
%36 = and i16 %35, %0
%37 = icmp eq i16 %36, 0
br i1 %37, label %40, label %38
38: ; preds = %34
%39 = select i1 %12, i8 83, i8 115
store i8 %39, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @pperm.buf, i64 0, i64 5)
br label %40
40: ; preds = %38, %34
%41 = load i16, i16* @S_ISVTX
%42 = and i16 %41, %0
%43 = icmp eq i16 %42, 0
br i1 %43, label %46, label %44
44: ; preds = %40
%45 = select i1 %3, i8 84, i8 116
store i8 %45, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @pperm.buf, i64 0, i64 8)
br label %46
46: ; preds = %44, %40
ret i8* getelementptr inbounds ([16 x i8], [16 x i8]* @pperm.buf, i64 0, i64 0)
}