#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*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ memset(unsigned char *, int /*<<< orphan*/, int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int read(int, unsigned char *, int);
int write(int, unsigned char *, int);
int main(int argc, char *argv[]) {
  int ret = 0;
  int count = 0;
  int index = 0;
  unsigned char nvram[5] = "";
  int fd = open("/sys/class/i2c-dev/i2c-3/device/3-0068/nvram", O_RDWR);
  if (fd < 0) {
    printf("Error opening NVRAM file\n");
    exit(0);
  } else {
    ret = read(fd, nvram, 5);
    printf("NVRAM read: %d\n", ret);
    printf("NVRAM: ", ret);
    for (index = 0; index < 5; index++)
      printf("%d ", nvram[index]);
    printf("\n");
    for (index = 0; index < 5; index++)
      nvram[index] = index;
    ret = write(fd, nvram, 5);
    printf("NVRAM write: %d\n", ret);
    printf("NVRAM: ");
    memset(nvram, 0, 5);
    ret = read(fd, nvram, 5);
    printf("NVRAM read: %d\n", ret);
    for (index = 0; index < 5; index++)
      printf("%d ", nvram[index]);
    printf("\n");
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
lea    -0x21(%rbp),%rdi
xor    %esi,%esi
mov    $0x5,%edx
call   1050 <memset@plt>
mov    0x2e46(%rip),%rax
mov    (%rax),%esi
lea    0xe55(%rip),%rdi
call   1070 <open@plt>
mov    %eax,-0x28(%rbp)
cmpl   $0x0,-0x28(%rbp)
jge    11d2 <main+0x72>
lea    0xe69(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %edi,%edi
call   1080 <exit@plt>
mov    -0x28(%rbp),%edi
lea    -0x21(%rbp),%rsi
mov    $0x5,%edx
call   1060 <read@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%esi
lea    0xe57(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x14(%rbp),%esi
lea    0xe56(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x1c(%rbp)
cmpl   $0x5,-0x1c(%rbp)
jge    123e <main+0xde>
movslq -0x1c(%rbp),%rax
movzbl -0x21(%rbp,%rax,1),%esi
lea    0xe36(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    120f <main+0xaf>
lea    0xe10(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x1c(%rbp)
cmpl   $0x5,-0x1c(%rbp)
jge    1278 <main+0x118>
mov    -0x1c(%rbp),%eax
mov    %al,%cl
movslq -0x1c(%rbp),%rax
mov    %cl,-0x21(%rbp,%rax,1)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1253 <main+0xf3>
mov    -0x28(%rbp),%edi
lea    -0x21(%rbp),%rsi
mov    $0x5,%edx
call   1030 <write@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%esi
lea    0xdcd(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xdb3(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x21(%rbp),%rdi
xor    %esi,%esi
mov    $0x5,%edx
call   1050 <memset@plt>
mov    -0x28(%rbp),%edi
lea    -0x21(%rbp),%rsi
mov    $0x5,%edx
call   1060 <read@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%esi
lea    0xd6e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x1c(%rbp)
cmpl   $0x5,-0x1c(%rbp)
jge    1316 <main+0x1b6>
movslq -0x1c(%rbp),%rax
movzbl -0x21(%rbp,%rax,1),%esi
lea    0xd5e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    12e7 <main+0x187>
lea    0xd38(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
movb   $0x0,0xc(%rsp)
movl   $0x0,0x8(%rsp)
mov    0x2e48(%rip),%rax
mov    (%rax),%esi
lea    0xe57(%rip),%rdi
call   1090 <open@plt>
test   %eax,%eax
js     1314 <main+0x194>
mov    %eax,%ebp
lea    0x8(%rsp),%r14
mov    %eax,%edi
mov    %r14,%rsi
mov    $0x5,%edx
call   1080 <read@plt>
mov    %eax,%ebx
lea    0xe58(%rip),%r15
mov    %r15,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xe55(%rip),%r12
mov    %r12,%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1060 <printf@plt>
movzbl 0x8(%rsp),%esi
lea    0xe45(%rip),%rbx
mov    %rbx,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
movzbl 0x9(%rsp),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
movzbl 0xa(%rsp),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
movzbl 0xb(%rsp),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
movzbl 0xc(%rsp),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
movl   $0x3020100,0x8(%rsp)
03
movb   $0x4,0xc(%rsp)
mov    %ebp,%edi
mov    %r14,%rsi
mov    $0x5,%edx
call   1050 <write@plt>
lea    0xdd6(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %r12,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x5,%edx
call   1070 <memset@plt>
mov    %ebp,%edi
mov    %r14,%rsi
mov    $0x5,%edx
call   1080 <read@plt>
mov    %r15,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1060 <printf@plt>
movzbl 0x8(%rsp),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
movzbl 0x9(%rsp),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
movzbl 0xa(%rsp),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
movzbl 0xb(%rsp),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
movzbl 0xc(%rsp),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd3f(%rip),%rdi
call   1040 <puts@plt>
xor    %edi,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@.str = [45 x i8] c"/sys/class/i2c-dev/i2c-3/device/3-0068/nvram\00"
@O_RDWR = global i32 0
@.str.1 = [26 x i8] c"Error opening NVRAM file\0A\00"
@.str.2 = [16 x i8] c"NVRAM read: %d\0A\00"
@.str.3 = [8 x i8] c"NVRAM: \00"
@.str.4 = [4 x i8] c"%d \00"
@.str.5 = [2 x i8] c"\0A\00"
@.str.6 = [17 x i8] c"NVRAM write: %d\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca [5 x i8]
%10 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %6
store i32 0, i32* %7
store i32 0, i32* %8
%11 = bitcast [5 x i8]* %9 to i8*
%12 = load i32, i32* @O_RDWR
%13 = call i32 @open(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0), i32 %12)
store i32 %13, i32* %10
%14 = load i32, i32* %10
%15 = icmp slt i32 %14, 0
br i1 %15, label %16, label %19
16: ; preds = %2
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0))
%18 = call i32 @exit(i32 0)
unreachable
19: ; preds = %2
%20 = load i32, i32* %10
%21 = getelementptr inbounds [5 x i8], [5 x i8]* %9, i64 0, i64 0
%22 = call i32 @read(i32 %20, i8* %21, i32 5)
store i32 %22, i32* %6
%23 = load i32, i32* %6
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i32 %23)
%25 = load i32, i32* %6
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i32 %25)
store i32 0, i32* %8
br label %27
27: ; preds = %37, %19
%28 = load i32, i32* %8
%29 = icmp slt i32 %28, 5
br i1 %29, label %30, label %40
30: ; preds = %27
%31 = load i32, i32* %8
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds [5 x i8], [5 x i8]* %9, i64 0, i64 %32
%34 = load i8, i8* %33
%35 = zext i8 %34 to i32
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32 %35)
br label %37
37: ; preds = %30
%38 = load i32, i32* %8
%39 = add nsw i32 %38, 1
store i32 %39, i32* %8
br label %27
40: ; preds = %27
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
store i32 0, i32* %8
br label %42
42: ; preds = %51, %40
%43 = load i32, i32* %8
%44 = icmp slt i32 %43, 5
br i1 %44, label %45, label %54
45: ; preds = %42
%46 = load i32, i32* %8
%47 = trunc i32 %46 to i8
%48 = load i32, i32* %8
%49 = sext i32 %48 to i64
%50 = getelementptr inbounds [5 x i8], [5 x i8]* %9, i64 0, i64 %49
store i8 %47, i8* %50
br label %51
51: ; preds = %45
%52 = load i32, i32* %8
%53 = add nsw i32 %52, 1
store i32 %53, i32* %8
br label %42
54: ; preds = %42
%55 = load i32, i32* %10
%56 = getelementptr inbounds [5 x i8], [5 x i8]* %9, i64 0, i64 0
%57 = call i32 @write(i32 %55, i8* %56, i32 5)
store i32 %57, i32* %6
%58 = load i32, i32* %6
%59 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.6, i64 0, i64 0), i32 %58)
%60 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
%61 = getelementptr inbounds [5 x i8], [5 x i8]* %9, i64 0, i64 0
%62 = call i32 @memset(i8* %61, i32 0, i32 5)
%63 = load i32, i32* %10
%64 = getelementptr inbounds [5 x i8], [5 x i8]* %9, i64 0, i64 0
%65 = call i32 @read(i32 %63, i8* %64, i32 5)
store i32 %65, i32* %6
%66 = load i32, i32* %6
%67 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i32 %66)
store i32 0, i32* %8
br label %68
68: ; preds = %78, %54
%69 = load i32, i32* %8
%70 = icmp slt i32 %69, 5
br i1 %70, label %71, label %81
71: ; preds = %68
%72 = load i32, i32* %8
%73 = sext i32 %72 to i64
%74 = getelementptr inbounds [5 x i8], [5 x i8]* %9, i64 0, i64 %73
%75 = load i8, i8* %74
%76 = zext i8 %75 to i32
%77 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32 %76)
br label %78
78: ; preds = %71
%79 = load i32, i32* %8
%80 = add nsw i32 %79, 1
store i32 %80, i32* %8
br label %68
81: ; preds = %68
%82 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
br label %83
83: ; preds = %81
%84 = load i32, i32* %3
ret i32 %84
}

