#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 char, int);
int fc8300_ppi_dataread(void *handle, unsigned short devid, unsigned short addr,
                        unsigned char *data, unsigned int length) {
  int i;
  unsigned char command = 0x40 | 0x30;
  OAL_OBTAIN_SEMAPHORE();
  outb((addr & 0xff00) >> 8, 0x00);
  outb(addr & 0xff, 0x00);
  outb(command, 0x00);
  outb(0, 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    %dx,%ax
mov    %si,%dx
mov    %rdi,-0x8(%rbp)
mov    %dx,-0xa(%rbp)
mov    %ax,-0xc(%rbp)
mov    %rcx,-0x18(%rbp)
mov    %r8d,-0x1c(%rbp)
movb   $0x70,-0x21(%rbp)
mov    $0x0,%al
call   1060 <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>
xor    %esi,%esi
mov    %esi,%edi
call   1030 <outb@plt>
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jae    11df <fc8300_ppi_dataread+0x9f>
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    11b1 <fc8300_ppi_dataread+0x71>
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    $0x70,%edi
xor    %esi,%esi
call   1030 <outb@plt>
xor    %edi,%edi
xor    %esi,%esi
call   1030 <outb@plt>
test   %r14d,%r14d
je     11a4 <fc8300_ppi_dataread+0x64>
mov    %r14d,%ebp
xor    %ebx,%ebx
nopl   0x0(%rax)
xor    %edi,%edi
call   1040 <inb@plt>
mov    %al,(%r15,%rbx,1)
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    1190 <fc8300_ppi_dataread+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_dataread(i8* %0, i16 zeroext %1, i16 zeroext %2, i8* %3, i32 %4) {
%6 = alloca i8*
%7 = alloca i16
%8 = alloca i16
%9 = alloca i8*
%10 = alloca i32
%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 i32 %4, i32* %10
store i8 112, 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 = call i32 @outb(i8 zeroext 0, i32 0)
store i32 0, i32* %11
br label %28
28: ; preds = %38, %5
%29 = load i32, i32* %11
%30 = load i32, i32* %10
%31 = icmp ult i32 %29, %30
br i1 %31, label %32, label %41
32: ; preds = %28
%33 = call zeroext i8 @inb(i32 0)
%34 = load i8*, i8** %9
%35 = load i32, i32* %11
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds i8, i8* %34, i64 %36
store i8 %33, i8* %37
br label %38
38: ; preds = %32
%39 = load i32, i32* %11
%40 = add nsw i32 %39, 1
store i32 %40, i32* %11
br label %28
41: ; preds = %28
%42 = call i32 (...) @OAL_RELEASE_SEMAPHORE()
ret i32 0
}

LLVM IR (-O2):
define i32 @fc8300_ppi_dataread(i8* nocapture readnone %0, i16 zeroext %1, i16 zeroext %2, i8* nocapture writeonly %3, i32 %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 112, i32 0)
%13 = tail call i32 @outb(i8 zeroext 0, i32 0)
%14 = icmp eq i32 %4, 0
br i1 %14, label %23, label %15
15: ; preds = %5
%16 = zext i32 %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
}