#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 CANMessageClear(unsigned long ulBase, unsigned long ulObjID) {
  DEBUG_ASSERT(CANBaseValid(ulBase));
  DEBUG_ASSERT((ulObjID >= 1) && (ulObjID <= 32));
  while (CANRegRead(ulBase + 0x00000020) & 0x00008000) {
  }
  CANRegWrite(ulBase + 0x00000024, 0x00000080 | 0x00000020);
  CANRegWrite(ulBase + 0x00000030, 0);
  CANRegWrite(ulBase + 0x00000034, 0);
  CANRegWrite(ulBase + 0x00000020, ulObjID & 0x0000003F);
}


x86 assembly (clang, -O0):
<CANMessageClear>:
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>
xor    %eax,%eax
cmpq   $0x1,-0x10(%rbp)
mov    %al,-0x11(%rbp)
jb     117b <CANMessageClear+0x3b>
cmpq   $0x20,-0x10(%rbp)
setbe  %al
mov    %al,-0x11(%rbp)
mov    -0x11(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
call   1050 <DEBUG_ASSERT@plt>
mov    -0x8(%rbp),%rdi
add    $0x20,%rdi
call   1040 <CANRegRead@plt>
and    $0x8000,%eax
cmp    $0x0,%eax
je     11a8 <CANMessageClear+0x68>
jmp    1188 <CANMessageClear+0x48>
mov    -0x8(%rbp),%rdi
add    $0x24,%rdi
mov    $0xa0,%esi
call   1030 <CANRegWrite@plt>
mov    -0x8(%rbp),%rdi
add    $0x30,%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1030 <CANRegWrite@plt>
mov    -0x8(%rbp),%rdi
add    $0x34,%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1030 <CANRegWrite@plt>
mov    -0x8(%rbp),%rdi
add    $0x20,%rdi
mov    -0x10(%rbp),%rsi
and    $0x3f,%rsi
call   1030 <CANRegWrite@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<CANMessageClear>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%r15
call   1060 <CANBaseValid@plt>
mov    %eax,%edi
call   1050 <DEBUG_ASSERT@plt>
lea    -0x1(%r14),%rax
xor    %edi,%edi
cmp    $0x20,%rax
setb   %dil
call   1050 <DEBUG_ASSERT@plt>
lea    0x20(%r15),%rbx
xchg   %ax,%ax
mov    %rbx,%rdi
call   1040 <CANRegRead@plt>
test   $0x8000,%eax
jne    1170 <CANMessageClear+0x30>
lea    0x24(%r15),%rdi
mov    $0xa0,%esi
call   1030 <CANRegWrite@plt>
lea    0x30(%r15),%rdi
xor    %esi,%esi
call   1030 <CANRegWrite@plt>
add    $0x34,%r15
mov    %r15,%rdi
xor    %esi,%esi
call   1030 <CANRegWrite@plt>
and    $0x3f,%r14d
mov    %rbx,%rdi
mov    %r14,%rsi
pop    %rbx
pop    %r14
pop    %r15
jmp    1030 <CANRegWrite@plt>

LLVM IR (-O0):
define void @CANMessageClear(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 uge i64 %8, 1
br i1 %9, label %10, label %13
10: ; preds = %2
%11 = load i64, i64* %4
%12 = icmp ule i64 %11, 32
br label %13
13: ; preds = %10, %2
%14 = phi i1 [ false, %2 ], [ %12, %10 ]
%15 = zext i1 %14 to i32
%16 = call i32 @DEBUG_ASSERT(i32 %15)
br label %17
17: ; preds = %23, %13
%18 = load i64, i64* %3
%19 = add i64 %18, 32
%20 = call i32 @CANRegRead(i64 %19)
%21 = and i32 %20, 32768
%22 = icmp ne i32 %21, 0
br i1 %22, label %23, label %24
23: ; preds = %17
br label %17
24: ; preds = %17
%25 = load i64, i64* %3
%26 = add i64 %25, 36
%27 = call i32 @CANRegWrite(i64 %26, i64 160)
%28 = load i64, i64* %3
%29 = add i64 %28, 48
%30 = call i32 @CANRegWrite(i64 %29, i64 0)
%31 = load i64, i64* %3
%32 = add i64 %31, 52
%33 = call i32 @CANRegWrite(i64 %32, i64 0)
%34 = load i64, i64* %3
%35 = add i64 %34, 32
%36 = load i64, i64* %4
%37 = and i64 %36, 63
%38 = call i32 @CANRegWrite(i64 %35, i64 %37)
ret void
}

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