#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*/ ioctl(int, int, unsigned int *);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ print_usage(char *);
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ strcmp(char *, char *);
unsigned int strtoul(char *, int /*<<< orphan*/ *, int /*<<< orphan*/);
int main(int argc, char **argv) {
  int fd;
  unsigned int buf[2];
  unsigned int i;
  unsigned int num;
  if ((argc != 3) && (argc != 4)) {
    print_usage(argv[0]);
    return -1;
  }
  fd = open("/dev/ker_rw", O_RDWR);
  if (fd < 0) {
    printf("can't open /dev/ker_rw\n");
    return -2;
  }
  buf[0] = strtoul(argv[2], NULL, 0);
  if (argc == 4) {
    buf[1] = strtoul(argv[3], NULL, 0);
    num = buf[1];
  } else {
    num = 1;
  }
  if (strcmp(argv[1], "r8") == 0) {
    for (i = 0; i < num; i++) {
      ioctl(fd, 100, buf);
      printf("%02d. [%08x] = %02x\n", i, buf[0], (unsigned char)buf[1]);
      buf[0] += 1;
    }
  } else if (strcmp(argv[1], "r16") == 0) {
    for (i = 0; i < num; i++) {
      ioctl(fd, 101, buf);
      printf("%02d. [%08x] = %04x\n", i, buf[0], (unsigned short)buf[1]);
      buf[0] += 2;
    }
  } else if (strcmp(argv[1], "r32") == 0) {
    for (i = 0; i < num; i++) {
      ioctl(fd, 102, buf);
      printf("%02d. [%08x] = %08x\n", i, buf[0], (unsigned int)buf[1]);
      buf[0] += 4;
    }
  } else if (strcmp(argv[1], "w8") == 0) {
    ioctl(fd, 103, buf);
  } else if (strcmp(argv[1], "w16") == 0) {
    ioctl(fd, 104, buf);
  } else if (strcmp(argv[1], "w32") == 0) {
    ioctl(fd, 105, buf);
  } else {
    printf(argv[0]);
    return -1;
  }
  return 0;
}


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)
cmpl   $0x3,-0x8(%rbp)
je     11a2 <main+0x42>
cmpl   $0x4,-0x8(%rbp)
je     11a2 <main+0x42>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1080 <print_usage@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1461 <main+0x301>
mov    0x2e3f(%rip),%rax
mov    (%rax),%esi
lea    0xe4e(%rip),%rdi
call   1060 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    11de <main+0x7e>
lea    0xe41(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0xfffffffe,-0x4(%rbp)
jmp    1461 <main+0x301>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
xor    %eax,%eax
mov    %eax,%esi
xor    %edx,%edx
call   1070 <strtoul@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x4,-0x8(%rbp)
jne    121f <main+0xbf>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
xor    %eax,%eax
mov    %eax,%esi
xor    %edx,%edx
call   1070 <strtoul@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0x24(%rbp)
jmp    1226 <main+0xc6>
movl   $0x1,-0x24(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xdef(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    129e <main+0x13e>
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x24(%rbp),%eax
jae    1299 <main+0x139>
mov    -0x14(%rbp),%edi
lea    -0x1c(%rbp),%rdx
mov    $0x64,%esi
call   1040 <ioctl@plt>
mov    -0x20(%rbp),%esi
mov    -0x1c(%rbp),%edx
mov    -0x18(%rbp),%eax
movzbl %al,%ecx
lea    0xdac(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    124b <main+0xeb>
jmp    145a <main+0x2fa>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xd8f(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    1316 <main+0x1b6>
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x24(%rbp),%eax
jae    1311 <main+0x1b1>
mov    -0x14(%rbp),%edi
lea    -0x1c(%rbp),%rdx
mov    $0x65,%esi
call   1040 <ioctl@plt>
mov    -0x20(%rbp),%esi
mov    -0x1c(%rbp),%edx
mov    -0x18(%rbp),%eax
movzwl %ax,%ecx
lea    0xd4d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x1c(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    12c3 <main+0x163>
jmp    1455 <main+0x2f5>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xd30(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    138b <main+0x22b>
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x24(%rbp),%eax
jae    1386 <main+0x226>
mov    -0x14(%rbp),%edi
lea    -0x1c(%rbp),%rdx
mov    $0x66,%esi
call   1040 <ioctl@plt>
mov    -0x20(%rbp),%esi
mov    -0x1c(%rbp),%edx
mov    -0x18(%rbp),%ecx
lea    0xcf1(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x1c(%rbp),%eax
add    $0x4,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    133b <main+0x1db>
jmp    1450 <main+0x2f0>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xcd4(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    13bf <main+0x25f>
mov    -0x14(%rbp),%edi
lea    -0x1c(%rbp),%rdx
mov    $0x67,%esi
call   1040 <ioctl@plt>
jmp    144b <main+0x2eb>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xca3(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    13f3 <main+0x293>
mov    -0x14(%rbp),%edi
lea    -0x1c(%rbp),%rdx
mov    $0x68,%esi
call   1040 <ioctl@plt>
jmp    1446 <main+0x2e6>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xc73(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    1427 <main+0x2c7>
mov    -0x14(%rbp),%edi
lea    -0x1c(%rbp),%rdx
mov    $0x69,%esi
call   1040 <ioctl@plt>
jmp    1441 <main+0x2e1>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1461 <main+0x301>
jmp    1446 <main+0x2e6>
jmp    144b <main+0x2eb>
jmp    1450 <main+0x2f0>
jmp    1455 <main+0x2f5>
jmp    145a <main+0x2fa>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %edi,%ebx
lea    -0x5(%rbx),%eax
cmp    $0xfffffffd,%eax
ja     119b <main+0x2b>
mov    (%r14),%rdi
call   1090 <print_usage@plt>
mov    $0xffffffff,%r14d
jmp    13bd <main+0x24d>
mov    0x2e46(%rip),%rax
mov    (%rax),%esi
lea    0xeb5(%rip),%rdi
call   1070 <open@plt>
test   %eax,%eax
js     128d <main+0x11d>
mov    %eax,%r15d
mov    0x10(%r14),%rdi
xor    %esi,%esi
xor    %edx,%edx
call   1080 <strtoul@plt>
mov    %eax,(%rsp)
mov    $0x1,%ebp
cmp    $0x4,%ebx
jne    11e8 <main+0x78>
mov    0x18(%r14),%rdi
xor    %esi,%esi
xor    %edx,%edx
call   1080 <strtoul@plt>
mov    %eax,%ebp
mov    %eax,0x4(%rsp)
mov    0x8(%r14),%rdi
lea    0xe0d(%rip),%rsi
call   1060 <strcmp@plt>
test   %rax,%rax
je     12a4 <main+0x134>
mov    0x8(%r14),%rdi
lea    0xe0c(%rip),%rsi
call   1060 <strcmp@plt>
test   %rax,%rax
je     12f4 <main+0x184>
mov    0x8(%r14),%rdi
lea    0xe0c(%rip),%rsi
call   1060 <strcmp@plt>
test   %rax,%rax
je     1341 <main+0x1d1>
mov    0x8(%r14),%rdi
lea    0xe0c(%rip),%rsi
call   1060 <strcmp@plt>
test   %rax,%rax
je     1390 <main+0x220>
mov    0x8(%r14),%rdi
lea    0xdf6(%rip),%rsi
call   1060 <strcmp@plt>
test   %rax,%rax
je     139d <main+0x22d>
mov    0x8(%r14),%rdi
lea    0xde1(%rip),%rsi
call   1060 <strcmp@plt>
test   %rax,%rax
je     13aa <main+0x23a>
mov    (%r14),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    1190 <main+0x20>
lea    0xdc1(%rip),%rdi
call   1030 <puts@plt>
mov    $0xfffffffe,%r14d
jmp    13bd <main+0x24d>
xor    %r14d,%r14d
test   %ebp,%ebp
je     13bd <main+0x24d>
mov    %rsp,%r12
lea    0xd4a(%rip),%r13
xor    %ebx,%ebx
nopl   0x0(%rax,%rax,1)
mov    %r15d,%edi
mov    $0x64,%esi
mov    %r12,%rdx
call   1050 <ioctl@plt>
mov    (%rsp),%edx
movzbl 0x4(%rsp),%ecx
mov    %r13,%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
addl   $0x1,(%rsp)
add    $0x1,%ebx
cmp    %ebx,%ebp
jne    12c0 <main+0x150>
jmp    13bd <main+0x24d>
xor    %r14d,%r14d
test   %ebp,%ebp
je     13bd <main+0x24d>
mov    %rsp,%r12
lea    0xd13(%rip),%r13
xor    %ebx,%ebx
nopl   0x0(%rax,%rax,1)
mov    %r15d,%edi
mov    $0x65,%esi
mov    %r12,%rdx
call   1050 <ioctl@plt>
mov    (%rsp),%edx
movzwl 0x4(%rsp),%ecx
mov    %r13,%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
addl   $0x2,(%rsp)
add    $0x1,%ebx
cmp    %ebx,%ebp
jne    1310 <main+0x1a0>
jmp    13bd <main+0x24d>
xor    %r14d,%r14d
test   %ebp,%ebp
je     13bd <main+0x24d>
mov    %rsp,%r12
lea    0xce3(%rip),%r13
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %r15d,%edi
mov    $0x66,%esi
mov    %r12,%rdx
call   1050 <ioctl@plt>
mov    (%rsp),%edx
mov    0x4(%rsp),%ecx
mov    %r13,%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
addl   $0x4,(%rsp)
add    $0x1,%ebx
cmp    %ebx,%ebp
jne    1360 <main+0x1f0>
jmp    13bd <main+0x24d>
mov    %rsp,%rdx
mov    %r15d,%edi
mov    $0x67,%esi
jmp    13b5 <main+0x245>
mov    %rsp,%rdx
mov    %r15d,%edi
mov    $0x68,%esi
jmp    13b5 <main+0x245>
mov    %rsp,%rdx
mov    %r15d,%edi
mov    $0x69,%esi
call   1050 <ioctl@plt>
xor    %r14d,%r14d
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [12 x i8] c"/dev/ker_rw\00"
@O_RDWR = global i32 0
@.str.1 = [24 x i8] c"can't open /dev/ker_rw\0A\00"
@.str.2 = [3 x i8] c"r8\00"
@.str.3 = [21 x i8] c"%02d. [%08x] = %02x\0A\00"
@.str.4 = [4 x i8] c"r16\00"
@.str.5 = [21 x i8] c"%02d. [%08x] = %04x\0A\00"
@.str.6 = [4 x i8] c"r32\00"
@.str.7 = [21 x i8] c"%02d. [%08x] = %08x\0A\00"
@.str.8 = [3 x i8] c"w8\00"
@.str.9 = [4 x i8] c"w16\00"
@.str.10 = [4 x i8] c"w32\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca [2 x 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, 3
br i1 %11, label %12, label %20
12: ; preds = %2
%13 = load i32, i32* %4
%14 = icmp ne i32 %13, 4
br i1 %14, label %15, label %20
15: ; preds = %12
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 0
%18 = load i8*, i8** %17
%19 = call i32 @print_usage(i8* %18)
store i32 -1, i32* %3
br label %173
20: ; preds = %12, %2
%21 = load i32, i32* @O_RDWR
%22 = call i32 @open(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %21)
store i32 %22, i32* %6
%23 = load i32, i32* %6
%24 = icmp slt i32 %23, 0
br i1 %24, label %25, label %27
25: ; preds = %20
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0))
store i32 -2, i32* %3
br label %173
27: ; preds = %20
%28 = load i8**, i8*** %5
%29 = getelementptr inbounds i8*, i8** %28, i64 2
%30 = load i8*, i8** %29
%31 = call i32 @strtoul(i8* %30, i32* null, i32 0)
%32 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 0
store i32 %31, i32* %32
%33 = load i32, i32* %4
%34 = icmp eq i32 %33, 4
br i1 %34, label %35, label %43
35: ; preds = %27
%36 = load i8**, i8*** %5
%37 = getelementptr inbounds i8*, i8** %36, i64 3
%38 = load i8*, i8** %37
%39 = call i32 @strtoul(i8* %38, i32* null, i32 0)
%40 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 1
store i32 %39, i32* %40
%41 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 1
%42 = load i32, i32* %41
store i32 %42, i32* %9
br label %44
43: ; preds = %27
store i32 1, i32* %9
br label %44
44: ; preds = %43, %35
%45 = load i8**, i8*** %5
%46 = getelementptr inbounds i8*, i8** %45, i64 1
%47 = load i8*, i8** %46
%48 = call i64 @strcmp(i8* %47, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%49 = icmp eq i64 %48, 0
br i1 %49, label %50, label %74
50: ; preds = %44
store i32 0, i32* %8
br label %51
51: ; preds = %70, %50
%52 = load i32, i32* %8
%53 = load i32, i32* %9
%54 = icmp ult i32 %52, %53
br i1 %54, label %55, label %73
55: ; preds = %51
%56 = load i32, i32* %6
%57 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 0
%58 = call i32 @ioctl(i32 %56, i32 100, i32* %57)
%59 = load i32, i32* %8
%60 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 0
%61 = load i32, i32* %60
%62 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 1
%63 = load i32, i32* %62
%64 = trunc i32 %63 to i8
%65 = zext i8 %64 to i32
%66 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0), i32 %59, i32 %61, i32 %65)
%67 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 0
%68 = load i32, i32* %67
%69 = add i32 %68, 1
store i32 %69, i32* %67
br label %70
70: ; preds = %55
%71 = load i32, i32* %8
%72 = add i32 %71, 1
store i32 %72, i32* %8
br label %51
73: ; preds = %51
br label %172
74: ; preds = %44
%75 = load i8**, i8*** %5
%76 = getelementptr inbounds i8*, i8** %75, i64 1
%77 = load i8*, i8** %76
%78 = call i64 @strcmp(i8* %77, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0))
%79 = icmp eq i64 %78, 0
br i1 %79, label %80, label %104
80: ; preds = %74
store i32 0, i32* %8
br label %81
81: ; preds = %100, %80
%82 = load i32, i32* %8
%83 = load i32, i32* %9
%84 = icmp ult i32 %82, %83
br i1 %84, label %85, label %103
85: ; preds = %81
%86 = load i32, i32* %6
%87 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 0
%88 = call i32 @ioctl(i32 %86, i32 101, i32* %87)
%89 = load i32, i32* %8
%90 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 0
%91 = load i32, i32* %90
%92 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 1
%93 = load i32, i32* %92
%94 = trunc i32 %93 to i16
%95 = zext i16 %94 to i32
%96 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.5, i64 0, i64 0), i32 %89, i32 %91, i32 %95)
%97 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 0
%98 = load i32, i32* %97
%99 = add i32 %98, 2
store i32 %99, i32* %97
br label %100
100: ; preds = %85
%101 = load i32, i32* %8
%102 = add i32 %101, 1
store i32 %102, i32* %8
br label %81
103: ; preds = %81
br label %171
104: ; preds = %74
%105 = load i8**, i8*** %5
%106 = getelementptr inbounds i8*, i8** %105, i64 1
%107 = load i8*, i8** %106
%108 = call i64 @strcmp(i8* %107, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0))
%109 = icmp eq i64 %108, 0
br i1 %109, label %110, label %132
110: ; preds = %104
store i32 0, i32* %8
br label %111
111: ; preds = %128, %110
%112 = load i32, i32* %8
%113 = load i32, i32* %9
%114 = icmp ult i32 %112, %113
br i1 %114, label %115, label %131
115: ; preds = %111
%116 = load i32, i32* %6
%117 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 0
%118 = call i32 @ioctl(i32 %116, i32 102, i32* %117)
%119 = load i32, i32* %8
%120 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 0
%121 = load i32, i32* %120
%122 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 1
%123 = load i32, i32* %122
%124 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.7, i64 0, i64 0), i32 %119, i32 %121, i32 %123)
%125 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 0
%126 = load i32, i32* %125
%127 = add i32 %126, 4
store i32 %127, i32* %125
br label %128
128: ; preds = %115
%129 = load i32, i32* %8
%130 = add i32 %129, 1
store i32 %130, i32* %8
br label %111
131: ; preds = %111
br label %170
132: ; preds = %104
%133 = load i8**, i8*** %5
%134 = getelementptr inbounds i8*, i8** %133, i64 1
%135 = load i8*, i8** %134
%136 = call i64 @strcmp(i8* %135, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.8, i64 0, i64 0))
%137 = icmp eq i64 %136, 0
br i1 %137, label %138, label %142
138: ; preds = %132
%139 = load i32, i32* %6
%140 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 0
%141 = call i32 @ioctl(i32 %139, i32 103, i32* %140)
br label %169
142: ; preds = %132
%143 = load i8**, i8*** %5
%144 = getelementptr inbounds i8*, i8** %143, i64 1
%145 = load i8*, i8** %144
%146 = call i64 @strcmp(i8* %145, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.9, i64 0, i64 0))
%147 = icmp eq i64 %146, 0
br i1 %147, label %148, label %152
148: ; preds = %142
%149 = load i32, i32* %6
%150 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 0
%151 = call i32 @ioctl(i32 %149, i32 104, i32* %150)
br label %168
152: ; preds = %142
%153 = load i8**, i8*** %5
%154 = getelementptr inbounds i8*, i8** %153, i64 1
%155 = load i8*, i8** %154
%156 = call i64 @strcmp(i8* %155, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.10, i64 0, i64 0))
%157 = icmp eq i64 %156, 0
br i1 %157, label %158, label %162
158: ; preds = %152
%159 = load i32, i32* %6
%160 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 0
%161 = call i32 @ioctl(i32 %159, i32 105, i32* %160)
br label %167
162: ; preds = %152
%163 = load i8**, i8*** %5
%164 = getelementptr inbounds i8*, i8** %163, i64 0
%165 = load i8*, i8** %164
%166 = call i32 (i8*, ...) @printf(i8* %165)
store i32 -1, i32* %3
br label %173
167: ; preds = %158
br label %168
168: ; preds = %167, %148
br label %169
169: ; preds = %168, %138
br label %170
170: ; preds = %169, %131
br label %171
171: ; preds = %170, %103
br label %172
172: ; preds = %171, %73
store i32 0, i32* %3
br label %173
173: ; preds = %172, %162, %25, %15
%174 = load i32, i32* %3
ret i32 %174
}

