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

/* Variables and functions */
int /*<<< orphan*/ O_RDWR;
int /*<<< orphan*/ _IO(unsigned char, int /*<<< orphan*/);
int /*<<< orphan*/ close(int);
int errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
size_t fread(char *, int, size_t, int /*<<< orphan*/);
int /*<<< orphan*/ free(char *);
int fwrite(char *, size_t, int, int /*<<< orphan*/);
int ioctl(int, int /*<<< orphan*/);
char *malloc(size_t);
int open(char const *, int /*<<< orphan*/);
size_t read(int, char *, size_t);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ stdout;
scalar_t__ strcasecmp(char const *, char *);
char *strerror(int);
int /*<<< orphan*/ usage(int, char **);
size_t write(int, char *, size_t);
int main(int argc, char **argv) {
  const char *command, *devpath = "/dev/ucmb";
  int res, errcode = 0;
  int ucmb_fd;
  char *buf;
  size_t count, buflen;
  ssize_t nrbytes;
  if (argc != 2 && argc != 3) {
    usage(argc, argv);
    return 1;
  }
  if (argc == 3)
    devpath = argv[2];
  command = argv[1];
  ucmb_fd = open(devpath, O_RDWR);
  if (ucmb_fd == -1) {
    fprintf(stderr, "Failed to open %s\n", "/dev/ucmb");
    errcode = 1;
    goto out;
  }
  buflen = 4096;
  buf = malloc(buflen);
  if (!buf) {
    fprintf(stderr, "Out of memory\n");
    errcode = 1;
    goto out_close;
  }
  if (strcasecmp(command, "read") == 0) {
    nrbytes = read(ucmb_fd, buf, buflen);
    if (nrbytes < 0) {
      fprintf(stderr, "Failed to read UCMB: %s (%d)\n", strerror(errno), errno);
      errcode = 1;
      goto out_free;
    }
    if (fwrite(buf, nrbytes, 1, stdout) != 1) {
      fprintf(stderr, "Failed to write stdout\n");
      errcode = 1;
      goto out_free;
    }
  } else if (strcasecmp(command, "write") == 0) {
    count = fread(buf, 1, buflen, stdin);
    if (!count) {
      fprintf(stderr, "Failed to read stdin\n");
      errcode = 1;
      goto out_free;
    }
    nrbytes = write(ucmb_fd, buf, count);
    if (nrbytes != count) {
      fprintf(stderr, "Failed to write UCMB: %s (%d)\n", strerror(errno),
              errno);
      errcode = 1;
      goto out_free;
    }
  } else if (strcasecmp(command, "reset") == 0) {
    res = ioctl(ucmb_fd, _IO(('U' | 'C' | 'M' | 'B'), 0));
    if (res) {
      fprintf(stderr, "RESET ioctl failed: %s (%d)\n",
              strerror(res < 0 ? -res : res), res);
      errcode = 1;
      goto out_free;
    }
  } else {
    usage(argc, argv);
    errcode = 1;
    goto out_free;
  }
out_free:
  free(buf);
out_close:
  close(ucmb_fd);
out:
  return errcode;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe03(%rip),%rax
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x28(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     1234 <main+0x54>
cmpl   $0x3,-0x8(%rbp)
je     1234 <main+0x54>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   10d0 <usage@plt>
movl   $0x1,-0x4(%rbp)
jmp    1555 <main+0x375>
cmpl   $0x3,-0x8(%rbp)
jne    124a <main+0x6a>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x20(%rbp),%rdi
mov    0x2d87(%rip),%rax
mov    (%rax),%esi
call   10e0 <open@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0xffffffff,-0x2c(%rbp)
jne    129f <main+0xbf>
mov    0x2d54(%rip),%rax
mov    (%rax),%edi
lea    0xd85(%rip),%rsi
lea    0xd74(%rip),%rdx
mov    $0x0,%al
call   10b0 <fprintf@plt>
movl   $0x1,-0x28(%rbp)
jmp    154f <main+0x36f>
movq   $0x1000,-0x48(%rbp)
mov    -0x48(%rbp),%rdi
call   10c0 <malloc@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    12e2 <main+0x102>
mov    0x2d0a(%rip),%rax
mov    (%rax),%edi
lea    0xd4e(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
movl   $0x1,-0x28(%rbp)
jmp    1547 <main+0x367>
mov    -0x18(%rbp),%rdi
lea    0xd3f(%rip),%rsi
call   1040 <strcasecmp@plt>
cmp    $0x0,%rax
jne    13aa <main+0x1ca>
mov    -0x2c(%rbp),%edi
mov    -0x38(%rbp),%rsi
mov    -0x48(%rbp),%rdx
call   10a0 <read@plt>
mov    %rax,-0x50(%rbp)
cmpq   $0x0,-0x50(%rbp)
jae    135e <main+0x17e>
mov    0x2cae(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x54(%rbp)
mov    0x2c9a(%rip),%rax
mov    (%rax),%edi
call   1100 <strerror@plt>
mov    -0x54(%rbp),%edi
mov    %rax,%rdx
mov    0x2c86(%rip),%rax
mov    (%rax),%ecx
lea    0xce6(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
movl   $0x1,-0x28(%rbp)
jmp    153e <main+0x35e>
mov    -0x38(%rbp),%rdi
mov    -0x50(%rbp),%rsi
mov    0x2c53(%rip),%rax
mov    (%rax),%ecx
mov    $0x1,%edx
call   10f0 <fwrite@plt>
cmp    $0x1,%eax
je     13a5 <main+0x1c5>
mov    0x2c47(%rip),%rax
mov    (%rax),%edi
lea    0xcbd(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
movl   $0x1,-0x28(%rbp)
jmp    153e <main+0x35e>
jmp    1539 <main+0x359>
mov    -0x18(%rbp),%rdi
lea    0xcb2(%rip),%rsi
call   1040 <strcasecmp@plt>
cmp    $0x0,%rax
jne    147b <main+0x29b>
mov    -0x38(%rbp),%rdi
mov    -0x48(%rbp),%rdx
mov    0x2c0d(%rip),%rax
mov    (%rax),%ecx
mov    $0x1,%esi
call   1050 <fread@plt>
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x40(%rbp)
jne    1411 <main+0x231>
mov    0x2bdb(%rip),%rax
mov    (%rax),%edi
lea    0xc6f(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
movl   $0x1,-0x28(%rbp)
jmp    153e <main+0x35e>
mov    -0x2c(%rbp),%edi
mov    -0x38(%rbp),%rsi
mov    -0x40(%rbp),%rdx
call   1060 <write@plt>
mov    %rax,-0x50(%rbp)
mov    -0x50(%rbp),%rax
cmp    -0x40(%rbp),%rax
je     1476 <main+0x296>
mov    0x2b96(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x58(%rbp)
mov    0x2b82(%rip),%rax
mov    (%rax),%edi
call   1100 <strerror@plt>
mov    -0x58(%rbp),%edi
mov    %rax,%rdx
mov    0x2b6e(%rip),%rax
mov    (%rax),%ecx
lea    0xc20(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
movl   $0x1,-0x28(%rbp)
jmp    153e <main+0x35e>
jmp    1534 <main+0x354>
mov    -0x18(%rbp),%rdi
lea    0xc1c(%rip),%rsi
call   1040 <strcasecmp@plt>
cmp    $0x0,%rax
jne    1517 <main+0x337>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x5c(%rbp)
mov    $0x5f,%edi
xor    %esi,%esi
call   1070 <_IO@plt>
mov    -0x5c(%rbp),%edi
mov    %eax,%esi
call   1080 <ioctl@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
je     1512 <main+0x332>
mov    0x2b0b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x60(%rbp)
cmpl   $0x0,-0x24(%rbp)
jge    14e1 <main+0x301>
xor    %eax,%eax
sub    -0x24(%rbp),%eax
mov    %eax,-0x64(%rbp)
jmp    14e7 <main+0x307>
mov    -0x24(%rbp),%eax
mov    %eax,-0x64(%rbp)
mov    -0x64(%rbp),%edi
call   1100 <strerror@plt>
mov    -0x60(%rbp),%edi
mov    %rax,%rdx
mov    -0x24(%rbp),%ecx
lea    0xba9(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
movl   $0x1,-0x28(%rbp)
jmp    153e <main+0x35e>
jmp    152f <main+0x34f>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   10d0 <usage@plt>
movl   $0x1,-0x28(%rbp)
jmp    153e <main+0x35e>
jmp    1534 <main+0x354>
jmp    1539 <main+0x359>
jmp    153e <main+0x35e>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
mov    -0x2c(%rbp),%edi
call   1090 <close@plt>
mov    -0x28(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rsi,%rbp
mov    %edi,%ebx
mov    %edi,%eax
and    $0xfffffffe,%eax
cmp    $0x2,%eax
jne    1202 <main+0x22>
cmp    $0x3,%ebx
jne    1216 <main+0x36>
mov    0x10(%rbp),%rdi
jmp    121d <main+0x3d>
mov    %ebx,%edi
mov    %rbp,%rsi
call   10d0 <usage@plt>
mov    $0x1,%ebp
jmp    1404 <main+0x224>
lea    0xde3(%rip),%rdi
mov    0x8(%rbp),%r12
mov    0x2dc0(%rip),%rax
mov    (%rax),%esi
call   10e0 <open@plt>
cmp    $0xffffffff,%eax
je     12a4 <main+0xc4>
mov    %eax,%r15d
mov    $0x1000,%edi
call   10c0 <malloc@plt>
test   %rax,%rax
je     12cc <main+0xec>
mov    %rax,%r14
lea    0xdd8(%rip),%rsi
mov    %r12,%rdi
call   1040 <strcasecmp@plt>
test   %rax,%rax
je     12ed <main+0x10d>
lea    0xddd(%rip),%rsi
mov    %r12,%rdi
call   1040 <strcasecmp@plt>
test   %rax,%rax
je     133d <main+0x15d>
lea    0xe00(%rip),%rsi
mov    %r12,%rdi
call   1040 <strcasecmp@plt>
test   %rax,%rax
je     13a7 <main+0x1c7>
mov    %ebx,%edi
mov    %rbp,%rsi
call   10d0 <usage@plt>
jmp    13ef <main+0x20f>
mov    0x2d25(%rip),%rax
mov    (%rax),%edi
lea    0xd56(%rip),%rsi
lea    0xd45(%rip),%rdx
xor    %eax,%eax
call   10b0 <fprintf@plt>
mov    $0x1,%ebp
jmp    1404 <main+0x224>
mov    0x2cfd(%rip),%rax
mov    (%rax),%edi
lea    0xd41(%rip),%rsi
xor    %eax,%eax
call   10b0 <fprintf@plt>
mov    $0x1,%ebp
jmp    13fc <main+0x21c>
mov    $0x1000,%edx
mov    %r15d,%edi
mov    %r14,%rsi
call   10a0 <read@plt>
mov    0x2cbc(%rip),%rcx
mov    (%rcx),%ecx
mov    %r14,%rdi
mov    %rax,%rsi
mov    $0x1,%edx
call   10f0 <fwrite@plt>
xor    %ebp,%ebp
cmp    $0x1,%eax
je     13f4 <main+0x214>
mov    0x2ca8(%rip),%rax
mov    (%rax),%edi
lea    0xd00(%rip),%rsi
xor    %eax,%eax
call   10b0 <fprintf@plt>
jmp    13ef <main+0x20f>
mov    0x2c9c(%rip),%rax
mov    (%rax),%ecx
mov    $0x1,%ebp
mov    $0x1000,%edx
mov    %r14,%rdi
mov    $0x1,%esi
call   1050 <fread@plt>
test   %rax,%rax
je     140f <main+0x22f>
mov    %rax,%rbx
mov    %r15d,%edi
mov    %r14,%rsi
mov    %rax,%rdx
call   1060 <write@plt>
xor    %ebp,%ebp
cmp    %rbx,%rax
je     13f4 <main+0x214>
mov    0x2c4b(%rip),%rax
mov    (%rax),%ebx
mov    0x2c3a(%rip),%rbp
mov    0x0(%rbp),%edi
call   1100 <strerror@plt>
mov    0x0(%rbp),%ecx
lea    0xcc5(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
jmp    13e8 <main+0x208>
xor    %ebp,%ebp
mov    $0x5f,%edi
xor    %esi,%esi
call   1070 <_IO@plt>
mov    %r15d,%edi
mov    %eax,%esi
call   1080 <ioctl@plt>
test   %eax,%eax
je     13f4 <main+0x214>
mov    %eax,%ebx
mov    0x2c04(%rip),%rax
mov    (%rax),%ebp
mov    %ebx,%edi
neg    %edi
cmovs  %ebx,%edi
call   1100 <strerror@plt>
lea    0xca9(%rip),%rsi
mov    %ebp,%edi
mov    %rax,%rdx
mov    %ebx,%ecx
xor    %eax,%eax
call   10b0 <fprintf@plt>
mov    $0x1,%ebp
mov    %r14,%rdi
call   1030 <free@plt>
mov    %r15d,%edi
call   1090 <close@plt>
mov    %ebp,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2bba(%rip),%rax
mov    (%rax),%edi
lea    0xc30(%rip),%rsi
xor    %eax,%eax
call   10b0 <fprintf@plt>
jmp    13f4 <main+0x214>

LLVM IR (-O0):
@.str = [10 x i8] c"/dev/ucmb\00"
@O_RDWR = global i32 0
@stderr = global i32 0
@.str.1 = [19 x i8] c"Failed to open %s\0A\00"
@.str.2 = [15 x i8] c"Out of memory\0A\00"
@.str.3 = [5 x i8] c"read\00"
@.str.4 = [30 x i8] c"Failed to read UCMB: %s (%d)\0A\00"
@errno = global i32 0
@stdout = global i32 0
@.str.5 = [24 x i8] c"Failed to write stdout\0A\00"
@.str.6 = [6 x i8] c"write\00"
@stdin = global i32 0
@.str.7 = [22 x i8] c"Failed to read stdin\0A\00"
@.str.8 = [31 x i8] c"Failed to write UCMB: %s (%d)\0A\00"
@.str.9 = [6 x i8] c"reset\00"
@.str.10 = [29 x i8] c"RESET ioctl failed: %s (%d)\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i8*
%12 = alloca i64
%13 = alloca i64
%14 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8** %7
store i32 0, i32* %9
%15 = load i32, i32* %4
%16 = icmp ne i32 %15, 2
br i1 %16, label %17, label %24
17: ; preds = %2
%18 = load i32, i32* %4
%19 = icmp ne i32 %18, 3
br i1 %19, label %20, label %24
20: ; preds = %17
%21 = load i32, i32* %4
%22 = load i8**, i8*** %5
%23 = call i32 @usage(i32 %21, i8** %22)
store i32 1, i32* %3
br label %147
24: ; preds = %17, %2
%25 = load i32, i32* %4
%26 = icmp eq i32 %25, 3
br i1 %26, label %27, label %31
27: ; preds = %24
%28 = load i8**, i8*** %5
%29 = getelementptr inbounds i8*, i8** %28, i64 2
%30 = load i8*, i8** %29
store i8* %30, i8** %7
br label %31
31: ; preds = %27, %24
%32 = load i8**, i8*** %5
%33 = getelementptr inbounds i8*, i8** %32, i64 1
%34 = load i8*, i8** %33
store i8* %34, i8** %6
%35 = load i8*, i8** %7
%36 = load i32, i32* @O_RDWR
%37 = call i32 @open(i8* %35, i32 %36)
store i32 %37, i32* %10
%38 = load i32, i32* %10
%39 = icmp eq i32 %38, -1
br i1 %39, label %40, label %43
40: ; preds = %31
%41 = load i32, i32* @stderr
%42 = call i32 (i32, i8*, ...) @fprintf(i32 %41, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %9
br label %145
43: ; preds = %31
store i64 4096, i64* %13
%44 = load i64, i64* %13
%45 = call i8* @malloc(i64 %44)
store i8* %45, i8** %11
%46 = load i8*, i8** %11
%47 = icmp ne i8* %46, null
br i1 %47, label %51, label %48
48: ; preds = %43
%49 = load i32, i32* @stderr
%50 = call i32 (i32, i8*, ...) @fprintf(i32 %49, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %9
br label %142
51: ; preds = %43
%52 = load i8*, i8** %6
%53 = call i64 @strcasecmp(i8* %52, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%54 = icmp eq i64 %53, 0
br i1 %54, label %55, label %78
55: ; preds = %51
%56 = load i32, i32* %10
%57 = load i8*, i8** %11
%58 = load i64, i64* %13
%59 = call i64 @read(i32 %56, i8* %57, i64 %58)
store i64 %59, i64* %14
%60 = load i64, i64* %14
%61 = icmp ult i64 %60, 0
br i1 %61, label %62, label %68
62: ; preds = %55
%63 = load i32, i32* @stderr
%64 = load i32, i32* @errno
%65 = call i8* @strerror(i32 %64)
%66 = load i32, i32* @errno
%67 = call i32 (i32, i8*, ...) @fprintf(i32 %63, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.4, i64 0, i64 0), i8* %65, i32 %66)
store i32 1, i32* %9
br label %139
68: ; preds = %55
%69 = load i8*, i8** %11
%70 = load i64, i64* %14
%71 = load i32, i32* @stdout
%72 = call i32 @fwrite(i8* %69, i64 %70, i32 1, i32 %71)
%73 = icmp ne i32 %72, 1
br i1 %73, label %74, label %77
74: ; preds = %68
%75 = load i32, i32* @stderr
%76 = call i32 (i32, i8*, ...) @fprintf(i32 %75, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.5, i64 0, i64 0))
store i32 1, i32* %9
br label %139
77: ; preds = %68
br label %138
78: ; preds = %51
%79 = load i8*, i8** %6
%80 = call i64 @strcasecmp(i8* %79, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0))
%81 = icmp eq i64 %80, 0
br i1 %81, label %82, label %107
82: ; preds = %78
%83 = load i8*, i8** %11
%84 = load i64, i64* %13
%85 = load i32, i32* @stdin
%86 = call i64 @fread(i8* %83, i32 1, i64 %84, i32 %85)
store i64 %86, i64* %12
%87 = load i64, i64* %12
%88 = icmp ne i64 %87, 0
br i1 %88, label %92, label %89
89: ; preds = %82
%90 = load i32, i32* @stderr
%91 = call i32 (i32, i8*, ...) @fprintf(i32 %90, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.7, i64 0, i64 0))
store i32 1, i32* %9
br label %139
92: ; preds = %82
%93 = load i32, i32* %10
%94 = load i8*, i8** %11
%95 = load i64, i64* %12
%96 = call i64 @write(i32 %93, i8* %94, i64 %95)
store i64 %96, i64* %14
%97 = load i64, i64* %14
%98 = load i64, i64* %12
%99 = icmp ne i64 %97, %98
br i1 %99, label %100, label %106
100: ; preds = %92
%101 = load i32, i32* @stderr
%102 = load i32, i32* @errno
%103 = call i8* @strerror(i32 %102)
%104 = load i32, i32* @errno
%105 = call i32 (i32, i8*, ...) @fprintf(i32 %101, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.8, i64 0, i64 0), i8* %103, i32 %104)
store i32 1, i32* %9
br label %139
106: ; preds = %92
br label %137
107: ; preds = %78
%108 = load i8*, i8** %6
%109 = call i64 @strcasecmp(i8* %108, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.9, i64 0, i64 0))
%110 = icmp eq i64 %109, 0
br i1 %110, label %111, label %132
111: ; preds = %107
%112 = load i32, i32* %10
%113 = call i32 @_IO(i8 zeroext 95, i32 0)
%114 = call i32 @ioctl(i32 %112, i32 %113)
store i32 %114, i32* %8
%115 = load i32, i32* %8
%116 = icmp ne i32 %115, 0
br i1 %116, label %117, label %131
117: ; preds = %111
%118 = load i32, i32* @stderr
%119 = load i32, i32* %8
%120 = icmp slt i32 %119, 0
br i1 %120, label %121, label %124
121: ; preds = %117
%122 = load i32, i32* %8
%123 = sub nsw i32 0, %122
br label %126
124: ; preds = %117
%125 = load i32, i32* %8
br label %126
126: ; preds = %124, %121
%127 = phi i32 [ %123, %121 ], [ %125, %124 ]
%128 = call i8* @strerror(i32 %127)
%129 = load i32, i32* %8
%130 = call i32 (i32, i8*, ...) @fprintf(i32 %118, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.10, i64 0, i64 0), i8* %128, i32 %129)
store i32 1, i32* %9
br label %139
131: ; preds = %111
br label %136
132: ; preds = %107
%133 = load i32, i32* %4
%134 = load i8**, i8*** %5
%135 = call i32 @usage(i32 %133, i8** %134)
store i32 1, i32* %9
br label %139
136: ; preds = %131
br label %137
137: ; preds = %136, %106
br label %138
138: ; preds = %137, %77
br label %139
139: ; preds = %138, %132, %126, %100, %89, %74, %62
%140 = load i8*, i8** %11
%141 = call i32 @free(i8* %140)
br label %142
142: ; preds = %139, %48
%143 = load i32, i32* %10
%144 = call i32 @close(i32 %143)
br label %145
145: ; preds = %142, %40
%146 = load i32, i32* %9
store i32 %146, i32* %3
br label %147
147: ; preds = %145, %20
%148 = load i32, i32* %3
ret i32 %148
}

LLVM IR (-O2):
@.str = [10 x i8] c"/dev/ucmb\00"
@O_RDWR = global i32 0
@stderr = global i32 0
@.str.1 = [19 x i8] c"Failed to open %s\0A\00"
@.str.2 = [15 x i8] c"Out of memory\0A\00"
@.str.3 = [5 x i8] c"read\00"
@errno = global i32 0
@stdout = global i32 0
@.str.5 = [24 x i8] c"Failed to write stdout\0A\00"
@.str.6 = [6 x i8] c"write\00"
@stdin = global i32 0
@.str.7 = [22 x i8] c"Failed to read stdin\0A\00"
@.str.8 = [31 x i8] c"Failed to write UCMB: %s (%d)\0A\00"
@.str.9 = [6 x i8] c"reset\00"
@.str.10 = [29 x i8] c"RESET ioctl failed: %s (%d)\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = and i32 %0, -2
%4 = icmp eq i32 %3, 2
br i1 %4, label %7, label %5
5: ; preds = %2
%6 = tail call i32 @usage(i32 %0, i8** %1)
br label %78
7: ; preds = %2
%8 = icmp eq i32 %0, 3
br i1 %8, label %9, label %12
9: ; preds = %7
%10 = getelementptr inbounds i8*, i8** %1, i64 2
%11 = load i8*, i8** %10
br label %12
12: ; preds = %9, %7
%13 = phi i8* [ %11, %9 ], [ getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), %7 ]
%14 = getelementptr inbounds i8*, i8** %1, i64 1
%15 = load i8*, i8** %14
%16 = load i32, i32* @O_RDWR
%17 = tail call i32 @open(i8* %13, i32 %16)
%18 = icmp eq i32 %17, -1
br i1 %18, label %19, label %22
19: ; preds = %12
%20 = load i32, i32* @stderr
%21 = tail call i32 (i32, i8*, ...) @fprintf(i32 %20, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
br label %78
22: ; preds = %12
%23 = tail call dereferenceable_or_null(4096) i8* @malloc(i64 4096)
%24 = icmp eq i8* %23, null
br i1 %24, label %25, label %28
25: ; preds = %22
%26 = load i32, i32* @stderr
%27 = tail call i32 (i32, i8*, ...) @fprintf(i32 %26, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
br label %75
28: ; preds = %22
%29 = tail call i64 @strcasecmp(i8* %15, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%30 = icmp eq i64 %29, 0
br i1 %30, label %31, label %39
31: ; preds = %28
%32 = tail call i64 @read(i32 %17, i8* %23, i64 4096)
%33 = load i32, i32* @stdout
%34 = tail call i32 @fwrite(i8* %23, i64 %32, i32 1, i32 %33)
%35 = icmp eq i32 %34, 1
br i1 %35, label %72, label %36
36: ; preds = %31
%37 = load i32, i32* @stderr
%38 = tail call i32 (i32, i8*, ...) @fprintf(i32 %37, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.5, i64 0, i64 0))
br label %72
39: ; preds = %28
%40 = tail call i64 @strcasecmp(i8* %15, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0))
%41 = icmp eq i64 %40, 0
br i1 %41, label %42, label %58
42: ; preds = %39
%43 = load i32, i32* @stdin
%44 = tail call i64 @fread(i8* %23, i32 1, i64 4096, i32 %43)
%45 = icmp eq i64 %44, 0
br i1 %45, label %46, label %49
46: ; preds = %42
%47 = load i32, i32* @stderr
%48 = tail call i32 (i32, i8*, ...) @fprintf(i32 %47, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.7, i64 0, i64 0))
br label %72
49: ; preds = %42
%50 = tail call i64 @write(i32 %17, i8* %23, i64 %44)
%51 = icmp eq i64 %50, %44
br i1 %51, label %72, label %52
52: ; preds = %49
%53 = load i32, i32* @stderr
%54 = load i32, i32* @errno
%55 = tail call i8* @strerror(i32 %54)
%56 = load i32, i32* @errno
%57 = tail call i32 (i32, i8*, ...) @fprintf(i32 %53, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.8, i64 0, i64 0), i8* %55, i32 %56)
br label %72
58: ; preds = %39
%59 = tail call i64 @strcasecmp(i8* %15, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.9, i64 0, i64 0))
%60 = icmp eq i64 %59, 0
br i1 %60, label %61, label %70
61: ; preds = %58
%62 = tail call i32 @_IO(i8 zeroext 95, i32 0)
%63 = tail call i32 @ioctl(i32 %17, i32 %62)
%64 = icmp eq i32 %63, 0
br i1 %64, label %72, label %65
65: ; preds = %61
%66 = load i32, i32* @stderr
%67 = tail call i32 @llvm.abs.i32(i32 %63, i1 true)
%68 = tail call i8* @strerror(i32 %67)
%69 = tail call i32 (i32, i8*, ...) @fprintf(i32 %66, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.10, i64 0, i64 0), i8* %68, i32 %63)
br label %72
70: ; preds = %58
%71 = tail call i32 @usage(i32 %0, i8** %1)
br label %72
72: ; preds = %31, %61, %49, %70, %65, %52, %46, %36
%73 = phi i32 [ 1, %36 ], [ 0, %31 ], [ 1, %52 ], [ 0, %49 ], [ 1, %46 ], [ 1, %65 ], [ 0, %61 ], [ 1, %70 ]
%74 = tail call i32 @free(i8* %23)
br label %75
75: ; preds = %72, %25
%76 = phi i32 [ %73, %72 ], [ 1, %25 ]
%77 = tail call i32 @close(i32 %17)
br label %78
78: ; preds = %19, %75, %5
%79 = phi i32 [ 1, %5 ], [ 1, %19 ], [ %76, %75 ]
ret i32 %79
}