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


x86 assembly (clang, -O0):
<bot_serial_set_N82>:
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_set_N82+0x39>
lea    0xea8(%rip),%rdi
call   1050 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11d7 <bot_serial_set_N82+0xa7>
mov    0x2e68(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x10(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    0x2e5e(%rip),%rax
mov    (%rax),%eax
or     -0x10(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    0x2e2f(%rip),%rax
mov    (%rax),%eax
or     -0x10(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2e45(%rip),%rax
mov    (%rax),%esi
lea    -0x10(%rbp),%rdx
call   1040 <tcsetattr@plt>
cmp    $0x0,%rax
je     11d0 <bot_serial_set_N82+0xa0>
lea    0xe4b(%rip),%rdi
call   1050 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11d7 <bot_serial_set_N82+0xa7>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bot_serial_set_N82>:
push   %rbx
sub    $0x10,%rsp
mov    %edi,%ebx
lea    0x8(%rsp),%rsi
call   1030 <tcgetattr@plt>
test   %rax,%rax
jne    1190 <bot_serial_set_N82+0x60>
mov    0x2e8b(%rip),%rax
mov    (%rax),%eax
not    %eax
and    0x8(%rsp),%eax
mov    0x2e84(%rip),%rcx
or     (%rcx),%eax
mov    0x2e5b(%rip),%rcx
or     (%rcx),%eax
mov    %eax,0x8(%rsp)
mov    0x2e76(%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    1199 <bot_serial_set_N82+0x69>
add    $0x10,%rsp
pop    %rbx
ret
lea    0xe69(%rip),%rdi
jmp    11a0 <bot_serial_set_N82+0x70>
lea    0xe6a(%rip),%rdi
call   1050 <perror@plt>
mov    $0xffffffff,%eax
jmp    118a <bot_serial_set_N82+0x5a>

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

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