#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 */

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ TIOCMGET;
int TIOCM_RTS;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ ioctl(int, int /*<<< orphan*/, int *);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ stderr;
int main(int argc, char *argv[]) {
  int stat, fd;
  if (argc != 2) {
    fprintf(stderr, "Usage %s <device>\n", argv[0]);
    exit(-1);
  }
  fd = open(argv[1], O_RDONLY);
  if (fd == -1) {
    perror(argv[0]);
    exit(1);
  }
  ioctl(fd, TIOCMGET, &stat);
  if (stat & TIOCM_RTS)
    printf("Not asserted\n");
  else
    printf("Asserted\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     11a6 <main+0x46>
mov    0x2e41(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe69(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0xffffffff,%edi
call   1080 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2e33(%rip),%rax
mov    (%rax),%esi
call   1060 <open@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0xffffffff,-0x18(%rbp)
jne    11df <main+0x7f>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x18(%rbp),%edi
mov    0x2def(%rip),%rax
mov    (%rax),%esi
lea    -0x14(%rbp),%rdx
call   1040 <ioctl@plt>
mov    -0x14(%rbp),%eax
mov    0x2de2(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     121a <main+0xba>
lea    0xe03(%rip),%rdi
call   1030 <printf@plt>
jmp    1226 <main+0xc6>
lea    0xe00(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbx
cmp    $0x2,%edi
jne    11c5 <main+0x65>
mov    0x8(%rbx),%rdi
mov    0x2e70(%rip),%rax
mov    (%rax),%esi
call   1060 <open@plt>
cmp    $0xffffffff,%eax
je     11e7 <main+0x87>
mov    0x2e4d(%rip),%rcx
mov    (%rcx),%esi
lea    0xc(%rsp),%rdx
mov    %eax,%edi
call   1040 <ioctl@plt>
mov    0x2e40(%rip),%rax
mov    (%rax),%eax
and    0xc(%rsp),%eax
lea    0xe66(%rip),%rax
lea    0xe68(%rip),%rdi
cmove  %rax,%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret
mov    0x2dfc(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rdx
lea    0xe28(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0xffffffff,%edi
call   1080 <exit@plt>
mov    (%rbx),%rdi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [19 x i8] c"Usage %s <device>\0A\00"
@O_RDONLY = global i32 0
@TIOCMGET = global i32 0
@TIOCM_RTS = global i32 0
@.str.1 = [14 x i8] c"Not asserted\0A\00"
@.str.2 = [10 x i8] c"Asserted\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i32, i32* %4
%9 = icmp ne i32 %8, 2
br i1 %9, label %10, label %17
10: ; preds = %2
%11 = load i32, i32* @stderr
%12 = load i8**, i8*** %5
%13 = getelementptr inbounds i8*, i8** %12, i64 0
%14 = load i8*, i8** %13
%15 = call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* %14)
%16 = call i32 @exit(i32 -1)
unreachable
17: ; preds = %2
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 1
%20 = load i8*, i8** %19
%21 = load i32, i32* @O_RDONLY
%22 = call i32 @open(i8* %20, i32 %21)
store i32 %22, i32* %7
%23 = load i32, i32* %7
%24 = icmp eq i32 %23, -1
br i1 %24, label %25, label %31
25: ; preds = %17
%26 = load i8**, i8*** %5
%27 = getelementptr inbounds i8*, i8** %26, i64 0
%28 = load i8*, i8** %27
%29 = call i32 @perror(i8* %28)
%30 = call i32 @exit(i32 1)
unreachable
31: ; preds = %17
%32 = load i32, i32* %7
%33 = load i32, i32* @TIOCMGET
%34 = call i32 @ioctl(i32 %32, i32 %33, i32* %6)
%35 = load i32, i32* %6
%36 = load i32, i32* @TIOCM_RTS
%37 = and i32 %35, %36
%38 = icmp ne i32 %37, 0
br i1 %38, label %39, label %41
39: ; preds = %31
%40 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
br label %43
41: ; preds = %31
%42 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0))
br label %43
43: ; preds = %41, %39
ret i32 0
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [19 x i8] c"Usage %s <device>\0A\00"
@O_RDONLY = global i32 0
@TIOCMGET = global i32 0
@TIOCM_RTS = global i32 0
@str = [9 x i8] c"Asserted\00"
@str.3 = [13 x i8] c"Not asserted\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
%5 = icmp eq i32 %0, 2
br i1 %5, label %11, label %6
6: ; preds = %2
%7 = load i32, i32* @stderr
%8 = load i8*, i8** %1
%9 = tail call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* %8)
%10 = tail call i32 @exit(i32 -1)
unreachable
11: ; preds = %2
%12 = getelementptr inbounds i8*, i8** %1, i64 1
%13 = load i8*, i8** %12
%14 = load i32, i32* @O_RDONLY
%15 = tail call i32 @open(i8* %13, i32 %14)
%16 = icmp eq i32 %15, -1
br i1 %16, label %17, label %21
17: ; preds = %11
%18 = load i8*, i8** %1
%19 = tail call i32 @perror(i8* %18)
%20 = tail call i32 @exit(i32 1)
unreachable
21: ; preds = %11
%22 = load i32, i32* @TIOCMGET
%23 = call i32 @ioctl(i32 %15, i32 %22, i32* %3)
%24 = load i32, i32* %3
%25 = load i32, i32* @TIOCM_RTS
%26 = and i32 %25, %24
%27 = icmp eq i32 %26, 0
%28 = select i1 %27, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @str, i64 0, i64 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @str.3, i64 0, i64 0)
%29 = call i32 @puts(i8* dereferenceable(1) %28)
ret i32 0
}