#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 */

/* Variables and functions */
int CANBaseValid(unsigned long);
int CANRegRead(unsigned long);
int /*<<< orphan*/ CANRegWrite(unsigned long, unsigned long);
int /*<<< orphan*/ DEBUG_ASSERT(int);
void CANIntClear(unsigned long ulBase, unsigned long ulIntClr) {
  DEBUG_ASSERT(CANBaseValid(ulBase));
  DEBUG_ASSERT((ulIntClr == 0x00008000) ||
               ((ulIntClr >= 1) && (ulIntClr <= 32)));
  if (ulIntClr == 0x00008000) {
    CANRegRead(ulBase + 0x00000004);
  } else {
    while (CANRegRead(ulBase + 0x00000020) & 0x00008000) {
    }
    CANRegWrite(ulBase + 0x00000024, 0x00000008);
    CANRegWrite(ulBase + 0x00000020, ulIntClr & 0x0000003F);
    while (CANRegRead(ulBase + 0x00000020) & 0x00008000) {
    }
  }
}


x86 assembly (clang, -O0):
<CANIntClear>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1060 <CANBaseValid@plt>
mov    %eax,%edi
call   1050 <DEBUG_ASSERT@plt>
mov    $0x1,%al
cmpq   $0x8000,-0x10(%rbp)
mov    %al,-0x11(%rbp)
je     1194 <CANIntClear+0x54>
xor    %eax,%eax
cmpq   $0x1,-0x10(%rbp)
mov    %al,-0x12(%rbp)
jb     118e <CANIntClear+0x4e>
cmpq   $0x20,-0x10(%rbp)
setbe  %al
mov    %al,-0x12(%rbp)
mov    -0x12(%rbp),%al
mov    %al,-0x11(%rbp)
mov    -0x11(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
call   1050 <DEBUG_ASSERT@plt>
cmpq   $0x8000,-0x10(%rbp)
jne    11c1 <CANIntClear+0x81>
mov    -0x8(%rbp),%rdi
add    $0x4,%rdi
call   1040 <CANRegRead@plt>
jmp    1232 <CANIntClear+0xf2>
jmp    11c6 <CANIntClear+0x86>
mov    -0x8(%rbp),%rdi
add    $0x20,%rdi
call   1040 <CANRegRead@plt>
and    $0x8000,%eax
cmp    $0x0,%eax
je     11e6 <CANIntClear+0xa6>
jmp    11c6 <CANIntClear+0x86>
mov    -0x8(%rbp),%rdi
add    $0x24,%rdi
mov    $0x8,%esi
call   1030 <CANRegWrite@plt>
mov    -0x8(%rbp),%rdi
add    $0x20,%rdi
mov    -0x10(%rbp),%rsi
and    $0x3f,%rsi
call   1030 <CANRegWrite@plt>
mov    -0x8(%rbp),%rdi
add    $0x20,%rdi
call   1040 <CANRegRead@plt>
and    $0x8000,%eax
cmp    $0x0,%eax
je     122d <CANIntClear+0xed>
jmp    120d <CANIntClear+0xcd>
jmp    1232 <CANIntClear+0xf2>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<CANIntClear>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%r15
call   1060 <CANBaseValid@plt>
mov    %eax,%edi
call   1050 <DEBUG_ASSERT@plt>
cmp    $0x8000,%r14
sete   %al
lea    -0x1(%r14),%rcx
cmp    $0x20,%rcx
setb   %cl
or     %al,%cl
movzbl %cl,%edi
call   1050 <DEBUG_ASSERT@plt>
cmp    $0x8000,%r14
jne    1190 <CANIntClear+0x50>
add    $0x4,%r15
mov    %r15,%rdi
pop    %rbx
pop    %r14
pop    %r15
jmp    1040 <CANRegRead@plt>
lea    0x20(%r15),%rbx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %rbx,%rdi
call   1040 <CANRegRead@plt>
test   $0x8000,%eax
jne    11a0 <CANIntClear+0x60>
add    $0x24,%r15
mov    $0x8,%esi
mov    %r15,%rdi
call   1030 <CANRegWrite@plt>
and    $0x3f,%r14d
mov    %rbx,%rdi
mov    %r14,%rsi
call   1030 <CANRegWrite@plt>
nop
mov    %rbx,%rdi
call   1040 <CANRegRead@plt>
test   $0x8000,%eax
jne    11d0 <CANIntClear+0x90>
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define void @CANIntClear(i64 %0, i64 %1) {
%3 = alloca i64
%4 = alloca i64
store i64 %0, i64* %3
store i64 %1, i64* %4
%5 = load i64, i64* %3
%6 = call i32 @CANBaseValid(i64 %5)
%7 = call i32 @DEBUG_ASSERT(i32 %6)
%8 = load i64, i64* %4
%9 = icmp eq i64 %8, 32768
br i1 %9, label %18, label %10
10: ; preds = %2
%11 = load i64, i64* %4
%12 = icmp uge i64 %11, 1
br i1 %12, label %13, label %16
13: ; preds = %10
%14 = load i64, i64* %4
%15 = icmp ule i64 %14, 32
br label %16
16: ; preds = %13, %10
%17 = phi i1 [ false, %10 ], [ %15, %13 ]
br label %18
18: ; preds = %16, %2
%19 = phi i1 [ true, %2 ], [ %17, %16 ]
%20 = zext i1 %19 to i32
%21 = call i32 @DEBUG_ASSERT(i32 %20)
%22 = load i64, i64* %4
%23 = icmp eq i64 %22, 32768
br i1 %23, label %24, label %28
24: ; preds = %18
%25 = load i64, i64* %3
%26 = add i64 %25, 4
%27 = call i32 @CANRegRead(i64 %26)
br label %53
28: ; preds = %18
br label %29
29: ; preds = %35, %28
%30 = load i64, i64* %3
%31 = add i64 %30, 32
%32 = call i32 @CANRegRead(i64 %31)
%33 = and i32 %32, 32768
%34 = icmp ne i32 %33, 0
br i1 %34, label %35, label %36
35: ; preds = %29
br label %29
36: ; preds = %29
%37 = load i64, i64* %3
%38 = add i64 %37, 36
%39 = call i32 @CANRegWrite(i64 %38, i64 8)
%40 = load i64, i64* %3
%41 = add i64 %40, 32
%42 = load i64, i64* %4
%43 = and i64 %42, 63
%44 = call i32 @CANRegWrite(i64 %41, i64 %43)
br label %45
45: ; preds = %51, %36
%46 = load i64, i64* %3
%47 = add i64 %46, 32
%48 = call i32 @CANRegRead(i64 %47)
%49 = and i32 %48, 32768
%50 = icmp ne i32 %49, 0
br i1 %50, label %51, label %52
51: ; preds = %45
br label %45
52: ; preds = %45
br label %53
53: ; preds = %52, %24
ret void
}

LLVM IR (-O2):
define void @CANIntClear(i64 %0, i64 %1) {
%3 = tail call i32 @CANBaseValid(i64 %0)
%4 = tail call i32 @DEBUG_ASSERT(i32 %3)
%5 = icmp eq i64 %1, 32768
%6 = add i64 %1, -1
%7 = icmp ult i64 %6, 32
%8 = or i1 %5, %7
%9 = zext i1 %8 to i32
%10 = tail call i32 @DEBUG_ASSERT(i32 %9)
br i1 %5, label %13, label %11
11: ; preds = %2
%12 = add i64 %0, 32
br label %16
13: ; preds = %2
%14 = add i64 %0, 4
%15 = tail call i32 @CANRegRead(i64 %14)
br label %29
16: ; preds = %11, %16
%17 = tail call i32 @CANRegRead(i64 %12)
%18 = and i32 %17, 32768
%19 = icmp eq i32 %18, 0
br i1 %19, label %20, label %16
20: ; preds = %16
%21 = add i64 %0, 36
%22 = tail call i32 @CANRegWrite(i64 %21, i64 8)
%23 = and i64 %1, 63
%24 = tail call i32 @CANRegWrite(i64 %12, i64 %23)
br label %25
25: ; preds = %25, %20
%26 = tail call i32 @CANRegRead(i64 %12)
%27 = and i32 %26, 32768
%28 = icmp eq i32 %27, 0
br i1 %28, label %29, label %25
29: ; preds = %25, %13
ret void
}