#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_bulkread(void *handle, unsigned short devid, unsigned short addr,
                        unsigned char *data, unsigned short length) {
  int i;
  unsigned char command = 0x80 | 0x40;
  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) = length & 0xff;
  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    %r8w,%ax
mov    %rdi,-0x8(%rbp)
mov    %si,-0xa(%rbp)
mov    %dx,-0xc(%rbp)
mov    %rcx,-0x18(%rbp)
mov    %ax,-0x1a(%rbp)
movb   $0xc0,-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)
movzwl -0x1a(%rbp),%eax
and    $0xff,%eax
mov    %al,%cl
xor    %eax,%eax
mov    %cl,(%rax)
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
movzwl -0x1a(%rbp),%ecx
cmp    %ecx,%eax
jge    11b5 <fc8300_ppi_bulkread+0x95>
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    1189 <fc8300_ppi_bulkread+0x69>
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,%ebp
mov    %rcx,%rbx
mov    %edx,%r14d
xor    %eax,%eax
call   1040 <OAL_OBTAIN_SEMAPHORE@plt>
mov    %r14d,%eax
mov    %ah,0x0
mov    %al,0x0
movb   $0xc0,0x0
c0
mov    %bpl,0x0
test   %ebp,%ebp
je     11e4 <fc8300_ppi_bulkread+0xc4>
movzwl %bp,%ecx
lea    -0x1(%rcx),%rdx
mov    %ecx,%esi
and    $0x3,%esi
cmp    $0x3,%rdx
jae    1173 <fc8300_ppi_bulkread+0x53>
xor    %edx,%edx
jmp    11b8 <fc8300_ppi_bulkread+0x98>
and    $0xfffffffc,%ecx
xor    %edx,%edx
nopl   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_bulkread+0x60>
test   %rsi,%rsi
je     11e4 <fc8300_ppi_bulkread+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_bulkread+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_bulkread(i8* %0, i16 zeroext %1, i16 zeroext %2, i8* %3, i16 zeroext %4) {
%6 = alloca i8*
%7 = alloca i16
%8 = alloca i16
%9 = alloca i8*
%10 = alloca i16
%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 i16 %4, i16* %10
store i8 -64, 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
%24 = load i16, i16* %10
%25 = zext i16 %24 to i32
%26 = and i32 %25, 255
%27 = trunc i32 %26 to i8
store volatile i8 %27, i8* null
store i32 0, i32* %11
br label %28
28: ; preds = %39, %5
%29 = load i32, i32* %11
%30 = load i16, i16* %10
%31 = zext i16 %30 to i32
%32 = icmp slt i32 %29, %31
br i1 %32, label %33, label %42
33: ; preds = %28
%34 = load volatile i8, i8* null
%35 = load i8*, i8** %9
%36 = load i32, i32* %11
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds i8, i8* %35, i64 %37
store i8 %34, i8* %38
br label %39
39: ; preds = %33
%40 = load i32, i32* %11
%41 = add nsw i32 %40, 1
store i32 %41, i32* %11
br label %28
42: ; preds = %28
%43 = call i32 (...) @OAL_RELEASE_SEMAPHORE()
ret i32 0
}

LLVM IR (-O2):
define i32 @fc8300_ppi_bulkread(i8* nocapture readnone %0, i16 zeroext %1, i16 zeroext %2, i8* nocapture writeonly %3, i16 zeroext %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 -64, i8* null
%10 = trunc i16 %4 to i8
store volatile i8 %10, i8* null
%11 = icmp eq i16 %4, 0
br i1 %11, label %47, label %12
12: ; preds = %5
%13 = zext i16 %4 to i64
%14 = add nsw i64 %13, -1
%15 = and i64 %13, 3
%16 = icmp ult i64 %14, 3
br i1 %16, label %36, label %17
17: ; preds = %12
%18 = and i64 %13, 65532
br label %19
19: ; preds = %19, %17
%20 = phi i64 [ 0, %17 ], [ %33, %19 ]
%21 = phi i64 [ 0, %17 ], [ %34, %19 ]
%22 = load volatile i8, i8* null
%23 = getelementptr inbounds i8, i8* %3, i64 %20
store i8 %22, i8* %23
%24 = or i64 %20, 1
%25 = load volatile i8, i8* null
%26 = getelementptr inbounds i8, i8* %3, i64 %24
store i8 %25, i8* %26
%27 = or i64 %20, 2
%28 = load volatile i8, i8* null
%29 = getelementptr inbounds i8, i8* %3, i64 %27
store i8 %28, i8* %29
%30 = or i64 %20, 3
%31 = load volatile i8, i8* null
%32 = getelementptr inbounds i8, i8* %3, i64 %30
store i8 %31, i8* %32
%33 = add nuw nsw i64 %20, 4
%34 = add i64 %21, 4
%35 = icmp eq i64 %34, %18
br i1 %35, label %36, label %19
36: ; preds = %19, %12
%37 = phi i64 [ 0, %12 ], [ %33, %19 ]
%38 = icmp eq i64 %15, 0
br i1 %38, label %47, label %39
39: ; preds = %36, %39
%40 = phi i64 [ %44, %39 ], [ %37, %36 ]
%41 = phi i64 [ %45, %39 ], [ 0, %36 ]
%42 = load volatile i8, i8* null
%43 = getelementptr inbounds i8, i8* %3, i64 %40
store i8 %42, i8* %43
%44 = add nuw nsw i64 %40, 1
%45 = add i64 %41, 1
%46 = icmp eq i64 %45, %15
br i1 %46, label %47, label %39
47: ; preds = %36, %39, %5
%48 = tail call i32 (...) @OAL_RELEASE_SEMAPHORE()
ret i32 0
}