#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 134
#define S_IFCHR 133
#define S_IFDIR 132
#define S_IFIFO 131
#define S_IFLNK 130
int S_IFMT;
#define S_IFREG 129
#define S_IFSOCK 128
int /*<<< orphan*/ sprintf(char *, char *, char const *, char const *,
                           char const *);
void strmode(mode_t mode, char *dest) {
  static const char *rwx[] = {"---", "--x", "-w-", "-wx",
                              "r--", "r-x", "rw-", "rwx"};
  switch (mode & S_IFMT) {
  case S_IFIFO:
    dest[0] = 'p';
    break;
  case S_IFCHR:
    dest[0] = 'c';
    break;
  case S_IFDIR:
    dest[0] = 'd';
    break;
  case S_IFBLK:
    dest[0] = 'b';
    break;
  case S_IFREG:
    dest[0] = '-';
    break;
  case S_IFLNK:
    dest[0] = 'l';
    break;
  case S_IFSOCK:
    dest[0] = '=';
    break;
  default:
    dest[0] = '?';
    break;
  }
  sprintf(dest + 1, "%s%s%s", rwx[(mode >> 6) & 0x7], rwx[(mode >> 3) & 0x7],
          rwx[mode & 0x7]);
}


x86 assembly (clang, -O0):
<strmode>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x4(%rbp),%eax
mov    0x2eb7(%rip),%rcx
mov    (%rcx),%ecx
and    %ecx,%eax
add    $0xffffff80,%eax
mov    %eax,%ecx
mov    %rcx,-0x18(%rbp)
sub    $0x6,%eax
ja     11a7 <strmode+0x97>
mov    -0x18(%rbp),%rax
lea    0xeb6(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x10(%rbp),%rax
movb   $0x70,(%rax)
jmp    11ae <strmode+0x9e>
mov    -0x10(%rbp),%rax
movb   $0x63,(%rax)
jmp    11ae <strmode+0x9e>
mov    -0x10(%rbp),%rax
movb   $0x64,(%rax)
jmp    11ae <strmode+0x9e>
mov    -0x10(%rbp),%rax
movb   $0x62,(%rax)
jmp    11ae <strmode+0x9e>
mov    -0x10(%rbp),%rax
movb   $0x2d,(%rax)
jmp    11ae <strmode+0x9e>
mov    -0x10(%rbp),%rax
movb   $0x6c,(%rax)
jmp    11ae <strmode+0x9e>
mov    -0x10(%rbp),%rax
movb   $0x3d,(%rax)
jmp    11ae <strmode+0x9e>
mov    -0x10(%rbp),%rax
movb   $0x3f,(%rax)
mov    -0x10(%rbp),%rdi
add    $0x1,%rdi
mov    -0x4(%rbp),%eax
sar    $0x6,%eax
and    $0x7,%eax
movslq %eax,%rcx
lea    0x2e67(%rip),%rax
mov    (%rax,%rcx,8),%rdx
mov    -0x4(%rbp),%eax
sar    $0x3,%eax
and    $0x7,%eax
movslq %eax,%rcx
lea    0x2e50(%rip),%rax
mov    (%rax,%rcx,8),%rcx
mov    -0x4(%rbp),%eax
and    $0x7,%eax
movslq %eax,%rsi
lea    0x2e3c(%rip),%rax
mov    (%rax,%rsi,8),%r8
lea    0xe3d(%rip),%rsi
call   1030 <sprintf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strmode>:
mov    0x2ec1(%rip),%rax
mov    (%rax),%eax
and    %edi,%eax
lea    -0x400(,%rax,8),%ecx
add    $0xffffff80,%eax
movabs $0x626364706c2d3d,%rdx
shr    %cl,%rdx
cmp    $0x7,%eax
mov    $0x3f,%eax
cmovb  %edx,%eax
mov    %al,(%rsi)
lea    0x1(%rsi),%rax
mov    %edi,%ecx
shr    $0x6,%ecx
and    $0x7,%ecx
lea    0x2c7e(%rip),%rsi
mov    (%rsi,%rcx,8),%rdx
mov    %edi,%ecx
shr    $0x3,%ecx
and    $0x7,%ecx
mov    (%rsi,%rcx,8),%rcx
and    $0x7,%edi
mov    (%rsi,%rdi,8),%r8
lea    0xeb0(%rip),%rsi
mov    %rax,%rdi
jmp    1030 <sprintf@plt>

LLVM IR (-O0):
@strmode.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
@.str.8 = [7 x i8] c"%s%s%s\00"
define void @strmode(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 = load i32, i32* @S_IFMT
%7 = and i32 %5, %6
switch i32 %7, label %29 [
i32 131, label %8
i32 133, label %11
i32 132, label %14
i32 134, label %17
i32 129, label %20
i32 130, label %23
i32 128, label %26
]
8: ; preds = %2
%9 = load i8*, i8** %4
%10 = getelementptr inbounds i8, i8* %9, i64 0
store i8 112, i8* %10
br label %32
11: ; preds = %2
%12 = load i8*, i8** %4
%13 = getelementptr inbounds i8, i8* %12, i64 0
store i8 99, i8* %13
br label %32
14: ; preds = %2
%15 = load i8*, i8** %4
%16 = getelementptr inbounds i8, i8* %15, i64 0
store i8 100, i8* %16
br label %32
17: ; preds = %2
%18 = load i8*, i8** %4
%19 = getelementptr inbounds i8, i8* %18, i64 0
store i8 98, i8* %19
br label %32
20: ; preds = %2
%21 = load i8*, i8** %4
%22 = getelementptr inbounds i8, i8* %21, i64 0
store i8 45, i8* %22
br label %32
23: ; preds = %2
%24 = load i8*, i8** %4
%25 = getelementptr inbounds i8, i8* %24, i64 0
store i8 108, i8* %25
br label %32
26: ; preds = %2
%27 = load i8*, i8** %4
%28 = getelementptr inbounds i8, i8* %27, i64 0
store i8 61, i8* %28
br label %32
29: ; preds = %2
%30 = load i8*, i8** %4
%31 = getelementptr inbounds i8, i8* %30, i64 0
store i8 63, i8* %31
br label %32
32: ; preds = %29, %26, %23, %20, %17, %14, %11, %8
%33 = load i8*, i8** %4
%34 = getelementptr inbounds i8, i8* %33, i64 1
%35 = load i32, i32* %3
%36 = ashr i32 %35, 6
%37 = and i32 %36, 7
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds [8 x i8*], [8 x i8*]* @strmode.rwx, i64 0, i64 %38
%40 = load i8*, i8** %39
%41 = load i32, i32* %3
%42 = ashr i32 %41, 3
%43 = and i32 %42, 7
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds [8 x i8*], [8 x i8*]* @strmode.rwx, i64 0, i64 %44
%46 = load i8*, i8** %45
%47 = load i32, i32* %3
%48 = and i32 %47, 7
%49 = sext i32 %48 to i64
%50 = getelementptr inbounds [8 x i8*], [8 x i8*]* @strmode.rwx, i64 0, i64 %49
%51 = load i8*, i8** %50
%52 = call i32 @sprintf(i8* %34, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.8, i64 0, i64 0), i8* %40, i8* %46, i8* %51)
ret void
}

