#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 uint64_t;
struct winsize {
  unsigned int ws_col;
  unsigned int ws_row;
  scalar_t__ ws_ypixel;
  scalar_t__ ws_xpixel;
};
struct timeval {
  int tv_usec;
  scalar_t__ tv_sec;
};
struct termios {
  int dummy;
};
typedef scalar_t__ speed_t;
typedef int /*<<< orphan*/ fd_set;

/* Variables and functions */
scalar_t__ B115200;
scalar_t__ B19200;
scalar_t__ B57600;
scalar_t__ B9600;
scalar_t__ EAGAIN;
scalar_t__ EWOULDBLOCK;
int /*<<< orphan*/ FD_SET(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ FD_ZERO(int /*<<< orphan*/ *);
int /*<<< orphan*/ F_GETFL;
int /*<<< orphan*/ F_SETFL;
int O_NOCTTY;
int O_NONBLOCK;
int O_RDONLY;
int O_RDWR;
int /*<<< orphan*/ TCSANOW;
int /*<<< orphan*/ TIOCCONS;
int /*<<< orphan*/ TIOCSWINSZ;
int /*<<< orphan*/ cfmakeraw(struct termios *);
int /*<<< orphan*/ cfsetispeed(struct termios *, scalar_t__);
int /*<<< orphan*/ cfsetospeed(struct termios *, scalar_t__);
int /*<<< orphan*/ close(int);
scalar_t__ errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int fcntl(int, int /*<<< orphan*/, int);
int /*<<< orphan*/ ioctl(int, int /*<<< orphan*/, struct winsize *);
int open(char *, int);
int /*<<< orphan*/ printf(char *, char *);
int read(int, char *, int);
scalar_t__ select(int, int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                  int /*<<< orphan*/ *, struct timeval *);
int sscanf(char *, char *, unsigned int *, unsigned int *);
scalar_t__ strchr(char *, char);
int /*<<< orphan*/ strcpy(char *, char *);
int /*<<< orphan*/ strncpy(char *, char *, int);
int /*<<< orphan*/ tcgetattr(int, struct termios *);
int /*<<< orphan*/ tcsetattr(int, int /*<<< orphan*/, struct termios *);
scalar_t__ write(int, char *, int);
int main(int argc, char *argv[]) {
  struct termios tty;
  struct termios tty2;
  struct winsize ws;
  unsigned width, height;
  int ttyf;
  int tmpi;
  int currspeed;
  int flags;
  speed_t cspeed;
  char buff[128];
  int bufflen;
  fd_set set;
  struct timeval timeout;
  char *offset;
  uint64_t address;
  bufflen = 0;
  tmpi = open("/sys/firmware/acpi/tables/SPCR", O_RDONLY);
  if (tmpi < 0) {
    exit(0);
  }
  if (read(tmpi, buff, 80) < 80) {
    exit(0);
  }
  close(tmpi);
  if (buff[8] != 2)
    exit(0);
  if (buff[36] != 0)
    exit(0);
  if (buff[40] != 1)
    exit(0);
  address = *(uint64_t *)(buff + 44);
  currspeed = buff[58];
  offset = buff + 10;
  if (address == 0x3f8) {
    strncpy(buff, "/dev/ttyS0", 128);
  } else if (address == 0x2f8) {
    strncpy(buff, "/dev/ttyS1", 128);
  } else if (address == 0x3e8) {
    strncpy(buff, "/dev/ttyS2", 128);
  } else if (address == 0x2e8) {
    strncpy(buff, "/dev/ttyS3", 128);
  } else {
    exit(0);
  }
  ttyf = open(buff, O_RDWR | O_NOCTTY);
  if (currspeed == 3) {
    cspeed = B9600;
    strcpy(offset, ",9600");
  } else if (currspeed == 4) {
    cspeed = B19200;
    strcpy(offset, ",19200");
  } else if (currspeed == 6) {
    cspeed = B57600;
    strcpy(offset, ",57600");
  } else if (currspeed == 7) {
    cspeed = B115200;
    strcpy(offset, ",115200");
  } else {
    exit(0);
  }
  tcgetattr(ttyf, &tty);
  if (cspeed) {
    cfsetospeed(&tty, cspeed);
    cfsetispeed(&tty, cspeed);
  }
  printf("%s\n", buff);
  tcgetattr(ttyf, &tty2);
  cfmakeraw(&tty2);
  tcsetattr(ttyf, TCSANOW, &tty2);
  flags = fcntl(ttyf, F_GETFL, 0);
  fcntl(ttyf, F_SETFL, flags | O_NONBLOCK);
  while (read(ttyf, buff, 64) > 0) {
  }
  timeout.tv_sec = 0;
  timeout.tv_usec = 500000;
  FD_ZERO(&set);
  FD_SET(ttyf, &set);
  if (write(ttyf, "\0337\033[999;999H\033[6n\0338", 18) < 0) {
  };
  while (select(ttyf + 1, &set, NULL, NULL, &timeout) > 0) {
    if ((tmpi = read(ttyf, buff + bufflen, 127 - bufflen)) < 0) {
      if (errno == EAGAIN || errno == EWOULDBLOCK) {
        continue;
      } else {
        break;
      }
    }
    bufflen += tmpi;
    buff[bufflen] = 0;
    if (strchr(buff, 'R')) {
      break;
    }
  }
  fcntl(ttyf, F_SETFL, flags);
  ws.ws_xpixel = 0;
  ws.ws_ypixel = 0;
  if (sscanf(buff, "\033[%u;%uR", &height, &width) == 2) {
    ws.ws_col = width;
    ws.ws_row = height;
  } else {
    ws.ws_col = 100;
    ws.ws_row = 31;
  }
  if (ws.ws_col < 80) {
    ws.ws_col = 80;
  }
  if (ws.ws_row < 24) {
    ws.ws_col = 24;
  }
  ioctl(ttyf, TIOCSWINSZ, &ws);
  tcsetattr(ttyf, TCSANOW, &tty);
  ioctl(ttyf, TIOCCONS, 0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x110,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0xe4(%rbp)
mov    0x2d66(%rip),%rax
mov    (%rax),%esi
lea    0xd8d(%rip),%rdi
call   1130 <open@plt>
mov    %eax,-0x48(%rbp)
cmpl   $0x0,-0x48(%rbp)
jge    128c <main+0x4c>
xor    %edi,%edi
call   1150 <exit@plt>
mov    -0x48(%rbp),%edi
lea    -0xe0(%rbp),%rsi
mov    $0x50,%edx
call   10c0 <read@plt>
cmp    $0x50,%eax
jge    12b0 <main+0x70>
xor    %edi,%edi
call   1150 <exit@plt>
mov    -0x48(%rbp),%edi
call   10b0 <close@plt>
movsbl -0xd8(%rbp),%eax
cmp    $0x2,%eax
je     12cf <main+0x8f>
xor    %edi,%edi
call   1150 <exit@plt>
movsbl -0xbc(%rbp),%eax
cmp    $0x0,%eax
je     12e6 <main+0xa6>
xor    %edi,%edi
call   1150 <exit@plt>
movsbl -0xb8(%rbp),%eax
cmp    $0x1,%eax
je     12fd <main+0xbd>
xor    %edi,%edi
call   1150 <exit@plt>
mov    -0xb4(%rbp),%eax
mov    %eax,-0x104(%rbp)
movsbl -0xa6(%rbp),%eax
mov    %eax,-0x4c(%rbp)
lea    -0xe0(%rbp),%rax
add    $0xa,%rax
mov    %rax,-0x100(%rbp)
cmpl   $0x3f8,-0x104(%rbp)
jne    1352 <main+0x112>
lea    -0xe0(%rbp),%rdi
lea    0xcdc(%rip),%rsi
mov    $0x80,%edx
call   1030 <strncpy@plt>
jmp    13ef <main+0x1af>
cmpl   $0x2f8,-0x104(%rbp)
jne    137f <main+0x13f>
lea    -0xe0(%rbp),%rdi
lea    0xcba(%rip),%rsi
mov    $0x80,%edx
call   1030 <strncpy@plt>
jmp    13ea <main+0x1aa>
cmpl   $0x3e8,-0x104(%rbp)
jne    13ac <main+0x16c>
lea    -0xe0(%rbp),%rdi
lea    0xc98(%rip),%rsi
mov    $0x80,%edx
call   1030 <strncpy@plt>
jmp    13e5 <main+0x1a5>
cmpl   $0x2e8,-0x104(%rbp)
jne    13d9 <main+0x199>
lea    -0xe0(%rbp),%rdi
lea    0xc76(%rip),%rsi
mov    $0x80,%edx
call   1030 <strncpy@plt>
jmp    13e0 <main+0x1a0>
xor    %edi,%edi
call   1150 <exit@plt>
jmp    13e5 <main+0x1a5>
jmp    13ea <main+0x1aa>
jmp    13ef <main+0x1af>
lea    -0xe0(%rbp),%rdi
mov    0x2be3(%rip),%rax
mov    (%rax),%esi
mov    0x2b92(%rip),%rax
or     (%rax),%esi
call   1130 <open@plt>
mov    %eax,-0x44(%rbp)
cmpl   $0x3,-0x4c(%rbp)
jne    1440 <main+0x200>
mov    0x2b9f(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x58(%rbp)
mov    -0x100(%rbp),%rdi
lea    0xc15(%rip),%rsi
call   1040 <strcpy@plt>
jmp    14e6 <main+0x2a6>
cmpl   $0x4,-0x4c(%rbp)
jne    1470 <main+0x230>
mov    0x2b9f(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x58(%rbp)
mov    -0x100(%rbp),%rdi
lea    0xbeb(%rip),%rsi
call   1040 <strcpy@plt>
jmp    14e1 <main+0x2a1>
cmpl   $0x6,-0x4c(%rbp)
jne    14a0 <main+0x260>
mov    0x2b27(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x58(%rbp)
mov    -0x100(%rbp),%rdi
lea    0xbc2(%rip),%rsi
call   1040 <strcpy@plt>
jmp    14dc <main+0x29c>
cmpl   $0x7,-0x4c(%rbp)
jne    14d0 <main+0x290>
mov    0x2abf(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x58(%rbp)
mov    -0x100(%rbp),%rdi
lea    0xb99(%rip),%rsi
call   1040 <strcpy@plt>
jmp    14d7 <main+0x297>
xor    %edi,%edi
call   1150 <exit@plt>
jmp    14dc <main+0x29c>
jmp    14e1 <main+0x2a1>
jmp    14e6 <main+0x2a6>
mov    -0x44(%rbp),%edi
lea    -0x18(%rbp),%rsi
call   1110 <tcgetattr@plt>
cmpq   $0x0,-0x58(%rbp)
je     1517 <main+0x2d7>
mov    -0x58(%rbp),%rsi
lea    -0x18(%rbp),%rdi
call   1070 <cfsetospeed@plt>
mov    -0x58(%rbp),%rsi
lea    -0x18(%rbp),%rdi
call   1140 <cfsetispeed@plt>
lea    -0xe0(%rbp),%rsi
lea    0xb42(%rip),%rdi
call   1090 <printf@plt>
mov    -0x44(%rbp),%edi
lea    -0x20(%rbp),%rsi
call   1110 <tcgetattr@plt>
lea    -0x20(%rbp),%rdi
call   1100 <cfmakeraw@plt>
mov    -0x44(%rbp),%edi
mov    0x2a7f(%rip),%rax
mov    (%rax),%esi
lea    -0x20(%rbp),%rdx
call   1120 <tcsetattr@plt>
mov    -0x44(%rbp),%edi
mov    0x2a1a(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1050 <fcntl@plt>
mov    %eax,-0x50(%rbp)
mov    -0x44(%rbp),%edi
mov    0x2a1c(%rip),%rax
mov    (%rax),%esi
mov    -0x50(%rbp),%edx
mov    0x2a58(%rip),%rax
or     (%rax),%edx
call   1050 <fcntl@plt>
mov    -0x44(%rbp),%edi
lea    -0xe0(%rbp),%rsi
mov    $0x40,%edx
call   10c0 <read@plt>
cmp    $0x0,%eax
jle    15a9 <main+0x369>
jmp    1587 <main+0x347>
movq   $0x0,-0xf0(%rbp)
movl   $0x7a120,-0xf8(%rbp)
lea    -0xe8(%rbp),%rdi
call   10d0 <FD_ZERO@plt>
mov    -0x44(%rbp),%edi
lea    -0xe8(%rbp),%rsi
call   1160 <FD_SET@plt>
mov    -0x44(%rbp),%edi
lea    0xa88(%rip),%rsi
mov    $0x12,%edx
call   1060 <write@plt>
cmp    $0x0,%rax
jge    15fc <main+0x3bc>
jmp    15fc <main+0x3bc>
jmp    1601 <main+0x3c1>
mov    -0x44(%rbp),%edi
add    $0x1,%edi
lea    -0xe8(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%ecx
lea    -0xf8(%rbp),%r8
mov    %rcx,%rdx
call   10e0 <select@plt>
cmp    $0x0,%rax
jle    16dc <main+0x49c>
mov    -0x44(%rbp),%edi
lea    -0xe0(%rbp),%rsi
movslq -0xe4(%rbp),%rax
add    %rax,%rsi
mov    $0x7f,%edx
sub    -0xe4(%rbp),%edx
call   10c0 <read@plt>
mov    %eax,-0x48(%rbp)
cmp    $0x0,%eax
jge    1699 <main+0x459>
mov    0x2926(%rip),%rax
mov    (%rax),%rax
mov    0x28f4(%rip),%rcx
cmp    (%rcx),%rax
je     168f <main+0x44f>
mov    0x290c(%rip),%rax
mov    (%rax),%rax
mov    0x28fa(%rip),%rcx
cmp    (%rcx),%rax
jne    1694 <main+0x454>
jmp    1601 <main+0x3c1>
jmp    16dc <main+0x49c>
mov    -0x48(%rbp),%eax
add    -0xe4(%rbp),%eax
mov    %eax,-0xe4(%rbp)
movslq -0xe4(%rbp),%rax
movb   $0x0,-0xe0(%rbp,%rax,1)
lea    -0xe0(%rbp),%rdi
mov    $0x52,%esi
call   1080 <strchr@plt>
cmp    $0x0,%rax
je     16d7 <main+0x497>
jmp    16dc <main+0x49c>
jmp    1601 <main+0x3c1>
mov    -0x44(%rbp),%edi
mov    0x28aa(%rip),%rax
mov    (%rax),%esi
mov    -0x50(%rbp),%edx
call   1050 <fcntl@plt>
movq   $0x0,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
lea    -0xe0(%rbp),%rdi
lea    0x970(%rip),%rsi
lea    -0x40(%rbp),%rdx
lea    -0x3c(%rbp),%rcx
call   10f0 <sscanf@plt>
cmp    $0x2,%eax
jne    1735 <main+0x4f5>
mov    -0x3c(%rbp),%eax
mov    %eax,-0x38(%rbp)
mov    -0x40(%rbp),%eax
mov    %eax,-0x34(%rbp)
jmp    1743 <main+0x503>
movl   $0x64,-0x38(%rbp)
movl   $0x1f,-0x34(%rbp)
cmpl   $0x50,-0x38(%rbp)
jae    1754 <main+0x514>
movl   $0x50,-0x38(%rbp)
cmpl   $0x18,-0x34(%rbp)
jae    1765 <main+0x525>
movl   $0x18,-0x38(%rbp)
mov    -0x44(%rbp),%edi
mov    0x2841(%rip),%rax
mov    (%rax),%esi
lea    -0x38(%rbp),%rdx
call   10a0 <ioctl@plt>
mov    -0x44(%rbp),%edi
mov    0x2844(%rip),%rax
mov    (%rax),%esi
lea    -0x18(%rbp),%rdx
call   1120 <tcsetattr@plt>
mov    -0x44(%rbp),%edi
mov    0x281f(%rip),%rax
mov    (%rax),%esi
xor    %eax,%eax
mov    %eax,%edx
call   10a0 <ioctl@plt>
mov    -0x4(%rbp),%eax
add    $0x110,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xd8,%rsp
mov    0x2d80(%rip),%rax
mov    (%rax),%esi
lea    0xd9f(%rip),%rdi
call   1130 <open@plt>
test   %eax,%eax
js     15e5 <main+0x3a5>
mov    %eax,%ebx
lea    0x50(%rsp),%rsi
mov    %eax,%edi
mov    $0x50,%edx
call   10c0 <read@plt>
cmp    $0x4f,%eax
jle    15e5 <main+0x3a5>
mov    %ebx,%edi
call   10b0 <close@plt>
cmpb   $0x2,0x58(%rsp)
jne    15e5 <main+0x3a5>
cmpb   $0x0,0x74(%rsp)
jne    15e5 <main+0x3a5>
cmpb   $0x1,0x78(%rsp)
jne    15e5 <main+0x3a5>
mov    0x7c(%rsp),%eax
mov    0x8a(%rsp),%bl
cmp    $0x3e7,%eax
jg     12df <main+0x9f>
cmp    $0x2e8,%eax
je     12fa <main+0xba>
cmp    $0x2f8,%eax
jne    15e5 <main+0x3a5>
lea    0xd4d(%rip),%rsi
jmp    130a <main+0xca>
cmp    $0x3e8,%eax
je     1303 <main+0xc3>
cmp    $0x3f8,%eax
jne    15e5 <main+0x3a5>
lea    0xd27(%rip),%rsi
jmp    130a <main+0xca>
lea    0xd3f(%rip),%rsi
jmp    130a <main+0xca>
lea    0xd2b(%rip),%rsi
lea    0x50(%rsp),%rbp
mov    %rbp,%rdi
mov    $0x80,%edx
call   1030 <strncpy@plt>
mov    0x2cc5(%rip),%rax
mov    0x2c86(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    %rbp,%rdi
call   1130 <open@plt>
add    $0xfd,%bl
cmp    $0x5,%bl
jae    15e5 <main+0x3a5>
mov    %eax,%ebp
movzbl %bl,%eax
mov    $0x1b,%ecx
bt     %eax,%ecx
jae    15e5 <main+0x3a5>
lea    0x5a(%rsp),%rdi
movsbq %bl,%rax
lea    0x2a33(%rip),%rcx
mov    (%rcx,%rax,8),%rcx
lea    0xd18(%rip),%rdx
movslq (%rdx,%rax,4),%rsi
add    %rdx,%rsi
mov    (%rcx),%rbx
call   1040 <strcpy@plt>
mov    %rsp,%rsi
mov    %ebp,%edi
call   1110 <tcgetattr@plt>
test   %rbx,%rbx
je     13a7 <main+0x167>
mov    %rsp,%r14
mov    %r14,%rdi
mov    %rbx,%rsi
call   1070 <cfsetospeed@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1140 <cfsetispeed@plt>
lea    0xcb9(%rip),%rdi
lea    0x50(%rsp),%rbx
mov    %rbx,%rsi
call   1090 <printf@plt>
lea    0x38(%rsp),%r14
mov    %ebp,%edi
mov    %r14,%rsi
call   1110 <tcgetattr@plt>
mov    %r14,%rdi
call   1100 <cfmakeraw@plt>
mov    0x2bf7(%rip),%rax
mov    (%rax),%esi
mov    %ebp,%edi
mov    %r14,%rdx
call   1120 <tcsetattr@plt>
mov    0x2ba4(%rip),%rax
mov    (%rax),%esi
mov    %ebp,%edi
xor    %edx,%edx
call   1050 <fcntl@plt>
mov    %eax,%edx
mov    0x2ba8(%rip),%rax
mov    (%rax),%esi
mov    0x2bd7(%rip),%rax
mov    %edx,0x10(%rsp)
or     (%rax),%edx
mov    %ebp,%edi
call   1050 <fcntl@plt>
cs nopw 0x0(%rax,%rax,1)
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x40,%edx
call   10c0 <read@plt>
test   %eax,%eax
jg     1420 <main+0x1e0>
movq   $0x0,0x48(%rsp)
movl   $0x7a120,0x40(%rsp)
lea    0x14(%rsp),%rbx
mov    %rbx,%rdi
call   10d0 <FD_ZERO@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
call   1160 <FD_SET@plt>
lea    0xc09(%rip),%rsi
mov    %ebp,%edi
mov    $0x12,%edx
call   1060 <write@plt>
mov    %ebp,%ebx
add    $0x1,%ebx
xor    %eax,%eax
mov    %rax,0x8(%rsp)
lea    0x40(%rsp),%r12
mov    0x2afa(%rip),%r15
movslq 0x8(%rsp),%rax
lea    (%rsp,%rax,1),%r13
add    $0x50,%r13
mov    $0x7f,%r14d
sub    %eax,%r14d
nopl   0x0(%rax)
mov    %ebx,%edi
lea    0x14(%rsp),%rsi
xor    %edx,%edx
xor    %ecx,%ecx
mov    %r12,%r8
call   10e0 <select@plt>
test   %rax,%rax
jle    151c <main+0x2dc>
mov    %ebp,%edi
mov    %r13,%rsi
mov    %r14d,%edx
call   10c0 <read@plt>
test   %eax,%eax
jns    14f0 <main+0x2b0>
mov    0x2ad0(%rip),%rax
mov    (%rax),%rax
cmp    (%r15),%rax
je     14a0 <main+0x260>
mov    0x2ab9(%rip),%rcx
cmp    (%rcx),%rax
je     14a0 <main+0x260>
jmp    151c <main+0x2dc>
cs nopw 0x0(%rax,%rax,1)
mov    0x8(%rsp),%rcx
add    %eax,%ecx
mov    %rcx,0x8(%rsp)
movslq %ecx,%rax
movb   $0x0,0x50(%rsp,%rax,1)
lea    0x50(%rsp),%rdi
mov    $0x52,%esi
call   1080 <strchr@plt>
test   %rax,%rax
je     1486 <main+0x246>
mov    0x2a85(%rip),%rax
mov    (%rax),%esi
mov    %ebp,%edi
mov    0x10(%rsp),%edx
call   1050 <fcntl@plt>
xorps  %xmm0,%xmm0
movups %xmm0,0x28(%rsp)
lea    0xb3f(%rip),%rsi
lea    0x50(%rsp),%rdi
lea    0x18(%rsp),%rdx
lea    0x1c(%rsp),%rcx
call   10f0 <sscanf@plt>
cmp    $0x2,%eax
jne    1588 <main+0x348>
mov    0x1c(%rsp),%ecx
mov    0x18(%rsp),%eax
mov    %ecx,0x20(%rsp)
mov    %eax,0x24(%rsp)
cmp    $0x50,%ecx
jb     1572 <main+0x332>
cmp    $0x17,%eax
ja     1597 <main+0x357>
cmp    $0x18,%eax
mov    $0x18,%eax
mov    $0x50,%ecx
cmovb  %eax,%ecx
mov    %ecx,0x20(%rsp)
jmp    1597 <main+0x357>
movabs $0x1f00000064,%rax
mov    %rax,0x20(%rsp)
mov    0x2a22(%rip),%rax
mov    (%rax),%esi
lea    0x20(%rsp),%rdx
mov    %ebp,%edi
call   10a0 <ioctl@plt>
mov    0x2a1d(%rip),%rax
mov    (%rax),%esi
mov    %rsp,%rdx
mov    %ebp,%edi
call   1120 <tcsetattr@plt>
mov    0x2a02(%rip),%rax
mov    (%rax),%esi
mov    %ebp,%edi
xor    %edx,%edx
call   10a0 <ioctl@plt>
xor    %eax,%eax
add    $0xd8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
xor    %edi,%edi
call   1150 <exit@plt>

LLVM IR (-O0):
%struct.termios = type { i32 }
%struct.winsize = type { i32, i32, i64, i64 }
%struct.timeval = type { i32, i64 }
@.str = [31 x i8] c"/sys/firmware/acpi/tables/SPCR\00"
@O_RDONLY = global i32 0
@.str.1 = [11 x i8] c"/dev/ttyS0\00"
@.str.2 = [11 x i8] c"/dev/ttyS1\00"
@.str.3 = [11 x i8] c"/dev/ttyS2\00"
@.str.4 = [11 x i8] c"/dev/ttyS3\00"
@O_RDWR = global i32 0
@O_NOCTTY = global i32 0
@B9600 = global i64 0
@.str.5 = [6 x i8] c",9600\00"
@B19200 = global i64 0
@.str.6 = [7 x i8] c",19200\00"
@B57600 = global i64 0
@.str.7 = [7 x i8] c",57600\00"
@B115200 = global i64 0
@.str.8 = [8 x i8] c",115200\00"
@.str.9 = [4 x i8] c"%s\0A\00"
@TCSANOW = global i32 0
@F_GETFL = global i32 0
@F_SETFL = global i32 0
@O_NONBLOCK = global i32 0
@.str.10 = [19 x i8] c"\1B7\1B[999;999H\1B[6n\1B8\00"
@errno = global i64 0
@EAGAIN = global i64 0
@EWOULDBLOCK = global i64 0
@.str.11 = [9 x i8] c"\1B[%u;%uR\00"
@TIOCSWINSZ = global i32 0
@TIOCCONS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca %struct.termios
%7 = alloca %struct.termios
%8 = alloca %struct.winsize
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i64
%16 = alloca [128 x i8]
%17 = alloca i32
%18 = alloca i32
%19 = alloca %struct.timeval
%20 = alloca i8*
%21 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %17
%22 = load i32, i32* @O_RDONLY
%23 = call i32 @open(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i32 %22)
store i32 %23, i32* %12
%24 = load i32, i32* %12
%25 = icmp slt i32 %24, 0
br i1 %25, label %26, label %28
26: ; preds = %2
%27 = call i32 @exit(i32 0)
unreachable
28: ; preds = %2
%29 = load i32, i32* %12
%30 = getelementptr inbounds [128 x i8], [128 x i8]* %16, i64 0, i64 0
%31 = call i32 @read(i32 %29, i8* %30, i32 80)
%32 = icmp slt i32 %31, 80
br i1 %32, label %33, label %35
33: ; preds = %28
%34 = call i32 @exit(i32 0)
unreachable
35: ; preds = %28
%36 = load i32, i32* %12
%37 = call i32 @close(i32 %36)
%38 = getelementptr inbounds [128 x i8], [128 x i8]* %16, i64 0, i64 8
%39 = load i8, i8* %38
%40 = sext i8 %39 to i32
%41 = icmp ne i32 %40, 2
br i1 %41, label %42, label %44
42: ; preds = %35
%43 = call i32 @exit(i32 0)
unreachable
44: ; preds = %35
%45 = getelementptr inbounds [128 x i8], [128 x i8]* %16, i64 0, i64 36
%46 = load i8, i8* %45
%47 = sext i8 %46 to i32
%48 = icmp ne i32 %47, 0
br i1 %48, label %49, label %51
49: ; preds = %44
%50 = call i32 @exit(i32 0)
unreachable
51: ; preds = %44
%52 = getelementptr inbounds [128 x i8], [128 x i8]* %16, i64 0, i64 40
%53 = load i8, i8* %52
%54 = sext i8 %53 to i32
%55 = icmp ne i32 %54, 1
br i1 %55, label %56, label %58
56: ; preds = %51
%57 = call i32 @exit(i32 0)
unreachable
58: ; preds = %51
%59 = getelementptr inbounds [128 x i8], [128 x i8]* %16, i64 0, i64 0
%60 = getelementptr inbounds i8, i8* %59, i64 44
%61 = bitcast i8* %60 to i32*
%62 = load i32, i32* %61
store i32 %62, i32* %21
%63 = getelementptr inbounds [128 x i8], [128 x i8]* %16, i64 0, i64 58
%64 = load i8, i8* %63
%65 = sext i8 %64 to i32
store i32 %65, i32* %13
%66 = getelementptr inbounds [128 x i8], [128 x i8]* %16, i64 0, i64 0
%67 = getelementptr inbounds i8, i8* %66, i64 10
store i8* %67, i8** %20
%68 = load i32, i32* %21
%69 = icmp eq i32 %68, 1016
br i1 %69, label %70, label %73
70: ; preds = %58
%71 = getelementptr inbounds [128 x i8], [128 x i8]* %16, i64 0, i64 0
%72 = call i32 @strncpy(i8* %71, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i32 128)
br label %96
73: ; preds = %58
%74 = load i32, i32* %21
%75 = icmp eq i32 %74, 760
br i1 %75, label %76, label %79
76: ; preds = %73
%77 = getelementptr inbounds [128 x i8], [128 x i8]* %16, i64 0, i64 0
%78 = call i32 @strncpy(i8* %77, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i32 128)
br label %95
79: ; preds = %73
%80 = load i32, i32* %21
%81 = icmp eq i32 %80, 1000
br i1 %81, label %82, label %85
82: ; preds = %79
%83 = getelementptr inbounds [128 x i8], [128 x i8]* %16, i64 0, i64 0
%84 = call i32 @strncpy(i8* %83, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), i32 128)
br label %94
85: ; preds = %79
%86 = load i32, i32* %21
%87 = icmp eq i32 %86, 744
br i1 %87, label %88, label %91
88: ; preds = %85
%89 = getelementptr inbounds [128 x i8], [128 x i8]* %16, i64 0, i64 0
%90 = call i32 @strncpy(i8* %89, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0), i32 128)
br label %93
91: ; preds = %85
%92 = call i32 @exit(i32 0)
unreachable
93: ; preds = %88
br label %94
94: ; preds = %93, %82
br label %95
95: ; preds = %94, %76
br label %96
96: ; preds = %95, %70
%97 = getelementptr inbounds [128 x i8], [128 x i8]* %16, i64 0, i64 0
%98 = load i32, i32* @O_RDWR
%99 = load i32, i32* @O_NOCTTY
%100 = or i32 %98, %99
%101 = call i32 @open(i8* %97, i32 %100)
store i32 %101, i32* %11
%102 = load i32, i32* %13
%103 = icmp eq i32 %102, 3
br i1 %103, label %104, label %108
104: ; preds = %96
%105 = load i64, i64* @B9600
store i64 %105, i64* %15
%106 = load i8*, i8** %20
%107 = call i32 @strcpy(i8* %106, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0))
br label %134
108: ; preds = %96
%109 = load i32, i32* %13
%110 = icmp eq i32 %109, 4
br i1 %110, label %111, label %115
111: ; preds = %108
%112 = load i64, i64* @B19200
store i64 %112, i64* %15
%113 = load i8*, i8** %20
%114 = call i32 @strcpy(i8* %113, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0))
br label %133
115: ; preds = %108
%116 = load i32, i32* %13
%117 = icmp eq i32 %116, 6
br i1 %117, label %118, label %122
118: ; preds = %115
%119 = load i64, i64* @B57600
store i64 %119, i64* %15
%120 = load i8*, i8** %20
%121 = call i32 @strcpy(i8* %120, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.7, i64 0, i64 0))
br label %132
122: ; preds = %115
%123 = load i32, i32* %13
%124 = icmp eq i32 %123, 7
br i1 %124, label %125, label %129
125: ; preds = %122
%126 = load i64, i64* @B115200
store i64 %126, i64* %15
%127 = load i8*, i8** %20
%128 = call i32 @strcpy(i8* %127, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.8, i64 0, i64 0))
br label %131
129: ; preds = %122
%130 = call i32 @exit(i32 0)
unreachable
131: ; preds = %125
br label %132
132: ; preds = %131, %118
br label %133
133: ; preds = %132, %111
br label %134
134: ; preds = %133, %104
%135 = load i32, i32* %11
%136 = call i32 @tcgetattr(i32 %135, %struct.termios* %6)
%137 = load i64, i64* %15
%138 = icmp ne i64 %137, 0
br i1 %138, label %139, label %144
139: ; preds = %134
%140 = load i64, i64* %15
%141 = call i32 @cfsetospeed(%struct.termios* %6, i64 %140)
%142 = load i64, i64* %15
%143 = call i32 @cfsetispeed(%struct.termios* %6, i64 %142)
br label %144
144: ; preds = %139, %134
%145 = getelementptr inbounds [128 x i8], [128 x i8]* %16, i64 0, i64 0
%146 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.9, i64 0, i64 0), i8* %145)
%147 = load i32, i32* %11
%148 = call i32 @tcgetattr(i32 %147, %struct.termios* %7)
%149 = call i32 @cfmakeraw(%struct.termios* %7)
%150 = load i32, i32* %11
%151 = load i32, i32* @TCSANOW
%152 = call i32 @tcsetattr(i32 %150, i32 %151, %struct.termios* %7)
%153 = load i32, i32* %11
%154 = load i32, i32* @F_GETFL
%155 = call i32 @fcntl(i32 %153, i32 %154, i32 0)
store i32 %155, i32* %14
%156 = load i32, i32* %11
%157 = load i32, i32* @F_SETFL
%158 = load i32, i32* %14
%159 = load i32, i32* @O_NONBLOCK
%160 = or i32 %158, %159
%161 = call i32 @fcntl(i32 %156, i32 %157, i32 %160)
br label %162
162: ; preds = %167, %144
%163 = load i32, i32* %11
%164 = getelementptr inbounds [128 x i8], [128 x i8]* %16, i64 0, i64 0
%165 = call i32 @read(i32 %163, i8* %164, i32 64)
%166 = icmp sgt i32 %165, 0
br i1 %166, label %167, label %168
167: ; preds = %162
br label %162
168: ; preds = %162
%169 = getelementptr inbounds %struct.timeval, %struct.timeval* %19, i32 0, i32 1
store i64 0, i64* %169
%170 = getelementptr inbounds %struct.timeval, %struct.timeval* %19, i32 0, i32 0
store i32 500000, i32* %170
%171 = call i32 @FD_ZERO(i32* %18)
%172 = load i32, i32* %11
%173 = call i32 @FD_SET(i32 %172, i32* %18)
%174 = load i32, i32* %11
%175 = call i64 @write(i32 %174, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.10, i64 0, i64 0), i32 18)
%176 = icmp slt i64 %175, 0
br i1 %176, label %177, label %178
177: ; preds = %168
br label %178
178: ; preds = %177, %168
br label %179
179: ; preds = %215, %202, %178
%180 = load i32, i32* %11
%181 = add nsw i32 %180, 1
%182 = call i64 @select(i32 %181, i32* %18, i32* null, i32* null, %struct.timeval* %19)
%183 = icmp sgt i64 %182, 0
br i1 %183, label %184, label %216
184: ; preds = %179
%185 = load i32, i32* %11
%186 = getelementptr inbounds [128 x i8], [128 x i8]* %16, i64 0, i64 0
%187 = load i32, i32* %17
%188 = sext i32 %187 to i64
%189 = getelementptr inbounds i8, i8* %186, i64 %188
%190 = load i32, i32* %17
%191 = sub nsw i32 127, %190
%192 = call i32 @read(i32 %185, i8* %189, i32 %191)
store i32 %192, i32* %12
%193 = icmp slt i32 %192, 0
br i1 %193, label %194, label %204
194: ; preds = %184
%195 = load i64, i64* @errno
%196 = load i64, i64* @EAGAIN
%197 = icmp eq i64 %195, %196
br i1 %197, label %202, label %198
198: ; preds = %194
%199 = load i64, i64* @errno
%200 = load i64, i64* @EWOULDBLOCK
%201 = icmp eq i64 %199, %200
br i1 %201, label %202, label %203
202: ; preds = %198, %194
br label %179
203: ; preds = %198
br label %216
204: ; preds = %184
%205 = load i32, i32* %12
%206 = load i32, i32* %17
%207 = add nsw i32 %206, %205
store i32 %207, i32* %17
%208 = load i32, i32* %17
%209 = sext i32 %208 to i64
%210 = getelementptr inbounds [128 x i8], [128 x i8]* %16, i64 0, i64 %209
store i8 0, i8* %210
%211 = getelementptr inbounds [128 x i8], [128 x i8]* %16, i64 0, i64 0
%212 = call i64 @strchr(i8* %211, i8 signext 82)
%213 = icmp ne i64 %212, 0
br i1 %213, label %214, label %215
214: ; preds = %204
br label %216
215: ; preds = %204
br label %179
216: ; preds = %214, %203, %179
%217 = load i32, i32* %11
%218 = load i32, i32* @F_SETFL
%219 = load i32, i32* %14
%220 = call i32 @fcntl(i32 %217, i32 %218, i32 %219)
%221 = getelementptr inbounds %struct.winsize, %struct.winsize* %8, i32 0, i32 3
store i64 0, i64* %221
%222 = getelementptr inbounds %struct.winsize, %struct.winsize* %8, i32 0, i32 2
store i64 0, i64* %222
%223 = getelementptr inbounds [128 x i8], [128 x i8]* %16, i64 0, i64 0
%224 = call i32 @sscanf(i8* %223, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.11, i64 0, i64 0), i32* %10, i32* %9)
%225 = icmp eq i32 %224, 2
br i1 %225, label %226, label %231
226: ; preds = %216
%227 = load i32, i32* %9
%228 = getelementptr inbounds %struct.winsize, %struct.winsize* %8, i32 0, i32 0
store i32 %227, i32* %228
%229 = load i32, i32* %10
%230 = getelementptr inbounds %struct.winsize, %struct.winsize* %8, i32 0, i32 1
store i32 %229, i32* %230
br label %234
231: ; preds = %216
%232 = getelementptr inbounds %struct.winsize, %struct.winsize* %8, i32 0, i32 0
store i32 100, i32* %232
%233 = getelementptr inbounds %struct.winsize, %struct.winsize* %8, i32 0, i32 1
store i32 31, i32* %233
br label %234
234: ; preds = %231, %226
%235 = getelementptr inbounds %struct.winsize, %struct.winsize* %8, i32 0, i32 0
%236 = load i32, i32* %235
%237 = icmp ult i32 %236, 80
br i1 %237, label %238, label %240
238: ; preds = %234
%239 = getelementptr inbounds %struct.winsize, %struct.winsize* %8, i32 0, i32 0
store i32 80, i32* %239
br label %240
240: ; preds = %238, %234
%241 = getelementptr inbounds %struct.winsize, %struct.winsize* %8, i32 0, i32 1
%242 = load i32, i32* %241
%243 = icmp ult i32 %242, 24
br i1 %243, label %244, label %246
244: ; preds = %240
%245 = getelementptr inbounds %struct.winsize, %struct.winsize* %8, i32 0, i32 0
store i32 24, i32* %245
br label %246
246: ; preds = %244, %240
%247 = load i32, i32* %11
%248 = load i32, i32* @TIOCSWINSZ
%249 = call i32 @ioctl(i32 %247, i32 %248, %struct.winsize* %8)
%250 = load i32, i32* %11
%251 = load i32, i32* @TCSANOW
%252 = call i32 @tcsetattr(i32 %250, i32 %251, %struct.termios* %6)
%253 = load i32, i32* %11
%254 = load i32, i32* @TIOCCONS
%255 = call i32 @ioctl(i32 %253, i32 %254, %struct.winsize* null)
%256 = load i32, i32* %3
ret i32 %256
}

