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

/* 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 I2CWrapperReadWord(int handle, unsigned char cmd) {
  struct i2c_smbus_ioctl_data blk;
  union i2c_smbus_data i2cdata;
  blk.read_write = 1;
  blk.command = cmd;
  blk.size = I2C_SMBUS_WORD_DATA;
  blk.data = &i2cdata;
  if (ioctl(handle, I2C_SMBUS, &blk) < 0) {
    FailMessage("Unable to Read  I2C data\n");
    return -1;
  }
  return (int)i2cdata.word;
}


x86 assembly (clang, -O0):
<I2CWrapperReadWord>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %sil,%al
mov    %edi,-0x8(%rbp)
mov    %al,-0x9(%rbp)
movl   $0x1,-0x28(%rbp)
mov    -0x9(%rbp),%al
mov    %al,-0x24(%rbp)
mov    0x2e9b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
lea    -0x30(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2e8c(%rip),%rax
mov    (%rax),%esi
lea    -0x28(%rbp),%rdx
call   1040 <ioctl@plt>
cmp    $0x0,%rax
jge    1189 <I2CWrapperReadWord+0x69>
lea    0xe88(%rip),%rdi
call   1030 <FailMessage@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1190 <I2CWrapperReadWord+0x70>
mov    -0x30(%rbp),%rax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<I2CWrapperReadWord>:
sub    $0x28,%rsp
movl   $0x1,0x10(%rsp)
mov    %sil,0x14(%rsp)
mov    0x2ea8(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x20(%rsp)
lea    0x8(%rsp),%rax
mov    %rax,0x18(%rsp)
mov    0x2e99(%rip),%rax
mov    (%rax),%esi
lea    0x10(%rsp),%rdx
call   1040 <ioctl@plt>
test   %rax,%rax
js     1169 <I2CWrapperReadWord+0x49>
mov    0x8(%rsp),%eax
add    $0x28,%rsp
ret
lea    0xe90(%rip),%rdi
call   1030 <FailMessage@plt>
mov    $0xffffffff,%eax
add    $0x28,%rsp
ret

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

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