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


x86 assembly (clang, -O0):
<CANDataRegRead>:
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    1199 <CANDataRegRead+0x89>
mov    -0x10(%rbp),%rdi
mov    %rdi,%rax
add    $0x8,%rax
mov    %rax,-0x10(%rbp)
call   1030 <CANRegRead@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    %al,%dl
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0x18(%rbp)
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1194 <CANDataRegRead+0x84>
mov    -0x20(%rbp),%rax
shr    $0x8,%rax
mov    %al,%dl
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0x18(%rbp)
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
jmp    112a <CANDataRegRead+0x1a>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<CANDataRegRead>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
test   %edx,%edx
jle    1163 <CANDataRegRead+0x53>
mov    %edx,%r14d
mov    %rsi,%rbx
mov    %rdi,%r15
xor    %ebp,%ebp
jmp    113b <CANDataRegRead+0x2b>
nopl   0x0(%rax,%rax,1)
add    $0x8,%rbx
mov    %ecx,%ebp
cmp    %r14d,%ecx
jge    1163 <CANDataRegRead+0x53>
mov    %rbx,%rdi
call   1030 <CANRegRead@plt>
movslq %ebp,%rcx
mov    %r15,%rdx
mov    %al,(%r15,%rcx,1)
add    $0x1,%rcx
cmp    %r14d,%ecx
jge    1130 <CANDataRegRead+0x20>
add    $0x2,%ebp
mov    %r15,%rdx
mov    %ah,(%rdx,%rcx,1)
mov    %ebp,%ecx
jmp    1130 <CANDataRegRead+0x20>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @CANDataRegRead(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 = %37, %3
%10 = load i32, i32* %7
%11 = load i32, i32* %6
%12 = icmp slt i32 %10, %11
br i1 %12, label %13, label %38
13: ; preds = %9
%14 = load i64*, i64** %5
%15 = getelementptr inbounds i64, i64* %14, i32 1
store i64* %15, i64** %5
%16 = ptrtoint i64* %14 to i64
%17 = call i64 @CANRegRead(i64 %16)
store i64 %17, i64* %8
%18 = load i64, i64* %8
%19 = trunc i64 %18 to i8
%20 = load i8*, i8** %4
%21 = load i32, i32* %7
%22 = add nsw i32 %21, 1
store i32 %22, i32* %7
%23 = sext i32 %21 to i64
%24 = getelementptr inbounds i8, i8* %20, i64 %23
store i8 %19, i8* %24
%25 = load i32, i32* %7
%26 = load i32, i32* %6
%27 = icmp slt i32 %25, %26
br i1 %27, label %28, label %37
28: ; preds = %13
%29 = load i64, i64* %8
%30 = lshr i64 %29, 8
%31 = trunc i64 %30 to i8
%32 = load i8*, i8** %4
%33 = load i32, i32* %7
%34 = add nsw i32 %33, 1
store i32 %34, i32* %7
%35 = sext i32 %33 to i64
%36 = getelementptr inbounds i8, i8* %32, i64 %35
store i8 %31, i8* %36
br label %37
37: ; preds = %28, %13
br label %9
38: ; preds = %9
ret void
}

LLVM IR (-O2):
define void @CANDataRegRead(i8* nocapture writeonly %0, i64* %1, i32 %2) {
%4 = icmp sgt i32 %2, 0
br i1 %4, label %5, label %25
5: ; preds = %3, %22
%6 = phi i64* [ %8, %22 ], [ %1, %3 ]
%7 = phi i32 [ %23, %22 ], [ 0, %3 ]
%8 = getelementptr inbounds i64, i64* %6, i64 1
%9 = ptrtoint i64* %6 to i64
%10 = tail call i64 @CANRegRead(i64 %9)
%11 = trunc i64 %10 to i8
%12 = add nsw i32 %7, 1
%13 = sext i32 %7 to i64
%14 = getelementptr inbounds i8, i8* %0, i64 %13
store i8 %11, i8* %14
%15 = icmp slt i32 %12, %2
br i1 %15, label %16, label %22
16: ; preds = %5
%17 = lshr i64 %10, 8
%18 = trunc i64 %17 to i8
%19 = add nsw i32 %7, 2
%20 = sext i32 %12 to i64
%21 = getelementptr inbounds i8, i8* %0, i64 %20
store i8 %18, i8* %21
br label %22
22: ; preds = %16, %5
%23 = phi i32 [ %19, %16 ], [ %12, %5 ]
%24 = icmp slt i32 %23, %2
br i1 %24, label %5, label %25
25: ; preds = %22, %3
ret void
}