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

/* Variables and functions */
char *clean_string(char *);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stdin;
int strlen(char *);
int tolower(char);
int ask_yn(char *prompt, int the_default, int *out) {
  char buffer[16];
  char *clean;
  *out = -1;
  while (1) {
    printf("%s", prompt);
    if (!fgets(buffer, sizeof(buffer), stdin))
      return -1;
    clean = clean_string(buffer);
    if (strlen(clean) < 1) {
      *out = the_default;
      return 0;
    }
    switch (tolower(clean[0])) {
    case 'y':
      *out = 1;
      return 0;
    case 'n':
      *out = 0;
      return 0;
    }
    printf("Please type either yes or no.\n");
  }
}


x86 assembly (clang, -O0):
<ask_yn>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x20(%rbp),%rax
movl   $0xffffffff,(%rax)
mov    -0x10(%rbp),%rsi
lea    0xe88(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x30(%rbp),%rdi
mov    0x2e5e(%rip),%rax
mov    (%rax),%edx
mov    $0x10,%esi
call   1060 <fgets@plt>
cmp    $0x0,%eax
jne    11ab <ask_yn+0x5b>
movl   $0xffffffff,-0x4(%rbp)
jmp    124e <ask_yn+0xfe>
lea    -0x30(%rbp),%rdi
call   1050 <clean_string@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rdi
call   1030 <strlen@plt>
cmp    $0x1,%eax
jge    11df <ask_yn+0x8f>
mov    -0x14(%rbp),%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
movl   $0x0,-0x4(%rbp)
jmp    124e <ask_yn+0xfe>
mov    -0x38(%rbp),%rax
movsbl (%rax),%edi
call   1070 <tolower@plt>
mov    %eax,%ecx
mov    %ecx,-0x3c(%rbp)
sub    $0x6e,%eax
je     1225 <ask_yn+0xd5>
jmp    11fe <ask_yn+0xae>
mov    -0x3c(%rbp),%eax
sub    $0x79,%eax
jne    123b <ask_yn+0xeb>
jmp    120f <ask_yn+0xbf>
mov    -0x20(%rbp),%rax
movl   $0x1,(%rax)
movl   $0x0,-0x4(%rbp)
jmp    124e <ask_yn+0xfe>
mov    -0x20(%rbp),%rax
movl   $0x0,(%rax)
movl   $0x0,-0x4(%rbp)
jmp    124e <ask_yn+0xfe>
lea    0xdc1(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    116d <ask_yn+0x1d>
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ask_yn>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rdx,%rbx
mov    %esi,%r14d
mov    %rdi,%rbp
movl   $0xffffffff,(%rdx)
lea    0xe7c(%rip),%rdi
mov    %rbp,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x2e53(%rip),%r12
mov    (%r12),%edx
lea    0x10(%rsp),%rdi
mov    $0x10,%esi
call   1070 <fgets@plt>
mov    $0xffffffff,%ecx
test   %eax,%eax
je     1256 <ask_yn+0xf6>
mov    %r14d,0xc(%rsp)
mov    %rbx,(%rsp)
lea    0x10(%rsp),%rbx
lea    0xe39(%rip),%r13
lea    0xe2f(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1060 <clean_string@plt>
mov    %rax,%r15
mov    %rax,%rdi
call   1040 <strlen@plt>
test   %eax,%eax
jle    123b <ask_yn+0xdb>
movsbl (%r15),%edi
call   1080 <tolower@plt>
cmp    $0x6e,%eax
je     1245 <ask_yn+0xe5>
cmp    $0x79,%eax
je     1249 <ask_yn+0xe9>
mov    %r13,%rdi
call   1030 <puts@plt>
mov    %r14,%rdi
mov    %rbp,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    (%r12),%edx
mov    %rbx,%rdi
mov    $0x10,%esi
call   1070 <fgets@plt>
test   %eax,%eax
jne    11e0 <ask_yn+0x80>
mov    $0xffffffff,%ecx
jmp    1256 <ask_yn+0xf6>
mov    (%rsp),%rax
mov    0xc(%rsp),%ecx
jmp    1252 <ask_yn+0xf2>
xor    %ecx,%ecx
jmp    124e <ask_yn+0xee>
mov    $0x1,%ecx
mov    (%rsp),%rax
mov    %ecx,(%rax)
xor    %ecx,%ecx
mov    %ecx,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%s\00"
@stdin = global i32 0
@.str.1 = [31 x i8] c"Please type either yes or no.\0A\00"
define i32 @ask_yn(i8* %0, i32 %1, i32* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32*
%8 = alloca [16 x i8]
%9 = alloca i8*
store i8* %0, i8** %5
store i32 %1, i32* %6
store i32* %2, i32** %7
%10 = load i32*, i32** %7
store i32 -1, i32* %10
br label %11
11: ; preds = %3, %37
%12 = load i8*, i8** %5
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %12)
%14 = getelementptr inbounds [16 x i8], [16 x i8]* %8, i64 0, i64 0
%15 = load i32, i32* @stdin
%16 = call i32 @fgets(i8* %14, i32 16, i32 %15)
%17 = icmp ne i32 %16, 0
br i1 %17, label %19, label %18
18: ; preds = %11
store i32 -1, i32* %4
br label %39
19: ; preds = %11
%20 = getelementptr inbounds [16 x i8], [16 x i8]* %8, i64 0, i64 0
%21 = call i8* @clean_string(i8* %20)
store i8* %21, i8** %9
%22 = load i8*, i8** %9
%23 = call i32 @strlen(i8* %22)
%24 = icmp slt i32 %23, 1
br i1 %24, label %25, label %28
25: ; preds = %19
%26 = load i32, i32* %6
%27 = load i32*, i32** %7
store i32 %26, i32* %27
store i32 0, i32* %4
br label %39
28: ; preds = %19
%29 = load i8*, i8** %9
%30 = getelementptr inbounds i8, i8* %29, i64 0
%31 = load i8, i8* %30
%32 = call i32 @tolower(i8 signext %31)
switch i32 %32, label %37 [
i32 121, label %33
i32 110, label %35
]
33: ; preds = %28
%34 = load i32*, i32** %7
store i32 1, i32* %34
store i32 0, i32* %4
br label %39
35: ; preds = %28
%36 = load i32*, i32** %7
store i32 0, i32* %36
store i32 0, i32* %4
br label %39
37: ; preds = %28
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0))
br label %11
39: ; preds = %35, %33, %25, %18
%40 = load i32, i32* %4
ret i32 %40
}

