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

/* Variables and functions */
int /*<<< orphan*/ B9600;
int CLOCAL;
int CREAD;
int CRTSCTS;
int CS8;
int CSIZE;
int CSTOPB;
int ECHO;
int ECHOE;
int /*<<< orphan*/ F_SETFL;
int ICANON;
int ISIG;
int IXANY;
int IXOFF;
int IXON;
int /*<<< orphan*/ OPOST;
int PARENB;
int /*<<< orphan*/ TCSANOW;
size_t VMIN;
size_t VTIME;
int /*<<< orphan*/ cfsetispeed(struct termios *, int /*<<< orphan*/);
int /*<<< orphan*/ cfsetospeed(struct termios *, int /*<<< orphan*/);
int /*<<< orphan*/ fcntl(int, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ tcgetattr(int, struct termios *);
int /*<<< orphan*/ tcsetattr(int, int /*<<< orphan*/, struct termios *);
void config_port(int fd) {
  fcntl(fd, F_SETFL, 0);
  struct termios options;
  tcgetattr(fd, &options);
  cfsetispeed(&options, B9600);
  cfsetospeed(&options, B9600);
  options.c_cflag |= (CLOCAL | CREAD);
  options.c_cflag &= ~PARENB;
  options.c_cflag &= ~CSTOPB;
  options.c_cflag &= ~CSIZE;
  options.c_cflag |= CS8;
  options.c_cflag &= ~CRTSCTS;
  options.c_iflag &= ~(IXON | IXOFF | IXANY);
  options.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG);
  options.c_oflag &= ~OPOST;
  options.c_cc[VMIN] = 0;
  options.c_cc[VTIME] = 10;
  tcsetattr(fd, TCSANOW, &options);
}


