#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 */
typedef int uint32_t;

/* Variables and functions */
char spi_tfer(char v) {
  while (*(volatile uint32_t *)0x1400000 & 0x2)
    ;
  *(volatile uint32_t *)(0x1400000 + 8) = v;
  *(volatile uint32_t *)0x1400000 |= 0x2;
  while (*(volatile uint32_t *)0x1400000 & 0x2)
    ;
  return (char)(*(volatile uint32_t *)(0x1400000 + 8) & 0xff);
}


x86 assembly (clang, -O0):
<spi_tfer>:
push   %rbp
mov    %rsp,%rbp
mov    %dil,%al
mov    %al,-0x1(%rbp)
mov    $0x1400000,%eax
mov    (%rax),%eax
and    $0x2,%eax
cmp    $0x0,%eax
je     1122 <spi_tfer+0x22>
jmp    110a <spi_tfer+0xa>
movsbl -0x1(%rbp),%ecx
mov    $0x1400008,%eax
mov    %ecx,(%rax)
mov    $0x1400000,%eax
mov    (%rax),%ecx
or     $0x2,%ecx
mov    $0x1400000,%eax
mov    %ecx,(%rax)
mov    $0x1400000,%eax
mov    (%rax),%eax
and    $0x2,%eax
cmp    $0x0,%eax
je     1156 <spi_tfer+0x56>
jmp    113e <spi_tfer+0x3e>
mov    $0x1400008,%eax
mov    (%rax),%eax
and    $0xff,%eax
movsbl %al,%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<spi_tfer>:
testl  $0x2,0x1400000
jne    1100 <spi_tfer>
movsbl %dil,%eax
mov    %eax,0x1400008
orl    $0x2,0x1400000
02
testl  $0x2,0x1400000
jne    1120 <spi_tfer+0x20>
mov    0x1400008,%eax
ret

LLVM IR (-O0):
define signext i8 @spi_tfer(i8 signext %0) {
%2 = alloca i8
store i8 %0, i8* %2
br label %3
3: ; preds = %7, %1
%4 = load volatile i32, i32* inttoptr (i64 20971520 to i32*)
%5 = and i32 %4, 2
%6 = icmp ne i32 %5, 0
br i1 %6, label %7, label %8
7: ; preds = %3
br label %3
8: ; preds = %3
%9 = load i8, i8* %2
%10 = sext i8 %9 to i32
store volatile i32 %10, i32* inttoptr (i64 20971528 to i32*)
%11 = load volatile i32, i32* inttoptr (i64 20971520 to i32*)
%12 = or i32 %11, 2
store volatile i32 %12, i32* inttoptr (i64 20971520 to i32*)
br label %13
13: ; preds = %17, %8
%14 = load volatile i32, i32* inttoptr (i64 20971520 to i32*)
%15 = and i32 %14, 2
%16 = icmp ne i32 %15, 0
br i1 %16, label %17, label %18
17: ; preds = %13
br label %13
18: ; preds = %13
%19 = load volatile i32, i32* inttoptr (i64 20971528 to i32*)
%20 = and i32 %19, 255
%21 = trunc i32 %20 to i8
ret i8 %21
}

LLVM IR (-O2):
define signext i8 @spi_tfer(i8 signext %0) {
br label %2
2: ; preds = %2, %1
%3 = load volatile i32, i32* inttoptr (i64 20971520 to i32*)
%4 = and i32 %3, 2
%5 = icmp eq i32 %4, 0
br i1 %5, label %6, label %2
6: ; preds = %2
%7 = sext i8 %0 to i32
store volatile i32 %7, i32* inttoptr (i64 20971528 to i32*)
%8 = load volatile i32, i32* inttoptr (i64 20971520 to i32*)
%9 = or i32 %8, 2
store volatile i32 %9, i32* inttoptr (i64 20971520 to i32*)
br label %10
10: ; preds = %10, %6
%11 = load volatile i32, i32* inttoptr (i64 20971520 to i32*)
%12 = and i32 %11, 2
%13 = icmp eq i32 %12, 0
br i1 %13, label %14, label %10
14: ; preds = %10
%15 = load volatile i32, i32* inttoptr (i64 20971528 to i32*)
%16 = trunc i32 %15 to i8
ret i8 %16
}