#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_bulkwrite(void *, int, int, unsigned char *, int);
int i2c_dataread(void *, int, int, unsigned char *, unsigned int);
int fc8150_i2c_dataread(void *hDevice, unsigned short addr, unsigned char *data,
                        unsigned int length) {
  int res;
  unsigned char command = 0x01 | 0x00 | 0x00;
  OAL_OBTAIN_SEMAPHORE();
  res = i2c_bulkwrite(hDevice, 0x58, 0x00, (unsigned char *)&addr, 2);
  res |= i2c_bulkwrite(hDevice, 0x58, 0x01, &command, 1);
  res |= i2c_dataread(hDevice, 0x58, 0x02, data, length);
  OAL_RELEASE_SEMAPHORE();
  return res;
}


x86 assembly (clang, -O0):
<fc8150_i2c_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)
movb   $0x1,-0x21(%rbp)
mov    $0x0,%al
call   1060 <OAL_OBTAIN_SEMAPHORE@plt>
mov    -0x8(%rbp),%rdi
lea    -0xa(%rbp),%rcx
mov    $0x58,%esi
xor    %edx,%edx
mov    $0x2,%r8d
call   1050 <i2c_bulkwrite@plt>
mov    %eax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0x58,%esi
mov    $0x1,%r8d
lea    -0x21(%rbp),%rcx
mov    %r8d,%edx
call   1050 <i2c_bulkwrite@plt>
or     -0x20(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rcx
mov    -0x1c(%rbp),%r8d
mov    $0x58,%esi
mov    $0x2,%edx
call   1030 <i2c_dataread@plt>
or     -0x20(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    $0x0,%al
call   1040 <OAL_RELEASE_SEMAPHORE@plt>
mov    -0x20(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fc8150_i2c_dataread>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %ecx,%r14d
mov    %rdx,%r15
mov    %rdi,%rbp
mov    %si,0xe(%rsp)
movb   $0x1,0xd(%rsp)
xor    %eax,%eax
call   1060 <OAL_OBTAIN_SEMAPHORE@plt>
lea    0xe(%rsp),%rcx
mov    %rbp,%rdi
mov    $0x58,%esi
xor    %edx,%edx
mov    $0x2,%r8d
call   1050 <i2c_bulkwrite@plt>
mov    %eax,%r12d
lea    0xd(%rsp),%rcx
mov    %rbp,%rdi
mov    $0x58,%esi
mov    $0x1,%edx
mov    $0x1,%r8d
call   1050 <i2c_bulkwrite@plt>
mov    %eax,%ebx
or     %r12d,%ebx
mov    %rbp,%rdi
mov    $0x58,%esi
mov    $0x2,%edx
mov    %r15,%rcx
mov    %r14d,%r8d
call   1030 <i2c_dataread@plt>
mov    %eax,%ebp
or     %ebx,%ebp
xor    %eax,%eax
call   1040 <OAL_RELEASE_SEMAPHORE@plt>
mov    %ebp,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @fc8150_i2c_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
store i8 1, i8* %10
%11 = call i32 (...) @OAL_OBTAIN_SEMAPHORE()
%12 = load i8*, i8** %5
%13 = bitcast i16* %6 to i8*
%14 = call i32 @i2c_bulkwrite(i8* %12, i32 88, i32 0, i8* %13, i32 2)
store i32 %14, i32* %9
%15 = load i8*, i8** %5
%16 = call i32 @i2c_bulkwrite(i8* %15, i32 88, i32 1, i8* %10, i32 1)
%17 = load i32, i32* %9
%18 = or i32 %17, %16
store i32 %18, i32* %9
%19 = load i8*, i8** %5
%20 = load i8*, i8** %7
%21 = load i32, i32* %8
%22 = call i32 @i2c_dataread(i8* %19, i32 88, i32 2, i8* %20, i32 %21)
%23 = load i32, i32* %9
%24 = or i32 %23, %22
store i32 %24, i32* %9
%25 = call i32 (...) @OAL_RELEASE_SEMAPHORE()
%26 = load i32, i32* %9
ret i32 %26
}

LLVM IR (-O2):
define i32 @fc8150_i2c_dataread(i8* %0, i16 zeroext %1, i8* %2, i32 %3) {
%5 = alloca i16
%6 = alloca i8
store i16 %1, i16* %5
store i8 1, i8* %6
%7 = tail call i32 (...) @OAL_OBTAIN_SEMAPHORE()
%8 = bitcast i16* %5 to i8*
%9 = call i32 @i2c_bulkwrite(i8* %0, i32 88, i32 0, i8* %8, i32 2)
%10 = call i32 @i2c_bulkwrite(i8* %0, i32 88, i32 1, i8* %6, i32 1)
%11 = or i32 %10, %9
%12 = call i32 @i2c_dataread(i8* %0, i32 88, i32 2, i8* %2, i32 %3)
%13 = or i32 %11, %12
%14 = call i32 (...) @OAL_RELEASE_SEMAPHORE()
ret i32 %13
}