LLVM IR (-O2):
@.str = [12 x i8] c"/dev/ker_rw\00"
@O_RDWR = global i32 0
@.str.2 = [3 x i8] c"r8\00"
@.str.3 = [21 x i8] c"%02d. [%08x] = %02x\0A\00"
@.str.4 = [4 x i8] c"r16\00"
@.str.5 = [21 x i8] c"%02d. [%08x] = %04x\0A\00"
@.str.6 = [4 x i8] c"r32\00"
@.str.7 = [21 x i8] c"%02d. [%08x] = %08x\0A\00"
@.str.8 = [3 x i8] c"w8\00"
@.str.9 = [4 x i8] c"w16\00"
@.str.10 = [4 x i8] c"w32\00"
@str = [23 x i8] c"can't open /dev/ker_rw\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [2 x i32]
%4 = bitcast [2 x i32]* %3 to i8*
%5 = add i32 %0, -5
%6 = icmp ult i32 %5, -2
br i1 %6, label %7, label %10
7: ; preds = %2
%8 = load i8*, i8** %1
%9 = tail call i32 @print_usage(i8* %8)
br label %106
10: ; preds = %2
%11 = load i32, i32* @O_RDWR
%12 = tail call i32 @open(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %11)
%13 = icmp slt i32 %12, 0
br i1 %13, label %14, label %16
14: ; preds = %10
%15 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str, i64 0, i64 0))
br label %106
16: ; preds = %10
%17 = getelementptr inbounds i8*, i8** %1, i64 2
%18 = load i8*, i8** %17
%19 = tail call i32 @strtoul(i8* nocapture %18, i32* null, i32 0)
%20 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 0
store i32 %19, i32* %20
%21 = icmp eq i32 %0, 4
br i1 %21, label %22, label %27
22: ; preds = %16
%23 = getelementptr inbounds i8*, i8** %1, i64 3
%24 = load i8*, i8** %23
%25 = tail call i32 @strtoul(i8* nocapture %24, i32* null, i32 0)
%26 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 1
store i32 %25, i32* %26
br label %27
27: ; preds = %16, %22
%28 = phi i32 [ %25, %22 ], [ 1, %16 ]
%29 = getelementptr inbounds i8*, i8** %1, i64 1
%30 = load i8*, i8** %29
%31 = tail 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 %33, label %48
33: ; preds = %27
%34 = icmp eq i32 %28, 0
br i1 %34, label %106, label %35
35: ; preds = %33
%36 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 1
br label %37
37: ; preds = %35, %37
%38 = phi i32 [ 0, %35 ], [ %46, %37 ]
%39 = call i32 @ioctl(i32 %12, i32 100, i32* %20)
%40 = load i32, i32* %20
%41 = load i32, i32* %36
%42 = and i32 %41, 255
%43 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0), i32 %38, i32 %40, i32 %42)
%44 = load i32, i32* %20
%45 = add i32 %44, 1
store i32 %45, i32* %20
%46 = add nuw i32 %38, 1
%47 = icmp eq i32 %46, %28
br i1 %47, label %106, label %37
48: ; preds = %27
%49 = load i8*, i8** %29
%50 = tail call i64 @strcmp(i8* %49, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0))
%51 = icmp eq i64 %50, 0
br i1 %51, label %52, label %67
52: ; preds = %48
%53 = icmp eq i32 %28, 0
br i1 %53, label %106, label %54
54: ; preds = %52
%55 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 1
br label %56
56: ; preds = %54, %56
%57 = phi i32 [ 0, %54 ], [ %65, %56 ]
%58 = call i32 @ioctl(i32 %12, i32 101, i32* %20)
%59 = load i32, i32* %20
%60 = load i32, i32* %55
%61 = and i32 %60, 65535
%62 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.5, i64 0, i64 0), i32 %57, i32 %59, i32 %61)
%63 = load i32, i32* %20
%64 = add i32 %63, 2
store i32 %64, i32* %20
%65 = add nuw i32 %57, 1
%66 = icmp eq i32 %65, %28
br i1 %66, label %106, label %56
67: ; preds = %48
%68 = load i8*, i8** %29
%69 = tail call i64 @strcmp(i8* %68, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0))
%70 = icmp eq i64 %69, 0
br i1 %70, label %71, label %85
71: ; preds = %67
%72 = icmp eq i32 %28, 0
br i1 %72, label %106, label %73
73: ; preds = %71
%74 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 1
br label %75
75: ; preds = %73, %75
%76 = phi i32 [ 0, %73 ], [ %83, %75 ]
%77 = call i32 @ioctl(i32 %12, i32 102, i32* %20)
%78 = load i32, i32* %20
%79 = load i32, i32* %74
%80 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.7, i64 0, i64 0), i32 %76, i32 %78, i32 %79)
%81 = load i32, i32* %20
%82 = add i32 %81, 4
store i32 %82, i32* %20
%83 = add nuw i32 %76, 1
%84 = icmp eq i32 %83, %28
br i1 %84, label %106, label %75
85: ; preds = %67
%86 = load i8*, i8** %29
%87 = tail call i64 @strcmp(i8* %86, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.8, i64 0, i64 0))
%88 = icmp eq i64 %87, 0
br i1 %88, label %89, label %91
89: ; preds = %85
%90 = call i32 @ioctl(i32 %12, i32 103, i32* %20)
br label %106
91: ; preds = %85
%92 = load i8*, i8** %29
%93 = tail call i64 @strcmp(i8* %92, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.9, i64 0, i64 0))
%94 = icmp eq i64 %93, 0
br i1 %94, label %95, label %97
95: ; preds = %91
%96 = call i32 @ioctl(i32 %12, i32 104, i32* %20)
br label %106
97: ; preds = %91
%98 = load i8*, i8** %29
%99 = tail call i64 @strcmp(i8* %98, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.10, i64 0, i64 0))
%100 = icmp eq i64 %99, 0
br i1 %100, label %101, label %103
101: ; preds = %97
%102 = call i32 @ioctl(i32 %12, i32 105, i32* %20)
br label %106
103: ; preds = %97
%104 = load i8*, i8** %1
%105 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) %104)
br label %106
106: ; preds = %75, %56, %37, %71, %52, %33, %95, %101, %89, %103, %14, %7
%107 = phi i32 [ -1, %7 ], [ -2, %14 ], [ -1, %103 ], [ 0, %89 ], [ 0, %101 ], [ 0, %95 ], [ 0, %33 ], [ 0, %52 ], [ 0, %71 ], [ 0, %37 ], [ 0, %56 ], [ 0, %75 ]
ret i32 %107
}