#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_longread(void *handle, unsigned short devid, unsigned short addr,
                        unsigned int *data) {
  unsigned short length = 4;
  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;
  *data |= inb(0x00) << 16;
  *data |= inb(0x00) << 24;
  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   $0x4,-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    %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
xor    %edi,%edi
call   1040 <inb@plt>
mov    %eax,%ecx
shl    $0x8,%ecx
mov    -0x18(%rbp),%rax
or     (%rax),%ecx
mov    %ecx,(%rax)
xor    %edi,%edi
call   1040 <inb@plt>
mov    %eax,%ecx
shl    $0x10,%ecx
mov    -0x18(%rbp),%rax
or     (%rax),%ecx
mov    %ecx,(%rax)
xor    %edi,%edi
call   1040 <inb@plt>
mov    %eax,%ecx
shl    $0x18,%ecx
mov    -0x18(%rbp),%rax
or     (%rax),%ecx
mov    %ecx,(%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    $0x4,%edi
xor    %esi,%esi
call   1030 <outb@plt>
xor    %edi,%edi
call   1040 <inb@plt>
mov    %eax,(%rbx)
xor    %edi,%edi
call   1040 <inb@plt>
shl    $0x8,%eax
or     %eax,(%rbx)
xor    %edi,%edi
call   1040 <inb@plt>
shl    $0x10,%eax
or     %eax,(%rbx)
xor    %edi,%edi
call   1040 <inb@plt>
shl    $0x18,%eax
or     %eax,(%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_longread(i8* %0, i16 zeroext %1, i16 zeroext %2, i32* %3) {
%5 = alloca i8*
%6 = alloca i16
%7 = alloca i16
%8 = alloca i32*
%9 = alloca i16
%10 = alloca i8
store i8* %0, i8** %5
store i16 %1, i16* %6
store i16 %2, i16* %7
store i32* %3, i32** %8
store i16 4, 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 = load i32*, i32** %8
store i32 %31, i32* %32
%33 = call i32 @inb(i32 0)
%34 = shl i32 %33, 8
%35 = load i32*, i32** %8
%36 = load i32, i32* %35
%37 = or i32 %36, %34
store i32 %37, i32* %35
%38 = call i32 @inb(i32 0)
%39 = shl i32 %38, 16
%40 = load i32*, i32** %8
%41 = load i32, i32* %40
%42 = or i32 %41, %39
store i32 %42, i32* %40
%43 = call i32 @inb(i32 0)
%44 = shl i32 %43, 24
%45 = load i32*, i32** %8
%46 = load i32, i32* %45
%47 = or i32 %46, %44
store i32 %47, i32* %45
%48 = call i32 (...) @OAL_RELEASE_SEMAPHORE()
ret i32 0
}

LLVM IR (-O2):
define i32 @fc8300_ppi_longread(i8* nocapture readnone %0, i16 zeroext %1, i16 zeroext %2, i32* 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 4, i32 0)
%12 = tail call i32 @inb(i32 0)
store i32 %12, i32* %3
%13 = tail call i32 @inb(i32 0)
%14 = shl i32 %13, 8
%15 = load i32, i32* %3
%16 = or i32 %15, %14
store i32 %16, i32* %3
%17 = tail call i32 @inb(i32 0)
%18 = shl i32 %17, 16
%19 = load i32, i32* %3
%20 = or i32 %19, %18
store i32 %20, i32* %3
%21 = tail call i32 @inb(i32 0)
%22 = shl i32 %21, 24
%23 = load i32, i32* %3
%24 = or i32 %23, %22
store i32 %24, i32* %3
%25 = tail call i32 (...) @OAL_RELEASE_SEMAPHORE()
ret i32 0
}