#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;
unsigned int TIOCM_RTS;
int /*<<< orphan*/ errno;
int /*<<< orphan*/ error(int /*<<< orphan*/, int /*<<< orphan*/, char *);
scalar_t__ ioctl(int, int /*<<< orphan*/, unsigned int *);
int ttySetRTS(int fd, int st) {
  unsigned int status = 0;
  if (ioctl(fd, TIOCMGET, &status) < 0) {
    error(0, errno, "ioctl(TIOCMGET)");
    return 0;
  }
  if (st)
    status |= TIOCM_RTS;
  else
    status &= ~TIOCM_RTS;
  if (ioctl(fd, TIOCMSET, &status) < 0) {
    error(0, errno, "ioctl(TIOCMSET)");
    return 0;
  }
  return 1;
}


x86 assembly (clang, -O0):
<ttySetRTS>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2e99(%rip),%rax
mov    (%rax),%esi
lea    -0x10(%rbp),%rdx
call   1030 <ioctl@plt>
cmp    $0x0,%rax
jge    1177 <ttySetRTS+0x57>
mov    0x2e6d(%rip),%rax
mov    (%rax),%esi
xor    %edi,%edi
lea    0xe9a(%rip),%rdx
call   1040 <error@plt>
movl   $0x0,-0x4(%rbp)
jmp    11f0 <ttySetRTS+0xd0>
cmpl   $0x0,-0xc(%rbp)
je     1195 <ttySetRTS+0x75>
mov    0x2e58(%rip),%rax
mov    (%rax),%eax
or     -0x10(%rbp),%eax
mov    %eax,-0x10(%rbp)
jmp    11a7 <ttySetRTS+0x87>
mov    0x2e44(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x10(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2e37(%rip),%rax
mov    (%rax),%esi
lea    -0x10(%rbp),%rdx
call   1030 <ioctl@plt>
cmp    $0x0,%rax
jge    11e9 <ttySetRTS+0xc9>
mov    0x2dfb(%rip),%rax
mov    (%rax),%esi
xor    %edi,%edi
lea    0xe38(%rip),%rdx
call   1040 <error@plt>
movl   $0x0,-0x4(%rbp)
jmp    11f0 <ttySetRTS+0xd0>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ttySetRTS>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebp
mov    %edi,%ebx
movl   $0x0,0x4(%rsp)
mov    0x2ea2(%rip),%rax
mov    (%rax),%esi
lea    0x4(%rsp),%rdx
call   1030 <ioctl@plt>
test   %rax,%rax
js     115a <ttySetRTS+0x3a>
mov    0x2e92(%rip),%rax
mov    (%rax),%eax
test   %ebp,%ebp
je     1163 <ttySetRTS+0x43>
or     0x4(%rsp),%eax
jmp    1169 <ttySetRTS+0x49>
lea    0xe9f(%rip),%rdx
jmp    1193 <ttySetRTS+0x73>
not    %eax
and    0x4(%rsp),%eax
mov    %eax,0x4(%rsp)
mov    0x2e74(%rip),%rax
mov    (%rax),%esi
lea    0x4(%rsp),%rdx
mov    %ebx,%edi
call   1030 <ioctl@plt>
mov    $0x1,%ebx
test   %rax,%rax
jns    11a5 <ttySetRTS+0x85>
lea    0xe7d(%rip),%rdx
mov    0x2e2e(%rip),%rax
mov    (%rax),%esi
xor    %ebx,%ebx
xor    %edi,%edi
call   1040 <error@plt>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@TIOCMGET = global i32 0
@errno = global i32 0
@.str = [16 x i8] c"ioctl(TIOCMGET)\00"
@TIOCM_RTS = global i32 0
@TIOCMSET = global i32 0
@.str.1 = [16 x i8] c"ioctl(TIOCMSET)\00"
define i32 @ttySetRTS(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
store i32 0, i32* %6
%7 = load i32, i32* %4
%8 = load i32, i32* @TIOCMGET
%9 = call i64 @ioctl(i32 %7, i32 %8, i32* %6)
%10 = icmp slt i64 %9, 0
br i1 %10, label %11, label %14
11: ; preds = %2
%12 = load i32, i32* @errno
%13 = call i32 @error(i32 0, i32 %12, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
store i32 0, 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 i64 @ioctl(i32 %27, i32 %28, i32* %6)
%30 = icmp slt i64 %29, 0
br i1 %30, label %31, label %34
31: ; preds = %26
%32 = load i32, i32* @errno
%33 = call i32 @error(i32 0, i32 %32, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %3
br label %35
34: ; preds = %26
store i32 1, 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
@.str = [16 x i8] c"ioctl(TIOCMGET)\00"
@TIOCM_RTS = global i32 0
@TIOCMSET = global i32 0
@.str.1 = [16 x i8] c"ioctl(TIOCMSET)\00"
define i32 @ttySetRTS(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 i64 @ioctl(i32 %0, i32 %5, i32* %3)
%7 = icmp slt i64 %6, 0
br i1 %7, label %23, label %8
8: ; preds = %2
%9 = icmp eq i32 %1, 0
%10 = load i32, i32* @TIOCM_RTS
br i1 %9, label %14, label %11
11: ; preds = %8
%12 = load i32, i32* %3
%13 = or i32 %12, %10
br label %18
14: ; preds = %8
%15 = xor i32 %10, -1
%16 = load i32, i32* %3
%17 = and i32 %16, %15
br label %18
18: ; preds = %14, %11
%19 = phi i32 [ %17, %14 ], [ %13, %11 ]
store i32 %19, i32* %3
%20 = load i32, i32* @TIOCMSET
%21 = call i64 @ioctl(i32 %0, i32 %20, i32* %3)
%22 = icmp slt i64 %21, 0
br i1 %22, label %23, label %27
23: ; preds = %18, %2
%24 = phi i8* [ getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), %2 ], [ getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), %18 ]
%25 = load i32, i32* @errno
%26 = call i32 @error(i32 0, i32 %25, i8* %24)
br label %27
27: ; preds = %23, %18
%28 = phi i32 [ 1, %18 ], [ 0, %23 ]
ret i32 %28
}