#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 UART_LSR;
unsigned char UART_LSR_THRE;
int UART_TX;
int /*<<< orphan*/ barrier();
void putc(int c) {
  unsigned char v, *base = ((unsigned char *)0xf0000be0);
  do {
    v = base[UART_LSR << 2];
    barrier();
  } while (!(v & UART_LSR_THRE));
  base[UART_TX << 2] = c;
}


x86 assembly (clang, -O0):
<putc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    $0xf0000be0,%eax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    0x2ea1(%rip),%rcx
mov    (%rcx),%ecx
shl    $0x2,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,1),%al
mov    %al,-0x5(%rbp)
mov    $0x0,%al
call   1030 <barrier@plt>
movzbl -0x5(%rbp),%eax
mov    0x2e91(%rip),%rcx
movzbl (%rcx),%ecx
and    %ecx,%eax
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    1124 <putc+0x14>
mov    -0x4(%rbp),%eax
mov    %al,%dl
mov    -0x10(%rbp),%rax
mov    0x2e84(%rip),%rcx
mov    (%rcx),%ecx
shl    $0x2,%ecx
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<putc>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %edi,%r14d
mov    $0xf0000be0,%r15d
mov    0x2ea8(%rip),%r12
mov    0x2eb1(%rip),%rbp
nop
mov    (%r12),%eax
shl    $0x2,%eax
cltq
movzbl (%r15,%rax,1),%ebx
xor    %eax,%eax
call   1030 <barrier@plt>
test   %bl,0x0(%rbp)
je     1130 <putc+0x20>
mov    0x2ea7(%rip),%rax
mov    (%rax),%eax
shl    $0x2,%eax
cltq
mov    %r14b,(%r15,%rax,1)
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@UART_LSR = global i32 0
@UART_LSR_THRE = global i8 0
@UART_TX = global i32 0
define void @putc(i32 %0) {
%2 = alloca i32
%3 = alloca i8
%4 = alloca i8*
store i32 %0, i32* %2
store i8* inttoptr (i64 4026534880 to i8*), i8** %4
br label %5
5: ; preds = %13, %1
%6 = load i8*, i8** %4
%7 = load i32, i32* @UART_LSR
%8 = shl i32 %7, 2
%9 = sext i32 %8 to i64
%10 = getelementptr inbounds i8, i8* %6, i64 %9
%11 = load i8, i8* %10
store i8 %11, i8* %3
%12 = call i32 (...) @barrier()
br label %13
13: ; preds = %5
%14 = load i8, i8* %3
%15 = zext i8 %14 to i32
%16 = load i8, i8* @UART_LSR_THRE
%17 = zext i8 %16 to i32
%18 = and i32 %15, %17
%19 = icmp ne i32 %18, 0
%20 = xor i1 %19, true
br i1 %20, label %5, label %21
21: ; preds = %13
%22 = load i32, i32* %2
%23 = trunc i32 %22 to i8
%24 = load i8*, i8** %4
%25 = load i32, i32* @UART_TX
%26 = shl i32 %25, 2
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds i8, i8* %24, i64 %27
store i8 %23, i8* %28
ret void
}

LLVM IR (-O2):
@UART_LSR = global i32 0
@UART_LSR_THRE = global i8 0
@UART_TX = global i32 0
define void @putc(i32 %0) {
br label %2
2: ; preds = %2, %1
%3 = load i32, i32* @UART_LSR
%4 = shl i32 %3, 2
%5 = sext i32 %4 to i64
%6 = getelementptr inbounds i8, i8* inttoptr (i64 4026534880 to i8*), i64 %5
%7 = load i8, i8* %6
%8 = tail call i32 (...) @barrier()
%9 = load i8, i8* @UART_LSR_THRE
%10 = and i8 %9, %7
%11 = icmp eq i8 %10, 0
br i1 %11, label %2, label %12
12: ; preds = %2
%13 = trunc i32 %0 to i8
%14 = load i32, i32* @UART_TX
%15 = shl i32 %14, 2
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds i8, i8* inttoptr (i64 4026534880 to i8*), i64 %16
store i8 %13, i8* %17
ret void
}