#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;
  int /*<<< orphan*/ c_iflag;
};

/* Variables and functions */
int B9600;
int CLOCAL;
int CREAD;
int CS8;
int /*<<< orphan*/ IGNPAR;
int O_ASYNC;
int O_NOCTTY;
int O_NONBLOCK;
int O_RDWR;
int /*<<< orphan*/ TCIFLUSH;
int /*<<< orphan*/ TCSANOW;
size_t VMIN;
size_t VTIME;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ memset(struct termios *, int /*<<< orphan*/, int);
int open(char *, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ tcflush(int, int /*<<< orphan*/);
int /*<<< orphan*/ tcgetattr(int, struct termios *);
int /*<<< orphan*/ tcsetattr(int, int /*<<< orphan*/, struct termios *);
void opencpu(int *fd, struct termios *oldtio, struct termios *newtio) {
  *fd = open("/dev/ttyS0", O_RDWR | O_NOCTTY | O_NONBLOCK | O_ASYNC);
  if (*fd < 0) {
    perror("/dev/ttyS0");
    exit(-1);
  } else
    printf("Opened device %s.\n", "/dev/ttyS0");
  tcgetattr(*fd, oldtio);
  memset(newtio, 0, sizeof(*newtio));
  newtio->c_cflag = B9600 | CS8 | CLOCAL | CREAD;
  newtio->c_iflag = IGNPAR;
  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);
}


