void permission_characters(char *buffer, char mode) {
  if (mode & 4)
    buffer[0] = 'r';
  else
    buffer[0] = '-';
  if (mode & 2)
    buffer[1] = 'w';
  else
    buffer[1] = '-';
  if (mode & 1)
    buffer[2] = 'x';
  else
    buffer[2] = '-';
}


x86 assembly (clang, -O0):
<permission_characters>:
push   %rbp
mov    %rsp,%rbp
mov    %sil,%al
mov    %rdi,-0x8(%rbp)
mov    %al,-0x9(%rbp)
movsbl -0x9(%rbp),%eax
and    $0x4,%eax
cmp    $0x0,%eax
je     112a <permission_characters+0x2a>
mov    -0x8(%rbp),%rax
movb   $0x72,(%rax)
jmp    1131 <permission_characters+0x31>
mov    -0x8(%rbp),%rax
movb   $0x2d,(%rax)
movsbl -0x9(%rbp),%eax
and    $0x2,%eax
cmp    $0x0,%eax
je     114e <permission_characters+0x4e>
mov    -0x8(%rbp),%rax
movb   $0x77,0x1(%rax)
jmp    1156 <permission_characters+0x56>
mov    -0x8(%rbp),%rax
movb   $0x2d,0x1(%rax)
movsbl -0x9(%rbp),%eax
and    $0x1,%eax
cmp    $0x0,%eax
je     1173 <permission_characters+0x73>
mov    -0x8(%rbp),%rax
movb   $0x78,0x2(%rax)
jmp    117b <permission_characters+0x7b>
mov    -0x8(%rbp),%rax
movb   $0x2d,0x2(%rax)
pop    %rbp
ret

x86 assembly (clang, -O2):
<permission_characters>:
test   $0x4,%sil
mov    $0x2d,%eax
mov    $0x72,%ecx
cmove  %eax,%ecx
mov    %cl,(%rdi)
test   $0x2,%sil
mov    $0x77,%ecx
cmove  %eax,%ecx
mov    %cl,0x1(%rdi)
test   $0x1,%sil
mov    $0x78,%ecx
cmove  %eax,%ecx
mov    %cl,0x2(%rdi)
ret

LLVM IR (-O0):
define void @permission_characters(i8* %0, i8 signext %1) {
%3 = alloca i8*
%4 = alloca i8
store i8* %0, i8** %3
store i8 %1, i8* %4
%5 = load i8, i8* %4
%6 = sext i8 %5 to i32
%7 = and i32 %6, 4
%8 = icmp ne i32 %7, 0
br i1 %8, label %9, label %12
9: ; preds = %2
%10 = load i8*, i8** %3
%11 = getelementptr inbounds i8, i8* %10, i64 0
store i8 114, i8* %11
br label %15
12: ; preds = %2
%13 = load i8*, i8** %3
%14 = getelementptr inbounds i8, i8* %13, i64 0
store i8 45, i8* %14
br label %15
15: ; preds = %12, %9
%16 = load i8, i8* %4
%17 = sext i8 %16 to i32
%18 = and i32 %17, 2
%19 = icmp ne i32 %18, 0
br i1 %19, label %20, label %23
20: ; preds = %15
%21 = load i8*, i8** %3
%22 = getelementptr inbounds i8, i8* %21, i64 1
store i8 119, i8* %22
br label %26
23: ; preds = %15
%24 = load i8*, i8** %3
%25 = getelementptr inbounds i8, i8* %24, i64 1
store i8 45, i8* %25
br label %26
26: ; preds = %23, %20
%27 = load i8, i8* %4
%28 = sext i8 %27 to i32
%29 = and i32 %28, 1
%30 = icmp ne i32 %29, 0
br i1 %30, label %31, label %34
31: ; preds = %26
%32 = load i8*, i8** %3
%33 = getelementptr inbounds i8, i8* %32, i64 2
store i8 120, i8* %33
br label %37
34: ; preds = %26
%35 = load i8*, i8** %3
%36 = getelementptr inbounds i8, i8* %35, i64 2
store i8 45, i8* %36
br label %37
37: ; preds = %34, %31
ret void
}

LLVM IR (-O2):
define void @permission_characters(i8* nocapture writeonly %0, i8 signext %1) {
%3 = zext i8 %1 to i32
%4 = and i32 %3, 4
%5 = icmp eq i32 %4, 0
%6 = select i1 %5, i8 45, i8 114
store i8 %6, i8* %0
%7 = and i32 %3, 2
%8 = icmp eq i32 %7, 0
%9 = select i1 %8, i8 45, i8 119
%10 = getelementptr inbounds i8, i8* %0, i64 1
store i8 %9, i8* %10
%11 = and i32 %3, 1
%12 = icmp eq i32 %11, 0
%13 = select i1 %12, i8 45, i8 120
%14 = getelementptr inbounds i8, i8* %0, i64 2
store i8 %13, i8* %14
ret void
}