#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_bulkwrite(void *handle, unsigned short devid,
                         unsigned short addr, unsigned char *data,
                         unsigned short length) {
  int i;
  unsigned char command = 0x80 | 0x00;
  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++)
    (*(volatile unsigned char *)0x00) = data[i];
  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   $0x80,-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_bulkwrite+0x95>
mov    -0x18(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    (%rax,%rcx,1),%cl
xor    %eax,%eax
mov    %cl,(%rax)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1189 <fc8300_ppi_bulkwrite+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   $0x80,0x0
80
mov    %bpl,0x0
test   %ebp,%ebp
je     1214 <fc8300_ppi_bulkwrite+0xf4>
movzwl %bp,%ecx
lea    -0x1(%rcx),%rdx
mov    %ecx,%esi
and    $0x7,%esi
cmp    $0x7,%rdx
jae    1173 <fc8300_ppi_bulkwrite+0x53>
xor    %edx,%edx
jmp    11e8 <fc8300_ppi_bulkwrite+0xc8>
and    $0xfffffff8,%ecx
xor    %edx,%edx
nopl   0x0(%rax,%rax,1)
movzbl (%rbx,%rdx,1),%eax
mov    %al,0x0
movzbl 0x1(%rbx,%rdx,1),%eax
mov    %al,0x0
movzbl 0x2(%rbx,%rdx,1),%eax
mov    %al,0x0
movzbl 0x3(%rbx,%rdx,1),%eax
mov    %al,0x0
movzbl 0x4(%rbx,%rdx,1),%eax
mov    %al,0x0
movzbl 0x5(%rbx,%rdx,1),%eax
mov    %al,0x0
movzbl 0x6(%rbx,%rdx,1),%eax
mov    %al,0x0
movzbl 0x7(%rbx,%rdx,1),%eax
mov    %al,0x0
add    $0x8,%rdx
cmp    %rdx,%rcx
jne    1180 <fc8300_ppi_bulkwrite+0x60>
test   %rsi,%rsi
je     1214 <fc8300_ppi_bulkwrite+0xf4>
add    %rdx,%rbx
xor    %ecx,%ecx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movzbl (%rbx,%rcx,1),%eax
mov    %al,0x0
add    $0x1,%rcx
cmp    %rcx,%rsi
jne    1200 <fc8300_ppi_bulkwrite+0xe0>
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_bulkwrite(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 -128, 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 i8*, i8** %9
%35 = load i32, i32* %11
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds i8, i8* %34, i64 %36
%38 = load i8, i8* %37
store volatile i8 %38, i8* null
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_bulkwrite(i8* nocapture readnone %0, i16 zeroext %1, i16 zeroext %2, i8* nocapture %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 -128, i8* null
%10 = trunc i16 %4 to i8
store volatile i8 %10, i8* null
%11 = icmp eq i16 %4, 0
br i1 %11, label %59, label %12
12: ; preds = %5
%13 = zext i16 %4 to i64
%14 = add nsw i64 %13, -1
%15 = and i64 %13, 7
%16 = icmp ult i64 %14, 7
br i1 %16, label %48, label %17
17: ; preds = %12
%18 = and i64 %13, 65528
br label %19
19: ; preds = %19, %17
%20 = phi i64 [ 0, %17 ], [ %45, %19 ]
%21 = phi i64 [ 0, %17 ], [ %46, %19 ]
%22 = getelementptr inbounds i8, i8* %3, i64 %20
%23 = load i8, i8* %22
store volatile i8 %23, i8* null
%24 = or i64 %20, 1
%25 = getelementptr inbounds i8, i8* %3, i64 %24
%26 = load i8, i8* %25
store volatile i8 %26, i8* null
%27 = or i64 %20, 2
%28 = getelementptr inbounds i8, i8* %3, i64 %27
%29 = load i8, i8* %28
store volatile i8 %29, i8* null
%30 = or i64 %20, 3
%31 = getelementptr inbounds i8, i8* %3, i64 %30
%32 = load i8, i8* %31
store volatile i8 %32, i8* null
%33 = or i64 %20, 4
%34 = getelementptr inbounds i8, i8* %3, i64 %33
%35 = load i8, i8* %34
store volatile i8 %35, i8* null
%36 = or i64 %20, 5
%37 = getelementptr inbounds i8, i8* %3, i64 %36
%38 = load i8, i8* %37
store volatile i8 %38, i8* null
%39 = or i64 %20, 6
%40 = getelementptr inbounds i8, i8* %3, i64 %39
%41 = load i8, i8* %40
store volatile i8 %41, i8* null
%42 = or i64 %20, 7
%43 = getelementptr inbounds i8, i8* %3, i64 %42
%44 = load i8, i8* %43
store volatile i8 %44, i8* null
%45 = add nuw nsw i64 %20, 8
%46 = add i64 %21, 8
%47 = icmp eq i64 %46, %18
br i1 %47, label %48, label %19
48: ; preds = %19, %12
%49 = phi i64 [ 0, %12 ], [ %45, %19 ]
%50 = icmp eq i64 %15, 0
br i1 %50, label %59, label %51
51: ; preds = %48, %51
%52 = phi i64 [ %56, %51 ], [ %49, %48 ]
%53 = phi i64 [ %57, %51 ], [ 0, %48 ]
%54 = getelementptr inbounds i8, i8* %3, i64 %52
%55 = load i8, i8* %54
store volatile i8 %55, i8* null
%56 = add nuw nsw i64 %52, 1
%57 = add i64 %53, 1
%58 = icmp eq i64 %57, %15
br i1 %58, label %59, label %51
59: ; preds = %48, %51, %5
%60 = tail call i32 (...) @OAL_RELEASE_SEMAPHORE()
ret i32 0
}