#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 */
typedef int /*<<< orphan*/ tmpBuffer;
struct termios {
  int c_cflag;
  int c_lflag;
  int /*<<< orphan*/ c_oflag;
  int /*<<< orphan*/ c_iflag;
};

/* Variables and functions */
int /*<<< orphan*/ B19200;
int /*<<< orphan*/ B2400;
int /*<<< orphan*/ B9600;
int CLOCAL;
int CREAD;
int CS8;
int CSIZE;
int CSTOPB;
int ECHO;
int ECHOE;
int /*<<< orphan*/ FIONREAD;
int /*<<< orphan*/ F_SETFL;
int ICANON;
int /*<<< orphan*/ ICRNL;
int /*<<< orphan*/ IGNBRK;
int /*<<< orphan*/ IGNCR;
int /*<<< orphan*/ INLCR;
int ISIG;
int /*<<< orphan*/ IXOFF;
int /*<<< orphan*/ IXON;
int /*<<< orphan*/ OPOST;
int O_NDELAY;
int O_NOCTTY;
int O_NONBLOCK;
int O_RDWR;
int PARENB;
int /*<<< orphan*/ TCSANOW;
int atoi(char *);
int /*<<< orphan*/ cfsetispeed(struct termios *, int /*<<< orphan*/);
int /*<<< orphan*/ cfsetospeed(struct termios *, int /*<<< orphan*/);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ fcntl(int, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int ioctl(int, int /*<<< orphan*/, int *);
int open(char *, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int read(int, unsigned char **, int);
int /*<<< orphan*/ stdout;
int /*<<< orphan*/ tcgetattr(int, struct termios *);
int /*<<< orphan*/ tcsetattr(int, int /*<<< orphan*/, struct termios *);
int /*<<< orphan*/ usleep(int);
int main(int argc, char *argv[]) {
  char *serialPort = "/dev/ttyUSB0";
  char serialPort2[] = "/dev/ttyUSB0";
  int serialSpeed = 2400;
  int serialWait = 3;
  int actualHexTimeout;
  int IOReturn;
  int fd;
  int serialBytes;
  int x;
  int loop;
  int loop2;
  int c;
  int bytesHex = 0;
  int bufferHexCount = 0;
  unsigned char bufferHex[50];
  unsigned char tmpBuffer[40];
  if (argc > 1) {
    serialSpeed = atoi(argv[1]);
  } else {
    serialSpeed = 2400;
  }
  if (argc > 2) {
    serialPort = argv[2];
  } else {
    serialPort = serialPort2;
  }
  if (argc > 3) {
    serialWait = atoi(argv[3]);
  } else {
    serialWait = 40;
  }
  fd = open(serialPort, O_RDWR | O_NOCTTY | O_NDELAY | O_NONBLOCK);
  if (fd == -1) {
    perror("Unable to open serial-port");
    return (-1);
  } else {
    fcntl(fd, F_SETFL, 0);
  }
  struct termios options;
  tcgetattr(fd, &options);
  if (serialSpeed == 2400) {
    printf("2.400\n");
    cfsetispeed(&options, B2400);
    cfsetospeed(&options, B2400);
  }
  if (serialSpeed == 9600) {
    printf("9.600\n");
    cfsetispeed(&options, B9600);
    cfsetospeed(&options, B9600);
  }
  if (serialSpeed == 19200) {
    printf("19.200\n");
    cfsetispeed(&options, B19200);
    cfsetospeed(&options, B19200);
  }
  options.c_cflag |= (CLOCAL | CREAD);
  options.c_cflag &= ~CSIZE;
  options.c_cflag |= CS8;
  options.c_cflag &= ~PARENB;
  options.c_cflag &= ~CSTOPB;
  options.c_cflag &= ~CSIZE;
  options.c_cflag |= CS8;
  options.c_iflag &= ~IXON;
  options.c_iflag &= ~IXOFF;
  options.c_iflag &= ~IGNCR;
  options.c_iflag &= ~ICRNL;
  options.c_iflag &= ~INLCR;
  options.c_iflag |= IGNBRK;
  options.c_oflag &= ~OPOST;
  options.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG);
  tcsetattr(fd, TCSANOW, &options);
  for (loop = 0;; loop++) {
    if (loop >= 0x80000000) {
      loop = 0;
    }
    IOReturn = ioctl(fd, FIONREAD, &serialBytes);
    if (IOReturn < 0) {
      perror("ioctl(hex)");
      if (actualHexTimeout > 0)
        actualHexTimeout--;
    }
    if (IOReturn == 0) {
      if ((serialBytes == 0) && (actualHexTimeout > 0)) {
        actualHexTimeout--;
      }
      if (serialBytes > 0) {
        if ((actualHexTimeout == 0) && (bufferHexCount == 0)) {
          actualHexTimeout = serialWait;
        }
        if ((actualHexTimeout >= 0) && (bufferHexCount >= 0)) {
          actualHexTimeout = serialWait;
        }
        bytesHex = read(fd, &tmpBuffer, sizeof(tmpBuffer));
        if (bytesHex < 0) {
          perror("read(Hex)");
        }
        if (bytesHex <= 0) {
          actualHexTimeout--;
        }
        if (bytesHex > 0) {
          for (loop2 = 0; loop2 < bytesHex; loop2++) {
            bufferHex[bufferHexCount + loop2] = tmpBuffer[loop2];
          }
          bufferHexCount += bytesHex;
        }
      }
      if ((actualHexTimeout == 0) && (bufferHexCount > 0)) {
        printf("\n\033[1m%6d.%03d Hex:\033[0m ", loop / 2000,
               (loop / 2) % 1000);
        for (x = 0; x < (bufferHexCount - 1); x++) {
          c = bufferHex[x];
          printf("%02X ", c);
        }
        c = bufferHex[bufferHexCount - 1];
        printf("%02X ", c);
        bufferHexCount = 0;
        fflush(stdout);
      }
    }
    usleep(500);
  }
  close(fd);
  printf("<serial port closed!\n");
  return (0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xd0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe10(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    0xe05(%rip),%rax
mov    %rax,-0x25(%rbp)
mov    0xe03(%rip),%eax
mov    %eax,-0x1d(%rbp)
mov    0xdfe(%rip),%al
mov    %al,-0x19(%rbp)
movl   $0x960,-0x2c(%rbp)
movl   $0x3,-0x30(%rbp)
movl   $0x0,-0x54(%rbp)
movl   $0x0,-0x58(%rbp)
cmpl   $0x1,-0x8(%rbp)
jle    124c <main+0x7c>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   10e0 <atoi@plt>
mov    %eax,-0x2c(%rbp)
jmp    1253 <main+0x83>
movl   $0x960,-0x2c(%rbp)
cmpl   $0x2,-0x8(%rbp)
jle    126e <main+0x9e>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x18(%rbp)
jmp    1276 <main+0xa6>
lea    -0x25(%rbp),%rax
mov    %rax,-0x18(%rbp)
cmpl   $0x3,-0x8(%rbp)
jle    1295 <main+0xc5>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
call   10e0 <atoi@plt>
mov    %eax,-0x30(%rbp)
jmp    129c <main+0xcc>
movl   $0x28,-0x30(%rbp)
mov    -0x18(%rbp),%rdi
mov    0x2d39(%rip),%rax
mov    (%rax),%esi
mov    0x2c98(%rip),%rax
or     (%rax),%esi
mov    0x2c77(%rip),%rax
or     (%rax),%esi
mov    0x2cf6(%rip),%rax
or     (%rax),%esi
call   10b0 <open@plt>
mov    %eax,-0x3c(%rbp)
cmpl   $0xffffffff,-0x3c(%rbp)
jne    12f0 <main+0x120>
lea    0xd30(%rip),%rdi
call   10d0 <perror@plt>
mov    $0xffffffff,%eax
add    $0xd0,%rsp
pop    %rbp
ret
mov    -0x3c(%rbp),%edi
mov    0x2c3e(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1030 <fcntl@plt>
mov    -0x3c(%rbp),%edi
lea    -0xd0(%rbp),%rsi
call   1090 <tcgetattr@plt>
cmpl   $0x960,-0x2c(%rbp)
jne    1357 <main+0x187>
lea    0xd02(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    0x2c0c(%rip),%rax
mov    (%rax),%esi
lea    -0xd0(%rbp),%rdi
call   10c0 <cfsetispeed@plt>
mov    0x2bf7(%rip),%rax
mov    (%rax),%esi
lea    -0xd0(%rbp),%rdi
call   1040 <cfsetospeed@plt>
cmpl   $0x2580,-0x2c(%rbp)
jne    139c <main+0x1cc>
lea    0xcc4(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    0x2bf7(%rip),%rax
mov    (%rax),%esi
lea    -0xd0(%rbp),%rdi
call   10c0 <cfsetispeed@plt>
mov    0x2be2(%rip),%rax
mov    (%rax),%esi
lea    -0xd0(%rbp),%rdi
call   1040 <cfsetospeed@plt>
cmpl   $0x4b00,-0x2c(%rbp)
jne    13e1 <main+0x211>
lea    0xc86(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    0x2c32(%rip),%rax
mov    (%rax),%esi
lea    -0xd0(%rbp),%rdi
call   10c0 <cfsetispeed@plt>
mov    0x2c1d(%rip),%rax
mov    (%rax),%esi
lea    -0xd0(%rbp),%rdi
call   1040 <cfsetospeed@plt>
mov    0x2b18(%rip),%rax
mov    (%rax),%eax
mov    0x2b77(%rip),%rcx
or     (%rcx),%eax
or     -0xd0(%rbp),%eax
mov    %eax,-0xd0(%rbp)
mov    0x2b52(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0xd0(%rbp),%eax
mov    %eax,-0xd0(%rbp)
mov    0x2b42(%rip),%rax
mov    (%rax),%eax
or     -0xd0(%rbp),%eax
mov    %eax,-0xd0(%rbp)
mov    0x2b65(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0xd0(%rbp),%eax
mov    %eax,-0xd0(%rbp)
mov    0x2abd(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0xd0(%rbp),%eax
mov    %eax,-0xd0(%rbp)
mov    0x2af5(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0xd0(%rbp),%eax
mov    %eax,-0xd0(%rbp)
mov    0x2ae5(%rip),%rax
mov    (%rax),%eax
or     -0xd0(%rbp),%eax
mov    %eax,-0xd0(%rbp)
mov    0x2b10(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0xc4(%rbp),%eax
mov    %eax,-0xc4(%rbp)
mov    0x2b18(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0xc4(%rbp),%eax
mov    %eax,-0xc4(%rbp)
mov    0x2af0(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0xc4(%rbp),%eax
mov    %eax,-0xc4(%rbp)
mov    0x2af8(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0xc4(%rbp),%eax
mov    %eax,-0xc4(%rbp)
mov    0x2ad8(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0xc4(%rbp),%eax
mov    %eax,-0xc4(%rbp)
mov    0x2a18(%rip),%rax
mov    (%rax),%eax
or     -0xc4(%rbp),%eax
mov    %eax,-0xc4(%rbp)
mov    0x2a8b(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0xc8(%rbp),%eax
mov    %eax,-0xc8(%rbp)
mov    0x29e3(%rip),%rax
mov    (%rax),%eax
mov    0x2a4a(%rip),%rcx
or     (%rcx),%eax
mov    0x2a39(%rip),%rcx
or     (%rcx),%eax
mov    0x2a28(%rip),%rcx
or     (%rcx),%eax
xor    $0xffffffff,%eax
and    -0xcc(%rbp),%eax
mov    %eax,-0xcc(%rbp)
mov    -0x3c(%rbp),%edi
mov    0x2a25(%rip),%rax
mov    (%rax),%esi
lea    -0xd0(%rbp),%rdx
call   10a0 <tcsetattr@plt>
movl   $0x0,-0x48(%rbp)
cmpl   $0x80000000,-0x48(%rbp)
jb     1594 <main+0x3c4>
movl   $0x0,-0x48(%rbp)
mov    -0x3c(%rbp),%edi
mov    0x2a3a(%rip),%rax
mov    (%rax),%esi
lea    -0x40(%rbp),%rdx
call   1060 <ioctl@plt>
mov    %eax,-0x38(%rbp)
cmpl   $0x0,-0x38(%rbp)
jge    15da <main+0x40a>
lea    0xa81(%rip),%rdi
call   10d0 <perror@plt>
cmpl   $0x0,-0x34(%rbp)
jle    15d5 <main+0x405>
mov    -0x34(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x34(%rbp)
jmp    15da <main+0x40a>
cmpl   $0x0,-0x38(%rbp)
jne    1798 <main+0x5c8>
cmpl   $0x0,-0x40(%rbp)
jne    1601 <main+0x431>
cmpl   $0x0,-0x34(%rbp)
jle    1601 <main+0x431>
mov    -0x34(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x34(%rbp)
cmpl   $0x0,-0x40(%rbp)
jle    16d2 <main+0x502>
cmpl   $0x0,-0x34(%rbp)
jne    1625 <main+0x455>
cmpl   $0x0,-0x58(%rbp)
jne    1625 <main+0x455>
mov    -0x30(%rbp),%eax
mov    %eax,-0x34(%rbp)
cmpl   $0x0,-0x34(%rbp)
jl     163f <main+0x46f>
cmpl   $0x0,-0x58(%rbp)
jl     163f <main+0x46f>
mov    -0x30(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    -0x3c(%rbp),%edi
lea    -0xc0(%rbp),%rsi
mov    $0x28,%edx
call   1070 <read@plt>
mov    %eax,-0x54(%rbp)
cmpl   $0x0,-0x54(%rbp)
jge    166c <main+0x49c>
lea    0x9e2(%rip),%rdi
call   10d0 <perror@plt>
cmpl   $0x0,-0x54(%rbp)
jg     167f <main+0x4af>
mov    -0x34(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x34(%rbp)
cmpl   $0x0,-0x54(%rbp)
jle    16cd <main+0x4fd>
movl   $0x0,-0x4c(%rbp)
mov    -0x4c(%rbp),%eax
cmp    -0x54(%rbp),%eax
jge    16c4 <main+0x4f4>
movslq -0x4c(%rbp),%rax
mov    -0xc0(%rbp,%rax,1),%cl
mov    -0x58(%rbp),%eax
add    -0x4c(%rbp),%eax
cltq
mov    %cl,-0x90(%rbp,%rax,1)
mov    -0x4c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4c(%rbp)
jmp    1690 <main+0x4c0>
mov    -0x54(%rbp),%eax
add    -0x58(%rbp),%eax
mov    %eax,-0x58(%rbp)
jmp    16d2 <main+0x502>
cmpl   $0x0,-0x34(%rbp)
jne    1793 <main+0x5c3>
cmpl   $0x0,-0x58(%rbp)
jle    1793 <main+0x5c3>
mov    -0x48(%rbp),%eax
mov    $0x7d0,%ecx
cltd
idiv   %ecx
mov    %eax,%esi
mov    -0x48(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    $0x3e8,%ecx
cltd
idiv   %ecx
lea    0x946(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0x44(%rbp)
mov    -0x44(%rbp),%eax
mov    -0x58(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    175a <main+0x58a>
movslq -0x44(%rbp),%rax
movzbl -0x90(%rbp,%rax,1),%eax
ff
mov    %eax,-0x50(%rbp)
mov    -0x50(%rbp),%esi
lea    0x926(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x44(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x44(%rbp)
jmp    171b <main+0x54b>
mov    -0x58(%rbp),%eax
sub    $0x1,%eax
cltq
movzbl -0x90(%rbp,%rax,1),%eax
ff
mov    %eax,-0x50(%rbp)
mov    -0x50(%rbp),%esi
lea    0x8f4(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0x58(%rbp)
mov    0x279c(%rip),%rax
mov    (%rax),%edi
call   1080 <fflush@plt>
jmp    1798 <main+0x5c8>
mov    $0x1f4,%edi
call   10f0 <usleep@plt>
mov    -0x48(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x48(%rbp)
jmp    1580 <main+0x3b0>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x98,%rsp
lea    0x20(%rsp),%r15
movabs $0x30425355797474,%rax
mov    %rax,0x25(%rsp)
movabs $0x7974742f7665642f,%rax
74 74 79
mov    %rax,0x20(%rsp)
movl   $0x28,0x4(%rsp)
mov    $0x960,%r12d
cmp    $0x2,%edi
jl     1263 <main+0x73>
mov    %rsi,%rbp
mov    %edi,%ebx
mov    0x8(%rsi),%rdi
call   1100 <atoi@plt>
mov    %eax,%r12d
cmp    $0x2,%ebx
je     1263 <main+0x73>
mov    0x10(%rbp),%r15
cmp    $0x4,%ebx
jb     1263 <main+0x73>
mov    0x18(%rbp),%rdi
call   1100 <atoi@plt>
mov    %eax,0x4(%rsp)
mov    0x2d76(%rip),%rax
mov    0x2cd7(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2cb4(%rip),%rax
or     (%rax),%esi
mov    0x2d33(%rip),%rax
or     (%rax),%esi
mov    %r15,%rdi
call   10d0 <open@plt>
cmp    $0xffffffff,%eax
je     158b <main+0x39b>
mov    %eax,%ebx
mov    0x2c97(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edi
xor    %edx,%edx
call   1040 <fcntl@plt>
lea    0x8(%rsp),%rsi
mov    %ebx,%ebp
mov    %ebx,%edi
call   10b0 <tcgetattr@plt>
cmp    $0x960,%r12d
je     12e8 <main+0xf8>
cmp    $0x4b00,%r12d
je     12f8 <main+0x108>
cmp    $0x2580,%r12d
mov    %ebp,%r12d
jne    1327 <main+0x137>
mov    0x2c91(%rip),%rbx
lea    0xd7c(%rip),%rdi
jmp    1309 <main+0x119>
mov    0x2c51(%rip),%rbx
lea    0xd72(%rip),%rdi
jmp    1306 <main+0x116>
mov    0x2cf1(%rip),%rbx
lea    0xd55(%rip),%rdi
mov    %ebp,%r12d
call   1030 <puts@plt>
mov    (%rbx),%esi
lea    0x8(%rsp),%r14
mov    %r14,%rdi
call   10e0 <cfsetispeed@plt>
mov    (%rbx),%esi
mov    %r14,%rdi
call   1050 <cfsetospeed@plt>
mov    0x2bd2(%rip),%rax
mov    0x2c33(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
or     0x8(%rsp),%ecx
mov    0x2c14(%rip),%rax
mov    0x2c15(%rip),%rdx
mov    0x2bb6(%rip),%rsi
mov    (%rsi),%esi
or     (%rax),%esi
mov    0x2c3b(%rip),%rax
or     (%rax),%esi
not    %esi
and    %ecx,%esi
or     (%rdx),%esi
mov    0x2c34(%rip),%rax
mov    (%rax),%eax
mov    0x2c4b(%rip),%rcx
or     (%rcx),%eax
mov    0x2c32(%rip),%rcx
or     (%rcx),%eax
mov    0x2c49(%rip),%rcx
or     (%rcx),%eax
mov    0x2c38(%rip),%rcx
or     (%rcx),%eax
mov    %esi,0x8(%rsp)
not    %eax
and    0x14(%rsp),%eax
mov    0x2b7d(%rip),%rcx
or     (%rcx),%eax
mov    %eax,0x14(%rsp)
mov    0x2bf8(%rip),%rax
mov    (%rax),%eax
not    %eax
and    %eax,0x10(%rsp)
mov    0x2b59(%rip),%rax
mov    0x2bc2(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
mov    0x2baf(%rip),%rax
or     (%rax),%ecx
mov    0x2b9e(%rip),%rax
or     (%rax),%ecx
not    %ecx
and    %ecx,0xc(%rsp)
mov    0x2ba7(%rip),%rax
mov    (%rax),%esi
lea    0x8(%rsp),%rdx
mov    %r12d,%edi
call   10c0 <tcsetattr@plt>
mov    0x2bd9(%rip),%rbp
lea    0xc4f(%rip),%r13
xor    %r15d,%r15d
xor    %r14d,%r14d
mov    %r12d,(%rsp)
jmp    1443 <main+0x253>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
lea    0xc01(%rip),%rdi
call   10f0 <perror@plt>
xor    %eax,%eax
test   %ebx,%ebx
setg   %al
sub    %eax,%ebx
mov    $0x1f4,%edi
call   1110 <usleep@plt>
add    $0x1,%r15d
mov    0x0(%rbp),%esi
mov    %r12d,%edi
lea    0x1c(%rsp),%rdx
call   1070 <ioctl@plt>
test   %eax,%eax
js     1420 <main+0x230>
jne    1435 <main+0x245>
mov    0x1c(%rsp),%eax
test   %eax,%eax
sete   %cl
test   %ebx,%ebx
setg   %dl
and    %cl,%dl
movzbl %dl,%ecx
sub    %ecx,%ebx
test   %eax,%eax
jle    14e3 <main+0x2f3>
mov    %ebx,%eax
or     %r14d,%eax
mov    0x4(%rsp),%ecx
cmove  %ecx,%ebx
mov    %ebx,%eax
or     %r14d,%eax
cmovns %ecx,%ebx
mov    %r12d,%edi
lea    0x70(%rsp),%rsi
mov    $0x28,%edx
call   1080 <read@plt>
test   %eax,%eax
jns    14ad <main+0x2bd>
lea    0xb90(%rip),%rdi
call   10f0 <perror@plt>
add    $0xffffffff,%ebx
jmp    14d8 <main+0x2e8>
mov    %eax,%r12d
sete   %al
movzbl %al,%eax
sub    %eax,%ebx
test   %r12d,%r12d
je     14d8 <main+0x2e8>
movslq %r14d,%rax
lea    (%rsp,%rax,1),%rdi
add    $0x30,%rdi
mov    %r12d,%edx
lea    0x70(%rsp),%rsi
call   1090 <memcpy@plt>
add    %r12d,%r14d
mov    0x2af9(%rip),%rbp
mov    (%rsp),%r12d
test   %ebx,%ebx
jne    1435 <main+0x245>
test   %r14d,%r14d
jle    1435 <main+0x245>
mov    %r15d,%eax
imul   $0x10624dd3,%rax,%rsi
shr    $0x27,%rsi
mov    %r15d,%edx
shr    %edx
imul   $0x10624dd3,%rdx,%rax
shr    $0x26,%rax
imul   $0x3e8,%eax,%eax
sub    %eax,%edx
lea    0xb1c(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
movslq %r14d,%r12
add    $0xffffffffffffffff,%r12
cmp    $0x2,%r14d
jb     1558 <main+0x368>
mov    %r12d,%ebp
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
movzbl 0x30(%rsp,%rbx,1),%esi
mov    %r13,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    1540 <main+0x350>
movzbl 0x30(%rsp,%r12,1),%esi
xor    %ebx,%ebx
mov    %r13,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    0x29b7(%rip),%rax
mov    (%rax),%edi
call   10a0 <fflush@plt>
xor    %r14d,%r14d
mov    (%rsp),%r12d
mov    0x2a52(%rip),%rbp
jmp    1435 <main+0x245>
lea    0xa7b(%rip),%rdi
call   10f0 <perror@plt>
mov    $0xffffffff,%eax
add    $0x98,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.termios = type { i32, i32, i32, i32 }
@.str = [13 x i8] c"/dev/ttyUSB0\00"
@__const.main.serialPort2 = [13 x i8] c"/dev/ttyUSB0\00"
@O_RDWR = global i32 0
@O_NOCTTY = global i32 0
@O_NDELAY = global i32 0
@O_NONBLOCK = global i32 0
@.str.1 = [27 x i8] c"Unable to open serial-port\00"
@F_SETFL = global i32 0
@.str.2 = [7 x i8] c"2.400\0A\00"
@B2400 = global i32 0
@.str.3 = [7 x i8] c"9.600\0A\00"
@B9600 = global i32 0
@.str.4 = [8 x i8] c"19.200\0A\00"
@B19200 = global i32 0
@CLOCAL = global i32 0
@CREAD = global i32 0
@CSIZE = global i32 0
@CS8 = global i32 0
@PARENB = global i32 0
@CSTOPB = global i32 0
@IXON = global i32 0
@IXOFF = global i32 0
@IGNCR = global i32 0
@ICRNL = global i32 0
@INLCR = global i32 0
@IGNBRK = global i32 0
@OPOST = global i32 0
@ICANON = global i32 0
@ECHO = global i32 0
@ECHOE = global i32 0
@ISIG = global i32 0
@TCSANOW = global i32 0
@FIONREAD = global i32 0
@.str.5 = [11 x i8] c"ioctl(hex)\00"
@.str.6 = [10 x i8] c"read(Hex)\00"
@.str.7 = [24 x i8] c"\0A\1B[1m%6d.%03d Hex:\1B[0m \00"
@.str.8 = [6 x i8] c"%02X \00"
@stdout = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca [13 x i8]
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
%16 = alloca i32
%17 = alloca i32
%18 = alloca i32
%19 = alloca i32
%20 = alloca [50 x i8]
%21 = alloca [40 x i8]
%22 = alloca %struct.termios
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8** %6
%23 = bitcast [13 x i8]* %7 to i8*
store i32 2400, i32* %8
store i32 3, i32* %9
store i32 0, i32* %18
store i32 0, i32* %19
%24 = load i32, i32* %4
%25 = icmp sgt i32 %24, 1
br i1 %25, label %26, label %31
26: ; preds = %2
%27 = load i8**, i8*** %5
%28 = getelementptr inbounds i8*, i8** %27, i64 1
%29 = load i8*, i8** %28
%30 = call i32 @atoi(i8* %29)
store i32 %30, i32* %8
br label %32
31: ; preds = %2
store i32 2400, i32* %8
br label %32
32: ; preds = %31, %26
%33 = load i32, i32* %4
%34 = icmp sgt i32 %33, 2
br i1 %34, label %35, label %39
35: ; preds = %32
%36 = load i8**, i8*** %5
%37 = getelementptr inbounds i8*, i8** %36, i64 2
%38 = load i8*, i8** %37
store i8* %38, i8** %6
br label %41
39: ; preds = %32
%40 = getelementptr inbounds [13 x i8], [13 x i8]* %7, i64 0, i64 0
store i8* %40, i8** %6
br label %41
41: ; preds = %39, %35
%42 = load i32, i32* %4
%43 = icmp sgt i32 %42, 3
br i1 %43, label %44, label %49
44: ; preds = %41
%45 = load i8**, i8*** %5
%46 = getelementptr inbounds i8*, i8** %45, i64 3
%47 = load i8*, i8** %46
%48 = call i32 @atoi(i8* %47)
store i32 %48, i32* %9
br label %50
49: ; preds = %41
store i32 40, i32* %9
br label %50
50: ; preds = %49, %44
%51 = load i8*, i8** %6
%52 = load i32, i32* @O_RDWR
%53 = load i32, i32* @O_NOCTTY
%54 = or i32 %52, %53
%55 = load i32, i32* @O_NDELAY
%56 = or i32 %54, %55
%57 = load i32, i32* @O_NONBLOCK
%58 = or i32 %56, %57
%59 = call i32 @open(i8* %51, i32 %58)
store i32 %59, i32* %12
%60 = load i32, i32* %12
%61 = icmp eq i32 %60, -1
br i1 %61, label %62, label %64
62: ; preds = %50
%63 = call i32 @perror(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0))
ret i32 -1
64: ; preds = %50
%65 = load i32, i32* %12
%66 = load i32, i32* @F_SETFL
%67 = call i32 @fcntl(i32 %65, i32 %66, i32 0)
br label %68
68: ; preds = %64
%69 = load i32, i32* %12
%70 = call i32 @tcgetattr(i32 %69, %struct.termios* %22)
%71 = load i32, i32* %8
%72 = icmp eq i32 %71, 2400
br i1 %72, label %73, label %79
73: ; preds = %68
%74 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%75 = load i32, i32* @B2400
%76 = call i32 @cfsetispeed(%struct.termios* %22, i32 %75)
%77 = load i32, i32* @B2400
%78 = call i32 @cfsetospeed(%struct.termios* %22, i32 %77)
br label %79
79: ; preds = %73, %68
%80 = load i32, i32* %8
%81 = icmp eq i32 %80, 9600
br i1 %81, label %82, label %88
82: ; preds = %79
%83 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
%84 = load i32, i32* @B9600
%85 = call i32 @cfsetispeed(%struct.termios* %22, i32 %84)
%86 = load i32, i32* @B9600
%87 = call i32 @cfsetospeed(%struct.termios* %22, i32 %86)
br label %88
88: ; preds = %82, %79
%89 = load i32, i32* %8
%90 = icmp eq i32 %89, 19200
br i1 %90, label %91, label %97
91: ; preds = %88
%92 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0))
%93 = load i32, i32* @B19200
%94 = call i32 @cfsetispeed(%struct.termios* %22, i32 %93)
%95 = load i32, i32* @B19200
%96 = call i32 @cfsetospeed(%struct.termios* %22, i32 %95)
br label %97
97: ; preds = %91, %88
%98 = load i32, i32* @CLOCAL
%99 = load i32, i32* @CREAD
%100 = or i32 %98, %99
%101 = getelementptr inbounds %struct.termios, %struct.termios* %22, i32 0, i32 0
%102 = load i32, i32* %101
%103 = or i32 %102, %100
store i32 %103, i32* %101
%104 = load i32, i32* @CSIZE
%105 = xor i32 %104, -1
%106 = getelementptr inbounds %struct.termios, %struct.termios* %22, i32 0, i32 0
%107 = load i32, i32* %106
%108 = and i32 %107, %105
store i32 %108, i32* %106
%109 = load i32, i32* @CS8
%110 = getelementptr inbounds %struct.termios, %struct.termios* %22, i32 0, i32 0
%111 = load i32, i32* %110
%112 = or i32 %111, %109
store i32 %112, i32* %110
%113 = load i32, i32* @PARENB
%114 = xor i32 %113, -1
%115 = getelementptr inbounds %struct.termios, %struct.termios* %22, i32 0, i32 0
%116 = load i32, i32* %115
%117 = and i32 %116, %114
store i32 %117, i32* %115
%118 = load i32, i32* @CSTOPB
%119 = xor i32 %118, -1
%120 = getelementptr inbounds %struct.termios, %struct.termios* %22, i32 0, i32 0
%121 = load i32, i32* %120
%122 = and i32 %121, %119
store i32 %122, i32* %120
%123 = load i32, i32* @CSIZE
%124 = xor i32 %123, -1
%125 = getelementptr inbounds %struct.termios, %struct.termios* %22, i32 0, i32 0
%126 = load i32, i32* %125
%127 = and i32 %126, %124
store i32 %127, i32* %125
%128 = load i32, i32* @CS8
%129 = getelementptr inbounds %struct.termios, %struct.termios* %22, i32 0, i32 0
%130 = load i32, i32* %129
%131 = or i32 %130, %128
store i32 %131, i32* %129
%132 = load i32, i32* @IXON
%133 = xor i32 %132, -1
%134 = getelementptr inbounds %struct.termios, %struct.termios* %22, i32 0, i32 3
%135 = load i32, i32* %134
%136 = and i32 %135, %133
store i32 %136, i32* %134
%137 = load i32, i32* @IXOFF
%138 = xor i32 %137, -1
%139 = getelementptr inbounds %struct.termios, %struct.termios* %22, i32 0, i32 3
%140 = load i32, i32* %139
%141 = and i32 %140, %138
store i32 %141, i32* %139
%142 = load i32, i32* @IGNCR
%143 = xor i32 %142, -1
%144 = getelementptr inbounds %struct.termios, %struct.termios* %22, i32 0, i32 3
%145 = load i32, i32* %144
%146 = and i32 %145, %143
store i32 %146, i32* %144
%147 = load i32, i32* @ICRNL
%148 = xor i32 %147, -1
%149 = getelementptr inbounds %struct.termios, %struct.termios* %22, i32 0, i32 3
%150 = load i32, i32* %149
%151 = and i32 %150, %148
store i32 %151, i32* %149
%152 = load i32, i32* @INLCR
%153 = xor i32 %152, -1
%154 = getelementptr inbounds %struct.termios, %struct.termios* %22, i32 0, i32 3
%155 = load i32, i32* %154
%156 = and i32 %155, %153
store i32 %156, i32* %154
%157 = load i32, i32* @IGNBRK
%158 = getelementptr inbounds %struct.termios, %struct.termios* %22, i32 0, i32 3
%159 = load i32, i32* %158
%160 = or i32 %159, %157
store i32 %160, i32* %158
%161 = load i32, i32* @OPOST
%162 = xor i32 %161, -1
%163 = getelementptr inbounds %struct.termios, %struct.termios* %22, i32 0, i32 2
%164 = load i32, i32* %163
%165 = and i32 %164, %162
store i32 %165, i32* %163
%166 = load i32, i32* @ICANON
%167 = load i32, i32* @ECHO
%168 = or i32 %166, %167
%169 = load i32, i32* @ECHOE
%170 = or i32 %168, %169
%171 = load i32, i32* @ISIG
%172 = or i32 %170, %171
%173 = xor i32 %172, -1
%174 = getelementptr inbounds %struct.termios, %struct.termios* %22, i32 0, i32 1
%175 = load i32, i32* %174
%176 = and i32 %175, %173
store i32 %176, i32* %174
%177 = load i32, i32* %12
%178 = load i32, i32* @TCSANOW
%179 = call i32 @tcsetattr(i32 %177, i32 %178, %struct.termios* %22)
store i32 0, i32* %15
br label %180
180: ; preds = %312, %97
%181 = load i32, i32* %15
%182 = icmp uge i32 %181, -2147483648
br i1 %182, label %183, label %184
183: ; preds = %180
store i32 0, i32* %15
br label %184
184: ; preds = %183, %180
%185 = load i32, i32* %12
%186 = load i32, i32* @FIONREAD
%187 = call i32 @ioctl(i32 %185, i32 %186, i32* %13)
store i32 %187, i32* %11
%188 = load i32, i32* %11
%189 = icmp slt i32 %188, 0
br i1 %189, label %190, label %198
190: ; preds = %184
%191 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.5, i64 0, i64 0))
%192 = load i32, i32* %10
%193 = icmp sgt i32 %192, 0
br i1 %193, label %194, label %197
194: ; preds = %190
%195 = load i32, i32* %10
%196 = add nsw i32 %195, -1
store i32 %196, i32* %10
br label %197
197: ; preds = %194, %190
br label %198
198: ; preds = %197, %184
%199 = load i32, i32* %11
%200 = icmp eq i32 %199, 0
br i1 %200, label %201, label %310
201: ; preds = %198
%202 = load i32, i32* %13
%203 = icmp eq i32 %202, 0
br i1 %203, label %204, label %210
204: ; preds = %201
%205 = load i32, i32* %10
%206 = icmp sgt i32 %205, 0
br i1 %206, label %207, label %210
207: ; preds = %204
%208 = load i32, i32* %10
%209 = add nsw i32 %208, -1
store i32 %209, i32* %10
br label %210
210: ; preds = %207, %204, %201
%211 = load i32, i32* %13
%212 = icmp sgt i32 %211, 0
br i1 %212, label %213, label %269
213: ; preds = %210
%214 = load i32, i32* %10
%215 = icmp eq i32 %214, 0
br i1 %215, label %216, label %221
216: ; preds = %213
%217 = load i32, i32* %19
%218 = icmp eq i32 %217, 0
br i1 %218, label %219, label %221
219: ; preds = %216
%220 = load i32, i32* %9
store i32 %220, i32* %10
br label %221
221: ; preds = %219, %216, %213
%222 = load i32, i32* %10
%223 = icmp sge i32 %222, 0
br i1 %223, label %224, label %229
224: ; preds = %221
%225 = load i32, i32* %19
%226 = icmp sge i32 %225, 0
br i1 %226, label %227, label %229
227: ; preds = %224
%228 = load i32, i32* %9
store i32 %228, i32* %10
br label %229
229: ; preds = %227, %224, %221
%230 = load i32, i32* %12
%231 = bitcast [40 x i8]* %21 to i8**
%232 = call i32 @read(i32 %230, i8** %231, i32 40)
store i32 %232, i32* %18
%233 = load i32, i32* %18
%234 = icmp slt i32 %233, 0
br i1 %234, label %235, label %237
235: ; preds = %229
%236 = call i32 @perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.6, i64 0, i64 0))
br label %237
237: ; preds = %235, %229
%238 = load i32, i32* %18
%239 = icmp sle i32 %238, 0
br i1 %239, label %240, label %243
240: ; preds = %237
%241 = load i32, i32* %10
%242 = add nsw i32 %241, -1
store i32 %242, i32* %10
br label %243
243: ; preds = %240, %237
%244 = load i32, i32* %18
%245 = icmp sgt i32 %244, 0
br i1 %245, label %246, label %268
246: ; preds = %243
store i32 0, i32* %16
br label %247
247: ; preds = %261, %246
%248 = load i32, i32* %16
%249 = load i32, i32* %18
%250 = icmp slt i32 %248, %249
br i1 %250, label %251, label %264
251: ; preds = %247
%252 = load i32, i32* %16
%253 = sext i32 %252 to i64
%254 = getelementptr inbounds [40 x i8], [40 x i8]* %21, i64 0, i64 %253
%255 = load i8, i8* %254
%256 = load i32, i32* %19
%257 = load i32, i32* %16
%258 = add nsw i32 %256, %257
%259 = sext i32 %258 to i64
%260 = getelementptr inbounds [50 x i8], [50 x i8]* %20, i64 0, i64 %259
store i8 %255, i8* %260
br label %261
261: ; preds = %251
%262 = load i32, i32* %16
%263 = add nsw i32 %262, 1
store i32 %263, i32* %16
br label %247
264: ; preds = %247
%265 = load i32, i32* %18
%266 = load i32, i32* %19
%267 = add nsw i32 %266, %265
store i32 %267, i32* %19
br label %268
268: ; preds = %264, %243
br label %269
269: ; preds = %268, %210
%270 = load i32, i32* %10
%271 = icmp eq i32 %270, 0
br i1 %271, label %272, label %309
272: ; preds = %269
%273 = load i32, i32* %19
%274 = icmp sgt i32 %273, 0
br i1 %274, label %275, label %309
275: ; preds = %272
%276 = load i32, i32* %15
%277 = sdiv i32 %276, 2000
%278 = load i32, i32* %15
%279 = sdiv i32 %278, 2
%280 = srem i32 %279, 1000
%281 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.7, i64 0, i64 0), i32 %277, i32 %280)
store i32 0, i32* %14
br label %282
282: ; preds = %295, %275
%283 = load i32, i32* %14
%284 = load i32, i32* %19
%285 = sub nsw i32 %284, 1
%286 = icmp slt i32 %283, %285
br i1 %286, label %287, label %298
287: ; preds = %282
%288 = load i32, i32* %14
%289 = sext i32 %288 to i64
%290 = getelementptr inbounds [50 x i8], [50 x i8]* %20, i64 0, i64 %289
%291 = load i8, i8* %290
%292 = zext i8 %291 to i32
store i32 %292, i32* %17
%293 = load i32, i32* %17
%294 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.8, i64 0, i64 0), i32 %293)
br label %295
295: ; preds = %287
%296 = load i32, i32* %14
%297 = add nsw i32 %296, 1
store i32 %297, i32* %14
br label %282
298: ; preds = %282
%299 = load i32, i32* %19
%300 = sub nsw i32 %299, 1
%301 = sext i32 %300 to i64
%302 = getelementptr inbounds [50 x i8], [50 x i8]* %20, i64 0, i64 %301
%303 = load i8, i8* %302
%304 = zext i8 %303 to i32
store i32 %304, i32* %17
%305 = load i32, i32* %17
%306 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.8, i64 0, i64 0), i32 %305)
store i32 0, i32* %19
%307 = load i32, i32* @stdout
%308 = call i32 @fflush(i32 %307)
br label %309
309: ; preds = %298, %272, %269
br label %310
310: ; preds = %309, %198
%311 = call i32 @usleep(i32 500)
br label %312
312: ; preds = %310
%313 = load i32, i32* %15
%314 = add nsw i32 %313, 1
store i32 %314, i32* %15
br label %180
}

LLVM IR (-O2):
%struct.termios = type { i32, i32, i32, i32 }
@__const.main.serialPort2 = [13 x i8] c"/dev/ttyUSB0\00"
@O_RDWR = global i32 0
@O_NOCTTY = global i32 0
@O_NDELAY = global i32 0
@O_NONBLOCK = global i32 0
@.str.1 = [27 x i8] c"Unable to open serial-port\00"
@F_SETFL = global i32 0
@B2400 = global i32 0
@B9600 = global i32 0
@B19200 = global i32 0
@CLOCAL = global i32 0
@CREAD = global i32 0
@CSIZE = global i32 0
@CS8 = global i32 0
@PARENB = global i32 0
@CSTOPB = global i32 0
@IXON = global i32 0
@IXOFF = global i32 0
@IGNCR = global i32 0
@ICRNL = global i32 0
@INLCR = global i32 0
@IGNBRK = global i32 0
@OPOST = global i32 0
@ICANON = global i32 0
@ECHO = global i32 0
@ECHOE = global i32 0
@ISIG = global i32 0
@TCSANOW = global i32 0
@FIONREAD = global i32 0
@.str.5 = [11 x i8] c"ioctl(hex)\00"
@.str.6 = [10 x i8] c"read(Hex)\00"
@.str.7 = [24 x i8] c"\0A\1B[1m%6d.%03d Hex:\1B[0m \00"
@.str.8 = [6 x i8] c"%02X \00"
@stdout = global i32 0
@str = [7 x i8] c"19.200\00"
@str.9 = [6 x i8] c"9.600\00"
@str.10 = [6 x i8] c"2.400\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [13 x i8]
%4 = alloca i32
%5 = alloca [50 x i8]
%6 = alloca [40 x i8]
%7 = getelementptr inbounds [40 x i8], [40 x i8]* %6, i64 0, i64 0
%8 = alloca %struct.termios
%9 = getelementptr inbounds [13 x i8], [13 x i8]* %3, i64 0, i64 0
%10 = bitcast i32* %4 to i8*
%11 = getelementptr inbounds [50 x i8], [50 x i8]* %5, i64 0, i64 0
%12 = getelementptr inbounds [40 x i8], [40 x i8]* %6, i64 0, i64 0
%13 = icmp sgt i32 %0, 1
br i1 %13, label %14, label %27
14: ; preds = %2
%15 = getelementptr inbounds i8*, i8** %1, i64 1
%16 = load i8*, i8** %15
%17 = tail call i32 @atoi(i8* %16)
%18 = icmp eq i32 %0, 2
br i1 %18, label %27, label %19
19: ; preds = %14
%20 = getelementptr inbounds i8*, i8** %1, i64 2
%21 = load i8*, i8** %20
%22 = icmp ugt i32 %0, 3
br i1 %22, label %23, label %27
23: ; preds = %19
%24 = getelementptr inbounds i8*, i8** %1, i64 3
%25 = load i8*, i8** %24
%26 = tail call i32 @atoi(i8* %25)
br label %27
27: ; preds = %2, %14, %19, %23
%28 = phi i8* [ %21, %23 ], [ %21, %19 ], [ %9, %14 ], [ %9, %2 ]
%29 = phi i32 [ %17, %23 ], [ %17, %19 ], [ %17, %14 ], [ 2400, %2 ]
%30 = phi i32 [ %26, %23 ], [ 40, %19 ], [ 40, %14 ], [ 40, %2 ]
%31 = load i32, i32* @O_RDWR
%32 = load i32, i32* @O_NOCTTY
%33 = or i32 %32, %31
%34 = load i32, i32* @O_NDELAY
%35 = or i32 %33, %34
%36 = load i32, i32* @O_NONBLOCK
%37 = or i32 %35, %36
%38 = call i32 @open(i8* %28, i32 %37)
%39 = icmp eq i32 %38, -1
br i1 %39, label %40, label %42
40: ; preds = %27
%41 = tail call i32 @perror(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0))
ret i32 -1
42: ; preds = %27
%43 = load i32, i32* @F_SETFL
%44 = tail call i32 @fcntl(i32 %38, i32 %43, i32 0)
%45 = bitcast %struct.termios* %8 to i8*
%46 = call i32 @tcgetattr(i32 %38, %struct.termios* %8)
switch i32 %29, label %57 [
i32 2400, label %49
i32 9600, label %47
i32 19200, label %48
]
47: ; preds = %42
br label %49
48: ; preds = %42
br label %49
49: ; preds = %42, %48, %47
%50 = phi i8* [ getelementptr inbounds ([6 x i8], [6 x i8]* @str.9, i64 0, i64 0), %47 ], [ getelementptr inbounds ([7 x i8], [7 x i8]* @str, i64 0, i64 0), %48 ], [ getelementptr inbounds ([6 x i8], [6 x i8]* @str.10, i64 0, i64 0), %42 ]
%51 = phi i32* [ @B9600, %47 ], [ @B19200, %48 ], [ @B2400, %42 ]
%52 = call i32 @puts(i8* dereferenceable(1) %50)
%53 = load i32, i32* %51
%54 = call i32 @cfsetispeed(%struct.termios* %8, i32 %53)
%55 = load i32, i32* %51
%56 = call i32 @cfsetospeed(%struct.termios* %8, i32 %55)
br label %57
57: ; preds = %49, %42
%58 = load i32, i32* @CLOCAL
%59 = load i32, i32* @CREAD
%60 = or i32 %59, %58
%61 = getelementptr inbounds %struct.termios, %struct.termios* %8, i64 0, i32 0
%62 = load i32, i32* %61
%63 = or i32 %60, %62
%64 = load i32, i32* @CSIZE
%65 = load i32, i32* @CS8
%66 = load i32, i32* @PARENB
%67 = load i32, i32* @CSTOPB
%68 = or i32 %67, %64
%69 = or i32 %66, %68
%70 = xor i32 %69, -1
%71 = and i32 %63, %70
%72 = or i32 %65, %71
store i32 %72, i32* %61
%73 = load i32, i32* @IXON
%74 = getelementptr inbounds %struct.termios, %struct.termios* %8, i64 0, i32 3
%75 = load i32, i32* %74
%76 = load i32, i32* @IXOFF
%77 = or i32 %73, %76
%78 = load i32, i32* @IGNCR
%79 = or i32 %77, %78
%80 = load i32, i32* @ICRNL
%81 = or i32 %79, %80
%82 = load i32, i32* @INLCR
%83 = or i32 %81, %82
%84 = xor i32 %83, -1
%85 = and i32 %75, %84
%86 = load i32, i32* @IGNBRK
%87 = or i32 %86, %85
store i32 %87, i32* %74
%88 = load i32, i32* @OPOST
%89 = xor i32 %88, -1
%90 = getelementptr inbounds %struct.termios, %struct.termios* %8, i64 0, i32 2
%91 = load i32, i32* %90
%92 = and i32 %91, %89
store i32 %92, i32* %90
%93 = load i32, i32* @ICANON
%94 = load i32, i32* @ECHO
%95 = or i32 %94, %93
%96 = load i32, i32* @ECHOE
%97 = or i32 %95, %96
%98 = load i32, i32* @ISIG
%99 = or i32 %97, %98
%100 = xor i32 %99, -1
%101 = getelementptr inbounds %struct.termios, %struct.termios* %8, i64 0, i32 1
%102 = load i32, i32* %101
%103 = and i32 %102, %100
store i32 %103, i32* %101
%104 = load i32, i32* @TCSANOW
%105 = call i32 @tcsetattr(i32 %38, i32 %104, %struct.termios* %8)
%106 = bitcast [40 x i8]* %6 to i8**
br label %107
107: ; preds = %183, %57
%108 = phi i32 [ undef, %57 ], [ %184, %183 ]
%109 = phi i32 [ 0, %57 ], [ %187, %183 ]
%110 = phi i32 [ 0, %57 ], [ %185, %183 ]
%111 = load i32, i32* @FIONREAD
%112 = call i32 @ioctl(i32 %38, i32 %111, i32* %4)
%113 = icmp slt i32 %112, 0
br i1 %113, label %114, label %119
114: ; preds = %107
%115 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.5, i64 0, i64 0))
%116 = icmp sgt i32 %108, 0
%117 = sext i1 %116 to i32
%118 = add nsw i32 %108, %117
br label %183
119: ; preds = %107
%120 = icmp eq i32 %112, 0
br i1 %120, label %121, label %183
121: ; preds = %119
%122 = load i32, i32* %4
%123 = icmp eq i32 %122, 0
%124 = icmp sgt i32 %108, 0
%125 = select i1 %123, i1 %124, i1 false
%126 = sext i1 %125 to i32
%127 = add nsw i32 %108, %126
%128 = icmp sgt i32 %122, 0
br i1 %128, label %129, label %152
129: ; preds = %121
%130 = icmp eq i32 %127, 0
%131 = icmp eq i32 %110, 0
%132 = select i1 %130, i1 %131, i1 false
%133 = select i1 %132, i32 %30, i32 %127
%134 = icmp sgt i32 %133, -1
%135 = icmp sgt i32 %110, -1
%136 = select i1 %134, i1 %135, i1 false
%137 = select i1 %136, i32 %30, i32 %133
%138 = call i32 @read(i32 %38, i8** %106, i32 40)
%139 = icmp slt i32 %138, 0
br i1 %139, label %140, label %143
140: ; preds = %129
%141 = call i32 @perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.6, i64 0, i64 0))
%142 = add nsw i32 %137, -1
br label %152
143: ; preds = %129
%144 = icmp eq i32 %138, 0
%145 = sext i1 %144 to i32
%146 = add nsw i32 %137, %145
br i1 %144, label %152, label %147
147: ; preds = %143
%148 = sext i32 %110 to i64
%149 = getelementptr [50 x i8], [50 x i8]* %5, i64 0, i64 %148
%150 = zext i32 %138 to i64
%151 = add nsw i32 %138, %110
br label %152
152: ; preds = %140, %143, %147, %121
%153 = phi i32 [ %146, %147 ], [ %146, %143 ], [ %127, %121 ], [ %142, %140 ]
%154 = phi i32 [ %151, %147 ], [ %110, %143 ], [ %110, %121 ], [ %110, %140 ]
%155 = icmp eq i32 %153, 0
%156 = icmp sgt i32 %154, 0
%157 = select i1 %155, i1 %156, i1 false
br i1 %157, label %158, label %183
158: ; preds = %152
%159 = udiv i32 %109, 2000
%160 = lshr i32 %109, 1
%161 = urem i32 %160, 1000
%162 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.7, i64 0, i64 0), i32 %159, i32 %161)
%163 = add nsw i32 %154, -1
%164 = icmp ugt i32 %154, 1
br i1 %164, label %165, label %175
165: ; preds = %158
%166 = zext i32 %163 to i64
br label %167
167: ; preds = %165, %167
%168 = phi i64 [ 0, %165 ], [ %173, %167 ]
%169 = getelementptr inbounds [50 x i8], [50 x i8]* %5, i64 0, i64 %168
%170 = load i8, i8* %169
%171 = zext i8 %170 to i32
%172 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.8, i64 0, i64 0), i32 %171)
%173 = add nuw nsw i64 %168, 1
%174 = icmp eq i64 %173, %166
br i1 %174, label %175, label %167
175: ; preds = %167, %158
%176 = sext i32 %163 to i64
%177 = getelementptr inbounds [50 x i8], [50 x i8]* %5, i64 0, i64 %176
%178 = load i8, i8* %177
%179 = zext i8 %178 to i32
%180 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.8, i64 0, i64 0), i32 %179)
%181 = load i32, i32* @stdout
%182 = call i32 @fflush(i32 %181)
br label %183
183: ; preds = %114, %152, %175, %119
%184 = phi i32 [ 0, %175 ], [ %153, %152 ], [ %108, %119 ], [ %118, %114 ]
%185 = phi i32 [ 0, %175 ], [ %154, %152 ], [ %110, %119 ], [ %110, %114 ]
%186 = call i32 @usleep(i32 500)
%187 = add nuw nsw i32 %109, 1
br label %107
}