#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 /*<<< orphan*/ B9600;
int CLOCAL;
int CREAD;
int CS8;
int /*<<< orphan*/ IGNPAR;
int O_NOCTTY;
int O_RDWR;
int /*<<< orphan*/ TCIFLUSH;
int /*<<< orphan*/ TCOFLUSH;
int /*<<< orphan*/ TCSANOW;
size_t VMIN;
size_t VTIME;
int /*<<< orphan*/ cfsetispeed(struct termios *, int /*<<< orphan*/);
int /*<<< orphan*/ cfsetospeed(struct termios *, int /*<<< orphan*/);
int open(char *, int);
int tcflush(int, int /*<<< orphan*/);
int tcsetattr(int, int /*<<< orphan*/, struct termios *);
int chronopic_open(char *disp) {
  struct termios newtermios;
  int fd;
  fd = open(disp, O_RDWR | O_NOCTTY);
  newtermios.c_cflag = CS8 | CLOCAL | CREAD;
  newtermios.c_iflag = IGNPAR;
  newtermios.c_oflag = 0;
  newtermios.c_lflag = 0;
  newtermios.c_cc[VMIN] = 1;
  newtermios.c_cc[VTIME] = 0;
  cfsetospeed(&newtermios, B9600);
  cfsetispeed(&newtermios, B9600);
  if (tcflush(fd, TCIFLUSH) == -1) {
    return -1;
  }
  if (tcflush(fd, TCOFLUSH) == -1) {
    return -1;
  }
  if (tcsetattr(fd, TCSANOW, &newtermios) == -1) {
    return -1;
  }
  return fd;
}


