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

/* Variables and functions */
int CAN_EFF_FLAG;
int CAN_EFF_MASK;
int CAN_RTR_FLAG;
canid_t calc_mask(int testcase) {
  canid_t mask = 0x7FF;
  if (testcase > 15)
    return (CAN_EFF_MASK | CAN_EFF_FLAG | CAN_RTR_FLAG);
  if (testcase & 4)
    mask |= CAN_EFF_FLAG;
  if (testcase & 8)
    mask |= CAN_RTR_FLAG;
  return mask;
}


x86 assembly (clang, -O0):
<calc_mask>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x8(%rbp)
movl   $0x7ff,-0xc(%rbp)
cmpl   $0xf,-0x8(%rbp)
jle    113b <calc_mask+0x3b>
mov    0x2ec9(%rip),%rax
mov    (%rax),%eax
mov    0x2eb0(%rip),%rcx
or     (%rcx),%eax
mov    0x2e9f(%rip),%rcx
or     (%rcx),%eax
mov    %eax,-0x4(%rbp)
jmp    117d <calc_mask+0x7d>
mov    -0x8(%rbp),%eax
and    $0x4,%eax
cmp    $0x0,%eax
je     1159 <calc_mask+0x59>
mov    0x2e87(%rip),%rax
mov    (%rax),%eax
or     -0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%eax
and    $0x8,%eax
cmp    $0x0,%eax
je     1177 <calc_mask+0x77>
mov    0x2e61(%rip),%rax
mov    (%rax),%eax
or     -0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<calc_mask>:
cmp    $0x10,%edi
jl     1121 <calc_mask+0x21>
mov    0x2edc(%rip),%rcx
mov    0x2ec5(%rip),%rax
mov    (%rax),%eax
or     (%rcx),%eax
mov    0x2eb2(%rip),%rcx
or     (%rcx),%eax
ret
mov    %edi,%eax
mov    0x2eae(%rip),%rcx
mov    $0x7ff,%edx
mov    (%rcx),%ecx
or     %edx,%ecx
test   $0x4,%al
cmove  %edx,%ecx
shl    $0x1c,%eax
sar    $0x1f,%eax
mov    0x2e8b(%rip),%rdx
and    (%rdx),%eax
or     %ecx,%eax
ret

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

LLVM IR (-O2):
@CAN_EFF_MASK = global i32 0
@CAN_EFF_FLAG = global i32 0
@CAN_RTR_FLAG = global i32 0
define i32 @calc_mask(i32 %0) {
%2 = icmp sgt i32 %0, 15
br i1 %2, label %3, label %9
3: ; preds = %1
%4 = load i32, i32* @CAN_EFF_MASK
%5 = load i32, i32* @CAN_EFF_FLAG
%6 = or i32 %5, %4
%7 = load i32, i32* @CAN_RTR_FLAG
%8 = or i32 %6, %7
br label %20
9: ; preds = %1
%10 = and i32 %0, 4
%11 = icmp eq i32 %10, 0
%12 = load i32, i32* @CAN_EFF_FLAG
%13 = or i32 %12, 2047
%14 = select i1 %11, i32 2047, i32 %13
%15 = and i32 %0, 8
%16 = icmp eq i32 %15, 0
%17 = load i32, i32* @CAN_RTR_FLAG
%18 = select i1 %16, i32 0, i32 %17
%19 = or i32 %14, %18
br label %20
20: ; preds = %9, %3
%21 = phi i32 [ %8, %3 ], [ %19, %9 ]
ret i32 %21
}