#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 */
void *i2c_read(int);
int /*<<< orphan*/ i2c_restart();
int /*<<< orphan*/ i2c_start();
int /*<<< orphan*/ i2c_stop();
int /*<<< orphan*/ i2c_write(char);
void ee24_read_sequential(char device_address, short data_address, char *data,
                          unsigned short count) {
  char control_byte = 0b10100000;
  control_byte |= (device_address << 1) & 0b00001110;
  i2c_start();
  i2c_write(control_byte);
  i2c_write(data_address >> 8);
  i2c_write((char)data_address & 0x00ff);
  i2c_restart();
  i2c_write(control_byte | 0b0000001);
  while (--count) {
    *data++ = i2c_read(0);
  }
  *data++ = i2c_read(1);
  i2c_stop();
}


x86 assembly (clang, -O0):
<ee24_read_sequential>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %cx,%ax
mov    %si,%cx
mov    %dil,%sil
mov    %sil,-0x1(%rbp)
mov    %cx,-0x4(%rbp)
mov    %rdx,-0x10(%rbp)
mov    %ax,-0x12(%rbp)
movb   $0xa0,-0x13(%rbp)
movsbl -0x1(%rbp),%ecx
shl    $0x1,%ecx
and    $0xe,%ecx
movsbl -0x13(%rbp),%eax
or     %ecx,%eax
mov    %al,-0x13(%rbp)
mov    $0x0,%al
call   1070 <i2c_start@plt>
movsbl -0x13(%rbp),%edi
call   1050 <i2c_write@plt>
movswl -0x4(%rbp),%eax
sar    $0x8,%eax
movsbl %al,%edi
call   1050 <i2c_write@plt>
mov    -0x4(%rbp),%ax
movsbl %al,%eax
and    $0xff,%eax
movsbl %al,%edi
call   1050 <i2c_write@plt>
mov    $0x0,%al
call   1040 <i2c_restart@plt>
movsbl -0x13(%rbp),%eax
or     $0x1,%eax
movsbl %al,%edi
call   1050 <i2c_write@plt>
mov    -0x12(%rbp),%ax
add    $0xffff,%ax
mov    %ax,-0x12(%rbp)
cmp    $0x0,%ax
je     1206 <ee24_read_sequential+0xb6>
xor    %edi,%edi
call   1030 <i2c_read@plt>
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x10(%rbp)
mov    %cl,(%rax)
jmp    11d1 <ee24_read_sequential+0x81>
mov    $0x1,%edi
call   1030 <i2c_read@plt>
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x10(%rbp)
mov    %cl,(%rax)
mov    $0x0,%al
call   1060 <i2c_stop@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ee24_read_sequential>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %ecx,%ebp
mov    %rdx,%rbx
mov    %esi,%r15d
mov    %edi,%r14d
add    %r14b,%r14b
and    $0xe,%r14b
lea    -0x60(%r14),%r12d
xor    %eax,%eax
call   1070 <i2c_start@plt>
movsbl %r12b,%edi
call   1050 <i2c_write@plt>
mov    %r15d,%edi
sar    $0x8,%edi
call   1050 <i2c_write@plt>
movsbl %r15b,%edi
call   1050 <i2c_write@plt>
xor    %eax,%eax
call   1040 <i2c_restart@plt>
or     $0xa1,%r14b
movsbl %r14b,%edi
call   1050 <i2c_write@plt>
add    $0xffff,%bp
je     11c3 <ee24_read_sequential+0x73>
nopl   0x0(%rax)
xor    %edi,%edi
call   1030 <i2c_read@plt>
mov    %al,(%rbx)
add    $0x1,%rbx
add    $0xffff,%bp
jne    11b0 <ee24_read_sequential+0x60>
mov    $0x1,%edi
call   1030 <i2c_read@plt>
mov    %al,(%rbx)
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1060 <i2c_stop@plt>

