#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;
int S_ISGID;
int S_ISUID;
int S_IWGRP;
int S_IWOTH;
int S_IWUSR;
int S_IXGRP;
int S_IXOTH;
int S_IXUSR;
char getFileMode(int);
void getFileModeString(mode_t mode, char *buf) {
  buf[0] = getFileMode(mode);
  buf[1] = mode & S_IRUSR ? 'r' : '-';
  buf[2] = mode & S_IWUSR ? 'w' : '-';
  buf[3] = (mode & S_ISUID ? (mode & S_IXUSR ? 's' : 'S')
                           : (mode & S_IXUSR ? 'x' : '-'));
  buf[4] = mode & S_IRGRP ? 'r' : '-';
  buf[5] = mode & S_IWGRP ? 'w' : '-';
  buf[6] = (mode & S_ISGID ? (mode & S_IXGRP ? 's' : 'S')
                           : (mode & S_IXGRP ? 'x' : '-'));
  buf[7] = mode & S_IROTH ? 'r' : '-';
  buf[8] = mode & S_IWOTH ? 'w' : '-';
  buf[9] = (mode & S_IXOTH ? 'x' : '-');
  buf[10] = ' ';
  buf[11] = '\0';
}


x86 assembly (clang, -O0):
<getFileModeString>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x4(%rbp),%edi
call   1030 <getFileMode@plt>
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %cl,(%rax)
mov    -0x4(%rbp),%edx
mov    0x2e5f(%rip),%rax
and    (%rax),%edx
mov    $0x2d,%eax
mov    $0x72,%ecx
cmp    $0x0,%edx
cmovne %ecx,%eax
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %cl,0x1(%rax)
mov    -0x4(%rbp),%edx
mov    0x2e6a(%rip),%rax
and    (%rax),%edx
mov    $0x2d,%eax
mov    $0x77,%ecx
cmp    $0x0,%edx
cmovne %ecx,%eax
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %cl,0x2(%rax)
mov    -0x4(%rbp),%eax
mov    0x2e55(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     11b2 <getFileModeString+0xa2>
mov    -0x4(%rbp),%edx
mov    0x2e48(%rip),%rax
and    (%rax),%edx
mov    $0x53,%eax
mov    $0x73,%ecx
cmp    $0x0,%edx
cmovne %ecx,%eax
mov    %eax,-0x14(%rbp)
jmp    11d1 <getFileModeString+0xc1>
mov    -0x4(%rbp),%edx
mov    0x2e24(%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,%cl
mov    -0x10(%rbp),%rax
mov    %cl,0x3(%rax)
mov    -0x4(%rbp),%edx
mov    0x2dc1(%rip),%rax
and    (%rax),%edx
mov    $0x2d,%eax
mov    $0x72,%ecx
cmp    $0x0,%edx
cmovne %ecx,%eax
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %cl,0x4(%rax)
mov    -0x4(%rbp),%edx
mov    0x2dc4(%rip),%rax
and    (%rax),%edx
mov    $0x2d,%eax
mov    $0x77,%ecx
cmp    $0x0,%edx
cmovne %ecx,%eax
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %cl,0x5(%rax)
mov    -0x4(%rbp),%eax
mov    0x2d7f(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     1260 <getFileModeString+0x150>
mov    -0x4(%rbp),%edx
mov    0x2d7a(%rip),%rax
and    (%rax),%edx
mov    $0x53,%eax
mov    $0x73,%ecx
cmp    $0x0,%edx
cmovne %ecx,%eax
mov    %eax,-0x18(%rbp)
jmp    127f <getFileModeString+0x16f>
mov    -0x4(%rbp),%edx
mov    0x2d56(%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,%cl
mov    -0x10(%rbp),%rax
mov    %cl,0x6(%rax)
mov    -0x4(%rbp),%edx
mov    0x2d0b(%rip),%rax
and    (%rax),%edx
mov    $0x2d,%eax
mov    $0x72,%ecx
cmp    $0x0,%edx
cmovne %ecx,%eax
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %cl,0x7(%rax)
mov    -0x4(%rbp),%edx
mov    0x2cce(%rip),%rax
and    (%rax),%edx
mov    $0x2d,%eax
mov    $0x77,%ecx
cmp    $0x0,%edx
cmovne %ecx,%eax
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %cl,0x8(%rax)
mov    -0x4(%rbp),%edx
mov    0x2d09(%rip),%rax
and    (%rax),%edx
mov    $0x2d,%eax
mov    $0x78,%ecx
cmp    $0x0,%edx
cmovne %ecx,%eax
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %cl,0x9(%rax)
mov    -0x10(%rbp),%rax
movb   $0x20,0xa(%rax)
mov    -0x10(%rbp),%rax
movb   $0x0,0xb(%rax)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getFileModeString>:
push   %rbp
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %edi,%ebp
call   1030 <getFileMode@plt>
mov    %al,(%rbx)
mov    0x2e72(%rip),%rax
mov    (%rax),%eax
and    %ebp,%eax
mov    $0x2d,%eax
mov    $0x72,%r8d
mov    $0x72,%edx
cmove  %eax,%edx
mov    %dl,0x1(%rbx)
mov    0x2e81(%rip),%rdx
mov    (%rdx),%edx
and    %ebp,%edx
mov    $0x77,%r9d
mov    $0x77,%esi
cmove  %eax,%esi
mov    %sil,0x2(%rbx)
mov    0x2e74(%rip),%rsi
mov    (%rsi),%esi
and    %ebp,%esi
mov    0x2e71(%rip),%rdi
mov    (%rdi),%edi
and    %ebp,%edi
setne  %cl
mov    $0x78,%edi
cmove  %eax,%edi
shl    $0x5,%cl
or     $0x53,%cl
test   %esi,%esi
movzbl %cl,%ecx
cmove  %edi,%ecx
mov    $0x78,%esi
mov    %cl,0x3(%rbx)
mov    0x2e0d(%rip),%rcx
mov    (%rcx),%ecx
and    %ebp,%ecx
mov    $0x72,%ecx
cmove  %eax,%ecx
mov    %cl,0x4(%rbx)
mov    0x2e1f(%rip),%rcx
mov    (%rcx),%ecx
and    %ebp,%ecx
mov    $0x77,%ecx
cmove  %eax,%ecx
mov    %cl,0x5(%rbx)
mov    0x2de9(%rip),%rcx
mov    (%rcx),%ecx
and    %ebp,%ecx
mov    0x2dee(%rip),%rdi
mov    (%rdi),%edi
and    %ebp,%edi
setne  %dl
mov    $0x78,%edi
cmove  %eax,%edi
shl    $0x5,%dl
or     $0x53,%dl
test   %ecx,%ecx
movzbl %dl,%ecx
cmove  %edi,%ecx
mov    %cl,0x6(%rbx)
mov    0x2da7(%rip),%rcx
mov    (%rcx),%ecx
and    %ebp,%ecx
cmove  %eax,%r8d
mov    %r8b,0x7(%rbx)
mov    0x2d7c(%rip),%rcx
mov    (%rcx),%ecx
and    %ebp,%ecx
cmove  %eax,%r9d
mov    %r9b,0x8(%rbx)
mov    0x2dc9(%rip),%rcx
and    (%rcx),%ebp
cmove  %eax,%esi
mov    %sil,0x9(%rbx)
movw   $0x20,0xa(%rbx)
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@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_IXOTH = global i32 0
define void @getFileModeString(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
store i32 %0, i32* %3
store i8* %1, i8** %4
%5 = load i32, i32* %3
%6 = call signext i8 @getFileMode(i32 %5)
%7 = load i8*, i8** %4
%8 = getelementptr inbounds i8, i8* %7, i64 0
store i8 %6, i8* %8
%9 = load i32, i32* %3
%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
%16 = load i8*, i8** %4
%17 = getelementptr inbounds i8, i8* %16, i64 1
store i8 %15, i8* %17
%18 = load i32, i32* %3
%19 = load i32, i32* @S_IWUSR
%20 = and i32 %18, %19
%21 = icmp ne i32 %20, 0
%22 = zext i1 %21 to i64
%23 = select i1 %21, i32 119, i32 45
%24 = trunc i32 %23 to i8
%25 = load i8*, i8** %4
%26 = getelementptr inbounds i8, i8* %25, i64 2
store i8 %24, i8* %26
%27 = load i32, i32* %3
%28 = load i32, i32* @S_ISUID
%29 = and i32 %27, %28
%30 = icmp ne i32 %29, 0
br i1 %30, label %31, label %38
31: ; preds = %2
%32 = load i32, i32* %3
%33 = load i32, i32* @S_IXUSR
%34 = and i32 %32, %33
%35 = icmp ne i32 %34, 0
%36 = zext i1 %35 to i64
%37 = select i1 %35, i32 115, i32 83
br label %45
38: ; preds = %2
%39 = load i32, i32* %3
%40 = load i32, i32* @S_IXUSR
%41 = and i32 %39, %40
%42 = icmp ne i32 %41, 0
%43 = zext i1 %42 to i64
%44 = select i1 %42, i32 120, i32 45
br label %45
45: ; preds = %38, %31
%46 = phi i32 [ %37, %31 ], [ %44, %38 ]
%47 = trunc i32 %46 to i8
%48 = load i8*, i8** %4
%49 = getelementptr inbounds i8, i8* %48, i64 3
store i8 %47, i8* %49
%50 = load i32, i32* %3
%51 = load i32, i32* @S_IRGRP
%52 = and i32 %50, %51
%53 = icmp ne i32 %52, 0
%54 = zext i1 %53 to i64
%55 = select i1 %53, i32 114, i32 45
%56 = trunc i32 %55 to i8
%57 = load i8*, i8** %4
%58 = getelementptr inbounds i8, i8* %57, i64 4
store i8 %56, i8* %58
%59 = load i32, i32* %3
%60 = load i32, i32* @S_IWGRP
%61 = and i32 %59, %60
%62 = icmp ne i32 %61, 0
%63 = zext i1 %62 to i64
%64 = select i1 %62, i32 119, i32 45
%65 = trunc i32 %64 to i8
%66 = load i8*, i8** %4
%67 = getelementptr inbounds i8, i8* %66, i64 5
store i8 %65, i8* %67
%68 = load i32, i32* %3
%69 = load i32, i32* @S_ISGID
%70 = and i32 %68, %69
%71 = icmp ne i32 %70, 0
br i1 %71, label %72, label %79
72: ; preds = %45
%73 = load i32, i32* %3
%74 = load i32, i32* @S_IXGRP
%75 = and i32 %73, %74
%76 = icmp ne i32 %75, 0
%77 = zext i1 %76 to i64
%78 = select i1 %76, i32 115, i32 83
br label %86
79: ; preds = %45
%80 = load i32, i32* %3
%81 = load i32, i32* @S_IXGRP
%82 = and i32 %80, %81
%83 = icmp ne i32 %82, 0
%84 = zext i1 %83 to i64
%85 = select i1 %83, i32 120, i32 45
br label %86
86: ; preds = %79, %72
%87 = phi i32 [ %78, %72 ], [ %85, %79 ]
%88 = trunc i32 %87 to i8
%89 = load i8*, i8** %4
%90 = getelementptr inbounds i8, i8* %89, i64 6
store i8 %88, i8* %90
%91 = load i32, i32* %3
%92 = load i32, i32* @S_IROTH
%93 = and i32 %91, %92
%94 = icmp ne i32 %93, 0
%95 = zext i1 %94 to i64
%96 = select i1 %94, i32 114, i32 45
%97 = trunc i32 %96 to i8
%98 = load i8*, i8** %4
%99 = getelementptr inbounds i8, i8* %98, i64 7
store i8 %97, i8* %99
%100 = load i32, i32* %3
%101 = load i32, i32* @S_IWOTH
%102 = and i32 %100, %101
%103 = icmp ne i32 %102, 0
%104 = zext i1 %103 to i64
%105 = select i1 %103, i32 119, i32 45
%106 = trunc i32 %105 to i8
%107 = load i8*, i8** %4
%108 = getelementptr inbounds i8, i8* %107, i64 8
store i8 %106, i8* %108
%109 = load i32, i32* %3
%110 = load i32, i32* @S_IXOTH
%111 = and i32 %109, %110
%112 = icmp ne i32 %111, 0
%113 = zext i1 %112 to i64
%114 = select i1 %112, i32 120, i32 45
%115 = trunc i32 %114 to i8
%116 = load i8*, i8** %4
%117 = getelementptr inbounds i8, i8* %116, i64 9
store i8 %115, i8* %117
%118 = load i8*, i8** %4
%119 = getelementptr inbounds i8, i8* %118, i64 10
store i8 32, i8* %119
%120 = load i8*, i8** %4
%121 = getelementptr inbounds i8, i8* %120, i64 11
store i8 0, i8* %121
ret void
}

LLVM IR (-O2):
@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_IXOTH = global i32 0
define void @getFileModeString(i32 %0, i8* nocapture writeonly %1) {
%3 = tail call signext i8 @getFileMode(i32 %0)
store i8 %3, i8* %1
%4 = load i32, i32* @S_IRUSR
%5 = and i32 %4, %0
%6 = icmp eq i32 %5, 0
%7 = select i1 %6, i8 45, i8 114
%8 = getelementptr inbounds i8, i8* %1, i64 1
store i8 %7, i8* %8
%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
%13 = getelementptr inbounds i8, i8* %1, i64 2
store i8 %12, i8* %13
%14 = load i32, i32* @S_ISUID
%15 = and i32 %14, %0
%16 = icmp eq i32 %15, 0
%17 = load i32, i32* @S_IXUSR
%18 = and i32 %17, %0
%19 = icmp eq i32 %18, 0
%20 = select i1 %19, i8 83, i8 115
%21 = select i1 %19, i8 45, i8 120
%22 = select i1 %16, i8 %21, i8 %20
%23 = getelementptr inbounds i8, i8* %1, i64 3
store i8 %22, i8* %23
%24 = load i32, i32* @S_IRGRP
%25 = and i32 %24, %0
%26 = icmp eq i32 %25, 0
%27 = select i1 %26, i8 45, i8 114
%28 = getelementptr inbounds i8, i8* %1, i64 4
store i8 %27, i8* %28
%29 = load i32, i32* @S_IWGRP
%30 = and i32 %29, %0
%31 = icmp eq i32 %30, 0
%32 = select i1 %31, i8 45, i8 119
%33 = getelementptr inbounds i8, i8* %1, i64 5
store i8 %32, i8* %33
%34 = load i32, i32* @S_ISGID
%35 = and i32 %34, %0
%36 = icmp eq i32 %35, 0
%37 = load i32, i32* @S_IXGRP
%38 = and i32 %37, %0
%39 = icmp eq i32 %38, 0
%40 = select i1 %39, i8 83, i8 115
%41 = select i1 %39, i8 45, i8 120
%42 = select i1 %36, i8 %41, i8 %40
%43 = getelementptr inbounds i8, i8* %1, i64 6
store i8 %42, i8* %43
%44 = load i32, i32* @S_IROTH
%45 = and i32 %44, %0
%46 = icmp eq i32 %45, 0
%47 = select i1 %46, i8 45, i8 114
%48 = getelementptr inbounds i8, i8* %1, i64 7
store i8 %47, i8* %48
%49 = load i32, i32* @S_IWOTH
%50 = and i32 %49, %0
%51 = icmp eq i32 %50, 0
%52 = select i1 %51, i8 45, i8 119
%53 = getelementptr inbounds i8, i8* %1, i64 8
store i8 %52, i8* %53
%54 = load i32, i32* @S_IXOTH
%55 = and i32 %54, %0
%56 = icmp eq i32 %55, 0
%57 = select i1 %56, i8 45, i8 120
%58 = getelementptr inbounds i8, i8* %1, i64 9
store i8 %57, i8* %58
%59 = getelementptr inbounds i8, i8* %1, i64 10
store i8 32, i8* %59
%60 = getelementptr inbounds i8, i8* %1, i64 11
store i8 0, i8* %60
ret void
}