#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_cflag;
  int *c_cc;
  scalar_t__ c_oflag;
  scalar_t__ c_lflag;
  int /*<<< orphan*/ c_iflag;
};

/* Variables and functions */
int CLOCAL;
int CREAD;
int CS8;
int CSIZE;
int CSTOPB;
int /*<<< orphan*/ IGNBRK;
int PARENB;
int PARODD;
int /*<<< orphan*/ TCSANOW;
size_t VMIN;
size_t VTIME;
int /*<<< orphan*/ cfsetispeed(struct termios *, int);
int /*<<< orphan*/ cfsetospeed(struct termios *, int);
int /*<<< orphan*/ memset(struct termios *, int /*<<< orphan*/, int);
int /*<<< orphan*/ perror(char *);
scalar_t__ tcgetattr(int, struct termios *);
scalar_t__ tcsetattr(int, int /*<<< orphan*/, struct termios *);
int ANT_SetSerialAttrs(int fd, int baud, int parity) {
  struct termios tty;
  memset(&tty, 0, sizeof tty);
  if (tcgetattr(fd, &tty) != 0) {
    perror("tcgetattr");
    return -1;
  }
  cfsetospeed(&tty, baud);
  cfsetispeed(&tty, baud);
  tty.c_cflag = (tty.c_cflag & ~CSIZE) | CS8;
  tty.c_iflag &= ~IGNBRK;
  tty.c_lflag = 0;
  tty.c_oflag = 0;
  tty.c_cc[VMIN] = 0;
  tty.c_cc[VTIME] = 5;
  tty.c_cflag |= (CLOCAL | CREAD);
  tty.c_cflag &= ~(PARENB | PARODD);
  tty.c_cflag |= parity;
  tty.c_cflag &= ~CSTOPB;
  if (tcsetattr(fd, TCSANOW, &tty) != 0) {
    perror("tcsetattr");
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<ANT_SetSerialAttrs>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
lea    -0x38(%rbp),%rdi
xor    %esi,%esi
mov    $0x28,%edx
call   1040 <memset@plt>
mov    -0x8(%rbp),%edi
lea    -0x38(%rbp),%rsi
call   1050 <tcgetattr@plt>
cmp    $0x0,%rax
je     11af <ANT_SetSerialAttrs+0x4f>
lea    0xe62(%rip),%rdi
call   1080 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12bc <ANT_SetSerialAttrs+0x15c>
mov    -0xc(%rbp),%esi
lea    -0x38(%rbp),%rdi
call   1030 <cfsetospeed@plt>
mov    -0xc(%rbp),%esi
lea    -0x38(%rbp),%rdi
call   1070 <cfsetispeed@plt>
mov    -0x38(%rbp),%eax
mov    0x2de7(%rip),%rcx
mov    (%rcx),%ecx
xor    $0xffffffff,%ecx
and    %ecx,%eax
mov    0x2de9(%rip),%rcx
or     (%rcx),%eax
mov    %eax,-0x38(%rbp)
mov    0x2dbd(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
mov    -0x30(%rbp),%rax
mov    0x2daf(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x0,(%rax,%rcx,4)
mov    -0x30(%rbp),%rax
mov    0x2d7a(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x5,(%rax,%rcx,4)
mov    0x2d51(%rip),%rax
mov    (%rax),%eax
mov    0x2d90(%rip),%rcx
or     (%rcx),%eax
or     -0x38(%rbp),%eax
mov    %eax,-0x38(%rbp)
mov    0x2d99(%rip),%rax
mov    (%rax),%eax
mov    0x2d80(%rip),%rcx
or     (%rcx),%eax
xor    $0xffffffff,%eax
and    -0x38(%rbp),%eax
mov    %eax,-0x38(%rbp)
mov    -0x10(%rbp),%eax
or     -0x38(%rbp),%eax
mov    %eax,-0x38(%rbp)
mov    0x2d1d(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x38(%rbp),%eax
mov    %eax,-0x38(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2d58(%rip),%rax
mov    (%rax),%esi
lea    -0x38(%rbp),%rdx
call   1060 <tcsetattr@plt>
cmp    $0x0,%rax
je     12b5 <ANT_SetSerialAttrs+0x155>
lea    0xd66(%rip),%rdi
call   1080 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12bc <ANT_SetSerialAttrs+0x15c>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ANT_SetSerialAttrs>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %edx,%r15d
mov    %esi,%ebx
mov    %edi,%r13d
mov    %rsp,%rbp
xor    %r14d,%r14d
mov    %rbp,%rdi
xor    %esi,%esi
mov    $0x28,%edx
call   1040 <memset@plt>
mov    %r13d,%edi
mov    %rbp,%rsi
call   1050 <tcgetattr@plt>
test   %rax,%rax
jne    1277 <ANT_SetSerialAttrs+0x117>
mov    %rsp,%r12
mov    %r12,%rdi
mov    %ebx,%esi
call   1030 <cfsetospeed@plt>
mov    %r12,%rdi
mov    %ebx,%esi
call   1070 <cfsetispeed@plt>
mov    0x2dfb(%rip),%rax
mov    (%rax),%eax
not    %eax
and    (%rsp),%eax
mov    0x2dfd(%rip),%rcx
or     (%rcx),%eax
mov    %eax,(%rsp)
mov    0x2dd1(%rip),%rax
mov    (%rax),%eax
not    %eax
and    %eax,0x20(%rsp)
xorps  %xmm0,%xmm0
movups %xmm0,0x10(%rsp)
mov    0x8(%rsp),%rax
mov    0x2dcd(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x0,(%rax,%rcx,4)
mov    0x2d9c(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x5,(%rax,%rcx,4)
mov    0x2d73(%rip),%rax
mov    0x2db4(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
or     (%rsp),%ecx
mov    0x2dbe(%rip),%rax
mov    0x2da7(%rip),%rdx
mov    (%rdx),%edx
or     (%rax),%edx
not    %edx
and    %ecx,%edx
or     %r15d,%edx
mov    0x2d4d(%rip),%rax
mov    (%rax),%eax
not    %eax
and    %edx,%eax
mov    %eax,(%rsp)
mov    0x2d8d(%rip),%rax
mov    (%rax),%esi
mov    %r13d,%edi
mov    %r12,%rdx
call   1060 <tcsetattr@plt>
test   %rax,%rax
jne    1280 <ANT_SetSerialAttrs+0x120>
mov    %r14d,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd82(%rip),%rdi
jmp    1287 <ANT_SetSerialAttrs+0x127>
lea    0xd83(%rip),%rdi
call   1080 <perror@plt>
mov    $0xffffffff,%r14d
jmp    1265 <ANT_SetSerialAttrs+0x105>

LLVM IR (-O0):
%struct.termios = type { i32, i32*, i64, i64, i32 }
@.str = [10 x i8] c"tcgetattr\00"
@CSIZE = global i32 0
@CS8 = global i32 0
@IGNBRK = global i32 0
@VMIN = global i64 0
@VTIME = global i64 0
@CLOCAL = global i32 0
@CREAD = global i32 0
@PARENB = global i32 0
@PARODD = global i32 0
@CSTOPB = global i32 0
@TCSANOW = global i32 0
@.str.1 = [10 x i8] c"tcsetattr\00"
define i32 @ANT_SetSerialAttrs(i32 %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca %struct.termios
store i32 %0, i32* %5
store i32 %1, i32* %6
store i32 %2, i32* %7
%9 = call i32 @memset(%struct.termios* %8, i32 0, i32 40)
%10 = load i32, i32* %5
%11 = call i64 @tcgetattr(i32 %10, %struct.termios* %8)
%12 = icmp ne i64 %11, 0
br i1 %12, label %13, label %15
13: ; preds = %3
%14 = call i32 @perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %4
br label %72
15: ; preds = %3
%16 = load i32, i32* %6
%17 = call i32 @cfsetospeed(%struct.termios* %8, i32 %16)
%18 = load i32, i32* %6
%19 = call i32 @cfsetispeed(%struct.termios* %8, i32 %18)
%20 = getelementptr inbounds %struct.termios, %struct.termios* %8, i32 0, i32 0
%21 = load i32, i32* %20
%22 = load i32, i32* @CSIZE
%23 = xor i32 %22, -1
%24 = and i32 %21, %23
%25 = load i32, i32* @CS8
%26 = or i32 %24, %25
%27 = getelementptr inbounds %struct.termios, %struct.termios* %8, i32 0, i32 0
store i32 %26, i32* %27
%28 = load i32, i32* @IGNBRK
%29 = xor i32 %28, -1
%30 = getelementptr inbounds %struct.termios, %struct.termios* %8, i32 0, i32 4
%31 = load i32, i32* %30
%32 = and i32 %31, %29
store i32 %32, i32* %30
%33 = getelementptr inbounds %struct.termios, %struct.termios* %8, i32 0, i32 3
store i64 0, i64* %33
%34 = getelementptr inbounds %struct.termios, %struct.termios* %8, i32 0, i32 2
store i64 0, i64* %34
%35 = getelementptr inbounds %struct.termios, %struct.termios* %8, i32 0, i32 1
%36 = load i32*, i32** %35
%37 = load i64, i64* @VMIN
%38 = getelementptr inbounds i32, i32* %36, i64 %37
store i32 0, i32* %38
%39 = getelementptr inbounds %struct.termios, %struct.termios* %8, i32 0, i32 1
%40 = load i32*, i32** %39
%41 = load i64, i64* @VTIME
%42 = getelementptr inbounds i32, i32* %40, i64 %41
store i32 5, i32* %42
%43 = load i32, i32* @CLOCAL
%44 = load i32, i32* @CREAD
%45 = or i32 %43, %44
%46 = getelementptr inbounds %struct.termios, %struct.termios* %8, i32 0, i32 0
%47 = load i32, i32* %46
%48 = or i32 %47, %45
store i32 %48, i32* %46
%49 = load i32, i32* @PARENB
%50 = load i32, i32* @PARODD
%51 = or i32 %49, %50
%52 = xor i32 %51, -1
%53 = getelementptr inbounds %struct.termios, %struct.termios* %8, i32 0, i32 0
%54 = load i32, i32* %53
%55 = and i32 %54, %52
store i32 %55, i32* %53
%56 = load i32, i32* %7
%57 = getelementptr inbounds %struct.termios, %struct.termios* %8, i32 0, i32 0
%58 = load i32, i32* %57
%59 = or i32 %58, %56
store i32 %59, i32* %57
%60 = load i32, i32* @CSTOPB
%61 = xor i32 %60, -1
%62 = getelementptr inbounds %struct.termios, %struct.termios* %8, i32 0, i32 0
%63 = load i32, i32* %62
%64 = and i32 %63, %61
store i32 %64, i32* %62
%65 = load i32, i32* %5
%66 = load i32, i32* @TCSANOW
%67 = call i64 @tcsetattr(i32 %65, i32 %66, %struct.termios* %8)
%68 = icmp ne i64 %67, 0
br i1 %68, label %69, label %71
69: ; preds = %15
%70 = call i32 @perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %4
br label %72
71: ; preds = %15
store i32 0, i32* %4
br label %72
72: ; preds = %71, %69, %13
%73 = load i32, i32* %4
ret i32 %73
}

LLVM IR (-O2):
%struct.termios = type { i32, i32*, i64, i64, i32 }
@.str = [10 x i8] c"tcgetattr\00"
@CSIZE = global i32 0
@CS8 = global i32 0
@IGNBRK = global i32 0
@VMIN = global i64 0
@VTIME = global i64 0
@CLOCAL = global i32 0
@CREAD = global i32 0
@PARENB = global i32 0
@PARODD = global i32 0
@CSTOPB = global i32 0
@TCSANOW = global i32 0
@.str.1 = [10 x i8] c"tcsetattr\00"
define i32 @ANT_SetSerialAttrs(i32 %0, i32 %1, i32 %2) {
%4 = alloca %struct.termios
%5 = bitcast %struct.termios* %4 to i8*
%6 = call i32 @memset(%struct.termios* %4, i32 0, i32 40)
%7 = call i64 @tcgetattr(i32 %0, %struct.termios* %4)
%8 = icmp eq i64 %7, 0
br i1 %8, label %9, label %49
9: ; preds = %3
%10 = call i32 @cfsetospeed(%struct.termios* %4, i32 %1)
%11 = call i32 @cfsetispeed(%struct.termios* %4, i32 %1)
%12 = getelementptr inbounds %struct.termios, %struct.termios* %4, i64 0, i32 0
%13 = load i32, i32* %12
%14 = load i32, i32* @CSIZE
%15 = xor i32 %14, -1
%16 = and i32 %13, %15
%17 = load i32, i32* @CS8
%18 = or i32 %16, %17
store i32 %18, i32* %12
%19 = load i32, i32* @IGNBRK
%20 = xor i32 %19, -1
%21 = getelementptr inbounds %struct.termios, %struct.termios* %4, i64 0, i32 4
%22 = load i32, i32* %21
%23 = and i32 %22, %20
store i32 %23, i32* %21
%24 = getelementptr inbounds %struct.termios, %struct.termios* %4, i64 0, i32 2
%25 = getelementptr inbounds %struct.termios, %struct.termios* %4, i64 0, i32 1
%26 = bitcast i64* %24 to i8*
%27 = load i32*, i32** %25
%28 = load i64, i64* @VMIN
%29 = getelementptr inbounds i32, i32* %27, i64 %28
store i32 0, i32* %29
%30 = load i64, i64* @VTIME
%31 = getelementptr inbounds i32, i32* %27, i64 %30
store i32 5, i32* %31
%32 = load i32, i32* @CLOCAL
%33 = load i32, i32* @CREAD
%34 = or i32 %33, %32
%35 = load i32, i32* %12
%36 = or i32 %34, %35
%37 = load i32, i32* @PARENB
%38 = load i32, i32* @PARODD
%39 = or i32 %38, %37
%40 = xor i32 %39, -1
%41 = and i32 %36, %40
%42 = or i32 %41, %2
%43 = load i32, i32* @CSTOPB
%44 = xor i32 %43, -1
%45 = and i32 %42, %44
store i32 %45, i32* %12
%46 = load i32, i32* @TCSANOW
%47 = call i64 @tcsetattr(i32 %0, i32 %46, %struct.termios* %4)
%48 = icmp eq i64 %47, 0
br i1 %48, label %52, label %49
49: ; preds = %9, %3
%50 = phi i8* [ getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), %3 ], [ getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), %9 ]
%51 = call i32 @perror(i8* %50)
br label %52
52: ; preds = %49, %9
%53 = phi i32 [ 0, %9 ], [ -1, %49 ]
ret i32 %53
}