#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_IWGRP;
int S_IWOTH;
int S_IWUSR;
int S_IXGRP;
int S_IXOTH;
int S_IXUSR;
int /*<<< orphan*/ assert(char const *);
int /*<<< orphan*/ sprintf(char *, char *);
scalar_t__ stat(char const *, struct stat *);
void file_mode(const char *fname, char *mode) {
  assert(fname);
  assert(mode);
  struct stat s;
  if (stat(fname, &s)) {
    *mode = '\0';
    return;
  }
  sprintf(mode, (s.st_mode & S_IRUSR) ? "r" : "-");
  sprintf(mode + 1, (s.st_mode & S_IWUSR) ? "w" : "-");
  sprintf(mode + 2, (s.st_mode & S_IXUSR) ? "x" : "-");
  sprintf(mode + 3, (s.st_mode & S_IRGRP) ? "r" : "-");
  sprintf(mode + 4, (s.st_mode & S_IWGRP) ? "w" : "-");
  sprintf(mode + 5, (s.st_mode & S_IXGRP) ? "x" : "-");
  sprintf(mode + 6, (s.st_mode & S_IROTH) ? "r" : "-");
  sprintf(mode + 7, (s.st_mode & S_IWOTH) ? "w" : "-");
  sprintf(mode + 8, (s.st_mode & S_IXOTH) ? "x" : "-");
}


