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


x86 assembly (clang, -O0):
<fc8180_ppi_bulkwrite>:
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     $0x80,%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    1220 <fc8180_ppi_bulkwrite+0x100>
mov    -0x18(%rbp),%rax
movslq -0x20(%rbp),%rcx
movzbl (%rax,%rcx,1),%eax
sar    $0x4,%eax
and    $0xf,%eax
mov    %al,%cl
xor    %eax,%eax
mov    %cl,(%rax)
mov    -0x18(%rbp),%rax
movslq -0x20(%rbp),%rcx
movzbl (%rax,%rcx,1),%eax
and    $0xf,%eax
mov    %al,%cl
xor    %eax,%eax
mov    %cl,(%rax)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    11d6 <fc8180_ppi_bulkwrite+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_bulkwrite>:
push   %rbp
push   %r14
push   %rbx
mov    %ecx,%ebp
mov    %rdx,%rbx
mov    %esi,%r14d
xor    %eax,%eax
call   1040 <OAL_OBTAIN_SEMAPHORE@plt>
mov    %ebp,%ecx
mov    %r14d,%edx
mov    %dl,0x0
mov    %r14d,%eax
shr    $0x4,%eax
mov    %al,0x0
mov    %dh,0x0
shr    $0xc,%edx
mov    %dl,0x0
movb   $0x8,0x0
08
movb   $0x80,0x0
80
mov    %ebp,%eax
shr    $0xc,%eax
mov    %al,0x0
mov    %ch,0x0
mov    %ebp,%eax
shr    $0x4,%eax
mov    %al,0x0
mov    %cl,0x0
test   %ebp,%ebp
je     1262 <fc8180_ppi_bulkwrite+0x142>
movzwl %cx,%edi
lea    -0x1(%rdi),%rdx
mov    %edi,%esi
and    $0x3,%esi
cmp    $0x3,%rdx
jae    11b4 <fc8180_ppi_bulkwrite+0x94>
xor    %edx,%edx
jmp    1231 <fc8180_ppi_bulkwrite+0x111>
and    $0xfffffffc,%edi
xor    %edx,%edx
nopl   0x0(%rax)
movzbl (%rbx,%rdx,1),%ecx
mov    %ecx,%eax
shr    $0x4,%al
mov    %al,0x0
and    $0xf,%cl
mov    %cl,0x0
movzbl 0x1(%rbx,%rdx,1),%eax
mov    %eax,%ecx
shr    $0x4,%cl
mov    %cl,0x0
and    $0xf,%al
mov    %al,0x0
movzbl 0x2(%rbx,%rdx,1),%eax
mov    %eax,%ecx
shr    $0x4,%cl
mov    %cl,0x0
and    $0xf,%al
mov    %al,0x0
movzbl 0x3(%rbx,%rdx,1),%eax
mov    %eax,%ecx
shr    $0x4,%cl
mov    %cl,0x0
and    $0xf,%al
mov    %al,0x0
add    $0x4,%rdx
cmp    %rdx,%rdi
jne    11c0 <fc8180_ppi_bulkwrite+0xa0>
test   %rsi,%rsi
je     1262 <fc8180_ppi_bulkwrite+0x142>
add    %rdx,%rbx
xor    %ecx,%ecx
nopl   0x0(%rax,%rax,1)
movzbl (%rbx,%rcx,1),%eax
mov    %eax,%edx
shr    $0x4,%dl
mov    %dl,0x0
and    $0xf,%al
mov    %al,0x0
add    $0x1,%rcx
cmp    %rcx,%rsi
jne    1240 <fc8180_ppi_bulkwrite+0x120>
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_bulkwrite(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 128, %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 = %74, %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 %77
56: ; preds = %51
%57 = load i8*, i8** %7
%58 = load i32, i32* %9
%59 = sext i32 %58 to i64
%60 = getelementptr inbounds i8, i8* %57, i64 %59
%61 = load i8, i8* %60
%62 = zext i8 %61 to i32
%63 = ashr i32 %62, 4
%64 = and i32 %63, 15
%65 = trunc i32 %64 to i8
store volatile i8 %65, i8* null
%66 = load i8*, i8** %7
%67 = load i32, i32* %9
%68 = sext i32 %67 to i64
%69 = getelementptr inbounds i8, i8* %66, i64 %68
%70 = load i8, i8* %69
%71 = zext i8 %70 to i32
%72 = and i32 %71, 15
%73 = trunc i32 %72 to i8
store volatile i8 %73, i8* null
br label %74
74: ; preds = %56
%75 = load i32, i32* %9
%76 = add nsw i32 %75, 1
store i32 %76, i32* %9
br label %51
77: ; preds = %51
%78 = call i32 (...) @OAL_RELEASE_SEMAPHORE()
ret i32 0
}

