#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 serial_putc(char a, int tty_minor) {
  int com;
  switch (tty_minor) {
  case 1:
    com = 0x3F8;
    break;
  case 1 + 1:
    com = 0x2F8;
    break;
  case 1 + 2:
    com = 0x3E8;
    break;
  case 1 + 3:
    com = 0x2E8;
    break;
  }
  while ((inb(com + 5) & 0x20) == 0)
    ;
  outb(com, a);
}


x86 assembly (clang, -O0):
<serial_putc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %dil,%al
mov    %al,-0x1(%rbp)
mov    %esi,-0x8(%rbp)
mov    -0x8(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,%ecx
mov    %rcx,-0x18(%rbp)
sub    $0x3,%eax
ja     1185 <serial_putc+0x65>
mov    -0x18(%rbp),%rax
lea    0xeaf(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
movl   $0x3f8,-0xc(%rbp)
jmp    1185 <serial_putc+0x65>
movl   $0x2f8,-0xc(%rbp)
jmp    1185 <serial_putc+0x65>
movl   $0x3e8,-0xc(%rbp)
jmp    1185 <serial_putc+0x65>
movl   $0x2e8,-0xc(%rbp)
jmp    118a <serial_putc+0x6a>
mov    -0xc(%rbp),%edi
add    $0x5,%edi
call   1040 <inb@plt>
and    $0x20,%eax
cmp    $0x0,%eax
jne    11a6 <serial_putc+0x86>
jmp    118a <serial_putc+0x6a>
mov    -0xc(%rbp),%edi
movsbl -0x1(%rbp),%esi
call   1030 <outb@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<serial_putc>:
push   %rbp
push   %r14
push   %rbx
mov    %edi,%r14d
add    $0xfffffffe,%esi
mov    $0x3f8,%ebx
cmp    $0x2,%esi
ja     1141 <serial_putc+0x21>
movslq %esi,%rax
lea    0xec2(%rip),%rcx
mov    (%rcx,%rax,4),%ebx
mov    %ebx,%ebp
or     $0x5,%ebp
cs nopw 0x0(%rax,%rax,1)
mov    %ebp,%edi
call   1040 <inb@plt>
test   $0x20,%al
je     1150 <serial_putc+0x30>
movsbl %r14b,%esi
mov    %ebx,%edi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1030 <outb@plt>

LLVM IR (-O0):
define void @serial_putc(i8 signext %0, i32 %1) {
%3 = alloca i8
%4 = alloca i32
%5 = alloca i32
store i8 %0, i8* %3
store i32 %1, i32* %4
%6 = load i32, i32* %4
switch i32 %6, label %11 [
i32 1, label %7
i32 2, label %8
i32 3, label %9
i32 4, label %10
]
7: ; preds = %2
store i32 1016, i32* %5
br label %11
8: ; preds = %2
store i32 760, i32* %5
br label %11
9: ; preds = %2
store i32 1000, i32* %5
br label %11
10: ; preds = %2
store i32 744, i32* %5
br label %11
11: ; preds = %2, %10, %9, %8, %7
br label %12
12: ; preds = %18, %11
%13 = load i32, i32* %5
%14 = add nsw i32 %13, 5
%15 = call i32 @inb(i32 %14)
%16 = and i32 %15, 32
%17 = icmp eq i32 %16, 0
br i1 %17, label %18, label %19
18: ; preds = %12
br label %12
19: ; preds = %12
%20 = load i32, i32* %5
%21 = load i8, i8* %3
%22 = call i32 @outb(i32 %20, i8 signext %21)
ret void
}

LLVM IR (-O2):
@switch.table.serial_putc = [3 x i32] [i32 760, i32 1000, i32 744]
define void @serial_putc(i8 signext %0, i32 %1) {
%3 = add i32 %1, -2
%4 = icmp ult i32 %3, 3
br i1 %4, label %5, label %9
5: ; preds = %2
%6 = sext i32 %3 to i64
%7 = getelementptr inbounds [3 x i32], [3 x i32]* @switch.table.serial_putc, i64 0, i64 %6
%8 = load i32, i32* %7
br label %9
9: ; preds = %5, %2
%10 = phi i32 [ 1016, %2 ], [ %8, %5 ]
%11 = or i32 %10, 5
br label %12
12: ; preds = %12, %9
%13 = tail call i32 @inb(i32 %11)
%14 = and i32 %13, 32
%15 = icmp eq i32 %14, 0
br i1 %15, label %12, label %16
16: ; preds = %12
%17 = tail call i32 @outb(i32 %10, i8 signext %0)
ret void
}