#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*/ memcpy(char *, char *, int);
int /*<<< orphan*/ printf(char *, int, int);
int write(int, char **, int);
int write_eeprom(int fd, char buff[], int addr, int count) {
  int res;
  int i;
  static char sendbuffer[8 + 1];
  memcpy(sendbuffer + 1, buff, count);
  sendbuffer[0] = addr;
  res = write(fd, &sendbuffer, count + 1);
  printf("write %d byte at 0x%x\n", res, addr);
}


x86 assembly (clang, -O0):
<write_eeprom>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%edx
lea    0x2ee7(%rip),%rdi
call   1050 <memcpy@plt>
mov    -0x14(%rbp),%eax
mov    %al,0x2ed8(%rip)
mov    -0x8(%rbp),%edi
mov    -0x18(%rbp),%edx
add    $0x1,%edx
lea    0x2ec8(%rip),%rsi
call   1030 <write@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%esi
mov    -0x14(%rbp),%edx
lea    0xe7a(%rip),%rdi
call   1040 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_eeprom>:
push   %rbp
push   %r14
push   %rbx
mov    %ecx,%ebx
mov    %edx,%ebp
mov    %edi,%r14d
lea    0x2ef8(%rip),%rdi
mov    %ecx,%edx
call   1050 <memcpy@plt>
lea    0x2ee9(%rip),%rsi
mov    %bpl,0x2ee2(%rip)
add    $0x1,%ebx
mov    %r14d,%edi
mov    %ebx,%edx
call   1030 <write@plt>
lea    0xe95(%rip),%rdi
mov    %eax,%esi
mov    %ebp,%edx
pop    %rbx
pop    %r14
pop    %rbp
jmp    1040 <printf@plt>

LLVM IR (-O0):
@write_eeprom.sendbuffer = internal global [9 x i8] zeroinitializer
@.str = [23 x i8] c"write %d byte at 0x%x\0A\00"
define i32 @write_eeprom(i32 %0, i8* %1, i32 %2, i32 %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
store i32 %0, i32* %6
store i8* %1, i8** %7
store i32 %2, i32* %8
store i32 %3, i32* %9
%12 = load i8*, i8** %7
%13 = load i32, i32* %9
%14 = call i32 @memcpy(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @write_eeprom.sendbuffer, i64 0, i64 1), i8* %12, i32 %13)
%15 = load i32, i32* %8
%16 = trunc i32 %15 to i8
store i8 %16, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @write_eeprom.sendbuffer, i64 0, i64 0)
%17 = load i32, i32* %6
%18 = load i32, i32* %9
%19 = add nsw i32 %18, 1
%20 = call i32 @write(i32 %17, i8** bitcast ([9 x i8]* @write_eeprom.sendbuffer to i8**), i32 %19)
store i32 %20, i32* %10
%21 = load i32, i32* %10
%22 = load i32, i32* %8
%23 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i32 %21, i32 %22)
%24 = load i32, i32* %5
ret i32 %24
}

LLVM IR (-O2):
@write_eeprom.sendbuffer = internal global [9 x i8] zeroinitializer
@.str = [23 x i8] c"write %d byte at 0x%x\0A\00"
define i32 @write_eeprom(i32 %0, i8* %1, i32 %2, i32 %3) {
%5 = tail call i32 @memcpy(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @write_eeprom.sendbuffer, i64 0, i64 1), i8* %1, i32 %3)
%6 = trunc i32 %2 to i8
store i8 %6, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @write_eeprom.sendbuffer, i64 0, i64 0)
%7 = add nsw i32 %3, 1
%8 = tail call i32 @write(i32 %0, i8** bitcast ([9 x i8]* @write_eeprom.sendbuffer to i8**), i32 %7)
%9 = tail call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i32 %8, i32 %2)
ret i32 undef
}