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

/* Variables and functions */
int /*<<< orphan*/ B9600;
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_NONBLOCK;
int O_RDWR;
int PARENB;
int /*<<< orphan*/ TCSANOW;
size_t VMIN;
size_t VTIME;
int /*<<< orphan*/ cfmakeraw(struct termios *);
int /*<<< orphan*/ cfsetispeed(struct termios *, int /*<<< orphan*/);
int /*<<< orphan*/ cfsetospeed(struct termios *, int /*<<< orphan*/);
int open(char const *, int);
int /*<<< orphan*/ tcsetattr(int, int /*<<< orphan*/, struct termios *);
int openTty(const char *input) {
  int f = open(input, O_RDWR | O_NONBLOCK);
  if (f < 0) {
    return f;
  }
  struct termios tio;
  cfmakeraw(&tio);
  cfsetispeed(&tio, B9600);
  cfsetospeed(&tio, B9600);
  tio.c_cflag &= ~PARENB;
  tio.c_cflag &= ~CSTOPB;
  tio.c_cflag &= ~CSIZE;
  tio.c_cflag |= CS8;
  tio.c_cflag &= ~CRTSCTS;
  tio.c_cflag |= CREAD | CLOCAL;
  tio.c_iflag &= ~(IXON | IXOFF | IXANY);
  tio.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG);
  tio.c_oflag &= ~OPOST;
  tio.c_cc[VMIN] = 0;
  tio.c_cc[VTIME] = 0;
  tcsetattr(f, TCSANOW, &tio);
  return f;
}


