#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 */
struct eeprom {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ do_die_if(int, char *, int);
int eeprom_read_byte(struct eeprom *, int);
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdout;
int read_from_eeprom(struct eeprom *e, int addr, int size) {
  int ch, i;
  for (i = 0; i < size; ++i, ++addr) {
    do {
      do_die_if((ch = eeprom_read_byte(e, addr)) < 0, "read error", 57);
    } while (0);
    ;
    if ((i % 16) == 0)
      printf("\n %.4x|  ", addr);
    else if ((i % 8) == 0)
      printf("  ");
    printf("%.2x ", ch);
    fflush(stdout);
  }
  fprintf(stderr, "\n\n");
  return 0;
}


x86 assembly (clang, -O0):
<read_from_eeprom>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    122c <read_from_eeprom+0xdc>
jmp    117a <read_from_eeprom+0x2a>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1070 <eeprom_read_byte@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
setl   %al
and    $0x1,%al
movzbl %al,%edi
lea    0xe65(%rip),%rsi
mov    $0x39,%edx
call   1030 <do_die_if@plt>
mov    -0x18(%rbp),%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    11cf <read_from_eeprom+0x7f>
mov    -0xc(%rbp),%esi
lea    0xe48(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    11f6 <read_from_eeprom+0xa6>
mov    -0x18(%rbp),%eax
mov    $0x8,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    11f1 <read_from_eeprom+0xa1>
lea    0xe28(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    11f6 <read_from_eeprom+0xa6>
mov    -0x14(%rbp),%esi
lea    0xe15(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    0x2dca(%rip),%rax
mov    (%rax),%edi
call   1060 <fflush@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1169 <read_from_eeprom+0x19>
mov    0x2dad(%rip),%rax
mov    (%rax),%edi
lea    0xddf(%rip),%rsi
call   1050 <fprintf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_from_eeprom>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
test   %edx,%edx
jle    11eb <read_from_eeprom+0x9b>
mov    %edx,%ebx
mov    %esi,%r14d
mov    %rdi,%r15
xor    %ebp,%ebp
jmp    11a7 <read_from_eeprom+0x57>
nop
lea    0xe94(%rip),%rdi
mov    %r12d,%esi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe8d(%rip),%rdi
mov    %r13d,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x2e3f(%rip),%rax
mov    (%rax),%edi
call   1060 <fflush@plt>
add    $0x1,%ebp
cmp    %ebp,%ebx
je     11eb <read_from_eeprom+0x9b>
lea    (%r14,%rbp,1),%r12d
mov    %r15,%rdi
mov    %r12d,%esi
call   1070 <eeprom_read_byte@plt>
mov    %eax,%r13d
mov    %eax,%edi
shr    $0x1f,%edi
lea    0xe3b(%rip),%rsi
mov    $0x39,%edx
call   1030 <do_die_if@plt>
test   $0xf,%bpl
je     1170 <read_from_eeprom+0x20>
test   $0x7,%bpl
jne    1181 <read_from_eeprom+0x31>
lea    0xe30(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    1181 <read_from_eeprom+0x31>
mov    0x2dee(%rip),%rax
mov    (%rax),%edi
lea    0xe20(%rip),%rsi
call   1050 <fprintf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.eeprom = type { i32 }
@.str = [11 x i8] c"read error\00"
@.str.1 = [10 x i8] c"\0A %.4x| \00"
@.str.2 = [3 x i8] c" \00"
@.str.3 = [6 x i8] c"%.2x \00"
@stdout = global i32 0
@stderr = global i32 0
@.str.4 = [3 x i8] c"\0A\0A\00"
define i32 @read_from_eeprom(%struct.eeprom* %0, i32 %1, i32 %2) {
%4 = alloca %struct.eeprom*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store %struct.eeprom* %0, %struct.eeprom** %4
store i32 %1, i32* %5
store i32 %2, i32* %6
store i32 0, i32* %8
br label %9
9: ; preds = %40, %3
%10 = load i32, i32* %8
%11 = load i32, i32* %6
%12 = icmp slt i32 %10, %11
br i1 %12, label %13, label %45
13: ; preds = %9
br label %14
14: ; preds = %13
%15 = load %struct.eeprom*, %struct.eeprom** %4
%16 = load i32, i32* %5
%17 = call i32 @eeprom_read_byte(%struct.eeprom* %15, i32 %16)
store i32 %17, i32* %7
%18 = icmp slt i32 %17, 0
%19 = zext i1 %18 to i32
%20 = call i32 @do_die_if(i32 %19, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 57)
br label %21
21: ; preds = %14
%22 = load i32, i32* %8
%23 = srem i32 %22, 16
%24 = icmp eq i32 %23, 0
br i1 %24, label %25, label %28
25: ; preds = %21
%26 = load i32, i32* %5
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32 %26)
br label %35
28: ; preds = %21
%29 = load i32, i32* %8
%30 = srem i32 %29, 8
%31 = icmp eq i32 %30, 0
br i1 %31, label %32, label %34
32: ; preds = %28
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
br label %34
34: ; preds = %32, %28
br label %35
35: ; preds = %34, %25
%36 = load i32, i32* %7
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i32 %36)
%38 = load i32, i32* @stdout
%39 = call i32 @fflush(i32 %38)
br label %40
40: ; preds = %35
%41 = load i32, i32* %8
%42 = add nsw i32 %41, 1
store i32 %42, i32* %8
%43 = load i32, i32* %5
%44 = add nsw i32 %43, 1
store i32 %44, i32* %5
br label %9
45: ; preds = %9
%46 = load i32, i32* @stderr
%47 = call i32 @fprintf(i32 %46, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
%struct.eeprom = type { i32 }
@.str = [11 x i8] c"read error\00"
@.str.1 = [10 x i8] c"\0A %.4x| \00"
@.str.2 = [3 x i8] c" \00"
@.str.3 = [6 x i8] c"%.2x \00"
@stdout = global i32 0
@stderr = global i32 0
@.str.4 = [3 x i8] c"\0A\0A\00"
define i32 @read_from_eeprom(%struct.eeprom* %0, i32 %1, i32 %2) {
%4 = icmp sgt i32 %2, 0
br i1 %4, label %5, label %27
5: ; preds = %3, %20
%6 = phi i32 [ %24, %20 ], [ 0, %3 ]
%7 = phi i32 [ %25, %20 ], [ %1, %3 ]
%8 = tail call i32 @eeprom_read_byte(%struct.eeprom* %0, i32 %7)
%9 = lshr i32 %8, 31
%10 = tail call i32 @do_die_if(i32 %9, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 57)
%11 = and i32 %6, 15
%12 = icmp eq i32 %11, 0
br i1 %12, label %13, label %15
13: ; preds = %5
%14 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32 %7)
br label %20
15: ; preds = %5
%16 = and i32 %6, 7
%17 = icmp eq i32 %16, 0
br i1 %17, label %18, label %20
18: ; preds = %15
%19 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
br label %20
20: ; preds = %15, %18, %13
%21 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i32 %8)
%22 = load i32, i32* @stdout
%23 = tail call i32 @fflush(i32 %22)
%24 = add nuw nsw i32 %6, 1
%25 = add nsw i32 %7, 1
%26 = icmp eq i32 %24, %2
br i1 %26, label %27, label %5
27: ; preds = %20, %3
%28 = load i32, i32* @stderr
%29 = tail call i32 @fprintf(i32 %28, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
ret i32 0
}