#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();
signed int fc8180_ppi_bulkread(void *handle, unsigned short addr,
                               unsigned char *data, unsigned short length) {
  signed int i;
  unsigned char cmd = 0x80 | 0x40 | ((length & 0x0f0000) >> 16);
  OAL_OBTAIN_SEMAPHORE();
  (*(volatile unsigned char *)(0x00)) = addr;
  (*(volatile unsigned char *)(0x00)) = addr >> 4;
  (*(volatile unsigned char *)(0x00)) = addr >> 8;
  (*(volatile unsigned char *)(0x00)) = addr >> 12;
  (*(volatile unsigned char *)(0x00)) = cmd >> 4;
  (*(volatile unsigned char *)(0x00)) = cmd;
  (*(volatile unsigned char *)(0x00)) = length >> 12;
  (*(volatile unsigned char *)(0x00)) = length >> 8;
  (*(volatile unsigned char *)(0x00)) = length >> 4;
  (*(volatile unsigned char *)(0x00)) = length;
  for (i = 0; i < length; i++) {
    data[i] = ((*(volatile unsigned char *)(0x00)) & 0x0f) << 4;
    data[i] |= ((*(volatile unsigned char *)(0x00)) & 0x0f);
  }
  OAL_RELEASE_SEMAPHORE();
  return 0;
}


