#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 inb(int);
int /*<<< orphan*/ outb(int, int);
void serial_init(void) {
  int status;
  int divisor, lcs;
  divisor = (115200 / (9600));
  lcs = ((((8) - 5) << 0) | (((0)) << 3) | (((1) - 1) << 2));
  outb((0x80 | lcs), ((0x3f8) + 0x03));
  outb((0xaa), ((0x3f8) + 0x00));
  if (inb((0x3f8) + 0x00) != 0xaa) {
    goto out;
  }
  outb((0x55), ((0x3f8) + 0x00));
  if (inb((0x3f8) + 0x00) != 0x55) {
    goto out;
  }
  outb((divisor & 0xff), ((0x3f8) + 0x00));
  if (inb((0x3f8) + 0x00) != (divisor & 0xff)) {
    goto out;
  }
  outb((0xaa), ((0x3f8) + 0x01));
  if (inb((0x3f8) + 0x01) != 0xaa) {
    goto out;
  }
  outb((0x55), ((0x3f8) + 0x01));
  if (inb((0x3f8) + 0x01) != 0x55) {
    goto out;
  }
  outb(((divisor >> 8) & 0xff), ((0x3f8) + 0x01));
  if (inb((0x3f8) + 0x01) != ((divisor >> 8) & 0xff)) {
    goto out;
  }
  outb((lcs), ((0x3f8) + 0x03));
  outb((0x0), ((0x3f8) + 0x01));
  outb((0x00), ((0x3f8) + 0x02));
  outb(((1 << 1)), ((0x3f8) + 0x04));
  do {
    (void)inb((0x3f8) + 0x00);
    status = inb((0x3f8) + 0x05);
  } while (status & 0x01);
out:
  return;
}


