#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 */

/* Variables and functions */
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, char *);
int /*<<< orphan*/ free(char *);
int getline(char **, size_t *, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ stdout;
int yesno(char *prompt, int expect) {
  char *line, *pr2;
  int i;
  size_t n;
  int ret;
  if (expect)
    pr2 = "[Y/n]";
  else
    pr2 = "[N/y]";
  fflush(stdout);
  do {
    fprintf(stderr, "%s%s", prompt, pr2);
    fflush(stderr);
    n = ret = 0;
    line = NULL;
    i = getline(&line, &n, stdin);
    if (i < 0)
      exit(1);
    if (i == 1)
      ret = expect | 2;
    if (i > 1) {
      if (*line == 'y' || *line == 'Y')
        ret = 1;
      if (*line == 'n' || *line == 'N')
        ret = 2;
    }
    if (ret)
      break;
    if (line)
      free(line);
  } while (1);
  return ret & 1;
}


x86 assembly (clang, -O0):
<yesno>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
je     1179 <yesno+0x29>
lea    0xe90(%rip),%rax
mov    %rax,-0x20(%rbp)
jmp    1184 <yesno+0x34>
lea    0xe86(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    0x2e45(%rip),%rax
mov    (%rax),%edi
call   1050 <fflush@plt>
mov    0x2e3f(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
mov    -0x20(%rbp),%rcx
lea    0xe62(%rip),%rsi
call   1040 <fprintf@plt>
mov    0x2e22(%rip),%rax
mov    (%rax),%edi
call   1050 <fflush@plt>
movl   $0x0,-0x34(%rbp)
movq   $0x0,-0x30(%rbp)
movq   $0x0,-0x18(%rbp)
mov    0x2e0d(%rip),%rax
mov    (%rax),%edx
lea    -0x18(%rbp),%rdi
lea    -0x30(%rbp),%rsi
call   1060 <getline@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jge    1201 <yesno+0xb1>
mov    $0x1,%edi
call   1070 <exit@plt>
cmpl   $0x1,-0x24(%rbp)
jne    1214 <yesno+0xc4>
mov    -0xc(%rbp),%eax
or     $0x2,%eax
mov    %eax,-0x34(%rbp)
cmpl   $0x1,-0x24(%rbp)
jle    1271 <yesno+0x121>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x79,%eax
je     123e <yesno+0xee>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x59,%eax
jne    1245 <yesno+0xf5>
movl   $0x1,-0x34(%rbp)
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x6e,%eax
je     1265 <yesno+0x115>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x4e,%eax
jne    126c <yesno+0x11c>
movl   $0x2,-0x34(%rbp)
jmp    1271 <yesno+0x121>
cmpl   $0x0,-0x34(%rbp)
je     1280 <yesno+0x130>
jmp    12a8 <yesno+0x158>
cmpq   $0x0,-0x18(%rbp)
je     1294 <yesno+0x144>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
jmp    1299 <yesno+0x149>
mov    $0x1,%al
test   $0x1,%al
jne    1192 <yesno+0x42>
jmp    12a8 <yesno+0x158>
mov    -0x34(%rbp),%eax
and    $0x1,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<yesno>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %esi,%ebx
mov    %rdi,%r14
test   %esi,%esi
lea    0xe9a(%rip),%rax
lea    0xe8d(%rip),%r15
cmove  %rax,%r15
mov    0x2e52(%rip),%rax
mov    (%rax),%edi
call   1050 <fflush@plt>
or     $0x2,%ebx
mov    0x2e49(%rip),%r12
lea    0x8(%rsp),%r13
lea    0x10(%rsp),%rbp
nopl   0x0(%rax)
mov    (%r12),%edi
lea    0xe61(%rip),%rsi
mov    %r14,%rdx
mov    %r15,%rcx
call   1040 <fprintf@plt>
mov    (%r12),%edi
call   1050 <fflush@plt>
movq   $0x0,0x10(%rsp)
movq   $0x0,0x8(%rsp)
mov    0x2e10(%rip),%rax
mov    (%rax),%edx
mov    %r13,%rdi
mov    %rbp,%rsi
call   1060 <getline@plt>
test   %eax,%eax
js     1241 <yesno+0xf1>
mov    %eax,%ecx
mov    $0x0,%eax
cmp    $0x1,%ecx
cmove  %ebx,%eax
jbe    1212 <yesno+0xc2>
mov    0x8(%rsp),%rcx
movzbl (%rcx),%ecx
or     $0x20,%cl
cmp    $0x79,%cl
jne    120d <yesno+0xbd>
mov    $0x1,%eax
cmp    $0x6e,%cl
je     122a <yesno+0xda>
test   %eax,%eax
jne    122f <yesno+0xdf>
mov    0x8(%rsp),%rdi
test   %rdi,%rdi
je     11a0 <yesno+0x50>
call   1030 <free@plt>
jmp    11a0 <yesno+0x50>
mov    $0x2,%eax
and    $0x1,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    $0x1,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [6 x i8] c"[Y/n]\00"
@.str.1 = [6 x i8] c"[N/y]\00"
@stdout = global i32 0
@stderr = global i32 0
@.str.2 = [5 x i8] c"%s%s\00"
@stdin = global i32 0
define i32 @yesno(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i64
%9 = alloca i32
store i8* %0, i8** %3
store i32 %1, i32* %4
%10 = load i32, i32* %4
%11 = icmp ne i32 %10, 0
br i1 %11, label %12, label %13
12: ; preds = %2
store i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8** %6
br label %14
13: ; preds = %2
store i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8** %6
br label %14
14: ; preds = %13, %12
%15 = load i32, i32* @stdout
%16 = call i32 @fflush(i32 %15)
br label %17
17: ; preds = %73, %14
%18 = load i32, i32* @stderr
%19 = load i8*, i8** %3
%20 = load i8*, i8** %6
%21 = call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* %19, i8* %20)
%22 = load i32, i32* @stderr
%23 = call i32 @fflush(i32 %22)
store i32 0, i32* %9
store i64 0, i64* %8
store i8* null, i8** %5
%24 = load i32, i32* @stdin
%25 = call i32 @getline(i8** %5, i64* %8, i32 %24)
store i32 %25, i32* %7
%26 = load i32, i32* %7
%27 = icmp slt i32 %26, 0
br i1 %27, label %28, label %30
28: ; preds = %17
%29 = call i32 @exit(i32 1)
unreachable
30: ; preds = %17
%31 = load i32, i32* %7
%32 = icmp eq i32 %31, 1
br i1 %32, label %33, label %36
33: ; preds = %30
%34 = load i32, i32* %4
%35 = or i32 %34, 2
store i32 %35, i32* %9
br label %36
36: ; preds = %33, %30
%37 = load i32, i32* %7
%38 = icmp sgt i32 %37, 1
br i1 %38, label %39, label %62
39: ; preds = %36
%40 = load i8*, i8** %5
%41 = load i8, i8* %40
%42 = sext i8 %41 to i32
%43 = icmp eq i32 %42, 121
br i1 %43, label %49, label %44
44: ; preds = %39
%45 = load i8*, i8** %5
%46 = load i8, i8* %45
%47 = sext i8 %46 to i32
%48 = icmp eq i32 %47, 89
br i1 %48, label %49, label %50
49: ; preds = %44, %39
store i32 1, i32* %9
br label %50
50: ; preds = %49, %44
%51 = load i8*, i8** %5
%52 = load i8, i8* %51
%53 = sext i8 %52 to i32
%54 = icmp eq i32 %53, 110
br i1 %54, label %60, label %55
55: ; preds = %50
%56 = load i8*, i8** %5
%57 = load i8, i8* %56
%58 = sext i8 %57 to i32
%59 = icmp eq i32 %58, 78
br i1 %59, label %60, label %61
60: ; preds = %55, %50
store i32 2, i32* %9
br label %61
61: ; preds = %60, %55
br label %62
62: ; preds = %61, %36
%63 = load i32, i32* %9
%64 = icmp ne i32 %63, 0
br i1 %64, label %65, label %66
65: ; preds = %62
br label %74
66: ; preds = %62
%67 = load i8*, i8** %5
%68 = icmp ne i8* %67, null
br i1 %68, label %69, label %72
69: ; preds = %66
%70 = load i8*, i8** %5
%71 = call i32 @free(i8* %70)
br label %72
72: ; preds = %69, %66
br label %73
73: ; preds = %72
br i1 true, label %17, label %74
74: ; preds = %73, %65
%75 = load i32, i32* %9
%76 = and i32 %75, 1
ret i32 %76
}

LLVM IR (-O2):
@.str = [6 x i8] c"[Y/n]\00"
@.str.1 = [6 x i8] c"[N/y]\00"
@stdout = global i32 0
@stderr = global i32 0
@.str.2 = [5 x i8] c"%s%s\00"
@stdin = global i32 0
define i32 @yesno(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i64
%5 = bitcast i8** %3 to i8*
%6 = bitcast i64* %4 to i8*
%7 = icmp eq i32 %1, 0
%8 = select i1 %7, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0)
%9 = load i32, i32* @stdout
%10 = tail call i32 @fflush(i32 %9)
%11 = or i32 %1, 2
br label %12
12: ; preds = %38, %2
%13 = load i32, i32* @stderr
%14 = call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* %0, i8* %8)
%15 = load i32, i32* @stderr
%16 = call i32 @fflush(i32 %15)
store i64 0, i64* %4
store i8* null, i8** %3
%17 = load i32, i32* @stdin
%18 = call i32 @getline(i8** %3, i64* %4, i32 %17)
%19 = icmp slt i32 %18, 0
br i1 %19, label %20, label %22
20: ; preds = %12
%21 = call i32 @exit(i32 1)
unreachable
22: ; preds = %12
%23 = icmp eq i32 %18, 1
%24 = select i1 %23, i32 %11, i32 0
%25 = icmp ugt i32 %18, 1
br i1 %25, label %26, label %32
26: ; preds = %22
%27 = load i8*, i8** %3
%28 = load i8, i8* %27
switch i8 %28, label %30 [
i8 121, label %29
i8 89, label %29
]
29: ; preds = %26, %26
br label %30
30: ; preds = %26, %29
%31 = phi i32 [ 1, %29 ], [ %24, %26 ]
switch i8 %28, label %32 [
i8 110, label %41
i8 78, label %41
]
32: ; preds = %30, %22
%33 = phi i32 [ %24, %22 ], [ %31, %30 ]
%34 = icmp eq i32 %33, 0
br i1 %34, label %35, label %41
35: ; preds = %32
%36 = load i8*, i8** %3
%37 = icmp eq i8* %36, null
br i1 %37, label %38, label %39
38: ; preds = %35, %39
br label %12
39: ; preds = %35
%40 = call i32 @free(i8* %36)
br label %38
41: ; preds = %30, %30, %32
%42 = phi i32 [ %33, %32 ], [ 2, %30 ], [ 2, %30 ]
%43 = and i32 %42, 1
ret i32 %43
}