#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_RTS;
int /*<<< orphan*/ ioctl(int, int /*<<< orphan*/, int *);
void toggle_rts(int fd, bool force_low) {
  int pins = 0;
  ioctl(fd, TIOCMGET, &pins);
  bool bit = (pins & TIOCM_RTS);
  pins = pins & ~TIOCM_RTS | (force_low ? 0 : (!bit ? TIOCM_RTS : 0));
  ioctl(fd, TIOCMSET, &pins);
}


x86 assembly (clang, -O0):
<toggle_rts>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2ea9(%rip),%rax
mov    (%rax),%esi
lea    -0xc(%rbp),%rdx
call   1030 <ioctl@plt>
mov    -0xc(%rbp),%eax
mov    0x2e9c(%rip),%rcx
and    (%rcx),%eax
mov    %eax,-0x10(%rbp)
mov    -0xc(%rbp),%eax
mov    0x2e8d(%rip),%rcx
mov    (%rcx),%ecx
xor    $0xffffffff,%ecx
and    %ecx,%eax
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x8(%rbp)
je     1171 <toggle_rts+0x61>
xor    %eax,%eax
mov    %eax,-0x18(%rbp)
jmp    119c <toggle_rts+0x8c>
cmpl   $0x0,-0x10(%rbp)
jne    118c <toggle_rts+0x7c>
mov    0x2e5e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
jmp    1196 <toggle_rts+0x86>
xor    %eax,%eax
mov    %eax,-0x1c(%rbp)
jmp    1196 <toggle_rts+0x86>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%eax
mov    -0x18(%rbp),%ecx
or     %ecx,%eax
mov    %eax,-0xc(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2e37(%rip),%rax
mov    (%rax),%esi
lea    -0xc(%rbp),%rdx
call   1030 <ioctl@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<toggle_rts>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %esi,%ebp
mov    %edi,%ebx
movl   $0x0,0xc(%rsp)
mov    0x2ead(%rip),%rax
mov    (%rax),%esi
lea    0xc(%rsp),%r14
mov    %r14,%rdx
call   1030 <ioctl@plt>
mov    0xc(%rsp),%eax
mov    0x2e9b(%rip),%rcx
mov    (%rcx),%ecx
mov    %ecx,%edx
and    %eax,%edx
mov    %ecx,%esi
not    %esi
and    %eax,%esi
xor    %eax,%eax
or     %ebp,%edx
cmove  %ecx,%eax
or     %esi,%eax
mov    %eax,0xc(%rsp)
mov    0x2e83(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edi
mov    %r14,%rdx
call   1030 <ioctl@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@TIOCMGET = global i32 0
@TIOCM_RTS = global i32 0
@TIOCMSET = global i32 0
define void @toggle_rts(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32 %0, i32* %3
store i32 %1, i32* %4
store i32 0, i32* %5
%7 = load i32, i32* %3
%8 = load i32, i32* @TIOCMGET
%9 = call i32 @ioctl(i32 %7, i32 %8, i32* %5)
%10 = load i32, i32* %5
%11 = load i32, i32* @TIOCM_RTS
%12 = and i32 %10, %11
store i32 %12, i32* %6
%13 = load i32, i32* %5
%14 = load i32, i32* @TIOCM_RTS
%15 = xor i32 %14, -1
%16 = and i32 %13, %15
%17 = load i32, i32* %4
%18 = icmp ne i32 %17, 0
br i1 %18, label %19, label %20
19: ; preds = %2
br label %28
20: ; preds = %2
%21 = load i32, i32* %6
%22 = icmp ne i32 %21, 0
br i1 %22, label %25, label %23
23: ; preds = %20
%24 = load i32, i32* @TIOCM_RTS
br label %26
25: ; preds = %20
br label %26
26: ; preds = %25, %23
%27 = phi i32 [ %24, %23 ], [ 0, %25 ]
br label %28
28: ; preds = %26, %19
%29 = phi i32 [ 0, %19 ], [ %27, %26 ]
%30 = or i32 %16, %29
store i32 %30, i32* %5
%31 = load i32, i32* %3
%32 = load i32, i32* @TIOCMSET
%33 = call i32 @ioctl(i32 %31, i32 %32, i32* %5)
ret void
}

LLVM IR (-O2):
@TIOCMGET = global i32 0
@TIOCM_RTS = global i32 0
@TIOCMSET = global i32 0
define void @toggle_rts(i32 %0, i32 %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
store i32 0, i32* %3
%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 = xor i32 %8, -1
%11 = and i32 %7, %10
%12 = icmp eq i32 %1, 0
%13 = icmp eq i32 %9, 0
%14 = select i1 %12, i1 %13, i1 false
%15 = select i1 %14, i32 %8, i32 0
%16 = or i32 %15, %11
store i32 %16, i32* %3
%17 = load i32, i32* @TIOCMSET
%18 = call i32 @ioctl(i32 %0, i32 %17, i32* %3)
ret void
}