x86 assembly (clang, -O0):
<serial_init>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0xc,-0x8(%rbp)
movl   $0x3,-0xc(%rbp)
mov    -0xc(%rbp),%edi
or     $0x80,%edi
mov    $0x3fb,%esi
call   1030 <outb@plt>
mov    $0xaa,%edi
mov    $0x3f8,%esi
call   1030 <outb@plt>
mov    $0x3f8,%edi
call   1040 <inb@plt>
cmp    $0xaa,%eax
je     1172 <serial_init+0x52>
jmp    12b4 <serial_init+0x194>
mov    $0x55,%edi
mov    $0x3f8,%esi
call   1030 <outb@plt>
mov    $0x3f8,%edi
call   1040 <inb@plt>
cmp    $0x55,%eax
je     1199 <serial_init+0x79>
jmp    12b4 <serial_init+0x194>
mov    -0x8(%rbp),%edi
and    $0xff,%edi
mov    $0x3f8,%esi
call   1030 <outb@plt>
mov    $0x3f8,%edi
call   1040 <inb@plt>
mov    -0x8(%rbp),%ecx
and    $0xff,%ecx
cmp    %ecx,%eax
je     11cc <serial_init+0xac>
jmp    12b4 <serial_init+0x194>
mov    $0xaa,%edi
mov    $0x3f9,%esi
call   1030 <outb@plt>
mov    $0x3f9,%edi
call   1040 <inb@plt>
cmp    $0xaa,%eax
je     11f5 <serial_init+0xd5>
jmp    12b4 <serial_init+0x194>
mov    $0x55,%edi
mov    $0x3f9,%esi
call   1030 <outb@plt>
mov    $0x3f9,%edi
call   1040 <inb@plt>
cmp    $0x55,%eax
je     121c <serial_init+0xfc>
jmp    12b4 <serial_init+0x194>
mov    -0x8(%rbp),%edi
sar    $0x8,%edi
and    $0xff,%edi
mov    $0x3f9,%esi
call   1030 <outb@plt>
mov    $0x3f9,%edi
call   1040 <inb@plt>
mov    -0x8(%rbp),%ecx
sar    $0x8,%ecx
and    $0xff,%ecx
cmp    %ecx,%eax
je     1255 <serial_init+0x135>
jmp    12b4 <serial_init+0x194>
mov    -0xc(%rbp),%edi
mov    $0x3fb,%esi
call   1030 <outb@plt>
xor    %edi,%edi
mov    $0x3f9,%esi
call   1030 <outb@plt>
xor    %edi,%edi
mov    $0x3fa,%esi
call   1030 <outb@plt>
mov    $0x2,%edi
mov    $0x3fc,%esi
call   1030 <outb@plt>
mov    $0x3f8,%edi
call   1040 <inb@plt>
mov    $0x3fd,%edi
call   1040 <inb@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
and    $0x1,%eax
cmp    $0x0,%eax
jne    1289 <serial_init+0x169>
jmp    12b4 <serial_init+0x194>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<serial_init>:
push   %rax
mov    $0x83,%edi
mov    $0x3fb,%esi
call   1030 <outb@plt>
mov    $0xaa,%edi
mov    $0x3f8,%esi
call   1030 <outb@plt>
mov    $0x3f8,%edi
call   1040 <inb@plt>
cmp    $0xaa,%eax
jne    1248 <serial_init+0x128>
mov    $0x55,%edi
mov    $0x3f8,%esi
call   1030 <outb@plt>
mov    $0x3f8,%edi
call   1040 <inb@plt>
cmp    $0x55,%eax
jne    1248 <serial_init+0x128>
mov    $0xc,%edi
mov    $0x3f8,%esi
call   1030 <outb@plt>
mov    $0x3f8,%edi
call   1040 <inb@plt>
cmp    $0xc,%eax
jne    1248 <serial_init+0x128>
mov    $0xaa,%edi
mov    $0x3f9,%esi
call   1030 <outb@plt>
mov    $0x3f9,%edi
call   1040 <inb@plt>
cmp    $0xaa,%eax
jne    1248 <serial_init+0x128>
mov    $0x55,%edi
mov    $0x3f9,%esi
call   1030 <outb@plt>
mov    $0x3f9,%edi
call   1040 <inb@plt>
cmp    $0x55,%eax
jne    1248 <serial_init+0x128>
xor    %edi,%edi
mov    $0x3f9,%esi
call   1030 <outb@plt>
mov    $0x3f9,%edi
call   1040 <inb@plt>
test   %eax,%eax
jne    1248 <serial_init+0x128>
mov    $0x3,%edi
mov    $0x3fb,%esi
call   1030 <outb@plt>
xor    %edi,%edi
mov    $0x3f9,%esi
call   1030 <outb@plt>
xor    %edi,%edi
mov    $0x3fa,%esi
call   1030 <outb@plt>
mov    $0x2,%edi
mov    $0x3fc,%esi
call   1030 <outb@plt>
nopw   0x0(%rax,%rax,1)
mov    $0x3f8,%edi
call   1040 <inb@plt>
mov    $0x3fd,%edi
call   1040 <inb@plt>
test   $0x1,%al
jne    1230 <serial_init+0x110>
pop    %rax
ret

