void CANMessageSetTx(unsigned long ulId, const unsigned char *pucData,
                     unsigned long ulSize) {
  unsigned short usCmdMaskReg;
  unsigned short usArbReg0, usArbReg1;
  unsigned short usMsgCtrl;
  unsigned short *pusData;
  while ((*((volatile unsigned long *)(0x40040000 + 0x00000020))) &
         0x00008000) {
  }
  usCmdMaskReg =
      (0x00000080 | 0x00000002 | 0x00000001 | 0x00000010 | 0x00000020);
  usArbReg0 = ulId & 0x0000FFFF;
  usArbReg1 =
      (((ulId >> 16) & 0x00001FFF) | (0x00002000 | 0x00008000 | 0x00004000));
  usMsgCtrl = (0x00000100 | 0x00000080 | (ulSize & 0x0000000F));
  pusData = (unsigned short *)pucData;
  (*((volatile unsigned long *)(0x40040000 + 0x0000003C))) = pusData[0];
  (*((volatile unsigned long *)(0x40040000 + 0x00000040))) = pusData[1];
  (*((volatile unsigned long *)(0x40040000 + 0x00000044))) = pusData[2];
  (*((volatile unsigned long *)(0x40040000 + 0x00000048))) = pusData[3];
  (*((volatile unsigned long *)(0x40040000 + 0x00000024))) = usCmdMaskReg;
  (*((volatile unsigned long *)(0x40040000 + 0x00000030))) = usArbReg0;
  (*((volatile unsigned long *)(0x40040000 + 0x00000034))) = usArbReg1;
  (*((volatile unsigned long *)(0x40040000 + 0x00000038))) = usMsgCtrl;
  (*((volatile unsigned long *)(0x40040000 + 0x00000020))) = (2) & 0x0000003F;
}


x86 assembly (clang, -O0):
<CANMessageSetTx>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    $0x40040020,%eax
mov    (%rax),%rax
and    $0x8000,%rax
cmp    $0x0,%rax
je     112d <CANMessageSetTx+0x2d>
jmp    1110 <CANMessageSetTx+0x10>
movw   $0xb3,-0x1a(%rbp)
mov    -0x8(%rbp),%rax
and    $0xffff,%rax
mov    %ax,-0x1c(%rbp)
mov    -0x8(%rbp),%rax
shr    $0x10,%rax
and    $0x1fff,%rax
or     $0xe000,%rax
mov    %ax,-0x1e(%rbp)
mov    -0x18(%rbp),%rax
and    $0xf,%rax
or     $0x180,%rax
mov    %ax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
movzwl (%rax),%eax
mov    %eax,%ecx
mov    $0x4004003c,%eax
mov    %rcx,(%rax)
mov    -0x28(%rbp),%rax
movzwl 0x2(%rax),%eax
mov    %eax,%ecx
mov    $0x40040040,%eax
mov    %rcx,(%rax)
mov    -0x28(%rbp),%rax
movzwl 0x4(%rax),%eax
mov    %eax,%ecx
mov    $0x40040044,%eax
mov    %rcx,(%rax)
mov    -0x28(%rbp),%rax
movzwl 0x6(%rax),%eax
mov    %eax,%ecx
mov    $0x40040048,%eax
mov    %rcx,(%rax)
movzwl -0x1a(%rbp),%eax
mov    %eax,%ecx
mov    $0x40040024,%eax
mov    %rcx,(%rax)
movzwl -0x1c(%rbp),%eax
mov    %eax,%ecx
mov    $0x40040030,%eax
mov    %rcx,(%rax)
movzwl -0x1e(%rbp),%eax
mov    %eax,%ecx
mov    $0x40040034,%eax
mov    %rcx,(%rax)
movzwl -0x20(%rbp),%eax
mov    %eax,%ecx
mov    $0x40040038,%eax
mov    %rcx,(%rax)
mov    $0x40040020,%eax
movq   $0x2,(%rax)
pop    %rbp
ret

x86 assembly (clang, -O2):
<CANMessageSetTx>:
testq  $0x8000,0x40040020
jne    1100 <CANMessageSetTx>
mov    %edi,%eax
shr    $0x10,%eax
and    $0xf,%edx
or     $0x180,%rdx
movzwl (%rsi),%ecx
mov    %rcx,0x4004003c
40
movzwl 0x2(%rsi),%ecx
mov    %rcx,0x40040040
40
movzwl 0x4(%rsi),%ecx
mov    %rcx,0x40040044
40
movzwl 0x6(%rsi),%ecx
mov    %rcx,0x40040048
40
movq   $0xb3,0x40040024
movzwl %di,%ecx
mov    %rcx,0x40040030
40
or     $0xe000,%rax
mov    %rax,0x40040034
40
mov    %rdx,0x40040038
40
movq   $0x2,0x40040020
ret

