#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 */

/* Variables and functions */
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ putchar(char);
int reg_r(void *, int);
int /*<<< orphan*/ reg_w(void *, int, int);
void dump_eep(void *base) {
  int i;
  printf("Current eeprom:\n");
  for (i = 0; i < 32; i++) {
    while (reg_r(base, 0xB0) & 0x80000000)
      ;
    reg_w(base, 0xB0, 0 | 0x00000000 | i);
    reg_w(base, 0xB0, 0 | 0x80000000 | 0x00000000 | i);
    while (reg_r(base, 0xB0) & 0x80000000)
      ;
    printf("%02lx", reg_r(base, 0xB4));
    putchar((i & 7) == 7 ? '\n' : ' ');
  }
}


x86 assembly (clang, -O0):
<dump_eep>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
lea    0xead(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0xc(%rbp)
cmpl   $0x20,-0xc(%rbp)
jge    1227 <dump_eep+0xe7>
jmp    1170 <dump_eep+0x30>
mov    -0x8(%rbp),%rdi
mov    $0xb0,%esi
call   1060 <reg_r@plt>
and    $0x80000000,%eax
cmp    $0x0,%eax
je     1191 <dump_eep+0x51>
jmp    1170 <dump_eep+0x30>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%edx
or     $0x0,%edx
mov    $0xb0,%esi
call   1040 <reg_w@plt>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%edx
or     $0x80000000,%edx
mov    $0xb0,%esi
call   1040 <reg_w@plt>
mov    -0x8(%rbp),%rdi
mov    $0xb0,%esi
call   1060 <reg_r@plt>
and    $0x80000000,%eax
cmp    $0x0,%eax
je     11dd <dump_eep+0x9d>
jmp    11bc <dump_eep+0x7c>
mov    -0x8(%rbp),%rdi
mov    $0xb4,%esi
call   1060 <reg_r@plt>
mov    %eax,%esi
lea    0xe1d(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0xc(%rbp),%edx
and    $0x7,%edx
mov    $0x20,%eax
mov    $0xa,%ecx
cmp    $0x7,%edx
cmove  %ecx,%eax
movsbl %al,%edi
call   1030 <putchar@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1161 <dump_eep+0x21>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dump_eep>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
lea    0xea5(%rip),%rdi
call   1040 <puts@plt>
lea    0xe93(%rip),%r14
mov    $0xa,%r15d
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nop
mov    %rbx,%rdi
mov    $0xb0,%esi
call   1070 <reg_r@plt>
test   %eax,%eax
js     1180 <dump_eep+0x30>
mov    %rbx,%rdi
mov    $0xb0,%esi
mov    %ebp,%edx
call   1050 <reg_w@plt>
mov    %ebp,%edx
or     $0x80000000,%edx
mov    %rbx,%rdi
mov    $0xb0,%esi
call   1050 <reg_w@plt>
cs nopw 0x0(%rax,%rax,1)
nop
mov    %rbx,%rdi
mov    $0xb0,%esi
call   1070 <reg_r@plt>
test   %eax,%eax
js     11c0 <dump_eep+0x70>
mov    %rbx,%rdi
mov    $0xb4,%esi
call   1070 <reg_r@plt>
mov    %r14,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %ebp,%eax
not    %eax
test   $0x7,%al
mov    $0x20,%edi
cmove  %r15d,%edi
call   1030 <putchar@plt>
add    $0x1,%ebp
cmp    $0x20,%ebp
jne    1180 <dump_eep+0x30>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [17 x i8] c"Current eeprom:\0A\00"
@.str.1 = [6 x i8] c"%02lx\00"
define void @dump_eep(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
store i8* %0, i8** %2
%4 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %3
br label %5
5: ; preds = %41, %1
%6 = load i32, i32* %3
%7 = icmp slt i32 %6, 32
br i1 %7, label %8, label %44
8: ; preds = %5
br label %9
9: ; preds = %14, %8
%10 = load i8*, i8** %2
%11 = call i32 @reg_r(i8* %10, i32 176)
%12 = and i32 %11, -2147483648
%13 = icmp ne i32 %12, 0
br i1 %13, label %14, label %15
14: ; preds = %9
br label %9
15: ; preds = %9
%16 = load i8*, i8** %2
%17 = load i32, i32* %3
%18 = or i32 0, %17
%19 = call i32 @reg_w(i8* %16, i32 176, i32 %18)
%20 = load i8*, i8** %2
%21 = load i32, i32* %3
%22 = or i32 -2147483648, %21
%23 = call i32 @reg_w(i8* %20, i32 176, i32 %22)
br label %24
24: ; preds = %29, %15
%25 = load i8*, i8** %2
%26 = call i32 @reg_r(i8* %25, i32 176)
%27 = and i32 %26, -2147483648
%28 = icmp ne i32 %27, 0
br i1 %28, label %29, label %30
29: ; preds = %24
br label %24
30: ; preds = %24
%31 = load i8*, i8** %2
%32 = call i32 @reg_r(i8* %31, i32 180)
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %32)
%34 = load i32, i32* %3
%35 = and i32 %34, 7
%36 = icmp eq i32 %35, 7
%37 = zext i1 %36 to i64
%38 = select i1 %36, i32 10, i32 32
%39 = trunc i32 %38 to i8
%40 = call i32 @putchar(i8 signext %39)
br label %41
41: ; preds = %30
%42 = load i32, i32* %3
%43 = add nsw i32 %42, 1
store i32 %43, i32* %3
br label %5
44: ; preds = %5
ret void
}

LLVM IR (-O2):
@.str.1 = [6 x i8] c"%02lx\00"
@str = [16 x i8] c"Current eeprom:\00"
define void @dump_eep(i8* %0) {
%2 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str, i64 0, i64 0))
br label %3
3: ; preds = %1, %15
%4 = phi i32 [ 0, %1 ], [ %22, %15 ]
br label %5
5: ; preds = %3, %5
%6 = tail call i32 @reg_r(i8* %0, i32 176)
%7 = icmp sgt i32 %6, -1
br i1 %7, label %8, label %5
8: ; preds = %5
%9 = tail call i32 @reg_w(i8* %0, i32 176, i32 %4)
%10 = or i32 %4, -2147483648
%11 = tail call i32 @reg_w(i8* %0, i32 176, i32 %10)
br label %12
12: ; preds = %12, %8
%13 = tail call i32 @reg_r(i8* %0, i32 176)
%14 = icmp sgt i32 %13, -1
br i1 %14, label %15, label %12
15: ; preds = %12
%16 = tail call i32 @reg_r(i8* %0, i32 180)
%17 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %16)
%18 = and i32 %4, 7
%19 = icmp eq i32 %18, 7
%20 = select i1 %19, i8 10, i8 32
%21 = tail call i32 @putchar(i8 signext %20)
%22 = add nuw nsw i32 %4, 1
%23 = icmp eq i32 %22, 32
br i1 %23, label %24, label %3
24: ; preds = %15
ret void
}