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

/* Variables and functions */
int /*<<< orphan*/ B115200;
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_NDELAY;
int O_NOCTTY;
int O_RDWR;
int PARENB;
int /*<<< orphan*/ TCSANOW;
size_t VTIME;
int /*<<< orphan*/ cfsetispeed(struct termios *, int /*<<< orphan*/);
int /*<<< orphan*/ cfsetospeed(struct termios *, int /*<<< orphan*/);
int /*<<< orphan*/ exit(int);
int open(char *, int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ tcgetattr(int, struct termios *);
int /*<<< orphan*/ tcsetattr(int, int /*<<< orphan*/, struct termios *);
int open_devfd(char *fn) {
  struct termios options;
  int fd;
  fd = open(fn, O_RDWR | O_NOCTTY | O_NDELAY);
  if (fd == -1) {
    printf("Serial open fail\n");
    exit(2);
  }
  tcgetattr(fd, &options);
  cfsetispeed(&options, B115200);
  cfsetospeed(&options, B115200);
  options.c_cflag |= (CLOCAL | CREAD);
  options.c_cflag &= ~PARENB;
  options.c_cflag &= ~CSTOPB;
  options.c_cflag &= ~CSIZE;
  options.c_cflag &= ~CRTSCTS;
  options.c_cflag |= CS8;
  options.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG);
  options.c_iflag &= ~(IXON | IXOFF | IXANY);
  options.c_oflag &= ~OPOST;
  options.c_cc[VTIME] = 0;
  tcsetattr(fd, TCSANOW, &options);
  return fd;
}


