#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 /*<<< orphan*/ I2C1_Rd(int);
int /*<<< orphan*/ I2C1_Repeated_Start();
int /*<<< orphan*/ I2C1_Start();
int /*<<< orphan*/ I2C1_Stop();
int /*<<< orphan*/ I2C1_Wr(int);
void eepromReadMulti(int deviceAddress, unsigned int memAddress,
                     unsigned char *values, unsigned int size) {
  I2C1_Start();
  I2C1_Wr(0xa0 + (deviceAddress << 1) + 0);
  I2C1_Wr(memAddress >> 8);
  I2C1_Wr(memAddress & 0xff);
  I2C1_Repeated_Start();
  I2C1_Wr(0xa0 + (deviceAddress << 1) + 1);
  while (size--)
    *values++ = I2C1_Rd(size != 0);
  I2C1_Stop();
}


x86 assembly (clang, -O0):
<eepromReadMulti>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %rdx,-0x10(%rbp)
mov    %ecx,-0x14(%rbp)
mov    $0x0,%al
call   1060 <I2C1_Start@plt>
mov    -0x4(%rbp),%edi
shl    $0x1,%edi
add    $0xa0,%edi
add    $0x0,%edi
call   1050 <I2C1_Wr@plt>
mov    -0x8(%rbp),%edi
shr    $0x8,%edi
call   1050 <I2C1_Wr@plt>
mov    -0x8(%rbp),%edi
and    $0xff,%edi
call   1050 <I2C1_Wr@plt>
mov    $0x0,%al
call   1070 <I2C1_Repeated_Start@plt>
mov    -0x4(%rbp),%edi
shl    $0x1,%edi
add    $0xa0,%edi
add    $0x1,%edi
call   1050 <I2C1_Wr@plt>
mov    -0x14(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x14(%rbp)
cmp    $0x0,%eax
je     11f1 <eepromReadMulti+0xa1>
cmpl   $0x0,-0x14(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1030 <I2C1_Rd@plt>
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x10(%rbp)
mov    %cl,(%rax)
jmp    11b4 <eepromReadMulti+0x64>
mov    $0x0,%al
call   1040 <I2C1_Stop@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<eepromReadMulti>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %ecx,%r14d
mov    %rdx,%r12
mov    %esi,%ebp
mov    %edi,%r15d
xor    %eax,%eax
call   1060 <I2C1_Start@plt>
lea    (%r15,%r15,1),%edi
add    $0xa0,%edi
call   1050 <I2C1_Wr@plt>
mov    %ebp,%edi
shr    $0x8,%edi
call   1050 <I2C1_Wr@plt>
movzbl %bpl,%edi
call   1050 <I2C1_Wr@plt>
xor    %eax,%eax
call   1070 <I2C1_Repeated_Start@plt>
lea    (%r15,%r15,1),%edi
add    $0xa1,%edi
call   1050 <I2C1_Wr@plt>
test   %r14d,%r14d
je     11ca <eepromReadMulti+0x7a>
mov    %r14d,%r14d
lea    -0x1(%r14),%rbx
xor    %ebp,%ebp
xor    %edi,%edi
cmp    %ebp,%ebx
setne  %dil
call   1030 <I2C1_Rd@plt>
mov    %al,(%r12,%rbp,1)
add    $0x1,%rbp
cmp    %ebp,%r14d
jne    11b0 <eepromReadMulti+0x60>
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <I2C1_Stop@plt>

LLVM IR (-O0):
define void @eepromReadMulti(i32 %0, i32 %1, i8* %2, i32 %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
store i32 %0, i32* %5
store i32 %1, i32* %6
store i8* %2, i8** %7
store i32 %3, i32* %8
%9 = call i32 (...) @I2C1_Start()
%10 = load i32, i32* %5
%11 = shl i32 %10, 1
%12 = add nsw i32 160, %11
%13 = add nsw i32 %12, 0
%14 = call i32 @I2C1_Wr(i32 %13)
%15 = load i32, i32* %6
%16 = lshr i32 %15, 8
%17 = call i32 @I2C1_Wr(i32 %16)
%18 = load i32, i32* %6
%19 = and i32 %18, 255
%20 = call i32 @I2C1_Wr(i32 %19)
%21 = call i32 (...) @I2C1_Repeated_Start()
%22 = load i32, i32* %5
%23 = shl i32 %22, 1
%24 = add nsw i32 160, %23
%25 = add nsw i32 %24, 1
%26 = call i32 @I2C1_Wr(i32 %25)
br label %27
27: ; preds = %31, %4
%28 = load i32, i32* %8
%29 = add i32 %28, -1
store i32 %29, i32* %8
%30 = icmp ne i32 %28, 0
br i1 %30, label %31, label %39
31: ; preds = %27
%32 = load i32, i32* %8
%33 = icmp ne i32 %32, 0
%34 = zext i1 %33 to i32
%35 = call i32 @I2C1_Rd(i32 %34)
%36 = trunc i32 %35 to i8
%37 = load i8*, i8** %7
%38 = getelementptr inbounds i8, i8* %37, i32 1
store i8* %38, i8** %7
store i8 %36, i8* %37
br label %27
39: ; preds = %27
%40 = call i32 (...) @I2C1_Stop()
ret void
}

LLVM IR (-O2):
define void @eepromReadMulti(i32 %0, i32 %1, i8* nocapture writeonly %2, i32 %3) {
%5 = tail call i32 (...) @I2C1_Start()
%6 = shl i32 %0, 1
%7 = add nsw i32 %6, 160
%8 = tail call i32 @I2C1_Wr(i32 %7)
%9 = lshr i32 %1, 8
%10 = tail call i32 @I2C1_Wr(i32 %9)
%11 = and i32 %1, 255
%12 = tail call i32 @I2C1_Wr(i32 %11)
%13 = tail call i32 (...) @I2C1_Repeated_Start()
%14 = add nsw i32 %6, 161
%15 = tail call i32 @I2C1_Wr(i32 %14)
%16 = icmp eq i32 %3, 0
br i1 %16, label %27, label %17
17: ; preds = %4, %17
%18 = phi i32 [ %20, %17 ], [ %3, %4 ]
%19 = phi i8* [ %25, %17 ], [ %2, %4 ]
%20 = add i32 %18, -1
%21 = icmp ne i32 %20, 0
%22 = zext i1 %21 to i32
%23 = tail call i32 @I2C1_Rd(i32 %22)
%24 = trunc i32 %23 to i8
%25 = getelementptr inbounds i8, i8* %19, i64 1
store i8 %24, i8* %19
%26 = icmp eq i32 %20, 0
br i1 %26, label %27, label %17
27: ; preds = %17, %4
%28 = tail call i32 (...) @I2C1_Stop()
ret void
}