x86 assembly (clang, -O0):
<file_mode>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <assert@plt>
mov    -0x10(%rbp),%rdi
call   1030 <assert@plt>
mov    -0x8(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   1040 <stat@plt>
cmp    $0x0,%rax
je     1175 <file_mode+0x45>
mov    -0x10(%rbp),%rax
movb   $0x0,(%rax)
jmp    130f <file_mode+0x1df>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%ecx
mov    0x2e25(%rip),%rax
and    (%rax),%ecx
lea    0xe76(%rip),%rsi
lea    0xe6d(%rip),%rax
cmp    $0x0,%ecx
cmovne %rax,%rsi
call   1050 <sprintf@plt>
mov    -0x10(%rbp),%rdi
add    $0x1,%rdi
mov    -0x18(%rbp),%ecx
mov    0x2e1f(%rip),%rax
and    (%rax),%ecx
lea    0xe48(%rip),%rsi
lea    0xe43(%rip),%rax
cmp    $0x0,%ecx
cmovne %rax,%rsi
call   1050 <sprintf@plt>
mov    -0x10(%rbp),%rdi
add    $0x2,%rdi
mov    -0x18(%rbp),%ecx
mov    0x2e01(%rip),%rax
and    (%rax),%ecx
lea    0xe1a(%rip),%rsi
lea    0xe17(%rip),%rax
cmp    $0x0,%ecx
cmovne %rax,%rsi
call   1050 <sprintf@plt>
mov    -0x10(%rbp),%rdi
add    $0x3,%rdi
mov    -0x18(%rbp),%ecx
mov    0x2dab(%rip),%rax
and    (%rax),%ecx
lea    0xdec(%rip),%rsi
lea    0xde3(%rip),%rax
cmp    $0x0,%ecx
cmovne %rax,%rsi
call   1050 <sprintf@plt>
mov    -0x10(%rbp),%rdi
add    $0x4,%rdi
mov    -0x18(%rbp),%ecx
mov    0x2d9d(%rip),%rax
and    (%rax),%ecx
lea    0xdbe(%rip),%rsi
lea    0xdb9(%rip),%rax
cmp    $0x0,%ecx
cmovne %rax,%rsi
call   1050 <sprintf@plt>
mov    -0x10(%rbp),%rdi
add    $0x5,%rdi
mov    -0x18(%rbp),%ecx
mov    0x2d5f(%rip),%rax
and    (%rax),%ecx
lea    0xd90(%rip),%rsi
lea    0xd8d(%rip),%rax
cmp    $0x0,%ecx
cmovne %rax,%rsi
call   1050 <sprintf@plt>
mov    -0x10(%rbp),%rdi
add    $0x6,%rdi
mov    -0x18(%rbp),%ecx
mov    0x2d19(%rip),%rax
and    (%rax),%ecx
lea    0xd62(%rip),%rsi
lea    0xd59(%rip),%rax
cmp    $0x0,%ecx
cmovne %rax,%rsi
call   1050 <sprintf@plt>
mov    -0x10(%rbp),%rdi
add    $0x7,%rdi
mov    -0x18(%rbp),%ecx
mov    0x2cd3(%rip),%rax
and    (%rax),%ecx
lea    0xd34(%rip),%rsi
lea    0xd2f(%rip),%rax
cmp    $0x0,%ecx
cmovne %rax,%rsi
call   1050 <sprintf@plt>
mov    -0x10(%rbp),%rdi
add    $0x8,%rdi
mov    -0x18(%rbp),%ecx
mov    0x2cf5(%rip),%rax
and    (%rax),%ecx
lea    0xd06(%rip),%rsi
lea    0xd03(%rip),%rax
cmp    $0x0,%ecx
cmovne %rax,%rsi
call   1050 <sprintf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<file_mode>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%r13
mov    %rdi,%rbx
call   1030 <assert@plt>
mov    %r13,%rdi
call   1030 <assert@plt>
lea    0x8(%rsp),%rsi
mov    %rbx,%rdi
call   1040 <stat@plt>
test   %rax,%rax
je     116c <file_mode+0x3c>
movb   $0x0,0x0(%r13)
jmp    128f <file_mode+0x15f>
mov    0x2e35(%rip),%rax
mov    (%rax),%eax
and    0x8(%rsp),%eax
lea    0xe82(%rip),%rbx
lea    0xe79(%rip),%r14
mov    %r14,%rsi
cmove  %rbx,%rsi
mov    %r13,%rdi
call   1050 <sprintf@plt>
mov    0x2e33(%rip),%rax
mov    (%rax),%eax
and    0x8(%rsp),%eax
lea    0x1(%r13),%rdi
lea    0xe56(%rip),%r15
mov    %r15,%rsi
cmove  %rbx,%rsi
call   1050 <sprintf@plt>
mov    0x2e1f(%rip),%rax
mov    (%rax),%eax
and    0x8(%rsp),%eax
lea    0x2(%r13),%rdi
lea    0xe34(%rip),%r12
mov    %r12,%rsi
cmove  %rbx,%rsi
call   1050 <sprintf@plt>
lea    0x3(%r13),%rdi
mov    0x2dcf(%rip),%rax
mov    (%rax),%eax
and    0x8(%rsp),%eax
mov    %r14,%rsi
cmove  %rbx,%rsi
call   1050 <sprintf@plt>
lea    0x4(%r13),%rdi
mov    0x2dd2(%rip),%rax
mov    (%rax),%eax
and    0x8(%rsp),%eax
mov    %r15,%rsi
cmove  %rbx,%rsi
call   1050 <sprintf@plt>
lea    0x5(%r13),%rdi
mov    0x2da5(%rip),%rax
mov    (%rax),%eax
and    0x8(%rsp),%eax
mov    %r12,%rsi
cmove  %rbx,%rsi
call   1050 <sprintf@plt>
lea    0x6(%r13),%rdi
mov    0x2d70(%rip),%rax
mov    (%rax),%eax
and    0x8(%rsp),%eax
cmove  %rbx,%r14
mov    %r14,%rsi
call   1050 <sprintf@plt>
lea    0x7(%r13),%rdi
mov    0x2d3b(%rip),%rax
mov    (%rax),%eax
and    0x8(%rsp),%eax
cmove  %rbx,%r15
mov    %r15,%rsi
call   1050 <sprintf@plt>
add    $0x8,%r13
mov    0x2d6e(%rip),%rax
mov    (%rax),%eax
and    0x8(%rsp),%eax
cmove  %rbx,%r12
mov    %r13,%rdi
mov    %r12,%rsi
call   1050 <sprintf@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.stat = type { i32 }
@S_IRUSR = global i32 0
@.str = [2 x i8] c"r\00"
@.str.1 = [2 x i8] c"-\00"
@S_IWUSR = global i32 0
@.str.2 = [2 x i8] c"w\00"
@S_IXUSR = global i32 0
@.str.3 = [2 x i8] c"x\00"
@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 void @file_mode(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca %struct.stat
store i8* %0, i8** %3
store i8* %1, i8** %4
%6 = load i8*, i8** %3
%7 = call i32 @assert(i8* %6)
%8 = load i8*, i8** %4
%9 = call i32 @assert(i8* %8)
%10 = load i8*, i8** %3
%11 = call i64 @stat(i8* %10, %struct.stat* %5)
%12 = icmp ne i64 %11, 0
br i1 %12, label %13, label %15
13: ; preds = %2
%14 = load i8*, i8** %4
store i8 0, i8* %14
br label %105
15: ; preds = %2
%16 = load i8*, i8** %4
%17 = getelementptr inbounds %struct.stat, %struct.stat* %5, i32 0, i32 0
%18 = load i32, i32* %17
%19 = load i32, i32* @S_IRUSR
%20 = and i32 %18, %19
%21 = icmp ne i32 %20, 0
%22 = zext i1 %21 to i64
%23 = select i1 %21, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0)
%24 = call i32 @sprintf(i8* %16, i8* %23)
%25 = load i8*, i8** %4
%26 = getelementptr inbounds i8, i8* %25, i64 1
%27 = getelementptr inbounds %struct.stat, %struct.stat* %5, i32 0, i32 0
%28 = load i32, i32* %27
%29 = load i32, i32* @S_IWUSR
%30 = and i32 %28, %29
%31 = icmp ne i32 %30, 0
%32 = zext i1 %31 to i64
%33 = select i1 %31, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0)
%34 = call i32 @sprintf(i8* %26, i8* %33)
%35 = load i8*, i8** %4
%36 = getelementptr inbounds i8, i8* %35, i64 2
%37 = getelementptr inbounds %struct.stat, %struct.stat* %5, i32 0, i32 0
%38 = load i32, i32* %37
%39 = load i32, i32* @S_IXUSR
%40 = and i32 %38, %39
%41 = icmp ne i32 %40, 0
%42 = zext i1 %41 to i64
%43 = select i1 %41, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0)
%44 = call i32 @sprintf(i8* %36, i8* %43)
%45 = load i8*, i8** %4
%46 = getelementptr inbounds i8, i8* %45, i64 3
%47 = getelementptr inbounds %struct.stat, %struct.stat* %5, i32 0, i32 0
%48 = load i32, i32* %47
%49 = load i32, i32* @S_IRGRP
%50 = and i32 %48, %49
%51 = icmp ne i32 %50, 0
%52 = zext i1 %51 to i64
%53 = select i1 %51, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0)
%54 = call i32 @sprintf(i8* %46, i8* %53)
%55 = load i8*, i8** %4
%56 = getelementptr inbounds i8, i8* %55, i64 4
%57 = getelementptr inbounds %struct.stat, %struct.stat* %5, i32 0, i32 0
%58 = load i32, i32* %57
%59 = load i32, i32* @S_IWGRP
%60 = and i32 %58, %59
%61 = icmp ne i32 %60, 0
%62 = zext i1 %61 to i64
%63 = select i1 %61, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0)
%64 = call i32 @sprintf(i8* %56, i8* %63)
%65 = load i8*, i8** %4
%66 = getelementptr inbounds i8, i8* %65, i64 5
%67 = getelementptr inbounds %struct.stat, %struct.stat* %5, i32 0, i32 0
%68 = load i32, i32* %67
%69 = load i32, i32* @S_IXGRP
%70 = and i32 %68, %69
%71 = icmp ne i32 %70, 0
%72 = zext i1 %71 to i64
%73 = select i1 %71, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0)
%74 = call i32 @sprintf(i8* %66, i8* %73)
%75 = load i8*, i8** %4
%76 = getelementptr inbounds i8, i8* %75, i64 6
%77 = getelementptr inbounds %struct.stat, %struct.stat* %5, i32 0, i32 0
%78 = load i32, i32* %77
%79 = load i32, i32* @S_IROTH
%80 = and i32 %78, %79
%81 = icmp ne i32 %80, 0
%82 = zext i1 %81 to i64
%83 = select i1 %81, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0)
%84 = call i32 @sprintf(i8* %76, i8* %83)
%85 = load i8*, i8** %4
%86 = getelementptr inbounds i8, i8* %85, i64 7
%87 = getelementptr inbounds %struct.stat, %struct.stat* %5, i32 0, i32 0
%88 = load i32, i32* %87
%89 = load i32, i32* @S_IWOTH
%90 = and i32 %88, %89
%91 = icmp ne i32 %90, 0
%92 = zext i1 %91 to i64
%93 = select i1 %91, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0)
%94 = call i32 @sprintf(i8* %86, i8* %93)
%95 = load i8*, i8** %4
%96 = getelementptr inbounds i8, i8* %95, i64 8
%97 = getelementptr inbounds %struct.stat, %struct.stat* %5, i32 0, i32 0
%98 = load i32, i32* %97
%99 = load i32, i32* @S_IXOTH
%100 = and i32 %98, %99
%101 = icmp ne i32 %100, 0
%102 = zext i1 %101 to i64
%103 = select i1 %101, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0)
%104 = call i32 @sprintf(i8* %96, i8* %103)
br label %105
105: ; preds = %15, %13
ret void
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@S_IRUSR = global i32 0
@.str = [2 x i8] c"r\00"
@.str.1 = [2 x i8] c"-\00"
@S_IWUSR = global i32 0
@.str.2 = [2 x i8] c"w\00"
@S_IXUSR = global i32 0
@.str.3 = [2 x i8] c"x\00"
@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 void @file_mode(i8* %0, i8* %1) {
%3 = alloca %struct.stat
%4 = tail call i32 @assert(i8* %0)
%5 = tail call i32 @assert(i8* %1)
%6 = bitcast %struct.stat* %3 to i8*
%7 = call i64 @stat(i8* %0, %struct.stat* %3)
%8 = icmp eq i64 %7, 0
br i1 %8, label %10, label %9
9: ; preds = %2
store i8 0, i8* %1
br label %74
10: ; preds = %2
%11 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 0
%12 = load i32, i32* %11
%13 = load i32, i32* @S_IRUSR
%14 = and i32 %13, %12
%15 = icmp eq i32 %14, 0
%16 = select i1 %15, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0)
%17 = call i32 @sprintf(i8* dereferenceable(1) %1, i8* dereferenceable(1) %16)
%18 = getelementptr inbounds i8, i8* %1, i64 1
%19 = load i32, i32* %11
%20 = load i32, i32* @S_IWUSR
%21 = and i32 %20, %19
%22 = icmp eq i32 %21, 0
%23 = select i1 %22, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0)
%24 = call i32 @sprintf(i8* %18, i8* dereferenceable(1) %23)
%25 = getelementptr inbounds i8, i8* %1, i64 2
%26 = load i32, i32* %11
%27 = load i32, i32* @S_IXUSR
%28 = and i32 %27, %26
%29 = icmp eq i32 %28, 0
%30 = select i1 %29, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0)
%31 = call i32 @sprintf(i8* %25, i8* dereferenceable(1) %30)
%32 = getelementptr inbounds i8, i8* %1, i64 3
%33 = load i32, i32* %11
%34 = load i32, i32* @S_IRGRP
%35 = and i32 %34, %33
%36 = icmp eq i32 %35, 0
%37 = select i1 %36, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0)
%38 = call i32 @sprintf(i8* %32, i8* dereferenceable(1) %37)
%39 = getelementptr inbounds i8, i8* %1, i64 4
%40 = load i32, i32* %11
%41 = load i32, i32* @S_IWGRP
%42 = and i32 %41, %40
%43 = icmp eq i32 %42, 0
%44 = select i1 %43, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0)
%45 = call i32 @sprintf(i8* %39, i8* dereferenceable(1) %44)
%46 = getelementptr inbounds i8, i8* %1, i64 5
%47 = load i32, i32* %11
%48 = load i32, i32* @S_IXGRP
%49 = and i32 %48, %47
%50 = icmp eq i32 %49, 0
%51 = select i1 %50, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0)
%52 = call i32 @sprintf(i8* %46, i8* dereferenceable(1) %51)
%53 = getelementptr inbounds i8, i8* %1, i64 6
%54 = load i32, i32* %11
%55 = load i32, i32* @S_IROTH
%56 = and i32 %55, %54
%57 = icmp eq i32 %56, 0
%58 = select i1 %57, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0)
%59 = call i32 @sprintf(i8* %53, i8* dereferenceable(1) %58)
%60 = getelementptr inbounds i8, i8* %1, i64 7
%61 = load i32, i32* %11
%62 = load i32, i32* @S_IWOTH
%63 = and i32 %62, %61
%64 = icmp eq i32 %63, 0
%65 = select i1 %64, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0)
%66 = call i32 @sprintf(i8* %60, i8* dereferenceable(1) %65)
%67 = getelementptr inbounds i8, i8* %1, i64 8
%68 = load i32, i32* %11
%69 = load i32, i32* @S_IXOTH
%70 = and i32 %69, %68
%71 = icmp eq i32 %70, 0
%72 = select i1 %71, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0)
%73 = call i32 @sprintf(i8* %67, i8* dereferenceable(1) %72)
br label %74
74: ; preds = %10, %9
ret void
}