LLVM IR (-O2):
@.str = [3 x i8] c"%s\00"
@stdin = global i32 0
@str = [30 x i8] c"Please type either yes or no.\00"
define i32 @ask_yn(i8* %0, i32 %1, i32* nocapture writeonly %2) {
%4 = alloca [16 x i8]
%5 = getelementptr inbounds [16 x i8], [16 x i8]* %4, i64 0, i64 0
store i32 -1, i32* %2
%6 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %0)
%7 = load i32, i32* @stdin
%8 = call i32 @fgets(i8* %5, i32 16, i32 %7)
%9 = icmp eq i32 %8, 0
br i1 %9, label %26, label %10
10: ; preds = %3, %17
%11 = call i8* @clean_string(i8* %5)
%12 = call i32 @strlen(i8* %11)
%13 = icmp slt i32 %12, 1
br i1 %13, label %24, label %14
14: ; preds = %10
%15 = load i8, i8* %11
%16 = call i32 @tolower(i8 signext %15)
switch i32 %16, label %17 [
i32 121, label %24
i32 110, label %23
]
17: ; preds = %14
%18 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @str, i64 0, i64 0))
%19 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %0)
%20 = load i32, i32* @stdin
%21 = call i32 @fgets(i8* %5, i32 16, i32 %20)
%22 = icmp eq i32 %21, 0
br i1 %22, label %26, label %10
23: ; preds = %14
br label %24
24: ; preds = %14, %10, %23
%25 = phi i32 [ 0, %23 ], [ 1, %14 ], [ %1, %10 ]
store i32 %25, i32* %2
br label %26
26: ; preds = %17, %24, %3
%27 = phi i32 [ -1, %3 ], [ 0, %24 ], [ -1, %17 ]
ret i32 %27
}