#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;
};

/* Variables and functions */
int /*<<< orphan*/ B115200;
int CLOCAL;
int CREAD;
int CS8;
int CSIZE;
int CSTOPB;
int O_NDELAY;
int O_NOCTTY;
int O_RDONLY;
int PARENB;
int /*<<< orphan*/ TCSANOW;
int /*<<< orphan*/ cfsetspeed(struct termios *, int /*<<< orphan*/);
int open(char *, int);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ tcsetattr(int, int /*<<< orphan*/, struct termios *);
int serial_open(char *portname) {
  int FD_com;
  struct termios term;
  FD_com = open(portname, O_RDONLY | O_NOCTTY | O_NDELAY);
  if (FD_com == -1) {
    printf("serial_open: Unable to open %s.\n", portname);
  } else {
    cfsetspeed(&term, B115200);
    term.c_cflag &= ~PARENB;
    term.c_cflag &= ~CSTOPB;
    term.c_cflag &= ~CSIZE;
    term.c_cflag |= CS8;
    term.c_cflag |= (CLOCAL | CREAD);
    tcsetattr(FD_com, TCSANOW, &term);
  }
  return (FD_com);
}


x86 assembly (clang, -O0):
<serial_open>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
mov    0x2e91(%rip),%rax
mov    (%rax),%esi
mov    0x2e50(%rip),%rax
or     (%rax),%esi
mov    0x2e3f(%rip),%rax
or     (%rax),%esi
call   1060 <open@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0xffffffff,-0xc(%rbp)
jne    1192 <serial_open+0x52>
mov    -0x8(%rbp),%rsi
lea    0xe78(%rip),%rdi
call   1030 <printf@plt>
jmp    1216 <serial_open+0xd6>
mov    0x2e07(%rip),%rax
mov    (%rax),%esi
lea    -0x10(%rbp),%rdi
call   1040 <cfsetspeed@plt>
mov    0x2e35(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x10(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    0x2dd3(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x10(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    0x2df1(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x10(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    0x2de7(%rip),%rax
mov    (%rax),%eax
or     -0x10(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    0x2d98(%rip),%rax
mov    (%rax),%eax
mov    0x2dd7(%rip),%rcx
or     (%rcx),%eax
or     -0x10(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0xc(%rbp),%edi
mov    0x2dcd(%rip),%rax
mov    (%rax),%esi
lea    -0x10(%rbp),%rdx
call   1050 <tcsetattr@plt>
mov    -0xc(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<serial_open>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    0x2e99(%rip),%rax
mov    0x2e5a(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    %rdi,%rbx
mov    0x2e44(%rip),%rax
or     (%rax),%esi
call   1060 <open@plt>
mov    %eax,%ebp
cmp    $0xffffffff,%eax
je     11dd <serial_open+0x9d>
mov    0x2e27(%rip),%rax
mov    (%rax),%esi
lea    0x8(%rsp),%r14
mov    %r14,%rdi
call   1040 <cfsetspeed@plt>
mov    0x2e51(%rip),%rax
mov    (%rax),%eax
mov    0x2df8(%rip),%rcx
or     (%rcx),%eax
mov    0x2e1f(%rip),%rcx
or     (%rcx),%eax
not    %eax
and    0x8(%rsp),%eax
mov    0x2e18(%rip),%rcx
or     (%rcx),%eax
mov    0x2dcf(%rip),%rcx
mov    0x2e10(%rip),%rdx
or     (%rcx),%eax
or     (%rdx),%eax
mov    %eax,0x8(%rsp)
mov    0x2e09(%rip),%rax
mov    (%rax),%esi
mov    %ebp,%edi
mov    %r14,%rdx
call   1050 <tcsetattr@plt>
jmp    11ec <serial_open+0xac>
lea    0xe1c(%rip),%rdi
mov    %rbx,%rsi
call   1030 <printf@plt>
mov    %ebp,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.termios = type { i32 }
@O_RDONLY = global i32 0
@O_NOCTTY = global i32 0
@O_NDELAY = global i32 0
@.str = [33 x i8] c"serial_open: Unable to open %s.\0A\00"
@B115200 = global i32 0
@PARENB = global i32 0
@CSTOPB = global i32 0
@CSIZE = global i32 0
@CS8 = global i32 0
@CLOCAL = global i32 0
@CREAD = global i32 0
@TCSANOW = global i32 0
define i32 @serial_open(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca %struct.termios
store i8* %0, i8** %2
%5 = load i8*, i8** %2
%6 = load i32, i32* @O_RDONLY
%7 = load i32, i32* @O_NOCTTY
%8 = or i32 %6, %7
%9 = load i32, i32* @O_NDELAY
%10 = or i32 %8, %9
%11 = call i32 @open(i8* %5, i32 %10)
store i32 %11, i32* %3
%12 = load i32, i32* %3
%13 = icmp eq i32 %12, -1
br i1 %13, label %14, label %17
14: ; preds = %1
%15 = load i8*, i8** %2
%16 = call i32 @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0), i8* %15)
br label %48
17: ; preds = %1
%18 = load i32, i32* @B115200
%19 = call i32 @cfsetspeed(%struct.termios* %4, i32 %18)
%20 = load i32, i32* @PARENB
%21 = xor i32 %20, -1
%22 = getelementptr inbounds %struct.termios, %struct.termios* %4, i32 0, i32 0
%23 = load i32, i32* %22
%24 = and i32 %23, %21
store i32 %24, i32* %22
%25 = load i32, i32* @CSTOPB
%26 = xor i32 %25, -1
%27 = getelementptr inbounds %struct.termios, %struct.termios* %4, i32 0, i32 0
%28 = load i32, i32* %27
%29 = and i32 %28, %26
store i32 %29, i32* %27
%30 = load i32, i32* @CSIZE
%31 = xor i32 %30, -1
%32 = getelementptr inbounds %struct.termios, %struct.termios* %4, i32 0, i32 0
%33 = load i32, i32* %32
%34 = and i32 %33, %31
store i32 %34, i32* %32
%35 = load i32, i32* @CS8
%36 = getelementptr inbounds %struct.termios, %struct.termios* %4, i32 0, i32 0
%37 = load i32, i32* %36
%38 = or i32 %37, %35
store i32 %38, i32* %36
%39 = load i32, i32* @CLOCAL
%40 = load i32, i32* @CREAD
%41 = or i32 %39, %40
%42 = getelementptr inbounds %struct.termios, %struct.termios* %4, i32 0, i32 0
%43 = load i32, i32* %42
%44 = or i32 %43, %41
store i32 %44, i32* %42
%45 = load i32, i32* %3
%46 = load i32, i32* @TCSANOW
%47 = call i32 @tcsetattr(i32 %45, i32 %46, %struct.termios* %4)
br label %48
48: ; preds = %17, %14
%49 = load i32, i32* %3
ret i32 %49
}

LLVM IR (-O2):
%struct.termios = type { i32 }
@O_RDONLY = global i32 0
@O_NOCTTY = global i32 0
@O_NDELAY = global i32 0
@.str = [33 x i8] c"serial_open: Unable to open %s.\0A\00"
@B115200 = global i32 0
@PARENB = global i32 0
@CSTOPB = global i32 0
@CSIZE = global i32 0
@CS8 = global i32 0
@CLOCAL = global i32 0
@CREAD = global i32 0
@TCSANOW = global i32 0
define i32 @serial_open(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 ([33 x i8], [33 x i8]* @.str, i64 0, i64 0), i8* %0)
br label %33
13: ; preds = %1
%14 = load i32, i32* @B115200
%15 = call i32 @cfsetspeed(%struct.termios* %2, i32 %14)
%16 = load i32, i32* @PARENB
%17 = getelementptr inbounds %struct.termios, %struct.termios* %2, i64 0, i32 0
%18 = load i32, i32* %17
%19 = load i32, i32* @CSTOPB
%20 = or i32 %16, %19
%21 = load i32, i32* @CSIZE
%22 = or i32 %20, %21
%23 = xor i32 %22, -1
%24 = and i32 %18, %23
%25 = load i32, i32* @CS8
%26 = or i32 %25, %24
%27 = load i32, i32* @CLOCAL
%28 = load i32, i32* @CREAD
%29 = or i32 %27, %26
%30 = or i32 %29, %28
store i32 %30, i32* %17
%31 = load i32, i32* @TCSANOW
%32 = call i32 @tcsetattr(i32 %9, i32 %31, %struct.termios* %2)
br label %33
33: ; preds = %13, %11
ret i32 %9
}