#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 */

/* Variables and functions */
scalar_t__ i2cwritearray(int, int, int, unsigned char *);
int writeI2CDataArray(int i2cfile, unsigned char *array, int len) {
  int i, j;
  for (i = 0; i < len; i += 4) {
    for (j = 0; j < 5; j++) {
      int shortlen = ((len - i) > 4) ? 4 : (len - i);
      if (i2cwritearray(i2cfile, 1 + i, shortlen, &array[i]) >= 0) {
        break;
      }
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<writeI2CDataArray>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11c2 <writeI2CDataArray+0xb2>
movl   $0x0,-0x1c(%rbp)
cmpl   $0x5,-0x1c(%rbp)
jge    11af <writeI2CDataArray+0x9f>
mov    -0x14(%rbp),%eax
sub    -0x18(%rbp),%eax
cmp    $0x4,%eax
jle    1162 <writeI2CDataArray+0x52>
mov    $0x4,%eax
mov    %eax,-0x24(%rbp)
jmp    116b <writeI2CDataArray+0x5b>
mov    -0x14(%rbp),%eax
sub    -0x18(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x18(%rbp),%esi
add    $0x1,%esi
mov    -0x20(%rbp),%edx
mov    -0x10(%rbp),%rcx
movslq -0x18(%rbp),%rax
add    %rax,%rcx
call   1030 <i2cwritearray@plt>
cmp    $0x0,%rax
jl     119c <writeI2CDataArray+0x8c>
jmp    11af <writeI2CDataArray+0x9f>
jmp    11a1 <writeI2CDataArray+0x91>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    113c <writeI2CDataArray+0x2c>
jmp    11b4 <writeI2CDataArray+0xa4>
mov    -0x18(%rbp),%eax
add    $0x4,%eax
mov    %eax,-0x18(%rbp)
jmp    1129 <writeI2CDataArray+0x19>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<writeI2CDataArray>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,0x10(%rsp)
test   %edx,%edx
jle    1193 <writeI2CDataArray+0x83>
mov    %edx,%ebx
mov    %edi,%r12d
xor    %r14d,%r14d
mov    %edx,0xc(%rsp)
jmp    114d <writeI2CDataArray+0x3d>
cs nopw 0x0(%rax,%rax,1)
nop
add    $0x4,%r14
mov    0xc(%rsp),%ebx
cmp    %ebx,%r14d
jge    1193 <writeI2CDataArray+0x83>
sub    %r14d,%ebx
cmp    $0x4,%ebx
mov    $0x4,%eax
cmovge %eax,%ebx
mov    0x10(%rsp),%rax
lea    (%rax,%r14,1),%r13
mov    %r14d,%ebp
or     $0x1,%ebp
xor    %r15d,%r15d
nopl   (%rax)
mov    %r12d,%edi
mov    %ebp,%esi
mov    %ebx,%edx
mov    %r13,%rcx
call   1030 <i2cwritearray@plt>
test   %rax,%rax
jns    1140 <writeI2CDataArray+0x30>
lea    0x1(%r15),%eax
cmp    $0x4,%r15d
mov    %eax,%r15d
jb     1170 <writeI2CDataArray+0x60>
jmp    1140 <writeI2CDataArray+0x30>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define i32 @writeI2CDataArray(i32 %0, i8* %1, i32 %2) {
%4 = icmp sgt i32 %2, 0
br i1 %4, label %5, label %25
5: ; preds = %3, %21
%6 = phi i64 [ %22, %21 ], [ 0, %3 ]
%7 = trunc i64 %6 to i32
%8 = sub nsw i32 %2, %7
%9 = icmp slt i32 %8, 4
%10 = select i1 %9, i32 %8, i32 4
%11 = getelementptr inbounds i8, i8* %1, i64 %6
%12 = trunc i64 %6 to i32
%13 = or i32 %12, 1
br label %14
14: ; preds = %14, %5
%15 = phi i32 [ 0, %5 ], [ %18, %14 ]
%16 = tail call i64 @i2cwritearray(i32 %0, i32 %13, i32 %10, i8* %11)
%17 = icmp slt i64 %16, 0
%18 = add nuw nsw i32 %15, 1
%19 = icmp ult i32 %15, 4
%20 = select i1 %17, i1 %19, i1 false
br i1 %20, label %14, label %21
21: ; preds = %14
%22 = add nuw i64 %6, 4
%23 = trunc i64 %22 to i32
%24 = icmp slt i32 %23, %2
br i1 %24, label %5, label %25
25: ; preds = %21, %3
ret i32 0
}