#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 serial_set_rts(int fd, bool enabled) {
  int status;
  ioctl(fd, TIOCMGET, &status);
  if (!enabled) {
    status |= TIOCM_RTS;
  } else {
    status &= ~TIOCM_RTS;
  }
  ioctl(fd, TIOCMSET, &status);
}


x86 assembly (clang, -O0):
<serial_set_rts>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2eb0(%rip),%rax
mov    (%rax),%esi
lea    -0xc(%rbp),%rdx
call   1030 <ioctl@plt>
cmpl   $0x0,-0x8(%rbp)
jne    1151 <serial_set_rts+0x41>
mov    0x2e9c(%rip),%rax
mov    (%rax),%eax
or     -0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
jmp    1163 <serial_set_rts+0x53>
mov    0x2e88(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2e7b(%rip),%rax
mov    (%rax),%esi
lea    -0xc(%rbp),%rdx
call   1030 <ioctl@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<serial_set_rts>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebp
mov    %edi,%ebx
mov    0x2eba(%rip),%rax
mov    (%rax),%esi
lea    0x4(%rsp),%rdx
call   1030 <ioctl@plt>
mov    0x2eaf(%rip),%rax
mov    (%rax),%eax
test   %ebp,%ebp
je     113f <serial_set_rts+0x2f>
not    %eax
and    0x4(%rsp),%eax
jmp    1143 <serial_set_rts+0x33>
or     0x4(%rsp),%eax
mov    %eax,0x4(%rsp)
mov    0x2e9a(%rip),%rax
mov    (%rax),%esi
lea    0x4(%rsp),%rdx
mov    %ebx,%edi
call   1030 <ioctl@plt>
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@TIOCMGET = global i32 0
@TIOCM_RTS = global i32 0
@TIOCMSET = global i32 0
define void @serial_set_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* %4
%10 = icmp ne i32 %9, 0
br i1 %10, label %15, label %11
11: ; preds = %2
%12 = load i32, i32* @TIOCM_RTS
%13 = load i32, i32* %5
%14 = or i32 %13, %12
store i32 %14, i32* %5
br label %20
15: ; preds = %2
%16 = load i32, i32* @TIOCM_RTS
%17 = xor i32 %16, -1
%18 = load i32, i32* %5
%19 = and i32 %18, %17
store i32 %19, i32* %5
br label %20
20: ; preds = %15, %11
%21 = load i32, i32* %3
%22 = load i32, i32* @TIOCMSET
%23 = call i32 @ioctl(i32 %21, i32 %22, i32* %5)
ret void
}

LLVM IR (-O2):
@TIOCMGET = global i32 0
@TIOCM_RTS = global i32 0
@TIOCMSET = global i32 0
define void @serial_set_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 = icmp eq i32 %1, 0
%8 = load i32, i32* @TIOCM_RTS
br i1 %7, label %9, label %12
9: ; preds = %2
%10 = load i32, i32* %3
%11 = or i32 %10, %8
br label %16
12: ; preds = %2
%13 = xor i32 %8, -1
%14 = load i32, i32* %3
%15 = and i32 %14, %13
br label %16
16: ; preds = %12, %9
%17 = phi i32 [ %11, %9 ], [ %15, %12 ]
store i32 %17, i32* %3
%18 = load i32, i32* @TIOCMSET
%19 = call i32 @ioctl(i32 %0, i32 %18, i32* %3)
ret void
}