#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 CANRegRead(unsigned long);
int /*<<< orphan*/ CANRegWrite(unsigned long, unsigned long);
void CANInit(unsigned long ulBase) {
  unsigned long ulMsg;
  ;
  CANRegWrite(ulBase + 0x00000000, 0x00000001);
  while (CANRegRead(ulBase + 0x00000020) & 0x00008000) {
  }
  CANRegWrite(ulBase + 0x00000024, 0x00000080 | 0x00000020 | 0x00000010);
  CANRegWrite(ulBase + 0x00000034, 0);
  CANRegWrite(ulBase + 0x00000038, 0);
  for (ulMsg = 1; ulMsg <= 32; ulMsg++) {
    while (CANRegRead(ulBase + 0x00000020) & 0x00008000) {
    }
    CANRegWrite(ulBase + 0x00000020, ulMsg);
  }
  CANRegWrite(ulBase + 0x00000024, 0x00000004 | 0x00000008);
  for (ulMsg = 1; ulMsg <= 32; ulMsg++) {
    while (CANRegRead(ulBase + 0x00000020) & 0x00008000) {
    }
    CANRegWrite(ulBase + 0x00000020, ulMsg);
  }
  CANRegRead(ulBase + 0x00000004);
}


x86 assembly (clang, -O0):
<CANInit>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
add    $0x0,%rdi
mov    $0x1,%esi
call   1030 <CANRegWrite@plt>
mov    -0x8(%rbp),%rdi
add    $0x20,%rdi
call   1040 <CANRegRead@plt>
and    $0x8000,%eax
cmp    $0x0,%eax
je     115e <CANInit+0x3e>
jmp    113e <CANInit+0x1e>
mov    -0x8(%rbp),%rdi
add    $0x24,%rdi
mov    $0xb0,%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    $0x38,%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1030 <CANRegWrite@plt>
movq   $0x1,-0x10(%rbp)
cmpq   $0x20,-0x10(%rbp)
ja     11ec <CANInit+0xcc>
jmp    11aa <CANInit+0x8a>
mov    -0x8(%rbp),%rdi
add    $0x20,%rdi
call   1040 <CANRegRead@plt>
and    $0x8000,%eax
cmp    $0x0,%eax
je     11ca <CANInit+0xaa>
jmp    11aa <CANInit+0x8a>
mov    -0x8(%rbp),%rdi
add    $0x20,%rdi
mov    -0x10(%rbp),%rsi
call   1030 <CANRegWrite@plt>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    119a <CANInit+0x7a>
mov    -0x8(%rbp),%rdi
add    $0x24,%rdi
mov    $0xc,%esi
call   1030 <CANRegWrite@plt>
movq   $0x1,-0x10(%rbp)
cmpq   $0x20,-0x10(%rbp)
ja     1258 <CANInit+0x138>
jmp    1216 <CANInit+0xf6>
mov    -0x8(%rbp),%rdi
add    $0x20,%rdi
call   1040 <CANRegRead@plt>
and    $0x8000,%eax
cmp    $0x0,%eax
je     1236 <CANInit+0x116>
jmp    1216 <CANInit+0xf6>
mov    -0x8(%rbp),%rdi
add    $0x20,%rdi
mov    -0x10(%rbp),%rsi
call   1030 <CANRegWrite@plt>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    1206 <CANInit+0xe6>
mov    -0x8(%rbp),%rdi
add    $0x4,%rdi
call   1040 <CANRegRead@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<CANInit>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r14
mov    $0x1,%esi
call   1030 <CANRegWrite@plt>
lea    0x20(%r14),%rbx
nopl   0x0(%rax)
mov    %rbx,%rdi
call   1040 <CANRegRead@plt>
test   $0x8000,%eax
jne    1140 <CANInit+0x20>
lea    0x24(%r14),%r15
mov    $0xb0,%esi
mov    %r15,%rdi
call   1030 <CANRegWrite@plt>
lea    0x34(%r14),%rdi
xor    %esi,%esi
call   1030 <CANRegWrite@plt>
lea    0x38(%r14),%rdi
xor    %esi,%esi
call   1030 <CANRegWrite@plt>
mov    $0x1,%r12d
nopl   0x0(%rax)
mov    %rbx,%rdi
call   1040 <CANRegRead@plt>
test   $0x8000,%eax
jne    1180 <CANInit+0x60>
mov    %rbx,%rdi
mov    %r12,%rsi
call   1030 <CANRegWrite@plt>
add    $0x1,%r12
cmp    $0x21,%r12
jne    1180 <CANInit+0x60>
mov    $0xc,%esi
mov    %r15,%rdi
call   1030 <CANRegWrite@plt>
mov    $0x1,%r15d
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1040 <CANRegRead@plt>
test   $0x8000,%eax
jne    11c0 <CANInit+0xa0>
mov    %rbx,%rdi
mov    %r15,%rsi
call   1030 <CANRegWrite@plt>
add    $0x1,%r15
cmp    $0x21,%r15
jne    11c0 <CANInit+0xa0>
add    $0x4,%r14
mov    %r14,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1040 <CANRegRead@plt>

