#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 */
union i2c_smbus_data {
  unsigned short word;
};
struct i2c_smbus_ioctl_data {
  unsigned char command;
  union i2c_smbus_data *data;
  int /*<<< orphan*/ size;
  scalar_t__ read_write;
};

/* Variables and functions */
int /*<<< orphan*/ FailMessage(char *);
int /*<<< orphan*/ I2C_SMBUS;
int /*<<< orphan*/ I2C_SMBUS_WORD_DATA;
scalar_t__ ioctl(int, int /*<<< orphan*/, struct i2c_smbus_ioctl_data *);
int I2CWrapperWriteWord(int handle, unsigned char cmd, unsigned short value) {
  struct i2c_smbus_ioctl_data blk;
  union i2c_smbus_data i2cdata;
  i2cdata.word = value;
  blk.read_write = 0;
  blk.command = cmd;
  blk.size = I2C_SMBUS_WORD_DATA;
  blk.data = &i2cdata;
  if (ioctl(handle, I2C_SMBUS, &blk) < 0) {
    FailMessage("Unable to write I2C data\n");
    return -1;
  }
  return 2;
}


x86 assembly (clang, -O0):
<I2CWrapperWriteWord>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %dx,%ax
mov    %sil,%cl
mov    %edi,-0x8(%rbp)
mov    %cl,-0x9(%rbp)
mov    %ax,-0xc(%rbp)
mov    -0xc(%rbp),%ax
mov    %ax,-0x38(%rbp)
movq   $0x0,-0x18(%rbp)
mov    -0x9(%rbp),%al
mov    %al,-0x30(%rbp)
mov    0x2e8b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
lea    -0x38(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2e7c(%rip),%rax
mov    (%rax),%esi
lea    -0x30(%rbp),%rdx
call   1040 <ioctl@plt>
cmp    $0x0,%rax
jge    1199 <I2CWrapperWriteWord+0x79>
lea    0xe78(%rip),%rdi
call   1030 <FailMessage@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11a0 <I2CWrapperWriteWord+0x80>
movl   $0x2,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<I2CWrapperWriteWord>:
sub    $0x28,%rsp
mov    %dx,(%rsp)
movq   $0x0,0x20(%rsp)
mov    %sil,0x8(%rsp)
mov    0x2ea3(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x18(%rsp)
mov    %rsp,%rax
mov    %rax,0x10(%rsp)
mov    0x2e96(%rip),%rax
mov    (%rax),%esi
lea    0x8(%rsp),%rdx
call   1040 <ioctl@plt>
mov    %rax,%rcx
mov    $0x2,%eax
test   %rcx,%rcx
js     1170 <I2CWrapperWriteWord+0x50>
add    $0x28,%rsp
ret
lea    0xe89(%rip),%rdi
call   1030 <FailMessage@plt>
mov    $0xffffffff,%eax
add    $0x28,%rsp
ret

LLVM IR (-O0):
%struct.i2c_smbus_ioctl_data = type { i8, %union.i2c_smbus_data*, i32, i64 }
%union.i2c_smbus_data = type { i16 }
@I2C_SMBUS_WORD_DATA = global i32 0
@I2C_SMBUS = global i32 0
@.str = [26 x i8] c"Unable to write I2C data\0A\00"
define i32 @I2CWrapperWriteWord(i32 %0, i8 zeroext %1, i16 zeroext %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8
%7 = alloca i16
%8 = alloca %struct.i2c_smbus_ioctl_data
%9 = alloca %union.i2c_smbus_data
store i32 %0, i32* %5
store i8 %1, i8* %6
store i16 %2, i16* %7
%10 = load i16, i16* %7
%11 = bitcast %union.i2c_smbus_data* %9 to i16*
store i16 %10, i16* %11
%12 = getelementptr inbounds %struct.i2c_smbus_ioctl_data, %struct.i2c_smbus_ioctl_data* %8, i32 0, i32 3
store i64 0, i64* %12
%13 = load i8, i8* %6
%14 = getelementptr inbounds %struct.i2c_smbus_ioctl_data, %struct.i2c_smbus_ioctl_data* %8, i32 0, i32 0
store i8 %13, i8* %14
%15 = load i32, i32* @I2C_SMBUS_WORD_DATA
%16 = getelementptr inbounds %struct.i2c_smbus_ioctl_data, %struct.i2c_smbus_ioctl_data* %8, i32 0, i32 2
store i32 %15, i32* %16
%17 = getelementptr inbounds %struct.i2c_smbus_ioctl_data, %struct.i2c_smbus_ioctl_data* %8, i32 0, i32 1
store %union.i2c_smbus_data* %9, %union.i2c_smbus_data** %17
%18 = load i32, i32* %5
%19 = load i32, i32* @I2C_SMBUS
%20 = call i64 @ioctl(i32 %18, i32 %19, %struct.i2c_smbus_ioctl_data* %8)
%21 = icmp slt i64 %20, 0
br i1 %21, label %22, label %24
22: ; preds = %3
%23 = call i32 @FailMessage(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %4
br label %25
24: ; preds = %3
store i32 2, i32* %4
br label %25
25: ; preds = %24, %22
%26 = load i32, i32* %4
ret i32 %26
}

LLVM IR (-O2):
%struct.i2c_smbus_ioctl_data = type { i8, %union.i2c_smbus_data*, i32, i64 }
%union.i2c_smbus_data = type { i16 }
@I2C_SMBUS_WORD_DATA = global i32 0
@I2C_SMBUS = global i32 0
@.str = [26 x i8] c"Unable to write I2C data\0A\00"
define i32 @I2CWrapperWriteWord(i32 %0, i8 zeroext %1, i16 zeroext %2) {
%4 = alloca %struct.i2c_smbus_ioctl_data
%5 = alloca %union.i2c_smbus_data
%6 = getelementptr inbounds %struct.i2c_smbus_ioctl_data, %struct.i2c_smbus_ioctl_data* %4, i64 0, i32 0
%7 = bitcast %union.i2c_smbus_data* %5 to i8*
%8 = getelementptr inbounds %union.i2c_smbus_data, %union.i2c_smbus_data* %5, i64 0, i32 0
store i16 %2, i16* %8
%9 = getelementptr inbounds %struct.i2c_smbus_ioctl_data, %struct.i2c_smbus_ioctl_data* %4, i64 0, i32 3
store i64 0, i64* %9
store i8 %1, i8* %6
%10 = load i32, i32* @I2C_SMBUS_WORD_DATA
%11 = getelementptr inbounds %struct.i2c_smbus_ioctl_data, %struct.i2c_smbus_ioctl_data* %4, i64 0, i32 2
store i32 %10, i32* %11
%12 = getelementptr inbounds %struct.i2c_smbus_ioctl_data, %struct.i2c_smbus_ioctl_data* %4, i64 0, i32 1
store %union.i2c_smbus_data* %5, %union.i2c_smbus_data** %12
%13 = load i32, i32* @I2C_SMBUS
%14 = call i64 @ioctl(i32 %0, i32 %13, %struct.i2c_smbus_ioctl_data* %4)
%15 = icmp slt i64 %14, 0
br i1 %15, label %16, label %18
16: ; preds = %3
%17 = call i32 @FailMessage(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
br label %18
18: ; preds = %3, %16
%19 = phi i32 [ -1, %16 ], [ 2, %3 ]
ret i32 %19
}