#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 */
typedef int uint8_t;
typedef int uint16_t;
typedef int int16_t;

/* Variables and functions */
int i2c_write(int, int *, int);
int i2c_write_word(int file_handle, uint16_t word_value) {
  uint8_t byte_value[2];
  byte_value[0] = ((word_value & 0xFF00) >> 8);
  byte_value[1] = (word_value & 0x00FF);
  int16_t return_value = i2c_write(file_handle, byte_value, 2);
  if (return_value < 0)
    return -1;
  else if (return_value != 2)
    return -1;
  else
    return 0;
}


x86 assembly (clang, -O0):
<i2c_write_word>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0xc(%rbp),%eax
and    $0xff00,%eax
sar    $0x8,%eax
mov    %eax,-0x14(%rbp)
mov    -0xc(%rbp),%eax
and    $0xff,%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x14(%rbp),%rsi
mov    $0x2,%edx
call   1030 <i2c_write@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    1161 <i2c_write_word+0x51>
movl   $0xffffffff,-0x4(%rbp)
jmp    117e <i2c_write_word+0x6e>
cmpl   $0x2,-0x18(%rbp)
je     1177 <i2c_write_word+0x67>
movl   $0xffffffff,-0x4(%rbp)
jmp    117e <i2c_write_word+0x6e>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<i2c_write_word>:
push   %rax
mov    %esi,%eax
movzbl %ah,%ecx
mov    %ecx,(%rsp)
movzbl %al,%eax
mov    %eax,0x4(%rsp)
mov    %rsp,%rsi
mov    $0x2,%edx
call   1030 <i2c_write@plt>
xor    %ecx,%ecx
cmp    $0x2,%eax
setne  %cl
neg    %ecx
mov    %ecx,%eax
pop    %rcx
ret

LLVM IR (-O0):
define i32 @i2c_write_word(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca [2 x i32]
%7 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
%8 = load i32, i32* %5
%9 = and i32 %8, 65280
%10 = ashr i32 %9, 8
%11 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 0
store i32 %10, i32* %11
%12 = load i32, i32* %5
%13 = and i32 %12, 255
%14 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 1
store i32 %13, i32* %14
%15 = load i32, i32* %4
%16 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 0
%17 = call i32 @i2c_write(i32 %15, i32* %16, i32 2)
store i32 %17, i32* %7
%18 = load i32, i32* %7
%19 = icmp slt i32 %18, 0
br i1 %19, label %20, label %21
20: ; preds = %2
store i32 -1, i32* %3
br label %26
21: ; preds = %2
%22 = load i32, i32* %7
%23 = icmp ne i32 %22, 2
br i1 %23, label %24, label %25
24: ; preds = %21
store i32 -1, i32* %3
br label %26
25: ; preds = %21
store i32 0, i32* %3
br label %26
26: ; preds = %25, %24, %20
%27 = load i32, i32* %3
ret i32 %27
}

LLVM IR (-O2):
define i32 @i2c_write_word(i32 %0, i32 %1) {
%3 = alloca [2 x i32]
%4 = bitcast [2 x i32]* %3 to i8*
%5 = lshr i32 %1, 8
%6 = and i32 %5, 255
%7 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 0
store i32 %6, i32* %7
%8 = and i32 %1, 255
%9 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 1
store i32 %8, i32* %9
%10 = call i32 @i2c_write(i32 %0, i32* %7, i32 2)
%11 = icmp ne i32 %10, 2
%12 = sext i1 %11 to i32
ret i32 %12
}