#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_lflag;
  int c_iflag;
  int *c_cc;
  int /*<<< orphan*/ c_oflag;
};
typedef int /*<<< orphan*/ fd_set;

/* Variables and functions */
int CS8;
int CSIZE;
int CSTOPB;
int ECHO;
int ECHOE;
int ECHOK;
int ECHONL;
scalar_t__ FD_ISSET(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ FD_SET(int, int /*<<< orphan*/ *);
int ICANON;
int ICRNL;
int IGNBRK;
int IGNPAR;
int INLCR;
int INPCK;
int ISIG;
int /*<<< orphan*/ OPOST;
int /*<<< orphan*/ O_RDWR;
int PARENB;
int /*<<< orphan*/ TCSANOW;
size_t VMIN;
size_t VTIME;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int read(int, char *, int);
scalar_t__ select(int, int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                  int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
scalar_t__ strcmp(char *, char *);
scalar_t__ tcgetattr(int, struct termios *);
scalar_t__ tcsetattr(int, int /*<<< orphan*/, struct termios *);
int /*<<< orphan*/ write(int, char *, int);
main(int argc, char *argv[]) {
  int fd;
  int sendcrlf = 0;
  int passcr = 0;
  struct termios tc;
  char *arg0 = argv[0];
  while (argv[1] && argv[1][0] == '-') {
    if (strcmp(argv[1], "-s") == 0)
      sendcrlf = 1;
    else if (strcmp(argv[1], "-r") == 0)
      passcr = 1;
    else
      (argv--)[1] = NULL;
    argv++;
  }
  if (!argv[1]) {
    fprintf(stderr, "usage: %s [-s] [-r] /dev/ttyHS?\n", arg0);
    fprintf(stderr, "  -s send \\n as \\n and not as CRLF\n");
    fprintf(stderr, "  -r pass \\r and don't ignore\n");
    return 1;
  }
  fd = open(argv[1], O_RDWR);
  if (fd < 0) {
    perror("open");
    return 1;
  }
  if (tcgetattr(fd, &tc) < 0) {
    perror("tcgetattr");
    return 1;
  }
  tc.c_cflag &= ~(CSIZE | PARENB | CSTOPB | CSIZE);
  tc.c_cflag |= CS8;
  tc.c_lflag &= ~(ICANON | ECHO | ECHOE | ECHOK | ECHONL | INPCK | ISIG);
  tc.c_iflag |= IGNBRK | IGNPAR | ICRNL | INLCR;
  tc.c_oflag &= ~OPOST;
  tc.c_cc[VMIN] = 1;
  tc.c_cc[VTIME] = 0;
  if (tcsetattr(fd, TCSANOW, &tc) < 0) {
    perror("tcsetattr");
    return 1;
  }
  while (1) {
    fd_set rfd, wfd, efd;
    FD_SET(0, &rfd);
    FD_SET(fd, &rfd);
    FD_SET(1, &wfd);
    FD_SET(fd, &wfd);
    if (select(fd + 1, &rfd, &wfd, &efd, NULL) > 0) {
      char buf[1];
      if (FD_ISSET(0, &rfd) && FD_ISSET(fd, &wfd)) {
        int n = read(0, buf, 1);
        if (n < 0)
          return 2;
        if (n == 0)
          return 0;
        if (!sendcrlf && buf[0] == '\n') {
          buf[0] = '\r';
          write(fd, buf, n);
          buf[0] = '\n';
        }
        write(fd, buf, n);
      }
      if (FD_ISSET(fd, &rfd) && FD_ISSET(1, &wfd)) {
        int n = read(fd, buf, 1);
        if (n < 0)
          return 3;
        if (!passcr && buf[0] == '\r')
          continue;
        if (n > 0)
          write(1, buf, n);
      }
    }
  }
}


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)
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x48(%rbp)
mov    -0x10(%rbp),%rcx
xor    %eax,%eax
cmpq   $0x0,0x8(%rcx)
mov    %al,-0x61(%rbp)
je     1207 <main+0x57>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
movsbl (%rax),%eax
cmp    $0x2d,%eax
sete   %al
mov    %al,-0x61(%rbp)
mov    -0x61(%rbp),%al
test   $0x1,%al
jne    1217 <main+0x67>
jmp    1298 <main+0xe8>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xdda(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
jne    1241 <main+0x91>
movl   $0x1,-0x18(%rbp)
jmp    1287 <main+0xd7>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xdb3(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
jne    126b <main+0xbb>
movl   $0x1,-0x1c(%rbp)
jmp    1282 <main+0xd2>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0xfffffffffffffff8,%rcx
mov    %rcx,-0x10(%rbp)
movq   $0x0,0x8(%rax)
jmp    1287 <main+0xd7>
mov    -0x10(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x10(%rbp)
jmp    11df <main+0x2f>
mov    -0x10(%rbp),%rax
cmpq   $0x0,0x8(%rax)
jne    12fc <main+0x14c>
mov    0x2cd2(%rip),%rax
mov    (%rax),%edi
mov    -0x48(%rbp),%rdx
lea    0xd4b(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    0x2cb7(%rip),%rax
mov    (%rax),%edi
lea    0xd55(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    0x2ca0(%rip),%rax
mov    (%rax),%edi
lea    0xd62(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1627 <main+0x477>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2cdd(%rip),%rax
mov    (%rax),%esi
call   10b0 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    1337 <main+0x187>
lea    0xd44(%rip),%rdi
call   10c0 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    1627 <main+0x477>
mov    -0x14(%rbp),%edi
lea    -0x40(%rbp),%rsi
call   1090 <tcgetattr@plt>
cmp    $0x0,%rax
jge    1365 <main+0x1b5>
lea    0xd1b(%rip),%rdi
call   10c0 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    1627 <main+0x477>
mov    0x2c24(%rip),%rax
mov    (%rax),%eax
mov    0x2c53(%rip),%rcx
or     (%rcx),%eax
mov    0x2bba(%rip),%rcx
or     (%rcx),%eax
mov    0x2c09(%rip),%rcx
or     (%rcx),%eax
xor    $0xffffffff,%eax
and    -0x40(%rbp),%eax
mov    %eax,-0x40(%rbp)
mov    0x2c07(%rip),%rax
mov    (%rax),%eax
or     -0x40(%rbp),%eax
mov    %eax,-0x40(%rbp)
mov    0x2ba0(%rip),%rax
mov    (%rax),%eax
mov    0x2c07(%rip),%rcx
or     (%rcx),%eax
mov    0x2bf6(%rip),%rcx
or     (%rcx),%eax
mov    0x2bad(%rip),%rcx
or     (%rcx),%eax
mov    0x2b9c(%rip),%rcx
or     (%rcx),%eax
mov    0x2ba3(%rip),%rcx
or     (%rcx),%eax
mov    0x2bca(%rip),%rcx
or     (%rcx),%eax
xor    $0xffffffff,%eax
and    -0x3c(%rbp),%eax
mov    %eax,-0x3c(%rbp)
mov    0x2b70(%rip),%rax
mov    (%rax),%eax
mov    0x2b57(%rip),%rcx
or     (%rcx),%eax
mov    0x2bde(%rip),%rcx
or     (%rcx),%eax
mov    0x2bcd(%rip),%rcx
or     (%rcx),%eax
or     -0x38(%rbp),%eax
mov    %eax,-0x38(%rbp)
mov    0x2bb6(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x28(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    -0x30(%rbp),%rax
mov    0x2b68(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x1,(%rax,%rcx,4)
mov    -0x30(%rbp),%rax
mov    0x2b13(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x0,(%rax,%rcx,4)
mov    -0x14(%rbp),%edi
mov    0x2b67(%rip),%rax
mov    (%rax),%esi
lea    -0x40(%rbp),%rdx
call   10a0 <tcsetattr@plt>
cmp    $0x0,%rax
jge    1486 <main+0x2d6>
lea    0xc04(%rip),%rdi
call   10c0 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    1627 <main+0x477>
jmp    148b <main+0x2db>
xor    %edi,%edi
lea    -0x4c(%rbp),%rsi
call   10d0 <FD_SET@plt>
mov    -0x14(%rbp),%edi
lea    -0x4c(%rbp),%rsi
call   10d0 <FD_SET@plt>
mov    $0x1,%edi
lea    -0x50(%rbp),%rsi
call   10d0 <FD_SET@plt>
mov    -0x14(%rbp),%edi
lea    -0x50(%rbp),%rsi
call   10d0 <FD_SET@plt>
mov    -0x14(%rbp),%edi
add    $0x1,%edi
lea    -0x4c(%rbp),%rsi
lea    -0x50(%rbp),%rdx
lea    -0x54(%rbp),%rcx
xor    %eax,%eax
mov    %eax,%r8d
call   1080 <select@plt>
cmp    $0x0,%rax
jle    1622 <main+0x472>
xor    %edi,%edi
lea    -0x4c(%rbp),%rsi
call   1040 <FD_ISSET@plt>
cmp    $0x0,%rax
je     1589 <main+0x3d9>
mov    -0x14(%rbp),%edi
lea    -0x50(%rbp),%rsi
call   1040 <FD_ISSET@plt>
cmp    $0x0,%rax
je     1589 <main+0x3d9>
lea    -0x55(%rbp),%rsi
xor    %edi,%edi
mov    $0x1,%edx
call   1050 <read@plt>
mov    %eax,-0x5c(%rbp)
cmpl   $0x0,-0x5c(%rbp)
jge    1536 <main+0x386>
movl   $0x2,-0x4(%rbp)
jmp    1627 <main+0x477>
cmpl   $0x0,-0x5c(%rbp)
jne    154c <main+0x39c>
movl   $0x0,-0x4(%rbp)
jmp    1627 <main+0x477>
cmpl   $0x0,-0x18(%rbp)
jne    157a <main+0x3ca>
movsbl -0x55(%rbp),%eax
cmp    $0xa,%eax
jne    157a <main+0x3ca>
movb   $0xd,-0x55(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x55(%rbp),%rsi
mov    -0x5c(%rbp),%edx
call   1030 <write@plt>
movb   $0xa,-0x55(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x55(%rbp),%rsi
mov    -0x5c(%rbp),%edx
call   1030 <write@plt>
mov    -0x14(%rbp),%edi
lea    -0x4c(%rbp),%rsi
call   1040 <FD_ISSET@plt>
cmp    $0x0,%rax
je     161d <main+0x46d>
mov    $0x1,%edi
lea    -0x50(%rbp),%rsi
call   1040 <FD_ISSET@plt>
cmp    $0x0,%rax
je     161d <main+0x46d>
mov    -0x14(%rbp),%edi
lea    -0x55(%rbp),%rsi
mov    $0x1,%edx
call   1050 <read@plt>
mov    %eax,-0x60(%rbp)
cmpl   $0x0,-0x60(%rbp)
jge    15e1 <main+0x431>
movl   $0x3,-0x4(%rbp)
jmp    1627 <main+0x477>
cmpl   $0x0,-0x1c(%rbp)
jne    15fd <main+0x44d>
movsbl -0x55(%rbp),%eax
cmp    $0xd,%eax
jne    15fd <main+0x44d>
jmp    148b <main+0x2db>
cmpl   $0x0,-0x60(%rbp)
jle    1618 <main+0x468>
lea    -0x55(%rbp),%rsi
mov    -0x60(%rbp),%edx
mov    $0x1,%edi
call   1030 <write@plt>
jmp    161d <main+0x46d>
jmp    1622 <main+0x472>
jmp    148b <main+0x2db>
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    $0x38,%rsp
mov    (%rsi),%r14
mov    0x8(%rsi),%rdi
test   %rdi,%rdi
je     1258 <main+0xa8>
mov    %rsi,%rbp
lea    0x8(%rsi),%rbx
movl   $0x0,0x8(%rsp)
lea    0xe1c(%rip),%r12
lea    0xe18(%rip),%r15
xor    %r13d,%r13d
jmp    120f <main+0x5f>
movl   $0x1,0x8(%rsp)
lea    0x8(%rbp),%rax
mov    0x10(%rbp),%rdi
add    $0x10,%rbp
mov    %rbp,%rbx
mov    %rax,%rbp
test   %rdi,%rdi
je     1258 <main+0xa8>
cmpb   $0x2d,(%rdi)
jne    12a6 <main+0xf6>
mov    %r12,%rsi
call   1060 <strcmp@plt>
test   %rax,%rax
je     11f0 <main+0x40>
mov    (%rbx),%rdi
mov    %r15,%rsi
call   1060 <strcmp@plt>
test   %rax,%rax
je     1250 <main+0xa0>
add    $0xfffffffffffffff8,%rbp
movq   $0x0,(%rbx)
jmp    11f8 <main+0x48>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    $0x1,%r13d
jmp    11f8 <main+0x48>
mov    0x2d21(%rip),%rbx
mov    (%rbx),%edi
lea    0xd9e(%rip),%rsi
mov    %r14,%rdx
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    (%rbx),%edi
lea    0xdac(%rip),%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    (%rbx),%edi
lea    0xdc0(%rip),%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    $0x1,%eax
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2d3b(%rip),%rax
mov    (%rax),%esi
call   10b0 <open@plt>
test   %eax,%eax
js     1543 <main+0x393>
mov    %eax,%r15d
lea    0x10(%rsp),%rsi
mov    %eax,%edi
call   1090 <tcgetattr@plt>
test   %rax,%rax
js     1554 <main+0x3a4>
mov    0x2cb5(%rip),%rax
mov    0x2ce6(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
mov    0x2c4b(%rip),%rax
or     (%rax),%ecx
not    %ecx
and    0x10(%rsp),%ecx
mov    0x2ca4(%rip),%rax
or     (%rax),%ecx
mov    0x2c43(%rip),%rax
mov    0x2cac(%rip),%rdx
mov    (%rdx),%edx
or     (%rax),%edx
mov    0x2c99(%rip),%rax
or     (%rax),%edx
mov    0x2c50(%rip),%rax
or     (%rax),%edx
mov    0x2c3f(%rip),%rax
or     (%rax),%edx
mov    %ecx,0x10(%rsp)
mov    0x2c42(%rip),%rax
or     (%rax),%edx
mov    0x2c69(%rip),%rax
or     (%rax),%edx
not    %edx
and    %edx,0x14(%rsp)
mov    0x2c12(%rip),%rax
mov    0x2bfb(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
mov    0x2c80(%rip),%rax
or     (%rax),%ecx
mov    0x2c6f(%rip),%rax
or     (%rax),%ecx
or     %ecx,0x18(%rsp)
mov    0x2c5a(%rip),%rax
mov    (%rax),%eax
not    %eax
and    %eax,0x28(%rsp)
mov    0x20(%rsp),%rax
mov    0x2c0e(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x1,(%rax,%rcx,4)
mov    0x2bbd(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x0,(%rax,%rcx,4)
mov    0x2c14(%rip),%rax
mov    (%rax),%esi
lea    0x10(%rsp),%rdx
mov    %r15d,%edi
call   10a0 <tcsetattr@plt>
test   %rax,%rax
js     1565 <main+0x3b5>
mov    %r15d,%r14d
add    $0x1,%r14d
lea    0xc(%rsp),%rbx
lea    0x34(%rsp),%rbp
lea    0x30(%rsp),%r12
nopw   0x0(%rax,%rax,1)
xor    %edi,%edi
mov    %rbx,%rsi
call   10d0 <FD_SET@plt>
mov    %r15d,%edi
mov    %rbx,%rsi
call   10d0 <FD_SET@plt>
mov    $0x1,%edi
mov    %rbp,%rsi
call   10d0 <FD_SET@plt>
mov    %r15d,%edi
mov    %rbp,%rsi
call   10d0 <FD_SET@plt>
mov    %r14d,%edi
mov    %rbx,%rsi
mov    %rbp,%rdx
mov    %r12,%rcx
xor    %r8d,%r8d
call   1080 <select@plt>
test   %rax,%rax
jle    13e0 <main+0x230>
xor    %edi,%edi
mov    %rbx,%rsi
call   1040 <FD_ISSET@plt>
test   %rax,%rax
je     14ba <main+0x30a>
mov    %r15d,%edi
mov    %rbp,%rsi
call   1040 <FD_ISSET@plt>
test   %rax,%rax
je     14ba <main+0x30a>
mov    %r14d,%ebx
mov    %r12,%r14
mov    %r13d,%r12d
xor    %edi,%edi
lea    0x7(%rsp),%rsi
mov    $0x1,%edx
call   1050 <read@plt>
test   %eax,%eax
js     1528 <main+0x378>
je     1532 <main+0x382>
mov    %eax,%r13d
cmpl   $0x0,0x8(%rsp)
jne    149c <main+0x2ec>
cmpb   $0xa,0x7(%rsp)
jne    149c <main+0x2ec>
movb   $0xd,0x7(%rsp)
mov    %r15d,%edi
lea    0x7(%rsp),%rsi
mov    %r13d,%edx
call   1030 <write@plt>
movb   $0xa,0x7(%rsp)
mov    %r15d,%edi
lea    0x7(%rsp),%rsi
mov    %r13d,%edx
call   1030 <write@plt>
mov    %r12d,%r13d
mov    %r14,%r12
mov    %ebx,%r14d
lea    0xc(%rsp),%rbx
mov    %r15d,%edi
mov    %rbx,%rsi
call   1040 <FD_ISSET@plt>
test   %rax,%rax
je     13e0 <main+0x230>
mov    $0x1,%edi
mov    %rbp,%rsi
call   1040 <FD_ISSET@plt>
test   %rax,%rax
je     13e0 <main+0x230>
mov    %r15d,%edi
lea    0x7(%rsp),%rsi
mov    $0x1,%edx
call   1050 <read@plt>
test   %eax,%eax
js     1539 <main+0x389>
test   %r13d,%r13d
jne    150a <main+0x35a>
cmpb   $0xd,0x7(%rsp)
je     13e0 <main+0x230>
test   %eax,%eax
je     13e0 <main+0x230>
mov    $0x1,%edi
lea    0x7(%rsp),%rsi
mov    %eax,%edx
call   1030 <write@plt>
jmp    13e0 <main+0x230>
mov    $0x2,%eax
jmp    1297 <main+0xe7>
xor    %eax,%eax
jmp    1297 <main+0xe7>
mov    $0x3,%eax
jmp    1297 <main+0xe7>
lea    0xb20(%rip),%rdi
call   10c0 <perror@plt>
jmp    1292 <main+0xe2>
lea    0xb14(%rip),%rdi
call   10c0 <perror@plt>
jmp    1292 <main+0xe2>
lea    0xb0d(%rip),%rdi
call   10c0 <perror@plt>
jmp    1292 <main+0xe2>

LLVM IR (-O0):
%struct.termios = type { i32, i32, i32, i32*, i32 }
@.str = [3 x i8] c"-s\00"
@.str.1 = [3 x i8] c"-r\00"
@stderr = global i32 0
@.str.2 = [33 x i8] c"usage: %s [-s] [-r] /dev/ttyHS?\0A\00"
@.str.3 = [36 x i8] c" -s send \\n as \\n and not as CRLF\0A\00"
@.str.4 = [31 x i8] c" -r pass \\r and don't ignore\0A\00"
@O_RDWR = global i32 0
@.str.5 = [5 x i8] c"open\00"
@.str.6 = [10 x i8] c"tcgetattr\00"
@CSIZE = global i32 0
@PARENB = global i32 0
@CSTOPB = global i32 0
@CS8 = global i32 0
@ICANON = global i32 0
@ECHO = global i32 0
@ECHOE = global i32 0
@ECHOK = global i32 0
@ECHONL = global i32 0
@INPCK = global i32 0
@ISIG = global i32 0
@IGNBRK = global i32 0
@IGNPAR = global i32 0
@ICRNL = global i32 0
@INLCR = global i32 0
@OPOST = global i32 0
@VMIN = global i64 0
@VTIME = global i64 0
@TCSANOW = global i32 0
@.str.7 = [10 x i8] c"tcsetattr\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 %struct.termios
%10 = alloca i8*
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca [1 x i8]
%15 = alloca i32
%16 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %7
store i32 0, i32* %8
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 0
%19 = load i8*, i8** %18
store i8* %19, i8** %10
br label %20
20: ; preds = %54, %2
%21 = load i8**, i8*** %5
%22 = getelementptr inbounds i8*, i8** %21, i64 1
%23 = load i8*, i8** %22
%24 = icmp ne i8* %23, null
br i1 %24, label %25, label %33
25: ; preds = %20
%26 = load i8**, i8*** %5
%27 = getelementptr inbounds i8*, i8** %26, i64 1
%28 = load i8*, i8** %27
%29 = getelementptr inbounds i8, i8* %28, i64 0
%30 = load i8, i8* %29
%31 = sext i8 %30 to i32
%32 = icmp eq i32 %31, 45
br label %33
33: ; preds = %25, %20
%34 = phi i1 [ false, %20 ], [ %32, %25 ]
br i1 %34, label %35, label %57
35: ; preds = %33
%36 = load i8**, i8*** %5
%37 = getelementptr inbounds i8*, i8** %36, i64 1
%38 = load i8*, i8** %37
%39 = call i64 @strcmp(i8* %38, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%40 = icmp eq i64 %39, 0
br i1 %40, label %41, label %42
41: ; preds = %35
store i32 1, i32* %7
br label %54
42: ; preds = %35
%43 = load i8**, i8*** %5
%44 = getelementptr inbounds i8*, i8** %43, i64 1
%45 = load i8*, i8** %44
%46 = call i64 @strcmp(i8* %45, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%47 = icmp eq i64 %46, 0
br i1 %47, label %48, label %49
48: ; preds = %42
store i32 1, i32* %8
br label %53
49: ; preds = %42
%50 = load i8**, i8*** %5
%51 = getelementptr inbounds i8*, i8** %50, i32 -1
store i8** %51, i8*** %5
%52 = getelementptr inbounds i8*, i8** %50, i64 1
store i8* null, i8** %52
br label %53
53: ; preds = %49, %48
br label %54
54: ; preds = %53, %41
%55 = load i8**, i8*** %5
%56 = getelementptr inbounds i8*, i8** %55, i32 1
store i8** %56, i8*** %5
br label %20
57: ; preds = %33
%58 = load i8**, i8*** %5
%59 = getelementptr inbounds i8*, i8** %58, i64 1
%60 = load i8*, i8** %59
%61 = icmp ne i8* %60, null
br i1 %61, label %70, label %62
62: ; preds = %57
%63 = load i32, i32* @stderr
%64 = load i8*, i8** %10
%65 = call i32 (i32, i8*, ...) @fprintf(i32 %63, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0), i8* %64)
%66 = load i32, i32* @stderr
%67 = call i32 (i32, i8*, ...) @fprintf(i32 %66, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.3, i64 0, i64 0))
%68 = load i32, i32* @stderr
%69 = call i32 (i32, i8*, ...) @fprintf(i32 %68, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.4, i64 0, i64 0))
store i32 1, i32* %3
br label %230
70: ; preds = %57
%71 = load i8**, i8*** %5
%72 = getelementptr inbounds i8*, i8** %71, i64 1
%73 = load i8*, i8** %72
%74 = load i32, i32* @O_RDWR
%75 = call i32 @open(i8* %73, i32 %74)
store i32 %75, i32* %6
%76 = load i32, i32* %6
%77 = icmp slt i32 %76, 0
br i1 %77, label %78, label %80
78: ; preds = %70
%79 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
store i32 1, i32* %3
br label %230
80: ; preds = %70
%81 = load i32, i32* %6
%82 = call i64 @tcgetattr(i32 %81, %struct.termios* %9)
%83 = icmp slt i64 %82, 0
br i1 %83, label %84, label %86
84: ; preds = %80
%85 = call i32 @perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.6, i64 0, i64 0))
store i32 1, i32* %3
br label %230
86: ; preds = %80
%87 = load i32, i32* @CSIZE
%88 = load i32, i32* @PARENB
%89 = or i32 %87, %88
%90 = load i32, i32* @CSTOPB
%91 = or i32 %89, %90
%92 = load i32, i32* @CSIZE
%93 = or i32 %91, %92
%94 = xor i32 %93, -1
%95 = getelementptr inbounds %struct.termios, %struct.termios* %9, i32 0, i32 0
%96 = load i32, i32* %95
%97 = and i32 %96, %94
store i32 %97, i32* %95
%98 = load i32, i32* @CS8
%99 = getelementptr inbounds %struct.termios, %struct.termios* %9, i32 0, i32 0
%100 = load i32, i32* %99
%101 = or i32 %100, %98
store i32 %101, i32* %99
%102 = load i32, i32* @ICANON
%103 = load i32, i32* @ECHO
%104 = or i32 %102, %103
%105 = load i32, i32* @ECHOE
%106 = or i32 %104, %105
%107 = load i32, i32* @ECHOK
%108 = or i32 %106, %107
%109 = load i32, i32* @ECHONL
%110 = or i32 %108, %109
%111 = load i32, i32* @INPCK
%112 = or i32 %110, %111
%113 = load i32, i32* @ISIG
%114 = or i32 %112, %113
%115 = xor i32 %114, -1
%116 = getelementptr inbounds %struct.termios, %struct.termios* %9, i32 0, i32 1
%117 = load i32, i32* %116
%118 = and i32 %117, %115
store i32 %118, i32* %116
%119 = load i32, i32* @IGNBRK
%120 = load i32, i32* @IGNPAR
%121 = or i32 %119, %120
%122 = load i32, i32* @ICRNL
%123 = or i32 %121, %122
%124 = load i32, i32* @INLCR
%125 = or i32 %123, %124
%126 = getelementptr inbounds %struct.termios, %struct.termios* %9, i32 0, i32 2
%127 = load i32, i32* %126
%128 = or i32 %127, %125
store i32 %128, i32* %126
%129 = load i32, i32* @OPOST
%130 = xor i32 %129, -1
%131 = getelementptr inbounds %struct.termios, %struct.termios* %9, i32 0, i32 4
%132 = load i32, i32* %131
%133 = and i32 %132, %130
store i32 %133, i32* %131
%134 = getelementptr inbounds %struct.termios, %struct.termios* %9, i32 0, i32 3
%135 = load i32*, i32** %134
%136 = load i64, i64* @VMIN
%137 = getelementptr inbounds i32, i32* %135, i64 %136
store i32 1, i32* %137
%138 = getelementptr inbounds %struct.termios, %struct.termios* %9, i32 0, i32 3
%139 = load i32*, i32** %138
%140 = load i64, i64* @VTIME
%141 = getelementptr inbounds i32, i32* %139, i64 %140
store i32 0, i32* %141
%142 = load i32, i32* %6
%143 = load i32, i32* @TCSANOW
%144 = call i64 @tcsetattr(i32 %142, i32 %143, %struct.termios* %9)
%145 = icmp slt i64 %144, 0
br i1 %145, label %146, label %148
146: ; preds = %86
%147 = call i32 @perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.7, i64 0, i64 0))
store i32 1, i32* %3
br label %230
148: ; preds = %86
br label %149
149: ; preds = %148, %219, %229
%150 = call i32 @FD_SET(i32 0, i32* %11)
%151 = load i32, i32* %6
%152 = call i32 @FD_SET(i32 %151, i32* %11)
%153 = call i32 @FD_SET(i32 1, i32* %12)
%154 = load i32, i32* %6
%155 = call i32 @FD_SET(i32 %154, i32* %12)
%156 = load i32, i32* %6
%157 = add nsw i32 %156, 1
%158 = call i64 @select(i32 %157, i32* %11, i32* %12, i32* %13, i32* null)
%159 = icmp sgt i64 %158, 0
br i1 %159, label %160, label %229
160: ; preds = %149
%161 = call i64 @FD_ISSET(i32 0, i32* %11)
%162 = icmp ne i64 %161, 0
br i1 %162, label %163, label %197
163: ; preds = %160
%164 = load i32, i32* %6
%165 = call i64 @FD_ISSET(i32 %164, i32* %12)
%166 = icmp ne i64 %165, 0
br i1 %166, label %167, label %197
167: ; preds = %163
%168 = getelementptr inbounds [1 x i8], [1 x i8]* %14, i64 0, i64 0
%169 = call i32 @read(i32 0, i8* %168, i32 1)
store i32 %169, i32* %15
%170 = load i32, i32* %15
%171 = icmp slt i32 %170, 0
br i1 %171, label %172, label %173
172: ; preds = %167
store i32 2, i32* %3
br label %230
173: ; preds = %167
%174 = load i32, i32* %15
%175 = icmp eq i32 %174, 0
br i1 %175, label %176, label %177
176: ; preds = %173
store i32 0, i32* %3
br label %230
177: ; preds = %173
%178 = load i32, i32* %7
%179 = icmp ne i32 %178, 0
br i1 %179, label %192, label %180
180: ; preds = %177
%181 = getelementptr inbounds [1 x i8], [1 x i8]* %14, i64 0, i64 0
%182 = load i8, i8* %181
%183 = sext i8 %182 to i32
%184 = icmp eq i32 %183, 10
br i1 %184, label %185, label %192
185: ; preds = %180
%186 = getelementptr inbounds [1 x i8], [1 x i8]* %14, i64 0, i64 0
store i8 13, i8* %186
%187 = load i32, i32* %6
%188 = getelementptr inbounds [1 x i8], [1 x i8]* %14, i64 0, i64 0
%189 = load i32, i32* %15
%190 = call i32 @write(i32 %187, i8* %188, i32 %189)
%191 = getelementptr inbounds [1 x i8], [1 x i8]* %14, i64 0, i64 0
store i8 10, i8* %191
br label %192
192: ; preds = %185, %180, %177
%193 = load i32, i32* %6
%194 = getelementptr inbounds [1 x i8], [1 x i8]* %14, i64 0, i64 0
%195 = load i32, i32* %15
%196 = call i32 @write(i32 %193, i8* %194, i32 %195)
br label %197
197: ; preds = %192, %163, %160
%198 = load i32, i32* %6
%199 = call i64 @FD_ISSET(i32 %198, i32* %11)
%200 = icmp ne i64 %199, 0
br i1 %200, label %201, label %228
201: ; preds = %197
%202 = call i64 @FD_ISSET(i32 1, i32* %12)
%203 = icmp ne i64 %202, 0
br i1 %203, label %204, label %228
204: ; preds = %201
%205 = load i32, i32* %6
%206 = getelementptr inbounds [1 x i8], [1 x i8]* %14, i64 0, i64 0
%207 = call i32 @read(i32 %205, i8* %206, i32 1)
store i32 %207, i32* %16
%208 = load i32, i32* %16
%209 = icmp slt i32 %208, 0
br i1 %209, label %210, label %211
210: ; preds = %204
store i32 3, i32* %3
br label %230
211: ; preds = %204
%212 = load i32, i32* %8
%213 = icmp ne i32 %212, 0
br i1 %213, label %220, label %214
214: ; preds = %211
%215 = getelementptr inbounds [1 x i8], [1 x i8]* %14, i64 0, i64 0
%216 = load i8, i8* %215
%217 = sext i8 %216 to i32
%218 = icmp eq i32 %217, 13
br i1 %218, label %219, label %220
219: ; preds = %214
br label %149
220: ; preds = %214, %211
%221 = load i32, i32* %16
%222 = icmp sgt i32 %221, 0
br i1 %222, label %223, label %227
223: ; preds = %220
%224 = getelementptr inbounds [1 x i8], [1 x i8]* %14, i64 0, i64 0
%225 = load i32, i32* %16
%226 = call i32 @write(i32 1, i8* %224, i32 %225)
br label %227
227: ; preds = %223, %220
br label %228
228: ; preds = %227, %201, %197
br label %229
229: ; preds = %228, %149
br label %149
230: ; preds = %210, %176, %172, %146, %84, %78, %62
%231 = load i32, i32* %3
ret i32 %231
}

LLVM IR (-O2):
%struct.termios = type { i32, i32, i32, i32*, i32 }
@.str = [3 x i8] c"-s\00"
@.str.1 = [3 x i8] c"-r\00"
@stderr = global i32 0
@.str.2 = [33 x i8] c"usage: %s [-s] [-r] /dev/ttyHS?\0A\00"
@.str.3 = [36 x i8] c" -s send \\n as \\n and not as CRLF\0A\00"
@.str.4 = [31 x i8] c" -r pass \\r and don't ignore\0A\00"
@O_RDWR = global i32 0
@.str.5 = [5 x i8] c"open\00"
@.str.6 = [10 x i8] c"tcgetattr\00"
@CSIZE = global i32 0
@PARENB = global i32 0
@CSTOPB = global i32 0
@CS8 = global i32 0
@ICANON = global i32 0
@ECHO = global i32 0
@ECHOE = global i32 0
@ECHOK = global i32 0
@ECHONL = global i32 0
@INPCK = global i32 0
@ISIG = global i32 0
@IGNBRK = global i32 0
@IGNPAR = global i32 0
@ICRNL = global i32 0
@INLCR = global i32 0
@OPOST = global i32 0
@VMIN = global i64 0
@VTIME = global i64 0
@TCSANOW = global i32 0
@.str.7 = [10 x i8] c"tcsetattr\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.termios
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca [1 x i8]
%8 = bitcast %struct.termios* %3 to i8*
%9 = load i8*, i8** %1
%10 = getelementptr inbounds i8*, i8** %1, i64 1
%11 = load i8*, i8** %10
%12 = icmp eq i8* %11, null
br i1 %12, label %38, label %13
13: ; preds = %2, %30
%14 = phi i8* [ %36, %30 ], [ %11, %2 ]
%15 = phi i8** [ %35, %30 ], [ %10, %2 ]
%16 = phi i8** [ %34, %30 ], [ %1, %2 ]
%17 = phi i32 [ %32, %30 ], [ 0, %2 ]
%18 = phi i32 [ %31, %30 ], [ 0, %2 ]
%19 = load i8, i8* %14
%20 = icmp eq i8 %19, 45
br i1 %20, label %21, label %45
21: ; preds = %13
%22 = tail call i64 @strcmp(i8* %14, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%23 = icmp eq i64 %22, 0
br i1 %23, label %30, label %24
24: ; preds = %21
%25 = load i8*, i8** %15
%26 = tail call i64 @strcmp(i8* %25, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%27 = icmp eq i64 %26, 0
br i1 %27, label %30, label %28
28: ; preds = %24
%29 = getelementptr inbounds i8*, i8** %16, i64 -1
store i8* null, i8** %15
br label %30
30: ; preds = %24, %21, %28
%31 = phi i32 [ %18, %28 ], [ %18, %21 ], [ 1, %24 ]
%32 = phi i32 [ %17, %28 ], [ 1, %21 ], [ %17, %24 ]
%33 = phi i8** [ %29, %28 ], [ %16, %21 ], [ %16, %24 ]
%34 = getelementptr inbounds i8*, i8** %33, i64 1
%35 = getelementptr inbounds i8*, i8** %33, i64 2
%36 = load i8*, i8** %35
%37 = icmp eq i8* %36, null
br i1 %37, label %38, label %13
38: ; preds = %30, %2
%39 = load i32, i32* @stderr
%40 = tail call i32 (i32, i8*, ...) @fprintf(i32 %39, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0), i8* %9)
%41 = load i32, i32* @stderr
%42 = tail call i32 (i32, i8*, ...) @fprintf(i32 %41, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.3, i64 0, i64 0))
%43 = load i32, i32* @stderr
%44 = tail call i32 (i32, i8*, ...) @fprintf(i32 %43, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.4, i64 0, i64 0))
br label %168
45: ; preds = %13
%46 = load i32, i32* @O_RDWR
%47 = tail call i32 @open(i8* %14, i32 %46)
%48 = icmp slt i32 %47, 0
br i1 %48, label %49, label %51
49: ; preds = %45
%50 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
br label %168
51: ; preds = %45
%52 = call i64 @tcgetattr(i32 %47, %struct.termios* %3)
%53 = icmp slt i64 %52, 0
br i1 %53, label %54, label %56
54: ; preds = %51
%55 = call i32 @perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.6, i64 0, i64 0))
br label %168
56: ; preds = %51
%57 = load i32, i32* @CSIZE
%58 = load i32, i32* @PARENB
%59 = or i32 %58, %57
%60 = load i32, i32* @CSTOPB
%61 = or i32 %59, %60
%62 = xor i32 %61, -1
%63 = getelementptr inbounds %struct.termios, %struct.termios* %3, i64 0, i32 0
%64 = load i32, i32* %63
%65 = and i32 %64, %62
%66 = load i32, i32* @CS8
%67 = or i32 %66, %65
store i32 %67, i32* %63
%68 = load i32, i32* @ICANON
%69 = load i32, i32* @ECHO
%70 = or i32 %69, %68
%71 = load i32, i32* @ECHOE
%72 = or i32 %70, %71
%73 = load i32, i32* @ECHOK
%74 = or i32 %72, %73
%75 = load i32, i32* @ECHONL
%76 = or i32 %74, %75
%77 = load i32, i32* @INPCK
%78 = or i32 %76, %77
%79 = load i32, i32* @ISIG
%80 = or i32 %78, %79
%81 = xor i32 %80, -1
%82 = getelementptr inbounds %struct.termios, %struct.termios* %3, i64 0, i32 1
%83 = load i32, i32* %82
%84 = and i32 %83, %81
store i32 %84, i32* %82
%85 = load i32, i32* @IGNBRK
%86 = load i32, i32* @IGNPAR
%87 = or i32 %86, %85
%88 = load i32, i32* @ICRNL
%89 = or i32 %87, %88
%90 = load i32, i32* @INLCR
%91 = or i32 %89, %90
%92 = getelementptr inbounds %struct.termios, %struct.termios* %3, i64 0, i32 2
%93 = load i32, i32* %92
%94 = or i32 %91, %93
store i32 %94, i32* %92
%95 = load i32, i32* @OPOST
%96 = xor i32 %95, -1
%97 = getelementptr inbounds %struct.termios, %struct.termios* %3, i64 0, i32 4
%98 = load i32, i32* %97
%99 = and i32 %98, %96
store i32 %99, i32* %97
%100 = getelementptr inbounds %struct.termios, %struct.termios* %3, i64 0, i32 3
%101 = load i32*, i32** %100
%102 = load i64, i64* @VMIN
%103 = getelementptr inbounds i32, i32* %101, i64 %102
store i32 1, i32* %103
%104 = load i64, i64* @VTIME
%105 = getelementptr inbounds i32, i32* %101, i64 %104
store i32 0, i32* %105
%106 = load i32, i32* @TCSANOW
%107 = call i64 @tcsetattr(i32 %47, i32 %106, %struct.termios* %3)
%108 = icmp slt i64 %107, 0
br i1 %108, label %117, label %109
109: ; preds = %56
%110 = bitcast i32* %4 to i8*
%111 = bitcast i32* %5 to i8*
%112 = bitcast i32* %6 to i8*
%113 = add nuw nsw i32 %47, 1
%114 = getelementptr inbounds [1 x i8], [1 x i8]* %7, i64 0, i64 0
%115 = icmp eq i32 %17, 0
%116 = icmp eq i32 %18, 0
br label %119
117: ; preds = %56
%118 = call i32 @perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.7, i64 0, i64 0))
br label %168
119: ; preds = %165, %109
%120 = call i32 @FD_SET(i32 0, i32* %4)
%121 = call i32 @FD_SET(i32 %47, i32* %4)
%122 = call i32 @FD_SET(i32 1, i32* %5)
%123 = call i32 @FD_SET(i32 %47, i32* %5)
%124 = call i64 @select(i32 %113, i32* %4, i32* %5, i32* %6, i32* null)
%125 = icmp sgt i64 %124, 0
br i1 %125, label %126, label %163
126: ; preds = %119
%127 = call i64 @FD_ISSET(i32 0, i32* %4)
%128 = icmp eq i64 %127, 0
br i1 %128, label %145, label %129
129: ; preds = %126
%130 = call i64 @FD_ISSET(i32 %47, i32* %5)
%131 = icmp eq i64 %130, 0
br i1 %131, label %145, label %132
132: ; preds = %129
%133 = call i32 @read(i32 0, i8* %114, i32 1)
%134 = icmp slt i32 %133, 0
br i1 %134, label %166, label %135
135: ; preds = %132
%136 = icmp eq i32 %133, 0
br i1 %136, label %166, label %137
137: ; preds = %135
%138 = load i8, i8* %114
%139 = icmp eq i8 %138, 10
%140 = select i1 %115, i1 %139, i1 false
br i1 %140, label %141, label %143
141: ; preds = %137
store i8 13, i8* %114
%142 = call i32 @write(i32 %47, i8* %114, i32 %133)
store i8 10, i8* %114
br label %143
143: ; preds = %137, %141
%144 = call i32 @write(i32 %47, i8* %114, i32 %133)
br label %145
145: ; preds = %143, %129, %126
%146 = call i64 @FD_ISSET(i32 %47, i32* %4)
%147 = icmp eq i64 %146, 0
br i1 %147, label %162, label %148
148: ; preds = %145
%149 = call i64 @FD_ISSET(i32 1, i32* %5)
%150 = icmp eq i64 %149, 0
br i1 %150, label %162, label %151
151: ; preds = %148
%152 = call i32 @read(i32 %47, i8* %114, i32 1)
%153 = icmp slt i32 %152, 0
br i1 %153, label %166, label %154
154: ; preds = %151
%155 = load i8, i8* %114
%156 = icmp eq i8 %155, 13
%157 = select i1 %116, i1 %156, i1 false
br i1 %157, label %164, label %158
158: ; preds = %154
%159 = icmp eq i32 %152, 0
br i1 %159, label %162, label %160
160: ; preds = %158
%161 = call i32 @write(i32 1, i8* %114, i32 %152)
br label %162
162: ; preds = %148, %145, %160, %158
br label %163
163: ; preds = %162, %119
br label %165
164: ; preds = %154
br label %165
165: ; preds = %164, %163
br label %119
166: ; preds = %151, %132, %135
%167 = phi i32 [ 0, %135 ], [ 2, %132 ], [ 3, %151 ]
br label %168
168: ; preds = %166, %117, %54, %49, %38
%169 = phi i32 [ 1, %49 ], [ 1, %54 ], [ 1, %117 ], [ 1, %38 ], [ %167, %166 ]
ret i32 %169
}