#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*/ SPI_wait(int);
unsigned int SPI_xfer(int channel, unsigned int data) {
  unsigned int rxData = 0;
  if (channel & 1) {
    (*((volatile unsigned short *)0xE0020008)) = data;
    SPI_wait(channel);
    rxData = (*((volatile unsigned short *)0xE0020008));
  }
  if (channel & 2) {
    (*((volatile unsigned short *)0xE0068008)) = data;
    while ((*((volatile unsigned char *)0xE006800C)) & (1 << 4))
      ;
    rxData = (*((volatile unsigned short *)0xE0068008));
  }
  return rxData;
}


x86 assembly (clang, -O0):
<SPI_xfer>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0x4(%rbp),%eax
and    $0x1,%eax
cmp    $0x0,%eax
je     1158 <SPI_xfer+0x48>
mov    -0x8(%rbp),%eax
mov    %ax,%cx
mov    $0xe0020008,%eax
mov    %cx,(%rax)
mov    -0x4(%rbp),%edi
call   1030 <SPI_wait@plt>
mov    $0xe0020008,%eax
mov    (%rax),%ax
movzwl %ax,%eax
mov    %eax,-0xc(%rbp)
mov    -0x4(%rbp),%eax
and    $0x2,%eax
cmp    $0x0,%eax
je     119e <SPI_xfer+0x8e>
mov    -0x8(%rbp),%eax
mov    %ax,%cx
mov    $0xe0068008,%eax
mov    %cx,(%rax)
mov    $0xe006800c,%eax
mov    (%rax),%al
movzbl %al,%eax
and    $0x10,%eax
cmp    $0x0,%eax
je     1190 <SPI_xfer+0x80>
jmp    1175 <SPI_xfer+0x65>
mov    $0xe0068008,%eax
mov    (%rax),%ax
movzwl %ax,%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<SPI_xfer>:
push   %rbp
push   %r14
push   %rbx
mov    %esi,%r14d
mov    %edi,%ebp
mov    $0xe0020008,%ebx
xor    %eax,%eax
test   $0x1,%bpl
je     1134 <SPI_xfer+0x24>
mov    %r14w,(%rbx)
mov    %ebp,%edi
call   1030 <SPI_wait@plt>
movzwl (%rbx),%eax
test   $0x2,%bpl
je     1160 <SPI_xfer+0x50>
mov    %r14w,0x48000(%rbx)
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
testb  $0x10,0x48004(%rbx)
jne    1150 <SPI_xfer+0x40>
movzwl 0x48000(%rbx),%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @SPI_xfer(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 %0, i32* %3
store i32 %1, i32* %4
store i32 0, i32* %5
%6 = load i32, i32* %3
%7 = and i32 %6, 1
%8 = icmp ne i32 %7, 0
br i1 %8, label %9, label %16
9: ; preds = %2
%10 = load i32, i32* %4
%11 = trunc i32 %10 to i16
store volatile i16 %11, i16* inttoptr (i64 3758227464 to i16*)
%12 = load i32, i32* %3
%13 = call i32 @SPI_wait(i32 %12)
%14 = load volatile i16, i16* inttoptr (i64 3758227464 to i16*)
%15 = zext i16 %14 to i32
store i32 %15, i32* %5
br label %16
16: ; preds = %9, %2
%17 = load i32, i32* %3
%18 = and i32 %17, 2
%19 = icmp ne i32 %18, 0
br i1 %19, label %20, label %32
20: ; preds = %16
%21 = load i32, i32* %4
%22 = trunc i32 %21 to i16
store volatile i16 %22, i16* inttoptr (i64 3758522376 to i16*)
br label %23
23: ; preds = %28, %20
%24 = load volatile i8, i8* inttoptr (i64 3758522380 to i8*)
%25 = zext i8 %24 to i32
%26 = and i32 %25, 16
%27 = icmp ne i32 %26, 0
br i1 %27, label %28, label %29
28: ; preds = %23
br label %23
29: ; preds = %23
%30 = load volatile i16, i16* inttoptr (i64 3758522376 to i16*)
%31 = zext i16 %30 to i32
store i32 %31, i32* %5
br label %32
32: ; preds = %29, %16
%33 = load i32, i32* %5
ret i32 %33
}

LLVM IR (-O2):
define i32 @SPI_xfer(i32 %0, i32 %1) {
%3 = and i32 %0, 1
%4 = icmp eq i32 %3, 0
br i1 %4, label %10, label %5
5: ; preds = %2
%6 = trunc i32 %1 to i16
store volatile i16 %6, i16* inttoptr (i64 3758227464 to i16*)
%7 = tail call i32 @SPI_wait(i32 %0)
%8 = load volatile i16, i16* inttoptr (i64 3758227464 to i16*)
%9 = zext i16 %8 to i32
br label %10
10: ; preds = %5, %2
%11 = phi i32 [ %9, %5 ], [ 0, %2 ]
%12 = and i32 %0, 2
%13 = icmp eq i32 %12, 0
br i1 %13, label %23, label %14
14: ; preds = %10
%15 = trunc i32 %1 to i16
store volatile i16 %15, i16* inttoptr (i64 3758522376 to i16*)
br label %16
16: ; preds = %16, %14
%17 = load volatile i8, i8* inttoptr (i64 3758522380 to i8*)
%18 = and i8 %17, 16
%19 = icmp eq i8 %18, 0
br i1 %19, label %20, label %16
20: ; preds = %16
%21 = load volatile i16, i16* inttoptr (i64 3758522376 to i16*)
%22 = zext i16 %21 to i32
br label %23
23: ; preds = %20, %10
%24 = phi i32 [ %22, %20 ], [ %11, %10 ]
ret i32 %24
}