void format_rights(int mode, char *str) {
  char c;
  switch (mode & 0170000) {
  case 0010000:
    c = 'f';
    break;
  case 0020000:
    c = 'c';
    break;
  case 0040000:
    c = 'd';
    break;
  case 0060000:
    c = 'b';
    break;
  case 0100000:
    c = '-';
    break;
  case 0120000:
    c = 'l';
    break;
  case 0140000:
    c = 's';
    break;
  };
  str[0] = c;
  str[1] = (mode & 0000400) ? 'r' : '-';
  str[2] = (mode & 0000200) ? 'w' : '-';
  str[3] = (mode & 0000100) ? 'x' : '-';
  str[4] = (mode & 0000040) ? 'r' : '-';
  str[5] = (mode & 0000020) ? 'w' : '-';
  str[6] = (mode & 0000010) ? 'x' : '-';
  str[7] = (mode & 0000004) ? 'r' : '-';
  str[8] = (mode & 0000002) ? 'w' : '-';
  str[9] = (mode & 0000001) ? 'x' : '-';
  str[10] = 0;
  if (mode & 04000)
    str[3] = (mode & 0100) ? 's' : 'S';
  if (mode & 02000)
    str[6] = (mode & 0010) ? 's' : 'S';
  if (mode & 01000)
    str[9] = (mode & 0001) ? 't' : 'T';
  return;
}


x86 assembly (clang, -O0):
<format_rights>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x4(%rbp),%eax
and    $0xf000,%eax
mov    %eax,-0x18(%rbp)
sub    $0x1000,%eax
je     1198 <format_rights+0x98>
jmp    1126 <format_rights+0x26>
mov    -0x18(%rbp),%eax
sub    $0x2000,%eax
je     11a1 <format_rights+0xa1>
jmp    1139 <format_rights+0x39>
mov    -0x18(%rbp),%eax
sub    $0x4000,%eax
je     11aa <format_rights+0xaa>
jmp    114c <format_rights+0x4c>
mov    -0x18(%rbp),%eax
sub    $0x6000,%eax
je     11b3 <format_rights+0xb3>
jmp    115f <format_rights+0x5f>
mov    -0x18(%rbp),%eax
sub    $0x8000,%eax
je     11bc <format_rights+0xbc>
jmp    1172 <format_rights+0x72>
mov    -0x18(%rbp),%eax
sub    $0xa000,%eax
je     11c5 <format_rights+0xc5>
jmp    1185 <format_rights+0x85>
mov    -0x18(%rbp),%eax
sub    $0xc000,%eax
je     11ce <format_rights+0xce>
jmp    11d2 <format_rights+0xd2>
movb   $0x66,-0x11(%rbp)
jmp    11d2 <format_rights+0xd2>
movb   $0x63,-0x11(%rbp)
jmp    11d2 <format_rights+0xd2>
movb   $0x64,-0x11(%rbp)
jmp    11d2 <format_rights+0xd2>
movb   $0x62,-0x11(%rbp)
jmp    11d2 <format_rights+0xd2>
movb   $0x2d,-0x11(%rbp)
jmp    11d2 <format_rights+0xd2>
movb   $0x6c,-0x11(%rbp)
jmp    11d2 <format_rights+0xd2>
movb   $0x73,-0x11(%rbp)
mov    -0x11(%rbp),%cl
mov    -0x10(%rbp),%rax
mov    %cl,(%rax)
mov    -0x4(%rbp),%edx
and    $0x100,%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
and    $0x80,%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),%edx
and    $0x40,%edx
mov    $0x2d,%eax
mov    $0x78,%ecx
cmp    $0x0,%edx
cmovne %ecx,%eax
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %cl,0x3(%rax)
mov    -0x4(%rbp),%edx
and    $0x20,%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
and    $0x10,%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),%edx
and    $0x8,%edx
mov    $0x2d,%eax
mov    $0x78,%ecx
cmp    $0x0,%edx
cmovne %ecx,%eax
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %cl,0x6(%rax)
mov    -0x4(%rbp),%edx
and    $0x4,%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
and    $0x2,%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
and    $0x1,%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   $0x0,0xa(%rax)
mov    -0x4(%rbp),%eax
and    $0x800,%eax
cmp    $0x0,%eax
je     1330 <format_rights+0x230>
mov    -0x4(%rbp),%edx
and    $0x40,%edx
mov    $0x53,%eax
mov    $0x73,%ecx
cmp    $0x0,%edx
cmovne %ecx,%eax
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %cl,0x3(%rax)
mov    -0x4(%rbp),%eax
and    $0x400,%eax
cmp    $0x0,%eax
je     1360 <format_rights+0x260>
mov    -0x4(%rbp),%edx
and    $0x8,%edx
mov    $0x53,%eax
mov    $0x73,%ecx
cmp    $0x0,%edx
cmovne %ecx,%eax
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %cl,0x6(%rax)
mov    -0x4(%rbp),%eax
and    $0x200,%eax
cmp    $0x0,%eax
je     1390 <format_rights+0x290>
mov    -0x4(%rbp),%edx
and    $0x1,%edx
mov    $0x54,%eax
mov    $0x74,%ecx
cmp    $0x0,%edx
cmovne %ecx,%eax
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %cl,0x9(%rax)
pop    %rbp
ret

