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

/* Variables and functions */
int /*<<< orphan*/ B921600;
int CLOCAL;
int CREAD;
int CRTSCTS;
int CS8;
int CSIZE;
int CSTOPB;
int ECHO;
int ECHOE;
int ICANON;
int ISIG;
int IXANY;
int IXOFF;
int IXON;
int /*<<< orphan*/ OPOST;
int O_NOCTTY;
int O_RDWR;
int PARENB;
int /*<<< orphan*/ TCIFLUSH;
int /*<<< orphan*/ TCSANOW;
size_t VMIN;
size_t VTIME;
int /*<<< orphan*/ cfsetispeed(struct termios *, int /*<<< orphan*/);
int /*<<< orphan*/ cfsetospeed(struct termios *, int /*<<< orphan*/);
int open(char *, int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ tcflush(int, int /*<<< orphan*/);
int /*<<< orphan*/ tcgetattr(int, struct termios *);
scalar_t__ tcsetattr(int, int /*<<< orphan*/, struct termios *);
int initBNO080() {
  int fd;
  fd = open("/dev/ttyACM0", O_RDWR | O_NOCTTY);
  if (fd <= 0) {
    printf("Fail");
    return -1;
  } else
    printf("ttyACM0 Opened Successfully\n");
  struct termios SerialPortSettings;
  tcgetattr(fd, &SerialPortSettings);
  cfsetispeed(&SerialPortSettings, B921600);
  cfsetospeed(&SerialPortSettings, B921600);
  SerialPortSettings.c_cflag &= ~PARENB;
  SerialPortSettings.c_cflag &= ~CSTOPB;
  SerialPortSettings.c_cflag &= ~CSIZE;
  SerialPortSettings.c_cflag |= CS8;
  SerialPortSettings.c_cflag &= ~CRTSCTS;
  SerialPortSettings.c_cflag |= CREAD | CLOCAL;
  SerialPortSettings.c_iflag &= ~(IXON | IXOFF | IXANY);
  SerialPortSettings.c_iflag &= ~(ICANON | ECHO | ECHOE | ISIG);
  SerialPortSettings.c_oflag &= ~OPOST;
  SerialPortSettings.c_cc[VMIN] = 1;
  SerialPortSettings.c_cc[VTIME] = 1;
  if ((tcsetattr(fd, TCSANOW, &SerialPortSettings)) != 0) {
    printf("\n  ERROR ! in Setting attributes \n");
    return -1;
  } else
    printf("\n  BaudRate = 921600 \n  StopBits = 1 \n  Parity   = none \n");
  tcflush(fd, TCIFLUSH);
  return fd;
}


x86 assembly (clang, -O0):
<initBNO080>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    0x2e69(%rip),%rax
mov    (%rax),%esi
mov    0x2dd8(%rip),%rax
or     (%rax),%esi
lea    0xe6f(%rip),%rdi
call   1080 <open@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jg     11bb <initBNO080+0x4b>
lea    0xe63(%rip),%rdi
call   1050 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    134d <initBNO080+0x1dd>
lea    0xe50(%rip),%rdi
call   1050 <printf@plt>
mov    -0x8(%rbp),%edi
lea    -0x20(%rbp),%rsi
call   1060 <tcgetattr@plt>
mov    0x2dce(%rip),%rax
mov    (%rax),%esi
lea    -0x20(%rbp),%rdi
call   1090 <cfsetispeed@plt>
mov    0x2dbc(%rip),%rax
mov    (%rax),%esi
lea    -0x20(%rbp),%rdi
call   1030 <cfsetospeed@plt>
mov    0x2dca(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x20(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    0x2d28(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x20(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    0x2d5e(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x20(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    0x2d5c(%rip),%rax
mov    (%rax),%eax
or     -0x20(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    0x2cfd(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x20(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    0x2d43(%rip),%rax
mov    (%rax),%eax
mov    0x2cd2(%rip),%rcx
or     (%rcx),%eax
or     -0x20(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    0x2d63(%rip),%rax
mov    (%rax),%eax
mov    0x2d6a(%rip),%rcx
or     (%rcx),%eax
mov    0x2cf1(%rip),%rcx
or     (%rcx),%eax
xor    $0xffffffff,%eax
and    -0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    0x2cbf(%rip),%rax
mov    (%rax),%eax
mov    0x2d1e(%rip),%rcx
or     (%rcx),%eax
mov    0x2d0d(%rip),%rcx
or     (%rcx),%eax
mov    0x2cf4(%rip),%rcx
or     (%rcx),%eax
xor    $0xffffffff,%eax
and    -0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    0x2d1a(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x10(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x18(%rbp),%rax
mov    0x2cb4(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x1,(%rax,%rcx,4)
mov    -0x18(%rbp),%rax
mov    0x2c6f(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x1,(%rax,%rcx,4)
mov    -0x8(%rbp),%edi
mov    0x2cc3(%rip),%rax
mov    (%rax),%esi
lea    -0x20(%rbp),%rdx
call   1070 <tcsetattr@plt>
cmp    $0x0,%rax
je     132a <initBNO080+0x1ba>
lea    0xd16(%rip),%rdi
call   1050 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    134d <initBNO080+0x1dd>
lea    0xd21(%rip),%rdi
call   1050 <printf@plt>
mov    -0x8(%rbp),%edi
mov    0x2c28(%rip),%rax
mov    (%rax),%esi
call   1040 <tcflush@plt>
mov    -0x8(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<initBNO080>:
push   %r15
push   %r14
push   %rbx
sub    $0x20,%rsp
mov    0x2e58(%rip),%rax
mov    0x2dc9(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
lea    0xe5e(%rip),%rdi
call   1090 <open@plt>
test   %eax,%eax
jle    12de <initBNO080+0x15e>
mov    %eax,%ebx
lea    0xe5a(%rip),%rdi
call   1030 <puts@plt>
lea    0x8(%rsp),%r14
mov    %ebx,%edi
mov    %r14,%rsi
call   1070 <tcgetattr@plt>
mov    0x2dd5(%rip),%r15
mov    (%r15),%esi
mov    %r14,%rdi
call   10a0 <cfsetispeed@plt>
mov    (%r15),%esi
mov    %r14,%rdi
call   1040 <cfsetospeed@plt>
mov    0x2dd8(%rip),%rax
mov    (%rax),%eax
mov    0x2d3f(%rip),%rcx
or     (%rcx),%eax
mov    0x2d7e(%rip),%rcx
or     (%rcx),%eax
not    %eax
and    0x8(%rsp),%eax
mov    0x2d7f(%rip),%rcx
or     (%rcx),%eax
mov    0x2d26(%rip),%rcx
mov    (%rcx),%ecx
not    %ecx
and    %eax,%ecx
mov    0x2d71(%rip),%rax
or     (%rax),%ecx
mov    0x2d00(%rip),%rax
or     (%rax),%ecx
mov    0x2d97(%rip),%rax
mov    0x2da0(%rip),%rdx
mov    (%rdx),%edx
or     (%rax),%edx
mov    0x2d25(%rip),%rax
or     (%rax),%edx
mov    0x2cfc(%rip),%rax
mov    0x2d5d(%rip),%rsi
mov    (%rsi),%esi
or     (%rax),%esi
mov    %ecx,0x8(%rsp)
mov    0x2d46(%rip),%rax
or     (%rax),%esi
mov    0x2d2d(%rip),%rax
or     (%rax),%esi
or     %edx,%esi
not    %esi
and    %esi,0xc(%rsp)
mov    0x2d54(%rip),%rax
mov    (%rax),%eax
not    %eax
and    %eax,0x18(%rsp)
mov    0x10(%rsp),%rax
mov    0x2cf0(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x1,(%rax,%rcx,4)
mov    0x2caf(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x1,(%rax,%rcx,4)
mov    0x2d06(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edi
mov    %r14,%rdx
call   1080 <tcsetattr@plt>
test   %rax,%rax
je     12f1 <initBNO080+0x171>
lea    0xd95(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%ebx
jmp    130d <initBNO080+0x18d>
lea    0xd28(%rip),%rdi
call   1060 <printf@plt>
mov    $0xffffffff,%ebx
jmp    130d <initBNO080+0x18d>
lea    0xd36(%rip),%rdi
call   1030 <puts@plt>
mov    0x2c64(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edi
call   1050 <tcflush@plt>
mov    %ebx,%eax
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.termios = type { i32, i32, i32*, i32 }
@.str = [13 x i8] c"/dev/ttyACM0\00"
@O_RDWR = global i32 0
@O_NOCTTY = global i32 0
@.str.1 = [5 x i8] c"Fail\00"
@.str.2 = [29 x i8] c"ttyACM0 Opened Successfully\0A\00"
@B921600 = global i32 0
@PARENB = global i32 0
@CSTOPB = global i32 0
@CSIZE = global i32 0
@CS8 = global i32 0
@CRTSCTS = global i32 0
@CREAD = global i32 0
@CLOCAL = global i32 0
@IXON = global i32 0
@IXOFF = global i32 0
@IXANY = global i32 0
@ICANON = global i32 0
@ECHO = global i32 0
@ECHOE = global i32 0
@ISIG = global i32 0
@OPOST = global i32 0
@VMIN = global i64 0
@VTIME = global i64 0
@TCSANOW = global i32 0
@.str.3 = [35 x i8] c"\0A ERROR ! in Setting attributes \0A\00"
@.str.4 = [58 x i8] c"\0A BaudRate = 921600 \0A StopBits = 1 \0A Parity = none \0A\00"
@TCIFLUSH = global i32 0
define i32 @initBNO080() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca %struct.termios
%4 = load i32, i32* @O_RDWR
%5 = load i32, i32* @O_NOCTTY
%6 = or i32 %4, %5
%7 = call i32 @open(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %6)
store i32 %7, i32* %2
%8 = load i32, i32* %2
%9 = icmp sle i32 %8, 0
br i1 %9, label %10, label %12
10: ; preds = %0
%11 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %1
br label %97
12: ; preds = %0
%13 = call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0))
br label %14
14: ; preds = %12
%15 = load i32, i32* %2
%16 = call i32 @tcgetattr(i32 %15, %struct.termios* %3)
%17 = load i32, i32* @B921600
%18 = call i32 @cfsetispeed(%struct.termios* %3, i32 %17)
%19 = load i32, i32* @B921600
%20 = call i32 @cfsetospeed(%struct.termios* %3, i32 %19)
%21 = load i32, i32* @PARENB
%22 = xor i32 %21, -1
%23 = getelementptr inbounds %struct.termios, %struct.termios* %3, i32 0, i32 0
%24 = load i32, i32* %23
%25 = and i32 %24, %22
store i32 %25, i32* %23
%26 = load i32, i32* @CSTOPB
%27 = xor i32 %26, -1
%28 = getelementptr inbounds %struct.termios, %struct.termios* %3, i32 0, i32 0
%29 = load i32, i32* %28
%30 = and i32 %29, %27
store i32 %30, i32* %28
%31 = load i32, i32* @CSIZE
%32 = xor i32 %31, -1
%33 = getelementptr inbounds %struct.termios, %struct.termios* %3, i32 0, i32 0
%34 = load i32, i32* %33
%35 = and i32 %34, %32
store i32 %35, i32* %33
%36 = load i32, i32* @CS8
%37 = getelementptr inbounds %struct.termios, %struct.termios* %3, i32 0, i32 0
%38 = load i32, i32* %37
%39 = or i32 %38, %36
store i32 %39, i32* %37
%40 = load i32, i32* @CRTSCTS
%41 = xor i32 %40, -1
%42 = getelementptr inbounds %struct.termios, %struct.termios* %3, i32 0, i32 0
%43 = load i32, i32* %42
%44 = and i32 %43, %41
store i32 %44, i32* %42
%45 = load i32, i32* @CREAD
%46 = load i32, i32* @CLOCAL
%47 = or i32 %45, %46
%48 = getelementptr inbounds %struct.termios, %struct.termios* %3, i32 0, i32 0
%49 = load i32, i32* %48
%50 = or i32 %49, %47
store i32 %50, i32* %48
%51 = load i32, i32* @IXON
%52 = load i32, i32* @IXOFF
%53 = or i32 %51, %52
%54 = load i32, i32* @IXANY
%55 = or i32 %53, %54
%56 = xor i32 %55, -1
%57 = getelementptr inbounds %struct.termios, %struct.termios* %3, i32 0, i32 1
%58 = load i32, i32* %57
%59 = and i32 %58, %56
store i32 %59, i32* %57
%60 = load i32, i32* @ICANON
%61 = load i32, i32* @ECHO
%62 = or i32 %60, %61
%63 = load i32, i32* @ECHOE
%64 = or i32 %62, %63
%65 = load i32, i32* @ISIG
%66 = or i32 %64, %65
%67 = xor i32 %66, -1
%68 = getelementptr inbounds %struct.termios, %struct.termios* %3, i32 0, i32 1
%69 = load i32, i32* %68
%70 = and i32 %69, %67
store i32 %70, i32* %68
%71 = load i32, i32* @OPOST
%72 = xor i32 %71, -1
%73 = getelementptr inbounds %struct.termios, %struct.termios* %3, i32 0, i32 3
%74 = load i32, i32* %73
%75 = and i32 %74, %72
store i32 %75, i32* %73
%76 = getelementptr inbounds %struct.termios, %struct.termios* %3, i32 0, i32 2
%77 = load i32*, i32** %76
%78 = load i64, i64* @VMIN
%79 = getelementptr inbounds i32, i32* %77, i64 %78
store i32 1, i32* %79
%80 = getelementptr inbounds %struct.termios, %struct.termios* %3, i32 0, i32 2
%81 = load i32*, i32** %80
%82 = load i64, i64* @VTIME
%83 = getelementptr inbounds i32, i32* %81, i64 %82
store i32 1, i32* %83
%84 = load i32, i32* %2
%85 = load i32, i32* @TCSANOW
%86 = call i64 @tcsetattr(i32 %84, i32 %85, %struct.termios* %3)
%87 = icmp ne i64 %86, 0
br i1 %87, label %88, label %90
88: ; preds = %14
%89 = call i32 @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.3, i64 0, i64 0))
store i32 -1, i32* %1
br label %97
90: ; preds = %14
%91 = call i32 @printf(i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str.4, i64 0, i64 0))
br label %92
92: ; preds = %90
%93 = load i32, i32* %2
%94 = load i32, i32* @TCIFLUSH
%95 = call i32 @tcflush(i32 %93, i32 %94)
%96 = load i32, i32* %2
store i32 %96, i32* %1
br label %97
97: ; preds = %92, %88, %10
%98 = load i32, i32* %1
ret i32 %98
}

LLVM IR (-O2):
%struct.termios = type { i32, i32, i32*, i32 }
@.str = [13 x i8] c"/dev/ttyACM0\00"
@O_RDWR = global i32 0
@O_NOCTTY = global i32 0
@.str.1 = [5 x i8] c"Fail\00"
@B921600 = global i32 0
@PARENB = global i32 0
@CSTOPB = global i32 0
@CSIZE = global i32 0
@CS8 = global i32 0
@CRTSCTS = global i32 0
@CREAD = global i32 0
@CLOCAL = global i32 0
@IXON = global i32 0
@IXOFF = global i32 0
@IXANY = global i32 0
@ICANON = global i32 0
@ECHO = global i32 0
@ECHOE = global i32 0
@ISIG = global i32 0
@OPOST = global i32 0
@VMIN = global i64 0
@VTIME = global i64 0
@TCSANOW = global i32 0
@TCIFLUSH = global i32 0
@str = [28 x i8] c"ttyACM0 Opened Successfully\00"
@str.5 = [57 x i8] c"\0A BaudRate = 921600 \0A StopBits = 1 \0A Parity = none \00"
@str.6 = [34 x i8] c"\0A ERROR ! in Setting attributes \00"
define i32 @initBNO080() {
%1 = alloca %struct.termios
%2 = load i32, i32* @O_RDWR
%3 = load i32, i32* @O_NOCTTY
%4 = or i32 %3, %2
%5 = tail call i32 @open(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %4)
%6 = icmp slt i32 %5, 1
br i1 %6, label %7, label %9
7: ; preds = %0
%8 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
br label %74
9: ; preds = %0
%10 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @str, i64 0, i64 0))
%11 = bitcast %struct.termios* %1 to i8*
%12 = call i32 @tcgetattr(i32 %5, %struct.termios* %1)
%13 = load i32, i32* @B921600
%14 = call i32 @cfsetispeed(%struct.termios* %1, i32 %13)
%15 = load i32, i32* @B921600
%16 = call i32 @cfsetospeed(%struct.termios* %1, i32 %15)
%17 = load i32, i32* @PARENB
%18 = getelementptr inbounds %struct.termios, %struct.termios* %1, i64 0, i32 0
%19 = load i32, i32* %18
%20 = load i32, i32* @CSTOPB
%21 = or i32 %17, %20
%22 = load i32, i32* @CSIZE
%23 = or i32 %21, %22
%24 = xor i32 %23, -1
%25 = and i32 %19, %24
%26 = load i32, i32* @CS8
%27 = or i32 %26, %25
%28 = load i32, i32* @CRTSCTS
%29 = xor i32 %28, -1
%30 = and i32 %27, %29
%31 = load i32, i32* @CREAD
%32 = load i32, i32* @CLOCAL
%33 = or i32 %31, %30
%34 = or i32 %33, %32
store i32 %34, i32* %18
%35 = load i32, i32* @IXON
%36 = load i32, i32* @IXOFF
%37 = or i32 %36, %35
%38 = load i32, i32* @IXANY
%39 = or i32 %37, %38
%40 = getelementptr inbounds %struct.termios, %struct.termios* %1, i64 0, i32 1
%41 = load i32, i32* %40
%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 = load i32, i32* @ISIG
%48 = or i32 %46, %47
%49 = or i32 %39, %48
%50 = xor i32 %49, -1
%51 = and i32 %41, %50
store i32 %51, i32* %40
%52 = load i32, i32* @OPOST
%53 = xor i32 %52, -1
%54 = getelementptr inbounds %struct.termios, %struct.termios* %1, i64 0, i32 3
%55 = load i32, i32* %54
%56 = and i32 %55, %53
store i32 %56, i32* %54
%57 = getelementptr inbounds %struct.termios, %struct.termios* %1, i64 0, i32 2
%58 = load i32*, i32** %57
%59 = load i64, i64* @VMIN
%60 = getelementptr inbounds i32, i32* %58, i64 %59
store i32 1, i32* %60
%61 = load i64, i64* @VTIME
%62 = getelementptr inbounds i32, i32* %58, i64 %61
store i32 1, i32* %62
%63 = load i32, i32* @TCSANOW
%64 = call i64 @tcsetattr(i32 %5, i32 %63, %struct.termios* %1)
%65 = icmp eq i64 %64, 0
br i1 %65, label %68, label %66
66: ; preds = %9
%67 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @str.6, i64 0, i64 0))
br label %72
68: ; preds = %9
%69 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([57 x i8], [57 x i8]* @str.5, i64 0, i64 0))
%70 = load i32, i32* @TCIFLUSH
%71 = call i32 @tcflush(i32 %5, i32 %70)
br label %72
72: ; preds = %68, %66
%73 = phi i32 [ -1, %66 ], [ %5, %68 ]
br label %74
74: ; preds = %72, %7
%75 = phi i32 [ -1, %7 ], [ %73, %72 ]
ret i32 %75
}