#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_cc;
  int /*<<< orphan*/ c_iflag;
};
typedef int /*<<< orphan*/ newtio;
typedef int /*<<< orphan*/ buf;
typedef int /*<<< orphan*/ bauds;

/* Variables and functions */
int /*<<< orphan*/ B1200;
int /*<<< orphan*/ B1800;
int /*<<< orphan*/ B19200;
int /*<<< orphan*/ B2400;
int /*<<< orphan*/ B300;
int /*<<< orphan*/ B38400;
int /*<<< orphan*/ B4800;
int /*<<< orphan*/ B600;
int /*<<< orphan*/ B9600;
int CLOCAL;
int CREAD;
int CS8;
int /*<<< orphan*/ IGNPAR;
int O_NOCTTY;
int O_RDWR;
int /*<<< orphan*/ TCIFLUSH;
int /*<<< orphan*/ TCSANOW;
size_t VTIME;
int /*<<< orphan*/ bzero(struct termios *, int);
int /*<<< orphan*/ *check(char *, int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ flush(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/);
int open(char *, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ puts(char *);
int /*<<< orphan*/ *response(int, char *, int, int);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdout;
int /*<<< orphan*/ strncpy(char *, char *, int);
int strnlen(char *, int);
int tcflush(int, int /*<<< orphan*/);
int /*<<< orphan*/ tcgetattr(int, struct termios *);
int tcsetattr(int, int /*<<< orphan*/, struct termios *);
int write(int, char *, int);
int main(int argc, char *argv[]) {
  int fd, i = 0, len, cmd, ret = -1;
  struct termios newtio;
  char buf[256], zero[] = "\1Z\xD";
  signed short x = 0, y = 0;
  struct baud {
    int code;
    int num;
  } bauds[] = {{B9600, 9600}, {B2400, 2400},   {B300, 300},
               {B600, 600},   {B1200, 1200},   {B1800, 1800},
               {B4800, 4800}, {B19200, 19200}, {B38400, 38400}};
  if (argc < 3) {
    printf("Usage: %s <device> <command>\n", argv[0]);
    puts("Commands are:\n"
         " Z\t- null command\n"
         " NM\t- get controller's name\n"
         " OI\t- get controller's identifier\n"
         " UV\t- get controller's features\n"
         " R\t- reset\n"
         " RD\t- restore defaults\n"
         " CX\t- extended (interactive) calibration\n"
         " CR\t- collect raw coordinates\n"
         " FR\t- raw format\n"
         " FT\t- tablet format (preferred)\n"
         " MS\t- stream mode\n"
         " Ppdsb\t- set communication parameters (see manual)\n"
         " XY\t- (emulated) wait for screen touch and report x,y coordinates");
    return 0;
  }
  if ((fd = open(argv[1], O_RDWR | O_NOCTTY)) == -1) {
    perror(argv[1]);
    return -1;
  }
  cmd = argv[2][0] << 8 | argv[2][1];
  for (i = 0; i < sizeof(bauds) / sizeof(bauds[0]); i++) {
    bzero(&newtio, sizeof(newtio));
    newtio.c_cflag = bauds[i].code | CS8 | CLOCAL | CREAD;
    newtio.c_iflag = IGNPAR;
    newtio.c_cc[VTIME] = 1;
    if (tcflush(fd, TCIFLUSH) == -1) {
      perror("tcflush");
      goto end;
    }
    if (tcsetattr(fd, TCSANOW, &newtio) == -1) {
      perror("tcsetattr");
      goto end;
    }
    flush(fd);
    if (write(fd, zero, strnlen(zero, 7)) < 1) {
      perror("write error");
      goto end;
    }
    if (response(fd, buf, 0, sizeof(buf)) != NULL && buf[1] == '0')
      break;
  }
  if (i == sizeof(bauds) / sizeof(bauds[0])) {
    fputs("Can't detect connection speed\n", stderr);
    goto end;
  }
  fprintf(stderr, "%d baud connection detected\n", bauds[i].num);
  if (!(cmd & ~('X' << 8 | 'Y'))) {
    flush(fd);
    response(fd, buf, 5, 15);
    if (!(buf[0] & 0x80)) {
      fputs("stream error", stderr);
      goto end;
    }
    x = buf[1] & ~0x80;
    x |= (signed short)(buf[2] & ~0x80) << 7;
    y = (buf[3] & ~0x80);
    y |= (signed short)(buf[4] & ~0x80) << 7;
    printf("FT %hd %hd\n", x, y);
    x <<= 2;
    x >>= 5;
    y <<= 2;
    y >>= 5;
    printf("CR %hd %hd\n", x, y);
  } else {
    len = strnlen(argv[2], 7);
    strncpy(buf + 1, argv[2], len);
    buf[0] = 1;
    buf[1 + len] = 0xD;
    buf[1 + len + 1] = '\0';
    tcgetattr(fd, &newtio);
    if (!(cmd & ~('R' << 8))) {
      newtio.c_cc[VTIME] = 8;
      tcsetattr(fd, TCSANOW, &newtio);
    }
    if (!(cmd & ~('R' << 8 | 'D'))) {
      newtio.c_cc[VTIME] = 28;
      tcsetattr(fd, TCSANOW, &newtio);
    }
    flush(fd);
    if (write(fd, buf, len + 2) < 1) {
      perror("write error");
      goto end;
    }
    if (response(fd, buf, 1, sizeof(buf)) != NULL)
      if (check(buf, sizeof(buf)) != NULL) {
        puts(buf + 1);
        fflush(stdout);
      }
    if (!(cmd & ~('C' << 8 | 'X'))) {
      while (response(fd, buf, 3, 6) == NULL)
        ;
      if (check(buf, sizeof(buf)) != NULL) {
        puts(buf + 1);
        fflush(stdout);
      }
      while (response(fd, buf, 3, 6) == NULL)
        ;
      if (check(buf, sizeof(buf)) != NULL) {
        puts(buf + 1);
        fflush(stdout);
      }
    }
  }
  ret = 0;
end:
  if (fd >= 0)
    close(fd);
  return ret;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1a0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0xffffffff,-0x24(%rbp)
mov    0xdb3(%rip),%eax
mov    %eax,-0x144(%rbp)
movw   $0x0,-0x146(%rbp)
movw   $0x0,-0x148(%rbp)
mov    0x2d54(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x190(%rbp)
movl   $0x2580,-0x18c(%rbp)
mov    0x2cf3(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x188(%rbp)
movl   $0x960,-0x184(%rbp)
mov    0x2d1a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x180(%rbp)
movl   $0x12c,-0x17c(%rbp)
mov    0x2d19(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x178(%rbp)
movl   $0x258,-0x174(%rbp)
mov    0x2ca0(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x170(%rbp)
movl   $0x4b0,-0x16c(%rbp)
mov    0x2caf(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x168(%rbp)
movl   $0x708,-0x164(%rbp)
mov    0x2cc6(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x160(%rbp)
movl   $0x12c0,-0x15c(%rbp)
mov    0x2cd5(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x158(%rbp)
movl   $0x4b00,-0x154(%rbp)
mov    0x2c0c(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x150(%rbp)
movl   $0x9600,-0x14c(%rbp)
cmpl   $0x3,-0x8(%rbp)
jge    137d <main+0x15d>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xca6(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
lea    0xcb6(%rip),%rdi
call   1050 <puts@plt>
movl   $0x0,-0x4(%rbp)
jmp    195b <main+0x73b>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2c54(%rip),%rax
mov    (%rax),%esi
mov    0x2bf3(%rip),%rax
or     (%rax),%esi
call   1100 <open@plt>
mov    %eax,-0x14(%rbp)
cmp    $0xffffffff,%eax
jne    13c1 <main+0x1a1>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1110 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    195b <main+0x73b>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
movsbl (%rax),%eax
shl    $0x8,%eax
mov    -0x10(%rbp),%rcx
mov    0x10(%rcx),%rcx
movsbl 0x1(%rcx),%ecx
or     %ecx,%eax
mov    %eax,-0x20(%rbp)
movl   $0x0,-0x18(%rbp)
movslq -0x18(%rbp),%rax
cmp    $0x9,%rax
jae    154d <main+0x32d>
lea    -0x40(%rbp),%rdi
mov    $0x18,%esi
call   1120 <bzero@plt>
movslq -0x18(%rbp),%rax
mov    -0x190(%rbp,%rax,8),%eax
mov    0x2b93(%rip),%rcx
or     (%rcx),%eax
mov    0x2b2a(%rip),%rcx
or     (%rcx),%eax
mov    0x2b89(%rip),%rcx
or     (%rcx),%eax
mov    %eax,-0x40(%rbp)
mov    0x2b25(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x30(%rbp)
mov    -0x38(%rbp),%rax
mov    0x2b1d(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x1,(%rax,%rcx,4)
mov    -0x14(%rbp),%edi
mov    0x2b39(%rip),%rax
mov    (%rax),%esi
call   1070 <tcflush@plt>
cmp    $0xffffffff,%eax
jne    1478 <main+0x258>
lea    0xd53(%rip),%rdi
call   1110 <perror@plt>
jmp    1943 <main+0x723>
mov    -0x14(%rbp),%edi
mov    0x2b56(%rip),%rax
mov    (%rax),%esi
lea    -0x40(%rbp),%rdx
call   10f0 <tcsetattr@plt>
cmp    $0xffffffff,%eax
jne    14a7 <main+0x287>
lea    0xd2c(%rip),%rdi
call   1110 <perror@plt>
jmp    1943 <main+0x723>
mov    -0x14(%rbp),%edi
call   1030 <flush@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x19c(%rbp)
lea    -0x144(%rbp),%rax
mov    %rax,-0x198(%rbp)
lea    -0x144(%rbp),%rdi
mov    $0x7,%esi
call   10a0 <strnlen@plt>
mov    -0x19c(%rbp),%edi
mov    -0x198(%rbp),%rsi
mov    %eax,%edx
call   1060 <write@plt>
cmp    $0x1,%eax
jge    1505 <main+0x2e5>
lea    0xcd8(%rip),%rdi
call   1110 <perror@plt>
jmp    1943 <main+0x723>
mov    -0x14(%rbp),%edi
lea    -0x140(%rbp),%rsi
xor    %edx,%edx
mov    $0x100,%ecx
call   1140 <response@plt>
cmp    $0x0,%rax
je     153a <main+0x31a>
movsbl -0x13f(%rbp),%eax
cmp    $0x30,%eax
jne    153a <main+0x31a>
jmp    154d <main+0x32d>
jmp    153f <main+0x31f>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    13e7 <main+0x1c7>
movslq -0x18(%rbp),%rax
cmp    $0x9,%rax
jne    1575 <main+0x355>
mov    0x2a1e(%rip),%rax
mov    (%rax),%esi
lea    0xc74(%rip),%rdi
call   1090 <fputs@plt>
jmp    1943 <main+0x723>
mov    0x2a04(%rip),%rax
mov    (%rax),%edi
movslq -0x18(%rbp),%rax
mov    -0x18c(%rbp,%rax,8),%edx
lea    0xc6e(%rip),%rsi
call   10c0 <fprintf@plt>
mov    -0x20(%rbp),%eax
and    $0xffffa7a6,%eax
cmp    $0x0,%eax
jne    16e1 <main+0x4c1>
mov    -0x14(%rbp),%edi
call   1030 <flush@plt>
mov    -0x14(%rbp),%edi
lea    -0x140(%rbp),%rsi
mov    $0x5,%edx
mov    $0xf,%ecx
call   1140 <response@plt>
movsbl -0x140(%rbp),%eax
and    $0x80,%eax
cmp    $0x0,%eax
jne    15f6 <main+0x3d6>
mov    0x299d(%rip),%rax
mov    (%rax),%esi
lea    0xc2f(%rip),%rdi
call   1090 <fputs@plt>
jmp    1943 <main+0x723>
movsbl -0x13f(%rbp),%eax
and    $0xffffff7f,%eax
mov    %ax,-0x146(%rbp)
movsbl -0x13e(%rbp),%eax
and    $0xffffff7f,%eax
movswl %ax,%ecx
shl    $0x7,%ecx
movswl -0x146(%rbp),%eax
or     %ecx,%eax
mov    %ax,-0x146(%rbp)
movsbl -0x13d(%rbp),%eax
and    $0xffffff7f,%eax
mov    %ax,-0x148(%rbp)
movsbl -0x13c(%rbp),%eax
and    $0xffffff7f,%eax
movswl %ax,%ecx
shl    $0x7,%ecx
movswl -0x148(%rbp),%eax
or     %ecx,%eax
mov    %ax,-0x148(%rbp)
movswl -0x146(%rbp),%esi
movswl -0x148(%rbp),%edx
lea    0xbb3(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
movswl -0x146(%rbp),%eax
shl    $0x2,%eax
mov    %ax,-0x146(%rbp)
movswl -0x146(%rbp),%eax
sar    $0x5,%eax
mov    %ax,-0x146(%rbp)
movswl -0x148(%rbp),%eax
shl    $0x2,%eax
mov    %ax,-0x148(%rbp)
movswl -0x148(%rbp),%eax
sar    $0x5,%eax
mov    %ax,-0x148(%rbp)
movswl -0x146(%rbp),%esi
movswl -0x148(%rbp),%edx
lea    0xb5f(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
jmp    193c <main+0x71c>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
mov    $0x7,%esi
call   10a0 <strnlen@plt>
mov    %eax,-0x1c(%rbp)
lea    -0x140(%rbp),%rdi
add    $0x1,%rdi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
mov    -0x1c(%rbp),%edx
call   1040 <strncpy@plt>
movb   $0x1,-0x140(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
cltq
movb   $0xd,-0x140(%rbp,%rax,1)
0d
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
add    $0x1,%eax
cltq
movb   $0x0,-0x140(%rbp,%rax,1)
mov    -0x14(%rbp),%edi
lea    -0x40(%rbp),%rsi
call   10e0 <tcgetattr@plt>
mov    -0x20(%rbp),%eax
and    $0xffffadff,%eax
cmp    $0x0,%eax
jne    1782 <main+0x562>
mov    -0x38(%rbp),%rax
mov    0x27fd(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x8,(%rax,%rcx,4)
mov    -0x14(%rbp),%edi
mov    0x2861(%rip),%rax
mov    (%rax),%esi
lea    -0x40(%rbp),%rdx
call   10f0 <tcsetattr@plt>
mov    -0x20(%rbp),%eax
and    $0xffffadbb,%eax
cmp    $0x0,%eax
jne    17bd <main+0x59d>
mov    -0x38(%rbp),%rax
mov    0x27c2(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x1c,(%rax,%rcx,4)
mov    -0x14(%rbp),%edi
mov    0x2826(%rip),%rax
mov    (%rax),%esi
lea    -0x40(%rbp),%rdx
call   10f0 <tcsetattr@plt>
mov    -0x14(%rbp),%edi
call   1030 <flush@plt>
mov    -0x14(%rbp),%edi
lea    -0x140(%rbp),%rsi
mov    -0x1c(%rbp),%edx
add    $0x2,%edx
call   1060 <write@plt>
cmp    $0x1,%eax
jge    17f4 <main+0x5d4>
lea    0x9e9(%rip),%rdi
call   1110 <perror@plt>
jmp    1943 <main+0x723>
mov    -0x14(%rbp),%edi
lea    -0x140(%rbp),%rsi
mov    $0x1,%edx
mov    $0x100,%ecx
call   1140 <response@plt>
cmp    $0x0,%rax
je     1855 <main+0x635>
lea    -0x140(%rbp),%rdi
mov    $0x100,%esi
call   1130 <check@plt>
cmp    $0x0,%rax
je     1850 <main+0x630>
lea    -0x140(%rbp),%rdi
add    $0x1,%rdi
call   1050 <puts@plt>
mov    0x271f(%rip),%rax
mov    (%rax),%edi
call   10d0 <fflush@plt>
jmp    1855 <main+0x635>
mov    -0x20(%rbp),%eax
and    $0xffffbca7,%eax
cmp    $0x0,%eax
jne    1937 <main+0x717>
jmp    186b <main+0x64b>
mov    -0x14(%rbp),%edi
lea    -0x140(%rbp),%rsi
mov    $0x3,%edx
mov    $0x6,%ecx
call   1140 <response@plt>
cmp    $0x0,%rax
jne    1893 <main+0x673>
jmp    186b <main+0x64b>
lea    -0x140(%rbp),%rdi
mov    $0x100,%esi
call   1130 <check@plt>
cmp    $0x0,%rax
je     18cc <main+0x6ac>
lea    -0x140(%rbp),%rdi
add    $0x1,%rdi
call   1050 <puts@plt>
mov    0x26a3(%rip),%rax
mov    (%rax),%edi
call   10d0 <fflush@plt>
jmp    18d1 <main+0x6b1>
mov    -0x14(%rbp),%edi
lea    -0x140(%rbp),%rsi
mov    $0x3,%edx
mov    $0x6,%ecx
call   1140 <response@plt>
cmp    $0x0,%rax
jne    18f9 <main+0x6d9>
jmp    18d1 <main+0x6b1>
lea    -0x140(%rbp),%rdi
mov    $0x100,%esi
call   1130 <check@plt>
cmp    $0x0,%rax
je     1932 <main+0x712>
lea    -0x140(%rbp),%rdi
add    $0x1,%rdi
call   1050 <puts@plt>
mov    0x263d(%rip),%rax
mov    (%rax),%edi
call   10d0 <fflush@plt>
jmp    1937 <main+0x717>
jmp    193c <main+0x71c>
movl   $0x0,-0x24(%rbp)
cmpl   $0x0,-0x14(%rbp)
jl     1955 <main+0x735>
mov    -0x14(%rbp),%edi
call   10b0 <close@plt>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x1a0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x178,%rsp
mov    %rsi,%rbp
movl   $0xd5a01,0x4(%rsp)
mov    0x2d7d(%rip),%rax
mov    (%rax),%r12d
mov    %r12d,0x20(%rsp)
movl   $0x2580,0x24(%rsp)
mov    0x2d1e(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x28(%rsp)
movl   $0x960,0x2c(%rsp)
mov    0x2d49(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x30(%rsp)
movl   $0x12c,0x34(%rsp)
mov    0x2d4c(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x38(%rsp)
movl   $0x258,0x3c(%rsp)
mov    0x2cd7(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x40(%rsp)
movl   $0x4b0,0x44(%rsp)
mov    0x2cea(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x48(%rsp)
movl   $0x708,0x4c(%rsp)
mov    0x2d05(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x50(%rsp)
movl   $0x12c0,0x54(%rsp)
mov    0x2d18(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x58(%rsp)
movl   $0x4b00,0x5c(%rsp)
mov    0x2c53(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x60(%rsp)
movl   $0x9600,0x64(%rsp)
cmp    $0x2,%edi
jg     1326 <main+0x106>
mov    0x0(%rbp),%rsi
lea    0xcf5(%rip),%rdi
xor    %r15d,%r15d
xor    %eax,%eax
call   1080 <printf@plt>
lea    0xd02(%rip),%rdi
call   1050 <puts@plt>
jmp    16af <main+0x48f>
mov    0x8(%rbp),%rdi
mov    0x2caf(%rip),%rax
mov    0x2c50(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
call   1100 <open@plt>
cmp    $0xffffffff,%eax
je     1741 <main+0x521>
mov    %eax,%ebx
mov    %rbp,0x68(%rsp)
mov    0x10(%rbp),%rax
movsbl (%rax),%ecx
shl    $0x8,%ecx
movsbl 0x1(%rax),%eax
or     %ecx,%eax
mov    %eax,(%rsp)
xor    %r15d,%r15d
lea    0x8(%rsp),%r13
mov    0x2c1d(%rip),%r14
lea    0x4(%rsp),%rbp
nopl   0x0(%rax,%rax,1)
mov    %r13,%rdi
mov    $0x18,%esi
call   1120 <bzero@plt>
mov    0x2c14(%rip),%rax
or     (%rax),%r12d
mov    0x2baa(%rip),%rax
or     (%rax),%r12d
mov    0x2c08(%rip),%rax
or     (%rax),%r12d
mov    %r12d,0x8(%rsp)
mov    0x2ba1(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x18(%rsp)
mov    0x10(%rsp),%rax
mov    0x2b97(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x1,(%rax,%rcx,4)
mov    (%r14),%esi
mov    %ebx,%edi
call   1070 <tcflush@plt>
cmp    $0xffffffff,%eax
je     175e <main+0x53e>
mov    0x2beb(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edi
mov    %r13,%rdx
call   10f0 <tcsetattr@plt>
cmp    $0xffffffff,%eax
je     1767 <main+0x547>
mov    %ebx,%edi
call   1030 <flush@plt>
mov    %rbp,%rdi
mov    $0x7,%esi
call   10a0 <strnlen@plt>
mov    %ebx,%edi
mov    %rbp,%rsi
mov    %eax,%edx
call   1060 <write@plt>
test   %eax,%eax
jle    1755 <main+0x535>
mov    %ebx,%edi
lea    0x70(%rsp),%rsi
xor    %edx,%edx
mov    $0x100,%ecx
call   1140 <response@plt>
test   %rax,%rax
je     1449 <main+0x229>
cmpb   $0x30,0x71(%rsp)
je     1461 <main+0x241>
cmp    $0x8,%r15
je     1659 <main+0x439>
mov    0x28(%rsp,%r15,8),%r12d
add    $0x1,%r15
jmp    1380 <main+0x160>
mov    0x2b18(%rip),%rbp
mov    0x0(%rbp),%edi
mov    0x24(%rsp,%r15,8),%edx
lea    0xd83(%rip),%rsi
call   10c0 <fprintf@plt>
mov    (%rsp),%r12d
test   $0xffffa7a6,%r12d
je     166b <main+0x44b>
mov    0x68(%rsp),%rbp
mov    0x10(%rbp),%rdi
mov    $0x7,%esi
call   10a0 <strnlen@plt>
mov    %eax,%r15d
mov    0x10(%rbp),%rsi
lea    0x71(%rsp),%r14
mov    %r14,%rdi
mov    %eax,%edx
call   1040 <strncpy@plt>
movb   $0x1,0x70(%rsp)
movslq %r15d,%rax
lea    0x70(%rsp),%rcx
movw   $0xd,0x1(%rax,%rcx,1)
lea    0x8(%rsp),%rsi
mov    %ebx,%edi
call   10e0 <tcgetattr@plt>
test   $0xffffadff,%r12d
jne    150a <main+0x2ea>
mov    0x10(%rsp),%rax
mov    0x2a75(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x8,(%rax,%rcx,4)
mov    0x2adc(%rip),%rax
mov    (%rax),%esi
lea    0x8(%rsp),%rdx
mov    %ebx,%edi
call   10f0 <tcsetattr@plt>
add    $0x2,%r15d
test   $0xffffadbb,%r12d
jne    1542 <main+0x322>
mov    0x10(%rsp),%rax
mov    0x2a3d(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x1c,(%rax,%rcx,4)
mov    0x2aa4(%rip),%rax
mov    (%rax),%esi
lea    0x8(%rsp),%rdx
mov    %ebx,%edi
call   10f0 <tcsetattr@plt>
mov    %ebx,%edi
call   1030 <flush@plt>
lea    0x70(%rsp),%rsi
mov    %ebx,%edi
mov    %r15d,%edx
call   1060 <write@plt>
test   %eax,%eax
jle    1755 <main+0x535>
lea    0x70(%rsp),%rsi
mov    %ebx,%edi
mov    $0x1,%edx
mov    $0x100,%ecx
call   1140 <response@plt>
test   %rax,%rax
je     15a5 <main+0x385>
lea    0x70(%rsp),%rdi
mov    $0x100,%esi
call   1130 <check@plt>
test   %rax,%rax
je     15a5 <main+0x385>
mov    %r14,%rdi
call   1050 <puts@plt>
mov    0x29ca(%rip),%rax
mov    (%rax),%edi
call   10d0 <fflush@plt>
xor    %r15d,%r15d
test   $0xffffbca7,%r12d
jne    16a4 <main+0x484>
lea    0x70(%rsp),%rbp
nopw   0x0(%rax,%rax,1)
mov    %ebx,%edi
mov    %rbp,%rsi
mov    $0x3,%edx
mov    $0x6,%ecx
call   1140 <response@plt>
test   %rax,%rax
je     15c0 <main+0x3a0>
lea    0x70(%rsp),%rdi
mov    $0x100,%esi
call   1130 <check@plt>
test   %rax,%rax
je     1603 <main+0x3e3>
mov    %r14,%rdi
call   1050 <puts@plt>
mov    0x296c(%rip),%rax
mov    (%rax),%edi
call   10d0 <fflush@plt>
lea    0x70(%rsp),%rbp
nopl   0x0(%rax,%rax,1)
mov    %ebx,%edi
mov    %rbp,%rsi
mov    $0x3,%edx
mov    $0x6,%ecx
call   1140 <response@plt>
test   %rax,%rax
je     1610 <main+0x3f0>
lea    0x70(%rsp),%rdi
mov    $0x100,%esi
call   1130 <check@plt>
test   %rax,%rax
je     16a4 <main+0x484>
mov    %r14,%rdi
call   1050 <puts@plt>
mov    0x291c(%rip),%rax
mov    (%rax),%edi
call   10d0 <fflush@plt>
test   %ebx,%ebx
jns    16a8 <main+0x488>
jmp    16af <main+0x48f>
mov    0x2920(%rip),%rax
mov    (%rax),%esi
lea    0xb72(%rip),%rdi
jmp    1699 <main+0x479>
mov    %ebx,%edi
call   1030 <flush@plt>
lea    0x70(%rsp),%rsi
mov    %ebx,%edi
mov    $0x5,%edx
mov    $0xf,%ecx
call   1140 <response@plt>
cmpb   $0x0,0x70(%rsp)
js     16c4 <main+0x4a4>
mov    0x0(%rbp),%esi
lea    0xb7e(%rip),%rdi
call   1090 <fputs@plt>
mov    $0xffffffff,%r15d
test   %ebx,%ebx
js     16af <main+0x48f>
mov    %ebx,%edi
call   10b0 <close@plt>
mov    %r15d,%eax
add    $0x178,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
movsbl 0x71(%rsp),%eax
and    $0xffffff7f,%eax
movsbl 0x72(%rsp),%r14d
shl    $0x7,%r14d
and    $0xffffbf80,%r14d
or     %eax,%r14d
movsbl 0x73(%rsp),%eax
and    $0xffffff7f,%eax
movsbl 0x74(%rsp),%ebp
shl    $0x7,%ebp
and    $0xffffbf80,%ebp
or     %eax,%ebp
lea    0xb21(%rip),%rdi
xor    %r15d,%r15d
mov    %r14d,%esi
mov    %ebp,%edx
xor    %eax,%eax
call   1080 <printf@plt>
shl    $0x2,%r14d
movswl %r14w,%esi
sar    $0x5,%esi
shl    $0x2,%ebp
movswl %bp,%edx
sar    $0x5,%edx
lea    0xb03(%rip),%rdi
xor    %eax,%eax
call   1080 <printf@plt>
test   %ebx,%ebx
jns    16a8 <main+0x488>
jmp    16af <main+0x48f>
mov    0x8(%rbp),%rdi
call   1110 <perror@plt>
mov    $0xffffffff,%r15d
jmp    16af <main+0x48f>
lea    0xa73(%rip),%rdi
jmp    176e <main+0x54e>
lea    0xa58(%rip),%rdi
jmp    176e <main+0x54e>
lea    0xa57(%rip),%rdi
call   1110 <perror@plt>
jmp    169e <main+0x47e>

LLVM IR (-O0):
%struct.termios = type { i32, i32*, i32 }
%struct.baud = type { i32, i32 }
@__const.main.zero = [4 x i8] c"\01Z\0D\00"
@B9600 = global i32 0
@B2400 = global i32 0
@B300 = global i32 0
@B600 = global i32 0
@B1200 = global i32 0
@B1800 = global i32 0
@B4800 = global i32 0
@B19200 = global i32 0
@B38400 = global i32 0
@.str = [30 x i8] c"Usage: %s <device> <command>\0A\00"
@.str.1 = [415 x i8] c"Commands are:\0A Z\09- null command\0A NM\09- get controller's name\0A OI\09- get controller's identifier\0A UV\09- get controller's features\0A R\09- reset\0A RD\09- restore defaults\0A CX\09- extended (interactive) calibration\0A CR\09- collect raw coordinates\0A FR\09- raw format\0A FT\09- tablet format (preferred)\0A MS\09- stream mode\0A Ppdsb\09- set communication parameters (see manual)\0A XY\09- (emulated) wait for screen touch and report x,y coordinates\00"
@O_RDWR = global i32 0
@O_NOCTTY = global i32 0
@CS8 = global i32 0
@CLOCAL = global i32 0
@CREAD = global i32 0
@IGNPAR = global i32 0
@VTIME = global i64 0
@TCIFLUSH = global i32 0
@.str.2 = [8 x i8] c"tcflush\00"
@TCSANOW = global i32 0
@.str.3 = [10 x i8] c"tcsetattr\00"
@.str.4 = [12 x i8] c"write error\00"
@.str.5 = [31 x i8] c"Can't detect connection speed\0A\00"
@stderr = global i32 0
@.str.6 = [29 x i8] c"%d baud connection detected\0A\00"
@.str.7 = [13 x i8] c"stream error\00"
@.str.8 = [12 x i8] c"FT %hd %hd\0A\00"
@.str.9 = [12 x i8] c"CR %hd %hd\0A\00"
@stdout = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca %struct.termios
%12 = alloca [256 x i8]
%13 = alloca [4 x i8]
%14 = alloca i16
%15 = alloca i16
%16 = alloca [9 x %struct.baud]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %7
store i32 -1, i32* %10
%17 = bitcast [4 x i8]* %13 to i8*
store i16 0, i16* %14
store i16 0, i16* %15
%18 = getelementptr inbounds [9 x %struct.baud], [9 x %struct.baud]* %16, i64 0, i64 0
%19 = getelementptr inbounds %struct.baud, %struct.baud* %18, i32 0, i32 0
%20 = load i32, i32* @B9600
store i32 %20, i32* %19
%21 = getelementptr inbounds %struct.baud, %struct.baud* %18, i32 0, i32 1
store i32 9600, i32* %21
%22 = getelementptr inbounds %struct.baud, %struct.baud* %18, i64 1
%23 = getelementptr inbounds %struct.baud, %struct.baud* %22, i32 0, i32 0
%24 = load i32, i32* @B2400
store i32 %24, i32* %23
%25 = getelementptr inbounds %struct.baud, %struct.baud* %22, i32 0, i32 1
store i32 2400, i32* %25
%26 = getelementptr inbounds %struct.baud, %struct.baud* %22, i64 1
%27 = getelementptr inbounds %struct.baud, %struct.baud* %26, i32 0, i32 0
%28 = load i32, i32* @B300
store i32 %28, i32* %27
%29 = getelementptr inbounds %struct.baud, %struct.baud* %26, i32 0, i32 1
store i32 300, i32* %29
%30 = getelementptr inbounds %struct.baud, %struct.baud* %26, i64 1
%31 = getelementptr inbounds %struct.baud, %struct.baud* %30, i32 0, i32 0
%32 = load i32, i32* @B600
store i32 %32, i32* %31
%33 = getelementptr inbounds %struct.baud, %struct.baud* %30, i32 0, i32 1
store i32 600, i32* %33
%34 = getelementptr inbounds %struct.baud, %struct.baud* %30, i64 1
%35 = getelementptr inbounds %struct.baud, %struct.baud* %34, i32 0, i32 0
%36 = load i32, i32* @B1200
store i32 %36, i32* %35
%37 = getelementptr inbounds %struct.baud, %struct.baud* %34, i32 0, i32 1
store i32 1200, i32* %37
%38 = getelementptr inbounds %struct.baud, %struct.baud* %34, i64 1
%39 = getelementptr inbounds %struct.baud, %struct.baud* %38, i32 0, i32 0
%40 = load i32, i32* @B1800
store i32 %40, i32* %39
%41 = getelementptr inbounds %struct.baud, %struct.baud* %38, i32 0, i32 1
store i32 1800, i32* %41
%42 = getelementptr inbounds %struct.baud, %struct.baud* %38, i64 1
%43 = getelementptr inbounds %struct.baud, %struct.baud* %42, i32 0, i32 0
%44 = load i32, i32* @B4800
store i32 %44, i32* %43
%45 = getelementptr inbounds %struct.baud, %struct.baud* %42, i32 0, i32 1
store i32 4800, i32* %45
%46 = getelementptr inbounds %struct.baud, %struct.baud* %42, i64 1
%47 = getelementptr inbounds %struct.baud, %struct.baud* %46, i32 0, i32 0
%48 = load i32, i32* @B19200
store i32 %48, i32* %47
%49 = getelementptr inbounds %struct.baud, %struct.baud* %46, i32 0, i32 1
store i32 19200, i32* %49
%50 = getelementptr inbounds %struct.baud, %struct.baud* %46, i64 1
%51 = getelementptr inbounds %struct.baud, %struct.baud* %50, i32 0, i32 0
%52 = load i32, i32* @B38400
store i32 %52, i32* %51
%53 = getelementptr inbounds %struct.baud, %struct.baud* %50, i32 0, i32 1
store i32 38400, i32* %53
%54 = load i32, i32* %4
%55 = icmp slt i32 %54, 3
br i1 %55, label %56, label %62
56: ; preds = %2
%57 = load i8**, i8*** %5
%58 = getelementptr inbounds i8*, i8** %57, i64 0
%59 = load i8*, i8** %58
%60 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i8* %59)
%61 = call i32 @puts(i8* getelementptr inbounds ([415 x i8], [415 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %3
br label %368
62: ; preds = %2
%63 = load i8**, i8*** %5
%64 = getelementptr inbounds i8*, i8** %63, i64 1
%65 = load i8*, i8** %64
%66 = load i32, i32* @O_RDWR
%67 = load i32, i32* @O_NOCTTY
%68 = or i32 %66, %67
%69 = call i32 @open(i8* %65, i32 %68)
store i32 %69, i32* %6
%70 = icmp eq i32 %69, -1
br i1 %70, label %71, label %76
71: ; preds = %62
%72 = load i8**, i8*** %5
%73 = getelementptr inbounds i8*, i8** %72, i64 1
%74 = load i8*, i8** %73
%75 = call i32 @perror(i8* %74)
store i32 -1, i32* %3
br label %368
76: ; preds = %62
%77 = load i8**, i8*** %5
%78 = getelementptr inbounds i8*, i8** %77, i64 2
%79 = load i8*, i8** %78
%80 = getelementptr inbounds i8, i8* %79, i64 0
%81 = load i8, i8* %80
%82 = sext i8 %81 to i32
%83 = shl i32 %82, 8
%84 = load i8**, i8*** %5
%85 = getelementptr inbounds i8*, i8** %84, i64 2
%86 = load i8*, i8** %85
%87 = getelementptr inbounds i8, i8* %86, i64 1
%88 = load i8, i8* %87
%89 = sext i8 %88 to i32
%90 = or i32 %83, %89
store i32 %90, i32* %9
store i32 0, i32* %7
br label %91
91: ; preds = %151, %76
%92 = load i32, i32* %7
%93 = sext i32 %92 to i64
%94 = icmp ult i64 %93, 9
br i1 %94, label %95, label %154
95: ; preds = %91
%96 = call i32 @bzero(%struct.termios* %11, i32 24)
%97 = load i32, i32* %7
%98 = sext i32 %97 to i64
%99 = getelementptr inbounds [9 x %struct.baud], [9 x %struct.baud]* %16, i64 0, i64 %98
%100 = getelementptr inbounds %struct.baud, %struct.baud* %99, i32 0, i32 0
%101 = load i32, i32* %100
%102 = load i32, i32* @CS8
%103 = or i32 %101, %102
%104 = load i32, i32* @CLOCAL
%105 = or i32 %103, %104
%106 = load i32, i32* @CREAD
%107 = or i32 %105, %106
%108 = getelementptr inbounds %struct.termios, %struct.termios* %11, i32 0, i32 0
store i32 %107, i32* %108
%109 = load i32, i32* @IGNPAR
%110 = getelementptr inbounds %struct.termios, %struct.termios* %11, i32 0, i32 2
store i32 %109, i32* %110
%111 = getelementptr inbounds %struct.termios, %struct.termios* %11, i32 0, i32 1
%112 = load i32*, i32** %111
%113 = load i64, i64* @VTIME
%114 = getelementptr inbounds i32, i32* %112, i64 %113
store i32 1, i32* %114
%115 = load i32, i32* %6
%116 = load i32, i32* @TCIFLUSH
%117 = call i32 @tcflush(i32 %115, i32 %116)
%118 = icmp eq i32 %117, -1
br i1 %118, label %119, label %121
119: ; preds = %95
%120 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
br label %360
121: ; preds = %95
%122 = load i32, i32* %6
%123 = load i32, i32* @TCSANOW
%124 = call i32 @tcsetattr(i32 %122, i32 %123, %struct.termios* %11)
%125 = icmp eq i32 %124, -1
br i1 %125, label %126, label %128
126: ; preds = %121
%127 = call i32 @perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0))
br label %360
128: ; preds = %121
%129 = load i32, i32* %6
%130 = call i32 @flush(i32 %129)
%131 = load i32, i32* %6
%132 = getelementptr inbounds [4 x i8], [4 x i8]* %13, i64 0, i64 0
%133 = getelementptr inbounds [4 x i8], [4 x i8]* %13, i64 0, i64 0
%134 = call i32 @strnlen(i8* %133, i32 7)
%135 = call i32 @write(i32 %131, i8* %132, i32 %134)
%136 = icmp slt i32 %135, 1
br i1 %136, label %137, label %139
137: ; preds = %128
%138 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0))
br label %360
139: ; preds = %128
%140 = load i32, i32* %6
%141 = getelementptr inbounds [256 x i8], [256 x i8]* %12, i64 0, i64 0
%142 = call i32* @response(i32 %140, i8* %141, i32 0, i32 256)
%143 = icmp ne i32* %142, null
br i1 %143, label %144, label %150
144: ; preds = %139
%145 = getelementptr inbounds [256 x i8], [256 x i8]* %12, i64 0, i64 1
%146 = load i8, i8* %145
%147 = sext i8 %146 to i32
%148 = icmp eq i32 %147, 48
br i1 %148, label %149, label %150
149: ; preds = %144
br label %154
150: ; preds = %144, %139
br label %151
151: ; preds = %150
%152 = load i32, i32* %7
%153 = add nsw i32 %152, 1
store i32 %153, i32* %7
br label %91
154: ; preds = %149, %91
%155 = load i32, i32* %7
%156 = sext i32 %155 to i64
%157 = icmp eq i64 %156, 9
br i1 %157, label %158, label %161
158: ; preds = %154
%159 = load i32, i32* @stderr
%160 = call i32 @fputs(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.5, i64 0, i64 0), i32 %159)
br label %360
161: ; preds = %154
%162 = load i32, i32* @stderr
%163 = load i32, i32* %7
%164 = sext i32 %163 to i64
%165 = getelementptr inbounds [9 x %struct.baud], [9 x %struct.baud]* %16, i64 0, i64 %164
%166 = getelementptr inbounds %struct.baud, %struct.baud* %165, i32 0, i32 1
%167 = load i32, i32* %166
%168 = call i32 @fprintf(i32 %162, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.6, i64 0, i64 0), i32 %167)
%169 = load i32, i32* %9
%170 = and i32 %169, -22618
%171 = icmp ne i32 %170, 0
br i1 %171, label %245, label %172
172: ; preds = %161
%173 = load i32, i32* %6
%174 = call i32 @flush(i32 %173)
%175 = load i32, i32* %6
%176 = getelementptr inbounds [256 x i8], [256 x i8]* %12, i64 0, i64 0
%177 = call i32* @response(i32 %175, i8* %176, i32 5, i32 15)
%178 = getelementptr inbounds [256 x i8], [256 x i8]* %12, i64 0, i64 0
%179 = load i8, i8* %178
%180 = sext i8 %179 to i32
%181 = and i32 %180, 128
%182 = icmp ne i32 %181, 0
br i1 %182, label %186, label %183
183: ; preds = %172
%184 = load i32, i32* @stderr
%185 = call i32 @fputs(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.7, i64 0, i64 0), i32 %184)
br label %360
186: ; preds = %172
%187 = getelementptr inbounds [256 x i8], [256 x i8]* %12, i64 0, i64 1
%188 = load i8, i8* %187
%189 = sext i8 %188 to i32
%190 = and i32 %189, -129
%191 = trunc i32 %190 to i16
store i16 %191, i16* %14
%192 = getelementptr inbounds [256 x i8], [256 x i8]* %12, i64 0, i64 2
%193 = load i8, i8* %192
%194 = sext i8 %193 to i32
%195 = and i32 %194, -129
%196 = trunc i32 %195 to i16
%197 = sext i16 %196 to i32
%198 = shl i32 %197, 7
%199 = load i16, i16* %14
%200 = sext i16 %199 to i32
%201 = or i32 %200, %198
%202 = trunc i32 %201 to i16
store i16 %202, i16* %14
%203 = getelementptr inbounds [256 x i8], [256 x i8]* %12, i64 0, i64 3
%204 = load i8, i8* %203
%205 = sext i8 %204 to i32
%206 = and i32 %205, -129
%207 = trunc i32 %206 to i16
store i16 %207, i16* %15
%208 = getelementptr inbounds [256 x i8], [256 x i8]* %12, i64 0, i64 4
%209 = load i8, i8* %208
%210 = sext i8 %209 to i32
%211 = and i32 %210, -129
%212 = trunc i32 %211 to i16
%213 = sext i16 %212 to i32
%214 = shl i32 %213, 7
%215 = load i16, i16* %15
%216 = sext i16 %215 to i32
%217 = or i32 %216, %214
%218 = trunc i32 %217 to i16
store i16 %218, i16* %15
%219 = load i16, i16* %14
%220 = sext i16 %219 to i32
%221 = load i16, i16* %15
%222 = sext i16 %221 to i32
%223 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.8, i64 0, i64 0), i32 %220, i32 %222)
%224 = load i16, i16* %14
%225 = sext i16 %224 to i32
%226 = shl i32 %225, 2
%227 = trunc i32 %226 to i16
store i16 %227, i16* %14
%228 = load i16, i16* %14
%229 = sext i16 %228 to i32
%230 = ashr i32 %229, 5
%231 = trunc i32 %230 to i16
store i16 %231, i16* %14
%232 = load i16, i16* %15
%233 = sext i16 %232 to i32
%234 = shl i32 %233, 2
%235 = trunc i32 %234 to i16
store i16 %235, i16* %15
%236 = load i16, i16* %15
%237 = sext i16 %236 to i32
%238 = ashr i32 %237, 5
%239 = trunc i32 %238 to i16
store i16 %239, i16* %15
%240 = load i16, i16* %14
%241 = sext i16 %240 to i32
%242 = load i16, i16* %15
%243 = sext i16 %242 to i32
%244 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.9, i64 0, i64 0), i32 %241, i32 %243)
br label %359
245: ; preds = %161
%246 = load i8**, i8*** %5
%247 = getelementptr inbounds i8*, i8** %246, i64 2
%248 = load i8*, i8** %247
%249 = call i32 @strnlen(i8* %248, i32 7)
store i32 %249, i32* %8
%250 = getelementptr inbounds [256 x i8], [256 x i8]* %12, i64 0, i64 0
%251 = getelementptr inbounds i8, i8* %250, i64 1
%252 = load i8**, i8*** %5
%253 = getelementptr inbounds i8*, i8** %252, i64 2
%254 = load i8*, i8** %253
%255 = load i32, i32* %8
%256 = call i32 @strncpy(i8* %251, i8* %254, i32 %255)
%257 = getelementptr inbounds [256 x i8], [256 x i8]* %12, i64 0, i64 0
store i8 1, i8* %257
%258 = load i32, i32* %8
%259 = add nsw i32 1, %258
%260 = sext i32 %259 to i64
%261 = getelementptr inbounds [256 x i8], [256 x i8]* %12, i64 0, i64 %260
store i8 13, i8* %261
%262 = load i32, i32* %8
%263 = add nsw i32 1, %262
%264 = add nsw i32 %263, 1
%265 = sext i32 %264 to i64
%266 = getelementptr inbounds [256 x i8], [256 x i8]* %12, i64 0, i64 %265
store i8 0, i8* %266
%267 = load i32, i32* %6
%268 = call i32 @tcgetattr(i32 %267, %struct.termios* %11)
%269 = load i32, i32* %9
%270 = and i32 %269, -20993
%271 = icmp ne i32 %270, 0
br i1 %271, label %280, label %272
272: ; preds = %245
%273 = getelementptr inbounds %struct.termios, %struct.termios* %11, i32 0, i32 1
%274 = load i32*, i32** %273
%275 = load i64, i64* @VTIME
%276 = getelementptr inbounds i32, i32* %274, i64 %275
store i32 8, i32* %276
%277 = load i32, i32* %6
%278 = load i32, i32* @TCSANOW
%279 = call i32 @tcsetattr(i32 %277, i32 %278, %struct.termios* %11)
br label %280
280: ; preds = %272, %245
%281 = load i32, i32* %9
%282 = and i32 %281, -21061
%283 = icmp ne i32 %282, 0
br i1 %283, label %292, label %284
284: ; preds = %280
%285 = getelementptr inbounds %struct.termios, %struct.termios* %11, i32 0, i32 1
%286 = load i32*, i32** %285
%287 = load i64, i64* @VTIME
%288 = getelementptr inbounds i32, i32* %286, i64 %287
store i32 28, i32* %288
%289 = load i32, i32* %6
%290 = load i32, i32* @TCSANOW
%291 = call i32 @tcsetattr(i32 %289, i32 %290, %struct.termios* %11)
br label %292
292: ; preds = %284, %280
%293 = load i32, i32* %6
%294 = call i32 @flush(i32 %293)
%295 = load i32, i32* %6
%296 = getelementptr inbounds [256 x i8], [256 x i8]* %12, i64 0, i64 0
%297 = load i32, i32* %8
%298 = add nsw i32 %297, 2
%299 = call i32 @write(i32 %295, i8* %296, i32 %298)
%300 = icmp slt i32 %299, 1
br i1 %300, label %301, label %303
301: ; preds = %292
%302 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0))
br label %360
303: ; preds = %292
%304 = load i32, i32* %6
%305 = getelementptr inbounds [256 x i8], [256 x i8]* %12, i64 0, i64 0
%306 = call i32* @response(i32 %304, i8* %305, i32 1, i32 256)
%307 = icmp ne i32* %306, null
br i1 %307, label %308, label %319
308: ; preds = %303
%309 = getelementptr inbounds [256 x i8], [256 x i8]* %12, i64 0, i64 0
%310 = call i32* @check(i8* %309, i32 256)
%311 = icmp ne i32* %310, null
br i1 %311, label %312, label %318
312: ; preds = %308
%313 = getelementptr inbounds [256 x i8], [256 x i8]* %12, i64 0, i64 0
%314 = getelementptr inbounds i8, i8* %313, i64 1
%315 = call i32 @puts(i8* %314)
%316 = load i32, i32* @stdout
%317 = call i32 @fflush(i32 %316)
br label %318
318: ; preds = %312, %308
br label %319
319: ; preds = %318, %303
%320 = load i32, i32* %9
%321 = and i32 %320, -17241
%322 = icmp ne i32 %321, 0
br i1 %322, label %358, label %323
323: ; preds = %319
br label %324
324: ; preds = %329, %323
%325 = load i32, i32* %6
%326 = getelementptr inbounds [256 x i8], [256 x i8]* %12, i64 0, i64 0
%327 = call i32* @response(i32 %325, i8* %326, i32 3, i32 6)
%328 = icmp eq i32* %327, null
br i1 %328, label %329, label %330
329: ; preds = %324
br label %324
330: ; preds = %324
%331 = getelementptr inbounds [256 x i8], [256 x i8]* %12, i64 0, i64 0
%332 = call i32* @check(i8* %331, i32 256)
%333 = icmp ne i32* %332, null
br i1 %333, label %334, label %340
334: ; preds = %330
%335 = getelementptr inbounds [256 x i8], [256 x i8]* %12, i64 0, i64 0
%336 = getelementptr inbounds i8, i8* %335, i64 1
%337 = call i32 @puts(i8* %336)
%338 = load i32, i32* @stdout
%339 = call i32 @fflush(i32 %338)
br label %340
340: ; preds = %334, %330
br label %341
341: ; preds = %346, %340
%342 = load i32, i32* %6
%343 = getelementptr inbounds [256 x i8], [256 x i8]* %12, i64 0, i64 0
%344 = call i32* @response(i32 %342, i8* %343, i32 3, i32 6)
%345 = icmp eq i32* %344, null
br i1 %345, label %346, label %347
346: ; preds = %341
br label %341
347: ; preds = %341
%348 = getelementptr inbounds [256 x i8], [256 x i8]* %12, i64 0, i64 0
%349 = call i32* @check(i8* %348, i32 256)
%350 = icmp ne i32* %349, null
br i1 %350, label %351, label %357
351: ; preds = %347
%352 = getelementptr inbounds [256 x i8], [256 x i8]* %12, i64 0, i64 0
%353 = getelementptr inbounds i8, i8* %352, i64 1
%354 = call i32 @puts(i8* %353)
%355 = load i32, i32* @stdout
%356 = call i32 @fflush(i32 %355)
br label %357
357: ; preds = %351, %347
br label %358
358: ; preds = %357, %319
br label %359
359: ; preds = %358, %186
store i32 0, i32* %10
br label %360
360: ; preds = %359, %301, %183, %158, %137, %126, %119
%361 = load i32, i32* %6
%362 = icmp sge i32 %361, 0
br i1 %362, label %363, label %366
363: ; preds = %360
%364 = load i32, i32* %6
%365 = call i32 @close(i32 %364)
br label %366
366: ; preds = %363, %360
%367 = load i32, i32* %10
store i32 %367, i32* %3
br label %368
368: ; preds = %366, %71, %56
%369 = load i32, i32* %3
ret i32 %369
}

LLVM IR (-O2):
%struct.termios = type { i32, i32*, i32 }
%struct.baud = type { i32, i32 }
@B9600 = global i32 0
@B2400 = global i32 0
@B300 = global i32 0
@B600 = global i32 0
@B1200 = global i32 0
@B1800 = global i32 0
@B4800 = global i32 0
@B19200 = global i32 0
@B38400 = global i32 0
@.str = [30 x i8] c"Usage: %s <device> <command>\0A\00"
@.str.1 = [415 x i8] c"Commands are:\0A Z\09- null command\0A NM\09- get controller's name\0A OI\09- get controller's identifier\0A UV\09- get controller's features\0A R\09- reset\0A RD\09- restore defaults\0A CX\09- extended (interactive) calibration\0A CR\09- collect raw coordinates\0A FR\09- raw format\0A FT\09- tablet format (preferred)\0A MS\09- stream mode\0A Ppdsb\09- set communication parameters (see manual)\0A XY\09- (emulated) wait for screen touch and report x,y coordinates\00"
@O_RDWR = global i32 0
@O_NOCTTY = global i32 0
@CS8 = global i32 0
@CLOCAL = global i32 0
@CREAD = global i32 0
@IGNPAR = global i32 0
@VTIME = global i64 0
@TCIFLUSH = global i32 0
@.str.2 = [8 x i8] c"tcflush\00"
@TCSANOW = global i32 0
@.str.3 = [10 x i8] c"tcsetattr\00"
@.str.4 = [12 x i8] c"write error\00"
@.str.5 = [31 x i8] c"Can't detect connection speed\0A\00"
@stderr = global i32 0
@.str.6 = [29 x i8] c"%d baud connection detected\0A\00"
@.str.7 = [13 x i8] c"stream error\00"
@.str.8 = [12 x i8] c"FT %hd %hd\0A\00"
@.str.9 = [12 x i8] c"CR %hd %hd\0A\00"
@stdout = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.termios
%4 = alloca [256 x i8]
%5 = alloca i32
%6 = alloca [9 x %struct.baud]
%7 = bitcast %struct.termios* %3 to i8*
%8 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%9 = bitcast i32* %5 to i8*
store i32 875009, i32* %5
%10 = bitcast [9 x %struct.baud]* %6 to i8*
%11 = getelementptr inbounds [9 x %struct.baud], [9 x %struct.baud]* %6, i64 0, i64 0, i32 0
%12 = load i32, i32* @B9600
store i32 %12, i32* %11
%13 = getelementptr inbounds [9 x %struct.baud], [9 x %struct.baud]* %6, i64 0, i64 0, i32 1
store i32 9600, i32* %13
%14 = getelementptr inbounds [9 x %struct.baud], [9 x %struct.baud]* %6, i64 0, i64 1, i32 0
%15 = load i32, i32* @B2400
store i32 %15, i32* %14
%16 = getelementptr inbounds [9 x %struct.baud], [9 x %struct.baud]* %6, i64 0, i64 1, i32 1
store i32 2400, i32* %16
%17 = getelementptr inbounds [9 x %struct.baud], [9 x %struct.baud]* %6, i64 0, i64 2, i32 0
%18 = load i32, i32* @B300
store i32 %18, i32* %17
%19 = getelementptr inbounds [9 x %struct.baud], [9 x %struct.baud]* %6, i64 0, i64 2, i32 1
store i32 300, i32* %19
%20 = getelementptr inbounds [9 x %struct.baud], [9 x %struct.baud]* %6, i64 0, i64 3, i32 0
%21 = load i32, i32* @B600
store i32 %21, i32* %20
%22 = getelementptr inbounds [9 x %struct.baud], [9 x %struct.baud]* %6, i64 0, i64 3, i32 1
store i32 600, i32* %22
%23 = getelementptr inbounds [9 x %struct.baud], [9 x %struct.baud]* %6, i64 0, i64 4, i32 0
%24 = load i32, i32* @B1200
store i32 %24, i32* %23
%25 = getelementptr inbounds [9 x %struct.baud], [9 x %struct.baud]* %6, i64 0, i64 4, i32 1
store i32 1200, i32* %25
%26 = getelementptr inbounds [9 x %struct.baud], [9 x %struct.baud]* %6, i64 0, i64 5, i32 0
%27 = load i32, i32* @B1800
store i32 %27, i32* %26
%28 = getelementptr inbounds [9 x %struct.baud], [9 x %struct.baud]* %6, i64 0, i64 5, i32 1
store i32 1800, i32* %28
%29 = getelementptr inbounds [9 x %struct.baud], [9 x %struct.baud]* %6, i64 0, i64 6, i32 0
%30 = load i32, i32* @B4800
store i32 %30, i32* %29
%31 = getelementptr inbounds [9 x %struct.baud], [9 x %struct.baud]* %6, i64 0, i64 6, i32 1
store i32 4800, i32* %31
%32 = getelementptr inbounds [9 x %struct.baud], [9 x %struct.baud]* %6, i64 0, i64 7, i32 0
%33 = load i32, i32* @B19200
store i32 %33, i32* %32
%34 = getelementptr inbounds [9 x %struct.baud], [9 x %struct.baud]* %6, i64 0, i64 7, i32 1
store i32 19200, i32* %34
%35 = getelementptr inbounds [9 x %struct.baud], [9 x %struct.baud]* %6, i64 0, i64 8, i32 0
%36 = load i32, i32* @B38400
store i32 %36, i32* %35
%37 = getelementptr inbounds [9 x %struct.baud], [9 x %struct.baud]* %6, i64 0, i64 8, i32 1
store i32 38400, i32* %37
%38 = icmp slt i32 %0, 3
br i1 %38, label %39, label %43
39: ; preds = %2
%40 = load i8*, i8** %1
%41 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i8* %40)
%42 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([415 x i8], [415 x i8]* @.str.1, i64 0, i64 0))
br label %235
43: ; preds = %2
%44 = getelementptr inbounds i8*, i8** %1, i64 1
%45 = load i8*, i8** %44
%46 = load i32, i32* @O_RDWR
%47 = load i32, i32* @O_NOCTTY
%48 = or i32 %47, %46
%49 = tail call i32 @open(i8* %45, i32 %48)
%50 = icmp eq i32 %49, -1
br i1 %50, label %51, label %54
51: ; preds = %43
%52 = load i8*, i8** %44
%53 = tail call i32 @perror(i8* %52)
br label %235
54: ; preds = %43
%55 = getelementptr inbounds i8*, i8** %1, i64 2
%56 = load i8*, i8** %55
%57 = load i8, i8* %56
%58 = sext i8 %57 to i32
%59 = shl nsw i32 %58, 8
%60 = getelementptr inbounds i8, i8* %56, i64 1
%61 = load i8, i8* %60
%62 = sext i8 %61 to i32
%63 = or i32 %59, %62
%64 = getelementptr inbounds %struct.termios, %struct.termios* %3, i64 0, i32 0
%65 = getelementptr inbounds %struct.termios, %struct.termios* %3, i64 0, i32 2
%66 = getelementptr inbounds %struct.termios, %struct.termios* %3, i64 0, i32 1
%67 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 1
br label %68
68: ; preds = %109, %54
%69 = phi i32 [ %12, %54 ], [ %111, %109 ]
%70 = phi i64 [ 0, %54 ], [ %107, %109 ]
%71 = call i32 @bzero(%struct.termios* %3, i32 24)
%72 = load i32, i32* @CS8
%73 = or i32 %72, %69
%74 = load i32, i32* @CLOCAL
%75 = or i32 %73, %74
%76 = load i32, i32* @CREAD
%77 = or i32 %75, %76
store i32 %77, i32* %64
%78 = load i32, i32* @IGNPAR
store i32 %78, i32* %65
%79 = load i32*, i32** %66
%80 = load i64, i64* @VTIME
%81 = getelementptr inbounds i32, i32* %79, i64 %80
store i32 1, i32* %81
%82 = load i32, i32* @TCIFLUSH
%83 = call i32 @tcflush(i32 %49, i32 %82)
%84 = icmp eq i32 %83, -1
br i1 %84, label %85, label %87
85: ; preds = %68
%86 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
br label %230
87: ; preds = %68
%88 = load i32, i32* @TCSANOW
%89 = call i32 @tcsetattr(i32 %49, i32 %88, %struct.termios* %3)
%90 = icmp eq i32 %89, -1
br i1 %90, label %91, label %93
91: ; preds = %87
%92 = call i32 @perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0))
br label %230
93: ; preds = %87
%94 = call i32 @flush(i32 %49)
%95 = call i32 @strnlen(i8* %9, i32 7)
%96 = call i32 @write(i32 %49, i8* %9, i32 %95)
%97 = icmp slt i32 %96, 1
br i1 %97, label %98, label %100
98: ; preds = %93
%99 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0))
br label %230
100: ; preds = %93
%101 = call i32* @response(i32 %49, i8* %8, i32 0, i32 256)
%102 = icmp ne i32* %101, null
%103 = load i8, i8* %67
%104 = icmp eq i8 %103, 48
%105 = select i1 %102, i1 %104, i1 false
br i1 %105, label %115, label %106
106: ; preds = %100
%107 = add nuw nsw i64 %70, 1
%108 = icmp eq i64 %107, 9
br i1 %108, label %112, label %109
109: ; preds = %106
%110 = getelementptr inbounds [9 x %struct.baud], [9 x %struct.baud]* %6, i64 0, i64 %107, i32 0
%111 = load i32, i32* %110
br label %68
112: ; preds = %106
%113 = load i32, i32* @stderr
%114 = call i32 @fputs(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.5, i64 0, i64 0), i32 %113)
br label %230
115: ; preds = %100
%116 = and i64 %70, 4294967295
%117 = load i32, i32* @stderr
%118 = getelementptr inbounds [9 x %struct.baud], [9 x %struct.baud]* %6, i64 0, i64 %116, i32 1
%119 = load i32, i32* %118
%120 = call i32 @fprintf(i32 %117, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.6, i64 0, i64 0), i32 %119)
%121 = and i32 %63, -22618
%122 = icmp eq i32 %121, 0
br i1 %122, label %123, label %161
123: ; preds = %115
%124 = call i32 @flush(i32 %49)
%125 = call i32* @response(i32 %49, i8* %8, i32 5, i32 15)
%126 = load i8, i8* %8
%127 = icmp sgt i8 %126, -1
br i1 %127, label %128, label %131
128: ; preds = %123
%129 = load i32, i32* @stderr
%130 = call i32 @fputs(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.7, i64 0, i64 0), i32 %129)
br label %230
131: ; preds = %123
%132 = load i8, i8* %67
%133 = sext i8 %132 to i16
%134 = and i16 %133, -129
%135 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 2
%136 = load i8, i8* %135
%137 = sext i8 %136 to i16
%138 = shl nsw i16 %137, 7
%139 = and i16 %138, -16512
%140 = or i16 %139, %134
%141 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 3
%142 = load i8, i8* %141
%143 = sext i8 %142 to i16
%144 = and i16 %143, -129
%145 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 4
%146 = load i8, i8* %145
%147 = sext i8 %146 to i16
%148 = shl nsw i16 %147, 7
%149 = and i16 %148, -16512
%150 = or i16 %149, %144
%151 = sext i16 %140 to i32
%152 = sext i16 %150 to i32
%153 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.8, i64 0, i64 0), i32 %151, i32 %152)
%154 = shl i16 %140, 2
%155 = ashr i16 %154, 5
%156 = shl i16 %150, 2
%157 = ashr i16 %156, 5
%158 = sext i16 %155 to i32
%159 = sext i16 %157 to i32
%160 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.9, i64 0, i64 0), i32 %158, i32 %159)
br label %230
161: ; preds = %115
%162 = load i8*, i8** %55
%163 = call i32 @strnlen(i8* %162, i32 7)
%164 = load i8*, i8** %55
%165 = call i32 @strncpy(i8* %67, i8* %164, i32 %163)
store i8 1, i8* %8
%166 = add nsw i32 %163, 1
%167 = sext i32 %166 to i64
%168 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 %167
store i8 13, i8* %168
%169 = add nsw i32 %163, 2
%170 = sext i32 %169 to i64
%171 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 %170
store i8 0, i8* %171
%172 = call i32 @tcgetattr(i32 %49, %struct.termios* %3)
%173 = and i32 %63, -20993
%174 = icmp eq i32 %173, 0
br i1 %174, label %175, label %181
175: ; preds = %161
%176 = load i32*, i32** %66
%177 = load i64, i64* @VTIME
%178 = getelementptr inbounds i32, i32* %176, i64 %177
store i32 8, i32* %178
%179 = load i32, i32* @TCSANOW
%180 = call i32 @tcsetattr(i32 %49, i32 %179, %struct.termios* %3)
br label %181
181: ; preds = %175, %161
%182 = and i32 %63, -21061
%183 = icmp eq i32 %182, 0
br i1 %183, label %184, label %190
184: ; preds = %181
%185 = load i32*, i32** %66
%186 = load i64, i64* @VTIME
%187 = getelementptr inbounds i32, i32* %185, i64 %186
store i32 28, i32* %187
%188 = load i32, i32* @TCSANOW
%189 = call i32 @tcsetattr(i32 %49, i32 %188, %struct.termios* %3)
br label %190
190: ; preds = %184, %181
%191 = call i32 @flush(i32 %49)
%192 = call i32 @write(i32 %49, i8* %8, i32 %169)
%193 = icmp slt i32 %192, 1
br i1 %193, label %194, label %196
194: ; preds = %190
%195 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0))
br label %230
196: ; preds = %190
%197 = call i32* @response(i32 %49, i8* %8, i32 1, i32 256)
%198 = icmp eq i32* %197, null
br i1 %198, label %206, label %199
199: ; preds = %196
%200 = call i32* @check(i8* %8, i32 256)
%201 = icmp eq i32* %200, null
br i1 %201, label %206, label %202
202: ; preds = %199
%203 = call i32 @puts(i8* %67)
%204 = load i32, i32* @stdout
%205 = call i32 @fflush(i32 %204)
br label %206
206: ; preds = %199, %202, %196
%207 = and i32 %63, -17241
%208 = icmp eq i32 %207, 0
br i1 %208, label %209, label %230
209: ; preds = %206, %209
%210 = call i32* @response(i32 %49, i8* %8, i32 3, i32 6)
%211 = icmp eq i32* %210, null
br i1 %211, label %209, label %212
212: ; preds = %209
%213 = call i32* @check(i8* %8, i32 256)
%214 = icmp eq i32* %213, null
br i1 %214, label %219, label %215
215: ; preds = %212
%216 = call i32 @puts(i8* %67)
%217 = load i32, i32* @stdout
%218 = call i32 @fflush(i32 %217)
br label %219
219: ; preds = %215, %212
br label %220
220: ; preds = %219, %220
%221 = call i32* @response(i32 %49, i8* %8, i32 3, i32 6)
%222 = icmp eq i32* %221, null
br i1 %222, label %220, label %223
223: ; preds = %220
%224 = call i32* @check(i8* %8, i32 256)
%225 = icmp eq i32* %224, null
br i1 %225, label %230, label %226
226: ; preds = %223
%227 = call i32 @puts(i8* %67)
%228 = load i32, i32* @stdout
%229 = call i32 @fflush(i32 %228)
br label %230
230: ; preds = %131, %223, %226, %206, %194, %128, %112, %98, %91, %85
%231 = phi i32 [ -1, %85 ], [ -1, %91 ], [ -1, %98 ], [ -1, %112 ], [ -1, %194 ], [ -1, %128 ], [ 0, %206 ], [ 0, %226 ], [ 0, %223 ], [ 0, %131 ]
%232 = icmp sgt i32 %49, -1
br i1 %232, label %233, label %235
233: ; preds = %230
%234 = call i32 @close(i32 %49)
br label %235
235: ; preds = %230, %233, %51, %39
%236 = phi i32 [ 0, %39 ], [ -1, %51 ], [ %231, %233 ], [ %231, %230 ]
ret i32 %236
}