#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*/ eeprom_write_block(char *, char *, size_t);
size_t read(int, char *, int);
void readeedatafromfile(int fd) {
  char buf[8192], *eeprom = 0;
  size_t len;
  while ((len = read(fd, buf, sizeof buf)) > 0) {
    eeprom_write_block(buf, eeprom, len);
    eeprom += len;
  }
}


x86 assembly (clang, -O0):
<readeedatafromfile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x2020,%rsp
mov    %edi,-0x4(%rbp)
movq   $0x0,-0x2018(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x2010(%rbp),%rsi
mov    $0x2000,%edx
call   1040 <read@plt>
mov    %rax,-0x2020(%rbp)
cmp    $0x0,%rax
jbe    1192 <readeedatafromfile+0x72>
lea    -0x2010(%rbp),%rdi
mov    -0x2018(%rbp),%rsi
mov    -0x2020(%rbp),%rdx
call   1030 <eeprom_write_block@plt>
mov    -0x2020(%rbp),%rax
add    -0x2018(%rbp),%rax
mov    %rax,-0x2018(%rbp)
jmp    1139 <readeedatafromfile+0x19>
add    $0x2020,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readeedatafromfile>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x2008,%rsp
mov    %edi,%r14d
mov    %rsp,%rsi
mov    $0x2000,%edx
call   1040 <read@plt>
test   %rax,%rax
je     1179 <readeedatafromfile+0x59>
mov    %rax,%rbp
xor    %ebx,%ebx
mov    %rsp,%r15
nopw   0x0(%rax,%rax,1)
mov    %r15,%rdi
mov    %rbx,%rsi
mov    %rbp,%rdx
call   1030 <eeprom_write_block@plt>
add    %rbp,%rbx
mov    %r14d,%edi
mov    %r15,%rsi
mov    $0x2000,%edx
call   1040 <read@plt>
mov    %rax,%rbp
test   %rax,%rax
jne    1150 <readeedatafromfile+0x30>
add    $0x2008,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @readeedatafromfile(i32 %0) {
%2 = alloca i32
%3 = alloca [8192 x i8]
%4 = alloca i8*
%5 = alloca i64
store i32 %0, i32* %2
store i8* null, i8** %4
br label %6
6: ; preds = %11, %1
%7 = load i32, i32* %2
%8 = getelementptr inbounds [8192 x i8], [8192 x i8]* %3, i64 0, i64 0
%9 = call i64 @read(i32 %7, i8* %8, i32 8192)
store i64 %9, i64* %5
%10 = icmp ugt i64 %9, 0
br i1 %10, label %11, label %19
11: ; preds = %6
%12 = getelementptr inbounds [8192 x i8], [8192 x i8]* %3, i64 0, i64 0
%13 = load i8*, i8** %4
%14 = load i64, i64* %5
%15 = call i32 @eeprom_write_block(i8* %12, i8* %13, i64 %14)
%16 = load i64, i64* %5
%17 = load i8*, i8** %4
%18 = getelementptr inbounds i8, i8* %17, i64 %16
store i8* %18, i8** %4
br label %6
19: ; preds = %6
ret void
}

LLVM IR (-O2):
define void @readeedatafromfile(i32 %0) {
%2 = alloca [8192 x i8]
%3 = getelementptr inbounds [8192 x i8], [8192 x i8]* %2, i64 0, i64 0
%4 = call i64 @read(i32 %0, i8* %3, i32 8192)
%5 = icmp eq i64 %4, 0
br i1 %5, label %13, label %6
6: ; preds = %1, %6
%7 = phi i64 [ %11, %6 ], [ %4, %1 ]
%8 = phi i8* [ %10, %6 ], [ null, %1 ]
%9 = call i32 @eeprom_write_block(i8* %3, i8* %8, i64 %7)
%10 = getelementptr inbounds i8, i8* %8, i64 %7
%11 = call i64 @read(i32 %0, i8* %3, i32 8192)
%12 = icmp eq i64 %11, 0
br i1 %12, label %13, label %6
13: ; preds = %6, %1
ret void
}