#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_byteread(void *handle, unsigned short devid, unsigned short addr,
                        unsigned char *data) {
  unsigned short length = 1;
  unsigned char command = 0x40;
  OAL_OBTAIN_SEMAPHORE();
  outb((addr & 0xff00) >> 8, 0x00);
  outb(addr & 0xff, 0x00);
  outb(command, 0x00);
  outb(length & 0xff, 0x00);
  *data = inb(0x00);
  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   $0x1,-0x1a(%rbp)
movb   $0x40,-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    %al,%cl
mov    -0x18(%rbp),%rax
mov    %cl,(%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    $0x40,%edi
xor    %esi,%esi
call   1030 <outb@plt>
mov    $0x1,%edi
xor    %esi,%esi
call   1030 <outb@plt>
xor    %edi,%edi
call   1040 <inb@plt>
mov    %al,(%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_byteread(i8* %0, i16 zeroext %1, i16 zeroext %2, i8* %3) {
%5 = alloca i8*
%6 = alloca i16
%7 = alloca i16
%8 = alloca i8*
%9 = alloca i16
%10 = alloca i8
store i8* %0, i8** %5
store i16 %1, i16* %6
store i16 %2, i16* %7
store i8* %3, i8** %8
store i16 1, 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 zeroext i8 @inb(i32 0)
%32 = load i8*, i8** %8
store i8 %31, i8* %32
%33 = call i32 (...) @OAL_RELEASE_SEMAPHORE()
ret i32 0
}

LLVM IR (-O2):
define i32 @fc8300_ppi_byteread(i8* nocapture readnone %0, i16 zeroext %1, i16 zeroext %2, i8* nocapture writeonly %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 64, i32 0)
%11 = tail call i32 @outb(i16 zeroext 1, i32 0)
%12 = tail call zeroext i8 @inb(i32 0)
store i8 %12, i8* %3
%13 = tail call i32 (...) @OAL_RELEASE_SEMAPHORE()
ret i32 0
}