x86 assembly (clang, -O0):
<open_devfd>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
mov    0x2e61(%rip),%rax
mov    (%rax),%esi
mov    0x2de8(%rip),%rax
or     (%rax),%esi
mov    0x2dd7(%rip),%rax
or     (%rax),%esi
call   1070 <open@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0xffffffff,-0x2c(%rbp)
jne    11c3 <open_devfd+0x53>
lea    0xe4c(%rip),%rdi
call   1040 <printf@plt>
mov    $0x2,%edi
call   1090 <exit@plt>
mov    -0x2c(%rbp),%edi
lea    -0x28(%rbp),%rsi
call   1050 <tcgetattr@plt>
mov    0x2d92(%rip),%rax
mov    (%rax),%esi
lea    -0x28(%rbp),%rdi
call   1080 <cfsetispeed@plt>
mov    0x2d80(%rip),%rax
mov    (%rax),%esi
lea    -0x28(%rbp),%rdi
call   1030 <cfsetospeed@plt>
mov    0x2d3e(%rip),%rax
mov    (%rax),%eax
mov    0x2d9d(%rip),%rcx
or     (%rcx),%eax
or     -0x28(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    0x2db6(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x28(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    0x2d1c(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x28(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    0x2d5a(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x28(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    0x2d00(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x28(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    0x2d3e(%rip),%rax
mov    (%rax),%eax
or     -0x28(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    0x2cef(%rip),%rax
mov    (%rax),%eax
mov    0x2d46(%rip),%rcx
or     (%rcx),%eax
mov    0x2d35(%rip),%rcx
or     (%rcx),%eax
mov    0x2d24(%rip),%rcx
or     (%rcx),%eax
xor    $0xffffffff,%eax
and    -0x24(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    0x2d3a(%rip),%rax
mov    (%rax),%eax
mov    0x2d41(%rip),%rcx
or     (%rcx),%eax
mov    0x2cd8(%rip),%rcx
or     (%rcx),%eax
xor    $0xffffffff,%eax
and    -0x20(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    0x2d1e(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x10(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x18(%rbp),%rax
mov    0x2c90(%rip),%rcx
mov    (%rcx),%rcx
movq   $0x0,(%rax,%rcx,8)
mov    -0x2c(%rbp),%edi
mov    0x2cdb(%rip),%rax
mov    (%rax),%esi
lea    -0x28(%rbp),%rdx
call   1060 <tcsetattr@plt>
mov    -0x2c(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<open_devfd>:
push   %rbp
push   %r14
push   %rbx
sub    $0x20,%rsp
mov    0x2e69(%rip),%rax
mov    0x2df2(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2ddf(%rip),%rax
or     (%rax),%esi
call   1070 <open@plt>
cmp    $0xffffffff,%eax
je     12a3 <open_devfd+0x133>
mov    %eax,%ebp
mov    %rsp,%r14
mov    %eax,%edi
mov    %r14,%rsi
call   1050 <tcgetattr@plt>
mov    0x2db1(%rip),%rbx
mov    (%rbx),%esi
mov    %r14,%rdi
call   1080 <cfsetispeed@plt>
mov    (%rbx),%esi
mov    %r14,%rdi
call   1040 <cfsetospeed@plt>
mov    0x2d66(%rip),%rax
mov    0x2dc7(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
or     (%rsp),%ecx
mov    0x2de1(%rip),%rax
mov    (%rax),%eax
mov    0x2d50(%rip),%rdx
or     (%rdx),%eax
mov    0x2d97(%rip),%rdx
or     (%rdx),%eax
mov    0x2d46(%rip),%rdx
or     (%rdx),%eax
not    %eax
and    %ecx,%eax
mov    0x2d89(%rip),%rcx
or     (%rcx),%eax
mov    0x2d40(%rip),%rcx
mov    0x2d99(%rip),%rdx
mov    (%rdx),%edx
or     (%rcx),%edx
mov    %eax,(%rsp)
mov    0x2d83(%rip),%rax
or     (%rax),%edx
mov    0x2d72(%rip),%rax
or     (%rax),%edx
not    %edx
and    %edx,0x4(%rsp)
mov    0x2d8b(%rip),%rax
mov    0x2d94(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
mov    0x2d29(%rip),%rax
or     (%rax),%ecx
not    %ecx
and    %ecx,0x8(%rsp)
mov    0x2d72(%rip),%rax
mov    (%rax),%eax
not    %eax
and    %eax,0x18(%rsp)
mov    0x10(%rsp),%rax
mov    0x2ce6(%rip),%rcx
mov    (%rcx),%rcx
movq   $0x0,(%rax,%rcx,8)
mov    0x2d34(%rip),%rax
mov    (%rax),%esi
mov    %ebp,%edi
mov    %r14,%rdx
call   1060 <tcsetattr@plt>
mov    %ebp,%eax
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xd56(%rip),%rdi
call   1030 <puts@plt>
mov    $0x2,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
%struct.termios = type { i32, i32, i32, i64*, i32 }
@O_RDWR = global i32 0
@O_NOCTTY = global i32 0
@O_NDELAY = global i32 0
@.str = [18 x i8] c"Serial open fail\0A\00"
@B115200 = global i32 0
@CLOCAL = global i32 0
@CREAD = global i32 0
@PARENB = global i32 0
@CSTOPB = global i32 0
@CSIZE = global i32 0
@CRTSCTS = global i32 0
@CS8 = global i32 0
@ICANON = global i32 0
@ECHO = global i32 0
@ECHOE = global i32 0
@ISIG = global i32 0
@IXON = global i32 0
@IXOFF = global i32 0
@IXANY = global i32 0
@OPOST = global i32 0
@VTIME = global i64 0
@TCSANOW = global i32 0
define i32 @open_devfd(i8* %0) {
%2 = alloca i8*
%3 = alloca %struct.termios
%4 = alloca i32
store i8* %0, i8** %2
%5 = load i8*, i8** %2
%6 = load i32, i32* @O_RDWR
%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* %4
%12 = load i32, i32* %4
%13 = icmp eq i32 %12, -1
br i1 %13, label %14, label %17
14: ; preds = %1
%15 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
%16 = call i32 @exit(i32 2)
unreachable
17: ; preds = %1
%18 = load i32, i32* %4
%19 = call i32 @tcgetattr(i32 %18, %struct.termios* %3)
%20 = load i32, i32* @B115200
%21 = call i32 @cfsetispeed(%struct.termios* %3, i32 %20)
%22 = load i32, i32* @B115200
%23 = call i32 @cfsetospeed(%struct.termios* %3, i32 %22)
%24 = load i32, i32* @CLOCAL
%25 = load i32, i32* @CREAD
%26 = or i32 %24, %25
%27 = getelementptr inbounds %struct.termios, %struct.termios* %3, i32 0, i32 0
%28 = load i32, i32* %27
%29 = or i32 %28, %26
store i32 %29, i32* %27
%30 = load i32, i32* @PARENB
%31 = xor i32 %30, -1
%32 = getelementptr inbounds %struct.termios, %struct.termios* %3, i32 0, i32 0
%33 = load i32, i32* %32
%34 = and i32 %33, %31
store i32 %34, i32* %32
%35 = load i32, i32* @CSTOPB
%36 = xor i32 %35, -1
%37 = getelementptr inbounds %struct.termios, %struct.termios* %3, i32 0, i32 0
%38 = load i32, i32* %37
%39 = and i32 %38, %36
store i32 %39, i32* %37
%40 = load i32, i32* @CSIZE
%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* @CRTSCTS
%46 = xor i32 %45, -1
%47 = getelementptr inbounds %struct.termios, %struct.termios* %3, i32 0, i32 0
%48 = load i32, i32* %47
%49 = and i32 %48, %46
store i32 %49, i32* %47
%50 = load i32, i32* @CS8
%51 = getelementptr inbounds %struct.termios, %struct.termios* %3, i32 0, i32 0
%52 = load i32, i32* %51
%53 = or i32 %52, %50
store i32 %53, i32* %51
%54 = load i32, i32* @ICANON
%55 = load i32, i32* @ECHO
%56 = or i32 %54, %55
%57 = load i32, i32* @ECHOE
%58 = or i32 %56, %57
%59 = load i32, i32* @ISIG
%60 = or i32 %58, %59
%61 = xor i32 %60, -1
%62 = getelementptr inbounds %struct.termios, %struct.termios* %3, i32 0, i32 1
%63 = load i32, i32* %62
%64 = and i32 %63, %61
store i32 %64, i32* %62
%65 = load i32, i32* @IXON
%66 = load i32, i32* @IXOFF
%67 = or i32 %65, %66
%68 = load i32, i32* @IXANY
%69 = or i32 %67, %68
%70 = xor i32 %69, -1
%71 = getelementptr inbounds %struct.termios, %struct.termios* %3, i32 0, i32 2
%72 = load i32, i32* %71
%73 = and i32 %72, %70
store i32 %73, i32* %71
%74 = load i32, i32* @OPOST
%75 = xor i32 %74, -1
%76 = getelementptr inbounds %struct.termios, %struct.termios* %3, i32 0, i32 4
%77 = load i32, i32* %76
%78 = and i32 %77, %75
store i32 %78, i32* %76
%79 = getelementptr inbounds %struct.termios, %struct.termios* %3, i32 0, i32 3
%80 = load i64*, i64** %79
%81 = load i64, i64* @VTIME
%82 = getelementptr inbounds i64, i64* %80, i64 %81
store i64 0, i64* %82
%83 = load i32, i32* %4
%84 = load i32, i32* @TCSANOW
%85 = call i32 @tcsetattr(i32 %83, i32 %84, %struct.termios* %3)
%86 = load i32, i32* %4
ret i32 %86
}

LLVM IR (-O2):
%struct.termios = type { i32, i32, i32, i64*, i32 }
@O_RDWR = global i32 0
@O_NOCTTY = global i32 0
@O_NDELAY = global i32 0
@B115200 = global i32 0
@CLOCAL = global i32 0
@CREAD = global i32 0
@PARENB = global i32 0
@CSTOPB = global i32 0
@CSIZE = global i32 0
@CRTSCTS = global i32 0
@CS8 = global i32 0
@ICANON = global i32 0
@ECHO = global i32 0
@ECHOE = global i32 0
@ISIG = global i32 0
@IXON = global i32 0
@IXOFF = global i32 0
@IXANY = global i32 0
@OPOST = global i32 0
@VTIME = global i64 0
@TCSANOW = global i32 0
@str = [17 x i8] c"Serial open fail\00"
define i32 @open_devfd(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 %14
11: ; preds = %1
%12 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str, i64 0, i64 0))
%13 = tail call i32 @exit(i32 2)
unreachable
14: ; preds = %1
%15 = call i32 @tcgetattr(i32 %9, %struct.termios* %2)
%16 = load i32, i32* @B115200
%17 = call i32 @cfsetispeed(%struct.termios* %2, i32 %16)
%18 = load i32, i32* @B115200
%19 = call i32 @cfsetospeed(%struct.termios* %2, i32 %18)
%20 = load i32, i32* @CLOCAL
%21 = load i32, i32* @CREAD
%22 = or i32 %21, %20
%23 = getelementptr inbounds %struct.termios, %struct.termios* %2, i64 0, i32 0
%24 = load i32, i32* %23
%25 = or i32 %22, %24
%26 = load i32, i32* @PARENB
%27 = load i32, i32* @CSTOPB
%28 = or i32 %26, %27
%29 = load i32, i32* @CSIZE
%30 = or i32 %28, %29
%31 = load i32, i32* @CRTSCTS
%32 = or i32 %30, %31
%33 = xor i32 %32, -1
%34 = and i32 %25, %33
%35 = load i32, i32* @CS8
%36 = or i32 %35, %34
store i32 %36, i32* %23
%37 = load i32, i32* @ICANON
%38 = load i32, i32* @ECHO
%39 = or i32 %38, %37
%40 = load i32, i32* @ECHOE
%41 = or i32 %39, %40
%42 = load i32, i32* @ISIG
%43 = or i32 %41, %42
%44 = xor i32 %43, -1
%45 = getelementptr inbounds %struct.termios, %struct.termios* %2, i64 0, i32 1
%46 = load i32, i32* %45
%47 = and i32 %46, %44
store i32 %47, i32* %45
%48 = load i32, i32* @IXON
%49 = load i32, i32* @IXOFF
%50 = or i32 %49, %48
%51 = load i32, i32* @IXANY
%52 = or i32 %50, %51
%53 = xor i32 %52, -1
%54 = getelementptr inbounds %struct.termios, %struct.termios* %2, i64 0, i32 2
%55 = load i32, i32* %54
%56 = and i32 %55, %53
store i32 %56, i32* %54
%57 = load i32, i32* @OPOST
%58 = xor i32 %57, -1
%59 = getelementptr inbounds %struct.termios, %struct.termios* %2, i64 0, i32 4
%60 = load i32, i32* %59
%61 = and i32 %60, %58
store i32 %61, i32* %59
%62 = getelementptr inbounds %struct.termios, %struct.termios* %2, i64 0, i32 3
%63 = load i64*, i64** %62
%64 = load i64, i64* @VTIME
%65 = getelementptr inbounds i64, i64* %63, i64 %64
store i64 0, i64* %65
%66 = load i32, i32* @TCSANOW
%67 = call i32 @tcsetattr(i32 %9, i32 %66, %struct.termios* %2)
ret i32 %9
}