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

/* Variables and functions */
int /*<<< orphan*/ B2400;
int CLOCAL;
int CREAD;
int CRTSCTS;
int CS7;
int CSIZE;
int CSTOPB;
int ECHO;
int ECHOE;
int /*<<< orphan*/ F_SETFL;
int ICANON;
int IGNPAR;
int IXANY;
int IXOFF;
int IXON;
int /*<<< orphan*/ OPOST;
int O_NDELAY;
int O_NOCTTY;
int O_RDONLY;
int PARENB;
int PARODD;
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*/ printf(char *, char *);
int /*<<< orphan*/ tcgetattr(int, struct termios *);
int /*<<< orphan*/ tcsetattr(int, int /*<<< orphan*/, struct termios *);
int open_port_ut804(char *device) {
  int fd;
  struct termios options;
  fd = open(device, O_RDONLY | O_NOCTTY | O_NDELAY);
  if (fd == -1) {
    printf("open_port_ut804: Unable to open %s\n", device);
    return (fd);
  } else {
    printf("open_port_ut804: Open %s\n", device);
    fcntl(fd, F_SETFL, 0);
  }
  tcgetattr(fd, &options);
  cfsetispeed(&options, B2400);
  cfsetospeed(&options, B2400);
  options.c_cflag |= (CLOCAL | CREAD);
  options.c_cflag |= PARENB;
  options.c_cflag |= PARODD;
  options.c_cflag &= ~CSTOPB;
  options.c_cflag &= ~CSIZE;
  options.c_cflag |= CS7;
  options.c_cflag &= ~CRTSCTS;
  options.c_lflag |= (ICANON | ECHO | ECHOE);
  options.c_iflag |= IGNPAR;
  options.c_iflag |= (IXON | IXOFF | IXANY);
  options.c_oflag &= ~OPOST;
  tcsetattr(fd, TCSANOW, &options);
  return (fd);
}


