#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, unsigned char);
int /*<<< orphan*/ serial_is_tx_fifo_empty(int);
void serial_write(unsigned char *b, unsigned short len) {
  int i = 0;
  while (!serial_is_tx_fifo_empty(0x3F8))
    ;
  while (i < len) {
    outb(0x3F8, b[i++]);
  }
}


x86 assembly (clang, -O0):
<serial_write>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %si,%ax
mov    %rdi,-0x8(%rbp)
mov    %ax,-0xa(%rbp)
movl   $0x0,-0x10(%rbp)
mov    $0x3f8,%edi
call   1040 <serial_is_tx_fifo_empty@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    1159 <serial_write+0x39>
jmp    115e <serial_write+0x3e>
jmp    113a <serial_write+0x1a>
jmp    1163 <serial_write+0x43>
mov    -0x10(%rbp),%eax
movzwl -0xa(%rbp),%ecx
cmp    %ecx,%eax
jge    1197 <serial_write+0x77>
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%ecx
mov    %ecx,%edx
add    $0x1,%edx
mov    %edx,-0x10(%rbp)
movslq %ecx,%rcx
mov    $0x3f8,%edi
movzbl (%rax,%rcx,1),%esi
call   1030 <outb@plt>
jmp    1163 <serial_write+0x43>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<serial_write>:
push   %rbp
push   %r14
push   %rbx
mov    %esi,%ebp
mov    %rdi,%r14
nopl   0x0(%rax)
mov    $0x3f8,%edi
call   1040 <serial_is_tx_fifo_empty@plt>
test   %eax,%eax
je     1130 <serial_write+0x10>
test   %bp,%bp
je     1168 <serial_write+0x48>
movzwl %bp,%ebp
xor    %ebx,%ebx
nopl   0x0(%rax,%rax,1)
movzbl (%r14,%rbx,1),%esi
add    $0x1,%rbx
mov    $0x3f8,%edi
call   1030 <outb@plt>
cmp    %rbx,%rbp
jne    1150 <serial_write+0x30>
pop    %rbx
pop    %r14
pop    %rbp
ret

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

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