#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 int ssize_t;

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int EXIT_SUCCESS;
int O_EXCL;
int O_RDWR;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int ioctl(int, int, char *);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int open(char *, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ putchar(char);
int read(int, char *, int);
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ stdout;
scalar_t__ strcmp(char *, char *);
int /*<<< orphan*/ strlen(char *);
int /*<<< orphan*/ usage();
int write(int, char *, int /*<<< orphan*/);
int main(int argc, char *argv[]) {
  if (argc != 2)
    usage();
  char buf[256];
  memset(buf, 0, 256);
  int fd = open("/dev/char_driver", O_RDWR | O_EXCL);
  if (fd == -1) {
    perror("open");
    exit(EXIT_FAILURE);
  }
  ssize_t n = -1;
  if ((strcmp(argv[1], "-r") == 0) || (strcmp(argv[1], "-a") == 0)) {
    fprintf(stdout, "try to read data from %s\n", "/dev/char_driver");
    n = read(fd, buf, 256);
    if (n == -1) {
      perror("read");
      exit(EXIT_FAILURE);
    }
    fprintf(stdout, "read %d bytes \"%s\"\n", (int)n, buf);
    putchar('\n');
    sleep(1);
  }
  if ((strcmp(argv[1], "-w") == 0) || (strcmp(argv[1], "-a") == 0)) {
    fprintf(stdout, "try to write \"%s\" from %s\n",
            "this is a another test string with no real meaning",
            "/dev/char_driver");
    n = write(fd, "this is a another test string with no real meaning",
              strlen("this is a another test string with no real meaning"));
    if (n == -1) {
      perror("write");
      exit(EXIT_FAILURE);
    }
    fprintf(stdout, "wrote %d bytes \"%s\"\n", (int)n,
            "this is a another test string with no real meaning");
    putchar('\n');
    sleep(1);
  }
  if ((strcmp(argv[1], "-w") == 0) || (strcmp(argv[1], "-a") == 0)) {
    fprintf(stdout, "try to read data from %s\n", "/dev/char_driver");
    memset(buf, 0, 256);
    n = read(fd, buf, 256);
    if (n == -1) {
      perror("read");
      exit(EXIT_FAILURE);
    }
    fprintf(stdout, "read %d bytes \"%s\"\n", (int)n, buf);
    putchar('\n');
    sleep(1);
  }
  if ((strcmp(argv[1], "-i") == 0) || (strcmp(argv[1], "-a") == 0)) {
    int ret = ioctl(fd, 0x0001, "set via ioctl");
    if (ret == -1) {
      perror("ioctl");
      exit(EXIT_FAILURE);
    }
  }
  if ((strcmp(argv[1], "-i") == 0) || (strcmp(argv[1], "-a") == 0)) {
    fprintf(stdout, "try to read data from %s\n", "/dev/char_driver");
    memset(buf, 0, 256);
    n = read(fd, buf, 256);
    if (n == -1) {
      perror("read");
      exit(EXIT_FAILURE);
    }
    fprintf(stdout, "read %d bytes \"%s\"\n", (int)n, buf);
  }
  close(fd);
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x120,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     120a <main+0x2a>
mov    $0x0,%al
call   10c0 <usage@plt>
lea    -0x110(%rbp),%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1060 <memset@plt>
mov    0x2dc4(%rip),%rax
mov    (%rax),%esi
mov    0x2dab(%rip),%rax
or     (%rax),%esi
lea    0xdca(%rip),%rdi
call   10d0 <open@plt>
mov    %eax,-0x114(%rbp)
cmpl   $0xffffffff,-0x114(%rbp)
jne    1268 <main+0x88>
lea    0xdbc(%rip),%rdi
call   10e0 <perror@plt>
mov    0x2d6f(%rip),%rax
mov    (%rax),%edi
call   10f0 <exit@plt>
movl   $0xffffffff,-0x118(%rbp)
ff ff ff
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xd95(%rip),%rsi
call   10a0 <strcmp@plt>
cmp    $0x0,%rax
je     12ae <main+0xce>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xd7a(%rip),%rsi
call   10a0 <strcmp@plt>
cmp    $0x0,%rax
jne    1348 <main+0x168>
mov    0x2d13(%rip),%rax
mov    (%rax),%edi
lea    0xd5e(%rip),%rsi
lea    0xd3b(%rip),%rdx
mov    $0x0,%al
call   10b0 <fprintf@plt>
mov    -0x114(%rbp),%edi
lea    -0x110(%rbp),%rsi
mov    $0x100,%edx
call   1090 <read@plt>
mov    %eax,-0x118(%rbp)
cmpl   $0xffffffff,-0x118(%rbp)
jne    1310 <main+0x130>
lea    0xd39(%rip),%rdi
call   10e0 <perror@plt>
mov    0x2cc7(%rip),%rax
mov    (%rax),%edi
call   10f0 <exit@plt>
mov    0x2cb1(%rip),%rax
mov    (%rax),%edi
mov    -0x118(%rbp),%edx
lea    -0x110(%rbp),%rcx
lea    0xd0e(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    $0x1,%edi
call   1100 <sleep@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xcf8(%rip),%rsi
call   10a0 <strcmp@plt>
cmp    $0x0,%rax
je     1384 <main+0x1a4>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xca4(%rip),%rsi
call   10a0 <strcmp@plt>
cmp    $0x0,%rax
jne    143a <main+0x25a>
mov    0x2c3d(%rip),%rax
mov    (%rax),%edi
lea    0xcbe(%rip),%rsi
lea    0xcd2(%rip),%rdx
lea    0xc5e(%rip),%rcx
mov    $0x0,%al
call   10b0 <fprintf@plt>
mov    -0x114(%rbp),%eax
mov    %eax,-0x120(%rbp)
lea    0xcb1(%rip),%rdi
call   1050 <strlen@plt>
mov    -0x120(%rbp),%edi
mov    %eax,%edx
lea    0xc9d(%rip),%rsi
call   1040 <write@plt>
mov    %eax,-0x118(%rbp)
cmpl   $0xffffffff,-0x118(%rbp)
jne    1402 <main+0x222>
lea    0xcb1(%rip),%rdi
call   10e0 <perror@plt>
mov    0x2bd5(%rip),%rax
mov    (%rax),%edi
call   10f0 <exit@plt>
mov    0x2bbf(%rip),%rax
mov    (%rax),%edi
mov    -0x118(%rbp),%edx
lea    0xc8e(%rip),%rsi
lea    0xc4e(%rip),%rcx
mov    $0x0,%al
call   10b0 <fprintf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    $0x1,%edi
call   1100 <sleep@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xc06(%rip),%rsi
call   10a0 <strcmp@plt>
cmp    $0x0,%rax
je     1476 <main+0x296>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xbb2(%rip),%rsi
call   10a0 <strcmp@plt>
cmp    $0x0,%rax
jne    1523 <main+0x343>
mov    0x2b4b(%rip),%rax
mov    (%rax),%edi
lea    0xb96(%rip),%rsi
lea    0xb73(%rip),%rdx
mov    $0x0,%al
call   10b0 <fprintf@plt>
lea    -0x110(%rbp),%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1060 <memset@plt>
mov    -0x114(%rbp),%edi
lea    -0x110(%rbp),%rsi
mov    $0x100,%edx
call   1090 <read@plt>
mov    %eax,-0x118(%rbp)
cmpl   $0xffffffff,-0x118(%rbp)
jne    14eb <main+0x30b>
lea    0xb5e(%rip),%rdi
call   10e0 <perror@plt>
mov    0x2aec(%rip),%rax
mov    (%rax),%edi
call   10f0 <exit@plt>
mov    0x2ad6(%rip),%rax
mov    (%rax),%edi
mov    -0x118(%rbp),%edx
lea    -0x110(%rbp),%rcx
lea    0xb33(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    $0x1,%edi
call   1100 <sleep@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xb89(%rip),%rsi
call   10a0 <strcmp@plt>
cmp    $0x0,%rax
je     155f <main+0x37f>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xac9(%rip),%rsi
call   10a0 <strcmp@plt>
cmp    $0x0,%rax
jne    15a8 <main+0x3c8>
mov    -0x114(%rbp),%edi
mov    $0x1,%esi
lea    0xb4d(%rip),%rdx
call   1070 <ioctl@plt>
mov    %eax,-0x11c(%rbp)
cmpl   $0xffffffff,-0x11c(%rbp)
jne    15a3 <main+0x3c3>
lea    0xb36(%rip),%rdi
call   10e0 <perror@plt>
mov    0x2a34(%rip),%rax
mov    (%rax),%edi
call   10f0 <exit@plt>
jmp    15a8 <main+0x3c8>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xb04(%rip),%rsi
call   10a0 <strcmp@plt>
cmp    $0x0,%rax
je     15e4 <main+0x404>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xa44(%rip),%rsi
call   10a0 <strcmp@plt>
cmp    $0x0,%rax
jne    167d <main+0x49d>
mov    0x29dd(%rip),%rax
mov    (%rax),%edi
lea    0xa28(%rip),%rsi
lea    0xa05(%rip),%rdx
mov    $0x0,%al
call   10b0 <fprintf@plt>
lea    -0x110(%rbp),%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1060 <memset@plt>
mov    -0x114(%rbp),%edi
lea    -0x110(%rbp),%rsi
mov    $0x100,%edx
call   1090 <read@plt>
mov    %eax,-0x118(%rbp)
cmpl   $0xffffffff,-0x118(%rbp)
jne    1659 <main+0x479>
lea    0x9f0(%rip),%rdi
call   10e0 <perror@plt>
mov    0x297e(%rip),%rax
mov    (%rax),%edi
call   10f0 <exit@plt>
mov    0x2968(%rip),%rax
mov    (%rax),%edi
mov    -0x118(%rbp),%edx
lea    -0x110(%rbp),%rcx
lea    0x9c5(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
mov    -0x114(%rbp),%edi
call   1080 <close@plt>
mov    0x2931(%rip),%rax
mov    (%rax),%eax
add    $0x120,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x108,%rsp
mov    %rsi,%rbx
cmp    $0x2,%edi
je     11fc <main+0x1c>
xor    %eax,%eax
call   10c0 <usage@plt>
mov    %rsp,%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1060 <memset@plt>
mov    0x2dd6(%rip),%rax
mov    0x2dbf(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
lea    0xddc(%rip),%rdi
call   10d0 <open@plt>
cmp    $0xffffffff,%eax
je     14f3 <main+0x313>
mov    %eax,%r14d
mov    0x8(%rbx),%rdi
lea    0xdd6(%rip),%rsi
call   10a0 <strcmp@plt>
test   %rax,%rax
je     125f <main+0x7f>
mov    0x8(%rbx),%rdi
lea    0xdc4(%rip),%rsi
call   10a0 <strcmp@plt>
test   %rax,%rax
jne    12c1 <main+0xe1>
mov    0x2d62(%rip),%rbp
mov    0x0(%rbp),%edi
lea    0xdac(%rip),%rsi
lea    0xd89(%rip),%rdx
xor    %eax,%eax
call   10b0 <fprintf@plt>
mov    %rsp,%rsi
mov    %r14d,%edi
mov    $0x100,%edx
call   1090 <read@plt>
cmp    $0xffffffff,%eax
je     14ea <main+0x30a>
mov    0x0(%rbp),%edi
lea    0xd9a(%rip),%rsi
mov    %rsp,%rcx
mov    %eax,%edx
xor    %eax,%eax
call   10b0 <fprintf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    $0x1,%edi
call   1100 <sleep@plt>
mov    0x8(%rbx),%rdi
lea    0xd83(%rip),%rsi
call   10a0 <strcmp@plt>
test   %rax,%rax
je     12eb <main+0x10b>
mov    0x8(%rbx),%rdi
lea    0xd38(%rip),%rsi
call   10a0 <strcmp@plt>
test   %rax,%rax
jne    1360 <main+0x180>
mov    0x2cd6(%rip),%r15
mov    (%r15),%edi
lea    0xd56(%rip),%rsi
lea    0xd6a(%rip),%rbp
lea    0xcf6(%rip),%rcx
mov    %rbp,%rdx
xor    %eax,%eax
call   10b0 <fprintf@plt>
mov    %rbp,%rdi
call   1050 <strlen@plt>
mov    %r14d,%edi
mov    %rbp,%rsi
mov    %eax,%edx
call   1040 <write@plt>
cmp    $0xffffffff,%eax
je     14fc <main+0x31c>
mov    (%r15),%edi
lea    0xd6a(%rip),%rsi
lea    0xd2a(%rip),%rcx
mov    %eax,%edx
xor    %eax,%eax
call   10b0 <fprintf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    $0x1,%edi
call   1100 <sleep@plt>
mov    0x8(%rbx),%rdi
lea    0xce4(%rip),%rsi
call   10a0 <strcmp@plt>
test   %rax,%rax
je     138a <main+0x1aa>
mov    0x8(%rbx),%rdi
lea    0xc99(%rip),%rsi
call   10a0 <strcmp@plt>
test   %rax,%rax
jne    13fe <main+0x21e>
mov    0x2c37(%rip),%r15
mov    (%r15),%edi
lea    0xc81(%rip),%rsi
lea    0xc5e(%rip),%rdx
xor    %eax,%eax
call   10b0 <fprintf@plt>
mov    %rsp,%rbp
mov    %rbp,%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1060 <memset@plt>
mov    %r14d,%edi
mov    %rbp,%rsi
mov    $0x100,%edx
call   1090 <read@plt>
cmp    $0xffffffff,%eax
je     14ea <main+0x30a>
mov    (%r15),%edi
lea    0xc5d(%rip),%rsi
mov    %rsp,%rcx
mov    %eax,%edx
xor    %eax,%eax
call   10b0 <fprintf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    $0x1,%edi
call   1100 <sleep@plt>
mov    0x8(%rbx),%rdi
lea    0xcb2(%rip),%rsi
call   10a0 <strcmp@plt>
test   %rax,%rax
je     1428 <main+0x248>
mov    0x8(%rbx),%rdi
lea    0xbfb(%rip),%rsi
call   10a0 <strcmp@plt>
test   %rax,%rax
jne    1445 <main+0x265>
lea    0xc8f(%rip),%rdx
mov    %r14d,%edi
mov    $0x1,%esi
call   1070 <ioctl@plt>
cmp    $0xffffffff,%eax
je     1505 <main+0x325>
mov    0x8(%rbx),%rdi
lea    0xc6b(%rip),%rsi
call   10a0 <strcmp@plt>
test   %rax,%rax
je     146f <main+0x28f>
mov    0x8(%rbx),%rdi
lea    0xbb4(%rip),%rsi
call   10a0 <strcmp@plt>
test   %rax,%rax
jne    14cb <main+0x2eb>
mov    0x2b52(%rip),%rbp
mov    0x0(%rbp),%edi
lea    0xb9c(%rip),%rsi
lea    0xb79(%rip),%rdx
xor    %eax,%eax
call   10b0 <fprintf@plt>
mov    %rsp,%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1060 <memset@plt>
mov    %r14d,%edi
mov    %rbx,%rsi
mov    $0x100,%edx
call   1090 <read@plt>
cmp    $0xffffffff,%eax
je     14ea <main+0x30a>
mov    0x0(%rbp),%edi
lea    0xb7c(%rip),%rsi
mov    %rsp,%rcx
mov    %eax,%edx
xor    %eax,%eax
call   10b0 <fprintf@plt>
mov    %r14d,%edi
call   1080 <close@plt>
mov    0x2ae6(%rip),%rax
mov    (%rax),%eax
add    $0x108,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xb45(%rip),%rdi
jmp    150c <main+0x32c>
lea    0xb17(%rip),%rdi
jmp    150c <main+0x32c>
lea    0xb9d(%rip),%rdi
jmp    150c <main+0x32c>
lea    0xbba(%rip),%rdi
call   10e0 <perror@plt>
mov    0x2ab8(%rip),%rax
mov    (%rax),%edi
call   10f0 <exit@plt>

LLVM IR (-O0):
@.str = [17 x i8] c"/dev/char_driver\00"
@O_RDWR = global i32 0
@O_EXCL = global i32 0
@.str.1 = [5 x i8] c"open\00"
@EXIT_FAILURE = global i32 0
@.str.2 = [3 x i8] c"-r\00"
@.str.3 = [3 x i8] c"-a\00"
@stdout = global i32 0
@.str.4 = [26 x i8] c"try to read data from %s\0A\00"
@.str.5 = [5 x i8] c"read\00"
@.str.6 = [20 x i8] c"read %d bytes \22%s\22\0A\00"
@.str.7 = [3 x i8] c"-w\00"
@.str.8 = [27 x i8] c"try to write \22%s\22 from %s\0A\00"
@.str.9 = [51 x i8] c"this is a another test string with no real meaning\00"
@.str.10 = [6 x i8] c"write\00"
@.str.11 = [21 x i8] c"wrote %d bytes \22%s\22\0A\00"
@.str.12 = [3 x i8] c"-i\00"
@.str.13 = [14 x i8] c"set via ioctl\00"
@.str.14 = [6 x i8] c"ioctl\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [256 x i8]
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* %4
%11 = icmp ne i32 %10, 2
br i1 %11, label %12, label %14
12: ; preds = %2
%13 = call i32 (...) @usage()
br label %14
14: ; preds = %12, %2
%15 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%16 = call i32 @memset(i8* %15, i32 0, i32 256)
%17 = load i32, i32* @O_RDWR
%18 = load i32, i32* @O_EXCL
%19 = or i32 %17, %18
%20 = call i32 @open(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i32 %19)
store i32 %20, i32* %7
%21 = load i32, i32* %7
%22 = icmp eq i32 %21, -1
br i1 %22, label %23, label %27
23: ; preds = %14
%24 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%25 = load i32, i32* @EXIT_FAILURE
%26 = call i32 @exit(i32 %25)
unreachable
27: ; preds = %14
store i32 -1, i32* %8
%28 = load i8**, i8*** %5
%29 = getelementptr inbounds i8*, i8** %28, i64 1
%30 = load i8*, i8** %29
%31 = call i64 @strcmp(i8* %30, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%32 = icmp eq i64 %31, 0
br i1 %32, label %39, label %33
33: ; preds = %27
%34 = load i8**, i8*** %5
%35 = getelementptr inbounds i8*, i8** %34, i64 1
%36 = load i8*, i8** %35
%37 = call i64 @strcmp(i8* %36, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%38 = icmp eq i64 %37, 0
br i1 %38, label %39, label %58
39: ; preds = %33, %27
%40 = load i32, i32* @stdout
%41 = call i32 (i32, i8*, ...) @fprintf(i32 %40, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
%42 = load i32, i32* %7
%43 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%44 = call i32 @read(i32 %42, i8* %43, i32 256)
store i32 %44, i32* %8
%45 = load i32, i32* %8
%46 = icmp eq i32 %45, -1
br i1 %46, label %47, label %51
47: ; preds = %39
%48 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
%49 = load i32, i32* @EXIT_FAILURE
%50 = call i32 @exit(i32 %49)
unreachable
51: ; preds = %39
%52 = load i32, i32* @stdout
%53 = load i32, i32* %8
%54 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%55 = call i32 (i32, i8*, ...) @fprintf(i32 %52, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.6, i64 0, i64 0), i32 %53, i8* %54)
%56 = call i32 @putchar(i8 signext 10)
%57 = call i32 @sleep(i32 1)
br label %58
58: ; preds = %51, %33
%59 = load i8**, i8*** %5
%60 = getelementptr inbounds i8*, i8** %59, i64 1
%61 = load i8*, i8** %60
%62 = call i64 @strcmp(i8* %61, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0))
%63 = icmp eq i64 %62, 0
br i1 %63, label %70, label %64
64: ; preds = %58
%65 = load i8**, i8*** %5
%66 = getelementptr inbounds i8*, i8** %65, i64 1
%67 = load i8*, i8** %66
%68 = call i64 @strcmp(i8* %67, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%69 = icmp eq i64 %68, 0
br i1 %69, label %70, label %88
70: ; preds = %64, %58
%71 = load i32, i32* @stdout
%72 = call i32 (i32, i8*, ...) @fprintf(i32 %71, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.8, i64 0, i64 0), i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.9, i64 0, i64 0), i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
%73 = load i32, i32* %7
%74 = call i32 @strlen(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.9, i64 0, i64 0))
%75 = call i32 @write(i32 %73, i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.9, i64 0, i64 0), i32 %74)
store i32 %75, i32* %8
%76 = load i32, i32* %8
%77 = icmp eq i32 %76, -1
br i1 %77, label %78, label %82
78: ; preds = %70
%79 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.10, i64 0, i64 0))
%80 = load i32, i32* @EXIT_FAILURE
%81 = call i32 @exit(i32 %80)
unreachable
82: ; preds = %70
%83 = load i32, i32* @stdout
%84 = load i32, i32* %8
%85 = call i32 (i32, i8*, ...) @fprintf(i32 %83, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.11, i64 0, i64 0), i32 %84, i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.9, i64 0, i64 0))
%86 = call i32 @putchar(i8 signext 10)
%87 = call i32 @sleep(i32 1)
br label %88
88: ; preds = %82, %64
%89 = load i8**, i8*** %5
%90 = getelementptr inbounds i8*, i8** %89, i64 1
%91 = load i8*, i8** %90
%92 = call i64 @strcmp(i8* %91, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0))
%93 = icmp eq i64 %92, 0
br i1 %93, label %100, label %94
94: ; preds = %88
%95 = load i8**, i8*** %5
%96 = getelementptr inbounds i8*, i8** %95, i64 1
%97 = load i8*, i8** %96
%98 = call i64 @strcmp(i8* %97, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%99 = icmp eq i64 %98, 0
br i1 %99, label %100, label %121
100: ; preds = %94, %88
%101 = load i32, i32* @stdout
%102 = call i32 (i32, i8*, ...) @fprintf(i32 %101, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
%103 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%104 = call i32 @memset(i8* %103, i32 0, i32 256)
%105 = load i32, i32* %7
%106 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%107 = call i32 @read(i32 %105, i8* %106, i32 256)
store i32 %107, i32* %8
%108 = load i32, i32* %8
%109 = icmp eq i32 %108, -1
br i1 %109, label %110, label %114
110: ; preds = %100
%111 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
%112 = load i32, i32* @EXIT_FAILURE
%113 = call i32 @exit(i32 %112)
unreachable
114: ; preds = %100
%115 = load i32, i32* @stdout
%116 = load i32, i32* %8
%117 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%118 = call i32 (i32, i8*, ...) @fprintf(i32 %115, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.6, i64 0, i64 0), i32 %116, i8* %117)
%119 = call i32 @putchar(i8 signext 10)
%120 = call i32 @sleep(i32 1)
br label %121
121: ; preds = %114, %94
%122 = load i8**, i8*** %5
%123 = getelementptr inbounds i8*, i8** %122, i64 1
%124 = load i8*, i8** %123
%125 = call i64 @strcmp(i8* %124, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.12, i64 0, i64 0))
%126 = icmp eq i64 %125, 0
br i1 %126, label %133, label %127
127: ; preds = %121
%128 = load i8**, i8*** %5
%129 = getelementptr inbounds i8*, i8** %128, i64 1
%130 = load i8*, i8** %129
%131 = call i64 @strcmp(i8* %130, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%132 = icmp eq i64 %131, 0
br i1 %132, label %133, label %143
133: ; preds = %127, %121
%134 = load i32, i32* %7
%135 = call i32 @ioctl(i32 %134, i32 1, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.13, i64 0, i64 0))
store i32 %135, i32* %9
%136 = load i32, i32* %9
%137 = icmp eq i32 %136, -1
br i1 %137, label %138, label %142
138: ; preds = %133
%139 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.14, i64 0, i64 0))
%140 = load i32, i32* @EXIT_FAILURE
%141 = call i32 @exit(i32 %140)
unreachable
142: ; preds = %133
br label %143
143: ; preds = %142, %127
%144 = load i8**, i8*** %5
%145 = getelementptr inbounds i8*, i8** %144, i64 1
%146 = load i8*, i8** %145
%147 = call i64 @strcmp(i8* %146, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.12, i64 0, i64 0))
%148 = icmp eq i64 %147, 0
br i1 %148, label %155, label %149
149: ; preds = %143
%150 = load i8**, i8*** %5
%151 = getelementptr inbounds i8*, i8** %150, i64 1
%152 = load i8*, i8** %151
%153 = call i64 @strcmp(i8* %152, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%154 = icmp eq i64 %153, 0
br i1 %154, label %155, label %174
155: ; preds = %149, %143
%156 = load i32, i32* @stdout
%157 = call i32 (i32, i8*, ...) @fprintf(i32 %156, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
%158 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%159 = call i32 @memset(i8* %158, i32 0, i32 256)
%160 = load i32, i32* %7
%161 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%162 = call i32 @read(i32 %160, i8* %161, i32 256)
store i32 %162, i32* %8
%163 = load i32, i32* %8
%164 = icmp eq i32 %163, -1
br i1 %164, label %165, label %169
165: ; preds = %155
%166 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
%167 = load i32, i32* @EXIT_FAILURE
%168 = call i32 @exit(i32 %167)
unreachable
169: ; preds = %155
%170 = load i32, i32* @stdout
%171 = load i32, i32* %8
%172 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%173 = call i32 (i32, i8*, ...) @fprintf(i32 %170, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.6, i64 0, i64 0), i32 %171, i8* %172)
br label %174
174: ; preds = %169, %149
%175 = load i32, i32* %7
%176 = call i32 @close(i32 %175)
%177 = load i32, i32* @EXIT_SUCCESS
ret i32 %177
}