LLVM IR (-O0):
define void @CANInit(i64 %0) {
%2 = alloca i64
%3 = alloca i64
store i64 %0, i64* %2
%4 = load i64, i64* %2
%5 = add i64 %4, 0
%6 = call i32 @CANRegWrite(i64 %5, i64 1)
br label %7
7: ; preds = %13, %1
%8 = load i64, i64* %2
%9 = add i64 %8, 32
%10 = call i32 @CANRegRead(i64 %9)
%11 = and i32 %10, 32768
%12 = icmp ne i32 %11, 0
br i1 %12, label %13, label %14
13: ; preds = %7
br label %7
14: ; preds = %7
%15 = load i64, i64* %2
%16 = add i64 %15, 36
%17 = call i32 @CANRegWrite(i64 %16, i64 176)
%18 = load i64, i64* %2
%19 = add i64 %18, 52
%20 = call i32 @CANRegWrite(i64 %19, i64 0)
%21 = load i64, i64* %2
%22 = add i64 %21, 56
%23 = call i32 @CANRegWrite(i64 %22, i64 0)
store i64 1, i64* %3
br label %24
24: ; preds = %40, %14
%25 = load i64, i64* %3
%26 = icmp ule i64 %25, 32
br i1 %26, label %27, label %43
27: ; preds = %24
br label %28
28: ; preds = %34, %27
%29 = load i64, i64* %2
%30 = add i64 %29, 32
%31 = call i32 @CANRegRead(i64 %30)
%32 = and i32 %31, 32768
%33 = icmp ne i32 %32, 0
br i1 %33, label %34, label %35
34: ; preds = %28
br label %28
35: ; preds = %28
%36 = load i64, i64* %2
%37 = add i64 %36, 32
%38 = load i64, i64* %3
%39 = call i32 @CANRegWrite(i64 %37, i64 %38)
br label %40
40: ; preds = %35
%41 = load i64, i64* %3
%42 = add i64 %41, 1
store i64 %42, i64* %3
br label %24
43: ; preds = %24
%44 = load i64, i64* %2
%45 = add i64 %44, 36
%46 = call i32 @CANRegWrite(i64 %45, i64 12)
store i64 1, i64* %3
br label %47
47: ; preds = %63, %43
%48 = load i64, i64* %3
%49 = icmp ule i64 %48, 32
br i1 %49, label %50, label %66
50: ; preds = %47
br label %51
51: ; preds = %57, %50
%52 = load i64, i64* %2
%53 = add i64 %52, 32
%54 = call i32 @CANRegRead(i64 %53)
%55 = and i32 %54, 32768
%56 = icmp ne i32 %55, 0
br i1 %56, label %57, label %58
57: ; preds = %51
br label %51
58: ; preds = %51
%59 = load i64, i64* %2
%60 = add i64 %59, 32
%61 = load i64, i64* %3
%62 = call i32 @CANRegWrite(i64 %60, i64 %61)
br label %63
63: ; preds = %58
%64 = load i64, i64* %3
%65 = add i64 %64, 1
store i64 %65, i64* %3
br label %47
66: ; preds = %47
%67 = load i64, i64* %2
%68 = add i64 %67, 4
%69 = call i32 @CANRegRead(i64 %68)
ret void
}

LLVM IR (-O2):
define void @CANInit(i64 %0) {
%2 = tail call i32 @CANRegWrite(i64 %0, i64 1)
%3 = add i64 %0, 32
br label %4
4: ; preds = %4, %1
%5 = tail call i32 @CANRegRead(i64 %3)
%6 = and i32 %5, 32768
%7 = icmp eq i32 %6, 0
br i1 %7, label %8, label %4
8: ; preds = %4
%9 = add i64 %0, 36
%10 = tail call i32 @CANRegWrite(i64 %9, i64 176)
%11 = add i64 %0, 52
%12 = tail call i32 @CANRegWrite(i64 %11, i64 0)
%13 = add i64 %0, 56
%14 = tail call i32 @CANRegWrite(i64 %13, i64 0)
br label %15
15: ; preds = %8, %21
%16 = phi i64 [ 1, %8 ], [ %23, %21 ]
br label %17
17: ; preds = %15, %17
%18 = tail call i32 @CANRegRead(i64 %3)
%19 = and i32 %18, 32768
%20 = icmp eq i32 %19, 0
br i1 %20, label %21, label %17
21: ; preds = %17
%22 = tail call i32 @CANRegWrite(i64 %3, i64 %16)
%23 = add nuw nsw i64 %16, 1
%24 = icmp eq i64 %23, 33
br i1 %24, label %25, label %15
25: ; preds = %21
%26 = tail call i32 @CANRegWrite(i64 %9, i64 12)
br label %27
27: ; preds = %25, %33
%28 = phi i64 [ 1, %25 ], [ %35, %33 ]
br label %29
29: ; preds = %27, %29
%30 = tail call i32 @CANRegRead(i64 %3)
%31 = and i32 %30, 32768
%32 = icmp eq i32 %31, 0
br i1 %32, label %33, label %29
33: ; preds = %29
%34 = tail call i32 @CANRegWrite(i64 %3, i64 %28)
%35 = add nuw nsw i64 %28, 1
%36 = icmp eq i64 %35, 33
br i1 %36, label %37, label %27
37: ; preds = %33
%38 = add i64 %0, 4
%39 = tail call i32 @CANRegRead(i64 %38)
ret void
}