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

/* Variables and functions */
int CLOCAL;
int CREAD;
int ECHO;
int ECHOE;
int /*<<< orphan*/ F_SETFL;
int ICANON;
int ISIG;
int /*<<< orphan*/ OPOST;
int O_NDELAY;
int O_NOCTTY;
int O_RDWR;
int /*<<< orphan*/ TCSANOW;
size_t VMIN;
size_t VTIME;
int /*<<< orphan*/ assert(int);
int fcntl(int, int /*<<< orphan*/, int /*<<< orphan*/);
int open(char *, int);
int tcgetattr(int, struct termios *);
int tcsetattr(int, int /*<<< orphan*/, struct termios *);
int init_port(char *port) {
  int fd, rc;
  struct termios options;
  fd = open(port, O_RDWR | O_NOCTTY | O_NDELAY);
  rc = fcntl(fd, F_SETFL, 0);
  assert(0 == rc);
  rc = tcgetattr(fd, &options);
  assert(0 == rc);
  options.c_cflag |= (CLOCAL | CREAD);
  options.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG);
  options.c_oflag &= ~OPOST;
  options.c_cc[VMIN] = 0;
  options.c_cc[VTIME] = 10;
  rc = tcsetattr(fd, TCSANOW, &options);
  assert(0 == rc);
  return fd;
}


