#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__ eeprom_24cxx_write_byte(unsigned char, char const);
int eeprom_24cxx_write(unsigned char address, const void *src, int length) {
  const char *buf = (const char *)src;
  int i;
  for (i = 0; i < length; i++) {
    if (eeprom_24cxx_write_byte(address + i, buf[i]) < 0)
      return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<eeprom_24cxx_write>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %dil,%al
mov    %al,-0x5(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1186 <eeprom_24cxx_write+0x76>
movzbl -0x5(%rbp),%eax
add    -0x24(%rbp),%eax
mov    %al,%dl
mov    -0x20(%rbp),%rax
movslq -0x24(%rbp),%rcx
movzbl %dl,%edi
movsbl (%rax,%rcx,1),%esi
call   1030 <eeprom_24cxx_write_byte@plt>
cmp    $0x0,%rax
jge    1173 <eeprom_24cxx_write+0x63>
movl   $0xffffffff,-0x4(%rbp)
jmp    118d <eeprom_24cxx_write+0x7d>
jmp    1178 <eeprom_24cxx_write+0x68>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1134 <eeprom_24cxx_write+0x24>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<eeprom_24cxx_write>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
test   %edx,%edx
jle    114f <eeprom_24cxx_write+0x3f>
mov    %rsi,%r14
mov    %edx,%r15d
movzbl %dil,%r12d
xor    %ebx,%ebx
nopl   0x0(%rax,%rax,1)
lea    (%r12,%rbx,1),%eax
movsbl (%r14,%rbx,1),%esi
movzbl %al,%edi
call   1030 <eeprom_24cxx_write_byte@plt>
test   %rax,%rax
js     1153 <eeprom_24cxx_write+0x43>
add    $0x1,%rbx
cmp    %rbx,%r15
jne    1130 <eeprom_24cxx_write+0x20>
xor    %eax,%eax
jmp    1158 <eeprom_24cxx_write+0x48>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i32 @eeprom_24cxx_write(i8 zeroext %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i32
store i8 %0, i8* %5
store i8* %1, i8** %6
store i32 %2, i32* %7
%10 = load i8*, i8** %6
store i8* %10, i8** %8
store i32 0, i32* %9
br label %11
11: ; preds = %30, %3
%12 = load i32, i32* %9
%13 = load i32, i32* %7
%14 = icmp slt i32 %12, %13
br i1 %14, label %15, label %33
15: ; preds = %11
%16 = load i8, i8* %5
%17 = zext i8 %16 to i32
%18 = load i32, i32* %9
%19 = add nsw i32 %17, %18
%20 = trunc i32 %19 to i8
%21 = load i8*, i8** %8
%22 = load i32, i32* %9
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i8, i8* %21, i64 %23
%25 = load i8, i8* %24
%26 = call i64 @eeprom_24cxx_write_byte(i8 zeroext %20, i8 signext %25)
%27 = icmp slt i64 %26, 0
br i1 %27, label %28, label %29
28: ; preds = %15
store i32 -1, i32* %4
br label %34
29: ; preds = %15
br label %30
30: ; preds = %29
%31 = load i32, i32* %9
%32 = add nsw i32 %31, 1
store i32 %32, i32* %9
br label %11
33: ; preds = %11
store i32 0, i32* %4
br label %34
34: ; preds = %33, %28
%35 = load i32, i32* %4
ret i32 %35
}

LLVM IR (-O2):
define i32 @eeprom_24cxx_write(i8 zeroext %0, i8* nocapture %1, i32 %2) {
%4 = icmp sgt i32 %2, 0
br i1 %4, label %5, label %18
5: ; preds = %3
%6 = zext i32 %2 to i64
br label %9
7: ; preds = %9
%8 = icmp eq i64 %17, %6
br i1 %8, label %18, label %9
9: ; preds = %5, %7
%10 = phi i64 [ 0, %5 ], [ %17, %7 ]
%11 = trunc i64 %10 to i8
%12 = add i8 %11, %0
%13 = getelementptr inbounds i8, i8* %1, i64 %10
%14 = load i8, i8* %13
%15 = tail call i64 @eeprom_24cxx_write_byte(i8 zeroext %12, i8 signext %14)
%16 = icmp slt i64 %15, 0
%17 = add nuw nsw i64 %10, 1
br i1 %16, label %18, label %7
18: ; preds = %9, %7, %3
%19 = phi i32 [ 0, %3 ], [ 0, %7 ], [ -1, %9 ]
ret i32 %19
}