#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_iflag;
  int c_cflag;
  int *c_cc;
  scalar_t__ c_oflag;
};
typedef int /*<<< orphan*/ line;

/* Variables and functions */
int B9600;
int CLOCAL;
int CREAD;
int CS8;
int /*<<< orphan*/ F_SETFL;
int IGNBRK;
int IGNPAR;
int O_EXCL;
int O_NDELAY;
int O_NOCTTY;
int /*<<< orphan*/ O_NONBLOCK;
int O_RDWR;
int /*<<< orphan*/ TCSAFLUSH;
int /*<<< orphan*/ TIOCMBIC;
int /*<<< orphan*/ TIOCMBIS;
int /*<<< orphan*/ TIOCMGET;
int TIOCM_CTS;
int TIOCM_RTS;
size_t VMIN;
size_t VTIME;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fcntl(int, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
scalar_t__ ioctl(int, int /*<<< orphan*/, int *);
int open(char *, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdin;
char *strerror(int /*<<< orphan*/);
scalar_t__ tcgetattr(int, struct termios *);
scalar_t__ tcsetattr(int, int /*<<< orphan*/, struct termios *);
int main(int argc, char **argv) {
  int fd;
  int rts = 0;
  char line[200];
  char *devName = argv[1];
  struct termios attr;
  if (argc != 2) {
    fprintf(stderr, "Usage: rts port\n");
    exit(1);
  }
  if ((fd = open(devName, O_RDWR | O_EXCL | O_NOCTTY | O_NDELAY)) < 0) {
    fprintf(stderr, "Unable to open serial port '%s': %s\n", devName,
            strerror(errno));
    exit(2);
  }
  fcntl(fd, F_SETFL, O_NONBLOCK);
  if (tcgetattr(fd, &attr) < 0) {
    fprintf(stderr, "Call to tcgetattr failed: %s\n", strerror(errno));
    exit(3);
  }
  attr.c_iflag = IGNBRK | IGNPAR;
  attr.c_oflag = 0;
  attr.c_cflag = CLOCAL | CREAD | CS8 | B9600;
  attr.c_cc[VMIN] = 1;
  attr.c_cc[VTIME] = 0;
  if (tcsetattr(fd, TCSAFLUSH, &attr) < 0) {
    fprintf(stderr, "Call to tcsetattr failed: %s\n", strerror(errno));
    exit(4);
  }
  printf("Press RETURN to toggle the RTS state\n");
  while (fgets(line, sizeof(line), stdin) != NULL) {
    int bits;
    if (ioctl(fd, TIOCMGET, &bits) != 0) {
      fprintf(stderr, "ioctl TIOCMGET failed\n");
    }
    rts = !rts;
    bits = TIOCM_RTS;
    if (rts) {
      printf("Setting RTS, CTS = %d\n", (bits & TIOCM_CTS) != 0);
      if (ioctl(fd, TIOCMBIS, &bits) != 0) {
        fprintf(stderr, "ioctl TIOCMSET failed\n");
      }
    } else {
      printf("Clearing RTS, CTS = %d\n", (bits & TIOCM_CTS) != 0);
      if (ioctl(fd, TIOCMBIC, &bits) != 0) {
        fprintf(stderr, "ioctl TIOCMSET failed\n");
      }
    }
  }
  close(fd);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x120,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0xe8(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     120a <main+0x5a>
mov    0x2d88(%rip),%rax
mov    (%rax),%edi
lea    0xe07(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
mov    -0xe8(%rbp),%rdi
mov    0x2dd0(%rip),%rax
mov    (%rax),%esi
mov    0x2d4f(%rip),%rax
or     (%rax),%esi
mov    0x2d5e(%rip),%rax
or     (%rax),%esi
mov    0x2d25(%rip),%rax
or     (%rax),%esi
call   10b0 <open@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jge    1299 <main+0xe9>
mov    0x2d2b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x114(%rbp)
mov    -0xe8(%rbp),%rax
mov    %rax,-0x110(%rbp)
mov    0x2cf6(%rip),%rax
mov    (%rax),%edi
call   10d0 <strerror@plt>
mov    -0x114(%rbp),%edi
mov    -0x110(%rbp),%rdx
mov    %rax,%rcx
lea    0xd89(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    $0x2,%edi
call   10c0 <exit@plt>
mov    -0x14(%rbp),%edi
mov    0x2cc5(%rip),%rax
mov    (%rax),%esi
mov    0x2d2c(%rip),%rax
mov    (%rax),%edx
call   1030 <fcntl@plt>
mov    -0x14(%rbp),%edi
lea    -0x100(%rbp),%rsi
call   1090 <tcgetattr@plt>
cmp    $0x0,%rax
jge    130a <main+0x15a>
mov    0x2ca5(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x118(%rbp)
mov    0x2c7e(%rip),%rax
mov    (%rax),%edi
call   10d0 <strerror@plt>
mov    -0x118(%rbp),%edi
mov    %rax,%rdx
lea    0xd3d(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    $0x3,%edi
call   10c0 <exit@plt>
mov    0x2c3f(%rip),%rax
mov    (%rax),%eax
mov    0x2c1e(%rip),%rcx
or     (%rcx),%eax
mov    %eax,-0x100(%rbp)
movq   $0x0,-0xf0(%rbp)
mov    0x2bf4(%rip),%rax
mov    (%rax),%eax
mov    0x2c7b(%rip),%rcx
or     (%rcx),%eax
mov    0x2c6a(%rip),%rcx
or     (%rcx),%eax
mov    0x2c71(%rip),%rcx
or     (%rcx),%eax
mov    %eax,-0xfc(%rbp)
mov    -0xf8(%rbp),%rax
mov    0x2c43(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x1,(%rax,%rcx,4)
mov    -0xf8(%rbp),%rax
mov    0x2bcb(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x0,(%rax,%rcx,4)
mov    -0x14(%rbp),%edi
mov    0x2c4f(%rip),%rax
mov    (%rax),%esi
lea    -0x100(%rbp),%rdx
call   10a0 <tcsetattr@plt>
cmp    $0x0,%rax
jge    13e7 <main+0x237>
mov    0x2bc8(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x11c(%rbp)
mov    0x2ba1(%rip),%rax
mov    (%rax),%edi
call   10d0 <strerror@plt>
mov    -0x11c(%rbp),%edi
mov    %rax,%rdx
lea    0xc7e(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    $0x4,%edi
call   10c0 <exit@plt>
lea    0xc84(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0xe0(%rbp),%rdi
mov    0x2bcd(%rip),%rax
mov    (%rax),%edx
mov    $0xc8,%esi
call   1070 <fgets@plt>
cmp    $0x0,%rax
je     154d <main+0x39d>
mov    -0x14(%rbp),%edi
mov    0x2b7d(%rip),%rax
mov    (%rax),%esi
lea    -0x104(%rbp),%rdx
call   1050 <ioctl@plt>
cmp    $0x0,%rax
je     1452 <main+0x2a2>
mov    0x2b36(%rip),%rax
mov    (%rax),%edi
lea    0xc4d(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
cmpl   $0x0,-0x18(%rbp)
setne  %al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x18(%rbp)
mov    0x2b5e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x104(%rbp)
cmpl   $0x0,-0x18(%rbp)
je     14e2 <main+0x332>
mov    -0x104(%rbp),%eax
mov    0x2ab7(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
setne  %al
and    $0x1,%al
movzbl %al,%esi
lea    0xc12(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x14(%rbp),%edi
mov    0x2ae2(%rip),%rax
mov    (%rax),%esi
lea    -0x104(%rbp),%rdx
call   1050 <ioctl@plt>
cmp    $0x0,%rax
je     14dd <main+0x32d>
mov    0x2aab(%rip),%rax
mov    (%rax),%edi
lea    0xbf0(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
jmp    1548 <main+0x398>
mov    -0x104(%rbp),%eax
mov    0x2a51(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
setne  %al
and    $0x1,%al
movzbl %al,%esi
lea    0xbda(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x14(%rbp),%edi
mov    0x2a6c(%rip),%rax
mov    (%rax),%esi
lea    -0x104(%rbp),%rdx
call   1050 <ioctl@plt>
cmp    $0x0,%rax
je     1543 <main+0x393>
mov    0x2a45(%rip),%rax
mov    (%rax),%edi
lea    0xb8a(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
jmp    1548 <main+0x398>
jmp    13f5 <main+0x245>
mov    -0x14(%rbp),%edi
call   1060 <close@plt>
mov    -0x4(%rbp),%eax
add    $0x120,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xe8,%rsp
cmp    $0x2,%edi
jne    13fb <main+0x23b>
mov    0x2e07(%rip),%rcx
mov    0x2d88(%rip),%rax
mov    (%rax),%eax
or     (%rcx),%eax
mov    0x2d95(%rip),%rcx
or     (%rcx),%eax
mov    0x8(%rsi),%rbp
mov    0x2d58(%rip),%rcx
or     (%rcx),%eax
mov    %rbp,%rdi
mov    %eax,%esi
call   10c0 <open@plt>
test   %eax,%eax
js     141c <main+0x25c>
mov    %eax,%ebx
mov    0x2d4b(%rip),%rax
mov    (%rax),%esi
mov    0x2db2(%rip),%rax
mov    (%rax),%edx
mov    %ebx,%edi
call   1040 <fcntl@plt>
lea    0x8(%rsp),%rsi
mov    %ebx,%edi
call   10a0 <tcgetattr@plt>
test   %rax,%rax
js     1453 <main+0x293>
mov    0x2d05(%rip),%rax
mov    0x2ce6(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
mov    %ecx,0x8(%rsp)
movq   $0x0,0x18(%rsp)
mov    0x2cbe(%rip),%rax
mov    0x2d47(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
mov    0x2d34(%rip),%rax
or     (%rax),%ecx
mov    0x2d3b(%rip),%rax
or     (%rax),%ecx
mov    %ecx,0xc(%rsp)
mov    0x10(%rsp),%rax
mov    0x2d11(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x1,(%rax,%rcx,4)
mov    0x2ca0(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x0,(%rax,%rcx,4)
mov    0x2d27(%rip),%rax
mov    (%rax),%esi
lea    0x8(%rsp),%rdx
mov    %ebx,%edi
call   10b0 <tcsetattr@plt>
test   %rax,%rax
js     1487 <main+0x2c7>
lea    0xdf8(%rip),%rdi
call   1030 <puts@plt>
mov    0x2ced(%rip),%rax
mov    (%rax),%edx
lea    0x20(%rsp),%rdi
mov    $0xc8,%esi
call   1080 <fgets@plt>
test   %rax,%rax
je     13e0 <main+0x220>
lea    0x4(%rsp),%r14
mov    0x2c37(%rip),%r13
lea    0x20(%rsp),%r12
mov    0x2c63(%rip),%rbp
xor    %r15d,%r15d
jmp    1343 <main+0x183>
nopw   0x0(%rax,%rax,1)
xor    $0x1,%r15d
mov    0x2ca5(%rip),%rax
mov    (%rax),%edx
mov    %r12,%rdi
mov    $0xc8,%esi
call   1080 <fgets@plt>
test   %rax,%rax
je     13e0 <main+0x220>
mov    0x2c56(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edi
mov    %r14,%rdx
call   1060 <ioctl@plt>
test   %rax,%rax
je     136c <main+0x1ac>
mov    0x0(%rbp),%edi
lea    0xd0d(%rip),%rsi
xor    %eax,%eax
call   1090 <fprintf@plt>
mov    0x2c55(%rip),%rax
mov    (%rax),%eax
xor    %esi,%esi
test   %eax,0x0(%r13)
setne  %sil
mov    %eax,0x4(%rsp)
test   %r15d,%r15d
je     13a0 <main+0x1e0>
lea    0xd28(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x2be3(%rip),%rax
jmp    13b5 <main+0x1f5>
nop
lea    0xce2(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x2bdb(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edi
mov    %r14,%rdx
call   1060 <ioctl@plt>
test   %rax,%rax
je     1320 <main+0x160>
mov    0x0(%rbp),%edi
lea    0xccc(%rip),%rsi
xor    %eax,%eax
call   1090 <fprintf@plt>
jmp    1320 <main+0x160>
mov    %ebx,%edi
call   1070 <close@plt>
xor    %eax,%eax
add    $0xe8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2b76(%rip),%rax
mov    (%rax),%edi
lea    0xbf5(%rip),%rsi
xor    %eax,%eax
call   1090 <fprintf@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
mov    0x2b55(%rip),%rax
mov    (%rax),%ebx
mov    0x2b34(%rip),%rax
mov    (%rax),%edi
call   10e0 <strerror@plt>
lea    0xbd7(%rip),%rsi
mov    %ebx,%edi
mov    %rbp,%rdx
mov    %rax,%rcx
xor    %eax,%eax
call   1090 <fprintf@plt>
mov    $0x2,%edi
call   10d0 <exit@plt>
mov    0x2b1e(%rip),%rax
mov    (%rax),%ebx
mov    0x2afd(%rip),%rax
mov    (%rax),%edi
call   10e0 <strerror@plt>
lea    0xbc5(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
xor    %eax,%eax
call   1090 <fprintf@plt>
mov    $0x3,%edi
call   10d0 <exit@plt>
mov    0x2aea(%rip),%rax
mov    (%rax),%ebx
mov    0x2ac9(%rip),%rax
mov    (%rax),%edi
call   10e0 <strerror@plt>
lea    0xbaf(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
xor    %eax,%eax
call   1090 <fprintf@plt>
mov    $0x4,%edi
call   10d0 <exit@plt>

LLVM IR (-O0):
%struct.termios = type { i32, i32, i32*, i64 }
@stderr = global i32 0
@.str = [17 x i8] c"Usage: rts port\0A\00"
@O_RDWR = global i32 0
@O_EXCL = global i32 0
@O_NOCTTY = global i32 0
@O_NDELAY = global i32 0
@.str.1 = [37 x i8] c"Unable to open serial port '%s': %s\0A\00"
@errno = global i32 0
@F_SETFL = global i32 0
@O_NONBLOCK = global i32 0
@.str.2 = [30 x i8] c"Call to tcgetattr failed: %s\0A\00"
@IGNBRK = global i32 0
@IGNPAR = global i32 0
@CLOCAL = global i32 0
@CREAD = global i32 0
@CS8 = global i32 0
@B9600 = global i32 0
@VMIN = global i64 0
@VTIME = global i64 0
@TCSAFLUSH = global i32 0
@.str.3 = [30 x i8] c"Call to tcsetattr failed: %s\0A\00"
@.str.4 = [38 x i8] c"Press RETURN to toggle the RTS state\0A\00"
@stdin = global i32 0
@TIOCMGET = global i32 0
@.str.5 = [23 x i8] c"ioctl TIOCMGET failed\0A\00"
@TIOCM_RTS = global i32 0
@.str.6 = [23 x i8] c"Setting RTS, CTS = %d\0A\00"
@TIOCM_CTS = global i32 0
@TIOCMBIS = global i32 0
@.str.7 = [23 x i8] c"ioctl TIOCMSET failed\0A\00"
@.str.8 = [24 x i8] c"Clearing RTS, CTS = %d\0A\00"
@TIOCMBIC = 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 [200 x i8]
%9 = alloca i8*
%10 = alloca %struct.termios
%11 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %7
%12 = load i8**, i8*** %5
%13 = getelementptr inbounds i8*, i8** %12, i64 1
%14 = load i8*, i8** %13
store i8* %14, i8** %9
%15 = load i32, i32* %4
%16 = icmp ne i32 %15, 2
br i1 %16, label %17, label %21
17: ; preds = %2
%18 = load i32, i32* @stderr
%19 = call i32 (i32, i8*, ...) @fprintf(i32 %18, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
%20 = call i32 @exit(i32 1)
unreachable
21: ; preds = %2
%22 = load i8*, i8** %9
%23 = load i32, i32* @O_RDWR
%24 = load i32, i32* @O_EXCL
%25 = or i32 %23, %24
%26 = load i32, i32* @O_NOCTTY
%27 = or i32 %25, %26
%28 = load i32, i32* @O_NDELAY
%29 = or i32 %27, %28
%30 = call i32 @open(i8* %22, i32 %29)
store i32 %30, i32* %6
%31 = icmp slt i32 %30, 0
br i1 %31, label %32, label %39
32: ; preds = %21
%33 = load i32, i32* @stderr
%34 = load i8*, i8** %9
%35 = load i32, i32* @errno
%36 = call i8* @strerror(i32 %35)
%37 = call i32 (i32, i8*, ...) @fprintf(i32 %33, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0), i8* %34, i8* %36)
%38 = call i32 @exit(i32 2)
unreachable
39: ; preds = %21
%40 = load i32, i32* %6
%41 = load i32, i32* @F_SETFL
%42 = load i32, i32* @O_NONBLOCK
%43 = call i32 @fcntl(i32 %40, i32 %41, i32 %42)
%44 = load i32, i32* %6
%45 = call i64 @tcgetattr(i32 %44, %struct.termios* %10)
%46 = icmp slt i64 %45, 0
br i1 %46, label %47, label %53
47: ; preds = %39
%48 = load i32, i32* @stderr
%49 = load i32, i32* @errno
%50 = call i8* @strerror(i32 %49)
%51 = call i32 (i32, i8*, ...) @fprintf(i32 %48, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0), i8* %50)
%52 = call i32 @exit(i32 3)
unreachable
53: ; preds = %39
%54 = load i32, i32* @IGNBRK
%55 = load i32, i32* @IGNPAR
%56 = or i32 %54, %55
%57 = getelementptr inbounds %struct.termios, %struct.termios* %10, i32 0, i32 0
store i32 %56, i32* %57
%58 = getelementptr inbounds %struct.termios, %struct.termios* %10, i32 0, i32 3
store i64 0, i64* %58
%59 = load i32, i32* @CLOCAL
%60 = load i32, i32* @CREAD
%61 = or i32 %59, %60
%62 = load i32, i32* @CS8
%63 = or i32 %61, %62
%64 = load i32, i32* @B9600
%65 = or i32 %63, %64
%66 = getelementptr inbounds %struct.termios, %struct.termios* %10, i32 0, i32 1
store i32 %65, i32* %66
%67 = getelementptr inbounds %struct.termios, %struct.termios* %10, i32 0, i32 2
%68 = load i32*, i32** %67
%69 = load i64, i64* @VMIN
%70 = getelementptr inbounds i32, i32* %68, i64 %69
store i32 1, i32* %70
%71 = getelementptr inbounds %struct.termios, %struct.termios* %10, i32 0, i32 2
%72 = load i32*, i32** %71
%73 = load i64, i64* @VTIME
%74 = getelementptr inbounds i32, i32* %72, i64 %73
store i32 0, i32* %74
%75 = load i32, i32* %6
%76 = load i32, i32* @TCSAFLUSH
%77 = call i64 @tcsetattr(i32 %75, i32 %76, %struct.termios* %10)
%78 = icmp slt i64 %77, 0
br i1 %78, label %79, label %85
79: ; preds = %53
%80 = load i32, i32* @stderr
%81 = load i32, i32* @errno
%82 = call i8* @strerror(i32 %81)
%83 = call i32 (i32, i8*, ...) @fprintf(i32 %80, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.3, i64 0, i64 0), i8* %82)
%84 = call i32 @exit(i32 4)
unreachable
85: ; preds = %53
%86 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.4, i64 0, i64 0))
br label %87
87: ; preds = %138, %85
%88 = getelementptr inbounds [200 x i8], [200 x i8]* %8, i64 0, i64 0
%89 = load i32, i32* @stdin
%90 = call i32* @fgets(i8* %88, i32 200, i32 %89)
%91 = icmp ne i32* %90, null
br i1 %91, label %92, label %139
92: ; preds = %87
%93 = load i32, i32* %6
%94 = load i32, i32* @TIOCMGET
%95 = call i64 @ioctl(i32 %93, i32 %94, i32* %11)
%96 = icmp ne i64 %95, 0
br i1 %96, label %97, label %100
97: ; preds = %92
%98 = load i32, i32* @stderr
%99 = call i32 (i32, i8*, ...) @fprintf(i32 %98, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.5, i64 0, i64 0))
br label %100
100: ; preds = %97, %92
%101 = load i32, i32* %7
%102 = icmp ne i32 %101, 0
%103 = xor i1 %102, true
%104 = zext i1 %103 to i32
store i32 %104, i32* %7
%105 = load i32, i32* @TIOCM_RTS
store i32 %105, i32* %11
%106 = load i32, i32* %7
%107 = icmp ne i32 %106, 0
br i1 %107, label %108, label %123
108: ; preds = %100
%109 = load i32, i32* %11
%110 = load i32, i32* @TIOCM_CTS
%111 = and i32 %109, %110
%112 = icmp ne i32 %111, 0
%113 = zext i1 %112 to i32
%114 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.6, i64 0, i64 0), i32 %113)
%115 = load i32, i32* %6
%116 = load i32, i32* @TIOCMBIS
%117 = call i64 @ioctl(i32 %115, i32 %116, i32* %11)
%118 = icmp ne i64 %117, 0
br i1 %118, label %119, label %122
119: ; preds = %108
%120 = load i32, i32* @stderr
%121 = call i32 (i32, i8*, ...) @fprintf(i32 %120, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.7, i64 0, i64 0))
br label %122
122: ; preds = %119, %108
br label %138
123: ; preds = %100
%124 = load i32, i32* %11
%125 = load i32, i32* @TIOCM_CTS
%126 = and i32 %124, %125
%127 = icmp ne i32 %126, 0
%128 = zext i1 %127 to i32
%129 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.8, i64 0, i64 0), i32 %128)
%130 = load i32, i32* %6
%131 = load i32, i32* @TIOCMBIC
%132 = call i64 @ioctl(i32 %130, i32 %131, i32* %11)
%133 = icmp ne i64 %132, 0
br i1 %133, label %134, label %137
134: ; preds = %123
%135 = load i32, i32* @stderr
%136 = call i32 (i32, i8*, ...) @fprintf(i32 %135, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.7, i64 0, i64 0))
br label %137
137: ; preds = %134, %123
br label %138
138: ; preds = %137, %122
br label %87
139: ; preds = %87
%140 = load i32, i32* %6
%141 = call i32 @close(i32 %140)
%142 = load i32, i32* %3
ret i32 %142
}

LLVM IR (-O2):
%struct.termios = type { i32, i32, i32*, i64 }
@stderr = global i32 0
@.str = [17 x i8] c"Usage: rts port\0A\00"
@O_RDWR = global i32 0
@O_EXCL = global i32 0
@O_NOCTTY = global i32 0
@O_NDELAY = global i32 0
@.str.1 = [37 x i8] c"Unable to open serial port '%s': %s\0A\00"
@errno = global i32 0
@F_SETFL = global i32 0
@O_NONBLOCK = global i32 0
@.str.2 = [30 x i8] c"Call to tcgetattr failed: %s\0A\00"
@IGNBRK = global i32 0
@IGNPAR = global i32 0
@CLOCAL = global i32 0
@CREAD = global i32 0
@CS8 = global i32 0
@B9600 = global i32 0
@VMIN = global i64 0
@VTIME = global i64 0
@TCSAFLUSH = global i32 0
@.str.3 = [30 x i8] c"Call to tcsetattr failed: %s\0A\00"
@stdin = global i32 0
@TIOCMGET = global i32 0
@.str.5 = [23 x i8] c"ioctl TIOCMGET failed\0A\00"
@TIOCM_RTS = global i32 0
@.str.6 = [23 x i8] c"Setting RTS, CTS = %d\0A\00"
@TIOCM_CTS = global i32 0
@TIOCMBIS = global i32 0
@.str.7 = [23 x i8] c"ioctl TIOCMSET failed\0A\00"
@.str.8 = [24 x i8] c"Clearing RTS, CTS = %d\0A\00"
@TIOCMBIC = global i32 0
@str = [37 x i8] c"Press RETURN to toggle the RTS state\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [200 x i8]
%4 = alloca %struct.termios
%5 = alloca i32
%6 = getelementptr inbounds [200 x i8], [200 x i8]* %3, i64 0, i64 0
%7 = getelementptr inbounds i8*, i8** %1, i64 1
%8 = load i8*, i8** %7
%9 = bitcast %struct.termios* %4 to i8*
%10 = icmp eq i32 %0, 2
br i1 %10, label %15, label %11
11: ; preds = %2
%12 = load i32, i32* @stderr
%13 = tail call i32 (i32, i8*, ...) @fprintf(i32 %12, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
%14 = tail call i32 @exit(i32 1)
unreachable
15: ; preds = %2
%16 = load i32, i32* @O_RDWR
%17 = load i32, i32* @O_EXCL
%18 = or i32 %17, %16
%19 = load i32, i32* @O_NOCTTY
%20 = or i32 %18, %19
%21 = load i32, i32* @O_NDELAY
%22 = or i32 %20, %21
%23 = tail call i32 @open(i8* %8, i32 %22)
%24 = icmp slt i32 %23, 0
br i1 %24, label %25, label %31
25: ; preds = %15
%26 = load i32, i32* @stderr
%27 = load i32, i32* @errno
%28 = tail call i8* @strerror(i32 %27)
%29 = tail call i32 (i32, i8*, ...) @fprintf(i32 %26, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0), i8* %8, i8* %28)
%30 = tail call i32 @exit(i32 2)
unreachable
31: ; preds = %15
%32 = load i32, i32* @F_SETFL
%33 = load i32, i32* @O_NONBLOCK
%34 = tail call i32 @fcntl(i32 %23, i32 %32, i32 %33)
%35 = call i64 @tcgetattr(i32 %23, %struct.termios* %4)
%36 = icmp slt i64 %35, 0
br i1 %36, label %37, label %43
37: ; preds = %31
%38 = load i32, i32* @stderr
%39 = load i32, i32* @errno
%40 = call i8* @strerror(i32 %39)
%41 = call i32 (i32, i8*, ...) @fprintf(i32 %38, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0), i8* %40)
%42 = call i32 @exit(i32 3)
unreachable
43: ; preds = %31
%44 = load i32, i32* @IGNBRK
%45 = load i32, i32* @IGNPAR
%46 = or i32 %45, %44
%47 = getelementptr inbounds %struct.termios, %struct.termios* %4, i64 0, i32 0
store i32 %46, i32* %47
%48 = getelementptr inbounds %struct.termios, %struct.termios* %4, i64 0, i32 3
store i64 0, i64* %48
%49 = load i32, i32* @CLOCAL
%50 = load i32, i32* @CREAD
%51 = or i32 %50, %49
%52 = load i32, i32* @CS8
%53 = or i32 %51, %52
%54 = load i32, i32* @B9600
%55 = or i32 %53, %54
%56 = getelementptr inbounds %struct.termios, %struct.termios* %4, i64 0, i32 1
store i32 %55, i32* %56
%57 = getelementptr inbounds %struct.termios, %struct.termios* %4, i64 0, i32 2
%58 = load i32*, i32** %57
%59 = load i64, i64* @VMIN
%60 = getelementptr inbounds i32, i32* %58, i64 %59
store i32 1, i32* %60
%61 = load i64, i64* @VTIME
%62 = getelementptr inbounds i32, i32* %58, i64 %61
store i32 0, i32* %62
%63 = load i32, i32* @TCSAFLUSH
%64 = call i64 @tcsetattr(i32 %23, i32 %63, %struct.termios* %4)
%65 = icmp slt i64 %64, 0
br i1 %65, label %66, label %72
66: ; preds = %43
%67 = load i32, i32* @stderr
%68 = load i32, i32* @errno
%69 = call i8* @strerror(i32 %68)
%70 = call i32 (i32, i8*, ...) @fprintf(i32 %67, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.3, i64 0, i64 0), i8* %69)
%71 = call i32 @exit(i32 4)
unreachable
72: ; preds = %43
%73 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @str, i64 0, i64 0))
%74 = load i32, i32* @stdin
%75 = call i32* @fgets(i8* %6, i32 200, i32 %74)
%76 = icmp eq i32* %75, null
br i1 %76, label %112, label %77
77: ; preds = %72
%78 = bitcast i32* %5 to i8*
br label %79
79: ; preds = %77, %108
%80 = phi i32 [ 0, %77 ], [ %89, %108 ]
%81 = load i32, i32* @TIOCMGET
%82 = call i64 @ioctl(i32 %23, i32 %81, i32* %5)
%83 = icmp eq i64 %82, 0
br i1 %83, label %87, label %84
84: ; preds = %79
%85 = load i32, i32* @stderr
%86 = call i32 (i32, i8*, ...) @fprintf(i32 %85, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.5, i64 0, i64 0))
br label %87
87: ; preds = %84, %79
%88 = icmp eq i32 %80, 0
%89 = xor i32 %80, 1
%90 = load i32, i32* @TIOCM_RTS
store i32 %90, i32* %5
%91 = load i32, i32* @TIOCM_CTS
%92 = and i32 %91, %90
%93 = icmp ne i32 %92, 0
%94 = zext i1 %93 to i32
br i1 %88, label %95, label %100
95: ; preds = %87
%96 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.6, i64 0, i64 0), i32 %94)
%97 = load i32, i32* @TIOCMBIS
%98 = call i64 @ioctl(i32 %23, i32 %97, i32* %5)
%99 = icmp eq i64 %98, 0
br i1 %99, label %108, label %105
100: ; preds = %87
%101 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.8, i64 0, i64 0), i32 %94)
%102 = load i32, i32* @TIOCMBIC
%103 = call i64 @ioctl(i32 %23, i32 %102, i32* %5)
%104 = icmp eq i64 %103, 0
br i1 %104, label %108, label %105
105: ; preds = %100, %95
%106 = load i32, i32* @stderr
%107 = call i32 (i32, i8*, ...) @fprintf(i32 %106, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.7, i64 0, i64 0))
br label %108
108: ; preds = %105, %100, %95
%109 = load i32, i32* @stdin
%110 = call i32* @fgets(i8* %6, i32 200, i32 %109)
%111 = icmp eq i32* %110, null
br i1 %111, label %112, label %79
112: ; preds = %108, %72
%113 = call i32 @close(i32 %23)
ret i32 0
}