#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 */
int S_IRWXG;
int S_IRWXO;
int S_IRWXU;
scalar_t__ S_ISBLK(int);
scalar_t__ S_ISCHR(int);
scalar_t__ S_ISDIR(int);
scalar_t__ S_ISFIFO(int);
int S_ISGID;
scalar_t__ S_ISLNK(int);
scalar_t__ S_ISSOCK(int);
int S_ISUID;
int S_ISVTX;
int /*<<< orphan*/ snprintf(char *, int, char *, char const *const,
                            char const *const, char const *const);
void get_perm_string(char buf[], int len, mode_t mode) {
  static const char *const perm_sets[] = {"---", "--x", "-w-", "-wx",
                                          "r--", "r-x", "rw-", "rwx"};
  int u, g, o;
  u = (mode & S_IRWXU) >> 6;
  g = (mode & S_IRWXG) >> 3;
  o = (mode & S_IRWXO);
  snprintf(buf, len, "-%s%s%s", perm_sets[u], perm_sets[g], perm_sets[o]);
  if (S_ISLNK(mode))
    buf[0] = 'l';
  else if (S_ISDIR(mode))
    buf[0] = 'd';
  else if (S_ISBLK(mode))
    buf[0] = 'b';
  else if (S_ISCHR(mode))
    buf[0] = 'c';
  else if (S_ISFIFO(mode))
    buf[0] = 'p';
  else if (S_ISSOCK(mode))
    buf[0] = 's';
  if (mode & S_ISVTX)
    buf[9] = (buf[9] == '-') ? 'T' : 't';
  if (mode & S_ISGID)
    buf[6] = (buf[6] == '-') ? 'S' : 's';
  if (mode & S_ISUID)
    buf[3] = (buf[3] == '-') ? 'S' : 's';
}


