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


x86 assembly (clang, -O0):
<rts>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2ea0(%rip),%rax
mov    (%rax),%esi
lea    -0xc(%rbp),%rdx
call   1040 <ioctl@plt>
mov    -0xc(%rbp),%esi
mov    -0xc(%rbp),%ecx
mov    0x2e90(%rip),%rax
and    (%rax),%ecx
xor    %edx,%edx
mov    $0x1,%eax
cmp    $0x0,%ecx
cmovne %eax,%edx
mov    -0xc(%rbp),%edi
mov    0x2e5f(%rip),%rax
and    (%rax),%edi
xor    %ecx,%ecx
mov    $0x1,%eax
cmp    $0x0,%edi
cmovne %eax,%ecx
lea    0xe81(%rip),%rdi
call   1030 <printf@plt>
cmpl   $0x0,-0x8(%rbp)
je     11a2 <rts+0x82>
mov    0x2e4b(%rip),%rax
mov    (%rax),%eax
or     -0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
jmp    11b4 <rts+0x94>
mov    0x2e37(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2e2a(%rip),%rax
mov    (%rax),%esi
lea    -0xc(%rbp),%rdx
call   1040 <ioctl@plt>
mov    -0xc(%rbp),%esi
mov    -0xc(%rbp),%ecx
mov    0x2e0a(%rip),%rax
and    (%rax),%ecx
xor    %edx,%edx
mov    $0x1,%eax
cmp    $0x0,%ecx
cmovne %eax,%edx
mov    -0xc(%rbp),%edi
mov    0x2dd9(%rip),%rax
and    (%rax),%edi
xor    %ecx,%ecx
mov    $0x1,%eax
cmp    $0x0,%edi
cmovne %eax,%ecx
lea    0xe25(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rts>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %esi,%ebp
mov    %edi,%ebx
mov    0x2ea6(%rip),%rax
mov    (%rax),%esi
lea    0x4(%rsp),%rdx
call   1040 <ioctl@plt>
mov    0x4(%rsp),%esi
mov    0x2e97(%rip),%r14
xor    %edx,%edx
mov    (%r14),%eax
and    %esi,%eax
setne  %dl
mov    0x2e6e(%rip),%r15
xor    %ecx,%ecx
mov    (%r15),%eax
and    %esi,%eax
setne  %cl
lea    0xe95(%rip),%rdi
call   1030 <printf@plt>
mov    (%r14),%eax
test   %ebp,%ebp
je     117d <rts+0x5d>
or     0x4(%rsp),%eax
jmp    1183 <rts+0x63>
not    %eax
and    0x4(%rsp),%eax
mov    %eax,0x4(%rsp)
mov    0x2e5a(%rip),%rax
mov    (%rax),%esi
lea    0x4(%rsp),%rdx
mov    %ebx,%edi
call   1040 <ioctl@plt>
mov    0x4(%rsp),%esi
xor    %edx,%edx
mov    (%r14),%eax
and    %esi,%eax
setne  %dl
xor    %ecx,%ecx
mov    (%r15),%eax
and    %esi,%eax
setne  %cl
lea    0xe6f(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@TIOCMGET = global i32 0
@.str = [42 x i8] c"Info: Flags before: %x\09 RTS: %d\09 CTS: %d\0A\00"
@TIOCM_RTS = global i32 0
@TIOCM_CTS = global i32 0
@TIOCMSET = global i32 0
@.str.1 = [41 x i8] c"Info: Flags after: %x\09 RTS: %d\09 CTS: %d\0A\00"
define i32 @rts(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 %0, i32* %3
store i32 %1, i32* %4
%6 = load i32, i32* %3
%7 = load i32, i32* @TIOCMGET
%8 = call i32 @ioctl(i32 %6, i32 %7, i32* %5)
%9 = load i32, i32* %5
%10 = load i32, i32* %5
%11 = load i32, i32* @TIOCM_RTS
%12 = and i32 %10, %11
%13 = icmp ne i32 %12, 0
%14 = zext i1 %13 to i64
%15 = select i1 %13, i32 1, i32 0
%16 = load i32, i32* %5
%17 = load i32, i32* @TIOCM_CTS
%18 = and i32 %16, %17
%19 = icmp ne i32 %18, 0
%20 = zext i1 %19 to i64
%21 = select i1 %19, i32 1, i32 0
%22 = call i32 @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0), i32 %9, i32 %15, i32 %21)
%23 = load i32, i32* %4
%24 = icmp ne i32 %23, 0
br i1 %24, label %25, label %29
25: ; preds = %2
%26 = load i32, i32* @TIOCM_RTS
%27 = load i32, i32* %5
%28 = or i32 %27, %26
store i32 %28, i32* %5
br label %34
29: ; preds = %2
%30 = load i32, i32* @TIOCM_RTS
%31 = xor i32 %30, -1
%32 = load i32, i32* %5
%33 = and i32 %32, %31
store i32 %33, i32* %5
br label %34
34: ; preds = %29, %25
%35 = load i32, i32* %3
%36 = load i32, i32* @TIOCMSET
%37 = call i32 @ioctl(i32 %35, i32 %36, i32* %5)
%38 = load i32, i32* %5
%39 = load i32, i32* %5
%40 = load i32, i32* @TIOCM_RTS
%41 = and i32 %39, %40
%42 = icmp ne i32 %41, 0
%43 = zext i1 %42 to i64
%44 = select i1 %42, i32 1, i32 0
%45 = load i32, i32* %5
%46 = load i32, i32* @TIOCM_CTS
%47 = and i32 %45, %46
%48 = icmp ne i32 %47, 0
%49 = zext i1 %48 to i64
%50 = select i1 %48, i32 1, i32 0
%51 = call i32 @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.1, i64 0, i64 0), i32 %38, i32 %44, i32 %50)
ret i32 0
}

