#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;
int /*<<< orphan*/ memset(char *, char, int);
void makePermissionString(char result[10], mode_t fmode) {
  memset(result, '-', 10);
  switch (S_IFMT & fmode) {
  case S_IFDIR:
    result[0] = 'd';
    break;
  case S_IFSOCK:
    result[0] = 's';
    break;
  case S_IFLNK:
    result[0] = 'l';
    break;
  case S_IFBLK:
    result[0] = 'b';
    break;
  case S_IFCHR:
    result[0] = 'c';
    break;
  case S_IFIFO:
    result[0] = 'f';
    break;
  case S_IFREG:
    result[0] = '-';
    break;
  default:
    break;
  }
  if (S_IRUSR & fmode)
    result[1] = 'r';
  if (S_IWUSR & fmode)
    result[2] = 'w';
  if (S_IXUSR & fmode)
    result[3] = 'x';
  if (S_IRGRP & fmode)
    result[4] = 'r';
  if (S_IWGRP & fmode)
    result[5] = 'w';
  if (S_IXGRP & fmode)
    result[6] = 'x';
  if (S_IROTH & fmode)
    result[7] = 'r';
  if (S_IWOTH & fmode)
    result[8] = 'w';
  if (S_IXOTH & fmode)
    result[9] = 'x';
}