LLVM IR (-O2):
@strmode.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
@.str.8 = [7 x i8] c"%s%s%s\00"
define void @strmode(i32 %0, i8* nocapture writeonly %1) {
%3 = load i32, i32* @S_IFMT
%4 = and i32 %3, %0
%5 = add i32 %4, -128
%6 = icmp ult i32 %5, 7
%7 = zext i32 %5 to i56
%8 = shl nuw nsw i56 %7, 3
%9 = lshr i56 27693830751661373, %8
%10 = trunc i56 %9 to i8
%11 = select i1 %6, i8 %10, i8 63
store i8 %11, i8* %1
%12 = getelementptr inbounds i8, i8* %1, i64 1
%13 = lshr i32 %0, 6
%14 = and i32 %13, 7
%15 = zext i32 %14 to i64
%16 = getelementptr inbounds [8 x i8*], [8 x i8*]* @strmode.rwx, i64 0, i64 %15
%17 = load i8*, i8** %16
%18 = lshr i32 %0, 3
%19 = and i32 %18, 7
%20 = zext i32 %19 to i64
%21 = getelementptr inbounds [8 x i8*], [8 x i8*]* @strmode.rwx, i64 0, i64 %20
%22 = load i8*, i8** %21
%23 = and i32 %0, 7
%24 = zext i32 %23 to i64
%25 = getelementptr inbounds [8 x i8*], [8 x i8*]* @strmode.rwx, i64 0, i64 %24
%26 = load i8*, i8** %25
%27 = tail call i32 @sprintf(i8* %12, i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.8, i64 0, i64 0), i8* %17, i8* %22, i8* %26)
ret void
}