#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 scalar_t__ uint32_t;

/* Variables and functions */
int read32(scalar_t__);
int /*<<< orphan*/ write32(scalar_t__, unsigned char);
int uart_putc(uint32_t base_address, unsigned char character) {
  uint32_t counter = 0;
  while (!(read32(base_address + 0x14) & (1 << 5)))
    if (counter++ > 1024)
      return 1;
  write32(base_address + 0x00, character);
  return 0;
}


x86 assembly (clang, -O0):
<uart_putc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %sil,%al
mov    %rdi,-0x10(%rbp)
mov    %al,-0x11(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
add    $0x14,%rdi
call   1040 <read32@plt>
and    $0x20,%eax
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    115f <uart_putc+0x3f>
jmp    118b <uart_putc+0x6b>
mov    -0x20(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x20(%rbp)
cmp    $0x400,%rax
jle    1186 <uart_putc+0x66>
movl   $0x1,-0x4(%rbp)
jmp    11a3 <uart_putc+0x83>
jmp    113a <uart_putc+0x1a>
mov    -0x10(%rbp),%rdi
add    $0x0,%rdi
movzbl -0x11(%rbp),%esi
call   1030 <write32@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<uart_putc>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %esi,%r14d
mov    %rdi,%r15
lea    0x14(%rdi),%rbp
mov    $0x402,%ebx
cs nopw 0x0(%rax,%rax,1)
mov    %rbp,%rdi
call   1040 <read32@plt>
test   $0x20,%al
jne    1159 <uart_putc+0x39>
add    $0xffffffffffffffff,%rbx
jne    1140 <uart_putc+0x20>
mov    $0x1,%eax
jmp    1167 <uart_putc+0x47>
movzbl %r14b,%esi
mov    %r15,%rdi
call   1030 <write32@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @uart_putc(i64 %0, i8 zeroext %1) {
%3 = alloca i32
%4 = alloca i64
%5 = alloca i8
%6 = alloca i64
store i64 %0, i64* %4
store i8 %1, i8* %5
store i64 0, i64* %6
br label %7
7: ; preds = %19, %2
%8 = load i64, i64* %4
%9 = add nsw i64 %8, 20
%10 = call i32 @read32(i64 %9)
%11 = and i32 %10, 32
%12 = icmp ne i32 %11, 0
%13 = xor i1 %12, true
br i1 %13, label %14, label %20
14: ; preds = %7
%15 = load i64, i64* %6
%16 = add nsw i64 %15, 1
store i64 %16, i64* %6
%17 = icmp sgt i64 %15, 1024
br i1 %17, label %18, label %19
18: ; preds = %14
store i32 1, i32* %3
br label %25
19: ; preds = %14
br label %7
20: ; preds = %7
%21 = load i64, i64* %4
%22 = add nsw i64 %21, 0
%23 = load i8, i8* %5
%24 = call i32 @write32(i64 %22, i8 zeroext %23)
store i32 0, i32* %3
br label %25
25: ; preds = %20, %18
%26 = load i32, i32* %3
ret i32 %26
}

LLVM IR (-O2):
define i32 @uart_putc(i64 %0, i8 zeroext %1) {
%3 = add nsw i64 %0, 20
br label %4
4: ; preds = %9, %2
%5 = phi i64 [ 0, %2 ], [ %10, %9 ]
%6 = tail call i32 @read32(i64 %3)
%7 = and i32 %6, 32
%8 = icmp eq i32 %7, 0
br i1 %8, label %9, label %12
9: ; preds = %4
%10 = add nuw nsw i64 %5, 1
%11 = icmp eq i64 %10, 1026
br i1 %11, label %14, label %4
12: ; preds = %4
%13 = tail call i32 @write32(i64 %0, i8 zeroext %1)
br label %14
14: ; preds = %9, %12
%15 = phi i32 [ 0, %12 ], [ 1, %9 ]
ret i32 %15
}