x86 assembly (clang, -O0):
<makePermissionString>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0x2d,%esi
mov    $0xa,%edx
call   1030 <memset@plt>
mov    0x2e7f(%rip),%rax
mov    (%rax),%eax
mov    -0xc(%rbp),%ecx
and    %ecx,%eax
add    $0xffffff80,%eax
mov    %eax,%ecx
mov    %rcx,-0x18(%rbp)
sub    $0x6,%eax
ja     11ba <makePermissionString+0xaa>
mov    -0x18(%rbp),%rax
lea    0xea3(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x8(%rbp),%rax
movb   $0x64,(%rax)
jmp    11bf <makePermissionString+0xaf>
mov    -0x8(%rbp),%rax
movb   $0x73,(%rax)
jmp    11bf <makePermissionString+0xaf>
mov    -0x8(%rbp),%rax
movb   $0x6c,(%rax)
jmp    11bf <makePermissionString+0xaf>
mov    -0x8(%rbp),%rax
movb   $0x62,(%rax)
jmp    11bf <makePermissionString+0xaf>
mov    -0x8(%rbp),%rax
movb   $0x63,(%rax)
jmp    11bf <makePermissionString+0xaf>
mov    -0x8(%rbp),%rax
movb   $0x66,(%rax)
jmp    11bf <makePermissionString+0xaf>
mov    -0x8(%rbp),%rax
movb   $0x2d,(%rax)
jmp    11bf <makePermissionString+0xaf>
jmp    11bf <makePermissionString+0xaf>
mov    0x2dda(%rip),%rax
mov    (%rax),%eax
and    -0xc(%rbp),%eax
cmp    $0x0,%eax
je     11dc <makePermissionString+0xcc>
mov    -0x8(%rbp),%rax
movb   $0x72,0x1(%rax)
mov    0x2ded(%rip),%rax
mov    (%rax),%eax
and    -0xc(%rbp),%eax
cmp    $0x0,%eax
je     11f9 <makePermissionString+0xe9>
mov    -0x8(%rbp),%rax
movb   $0x77,0x2(%rax)
mov    0x2de0(%rip),%rax
mov    (%rax),%eax
and    -0xc(%rbp),%eax
cmp    $0x0,%eax
je     1216 <makePermissionString+0x106>
mov    -0x8(%rbp),%rax
movb   $0x78,0x3(%rax)
mov    0x2d93(%rip),%rax
mov    (%rax),%eax
and    -0xc(%rbp),%eax
cmp    $0x0,%eax
je     1233 <makePermissionString+0x123>
mov    -0x8(%rbp),%rax
movb   $0x72,0x4(%rax)
mov    0x2d9e(%rip),%rax
mov    (%rax),%eax
and    -0xc(%rbp),%eax
cmp    $0x0,%eax
je     1250 <makePermissionString+0x140>
mov    -0x8(%rbp),%rax
movb   $0x77,0x5(%rax)
mov    0x2d71(%rip),%rax
mov    (%rax),%eax
and    -0xc(%rbp),%eax
cmp    $0x0,%eax
je     126d <makePermissionString+0x15d>
mov    -0x8(%rbp),%rax
movb   $0x78,0x6(%rax)
mov    0x2d34(%rip),%rax
mov    (%rax),%eax
and    -0xc(%rbp),%eax
cmp    $0x0,%eax
je     128a <makePermissionString+0x17a>
mov    -0x8(%rbp),%rax
movb   $0x72,0x7(%rax)
mov    0x2cff(%rip),%rax
mov    (%rax),%eax
and    -0xc(%rbp),%eax
cmp    $0x0,%eax
je     12a7 <makePermissionString+0x197>
mov    -0x8(%rbp),%rax
movb   $0x77,0x8(%rax)
mov    0x2d3a(%rip),%rax
mov    (%rax),%eax
and    -0xc(%rbp),%eax
cmp    $0x0,%eax
je     12c4 <makePermissionString+0x1b4>
mov    -0x8(%rbp),%rax
movb   $0x78,0x9(%rax)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<makePermissionString>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebp
mov    %rdi,%rbx
mov    $0x2d,%esi
mov    $0xa,%edx
call   1030 <memset@plt>
mov    0x2e8a(%rip),%rax
mov    (%rax),%ecx
and    %ebp,%ecx
add    $0xffffff80,%ecx
cmp    $0x6,%ecx
ja     114c <makePermissionString+0x3c>
shl    $0x3,%ecx
movabs $0x626364666c2d73,%rax
shr    %cl,%rax
mov    %al,(%rbx)
mov    0x2e4d(%rip),%rax
test   %ebp,(%rax)
je     115b <makePermissionString+0x4b>
movb   $0x72,0x1(%rbx)
mov    0x2e6e(%rip),%rax
test   %ebp,(%rax)
je     116a <makePermissionString+0x5a>
movb   $0x77,0x2(%rbx)
mov    0x2e6f(%rip),%rax
test   %ebp,(%rax)
je     1179 <makePermissionString+0x69>
movb   $0x78,0x3(%rbx)
mov    0x2e30(%rip),%rax
test   %ebp,(%rax)
je     1188 <makePermissionString+0x78>
movb   $0x72,0x4(%rbx)
mov    0x2e49(%rip),%rax
test   %ebp,(%rax)
je     1197 <makePermissionString+0x87>
movb   $0x77,0x5(%rbx)
mov    0x2e2a(%rip),%rax
test   %ebp,(%rax)
je     11a6 <makePermissionString+0x96>
movb   $0x78,0x6(%rbx)
mov    0x2dfb(%rip),%rax
test   %ebp,(%rax)
je     11b5 <makePermissionString+0xa5>
movb   $0x72,0x7(%rbx)
mov    0x2dd4(%rip),%rax
test   %ebp,(%rax)
je     11c4 <makePermissionString+0xb4>
movb   $0x77,0x8(%rbx)
mov    0x2e1d(%rip),%rax
test   %ebp,(%rax)
je     11d3 <makePermissionString+0xc3>
movb   $0x78,0x9(%rbx)
add    $0x8,%rsp
pop    %rbx
pop    %rbp
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 @makePermissionString(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
store i8* %0, i8** %3
store i32 %1, i32* %4
%5 = load i8*, i8** %3
%6 = call i32 @memset(i8* %5, i8 signext 45, i32 10)
%7 = load i32, i32* @S_IFMT
%8 = load i32, i32* %4
%9 = and i32 %7, %8
switch i32 %9, label %31 [
i32 132, label %10
i32 128, label %13
i32 130, label %16
i32 134, label %19
i32 133, label %22
i32 131, label %25
i32 129, label %28
]
10: ; preds = %2
%11 = load i8*, i8** %3
%12 = getelementptr inbounds i8, i8* %11, i64 0
store i8 100, i8* %12
br label %32
13: ; preds = %2
%14 = load i8*, i8** %3
%15 = getelementptr inbounds i8, i8* %14, i64 0
store i8 115, i8* %15
br label %32
16: ; preds = %2
%17 = load i8*, i8** %3
%18 = getelementptr inbounds i8, i8* %17, i64 0
store i8 108, i8* %18
br label %32
19: ; preds = %2
%20 = load i8*, i8** %3
%21 = getelementptr inbounds i8, i8* %20, i64 0
store i8 98, i8* %21
br label %32
22: ; preds = %2
%23 = load i8*, i8** %3
%24 = getelementptr inbounds i8, i8* %23, i64 0
store i8 99, i8* %24
br label %32
25: ; preds = %2
%26 = load i8*, i8** %3
%27 = getelementptr inbounds i8, i8* %26, i64 0
store i8 102, i8* %27
br label %32
28: ; preds = %2
%29 = load i8*, i8** %3
%30 = getelementptr inbounds i8, i8* %29, i64 0
store i8 45, i8* %30
br label %32
31: ; preds = %2
br label %32
32: ; preds = %31, %28, %25, %22, %19, %16, %13, %10
%33 = load i32, i32* @S_IRUSR
%34 = load i32, i32* %4
%35 = and i32 %33, %34
%36 = icmp ne i32 %35, 0
br i1 %36, label %37, label %40
37: ; preds = %32
%38 = load i8*, i8** %3
%39 = getelementptr inbounds i8, i8* %38, i64 1
store i8 114, i8* %39
br label %40
40: ; preds = %37, %32
%41 = load i32, i32* @S_IWUSR
%42 = load i32, i32* %4
%43 = and i32 %41, %42
%44 = icmp ne i32 %43, 0
br i1 %44, label %45, label %48
45: ; preds = %40
%46 = load i8*, i8** %3
%47 = getelementptr inbounds i8, i8* %46, i64 2
store i8 119, i8* %47
br label %48
48: ; preds = %45, %40
%49 = load i32, i32* @S_IXUSR
%50 = load i32, i32* %4
%51 = and i32 %49, %50
%52 = icmp ne i32 %51, 0
br i1 %52, label %53, label %56
53: ; preds = %48
%54 = load i8*, i8** %3
%55 = getelementptr inbounds i8, i8* %54, i64 3
store i8 120, i8* %55
br label %56
56: ; preds = %53, %48
%57 = load i32, i32* @S_IRGRP
%58 = load i32, i32* %4
%59 = and i32 %57, %58
%60 = icmp ne i32 %59, 0
br i1 %60, label %61, label %64
61: ; preds = %56
%62 = load i8*, i8** %3
%63 = getelementptr inbounds i8, i8* %62, i64 4
store i8 114, i8* %63
br label %64
64: ; preds = %61, %56
%65 = load i32, i32* @S_IWGRP
%66 = load i32, i32* %4
%67 = and i32 %65, %66
%68 = icmp ne i32 %67, 0
br i1 %68, label %69, label %72
69: ; preds = %64
%70 = load i8*, i8** %3
%71 = getelementptr inbounds i8, i8* %70, i64 5
store i8 119, i8* %71
br label %72
72: ; preds = %69, %64
%73 = load i32, i32* @S_IXGRP
%74 = load i32, i32* %4
%75 = and i32 %73, %74
%76 = icmp ne i32 %75, 0
br i1 %76, label %77, label %80
77: ; preds = %72
%78 = load i8*, i8** %3
%79 = getelementptr inbounds i8, i8* %78, i64 6
store i8 120, i8* %79
br label %80
80: ; preds = %77, %72
%81 = load i32, i32* @S_IROTH
%82 = load i32, i32* %4
%83 = and i32 %81, %82
%84 = icmp ne i32 %83, 0
br i1 %84, label %85, label %88
85: ; preds = %80
%86 = load i8*, i8** %3
%87 = getelementptr inbounds i8, i8* %86, i64 7
store i8 114, i8* %87
br label %88
88: ; preds = %85, %80
%89 = load i32, i32* @S_IWOTH
%90 = load i32, i32* %4
%91 = and i32 %89, %90
%92 = icmp ne i32 %91, 0
br i1 %92, label %93, label %96
93: ; preds = %88
%94 = load i8*, i8** %3
%95 = getelementptr inbounds i8, i8* %94, i64 8
store i8 119, i8* %95
br label %96
96: ; preds = %93, %88
%97 = load i32, i32* @S_IXOTH
%98 = load i32, i32* %4
%99 = and i32 %97, %98
%100 = icmp ne i32 %99, 0
br i1 %100, label %101, label %104
101: ; preds = %96
%102 = load i8*, i8** %3
%103 = getelementptr inbounds i8, i8* %102, i64 9
store i8 120, i8* %103
br label %104
104: ; preds = %101, %96
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 @makePermissionString(i8* %0, i32 %1) {
%3 = tail call i32 @memset(i8* %0, i8 signext 45, i32 10)
%4 = load i32, i32* @S_IFMT
%5 = and i32 %4, %1
%6 = add i32 %5, -128
%7 = icmp ult i32 %6, 7
br i1 %7, label %8, label %13
8: ; preds = %2
%9 = zext i32 %6 to i56
%10 = shl nuw nsw i56 %9, 3
%11 = lshr i56 27693830583889267, %10
%12 = trunc i56 %11 to i8
store i8 %12, i8* %0
br label %13
13: ; preds = %2, %8
%14 = load i32, i32* @S_IRUSR
%15 = and i32 %14, %1
%16 = icmp eq i32 %15, 0
br i1 %16, label %19, label %17
17: ; preds = %13
%18 = getelementptr inbounds i8, i8* %0, i64 1
store i8 114, i8* %18
br label %19
19: ; preds = %17, %13
%20 = load i32, i32* @S_IWUSR
%21 = and i32 %20, %1
%22 = icmp eq i32 %21, 0
br i1 %22, label %25, label %23
23: ; preds = %19
%24 = getelementptr inbounds i8, i8* %0, i64 2
store i8 119, i8* %24
br label %25
25: ; preds = %23, %19
%26 = load i32, i32* @S_IXUSR
%27 = and i32 %26, %1
%28 = icmp eq i32 %27, 0
br i1 %28, label %31, label %29
29: ; preds = %25
%30 = getelementptr inbounds i8, i8* %0, i64 3
store i8 120, i8* %30
br label %31
31: ; preds = %29, %25
%32 = load i32, i32* @S_IRGRP
%33 = and i32 %32, %1
%34 = icmp eq i32 %33, 0
br i1 %34, label %37, label %35
35: ; preds = %31
%36 = getelementptr inbounds i8, i8* %0, i64 4
store i8 114, i8* %36
br label %37
37: ; preds = %35, %31
%38 = load i32, i32* @S_IWGRP
%39 = and i32 %38, %1
%40 = icmp eq i32 %39, 0
br i1 %40, label %43, label %41
41: ; preds = %37
%42 = getelementptr inbounds i8, i8* %0, i64 5
store i8 119, i8* %42
br label %43
43: ; preds = %41, %37
%44 = load i32, i32* @S_IXGRP
%45 = and i32 %44, %1
%46 = icmp eq i32 %45, 0
br i1 %46, label %49, label %47
47: ; preds = %43
%48 = getelementptr inbounds i8, i8* %0, i64 6
store i8 120, i8* %48
br label %49
49: ; preds = %47, %43
%50 = load i32, i32* @S_IROTH
%51 = and i32 %50, %1
%52 = icmp eq i32 %51, 0
br i1 %52, label %55, label %53
53: ; preds = %49
%54 = getelementptr inbounds i8, i8* %0, i64 7
store i8 114, i8* %54
br label %55
55: ; preds = %53, %49
%56 = load i32, i32* @S_IWOTH
%57 = and i32 %56, %1
%58 = icmp eq i32 %57, 0
br i1 %58, label %61, label %59
59: ; preds = %55
%60 = getelementptr inbounds i8, i8* %0, i64 8
store i8 119, i8* %60
br label %61
61: ; preds = %59, %55
%62 = load i32, i32* @S_IXOTH
%63 = and i32 %62, %1
%64 = icmp eq i32 %63, 0
br i1 %64, label %67, label %65
65: ; preds = %61
%66 = getelementptr inbounds i8, i8* %0, i64 9
store i8 120, i8* %66
br label %67
67: ; preds = %65, %61
ret void
}