#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 */
struct termios {
  int /*<<< orphan*/ c_cflag;
};

/* Variables and functions */
int /*<<< orphan*/ CRTSCTS;
int /*<<< orphan*/ CSTOPB;
int /*<<< orphan*/ TCSAFLUSH;
int tcgetattr(int, struct termios *);
int tcsetattr(int, int /*<<< orphan*/, struct termios *);
int tty_setrtscts(int fd, int enable) {
  struct termios options;
  if (tcgetattr(fd, &options) == -1) {
    do {
    } while (0);
    do {
    } while (0);
    return (0);
  }
  if (enable) {
    options.c_cflag |= CRTSCTS;
    options.c_cflag |= CSTOPB;
  } else {
    options.c_cflag &= ~CRTSCTS;
    options.c_cflag &= ~CSTOPB;
  }
  if (tcsetattr(fd, TCSAFLUSH, &options) == -1) {
    do {
    } while (0);
    do {
    } while (0);
    return (0);
  }
  return (1);
}


x86 assembly (clang, -O0):
<tty_setrtscts>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x10(%rbp),%rsi
call   1030 <tcgetattr@plt>
cmp    $0xffffffff,%eax
jne    1163 <tty_setrtscts+0x43>
jmp    1148 <tty_setrtscts+0x28>
jmp    114d <tty_setrtscts+0x2d>
jmp    1152 <tty_setrtscts+0x32>
jmp    1157 <tty_setrtscts+0x37>
movl   $0x0,-0x4(%rbp)
jmp    11f9 <tty_setrtscts+0xd9>
cmpl   $0x0,-0xc(%rbp)
je     1190 <tty_setrtscts+0x70>
mov    0x2e5c(%rip),%rax
mov    (%rax),%eax
or     -0x10(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    0x2e45(%rip),%rax
mov    (%rax),%eax
or     -0x10(%rbp),%eax
mov    %eax,-0x10(%rbp)
jmp    11b4 <tty_setrtscts+0x94>
mov    0x2e39(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x10(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    0x2e1f(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x10(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2e2a(%rip),%rax
mov    (%rax),%esi
lea    -0x10(%rbp),%rdx
call   1040 <tcsetattr@plt>
cmp    $0xffffffff,%eax
jne    11f2 <tty_setrtscts+0xd2>
jmp    11d7 <tty_setrtscts+0xb7>
jmp    11dc <tty_setrtscts+0xbc>
jmp    11e1 <tty_setrtscts+0xc1>
jmp    11e6 <tty_setrtscts+0xc6>
movl   $0x0,-0x4(%rbp)
jmp    11f9 <tty_setrtscts+0xd9>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tty_setrtscts>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebp
mov    %edi,%ebx
mov    %rsp,%rsi
call   1030 <tcgetattr@plt>
cmp    $0xffffffff,%eax
je     1151 <tty_setrtscts+0x31>
mov    0x2e95(%rip),%rax
mov    (%rax),%ecx
mov    (%rsp),%eax
test   %ebp,%ebp
je     1155 <tty_setrtscts+0x35>
or     %ecx,%eax
mov    0x2e7b(%rip),%rcx
or     (%rcx),%eax
jmp    1162 <tty_setrtscts+0x42>
xor    %eax,%eax
jmp    1182 <tty_setrtscts+0x62>
mov    0x2e6c(%rip),%rdx
or     (%rdx),%ecx
not    %ecx
and    %ecx,%eax
mov    %eax,(%rsp)
mov    0x2e7c(%rip),%rax
mov    (%rax),%esi
mov    %rsp,%rdx
mov    %ebx,%edi
call   1040 <tcsetattr@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0xffffffff,%ecx
setne  %al
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.termios = type { i32 }
@CRTSCTS = global i32 0
@CSTOPB = global i32 0
@TCSAFLUSH = global i32 0
define i32 @tty_setrtscts(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca %struct.termios
store i32 %0, i32* %4
store i32 %1, i32* %5
%7 = load i32, i32* %4
%8 = call i32 @tcgetattr(i32 %7, %struct.termios* %6)
%9 = icmp eq i32 %8, -1
br i1 %9, label %10, label %15
10: ; preds = %2
br label %11
11: ; preds = %10
br label %12
12: ; preds = %11
br label %13
13: ; preds = %12
br label %14
14: ; preds = %13
store i32 0, i32* %3
br label %49
15: ; preds = %2
%16 = load i32, i32* %5
%17 = icmp ne i32 %16, 0
br i1 %17, label %18, label %27
18: ; preds = %15
%19 = load i32, i32* @CRTSCTS
%20 = getelementptr inbounds %struct.termios, %struct.termios* %6, i32 0, i32 0
%21 = load i32, i32* %20
%22 = or i32 %21, %19
store i32 %22, i32* %20
%23 = load i32, i32* @CSTOPB
%24 = getelementptr inbounds %struct.termios, %struct.termios* %6, i32 0, i32 0
%25 = load i32, i32* %24
%26 = or i32 %25, %23
store i32 %26, i32* %24
br label %38
27: ; preds = %15
%28 = load i32, i32* @CRTSCTS
%29 = xor i32 %28, -1
%30 = getelementptr inbounds %struct.termios, %struct.termios* %6, i32 0, i32 0
%31 = load i32, i32* %30
%32 = and i32 %31, %29
store i32 %32, i32* %30
%33 = load i32, i32* @CSTOPB
%34 = xor i32 %33, -1
%35 = getelementptr inbounds %struct.termios, %struct.termios* %6, i32 0, i32 0
%36 = load i32, i32* %35
%37 = and i32 %36, %34
store i32 %37, i32* %35
br label %38
38: ; preds = %27, %18
%39 = load i32, i32* %4
%40 = load i32, i32* @TCSAFLUSH
%41 = call i32 @tcsetattr(i32 %39, i32 %40, %struct.termios* %6)
%42 = icmp eq i32 %41, -1
br i1 %42, label %43, label %48
43: ; preds = %38
br label %44
44: ; preds = %43
br label %45
45: ; preds = %44
br label %46
46: ; preds = %45
br label %47
47: ; preds = %46
store i32 0, i32* %3
br label %49
48: ; preds = %38
store i32 1, i32* %3
br label %49
49: ; preds = %48, %47, %14
%50 = load i32, i32* %3
ret i32 %50
}

LLVM IR (-O2):
%struct.termios = type { i32 }
@CRTSCTS = global i32 0
@CSTOPB = global i32 0
@TCSAFLUSH = global i32 0
define i32 @tty_setrtscts(i32 %0, i32 %1) {
%3 = alloca %struct.termios
%4 = bitcast %struct.termios* %3 to i8*
%5 = call i32 @tcgetattr(i32 %0, %struct.termios* %3)
%6 = icmp eq i32 %5, -1
br i1 %6, label %27, label %7
7: ; preds = %2
%8 = icmp eq i32 %1, 0
%9 = load i32, i32* @CRTSCTS
%10 = getelementptr inbounds %struct.termios, %struct.termios* %3, i64 0, i32 0
%11 = load i32, i32* %10
br i1 %8, label %16, label %12
12: ; preds = %7
%13 = or i32 %11, %9
%14 = load i32, i32* @CSTOPB
%15 = or i32 %14, %13
br label %21
16: ; preds = %7
%17 = load i32, i32* @CSTOPB
%18 = or i32 %9, %17
%19 = xor i32 %18, -1
%20 = and i32 %11, %19
br label %21
21: ; preds = %16, %12
%22 = phi i32 [ %15, %12 ], [ %20, %16 ]
store i32 %22, i32* %10
%23 = load i32, i32* @TCSAFLUSH
%24 = call i32 @tcsetattr(i32 %0, i32 %23, %struct.termios* %3)
%25 = icmp ne i32 %24, -1
%26 = zext i1 %25 to i32
br label %27
27: ; preds = %21, %2
%28 = phi i32 [ 0, %2 ], [ %26, %21 ]
ret i32 %28
}