#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*/ free(char *);
char *getLine();
int /*<<< orphan*/ printf(char *, char *, char);
char toupper(char);
int yesno(char *query, int def) {
  char *yn;
  int ans = 2;
  while (ans > 1) {
    printf("%s (yes or no) [%c]:  ", query, def ? 'Y' : 'N');
    yn = getLine();
    if (!*yn)
      ans = def;
    else if (toupper(*yn) == 'Y')
      ans = 1;
    else if (toupper(*yn) == 'N')
      ans = 0;
    free(yn);
  }
  return ans;
}


x86 assembly (clang, -O0):
<yesno>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x2,-0x1c(%rbp)
cmpl   $0x1,-0x1c(%rbp)
jle    1204 <yesno+0xc4>
mov    -0x8(%rbp),%rsi
mov    -0xc(%rbp),%edx
mov    $0x4e,%eax
mov    $0x59,%ecx
cmp    $0x0,%edx
cmovne %ecx,%eax
lea    0xe82(%rip),%rdi
movsbl %al,%edx
call   1050 <printf@plt>
mov    $0x0,%al
call   1060 <getLine@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
cmpb   $0x0,(%rax)
jne    11a9 <yesno+0x69>
mov    -0xc(%rbp),%eax
mov    %eax,-0x1c(%rbp)
jmp    11f6 <yesno+0xb6>
mov    -0x18(%rbp),%rax
movsbl (%rax),%edi
call   1040 <toupper@plt>
movsbl %al,%eax
cmp    $0x59,%eax
jne    11cd <yesno+0x8d>
movl   $0x1,-0x1c(%rbp)
jmp    11f1 <yesno+0xb1>
mov    -0x18(%rbp),%rax
movsbl (%rax),%edi
call   1040 <toupper@plt>
movsbl %al,%eax
cmp    $0x4e,%eax
jne    11ec <yesno+0xac>
movl   $0x0,-0x1c(%rbp)
jmp    11f1 <yesno+0xb1>
jmp    11f6 <yesno+0xb6>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
jmp    1156 <yesno+0x16>
mov    -0x1c(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<yesno>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %esi,%r14d
test   %esi,%esi
mov    $0x4e,%eax
mov    $0x59,%ecx
cmove  %eax,%ecx
mov    %rdi,%r12
mov    $0x2,%r15d
movzbl %cl,%r13d
jmp    1180 <yesno+0x40>
nopl   0x0(%rax)
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %ebp,%r15d
cmp    $0x1,%ebp
jle    11d2 <yesno+0x92>
lea    0xe79(%rip),%rdi
mov    %r12,%rsi
mov    %r13d,%edx
call   1050 <printf@plt>
xor    %eax,%eax
call   1060 <getLine@plt>
mov    %rax,%rbx
movzbl (%rax),%eax
mov    %r14d,%ebp
test   %al,%al
je     1170 <yesno+0x30>
movsbl %al,%edi
call   1040 <toupper@plt>
cmp    $0x59,%al
je     11c5 <yesno+0x85>
movsbl (%rbx),%edi
call   1040 <toupper@plt>
mov    %r15d,%ebp
cmp    $0x4e,%al
jne    1170 <yesno+0x30>
xor    %ebp,%ebp
jmp    11ca <yesno+0x8a>
mov    $0x1,%ebp
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [23 x i8] c"%s (yes or no) [%c]: \00"
define i32 @yesno(i8* %0, i32 %1) {
%3 = icmp eq i32 %1, 0
%4 = select i1 %3, i8 78, i8 89
br label %5
5: ; preds = %2, %21
%6 = phi i32 [ 2, %2 ], [ %22, %21 ]
%7 = tail call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i8* %0, i8 signext %4)
%8 = tail call i8* (...) @getLine()
%9 = load i8, i8* %8
%10 = icmp eq i8 %9, 0
br i1 %10, label %21, label %11
11: ; preds = %5
%12 = tail call signext i8 @toupper(i8 signext %9)
%13 = icmp eq i8 %12, 89
br i1 %13, label %18, label %14
14: ; preds = %11
%15 = load i8, i8* %8
%16 = tail call signext i8 @toupper(i8 signext %15)
%17 = icmp eq i8 %16, 78
br i1 %17, label %18, label %21
18: ; preds = %11, %14
%19 = phi i32 [ 1, %11 ], [ 0, %14 ]
%20 = tail call i32 @free(i8* %8)
br label %25
21: ; preds = %14, %5
%22 = phi i32 [ %1, %5 ], [ %6, %14 ]
%23 = tail call i32 @free(i8* %8)
%24 = icmp sgt i32 %22, 1
br i1 %24, label %5, label %25
25: ; preds = %21, %18
%26 = phi i32 [ %19, %18 ], [ %22, %21 ]
ret i32 %26
}