#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 */
typedef int /*<<< orphan*/ t;
struct termios {
  int c_cflag;
};

/* Variables and functions */
int /*<<< orphan*/ B38400;
int CLOCAL;
int CREAD;
int O_NOCTTY;
int O_RDWR;
int /*<<< orphan*/ TCIFLUSH;
int /*<<< orphan*/ TCSANOW;
int /*<<< orphan*/ cfmakeraw(struct termios *);
int /*<<< orphan*/ cfsetspeed(struct termios *, int /*<<< orphan*/);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ memset(struct termios *, int /*<<< orphan*/, int);
int open(char const *, int);
int /*<<< orphan*/ tcflush(int, int /*<<< orphan*/);
int tcsetattr(int, int /*<<< orphan*/, struct termios *);
int epos_open(const char *path_to_dev) {
  int port;
  struct termios t;
  if ((port = open(path_to_dev, O_RDWR | O_NOCTTY)) == -1) {
    do {
    } while (0);
    return -1;
  }
  memset(&t, 0, sizeof(t));
  cfmakeraw(&t);
  t.c_cflag |= CLOCAL | CREAD;
  cfsetspeed(&t, B38400);
  tcflush(port, TCIFLUSH);
  if (tcsetattr(port, TCSANOW, &t) == -1) {
    do {
    } while (0);
    close(port);
    return -1;
  }
  return port;
}


