#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*/ delay();
int inb(int);
int /*<<< orphan*/ outb(scalar_t__, int);
void serial_putc(int c) {
  int i;
  for (i = 0; !(inb(0x3F8 + 5) & 0x20) && i < 12800; i++)
    delay();
  if (c == '\b') {
    outb(0x3F8 + 0, c);
    for (i = 0; !(inb(0x3F8 + 5) & 0x20) && i < 12800; i++)
      delay();
    outb(0x3F8 + 0, ' ');
    for (i = 0; !(inb(0x3F8 + 5) & 0x20) && i < 12800; i++)
      delay();
    outb(0x3F8 + 0, c);
    return;
  }
  outb(0x3F8 + 0, c);
}


x86 assembly (clang, -O0):
<serial_putc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
mov    $0x3fd,%edi
call   1050 <inb@plt>
mov    %eax,%ecx
and    $0x20,%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x9(%rbp)
jne    116c <serial_putc+0x3c>
cmpl   $0x3200,-0x8(%rbp)
setl   %al
mov    %al,-0x9(%rbp)
mov    -0x9(%rbp),%al
test   $0x1,%al
jne    117c <serial_putc+0x4c>
jmp    1191 <serial_putc+0x61>
mov    $0x0,%al
call   1040 <delay@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1142 <serial_putc+0x12>
cmpl   $0x8,-0x4(%rbp)
jne    1275 <serial_putc+0x145>
mov    -0x4(%rbp),%esi
mov    $0x3f8,%edi
call   1030 <outb@plt>
movl   $0x0,-0x8(%rbp)
mov    $0x3fd,%edi
call   1050 <inb@plt>
mov    %eax,%ecx
and    $0x20,%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0xa(%rbp)
jne    11d9 <serial_putc+0xa9>
cmpl   $0x3200,-0x8(%rbp)
setl   %al
mov    %al,-0xa(%rbp)
mov    -0xa(%rbp),%al
test   $0x1,%al
jne    11e9 <serial_putc+0xb9>
jmp    11fe <serial_putc+0xce>
mov    $0x0,%al
call   1040 <delay@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    11af <serial_putc+0x7f>
mov    $0x3f8,%edi
mov    $0x20,%esi
call   1030 <outb@plt>
movl   $0x0,-0x8(%rbp)
mov    $0x3fd,%edi
call   1050 <inb@plt>
mov    %eax,%ecx
and    $0x20,%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0xb(%rbp)
jne    123e <serial_putc+0x10e>
cmpl   $0x3200,-0x8(%rbp)
setl   %al
mov    %al,-0xb(%rbp)
mov    -0xb(%rbp),%al
test   $0x1,%al
jne    124e <serial_putc+0x11e>
jmp    1263 <serial_putc+0x133>
mov    $0x0,%al
call   1040 <delay@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1214 <serial_putc+0xe4>
mov    -0x4(%rbp),%esi
mov    $0x3f8,%edi
call   1030 <outb@plt>
jmp    1282 <serial_putc+0x152>
mov    -0x4(%rbp),%esi
mov    $0x3f8,%edi
call   1030 <outb@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<serial_putc>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebp
mov    $0x3fd,%edi
call   1050 <inb@plt>
test   $0x20,%al
jne    1172 <serial_putc+0x42>
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nop
xor    %eax,%eax
call   1040 <delay@plt>
mov    $0x3fd,%edi
call   1050 <inb@plt>
test   $0x20,%al
jne    1172 <serial_putc+0x42>
lea    0x1(%rbx),%eax
cmp    $0x31ff,%ebx
mov    %eax,%ebx
jb     1150 <serial_putc+0x20>
cmp    $0x8,%ebp
jne    1212 <serial_putc+0xe2>
mov    $0x8,%ebp
mov    $0x3f8,%edi
mov    $0x8,%esi
call   1030 <outb@plt>
mov    $0x3fd,%edi
call   1050 <inb@plt>
test   $0x20,%al
jne    11c2 <serial_putc+0x92>
xor    %ebx,%ebx
nop
xor    %eax,%eax
call   1040 <delay@plt>
mov    $0x3fd,%edi
call   1050 <inb@plt>
test   $0x20,%al
jne    11c2 <serial_putc+0x92>
lea    0x1(%rbx),%eax
cmp    $0x31ff,%ebx
mov    %eax,%ebx
jb     11a0 <serial_putc+0x70>
mov    $0x3f8,%edi
mov    $0x20,%esi
call   1030 <outb@plt>
mov    $0x3fd,%edi
call   1050 <inb@plt>
test   $0x20,%al
jne    1212 <serial_putc+0xe2>
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1040 <delay@plt>
mov    $0x3fd,%edi
call   1050 <inb@plt>
test   $0x20,%al
jne    1212 <serial_putc+0xe2>
lea    0x1(%rbx),%eax
cmp    $0x31ff,%ebx
mov    %eax,%ebx
jb     11f0 <serial_putc+0xc0>
mov    $0x3f8,%edi
mov    %ebp,%esi
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1030 <outb@plt>

