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

/* Variables and functions */
int /*<<< orphan*/ CS8;
int /*<<< orphan*/ CSIZE;
int /*<<< orphan*/ CSTOPB;
int ECHO;
int ECHOE;
int ICANON;
int ICRNL;
int INLCR;
int ISIG;
int IXANY;
int IXOFF;
int IXON;
int OCRNL;
int ONLCR;
int OPOST;
int /*<<< orphan*/ PARENB;
int /*<<< orphan*/ TCIOFLUSH;
int /*<<< orphan*/ TCSANOW;
size_t VMIN;
size_t VTIME;
int /*<<< orphan*/ cfsetispeed(struct termios *, int);
int /*<<< orphan*/ cfsetospeed(struct termios *, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ tcflush(int, int /*<<< orphan*/);
scalar_t__ tcgetattr(int, struct termios *);
scalar_t__ tcsetattr(int, int /*<<< orphan*/, struct termios *);
void set_speed_and_parity(int fd, int speed) {
  int i = 0;
  struct termios Opt;
  if (tcgetattr(fd, &Opt) != 0) {
    perror("tcgetattr fd");
    return;
  }
  tcflush(fd, TCIOFLUSH);
  cfsetispeed(&Opt, speed);
  cfsetospeed(&Opt, speed);
  if (tcsetattr(fd, TCSANOW, &Opt) != 0) {
    perror("tcsetattr fd");
    return;
  }
  tcflush(fd, TCIOFLUSH);
  Opt.c_cflag &= ~PARENB;
  Opt.c_cflag &= ~CSTOPB;
  Opt.c_cflag &= ~CSIZE;
  Opt.c_cflag |= CS8;
  Opt.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG);
  Opt.c_iflag &= ~(IXON | IXOFF | IXANY);
  Opt.c_oflag |= ~OPOST;
  Opt.c_cc[VTIME] = 0;
  Opt.c_cc[VMIN] = 0;
  Opt.c_oflag &= ~(ONLCR | OCRNL);
  Opt.c_iflag &= ~(ICRNL | INLCR);
  tcflush(fd, TCIOFLUSH);
}


