#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, char);
int /*<<< orphan*/ serial_configure_baud_rate(int, int);
int /*<<< orphan*/ serial_configure_line(int);
int /*<<< orphan*/ serial_is_transmit_fifo_empty(int);
void serial_write(char *buf, unsigned int len) {
  serial_configure_baud_rate(0x3F8, 3);
  serial_configure_line(0x3F8);
  unsigned int i;
  for (i = 0; i < len; i++) {
    while (!serial_is_transmit_fifo_empty(0x3F8))
      ;
    outb((0x3F8), buf[i]);
  }
}


x86 assembly (clang, -O0):
<serial_write>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    $0x3f8,%edi
mov    $0x3,%esi
call   1050 <serial_configure_baud_rate@plt>
mov    $0x3f8,%edi
call   1040 <serial_configure_line@plt>
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jae    11c7 <serial_write+0x87>
jmp    1180 <serial_write+0x40>
mov    $0x3f8,%edi
call   1060 <serial_is_transmit_fifo_empty@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    119f <serial_write+0x5f>
jmp    11a4 <serial_write+0x64>
jmp    1180 <serial_write+0x40>
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%ecx
mov    $0x3f8,%edi
movsbl (%rax,%rcx,1),%esi
call   1030 <outb@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    116f <serial_write+0x2f>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<serial_write>:
push   %rbp
push   %r14
push   %rbx
mov    %esi,%ebp
mov    %rdi,%r14
mov    $0x3f8,%edi
mov    $0x3,%esi
call   1050 <serial_configure_baud_rate@plt>
mov    $0x3f8,%edi
call   1040 <serial_configure_line@plt>
test   %ebp,%ebp
je     1196 <serial_write+0x56>
mov    %ebp,%ebp
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
mov    $0x3f8,%edi
call   1060 <serial_is_transmit_fifo_empty@plt>
test   %eax,%eax
je     1170 <serial_write+0x30>
movsbl (%r14,%rbx,1),%esi
mov    $0x3f8,%edi
call   1030 <outb@plt>
add    $0x1,%rbx
cmp    %rbp,%rbx
jne    1170 <serial_write+0x30>
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define void @serial_write(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
store i8* %0, i8** %3
store i32 %1, i32* %4
%6 = call i32 @serial_configure_baud_rate(i32 1016, i32 3)
%7 = call i32 @serial_configure_line(i32 1016)
store i32 0, i32* %5
br label %8
8: ; preds = %25, %2
%9 = load i32, i32* %5
%10 = load i32, i32* %4
%11 = icmp ult i32 %9, %10
br i1 %11, label %12, label %28
12: ; preds = %8
br label %13
13: ; preds = %17, %12
%14 = call i32 @serial_is_transmit_fifo_empty(i32 1016)
%15 = icmp ne i32 %14, 0
%16 = xor i1 %15, true
br i1 %16, label %17, label %18
17: ; preds = %13
br label %13
18: ; preds = %13
%19 = load i8*, i8** %3
%20 = load i32, i32* %5
%21 = zext i32 %20 to i64
%22 = getelementptr inbounds i8, i8* %19, i64 %21
%23 = load i8, i8* %22
%24 = call i32 @outb(i32 1016, i8 signext %23)
br label %25
25: ; preds = %18
%26 = load i32, i32* %5
%27 = add i32 %26, 1
store i32 %27, i32* %5
br label %8
28: ; preds = %8
ret void
}

LLVM IR (-O2):
define void @serial_write(i8* nocapture %0, i32 %1) {
%3 = tail call i32 @serial_configure_baud_rate(i32 1016, i32 3)
%4 = tail call i32 @serial_configure_line(i32 1016)
%5 = icmp eq i32 %1, 0
br i1 %5, label %19, label %6
6: ; preds = %2
%7 = zext i32 %1 to i64
br label %8
8: ; preds = %6, %13
%9 = phi i64 [ 0, %6 ], [ %17, %13 ]
br label %10
10: ; preds = %8, %10
%11 = tail call i32 @serial_is_transmit_fifo_empty(i32 1016)
%12 = icmp eq i32 %11, 0
br i1 %12, label %10, label %13
13: ; preds = %10
%14 = getelementptr inbounds i8, i8* %0, i64 %9
%15 = load i8, i8* %14
%16 = tail call i32 @outb(i32 1016, i8 signext %15)
%17 = add nuw nsw i64 %9, 1
%18 = icmp eq i64 %17, %7
br i1 %18, label %19, label %8
19: ; preds = %13, %2
ret void
}