#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 */
typedef int /*<<< orphan*/ va_list;

/* Variables and functions */
int ask_yn(char const *);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ printf(char *);
int readline(char **);
int /*<<< orphan*/ stdout;
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char const *);
scalar_t__ strlen(char const *);
int /*<<< orphan*/ vfprintf(int /*<<< orphan*/, char *, int /*<<< orphan*/);
bool vask_yn(const char *q, va_list chars) {
  char format[strlen(q) + strlen(" (y/n) ") + 1];
  strcpy(format, q);
  strcat(format, " (y/n) ");
  vfprintf(stdout, format, chars);
  char *resp = NULL;
  int linesize = readline(&resp);
  bool ret = -1;
  if (linesize == 2) {
    if (resp[0] == 'n') {
      ret = false;
    } else if (resp[0] == 'y') {
      ret = true;
    } else {
      printf("invalid input\n");
      ret = ask_yn(q);
    }
  } else {
    printf("invalid input\n");
    ret = ask_yn(q);
  }
  free(resp);
  return ret;
}


x86 assembly (clang, -O0):
<vask_yn>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
call   1060 <strlen@plt>
mov    %rax,-0x40(%rbp)
lea    0xe5d(%rip),%rdi
call   1060 <strlen@plt>
mov    -0x40(%rbp),%rcx
mov    %rax,%rdx
lea    0x1(%rcx,%rdx,1),%rax
mov    %rsp,%rsi
mov    %rsi,-0x18(%rbp)
lea    0x10(%rcx,%rdx,1),%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x38(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rsi
call   1050 <strcpy@plt>
mov    -0x38(%rbp),%rdi
lea    0xe17(%rip),%rsi
call   10a0 <strcat@plt>
mov    -0x38(%rbp),%rsi
mov    0x2de7(%rip),%rax
mov    (%rax),%edi
mov    -0xc(%rbp),%edx
call   1090 <vfprintf@plt>
movq   $0x0,-0x28(%rbp)
lea    -0x28(%rbp),%rdi
call   1080 <readline@plt>
mov    %eax,-0x2c(%rbp)
movl   $0xffffffff,-0x30(%rbp)
cmpl   $0x2,-0x2c(%rbp)
jne    1282 <vask_yn+0x102>
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x6e,%eax
jne    1244 <vask_yn+0xc4>
movl   $0x0,-0x30(%rbp)
jmp    127d <vask_yn+0xfd>
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x79,%eax
jne    1260 <vask_yn+0xe0>
movl   $0x1,-0x30(%rbp)
jmp    1278 <vask_yn+0xf8>
lea    0xda1(%rip),%rdi
call   1070 <printf@plt>
mov    -0x8(%rbp),%rdi
call   1040 <ask_yn@plt>
mov    %eax,-0x30(%rbp)
jmp    127d <vask_yn+0xfd>
jmp    129a <vask_yn+0x11a>
lea    0xd7f(%rip),%rdi
call   1070 <printf@plt>
mov    -0x8(%rbp),%rdi
call   1040 <ask_yn@plt>
mov    %eax,-0x30(%rbp)
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x30(%rbp),%eax
mov    -0x18(%rbp),%rcx
mov    %rcx,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<vask_yn>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %esi,%r14d
mov    %rdi,%r15
call   1070 <strlen@plt>
mov    %rsp,%rbx
add    $0x17,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
mov    %rbx,%rdi
mov    %r15,%rsi
call   1050 <strcpy@plt>
lea    0xe48(%rip),%rsi
mov    %rbx,%rdi
call   10a0 <strcat@plt>
mov    0x2e19(%rip),%rax
mov    (%rax),%edi
mov    %rbx,%rsi
mov    %r14d,%edx
call   1090 <vfprintf@plt>
movq   $0x0,-0x20(%rbp)
lea    -0x20(%rbp),%rdi
call   1080 <readline@plt>
cmp    $0x2,%eax
jne    11ff <vask_yn+0x7f>
mov    -0x20(%rbp),%rax
mov    (%rax),%al
cmp    $0x6e,%al
je     1217 <vask_yn+0x97>
cmp    $0x79,%al
jne    11ff <vask_yn+0x7f>
mov    $0x1,%ebx
jmp    1219 <vask_yn+0x99>
lea    0xe02(%rip),%rdi
call   1060 <puts@plt>
mov    %r15,%rdi
call   1040 <ask_yn@plt>
mov    %eax,%ebx
jmp    1219 <vask_yn+0x99>
xor    %ebx,%ebx
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    %ebx,%eax
lea    -0x18(%rbp),%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [8 x i8] c" (y/n) \00"
@stdout = global i32 0
@.str.1 = [15 x i8] c"invalid input\0A\00"
define i32 @vask_yn(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
store i8* %0, i8** %3
store i32 %1, i32* %4
%10 = load i8*, i8** %3
%11 = call i64 @strlen(i8* %10)
%12 = call i64 @strlen(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%13 = add nsw i64 %11, %12
%14 = add nsw i64 %13, 1
%15 = call i8* @llvm.stacksave()
store i8* %15, i8** %5
%16 = alloca i8, i64 %14
store i64 %14, i64* %6
%17 = load i8*, i8** %3
%18 = call i32 @strcpy(i8* %16, i8* %17)
%19 = call i32 @strcat(i8* %16, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%20 = load i32, i32* @stdout
%21 = load i32, i32* %4
%22 = call i32 @vfprintf(i32 %20, i8* %16, i32 %21)
store i8* null, i8** %7
%23 = call i32 @readline(i8** %7)
store i32 %23, i32* %8
store i32 -1, i32* %9
%24 = load i32, i32* %8
%25 = icmp eq i32 %24, 2
br i1 %25, label %26, label %46
26: ; preds = %2
%27 = load i8*, i8** %7
%28 = getelementptr inbounds i8, i8* %27, i64 0
%29 = load i8, i8* %28
%30 = sext i8 %29 to i32
%31 = icmp eq i32 %30, 110
br i1 %31, label %32, label %33
32: ; preds = %26
store i32 0, i32* %9
br label %45
33: ; preds = %26
%34 = load i8*, i8** %7
%35 = getelementptr inbounds i8, i8* %34, i64 0
%36 = load i8, i8* %35
%37 = sext i8 %36 to i32
%38 = icmp eq i32 %37, 121
br i1 %38, label %39, label %40
39: ; preds = %33
store i32 1, i32* %9
br label %44
40: ; preds = %33
%41 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
%42 = load i8*, i8** %3
%43 = call i32 @ask_yn(i8* %42)
store i32 %43, i32* %9
br label %44
44: ; preds = %40, %39
br label %45
45: ; preds = %44, %32
br label %50
46: ; preds = %2
%47 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
%48 = load i8*, i8** %3
%49 = call i32 @ask_yn(i8* %48)
store i32 %49, i32* %9
br label %50
50: ; preds = %46, %45
%51 = load i8*, i8** %7
%52 = call i32 @free(i8* %51)
%53 = load i32, i32* %9
%54 = load i8*, i8** %5
ret i32 %53
}

LLVM IR (-O2):
@.str = [8 x i8] c" (y/n) \00"
@stdout = global i32 0
@str.2 = [14 x i8] c"invalid input\00"
define i32 @vask_yn(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%5 = add nsw i64 %4, 8
%6 = alloca i8, i64 %5
%7 = call i32 @strcpy(i8* %6, i8* %0)
%8 = call i32 @strcat(i8* %6, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%9 = load i32, i32* @stdout
%10 = call i32 @vfprintf(i32 %9, i8* %6, i32 %1)
%11 = bitcast i8** %3 to i8*
store i8* null, i8** %3
%12 = call i32 @readline(i8** %3)
%13 = icmp eq i32 %12, 2
br i1 %13, label %14, label %21
14: ; preds = %2
%15 = load i8*, i8** %3
%16 = load i8, i8* %15
switch i8 %16, label %18 [
i8 110, label %24
i8 121, label %17
]
17: ; preds = %14
br label %24
18: ; preds = %14
%19 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @str.2, i64 0, i64 0))
%20 = call i32 @ask_yn(i8* %0)
br label %24
21: ; preds = %2
%22 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @str.2, i64 0, i64 0))
%23 = call i32 @ask_yn(i8* %0)
br label %24
24: ; preds = %14, %18, %17, %21
%25 = phi i32 [ 1, %17 ], [ %20, %18 ], [ %23, %21 ], [ 0, %14 ]
%26 = load i8*, i8** %3
%27 = call i32 @free(i8* %26)
ret i32 %25
}