#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 sport_fd, int State) {
  int status;
  if (ioctl(sport_fd, TIOCMGET, &status) == -1) {
    perror("TIOCMGET failed");
    return -1;
  }
  if (State) {
    status |= TIOCM_RTS;
    ;
    if (ioctl(sport_fd, TIOCMSET, &status) == -1) {
      perror("TIOCMSET failed ");
      return -1;
    }
  } else {
    status &= ~TIOCM_RTS;
    ;
    if (ioctl(sport_fd, TIOCMSET, &status) == -1) {
      perror("TIOCMSET failed ");
      return -1;
    }
  }
  return 0;
}


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   $0xffffffff,-0x4(%rbp)
jmp    120c <setRTS+0xec>
cmpl   $0x0,-0xc(%rbp)
je     11b8 <setRTS+0x98>
mov    0x2e6b(%rip),%rax
mov    (%rax),%eax
or     -0x10(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2e61(%rip),%rax
mov    (%rax),%esi
lea    -0x10(%rbp),%rdx
call   1030 <ioctl@plt>
cmp    $0xffffffff,%eax
jne    11b3 <setRTS+0x93>
lea    0xe6e(%rip),%rdi
call   1040 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    120c <setRTS+0xec>
jmp    1205 <setRTS+0xe5>
mov    0x2e21(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x10(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2e14(%rip),%rax
mov    (%rax),%esi
lea    -0x10(%rbp),%rdx
call   1030 <ioctl@plt>
cmp    $0xffffffff,%eax
jne    1200 <setRTS+0xe0>
lea    0xe21(%rip),%rdi
call   1040 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    120c <setRTS+0xec>
jmp    1205 <setRTS+0xe5>
movl   $0x0,-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     117d <setRTS+0x5d>
mov    0x2e9a(%rip),%rax
mov    (%rax),%eax
test   %ebp,%ebp
je     1152 <setRTS+0x32>
or     %eax,0x4(%rsp)
jmp    1158 <setRTS+0x38>
not    %eax
and    %eax,0x4(%rsp)
mov    0x2e89(%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
je     1186 <setRTS+0x66>
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
lea    0xe7c(%rip),%rdi
jmp    118d <setRTS+0x6d>
lea    0xe83(%rip),%rdi
call   1040 <perror@plt>
mov    $0xffffffff,%eax
jmp    1176 <setRTS+0x56>

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

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