#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*/ I2C_ack();
int /*<<< orphan*/ I2C_noack();
unsigned char I2C_read();
int /*<<< orphan*/ I2C_start();
int /*<<< orphan*/ I2C_stop();
int /*<<< orphan*/ I2C_write(int);
void EEPROM_pager(unsigned int addr, unsigned int number,
                  unsigned char *data1) {
  int i;
  I2C_start();
  I2C_write(0xA0);
  I2C_write(addr & 0xF0);
  I2C_write(addr & 0x0F);
  I2C_start();
  I2C_write(0xA0 + 1);
  for (i = 0; i < number; i++, data1++) {
    *data1 = I2C_read();
    if (i != (number - 1))
      I2C_ack();
  }
  I2C_noack();
  I2C_stop();
}


x86 assembly (clang, -O0):
<EEPROM_pager>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %rdx,-0x10(%rbp)
mov    $0x0,%al
call   1060 <I2C_start@plt>
mov    $0xa0,%edi
call   1080 <I2C_write@plt>
mov    -0x4(%rbp),%edi
and    $0xf0,%edi
call   1080 <I2C_write@plt>
mov    -0x4(%rbp),%edi
and    $0xf,%edi
call   1080 <I2C_write@plt>
mov    $0x0,%al
call   1060 <I2C_start@plt>
mov    $0xa1,%edi
call   1080 <I2C_write@plt>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x8(%rbp),%eax
jae    1206 <EEPROM_pager+0xa6>
mov    $0x0,%al
call   1050 <I2C_read@plt>
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %cl,(%rax)
mov    -0x14(%rbp),%eax
mov    -0x8(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
je     11e7 <EEPROM_pager+0x87>
mov    $0x0,%al
call   1070 <I2C_ack@plt>
jmp    11ec <EEPROM_pager+0x8c>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    11b4 <EEPROM_pager+0x54>
mov    $0x0,%al
call   1030 <I2C_noack@plt>
mov    $0x0,%al
call   1040 <I2C_stop@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<EEPROM_pager>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %esi,%r15d
mov    %edi,%ebp
xor    %eax,%eax
call   1060 <I2C_start@plt>
mov    $0xa0,%edi
call   1080 <I2C_write@plt>
mov    %ebp,%edi
and    $0xf0,%edi
call   1080 <I2C_write@plt>
and    $0xf,%ebp
mov    %ebp,%edi
call   1080 <I2C_write@plt>
xor    %eax,%eax
call   1060 <I2C_start@plt>
mov    $0xa1,%edi
call   1080 <I2C_write@plt>
test   %r15d,%r15d
je     11e8 <EEPROM_pager+0x88>
neg    %r15d
xor    %ebp,%ebp
jmp    11cb <EEPROM_pager+0x6b>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
add    $0x1,%rbp
mov    %ebp,%eax
add    %r15d,%eax
je     11e8 <EEPROM_pager+0x88>
lea    (%r15,%rbp,1),%ebx
xor    %eax,%eax
call   1050 <I2C_read@plt>
mov    %al,(%r14,%rbp,1)
cmp    $0xffffffff,%ebx
je     11c0 <EEPROM_pager+0x60>
xor    %eax,%eax
call   1070 <I2C_ack@plt>
jmp    11c0 <EEPROM_pager+0x60>
xor    %eax,%eax
call   1030 <I2C_noack@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <I2C_stop@plt>

LLVM IR (-O0):
define void @EEPROM_pager(i32 %0, i32 %1, i8* %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
store i8* %2, i8** %6
%8 = call i32 (...) @I2C_start()
%9 = call i32 @I2C_write(i32 160)
%10 = load i32, i32* %4
%11 = and i32 %10, 240
%12 = call i32 @I2C_write(i32 %11)
%13 = load i32, i32* %4
%14 = and i32 %13, 15
%15 = call i32 @I2C_write(i32 %14)
%16 = call i32 (...) @I2C_start()
%17 = call i32 @I2C_write(i32 161)
store i32 0, i32* %7
br label %18
18: ; preds = %32, %3
%19 = load i32, i32* %7
%20 = load i32, i32* %5
%21 = icmp ult i32 %19, %20
br i1 %21, label %22, label %37
22: ; preds = %18
%23 = call zeroext i8 (...) @I2C_read()
%24 = load i8*, i8** %6
store i8 %23, i8* %24
%25 = load i32, i32* %7
%26 = load i32, i32* %5
%27 = sub i32 %26, 1
%28 = icmp ne i32 %25, %27
br i1 %28, label %29, label %31
29: ; preds = %22
%30 = call i32 (...) @I2C_ack()
br label %31
31: ; preds = %29, %22
br label %32
32: ; preds = %31
%33 = load i32, i32* %7
%34 = add nsw i32 %33, 1
store i32 %34, i32* %7
%35 = load i8*, i8** %6
%36 = getelementptr inbounds i8, i8* %35, i32 1
store i8* %36, i8** %6
br label %18
37: ; preds = %18
%38 = call i32 (...) @I2C_noack()
%39 = call i32 (...) @I2C_stop()
ret void
}

LLVM IR (-O2):
define void @EEPROM_pager(i32 %0, i32 %1, i8* nocapture writeonly %2) {
%4 = tail call i32 (...) @I2C_start()
%5 = tail call i32 @I2C_write(i32 160)
%6 = and i32 %0, 240
%7 = tail call i32 @I2C_write(i32 %6)
%8 = and i32 %0, 15
%9 = tail call i32 @I2C_write(i32 %8)
%10 = tail call i32 (...) @I2C_start()
%11 = tail call i32 @I2C_write(i32 161)
%12 = icmp eq i32 %1, 0
br i1 %12, label %26, label %13
13: ; preds = %3
%14 = add i32 %1, -1
br label %15
15: ; preds = %13, %22
%16 = phi i32 [ 0, %13 ], [ %23, %22 ]
%17 = phi i8* [ %2, %13 ], [ %24, %22 ]
%18 = tail call zeroext i8 (...) @I2C_read()
store i8 %18, i8* %17
%19 = icmp eq i32 %16, %14
br i1 %19, label %22, label %20
20: ; preds = %15
%21 = tail call i32 (...) @I2C_ack()
br label %22
22: ; preds = %15, %20
%23 = add nuw i32 %16, 1
%24 = getelementptr inbounds i8, i8* %17, i64 1
%25 = icmp eq i32 %23, %1
br i1 %25, label %26, label %15
26: ; preds = %22, %3
%27 = tail call i32 (...) @I2C_noack()
%28 = tail call i32 (...) @I2C_stop()
ret void
}