LLVM IR (-O0):
define void @serial_init() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
store i32 12, i32* %2
store i32 3, i32* %3
%4 = load i32, i32* %3
%5 = or i32 128, %4
%6 = call i32 @outb(i32 %5, i32 1019)
%7 = call i32 @outb(i32 170, i32 1016)
%8 = call i32 @inb(i32 1016)
%9 = icmp ne i32 %8, 170
br i1 %9, label %10, label %11
10: ; preds = %0
br label %60
11: ; preds = %0
%12 = call i32 @outb(i32 85, i32 1016)
%13 = call i32 @inb(i32 1016)
%14 = icmp ne i32 %13, 85
br i1 %14, label %15, label %16
15: ; preds = %11
br label %60
16: ; preds = %11
%17 = load i32, i32* %2
%18 = and i32 %17, 255
%19 = call i32 @outb(i32 %18, i32 1016)
%20 = call i32 @inb(i32 1016)
%21 = load i32, i32* %2
%22 = and i32 %21, 255
%23 = icmp ne i32 %20, %22
br i1 %23, label %24, label %25
24: ; preds = %16
br label %60
25: ; preds = %16
%26 = call i32 @outb(i32 170, i32 1017)
%27 = call i32 @inb(i32 1017)
%28 = icmp ne i32 %27, 170
br i1 %28, label %29, label %30
29: ; preds = %25
br label %60
30: ; preds = %25
%31 = call i32 @outb(i32 85, i32 1017)
%32 = call i32 @inb(i32 1017)
%33 = icmp ne i32 %32, 85
br i1 %33, label %34, label %35
34: ; preds = %30
br label %60
35: ; preds = %30
%36 = load i32, i32* %2
%37 = ashr i32 %36, 8
%38 = and i32 %37, 255
%39 = call i32 @outb(i32 %38, i32 1017)
%40 = call i32 @inb(i32 1017)
%41 = load i32, i32* %2
%42 = ashr i32 %41, 8
%43 = and i32 %42, 255
%44 = icmp ne i32 %40, %43
br i1 %44, label %45, label %46
45: ; preds = %35
br label %60
46: ; preds = %35
%47 = load i32, i32* %3
%48 = call i32 @outb(i32 %47, i32 1019)
%49 = call i32 @outb(i32 0, i32 1017)
%50 = call i32 @outb(i32 0, i32 1018)
%51 = call i32 @outb(i32 2, i32 1020)
br label %52
52: ; preds = %55, %46
%53 = call i32 @inb(i32 1016)
%54 = call i32 @inb(i32 1021)
store i32 %54, i32* %1
br label %55
55: ; preds = %52
%56 = load i32, i32* %1
%57 = and i32 %56, 1
%58 = icmp ne i32 %57, 0
br i1 %58, label %52, label %59
59: ; preds = %55
br label %60
60: ; preds = %59, %45, %34, %29, %24, %15, %10
ret void
}

LLVM IR (-O2):
define void @serial_init() {
%1 = tail call i32 @outb(i32 131, i32 1019)
%2 = tail call i32 @outb(i32 170, i32 1016)
%3 = tail call i32 @inb(i32 1016)
%4 = icmp eq i32 %3, 170
br i1 %4, label %5, label %35
5: ; preds = %0
%6 = tail call i32 @outb(i32 85, i32 1016)
%7 = tail call i32 @inb(i32 1016)
%8 = icmp eq i32 %7, 85
br i1 %8, label %9, label %35
9: ; preds = %5
%10 = tail call i32 @outb(i32 12, i32 1016)
%11 = tail call i32 @inb(i32 1016)
%12 = icmp eq i32 %11, 12
br i1 %12, label %13, label %35
13: ; preds = %9
%14 = tail call i32 @outb(i32 170, i32 1017)
%15 = tail call i32 @inb(i32 1017)
%16 = icmp eq i32 %15, 170
br i1 %16, label %17, label %35
17: ; preds = %13
%18 = tail call i32 @outb(i32 85, i32 1017)
%19 = tail call i32 @inb(i32 1017)
%20 = icmp eq i32 %19, 85
br i1 %20, label %21, label %35
21: ; preds = %17
%22 = tail call i32 @outb(i32 0, i32 1017)
%23 = tail call i32 @inb(i32 1017)
%24 = icmp eq i32 %23, 0
br i1 %24, label %25, label %35
25: ; preds = %21
%26 = tail call i32 @outb(i32 3, i32 1019)
%27 = tail call i32 @outb(i32 0, i32 1017)
%28 = tail call i32 @outb(i32 0, i32 1018)
%29 = tail call i32 @outb(i32 2, i32 1020)
br label %30
30: ; preds = %30, %25
%31 = tail call i32 @inb(i32 1016)
%32 = tail call i32 @inb(i32 1021)
%33 = and i32 %32, 1
%34 = icmp eq i32 %33, 0
br i1 %34, label %35, label %30
35: ; preds = %30, %21, %17, %13, %9, %5, %0
ret void
}