#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 */
typedef union i2c_smbus_data {
  int dummy;
} i2c_smbus_data;
struct i2c_smbus_ioctl_data {
  char read_write;
  int size;
  union i2c_smbus_data *data;
  int /*<<< orphan*/ command;
};
typedef int /*<<< orphan*/ __u8;
typedef int __s32;

/* Variables and functions */
int /*<<< orphan*/ I2C_SMBUS;
int errno;
int ioctl(int, int /*<<< orphan*/, struct i2c_smbus_ioctl_data *);
__s32 i2c_smbus_access(int file, char read_write, __u8 command, int size,
                       union i2c_smbus_data *data) {
  struct i2c_smbus_ioctl_data args;
  __s32 err;
  args.read_write = read_write;
  args.command = command;
  args.size = size;
  args.data = data;
  err = ioctl(file, I2C_SMBUS, &args);
  if (err == -1)
    err = -errno;
  return err;
}


x86 assembly (clang, -O0):
<i2c_smbus_access>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %sil,%al
mov    %edi,-0x4(%rbp)
mov    %al,-0x5(%rbp)
mov    %edx,-0xc(%rbp)
mov    %ecx,-0x10(%rbp)
mov    %r8,-0x18(%rbp)
mov    -0x5(%rbp),%al
mov    %al,-0x30(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x10(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2e99(%rip),%rax
mov    (%rax),%esi
lea    -0x30(%rbp),%rdx
call   1030 <ioctl@plt>
mov    %eax,-0x34(%rbp)
cmpl   $0xffffffff,-0x34(%rbp)
jne    1175 <i2c_smbus_access+0x65>
xor    %eax,%eax
mov    0x2e68(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x34(%rbp)
mov    -0x34(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<i2c_smbus_access>:
sub    $0x18,%rsp
mov    %sil,(%rsp)
mov    %edx,0x10(%rsp)
mov    %ecx,0x4(%rsp)
mov    %r8,0x8(%rsp)
mov    0x2ebc(%rip),%rax
mov    (%rax),%esi
mov    %rsp,%rdx
call   1030 <ioctl@plt>
mov    0x2e9b(%rip),%rcx
xor    %edx,%edx
sub    (%rcx),%edx
cmp    $0xffffffff,%eax
cmove  %edx,%eax
add    $0x18,%rsp
ret

LLVM IR (-O0):
%union.i2c_smbus_data = type { i32 }
%struct.i2c_smbus_ioctl_data = type { i8, i32, %union.i2c_smbus_data*, i32 }
@I2C_SMBUS = global i32 0
@errno = global i32 0
define i32 @i2c_smbus_access(i32 %0, i8 signext %1, i32 %2, i32 %3, %union.i2c_smbus_data* %4) {
%6 = alloca i32
%7 = alloca i8
%8 = alloca i32
%9 = alloca i32
%10 = alloca %union.i2c_smbus_data*
%11 = alloca %struct.i2c_smbus_ioctl_data
%12 = alloca i32
store i32 %0, i32* %6
store i8 %1, i8* %7
store i32 %2, i32* %8
store i32 %3, i32* %9
store %union.i2c_smbus_data* %4, %union.i2c_smbus_data** %10
%13 = load i8, i8* %7
%14 = getelementptr inbounds %struct.i2c_smbus_ioctl_data, %struct.i2c_smbus_ioctl_data* %11, i32 0, i32 0
store i8 %13, i8* %14
%15 = load i32, i32* %8
%16 = getelementptr inbounds %struct.i2c_smbus_ioctl_data, %struct.i2c_smbus_ioctl_data* %11, i32 0, i32 3
store i32 %15, i32* %16
%17 = load i32, i32* %9
%18 = getelementptr inbounds %struct.i2c_smbus_ioctl_data, %struct.i2c_smbus_ioctl_data* %11, i32 0, i32 1
store i32 %17, i32* %18
%19 = load %union.i2c_smbus_data*, %union.i2c_smbus_data** %10
%20 = getelementptr inbounds %struct.i2c_smbus_ioctl_data, %struct.i2c_smbus_ioctl_data* %11, i32 0, i32 2
store %union.i2c_smbus_data* %19, %union.i2c_smbus_data** %20
%21 = load i32, i32* %6
%22 = load i32, i32* @I2C_SMBUS
%23 = call i32 @ioctl(i32 %21, i32 %22, %struct.i2c_smbus_ioctl_data* %11)
store i32 %23, i32* %12
%24 = load i32, i32* %12
%25 = icmp eq i32 %24, -1
br i1 %25, label %26, label %29
26: ; preds = %5
%27 = load i32, i32* @errno
%28 = sub nsw i32 0, %27
store i32 %28, i32* %12
br label %29
29: ; preds = %26, %5
%30 = load i32, i32* %12
ret i32 %30
}

LLVM IR (-O2):
%union.i2c_smbus_data = type { i32 }
%struct.i2c_smbus_ioctl_data = type { i8, i32, %union.i2c_smbus_data*, i32 }
@I2C_SMBUS = global i32 0
@errno = global i32 0
define i32 @i2c_smbus_access(i32 %0, i8 signext %1, i32 %2, i32 %3, %union.i2c_smbus_data* %4) {
%6 = alloca %struct.i2c_smbus_ioctl_data
%7 = getelementptr inbounds %struct.i2c_smbus_ioctl_data, %struct.i2c_smbus_ioctl_data* %6, i64 0, i32 0
store i8 %1, i8* %7
%8 = getelementptr inbounds %struct.i2c_smbus_ioctl_data, %struct.i2c_smbus_ioctl_data* %6, i64 0, i32 3
store i32 %2, i32* %8
%9 = getelementptr inbounds %struct.i2c_smbus_ioctl_data, %struct.i2c_smbus_ioctl_data* %6, i64 0, i32 1
store i32 %3, i32* %9
%10 = getelementptr inbounds %struct.i2c_smbus_ioctl_data, %struct.i2c_smbus_ioctl_data* %6, i64 0, i32 2
store %union.i2c_smbus_data* %4, %union.i2c_smbus_data** %10
%11 = load i32, i32* @I2C_SMBUS
%12 = call i32 @ioctl(i32 %0, i32 %11, %struct.i2c_smbus_ioctl_data* %6)
%13 = icmp eq i32 %12, -1
%14 = load i32, i32* @errno
%15 = sub nsw i32 0, %14
%16 = select i1 %13, i32 %15, i32 %12
ret i32 %16
}