#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 timeval {
  int tv_usec;
  scalar_t__ tv_sec;
};
struct termios {
  int /*<<< orphan*/ c_lflag;
};
typedef int /*<<< orphan*/ fd_set;

/* Variables and functions */
int B115200;
int B19200;
int B38400;
int B4800;
int B57600;
int B9600;
scalar_t__ ENOENT;
scalar_t__ FD_ISSET(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ FD_SET(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ FD_ZERO(int /*<<< orphan*/ *);
int /*<<< orphan*/ ICANON;
int /*<<< orphan*/ O_RDWR;
int /*<<< orphan*/ TCIOFLUSH;
int /*<<< orphan*/ TCSAFLUSH;
int atoi(char *);
int cfsetispeed(struct termios *, int);
int cfsetspeed(struct termios *, int);
int /*<<< orphan*/ close(int);
scalar_t__ errno;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int open(char *, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int read(int, unsigned char *, int);
int select(int, int /*<<< orphan*/ *, int /*<<< orphan*/ *,
           int /*<<< orphan*/ *, struct timeval *);
int /*<<< orphan*/ stderr;
scalar_t__ strcmp(char *, char *);
char *strerror(scalar_t__);
int /*<<< orphan*/ tcflush(int, int /*<<< orphan*/);
int tcgetattr(int, struct termios *);
int tcsetattr(int, int /*<<< orphan*/, struct termios *);
int /*<<< orphan*/ usleep(int);
int write(int, unsigned char *, int);
int main(int argc, char *argv[]) {
  int fd, err, rc, bitrate;
  struct termios t;
  struct timeval tv;
  unsigned char w[1], r[1];
  fd_set fds;
  if ((argc != 3) || (strcmp(argv[1], "-h") == 0) ||
      (strcmp(argv[1], "--help") == 0)) {
    printf("Usage: %s <serial device> <baudrate>\n", argv[0]);
  } else {
    printf("Opening serial device %s.\n", argv[1]);
    switch (atoi(argv[2])) {
    case 4800:
      bitrate = B4800;
      break;
    case 9600:
      bitrate = B9600;
      break;
    case 19200:
      bitrate = B19200;
      break;
    case 38400:
      bitrate = B38400;
      break;
    case 57600:
      bitrate = B57600;
      break;
    case 115200:
      bitrate = B115200;
      break;
    default:
      fprintf(stderr, "Unknown bitrate \"%s\n\"", argv[2]);
      exit(1);
    }
    fd = open(argv[1], O_RDWR, 0);
    if (fd < 0) {
      if (errno == ENOENT) {
        printf(
            "Serial device does not exist, waiting for it to be plugged in.\n");
        while ((fd = open(argv[1], O_RDWR, 0)) < 0) {
          usleep(10000);
        }
      } else {
        fprintf(stderr, "%s: %s\n", argv[1], strerror(errno));
        close(fd);
        exit(1);
      }
    }
    err = tcgetattr(fd, &t);
    if (err < 0) {
      fprintf(stderr, "tcgetattr: %s\n", strerror(errno));
      close(fd);
      exit(2);
    }
    err = cfsetispeed(&t, bitrate);
    if (err < 0) {
      fprintf(stderr, "cfsetispeed: %s\n", strerror(errno));
      close(fd);
      exit(3);
    }
    err = cfsetspeed(&t, bitrate);
    if (err < 0) {
      fprintf(stderr, "cfsetspeed: %s\n", strerror(errno));
      close(fd);
      exit(4);
    }
    t.c_lflag &= ~ICANON;
    err = tcsetattr(fd, TCSAFLUSH, &t);
    if (err < 0) {
      fprintf(stderr, "tcsetattr: %s\n", strerror(errno));
      close(fd);
      exit(5);
    }
    tcflush(fd, TCIOFLUSH);
    w[0] = 'p';
    tv.tv_sec = 0;
    tv.tv_usec = 200;
    printf("Sending bootloader entry command (%c).\n", 'p');
    printf("You may now plug in the target device.\n");
    for (;;) {
      if (write(fd, w, 1) < 1) {
        fprintf(stderr, "error during write: %s\n", strerror(errno));
        exit(6);
      }
      FD_ZERO(&fds);
      FD_SET(fd, &fds);
      rc = select(fd + 1, &fds, NULL, NULL, &tv);
      if (rc < 0) {
        fprintf(stderr, "error in select\n");
        exit(7);
      } else {
        if (FD_ISSET(fd, &fds)) {
          if (read(fd, r, 1) < 1) {
            fprintf(stderr, "error during read: %s\n", strerror(errno));
            exit(8);
          }
          if (r[0] == 'S') {
            printf("Bootloader running.\n");
            exit(0);
          }
        }
      }
    }
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
jne    129c <main+0x5c>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xd91(%rip),%rsi
call   10a0 <strcmp@plt>
cmp    $0x0,%rax
je     129c <main+0x5c>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xd76(%rip),%rsi
call   10a0 <strcmp@plt>
cmp    $0x0,%rax
jne    12b6 <main+0x76>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xd60(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    17c9 <main+0x589>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xd6b(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1120 <atoi@plt>
mov    %eax,%ecx
mov    %ecx,-0x44(%rbp)
sub    $0x12c0,%eax
je     134d <main+0x10d>
jmp    12ee <main+0xae>
mov    -0x44(%rbp),%eax
sub    $0x2580,%eax
je     135e <main+0x11e>
jmp    1301 <main+0xc1>
mov    -0x44(%rbp),%eax
sub    $0x4b00,%eax
je     136f <main+0x12f>
jmp    1314 <main+0xd4>
mov    -0x44(%rbp),%eax
sub    $0x9600,%eax
je     1380 <main+0x140>
jmp    1327 <main+0xe7>
mov    -0x44(%rbp),%eax
sub    $0xe100,%eax
je     1391 <main+0x151>
jmp    133a <main+0xfa>
mov    -0x44(%rbp),%eax
sub    $0x1c200,%eax
je     13a2 <main+0x162>
jmp    13b3 <main+0x173>
mov    0x2c7c(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
jmp    13dc <main+0x19c>
mov    0x2c63(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
jmp    13dc <main+0x19c>
mov    0x2c7a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
jmp    13dc <main+0x19c>
mov    0x2bf1(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
jmp    13dc <main+0x19c>
mov    0x2c28(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
jmp    13dc <main+0x19c>
mov    0x2bef(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
jmp    13dc <main+0x19c>
mov    0x2bf6(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdx
lea    0xc80(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
mov    $0x1,%edi
call   1130 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2bf5(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1100 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    14b7 <main+0x277>
mov    0x2ba0(%rip),%rax
mov    (%rax),%rax
mov    0x2b6e(%rip),%rcx
cmp    (%rcx),%rax
jne    1461 <main+0x221>
lea    0xc3f(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2ba8(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1100 <open@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jge    145c <main+0x21c>
mov    $0x2710,%edi
call   1160 <usleep@plt>
jmp    1429 <main+0x1e9>
jmp    14b2 <main+0x272>
mov    0x2b48(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x54(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x50(%rbp)
mov    0x2b28(%rip),%rax
mov    (%rax),%rdi
call   1140 <strerror@plt>
mov    -0x54(%rbp),%edi
mov    -0x50(%rbp),%rdx
mov    %rax,%rcx
lea    0xc08(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
mov    -0x14(%rbp),%edi
call   1080 <close@plt>
mov    $0x1,%edi
call   1130 <exit@plt>
jmp    14b7 <main+0x277>
mov    -0x14(%rbp),%edi
lea    -0x28(%rbp),%rsi
call   10e0 <tcgetattr@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    1511 <main+0x2d1>
mov    0x2ad9(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x58(%rbp)
mov    0x2ac5(%rip),%rax
mov    (%rax),%rdi
call   1140 <strerror@plt>
mov    -0x58(%rbp),%edi
mov    %rax,%rdx
lea    0xbb1(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
mov    -0x14(%rbp),%edi
call   1080 <close@plt>
mov    $0x2,%edi
call   1130 <exit@plt>
mov    -0x20(%rbp),%esi
lea    -0x28(%rbp),%rdi
call   1110 <cfsetispeed@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    156b <main+0x32b>
mov    0x2a7f(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x5c(%rbp)
mov    0x2a6b(%rip),%rax
mov    (%rax),%rdi
call   1140 <strerror@plt>
mov    -0x5c(%rbp),%edi
mov    %rax,%rdx
lea    0xb66(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
mov    -0x14(%rbp),%edi
call   1080 <close@plt>
mov    $0x3,%edi
call   1130 <exit@plt>
mov    -0x20(%rbp),%esi
lea    -0x28(%rbp),%rdi
call   1070 <cfsetspeed@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    15c5 <main+0x385>
mov    0x2a25(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x60(%rbp)
mov    0x2a11(%rip),%rax
mov    (%rax),%rdi
call   1140 <strerror@plt>
mov    -0x60(%rbp),%edi
mov    %rax,%rdx
lea    0xb1d(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
mov    -0x14(%rbp),%edi
call   1080 <close@plt>
mov    $0x4,%edi
call   1130 <exit@plt>
mov    0x29c4(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x28(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    -0x14(%rbp),%edi
mov    0x29f7(%rip),%rax
mov    (%rax),%esi
lea    -0x28(%rbp),%rdx
call   10f0 <tcsetattr@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    163a <main+0x3fa>
mov    0x29b0(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x64(%rbp)
mov    0x299c(%rip),%rax
mov    (%rax),%rdi
call   1140 <strerror@plt>
mov    -0x64(%rbp),%edi
mov    %rax,%rdx
lea    0xab8(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
mov    -0x14(%rbp),%edi
call   1080 <close@plt>
mov    $0x5,%edi
call   1130 <exit@plt>
mov    -0x14(%rbp),%edi
mov    0x295c(%rip),%rax
mov    (%rax),%esi
call   1050 <tcflush@plt>
movb   $0x70,-0x39(%rbp)
movq   $0x0,-0x30(%rbp)
movl   $0xc8,-0x38(%rbp)
lea    0xa83(%rip),%rdi
mov    $0x70,%esi
mov    $0x0,%al
call   1060 <printf@plt>
lea    0xa98(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x14(%rbp),%edi
lea    -0x39(%rbp),%rsi
mov    $0x1,%edx
call   1030 <write@plt>
cmp    $0x1,%eax
jge    16d2 <main+0x492>
mov    0x2910(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x68(%rbp)
mov    0x28fc(%rip),%rax
mov    (%rax),%rdi
call   1140 <strerror@plt>
mov    -0x68(%rbp),%edi
mov    %rax,%rdx
lea    0xa77(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
mov    $0x6,%edi
call   1130 <exit@plt>
lea    -0x40(%rbp),%rdi
call   10c0 <FD_ZERO@plt>
mov    -0x14(%rbp),%edi
lea    -0x40(%rbp),%rsi
call   1150 <FD_SET@plt>
mov    -0x14(%rbp),%edi
add    $0x1,%edi
lea    -0x40(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%ecx
lea    -0x38(%rbp),%r8
mov    %rcx,%rdx
call   10d0 <select@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    172f <main+0x4ef>
mov    0x289b(%rip),%rax
mov    (%rax),%edi
lea    0xa32(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
mov    $0x7,%edi
call   1130 <exit@plt>
mov    -0x14(%rbp),%edi
lea    -0x40(%rbp),%rsi
call   1040 <FD_ISSET@plt>
cmp    $0x0,%rax
je     17bf <main+0x57f>
mov    -0x14(%rbp),%edi
lea    -0x3a(%rbp),%rsi
mov    $0x1,%edx
call   1090 <read@plt>
cmp    $0x1,%eax
jge    1798 <main+0x558>
mov    0x284a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x6c(%rbp)
mov    0x2836(%rip),%rax
mov    (%rax),%rdi
call   1140 <strerror@plt>
mov    -0x6c(%rbp),%edi
mov    %rax,%rdx
lea    0x9da(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
mov    $0x8,%edi
call   1130 <exit@plt>
movzbl -0x3a(%rbp),%eax
cmp    $0x53,%eax
jne    17ba <main+0x57a>
lea    0x9cc(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
xor    %edi,%edi
call   1130 <exit@plt>
jmp    17bf <main+0x57f>
jmp    17c4 <main+0x584>
jmp    167f <main+0x43f>
mov    -0x4(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rsi,%rbx
cmp    $0x3,%edi
jne    1290 <main+0x40>
mov    0x8(%rbx),%rdi
lea    0xd8f(%rip),%rsi
call   10b0 <strcmp@plt>
test   %rax,%rax
je     1290 <main+0x40>
mov    0x8(%rbx),%rdi
lea    0xd7d(%rip),%rsi
call   10b0 <strcmp@plt>
test   %rax,%rax
jne    12b2 <main+0x62>
mov    (%rbx),%rsi
lea    0xd70(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
xor    %eax,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x8(%rbx),%rsi
lea    0xd73(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
mov    0x10(%rbx),%rbp
mov    %rbp,%rdi
call   1130 <atoi@plt>
cmp    $0x95ff,%eax
jg     12f9 <main+0xa9>
cmp    $0x12c0,%eax
je     131b <main+0xcb>
cmp    $0x2580,%eax
je     1324 <main+0xd4>
cmp    $0x4b00,%eax
jne    14da <main+0x28a>
mov    0x2cf9(%rip),%rax
jmp    133d <main+0xed>
cmp    $0x9600,%eax
je     132d <main+0xdd>
cmp    $0xe100,%eax
je     1336 <main+0xe6>
cmp    $0x1c200,%eax
jne    14da <main+0x28a>
mov    0x2c7f(%rip),%rax
jmp    133d <main+0xed>
mov    0x2cae(%rip),%rax
jmp    133d <main+0xed>
mov    0x2c9d(%rip),%rax
jmp    133d <main+0xed>
mov    0x2c44(%rip),%rax
jmp    133d <main+0xed>
mov    0x2c83(%rip),%rax
mov    (%rax),%r15d
mov    0x8(%rbx),%rdi
mov    0x2c95(%rip),%rbp
mov    0x0(%rbp),%esi
xor    %edx,%edx
call   1110 <open@plt>
mov    %eax,%r14d
test   %eax,%eax
jns    13b6 <main+0x166>
mov    0x2c45(%rip),%rax
mov    (%rax),%rdi
mov    0x2c13(%rip),%rax
cmp    (%rax),%rdi
jne    1452 <main+0x202>
lea    0xdce(%rip),%rdi
call   1030 <puts@plt>
mov    0x8(%rbx),%rdi
mov    0x0(%rbp),%esi
xor    %edx,%edx
call   1110 <open@plt>
mov    %eax,%r14d
test   %eax,%eax
jns    13b6 <main+0x166>
mov    $0x2710,%edi
call   1170 <usleep@plt>
mov    0x8(%rbx),%rdi
mov    0x0(%rbp),%esi
xor    %edx,%edx
call   1110 <open@plt>
test   %eax,%eax
js     1397 <main+0x147>
mov    %eax,%r14d
lea    0x10(%rsp),%rsi
mov    %r14d,%edi
call   10f0 <tcgetattr@plt>
test   %eax,%eax
jns    1404 <main+0x1b4>
mov    0x2be2(%rip),%rax
mov    (%rax),%ebx
mov    0x2bd1(%rip),%rax
mov    (%rax),%rdi
call   1150 <strerror@plt>
lea    0xc83(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
xor    %eax,%eax
call   10c0 <fprintf@plt>
mov    %r14d,%edi
call   1090 <close@plt>
mov    $0x2,%edi
call   1140 <exit@plt>
lea    0x10(%rsp),%rdi
mov    %r15d,%esi
call   1120 <cfsetispeed@plt>
test   %eax,%eax
jns    148c <main+0x23c>
mov    0x2b94(%rip),%rax
mov    (%rax),%ebx
mov    0x2b83(%rip),%rax
mov    (%rax),%rdi
call   1150 <strerror@plt>
lea    0xc44(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
xor    %eax,%eax
call   10c0 <fprintf@plt>
mov    %r14d,%edi
call   1090 <close@plt>
mov    $0x3,%edi
call   1140 <exit@plt>
mov    0x2b57(%rip),%rax
mov    (%rax),%ebp
mov    0x8(%rbx),%rbx
call   1150 <strerror@plt>
lea    0xbf6(%rip),%rsi
mov    %ebp,%edi
mov    %rbx,%rdx
mov    %rax,%rcx
xor    %eax,%eax
call   10c0 <fprintf@plt>
mov    %r14d,%edi
call   1090 <close@plt>
mov    $0x1,%edi
call   1140 <exit@plt>
lea    0x10(%rsp),%rdi
mov    %r15d,%esi
call   1080 <cfsetspeed@plt>
test   %eax,%eax
jns    14fe <main+0x2ae>
mov    0x2b0c(%rip),%rax
mov    (%rax),%ebx
mov    0x2afb(%rip),%rax
mov    (%rax),%rdi
call   1150 <strerror@plt>
lea    0xbcd(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
xor    %eax,%eax
call   10c0 <fprintf@plt>
mov    %r14d,%edi
call   1090 <close@plt>
mov    $0x4,%edi
call   1140 <exit@plt>
mov    0x2acf(%rip),%rax
mov    (%rax),%edi
lea    0xb61(%rip),%rsi
mov    %rbp,%rdx
xor    %eax,%eax
call   10c0 <fprintf@plt>
mov    $0x1,%edi
call   1140 <exit@plt>
mov    0x2a8b(%rip),%rax
mov    (%rax),%eax
not    %eax
and    %eax,0x10(%rsp)
mov    0x2ac4(%rip),%rax
mov    (%rax),%esi
lea    0x10(%rsp),%rdx
mov    %r14d,%edi
call   1100 <tcsetattr@plt>
test   %eax,%eax
jns    1564 <main+0x314>
mov    0x2a82(%rip),%rax
mov    (%rax),%ebx
mov    0x2a71(%rip),%rax
mov    (%rax),%rdi
call   1150 <strerror@plt>
lea    0xb53(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
xor    %eax,%eax
call   10c0 <fprintf@plt>
mov    %r14d,%edi
call   1090 <close@plt>
mov    $0x5,%edi
call   1140 <exit@plt>
mov    0x2a35(%rip),%rax
mov    (%rax),%esi
mov    %r14d,%edi
call   1060 <tcflush@plt>
movb   $0x70,0xe(%rsp)
movq   $0x0,0x20(%rsp)
movl   $0xc8,0x18(%rsp)
lea    0xb16(%rip),%rdi
mov    $0x70,%esi
xor    %eax,%eax
call   1070 <printf@plt>
lea    0xb6b(%rip),%rdi
call   1030 <puts@plt>
lea    0xe(%rsp),%rsi
mov    %r14d,%edi
mov    $0x1,%edx
call   1040 <write@plt>
test   %eax,%eax
jg     15f5 <main+0x3a5>
mov    0x29e9(%rip),%rax
mov    (%rax),%ebx
mov    0x29d8(%rip),%rax
mov    (%rax),%rdi
call   1150 <strerror@plt>
lea    0xaf1(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
xor    %eax,%eax
call   10c0 <fprintf@plt>
mov    $0x6,%edi
call   1140 <exit@plt>
lea    0x1(%r14),%ebx
lea    0x14(%rsp),%rbp
lea    0x18(%rsp),%r15
lea    0xe(%rsp),%r12
lea    0xf(%rsp),%r13
jmp    1623 <main+0x3d3>
mov    %r14d,%edi
mov    %r12,%rsi
mov    $0x1,%edx
call   1040 <write@plt>
test   %eax,%eax
jle    15c0 <main+0x370>
mov    %rbp,%rdi
call   10d0 <FD_ZERO@plt>
mov    %r14d,%edi
mov    %rbp,%rsi
call   1160 <FD_SET@plt>
mov    %ebx,%edi
mov    %rbp,%rsi
xor    %edx,%edx
xor    %ecx,%ecx
mov    %r15,%r8
call   10e0 <select@plt>
test   %eax,%eax
js     1689 <main+0x439>
mov    %r14d,%edi
mov    %rbp,%rsi
call   1050 <FD_ISSET@plt>
test   %rax,%rax
je     160f <main+0x3bf>
mov    %r14d,%edi
mov    %r13,%rsi
mov    $0x1,%edx
call   10a0 <read@plt>
test   %eax,%eax
jle    16aa <main+0x45a>
cmpb   $0x53,0xf(%rsp)
jne    160f <main+0x3bf>
lea    0xaba(%rip),%rdi
call   1030 <puts@plt>
xor    %edi,%edi
call   1140 <exit@plt>
mov    0x2920(%rip),%rax
mov    (%rax),%edi
lea    0xa4f(%rip),%rsi
xor    %eax,%eax
call   10c0 <fprintf@plt>
mov    $0x7,%edi
call   1140 <exit@plt>
mov    0x28ff(%rip),%rax
mov    (%rax),%ebx
mov    0x28ee(%rip),%rax
mov    (%rax),%rdi
call   1150 <strerror@plt>
lea    0xa30(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
xor    %eax,%eax
call   10c0 <fprintf@plt>
mov    $0x8,%edi
call   1140 <exit@plt>

LLVM IR (-O0):
%struct.termios = type { i32 }
%struct.timeval = type { i32, i64 }
@.str = [3 x i8] c"-h\00"
@.str.1 = [7 x i8] c"--help\00"
@.str.2 = [38 x i8] c"Usage: %s <serial device> <baudrate>\0A\00"
@.str.3 = [27 x i8] c"Opening serial device %s.\0A\00"
@B4800 = global i32 0
@B9600 = global i32 0
@B19200 = global i32 0
@B38400 = global i32 0
@B57600 = global i32 0
@B115200 = global i32 0
@stderr = global i32 0
@.str.4 = [22 x i8] c"Unknown bitrate \22%s\0A\22\00"
@O_RDWR = global i32 0
@errno = global i64 0
@ENOENT = global i64 0
@.str.5 = [64 x i8] c"Serial device does not exist, waiting for it to be plugged in.\0A\00"
@.str.6 = [8 x i8] c"%s: %s\0A\00"
@.str.7 = [15 x i8] c"tcgetattr: %s\0A\00"
@.str.8 = [17 x i8] c"cfsetispeed: %s\0A\00"
@.str.9 = [16 x i8] c"cfsetspeed: %s\0A\00"
@ICANON = global i32 0
@TCSAFLUSH = global i32 0
@.str.10 = [15 x i8] c"tcsetattr: %s\0A\00"
@TCIOFLUSH = global i32 0
@.str.11 = [40 x i8] c"Sending bootloader entry command (%c).\0A\00"
@.str.12 = [40 x i8] c"You may now plug in the target device.\0A\00"
@.str.13 = [24 x i8] c"error during write: %s\0A\00"
@.str.14 = [17 x i8] c"error in select\0A\00"
@.str.15 = [23 x i8] c"error during read: %s\0A\00"
@.str.16 = [21 x i8] c"Bootloader running.\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 %struct.termios
%11 = alloca %struct.timeval
%12 = alloca [1 x i8]
%13 = alloca [1 x i8]
%14 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%15 = load i32, i32* %4
%16 = icmp ne i32 %15, 3
br i1 %16, label %29, label %17
17: ; preds = %2
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 1
%20 = load i8*, i8** %19
%21 = call i64 @strcmp(i8* %20, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%22 = icmp eq i64 %21, 0
br i1 %22, label %29, label %23
23: ; preds = %17
%24 = load i8**, i8*** %5
%25 = getelementptr inbounds i8*, i8** %24, i64 1
%26 = load i8*, i8** %25
%27 = call i64 @strcmp(i8* %26, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%28 = icmp eq i64 %27, 0
br i1 %28, label %29, label %34
29: ; preds = %23, %17, %2
%30 = load i8**, i8*** %5
%31 = getelementptr inbounds i8*, i8** %30, i64 0
%32 = load i8*, i8** %31
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.2, i64 0, i64 0), i8* %32)
br label %215
34: ; preds = %23
%35 = load i8**, i8*** %5
%36 = getelementptr inbounds i8*, i8** %35, i64 1
%37 = load i8*, i8** %36
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0), i8* %37)
%39 = load i8**, i8*** %5
%40 = getelementptr inbounds i8*, i8** %39, i64 2
%41 = load i8*, i8** %40
%42 = call i32 @atoi(i8* %41)
switch i32 %42, label %55 [
i32 4800, label %43
i32 9600, label %45
i32 19200, label %47
i32 38400, label %49
i32 57600, label %51
i32 115200, label %53
]
43: ; preds = %34
%44 = load i32, i32* @B4800
store i32 %44, i32* %9
br label %62
45: ; preds = %34
%46 = load i32, i32* @B9600
store i32 %46, i32* %9
br label %62
47: ; preds = %34
%48 = load i32, i32* @B19200
store i32 %48, i32* %9
br label %62
49: ; preds = %34
%50 = load i32, i32* @B38400
store i32 %50, i32* %9
br label %62
51: ; preds = %34
%52 = load i32, i32* @B57600
store i32 %52, i32* %9
br label %62
53: ; preds = %34
%54 = load i32, i32* @B115200
store i32 %54, i32* %9
br label %62
55: ; preds = %34
%56 = load i32, i32* @stderr
%57 = load i8**, i8*** %5
%58 = getelementptr inbounds i8*, i8** %57, i64 2
%59 = load i8*, i8** %58
%60 = call i32 (i32, i8*, ...) @fprintf(i32 %56, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.4, i64 0, i64 0), i8* %59)
%61 = call i32 @exit(i32 1)
unreachable
62: ; preds = %53, %51, %49, %47, %45, %43
%63 = load i8**, i8*** %5
%64 = getelementptr inbounds i8*, i8** %63, i64 1
%65 = load i8*, i8** %64
%66 = load i32, i32* @O_RDWR
%67 = call i32 @open(i8* %65, i32 %66, i32 0)
store i32 %67, i32* %6
%68 = load i32, i32* %6
%69 = icmp slt i32 %68, 0
br i1 %69, label %70, label %98
70: ; preds = %62
%71 = load i64, i64* @errno
%72 = load i64, i64* @ENOENT
%73 = icmp eq i64 %71, %72
br i1 %73, label %74, label %86
74: ; preds = %70
%75 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([64 x i8], [64 x i8]* @.str.5, i64 0, i64 0))
br label %76
76: ; preds = %83, %74
%77 = load i8**, i8*** %5
%78 = getelementptr inbounds i8*, i8** %77, i64 1
%79 = load i8*, i8** %78
%80 = load i32, i32* @O_RDWR
%81 = call i32 @open(i8* %79, i32 %80, i32 0)
store i32 %81, i32* %6
%82 = icmp slt i32 %81, 0
br i1 %82, label %83, label %85
83: ; preds = %76
%84 = call i32 @usleep(i32 10000)
br label %76
85: ; preds = %76
br label %97
86: ; preds = %70
%87 = load i32, i32* @stderr
%88 = load i8**, i8*** %5
%89 = getelementptr inbounds i8*, i8** %88, i64 1
%90 = load i8*, i8** %89
%91 = load i64, i64* @errno
%92 = call i8* @strerror(i64 %91)
%93 = call i32 (i32, i8*, ...) @fprintf(i32 %87, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.6, i64 0, i64 0), i8* %90, i8* %92)
%94 = load i32, i32* %6
%95 = call i32 @close(i32 %94)
%96 = call i32 @exit(i32 1)
unreachable
97: ; preds = %85
br label %98
98: ; preds = %97, %62
%99 = load i32, i32* %6
%100 = call i32 @tcgetattr(i32 %99, %struct.termios* %10)
store i32 %100, i32* %7
%101 = load i32, i32* %7
%102 = icmp slt i32 %101, 0
br i1 %102, label %103, label %111
103: ; preds = %98
%104 = load i32, i32* @stderr
%105 = load i64, i64* @errno
%106 = call i8* @strerror(i64 %105)
%107 = call i32 (i32, i8*, ...) @fprintf(i32 %104, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.7, i64 0, i64 0), i8* %106)
%108 = load i32, i32* %6
%109 = call i32 @close(i32 %108)
%110 = call i32 @exit(i32 2)
unreachable
111: ; preds = %98
%112 = load i32, i32* %9
%113 = call i32 @cfsetispeed(%struct.termios* %10, i32 %112)
store i32 %113, i32* %7
%114 = load i32, i32* %7
%115 = icmp slt i32 %114, 0
br i1 %115, label %116, label %124
116: ; preds = %111
%117 = load i32, i32* @stderr
%118 = load i64, i64* @errno
%119 = call i8* @strerror(i64 %118)
%120 = call i32 (i32, i8*, ...) @fprintf(i32 %117, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.8, i64 0, i64 0), i8* %119)
%121 = load i32, i32* %6
%122 = call i32 @close(i32 %121)
%123 = call i32 @exit(i32 3)
unreachable
124: ; preds = %111
%125 = load i32, i32* %9
%126 = call i32 @cfsetspeed(%struct.termios* %10, i32 %125)
store i32 %126, i32* %7
%127 = load i32, i32* %7
%128 = icmp slt i32 %127, 0
br i1 %128, label %129, label %137
129: ; preds = %124
%130 = load i32, i32* @stderr
%131 = load i64, i64* @errno
%132 = call i8* @strerror(i64 %131)
%133 = call i32 (i32, i8*, ...) @fprintf(i32 %130, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.9, i64 0, i64 0), i8* %132)
%134 = load i32, i32* %6
%135 = call i32 @close(i32 %134)
%136 = call i32 @exit(i32 4)
unreachable
137: ; preds = %124
%138 = load i32, i32* @ICANON
%139 = xor i32 %138, -1
%140 = getelementptr inbounds %struct.termios, %struct.termios* %10, i32 0, i32 0
%141 = load i32, i32* %140
%142 = and i32 %141, %139
store i32 %142, i32* %140
%143 = load i32, i32* %6
%144 = load i32, i32* @TCSAFLUSH
%145 = call i32 @tcsetattr(i32 %143, i32 %144, %struct.termios* %10)
store i32 %145, i32* %7
%146 = load i32, i32* %7
%147 = icmp slt i32 %146, 0
br i1 %147, label %148, label %156
148: ; preds = %137
%149 = load i32, i32* @stderr
%150 = load i64, i64* @errno
%151 = call i8* @strerror(i64 %150)
%152 = call i32 (i32, i8*, ...) @fprintf(i32 %149, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.10, i64 0, i64 0), i8* %151)
%153 = load i32, i32* %6
%154 = call i32 @close(i32 %153)
%155 = call i32 @exit(i32 5)
unreachable
156: ; preds = %137
%157 = load i32, i32* %6
%158 = load i32, i32* @TCIOFLUSH
%159 = call i32 @tcflush(i32 %157, i32 %158)
%160 = getelementptr inbounds [1 x i8], [1 x i8]* %12, i64 0, i64 0
store i8 112, i8* %160
%161 = getelementptr inbounds %struct.timeval, %struct.timeval* %11, i32 0, i32 1
store i64 0, i64* %161
%162 = getelementptr inbounds %struct.timeval, %struct.timeval* %11, i32 0, i32 0
store i32 200, i32* %162
%163 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.11, i64 0, i64 0), i32 112)
%164 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.12, i64 0, i64 0))
br label %165
165: ; preds = %214, %156
%166 = load i32, i32* %6
%167 = getelementptr inbounds [1 x i8], [1 x i8]* %12, i64 0, i64 0
%168 = call i32 @write(i32 %166, i8* %167, i32 1)
%169 = icmp slt i32 %168, 1
br i1 %169, label %170, label %176
170: ; preds = %165
%171 = load i32, i32* @stderr
%172 = load i64, i64* @errno
%173 = call i8* @strerror(i64 %172)
%174 = call i32 (i32, i8*, ...) @fprintf(i32 %171, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.13, i64 0, i64 0), i8* %173)
%175 = call i32 @exit(i32 6)
unreachable
176: ; preds = %165
%177 = call i32 @FD_ZERO(i32* %14)
%178 = load i32, i32* %6
%179 = call i32 @FD_SET(i32 %178, i32* %14)
%180 = load i32, i32* %6
%181 = add nsw i32 %180, 1
%182 = call i32 @select(i32 %181, i32* %14, i32* null, i32* null, %struct.timeval* %11)
store i32 %182, i32* %8
%183 = load i32, i32* %8
%184 = icmp slt i32 %183, 0
br i1 %184, label %185, label %189
185: ; preds = %176
%186 = load i32, i32* @stderr
%187 = call i32 (i32, i8*, ...) @fprintf(i32 %186, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.14, i64 0, i64 0))
%188 = call i32 @exit(i32 7)
unreachable
189: ; preds = %176
%190 = load i32, i32* %6
%191 = call i64 @FD_ISSET(i32 %190, i32* %14)
%192 = icmp ne i64 %191, 0
br i1 %192, label %193, label %213
193: ; preds = %189
%194 = load i32, i32* %6
%195 = getelementptr inbounds [1 x i8], [1 x i8]* %13, i64 0, i64 0
%196 = call i32 @read(i32 %194, i8* %195, i32 1)
%197 = icmp slt i32 %196, 1
br i1 %197, label %198, label %204
198: ; preds = %193
%199 = load i32, i32* @stderr
%200 = load i64, i64* @errno
%201 = call i8* @strerror(i64 %200)
%202 = call i32 (i32, i8*, ...) @fprintf(i32 %199, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.15, i64 0, i64 0), i8* %201)
%203 = call i32 @exit(i32 8)
unreachable
204: ; preds = %193
%205 = getelementptr inbounds [1 x i8], [1 x i8]* %13, i64 0, i64 0
%206 = load i8, i8* %205
%207 = zext i8 %206 to i32
%208 = icmp eq i32 %207, 83
br i1 %208, label %209, label %212
209: ; preds = %204
%210 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.16, i64 0, i64 0))
%211 = call i32 @exit(i32 0)
unreachable
212: ; preds = %204
br label %213
213: ; preds = %212, %189
br label %214
214: ; preds = %213
br label %165
215: ; preds = %29
%216 = load i32, i32* %3
ret i32 %216
}

LLVM IR (-O2):
%struct.termios = type { i32 }
%struct.timeval = type { i32, i64 }
@.str = [3 x i8] c"-h\00"
@.str.1 = [7 x i8] c"--help\00"
@.str.2 = [38 x i8] c"Usage: %s <serial device> <baudrate>\0A\00"
@.str.3 = [27 x i8] c"Opening serial device %s.\0A\00"
@B4800 = global i32 0
@B9600 = global i32 0
@B19200 = global i32 0
@B38400 = global i32 0
@B57600 = global i32 0
@B115200 = global i32 0
@stderr = global i32 0
@.str.4 = [22 x i8] c"Unknown bitrate \22%s\0A\22\00"
@O_RDWR = global i32 0
@errno = global i64 0
@ENOENT = global i64 0
@.str.6 = [8 x i8] c"%s: %s\0A\00"
@.str.7 = [15 x i8] c"tcgetattr: %s\0A\00"
@.str.8 = [17 x i8] c"cfsetispeed: %s\0A\00"
@.str.9 = [16 x i8] c"cfsetspeed: %s\0A\00"
@ICANON = global i32 0
@TCSAFLUSH = global i32 0
@.str.10 = [15 x i8] c"tcsetattr: %s\0A\00"
@TCIOFLUSH = global i32 0
@.str.11 = [40 x i8] c"Sending bootloader entry command (%c).\0A\00"
@.str.13 = [24 x i8] c"error during write: %s\0A\00"
@.str.14 = [17 x i8] c"error in select\0A\00"
@.str.15 = [23 x i8] c"error during read: %s\0A\00"
@str = [39 x i8] c"You may now plug in the target device.\00"
@str.17 = [20 x i8] c"Bootloader running.\00"
@str.18 = [63 x i8] c"Serial device does not exist, waiting for it to be plugged in.\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.termios
%4 = alloca %struct.timeval
%5 = alloca [1 x i8]
%6 = alloca [1 x i8]
%7 = alloca i32
%8 = bitcast %struct.termios* %3 to i8*
%9 = bitcast %struct.timeval* %4 to i8*
%10 = getelementptr inbounds [1 x i8], [1 x i8]* %5, i64 0, i64 0
%11 = getelementptr inbounds [1 x i8], [1 x i8]* %6, i64 0, i64 0
%12 = bitcast i32* %7 to i8*
%13 = icmp eq i32 %0, 3
br i1 %13, label %14, label %23
14: ; preds = %2
%15 = getelementptr inbounds i8*, i8** %1, i64 1
%16 = load i8*, i8** %15
%17 = tail call i64 @strcmp(i8* %16, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%18 = icmp eq i64 %17, 0
br i1 %18, label %23, label %19
19: ; preds = %14
%20 = load i8*, i8** %15
%21 = tail call i64 @strcmp(i8* %20, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%22 = icmp eq i64 %21, 0
br i1 %22, label %23, label %26
23: ; preds = %19, %14, %2
%24 = load i8*, i8** %1
%25 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @.str.2, i64 0, i64 0), i8* %24)
ret i32 0
26: ; preds = %19
%27 = load i8*, i8** %15
%28 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0), i8* %27)
%29 = getelementptr inbounds i8*, i8** %1, i64 2
%30 = load i8*, i8** %29
%31 = tail call i32 @atoi(i8* %30)
switch i32 %31, label %37 [
i32 4800, label %41
i32 9600, label %32
i32 19200, label %33
i32 38400, label %34
i32 57600, label %35
i32 115200, label %36
]
32: ; preds = %26
br label %41
33: ; preds = %26
br label %41
34: ; preds = %26
br label %41
35: ; preds = %26
br label %41
36: ; preds = %26
br label %41
37: ; preds = %26
%38 = load i32, i32* @stderr
%39 = tail call i32 (i32, i8*, ...) @fprintf(i32 %38, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.4, i64 0, i64 0), i8* %30)
%40 = tail call i32 @exit(i32 1)
unreachable
41: ; preds = %26, %36, %35, %34, %33, %32
%42 = phi i32* [ @B115200, %36 ], [ @B57600, %35 ], [ @B38400, %34 ], [ @B19200, %33 ], [ @B9600, %32 ], [ @B4800, %26 ]
%43 = load i32, i32* %42
%44 = load i8*, i8** %15
%45 = load i32, i32* @O_RDWR
%46 = tail call i32 @open(i8* %44, i32 %45, i32 0)
%47 = icmp slt i32 %46, 0
br i1 %47, label %48, label %71
48: ; preds = %41
%49 = load i64, i64* @errno
%50 = load i64, i64* @ENOENT
%51 = icmp eq i64 %49, %50
br i1 %51, label %52, label %64
52: ; preds = %48
%53 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([63 x i8], [63 x i8]* @str.18, i64 0, i64 0))
%54 = load i8*, i8** %15
%55 = load i32, i32* @O_RDWR
%56 = tail call i32 @open(i8* %54, i32 %55, i32 0)
%57 = icmp slt i32 %56, 0
br i1 %57, label %58, label %71
58: ; preds = %52, %58
%59 = tail call i32 @usleep(i32 10000)
%60 = load i8*, i8** %15
%61 = load i32, i32* @O_RDWR
%62 = tail call i32 @open(i8* %60, i32 %61, i32 0)
%63 = icmp slt i32 %62, 0
br i1 %63, label %58, label %71
64: ; preds = %48
%65 = load i32, i32* @stderr
%66 = load i8*, i8** %15
%67 = tail call i8* @strerror(i64 %49)
%68 = tail call i32 (i32, i8*, ...) @fprintf(i32 %65, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.6, i64 0, i64 0), i8* %66, i8* %67)
%69 = tail call i32 @close(i32 %46)
%70 = tail call i32 @exit(i32 1)
unreachable
71: ; preds = %58, %52, %41
%72 = phi i32 [ %46, %41 ], [ %56, %52 ], [ %62, %58 ]
%73 = call i32 @tcgetattr(i32 %72, %struct.termios* %3)
%74 = icmp slt i32 %73, 0
br i1 %74, label %75, label %82
75: ; preds = %71
%76 = load i32, i32* @stderr
%77 = load i64, i64* @errno
%78 = call i8* @strerror(i64 %77)
%79 = call i32 (i32, i8*, ...) @fprintf(i32 %76, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.7, i64 0, i64 0), i8* %78)
%80 = call i32 @close(i32 %72)
%81 = call i32 @exit(i32 2)
unreachable
82: ; preds = %71
%83 = call i32 @cfsetispeed(%struct.termios* %3, i32 %43)
%84 = icmp slt i32 %83, 0
br i1 %84, label %85, label %92
85: ; preds = %82
%86 = load i32, i32* @stderr
%87 = load i64, i64* @errno
%88 = call i8* @strerror(i64 %87)
%89 = call i32 (i32, i8*, ...) @fprintf(i32 %86, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.8, i64 0, i64 0), i8* %88)
%90 = call i32 @close(i32 %72)
%91 = call i32 @exit(i32 3)
unreachable
92: ; preds = %82
%93 = call i32 @cfsetspeed(%struct.termios* %3, i32 %43)
%94 = icmp slt i32 %93, 0
br i1 %94, label %95, label %102
95: ; preds = %92
%96 = load i32, i32* @stderr
%97 = load i64, i64* @errno
%98 = call i8* @strerror(i64 %97)
%99 = call i32 (i32, i8*, ...) @fprintf(i32 %96, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.9, i64 0, i64 0), i8* %98)
%100 = call i32 @close(i32 %72)
%101 = call i32 @exit(i32 4)
unreachable
102: ; preds = %92
%103 = load i32, i32* @ICANON
%104 = xor i32 %103, -1
%105 = getelementptr inbounds %struct.termios, %struct.termios* %3, i64 0, i32 0
%106 = load i32, i32* %105
%107 = and i32 %106, %104
store i32 %107, i32* %105
%108 = load i32, i32* @TCSAFLUSH
%109 = call i32 @tcsetattr(i32 %72, i32 %108, %struct.termios* %3)
%110 = icmp slt i32 %109, 0
br i1 %110, label %111, label %118
111: ; preds = %102
%112 = load i32, i32* @stderr
%113 = load i64, i64* @errno
%114 = call i8* @strerror(i64 %113)
%115 = call i32 (i32, i8*, ...) @fprintf(i32 %112, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.10, i64 0, i64 0), i8* %114)
%116 = call i32 @close(i32 %72)
%117 = call i32 @exit(i32 5)
unreachable
118: ; preds = %102
%119 = load i32, i32* @TCIOFLUSH
%120 = call i32 @tcflush(i32 %72, i32 %119)
store i8 112, i8* %10
%121 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i64 0, i32 1
store i64 0, i64* %121
%122 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i64 0, i32 0
store i32 200, i32* %122
%123 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @.str.11, i64 0, i64 0), i32 112)
%124 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @str, i64 0, i64 0))
%125 = call i32 @write(i32 %72, i8* %10, i32 1)
%126 = icmp slt i32 %125, 1
br i1 %126, label %129, label %127
127: ; preds = %118
%128 = add nuw nsw i32 %72, 1
br label %135
129: ; preds = %162, %118
%130 = load i32, i32* @stderr
%131 = load i64, i64* @errno
%132 = call i8* @strerror(i64 %131)
%133 = call i32 (i32, i8*, ...) @fprintf(i32 %130, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.13, i64 0, i64 0), i8* %132)
%134 = call i32 @exit(i32 6)
unreachable
135: ; preds = %127, %162
%136 = call i32 @FD_ZERO(i32* %7)
%137 = call i32 @FD_SET(i32 %72, i32* %7)
%138 = call i32 @select(i32 %128, i32* %7, i32* null, i32* null, %struct.timeval* %4)
%139 = icmp slt i32 %138, 0
br i1 %139, label %140, label %144
140: ; preds = %135
%141 = load i32, i32* @stderr
%142 = call i32 (i32, i8*, ...) @fprintf(i32 %141, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.14, i64 0, i64 0))
%143 = call i32 @exit(i32 7)
unreachable
144: ; preds = %135
%145 = call i64 @FD_ISSET(i32 %72, i32* %7)
%146 = icmp eq i64 %145, 0
br i1 %146, label %162, label %147
147: ; preds = %144
%148 = call i32 @read(i32 %72, i8* %11, i32 1)
%149 = icmp slt i32 %148, 1
br i1 %149, label %150, label %156
150: ; preds = %147
%151 = load i32, i32* @stderr
%152 = load i64, i64* @errno
%153 = call i8* @strerror(i64 %152)
%154 = call i32 (i32, i8*, ...) @fprintf(i32 %151, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.15, i64 0, i64 0), i8* %153)
%155 = call i32 @exit(i32 8)
unreachable
156: ; preds = %147
%157 = load i8, i8* %11
%158 = icmp eq i8 %157, 83
br i1 %158, label %159, label %162
159: ; preds = %156
%160 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str.17, i64 0, i64 0))
%161 = call i32 @exit(i32 0)
unreachable
162: ; preds = %144, %156
%163 = call i32 @write(i32 %72, i8* %10, i32 1)
%164 = icmp slt i32 %163, 1
br i1 %164, label %129, label %135
}