#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 *, int, int, unsigned char *, int);
int i2c_bulkwrite(void *, int, int, unsigned char *, int);
int fc8150_i2c_longread(void *hDevice, unsigned short addr,
                        unsigned int *data) {
  int res;
  unsigned char command = 0x01 | 0x04 | 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_bulkread(hDevice, 0x58, 0x02, (unsigned char *)data, 4);
  OAL_RELEASE_SEMAPHORE();
  return res;
}


x86 assembly (clang, -O0):
<fc8150_i2c_longread>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %si,%ax
mov    %rdi,-0x8(%rbp)
mov    %ax,-0xa(%rbp)
mov    %rdx,-0x18(%rbp)
movb   $0x5,-0x1d(%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,-0x1c(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0x58,%esi
mov    $0x1,%r8d
lea    -0x1d(%rbp),%rcx
mov    %r8d,%edx
call   1050 <i2c_bulkwrite@plt>
or     -0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rcx
mov    $0x58,%esi
mov    $0x2,%edx
mov    $0x4,%r8d
call   1030 <i2c_bulkread@plt>
or     -0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    $0x0,%al
call   1040 <OAL_RELEASE_SEMAPHORE@plt>
mov    -0x1c(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fc8150_i2c_longread>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rdi,%rbx
mov    %si,0x6(%rsp)
movb   $0x5,0x5(%rsp)
xor    %eax,%eax
call   1060 <OAL_OBTAIN_SEMAPHORE@plt>
lea    0x6(%rsp),%rcx
mov    %rbx,%rdi
mov    $0x58,%esi
xor    %edx,%edx
mov    $0x2,%r8d
call   1050 <i2c_bulkwrite@plt>
mov    %eax,%r15d
lea    0x5(%rsp),%rcx
mov    %rbx,%rdi
mov    $0x58,%esi
mov    $0x1,%edx
mov    $0x1,%r8d
call   1050 <i2c_bulkwrite@plt>
mov    %eax,%ebp
or     %r15d,%ebp
mov    %rbx,%rdi
mov    $0x58,%esi
mov    $0x2,%edx
mov    %r14,%rcx
mov    $0x4,%r8d
call   1030 <i2c_bulkread@plt>
mov    %eax,%ebx
or     %ebp,%ebx
xor    %eax,%eax
call   1040 <OAL_RELEASE_SEMAPHORE@plt>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @fc8150_i2c_longread(i8* %0, i16 zeroext %1, i32* %2) {
%4 = alloca i8*
%5 = alloca i16
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i8
store i8* %0, i8** %4
store i16 %1, i16* %5
store i32* %2, i32** %6
store i8 5, i8* %8
%9 = call i32 (...) @OAL_OBTAIN_SEMAPHORE()
%10 = load i8*, i8** %4
%11 = bitcast i16* %5 to i8*
%12 = call i32 @i2c_bulkwrite(i8* %10, i32 88, i32 0, i8* %11, i32 2)
store i32 %12, i32* %7
%13 = load i8*, i8** %4
%14 = call i32 @i2c_bulkwrite(i8* %13, i32 88, i32 1, i8* %8, i32 1)
%15 = load i32, i32* %7
%16 = or i32 %15, %14
store i32 %16, i32* %7
%17 = load i8*, i8** %4
%18 = load i32*, i32** %6
%19 = bitcast i32* %18 to i8*
%20 = call i32 @i2c_bulkread(i8* %17, i32 88, i32 2, i8* %19, i32 4)
%21 = load i32, i32* %7
%22 = or i32 %21, %20
store i32 %22, i32* %7
%23 = call i32 (...) @OAL_RELEASE_SEMAPHORE()
%24 = load i32, i32* %7
ret i32 %24
}

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