#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 */

/* Variables and functions */
int PF_R;
int PF_W;
int PF_X;
int PROT_EXEC;
int PROT_READ;
int PROT_WRITE;
int map_flags(int flags) {
  int perm = 0;
  if (flags & PF_X)
    perm |= PROT_EXEC;
  if (flags & PF_R)
    perm |= PROT_READ;
  if (flags & PF_W)
    perm |= PROT_WRITE;
  return perm;
}


x86 assembly (clang, -O0):
<map_flags>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
mov    -0x4(%rbp),%eax
mov    0x2ec8(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     1132 <map_flags+0x32>
mov    0x2eae(%rip),%rax
mov    (%rax),%eax
or     -0x8(%rbp),%eax
mov    %eax,-0x8(%rbp)
mov    -0x4(%rbp),%eax
mov    0x2e7c(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     1156 <map_flags+0x56>
mov    0x2eaa(%rip),%rax
mov    (%rax),%eax
or     -0x8(%rbp),%eax
mov    %eax,-0x8(%rbp)
mov    -0x4(%rbp),%eax
mov    0x2e68(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     117a <map_flags+0x7a>
mov    0x2e4e(%rip),%rax
mov    (%rax),%eax
or     -0x8(%rbp),%eax
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<map_flags>:
mov    0x2ed9(%rip),%rax
mov    (%rax),%ecx
and    %edi,%ecx
je     1116 <map_flags+0x16>
mov    0x2ec4(%rip),%rax
mov    (%rax),%ecx
mov    0x2e9b(%rip),%rax
mov    (%rax),%eax
and    %edi,%eax
je     112c <map_flags+0x2c>
mov    0x2ece(%rip),%rax
mov    (%rax),%eax
or     %ecx,%eax
mov    0x2e93(%rip),%rcx
and    (%rcx),%edi
je     1142 <map_flags+0x42>
mov    0x2e80(%rip),%rcx
mov    (%rcx),%edi
or     %edi,%eax
ret

LLVM IR (-O0):
@PF_X = global i32 0
@PROT_EXEC = global i32 0
@PF_R = global i32 0
@PROT_READ = global i32 0
@PF_W = global i32 0
@PROT_WRITE = global i32 0
define i32 @map_flags(i32 %0) {
%2 = alloca i32
%3 = alloca i32
store i32 %0, i32* %2
store i32 0, i32* %3
%4 = load i32, i32* %2
%5 = load i32, i32* @PF_X
%6 = and i32 %4, %5
%7 = icmp ne i32 %6, 0
br i1 %7, label %8, label %12
8: ; preds = %1
%9 = load i32, i32* @PROT_EXEC
%10 = load i32, i32* %3
%11 = or i32 %10, %9
store i32 %11, i32* %3
br label %12
12: ; preds = %8, %1
%13 = load i32, i32* %2
%14 = load i32, i32* @PF_R
%15 = and i32 %13, %14
%16 = icmp ne i32 %15, 0
br i1 %16, label %17, label %21
17: ; preds = %12
%18 = load i32, i32* @PROT_READ
%19 = load i32, i32* %3
%20 = or i32 %19, %18
store i32 %20, i32* %3
br label %21
21: ; preds = %17, %12
%22 = load i32, i32* %2
%23 = load i32, i32* @PF_W
%24 = and i32 %22, %23
%25 = icmp ne i32 %24, 0
br i1 %25, label %26, label %30
26: ; preds = %21
%27 = load i32, i32* @PROT_WRITE
%28 = load i32, i32* %3
%29 = or i32 %28, %27
store i32 %29, i32* %3
br label %30
30: ; preds = %26, %21
%31 = load i32, i32* %3
ret i32 %31
}

LLVM IR (-O2):
@PF_X = global i32 0
@PROT_EXEC = global i32 0
@PF_R = global i32 0
@PROT_READ = global i32 0
@PF_W = global i32 0
@PROT_WRITE = global i32 0
define i32 @map_flags(i32 %0) {
%2 = load i32, i32* @PF_X
%3 = and i32 %2, %0
%4 = icmp eq i32 %3, 0
%5 = load i32, i32* @PROT_EXEC
%6 = select i1 %4, i32 0, i32 %5
%7 = load i32, i32* @PF_R
%8 = and i32 %7, %0
%9 = icmp eq i32 %8, 0
%10 = load i32, i32* @PROT_READ
%11 = select i1 %9, i32 0, i32 %10
%12 = or i32 %11, %6
%13 = load i32, i32* @PF_W
%14 = and i32 %13, %0
%15 = icmp eq i32 %14, 0
%16 = load i32, i32* @PROT_WRITE
%17 = select i1 %15, i32 0, i32 %16
%18 = or i32 %12, %17
ret i32 %18
}