#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_cc;
  scalar_t__ c_lflag;
  scalar_t__ c_oflag;
};
struct pollfd {
  int dummy;
};
typedef int /*<<< orphan*/ newtio;

/* Variables and functions */
int B115200;
int CLOCAL;
int CREAD;
int CS8;
int /*<<< orphan*/ FNDELAY;
int /*<<< orphan*/ F_SETFL;
int O_NOCTTY;
int O_NONBLOCK;
int O_RDWR;
int O_WRONLY;
int S_IWRITE;
int /*<<< orphan*/ TCIFLUSH;
int /*<<< orphan*/ TCSANOW;
size_t VMIN;
size_t VTIME;
int /*<<< orphan*/ fcntl(int, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ memset(struct termios *, int /*<<< orphan*/, int);
int open(char *, int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ tcflush(int, int /*<<< orphan*/);
int /*<<< orphan*/ tcsetattr(int, int /*<<< orphan*/, struct termios *);
int /*<<< orphan*/ write(int, char *, int);
int main(void) {
  int fd;
  int fd1 = open("/sys/devices/bone_capemgr.9/slots", O_WRONLY | S_IWRITE);
  ;
  int ndx;
  int cnt;
  char buf[1024];
  struct termios newtio;
  struct pollfd poll_events;
  int poll_state;
  if (0 > fd1) {
    printf("Capemgr error error\n");
    return -1;
  }
  write(fd1, "cape-universaln", 16);
  printf("can use cape-universaln \n");
  fd = open("/dev/ttyO2", O_RDWR | O_NOCTTY | O_NONBLOCK);
  if (0 > fd) {
    printf("open error\n");
    return -1;
  }
  memset(&newtio, 0, sizeof(newtio));
  newtio.c_cflag = B115200 | CS8 | CLOCAL | CREAD;
  newtio.c_oflag = 0;
  newtio.c_lflag = 0;
  newtio.c_cc[VTIME] = 0;
  newtio.c_cc[VMIN] = 1;
  tcflush(fd, TCIFLUSH);
  tcsetattr(fd, TCSANOW, &newtio);
  fcntl(fd, F_SETFL, FNDELAY);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x450,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2de7(%rip),%rax
mov    (%rax),%esi
mov    0x2e3e(%rip),%rax
or     (%rax),%esi
lea    0xe65(%rip),%rdi
call   1090 <open@plt>
mov    %eax,-0xc(%rbp)
xor    %eax,%eax
cmp    -0xc(%rbp),%eax
jle    11c6 <main+0x56>
lea    0xe6d(%rip),%rdi
call   1060 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12f9 <main+0x189>
mov    -0xc(%rbp),%edi
lea    0xe67(%rip),%rsi
mov    $0x10,%edx
call   1040 <write@plt>
lea    0xe66(%rip),%rdi
call   1060 <printf@plt>
mov    0x2dfb(%rip),%rax
mov    (%rax),%esi
mov    0x2daa(%rip),%rax
or     (%rax),%esi
mov    0x2de1(%rip),%rax
or     (%rax),%esi
lea    0xe59(%rip),%rdi
call   1090 <open@plt>
mov    %eax,-0x8(%rbp)
xor    %eax,%eax
cmp    -0x8(%rbp),%eax
jle    1233 <main+0xc3>
lea    0xe4a(%rip),%rdi
call   1060 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12f9 <main+0x189>
lea    -0x440(%rbp),%rdi
xor    %esi,%esi
mov    $0x20,%edx
call   1070 <memset@plt>
mov    0x2d3b(%rip),%rax
mov    (%rax),%eax
mov    0x2d6a(%rip),%rcx
or     (%rcx),%eax
mov    0x2d09(%rip),%rcx
or     (%rcx),%eax
mov    0x2d60(%rip),%rcx
or     (%rcx),%eax
mov    %eax,-0x440(%rbp)
movq   $0x0,-0x428(%rbp)
movq   $0x0,-0x430(%rbp)
mov    -0x438(%rbp),%rax
mov    0x2cec(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x0,(%rax,%rcx,4)
mov    -0x438(%rbp),%rax
mov    0x2d0c(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x1,(%rax,%rcx,4)
mov    -0x8(%rbp),%edi
mov    0x2ce8(%rip),%rax
mov    (%rax),%esi
call   1050 <tcflush@plt>
mov    -0x8(%rbp),%edi
mov    0x2d07(%rip),%rax
mov    (%rax),%esi
lea    -0x440(%rbp),%rdx
call   1080 <tcsetattr@plt>
mov    -0x8(%rbp),%edi
mov    0x2caf(%rip),%rax
mov    (%rax),%esi
mov    0x2c9e(%rip),%rax
mov    (%rax),%edx
call   1030 <fcntl@plt>
mov    -0x4(%rbp),%eax
add    $0x450,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x20,%rsp
mov    0x2df1(%rip),%rax
mov    0x2e4a(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
lea    0xe6f(%rip),%rdi
call   1090 <open@plt>
test   %eax,%eax
js     1296 <main+0x126>
lea    0xe7d(%rip),%rsi
mov    %eax,%edi
mov    $0x10,%edx
call   1050 <write@plt>
lea    0xe85(%rip),%rdi
call   1030 <puts@plt>
mov    0x2e24(%rip),%rax
mov    0x2dd5(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2e0a(%rip),%rax
or     (%rax),%esi
lea    0xe53(%rip),%rdi
call   1090 <open@plt>
test   %eax,%eax
js     129f <main+0x12f>
mov    %eax,%ebp
mov    %rsp,%r14
xor    %ebx,%ebx
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x20,%edx
call   1070 <memset@plt>
mov    0x2d7f(%rip),%rax
mov    0x2db0(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
mov    0x2d4d(%rip),%rax
or     (%rax),%ecx
mov    0x2da4(%rip),%rax
or     (%rax),%ecx
mov    %ecx,(%rsp)
xorps  %xmm0,%xmm0
movups %xmm0,0x10(%rsp)
mov    0x8(%rsp),%rax
mov    0x2d43(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x0,(%rax,%rcx,4)
mov    0x2d6a(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x1,(%rax,%rcx,4)
mov    0x2d49(%rip),%rax
mov    (%rax),%esi
mov    %ebp,%edi
call   1060 <tcflush@plt>
mov    0x2d69(%rip),%rax
mov    (%rax),%esi
mov    %ebp,%edi
mov    %r14,%rdx
call   1080 <tcsetattr@plt>
mov    0x2d16(%rip),%rax
mov    (%rax),%esi
mov    0x2d05(%rip),%rax
mov    (%rax),%edx
mov    %ebp,%edi
call   1040 <fcntl@plt>
jmp    12b0 <main+0x140>
lea    0xdc4(%rip),%rdi
jmp    12a6 <main+0x136>
lea    0xdb0(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.termios = type { i32, i32*, i64, i64 }
%struct.pollfd = type { i32 }
@.str = [34 x i8] c"/sys/devices/bone_capemgr.9/slots\00"
@O_WRONLY = global i32 0
@S_IWRITE = global i32 0
@.str.1 = [21 x i8] c"Capemgr error error\0A\00"
@.str.2 = [16 x i8] c"cape-universaln\00"
@.str.3 = [26 x i8] c"can use cape-universaln \0A\00"
@.str.4 = [11 x i8] c"/dev/ttyO2\00"
@O_RDWR = global i32 0
@O_NOCTTY = global i32 0
@O_NONBLOCK = global i32 0
@.str.5 = [12 x i8] c"open error\0A\00"
@B115200 = global i32 0
@CS8 = global i32 0
@CLOCAL = global i32 0
@CREAD = global i32 0
@VTIME = global i64 0
@VMIN = global i64 0
@TCIFLUSH = global i32 0
@TCSANOW = global i32 0
@F_SETFL = global i32 0
@FNDELAY = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca [1024 x i8]
%7 = alloca %struct.termios
%8 = alloca %struct.pollfd
%9 = alloca i32
store i32 0, i32* %1
%10 = load i32, i32* @O_WRONLY
%11 = load i32, i32* @S_IWRITE
%12 = or i32 %10, %11
%13 = call i32 @open(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i32 %12)
store i32 %13, i32* %3
%14 = load i32, i32* %3
%15 = icmp sgt i32 0, %14
br i1 %15, label %16, label %18
16: ; preds = %0
%17 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %1
br label %62
18: ; preds = %0
%19 = load i32, i32* %3
%20 = call i32 @write(i32 %19, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i32 16)
%21 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0))
%22 = load i32, i32* @O_RDWR
%23 = load i32, i32* @O_NOCTTY
%24 = or i32 %22, %23
%25 = load i32, i32* @O_NONBLOCK
%26 = or i32 %24, %25
%27 = call i32 @open(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0), i32 %26)
store i32 %27, i32* %2
%28 = load i32, i32* %2
%29 = icmp sgt i32 0, %28
br i1 %29, label %30, label %32
30: ; preds = %18
%31 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.5, i64 0, i64 0))
store i32 -1, i32* %1
br label %62
32: ; preds = %18
%33 = call i32 @memset(%struct.termios* %7, i32 0, i32 32)
%34 = load i32, i32* @B115200
%35 = load i32, i32* @CS8
%36 = or i32 %34, %35
%37 = load i32, i32* @CLOCAL
%38 = or i32 %36, %37
%39 = load i32, i32* @CREAD
%40 = or i32 %38, %39
%41 = getelementptr inbounds %struct.termios, %struct.termios* %7, i32 0, i32 0
store i32 %40, i32* %41
%42 = getelementptr inbounds %struct.termios, %struct.termios* %7, i32 0, i32 3
store i64 0, i64* %42
%43 = getelementptr inbounds %struct.termios, %struct.termios* %7, i32 0, i32 2
store i64 0, i64* %43
%44 = getelementptr inbounds %struct.termios, %struct.termios* %7, i32 0, i32 1
%45 = load i32*, i32** %44
%46 = load i64, i64* @VTIME
%47 = getelementptr inbounds i32, i32* %45, i64 %46
store i32 0, i32* %47
%48 = getelementptr inbounds %struct.termios, %struct.termios* %7, i32 0, i32 1
%49 = load i32*, i32** %48
%50 = load i64, i64* @VMIN
%51 = getelementptr inbounds i32, i32* %49, i64 %50
store i32 1, i32* %51
%52 = load i32, i32* %2
%53 = load i32, i32* @TCIFLUSH
%54 = call i32 @tcflush(i32 %52, i32 %53)
%55 = load i32, i32* %2
%56 = load i32, i32* @TCSANOW
%57 = call i32 @tcsetattr(i32 %55, i32 %56, %struct.termios* %7)
%58 = load i32, i32* %2
%59 = load i32, i32* @F_SETFL
%60 = load i32, i32* @FNDELAY
%61 = call i32 @fcntl(i32 %58, i32 %59, i32 %60)
br label %62
62: ; preds = %32, %30, %16
%63 = load i32, i32* %1
ret i32 %63
}

LLVM IR (-O2):
%struct.termios = type { i32, i32*, i64, i64 }
@.str = [34 x i8] c"/sys/devices/bone_capemgr.9/slots\00"
@O_WRONLY = global i32 0
@S_IWRITE = global i32 0
@.str.2 = [16 x i8] c"cape-universaln\00"
@.str.4 = [11 x i8] c"/dev/ttyO2\00"
@O_RDWR = global i32 0
@O_NOCTTY = global i32 0
@O_NONBLOCK = global i32 0
@B115200 = global i32 0
@CS8 = global i32 0
@CLOCAL = global i32 0
@CREAD = global i32 0
@VTIME = global i64 0
@VMIN = global i64 0
@TCIFLUSH = global i32 0
@TCSANOW = global i32 0
@F_SETFL = global i32 0
@FNDELAY = global i32 0
@str = [25 x i8] c"can use cape-universaln \00"
@str.6 = [11 x i8] c"open error\00"
@str.7 = [20 x i8] c"Capemgr error error\00"
define i32 @main() {
%1 = alloca %struct.termios
%2 = load i32, i32* @O_WRONLY
%3 = load i32, i32* @S_IWRITE
%4 = or i32 %3, %2
%5 = tail call i32 @open(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i32 %4)
%6 = bitcast %struct.termios* %1 to i8*
%7 = icmp slt i32 %5, 0
br i1 %7, label %8, label %10
8: ; preds = %0
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str.7, i64 0, i64 0))
br label %47
10: ; preds = %0
%11 = tail call i32 @write(i32 %5, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i32 16)
%12 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str, i64 0, i64 0))
%13 = load i32, i32* @O_RDWR
%14 = load i32, i32* @O_NOCTTY
%15 = or i32 %14, %13
%16 = load i32, i32* @O_NONBLOCK
%17 = or i32 %15, %16
%18 = tail call i32 @open(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0), i32 %17)
%19 = icmp slt i32 %18, 0
br i1 %19, label %20, label %22
20: ; preds = %10
%21 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @str.6, i64 0, i64 0))
br label %47
22: ; preds = %10
%23 = call i32 @memset(%struct.termios* %1, i32 0, i32 32)
%24 = load i32, i32* @B115200
%25 = load i32, i32* @CS8
%26 = or i32 %25, %24
%27 = load i32, i32* @CLOCAL
%28 = or i32 %26, %27
%29 = load i32, i32* @CREAD
%30 = or i32 %28, %29
%31 = getelementptr inbounds %struct.termios, %struct.termios* %1, i64 0, i32 0
store i32 %30, i32* %31
%32 = getelementptr inbounds %struct.termios, %struct.termios* %1, i64 0, i32 2
%33 = getelementptr inbounds %struct.termios, %struct.termios* %1, i64 0, i32 1
%34 = bitcast i64* %32 to i8*
%35 = load i32*, i32** %33
%36 = load i64, i64* @VTIME
%37 = getelementptr inbounds i32, i32* %35, i64 %36
store i32 0, i32* %37
%38 = load i64, i64* @VMIN
%39 = getelementptr inbounds i32, i32* %35, i64 %38
store i32 1, i32* %39
%40 = load i32, i32* @TCIFLUSH
%41 = call i32 @tcflush(i32 %18, i32 %40)
%42 = load i32, i32* @TCSANOW
%43 = call i32 @tcsetattr(i32 %18, i32 %42, %struct.termios* %1)
%44 = load i32, i32* @F_SETFL
%45 = load i32, i32* @FNDELAY
%46 = call i32 @fcntl(i32 %18, i32 %44, i32 %45)
br label %47
47: ; preds = %22, %20, %8
%48 = phi i32 [ -1, %8 ], [ -1, %20 ], [ 0, %22 ]
ret i32 %48
}