x86 assembly (clang, -O2):
<format_rights>:
mov    %edi,%eax
and    $0xf000,%eax
add    $0xfffff000,%eax
shr    $0xc,%eax
add    $0xffffffffffffffff,%rax
mov    $0x66,%cl
cmp    $0xa,%eax
ja     1124 <format_rights+0x24>
lea    0xedf(%rip),%rcx
mov    (%rax,%rcx,1),%cl
mov    %cl,(%rsi)
test   $0x100,%edi
mov    $0x2d,%eax
mov    $0x72,%r8d
mov    $0x72,%edx
cmove  %eax,%edx
mov    %dl,0x1(%rsi)
test   $0x80,%dil
mov    $0x77,%r9d
mov    $0x77,%ecx
cmove  %eax,%ecx
test   $0x40,%dil
mov    $0x78,%edx
cmove  %eax,%edx
mov    %cl,0x2(%rsi)
mov    %dl,0x3(%rsi)
test   $0x20,%dil
mov    $0x72,%ecx
cmove  %eax,%ecx
mov    %cl,0x4(%rsi)
test   $0x10,%dil
mov    $0x77,%ecx
cmove  %eax,%ecx
mov    %cl,0x5(%rsi)
test   $0x8,%dil
mov    $0x78,%ecx
cmove  %eax,%ecx
mov    $0x78,%edx
test   $0x4,%dil
cmove  %eax,%r8d
mov    %cl,0x6(%rsi)
test   $0x2,%dil
cmove  %eax,%r9d
mov    %r8b,0x7(%rsi)
test   $0x1,%dil
cmove  %eax,%edx
mov    %r9b,0x8(%rsi)
mov    %dl,0x9(%rsi)
movb   $0x0,0xa(%rsi)
test   $0x800,%edi
jne    11d7 <format_rights+0xd7>
test   $0x400,%edi
jne    11ee <format_rights+0xee>
test   $0x200,%edi
jne    1202 <format_rights+0x102>
ret
movzbl %dil,%eax
shr    $0x6,%eax
shl    $0x5,%al
or     $0x53,%al
mov    %al,0x3(%rsi)
test   $0x400,%edi
je     11ce <format_rights+0xce>
mov    %edi,%eax
and    $0x8,%al
shl    $0x2,%al
or     $0x53,%al
mov    %al,0x6(%rsi)
test   $0x200,%edi
je     11d6 <format_rights+0xd6>
and    $0x1,%dil
shl    $0x5,%dil
or     $0x54,%dil
mov    %dil,0x9(%rsi)
ret

