#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 *block;
};
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_I2C_BLOCK_DATA;
scalar_t__ ioctl(int, int /*<<< orphan*/, struct i2c_smbus_ioctl_data *);
int /*<<< orphan*/ memcpy(void *, unsigned char *, unsigned char);
int I2CWrapperReadBlock(int handle, unsigned char cmd, unsigned char size,
                        void *array) {
  struct i2c_smbus_ioctl_data blk;
  union i2c_smbus_data i2cdata;
  blk.read_write = 1;
  blk.command = cmd;
  blk.size = I2C_SMBUS_I2C_BLOCK_DATA;
  blk.data = &i2cdata;
  i2cdata.block[0] = size;
  if (ioctl(handle, I2C_SMBUS, &blk) < 0) {
    FailMessage("Unable to Read I2C data\n");
    return -1;
  }
  memcpy(array, &i2cdata.block[1], size);
  return i2cdata.block[0];
}


x86 assembly (clang, -O0):
<I2CWrapperReadBlock>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %dl,%al
mov    %sil,%dl
mov    %edi,-0x8(%rbp)
mov    %dl,-0x9(%rbp)
mov    %al,-0xa(%rbp)
mov    %rcx,-0x18(%rbp)
movl   $0x1,-0x30(%rbp)
mov    -0x9(%rbp),%al
mov    %al,-0x2c(%rbp)
mov    0x2e7a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
lea    -0x38(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0xa(%rbp),%cl
mov    -0x38(%rbp),%rax
mov    %cl,(%rax)
mov    -0x8(%rbp),%edi
mov    0x2e6a(%rip),%rax
mov    (%rax),%esi
lea    -0x30(%rbp),%rdx
call   1040 <ioctl@plt>
cmp    $0x0,%rax
jge    11ab <I2CWrapperReadBlock+0x7b>
lea    0xe66(%rip),%rdi
call   1030 <FailMessage@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11cc <I2CWrapperReadBlock+0x9c>
mov    -0x18(%rbp),%rdi
mov    -0x38(%rbp),%rsi
add    $0x1,%rsi
mov    -0xa(%rbp),%al
movzbl %al,%edx
call   1050 <memcpy@plt>
mov    -0x38(%rbp),%rax
movzbl (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
LLVM IR (-O0):
%struct.i2c_smbus_ioctl_data = type { i32, i8, %union.i2c_smbus_data*, i32 }
%union.i2c_smbus_data = type { i8* }
@I2C_SMBUS_I2C_BLOCK_DATA = global i32 0
@I2C_SMBUS = global i32 0
@.str = [25 x i8] c"Unable to Read I2C data\0A\00"
define i32 @I2CWrapperReadBlock(i32 %0, i8 zeroext %1, i8 zeroext %2, i8* %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8
%8 = alloca i8
%9 = alloca i8*
%10 = alloca %struct.i2c_smbus_ioctl_data
%11 = alloca %union.i2c_smbus_data
store i32 %0, i32* %6
store i8 %1, i8* %7
store i8 %2, i8* %8
store i8* %3, i8** %9
%12 = getelementptr inbounds %struct.i2c_smbus_ioctl_data, %struct.i2c_smbus_ioctl_data* %10, i32 0, i32 0
store i32 1, i32* %12
%13 = load i8, i8* %7
%14 = getelementptr inbounds %struct.i2c_smbus_ioctl_data, %struct.i2c_smbus_ioctl_data* %10, i32 0, i32 1
store i8 %13, i8* %14
%15 = load i32, i32* @I2C_SMBUS_I2C_BLOCK_DATA
%16 = getelementptr inbounds %struct.i2c_smbus_ioctl_data, %struct.i2c_smbus_ioctl_data* %10, i32 0, i32 3
store i32 %15, i32* %16
%17 = getelementptr inbounds %struct.i2c_smbus_ioctl_data, %struct.i2c_smbus_ioctl_data* %10, i32 0, i32 2
store %union.i2c_smbus_data* %11, %union.i2c_smbus_data** %17
%18 = load i8, i8* %8
%19 = bitcast %union.i2c_smbus_data* %11 to i8**
%20 = load i8*, i8** %19
%21 = getelementptr inbounds i8, i8* %20, i64 0
store i8 %18, i8* %21
%22 = load i32, i32* %6
%23 = load i32, i32* @I2C_SMBUS
%24 = call i64 @ioctl(i32 %22, i32 %23, %struct.i2c_smbus_ioctl_data* %10)
%25 = icmp slt i64 %24, 0
br i1 %25, label %26, label %28
26: ; preds = %4
%27 = call i32 @FailMessage(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %5
br label %40
28: ; preds = %4
%29 = load i8*, i8** %9
%30 = bitcast %union.i2c_smbus_data* %11 to i8**
%31 = load i8*, i8** %30
%32 = getelementptr inbounds i8, i8* %31, i64 1
%33 = load i8, i8* %8
%34 = call i32 @memcpy(i8* %29, i8* %32, i8 zeroext %33)
%35 = bitcast %union.i2c_smbus_data* %11 to i8**
%36 = load i8*, i8** %35
%37 = getelementptr inbounds i8, i8* %36, i64 0
%38 = load i8, i8* %37
%39 = zext i8 %38 to i32
store i32 %39, i32* %5
br label %40
40: ; preds = %28, %26
%41 = load i32, i32* %5
ret i32 %41
}

LLVM IR (-O2):