#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 i2c_bulkread(void *, unsigned char, unsigned short, unsigned char *,
                 unsigned int);
int fc8300_i2c_dataread(void *handle, unsigned short devid, unsigned short addr,
                        unsigned char *data, unsigned int length) {
  int res;
  OAL_OBTAIN_SEMAPHORE();
  res = i2c_bulkread(handle, (unsigned char)(devid >> 8) & 0xff, addr, data,
                     length);
  OAL_RELEASE_SEMAPHORE();
  return res;
}


x86 assembly (clang, -O0):
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %dx,%ax
mov    %si,%dx
mov    %rdi,-0x8(%rbp)
mov    %dx,-0xa(%rbp)
mov    %ax,-0xc(%rbp)
mov    %rcx,-0x18(%rbp)
mov    %r8d,-0x1c(%rbp)
mov    $0x0,%al
call   1050 <OAL_OBTAIN_SEMAPHORE@plt>
mov    -0x8(%rbp),%rdi
movzwl -0xa(%rbp),%eax
sar    $0x8,%eax
movzbl %al,%eax
and    $0xff,%eax
mov    %al,%dl
mov    -0xc(%rbp),%ax
mov    -0x18(%rbp),%rcx
mov    -0x1c(%rbp),%r8d
movzbl %dl,%esi
movzwl %ax,%edx
call   1030 <i2c_bulkread@plt>
mov    %eax,-0x20(%rbp)
mov    $0x0,%al
call   1040 <OAL_RELEASE_SEMAPHORE@plt>
mov    -0x20(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %r8d,%r14d
mov    %rcx,%r15
mov    %edx,%r12d
mov    %esi,%ebx
mov    %rdi,%rbp
xor    %eax,%eax
call   1050 <OAL_OBTAIN_SEMAPHORE@plt>
shr    $0x8,%ebx
mov    %rbp,%rdi
mov    %ebx,%esi
mov    %r12d,%edx
mov    %r15,%rcx
mov    %r14d,%r8d
call   1030 <i2c_bulkread@plt>
mov    %eax,%ebx
xor    %eax,%eax
call   1040 <OAL_RELEASE_SEMAPHORE@plt>
mov    %ebx,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @fc8300_i2c_dataread(i8* %0, i16 zeroext %1, i16 zeroext %2, i8* %3, i32 %4) {
%6 = alloca i8*
%7 = alloca i16
%8 = alloca i16
%9 = alloca i8*
%10 = alloca i32
%11 = alloca i32
store i8* %0, i8** %6
store i16 %1, i16* %7
store i16 %2, i16* %8
store i8* %3, i8** %9
store i32 %4, i32* %10
%12 = call i32 (...) @OAL_OBTAIN_SEMAPHORE()
%13 = load i8*, i8** %6
%14 = load i16, i16* %7
%15 = zext i16 %14 to i32
%16 = ashr i32 %15, 8
%17 = trunc i32 %16 to i8
%18 = zext i8 %17 to i32
%19 = and i32 %18, 255
%20 = trunc i32 %19 to i8
%21 = load i16, i16* %8
%22 = load i8*, i8** %9
%23 = load i32, i32* %10
%24 = call i32 @i2c_bulkread(i8* %13, i8 zeroext %20, i16 zeroext %21, i8* %22, i32 %23)
store i32 %24, i32* %11
%25 = call i32 (...) @OAL_RELEASE_SEMAPHORE()
%26 = load i32, i32* %11
ret i32 %26
}

LLVM IR (-O2):
define i32 @fc8300_i2c_dataread(i8* %0, i16 zeroext %1, i16 zeroext %2, i8* %3, i32 %4) {
%6 = tail call i32 (...) @OAL_OBTAIN_SEMAPHORE()
%7 = lshr i16 %1, 8
%8 = trunc i16 %7 to i8
%9 = tail call i32 @i2c_bulkread(i8* %0, i8 zeroext %8, i16 zeroext %2, i8* %3, i32 %4)
%10 = tail call i32 (...) @OAL_RELEASE_SEMAPHORE()
ret i32 %9
}