#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 {
  int addr;
  unsigned char *buf;
  int len;
  scalar_t__ flags;
};

/* Variables and functions */
int /*<<< orphan*/ I2C_RDWR;
int ioctl(int, int /*<<< orphan*/, struct i2c_rdwr_ioctl_data *);
int i2cwritearray(int i2cfile, int addr, int len, unsigned char *array) {
  unsigned char buf2[257];
  int i;
  buf2[0] = addr;
  for (i = 0; i < len; i++)
    buf2[i + 1] = array[i];
  struct i2c_msg i2cmsg[1];
  struct i2c_rdwr_ioctl_data i2cmsgdata;
  i2cmsg[0].addr = 0x70;
  i2cmsg[0].flags = 0;
  i2cmsg[0].buf = (unsigned char *)&buf2;
  i2cmsg[0].len = len + 1;
  i2cmsgdata.msgs = i2cmsg;
  i2cmsgdata.nmsgs = 1;
  return ioctl(i2cfile, I2C_RDWR, &i2cmsgdata);
}


x86 assembly (clang, -O0):
<i2cwritearray>:
push   %rbp
mov    %rsp,%rbp
sub    $0x160,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    %rcx,-0x18(%rbp)
mov    -0x8(%rbp),%eax
mov    %al,-0x120(%rbp)
movl   $0x0,-0x124(%rbp)
mov    -0x124(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    117e <i2cwritearray+0x6e>
mov    -0x18(%rbp),%rax
movslq -0x124(%rbp),%rcx
mov    (%rax,%rcx,1),%cl
mov    -0x124(%rbp),%eax
add    $0x1,%eax
cltq
mov    %cl,-0x120(%rbp,%rax,1)
mov    -0x124(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x124(%rbp)
jmp    113b <i2cwritearray+0x2b>
movl   $0x70,-0x150(%rbp)
movq   $0x0,-0x138(%rbp)
lea    -0x120(%rbp),%rax
mov    %rax,-0x148(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x140(%rbp)
lea    -0x150(%rbp),%rax
mov    %rax,-0x158(%rbp)
movl   $0x1,-0x160(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2e09(%rip),%rax
mov    (%rax),%esi
lea    -0x160(%rbp),%rdx
call   1030 <ioctl@plt>
add    $0x160,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<i2cwritearray>:
push   %rbp
push   %rbx
sub    $0x138,%rsp
mov    %edx,%ebp
mov    %edi,%ebx
mov    %sil,0x30(%rsp)
test   %edx,%edx
jle    1145 <i2cwritearray+0x25>
lea    0x31(%rsp),%rdi
mov    %ebp,%edx
mov    %rcx,%rsi
call   1040 <memcpy@plt>
movl   $0x70,0x10(%rsp)
movq   $0x0,0x28(%rsp)
lea    0x30(%rsp),%rax
mov    %rax,0x18(%rsp)
add    $0x1,%ebp
mov    %ebp,0x20(%rsp)
lea    0x10(%rsp),%rax
mov    %rax,0x8(%rsp)
movl   $0x1,(%rsp)
mov    0x2e59(%rip),%rax
mov    (%rax),%esi
mov    %rsp,%rdx
mov    %ebx,%edi
call   1030 <ioctl@plt>
add    $0x138,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.i2c_msg = type { i32, i8*, i32, i64 }
%struct.i2c_rdwr_ioctl_data = type { i32, %struct.i2c_msg* }
@I2C_RDWR = global i32 0
define i32 @i2cwritearray(i32 %0, i32 %1, i32 %2, i8* %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
%9 = alloca [257 x i8]
%10 = alloca i32
%11 = alloca [1 x %struct.i2c_msg]
%12 = alloca %struct.i2c_rdwr_ioctl_data
store i32 %0, i32* %5
store i32 %1, i32* %6
store i32 %2, i32* %7
store i8* %3, i8** %8
%13 = load i32, i32* %6
%14 = trunc i32 %13 to i8
%15 = getelementptr inbounds [257 x i8], [257 x i8]* %9, i64 0, i64 0
store i8 %14, i8* %15
store i32 0, i32* %10
br label %16
16: ; preds = %30, %4
%17 = load i32, i32* %10
%18 = load i32, i32* %7
%19 = icmp slt i32 %17, %18
br i1 %19, label %20, label %33
20: ; preds = %16
%21 = load i8*, i8** %8
%22 = load i32, i32* %10
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i8, i8* %21, i64 %23
%25 = load i8, i8* %24
%26 = load i32, i32* %10
%27 = add nsw i32 %26, 1
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds [257 x i8], [257 x i8]* %9, i64 0, i64 %28
store i8 %25, i8* %29
br label %30
30: ; preds = %20
%31 = load i32, i32* %10
%32 = add nsw i32 %31, 1
store i32 %32, i32* %10
br label %16
33: ; preds = %16
%34 = getelementptr inbounds [1 x %struct.i2c_msg], [1 x %struct.i2c_msg]* %11, i64 0, i64 0
%35 = getelementptr inbounds %struct.i2c_msg, %struct.i2c_msg* %34, i32 0, i32 0
store i32 112, i32* %35
%36 = getelementptr inbounds [1 x %struct.i2c_msg], [1 x %struct.i2c_msg]* %11, i64 0, i64 0
%37 = getelementptr inbounds %struct.i2c_msg, %struct.i2c_msg* %36, i32 0, i32 3
store i64 0, i64* %37
%38 = bitcast [257 x i8]* %9 to i8*
%39 = getelementptr inbounds [1 x %struct.i2c_msg], [1 x %struct.i2c_msg]* %11, i64 0, i64 0
%40 = getelementptr inbounds %struct.i2c_msg, %struct.i2c_msg* %39, i32 0, i32 1
store i8* %38, i8** %40
%41 = load i32, i32* %7
%42 = add nsw i32 %41, 1
%43 = getelementptr inbounds [1 x %struct.i2c_msg], [1 x %struct.i2c_msg]* %11, i64 0, i64 0
%44 = getelementptr inbounds %struct.i2c_msg, %struct.i2c_msg* %43, i32 0, i32 2
store i32 %42, i32* %44
%45 = getelementptr inbounds [1 x %struct.i2c_msg], [1 x %struct.i2c_msg]* %11, i64 0, i64 0
%46 = getelementptr inbounds %struct.i2c_rdwr_ioctl_data, %struct.i2c_rdwr_ioctl_data* %12, i32 0, i32 1
store %struct.i2c_msg* %45, %struct.i2c_msg** %46
%47 = getelementptr inbounds %struct.i2c_rdwr_ioctl_data, %struct.i2c_rdwr_ioctl_data* %12, i32 0, i32 0
store i32 1, i32* %47
%48 = load i32, i32* %5
%49 = load i32, i32* @I2C_RDWR
%50 = call i32 @ioctl(i32 %48, i32 %49, %struct.i2c_rdwr_ioctl_data* %12)
ret i32 %50
}

LLVM IR (-O2):
%struct.i2c_msg = type { i32, i8*, i32, i64 }
%struct.i2c_rdwr_ioctl_data = type { i32, %struct.i2c_msg* }
@I2C_RDWR = global i32 0
define i32 @i2cwritearray(i32 %0, i32 %1, i32 %2, i8* nocapture %3) {
%5 = alloca [257 x i8]
%6 = alloca [1 x %struct.i2c_msg]
%7 = alloca %struct.i2c_rdwr_ioctl_data
%8 = getelementptr inbounds [257 x i8], [257 x i8]* %5, i64 0, i64 0
%9 = trunc i32 %1 to i8
store i8 %9, i8* %8
%10 = icmp sgt i32 %2, 0
br i1 %10, label %11, label %14
11: ; preds = %4
%12 = getelementptr inbounds [257 x i8], [257 x i8]* %5, i64 0, i64 1
%13 = zext i32 %2 to i64
br label %14
14: ; preds = %11, %4
%15 = bitcast [1 x %struct.i2c_msg]* %6 to i8*
%16 = bitcast %struct.i2c_rdwr_ioctl_data* %7 to i8*
%17 = getelementptr inbounds [1 x %struct.i2c_msg], [1 x %struct.i2c_msg]* %6, i64 0, i64 0
%18 = getelementptr inbounds [1 x %struct.i2c_msg], [1 x %struct.i2c_msg]* %6, i64 0, i64 0, i32 0
store i32 112, i32* %18
%19 = getelementptr inbounds [1 x %struct.i2c_msg], [1 x %struct.i2c_msg]* %6, i64 0, i64 0, i32 3
store i64 0, i64* %19
%20 = getelementptr inbounds [1 x %struct.i2c_msg], [1 x %struct.i2c_msg]* %6, i64 0, i64 0, i32 1
store i8* %8, i8** %20
%21 = add nsw i32 %2, 1
%22 = getelementptr inbounds [1 x %struct.i2c_msg], [1 x %struct.i2c_msg]* %6, i64 0, i64 0, i32 2
store i32 %21, i32* %22
%23 = getelementptr inbounds %struct.i2c_rdwr_ioctl_data, %struct.i2c_rdwr_ioctl_data* %7, i64 0, i32 1
store %struct.i2c_msg* %17, %struct.i2c_msg** %23
%24 = getelementptr inbounds %struct.i2c_rdwr_ioctl_data, %struct.i2c_rdwr_ioctl_data* %7, i64 0, i32 0
store i32 1, i32* %24
%25 = load i32, i32* @I2C_RDWR
%26 = call i32 @ioctl(i32 %0, i32 %25, %struct.i2c_rdwr_ioctl_data* %7)
ret i32 %26
}