#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 eeprom_read_current_byte(struct eeprom *);
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;
  do {
    do_die_if((ch = eeprom_read_byte(e, addr)) < 0, "read error", 127);
  } while (0);
  ;
  i = 1;
  if (hex)
    printf("\n %.4x|  %.2x ", addr, ch);
  else
    putchar(ch);
  while (--size) {
    do {
      do_die_if((ch = eeprom_read_current_byte(e)) < 0, "read error", 135);
    } while (0);
    ;
    if (hex) {
      addr++;
      if ((i % 16) == 0)
        printf("\n %.4x|  ", addr);
      else if ((i % 8) == 0)
        printf("  ");
      i++;
      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)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1080 <eeprom_read_byte@plt>
mov    %eax,-0x18(%rbp)
cmp    $0x0,%eax
setl   %al
and    $0x1,%al
movzbl %al,%edi
lea    0xe6a(%rip),%rsi
mov    $0x7f,%edx
call   1030 <do_die_if@plt>
movl   $0x1,-0x1c(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     11ca <read_from_eeprom+0x6a>
mov    -0xc(%rbp),%esi
mov    -0x18(%rbp),%edx
lea    0xe4d(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    11d2 <read_from_eeprom+0x72>
mov    -0x18(%rbp),%edi
call   1040 <putchar@plt>
jmp    11d7 <read_from_eeprom+0x77>
mov    -0x10(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x10(%rbp)
cmp    $0x0,%eax
je     12a6 <read_from_eeprom+0x146>
jmp    11ee <read_from_eeprom+0x8e>
mov    -0x8(%rbp),%rdi
call   1060 <eeprom_read_current_byte@plt>
mov    %eax,-0x18(%rbp)
cmp    $0x0,%eax
setl   %al
and    $0x1,%al
movzbl %al,%edi
lea    0xdf4(%rip),%rsi
mov    $0x87,%edx
call   1030 <do_die_if@plt>
cmpl   $0x0,-0x14(%rbp)
je     1299 <read_from_eeprom+0x139>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
mov    -0x1c(%rbp),%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    1253 <read_from_eeprom+0xf3>
mov    -0xc(%rbp),%esi
lea    0xdd3(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    127a <read_from_eeprom+0x11a>
mov    -0x1c(%rbp),%eax
mov    $0x8,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    1275 <read_from_eeprom+0x115>
lea    0xdb3(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    127a <read_from_eeprom+0x11a>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%esi
lea    0xd87(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    12a1 <read_from_eeprom+0x141>
mov    -0x18(%rbp),%edi
call   1040 <putchar@plt>
jmp    11d7 <read_from_eeprom+0x77>
cmpl   $0x0,-0x14(%rbp)
je     12be <read_from_eeprom+0x15e>
lea    0xd6d(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    0x2d1b(%rip),%rax
mov    (%rax),%edi
call   1070 <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,%r14d
mov    %edx,%ebp
mov    %esi,%ebx
mov    %rdi,%r15
call   1090 <eeprom_read_byte@plt>
mov    %eax,%r12d
mov    %eax,%edi
shr    $0x1f,%edi
lea    0xe67(%rip),%rsi
mov    $0x7f,%edx
call   1030 <do_die_if@plt>
test   %r14d,%r14d
je     11c5 <read_from_eeprom+0x55>
lea    0xe5c(%rip),%rdi
mov    %ebx,%esi
mov    %r12d,%edx
xor    %eax,%eax
call   1060 <printf@plt>
add    $0xffffffff,%ebp
jne    11d6 <read_from_eeprom+0x66>
jmp    125d <read_from_eeprom+0xed>
mov    %r12d,%edi
call   1040 <putchar@plt>
add    $0xffffffff,%ebp
je     125d <read_from_eeprom+0xed>
mov    $0x1,%r12d
jmp    120a <read_from_eeprom+0x9a>
xchg   %ax,%ax
lea    0xe33(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1060 <printf@plt>
add    $0x1,%r12d
lea    0xe19(%rip),%rdi
mov    %r13d,%esi
xor    %eax,%eax
call   1060 <printf@plt>
add    $0xffffffff,%ebp
je     125d <read_from_eeprom+0xed>
mov    %r15,%rdi
call   1070 <eeprom_read_current_byte@plt>
mov    %eax,%r13d
mov    %eax,%edi
shr    $0x1f,%edi
lea    0xddf(%rip),%rsi
mov    $0x87,%edx
call   1030 <do_die_if@plt>
test   %r14d,%r14d
je     1250 <read_from_eeprom+0xe0>
add    $0x1,%ebx
test   $0xf,%r12b
je     11e0 <read_from_eeprom+0x70>
test   $0x7,%r12b
jne    11f0 <read_from_eeprom+0x80>
lea    0xddb(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
jmp    11f0 <read_from_eeprom+0x80>
nop
mov    %r13d,%edi
call   1040 <putchar@plt>
add    $0xffffffff,%ebp
jne    120a <read_from_eeprom+0x9a>
test   %r14d,%r14d
je     126e <read_from_eeprom+0xfe>
lea    0xdbb(%rip),%rdi
call   1050 <puts@plt>
mov    0x2d6b(%rip),%rax
mov    (%rax),%edi
call   1080 <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 = [15 x i8] c"\0A %.4x| %.2x \00"
@.str.2 = [10 x i8] c"\0A %.4x| \00"
@.str.3 = [3 x i8] c" \00"
@.str.4 = [6 x i8] c"%.2x \00"
@.str.5 = [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
br label %11
11: ; preds = %4
%12 = load %struct.eeprom*, %struct.eeprom** %5
%13 = load i32, i32* %6
%14 = call i32 @eeprom_read_byte(%struct.eeprom* %12, i32 %13)
store i32 %14, i32* %9
%15 = icmp slt i32 %14, 0
%16 = zext i1 %15 to i32
%17 = call i32 @do_die_if(i32 %16, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 127)
br label %18
18: ; preds = %11
store i32 1, i32* %10
%19 = load i32, i32* %8
%20 = icmp ne i32 %19, 0
br i1 %20, label %21, label %25
21: ; preds = %18
%22 = load i32, i32* %6
%23 = load i32, i32* %9
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i32 %22, i32 %23)
br label %28
25: ; preds = %18
%26 = load i32, i32* %9
%27 = call i32 @putchar(i32 %26)
br label %28
28: ; preds = %25, %21
br label %29
29: ; preds = %67, %28
%30 = load i32, i32* %7
%31 = add nsw i32 %30, -1
store i32 %31, i32* %7
%32 = icmp ne i32 %31, 0
br i1 %32, label %33, label %68
33: ; preds = %29
br label %34
34: ; preds = %33
%35 = load %struct.eeprom*, %struct.eeprom** %5
%36 = call i32 @eeprom_read_current_byte(%struct.eeprom* %35)
store i32 %36, i32* %9
%37 = icmp slt i32 %36, 0
%38 = zext i1 %37 to i32
%39 = call i32 @do_die_if(i32 %38, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 135)
br label %40
40: ; preds = %34
%41 = load i32, i32* %8
%42 = icmp ne i32 %41, 0
br i1 %42, label %43, label %64
43: ; preds = %40
%44 = load i32, i32* %6
%45 = add nsw i32 %44, 1
store i32 %45, i32* %6
%46 = load i32, i32* %10
%47 = srem i32 %46, 16
%48 = icmp eq i32 %47, 0
br i1 %48, label %49, label %52
49: ; preds = %43
%50 = load i32, i32* %6
%51 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i32 %50)
br label %59
52: ; preds = %43
%53 = load i32, i32* %10
%54 = srem i32 %53, 8
%55 = icmp eq i32 %54, 0
br i1 %55, label %56, label %58
56: ; preds = %52
%57 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
br label %58
58: ; preds = %56, %52
br label %59
59: ; preds = %58, %49
%60 = load i32, i32* %10
%61 = add nsw i32 %60, 1
store i32 %61, i32* %10
%62 = load i32, i32* %9
%63 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i32 %62)
br label %67
64: ; preds = %40
%65 = load i32, i32* %9
%66 = call i32 @putchar(i32 %65)
br label %67
67: ; preds = %64, %59
br label %29
68: ; preds = %29
%69 = load i32, i32* %8
%70 = icmp ne i32 %69, 0
br i1 %70, label %71, label %73
71: ; preds = %68
%72 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
br label %73
73: ; preds = %71, %68
%74 = load i32, i32* @stdout
%75 = call i32 @fflush(i32 %74)
ret i32 0
}

LLVM IR (-O2):
%struct.eeprom = type { i32 }
@.str = [11 x i8] c"read error\00"
@.str.1 = [15 x i8] c"\0A %.4x| %.2x \00"
@.str.2 = [10 x i8] c"\0A %.4x| \00"
@.str.3 = [3 x i8] c" \00"
@.str.4 = [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 = tail call i32 @eeprom_read_byte(%struct.eeprom* %0, i32 %1)
%6 = lshr i32 %5, 31
%7 = tail call i32 @do_die_if(i32 %6, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 127)
%8 = icmp eq i32 %3, 0
br i1 %8, label %11, label %9
9: ; preds = %4
%10 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i32 %1, i32 %5)
br label %13
11: ; preds = %4
%12 = tail call i32 @putchar(i32 %5)
br label %13
13: ; preds = %11, %9
%14 = add nsw i32 %2, -1
%15 = icmp eq i32 %14, 0
br i1 %15, label %44, label %16
16: ; preds = %13, %39
%17 = phi i32 [ %42, %39 ], [ %14, %13 ]
%18 = phi i32 [ %41, %39 ], [ 1, %13 ]
%19 = phi i32 [ %40, %39 ], [ %1, %13 ]
%20 = tail call i32 @eeprom_read_current_byte(%struct.eeprom* %0)
%21 = lshr i32 %20, 31
%22 = tail call i32 @do_die_if(i32 %21, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 135)
br i1 %8, label %37, label %23
23: ; preds = %16
%24 = add nsw i32 %19, 1
%25 = and i32 %18, 15
%26 = icmp eq i32 %25, 0
br i1 %26, label %27, label %29
27: ; preds = %23
%28 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i32 %24)
br label %34
29: ; preds = %23
%30 = and i32 %18, 7
%31 = icmp eq i32 %30, 0
br i1 %31, label %32, label %34
32: ; preds = %29
%33 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
br label %34
34: ; preds = %29, %32, %27
%35 = add nsw i32 %18, 1
%36 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i32 %20)
br label %39
37: ; preds = %16
%38 = tail call i32 @putchar(i32 %20)
br label %39
39: ; preds = %37, %34
%40 = phi i32 [ %24, %34 ], [ %19, %37 ]
%41 = phi i32 [ %35, %34 ], [ %18, %37 ]
%42 = add nsw i32 %17, -1
%43 = icmp eq i32 %42, 0
br i1 %43, label %44, label %16
44: ; preds = %39, %13
br i1 %8, label %47, label %45
45: ; preds = %44
%46 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([2 x i8], [2 x i8]* @str, i64 0, i64 0))
br label %47
47: ; preds = %45, %44
%48 = load i32, i32* @stdout
%49 = tail call i32 @fflush(i32 %48)
ret i32 0
}