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

/* Variables and functions */
int /*<<< orphan*/ B2400;
int CLOCAL;
int CREAD;
int CS8;
int CSIZE;
int CSTOPB;
int ECHO;
int ECHOE;
int /*<<< orphan*/ F_SETFL;
int ICANON;
int /*<<< orphan*/ ICRNL;
int /*<<< orphan*/ IGNBRK;
int /*<<< orphan*/ IGNCR;
int /*<<< orphan*/ INLCR;
int ISIG;
int /*<<< orphan*/ IXOFF;
int /*<<< orphan*/ IXON;
int O_NDELAY;
int O_NOCTTY;
int O_NONBLOCK;
int O_RDWR;
int PARENB;
int /*<<< orphan*/ TCSANOW;
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 *, int);
int /*<<< orphan*/ tcgetattr(int, struct termios *);
int /*<<< orphan*/ tcsetattr(int, int /*<<< orphan*/, struct termios *);
int openSmiPort(char *port) {
  int fd2;
  fd2 = open(port, O_RDWR | O_NOCTTY | O_NDELAY | O_NONBLOCK);
  if (fd2 == -1) {
    return (-1);
  } else {
    fcntl(fd2, F_SETFL, 0);
  }
  struct termios options2;
  tcgetattr(fd2, &options2);
  cfsetispeed(&options2, B2400);
  cfsetospeed(&options2, B2400);
  options2.c_cflag |= (CLOCAL | CREAD);
  options2.c_cflag &= ~CSIZE;
  options2.c_cflag |= CS8;
  options2.c_cflag &= ~PARENB;
  options2.c_cflag &= ~CSTOPB;
  options2.c_iflag &= ~IXON;
  options2.c_iflag &= ~IXOFF;
  options2.c_iflag &= ~IGNCR;
  options2.c_iflag &= ~ICRNL;
  options2.c_iflag &= ~INLCR;
  options2.c_iflag |= IGNBRK;
  options2.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG);
  tcsetattr(fd2, TCSANOW, &options2);
  return fd2;
}


