#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_dataread(void *handle, unsigned short addr,
                               unsigned char *data, unsigned int length) {
  signed int i;
  unsigned char cmd = 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_dataread>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %si,%ax
mov    %rdi,-0x8(%rbp)
mov    %ax,-0xa(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
and    $0xf0000,%eax
shr    $0x10,%eax
or     $0x40,%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)
mov    -0x1c(%rbp),%eax
shr    $0xc,%eax
mov    %al,%cl
xor    %eax,%eax
mov    %cl,(%rax)
mov    -0x1c(%rbp),%eax
shr    $0x8,%eax
mov    %al,%cl
xor    %eax,%eax
mov    %cl,(%rax)
mov    -0x1c(%rbp),%eax
shr    $0x4,%eax
mov    %al,%cl
xor    %eax,%eax
mov    %cl,(%rax)
mov    -0x1c(%rbp),%eax
mov    %al,%cl
xor    %eax,%eax
mov    %cl,(%rax)
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jae    121a <fc8180_ppi_dataread+0xfa>
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    11cb <fc8180_ppi_dataread+0xab>
mov    $0x0,%al
call   1030 <OAL_RELEASE_SEMAPHORE@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fc8180_ppi_dataread>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %ecx,%r14d
mov    %rdx,%rbp
mov    %esi,%r15d
mov    %ecx,%ebx
shr    $0x10,%ebx
and    $0xf,%bl
or     $0x40,%bl
xor    %eax,%eax
call   1040 <OAL_OBTAIN_SEMAPHORE@plt>
mov    %r14d,%ecx
mov    %r15d,%edx
mov    %dl,0x0
mov    %r15d,%eax
shr    $0x4,%eax
mov    %al,0x0
mov    %dh,0x0
shr    $0xc,%edx
mov    %dl,0x0
movb   $0x4,0x0
04
mov    %bl,0x0
mov    %r14d,%eax
shr    $0xc,%eax
mov    %al,0x0
mov    %ch,0x0
mov    %r14d,%eax
shr    $0x4,%eax
mov    %al,0x0
mov    %cl,0x0
test   %r14d,%r14d
je     1221 <fc8180_ppi_dataread+0x101>
mov    %ecx,%esi
cmp    $0x1,%ecx
jne    11b4 <fc8180_ppi_dataread+0x94>
xor    %eax,%eax
jmp    1201 <fc8180_ppi_dataread+0xe1>
mov    %esi,%edx
and    $0xfffffffe,%edx
xor    %eax,%eax
nopl   0x0(%rax,%rax,1)
movzbl 0x0,%ecx
shl    $0x4,%cl
movzbl 0x0,%ebx
and    $0xf,%bl
or     %cl,%bl
mov    %bl,0x0(%rbp,%rax,1)
movzbl 0x0,%ecx
shl    $0x4,%cl
movzbl 0x0,%ebx
and    $0xf,%bl
or     %cl,%bl
mov    %bl,0x1(%rbp,%rax,1)
add    $0x2,%rax
cmp    %rax,%rdx
jne    11c0 <fc8180_ppi_dataread+0xa0>
test   $0x1,%sil
je     1221 <fc8180_ppi_dataread+0x101>
mov    0x0,%cl
shl    $0x4,%cl
mov    0x0,%dl
and    $0xf,%dl
or     %cl,%dl
mov    %dl,0x0(%rbp,%rax,1)
xor    %eax,%eax
call   1030 <OAL_RELEASE_SEMAPHORE@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

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