#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 /*<<< orphan*/ CANRegWrite(unsigned long, unsigned long);
void CANDataRegWrite(unsigned char *pucData, unsigned long *pulRegister,
                     int iSize) {
  int iIdx;
  unsigned long ulValue;
  for (iIdx = 0; iIdx < iSize;) {
    ulValue = pucData[iIdx++];
    if (iIdx < iSize) {
      ulValue |= (pucData[iIdx++] << 8);
    }
    CANRegWrite((unsigned long)(pulRegister++), ulValue);
  }
}


x86 assembly (clang, -O0):
<CANDataRegWrite>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    119c <CANDataRegWrite+0x8c>
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%ecx
mov    %ecx,%edx
add    $0x1,%edx
mov    %edx,-0x18(%rbp)
movslq %ecx,%rcx
movzbl (%rax,%rcx,1),%eax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    117f <CANDataRegWrite+0x6f>
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%ecx
mov    %ecx,%edx
add    $0x1,%edx
mov    %edx,-0x18(%rbp)
movslq %ecx,%rcx
movzbl (%rax,%rcx,1),%eax
shl    $0x8,%eax
cltq
or     -0x20(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    %rdi,%rax
add    $0x8,%rax
mov    %rax,-0x10(%rbp)
mov    -0x20(%rbp),%rsi
call   1030 <CANRegWrite@plt>
jmp    112a <CANDataRegWrite+0x1a>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<CANDataRegWrite>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
test   %edx,%edx
jle    1167 <CANDataRegWrite+0x57>
mov    %edx,%r15d
mov    %rsi,%rbx
mov    %rdi,%r14
xor    %eax,%eax
jmp    1143 <CANDataRegWrite+0x33>
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1030 <CANRegWrite@plt>
add    $0x8,%rbx
mov    %ebp,%eax
cmp    %r15d,%ebp
jge    1167 <CANDataRegWrite+0x57>
movslq %eax,%rbp
movzbl (%r14,%rbp,1),%esi
add    $0x1,%rbp
cmp    %r15d,%ebp
jge    1130 <CANDataRegWrite+0x20>
add    $0x2,%eax
movzbl (%r14,%rbp,1),%ecx
shl    $0x8,%rcx
or     %rcx,%rsi
mov    %eax,%ebp
jmp    1130 <CANDataRegWrite+0x20>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @CANDataRegWrite(i8* %0, i64* %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i64*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i64
store i8* %0, i8** %4
store i64* %1, i64** %5
store i32 %2, i32* %6
store i32 0, i32* %7
br label %9
9: ; preds = %36, %3
%10 = load i32, i32* %7
%11 = load i32, i32* %6
%12 = icmp slt i32 %10, %11
br i1 %12, label %13, label %42
13: ; preds = %9
%14 = load i8*, i8** %4
%15 = load i32, i32* %7
%16 = add nsw i32 %15, 1
store i32 %16, i32* %7
%17 = sext i32 %15 to i64
%18 = getelementptr inbounds i8, i8* %14, i64 %17
%19 = load i8, i8* %18
%20 = zext i8 %19 to i64
store i64 %20, i64* %8
%21 = load i32, i32* %7
%22 = load i32, i32* %6
%23 = icmp slt i32 %21, %22
br i1 %23, label %24, label %36
24: ; preds = %13
%25 = load i8*, i8** %4
%26 = load i32, i32* %7
%27 = add nsw i32 %26, 1
store i32 %27, i32* %7
%28 = sext i32 %26 to i64
%29 = getelementptr inbounds i8, i8* %25, i64 %28
%30 = load i8, i8* %29
%31 = zext i8 %30 to i32
%32 = shl i32 %31, 8
%33 = sext i32 %32 to i64
%34 = load i64, i64* %8
%35 = or i64 %34, %33
store i64 %35, i64* %8
br label %36
36: ; preds = %24, %13
%37 = load i64*, i64** %5
%38 = getelementptr inbounds i64, i64* %37, i32 1
store i64* %38, i64** %5
%39 = ptrtoint i64* %37 to i64
%40 = load i64, i64* %8
%41 = call i32 @CANRegWrite(i64 %39, i64 %40)
br label %9
42: ; preds = %9
ret void
}

LLVM IR (-O2):
define void @CANDataRegWrite(i8* nocapture %0, i64* %1, i32 %2) {
%4 = icmp sgt i32 %2, 0
br i1 %4, label %5, label %29
5: ; preds = %3, %22
%6 = phi i32 [ %23, %22 ], [ 0, %3 ]
%7 = phi i64* [ %25, %22 ], [ %1, %3 ]
%8 = add nsw i32 %6, 1
%9 = sext i32 %6 to i64
%10 = getelementptr inbounds i8, i8* %0, i64 %9
%11 = load i8, i8* %10
%12 = zext i8 %11 to i64
%13 = icmp slt i32 %8, %2
br i1 %13, label %14, label %22
14: ; preds = %5
%15 = add nsw i32 %6, 2
%16 = sext i32 %8 to i64
%17 = getelementptr inbounds i8, i8* %0, i64 %16
%18 = load i8, i8* %17
%19 = zext i8 %18 to i64
%20 = shl nuw nsw i64 %19, 8
%21 = or i64 %20, %12
br label %22
22: ; preds = %14, %5
%23 = phi i32 [ %15, %14 ], [ %8, %5 ]
%24 = phi i64 [ %21, %14 ], [ %12, %5 ]
%25 = getelementptr inbounds i64, i64* %7, i64 1
%26 = ptrtoint i64* %7 to i64
%27 = tail call i32 @CANRegWrite(i64 %26, i64 %24)
%28 = icmp slt i32 %23, %2
br i1 %28, label %5, label %29
29: ; preds = %22, %3
ret void
}