#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 */
struct stat {
  int st_mode;
};

/* Variables and functions */
int S_IRGRP;
int S_IROTH;
int S_IRUSR;
int S_ISGID;
int S_ISUID;
int S_ISVTX;
int S_IWGRP;
int S_IWOTH;
int S_IWUSR;
int S_IXGRP;
int S_IXOTH;
int S_IXUSR;
char do_get_type(struct stat);
char *do_get_perms(struct stat attr) {
  static char perms[11];
  char type = do_get_type(attr);
  perms[0] = (char)(type == 'f' ? '-' : type);
  perms[1] = (char)(attr.st_mode & S_IRUSR ? 'r' : '-');
  perms[2] = (char)(attr.st_mode & S_IWUSR ? 'w' : '-');
  perms[3] =
      (char)(attr.st_mode & S_ISUID ? (attr.st_mode & S_IXUSR ? 's' : 'S')
                                    : (attr.st_mode & S_IXUSR ? 'x' : '-'));
  perms[4] = (char)(attr.st_mode & S_IRGRP ? 'r' : '-');
  perms[5] = (char)(attr.st_mode & S_IWGRP ? 'w' : '-');
  perms[6] =
      (char)(attr.st_mode & S_ISGID ? (attr.st_mode & S_IXGRP ? 's' : 'S')
                                    : (attr.st_mode & S_IXGRP ? 'x' : '-'));
  perms[7] = (char)(attr.st_mode & S_IROTH ? 'r' : '-');
  perms[8] = (char)(attr.st_mode & S_IWOTH ? 'w' : '-');
  perms[9] =
      (char)(attr.st_mode & S_ISVTX ? (attr.st_mode & S_IXOTH ? 't' : 'T')
                                    : (attr.st_mode & S_IXOTH ? 'x' : '-'));
  perms[10] = '\0';
  return perms;
}


