#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*/ OAL_OBTAIN_SEMAPHORE();
int /*<<< orphan*/ OAL_RELEASE_SEMAPHORE();
int /*<<< orphan*/ outb(unsigned char, int);
int fc8300_ppi_bulkwrite(void *handle, unsigned short devid,
                         unsigned short addr, unsigned char *data,
                         unsigned short length) {
  int i;
  unsigned char command = 0x80 | 0x00;
  OAL_OBTAIN_SEMAPHORE();
  outb((addr & 0xff00) >> 8, 0x00);
  outb(addr & 0xff, 0x00);
  outb(command, 0x00);
  outb(length & 0xff, 0x00);
  for (i = 0; i < length; i++)
    outb(data[i], 0x00);
  OAL_RELEASE_SEMAPHORE();
  return 0;
}


x86 assembly (clang, -O0):
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %r8w,%ax
mov    %rdi,-0x8(%rbp)
mov    %si,-0xa(%rbp)
mov    %dx,-0xc(%rbp)
mov    %rcx,-0x18(%rbp)
mov    %ax,-0x1a(%rbp)
movb   $0x80,-0x21(%rbp)
mov    $0x0,%al
call   1050 <OAL_OBTAIN_SEMAPHORE@plt>
movzwl -0xc(%rbp),%eax
and    $0xff00,%eax
sar    $0x8,%eax
xor    %esi,%esi
movzbl %al,%edi
call   1030 <outb@plt>
movzwl -0xc(%rbp),%eax
and    $0xff,%eax
xor    %esi,%esi
movzbl %al,%edi
call   1030 <outb@plt>
xor    %esi,%esi
movzbl -0x21(%rbp),%edi
call   1030 <outb@plt>
movzwl -0x1a(%rbp),%eax
and    $0xff,%eax
xor    %esi,%esi
movzbl %al,%edi
call   1030 <outb@plt>
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
movzwl -0x1a(%rbp),%ecx
cmp    %ecx,%eax
jge    11d9 <fc8300_ppi_bulkwrite+0xa9>
mov    -0x18(%rbp),%rax
movslq -0x20(%rbp),%rcx
xor    %esi,%esi
movzbl (%rax,%rcx,1),%edi
call   1030 <outb@plt>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    11a9 <fc8300_ppi_bulkwrite+0x79>
mov    $0x0,%al
call   1040 <OAL_RELEASE_SEMAPHORE@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %r8d,%r14d
mov    %rcx,%r15
mov    %edx,%ebp
xor    %eax,%eax
call   1050 <OAL_OBTAIN_SEMAPHORE@plt>
mov    %ebp,%edi
shr    $0x8,%edi
xor    %esi,%esi
call   1030 <outb@plt>
movzbl %bpl,%edi
xor    %esi,%esi
call   1030 <outb@plt>
mov    $0x80,%edi
xor    %esi,%esi
call   1030 <outb@plt>
movzbl %r14b,%edi
xor    %esi,%esi
call   1030 <outb@plt>
test   %r14d,%r14d
je     1195 <fc8300_ppi_bulkwrite+0x65>
movzwl %r14w,%ebp
xor    %ebx,%ebx
nop
movzbl (%r15,%rbx,1),%edi
xor    %esi,%esi
call   1030 <outb@plt>
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    1180 <fc8300_ppi_bulkwrite+0x50>
xor    %eax,%eax
call   1040 <OAL_RELEASE_SEMAPHORE@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @fc8300_ppi_bulkwrite(i8* %0, i16 zeroext %1, i16 zeroext %2, i8* %3, i16 zeroext %4) {
%6 = alloca i8*
%7 = alloca i16
%8 = alloca i16
%9 = alloca i8*
%10 = alloca i16
%11 = alloca i32
%12 = alloca i8
store i8* %0, i8** %6
store i16 %1, i16* %7
store i16 %2, i16* %8
store i8* %3, i8** %9
store i16 %4, i16* %10
store i8 -128, i8* %12
%13 = call i32 (...) @OAL_OBTAIN_SEMAPHORE()
%14 = load i16, i16* %8
%15 = zext i16 %14 to i32
%16 = and i32 %15, 65280
%17 = ashr i32 %16, 8
%18 = trunc i32 %17 to i8
%19 = call i32 @outb(i8 zeroext %18, i32 0)
%20 = load i16, i16* %8
%21 = zext i16 %20 to i32
%22 = and i32 %21, 255
%23 = trunc i32 %22 to i8
%24 = call i32 @outb(i8 zeroext %23, i32 0)
%25 = load i8, i8* %12
%26 = call i32 @outb(i8 zeroext %25, i32 0)
%27 = load i16, i16* %10
%28 = zext i16 %27 to i32
%29 = and i32 %28, 255
%30 = trunc i32 %29 to i8
%31 = call i32 @outb(i8 zeroext %30, i32 0)
store i32 0, i32* %11
br label %32
32: ; preds = %44, %5
%33 = load i32, i32* %11
%34 = load i16, i16* %10
%35 = zext i16 %34 to i32
%36 = icmp slt i32 %33, %35
br i1 %36, label %37, label %47
37: ; preds = %32
%38 = load i8*, i8** %9
%39 = load i32, i32* %11
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds i8, i8* %38, i64 %40
%42 = load i8, i8* %41
%43 = call i32 @outb(i8 zeroext %42, i32 0)
br label %44
44: ; preds = %37
%45 = load i32, i32* %11
%46 = add nsw i32 %45, 1
store i32 %46, i32* %11
br label %32
47: ; preds = %32
%48 = call i32 (...) @OAL_RELEASE_SEMAPHORE()
ret i32 0
}

LLVM IR (-O2):
define i32 @fc8300_ppi_bulkwrite(i8* nocapture readnone %0, i16 zeroext %1, i16 zeroext %2, i8* nocapture %3, i16 zeroext %4) {
%6 = tail call i32 (...) @OAL_OBTAIN_SEMAPHORE()
%7 = lshr i16 %2, 8
%8 = trunc i16 %7 to i8
%9 = tail call i32 @outb(i8 zeroext %8, i32 0)
%10 = trunc i16 %2 to i8
%11 = tail call i32 @outb(i8 zeroext %10, i32 0)
%12 = tail call i32 @outb(i8 zeroext -128, i32 0)
%13 = trunc i16 %4 to i8
%14 = tail call i32 @outb(i8 zeroext %13, i32 0)
%15 = icmp eq i16 %4, 0
br i1 %15, label %25, label %16
16: ; preds = %5
%17 = zext i16 %4 to i64
br label %18
18: ; preds = %16, %18
%19 = phi i64 [ 0, %16 ], [ %23, %18 ]
%20 = getelementptr inbounds i8, i8* %3, i64 %19
%21 = load i8, i8* %20
%22 = tail call i32 @outb(i8 zeroext %21, i32 0)
%23 = add nuw nsw i64 %19, 1
%24 = icmp eq i64 %23, %17
br i1 %24, label %25, label %18
25: ; preds = %18, %5
%26 = tail call i32 (...) @OAL_RELEASE_SEMAPHORE()
ret i32 0
}