#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*/ TIOCMGET;
int TIOCM_CTS;
int TIOCM_RTS;
int /*<<< orphan*/ ioctl(int, int /*<<< orphan*/, int *);
int /*<<< orphan*/ printf(char *, int, int, int);
int get_rts(int fd) {
  int flags;
  ioctl(fd, TIOCMGET, &flags);
  printf("Info: Flags: %x\t RTS: %d\t CTS: %d\n", flags,
         ((flags & TIOCM_RTS) ? 1 : 0), ((flags & TIOCM_CTS) ? 1 : 0));
  return (flags & TIOCM_RTS) ? 1 : 0;
}


x86 assembly (clang, -O0):
<get_rts>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2eab(%rip),%rax
mov    (%rax),%esi
lea    -0x8(%rbp),%rdx
call   1040 <ioctl@plt>
mov    -0x8(%rbp),%esi
mov    -0x8(%rbp),%ecx
mov    0x2e9b(%rip),%rax
and    (%rax),%ecx
xor    %edx,%edx
mov    $0x1,%eax
cmp    $0x0,%ecx
cmovne %eax,%edx
mov    -0x8(%rbp),%edi
mov    0x2e6a(%rip),%rax
and    (%rax),%edi
xor    %ecx,%ecx
mov    $0x1,%eax
cmp    $0x0,%edi
cmovne %eax,%ecx
lea    0xe84(%rip),%rdi
call   1030 <printf@plt>
mov    -0x8(%rbp),%edx
mov    0x2e5d(%rip),%rax
and    (%rax),%edx
xor    %eax,%eax
mov    $0x1,%ecx
cmp    $0x0,%edx
cmovne %ecx,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_rts>:
push   %rbx
sub    $0x10,%rsp
mov    0x2eb4(%rip),%rax
mov    (%rax),%esi
lea    0xc(%rsp),%rdx
call   1040 <ioctl@plt>
mov    0xc(%rsp),%esi
mov    0x2ea5(%rip),%rbx
xor    %edx,%edx
mov    (%rbx),%eax
and    %esi,%eax
setne  %dl
mov    0x2e7d(%rip),%rax
xor    %ecx,%ecx
mov    (%rax),%eax
and    %esi,%eax
setne  %cl
lea    0xe9d(%rip),%rdi
call   1030 <printf@plt>
mov    (%rbx),%ecx
xor    %eax,%eax
and    0xc(%rsp),%ecx
setne  %al
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@TIOCMGET = global i32 0
@.str = [35 x i8] c"Info: Flags: %x\09 RTS: %d\09 CTS: %d\0A\00"
@TIOCM_RTS = global i32 0
@TIOCM_CTS = global i32 0
define i32 @get_rts(i32 %0) {
%2 = alloca i32
%3 = alloca i32
store i32 %0, i32* %2
%4 = load i32, i32* %2
%5 = load i32, i32* @TIOCMGET
%6 = call i32 @ioctl(i32 %4, i32 %5, i32* %3)
%7 = load i32, i32* %3
%8 = load i32, i32* %3
%9 = load i32, i32* @TIOCM_RTS
%10 = and i32 %8, %9
%11 = icmp ne i32 %10, 0
%12 = zext i1 %11 to i64
%13 = select i1 %11, i32 1, i32 0
%14 = load i32, i32* %3
%15 = load i32, i32* @TIOCM_CTS
%16 = and i32 %14, %15
%17 = icmp ne i32 %16, 0
%18 = zext i1 %17 to i64
%19 = select i1 %17, i32 1, i32 0
%20 = call i32 @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i32 %7, i32 %13, i32 %19)
%21 = load i32, i32* %3
%22 = load i32, i32* @TIOCM_RTS
%23 = and i32 %21, %22
%24 = icmp ne i32 %23, 0
%25 = zext i1 %24 to i64
%26 = select i1 %24, i32 1, i32 0
ret i32 %26
}

LLVM IR (-O2):
@TIOCMGET = global i32 0
@.str = [35 x i8] c"Info: Flags: %x\09 RTS: %d\09 CTS: %d\0A\00"
@TIOCM_RTS = global i32 0
@TIOCM_CTS = global i32 0
define i32 @get_rts(i32 %0) {
%2 = alloca i32
%3 = bitcast i32* %2 to i8*
%4 = load i32, i32* @TIOCMGET
%5 = call i32 @ioctl(i32 %0, i32 %4, i32* %2)
%6 = load i32, i32* %2
%7 = load i32, i32* @TIOCM_RTS
%8 = and i32 %7, %6
%9 = icmp ne i32 %8, 0
%10 = zext i1 %9 to i32
%11 = load i32, i32* @TIOCM_CTS
%12 = and i32 %11, %6
%13 = icmp ne i32 %12, 0
%14 = zext i1 %13 to i32
%15 = call i32 @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i32 %6, i32 %10, i32 %14)
%16 = load i32, i32* %2
%17 = load i32, i32* @TIOCM_RTS
%18 = and i32 %17, %16
%19 = icmp ne i32 %18, 0
%20 = zext i1 %19 to i32
ret i32 %20
}