LLVM IR (-O2):
%struct.termios = type { i32 }
%struct.winsize = type { i32, i32, i64, i64 }
%struct.timeval = type { i32, i64 }
@.str = [31 x i8] c"/sys/firmware/acpi/tables/SPCR\00"
@O_RDONLY = global i32 0
@.str.1 = [11 x i8] c"/dev/ttyS0\00"
@.str.2 = [11 x i8] c"/dev/ttyS1\00"
@.str.3 = [11 x i8] c"/dev/ttyS2\00"
@.str.4 = [11 x i8] c"/dev/ttyS3\00"
@O_RDWR = global i32 0
@O_NOCTTY = global i32 0
@B9600 = global i64 0
@.str.5 = [6 x i8] c",9600\00"
@B19200 = global i64 0
@.str.6 = [7 x i8] c",19200\00"
@B57600 = global i64 0
@.str.7 = [7 x i8] c",57600\00"
@B115200 = global i64 0
@.str.8 = [8 x i8] c",115200\00"
@.str.9 = [4 x i8] c"%s\0A\00"
@TCSANOW = global i32 0
@F_GETFL = global i32 0
@F_SETFL = global i32 0
@O_NONBLOCK = global i32 0
@.str.10 = [19 x i8] c"\1B7\1B[999;999H\1B[6n\1B8\00"
@errno = global i64 0
@EAGAIN = global i64 0
@EWOULDBLOCK = global i64 0
@.str.11 = [9 x i8] c"\1B[%u;%uR\00"
@TIOCSWINSZ = global i32 0
@TIOCCONS = global i32 0
@switch.table.main = [5 x i64*] [i64* @B9600, i64* @B19200, i64* @B9600, i64* @B57600, i64* @B115200]
@reltable.main = [5 x i32] [i32 trunc (i64 sub (i64 ptrtoint ([6 x i8]* @.str.5 to i64), i64 ptrtoint ([5 x i32]* @reltable.main to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([7 x i8]* @.str.6 to i64), i64 ptrtoint ([5 x i32]* @reltable.main to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([6 x i8]* @.str.5 to i64), i64 ptrtoint ([5 x i32]* @reltable.main to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([7 x i8]* @.str.7 to i64), i64 ptrtoint ([5 x i32]* @reltable.main to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([8 x i8]* @.str.8 to i64), i64 ptrtoint ([5 x i32]* @reltable.main to i64)) to i32)]
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca %struct.termios
%4 = alloca %struct.termios
%5 = alloca %struct.winsize
%6 = alloca i32
%7 = alloca i32
%8 = alloca [128 x i8]
%9 = alloca i32
%10 = alloca %struct.timeval
%11 = bitcast %struct.termios* %3 to i8*
%12 = bitcast %struct.termios* %4 to i8*
%13 = bitcast %struct.winsize* %5 to i8*
%14 = bitcast i32* %6 to i8*
%15 = bitcast i32* %7 to i8*
%16 = getelementptr inbounds [128 x i8], [128 x i8]* %8, i64 0, i64 0
%17 = bitcast i32* %9 to i8*
%18 = bitcast %struct.timeval* %10 to i8*
%19 = load i32, i32* @O_RDONLY
%20 = tail call i32 @open(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i32 %19)
%21 = icmp slt i32 %20, 0
br i1 %21, label %22, label %24
22: ; preds = %2
%23 = tail call i32 @exit(i32 0)
unreachable
24: ; preds = %2
%25 = call i32 @read(i32 %20, i8* %16, i32 80)
%26 = icmp slt i32 %25, 80
br i1 %26, label %27, label %29
27: ; preds = %24
%28 = tail call i32 @exit(i32 0)
unreachable
29: ; preds = %24
%30 = tail call i32 @close(i32 %20)
%31 = getelementptr inbounds [128 x i8], [128 x i8]* %8, i64 0, i64 8
%32 = load i8, i8* %31
%33 = icmp eq i8 %32, 2
br i1 %33, label %36, label %34
34: ; preds = %29
%35 = tail call i32 @exit(i32 0)
unreachable
36: ; preds = %29
%37 = getelementptr inbounds [128 x i8], [128 x i8]* %8, i64 0, i64 36
%38 = load i8, i8* %37
%39 = icmp eq i8 %38, 0
br i1 %39, label %42, label %40
40: ; preds = %36
%41 = tail call i32 @exit(i32 0)
unreachable
42: ; preds = %36
%43 = getelementptr inbounds [128 x i8], [128 x i8]* %8, i64 0, i64 40
%44 = load i8, i8* %43
%45 = icmp eq i8 %44, 1
br i1 %45, label %48, label %46
46: ; preds = %42
%47 = tail call i32 @exit(i32 0)
unreachable
48: ; preds = %42
%49 = getelementptr inbounds [128 x i8], [128 x i8]* %8, i64 0, i64 44
%50 = bitcast i8* %49 to i32*
%51 = load i32, i32* %50
%52 = getelementptr inbounds [128 x i8], [128 x i8]* %8, i64 0, i64 58
%53 = load i8, i8* %52
%54 = getelementptr inbounds [128 x i8], [128 x i8]* %8, i64 0, i64 10
switch i32 %51, label %58 [
i32 1016, label %60
i32 760, label %55
i32 1000, label %56
i32 744, label %57
]
55: ; preds = %48
br label %60
56: ; preds = %48
br label %60
57: ; preds = %48
br label %60
58: ; preds = %48
%59 = tail call i32 @exit(i32 0)
unreachable
60: ; preds = %48, %55, %57, %56
%61 = phi i8* [ getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), %55 ], [ getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0), %57 ], [ getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), %56 ], [ getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), %48 ]
%62 = call i32 @strncpy(i8* %16, i8* %61, i32 128)
%63 = load i32, i32* @O_RDWR
%64 = load i32, i32* @O_NOCTTY
%65 = or i32 %64, %63
%66 = call i32 @open(i8* %16, i32 %65)
%67 = add i8 %53, -3
%68 = icmp ult i8 %67, 5
br i1 %68, label %71, label %69
69: ; preds = %71, %60
%70 = call i32 @exit(i32 0)
unreachable
71: ; preds = %60
%72 = lshr i8 27, %67
%73 = and i8 %72, 1
%74 = icmp eq i8 %73, 0
br i1 %74, label %69, label %75
75: ; preds = %71
%76 = sext i8 %67 to i64
%77 = getelementptr inbounds [5 x i64*], [5 x i64*]* @switch.table.main, i64 0, i64 %76
%78 = load i64*, i64** %77
%79 = sext i8 %67 to i64
%80 = shl i64 %79, 2
%81 = call i8* @llvm.load.relative.i64(i8* bitcast ([5 x i32]* @reltable.main to i8*), i64 %80)
%82 = load i64, i64* %78
%83 = call i32 @strcpy(i8* %54, i8* %81)
%84 = call i32 @tcgetattr(i32 %66, %struct.termios* %3)
%85 = icmp eq i64 %82, 0
br i1 %85, label %89, label %86
86: ; preds = %75
%87 = call i32 @cfsetospeed(%struct.termios* %3, i64 %82)
%88 = call i32 @cfsetispeed(%struct.termios* %3, i64 %82)
br label %89
89: ; preds = %86, %75
%90 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.9, i64 0, i64 0), i8* %16)
%91 = call i32 @tcgetattr(i32 %66, %struct.termios* %4)
%92 = call i32 @cfmakeraw(%struct.termios* %4)
%93 = load i32, i32* @TCSANOW
%94 = call i32 @tcsetattr(i32 %66, i32 %93, %struct.termios* %4)
%95 = load i32, i32* @F_GETFL
%96 = call i32 @fcntl(i32 %66, i32 %95, i32 0)
%97 = load i32, i32* @F_SETFL
%98 = load i32, i32* @O_NONBLOCK
%99 = or i32 %98, %96
%100 = call i32 @fcntl(i32 %66, i32 %97, i32 %99)
br label %101
101: ; preds = %101, %89
%102 = call i32 @read(i32 %66, i8* %16, i32 64)
%103 = icmp sgt i32 %102, 0
br i1 %103, label %101, label %104
104: ; preds = %101
%105 = getelementptr inbounds %struct.timeval, %struct.timeval* %10, i64 0, i32 1
store i64 0, i64* %105
%106 = getelementptr inbounds %struct.timeval, %struct.timeval* %10, i64 0, i32 0
store i32 500000, i32* %106
%107 = call i32 @FD_ZERO(i32* %9)
%108 = call i32 @FD_SET(i32 %66, i32* %9)
%109 = call i64 @write(i32 %66, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.10, i64 0, i64 0), i32 18)
%110 = add nsw i32 %66, 1
br label %111
111: ; preds = %129, %104
%112 = phi i32 [ %130, %129 ], [ 0, %104 ]
%113 = sext i32 %112 to i64
%114 = getelementptr inbounds [128 x i8], [128 x i8]* %8, i64 0, i64 %113
%115 = sub nsw i32 127, %112
br label %116
116: ; preds = %111, %122
%117 = call i64 @select(i32 %110, i32* %9, i32* null, i32* null, %struct.timeval* %10)
%118 = icmp sgt i64 %117, 0
br i1 %118, label %119, label %135
119: ; preds = %116
%120 = call i32 @read(i32 %66, i8* %114, i32 %115)
%121 = icmp slt i32 %120, 0
br i1 %121, label %122, label %129
122: ; preds = %119
%123 = load i64, i64* @errno
%124 = load i64, i64* @EAGAIN
%125 = icmp eq i64 %123, %124
%126 = load i64, i64* @EWOULDBLOCK
%127 = icmp eq i64 %123, %126
%128 = select i1 %125, i1 true, i1 %127
br i1 %128, label %116, label %135
129: ; preds = %119
%130 = add nsw i32 %120, %112
%131 = sext i32 %130 to i64
%132 = getelementptr inbounds [128 x i8], [128 x i8]* %8, i64 0, i64 %131
store i8 0, i8* %132
%133 = call i64 @strchr(i8* %16, i8 signext 82)
%134 = icmp eq i64 %133, 0
br i1 %134, label %111, label %135
135: ; preds = %129, %122, %116
%136 = load i32, i32* @F_SETFL
%137 = call i32 @fcntl(i32 %66, i32 %136, i32 %96)
%138 = getelementptr inbounds %struct.winsize, %struct.winsize* %5, i64 0, i32 2
%139 = bitcast i64* %138 to i8*
%140 = call i32 @sscanf(i8* %16, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.11, i64 0, i64 0), i32* %7, i32* %6)
%141 = icmp eq i32 %140, 2
br i1 %141, label %145, label %142
142: ; preds = %135
%143 = getelementptr inbounds %struct.winsize, %struct.winsize* %5, i64 0, i32 0
store i32 100, i32* %143
%144 = getelementptr inbounds %struct.winsize, %struct.winsize* %5, i64 0, i32 1
store i32 31, i32* %144
br label %155
145: ; preds = %135
%146 = load i32, i32* %6
%147 = load i32, i32* %7
%148 = getelementptr inbounds %struct.winsize, %struct.winsize* %5, i64 0, i32 0
store i32 %146, i32* %148
%149 = getelementptr inbounds %struct.winsize, %struct.winsize* %5, i64 0, i32 1
store i32 %147, i32* %149
%150 = icmp ult i32 %146, 80
%151 = icmp ult i32 %147, 24
%152 = or i1 %150, %151
br i1 %152, label %153, label %155
153: ; preds = %145
%154 = select i1 %151, i32 24, i32 80
store i32 %154, i32* %148
br label %155
155: ; preds = %153, %145, %142
%156 = load i32, i32* @TIOCSWINSZ
%157 = call i32 @ioctl(i32 %66, i32 %156, %struct.winsize* %5)
%158 = load i32, i32* @TCSANOW
%159 = call i32 @tcsetattr(i32 %66, i32 %158, %struct.termios* %3)
%160 = load i32, i32* @TIOCCONS
%161 = call i32 @ioctl(i32 %66, i32 %160, %struct.winsize* null)
ret i32 0
}