x86 assembly (clang, -O0):
<do_get_perms>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    -0x8(%rbp),%edi
call   1030 <do_get_type@plt>
mov    %al,-0x9(%rbp)
movsbl -0x9(%rbp),%eax
cmp    $0x66,%eax
jne    1140 <do_get_perms+0x30>
mov    $0x2d,%eax
mov    %eax,-0x10(%rbp)
jmp    1147 <do_get_perms+0x37>
movsbl -0x9(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%eax
mov    %al,0x2edc(%rip)
mov    -0x8(%rbp),%edx
mov    0x2e36(%rip),%rax
and    (%rax),%edx
mov    $0x2d,%eax
mov    $0x72,%ecx
cmp    $0x0,%edx
cmovne %ecx,%eax
mov    %al,0x2ebb(%rip)
mov    -0x8(%rbp),%edx
mov    0x2e44(%rip),%rax
and    (%rax),%edx
mov    $0x2d,%eax
mov    $0x77,%ecx
cmp    $0x0,%edx
cmovne %ecx,%eax
mov    %al,0x2e9a(%rip)
mov    -0x8(%rbp),%eax
mov    0x2e32(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     11cd <do_get_perms+0xbd>
mov    -0x8(%rbp),%edx
mov    0x2e25(%rip),%rax
and    (%rax),%edx
mov    $0x53,%eax
mov    $0x73,%ecx
cmp    $0x0,%edx
cmovne %ecx,%eax
mov    %eax,-0x14(%rbp)
jmp    11ec <do_get_perms+0xdc>
mov    -0x8(%rbp),%edx
mov    0x2e01(%rip),%rax
and    (%rax),%edx
mov    $0x2d,%eax
mov    $0x78,%ecx
cmp    $0x0,%edx
cmovne %ecx,%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %al,0x2e3a(%rip)
mov    -0x8(%rbp),%edx
mov    0x2da1(%rip),%rax
and    (%rax),%edx
mov    $0x2d,%eax
mov    $0x72,%ecx
cmp    $0x0,%edx
cmovne %ecx,%eax
mov    %al,0x2e19(%rip)
mov    -0x8(%rbp),%edx
mov    0x2da7(%rip),%rax
and    (%rax),%edx
mov    $0x2d,%eax
mov    $0x77,%ecx
cmp    $0x0,%edx
cmovne %ecx,%eax
mov    %al,0x2df8(%rip)
mov    -0x8(%rbp),%eax
mov    0x2d65(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     1272 <do_get_perms+0x162>
mov    -0x8(%rbp),%edx
mov    0x2d60(%rip),%rax
and    (%rax),%edx
mov    $0x53,%eax
mov    $0x73,%ecx
cmp    $0x0,%edx
cmovne %ecx,%eax
mov    %eax,-0x18(%rbp)
jmp    1291 <do_get_perms+0x181>
mov    -0x8(%rbp),%edx
mov    0x2d3c(%rip),%rax
and    (%rax),%edx
mov    $0x2d,%eax
mov    $0x78,%ecx
cmp    $0x0,%edx
cmovne %ecx,%eax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    %al,0x2d98(%rip)
mov    -0x8(%rbp),%edx
mov    0x2cf4(%rip),%rax
and    (%rax),%edx
mov    $0x2d,%eax
mov    $0x72,%ecx
cmp    $0x0,%edx
cmovne %ecx,%eax
mov    %al,0x2d77(%rip)
mov    -0x8(%rbp),%edx
mov    0x2cba(%rip),%rax
and    (%rax),%edx
mov    $0x2d,%eax
mov    $0x77,%ecx
cmp    $0x0,%edx
cmovne %ecx,%eax
mov    %al,0x2d56(%rip)
mov    -0x8(%rbp),%eax
mov    0x2d00(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     1317 <do_get_perms+0x207>
mov    -0x8(%rbp),%edx
mov    0x2ce3(%rip),%rax
and    (%rax),%edx
mov    $0x54,%eax
mov    $0x74,%ecx
cmp    $0x0,%edx
cmovne %ecx,%eax
mov    %eax,-0x1c(%rbp)
jmp    1336 <do_get_perms+0x226>
mov    -0x8(%rbp),%edx
mov    0x2cbf(%rip),%rax
and    (%rax),%edx
mov    $0x2d,%eax
mov    $0x78,%ecx
cmp    $0x0,%edx
cmovne %ecx,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    %al,0x2cf6(%rip)
movb   $0x0,0x2cf0(%rip)
lea    0x2cdf(%rip),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<do_get_perms>:
push   %rbx
mov    %edi,%ebx
call   1030 <do_get_type@plt>
cmp    $0x66,%al
movzbl %al,%eax
mov    $0x2d,%edi
cmove  %edi,%eax
mov    %al,0x2f01(%rip)
lea    0x2efa(%rip),%rax
mov    0x2e57(%rip),%rdx
mov    (%rdx),%edx
and    %ebx,%edx
mov    $0x72,%edx
cmove  %edi,%edx
mov    $0x72,%r9d
mov    %dl,0x2edc(%rip)
mov    0x2e68(%rip),%rdx
mov    (%rdx),%edx
and    %ebx,%edx
mov    $0x77,%esi
cmove  %edi,%esi
mov    $0x77,%r8d
mov    %sil,0x2ebd(%rip)
mov    0x2e58(%rip),%rsi
mov    (%rsi),%edx
and    %ebx,%edx
mov    0x2e55(%rip),%rsi
mov    (%rsi),%esi
and    %ebx,%esi
setne  %cl
mov    $0x78,%esi
cmove  %edi,%esi
mov    $0x78,%r10d
shl    $0x5,%cl
or     $0x53,%cl
test   %edx,%edx
movzbl %cl,%ecx
cmove  %esi,%ecx
mov    %cl,0x2e83(%rip)
mov    0x2ded(%rip),%rcx
mov    (%rcx),%ecx
and    %ebx,%ecx
mov    $0x72,%ecx
cmove  %edi,%ecx
mov    0x2e02(%rip),%rdx
mov    (%rdx),%edx
and    %ebx,%edx
mov    $0x77,%edx
cmove  %edi,%edx
mov    %cl,0x2e58(%rip)
mov    %dl,0x2e53(%rip)
mov    0x2dc3(%rip),%rcx
mov    (%rcx),%ecx
and    %ebx,%ecx
mov    0x2dc8(%rip),%rdx
mov    (%rdx),%edx
and    %ebx,%edx
setne  %dl
mov    $0x78,%esi
cmove  %edi,%esi
shl    $0x5,%dl
or     $0x53,%dl
test   %ecx,%ecx
movzbl %dl,%ecx
cmove  %esi,%ecx
mov    %cl,0x2e1f(%rip)
mov    0x2d7e(%rip),%rcx
mov    (%rcx),%ecx
and    %ebx,%ecx
cmove  %edi,%r9d
mov    %r9b,0x2e0a(%rip)
mov    0x2d50(%rip),%rcx
mov    (%rcx),%ecx
and    %ebx,%ecx
cmove  %edi,%r8d
mov    0x2da9(%rip),%rcx
mov    (%rcx),%ecx
and    %ebx,%ecx
mov    0x2d96(%rip),%rdx
and    (%rdx),%ebx
mov    %r8b,0x2de1(%rip)
setne  %dl
cmove  %edi,%r10d
shl    $0x5,%dl
or     $0x54,%dl
test   %ecx,%ecx
movzbl %dl,%ecx
cmove  %r10d,%ecx
mov    %cl,0x2dc6(%rip)
movb   $0x0,0x2dc0(%rip)
pop    %rbx
ret

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

LLVM IR (-O2):
@do_get_perms.perms = internal global [11 x i8] zeroinitializer
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@S_ISUID = global i32 0
@S_IXUSR = global i32 0
@S_IRGRP = global i32 0
@S_IWGRP = global i32 0
@S_ISGID = global i32 0
@S_IXGRP = global i32 0
@S_IROTH = global i32 0
@S_IWOTH = global i32 0
@S_ISVTX = global i32 0
@S_IXOTH = global i32 0
define i8* @do_get_perms(i32 %0) {
%2 = tail call signext i8 @do_get_type(i32 %0)
%3 = icmp eq i8 %2, 102
%4 = select i1 %3, i8 45, i8 %2
store i8 %4, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @do_get_perms.perms, i64 0, i64 0)
%5 = load i32, i32* @S_IRUSR
%6 = and i32 %5, %0
%7 = icmp eq i32 %6, 0
%8 = select i1 %7, i8 45, i8 114
store i8 %8, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @do_get_perms.perms, i64 0, i64 1)
%9 = load i32, i32* @S_IWUSR
%10 = and i32 %9, %0
%11 = icmp eq i32 %10, 0
%12 = select i1 %11, i8 45, i8 119
store i8 %12, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @do_get_perms.perms, i64 0, i64 2)
%13 = load i32, i32* @S_ISUID
%14 = and i32 %13, %0
%15 = icmp eq i32 %14, 0
%16 = load i32, i32* @S_IXUSR
%17 = and i32 %16, %0
%18 = icmp eq i32 %17, 0
%19 = select i1 %18, i8 83, i8 115
%20 = select i1 %18, i8 45, i8 120
%21 = select i1 %15, i8 %20, i8 %19
store i8 %21, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @do_get_perms.perms, i64 0, i64 3)
%22 = load i32, i32* @S_IRGRP
%23 = and i32 %22, %0
%24 = icmp eq i32 %23, 0
%25 = select i1 %24, i8 45, i8 114
store i8 %25, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @do_get_perms.perms, i64 0, i64 4)
%26 = load i32, i32* @S_IWGRP
%27 = and i32 %26, %0
%28 = icmp eq i32 %27, 0
%29 = select i1 %28, i8 45, i8 119
store i8 %29, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @do_get_perms.perms, i64 0, i64 5)
%30 = load i32, i32* @S_ISGID
%31 = and i32 %30, %0
%32 = icmp eq i32 %31, 0
%33 = load i32, i32* @S_IXGRP
%34 = and i32 %33, %0
%35 = icmp eq i32 %34, 0
%36 = select i1 %35, i8 83, i8 115
%37 = select i1 %35, i8 45, i8 120
%38 = select i1 %32, i8 %37, i8 %36
store i8 %38, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @do_get_perms.perms, i64 0, i64 6)
%39 = load i32, i32* @S_IROTH
%40 = and i32 %39, %0
%41 = icmp eq i32 %40, 0
%42 = select i1 %41, i8 45, i8 114
store i8 %42, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @do_get_perms.perms, i64 0, i64 7)
%43 = load i32, i32* @S_IWOTH
%44 = and i32 %43, %0
%45 = icmp eq i32 %44, 0
%46 = select i1 %45, i8 45, i8 119
store i8 %46, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @do_get_perms.perms, i64 0, i64 8)
%47 = load i32, i32* @S_ISVTX
%48 = and i32 %47, %0
%49 = icmp eq i32 %48, 0
%50 = load i32, i32* @S_IXOTH
%51 = and i32 %50, %0
%52 = icmp eq i32 %51, 0
%53 = select i1 %52, i8 84, i8 116
%54 = select i1 %52, i8 45, i8 120
%55 = select i1 %49, i8 %54, i8 %53
store i8 %55, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @do_get_perms.perms, i64 0, i64 9)
store i8 0, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @do_get_perms.perms, i64 0, i64 10)
ret i8* getelementptr inbounds ([11 x i8], [11 x i8]* @do_get_perms.perms, i64 0, i64 0)
}