#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_IFBLK 134
#define S_IFCHR 133
#define S_IFDIR 132
#define S_IFIFO 131
#define S_IFLNK 130
int S_IFMT;
#define S_IFREG 129
#define S_IFSOCK 128
int S_IRGRP;
int S_IROTH;
int S_IRUSR;
int S_IWGRP;
int S_IWOTH;
int S_IWUSR;
int S_IXGRP;
int S_IXOTH;
int S_IXUSR;
void setPermissions(mode_t mode, char *string) {
  switch (mode & S_IFMT) {
  case S_IFREG:
    string[0] = '-';
    break;
  case S_IFDIR:
    string[0] = 'd';
    break;
  case S_IFLNK:
    string[0] = 'l';
    break;
  case S_IFCHR:
    string[0] = 'c';
    break;
  case S_IFBLK:
    string[0] = 'b';
    break;
  case S_IFSOCK:
    string[0] = 's';
    break;
  case S_IFIFO:
    string[0] = 'f';
    break;
  default:
    string[0] = '-';
    break;
  }
  string[1] = (mode & S_IRUSR) ? 'r' : '-';
  string[2] = (mode & S_IWUSR) ? 'w' : '-';
  string[3] = (mode & S_IXUSR) ? 'x' : '-';
  string[4] = (mode & S_IRGRP) ? 'r' : '-';
  string[5] = (mode & S_IWGRP) ? 'w' : '-';
  string[6] = (mode & S_IXGRP) ? 'x' : '-';
  string[7] = (mode & S_IROTH) ? 'r' : '-';
  string[8] = (mode & S_IWOTH) ? 'w' : '-';
  string[9] = (mode & S_IXOTH) ? 'x' : '-';
  string[10] = '\0';
}


