#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_is_transmit_fifo_empty(int);
void serial_write(char *buffer) {
  for (int i = 0;; i++) {
    char next_char = buffer[i];
    if (next_char == '\0') {
      return;
    }
    while (!serial_is_transmit_fifo_empty(0x3F8)) {
    };
    outb((0x3F8), next_char);
  }
}


x86 assembly (clang, -O0):
<serial_write>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
mov    (%rax,%rcx,1),%al
mov    %al,-0xd(%rbp)
movsbl -0xd(%rbp),%eax
cmp    $0x0,%eax
jne    1154 <serial_write+0x34>
add    $0x10,%rsp
pop    %rbp
ret
jmp    1159 <serial_write+0x39>
mov    $0x3f8,%edi
call   1040 <serial_is_transmit_fifo_empty@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    1178 <serial_write+0x58>
jmp    117d <serial_write+0x5d>
jmp    1159 <serial_write+0x39>
mov    $0x3f8,%edi
movsbl -0xd(%rbp),%esi
call   1030 <outb@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1133 <serial_write+0x13>

x86 assembly (clang, -O2):
<serial_write>:
push   %rbp
push   %r14
push   %rbx
mov    (%rdi),%bpl
test   %bpl,%bpl
je     116b <serial_write+0x4b>
mov    %rdi,%r14
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    $0x3f8,%edi
call   1040 <serial_is_transmit_fifo_empty@plt>
test   %eax,%eax
je     1140 <serial_write+0x20>
movsbl %bpl,%esi
mov    $0x3f8,%edi
call   1030 <outb@plt>
movzbl 0x1(%r14,%rbx,1),%ebp
add    $0x1,%rbx
test   %bpl,%bpl
jne    1140 <serial_write+0x20>
pop    %rbx
pop    %r14
pop    %rbp
ret

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

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