#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*/ TCSANOW;
int /*<<< orphan*/ perror(char *);
scalar_t__ tcgetattr(int, struct termios *);
scalar_t__ tcsetattr(int, int /*<<< orphan*/, struct termios *);
int bot_serial_enablectsrts(int fd) {
  struct termios opts;
  if (tcgetattr(fd, &opts)) {
    perror("tcgetattr");
    return -1;
  }
  opts.c_cflag |= CRTSCTS;
  if (tcsetattr(fd, TCSANOW, &opts)) {
    perror("tcsetattr");
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<bot_serial_enablectsrts>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x10(%rbp),%rsi
call   1030 <tcgetattr@plt>
cmp    $0x0,%rax
je     1169 <bot_serial_enablectsrts+0x39>
lea    0xea8(%rip),%rdi
call   1050 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11b6 <bot_serial_enablectsrts+0x86>
mov    0x2e60(%rip),%rax
mov    (%rax),%eax
or     -0x10(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2e66(%rip),%rax
mov    (%rax),%esi
lea    -0x10(%rbp),%rdx
call   1040 <tcsetattr@plt>
cmp    $0x0,%rax
je     11af <bot_serial_enablectsrts+0x7f>
lea    0xe6c(%rip),%rdi
call   1050 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11b6 <bot_serial_enablectsrts+0x86>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bot_serial_enablectsrts>:
push   %rbx
sub    $0x10,%rsp
mov    %edi,%ebx
lea    0x8(%rsp),%rsi
call   1030 <tcgetattr@plt>
test   %rax,%rax
jne    1178 <bot_serial_enablectsrts+0x48>
mov    0x2e83(%rip),%rax
mov    (%rax),%eax
or     %eax,0x8(%rsp)
mov    0x2e8e(%rip),%rax
mov    (%rax),%esi
lea    0x8(%rsp),%rdx
mov    %ebx,%edi
call   1040 <tcsetattr@plt>
mov    %rax,%rcx
xor    %eax,%eax
test   %rcx,%rcx
jne    1181 <bot_serial_enablectsrts+0x51>
add    $0x10,%rsp
pop    %rbx
ret
lea    0xe81(%rip),%rdi
jmp    1188 <bot_serial_enablectsrts+0x58>
lea    0xe82(%rip),%rdi
call   1050 <perror@plt>
mov    $0xffffffff,%eax
jmp    1172 <bot_serial_enablectsrts+0x42>

LLVM IR (-O0):
%struct.termios = type { i32 }
@.str = [10 x i8] c"tcgetattr\00"
@CRTSCTS = global i32 0
@TCSANOW = global i32 0
@.str.1 = [10 x i8] c"tcsetattr\00"
define i32 @bot_serial_enablectsrts(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca %struct.termios
store i32 %0, i32* %3
%5 = load i32, i32* %3
%6 = call i64 @tcgetattr(i32 %5, %struct.termios* %4)
%7 = icmp ne i64 %6, 0
br i1 %7, label %8, label %10
8: ; preds = %1
%9 = call i32 @perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %2
br label %22
10: ; preds = %1
%11 = load i32, i32* @CRTSCTS
%12 = getelementptr inbounds %struct.termios, %struct.termios* %4, i32 0, i32 0
%13 = load i32, i32* %12
%14 = or i32 %13, %11
store i32 %14, i32* %12
%15 = load i32, i32* %3
%16 = load i32, i32* @TCSANOW
%17 = call i64 @tcsetattr(i32 %15, i32 %16, %struct.termios* %4)
%18 = icmp ne i64 %17, 0
br i1 %18, label %19, label %21
19: ; preds = %10
%20 = call i32 @perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %2
br label %22
21: ; preds = %10
store i32 0, i32* %2
br label %22
22: ; preds = %21, %19, %8
%23 = load i32, i32* %2
ret i32 %23
}

LLVM IR (-O2):
%struct.termios = type { i32 }
@.str = [10 x i8] c"tcgetattr\00"
@CRTSCTS = global i32 0
@TCSANOW = global i32 0
@.str.1 = [10 x i8] c"tcsetattr\00"
define i32 @bot_serial_enablectsrts(i32 %0) {
%2 = alloca %struct.termios
%3 = bitcast %struct.termios* %2 to i8*
%4 = call i64 @tcgetattr(i32 %0, %struct.termios* %2)
%5 = icmp eq i64 %4, 0
br i1 %5, label %6, label %14
6: ; preds = %1
%7 = load i32, i32* @CRTSCTS
%8 = getelementptr inbounds %struct.termios, %struct.termios* %2, i64 0, i32 0
%9 = load i32, i32* %8
%10 = or i32 %9, %7
store i32 %10, i32* %8
%11 = load i32, i32* @TCSANOW
%12 = call i64 @tcsetattr(i32 %0, i32 %11, %struct.termios* %2)
%13 = icmp eq i64 %12, 0
br i1 %13, label %17, label %14
14: ; preds = %6, %1
%15 = phi i8* [ getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), %1 ], [ getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), %6 ]
%16 = call i32 @perror(i8* %15)
br label %17
17: ; preds = %14, %6
%18 = phi i32 [ 0, %6 ], [ -1, %14 ]
ret i32 %18
}