#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 errno;
int ioctl(int, int /*<<< orphan*/, int *);
int set_rts(int fd, int level) {
  int status;
  if (ioctl(fd, TIOCMGET, &status) == -1)
    return -errno;
  if (level)
    status |= TIOCM_RTS;
  else
    status &= ~TIOCM_RTS;
  if (ioctl(fd, TIOCMSET, &status) == -1)
    return -errno;
  return 0;
}


x86 assembly (clang, -O0):
<set_rts>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2eb0(%rip),%rax
mov    (%rax),%esi
lea    -0x10(%rbp),%rdx
call   1030 <ioctl@plt>
cmp    $0xffffffff,%eax
jne    114f <set_rts+0x3f>
xor    %eax,%eax
mov    0x2e83(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x4(%rbp)
jmp    11b7 <set_rts+0xa7>
cmpl   $0x0,-0xc(%rbp)
je     116d <set_rts+0x5d>
mov    0x2e80(%rip),%rax
mov    (%rax),%eax
or     -0x10(%rbp),%eax
mov    %eax,-0x10(%rbp)
jmp    117f <set_rts+0x6f>
mov    0x2e6c(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x10(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2e5f(%rip),%rax
mov    (%rax),%esi
lea    -0x10(%rbp),%rdx
call   1030 <ioctl@plt>
cmp    $0xffffffff,%eax
jne    11b0 <set_rts+0xa0>
xor    %eax,%eax
mov    0x2e22(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x4(%rbp)
jmp    11b7 <set_rts+0xa7>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<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>
cmp    $0xffffffff,%eax
je     116a <set_rts+0x5a>
mov    0x2eaa(%rip),%rax
mov    (%rax),%eax
test   %ebp,%ebp
je     1142 <set_rts+0x32>
or     0x4(%rsp),%eax
jmp    1148 <set_rts+0x38>
not    %eax
and    0x4(%rsp),%eax
mov    %eax,0x4(%rsp)
mov    0x2e95(%rip),%rax
mov    (%rax),%esi
lea    0x4(%rsp),%rdx
mov    %ebx,%edi
call   1030 <ioctl@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0xffffffff,%ecx
jne    1175 <set_rts+0x65>
mov    0x2e57(%rip),%rcx
xor    %eax,%eax
sub    (%rcx),%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

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

LLVM IR (-O2):
@TIOCMGET = global i32 0
@errno = global i32 0
@TIOCM_RTS = global i32 0
@TIOCMSET = global i32 0
define i32 @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 %6, -1
br i1 %7, label %8, label %11
8: ; preds = %2
%9 = load i32, i32* @errno
%10 = sub nsw i32 0, %9
br label %29
11: ; preds = %2
%12 = icmp eq i32 %1, 0
%13 = load i32, i32* @TIOCM_RTS
br i1 %12, label %17, label %14
14: ; preds = %11
%15 = load i32, i32* %3
%16 = or i32 %15, %13
br label %21
17: ; preds = %11
%18 = xor i32 %13, -1
%19 = load i32, i32* %3
%20 = and i32 %19, %18
br label %21
21: ; preds = %17, %14
%22 = phi i32 [ %20, %17 ], [ %16, %14 ]
store i32 %22, i32* %3
%23 = load i32, i32* @TIOCMSET
%24 = call i32 @ioctl(i32 %0, i32 %23, i32* %3)
%25 = icmp eq i32 %24, -1
br i1 %25, label %26, label %29
26: ; preds = %21
%27 = load i32, i32* @errno
%28 = sub nsw i32 0, %27
br label %29
29: ; preds = %21, %26, %8
%30 = phi i32 [ %10, %8 ], [ %28, %26 ], [ 0, %21 ]
ret i32 %30
}