#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 /*<<< orphan*/ c_lflag;
  scalar_t__ c_oflag;
};

/* Variables and functions */
int B9600;
int CLOCAL;
int CREAD;
int CS8;
int /*<<< orphan*/ FNDELAY;
int /*<<< orphan*/ F_SETFL;
int /*<<< orphan*/ ICANON;
int ICRNL;
int IGNPAR;
int O_NDELAY;
int O_NOCTTY;
int O_NONBLOCK;
int O_RDWR;
int /*<<< orphan*/ TCIOFLUSH;
int /*<<< orphan*/ TCSANOW;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fcntl(int, int /*<<< orphan*/, int /*<<< orphan*/);
int open(char *, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ tcflush(int, int /*<<< orphan*/);
int /*<<< orphan*/ tcsetattr(int, int /*<<< orphan*/, struct termios *);
int open_port(void) {
  int fd_ser;
  struct termios terminal;
  fd_ser = open("/dev/ttyS0", O_RDWR | O_NOCTTY | O_NDELAY | O_NONBLOCK);
  if (fd_ser == -1) {
    perror("Kann die Serielle nicht oeffnen");
    exit(1);
  }
  fcntl(fd_ser, F_SETFL, FNDELAY);
  terminal.c_cflag = B9600 | CS8 | CLOCAL | CREAD;
  terminal.c_iflag = IGNPAR | ICRNL;
  terminal.c_oflag = 0;
  terminal.c_lflag &= ~(ICANON);
  tcflush(fd_ser, TCIOFLUSH);
  tcsetattr(fd_ser, TCSANOW, &terminal);
  return fd_ser;
}


x86 assembly (clang, -O0):
<open_port>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    0x2e79(%rip),%rax
mov    (%rax),%esi
mov    0x2e30(%rip),%rax
or     (%rax),%esi
mov    0x2e17(%rip),%rax
or     (%rax),%esi
mov    0x2e4e(%rip),%rax
or     (%rax),%esi
lea    0xe6d(%rip),%rdi
call   1060 <open@plt>
mov    %eax,-0x4(%rbp)
cmpl   $0xffffffff,-0x4(%rbp)
jne    11bb <open_port+0x5b>
lea    0xe5f(%rip),%rdi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x4(%rbp),%edi
mov    0x2ddb(%rip),%rax
mov    (%rax),%esi
mov    0x2dba(%rip),%rax
mov    (%rax),%edx
call   1030 <fcntl@plt>
mov    0x2dec(%rip),%rax
mov    (%rax),%eax
mov    0x2dd3(%rip),%rcx
or     (%rcx),%eax
mov    0x2d7a(%rip),%rcx
or     (%rcx),%eax
mov    0x2dc9(%rip),%rcx
or     (%rcx),%eax
mov    %eax,-0x20(%rbp)
mov    0x2d7d(%rip),%rax
mov    (%rax),%eax
mov    0x2dd4(%rip),%rcx
or     (%rcx),%eax
mov    %eax,-0x1c(%rbp)
movq   $0x0,-0x10(%rbp)
mov    0x2d58(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2d5b(%rip),%rax
mov    (%rax),%esi
call   1040 <tcflush@plt>
mov    -0x4(%rbp),%edi
mov    0x2d8a(%rip),%rax
mov    (%rax),%esi
lea    -0x20(%rbp),%rdx
call   1050 <tcsetattr@plt>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<open_port>:
push   %rbx
sub    $0x20,%rsp
mov    0x2e7c(%rip),%rax
mov    0x2e35(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2e1a(%rip),%rax
or     (%rax),%esi
mov    0x2e51(%rip),%rax
or     (%rax),%esi
lea    0xe70(%rip),%rdi
call   1060 <open@plt>
cmp    $0xffffffff,%eax
je     1235 <open_port+0xd5>
mov    %eax,%ebx
mov    0x2df9(%rip),%rax
mov    (%rax),%esi
mov    0x2dd8(%rip),%rax
mov    (%rax),%edx
mov    %ebx,%edi
call   1030 <fcntl@plt>
mov    0x2e08(%rip),%rax
mov    0x2df1(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
mov    0x2d9e(%rip),%rax
or     (%rax),%ecx
mov    0x2de5(%rip),%rax
or     (%rax),%ecx
mov    %ecx,0x8(%rsp)
mov    0x2d98(%rip),%rax
mov    0x2df1(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
mov    %ecx,0xc(%rsp)
movq   $0x0,0x18(%rsp)
movl   $0x0,0x10(%rsp)
mov    0x2d81(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edi
call   1040 <tcflush@plt>
mov    0x2db1(%rip),%rax
mov    (%rax),%esi
lea    0x8(%rsp),%rdx
mov    %ebx,%edi
call   1050 <tcsetattr@plt>
mov    %ebx,%eax
add    $0x20,%rsp
pop    %rbx
ret
lea    0xdcf(%rip),%rdi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
%struct.termios = type { i32, i32, i32, i64 }
@.str = [11 x i8] c"/dev/ttyS0\00"
@O_RDWR = global i32 0
@O_NOCTTY = global i32 0
@O_NDELAY = global i32 0
@O_NONBLOCK = global i32 0
@.str.1 = [32 x i8] c"Kann die Serielle nicht oeffnen\00"
@F_SETFL = global i32 0
@FNDELAY = global i32 0
@B9600 = global i32 0
@CS8 = global i32 0
@CLOCAL = global i32 0
@CREAD = global i32 0
@IGNPAR = global i32 0
@ICRNL = global i32 0
@ICANON = global i32 0
@TCIOFLUSH = global i32 0
@TCSANOW = global i32 0
define i32 @open_port() {
%1 = alloca i32
%2 = alloca %struct.termios
%3 = load i32, i32* @O_RDWR
%4 = load i32, i32* @O_NOCTTY
%5 = or i32 %3, %4
%6 = load i32, i32* @O_NDELAY
%7 = or i32 %5, %6
%8 = load i32, i32* @O_NONBLOCK
%9 = or i32 %7, %8
%10 = call i32 @open(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %9)
store i32 %10, i32* %1
%11 = load i32, i32* %1
%12 = icmp eq i32 %11, -1
br i1 %12, label %13, label %16
13: ; preds = %0
%14 = call i32 @perror(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0))
%15 = call i32 @exit(i32 1)
unreachable
16: ; preds = %0
%17 = load i32, i32* %1
%18 = load i32, i32* @F_SETFL
%19 = load i32, i32* @FNDELAY
%20 = call i32 @fcntl(i32 %17, i32 %18, i32 %19)
%21 = load i32, i32* @B9600
%22 = load i32, i32* @CS8
%23 = or i32 %21, %22
%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, i32 0, i32 0
store i32 %27, i32* %28
%29 = load i32, i32* @IGNPAR
%30 = load i32, i32* @ICRNL
%31 = or i32 %29, %30
%32 = getelementptr inbounds %struct.termios, %struct.termios* %2, i32 0, i32 1
store i32 %31, i32* %32
%33 = getelementptr inbounds %struct.termios, %struct.termios* %2, i32 0, i32 3
store i64 0, i64* %33
%34 = load i32, i32* @ICANON
%35 = xor i32 %34, -1
%36 = getelementptr inbounds %struct.termios, %struct.termios* %2, i32 0, i32 2
%37 = load i32, i32* %36
%38 = and i32 %37, %35
store i32 %38, i32* %36
%39 = load i32, i32* %1
%40 = load i32, i32* @TCIOFLUSH
%41 = call i32 @tcflush(i32 %39, i32 %40)
%42 = load i32, i32* %1
%43 = load i32, i32* @TCSANOW
%44 = call i32 @tcsetattr(i32 %42, i32 %43, %struct.termios* %2)
%45 = load i32, i32* %1
ret i32 %45
}

LLVM IR (-O2):
%struct.termios = type { i32, i32, i32, i64 }
@.str = [11 x i8] c"/dev/ttyS0\00"
@O_RDWR = global i32 0
@O_NOCTTY = global i32 0
@O_NDELAY = global i32 0
@O_NONBLOCK = global i32 0
@.str.1 = [32 x i8] c"Kann die Serielle nicht oeffnen\00"
@F_SETFL = global i32 0
@FNDELAY = global i32 0
@B9600 = global i32 0
@CS8 = global i32 0
@CLOCAL = global i32 0
@CREAD = global i32 0
@IGNPAR = global i32 0
@ICRNL = global i32 0
@ICANON = global i32 0
@TCIOFLUSH = global i32 0
@TCSANOW = global i32 0
define i32 @open_port() {
%1 = alloca %struct.termios
%2 = bitcast %struct.termios* %1 to i8*
%3 = load i32, i32* @O_RDWR
%4 = load i32, i32* @O_NOCTTY
%5 = or i32 %4, %3
%6 = load i32, i32* @O_NDELAY
%7 = or i32 %5, %6
%8 = load i32, i32* @O_NONBLOCK
%9 = or i32 %7, %8
%10 = tail call i32 @open(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %9)
%11 = icmp eq i32 %10, -1
br i1 %11, label %12, label %15
12: ; preds = %0
%13 = tail call i32 @perror(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0))
%14 = tail call i32 @exit(i32 1)
unreachable
15: ; preds = %0
%16 = load i32, i32* @F_SETFL
%17 = load i32, i32* @FNDELAY
%18 = tail call i32 @fcntl(i32 %10, i32 %16, i32 %17)
%19 = load i32, i32* @B9600
%20 = load i32, i32* @CS8
%21 = or i32 %20, %19
%22 = load i32, i32* @CLOCAL
%23 = or i32 %21, %22
%24 = load i32, i32* @CREAD
%25 = or i32 %23, %24
%26 = getelementptr inbounds %struct.termios, %struct.termios* %1, i64 0, i32 0
store i32 %25, i32* %26
%27 = load i32, i32* @IGNPAR
%28 = load i32, i32* @ICRNL
%29 = or i32 %28, %27
%30 = getelementptr inbounds %struct.termios, %struct.termios* %1, i64 0, i32 1
store i32 %29, i32* %30
%31 = getelementptr inbounds %struct.termios, %struct.termios* %1, i64 0, i32 3
store i64 0, i64* %31
%32 = getelementptr inbounds %struct.termios, %struct.termios* %1, i64 0, i32 2
store i32 0, i32* %32
%33 = load i32, i32* @TCIOFLUSH
%34 = tail call i32 @tcflush(i32 %10, i32 %33)
%35 = load i32, i32* @TCSANOW
%36 = call i32 @tcsetattr(i32 %10, i32 %35, %struct.termios* %1)
ret i32 %10
}