#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 */
long SPITransfer16(unsigned long, unsigned short *, unsigned short *,
                   unsigned long, unsigned long);
long SPITransfer32(unsigned long, unsigned long *, unsigned long *,
                   unsigned long, unsigned long);
long SPITransfer8(unsigned long, unsigned char *, unsigned char *,
                  unsigned long, unsigned long);
long SPITransfer(unsigned long ulBase, unsigned char *ucDout,
                 unsigned char *ucDin, unsigned long ulCount,
                 unsigned long ulFlags) {
  unsigned long ulWordLength;
  long lRet;
  ulWordLength =
      ((*((volatile unsigned long *)(ulBase + 0x0000012C))) & 0x00000F80);
  if (!((ulWordLength == 0x00000380) || (ulWordLength == 0x00000780) ||
        (ulWordLength == 0x00000F80))) {
    return -1;
  }
  if (ulWordLength == 0x00000380) {
    lRet = SPITransfer8(ulBase, ucDout, ucDin, ulCount, ulFlags);
  } else if (ulWordLength == 0x00000780) {
    lRet = SPITransfer16(ulBase, (unsigned short *)ucDout,
                         (unsigned short *)ucDin, ulCount, ulFlags);
  } else {
    lRet = SPITransfer32(ulBase, (unsigned long *)ucDout,
                         (unsigned long *)ucDin, ulCount, ulFlags);
  }
  return lRet;
}


