#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();
unsigned char inb(int);
int /*<<< orphan*/ outb(unsigned short, int);
int fc8300_ppi_bulkread(void *handle, unsigned short devid, unsigned short addr,
                        unsigned char *data, unsigned short length) {
  int i;
  unsigned char command = 0x80 | 0x40;
  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++)
    data[i] = inb(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   $0xc0,-0x21(%rbp)
mov    $0x0,%al
call   1060 <OAL_OBTAIN_SEMAPHORE@plt>
movzwl -0xc(%rbp),%eax
and    $0xff00,%eax
sar    $0x8,%eax
xor    %esi,%esi
movzwl %ax,%edi
call   1030 <outb@plt>
movzwl -0xc(%rbp),%eax
and    $0xff,%eax
xor    %esi,%esi
movzwl %ax,%edi
call   1030 <outb@plt>
movzbl -0x21(%rbp),%eax
xor    %esi,%esi
movzwl %ax,%edi
call   1030 <outb@plt>
movzwl -0x1a(%rbp),%eax
and    $0xff,%eax
xor    %esi,%esi
movzwl %ax,%edi
call   1030 <outb@plt>
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
movzwl -0x1a(%rbp),%ecx
cmp    %ecx,%eax
jge    11ed <fc8300_ppi_bulkread+0xad>
xor    %edi,%edi
call   1040 <inb@plt>
mov    %al,%dl
mov    -0x18(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    11bc <fc8300_ppi_bulkread+0x7c>
mov    $0x0,%al
call   1050 <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   1060 <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    $0xc0,%edi
xor    %esi,%esi
call   1030 <outb@plt>
movzbl %r14b,%edi
xor    %esi,%esi
call   1030 <outb@plt>
test   %r14d,%r14d
je     11a4 <fc8300_ppi_bulkread+0x64>
movzwl %r14w,%ebp
xor    %ebx,%ebx
nop
xor    %edi,%edi
call   1040 <inb@plt>
mov    %al,(%r15,%rbx,1)
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    1190 <fc8300_ppi_bulkread+0x50>
xor    %eax,%eax
call   1050 <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_bulkread(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 -64, 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 i16
%19 = call i32 @outb(i16 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 i16
%24 = call i32 @outb(i16 zeroext %23, i32 0)
%25 = load i8, i8* %12
%26 = zext i8 %25 to i16
%27 = call i32 @outb(i16 zeroext %26, i32 0)
%28 = load i16, i16* %10
%29 = zext i16 %28 to i32
%30 = and i32 %29, 255
%31 = trunc i32 %30 to i16
%32 = call i32 @outb(i16 zeroext %31, i32 0)
store i32 0, i32* %11
br label %33
33: ; preds = %44, %5
%34 = load i32, i32* %11
%35 = load i16, i16* %10
%36 = zext i16 %35 to i32
%37 = icmp slt i32 %34, %36
br i1 %37, label %38, label %47
38: ; preds = %33
%39 = call zeroext i8 @inb(i32 0)
%40 = load i8*, i8** %9
%41 = load i32, i32* %11
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds i8, i8* %40, i64 %42
store i8 %39, i8* %43
br label %44
44: ; preds = %38
%45 = load i32, i32* %11
%46 = add nsw i32 %45, 1
store i32 %46, i32* %11
br label %33
47: ; preds = %33
%48 = call i32 (...) @OAL_RELEASE_SEMAPHORE()
ret i32 0
}

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