LLVM IR (-O2):
@.str = [45 x i8] c"/sys/class/i2c-dev/i2c-3/device/3-0068/nvram\00"
@O_RDWR = global i32 0
@.str.2 = [16 x i8] c"NVRAM read: %d\0A\00"
@.str.3 = [8 x i8] c"NVRAM: \00"
@.str.4 = [4 x i8] c"%d \00"
@.str.6 = [17 x i8] c"NVRAM write: %d\0A\00"
@str = [25 x i8] c"Error opening NVRAM file\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [5 x i8]
%4 = getelementptr inbounds [5 x i8], [5 x i8]* %3, i64 0, i64 0
%5 = load i32, i32* @O_RDWR
%6 = tail call i32 @open(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0), i32 %5)
%7 = icmp slt i32 %6, 0
br i1 %7, label %8, label %11
8: ; preds = %2
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str, i64 0, i64 0))
%10 = tail call i32 @exit(i32 0)
unreachable
11: ; preds = %2
%12 = call i32 @read(i32 %6, i8* %4, i32 5)
%13 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i32 %12)
%14 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i32 %12)
%15 = load i8, i8* %4
%16 = zext i8 %15 to i32
%17 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32 %16)
%18 = getelementptr inbounds [5 x i8], [5 x i8]* %3, i64 0, i64 1
%19 = load i8, i8* %18
%20 = zext i8 %19 to i32
%21 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32 %20)
%22 = getelementptr inbounds [5 x i8], [5 x i8]* %3, i64 0, i64 2
%23 = load i8, i8* %22
%24 = zext i8 %23 to i32
%25 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32 %24)
%26 = getelementptr inbounds [5 x i8], [5 x i8]* %3, i64 0, i64 3
%27 = load i8, i8* %26
%28 = zext i8 %27 to i32
%29 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32 %28)
%30 = getelementptr inbounds [5 x i8], [5 x i8]* %3, i64 0, i64 4
%31 = load i8, i8* %30
%32 = zext i8 %31 to i32
%33 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32 %32)
%34 = tail call i32 @putchar(i32 10)
store i8 0, i8* %4
store i8 1, i8* %18
store i8 2, i8* %22
store i8 3, i8* %26
store i8 4, i8* %30
%35 = call i32 @write(i32 %6, i8* %4, i32 5)
%36 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.6, i64 0, i64 0), i32 %35)
%37 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
%38 = call i32 @memset(i8* %4, i32 0, i32 5)
%39 = call i32 @read(i32 %6, i8* %4, i32 5)
%40 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i32 %39)
%41 = load i8, i8* %4
%42 = zext i8 %41 to i32
%43 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32 %42)
%44 = load i8, i8* %18
%45 = zext i8 %44 to i32
%46 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32 %45)
%47 = load i8, i8* %22
%48 = zext i8 %47 to i32
%49 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32 %48)
%50 = load i8, i8* %26
%51 = zext i8 %50 to i32
%52 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32 %51)
%53 = load i8, i8* %30
%54 = zext i8 %53 to i32
%55 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32 %54)
%56 = call i32 @putchar(i32 10)
ret i32 0
}