#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 scalar_t__ src_prot;
typedef scalar_t__ dst_prot;

/* Variables and functions */
int /*<<< orphan*/ PROT_EXEC;
int PROT_READ;
int PROT_WRITE;
int check_prot(int src_prot, int dst_prot) {
  if (((src_prot) & (PROT_READ | PROT_WRITE)) !=
      ((dst_prot) & (PROT_READ | PROT_WRITE)))
    return 0;
  return (((dst_prot)&PROT_EXEC) & ((src_prot)&PROT_EXEC)) ==
         ((dst_prot)&PROT_EXEC);
}


x86 assembly (clang, -O0):
<check_prot>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%eax
mov    0x2ee4(%rip),%rcx
mov    (%rcx),%ecx
mov    0x2eb3(%rip),%rdx
or     (%rdx),%ecx
and    %ecx,%eax
mov    -0xc(%rbp),%ecx
mov    0x2ecd(%rip),%rdx
mov    (%rdx),%edx
mov    0x2e9c(%rip),%rsi
or     (%rsi),%edx
and    %edx,%ecx
cmp    %ecx,%eax
je     114c <check_prot+0x4c>
movl   $0x0,-0x4(%rbp)
jmp    117f <check_prot+0x7f>
mov    -0xc(%rbp),%eax
mov    0x2e8a(%rip),%rcx
and    (%rcx),%eax
mov    -0x8(%rbp),%ecx
mov    0x2e7e(%rip),%rdx
and    (%rdx),%ecx
and    %ecx,%eax
mov    -0xc(%rbp),%ecx
mov    0x2e70(%rip),%rdx
and    (%rdx),%ecx
cmp    %ecx,%eax
sete   %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<check_prot>:
mov    0x2ef1(%rip),%rax
mov    0x2ec2(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
mov    %esi,%edx
xor    %edi,%edx
xor    %eax,%eax
test   %edx,%ecx
je     111d <check_prot+0x1d>
ret
mov    0x2ebc(%rip),%rax
and    (%rax),%esi
not    %edi
xor    %eax,%eax
test   %edi,%esi
sete   %al
ret

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

LLVM IR (-O2):
@PROT_READ = global i32 0
@PROT_WRITE = global i32 0
@PROT_EXEC = global i32 0
define i32 @check_prot(i32 %0, i32 %1) {
%3 = load i32, i32* @PROT_READ
%4 = load i32, i32* @PROT_WRITE
%5 = or i32 %4, %3
%6 = xor i32 %1, %0
%7 = and i32 %5, %6
%8 = icmp eq i32 %7, 0
br i1 %8, label %9, label %15
9: ; preds = %2
%10 = load i32, i32* @PROT_EXEC
%11 = and i32 %10, %1
%12 = and i32 %11, %0
%13 = icmp eq i32 %12, %11
%14 = zext i1 %13 to i32
br label %15
15: ; preds = %2, %9
%16 = phi i32 [ %14, %9 ], [ 0, %2 ]
ret i32 %16
}