#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*/ printf(char *, char *);
int /*<<< orphan*/ scanf(char *, char *);
int /*<<< orphan*/ showhelp(int);
char get_input_yn(char *question, char defval, int helpnum) {
  char str[80];
  for (;;) {
    printf("\n%s? (y/n/?) -> ", question);
    scanf("%s", str);
    if (str[0] == '?')
      showhelp(helpnum);
    else if (str[0] == 'y' || str[0] == 'n')
      return str[0];
    else
      return defval;
  }
}


x86 assembly (clang, -O0):
<get_input_yn>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %sil,%al
mov    %rdi,-0x10(%rbp)
mov    %al,-0x11(%rbp)
mov    %edx,-0x18(%rbp)
mov    -0x10(%rbp),%rsi
lea    0xeb0(%rip),%rdi
call   1030 <printf@plt>
lea    -0x70(%rbp),%rsi
lea    0xeb1(%rip),%rdi
call   1040 <scanf@plt>
movsbl -0x70(%rbp),%eax
cmp    $0x3f,%eax
jne    117f <get_input_yn+0x4f>
mov    -0x18(%rbp),%edi
call   1050 <showhelp@plt>
jmp    11af <get_input_yn+0x7f>
movsbl -0x70(%rbp),%eax
cmp    $0x79,%eax
je     1199 <get_input_yn+0x69>
movsbl -0x70(%rbp),%eax
cmp    $0x6e,%eax
jne    11a4 <get_input_yn+0x74>
mov    -0x70(%rbp),%al
mov    %al,-0x1(%rbp)
jmp    11b4 <get_input_yn+0x84>
mov    -0x11(%rbp),%al
mov    %al,-0x1(%rbp)
jmp    11b4 <get_input_yn+0x84>
jmp    1145 <get_input_yn+0x15>
movsbl -0x1(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_input_yn>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x58,%rsp
mov    %edx,%ebp
mov    %esi,%r14d
mov    %rdi,%rbx
lea    0xeb3(%rip),%r15
lea    0xebd(%rip),%r12
mov    %rsp,%r13
nopw   0x0(%rax,%rax,1)
mov    %r15,%rdi
mov    %rbx,%rsi
call   1030 <printf@plt>
mov    %r12,%rdi
mov    %r13,%rsi
call   1040 <scanf@plt>
movzbl (%rsp),%eax
cmp    $0x3f,%al
jne    1187 <get_input_yn+0x57>
mov    %ebp,%edi
call   1050 <showhelp@plt>
jmp    1160 <get_input_yn+0x30>
cmp    $0x6e,%al
je     1192 <get_input_yn+0x62>
cmp    $0x79,%al
je     1192 <get_input_yn+0x62>
mov    %r14d,%eax
add    $0x58,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [17 x i8] c"\0A%s? (y/n/?) -> \00"
@.str.1 = [3 x i8] c"%s\00"
define signext i8 @get_input_yn(i8* %0, i8 signext %1, i32 %2) {
%4 = alloca i8
%5 = alloca i8*
%6 = alloca i8
%7 = alloca i32
%8 = alloca [80 x i8]
store i8* %0, i8** %5
store i8 %1, i8* %6
store i32 %2, i32* %7
br label %9
9: ; preds = %36, %3
%10 = load i8*, i8** %5
%11 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* %10)
%12 = getelementptr inbounds [80 x i8], [80 x i8]* %8, i64 0, i64 0
%13 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %12)
%14 = getelementptr inbounds [80 x i8], [80 x i8]* %8, i64 0, i64 0
%15 = load i8, i8* %14
%16 = sext i8 %15 to i32
%17 = icmp eq i32 %16, 63
br i1 %17, label %18, label %21
18: ; preds = %9
%19 = load i32, i32* %7
%20 = call i32 @showhelp(i32 %19)
br label %36
21: ; preds = %9
%22 = getelementptr inbounds [80 x i8], [80 x i8]* %8, i64 0, i64 0
%23 = load i8, i8* %22
%24 = sext i8 %23 to i32
%25 = icmp eq i32 %24, 121
br i1 %25, label %31, label %26
26: ; preds = %21
%27 = getelementptr inbounds [80 x i8], [80 x i8]* %8, i64 0, i64 0
%28 = load i8, i8* %27
%29 = sext i8 %28 to i32
%30 = icmp eq i32 %29, 110
br i1 %30, label %31, label %34
31: ; preds = %26, %21
%32 = getelementptr inbounds [80 x i8], [80 x i8]* %8, i64 0, i64 0
%33 = load i8, i8* %32
store i8 %33, i8* %4
br label %37
34: ; preds = %26
%35 = load i8, i8* %6
store i8 %35, i8* %4
br label %37
36: ; preds = %18
br label %9
37: ; preds = %34, %31
%38 = load i8, i8* %4
ret i8 %38
}

LLVM IR (-O2):
@.str = [17 x i8] c"\0A%s? (y/n/?) -> \00"
@.str.1 = [3 x i8] c"%s\00"
define signext i8 @get_input_yn(i8* %0, i8 signext %1, i32 %2) {
%4 = alloca [80 x i8]
%5 = getelementptr inbounds [80 x i8], [80 x i8]* %4, i64 0, i64 0
br label %6
6: ; preds = %10, %3
%7 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* %0)
%8 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %5)
%9 = load i8, i8* %5
switch i8 %9, label %13 [
i8 63, label %10
i8 121, label %12
i8 110, label %12
]
10: ; preds = %6
%11 = call i32 @showhelp(i32 %2)
br label %6
12: ; preds = %6, %6
br label %13
13: ; preds = %6, %12
%14 = phi i8 [ %9, %12 ], [ %1, %6 ]
ret i8 %14
}