x86 assembly (clang, -O0):
<epos_open>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2e61(%rip),%rax
mov    (%rax),%esi
mov    0x2e30(%rip),%rax
or     (%rax),%esi
call   1090 <open@plt>
mov    %eax,-0x14(%rbp)
cmp    $0xffffffff,%eax
jne    11b9 <epos_open+0x49>
jmp    11a8 <epos_open+0x38>
jmp    11ad <epos_open+0x3d>
movl   $0xffffffff,-0x4(%rbp)
jmp    124f <epos_open+0xdf>
lea    -0x18(%rbp),%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1040 <memset@plt>
lea    -0x18(%rbp),%rdi
call   1070 <cfmakeraw@plt>
mov    0x2dd7(%rip),%rax
mov    (%rax),%eax
mov    0x2df6(%rip),%rcx
or     (%rcx),%eax
or     -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    0x2db7(%rip),%rax
mov    (%rax),%esi
lea    -0x18(%rbp),%rdi
call   1050 <cfsetspeed@plt>
mov    -0x14(%rbp),%edi
mov    0x2dc2(%rip),%rax
mov    (%rax),%esi
call   1030 <tcflush@plt>
mov    -0x14(%rbp),%edi
mov    0x2dc9(%rip),%rax
mov    (%rax),%esi
lea    -0x18(%rbp),%rdx
call   1080 <tcsetattr@plt>
cmp    $0xffffffff,%eax
jne    1249 <epos_open+0xd9>
jmp    1230 <epos_open+0xc0>
jmp    1235 <epos_open+0xc5>
mov    -0x14(%rbp),%edi
call   1060 <close@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    124f <epos_open+0xdf>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<epos_open>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    0x2e69(%rip),%rax
mov    0x2e3a(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
call   1090 <open@plt>
mov    $0xffffffff,%ebx
cmp    $0xffffffff,%eax
je     1211 <epos_open+0xa1>
mov    %eax,%ebp
lea    0x8(%rsp),%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1040 <memset@plt>
mov    %r14,%rdi
call   1070 <cfmakeraw@plt>
mov    0x2df2(%rip),%rax
mov    0x2e13(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
or     %ecx,0x8(%rsp)
mov    0x2dd4(%rip),%rax
mov    (%rax),%esi
mov    %r14,%rdi
call   1050 <cfsetspeed@plt>
mov    0x2de3(%rip),%rax
mov    (%rax),%esi
mov    %ebp,%edi
call   1030 <tcflush@plt>
mov    0x2deb(%rip),%rax
mov    (%rax),%esi
mov    %ebp,%edi
mov    %r14,%rdx
call   1080 <tcsetattr@plt>
cmp    $0xffffffff,%eax
je     120a <epos_open+0x9a>
mov    %ebp,%ebx
jmp    1211 <epos_open+0xa1>
mov    %ebp,%edi
call   1060 <close@plt>
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.termios = type { i32 }
@O_RDWR = global i32 0
@O_NOCTTY = global i32 0
@CLOCAL = global i32 0
@CREAD = global i32 0
@B38400 = global i32 0
@TCIFLUSH = global i32 0
@TCSANOW = global i32 0
define i32 @epos_open(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 = call i32 @open(i8* %6, i32 %9)
store i32 %10, i32* %4
%11 = icmp eq i32 %10, -1
br i1 %11, label %12, label %15
12: ; preds = %1
br label %13
13: ; preds = %12
br label %14
14: ; preds = %13
store i32 -1, i32* %2
br label %40
15: ; preds = %1
%16 = call i32 @memset(%struct.termios* %5, i32 0, i32 4)
%17 = call i32 @cfmakeraw(%struct.termios* %5)
%18 = load i32, i32* @CLOCAL
%19 = load i32, i32* @CREAD
%20 = or i32 %18, %19
%21 = getelementptr inbounds %struct.termios, %struct.termios* %5, i32 0, i32 0
%22 = load i32, i32* %21
%23 = or i32 %22, %20
store i32 %23, i32* %21
%24 = load i32, i32* @B38400
%25 = call i32 @cfsetspeed(%struct.termios* %5, i32 %24)
%26 = load i32, i32* %4
%27 = load i32, i32* @TCIFLUSH
%28 = call i32 @tcflush(i32 %26, i32 %27)
%29 = load i32, i32* %4
%30 = load i32, i32* @TCSANOW
%31 = call i32 @tcsetattr(i32 %29, i32 %30, %struct.termios* %5)
%32 = icmp eq i32 %31, -1
br i1 %32, label %33, label %38
33: ; preds = %15
br label %34
34: ; preds = %33
br label %35
35: ; preds = %34
%36 = load i32, i32* %4
%37 = call i32 @close(i32 %36)
store i32 -1, i32* %2
br label %40
38: ; preds = %15
%39 = load i32, i32* %4
store i32 %39, i32* %2
br label %40
40: ; preds = %38, %35, %14
%41 = load i32, i32* %2
ret i32 %41
}

LLVM IR (-O2):
%struct.termios = type { i32 }
@O_RDWR = global i32 0
@O_NOCTTY = global i32 0
@CLOCAL = global i32 0
@CREAD = global i32 0
@B38400 = global i32 0
@TCIFLUSH = global i32 0
@TCSANOW = global i32 0
define i32 @epos_open(i8* nocapture %0) {
%2 = alloca %struct.termios
%3 = bitcast %struct.termios* %2 to i8*
%4 = load i32, i32* @O_RDWR
%5 = load i32, i32* @O_NOCTTY
%6 = or i32 %5, %4
%7 = tail call i32 @open(i8* %0, i32 %6)
%8 = icmp eq i32 %7, -1
br i1 %8, label %27, label %9
9: ; preds = %1
%10 = call i32 @memset(%struct.termios* %2, i32 0, i32 4)
%11 = call i32 @cfmakeraw(%struct.termios* %2)
%12 = load i32, i32* @CLOCAL
%13 = load i32, i32* @CREAD
%14 = or i32 %13, %12
%15 = getelementptr inbounds %struct.termios, %struct.termios* %2, i64 0, i32 0
%16 = load i32, i32* %15
%17 = or i32 %14, %16
store i32 %17, i32* %15
%18 = load i32, i32* @B38400
%19 = call i32 @cfsetspeed(%struct.termios* %2, i32 %18)
%20 = load i32, i32* @TCIFLUSH
%21 = call i32 @tcflush(i32 %7, i32 %20)
%22 = load i32, i32* @TCSANOW
%23 = call i32 @tcsetattr(i32 %7, i32 %22, %struct.termios* %2)
%24 = icmp eq i32 %23, -1
br i1 %24, label %25, label %27
25: ; preds = %9
%26 = call i32 @close(i32 %7)
br label %27
27: ; preds = %9, %1, %25
%28 = phi i32 [ -1, %25 ], [ -1, %1 ], [ %7, %9 ]
ret i32 %28
}