LLVM IR (-O0):
define void @format_rights(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8
store i32 %0, i32* %3
store i8* %1, i8** %4
%6 = load i32, i32* %3
%7 = and i32 %6, 61440
switch i32 %7, label %15 [
i32 4096, label %8
i32 8192, label %9
i32 16384, label %10
i32 24576, label %11
i32 32768, label %12
i32 40960, label %13
i32 49152, label %14
]
8: ; preds = %2
store i8 102, i8* %5
br label %15
9: ; preds = %2
store i8 99, i8* %5
br label %15
10: ; preds = %2
store i8 100, i8* %5
br label %15
11: ; preds = %2
store i8 98, i8* %5
br label %15
12: ; preds = %2
store i8 45, i8* %5
br label %15
13: ; preds = %2
store i8 108, i8* %5
br label %15
14: ; preds = %2
store i8 115, i8* %5
br label %15
15: ; preds = %2, %14, %13, %12, %11, %10, %9, %8
%16 = load i8, i8* %5
%17 = load i8*, i8** %4
%18 = getelementptr inbounds i8, i8* %17, i64 0
store i8 %16, i8* %18
%19 = load i32, i32* %3
%20 = and i32 %19, 256
%21 = icmp ne i32 %20, 0
%22 = zext i1 %21 to i64
%23 = select i1 %21, i32 114, i32 45
%24 = trunc i32 %23 to i8
%25 = load i8*, i8** %4
%26 = getelementptr inbounds i8, i8* %25, i64 1
store i8 %24, i8* %26
%27 = load i32, i32* %3
%28 = and i32 %27, 128
%29 = icmp ne i32 %28, 0
%30 = zext i1 %29 to i64
%31 = select i1 %29, i32 119, i32 45
%32 = trunc i32 %31 to i8
%33 = load i8*, i8** %4
%34 = getelementptr inbounds i8, i8* %33, i64 2
store i8 %32, i8* %34
%35 = load i32, i32* %3
%36 = and i32 %35, 64
%37 = icmp ne i32 %36, 0
%38 = zext i1 %37 to i64
%39 = select i1 %37, i32 120, i32 45
%40 = trunc i32 %39 to i8
%41 = load i8*, i8** %4
%42 = getelementptr inbounds i8, i8* %41, i64 3
store i8 %40, i8* %42
%43 = load i32, i32* %3
%44 = and i32 %43, 32
%45 = icmp ne i32 %44, 0
%46 = zext i1 %45 to i64
%47 = select i1 %45, i32 114, i32 45
%48 = trunc i32 %47 to i8
%49 = load i8*, i8** %4
%50 = getelementptr inbounds i8, i8* %49, i64 4
store i8 %48, i8* %50
%51 = load i32, i32* %3
%52 = and i32 %51, 16
%53 = icmp ne i32 %52, 0
%54 = zext i1 %53 to i64
%55 = select i1 %53, i32 119, i32 45
%56 = trunc i32 %55 to i8
%57 = load i8*, i8** %4
%58 = getelementptr inbounds i8, i8* %57, i64 5
store i8 %56, i8* %58
%59 = load i32, i32* %3
%60 = and i32 %59, 8
%61 = icmp ne i32 %60, 0
%62 = zext i1 %61 to i64
%63 = select i1 %61, i32 120, i32 45
%64 = trunc i32 %63 to i8
%65 = load i8*, i8** %4
%66 = getelementptr inbounds i8, i8* %65, i64 6
store i8 %64, i8* %66
%67 = load i32, i32* %3
%68 = and i32 %67, 4
%69 = icmp ne i32 %68, 0
%70 = zext i1 %69 to i64
%71 = select i1 %69, i32 114, i32 45
%72 = trunc i32 %71 to i8
%73 = load i8*, i8** %4
%74 = getelementptr inbounds i8, i8* %73, i64 7
store i8 %72, i8* %74
%75 = load i32, i32* %3
%76 = and i32 %75, 2
%77 = icmp ne i32 %76, 0
%78 = zext i1 %77 to i64
%79 = select i1 %77, i32 119, i32 45
%80 = trunc i32 %79 to i8
%81 = load i8*, i8** %4
%82 = getelementptr inbounds i8, i8* %81, i64 8
store i8 %80, i8* %82
%83 = load i32, i32* %3
%84 = and i32 %83, 1
%85 = icmp ne i32 %84, 0
%86 = zext i1 %85 to i64
%87 = select i1 %85, i32 120, i32 45
%88 = trunc i32 %87 to i8
%89 = load i8*, i8** %4
%90 = getelementptr inbounds i8, i8* %89, i64 9
store i8 %88, i8* %90
%91 = load i8*, i8** %4
%92 = getelementptr inbounds i8, i8* %91, i64 10
store i8 0, i8* %92
%93 = load i32, i32* %3
%94 = and i32 %93, 2048
%95 = icmp ne i32 %94, 0
br i1 %95, label %96, label %105
96: ; preds = %15
%97 = load i32, i32* %3
%98 = and i32 %97, 64
%99 = icmp ne i32 %98, 0
%100 = zext i1 %99 to i64
%101 = select i1 %99, i32 115, i32 83
%102 = trunc i32 %101 to i8
%103 = load i8*, i8** %4
%104 = getelementptr inbounds i8, i8* %103, i64 3
store i8 %102, i8* %104
br label %105
105: ; preds = %96, %15
%106 = load i32, i32* %3
%107 = and i32 %106, 1024
%108 = icmp ne i32 %107, 0
br i1 %108, label %109, label %118
109: ; preds = %105
%110 = load i32, i32* %3
%111 = and i32 %110, 8
%112 = icmp ne i32 %111, 0
%113 = zext i1 %112 to i64
%114 = select i1 %112, i32 115, i32 83
%115 = trunc i32 %114 to i8
%116 = load i8*, i8** %4
%117 = getelementptr inbounds i8, i8* %116, i64 6
store i8 %115, i8* %117
br label %118
118: ; preds = %109, %105
%119 = load i32, i32* %3
%120 = and i32 %119, 512
%121 = icmp ne i32 %120, 0
br i1 %121, label %122, label %131
122: ; preds = %118
%123 = load i32, i32* %3
%124 = and i32 %123, 1
%125 = icmp ne i32 %124, 0
%126 = zext i1 %125 to i64
%127 = select i1 %125, i32 116, i32 84
%128 = trunc i32 %127 to i8
%129 = load i8*, i8** %4
%130 = getelementptr inbounds i8, i8* %129, i64 9
store i8 %128, i8* %130
br label %131
131: ; preds = %122, %118
ret void
}

