#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_IRGRP;
int S_IROTH;
int S_IRUSR;
scalar_t__ S_ISDIR(int);
int S_IWGRP;
int S_IWOTH;
int S_IWUSR;
int S_IXGRP;
int S_IXOTH;
int S_IXUSR;
char *mode2str(mode_t mode) {
  static char s[16];
  s[0] = S_ISDIR(mode) ? 'd' : '-';
  s[1] = mode & S_IRUSR ? 'r' : '-';
  s[2] = mode & S_IWUSR ? 'w' : '-';
  s[3] = mode & S_IXUSR ? 'x' : '-';
  s[4] = mode & S_IRGRP ? 'r' : '-';
  s[5] = mode & S_IWGRP ? 'w' : '-';
  s[6] = mode & S_IXGRP ? 'x' : '-';
  s[7] = mode & S_IROTH ? 'r' : '-';
  s[8] = mode & S_IWOTH ? 'w' : '-';
  s[9] = mode & S_IXOTH ? 'x' : '-';
  s[10] = '.';
  s[11] = '\0';
  return s;
}


x86 assembly (clang, -O0):
<mode2str>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%edi
call   1030 <S_ISDIR@plt>
mov    %rax,%rdx
mov    $0x2d,%eax
mov    $0x64,%ecx
cmp    $0x0,%rdx
cmovne %ecx,%eax
mov    %al,0x2f03(%rip)
mov    -0x4(%rbp),%edx
mov    0x2e61(%rip),%rax
and    (%rax),%edx
mov    $0x2d,%eax
mov    $0x72,%ecx
cmp    $0x0,%edx
cmovne %ecx,%eax
mov    %al,0x2ee2(%rip)
mov    -0x4(%rbp),%edx
mov    0x2e67(%rip),%rax
and    (%rax),%edx
mov    $0x2d,%eax
mov    $0x77,%ecx
cmp    $0x0,%edx
cmovne %ecx,%eax
mov    %al,0x2ec1(%rip)
mov    -0x4(%rbp),%edx
mov    0x2e55(%rip),%rax
and    (%rax),%edx
mov    $0x2d,%eax
mov    $0x78,%ecx
cmp    $0x0,%edx
cmovne %ecx,%eax
mov    %al,0x2ea0(%rip)
mov    -0x4(%rbp),%edx
mov    0x2e0b(%rip),%rax
and    (%rax),%edx
mov    $0x2d,%eax
mov    $0x72,%ecx
cmp    $0x0,%edx
cmovne %ecx,%eax
mov    %al,0x2e7f(%rip)
mov    -0x4(%rbp),%edx
mov    0x2e09(%rip),%rax
and    (%rax),%edx
mov    $0x2d,%eax
mov    $0x77,%ecx
cmp    $0x0,%edx
cmovne %ecx,%eax
mov    %al,0x2e5e(%rip)
mov    -0x4(%rbp),%edx
mov    0x2dd7(%rip),%rax
and    (%rax),%edx
mov    $0x2d,%eax
mov    $0x78,%ecx
cmp    $0x0,%edx
cmovne %ecx,%eax
mov    %al,0x2e3d(%rip)
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,0x2e1c(%rip)
mov    -0x4(%rbp),%edx
mov    0x2d63(%rip),%rax
and    (%rax),%edx
mov    $0x2d,%eax
mov    $0x77,%ecx
cmp    $0x0,%edx
cmovne %ecx,%eax
mov    %al,0x2dfb(%rip)
mov    -0x4(%rbp),%edx
mov    0x2d91(%rip),%rax
and    (%rax),%edx
mov    $0x2d,%eax
mov    $0x78,%ecx
cmp    $0x0,%edx
cmovne %ecx,%eax
mov    %al,0x2dda(%rip)
movb   $0x2e,0x2dd4(%rip)
movb   $0x0,0x2dce(%rip)
lea    0x2dbc(%rip),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mode2str>:
push   %rbx
mov    %edi,%ebx
call   1030 <S_ISDIR@plt>
test   %rax,%rax
mov    $0x2d,%ecx
mov    $0x64,%eax
cmove  %ecx,%eax
mov    %al,0x2f12(%rip)
lea    0x2f0b(%rip),%rax
mov    0x2e6c(%rip),%rdx
mov    (%rdx),%edx
and    %ebx,%edx
mov    $0x72,%r8d
mov    $0x72,%esi
cmove  %ecx,%esi
mov    %sil,0x2eec(%rip)
mov    0x2e74(%rip),%rsi
mov    (%rsi),%esi
and    %ebx,%esi
mov    $0x77,%esi
mov    $0x77,%edi
cmove  %ecx,%edi
mov    %dil,0x2ece(%rip)
mov    0x2e65(%rip),%rdi
mov    (%rdi),%edi
and    %ebx,%edi
mov    $0x78,%edi
cmove  %ecx,%edi
mov    0x2e2a(%rip),%rdx
mov    (%rdx),%edx
and    %ebx,%edx
mov    $0x72,%edx
cmove  %ecx,%edx
mov    %dil,0x2ea2(%rip)
mov    %dl,0x2e9d(%rip)
mov    0x2e2a(%rip),%rdx
mov    (%rdx),%edx
and    %ebx,%edx
mov    $0x77,%edx
cmove  %ecx,%edx
mov    $0x78,%edi
mov    %dl,0x2e80(%rip)
mov    0x2dfc(%rip),%rdx
mov    (%rdx),%edx
and    %ebx,%edx
mov    $0x78,%edx
cmove  %ecx,%edx
mov    %dl,0x2e68(%rip)
mov    0x2dcb(%rip),%rdx
mov    (%rdx),%edx
and    %ebx,%edx
cmove  %ecx,%r8d
mov    %r8b,0x2e53(%rip)
mov    0x2d9d(%rip),%rdx
mov    (%rdx),%edx
and    %ebx,%edx
cmove  %ecx,%esi
mov    %sil,0x2e3f(%rip)
mov    0x2dd8(%rip),%rdx
and    (%rdx),%ebx
cmove  %ecx,%edi
mov    %dil,0x2e2d(%rip)
movw   $0x2e,0x2e25(%rip)
pop    %rbx
ret

