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

/* Variables and functions */
int /*<<< orphan*/ B115200;
int /*<<< orphan*/ CS8;
int /*<<< orphan*/ CSIZE;
int /*<<< orphan*/ CSTOPB;
int ECHO;
int ECHOE;
int ICANON;
int ISIG;
int /*<<< orphan*/ OPOST;
int O_NDELAY;
int O_NOCTTY;
int O_RDWR;
int /*<<< orphan*/ PARENB;
int /*<<< orphan*/ TCIFLUSH;
int /*<<< orphan*/ TCSANOW;
int /*<<< orphan*/ cfsetispeed(struct termios *, int /*<<< orphan*/);
int /*<<< orphan*/ cfsetospeed(struct termios *, int /*<<< orphan*/);
int open(char *, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ tcflush(int, int /*<<< orphan*/);
scalar_t__ tcgetattr(int, struct termios *);
scalar_t__ tcsetattr(int, int /*<<< orphan*/, struct termios *);
int Initial_SerialPort(char *serial_port) {
  int fd;
  struct termios options;
  fd = open(serial_port, O_RDWR | O_NOCTTY | O_NDELAY);
  if (fd == -1) {
    perror("Can't open serial port!");
    return -1;
  }
  tcgetattr(fd, &options);
  cfsetispeed(&options, B115200);
  cfsetospeed(&options, B115200);
  tcsetattr(fd, TCSANOW, &options);
  if (0 != tcgetattr(fd, &options)) {
    perror("SetupSerial 1");
    return -1;
  }
  options.c_cflag &= ~PARENB;
  options.c_cflag &= ~CSTOPB;
  options.c_cflag &= ~CSIZE;
  options.c_cflag |= CS8;
  tcflush(fd, TCIFLUSH);
  options.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG);
  options.c_oflag &= ~OPOST;
  if (0 != tcsetattr(fd, TCSANOW, &options)) {
    perror("SetupSerial error");
    return -1;
  }
  return fd;
}


