#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 unsigned char off_t;

/* Variables and functions */
int /*<<< orphan*/ O_RDWR;
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ getchar();
int lseek(int, unsigned char, int /*<<< orphan*/);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int read(int, unsigned char *, int);
int /*<<< orphan*/ scanf(char *, ...);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strlen(unsigned char *);
int write(int, unsigned char *, int /*<<< orphan*/);
int main(int argc, char *argv[]) {
  char *file_name;
  int choice;
  int fd = -1;
  unsigned char data[128];
  int cnt;
  int i;
  off_t seek;
  if (argc != 2) {
    fprintf(stderr, "Usage: %s <device file name>\n", argv[0]);
    return 1;
  } else {
    file_name = argv[1];
  }
  do {
    printf("1: Open\n");
    printf("2: Read\n");
    printf("3: Write\n");
    printf("4: Close\n");
    printf("5: Seek\n");
    printf("0: Exit\n");
    printf("Enter choice: ");
    scanf("%d", &choice);
    getchar();
    switch (choice) {
    case 1:
      fd = open(file_name, O_RDWR);
      if (fd == -1) {
        perror("file_ops open");
      }
      break;
    case 2:
      if (fd == -1) {
        printf("File not open\n");
        break;
      }
      printf("Bytes to read: ");
      scanf("%d", &cnt);
      getchar();
      cnt = read(fd, data, cnt);
      if (cnt == -1) {
        perror("file_ops read");
        break;
      }
      printf("Read %d bytes in %p: ", cnt, data);
      for (i = 0; i < cnt; i++) {
        printf("%c (%02X) ", data[i], data[i]);
      }
      printf("\n");
      break;
    case 3:
      if (fd == -1) {
        printf("File not open\n");
        break;
      }
      printf("Enter your string: ");
      scanf("%[^\n]", data);
      getchar();
      cnt = write(fd, data, strlen(data));
      if (cnt == -1) {
        perror("file_ops write");
        break;
      }
      printf("Wrote %d bytes from %p\n", cnt, data);
      break;
    case 4:
      if (fd == -1) {
        printf("File not open\n");
        break;
      }
      close(fd);
      fd = -1;
      break;
    case 5:
      if (fd == -1) {
        printf("File not open\n");
        break;
      }
      printf("Enter the seek from start of device file: ");
      scanf("%lld", &seek);
      getchar();
      if (lseek(fd, seek, SEEK_SET) == -1) {
        perror("file_ops lseek");
        break;
      }
      break;
    }
  } while (choice != 0);
  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   $0xffffffff,-0x20(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     1202 <main+0x52>
mov    0x2df7(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe23(%rip),%rsi
call   10a0 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    15a6 <main+0x3f6>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x18(%rbp)
jmp    1213 <main+0x63>
lea    0xe18(%rip),%rdi
xor    %eax,%eax
mov    %al,-0xb9(%rbp)
call   1050 <printf@plt>
mov    -0xb9(%rbp),%al
lea    0xe07(%rip),%rdi
call   1050 <printf@plt>
mov    -0xb9(%rbp),%al
lea    0xdfe(%rip),%rdi
call   1050 <printf@plt>
mov    -0xb9(%rbp),%al
lea    0xdf6(%rip),%rdi
call   1050 <printf@plt>
mov    -0xb9(%rbp),%al
lea    0xdee(%rip),%rdi
call   1050 <printf@plt>
mov    -0xb9(%rbp),%al
lea    0xde5(%rip),%rdi
call   1050 <printf@plt>
mov    -0xb9(%rbp),%al
lea    0xddc(%rip),%rdi
call   1050 <printf@plt>
mov    -0xb9(%rbp),%al
lea    0xdd9(%rip),%rdi
lea    -0x1c(%rbp),%rsi
call   10b0 <scanf@plt>
mov    -0xb9(%rbp),%al
call   1090 <getchar@plt>
mov    -0x1c(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,%ecx
mov    %rcx,-0xb8(%rbp)
sub    $0x4,%eax
ja     1590 <main+0x3e0>
mov    -0xb8(%rbp),%rax
lea    0xd26(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x18(%rbp),%rdi
mov    0x2cfa(%rip),%rax
mov    (%rax),%esi
call   10c0 <open@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0xffffffff,-0x20(%rbp)
jne    130e <main+0x15e>
lea    0xd73(%rip),%rdi
call   10d0 <perror@plt>
jmp    1590 <main+0x3e0>
cmpl   $0xffffffff,-0x20(%rbp)
jne    1330 <main+0x180>
lea    0xd66(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    1590 <main+0x3e0>
lea    0xd62(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xd34(%rip),%rdi
lea    -0xa4(%rbp),%rsi
mov    $0x0,%al
call   10b0 <scanf@plt>
mov    $0x0,%al
call   1090 <getchar@plt>
mov    -0x20(%rbp),%edi
lea    -0xa0(%rbp),%rsi
mov    -0xa4(%rbp),%edx
call   1080 <read@plt>
mov    %eax,-0xa4(%rbp)
cmpl   $0xffffffff,-0xa4(%rbp)
jne    1393 <main+0x1e3>
lea    0xd20(%rip),%rdi
call   10d0 <perror@plt>
jmp    1590 <main+0x3e0>
mov    -0xa4(%rbp),%esi
lea    -0xa0(%rbp),%rdx
lea    0xd10(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0xa8(%rbp)
mov    -0xa8(%rbp),%eax
cmp    -0xa4(%rbp),%eax
jge    140a <main+0x25a>
movslq -0xa8(%rbp),%rax
movzbl -0xa0(%rbp,%rax,1),%esi
ff
movslq -0xa8(%rbp),%rax
movzbl -0xa0(%rbp,%rax,1),%edx
ff
lea    0xcde(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0xa8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xa8(%rbp)
jmp    13b8 <main+0x208>
lea    0xc1f(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    1590 <main+0x3e0>
cmpl   $0xffffffff,-0x20(%rbp)
jne    143a <main+0x28a>
lea    0xc5c(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    1590 <main+0x3e0>
lea    0xc97(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0xa0(%rbp),%rsi
lea    0xc96(%rip),%rdi
mov    $0x0,%al
call   10b0 <scanf@plt>
mov    $0x0,%al
call   1090 <getchar@plt>
mov    -0x20(%rbp),%eax
mov    %eax,-0xcc(%rbp)
lea    -0xa0(%rbp),%rax
mov    %rax,-0xc8(%rbp)
lea    -0xa0(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0xcc(%rbp),%edi
mov    -0xc8(%rbp),%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    %eax,-0xa4(%rbp)
cmpl   $0xffffffff,-0xa4(%rbp)
jne    14bf <main+0x30f>
lea    0xc3d(%rip),%rdi
call   10d0 <perror@plt>
jmp    1590 <main+0x3e0>
mov    -0xa4(%rbp),%esi
lea    -0xa0(%rbp),%rdx
lea    0xc2e(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    1590 <main+0x3e0>
cmpl   $0xffffffff,-0x20(%rbp)
jne    14fc <main+0x34c>
lea    0xb9a(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    1590 <main+0x3e0>
mov    -0x20(%rbp),%edi
call   1070 <close@plt>
movl   $0xffffffff,-0x20(%rbp)
jmp    1590 <main+0x3e0>
cmpl   $0xffffffff,-0x20(%rbp)
jne    152d <main+0x37d>
lea    0xb69(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    1590 <main+0x3e0>
lea    0xbe5(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xc02(%rip),%rdi
lea    -0xa9(%rbp),%rsi
mov    $0x0,%al
call   10b0 <scanf@plt>
mov    $0x0,%al
call   1090 <getchar@plt>
mov    -0x20(%rbp),%edi
mov    -0xa9(%rbp),%al
mov    0x2a69(%rip),%rcx
mov    (%rcx),%edx
movzbl %al,%esi
call   1060 <lseek@plt>
cmp    $0xffffffff,%eax
jne    158b <main+0x3db>
lea    0xbc8(%rip),%rdi
call   10d0 <perror@plt>
jmp    1590 <main+0x3e0>
jmp    1590 <main+0x3e0>
jmp    1595 <main+0x3e5>
cmpl   $0x0,-0x1c(%rbp)
jne    1213 <main+0x63>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xd0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xa8,%rsp
cmp    $0x2,%edi
jne    148e <main+0x2be>
mov    0x8(%rsi),%rax
mov    %rax,0x18(%rsp)
mov    $0xffffffff,%ebp
lea    0xf12(%rip),%r13
lea    0xf13(%rip),%r14
lea    0xf14(%rip),%r12
lea    0xf16(%rip),%rbx
jmp    124c <main+0x7c>
mov    0x2dcb(%rip),%rax
mov    (%rax),%esi
mov    0x18(%rsp),%rdi
call   10e0 <open@plt>
mov    %eax,%ebp
cmp    $0xffffffff,%eax
je     1466 <main+0x296>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    0x14(%rsp),%eax
test   %eax,%eax
je     14ad <main+0x2dd>
mov    %r13,%rdi
call   1040 <puts@plt>
mov    %r14,%rdi
call   1040 <puts@plt>
mov    %r12,%rdi
call   1040 <puts@plt>
mov    %rbx,%rdi
call   1040 <puts@plt>
lea    0xec0(%rip),%rdi
call   1040 <puts@plt>
lea    0xebc(%rip),%rdi
call   1040 <puts@plt>
lea    0xda7(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
lea    0xda8(%rip),%rdi
lea    0x14(%rsp),%rsi
xor    %eax,%eax
call   10d0 <scanf@plt>
xor    %eax,%eax
call   10b0 <getchar@plt>
mov    0x14(%rsp),%eax
lea    -0x1(%rax),%ecx
cmp    $0x4,%ecx
ja     1244 <main+0x74>
lea    0xd41(%rip),%rdx
movslq (%rdx,%rcx,4),%rax
add    %rdx,%rax
jmp    *%rax
cmp    $0xffffffff,%ebp
je     1450 <main+0x280>
lea    0xd7a(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
lea    0xd5b(%rip),%rdi
lea    0x10(%rsp),%rsi
xor    %eax,%eax
call   10d0 <scanf@plt>
xor    %eax,%eax
call   10b0 <getchar@plt>
mov    0x10(%rsp),%edx
mov    %ebp,%edi
lea    0x20(%rsp),%r15
mov    %r15,%rsi
call   10a0 <read@plt>
mov    %eax,0x10(%rsp)
cmp    $0xffffffff,%eax
je     1474 <main+0x2a4>
lea    0xd50(%rip),%rdi
mov    %eax,%esi
mov    %r15,%rdx
xor    %eax,%eax
call   1070 <printf@plt>
cmpl   $0x0,0x10(%rsp)
lea    0xd4e(%rip),%rbx
jle    1360 <main+0x190>
xor    %r15d,%r15d
nopl   (%rax)
movzbl 0x20(%rsp,%r15,1),%edx
mov    %rbx,%rdi
mov    %edx,%esi
xor    %eax,%eax
call   1070 <printf@plt>
add    $0x1,%r15
movslq 0x10(%rsp),%rax
cmp    %rax,%r15
jl     1340 <main+0x170>
mov    $0xa,%edi
call   1030 <putchar@plt>
lea    0xdb0(%rip),%r12
lea    0xdb2(%rip),%rbx
jmp    1240 <main+0x70>
cmp    $0xffffffff,%ebp
je     1450 <main+0x280>
lea    0xd04(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
lea    0xd0a(%rip),%rdi
lea    0x20(%rsp),%r15
mov    %r15,%rsi
xor    %eax,%eax
call   10d0 <scanf@plt>
xor    %eax,%eax
call   10b0 <getchar@plt>
mov    %r15,%rdi
call   1060 <strlen@plt>
mov    %ebp,%edi
mov    %r15,%rsi
mov    %eax,%edx
call   1050 <write@plt>
mov    %eax,0x10(%rsp)
cmp    $0xffffffff,%eax
je     147d <main+0x2ad>
lea    0xce1(%rip),%rdi
mov    %eax,%esi
mov    %r15,%rdx
xor    %eax,%eax
call   1070 <printf@plt>
jmp    1240 <main+0x70>
cmp    $0xffffffff,%ebp
je     1450 <main+0x280>
mov    %ebp,%edi
call   1090 <close@plt>
jmp    145c <main+0x28c>
cmp    $0xffffffff,%ebp
je     1450 <main+0x280>
lea    0xcce(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
lea    0xceb(%rip),%rdi
lea    0xf(%rsp),%rsi
xor    %eax,%eax
call   10d0 <scanf@plt>
xor    %eax,%eax
call   10b0 <getchar@plt>
movzbl 0xf(%rsp),%esi
mov    0x2b9f(%rip),%rax
mov    (%rax),%edx
mov    %ebp,%edi
call   1080 <lseek@plt>
cmp    $0xffffffff,%eax
jne    1240 <main+0x70>
lea    0xcb8(%rip),%rdi
jmp    1484 <main+0x2b4>
nopl   0x0(%rax)
lea    0xcec(%rip),%rdi
call   1040 <puts@plt>
mov    $0xffffffff,%ebp
jmp    1240 <main+0x70>
lea    0xbd7(%rip),%rdi
call   10f0 <perror@plt>
jmp    145c <main+0x28c>
lea    0xbe7(%rip),%rdi
jmp    1484 <main+0x2b4>
lea    0xc27(%rip),%rdi
call   10f0 <perror@plt>
jmp    1240 <main+0x70>
mov    0x2b43(%rip),%rax
mov    (%rax),%edi
mov    (%rsi),%rdx
lea    0xb73(%rip),%rsi
call   10c0 <fprintf@plt>
mov    $0x1,%eax
jmp    14af <main+0x2df>
xor    %eax,%eax
add    $0xa8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [30 x i8] c"Usage: %s <device file name>\0A\00"
@.str.1 = [9 x i8] c"1: Open\0A\00"
@.str.2 = [9 x i8] c"2: Read\0A\00"
@.str.3 = [10 x i8] c"3: Write\0A\00"
@.str.4 = [10 x i8] c"4: Close\0A\00"
@.str.5 = [9 x i8] c"5: Seek\0A\00"
@.str.6 = [9 x i8] c"0: Exit\0A\00"
@.str.7 = [15 x i8] c"Enter choice: \00"
@.str.8 = [3 x i8] c"%d\00"
@O_RDWR = global i32 0
@.str.9 = [14 x i8] c"file_ops open\00"
@.str.10 = [15 x i8] c"File not open\0A\00"
@.str.11 = [16 x i8] c"Bytes to read: \00"
@.str.12 = [14 x i8] c"file_ops read\00"
@.str.13 = [22 x i8] c"Read %d bytes in %p: \00"
@.str.14 = [11 x i8] c"%c (%02X) \00"
@.str.15 = [2 x i8] c"\0A\00"
@.str.16 = [20 x i8] c"Enter your string: \00"
@.str.17 = [6 x i8] c"%[^\0A]\00"
@.str.18 = [15 x i8] c"file_ops write\00"
@.str.19 = [24 x i8] c"Wrote %d bytes from %p\0A\00"
@.str.20 = [43 x i8] c"Enter the seek from start of device file: \00"
@.str.21 = [5 x i8] c"%lld\00"
@SEEK_SET = global i32 0
@.str.22 = [15 x i8] c"file_ops lseek\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca [128 x i8]
%10 = alloca i32
%11 = alloca i32
%12 = alloca i8
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 -1, i32* %8
%13 = load i32, i32* %4
%14 = icmp ne i32 %13, 2
br i1 %14, label %15, label %21
15: ; preds = %2
%16 = load i32, i32* @stderr
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 0
%19 = load i8*, i8** %18
%20 = call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i8* %19)
store i32 1, i32* %3
br label %141
21: ; preds = %2
%22 = load i8**, i8*** %5
%23 = getelementptr inbounds i8*, i8** %22, i64 1
%24 = load i8*, i8** %23
store i8* %24, i8** %6
br label %25
25: ; preds = %21
br label %26
26: ; preds = %137, %25
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0))
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0))
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0))
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0))
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.6, i64 0, i64 0))
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.7, i64 0, i64 0))
%34 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.8, i64 0, i64 0), i32* %7)
%35 = call i32 (...) @getchar()
%36 = load i32, i32* %7
switch i32 %36, label %136 [
i32 1, label %37
i32 2, label %46
i32 3, label %88
i32 4, label %111
i32 5, label %119
]
37: ; preds = %26
%38 = load i8*, i8** %6
%39 = load i32, i32* @O_RDWR
%40 = call i32 @open(i8* %38, i32 %39)
store i32 %40, i32* %8
%41 = load i32, i32* %8
%42 = icmp eq i32 %41, -1
br i1 %42, label %43, label %45
43: ; preds = %37
%44 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.9, i64 0, i64 0))
br label %45
45: ; preds = %43, %37
br label %136
46: ; preds = %26
%47 = load i32, i32* %8
%48 = icmp eq i32 %47, -1
br i1 %48, label %49, label %51
49: ; preds = %46
%50 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.10, i64 0, i64 0))
br label %136
51: ; preds = %46
%52 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.11, i64 0, i64 0))
%53 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.8, i64 0, i64 0), i32* %10)
%54 = call i32 (...) @getchar()
%55 = load i32, i32* %8
%56 = getelementptr inbounds [128 x i8], [128 x i8]* %9, i64 0, i64 0
%57 = load i32, i32* %10
%58 = call i32 @read(i32 %55, i8* %56, i32 %57)
store i32 %58, i32* %10
%59 = load i32, i32* %10
%60 = icmp eq i32 %59, -1
br i1 %60, label %61, label %63
61: ; preds = %51
%62 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.12, i64 0, i64 0))
br label %136
63: ; preds = %51
%64 = load i32, i32* %10
%65 = getelementptr inbounds [128 x i8], [128 x i8]* %9, i64 0, i64 0
%66 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.13, i64 0, i64 0), i32 %64, i8* %65)
store i32 0, i32* %11
br label %67
67: ; preds = %83, %63
%68 = load i32, i32* %11
%69 = load i32, i32* %10
%70 = icmp slt i32 %68, %69
br i1 %70, label %71, label %86
71: ; preds = %67
%72 = load i32, i32* %11
%73 = sext i32 %72 to i64
%74 = getelementptr inbounds [128 x i8], [128 x i8]* %9, i64 0, i64 %73
%75 = load i8, i8* %74
%76 = zext i8 %75 to i32
%77 = load i32, i32* %11
%78 = sext i32 %77 to i64
%79 = getelementptr inbounds [128 x i8], [128 x i8]* %9, i64 0, i64 %78
%80 = load i8, i8* %79
%81 = zext i8 %80 to i32
%82 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.14, i64 0, i64 0), i32 %76, i32 %81)
br label %83
83: ; preds = %71
%84 = load i32, i32* %11
%85 = add nsw i32 %84, 1
store i32 %85, i32* %11
br label %67
86: ; preds = %67
%87 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.15, i64 0, i64 0))
br label %136
88: ; preds = %26
%89 = load i32, i32* %8
%90 = icmp eq i32 %89, -1
br i1 %90, label %91, label %93
91: ; preds = %88
%92 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.10, i64 0, i64 0))
br label %136
93: ; preds = %88
%94 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.16, i64 0, i64 0))
%95 = getelementptr inbounds [128 x i8], [128 x i8]* %9, i64 0, i64 0
%96 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.17, i64 0, i64 0), i8* %95)
%97 = call i32 (...) @getchar()
%98 = load i32, i32* %8
%99 = getelementptr inbounds [128 x i8], [128 x i8]* %9, i64 0, i64 0
%100 = getelementptr inbounds [128 x i8], [128 x i8]* %9, i64 0, i64 0
%101 = call i32 @strlen(i8* %100)
%102 = call i32 @write(i32 %98, i8* %99, i32 %101)
store i32 %102, i32* %10
%103 = load i32, i32* %10
%104 = icmp eq i32 %103, -1
br i1 %104, label %105, label %107
105: ; preds = %93
%106 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.18, i64 0, i64 0))
br label %136
107: ; preds = %93
%108 = load i32, i32* %10
%109 = getelementptr inbounds [128 x i8], [128 x i8]* %9, i64 0, i64 0
%110 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.19, i64 0, i64 0), i32 %108, i8* %109)
br label %136
111: ; preds = %26
%112 = load i32, i32* %8
%113 = icmp eq i32 %112, -1
br i1 %113, label %114, label %116
114: ; preds = %111
%115 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.10, i64 0, i64 0))
br label %136
116: ; preds = %111
%117 = load i32, i32* %8
%118 = call i32 @close(i32 %117)
store i32 -1, i32* %8
br label %136
119: ; preds = %26
%120 = load i32, i32* %8
%121 = icmp eq i32 %120, -1
br i1 %121, label %122, label %124
122: ; preds = %119
%123 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.10, i64 0, i64 0))
br label %136
124: ; preds = %119
%125 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.20, i64 0, i64 0))
%126 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.21, i64 0, i64 0), i8* %12)
%127 = call i32 (...) @getchar()
%128 = load i32, i32* %8
%129 = load i8, i8* %12
%130 = load i32, i32* @SEEK_SET
%131 = call i32 @lseek(i32 %128, i8 zeroext %129, i32 %130)
%132 = icmp eq i32 %131, -1
br i1 %132, label %133, label %135
133: ; preds = %124
%134 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.22, i64 0, i64 0))
br label %136
135: ; preds = %124
br label %136
136: ; preds = %26, %135, %133, %122, %116, %114, %107, %105, %91, %86, %61, %49, %45
br label %137
137: ; preds = %136
%138 = load i32, i32* %7
%139 = icmp ne i32 %138, 0
br i1 %139, label %26, label %140
140: ; preds = %137
store i32 0, i32* %3
br label %141
141: ; preds = %140, %15
%142 = load i32, i32* %3
ret i32 %142
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [30 x i8] c"Usage: %s <device file name>\0A\00"
@.str.7 = [15 x i8] c"Enter choice: \00"
@.str.8 = [3 x i8] c"%d\00"
@O_RDWR = global i32 0
@.str.9 = [14 x i8] c"file_ops open\00"
@.str.11 = [16 x i8] c"Bytes to read: \00"
@.str.12 = [14 x i8] c"file_ops read\00"
@.str.13 = [22 x i8] c"Read %d bytes in %p: \00"
@.str.14 = [11 x i8] c"%c (%02X) \00"
@.str.16 = [20 x i8] c"Enter your string: \00"
@.str.17 = [6 x i8] c"%[^\0A]\00"
@.str.18 = [15 x i8] c"file_ops write\00"
@.str.19 = [24 x i8] c"Wrote %d bytes from %p\0A\00"
@.str.20 = [43 x i8] c"Enter the seek from start of device file: \00"
@.str.21 = [5 x i8] c"%lld\00"
@SEEK_SET = global i32 0
@.str.22 = [15 x i8] c"file_ops lseek\00"
@str = [8 x i8] c"1: Open\00"
@str.23 = [8 x i8] c"2: Read\00"
@str.24 = [9 x i8] c"3: Write\00"
@str.25 = [9 x i8] c"4: Close\00"
@str.26 = [8 x i8] c"5: Seek\00"
@str.27 = [8 x i8] c"0: Exit\00"
@str.31 = [14 x i8] c"File not open\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = alloca [128 x i8]
%5 = alloca i32
%6 = alloca i8
%7 = bitcast i32* %3 to i8*
%8 = getelementptr inbounds [128 x i8], [128 x i8]* %4, i64 0, i64 0
%9 = bitcast i32* %5 to i8*
%10 = icmp eq i32 %0, 2
br i1 %10, label %15, label %11
11: ; preds = %2
%12 = load i32, i32* @stderr
%13 = load i8*, i8** %1
%14 = tail call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i8* %13)
br label %107
15: ; preds = %2
%16 = getelementptr inbounds i8*, i8** %1, i64 1
%17 = load i8*, i8** %16
br label %18
18: ; preds = %103, %15
%19 = phi i32 [ -1, %15 ], [ %105, %103 ]
%20 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @str, i64 0, i64 0))
%21 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @str.23, i64 0, i64 0))
%22 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @str.24, i64 0, i64 0))
%23 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @str.25, i64 0, i64 0))
%24 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @str.26, i64 0, i64 0))
%25 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @str.27, i64 0, i64 0))
%26 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.7, i64 0, i64 0))
%27 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.8, i64 0, i64 0), i32* %3)
%28 = call i32 (...) @getchar()
%29 = load i32, i32* %3
switch i32 %29, label %103 [
i32 1, label %30
i32 2, label %36
i32 3, label %65
i32 4, label %80
i32 5, label %86
]
30: ; preds = %18
%31 = load i32, i32* @O_RDWR
%32 = call i32 @open(i8* %17, i32 %31)
%33 = icmp eq i32 %32, -1
br i1 %33, label %34, label %100
34: ; preds = %30
%35 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.9, i64 0, i64 0))
br label %100
36: ; preds = %18
%37 = icmp eq i32 %19, -1
br i1 %37, label %38, label %40
38: ; preds = %36
%39 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @str.31, i64 0, i64 0))
br label %100
40: ; preds = %36
%41 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.11, i64 0, i64 0))
%42 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.8, i64 0, i64 0), i32* %5)
%43 = call i32 (...) @getchar()
%44 = load i32, i32* %5
%45 = call i32 @read(i32 %19, i8* %8, i32 %44)
store i32 %45, i32* %5
%46 = icmp eq i32 %45, -1
br i1 %46, label %47, label %49
47: ; preds = %40
%48 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.12, i64 0, i64 0))
br label %100
49: ; preds = %40
%50 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.13, i64 0, i64 0), i32 %45, i8* %8)
%51 = load i32, i32* %5
%52 = icmp sgt i32 %51, 0
br i1 %52, label %53, label %63
53: ; preds = %49, %53
%54 = phi i64 [ %59, %53 ], [ 0, %49 ]
%55 = getelementptr inbounds [128 x i8], [128 x i8]* %4, i64 0, i64 %54
%56 = load i8, i8* %55
%57 = zext i8 %56 to i32
%58 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.14, i64 0, i64 0), i32 %57, i32 %57)
%59 = add nuw nsw i64 %54, 1
%60 = load i32, i32* %5
%61 = sext i32 %60 to i64
%62 = icmp slt i64 %59, %61
br i1 %62, label %53, label %63
63: ; preds = %53, %49
%64 = call i32 @putchar(i32 10)
br label %100
65: ; preds = %18
%66 = icmp eq i32 %19, -1
br i1 %66, label %67, label %69
67: ; preds = %65
%68 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @str.31, i64 0, i64 0))
br label %100
69: ; preds = %65
%70 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.16, i64 0, i64 0))
%71 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.17, i64 0, i64 0), i8* %8)
%72 = call i32 (...) @getchar()
%73 = call i32 @strlen(i8* %8)
%74 = call i32 @write(i32 %19, i8* %8, i32 %73)
store i32 %74, i32* %5
%75 = icmp eq i32 %74, -1
br i1 %75, label %76, label %78
76: ; preds = %69
%77 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.18, i64 0, i64 0))
br label %100
78: ; preds = %69
%79 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.19, i64 0, i64 0), i32 %74, i8* %8)
br label %100
80: ; preds = %18
%81 = icmp eq i32 %19, -1
br i1 %81, label %82, label %84
82: ; preds = %80
%83 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @str.31, i64 0, i64 0))
br label %100
84: ; preds = %80
%85 = call i32 @close(i32 %19)
br label %100
86: ; preds = %18
%87 = icmp eq i32 %19, -1
br i1 %87, label %88, label %90
88: ; preds = %86
%89 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @str.31, i64 0, i64 0))
br label %100
90: ; preds = %86
%91 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([43 x i8], [43 x i8]* @.str.20, i64 0, i64 0))
%92 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.21, i64 0, i64 0), i8* %6)
%93 = call i32 (...) @getchar()
%94 = load i8, i8* %6
%95 = load i32, i32* @SEEK_SET
%96 = call i32 @lseek(i32 %19, i8 zeroext %94, i32 %95)
%97 = icmp eq i32 %96, -1
br i1 %97, label %98, label %100
98: ; preds = %90
%99 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.22, i64 0, i64 0))
br label %100
100: ; preds = %90, %30, %34, %98, %88, %84, %82, %78, %76, %67, %63, %47, %38
%101 = phi i32 [ %32, %30 ], [ -1, %34 ], [ %19, %63 ], [ %19, %47 ], [ -1, %38 ], [ %19, %78 ], [ %19, %76 ], [ -1, %67 ], [ -1, %84 ], [ -1, %82 ], [ %19, %90 ], [ %19, %98 ], [ -1, %88 ]
%102 = load i32, i32* %3
br label %103
103: ; preds = %100, %18
%104 = phi i32 [ %102, %100 ], [ %29, %18 ]
%105 = phi i32 [ %101, %100 ], [ %19, %18 ]
%106 = icmp eq i32 %104, 0
br i1 %106, label %107, label %18
107: ; preds = %103, %11
%108 = phi i32 [ 1, %11 ], [ 0, %103 ]
ret i32 %108
}