x86 assembly (clang, -O0):
<SPITransfer>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    %r8,-0x30(%rbp)
mov    -0x10(%rbp),%rax
mov    0x12c(%rax),%rax
and    $0xf80,%rax
mov    %rax,-0x38(%rbp)
cmpq   $0x380,-0x38(%rbp)
je     1198 <SPITransfer+0x68>
cmpq   $0x780,-0x38(%rbp)
je     1198 <SPITransfer+0x68>
cmpq   $0xf80,-0x38(%rbp)
je     1198 <SPITransfer+0x68>
movq   $0xffffffffffffffff,-0x8(%rbp)
ff
jmp    1222 <SPITransfer+0xf2>
cmpq   $0x380,-0x38(%rbp)
jne    11c8 <SPITransfer+0x98>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
mov    -0x28(%rbp),%rcx
mov    -0x30(%rbp),%r8
call   1050 <SPITransfer8@plt>
mov    %rax,-0x40(%rbp)
jmp    121a <SPITransfer+0xea>
cmpq   $0x780,-0x38(%rbp)
jne    11f8 <SPITransfer+0xc8>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
mov    -0x28(%rbp),%rcx
mov    -0x30(%rbp),%r8
call   1040 <SPITransfer16@plt>
mov    %rax,-0x40(%rbp)
jmp    1215 <SPITransfer+0xe5>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
mov    -0x28(%rbp),%rcx
mov    -0x30(%rbp),%r8
call   1030 <SPITransfer32@plt>
mov    %rax,-0x40(%rbp)
jmp    121a <SPITransfer+0xea>
mov    -0x40(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<SPITransfer>:
mov    0x12c(%rdi),%rax
mov    %eax,%r9d
and    $0xf80,%r9d
and    $0xb80,%eax
cmp    $0x380,%eax
je     115e <SPITransfer+0x2e>
cmp    $0xf80,%r9d
je     115e <SPITransfer+0x2e>
mov    $0xffffffffffffffff,%rax
ret
cmp    $0x780,%r9d
je     1175 <SPITransfer+0x45>
cmp    $0x380,%r9d
jne    117a <SPITransfer+0x4a>
jmp    1050 <SPITransfer8@plt>
jmp    1040 <SPITransfer16@plt>
jmp    1030 <SPITransfer32@plt>

LLVM IR (-O0):
define i64 @SPITransfer(i64 %0, i8* %1, i8* %2, i64 %3, i64 %4) {
%6 = alloca i64
%7 = alloca i64
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i64
%11 = alloca i64
%12 = alloca i64
%13 = alloca i64
store i64 %0, i64* %7
store i8* %1, i8** %8
store i8* %2, i8** %9
store i64 %3, i64* %10
store i64 %4, i64* %11
%14 = load i64, i64* %7
%15 = add i64 %14, 300
%16 = inttoptr i64 %15 to i64*
%17 = load volatile i64, i64* %16
%18 = and i64 %17, 3968
store i64 %18, i64* %12
%19 = load i64, i64* %12
%20 = icmp eq i64 %19, 896
br i1 %20, label %28, label %21
21: ; preds = %5
%22 = load i64, i64* %12
%23 = icmp eq i64 %22, 1920
br i1 %23, label %28, label %24
24: ; preds = %21
%25 = load i64, i64* %12
%26 = icmp eq i64 %25, 3968
br i1 %26, label %28, label %27
27: ; preds = %24
store i64 -1, i64* %6
br label %62
28: ; preds = %24, %21, %5
%29 = load i64, i64* %12
%30 = icmp eq i64 %29, 896
br i1 %30, label %31, label %38
31: ; preds = %28
%32 = load i64, i64* %7
%33 = load i8*, i8** %8
%34 = load i8*, i8** %9
%35 = load i64, i64* %10
%36 = load i64, i64* %11
%37 = call i64 @SPITransfer8(i64 %32, i8* %33, i8* %34, i64 %35, i64 %36)
store i64 %37, i64* %13
br label %60
38: ; preds = %28
%39 = load i64, i64* %12
%40 = icmp eq i64 %39, 1920
br i1 %40, label %41, label %50
41: ; preds = %38
%42 = load i64, i64* %7
%43 = load i8*, i8** %8
%44 = bitcast i8* %43 to i16*
%45 = load i8*, i8** %9
%46 = bitcast i8* %45 to i16*
%47 = load i64, i64* %10
%48 = load i64, i64* %11
%49 = call i64 @SPITransfer16(i64 %42, i16* %44, i16* %46, i64 %47, i64 %48)
store i64 %49, i64* %13
br label %59
50: ; preds = %38
%51 = load i64, i64* %7
%52 = load i8*, i8** %8
%53 = bitcast i8* %52 to i64*
%54 = load i8*, i8** %9
%55 = bitcast i8* %54 to i64*
%56 = load i64, i64* %10
%57 = load i64, i64* %11
%58 = call i64 @SPITransfer32(i64 %51, i64* %53, i64* %55, i64 %56, i64 %57)
store i64 %58, i64* %13
br label %59
59: ; preds = %50, %41
br label %60
60: ; preds = %59, %31
%61 = load i64, i64* %13
store i64 %61, i64* %6
br label %62
62: ; preds = %60, %27
%63 = load i64, i64* %6
ret i64 %63
}

LLVM IR (-O2):
define i64 @SPITransfer(i64 %0, i8* %1, i8* %2, i64 %3, i64 %4) {
%6 = add i64 %0, 300
%7 = inttoptr i64 %6 to i64*
%8 = load volatile i64, i64* %7
%9 = and i64 %8, 3968
%10 = and i64 %8, 2944
%11 = icmp eq i64 %10, 896
%12 = icmp eq i64 %9, 3968
%13 = or i1 %11, %12
br i1 %13, label %14, label %25
14: ; preds = %5
switch i64 %9, label %21 [
i64 896, label %15
i64 1920, label %17
]
15: ; preds = %14
%16 = tail call i64 @SPITransfer8(i64 %0, i8* %1, i8* %2, i64 %3, i64 %4)
br label %25
17: ; preds = %14
%18 = bitcast i8* %1 to i16*
%19 = bitcast i8* %2 to i16*
%20 = tail call i64 @SPITransfer16(i64 %0, i16* %18, i16* %19, i64 %3, i64 %4)
br label %25
21: ; preds = %14
%22 = bitcast i8* %1 to i64*
%23 = bitcast i8* %2 to i64*
%24 = tail call i64 @SPITransfer32(i64 %0, i64* %22, i64* %23, i64 %3, i64 %4)
br label %25
25: ; preds = %15, %21, %17, %5
%26 = phi i64 [ -1, %5 ], [ %16, %15 ], [ %20, %17 ], [ %24, %21 ]
ret i64 %26
}