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


x86 assembly (clang, -O0):
<ee24_write_sequential>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %cl,%al
mov    %si,%cx
mov    %dil,%sil
mov    %sil,-0x1(%rbp)
mov    %cx,-0x4(%rbp)
mov    %rdx,-0x10(%rbp)
mov    %al,-0x11(%rbp)
movb   $0xa0,-0x12(%rbp)
movsbl -0x1(%rbp),%ecx
shl    $0x1,%ecx
and    $0xe,%ecx
movsbl -0x12(%rbp),%eax
or     %ecx,%eax
mov    %al,-0x12(%rbp)
movsbl -0x12(%rbp),%edi
call   1040 <ee24_is_busy@plt>
cmp    $0x0,%rax
je     118e <ee24_write_sequential+0x4e>
jmp    1176 <ee24_write_sequential+0x36>
mov    $0x0,%al
call   1060 <i2c_start@plt>
movsbl -0x12(%rbp),%edi
call   1030 <i2c_write@plt>
movswl -0x4(%rbp),%eax
sar    $0x8,%eax
movsbl %al,%edi
call   1030 <i2c_write@plt>
mov    -0x4(%rbp),%ax
movsbl %al,%eax
and    $0xff,%eax
movsbl %al,%edi
call   1030 <i2c_write@plt>
cmpb   $0x0,-0x11(%rbp)
je     11ef <ee24_write_sequential+0xaf>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
movsbl (%rax),%edi
call   1030 <i2c_write@plt>
mov    -0x11(%rbp),%al
add    $0xff,%al
mov    %al,-0x11(%rbp)
jmp    11c1 <ee24_write_sequential+0x81>
mov    $0x0,%al
call   1050 <i2c_stop@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ee24_write_sequential>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %ecx,%r14d
mov    %rdx,%r12
mov    %esi,%r15d
add    %dil,%dil
and    $0xe,%dil
or     $0xa0,%dil
movsbl %dil,%ebp
mov    %ebp,%edi
call   1040 <ee24_is_busy@plt>
test   %rax,%rax
jne    1160 <ee24_write_sequential+0x20>
xor    %eax,%eax
call   1060 <i2c_start@plt>
mov    %ebp,%edi
call   1030 <i2c_write@plt>
mov    %r15d,%eax
shr    $0x8,%eax
movsbl %al,%edi
call   1030 <i2c_write@plt>
movsbl %r15b,%edi
call   1030 <i2c_write@plt>
test   %r14b,%r14b
je     11b3 <ee24_write_sequential+0x73>
movzbl %r14b,%ebp
xor    %ebx,%ebx
nopl   0x0(%rax)
movsbl (%r12,%rbx,1),%edi
call   1030 <i2c_write@plt>
add    $0x1,%rbx
cmp    %bl,%bpl
jne    11a0 <ee24_write_sequential+0x60>
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1050 <i2c_stop@plt>

LLVM IR (-O0):
define void @ee24_write_sequential(i8 signext %0, i16 signext %1, i8* %2, i8 zeroext %3) {
%5 = alloca i8
%6 = alloca i16
%7 = alloca i8*
%8 = alloca i8
%9 = alloca i8
store i8 %0, i8* %5
store i16 %1, i16* %6
store i8* %2, i8** %7
store i8 %3, i8* %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
br label %18
18: ; preds = %22, %4
%19 = load i8, i8* %9
%20 = call i64 @ee24_is_busy(i8 signext %19)
%21 = icmp ne i64 %20, 0
br i1 %21, label %22, label %23
22: ; preds = %18
br label %18
23: ; preds = %18
%24 = call i32 (...) @i2c_start()
%25 = load i8, i8* %9
%26 = call i32 @i2c_write(i8 signext %25)
%27 = load i16, i16* %6
%28 = sext i16 %27 to i32
%29 = ashr i32 %28, 8
%30 = trunc i32 %29 to i8
%31 = call i32 @i2c_write(i8 signext %30)
%32 = load i16, i16* %6
%33 = trunc i16 %32 to i8
%34 = sext i8 %33 to i32
%35 = and i32 %34, 255
%36 = trunc i32 %35 to i8
%37 = call i32 @i2c_write(i8 signext %36)
br label %38
38: ; preds = %41, %23
%39 = load i8, i8* %8
%40 = icmp ne i8 %39, 0
br i1 %40, label %41, label %48
41: ; preds = %38
%42 = load i8*, i8** %7
%43 = getelementptr inbounds i8, i8* %42, i32 1
store i8* %43, i8** %7
%44 = load i8, i8* %42
%45 = call i32 @i2c_write(i8 signext %44)
%46 = load i8, i8* %8
%47 = add i8 %46, -1
store i8 %47, i8* %8
br label %38
48: ; preds = %38
%49 = call i32 (...) @i2c_stop()
ret void
}

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