LLVM IR (-O2):
@TIOCMGET = global i32 0
@.str = [42 x i8] c"Info: Flags before: %x\09 RTS: %d\09 CTS: %d\0A\00"
@TIOCM_RTS = global i32 0
@TIOCM_CTS = global i32 0
@TIOCMSET = global i32 0
@.str.1 = [41 x i8] c"Info: Flags after: %x\09 RTS: %d\09 CTS: %d\0A\00"
define i32 @rts(i32 %0, i32 %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
%5 = load i32, i32* @TIOCMGET
%6 = call i32 @ioctl(i32 %0, i32 %5, i32* %3)
%7 = load i32, i32* %3
%8 = load i32, i32* @TIOCM_RTS
%9 = and i32 %8, %7
%10 = icmp ne i32 %9, 0
%11 = zext i1 %10 to i32
%12 = load i32, i32* @TIOCM_CTS
%13 = and i32 %12, %7
%14 = icmp ne i32 %13, 0
%15 = zext i1 %14 to i32
%16 = call i32 @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0), i32 %7, i32 %11, i32 %15)
%17 = icmp eq i32 %1, 0
%18 = load i32, i32* @TIOCM_RTS
br i1 %17, label %22, label %19
19: ; preds = %2
%20 = load i32, i32* %3
%21 = or i32 %20, %18
br label %26
22: ; preds = %2
%23 = xor i32 %18, -1
%24 = load i32, i32* %3
%25 = and i32 %24, %23
br label %26
26: ; preds = %22, %19
%27 = phi i32 [ %25, %22 ], [ %21, %19 ]
store i32 %27, i32* %3
%28 = load i32, i32* @TIOCMSET
%29 = call i32 @ioctl(i32 %0, i32 %28, i32* %3)
%30 = load i32, i32* %3
%31 = load i32, i32* @TIOCM_RTS
%32 = and i32 %31, %30
%33 = icmp ne i32 %32, 0
%34 = zext i1 %33 to i32
%35 = load i32, i32* @TIOCM_CTS
%36 = and i32 %35, %30
%37 = icmp ne i32 %36, 0
%38 = zext i1 %37 to i32
%39 = call i32 @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.1, i64 0, i64 0), i32 %30, i32 %34, i32 %38)
ret i32 0
}