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


x86 assembly (clang, -O0):
<setRTS>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2ea0(%rip),%rax
mov    (%rax),%esi
lea    -0x10(%rbp),%rdx
call   1030 <ioctl@plt>
cmp    $0xffffffff,%eax
jne    1164 <setRTS+0x44>
lea    0xead(%rip),%rdi
call   1040 <perror@plt>
movl   $0x0,-0x4(%rbp)
jmp    11d1 <setRTS+0xb1>
cmpl   $0x0,-0xc(%rbp)
je     1182 <setRTS+0x62>
mov    0x2e6b(%rip),%rax
mov    (%rax),%eax
or     -0x10(%rbp),%eax
mov    %eax,-0x10(%rbp)
jmp    1194 <setRTS+0x74>
mov    0x2e57(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x10(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2e4a(%rip),%rax
mov    (%rax),%esi
lea    -0x10(%rbp),%rdx
call   1030 <ioctl@plt>
cmp    $0xffffffff,%eax
jne    11ca <setRTS+0xaa>
lea    0xe5a(%rip),%rdi
call   1040 <perror@plt>
movl   $0x0,-0x4(%rbp)
jmp    11d1 <setRTS+0xb1>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<setRTS>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebp
mov    %edi,%ebx
mov    0x2eaa(%rip),%rax
mov    (%rax),%esi
lea    0x4(%rsp),%rdx
call   1030 <ioctl@plt>
cmp    $0xffffffff,%eax
je     1184 <setRTS+0x64>
mov    0x2e9a(%rip),%rax
mov    (%rax),%eax
test   %ebp,%ebp
je     1152 <setRTS+0x32>
or     0x4(%rsp),%eax
jmp    1158 <setRTS+0x38>
not    %eax
and    0x4(%rsp),%eax
mov    %eax,0x4(%rsp)
mov    0x2e85(%rip),%rax
mov    (%rax),%esi
lea    0x4(%rsp),%rdx
mov    %ebx,%edi
call   1030 <ioctl@plt>
mov    %eax,%ecx
mov    $0x1,%eax
cmp    $0xffffffff,%ecx
je     118d <setRTS+0x6d>
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
lea    0xe75(%rip),%rdi
jmp    1194 <setRTS+0x74>
lea    0xe7f(%rip),%rdi
call   1040 <perror@plt>
xor    %eax,%eax
jmp    117d <setRTS+0x5d>

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

LLVM IR (-O2):
@TIOCMGET = global i32 0
@.str = [19 x i8] c"setRTS(): TIOCMGET\00"
@TIOCM_RTS = global i32 0
@TIOCMSET = global i32 0
@.str.1 = [19 x i8] c"setRTS(): TIOCMSET\00"
define i32 @setRTS(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 %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 i32 @ioctl(i32 %0, i32 %20, i32* %3)
%22 = icmp eq i32 %21, -1
br i1 %22, label %23, label %26
23: ; preds = %18, %2
%24 = phi i8* [ getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), %2 ], [ getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), %18 ]
%25 = call i32 @perror(i8* %24)
br label %26
26: ; preds = %23, %18
%27 = phi i32 [ 1, %18 ], [ 0, %23 ]
ret i32 %27
}