#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*/ interrupt_wait(unsigned int);
int /*<<< orphan*/ mkfifo(char *, int /*<<< orphan*/);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ read(int, char *, int);
void serialout(volatile unsigned int *uart, unsigned int intr) {
  int fd;
  char c;
  int doread = 1;
  mkfifo("/dev/tty0/out", 0);
  fd = open("/dev/tty0/out", 0);
  *(uart + 0x0E) |= 0x20;
  while (1) {
    if (doread)
      read(fd, &c, 1);
    doread = 0;
    if (!(*(uart + 0x06) & 0x20)) {
      *uart = c;
      doread = 1;
    }
    interrupt_wait(intr);
    *(uart + 0x11) = 0x20;
  }
}


x86 assembly (clang, -O0):
<serialout>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x1,-0x18(%rbp)
lea    0xea3(%rip),%rdi
xor    %esi,%esi
call   1040 <mkfifo@plt>
lea    0xe95(%rip),%rdi
xor    %esi,%esi
call   1050 <open@plt>
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    0x38(%rax),%ecx
or     $0x20,%ecx
mov    %ecx,0x38(%rax)
cmpl   $0x0,-0x18(%rbp)
je     119d <serialout+0x5d>
mov    -0x10(%rbp),%edi
lea    -0x11(%rbp),%rsi
mov    $0x1,%edx
call   1030 <read@plt>
movl   $0x0,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    0x18(%rax),%eax
and    $0x20,%eax
cmp    $0x0,%eax
jne    11c8 <serialout+0x88>
movsbl -0x11(%rbp),%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,(%rax)
movl   $0x1,-0x18(%rbp)
mov    -0xc(%rbp),%edi
call   1060 <interrupt_wait@plt>
mov    -0x8(%rbp),%rax
movl   $0x20,0x44(%rax)
jmp    1182 <serialout+0x42>

x86 assembly (clang, -O2):
<serialout>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %esi,%r12d
mov    %rdi,%rbx
lea    0xea7(%rip),%r14
mov    %r14,%rdi
xor    %esi,%esi
call   1040 <mkfifo@plt>
mov    %r14,%rdi
xor    %esi,%esi
call   1050 <open@plt>
orl    $0x20,0x38(%rbx)
mov    %eax,%r14d
mov    $0x1,%ebp
lea    0xf(%rsp),%r15
jmp    118f <serialout+0x4f>
mov    %r12d,%edi
call   1060 <interrupt_wait@plt>
movl   $0x20,0x44(%rbx)
test   %ebp,%ebp
je     11a3 <serialout+0x63>
mov    %r14d,%edi
mov    %r15,%rsi
mov    $0x1,%edx
call   1030 <read@plt>
xor    %ebp,%ebp
testl  $0x20,0x18(%rbx)
jne    1180 <serialout+0x40>
movsbl 0xf(%rsp),%eax
mov    %eax,(%rbx)
mov    $0x1,%ebp
jmp    1180 <serialout+0x40>

LLVM IR (-O0):
@.str = [14 x i8] c"/dev/tty0/out\00"
define void @serialout(i32* %0, i32 %1) {
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8
%7 = alloca i32
store i32* %0, i32** %3
store i32 %1, i32* %4
store i32 1, i32* %7
%8 = call i32 @mkfifo(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i32 0)
%9 = call i32 @open(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i32 0)
store i32 %9, i32* %5
%10 = load i32*, i32** %3
%11 = getelementptr inbounds i32, i32* %10, i64 14
%12 = load volatile i32, i32* %11
%13 = or i32 %12, 32
store volatile i32 %13, i32* %11
br label %14
14: ; preds = %2, %30
%15 = load i32, i32* %7
%16 = icmp ne i32 %15, 0
br i1 %16, label %17, label %20
17: ; preds = %14
%18 = load i32, i32* %5
%19 = call i32 @read(i32 %18, i8* %6, i32 1)
br label %20
20: ; preds = %17, %14
store i32 0, i32* %7
%21 = load i32*, i32** %3
%22 = getelementptr inbounds i32, i32* %21, i64 6
%23 = load volatile i32, i32* %22
%24 = and i32 %23, 32
%25 = icmp ne i32 %24, 0
br i1 %25, label %30, label %26
26: ; preds = %20
%27 = load i8, i8* %6
%28 = sext i8 %27 to i32
%29 = load i32*, i32** %3
store volatile i32 %28, i32* %29
store i32 1, i32* %7
br label %30
30: ; preds = %26, %20
%31 = load i32, i32* %4
%32 = call i32 @interrupt_wait(i32 %31)
%33 = load i32*, i32** %3
%34 = getelementptr inbounds i32, i32* %33, i64 17
store volatile i32 32, i32* %34
br label %14
}

LLVM IR (-O2):
@.str = [14 x i8] c"/dev/tty0/out\00"
define void @serialout(i32* %0, i32 %1) {
%3 = alloca i8
%4 = tail call i32 @mkfifo(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i32 0)
%5 = tail call i32 @open(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i32 0)
%6 = getelementptr inbounds i32, i32* %0, i64 14
%7 = load volatile i32, i32* %6
%8 = or i32 %7, 32
store volatile i32 %8, i32* %6
%9 = getelementptr inbounds i32, i32* %0, i64 6
%10 = getelementptr inbounds i32, i32* %0, i64 17
br label %11
11: ; preds = %23, %2
%12 = phi i32 [ 1, %2 ], [ %24, %23 ]
%13 = icmp eq i32 %12, 0
br i1 %13, label %16, label %14
14: ; preds = %11
%15 = call i32 @read(i32 %5, i8* %3, i32 1)
br label %16
16: ; preds = %14, %11
%17 = load volatile i32, i32* %9
%18 = and i32 %17, 32
%19 = icmp eq i32 %18, 0
br i1 %19, label %20, label %23
20: ; preds = %16
%21 = load i8, i8* %3
%22 = sext i8 %21 to i32
store volatile i32 %22, i32* %0
br label %23
23: ; preds = %20, %16
%24 = phi i32 [ 0, %16 ], [ 1, %20 ]
%25 = tail call i32 @interrupt_wait(i32 %1)
store volatile i32 32, i32* %10
br label %11
}