LLVM IR (-O0):
define void @serial_putc(i32 %0) {
%2 = alloca i32
%3 = alloca i32
store i32 %0, i32* %2
store i32 0, i32* %3
br label %4
4: ; preds = %15, %1
%5 = call i32 @inb(i32 1021)
%6 = and i32 %5, 32
%7 = icmp ne i32 %6, 0
br i1 %7, label %11, label %8
8: ; preds = %4
%9 = load i32, i32* %3
%10 = icmp slt i32 %9, 12800
br label %11
11: ; preds = %8, %4
%12 = phi i1 [ false, %4 ], [ %10, %8 ]
br i1 %12, label %13, label %18
13: ; preds = %11
%14 = call i32 (...) @delay()
br label %15
15: ; preds = %13
%16 = load i32, i32* %3
%17 = add nsw i32 %16, 1
store i32 %17, i32* %3
br label %4
18: ; preds = %11
%19 = load i32, i32* %2
%20 = icmp eq i32 %19, 8
br i1 %20, label %21, label %57
21: ; preds = %18
%22 = load i32, i32* %2
%23 = call i32 @outb(i64 1016, i32 %22)
store i32 0, i32* %3
br label %24
24: ; preds = %35, %21
%25 = call i32 @inb(i32 1021)
%26 = and i32 %25, 32
%27 = icmp ne i32 %26, 0
br i1 %27, label %31, label %28
28: ; preds = %24
%29 = load i32, i32* %3
%30 = icmp slt i32 %29, 12800
br label %31
31: ; preds = %28, %24
%32 = phi i1 [ false, %24 ], [ %30, %28 ]
br i1 %32, label %33, label %38
33: ; preds = %31
%34 = call i32 (...) @delay()
br label %35
35: ; preds = %33
%36 = load i32, i32* %3
%37 = add nsw i32 %36, 1
store i32 %37, i32* %3
br label %24
38: ; preds = %31
%39 = call i32 @outb(i64 1016, i32 32)
store i32 0, i32* %3
br label %40
40: ; preds = %51, %38
%41 = call i32 @inb(i32 1021)
%42 = and i32 %41, 32
%43 = icmp ne i32 %42, 0
br i1 %43, label %47, label %44
44: ; preds = %40
%45 = load i32, i32* %3
%46 = icmp slt i32 %45, 12800
br label %47
47: ; preds = %44, %40
%48 = phi i1 [ false, %40 ], [ %46, %44 ]
br i1 %48, label %49, label %54
49: ; preds = %47
%50 = call i32 (...) @delay()
br label %51
51: ; preds = %49
%52 = load i32, i32* %3
%53 = add nsw i32 %52, 1
store i32 %53, i32* %3
br label %40
54: ; preds = %47
%55 = load i32, i32* %2
%56 = call i32 @outb(i64 1016, i32 %55)
br label %60
57: ; preds = %18
%58 = load i32, i32* %2
%59 = call i32 @outb(i64 1016, i32 %58)
br label %60
60: ; preds = %57, %54
ret void
}

LLVM IR (-O2):
define void @serial_putc(i32 %0) {
%2 = tail call i32 @inb(i32 1021)
%3 = and i32 %2, 32
%4 = icmp eq i32 %3, 0
br i1 %4, label %5, label %14
5: ; preds = %1, %5
%6 = phi i32 [ %8, %5 ], [ 0, %1 ]
%7 = tail call i32 (...) @delay()
%8 = add nuw nsw i32 %6, 1
%9 = tail call i32 @inb(i32 1021)
%10 = and i32 %9, 32
%11 = icmp eq i32 %10, 0
%12 = icmp ult i32 %6, 12799
%13 = select i1 %11, i1 %12, i1 false
br i1 %13, label %5, label %14
14: ; preds = %5, %1
%15 = icmp eq i32 %0, 8
br i1 %15, label %16, label %44
16: ; preds = %14
%17 = tail call i32 @outb(i64 1016, i32 8)
%18 = tail call i32 @inb(i32 1021)
%19 = and i32 %18, 32
%20 = icmp eq i32 %19, 0
br i1 %20, label %21, label %30
21: ; preds = %16, %21
%22 = phi i32 [ %24, %21 ], [ 0, %16 ]
%23 = tail call i32 (...) @delay()
%24 = add nuw nsw i32 %22, 1
%25 = tail call i32 @inb(i32 1021)
%26 = and i32 %25, 32
%27 = icmp eq i32 %26, 0
%28 = icmp ult i32 %22, 12799
%29 = select i1 %27, i1 %28, i1 false
br i1 %29, label %21, label %30
30: ; preds = %21, %16
%31 = tail call i32 @outb(i64 1016, i32 32)
%32 = tail call i32 @inb(i32 1021)
%33 = and i32 %32, 32
%34 = icmp eq i32 %33, 0
br i1 %34, label %35, label %44
35: ; preds = %30, %35
%36 = phi i32 [ %38, %35 ], [ 0, %30 ]
%37 = tail call i32 (...) @delay()
%38 = add nuw nsw i32 %36, 1
%39 = tail call i32 @inb(i32 1021)
%40 = and i32 %39, 32
%41 = icmp eq i32 %40, 0
%42 = icmp ult i32 %36, 12799
%43 = select i1 %41, i1 %42, i1 false
br i1 %43, label %35, label %44
44: ; preds = %35, %14, %30
%45 = phi i32 [ 8, %30 ], [ %0, %14 ], [ 8, %35 ]
%46 = tail call i32 @outb(i64 1016, i32 %45)
ret void
}