#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*/ SPISingleDataReadWrite(unsigned long, unsigned short);
void SPIDataWrite(unsigned long ulBase, void *pulWData, unsigned long ulLen) {
  unsigned long i;

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


x86 assembly (clang, -O0):
<SPIDataWrite>:
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    119b <SPIDataWrite+0x8b>
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
and    $0x800,%rax
cmp    $0x800,%rax
je     1170 <SPIDataWrite+0x60>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%rcx
movzbl (%rax,%rcx,1),%eax
movzwl %ax,%esi
call   1030 <SPISingleDataReadWrite@plt>
jmp    1185 <SPIDataWrite+0x75>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%rcx
movzwl (%rax,%rcx,2),%esi
call   1030 <SPISingleDataReadWrite@plt>
jmp    118a <SPIDataWrite+0x7a>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    112c <SPIDataWrite+0x1c>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<SPIDataWrite>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
test   %rdx,%rdx
je     115a <SPIDataWrite+0x4a>
mov    %rdx,%r15
mov    %rsi,%r14
mov    %rdi,%r12
xor    %ebx,%ebx
jmp    1149 <SPIDataWrite+0x39>
nopw   0x0(%rax,%rax,1)
movzwl (%r14,%rbx,2),%eax
movzwl %ax,%esi
mov    %r12,%rdi
call   1030 <SPISingleDataReadWrite@plt>
add    $0x1,%rbx
cmp    %rbx,%r15
je     115a <SPIDataWrite+0x4a>
testq  $0x800,(%r12)
jne    1130 <SPIDataWrite+0x20>
movzbl (%r14,%rbx,1),%eax
jmp    1135 <SPIDataWrite+0x25>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define void @SPIDataWrite(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 = %36, %3
%9 = load i64, i64* %7
%10 = load i64, i64* %6
%11 = icmp ult i64 %9, %10
br i1 %11, label %12, label %39
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 %27
19: ; preds = %12
%20 = load i64, i64* %4
%21 = load i8*, i8** %5
%22 = load i64, i64* %7
%23 = getelementptr inbounds i8, i8* %21, i64 %22
%24 = load i8, i8* %23
%25 = zext i8 %24 to i16
%26 = call i32 @SPISingleDataReadWrite(i64 %20, i16 zeroext %25)
br label %35
27: ; preds = %12
%28 = load i64, i64* %4
%29 = load i8*, i8** %5
%30 = bitcast i8* %29 to i16*
%31 = load i64, i64* %7
%32 = getelementptr inbounds i16, i16* %30, i64 %31
%33 = load i16, i16* %32
%34 = call i32 @SPISingleDataReadWrite(i64 %28, i16 zeroext %33)
br label %35
35: ; preds = %27, %19
br label %36
36: ; preds = %35
%37 = load i64, i64* %7
%38 = add i64 %37, 1
store i64 %38, i64* %7
br label %8
39: ; preds = %8
ret void
}

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