#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_cc;
  scalar_t__ c_lflag;
};

/* Variables and functions */
int /*<<< orphan*/ TCIFLUSH;
int /*<<< orphan*/ TCSANOW;
size_t VMIN;
size_t VTIME;
int fileno(int /*<<< orphan*/);
int /*<<< orphan*/ memcpy(struct termios *, struct termios *, int);
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ tcflush(int, int /*<<< orphan*/);
int /*<<< orphan*/ tcgetattr(int, struct termios *);
int /*<<< orphan*/ tcsetattr(int, int /*<<< orphan*/, struct termios *);
void openstdin(int *fd, struct termios *oldtio, struct termios *newtio) {
  *fd = fileno(stdin);
  tcgetattr(*fd, oldtio);
  memcpy(newtio, oldtio, sizeof(*oldtio));
  newtio->c_lflag = 0;
  newtio->c_cc[VTIME] = 0;
  newtio->c_cc[VMIN] = 1;
  tcflush(*fd, TCIFLUSH);
  tcsetattr(*fd, TCSANOW, newtio);
}


x86 assembly (clang, -O0):
<openstdin>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    0x2e7d(%rip),%rax
mov    (%rax),%edi
call   1050 <fileno@plt>
mov    %eax,%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x8(%rbp),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rsi
call   1060 <tcgetattr@plt>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    $0x10,%edx
call   1040 <memcpy@plt>
mov    -0x18(%rbp),%rax
movq   $0x0,0x8(%rax)
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
mov    0x2e0b(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x0,(%rax,%rcx,4)
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
mov    0x2e0b(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x1,(%rax,%rcx,4)
mov    -0x8(%rbp),%rax
mov    (%rax),%edi
mov    0x2de4(%rip),%rax
mov    (%rax),%esi
call   1030 <tcflush@plt>
mov    -0x8(%rbp),%rax
mov    (%rax),%edi
mov    0x2de8(%rip),%rax
mov    (%rax),%esi
mov    -0x18(%rbp),%rdx
call   1070 <tcsetattr@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<openstdin>:
push   %r15
push   %r14
push   %rbx
mov    %rdx,%rbx
mov    %rsi,%r15
mov    %rdi,%r14
mov    0x2e83(%rip),%rax
mov    (%rax),%edi
call   1050 <fileno@plt>
mov    %eax,(%r14)
mov    %eax,%edi
mov    %r15,%rsi
call   1060 <tcgetattr@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    $0x10,%edx
call   1040 <memcpy@plt>
movq   $0x0,0x8(%rbx)
mov    (%rbx),%rax
mov    0x2e25(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x0,(%rax,%rcx,4)
mov    0x2e2c(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x1,(%rax,%rcx,4)
mov    (%r14),%edi
mov    0x2e08(%rip),%rax
mov    (%rax),%esi
call   1030 <tcflush@plt>
mov    (%r14),%edi
mov    0x2e0f(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdx
pop    %rbx
pop    %r14
pop    %r15
jmp    1070 <tcsetattr@plt>

LLVM IR (-O0):
%struct.termios = type { i32*, i64 }
@stdin = global i32 0
@VTIME = global i64 0
@VMIN = global i64 0
@TCIFLUSH = global i32 0
@TCSANOW = global i32 0
define void @openstdin(i32* %0, %struct.termios* %1, %struct.termios* %2) {
%4 = alloca i32*
%5 = alloca %struct.termios*
%6 = alloca %struct.termios*
store i32* %0, i32** %4
store %struct.termios* %1, %struct.termios** %5
store %struct.termios* %2, %struct.termios** %6
%7 = load i32, i32* @stdin
%8 = call i32 @fileno(i32 %7)
%9 = load i32*, i32** %4
store i32 %8, i32* %9
%10 = load i32*, i32** %4
%11 = load i32, i32* %10
%12 = load %struct.termios*, %struct.termios** %5
%13 = call i32 @tcgetattr(i32 %11, %struct.termios* %12)
%14 = load %struct.termios*, %struct.termios** %6
%15 = load %struct.termios*, %struct.termios** %5
%16 = call i32 @memcpy(%struct.termios* %14, %struct.termios* %15, i32 16)
%17 = load %struct.termios*, %struct.termios** %6
%18 = getelementptr inbounds %struct.termios, %struct.termios* %17, i32 0, i32 1
store i64 0, i64* %18
%19 = load %struct.termios*, %struct.termios** %6
%20 = getelementptr inbounds %struct.termios, %struct.termios* %19, i32 0, i32 0
%21 = load i32*, i32** %20
%22 = load i64, i64* @VTIME
%23 = getelementptr inbounds i32, i32* %21, i64 %22
store i32 0, i32* %23
%24 = load %struct.termios*, %struct.termios** %6
%25 = getelementptr inbounds %struct.termios, %struct.termios* %24, i32 0, i32 0
%26 = load i32*, i32** %25
%27 = load i64, i64* @VMIN
%28 = getelementptr inbounds i32, i32* %26, i64 %27
store i32 1, i32* %28
%29 = load i32*, i32** %4
%30 = load i32, i32* %29
%31 = load i32, i32* @TCIFLUSH
%32 = call i32 @tcflush(i32 %30, i32 %31)
%33 = load i32*, i32** %4
%34 = load i32, i32* %33
%35 = load i32, i32* @TCSANOW
%36 = load %struct.termios*, %struct.termios** %6
%37 = call i32 @tcsetattr(i32 %34, i32 %35, %struct.termios* %36)
ret void
}

LLVM IR (-O2):
%struct.termios = type { i32*, i64 }
@stdin = global i32 0
@VTIME = global i64 0
@VMIN = global i64 0
@TCIFLUSH = global i32 0
@TCSANOW = global i32 0
define void @openstdin(i32* nocapture %0, %struct.termios* %1, %struct.termios* %2) {
%4 = load i32, i32* @stdin
%5 = tail call i32 @fileno(i32 %4)
store i32 %5, i32* %0
%6 = tail call i32 @tcgetattr(i32 %5, %struct.termios* %1)
%7 = tail call i32 @memcpy(%struct.termios* %2, %struct.termios* %1, i32 16)
%8 = getelementptr inbounds %struct.termios, %struct.termios* %2, i64 0, i32 1
store i64 0, i64* %8
%9 = getelementptr inbounds %struct.termios, %struct.termios* %2, i64 0, i32 0
%10 = load i32*, i32** %9
%11 = load i64, i64* @VTIME
%12 = getelementptr inbounds i32, i32* %10, i64 %11
store i32 0, i32* %12
%13 = load i64, i64* @VMIN
%14 = getelementptr inbounds i32, i32* %10, i64 %13
store i32 1, i32* %14
%15 = load i32, i32* %0
%16 = load i32, i32* @TCIFLUSH
%17 = tail call i32 @tcflush(i32 %15, i32 %16)
%18 = load i32, i32* %0
%19 = load i32, i32* @TCSANOW
%20 = tail call i32 @tcsetattr(i32 %18, i32 %19, %struct.termios* %2)
ret void
}