#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 */
void *SPISingleDataReadWrite(unsigned long, int);
void SPIDataRead(unsigned long ulBase, void *pulRData, unsigned long ulLen) {
  unsigned long i;

  ;
  for (i = 0; i < ulLen; i++) {
    if (((*((volatile unsigned long *)(ulBase + 0x00000000))) & 0x00000800) !=
        0x00000800) {
      ((unsigned char *)pulRData)[i] = SPISingleDataReadWrite(ulBase, 0xFF);
    } else {
      ((unsigned short *)pulRData)[i] = SPISingleDataReadWrite(ulBase, 0xFFFF);
    }
  }
}


x86 assembly (clang, -O0):
<SPIDataRead>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%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    11a6 <SPIDataRead+0x96>
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
and    $0x800,%rax
cmp    $0x800,%rax
je     1173 <SPIDataRead+0x63>
mov    -0x8(%rbp),%rdi
mov    $0xff,%esi
call   1030 <SPISingleDataReadWrite@plt>
mov    %al,%dl
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
jmp    1190 <SPIDataRead+0x80>
mov    -0x8(%rbp),%rdi
mov    $0xffff,%esi
call   1030 <SPISingleDataReadWrite@plt>
mov    %ax,%dx
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%rcx
mov    %dx,(%rax,%rcx,2)
jmp    1195 <SPIDataRead+0x85>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    112c <SPIDataRead+0x1c>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<SPIDataRead>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
test   %rdx,%rdx
je     1168 <SPIDataRead+0x58>
mov    %rdx,%r15
mov    %rsi,%r14
mov    %rdi,%r12
xor    %ebx,%ebx
jmp    114b <SPIDataRead+0x3b>
nopw   0x0(%rax,%rax,1)
mov    %r12,%rdi
mov    $0xffff,%esi
call   1030 <SPISingleDataReadWrite@plt>
mov    %ax,(%r14,%rbx,2)
add    $0x1,%rbx
cmp    %rbx,%r15
je     1168 <SPIDataRead+0x58>
testq  $0x800,(%r12)
jne    1130 <SPIDataRead+0x20>
mov    %r12,%rdi
mov    $0xff,%esi
call   1030 <SPISingleDataReadWrite@plt>
mov    %al,(%r14,%rbx,1)
jmp    1142 <SPIDataRead+0x32>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define void @SPIDataRead(i64 %0, i8* %1, i64 %2) {
%4 = alloca i64
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i64
store i64 %0, i64* %4
store i8* %1, i8** %5
store i64 %2, i64* %6
store i64 0, i64* %7
br label %8
8: ; preds = %35, %3
%9 = load i64, i64* %7
%10 = load i64, i64* %6
%11 = icmp ult i64 %9, %10
br i1 %11, label %12, label %38
12: ; preds = %8
%13 = load i64, i64* %4
%14 = add i64 %13, 0
%15 = inttoptr i64 %14 to i64*
%16 = load volatile i64, i64* %15
%17 = and i64 %16, 2048
%18 = icmp ne i64 %17, 2048
br i1 %18, label %19, label %26
19: ; preds = %12
%20 = load i64, i64* %4
%21 = call i8* @SPISingleDataReadWrite(i64 %20, i32 255)
%22 = ptrtoint i8* %21 to i8
%23 = load i8*, i8** %5
%24 = load i64, i64* %7
%25 = getelementptr inbounds i8, i8* %23, i64 %24
store i8 %22, i8* %25
br label %34
26: ; preds = %12
%27 = load i64, i64* %4
%28 = call i8* @SPISingleDataReadWrite(i64 %27, i32 65535)
%29 = ptrtoint i8* %28 to i16
%30 = load i8*, i8** %5
%31 = bitcast i8* %30 to i16*
%32 = load i64, i64* %7
%33 = getelementptr inbounds i16, i16* %31, i64 %32
store i16 %29, i16* %33
br label %34
34: ; preds = %26, %19
br label %35
35: ; preds = %34
%36 = load i64, i64* %7
%37 = add i64 %36, 1
store i64 %37, i64* %7
br label %8
38: ; preds = %8
ret void
}

LLVM IR (-O2):
define void @SPIDataRead(i64 %0, i8* nocapture writeonly %1, i64 %2) {
%4 = icmp eq i64 %2, 0
br i1 %4, label %26, label %5
5: ; preds = %3
%6 = inttoptr i64 %0 to i64*
%7 = bitcast i8* %1 to i16*
br label %8
8: ; preds = %5, %23
%9 = phi i64 [ 0, %5 ], [ %24, %23 ]
%10 = load volatile i64, i64* %6
%11 = and i64 %10, 2048
%12 = icmp eq i64 %11, 0
br i1 %12, label %13, label %18
13: ; preds = %8
%14 = tail call i8* @SPISingleDataReadWrite(i64 %0, i32 255)
%15 = ptrtoint i8* %14 to i64
%16 = trunc i64 %15 to i8
%17 = getelementptr inbounds i8, i8* %1, i64 %9
store i8 %16, i8* %17
br label %23
18: ; preds = %8
%19 = tail call i8* @SPISingleDataReadWrite(i64 %0, i32 65535)
%20 = ptrtoint i8* %19 to i64
%21 = trunc i64 %20 to i16
%22 = getelementptr inbounds i16, i16* %7, i64 %9
store i16 %21, i16* %22
br label %23
23: ; preds = %13, %18
%24 = add nuw i64 %9, 1
%25 = icmp eq i64 %24, %2
br i1 %25, label %26, label %8
26: ; preds = %23, %3
ret void
}