#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*/ close_EEPROM();
int /*<<< orphan*/ exit(int /*<<< orphan*/);
char getchar();
int open_EEPROM();
int /*<<< orphan*/ printf(char *, ...);
int rand();
int read_EEPROM(char *, int);
int /*<<< orphan*/ scanf(char *, int *);
int /*<<< orphan*/ seek_EEPROM(int);
int /*<<< orphan*/ show_menu();
int /*<<< orphan*/ usleep(int);
int write_EEPROM(char *, int);
int main(int argc, char *argv[]) {
  int ret, i, fd;
  int val = 0;
  char c;
  char wdata[64 + 1] = {0};
  char rdata[64 + 1] = {0};
  fd = open_EEPROM();
  if (fd < 0) {
    printf("Can not open device file.\n");
    return -1;
  }
  while (1) {
    show_menu();
    c = getchar();
    getchar();
    printf("\n");
    switch (c) {
    case '1':
    case 'w':
      for (i = 0; i < 64; i++)
        wdata[i] = rand() % 3 < 2 ? rand() % 26 + 'A' : rand() % 10 + '0';
      ret = write_EEPROM(wdata, 1);
      if (ret < 0) {
        printf("write() failed.\n");
      }
      break;
    case '2':
    case 'r':
      printf("How many pages to read: ");
      scanf("%d", &val);
      getchar();
      printf("\n");
      if ((val < 0x0000) || (val >= 0x0200)) {
        printf("Invalid input...\n");
      } else {
        for (i = 0; i < val; i++) {
          ret = read_EEPROM(rdata, 1);
          if (ret < 0) {
            printf("read() failed.\n");
            break;
          } else {
            printf("Read Data = %s\n", rdata);
          }
        }
      }
      break;
    case '3':
    case 's':
      printf("Choose the input value: ");
      scanf("%d", &val);
      getchar();
      printf("\n");
      if ((val < 0x0000) || (val >= 0x7FFF)) {
        printf("Invalid input...\n");
      } else {
        if (seek_EEPROM(val)) {
          printf("seek failed\n");
        }
      }
      break;
    case '4':
      for (i = 0; i < 64; i++)
        wdata[i] = '.';
      seek_EEPROM(0);
      for (i = 0; i < 512; i++) {
        ret = write_EEPROM(wdata, 1);
        if (ret < 0) {
          printf("write() failed.\n");
          break;
        } else
          printf("writing done for page  %d\n", i);
        usleep(10000);
      }
      break;
    case '5':
      close_EEPROM();
      exit(0);
      break;
    default:
      printf("Invalid input\n");
      break;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xd0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x20(%rbp)
lea    -0x70(%rbp),%rdi
xor    %esi,%esi
mov    $0x41,%edx
call   1060 <memset@plt>
lea    -0xc0(%rbp),%rdi
xor    %esi,%esi
mov    $0x41,%edx
call   1060 <memset@plt>
mov    $0x0,%al
call   1040 <open_EEPROM@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    1243 <main+0x73>
lea    0xeee(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0xffffffff,%eax
add    $0xd0,%rsp
pop    %rbp
ret
jmp    1248 <main+0x78>
xor    %eax,%eax
mov    %al,-0xc9(%rbp)
call   10b0 <show_menu@plt>
mov    -0xc9(%rbp),%al
call   1080 <getchar@plt>
mov    %al,%cl
mov    -0xc9(%rbp),%al
mov    %cl,-0x21(%rbp)
call   1080 <getchar@plt>
mov    -0xc9(%rbp),%al
lea    0xef7(%rip),%rdi
call   1050 <printf@plt>
movsbl -0x21(%rbp),%eax
add    $0xffffffcf,%eax
mov    %eax,%ecx
mov    %rcx,-0xc8(%rbp)
sub    $0x46,%eax
ja     1566 <main+0x396>
mov    -0xc8(%rbp),%rax
lea    0xd57(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
movl   $0x0,-0x18(%rbp)
cmpl   $0x40,-0x18(%rbp)
jge    1332 <main+0x162>
mov    $0x0,%al
call   10e0 <rand@plt>
mov    $0x3,%ecx
cltd
idiv   %ecx
cmp    $0x2,%edx
jge    12fa <main+0x12a>
mov    $0x0,%al
call   10e0 <rand@plt>
mov    $0x1a,%ecx
cltd
idiv   %ecx
mov    %edx,%eax
add    $0x41,%eax
mov    %eax,-0xd0(%rbp)
jmp    1314 <main+0x144>
mov    $0x0,%al
call   10e0 <rand@plt>
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %edx,%eax
add    $0x30,%eax
mov    %eax,-0xd0(%rbp)
mov    -0xd0(%rbp),%eax
mov    %al,%cl
movslq -0x18(%rbp),%rax
mov    %cl,-0x70(%rbp,%rax,1)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    12b9 <main+0xe9>
lea    -0x70(%rbp),%rdi
mov    $0x1,%esi
call   1090 <write_EEPROM@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    135b <main+0x18b>
lea    0xde3(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    1574 <main+0x3a4>
lea    0xde1(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xdec(%rip),%rdi
lea    -0x20(%rbp),%rsi
call   10a0 <scanf@plt>
mov    $0x0,%al
call   1080 <getchar@plt>
lea    0xde8(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
cmpl   $0x0,-0x20(%rbp)
jl     13aa <main+0x1da>
cmpl   $0x200,-0x20(%rbp)
jl     13bd <main+0x1ed>
lea    0xdb3(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    142e <main+0x25e>
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x20(%rbp),%eax
jge    1429 <main+0x259>
lea    -0xc0(%rbp),%rdi
mov    $0x1,%esi
call   10d0 <read_EEPROM@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    1401 <main+0x231>
lea    0xd81(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    1429 <main+0x259>
lea    -0xc0(%rbp),%rsi
lea    0xd77(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    141b <main+0x24b>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    13c4 <main+0x1f4>
jmp    142e <main+0x25e>
jmp    1574 <main+0x3a4>
lea    0xd5c(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xd19(%rip),%rdi
lea    -0x20(%rbp),%rsi
call   10a0 <scanf@plt>
mov    $0x0,%al
call   1080 <getchar@plt>
lea    0xd15(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
cmpl   $0x0,-0x20(%rbp)
jl     147d <main+0x2ad>
cmpl   $0x7fff,-0x20(%rbp)
jl     1490 <main+0x2c0>
lea    0xce0(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    14b4 <main+0x2e4>
mov    -0x20(%rbp),%edi
call   1070 <seek_EEPROM@plt>
cmp    $0x0,%eax
je     14af <main+0x2df>
lea    0xd07(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    14b4 <main+0x2e4>
jmp    1574 <main+0x3a4>
movl   $0x0,-0x18(%rbp)
cmpl   $0x40,-0x18(%rbp)
jge    14e1 <main+0x311>
movslq -0x18(%rbp),%rax
movb   $0x2e,-0x70(%rbp,%rax,1)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    14c0 <main+0x2f0>
xor    %edi,%edi
call   1070 <seek_EEPROM@plt>
movl   $0x0,-0x18(%rbp)
cmpl   $0x200,-0x18(%rbp)
jge    1553 <main+0x383>
lea    -0x70(%rbp),%rdi
mov    $0x1,%esi
call   1090 <write_EEPROM@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    152a <main+0x35a>
lea    0xc19(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    1553 <main+0x383>
mov    -0x18(%rbp),%esi
lea    0xc88(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x2710,%edi
call   10f0 <usleep@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    14ef <main+0x31f>
jmp    1574 <main+0x3a4>
mov    $0x0,%al
call   1030 <close_EEPROM@plt>
xor    %edi,%edi
call   10c0 <exit@plt>
lea    0xc6a(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    1248 <main+0x78>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xa8,%rsp
movl   $0x0,0xc(%rsp)
xorps  %xmm0,%xmm0
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x10(%rsp)
movb   $0x0,0x50(%rsp)
movaps %xmm0,0x90(%rsp)
movaps %xmm0,0x80(%rsp)
movaps %xmm0,0x70(%rsp)
movaps %xmm0,0x60(%rsp)
movb   $0x0,0xa0(%rsp)
xor    %eax,%eax
call   1060 <open_EEPROM@plt>
test   %eax,%eax
jns    1265 <main+0x85>
lea    0xf8d(%rip),%rdi
call   1050 <puts@plt>
mov    $0xffffffff,%eax
add    $0xa8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xf5c(%rip),%r13
lea    0x10(%rsp),%r14
lea    0xecd(%rip),%r12
jmp    1285 <main+0xa5>
nopw   0x0(%rax,%rax,1)
call   1050 <puts@plt>
xor    %eax,%eax
call   10c0 <show_menu@plt>
xor    %eax,%eax
call   1090 <getchar@plt>
mov    %eax,%ebx
xor    %eax,%eax
call   1090 <getchar@plt>
mov    $0xa,%edi
call   1040 <putchar@plt>
movsbl %bl,%eax
add    $0xffffffcf,%eax
mov    %r13,%rdi
cmp    $0x46,%eax
ja     1280 <main+0xa0>
lea    0xd55(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
mov    %r13,%rdi
jmp    *%rax
mov    %r14,%r12
xor    %ebx,%ebx
nopl   0x0(%rax)
xor    %eax,%eax
call   10f0 <rand@plt>
movslq %eax,%r15
imul   $0x55555556,%r15,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
shr    $0x20,%rax
add    %ecx,%eax
lea    (%rax,%rax,2),%eax
sub    %eax,%r15d
xor    %ebp,%ebp
cmp    $0x2,%r15d
setl   %bpl
xor    %eax,%eax
call   10f0 <rand@plt>
shl    $0x4,%ebp
or     $0xa,%ebp
cltd
idiv   %ebp
lea    0x41(%rdx),%eax
add    $0x30,%edx
cmp    $0x2,%r15d
cmovl  %eax,%edx
mov    %dl,0x10(%rsp,%rbx,1)
add    $0x1,%rbx
cmp    $0x40,%rbx
jne    12d0 <main+0xf0>
mov    %r12,%rdi
mov    $0x1,%esi
call   10a0 <write_EEPROM@plt>
lea    0xe7b(%rip),%rdi
test   %eax,%eax
mov    %r12,%r14
lea    0xdfc(%rip),%r12
jns    1285 <main+0xa5>
jmp    1280 <main+0xa0>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
lea    0xdc5(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %r12,%rdi
lea    0xc(%rsp),%rsi
call   10b0 <scanf@plt>
xor    %eax,%eax
call   1090 <getchar@plt>
mov    $0xa,%edi
call   1040 <putchar@plt>
mov    0xc(%rsp),%eax
lea    0xe10(%rip),%rdi
cmp    $0x1ff,%eax
ja     1280 <main+0xa0>
test   %eax,%eax
je     1285 <main+0xa5>
xor    %ebx,%ebx
nopl   0x0(%rax)
lea    0x60(%rsp),%rbp
mov    %rbp,%rdi
mov    $0x1,%esi
call   10e0 <read_EEPROM@plt>
test   %eax,%eax
js     14cf <main+0x2ef>
lea    0xd77(%rip),%rdi
mov    %rbp,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
add    $0x1,%ebx
cmp    0xc(%rsp),%ebx
jl     13b0 <main+0x1d0>
jmp    1285 <main+0xa5>
nopl   0x0(%rax)
lea    0xd61(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %r12,%rdi
lea    0xc(%rsp),%rsi
call   10b0 <scanf@plt>
xor    %eax,%eax
call   1090 <getchar@plt>
mov    $0xa,%edi
call   1040 <putchar@plt>
mov    0xc(%rsp),%eax
lea    0xd80(%rip),%rdi
cmp    $0x7ffe,%eax
ja     1280 <main+0xa0>
mov    %eax,%edi
call   1080 <seek_EEPROM@plt>
lea    0xd4c(%rip),%rdi
test   %eax,%eax
jne    1280 <main+0xa0>
jmp    1285 <main+0xa5>
movaps 0xbac(%rip),%xmm0
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x10(%rsp)
xor    %r15d,%r15d
xor    %edi,%edi
call   1080 <seek_EEPROM@plt>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r14,%rdi
mov    $0x1,%esi
call   10a0 <write_EEPROM@plt>
test   %eax,%eax
js     14be <main+0x2de>
lea    0xcd9(%rip),%rdi
mov    %r15d,%esi
xor    %eax,%eax
call   1070 <printf@plt>
mov    $0x2710,%edi
call   1100 <usleep@plt>
add    $0x1,%r15d
cmp    $0x200,%r15d
jne    1480 <main+0x2a0>
jmp    1285 <main+0xa5>
lea    0xcf3(%rip),%rdi
call   1050 <puts@plt>
jmp    1285 <main+0xa5>
lea    0xcc2(%rip),%rdi
call   1050 <puts@plt>
jmp    1285 <main+0xa5>
xor    %eax,%eax
call   1030 <close_EEPROM@plt>
xor    %edi,%edi
call   10d0 <exit@plt>

LLVM IR (-O0):
@.str = [27 x i8] c"Can not open device file.\0A\00"
@.str.1 = [2 x i8] c"\0A\00"
@.str.2 = [17 x i8] c"write() failed.\0A\00"
@.str.3 = [25 x i8] c"How many pages to read: \00"
@.str.4 = [3 x i8] c"%d\00"
@.str.5 = [18 x i8] c"Invalid input...\0A\00"
@.str.6 = [16 x i8] c"read() failed.\0A\00"
@.str.7 = [16 x i8] c"Read Data = %s\0A\00"
@.str.8 = [25 x i8] c"Choose the input value: \00"
@.str.9 = [13 x i8] c"seek failed\0A\00"
@.str.10 = [27 x i8] c"writing done for page %d\0A\00"
@.str.11 = [15 x i8] c"Invalid input\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 i32
%10 = alloca i8
%11 = alloca [65 x i8]
%12 = alloca [65 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %9
%13 = bitcast [65 x i8]* %11 to i8*
%14 = bitcast [65 x i8]* %12 to i8*
%15 = call i32 (...) @open_EEPROM()
store i32 %15, i32* %8
%16 = load i32, i32* %8
%17 = icmp slt i32 %16, 0
br i1 %17, label %18, label %20
18: ; preds = %2
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
ret i32 -1
20: ; preds = %2
br label %21
21: ; preds = %20, %151
%22 = call i32 (...) @show_menu()
%23 = call signext i8 (...) @getchar()
store i8 %23, i8* %10
%24 = call signext i8 (...) @getchar()
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%26 = load i8, i8* %10
%27 = sext i8 %26 to i32
switch i32 %27, label %149 [
i32 49, label %28
i32 119, label %28
i32 50, label %61
i32 114, label %61
i32 51, label %94
i32 115, label %94
i32 52, label %114
i32 53, label %146
]
28: ; preds = %21, %21
store i32 0, i32* %7
br label %29
29: ; preds = %50, %28
%30 = load i32, i32* %7
%31 = icmp slt i32 %30, 64
br i1 %31, label %32, label %53
32: ; preds = %29
%33 = call i32 (...) @rand()
%34 = srem i32 %33, 3
%35 = icmp slt i32 %34, 2
br i1 %35, label %36, label %40
36: ; preds = %32
%37 = call i32 (...) @rand()
%38 = srem i32 %37, 26
%39 = add nsw i32 %38, 65
br label %44
40: ; preds = %32
%41 = call i32 (...) @rand()
%42 = srem i32 %41, 10
%43 = add nsw i32 %42, 48
br label %44
44: ; preds = %40, %36
%45 = phi i32 [ %39, %36 ], [ %43, %40 ]
%46 = trunc i32 %45 to i8
%47 = load i32, i32* %7
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds [65 x i8], [65 x i8]* %11, i64 0, i64 %48
store i8 %46, i8* %49
br label %50
50: ; preds = %44
%51 = load i32, i32* %7
%52 = add nsw i32 %51, 1
store i32 %52, i32* %7
br label %29
53: ; preds = %29
%54 = getelementptr inbounds [65 x i8], [65 x i8]* %11, i64 0, i64 0
%55 = call i32 @write_EEPROM(i8* %54, i32 1)
store i32 %55, i32* %6
%56 = load i32, i32* %6
%57 = icmp slt i32 %56, 0
br i1 %57, label %58, label %60
58: ; preds = %53
%59 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
br label %60
60: ; preds = %58, %53
br label %151
61: ; preds = %21, %21
%62 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0))
%63 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32* %9)
%64 = call signext i8 (...) @getchar()
%65 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%66 = load i32, i32* %9
%67 = icmp slt i32 %66, 0
br i1 %67, label %71, label %68
68: ; preds = %61
%69 = load i32, i32* %9
%70 = icmp sge i32 %69, 512
br i1 %70, label %71, label %73
71: ; preds = %68, %61
%72 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0))
br label %93
73: ; preds = %68
store i32 0, i32* %7
br label %74
74: ; preds = %89, %73
%75 = load i32, i32* %7
%76 = load i32, i32* %9
%77 = icmp slt i32 %75, %76
br i1 %77, label %78, label %92
78: ; preds = %74
%79 = getelementptr inbounds [65 x i8], [65 x i8]* %12, i64 0, i64 0
%80 = call i32 @read_EEPROM(i8* %79, i32 1)
store i32 %80, i32* %6
%81 = load i32, i32* %6
%82 = icmp slt i32 %81, 0
br i1 %82, label %83, label %85
83: ; preds = %78
%84 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.6, i64 0, i64 0))
br label %92
85: ; preds = %78
%86 = getelementptr inbounds [65 x i8], [65 x i8]* %12, i64 0, i64 0
%87 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.7, i64 0, i64 0), i8* %86)
br label %88
88: ; preds = %85
br label %89
89: ; preds = %88
%90 = load i32, i32* %7
%91 = add nsw i32 %90, 1
store i32 %91, i32* %7
br label %74
92: ; preds = %83, %74
br label %93
93: ; preds = %92, %71
br label %151
94: ; preds = %21, %21
%95 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.8, i64 0, i64 0))
%96 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32* %9)
%97 = call signext i8 (...) @getchar()
%98 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%99 = load i32, i32* %9
%100 = icmp slt i32 %99, 0
br i1 %100, label %104, label %101
101: ; preds = %94
%102 = load i32, i32* %9
%103 = icmp sge i32 %102, 32767
br i1 %103, label %104, label %106
104: ; preds = %101, %94
%105 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0))
br label %113
106: ; preds = %101
%107 = load i32, i32* %9
%108 = call i32 @seek_EEPROM(i32 %107)
%109 = icmp ne i32 %108, 0
br i1 %109, label %110, label %112
110: ; preds = %106
%111 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.9, i64 0, i64 0))
br label %112
112: ; preds = %110, %106
br label %113
113: ; preds = %112, %104
br label %151
114: ; preds = %21
store i32 0, i32* %7
br label %115
115: ; preds = %122, %114
%116 = load i32, i32* %7
%117 = icmp slt i32 %116, 64
br i1 %117, label %118, label %125
118: ; preds = %115
%119 = load i32, i32* %7
%120 = sext i32 %119 to i64
%121 = getelementptr inbounds [65 x i8], [65 x i8]* %11, i64 0, i64 %120
store i8 46, i8* %121
br label %122
122: ; preds = %118
%123 = load i32, i32* %7
%124 = add nsw i32 %123, 1
store i32 %124, i32* %7
br label %115
125: ; preds = %115
%126 = call i32 @seek_EEPROM(i32 0)
store i32 0, i32* %7
br label %127
127: ; preds = %142, %125
%128 = load i32, i32* %7
%129 = icmp slt i32 %128, 512
br i1 %129, label %130, label %145
130: ; preds = %127
%131 = getelementptr inbounds [65 x i8], [65 x i8]* %11, i64 0, i64 0
%132 = call i32 @write_EEPROM(i8* %131, i32 1)
store i32 %132, i32* %6
%133 = load i32, i32* %6
%134 = icmp slt i32 %133, 0
br i1 %134, label %135, label %137
135: ; preds = %130
%136 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
br label %145
137: ; preds = %130
%138 = load i32, i32* %7
%139 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.10, i64 0, i64 0), i32 %138)
br label %140
140: ; preds = %137
%141 = call i32 @usleep(i32 10000)
br label %142
142: ; preds = %140
%143 = load i32, i32* %7
%144 = add nsw i32 %143, 1
store i32 %144, i32* %7
br label %127
145: ; preds = %135, %127
br label %151
146: ; preds = %21
%147 = call i32 (...) @close_EEPROM()
%148 = call i32 @exit(i32 0)
unreachable
149: ; preds = %21
%150 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.11, i64 0, i64 0))
br label %151
151: ; preds = %149, %145, %113, %93, %60
br label %21
}

LLVM IR (-O2):
@.str.3 = [25 x i8] c"How many pages to read: \00"
@.str.4 = [3 x i8] c"%d\00"
@.str.7 = [16 x i8] c"Read Data = %s\0A\00"
@.str.8 = [25 x i8] c"Choose the input value: \00"
@.str.10 = [27 x i8] c"writing done for page %d\0A\00"
@str.12 = [12 x i8] c"seek failed\00"
@str.14 = [15 x i8] c"read() failed.\00"
@str.15 = [17 x i8] c"Invalid input...\00"
@str.16 = [16 x i8] c"write() failed.\00"
@str.17 = [14 x i8] c"Invalid input\00"
@str.18 = [26 x i8] c"Can not open device file.\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i32
%4 = alloca [65 x i8]
%5 = getelementptr inbounds [65 x i8], [65 x i8]* %4, i64 0, i64 0
%6 = alloca [65 x i8]
%7 = bitcast i32* %3 to i8*
store i32 0, i32* %3
%8 = getelementptr inbounds [65 x i8], [65 x i8]* %4, i64 0, i64 0
%9 = getelementptr inbounds [65 x i8], [65 x i8]* %6, i64 0, i64 0
%10 = tail call i32 (...) @open_EEPROM()
%11 = icmp slt i32 %10, 0
br i1 %11, label %12, label %14
12: ; preds = %2
%13 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str.18, i64 0, i64 0))
ret i32 -1
14: ; preds = %2, %83
%15 = call i32 (...) @show_menu()
%16 = call signext i8 (...) @getchar()
%17 = call signext i8 (...) @getchar()
%18 = call i32 @putchar(i32 10)
%19 = sext i8 %16 to i32
switch i32 %19, label %80 [
i32 49, label %20
i32 119, label %20
i32 50, label %40
i32 114, label %40
i32 51, label %58
i32 115, label %58
i32 52, label %21
i32 53, label %77
]
20: ; preds = %14, %14
br label %23
21: ; preds = %14
%22 = call i32 @seek_EEPROM(i32 0)
br label %68
23: ; preds = %20, %23
%24 = phi i64 [ %35, %23 ], [ 0, %20 ]
%25 = call i32 (...) @rand()
%26 = srem i32 %25, 3
%27 = icmp slt i32 %26, 2
%28 = call i32 (...) @rand()
%29 = select i1 %27, i32 26, i32 10
%30 = select i1 %27, i32 65, i32 48
%31 = srem i32 %28, %29
%32 = add nsw i32 %31, %30
%33 = trunc i32 %32 to i8
%34 = getelementptr inbounds [65 x i8], [65 x i8]* %4, i64 0, i64 %24
store i8 %33, i8* %34
%35 = add nuw nsw i64 %24, 1
%36 = icmp eq i64 %35, 64
br i1 %36, label %37, label %23
37: ; preds = %23
%38 = call i32 @write_EEPROM(i8* %8, i32 1)
%39 = icmp slt i32 %38, 0
br i1 %39, label %80, label %83
40: ; preds = %14, %14
%41 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0))
%42 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32* %3)
%43 = call signext i8 (...) @getchar()
%44 = call i32 @putchar(i32 10)
%45 = load i32, i32* %3
%46 = icmp ugt i32 %45, 511
br i1 %46, label %80, label %47
47: ; preds = %40
%48 = icmp eq i32 %45, 0
br i1 %48, label %83, label %49
49: ; preds = %47, %53
%50 = phi i32 [ %55, %53 ], [ 0, %47 ]
%51 = call i32 @read_EEPROM(i8* %9, i32 1)
%52 = icmp slt i32 %51, 0
br i1 %52, label %80, label %53
53: ; preds = %49
%54 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.7, i64 0, i64 0), i8* %9)
%55 = add nuw nsw i32 %50, 1
%56 = load i32, i32* %3
%57 = icmp slt i32 %55, %56
br i1 %57, label %49, label %83
58: ; preds = %14, %14
%59 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.8, i64 0, i64 0))
%60 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32* %3)
%61 = call signext i8 (...) @getchar()
%62 = call i32 @putchar(i32 10)
%63 = load i32, i32* %3
%64 = icmp ugt i32 %63, 32766
br i1 %64, label %80, label %65
65: ; preds = %58
%66 = call i32 @seek_EEPROM(i32 %63)
%67 = icmp eq i32 %66, 0
br i1 %67, label %83, label %80
68: ; preds = %21, %72
%69 = phi i32 [ 0, %21 ], [ %75, %72 ]
%70 = call i32 @write_EEPROM(i8* %8, i32 1)
%71 = icmp slt i32 %70, 0
br i1 %71, label %80, label %72
72: ; preds = %68
%73 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.10, i64 0, i64 0), i32 %69)
%74 = call i32 @usleep(i32 10000)
%75 = add nuw nsw i32 %69, 1
%76 = icmp eq i32 %75, 512
br i1 %76, label %83, label %68
77: ; preds = %14
%78 = call i32 (...) @close_EEPROM()
%79 = call i32 @exit(i32 0)
unreachable
80: ; preds = %68, %49, %14, %65, %58, %40, %37
%81 = phi i8* [ getelementptr inbounds ([16 x i8], [16 x i8]* @str.16, i64 0, i64 0), %37 ], [ getelementptr inbounds ([17 x i8], [17 x i8]* @str.15, i64 0, i64 0), %40 ], [ getelementptr inbounds ([17 x i8], [17 x i8]* @str.15, i64 0, i64 0), %58 ], [ getelementptr inbounds ([12 x i8], [12 x i8]* @str.12, i64 0, i64 0), %65 ], [ getelementptr inbounds ([14 x i8], [14 x i8]* @str.17, i64 0, i64 0), %14 ], [ getelementptr inbounds ([15 x i8], [15 x i8]* @str.14, i64 0, i64 0), %49 ], [ getelementptr inbounds ([16 x i8], [16 x i8]* @str.16, i64 0, i64 0), %68 ]
%82 = call i32 @puts(i8* dereferenceable(1) %81)
br label %83
83: ; preds = %72, %53, %80, %47, %65, %37
br label %14
}