LLVM IR (-O0):
define void @ee24_read_sequential(i8 signext %0, i16 signext %1, i8* %2, i16 zeroext %3) {
%5 = alloca i8
%6 = alloca i16
%7 = alloca i8*
%8 = alloca i16
%9 = alloca i8
store i8 %0, i8* %5
store i16 %1, i16* %6
store i8* %2, i8** %7
store i16 %3, i16* %8
store i8 -96, i8* %9
%10 = load i8, i8* %5
%11 = sext i8 %10 to i32
%12 = shl i32 %11, 1
%13 = and i32 %12, 14
%14 = load i8, i8* %9
%15 = sext i8 %14 to i32
%16 = or i32 %15, %13
%17 = trunc i32 %16 to i8
store i8 %17, i8* %9
%18 = call i32 (...) @i2c_start()
%19 = load i8, i8* %9
%20 = call i32 @i2c_write(i8 signext %19)
%21 = load i16, i16* %6
%22 = sext i16 %21 to i32
%23 = ashr i32 %22, 8
%24 = trunc i32 %23 to i8
%25 = call i32 @i2c_write(i8 signext %24)
%26 = load i16, i16* %6
%27 = trunc i16 %26 to i8
%28 = sext i8 %27 to i32
%29 = and i32 %28, 255
%30 = trunc i32 %29 to i8
%31 = call i32 @i2c_write(i8 signext %30)
%32 = call i32 (...) @i2c_restart()
%33 = load i8, i8* %9
%34 = sext i8 %33 to i32
%35 = or i32 %34, 1
%36 = trunc i32 %35 to i8
%37 = call i32 @i2c_write(i8 signext %36)
br label %38
38: ; preds = %42, %4
%39 = load i16, i16* %8
%40 = add i16 %39, -1
store i16 %40, i16* %8
%41 = icmp ne i16 %40, 0
br i1 %41, label %42, label %47
42: ; preds = %38
%43 = call i8* @i2c_read(i32 0)
%44 = ptrtoint i8* %43 to i8
%45 = load i8*, i8** %7
%46 = getelementptr inbounds i8, i8* %45, i32 1
store i8* %46, i8** %7
store i8 %44, i8* %45
br label %38
47: ; preds = %38
%48 = call i8* @i2c_read(i32 1)
%49 = ptrtoint i8* %48 to i8
%50 = load i8*, i8** %7
%51 = getelementptr inbounds i8, i8* %50, i32 1
store i8* %51, i8** %7
store i8 %49, i8* %50
%52 = call i32 (...) @i2c_stop()
ret void
}

LLVM IR (-O2):
define void @ee24_read_sequential(i8 signext %0, i16 signext %1, i8* nocapture writeonly %2, i16 zeroext %3) {
%5 = shl i8 %0, 1
%6 = and i8 %5, 14
%7 = or i8 %6, -96
%8 = tail call i32 (...) @i2c_start()
%9 = tail call i32 @i2c_write(i8 signext %7)
%10 = lshr i16 %1, 8
%11 = trunc i16 %10 to i8
%12 = tail call i32 @i2c_write(i8 signext %11)
%13 = trunc i16 %1 to i8
%14 = tail call i32 @i2c_write(i8 signext %13)
%15 = tail call i32 (...) @i2c_restart()
%16 = or i8 %6, -95
%17 = tail call i32 @i2c_write(i8 signext %16)
%18 = add i16 %3, -1
%19 = icmp eq i16 %18, 0
br i1 %19, label %29, label %20
20: ; preds = %4, %20
%21 = phi i16 [ %27, %20 ], [ %18, %4 ]
%22 = phi i8* [ %26, %20 ], [ %2, %4 ]
%23 = tail call i8* @i2c_read(i32 0)
%24 = ptrtoint i8* %23 to i64
%25 = trunc i64 %24 to i8
%26 = getelementptr inbounds i8, i8* %22, i64 1
store i8 %25, i8* %22
%27 = add i16 %21, -1
%28 = icmp eq i16 %27, 0
br i1 %28, label %29, label %20
29: ; preds = %20, %4
%30 = phi i8* [ %2, %4 ], [ %26, %20 ]
%31 = tail call i8* @i2c_read(i32 1)
%32 = ptrtoint i8* %31 to i64
%33 = trunc i64 %32 to i8
store i8 %33, i8* %30
%34 = tail call i32 (...) @i2c_stop()
ret void
}