#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 *buf, unsigned int len) {
  for (unsigned int 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)
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jae    118e <serial_write+0x6e>
jmp    1147 <serial_write+0x27>
mov    $0x3f8,%edi
call   1040 <serial_is_transmit_fifo_empty@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    1166 <serial_write+0x46>
jmp    116b <serial_write+0x4b>
jmp    1147 <serial_write+0x27>
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    1136 <serial_write+0x16>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<serial_write>:
push   %r15
push   %r14
push   %rbx
test   %esi,%esi
je     1166 <serial_write+0x46>
mov    %rdi,%r14
mov    %esi,%r15d
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 (%r14,%rbx,1),%esi
mov    $0x3f8,%edi
call   1030 <outb@plt>
add    $0x1,%rbx
cmp    %r15,%rbx
jne    1140 <serial_write+0x20>
pop    %rbx
pop    %r14
pop    %r15
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
store i32 0, i32* %5
br label %6
6: ; preds = %23, %2
%7 = load i32, i32* %5
%8 = load i32, i32* %4
%9 = icmp ult i32 %7, %8
br i1 %9, label %10, label %26
10: ; preds = %6
br label %11
11: ; preds = %15, %10
%12 = call i32 @serial_is_transmit_fifo_empty(i32 1016)
%13 = icmp ne i32 %12, 0
%14 = xor i1 %13, true
br i1 %14, label %15, label %16
15: ; preds = %11
br label %11
16: ; preds = %11
%17 = load i8*, i8** %3
%18 = load i32, i32* %5
%19 = zext i32 %18 to i64
%20 = getelementptr inbounds i8, i8* %17, i64 %19
%21 = load i8, i8* %20
%22 = call i32 @outb(i32 1016, i8 signext %21)
br label %23
23: ; preds = %16
%24 = load i32, i32* %5
%25 = add i32 %24, 1
store i32 %25, i32* %5
br label %6
26: ; preds = %6
ret void
}

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