#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_cflag;
  int /*<<< orphan*/ c_lflag;
};
typedef int /*<<< orphan*/ fd_set;

/* Variables and functions */
int B115200;
int B19200;
int B38400;
int B4800;
int B57600;
int B9600;
int /*<<< orphan*/ CLOCAL;
scalar_t__ ENOENT;
scalar_t__ EWOULDBLOCK;
scalar_t__ FD_ISSET(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ FD_SET(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ FD_ZERO(int /*<<< orphan*/ *);
int /*<<< orphan*/ ICANON;
int O_NONBLOCK;
int O_RDWR;
int /*<<< orphan*/ TCIOFLUSH;
int /*<<< orphan*/ TCSAFLUSH;
int atoi(char *);
int cfsetispeed(struct termios *, int);
int cfsetspeed(struct termios *, int);
scalar_t__ errno;
int /*<<< orphan*/ errx(int, char *, ...);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int open(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int read(int, unsigned char *, int);
int select(int, int /*<<< orphan*/ *, int /*<<< orphan*/ *,
           int /*<<< orphan*/ *, struct timeval *);
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")) || (strcmp(argv[1], "--help"))) {
    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:
      errx(1, "Unknown bitrate \"%s\"", argv[2]);
      break;
    }
    fd = open(argv[1], O_RDWR | O_NONBLOCK, 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 | O_NONBLOCK, 0)) < 0) {
          usleep(10000);
        }
      } else
        errx(1, "%s: %s", argv[1], strerror(errno));
    }
    err = tcgetattr(fd, &t);
    if (err < 0)
      errx(2, "tcgetattr: %s", strerror(errno));
    err = cfsetispeed(&t, bitrate);
    if (err < 0)
      errx(3, "cfsetispeed: %s", strerror(errno));
    err = cfsetspeed(&t, bitrate);
    if (err < 0)
      errx(4, "cfsetspeed: %s", strerror(errno));
    t.c_lflag &= ~ICANON;
    t.c_cflag |= CLOCAL;
    err = tcsetattr(fd, TCSAFLUSH, &t);
    if (err < 0)
      errx(5, "tcsetattr: %s", strerror(errno));
    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 (;;) {
      usleep(2000);
      if (write(fd, w, 1) < 1) {
        if (errno == EWOULDBLOCK) {
          usleep(2000);
          continue;
        } else
          errx(6, "error during write: %s", strerror(errno));
      }
      FD_ZERO(&fds);
      FD_SET(fd, &fds);
      rc = select(fd + 1, &fds, NULL, NULL, &tv);
      if (rc < 0)
        errx(7, "error in select");
      else {
        if (FD_ISSET(fd, &fds)) {
          if (read(fd, r, 1) < 1)
            errx(8, "error during read: %s", strerror(errno));
          if (r[0] == 'S') {
            printf("Bootloader running.\n");
            exit(0);
          }
        }
      }
    }
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
jne    128c <main+0x5c>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xda1(%rip),%rsi
call   10a0 <strcmp@plt>
cmp    $0x0,%rax
jne    128c <main+0x5c>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xd86(%rip),%rsi
call   10a0 <strcmp@plt>
cmp    $0x0,%rax
je     12a6 <main+0x76>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xd70(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
jmp    1747 <main+0x517>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xd7b(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1110 <atoi@plt>
mov    %eax,%ecx
mov    %ecx,-0x44(%rbp)
sub    $0x12c0,%eax
je     133d <main+0x10d>
jmp    12de <main+0xae>
mov    -0x44(%rbp),%eax
sub    $0x2580,%eax
je     134e <main+0x11e>
jmp    12f1 <main+0xc1>
mov    -0x44(%rbp),%eax
sub    $0x4b00,%eax
je     135f <main+0x12f>
jmp    1304 <main+0xd4>
mov    -0x44(%rbp),%eax
sub    $0x9600,%eax
je     1370 <main+0x140>
jmp    1317 <main+0xe7>
mov    -0x44(%rbp),%eax
sub    $0xe100,%eax
je     1381 <main+0x151>
jmp    132a <main+0xfa>
mov    -0x44(%rbp),%eax
sub    $0x1c200,%eax
je     1392 <main+0x162>
jmp    13a3 <main+0x173>
mov    0x2c84(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
jmp    13be <main+0x18e>
mov    0x2c6b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
jmp    13be <main+0x18e>
mov    0x2c8a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
jmp    13be <main+0x18e>
mov    0x2bf1(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
jmp    13be <main+0x18e>
mov    0x2c30(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
jmp    13be <main+0x18e>
mov    0x2bf7(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
jmp    13be <main+0x18e>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdx
mov    $0x1,%edi
lea    0xc94(%rip),%rsi
mov    $0x0,%al
call   1050 <errx@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2c13(%rip),%rax
mov    (%rax),%esi
mov    0x2bfa(%rip),%rax
or     (%rax),%esi
xor    %edx,%edx
call   10f0 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    148f <main+0x25f>
mov    0x2bb5(%rip),%rax
mov    (%rax),%rax
mov    0x2b7b(%rip),%rcx
cmp    (%rcx),%rax
jne    1455 <main+0x225>
lea    0xc53(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2bbd(%rip),%rax
mov    (%rax),%esi
mov    0x2ba4(%rip),%rax
or     (%rax),%esi
xor    %edx,%edx
call   10f0 <open@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jge    1450 <main+0x220>
mov    $0x2710,%edi
call   1150 <usleep@plt>
jmp    1414 <main+0x1e4>
jmp    148a <main+0x25a>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x50(%rbp)
mov    0x2b40(%rip),%rax
mov    (%rax),%rdi
call   1130 <strerror@plt>
mov    -0x50(%rbp),%rdx
mov    %rax,%rcx
mov    $0x1,%edi
lea    0xc1d(%rip),%rsi
mov    $0x0,%al
call   1050 <errx@plt>
jmp    148f <main+0x25f>
mov    -0x14(%rbp),%edi
lea    -0x28(%rbp),%rsi
call   10d0 <tcgetattr@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    14cd <main+0x29d>
mov    0x2af9(%rip),%rax
mov    (%rax),%rdi
call   1130 <strerror@plt>
mov    %rax,%rdx
mov    $0x2,%edi
lea    0xbe1(%rip),%rsi
mov    $0x0,%al
call   1050 <errx@plt>
mov    -0x20(%rbp),%esi
lea    -0x28(%rbp),%rdi
call   1100 <cfsetispeed@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    150b <main+0x2db>
mov    0x2abb(%rip),%rax
mov    (%rax),%rdi
call   1130 <strerror@plt>
mov    %rax,%rdx
mov    $0x3,%edi
lea    0xbb1(%rip),%rsi
mov    $0x0,%al
call   1050 <errx@plt>
mov    -0x20(%rbp),%esi
lea    -0x28(%rbp),%rdi
call   1080 <cfsetspeed@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    1549 <main+0x319>
mov    0x2a7d(%rip),%rax
mov    (%rax),%rdi
call   1130 <strerror@plt>
mov    %rax,%rdx
mov    $0x4,%edi
lea    0xb83(%rip),%rsi
mov    $0x0,%al
call   1050 <errx@plt>
mov    0x2a38(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x24(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    0x2a0e(%rip),%rax
mov    (%rax),%eax
or     -0x28(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    -0x14(%rbp),%edi
mov    0x2a64(%rip),%rax
mov    (%rax),%esi
lea    -0x28(%rbp),%rdx
call   10e0 <tcsetattr@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    15b1 <main+0x381>
mov    0x2a15(%rip),%rax
mov    (%rax),%rdi
call   1130 <strerror@plt>
mov    %rax,%rdx
mov    $0x5,%edi
lea    0xb2a(%rip),%rsi
mov    $0x0,%al
call   1050 <errx@plt>
mov    -0x14(%rbp),%edi
mov    0x29dd(%rip),%rax
mov    (%rax),%esi
call   1060 <tcflush@plt>
movb   $0x70,-0x39(%rbp)
movq   $0x0,-0x30(%rbp)
movl   $0xc8,-0x38(%rbp)
lea    0xb06(%rip),%rdi
mov    $0x70,%esi
mov    $0x0,%al
call   1070 <printf@plt>
lea    0xb1b(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    $0x7d0,%edi
call   1150 <usleep@plt>
mov    -0x14(%rbp),%edi
lea    -0x39(%rbp),%rsi
mov    $0x1,%edx
call   1030 <write@plt>
cmp    $0x1,%eax
jge    166d <main+0x43d>
mov    0x2987(%rip),%rax
mov    (%rax),%rax
mov    0x2975(%rip),%rcx
cmp    (%rcx),%rax
jne    1643 <main+0x413>
mov    $0x7d0,%edi
call   1150 <usleep@plt>
jmp    15f6 <main+0x3c6>
mov    0x295e(%rip),%rax
mov    (%rax),%rdi
call   1130 <strerror@plt>
mov    %rax,%rdx
mov    $0x6,%edi
lea    0xad1(%rip),%rsi
mov    $0x0,%al
call   1050 <errx@plt>
jmp    166d <main+0x43d>
lea    -0x40(%rbp),%rdi
call   10b0 <FD_ZERO@plt>
mov    -0x14(%rbp),%edi
lea    -0x40(%rbp),%rsi
call   1140 <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   10c0 <select@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    16c1 <main+0x491>
mov    $0x7,%edi
lea    0xa94(%rip),%rsi
mov    $0x0,%al
call   1050 <errx@plt>
jmp    1742 <main+0x512>
mov    -0x14(%rbp),%edi
lea    -0x40(%rbp),%rsi
call   1040 <FD_ISSET@plt>
cmp    $0x0,%rax
je     173d <main+0x50d>
mov    -0x14(%rbp),%edi
lea    -0x3a(%rbp),%rsi
mov    $0x1,%edx
call   1090 <read@plt>
cmp    $0x1,%eax
jge    1716 <main+0x4e6>
mov    0x28b0(%rip),%rax
mov    (%rax),%rdi
call   1130 <strerror@plt>
mov    %rax,%rdx
mov    $0x8,%edi
lea    0xa4a(%rip),%rsi
mov    $0x0,%al
call   1050 <errx@plt>
movzbl -0x3a(%rbp),%eax
cmp    $0x53,%eax
jne    1738 <main+0x508>
lea    0xa45(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
xor    %edi,%edi
call   1120 <exit@plt>
jmp    173d <main+0x50d>
jmp    1742 <main+0x512>
jmp    15f6 <main+0x3c6>
mov    -0x4(%rbp),%eax
add    $0x50,%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    1280 <main+0x40>
mov    0x8(%rbx),%rdi
lea    0xd9f(%rip),%rsi
call   10b0 <strcmp@plt>
test   %rax,%rax
jne    1280 <main+0x40>
mov    0x8(%rbx),%rdi
lea    0xd8d(%rip),%rsi
call   10b0 <strcmp@plt>
test   %rax,%rax
je     12a2 <main+0x62>
mov    (%rbx),%rsi
lea    0xd80(%rip),%rdi
xor    %eax,%eax
call   1080 <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    0xd83(%rip),%rdi
xor    %eax,%eax
call   1080 <printf@plt>
mov    0x10(%rbx),%rbp
mov    %rbp,%rdi
call   1120 <atoi@plt>
cmp    $0x95ff,%eax
jg     12e8 <main+0xa8>
cmp    $0x12c0,%eax
je     1309 <main+0xc9>
cmp    $0x2580,%eax
je     1315 <main+0xd5>
cmp    $0x4b00,%eax
jne    1339 <main+0xf9>
mov    0x2d0d(%rip),%rax
mov    (%rax),%r15d
jmp    134f <main+0x10f>
cmp    $0x9600,%eax
je     1321 <main+0xe1>
cmp    $0xe100,%eax
je     132d <main+0xed>
cmp    $0x1c200,%eax
jne    1339 <main+0xf9>
mov    0x2c8c(%rip),%rax
mov    (%rax),%r15d
jmp    134f <main+0x10f>
mov    0x2cb8(%rip),%rax
mov    (%rax),%r15d
jmp    134f <main+0x10f>
mov    0x2ca4(%rip),%rax
mov    (%rax),%r15d
jmp    134f <main+0x10f>
mov    0x2c40(%rip),%rax
mov    (%rax),%r15d
jmp    134f <main+0x10f>
mov    0x2c84(%rip),%rax
mov    (%rax),%r15d
jmp    134f <main+0x10f>
lea    0xd0b(%rip),%rsi
mov    $0x1,%edi
mov    %rbp,%rdx
xor    %eax,%eax
call   1060 <errx@plt>
mov    0x8(%rbx),%rdi
mov    0x2c86(%rip),%r12
mov    0x2c6f(%rip),%rbp
mov    0x0(%rbp),%esi
or     (%r12),%esi
xor    %edx,%edx
call   1100 <open@plt>
mov    %eax,%r14d
test   %eax,%eax
jns    13fc <main+0x1bc>
mov    0x2c27(%rip),%rax
mov    (%rax),%rdi
mov    0x2bed(%rip),%rax
cmp    (%rax),%rdi
jne    13da <main+0x19a>
lea    0xdab(%rip),%rdi
call   1030 <puts@plt>
mov    0x8(%rbx),%rdi
mov    0x0(%rbp),%esi
or     (%r12),%esi
xor    %edx,%edx
call   1100 <open@plt>
mov    %eax,%r14d
test   %eax,%eax
jns    13fc <main+0x1bc>
mov    $0x2710,%edi
call   1160 <usleep@plt>
mov    0x8(%rbx),%rdi
mov    0x0(%rbp),%esi
or     (%r12),%esi
xor    %edx,%edx
call   1100 <open@plt>
test   %eax,%eax
js     13b5 <main+0x175>
mov    %eax,%r14d
jmp    13fc <main+0x1bc>
mov    0x8(%rbx),%rbx
call   1140 <strerror@plt>
lea    0xc76(%rip),%rsi
mov    $0x1,%edi
mov    %rbx,%rdx
mov    %rax,%rcx
xor    %eax,%eax
call   1060 <errx@plt>
lea    0x8(%rsp),%rsi
mov    %r14d,%edi
call   10e0 <tcgetattr@plt>
test   %eax,%eax
jns    1432 <main+0x1f2>
mov    0x2b94(%rip),%rax
mov    (%rax),%rdi
call   1140 <strerror@plt>
lea    0xc44(%rip),%rsi
mov    $0x2,%edi
mov    %rax,%rdx
xor    %eax,%eax
call   1060 <errx@plt>
lea    0x8(%rsp),%rdi
mov    %r15d,%esi
call   1110 <cfsetispeed@plt>
test   %eax,%eax
jns    1468 <main+0x228>
mov    0x2b5e(%rip),%rax
mov    (%rax),%rdi
call   1140 <strerror@plt>
lea    0xc1c(%rip),%rsi
mov    $0x3,%edi
mov    %rax,%rdx
xor    %eax,%eax
call   1060 <errx@plt>
lea    0x8(%rsp),%rdi
mov    %r15d,%esi
call   1090 <cfsetspeed@plt>
test   %eax,%eax
jns    149e <main+0x25e>
mov    0x2b28(%rip),%rax
mov    (%rax),%rdi
call   1140 <strerror@plt>
lea    0xbf6(%rip),%rsi
mov    $0x4,%edi
mov    %rax,%rdx
xor    %eax,%eax
call   1060 <errx@plt>
mov    0x2ae3(%rip),%rax
mov    (%rax),%eax
not    %eax
and    %eax,0xc(%rsp)
mov    0x2abc(%rip),%rax
mov    (%rax),%eax
or     %eax,0x8(%rsp)
mov    0x2b17(%rip),%rax
mov    (%rax),%esi
lea    0x8(%rsp),%rdx
mov    %r14d,%edi
call   10f0 <tcsetattr@plt>
test   %eax,%eax
jns    14f9 <main+0x2b9>
mov    0x2acd(%rip),%rax
mov    (%rax),%rdi
call   1140 <strerror@plt>
lea    0xbaa(%rip),%rsi
mov    $0x5,%edi
mov    %rax,%rdx
xor    %eax,%eax
call   1060 <errx@plt>
mov    0x2a98(%rip),%rax
mov    (%rax),%esi
mov    %r14d,%edi
call   1070 <tcflush@plt>
movb   $0x70,0x7(%rsp)
movq   $0x0,0x20(%rsp)
movl   $0xc8,0x18(%rsp)
lea    0xb7b(%rip),%rdi
mov    $0x70,%esi
xor    %eax,%eax
call   1080 <printf@plt>
lea    0xbcd(%rip),%rdi
call   1030 <puts@plt>
lea    0x1(%r14),%ebx
lea    0x7(%rsp),%r12
mov    0x2a59(%rip),%r15
lea    0x14(%rsp),%rbp
lea    0x18(%rsp),%r13
jmp    156e <main+0x32e>
mov    $0x7,%edi
lea    0xb7a(%rip),%rsi
xor    %eax,%eax
call   1060 <errx@plt>
mov    $0x7d0,%edi
call   1160 <usleep@plt>
mov    %r14d,%edi
mov    %r12,%rsi
mov    $0x1,%edx
call   1040 <write@plt>
test   %eax,%eax
jg     15c2 <main+0x382>
mov    (%r15),%rdi
mov    0x2a0a(%rip),%rax
cmp    (%rax),%rdi
jne    15a7 <main+0x367>
mov    $0x7d0,%edi
call   1160 <usleep@plt>
jmp    156e <main+0x32e>
call   1140 <strerror@plt>
mov    $0x6,%edi
lea    0xb12(%rip),%rsi
mov    %rax,%rdx
xor    %eax,%eax
call   1060 <errx@plt>
mov    %rbp,%rdi
call   10c0 <FD_ZERO@plt>
mov    %r14d,%edi
mov    %rbp,%rsi
call   1150 <FD_SET@plt>
mov    %ebx,%edi
mov    %rbp,%rsi
xor    %edx,%edx
xor    %ecx,%ecx
mov    %r13,%r8
call   10d0 <select@plt>
test   %eax,%eax
js     155b <main+0x31b>
mov    %r14d,%edi
mov    %rbp,%rsi
call   1050 <FD_ISSET@plt>
test   %rax,%rax
je     156e <main+0x32e>
mov    %r14d,%edi
lea    0x6(%rsp),%rsi
mov    $0x1,%edx
call   10a0 <read@plt>
test   %eax,%eax
jle    1625 <main+0x3e5>
cmpb   $0x53,0x6(%rsp)
jne    156e <main+0x32e>
jmp    164e <main+0x40e>
mov    (%r15),%rdi
call   1140 <strerror@plt>
mov    $0x8,%edi
lea    0xab8(%rip),%rsi
mov    %rax,%rdx
xor    %eax,%eax
call   1060 <errx@plt>
cmpb   $0x53,0x6(%rsp)
jne    156e <main+0x32e>
lea    0xad9(%rip),%rdi
call   1030 <puts@plt>
xor    %edi,%edi
call   1130 <exit@plt>

LLVM IR (-O0):
%struct.termios = type { i32, 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
@.str.4 = [21 x i8] c"Unknown bitrate \22%s\22\00"
@O_RDWR = global i32 0
@O_NONBLOCK = 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 = [7 x i8] c"%s: %s\00"
@.str.7 = [14 x i8] c"tcgetattr: %s\00"
@.str.8 = [16 x i8] c"cfsetispeed: %s\00"
@.str.9 = [15 x i8] c"cfsetspeed: %s\00"
@ICANON = global i32 0
@CLOCAL = global i32 0
@TCSAFLUSH = global i32 0
@.str.10 = [14 x i8] c"tcsetattr: %s\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"
@EWOULDBLOCK = global i64 0
@.str.13 = [23 x i8] c"error during write: %s\00"
@.str.14 = [16 x i8] c"error in select\00"
@.str.15 = [22 x i8] c"error during read: %s\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 ne 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 ne 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 %203
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 %60
45: ; preds = %34
%46 = load i32, i32* @B9600
store i32 %46, i32* %9
br label %60
47: ; preds = %34
%48 = load i32, i32* @B19200
store i32 %48, i32* %9
br label %60
49: ; preds = %34
%50 = load i32, i32* @B38400
store i32 %50, i32* %9
br label %60
51: ; preds = %34
%52 = load i32, i32* @B57600
store i32 %52, i32* %9
br label %60
53: ; preds = %34
%54 = load i32, i32* @B115200
store i32 %54, i32* %9
br label %60
55: ; preds = %34
%56 = load i8**, i8*** %5
%57 = getelementptr inbounds i8*, i8** %56, i64 2
%58 = load i8*, i8** %57
%59 = call i32 (i32, i8*, ...) @errx(i32 1, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0), i8* %58)
br label %60
60: ; preds = %55, %53, %51, %49, %47, %45, %43
%61 = load i8**, i8*** %5
%62 = getelementptr inbounds i8*, i8** %61, i64 1
%63 = load i8*, i8** %62
%64 = load i32, i32* @O_RDWR
%65 = load i32, i32* @O_NONBLOCK
%66 = or i32 %64, %65
%67 = call i32 @open(i8* %63, 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 %96
70: ; preds = %60
%71 = load i64, i64* @errno
%72 = load i64, i64* @ENOENT
%73 = icmp eq i64 %71, %72
br i1 %73, label %74, label %88
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 = %85, %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 = load i32, i32* @O_NONBLOCK
%82 = or i32 %80, %81
%83 = call i32 @open(i8* %79, i32 %82, i32 0)
store i32 %83, i32* %6
%84 = icmp slt i32 %83, 0
br i1 %84, label %85, label %87
85: ; preds = %76
%86 = call i32 @usleep(i32 10000)
br label %76
87: ; preds = %76
br label %95
88: ; preds = %70
%89 = load i8**, i8*** %5
%90 = getelementptr inbounds i8*, i8** %89, i64 1
%91 = load i8*, i8** %90
%92 = load i64, i64* @errno
%93 = call i8* @strerror(i64 %92)
%94 = call i32 (i32, i8*, ...) @errx(i32 1, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0), i8* %91, i8* %93)
br label %95
95: ; preds = %88, %87
br label %96
96: ; preds = %95, %60
%97 = load i32, i32* %6
%98 = call i32 @tcgetattr(i32 %97, %struct.termios* %10)
store i32 %98, i32* %7
%99 = load i32, i32* %7
%100 = icmp slt i32 %99, 0
br i1 %100, label %101, label %105
101: ; preds = %96
%102 = load i64, i64* @errno
%103 = call i8* @strerror(i64 %102)
%104 = call i32 (i32, i8*, ...) @errx(i32 2, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.7, i64 0, i64 0), i8* %103)
br label %105
105: ; preds = %101, %96
%106 = load i32, i32* %9
%107 = call i32 @cfsetispeed(%struct.termios* %10, i32 %106)
store i32 %107, i32* %7
%108 = load i32, i32* %7
%109 = icmp slt i32 %108, 0
br i1 %109, label %110, label %114
110: ; preds = %105
%111 = load i64, i64* @errno
%112 = call i8* @strerror(i64 %111)
%113 = call i32 (i32, i8*, ...) @errx(i32 3, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.8, i64 0, i64 0), i8* %112)
br label %114
114: ; preds = %110, %105
%115 = load i32, i32* %9
%116 = call i32 @cfsetspeed(%struct.termios* %10, i32 %115)
store i32 %116, i32* %7
%117 = load i32, i32* %7
%118 = icmp slt i32 %117, 0
br i1 %118, label %119, label %123
119: ; preds = %114
%120 = load i64, i64* @errno
%121 = call i8* @strerror(i64 %120)
%122 = call i32 (i32, i8*, ...) @errx(i32 4, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.9, i64 0, i64 0), i8* %121)
br label %123
123: ; preds = %119, %114
%124 = load i32, i32* @ICANON
%125 = xor i32 %124, -1
%126 = getelementptr inbounds %struct.termios, %struct.termios* %10, i32 0, i32 1
%127 = load i32, i32* %126
%128 = and i32 %127, %125
store i32 %128, i32* %126
%129 = load i32, i32* @CLOCAL
%130 = getelementptr inbounds %struct.termios, %struct.termios* %10, i32 0, i32 0
%131 = load i32, i32* %130
%132 = or i32 %131, %129
store i32 %132, i32* %130
%133 = load i32, i32* %6
%134 = load i32, i32* @TCSAFLUSH
%135 = call i32 @tcsetattr(i32 %133, i32 %134, %struct.termios* %10)
store i32 %135, i32* %7
%136 = load i32, i32* %7
%137 = icmp slt i32 %136, 0
br i1 %137, label %138, label %142
138: ; preds = %123
%139 = load i64, i64* @errno
%140 = call i8* @strerror(i64 %139)
%141 = call i32 (i32, i8*, ...) @errx(i32 5, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.10, i64 0, i64 0), i8* %140)
br label %142
142: ; preds = %138, %123
%143 = load i32, i32* %6
%144 = load i32, i32* @TCIOFLUSH
%145 = call i32 @tcflush(i32 %143, i32 %144)
%146 = getelementptr inbounds [1 x i8], [1 x i8]* %12, i64 0, i64 0
store i8 112, i8* %146
%147 = getelementptr inbounds %struct.timeval, %struct.timeval* %11, i32 0, i32 1
store i64 0, i64* %147
%148 = getelementptr inbounds %struct.timeval, %struct.timeval* %11, i32 0, i32 0
store i32 200, i32* %148
%149 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.11, i64 0, i64 0), i32 112)
%150 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.12, i64 0, i64 0))
br label %151
151: ; preds = %202, %161, %142
%152 = call i32 @usleep(i32 2000)
%153 = load i32, i32* %6
%154 = getelementptr inbounds [1 x i8], [1 x i8]* %12, i64 0, i64 0
%155 = call i32 @write(i32 %153, i8* %154, i32 1)
%156 = icmp slt i32 %155, 1
br i1 %156, label %157, label %168
157: ; preds = %151
%158 = load i64, i64* @errno
%159 = load i64, i64* @EWOULDBLOCK
%160 = icmp eq i64 %158, %159
br i1 %160, label %161, label %163
161: ; preds = %157
%162 = call i32 @usleep(i32 2000)
br label %151
163: ; preds = %157
%164 = load i64, i64* @errno
%165 = call i8* @strerror(i64 %164)
%166 = call i32 (i32, i8*, ...) @errx(i32 6, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.13, i64 0, i64 0), i8* %165)
br label %167
167: ; preds = %163
br label %168
168: ; preds = %167, %151
%169 = call i32 @FD_ZERO(i32* %14)
%170 = load i32, i32* %6
%171 = call i32 @FD_SET(i32 %170, i32* %14)
%172 = load i32, i32* %6
%173 = add nsw i32 %172, 1
%174 = call i32 @select(i32 %173, i32* %14, i32* null, i32* null, %struct.timeval* %11)
store i32 %174, i32* %8
%175 = load i32, i32* %8
%176 = icmp slt i32 %175, 0
br i1 %176, label %177, label %179
177: ; preds = %168
%178 = call i32 (i32, i8*, ...) @errx(i32 7, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.14, i64 0, i64 0))
br label %202
179: ; preds = %168
%180 = load i32, i32* %6
%181 = call i64 @FD_ISSET(i32 %180, i32* %14)
%182 = icmp ne i64 %181, 0
br i1 %182, label %183, label %201
183: ; preds = %179
%184 = load i32, i32* %6
%185 = getelementptr inbounds [1 x i8], [1 x i8]* %13, i64 0, i64 0
%186 = call i32 @read(i32 %184, i8* %185, i32 1)
%187 = icmp slt i32 %186, 1
br i1 %187, label %188, label %192
188: ; preds = %183
%189 = load i64, i64* @errno
%190 = call i8* @strerror(i64 %189)
%191 = call i32 (i32, i8*, ...) @errx(i32 8, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.15, i64 0, i64 0), i8* %190)
br label %192
192: ; preds = %188, %183
%193 = getelementptr inbounds [1 x i8], [1 x i8]* %13, i64 0, i64 0
%194 = load i8, i8* %193
%195 = zext i8 %194 to i32
%196 = icmp eq i32 %195, 83
br i1 %196, label %197, label %200
197: ; preds = %192
%198 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.16, i64 0, i64 0))
%199 = call i32 @exit(i32 0)
unreachable
200: ; preds = %192
br label %201
201: ; preds = %200, %179
br label %202
202: ; preds = %201, %177
br label %151
203: ; preds = %29
%204 = load i32, i32* %3
ret i32 %204
}