x86 assembly (clang, -O0):
<set_speed_and_parity>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x30(%rbp),%rsi
call   1050 <tcgetattr@plt>
cmp    $0x0,%rax
je     119c <set_speed_and_parity+0x3c>
lea    0xe6e(%rip),%rdi
call   1080 <perror@plt>
jmp    1321 <set_speed_and_parity+0x1c1>
mov    -0x4(%rbp),%edi
mov    0x2dc2(%rip),%rax
mov    (%rax),%esi
call   1040 <tcflush@plt>
mov    -0x8(%rbp),%esi
lea    -0x30(%rbp),%rdi
call   1070 <cfsetispeed@plt>
mov    -0x8(%rbp),%esi
lea    -0x30(%rbp),%rdi
call   1030 <cfsetospeed@plt>
mov    -0x4(%rbp),%edi
mov    0x2de1(%rip),%rax
mov    (%rax),%esi
lea    -0x30(%rbp),%rdx
call   1060 <tcsetattr@plt>
cmp    $0x0,%rax
je     11f5 <set_speed_and_parity+0x95>
lea    0xe22(%rip),%rdi
call   1080 <perror@plt>
jmp    1321 <set_speed_and_parity+0x1c1>
mov    -0x4(%rbp),%edi
mov    0x2d69(%rip),%rax
mov    (%rax),%esi
call   1040 <tcflush@plt>
mov    0x2dab(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    0x2d21(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    0x2d4f(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    0x2d4d(%rip),%rax
mov    (%rax),%eax
or     -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    0x2cfe(%rip),%rax
mov    (%rax),%eax
mov    0x2d4d(%rip),%rcx
or     (%rcx),%eax
mov    0x2d3c(%rip),%rcx
or     (%rcx),%eax
mov    0x2d2b(%rip),%rcx
or     (%rcx),%eax
xor    $0xffffffff,%eax
and    -0x30(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    0x2d41(%rip),%rax
mov    (%rax),%eax
mov    0x2d48(%rip),%rcx
or     (%rcx),%eax
mov    0x2cdf(%rip),%rcx
or     (%rcx),%eax
xor    $0xffffffff,%eax
and    -0x2c(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    0x2d25(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
or     -0x28(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    -0x20(%rbp),%rax
mov    0x2c9f(%rip),%rcx
mov    (%rcx),%rcx
movq   $0x0,(%rax,%rcx,8)
mov    -0x20(%rbp),%rax
mov    0x2cb9(%rip),%rcx
mov    (%rcx),%rcx
movq   $0x0,(%rax,%rcx,8)
mov    0x2c7f(%rip),%rax
mov    (%rax),%eax
mov    0x2d06(%rip),%rcx
or     (%rcx),%eax
xor    $0xffffffff,%eax
and    -0x28(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    0x2ce4(%rip),%rax
mov    (%rax),%eax
mov    0x2cd3(%rip),%rcx
or     (%rcx),%eax
xor    $0xffffffff,%eax
and    -0x2c(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2c4e(%rip),%rax
mov    (%rax),%esi
call   1040 <tcflush@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_speed_and_parity>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x28,%rsp
mov    %esi,%ebp
mov    %edi,%r14d
lea    0x8(%rsp),%rsi
call   1050 <tcgetattr@plt>
test   %rax,%rax
jne    12d0 <set_speed_and_parity+0x170>
mov    0x2ddf(%rip),%r15
mov    (%r15),%esi
mov    %r14d,%edi
call   1040 <tcflush@plt>
lea    0x8(%rsp),%rbx
mov    %rbx,%rdi
mov    %ebp,%esi
call   1070 <cfsetispeed@plt>
mov    %rbx,%rdi
mov    %ebp,%esi
call   1030 <cfsetospeed@plt>
mov    0x2dfc(%rip),%rax
mov    (%rax),%esi
mov    %r14d,%edi
mov    %rbx,%rdx
call   1060 <tcsetattr@plt>
test   %rax,%rax
jne    12de <set_speed_and_parity+0x17e>
mov    (%r15),%esi
mov    %r14d,%edi
call   1040 <tcflush@plt>
mov    0x2ddc(%rip),%rax
mov    (%rax),%eax
mov    0x2d5b(%rip),%rcx
or     (%rcx),%eax
mov    0x2d92(%rip),%rcx
or     (%rcx),%eax
not    %eax
and    0x20(%rsp),%eax
mov    0x2d93(%rip),%rcx
or     (%rcx),%eax
mov    0x2d4a(%rip),%rcx
mov    0x2d9b(%rip),%rdx
mov    (%rdx),%edx
or     (%rcx),%edx
mov    %eax,0x20(%rsp)
mov    0x2d84(%rip),%rax
or     (%rax),%edx
mov    0x2d73(%rip),%rax
or     (%rax),%edx
not    %edx
and    %edx,0x8(%rsp)
mov    0x2d8c(%rip),%rcx
mov    0x2d95(%rip),%rax
mov    (%rax),%eax
or     (%rcx),%eax
mov    0x2d2a(%rip),%rcx
or     (%rcx),%eax
mov    0xc(%rsp),%ecx
mov    0x2d75(%rip),%rdx
mov    (%rdx),%edx
not    %edx
or     0x10(%rsp),%edx
mov    0x18(%rsp),%rsi
mov    0x2cf1(%rip),%rdi
mov    (%rdi),%rdi
movq   $0x0,(%rsi,%rdi,8)
mov    0x2d0f(%rip),%rdi
mov    (%rdi),%rdi
movq   $0x0,(%rsi,%rdi,8)
mov    0x2cd5(%rip),%rsi
mov    0x2d5e(%rip),%rdi
mov    (%rdi),%edi
or     (%rsi),%edi
not    %edi
and    %edx,%edi
mov    %edi,0x10(%rsp)
mov    0x2d3b(%rip),%rdx
mov    0x2d2c(%rip),%rsi
mov    (%rsi),%esi
or     (%rdx),%esi
or     %eax,%esi
not    %esi
and    %ecx,%esi
mov    %esi,0xc(%rsp)
mov    (%r15),%esi
mov    %r14d,%edi
call   1040 <tcflush@plt>
add    $0x28,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd29(%rip),%rdi
call   1080 <perror@plt>
jmp    12c5 <set_speed_and_parity+0x165>
lea    0xd28(%rip),%rdi
call   1080 <perror@plt>
jmp    12c5 <set_speed_and_parity+0x165>

LLVM IR (-O0):
%struct.termios = type { i32, i32, i32, i64*, i32 }
@.str = [13 x i8] c"tcgetattr fd\00"
@TCIOFLUSH = global i32 0
@TCSANOW = global i32 0
@.str.1 = [13 x i8] c"tcsetattr fd\00"
@PARENB = global i32 0
@CSTOPB = global i32 0
@CSIZE = global i32 0
@CS8 = global i32 0
@ICANON = global i32 0
@ECHO = global i32 0
@ECHOE = global i32 0
@ISIG = global i32 0
@IXON = global i32 0
@IXOFF = global i32 0
@IXANY = global i32 0
@OPOST = global i32 0
@VTIME = global i64 0
@VMIN = global i64 0
@ONLCR = global i32 0
@OCRNL = global i32 0
@ICRNL = global i32 0
@INLCR = global i32 0
define void @set_speed_and_parity(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca %struct.termios
store i32 %0, i32* %3
store i32 %1, i32* %4
store i32 0, i32* %5
%7 = load i32, i32* %3
%8 = call i64 @tcgetattr(i32 %7, %struct.termios* %6)
%9 = icmp ne i64 %8, 0
br i1 %9, label %10, label %12
10: ; preds = %2
%11 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
br label %99
12: ; preds = %2
%13 = load i32, i32* %3
%14 = load i32, i32* @TCIOFLUSH
%15 = call i32 @tcflush(i32 %13, i32 %14)
%16 = load i32, i32* %4
%17 = call i32 @cfsetispeed(%struct.termios* %6, i32 %16)
%18 = load i32, i32* %4
%19 = call i32 @cfsetospeed(%struct.termios* %6, i32 %18)
%20 = load i32, i32* %3
%21 = load i32, i32* @TCSANOW
%22 = call i64 @tcsetattr(i32 %20, i32 %21, %struct.termios* %6)
%23 = icmp ne i64 %22, 0
br i1 %23, label %24, label %26
24: ; preds = %12
%25 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
br label %99
26: ; preds = %12
%27 = load i32, i32* %3
%28 = load i32, i32* @TCIOFLUSH
%29 = call i32 @tcflush(i32 %27, i32 %28)
%30 = load i32, i32* @PARENB
%31 = xor i32 %30, -1
%32 = getelementptr inbounds %struct.termios, %struct.termios* %6, i32 0, i32 4
%33 = load i32, i32* %32
%34 = and i32 %33, %31
store i32 %34, i32* %32
%35 = load i32, i32* @CSTOPB
%36 = xor i32 %35, -1
%37 = getelementptr inbounds %struct.termios, %struct.termios* %6, i32 0, i32 4
%38 = load i32, i32* %37
%39 = and i32 %38, %36
store i32 %39, i32* %37
%40 = load i32, i32* @CSIZE
%41 = xor i32 %40, -1
%42 = getelementptr inbounds %struct.termios, %struct.termios* %6, i32 0, i32 4
%43 = load i32, i32* %42
%44 = and i32 %43, %41
store i32 %44, i32* %42
%45 = load i32, i32* @CS8
%46 = getelementptr inbounds %struct.termios, %struct.termios* %6, i32 0, i32 4
%47 = load i32, i32* %46
%48 = or i32 %47, %45
store i32 %48, i32* %46
%49 = load i32, i32* @ICANON
%50 = load i32, i32* @ECHO
%51 = or i32 %49, %50
%52 = load i32, i32* @ECHOE
%53 = or i32 %51, %52
%54 = load i32, i32* @ISIG
%55 = or i32 %53, %54
%56 = xor i32 %55, -1
%57 = getelementptr inbounds %struct.termios, %struct.termios* %6, i32 0, i32 0
%58 = load i32, i32* %57
%59 = and i32 %58, %56
store i32 %59, i32* %57
%60 = load i32, i32* @IXON
%61 = load i32, i32* @IXOFF
%62 = or i32 %60, %61
%63 = load i32, i32* @IXANY
%64 = or i32 %62, %63
%65 = xor i32 %64, -1
%66 = getelementptr inbounds %struct.termios, %struct.termios* %6, i32 0, i32 1
%67 = load i32, i32* %66
%68 = and i32 %67, %65
store i32 %68, i32* %66
%69 = load i32, i32* @OPOST
%70 = xor i32 %69, -1
%71 = getelementptr inbounds %struct.termios, %struct.termios* %6, i32 0, i32 2
%72 = load i32, i32* %71
%73 = or i32 %72, %70
store i32 %73, i32* %71
%74 = getelementptr inbounds %struct.termios, %struct.termios* %6, i32 0, i32 3
%75 = load i64*, i64** %74
%76 = load i64, i64* @VTIME
%77 = getelementptr inbounds i64, i64* %75, i64 %76
store i64 0, i64* %77
%78 = getelementptr inbounds %struct.termios, %struct.termios* %6, i32 0, i32 3
%79 = load i64*, i64** %78
%80 = load i64, i64* @VMIN
%81 = getelementptr inbounds i64, i64* %79, i64 %80
store i64 0, i64* %81
%82 = load i32, i32* @ONLCR
%83 = load i32, i32* @OCRNL
%84 = or i32 %82, %83
%85 = xor i32 %84, -1
%86 = getelementptr inbounds %struct.termios, %struct.termios* %6, i32 0, i32 2
%87 = load i32, i32* %86
%88 = and i32 %87, %85
store i32 %88, i32* %86
%89 = load i32, i32* @ICRNL
%90 = load i32, i32* @INLCR
%91 = or i32 %89, %90
%92 = xor i32 %91, -1
%93 = getelementptr inbounds %struct.termios, %struct.termios* %6, i32 0, i32 1
%94 = load i32, i32* %93
%95 = and i32 %94, %92
store i32 %95, i32* %93
%96 = load i32, i32* %3
%97 = load i32, i32* @TCIOFLUSH
%98 = call i32 @tcflush(i32 %96, i32 %97)
br label %99
99: ; preds = %26, %24, %10
ret void
}

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