x86 assembly (clang, -O0):
<get_perm_string>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    -0x10(%rbp),%eax
mov    0x2e54(%rip),%rcx
and    (%rcx),%eax
sar    $0x6,%eax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%eax
mov    0x2e32(%rip),%rcx
and    (%rcx),%eax
sar    $0x3,%eax
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%eax
mov    0x2e40(%rip),%rcx
and    (%rcx),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
movslq -0x14(%rbp),%rcx
lea    0x2be9(%rip),%rax
mov    (%rax,%rcx,8),%rcx
movslq -0x18(%rbp),%rdx
lea    0x2bda(%rip),%rax
mov    (%rax,%rdx,8),%r8
movslq -0x1c(%rbp),%rdx
lea    0x2bcb(%rip),%rax
mov    (%rax,%rdx,8),%r9
lea    0xe30(%rip),%rdx
call   1070 <snprintf@plt>
mov    -0x10(%rbp),%edi
call   1030 <S_ISLNK@plt>
cmp    $0x0,%rax
je     1213 <get_perm_string+0xa3>
mov    -0x8(%rbp),%rax
movb   $0x6c,(%rax)
jmp    12bd <get_perm_string+0x14d>
mov    -0x10(%rbp),%edi
call   1060 <S_ISDIR@plt>
cmp    $0x0,%rax
je     1231 <get_perm_string+0xc1>
mov    -0x8(%rbp),%rax
movb   $0x64,(%rax)
jmp    12b8 <get_perm_string+0x148>
mov    -0x10(%rbp),%edi
call   1090 <S_ISBLK@plt>
cmp    $0x0,%rax
je     124f <get_perm_string+0xdf>
mov    -0x8(%rbp),%rax
movb   $0x62,(%rax)
jmp    12b3 <get_perm_string+0x143>
mov    -0x10(%rbp),%edi
call   1080 <S_ISCHR@plt>
cmp    $0x0,%rax
je     126d <get_perm_string+0xfd>
mov    -0x8(%rbp),%rax
movb   $0x63,(%rax)
jmp    12ae <get_perm_string+0x13e>
mov    -0x10(%rbp),%edi
call   1040 <S_ISFIFO@plt>
cmp    $0x0,%rax
je     128b <get_perm_string+0x11b>
mov    -0x8(%rbp),%rax
movb   $0x70,(%rax)
jmp    12a9 <get_perm_string+0x139>
mov    -0x10(%rbp),%edi
call   1050 <S_ISSOCK@plt>
cmp    $0x0,%rax
je     12a4 <get_perm_string+0x134>
mov    -0x8(%rbp),%rax
movb   $0x73,(%rax)
jmp    12a9 <get_perm_string+0x139>
jmp    12ae <get_perm_string+0x13e>
jmp    12b3 <get_perm_string+0x143>
jmp    12b8 <get_perm_string+0x148>
jmp    12bd <get_perm_string+0x14d>
mov    -0x10(%rbp),%eax
mov    0x2d11(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     12f3 <get_perm_string+0x183>
mov    -0x8(%rbp),%rax
movsbl 0x9(%rax),%edx
mov    $0x74,%eax
mov    $0x54,%ecx
cmp    $0x2d,%edx
cmove  %ecx,%eax
mov    %al,%cl
mov    -0x8(%rbp),%rax
mov    %cl,0x9(%rax)
mov    -0x10(%rbp),%eax
mov    0x2cbb(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     1329 <get_perm_string+0x1b9>
mov    -0x8(%rbp),%rax
movsbl 0x6(%rax),%edx
mov    $0x73,%eax
mov    $0x53,%ecx
cmp    $0x2d,%edx
cmove  %ecx,%eax
mov    %al,%cl
mov    -0x8(%rbp),%rax
mov    %cl,0x6(%rax)
mov    -0x10(%rbp),%eax
mov    0x2c95(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     135f <get_perm_string+0x1ef>
mov    -0x8(%rbp),%rax
movsbl 0x3(%rax),%edx
mov    $0x73,%eax
mov    $0x53,%ecx
cmp    $0x2d,%edx
cmove  %ecx,%eax
mov    %al,%cl
mov    -0x8(%rbp),%rax
mov    %cl,0x3(%rax)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_perm_string>:
push   %rbp
push   %r14
push   %rbx
mov    %edx,%ebp
mov    %rdi,%r14
mov    0x2e60(%rip),%rax
mov    (%rax),%eax
and    %edx,%eax
sar    $0x6,%eax
mov    0x2e42(%rip),%rcx
mov    (%rcx),%edx
and    %ebp,%edx
sar    $0x3,%edx
mov    0x2e54(%rip),%rcx
mov    (%rcx),%ecx
and    %ebp,%ecx
movslq %ecx,%rdi
cltq
lea    0x2c04(%rip),%rbx
mov    (%rbx,%rax,8),%rcx
movslq %edx,%rax
mov    (%rbx,%rax,8),%r8
mov    (%rbx,%rdi,8),%r9
lea    0xe5e(%rip),%rdx
mov    %r14,%rdi
call   1070 <snprintf@plt>
mov    %ebp,%edi
call   1030 <S_ISLNK@plt>
mov    $0x6c,%cl
test   %rax,%rax
jne    121e <get_perm_string+0xae>
mov    %ebp,%edi
call   1060 <S_ISDIR@plt>
mov    $0x64,%cl
test   %rax,%rax
jne    121e <get_perm_string+0xae>
mov    %ebp,%edi
call   1090 <S_ISBLK@plt>
mov    $0x62,%cl
test   %rax,%rax
jne    121e <get_perm_string+0xae>
mov    %ebp,%edi
call   1080 <S_ISCHR@plt>
mov    $0x63,%cl
test   %rax,%rax
jne    121e <get_perm_string+0xae>
mov    %ebp,%edi
call   1040 <S_ISFIFO@plt>
mov    $0x70,%cl
test   %rax,%rax
jne    121e <get_perm_string+0xae>
mov    %ebp,%edi
call   1050 <S_ISSOCK@plt>
mov    $0x73,%cl
test   %rax,%rax
je     1221 <get_perm_string+0xb1>
mov    %cl,(%r14)
mov    0x2db0(%rip),%rax
test   %ebp,(%rax)
je     123d <get_perm_string+0xcd>
cmpb   $0x2d,0x9(%r14)
setne  %al
shl    $0x5,%al
or     $0x54,%al
mov    %al,0x9(%r14)
mov    0x2d74(%rip),%rax
test   %ebp,(%rax)
je     1259 <get_perm_string+0xe9>
cmpb   $0x2d,0x6(%r14)
setne  %al
shl    $0x5,%al
or     $0x53,%al
mov    %al,0x6(%r14)
mov    0x2d68(%rip),%rax
test   %ebp,(%rax)
je     1275 <get_perm_string+0x105>
cmpb   $0x2d,0x3(%r14)
setne  %al
shl    $0x5,%al
or     $0x53,%al
mov    %al,0x3(%r14)
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@get_perm_string.perm_sets = internal constant [8 x i8*] [i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i32 0, i32 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i32 0, i32 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i32 0, i32 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i32 0, i32 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i32 0, i32 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i32 0, i32 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.7, i32 0, i32 0)]
@.str = [4 x i8] c"---\00"
@.str.1 = [4 x i8] c"--x\00"
@.str.2 = [4 x i8] c"-w-\00"
@.str.3 = [4 x i8] c"-wx\00"
@.str.4 = [4 x i8] c"r--\00"
@.str.5 = [4 x i8] c"r-x\00"
@.str.6 = [4 x i8] c"rw-\00"
@.str.7 = [4 x i8] c"rwx\00"
@S_IRWXU = global i32 0
@S_IRWXG = global i32 0
@S_IRWXO = global i32 0
@.str.8 = [8 x i8] c"-%s%s%s\00"
@S_ISVTX = global i32 0
@S_ISGID = global i32 0
@S_ISUID = global i32 0
define void @get_perm_string(i8* %0, i32 %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%10 = load i32, i32* %6
%11 = load i32, i32* @S_IRWXU
%12 = and i32 %10, %11
%13 = ashr i32 %12, 6
store i32 %13, i32* %7
%14 = load i32, i32* %6
%15 = load i32, i32* @S_IRWXG
%16 = and i32 %14, %15
%17 = ashr i32 %16, 3
store i32 %17, i32* %8
%18 = load i32, i32* %6
%19 = load i32, i32* @S_IRWXO
%20 = and i32 %18, %19
store i32 %20, i32* %9
%21 = load i8*, i8** %4
%22 = load i32, i32* %5
%23 = load i32, i32* %7
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds [8 x i8*], [8 x i8*]* @get_perm_string.perm_sets, i64 0, i64 %24
%26 = load i8*, i8** %25
%27 = load i32, i32* %8
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds [8 x i8*], [8 x i8*]* @get_perm_string.perm_sets, i64 0, i64 %28
%30 = load i8*, i8** %29
%31 = load i32, i32* %9
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds [8 x i8*], [8 x i8*]* @get_perm_string.perm_sets, i64 0, i64 %32
%34 = load i8*, i8** %33
%35 = call i32 @snprintf(i8* %21, i32 %22, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.8, i64 0, i64 0), i8* %26, i8* %30, i8* %34)
%36 = load i32, i32* %6
%37 = call i64 @S_ISLNK(i32 %36)
%38 = icmp ne i64 %37, 0
br i1 %38, label %39, label %42
39: ; preds = %3
%40 = load i8*, i8** %4
%41 = getelementptr inbounds i8, i8* %40, i64 0
store i8 108, i8* %41
br label %82
42: ; preds = %3
%43 = load i32, i32* %6
%44 = call i64 @S_ISDIR(i32 %43)
%45 = icmp ne i64 %44, 0
br i1 %45, label %46, label %49
46: ; preds = %42
%47 = load i8*, i8** %4
%48 = getelementptr inbounds i8, i8* %47, i64 0
store i8 100, i8* %48
br label %81
49: ; preds = %42
%50 = load i32, i32* %6
%51 = call i64 @S_ISBLK(i32 %50)
%52 = icmp ne i64 %51, 0
br i1 %52, label %53, label %56
53: ; preds = %49
%54 = load i8*, i8** %4
%55 = getelementptr inbounds i8, i8* %54, i64 0
store i8 98, i8* %55
br label %80
56: ; preds = %49
%57 = load i32, i32* %6
%58 = call i64 @S_ISCHR(i32 %57)
%59 = icmp ne i64 %58, 0
br i1 %59, label %60, label %63
60: ; preds = %56
%61 = load i8*, i8** %4
%62 = getelementptr inbounds i8, i8* %61, i64 0
store i8 99, i8* %62
br label %79
63: ; preds = %56
%64 = load i32, i32* %6
%65 = call i64 @S_ISFIFO(i32 %64)
%66 = icmp ne i64 %65, 0
br i1 %66, label %67, label %70
67: ; preds = %63
%68 = load i8*, i8** %4
%69 = getelementptr inbounds i8, i8* %68, i64 0
store i8 112, i8* %69
br label %78
70: ; preds = %63
%71 = load i32, i32* %6
%72 = call i64 @S_ISSOCK(i32 %71)
%73 = icmp ne i64 %72, 0
br i1 %73, label %74, label %77
74: ; preds = %70
%75 = load i8*, i8** %4
%76 = getelementptr inbounds i8, i8* %75, i64 0
store i8 115, i8* %76
br label %77
77: ; preds = %74, %70
br label %78
78: ; preds = %77, %67
br label %79
79: ; preds = %78, %60
br label %80
80: ; preds = %79, %53
br label %81
81: ; preds = %80, %46
br label %82
82: ; preds = %81, %39
%83 = load i32, i32* %6
%84 = load i32, i32* @S_ISVTX
%85 = and i32 %83, %84
%86 = icmp ne i32 %85, 0
br i1 %86, label %87, label %98
87: ; preds = %82
%88 = load i8*, i8** %4
%89 = getelementptr inbounds i8, i8* %88, i64 9
%90 = load i8, i8* %89
%91 = sext i8 %90 to i32
%92 = icmp eq i32 %91, 45
%93 = zext i1 %92 to i64
%94 = select i1 %92, i32 84, i32 116
%95 = trunc i32 %94 to i8
%96 = load i8*, i8** %4
%97 = getelementptr inbounds i8, i8* %96, i64 9
store i8 %95, i8* %97
br label %98
98: ; preds = %87, %82
%99 = load i32, i32* %6
%100 = load i32, i32* @S_ISGID
%101 = and i32 %99, %100
%102 = icmp ne i32 %101, 0
br i1 %102, label %103, label %114
103: ; preds = %98
%104 = load i8*, i8** %4
%105 = getelementptr inbounds i8, i8* %104, i64 6
%106 = load i8, i8* %105
%107 = sext i8 %106 to i32
%108 = icmp eq i32 %107, 45
%109 = zext i1 %108 to i64
%110 = select i1 %108, i32 83, i32 115
%111 = trunc i32 %110 to i8
%112 = load i8*, i8** %4
%113 = getelementptr inbounds i8, i8* %112, i64 6
store i8 %111, i8* %113
br label %114
114: ; preds = %103, %98
%115 = load i32, i32* %6
%116 = load i32, i32* @S_ISUID
%117 = and i32 %115, %116
%118 = icmp ne i32 %117, 0
br i1 %118, label %119, label %130
119: ; preds = %114
%120 = load i8*, i8** %4
%121 = getelementptr inbounds i8, i8* %120, i64 3
%122 = load i8, i8* %121
%123 = sext i8 %122 to i32
%124 = icmp eq i32 %123, 45
%125 = zext i1 %124 to i64
%126 = select i1 %124, i32 83, i32 115
%127 = trunc i32 %126 to i8
%128 = load i8*, i8** %4
%129 = getelementptr inbounds i8, i8* %128, i64 3
store i8 %127, i8* %129
br label %130
130: ; preds = %119, %114
ret void
}

LLVM IR (-O2):
@get_perm_string.perm_sets = internal unnamed_addr constant [8 x i8*] [i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i32 0, i32 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i32 0, i32 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i32 0, i32 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i32 0, i32 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i32 0, i32 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i32 0, i32 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.7, i32 0, i32 0)]
@.str = [4 x i8] c"---\00"
@.str.1 = [4 x i8] c"--x\00"
@.str.2 = [4 x i8] c"-w-\00"
@.str.3 = [4 x i8] c"-wx\00"
@.str.4 = [4 x i8] c"r--\00"
@.str.5 = [4 x i8] c"r-x\00"
@.str.6 = [4 x i8] c"rw-\00"
@.str.7 = [4 x i8] c"rwx\00"
@S_IRWXU = global i32 0
@S_IRWXG = global i32 0
@S_IRWXO = global i32 0
@.str.8 = [8 x i8] c"-%s%s%s\00"
@S_ISVTX = global i32 0
@S_ISGID = global i32 0
@S_ISUID = global i32 0
define void @get_perm_string(i8* %0, i32 %1, i32 %2) {
%4 = load i32, i32* @S_IRWXU
%5 = and i32 %4, %2
%6 = ashr i32 %5, 6
%7 = load i32, i32* @S_IRWXG
%8 = and i32 %7, %2
%9 = ashr i32 %8, 3
%10 = load i32, i32* @S_IRWXO
%11 = and i32 %10, %2
%12 = sext i32 %6 to i64
%13 = getelementptr inbounds [8 x i8*], [8 x i8*]* @get_perm_string.perm_sets, i64 0, i64 %12
%14 = load i8*, i8** %13
%15 = sext i32 %9 to i64
%16 = getelementptr inbounds [8 x i8*], [8 x i8*]* @get_perm_string.perm_sets, i64 0, i64 %15
%17 = load i8*, i8** %16
%18 = sext i32 %11 to i64
%19 = getelementptr inbounds [8 x i8*], [8 x i8*]* @get_perm_string.perm_sets, i64 0, i64 %18
%20 = load i8*, i8** %19
%21 = tail call i32 @snprintf(i8* %0, i32 %1, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.8, i64 0, i64 0), i8* %14, i8* %17, i8* %20)
%22 = tail call i64 @S_ISLNK(i32 %2)
%23 = icmp eq i64 %22, 0
br i1 %23, label %24, label %39
24: ; preds = %3
%25 = tail call i64 @S_ISDIR(i32 %2)
%26 = icmp eq i64 %25, 0
br i1 %26, label %27, label %39
27: ; preds = %24
%28 = tail call i64 @S_ISBLK(i32 %2)
%29 = icmp eq i64 %28, 0
br i1 %29, label %30, label %39
30: ; preds = %27
%31 = tail call i64 @S_ISCHR(i32 %2)
%32 = icmp eq i64 %31, 0
br i1 %32, label %33, label %39
33: ; preds = %30
%34 = tail call i64 @S_ISFIFO(i32 %2)
%35 = icmp eq i64 %34, 0
br i1 %35, label %36, label %39
36: ; preds = %33
%37 = tail call i64 @S_ISSOCK(i32 %2)
%38 = icmp eq i64 %37, 0
br i1 %38, label %41, label %39
39: ; preds = %36, %33, %30, %27, %24, %3
%40 = phi i8 [ 108, %3 ], [ 100, %24 ], [ 98, %27 ], [ 99, %30 ], [ 112, %33 ], [ 115, %36 ]
store i8 %40, i8* %0
br label %41
41: ; preds = %39, %36
%42 = load i32, i32* @S_ISVTX
%43 = and i32 %42, %2
%44 = icmp eq i32 %43, 0
br i1 %44, label %50, label %45
45: ; preds = %41
%46 = getelementptr inbounds i8, i8* %0, i64 9
%47 = load i8, i8* %46
%48 = icmp eq i8 %47, 45
%49 = select i1 %48, i8 84, i8 116
store i8 %49, i8* %46
br label %50
50: ; preds = %45, %41
%51 = load i32, i32* @S_ISGID
%52 = and i32 %51, %2
%53 = icmp eq i32 %52, 0
br i1 %53, label %59, label %54
54: ; preds = %50
%55 = getelementptr inbounds i8, i8* %0, i64 6
%56 = load i8, i8* %55
%57 = icmp eq i8 %56, 45
%58 = select i1 %57, i8 83, i8 115
store i8 %58, i8* %55
br label %59
59: ; preds = %54, %50
%60 = load i32, i32* @S_ISUID
%61 = and i32 %60, %2
%62 = icmp eq i32 %61, 0
br i1 %62, label %68, label %63
63: ; preds = %59
%64 = getelementptr inbounds i8, i8* %0, i64 3
%65 = load i8, i8* %64
%66 = icmp eq i8 %65, 45
%67 = select i1 %66, i8 83, i8 115
store i8 %67, i8* %64
br label %68
68: ; preds = %63, %59
ret void
}