#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_cc;
  int /*<<< orphan*/ c_oflag;
  int /*<<< orphan*/ c_lflag;
  int /*<<< orphan*/ c_cflag;
};

/* Variables and functions */
int /*<<< orphan*/ CRTSCTS;
int /*<<< orphan*/ OPOST;
int /*<<< orphan*/ TCIFLUSH;
int /*<<< orphan*/ TCSANOW;
size_t VMIN;
size_t VTIME;
int /*<<< orphan*/ set_baudrate(struct termios *, int);
int /*<<< orphan*/ set_data_bit(struct termios *, int);
int /*<<< orphan*/ set_parity(struct termios *, char);
int /*<<< orphan*/ set_stopbit(struct termios *, char const *);
int /*<<< orphan*/ tcflush(int, int /*<<< orphan*/);
int /*<<< orphan*/ tcgetattr(int, struct termios *);
int tcsetattr(int, int /*<<< orphan*/, struct termios *);
int set_port_attr(int fd, int baudrate, int databit, const char *stopbit,
                  char parity, int vtime, int vmin) {
  struct termios opt;
  tcgetattr(fd, &opt);
  set_baudrate(&opt, baudrate);
  opt.c_cflag &= ~CRTSCTS;
  set_data_bit(&opt, databit);
  set_parity(&opt, parity);
  set_stopbit(&opt, stopbit);
  opt.c_oflag = 0;
  opt.c_lflag |= 0;
  opt.c_oflag &= ~OPOST;
  opt.c_cc[VTIME] = vtime;
  opt.c_cc[VMIN] = vmin;
  tcflush(fd, TCIFLUSH);
  return (tcsetattr(fd, TCSANOW, &opt));
}


