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


x86 assembly (clang, -O0):
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %cx,%ax
mov    %dx,%cx
mov    %si,%dx
mov    %rdi,-0x8(%rbp)
mov    %dx,-0xa(%rbp)
mov    %cx,-0xc(%rbp)
mov    %ax,-0xe(%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
lea    -0xe(%rbp),%rcx
mov    $0x2,%r8d
movzbl %dl,%esi
movzwl %ax,%edx
call   1040 <i2c_bulkwrite@plt>
mov    %eax,-0x14(%rbp)
mov    $0x0,%al
call   1030 <OAL_RELEASE_SEMAPHORE@plt>
mov    -0x14(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %edx,%r14d
mov    %esi,%ebp
mov    %rdi,%rbx
mov    %cx,0xe(%rsp)
xor    %eax,%eax
call   1050 <OAL_OBTAIN_SEMAPHORE@plt>
shr    $0x8,%ebp
lea    0xe(%rsp),%rcx
mov    %rbx,%rdi
mov    %ebp,%esi
mov    %r14d,%edx
mov    $0x2,%r8d
call   1040 <i2c_bulkwrite@plt>
mov    %eax,%ebx
xor    %eax,%eax
call   1030 <OAL_RELEASE_SEMAPHORE@plt>
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

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

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