#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*/ SEEK_SET;
int /*<<< orphan*/ close(int);
int getopt(int, char **, char *);
int lseek(int, unsigned int, int /*<<< orphan*/);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ optarg;
int /*<<< orphan*/ print_usage();
int /*<<< orphan*/ printf(char *, ...);
int read(int, char *, int);
scalar_t__ strcmp(char *, char *);
unsigned int strtoul(int /*<<< orphan*/, char **, int);
int write(int, char *, int);
int main(int argc, char *argv[]) {
  int fd, ch;
  int is_read = -1;
  unsigned int bankaddr;
  unsigned int value;
  char ch_val;
  char *end_char = NULL;
  if (argc < 4 || argc > 6)
    goto invalid_param_out;
  if (strcmp(argv[1], "read") == 0) {
    if (argc != 4)
      goto invalid_param_out;
    is_read = 1;
  } else if (strcmp(argv[1], "blow") == 0) {
    if (argc != 6)
      goto invalid_param_out;
    is_read = 0;
  } else {
    printf("Unsupported option: %s!\n", argv[1]);
    goto invalid_param_out;
  }
  while (-1 != (ch = getopt(argc - 1, &argv[1], "d:v:"))) {
    switch (ch) {
    case 'd':
      bankaddr = strtoul(optarg, &end_char, 16);
      if (*end_char)
        goto invalid_param_out;
      break;
    case 'v':
      value = strtoul(optarg, &end_char, 16);
      if (*end_char)
        goto invalid_param_out;
      break;
    default:
      printf("Unsupported option: -%c!\n", ch);
      goto invalid_param_out;
      break;
    }
  }
  if (-1 == is_read)
    goto invalid_param_out;
  fd = open("/dev/mxc_iim", O_RDWR);
  if (-1 == fd) {
    printf("Can't open /dev/mxc_iim!\n");
    return -1;
  }
  if (bankaddr) {
    if (-1 == lseek(fd, bankaddr, SEEK_SET)) {
      printf("lseek failed at bank addr 0x%08x\n", bankaddr);
      goto op_err_out;
    }
  }
  ch_val = (char)value;
  if (is_read) {
    if (-1 == read(fd, &ch_val, sizeof(char))) {
      printf("Read failed at bank addr 0x%08x\n", bankaddr);
      goto op_err_out;
    }
    printf("Value at bank addr 0x%08x: 0x%x\n", bankaddr, ch_val);
  } else {
    if (-1 == write(fd, &ch_val, sizeof(char))) {
      printf("Write failed at bank addr 0x%08x, "
             "value: 0x%08x\n",
             bankaddr, ch_val);
      goto op_err_out;
    }
    printf("Writting 0x%08x to bank addr 0x%08x\n", ch_val, bankaddr);
    if (-1 == lseek(fd, bankaddr, SEEK_SET)) {
      printf("lseek failed at bank addr 0x%08x\n", bankaddr);
      goto op_err_out;
    }
    if (-1 == read(fd, &ch_val, sizeof(char))) {
      printf("Read failed at bank addr 0x%08x\n", bankaddr);
      goto op_err_out;
    }
    printf("Value at bank addr 0x%08x: 0x%08x\n", bankaddr, ch_val);
  }
  close(fd);
  return 0;
op_err_out:
  return -2;
invalid_param_out:
  printf("Invalid parameters!\n");
  print_usage();
  return -1;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0xffffffff,-0x1c(%rbp)
movq   $0x0,-0x30(%rbp)
cmpl   $0x4,-0x8(%rbp)
jl     11d9 <main+0x39>
cmpl   $0x6,-0x8(%rbp)
jle    11de <main+0x3e>
jmp    1531 <main+0x391>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe13(%rip),%rsi
call   1080 <strcmp@plt>
cmp    $0x0,%rax
jne    1217 <main+0x77>
cmpl   $0x4,-0x8(%rbp)
je     120b <main+0x6b>
jmp    1531 <main+0x391>
movl   $0x1,-0x1c(%rbp)
jmp    1270 <main+0xd0>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xddf(%rip),%rsi
call   1080 <strcmp@plt>
cmp    $0x0,%rax
jne    1250 <main+0xb0>
cmpl   $0x6,-0x8(%rbp)
je     1244 <main+0xa4>
jmp    1531 <main+0x391>
movl   $0x0,-0x1c(%rbp)
jmp    126b <main+0xcb>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xdab(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1531 <main+0x391>
jmp    1270 <main+0xd0>
jmp    1275 <main+0xd5>
mov    -0x8(%rbp),%edi
sub    $0x1,%edi
mov    -0x10(%rbp),%rsi
add    $0x8,%rsi
lea    0xd99(%rip),%rdx
call   10a0 <getopt@plt>
mov    %eax,%ecx
mov    %ecx,-0x18(%rbp)
mov    $0xffffffff,%eax
cmp    %ecx,%eax
je     1343 <main+0x1a3>
mov    -0x18(%rbp),%eax
mov    %eax,-0x34(%rbp)
sub    $0x64,%eax
je     12c6 <main+0x126>
jmp    12b5 <main+0x115>
mov    -0x34(%rbp),%eax
sub    $0x76,%eax
je     12f7 <main+0x157>
jmp    1328 <main+0x188>
mov    0x2d2b(%rip),%rax
mov    (%rax),%edi
lea    -0x30(%rbp),%rsi
mov    $0x10,%edx
call   10b0 <strtoul@plt>
mov    %eax,-0x20(%rbp)
mov    -0x30(%rbp),%rax
cmpb   $0x0,(%rax)
je     12f2 <main+0x152>
jmp    1531 <main+0x391>
jmp    133e <main+0x19e>
mov    0x2cfa(%rip),%rax
mov    (%rax),%edi
lea    -0x30(%rbp),%rsi
mov    $0x10,%edx
call   10b0 <strtoul@plt>
mov    %eax,-0x24(%rbp)
mov    -0x30(%rbp),%rax
cmpb   $0x0,(%rax)
je     1323 <main+0x183>
jmp    1531 <main+0x391>
jmp    133e <main+0x19e>
mov    -0x18(%rbp),%esi
lea    0xcf6(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1531 <main+0x391>
jmp    1275 <main+0xd5>
mov    $0xffffffff,%eax
cmp    -0x1c(%rbp),%eax
jne    1356 <main+0x1b6>
jmp    1531 <main+0x391>
mov    0x2c83(%rip),%rax
mov    (%rax),%esi
lea    0xcdc(%rip),%rdi
call   1090 <open@plt>
mov    %eax,-0x14(%rbp)
mov    $0xffffffff,%eax
cmp    -0x14(%rbp),%eax
jne    1396 <main+0x1f6>
lea    0xccc(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    154d <main+0x3ad>
cmpl   $0x0,-0x20(%rbp)
je     13de <main+0x23e>
mov    -0x14(%rbp),%edi
mov    -0x20(%rbp),%esi
mov    0x2c23(%rip),%rax
mov    (%rax),%edx
call   1050 <lseek@plt>
mov    %eax,%ecx
mov    $0xffffffff,%eax
cmp    %ecx,%eax
jne    13d9 <main+0x239>
mov    -0x20(%rbp),%esi
lea    0xc9c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1525 <main+0x385>
jmp    13de <main+0x23e>
mov    -0x24(%rbp),%eax
mov    %al,-0x25(%rbp)
cmpl   $0x0,-0x1c(%rbp)
je     143e <main+0x29e>
mov    -0x14(%rbp),%edi
lea    -0x25(%rbp),%rsi
mov    $0x1,%edx
call   1070 <read@plt>
mov    %eax,%ecx
mov    $0xffffffff,%eax
cmp    %ecx,%eax
jne    1424 <main+0x284>
mov    -0x20(%rbp),%esi
lea    0xc73(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1525 <main+0x385>
mov    -0x20(%rbp),%esi
movsbl -0x25(%rbp),%edx
lea    0xc7a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1511 <main+0x371>
mov    -0x14(%rbp),%edi
lea    -0x25(%rbp),%rsi
mov    $0x1,%edx
call   1030 <write@plt>
mov    %eax,%ecx
mov    $0xffffffff,%eax
cmp    %ecx,%eax
jne    1478 <main+0x2d8>
mov    -0x20(%rbp),%esi
movsbl -0x25(%rbp),%edx
lea    0xc61(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1525 <main+0x385>
movsbl -0x25(%rbp),%esi
mov    -0x20(%rbp),%edx
lea    0xc78(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x14(%rbp),%edi
mov    -0x20(%rbp),%esi
mov    0x2b36(%rip),%rax
mov    (%rax),%edx
call   1050 <lseek@plt>
mov    %eax,%ecx
mov    $0xffffffff,%eax
cmp    %ecx,%eax
jne    14c6 <main+0x326>
mov    -0x20(%rbp),%esi
lea    0xbaf(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1525 <main+0x385>
mov    -0x14(%rbp),%edi
lea    -0x25(%rbp),%rsi
mov    $0x1,%edx
call   1070 <read@plt>
mov    %eax,%ecx
mov    $0xffffffff,%eax
cmp    %ecx,%eax
jne    14fc <main+0x35c>
mov    -0x20(%rbp),%esi
lea    0xb9b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1525 <main+0x385>
mov    -0x20(%rbp),%esi
movsbl -0x25(%rbp),%edx
lea    0xc19(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x14(%rbp),%edi
call   1060 <close@plt>
movl   $0x0,-0x4(%rbp)
jmp    154d <main+0x3ad>
movl   $0xfffffffe,-0x4(%rbp)
jmp    154d <main+0x3ad>
lea    0xc0e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x0,%al
call   10c0 <print_usage@plt>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %edi,%r12d
movq   $0x0,0x8(%rsp)
lea    -0x7(%r12),%eax
cmp    $0xfffffffd,%eax
jb     1391 <main+0x1e1>
mov    %rsi,%rbp
mov    0x8(%rsi),%rdi
add    $0x8,%rbp
lea    0xe16(%rip),%rsi
call   1090 <strcmp@plt>
mov    %rax,%rbx
test   %rax,%rax
je     1223 <main+0x73>
mov    0x0(%rbp),%rdi
lea    0xe03(%rip),%rsi
call   1090 <strcmp@plt>
test   %rax,%rax
je     1233 <main+0x83>
mov    0x0(%rbp),%rsi
lea    0xdf3(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    1391 <main+0x1e1>
mov    %rbx,0x10(%rsp)
cmp    $0x4,%r12d
je     1242 <main+0x92>
jmp    1391 <main+0x1e1>
mov    %rbx,0x10(%rsp)
cmp    $0x6,%r12d
jne    1391 <main+0x1e1>
add    $0xffffffff,%r12d
lea    0xdd6(%rip),%r13
mov    0x2da4(%rip),%r15
lea    0x8(%rsp),%r14
nopl   0x0(%rax)
mov    %r12d,%edi
mov    %rbp,%rsi
mov    %r13,%rdx
call   10b0 <getopt@plt>
cmp    $0x76,%eax
jne    1294 <main+0xe4>
mov    (%r15),%edi
mov    %r14,%rsi
mov    $0x10,%edx
call   10c0 <strtoul@plt>
mov    %eax,%ebx
mov    0x8(%rsp),%rax
cmpb   $0x0,(%rax)
je     1260 <main+0xb0>
jmp    1391 <main+0x1e1>
cmp    $0xffffffff,%eax
je     12b8 <main+0x108>
cmp    $0x64,%eax
jne    1381 <main+0x1d1>
mov    (%r15),%edi
mov    %r14,%rsi
mov    $0x10,%edx
call   10c0 <strtoul@plt>
mov    %eax,0x4(%rsp)
jmp    1285 <main+0xd5>
mov    0x2d21(%rip),%rax
mov    (%rax),%esi
lea    0xd7a(%rip),%rdi
call   10a0 <open@plt>
cmp    $0xffffffff,%eax
je     13ba <main+0x20a>
mov    %eax,%ebp
cmpl   $0x0,0x4(%rsp)
je     1300 <main+0x150>
mov    0x2cea(%rip),%rax
mov    (%rax),%edx
mov    %ebp,%edi
mov    0x4(%rsp),%esi
call   1060 <lseek@plt>
mov    0x4(%rsp),%esi
cmp    $0xffffffff,%eax
je     1400 <main+0x250>
mov    %bl,0x3(%rsp)
cmpq   $0x0,0x10(%rsp)
je     13c8 <main+0x218>
lea    0x3(%rsp),%rsi
mov    %ebp,%edi
mov    $0x1,%edx
call   1040 <write@plt>
movsbl %bl,%edx
cmp    $0xffffffff,%eax
je     1409 <main+0x259>
lea    0xdb0(%rip),%rdi
mov    %edx,%esi
mov    0x4(%rsp),%ebx
mov    %ebx,%edx
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x2c86(%rip),%rax
mov    (%rax),%edx
mov    %ebp,%edi
mov    %ebx,%esi
call   1060 <lseek@plt>
cmp    $0xffffffff,%eax
je     142f <main+0x27f>
lea    0x3(%rsp),%rsi
mov    %ebp,%edi
mov    $0x1,%edx
call   1080 <read@plt>
cmp    $0xffffffff,%eax
je     1422 <main+0x272>
lea    0xd8a(%rip),%rdi
jmp    13e5 <main+0x235>
lea    0xca0(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xd94(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
call   10d0 <print_usage@plt>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd7f(%rip),%rdi
call   1030 <puts@plt>
jmp    13a4 <main+0x1f4>
lea    0x3(%rsp),%rsi
mov    %ebp,%edi
mov    $0x1,%edx
call   1080 <read@plt>
cmp    $0xffffffff,%eax
je     1422 <main+0x272>
lea    0xcad(%rip),%rdi
mov    0x4(%rsp),%esi
movsbl 0x3(%rsp),%edx
xor    %ebx,%ebx
xor    %eax,%eax
call   1050 <printf@plt>
mov    %ebp,%edi
call   1070 <close@plt>
jmp    13a9 <main+0x1f9>
lea    0xc48(%rip),%rdi
jmp    1438 <main+0x288>
lea    0xca3(%rip),%rdi
mov    0x4(%rsp),%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0xfffffffe,%ebx
jmp    13a9 <main+0x1f9>
lea    0xc48(%rip),%rdi
mov    0x4(%rsp),%esi
jmp    1438 <main+0x288>
lea    0xc19(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0xfffffffe,%ebx
jmp    13a9 <main+0x1f9>

LLVM IR (-O0):
@.str = [5 x i8] c"read\00"
@.str.1 = [5 x i8] c"blow\00"
@.str.2 = [25 x i8] c"Unsupported option: %s!\0A\00"
@.str.3 = [5 x i8] c"d:v:\00"
@optarg = global i32 0
@.str.4 = [26 x i8] c"Unsupported option: -%c!\0A\00"
@.str.5 = [13 x i8] c"/dev/mxc_iim\00"
@O_RDWR = global i32 0
@.str.6 = [26 x i8] c"Can't open /dev/mxc_iim!\0A\00"
@SEEK_SET = global i32 0
@.str.7 = [34 x i8] c"lseek failed at bank addr 0x%08x\0A\00"
@.str.8 = [33 x i8] c"Read failed at bank addr 0x%08x\0A\00"
@.str.9 = [33 x i8] c"Value at bank addr 0x%08x: 0x%x\0A\00"
@.str.10 = [49 x i8] c"Write failed at bank addr 0x%08x, value: 0x%08x\0A\00"
@.str.11 = [37 x i8] c"Writting 0x%08x to bank addr 0x%08x\0A\00"
@.str.12 = [35 x i8] c"Value at bank addr 0x%08x: 0x%08x\0A\00"
@.str.13 = [21 x i8] c"Invalid parameters!\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 i32
%11 = alloca i8
%12 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 -1, i32* %8
store i8* null, i8** %12
%13 = load i32, i32* %4
%14 = icmp slt i32 %13, 4
br i1 %14, label %18, label %15
15: ; preds = %2
%16 = load i32, i32* %4
%17 = icmp sgt i32 %16, 6
br i1 %17, label %18, label %19
18: ; preds = %15, %2
br label %156
19: ; preds = %15
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 1
%22 = load i8*, i8** %21
%23 = call i64 @strcmp(i8* %22, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%24 = icmp eq i64 %23, 0
br i1 %24, label %25, label %30
25: ; preds = %19
%26 = load i32, i32* %4
%27 = icmp ne i32 %26, 4
br i1 %27, label %28, label %29
28: ; preds = %25
br label %156
29: ; preds = %25
store i32 1, i32* %8
br label %47
30: ; preds = %19
%31 = load i8**, i8*** %5
%32 = getelementptr inbounds i8*, i8** %31, i64 1
%33 = load i8*, i8** %32
%34 = call i64 @strcmp(i8* %33, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%35 = icmp eq i64 %34, 0
br i1 %35, label %36, label %41
36: ; preds = %30
%37 = load i32, i32* %4
%38 = icmp ne i32 %37, 6
br i1 %38, label %39, label %40
39: ; preds = %36
br label %156
40: ; preds = %36
store i32 0, i32* %8
br label %46
41: ; preds = %30
%42 = load i8**, i8*** %5
%43 = getelementptr inbounds i8*, i8** %42, i64 1
%44 = load i8*, i8** %43
%45 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0), i8* %44)
br label %156
46: ; preds = %40
br label %47
47: ; preds = %46, %29
br label %48
48: ; preds = %76, %47
%49 = load i32, i32* %4
%50 = sub nsw i32 %49, 1
%51 = load i8**, i8*** %5
%52 = getelementptr inbounds i8*, i8** %51, i64 1
%53 = call i32 @getopt(i32 %50, i8** %52, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
store i32 %53, i32* %7
%54 = icmp ne i32 -1, %53
br i1 %54, label %55, label %77
55: ; preds = %48
%56 = load i32, i32* %7
switch i32 %56, label %73 [
i32 100, label %57
i32 118, label %65
]
57: ; preds = %55
%58 = load i32, i32* @optarg
%59 = call i32 @strtoul(i32 %58, i8** %12, i32 16)
store i32 %59, i32* %9
%60 = load i8*, i8** %12
%61 = load i8, i8* %60
%62 = icmp ne i8 %61, 0
br i1 %62, label %63, label %64
63: ; preds = %57
br label %156
64: ; preds = %57
br label %76
65: ; preds = %55
%66 = load i32, i32* @optarg
%67 = call i32 @strtoul(i32 %66, i8** %12, i32 16)
store i32 %67, i32* %10
%68 = load i8*, i8** %12
%69 = load i8, i8* %68
%70 = icmp ne i8 %69, 0
br i1 %70, label %71, label %72
71: ; preds = %65
br label %156
72: ; preds = %65
br label %76
73: ; preds = %55
%74 = load i32, i32* %7
%75 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.4, i64 0, i64 0), i32 %74)
br label %156
76: ; preds = %72, %64
br label %48
77: ; preds = %48
%78 = load i32, i32* %8
%79 = icmp eq i32 -1, %78
br i1 %79, label %80, label %81
80: ; preds = %77
br label %156
81: ; preds = %77
%82 = load i32, i32* @O_RDWR
%83 = call i32 @open(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0), i32 %82)
store i32 %83, i32* %6
%84 = load i32, i32* %6
%85 = icmp eq i32 -1, %84
br i1 %85, label %86, label %88
86: ; preds = %81
%87 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.6, i64 0, i64 0))
store i32 -1, i32* %3
br label %159
88: ; preds = %81
%89 = load i32, i32* %9
%90 = icmp ne i32 %89, 0
br i1 %90, label %91, label %101
91: ; preds = %88
%92 = load i32, i32* %6
%93 = load i32, i32* %9
%94 = load i32, i32* @SEEK_SET
%95 = call i32 @lseek(i32 %92, i32 %93, i32 %94)
%96 = icmp eq i32 -1, %95
br i1 %96, label %97, label %100
97: ; preds = %91
%98 = load i32, i32* %9
%99 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.7, i64 0, i64 0), i32 %98)
br label %155
100: ; preds = %91
br label %101
101: ; preds = %100, %88
%102 = load i32, i32* %10
%103 = trunc i32 %102 to i8
store i8 %103, i8* %11
%104 = load i32, i32* %8
%105 = icmp ne i32 %104, 0
br i1 %105, label %106, label %118
106: ; preds = %101
%107 = load i32, i32* %6
%108 = call i32 @read(i32 %107, i8* %11, i32 1)
%109 = icmp eq i32 -1, %108
br i1 %109, label %110, label %113
110: ; preds = %106
%111 = load i32, i32* %9
%112 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.8, i64 0, i64 0), i32 %111)
br label %155
113: ; preds = %106
%114 = load i32, i32* %9
%115 = load i8, i8* %11
%116 = sext i8 %115 to i32
%117 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.9, i64 0, i64 0), i32 %114, i32 %116)
br label %152
118: ; preds = %101
%119 = load i32, i32* %6
%120 = call i32 @write(i32 %119, i8* %11, i32 1)
%121 = icmp eq i32 -1, %120
br i1 %121, label %122, label %127
122: ; preds = %118
%123 = load i32, i32* %9
%124 = load i8, i8* %11
%125 = sext i8 %124 to i32
%126 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.10, i64 0, i64 0), i32 %123, i32 %125)
br label %155
127: ; preds = %118
%128 = load i8, i8* %11
%129 = sext i8 %128 to i32
%130 = load i32, i32* %9
%131 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.11, i64 0, i64 0), i32 %129, i32 %130)
%132 = load i32, i32* %6
%133 = load i32, i32* %9
%134 = load i32, i32* @SEEK_SET
%135 = call i32 @lseek(i32 %132, i32 %133, i32 %134)
%136 = icmp eq i32 -1, %135
br i1 %136, label %137, label %140
137: ; preds = %127
%138 = load i32, i32* %9
%139 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.7, i64 0, i64 0), i32 %138)
br label %155
140: ; preds = %127
%141 = load i32, i32* %6
%142 = call i32 @read(i32 %141, i8* %11, i32 1)
%143 = icmp eq i32 -1, %142
br i1 %143, label %144, label %147
144: ; preds = %140
%145 = load i32, i32* %9
%146 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.8, i64 0, i64 0), i32 %145)
br label %155
147: ; preds = %140
%148 = load i32, i32* %9
%149 = load i8, i8* %11
%150 = sext i8 %149 to i32
%151 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.12, i64 0, i64 0), i32 %148, i32 %150)
br label %152
152: ; preds = %147, %113
%153 = load i32, i32* %6
%154 = call i32 @close(i32 %153)
store i32 0, i32* %3
br label %159
155: ; preds = %144, %137, %122, %110, %97
store i32 -2, i32* %3
br label %159
156: ; preds = %80, %73, %71, %63, %41, %39, %28, %18
%157 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.13, i64 0, i64 0))
%158 = call i32 (...) @print_usage()
store i32 -1, i32* %3
br label %159
159: ; preds = %156, %155, %152, %86
%160 = load i32, i32* %3
ret i32 %160
}