x86 assembly (clang, -O0):
<set_port_attr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %r8b,%al
mov    0x10(%rbp),%r8d
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    %rcx,-0x18(%rbp)
mov    %al,-0x19(%rbp)
mov    %r9d,-0x20(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x38(%rbp),%rsi
call   1050 <tcgetattr@plt>
mov    -0x8(%rbp),%esi
lea    -0x38(%rbp),%rdi
call   1080 <set_baudrate@plt>
mov    0x2dfe(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x28(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    -0xc(%rbp),%esi
lea    -0x38(%rbp),%rdi
call   1090 <set_data_bit@plt>
lea    -0x38(%rbp),%rdi
movsbl -0x19(%rbp),%esi
call   1070 <set_parity@plt>
mov    -0x18(%rbp),%rsi
lea    -0x38(%rbp),%rdi
call   1040 <set_stopbit@plt>
movl   $0x0,-0x30(%rbp)
mov    -0x2c(%rbp),%eax
or     $0x0,%eax
mov    %eax,-0x2c(%rbp)
mov    0x2dee(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x30(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    -0x20(%rbp),%edx
mov    -0x38(%rbp),%rax
mov    0x2dad(%rip),%rcx
mov    (%rcx),%rcx
mov    %edx,(%rax,%rcx,4)
mov    0x10(%rbp),%edx
mov    -0x38(%rbp),%rax
mov    0x2db1(%rip),%rcx
mov    (%rcx),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x4(%rbp),%edi
mov    0x2d91(%rip),%rax
mov    (%rax),%esi
call   1030 <tcflush@plt>
mov    -0x4(%rbp),%edi
mov    0x2d98(%rip),%rax
mov    (%rax),%esi
lea    -0x38(%rbp),%rdx
call   1060 <tcsetattr@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_port_attr>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %r9d,0xc(%rsp)
mov    %r8d,%r13d
mov    %rcx,%r12
mov    %edx,%ebp
mov    %esi,%r15d
mov    %edi,%ebx
lea    0x10(%rsp),%r14
mov    %r14,%rsi
call   1050 <tcgetattr@plt>
mov    %r14,%rdi
mov    %r15d,%esi
call   1080 <set_baudrate@plt>
mov    0x2e09(%rip),%rax
mov    (%rax),%eax
not    %eax
and    %eax,0x20(%rsp)
mov    %r14,%rdi
mov    %ebp,%esi
call   1090 <set_data_bit@plt>
mov    %r14,%rdi
mov    %r13d,%esi
call   1070 <set_parity@plt>
mov    %r14,%rdi
mov    %r12,%rsi
call   1040 <set_stopbit@plt>
movl   $0x0,0x18(%rsp)
mov    0x10(%rsp),%rax
mov    0x2ddd(%rip),%rcx
mov    (%rcx),%rcx
mov    0xc(%rsp),%edx
mov    %edx,(%rax,%rcx,4)
mov    0x2de4(%rip),%rcx
mov    (%rcx),%rcx
mov    0x60(%rsp),%edx
mov    %edx,(%rax,%rcx,4)
mov    0x2dc3(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edi
call   1030 <tcflush@plt>
mov    0x2dcb(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edi
mov    %r14,%rdx
call   1060 <tcsetattr@plt>
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.termios = type { i32*, i32, i32, i32 }
@CRTSCTS = global i32 0
@OPOST = global i32 0
@VTIME = global i64 0
@VMIN = global i64 0
@TCIFLUSH = global i32 0
@TCSANOW = global i32 0
define i32 @set_port_attr(i32 %0, i32 %1, i32 %2, i8* %3, i8 signext %4, i32 %5, i32 %6) {
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i8*
%12 = alloca i8
%13 = alloca i32
%14 = alloca i32
%15 = alloca %struct.termios
store i32 %0, i32* %8
store i32 %1, i32* %9
store i32 %2, i32* %10
store i8* %3, i8** %11
store i8 %4, i8* %12
store i32 %5, i32* %13
store i32 %6, i32* %14
%16 = load i32, i32* %8
%17 = call i32 @tcgetattr(i32 %16, %struct.termios* %15)
%18 = load i32, i32* %9
%19 = call i32 @set_baudrate(%struct.termios* %15, i32 %18)
%20 = load i32, i32* @CRTSCTS
%21 = xor i32 %20, -1
%22 = getelementptr inbounds %struct.termios, %struct.termios* %15, i32 0, i32 3
%23 = load i32, i32* %22
%24 = and i32 %23, %21
store i32 %24, i32* %22
%25 = load i32, i32* %10
%26 = call i32 @set_data_bit(%struct.termios* %15, i32 %25)
%27 = load i8, i8* %12
%28 = call i32 @set_parity(%struct.termios* %15, i8 signext %27)
%29 = load i8*, i8** %11
%30 = call i32 @set_stopbit(%struct.termios* %15, i8* %29)
%31 = getelementptr inbounds %struct.termios, %struct.termios* %15, i32 0, i32 1
store i32 0, i32* %31
%32 = getelementptr inbounds %struct.termios, %struct.termios* %15, i32 0, i32 2
%33 = load i32, i32* %32
%34 = or i32 %33, 0
store i32 %34, i32* %32
%35 = load i32, i32* @OPOST
%36 = xor i32 %35, -1
%37 = getelementptr inbounds %struct.termios, %struct.termios* %15, i32 0, i32 1
%38 = load i32, i32* %37
%39 = and i32 %38, %36
store i32 %39, i32* %37
%40 = load i32, i32* %13
%41 = getelementptr inbounds %struct.termios, %struct.termios* %15, i32 0, i32 0
%42 = load i32*, i32** %41
%43 = load i64, i64* @VTIME
%44 = getelementptr inbounds i32, i32* %42, i64 %43
store i32 %40, i32* %44
%45 = load i32, i32* %14
%46 = getelementptr inbounds %struct.termios, %struct.termios* %15, i32 0, i32 0
%47 = load i32*, i32** %46
%48 = load i64, i64* @VMIN
%49 = getelementptr inbounds i32, i32* %47, i64 %48
store i32 %45, i32* %49
%50 = load i32, i32* %8
%51 = load i32, i32* @TCIFLUSH
%52 = call i32 @tcflush(i32 %50, i32 %51)
%53 = load i32, i32* %8
%54 = load i32, i32* @TCSANOW
%55 = call i32 @tcsetattr(i32 %53, i32 %54, %struct.termios* %15)
ret i32 %55
}

LLVM IR (-O2):
%struct.termios = type { i32*, i32, i32, i32 }
@CRTSCTS = global i32 0
@OPOST = global i32 0
@VTIME = global i64 0
@VMIN = global i64 0
@TCIFLUSH = global i32 0
@TCSANOW = global i32 0
define i32 @set_port_attr(i32 %0, i32 %1, i32 %2, i8* %3, i8 signext %4, i32 %5, i32 %6) {
%8 = alloca %struct.termios
%9 = bitcast %struct.termios* %8 to i8*
%10 = call i32 @tcgetattr(i32 %0, %struct.termios* %8)
%11 = call i32 @set_baudrate(%struct.termios* %8, i32 %1)
%12 = load i32, i32* @CRTSCTS
%13 = xor i32 %12, -1
%14 = getelementptr inbounds %struct.termios, %struct.termios* %8, i64 0, i32 3
%15 = load i32, i32* %14
%16 = and i32 %15, %13
store i32 %16, i32* %14
%17 = call i32 @set_data_bit(%struct.termios* %8, i32 %2)
%18 = call i32 @set_parity(%struct.termios* %8, i8 signext %4)
%19 = call i32 @set_stopbit(%struct.termios* %8, i8* %3)
%20 = getelementptr inbounds %struct.termios, %struct.termios* %8, i64 0, i32 1
store i32 0, i32* %20
%21 = getelementptr inbounds %struct.termios, %struct.termios* %8, i64 0, i32 0
%22 = load i32*, i32** %21
%23 = load i64, i64* @VTIME
%24 = getelementptr inbounds i32, i32* %22, i64 %23
store i32 %5, i32* %24
%25 = load i64, i64* @VMIN
%26 = getelementptr inbounds i32, i32* %22, i64 %25
store i32 %6, i32* %26
%27 = load i32, i32* @TCIFLUSH
%28 = call i32 @tcflush(i32 %0, i32 %27)
%29 = load i32, i32* @TCSANOW
%30 = call i32 @tcsetattr(i32 %0, i32 %29, %struct.termios* %8)
ret i32 %30
}