#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, int);
void CANInit(unsigned long ulBase) {
  int iMsg;
  ;
  CANRegWrite(ulBase + 0x00000000, 0x00000001);
  while (CANRegRead(ulBase + 0x00000020) & 0x00008000) {
  }
  CANRegWrite(ulBase + 0x00000024, 0x00000080 | 0x00000020 | 0x00000010);
  CANRegWrite(ulBase + 0x00000034, 0);
  CANRegWrite(ulBase + 0x00000038, 0);
  for (iMsg = 1; iMsg <= 32; iMsg++) {
    while (CANRegRead(ulBase + 0x00000020) & 0x00008000) {
    }
    CANRegWrite(ulBase + 0x00000020, iMsg);
  }
  CANRegWrite(ulBase + 0x00000024, 0x00000004 | 0x00000008);
  for (iMsg = 1; iMsg <= 32; iMsg++) {
    while (CANRegRead(ulBase + 0x00000020) & 0x00008000) {
    }
    CANRegWrite(ulBase + 0x00000020, iMsg);
  }
  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    %esi,%esi
call   1030 <CANRegWrite@plt>
mov    -0x8(%rbp),%rdi
add    $0x38,%rdi
xor    %esi,%esi
call   1030 <CANRegWrite@plt>
movl   $0x1,-0xc(%rbp)
cmpl   $0x20,-0xc(%rbp)
jg     11e2 <CANInit+0xc2>
jmp    11a4 <CANInit+0x84>
mov    -0x8(%rbp),%rdi
add    $0x20,%rdi
call   1040 <CANRegRead@plt>
and    $0x8000,%eax
cmp    $0x0,%eax
je     11c4 <CANInit+0xa4>
jmp    11a4 <CANInit+0x84>
mov    -0x8(%rbp),%rdi
add    $0x20,%rdi
mov    -0xc(%rbp),%esi
call   1030 <CANRegWrite@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1195 <CANInit+0x75>
mov    -0x8(%rbp),%rdi
add    $0x24,%rdi
mov    $0xc,%esi
call   1030 <CANRegWrite@plt>
movl   $0x1,-0xc(%rbp)
cmpl   $0x20,-0xc(%rbp)
jg     1248 <CANInit+0x128>
jmp    120a <CANInit+0xea>
mov    -0x8(%rbp),%rdi
add    $0x20,%rdi
call   1040 <CANRegRead@plt>
and    $0x8000,%eax
cmp    $0x0,%eax
je     122a <CANInit+0x10a>
jmp    120a <CANInit+0xea>
mov    -0x8(%rbp),%rdi
add    $0x20,%rdi
mov    -0xc(%rbp),%esi
call   1030 <CANRegWrite@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    11fb <CANInit+0xdb>
mov    -0x8(%rbp),%rdi
add    $0x4,%rdi
call   1040 <CANRegRead@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<CANInit>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
mov    $0x1,%esi
call   1030 <CANRegWrite@plt>
lea    0x20(%r14),%rbx
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1040 <CANRegRead@plt>
test   $0x8000,%eax
jne    1140 <CANInit+0x20>
lea    0x24(%r14),%r15
mov    %r15,%rdi
mov    $0xb0,%esi
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,%ebp
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1040 <CANRegRead@plt>
test   $0x8000,%eax
jne    1180 <CANInit+0x60>
mov    %rbx,%rdi
mov    %ebp,%esi
call   1030 <CANRegWrite@plt>
add    $0x1,%ebp
cmp    $0x21,%ebp
jne    1180 <CANInit+0x60>
mov    %r15,%rdi
mov    $0xc,%esi
call   1030 <CANRegWrite@plt>
mov    $0x1,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %rbx,%rdi
call   1040 <CANRegRead@plt>
test   $0x8000,%eax
jne    11c0 <CANInit+0xa0>
mov    %rbx,%rdi
mov    %ebp,%esi
call   1030 <CANRegWrite@plt>
add    $0x1,%ebp
cmp    $0x21,%ebp
jne    11c0 <CANInit+0xa0>
add    $0x4,%r14
mov    %r14,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <CANRegRead@plt>

LLVM IR (-O0):
define void @CANInit(i64 %0) {
%2 = alloca i64
%3 = alloca i32
store i64 %0, i64* %2
%4 = load i64, i64* %2
%5 = add i64 %4, 0
%6 = call i32 @CANRegWrite(i64 %5, i32 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, i32 176)
%18 = load i64, i64* %2
%19 = add i64 %18, 52
%20 = call i32 @CANRegWrite(i64 %19, i32 0)
%21 = load i64, i64* %2
%22 = add i64 %21, 56
%23 = call i32 @CANRegWrite(i64 %22, i32 0)
store i32 1, i32* %3
br label %24
24: ; preds = %40, %14
%25 = load i32, i32* %3
%26 = icmp sle i32 %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 i32, i32* %3
%39 = call i32 @CANRegWrite(i64 %37, i32 %38)
br label %40
40: ; preds = %35
%41 = load i32, i32* %3
%42 = add nsw i32 %41, 1
store i32 %42, i32* %3
br label %24
43: ; preds = %24
%44 = load i64, i64* %2
%45 = add i64 %44, 36
%46 = call i32 @CANRegWrite(i64 %45, i32 12)
store i32 1, i32* %3
br label %47
47: ; preds = %63, %43
%48 = load i32, i32* %3
%49 = icmp sle i32 %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 i32, i32* %3
%62 = call i32 @CANRegWrite(i64 %60, i32 %61)
br label %63
63: ; preds = %58
%64 = load i32, i32* %3
%65 = add nsw i32 %64, 1
store i32 %65, i32* %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, i32 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, i32 176)
%11 = add i64 %0, 52
%12 = tail call i32 @CANRegWrite(i64 %11, i32 0)
%13 = add i64 %0, 56
%14 = tail call i32 @CANRegWrite(i64 %13, i32 0)
br label %15
15: ; preds = %8, %21
%16 = phi i32 [ 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, i32 %16)
%23 = add nuw nsw i32 %16, 1
%24 = icmp eq i32 %23, 33
br i1 %24, label %25, label %15
25: ; preds = %21
%26 = tail call i32 @CANRegWrite(i64 %9, i32 12)
br label %27
27: ; preds = %25, %33
%28 = phi i32 [ 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, i32 %28)
%35 = add nuw nsw i32 %28, 1
%36 = icmp eq i32 %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
}