x86 assembly (clang, -O0):
<Initial_SerialPort>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2e61(%rip),%rax
mov    (%rax),%esi
mov    0x2e00(%rip),%rax
or     (%rax),%esi
mov    0x2def(%rip),%rax
or     (%rax),%esi
call   1070 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    11c5 <Initial_SerialPort+0x55>
lea    0xe4c(%rip),%rdi
call   1090 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1312 <Initial_SerialPort+0x1a2>
mov    -0x14(%rbp),%edi
lea    -0x20(%rbp),%rsi
call   1050 <tcgetattr@plt>
mov    0x2da8(%rip),%rax
mov    (%rax),%esi
lea    -0x20(%rbp),%rdi
call   1080 <cfsetispeed@plt>
mov    0x2d96(%rip),%rax
mov    (%rax),%esi
lea    -0x20(%rbp),%rdi
call   1030 <cfsetospeed@plt>
mov    -0x14(%rbp),%edi
mov    0x2dd1(%rip),%rax
mov    (%rax),%esi
lea    -0x20(%rbp),%rdx
call   1060 <tcsetattr@plt>
mov    -0x14(%rbp),%edi
lea    -0x20(%rbp),%rsi
call   1050 <tcgetattr@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
je     123c <Initial_SerialPort+0xcc>
lea    0xded(%rip),%rdi
call   1090 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1312 <Initial_SerialPort+0x1a2>
mov    0x2d95(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    0x2d13(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    0x2d41(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    0x2d37(%rip),%rax
mov    (%rax),%eax
or     -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%edi
mov    0x2d0d(%rip),%rax
mov    (%rax),%esi
call   1040 <tcflush@plt>
mov    0x2cdf(%rip),%rax
mov    (%rax),%eax
mov    0x2d26(%rip),%rcx
or     (%rcx),%eax
mov    0x2d15(%rip),%rcx
or     (%rcx),%eax
mov    0x2d04(%rip),%rcx
or     (%rcx),%eax
xor    $0xffffffff,%eax
and    -0x20(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    0x2d1a(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x14(%rbp),%edi
mov    0x2cf5(%rip),%rax
mov    (%rax),%esi
lea    -0x20(%rbp),%rdx
call   1060 <tcsetattr@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
je     130c <Initial_SerialPort+0x19c>
lea    0xd2b(%rip),%rdi
call   1090 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1312 <Initial_SerialPort+0x1a2>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Initial_SerialPort>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    0x2e68(%rip),%rax
mov    0x2e09(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2df6(%rip),%rax
or     (%rax),%esi
call   1070 <open@plt>
cmp    $0xffffffff,%eax
je     1289 <Initial_SerialPort+0x119>
mov    %eax,%ebx
mov    %rsp,%r14
mov    %eax,%edi
mov    %r14,%rsi
call   1050 <tcgetattr@plt>
mov    0x2dc8(%rip),%r15
mov    (%r15),%esi
mov    %r14,%rdi
call   1080 <cfsetispeed@plt>
mov    (%r15),%esi
mov    %r14,%rdi
call   1030 <cfsetospeed@plt>
mov    0x2dfb(%rip),%r15
mov    (%r15),%esi
mov    %ebx,%edi
mov    %r14,%rdx
call   1060 <tcsetattr@plt>
mov    %ebx,%edi
mov    %r14,%rsi
call   1050 <tcgetattr@plt>
test   %rax,%rax
jne    1292 <Initial_SerialPort+0x122>
mov    0x2ddc(%rip),%rax
mov    (%rax),%eax
mov    0x2d63(%rip),%rcx
or     (%rcx),%eax
mov    0x2d9a(%rip),%rcx
or     (%rcx),%eax
not    %eax
and    0x8(%rsp),%eax
mov    0x2d93(%rip),%rcx
or     (%rcx),%eax
mov    %eax,0x8(%rsp)
mov    0x2d6e(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edi
call   1040 <tcflush@plt>
mov    0x2d3e(%rip),%rax
mov    0x2d87(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
mov    0x2d74(%rip),%rax
or     (%rax),%ecx
mov    0x2d63(%rip),%rax
or     (%rax),%ecx
not    %ecx
and    %ecx,(%rsp)
mov    0x2d7d(%rip),%rax
mov    (%rax),%eax
not    %eax
and    %eax,0x4(%rsp)
mov    (%r15),%esi
mov    %rsp,%rdx
mov    %ebx,%edi
call   1060 <tcsetattr@plt>
test   %rax,%rax
jne    129b <Initial_SerialPort+0x12b>
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
lea    0xd70(%rip),%rdi
jmp    12a2 <Initial_SerialPort+0x132>
lea    0xd7f(%rip),%rdi
jmp    12a2 <Initial_SerialPort+0x132>
lea    0xd84(%rip),%rdi
call   1090 <perror@plt>
mov    $0xffffffff,%ebx
jmp    127d <Initial_SerialPort+0x10d>

LLVM IR (-O0):
%struct.termios = type { i32, i32, i32 }
@O_RDWR = global i32 0
@O_NOCTTY = global i32 0
@O_NDELAY = global i32 0
@.str = [24 x i8] c"Can't open serial port!\00"
@B115200 = global i32 0
@TCSANOW = global i32 0
@.str.1 = [14 x i8] c"SetupSerial 1\00"
@PARENB = global i32 0
@CSTOPB = global i32 0
@CSIZE = global i32 0
@CS8 = global i32 0
@TCIFLUSH = global i32 0
@ICANON = global i32 0
@ECHO = global i32 0
@ECHOE = global i32 0
@ISIG = global i32 0
@OPOST = global i32 0
@.str.2 = [18 x i8] c"SetupSerial error\00"
define i32 @Initial_SerialPort(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 = 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 %17
15: ; preds = %1
%16 = call i32 @perror(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %2
br label %79
17: ; preds = %1
%18 = load i32, i32* %4
%19 = call i64 @tcgetattr(i32 %18, %struct.termios* %5)
%20 = load i32, i32* @B115200
%21 = call i32 @cfsetispeed(%struct.termios* %5, i32 %20)
%22 = load i32, i32* @B115200
%23 = call i32 @cfsetospeed(%struct.termios* %5, i32 %22)
%24 = load i32, i32* %4
%25 = load i32, i32* @TCSANOW
%26 = call i64 @tcsetattr(i32 %24, i32 %25, %struct.termios* %5)
%27 = load i32, i32* %4
%28 = call i64 @tcgetattr(i32 %27, %struct.termios* %5)
%29 = icmp ne i64 0, %28
br i1 %29, label %30, label %32
30: ; preds = %17
%31 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %2
br label %79
32: ; preds = %17
%33 = load i32, i32* @PARENB
%34 = xor i32 %33, -1
%35 = getelementptr inbounds %struct.termios, %struct.termios* %5, i32 0, i32 2
%36 = load i32, i32* %35
%37 = and i32 %36, %34
store i32 %37, i32* %35
%38 = load i32, i32* @CSTOPB
%39 = xor i32 %38, -1
%40 = getelementptr inbounds %struct.termios, %struct.termios* %5, i32 0, i32 2
%41 = load i32, i32* %40
%42 = and i32 %41, %39
store i32 %42, i32* %40
%43 = load i32, i32* @CSIZE
%44 = xor i32 %43, -1
%45 = getelementptr inbounds %struct.termios, %struct.termios* %5, i32 0, i32 2
%46 = load i32, i32* %45
%47 = and i32 %46, %44
store i32 %47, i32* %45
%48 = load i32, i32* @CS8
%49 = getelementptr inbounds %struct.termios, %struct.termios* %5, i32 0, i32 2
%50 = load i32, i32* %49
%51 = or i32 %50, %48
store i32 %51, i32* %49
%52 = load i32, i32* %4
%53 = load i32, i32* @TCIFLUSH
%54 = call i32 @tcflush(i32 %52, i32 %53)
%55 = load i32, i32* @ICANON
%56 = load i32, i32* @ECHO
%57 = or i32 %55, %56
%58 = load i32, i32* @ECHOE
%59 = or i32 %57, %58
%60 = load i32, i32* @ISIG
%61 = or i32 %59, %60
%62 = xor i32 %61, -1
%63 = getelementptr inbounds %struct.termios, %struct.termios* %5, i32 0, i32 0
%64 = load i32, i32* %63
%65 = and i32 %64, %62
store i32 %65, i32* %63
%66 = load i32, i32* @OPOST
%67 = xor i32 %66, -1
%68 = getelementptr inbounds %struct.termios, %struct.termios* %5, i32 0, i32 1
%69 = load i32, i32* %68
%70 = and i32 %69, %67
store i32 %70, i32* %68
%71 = load i32, i32* %4
%72 = load i32, i32* @TCSANOW
%73 = call i64 @tcsetattr(i32 %71, i32 %72, %struct.termios* %5)
%74 = icmp ne i64 0, %73
br i1 %74, label %75, label %77
75: ; preds = %32
%76 = call i32 @perror(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %2
br label %79
77: ; preds = %32
%78 = load i32, i32* %4
store i32 %78, i32* %2
br label %79
79: ; preds = %77, %75, %30, %15
%80 = load i32, i32* %2
ret i32 %80
}

LLVM IR (-O2):
%struct.termios = type { i32, i32, i32 }
@O_RDWR = global i32 0
@O_NOCTTY = global i32 0
@O_NDELAY = global i32 0
@.str = [24 x i8] c"Can't open serial port!\00"
@B115200 = global i32 0
@TCSANOW = global i32 0
@.str.1 = [14 x i8] c"SetupSerial 1\00"
@PARENB = global i32 0
@CSTOPB = global i32 0
@CSIZE = global i32 0
@CS8 = global i32 0
@TCIFLUSH = global i32 0
@ICANON = global i32 0
@ECHO = global i32 0
@ECHOE = global i32 0
@ISIG = global i32 0
@OPOST = global i32 0
@.str.2 = [18 x i8] c"SetupSerial error\00"
define i32 @Initial_SerialPort(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 = 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 @perror(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
br label %60
13: ; preds = %1
%14 = call i64 @tcgetattr(i32 %9, %struct.termios* %2)
%15 = load i32, i32* @B115200
%16 = call i32 @cfsetispeed(%struct.termios* %2, i32 %15)
%17 = load i32, i32* @B115200
%18 = call i32 @cfsetospeed(%struct.termios* %2, i32 %17)
%19 = load i32, i32* @TCSANOW
%20 = call i64 @tcsetattr(i32 %9, i32 %19, %struct.termios* %2)
%21 = call i64 @tcgetattr(i32 %9, %struct.termios* %2)
%22 = icmp eq i64 %21, 0
br i1 %22, label %25, label %23
23: ; preds = %13
%24 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
br label %60
25: ; preds = %13
%26 = load i32, i32* @PARENB
%27 = getelementptr inbounds %struct.termios, %struct.termios* %2, i64 0, i32 2
%28 = load i32, i32* %27
%29 = load i32, i32* @CSTOPB
%30 = or i32 %26, %29
%31 = load i32, i32* @CSIZE
%32 = or i32 %30, %31
%33 = xor i32 %32, -1
%34 = and i32 %28, %33
%35 = load i32, i32* @CS8
%36 = or i32 %35, %34
store i32 %36, i32* %27
%37 = load i32, i32* @TCIFLUSH
%38 = call i32 @tcflush(i32 %9, i32 %37)
%39 = load i32, i32* @ICANON
%40 = load i32, i32* @ECHO
%41 = or i32 %40, %39
%42 = load i32, i32* @ECHOE
%43 = or i32 %41, %42
%44 = load i32, i32* @ISIG
%45 = or i32 %43, %44
%46 = xor i32 %45, -1
%47 = getelementptr inbounds %struct.termios, %struct.termios* %2, i64 0, i32 0
%48 = load i32, i32* %47
%49 = and i32 %48, %46
store i32 %49, i32* %47
%50 = load i32, i32* @OPOST
%51 = xor i32 %50, -1
%52 = getelementptr inbounds %struct.termios, %struct.termios* %2, i64 0, i32 1
%53 = load i32, i32* %52
%54 = and i32 %53, %51
store i32 %54, i32* %52
%55 = load i32, i32* @TCSANOW
%56 = call i64 @tcsetattr(i32 %9, i32 %55, %struct.termios* %2)
%57 = icmp eq i64 %56, 0
br i1 %57, label %60, label %58
58: ; preds = %25
%59 = call i32 @perror(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0))
br label %60
60: ; preds = %25, %58, %23, %11
%61 = phi i32 [ -1, %11 ], [ -1, %23 ], [ -1, %58 ], [ %9, %25 ]
ret i32 %61
}