#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*/ alarm(int);
int errno;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ printf(char *, ...);
int pty_setup();
int /*<<< orphan*/ putchar(int);
int read(int, unsigned char *, int);
int /*<<< orphan*/ send_data(int, unsigned char *, char *, int);
int /*<<< orphan*/ setbuf(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ setup_signals();
int /*<<< orphan*/ stdout;
scalar_t__ strcmp(char *, char *);
char *strerror(int);
int /*<<< orphan*/ write(int, char *, int);
void main(int argc, char *argv[]) {
  char *data_dir;
  int mfd, address_size;
  if (argc != 3) {
    printf("Usage: %s [-c|-e] <data_dir>\n", argv[0]);
    printf("Where:  [-c|-e]    Model to simulate, e=EMC, c=Commander\n");
    printf("        <data_dir> Directory that contains data files.\n");
    return;
  }
  if (strcmp(argv[1], "-c") == 0) {
    address_size = 3;
  } else if (strcmp(argv[1], "-e") == 0) {
    address_size = 4;
  }
  data_dir = argv[2];
  setbuf(stdout, 0);
  unsigned char buffer[4096];
  int byte_count, bytes_expected;
  int bytes_read;
  char whirlygig[5] = "-\\|/";
  int whirlygig_ndx = 0;
  if ((mfd = pty_setup()) == -1)
    exit(1);
  setup_signals();
  while (1) {
    alarm(1);
    byte_count = read(mfd, buffer, 1);
    alarm(0);
    if (byte_count < 0) {
      if (errno == 4) {
        write(mfd, "\xAA", 1);
        putchar(whirlygig[whirlygig_ndx++]);
        putchar(0xd);
        if (whirlygig_ndx > 3)
          whirlygig_ndx = 0;
      } else {
        printf("[%d]%s\n", errno, strerror(errno));
      }
      continue;
    }
    switch (buffer[0]) {
    case 0x05:
      bytes_expected = 5;
      break;
    case 0x96:
      bytes_expected = 1;
      break;
    case 0x89:
      bytes_expected = 6;
      break;
    case 0x15:
      bytes_expected = address_size * 2 + 1;
      break;
    default:
      printf("Unknown command %02x.\n", buffer[0]);
      continue;
    }
    bytes_read = 0;
    while (bytes_read < bytes_expected) {
      byte_count = read(mfd, &(buffer[1 + bytes_read]), bytes_expected);
      if (byte_count < 0) {
        printf("%s: error reading device\n", strerror(errno));
        continue;
      }
      bytes_read += byte_count;
    }
    printf("Command: ");
    for (int n = 0; n <= bytes_read; n++)
      printf("%02x ", buffer[n]);
    printf("\n");
    send_data(mfd, buffer, data_dir, address_size);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1050,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x4(%rbp)
je     1216 <main+0x56>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe16(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    0xe26(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    0xe52(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
add    $0x1050,%rsp
pop    %rbp
ret
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe6b(%rip),%rsi
call   1090 <strcmp@plt>
cmp    $0x0,%rax
jne    1240 <main+0x80>
movl   $0x3,-0x20(%rbp)
jmp    126a <main+0xaa>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe44(%rip),%rsi
call   1090 <strcmp@plt>
cmp    $0x0,%rax
jne    1265 <main+0xa5>
movl   $0x4,-0x20(%rbp)
jmp    126a <main+0xaa>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x18(%rbp)
mov    0x2d5b(%rip),%rax
mov    (%rax),%edi
xor    %esi,%esi
call   1050 <setbuf@plt>
mov    0xe0a(%rip),%eax
mov    %eax,-0x1031(%rbp)
mov    0xe02(%rip),%al
mov    %al,-0x102d(%rbp)
movl   $0x0,-0x1038(%rbp)
mov    $0x0,%al
call   10c0 <pty_setup@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0xffffffff,%eax
jne    12c5 <main+0x105>
mov    $0x1,%edi
call   10d0 <exit@plt>
mov    $0x0,%al
call   10a0 <setup_signals@plt>
mov    $0x1,%edi
call   1070 <alarm@plt>
mov    -0x1c(%rbp),%edi
lea    -0x1020(%rbp),%rsi
mov    $0x1,%edx
call   1080 <read@plt>
mov    %eax,-0x1024(%rbp)
xor    %edi,%edi
call   1070 <alarm@plt>
cmpl   $0x0,-0x1024(%rbp)
jge    13a7 <main+0x1e7>
mov    0x2cd5(%rip),%rax
cmpl   $0x4,(%rax)
jne    136e <main+0x1ae>
mov    -0x1c(%rbp),%edi
lea    0xd7d(%rip),%rsi
mov    $0x1,%edx
call   1040 <write@plt>
mov    -0x1038(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0x1038(%rbp)
cltq
movsbl -0x1031(%rbp,%rax,1),%edi
ff
call   1030 <putchar@plt>
mov    $0xd,%edi
call   1030 <putchar@plt>
cmpl   $0x3,-0x1038(%rbp)
jle    1369 <main+0x1a9>
movl   $0x0,-0x1038(%rbp)
jmp    13a2 <main+0x1e2>
mov    0x2c6b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1040(%rbp)
mov    0x2c5c(%rip),%rax
mov    (%rax),%edi
call   10e0 <strerror@plt>
mov    -0x1040(%rbp),%esi
mov    %rax,%rdx
lea    0xd02(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    12cc <main+0x10c>
movzbl -0x1020(%rbp),%eax
mov    %eax,-0x1044(%rbp)
sub    $0x5,%eax
je     1402 <main+0x242>
jmp    13c2 <main+0x202>
mov    -0x1044(%rbp),%eax
sub    $0x15,%eax
je     142f <main+0x26f>
jmp    13d6 <main+0x216>
mov    -0x1044(%rbp),%eax
sub    $0x89,%eax
je     1420 <main+0x260>
jmp    13ec <main+0x22c>
mov    -0x1044(%rbp),%eax
sub    $0x96,%eax
je     1411 <main+0x251>
jmp    1443 <main+0x283>
movl   $0x5,-0x1028(%rbp)
jmp    145d <main+0x29d>
movl   $0x1,-0x1028(%rbp)
jmp    145d <main+0x29d>
movl   $0x6,-0x1028(%rbp)
jmp    145d <main+0x29d>
mov    -0x20(%rbp),%eax
shl    $0x1,%eax
add    $0x1,%eax
mov    %eax,-0x1028(%rbp)
jmp    145d <main+0x29d>
movzbl -0x1020(%rbp),%esi
lea    0xc54(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    12cc <main+0x10c>
movl   $0x0,-0x102c(%rbp)
mov    -0x102c(%rbp),%eax
cmp    -0x1028(%rbp),%eax
jge    14ea <main+0x32a>
mov    -0x1c(%rbp),%edi
mov    -0x102c(%rbp),%eax
add    $0x1,%eax
cltq
lea    -0x1020(%rbp),%rsi
add    %rax,%rsi
mov    -0x1028(%rbp),%edx
call   1080 <read@plt>
mov    %eax,-0x1024(%rbp)
cmpl   $0x0,-0x1024(%rbp)
jge    14d3 <main+0x313>
mov    0x2b2a(%rip),%rax
mov    (%rax),%edi
call   10e0 <strerror@plt>
mov    %rax,%rsi
lea    0xbf5(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    1467 <main+0x2a7>
mov    -0x1024(%rbp),%eax
add    -0x102c(%rbp),%eax
mov    %eax,-0x102c(%rbp)
jmp    1467 <main+0x2a7>
lea    0xbe5(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x0,-0x103c(%rbp)
mov    -0x103c(%rbp),%eax
cmp    -0x102c(%rbp),%eax
jg     1545 <main+0x385>
movslq -0x103c(%rbp),%rax
movzbl -0x1020(%rbp,%rax,1),%esi
ff
lea    0xbb6(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x103c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x103c(%rbp)
jmp    1502 <main+0x342>
lea    0xb42(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x1c(%rbp),%edi
lea    -0x1020(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%ecx
call   10b0 <send_data@plt>
jmp    12cc <main+0x10c>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x1028,%rsp
mov    %rsi,%rbx
cmp    $0x3,%edi
jne    1215 <main+0x45>
mov    0x8(%rbx),%rdi
lea    0xe2a(%rip),%rsi
call   10a0 <strcmp@plt>
test   %rax,%rax
je     124f <main+0x7f>
mov    0x8(%rbx),%rdi
lea    0xe18(%rip),%rsi
call   10a0 <strcmp@plt>
mov    $0x4,%eax
jmp    1254 <main+0x84>
mov    (%rbx),%rsi
lea    0xde1(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
lea    0xe47(%rip),%rdi
call   1040 <puts@plt>
lea    0xe74(%rip),%rdi
add    $0x1028,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <puts@plt>
mov    $0x3,%eax
mov    %rax,0x8(%rsp)
mov    0x10(%rbx),%rax
mov    %rax,0x18(%rsp)
mov    0x2d6f(%rip),%rax
mov    (%rax),%edi
xor    %esi,%esi
call   1060 <setbuf@plt>
xor    %eax,%eax
call   10d0 <pty_setup@plt>
cmp    $0xffffffff,%eax
je     14cd <main+0x2fd>
mov    %eax,%r13d
xor    %eax,%eax
call   10b0 <setup_signals@plt>
mov    0x8(%rsp),%rax
add    %eax,%eax
add    $0x1,%eax
mov    %eax,0x14(%rsp)
lea    0x20(%rsp),%r14
mov    0x2d3a(%rip),%r15
lea    0xd9d(%rip),%r12
xor    %ebp,%ebp
jmp    1306 <main+0x136>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %rbp,%r14
mov    %r13d,%edi
lea    0xd5c(%rip),%rsi
mov    $0x1,%edx
call   1050 <write@plt>
mov    0x10(%rsp),%ebp
movslq %ebp,%rbx
add    $0x1,%ebp
lea    0xd3c(%rip),%rax
movsbl (%rbx,%rax,1),%edi
call   1030 <putchar@plt>
mov    $0xd,%edi
call   1030 <putchar@plt>
cmp    $0x3,%ebx
mov    $0x0,%eax
cmovge %eax,%ebp
mov    %ebp,0x10(%rsp)
mov    %r14,%rbp
nopl   (%rax)
mov    $0x1,%edi
call   1080 <alarm@plt>
mov    %r13d,%edi
mov    %rbp,%rsi
mov    $0x1,%edx
call   1090 <read@plt>
mov    %eax,%r14d
xor    %edi,%edi
call   1080 <alarm@plt>
test   %r14d,%r14d
jns    13c4 <main+0x1f4>
mov    (%r15),%r14d
cmp    $0x4,%r14d
je     12c0 <main+0xf0>
mov    %r14d,%edi
call   10f0 <strerror@plt>
lea    0xcd2(%rip),%rdi
mov    %r14d,%esi
mov    %rax,%rdx
xor    %eax,%eax
call   1070 <printf@plt>
jmp    1310 <main+0x140>
nopl   0x0(%rax,%rax,1)
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    %r13d,%edi
mov    %r14,%rbp
mov    %r14,%rsi
mov    0x18(%rsp),%rdx
mov    0x8(%rsp),%rcx
call   10c0 <send_data@plt>
mov    0x2c47(%rip),%r15
mov    $0x1,%edi
call   1080 <alarm@plt>
mov    %r13d,%edi
mov    %rbp,%rsi
mov    $0x1,%edx
call   1090 <read@plt>
mov    %eax,%ebx
xor    %edi,%edi
call   1080 <alarm@plt>
test   %ebx,%ebx
js     133d <main+0x16d>
mov    0x20(%rsp),%al
cmp    $0x4,%al
jg     13e0 <main+0x210>
cmp    $0x89,%al
je     1400 <main+0x230>
cmp    $0x96,%al
jne    13ed <main+0x21d>
mov    $0x1,%r14d
jmp    140e <main+0x23e>
nopl   0x0(%rax)
cmp    $0x5,%al
je     1408 <main+0x238>
mov    0x14(%rsp),%r14d
cmp    $0x15,%al
je     140e <main+0x23e>
movzbl %al,%esi
lea    0xc3c(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
jmp    1399 <main+0x1c9>
mov    $0x6,%r14d
jmp    140e <main+0x23e>
mov    $0x5,%r14d
xor    %ebx,%ebx
jmp    1427 <main+0x257>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
add    %eax,%ebx
cmp    %r14d,%ebx
jge    1480 <main+0x2b0>
movslq %ebx,%rax
lea    (%rax,%rbp,1),%r15
add    $0x1,%r15
mov    %r13d,%edi
mov    %r15,%rsi
mov    %r14d,%edx
call   1090 <read@plt>
test   %eax,%eax
jns    1420 <main+0x250>
mov    0x2b95(%rip),%rbp
nopl   0x0(%rax,%rax,1)
mov    0x0(%rbp),%edi
call   10f0 <strerror@plt>
mov    %r12,%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %r13d,%edi
mov    %r15,%rsi
mov    %r14d,%edx
call   1090 <read@plt>
test   %eax,%eax
js     1450 <main+0x280>
lea    0x20(%rsp),%rbp
jmp    1420 <main+0x250>
xchg   %ax,%ax
mov    %rbp,%r14
lea    0xbda(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
test   %ebx,%ebx
lea    0xbd4(%rip),%r15
js     1370 <main+0x1a0>
add    $0x1,%ebx
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nop
movzbl 0x20(%rsp,%rbp,1),%esi
mov    %r15,%rdi
xor    %eax,%eax
call   1070 <printf@plt>
add    $0x1,%rbp
cmp    %rbp,%rbx
jne    14b0 <main+0x2e0>
jmp    1370 <main+0x1a0>
mov    $0x1,%edi
call   10e0 <exit@plt>

LLVM IR (-O0):
@.str = [30 x i8] c"Usage: %s [-c|-e] <data_dir>\0A\00"
@.str.1 = [58 x i8] c"Where: [-c|-e] Model to simulate, e=EMC, c=Commander\0A\00"
@.str.2 = [56 x i8] c" <data_dir> Directory that contains data files.\0A\00"
@.str.3 = [3 x i8] c"-c\00"
@.str.4 = [3 x i8] c"-e\00"
@stdout = global i32 0
@__const.main.whirlygig = [5 x i8] c"-\\|/\00"
@errno = global i32 0
@.str.5 = [2 x i8] c"\AA\00"
@.str.6 = [8 x i8] c"[%d]%s\0A\00"
@.str.7 = [23 x i8] c"Unknown command %02x.\0A\00"
@.str.8 = [26 x i8] c"%s: error reading device\0A\00"
@.str.9 = [10 x i8] c"Command: \00"
@.str.10 = [6 x i8] c"%02x \00"
@.str.11 = [2 x i8] c"\0A\00"
define void @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca [4096 x i8]
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca [5 x i8]
%13 = alloca i32
%14 = alloca i32
store i32 %0, i32* %3
store i8** %1, i8*** %4
%15 = load i32, i32* %3
%16 = icmp ne i32 %15, 3
br i1 %16, label %17, label %24
17: ; preds = %2
%18 = load i8**, i8*** %4
%19 = getelementptr inbounds i8*, i8** %18, i64 0
%20 = load i8*, i8** %19
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i8* %20)
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str.1, i64 0, i64 0))
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.2, i64 0, i64 0))
ret void
24: ; preds = %2
%25 = load i8**, i8*** %4
%26 = getelementptr inbounds i8*, i8** %25, i64 1
%27 = load i8*, i8** %26
%28 = call i64 @strcmp(i8* %27, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%29 = icmp eq i64 %28, 0
br i1 %29, label %30, label %31
30: ; preds = %24
store i32 3, i32* %7
br label %39
31: ; preds = %24
%32 = load i8**, i8*** %4
%33 = getelementptr inbounds i8*, i8** %32, i64 1
%34 = load i8*, i8** %33
%35 = call i64 @strcmp(i8* %34, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
%36 = icmp eq i64 %35, 0
br i1 %36, label %37, label %38
37: ; preds = %31
store i32 4, i32* %7
br label %38
38: ; preds = %37, %31
br label %39
39: ; preds = %38, %30
%40 = load i8**, i8*** %4
%41 = getelementptr inbounds i8*, i8** %40, i64 2
%42 = load i8*, i8** %41
store i8* %42, i8** %5
%43 = load i32, i32* @stdout
%44 = call i32 @setbuf(i32 %43, i32 0)
%45 = bitcast [5 x i8]* %12 to i8*
store i32 0, i32* %13
%46 = call i32 (...) @pty_setup()
store i32 %46, i32* %6
%47 = icmp eq i32 %46, -1
br i1 %47, label %48, label %50
48: ; preds = %39
%49 = call i32 @exit(i32 1)
unreachable
50: ; preds = %39
%51 = call i32 (...) @setup_signals()
br label %52
52: ; preds = %50, %83, %95, %139
%53 = call i32 @alarm(i32 1)
%54 = load i32, i32* %6
%55 = getelementptr inbounds [4096 x i8], [4096 x i8]* %8, i64 0, i64 0
%56 = call i32 @read(i32 %54, i8* %55, i32 1)
store i32 %56, i32* %9
%57 = call i32 @alarm(i32 0)
%58 = load i32, i32* %9
%59 = icmp slt i32 %58, 0
br i1 %59, label %60, label %84
60: ; preds = %52
%61 = load i32, i32* @errno
%62 = icmp eq i32 %61, 4
br i1 %62, label %63, label %78
63: ; preds = %60
%64 = load i32, i32* %6
%65 = call i32 @write(i32 %64, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0), i32 1)
%66 = load i32, i32* %13
%67 = add nsw i32 %66, 1
store i32 %67, i32* %13
%68 = sext i32 %66 to i64
%69 = getelementptr inbounds [5 x i8], [5 x i8]* %12, i64 0, i64 %68
%70 = load i8, i8* %69
%71 = sext i8 %70 to i32
%72 = call i32 @putchar(i32 %71)
%73 = call i32 @putchar(i32 13)
%74 = load i32, i32* %13
%75 = icmp sgt i32 %74, 3
br i1 %75, label %76, label %77
76: ; preds = %63
store i32 0, i32* %13
br label %77
77: ; preds = %76, %63
br label %83
78: ; preds = %60
%79 = load i32, i32* @errno
%80 = load i32, i32* @errno
%81 = call i8* @strerror(i32 %80)
%82 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.6, i64 0, i64 0), i32 %79, i8* %81)
br label %83
83: ; preds = %78, %77
br label %52
84: ; preds = %52
%85 = getelementptr inbounds [4096 x i8], [4096 x i8]* %8, i64 0, i64 0
%86 = load i8, i8* %85
%87 = zext i8 %86 to i32
switch i32 %87, label %95 [
i32 5, label %88
i32 150, label %89
i32 137, label %90
i32 21, label %91
]
88: ; preds = %84
store i32 5, i32* %10
br label %100
89: ; preds = %84
store i32 1, i32* %10
br label %100
90: ; preds = %84
store i32 6, i32* %10
br label %100
91: ; preds = %84
%92 = load i32, i32* %7
%93 = mul nsw i32 %92, 2
%94 = add nsw i32 %93, 1
store i32 %94, i32* %10
br label %100
95: ; preds = %84
%96 = getelementptr inbounds [4096 x i8], [4096 x i8]* %8, i64 0, i64 0
%97 = load i8, i8* %96
%98 = zext i8 %97 to i32
%99 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.7, i64 0, i64 0), i32 %98)
br label %52
100: ; preds = %91, %90, %89, %88
store i32 0, i32* %11
br label %101
101: ; preds = %119, %115, %100
%102 = load i32, i32* %11
%103 = load i32, i32* %10
%104 = icmp slt i32 %102, %103
br i1 %104, label %105, label %123
105: ; preds = %101
%106 = load i32, i32* %6
%107 = load i32, i32* %11
%108 = add nsw i32 1, %107
%109 = sext i32 %108 to i64
%110 = getelementptr inbounds [4096 x i8], [4096 x i8]* %8, i64 0, i64 %109
%111 = load i32, i32* %10
%112 = call i32 @read(i32 %106, i8* %110, i32 %111)
store i32 %112, i32* %9
%113 = load i32, i32* %9
%114 = icmp slt i32 %113, 0
br i1 %114, label %115, label %119
115: ; preds = %105
%116 = load i32, i32* @errno
%117 = call i8* @strerror(i32 %116)
%118 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.8, i64 0, i64 0), i8* %117)
br label %101
119: ; preds = %105
%120 = load i32, i32* %9
%121 = load i32, i32* %11
%122 = add nsw i32 %121, %120
store i32 %122, i32* %11
br label %101
123: ; preds = %101
%124 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.9, i64 0, i64 0))
store i32 0, i32* %14
br label %125
125: ; preds = %136, %123
%126 = load i32, i32* %14
%127 = load i32, i32* %11
%128 = icmp sle i32 %126, %127
br i1 %128, label %129, label %139
129: ; preds = %125
%130 = load i32, i32* %14
%131 = sext i32 %130 to i64
%132 = getelementptr inbounds [4096 x i8], [4096 x i8]* %8, i64 0, i64 %131
%133 = load i8, i8* %132
%134 = zext i8 %133 to i32
%135 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.10, i64 0, i64 0), i32 %134)
br label %136
136: ; preds = %129
%137 = load i32, i32* %14
%138 = add nsw i32 %137, 1
store i32 %138, i32* %14
br label %125
139: ; preds = %125
%140 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.11, i64 0, i64 0))
%141 = load i32, i32* %6
%142 = getelementptr inbounds [4096 x i8], [4096 x i8]* %8, i64 0, i64 0
%143 = load i8*, i8** %5
%144 = load i32, i32* %7
%145 = call i32 @send_data(i32 %141, i8* %142, i8* %143, i32 %144)
br label %52
}

