#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_lflag;
};

/* Variables and functions */
int ECHO;
int ICANON;
int /*<<< orphan*/ STDIN_FILENO;
int /*<<< orphan*/ TCSANOW;
int getchar();
int /*<<< orphan*/ putchar(char);
int /*<<< orphan*/ tcgetattr(int /*<<< orphan*/, struct termios *);
int /*<<< orphan*/ tcsetattr(int /*<<< orphan*/, int /*<<< orphan*/,
                             struct termios *);
int read_yes_no() {
  struct termios oldt, newt;
  tcgetattr(STDIN_FILENO, &oldt);
  newt = oldt;
  newt.c_lflag &= ~(ICANON | ECHO);
  tcsetattr(STDIN_FILENO, TCSANOW, &newt);
  int c;
  for (c = getchar();; c = getchar())
    if (c == 'y' || c == 'Y') {
      c = 1;
      break;
    } else if (c == 'n' || c == 'N') {
      c = 0;
      break;
    }
  tcsetattr(STDIN_FILENO, TCSANOW, &oldt);
  putchar('\n');
  return c;
}


x86 assembly (clang, -O0):
<read_yes_no>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    0x2e81(%rip),%rax
mov    (%rax),%edi
lea    -0x8(%rbp),%rsi
call   1050 <tcgetattr@plt>
mov    -0x8(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    0x2e61(%rip),%rax
mov    (%rax),%eax
mov    0x2e70(%rip),%rcx
or     (%rcx),%eax
xor    $0xffffffff,%eax
and    -0x10(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    0x2e4e(%rip),%rax
mov    (%rax),%edi
mov    0x2e5d(%rip),%rax
mov    (%rax),%esi
lea    -0x10(%rbp),%rdx
call   1060 <tcsetattr@plt>
mov    $0x0,%al
call   1040 <getchar@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x79,-0x14(%rbp)
je     11b4 <read_yes_no+0x74>
cmpl   $0x59,-0x14(%rbp)
jne    11c0 <read_yes_no+0x80>
movl   $0x1,-0x14(%rbp)
jmp    11f9 <read_yes_no+0xb9>
cmpl   $0x6e,-0x14(%rbp)
je     11d4 <read_yes_no+0x94>
cmpl   $0x4e,-0x14(%rbp)
jne    11e0 <read_yes_no+0xa0>
movl   $0x0,-0x14(%rbp)
jmp    11f9 <read_yes_no+0xb9>
jmp    11e5 <read_yes_no+0xa5>
jmp    11ea <read_yes_no+0xaa>
mov    $0x0,%al
call   1040 <getchar@plt>
mov    %eax,-0x14(%rbp)
jmp    11a0 <read_yes_no+0x60>
mov    0x2dd0(%rip),%rax
mov    (%rax),%edi
mov    0x2ddf(%rip),%rax
mov    (%rax),%esi
lea    -0x8(%rbp),%rdx
call   1060 <tcsetattr@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    -0x14(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_yes_no>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    0x2e80(%rip),%r14
mov    (%r14),%edi
mov    %rsp,%rsi
call   1050 <tcgetattr@plt>
mov    0x2e66(%rip),%rax
mov    0x2e77(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
not    %ecx
and    (%rsp),%ecx
mov    %ecx,0x8(%rsp)
mov    (%r14),%edi
mov    0x2e68(%rip),%r15
mov    (%r15),%esi
lea    0x8(%rsp),%rdx
call   1060 <tcsetattr@plt>
nopl   (%rax)
xor    %eax,%eax
call   1040 <getchar@plt>
and    $0xffffffdf,%eax
cmp    $0x4e,%eax
je     11ab <read_yes_no+0x6b>
cmp    $0x59,%eax
jne    1190 <read_yes_no+0x50>
mov    $0x1,%ebx
jmp    11ad <read_yes_no+0x6d>
xor    %ebx,%ebx
mov    (%r14),%edi
mov    (%r15),%esi
mov    %rsp,%rdx
call   1060 <tcsetattr@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.termios = type { i32 }
@STDIN_FILENO = global i32 0
@ICANON = global i32 0
@ECHO = global i32 0
@TCSANOW = global i32 0
define i32 @read_yes_no() {
%1 = alloca %struct.termios
%2 = alloca %struct.termios
%3 = alloca i32
%4 = load i32, i32* @STDIN_FILENO
%5 = call i32 @tcgetattr(i32 %4, %struct.termios* %1)
%6 = bitcast %struct.termios* %2 to i8*
%7 = bitcast %struct.termios* %1 to i8*
%8 = load i32, i32* @ICANON
%9 = load i32, i32* @ECHO
%10 = or i32 %8, %9
%11 = xor i32 %10, -1
%12 = getelementptr inbounds %struct.termios, %struct.termios* %2, i32 0, i32 0
%13 = load i32, i32* %12
%14 = and i32 %13, %11
store i32 %14, i32* %12
%15 = load i32, i32* @STDIN_FILENO
%16 = load i32, i32* @TCSANOW
%17 = call i32 @tcsetattr(i32 %15, i32 %16, %struct.termios* %2)
%18 = call i32 (...) @getchar()
store i32 %18, i32* %3
br label %19
19: ; preds = %35, %0
%20 = load i32, i32* %3
%21 = icmp eq i32 %20, 121
br i1 %21, label %25, label %22
22: ; preds = %19
%23 = load i32, i32* %3
%24 = icmp eq i32 %23, 89
br i1 %24, label %25, label %26
25: ; preds = %22, %19
store i32 1, i32* %3
br label %37
26: ; preds = %22
%27 = load i32, i32* %3
%28 = icmp eq i32 %27, 110
br i1 %28, label %32, label %29
29: ; preds = %26
%30 = load i32, i32* %3
%31 = icmp eq i32 %30, 78
br i1 %31, label %32, label %33
32: ; preds = %29, %26
store i32 0, i32* %3
br label %37
33: ; preds = %29
br label %34
34: ; preds = %33
br label %35
35: ; preds = %34
%36 = call i32 (...) @getchar()
store i32 %36, i32* %3
br label %19
37: ; preds = %32, %25
%38 = load i32, i32* @STDIN_FILENO
%39 = load i32, i32* @TCSANOW
%40 = call i32 @tcsetattr(i32 %38, i32 %39, %struct.termios* %1)
%41 = call i32 @putchar(i8 signext 10)
%42 = load i32, i32* %3
ret i32 %42
}

LLVM IR (-O2):
%struct.termios = type { i32 }
@STDIN_FILENO = global i32 0
@ICANON = global i32 0
@ECHO = global i32 0
@TCSANOW = global i32 0
define i32 @read_yes_no() {
%1 = alloca %struct.termios
%2 = alloca %struct.termios
%3 = bitcast %struct.termios* %1 to i8*
%4 = bitcast %struct.termios* %2 to i8*
%5 = load i32, i32* @STDIN_FILENO
%6 = call i32 @tcgetattr(i32 %5, %struct.termios* %1)
%7 = getelementptr inbounds %struct.termios, %struct.termios* %1, i64 0, i32 0
%8 = getelementptr inbounds %struct.termios, %struct.termios* %2, i64 0, i32 0
%9 = load i32, i32* %7
%10 = load i32, i32* @ICANON
%11 = load i32, i32* @ECHO
%12 = or i32 %11, %10
%13 = xor i32 %12, -1
%14 = and i32 %9, %13
store i32 %14, i32* %8
%15 = load i32, i32* @STDIN_FILENO
%16 = load i32, i32* @TCSANOW
%17 = call i32 @tcsetattr(i32 %15, i32 %16, %struct.termios* %2)
br label %18
18: ; preds = %18, %0
%19 = call i32 (...) @getchar()
%20 = and i32 %19, -33
switch i32 %20, label %18 [
i32 89, label %21
i32 78, label %22
]
21: ; preds = %18
br label %22
22: ; preds = %18, %21
%23 = phi i32 [ 1, %21 ], [ 0, %18 ]
%24 = load i32, i32* @STDIN_FILENO
%25 = load i32, i32* @TCSANOW
%26 = call i32 @tcsetattr(i32 %24, i32 %25, %struct.termios* %1)
%27 = call i32 @putchar(i8 signext 10)
ret i32 %23
}