x86 assembly (clang, -O0):
<openTty>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2e81(%rip),%rax
mov    (%rax),%esi
mov    0x2e68(%rip),%rax
or     (%rax),%esi
call   1060 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    118f <openTty+0x3f>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    12d5 <openTty+0x185>
lea    -0x38(%rbp),%rdi
call   1040 <cfmakeraw@plt>
mov    0x2df9(%rip),%rax
mov    (%rax),%esi
lea    -0x38(%rbp),%rdi
call   1070 <cfsetispeed@plt>
mov    0x2de7(%rip),%rax
mov    (%rax),%esi
lea    -0x38(%rbp),%rdi
call   1030 <cfsetospeed@plt>
mov    0x2dfd(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x38(%rbp),%eax
mov    %eax,-0x38(%rbp)
mov    0x2d6b(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x38(%rbp),%eax
mov    %eax,-0x38(%rbp)
mov    0x2d91(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x38(%rbp),%eax
mov    %eax,-0x38(%rbp)
mov    0x2d8f(%rip),%rax
mov    (%rax),%eax
or     -0x38(%rbp),%eax
mov    %eax,-0x38(%rbp)
mov    0x2d40(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x38(%rbp),%eax
mov    %eax,-0x38(%rbp)
mov    0x2d76(%rip),%rax
mov    (%rax),%eax
mov    0x2d15(%rip),%rcx
or     (%rcx),%eax
or     -0x38(%rbp),%eax
mov    %eax,-0x38(%rbp)
mov    0x2d96(%rip),%rax
mov    (%rax),%eax
mov    0x2da5(%rip),%rcx
or     (%rcx),%eax
mov    0x2d24(%rip),%rcx
or     (%rcx),%eax
xor    $0xffffffff,%eax
and    -0x34(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    0x2d02(%rip),%rax
mov    (%rax),%eax
mov    0x2d51(%rip),%rcx
or     (%rcx),%eax
mov    0x2d40(%rip),%rcx
or     (%rcx),%eax
mov    0x2d2f(%rip),%rcx
or     (%rcx),%eax
xor    $0xffffffff,%eax
and    -0x30(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    0x2d4d(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x20(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x28(%rbp),%rax
mov    0x2ce7(%rip),%rcx
mov    (%rcx),%rcx
movq   $0x0,(%rax,%rcx,8)
mov    -0x28(%rbp),%rax
mov    0x2cb1(%rip),%rcx
mov    (%rcx),%rcx
movq   $0x0,(%rax,%rcx,8)
mov    -0x14(%rbp),%edi
mov    0x2cf4(%rip),%rax
mov    (%rax),%esi
lea    -0x38(%rbp),%rdx
call   1050 <tcsetattr@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<openTty>:
push   %rbp
push   %r14
push   %rbx
sub    $0x20,%rsp
mov    0x2e89(%rip),%rax
mov    0x2e72(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
call   1060 <open@plt>
mov    %eax,%ebp
test   %eax,%eax
js     1280 <openTty+0x130>
mov    %rsp,%r14
mov    %r14,%rdi
call   1040 <cfmakeraw@plt>
mov    0x2e0d(%rip),%rbx
mov    (%rbx),%esi
mov    %r14,%rdi
call   1070 <cfsetispeed@plt>
mov    (%rbx),%esi
mov    %r14,%rdi
call   1030 <cfsetospeed@plt>
mov    0x2e1a(%rip),%rax
mov    (%rax),%eax
mov    0x2d91(%rip),%rcx
or     (%rcx),%eax
mov    0x2dc0(%rip),%rcx
or     (%rcx),%eax
not    %eax
and    (%rsp),%eax
mov    0x2dc2(%rip),%rcx
or     (%rcx),%eax
mov    0x2d79(%rip),%rcx
mov    (%rcx),%ecx
not    %ecx
and    %eax,%ecx
mov    0x2db4(%rip),%rax
mov    0x2d55(%rip),%rdx
or     (%rax),%ecx
or     (%rdx),%ecx
mov    %ecx,(%rsp)
mov    0x2dd7(%rip),%rax
mov    0x2de8(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
mov    0x2d65(%rip),%rax
or     (%rax),%ecx
not    %ecx
and    %ecx,0x4(%rsp)
mov    0x2d46(%rip),%rax
mov    0x2d97(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
mov    0x2d84(%rip),%rax
or     (%rax),%ecx
mov    0x2d73(%rip),%rax
or     (%rax),%ecx
not    %ecx
and    %ecx,0x8(%rsp)
mov    0x2d94(%rip),%rax
mov    (%rax),%eax
not    %eax
and    %eax,0x18(%rsp)
mov    0x10(%rsp),%rax
mov    0x2d30(%rip),%rcx
mov    (%rcx),%rcx
movq   $0x0,(%rax,%rcx,8)
mov    0x2cfe(%rip),%rcx
mov    (%rcx),%rcx
movq   $0x0,(%rax,%rcx,8)
mov    0x2d44(%rip),%rax
mov    (%rax),%esi
mov    %ebp,%edi
mov    %r14,%rdx
call   1050 <tcsetattr@plt>
mov    %ebp,%eax
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.termios = type { i32, i32, i32, i64*, i32 }
@O_RDWR = global i32 0
@O_NONBLOCK = global i32 0
@B9600 = global i32 0
@PARENB = global i32 0
@CSTOPB = global i32 0
@CSIZE = global i32 0
@CS8 = global i32 0
@CRTSCTS = global i32 0
@CREAD = global i32 0
@CLOCAL = global i32 0
@IXON = global i32 0
@IXOFF = global i32 0
@IXANY = 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 @openTty(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca %struct.termios
store i8* %0, i8** %3
%6 = load i8*, i8** %3
%7 = load i32, i32* @O_RDWR
%8 = load i32, i32* @O_NONBLOCK
%9 = or i32 %7, %8
%10 = call i32 @open(i8* %6, i32 %9)
store i32 %10, i32* %4
%11 = load i32, i32* %4
%12 = icmp slt i32 %11, 0
br i1 %12, label %13, label %15
13: ; preds = %1
%14 = load i32, i32* %4
store i32 %14, i32* %2
br label %88
15: ; preds = %1
%16 = call i32 @cfmakeraw(%struct.termios* %5)
%17 = load i32, i32* @B9600
%18 = call i32 @cfsetispeed(%struct.termios* %5, i32 %17)
%19 = load i32, i32* @B9600
%20 = call i32 @cfsetospeed(%struct.termios* %5, i32 %19)
%21 = load i32, i32* @PARENB
%22 = xor i32 %21, -1
%23 = getelementptr inbounds %struct.termios, %struct.termios* %5, i32 0, i32 0
%24 = load i32, i32* %23
%25 = and i32 %24, %22
store i32 %25, i32* %23
%26 = load i32, i32* @CSTOPB
%27 = xor i32 %26, -1
%28 = getelementptr inbounds %struct.termios, %struct.termios* %5, i32 0, i32 0
%29 = load i32, i32* %28
%30 = and i32 %29, %27
store i32 %30, i32* %28
%31 = load i32, i32* @CSIZE
%32 = xor i32 %31, -1
%33 = getelementptr inbounds %struct.termios, %struct.termios* %5, i32 0, i32 0
%34 = load i32, i32* %33
%35 = and i32 %34, %32
store i32 %35, i32* %33
%36 = load i32, i32* @CS8
%37 = getelementptr inbounds %struct.termios, %struct.termios* %5, i32 0, i32 0
%38 = load i32, i32* %37
%39 = or i32 %38, %36
store i32 %39, i32* %37
%40 = load i32, i32* @CRTSCTS
%41 = xor i32 %40, -1
%42 = getelementptr inbounds %struct.termios, %struct.termios* %5, i32 0, i32 0
%43 = load i32, i32* %42
%44 = and i32 %43, %41
store i32 %44, i32* %42
%45 = load i32, i32* @CREAD
%46 = load i32, i32* @CLOCAL
%47 = or i32 %45, %46
%48 = getelementptr inbounds %struct.termios, %struct.termios* %5, i32 0, i32 0
%49 = load i32, i32* %48
%50 = or i32 %49, %47
store i32 %50, i32* %48
%51 = load i32, i32* @IXON
%52 = load i32, i32* @IXOFF
%53 = or i32 %51, %52
%54 = load i32, i32* @IXANY
%55 = or i32 %53, %54
%56 = xor i32 %55, -1
%57 = getelementptr inbounds %struct.termios, %struct.termios* %5, i32 0, i32 1
%58 = load i32, i32* %57
%59 = and i32 %58, %56
store i32 %59, i32* %57
%60 = load i32, i32* @ICANON
%61 = load i32, i32* @ECHO
%62 = or i32 %60, %61
%63 = load i32, i32* @ECHOE
%64 = or i32 %62, %63
%65 = load i32, i32* @ISIG
%66 = or i32 %64, %65
%67 = xor i32 %66, -1
%68 = getelementptr inbounds %struct.termios, %struct.termios* %5, i32 0, i32 2
%69 = load i32, i32* %68
%70 = and i32 %69, %67
store i32 %70, i32* %68
%71 = load i32, i32* @OPOST
%72 = xor i32 %71, -1
%73 = getelementptr inbounds %struct.termios, %struct.termios* %5, i32 0, i32 4
%74 = load i32, i32* %73
%75 = and i32 %74, %72
store i32 %75, i32* %73
%76 = getelementptr inbounds %struct.termios, %struct.termios* %5, i32 0, i32 3
%77 = load i64*, i64** %76
%78 = load i64, i64* @VMIN
%79 = getelementptr inbounds i64, i64* %77, i64 %78
store i64 0, i64* %79
%80 = getelementptr inbounds %struct.termios, %struct.termios* %5, i32 0, i32 3
%81 = load i64*, i64** %80
%82 = load i64, i64* @VTIME
%83 = getelementptr inbounds i64, i64* %81, i64 %82
store i64 0, i64* %83
%84 = load i32, i32* %4
%85 = load i32, i32* @TCSANOW
%86 = call i32 @tcsetattr(i32 %84, i32 %85, %struct.termios* %5)
%87 = load i32, i32* %4
store i32 %87, i32* %2
br label %88
88: ; preds = %15, %13
%89 = load i32, i32* %2
ret i32 %89
}

LLVM IR (-O2):
%struct.termios = type { i32, i32, i32, i64*, i32 }
@O_RDWR = global i32 0
@O_NONBLOCK = global i32 0
@B9600 = global i32 0
@PARENB = global i32 0
@CSTOPB = global i32 0
@CSIZE = global i32 0
@CS8 = global i32 0
@CRTSCTS = global i32 0
@CREAD = global i32 0
@CLOCAL = global i32 0
@IXON = global i32 0
@IXOFF = global i32 0
@IXANY = 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 @openTty(i8* nocapture %0) {
%2 = alloca %struct.termios
%3 = load i32, i32* @O_RDWR
%4 = load i32, i32* @O_NONBLOCK
%5 = or i32 %4, %3
%6 = tail call i32 @open(i8* %0, i32 %5)
%7 = icmp slt i32 %6, 0
br i1 %7, label %66, label %8
8: ; preds = %1
%9 = bitcast %struct.termios* %2 to i8*
%10 = call i32 @cfmakeraw(%struct.termios* %2)
%11 = load i32, i32* @B9600
%12 = call i32 @cfsetispeed(%struct.termios* %2, i32 %11)
%13 = load i32, i32* @B9600
%14 = call i32 @cfsetospeed(%struct.termios* %2, i32 %13)
%15 = load i32, i32* @PARENB
%16 = getelementptr inbounds %struct.termios, %struct.termios* %2, i64 0, i32 0
%17 = load i32, i32* %16
%18 = load i32, i32* @CSTOPB
%19 = or i32 %15, %18
%20 = load i32, i32* @CSIZE
%21 = or i32 %19, %20
%22 = xor i32 %21, -1
%23 = and i32 %17, %22
%24 = load i32, i32* @CS8
%25 = or i32 %24, %23
%26 = load i32, i32* @CRTSCTS
%27 = xor i32 %26, -1
%28 = and i32 %25, %27
%29 = load i32, i32* @CREAD
%30 = load i32, i32* @CLOCAL
%31 = or i32 %29, %28
%32 = or i32 %31, %30
store i32 %32, i32* %16
%33 = load i32, i32* @IXON
%34 = load i32, i32* @IXOFF
%35 = or i32 %34, %33
%36 = load i32, i32* @IXANY
%37 = or i32 %35, %36
%38 = xor i32 %37, -1
%39 = getelementptr inbounds %struct.termios, %struct.termios* %2, i64 0, i32 1
%40 = load i32, i32* %39
%41 = and i32 %40, %38
store i32 %41, i32* %39
%42 = load i32, i32* @ICANON
%43 = load i32, i32* @ECHO
%44 = or i32 %43, %42
%45 = load i32, i32* @ECHOE
%46 = or i32 %44, %45
%47 = load i32, i32* @ISIG
%48 = or i32 %46, %47
%49 = xor i32 %48, -1
%50 = getelementptr inbounds %struct.termios, %struct.termios* %2, i64 0, i32 2
%51 = load i32, i32* %50
%52 = and i32 %51, %49
store i32 %52, i32* %50
%53 = load i32, i32* @OPOST
%54 = xor i32 %53, -1
%55 = getelementptr inbounds %struct.termios, %struct.termios* %2, i64 0, i32 4
%56 = load i32, i32* %55
%57 = and i32 %56, %54
store i32 %57, i32* %55
%58 = getelementptr inbounds %struct.termios, %struct.termios* %2, i64 0, i32 3
%59 = load i64*, i64** %58
%60 = load i64, i64* @VMIN
%61 = getelementptr inbounds i64, i64* %59, i64 %60
store i64 0, i64* %61
%62 = load i64, i64* @VTIME
%63 = getelementptr inbounds i64, i64* %59, i64 %62
store i64 0, i64* %63
%64 = load i32, i32* @TCSANOW
%65 = call i32 @tcsetattr(i32 %6, i32 %64, %struct.termios* %2)
br label %66
66: ; preds = %1, %8
ret i32 %6
}