#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;
  unsigned char command;
  int size;
  union i2c_smbus_data *data;
};

/* Variables and functions */
int /*<<< orphan*/ I2C_SMBUS;
long errno;
long ioctl(int, int /*<<< orphan*/, struct i2c_smbus_ioctl_data *);
long i2c_smbus_access(int file, char read_write, unsigned char command,
                      int size, union i2c_smbus_data *data) {
  struct i2c_smbus_ioctl_data args;
  long 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    $0x30,%rsp
mov    %dl,%al
mov    %sil,%dl
mov    %edi,-0x4(%rbp)
mov    %dl,-0x5(%rbp)
mov    %al,-0x6(%rbp)
mov    %ecx,-0xc(%rbp)
mov    %r8,-0x18(%rbp)
mov    -0x5(%rbp),%al
mov    %al,-0x28(%rbp)
mov    -0x6(%rbp),%al
mov    %al,-0x27(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2e97(%rip),%rax
mov    (%rax),%esi
lea    -0x28(%rbp),%rdx
call   1030 <ioctl@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0xffffffffffffffff,-0x30(%rbp)
jne    117b <i2c_smbus_access+0x6b>
xor    %eax,%eax
mov    0x2e64(%rip),%rcx
sub    (%rcx),%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<i2c_smbus_access>:
sub    $0x18,%rsp
mov    %sil,0x8(%rsp)
mov    %dl,0x9(%rsp)
mov    %ecx,0xc(%rsp)
mov    %r8,0x10(%rsp)
mov    0x2ebb(%rip),%rax
mov    (%rax),%esi
lea    0x8(%rsp),%rdx
call   1030 <ioctl@plt>
mov    0x2e98(%rip),%rcx
xor    %edx,%edx
sub    (%rcx),%rdx
cmp    $0xffffffffffffffff,%rax
cmove  %rdx,%rax
add    $0x18,%rsp
ret

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

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