#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;
int CAN_SFF_MASK;
canid_t calc_mask(int testcase) {
  canid_t mask = CAN_SFF_MASK;
  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)
mov    0x2eb2(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xc(%rbp)
cmpl   $0xf,-0x8(%rbp)
jle    1140 <calc_mask+0x40>
mov    0x2ec4(%rip),%rax
mov    (%rax),%eax
mov    0x2eab(%rip),%rcx
or     (%rcx),%eax
mov    0x2e9a(%rip),%rcx
or     (%rcx),%eax
mov    %eax,-0x4(%rbp)
jmp    1182 <calc_mask+0x82>
mov    -0x8(%rbp),%eax
and    $0x4,%eax
cmp    $0x0,%eax
je     115e <calc_mask+0x5e>
mov    0x2e82(%rip),%rax
mov    (%rax),%eax
or     -0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%eax
and    $0x8,%eax
cmp    $0x0,%eax
je     117c <calc_mask+0x7c>
mov    0x2e5c(%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    0x2e96(%rip),%rcx
mov    %edi,%edx
shl    $0x1d,%edx
sar    $0x1f,%edx
mov    0x2e9f(%rip),%rsi
and    (%rsi),%edx
or     (%rcx),%edx
shl    $0x1c,%eax
sar    $0x1f,%eax
mov    0x2e86(%rip),%rcx
and    (%rcx),%eax
or     %edx,%eax
ret

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

LLVM IR (-O2):
@CAN_SFF_MASK = global i32 0
@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 %21
9: ; preds = %1
%10 = load i32, i32* @CAN_SFF_MASK
%11 = and i32 %0, 4
%12 = icmp eq i32 %11, 0
%13 = load i32, i32* @CAN_EFF_FLAG
%14 = select i1 %12, i32 0, i32 %13
%15 = or i32 %14, %10
%16 = and i32 %0, 8
%17 = icmp eq i32 %16, 0
%18 = load i32, i32* @CAN_RTR_FLAG
%19 = select i1 %17, i32 0, i32 %18
%20 = or i32 %15, %19
br label %21
21: ; preds = %9, %3
%22 = phi i32 [ %8, %3 ], [ %20, %9 ]
ret i32 %22
}