#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 133
#define S_IFCHR 132
#define S_IFDIR 131
#define S_IFIFO 130
#define S_IFLNK 129
int S_IFMT;
#define S_IFSOCK 128
int S_ISGID;
int S_ISUID;
int S_ISVTX;
int S_IXGRP;
int S_IXOTH;
int S_IXUSR;
int /*<<< orphan*/ strcpy(char *, char const *);
scalar_t__ utils_calloc(int, int);
char *_file_info_permissions(mode_t mode) {
  static const char *rwx[] = {"---", "--x", "-w-", "-wx",
                              "r--", "r-x", "rw-", "rwx"};
  char *bits = (char *)utils_calloc(11, sizeof(char));
  switch (mode & S_IFMT) {
  case S_IFSOCK:
    *bits = 's';
    break;
  case S_IFLNK:
    *bits = 'l';
    break;
  case S_IFBLK:
    *bits = 'b';
    break;
  case S_IFDIR:
    *bits = 'd';
    break;
  case S_IFCHR:
    *bits = 'c';
    break;
  case S_IFIFO:
    *bits = 'p';
    break;
  default:
    *bits = '-';
  }
  strcpy(&bits[1], rwx[(mode >> 6) & 7]);
  strcpy(&bits[4], rwx[(mode >> 3) & 7]);
  strcpy(&bits[7], rwx[(mode & 7)]);
  if (mode & S_ISUID) {
    bits[3] = (mode & S_IXUSR) ? 's' : 'S';
  }
  if (mode & S_ISGID) {
    bits[6] = (mode & S_IXGRP) ? 's' : 'l';
  }
  if (mode & S_ISVTX) {
    bits[9] = (mode & S_IXOTH) ? 't' : 'T';
  }
  return bits;
}