LLVM IR (-O2):
@.str = [30 x i8] c"Usage: %s [-c|-e] <data_dir>\0A\00"
@.str.3 = [3 x i8] c"-c\00"
@.str.4 = [3 x i8] c"-e\00"
@stdout = global i32 0
@__const.main.whirlygig = [5 x i8] c"-\\|/\00"
@errno = global i32 0
@.str.5 = [2 x i8] c"\AA\00"
@.str.6 = [8 x i8] c"[%d]%s\0A\00"
@.str.7 = [23 x i8] c"Unknown command %02x.\0A\00"
@.str.8 = [26 x i8] c"%s: error reading device\0A\00"
@.str.9 = [10 x i8] c"Command: \00"
@.str.10 = [6 x i8] c"%02x \00"
@str = [57 x i8] c"Where: [-c|-e] Model to simulate, e=EMC, c=Commander\00"
@str.12 = [55 x i8] c" <data_dir> Directory that contains data files.\00"
define void @main(i32 %0, i8** nocapture %1) {
%3 = alloca [4096 x i8]
%4 = icmp eq i32 %0, 3
br i1 %4, label %10, label %5
5: ; preds = %2
%6 = load i8*, i8** %1
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i8* %6)
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([57 x i8], [57 x i8]* @str, i64 0, i64 0))
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([55 x i8], [55 x i8]* @str.12, i64 0, i64 0))
ret void
10: ; preds = %2
%11 = getelementptr inbounds i8*, i8** %1, i64 1
%12 = load i8*, i8** %11
%13 = tail call i64 @strcmp(i8* %12, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%14 = icmp eq i64 %13, 0
br i1 %14, label %18, label %15
15: ; preds = %10
%16 = load i8*, i8** %11
%17 = tail call i64 @strcmp(i8* %16, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
br label %18
18: ; preds = %15, %10
%19 = phi i32 [ 3, %10 ], [ 4, %15 ]
%20 = getelementptr inbounds i8*, i8** %1, i64 2
%21 = load i8*, i8** %20
%22 = load i32, i32* @stdout
%23 = tail call i32 @setbuf(i32 %22, i32 0)
%24 = getelementptr inbounds [4096 x i8], [4096 x i8]* %3, i64 0, i64 0
%25 = tail call i32 (...) @pty_setup()
%26 = icmp eq i32 %25, -1
br i1 %26, label %27, label %29
27: ; preds = %18
%28 = tail call i32 @exit(i32 1)
unreachable
29: ; preds = %18
%30 = tail call i32 (...) @setup_signals()
%31 = shl nuw nsw i32 %19, 1
%32 = or i32 %31, 1
br label %33
33: ; preds = %43, %29
%34 = phi i32 [ %53, %43 ], [ 0, %29 ]
br label %35
35: ; preds = %33, %54
%36 = call i32 @alarm(i32 1)
%37 = call i32 @read(i32 %25, i8* %24, i32 1)
%38 = call i32 @alarm(i32 0)
%39 = icmp slt i32 %37, 0
br i1 %39, label %40, label %57
40: ; preds = %65, %35
%41 = load i32, i32* @errno
%42 = icmp eq i32 %41, 4
br i1 %42, label %43, label %54
43: ; preds = %40
%44 = call i32 @write(i32 %25, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0), i32 1)
%45 = add nsw i32 %34, 1
%46 = sext i32 %34 to i64
%47 = getelementptr inbounds [5 x i8], [5 x i8]* @__const.main.whirlygig, i64 0, i64 %46
%48 = load i8, i8* %47
%49 = sext i8 %48 to i32
%50 = call i32 @putchar(i32 %49)
%51 = call i32 @putchar(i32 13)
%52 = icmp sgt i32 %34, 2
%53 = select i1 %52, i32 0, i32 %45
br label %33
54: ; preds = %40
%55 = call i8* @strerror(i32 %41)
%56 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.6, i64 0, i64 0), i32 %41, i8* %55)
br label %35
57: ; preds = %35, %65
%58 = load i8, i8* %24
switch i8 %58, label %62 [
i8 5, label %70
i8 -106, label %59
i8 -119, label %60
i8 21, label %61
]
59: ; preds = %57
br label %70
60: ; preds = %57
br label %70
61: ; preds = %57
br label %70
62: ; preds = %57
%63 = zext i8 %58 to i32
%64 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.7, i64 0, i64 0), i32 %63)
br label %65
65: ; preds = %62, %95
%66 = call i32 @alarm(i32 1)
%67 = call i32 @read(i32 %25, i8* %24, i32 1)
%68 = call i32 @alarm(i32 0)
%69 = icmp slt i32 %67, 0
br i1 %69, label %40, label %57
70: ; preds = %57, %61, %60, %59
%71 = phi i32 [ %32, %61 ], [ 6, %60 ], [ 1, %59 ], [ 5, %57 ]
br label %72
72: ; preds = %70, %85
%73 = phi i32 [ 0, %70 ], [ %87, %85 ]
%74 = add nsw i32 %73, 1
%75 = sext i32 %74 to i64
%76 = getelementptr inbounds [4096 x i8], [4096 x i8]* %3, i64 0, i64 %75
%77 = call i32 @read(i32 %25, i8* %76, i32 %71)
%78 = icmp slt i32 %77, 0
br i1 %78, label %79, label %85
79: ; preds = %72, %79
%80 = load i32, i32* @errno
%81 = call i8* @strerror(i32 %80)
%82 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.8, i64 0, i64 0), i8* %81)
%83 = call i32 @read(i32 %25, i8* %76, i32 %71)
%84 = icmp slt i32 %83, 0
br i1 %84, label %79, label %85
85: ; preds = %79, %72
%86 = phi i32 [ %77, %72 ], [ %83, %79 ]
%87 = add nsw i32 %86, %73
%88 = icmp slt i32 %87, %71
br i1 %88, label %72, label %89
89: ; preds = %85
%90 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.9, i64 0, i64 0))
%91 = icmp slt i32 %87, 0
br i1 %91, label %95, label %92
92: ; preds = %89
%93 = add nuw i32 %87, 1
%94 = zext i32 %93 to i64
br label %98
95: ; preds = %98, %89
%96 = call i32 @putchar(i32 10)
%97 = call i32 @send_data(i32 %25, i8* %24, i8* %21, i32 %19)
br label %65
98: ; preds = %92, %98
%99 = phi i64 [ 0, %92 ], [ %104, %98 ]
%100 = getelementptr inbounds [4096 x i8], [4096 x i8]* %3, i64 0, i64 %99
%101 = load i8, i8* %100
%102 = zext i8 %101 to i32
%103 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.10, i64 0, i64 0), i32 %102)
%104 = add nuw nsw i64 %99, 1
%105 = icmp eq i64 %104, %94
br i1 %105, label %95, label %98
}