LLVM IR (-O2):
@.str = [17 x i8] c"/dev/char_driver\00"
@O_RDWR = global i32 0
@O_EXCL = global i32 0
@.str.1 = [5 x i8] c"open\00"
@EXIT_FAILURE = global i32 0
@.str.2 = [3 x i8] c"-r\00"
@.str.3 = [3 x i8] c"-a\00"
@stdout = global i32 0
@.str.4 = [26 x i8] c"try to read data from %s\0A\00"
@.str.5 = [5 x i8] c"read\00"
@.str.6 = [20 x i8] c"read %d bytes \22%s\22\0A\00"
@.str.7 = [3 x i8] c"-w\00"
@.str.8 = [27 x i8] c"try to write \22%s\22 from %s\0A\00"
@.str.9 = [51 x i8] c"this is a another test string with no real meaning\00"
@.str.10 = [6 x i8] c"write\00"
@.str.11 = [21 x i8] c"wrote %d bytes \22%s\22\0A\00"
@.str.12 = [3 x i8] c"-i\00"
@.str.13 = [14 x i8] c"set via ioctl\00"
@.str.14 = [6 x i8] c"ioctl\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [256 x i8]
%4 = icmp eq i32 %0, 2
br i1 %4, label %7, label %5
5: ; preds = %2
%6 = tail call i32 (...) @usage()
br label %7
7: ; preds = %5, %2
%8 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%9 = call i32 @memset(i8* %8, i32 0, i32 256)
%10 = load i32, i32* @O_RDWR
%11 = load i32, i32* @O_EXCL
%12 = or i32 %11, %10
%13 = call i32 @open(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i32 %12)
%14 = icmp eq i32 %13, -1
br i1 %14, label %15, label %19
15: ; preds = %7
%16 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%17 = load i32, i32* @EXIT_FAILURE
%18 = call i32 @exit(i32 %17)
unreachable
19: ; preds = %7
%20 = getelementptr inbounds i8*, i8** %1, i64 1
%21 = load i8*, i8** %20
%22 = call i64 @strcmp(i8* %21, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%23 = icmp eq i64 %22, 0
br i1 %23, label %28, label %24
24: ; preds = %19
%25 = load i8*, i8** %20
%26 = call i64 @strcmp(i8* %25, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%27 = icmp eq i64 %26, 0
br i1 %27, label %28, label %42
28: ; preds = %24, %19
%29 = load i32, i32* @stdout
%30 = call i32 (i32, i8*, ...) @fprintf(i32 %29, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
%31 = call i32 @read(i32 %13, i8* %8, i32 256)
%32 = icmp eq i32 %31, -1
br i1 %32, label %33, label %37
33: ; preds = %28
%34 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
%35 = load i32, i32* @EXIT_FAILURE
%36 = call i32 @exit(i32 %35)
unreachable
37: ; preds = %28
%38 = load i32, i32* @stdout
%39 = call i32 (i32, i8*, ...) @fprintf(i32 %38, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.6, i64 0, i64 0), i32 %31, i8* %8)
%40 = call i32 @putchar(i8 signext 10)
%41 = call i32 @sleep(i32 1)
br label %42
42: ; preds = %37, %24
%43 = load i8*, i8** %20
%44 = call i64 @strcmp(i8* %43, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0))
%45 = icmp eq i64 %44, 0
br i1 %45, label %50, label %46
46: ; preds = %42
%47 = load i8*, i8** %20
%48 = call i64 @strcmp(i8* %47, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%49 = icmp eq i64 %48, 0
br i1 %49, label %50, label %65
50: ; preds = %46, %42
%51 = load i32, i32* @stdout
%52 = call i32 (i32, i8*, ...) @fprintf(i32 %51, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.8, i64 0, i64 0), i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.9, i64 0, i64 0), i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
%53 = call i32 @strlen(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.9, i64 0, i64 0))
%54 = call i32 @write(i32 %13, i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.9, i64 0, i64 0), i32 %53)
%55 = icmp eq i32 %54, -1
br i1 %55, label %56, label %60
56: ; preds = %50
%57 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.10, i64 0, i64 0))
%58 = load i32, i32* @EXIT_FAILURE
%59 = call i32 @exit(i32 %58)
unreachable
60: ; preds = %50
%61 = load i32, i32* @stdout
%62 = call i32 (i32, i8*, ...) @fprintf(i32 %61, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.11, i64 0, i64 0), i32 %54, i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.9, i64 0, i64 0))
%63 = call i32 @putchar(i8 signext 10)
%64 = call i32 @sleep(i32 1)
br label %65
65: ; preds = %60, %46
%66 = load i8*, i8** %20
%67 = call i64 @strcmp(i8* %66, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0))
%68 = icmp eq i64 %67, 0
br i1 %68, label %73, label %69
69: ; preds = %65
%70 = load i8*, i8** %20
%71 = call i64 @strcmp(i8* %70, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%72 = icmp eq i64 %71, 0
br i1 %72, label %73, label %88
73: ; preds = %69, %65
%74 = load i32, i32* @stdout
%75 = call i32 (i32, i8*, ...) @fprintf(i32 %74, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
%76 = call i32 @memset(i8* %8, i32 0, i32 256)
%77 = call i32 @read(i32 %13, i8* %8, i32 256)
%78 = icmp eq i32 %77, -1
br i1 %78, label %79, label %83
79: ; preds = %73
%80 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
%81 = load i32, i32* @EXIT_FAILURE
%82 = call i32 @exit(i32 %81)
unreachable
83: ; preds = %73
%84 = load i32, i32* @stdout
%85 = call i32 (i32, i8*, ...) @fprintf(i32 %84, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.6, i64 0, i64 0), i32 %77, i8* %8)
%86 = call i32 @putchar(i8 signext 10)
%87 = call i32 @sleep(i32 1)
br label %88
88: ; preds = %83, %69
%89 = load i8*, i8** %20
%90 = call i64 @strcmp(i8* %89, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.12, i64 0, i64 0))
%91 = icmp eq i64 %90, 0
br i1 %91, label %96, label %92
92: ; preds = %88
%93 = load i8*, i8** %20
%94 = call i64 @strcmp(i8* %93, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%95 = icmp eq i64 %94, 0
br i1 %95, label %96, label %103
96: ; preds = %92, %88
%97 = call i32 @ioctl(i32 %13, i32 1, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.13, i64 0, i64 0))
%98 = icmp eq i32 %97, -1
br i1 %98, label %99, label %103
99: ; preds = %96
%100 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.14, i64 0, i64 0))
%101 = load i32, i32* @EXIT_FAILURE
%102 = call i32 @exit(i32 %101)
unreachable
103: ; preds = %96, %92
%104 = load i8*, i8** %20
%105 = call i64 @strcmp(i8* %104, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.12, i64 0, i64 0))
%106 = icmp eq i64 %105, 0
br i1 %106, label %111, label %107
107: ; preds = %103
%108 = load i8*, i8** %20
%109 = call i64 @strcmp(i8* %108, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%110 = icmp eq i64 %109, 0
br i1 %110, label %111, label %124
111: ; preds = %107, %103
%112 = load i32, i32* @stdout
%113 = call i32 (i32, i8*, ...) @fprintf(i32 %112, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
%114 = call i32 @memset(i8* %8, i32 0, i32 256)
%115 = call i32 @read(i32 %13, i8* %8, i32 256)
%116 = icmp eq i32 %115, -1
br i1 %116, label %117, label %121
117: ; preds = %111
%118 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
%119 = load i32, i32* @EXIT_FAILURE
%120 = call i32 @exit(i32 %119)
unreachable
121: ; preds = %111
%122 = load i32, i32* @stdout
%123 = call i32 (i32, i8*, ...) @fprintf(i32 %122, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.6, i64 0, i64 0), i32 %115, i8* %8)
br label %124
124: ; preds = %121, %107
%125 = call i32 @close(i32 %13)
%126 = load i32, i32* @EXIT_SUCCESS
ret i32 %126
}