#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 EOF;
int /*<<< orphan*/ SEEK_END;
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, long, long);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, long, int /*<<< orphan*/);
long ftell(int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ putchar(int);
int /*<<< orphan*/ rewind(int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdout;
int /*<<< orphan*/ usleep(int);
int main() {
  int c;
  long j = 0;
  long k;
  FILE *file;
  file = fopen("EEPROM", "r");
  if (file != NULL) {
    usleep(5000000);
    fseek(file, 0L, SEEK_END);
    k = ftell(file);
    rewind(file);
    while ((c = fgetc(file)) != EOF) {
      fprintf(stderr, "Bytes written: %d/%d\r", j, k);
      fflush(stderr);
      putchar(c);
      fflush(stdout);
      usleep(50000);
      j++;
    }
  } else
    printf("Could not find or open file!\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movq   $0x0,-0x10(%rbp)
lea    0xe42(%rip),%rdi
lea    0xe42(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     128b <main+0xeb>
mov    $0x4c4b40,%edi
call   10c0 <usleep@plt>
mov    -0x20(%rbp),%rdi
mov    0x2dfa(%rip),%rax
mov    (%rax),%edx
xor    %eax,%eax
mov    %eax,%esi
call   10a0 <fseek@plt>
mov    -0x20(%rbp),%rdi
call   1080 <ftell@plt>
mov    %rax,-0x18(%rbp)
mov    -0x20(%rbp),%rdi
call   1050 <rewind@plt>
mov    -0x20(%rbp),%rdi
call   1060 <fgetc@plt>
mov    %eax,-0x8(%rbp)
mov    0x2dbe(%rip),%rcx
cmp    (%rcx),%eax
je     1286 <main+0xe6>
mov    0x2d9f(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
mov    -0x18(%rbp),%rcx
lea    0xdc7(%rip),%rsi
call   1070 <fprintf@plt>
mov    0x2d82(%rip),%rax
mov    (%rax),%edi
call   1090 <fflush@plt>
mov    -0x8(%rbp),%edi
call   1030 <putchar@plt>
mov    0x2d64(%rip),%rax
mov    (%rax),%edi
call   1090 <fflush@plt>
mov    $0xc350,%edi
call   10c0 <usleep@plt>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    120f <main+0x6f>
jmp    1297 <main+0xf7>
lea    0xd8d(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
lea    0xe4e(%rip),%rdi
lea    0xe4e(%rip),%rsi
call   10b0 <fopen@plt>
test   %rax,%rax
je     1274 <main+0xd4>
mov    %rax,%r15
mov    $0x4c4b40,%edi
call   10c0 <usleep@plt>
mov    0x2e0d(%rip),%rax
mov    (%rax),%edx
mov    %r15,%rdi
xor    %esi,%esi
call   10a0 <fseek@plt>
mov    %r15,%rdi
call   1080 <ftell@plt>
mov    %rax,%r14
mov    %r15,%rdi
call   1050 <rewind@plt>
mov    %r15,%rdi
call   1060 <fgetc@plt>
mov    0x2dd7(%rip),%r12
cmp    (%r12),%eax
je     1280 <main+0xe0>
mov    %eax,%ebp
xor    %ebx,%ebx
mov    0x2db6(%rip),%r13
nopw   0x0(%rax,%rax,1)
mov    0x0(%r13),%edi
lea    0xdde(%rip),%rsi
mov    %rbx,%rdx
mov    %r14,%rcx
call   1070 <fprintf@plt>
mov    0x0(%r13),%edi
call   1090 <fflush@plt>
mov    %ebp,%edi
call   1030 <putchar@plt>
mov    0x2d7b(%rip),%rax
mov    (%rax),%edi
call   1090 <fflush@plt>
mov    $0xc350,%edi
call   10c0 <usleep@plt>
add    $0x1,%rbx
mov    %r15,%rdi
call   1060 <fgetc@plt>
mov    %eax,%ebp
cmp    (%r12),%eax
jne    1220 <main+0x80>
jmp    1280 <main+0xe0>
lea    0xda4(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [7 x i8] c"EEPROM\00"
@.str.1 = [2 x i8] c"r\00"
@SEEK_END = global i32 0
@EOF = global i32 0
@stderr = global i32 0
@.str.2 = [22 x i8] c"Bytes written: %d/%d\0D\00"
@stdout = global i32 0
@.str.3 = [30 x i8] c"Could not find or open file!\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i64
%4 = alloca i64
%5 = alloca i32*
store i32 0, i32* %1
store i64 0, i64* %3
%6 = call i32* @fopen(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %6, i32** %5
%7 = load i32*, i32** %5
%8 = icmp ne i32* %7, null
br i1 %8, label %9, label %38
9: ; preds = %0
%10 = call i32 @usleep(i32 5000000)
%11 = load i32*, i32** %5
%12 = load i32, i32* @SEEK_END
%13 = call i32 @fseek(i32* %11, i64 0, i32 %12)
%14 = load i32*, i32** %5
%15 = call i64 @ftell(i32* %14)
store i64 %15, i64* %4
%16 = load i32*, i32** %5
%17 = call i32 @rewind(i32* %16)
br label %18
18: ; preds = %23, %9
%19 = load i32*, i32** %5
%20 = call i32 @fgetc(i32* %19)
store i32 %20, i32* %2
%21 = load i32, i32* @EOF
%22 = icmp ne i32 %20, %21
br i1 %22, label %23, label %37
23: ; preds = %18
%24 = load i32, i32* @stderr
%25 = load i64, i64* %3
%26 = load i64, i64* %4
%27 = call i32 @fprintf(i32 %24, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0), i64 %25, i64 %26)
%28 = load i32, i32* @stderr
%29 = call i32 @fflush(i32 %28)
%30 = load i32, i32* %2
%31 = call i32 @putchar(i32 %30)
%32 = load i32, i32* @stdout
%33 = call i32 @fflush(i32 %32)
%34 = call i32 @usleep(i32 50000)
%35 = load i64, i64* %3
%36 = add nsw i64 %35, 1
store i64 %36, i64* %3
br label %18
37: ; preds = %18
br label %40
38: ; preds = %0
%39 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.3, i64 0, i64 0))
br label %40
40: ; preds = %38, %37
ret i32 0
}

LLVM IR (-O2):
@.str = [7 x i8] c"EEPROM\00"
@.str.1 = [2 x i8] c"r\00"
@SEEK_END = global i32 0
@EOF = global i32 0
@stderr = global i32 0
@.str.2 = [22 x i8] c"Bytes written: %d/%d\0D\00"
@stdout = global i32 0
@str = [29 x i8] c"Could not find or open file!\00"
define i32 @main() {
%1 = tail call i32* @fopen(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%2 = icmp eq i32* %1, null
br i1 %2, label %27, label %3
3: ; preds = %0
%4 = tail call i32 @usleep(i32 5000000)
%5 = load i32, i32* @SEEK_END
%6 = tail call i32 @fseek(i32* %1, i64 0, i32 %5)
%7 = tail call i64 @ftell(i32* %1)
%8 = tail call i32 @rewind(i32* %1)
%9 = tail call i32 @fgetc(i32* %1)
%10 = load i32, i32* @EOF
%11 = icmp eq i32 %9, %10
br i1 %11, label %29, label %12
12: ; preds = %3, %12
%13 = phi i32 [ %24, %12 ], [ %9, %3 ]
%14 = phi i64 [ %23, %12 ], [ 0, %3 ]
%15 = load i32, i32* @stderr
%16 = tail call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0), i64 %14, i64 %7)
%17 = load i32, i32* @stderr
%18 = tail call i32 @fflush(i32 %17)
%19 = tail call i32 @putchar(i32 %13)
%20 = load i32, i32* @stdout
%21 = tail call i32 @fflush(i32 %20)
%22 = tail call i32 @usleep(i32 50000)
%23 = add nuw nsw i64 %14, 1
%24 = tail call i32 @fgetc(i32* %1)
%25 = load i32, i32* @EOF
%26 = icmp eq i32 %24, %25
br i1 %26, label %29, label %12
27: ; preds = %0
%28 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @str, i64 0, i64 0))
br label %29
29: ; preds = %12, %3, %27
ret i32 0
}