#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, char);
void serialputc(char c) {
  static int serialinit = 0;
  if (!serialinit) {
    outb(0x3F9, 0x00);
    outb(0x3FB, 0x80);
    outb(0x3F8, 0x03);
    outb(0x3F9, 0x00);
    outb(0x3FB, 0x03);
    outb(0x3FA, 0xC7);
    outb(0x3FC, 0x0B);
    serialinit = 1;
    serialputc('\n');
  }
  while ((inb(0x3FD) & 0x20) == 0)
    ;
  if (c == '\n')
    outb(0x3F8, '\r');
  outb(0x3F8, c);
}


x86 assembly (clang, -O0):
<serialputc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %dil,%al
mov    %al,-0x1(%rbp)
cmpl   $0x0,0x2ef7(%rip)
jne    11c2 <serialputc+0x92>
mov    $0x3f9,%edi
xor    %esi,%esi
call   1040 <outb@plt>
mov    $0x3fb,%edi
mov    $0xffffff80,%esi
call   1040 <outb@plt>
mov    $0x3f8,%edi
mov    $0x3,%esi
call   1040 <outb@plt>
mov    $0x3f9,%edi
xor    %esi,%esi
call   1040 <outb@plt>
mov    $0x3fb,%edi
mov    $0x3,%esi
call   1040 <outb@plt>
mov    $0x3fa,%edi
mov    $0xffffffc7,%esi
call   1040 <outb@plt>
mov    $0x3fc,%edi
mov    $0xb,%esi
call   1040 <outb@plt>
movl   $0x1,0x2e84(%rip)
mov    $0xa,%edi
call   1030 <serialputc@plt>
jmp    11c7 <serialputc+0x97>
mov    $0x3fd,%edi
call   1050 <inb@plt>
and    $0x20,%eax
cmp    $0x0,%eax
jne    11e2 <serialputc+0xb2>
jmp    11c7 <serialputc+0x97>
movsbl -0x1(%rbp),%eax
cmp    $0xa,%eax
jne    11fe <serialputc+0xce>
mov    $0x3f8,%edi
mov    $0xd,%esi
call   1040 <outb@plt>
mov    $0x3f8,%edi
movsbl -0x1(%rbp),%esi
call   1040 <outb@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<serialputc>:
push   %rbx
mov    %edi,%ebx
cmpb   $0x0,0x2f02(%rip)
jne    11b0 <serialputc+0x80>
mov    $0x3f9,%edi
xor    %esi,%esi
call   1040 <outb@plt>
mov    $0x3fb,%edi
mov    $0xffffff80,%esi
call   1040 <outb@plt>
mov    $0x3f8,%edi
mov    $0x3,%esi
call   1040 <outb@plt>
mov    $0x3f9,%edi
xor    %esi,%esi
call   1040 <outb@plt>
mov    $0x3fb,%edi
mov    $0x3,%esi
call   1040 <outb@plt>
mov    $0x3fa,%edi
mov    $0xffffffc7,%esi
call   1040 <outb@plt>
mov    $0x3fc,%edi
mov    $0xb,%esi
call   1040 <outb@plt>
movb   $0x1,0x2e96(%rip)
mov    $0xa,%edi
call   1030 <serialputc@plt>
mov    $0x3fd,%edi
call   1050 <inb@plt>
test   $0x20,%al
je     11b0 <serialputc+0x80>
cmp    $0xa,%bl
jne    11d2 <serialputc+0xa2>
mov    $0x3f8,%edi
mov    $0xd,%esi
call   1040 <outb@plt>
movsbl %bl,%esi
mov    $0x3f8,%edi
pop    %rbx
jmp    1040 <outb@plt>

LLVM IR (-O0):
@serialputc.serialinit = internal global i32 0
define void @serialputc(i8 signext %0) {
%2 = alloca i8
store i8 %0, i8* %2
%3 = load i32, i32* @serialputc.serialinit
%4 = icmp ne i32 %3, 0
br i1 %4, label %13, label %5
5: ; preds = %1
%6 = call i32 @outb(i32 1017, i8 signext 0)
%7 = call i32 @outb(i32 1019, i8 signext -128)
%8 = call i32 @outb(i32 1016, i8 signext 3)
%9 = call i32 @outb(i32 1017, i8 signext 0)
%10 = call i32 @outb(i32 1019, i8 signext 3)
%11 = call i32 @outb(i32 1018, i8 signext -57)
%12 = call i32 @outb(i32 1020, i8 signext 11)
store i32 1, i32* @serialputc.serialinit
br label %13
13: ; preds = %5, %1
br label %14
14: ; preds = %18, %13
%15 = call i32 @inb(i32 1021)
%16 = and i32 %15, 32
%17 = icmp eq i32 %16, 0
br i1 %17, label %18, label %19
18: ; preds = %14
br label %14
19: ; preds = %14
%20 = load i8, i8* %2
%21 = sext i8 %20 to i32
%22 = icmp eq i32 %21, 10
br i1 %22, label %23, label %25
23: ; preds = %19
%24 = call i32 @outb(i32 1016, i8 signext 13)
br label %25
25: ; preds = %23, %19
%26 = load i8, i8* %2
%27 = call i32 @outb(i32 1016, i8 signext %26)
ret void
}

LLVM IR (-O2):
@serialputc.serialinit = internal unnamed_addr global i1 false
define void @serialputc(i8 signext %0) {
%2 = load i1, i1* @serialputc.serialinit
br i1 %2, label %11, label %3
3: ; preds = %1
%4 = tail call i32 @outb(i32 1017, i8 signext 0)
%5 = tail call i32 @outb(i32 1019, i8 signext -128)
%6 = tail call i32 @outb(i32 1016, i8 signext 3)
%7 = tail call i32 @outb(i32 1017, i8 signext 0)
%8 = tail call i32 @outb(i32 1019, i8 signext 3)
%9 = tail call i32 @outb(i32 1018, i8 signext -57)
%10 = tail call i32 @outb(i32 1020, i8 signext 11)
store i1 true, i1* @serialputc.serialinit
tail call void @serialputc(i8 signext 10)
br label %11
11: ; preds = %3, %1
br label %12
12: ; preds = %11, %12
%13 = tail call i32 @inb(i32 1021)
%14 = and i32 %13, 32
%15 = icmp eq i32 %14, 0
br i1 %15, label %12, label %16
16: ; preds = %12
%17 = icmp eq i8 %0, 10
br i1 %17, label %18, label %20
18: ; preds = %16
%19 = tail call i32 @outb(i32 1016, i8 signext 13)
br label %20
20: ; preds = %18, %16
%21 = tail call i32 @outb(i32 1016, i8 signext %0)
ret void
}