int i2c_write_array(unsigned char addr, char *buf, int len) {
  int i;
  int ret;
  ret = i2c_select_device(0x50, 0);
  if (ret) {
    __s5p_printf("i2c devices no response.\n");
    goto i2c_select_device_fail;
  }
  __s5p_printf("%p - addr is 0x%p\n", __func__, addr);
  ret = i2c_send_addr(addr);
  if (ret) {
    __s5p_printf("i2c send address fail.\n");
    goto i2c_fail;
  }
  for (i = 0; i < len; i++) {
    __s5p_printf("send data is 0x%p\n", buf[i]);
    ret = i2c_send_data(buf[i]);
    if (ret) {
      __s5p_printf("i2c send data fail, 0x%p bytes success.\n", i);
      goto i2c_fail;
    }
  }
  ret = len;
i2c_fail:
  i2c_stop();
  i2c_trx_resume();
i2c_select_device_fail:
  return ret;
}


x86 assembly (clang, -O0):
<i2c_write_array>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %dil,%al
mov    %al,-0x1(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    $0x50,%edi
xor    %esi,%esi
mov    $0x0,%al
call   1080 <i2c_select_device@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
je     11a3 <i2c_write_array+0x43>
lea    0xe69(%rip),%rdi
mov    $0x0,%al
call   1030 <__s5p_printf@plt>
jmp    1271 <i2c_write_array+0x111>
movzbl -0x1(%rbp),%edx
lea    0xe6c(%rip),%rdi
lea    0xe78(%rip),%rsi
mov    $0x0,%al
call   1030 <__s5p_printf@plt>
movzbl -0x1(%rbp),%edi
mov    $0x0,%al
call   1040 <i2c_send_addr@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
je     11e7 <i2c_write_array+0x87>
lea    0xe62(%rip),%rdi
mov    $0x0,%al
call   1030 <__s5p_printf@plt>
jmp    1263 <i2c_write_array+0x103>
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    125d <i2c_write_array+0xfd>
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
movsbl (%rax,%rcx,1),%esi
lea    0xe48(%rip),%rdi
mov    $0x0,%al
call   1030 <__s5p_printf@plt>
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
mov    $0x0,%al
call   1070 <i2c_send_data@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
je     124a <i2c_write_array+0xea>
mov    -0x18(%rbp),%esi
lea    0xe2a(%rip),%rdi
mov    $0x0,%al
call   1030 <__s5p_printf@plt>
jmp    1263 <i2c_write_array+0x103>
jmp    124f <i2c_write_array+0xef>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    11ee <i2c_write_array+0x8e>
mov    -0x14(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    $0x0,%al
call   1060 <i2c_stop@plt>
mov    $0x0,%al
call   1050 <i2c_trx_resume@plt>
mov    -0x1c(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<i2c_write_array>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %edx,%ebp
mov    %rsi,%r14
mov    %edi,%ebx
mov    $0x50,%edi
xor    %esi,%esi
xor    %eax,%eax
call   1080 <i2c_select_device@plt>
test   %eax,%eax
je     1194 <i2c_write_array+0x34>
mov    %eax,%r12d
lea    0xe75(%rip),%rdi
xor    %eax,%eax
call   1030 <__s5p_printf@plt>
jmp    11da <i2c_write_array+0x7a>
movzbl %bl,%ebx
lea    0xe7c(%rip),%rdi
lea    0xe88(%rip),%rsi
mov    %ebx,%edx
xor    %eax,%eax
call   1030 <__s5p_printf@plt>
mov    %ebx,%edi
xor    %eax,%eax
call   1040 <i2c_send_addr@plt>
test   %eax,%eax
je     11e6 <i2c_write_array+0x86>
mov    %eax,%r12d
lea    0xe78(%rip),%rdi
xor    %eax,%eax
call   1030 <__s5p_printf@plt>
xor    %eax,%eax
call   1060 <i2c_stop@plt>
xor    %eax,%eax
call   1050 <i2c_trx_resume@plt>
mov    %r12d,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %ebp,%r12d
test   %ebp,%ebp
jle    11cc <i2c_write_array+0x6c>
lea    0xe61(%rip),%r15
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
movsbl (%r14,%rbp,1),%esi
mov    %r15,%rdi
xor    %eax,%eax
call   1030 <__s5p_printf@plt>
movsbl (%r14,%rbp,1),%edi
xor    %eax,%eax
call   1070 <i2c_send_data@plt>
test   %eax,%eax
jne    122a <i2c_write_array+0xca>
add    $0x1,%rbp
cmp    %rbp,%r12
jne    1200 <i2c_write_array+0xa0>
jmp    11cc <i2c_write_array+0x6c>
mov    %eax,%ebx
lea    0xe35(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1030 <__s5p_printf@plt>
mov    %ebx,%r12d
jmp    11cc <i2c_write_array+0x6c>

LLVM IR (-O0):
@.str = [26 x i8] c"i2c devices no response.\0A\00"
@.str.1 = [19 x i8] c"%p - addr is 0x%p\0A\00"
@__func__.i2c_write_array = [16 x i8] c"i2c_write_array\00"
@.str.2 = [24 x i8] c"i2c send address fail.\0A\00"
@.str.3 = [19 x i8] c"send data is 0x%p\0A\00"
@.str.4 = [41 x i8] c"i2c send data fail, 0x%p bytes success.\0A\00"
define i32 @i2c_write_array(i8 zeroext %0, i8* %1, i32 %2) {
%4 = alloca i8
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i8 %0, i8* %4
store i8* %1, i8** %5
store i32 %2, i32* %6
%9 = call i32 (i32, i32, ...) bitcast (i32 (...)* @i2c_select_device to i32 (i32, i32, ...)*)(i32 80, i32 0)
store i32 %9, i32* %8
%10 = load i32, i32* %8
%11 = icmp ne i32 %10, 0
br i1 %11, label %12, label %14
12: ; preds = %3
%13 = call i32 (i8*, ...) bitcast (i32 (...)* @__s5p_printf to i32 (i8*, ...)*)(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
br label %59
14: ; preds = %3
%15 = load i8, i8* %4
%16 = zext i8 %15 to i32
%17 = call i32 (i8*, i8*, i32, ...) bitcast (i32 (...)* @__s5p_printf to i32 (i8*, i8*, i32, ...)*)(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([16 x i8], [16 x i8]* @__func__.i2c_write_array, i64 0, i64 0), i32 %16)
%18 = load i8, i8* %4
%19 = zext i8 %18 to i32
%20 = call i32 (i32, ...) bitcast (i32 (...)* @i2c_send_addr to i32 (i32, ...)*)(i32 %19)
store i32 %20, i32* %8
%21 = load i32, i32* %8
%22 = icmp ne i32 %21, 0
br i1 %22, label %23, label %25
23: ; preds = %14
%24 = call i32 (i8*, ...) bitcast (i32 (...)* @__s5p_printf to i32 (i8*, ...)*)(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0))
br label %56
25: ; preds = %14
store i32 0, i32* %7
br label %26
26: ; preds = %51, %25
%27 = load i32, i32* %7
%28 = load i32, i32* %6
%29 = icmp slt i32 %27, %28
br i1 %29, label %30, label %54
30: ; preds = %26
%31 = load i8*, i8** %5
%32 = load i32, i32* %7
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds i8, i8* %31, i64 %33
%35 = load i8, i8* %34
%36 = sext i8 %35 to i32
%37 = call i32 (i8*, i32, ...) bitcast (i32 (...)* @__s5p_printf to i32 (i8*, i32, ...)*)(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i32 %36)
%38 = load i8*, i8** %5
%39 = load i32, i32* %7
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds i8, i8* %38, i64 %40
%42 = load i8, i8* %41
%43 = sext i8 %42 to i32
%44 = call i32 (i32, ...) bitcast (i32 (...)* @i2c_send_data to i32 (i32, ...)*)(i32 %43)
store i32 %44, i32* %8
%45 = load i32, i32* %8
%46 = icmp ne i32 %45, 0
br i1 %46, label %47, label %50
47: ; preds = %30
%48 = load i32, i32* %7
%49 = call i32 (i8*, i32, ...) bitcast (i32 (...)* @__s5p_printf to i32 (i8*, i32, ...)*)(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.4, i64 0, i64 0), i32 %48)
br label %56
50: ; preds = %30
br label %51
51: ; preds = %50
%52 = load i32, i32* %7
%53 = add nsw i32 %52, 1
store i32 %53, i32* %7
br label %26
54: ; preds = %26
%55 = load i32, i32* %6
store i32 %55, i32* %8
br label %56
56: ; preds = %54, %47, %23
%57 = call i32 (...) @i2c_stop()
%58 = call i32 (...) @i2c_trx_resume()
br label %59
59: ; preds = %56, %12
%60 = load i32, i32* %8
ret i32 %60
}

LLVM IR (-O2):
@.str = [26 x i8] c"i2c devices no response.\0A\00"
@.str.1 = [19 x i8] c"%p - addr is 0x%p\0A\00"
@__func__.i2c_write_array = [16 x i8] c"i2c_write_array\00"
@.str.2 = [24 x i8] c"i2c send address fail.\0A\00"
@.str.3 = [19 x i8] c"send data is 0x%p\0A\00"
@.str.4 = [41 x i8] c"i2c send data fail, 0x%p bytes success.\0A\00"
define i32 @i2c_write_array(i8 zeroext %0, i8* nocapture %1, i32 %2) {
%4 = tail call i32 (i32, i32, ...) bitcast (i32 (...)* @i2c_select_device to i32 (i32, i32, ...)*)(i32 80, i32 0)
%5 = icmp eq i32 %4, 0
br i1 %5, label %8, label %6
6: ; preds = %3
%7 = tail call i32 (i8*, ...) bitcast (i32 (...)* @__s5p_printf to i32 (i8*, ...)*)(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
br label %39
8: ; preds = %3
%9 = zext i8 %0 to i32
%10 = tail call i32 (i8*, i8*, i32, ...) bitcast (i32 (...)* @__s5p_printf to i32 (i8*, i8*, i32, ...)*)(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([16 x i8], [16 x i8]* @__func__.i2c_write_array, i64 0, i64 0), i32 %9)
%11 = tail call i32 (i32, ...) bitcast (i32 (...)* @i2c_send_addr to i32 (i32, ...)*)(i32 %9)
%12 = icmp eq i32 %11, 0
br i1 %12, label %13, label %17
13: ; preds = %8
%14 = icmp sgt i32 %2, 0
br i1 %14, label %15, label %35
15: ; preds = %13
%16 = zext i32 %2 to i64
br label %19
17: ; preds = %8
%18 = tail call i32 (i8*, ...) bitcast (i32 (...)* @__s5p_printf to i32 (i8*, ...)*)(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0))
br label %35
19: ; preds = %15, %32
%20 = phi i64 [ 0, %15 ], [ %33, %32 ]
%21 = getelementptr inbounds i8, i8* %1, i64 %20
%22 = load i8, i8* %21
%23 = sext i8 %22 to i32
%24 = tail call i32 (i8*, i32, ...) bitcast (i32 (...)* @__s5p_printf to i32 (i8*, i32, ...)*)(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i32 %23)
%25 = load i8, i8* %21
%26 = sext i8 %25 to i32
%27 = tail call i32 (i32, ...) bitcast (i32 (...)* @i2c_send_data to i32 (i32, ...)*)(i32 %26)
%28 = icmp eq i32 %27, 0
br i1 %28, label %32, label %29
29: ; preds = %19
%30 = trunc i64 %20 to i32
%31 = tail call i32 (i8*, i32, ...) bitcast (i32 (...)* @__s5p_printf to i32 (i8*, i32, ...)*)(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.4, i64 0, i64 0), i32 %30)
br label %35
32: ; preds = %19
%33 = add nuw nsw i64 %20, 1
%34 = icmp eq i64 %33, %16
br i1 %34, label %35, label %19
35: ; preds = %32, %13, %29, %17
%36 = phi i32 [ %11, %17 ], [ %27, %29 ], [ %2, %13 ], [ %2, %32 ]
%37 = tail call i32 (...) @i2c_stop()
%38 = tail call i32 (...) @i2c_trx_resume()
br label %39
39: ; preds = %35, %6
%40 = phi i32 [ %4, %6 ], [ %36, %35 ]
ret i32 %40
}