#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 */
struct stat {
  int st_size;
};
typedef int ssize_t;
typedef int intmax_t;

/* Variables and functions */
int EXIT_FAILURE;
int EXIT_SUCCESS;
int O_NOCTTY;
int O_RDONLY;
int O_RDWR;
int O_SYNC;
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ abort();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int getopt(int, char **, char *);
int /*<<< orphan*/ isprint(char);
int /*<<< orphan*/ lseek(int, int /*<<< orphan*/, int /*<<< orphan*/);
int open(char *, int);
char *optarg;
char optopt;
int /*<<< orphan*/ printf(char *, ...);
int read(int, char *, int);
int /*<<< orphan*/ restart_mojo(int);
scalar_t__ setup_serial(int);
int stat(char *, struct stat *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ wait_for_fd(int, int /*<<< orphan*/);
int write(int, char *, int);
int main(int argc, char *argv[]) {
  int c, fd, fd2, flash_size = 0;
  ssize_t numRead;
  char *portname = NULL;
  char *binpath = NULL;
  int clearflash = 0, verify = 0, ramonly = 0;
  char buf[256], len[4];
  struct stat statbuf;
  while ((c = getopt(argc, argv, "crvd:f:")) != -1)
    switch (c) {
    case 'c':
      clearflash = 1;
      break;
    case 'd':
      portname = optarg;
      break;
    case 'f':
      binpath = optarg;
      break;
    case 'r':
      ramonly = 1;
      break;
    case 'v':
      verify = 1;
      break;
    case '?':
      if (optopt == 'c')
        fprintf(stderr, "Option -%c requires path to binary.\n", optopt);
      else if (isprint(optopt))
        fprintf(stderr, "Unknown option `-%c'.\n", optopt);
      else
        fprintf(stderr, "Unknown option character `\\x%x'.\n", optopt);
      return EXIT_FAILURE;
    default:
      fprintf(stderr, "%s: -d <dev> [-c | -r | -v] [-f <bin>]\n", argv[0]);
      fprintf(stderr, "\t-r : load to ram\n");
      fprintf(stderr, "\t-v : verify flash after write\n");
      fprintf(stderr, "\t-c : clear flash\n");
      abort();
    }
  if (!portname) {
    fprintf(stderr, "%s: -d <dev> [-c | -r | -v] [-f <bin>]\n", argv[0]);
    fprintf(stderr, "\t-r : load to ram\n");
    fprintf(stderr, "\t-v : verify flash after write\n");
    fprintf(stderr, "\t-c : clear flash\n");
    return EXIT_FAILURE;
  }
  if ((fd = open(portname, O_RDWR | O_NOCTTY | O_SYNC)) < 0) {
    fprintf(stderr, "Failed opening %s\n", portname);
    return EXIT_FAILURE;
  }
  if (setup_serial(fd)) {
    fprintf(stderr, "Failed setting attributes of %s\n", portname);
    return EXIT_FAILURE;
  }
  restart_mojo(fd);
  if (!ramonly && clearflash) {
    printf("Erasing flash...\n");
    write(fd, "E", 1);
    wait_for_fd(fd, 0);
    if (read(fd, buf, 1) == 1 && buf[0] == 'D')
      printf("Erasing done. Read %c\n", buf[0]);
    return EXIT_SUCCESS;
  }
  if (!binpath) {
    fprintf(stderr, "Error: No flash file specified\n");
    return EXIT_FAILURE;
  }
  if ((fd2 = open(binpath, O_RDONLY)) < 0 || (stat(binpath, &statbuf) == -1)) {
    fprintf(stderr, "Failed opening %s\n", binpath);
    return EXIT_FAILURE;
  }
  write(fd, ramonly ? "R" : (verify ? "V" : "F"), 1);
  wait_for_fd(fd, 0);
  if (read(fd, buf, 1) != 1 || buf[0] != 'R') {
    printf("Phase 1: Mojo didn't respond. Read %c\n", buf[0]);
    return EXIT_FAILURE;
  }
  for (int i = 0; i < 4; i++) {
    len[i] = ((intmax_t)statbuf.st_size >> (i * 8) & 0xff);
  }
  write(fd, len, 4);
  wait_for_fd(fd, 0);
  if (read(fd, buf, 1) != 1 || buf[0] != 'O') {
    printf("Phase 2: Mojo didn't respond. Read %c\n", buf[0]);
    return EXIT_FAILURE;
  }
  while ((numRead = read(fd2, buf, 256)) > 0)
    if (write(fd, buf, numRead) != numRead) {
      fprintf(stderr, "Error loading file %s\n", binpath);
      return EXIT_FAILURE;
    }
  wait_for_fd(fd, 0);
  if (read(fd, buf, 1) != 1 || buf[0] != 'D') {
    printf("Phase 3: Mojo didn't respond. Read %c\n", buf[0]);
    return EXIT_FAILURE;
  }
  if (!ramonly && verify) {
    printf("Verifying...");
    write(fd, "S", 1);
    wait_for_fd(fd, 0);
    if (read(fd, buf, 5) != 5 || buf[0] != '\xaa') {
      printf("Failed. Mojo didn't not send valid header. Read %c\n", buf[0]);
      return EXIT_FAILURE;
    }
    for (int i = 0; i < 4; i++) {
      flash_size |= ((intmax_t)buf[i + 1] & 0xff) << (i * 8);
    }
    if ((flash_size - 5) != statbuf.st_size) {
      printf("Failed. Size mismatch. %d vs %d\n", flash_size - 5,
             statbuf.st_size);
      return EXIT_FAILURE;
    }
    lseek(fd2, 0, SEEK_SET);
    int need = flash_size - 5;
    int want = (need > 256) ? 256 : need;
    int loc = 1;
    wait_for_fd(fd, 0);
    while ((numRead = read(fd, buf, want)) > 0) {
      char tmp[256];
      need -= numRead;
      want = (need > 256) ? 256 : need;
      wait_for_fd(fd2, 0);
      read(fd2, tmp, numRead);
      for (int i = 0; i < numRead; i++, loc++) {
        if (buf[i] != tmp[i]) {
          printf("Failed. Data mismatch. Got %02x expected %02x @ offset %d\n",
                 buf[i], tmp[i], loc);
          return EXIT_FAILURE;
        }
      }
      wait_for_fd(fd, 0);
    }
    printf("OK\n");
  }
  write(fd, "L", 1);
  wait_for_fd(fd, 0);
  if (read(fd, buf, 1) != 1 || buf[0] != 'D') {
    printf("Phase 4: Mojo didn't respond. Read %c\n", buf[0]);
    return EXIT_FAILURE;
  }
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x2a0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x20(%rbp)
movq   $0x0,-0x30(%rbp)
movq   $0x0,-0x38(%rbp)
movl   $0x0,-0x3c(%rbp)
movl   $0x0,-0x40(%rbp)
movl   $0x0,-0x44(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xebd(%rip),%rdx
call   10f0 <getopt@plt>
mov    %eax,-0x14(%rbp)
cmp    $0xffffffff,%eax
je     13ca <main+0x1fa>
mov    -0x14(%rbp),%eax
add    $0xffffffc1,%eax
mov    %eax,%ecx
mov    %rcx,-0x280(%rbp)
sub    $0x37,%eax
ja     135b <main+0x18b>
mov    -0x280(%rbp),%rax
lea    0xda6(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
movl   $0x1,-0x3c(%rbp)
jmp    13c5 <main+0x1f5>
mov    0x2d82(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x30(%rbp)
jmp    13c5 <main+0x1f5>
mov    0x2d6f(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x38(%rbp)
jmp    13c5 <main+0x1f5>
movl   $0x1,-0x44(%rbp)
jmp    13c5 <main+0x1f5>
movl   $0x1,-0x40(%rbp)
jmp    13c5 <main+0x1f5>
mov    0x2d14(%rip),%rax
movsbl (%rax),%eax
cmp    $0x63,%eax
jne    12e6 <main+0x116>
mov    0x2ce9(%rip),%rax
mov    (%rax),%edi
mov    0x2cf8(%rip),%rax
movsbl (%rax),%edx
lea    0xe0e(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
jmp    134a <main+0x17a>
mov    0x2cdb(%rip),%rax
movsbl (%rax),%edi
call   10d0 <isprint@plt>
cmp    $0x0,%eax
je     1324 <main+0x154>
mov    0x2cab(%rip),%rax
mov    (%rax),%edi
mov    0x2cba(%rip),%rax
movsbl (%rax),%edx
lea    0xdf5(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
jmp    1345 <main+0x175>
mov    0x2c85(%rip),%rax
mov    (%rax),%edi
mov    0x2c94(%rip),%rax
movsbl (%rax),%edx
lea    0xde6(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
jmp    134a <main+0x17a>
mov    0x2c4f(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1bb6 <main+0x9e6>
mov    0x2c4e(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xdd4(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
mov    0x2c30(%rip),%rax
mov    (%rax),%edi
lea    0xde5(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
mov    0x2c19(%rip),%rax
mov    (%rax),%edi
lea    0xde1(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
mov    0x2c02(%rip),%rax
mov    (%rax),%edi
lea    0xdea(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
mov    $0x0,%al
call   1030 <abort@plt>
jmp    1215 <main+0x45>
cmpq   $0x0,-0x30(%rbp)
jne    1449 <main+0x279>
mov    0x2bd4(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xd5a(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
mov    0x2bb6(%rip),%rax
mov    (%rax),%edi
lea    0xd6b(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
mov    0x2b9f(%rip),%rax
mov    (%rax),%edi
lea    0xd67(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
mov    0x2b88(%rip),%rax
mov    (%rax),%edi
lea    0xd70(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
mov    0x2b61(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1bb6 <main+0x9e6>
mov    -0x30(%rbp),%rdi
mov    0x2b8c(%rip),%rax
mov    (%rax),%esi
mov    0x2b5b(%rip),%rax
or     (%rax),%esi
mov    0x2b72(%rip),%rax
or     (%rax),%esi
call   10e0 <open@plt>
mov    %eax,-0x18(%rbp)
cmp    $0x0,%eax
jge    14a5 <main+0x2d5>
mov    0x2b30(%rip),%rax
mov    (%rax),%edi
mov    -0x30(%rbp),%rdx
lea    0xd27(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
mov    0x2b05(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1bb6 <main+0x9e6>
mov    -0x18(%rbp),%edi
call   1060 <setup_serial@plt>
cmp    $0x0,%rax
je     14e3 <main+0x313>
mov    0x2af2(%rip),%rax
mov    (%rax),%edi
mov    -0x30(%rbp),%rdx
lea    0xcfc(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
mov    0x2ac7(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1bb6 <main+0x9e6>
mov    -0x18(%rbp),%edi
call   10c0 <restart_mojo@plt>
cmpl   $0x0,-0x44(%rbp)
jne    157e <main+0x3ae>
cmpl   $0x0,-0x3c(%rbp)
je     157e <main+0x3ae>
lea    0xce2(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x18(%rbp),%edi
lea    0xce3(%rip),%rsi
mov    $0x1,%edx
call   1040 <write@plt>
mov    -0x18(%rbp),%edi
xor    %esi,%esi
call   1050 <wait_for_fd@plt>
mov    -0x18(%rbp),%edi
lea    -0x150(%rbp),%rsi
mov    $0x1,%edx
call   1090 <read@plt>
cmp    $0x1,%eax
jne    156d <main+0x39d>
movsbl -0x150(%rbp),%eax
cmp    $0x44,%eax
jne    156d <main+0x39d>
movsbl -0x150(%rbp),%esi
lea    0xc96(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    0x2a24(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1bb6 <main+0x9e6>
cmpq   $0x0,-0x38(%rbp)
jne    15b1 <main+0x3e1>
mov    0x2a20(%rip),%rax
mov    (%rax),%edi
lea    0xc7a(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
mov    0x29f9(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1bb6 <main+0x9e6>
mov    -0x38(%rbp),%rdi
mov    0x2a14(%rip),%rax
mov    (%rax),%esi
call   10e0 <open@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0x0,%eax
jl     15e8 <main+0x418>
mov    -0x38(%rbp),%rdi
lea    -0x158(%rbp),%rsi
call   10b0 <stat@plt>
cmp    $0xffffffff,%eax
jne    1614 <main+0x444>
mov    0x29c1(%rip),%rax
mov    (%rax),%edi
mov    -0x38(%rbp),%rdx
lea    0xbb8(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
mov    0x2996(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1bb6 <main+0x9e6>
mov    -0x18(%rbp),%eax
mov    %eax,-0x284(%rbp)
cmpl   $0x0,-0x44(%rbp)
je     163a <main+0x46a>
lea    0xc05(%rip),%rax
mov    %rax,-0x290(%rbp)
jmp    1659 <main+0x489>
mov    -0x40(%rbp),%edx
lea    0xbf3(%rip),%rax
lea    0xbea(%rip),%rcx
cmp    $0x0,%edx
cmovne %rcx,%rax
mov    %rax,-0x290(%rbp)
mov    -0x284(%rbp),%edi
mov    -0x290(%rbp),%rsi
mov    $0x1,%edx
call   1040 <write@plt>
mov    -0x18(%rbp),%edi
xor    %esi,%esi
call   1050 <wait_for_fd@plt>
mov    -0x18(%rbp),%edi
lea    -0x150(%rbp),%rsi
mov    $0x1,%edx
call   1090 <read@plt>
cmp    $0x1,%eax
jne    16a7 <main+0x4d7>
movsbl -0x150(%rbp),%eax
cmp    $0x52,%eax
je     16cd <main+0x4fd>
movsbl -0x150(%rbp),%esi
lea    0xb84(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    0x28dd(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1bb6 <main+0x9e6>
movl   $0x0,-0x15c(%rbp)
cmpl   $0x4,-0x15c(%rbp)
jge    171e <main+0x54e>
mov    -0x158(%rbp),%eax
mov    -0x15c(%rbp),%ecx
shl    $0x3,%ecx
sar    %cl,%eax
and    $0xff,%eax
mov    %al,%cl
movslq -0x15c(%rbp),%rax
mov    %cl,-0x154(%rbp,%rax,1)
mov    -0x15c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x15c(%rbp)
jmp    16d7 <main+0x507>
mov    -0x18(%rbp),%edi
lea    -0x154(%rbp),%rsi
mov    $0x4,%edx
call   1040 <write@plt>
mov    -0x18(%rbp),%edi
xor    %esi,%esi
call   1050 <wait_for_fd@plt>
mov    -0x18(%rbp),%edi
lea    -0x150(%rbp),%rsi
mov    $0x1,%edx
call   1090 <read@plt>
cmp    $0x1,%eax
jne    1769 <main+0x599>
movsbl -0x150(%rbp),%eax
cmp    $0x4f,%eax
je     178f <main+0x5bf>
movsbl -0x150(%rbp),%esi
lea    0xae9(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    0x281b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1bb6 <main+0x9e6>
jmp    1794 <main+0x5c4>
mov    -0x1c(%rbp),%edi
lea    -0x150(%rbp),%rsi
mov    $0x100,%edx
call   1090 <read@plt>
mov    %eax,-0x24(%rbp)
cmp    $0x0,%eax
jle    1800 <main+0x630>
mov    -0x18(%rbp),%edi
lea    -0x150(%rbp),%rsi
mov    -0x24(%rbp),%edx
call   1040 <write@plt>
cmp    -0x24(%rbp),%eax
je     17fb <main+0x62b>
mov    0x27da(%rip),%rax
mov    (%rax),%edi
mov    -0x38(%rbp),%rdx
lea    0xaa4(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
mov    0x27af(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1bb6 <main+0x9e6>
jmp    1794 <main+0x5c4>
mov    -0x18(%rbp),%edi
xor    %esi,%esi
call   1050 <wait_for_fd@plt>
mov    -0x18(%rbp),%edi
lea    -0x150(%rbp),%rsi
mov    $0x1,%edx
call   1090 <read@plt>
cmp    $0x1,%eax
jne    1837 <main+0x667>
movsbl -0x150(%rbp),%eax
cmp    $0x44,%eax
je     185d <main+0x68d>
movsbl -0x150(%rbp),%esi
lea    0xa59(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    0x274d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1bb6 <main+0x9e6>
cmpl   $0x0,-0x44(%rbp)
jne    1b39 <main+0x969>
cmpl   $0x0,-0x40(%rbp)
je     1b39 <main+0x969>
lea    0xa4d(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x18(%rbp),%edi
lea    0xa49(%rip),%rsi
mov    $0x1,%edx
call   1040 <write@plt>
mov    -0x18(%rbp),%edi
xor    %esi,%esi
call   1050 <wait_for_fd@plt>
mov    -0x18(%rbp),%edi
lea    -0x150(%rbp),%rsi
mov    $0x5,%edx
call   1090 <read@plt>
cmp    $0x5,%eax
jne    18ca <main+0x6fa>
movsbl -0x150(%rbp),%eax
cmp    $0xffffffaa,%eax
je     18f0 <main+0x720>
movsbl -0x150(%rbp),%esi
lea    0x9fc(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    0x26ba(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1bb6 <main+0x9e6>
movl   $0x0,-0x160(%rbp)
cmpl   $0x4,-0x160(%rbp)
jge    1944 <main+0x774>
mov    -0x160(%rbp),%eax
add    $0x1,%eax
cltq
movsbl -0x150(%rbp,%rax,1),%eax
ff
and    $0xff,%eax
mov    -0x160(%rbp),%ecx
shl    $0x3,%ecx
shl    %cl,%eax
or     -0x20(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x160(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x160(%rbp)
jmp    18fa <main+0x72a>
mov    -0x20(%rbp),%eax
sub    $0x5,%eax
cmp    -0x158(%rbp),%eax
je     1981 <main+0x7b1>
mov    -0x20(%rbp),%esi
sub    $0x5,%esi
mov    -0x158(%rbp),%edx
lea    0x99f(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    0x2629(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1bb6 <main+0x9e6>
mov    -0x1c(%rbp),%edi
mov    0x261d(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1080 <lseek@plt>
mov    -0x20(%rbp),%eax
sub    $0x5,%eax
mov    %eax,-0x164(%rbp)
cmpl   $0x100,-0x164(%rbp)
jle    19c0 <main+0x7f0>
mov    $0x100,%eax
mov    %eax,-0x294(%rbp)
jmp    19cc <main+0x7fc>
mov    -0x164(%rbp),%eax
mov    %eax,-0x294(%rbp)
mov    -0x294(%rbp),%eax
mov    %eax,-0x168(%rbp)
movl   $0x1,-0x16c(%rbp)
mov    -0x18(%rbp),%edi
xor    %esi,%esi
call   1050 <wait_for_fd@plt>
mov    -0x18(%rbp),%edi
lea    -0x150(%rbp),%rsi
mov    -0x168(%rbp),%edx
call   1090 <read@plt>
mov    %eax,-0x24(%rbp)
cmp    $0x0,%eax
jle    1b2b <main+0x95b>
mov    -0x24(%rbp),%ecx
mov    -0x164(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x164(%rbp)
cmpl   $0x100,-0x164(%rbp)
jle    1a3e <main+0x86e>
mov    $0x100,%eax
mov    %eax,-0x298(%rbp)
jmp    1a4a <main+0x87a>
mov    -0x164(%rbp),%eax
mov    %eax,-0x298(%rbp)
mov    -0x298(%rbp),%eax
mov    %eax,-0x168(%rbp)
mov    -0x1c(%rbp),%edi
xor    %esi,%esi
call   1050 <wait_for_fd@plt>
mov    -0x1c(%rbp),%edi
lea    -0x270(%rbp),%rsi
mov    -0x24(%rbp),%edx
call   1090 <read@plt>
movl   $0x0,-0x274(%rbp)
mov    -0x274(%rbp),%eax
cmp    -0x24(%rbp),%eax
jge    1b1c <main+0x94c>
movslq -0x274(%rbp),%rax
movsbl -0x150(%rbp,%rax,1),%eax
ff
movslq -0x274(%rbp),%rcx
movsbl -0x270(%rbp,%rcx,1),%ecx
ff
cmp    %ecx,%eax
je     1af4 <main+0x924>
movslq -0x274(%rbp),%rax
movsbl -0x150(%rbp,%rax,1),%esi
ff
movslq -0x274(%rbp),%rax
movsbl -0x270(%rbp,%rax,1),%edx
ff
mov    -0x16c(%rbp),%ecx
lea    0x84d(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    0x24b6(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1bb6 <main+0x9e6>
jmp    1af9 <main+0x929>
mov    -0x274(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x274(%rbp)
mov    -0x16c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x16c(%rbp)
jmp    1a7c <main+0x8ac>
mov    -0x18(%rbp),%edi
xor    %esi,%esi
call   1050 <wait_for_fd@plt>
jmp    19ec <main+0x81c>
lea    0x832(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x18(%rbp),%edi
lea    0x825(%rip),%rsi
mov    $0x1,%edx
call   1040 <write@plt>
mov    -0x18(%rbp),%edi
xor    %esi,%esi
call   1050 <wait_for_fd@plt>
mov    -0x18(%rbp),%edi
lea    -0x150(%rbp),%rsi
mov    $0x1,%edx
call   1090 <read@plt>
cmp    $0x1,%eax
jne    1b84 <main+0x9b4>
movsbl -0x150(%rbp),%eax
cmp    $0x44,%eax
je     1baa <main+0x9da>
movsbl -0x150(%rbp),%esi
lea    0x7d8(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    0x2400(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1bb6 <main+0x9e6>
mov    0x23e7(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x2a0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x228,%rsp
mov    %rsi,%rbp
mov    %edi,%ebx
xor    %r14d,%r14d
lea    0xe50(%rip),%r15
lea    0xdf9(%rip),%r13
movl   $0x0,0x8(%rsp)
xor    %eax,%eax
mov    %rax,0x10(%rsp)
movl   $0x0,0xc(%rsp)
xor    %r12d,%r12d
mov    %r12d,%ecx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %ecx,%r12d
mov    %ebx,%edi
mov    %rbp,%rsi
mov    %r15,%rdx
call   1100 <getopt@plt>
mov    $0x1,%ecx
cmp    $0x72,%eax
je     1230 <main+0x50>
lea    -0x63(%rax),%ecx
cmp    $0x13,%ecx
ja     128d <main+0xad>
movslq 0x0(%r13,%rcx,4),%rax
add    %r13,%rax
jmp    *%rax
movl   $0x1,0x8(%rsp)
jmp    1221 <main+0x41>
mov    0x2d8b(%rip),%rax
mov    (%rax),%r14
jmp    1221 <main+0x41>
mov    0x2d7f(%rip),%rax
mov    (%rax),%rax
mov    %rax,0x10(%rsp)
jmp    1221 <main+0x41>
movl   $0x1,0xc(%rsp)
jmp    1221 <main+0x41>
cmp    $0xffffffff,%eax
je     12c2 <main+0xe2>
cmp    $0x3f,%eax
jne    17ec <main+0x60c>
mov    0x2d26(%rip),%rbx
mov    (%rbx),%al
cmp    $0x63,%al
jne    1317 <main+0x137>
mov    0x2d01(%rip),%rax
mov    (%rax),%edi
lea    0xda0(%rip),%rsi
mov    $0x63,%edx
jmp    13a8 <main+0x1c8>
test   %r14,%r14
je     1338 <main+0x158>
mov    0x2d12(%rip),%rax
mov    0x2ce3(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2cf8(%rip),%rax
or     (%rax),%esi
mov    %r14,%rdi
call   10f0 <open@plt>
test   %eax,%eax
js     1385 <main+0x1a5>
mov    %eax,%r15d
mov    %eax,%edi
call   1070 <setup_serial@plt>
test   %rax,%rax
je     13ca <main+0x1ea>
mov    0x2ca4(%rip),%rax
mov    (%rax),%edi
lea    0xe22(%rip),%rsi
jmp    1395 <main+0x1b5>
movsbl %al,%edi
call   10e0 <isprint@plt>
mov    0x2c8a(%rip),%rcx
mov    (%rcx),%edi
movsbl (%rbx),%edx
test   %eax,%eax
je     13a1 <main+0x1c1>
lea    0xd47(%rip),%rsi
jmp    13a8 <main+0x1c8>
mov    0x2c71(%rip),%rbx
mov    (%rbx),%edi
mov    0x0(%rbp),%rdx
lea    0xd6a(%rip),%rsi
xor    %eax,%eax
call   10b0 <fprintf@plt>
mov    (%rbx),%edi
lea    0xd82(%rip),%rsi
xor    %eax,%eax
call   10b0 <fprintf@plt>
mov    (%rbx),%edi
lea    0xd85(%rip),%rsi
xor    %eax,%eax
call   10b0 <fprintf@plt>
mov    (%rbx),%edi
lea    0xd95(%rip),%rsi
xor    %eax,%eax
call   10b0 <fprintf@plt>
jmp    13af <main+0x1cf>
mov    0x2c24(%rip),%rax
mov    (%rax),%edi
lea    0xd8f(%rip),%rsi
mov    %r14,%rdx
xor    %eax,%eax
call   10b0 <fprintf@plt>
jmp    13af <main+0x1cf>
lea    0xcec(%rip),%rsi
xor    %eax,%eax
call   10b0 <fprintf@plt>
mov    0x2bea(%rip),%rax
mov    (%rax),%eax
add    $0x228,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %r15d,%edi
call   10d0 <restart_mojo@plt>
test   %r12d,%r12d
jne    1445 <main+0x265>
cmpl   $0x0,0x8(%rsp)
je     1445 <main+0x265>
lea    0xf09(%rip),%rdi
call   1040 <puts@plt>
lea    0xd67(%rip),%rsi
mov    %r15d,%edi
mov    $0x1,%edx
call   1050 <write@plt>
mov    %r15d,%edi
xor    %esi,%esi
call   1060 <wait_for_fd@plt>
lea    0x20(%rsp),%rsi
mov    %r15d,%edi
mov    $0x1,%edx
call   10a0 <read@plt>
cmp    $0x1,%eax
jne    1439 <main+0x259>
cmpb   $0x44,0x20(%rsp)
jne    1439 <main+0x259>
lea    0xd2d(%rip),%rdi
mov    $0x44,%esi
xor    %eax,%eax
call   1080 <printf@plt>
mov    0x2b58(%rip),%rax
jmp    13b6 <main+0x1d6>
mov    0x10(%rsp),%rbx
test   %rbx,%rbx
je     159a <main+0x3ba>
mov    0x2b76(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   10f0 <open@plt>
test   %eax,%eax
js     1582 <main+0x3a2>
mov    %eax,%r14d
lea    0x18(%rsp),%rsi
mov    %rbx,%rdi
call   10c0 <stat@plt>
cmp    $0xffffffff,%eax
je     1582 <main+0x3a2>
mov    0xc(%rsp),%r13d
test   %r13d,%r13d
lea    0xd01(%rip),%rax
lea    0xcf8(%rip),%rcx
cmove  %rax,%rcx
test   %r12d,%r12d
lea    0xce8(%rip),%rsi
cmove  %rcx,%rsi
mov    %r15d,%edi
mov    $0x1,%edx
call   1050 <write@plt>
mov    %r15d,%edi
xor    %esi,%esi
call   1060 <wait_for_fd@plt>
lea    0x20(%rsp),%rsi
mov    %r15d,%edi
mov    $0x1,%edx
call   10a0 <read@plt>
mov    0x20(%rsp),%cl
cmp    $0x1,%eax
jne    15af <main+0x3cf>
cmp    $0x52,%cl
jne    15af <main+0x3cf>
mov    0x18(%rsp),%ebx
mov    %ebx,0x1c(%rsp)
lea    0x1c(%rsp),%rsi
mov    %r15d,%edi
mov    $0x4,%edx
call   1050 <write@plt>
mov    %r15d,%edi
xor    %esi,%esi
call   1060 <wait_for_fd@plt>
lea    0x20(%rsp),%rsi
mov    %r15d,%edi
mov    $0x1,%edx
call   10a0 <read@plt>
mov    0x20(%rsp),%cl
cmp    $0x1,%eax
jne    15be <main+0x3de>
cmp    $0x4f,%cl
jne    15be <main+0x3de>
mov    %ebx,0x8(%rsp)
lea    0x20(%rsp),%rbx
mov    %r14d,%edi
mov    %rbx,%rsi
mov    $0x100,%edx
call   10a0 <read@plt>
test   %eax,%eax
jle    15cd <main+0x3ed>
mov    %eax,%ebp
mov    %r15d,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1050 <write@plt>
cmp    %ebp,%eax
je     1541 <main+0x361>
mov    0x2a41(%rip),%rax
mov    (%rax),%edi
lea    0xc6d(%rip),%rsi
mov    0x10(%rsp),%rdx
jmp    1398 <main+0x1b8>
mov    0x2a27(%rip),%rax
mov    (%rax),%edi
lea    0xb92(%rip),%rsi
mov    %rbx,%rdx
jmp    1398 <main+0x1b8>
mov    0x2a0f(%rip),%rax
mov    (%rax),%edi
lea    0xbc7(%rip),%rsi
jmp    137c <main+0x19c>
movsbl %cl,%esi
lea    0xbde(%rip),%rdi
jmp    17a6 <main+0x5c6>
movsbl %cl,%esi
lea    0xbf6(%rip),%rdi
jmp    17a6 <main+0x5c6>
mov    %r15d,%edi
xor    %esi,%esi
call   1060 <wait_for_fd@plt>
lea    0x20(%rsp),%rsi
mov    %r15d,%edi
mov    $0x1,%edx
call   10a0 <read@plt>
mov    0x20(%rsp),%cl
cmp    $0x1,%eax
jne    179c <main+0x5bc>
cmp    $0x44,%cl
jne    179c <main+0x5bc>
test   %r12d,%r12d
jne    174e <main+0x56e>
test   %r13d,%r13d
je     174e <main+0x56e>
lea    0xc0b(%rip),%rdi
xor    %eax,%eax
call   1080 <printf@plt>
lea    0xc0a(%rip),%rsi
mov    %r15d,%edi
mov    $0x1,%edx
call   1050 <write@plt>
mov    %r15d,%edi
xor    %esi,%esi
call   1060 <wait_for_fd@plt>
lea    0x20(%rsp),%rsi
mov    %r15d,%edi
mov    $0x5,%edx
call   10a0 <read@plt>
mov    0x20(%rsp),%cl
cmp    $0x5,%eax
jne    17b2 <main+0x5d2>
cmp    $0xaa,%cl
jne    17b2 <main+0x5d2>
mov    0x21(%rsp),%esi
add    $0xfffffffb,%esi
mov    0x8(%rsp),%ebp
cmp    %ebp,%esi
jne    17be <main+0x5de>
mov    0x2929(%rip),%rax
mov    (%rax),%edx
mov    %r14d,%edi
xor    %esi,%esi
call   1090 <lseek@plt>
cmp    $0x100,%ebp
mov    $0x100,%ebx
cmovl  %ebp,%ebx
mov    %r15d,%edi
xor    %esi,%esi
call   1060 <wait_for_fd@plt>
lea    0x20(%rsp),%rsi
mov    %r15d,%edi
mov    %ebx,%edx
call   10a0 <read@plt>
test   %eax,%eax
jle    1742 <main+0x562>
mov    %eax,%ebx
mov    $0x1,%r12d
mov    0x8(%rsp),%eax
sub    %ebx,%eax
cmp    $0x100,%eax
mov    $0x100,%r13d
mov    %eax,0x8(%rsp)
cmovl  %eax,%r13d
mov    %r14d,%edi
xor    %esi,%esi
call   1060 <wait_for_fd@plt>
mov    %r14d,%edi
lea    0x120(%rsp),%rsi
mov    %ebx,%edx
call   10a0 <read@plt>
mov    %ebx,%eax
mov    %ebx,%ebp
add    %r12d,%ebp
xor    %ecx,%ecx
movsbl 0x20(%rsp,%rcx,1),%esi
movsbl 0x120(%rsp,%rcx,1),%edx
cmp    %dl,%sil
jne    17d3 <main+0x5f3>
add    $0x1,%rcx
cmp    %rcx,%rax
jne    1700 <main+0x520>
mov    %r15d,%edi
xor    %esi,%esi
call   1060 <wait_for_fd@plt>
mov    %r15d,%edi
lea    0x20(%rsp),%rsi
mov    %r13d,%edx
call   10a0 <read@plt>
mov    %eax,%ebx
mov    %ebp,%r12d
test   %eax,%eax
jg     16c2 <main+0x4e2>
lea    0xba2(%rip),%rdi
call   1040 <puts@plt>
lea    0xb6d(%rip),%rsi
mov    %r15d,%edi
mov    $0x1,%edx
call   1050 <write@plt>
mov    %r15d,%edi
xor    %esi,%esi
call   1060 <wait_for_fd@plt>
lea    0x20(%rsp),%rsi
mov    %r15d,%edi
mov    $0x1,%edx
call   10a0 <read@plt>
mov    0x20(%rsp),%cl
cmp    $0x1,%eax
jne    1790 <main+0x5b0>
cmp    $0x44,%cl
je     1439 <main+0x259>
movsbl %cl,%esi
lea    0xb2a(%rip),%rdi
jmp    17a6 <main+0x5c6>
movsbl %cl,%esi
lea    0xa56(%rip),%rdi
xor    %eax,%eax
call   1080 <printf@plt>
jmp    13af <main+0x1cf>
movsbl %cl,%esi
lea    0xa76(%rip),%rdi
jmp    17a6 <main+0x5c6>
lea    0xaa1(%rip),%rdi
mov    %ebp,%edx
xor    %eax,%eax
call   1080 <printf@plt>
jmp    13af <main+0x1cf>
add    %ecx,%r12d
lea    0xaaa(%rip),%rdi
mov    %r12d,%ecx
xor    %eax,%eax
call   1080 <printf@plt>
jmp    13af <main+0x1cf>
mov    0x27bd(%rip),%rbx
mov    (%rbx),%edi
mov    0x0(%rbp),%rdx
lea    0x8b6(%rip),%rsi
xor    %eax,%eax
call   10b0 <fprintf@plt>
mov    (%rbx),%edi
lea    0x8ce(%rip),%rsi
xor    %eax,%eax
call   10b0 <fprintf@plt>
mov    (%rbx),%edi
lea    0x8d1(%rip),%rsi
xor    %eax,%eax
call   10b0 <fprintf@plt>
mov    (%rbx),%edi
lea    0x8e1(%rip),%rsi
xor    %eax,%eax
call   10b0 <fprintf@plt>
xor    %eax,%eax
call   1030 <abort@plt>

LLVM IR (-O0):
%struct.stat = type { i32 }
@.str = [8 x i8] c"crvd:f:\00"
@optarg = global i8* null
@optopt = global i8 0
@stderr = global i32 0
@.str.1 = [37 x i8] c"Option -%c requires path to binary.\0A\00"
@.str.2 = [23 x i8] c"Unknown option `-%c'.\0A\00"
@.str.3 = [34 x i8] c"Unknown option character `\\x%x'.\0A\00"
@EXIT_FAILURE = global i32 0
@.str.4 = [40 x i8] c"%s: -d <dev> [-c | -r | -v] [-f <bin>]\0A\00"
@.str.5 = [19 x i8] c"\09-r : load to ram\0A\00"
@.str.6 = [32 x i8] c"\09-v : verify flash after write\0A\00"
@.str.7 = [19 x i8] c"\09-c : clear flash\0A\00"
@O_RDWR = global i32 0
@O_NOCTTY = global i32 0
@O_SYNC = global i32 0
@.str.8 = [19 x i8] c"Failed opening %s\0A\00"
@.str.9 = [33 x i8] c"Failed setting attributes of %s\0A\00"
@.str.10 = [18 x i8] c"Erasing flash...\0A\00"
@.str.11 = [2 x i8] c"E\00"
@.str.12 = [23 x i8] c"Erasing done. Read %c\0A\00"
@EXIT_SUCCESS = global i32 0
@.str.13 = [32 x i8] c"Error: No flash file specified\0A\00"
@O_RDONLY = global i32 0
@.str.14 = [2 x i8] c"R\00"
@.str.15 = [2 x i8] c"V\00"
@.str.16 = [2 x i8] c"F\00"
@.str.17 = [39 x i8] c"Phase 1: Mojo didn't respond. Read %c\0A\00"
@.str.18 = [39 x i8] c"Phase 2: Mojo didn't respond. Read %c\0A\00"
@.str.19 = [23 x i8] c"Error loading file %s\0A\00"
@.str.20 = [39 x i8] c"Phase 3: Mojo didn't respond. Read %c\0A\00"
@.str.21 = [13 x i8] c"Verifying...\00"
@.str.22 = [2 x i8] c"S\00"
@.str.23 = [52 x i8] c"Failed. Mojo didn't not send valid header. Read %c\0A\00"
@.str.24 = [33 x i8] c"Failed. Size mismatch. %d vs %d\0A\00"
@SEEK_SET = global i32 0
@.str.25 = [59 x i8] c"Failed. Data mismatch. Got %02x expected %02x @ offset %d\0A\00"
@.str.26 = [4 x i8] c"OK\0A\00"
@.str.27 = [2 x i8] c"L\00"
@.str.28 = [39 x i8] c"Phase 4: Mojo didn't respond. Read %c\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*
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
%16 = alloca [256 x i8]
%17 = alloca [4 x i8]
%18 = alloca %struct.stat
%19 = alloca i32
%20 = alloca i32
%21 = alloca i32
%22 = alloca i32
%23 = alloca i32
%24 = alloca [256 x i8]
%25 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %9
store i8* null, i8** %11
store i8* null, i8** %12
store i32 0, i32* %13
store i32 0, i32* %14
store i32 0, i32* %15
br label %26
26: ; preds = %79, %2
%27 = load i32, i32* %4
%28 = load i8**, i8*** %5
%29 = call i32 @getopt(i32 %27, i8** %28, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
store i32 %29, i32* %6
%30 = icmp ne i32 %29, -1
br i1 %30, label %31, label %80
31: ; preds = %26
%32 = load i32, i32* %6
switch i32 %32, label %66 [
i32 99, label %33
i32 100, label %34
i32 102, label %36
i32 114, label %38
i32 118, label %39
i32 63, label %40
]
33: ; preds = %31
store i32 1, i32* %13
br label %79
34: ; preds = %31
%35 = load i8*, i8** @optarg
store i8* %35, i8** %11
br label %79
36: ; preds = %31
%37 = load i8*, i8** @optarg
store i8* %37, i8** %12
br label %79
38: ; preds = %31
store i32 1, i32* %15
br label %79
39: ; preds = %31
store i32 1, i32* %14
br label %79
40: ; preds = %31
%41 = load i8, i8* @optopt
%42 = sext i8 %41 to i32
%43 = icmp eq i32 %42, 99
br i1 %43, label %44, label %49
44: ; preds = %40
%45 = load i32, i32* @stderr
%46 = load i8, i8* @optopt
%47 = sext i8 %46 to i32
%48 = call i32 (i32, i8*, ...) @fprintf(i32 %45, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0), i32 %47)
br label %64
49: ; preds = %40
%50 = load i8, i8* @optopt
%51 = call i32 @isprint(i8 signext %50)
%52 = icmp ne i32 %51, 0
br i1 %52, label %53, label %58
53: ; preds = %49
%54 = load i32, i32* @stderr
%55 = load i8, i8* @optopt
%56 = sext i8 %55 to i32
%57 = call i32 (i32, i8*, ...) @fprintf(i32 %54, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i32 %56)
br label %63
58: ; preds = %49
%59 = load i32, i32* @stderr
%60 = load i8, i8* @optopt
%61 = sext i8 %60 to i32
%62 = call i32 (i32, i8*, ...) @fprintf(i32 %59, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.3, i64 0, i64 0), i32 %61)
br label %63
63: ; preds = %58, %53
br label %64
64: ; preds = %63, %44
%65 = load i32, i32* @EXIT_FAILURE
store i32 %65, i32* %3
br label %437
66: ; preds = %31
%67 = load i32, i32* @stderr
%68 = load i8**, i8*** %5
%69 = getelementptr inbounds i8*, i8** %68, i64 0
%70 = load i8*, i8** %69
%71 = call i32 (i32, i8*, ...) @fprintf(i32 %67, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.4, i64 0, i64 0), i8* %70)
%72 = load i32, i32* @stderr
%73 = call i32 (i32, i8*, ...) @fprintf(i32 %72, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.5, i64 0, i64 0))
%74 = load i32, i32* @stderr
%75 = call i32 (i32, i8*, ...) @fprintf(i32 %74, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.6, i64 0, i64 0))
%76 = load i32, i32* @stderr
%77 = call i32 (i32, i8*, ...) @fprintf(i32 %76, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.7, i64 0, i64 0))
%78 = call i32 (...) @abort()
unreachable
79: ; preds = %39, %38, %36, %34, %33
br label %26
80: ; preds = %26
%81 = load i8*, i8** %11
%82 = icmp ne i8* %81, null
br i1 %82, label %96, label %83
83: ; preds = %80
%84 = load i32, i32* @stderr
%85 = load i8**, i8*** %5
%86 = getelementptr inbounds i8*, i8** %85, i64 0
%87 = load i8*, i8** %86
%88 = call i32 (i32, i8*, ...) @fprintf(i32 %84, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.4, i64 0, i64 0), i8* %87)
%89 = load i32, i32* @stderr
%90 = call i32 (i32, i8*, ...) @fprintf(i32 %89, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.5, i64 0, i64 0))
%91 = load i32, i32* @stderr
%92 = call i32 (i32, i8*, ...) @fprintf(i32 %91, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.6, i64 0, i64 0))
%93 = load i32, i32* @stderr
%94 = call i32 (i32, i8*, ...) @fprintf(i32 %93, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.7, i64 0, i64 0))
%95 = load i32, i32* @EXIT_FAILURE
store i32 %95, i32* %3
br label %437
96: ; preds = %80
%97 = load i8*, i8** %11
%98 = load i32, i32* @O_RDWR
%99 = load i32, i32* @O_NOCTTY
%100 = or i32 %98, %99
%101 = load i32, i32* @O_SYNC
%102 = or i32 %100, %101
%103 = call i32 @open(i8* %97, i32 %102)
store i32 %103, i32* %7
%104 = icmp slt i32 %103, 0
br i1 %104, label %105, label %110
105: ; preds = %96
%106 = load i32, i32* @stderr
%107 = load i8*, i8** %11
%108 = call i32 (i32, i8*, ...) @fprintf(i32 %106, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.8, i64 0, i64 0), i8* %107)
%109 = load i32, i32* @EXIT_FAILURE
store i32 %109, i32* %3
br label %437
110: ; preds = %96
%111 = load i32, i32* %7
%112 = call i64 @setup_serial(i32 %111)
%113 = icmp ne i64 %112, 0
br i1 %113, label %114, label %119
114: ; preds = %110
%115 = load i32, i32* @stderr
%116 = load i8*, i8** %11
%117 = call i32 (i32, i8*, ...) @fprintf(i32 %115, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.9, i64 0, i64 0), i8* %116)
%118 = load i32, i32* @EXIT_FAILURE
store i32 %118, i32* %3
br label %437
119: ; preds = %110
%120 = load i32, i32* %7
%121 = call i32 @restart_mojo(i32 %120)
%122 = load i32, i32* %15
%123 = icmp ne i32 %122, 0
br i1 %123, label %149, label %124
124: ; preds = %119
%125 = load i32, i32* %13
%126 = icmp ne i32 %125, 0
br i1 %126, label %127, label %149
127: ; preds = %124
%128 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.10, i64 0, i64 0))
%129 = load i32, i32* %7
%130 = call i32 @write(i32 %129, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.11, i64 0, i64 0), i32 1)
%131 = load i32, i32* %7
%132 = call i32 @wait_for_fd(i32 %131, i32 0)
%133 = load i32, i32* %7
%134 = getelementptr inbounds [256 x i8], [256 x i8]* %16, i64 0, i64 0
%135 = call i32 @read(i32 %133, i8* %134, i32 1)
%136 = icmp eq i32 %135, 1
br i1 %136, label %137, label %147
137: ; preds = %127
%138 = getelementptr inbounds [256 x i8], [256 x i8]* %16, i64 0, i64 0
%139 = load i8, i8* %138
%140 = sext i8 %139 to i32
%141 = icmp eq i32 %140, 68
br i1 %141, label %142, label %147
142: ; preds = %137
%143 = getelementptr inbounds [256 x i8], [256 x i8]* %16, i64 0, i64 0
%144 = load i8, i8* %143
%145 = sext i8 %144 to i32
%146 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.12, i64 0, i64 0), i32 %145)
br label %147
147: ; preds = %142, %137, %127
%148 = load i32, i32* @EXIT_SUCCESS
store i32 %148, i32* %3
br label %437
149: ; preds = %124, %119
%150 = load i8*, i8** %12
%151 = icmp ne i8* %150, null
br i1 %151, label %156, label %152
152: ; preds = %149
%153 = load i32, i32* @stderr
%154 = call i32 (i32, i8*, ...) @fprintf(i32 %153, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.13, i64 0, i64 0))
%155 = load i32, i32* @EXIT_FAILURE
store i32 %155, i32* %3
br label %437
156: ; preds = %149
%157 = load i8*, i8** %12
%158 = load i32, i32* @O_RDONLY
%159 = call i32 @open(i8* %157, i32 %158)
store i32 %159, i32* %8
%160 = icmp slt i32 %159, 0
br i1 %160, label %165, label %161
161: ; preds = %156
%162 = load i8*, i8** %12
%163 = call i32 @stat(i8* %162, %struct.stat* %18)
%164 = icmp eq i32 %163, -1
br i1 %164, label %165, label %170
165: ; preds = %161, %156
%166 = load i32, i32* @stderr
%167 = load i8*, i8** %12
%168 = call i32 (i32, i8*, ...) @fprintf(i32 %166, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.8, i64 0, i64 0), i8* %167)
%169 = load i32, i32* @EXIT_FAILURE
store i32 %169, i32* %3
br label %437
170: ; preds = %161
%171 = load i32, i32* %7
%172 = load i32, i32* %15
%173 = icmp ne i32 %172, 0
br i1 %173, label %174, label %175
174: ; preds = %170
br label %180
175: ; preds = %170
%176 = load i32, i32* %14
%177 = icmp ne i32 %176, 0
%178 = zext i1 %177 to i64
%179 = select i1 %177, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.15, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.16, i64 0, i64 0)
br label %180
180: ; preds = %175, %174
%181 = phi i8* [ getelementptr inbounds ([2 x i8], [2 x i8]* @.str.14, i64 0, i64 0), %174 ], [ %179, %175 ]
%182 = call i32 @write(i32 %171, i8* %181, i32 1)
%183 = load i32, i32* %7
%184 = call i32 @wait_for_fd(i32 %183, i32 0)
%185 = load i32, i32* %7
%186 = getelementptr inbounds [256 x i8], [256 x i8]* %16, i64 0, i64 0
%187 = call i32 @read(i32 %185, i8* %186, i32 1)
%188 = icmp ne i32 %187, 1
br i1 %188, label %194, label %189
189: ; preds = %180
%190 = getelementptr inbounds [256 x i8], [256 x i8]* %16, i64 0, i64 0
%191 = load i8, i8* %190
%192 = sext i8 %191 to i32
%193 = icmp ne i32 %192, 82
br i1 %193, label %194, label %200
194: ; preds = %189, %180
%195 = getelementptr inbounds [256 x i8], [256 x i8]* %16, i64 0, i64 0
%196 = load i8, i8* %195
%197 = sext i8 %196 to i32
%198 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.17, i64 0, i64 0), i32 %197)
%199 = load i32, i32* @EXIT_FAILURE
store i32 %199, i32* %3
br label %437
200: ; preds = %189
store i32 0, i32* %19
br label %201
201: ; preds = %215, %200
%202 = load i32, i32* %19
%203 = icmp slt i32 %202, 4
br i1 %203, label %204, label %218
204: ; preds = %201
%205 = getelementptr inbounds %struct.stat, %struct.stat* %18, i32 0, i32 0
%206 = load i32, i32* %205
%207 = load i32, i32* %19
%208 = mul nsw i32 %207, 8
%209 = ashr i32 %206, %208
%210 = and i32 %209, 255
%211 = trunc i32 %210 to i8
%212 = load i32, i32* %19
%213 = sext i32 %212 to i64
%214 = getelementptr inbounds [4 x i8], [4 x i8]* %17, i64 0, i64 %213
store i8 %211, i8* %214
br label %215
215: ; preds = %204
%216 = load i32, i32* %19
%217 = add nsw i32 %216, 1
store i32 %217, i32* %19
br label %201
218: ; preds = %201
%219 = load i32, i32* %7
%220 = getelementptr inbounds [4 x i8], [4 x i8]* %17, i64 0, i64 0
%221 = call i32 @write(i32 %219, i8* %220, i32 4)
%222 = load i32, i32* %7
%223 = call i32 @wait_for_fd(i32 %222, i32 0)
%224 = load i32, i32* %7
%225 = getelementptr inbounds [256 x i8], [256 x i8]* %16, i64 0, i64 0
%226 = call i32 @read(i32 %224, i8* %225, i32 1)
%227 = icmp ne i32 %226, 1
br i1 %227, label %233, label %228
228: ; preds = %218
%229 = getelementptr inbounds [256 x i8], [256 x i8]* %16, i64 0, i64 0
%230 = load i8, i8* %229
%231 = sext i8 %230 to i32
%232 = icmp ne i32 %231, 79
br i1 %232, label %233, label %239
233: ; preds = %228, %218
%234 = getelementptr inbounds [256 x i8], [256 x i8]* %16, i64 0, i64 0
%235 = load i8, i8* %234
%236 = sext i8 %235 to i32
%237 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.18, i64 0, i64 0), i32 %236)
%238 = load i32, i32* @EXIT_FAILURE
store i32 %238, i32* %3
br label %437
239: ; preds = %228
br label %240
240: ; preds = %257, %239
%241 = load i32, i32* %8
%242 = getelementptr inbounds [256 x i8], [256 x i8]* %16, i64 0, i64 0
%243 = call i32 @read(i32 %241, i8* %242, i32 256)
store i32 %243, i32* %10
%244 = icmp sgt i32 %243, 0
br i1 %244, label %245, label %258
245: ; preds = %240
%246 = load i32, i32* %7
%247 = getelementptr inbounds [256 x i8], [256 x i8]* %16, i64 0, i64 0
%248 = load i32, i32* %10
%249 = call i32 @write(i32 %246, i8* %247, i32 %248)
%250 = load i32, i32* %10
%251 = icmp ne i32 %249, %250
br i1 %251, label %252, label %257
252: ; preds = %245
%253 = load i32, i32* @stderr
%254 = load i8*, i8** %12
%255 = call i32 (i32, i8*, ...) @fprintf(i32 %253, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.19, i64 0, i64 0), i8* %254)
%256 = load i32, i32* @EXIT_FAILURE
store i32 %256, i32* %3
br label %437
257: ; preds = %245
br label %240
258: ; preds = %240
%259 = load i32, i32* %7
%260 = call i32 @wait_for_fd(i32 %259, i32 0)
%261 = load i32, i32* %7
%262 = getelementptr inbounds [256 x i8], [256 x i8]* %16, i64 0, i64 0
%263 = call i32 @read(i32 %261, i8* %262, i32 1)
%264 = icmp ne i32 %263, 1
br i1 %264, label %270, label %265
265: ; preds = %258
%266 = getelementptr inbounds [256 x i8], [256 x i8]* %16, i64 0, i64 0
%267 = load i8, i8* %266
%268 = sext i8 %267 to i32
%269 = icmp ne i32 %268, 68
br i1 %269, label %270, label %276
270: ; preds = %265, %258
%271 = getelementptr inbounds [256 x i8], [256 x i8]* %16, i64 0, i64 0
%272 = load i8, i8* %271
%273 = sext i8 %272 to i32
%274 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.20, i64 0, i64 0), i32 %273)
%275 = load i32, i32* @EXIT_FAILURE
store i32 %275, i32* %3
br label %437
276: ; preds = %265
%277 = load i32, i32* %15
%278 = icmp ne i32 %277, 0
br i1 %278, label %415, label %279
279: ; preds = %276
%280 = load i32, i32* %14
%281 = icmp ne i32 %280, 0
br i1 %281, label %282, label %415
282: ; preds = %279
%283 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.21, i64 0, i64 0))
%284 = load i32, i32* %7
%285 = call i32 @write(i32 %284, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.22, i64 0, i64 0), i32 1)
%286 = load i32, i32* %7
%287 = call i32 @wait_for_fd(i32 %286, i32 0)
%288 = load i32, i32* %7
%289 = getelementptr inbounds [256 x i8], [256 x i8]* %16, i64 0, i64 0
%290 = call i32 @read(i32 %288, i8* %289, i32 5)
%291 = icmp ne i32 %290, 5
br i1 %291, label %297, label %292
292: ; preds = %282
%293 = getelementptr inbounds [256 x i8], [256 x i8]* %16, i64 0, i64 0
%294 = load i8, i8* %293
%295 = sext i8 %294 to i32
%296 = icmp ne i32 %295, -86
br i1 %296, label %297, label %303
297: ; preds = %292, %282
%298 = getelementptr inbounds [256 x i8], [256 x i8]* %16, i64 0, i64 0
%299 = load i8, i8* %298
%300 = sext i8 %299 to i32
%301 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.23, i64 0, i64 0), i32 %300)
%302 = load i32, i32* @EXIT_FAILURE
store i32 %302, i32* %3
br label %437
303: ; preds = %292
store i32 0, i32* %20
br label %304
304: ; preds = %320, %303
%305 = load i32, i32* %20
%306 = icmp slt i32 %305, 4
br i1 %306, label %307, label %323
307: ; preds = %304
%308 = load i32, i32* %20
%309 = add nsw i32 %308, 1
%310 = sext i32 %309 to i64
%311 = getelementptr inbounds [256 x i8], [256 x i8]* %16, i64 0, i64 %310
%312 = load i8, i8* %311
%313 = sext i8 %312 to i32
%314 = and i32 %313, 255
%315 = load i32, i32* %20
%316 = mul nsw i32 %315, 8
%317 = shl i32 %314, %316
%318 = load i32, i32* %9
%319 = or i32 %318, %317
store i32 %319, i32* %9
br label %320
320: ; preds = %307
%321 = load i32, i32* %20
%322 = add nsw i32 %321, 1
store i32 %322, i32* %20
br label %304
323: ; preds = %304
%324 = load i32, i32* %9
%325 = sub nsw i32 %324, 5
%326 = getelementptr inbounds %struct.stat, %struct.stat* %18, i32 0, i32 0
%327 = load i32, i32* %326
%328 = icmp ne i32 %325, %327
br i1 %328, label %329, label %336
329: ; preds = %323
%330 = load i32, i32* %9
%331 = sub nsw i32 %330, 5
%332 = getelementptr inbounds %struct.stat, %struct.stat* %18, i32 0, i32 0
%333 = load i32, i32* %332
%334 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.24, i64 0, i64 0), i32 %331, i32 %333)
%335 = load i32, i32* @EXIT_FAILURE
store i32 %335, i32* %3
br label %437
336: ; preds = %323
%337 = load i32, i32* %8
%338 = load i32, i32* @SEEK_SET
%339 = call i32 @lseek(i32 %337, i32 0, i32 %338)
%340 = load i32, i32* %9
%341 = sub nsw i32 %340, 5
store i32 %341, i32* %21
%342 = load i32, i32* %21
%343 = icmp sgt i32 %342, 256
br i1 %343, label %344, label %345
344: ; preds = %336
br label %347
345: ; preds = %336
%346 = load i32, i32* %21
br label %347
347: ; preds = %345, %344
%348 = phi i32 [ 256, %344 ], [ %346, %345 ]
store i32 %348, i32* %22
store i32 1, i32* %23
%349 = load i32, i32* %7
%350 = call i32 @wait_for_fd(i32 %349, i32 0)
br label %351
351: ; preds = %410, %347
%352 = load i32, i32* %7
%353 = getelementptr inbounds [256 x i8], [256 x i8]* %16, i64 0, i64 0
%354 = load i32, i32* %22
%355 = call i32 @read(i32 %352, i8* %353, i32 %354)
store i32 %355, i32* %10
%356 = icmp sgt i32 %355, 0
br i1 %356, label %357, label %413
357: ; preds = %351
%358 = load i32, i32* %10
%359 = load i32, i32* %21
%360 = sub nsw i32 %359, %358
store i32 %360, i32* %21
%361 = load i32, i32* %21
%362 = icmp sgt i32 %361, 256
br i1 %362, label %363, label %364
363: ; preds = %357
br label %366
364: ; preds = %357
%365 = load i32, i32* %21
br label %366
366: ; preds = %364, %363
%367 = phi i32 [ 256, %363 ], [ %365, %364 ]
store i32 %367, i32* %22
%368 = load i32, i32* %8
%369 = call i32 @wait_for_fd(i32 %368, i32 0)
%370 = load i32, i32* %8
%371 = getelementptr inbounds [256 x i8], [256 x i8]* %24, i64 0, i64 0
%372 = load i32, i32* %10
%373 = call i32 @read(i32 %370, i8* %371, i32 %372)
store i32 0, i32* %25
br label %374
374: ; preds = %405, %366
%375 = load i32, i32* %25
%376 = load i32, i32* %10
%377 = icmp slt i32 %375, %376
br i1 %377, label %378, label %410
378: ; preds = %374
%379 = load i32, i32* %25
%380 = sext i32 %379 to i64
%381 = getelementptr inbounds [256 x i8], [256 x i8]* %16, i64 0, i64 %380
%382 = load i8, i8* %381
%383 = sext i8 %382 to i32
%384 = load i32, i32* %25
%385 = sext i32 %384 to i64
%386 = getelementptr inbounds [256 x i8], [256 x i8]* %24, i64 0, i64 %385
%387 = load i8, i8* %386
%388 = sext i8 %387 to i32
%389 = icmp ne i32 %383, %388
br i1 %389, label %390, label %404
390: ; preds = %378
%391 = load i32, i32* %25
%392 = sext i32 %391 to i64
%393 = getelementptr inbounds [256 x i8], [256 x i8]* %16, i64 0, i64 %392
%394 = load i8, i8* %393
%395 = sext i8 %394 to i32
%396 = load i32, i32* %25
%397 = sext i32 %396 to i64
%398 = getelementptr inbounds [256 x i8], [256 x i8]* %24, i64 0, i64 %397
%399 = load i8, i8* %398
%400 = sext i8 %399 to i32
%401 = load i32, i32* %23
%402 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str.25, i64 0, i64 0), i32 %395, i32 %400, i32 %401)
%403 = load i32, i32* @EXIT_FAILURE
store i32 %403, i32* %3
br label %437
404: ; preds = %378
br label %405
405: ; preds = %404
%406 = load i32, i32* %25
%407 = add nsw i32 %406, 1
store i32 %407, i32* %25
%408 = load i32, i32* %23
%409 = add nsw i32 %408, 1
store i32 %409, i32* %23
br label %374
410: ; preds = %374
%411 = load i32, i32* %7
%412 = call i32 @wait_for_fd(i32 %411, i32 0)
br label %351
413: ; preds = %351
%414 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.26, i64 0, i64 0))
br label %415
415: ; preds = %413, %279, %276
%416 = load i32, i32* %7
%417 = call i32 @write(i32 %416, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.27, i64 0, i64 0), i32 1)
%418 = load i32, i32* %7
%419 = call i32 @wait_for_fd(i32 %418, i32 0)
%420 = load i32, i32* %7
%421 = getelementptr inbounds [256 x i8], [256 x i8]* %16, i64 0, i64 0
%422 = call i32 @read(i32 %420, i8* %421, i32 1)
%423 = icmp ne i32 %422, 1
br i1 %423, label %429, label %424
424: ; preds = %415
%425 = getelementptr inbounds [256 x i8], [256 x i8]* %16, i64 0, i64 0
%426 = load i8, i8* %425
%427 = sext i8 %426 to i32
%428 = icmp ne i32 %427, 68
br i1 %428, label %429, label %435
429: ; preds = %424, %415
%430 = getelementptr inbounds [256 x i8], [256 x i8]* %16, i64 0, i64 0
%431 = load i8, i8* %430
%432 = sext i8 %431 to i32
%433 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.28, i64 0, i64 0), i32 %432)
%434 = load i32, i32* @EXIT_FAILURE
store i32 %434, i32* %3
br label %437
435: ; preds = %424
%436 = load i32, i32* @EXIT_SUCCESS
store i32 %436, i32* %3
br label %437
437: ; preds = %435, %429, %390, %329, %297, %270, %252, %233, %194, %165, %152, %147, %114, %105, %83, %64
%438 = load i32, i32* %3
ret i32 %438
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@.str = [8 x i8] c"crvd:f:\00"
@optarg = global i8* null
@optopt = global i8 0
@stderr = global i32 0
@.str.1 = [37 x i8] c"Option -%c requires path to binary.\0A\00"
@.str.2 = [23 x i8] c"Unknown option `-%c'.\0A\00"
@.str.3 = [34 x i8] c"Unknown option character `\\x%x'.\0A\00"
@EXIT_FAILURE = global i32 0
@.str.4 = [40 x i8] c"%s: -d <dev> [-c | -r | -v] [-f <bin>]\0A\00"
@.str.5 = [19 x i8] c"\09-r : load to ram\0A\00"
@.str.6 = [32 x i8] c"\09-v : verify flash after write\0A\00"
@.str.7 = [19 x i8] c"\09-c : clear flash\0A\00"
@O_RDWR = global i32 0
@O_NOCTTY = global i32 0
@O_SYNC = global i32 0
@.str.8 = [19 x i8] c"Failed opening %s\0A\00"
@.str.9 = [33 x i8] c"Failed setting attributes of %s\0A\00"
@.str.11 = [2 x i8] c"E\00"
@.str.12 = [23 x i8] c"Erasing done. Read %c\0A\00"
@EXIT_SUCCESS = global i32 0
@.str.13 = [32 x i8] c"Error: No flash file specified\0A\00"
@O_RDONLY = global i32 0
@.str.14 = [2 x i8] c"R\00"
@.str.15 = [2 x i8] c"V\00"
@.str.16 = [2 x i8] c"F\00"
@.str.17 = [39 x i8] c"Phase 1: Mojo didn't respond. Read %c\0A\00"
@.str.18 = [39 x i8] c"Phase 2: Mojo didn't respond. Read %c\0A\00"
@.str.19 = [23 x i8] c"Error loading file %s\0A\00"
@.str.20 = [39 x i8] c"Phase 3: Mojo didn't respond. Read %c\0A\00"
@.str.21 = [13 x i8] c"Verifying...\00"
@.str.22 = [2 x i8] c"S\00"
@.str.23 = [52 x i8] c"Failed. Mojo didn't not send valid header. Read %c\0A\00"
@.str.24 = [33 x i8] c"Failed. Size mismatch. %d vs %d\0A\00"
@SEEK_SET = global i32 0
@.str.25 = [59 x i8] c"Failed. Data mismatch. Got %02x expected %02x @ offset %d\0A\00"
@.str.27 = [2 x i8] c"L\00"
@.str.28 = [39 x i8] c"Phase 4: Mojo didn't respond. Read %c\0A\00"
@str = [3 x i8] c"OK\00"
@str.29 = [17 x i8] c"Erasing flash...\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca [256 x i8]
%4 = alloca [4 x i8]
%5 = alloca %struct.stat
%6 = alloca [256 x i8]
%7 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%8 = getelementptr inbounds [4 x i8], [4 x i8]* %4, i64 0, i64 0
%9 = bitcast %struct.stat* %5 to i8*
br label %10
10: ; preds = %31, %2
%11 = phi i8* [ %32, %31 ], [ null, %2 ]
%12 = phi i8* [ %17, %31 ], [ null, %2 ]
%13 = phi i32 [ %22, %31 ], [ 0, %2 ]
%14 = phi i32 [ %26, %31 ], [ 0, %2 ]
%15 = phi i32 [ %29, %31 ], [ 0, %2 ]
br label %16
16: ; preds = %10, %33
%17 = phi i8* [ %12, %10 ], [ %34, %33 ]
%18 = phi i32 [ %13, %10 ], [ %22, %33 ]
%19 = phi i32 [ %14, %10 ], [ %26, %33 ]
%20 = phi i32 [ %15, %10 ], [ %29, %33 ]
br label %21
21: ; preds = %28, %16
%22 = phi i32 [ %18, %16 ], [ 1, %28 ]
%23 = phi i32 [ %19, %16 ], [ %26, %28 ]
%24 = phi i32 [ %20, %16 ], [ %29, %28 ]
br label %25
25: ; preds = %28, %21
%26 = phi i32 [ %23, %21 ], [ 1, %28 ]
%27 = phi i32 [ %24, %21 ], [ %29, %28 ]
br label %28
28: ; preds = %28, %25
%29 = phi i32 [ %27, %25 ], [ 1, %28 ]
%30 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
switch i32 %30, label %53 [
i32 -1, label %64
i32 99, label %21
i32 100, label %31
i32 102, label %33
i32 114, label %28
i32 118, label %25
i32 63, label %35
]
31: ; preds = %28
%32 = load i8*, i8** @optarg
br label %10
33: ; preds = %28
%34 = load i8*, i8** @optarg
br label %16
35: ; preds = %28
%36 = load i8, i8* @optopt
%37 = icmp eq i8 %36, 99
br i1 %37, label %38, label %41
38: ; preds = %35
%39 = load i32, i32* @stderr
%40 = tail call i32 (i32, i8*, ...) @fprintf(i32 %39, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0), i32 99)
br label %51
41: ; preds = %35
%42 = tail call i32 @isprint(i8 signext %36)
%43 = icmp eq i32 %42, 0
%44 = load i32, i32* @stderr
%45 = load i8, i8* @optopt
%46 = sext i8 %45 to i32
br i1 %43, label %49, label %47
47: ; preds = %41
%48 = tail call i32 (i32, i8*, ...) @fprintf(i32 %44, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i32 %46)
br label %51
49: ; preds = %41
%50 = tail call i32 (i32, i8*, ...) @fprintf(i32 %44, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.3, i64 0, i64 0), i32 %46)
br label %51
51: ; preds = %47, %49, %38
%52 = load i32, i32* @EXIT_FAILURE
br label %289
53: ; preds = %28
%54 = load i32, i32* @stderr
%55 = load i8*, i8** %1
%56 = tail call i32 (i32, i8*, ...) @fprintf(i32 %54, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.4, i64 0, i64 0), i8* %55)
%57 = load i32, i32* @stderr
%58 = tail call i32 (i32, i8*, ...) @fprintf(i32 %57, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.5, i64 0, i64 0))
%59 = load i32, i32* @stderr
%60 = tail call i32 (i32, i8*, ...) @fprintf(i32 %59, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.6, i64 0, i64 0))
%61 = load i32, i32* @stderr
%62 = tail call i32 (i32, i8*, ...) @fprintf(i32 %61, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.7, i64 0, i64 0))
%63 = tail call i32 (...) @abort()
unreachable
64: ; preds = %28
%65 = icmp eq i8* %11, null
br i1 %65, label %66, label %77
66: ; preds = %64
%67 = load i32, i32* @stderr
%68 = load i8*, i8** %1
%69 = tail call i32 (i32, i8*, ...) @fprintf(i32 %67, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.4, i64 0, i64 0), i8* %68)
%70 = load i32, i32* @stderr
%71 = tail call i32 (i32, i8*, ...) @fprintf(i32 %70, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.5, i64 0, i64 0))
%72 = load i32, i32* @stderr
%73 = tail call i32 (i32, i8*, ...) @fprintf(i32 %72, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.6, i64 0, i64 0))
%74 = load i32, i32* @stderr
%75 = tail call i32 (i32, i8*, ...) @fprintf(i32 %74, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.7, i64 0, i64 0))
%76 = load i32, i32* @EXIT_FAILURE
br label %289
77: ; preds = %64
%78 = load i32, i32* @O_RDWR
%79 = load i32, i32* @O_NOCTTY
%80 = or i32 %79, %78
%81 = load i32, i32* @O_SYNC
%82 = or i32 %80, %81
%83 = tail call i32 @open(i8* %11, i32 %82)
%84 = icmp slt i32 %83, 0
br i1 %84, label %85, label %89
85: ; preds = %77
%86 = load i32, i32* @stderr
%87 = tail call i32 (i32, i8*, ...) @fprintf(i32 %86, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.8, i64 0, i64 0), i8* %11)
%88 = load i32, i32* @EXIT_FAILURE
br label %289
89: ; preds = %77
%90 = tail call i64 @setup_serial(i32 %83)
%91 = icmp eq i64 %90, 0
br i1 %91, label %96, label %92
92: ; preds = %89
%93 = load i32, i32* @stderr
%94 = tail call i32 (i32, i8*, ...) @fprintf(i32 %93, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.9, i64 0, i64 0), i8* %11)
%95 = load i32, i32* @EXIT_FAILURE
br label %289
96: ; preds = %89
%97 = tail call i32 @restart_mojo(i32 %83)
%98 = icmp eq i32 %29, 0
%99 = icmp ne i32 %22, 0
%100 = select i1 %98, i1 %99, i1 false
br i1 %100, label %101, label %114
101: ; preds = %96
%102 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str.29, i64 0, i64 0))
%103 = tail call i32 @write(i32 %83, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.11, i64 0, i64 0), i32 1)
%104 = tail call i32 @wait_for_fd(i32 %83, i32 0)
%105 = call i32 @read(i32 %83, i8* %7, i32 1)
%106 = icmp eq i32 %105, 1
%107 = load i8, i8* %7
%108 = icmp eq i8 %107, 68
%109 = select i1 %106, i1 %108, i1 false
br i1 %109, label %110, label %112
110: ; preds = %101
%111 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.12, i64 0, i64 0), i32 68)
br label %112
112: ; preds = %110, %101
%113 = load i32, i32* @EXIT_SUCCESS
br label %289
114: ; preds = %96
%115 = icmp eq i8* %17, null
br i1 %115, label %116, label %120
116: ; preds = %114
%117 = load i32, i32* @stderr
%118 = tail call i32 (i32, i8*, ...) @fprintf(i32 %117, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.13, i64 0, i64 0))
%119 = load i32, i32* @EXIT_FAILURE
br label %289
120: ; preds = %114
%121 = load i32, i32* @O_RDONLY
%122 = tail call i32 @open(i8* %17, i32 %121)
%123 = icmp slt i32 %122, 0
br i1 %123, label %127, label %124
124: ; preds = %120
%125 = call i32 @stat(i8* %17, %struct.stat* %5)
%126 = icmp eq i32 %125, -1
br i1 %126, label %127, label %131
127: ; preds = %124, %120
%128 = load i32, i32* @stderr
%129 = tail call i32 (i32, i8*, ...) @fprintf(i32 %128, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.8, i64 0, i64 0), i8* %17)
%130 = load i32, i32* @EXIT_FAILURE
br label %289
131: ; preds = %124
%132 = icmp eq i32 %26, 0
%133 = select i1 %132, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.16, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.15, i64 0, i64 0)
%134 = select i1 %98, i8* %133, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.14, i64 0, i64 0)
%135 = tail call i32 @write(i32 %83, i8* %134, i32 1)
%136 = tail call i32 @wait_for_fd(i32 %83, i32 0)
%137 = call i32 @read(i32 %83, i8* %7, i32 1)
%138 = icmp ne i32 %137, 1
%139 = load i8, i8* %7
%140 = icmp ne i8 %139, 82
%141 = select i1 %138, i1 true, i1 %140
br i1 %141, label %162, label %142
142: ; preds = %131
%143 = getelementptr inbounds %struct.stat, %struct.stat* %5, i64 0, i32 0
%144 = load i32, i32* %143
%145 = trunc i32 %144 to i8
store i8 %145, i8* %8
%146 = lshr i32 %144, 8
%147 = trunc i32 %146 to i8
%148 = getelementptr inbounds [4 x i8], [4 x i8]* %4, i64 0, i64 1
store i8 %147, i8* %148
%149 = lshr i32 %144, 16
%150 = trunc i32 %149 to i8
%151 = getelementptr inbounds [4 x i8], [4 x i8]* %4, i64 0, i64 2
store i8 %150, i8* %151
%152 = lshr i32 %144, 24
%153 = trunc i32 %152 to i8
%154 = getelementptr inbounds [4 x i8], [4 x i8]* %4, i64 0, i64 3
store i8 %153, i8* %154
%155 = call i32 @write(i32 %83, i8* %8, i32 4)
%156 = tail call i32 @wait_for_fd(i32 %83, i32 0)
%157 = call i32 @read(i32 %83, i8* %7, i32 1)
%158 = icmp ne i32 %157, 1
%159 = load i8, i8* %7
%160 = icmp ne i8 %159, 79
%161 = select i1 %158, i1 true, i1 %160
br i1 %161, label %166, label %170
162: ; preds = %131
%163 = sext i8 %139 to i32
%164 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @.str.17, i64 0, i64 0), i32 %163)
%165 = load i32, i32* @EXIT_FAILURE
br label %289
166: ; preds = %142
%167 = sext i8 %159 to i32
%168 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @.str.18, i64 0, i64 0), i32 %167)
%169 = load i32, i32* @EXIT_FAILURE
br label %289
170: ; preds = %142, %173
%171 = call i32 @read(i32 %122, i8* %7, i32 256)
%172 = icmp sgt i32 %171, 0
br i1 %172, label %173, label %180
173: ; preds = %170
%174 = call i32 @write(i32 %83, i8* %7, i32 %171)
%175 = icmp eq i32 %174, %171
br i1 %175, label %170, label %176
176: ; preds = %173
%177 = load i32, i32* @stderr
%178 = tail call i32 (i32, i8*, ...) @fprintf(i32 %177, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.19, i64 0, i64 0), i8* %17)
%179 = load i32, i32* @EXIT_FAILURE
br label %289
180: ; preds = %170
%181 = tail call i32 @wait_for_fd(i32 %83, i32 0)
%182 = call i32 @read(i32 %83, i8* %7, i32 1)
%183 = icmp ne i32 %182, 1
%184 = load i8, i8* %7
%185 = icmp ne i8 %184, 68
%186 = select i1 %183, i1 true, i1 %185
br i1 %186, label %187, label %191
187: ; preds = %180
%188 = sext i8 %184 to i32
%189 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @.str.20, i64 0, i64 0), i32 %188)
%190 = load i32, i32* @EXIT_FAILURE
br label %289
191: ; preds = %180
%192 = icmp ne i32 %26, 0
%193 = select i1 %98, i1 %192, i1 false
br i1 %193, label %194, label %275
194: ; preds = %191
%195 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.21, i64 0, i64 0))
%196 = tail call i32 @write(i32 %83, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.22, i64 0, i64 0), i32 1)
%197 = tail call i32 @wait_for_fd(i32 %83, i32 0)
%198 = call i32 @read(i32 %83, i8* %7, i32 5)
%199 = icmp ne i32 %198, 5
%200 = load i8, i8* %7
%201 = icmp ne i8 %200, -86
%202 = select i1 %199, i1 true, i1 %201
br i1 %202, label %224, label %203
203: ; preds = %194
%204 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 1
%205 = load i8, i8* %204
%206 = zext i8 %205 to i32
%207 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 2
%208 = load i8, i8* %207
%209 = zext i8 %208 to i32
%210 = shl nuw nsw i32 %209, 8
%211 = or i32 %210, %206
%212 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 3
%213 = load i8, i8* %212
%214 = zext i8 %213 to i32
%215 = shl nuw nsw i32 %214, 16
%216 = or i32 %215, %211
%217 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 4
%218 = load i8, i8* %217
%219 = zext i8 %218 to i32
%220 = shl nuw i32 %219, 24
%221 = or i32 %220, %216
%222 = add nsw i32 %221, -5
%223 = icmp eq i32 %222, %144
br i1 %223, label %231, label %228
224: ; preds = %194
%225 = sext i8 %200 to i32
%226 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([52 x i8], [52 x i8]* @.str.23, i64 0, i64 0), i32 %225)
%227 = load i32, i32* @EXIT_FAILURE
br label %289
228: ; preds = %203
%229 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str.24, i64 0, i64 0), i32 %222, i32 %144)
%230 = load i32, i32* @EXIT_FAILURE
br label %289
231: ; preds = %203
%232 = load i32, i32* @SEEK_SET
%233 = tail call i32 @lseek(i32 %122, i32 0, i32 %232)
%234 = icmp slt i32 %144, 256
%235 = select i1 %234, i32 %144, i32 256
%236 = tail call i32 @wait_for_fd(i32 %83, i32 0)
%237 = call i32 @read(i32 %83, i8* %7, i32 %235)
%238 = icmp sgt i32 %237, 0
br i1 %238, label %239, label %268
239: ; preds = %231
%240 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
br label %241
241: ; preds = %264, %239
%242 = phi i32 [ %237, %239 ], [ %266, %264 ]
%243 = phi i32 [ 1, %239 ], [ %250, %264 ]
%244 = phi i32 [ %144, %239 ], [ %245, %264 ]
%245 = sub nsw i32 %244, %242
%246 = icmp slt i32 %245, 256
%247 = select i1 %246, i32 %245, i32 256
%248 = tail call i32 @wait_for_fd(i32 %122, i32 0)
%249 = call i32 @read(i32 %122, i8* %240, i32 %242)
%250 = add i32 %242, %243
%251 = zext i32 %242 to i64
br label %252
252: ; preds = %241, %260
%253 = phi i64 [ 0, %241 ], [ %261, %260 ]
%254 = phi i32 [ %243, %241 ], [ %262, %260 ]
%255 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 %253
%256 = load i8, i8* %255
%257 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 %253
%258 = load i8, i8* %257
%259 = icmp eq i8 %256, %258
br i1 %259, label %260, label %270
260: ; preds = %252
%261 = add nuw nsw i64 %253, 1
%262 = add nsw i32 %254, 1
%263 = icmp eq i64 %261, %251
br i1 %263, label %264, label %252
264: ; preds = %260
%265 = tail call i32 @wait_for_fd(i32 %83, i32 0)
%266 = call i32 @read(i32 %83, i8* %7, i32 %247)
%267 = icmp sgt i32 %266, 0
br i1 %267, label %241, label %268
268: ; preds = %264, %231
%269 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @str, i64 0, i64 0))
br label %275
270: ; preds = %252
%271 = sext i8 %258 to i32
%272 = sext i8 %256 to i32
%273 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([59 x i8], [59 x i8]* @.str.25, i64 0, i64 0), i32 %272, i32 %271, i32 %254)
%274 = load i32, i32* @EXIT_FAILURE
br label %289
275: ; preds = %268, %191
%276 = tail call i32 @write(i32 %83, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.27, i64 0, i64 0), i32 1)
%277 = tail call i32 @wait_for_fd(i32 %83, i32 0)
%278 = call i32 @read(i32 %83, i8* %7, i32 1)
%279 = icmp ne i32 %278, 1
%280 = load i8, i8* %7
%281 = icmp ne i8 %280, 68
%282 = select i1 %279, i1 true, i1 %281
br i1 %282, label %283, label %287
283: ; preds = %275
%284 = sext i8 %280 to i32
%285 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @.str.28, i64 0, i64 0), i32 %284)
%286 = load i32, i32* @EXIT_FAILURE
br label %289
287: ; preds = %275
%288 = load i32, i32* @EXIT_SUCCESS
br label %289
289: ; preds = %270, %287, %283, %228, %224, %187, %176, %166, %162, %127, %116, %112, %92, %85, %66, %51
%290 = phi i32 [ %52, %51 ], [ %88, %85 ], [ %95, %92 ], [ %113, %112 ], [ %130, %127 ], [ %165, %162 ], [ %169, %166 ], [ %179, %176 ], [ %190, %187 ], [ %227, %224 ], [ %230, %228 ], [ %286, %283 ], [ %288, %287 ], [ %274, %270 ], [ %119, %116 ], [ %76, %66 ]
ret i32 %290
}