#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*/ outb(int, int);
int /*<<< orphan*/ serial_write_com(int, int /*<<< orphan*/);
void serial_init(void) {
  outb(0x3F8 + 1, 0x00);
  outb(0x3F8 + 3, 0x80);
  outb(0x3F8 + 0, 0x03);
  outb(0x3F8 + 1, 0x00);
  outb(0x3F8 + 3, 0x02);
  outb(0x3F8 + 2, 0xC7);
  outb(0x3F8 + 4, 0x0B);
  outb(0x2F8 + 1, 0x00);
  outb(0x2F8 + 3, 0x80);
  outb(0x2F8 + 0, 0x03);
  outb(0x2F8 + 1, 0x00);
  outb(0x2F8 + 3, 0x02);
  outb(0x2F8 + 2, 0xC7);
  outb(0x2F8 + 4, 0x0B);
  const char *msg = "-----------------------------------\n";
  while (*msg)
    serial_write_com(1, *msg++);
}


x86 assembly (clang, -O0):
<serial_init>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    $0x3f9,%edi
xor    %esi,%esi
call   1030 <outb@plt>
mov    $0x3fb,%edi
mov    $0x80,%esi
call   1030 <outb@plt>
mov    $0x3f8,%edi
mov    $0x3,%esi
call   1030 <outb@plt>
mov    $0x3f9,%edi
xor    %esi,%esi
call   1030 <outb@plt>
mov    $0x3fb,%edi
mov    $0x2,%esi
call   1030 <outb@plt>
mov    $0x3fa,%edi
mov    $0xc7,%esi
call   1030 <outb@plt>
mov    $0x3fc,%edi
mov    $0xb,%esi
call   1030 <outb@plt>
mov    $0x2f9,%edi
xor    %esi,%esi
call   1030 <outb@plt>
mov    $0x2fb,%edi
mov    $0x80,%esi
call   1030 <outb@plt>
mov    $0x2f8,%edi
mov    $0x3,%esi
call   1030 <outb@plt>
mov    $0x2f9,%edi
xor    %esi,%esi
call   1030 <outb@plt>
mov    $0x2fb,%edi
mov    $0x2,%esi
call   1030 <outb@plt>
mov    $0x2fa,%edi
mov    $0xc7,%esi
call   1030 <outb@plt>
mov    $0x2fc,%edi
mov    $0xb,%esi
call   1030 <outb@plt>
lea    0xe0b(%rip),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
cmpb   $0x0,(%rax)
je     1227 <serial_init+0x107>
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
movsbl (%rax),%esi
mov    $0x1,%edi
call   1040 <serial_write_com@plt>
jmp    11f9 <serial_init+0xd9>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<serial_init>:
push   %r14
push   %rbx
push   %rax
mov    $0x3f9,%edi
xor    %esi,%esi
call   1030 <outb@plt>
mov    $0x3fb,%edi
mov    $0x80,%esi
call   1030 <outb@plt>
mov    $0x3f8,%edi
mov    $0x3,%esi
call   1030 <outb@plt>
mov    $0x3f9,%edi
xor    %esi,%esi
call   1030 <outb@plt>
mov    $0x3fb,%edi
mov    $0x2,%esi
call   1030 <outb@plt>
mov    $0x3fa,%edi
mov    $0xc7,%esi
call   1030 <outb@plt>
mov    $0x3fc,%edi
mov    $0xb,%esi
call   1030 <outb@plt>
mov    $0x2f9,%edi
xor    %esi,%esi
call   1030 <outb@plt>
mov    $0x2fb,%edi
mov    $0x80,%esi
call   1030 <outb@plt>
mov    $0x2f8,%edi
mov    $0x3,%esi
call   1030 <outb@plt>
mov    $0x2f9,%edi
xor    %esi,%esi
call   1030 <outb@plt>
mov    $0x2fb,%edi
mov    $0x2,%esi
call   1030 <outb@plt>
mov    $0x2fa,%edi
mov    $0xc7,%esi
call   1030 <outb@plt>
mov    $0x2fc,%edi
mov    $0xb,%esi
call   1030 <outb@plt>
mov    $0x2d,%al
mov    $0x1,%ebx
lea    0xe08(%rip),%r14
nopl   0x0(%rax,%rax,1)
movsbl %al,%esi
mov    $0x1,%edi
call   1040 <serial_write_com@plt>
movzbl (%rbx,%r14,1),%eax
add    $0x1,%rbx
cmp    $0x25,%rbx
jne    1200 <serial_init+0xe0>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [37 x i8] c"-----------------------------------\0A\00"
define void @serial_init() {
%1 = alloca i8*
%2 = call i32 @outb(i32 1017, i32 0)
%3 = call i32 @outb(i32 1019, i32 128)
%4 = call i32 @outb(i32 1016, i32 3)
%5 = call i32 @outb(i32 1017, i32 0)
%6 = call i32 @outb(i32 1019, i32 2)
%7 = call i32 @outb(i32 1018, i32 199)
%8 = call i32 @outb(i32 1020, i32 11)
%9 = call i32 @outb(i32 761, i32 0)
%10 = call i32 @outb(i32 763, i32 128)
%11 = call i32 @outb(i32 760, i32 3)
%12 = call i32 @outb(i32 761, i32 0)
%13 = call i32 @outb(i32 763, i32 2)
%14 = call i32 @outb(i32 762, i32 199)
%15 = call i32 @outb(i32 764, i32 11)
store i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0), i8** %1
br label %16
16: ; preds = %20, %0
%17 = load i8*, i8** %1
%18 = load i8, i8* %17
%19 = icmp ne i8 %18, 0
br i1 %19, label %20, label %26
20: ; preds = %16
%21 = load i8*, i8** %1
%22 = getelementptr inbounds i8, i8* %21, i32 1
store i8* %22, i8** %1
%23 = load i8, i8* %21
%24 = sext i8 %23 to i32
%25 = call i32 @serial_write_com(i32 1, i32 %24)
br label %16
26: ; preds = %16
ret void
}

LLVM IR (-O2):
@.str = [37 x i8] c"-----------------------------------\0A\00"
define void @serial_init() {
%1 = tail call i32 @outb(i32 1017, i32 0)
%2 = tail call i32 @outb(i32 1019, i32 128)
%3 = tail call i32 @outb(i32 1016, i32 3)
%4 = tail call i32 @outb(i32 1017, i32 0)
%5 = tail call i32 @outb(i32 1019, i32 2)
%6 = tail call i32 @outb(i32 1018, i32 199)
%7 = tail call i32 @outb(i32 1020, i32 11)
%8 = tail call i32 @outb(i32 761, i32 0)
%9 = tail call i32 @outb(i32 763, i32 128)
%10 = tail call i32 @outb(i32 760, i32 3)
%11 = tail call i32 @outb(i32 761, i32 0)
%12 = tail call i32 @outb(i32 763, i32 2)
%13 = tail call i32 @outb(i32 762, i32 199)
%14 = tail call i32 @outb(i32 764, i32 11)
br label %15
15: ; preds = %0, %15
%16 = phi i8 [ 45, %0 ], [ %21, %15 ]
%17 = phi i8* [ getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0), %0 ], [ %18, %15 ]
%18 = getelementptr inbounds i8, i8* %17, i64 1
%19 = sext i8 %16 to i32
%20 = tail call i32 @serial_write_com(i32 1, i32 %19)
%21 = load i8, i8* %18
%22 = icmp eq i8* %18, getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 36)
br i1 %22, label %23, label %15
23: ; preds = %15
ret void
}