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

/* Variables and functions */
int /*<<< orphan*/ I2C_SMBUS;
int /*<<< orphan*/ I2C_SMBUS_BYTE_DATA;
scalar_t__ ioctl(int, int /*<<< orphan*/, struct i2c_smbus_ioctl_data *);
int I2CWrapperReadByte(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_BYTE_DATA;
  blk.data = &i2cdata;
  if (ioctl(handle, I2C_SMBUS, &blk) < 0) {
    return -1;
  }
  return (int)i2cdata.byte;
}


x86 assembly (clang, -O0):
<I2CWrapperReadByte>:
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    0x2eab(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
lea    -0x30(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2e9c(%rip),%rax
mov    (%rax),%esi
lea    -0x28(%rbp),%rdx
call   1030 <ioctl@plt>
cmp    $0x0,%rax
jge    116d <I2CWrapperReadByte+0x5d>
movl   $0xffffffff,-0x4(%rbp)
jmp    1174 <I2CWrapperReadByte+0x64>
mov    -0x30(%rbp),%rax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<I2CWrapperReadByte>:
sub    $0x28,%rsp
movl   $0x1,0x10(%rsp)
mov    %sil,0x14(%rsp)
mov    0x2eb8(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x20(%rsp)
lea    0x8(%rsp),%rax
mov    %rax,0x18(%rsp)
mov    0x2ea9(%rip),%rax
mov    (%rax),%esi
lea    0x10(%rsp),%rdx
call   1030 <ioctl@plt>
mov    %rax,%rcx
mov    $0xffffffff,%eax
test   %rcx,%rcx
js     115c <I2CWrapperReadByte+0x4c>
mov    0x8(%rsp),%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_BYTE_DATA = global i32 0
@I2C_SMBUS = global i32 0
define i32 @I2CWrapperReadByte(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_BYTE_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 %19
18: ; preds = %2
store i32 -1, i32* %3
br label %23
19: ; preds = %2
%20 = bitcast %union.i2c_smbus_data* %7 to i64*
%21 = load i64, i64* %20
%22 = trunc i64 %21 to i32
store i32 %22, i32* %3
br label %23
23: ; preds = %19, %18
%24 = load i32, i32* %3
ret i32 %24
}

LLVM IR (-O2):
%struct.i2c_smbus_ioctl_data = type { i32, i8, %union.i2c_smbus_data*, i32 }
%union.i2c_smbus_data = type { i64 }
@I2C_SMBUS_BYTE_DATA = global i32 0
@I2C_SMBUS = global i32 0
define i32 @I2CWrapperReadByte(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_BYTE_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
%15 = getelementptr inbounds %union.i2c_smbus_data, %union.i2c_smbus_data* %4, i64 0, i32 0
%16 = load i64, i64* %15
%17 = trunc i64 %16 to i32
%18 = select i1 %14, i32 -1, i32 %17
ret i32 %18
}