LLVM IR (-O2):
define i32 @fc8180_ppi_bulkwrite(i8* nocapture readnone %0, i16 zeroext %1, i8* nocapture %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 8, i8* null
store volatile i8 -128, 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 %66, label %21
21: ; preds = %4
%22 = zext i16 %3 to i64
%23 = add nsw i64 %22, -1
%24 = and i64 %22, 3
%25 = icmp ult i64 %23, 3
br i1 %25, label %53, label %26
26: ; preds = %21
%27 = and i64 %22, 65532
br label %28
28: ; preds = %28, %26
%29 = phi i64 [ 0, %26 ], [ %50, %28 ]
%30 = phi i64 [ 0, %26 ], [ %51, %28 ]
%31 = getelementptr inbounds i8, i8* %2, i64 %29
%32 = load i8, i8* %31
%33 = lshr i8 %32, 4
store volatile i8 %33, i8* null
%34 = and i8 %32, 15
store volatile i8 %34, i8* null
%35 = or i64 %29, 1
%36 = getelementptr inbounds i8, i8* %2, i64 %35
%37 = load i8, i8* %36
%38 = lshr i8 %37, 4
store volatile i8 %38, i8* null
%39 = and i8 %37, 15
store volatile i8 %39, i8* null
%40 = or i64 %29, 2
%41 = getelementptr inbounds i8, i8* %2, i64 %40
%42 = load i8, i8* %41
%43 = lshr i8 %42, 4
store volatile i8 %43, i8* null
%44 = and i8 %42, 15
store volatile i8 %44, i8* null
%45 = or i64 %29, 3
%46 = getelementptr inbounds i8, i8* %2, i64 %45
%47 = load i8, i8* %46
%48 = lshr i8 %47, 4
store volatile i8 %48, i8* null
%49 = and i8 %47, 15
store volatile i8 %49, i8* null
%50 = add nuw nsw i64 %29, 4
%51 = add i64 %30, 4
%52 = icmp eq i64 %51, %27
br i1 %52, label %53, label %28
53: ; preds = %28, %21
%54 = phi i64 [ 0, %21 ], [ %50, %28 ]
%55 = icmp eq i64 %24, 0
br i1 %55, label %66, label %56
56: ; preds = %53, %56
%57 = phi i64 [ %63, %56 ], [ %54, %53 ]
%58 = phi i64 [ %64, %56 ], [ 0, %53 ]
%59 = getelementptr inbounds i8, i8* %2, i64 %57
%60 = load i8, i8* %59
%61 = lshr i8 %60, 4
store volatile i8 %61, i8* null
%62 = and i8 %60, 15
store volatile i8 %62, i8* null
%63 = add nuw nsw i64 %57, 1
%64 = add i64 %58, 1
%65 = icmp eq i64 %64, %24
br i1 %65, label %66, label %56
66: ; preds = %53, %56, %4
%67 = tail call i32 (...) @OAL_RELEASE_SEMAPHORE()
ret i32 0
}