#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 */
int eeprom_24cxx_read_byte(unsigned char, char *);
int eeprom_24cxx_read(unsigned char address, void *dest, int length) {
  char *buf = (char *)dest;
  int ret = 0;
  int i;
  for (i = 0; i < length; i++) {
    ret = eeprom_24cxx_read_byte(address + i, &buf[i]);
    if (ret < 0)
      return ret;
  }
  return ret;
}


x86 assembly (clang, -O0):
<eeprom_24cxx_read>:
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)
movl   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    118c <eeprom_24cxx_read+0x7c>
movzbl -0x5(%rbp),%eax
add    -0x28(%rbp),%eax
mov    -0x20(%rbp),%rsi
movslq -0x28(%rbp),%rcx
add    %rcx,%rsi
movzbl %al,%edi
call   1030 <eeprom_24cxx_read_byte@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jge    1179 <eeprom_24cxx_read+0x69>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1192 <eeprom_24cxx_read+0x82>
jmp    117e <eeprom_24cxx_read+0x6e>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    113b <eeprom_24cxx_read+0x2b>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<eeprom_24cxx_read>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
test   %edx,%edx
jle    1156 <eeprom_24cxx_read+0x46>
mov    %rsi,%rbx
mov    %edi,%ebp
mov    %edx,%r14d
mov    $0x1,%r15d
nopl   0x0(%rax)
movzbl %bpl,%edi
mov    %rbx,%rsi
call   1030 <eeprom_24cxx_read_byte@plt>
test   %eax,%eax
js     1158 <eeprom_24cxx_read+0x48>
add    $0x1,%bpl
add    $0x1,%rbx
lea    0x1(%r15),%rcx
cmp    %r14,%r15
mov    %rcx,%r15
jb     1130 <eeprom_24cxx_read+0x20>
jmp    1158 <eeprom_24cxx_read+0x48>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

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