#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 /*<<< orphan*/ ASSERT(int);
int _TimerBaseValid(int);
void TimerControlLevel(uint32_t ui32Base, uint32_t ui32Timer, bool bInvert) {
  ASSERT(_TimerBaseValid(ui32Base));
  ASSERT((ui32Timer == 0x000000ff) || (ui32Timer == 0x0000ff00) ||
         (ui32Timer == 0x0000ffff));
  ui32Timer &= 0x00000040 | 0x00004000;
  (*((volatile uint32_t *)(ui32Base + 0x0000000C))) =
      (bInvert ? ((*((volatile uint32_t *)(ui32Base + 0x0000000C))) | ui32Timer)
               : ((*((volatile uint32_t *)(ui32Base + 0x0000000C))) &
                  ~(ui32Timer)));
}


x86 assembly (clang, -O0):
<TimerControlLevel>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    -0x4(%rbp),%edi
call   1040 <_TimerBaseValid@plt>
mov    %eax,%edi
call   1030 <ASSERT@plt>
mov    $0x1,%al
cmpl   $0xff,-0x8(%rbp)
mov    %al,-0xd(%rbp)
je     1171 <TimerControlLevel+0x51>
mov    $0x1,%al
cmpl   $0xff00,-0x8(%rbp)
mov    %al,-0xd(%rbp)
je     1171 <TimerControlLevel+0x51>
cmpl   $0xffff,-0x8(%rbp)
sete   %al
mov    %al,-0xd(%rbp)
mov    -0xd(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
call   1030 <ASSERT@plt>
mov    -0x8(%rbp),%eax
and    $0x4040,%eax
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0xc(%rbp)
je     11a8 <TimerControlLevel+0x88>
mov    -0x4(%rbp),%eax
add    $0xc,%eax
cltq
mov    (%rax),%eax
or     -0x8(%rbp),%eax
mov    %eax,-0x14(%rbp)
jmp    11bd <TimerControlLevel+0x9d>
mov    -0x4(%rbp),%eax
add    $0xc,%eax
cltq
mov    (%rax),%eax
mov    -0x8(%rbp),%ecx
xor    $0xffffffff,%ecx
and    %ecx,%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%ecx
mov    -0x4(%rbp),%eax
add    $0xc,%eax
cltq
mov    %ecx,(%rax)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<TimerControlLevel>:
push   %rbp
push   %r14
push   %rbx
mov    %edx,%r14d
mov    %esi,%ebx
mov    %edi,%ebp
call   1040 <_TimerBaseValid@plt>
mov    %eax,%edi
call   1030 <ASSERT@plt>
mov    $0x1,%edi
cmp    $0xff,%ebx
je     1158 <TimerControlLevel+0x38>
cmp    $0xff00,%ebx
je     1158 <TimerControlLevel+0x38>
xor    %edi,%edi
cmp    $0xffff,%ebx
sete   %dil
call   1030 <ASSERT@plt>
and    $0x4040,%ebx
movslq %ebp,%rax
mov    0xc(%rax),%ecx
mov    %ebx,%edx
not    %edx
and    %ecx,%edx
or     %ecx,%ebx
test   %r14d,%r14d
cmove  %edx,%ebx
mov    %ebx,0xc(%rax)
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define void @TimerControlLevel(i32 %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%7 = load i32, i32* %4
%8 = call i32 @_TimerBaseValid(i32 %7)
%9 = call i32 @ASSERT(i32 %8)
%10 = load i32, i32* %5
%11 = icmp eq i32 %10, 255
br i1 %11, label %18, label %12
12: ; preds = %3
%13 = load i32, i32* %5
%14 = icmp eq i32 %13, 65280
br i1 %14, label %18, label %15
15: ; preds = %12
%16 = load i32, i32* %5
%17 = icmp eq i32 %16, 65535
br label %18
18: ; preds = %15, %12, %3
%19 = phi i1 [ true, %12 ], [ true, %3 ], [ %17, %15 ]
%20 = zext i1 %19 to i32
%21 = call i32 @ASSERT(i32 %20)
%22 = load i32, i32* %5
%23 = and i32 %22, 16448
store i32 %23, i32* %5
%24 = load i32, i32* %6
%25 = icmp ne i32 %24, 0
br i1 %25, label %26, label %34
26: ; preds = %18
%27 = load i32, i32* %4
%28 = add nsw i32 %27, 12
%29 = sext i32 %28 to i64
%30 = inttoptr i64 %29 to i32*
%31 = load volatile i32, i32* %30
%32 = load i32, i32* %5
%33 = or i32 %31, %32
br label %43
34: ; preds = %18
%35 = load i32, i32* %4
%36 = add nsw i32 %35, 12
%37 = sext i32 %36 to i64
%38 = inttoptr i64 %37 to i32*
%39 = load volatile i32, i32* %38
%40 = load i32, i32* %5
%41 = xor i32 %40, -1
%42 = and i32 %39, %41
br label %43
43: ; preds = %34, %26
%44 = phi i32 [ %33, %26 ], [ %42, %34 ]
%45 = load i32, i32* %4
%46 = add nsw i32 %45, 12
%47 = sext i32 %46 to i64
%48 = inttoptr i64 %47 to i32*
store volatile i32 %44, i32* %48
ret void
}

LLVM IR (-O2):
define void @TimerControlLevel(i32 %0, i32 %1, i32 %2) {
%4 = tail call i32 @_TimerBaseValid(i32 %0)
%5 = tail call i32 @ASSERT(i32 %4)
switch i32 %1, label %6 [
i32 65280, label %9
i32 255, label %9
]
6: ; preds = %3
%7 = icmp eq i32 %1, 65535
%8 = zext i1 %7 to i32
br label %9
9: ; preds = %3, %3, %6
%10 = phi i32 [ 1, %3 ], [ %8, %6 ], [ 1, %3 ]
%11 = tail call i32 @ASSERT(i32 %10)
%12 = and i32 %1, 16448
%13 = icmp eq i32 %2, 0
%14 = add nsw i32 %0, 12
%15 = sext i32 %14 to i64
%16 = inttoptr i64 %15 to i32*
%17 = load volatile i32, i32* %16
%18 = xor i32 %12, -1
%19 = and i32 %17, %18
%20 = or i32 %17, %12
%21 = select i1 %13, i32 %19, i32 %20
store volatile i32 %21, i32* %16
ret void
}