#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*/ gets(char *);
int /*<<< orphan*/ printf(char *, ...);
long yes_no(char *prompt) {
  char reply[128];
  while (1) {
    printf("%s [Y/N]: ", prompt);
    gets(reply);
    switch (*reply) {
    case 'y':
    case 'Y':
      return (1);
    case 'n':
    case 'N':
      return (0);
    default:
      printf("Please answer 'yes' or 'no'.\n");
    }
  }
}


x86 assembly (clang, -O0):
<yes_no>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rsi
lea    0xec6(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
lea    -0x90(%rbp),%rdi
call   1040 <gets@plt>
movsbl -0x90(%rbp),%eax
mov    %eax,-0x94(%rbp)
sub    $0x4e,%eax
je     11b1 <yes_no+0x91>
jmp    1168 <yes_no+0x48>
mov    -0x94(%rbp),%eax
sub    $0x59,%eax
je     11a4 <yes_no+0x84>
jmp    117c <yes_no+0x5c>
mov    -0x94(%rbp),%eax
sub    $0x6e,%eax
je     11b1 <yes_no+0x91>
jmp    1190 <yes_no+0x70>
mov    -0x94(%rbp),%eax
sub    $0x79,%eax
jne    11be <yes_no+0x9e>
jmp    11a4 <yes_no+0x84>
movq   $0x1,-0x8(%rbp)
jmp    11d1 <yes_no+0xb1>
movq   $0x0,-0x8(%rbp)
jmp    11d1 <yes_no+0xb1>
lea    0xe46(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    112f <yes_no+0xf>
mov    -0x8(%rbp),%rax
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<yes_no>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x88,%rsp
mov    %rdi,%rbx
lea    0xeb8(%rip),%r14
mov    %rsp,%r15
lea    0xeb9(%rip),%r12
jmp    1168 <yes_no+0x38>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %r12,%rdi
call   1030 <puts@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r15,%rdi
call   1050 <gets@plt>
movsbl (%rsp),%eax
cmp    $0x6d,%eax
jg     11a0 <yes_no+0x70>
cmp    $0x4e,%eax
je     11b1 <yes_no+0x81>
cmp    $0x59,%eax
jne    1160 <yes_no+0x30>
jmp    11aa <yes_no+0x7a>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
cmp    $0x6e,%eax
je     11b1 <yes_no+0x81>
cmp    $0x79,%eax
jne    1160 <yes_no+0x30>
mov    $0x1,%eax
jmp    11b3 <yes_no+0x83>
xor    %eax,%eax
add    $0x88,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [11 x i8] c"%s [Y/N]: \00"
@.str.1 = [30 x i8] c"Please answer 'yes' or 'no'.\0A\00"
define i64 @yes_no(i8* %0) {
%2 = alloca i64
%3 = alloca i8*
%4 = alloca [128 x i8]
store i8* %0, i8** %3
br label %5
5: ; preds = %1, %17
%6 = load i8*, i8** %3
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* %6)
%8 = getelementptr inbounds [128 x i8], [128 x i8]* %4, i64 0, i64 0
%9 = call i32 @gets(i8* %8)
%10 = getelementptr inbounds [128 x i8], [128 x i8]* %4, i64 0, i64 0
%11 = load i8, i8* %10
%12 = sext i8 %11 to i32
switch i32 %12, label %15 [
i32 121, label %13
i32 89, label %13
i32 110, label %14
i32 78, label %14
]
13: ; preds = %5, %5
store i64 1, i64* %2
br label %18
14: ; preds = %5, %5
store i64 0, i64* %2
br label %18
15: ; preds = %5
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0))
br label %17
17: ; preds = %15
br label %5
18: ; preds = %14, %13
%19 = load i64, i64* %2
ret i64 %19
}

LLVM IR (-O2):
@.str = [11 x i8] c"%s [Y/N]: \00"
@str = [29 x i8] c"Please answer 'yes' or 'no'.\00"
define i64 @yes_no(i8* %0) {
%2 = alloca [128 x i8]
%3 = getelementptr inbounds [128 x i8], [128 x i8]* %2, i64 0, i64 0
br label %4
4: ; preds = %9, %1
%5 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* %0)
%6 = call i32 @gets(i8* %3)
%7 = load i8, i8* %3
%8 = sext i8 %7 to i32
switch i32 %8, label %9 [
i32 121, label %11
i32 89, label %11
i32 110, label %12
i32 78, label %12
]
9: ; preds = %4
%10 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @str, i64 0, i64 0))
br label %4
11: ; preds = %4, %4
br label %12
12: ; preds = %4, %4, %11
%13 = phi i64 [ 1, %11 ], [ 0, %4 ], [ 0, %4 ]
ret i64 %13
}