x86 assembly (clang, -O0):
<config_port>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2e0b(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1030 <fcntl@plt>
mov    -0x4(%rbp),%edi
lea    -0x28(%rbp),%rsi
call   1050 <tcgetattr@plt>
mov    0x2e27(%rip),%rax
mov    (%rax),%esi
lea    -0x28(%rbp),%rdi
call   1070 <cfsetispeed@plt>
mov    0x2e15(%rip),%rax
mov    (%rax),%esi
lea    -0x28(%rbp),%rdi
call   1040 <cfsetospeed@plt>
mov    0x2d9b(%rip),%rax
mov    (%rax),%eax
mov    0x2df2(%rip),%rcx
or     (%rcx),%eax
or     -0x28(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    0x2e13(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x28(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    0x2d79(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x28(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    0x2da7(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x28(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    0x2da5(%rip),%rax
mov    (%rax),%eax
or     -0x28(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    0x2d4e(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x28(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    0x2dc4(%rip),%rax
mov    (%rax),%eax
mov    0x2dcb(%rip),%rcx
or     (%rcx),%eax
mov    0x2d52(%rip),%rcx
or     (%rcx),%eax
xor    $0xffffffff,%eax
and    -0x24(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    0x2d28(%rip),%rax
mov    (%rax),%eax
mov    0x2d7f(%rip),%rcx
or     (%rcx),%eax
mov    0x2d6e(%rip),%rcx
or     (%rcx),%eax
mov    0x2d5d(%rip),%rcx
or     (%rcx),%eax
xor    $0xffffffff,%eax
and    -0x20(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    0x2d7b(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x10(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x18(%rbp),%rax
mov    0x2d15(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x0,(%rax,%rcx,4)
mov    -0x18(%rbp),%rax
mov    0x2cd8(%rip),%rcx
mov    (%rcx),%rcx
movl   $0xa,(%rax,%rcx,4)
mov    -0x4(%rbp),%edi
mov    0x2d24(%rip),%rax
mov    (%rax),%esi
lea    -0x28(%rbp),%rdx
call   1060 <tcsetattr@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<config_port>:
push   %rbp
push   %r14
push   %rbx
sub    $0x20,%rsp
mov    %edi,%ebp
mov    0x2e0f(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1030 <fcntl@plt>
mov    %rsp,%r14
mov    %ebp,%edi
mov    %r14,%rsi
call   1050 <tcgetattr@plt>
mov    0x2e2a(%rip),%rbx
mov    (%rbx),%esi
mov    %r14,%rdi
call   1070 <cfsetispeed@plt>
mov    (%rbx),%esi
mov    %r14,%rdi
call   1040 <cfsetospeed@plt>
mov    0x2da7(%rip),%rax
mov    0x2e00(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
or     (%rsp),%ecx
mov    0x2e22(%rip),%rax
mov    (%rax),%eax
mov    0x2d91(%rip),%rdx
or     (%rdx),%eax
mov    0x2dc8(%rip),%rdx
or     (%rdx),%eax
not    %eax
and    %ecx,%eax
mov    0x2dcb(%rip),%rcx
or     (%rcx),%eax
mov    0x2d7a(%rip),%rcx
mov    (%rcx),%ecx
not    %ecx
and    %eax,%ecx
mov    %ecx,(%rsp)
mov    0x2df2(%rip),%rax
mov    0x2dfb(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
mov    0x2d80(%rip),%rax
or     (%rax),%ecx
not    %ecx
and    %ecx,0x4(%rsp)
mov    0x2d59(%rip),%rax
mov    0x2db2(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
mov    0x2d9f(%rip),%rax
or     (%rax),%ecx
mov    0x2d8e(%rip),%rax
or     (%rax),%ecx
not    %ecx
and    %ecx,0x8(%rsp)
mov    0x2daf(%rip),%rax
mov    (%rax),%eax
not    %eax
and    %eax,0x18(%rsp)
mov    0x10(%rsp),%rax
mov    0x2d4b(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x0,(%rax,%rcx,4)
mov    0x2d12(%rip),%rcx
mov    (%rcx),%rcx
movl   $0xa,(%rax,%rcx,4)
mov    0x2d61(%rip),%rax
mov    (%rax),%esi
mov    %ebp,%edi
mov    %r14,%rdx
call   1060 <tcsetattr@plt>
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.termios = type { i32, i32, i32, i32*, i32 }
@F_SETFL = global i32 0
@B9600 = global i32 0
@CLOCAL = global i32 0
@CREAD = global i32 0
@PARENB = global i32 0
@CSTOPB = global i32 0
@CSIZE = global i32 0
@CS8 = global i32 0
@CRTSCTS = global i32 0
@IXON = global i32 0
@IXOFF = global i32 0
@IXANY = global i32 0
@ICANON = global i32 0
@ECHO = global i32 0
@ECHOE = global i32 0
@ISIG = global i32 0
@OPOST = global i32 0
@VMIN = global i64 0
@VTIME = global i64 0
@TCSANOW = global i32 0
define void @config_port(i32 %0) {
%2 = alloca i32
%3 = alloca %struct.termios
store i32 %0, i32* %2
%4 = load i32, i32* %2
%5 = load i32, i32* @F_SETFL
%6 = call i32 @fcntl(i32 %4, i32 %5, i32 0)
%7 = load i32, i32* %2
%8 = call i32 @tcgetattr(i32 %7, %struct.termios* %3)
%9 = load i32, i32* @B9600
%10 = call i32 @cfsetispeed(%struct.termios* %3, i32 %9)
%11 = load i32, i32* @B9600
%12 = call i32 @cfsetospeed(%struct.termios* %3, i32 %11)
%13 = load i32, i32* @CLOCAL
%14 = load i32, i32* @CREAD
%15 = or i32 %13, %14
%16 = getelementptr inbounds %struct.termios, %struct.termios* %3, i32 0, i32 0
%17 = load i32, i32* %16
%18 = or i32 %17, %15
store i32 %18, i32* %16
%19 = load i32, i32* @PARENB
%20 = xor i32 %19, -1
%21 = getelementptr inbounds %struct.termios, %struct.termios* %3, i32 0, i32 0
%22 = load i32, i32* %21
%23 = and i32 %22, %20
store i32 %23, i32* %21
%24 = load i32, i32* @CSTOPB
%25 = xor i32 %24, -1
%26 = getelementptr inbounds %struct.termios, %struct.termios* %3, i32 0, i32 0
%27 = load i32, i32* %26
%28 = and i32 %27, %25
store i32 %28, i32* %26
%29 = load i32, i32* @CSIZE
%30 = xor i32 %29, -1
%31 = getelementptr inbounds %struct.termios, %struct.termios* %3, i32 0, i32 0
%32 = load i32, i32* %31
%33 = and i32 %32, %30
store i32 %33, i32* %31
%34 = load i32, i32* @CS8
%35 = getelementptr inbounds %struct.termios, %struct.termios* %3, i32 0, i32 0
%36 = load i32, i32* %35
%37 = or i32 %36, %34
store i32 %37, i32* %35
%38 = load i32, i32* @CRTSCTS
%39 = xor i32 %38, -1
%40 = getelementptr inbounds %struct.termios, %struct.termios* %3, i32 0, i32 0
%41 = load i32, i32* %40
%42 = and i32 %41, %39
store i32 %42, i32* %40
%43 = load i32, i32* @IXON
%44 = load i32, i32* @IXOFF
%45 = or i32 %43, %44
%46 = load i32, i32* @IXANY
%47 = or i32 %45, %46
%48 = xor i32 %47, -1
%49 = getelementptr inbounds %struct.termios, %struct.termios* %3, i32 0, i32 1
%50 = load i32, i32* %49
%51 = and i32 %50, %48
store i32 %51, i32* %49
%52 = load i32, i32* @ICANON
%53 = load i32, i32* @ECHO
%54 = or i32 %52, %53
%55 = load i32, i32* @ECHOE
%56 = or i32 %54, %55
%57 = load i32, i32* @ISIG
%58 = or i32 %56, %57
%59 = xor i32 %58, -1
%60 = getelementptr inbounds %struct.termios, %struct.termios* %3, i32 0, i32 2
%61 = load i32, i32* %60
%62 = and i32 %61, %59
store i32 %62, i32* %60
%63 = load i32, i32* @OPOST
%64 = xor i32 %63, -1
%65 = getelementptr inbounds %struct.termios, %struct.termios* %3, i32 0, i32 4
%66 = load i32, i32* %65
%67 = and i32 %66, %64
store i32 %67, i32* %65
%68 = getelementptr inbounds %struct.termios, %struct.termios* %3, i32 0, i32 3
%69 = load i32*, i32** %68
%70 = load i64, i64* @VMIN
%71 = getelementptr inbounds i32, i32* %69, i64 %70
store i32 0, i32* %71
%72 = getelementptr inbounds %struct.termios, %struct.termios* %3, i32 0, i32 3
%73 = load i32*, i32** %72
%74 = load i64, i64* @VTIME
%75 = getelementptr inbounds i32, i32* %73, i64 %74
store i32 10, i32* %75
%76 = load i32, i32* %2
%77 = load i32, i32* @TCSANOW
%78 = call i32 @tcsetattr(i32 %76, i32 %77, %struct.termios* %3)
ret void
}

LLVM IR (-O2):
%struct.termios = type { i32, i32, i32, i32*, i32 }
@F_SETFL = global i32 0
@B9600 = global i32 0
@CLOCAL = global i32 0
@CREAD = global i32 0
@PARENB = global i32 0
@CSTOPB = global i32 0
@CSIZE = global i32 0
@CS8 = global i32 0
@CRTSCTS = global i32 0
@IXON = global i32 0
@IXOFF = global i32 0
@IXANY = global i32 0
@ICANON = global i32 0
@ECHO = global i32 0
@ECHOE = global i32 0
@ISIG = global i32 0
@OPOST = global i32 0
@VMIN = global i64 0
@VTIME = global i64 0
@TCSANOW = global i32 0
define void @config_port(i32 %0) {
%2 = alloca %struct.termios
%3 = load i32, i32* @F_SETFL
%4 = tail call i32 @fcntl(i32 %0, i32 %3, i32 0)
%5 = bitcast %struct.termios* %2 to i8*
%6 = call i32 @tcgetattr(i32 %0, %struct.termios* %2)
%7 = load i32, i32* @B9600
%8 = call i32 @cfsetispeed(%struct.termios* %2, i32 %7)
%9 = load i32, i32* @B9600
%10 = call i32 @cfsetospeed(%struct.termios* %2, i32 %9)
%11 = load i32, i32* @CLOCAL
%12 = load i32, i32* @CREAD
%13 = or i32 %12, %11
%14 = getelementptr inbounds %struct.termios, %struct.termios* %2, i64 0, i32 0
%15 = load i32, i32* %14
%16 = or i32 %13, %15
%17 = load i32, i32* @PARENB
%18 = load i32, i32* @CSTOPB
%19 = or i32 %17, %18
%20 = load i32, i32* @CSIZE
%21 = or i32 %19, %20
%22 = xor i32 %21, -1
%23 = and i32 %16, %22
%24 = load i32, i32* @CS8
%25 = or i32 %24, %23
%26 = load i32, i32* @CRTSCTS
%27 = xor i32 %26, -1
%28 = and i32 %25, %27
store i32 %28, i32* %14
%29 = load i32, i32* @IXON
%30 = load i32, i32* @IXOFF
%31 = or i32 %30, %29
%32 = load i32, i32* @IXANY
%33 = or i32 %31, %32
%34 = xor i32 %33, -1
%35 = getelementptr inbounds %struct.termios, %struct.termios* %2, i64 0, i32 1
%36 = load i32, i32* %35
%37 = and i32 %36, %34
store i32 %37, i32* %35
%38 = load i32, i32* @ICANON
%39 = load i32, i32* @ECHO
%40 = or i32 %39, %38
%41 = load i32, i32* @ECHOE
%42 = or i32 %40, %41
%43 = load i32, i32* @ISIG
%44 = or i32 %42, %43
%45 = xor i32 %44, -1
%46 = getelementptr inbounds %struct.termios, %struct.termios* %2, i64 0, i32 2
%47 = load i32, i32* %46
%48 = and i32 %47, %45
store i32 %48, i32* %46
%49 = load i32, i32* @OPOST
%50 = xor i32 %49, -1
%51 = getelementptr inbounds %struct.termios, %struct.termios* %2, i64 0, i32 4
%52 = load i32, i32* %51
%53 = and i32 %52, %50
store i32 %53, i32* %51
%54 = getelementptr inbounds %struct.termios, %struct.termios* %2, i64 0, i32 3
%55 = load i32*, i32** %54
%56 = load i64, i64* @VMIN
%57 = getelementptr inbounds i32, i32* %55, i64 %56
store i32 0, i32* %57
%58 = load i64, i64* @VTIME
%59 = getelementptr inbounds i32, i32* %55, i64 %58
store i32 10, i32* %59
%60 = load i32, i32* @TCSANOW
%61 = call i32 @tcsetattr(i32 %0, i32 %60, %struct.termios* %2)
ret void
}