x86 assembly (clang, -O0):
<_file_info_permissions>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    $0xb,%edi
mov    $0x1,%esi
call   1040 <utils_calloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x4(%rbp),%eax
mov    0x2e70(%rip),%rcx
mov    (%rcx),%ecx
and    %ecx,%eax
add    $0xffffff80,%eax
mov    %eax,%ecx
mov    %rcx,-0x18(%rbp)
sub    $0x5,%eax
ja     11ba <_file_info_permissions+0x9a>
mov    -0x18(%rbp),%rax
lea    0xe97(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x10(%rbp),%rax
movb   $0x73,(%rax)
jmp    11c1 <_file_info_permissions+0xa1>
mov    -0x10(%rbp),%rax
movb   $0x6c,(%rax)
jmp    11c1 <_file_info_permissions+0xa1>
mov    -0x10(%rbp),%rax
movb   $0x62,(%rax)
jmp    11c1 <_file_info_permissions+0xa1>
mov    -0x10(%rbp),%rax
movb   $0x64,(%rax)
jmp    11c1 <_file_info_permissions+0xa1>
mov    -0x10(%rbp),%rax
movb   $0x63,(%rax)
jmp    11c1 <_file_info_permissions+0xa1>
mov    -0x10(%rbp),%rax
movb   $0x70,(%rax)
jmp    11c1 <_file_info_permissions+0xa1>
mov    -0x10(%rbp),%rax
movb   $0x2d,(%rax)
mov    -0x10(%rbp),%rdi
add    $0x1,%rdi
mov    -0x4(%rbp),%eax
sar    $0x6,%eax
and    $0x7,%eax
movslq %eax,%rcx
lea    0x2e64(%rip),%rax
mov    (%rax,%rcx,8),%rsi
call   1030 <strcpy@plt>
mov    -0x10(%rbp),%rdi
add    $0x4,%rdi
mov    -0x4(%rbp),%eax
sar    $0x3,%eax
and    $0x7,%eax
movslq %eax,%rcx
lea    0x2e40(%rip),%rax
mov    (%rax,%rcx,8),%rsi
call   1030 <strcpy@plt>
mov    -0x10(%rbp),%rdi
add    $0x7,%rdi
mov    -0x4(%rbp),%eax
and    $0x7,%eax
movslq %eax,%rcx
lea    0x2e1f(%rip),%rax
mov    (%rax,%rcx,8),%rsi
call   1030 <strcpy@plt>
mov    -0x4(%rbp),%eax
mov    0x2d9c(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     1264 <_file_info_permissions+0x144>
mov    -0x4(%rbp),%edx
mov    0x2d8f(%rip),%rax
and    (%rax),%edx
mov    $0x53,%eax
mov    $0x73,%ecx
cmp    $0x0,%edx
cmovne %ecx,%eax
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %cl,0x3(%rax)
mov    -0x4(%rbp),%eax
mov    0x2d42(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     129e <_file_info_permissions+0x17e>
mov    -0x4(%rbp),%edx
mov    0x2d45(%rip),%rax
and    (%rax),%edx
mov    $0x6c,%eax
mov    $0x73,%ecx
cmp    $0x0,%edx
cmovne %ecx,%eax
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %cl,0x6(%rax)
mov    -0x4(%rbp),%eax
mov    0x2d40(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     12d8 <_file_info_permissions+0x1b8>
mov    -0x4(%rbp),%edx
mov    0x2d23(%rip),%rax
and    (%rax),%edx
mov    $0x54,%eax
mov    $0x74,%ecx
cmp    $0x0,%edx
cmovne %ecx,%eax
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %cl,0x9(%rax)
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_file_info_permissions>:
push   %r15
push   %r14
push   %rbx
mov    %edi,%ebx
mov    $0xb,%edi
mov    $0x1,%esi
call   1040 <utils_calloc@plt>
mov    0x2e73(%rip),%rcx
mov    (%rcx),%edx
and    %ebx,%edx
lea    -0x400(,%rdx,8),%ecx
movabs $0x626364706c73,%rsi
shr    %cl,%rsi
mov    %rax,%r14
mov    %edx,%eax
add    $0xffffff80,%eax
cmp    $0x6,%eax
mov    $0x2d,%eax
cmovb  %esi,%eax
mov    %al,(%r14)
lea    0x1(%r14),%rdi
mov    %ebx,%eax
shr    $0x6,%eax
and    $0x7,%eax
lea    0x2c22(%rip),%r15
mov    (%r15,%rax,8),%rsi
call   1030 <strcpy@plt>
lea    0x4(%r14),%rdi
mov    %ebx,%eax
shr    $0x3,%eax
and    $0x7,%eax
mov    (%r15,%rax,8),%rsi
call   1030 <strcpy@plt>
mov    %r14,%rdi
add    $0x7,%rdi
mov    %ebx,%eax
and    $0x7,%eax
mov    (%r15,%rax,8),%rsi
call   1030 <strcpy@plt>
mov    0x2e10(%rip),%rax
test   %ebx,(%rax)
je     11d3 <_file_info_permissions+0xb3>
mov    0x2e0d(%rip),%rax
mov    (%rax),%eax
and    %ebx,%eax
setne  %al
shl    $0x5,%al
or     $0x53,%al
mov    %al,0x3(%r14)
mov    0x2dce(%rip),%rax
test   %ebx,(%rax)
je     11fa <_file_info_permissions+0xda>
mov    0x2ddb(%rip),%rax
mov    (%rax),%eax
and    %ebx,%eax
mov    $0x6c,%eax
mov    $0x73,%ecx
cmove  %eax,%ecx
mov    %cl,0x6(%r14)
mov    0x2ddf(%rip),%rax
test   %ebx,(%rax)
je     121a <_file_info_permissions+0xfa>
mov    0x2dcc(%rip),%rax
and    (%rax),%ebx
setne  %al
shl    $0x5,%al
or     $0x54,%al
mov    %al,0x9(%r14)
mov    %r14,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@_file_info_permissions.rwx = internal global [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_IFMT = global i32 0
@S_ISUID = global i32 0
@S_IXUSR = global i32 0
@S_ISGID = global i32 0
@S_IXGRP = global i32 0
@S_ISVTX = global i32 0
@S_IXOTH = global i32 0
define i8* @_file_info_permissions(i32 %0) {
%2 = alloca i32
%3 = alloca i8*
store i32 %0, i32* %2
%4 = call i64 @utils_calloc(i32 11, i32 1)
%5 = inttoptr i64 %4 to i8*
store i8* %5, i8** %3
%6 = load i32, i32* %2
%7 = load i32, i32* @S_IFMT
%8 = and i32 %6, %7
switch i32 %8, label %21 [
i32 128, label %9
i32 129, label %11
i32 133, label %13
i32 131, label %15
i32 132, label %17
i32 130, label %19
]
9: ; preds = %1
%10 = load i8*, i8** %3
store i8 115, i8* %10
br label %23
11: ; preds = %1
%12 = load i8*, i8** %3
store i8 108, i8* %12
br label %23
13: ; preds = %1
%14 = load i8*, i8** %3
store i8 98, i8* %14
br label %23
15: ; preds = %1
%16 = load i8*, i8** %3
store i8 100, i8* %16
br label %23
17: ; preds = %1
%18 = load i8*, i8** %3
store i8 99, i8* %18
br label %23
19: ; preds = %1
%20 = load i8*, i8** %3
store i8 112, i8* %20
br label %23
21: ; preds = %1
%22 = load i8*, i8** %3
store i8 45, i8* %22
br label %23
23: ; preds = %21, %19, %17, %15, %13, %11, %9
%24 = load i8*, i8** %3
%25 = getelementptr inbounds i8, i8* %24, i64 1
%26 = load i32, i32* %2
%27 = ashr i32 %26, 6
%28 = and i32 %27, 7
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds [8 x i8*], [8 x i8*]* @_file_info_permissions.rwx, i64 0, i64 %29
%31 = load i8*, i8** %30
%32 = call i32 @strcpy(i8* %25, i8* %31)
%33 = load i8*, i8** %3
%34 = getelementptr inbounds i8, i8* %33, i64 4
%35 = load i32, i32* %2
%36 = ashr i32 %35, 3
%37 = and i32 %36, 7
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds [8 x i8*], [8 x i8*]* @_file_info_permissions.rwx, i64 0, i64 %38
%40 = load i8*, i8** %39
%41 = call i32 @strcpy(i8* %34, i8* %40)
%42 = load i8*, i8** %3
%43 = getelementptr inbounds i8, i8* %42, i64 7
%44 = load i32, i32* %2
%45 = and i32 %44, 7
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds [8 x i8*], [8 x i8*]* @_file_info_permissions.rwx, i64 0, i64 %46
%48 = load i8*, i8** %47
%49 = call i32 @strcpy(i8* %43, i8* %48)
%50 = load i32, i32* %2
%51 = load i32, i32* @S_ISUID
%52 = and i32 %50, %51
%53 = icmp ne i32 %52, 0
br i1 %53, label %54, label %64
54: ; preds = %23
%55 = load i32, i32* %2
%56 = load i32, i32* @S_IXUSR
%57 = and i32 %55, %56
%58 = icmp ne i32 %57, 0
%59 = zext i1 %58 to i64
%60 = select i1 %58, i32 115, i32 83
%61 = trunc i32 %60 to i8
%62 = load i8*, i8** %3
%63 = getelementptr inbounds i8, i8* %62, i64 3
store i8 %61, i8* %63
br label %64
64: ; preds = %54, %23
%65 = load i32, i32* %2
%66 = load i32, i32* @S_ISGID
%67 = and i32 %65, %66
%68 = icmp ne i32 %67, 0
br i1 %68, label %69, label %79
69: ; preds = %64
%70 = load i32, i32* %2
%71 = load i32, i32* @S_IXGRP
%72 = and i32 %70, %71
%73 = icmp ne i32 %72, 0
%74 = zext i1 %73 to i64
%75 = select i1 %73, i32 115, i32 108
%76 = trunc i32 %75 to i8
%77 = load i8*, i8** %3
%78 = getelementptr inbounds i8, i8* %77, i64 6
store i8 %76, i8* %78
br label %79
79: ; preds = %69, %64
%80 = load i32, i32* %2
%81 = load i32, i32* @S_ISVTX
%82 = and i32 %80, %81
%83 = icmp ne i32 %82, 0
br i1 %83, label %84, label %94
84: ; preds = %79
%85 = load i32, i32* %2
%86 = load i32, i32* @S_IXOTH
%87 = and i32 %85, %86
%88 = icmp ne i32 %87, 0
%89 = zext i1 %88 to i64
%90 = select i1 %88, i32 116, i32 84
%91 = trunc i32 %90 to i8
%92 = load i8*, i8** %3
%93 = getelementptr inbounds i8, i8* %92, i64 9
store i8 %91, i8* %93
br label %94
94: ; preds = %84, %79
%95 = load i8*, i8** %3
ret i8* %95
}

LLVM IR (-O2):
@_file_info_permissions.rwx = 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_IFMT = global i32 0
@S_ISUID = global i32 0
@S_IXUSR = global i32 0
@S_ISGID = global i32 0
@S_IXGRP = global i32 0
@S_ISVTX = global i32 0
@S_IXOTH = global i32 0
define i8* @_file_info_permissions(i32 %0) {
%2 = tail call i64 @utils_calloc(i32 11, i32 1)
%3 = inttoptr i64 %2 to i8*
%4 = load i32, i32* @S_IFMT
%5 = and i32 %4, %0
%6 = add i32 %5, -128
%7 = icmp ult i32 %6, 6
%8 = zext i32 %6 to i48
%9 = shl nuw nsw i48 %8, 3
%10 = lshr i48 108179026373747, %9
%11 = trunc i48 %10 to i8
%12 = select i1 %7, i8 %11, i8 45
store i8 %12, i8* %3
%13 = getelementptr inbounds i8, i8* %3, i64 1
%14 = lshr i32 %0, 6
%15 = and i32 %14, 7
%16 = zext i32 %15 to i64
%17 = getelementptr inbounds [8 x i8*], [8 x i8*]* @_file_info_permissions.rwx, i64 0, i64 %16
%18 = load i8*, i8** %17
%19 = tail call i32 @strcpy(i8* %13, i8* %18)
%20 = getelementptr inbounds i8, i8* %3, i64 4
%21 = lshr i32 %0, 3
%22 = and i32 %21, 7
%23 = zext i32 %22 to i64
%24 = getelementptr inbounds [8 x i8*], [8 x i8*]* @_file_info_permissions.rwx, i64 0, i64 %23
%25 = load i8*, i8** %24
%26 = tail call i32 @strcpy(i8* %20, i8* %25)
%27 = getelementptr inbounds i8, i8* %3, i64 7
%28 = and i32 %0, 7
%29 = zext i32 %28 to i64
%30 = getelementptr inbounds [8 x i8*], [8 x i8*]* @_file_info_permissions.rwx, i64 0, i64 %29
%31 = load i8*, i8** %30
%32 = tail call i32 @strcpy(i8* %27, i8* %31)
%33 = load i32, i32* @S_ISUID
%34 = and i32 %33, %0
%35 = icmp eq i32 %34, 0
br i1 %35, label %42, label %36
36: ; preds = %1
%37 = load i32, i32* @S_IXUSR
%38 = and i32 %37, %0
%39 = icmp eq i32 %38, 0
%40 = select i1 %39, i8 83, i8 115
%41 = getelementptr inbounds i8, i8* %3, i64 3
store i8 %40, i8* %41
br label %42
42: ; preds = %36, %1
%43 = load i32, i32* @S_ISGID
%44 = and i32 %43, %0
%45 = icmp eq i32 %44, 0
br i1 %45, label %52, label %46
46: ; preds = %42
%47 = load i32, i32* @S_IXGRP
%48 = and i32 %47, %0
%49 = icmp eq i32 %48, 0
%50 = select i1 %49, i8 108, i8 115
%51 = getelementptr inbounds i8, i8* %3, i64 6
store i8 %50, i8* %51
br label %52
52: ; preds = %46, %42
%53 = load i32, i32* @S_ISVTX
%54 = and i32 %53, %0
%55 = icmp eq i32 %54, 0
br i1 %55, label %62, label %56
56: ; preds = %52
%57 = load i32, i32* @S_IXOTH
%58 = and i32 %57, %0
%59 = icmp eq i32 %58, 0
%60 = select i1 %59, i8 84, i8 116
%61 = getelementptr inbounds i8, i8* %3, i64 9
store i8 %60, i8* %61
br label %62
62: ; preds = %56, %52
ret i8* %3
}