x86 assembly (clang, -O0):
<setPermissions>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x4(%rbp),%eax
mov    0x2ea3(%rip),%rcx
mov    (%rcx),%ecx
and    %ecx,%eax
add    $0xffffff80,%eax
mov    %eax,%ecx
mov    %rcx,-0x18(%rbp)
sub    $0x6,%eax
ja     1193 <setPermissions+0x93>
mov    -0x18(%rbp),%rax
lea    0xeca(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x10(%rbp),%rax
movb   $0x2d,(%rax)
jmp    119a <setPermissions+0x9a>
mov    -0x10(%rbp),%rax
movb   $0x64,(%rax)
jmp    119a <setPermissions+0x9a>
mov    -0x10(%rbp),%rax
movb   $0x6c,(%rax)
jmp    119a <setPermissions+0x9a>
mov    -0x10(%rbp),%rax
movb   $0x63,(%rax)
jmp    119a <setPermissions+0x9a>
mov    -0x10(%rbp),%rax
movb   $0x62,(%rax)
jmp    119a <setPermissions+0x9a>
mov    -0x10(%rbp),%rax
movb   $0x73,(%rax)
jmp    119a <setPermissions+0x9a>
mov    -0x10(%rbp),%rax
movb   $0x66,(%rax)
jmp    119a <setPermissions+0x9a>
mov    -0x10(%rbp),%rax
movb   $0x2d,(%rax)
mov    -0x4(%rbp),%edx
mov    0x2dfc(%rip),%rax
and    (%rax),%edx
mov    $0x2d,%eax
mov    $0x72,%ecx
cmp    $0x0,%edx
cmovne %ecx,%eax
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %cl,0x1(%rax)
mov    -0x4(%rbp),%edx
mov    0x2e07(%rip),%rax
and    (%rax),%edx
mov    $0x2d,%eax
mov    $0x77,%ecx
cmp    $0x0,%edx
cmovne %ecx,%eax
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %cl,0x2(%rax)
mov    -0x4(%rbp),%edx
mov    0x2df2(%rip),%rax
and    (%rax),%edx
mov    $0x2d,%eax
mov    $0x78,%ecx
cmp    $0x0,%edx
cmovne %ecx,%eax
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %cl,0x3(%rax)
mov    -0x4(%rbp),%edx
mov    0x2d9d(%rip),%rax
and    (%rax),%edx
mov    $0x2d,%eax
mov    $0x72,%ecx
cmp    $0x0,%edx
cmovne %ecx,%eax
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %cl,0x4(%rax)
mov    -0x4(%rbp),%edx
mov    0x2da0(%rip),%rax
and    (%rax),%edx
mov    $0x2d,%eax
mov    $0x77,%ecx
cmp    $0x0,%edx
cmovne %ecx,%eax
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %cl,0x5(%rax)
mov    -0x4(%rbp),%edx
mov    0x2d6b(%rip),%rax
and    (%rax),%edx
mov    $0x2d,%eax
mov    $0x78,%ecx
cmp    $0x0,%edx
cmovne %ecx,%eax
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %cl,0x6(%rax)
mov    -0x4(%rbp),%edx
mov    0x2d26(%rip),%rax
and    (%rax),%edx
mov    $0x2d,%eax
mov    $0x72,%ecx
cmp    $0x0,%edx
cmovne %ecx,%eax
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %cl,0x7(%rax)
mov    -0x4(%rbp),%edx
mov    0x2ce9(%rip),%rax
and    (%rax),%edx
mov    $0x2d,%eax
mov    $0x77,%ecx
cmp    $0x0,%edx
cmovne %ecx,%eax
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %cl,0x8(%rax)
mov    -0x4(%rbp),%edx
mov    0x2d1c(%rip),%rax
and    (%rax),%edx
mov    $0x2d,%eax
mov    $0x78,%ecx
cmp    $0x0,%edx
cmovne %ecx,%eax
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %cl,0x9(%rax)
mov    -0x10(%rbp),%rax
movb   $0x0,0xa(%rax)
pop    %rbp
ret

x86 assembly (clang, -O2):
<setPermissions>:
mov    0x2eb1(%rip),%rax
mov    (%rax),%eax
and    %edi,%eax
lea    -0x400(,%rax,8),%ecx
movabs $0x626364666c2d73,%rdx
shr    %cl,%rdx
add    $0xffffff80,%eax
cmp    $0x7,%eax
mov    $0x2d,%r8d
cmovae %r8d,%edx
mov    %dl,(%rsi)
mov    0x2e68(%rip),%rax
mov    (%rax),%eax
and    %edi,%eax
mov    $0x72,%eax
cmove  %r8d,%eax
mov    %al,0x1(%rsi)
mov    0x2e81(%rip),%rax
mov    (%rax),%eax
and    %edi,%eax
mov    $0x77,%eax
cmove  %r8d,%eax
mov    %al,0x2(%rsi)
mov    0x2e7a(%rip),%rax
mov    (%rax),%eax
and    %edi,%eax
mov    $0x78,%eax
cmove  %r8d,%eax
mov    $0x72,%r9d
mov    %al,0x3(%rsi)
mov    0x2e2d(%rip),%rax
mov    (%rax),%eax
and    %edi,%eax
mov    $0x72,%eax
cmove  %r8d,%eax
mov    $0x77,%edx
mov    %al,0x4(%rsi)
mov    0x2e39(%rip),%rax
mov    (%rax),%eax
and    %edi,%eax
mov    $0x77,%ecx
cmove  %r8d,%ecx
mov    $0x78,%eax
mov    %cl,0x5(%rsi)
mov    0x2e0d(%rip),%rcx
mov    (%rcx),%ecx
and    %edi,%ecx
mov    $0x78,%ecx
cmove  %r8d,%ecx
mov    %cl,0x6(%rsi)
mov    0x2dd6(%rip),%rcx
mov    (%rcx),%ecx
and    %edi,%ecx
cmove  %r8d,%r9d
mov    %r9b,0x7(%rsi)
mov    0x2dab(%rip),%rcx
mov    (%rcx),%ecx
and    %edi,%ecx
cmove  %r8d,%edx
mov    %dl,0x8(%rsi)
mov    0x2df1(%rip),%rcx
and    (%rcx),%edi
cmove  %r8d,%eax
mov    %al,0x9(%rsi)
movb   $0x0,0xa(%rsi)
ret

LLVM IR (-O0):
@S_IFMT = global i32 0
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@S_IXUSR = global i32 0
@S_IRGRP = global i32 0
@S_IWGRP = global i32 0
@S_IXGRP = global i32 0
@S_IROTH = global i32 0
@S_IWOTH = global i32 0
@S_IXOTH = global i32 0
define void @setPermissions(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
store i32 %0, i32* %3
store i8* %1, i8** %4
%5 = load i32, i32* %3
%6 = load i32, i32* @S_IFMT
%7 = and i32 %5, %6
switch i32 %7, label %29 [
i32 129, label %8
i32 132, label %11
i32 130, label %14
i32 133, label %17
i32 134, label %20
i32 128, label %23
i32 131, label %26
]
8: ; preds = %2
%9 = load i8*, i8** %4
%10 = getelementptr inbounds i8, i8* %9, i64 0
store i8 45, i8* %10
br label %32
11: ; preds = %2
%12 = load i8*, i8** %4
%13 = getelementptr inbounds i8, i8* %12, i64 0
store i8 100, i8* %13
br label %32
14: ; preds = %2
%15 = load i8*, i8** %4
%16 = getelementptr inbounds i8, i8* %15, i64 0
store i8 108, i8* %16
br label %32
17: ; preds = %2
%18 = load i8*, i8** %4
%19 = getelementptr inbounds i8, i8* %18, i64 0
store i8 99, i8* %19
br label %32
20: ; preds = %2
%21 = load i8*, i8** %4
%22 = getelementptr inbounds i8, i8* %21, i64 0
store i8 98, i8* %22
br label %32
23: ; preds = %2
%24 = load i8*, i8** %4
%25 = getelementptr inbounds i8, i8* %24, i64 0
store i8 115, i8* %25
br label %32
26: ; preds = %2
%27 = load i8*, i8** %4
%28 = getelementptr inbounds i8, i8* %27, i64 0
store i8 102, i8* %28
br label %32
29: ; preds = %2
%30 = load i8*, i8** %4
%31 = getelementptr inbounds i8, i8* %30, i64 0
store i8 45, i8* %31
br label %32
32: ; preds = %29, %26, %23, %20, %17, %14, %11, %8
%33 = load i32, i32* %3
%34 = load i32, i32* @S_IRUSR
%35 = and i32 %33, %34
%36 = icmp ne i32 %35, 0
%37 = zext i1 %36 to i64
%38 = select i1 %36, i32 114, i32 45
%39 = trunc i32 %38 to i8
%40 = load i8*, i8** %4
%41 = getelementptr inbounds i8, i8* %40, i64 1
store i8 %39, i8* %41
%42 = load i32, i32* %3
%43 = load i32, i32* @S_IWUSR
%44 = and i32 %42, %43
%45 = icmp ne i32 %44, 0
%46 = zext i1 %45 to i64
%47 = select i1 %45, i32 119, i32 45
%48 = trunc i32 %47 to i8
%49 = load i8*, i8** %4
%50 = getelementptr inbounds i8, i8* %49, i64 2
store i8 %48, i8* %50
%51 = load i32, i32* %3
%52 = load i32, i32* @S_IXUSR
%53 = and i32 %51, %52
%54 = icmp ne i32 %53, 0
%55 = zext i1 %54 to i64
%56 = select i1 %54, i32 120, i32 45
%57 = trunc i32 %56 to i8
%58 = load i8*, i8** %4
%59 = getelementptr inbounds i8, i8* %58, i64 3
store i8 %57, i8* %59
%60 = load i32, i32* %3
%61 = load i32, i32* @S_IRGRP
%62 = and i32 %60, %61
%63 = icmp ne i32 %62, 0
%64 = zext i1 %63 to i64
%65 = select i1 %63, i32 114, i32 45
%66 = trunc i32 %65 to i8
%67 = load i8*, i8** %4
%68 = getelementptr inbounds i8, i8* %67, i64 4
store i8 %66, i8* %68
%69 = load i32, i32* %3
%70 = load i32, i32* @S_IWGRP
%71 = and i32 %69, %70
%72 = icmp ne i32 %71, 0
%73 = zext i1 %72 to i64
%74 = select i1 %72, i32 119, i32 45
%75 = trunc i32 %74 to i8
%76 = load i8*, i8** %4
%77 = getelementptr inbounds i8, i8* %76, i64 5
store i8 %75, i8* %77
%78 = load i32, i32* %3
%79 = load i32, i32* @S_IXGRP
%80 = and i32 %78, %79
%81 = icmp ne i32 %80, 0
%82 = zext i1 %81 to i64
%83 = select i1 %81, i32 120, i32 45
%84 = trunc i32 %83 to i8
%85 = load i8*, i8** %4
%86 = getelementptr inbounds i8, i8* %85, i64 6
store i8 %84, i8* %86
%87 = load i32, i32* %3
%88 = load i32, i32* @S_IROTH
%89 = and i32 %87, %88
%90 = icmp ne i32 %89, 0
%91 = zext i1 %90 to i64
%92 = select i1 %90, i32 114, i32 45
%93 = trunc i32 %92 to i8
%94 = load i8*, i8** %4
%95 = getelementptr inbounds i8, i8* %94, i64 7
store i8 %93, i8* %95
%96 = load i32, i32* %3
%97 = load i32, i32* @S_IWOTH
%98 = and i32 %96, %97
%99 = icmp ne i32 %98, 0
%100 = zext i1 %99 to i64
%101 = select i1 %99, i32 119, i32 45
%102 = trunc i32 %101 to i8
%103 = load i8*, i8** %4
%104 = getelementptr inbounds i8, i8* %103, i64 8
store i8 %102, i8* %104
%105 = load i32, i32* %3
%106 = load i32, i32* @S_IXOTH
%107 = and i32 %105, %106
%108 = icmp ne i32 %107, 0
%109 = zext i1 %108 to i64
%110 = select i1 %108, i32 120, i32 45
%111 = trunc i32 %110 to i8
%112 = load i8*, i8** %4
%113 = getelementptr inbounds i8, i8* %112, i64 9
store i8 %111, i8* %113
%114 = load i8*, i8** %4
%115 = getelementptr inbounds i8, i8* %114, i64 10
store i8 0, i8* %115
ret void
}

LLVM IR (-O2):
@S_IFMT = global i32 0
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@S_IXUSR = global i32 0
@S_IRGRP = global i32 0
@S_IWGRP = global i32 0
@S_IXGRP = global i32 0
@S_IROTH = global i32 0
@S_IWOTH = global i32 0
@S_IXOTH = global i32 0
define void @setPermissions(i32 %0, i8* nocapture writeonly %1) {
%3 = load i32, i32* @S_IFMT
%4 = and i32 %3, %0
%5 = add i32 %4, -128
%6 = icmp ult i32 %5, 7
%7 = zext i32 %5 to i56
%8 = shl nuw nsw i56 %7, 3
%9 = lshr i56 27693830583889267, %8
%10 = trunc i56 %9 to i8
%11 = select i1 %6, i8 %10, i8 45
store i8 %11, i8* %1
%12 = load i32, i32* @S_IRUSR
%13 = and i32 %12, %0
%14 = icmp eq i32 %13, 0
%15 = select i1 %14, i8 45, i8 114
%16 = getelementptr inbounds i8, i8* %1, i64 1
store i8 %15, i8* %16
%17 = load i32, i32* @S_IWUSR
%18 = and i32 %17, %0
%19 = icmp eq i32 %18, 0
%20 = select i1 %19, i8 45, i8 119
%21 = getelementptr inbounds i8, i8* %1, i64 2
store i8 %20, i8* %21
%22 = load i32, i32* @S_IXUSR
%23 = and i32 %22, %0
%24 = icmp eq i32 %23, 0
%25 = select i1 %24, i8 45, i8 120
%26 = getelementptr inbounds i8, i8* %1, i64 3
store i8 %25, i8* %26
%27 = load i32, i32* @S_IRGRP
%28 = and i32 %27, %0
%29 = icmp eq i32 %28, 0
%30 = select i1 %29, i8 45, i8 114
%31 = getelementptr inbounds i8, i8* %1, i64 4
store i8 %30, i8* %31
%32 = load i32, i32* @S_IWGRP
%33 = and i32 %32, %0
%34 = icmp eq i32 %33, 0
%35 = select i1 %34, i8 45, i8 119
%36 = getelementptr inbounds i8, i8* %1, i64 5
store i8 %35, i8* %36
%37 = load i32, i32* @S_IXGRP
%38 = and i32 %37, %0
%39 = icmp eq i32 %38, 0
%40 = select i1 %39, i8 45, i8 120
%41 = getelementptr inbounds i8, i8* %1, i64 6
store i8 %40, i8* %41
%42 = load i32, i32* @S_IROTH
%43 = and i32 %42, %0
%44 = icmp eq i32 %43, 0
%45 = select i1 %44, i8 45, i8 114
%46 = getelementptr inbounds i8, i8* %1, i64 7
store i8 %45, i8* %46
%47 = load i32, i32* @S_IWOTH
%48 = and i32 %47, %0
%49 = icmp eq i32 %48, 0
%50 = select i1 %49, i8 45, i8 119
%51 = getelementptr inbounds i8, i8* %1, i64 8
store i8 %50, i8* %51
%52 = load i32, i32* @S_IXOTH
%53 = and i32 %52, %0
%54 = icmp eq i32 %53, 0
%55 = select i1 %54, i8 45, i8 120
%56 = getelementptr inbounds i8, i8* %1, i64 9
store i8 %55, i8* %56
%57 = getelementptr inbounds i8, i8* %1, i64 10
store i8 0, i8* %57
ret void
}