#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 /*<<< orphan*/, char *, int);
int /*<<< orphan*/ eeprom_write_byte(struct eeprom *, int, int);
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdout;
int /*<<< orphan*/ usleep(int);
int write_to_eeprom(struct eeprom *e, int addr) {
  int i;
  for (i = 0, addr = 0; i < 256; i++, addr++) {
    if ((i % 16) == 0)
      printf("\n %.4x|  ", addr);
    else if ((i % 8) == 0)
      printf("  ");
    printf("%.2x ", i);
    fflush(stdout);
    do {
      do_die_if(eeprom_write_byte(e, addr, i), "write error", 80);
    } while (0);
    ;
    usleep(4000);
  }
  fprintf(stderr, "\n\n");
  return 0;
}


x86 assembly (clang, -O0):
<write_to_eeprom>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
movl   $0x0,-0xc(%rbp)
cmpl   $0x100,-0x10(%rbp)
jge    123d <write_to_eeprom+0xdd>
mov    -0x10(%rbp),%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    11b4 <write_to_eeprom+0x54>
mov    -0xc(%rbp),%esi
lea    0xe58(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    11db <write_to_eeprom+0x7b>
mov    -0x10(%rbp),%eax
mov    $0x8,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    11d6 <write_to_eeprom+0x76>
lea    0xe38(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    11db <write_to_eeprom+0x7b>
mov    -0x10(%rbp),%esi
lea    0xe25(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    0x2de5(%rip),%rax
mov    (%rax),%edi
call   1060 <fflush@plt>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
call   1070 <eeprom_write_byte@plt>
mov    %eax,%edi
lea    0xdfe(%rip),%rsi
mov    $0x50,%edx
call   1030 <do_die_if@plt>
mov    $0xfa0,%edi
call   1080 <usleep@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    117d <write_to_eeprom+0x1d>
mov    0x2d9c(%rip),%rax
mov    (%rax),%edi
lea    0xdcf(%rip),%rsi
call   1050 <fprintf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_to_eeprom>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%rbx
lea    0xe8b(%rip),%r14
lea    0xe8e(%rip),%r15
mov    0x2e55(%rip),%r13
lea    0xe86(%rip),%r12
xor    %ebp,%ebp
jmp    11e1 <write_to_eeprom+0x81>
xchg   %ax,%ax
mov    %r14,%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r15,%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x0(%r13),%edi
call   1060 <fflush@plt>
mov    %rbx,%rdi
mov    %ebp,%esi
mov    %ebp,%edx
call   1070 <eeprom_write_byte@plt>
mov    %eax,%edi
mov    %r12,%rsi
mov    $0x50,%edx
call   1030 <do_die_if@plt>
mov    $0xfa0,%edi
call   1080 <usleep@plt>
add    $0x1,%ebp
cmp    $0x100,%ebp
je     11fd <write_to_eeprom+0x9d>
test   $0xf,%bpl
je     1190 <write_to_eeprom+0x30>
test   $0x7,%bpl
jne    119c <write_to_eeprom+0x3c>
lea    0xe13(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    119c <write_to_eeprom+0x3c>
mov    0x2ddc(%rip),%rax
mov    (%rax),%edi
lea    0xe0f(%rip),%rsi
call   1050 <fprintf@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 = [10 x i8] c"\0A %.4x| \00"
@.str.1 = [3 x i8] c" \00"
@.str.2 = [6 x i8] c"%.2x \00"
@stdout = global i32 0
@.str.3 = [12 x i8] c"write error\00"
@stderr = global i32 0
@.str.4 = [3 x i8] c"\0A\0A\00"
define i32 @write_to_eeprom(%struct.eeprom* %0, i32 %1) {
%3 = alloca %struct.eeprom*
%4 = alloca i32
%5 = alloca i32
store %struct.eeprom* %0, %struct.eeprom** %3
store i32 %1, i32* %4
store i32 0, i32* %5
store i32 0, i32* %4
br label %6
6: ; preds = %36, %2
%7 = load i32, i32* %5
%8 = icmp slt i32 %7, 256
br i1 %8, label %9, label %41
9: ; preds = %6
%10 = load i32, i32* %5
%11 = srem i32 %10, 16
%12 = icmp eq i32 %11, 0
br i1 %12, label %13, label %16
13: ; preds = %9
%14 = load i32, i32* %4
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %14)
br label %23
16: ; preds = %9
%17 = load i32, i32* %5
%18 = srem i32 %17, 8
%19 = icmp eq i32 %18, 0
br i1 %19, label %20, label %22
20: ; preds = %16
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
br label %22
22: ; preds = %20, %16
br label %23
23: ; preds = %22, %13
%24 = load i32, i32* %5
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 %24)
%26 = load i32, i32* @stdout
%27 = call i32 @fflush(i32 %26)
br label %28
28: ; preds = %23
%29 = load %struct.eeprom*, %struct.eeprom** %3
%30 = load i32, i32* %4
%31 = load i32, i32* %5
%32 = call i32 @eeprom_write_byte(%struct.eeprom* %29, i32 %30, i32 %31)
%33 = call i32 @do_die_if(i32 %32, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i32 80)
br label %34
34: ; preds = %28
%35 = call i32 @usleep(i32 4000)
br label %36
36: ; preds = %34
%37 = load i32, i32* %5
%38 = add nsw i32 %37, 1
store i32 %38, i32* %5
%39 = load i32, i32* %4
%40 = add nsw i32 %39, 1
store i32 %40, i32* %4
br label %6
41: ; preds = %6
%42 = load i32, i32* @stderr
%43 = call i32 @fprintf(i32 %42, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
%struct.eeprom = type { i32 }
@.str = [10 x i8] c"\0A %.4x| \00"
@.str.1 = [3 x i8] c" \00"
@.str.2 = [6 x i8] c"%.2x \00"
@stdout = global i32 0
@.str.3 = [12 x i8] c"write error\00"
@stderr = global i32 0
@.str.4 = [3 x i8] c"\0A\0A\00"
define i32 @write_to_eeprom(%struct.eeprom* %0, i32 %1) {
br label %3
3: ; preds = %2, %14
%4 = phi i32 [ 0, %2 ], [ %21, %14 ]
%5 = and i32 %4, 15
%6 = icmp eq i32 %5, 0
br i1 %6, label %7, label %9
7: ; preds = %3
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %4)
br label %14
9: ; preds = %3
%10 = and i32 %4, 7
%11 = icmp eq i32 %10, 0
br i1 %11, label %12, label %14
12: ; preds = %9
%13 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
br label %14
14: ; preds = %9, %12, %7
%15 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 %4)
%16 = load i32, i32* @stdout
%17 = tail call i32 @fflush(i32 %16)
%18 = tail call i32 @eeprom_write_byte(%struct.eeprom* %0, i32 %4, i32 %4)
%19 = tail call i32 @do_die_if(i32 %18, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i32 80)
%20 = tail call i32 @usleep(i32 4000)
%21 = add nuw nsw i32 %4, 1
%22 = icmp eq i32 %21, 256
br i1 %22, label %23, label %3
23: ; preds = %14
%24 = load i32, i32* @stderr
%25 = tail call i32 @fprintf(i32 %24, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
ret i32 0
}