#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 termios {
  int c_cflag;
  int *c_cc;
};
typedef int /*<<< orphan*/ speed_t;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
scalar_t__ B115200;
int CLOCAL;
int CREAD;
int CRTSCTS;
int CS8;
int CSIZE;
int CSTOPB;
int O_NOCTTY;
int O_RDWR;
int PARENB;
int /*<<< orphan*/ SEEK_END;
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ TCIFLUSH;
int /*<<< orphan*/ TCSANOW;
size_t VMIN;
size_t VTIME;
int /*<<< orphan*/ cfmakeraw(struct termios *);
int /*<<< orphan*/ cfsetispeed(struct termios *, int /*<<< orphan*/);
int /*<<< orphan*/ cfsetospeed(struct termios *, int /*<<< orphan*/);
int errno;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ fread(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int /*<<< orphan*/,
                         int /*<<< orphan*/);
unsigned int ftell(int /*<<< orphan*/ *);
int /*<<< orphan*/ fwrite(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ memset(struct termios *, int /*<<< orphan*/, int);
int open(char *, int);
int /*<<< orphan*/ perror(char *);
int read(int, char *, int);
int /*<<< orphan*/ sscanf(char *, char *, unsigned int *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcmp(char *, char *);
int /*<<< orphan*/ tcflush(int, int /*<<< orphan*/);
scalar_t__ tcgetattr(int, struct termios *);
scalar_t__ tcsetattr(int, int /*<<< orphan*/, struct termios *);
int write(int, ...);
int main(int argc, char *argv[]) {
  int fd, res;
  char buf[255];
  struct termios tty;
  struct termios tty_old;
  memset(&tty, 0, sizeof tty);
  fd = open(argv[1], O_RDWR | O_NOCTTY);
  if (fd < 0) {
    perror("/dev/ttyUSB0");
    exit(-1);
  }
  if (tcgetattr(fd, &tty) != 0) {
    fprintf(stderr, "error %d from tcgetattr\n", errno);
  }
  tty_old = tty;
  cfsetospeed(&tty, (speed_t)B115200);
  cfsetispeed(&tty, (speed_t)B115200);
  tty.c_cflag &= ~PARENB;
  tty.c_cflag &= ~CSTOPB;
  tty.c_cflag &= ~CSIZE;
  tty.c_cflag |= CS8;
  tty.c_cflag &= ~CRTSCTS;
  tty.c_cc[VMIN] = 1;
  tty.c_cc[VTIME] = 5;
  tty.c_cflag |= CREAD | CLOCAL;
  cfmakeraw(&tty);
  tcflush(fd, TCIFLUSH);
  if (tcsetattr(fd, TCSANOW, &tty) != 0) {
    fprintf(stderr, "error %d from tcsetattr\n", errno);
  }
  if (!strcmp(argv[2], "save")) {
    unsigned int s;
    unsigned int e;
    sscanf(argv[4], "%x", &s);
    sscanf(argv[5], "%x", &e);
    fprintf(stderr, "> %x %x\n", s, e);
    FILE *outf = fopen(argv[3], "wb");
    if (outf) {
      unsigned char tmp[5] = {'S', (s >> 8) & 0xff, s & 0xff, (e >> 8) & 0xff,
                              e & 0xff};
      write(fd, tmp, 5);
      for (; s < e; s++) {
        res = read(fd, buf, 1);
        if (res < 0) {
          fprintf(stderr, "error %d\n", errno);
          break;
        }
        fwrite(buf, 1, 1, outf);
      }
      res = read(fd, buf, 1);
      if (buf[0] == 'O') {
        fprintf(stderr, "OK\n");
      }
      fclose(outf);
    } else {
      fprintf(stderr, "Can't open outfile\n");
    }
  }
  if (!strcmp(argv[2], "load")) {
    unsigned int s;
    unsigned int e;
    FILE *inf = fopen(argv[3], "rb");
    if (inf) {
      if (argc < 5) {
        s = 0x100;
      } else {
        sscanf(argv[4], "%x", &s);
      }
      if (argc < 6) {
        fseek(inf, 0, SEEK_END);
        e = s + ftell(inf);
        fseek(inf, 0, SEEK_SET);
      } else {
        sscanf(argv[5], "%x", &e);
      }
      fprintf(stderr, "< %x %x\n", s, e);
      unsigned char tmp[5] = {'L', (s >> 8) & 0xff, s & 0xff, (e >> 8) & 0xff,
                              e & 0xff};
      write(fd, tmp, 5);
      for (; s < e; s++) {
        fread(buf, 1, 1, inf);
        res = write(fd, buf, 1);
        if (res < 1) {
          fprintf(stderr, "error %d\n", errno);
          break;
        }
      }
      res = read(fd, buf, 1);
      if (buf[0] == 'O') {
        fprintf(stderr, "OK\n");
      }
      fclose(inf);
    } else {
      fprintf(stderr, "Can't open infile\n");
    }
  }
  if (!strcmp(argv[2], "go")) {
    unsigned int s;
    unsigned int e;
    sscanf(argv[3], "%x", &s);
    fprintf(stderr, "go %x\n", s);
    unsigned char tmp[5] = {'G', (s >> 8) & 0xff, s & 0xff};
    write(fd, tmp, 3);
  }
  tcsetattr(fd, TCSANOW, &tty_old);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1a0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x130(%rbp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1080 <memset@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2d5d(%rip),%rax
mov    (%rax),%esi
mov    0x2d04(%rip),%rax
or     (%rax),%esi
call   1120 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    12be <main+0x6e>
lea    0xd51(%rip),%rdi
call   1150 <perror@plt>
mov    $0xffffffff,%edi
call   1160 <exit@plt>
mov    -0x14(%rbp),%edi
lea    -0x130(%rbp),%rsi
call   1100 <tcgetattr@plt>
cmp    $0x0,%rax
je     12f7 <main+0xa7>
mov    0x2cb2(%rip),%rax
mov    (%rax),%edi
mov    0x2ca1(%rip),%rax
mov    (%rax),%edx
lea    0xd1d(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
mov    -0x130(%rbp),%rax
mov    %rax,-0x140(%rbp)
mov    -0x128(%rbp),%rax
mov    %rax,-0x138(%rbp)
mov    0x2c5e(%rip),%rax
mov    (%rax),%rax
mov    %eax,%esi
lea    -0x130(%rbp),%rdi
call   1060 <cfsetospeed@plt>
mov    0x2c46(%rip),%rax
mov    (%rax),%rax
mov    %eax,%esi
lea    -0x130(%rbp),%rdi
call   1140 <cfsetispeed@plt>
mov    0x2c8e(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x130(%rbp),%eax
mov    %eax,-0x130(%rbp)
mov    0x2bf6(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x130(%rbp),%eax
mov    %eax,-0x130(%rbp)
mov    0x2c36(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x130(%rbp),%eax
mov    %eax,-0x130(%rbp)
mov    0x2c2e(%rip),%rax
mov    (%rax),%eax
or     -0x130(%rbp),%eax
mov    %eax,-0x130(%rbp)
mov    0x2bb9(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x130(%rbp),%eax
mov    %eax,-0x130(%rbp)
mov    -0x128(%rbp),%rax
mov    0x2bf2(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x1,(%rax,%rcx,4)
mov    -0x128(%rbp),%rax
mov    0x2b92(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x5,(%rax,%rcx,4)
mov    0x2bd9(%rip),%rax
mov    (%rax),%eax
mov    0x2b58(%rip),%rcx
or     (%rcx),%eax
or     -0x130(%rbp),%eax
mov    %eax,-0x130(%rbp)
lea    -0x130(%rbp),%rdi
call   10f0 <cfmakeraw@plt>
mov    -0x14(%rbp),%edi
mov    0x2b84(%rip),%rax
mov    (%rax),%esi
call   1070 <tcflush@plt>
mov    -0x14(%rbp),%edi
mov    0x2ba3(%rip),%rax
mov    (%rax),%esi
lea    -0x130(%rbp),%rdx
call   1110 <tcsetattr@plt>
cmp    $0x0,%rax
je     1465 <main+0x215>
mov    0x2b44(%rip),%rax
mov    (%rax),%edi
mov    0x2b33(%rip),%rax
mov    (%rax),%edx
lea    0xbc8(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xbcb(%rip),%rsi
call   10a0 <strcmp@plt>
cmp    $0x0,%eax
jne    165c <main+0x40c>
mov    -0x10(%rbp),%rax
mov    0x20(%rax),%rdi
lea    0xbb3(%rip),%rsi
lea    -0x144(%rbp),%rdx
call   10d0 <sscanf@plt>
mov    -0x10(%rbp),%rax
mov    0x28(%rax),%rdi
lea    0xb98(%rip),%rsi
lea    -0x148(%rbp),%rdx
call   10d0 <sscanf@plt>
mov    0x2ad1(%rip),%rax
mov    (%rax),%edi
mov    -0x144(%rbp),%edx
mov    -0x148(%rbp),%ecx
lea    0xb73(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
lea    0xb66(%rip),%rsi
call   1130 <fopen@plt>
mov    %rax,-0x150(%rbp)
cmpq   $0x0,-0x150(%rbp)
je     1640 <main+0x3f0>
movb   $0x53,-0x155(%rbp)
mov    -0x144(%rbp),%eax
shr    $0x8,%eax
and    $0xff,%eax
mov    %al,-0x154(%rbp)
mov    -0x144(%rbp),%eax
and    $0xff,%eax
mov    %al,-0x153(%rbp)
mov    -0x148(%rbp),%eax
shr    $0x8,%eax
and    $0xff,%eax
mov    %al,-0x152(%rbp)
mov    -0x148(%rbp),%eax
and    $0xff,%eax
mov    %al,-0x151(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x155(%rbp),%rsi
mov    $0x5,%edx
mov    $0x0,%al
call   1040 <write@plt>
mov    -0x144(%rbp),%eax
cmp    -0x148(%rbp),%eax
jae    15f1 <main+0x3a1>
mov    -0x14(%rbp),%edi
lea    -0x120(%rbp),%rsi
mov    $0x1,%edx
call   1090 <read@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    15c3 <main+0x373>
mov    0x29eb(%rip),%rax
mov    (%rax),%edi
mov    0x29da(%rip),%rax
mov    (%rax),%edx
lea    0xa9c(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
jmp    15f1 <main+0x3a1>
lea    -0x120(%rbp),%rdi
mov    -0x150(%rbp),%rcx
mov    $0x1,%edx
mov    %edx,%esi
call   1170 <fwrite@plt>
mov    -0x144(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x144(%rbp)
jmp    156b <main+0x31b>
mov    -0x14(%rbp),%edi
lea    -0x120(%rbp),%rsi
mov    $0x1,%edx
call   1090 <read@plt>
mov    %eax,-0x18(%rbp)
movsbl -0x120(%rbp),%eax
cmp    $0x4f,%eax
jne    162f <main+0x3df>
mov    0x2971(%rip),%rax
mov    (%rax),%edi
lea    0xa35(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
mov    -0x150(%rbp),%rdi
call   1050 <fclose@plt>
jmp    1657 <main+0x407>
mov    0x2949(%rip),%rax
mov    (%rax),%edi
lea    0xa11(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
jmp    165c <main+0x40c>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xa0a(%rip),%rsi
call   10a0 <strcmp@plt>
cmp    $0x0,%eax
jne    18d8 <main+0x688>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
lea    0x9f2(%rip),%rsi
call   1130 <fopen@plt>
mov    %rax,-0x168(%rbp)
cmpq   $0x0,-0x168(%rbp)
je     18bc <main+0x66c>
cmpl   $0x5,-0x8(%rbp)
jge    16bb <main+0x46b>
movl   $0x100,-0x15c(%rbp)
jmp    16d6 <main+0x486>
mov    -0x10(%rbp),%rax
mov    0x20(%rax),%rdi
lea    0x97a(%rip),%rsi
lea    -0x15c(%rbp),%rdx
call   10d0 <sscanf@plt>
cmpl   $0x6,-0x8(%rbp)
jge    173b <main+0x4eb>
mov    -0x168(%rbp),%rdi
mov    0x28f2(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   10e0 <fseek@plt>
mov    -0x15c(%rbp),%eax
mov    %eax,-0x184(%rbp)
mov    -0x168(%rbp),%rdi
call   10c0 <ftell@plt>
mov    %eax,%ecx
mov    -0x184(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0x160(%rbp)
mov    -0x168(%rbp),%rdi
mov    0x2853(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   10e0 <fseek@plt>
jmp    1756 <main+0x506>
mov    -0x10(%rbp),%rax
mov    0x28(%rax),%rdi
lea    0x8fa(%rip),%rsi
lea    -0x160(%rbp),%rdx
call   10d0 <sscanf@plt>
mov    0x2833(%rip),%rax
mov    (%rax),%edi
mov    -0x15c(%rbp),%edx
mov    -0x160(%rbp),%ecx
lea    0x90b(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
movb   $0x4c,-0x16d(%rbp)
mov    -0x15c(%rbp),%eax
shr    $0x8,%eax
and    $0xff,%eax
mov    %al,-0x16c(%rbp)
mov    -0x15c(%rbp),%eax
and    $0xff,%eax
mov    %al,-0x16b(%rbp)
mov    -0x160(%rbp),%eax
shr    $0x8,%eax
and    $0xff,%eax
mov    %al,-0x16a(%rbp)
mov    -0x160(%rbp),%eax
and    $0xff,%eax
mov    %al,-0x169(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x16d(%rbp),%rsi
mov    $0x5,%edx
mov    $0x0,%al
call   1040 <write@plt>
mov    -0x15c(%rbp),%eax
cmp    -0x160(%rbp),%eax
jae    186d <main+0x61d>
lea    -0x120(%rbp),%rdi
mov    -0x168(%rbp),%rcx
mov    $0x1,%edx
mov    %edx,%esi
call   1030 <fread@plt>
mov    -0x14(%rbp),%edi
lea    -0x120(%rbp),%rsi
mov    $0x1,%edx
mov    $0x0,%al
call   1040 <write@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x1,-0x18(%rbp)
jge    1854 <main+0x604>
mov    0x275a(%rip),%rax
mov    (%rax),%edi
mov    0x2749(%rip),%rax
mov    (%rax),%edx
lea    0x80b(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
jmp    186d <main+0x61d>
jmp    1859 <main+0x609>
mov    -0x15c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x15c(%rbp)
jmp    17e0 <main+0x590>
mov    -0x14(%rbp),%edi
lea    -0x120(%rbp),%rsi
mov    $0x1,%edx
call   1090 <read@plt>
mov    %eax,-0x18(%rbp)
movsbl -0x120(%rbp),%eax
cmp    $0x4f,%eax
jne    18ab <main+0x65b>
mov    0x26f5(%rip),%rax
mov    (%rax),%edi
lea    0x7b9(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
mov    -0x168(%rbp),%rdi
call   1050 <fclose@plt>
jmp    18d3 <main+0x683>
mov    0x26cd(%rip),%rax
mov    (%rax),%edi
lea    0x7ba(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
jmp    18d8 <main+0x688>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0x7b2(%rip),%rsi
call   10a0 <strcmp@plt>
cmp    $0x0,%eax
jne    19c5 <main+0x775>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
lea    0x740(%rip),%rsi
lea    -0x174(%rbp),%rdx
call   10d0 <sscanf@plt>
mov    0x2679(%rip),%rax
mov    (%rax),%edi
mov    -0x174(%rbp),%edx
lea    0x776(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
lea    -0x17d(%rbp),%rcx
movb   $0x47,-0x17d(%rbp)
mov    %rcx,%rax
add    $0x1,%rax
mov    -0x174(%rbp),%edx
shr    $0x8,%edx
and    $0xff,%edx
mov    %dl,-0x17c(%rbp)
add    $0x1,%rax
mov    -0x174(%rbp),%edx
and    $0xff,%edx
mov    %dl,-0x17b(%rbp)
add    $0x1,%rax
add    $0x5,%rcx
mov    %rcx,-0x198(%rbp)
mov    %rax,-0x190(%rbp)
mov    -0x190(%rbp),%rax
mov    -0x198(%rbp),%rcx
movb   $0x0,(%rax)
add    $0x1,%rax
mov    %rax,-0x1a0(%rbp)
cmp    %rcx,%rax
mov    %rax,-0x190(%rbp)
jne    1983 <main+0x733>
mov    -0x14(%rbp),%edi
lea    -0x17d(%rbp),%rsi
mov    $0x3,%edx
mov    $0x0,%al
call   1040 <write@plt>
mov    -0x14(%rbp),%edi
mov    0x2601(%rip),%rax
mov    (%rax),%esi
lea    -0x140(%rbp),%rdx
call   1110 <tcsetattr@plt>
xor    %eax,%eax
add    $0x1a0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x138,%rsp
mov    %rsi,%r14
mov    %edi,%r15d
lea    0x10(%rsp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1080 <memset@plt>
mov    0x8(%r14),%rdi
mov    0x2d65(%rip),%rax
mov    0x2d0e(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
call   1130 <open@plt>
test   %eax,%eax
js     177f <main+0x52f>
mov    %eax,%r13d
lea    0x10(%rsp),%rsi
mov    %eax,%edi
call   1110 <tcgetattr@plt>
test   %rax,%rax
je     12cf <main+0x7f>
mov    0x2cda(%rip),%rax
mov    (%rax),%edi
mov    0x2cc9(%rip),%rax
mov    (%rax),%edx
lea    0xd45(%rip),%rsi
xor    %eax,%eax
call   10c0 <fprintf@plt>
movups 0x10(%rsp),%xmm0
movaps %xmm0,0x20(%rsp)
mov    0x2c98(%rip),%rbx
mov    (%rbx),%esi
lea    0x10(%rsp),%rbp
mov    %rbp,%rdi
call   1060 <cfsetospeed@plt>
mov    (%rbx),%esi
mov    %rbp,%rdi
call   1150 <cfsetispeed@plt>
mov    0x2cd8(%rip),%rax
mov    (%rax),%eax
mov    0x2c4f(%rip),%rcx
or     (%rcx),%eax
mov    0x2c9e(%rip),%rcx
or     (%rcx),%eax
not    %eax
and    0x10(%rsp),%eax
mov    0x2c9f(%rip),%rcx
or     (%rcx),%eax
mov    0x2c36(%rip),%rcx
mov    (%rcx),%ecx
not    %ecx
and    %eax,%ecx
mov    %ecx,0x10(%rsp)
mov    0x18(%rsp),%rax
mov    0x2c78(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x1,(%rax,%rcx,4)
mov    0x2c1f(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x5,(%rax,%rcx,4)
mov    0x2c66(%rip),%rax
mov    0x2be7(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
or     %ecx,0x10(%rsp)
mov    %rbp,%rdi
call   1100 <cfmakeraw@plt>
mov    0x2c20(%rip),%rax
mov    (%rax),%esi
mov    %r13d,%edi
call   1070 <tcflush@plt>
mov    0x2c3f(%rip),%rbx
mov    (%rbx),%esi
mov    %r13d,%edi
mov    %rbp,%rdx
call   1120 <tcsetattr@plt>
test   %rax,%rax
je     13c3 <main+0x173>
mov    0x2be6(%rip),%rax
mov    (%rax),%edi
mov    0x2bd5(%rip),%rax
mov    (%rax),%edx
lea    0xc6a(%rip),%rsi
xor    %eax,%eax
call   10c0 <fprintf@plt>
mov    0x10(%r14),%rbp
lea    0xc71(%rip),%rsi
mov    %rbp,%rdi
call   10b0 <strcmp@plt>
test   %eax,%eax
jne    152f <main+0x2df>
mov    0x20(%r14),%rdi
lea    0xc5b(%rip),%rbx
mov    %rsp,%rdx
mov    %rbx,%rsi
call   10e0 <sscanf@plt>
mov    0x28(%r14),%rdi
lea    0x4(%rsp),%rdx
mov    %rbx,%rsi
call   10e0 <sscanf@plt>
mov    0x2b84(%rip),%r12
mov    (%r12),%edi
mov    (%rsp),%edx
mov    0x4(%rsp),%ecx
lea    0xc29(%rip),%rsi
xor    %eax,%eax
call   10c0 <fprintf@plt>
mov    0x18(%r14),%rdi
lea    0xc20(%rip),%rsi
call   1140 <fopen@plt>
test   %rax,%rax
je     14c2 <main+0x272>
mov    %rax,%rbp
movb   $0x53,0xb(%rsp)
movzwl (%rsp),%eax
rol    $0x8,%ax
mov    %ax,0xc(%rsp)
movzwl 0x4(%rsp),%eax
rol    $0x8,%ax
mov    %ax,0xe(%rsp)
lea    0xb(%rsp),%rsi
mov    %r13d,%edi
mov    $0x5,%edx
xor    %eax,%eax
call   1040 <write@plt>
mov    (%rsp),%eax
cmp    0x4(%rsp),%eax
jae    14f1 <main+0x2a1>
lea    0x30(%rsp),%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %r13d,%edi
mov    %rbx,%rsi
mov    $0x1,%edx
call   10a0 <read@plt>
test   %eax,%eax
js     14d6 <main+0x286>
movsbl 0x30(%rsp),%edi
mov    %rbp,%rsi
call   1090 <fputc@plt>
mov    (%rsp),%eax
add    $0x1,%eax
mov    %eax,(%rsp)
cmp    0x4(%rsp),%eax
jb     1490 <main+0x240>
jmp    14f1 <main+0x2a1>
mov    (%r12),%edi
lea    0xb94(%rip),%rsi
xor    %eax,%eax
call   10c0 <fprintf@plt>
jmp    1524 <main+0x2d4>
mov    (%r12),%edi
mov    0x2aa7(%rip),%rax
mov    (%rax),%edx
lea    0xb69(%rip),%rsi
xor    %eax,%eax
call   10c0 <fprintf@plt>
lea    0x30(%rsp),%rsi
mov    %r13d,%edi
mov    $0x1,%edx
call   10a0 <read@plt>
cmpb   $0x4f,0x30(%rsp)
jne    151c <main+0x2cc>
mov    (%r12),%edi
lea    0xb48(%rip),%rsi
xor    %eax,%eax
call   10c0 <fprintf@plt>
mov    %rbp,%rdi
call   1050 <fclose@plt>
mov    0x2aa5(%rip),%rbx
mov    0x10(%r14),%rbp
lea    0xb3f(%rip),%rsi
mov    %rbp,%rdi
call   10b0 <strcmp@plt>
test   %eax,%eax
jne    16f1 <main+0x4a1>
mov    0x18(%r14),%rdi
lea    0xb29(%rip),%rsi
call   1140 <fopen@plt>
test   %rax,%rax
je     156d <main+0x31d>
mov    %rax,%r12
cmp    $0x4,%r15d
jg     1589 <main+0x339>
movl   $0x100,(%rsp)
jmp    15a2 <main+0x352>
mov    0x2a1c(%rip),%rax
mov    (%rax),%edi
lea    0xb09(%rip),%rsi
xor    %eax,%eax
call   10c0 <fprintf@plt>
jmp    16ed <main+0x49d>
mov    0x20(%r14),%rdi
lea    0xab0(%rip),%rsi
mov    %rsp,%rdx
call   10e0 <sscanf@plt>
cmp    $0x5,%r15d
jne    15dd <main+0x38d>
mov    0x2a37(%rip),%rax
mov    (%rax),%edx
mov    %r12,%rdi
xor    %esi,%esi
call   10f0 <fseek@plt>
mov    (%rsp),%ebx
mov    %r12,%rdi
call   10d0 <ftell@plt>
mov    %eax,%ebp
add    %ebx,%ebp
mov    %ebp,0x4(%rsp)
mov    0x29b1(%rip),%rax
mov    (%rax),%edx
mov    %r12,%rdi
xor    %esi,%esi
call   10f0 <fseek@plt>
jmp    15f6 <main+0x3a6>
mov    0x28(%r14),%rdi
lea    0xa5c(%rip),%rsi
lea    0x4(%rsp),%rdx
call   10e0 <sscanf@plt>
mov    0x4(%rsp),%ebp
mov    0x2993(%rip),%rbx
mov    (%rbx),%edi
mov    (%rsp),%edx
lea    0xa74(%rip),%rsi
mov    %ebp,%ecx
xor    %eax,%eax
call   10c0 <fprintf@plt>
movb   $0x4c,0xb(%rsp)
movzwl (%rsp),%eax
rol    $0x8,%ax
mov    %ax,0xc(%rsp)
movzwl 0x4(%rsp),%eax
rol    $0x8,%ax
mov    %ax,0xe(%rsp)
lea    0xb(%rsp),%rsi
mov    %r13d,%edi
mov    $0x5,%edx
xor    %eax,%eax
call   1040 <write@plt>
mov    (%rsp),%eax
cmp    0x4(%rsp),%eax
jae    16b5 <main+0x465>
lea    0x30(%rsp),%rbp
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %rbp,%rdi
mov    $0x1,%esi
mov    $0x1,%edx
mov    %r12,%rcx
call   1030 <fread@plt>
mov    %r13d,%edi
mov    %rbp,%rsi
mov    $0x1,%edx
xor    %eax,%eax
call   1040 <write@plt>
test   %eax,%eax
jle    169c <main+0x44c>
mov    (%rsp),%eax
add    $0x1,%eax
mov    %eax,(%rsp)
cmp    0x4(%rsp),%eax
jb     1660 <main+0x410>
jmp    16b5 <main+0x465>
mov    (%rbx),%edi
mov    0x28e3(%rip),%rax
mov    (%rax),%edx
lea    0x9a5(%rip),%rsi
xor    %eax,%eax
call   10c0 <fprintf@plt>
lea    0x30(%rsp),%rsi
mov    %r13d,%edi
mov    $0x1,%edx
call   10a0 <read@plt>
cmpb   $0x4f,0x30(%rsp)
jne    16de <main+0x48e>
mov    (%rbx),%edi
lea    0x986(%rip),%rsi
xor    %eax,%eax
call   10c0 <fprintf@plt>
mov    %r12,%rdi
call   1050 <fclose@plt>
mov    0x28e3(%rip),%rbx
mov    0x10(%r14),%rbp
lea    0x9a1(%rip),%rsi
mov    %rbp,%rdi
call   10b0 <strcmp@plt>
test   %eax,%eax
jne    175c <main+0x50c>
mov    0x18(%r14),%rdi
lea    0x935(%rip),%rsi
mov    %rsp,%rdx
call   10e0 <sscanf@plt>
mov    0x2872(%rip),%rax
mov    (%rax),%edi
mov    (%rsp),%edx
lea    0x972(%rip),%rsi
xor    %eax,%eax
call   10c0 <fprintf@plt>
movb   $0x47,0xb(%rsp)
mov    (%rsp),%eax
mov    %ah,0xc(%rsp)
mov    %al,0xd(%rsp)
movw   $0x0,0xe(%rsp)
lea    0xb(%rsp),%rsi
mov    %r13d,%edi
mov    $0x3,%edx
xor    %eax,%eax
call   1040 <write@plt>
mov    (%rbx),%esi
lea    0x20(%rsp),%rdx
mov    %r13d,%edi
call   1120 <tcsetattr@plt>
xor    %eax,%eax
add    $0x138,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0x87a(%rip),%rdi
call   1160 <perror@plt>
mov    $0xffffffff,%edi
call   1170 <exit@plt>

LLVM IR (-O0):
%struct.termios = type { i32, i32* }
@O_RDWR = global i32 0
@O_NOCTTY = global i32 0
@.str = [13 x i8] c"/dev/ttyUSB0\00"
@stderr = global i32 0
@.str.1 = [25 x i8] c"error %d from tcgetattr\0A\00"
@errno = global i32 0
@B115200 = global i64 0
@PARENB = global i32 0
@CSTOPB = global i32 0
@CSIZE = global i32 0
@CS8 = global i32 0
@CRTSCTS = global i32 0
@VMIN = global i64 0
@VTIME = global i64 0
@CREAD = global i32 0
@CLOCAL = global i32 0
@TCIFLUSH = global i32 0
@TCSANOW = global i32 0
@.str.2 = [25 x i8] c"error %d from tcsetattr\0A\00"
@.str.3 = [5 x i8] c"save\00"
@.str.4 = [3 x i8] c"%x\00"
@.str.5 = [9 x i8] c"> %x %x\0A\00"
@.str.6 = [3 x i8] c"wb\00"
@.str.7 = [10 x i8] c"error %d\0A\00"
@.str.8 = [4 x i8] c"OK\0A\00"
@.str.9 = [20 x i8] c"Can't open outfile\0A\00"
@.str.10 = [5 x i8] c"load\00"
@.str.11 = [3 x i8] c"rb\00"
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
@.str.12 = [9 x i8] c"< %x %x\0A\00"
@.str.13 = [19 x i8] c"Can't open infile\0A\00"
@.str.14 = [3 x i8] c"go\00"
@.str.15 = [7 x i8] c"go %x\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 [255 x i8]
%9 = alloca %struct.termios
%10 = alloca %struct.termios
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32*
%14 = alloca [5 x i8]
%15 = alloca i32
%16 = alloca i32
%17 = alloca i32*
%18 = alloca [5 x i8]
%19 = alloca i32
%20 = alloca i32
%21 = alloca [5 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%22 = call i32 @memset(%struct.termios* %9, i32 0, i32 16)
%23 = load i8**, i8*** %5
%24 = getelementptr inbounds i8*, i8** %23, i64 1
%25 = load i8*, i8** %24
%26 = load i32, i32* @O_RDWR
%27 = load i32, i32* @O_NOCTTY
%28 = or i32 %26, %27
%29 = call i32 @open(i8* %25, i32 %28)
store i32 %29, i32* %6
%30 = load i32, i32* %6
%31 = icmp slt i32 %30, 0
br i1 %31, label %32, label %35
32: ; preds = %2
%33 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%34 = call i32 @exit(i32 -1)
unreachable
35: ; preds = %2
%36 = load i32, i32* %6
%37 = call i64 @tcgetattr(i32 %36, %struct.termios* %9)
%38 = icmp ne i64 %37, 0
br i1 %38, label %39, label %43
39: ; preds = %35
%40 = load i32, i32* @stderr
%41 = load i32, i32* @errno
%42 = call i32 (i32, i8*, ...) @fprintf(i32 %40, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i32 %41)
br label %43
43: ; preds = %39, %35
%44 = bitcast %struct.termios* %10 to i8*
%45 = bitcast %struct.termios* %9 to i8*
%46 = load i64, i64* @B115200
%47 = trunc i64 %46 to i32
%48 = call i32 @cfsetospeed(%struct.termios* %9, i32 %47)
%49 = load i64, i64* @B115200
%50 = trunc i64 %49 to i32
%51 = call i32 @cfsetispeed(%struct.termios* %9, i32 %50)
%52 = load i32, i32* @PARENB
%53 = xor i32 %52, -1
%54 = getelementptr inbounds %struct.termios, %struct.termios* %9, i32 0, i32 0
%55 = load i32, i32* %54
%56 = and i32 %55, %53
store i32 %56, i32* %54
%57 = load i32, i32* @CSTOPB
%58 = xor i32 %57, -1
%59 = getelementptr inbounds %struct.termios, %struct.termios* %9, i32 0, i32 0
%60 = load i32, i32* %59
%61 = and i32 %60, %58
store i32 %61, i32* %59
%62 = load i32, i32* @CSIZE
%63 = xor i32 %62, -1
%64 = getelementptr inbounds %struct.termios, %struct.termios* %9, i32 0, i32 0
%65 = load i32, i32* %64
%66 = and i32 %65, %63
store i32 %66, i32* %64
%67 = load i32, i32* @CS8
%68 = getelementptr inbounds %struct.termios, %struct.termios* %9, i32 0, i32 0
%69 = load i32, i32* %68
%70 = or i32 %69, %67
store i32 %70, i32* %68
%71 = load i32, i32* @CRTSCTS
%72 = xor i32 %71, -1
%73 = getelementptr inbounds %struct.termios, %struct.termios* %9, i32 0, i32 0
%74 = load i32, i32* %73
%75 = and i32 %74, %72
store i32 %75, i32* %73
%76 = getelementptr inbounds %struct.termios, %struct.termios* %9, i32 0, i32 1
%77 = load i32*, i32** %76
%78 = load i64, i64* @VMIN
%79 = getelementptr inbounds i32, i32* %77, i64 %78
store i32 1, i32* %79
%80 = getelementptr inbounds %struct.termios, %struct.termios* %9, i32 0, i32 1
%81 = load i32*, i32** %80
%82 = load i64, i64* @VTIME
%83 = getelementptr inbounds i32, i32* %81, i64 %82
store i32 5, i32* %83
%84 = load i32, i32* @CREAD
%85 = load i32, i32* @CLOCAL
%86 = or i32 %84, %85
%87 = getelementptr inbounds %struct.termios, %struct.termios* %9, i32 0, i32 0
%88 = load i32, i32* %87
%89 = or i32 %88, %86
store i32 %89, i32* %87
%90 = call i32 @cfmakeraw(%struct.termios* %9)
%91 = load i32, i32* %6
%92 = load i32, i32* @TCIFLUSH
%93 = call i32 @tcflush(i32 %91, i32 %92)
%94 = load i32, i32* %6
%95 = load i32, i32* @TCSANOW
%96 = call i64 @tcsetattr(i32 %94, i32 %95, %struct.termios* %9)
%97 = icmp ne i64 %96, 0
br i1 %97, label %98, label %102
98: ; preds = %43
%99 = load i32, i32* @stderr
%100 = load i32, i32* @errno
%101 = call i32 (i32, i8*, ...) @fprintf(i32 %99, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0), i32 %100)
br label %102
102: ; preds = %98, %43
%103 = load i8**, i8*** %5
%104 = getelementptr inbounds i8*, i8** %103, i64 2
%105 = load i8*, i8** %104
%106 = call i32 @strcmp(i8* %105, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%107 = icmp ne i32 %106, 0
br i1 %107, label %189, label %108
108: ; preds = %102
%109 = load i8**, i8*** %5
%110 = getelementptr inbounds i8*, i8** %109, i64 4
%111 = load i8*, i8** %110
%112 = call i32 @sscanf(i8* %111, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32* %11)
%113 = load i8**, i8*** %5
%114 = getelementptr inbounds i8*, i8** %113, i64 5
%115 = load i8*, i8** %114
%116 = call i32 @sscanf(i8* %115, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32* %12)
%117 = load i32, i32* @stderr
%118 = load i32, i32* %11
%119 = load i32, i32* %12
%120 = call i32 (i32, i8*, ...) @fprintf(i32 %117, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0), i32 %118, i32 %119)
%121 = load i8**, i8*** %5
%122 = getelementptr inbounds i8*, i8** %121, i64 3
%123 = load i8*, i8** %122
%124 = call i32* @fopen(i8* %123, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0))
store i32* %124, i32** %13
%125 = load i32*, i32** %13
%126 = icmp ne i32* %125, null
br i1 %126, label %127, label %185
127: ; preds = %108
%128 = getelementptr inbounds [5 x i8], [5 x i8]* %14, i64 0, i64 0
store i8 83, i8* %128
%129 = getelementptr inbounds i8, i8* %128, i64 1
%130 = load i32, i32* %11
%131 = lshr i32 %130, 8
%132 = and i32 %131, 255
%133 = trunc i32 %132 to i8
store i8 %133, i8* %129
%134 = getelementptr inbounds i8, i8* %129, i64 1
%135 = load i32, i32* %11
%136 = and i32 %135, 255
%137 = trunc i32 %136 to i8
store i8 %137, i8* %134
%138 = getelementptr inbounds i8, i8* %134, i64 1
%139 = load i32, i32* %12
%140 = lshr i32 %139, 8
%141 = and i32 %140, 255
%142 = trunc i32 %141 to i8
store i8 %142, i8* %138
%143 = getelementptr inbounds i8, i8* %138, i64 1
%144 = load i32, i32* %12
%145 = and i32 %144, 255
%146 = trunc i32 %145 to i8
store i8 %146, i8* %143
%147 = load i32, i32* %6
%148 = getelementptr inbounds [5 x i8], [5 x i8]* %14, i64 0, i64 0
%149 = call i32 (i32, ...) @write(i32 %147, i8* %148, i32 5)
br label %150
150: ; preds = %168, %127
%151 = load i32, i32* %11
%152 = load i32, i32* %12
%153 = icmp ult i32 %151, %152
br i1 %153, label %154, label %171
154: ; preds = %150
%155 = load i32, i32* %6
%156 = getelementptr inbounds [255 x i8], [255 x i8]* %8, i64 0, i64 0
%157 = call i32 @read(i32 %155, i8* %156, i32 1)
store i32 %157, i32* %7
%158 = load i32, i32* %7
%159 = icmp slt i32 %158, 0
br i1 %159, label %160, label %164
160: ; preds = %154
%161 = load i32, i32* @stderr
%162 = load i32, i32* @errno
%163 = call i32 (i32, i8*, ...) @fprintf(i32 %161, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.7, i64 0, i64 0), i32 %162)
br label %171
164: ; preds = %154
%165 = getelementptr inbounds [255 x i8], [255 x i8]* %8, i64 0, i64 0
%166 = load i32*, i32** %13
%167 = call i32 @fwrite(i8* %165, i32 1, i32 1, i32* %166)
br label %168
168: ; preds = %164
%169 = load i32, i32* %11
%170 = add i32 %169, 1
store i32 %170, i32* %11
br label %150
171: ; preds = %160, %150
%172 = load i32, i32* %6
%173 = getelementptr inbounds [255 x i8], [255 x i8]* %8, i64 0, i64 0
%174 = call i32 @read(i32 %172, i8* %173, i32 1)
store i32 %174, i32* %7
%175 = getelementptr inbounds [255 x i8], [255 x i8]* %8, i64 0, i64 0
%176 = load i8, i8* %175
%177 = sext i8 %176 to i32
%178 = icmp eq i32 %177, 79
br i1 %178, label %179, label %182
179: ; preds = %171
%180 = load i32, i32* @stderr
%181 = call i32 (i32, i8*, ...) @fprintf(i32 %180, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.8, i64 0, i64 0))
br label %182
182: ; preds = %179, %171
%183 = load i32*, i32** %13
%184 = call i32 @fclose(i32* %183)
br label %188
185: ; preds = %108
%186 = load i32, i32* @stderr
%187 = call i32 (i32, i8*, ...) @fprintf(i32 %186, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.9, i64 0, i64 0))
br label %188
188: ; preds = %185, %182
br label %189
189: ; preds = %188, %102
%190 = load i8**, i8*** %5
%191 = getelementptr inbounds i8*, i8** %190, i64 2
%192 = load i8*, i8** %191
%193 = call i32 @strcmp(i8* %192, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.10, i64 0, i64 0))
%194 = icmp ne i32 %193, 0
br i1 %194, label %296, label %195
195: ; preds = %189
%196 = load i8**, i8*** %5
%197 = getelementptr inbounds i8*, i8** %196, i64 3
%198 = load i8*, i8** %197
%199 = call i32* @fopen(i8* %198, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.11, i64 0, i64 0))
store i32* %199, i32** %17
%200 = load i32*, i32** %17
%201 = icmp ne i32* %200, null
br i1 %201, label %202, label %292
202: ; preds = %195
%203 = load i32, i32* %4
%204 = icmp slt i32 %203, 5
br i1 %204, label %205, label %206
205: ; preds = %202
store i32 256, i32* %15
br label %211
206: ; preds = %202
%207 = load i8**, i8*** %5
%208 = getelementptr inbounds i8*, i8** %207, i64 4
%209 = load i8*, i8** %208
%210 = call i32 @sscanf(i8* %209, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32* %15)
br label %211
211: ; preds = %206, %205
%212 = load i32, i32* %4
%213 = icmp slt i32 %212, 6
br i1 %213, label %214, label %225
214: ; preds = %211
%215 = load i32*, i32** %17
%216 = load i32, i32* @SEEK_END
%217 = call i32 @fseek(i32* %215, i32 0, i32 %216)
%218 = load i32, i32* %15
%219 = load i32*, i32** %17
%220 = call i32 @ftell(i32* %219)
%221 = add i32 %218, %220
store i32 %221, i32* %16
%222 = load i32*, i32** %17
%223 = load i32, i32* @SEEK_SET
%224 = call i32 @fseek(i32* %222, i32 0, i32 %223)
br label %230
225: ; preds = %211
%226 = load i8**, i8*** %5
%227 = getelementptr inbounds i8*, i8** %226, i64 5
%228 = load i8*, i8** %227
%229 = call i32 @sscanf(i8* %228, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32* %16)
br label %230
230: ; preds = %225, %214
%231 = load i32, i32* @stderr
%232 = load i32, i32* %15
%233 = load i32, i32* %16
%234 = call i32 (i32, i8*, ...) @fprintf(i32 %231, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.12, i64 0, i64 0), i32 %232, i32 %233)
%235 = getelementptr inbounds [5 x i8], [5 x i8]* %18, i64 0, i64 0
store i8 76, i8* %235
%236 = getelementptr inbounds i8, i8* %235, i64 1
%237 = load i32, i32* %15
%238 = lshr i32 %237, 8
%239 = and i32 %238, 255
%240 = trunc i32 %239 to i8
store i8 %240, i8* %236
%241 = getelementptr inbounds i8, i8* %236, i64 1
%242 = load i32, i32* %15
%243 = and i32 %242, 255
%244 = trunc i32 %243 to i8
store i8 %244, i8* %241
%245 = getelementptr inbounds i8, i8* %241, i64 1
%246 = load i32, i32* %16
%247 = lshr i32 %246, 8
%248 = and i32 %247, 255
%249 = trunc i32 %248 to i8
store i8 %249, i8* %245
%250 = getelementptr inbounds i8, i8* %245, i64 1
%251 = load i32, i32* %16
%252 = and i32 %251, 255
%253 = trunc i32 %252 to i8
store i8 %253, i8* %250
%254 = load i32, i32* %6
%255 = getelementptr inbounds [5 x i8], [5 x i8]* %18, i64 0, i64 0
%256 = call i32 (i32, ...) @write(i32 %254, i8* %255, i32 5)
br label %257
257: ; preds = %275, %230
%258 = load i32, i32* %15
%259 = load i32, i32* %16
%260 = icmp ult i32 %258, %259
br i1 %260, label %261, label %278
261: ; preds = %257
%262 = getelementptr inbounds [255 x i8], [255 x i8]* %8, i64 0, i64 0
%263 = load i32*, i32** %17
%264 = call i32 @fread(i8* %262, i32 1, i32 1, i32* %263)
%265 = load i32, i32* %6
%266 = getelementptr inbounds [255 x i8], [255 x i8]* %8, i64 0, i64 0
%267 = call i32 (i32, ...) @write(i32 %265, i8* %266, i32 1)
store i32 %267, i32* %7
%268 = load i32, i32* %7
%269 = icmp slt i32 %268, 1
br i1 %269, label %270, label %274
270: ; preds = %261
%271 = load i32, i32* @stderr
%272 = load i32, i32* @errno
%273 = call i32 (i32, i8*, ...) @fprintf(i32 %271, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.7, i64 0, i64 0), i32 %272)
br label %278
274: ; preds = %261
br label %275
275: ; preds = %274
%276 = load i32, i32* %15
%277 = add i32 %276, 1
store i32 %277, i32* %15
br label %257
278: ; preds = %270, %257
%279 = load i32, i32* %6
%280 = getelementptr inbounds [255 x i8], [255 x i8]* %8, i64 0, i64 0
%281 = call i32 @read(i32 %279, i8* %280, i32 1)
store i32 %281, i32* %7
%282 = getelementptr inbounds [255 x i8], [255 x i8]* %8, i64 0, i64 0
%283 = load i8, i8* %282
%284 = sext i8 %283 to i32
%285 = icmp eq i32 %284, 79
br i1 %285, label %286, label %289
286: ; preds = %278
%287 = load i32, i32* @stderr
%288 = call i32 (i32, i8*, ...) @fprintf(i32 %287, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.8, i64 0, i64 0))
br label %289
289: ; preds = %286, %278
%290 = load i32*, i32** %17
%291 = call i32 @fclose(i32* %290)
br label %295
292: ; preds = %195
%293 = load i32, i32* @stderr
%294 = call i32 (i32, i8*, ...) @fprintf(i32 %293, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.13, i64 0, i64 0))
br label %295
295: ; preds = %292, %289
br label %296
296: ; preds = %295, %189
%297 = load i8**, i8*** %5
%298 = getelementptr inbounds i8*, i8** %297, i64 2
%299 = load i8*, i8** %298
%300 = call i32 @strcmp(i8* %299, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.14, i64 0, i64 0))
%301 = icmp ne i32 %300, 0
br i1 %301, label %330, label %302
302: ; preds = %296
%303 = load i8**, i8*** %5
%304 = getelementptr inbounds i8*, i8** %303, i64 3
%305 = load i8*, i8** %304
%306 = call i32 @sscanf(i8* %305, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32* %19)
%307 = load i32, i32* @stderr
%308 = load i32, i32* %19
%309 = call i32 (i32, i8*, ...) @fprintf(i32 %307, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.15, i64 0, i64 0), i32 %308)
%310 = getelementptr inbounds [5 x i8], [5 x i8]* %21, i64 0, i64 0
store i8 71, i8* %310
%311 = getelementptr inbounds i8, i8* %310, i64 1
%312 = load i32, i32* %19
%313 = lshr i32 %312, 8
%314 = and i32 %313, 255
%315 = trunc i32 %314 to i8
store i8 %315, i8* %311
%316 = getelementptr inbounds i8, i8* %311, i64 1
%317 = load i32, i32* %19
%318 = and i32 %317, 255
%319 = trunc i32 %318 to i8
store i8 %319, i8* %316
%320 = getelementptr inbounds i8, i8* %316, i64 1
%321 = getelementptr inbounds i8, i8* %310, i64 5
br label %322
322: ; preds = %322, %302
%323 = phi i8* [ %320, %302 ], [ %324, %322 ]
store i8 0, i8* %323
%324 = getelementptr inbounds i8, i8* %323, i64 1
%325 = icmp eq i8* %324, %321
br i1 %325, label %326, label %322
326: ; preds = %322
%327 = load i32, i32* %6
%328 = getelementptr inbounds [5 x i8], [5 x i8]* %21, i64 0, i64 0
%329 = call i32 (i32, ...) @write(i32 %327, i8* %328, i32 3)
br label %330
330: ; preds = %326, %296
%331 = load i32, i32* %6
%332 = load i32, i32* @TCSANOW
%333 = call i64 @tcsetattr(i32 %331, i32 %332, %struct.termios* %10)
ret i32 0
}

LLVM IR (-O2):
%struct.termios = type { i32, i32* }
@O_RDWR = global i32 0
@O_NOCTTY = global i32 0
@.str = [13 x i8] c"/dev/ttyUSB0\00"
@stderr = global i32 0
@.str.1 = [25 x i8] c"error %d from tcgetattr\0A\00"
@errno = global i32 0
@B115200 = global i64 0
@PARENB = global i32 0
@CSTOPB = global i32 0
@CSIZE = global i32 0
@CS8 = global i32 0
@CRTSCTS = global i32 0
@VMIN = global i64 0
@VTIME = global i64 0
@CREAD = global i32 0
@CLOCAL = global i32 0
@TCIFLUSH = global i32 0
@TCSANOW = global i32 0
@.str.2 = [25 x i8] c"error %d from tcsetattr\0A\00"
@.str.3 = [5 x i8] c"save\00"
@.str.4 = [3 x i8] c"%x\00"
@.str.5 = [9 x i8] c"> %x %x\0A\00"
@.str.6 = [3 x i8] c"wb\00"
@.str.7 = [10 x i8] c"error %d\0A\00"
@.str.8 = [4 x i8] c"OK\0A\00"
@.str.9 = [20 x i8] c"Can't open outfile\0A\00"
@.str.10 = [5 x i8] c"load\00"
@.str.11 = [3 x i8] c"rb\00"
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
@.str.12 = [9 x i8] c"< %x %x\0A\00"
@.str.13 = [19 x i8] c"Can't open infile\0A\00"
@.str.14 = [3 x i8] c"go\00"
@.str.15 = [7 x i8] c"go %x\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [255 x i8]
%4 = alloca %struct.termios
%5 = alloca %struct.termios
%6 = alloca i32
%7 = alloca i32
%8 = alloca [5 x i8]
%9 = alloca i32
%10 = alloca i32
%11 = alloca [5 x i8]
%12 = alloca i32
%13 = alloca [5 x i8]
%14 = getelementptr inbounds [255 x i8], [255 x i8]* %3, i64 0, i64 0
%15 = bitcast %struct.termios* %4 to i8*
%16 = bitcast %struct.termios* %5 to i8*
%17 = call i32 @memset(%struct.termios* %4, i32 0, i32 16)
%18 = getelementptr inbounds i8*, i8** %1, i64 1
%19 = load i8*, i8** %18
%20 = load i32, i32* @O_RDWR
%21 = load i32, i32* @O_NOCTTY
%22 = or i32 %21, %20
%23 = call i32 @open(i8* %19, i32 %22)
%24 = icmp slt i32 %23, 0
br i1 %24, label %25, label %28
25: ; preds = %2
%26 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%27 = call i32 @exit(i32 -1)
unreachable
28: ; preds = %2
%29 = call i64 @tcgetattr(i32 %23, %struct.termios* %4)
%30 = icmp eq i64 %29, 0
br i1 %30, label %35, label %31
31: ; preds = %28
%32 = load i32, i32* @stderr
%33 = load i32, i32* @errno
%34 = call i32 (i32, i8*, ...) @fprintf(i32 %32, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i32 %33)
br label %35
35: ; preds = %31, %28
%36 = load i64, i64* @B115200
%37 = trunc i64 %36 to i32
%38 = call i32 @cfsetospeed(%struct.termios* %4, i32 %37)
%39 = load i64, i64* @B115200
%40 = trunc i64 %39 to i32
%41 = call i32 @cfsetispeed(%struct.termios* %4, i32 %40)
%42 = load i32, i32* @PARENB
%43 = getelementptr inbounds %struct.termios, %struct.termios* %4, i64 0, i32 0
%44 = load i32, i32* %43
%45 = load i32, i32* @CSTOPB
%46 = or i32 %42, %45
%47 = load i32, i32* @CSIZE
%48 = or i32 %46, %47
%49 = xor i32 %48, -1
%50 = and i32 %44, %49
%51 = load i32, i32* @CS8
%52 = or i32 %51, %50
%53 = load i32, i32* @CRTSCTS
%54 = xor i32 %53, -1
%55 = and i32 %52, %54
store i32 %55, i32* %43
%56 = getelementptr inbounds %struct.termios, %struct.termios* %4, i64 0, i32 1
%57 = load i32*, i32** %56
%58 = load i64, i64* @VMIN
%59 = getelementptr inbounds i32, i32* %57, i64 %58
store i32 1, i32* %59
%60 = load i64, i64* @VTIME
%61 = getelementptr inbounds i32, i32* %57, i64 %60
store i32 5, i32* %61
%62 = load i32, i32* @CREAD
%63 = load i32, i32* @CLOCAL
%64 = or i32 %63, %62
%65 = load i32, i32* %43
%66 = or i32 %64, %65
store i32 %66, i32* %43
%67 = call i32 @cfmakeraw(%struct.termios* %4)
%68 = load i32, i32* @TCIFLUSH
%69 = call i32 @tcflush(i32 %23, i32 %68)
%70 = load i32, i32* @TCSANOW
%71 = call i64 @tcsetattr(i32 %23, i32 %70, %struct.termios* %4)
%72 = icmp eq i64 %71, 0
br i1 %72, label %77, label %73
73: ; preds = %35
%74 = load i32, i32* @stderr
%75 = load i32, i32* @errno
%76 = call i32 (i32, i8*, ...) @fprintf(i32 %74, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0), i32 %75)
br label %77
77: ; preds = %73, %35
%78 = getelementptr inbounds i8*, i8** %1, i64 2
%79 = load i8*, i8** %78
%80 = call i32 @strcmp(i8* dereferenceable(1) %79, i8* dereferenceable(5) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%81 = icmp eq i32 %80, 0
br i1 %81, label %82, label %146
82: ; preds = %77
%83 = bitcast i32* %6 to i8*
%84 = bitcast i32* %7 to i8*
%85 = getelementptr inbounds i8*, i8** %1, i64 4
%86 = load i8*, i8** %85
%87 = call i32 @sscanf(i8* %86, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32* %6)
%88 = getelementptr inbounds i8*, i8** %1, i64 5
%89 = load i8*, i8** %88
%90 = call i32 @sscanf(i8* %89, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32* %7)
%91 = load i32, i32* @stderr
%92 = load i32, i32* %6
%93 = load i32, i32* %7
%94 = call i32 (i32, i8*, ...) @fprintf(i32 %91, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0), i32 %92, i32 %93)
%95 = getelementptr inbounds i8*, i8** %1, i64 3
%96 = load i8*, i8** %95
%97 = call i32* @fopen(i8* %96, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0))
%98 = icmp eq i32* %97, null
br i1 %98, label %141, label %99
99: ; preds = %82
%100 = getelementptr inbounds [5 x i8], [5 x i8]* %8, i64 0, i64 0
store i8 83, i8* %100
%101 = getelementptr inbounds [5 x i8], [5 x i8]* %8, i64 0, i64 1
%102 = load i32, i32* %6
%103 = lshr i32 %102, 8
%104 = trunc i32 %103 to i8
store i8 %104, i8* %101
%105 = getelementptr inbounds [5 x i8], [5 x i8]* %8, i64 0, i64 2
%106 = trunc i32 %102 to i8
store i8 %106, i8* %105
%107 = getelementptr inbounds [5 x i8], [5 x i8]* %8, i64 0, i64 3
%108 = load i32, i32* %7
%109 = lshr i32 %108, 8
%110 = trunc i32 %109 to i8
store i8 %110, i8* %107
%111 = getelementptr inbounds [5 x i8], [5 x i8]* %8, i64 0, i64 4
%112 = trunc i32 %108 to i8
store i8 %112, i8* %111
%113 = call i32 (i32, ...) @write(i32 %23, i8* %100, i32 5)
%114 = load i32, i32* %6
%115 = load i32, i32* %7
%116 = icmp ult i32 %114, %115
br i1 %116, label %117, label %132
117: ; preds = %99, %124
%118 = call i32 @read(i32 %23, i8* %14, i32 1)
%119 = icmp slt i32 %118, 0
br i1 %119, label %120, label %124
120: ; preds = %117
%121 = load i32, i32* @stderr
%122 = load i32, i32* @errno
%123 = call i32 (i32, i8*, ...) @fprintf(i32 %121, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.7, i64 0, i64 0), i32 %122)
br label %132
124: ; preds = %117
%125 = load i8, i8* %14
%126 = sext i8 %125 to i32
%127 = call i32 @fputc(i32 %126, i32* %97)
%128 = load i32, i32* %6
%129 = add i32 %128, 1
store i32 %129, i32* %6
%130 = load i32, i32* %7
%131 = icmp ult i32 %129, %130
br i1 %131, label %117, label %132
132: ; preds = %124, %99, %120
%133 = call i32 @read(i32 %23, i8* %14, i32 1)
%134 = load i8, i8* %14
%135 = icmp eq i8 %134, 79
br i1 %135, label %136, label %139
136: ; preds = %132
%137 = load i32, i32* @stderr
%138 = call i32 (i32, i8*, ...) @fprintf(i32 %137, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.8, i64 0, i64 0))
br label %139
139: ; preds = %136, %132
%140 = call i32 @fclose(i32* %97)
br label %144
141: ; preds = %82
%142 = load i32, i32* @stderr
%143 = call i32 (i32, i8*, ...) @fprintf(i32 %142, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.9, i64 0, i64 0))
br label %144
144: ; preds = %141, %139
%145 = load i8*, i8** %78
br label %146
146: ; preds = %144, %77
%147 = phi i8* [ %145, %144 ], [ %79, %77 ]
%148 = call i32 @strcmp(i8* dereferenceable(1) %147, i8* dereferenceable(5) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.10, i64 0, i64 0))
%149 = icmp eq i32 %148, 0
br i1 %149, label %150, label %227
150: ; preds = %146
%151 = bitcast i32* %9 to i8*
%152 = bitcast i32* %10 to i8*
%153 = getelementptr inbounds i8*, i8** %1, i64 3
%154 = load i8*, i8** %153
%155 = call i32* @fopen(i8* %154, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.11, i64 0, i64 0))
%156 = icmp eq i32* %155, null
br i1 %156, label %222, label %157
157: ; preds = %150
%158 = icmp slt i32 %0, 5
br i1 %158, label %159, label %160
159: ; preds = %157
store i32 256, i32* %9
br label %165
160: ; preds = %157
%161 = getelementptr inbounds i8*, i8** %1, i64 4
%162 = load i8*, i8** %161
%163 = call i32 @sscanf(i8* %162, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32* %9)
%164 = icmp eq i32 %0, 5
br i1 %164, label %165, label %173
165: ; preds = %159, %160
%166 = load i32, i32* @SEEK_END
%167 = call i32 @fseek(i32* %155, i32 0, i32 %166)
%168 = load i32, i32* %9
%169 = call i32 @ftell(i32* %155)
%170 = add i32 %169, %168
store i32 %170, i32* %10
%171 = load i32, i32* @SEEK_SET
%172 = call i32 @fseek(i32* %155, i32 0, i32 %171)
br label %178
173: ; preds = %160
%174 = getelementptr inbounds i8*, i8** %1, i64 5
%175 = load i8*, i8** %174
%176 = call i32 @sscanf(i8* %175, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32* %10)
%177 = load i32, i32* %10
br label %178
178: ; preds = %173, %165
%179 = phi i32 [ %177, %173 ], [ %170, %165 ]
%180 = load i32, i32* @stderr
%181 = load i32, i32* %9
%182 = call i32 (i32, i8*, ...) @fprintf(i32 %180, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.12, i64 0, i64 0), i32 %181, i32 %179)
%183 = getelementptr inbounds [5 x i8], [5 x i8]* %11, i64 0, i64 0
store i8 76, i8* %183
%184 = getelementptr inbounds [5 x i8], [5 x i8]* %11, i64 0, i64 1
%185 = load i32, i32* %9
%186 = lshr i32 %185, 8
%187 = trunc i32 %186 to i8
store i8 %187, i8* %184
%188 = getelementptr inbounds [5 x i8], [5 x i8]* %11, i64 0, i64 2
%189 = trunc i32 %185 to i8
store i8 %189, i8* %188
%190 = getelementptr inbounds [5 x i8], [5 x i8]* %11, i64 0, i64 3
%191 = load i32, i32* %10
%192 = lshr i32 %191, 8
%193 = trunc i32 %192 to i8
store i8 %193, i8* %190
%194 = getelementptr inbounds [5 x i8], [5 x i8]* %11, i64 0, i64 4
%195 = trunc i32 %191 to i8
store i8 %195, i8* %194
%196 = call i32 (i32, ...) @write(i32 %23, i8* %183, i32 5)
%197 = load i32, i32* %9
%198 = load i32, i32* %10
%199 = icmp ult i32 %197, %198
br i1 %199, label %200, label %213
200: ; preds = %178, %208
%201 = call i32 @fread(i8* %14, i32 1, i32 1, i32* %155)
%202 = call i32 (i32, ...) @write(i32 %23, i8* %14, i32 1)
%203 = icmp slt i32 %202, 1
br i1 %203, label %204, label %208
204: ; preds = %200
%205 = load i32, i32* @stderr
%206 = load i32, i32* @errno
%207 = call i32 (i32, i8*, ...) @fprintf(i32 %205, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.7, i64 0, i64 0), i32 %206)
br label %213
208: ; preds = %200
%209 = load i32, i32* %9
%210 = add i32 %209, 1
store i32 %210, i32* %9
%211 = load i32, i32* %10
%212 = icmp ult i32 %210, %211
br i1 %212, label %200, label %213
213: ; preds = %208, %178, %204
%214 = call i32 @read(i32 %23, i8* %14, i32 1)
%215 = load i8, i8* %14
%216 = icmp eq i8 %215, 79
br i1 %216, label %217, label %220
217: ; preds = %213
%218 = load i32, i32* @stderr
%219 = call i32 (i32, i8*, ...) @fprintf(i32 %218, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.8, i64 0, i64 0))
br label %220
220: ; preds = %217, %213
%221 = call i32 @fclose(i32* %155)
br label %225
222: ; preds = %150
%223 = load i32, i32* @stderr
%224 = call i32 (i32, i8*, ...) @fprintf(i32 %223, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.13, i64 0, i64 0))
br label %225
225: ; preds = %222, %220
%226 = load i8*, i8** %78
br label %227
227: ; preds = %225, %146
%228 = phi i8* [ %226, %225 ], [ %147, %146 ]
%229 = call i32 @strcmp(i8* dereferenceable(1) %228, i8* dereferenceable(3) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.14, i64 0, i64 0))
%230 = icmp eq i32 %229, 0
br i1 %230, label %231, label %249
231: ; preds = %227
%232 = bitcast i32* %12 to i8*
%233 = getelementptr inbounds i8*, i8** %1, i64 3
%234 = load i8*, i8** %233
%235 = call i32 @sscanf(i8* %234, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32* %12)
%236 = load i32, i32* @stderr
%237 = load i32, i32* %12
%238 = call i32 (i32, i8*, ...) @fprintf(i32 %236, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.15, i64 0, i64 0), i32 %237)
%239 = getelementptr inbounds [5 x i8], [5 x i8]* %13, i64 0, i64 0
store i8 71, i8* %239
%240 = getelementptr inbounds [5 x i8], [5 x i8]* %13, i64 0, i64 1
%241 = load i32, i32* %12
%242 = lshr i32 %241, 8
%243 = trunc i32 %242 to i8
store i8 %243, i8* %240
%244 = getelementptr inbounds [5 x i8], [5 x i8]* %13, i64 0, i64 2
%245 = trunc i32 %241 to i8
store i8 %245, i8* %244
%246 = getelementptr inbounds [5 x i8], [5 x i8]* %13, i64 0, i64 3
%247 = bitcast i8* %246 to i16*
store i16 0, i16* %247
%248 = call i32 (i32, ...) @write(i32 %23, i8* %239, i32 3)
br label %249
249: ; preds = %231, %227
%250 = load i32, i32* @TCSANOW
%251 = call i64 @tcsetattr(i32 %23, i32 %250, %struct.termios* %5)
ret i32 0
}