#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 isa_read8(int);
int /*<<< orphan*/ isa_write8(int, unsigned char const);
void serial_write(const void *_buf, int len) {
  const unsigned char *buf = _buf;
  int i;
  for (i = 0; i < len; i++) {
    while ((isa_read8(0x2fd) & 0x20) == 0)
      ;
    isa_write8(0x2f8, buf[i]);
  }
}


x86 assembly (clang, -O0):
<serial_write>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    118e <serial_write+0x6e>
jmp    114f <serial_write+0x2f>
mov    $0x2fd,%edi
call   1040 <isa_read8@plt>
and    $0x20,%eax
cmp    $0x0,%eax
jne    116a <serial_write+0x4a>
jmp    114f <serial_write+0x2f>
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    $0x2f8,%edi
movzbl (%rax,%rcx,1),%esi
call   1030 <isa_write8@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    113e <serial_write+0x1e>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<serial_write>:
push   %r15
push   %r14
push   %rbx
test   %esi,%esi
jle    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    $0x2fd,%edi
call   1040 <isa_read8@plt>
test   $0x20,%al
je     1140 <serial_write+0x20>
movzbl (%r14,%rbx,1),%esi
mov    $0x2f8,%edi
call   1030 <isa_write8@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 i8*
%6 = alloca i32
store i8* %0, i8** %3
store i32 %1, i32* %4
%7 = load i8*, i8** %3
store i8* %7, i8** %5
store i32 0, i32* %6
br label %8
8: ; preds = %25, %2
%9 = load i32, i32* %6
%10 = load i32, i32* %4
%11 = icmp slt i32 %9, %10
br i1 %11, label %12, label %28
12: ; preds = %8
br label %13
13: ; preds = %17, %12
%14 = call i32 @isa_read8(i32 765)
%15 = and i32 %14, 32
%16 = icmp eq i32 %15, 0
br i1 %16, label %17, label %18
17: ; preds = %13
br label %13
18: ; preds = %13
%19 = load i8*, i8** %5
%20 = load i32, i32* %6
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds i8, i8* %19, i64 %21
%23 = load i8, i8* %22
%24 = call i32 @isa_write8(i32 760, i8 zeroext %23)
br label %25
25: ; preds = %18
%26 = load i32, i32* %6
%27 = add nsw i32 %26, 1
store i32 %27, i32* %6
br label %8
28: ; preds = %8
ret void
}

LLVM IR (-O2):
define void @serial_write(i8* nocapture %0, i32 %1) {
%3 = icmp sgt i32 %1, 0
br i1 %3, label %4, label %18
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 %8
8: ; preds = %6, %8
%9 = tail call i32 @isa_read8(i32 765)
%10 = and i32 %9, 32
%11 = icmp eq i32 %10, 0
br i1 %11, label %8, label %12
12: ; preds = %8
%13 = getelementptr inbounds i8, i8* %0, i64 %7
%14 = load i8, i8* %13
%15 = tail call i32 @isa_write8(i32 760, i8 zeroext %14)
%16 = add nuw nsw i64 %7, 1
%17 = icmp eq i64 %16, %5
br i1 %17, label %18, label %6
18: ; preds = %12, %2
ret void
}