x86 assembly (clang, -O0):
<opencpu>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    0x2e4d(%rip),%rax
mov    (%rax),%esi
mov    0x2dfc(%rip),%rax
or     (%rax),%esi
mov    0x2e33(%rip),%rax
or     (%rax),%esi
mov    0x2dd2(%rip),%rax
or     (%rax),%esi
lea    0xe41(%rip),%rdi
call   1080 <open@plt>
mov    %eax,%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x8(%rbp),%rax
cmpl   $0x0,(%rax)
jge    11ef <opencpu+0x6f>
lea    0xe20(%rip),%rdi
call   1090 <perror@plt>
mov    $0xffffffff,%edi
call   10a0 <exit@plt>
lea    0xe15(%rip),%rdi
lea    0xe03(%rip),%rsi
call   1040 <printf@plt>
mov    -0x8(%rbp),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rsi
call   1060 <tcgetattr@plt>
mov    -0x18(%rbp),%rdi
xor    %esi,%esi
mov    $0x28,%edx
call   1050 <memset@plt>
mov    0x2da8(%rip),%rax
mov    (%rax),%ecx
mov    0x2d8f(%rip),%rax
or     (%rax),%ecx
mov    0x2d3e(%rip),%rax
or     (%rax),%ecx
mov    0x2d85(%rip),%rax
or     (%rax),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    0x2d3e(%rip),%rax
mov    (%rax),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,0x20(%rax)
mov    -0x18(%rbp),%rax
movq   $0x0,0x18(%rax)
mov    -0x18(%rbp),%rax
movq   $0x0,0x10(%rax)
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%rax
mov    0x2d16(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x0,(%rax,%rcx,4)
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%rax
mov    0x2d1d(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x1,(%rax,%rcx,4)
mov    -0x8(%rbp),%rax
mov    (%rax),%edi
mov    0x2cf6(%rip),%rax
mov    (%rax),%esi
call   1030 <tcflush@plt>
mov    -0x8(%rbp),%rax
mov    (%rax),%edi
mov    0x2d12(%rip),%rax
mov    (%rax),%esi
mov    -0x18(%rbp),%rdx
call   1070 <tcsetattr@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<opencpu>:
push   %r15
push   %r14
push   %rbx
mov    0x2e5c(%rip),%rcx
mov    0x2e0d(%rip),%rax
mov    (%rax),%eax
or     (%rcx),%eax
mov    0x2e42(%rip),%rcx
or     (%rcx),%eax
mov    %rdx,%rbx
mov    %rsi,%r15
mov    %rdi,%r14
mov    0x2dd8(%rip),%rcx
or     (%rcx),%eax
lea    0xe47(%rip),%rdi
mov    %eax,%esi
call   1080 <open@plt>
mov    %eax,(%r14)
test   %eax,%eax
js     1281 <opencpu+0x101>
lea    0xe39(%rip),%rdi
lea    0xe27(%rip),%rsi
call   1040 <printf@plt>
mov    (%r14),%edi
mov    %r15,%rsi
call   1060 <tcgetattr@plt>
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x28,%edx
call   1050 <memset@plt>
mov    0x2dd1(%rip),%rax
mov    0x2dba(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
mov    0x2d67(%rip),%rax
or     (%rax),%ecx
mov    0x2dae(%rip),%rax
or     (%rax),%ecx
mov    %ecx,(%rbx)
mov    0x2d6b(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x20(%rbx)
xorps  %xmm0,%xmm0
movups %xmm0,0x10(%rbx)
mov    0x8(%rbx),%rax
mov    0x2d5c(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x0,(%rax,%rcx,4)
mov    0x2d6b(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x1,(%rax,%rcx,4)
mov    (%r14),%edi
mov    0x2d47(%rip),%rax
mov    (%rax),%esi
call   1030 <tcflush@plt>
mov    (%r14),%edi
mov    0x2d66(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdx
pop    %rbx
pop    %r14
pop    %r15
jmp    1070 <tcsetattr@plt>
lea    0xd78(%rip),%rdi
call   1090 <perror@plt>
mov    $0xffffffff,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
%struct.termios = type { i32, i32*, i64, i64, i32 }
@.str = [11 x i8] c"/dev/ttyS0\00"
@O_RDWR = global i32 0
@O_NOCTTY = global i32 0
@O_NONBLOCK = global i32 0
@O_ASYNC = global i32 0
@.str.1 = [19 x i8] c"Opened device %s.\0A\00"
@B9600 = global i32 0
@CS8 = global i32 0
@CLOCAL = global i32 0
@CREAD = global i32 0
@IGNPAR = global i32 0
@VTIME = global i64 0
@VMIN = global i64 0
@TCIFLUSH = global i32 0
@TCSANOW = global i32 0
define void @opencpu(i32* %0, %struct.termios* %1, %struct.termios* %2) {
%4 = alloca i32*
%5 = alloca %struct.termios*
%6 = alloca %struct.termios*
store i32* %0, i32** %4
store %struct.termios* %1, %struct.termios** %5
store %struct.termios* %2, %struct.termios** %6
%7 = load i32, i32* @O_RDWR
%8 = load i32, i32* @O_NOCTTY
%9 = or i32 %7, %8
%10 = load i32, i32* @O_NONBLOCK
%11 = or i32 %9, %10
%12 = load i32, i32* @O_ASYNC
%13 = or i32 %11, %12
%14 = call i32 @open(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %13)
%15 = load i32*, i32** %4
store i32 %14, i32* %15
%16 = load i32*, i32** %4
%17 = load i32, i32* %16
%18 = icmp slt i32 %17, 0
br i1 %18, label %19, label %22
19: ; preds = %3
%20 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%21 = call i32 @exit(i32 -1)
unreachable
22: ; preds = %3
%23 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
br label %24
24: ; preds = %22
%25 = load i32*, i32** %4
%26 = load i32, i32* %25
%27 = load %struct.termios*, %struct.termios** %5
%28 = call i32 @tcgetattr(i32 %26, %struct.termios* %27)
%29 = load %struct.termios*, %struct.termios** %6
%30 = call i32 @memset(%struct.termios* %29, i32 0, i32 40)
%31 = load i32, i32* @B9600
%32 = load i32, i32* @CS8
%33 = or i32 %31, %32
%34 = load i32, i32* @CLOCAL
%35 = or i32 %33, %34
%36 = load i32, i32* @CREAD
%37 = or i32 %35, %36
%38 = load %struct.termios*, %struct.termios** %6
%39 = getelementptr inbounds %struct.termios, %struct.termios* %38, i32 0, i32 0
store i32 %37, i32* %39
%40 = load i32, i32* @IGNPAR
%41 = load %struct.termios*, %struct.termios** %6
%42 = getelementptr inbounds %struct.termios, %struct.termios* %41, i32 0, i32 4
store i32 %40, i32* %42
%43 = load %struct.termios*, %struct.termios** %6
%44 = getelementptr inbounds %struct.termios, %struct.termios* %43, i32 0, i32 3
store i64 0, i64* %44
%45 = load %struct.termios*, %struct.termios** %6
%46 = getelementptr inbounds %struct.termios, %struct.termios* %45, i32 0, i32 2
store i64 0, i64* %46
%47 = load %struct.termios*, %struct.termios** %6
%48 = getelementptr inbounds %struct.termios, %struct.termios* %47, i32 0, i32 1
%49 = load i32*, i32** %48
%50 = load i64, i64* @VTIME
%51 = getelementptr inbounds i32, i32* %49, i64 %50
store i32 0, i32* %51
%52 = load %struct.termios*, %struct.termios** %6
%53 = getelementptr inbounds %struct.termios, %struct.termios* %52, i32 0, i32 1
%54 = load i32*, i32** %53
%55 = load i64, i64* @VMIN
%56 = getelementptr inbounds i32, i32* %54, i64 %55
store i32 1, i32* %56
%57 = load i32*, i32** %4
%58 = load i32, i32* %57
%59 = load i32, i32* @TCIFLUSH
%60 = call i32 @tcflush(i32 %58, i32 %59)
%61 = load i32*, i32** %4
%62 = load i32, i32* %61
%63 = load i32, i32* @TCSANOW
%64 = load %struct.termios*, %struct.termios** %6
%65 = call i32 @tcsetattr(i32 %62, i32 %63, %struct.termios* %64)
ret void
}

LLVM IR (-O2):
%struct.termios = type { i32, i32*, i64, i64, i32 }
@.str = [11 x i8] c"/dev/ttyS0\00"
@O_RDWR = global i32 0
@O_NOCTTY = global i32 0
@O_NONBLOCK = global i32 0
@O_ASYNC = global i32 0
@.str.1 = [19 x i8] c"Opened device %s.\0A\00"
@B9600 = global i32 0
@CS8 = global i32 0
@CLOCAL = global i32 0
@CREAD = global i32 0
@IGNPAR = global i32 0
@VTIME = global i64 0
@VMIN = global i64 0
@TCIFLUSH = global i32 0
@TCSANOW = global i32 0
define void @opencpu(i32* nocapture %0, %struct.termios* %1, %struct.termios* %2) {
%4 = load i32, i32* @O_RDWR
%5 = load i32, i32* @O_NOCTTY
%6 = or i32 %5, %4
%7 = load i32, i32* @O_NONBLOCK
%8 = or i32 %6, %7
%9 = load i32, i32* @O_ASYNC
%10 = or i32 %8, %9
%11 = tail call i32 @open(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %10)
store i32 %11, i32* %0
%12 = icmp slt i32 %11, 0
br i1 %12, label %13, label %16
13: ; preds = %3
%14 = tail call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%15 = tail call i32 @exit(i32 -1)
unreachable
16: ; preds = %3
%17 = tail call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%18 = load i32, i32* %0
%19 = tail call i32 @tcgetattr(i32 %18, %struct.termios* %1)
%20 = tail call i32 @memset(%struct.termios* %2, i32 0, i32 40)
%21 = load i32, i32* @B9600
%22 = load i32, i32* @CS8
%23 = or i32 %22, %21
%24 = load i32, i32* @CLOCAL
%25 = or i32 %23, %24
%26 = load i32, i32* @CREAD
%27 = or i32 %25, %26
%28 = getelementptr inbounds %struct.termios, %struct.termios* %2, i64 0, i32 0
store i32 %27, i32* %28
%29 = load i32, i32* @IGNPAR
%30 = getelementptr inbounds %struct.termios, %struct.termios* %2, i64 0, i32 4
store i32 %29, i32* %30
%31 = getelementptr inbounds %struct.termios, %struct.termios* %2, i64 0, i32 2
%32 = getelementptr inbounds %struct.termios, %struct.termios* %2, i64 0, i32 1
%33 = bitcast i64* %31 to i8*
%34 = load i32*, i32** %32
%35 = load i64, i64* @VTIME
%36 = getelementptr inbounds i32, i32* %34, i64 %35
store i32 0, i32* %36
%37 = load i64, i64* @VMIN
%38 = getelementptr inbounds i32, i32* %34, i64 %37
store i32 1, i32* %38
%39 = load i32, i32* %0
%40 = load i32, i32* @TCIFLUSH
%41 = tail call i32 @tcflush(i32 %39, i32 %40)
%42 = load i32, i32* %0
%43 = load i32, i32* @TCSANOW
%44 = tail call i32 @tcsetattr(i32 %42, i32 %43, %struct.termios* %2)
ret void
}