LLVM IR (-O2):
@.str = [5 x i8] c"read\00"
@.str.1 = [5 x i8] c"blow\00"
@.str.2 = [25 x i8] c"Unsupported option: %s!\0A\00"
@.str.3 = [5 x i8] c"d:v:\00"
@optarg = global i32 0
@.str.4 = [26 x i8] c"Unsupported option: -%c!\0A\00"
@.str.5 = [13 x i8] c"/dev/mxc_iim\00"
@O_RDWR = global i32 0
@SEEK_SET = global i32 0
@.str.7 = [34 x i8] c"lseek failed at bank addr 0x%08x\0A\00"
@.str.8 = [33 x i8] c"Read failed at bank addr 0x%08x\0A\00"
@.str.9 = [33 x i8] c"Value at bank addr 0x%08x: 0x%x\0A\00"
@.str.10 = [49 x i8] c"Write failed at bank addr 0x%08x, value: 0x%08x\0A\00"
@.str.11 = [37 x i8] c"Writting 0x%08x to bank addr 0x%08x\0A\00"
@.str.12 = [35 x i8] c"Value at bank addr 0x%08x: 0x%08x\0A\00"
@str = [20 x i8] c"Invalid parameters!\00"
@str.14 = [25 x i8] c"Can't open /dev/mxc_iim!\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i8
%4 = alloca i8*
%5 = bitcast i8** %4 to i8*
store i8* null, i8** %4
%6 = add i32 %0, -7
%7 = icmp ult i32 %6, -3
br i1 %7, label %92, label %8
8: ; preds = %2
%9 = getelementptr inbounds i8*, i8** %1, i64 1
%10 = load i8*, i8** %9
%11 = tail call i64 @strcmp(i8* %10, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%12 = icmp eq i64 %11, 0
br i1 %12, label %13, label %15
13: ; preds = %8
%14 = icmp eq i32 %0, 4
br i1 %14, label %24, label %92
15: ; preds = %8
%16 = load i8*, i8** %9
%17 = tail call i64 @strcmp(i8* %16, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%18 = icmp eq i64 %17, 0
br i1 %18, label %19, label %21
19: ; preds = %15
%20 = icmp eq i32 %0, 6
br i1 %20, label %24, label %92
21: ; preds = %15
%22 = load i8*, i8** %9
%23 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0), i8* %22)
br label %92
24: ; preds = %19, %13
%25 = add nsw i32 %0, -1
br label %26
26: ; preds = %32, %24
%27 = phi i32 [ %34, %32 ], [ undef, %24 ]
%28 = phi i32 [ %30, %32 ], [ undef, %24 ]
br label %29
29: ; preds = %26, %38
%30 = phi i32 [ %40, %38 ], [ %28, %26 ]
%31 = call i32 @getopt(i32 %25, i8** %9, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
switch i32 %31, label %44 [
i32 -1, label %46
i32 100, label %32
i32 118, label %38
]
32: ; preds = %29
%33 = load i32, i32* @optarg
%34 = call i32 @strtoul(i32 %33, i8** %4, i32 16)
%35 = load i8*, i8** %4
%36 = load i8, i8* %35
%37 = icmp eq i8 %36, 0
br i1 %37, label %26, label %92
38: ; preds = %29
%39 = load i32, i32* @optarg
%40 = call i32 @strtoul(i32 %39, i8** %4, i32 16)
%41 = load i8*, i8** %4
%42 = load i8, i8* %41
%43 = icmp eq i8 %42, 0
br i1 %43, label %29, label %92
44: ; preds = %29
%45 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.4, i64 0, i64 0), i32 %31)
br label %92
46: ; preds = %29
%47 = load i32, i32* @O_RDWR
%48 = call i32 @open(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0), i32 %47)
%49 = icmp eq i32 %48, -1
br i1 %49, label %50, label %52
50: ; preds = %46
%51 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str.14, i64 0, i64 0))
br label %95
52: ; preds = %46
%53 = icmp eq i32 %27, 0
br i1 %53, label %60, label %54
54: ; preds = %52
%55 = load i32, i32* @SEEK_SET
%56 = call i32 @lseek(i32 %48, i32 %27, i32 %55)
%57 = icmp eq i32 %56, -1
br i1 %57, label %58, label %60
58: ; preds = %54
%59 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @.str.7, i64 0, i64 0), i32 %27)
br label %95
60: ; preds = %54, %52
%61 = trunc i32 %30 to i8
store i8 %61, i8* %3
br i1 %12, label %62, label %67
62: ; preds = %60
%63 = call i32 @read(i32 %48, i8* %3, i32 1)
%64 = icmp eq i32 %63, -1
br i1 %64, label %65, label %86
65: ; preds = %62
%66 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str.8, i64 0, i64 0), i32 %27)
br label %95
67: ; preds = %60
%68 = call i32 @write(i32 %48, i8* %3, i32 1)
%69 = icmp eq i32 %68, -1
%70 = shl i32 %30, 24
%71 = ashr exact i32 %70, 24
br i1 %69, label %72, label %74
72: ; preds = %67
%73 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([49 x i8], [49 x i8]* @.str.10, i64 0, i64 0), i32 %27, i32 %71)
br label %95
74: ; preds = %67
%75 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @.str.11, i64 0, i64 0), i32 %71, i32 %27)
%76 = load i32, i32* @SEEK_SET
%77 = call i32 @lseek(i32 %48, i32 %27, i32 %76)
%78 = icmp eq i32 %77, -1
br i1 %78, label %79, label %81
79: ; preds = %74
%80 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @.str.7, i64 0, i64 0), i32 %27)
br label %95
81: ; preds = %74
%82 = call i32 @read(i32 %48, i8* %3, i32 1)
%83 = icmp eq i32 %82, -1
br i1 %83, label %84, label %86
84: ; preds = %81
%85 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str.8, i64 0, i64 0), i32 %27)
br label %95
86: ; preds = %81, %62
%87 = phi i8* [ getelementptr inbounds ([33 x i8], [33 x i8]* @.str.9, i64 0, i64 0), %62 ], [ getelementptr inbounds ([35 x i8], [35 x i8]* @.str.12, i64 0, i64 0), %81 ]
%88 = load i8, i8* %3
%89 = sext i8 %88 to i32
%90 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) %87, i32 %27, i32 %89)
%91 = call i32 @close(i32 %48)
br label %95
92: ; preds = %38, %32, %19, %13, %2, %44, %21
%93 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str, i64 0, i64 0))
%94 = call i32 (...) @print_usage()
br label %95
95: ; preds = %58, %65, %72, %79, %84, %92, %86, %50
%96 = phi i32 [ -1, %92 ], [ -1, %50 ], [ 0, %86 ], [ -2, %84 ], [ -2, %79 ], [ -2, %72 ], [ -2, %65 ], [ -2, %58 ]
ret i32 %96
}