#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 uint;

/* Variables and functions */
char *strdup(char *);
char *permissions(uint flags) {
  char *res = strdup("   ");
  if (flags & 1)
    res[0] = 'X';
  if (flags & 2)
    res[1] = 'W';
  if (flags & 4)
    res[2] = 'R';
  return res;
}


x86 assembly (clang, -O0):
<permissions>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
lea    0xede(%rip),%rdi
call   1030 <strdup@plt>
mov    %rax,-0x10(%rbp)
mov    -0x4(%rbp),%eax
and    $0x1,%eax
cmp    $0x0,%eax
je     1141 <permissions+0x31>
mov    -0x10(%rbp),%rax
movb   $0x58,(%rax)
mov    -0x4(%rbp),%eax
and    $0x2,%eax
cmp    $0x0,%eax
je     1158 <permissions+0x48>
mov    -0x10(%rbp),%rax
movb   $0x57,0x1(%rax)
mov    -0x4(%rbp),%eax
and    $0x4,%eax
cmp    $0x0,%eax
je     116f <permissions+0x5f>
mov    -0x10(%rbp),%rax
movb   $0x52,0x2(%rax)
mov    -0x10(%rbp),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<permissions>:
push   %rbx
mov    %edi,%ebx
lea    0xee6(%rip),%rdi
call   1030 <strdup@plt>
test   $0x1,%bl
jne    1130 <permissions+0x20>
test   $0x2,%bl
jne    1138 <permissions+0x28>
test   $0x4,%bl
jne    1141 <permissions+0x31>
pop    %rbx
ret
movb   $0x58,(%rax)
test   $0x2,%bl
je     1129 <permissions+0x19>
movb   $0x57,0x1(%rax)
test   $0x4,%bl
je     112e <permissions+0x1e>
movb   $0x52,0x2(%rax)
pop    %rbx
ret

LLVM IR (-O0):
@.str = [4 x i8] c" \00"
define i8* @permissions(i32 %0) {
%2 = alloca i32
%3 = alloca i8*
store i32 %0, i32* %2
%4 = call i8* @strdup(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
store i8* %4, i8** %3
%5 = load i32, i32* %2
%6 = and i32 %5, 1
%7 = icmp ne i32 %6, 0
br i1 %7, label %8, label %11
8: ; preds = %1
%9 = load i8*, i8** %3
%10 = getelementptr inbounds i8, i8* %9, i64 0
store i8 88, i8* %10
br label %11
11: ; preds = %8, %1
%12 = load i32, i32* %2
%13 = and i32 %12, 2
%14 = icmp ne i32 %13, 0
br i1 %14, label %15, label %18
15: ; preds = %11
%16 = load i8*, i8** %3
%17 = getelementptr inbounds i8, i8* %16, i64 1
store i8 87, i8* %17
br label %18
18: ; preds = %15, %11
%19 = load i32, i32* %2
%20 = and i32 %19, 4
%21 = icmp ne i32 %20, 0
br i1 %21, label %22, label %25
22: ; preds = %18
%23 = load i8*, i8** %3
%24 = getelementptr inbounds i8, i8* %23, i64 2
store i8 82, i8* %24
br label %25
25: ; preds = %22, %18
%26 = load i8*, i8** %3
ret i8* %26
}

LLVM IR (-O2):
@.str = [4 x i8] c" \00"
define noalias i8* @permissions(i32 %0) {
%2 = tail call dereferenceable_or_null(4) i8* @strdup(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%3 = and i32 %0, 1
%4 = icmp eq i32 %3, 0
br i1 %4, label %6, label %5
5: ; preds = %1
store i8 88, i8* %2
br label %6
6: ; preds = %5, %1
%7 = and i32 %0, 2
%8 = icmp eq i32 %7, 0
br i1 %8, label %11, label %9
9: ; preds = %6
%10 = getelementptr inbounds i8, i8* %2, i64 1
store i8 87, i8* %10
br label %11
11: ; preds = %9, %6
%12 = and i32 %0, 4
%13 = icmp eq i32 %12, 0
br i1 %13, label %16, label %14
14: ; preds = %11
%15 = getelementptr inbounds i8, i8* %2, i64 2
store i8 82, i8* %15
br label %16
16: ; preds = %14, %11
ret i8* %2
}