LLVM IR (-O0):
define void @CANMessageSetTx(i64 %0, i8* %1, i64 %2) {
%4 = alloca i64
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i16
%8 = alloca i16
%9 = alloca i16
%10 = alloca i16
%11 = alloca i16*
store i64 %0, i64* %4
store i8* %1, i8** %5
store i64 %2, i64* %6
br label %12
12: ; preds = %16, %3
%13 = load volatile i64, i64* inttoptr (i64 1074004000 to i64*)
%14 = and i64 %13, 32768
%15 = icmp ne i64 %14, 0
br i1 %15, label %16, label %17
16: ; preds = %12
br label %12
17: ; preds = %12
store i16 179, i16* %7
%18 = load i64, i64* %4
%19 = and i64 %18, 65535
%20 = trunc i64 %19 to i16
store i16 %20, i16* %8
%21 = load i64, i64* %4
%22 = lshr i64 %21, 16
%23 = and i64 %22, 8191
%24 = or i64 %23, 57344
%25 = trunc i64 %24 to i16
store i16 %25, i16* %9
%26 = load i64, i64* %6
%27 = and i64 %26, 15
%28 = or i64 384, %27
%29 = trunc i64 %28 to i16
store i16 %29, i16* %10
%30 = load i8*, i8** %5
%31 = bitcast i8* %30 to i16*
store i16* %31, i16** %11
%32 = load i16*, i16** %11
%33 = getelementptr inbounds i16, i16* %32, i64 0
%34 = load i16, i16* %33
%35 = zext i16 %34 to i64
store volatile i64 %35, i64* inttoptr (i64 1074004028 to i64*)
%36 = load i16*, i16** %11
%37 = getelementptr inbounds i16, i16* %36, i64 1
%38 = load i16, i16* %37
%39 = zext i16 %38 to i64
store volatile i64 %39, i64* inttoptr (i64 1074004032 to i64*)
%40 = load i16*, i16** %11
%41 = getelementptr inbounds i16, i16* %40, i64 2
%42 = load i16, i16* %41
%43 = zext i16 %42 to i64
store volatile i64 %43, i64* inttoptr (i64 1074004036 to i64*)
%44 = load i16*, i16** %11
%45 = getelementptr inbounds i16, i16* %44, i64 3
%46 = load i16, i16* %45
%47 = zext i16 %46 to i64
store volatile i64 %47, i64* inttoptr (i64 1074004040 to i64*)
%48 = load i16, i16* %7
%49 = zext i16 %48 to i64
store volatile i64 %49, i64* inttoptr (i64 1074004004 to i64*)
%50 = load i16, i16* %8
%51 = zext i16 %50 to i64
store volatile i64 %51, i64* inttoptr (i64 1074004016 to i64*)
%52 = load i16, i16* %9
%53 = zext i16 %52 to i64
store volatile i64 %53, i64* inttoptr (i64 1074004020 to i64*)
%54 = load i16, i16* %10
%55 = zext i16 %54 to i64
store volatile i64 %55, i64* inttoptr (i64 1074004024 to i64*)
store volatile i64 2, i64* inttoptr (i64 1074004000 to i64*)
ret void
}

LLVM IR (-O2):
define void @CANMessageSetTx(i64 %0, i8* nocapture %1, i64 %2) {
br label %4
4: ; preds = %4, %3
%5 = load volatile i64, i64* inttoptr (i64 1074004000 to i64*)
%6 = and i64 %5, 32768
%7 = icmp eq i64 %6, 0
br i1 %7, label %8, label %4
8: ; preds = %4
%9 = lshr i64 %0, 16
%10 = and i64 %2, 15
%11 = or i64 %10, 384
%12 = bitcast i8* %1 to i16*
%13 = load i16, i16* %12
%14 = zext i16 %13 to i64
store volatile i64 %14, i64* inttoptr (i64 1074004028 to i64*)
%15 = getelementptr inbounds i8, i8* %1, i64 2
%16 = bitcast i8* %15 to i16*
%17 = load i16, i16* %16
%18 = zext i16 %17 to i64
store volatile i64 %18, i64* inttoptr (i64 1074004032 to i64*)
%19 = getelementptr inbounds i8, i8* %1, i64 4
%20 = bitcast i8* %19 to i16*
%21 = load i16, i16* %20
%22 = zext i16 %21 to i64
store volatile i64 %22, i64* inttoptr (i64 1074004036 to i64*)
%23 = getelementptr inbounds i8, i8* %1, i64 6
%24 = bitcast i8* %23 to i16*
%25 = load i16, i16* %24
%26 = zext i16 %25 to i64
store volatile i64 %26, i64* inttoptr (i64 1074004040 to i64*)
store volatile i64 179, i64* inttoptr (i64 1074004004 to i64*)
%27 = and i64 %0, 65535
store volatile i64 %27, i64* inttoptr (i64 1074004016 to i64*)
%28 = and i64 %9, 8191
%29 = or i64 %28, 57344
store volatile i64 %29, i64* inttoptr (i64 1074004020 to i64*)
store volatile i64 %11, i64* inttoptr (i64 1074004024 to i64*)
store volatile i64 2, i64* inttoptr (i64 1074004000 to i64*)
ret void
}