#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 */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ *fopen(char *, char *);
int fread(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ putchar(char);
int /*<<< orphan*/ stdout;
int eeprom_dump(int addr, int size, int hex) {
  FILE *f;
  char ch;
  int i;
  f = fopen("/sys/bus/i2c/devices/i2c-1/1-0050/eeprom", "r+");
  if (f == NULL) {
    perror("eeprom fopen");
    return -1;
  }
  fseek(f, addr, SEEK_SET);
  for (i = 0; i < size; ++i, ++addr) {
    if (fread(&ch, 1, 1, f) != 1) {
      perror("eeprom fread");
      fclose(f);
      return -1;
    }
    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);
  fclose(f);
  return 0;
}


x86 assembly (clang, -O0):
<eeprom_dump>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
lea    0xe68(%rip),%rdi
lea    0xe8a(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11cb <eeprom_dump+0x4b>
lea    0xe72(%rip),%rdi
call   10a0 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12fe <eeprom_dump+0x17e>
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%esi
mov    0x2e07(%rip),%rax
mov    (%rax),%edx
call   1080 <fseek@plt>
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    12c8 <eeprom_dump+0x148>
mov    -0x18(%rbp),%rcx
lea    -0x19(%rbp),%rdi
mov    $0x1,%edx
mov    %edx,%esi
call   1040 <fread@plt>
cmp    $0x1,%eax
je     1231 <eeprom_dump+0xb1>
lea    0xe22(%rip),%rdi
call   10a0 <perror@plt>
mov    -0x18(%rbp),%rdi
call   1050 <fclose@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12fe <eeprom_dump+0x17e>
cmpl   $0x0,-0x10(%rbp)
je     12a3 <eeprom_dump+0x123>
mov    -0x20(%rbp),%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    1265 <eeprom_dump+0xe5>
mov    -0x8(%rbp),%esi
lea    0xded(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    128c <eeprom_dump+0x10c>
mov    -0x20(%rbp),%eax
mov    $0x8,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    1287 <eeprom_dump+0x107>
lea    0xdcd(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    128c <eeprom_dump+0x10c>
movsbl -0x19(%rbp),%esi
lea    0xdb9(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    12ac <eeprom_dump+0x12c>
movsbl -0x19(%rbp),%edi
call   1030 <putchar@plt>
jmp    12b1 <eeprom_dump+0x131>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    11e7 <eeprom_dump+0x67>
cmpl   $0x0,-0x10(%rbp)
je     12e0 <eeprom_dump+0x160>
lea    0xd7d(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    0x2cf1(%rip),%rax
mov    (%rax),%edi
call   1070 <fflush@plt>
mov    -0x18(%rbp),%rdi
call   1050 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<eeprom_dump>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %edx,%ebp
mov    %esi,%ebx
mov    %edi,%r15d
lea    0xe54(%rip),%rdi
lea    0xe76(%rip),%rsi
call   10a0 <fopen@plt>
test   %rax,%rax
je     12b3 <eeprom_dump+0x123>
mov    %rax,%r14
mov    0x2e15(%rip),%rax
mov    (%rax),%edx
mov    %r14,%rdi
mov    %r15,0x10(%rsp)
mov    %r15d,%esi
call   1090 <fseek@plt>
test   %ebx,%ebx
jle    127c <eeprom_dump+0xec>
lea    0xf(%rsp),%r12
lea    0xe5f(%rip),%r13
xor    %r15d,%r15d
jmp    122f <eeprom_dump+0x9f>
cs nopw 0x0(%rax,%rax,1)
mov    0x10(%rsp),%rax
lea    (%rax,%r15,1),%esi
lea    0xe36(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
movsbl 0xf(%rsp),%esi
mov    %r13,%rdi
xor    %eax,%eax
call   1070 <printf@plt>
add    $0x1,%r15d
cmp    %r15d,%ebx
je     127c <eeprom_dump+0xec>
mov    %r12,%rdi
mov    $0x1,%esi
mov    $0x1,%edx
mov    %r14,%rcx
call   1050 <fread@plt>
cmp    $0x1,%eax
jne    12c6 <eeprom_dump+0x136>
test   %ebp,%ebp
je     1270 <eeprom_dump+0xe0>
test   $0xf,%r15b
je     1200 <eeprom_dump+0x70>
test   $0x7,%r15b
jne    1217 <eeprom_dump+0x87>
lea    0xded(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
jmp    1217 <eeprom_dump+0x87>
nopl   0x0(%rax)
movsbl 0xf(%rsp),%edi
call   1030 <putchar@plt>
jmp    1226 <eeprom_dump+0x96>
test   %ebp,%ebp
je     128c <eeprom_dump+0xfc>
lea    0xdcf(%rip),%rdi
call   1040 <puts@plt>
mov    0x2d45(%rip),%rax
mov    (%rax),%edi
call   1080 <fflush@plt>
mov    %r14,%rdi
call   1060 <fclose@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd72(%rip),%rdi
call   10b0 <perror@plt>
mov    $0xffffffff,%eax
jmp    12a4 <eeprom_dump+0x114>
lea    0xd6c(%rip),%rdi
call   10b0 <perror@plt>
mov    %r14,%rdi
call   1060 <fclose@plt>
mov    $0xffffffff,%eax
jmp    12a4 <eeprom_dump+0x114>

LLVM IR (-O0):
@.str = [41 x i8] c"/sys/bus/i2c/devices/i2c-1/1-0050/eeprom\00"
@.str.1 = [3 x i8] c"r+\00"
@.str.2 = [13 x i8] c"eeprom fopen\00"
@SEEK_SET = global i32 0
@.str.3 = [13 x i8] c"eeprom fread\00"
@.str.4 = [10 x i8] c"\0A %.4x| \00"
@.str.5 = [3 x i8] c" \00"
@.str.6 = [6 x i8] c"%.2x \00"
@.str.7 = [3 x i8] c"\0A\0A\00"
@stdout = global i32 0
define i32 @eeprom_dump(i32 %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32*
%9 = alloca i8
%10 = alloca i32
store i32 %0, i32* %5
store i32 %1, i32* %6
store i32 %2, i32* %7
%11 = call i32* @fopen(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %11, i32** %8
%12 = load i32*, i32** %8
%13 = icmp eq i32* %12, null
br i1 %13, label %14, label %16
14: ; preds = %3
%15 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %4
br label %73
16: ; preds = %3
%17 = load i32*, i32** %8
%18 = load i32, i32* %5
%19 = load i32, i32* @SEEK_SET
%20 = call i32 @fseek(i32* %17, i32 %18, i32 %19)
store i32 0, i32* %10
br label %21
21: ; preds = %58, %16
%22 = load i32, i32* %10
%23 = load i32, i32* %6
%24 = icmp slt i32 %22, %23
br i1 %24, label %25, label %63
25: ; preds = %21
%26 = load i32*, i32** %8
%27 = call i32 @fread(i8* %9, i32 1, i32 1, i32* %26)
%28 = icmp ne i32 %27, 1
br i1 %28, label %29, label %33
29: ; preds = %25
%30 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0))
%31 = load i32*, i32** %8
%32 = call i32 @fclose(i32* %31)
store i32 -1, i32* %4
br label %73
33: ; preds = %25
%34 = load i32, i32* %7
%35 = icmp ne i32 %34, 0
br i1 %35, label %36, label %54
36: ; preds = %33
%37 = load i32, i32* %10
%38 = srem i32 %37, 16
%39 = icmp eq i32 %38, 0
br i1 %39, label %40, label %43
40: ; preds = %36
%41 = load i32, i32* %5
%42 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0), i32 %41)
br label %50
43: ; preds = %36
%44 = load i32, i32* %10
%45 = srem i32 %44, 8
%46 = icmp eq i32 %45, 0
br i1 %46, label %47, label %49
47: ; preds = %43
%48 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
br label %49
49: ; preds = %47, %43
br label %50
50: ; preds = %49, %40
%51 = load i8, i8* %9
%52 = sext i8 %51 to i32
%53 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0), i32 %52)
br label %57
54: ; preds = %33
%55 = load i8, i8* %9
%56 = call i32 @putchar(i8 signext %55)
br label %57
57: ; preds = %54, %50
br label %58
58: ; preds = %57
%59 = load i32, i32* %10
%60 = add nsw i32 %59, 1
store i32 %60, i32* %10
%61 = load i32, i32* %5
%62 = add nsw i32 %61, 1
store i32 %62, i32* %5
br label %21
63: ; preds = %21
%64 = load i32, i32* %7
%65 = icmp ne i32 %64, 0
br i1 %65, label %66, label %68
66: ; preds = %63
%67 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0))
br label %68
68: ; preds = %66, %63
%69 = load i32, i32* @stdout
%70 = call i32 @fflush(i32 %69)
%71 = load i32*, i32** %8
%72 = call i32 @fclose(i32* %71)
store i32 0, i32* %4
br label %73
73: ; preds = %68, %29, %14
%74 = load i32, i32* %4
ret i32 %74
}

LLVM IR (-O2):
@.str = [41 x i8] c"/sys/bus/i2c/devices/i2c-1/1-0050/eeprom\00"
@.str.1 = [3 x i8] c"r+\00"
@.str.2 = [13 x i8] c"eeprom fopen\00"
@SEEK_SET = global i32 0
@.str.3 = [13 x i8] c"eeprom fread\00"
@.str.4 = [10 x i8] c"\0A %.4x| \00"
@.str.5 = [3 x i8] c" \00"
@.str.6 = [6 x i8] c"%.2x \00"
@stdout = global i32 0
@str = [2 x i8] c"\0A\00"
define i32 @eeprom_dump(i32 %0, i32 %1, i32 %2) {
%4 = alloca i8
%5 = tail call i32* @fopen(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%6 = icmp eq i32* %5, null
br i1 %6, label %7, label %9
7: ; preds = %3
%8 = tail call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
br label %53
9: ; preds = %3
%10 = load i32, i32* @SEEK_SET
%11 = tail call i32 @fseek(i32* %5, i32 %0, i32 %10)
%12 = icmp sgt i32 %1, 0
br i1 %12, label %13, label %45
13: ; preds = %9
%14 = icmp eq i32 %2, 0
br label %15
15: ; preds = %13, %41
%16 = phi i32 [ 0, %13 ], [ %42, %41 ]
%17 = phi i32 [ %0, %13 ], [ %43, %41 ]
%18 = call i32 @fread(i8* %4, i32 1, i32 1, i32* %5)
%19 = icmp eq i32 %18, 1
br i1 %19, label %23, label %20
20: ; preds = %15
%21 = tail call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0))
%22 = tail call i32 @fclose(i32* %5)
br label %53
23: ; preds = %15
br i1 %14, label %38, label %24
24: ; preds = %23
%25 = and i32 %16, 15
%26 = icmp eq i32 %25, 0
br i1 %26, label %27, label %29
27: ; preds = %24
%28 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0), i32 %17)
br label %34
29: ; preds = %24
%30 = and i32 %16, 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.5, i64 0, i64 0))
br label %34
34: ; preds = %29, %32, %27
%35 = load i8, i8* %4
%36 = sext i8 %35 to i32
%37 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0), i32 %36)
br label %41
38: ; preds = %23
%39 = load i8, i8* %4
%40 = tail call i32 @putchar(i8 signext %39)
br label %41
41: ; preds = %34, %38
%42 = add nuw nsw i32 %16, 1
%43 = add nsw i32 %17, 1
%44 = icmp eq i32 %42, %1
br i1 %44, label %45, label %15
45: ; preds = %41, %9
%46 = icmp eq i32 %2, 0
br i1 %46, label %49, label %47
47: ; preds = %45
%48 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([2 x i8], [2 x i8]* @str, i64 0, i64 0))
br label %49
49: ; preds = %47, %45
%50 = load i32, i32* @stdout
%51 = tail call i32 @fflush(i32 %50)
%52 = tail call i32 @fclose(i32* %5)
br label %53
53: ; preds = %49, %20, %7
%54 = phi i32 [ -1, %7 ], [ -1, %20 ], [ 0, %49 ]
ret i32 %54
}