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

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


x86 assembly (clang, -O0):
<elfToMapProtection>:
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 <elfToMapProtection+0x32>
mov    0x2eae(%rip),%rax
mov    (%rax),%eax
or     -0x8(%rbp),%eax
mov    %eax,-0x8(%rbp)
mov    -0x4(%rbp),%eax
mov    0x2e8c(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     1156 <elfToMapProtection+0x56>
mov    0x2e72(%rip),%rax
mov    (%rax),%eax
or     -0x8(%rbp),%eax
mov    %eax,-0x8(%rbp)
mov    -0x4(%rbp),%eax
mov    0x2e58(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     117a <elfToMapProtection+0x7a>
mov    0x2e86(%rip),%rax
mov    (%rax),%eax
or     -0x8(%rbp),%eax
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<elfToMapProtection>:
mov    0x2ed9(%rip),%rax
mov    (%rax),%ecx
and    %edi,%ecx
je     1116 <elfToMapProtection+0x16>
mov    0x2ec4(%rip),%rax
mov    (%rax),%ecx
mov    0x2eab(%rip),%rax
mov    (%rax),%eax
and    %edi,%eax
je     112c <elfToMapProtection+0x2c>
mov    0x2e96(%rip),%rax
mov    (%rax),%eax
or     %ecx,%eax
mov    0x2e83(%rip),%rcx
and    (%rcx),%edi
je     1142 <elfToMapProtection+0x42>
mov    0x2eb8(%rip),%rcx
mov    (%rcx),%edi
or     %edi,%eax
ret

LLVM IR (-O0):
@PF_X = global i32 0
@PROT_EXEC = global i32 0
@PF_W = global i32 0
@PROT_WRITE = global i32 0
@PF_R = global i32 0
@PROT_READ = global i32 0
define i32 @elfToMapProtection(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_W
%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_WRITE
%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_R
%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_READ
%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_W = global i32 0
@PROT_WRITE = global i32 0
@PF_R = global i32 0
@PROT_READ = global i32 0
define i32 @elfToMapProtection(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_W
%8 = and i32 %7, %0
%9 = icmp eq i32 %8, 0
%10 = load i32, i32* @PROT_WRITE
%11 = select i1 %9, i32 0, i32 %10
%12 = or i32 %11, %6
%13 = load i32, i32* @PF_R
%14 = and i32 %13, %0
%15 = icmp eq i32 %14, 0
%16 = load i32, i32* @PROT_READ
%17 = select i1 %15, i32 0, i32 %16
%18 = or i32 %12, %17
ret i32 %18
}