#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 */
typedef int /*<<< orphan*/ uint8_t;
typedef int uint32_t;
typedef scalar_t__ int32_t;

/* Variables and functions */
scalar_t__ I2C_Xfer(int, int /*<<< orphan*/ *, int, int);
int32_t EEPROM_Read(uint8_t *dest, uint32_t startpos, uint32_t len) {
  int32_t retval = 0;
  if (startpos < 256 && dest && len && len <= 256) {
    uint8_t offset = (uint8_t)startpos;
    retval = I2C_Xfer((0x50 << 1), &offset, 1, 0);
    if (!retval) {
      retval = I2C_Xfer((0x50 << 1) | 1, dest, len, 1);
    }
  }
  return retval;
}


x86 assembly (clang, -O0):
<EEPROM_Read>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
cmpl   $0x100,-0xc(%rbp)
jge    11a2 <EEPROM_Read+0x92>
cmpq   $0x0,-0x8(%rbp)
je     11a2 <EEPROM_Read+0x92>
cmpl   $0x0,-0x10(%rbp)
je     11a2 <EEPROM_Read+0x92>
cmpl   $0x100,-0x10(%rbp)
jg     11a2 <EEPROM_Read+0x92>
mov    -0xc(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    $0xa0,%edi
lea    -0x1c(%rbp),%rsi
mov    $0x1,%edx
xor    %ecx,%ecx
call   1030 <I2C_Xfer@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    119d <EEPROM_Read+0x8d>
mov    -0x8(%rbp),%rsi
mov    -0x10(%rbp),%edx
mov    $0xa1,%edi
mov    $0x1,%ecx
call   1030 <I2C_Xfer@plt>
mov    %rax,-0x18(%rbp)
jmp    11a2 <EEPROM_Read+0x92>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<EEPROM_Read>:
push   %r14
push   %rbx
push   %rax
xor    %eax,%eax
cmp    $0x100,%edx
jg     1167 <EEPROM_Read+0x57>
mov    %rdi,%r14
test   %rdi,%rdi
je     1167 <EEPROM_Read+0x57>
cmp    $0xff,%esi
jg     1167 <EEPROM_Read+0x57>
mov    %edx,%ebx
test   %edx,%edx
je     1167 <EEPROM_Read+0x57>
mov    %esi,0x4(%rsp)
lea    0x4(%rsp),%rsi
mov    $0xa0,%edi
mov    $0x1,%edx
xor    %ecx,%ecx
call   1030 <I2C_Xfer@plt>
test   %rax,%rax
jne    1167 <EEPROM_Read+0x57>
mov    $0xa1,%edi
mov    %r14,%rsi
mov    %ebx,%edx
mov    $0x1,%ecx
call   1030 <I2C_Xfer@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i64 @EEPROM_Read(i32* %0, i32 %1, i32 %2) {
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i64
%8 = alloca i32
store i32* %0, i32** %4
store i32 %1, i32* %5
store i32 %2, i32* %6
store i64 0, i64* %7
%9 = load i32, i32* %5
%10 = icmp slt i32 %9, 256
br i1 %10, label %11, label %30
11: ; preds = %3
%12 = load i32*, i32** %4
%13 = icmp ne i32* %12, null
br i1 %13, label %14, label %30
14: ; preds = %11
%15 = load i32, i32* %6
%16 = icmp ne i32 %15, 0
br i1 %16, label %17, label %30
17: ; preds = %14
%18 = load i32, i32* %6
%19 = icmp sle i32 %18, 256
br i1 %19, label %20, label %30
20: ; preds = %17
%21 = load i32, i32* %5
store i32 %21, i32* %8
%22 = call i64 @I2C_Xfer(i32 160, i32* %8, i32 1, i32 0)
store i64 %22, i64* %7
%23 = load i64, i64* %7
%24 = icmp ne i64 %23, 0
br i1 %24, label %29, label %25
25: ; preds = %20
%26 = load i32*, i32** %4
%27 = load i32, i32* %6
%28 = call i64 @I2C_Xfer(i32 161, i32* %26, i32 %27, i32 1)
store i64 %28, i64* %7
br label %29
29: ; preds = %25, %20
br label %30
30: ; preds = %29, %17, %14, %11, %3
%31 = load i64, i64* %7
ret i64 %31
}

LLVM IR (-O2):
define i64 @EEPROM_Read(i32* %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = icmp slt i32 %1, 256
%6 = icmp ne i32* %0, null
%7 = and i1 %6, %5
%8 = icmp ne i32 %2, 0
%9 = and i1 %7, %8
%10 = icmp slt i32 %2, 257
%11 = and i1 %10, %9
br i1 %11, label %12, label %20
12: ; preds = %3
%13 = bitcast i32* %4 to i8*
store i32 %1, i32* %4
%14 = call i64 @I2C_Xfer(i32 160, i32* %4, i32 1, i32 0)
%15 = icmp eq i64 %14, 0
br i1 %15, label %16, label %18
16: ; preds = %12
%17 = call i64 @I2C_Xfer(i32 161, i32* %0, i32 %2, i32 1)
br label %18
18: ; preds = %16, %12
%19 = phi i64 [ %14, %12 ], [ %17, %16 ]
br label %20
20: ; preds = %18, %3
%21 = phi i64 [ %19, %18 ], [ 0, %3 ]
ret i64 %21
}