x86 assembly (clang, -O0):
<open_port_ut804>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2e59(%rip),%rax
mov    (%rax),%esi
mov    0x2df0(%rip),%rax
or     (%rax),%esi
mov    0x2dcf(%rip),%rax
or     (%rax),%esi
call   1080 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    11c8 <open_port_ut804+0x58>
mov    -0x10(%rbp),%rsi
lea    0xe48(%rip),%rdi
call   1050 <printf@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1314 <open_port_ut804+0x1a4>
mov    -0x10(%rbp),%rsi
lea    0xe51(%rip),%rdi
call   1050 <printf@plt>
mov    -0x14(%rbp),%edi
mov    0x2d8e(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1030 <fcntl@plt>
mov    -0x14(%rbp),%edi
lea    -0x28(%rbp),%rsi
call   1060 <tcgetattr@plt>
mov    0x2d7a(%rip),%rax
mov    (%rax),%esi
lea    -0x28(%rbp),%rdi
call   1090 <cfsetispeed@plt>
mov    0x2d68(%rip),%rax
mov    (%rax),%esi
lea    -0x28(%rbp),%rdi
call   1040 <cfsetospeed@plt>
mov    0x2d0e(%rip),%rax
mov    (%rax),%eax
mov    0x2d75(%rip),%rcx
or     (%rcx),%eax
or     -0x28(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    0x2d8e(%rip),%rax
mov    (%rax),%eax
or     -0x28(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    0x2d5f(%rip),%rax
mov    (%rax),%eax
or     -0x28(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    0x2ce8(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x28(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    0x2d2e(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x28(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    0x2cbc(%rip),%rax
mov    (%rax),%eax
or     -0x28(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    0x2cbd(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x28(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    0x2cbb(%rip),%rax
mov    (%rax),%eax
mov    0x2d12(%rip),%rcx
or     (%rcx),%eax
mov    0x2d01(%rip),%rcx
or     (%rcx),%eax
or     -0x24(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    0x2ca2(%rip),%rax
mov    (%rax),%eax
or     -0x20(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    0x2d03(%rip),%rax
mov    (%rax),%eax
mov    0x2d12(%rip),%rcx
or     (%rcx),%eax
mov    0x2ca9(%rip),%rcx
or     (%rcx),%eax
or     -0x20(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    0x2cea(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x14(%rbp),%edi
mov    0x2cbd(%rip),%rax
mov    (%rax),%esi
lea    -0x28(%rbp),%rdx
call   1070 <tcsetattr@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<open_port_ut804>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    0x2e61(%rip),%rax
mov    0x2dfa(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    %rdi,%rbx
mov    0x2dd4(%rip),%rax
or     (%rax),%esi
call   1080 <open@plt>
mov    %eax,%ebp
cmp    $0xffffffff,%eax
je     12b4 <open_port_ut804+0x144>
lea    0xe77(%rip),%rdi
mov    %rbx,%rsi
call   1050 <printf@plt>
mov    0x2db4(%rip),%rax
mov    (%rax),%esi
mov    %ebp,%edi
xor    %edx,%edx
call   1030 <fcntl@plt>
mov    %rsp,%r14
mov    %ebp,%edi
mov    %r14,%rsi
call   1060 <tcgetattr@plt>
mov    0x2d9d(%rip),%rbx
mov    (%rbx),%esi
mov    %r14,%rdi
call   1090 <cfsetispeed@plt>
mov    (%rbx),%esi
mov    %r14,%rdi
call   1040 <cfsetospeed@plt>
mov    0x2d3a(%rip),%rax
mov    0x2da3(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
or     (%rsp),%ecx
mov    0x2dbd(%rip),%rax
or     (%rax),%ecx
mov    0x2d94(%rip),%rax
or     (%rax),%ecx
mov    0x2d23(%rip),%rax
mov    (%rax),%eax
mov    0x2d72(%rip),%rdx
or     (%rdx),%eax
not    %eax
and    %ecx,%eax
mov    0x2d05(%rip),%rcx
or     (%rcx),%eax
mov    0x2d0c(%rip),%rcx
mov    (%rcx),%ecx
not    %ecx
and    %eax,%ecx
mov    0x2d0f(%rip),%rax
mov    0x2d68(%rip),%rdx
mov    (%rdx),%edx
or     (%rax),%edx
mov    %ecx,(%rsp)
mov    0x2d52(%rip),%rax
or     (%rax),%edx
or     %edx,0x4(%rsp)
mov    0x2cf5(%rip),%rax
mov    0x8(%rsp),%ecx
or     (%rax),%ecx
mov    0x2d58(%rip),%rax
mov    0x2d69(%rip),%rdx
mov    0x2d02(%rip),%rsi
or     (%rax),%ecx
or     (%rdx),%ecx
or     (%rsi),%ecx
mov    %ecx,0x8(%rsp)
mov    0x2d41(%rip),%rax
mov    (%rax),%eax
not    %eax
and    %eax,0xc(%rsp)
mov    0x2d1a(%rip),%rax
mov    (%rax),%esi
mov    %ebp,%edi
mov    %r14,%rdx
call   1070 <tcsetattr@plt>
jmp    12c3 <open_port_ut804+0x153>
lea    0xd45(%rip),%rdi
mov    %rbx,%rsi
call   1050 <printf@plt>
mov    %ebp,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.termios = type { i32, i32, i32, i32 }
@O_RDONLY = global i32 0
@O_NOCTTY = global i32 0
@O_NDELAY = global i32 0
@.str = [36 x i8] c"open_port_ut804: Unable to open %s\0A\00"
@.str.1 = [26 x i8] c"open_port_ut804: Open %s\0A\00"
@F_SETFL = global i32 0
@B2400 = global i32 0
@CLOCAL = global i32 0
@CREAD = global i32 0
@PARENB = global i32 0
@PARODD = global i32 0
@CSTOPB = global i32 0
@CSIZE = global i32 0
@CS7 = global i32 0
@CRTSCTS = global i32 0
@ICANON = global i32 0
@ECHO = global i32 0
@ECHOE = global i32 0
@IGNPAR = global i32 0
@IXON = global i32 0
@IXOFF = global i32 0
@IXANY = global i32 0
@OPOST = global i32 0
@TCSANOW = global i32 0
define i32 @open_port_ut804(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_RDONLY
%8 = load i32, i32* @O_NOCTTY
%9 = or i32 %7, %8
%10 = load i32, i32* @O_NDELAY
%11 = or i32 %9, %10
%12 = call i32 @open(i8* %6, i32 %11)
store i32 %12, i32* %4
%13 = load i32, i32* %4
%14 = icmp eq i32 %13, -1
br i1 %14, label %15, label %19
15: ; preds = %1
%16 = load i8*, i8** %3
%17 = call i32 @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0), i8* %16)
%18 = load i32, i32* %4
store i32 %18, i32* %2
br label %94
19: ; preds = %1
%20 = load i8*, i8** %3
%21 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i8* %20)
%22 = load i32, i32* %4
%23 = load i32, i32* @F_SETFL
%24 = call i32 @fcntl(i32 %22, i32 %23, i32 0)
br label %25
25: ; preds = %19
%26 = load i32, i32* %4
%27 = call i32 @tcgetattr(i32 %26, %struct.termios* %5)
%28 = load i32, i32* @B2400
%29 = call i32 @cfsetispeed(%struct.termios* %5, i32 %28)
%30 = load i32, i32* @B2400
%31 = call i32 @cfsetospeed(%struct.termios* %5, i32 %30)
%32 = load i32, i32* @CLOCAL
%33 = load i32, i32* @CREAD
%34 = or i32 %32, %33
%35 = getelementptr inbounds %struct.termios, %struct.termios* %5, i32 0, i32 0
%36 = load i32, i32* %35
%37 = or i32 %36, %34
store i32 %37, i32* %35
%38 = load i32, i32* @PARENB
%39 = getelementptr inbounds %struct.termios, %struct.termios* %5, i32 0, i32 0
%40 = load i32, i32* %39
%41 = or i32 %40, %38
store i32 %41, i32* %39
%42 = load i32, i32* @PARODD
%43 = getelementptr inbounds %struct.termios, %struct.termios* %5, i32 0, i32 0
%44 = load i32, i32* %43
%45 = or i32 %44, %42
store i32 %45, i32* %43
%46 = load i32, i32* @CSTOPB
%47 = xor i32 %46, -1
%48 = getelementptr inbounds %struct.termios, %struct.termios* %5, i32 0, i32 0
%49 = load i32, i32* %48
%50 = and i32 %49, %47
store i32 %50, i32* %48
%51 = load i32, i32* @CSIZE
%52 = xor i32 %51, -1
%53 = getelementptr inbounds %struct.termios, %struct.termios* %5, i32 0, i32 0
%54 = load i32, i32* %53
%55 = and i32 %54, %52
store i32 %55, i32* %53
%56 = load i32, i32* @CS7
%57 = getelementptr inbounds %struct.termios, %struct.termios* %5, i32 0, i32 0
%58 = load i32, i32* %57
%59 = or i32 %58, %56
store i32 %59, i32* %57
%60 = load i32, i32* @CRTSCTS
%61 = xor i32 %60, -1
%62 = getelementptr inbounds %struct.termios, %struct.termios* %5, i32 0, i32 0
%63 = load i32, i32* %62
%64 = and i32 %63, %61
store i32 %64, i32* %62
%65 = load i32, i32* @ICANON
%66 = load i32, i32* @ECHO
%67 = or i32 %65, %66
%68 = load i32, i32* @ECHOE
%69 = or i32 %67, %68
%70 = getelementptr inbounds %struct.termios, %struct.termios* %5, i32 0, i32 1
%71 = load i32, i32* %70
%72 = or i32 %71, %69
store i32 %72, i32* %70
%73 = load i32, i32* @IGNPAR
%74 = getelementptr inbounds %struct.termios, %struct.termios* %5, i32 0, i32 2
%75 = load i32, i32* %74
%76 = or i32 %75, %73
store i32 %76, i32* %74
%77 = load i32, i32* @IXON
%78 = load i32, i32* @IXOFF
%79 = or i32 %77, %78
%80 = load i32, i32* @IXANY
%81 = or i32 %79, %80
%82 = getelementptr inbounds %struct.termios, %struct.termios* %5, i32 0, i32 2
%83 = load i32, i32* %82
%84 = or i32 %83, %81
store i32 %84, i32* %82
%85 = load i32, i32* @OPOST
%86 = xor i32 %85, -1
%87 = getelementptr inbounds %struct.termios, %struct.termios* %5, i32 0, i32 3
%88 = load i32, i32* %87
%89 = and i32 %88, %86
store i32 %89, i32* %87
%90 = load i32, i32* %4
%91 = load i32, i32* @TCSANOW
%92 = call i32 @tcsetattr(i32 %90, i32 %91, %struct.termios* %5)
%93 = load i32, i32* %4
store i32 %93, i32* %2
br label %94
94: ; preds = %25, %15
%95 = load i32, i32* %2
ret i32 %95
}

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