#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 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();
  (*(volatile unsigned char *)0x00) = (addr & 0xff00) >> 8;
  (*(volatile unsigned char *)0x00) = addr & 0xff;
  (*(volatile unsigned char *)0x00) = command;
  (*(volatile unsigned char *)0x00) = 0;
  for (i = 0; i < length; i++)
    data[i] = (*(volatile unsigned char *)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   1040 <OAL_OBTAIN_SEMAPHORE@plt>
movzwl -0xc(%rbp),%eax
and    $0xff00,%eax
sar    $0x8,%eax
mov    %al,%cl
xor    %eax,%eax
mov    %cl,(%rax)
movzwl -0xc(%rbp),%eax
and    $0xff,%eax
mov    %al,%cl
xor    %eax,%eax
mov    %cl,(%rax)
mov    -0x21(%rbp),%cl
xor    %eax,%eax
mov    %cl,(%rax)
xor    %eax,%eax
movb   $0x0,(%rax)
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jae    11aa <fc8300_ppi_dataread+0x8a>
xor    %eax,%eax
mov    (%rax),%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    1181 <fc8300_ppi_dataread+0x61>
mov    $0x0,%al
call   1030 <OAL_RELEASE_SEMAPHORE@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
push   %rbp
push   %r14
push   %rbx
mov    %r8d,%r14d
mov    %rcx,%rbx
mov    %edx,%ebp
xor    %eax,%eax
call   1040 <OAL_OBTAIN_SEMAPHORE@plt>
mov    %ebp,%eax
mov    %ah,0x0
mov    %al,0x0
movb   $0x70,0x0
70
movb   $0x0,0x0
test   %r14d,%r14d
je     11e4 <fc8300_ppi_dataread+0xc4>
mov    %r14d,%ecx
lea    -0x1(%rcx),%rdx
mov    %ecx,%esi
and    $0x3,%esi
cmp    $0x3,%rdx
jae    1172 <fc8300_ppi_dataread+0x52>
xor    %edx,%edx
jmp    11b8 <fc8300_ppi_dataread+0x98>
and    $0xfffffffc,%ecx
xor    %edx,%edx
nopw   0x0(%rax,%rax,1)
movzbl 0x0,%eax
mov    %al,(%rbx,%rdx,1)
movzbl 0x0,%eax
mov    %al,0x1(%rbx,%rdx,1)
movzbl 0x0,%eax
mov    %al,0x2(%rbx,%rdx,1)
movzbl 0x0,%eax
mov    %al,0x3(%rbx,%rdx,1)
add    $0x4,%rdx
cmp    %rdx,%rcx
jne    1180 <fc8300_ppi_dataread+0x60>
test   %rsi,%rsi
je     11e4 <fc8300_ppi_dataread+0xc4>
add    %rdx,%rbx
xor    %ecx,%ecx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movzbl 0x0,%eax
mov    %al,(%rbx,%rcx,1)
add    $0x1,%rcx
cmp    %rcx,%rsi
jne    11d0 <fc8300_ppi_dataread+0xb0>
xor    %eax,%eax
call   1030 <OAL_RELEASE_SEMAPHORE@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
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
store volatile i8 %18, i8* null
%19 = load i16, i16* %8
%20 = zext i16 %19 to i32
%21 = and i32 %20, 255
%22 = trunc i32 %21 to i8
store volatile i8 %22, i8* null
%23 = load i8, i8* %12
store volatile i8 %23, i8* null
store volatile i8 0, i8* null
store i32 0, i32* %11
br label %24
24: ; preds = %34, %5
%25 = load i32, i32* %11
%26 = load i32, i32* %10
%27 = icmp ult i32 %25, %26
br i1 %27, label %28, label %37
28: ; preds = %24
%29 = load volatile i8, i8* null
%30 = load i8*, i8** %9
%31 = load i32, i32* %11
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i8, i8* %30, i64 %32
store i8 %29, i8* %33
br label %34
34: ; preds = %28
%35 = load i32, i32* %11
%36 = add nsw i32 %35, 1
store i32 %36, i32* %11
br label %24
37: ; preds = %24
%38 = 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
store volatile i8 %8, i8* null
%9 = trunc i16 %2 to i8
store volatile i8 %9, i8* null
store volatile i8 112, i8* null
store volatile i8 0, i8* null
%10 = icmp eq i32 %4, 0
br i1 %10, label %46, label %11
11: ; preds = %5
%12 = zext i32 %4 to i64
%13 = add nsw i64 %12, -1
%14 = and i64 %12, 3
%15 = icmp ult i64 %13, 3
br i1 %15, label %35, label %16
16: ; preds = %11
%17 = and i64 %12, 4294967292
br label %18
18: ; preds = %18, %16
%19 = phi i64 [ 0, %16 ], [ %32, %18 ]
%20 = phi i64 [ 0, %16 ], [ %33, %18 ]
%21 = load volatile i8, i8* null
%22 = getelementptr inbounds i8, i8* %3, i64 %19
store i8 %21, i8* %22
%23 = or i64 %19, 1
%24 = load volatile i8, i8* null
%25 = getelementptr inbounds i8, i8* %3, i64 %23
store i8 %24, i8* %25
%26 = or i64 %19, 2
%27 = load volatile i8, i8* null
%28 = getelementptr inbounds i8, i8* %3, i64 %26
store i8 %27, i8* %28
%29 = or i64 %19, 3
%30 = load volatile i8, i8* null
%31 = getelementptr inbounds i8, i8* %3, i64 %29
store i8 %30, i8* %31
%32 = add nuw nsw i64 %19, 4
%33 = add i64 %20, 4
%34 = icmp eq i64 %33, %17
br i1 %34, label %35, label %18
35: ; preds = %18, %11
%36 = phi i64 [ 0, %11 ], [ %32, %18 ]
%37 = icmp eq i64 %14, 0
br i1 %37, label %46, label %38
38: ; preds = %35, %38
%39 = phi i64 [ %43, %38 ], [ %36, %35 ]
%40 = phi i64 [ %44, %38 ], [ 0, %35 ]
%41 = load volatile i8, i8* null
%42 = getelementptr inbounds i8, i8* %3, i64 %39
store i8 %41, i8* %42
%43 = add nuw nsw i64 %39, 1
%44 = add i64 %40, 1
%45 = icmp eq i64 %44, %14
br i1 %45, label %46, label %38
46: ; preds = %35, %38, %5
%47 = tail call i32 (...) @OAL_RELEASE_SEMAPHORE()
ret i32 0
}