#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 char byte;
};
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_BYTE_DATA;
scalar_t__ ioctl(int, int /*<<< orphan*/, struct i2c_smbus_ioctl_data *);
int I2CWrapperWriteByte(int handle, unsigned char cmd, unsigned char value) {
  struct i2c_smbus_ioctl_data blk;
  union i2c_smbus_data i2cdata;
  i2cdata.byte = value;
  blk.read_write = 0;
  blk.command = cmd;
  blk.size = I2C_SMBUS_BYTE_DATA;
  blk.data = &i2cdata;
  if (ioctl(handle, I2C_SMBUS, &blk) < 0) {
    FailMessage("Unable to write I2C byte data\n");
    return -1;
  }
  return 1;
}


x86 assembly (clang, -O0):
<I2CWrapperWriteByte>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %dl,%al
mov    %sil,%cl
mov    %edi,-0x8(%rbp)
mov    %cl,-0x9(%rbp)
mov    %al,-0xa(%rbp)
mov    -0xa(%rbp),%al
mov    %al,-0x38(%rbp)
movq   $0x0,-0x18(%rbp)
mov    -0x9(%rbp),%al
mov    %al,-0x30(%rbp)
mov    0x2e8f(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
lea    -0x38(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2e80(%rip),%rax
mov    (%rax),%esi
lea    -0x30(%rbp),%rdx
call   1040 <ioctl@plt>
cmp    $0x0,%rax
jge    1195 <I2CWrapperWriteByte+0x75>
lea    0xe7c(%rip),%rdi
call   1030 <FailMessage@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    119c <I2CWrapperWriteByte+0x7c>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<I2CWrapperWriteByte>:
sub    $0x28,%rsp
mov    %dl,(%rsp)
movq   $0x0,0x20(%rsp)
mov    %sil,0x8(%rsp)
mov    0x2ea4(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x18(%rsp)
mov    %rsp,%rax
mov    %rax,0x10(%rsp)
mov    0x2e97(%rip),%rax
mov    (%rax),%esi
lea    0x8(%rsp),%rdx
call   1040 <ioctl@plt>
mov    %rax,%rcx
mov    $0x1,%eax
test   %rcx,%rcx
js     116f <I2CWrapperWriteByte+0x4f>
add    $0x28,%rsp
ret
lea    0xe8a(%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 { i8 }
@I2C_SMBUS_BYTE_DATA = global i32 0
@I2C_SMBUS = global i32 0
@.str = [31 x i8] c"Unable to write I2C byte data\0A\00"
define i32 @I2CWrapperWriteByte(i32 %0, i8 zeroext %1, i8 zeroext %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8
%7 = alloca i8
%8 = alloca %struct.i2c_smbus_ioctl_data
%9 = alloca %union.i2c_smbus_data
store i32 %0, i32* %5
store i8 %1, i8* %6
store i8 %2, i8* %7
%10 = load i8, i8* %7
%11 = bitcast %union.i2c_smbus_data* %9 to i8*
store i8 %10, i8* %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_BYTE_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 ([31 x i8], [31 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %4
br label %25
24: ; preds = %3
store i32 1, 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 { i8 }
@I2C_SMBUS_BYTE_DATA = global i32 0
@I2C_SMBUS = global i32 0
@.str = [31 x i8] c"Unable to write I2C byte data\0A\00"
define i32 @I2CWrapperWriteByte(i32 %0, i8 zeroext %1, i8 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 = getelementptr inbounds %union.i2c_smbus_data, %union.i2c_smbus_data* %5, i64 0, i32 0
store i8 %2, i8* %7
%8 = getelementptr inbounds %struct.i2c_smbus_ioctl_data, %struct.i2c_smbus_ioctl_data* %4, i64 0, i32 3
store i64 0, i64* %8
store i8 %1, i8* %6
%9 = load i32, i32* @I2C_SMBUS_BYTE_DATA
%10 = getelementptr inbounds %struct.i2c_smbus_ioctl_data, %struct.i2c_smbus_ioctl_data* %4, i64 0, i32 2
store i32 %9, i32* %10
%11 = 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** %11
%12 = load i32, i32* @I2C_SMBUS
%13 = call i64 @ioctl(i32 %0, i32 %12, %struct.i2c_smbus_ioctl_data* %4)
%14 = icmp slt i64 %13, 0
br i1 %14, label %15, label %17
15: ; preds = %3
%16 = call i32 @FailMessage(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0))
br label %17
17: ; preds = %3, %15
%18 = phi i32 [ -1, %15 ], [ 1, %3 ]
ret i32 %18
}