LLVM IR (-O0):
@mode2str.s = internal global [16 x i8] zeroinitializer
@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 i8* @mode2str(i32 %0) {
%2 = alloca i32
store i32 %0, i32* %2
%3 = load i32, i32* %2
%4 = call i64 @S_ISDIR(i32 %3)
%5 = icmp ne i64 %4, 0
%6 = zext i1 %5 to i64
%7 = select i1 %5, i32 100, i32 45
%8 = trunc i32 %7 to i8
store i8 %8, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @mode2str.s, i64 0, i64 0)
%9 = load i32, i32* %2
%10 = load i32, i32* @S_IRUSR
%11 = and i32 %9, %10
%12 = icmp ne i32 %11, 0
%13 = zext i1 %12 to i64
%14 = select i1 %12, i32 114, i32 45
%15 = trunc i32 %14 to i8
store i8 %15, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @mode2str.s, i64 0, i64 1)
%16 = load i32, i32* %2
%17 = load i32, i32* @S_IWUSR
%18 = and i32 %16, %17
%19 = icmp ne i32 %18, 0
%20 = zext i1 %19 to i64
%21 = select i1 %19, i32 119, i32 45
%22 = trunc i32 %21 to i8
store i8 %22, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @mode2str.s, i64 0, i64 2)
%23 = load i32, i32* %2
%24 = load i32, i32* @S_IXUSR
%25 = and i32 %23, %24
%26 = icmp ne i32 %25, 0
%27 = zext i1 %26 to i64
%28 = select i1 %26, i32 120, i32 45
%29 = trunc i32 %28 to i8
store i8 %29, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @mode2str.s, i64 0, i64 3)
%30 = load i32, i32* %2
%31 = load i32, i32* @S_IRGRP
%32 = and i32 %30, %31
%33 = icmp ne i32 %32, 0
%34 = zext i1 %33 to i64
%35 = select i1 %33, i32 114, i32 45
%36 = trunc i32 %35 to i8
store i8 %36, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @mode2str.s, i64 0, i64 4)
%37 = load i32, i32* %2
%38 = load i32, i32* @S_IWGRP
%39 = and i32 %37, %38
%40 = icmp ne i32 %39, 0
%41 = zext i1 %40 to i64
%42 = select i1 %40, i32 119, i32 45
%43 = trunc i32 %42 to i8
store i8 %43, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @mode2str.s, i64 0, i64 5)
%44 = load i32, i32* %2
%45 = load i32, i32* @S_IXGRP
%46 = and i32 %44, %45
%47 = icmp ne i32 %46, 0
%48 = zext i1 %47 to i64
%49 = select i1 %47, i32 120, i32 45
%50 = trunc i32 %49 to i8
store i8 %50, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @mode2str.s, i64 0, i64 6)
%51 = load i32, i32* %2
%52 = load i32, i32* @S_IROTH
%53 = and i32 %51, %52
%54 = icmp ne i32 %53, 0
%55 = zext i1 %54 to i64
%56 = select i1 %54, i32 114, i32 45
%57 = trunc i32 %56 to i8
store i8 %57, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @mode2str.s, i64 0, i64 7)
%58 = load i32, i32* %2
%59 = load i32, i32* @S_IWOTH
%60 = and i32 %58, %59
%61 = icmp ne i32 %60, 0
%62 = zext i1 %61 to i64
%63 = select i1 %61, i32 119, i32 45
%64 = trunc i32 %63 to i8
store i8 %64, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @mode2str.s, i64 0, i64 8)
%65 = load i32, i32* %2
%66 = load i32, i32* @S_IXOTH
%67 = and i32 %65, %66
%68 = icmp ne i32 %67, 0
%69 = zext i1 %68 to i64
%70 = select i1 %68, i32 120, i32 45
%71 = trunc i32 %70 to i8
store i8 %71, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @mode2str.s, i64 0, i64 9)
store i8 46, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @mode2str.s, i64 0, i64 10)
store i8 0, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @mode2str.s, i64 0, i64 11)
ret i8* getelementptr inbounds ([16 x i8], [16 x i8]* @mode2str.s, i64 0, i64 0)
}

