#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*/ printf(char *, ...);
int /*<<< orphan*/ putchar(int);
int /*<<< orphan*/ stdout;
int read_from_eeprom(struct eeprom *e, int addr, int size, int hex) {
  int ch, i;
  for (i = 0; i < size; ++i, ++addr) {
    do {
      do_die_if((ch = eeprom_read_byte(e, addr)) < 0, "read error", 127);
    } while (0);
    ;
    if (hex) {
      if ((i % 16) == 0)
        printf("\n %.4x|  ", addr);
      else if ((i % 8) == 0)
        printf("  ");
      printf("%.2x ", ch);
    } else
      putchar(ch);
  }
  if (hex)
    printf("\n\n");
  fflush(stdout);
  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)
mov    %ecx,-0x14(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    123d <read_from_eeprom+0xed>
jmp    117d <read_from_eeprom+0x2d>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1070 <eeprom_read_byte@plt>
mov    %eax,-0x18(%rbp)
cmp    $0x0,%eax
setl   %al
and    $0x1,%al
movzbl %al,%edi
lea    0xe62(%rip),%rsi
mov    $0x7f,%edx
call   1030 <do_die_if@plt>
cmpl   $0x0,-0x14(%rbp)
je     1219 <read_from_eeprom+0xc9>
mov    -0x1c(%rbp),%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    11dc <read_from_eeprom+0x8c>
mov    -0xc(%rbp),%esi
lea    0xe3b(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    1203 <read_from_eeprom+0xb3>
mov    -0x1c(%rbp),%eax
mov    $0x8,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    11fe <read_from_eeprom+0xae>
lea    0xe1b(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    1203 <read_from_eeprom+0xb3>
mov    -0x18(%rbp),%esi
lea    0xe08(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    1221 <read_from_eeprom+0xd1>
mov    -0x18(%rbp),%edi
call   1040 <putchar@plt>
jmp    1226 <read_from_eeprom+0xd6>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    116c <read_from_eeprom+0x1c>
cmpl   $0x0,-0x14(%rbp)
je     1255 <read_from_eeprom+0x105>
lea    0xdcd(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    0x2d84(%rip),%rax
mov    (%rax),%edi
call   1060 <fflush@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
mov    %ecx,%ebx
mov    %rsi,(%rsp)
test   %edx,%edx
jle    121a <read_from_eeprom+0xba>
mov    %edx,%ebp
mov    %rdi,%r15
xor    %r14d,%r14d
jmp    11bb <read_from_eeprom+0x5b>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
lea    0xe74(%rip),%rdi
mov    %r12d,%esi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xe6d(%rip),%rdi
mov    %r13d,%esi
xor    %eax,%eax
call   1060 <printf@plt>
add    $0x1,%r14d
cmp    %r14d,%ebp
je     121a <read_from_eeprom+0xba>
mov    (%rsp),%rax
lea    (%rax,%r14,1),%r12d
mov    %r15,%rdi
mov    %r12d,%esi
call   1080 <eeprom_read_byte@plt>
mov    %eax,%r13d
mov    %eax,%edi
shr    $0x1f,%edi
lea    0xe23(%rip),%rsi
mov    $0x7f,%edx
call   1030 <do_die_if@plt>
test   %ebx,%ebx
je     1210 <read_from_eeprom+0xb0>
test   $0xf,%r14b
je     1190 <read_from_eeprom+0x30>
test   $0x7,%r14b
jne    11a1 <read_from_eeprom+0x41>
lea    0xe14(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
jmp    11a1 <read_from_eeprom+0x41>
nopw   0x0(%rax,%rax,1)
mov    %r13d,%edi
call   1040 <putchar@plt>
jmp    11b2 <read_from_eeprom+0x52>
test   %ebx,%ebx
je     122a <read_from_eeprom+0xca>
lea    0xdf6(%rip),%rdi
call   1050 <puts@plt>
mov    0x2daf(%rip),%rax
mov    (%rax),%edi
call   1070 <fflush@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"
@.str.4 = [3 x i8] c"\0A\0A\00"
@stdout = global i32 0
define i32 @read_from_eeprom(%struct.eeprom* %0, i32 %1, i32 %2, i32 %3) {
%5 = alloca %struct.eeprom*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store %struct.eeprom* %0, %struct.eeprom** %5
store i32 %1, i32* %6
store i32 %2, i32* %7
store i32 %3, i32* %8
store i32 0, i32* %10
br label %11
11: ; preds = %47, %4
%12 = load i32, i32* %10
%13 = load i32, i32* %7
%14 = icmp slt i32 %12, %13
br i1 %14, label %15, label %52
15: ; preds = %11
br label %16
16: ; preds = %15
%17 = load %struct.eeprom*, %struct.eeprom** %5
%18 = load i32, i32* %6
%19 = call i32 @eeprom_read_byte(%struct.eeprom* %17, i32 %18)
store i32 %19, i32* %9
%20 = icmp slt i32 %19, 0
%21 = zext i1 %20 to i32
%22 = call i32 @do_die_if(i32 %21, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 127)
br label %23
23: ; preds = %16
%24 = load i32, i32* %8
%25 = icmp ne i32 %24, 0
br i1 %25, label %26, label %43
26: ; preds = %23
%27 = load i32, i32* %10
%28 = srem i32 %27, 16
%29 = icmp eq i32 %28, 0
br i1 %29, label %30, label %33
30: ; preds = %26
%31 = load i32, i32* %6
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32 %31)
br label %40
33: ; preds = %26
%34 = load i32, i32* %10
%35 = srem i32 %34, 8
%36 = icmp eq i32 %35, 0
br i1 %36, label %37, label %39
37: ; preds = %33
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
br label %39
39: ; preds = %37, %33
br label %40
40: ; preds = %39, %30
%41 = load i32, i32* %9
%42 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i32 %41)
br label %46
43: ; preds = %23
%44 = load i32, i32* %9
%45 = call i32 @putchar(i32 %44)
br label %46
46: ; preds = %43, %40
br label %47
47: ; preds = %46
%48 = load i32, i32* %10
%49 = add nsw i32 %48, 1
store i32 %49, i32* %10
%50 = load i32, i32* %6
%51 = add nsw i32 %50, 1
store i32 %51, i32* %6
br label %11
52: ; preds = %11
%53 = load i32, i32* %8
%54 = icmp ne i32 %53, 0
br i1 %54, label %55, label %57
55: ; preds = %52
%56 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
br label %57
57: ; preds = %55, %52
%58 = load i32, i32* @stdout
%59 = call i32 @fflush(i32 %58)
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
@str = [2 x i8] c"\0A\00"
define i32 @read_from_eeprom(%struct.eeprom* %0, i32 %1, i32 %2, i32 %3) {
%5 = icmp sgt i32 %2, 0
br i1 %5, label %6, label %32
6: ; preds = %4
%7 = icmp eq i32 %3, 0
br label %8
8: ; preds = %6, %28
%9 = phi i32 [ 0, %6 ], [ %29, %28 ]
%10 = phi i32 [ %1, %6 ], [ %30, %28 ]
%11 = tail call i32 @eeprom_read_byte(%struct.eeprom* %0, i32 %10)
%12 = lshr i32 %11, 31
%13 = tail call i32 @do_die_if(i32 %12, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 127)
br i1 %7, label %26, label %14
14: ; preds = %8
%15 = and i32 %9, 15
%16 = icmp eq i32 %15, 0
br i1 %16, label %17, label %19
17: ; preds = %14
%18 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32 %10)
br label %24
19: ; preds = %14
%20 = and i32 %9, 7
%21 = icmp eq i32 %20, 0
br i1 %21, label %22, label %24
22: ; preds = %19
%23 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
br label %24
24: ; preds = %19, %22, %17
%25 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i32 %11)
br label %28
26: ; preds = %8
%27 = tail call i32 @putchar(i32 %11)
br label %28
28: ; preds = %24, %26
%29 = add nuw nsw i32 %9, 1
%30 = add nsw i32 %10, 1
%31 = icmp eq i32 %29, %2
br i1 %31, label %32, label %8
32: ; preds = %28, %4
%33 = icmp eq i32 %3, 0
br i1 %33, label %36, label %34
34: ; preds = %32
%35 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([2 x i8], [2 x i8]* @str, i64 0, i64 0))
br label %36
36: ; preds = %34, %32
%37 = load i32, i32* @stdout
%38 = tail call i32 @fflush(i32 %37)
ret i32 0
}