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

/* Variables and functions */
int /*<<< orphan*/ CLOCAL;
int /*<<< orphan*/ CREAD;
int /*<<< orphan*/ CS8;
int /*<<< orphan*/ CSIZE;
int /*<<< orphan*/ CSTOPB;
int /*<<< orphan*/ ECHO;
int /*<<< orphan*/ ECHOE;
int /*<<< orphan*/ F_SETFL;
int /*<<< orphan*/ ICANON;
int /*<<< orphan*/ INPCK;
int /*<<< orphan*/ ISIG;
int /*<<< orphan*/ IXANY;
int /*<<< orphan*/ IXOFF;
int /*<<< orphan*/ IXON;
int /*<<< orphan*/ OPOST;
int O_NOCTTY;
int O_NONBLOCK;
int O_RDWR;
int /*<<< orphan*/ 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 open(char const *, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ tcgetattr(int, struct termios *);
int /*<<< orphan*/ tcsetattr(int, int /*<<< orphan*/, struct termios *);
int open_port(const char *str, speed_t baud) {
  struct termios options;
  int fd;
  fd = open(str, O_RDWR | O_NOCTTY | O_NONBLOCK);
  if (fd == -1) {
    perror("open");
  } else {
    fcntl(fd, F_SETFL, 0);
  }
  tcgetattr(fd, &options);
  cfsetispeed(&options, baud);
  cfsetospeed(&options, baud);
  options.c_iflag &= ~INPCK;
  options.c_iflag &= ~IXON;
  options.c_iflag &= ~IXOFF;
  options.c_iflag &= ~IXANY;
  options.c_oflag |= OPOST;
  options.c_cflag |= CLOCAL;
  options.c_cflag |= CREAD;
  options.c_cflag &= ~PARENB;
  options.c_cflag &= ~CSTOPB;
  options.c_cflag &= ~CSIZE;
  options.c_cflag |= CS8;
  options.c_lflag &= ~ICANON;
  options.c_lflag &= ~ECHO;
  options.c_lflag &= ~ECHOE;
  options.c_lflag &= ~ISIG;
  options.c_cc[VMIN] = 0;
  options.c_cc[VTIME] = 0;
  tcsetattr(fd, TCSANOW, &options);
  return (fd);
}


x86 assembly (clang, -O0):
<open_port>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
mov    0x2e5e(%rip),%rax
mov    (%rax),%esi
mov    0x2dd5(%rip),%rax
or     (%rax),%esi
mov    0x2e3c(%rip),%rax
or     (%rax),%esi
call   1070 <open@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0xffffffff,-0x2c(%rbp)
jne    11c1 <open_port+0x51>
lea    0xe49(%rip),%rdi
call   1090 <perror@plt>
jmp    11d4 <open_port+0x64>
mov    -0x2c(%rbp),%edi
mov    0x2d8d(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1030 <fcntl@plt>
mov    -0x2c(%rbp),%edi
lea    -0x28(%rbp),%rsi
call   1050 <tcgetattr@plt>
mov    -0xc(%rbp),%esi
lea    -0x28(%rbp),%rdi
call   1080 <cfsetispeed@plt>
mov    -0xc(%rbp),%esi
lea    -0x28(%rbp),%rdi
call   1040 <cfsetospeed@plt>
mov    0x2d61(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x14(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    0x2db7(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x14(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    0x2dbd(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x14(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    0x2d3b(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x14(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    0x2d89(%rip),%rax
mov    (%rax),%eax
or     -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    0x2cda(%rip),%rax
mov    (%rax),%eax
or     -0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    0x2d33(%rip),%rax
mov    (%rax),%eax
or     -0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    0x2d4c(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    0x2cb2(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    0x2ce8(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    0x2ce6(%rip),%rax
mov    (%rax),%eax
or     -0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    0x2c8f(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x20(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    0x2ce5(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x20(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    0x2ccb(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x20(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    0x2cb1(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x20(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x28(%rbp),%rax
mov    0x2c83(%rip),%rcx
mov    (%rcx),%rcx
movq   $0x0,(%rax,%rcx,8)
mov    -0x28(%rbp),%rax
mov    0x2c35(%rip),%rcx
mov    (%rcx),%rcx
movq   $0x0,(%rax,%rcx,8)
mov    -0x2c(%rbp),%edi
mov    0x2c88(%rip),%rax
mov    (%rax),%esi
lea    -0x28(%rbp),%rdx
call   1060 <tcsetattr@plt>
mov    -0x2c(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<open_port>:
push   %rbp
push   %r14
push   %rbx
sub    $0x20,%rsp
mov    0x2e69(%rip),%rcx
mov    0x2de2(%rip),%rax
mov    (%rax),%eax
or     (%rcx),%eax
mov    %esi,%ebp
mov    0x2e45(%rip),%rcx
or     (%rcx),%eax
mov    %eax,%esi
call   1070 <open@plt>
mov    %eax,%ebx
cmp    $0xffffffff,%eax
je     12c6 <open_port+0x156>
mov    0x2daa(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edi
xor    %edx,%edx
call   1030 <fcntl@plt>
lea    0x8(%rsp),%r14
mov    %ebx,%edi
mov    %r14,%rsi
call   1050 <tcgetattr@plt>
mov    %r14,%rdi
mov    %ebp,%esi
call   1080 <cfsetispeed@plt>
mov    %r14,%rdi
mov    %ebp,%esi
call   1040 <cfsetospeed@plt>
mov    0x2d7d(%rip),%rax
mov    (%rax),%eax
mov    0x2ddc(%rip),%rcx
or     (%rcx),%eax
mov    0x2deb(%rip),%rcx
or     (%rcx),%eax
mov    0x2d72(%rip),%rcx
or     (%rcx),%eax
not    %eax
and    %eax,0x1c(%rsp)
mov    0x2dc3(%rip),%rax
mov    (%rax),%eax
or     %eax,0x18(%rsp)
mov    0x2d16(%rip),%rax
mov    0x14(%rsp),%ecx
or     (%rax),%ecx
mov    0x2d71(%rip),%rax
or     (%rax),%ecx
mov    0x2d90(%rip),%rax
mov    (%rax),%eax
mov    0x2cff(%rip),%rdx
or     (%rdx),%eax
mov    0x2d3e(%rip),%rdx
or     (%rdx),%eax
not    %eax
and    %ecx,%eax
mov    0x2d41(%rip),%rcx
or     (%rcx),%eax
mov    0x2cf0(%rip),%rcx
mov    (%rcx),%ecx
mov    0x2d4f(%rip),%rdx
or     (%rdx),%ecx
mov    %eax,0x14(%rsp)
mov    0x2d3a(%rip),%rax
or     (%rax),%ecx
mov    0x2d29(%rip),%rax
or     (%rax),%ecx
not    %ecx
and    %ecx,0x10(%rsp)
mov    0x8(%rsp),%rax
mov    0x2cfd(%rip),%rcx
mov    (%rcx),%rcx
movq   $0x0,(%rax,%rcx,8)
mov    0x2cb3(%rip),%rcx
mov    (%rcx),%rcx
movq   $0x0,(%rax,%rcx,8)
mov    0x2d09(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edi
mov    %r14,%rdx
call   1060 <tcsetattr@plt>
mov    %ebx,%eax
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xd33(%rip),%rdi
call   1090 <perror@plt>
jmp    11b9 <open_port+0x49>

LLVM IR (-O0):
%struct.termios = type { i64*, i32, i32, i32, i32 }
@O_RDWR = global i32 0
@O_NOCTTY = global i32 0
@O_NONBLOCK = global i32 0
@.str = [5 x i8] c"open\00"
@F_SETFL = global i32 0
@INPCK = global i32 0
@IXON = global i32 0
@IXOFF = global i32 0
@IXANY = global i32 0
@OPOST = 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
@ICANON = global i32 0
@ECHO = global i32 0
@ECHOE = global i32 0
@ISIG = global i32 0
@VMIN = global i64 0
@VTIME = global i64 0
@TCSANOW = global i32 0
define i32 @open_port(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca %struct.termios
%6 = alloca i32
store i8* %0, i8** %3
store i32 %1, i32* %4
%7 = load i8*, i8** %3
%8 = load i32, i32* @O_RDWR
%9 = load i32, i32* @O_NOCTTY
%10 = or i32 %8, %9
%11 = load i32, i32* @O_NONBLOCK
%12 = or i32 %10, %11
%13 = call i32 @open(i8* %7, i32 %12)
store i32 %13, i32* %6
%14 = load i32, i32* %6
%15 = icmp eq i32 %14, -1
br i1 %15, label %16, label %18
16: ; preds = %2
%17 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
br label %22
18: ; preds = %2
%19 = load i32, i32* %6
%20 = load i32, i32* @F_SETFL
%21 = call i32 @fcntl(i32 %19, i32 %20, i32 0)
br label %22
22: ; preds = %18, %16
%23 = load i32, i32* %6
%24 = call i32 @tcgetattr(i32 %23, %struct.termios* %5)
%25 = load i32, i32* %4
%26 = call i32 @cfsetispeed(%struct.termios* %5, i32 %25)
%27 = load i32, i32* %4
%28 = call i32 @cfsetospeed(%struct.termios* %5, i32 %27)
%29 = load i32, i32* @INPCK
%30 = xor i32 %29, -1
%31 = getelementptr inbounds %struct.termios, %struct.termios* %5, i32 0, i32 4
%32 = load i32, i32* %31
%33 = and i32 %32, %30
store i32 %33, i32* %31
%34 = load i32, i32* @IXON
%35 = xor i32 %34, -1
%36 = getelementptr inbounds %struct.termios, %struct.termios* %5, i32 0, i32 4
%37 = load i32, i32* %36
%38 = and i32 %37, %35
store i32 %38, i32* %36
%39 = load i32, i32* @IXOFF
%40 = xor i32 %39, -1
%41 = getelementptr inbounds %struct.termios, %struct.termios* %5, i32 0, i32 4
%42 = load i32, i32* %41
%43 = and i32 %42, %40
store i32 %43, i32* %41
%44 = load i32, i32* @IXANY
%45 = xor i32 %44, -1
%46 = getelementptr inbounds %struct.termios, %struct.termios* %5, i32 0, i32 4
%47 = load i32, i32* %46
%48 = and i32 %47, %45
store i32 %48, i32* %46
%49 = load i32, i32* @OPOST
%50 = getelementptr inbounds %struct.termios, %struct.termios* %5, i32 0, i32 3
%51 = load i32, i32* %50
%52 = or i32 %51, %49
store i32 %52, i32* %50
%53 = load i32, i32* @CLOCAL
%54 = getelementptr inbounds %struct.termios, %struct.termios* %5, i32 0, i32 2
%55 = load i32, i32* %54
%56 = or i32 %55, %53
store i32 %56, i32* %54
%57 = load i32, i32* @CREAD
%58 = getelementptr inbounds %struct.termios, %struct.termios* %5, i32 0, i32 2
%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* %5, i32 0, i32 2
%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* %5, i32 0, i32 2
%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* %5, i32 0, i32 2
%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* %5, i32 0, i32 2
%78 = load i32, i32* %77
%79 = or i32 %78, %76
store i32 %79, i32* %77
%80 = load i32, i32* @ICANON
%81 = xor i32 %80, -1
%82 = getelementptr inbounds %struct.termios, %struct.termios* %5, i32 0, i32 1
%83 = load i32, i32* %82
%84 = and i32 %83, %81
store i32 %84, i32* %82
%85 = load i32, i32* @ECHO
%86 = xor i32 %85, -1
%87 = getelementptr inbounds %struct.termios, %struct.termios* %5, i32 0, i32 1
%88 = load i32, i32* %87
%89 = and i32 %88, %86
store i32 %89, i32* %87
%90 = load i32, i32* @ECHOE
%91 = xor i32 %90, -1
%92 = getelementptr inbounds %struct.termios, %struct.termios* %5, i32 0, i32 1
%93 = load i32, i32* %92
%94 = and i32 %93, %91
store i32 %94, i32* %92
%95 = load i32, i32* @ISIG
%96 = xor i32 %95, -1
%97 = getelementptr inbounds %struct.termios, %struct.termios* %5, i32 0, i32 1
%98 = load i32, i32* %97
%99 = and i32 %98, %96
store i32 %99, i32* %97
%100 = getelementptr inbounds %struct.termios, %struct.termios* %5, i32 0, i32 0
%101 = load i64*, i64** %100
%102 = load i64, i64* @VMIN
%103 = getelementptr inbounds i64, i64* %101, i64 %102
store i64 0, i64* %103
%104 = getelementptr inbounds %struct.termios, %struct.termios* %5, i32 0, i32 0
%105 = load i64*, i64** %104
%106 = load i64, i64* @VTIME
%107 = getelementptr inbounds i64, i64* %105, i64 %106
store i64 0, i64* %107
%108 = load i32, i32* %6
%109 = load i32, i32* @TCSANOW
%110 = call i32 @tcsetattr(i32 %108, i32 %109, %struct.termios* %5)
%111 = load i32, i32* %6
ret i32 %111
}

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