#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 c_iflag;
};

/* Variables and functions */
int IXOFF;
int IXON;
int /*<<< orphan*/ TCSANOW;
int /*<<< orphan*/ perror(char *);
scalar_t__ tcgetattr(int, struct termios *);
scalar_t__ tcsetattr(int, int /*<<< orphan*/, struct termios *);
int bot_serial_enablexon(int fd) {
  struct termios opts;
  if (tcgetattr(fd, &opts)) {
    perror("tcgetattr");
    return -1;
  }
  opts.c_iflag |= (IXON | IXOFF);
  if (tcsetattr(fd, TCSANOW, &opts)) {
    perror("tcsetattr");
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<bot_serial_enablexon>:
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_enablexon+0x39>
lea    0xea8(%rip),%rdi
call   1050 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11bf <bot_serial_enablexon+0x8f>
mov    0x2e70(%rip),%rax
mov    (%rax),%eax
mov    0x2e6f(%rip),%rcx
or     (%rcx),%eax
or     -0x10(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2e4d(%rip),%rax
mov    (%rax),%esi
lea    -0x10(%rbp),%rdx
call   1040 <tcsetattr@plt>
cmp    $0x0,%rax
je     11b8 <bot_serial_enablexon+0x88>
lea    0xe63(%rip),%rdi
call   1050 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11bf <bot_serial_enablexon+0x8f>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bot_serial_enablexon>:
push   %rbx
sub    $0x10,%rsp
mov    %edi,%ebx
lea    0x8(%rsp),%rsi
call   1030 <tcgetattr@plt>
test   %rax,%rax
jne    1181 <bot_serial_enablexon+0x51>
mov    0x2e93(%rip),%rax
mov    0x2e94(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
or     %ecx,0x8(%rsp)
mov    0x2e75(%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    118a <bot_serial_enablexon+0x5a>
add    $0x10,%rsp
pop    %rbx
ret
lea    0xe78(%rip),%rdi
jmp    1191 <bot_serial_enablexon+0x61>
lea    0xe79(%rip),%rdi
call   1050 <perror@plt>
mov    $0xffffffff,%eax
jmp    117b <bot_serial_enablexon+0x4b>

LLVM IR (-O0):
%struct.termios = type { i32 }
@.str = [10 x i8] c"tcgetattr\00"
@IXON = global i32 0
@IXOFF = global i32 0
@TCSANOW = global i32 0
@.str.1 = [10 x i8] c"tcsetattr\00"
define i32 @bot_serial_enablexon(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 %24
10: ; preds = %1
%11 = load i32, i32* @IXON
%12 = load i32, i32* @IXOFF
%13 = or i32 %11, %12
%14 = getelementptr inbounds %struct.termios, %struct.termios* %4, i32 0, i32 0
%15 = load i32, i32* %14
%16 = or i32 %15, %13
store i32 %16, i32* %14
%17 = load i32, i32* %3
%18 = load i32, i32* @TCSANOW
%19 = call i64 @tcsetattr(i32 %17, i32 %18, %struct.termios* %4)
%20 = icmp ne i64 %19, 0
br i1 %20, label %21, label %23
21: ; preds = %10
%22 = 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 %24
23: ; preds = %10
store i32 0, i32* %2
br label %24
24: ; preds = %23, %21, %8
%25 = load i32, i32* %2
ret i32 %25
}

LLVM IR (-O2):
%struct.termios = type { i32 }
@.str = [10 x i8] c"tcgetattr\00"
@IXON = global i32 0
@IXOFF = global i32 0
@TCSANOW = global i32 0
@.str.1 = [10 x i8] c"tcsetattr\00"
define i32 @bot_serial_enablexon(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 %16
6: ; preds = %1
%7 = load i32, i32* @IXON
%8 = load i32, i32* @IXOFF
%9 = or i32 %8, %7
%10 = getelementptr inbounds %struct.termios, %struct.termios* %2, i64 0, i32 0
%11 = load i32, i32* %10
%12 = or i32 %9, %11
store i32 %12, i32* %10
%13 = load i32, i32* @TCSANOW
%14 = call i64 @tcsetattr(i32 %0, i32 %13, %struct.termios* %2)
%15 = icmp eq i64 %14, 0
br i1 %15, label %19, label %16
16: ; preds = %6, %1
%17 = 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 ]
%18 = call i32 @perror(i8* %17)
br label %19
19: ; preds = %16, %6
%20 = phi i32 [ 0, %6 ], [ -1, %16 ]
ret i32 %20
}