LLVM IR (-O2):
%struct.termios = type { i32, 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
@.str.4 = [21 x i8] c"Unknown bitrate \22%s\22\00"
@O_RDWR = global i32 0
@O_NONBLOCK = global i32 0
@errno = global i64 0
@ENOENT = global i64 0
@.str.6 = [7 x i8] c"%s: %s\00"
@.str.7 = [14 x i8] c"tcgetattr: %s\00"
@.str.8 = [16 x i8] c"cfsetispeed: %s\00"
@.str.9 = [15 x i8] c"cfsetspeed: %s\00"
@ICANON = global i32 0
@CLOCAL = global i32 0
@TCSAFLUSH = global i32 0
@.str.10 = [14 x i8] c"tcsetattr: %s\00"
@TCIOFLUSH = global i32 0
@.str.11 = [40 x i8] c"Sending bootloader entry command (%c).\0A\00"
@EWOULDBLOCK = global i64 0
@.str.13 = [23 x i8] c"error during write: %s\00"
@.str.14 = [16 x i8] c"error in select\00"
@.str.15 = [22 x i8] c"error during read: %s\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 %19, label %23
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 %26, label %23
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 %44 [
i32 4800, label %32
i32 9600, label %34
i32 19200, label %36
i32 38400, label %38
i32 57600, label %40
i32 115200, label %42
]
32: ; preds = %26
%33 = load i32, i32* @B4800
br label %46
34: ; preds = %26
%35 = load i32, i32* @B9600
br label %46
36: ; preds = %26
%37 = load i32, i32* @B19200
br label %46
38: ; preds = %26
%39 = load i32, i32* @B38400
br label %46
40: ; preds = %26
%41 = load i32, i32* @B57600
br label %46
42: ; preds = %26
%43 = load i32, i32* @B115200
br label %46
44: ; preds = %26
%45 = tail call i32 (i32, i8*, ...) @errx(i32 1, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0), i8* %30)
br label %46
46: ; preds = %44, %42, %40, %38, %36, %34, %32
%47 = phi i32 [ undef, %44 ], [ %43, %42 ], [ %41, %40 ], [ %39, %38 ], [ %37, %36 ], [ %35, %34 ], [ %33, %32 ]
%48 = load i8*, i8** %15
%49 = load i32, i32* @O_RDWR
%50 = load i32, i32* @O_NONBLOCK
%51 = or i32 %50, %49
%52 = tail call i32 @open(i8* %48, i32 %51, i32 0)
%53 = icmp slt i32 %52, 0
br i1 %53, label %54, label %78
54: ; preds = %46
%55 = load i64, i64* @errno
%56 = load i64, i64* @ENOENT
%57 = icmp eq i64 %55, %56
br i1 %57, label %58, label %74
58: ; preds = %54
%59 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([63 x i8], [63 x i8]* @str.18, i64 0, i64 0))
%60 = load i8*, i8** %15
%61 = load i32, i32* @O_RDWR
%62 = load i32, i32* @O_NONBLOCK
%63 = or i32 %62, %61
%64 = tail call i32 @open(i8* %60, i32 %63, i32 0)
%65 = icmp slt i32 %64, 0
br i1 %65, label %66, label %78
66: ; preds = %58, %66
%67 = tail call i32 @usleep(i32 10000)
%68 = load i8*, i8** %15
%69 = load i32, i32* @O_RDWR
%70 = load i32, i32* @O_NONBLOCK
%71 = or i32 %70, %69
%72 = tail call i32 @open(i8* %68, i32 %71, i32 0)
%73 = icmp slt i32 %72, 0
br i1 %73, label %66, label %78
74: ; preds = %54
%75 = load i8*, i8** %15
%76 = tail call i8* @strerror(i64 %55)
%77 = tail call i32 (i32, i8*, ...) @errx(i32 1, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0), i8* %75, i8* %76)
br label %78
78: ; preds = %66, %58, %74, %46
%79 = phi i32 [ %52, %74 ], [ %52, %46 ], [ %64, %58 ], [ %72, %66 ]
%80 = call i32 @tcgetattr(i32 %79, %struct.termios* %3)
%81 = icmp slt i32 %80, 0
br i1 %81, label %82, label %86
82: ; preds = %78
%83 = load i64, i64* @errno
%84 = call i8* @strerror(i64 %83)
%85 = call i32 (i32, i8*, ...) @errx(i32 2, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.7, i64 0, i64 0), i8* %84)
br label %86
86: ; preds = %82, %78
%87 = call i32 @cfsetispeed(%struct.termios* %3, i32 %47)
%88 = icmp slt i32 %87, 0
br i1 %88, label %89, label %93
89: ; preds = %86
%90 = load i64, i64* @errno
%91 = call i8* @strerror(i64 %90)
%92 = call i32 (i32, i8*, ...) @errx(i32 3, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.8, i64 0, i64 0), i8* %91)
br label %93
93: ; preds = %89, %86
%94 = call i32 @cfsetspeed(%struct.termios* %3, i32 %47)
%95 = icmp slt i32 %94, 0
br i1 %95, label %96, label %100
96: ; preds = %93
%97 = load i64, i64* @errno
%98 = call i8* @strerror(i64 %97)
%99 = call i32 (i32, i8*, ...) @errx(i32 4, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.9, i64 0, i64 0), i8* %98)
br label %100
100: ; preds = %96, %93
%101 = load i32, i32* @ICANON
%102 = xor i32 %101, -1
%103 = getelementptr inbounds %struct.termios, %struct.termios* %3, i64 0, i32 1
%104 = load i32, i32* %103
%105 = and i32 %104, %102
store i32 %105, i32* %103
%106 = load i32, i32* @CLOCAL
%107 = getelementptr inbounds %struct.termios, %struct.termios* %3, i64 0, i32 0
%108 = load i32, i32* %107
%109 = or i32 %108, %106
store i32 %109, i32* %107
%110 = load i32, i32* @TCSAFLUSH
%111 = call i32 @tcsetattr(i32 %79, i32 %110, %struct.termios* %3)
%112 = icmp slt i32 %111, 0
br i1 %112, label %113, label %117
113: ; preds = %100
%114 = load i64, i64* @errno
%115 = call i8* @strerror(i64 %114)
%116 = call i32 (i32, i8*, ...) @errx(i32 5, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.10, i64 0, i64 0), i8* %115)
br label %117
117: ; preds = %113, %100
%118 = load i32, i32* @TCIOFLUSH
%119 = call i32 @tcflush(i32 %79, i32 %118)
store i8 112, i8* %10
%120 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i64 0, i32 1
store i64 0, i64* %120
%121 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i64 0, i32 0
store i32 200, i32* %121
%122 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @.str.11, i64 0, i64 0), i32 112)
%123 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @str, i64 0, i64 0))
%124 = add nsw i32 %79, 1
br label %125
125: ; preds = %145, %117
%126 = call i32 @usleep(i32 2000)
%127 = call i32 @write(i32 %79, i8* %10, i32 1)
%128 = icmp slt i32 %127, 1
br i1 %128, label %129, label %138
129: ; preds = %125
%130 = load i64, i64* @errno
%131 = load i64, i64* @EWOULDBLOCK
%132 = icmp eq i64 %130, %131
br i1 %132, label %133, label %135
133: ; preds = %129
%134 = call i32 @usleep(i32 2000)
br label %145
135: ; preds = %129
%136 = call i8* @strerror(i64 %130)
%137 = call i32 (i32, i8*, ...) @errx(i32 6, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.13, i64 0, i64 0), i8* %136)
br label %138
138: ; preds = %135, %125
%139 = call i32 @FD_ZERO(i32* %7)
%140 = call i32 @FD_SET(i32 %79, i32* %7)
%141 = call i32 @select(i32 %124, i32* %7, i32* null, i32* null, %struct.timeval* %4)
%142 = icmp slt i32 %141, 0
br i1 %142, label %143, label %146
143: ; preds = %138
%144 = call i32 (i32, i8*, ...) @errx(i32 7, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.14, i64 0, i64 0))
br label %145
145: ; preds = %143, %156, %146, %133
br label %125
146: ; preds = %138
%147 = call i64 @FD_ISSET(i32 %79, i32* %7)
%148 = icmp eq i64 %147, 0
br i1 %148, label %145, label %149
149: ; preds = %146
%150 = call i32 @read(i32 %79, i8* %11, i32 1)
%151 = icmp slt i32 %150, 1
br i1 %151, label %152, label %156
152: ; preds = %149
%153 = load i64, i64* @errno
%154 = call i8* @strerror(i64 %153)
%155 = call i32 (i32, i8*, ...) @errx(i32 8, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.15, i64 0, i64 0), i8* %154)
br label %156
156: ; preds = %152, %149
%157 = load i8, i8* %11
%158 = icmp eq i8 %157, 83
br i1 %158, label %159, label %145
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
}