x86 assembly (clang, -O0):
<openSmiPort>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2e71(%rip),%rax
mov    (%rax),%esi
mov    0x2de8(%rip),%rax
or     (%rax),%esi
mov    0x2dc7(%rip),%rax
or     (%rax),%esi
mov    0x2e36(%rip),%rax
or     (%rax),%esi
call   1070 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    11b2 <openSmiPort+0x52>
movl   $0xffffffff,-0x4(%rbp)
jmp    1303 <openSmiPort+0x1a3>
mov    -0x14(%rbp),%edi
mov    0x2d9c(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1030 <fcntl@plt>
mov    -0x14(%rbp),%edi
lea    -0x20(%rbp),%rsi
call   1050 <tcgetattr@plt>
mov    0x2d88(%rip),%rax
mov    (%rax),%esi
lea    -0x20(%rbp),%rdi
call   1080 <cfsetispeed@plt>
mov    0x2d76(%rip),%rax
mov    (%rax),%esi
lea    -0x20(%rbp),%rdi
call   1040 <cfsetospeed@plt>
mov    0x2d2c(%rip),%rax
mov    (%rax),%eax
mov    0x2d83(%rip),%rcx
or     (%rcx),%eax
or     -0x20(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    0x2d64(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x20(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    0x2d5a(%rip),%rax
mov    (%rax),%eax
or     -0x20(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    0x2d7b(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x20(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    0x2ce9(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x20(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    0x2d5f(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    0x2d65(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    0x2d43(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    0x2d51(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    0x2d37(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    0x2c95(%rip),%rax
mov    (%rax),%eax
or     -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    0x2c7e(%rip),%rax
mov    (%rax),%eax
mov    0x2cd5(%rip),%rcx
or     (%rcx),%eax
mov    0x2cc4(%rip),%rcx
or     (%rcx),%eax
mov    0x2cb3(%rip),%rcx
or     (%rcx),%eax
xor    $0xffffffff,%eax
and    -0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x14(%rbp),%edi
mov    0x2cb6(%rip),%rax
mov    (%rax),%esi
lea    -0x20(%rbp),%rdx
call   1060 <tcsetattr@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<openSmiPort>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    0x2e78(%rip),%rax
mov    0x2df1(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2dce(%rip),%rax
or     (%rax),%esi
mov    0x2e3d(%rip),%rax
or     (%rax),%esi
call   1070 <open@plt>
mov    %eax,%ebx
cmp    $0xffffffff,%eax
je     129a <openSmiPort+0x13a>
mov    0x2db4(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edi
xor    %edx,%edx
call   1030 <fcntl@plt>
mov    %rsp,%r14
mov    %ebx,%edi
mov    %r14,%rsi
call   1050 <tcgetattr@plt>
mov    0x2d9d(%rip),%r15
mov    (%r15),%esi
mov    %r14,%rdi
call   1080 <cfsetispeed@plt>
mov    (%r15),%esi
mov    %r14,%rdi
call   1040 <cfsetospeed@plt>
mov    0x2d48(%rip),%rax
mov    0x2da1(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
or     (%rsp),%ecx
mov    0x2d83(%rip),%rax
mov    (%rax),%eax
not    %eax
and    %ecx,%eax
mov    0x2d7e(%rip),%rcx
or     (%rcx),%eax
mov    0x2da5(%rip),%rcx
mov    (%rcx),%ecx
mov    0x2d1c(%rip),%rdx
or     (%rdx),%ecx
mov    0x2d9b(%rip),%rdx
mov    (%rdx),%edx
mov    0x2daa(%rip),%rsi
or     (%rsi),%edx
mov    0x2d91(%rip),%rsi
or     (%rsi),%edx
mov    0x2da8(%rip),%rsi
or     (%rsi),%edx
not    %ecx
and    %eax,%ecx
mov    0x2d93(%rip),%rax
or     (%rax),%edx
mov    %ecx,(%rsp)
not    %edx
and    0x8(%rsp),%edx
mov    0x2cf1(%rip),%rax
or     (%rax),%edx
mov    0x2ce0(%rip),%rax
mov    0x2d39(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
mov    0x2d26(%rip),%rax
or     (%rax),%ecx
mov    %edx,0x8(%rsp)
mov    0x2d11(%rip),%rax
or     (%rax),%ecx
not    %ecx
and    %ecx,0x4(%rsp)
mov    0x2d1a(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edi
mov    %r14,%rdx
call   1060 <tcsetattr@plt>
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
%struct.termios = type { i32, i32, i32 }
@O_RDWR = global i32 0
@O_NOCTTY = global i32 0
@O_NDELAY = global i32 0
@O_NONBLOCK = global i32 0
@F_SETFL = global i32 0
@B2400 = global i32 0
@CLOCAL = global i32 0
@CREAD = global i32 0
@CSIZE = global i32 0
@CS8 = global i32 0
@PARENB = global i32 0
@CSTOPB = global i32 0
@IXON = global i32 0
@IXOFF = global i32 0
@IGNCR = global i32 0
@ICRNL = global i32 0
@INLCR = global i32 0
@IGNBRK = global i32 0
@ICANON = global i32 0
@ECHO = global i32 0
@ECHOE = global i32 0
@ISIG = global i32 0
@TCSANOW = global i32 0
define i32 @openSmiPort(i8* nocapture %0) {
%2 = alloca %struct.termios
%3 = load i32, i32* @O_RDWR
%4 = load i32, i32* @O_NOCTTY
%5 = or i32 %4, %3
%6 = load i32, i32* @O_NDELAY
%7 = or i32 %5, %6
%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 %65, label %12
12: ; preds = %1
%13 = load i32, i32* @F_SETFL
%14 = tail call i32 @fcntl(i32 %10, i32 %13, i32 0)
%15 = bitcast %struct.termios* %2 to i8*
%16 = call i32 @tcgetattr(i32 %10, %struct.termios* %2)
%17 = load i32, i32* @B2400
%18 = call i32 @cfsetispeed(%struct.termios* %2, i32 %17)
%19 = load i32, i32* @B2400
%20 = call i32 @cfsetospeed(%struct.termios* %2, i32 %19)
%21 = load i32, i32* @CLOCAL
%22 = load i32, i32* @CREAD
%23 = or i32 %22, %21
%24 = getelementptr inbounds %struct.termios, %struct.termios* %2, i64 0, i32 0
%25 = load i32, i32* %24
%26 = or i32 %23, %25
%27 = load i32, i32* @CSIZE
%28 = xor i32 %27, -1
%29 = and i32 %26, %28
%30 = load i32, i32* @CS8
%31 = or i32 %30, %29
%32 = load i32, i32* @PARENB
%33 = load i32, i32* @CSTOPB
%34 = or i32 %32, %33
%35 = xor i32 %34, -1
%36 = and i32 %31, %35
store i32 %36, i32* %24
%37 = load i32, i32* @IXON
%38 = getelementptr inbounds %struct.termios, %struct.termios* %2, i64 0, i32 2
%39 = load i32, i32* %38
%40 = load i32, i32* @IXOFF
%41 = or i32 %37, %40
%42 = load i32, i32* @IGNCR
%43 = or i32 %41, %42
%44 = load i32, i32* @ICRNL
%45 = or i32 %43, %44
%46 = load i32, i32* @INLCR
%47 = or i32 %45, %46
%48 = xor i32 %47, -1
%49 = and i32 %39, %48
%50 = load i32, i32* @IGNBRK
%51 = or i32 %50, %49
store i32 %51, i32* %38
%52 = load i32, i32* @ICANON
%53 = load i32, i32* @ECHO
%54 = or i32 %53, %52
%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* %2, i64 0, i32 1
%61 = load i32, i32* %60
%62 = and i32 %61, %59
store i32 %62, i32* %60
%63 = load i32, i32* @TCSANOW
%64 = call i32 @tcsetattr(i32 %10, i32 %63, %struct.termios* %2)
br label %65
65: ; preds = %1, %12
ret i32 %10
}