char *pax_short_flags(unsigned long flags) {
  static char buffer[7];
  buffer[0] = (flags & 1 ? 'p' : 'P');
  buffer[1] = (flags & 2 ? 'E' : 'e');
  buffer[2] = (flags & 4 ? 'm' : 'M');
  buffer[3] = (flags & 8 ? 'r' : 'R');
  buffer[4] = (flags & 16 ? 'X' : 'x');
  buffer[5] = (flags & 32 ? 's' : 'S');
  return buffer;
}


x86 assembly (clang, -O0):
<pax_short_flags>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdx
and    $0x1,%rdx
mov    $0x50,%eax
mov    $0x70,%ecx
cmp    $0x0,%rdx
cmovne %ecx,%eax
mov    %al,0x2efa(%rip)
mov    -0x8(%rbp),%rdx
and    $0x2,%rdx
mov    $0x65,%eax
mov    $0x45,%ecx
cmp    $0x0,%rdx
cmovne %ecx,%eax
mov    %al,0x2edc(%rip)
mov    -0x8(%rbp),%rdx
and    $0x4,%rdx
mov    $0x4d,%eax
mov    $0x6d,%ecx
cmp    $0x0,%rdx
cmovne %ecx,%eax
mov    %al,0x2ebe(%rip)
mov    -0x8(%rbp),%rdx
and    $0x8,%rdx
mov    $0x52,%eax
mov    $0x72,%ecx
cmp    $0x0,%rdx
cmovne %ecx,%eax
mov    %al,0x2ea0(%rip)
mov    -0x8(%rbp),%rdx
and    $0x10,%rdx
mov    $0x78,%eax
mov    $0x58,%ecx
cmp    $0x0,%rdx
cmovne %ecx,%eax
mov    %al,0x2e82(%rip)
mov    -0x8(%rbp),%rdx
and    $0x20,%rdx
mov    $0x53,%eax
mov    $0x73,%ecx
cmp    $0x0,%rdx
cmovne %ecx,%eax
mov    %al,0x2e64(%rip)
lea    0x2e58(%rip),%rax
pop    %rbp
ret

x86 assembly (clang, -O2):
<pax_short_flags>:
mov    %edi,%eax
and    $0x1,%al
shl    $0x5,%al
or     $0x50,%al
mov    %al,0x2f12(%rip)
lea    0x2f0b(%rip),%rax
test   $0x2,%dil
sete   %cl
shl    $0x5,%cl
or     $0x45,%cl
mov    %cl,0x2ef9(%rip)
mov    %edi,%ecx
and    $0x4,%cl
shl    $0x3,%cl
or     $0x4d,%cl
mov    %cl,0x2ee9(%rip)
mov    %edi,%ecx
and    $0x8,%cl
shl    $0x2,%cl
or     $0x52,%cl
mov    %cl,0x2ed9(%rip)
test   $0x10,%dil
sete   %cl
shl    $0x5,%cl
or     $0x58,%cl
mov    %cl,0x2ec7(%rip)
and    $0x20,%dil
or     $0x53,%dil
mov    %dil,0x2eb9(%rip)
ret

LLVM IR (-O0):
@pax_short_flags.buffer = internal global [7 x i8] zeroinitializer
define i8* @pax_short_flags(i64 %0) {
%2 = alloca i64
store i64 %0, i64* %2
%3 = load i64, i64* %2
%4 = and i64 %3, 1
%5 = icmp ne i64 %4, 0
%6 = zext i1 %5 to i64
%7 = select i1 %5, i32 112, i32 80
%8 = trunc i32 %7 to i8
store i8 %8, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @pax_short_flags.buffer, i64 0, i64 0)
%9 = load i64, i64* %2
%10 = and i64 %9, 2
%11 = icmp ne i64 %10, 0
%12 = zext i1 %11 to i64
%13 = select i1 %11, i32 69, i32 101
%14 = trunc i32 %13 to i8
store i8 %14, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @pax_short_flags.buffer, i64 0, i64 1)
%15 = load i64, i64* %2
%16 = and i64 %15, 4
%17 = icmp ne i64 %16, 0
%18 = zext i1 %17 to i64
%19 = select i1 %17, i32 109, i32 77
%20 = trunc i32 %19 to i8
store i8 %20, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @pax_short_flags.buffer, i64 0, i64 2)
%21 = load i64, i64* %2
%22 = and i64 %21, 8
%23 = icmp ne i64 %22, 0
%24 = zext i1 %23 to i64
%25 = select i1 %23, i32 114, i32 82
%26 = trunc i32 %25 to i8
store i8 %26, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @pax_short_flags.buffer, i64 0, i64 3)
%27 = load i64, i64* %2
%28 = and i64 %27, 16
%29 = icmp ne i64 %28, 0
%30 = zext i1 %29 to i64
%31 = select i1 %29, i32 88, i32 120
%32 = trunc i32 %31 to i8
store i8 %32, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @pax_short_flags.buffer, i64 0, i64 4)
%33 = load i64, i64* %2
%34 = and i64 %33, 32
%35 = icmp ne i64 %34, 0
%36 = zext i1 %35 to i64
%37 = select i1 %35, i32 115, i32 83
%38 = trunc i32 %37 to i8
store i8 %38, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @pax_short_flags.buffer, i64 0, i64 5)
ret i8* getelementptr inbounds ([7 x i8], [7 x i8]* @pax_short_flags.buffer, i64 0, i64 0)
}

LLVM IR (-O2):
@pax_short_flags.buffer = internal global [7 x i8] zeroinitializer
define i8* @pax_short_flags(i64 %0) {
%2 = and i64 %0, 1
%3 = icmp eq i64 %2, 0
%4 = select i1 %3, i8 80, i8 112
store i8 %4, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @pax_short_flags.buffer, i64 0, i64 0)
%5 = and i64 %0, 2
%6 = icmp eq i64 %5, 0
%7 = select i1 %6, i8 101, i8 69
store i8 %7, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @pax_short_flags.buffer, i64 0, i64 1)
%8 = and i64 %0, 4
%9 = icmp eq i64 %8, 0
%10 = select i1 %9, i8 77, i8 109
store i8 %10, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @pax_short_flags.buffer, i64 0, i64 2)
%11 = and i64 %0, 8
%12 = icmp eq i64 %11, 0
%13 = select i1 %12, i8 82, i8 114
store i8 %13, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @pax_short_flags.buffer, i64 0, i64 3)
%14 = and i64 %0, 16
%15 = icmp eq i64 %14, 0
%16 = select i1 %15, i8 120, i8 88
store i8 %16, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @pax_short_flags.buffer, i64 0, i64 4)
%17 = and i64 %0, 32
%18 = icmp eq i64 %17, 0
%19 = select i1 %18, i8 83, i8 115
store i8 %19, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @pax_short_flags.buffer, i64 0, i64 5)
ret i8* getelementptr inbounds ([7 x i8], [7 x i8]* @pax_short_flags.buffer, i64 0, i64 0)
}