LLVM IR (-O2):
@switch.table.format_rights = [11 x i8] c"cfdfbf-flfs"
define void @format_rights(i32 %0, i8* nocapture writeonly %1) {
%3 = and i32 %0, 61440
%4 = add nsw i32 %3, -4096
%5 = lshr exact i32 %4, 12
%6 = add nsw i32 %5, -1
%7 = icmp ult i32 %6, 11
br i1 %7, label %8, label %12
8: ; preds = %2
%9 = sext i32 %6 to i64
%10 = getelementptr inbounds [11 x i8], [11 x i8]* @switch.table.format_rights, i64 0, i64 %9
%11 = load i8, i8* %10
br label %12
12: ; preds = %8, %2
%13 = phi i8 [ 102, %2 ], [ %11, %8 ]
store i8 %13, i8* %1
%14 = and i32 %0, 256
%15 = icmp eq i32 %14, 0
%16 = select i1 %15, i8 45, i8 114
%17 = getelementptr inbounds i8, i8* %1, i64 1
store i8 %16, i8* %17
%18 = and i32 %0, 128
%19 = icmp eq i32 %18, 0
%20 = select i1 %19, i8 45, i8 119
%21 = getelementptr inbounds i8, i8* %1, i64 2
store i8 %20, i8* %21
%22 = and i32 %0, 64
%23 = icmp eq i32 %22, 0
%24 = select i1 %23, i8 45, i8 120
%25 = getelementptr inbounds i8, i8* %1, i64 3
store i8 %24, i8* %25
%26 = and i32 %0, 32
%27 = icmp eq i32 %26, 0
%28 = select i1 %27, i8 45, i8 114
%29 = getelementptr inbounds i8, i8* %1, i64 4
store i8 %28, i8* %29
%30 = and i32 %0, 16
%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 = and i32 %0, 8
%35 = icmp eq i32 %34, 0
%36 = select i1 %35, i8 45, i8 120
%37 = getelementptr inbounds i8, i8* %1, i64 6
store i8 %36, i8* %37
%38 = and i32 %0, 4
%39 = icmp eq i32 %38, 0
%40 = select i1 %39, i8 45, i8 114
%41 = getelementptr inbounds i8, i8* %1, i64 7
store i8 %40, i8* %41
%42 = and i32 %0, 2
%43 = icmp eq i32 %42, 0
%44 = select i1 %43, i8 45, i8 119
%45 = getelementptr inbounds i8, i8* %1, i64 8
store i8 %44, i8* %45
%46 = and i32 %0, 1
%47 = icmp eq i32 %46, 0
%48 = select i1 %47, i8 45, i8 120
%49 = getelementptr inbounds i8, i8* %1, i64 9
store i8 %48, i8* %49
%50 = getelementptr inbounds i8, i8* %1, i64 10
store i8 0, i8* %50
%51 = and i32 %0, 2048
%52 = icmp eq i32 %51, 0
br i1 %52, label %55, label %53
53: ; preds = %12
%54 = select i1 %23, i8 83, i8 115
store i8 %54, i8* %25
br label %55
55: ; preds = %53, %12
%56 = and i32 %0, 1024
%57 = icmp eq i32 %56, 0
br i1 %57, label %60, label %58
58: ; preds = %55
%59 = select i1 %35, i8 83, i8 115
store i8 %59, i8* %37
br label %60
60: ; preds = %58, %55
%61 = and i32 %0, 512
%62 = icmp eq i32 %61, 0
br i1 %62, label %65, label %63
63: ; preds = %60
%64 = select i1 %47, i8 84, i8 116
store i8 %64, i8* %49
br label %65
65: ; preds = %63, %60
ret void
}