#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_oflag;
  int /*<<< orphan*/ c_iflag;
};
typedef int /*<<< orphan*/ newtio;

/* Variables and functions */
int B4800;
int CLOCAL;
int CREAD;
int CS8;
int /*<<< orphan*/ IGNPAR;
int O_NOCTTY;
int O_RDWR;
int /*<<< orphan*/ TCIFLUSH;
int /*<<< orphan*/ TCSANOW;
size_t VDISCARD;
size_t VEOF;
size_t VEOL;
size_t VEOL2;
size_t VERASE;
size_t VINTR;
size_t VKILL;
size_t VLNEXT;
size_t VMIN;
size_t VQUIT;
size_t VREPRINT;
size_t VSTART;
size_t VSTOP;
size_t VSUSP;
size_t VSWTC;
size_t VTIME;
size_t VWERASE;
int /*<<< orphan*/ bzero(struct termios *, int);
int /*<<< orphan*/ exit(int);
int open(char *, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ tcflush(int, int /*<<< orphan*/);
int /*<<< orphan*/ tcsetattr(int, int /*<<< orphan*/, struct termios *);
int open_input(char *input_dev) {
  int fd;
  struct termios newtio;
  printf("opening device '%s' for input\n", input_dev);
  fd = open(input_dev, O_RDWR | O_NOCTTY);
  if (fd < 0) {
    perror(input_dev);
    exit(-1);
  }
  bzero(&newtio, sizeof(newtio));
  newtio.c_cflag = B4800 | CS8 | CLOCAL | CREAD;
  newtio.c_iflag = IGNPAR;
  newtio.c_oflag = 0;
  newtio.c_cc[VINTR] = 0;
  newtio.c_cc[VQUIT] = 0;
  newtio.c_cc[VERASE] = 0;
  newtio.c_cc[VKILL] = 0;
  newtio.c_cc[VEOF] = 4;
  newtio.c_cc[VTIME] = 0;
  newtio.c_cc[VMIN] = 1;
  newtio.c_cc[VSWTC] = 0;
  newtio.c_cc[VSTART] = 0;
  newtio.c_cc[VSTOP] = 0;
  newtio.c_cc[VSUSP] = 0;
  newtio.c_cc[VEOL] = 0;
  newtio.c_cc[VREPRINT] = 0;
  newtio.c_cc[VDISCARD] = 0;
  newtio.c_cc[VWERASE] = 0;
  newtio.c_cc[VLNEXT] = 0;
  newtio.c_cc[VEOL2] = 0;
  tcflush(fd, TCIFLUSH);
  tcsetattr(fd, TCSANOW, &newtio);
  return fd;
}


x86 assembly (clang, -O0):
<open_input>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rsi
lea    0xe79(%rip),%rdi
call   1040 <printf@plt>
mov    -0x8(%rbp),%rdi
mov    0x2e51(%rip),%rax
mov    (%rax),%esi
mov    0x2dd0(%rip),%rax
or     (%rax),%esi
call   1060 <open@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jge    11c7 <open_input+0x57>
mov    -0x8(%rbp),%rdi
call   1070 <perror@plt>
mov    $0xffffffff,%edi
call   1090 <exit@plt>
lea    -0x30(%rbp),%rdi
mov    $0x20,%esi
call   1080 <bzero@plt>
mov    0x2dcc(%rip),%rax
mov    (%rax),%eax
mov    0x2dab(%rip),%rcx
or     (%rcx),%eax
mov    0x2d2a(%rip),%rcx
or     (%rcx),%eax
mov    0x2da1(%rip),%rcx
or     (%rcx),%eax
mov    %eax,-0x30(%rbp)
mov    0x2d45(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x28(%rbp),%rax
mov    0x2d15(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x0,(%rax,%rcx,4)
mov    -0x28(%rbp),%rax
mov    0x2d30(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x0,(%rax,%rcx,4)
mov    -0x28(%rbp),%rax
mov    0x2d73(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x0,(%rax,%rcx,4)
mov    -0x28(%rbp),%rax
mov    0x2d76(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x0,(%rax,%rcx,4)
mov    -0x28(%rbp),%rax
mov    0x2ca1(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x4,(%rax,%rcx,4)
mov    -0x28(%rbp),%rax
mov    0x2cd4(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x0,(%rax,%rcx,4)
mov    -0x28(%rbp),%rax
mov    0x2cef(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x1,(%rax,%rcx,4)
mov    -0x28(%rbp),%rax
mov    0x2ca2(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x0,(%rax,%rcx,4)
mov    -0x28(%rbp),%rax
mov    0x2c5d(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x0,(%rax,%rcx,4)
mov    -0x28(%rbp),%rax
mov    0x2cf0(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x0,(%rax,%rcx,4)
mov    -0x28(%rbp),%rax
mov    0x2c4b(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x0,(%rax,%rcx,4)
mov    -0x28(%rbp),%rax
mov    0x2c26(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x0,(%rax,%rcx,4)
mov    -0x28(%rbp),%rax
mov    0x2c89(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x0,(%rax,%rcx,4)
mov    -0x28(%rbp),%rax
mov    0x2c94(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x0,(%rax,%rcx,4)
mov    -0x28(%rbp),%rax
mov    0x2c97(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x0,(%rax,%rcx,4)
mov    -0x28(%rbp),%rax
mov    0x2c12(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x0,(%rax,%rcx,4)
mov    -0x28(%rbp),%rax
mov    0x2c75(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x0,(%rax,%rcx,4)
mov    -0xc(%rbp),%edi
mov    0x2bf9(%rip),%rax
mov    (%rax),%esi
call   1030 <tcflush@plt>
mov    -0xc(%rbp),%edi
mov    0x2c20(%rip),%rax
mov    (%rax),%esi
lea    -0x30(%rbp),%rdx
call   1050 <tcsetattr@plt>
mov    -0xc(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<open_input>:
push   %rbp
push   %r14
push   %rbx
sub    $0x20,%rsp
mov    %rdi,%rbx
lea    0xe7e(%rip),%rdi
mov    %rbx,%rsi
call   1040 <printf@plt>
mov    0x2e57(%rip),%rax
mov    0x2dd8(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    %rbx,%rdi
call   1060 <open@plt>
test   %eax,%eax
js     134f <open_input+0x1df>
mov    %eax,%ebp
mov    %rsp,%r14
mov    %r14,%rdi
mov    $0x20,%esi
call   1080 <bzero@plt>
mov    0x2de3(%rip),%rax
mov    0x2dc4(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
mov    0x2d41(%rip),%rax
or     (%rax),%ecx
mov    0x2db8(%rip),%rax
or     (%rax),%ecx
mov    %ecx,(%rsp)
mov    0x2d5c(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x18(%rsp)
movq   $0x0,0x10(%rsp)
mov    0x8(%rsp),%rax
mov    0x2d29(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x0,(%rax,%rcx,4)
mov    0x2d48(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x0,(%rax,%rcx,4)
mov    0x2d8f(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x0,(%rax,%rcx,4)
mov    0x2d96(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x0,(%rax,%rcx,4)
mov    0x2cc5(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x4,(%rax,%rcx,4)
mov    0x2cfc(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x0,(%rax,%rcx,4)
mov    0x2d1b(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x1,(%rax,%rcx,4)
mov    0x2cd2(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x0,(%rax,%rcx,4)
mov    0x2c91(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x0,(%rax,%rcx,4)
mov    0x2d28(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x0,(%rax,%rcx,4)
mov    0x2c87(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x0,(%rax,%rcx,4)
mov    0x2c66(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x0,(%rax,%rcx,4)
mov    0x2ccd(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x0,(%rax,%rcx,4)
mov    0x2cdc(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x0,(%rax,%rcx,4)
mov    0x2ce3(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x0,(%rax,%rcx,4)
mov    0x2c62(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x0,(%rax,%rcx,4)
mov    0x2cc9(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x0,(%rax,%rcx,4)
mov    0x2c50(%rip),%rax
mov    (%rax),%esi
mov    %ebp,%edi
call   1030 <tcflush@plt>
mov    0x2c78(%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
mov    %rbx,%rdi
call   1070 <perror@plt>
mov    $0xffffffff,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
%struct.termios = type { i32, i32*, i64, i32 }
@.str = [31 x i8] c"opening device '%s' for input\0A\00"
@O_RDWR = global i32 0
@O_NOCTTY = global i32 0
@B4800 = global i32 0
@CS8 = global i32 0
@CLOCAL = global i32 0
@CREAD = global i32 0
@IGNPAR = global i32 0
@VINTR = global i64 0
@VQUIT = global i64 0
@VERASE = global i64 0
@VKILL = global i64 0
@VEOF = global i64 0
@VTIME = global i64 0
@VMIN = global i64 0
@VSWTC = global i64 0
@VSTART = global i64 0
@VSTOP = global i64 0
@VSUSP = global i64 0
@VEOL = global i64 0
@VREPRINT = global i64 0
@VDISCARD = global i64 0
@VWERASE = global i64 0
@VLNEXT = global i64 0
@VEOL2 = global i64 0
@TCIFLUSH = global i32 0
@TCSANOW = global i32 0
define i32 @open_input(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca %struct.termios
store i8* %0, i8** %2
%5 = load i8*, i8** %2
%6 = call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i8* %5)
%7 = load i8*, i8** %2
%8 = load i32, i32* @O_RDWR
%9 = load i32, i32* @O_NOCTTY
%10 = or i32 %8, %9
%11 = call i32 @open(i8* %7, i32 %10)
store i32 %11, i32* %3
%12 = load i32, i32* %3
%13 = icmp slt i32 %12, 0
br i1 %13, label %14, label %18
14: ; preds = %1
%15 = load i8*, i8** %2
%16 = call i32 @perror(i8* %15)
%17 = call i32 @exit(i32 -1)
unreachable
18: ; preds = %1
%19 = call i32 @bzero(%struct.termios* %4, i32 32)
%20 = load i32, i32* @B4800
%21 = load i32, i32* @CS8
%22 = or i32 %20, %21
%23 = load i32, i32* @CLOCAL
%24 = or i32 %22, %23
%25 = load i32, i32* @CREAD
%26 = or i32 %24, %25
%27 = getelementptr inbounds %struct.termios, %struct.termios* %4, i32 0, i32 0
store i32 %26, i32* %27
%28 = load i32, i32* @IGNPAR
%29 = getelementptr inbounds %struct.termios, %struct.termios* %4, i32 0, i32 3
store i32 %28, i32* %29
%30 = getelementptr inbounds %struct.termios, %struct.termios* %4, i32 0, i32 2
store i64 0, i64* %30
%31 = getelementptr inbounds %struct.termios, %struct.termios* %4, i32 0, i32 1
%32 = load i32*, i32** %31
%33 = load i64, i64* @VINTR
%34 = getelementptr inbounds i32, i32* %32, i64 %33
store i32 0, i32* %34
%35 = getelementptr inbounds %struct.termios, %struct.termios* %4, i32 0, i32 1
%36 = load i32*, i32** %35
%37 = load i64, i64* @VQUIT
%38 = getelementptr inbounds i32, i32* %36, i64 %37
store i32 0, i32* %38
%39 = getelementptr inbounds %struct.termios, %struct.termios* %4, i32 0, i32 1
%40 = load i32*, i32** %39
%41 = load i64, i64* @VERASE
%42 = getelementptr inbounds i32, i32* %40, i64 %41
store i32 0, i32* %42
%43 = getelementptr inbounds %struct.termios, %struct.termios* %4, i32 0, i32 1
%44 = load i32*, i32** %43
%45 = load i64, i64* @VKILL
%46 = getelementptr inbounds i32, i32* %44, i64 %45
store i32 0, i32* %46
%47 = getelementptr inbounds %struct.termios, %struct.termios* %4, i32 0, i32 1
%48 = load i32*, i32** %47
%49 = load i64, i64* @VEOF
%50 = getelementptr inbounds i32, i32* %48, i64 %49
store i32 4, i32* %50
%51 = getelementptr inbounds %struct.termios, %struct.termios* %4, i32 0, i32 1
%52 = load i32*, i32** %51
%53 = load i64, i64* @VTIME
%54 = getelementptr inbounds i32, i32* %52, i64 %53
store i32 0, i32* %54
%55 = getelementptr inbounds %struct.termios, %struct.termios* %4, i32 0, i32 1
%56 = load i32*, i32** %55
%57 = load i64, i64* @VMIN
%58 = getelementptr inbounds i32, i32* %56, i64 %57
store i32 1, i32* %58
%59 = getelementptr inbounds %struct.termios, %struct.termios* %4, i32 0, i32 1
%60 = load i32*, i32** %59
%61 = load i64, i64* @VSWTC
%62 = getelementptr inbounds i32, i32* %60, i64 %61
store i32 0, i32* %62
%63 = getelementptr inbounds %struct.termios, %struct.termios* %4, i32 0, i32 1
%64 = load i32*, i32** %63
%65 = load i64, i64* @VSTART
%66 = getelementptr inbounds i32, i32* %64, i64 %65
store i32 0, i32* %66
%67 = getelementptr inbounds %struct.termios, %struct.termios* %4, i32 0, i32 1
%68 = load i32*, i32** %67
%69 = load i64, i64* @VSTOP
%70 = getelementptr inbounds i32, i32* %68, i64 %69
store i32 0, i32* %70
%71 = getelementptr inbounds %struct.termios, %struct.termios* %4, i32 0, i32 1
%72 = load i32*, i32** %71
%73 = load i64, i64* @VSUSP
%74 = getelementptr inbounds i32, i32* %72, i64 %73
store i32 0, i32* %74
%75 = getelementptr inbounds %struct.termios, %struct.termios* %4, i32 0, i32 1
%76 = load i32*, i32** %75
%77 = load i64, i64* @VEOL
%78 = getelementptr inbounds i32, i32* %76, i64 %77
store i32 0, i32* %78
%79 = getelementptr inbounds %struct.termios, %struct.termios* %4, i32 0, i32 1
%80 = load i32*, i32** %79
%81 = load i64, i64* @VREPRINT
%82 = getelementptr inbounds i32, i32* %80, i64 %81
store i32 0, i32* %82
%83 = getelementptr inbounds %struct.termios, %struct.termios* %4, i32 0, i32 1
%84 = load i32*, i32** %83
%85 = load i64, i64* @VDISCARD
%86 = getelementptr inbounds i32, i32* %84, i64 %85
store i32 0, i32* %86
%87 = getelementptr inbounds %struct.termios, %struct.termios* %4, i32 0, i32 1
%88 = load i32*, i32** %87
%89 = load i64, i64* @VWERASE
%90 = getelementptr inbounds i32, i32* %88, i64 %89
store i32 0, i32* %90
%91 = getelementptr inbounds %struct.termios, %struct.termios* %4, i32 0, i32 1
%92 = load i32*, i32** %91
%93 = load i64, i64* @VLNEXT
%94 = getelementptr inbounds i32, i32* %92, i64 %93
store i32 0, i32* %94
%95 = getelementptr inbounds %struct.termios, %struct.termios* %4, i32 0, i32 1
%96 = load i32*, i32** %95
%97 = load i64, i64* @VEOL2
%98 = getelementptr inbounds i32, i32* %96, i64 %97
store i32 0, i32* %98
%99 = load i32, i32* %3
%100 = load i32, i32* @TCIFLUSH
%101 = call i32 @tcflush(i32 %99, i32 %100)
%102 = load i32, i32* %3
%103 = load i32, i32* @TCSANOW
%104 = call i32 @tcsetattr(i32 %102, i32 %103, %struct.termios* %4)
%105 = load i32, i32* %3
ret i32 %105
}

LLVM IR (-O2):
%struct.termios = type { i32, i32*, i64, i32 }
@.str = [31 x i8] c"opening device '%s' for input\0A\00"
@O_RDWR = global i32 0
@O_NOCTTY = global i32 0
@B4800 = global i32 0
@CS8 = global i32 0
@CLOCAL = global i32 0
@CREAD = global i32 0
@IGNPAR = global i32 0
@VINTR = global i64 0
@VQUIT = global i64 0
@VERASE = global i64 0
@VKILL = global i64 0
@VEOF = global i64 0
@VTIME = global i64 0
@VMIN = global i64 0
@VSWTC = global i64 0
@VSTART = global i64 0
@VSTOP = global i64 0
@VSUSP = global i64 0
@VEOL = global i64 0
@VREPRINT = global i64 0
@VDISCARD = global i64 0
@VWERASE = global i64 0
@VLNEXT = global i64 0
@VEOL2 = global i64 0
@TCIFLUSH = global i32 0
@TCSANOW = global i32 0
define i32 @open_input(i8* %0) {
%2 = alloca %struct.termios
%3 = bitcast %struct.termios* %2 to i8*
%4 = tail call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i8* %0)
%5 = load i32, i32* @O_RDWR
%6 = load i32, i32* @O_NOCTTY
%7 = or i32 %6, %5
%8 = tail call i32 @open(i8* %0, i32 %7)
%9 = icmp slt i32 %8, 0
br i1 %9, label %10, label %13
10: ; preds = %1
%11 = tail call i32 @perror(i8* %0)
%12 = tail call i32 @exit(i32 -1)
unreachable
13: ; preds = %1
%14 = call i32 @bzero(%struct.termios* %2, i32 32)
%15 = load i32, i32* @B4800
%16 = load i32, i32* @CS8
%17 = or i32 %16, %15
%18 = load i32, i32* @CLOCAL
%19 = or i32 %17, %18
%20 = load i32, i32* @CREAD
%21 = or i32 %19, %20
%22 = getelementptr inbounds %struct.termios, %struct.termios* %2, i64 0, i32 0
store i32 %21, i32* %22
%23 = load i32, i32* @IGNPAR
%24 = getelementptr inbounds %struct.termios, %struct.termios* %2, i64 0, i32 3
store i32 %23, i32* %24
%25 = getelementptr inbounds %struct.termios, %struct.termios* %2, i64 0, i32 2
store i64 0, i64* %25
%26 = getelementptr inbounds %struct.termios, %struct.termios* %2, i64 0, i32 1
%27 = load i32*, i32** %26
%28 = load i64, i64* @VINTR
%29 = getelementptr inbounds i32, i32* %27, i64 %28
store i32 0, i32* %29
%30 = load i64, i64* @VQUIT
%31 = getelementptr inbounds i32, i32* %27, i64 %30
store i32 0, i32* %31
%32 = load i64, i64* @VERASE
%33 = getelementptr inbounds i32, i32* %27, i64 %32
store i32 0, i32* %33
%34 = load i64, i64* @VKILL
%35 = getelementptr inbounds i32, i32* %27, i64 %34
store i32 0, i32* %35
%36 = load i64, i64* @VEOF
%37 = getelementptr inbounds i32, i32* %27, i64 %36
store i32 4, i32* %37
%38 = load i64, i64* @VTIME
%39 = getelementptr inbounds i32, i32* %27, i64 %38
store i32 0, i32* %39
%40 = load i64, i64* @VMIN
%41 = getelementptr inbounds i32, i32* %27, i64 %40
store i32 1, i32* %41
%42 = load i64, i64* @VSWTC
%43 = getelementptr inbounds i32, i32* %27, i64 %42
store i32 0, i32* %43
%44 = load i64, i64* @VSTART
%45 = getelementptr inbounds i32, i32* %27, i64 %44
store i32 0, i32* %45
%46 = load i64, i64* @VSTOP
%47 = getelementptr inbounds i32, i32* %27, i64 %46
store i32 0, i32* %47
%48 = load i64, i64* @VSUSP
%49 = getelementptr inbounds i32, i32* %27, i64 %48
store i32 0, i32* %49
%50 = load i64, i64* @VEOL
%51 = getelementptr inbounds i32, i32* %27, i64 %50
store i32 0, i32* %51
%52 = load i64, i64* @VREPRINT
%53 = getelementptr inbounds i32, i32* %27, i64 %52
store i32 0, i32* %53
%54 = load i64, i64* @VDISCARD
%55 = getelementptr inbounds i32, i32* %27, i64 %54
store i32 0, i32* %55
%56 = load i64, i64* @VWERASE
%57 = getelementptr inbounds i32, i32* %27, i64 %56
store i32 0, i32* %57
%58 = load i64, i64* @VLNEXT
%59 = getelementptr inbounds i32, i32* %27, i64 %58
store i32 0, i32* %59
%60 = load i64, i64* @VEOL2
%61 = getelementptr inbounds i32, i32* %27, i64 %60
store i32 0, i32* %61
%62 = load i32, i32* @TCIFLUSH
%63 = tail call i32 @tcflush(i32 %8, i32 %62)
%64 = load i32, i32* @TCSANOW
%65 = call i32 @tcsetattr(i32 %8, i32 %64, %struct.termios* %2)
ret i32 %8
}