x86 assembly (clang, -O0):
<fc8180_ppi_bulkread>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %cx,%ax
mov    %si,%cx
mov    %rdi,-0x8(%rbp)
mov    %cx,-0xa(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ax,-0x1a(%rbp)
movzwl -0x1a(%rbp),%eax
and    $0xf0000,%eax
sar    $0x10,%eax
or     $0xc0,%eax
mov    %al,-0x21(%rbp)
mov    $0x0,%al
call   1040 <OAL_OBTAIN_SEMAPHORE@plt>
mov    -0xa(%rbp),%ax
mov    %al,%cl
xor    %eax,%eax
mov    %cl,(%rax)
movzwl -0xa(%rbp),%eax
sar    $0x4,%eax
mov    %al,%cl
xor    %eax,%eax
mov    %cl,(%rax)
movzwl -0xa(%rbp),%eax
sar    $0x8,%eax
mov    %al,%cl
xor    %eax,%eax
mov    %cl,(%rax)
movzwl -0xa(%rbp),%eax
sar    $0xc,%eax
mov    %al,%cl
xor    %eax,%eax
mov    %cl,(%rax)
movzbl -0x21(%rbp),%eax
sar    $0x4,%eax
mov    %al,%cl
xor    %eax,%eax
mov    %cl,(%rax)
mov    -0x21(%rbp),%cl
xor    %eax,%eax
mov    %cl,(%rax)
movzwl -0x1a(%rbp),%eax
sar    $0xc,%eax
mov    %al,%cl
xor    %eax,%eax
mov    %cl,(%rax)
movzwl -0x1a(%rbp),%eax
sar    $0x8,%eax
mov    %al,%cl
xor    %eax,%eax
mov    %cl,(%rax)
movzwl -0x1a(%rbp),%eax
sar    $0x4,%eax
mov    %al,%cl
xor    %eax,%eax
mov    %cl,(%rax)
mov    -0x1a(%rbp),%ax
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    1228 <fc8180_ppi_bulkread+0x108>
xor    %eax,%eax
mov    (%rax),%al
movzbl %al,%eax
and    $0xf,%eax
shl    $0x4,%eax
mov    %al,%dl
mov    -0x18(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
xor    %eax,%eax
mov    (%rax),%al
movzbl %al,%esi
and    $0xf,%esi
mov    -0x18(%rbp),%rax
movslq -0x20(%rbp),%rcx
movzbl (%rax,%rcx,1),%edx
or     %esi,%edx
mov    %dl,(%rax,%rcx,1)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    11d6 <fc8180_ppi_bulkread+0xb6>
mov    $0x0,%al
call   1030 <OAL_RELEASE_SEMAPHORE@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fc8180_ppi_bulkread>:
push   %rbp
push   %r14
push   %rbx
mov    %ecx,%ebx
mov    %rdx,%r14
mov    %esi,%ebp
xor    %eax,%eax
call   1040 <OAL_OBTAIN_SEMAPHORE@plt>
mov    %ebp,%ecx
mov    %cl,0x0
mov    %ebp,%eax
shr    $0x4,%eax
mov    %al,0x0
mov    %ch,0x0
shr    $0xc,%ecx
mov    %cl,0x0
movb   $0xc,0x0
0c
movb   $0xc0,0x0
c0
mov    %ebx,%eax
shr    $0xc,%eax
mov    %al,0x0
mov    %bh,0x0
mov    %ebx,%eax
shr    $0x4,%eax
mov    %al,0x0
mov    %bl,0x0
test   %ebx,%ebx
je     1212 <fc8180_ppi_bulkread+0xf2>
movzwl %bx,%esi
cmp    $0x1,%si
jne    11a3 <fc8180_ppi_bulkread+0x83>
xor    %eax,%eax
jmp    11f2 <fc8180_ppi_bulkread+0xd2>
mov    %esi,%edx
and    $0xfffffffe,%edx
xor    %eax,%eax
nopw   0x0(%rax,%rax,1)
movzbl 0x0,%ecx
shl    $0x4,%cl
movzbl 0x0,%ebx
and    $0xf,%bl
or     %cl,%bl
mov    %bl,(%r14,%rax,1)
movzbl 0x0,%ecx
shl    $0x4,%cl
movzbl 0x0,%ebx
and    $0xf,%bl
or     %cl,%bl
mov    %bl,0x1(%r14,%rax,1)
add    $0x2,%rax
cmp    %rax,%rdx
jne    11b0 <fc8180_ppi_bulkread+0x90>
test   $0x1,%sil
je     1212 <fc8180_ppi_bulkread+0xf2>
mov    0x0,%cl
shl    $0x4,%cl
mov    0x0,%dl
and    $0xf,%dl
or     %cl,%dl
mov    %dl,(%r14,%rax,1)
xor    %eax,%eax
call   1030 <OAL_RELEASE_SEMAPHORE@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @fc8180_ppi_bulkread(i8* %0, i16 zeroext %1, i8* %2, i16 zeroext %3) {
%5 = alloca i8*
%6 = alloca i16
%7 = alloca i8*
%8 = alloca i16
%9 = alloca i32
%10 = alloca i8
store i8* %0, i8** %5
store i16 %1, i16* %6
store i8* %2, i8** %7
store i16 %3, i16* %8
%11 = load i16, i16* %8
%12 = zext i16 %11 to i32
%13 = and i32 %12, 983040
%14 = ashr i32 %13, 16
%15 = or i32 192, %14
%16 = trunc i32 %15 to i8
store i8 %16, i8* %10
%17 = call i32 (...) @OAL_OBTAIN_SEMAPHORE()
%18 = load i16, i16* %6
%19 = trunc i16 %18 to i8
store volatile i8 %19, i8* null
%20 = load i16, i16* %6
%21 = zext i16 %20 to i32
%22 = ashr i32 %21, 4
%23 = trunc i32 %22 to i8
store volatile i8 %23, i8* null
%24 = load i16, i16* %6
%25 = zext i16 %24 to i32
%26 = ashr i32 %25, 8
%27 = trunc i32 %26 to i8
store volatile i8 %27, i8* null
%28 = load i16, i16* %6
%29 = zext i16 %28 to i32
%30 = ashr i32 %29, 12
%31 = trunc i32 %30 to i8
store volatile i8 %31, i8* null
%32 = load i8, i8* %10
%33 = zext i8 %32 to i32
%34 = ashr i32 %33, 4
%35 = trunc i32 %34 to i8
store volatile i8 %35, i8* null
%36 = load i8, i8* %10
store volatile i8 %36, i8* null
%37 = load i16, i16* %8
%38 = zext i16 %37 to i32
%39 = ashr i32 %38, 12
%40 = trunc i32 %39 to i8
store volatile i8 %40, i8* null
%41 = load i16, i16* %8
%42 = zext i16 %41 to i32
%43 = ashr i32 %42, 8
%44 = trunc i32 %43 to i8
store volatile i8 %44, i8* null
%45 = load i16, i16* %8
%46 = zext i16 %45 to i32
%47 = ashr i32 %46, 4
%48 = trunc i32 %47 to i8
store volatile i8 %48, i8* null
%49 = load i16, i16* %8
%50 = trunc i16 %49 to i8
store volatile i8 %50, i8* null
store i32 0, i32* %9
br label %51
51: ; preds = %77, %4
%52 = load i32, i32* %9
%53 = load i16, i16* %8
%54 = zext i16 %53 to i32
%55 = icmp slt i32 %52, %54
br i1 %55, label %56, label %80
56: ; preds = %51
%57 = load volatile i8, i8* null
%58 = zext i8 %57 to i32
%59 = and i32 %58, 15
%60 = shl i32 %59, 4
%61 = trunc i32 %60 to i8
%62 = load i8*, i8** %7
%63 = load i32, i32* %9
%64 = sext i32 %63 to i64
%65 = getelementptr inbounds i8, i8* %62, i64 %64
store i8 %61, i8* %65
%66 = load volatile i8, i8* null
%67 = zext i8 %66 to i32
%68 = and i32 %67, 15
%69 = load i8*, i8** %7
%70 = load i32, i32* %9
%71 = sext i32 %70 to i64
%72 = getelementptr inbounds i8, i8* %69, i64 %71
%73 = load i8, i8* %72
%74 = zext i8 %73 to i32
%75 = or i32 %74, %68
%76 = trunc i32 %75 to i8
store i8 %76, i8* %72
br label %77
77: ; preds = %56
%78 = load i32, i32* %9
%79 = add nsw i32 %78, 1
store i32 %79, i32* %9
br label %51
80: ; preds = %51
%81 = call i32 (...) @OAL_RELEASE_SEMAPHORE()
ret i32 0
}

LLVM IR (-O2):
define i32 @fc8180_ppi_bulkread(i8* nocapture readnone %0, i16 zeroext %1, i8* nocapture writeonly %2, i16 zeroext %3) {
%5 = tail call i32 (...) @OAL_OBTAIN_SEMAPHORE()
%6 = trunc i16 %1 to i8
store volatile i8 %6, i8* null
%7 = lshr i16 %1, 4
%8 = trunc i16 %7 to i8
store volatile i8 %8, i8* null
%9 = lshr i16 %1, 8
%10 = trunc i16 %9 to i8
store volatile i8 %10, i8* null
%11 = lshr i16 %1, 12
%12 = trunc i16 %11 to i8
store volatile i8 %12, i8* null
store volatile i8 12, i8* null
store volatile i8 -64, i8* null
%13 = lshr i16 %3, 12
%14 = trunc i16 %13 to i8
store volatile i8 %14, i8* null
%15 = lshr i16 %3, 8
%16 = trunc i16 %15 to i8
store volatile i8 %16, i8* null
%17 = lshr i16 %3, 4
%18 = trunc i16 %17 to i8
store volatile i8 %18, i8* null
%19 = trunc i16 %3 to i8
store volatile i8 %19, i8* null
%20 = icmp eq i16 %3, 0
br i1 %20, label %56, label %21
21: ; preds = %4
%22 = zext i16 %3 to i64
%23 = and i64 %22, 1
%24 = icmp eq i16 %3, 1
br i1 %24, label %46, label %25
25: ; preds = %21
%26 = and i64 %22, 65534
br label %27
27: ; preds = %27, %25
%28 = phi i64 [ 0, %25 ], [ %43, %27 ]
%29 = phi i64 [ 0, %25 ], [ %44, %27 ]
%30 = load volatile i8, i8* null
%31 = shl i8 %30, 4
%32 = getelementptr inbounds i8, i8* %2, i64 %28
%33 = load volatile i8, i8* null
%34 = and i8 %33, 15
%35 = or i8 %34, %31
store i8 %35, i8* %32
%36 = or i64 %28, 1
%37 = load volatile i8, i8* null
%38 = shl i8 %37, 4
%39 = getelementptr inbounds i8, i8* %2, i64 %36
%40 = load volatile i8, i8* null
%41 = and i8 %40, 15
%42 = or i8 %41, %38
store i8 %42, i8* %39
%43 = add nuw nsw i64 %28, 2
%44 = add i64 %29, 2
%45 = icmp eq i64 %44, %26
br i1 %45, label %46, label %27
46: ; preds = %27, %21
%47 = phi i64 [ 0, %21 ], [ %43, %27 ]
%48 = icmp eq i64 %23, 0
br i1 %48, label %56, label %49
49: ; preds = %46
%50 = load volatile i8, i8* null
%51 = shl i8 %50, 4
%52 = getelementptr inbounds i8, i8* %2, i64 %47
%53 = load volatile i8, i8* null
%54 = and i8 %53, 15
%55 = or i8 %54, %51
store i8 %55, i8* %52
br label %56
56: ; preds = %49, %46, %4
%57 = tail call i32 (...) @OAL_RELEASE_SEMAPHORE()
ret i32 0
}