#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,
                    unsigned long ulSize) {
  unsigned long ulIdx, ulValue;
  for (ulIdx = 0; ulIdx < ulSize;) {
    ulValue = CANRegRead((unsigned long)(pulRegister++));
    pucData[ulIdx++] = (unsigned char)ulValue;
    if (ulIdx < ulSize) {
      pucData[ulIdx++] = (unsigned char)(ulValue >> 8);
    }
  }
}


x86 assembly (clang, -O0):
<CANDataRegRead>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmp    -0x18(%rbp),%rax
jae    11a1 <CANDataRegRead+0x91>
mov    -0x10(%rbp),%rdi
mov    %rdi,%rax
add    $0x8,%rax
mov    %rax,-0x10(%rbp)
call   1030 <CANRegRead@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    %al,%dl
mov    -0x8(%rbp),%rax
mov    -0x20(%rbp),%rcx
mov    %rcx,%rsi
add    $0x1,%rsi
mov    %rsi,-0x20(%rbp)
mov    %dl,(%rax,%rcx,1)
mov    -0x20(%rbp),%rax
cmp    -0x18(%rbp),%rax
jae    119c <CANDataRegRead+0x8c>
mov    -0x28(%rbp),%rax
shr    $0x8,%rax
mov    %al,%dl
mov    -0x8(%rbp),%rax
mov    -0x20(%rbp),%rcx
mov    %rcx,%rsi
add    $0x1,%rsi
mov    %rsi,-0x20(%rbp)
mov    %dl,(%rax,%rcx,1)
jmp    112c <CANDataRegRead+0x1c>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<CANDataRegRead>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
test   %rdx,%rdx
je     1164 <CANDataRegRead+0x54>
mov    %rdx,%r14
mov    %rsi,%rbx
mov    %rdi,%r15
xor    %ebp,%ebp
jmp    113c <CANDataRegRead+0x2c>
nopl   0x0(%rax)
add    $0x8,%rbx
mov    %rcx,%rbp
cmp    %r14,%rcx
jae    1164 <CANDataRegRead+0x54>
mov    %rbx,%rdi
call   1030 <CANRegRead@plt>
lea    0x1(%rbp),%rcx
mov    %r15,%rdx
mov    %al,(%r15,%rbp,1)
cmp    %r14,%rcx
jae    1130 <CANDataRegRead+0x20>
mov    %r15,%rcx
mov    %ah,0x1(%rcx,%rbp,1)
add    $0x2,%rbp
mov    %rbp,%rcx
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, i64 %2) {
%4 = alloca i8*
%5 = alloca i64*
%6 = alloca i64
%7 = alloca i64
%8 = alloca i64
store i8* %0, i8** %4
store i64* %1, i64** %5
store i64 %2, i64* %6
store i64 0, i64* %7
br label %9
9: ; preds = %35, %3
%10 = load i64, i64* %7
%11 = load i64, i64* %6
%12 = icmp ult i64 %10, %11
br i1 %12, label %13, label %36
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 i64, i64* %7
%22 = add i64 %21, 1
store i64 %22, i64* %7
%23 = getelementptr inbounds i8, i8* %20, i64 %21
store i8 %19, i8* %23
%24 = load i64, i64* %7
%25 = load i64, i64* %6
%26 = icmp ult i64 %24, %25
br i1 %26, label %27, label %35
27: ; preds = %13
%28 = load i64, i64* %8
%29 = lshr i64 %28, 8
%30 = trunc i64 %29 to i8
%31 = load i8*, i8** %4
%32 = load i64, i64* %7
%33 = add i64 %32, 1
store i64 %33, i64* %7
%34 = getelementptr inbounds i8, i8* %31, i64 %32
store i8 %30, i8* %34
br label %35
35: ; preds = %27, %13
br label %9
36: ; preds = %9
ret void
}

LLVM IR (-O2):
define void @CANDataRegRead(i8* nocapture writeonly %0, i64* %1, i64 %2) {
%4 = icmp eq i64 %2, 0
br i1 %4, label %23, label %5
5: ; preds = %3, %20
%6 = phi i64* [ %8, %20 ], [ %1, %3 ]
%7 = phi i64 [ %21, %20 ], [ 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 nuw i64 %7, 1
%13 = getelementptr inbounds i8, i8* %0, i64 %7
store i8 %11, i8* %13
%14 = icmp ult i64 %12, %2
br i1 %14, label %15, label %20
15: ; preds = %5
%16 = lshr i64 %10, 8
%17 = trunc i64 %16 to i8
%18 = add nuw i64 %7, 2
%19 = getelementptr inbounds i8, i8* %0, i64 %12
store i8 %17, i8* %19
br label %20
20: ; preds = %15, %5
%21 = phi i64 [ %18, %15 ], [ %12, %5 ]
%22 = icmp ult i64 %21, %2
br i1 %22, label %5, label %23
23: ; preds = %20, %3
ret void
}