#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*/ cli();
int inb(int);
int /*<<< orphan*/ outb(int, int);
int /*<<< orphan*/ sti();
void serial_enable(int port) {
  cli();
  outb(port + 2, 0x02);
  outb(port + 3, 0x80);
  outb(port + 0, 115200 / 38400);
  outb(port + 1, 0);
  outb(port + 3, 0x03);
  outb(port + 4, 0);
  outb(port + 1, 0x01);
  if (inb(port + 5) == 0xFF)
    return;
  inb(port + 2);
  inb(port + 0);
  sti();
}


x86 assembly (clang, -O0):
<serial_enable>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    $0x0,%al
call   1060 <cli@plt>
mov    -0x4(%rbp),%edi
add    $0x2,%edi
mov    $0x2,%esi
call   1040 <outb@plt>
mov    -0x4(%rbp),%edi
add    $0x3,%edi
mov    $0x80,%esi
call   1040 <outb@plt>
mov    -0x4(%rbp),%edi
add    $0x0,%edi
mov    $0x3,%esi
call   1040 <outb@plt>
mov    -0x4(%rbp),%edi
add    $0x1,%edi
xor    %esi,%esi
call   1040 <outb@plt>
mov    -0x4(%rbp),%edi
add    $0x3,%edi
mov    $0x3,%esi
call   1040 <outb@plt>
mov    -0x4(%rbp),%edi
add    $0x4,%edi
xor    %esi,%esi
call   1040 <outb@plt>
mov    -0x4(%rbp),%edi
add    $0x1,%edi
mov    $0x1,%esi
call   1040 <outb@plt>
mov    -0x4(%rbp),%edi
add    $0x5,%edi
call   1050 <inb@plt>
cmp    $0xff,%eax
jne    11d7 <serial_enable+0x97>
jmp    11f4 <serial_enable+0xb4>
mov    -0x4(%rbp),%edi
add    $0x2,%edi
call   1050 <inb@plt>
mov    -0x4(%rbp),%edi
add    $0x0,%edi
call   1050 <inb@plt>
mov    $0x0,%al
call   1030 <sti@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<serial_enable>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edi,%ebx
xor    %eax,%eax
call   1060 <cli@plt>
lea    0x2(%rbx),%r14d
mov    %r14d,%edi
mov    $0x2,%esi
call   1040 <outb@plt>
lea    0x3(%rbx),%r15d
mov    %r15d,%edi
mov    $0x80,%esi
call   1040 <outb@plt>
mov    %ebx,%edi
mov    $0x3,%esi
call   1040 <outb@plt>
lea    0x1(%rbx),%ebp
mov    %ebp,%edi
xor    %esi,%esi
call   1040 <outb@plt>
mov    %r15d,%edi
mov    $0x3,%esi
call   1040 <outb@plt>
lea    0x4(%rbx),%edi
xor    %esi,%esi
call   1040 <outb@plt>
mov    %ebp,%edi
mov    $0x1,%esi
call   1040 <outb@plt>
lea    0x5(%rbx),%edi
call   1050 <inb@plt>
cmp    $0xff,%eax
jne    11c7 <serial_enable+0x87>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %r14d,%edi
call   1050 <inb@plt>
mov    %ebx,%edi
call   1050 <inb@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <sti@plt>

LLVM IR (-O0):
define void @serial_enable(i32 %0) {
%2 = alloca i32
store i32 %0, i32* %2
%3 = call i32 (...) @cli()
%4 = load i32, i32* %2
%5 = add nsw i32 %4, 2
%6 = call i32 @outb(i32 %5, i32 2)
%7 = load i32, i32* %2
%8 = add nsw i32 %7, 3
%9 = call i32 @outb(i32 %8, i32 128)
%10 = load i32, i32* %2
%11 = add nsw i32 %10, 0
%12 = call i32 @outb(i32 %11, i32 3)
%13 = load i32, i32* %2
%14 = add nsw i32 %13, 1
%15 = call i32 @outb(i32 %14, i32 0)
%16 = load i32, i32* %2
%17 = add nsw i32 %16, 3
%18 = call i32 @outb(i32 %17, i32 3)
%19 = load i32, i32* %2
%20 = add nsw i32 %19, 4
%21 = call i32 @outb(i32 %20, i32 0)
%22 = load i32, i32* %2
%23 = add nsw i32 %22, 1
%24 = call i32 @outb(i32 %23, i32 1)
%25 = load i32, i32* %2
%26 = add nsw i32 %25, 5
%27 = call i32 @inb(i32 %26)
%28 = icmp eq i32 %27, 255
br i1 %28, label %29, label %30
29: ; preds = %1
br label %38
30: ; preds = %1
%31 = load i32, i32* %2
%32 = add nsw i32 %31, 2
%33 = call i32 @inb(i32 %32)
%34 = load i32, i32* %2
%35 = add nsw i32 %34, 0
%36 = call i32 @inb(i32 %35)
%37 = call i32 (...) @sti()
br label %38
38: ; preds = %30, %29
ret void
}

LLVM IR (-O2):
define void @serial_enable(i32 %0) {
%2 = tail call i32 (...) @cli()
%3 = add nsw i32 %0, 2
%4 = tail call i32 @outb(i32 %3, i32 2)
%5 = add nsw i32 %0, 3
%6 = tail call i32 @outb(i32 %5, i32 128)
%7 = tail call i32 @outb(i32 %0, i32 3)
%8 = add nsw i32 %0, 1
%9 = tail call i32 @outb(i32 %8, i32 0)
%10 = tail call i32 @outb(i32 %5, i32 3)
%11 = add nsw i32 %0, 4
%12 = tail call i32 @outb(i32 %11, i32 0)
%13 = tail call i32 @outb(i32 %8, i32 1)
%14 = add nsw i32 %0, 5
%15 = tail call i32 @inb(i32 %14)
%16 = icmp eq i32 %15, 255
br i1 %16, label %21, label %17
17: ; preds = %1
%18 = tail call i32 @inb(i32 %3)
%19 = tail call i32 @inb(i32 %0)
%20 = tail call i32 (...) @sti()
br label %21
21: ; preds = %1, %17
ret void
}