#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 */
scalar_t__ fgets(char *, int, int /*<<< orphan*/);
char *getenv(char const *);
int /*<<< orphan*/ printf(char *, ...);
int sscanf(char *, char *, char *);
int /*<<< orphan*/ stdin;
int tolower(char const);
int toupper(char const);
char askforchar(const char *question, const char *envname, const char *allowed,
                char deflt) {
  char res;
  char buf[80];
  char *env;
  const char *c;
  env = getenv(envname);
  if (env && sscanf(env, "%c", &res) == 1)
    return tolower(res);
  do {
    (void)printf("%s (", question);
    res = tolower(deflt);
    for (c = allowed; *c; c++)
      if (*c == res)
        (void)printf("%c", toupper(*c));
      else
        (void)printf("%c", tolower(*c));
    (void)printf(")\n");
    if (fgets(buf, 80, stdin))
      sscanf(buf, " %c", &res);
    res = tolower(res);
    for (c = allowed; *c && *c != res; c++)
      ;
  } while (!*c);
  return res;
}


x86 assembly (clang, -O0):
<askforchar>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
mov    %cl,%al
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %al,-0x21(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x88(%rbp)
cmpq   $0x0,-0x88(%rbp)
je     11cb <askforchar+0x6b>
mov    -0x88(%rbp),%rdi
lea    0xe61(%rip),%rsi
lea    -0x22(%rbp),%rdx
call   1080 <sscanf@plt>
cmp    $0x1,%eax
jne    11cb <askforchar+0x6b>
movsbl -0x22(%rbp),%edi
call   1070 <tolower@plt>
mov    %al,-0x1(%rbp)
jmp    135d <askforchar+0x1fd>
jmp    11d0 <askforchar+0x70>
mov    -0x10(%rbp),%rsi
lea    0xe25(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movsbl -0x21(%rbp),%edi
call   1070 <tolower@plt>
mov    %al,-0x22(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x90(%rbp)
mov    -0x90(%rbp),%rax
cmpb   $0x0,(%rax)
je     127e <askforchar+0x11e>
mov    -0x90(%rbp),%rax
movsbl (%rax),%eax
movsbl -0x22(%rbp),%ecx
cmp    %ecx,%eax
jne    1243 <askforchar+0xe3>
mov    -0x90(%rbp),%rax
movsbl (%rax),%edi
call   1040 <toupper@plt>
mov    %eax,%esi
lea    0xdd2(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    1262 <askforchar+0x102>
mov    -0x90(%rbp),%rax
movsbl (%rax),%edi
call   1070 <tolower@plt>
mov    %eax,%esi
lea    0xdae(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    1267 <askforchar+0x107>
mov    -0x90(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x90(%rbp)
jmp    11f9 <askforchar+0x99>
lea    0xd80(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x80(%rbp),%rdi
mov    0x2d51(%rip),%rax
mov    (%rax),%edx
mov    $0x50,%esi
call   1060 <fgets@plt>
cmp    $0x0,%rax
je     12c1 <askforchar+0x161>
lea    -0x80(%rbp),%rdi
lea    0xd50(%rip),%rsi
lea    -0x22(%rbp),%rdx
call   1080 <sscanf@plt>
movsbl -0x22(%rbp),%edi
call   1070 <tolower@plt>
mov    %al,-0x22(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x90(%rbp)
mov    -0x90(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x91(%rbp)
je     130c <askforchar+0x1ac>
mov    -0x90(%rbp),%rax
movsbl (%rax),%eax
movsbl -0x22(%rbp),%ecx
cmp    %ecx,%eax
setne  %al
mov    %al,-0x91(%rbp)
mov    -0x91(%rbp),%al
test   $0x1,%al
jne    131f <askforchar+0x1bf>
jmp    133b <askforchar+0x1db>
jmp    1324 <askforchar+0x1c4>
mov    -0x90(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x90(%rbp)
jmp    12d8 <askforchar+0x178>
jmp    1340 <askforchar+0x1e0>
mov    -0x90(%rbp),%rax
cmpb   $0x0,(%rax)
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    11d0 <askforchar+0x70>
mov    -0x22(%rbp),%al
mov    %al,-0x1(%rbp)
movsbl -0x1(%rbp),%eax
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<askforchar>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x68,%rsp
mov    %ecx,%ebp
mov    %rdx,%rbx
mov    %rdi,%r14
mov    %rsi,%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     11d5 <askforchar+0x55>
lea    0xe5c(%rip),%rsi
lea    0xf(%rsp),%rdx
mov    %rax,%rdi
call   10a0 <sscanf@plt>
cmp    $0x1,%eax
jne    11d5 <askforchar+0x55>
movsbl 0xf(%rsp),%edi
call   1090 <tolower@plt>
add    $0x68,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0x1(%rbx),%r12
movsbl %bpl,%ebp
lea    0x10(%rsp),%r13
jmp    11f4 <askforchar+0x74>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
test   %dl,%dl
jne    11c6 <askforchar+0x46>
lea    0xe05(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %ebp,%edi
call   1090 <tolower@plt>
mov    %al,0xf(%rsp)
mov    (%rbx),%cl
test   %cl,%cl
je     1260 <askforchar+0xe0>
mov    %r12,%r15
cmp    %al,%cl
jne    1230 <askforchar+0xb0>
nopl   (%rax)
movsbl %al,%edi
call   1050 <toupper@plt>
jmp    1238 <askforchar+0xb8>
nopw   0x0(%rax,%rax,1)
movsbl %cl,%edi
call   1090 <tolower@plt>
mov    %eax,%edi
call   1040 <putchar@plt>
mov    (%r15),%cl
test   %cl,%cl
je     1260 <askforchar+0xe0>
mov    0xf(%rsp),%al
add    $0x1,%r15
cmp    %al,%cl
jne    1230 <askforchar+0xb0>
jmp    1220 <askforchar+0xa0>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
lea    0xda2(%rip),%rdi
call   1060 <puts@plt>
mov    0x2d75(%rip),%rax
mov    (%rax),%edx
mov    %r13,%rdi
mov    $0x50,%esi
call   1080 <fgets@plt>
test   %rax,%rax
je     129b <askforchar+0x11b>
mov    %r13,%rdi
lea    0xd74(%rip),%rsi
lea    0xf(%rsp),%rdx
call   10a0 <sscanf@plt>
movsbl 0xf(%rsp),%edi
call   1090 <tolower@plt>
mov    %al,0xf(%rsp)
mov    %rbx,%rcx
nopl   0x0(%rax)
movzbl (%rcx),%edx
test   %dl,%dl
je     11f0 <askforchar+0x70>
add    $0x1,%rcx
cmp    %al,%dl
jne    12b0 <askforchar+0x130>
jmp    11f0 <askforchar+0x70>

LLVM IR (-O0):
@.str = [3 x i8] c"%c\00"
@.str.1 = [5 x i8] c"%s (\00"
@.str.2 = [3 x i8] c")\0A\00"
@stdin = global i32 0
@.str.3 = [4 x i8] c" %c\00"
define signext i8 @askforchar(i8* %0, i8* %1, i8* %2, i8 signext %3) {
%5 = alloca i8
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8
%10 = alloca i8
%11 = alloca [80 x i8]
%12 = alloca i8*
%13 = alloca i8*
store i8* %0, i8** %6
store i8* %1, i8** %7
store i8* %2, i8** %8
store i8 %3, i8* %9
%14 = load i8*, i8** %7
%15 = call i8* @getenv(i8* %14)
store i8* %15, i8** %12
%16 = load i8*, i8** %12
%17 = icmp ne i8* %16, null
br i1 %17, label %18, label %26
18: ; preds = %4
%19 = load i8*, i8** %12
%20 = call i32 @sscanf(i8* %19, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %10)
%21 = icmp eq i32 %20, 1
br i1 %21, label %22, label %26
22: ; preds = %18
%23 = load i8, i8* %10
%24 = call i32 @tolower(i8 signext %23)
%25 = trunc i32 %24 to i8
store i8 %25, i8* %5
br label %99
26: ; preds = %18, %4
br label %27
27: ; preds = %92, %26
%28 = load i8*, i8** %6
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %28)
%30 = load i8, i8* %9
%31 = call i32 @tolower(i8 signext %30)
%32 = trunc i32 %31 to i8
store i8 %32, i8* %10
%33 = load i8*, i8** %8
store i8* %33, i8** %13
br label %34
34: ; preds = %56, %27
%35 = load i8*, i8** %13
%36 = load i8, i8* %35
%37 = icmp ne i8 %36, 0
br i1 %37, label %38, label %59
38: ; preds = %34
%39 = load i8*, i8** %13
%40 = load i8, i8* %39
%41 = sext i8 %40 to i32
%42 = load i8, i8* %10
%43 = sext i8 %42 to i32
%44 = icmp eq i32 %41, %43
br i1 %44, label %45, label %50
45: ; preds = %38
%46 = load i8*, i8** %13
%47 = load i8, i8* %46
%48 = call i32 @toupper(i8 signext %47)
%49 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %48)
br label %55
50: ; preds = %38
%51 = load i8*, i8** %13
%52 = load i8, i8* %51
%53 = call i32 @tolower(i8 signext %52)
%54 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %53)
br label %55
55: ; preds = %50, %45
br label %56
56: ; preds = %55
%57 = load i8*, i8** %13
%58 = getelementptr inbounds i8, i8* %57, i32 1
store i8* %58, i8** %13
br label %34
59: ; preds = %34
%60 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%61 = getelementptr inbounds [80 x i8], [80 x i8]* %11, i64 0, i64 0
%62 = load i32, i32* @stdin
%63 = call i64 @fgets(i8* %61, i32 80, i32 %62)
%64 = icmp ne i64 %63, 0
br i1 %64, label %65, label %68
65: ; preds = %59
%66 = getelementptr inbounds [80 x i8], [80 x i8]* %11, i64 0, i64 0
%67 = call i32 @sscanf(i8* %66, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %10)
br label %68
68: ; preds = %65, %59
%69 = load i8, i8* %10
%70 = call i32 @tolower(i8 signext %69)
%71 = trunc i32 %70 to i8
store i8 %71, i8* %10
%72 = load i8*, i8** %8
store i8* %72, i8** %13
br label %73
73: ; preds = %88, %68
%74 = load i8*, i8** %13
%75 = load i8, i8* %74
%76 = sext i8 %75 to i32
%77 = icmp ne i32 %76, 0
br i1 %77, label %78, label %85
78: ; preds = %73
%79 = load i8*, i8** %13
%80 = load i8, i8* %79
%81 = sext i8 %80 to i32
%82 = load i8, i8* %10
%83 = sext i8 %82 to i32
%84 = icmp ne i32 %81, %83
br label %85
85: ; preds = %78, %73
%86 = phi i1 [ false, %73 ], [ %84, %78 ]
br i1 %86, label %87, label %91
87: ; preds = %85
br label %88
88: ; preds = %87
%89 = load i8*, i8** %13
%90 = getelementptr inbounds i8, i8* %89, i32 1
store i8* %90, i8** %13
br label %73
91: ; preds = %85
br label %92
92: ; preds = %91
%93 = load i8*, i8** %13
%94 = load i8, i8* %93
%95 = icmp ne i8 %94, 0
%96 = xor i1 %95, true
br i1 %96, label %27, label %97
97: ; preds = %92
%98 = load i8, i8* %10
store i8 %98, i8* %5
br label %99
99: ; preds = %97, %22
%100 = load i8, i8* %5
ret i8 %100
}

LLVM IR (-O2):
@.str = [3 x i8] c"%c\00"
@.str.1 = [5 x i8] c"%s (\00"
@stdin = global i32 0
@.str.3 = [4 x i8] c" %c\00"
@str = [2 x i8] c")\00"
define signext i8 @askforchar(i8* %0, i8* nocapture %1, i8* nocapture %2, i8 signext %3) {
%5 = alloca i8
%6 = alloca [80 x i8]
%7 = getelementptr inbounds [80 x i8], [80 x i8]* %6, i64 0, i64 0
%8 = tail call i8* @getenv(i8* %1)
%9 = icmp eq i8* %8, null
br i1 %9, label %10, label %11
10: ; preds = %11, %4
br label %17
11: ; preds = %4
%12 = call i32 @sscanf(i8* %8, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %5)
%13 = icmp eq i32 %12, 1
br i1 %13, label %14, label %10
14: ; preds = %11
%15 = load i8, i8* %5
%16 = call i32 @tolower(i8 signext %15)
br label %59
17: ; preds = %10, %58
%18 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %0)
%19 = call i32 @tolower(i8 signext %3)
%20 = trunc i32 %19 to i8
store i8 %20, i8* %5
%21 = load i8, i8* %2
%22 = icmp eq i8 %21, 0
br i1 %22, label %40, label %23
23: ; preds = %17, %38
%24 = phi i8 [ %39, %38 ], [ %20, %17 ]
%25 = phi i8 [ %36, %38 ], [ %21, %17 ]
%26 = phi i8* [ %35, %38 ], [ %2, %17 ]
%27 = icmp eq i8 %25, %24
br i1 %27, label %28, label %30
28: ; preds = %23
%29 = call i32 @toupper(i8 signext %24)
br label %32
30: ; preds = %23
%31 = call i32 @tolower(i8 signext %25)
br label %32
32: ; preds = %28, %30
%33 = phi i32 [ %29, %28 ], [ %31, %30 ]
%34 = call i32 @putchar(i32 %33)
%35 = getelementptr inbounds i8, i8* %26, i64 1
%36 = load i8, i8* %35
%37 = icmp eq i8 %36, 0
br i1 %37, label %40, label %38
38: ; preds = %32
%39 = load i8, i8* %5
br label %23
40: ; preds = %32, %17
%41 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([2 x i8], [2 x i8]* @str, i64 0, i64 0))
%42 = load i32, i32* @stdin
%43 = call i64 @fgets(i8* %7, i32 80, i32 %42)
%44 = icmp eq i64 %43, 0
br i1 %44, label %47, label %45
45: ; preds = %40
%46 = call i32 @sscanf(i8* %7, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %5)
br label %47
47: ; preds = %45, %40
%48 = load i8, i8* %5
%49 = call i32 @tolower(i8 signext %48)
%50 = trunc i32 %49 to i8
store i8 %50, i8* %5
br label %51
51: ; preds = %51, %47
%52 = phi i8* [ %2, %47 ], [ %57, %51 ]
%53 = load i8, i8* %52
%54 = icmp eq i8 %53, 0
%55 = icmp eq i8 %53, %50
%56 = select i1 %54, i1 true, i1 %55
%57 = getelementptr inbounds i8, i8* %52, i64 1
br i1 %56, label %58, label %51
58: ; preds = %51
br i1 %54, label %17, label %59
59: ; preds = %58, %14
%60 = phi i32 [ %16, %14 ], [ %49, %58 ]
%61 = trunc i32 %60 to i8
ret i8 %61
}