#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*/ serial_configure_baud_rate(int, int);
int /*<<< orphan*/ serial_configure_fifo_queue(int);
int /*<<< orphan*/ serial_configure_line(int);
int /*<<< orphan*/ serial_configure_modem(int);
int /*<<< orphan*/ serial_is_transmit_fifo_empty(int);
int /*<<< orphan*/ serial_write_cell(int, char);
void serial_write(char *buf) {
  static int serial_configured = 0;
  if (!serial_configured) {
    serial_configure_baud_rate(0x3F8, 2);
    serial_configure_line(0x3F8);
    serial_configure_fifo_queue(0x3F8);
    serial_configure_modem(0x3F8);
    serial_configured = 1;
  }
  while (!serial_is_transmit_fifo_empty(0x3F8)) {
    ;
  }
  unsigned int i = 0;
  while (buf[i] != '\0') {
    serial_write_cell(0x3F8, buf[i]);
    i++;
  }
}


x86 assembly (clang, -O0):
<serial_write>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
cmpl   $0x0,0x2ee1(%rip)
jne    11b0 <serial_write+0x50>
mov    $0x3f8,%edi
mov    $0x2,%esi
call   1060 <serial_configure_baud_rate@plt>
mov    $0x3f8,%edi
call   1050 <serial_configure_line@plt>
mov    $0x3f8,%edi
call   1030 <serial_configure_fifo_queue@plt>
mov    $0x3f8,%edi
call   1040 <serial_configure_modem@plt>
movl   $0x1,0x2ea4(%rip)
jmp    11b5 <serial_write+0x55>
mov    $0x3f8,%edi
call   1080 <serial_is_transmit_fifo_empty@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    11d4 <serial_write+0x74>
jmp    11d9 <serial_write+0x79>
jmp    11b5 <serial_write+0x55>
movl   $0x0,-0xc(%rbp)
mov    -0x8(%rbp),%rax
mov    -0xc(%rbp),%ecx
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
je     1217 <serial_write+0xb7>
mov    -0x8(%rbp),%rax
mov    -0xc(%rbp),%ecx
mov    $0x3f8,%edi
movsbl (%rax,%rcx,1),%esi
call   1070 <serial_write_cell@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    11e0 <serial_write+0x80>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<serial_write>:
push   %rbp
push   %rbx
push   %rax
mov    %rdi,%rbx
cmpb   $0x0,0x2ee7(%rip)
jne    11b0 <serial_write+0x50>
mov    $0x3f8,%edi
mov    $0x2,%esi
call   1060 <serial_configure_baud_rate@plt>
mov    $0x3f8,%edi
call   1050 <serial_configure_line@plt>
mov    $0x3f8,%edi
call   1030 <serial_configure_fifo_queue@plt>
mov    $0x3f8,%edi
call   1040 <serial_configure_modem@plt>
movb   $0x1,0x2eb1(%rip)
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    $0x3f8,%edi
call   1080 <serial_is_transmit_fifo_empty@plt>
test   %eax,%eax
je     11b0 <serial_write+0x50>
mov    (%rbx),%al
test   %al,%al
je     11ea <serial_write+0x8a>
mov    $0x1,%ebp
nopl   0x0(%rax)
movsbl %al,%esi
mov    $0x3f8,%edi
call   1070 <serial_write_cell@plt>
mov    %ebp,%eax
movzbl (%rbx,%rax,1),%eax
add    $0x1,%ebp
test   %al,%al
jne    11d0 <serial_write+0x70>
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

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

LLVM IR (-O2):
@serial_write.serial_configured = internal unnamed_addr global i1 false
define void @serial_write(i8* nocapture %0) {
%2 = load i1, i1* @serial_write.serial_configured
br i1 %2, label %8, label %3
3: ; preds = %1
%4 = tail call i32 @serial_configure_baud_rate(i32 1016, i32 2)
%5 = tail call i32 @serial_configure_line(i32 1016)
%6 = tail call i32 @serial_configure_fifo_queue(i32 1016)
%7 = tail call i32 @serial_configure_modem(i32 1016)
store i1 true, i1* @serial_write.serial_configured
br label %8
8: ; preds = %3, %1
br label %9
9: ; preds = %8, %9
%10 = tail call i32 @serial_is_transmit_fifo_empty(i32 1016)
%11 = icmp eq i32 %10, 0
br i1 %11, label %9, label %12
12: ; preds = %9
%13 = load i8, i8* %0
%14 = icmp eq i8 %13, 0
br i1 %14, label %24, label %15
15: ; preds = %12, %15
%16 = phi i8 [ %22, %15 ], [ %13, %12 ]
%17 = phi i32 [ %19, %15 ], [ 0, %12 ]
%18 = tail call i32 @serial_write_cell(i32 1016, i8 signext %16)
%19 = add i32 %17, 1
%20 = zext i32 %19 to i64
%21 = getelementptr inbounds i8, i8* %0, i64 %20
%22 = load i8, i8* %21
%23 = icmp eq i8 %22, 0
br i1 %23, label %24, label %15
24: ; preds = %15, %12
ret void
}