LLVM IR (-O2):
@mode2str.s = internal global [16 x i8] zeroinitializer
@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 i8* @mode2str(i32 %0) {
%2 = tail call i64 @S_ISDIR(i32 %0)
%3 = icmp eq i64 %2, 0
%4 = select i1 %3, i8 45, i8 100
store i8 %4, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @mode2str.s, 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 ([16 x i8], [16 x i8]* @mode2str.s, 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 ([16 x i8], [16 x i8]* @mode2str.s, i64 0, i64 2)
%13 = load i32, i32* @S_IXUSR
%14 = and i32 %13, %0
%15 = icmp eq i32 %14, 0
%16 = select i1 %15, i8 45, i8 120
store i8 %16, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @mode2str.s, i64 0, i64 3)
%17 = load i32, i32* @S_IRGRP
%18 = and i32 %17, %0
%19 = icmp eq i32 %18, 0
%20 = select i1 %19, i8 45, i8 114
store i8 %20, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @mode2str.s, i64 0, i64 4)
%21 = load i32, i32* @S_IWGRP
%22 = and i32 %21, %0
%23 = icmp eq i32 %22, 0
%24 = select i1 %23, i8 45, i8 119
store i8 %24, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @mode2str.s, i64 0, i64 5)
%25 = load i32, i32* @S_IXGRP
%26 = and i32 %25, %0
%27 = icmp eq i32 %26, 0
%28 = select i1 %27, i8 45, i8 120
store i8 %28, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @mode2str.s, i64 0, i64 6)
%29 = load i32, i32* @S_IROTH
%30 = and i32 %29, %0
%31 = icmp eq i32 %30, 0
%32 = select i1 %31, i8 45, i8 114
store i8 %32, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @mode2str.s, i64 0, i64 7)
%33 = load i32, i32* @S_IWOTH
%34 = and i32 %33, %0
%35 = icmp eq i32 %34, 0
%36 = select i1 %35, i8 45, i8 119
store i8 %36, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @mode2str.s, i64 0, i64 8)
%37 = load i32, i32* @S_IXOTH
%38 = and i32 %37, %0
%39 = icmp eq i32 %38, 0
%40 = select i1 %39, i8 45, i8 120
store i8 %40, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @mode2str.s, i64 0, i64 9)
store i8 46, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @mode2str.s, i64 0, i64 10)
store i8 0, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @mode2str.s, i64 0, i64 11)
ret i8* getelementptr inbounds ([16 x i8], [16 x i8]* @mode2str.s, i64 0, i64 0)
}