#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*/ printf(char *, int, int);
int read(int, char *, int);
int write(int, int *, int);
int read_eeprom(int fd, char buff[], int addr, int count) {
  int res;
  if (write(fd, &addr, 1) != 1)
    return -1;
  res = read(fd, buff, count);
  printf("read %d byte at 0x %x\n", res, addr);
  return res;
}


x86 assembly (clang, -O0):
<read_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    -0x8(%rbp),%edi
lea    -0x14(%rbp),%rsi
mov    $0x1,%edx
call   1030 <write@plt>
cmp    $0x1,%eax
je     116b <read_eeprom+0x3b>
movl   $0xffffffff,-0x4(%rbp)
jmp    1195 <read_eeprom+0x65>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%edx
call   1050 <read@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%esi
mov    -0x14(%rbp),%edx
lea    0xe76(%rip),%rdi
call   1040 <printf@plt>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_eeprom>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %ecx,%r14d
mov    %edx,%r12d
mov    %rsi,%r15
mov    %edi,%ebp
mov    %edx,0xc(%rsp)
lea    0xc(%rsp),%rsi
mov    $0x1,%edx
call   1030 <write@plt>
mov    $0xffffffff,%ebx
cmp    $0x1,%eax
jne    1184 <read_eeprom+0x54>
mov    %ebp,%edi
mov    %r15,%rsi
mov    %r14d,%edx
call   1050 <read@plt>
mov    %eax,%ebx
lea    0xe86(%rip),%rdi
mov    %eax,%esi
mov    %r12d,%edx
call   1040 <printf@plt>
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [23 x i8] c"read %d byte at 0x %x\0A\00"
define i32 @read_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
store i32 %0, i32* %6
store i8* %1, i8** %7
store i32 %2, i32* %8
store i32 %3, i32* %9
%11 = load i32, i32* %6
%12 = call i32 @write(i32 %11, i32* %8, i32 1)
%13 = icmp ne i32 %12, 1
br i1 %13, label %14, label %15
14: ; preds = %4
store i32 -1, i32* %5
br label %24
15: ; preds = %4
%16 = load i32, i32* %6
%17 = load i8*, i8** %7
%18 = load i32, i32* %9
%19 = call i32 @read(i32 %16, i8* %17, i32 %18)
store i32 %19, i32* %10
%20 = load i32, i32* %10
%21 = load i32, i32* %8
%22 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i32 %20, i32 %21)
%23 = load i32, i32* %10
store i32 %23, i32* %5
br label %24
24: ; preds = %15, %14
%25 = load i32, i32* %5
ret i32 %25
}

LLVM IR (-O2):
@.str = [23 x i8] c"read %d byte at 0x %x\0A\00"
define i32 @read_eeprom(i32 %0, i8* nocapture %1, i32 %2, i32 %3) {
%5 = alloca i32
store i32 %2, i32* %5
%6 = call i32 @write(i32 %0, i32* %5, i32 1)
%7 = icmp eq i32 %6, 1
br i1 %7, label %8, label %11
8: ; preds = %4
%9 = tail call i32 @read(i32 %0, i8* %1, i32 %3)
%10 = tail call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i32 %9, i32 %2)
br label %11
11: ; preds = %4, %8
%12 = phi i32 [ %9, %8 ], [ -1, %4 ]
ret i32 %12
}