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


x86 assembly (clang, -O0):
<serialin>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
lea    0xeaa(%rip),%rdi
xor    %esi,%esi
call   1040 <mkfifo@plt>
lea    0xe9c(%rip),%rdi
xor    %esi,%esi
call   1050 <open@plt>
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    0x38(%rax),%ecx
or     $0x10,%ecx
mov    %ecx,0x38(%rax)
mov    -0xc(%rbp),%edi
call   1060 <interrupt_wait@plt>
mov    -0x8(%rbp),%rax
movl   $0x10,0x44(%rax)
mov    -0x8(%rbp),%rax
mov    0x18(%rax),%eax
and    $0x10,%eax
cmp    $0x0,%eax
jne    11bb <serialin+0x7b>
mov    -0x8(%rbp),%rax
mov    (%rax),%eax
mov    %al,-0x11(%rbp)
mov    -0x10(%rbp),%edi
lea    -0x11(%rbp),%rsi
mov    $0x1,%edx
call   1030 <write@plt>
jmp    117b <serialin+0x3b>

x86 assembly (clang, -O2):
<serialin>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %esi,%ebp
mov    %rdi,%rbx
lea    0xead(%rip),%r14
mov    %r14,%rdi
xor    %esi,%esi
call   1040 <mkfifo@plt>
mov    %r14,%rdi
xor    %esi,%esi
call   1050 <open@plt>
mov    %eax,%r14d
orl    $0x10,0x38(%rbx)
lea    0x7(%rsp),%r15
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %ebp,%edi
call   1060 <interrupt_wait@plt>
movl   $0x10,0x44(%rbx)
testl  $0x10,0x18(%rbx)
jne    1180 <serialin+0x40>
mov    (%rbx),%eax
mov    %al,0x7(%rsp)
mov    %r14d,%edi
mov    %r15,%rsi
mov    $0x1,%edx
call   1030 <write@plt>
jmp    1180 <serialin+0x40>

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

LLVM IR (-O2):
@.str = [13 x i8] c"/dev/tty0/in\00"
define void @serialin(i32* %0, i32 %1) {
%3 = alloca i8
%4 = tail call i32 @mkfifo(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 0)
%5 = tail call i32 @open(i8* getelementptr inbounds ([13 x i8], [13 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, 16
store volatile i32 %8, i32* %6
%9 = getelementptr inbounds i32, i32* %0, i64 17
%10 = getelementptr inbounds i32, i32* %0, i64 6
br label %11
11: ; preds = %20, %2
%12 = tail call i32 @interrupt_wait(i32 %1)
store volatile i32 16, i32* %9
%13 = load volatile i32, i32* %10
%14 = and i32 %13, 16
%15 = icmp eq i32 %14, 0
br i1 %15, label %16, label %20
16: ; preds = %11
%17 = load volatile i32, i32* %0
%18 = trunc i32 %17 to i8
store i8 %18, i8* %3
%19 = call i32 @write(i32 %5, i8* %3, i32 1)
br label %20
20: ; preds = %16, %11
br label %11
}