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

/* Variables and functions */
int B19200;
int BRKINT;
int CLOCAL;
int CREAD;
int CS8;
int CSIZE;
int ECHO;
int ECHONL;
int ICANON;
int ICRNL;
int IEXTEN;
int IGNBRK;
int IGNCR;
int INLCR;
int ISIG;
int ISTRIP;
int IXON;
int /*<<< orphan*/ OPOST;
int O_NOCTTY;
int O_RDWR;
int PARENB;
int PARMRK;
int /*<<< orphan*/ TCIFLUSH;
int /*<<< orphan*/ TCSANOW;
size_t VMIN;
size_t VTIME;
int /*<<< orphan*/ atoi(char *);
int /*<<< orphan*/ bzero(struct termios *, int);
int /*<<< orphan*/ close(int);
int get_cts(int);
int open(char *, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int read(int, int *, int);
int /*<<< orphan*/ rts(int, int /*<<< orphan*/);
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ strcmp(char *, char *);
int /*<<< orphan*/ tcflush(int, int /*<<< orphan*/);
int /*<<< orphan*/ tcgetattr(int, struct termios *);
int /*<<< orphan*/ tcsetattr(int, int /*<<< orphan*/, struct termios *);
int /*<<< orphan*/ usleep(int);
int write(int, char const *, int);
int main(int argc, char *argv[]) {
  struct termios oldtio, newtio;
  uint8_t buf[1024];
  int fd, ret;
  int read_count;
  if (argc < 3) {
    printf("Usage: %s DEVICE high/low/set \t\tVersion:20130110\n", argv[0]);
    return 1;
  }
  fd = open(argv[1], O_RDWR | O_NOCTTY);
  if (fd < 0) {
    printf("Usage: %s DEVICE high/low/set \t\tVersion:20130110\n", argv[0]);
    perror(argv[1]);
    return 1;
  }
  tcgetattr(fd, &oldtio);
  bzero(&newtio, sizeof(newtio));
  newtio.c_cflag |= B19200;
  newtio.c_cflag |= CS8;
  newtio.c_cflag |= CREAD;
  newtio.c_cflag |= CLOCAL;
  newtio.c_cflag &= ~(CSIZE | PARENB);
  newtio.c_iflag &=
      ~(IGNBRK | BRKINT | PARMRK | ISTRIP | INLCR | IGNCR | ICRNL | IXON);
  newtio.c_oflag &= ~OPOST;
  newtio.c_lflag &= ~(ECHO | ECHONL | ICANON | ISIG | IEXTEN);
  newtio.c_cc[VTIME] = 100;
  newtio.c_cc[VMIN] = 0;
  tcflush(fd, TCIFLUSH);
  tcsetattr(fd, TCSANOW, &newtio);
  if (!strcmp(argv[2], "set") && argc == 4) {
    while (1) {
      rts(fd, atoi(argv[3]));
      char b[2] = {'b', 'B'};
      if (write(fd, b, 1) != 1) {
        printf("Error: on write\n");
        goto xout;
      }
      usleep(1000000);
    }
  }
  const char *result = "A";
  int cts;
  cts = get_cts(fd);
  while ((!strcmp(argv[2], "high") && cts != 1) ||
         (!strcmp(argv[2], "low") && cts != 0)) {
    printf("CTS is not what I want. wait another second\n");
    sleep(1);
    cts = get_cts(fd);
  }
  printf("Write [A]\n");
  if (write(fd, result, 1) != 1) {
    printf("Error: on write\n");
    return 1;
  }
  get_cts(fd);
  uint8_t r[2] = {0, 0};
  printf("Read...\n");
  while (read(fd, r, 1) != 1) {
    printf("No data in 10 seconds\n");
  }
  printf(" [0x%02x:%c] \n", r[0], r[0]);
  get_cts(fd);
  printf("Done\n");
xout:
  tcsetattr(fd, TCSANOW, &oldtio);
  close(fd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1080,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
jge    1254 <main+0x44>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xdbf(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1692 <main+0x482>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2d75(%rip),%rax
mov    (%rax),%esi
mov    0x2cdc(%rip),%rax
or     (%rax),%esi
call   10e0 <open@plt>
mov    %eax,-0x1054(%rbp)
cmpl   $0x0,-0x1054(%rbp)
jge    12b4 <main+0xa4>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xd6c(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   10f0 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    1692 <main+0x482>
mov    -0x1054(%rbp),%edi
lea    -0x30(%rbp),%rsi
call   10c0 <tcgetattr@plt>
lea    -0x50(%rbp),%rdi
mov    $0x20,%esi
call   1100 <bzero@plt>
mov    0x2d18(%rip),%rax
mov    (%rax),%eax
or     -0x50(%rbp),%eax
mov    %eax,-0x50(%rbp)
mov    0x2c91(%rip),%rax
mov    (%rax),%eax
or     -0x50(%rbp),%eax
mov    %eax,-0x50(%rbp)
mov    0x2c8a(%rip),%rax
mov    (%rax),%eax
or     -0x50(%rbp),%eax
mov    %eax,-0x50(%rbp)
mov    0x2c0b(%rip),%rax
mov    (%rax),%eax
or     -0x50(%rbp),%eax
mov    %eax,-0x50(%rbp)
mov    0x2c54(%rip),%rax
mov    (%rax),%eax
mov    0x2c8b(%rip),%rcx
or     (%rcx),%eax
xor    $0xffffffff,%eax
and    -0x50(%rbp),%eax
mov    %eax,-0x50(%rbp)
mov    0x2c01(%rip),%rax
mov    (%rax),%eax
mov    0x2c50(%rip),%rcx
or     (%rcx),%eax
mov    0x2ca7(%rip),%rcx
or     (%rcx),%eax
mov    0x2bf6(%rip),%rcx
or     (%rcx),%eax
mov    0x2c75(%rip),%rcx
or     (%rcx),%eax
mov    0x2c64(%rip),%rcx
or     (%rcx),%eax
mov    0x2c6b(%rip),%rcx
or     (%rcx),%eax
mov    0x2c42(%rip),%rcx
or     (%rcx),%eax
xor    $0xffffffff,%eax
and    -0x4c(%rbp),%eax
mov    %eax,-0x4c(%rbp)
mov    0x2c38(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x38(%rbp),%eax
mov    %eax,-0x38(%rbp)
mov    0x2c06(%rip),%rax
mov    (%rax),%eax
mov    0x2b9d(%rip),%rcx
or     (%rcx),%eax
mov    0x2b7c(%rip),%rcx
or     (%rcx),%eax
mov    0x2be3(%rip),%rcx
or     (%rcx),%eax
mov    0x2baa(%rip),%rcx
or     (%rcx),%eax
xor    $0xffffffff,%eax
and    -0x48(%rbp),%eax
mov    %eax,-0x48(%rbp)
mov    -0x40(%rbp),%rax
mov    0x2b5c(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x64,(%rax,%rcx,4)
mov    -0x40(%rbp),%rax
mov    0x2b8f(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x0,(%rax,%rcx,4)
mov    -0x1054(%rbp),%edi
mov    0x2b58(%rip),%rax
mov    (%rax),%esi
call   1050 <tcflush@plt>
mov    -0x1054(%rbp),%edi
mov    0x2b94(%rip),%rax
mov    (%rax),%esi
lea    -0x50(%rbp),%rdx
call   10d0 <tcsetattr@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xc0c(%rip),%rsi
call   10a0 <strcmp@plt>
cmp    $0x0,%eax
jne    14b9 <main+0x2a9>
cmpl   $0x4,-0x8(%rbp)
jne    14b9 <main+0x2a9>
jmp    1443 <main+0x233>
mov    -0x1054(%rbp),%eax
mov    %eax,-0x1078(%rbp)
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
call   1110 <atoi@plt>
mov    -0x1078(%rbp),%edi
mov    %eax,%esi
call   1030 <rts@plt>
mov    0xc4f(%rip),%ax
mov    %ax,-0x105e(%rbp)
mov    -0x1054(%rbp),%edi
lea    -0x105e(%rbp),%rsi
mov    $0x1,%edx
call   1040 <write@plt>
cmp    $0x1,%eax
je     14aa <main+0x29a>
lea    0xb98(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    1668 <main+0x458>
mov    $0xf4240,%edi
call   1130 <usleep@plt>
jmp    1443 <main+0x233>
lea    0xb87(%rip),%rax
mov    %rax,-0x1068(%rbp)
mov    -0x1054(%rbp),%edi
call   10b0 <get_cts@plt>
mov    %eax,-0x106c(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xb62(%rip),%rsi
call   10a0 <strcmp@plt>
cmp    $0x0,%eax
jne    150a <main+0x2fa>
mov    $0x1,%al
cmpl   $0x1,-0x106c(%rbp)
mov    %al,-0x1079(%rbp)
jne    154d <main+0x33d>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xb35(%rip),%rsi
call   10a0 <strcmp@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x107a(%rbp)
jne    1541 <main+0x331>
cmpl   $0x0,-0x106c(%rbp)
setne  %al
mov    %al,-0x107a(%rbp)
mov    -0x107a(%rbp),%al
mov    %al,-0x1079(%rbp)
mov    -0x1079(%rbp),%al
test   $0x1,%al
jne    1560 <main+0x350>
jmp    158e <main+0x37e>
lea    0xaeb(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0x1,%edi
call   1120 <sleep@plt>
mov    -0x1054(%rbp),%edi
call   10b0 <get_cts@plt>
mov    %eax,-0x106c(%rbp)
jmp    14d8 <main+0x2c8>
lea    0xaea(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x1054(%rbp),%edi
mov    -0x1068(%rbp),%rsi
mov    $0x1,%edx
call   1040 <write@plt>
cmp    $0x1,%eax
je     15d6 <main+0x3c6>
lea    0xa73(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1692 <main+0x482>
mov    -0x1054(%rbp),%edi
call   10b0 <get_cts@plt>
lea    -0x1074(%rbp),%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1070 <memset@plt>
lea    0xa8f(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x1054(%rbp),%edi
lea    -0x1074(%rbp),%rsi
mov    $0x1,%edx
call   1090 <read@plt>
cmp    $0x1,%eax
je     1635 <main+0x425>
lea    0xa6a(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    1602 <main+0x3f2>
mov    -0x1074(%rbp),%esi
mov    -0x1074(%rbp),%edx
lea    0xa62(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x1054(%rbp),%edi
call   10b0 <get_cts@plt>
lea    0xa58(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x1054(%rbp),%edi
mov    0x292b(%rip),%rax
mov    (%rax),%esi
lea    -0x30(%rbp),%rdx
call   10d0 <tcsetattr@plt>
mov    -0x1054(%rbp),%edi
call   1080 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x1080,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x58,%rsp
mov    %rsi,%r14
cmp    $0x2,%edi
jg     1241 <main+0x31>
mov    (%r14),%rsi
lea    0xdd0(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
mov    $0x1,%ebp
jmp    158e <main+0x37e>
mov    %edi,%ebp
mov    0x8(%r14),%rdi
mov    0x2d8a(%rip),%rax
mov    0x2cf3(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
call   10e0 <open@plt>
test   %eax,%eax
js     159f <main+0x38f>
mov    %eax,%r12d
lea    0x38(%rsp),%rsi
mov    %eax,%edi
call   10c0 <tcgetattr@plt>
lea    0x18(%rsp),%r15
mov    %r15,%rdi
mov    $0x20,%esi
call   1100 <bzero@plt>
mov    0x2d62(%rip),%rcx
mov    0x18(%rsp),%eax
or     (%rcx),%eax
mov    0x2cdd(%rip),%rcx
or     (%rcx),%eax
mov    0x2cdc(%rip),%rcx
or     (%rcx),%eax
mov    0x2c63(%rip),%rcx
or     (%rcx),%eax
mov    0x2cb2(%rip),%rcx
mov    0x2ceb(%rip),%rdx
mov    (%rdx),%edx
or     (%rcx),%edx
mov    0x2c68(%rip),%rcx
mov    0x2cb9(%rip),%rsi
mov    (%rsi),%esi
or     (%rcx),%esi
mov    0x2d0e(%rip),%rcx
or     (%rcx),%esi
mov    0x2c5d(%rip),%rcx
or     (%rcx),%esi
mov    0x2cdc(%rip),%rcx
or     (%rcx),%esi
mov    0x2ccb(%rip),%rcx
or     (%rcx),%esi
not    %edx
and    %eax,%edx
mov    0x2cce(%rip),%rax
or     (%rax),%esi
mov    %edx,0x18(%rsp)
mov    0x2ca1(%rip),%rax
or     (%rax),%esi
not    %esi
and    %esi,0x1c(%rsp)
mov    0x2c9a(%rip),%rax
mov    (%rax),%eax
not    %eax
and    %eax,0x30(%rsp)
mov    0x2c6b(%rip),%rax
mov    0x2c04(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
mov    0x2be1(%rip),%rax
or     (%rax),%ecx
mov    0x2c48(%rip),%rax
or     (%rax),%ecx
mov    0x2c0f(%rip),%rax
or     (%rax),%ecx
not    %ecx
and    %ecx,0x20(%rsp)
mov    0x28(%rsp),%rax
mov    0x2bc3(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x64,(%rax,%rcx,4)
mov    0x2bfa(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x0,(%rax,%rcx,4)
mov    0x2bc9(%rip),%rax
mov    (%rax),%esi
mov    %r12d,%edi
call   1060 <tcflush@plt>
mov    0x2c08(%rip),%r13
mov    0x0(%r13),%esi
mov    %r12d,%edi
mov    %r15,%rdx
call   10d0 <tcsetattr@plt>
mov    0x10(%r14),%rdi
lea    0xc80(%rip),%rsi
call   10a0 <strcmp@plt>
cmp    $0x4,%ebp
jne    1466 <main+0x256>
test   %eax,%eax
jne    1466 <main+0x256>
mov    0x18(%r14),%rdi
call   1110 <atoi@plt>
mov    %r12d,%edi
mov    %eax,%esi
call   1040 <rts@plt>
movw   $0x4262,0xe(%rsp)
lea    0xe(%rsp),%rsi
mov    %r12d,%edi
mov    $0x1,%edx
call   1050 <write@plt>
cmp    $0x1,%eax
jne    1439 <main+0x229>
lea    0xe(%rsp),%rbp
xchg   %ax,%ax
mov    $0xf4240,%edi
call   1130 <usleep@plt>
mov    0x18(%r14),%rdi
call   1110 <atoi@plt>
mov    %r12d,%edi
mov    %eax,%esi
call   1040 <rts@plt>
movw   $0x4262,0xe(%rsp)
mov    %r12d,%edi
mov    %rbp,%rsi
mov    $0x1,%edx
call   1050 <write@plt>
cmp    $0x1,%eax
je     1400 <main+0x1f0>
lea    0xc69(%rip),%rdi
jmp    1560 <main+0x350>
cs nopw 0x0(%rax,%rax,1)
nop
lea    0xc26(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   1120 <sleep@plt>
mov    %r12d,%edi
call   10b0 <get_cts@plt>
mov    %eax,%ebp
mov    0x10(%r14),%rbx
lea    0xbbd(%rip),%rsi
mov    %rbx,%rdi
call   10a0 <strcmp@plt>
test   %eax,%eax
jne    148c <main+0x27c>
cmp    $0x1,%ebp
jne    1450 <main+0x240>
lea    0xbaa(%rip),%rsi
mov    %rbx,%rdi
call   10a0 <strcmp@plt>
test   %eax,%eax
jne    14a3 <main+0x293>
test   %ebp,%ebp
jne    1450 <main+0x240>
lea    0xba6(%rip),%rdi
call   1030 <puts@plt>
lea    0xb80(%rip),%rsi
mov    $0x1,%ebp
mov    %r12d,%edi
mov    $0x1,%edx
call   1050 <write@plt>
cmp    $0x1,%eax
jne    1582 <main+0x372>
mov    %r12d,%edi
call   10b0 <get_cts@plt>
movq   $0x0,0x10(%rsp)
lea    0xb71(%rip),%rdi
call   1030 <puts@plt>
lea    0x10(%rsp),%rsi
mov    %r12d,%edi
mov    $0x1,%edx
call   1090 <read@plt>
cmp    $0x1,%eax
je     153d <main+0x32d>
lea    0xb5b(%rip),%rbx
lea    0x10(%rsp),%rbp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1030 <puts@plt>
mov    %r12d,%edi
mov    %rbp,%rsi
mov    $0x1,%edx
call   1090 <read@plt>
cmp    $0x1,%eax
jne    1520 <main+0x310>
mov    0x10(%rsp),%edx
lea    0xaf9(%rip),%rdi
mov    %edx,%esi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %r12d,%edi
call   10b0 <get_cts@plt>
lea    0xb02(%rip),%rdi
call   1030 <puts@plt>
mov    0x0(%r13),%esi
lea    0x38(%rsp),%rdx
mov    %r12d,%edi
call   10d0 <tcsetattr@plt>
mov    %r12d,%edi
call   1080 <close@plt>
xor    %ebp,%ebp
jmp    158e <main+0x37e>
lea    0xb20(%rip),%rdi
call   1030 <puts@plt>
mov    %ebp,%eax
add    $0x58,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    (%r14),%rsi
lea    0xa57(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
mov    0x8(%r14),%rdi
call   10f0 <perror@plt>
jmp    1237 <main+0x27>

LLVM IR (-O0):
%struct.termios = type { i32, i32, i32, i32*, i32 }
@.str = [50 x i8] c"Usage: %s DEVICE high/low/set \09\09Version:20130110\0A\00"
@O_RDWR = global i32 0
@O_NOCTTY = global i32 0
@B19200 = global i32 0
@CS8 = global i32 0
@CREAD = global i32 0
@CLOCAL = global i32 0
@CSIZE = global i32 0
@PARENB = global i32 0
@IGNBRK = global i32 0
@BRKINT = global i32 0
@PARMRK = global i32 0
@ISTRIP = global i32 0
@INLCR = global i32 0
@IGNCR = global i32 0
@ICRNL = global i32 0
@IXON = global i32 0
@OPOST = global i32 0
@ECHO = global i32 0
@ECHONL = global i32 0
@ICANON = global i32 0
@ISIG = global i32 0
@IEXTEN = global i32 0
@VTIME = global i64 0
@VMIN = global i64 0
@TCIFLUSH = global i32 0
@TCSANOW = global i32 0
@.str.1 = [4 x i8] c"set\00"
@__const.main.b = [2 x i8] c"bB"
@.str.2 = [17 x i8] c"Error: on write\0A\00"
@.str.3 = [2 x i8] c"A\00"
@.str.4 = [5 x i8] c"high\00"
@.str.5 = [4 x i8] c"low\00"
@.str.6 = [45 x i8] c"CTS is not what I want. wait another second\0A\00"
@.str.7 = [11 x i8] c"Write [A]\0A\00"
@.str.8 = [9 x i8] c"Read...\0A\00"
@.str.9 = [23 x i8] c"No data in 10 seconds\0A\00"
@.str.10 = [15 x i8] c" [0x%02x:%c] \0A\00"
@.str.11 = [6 x i8] c"Done\0A\00"
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 [1024 x i32]
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca [2 x i8]
%13 = alloca i8*
%14 = alloca i32
%15 = alloca [2 x i32]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%16 = load i32, i32* %4
%17 = icmp slt i32 %16, 3
br i1 %17, label %18, label %23
18: ; preds = %2
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i64 0
%21 = load i8*, i8** %20
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str, i64 0, i64 0), i8* %21)
store i32 1, i32* %3
br label %210
23: ; preds = %2
%24 = load i8**, i8*** %5
%25 = getelementptr inbounds i8*, i8** %24, i64 1
%26 = load i8*, i8** %25
%27 = load i32, i32* @O_RDWR
%28 = load i32, i32* @O_NOCTTY
%29 = or i32 %27, %28
%30 = call i32 @open(i8* %26, i32 %29)
store i32 %30, i32* %9
%31 = load i32, i32* %9
%32 = icmp slt i32 %31, 0
br i1 %32, label %33, label %42
33: ; preds = %23
%34 = load i8**, i8*** %5
%35 = getelementptr inbounds i8*, i8** %34, i64 0
%36 = load i8*, i8** %35
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str, i64 0, i64 0), i8* %36)
%38 = load i8**, i8*** %5
%39 = getelementptr inbounds i8*, i8** %38, i64 1
%40 = load i8*, i8** %39
%41 = call i32 @perror(i8* %40)
store i32 1, i32* %3
br label %210
42: ; preds = %23
%43 = load i32, i32* %9
%44 = call i32 @tcgetattr(i32 %43, %struct.termios* %6)
%45 = call i32 @bzero(%struct.termios* %7, i32 32)
%46 = load i32, i32* @B19200
%47 = getelementptr inbounds %struct.termios, %struct.termios* %7, i32 0, i32 0
%48 = load i32, i32* %47
%49 = or i32 %48, %46
store i32 %49, i32* %47
%50 = load i32, i32* @CS8
%51 = getelementptr inbounds %struct.termios, %struct.termios* %7, i32 0, i32 0
%52 = load i32, i32* %51
%53 = or i32 %52, %50
store i32 %53, i32* %51
%54 = load i32, i32* @CREAD
%55 = getelementptr inbounds %struct.termios, %struct.termios* %7, i32 0, i32 0
%56 = load i32, i32* %55
%57 = or i32 %56, %54
store i32 %57, i32* %55
%58 = load i32, i32* @CLOCAL
%59 = getelementptr inbounds %struct.termios, %struct.termios* %7, i32 0, i32 0
%60 = load i32, i32* %59
%61 = or i32 %60, %58
store i32 %61, i32* %59
%62 = load i32, i32* @CSIZE
%63 = load i32, i32* @PARENB
%64 = or i32 %62, %63
%65 = xor i32 %64, -1
%66 = getelementptr inbounds %struct.termios, %struct.termios* %7, i32 0, i32 0
%67 = load i32, i32* %66
%68 = and i32 %67, %65
store i32 %68, i32* %66
%69 = load i32, i32* @IGNBRK
%70 = load i32, i32* @BRKINT
%71 = or i32 %69, %70
%72 = load i32, i32* @PARMRK
%73 = or i32 %71, %72
%74 = load i32, i32* @ISTRIP
%75 = or i32 %73, %74
%76 = load i32, i32* @INLCR
%77 = or i32 %75, %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* @IXON
%83 = or i32 %81, %82
%84 = xor i32 %83, -1
%85 = getelementptr inbounds %struct.termios, %struct.termios* %7, i32 0, i32 1
%86 = load i32, i32* %85
%87 = and i32 %86, %84
store i32 %87, i32* %85
%88 = load i32, i32* @OPOST
%89 = xor i32 %88, -1
%90 = getelementptr inbounds %struct.termios, %struct.termios* %7, i32 0, i32 4
%91 = load i32, i32* %90
%92 = and i32 %91, %89
store i32 %92, i32* %90
%93 = load i32, i32* @ECHO
%94 = load i32, i32* @ECHONL
%95 = or i32 %93, %94
%96 = load i32, i32* @ICANON
%97 = or i32 %95, %96
%98 = load i32, i32* @ISIG
%99 = or i32 %97, %98
%100 = load i32, i32* @IEXTEN
%101 = or i32 %99, %100
%102 = xor i32 %101, -1
%103 = getelementptr inbounds %struct.termios, %struct.termios* %7, i32 0, i32 2
%104 = load i32, i32* %103
%105 = and i32 %104, %102
store i32 %105, i32* %103
%106 = getelementptr inbounds %struct.termios, %struct.termios* %7, i32 0, i32 3
%107 = load i32*, i32** %106
%108 = load i64, i64* @VTIME
%109 = getelementptr inbounds i32, i32* %107, i64 %108
store i32 100, i32* %109
%110 = getelementptr inbounds %struct.termios, %struct.termios* %7, i32 0, i32 3
%111 = load i32*, i32** %110
%112 = load i64, i64* @VMIN
%113 = getelementptr inbounds i32, i32* %111, i64 %112
store i32 0, i32* %113
%114 = load i32, i32* %9
%115 = load i32, i32* @TCIFLUSH
%116 = call i32 @tcflush(i32 %114, i32 %115)
%117 = load i32, i32* %9
%118 = load i32, i32* @TCSANOW
%119 = call i32 @tcsetattr(i32 %117, i32 %118, %struct.termios* %7)
%120 = load i8**, i8*** %5
%121 = getelementptr inbounds i8*, i8** %120, i64 2
%122 = load i8*, i8** %121
%123 = call i32 @strcmp(i8* %122, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%124 = icmp ne i32 %123, 0
br i1 %124, label %145, label %125
125: ; preds = %42
%126 = load i32, i32* %4
%127 = icmp eq i32 %126, 4
br i1 %127, label %128, label %145
128: ; preds = %125
br label %129
129: ; preds = %128, %143
%130 = load i32, i32* %9
%131 = load i8**, i8*** %5
%132 = getelementptr inbounds i8*, i8** %131, i64 3
%133 = load i8*, i8** %132
%134 = call i32 @atoi(i8* %133)
%135 = call i32 @rts(i32 %130, i32 %134)
%136 = bitcast [2 x i8]* %12 to i8*
%137 = load i32, i32* %9
%138 = getelementptr inbounds [2 x i8], [2 x i8]* %12, i64 0, i64 0
%139 = call i32 @write(i32 %137, i8* %138, i32 1)
%140 = icmp ne i32 %139, 1
br i1 %140, label %141, label %143
141: ; preds = %129
%142 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
br label %204
143: ; preds = %129
%144 = call i32 @usleep(i32 1000000)
br label %129
145: ; preds = %125, %42
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0), i8** %13
%146 = load i32, i32* %9
%147 = call i32 @get_cts(i32 %146)
store i32 %147, i32* %14
br label %148
148: ; preds = %170, %145
%149 = load i8**, i8*** %5
%150 = getelementptr inbounds i8*, i8** %149, i64 2
%151 = load i8*, i8** %150
%152 = call i32 @strcmp(i8* %151, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%153 = icmp ne i32 %152, 0
br i1 %153, label %157, label %154
154: ; preds = %148
%155 = load i32, i32* %14
%156 = icmp ne i32 %155, 1
br i1 %156, label %168, label %157
157: ; preds = %154, %148
%158 = load i8**, i8*** %5
%159 = getelementptr inbounds i8*, i8** %158, i64 2
%160 = load i8*, i8** %159
%161 = call i32 @strcmp(i8* %160, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0))
%162 = icmp ne i32 %161, 0
br i1 %162, label %166, label %163
163: ; preds = %157
%164 = load i32, i32* %14
%165 = icmp ne i32 %164, 0
br label %166
166: ; preds = %163, %157
%167 = phi i1 [ false, %157 ], [ %165, %163 ]
br label %168
168: ; preds = %166, %154
%169 = phi i1 [ true, %154 ], [ %167, %166 ]
br i1 %169, label %170, label %175
170: ; preds = %168
%171 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.6, i64 0, i64 0))
%172 = call i32 @sleep(i32 1)
%173 = load i32, i32* %9
%174 = call i32 @get_cts(i32 %173)
store i32 %174, i32* %14
br label %148
175: ; preds = %168
%176 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.7, i64 0, i64 0))
%177 = load i32, i32* %9
%178 = load i8*, i8** %13
%179 = call i32 @write(i32 %177, i8* %178, i32 1)
%180 = icmp ne i32 %179, 1
br i1 %180, label %181, label %183
181: ; preds = %175
%182 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %3
br label %210
183: ; preds = %175
%184 = load i32, i32* %9
%185 = call i32 @get_cts(i32 %184)
%186 = bitcast [2 x i32]* %15 to i8*
%187 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.8, i64 0, i64 0))
br label %188
188: ; preds = %193, %183
%189 = load i32, i32* %9
%190 = getelementptr inbounds [2 x i32], [2 x i32]* %15, i64 0, i64 0
%191 = call i32 @read(i32 %189, i32* %190, i32 1)
%192 = icmp ne i32 %191, 1
br i1 %192, label %193, label %195
193: ; preds = %188
%194 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.9, i64 0, i64 0))
br label %188
195: ; preds = %188
%196 = getelementptr inbounds [2 x i32], [2 x i32]* %15, i64 0, i64 0
%197 = load i32, i32* %196
%198 = getelementptr inbounds [2 x i32], [2 x i32]* %15, i64 0, i64 0
%199 = load i32, i32* %198
%200 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.10, i64 0, i64 0), i32 %197, i32 %199)
%201 = load i32, i32* %9
%202 = call i32 @get_cts(i32 %201)
%203 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.11, i64 0, i64 0))
br label %204
204: ; preds = %195, %141
%205 = load i32, i32* %9
%206 = load i32, i32* @TCSANOW
%207 = call i32 @tcsetattr(i32 %205, i32 %206, %struct.termios* %6)
%208 = load i32, i32* %9
%209 = call i32 @close(i32 %208)
store i32 0, i32* %3
br label %210
210: ; preds = %204, %181, %33, %18
%211 = load i32, i32* %3
ret i32 %211
}

LLVM IR (-O2):
%struct.termios = type { i32, i32, i32, i32*, i32 }
@.str = [50 x i8] c"Usage: %s DEVICE high/low/set \09\09Version:20130110\0A\00"
@O_RDWR = global i32 0
@O_NOCTTY = global i32 0
@B19200 = global i32 0
@CS8 = global i32 0
@CREAD = global i32 0
@CLOCAL = global i32 0
@CSIZE = global i32 0
@PARENB = global i32 0
@IGNBRK = global i32 0
@BRKINT = global i32 0
@PARMRK = global i32 0
@ISTRIP = global i32 0
@INLCR = global i32 0
@IGNCR = global i32 0
@ICRNL = global i32 0
@IXON = global i32 0
@OPOST = global i32 0
@ECHO = global i32 0
@ECHONL = global i32 0
@ICANON = global i32 0
@ISIG = global i32 0
@IEXTEN = global i32 0
@VTIME = global i64 0
@VMIN = global i64 0
@TCIFLUSH = global i32 0
@TCSANOW = global i32 0
@.str.1 = [4 x i8] c"set\00"
@.str.3 = [2 x i8] c"A\00"
@.str.4 = [5 x i8] c"high\00"
@.str.5 = [4 x i8] c"low\00"
@.str.10 = [15 x i8] c" [0x%02x:%c] \0A\00"
@str = [10 x i8] c"Write [A]\00"
@str.12 = [8 x i8] c"Read...\00"
@str.13 = [5 x i8] c"Done\00"
@str.14 = [22 x i8] c"No data in 10 seconds\00"
@str.16 = [44 x i8] c"CTS is not what I want. wait another second\00"
@str.17 = [16 x i8] c"Error: on write\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.termios
%4 = alloca %struct.termios
%5 = alloca i16
%6 = alloca i64
%7 = bitcast %struct.termios* %3 to i8*
%8 = bitcast %struct.termios* %4 to i8*
%9 = icmp slt i32 %0, 3
br i1 %9, label %10, label %13
10: ; preds = %2
%11 = load i8*, i8** %1
%12 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([50 x i8], [50 x i8]* @.str, i64 0, i64 0), i8* %11)
br label %154
13: ; preds = %2
%14 = getelementptr inbounds i8*, i8** %1, i64 1
%15 = load i8*, i8** %14
%16 = load i32, i32* @O_RDWR
%17 = load i32, i32* @O_NOCTTY
%18 = or i32 %17, %16
%19 = tail call i32 @open(i8* %15, i32 %18)
%20 = icmp slt i32 %19, 0
br i1 %20, label %21, label %26
21: ; preds = %13
%22 = load i8*, i8** %1
%23 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([50 x i8], [50 x i8]* @.str, i64 0, i64 0), i8* %22)
%24 = load i8*, i8** %14
%25 = tail call i32 @perror(i8* %24)
br label %154
26: ; preds = %13
%27 = call i32 @tcgetattr(i32 %19, %struct.termios* %3)
%28 = call i32 @bzero(%struct.termios* %4, i32 32)
%29 = load i32, i32* @B19200
%30 = getelementptr inbounds %struct.termios, %struct.termios* %4, i64 0, i32 0
%31 = load i32, i32* %30
%32 = or i32 %31, %29
%33 = load i32, i32* @CS8
%34 = or i32 %33, %32
%35 = load i32, i32* @CREAD
%36 = or i32 %35, %34
%37 = load i32, i32* @CLOCAL
%38 = or i32 %37, %36
%39 = load i32, i32* @CSIZE
%40 = load i32, i32* @PARENB
%41 = or i32 %40, %39
%42 = xor i32 %41, -1
%43 = and i32 %38, %42
store i32 %43, i32* %30
%44 = load i32, i32* @IGNBRK
%45 = load i32, i32* @BRKINT
%46 = or i32 %45, %44
%47 = load i32, i32* @PARMRK
%48 = or i32 %46, %47
%49 = load i32, i32* @ISTRIP
%50 = or i32 %48, %49
%51 = load i32, i32* @INLCR
%52 = or i32 %50, %51
%53 = load i32, i32* @IGNCR
%54 = or i32 %52, %53
%55 = load i32, i32* @ICRNL
%56 = or i32 %54, %55
%57 = load i32, i32* @IXON
%58 = or i32 %56, %57
%59 = xor i32 %58, -1
%60 = getelementptr inbounds %struct.termios, %struct.termios* %4, i64 0, i32 1
%61 = load i32, i32* %60
%62 = and i32 %61, %59
store i32 %62, i32* %60
%63 = load i32, i32* @OPOST
%64 = xor i32 %63, -1
%65 = getelementptr inbounds %struct.termios, %struct.termios* %4, i64 0, i32 4
%66 = load i32, i32* %65
%67 = and i32 %66, %64
store i32 %67, i32* %65
%68 = load i32, i32* @ECHO
%69 = load i32, i32* @ECHONL
%70 = or i32 %69, %68
%71 = load i32, i32* @ICANON
%72 = or i32 %70, %71
%73 = load i32, i32* @ISIG
%74 = or i32 %72, %73
%75 = load i32, i32* @IEXTEN
%76 = or i32 %74, %75
%77 = xor i32 %76, -1
%78 = getelementptr inbounds %struct.termios, %struct.termios* %4, i64 0, i32 2
%79 = load i32, i32* %78
%80 = and i32 %79, %77
store i32 %80, i32* %78
%81 = getelementptr inbounds %struct.termios, %struct.termios* %4, i64 0, i32 3
%82 = load i32*, i32** %81
%83 = load i64, i64* @VTIME
%84 = getelementptr inbounds i32, i32* %82, i64 %83
store i32 100, i32* %84
%85 = load i64, i64* @VMIN
%86 = getelementptr inbounds i32, i32* %82, i64 %85
store i32 0, i32* %86
%87 = load i32, i32* @TCIFLUSH
%88 = call i32 @tcflush(i32 %19, i32 %87)
%89 = load i32, i32* @TCSANOW
%90 = call i32 @tcsetattr(i32 %19, i32 %89, %struct.termios* %4)
%91 = getelementptr inbounds i8*, i8** %1, i64 2
%92 = load i8*, i8** %91
%93 = call i32 @strcmp(i8* dereferenceable(1) %92, i8* dereferenceable(4) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%94 = icmp eq i32 %93, 0
%95 = icmp eq i32 %0, 4
%96 = and i1 %95, %94
br i1 %96, label %97, label %114
97: ; preds = %26
%98 = getelementptr inbounds i8*, i8** %1, i64 3
%99 = load i8*, i8** %98
%100 = call i32 @atoi(i8* %99)
%101 = call i32 @rts(i32 %19, i32 %100)
%102 = bitcast i16* %5 to i8*
store i16 16994, i16* %5
%103 = call i32 @write(i32 %19, i8* %102, i32 1)
%104 = icmp eq i32 %103, 1
br i1 %104, label %107, label %105
105: ; preds = %107, %97
%106 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str.17, i64 0, i64 0))
br label %150
107: ; preds = %97, %107
%108 = call i32 @usleep(i32 1000000)
%109 = load i8*, i8** %98
%110 = call i32 @atoi(i8* %109)
%111 = call i32 @rts(i32 %19, i32 %110)
store i16 16994, i16* %5
%112 = call i32 @write(i32 %19, i8* %102, i32 1)
%113 = icmp eq i32 %112, 1
br i1 %113, label %107, label %105
114: ; preds = %26, %126
%115 = call i32 @get_cts(i32 %19)
%116 = load i8*, i8** %91
%117 = call i32 @strcmp(i8* dereferenceable(1) %116, i8* dereferenceable(5) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%118 = icmp eq i32 %117, 0
%119 = icmp ne i32 %115, 1
%120 = select i1 %118, i1 %119, i1 false
br i1 %120, label %126, label %121
121: ; preds = %114
%122 = call i32 @strcmp(i8* dereferenceable(1) %116, i8* dereferenceable(4) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0))
%123 = icmp eq i32 %122, 0
%124 = icmp ne i32 %115, 0
%125 = select i1 %123, i1 %124, i1 false
br i1 %125, label %126, label %129
126: ; preds = %114, %121
%127 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([44 x i8], [44 x i8]* @str.16, i64 0, i64 0))
%128 = call i32 @sleep(i32 1)
br label %114
129: ; preds = %121
%130 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @str, i64 0, i64 0))
%131 = call i32 @write(i32 %19, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0), i32 1)
%132 = icmp eq i32 %131, 1
br i1 %132, label %135, label %133
133: ; preds = %129
%134 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str.17, i64 0, i64 0))
br label %154
135: ; preds = %129
%136 = call i32 @get_cts(i32 %19)
store i64 0, i64* %6
%137 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @str.12, i64 0, i64 0))
%138 = bitcast i64* %6 to i32*
%139 = call i32 @read(i32 %19, i32* %138, i32 1)
%140 = icmp eq i32 %139, 1
br i1 %140, label %145, label %141
141: ; preds = %135, %141
%142 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str.14, i64 0, i64 0))
%143 = call i32 @read(i32 %19, i32* %138, i32 1)
%144 = icmp eq i32 %143, 1
br i1 %144, label %145, label %141
145: ; preds = %141, %135
%146 = load i32, i32* %138
%147 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.10, i64 0, i64 0), i32 %146, i32 %146)
%148 = call i32 @get_cts(i32 %19)
%149 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @str.13, i64 0, i64 0))
br label %150
150: ; preds = %105, %145
%151 = load i32, i32* @TCSANOW
%152 = call i32 @tcsetattr(i32 %19, i32 %151, %struct.termios* %3)
%153 = call i32 @close(i32 %19)
br label %154
154: ; preds = %150, %133, %21, %10
%155 = phi i32 [ 1, %10 ], [ 1, %21 ], [ 0, %150 ], [ 1, %133 ]
ret i32 %155
}