x86 assembly (clang, -O0):
<chronopic_open>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2e79(%rip),%rax
mov    (%rax),%esi
mov    0x2e30(%rip),%rax
or     (%rax),%esi
call   1060 <open@plt>
mov    %eax,-0x3c(%rbp)
mov    0x2e3f(%rip),%rax
mov    (%rax),%eax
mov    0x2df6(%rip),%rcx
or     (%rcx),%eax
mov    0x2e35(%rip),%rcx
or     (%rcx),%eax
mov    %eax,-0x38(%rbp)
mov    0x2df1(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
mov    -0x30(%rbp),%rax
mov    0x2df9(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x1,(%rax,%rcx,4)
mov    -0x30(%rbp),%rax
mov    0x2dc4(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x0,(%rax,%rcx,4)
mov    0x2deb(%rip),%rax
mov    (%rax),%esi
lea    -0x38(%rbp),%rdi
call   1030 <cfsetospeed@plt>
mov    0x2dd9(%rip),%rax
mov    (%rax),%esi
lea    -0x38(%rbp),%rdi
call   1070 <cfsetispeed@plt>
mov    -0x3c(%rbp),%edi
mov    0x2d9c(%rip),%rax
mov    (%rax),%esi
call   1040 <tcflush@plt>
cmp    $0xffffffff,%eax
jne    1228 <chronopic_open+0xd8>
movl   $0xffffffff,-0x4(%rbp)
jmp    127e <chronopic_open+0x12e>
mov    -0x3c(%rbp),%edi
mov    0x2dbe(%rip),%rax
mov    (%rax),%esi
call   1040 <tcflush@plt>
cmp    $0xffffffff,%eax
jne    124e <chronopic_open+0xfe>
movl   $0xffffffff,-0x4(%rbp)
jmp    127e <chronopic_open+0x12e>
mov    -0x3c(%rbp),%edi
mov    0x2d80(%rip),%rax
mov    (%rax),%esi
lea    -0x38(%rbp),%rdx
call   1050 <tcsetattr@plt>
cmp    $0xffffffff,%eax
jne    1278 <chronopic_open+0x128>
movl   $0xffffffff,-0x4(%rbp)
jmp    127e <chronopic_open+0x12e>
mov    -0x3c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<chronopic_open>:
push   %rax
mov    0x2ed0(%rip),%rax
mov    0x2eb9(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
call   1030 <open@plt>

LLVM IR (-O0):
%struct.termios = type { i32, i32*, i64, i64, i32 }
@O_RDWR = global i32 0
@O_NOCTTY = global i32 0
@CS8 = global i32 0
@CLOCAL = global i32 0
@CREAD = global i32 0
@IGNPAR = global i32 0
@VMIN = global i64 0
@VTIME = global i64 0
@B9600 = global i32 0
@TCIFLUSH = global i32 0
@TCOFLUSH = global i32 0
@TCSANOW = global i32 0
define i32 @chronopic_open(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca %struct.termios
%5 = alloca i32
store i8* %0, i8** %3
%6 = load i8*, i8** %3
%7 = load i32, i32* @O_RDWR
%8 = load i32, i32* @O_NOCTTY
%9 = or i32 %7, %8
%10 = call i32 @open(i8* %6, i32 %9)
store i32 %10, i32* %5
%11 = load i32, i32* @CS8
%12 = load i32, i32* @CLOCAL
%13 = or i32 %11, %12
%14 = load i32, i32* @CREAD
%15 = or i32 %13, %14
%16 = getelementptr inbounds %struct.termios, %struct.termios* %4, i32 0, i32 0
store i32 %15, i32* %16
%17 = load i32, i32* @IGNPAR
%18 = getelementptr inbounds %struct.termios, %struct.termios* %4, i32 0, i32 4
store i32 %17, i32* %18
%19 = getelementptr inbounds %struct.termios, %struct.termios* %4, i32 0, i32 3
store i64 0, i64* %19
%20 = getelementptr inbounds %struct.termios, %struct.termios* %4, i32 0, i32 2
store i64 0, i64* %20
%21 = getelementptr inbounds %struct.termios, %struct.termios* %4, i32 0, i32 1
%22 = load i32*, i32** %21
%23 = load i64, i64* @VMIN
%24 = getelementptr inbounds i32, i32* %22, i64 %23
store i32 1, i32* %24
%25 = getelementptr inbounds %struct.termios, %struct.termios* %4, i32 0, i32 1
%26 = load i32*, i32** %25
%27 = load i64, i64* @VTIME
%28 = getelementptr inbounds i32, i32* %26, i64 %27
store i32 0, i32* %28
%29 = load i32, i32* @B9600
%30 = call i32 @cfsetospeed(%struct.termios* %4, i32 %29)
%31 = load i32, i32* @B9600
%32 = call i32 @cfsetispeed(%struct.termios* %4, i32 %31)
%33 = load i32, i32* %5
%34 = load i32, i32* @TCIFLUSH
%35 = call i32 @tcflush(i32 %33, i32 %34)
%36 = icmp eq i32 %35, -1
br i1 %36, label %37, label %38
37: ; preds = %1
store i32 -1, i32* %2
br label %52
38: ; preds = %1
%39 = load i32, i32* %5
%40 = load i32, i32* @TCOFLUSH
%41 = call i32 @tcflush(i32 %39, i32 %40)
%42 = icmp eq i32 %41, -1
br i1 %42, label %43, label %44
43: ; preds = %38
store i32 -1, i32* %2
br label %52
44: ; preds = %38
%45 = load i32, i32* %5
%46 = load i32, i32* @TCSANOW
%47 = call i32 @tcsetattr(i32 %45, i32 %46, %struct.termios* %4)
%48 = icmp eq i32 %47, -1
br i1 %48, label %49, label %50
49: ; preds = %44
store i32 -1, i32* %2
br label %52
50: ; preds = %44
%51 = load i32, i32* %5
store i32 %51, i32* %2
br label %52
52: ; preds = %50, %49, %43, %37
%53 = load i32, i32* %2
ret i32 %53
}

LLVM IR (-O2):
@O_RDWR = global i32 0
@O_NOCTTY = global i32 0
@CS8 = global i32 0
@CLOCAL = global i32 0
@CREAD = global i32 0
@IGNPAR = global i32 0
@VMIN = global i64 0
@VTIME = global i64 0
@B9600 = global i32 0
@TCIFLUSH = global i32 0
@TCOFLUSH = global i32 0
@TCSANOW = global i32 0
define i32 @chronopic_open(i8* nocapture %0) {
%2 = load i32, i32* @O_RDWR
%3 = load i32, i32* @O_NOCTTY
%4 = or i32 %3, %2
%5 = tail call i32 @open(i8* %0, i32 %4)
unreachable
}