#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*/ O_RDWR;
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ lseek(int, int /*<<< orphan*/, int /*<<< orphan*/);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char *);
int read(int, char *, int);
int /*<<< orphan*/ write(int, char *, int);
void eeprom_test(void) {
  int fd, ret;
  char buffer[256] = {0};
  fd = open("/sys/class/i2c-adapter/i2c-0/0-0050/eeprom", O_RDWR);
  if (fd < 0) {
    perror("");
    return;
  }
  write(fd, "HelloWorld\n", 11);
  lseek(fd, 0, SEEK_SET);
  ret = read(fd, buffer, 11);
  buffer[ret] = 0;
  printf("%s", buffer);
  close(fd);
}


x86 assembly (clang, -O0):
<eeprom_test>:
push   %rbp
mov    %rsp,%rbp
sub    $0x110,%rsp
lea    -0x110(%rbp),%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1060 <memset@plt>
mov    0x2e43(%rip),%rax
mov    (%rax),%esi
lea    0xe52(%rip),%rdi
call   1090 <open@plt>
mov    %eax,-0x4(%rbp)
cmpl   $0x0,-0x4(%rbp)
jge    11d1 <eeprom_test+0x51>
lea    0xe6f(%rip),%rdi
call   10a0 <perror@plt>
jmp    1236 <eeprom_test+0xb6>
mov    -0x4(%rbp),%edi
lea    0xe50(%rip),%rsi
mov    $0xb,%edx
call   1030 <write@plt>
mov    -0x4(%rbp),%edi
mov    0x2de9(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1050 <lseek@plt>
mov    -0x4(%rbp),%edi
lea    -0x110(%rbp),%rsi
mov    $0xb,%edx
call   1080 <read@plt>
mov    %eax,-0x8(%rbp)
movslq -0x8(%rbp),%rax
movb   $0x0,-0x110(%rbp,%rax,1)
lea    -0x110(%rbp),%rsi
lea    0xe0e(%rip),%rdi
call   1040 <printf@plt>
mov    -0x4(%rbp),%edi
call   1070 <close@plt>
add    $0x110,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<eeprom_test>:
push   %r14
push   %rbx
sub    $0x108,%rsp
xorps  %xmm0,%xmm0
movaps %xmm0,0xf0(%rsp)
movaps %xmm0,0xe0(%rsp)
movaps %xmm0,0xd0(%rsp)
movaps %xmm0,0xc0(%rsp)
movaps %xmm0,0xb0(%rsp)
movaps %xmm0,0xa0(%rsp)
movaps %xmm0,0x90(%rsp)
movaps %xmm0,0x80(%rsp)
movaps %xmm0,0x70(%rsp)
movaps %xmm0,0x60(%rsp)
movaps %xmm0,0x50(%rsp)
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x10(%rsp)
movaps %xmm0,(%rsp)
mov    0x2dfd(%rip),%rax
mov    (%rax),%esi
lea    0xe0c(%rip),%rdi
call   1080 <open@plt>
test   %eax,%eax
js     125d <eeprom_test+0xed>
mov    %eax,%ebx
lea    0xe25(%rip),%rsi
mov    %eax,%edi
mov    $0xb,%edx
call   1030 <write@plt>
mov    0x2dbf(%rip),%rax
mov    (%rax),%edx
mov    %ebx,%edi
xor    %esi,%esi
call   1050 <lseek@plt>
mov    %rsp,%r14
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0xb,%edx
call   1070 <read@plt>
cltq
movb   $0x0,(%rsp,%rax,1)
lea    0xdf4(%rip),%rdi
mov    %r14,%rsi
call   1040 <printf@plt>
mov    %ebx,%edi
call   1060 <close@plt>
add    $0x108,%rsp
pop    %rbx
pop    %r14
ret
lea    0xdd2(%rip),%rdi
add    $0x108,%rsp
pop    %rbx
pop    %r14
jmp    1090 <perror@plt>

LLVM IR (-O0):
@.str = [43 x i8] c"/sys/class/i2c-adapter/i2c-0/0-0050/eeprom\00"
@O_RDWR = global i32 0
@.str.1 = [1 x i8] zeroinitializer
@.str.2 = [12 x i8] c"HelloWorld\0A\00"
@SEEK_SET = global i32 0
@.str.3 = [3 x i8] c"%s\00"
define void @eeprom_test() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [256 x i8]
%4 = bitcast [256 x i8]* %3 to i8*
%5 = load i32, i32* @O_RDWR
%6 = call i32 @open(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0), i32 %5)
store i32 %6, i32* %1
%7 = load i32, i32* %1
%8 = icmp slt i32 %7, 0
br i1 %8, label %9, label %11
9: ; preds = %0
%10 = call i32 @perror(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0))
br label %27
11: ; preds = %0
%12 = load i32, i32* %1
%13 = call i32 @write(i32 %12, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i32 11)
%14 = load i32, i32* %1
%15 = load i32, i32* @SEEK_SET
%16 = call i32 @lseek(i32 %14, i32 0, i32 %15)
%17 = load i32, i32* %1
%18 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%19 = call i32 @read(i32 %17, i8* %18, i32 11)
store i32 %19, i32* %2
%20 = load i32, i32* %2
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 %21
store i8 0, i8* %22
%23 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%24 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %23)
%25 = load i32, i32* %1
%26 = call i32 @close(i32 %25)
br label %27
27: ; preds = %11, %9
ret void
}

LLVM IR (-O2):
@.str = [43 x i8] c"/sys/class/i2c-adapter/i2c-0/0-0050/eeprom\00"
@O_RDWR = global i32 0
@.str.1 = [1 x i8] zeroinitializer
@.str.2 = [12 x i8] c"HelloWorld\0A\00"
@SEEK_SET = global i32 0
@.str.3 = [3 x i8] c"%s\00"
define void @eeprom_test() {
%1 = alloca [256 x i8]
%2 = getelementptr inbounds [256 x i8], [256 x i8]* %1, i64 0, i64 0
%3 = load i32, i32* @O_RDWR
%4 = tail call i32 @open(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0), i32 %3)
%5 = icmp slt i32 %4, 0
br i1 %5, label %6, label %8
6: ; preds = %0
%7 = tail call i32 @perror(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0))
br label %17
8: ; preds = %0
%9 = tail call i32 @write(i32 %4, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i32 11)
%10 = load i32, i32* @SEEK_SET
%11 = tail call i32 @lseek(i32 %4, i32 0, i32 %10)
%12 = call i32 @read(i32 %4, i8* %2, i32 11)
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds [256 x i8], [256 x i8]* %1, i64 0, i64 %13
store i8 0, i8* %14
%15 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %2)
%16 = call i32 @close(i32 %4)
br label %17
17: ; preds = %8, %6
ret void
}