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


x86 assembly (clang, -O0):
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %dx,%ax
mov    %si,%dx
mov    %rdi,-0x8(%rbp)
mov    %dx,-0xa(%rbp)
mov    %ax,-0xc(%rbp)
mov    %rcx,-0x18(%rbp)
movw   $0x2,-0x1a(%rbp)
movb   $0xc0,-0x1b(%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 -0x1b(%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>
xor    %edi,%edi
call   1040 <inb@plt>
mov    %ax,%cx
mov    -0x18(%rbp),%rax
mov    %cx,(%rax)
xor    %edi,%edi
call   1040 <inb@plt>
mov    %eax,%edx
shl    $0x8,%edx
mov    -0x18(%rbp),%rax
movzwl (%rax),%ecx
or     %edx,%ecx
mov    %cx,(%rax)
mov    $0x0,%al
call   1050 <OAL_RELEASE_SEMAPHORE@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
push   %rbp
push   %rbx
push   %rax
mov    %rcx,%rbx
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>
mov    $0x2,%edi
xor    %esi,%esi
call   1030 <outb@plt>
xor    %edi,%edi
call   1040 <inb@plt>
mov    %ax,(%rbx)
xor    %edi,%edi
call   1040 <inb@plt>
shl    $0x8,%eax
or     %ax,(%rbx)
xor    %eax,%eax
call   1050 <OAL_RELEASE_SEMAPHORE@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define i32 @fc8300_ppi_wordread(i8* %0, i16 zeroext %1, i16 zeroext %2, i16* %3) {
%5 = alloca i8*
%6 = alloca i16
%7 = alloca i16
%8 = alloca i16*
%9 = alloca i16
%10 = alloca i8
store i8* %0, i8** %5
store i16 %1, i16* %6
store i16 %2, i16* %7
store i16* %3, i16** %8
store i16 2, i16* %9
store i8 -64, i8* %10
%11 = call i32 (...) @OAL_OBTAIN_SEMAPHORE()
%12 = load i16, i16* %7
%13 = zext i16 %12 to i32
%14 = and i32 %13, 65280
%15 = ashr i32 %14, 8
%16 = trunc i32 %15 to i16
%17 = call i32 @outb(i16 zeroext %16, i32 0)
%18 = load i16, i16* %7
%19 = zext i16 %18 to i32
%20 = and i32 %19, 255
%21 = trunc i32 %20 to i16
%22 = call i32 @outb(i16 zeroext %21, i32 0)
%23 = load i8, i8* %10
%24 = zext i8 %23 to i16
%25 = call i32 @outb(i16 zeroext %24, i32 0)
%26 = load i16, i16* %9
%27 = zext i16 %26 to i32
%28 = and i32 %27, 255
%29 = trunc i32 %28 to i16
%30 = call i32 @outb(i16 zeroext %29, i32 0)
%31 = call i32 @inb(i32 0)
%32 = trunc i32 %31 to i16
%33 = load i16*, i16** %8
store i16 %32, i16* %33
%34 = call i32 @inb(i32 0)
%35 = shl i32 %34, 8
%36 = load i16*, i16** %8
%37 = load i16, i16* %36
%38 = zext i16 %37 to i32
%39 = or i32 %38, %35
%40 = trunc i32 %39 to i16
store i16 %40, i16* %36
%41 = call i32 (...) @OAL_RELEASE_SEMAPHORE()
ret i32 0
}

LLVM IR (-O2):
define i32 @fc8300_ppi_wordread(i8* nocapture readnone %0, i16 zeroext %1, i16 zeroext %2, i16* nocapture %3) {
%5 = tail call i32 (...) @OAL_OBTAIN_SEMAPHORE()
%6 = lshr i16 %2, 8
%7 = tail call i32 @outb(i16 zeroext %6, i32 0)
%8 = and i16 %2, 255
%9 = tail call i32 @outb(i16 zeroext %8, i32 0)
%10 = tail call i32 @outb(i16 zeroext 192, i32 0)
%11 = tail call i32 @outb(i16 zeroext 2, i32 0)
%12 = tail call i32 @inb(i32 0)
%13 = trunc i32 %12 to i16
store i16 %13, i16* %3
%14 = tail call i32 @inb(i32 0)
%15 = load i16, i16* %3
%16 = trunc i32 %14 to i16
%17 = shl i16 %16, 8
%18 = or i16 %17, %15
store i16 %18, i16* %3
%19 = tail call i32 (...) @OAL_RELEASE_SEMAPHORE()
ret i32 0
}