#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_iflag;
  int *c_cc;
  scalar_t__ c_oflag;
  scalar_t__ c_lflag;
};

/* Variables and functions */
int CLOCAL;
int CREAD;
int CS8;
int CSIZE;
int CSTOPB;
int IGNBRK;
int IXANY;
int IXOFF;
int IXON;
int PARENB;
int /*<<< orphan*/ TCSANOW;
size_t VMIN;
size_t VTIME;
int /*<<< orphan*/ cfsetispeed(struct termios *, int);
int /*<<< orphan*/ cfsetospeed(struct termios *, int);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ memset(struct termios *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, char *);
char *strerror(int /*<<< orphan*/);
scalar_t__ tcgetattr(int, struct termios *);
scalar_t__ tcsetattr(int, int /*<<< orphan*/, struct termios *);
int set_avr_attribs(int fd, int speed, int parity) {
  struct termios tty;
  memset(&tty, 0, sizeof tty);
  if (tcgetattr(fd, &tty) != 0) {
    printf("error %s from tcgetattr", strerror(errno));
    return -1;
  }
  cfsetospeed(&tty, speed);
  cfsetispeed(&tty, speed);
  tty.c_cflag &= ~CSIZE;
  tty.c_cflag |= 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_iflag &= ~(IXON | IXOFF | IXANY);
  tty.c_cflag |= (CLOCAL | CREAD);
  tty.c_cflag &= ~PARENB;
  tty.c_cflag &= ~CSTOPB;
  tty.c_cflag &= ~CSIZE;
  tty.c_cflag |= CS8;
  if (tcsetattr(fd, TCSANOW, &tty) != 0) {
    printf("error %s from tcsetattr", strerror(errno));
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<set_avr_attribs>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
lea    -0x30(%rbp),%rdi
xor    %esi,%esi
mov    $0x20,%edx
call   1050 <memset@plt>
mov    -0x8(%rbp),%edi
lea    -0x30(%rbp),%rsi
call   1060 <tcgetattr@plt>
cmp    $0x0,%rax
je     11d0 <set_avr_attribs+0x60>
mov    0x2dea(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
mov    %rax,%rsi
lea    0xe41(%rip),%rdi
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1325 <set_avr_attribs+0x1b5>
mov    -0xc(%rbp),%esi
lea    -0x30(%rbp),%rdi
call   1030 <cfsetospeed@plt>
mov    -0xc(%rbp),%esi
lea    -0x30(%rbp),%rdi
call   1080 <cfsetispeed@plt>
mov    0x2dc1(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x30(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    0x2dbf(%rip),%rax
mov    (%rax),%eax
or     -0x30(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    0x2d80(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x2c(%rbp),%eax
mov    %eax,-0x2c(%rbp)
movq   $0x0,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x28(%rbp),%rax
mov    0x2d82(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x0,(%rax,%rcx,4)
mov    -0x28(%rbp),%rax
mov    0x2d3d(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x5,(%rax,%rcx,4)
mov    0x2d84(%rip),%rax
mov    (%rax),%eax
mov    0x2d83(%rip),%rcx
or     (%rcx),%eax
mov    0x2d32(%rip),%rcx
or     (%rcx),%eax
xor    $0xffffffff,%eax
and    -0x2c(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    0x2cf0(%rip),%rax
mov    (%rax),%eax
mov    0x2d3f(%rip),%rcx
or     (%rcx),%eax
or     -0x30(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    0x2d40(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x30(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    0x2cce(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x30(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    0x2cf4(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x30(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    0x2cf2(%rip),%rax
mov    (%rax),%eax
or     -0x30(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2cf0(%rip),%rax
mov    (%rax),%esi
lea    -0x30(%rbp),%rdx
call   1070 <tcsetattr@plt>
cmp    $0x0,%rax
je     131e <set_avr_attribs+0x1ae>
mov    0x2c9c(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
mov    %rax,%rsi
lea    0xd0b(%rip),%rdi
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1325 <set_avr_attribs+0x1b5>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_avr_attribs>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x20,%rsp
mov    %esi,%ebp
mov    %edi,%r15d
mov    %rsp,%rbx
xor    %r12d,%r12d
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x20,%edx
call   1050 <memset@plt>
mov    %r15d,%edi
mov    %rbx,%rsi
call   1060 <tcgetattr@plt>
test   %rax,%rax
je     11b2 <set_avr_attribs+0x42>
lea    0xe53(%rip),%rbx
jmp    1294 <set_avr_attribs+0x124>
mov    %rsp,%r14
mov    %r14,%rdi
mov    %ebp,%esi
call   1030 <cfsetospeed@plt>
mov    %r14,%rdi
mov    %ebp,%esi
call   1080 <cfsetispeed@plt>
mov    0x2de0(%rip),%rax
mov    (%rax),%edx
not    %edx
and    (%rsp),%edx
mov    0x2de2(%rip),%rcx
or     (%rcx),%edx
mov    %edx,(%rsp)
mov    0x2da6(%rip),%rdx
mov    (%rdx),%edx
not    %edx
and    %edx,0x4(%rsp)
xorps  %xmm0,%xmm0
movups %xmm0,0x10(%rsp)
mov    0x8(%rsp),%rdx
mov    0x2db2(%rip),%rsi
mov    (%rsi),%rsi
movl   $0x0,(%rdx,%rsi,4)
mov    0x2d71(%rip),%rsi
mov    (%rsi),%rsi
movl   $0x5,(%rdx,%rsi,4)
mov    0x2db8(%rip),%rdx
mov    0x2db9(%rip),%rsi
mov    (%rsi),%esi
or     (%rdx),%esi
mov    0x2d66(%rip),%rdx
or     (%rdx),%esi
not    %esi
and    %esi,0x4(%rsp)
mov    0x2d27(%rip),%rdx
mov    0x2d78(%rip),%rsi
mov    (%rsi),%esi
or     (%rdx),%esi
or     (%rsp),%esi
mov    0x2d7a(%rip),%rdx
mov    (%rdx),%edx
mov    0x2d11(%rip),%rdi
or     (%rdi),%edx
or     (%rax),%edx
not    %edx
and    %esi,%edx
or     (%rcx),%edx
mov    %edx,(%rsp)
mov    0x2d55(%rip),%rax
mov    (%rax),%esi
mov    %r15d,%edi
mov    %r14,%rdx
call   1070 <tcsetattr@plt>
test   %rax,%rax
je     12b3 <set_avr_attribs+0x143>
lea    0xd84(%rip),%rbx
mov    0x2cfd(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
mov    %rbx,%rdi
mov    %rax,%rsi
call   1040 <printf@plt>
mov    $0xffffffff,%r12d
mov    %r12d,%eax
add    $0x20,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.termios = type { i32, i32, i32*, i64, i64 }
@.str = [24 x i8] c"error %s from tcgetattr\00"
@errno = global i32 0
@CSIZE = global i32 0
@CS8 = global i32 0
@IGNBRK = global i32 0
@VMIN = global i64 0
@VTIME = global i64 0
@IXON = global i32 0
@IXOFF = global i32 0
@IXANY = global i32 0
@CLOCAL = global i32 0
@CREAD = global i32 0
@PARENB = global i32 0
@CSTOPB = global i32 0
@TCSANOW = global i32 0
@.str.1 = [24 x i8] c"error %s from tcsetattr\00"
define i32 @set_avr_attribs(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 32)
%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 %17
13: ; preds = %3
%14 = load i32, i32* @errno
%15 = call i8* @strerror(i32 %14)
%16 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8* %15)
store i32 -1, i32* %4
br label %89
17: ; preds = %3
%18 = load i32, i32* %6
%19 = call i32 @cfsetospeed(%struct.termios* %8, i32 %18)
%20 = load i32, i32* %6
%21 = call i32 @cfsetispeed(%struct.termios* %8, i32 %20)
%22 = load i32, i32* @CSIZE
%23 = xor i32 %22, -1
%24 = getelementptr inbounds %struct.termios, %struct.termios* %8, i32 0, i32 0
%25 = load i32, i32* %24
%26 = and i32 %25, %23
store i32 %26, i32* %24
%27 = load i32, i32* @CS8
%28 = getelementptr inbounds %struct.termios, %struct.termios* %8, i32 0, i32 0
%29 = load i32, i32* %28
%30 = or i32 %29, %27
store i32 %30, i32* %28
%31 = load i32, i32* @IGNBRK
%32 = xor i32 %31, -1
%33 = getelementptr inbounds %struct.termios, %struct.termios* %8, i32 0, i32 1
%34 = load i32, i32* %33
%35 = and i32 %34, %32
store i32 %35, i32* %33
%36 = getelementptr inbounds %struct.termios, %struct.termios* %8, i32 0, i32 4
store i64 0, i64* %36
%37 = getelementptr inbounds %struct.termios, %struct.termios* %8, i32 0, i32 3
store i64 0, i64* %37
%38 = getelementptr inbounds %struct.termios, %struct.termios* %8, i32 0, i32 2
%39 = load i32*, i32** %38
%40 = load i64, i64* @VMIN
%41 = getelementptr inbounds i32, i32* %39, i64 %40
store i32 0, i32* %41
%42 = getelementptr inbounds %struct.termios, %struct.termios* %8, i32 0, i32 2
%43 = load i32*, i32** %42
%44 = load i64, i64* @VTIME
%45 = getelementptr inbounds i32, i32* %43, i64 %44
store i32 5, i32* %45
%46 = load i32, i32* @IXON
%47 = load i32, i32* @IXOFF
%48 = or i32 %46, %47
%49 = load i32, i32* @IXANY
%50 = or i32 %48, %49
%51 = xor i32 %50, -1
%52 = getelementptr inbounds %struct.termios, %struct.termios* %8, i32 0, i32 1
%53 = load i32, i32* %52
%54 = and i32 %53, %51
store i32 %54, i32* %52
%55 = load i32, i32* @CLOCAL
%56 = load i32, i32* @CREAD
%57 = or i32 %55, %56
%58 = getelementptr inbounds %struct.termios, %struct.termios* %8, i32 0, i32 0
%59 = load i32, i32* %58
%60 = or i32 %59, %57
store i32 %60, i32* %58
%61 = load i32, i32* @PARENB
%62 = xor i32 %61, -1
%63 = getelementptr inbounds %struct.termios, %struct.termios* %8, i32 0, i32 0
%64 = load i32, i32* %63
%65 = and i32 %64, %62
store i32 %65, i32* %63
%66 = load i32, i32* @CSTOPB
%67 = xor i32 %66, -1
%68 = getelementptr inbounds %struct.termios, %struct.termios* %8, i32 0, i32 0
%69 = load i32, i32* %68
%70 = and i32 %69, %67
store i32 %70, i32* %68
%71 = load i32, i32* @CSIZE
%72 = xor i32 %71, -1
%73 = getelementptr inbounds %struct.termios, %struct.termios* %8, i32 0, i32 0
%74 = load i32, i32* %73
%75 = and i32 %74, %72
store i32 %75, i32* %73
%76 = load i32, i32* @CS8
%77 = getelementptr inbounds %struct.termios, %struct.termios* %8, i32 0, i32 0
%78 = load i32, i32* %77
%79 = or i32 %78, %76
store i32 %79, i32* %77
%80 = load i32, i32* %5
%81 = load i32, i32* @TCSANOW
%82 = call i64 @tcsetattr(i32 %80, i32 %81, %struct.termios* %8)
%83 = icmp ne i64 %82, 0
br i1 %83, label %84, label %88
84: ; preds = %17
%85 = load i32, i32* @errno
%86 = call i8* @strerror(i32 %85)
%87 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i8* %86)
store i32 -1, i32* %4
br label %89
88: ; preds = %17
store i32 0, i32* %4
br label %89
89: ; preds = %88, %84, %13
%90 = load i32, i32* %4
ret i32 %90
}

LLVM IR (-O2):
%struct.termios = type { i32, i32, i32*, i64, i64 }
@.str = [24 x i8] c"error %s from tcgetattr\00"
@errno = global i32 0
@CSIZE = global i32 0
@CS8 = global i32 0
@IGNBRK = global i32 0
@VMIN = global i64 0
@VTIME = global i64 0
@IXON = global i32 0
@IXOFF = global i32 0
@IXANY = global i32 0
@CLOCAL = global i32 0
@CREAD = global i32 0
@PARENB = global i32 0
@CSTOPB = global i32 0
@TCSANOW = global i32 0
@.str.1 = [24 x i8] c"error %s from tcsetattr\00"
define i32 @set_avr_attribs(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 32)
%7 = call i64 @tcgetattr(i32 %0, %struct.termios* %4)
%8 = icmp eq i64 %7, 0
br i1 %8, label %9, label %57
9: ; preds = %3
%10 = call i32 @cfsetospeed(%struct.termios* %4, i32 %1)
%11 = call i32 @cfsetispeed(%struct.termios* %4, i32 %1)
%12 = load i32, i32* @CSIZE
%13 = xor i32 %12, -1
%14 = getelementptr inbounds %struct.termios, %struct.termios* %4, i64 0, i32 0
%15 = load i32, i32* %14
%16 = and i32 %15, %13
%17 = load i32, i32* @CS8
%18 = or i32 %17, %16
store i32 %18, i32* %14
%19 = load i32, i32* @IGNBRK
%20 = xor i32 %19, -1
%21 = getelementptr inbounds %struct.termios, %struct.termios* %4, i64 0, i32 1
%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 3
%25 = getelementptr inbounds %struct.termios, %struct.termios* %4, i64 0, i32 2
%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* @IXON
%33 = load i32, i32* @IXOFF
%34 = or i32 %33, %32
%35 = load i32, i32* @IXANY
%36 = or i32 %34, %35
%37 = xor i32 %36, -1
%38 = load i32, i32* %21
%39 = and i32 %38, %37
store i32 %39, i32* %21
%40 = load i32, i32* @CLOCAL
%41 = load i32, i32* @CREAD
%42 = or i32 %41, %40
%43 = load i32, i32* %14
%44 = or i32 %42, %43
%45 = load i32, i32* @PARENB
%46 = load i32, i32* @CSTOPB
%47 = or i32 %45, %46
%48 = load i32, i32* @CSIZE
%49 = or i32 %47, %48
%50 = xor i32 %49, -1
%51 = and i32 %44, %50
%52 = load i32, i32* @CS8
%53 = or i32 %52, %51
store i32 %53, i32* %14
%54 = load i32, i32* @TCSANOW
%55 = call i64 @tcsetattr(i32 %0, i32 %54, %struct.termios* %4)
%56 = icmp eq i64 %55, 0
br i1 %56, label %62, label %57
57: ; preds = %9, %3
%58 = phi i8* [ getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), %3 ], [ getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), %9 ]
%59 = load i32, i32* @errno
%60 = call i8* @strerror(i32 %59)
%61 = call i32 @printf(i8* %58, i8* %60)
br label %62
62: ; preds = %57, %9
%63 = phi i32 [ 0, %9 ], [ -1, %57 ]
ret i32 %63
}