#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 */
char getchar();
int /*<<< orphan*/ printf(char *, char const *, char, char);
char tolower(char);
char toupper(char);
bool prompt_bool(const char *question, bool default_) {
  char yes = 'y', no = 'n';
  if (default_)
    yes = toupper(yes);
  else
    no = toupper(no);
  printf("%s [%c/%c]: ", question, yes, no);
  char choice = tolower(getchar());
  if (choice != '\n')
    while (getchar() != '\n')
      ;
  return choice == 'y' ? true : (choice == 'n' ? false : default_);
}


x86 assembly (clang, -O0):
<prompt_bool>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movb   $0x79,-0xd(%rbp)
movb   $0x6e,-0xe(%rbp)
cmpl   $0x0,-0xc(%rbp)
je     1172 <prompt_bool+0x32>
movsbl -0xd(%rbp),%edi
call   1030 <toupper@plt>
mov    %al,-0xd(%rbp)
jmp    117e <prompt_bool+0x3e>
movsbl -0xe(%rbp),%edi
call   1030 <toupper@plt>
mov    %al,-0xe(%rbp)
mov    -0x8(%rbp),%rsi
mov    -0xd(%rbp),%al
lea    0xe74(%rip),%rdi
movsbl %al,%edx
movsbl -0xe(%rbp),%ecx
call   1040 <printf@plt>
mov    $0x0,%al
call   1050 <getchar@plt>
movsbl %al,%edi
call   1060 <tolower@plt>
mov    %al,-0xf(%rbp)
movsbl -0xf(%rbp),%eax
cmp    $0xa,%eax
je     11d9 <prompt_bool+0x99>
jmp    11bc <prompt_bool+0x7c>
mov    $0x0,%al
call   1050 <getchar@plt>
movsbl %al,%eax
cmp    $0xa,%eax
je     11d4 <prompt_bool+0x94>
jmp    11bc <prompt_bool+0x7c>
jmp    11d9 <prompt_bool+0x99>
movsbl -0xf(%rbp),%eax
cmp    $0x79,%eax
jne    11f3 <prompt_bool+0xb3>
mov    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1216 <prompt_bool+0xd6>
movsbl -0xf(%rbp),%eax
cmp    $0x6e,%eax
jne    120a <prompt_bool+0xca>
xor    %eax,%eax
mov    %eax,-0x18(%rbp)
jmp    1210 <prompt_bool+0xd0>
mov    -0xc(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<prompt_bool>:
push   %rbp
push   %r14
push   %rbx
mov    %esi,%ebp
mov    %rdi,%r14
test   %esi,%esi
je     115d <prompt_bool+0x1d>
mov    $0x79,%edi
call   1030 <toupper@plt>
mov    %eax,%ecx
mov    $0x6e,%al
jmp    1169 <prompt_bool+0x29>
mov    $0x6e,%edi
call   1030 <toupper@plt>
mov    $0x79,%cl
movsbl %cl,%edx
movsbl %al,%ecx
lea    0xe8a(%rip),%rdi
mov    %r14,%rsi
call   1040 <printf@plt>
xor    %r14d,%r14d
xor    %eax,%eax
call   1050 <getchar@plt>
movsbl %al,%edi
call   1060 <tolower@plt>
mov    %eax,%ebx
cmp    $0xa,%al
je     11ab <prompt_bool+0x6b>
cs nopw 0x0(%rax,%rax,1)
xor    %eax,%eax
call   1050 <getchar@plt>
cmp    $0xa,%al
jne    11a0 <prompt_bool+0x60>
cmp    $0x6e,%bl
cmove  %r14d,%ebp
cmp    $0x79,%bl
mov    $0x1,%eax
cmovne %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [13 x i8] c"%s [%c/%c]: \00"
define i32 @prompt_bool(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i8
%6 = alloca i8
%7 = alloca i8
store i8* %0, i8** %3
store i32 %1, i32* %4
store i8 121, i8* %5
store i8 110, i8* %6
%8 = load i32, i32* %4
%9 = icmp ne i32 %8, 0
br i1 %9, label %10, label %13
10: ; preds = %2
%11 = load i8, i8* %5
%12 = call signext i8 @toupper(i8 signext %11)
store i8 %12, i8* %5
br label %16
13: ; preds = %2
%14 = load i8, i8* %6
%15 = call signext i8 @toupper(i8 signext %14)
store i8 %15, i8* %6
br label %16
16: ; preds = %13, %10
%17 = load i8*, i8** %3
%18 = load i8, i8* %5
%19 = load i8, i8* %6
%20 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* %17, i8 signext %18, i8 signext %19)
%21 = call signext i8 (...) @getchar()
%22 = call signext i8 @tolower(i8 signext %21)
store i8 %22, i8* %7
%23 = load i8, i8* %7
%24 = sext i8 %23 to i32
%25 = icmp ne i32 %24, 10
br i1 %25, label %26, label %33
26: ; preds = %16
br label %27
27: ; preds = %31, %26
%28 = call signext i8 (...) @getchar()
%29 = sext i8 %28 to i32
%30 = icmp ne i32 %29, 10
br i1 %30, label %31, label %32
31: ; preds = %27
br label %27
32: ; preds = %27
br label %33
33: ; preds = %32, %16
%34 = load i8, i8* %7
%35 = sext i8 %34 to i32
%36 = icmp eq i32 %35, 121
br i1 %36, label %37, label %38
37: ; preds = %33
br label %47
38: ; preds = %33
%39 = load i8, i8* %7
%40 = sext i8 %39 to i32
%41 = icmp eq i32 %40, 110
br i1 %41, label %42, label %43
42: ; preds = %38
br label %45
43: ; preds = %38
%44 = load i32, i32* %4
br label %45
45: ; preds = %43, %42
%46 = phi i32 [ 0, %42 ], [ %44, %43 ]
br label %47
47: ; preds = %45, %37
%48 = phi i32 [ 1, %37 ], [ %46, %45 ]
ret i32 %48
}

LLVM IR (-O2):
@.str = [13 x i8] c"%s [%c/%c]: \00"
define i32 @prompt_bool(i8* %0, i32 %1) {
%3 = icmp eq i32 %1, 0
br i1 %3, label %6, label %4
4: ; preds = %2
%5 = tail call signext i8 @toupper(i8 signext 121)
br label %8
6: ; preds = %2
%7 = tail call signext i8 @toupper(i8 signext 110)
br label %8
8: ; preds = %6, %4
%9 = phi i8 [ 110, %4 ], [ %7, %6 ]
%10 = phi i8 [ %5, %4 ], [ 121, %6 ]
%11 = tail call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* %0, i8 signext %10, i8 signext %9)
%12 = tail call signext i8 (...) @getchar()
%13 = tail call signext i8 @tolower(i8 signext %12)
%14 = icmp eq i8 %13, 10
br i1 %14, label %18, label %15
15: ; preds = %8, %15
%16 = tail call signext i8 (...) @getchar()
%17 = icmp eq i8 %16, 10
br i1 %17, label %18, label %15
18: ; preds = %15, %8
%19 = icmp eq i8 %13, 121
%20 = icmp eq i8 %13, 110
%21 = select i1 %20, i32 0, i32 %1
%22 = select i1 %19, i32 1, i32 %21
ret i32 %22
}