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

/* Variables and functions */
int CLOCAL;
int CREAD;
int 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 |= CLOCAL | CREAD;
  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    0x2dee(%rip),%rax
mov    (%rax),%eax
mov    0x2e1d(%rip),%rcx
or     (%rcx),%eax
or     -0x38(%rbp),%eax
mov    %eax,-0x38(%rbp)
mov    0x2dde(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x38(%rbp),%eax
mov    %eax,-0x38(%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,-0x28(%rbp)
mov    -0x24(%rbp),%eax
or     $0x0,%eax
mov    %eax,-0x24(%rbp)
mov    0x2dd6(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x28(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    -0x20(%rbp),%edx
mov    -0x30(%rbp),%rax
mov    0x2d8d(%rip),%rcx
mov    (%rcx),%rcx
mov    %edx,(%rax,%rcx,4)
mov    0x10(%rbp),%edx
mov    -0x30(%rbp),%rax
mov    0x2d91(%rip),%rcx
mov    (%rcx),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x4(%rbp),%edi
mov    0x2d71(%rip),%rax
mov    (%rax),%esi
call   1030 <tcflush@plt>
mov    -0x4(%rbp),%edi
mov    0x2d80(%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    0x2df9(%rip),%rax
mov    0x2e2a(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
or     0x10(%rsp),%ecx
mov    0x2deb(%rip),%rax
mov    (%rax),%eax
not    %eax
and    %ecx,%eax
mov    %eax,0x10(%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,0x20(%rsp)
mov    0x18(%rsp),%rax
mov    0x2dbd(%rip),%rcx
mov    (%rcx),%rcx
mov    0xc(%rsp),%edx
mov    %edx,(%rax,%rcx,4)
mov    0x2dc4(%rip),%rcx
mov    (%rcx),%rcx
mov    0x60(%rsp),%edx
mov    %edx,(%rax,%rcx,4)
mov    0x2da3(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edi
call   1030 <tcflush@plt>
mov    0x2db3(%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 }
@CLOCAL = global i32 0
@CREAD = global i32 0
@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* @CLOCAL
%21 = load i32, i32* @CREAD
%22 = or i32 %20, %21
%23 = getelementptr inbounds %struct.termios, %struct.termios* %15, i32 0, i32 0
%24 = load i32, i32* %23
%25 = or i32 %24, %22
store i32 %25, i32* %23
%26 = load i32, i32* @CRTSCTS
%27 = xor i32 %26, -1
%28 = getelementptr inbounds %struct.termios, %struct.termios* %15, i32 0, i32 0
%29 = load i32, i32* %28
%30 = and i32 %29, %27
store i32 %30, i32* %28
%31 = load i32, i32* %10
%32 = call i32 @set_data_bit(%struct.termios* %15, i32 %31)
%33 = load i8, i8* %12
%34 = call i32 @set_parity(%struct.termios* %15, i8 signext %33)
%35 = load i8*, i8** %11
%36 = call i32 @set_stopbit(%struct.termios* %15, i8* %35)
%37 = getelementptr inbounds %struct.termios, %struct.termios* %15, i32 0, i32 2
store i32 0, i32* %37
%38 = getelementptr inbounds %struct.termios, %struct.termios* %15, i32 0, i32 3
%39 = load i32, i32* %38
%40 = or i32 %39, 0
store i32 %40, i32* %38
%41 = load i32, i32* @OPOST
%42 = xor i32 %41, -1
%43 = getelementptr inbounds %struct.termios, %struct.termios* %15, i32 0, i32 2
%44 = load i32, i32* %43
%45 = and i32 %44, %42
store i32 %45, i32* %43
%46 = load i32, i32* %13
%47 = getelementptr inbounds %struct.termios, %struct.termios* %15, i32 0, i32 1
%48 = load i32*, i32** %47
%49 = load i64, i64* @VTIME
%50 = getelementptr inbounds i32, i32* %48, i64 %49
store i32 %46, i32* %50
%51 = load i32, i32* %14
%52 = getelementptr inbounds %struct.termios, %struct.termios* %15, i32 0, i32 1
%53 = load i32*, i32** %52
%54 = load i64, i64* @VMIN
%55 = getelementptr inbounds i32, i32* %53, i64 %54
store i32 %51, i32* %55
%56 = load i32, i32* %8
%57 = load i32, i32* @TCIFLUSH
%58 = call i32 @tcflush(i32 %56, i32 %57)
%59 = load i32, i32* %8
%60 = load i32, i32* @TCSANOW
%61 = call i32 @tcsetattr(i32 %59, i32 %60, %struct.termios* %15)
ret i32 %61
}

LLVM IR (-O2):
%struct.termios = type { i32, i32*, i32, i32 }
@CLOCAL = global i32 0
@CREAD = global i32 0
@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* @CLOCAL
%13 = load i32, i32* @CREAD
%14 = or i32 %13, %12
%15 = getelementptr inbounds %struct.termios, %struct.termios* %8, i64 0, i32 0
%16 = load i32, i32* %15
%17 = or i32 %14, %16
%18 = load i32, i32* @CRTSCTS
%19 = xor i32 %18, -1
%20 = and i32 %17, %19
store i32 %20, i32* %15
%21 = call i32 @set_data_bit(%struct.termios* %8, i32 %2)
%22 = call i32 @set_parity(%struct.termios* %8, i8 signext %4)
%23 = call i32 @set_stopbit(%struct.termios* %8, i8* %3)
%24 = getelementptr inbounds %struct.termios, %struct.termios* %8, i64 0, i32 2
store i32 0, i32* %24
%25 = getelementptr inbounds %struct.termios, %struct.termios* %8, i64 0, i32 1
%26 = load i32*, i32** %25
%27 = load i64, i64* @VTIME
%28 = getelementptr inbounds i32, i32* %26, i64 %27
store i32 %5, i32* %28
%29 = load i64, i64* @VMIN
%30 = getelementptr inbounds i32, i32* %26, i64 %29
store i32 %6, i32* %30
%31 = load i32, i32* @TCIFLUSH
%32 = call i32 @tcflush(i32 %0, i32 %31)
%33 = load i32, i32* @TCSANOW
%34 = call i32 @tcsetattr(i32 %0, i32 %33, %struct.termios* %8)
ret i32 %34
}