x86 assembly (clang, -O0):
<init_port>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
mov    0x2e81(%rip),%rax
mov    (%rax),%esi
mov    0x2e30(%rip),%rax
or     (%rax),%esi
mov    0x2e17(%rip),%rax
or     (%rax),%esi
call   1070 <open@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%edi
mov    0x2e0b(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1030 <fcntl@plt>
mov    %eax,-0x10(%rbp)
xor    %eax,%eax
cmp    -0x10(%rbp),%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    -0xc(%rbp),%edi
lea    -0x28(%rbp),%rsi
call   1050 <tcgetattr@plt>
mov    %eax,-0x10(%rbp)
xor    %eax,%eax
cmp    -0x10(%rbp),%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    0x2d9d(%rip),%rax
mov    (%rax),%eax
mov    0x2ddc(%rip),%rcx
or     (%rcx),%eax
or     -0x28(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    0x2d95(%rip),%rax
mov    (%rax),%eax
mov    0x2ddc(%rip),%rcx
or     (%rcx),%eax
mov    0x2dcb(%rip),%rcx
or     (%rcx),%eax
mov    0x2dba(%rip),%rcx
or     (%rcx),%eax
xor    $0xffffffff,%eax
and    -0x24(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    0x2dc8(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x20(%rbp),%rax
mov    0x2d82(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x0,(%rax,%rcx,4)
mov    -0x20(%rbp),%rax
mov    0x2d45(%rip),%rcx
mov    (%rcx),%rcx
movl   $0xa,(%rax,%rcx,4)
mov    -0xc(%rbp),%edi
mov    0x2d81(%rip),%rax
mov    (%rax),%esi
lea    -0x28(%rbp),%rdx
call   1060 <tcsetattr@plt>
mov    %eax,-0x10(%rbp)
xor    %eax,%eax
cmp    -0x10(%rbp),%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    -0xc(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<init_port>:
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    0x2e8a(%rip),%rax
mov    0x2e3b(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2e20(%rip),%rax
or     (%rax),%esi
call   1070 <open@plt>
mov    %eax,%ebx
mov    0x2e18(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edi
xor    %edx,%edx
call   1030 <fcntl@plt>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
call   1040 <assert@plt>
mov    %rsp,%r14
mov    %ebx,%edi
mov    %r14,%rsi
call   1050 <tcgetattr@plt>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
call   1040 <assert@plt>
mov    0x2db7(%rip),%rax
mov    0x2df8(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
or     %ecx,(%rsp)
mov    0x2db2(%rip),%rax
mov    0x2dfb(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
mov    0x2de8(%rip),%rax
or     (%rax),%ecx
mov    0x2dd7(%rip),%rax
or     (%rax),%ecx
not    %ecx
and    %ecx,0x4(%rsp)
mov    0x2de8(%rip),%rax
mov    (%rax),%eax
not    %eax
and    %eax,0x10(%rsp)
mov    0x8(%rsp),%rax
mov    0x2da4(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x0,(%rax,%rcx,4)
mov    0x2d6b(%rip),%rcx
mov    (%rcx),%rcx
movl   $0xa,(%rax,%rcx,4)
mov    0x2daa(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edi
mov    %r14,%rdx
call   1060 <tcsetattr@plt>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
call   1040 <assert@plt>
mov    %ebx,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.termios = type { i32, i32, i32*, i32 }
@O_RDWR = global i32 0
@O_NOCTTY = global i32 0
@O_NDELAY = global i32 0
@F_SETFL = global i32 0
@CLOCAL = global i32 0
@CREAD = global i32 0
@ICANON = global i32 0
@ECHO = global i32 0
@ECHOE = global i32 0
@ISIG = global i32 0
@OPOST = global i32 0
@VMIN = global i64 0
@VTIME = global i64 0
@TCSANOW = global i32 0
define i32 @init_port(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
%5 = alloca %struct.termios
store i8* %0, i8** %2
%6 = load i8*, i8** %2
%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* %3
%13 = load i32, i32* %3
%14 = load i32, i32* @F_SETFL
%15 = call i32 @fcntl(i32 %13, i32 %14, i32 0)
store i32 %15, i32* %4
%16 = load i32, i32* %4
%17 = icmp eq i32 0, %16
%18 = zext i1 %17 to i32
%19 = call i32 @assert(i32 %18)
%20 = load i32, i32* %3
%21 = call i32 @tcgetattr(i32 %20, %struct.termios* %5)
store i32 %21, i32* %4
%22 = load i32, i32* %4
%23 = icmp eq i32 0, %22
%24 = zext i1 %23 to i32
%25 = call i32 @assert(i32 %24)
%26 = load i32, i32* @CLOCAL
%27 = load i32, i32* @CREAD
%28 = or i32 %26, %27
%29 = getelementptr inbounds %struct.termios, %struct.termios* %5, i32 0, i32 0
%30 = load i32, i32* %29
%31 = or i32 %30, %28
store i32 %31, i32* %29
%32 = load i32, i32* @ICANON
%33 = load i32, i32* @ECHO
%34 = or i32 %32, %33
%35 = load i32, i32* @ECHOE
%36 = or i32 %34, %35
%37 = load i32, i32* @ISIG
%38 = or i32 %36, %37
%39 = xor i32 %38, -1
%40 = getelementptr inbounds %struct.termios, %struct.termios* %5, i32 0, i32 1
%41 = load i32, i32* %40
%42 = and i32 %41, %39
store i32 %42, i32* %40
%43 = load i32, i32* @OPOST
%44 = xor i32 %43, -1
%45 = getelementptr inbounds %struct.termios, %struct.termios* %5, i32 0, i32 3
%46 = load i32, i32* %45
%47 = and i32 %46, %44
store i32 %47, i32* %45
%48 = getelementptr inbounds %struct.termios, %struct.termios* %5, i32 0, i32 2
%49 = load i32*, i32** %48
%50 = load i64, i64* @VMIN
%51 = getelementptr inbounds i32, i32* %49, i64 %50
store i32 0, i32* %51
%52 = getelementptr inbounds %struct.termios, %struct.termios* %5, i32 0, i32 2
%53 = load i32*, i32** %52
%54 = load i64, i64* @VTIME
%55 = getelementptr inbounds i32, i32* %53, i64 %54
store i32 10, i32* %55
%56 = load i32, i32* %3
%57 = load i32, i32* @TCSANOW
%58 = call i32 @tcsetattr(i32 %56, i32 %57, %struct.termios* %5)
store i32 %58, i32* %4
%59 = load i32, i32* %4
%60 = icmp eq i32 0, %59
%61 = zext i1 %60 to i32
%62 = call i32 @assert(i32 %61)
%63 = load i32, i32* %3
ret i32 %63
}

LLVM IR (-O2):
%struct.termios = type { i32, i32, i32*, i32 }
@O_RDWR = global i32 0
@O_NOCTTY = global i32 0
@O_NDELAY = global i32 0
@F_SETFL = global i32 0
@CLOCAL = global i32 0
@CREAD = global i32 0
@ICANON = global i32 0
@ECHO = global i32 0
@ECHOE = global i32 0
@ISIG = global i32 0
@OPOST = global i32 0
@VMIN = global i64 0
@VTIME = global i64 0
@TCSANOW = global i32 0
define i32 @init_port(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 = load i32, i32* @F_SETFL
%11 = tail call i32 @fcntl(i32 %9, i32 %10, i32 0)
%12 = icmp eq i32 %11, 0
%13 = zext i1 %12 to i32
%14 = tail call i32 @assert(i32 %13)
%15 = call i32 @tcgetattr(i32 %9, %struct.termios* %2)
%16 = icmp eq i32 %15, 0
%17 = zext i1 %16 to i32
%18 = call i32 @assert(i32 %17)
%19 = load i32, i32* @CLOCAL
%20 = load i32, i32* @CREAD
%21 = or i32 %20, %19
%22 = getelementptr inbounds %struct.termios, %struct.termios* %2, i64 0, i32 0
%23 = load i32, i32* %22
%24 = or i32 %21, %23
store i32 %24, i32* %22
%25 = load i32, i32* @ICANON
%26 = load i32, i32* @ECHO
%27 = or i32 %26, %25
%28 = load i32, i32* @ECHOE
%29 = or i32 %27, %28
%30 = load i32, i32* @ISIG
%31 = or i32 %29, %30
%32 = xor i32 %31, -1
%33 = getelementptr inbounds %struct.termios, %struct.termios* %2, i64 0, i32 1
%34 = load i32, i32* %33
%35 = and i32 %34, %32
store i32 %35, i32* %33
%36 = load i32, i32* @OPOST
%37 = xor i32 %36, -1
%38 = getelementptr inbounds %struct.termios, %struct.termios* %2, i64 0, i32 3
%39 = load i32, i32* %38
%40 = and i32 %39, %37
store i32 %40, i32* %38
%41 = getelementptr inbounds %struct.termios, %struct.termios* %2, i64 0, i32 2
%42 = load i32*, i32** %41
%43 = load i64, i64* @VMIN
%44 = getelementptr inbounds i32, i32* %42, i64 %43
store i32 0, i32* %44
%45 = load i64, i64* @VTIME
%46 = getelementptr inbounds i32, i32* %42, i64 %45
store i32 10, i32* %46
%47 = load i32, i32* @TCSANOW
%48 = call i32 @tcsetattr(i32 %9, i32 %47, %struct.termios* %2)
%49 = icmp eq i32 %48, 0
%50 = zext i1 %49 to i32
%51 = call i32 @assert(i32 %50)
ret i32 %9
}