#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 */
struct i2c_rdwr_ioctl_data {
  int nmsgs;
  struct i2c_msg *msgs;
};
struct i2c_msg {
  unsigned char addr;
  unsigned int len;
  int flags;
  unsigned char *buf;
};

/* Variables and functions */
int I2C_M_IGNORE_NAK;
int /*<<< orphan*/ I2C_RDWR;
int /*<<< orphan*/ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
scalar_t__ ioctl(int, int /*<<< orphan*/, unsigned long);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
int i2c_write_ignore_nack(int handle, unsigned char addr_w, unsigned char *buf,
                          unsigned int length) {
  struct i2c_rdwr_ioctl_data msgset;
  struct i2c_msg msgs[1];
  msgs[0].addr = addr_w;
  msgs[0].len = length;
  msgs[0].flags = 0 | I2C_M_IGNORE_NAK;
  msgs[0].buf = buf;
  msgset.nmsgs = 1;
  msgset.msgs = msgs;
  if (ioctl(handle, I2C_RDWR, (unsigned long)&msgset) < 0) {
    fprintf(stderr, "i2c_write_ignore_nack error: %s\n", strerror(errno));
    return -1;
  }
  return (length);
}


x86 assembly (clang, -O0):
<i2c_write_ignore_nack>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %sil,%al
mov    %edi,-0x8(%rbp)
mov    %al,-0x9(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    -0x9(%rbp),%al
mov    %al,-0x50(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4c(%rbp)
mov    0x2e7d(%rip),%rax
mov    (%rax),%eax
or     $0x0,%eax
mov    %eax,-0x48(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x40(%rbp)
movl   $0x1,-0x30(%rbp)
lea    -0x50(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2e3c(%rip),%rax
mov    (%rax),%esi
lea    -0x30(%rbp),%rdx
call   1030 <ioctl@plt>
cmp    $0x0,%rax
jge    11d1 <i2c_write_ignore_nack+0xa1>
mov    0x2e40(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x54(%rbp)
mov    0x2e24(%rip),%rax
mov    (%rax),%edi
call   1050 <strerror@plt>
mov    -0x54(%rbp),%edi
mov    %rax,%rdx
lea    0xe40(%rip),%rsi
call   1040 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11d7 <i2c_write_ignore_nack+0xa7>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<i2c_write_ignore_nack>:
push   %rbx
sub    $0x30,%rsp
mov    %ecx,%ebx
mov    %sil,(%rsp)
mov    %ecx,0x4(%rsp)
mov    0x2e92(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x8(%rsp)
mov    %rdx,0x10(%rsp)
movl   $0x1,0x20(%rsp)
mov    %rsp,%rax
mov    %rax,0x28(%rsp)
mov    0x2e58(%rip),%rax
mov    (%rax),%esi
lea    0x20(%rsp),%rdx
call   1030 <ioctl@plt>
test   %rax,%rax
jns    11a6 <i2c_write_ignore_nack+0x76>
mov    0x2e60(%rip),%rax
mov    (%rax),%ebx
mov    0x2e47(%rip),%rax
mov    (%rax),%edi
call   1050 <strerror@plt>
lea    0xe69(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
call   1040 <fprintf@plt>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
add    $0x30,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.i2c_rdwr_ioctl_data = type { i32, %struct.i2c_msg* }
%struct.i2c_msg = type { i8, i32, i32, i8* }
@I2C_M_IGNORE_NAK = global i32 0
@I2C_RDWR = global i32 0
@stderr = global i32 0
@.str = [33 x i8] c"i2c_write_ignore_nack error: %s\0A\00"
@errno = global i32 0
define i32 @i2c_write_ignore_nack(i32 %0, i8 zeroext %1, i8* %2, i32 %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8
%8 = alloca i8*
%9 = alloca i32
%10 = alloca %struct.i2c_rdwr_ioctl_data
%11 = alloca [1 x %struct.i2c_msg]
store i32 %0, i32* %6
store i8 %1, i8* %7
store i8* %2, i8** %8
store i32 %3, i32* %9
%12 = load i8, i8* %7
%13 = getelementptr inbounds [1 x %struct.i2c_msg], [1 x %struct.i2c_msg]* %11, i64 0, i64 0
%14 = getelementptr inbounds %struct.i2c_msg, %struct.i2c_msg* %13, i32 0, i32 0
store i8 %12, i8* %14
%15 = load i32, i32* %9
%16 = getelementptr inbounds [1 x %struct.i2c_msg], [1 x %struct.i2c_msg]* %11, i64 0, i64 0
%17 = getelementptr inbounds %struct.i2c_msg, %struct.i2c_msg* %16, i32 0, i32 1
store i32 %15, i32* %17
%18 = load i32, i32* @I2C_M_IGNORE_NAK
%19 = or i32 0, %18
%20 = getelementptr inbounds [1 x %struct.i2c_msg], [1 x %struct.i2c_msg]* %11, i64 0, i64 0
%21 = getelementptr inbounds %struct.i2c_msg, %struct.i2c_msg* %20, i32 0, i32 2
store i32 %19, i32* %21
%22 = load i8*, i8** %8
%23 = getelementptr inbounds [1 x %struct.i2c_msg], [1 x %struct.i2c_msg]* %11, i64 0, i64 0
%24 = getelementptr inbounds %struct.i2c_msg, %struct.i2c_msg* %23, i32 0, i32 3
store i8* %22, i8** %24
%25 = getelementptr inbounds %struct.i2c_rdwr_ioctl_data, %struct.i2c_rdwr_ioctl_data* %10, i32 0, i32 0
store i32 1, i32* %25
%26 = getelementptr inbounds [1 x %struct.i2c_msg], [1 x %struct.i2c_msg]* %11, i64 0, i64 0
%27 = getelementptr inbounds %struct.i2c_rdwr_ioctl_data, %struct.i2c_rdwr_ioctl_data* %10, i32 0, i32 1
store %struct.i2c_msg* %26, %struct.i2c_msg** %27
%28 = load i32, i32* %6
%29 = load i32, i32* @I2C_RDWR
%30 = ptrtoint %struct.i2c_rdwr_ioctl_data* %10 to i64
%31 = call i64 @ioctl(i32 %28, i32 %29, i64 %30)
%32 = icmp slt i64 %31, 0
br i1 %32, label %33, label %38
33: ; preds = %4
%34 = load i32, i32* @stderr
%35 = load i32, i32* @errno
%36 = call i8* @strerror(i32 %35)
%37 = call i32 @fprintf(i32 %34, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0), i8* %36)
store i32 -1, i32* %5
br label %40
38: ; preds = %4
%39 = load i32, i32* %9
store i32 %39, i32* %5
br label %40
40: ; preds = %38, %33
%41 = load i32, i32* %5
ret i32 %41
}

LLVM IR (-O2):
%struct.i2c_rdwr_ioctl_data = type { i32, %struct.i2c_msg* }
%struct.i2c_msg = type { i8, i32, i32, i8* }
@I2C_M_IGNORE_NAK = global i32 0
@I2C_RDWR = global i32 0
@stderr = global i32 0
@.str = [33 x i8] c"i2c_write_ignore_nack error: %s\0A\00"
@errno = global i32 0
define i32 @i2c_write_ignore_nack(i32 %0, i8 zeroext %1, i8* %2, i32 %3) {
%5 = alloca %struct.i2c_rdwr_ioctl_data
%6 = alloca [1 x %struct.i2c_msg]
%7 = bitcast %struct.i2c_rdwr_ioctl_data* %5 to i8*
%8 = getelementptr inbounds [1 x %struct.i2c_msg], [1 x %struct.i2c_msg]* %6, i64 0, i64 0, i32 0
%9 = getelementptr inbounds [1 x %struct.i2c_msg], [1 x %struct.i2c_msg]* %6, i64 0, i64 0
store i8 %1, i8* %8
%10 = getelementptr inbounds [1 x %struct.i2c_msg], [1 x %struct.i2c_msg]* %6, i64 0, i64 0, i32 1
store i32 %3, i32* %10
%11 = load i32, i32* @I2C_M_IGNORE_NAK
%12 = getelementptr inbounds [1 x %struct.i2c_msg], [1 x %struct.i2c_msg]* %6, i64 0, i64 0, i32 2
store i32 %11, i32* %12
%13 = getelementptr inbounds [1 x %struct.i2c_msg], [1 x %struct.i2c_msg]* %6, i64 0, i64 0, i32 3
store i8* %2, i8** %13
%14 = getelementptr inbounds %struct.i2c_rdwr_ioctl_data, %struct.i2c_rdwr_ioctl_data* %5, i64 0, i32 0
store i32 1, i32* %14
%15 = getelementptr inbounds %struct.i2c_rdwr_ioctl_data, %struct.i2c_rdwr_ioctl_data* %5, i64 0, i32 1
store %struct.i2c_msg* %9, %struct.i2c_msg** %15
%16 = load i32, i32* @I2C_RDWR
%17 = ptrtoint %struct.i2c_rdwr_ioctl_data* %5 to i64
%18 = call i64 @ioctl(i32 %0, i32 %16, i64 %17)
%19 = icmp slt i64 %18, 0
br i1 %19, label %20, label %25
20: ; preds = %4
%21 = load i32, i32* @stderr
%22 = load i32, i32* @errno
%23 = call i8* @strerror(i32 %22)
%24 = call i32 @fprintf(i32 %21, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0), i8* %23)
br label %25
25: ; preds = %4, %20
%26 = phi i32 [ -1, %20 ], [ %3, %4 ]
ret i32 %26
}