#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*/ *);
scalar_t__ 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;
  }
  if (fseek(f, addr, SEEK_SET) != 0) {
    perror("eeprom fseek");
    fclose(f);
    return -1;
  }
  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    1329 <eeprom_dump+0x1a9>
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%esi
mov    0x2e07(%rip),%rax
mov    (%rax),%edx
call   1080 <fseek@plt>
cmp    $0x0,%rax
je     120b <eeprom_dump+0x8b>
lea    0xe48(%rip),%rdi
call   10a0 <perror@plt>
mov    -0x18(%rbp),%rdi
call   1050 <fclose@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1329 <eeprom_dump+0x1a9>
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    12f3 <eeprom_dump+0x173>
mov    -0x18(%rbp),%rcx
lea    -0x19(%rbp),%rdi
mov    $0x1,%edx
mov    %edx,%esi
call   1040 <fread@plt>
cmp    $0x1,%eax
je     125c <eeprom_dump+0xdc>
lea    0xe04(%rip),%rdi
call   10a0 <perror@plt>
mov    -0x18(%rbp),%rdi
call   1050 <fclose@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1329 <eeprom_dump+0x1a9>
cmpl   $0x0,-0x10(%rbp)
je     12ce <eeprom_dump+0x14e>
mov    -0x20(%rbp),%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    1290 <eeprom_dump+0x110>
mov    -0x8(%rbp),%esi
lea    0xdcf(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    12b7 <eeprom_dump+0x137>
mov    -0x20(%rbp),%eax
mov    $0x8,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    12b2 <eeprom_dump+0x132>
lea    0xdaf(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    12b7 <eeprom_dump+0x137>
movsbl -0x19(%rbp),%esi
lea    0xd9b(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    12d7 <eeprom_dump+0x157>
movsbl -0x19(%rbp),%edi
call   1030 <putchar@plt>
jmp    12dc <eeprom_dump+0x15c>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1212 <eeprom_dump+0x92>
cmpl   $0x0,-0x10(%rbp)
je     130b <eeprom_dump+0x18b>
lea    0xd5f(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    0x2cc6(%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    %r15d,%esi
call   1090 <fseek@plt>
test   %rax,%rax
jne    12c6 <eeprom_dump+0x136>
mov    %r15,0x10(%rsp)
test   %ebx,%ebx
jle    127c <eeprom_dump+0xec>
lea    0xf(%rsp),%r12
lea    0xe63(%rip),%r13
xor    %r15d,%r15d
jmp    122f <eeprom_dump+0x9f>
nop
mov    0x10(%rsp),%rax
lea    (%rax,%r15,1),%esi
lea    0xe43(%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    12cf <eeprom_dump+0x13f>
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    0xdf6(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
jmp    1217 <eeprom_dump+0x87>
nopl   (%rax)
movsbl 0xf(%rsp),%edi
call   1030 <putchar@plt>
jmp    1226 <eeprom_dump+0x96>
test   %ebp,%ebp
je     128c <eeprom_dump+0xfc>
lea    0xddc(%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
jmp    12d6 <eeprom_dump+0x146>
lea    0xd70(%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 fseek\00"
@.str.4 = [13 x i8] c"eeprom fread\00"
@.str.5 = [10 x i8] c"\0A %.4x| \00"
@.str.6 = [3 x i8] c" \00"
@.str.7 = [6 x i8] c"%.2x \00"
@.str.8 = [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 %79
16: ; preds = %3
%17 = load i32*, i32** %8
%18 = load i32, i32* %5
%19 = load i32, i32* @SEEK_SET
%20 = call i64 @fseek(i32* %17, i32 %18, i32 %19)
%21 = icmp ne i64 %20, 0
br i1 %21, label %22, label %26
22: ; preds = %16
%23 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0))
%24 = load i32*, i32** %8
%25 = call i32 @fclose(i32* %24)
store i32 -1, i32* %4
br label %79
26: ; preds = %16
store i32 0, i32* %10
br label %27
27: ; preds = %64, %26
%28 = load i32, i32* %10
%29 = load i32, i32* %6
%30 = icmp slt i32 %28, %29
br i1 %30, label %31, label %69
31: ; preds = %27
%32 = load i32*, i32** %8
%33 = call i32 @fread(i8* %9, i32 1, i32 1, i32* %32)
%34 = icmp ne i32 %33, 1
br i1 %34, label %35, label %39
35: ; preds = %31
%36 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0))
%37 = load i32*, i32** %8
%38 = call i32 @fclose(i32* %37)
store i32 -1, i32* %4
br label %79
39: ; preds = %31
%40 = load i32, i32* %7
%41 = icmp ne i32 %40, 0
br i1 %41, label %42, label %60
42: ; preds = %39
%43 = load i32, i32* %10
%44 = srem i32 %43, 16
%45 = icmp eq i32 %44, 0
br i1 %45, label %46, label %49
46: ; preds = %42
%47 = load i32, i32* %5
%48 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.5, i64 0, i64 0), i32 %47)
br label %56
49: ; preds = %42
%50 = load i32, i32* %10
%51 = srem i32 %50, 8
%52 = icmp eq i32 %51, 0
br i1 %52, label %53, label %55
53: ; preds = %49
%54 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0))
br label %55
55: ; preds = %53, %49
br label %56
56: ; preds = %55, %46
%57 = load i8, i8* %9
%58 = sext i8 %57 to i32
%59 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.7, i64 0, i64 0), i32 %58)
br label %63
60: ; preds = %39
%61 = load i8, i8* %9
%62 = call i32 @putchar(i8 signext %61)
br label %63
63: ; preds = %60, %56
br label %64
64: ; preds = %63
%65 = load i32, i32* %10
%66 = add nsw i32 %65, 1
store i32 %66, i32* %10
%67 = load i32, i32* %5
%68 = add nsw i32 %67, 1
store i32 %68, i32* %5
br label %27
69: ; preds = %27
%70 = load i32, i32* %7
%71 = icmp ne i32 %70, 0
br i1 %71, label %72, label %74
72: ; preds = %69
%73 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.8, i64 0, i64 0))
br label %74
74: ; preds = %72, %69
%75 = load i32, i32* @stdout
%76 = call i32 @fflush(i32 %75)
%77 = load i32*, i32** %8
%78 = call i32 @fclose(i32* %77)
store i32 0, i32* %4
br label %79
79: ; preds = %74, %35, %22, %14
%80 = load i32, i32* %4
ret i32 %80
}

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