#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*/ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ stdout;
int prompt_e_d(const char *prompt) {
  char input[64];
  char *t;
  int valid;
  while (1) {
    printf("%s (e/d)? ", prompt);
    fflush(stdout);
    fgets(input, 64, stdin);
    valid = 1;
    for (t = input + 1; t < input + 64; t++) {
      if (*t == 0)
        break;
      if (*t > 20) {
        valid = 0;
        break;
      }
    }
    if (valid) {
      if (*input == 'e' || *input == 'E')
        return 1;
      if (*input == 'd' || *input == 'D')
        return 0;
    }
    printf("Please enter E or D\n");
  }
  return 0;
}


x86 assembly (clang, -O0):
<prompt_e_d>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rsi
lea    0xeb9(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    0x2e83(%rip),%rax
mov    (%rax),%edi
call   1050 <fflush@plt>
lea    -0x50(%rbp),%rdi
mov    0x2e81(%rip),%rax
mov    (%rax),%edx
mov    $0x40,%esi
call   1040 <fgets@plt>
movl   $0x1,-0x5c(%rbp)
lea    -0x50(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x58(%rbp)
mov    -0x58(%rbp),%rax
lea    -0x50(%rbp),%rcx
add    $0x40,%rcx
cmp    %rcx,%rax
jae    11e2 <prompt_e_d+0xb2>
mov    -0x58(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    11b0 <prompt_e_d+0x80>
jmp    11e2 <prompt_e_d+0xb2>
mov    -0x58(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x14,%eax
jle    11cc <prompt_e_d+0x9c>
movl   $0x0,-0x5c(%rbp)
jmp    11e2 <prompt_e_d+0xb2>
jmp    11d1 <prompt_e_d+0xa1>
mov    -0x58(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x58(%rbp)
jmp    1186 <prompt_e_d+0x56>
cmpl   $0x0,-0x5c(%rbp)
je     123d <prompt_e_d+0x10d>
movsbl -0x50(%rbp),%eax
cmp    $0x65,%eax
je     1206 <prompt_e_d+0xd6>
movsbl -0x50(%rbp),%eax
cmp    $0x45,%eax
jne    1212 <prompt_e_d+0xe2>
movl   $0x1,-0x4(%rbp)
jmp    1250 <prompt_e_d+0x120>
movsbl -0x50(%rbp),%eax
cmp    $0x64,%eax
je     122c <prompt_e_d+0xfc>
movsbl -0x50(%rbp),%eax
cmp    $0x44,%eax
jne    1238 <prompt_e_d+0x108>
movl   $0x0,-0x4(%rbp)
jmp    1250 <prompt_e_d+0x120>
jmp    123d <prompt_e_d+0x10d>
lea    0xdc7(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    113c <prompt_e_d+0xc>
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<prompt_e_d>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x48,%rsp
mov    %rdi,%rbx
lea    0x40(%rsp),%rbp
mov    0x2e7b(%rip),%r13
mov    0x2e84(%rip),%r14
mov    %rsp,%r15
lea    0xe9d(%rip),%r12
jmp    1178 <prompt_e_d+0x38>
mov    %r12,%rdi
call   1030 <puts@plt>
lea    0xe81(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x0(%r13),%edi
call   1060 <fflush@plt>
mov    (%r14),%edx
mov    %r15,%rdi
mov    $0x40,%esi
call   1050 <fgets@plt>
lea    0x1(%rsp),%rax
nopw   0x0(%rax,%rax,1)
movzbl (%rax),%ecx
test   %cl,%cl
je     11c5 <prompt_e_d+0x85>
cmp    $0x14,%cl
jg     1170 <prompt_e_d+0x30>
add    $0x1,%rax
cmp    %rbp,%rax
jb     11b0 <prompt_e_d+0x70>
mov    (%rsp),%al
and    $0xdf,%al
cmp    $0x44,%al
je     11d9 <prompt_e_d+0x99>
cmp    $0x45,%al
jne    1170 <prompt_e_d+0x30>
mov    $0x1,%eax
jmp    11db <prompt_e_d+0x9b>
xor    %eax,%eax
add    $0x48,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [11 x i8] c"%s (e/d)? \00"
@stdout = global i32 0
@stdin = global i32 0
@.str.1 = [21 x i8] c"Please enter E or D\0A\00"
define i32 @prompt_e_d(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca [64 x i8]
%5 = alloca i8*
%6 = alloca i32
store i8* %0, i8** %3
br label %7
7: ; preds = %1, %64
%8 = load i8*, i8** %3
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* %8)
%10 = load i32, i32* @stdout
%11 = call i32 @fflush(i32 %10)
%12 = getelementptr inbounds [64 x i8], [64 x i8]* %4, i64 0, i64 0
%13 = load i32, i32* @stdin
%14 = call i32 @fgets(i8* %12, i32 64, i32 %13)
store i32 1, i32* %6
%15 = getelementptr inbounds [64 x i8], [64 x i8]* %4, i64 0, i64 0
%16 = getelementptr inbounds i8, i8* %15, i64 1
store i8* %16, i8** %5
br label %17
17: ; preds = %35, %7
%18 = load i8*, i8** %5
%19 = getelementptr inbounds [64 x i8], [64 x i8]* %4, i64 0, i64 0
%20 = getelementptr inbounds i8, i8* %19, i64 64
%21 = icmp ult i8* %18, %20
br i1 %21, label %22, label %38
22: ; preds = %17
%23 = load i8*, i8** %5
%24 = load i8, i8* %23
%25 = sext i8 %24 to i32
%26 = icmp eq i32 %25, 0
br i1 %26, label %27, label %28
27: ; preds = %22
br label %38
28: ; preds = %22
%29 = load i8*, i8** %5
%30 = load i8, i8* %29
%31 = sext i8 %30 to i32
%32 = icmp sgt i32 %31, 20
br i1 %32, label %33, label %34
33: ; preds = %28
store i32 0, i32* %6
br label %38
34: ; preds = %28
br label %35
35: ; preds = %34
%36 = load i8*, i8** %5
%37 = getelementptr inbounds i8, i8* %36, i32 1
store i8* %37, i8** %5
br label %17
38: ; preds = %33, %27, %17
%39 = load i32, i32* %6
%40 = icmp ne i32 %39, 0
br i1 %40, label %41, label %64
41: ; preds = %38
%42 = getelementptr inbounds [64 x i8], [64 x i8]* %4, i64 0, i64 0
%43 = load i8, i8* %42
%44 = sext i8 %43 to i32
%45 = icmp eq i32 %44, 101
br i1 %45, label %51, label %46
46: ; preds = %41
%47 = getelementptr inbounds [64 x i8], [64 x i8]* %4, i64 0, i64 0
%48 = load i8, i8* %47
%49 = sext i8 %48 to i32
%50 = icmp eq i32 %49, 69
br i1 %50, label %51, label %52
51: ; preds = %46, %41
store i32 1, i32* %2
br label %66
52: ; preds = %46
%53 = getelementptr inbounds [64 x i8], [64 x i8]* %4, i64 0, i64 0
%54 = load i8, i8* %53
%55 = sext i8 %54 to i32
%56 = icmp eq i32 %55, 100
br i1 %56, label %62, label %57
57: ; preds = %52
%58 = getelementptr inbounds [64 x i8], [64 x i8]* %4, i64 0, i64 0
%59 = load i8, i8* %58
%60 = sext i8 %59 to i32
%61 = icmp eq i32 %60, 68
br i1 %61, label %62, label %63
62: ; preds = %57, %52
store i32 0, i32* %2
br label %66
63: ; preds = %57
br label %64
64: ; preds = %63, %38
%65 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
br label %7
66: ; preds = %62, %51
%67 = load i32, i32* %2
ret i32 %67
}

LLVM IR (-O2):
@.str = [11 x i8] c"%s (e/d)? \00"
@stdout = global i32 0
@stdin = global i32 0
@str = [20 x i8] c"Please enter E or D\00"
define i32 @prompt_e_d(i8* %0) {
%2 = alloca [64 x i8]
%3 = getelementptr inbounds [64 x i8], [64 x i8]* %2, i64 0, i64 0
%4 = getelementptr inbounds [64 x i8], [64 x i8]* %2, i64 0, i64 1
%5 = getelementptr inbounds [64 x i8], [64 x i8]* %2, i64 0, i64 64
br label %6
6: ; preds = %24, %1
%7 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* %0)
%8 = load i32, i32* @stdout
%9 = call i32 @fflush(i32 %8)
%10 = load i32, i32* @stdin
%11 = call i32 @fgets(i8* %3, i32 64, i32 %10)
br label %14
12: ; preds = %18
%13 = icmp ult i8* %20, %5
br i1 %13, label %14, label %21
14: ; preds = %6, %12
%15 = phi i8* [ %4, %6 ], [ %20, %12 ]
%16 = load i8, i8* %15
%17 = icmp eq i8 %16, 0
br i1 %17, label %21, label %18
18: ; preds = %14
%19 = icmp sgt i8 %16, 20
%20 = getelementptr inbounds i8, i8* %15, i64 1
br i1 %19, label %24, label %12
21: ; preds = %12, %14
%22 = load i8, i8* %3
%23 = and i8 %22, -33
switch i8 %23, label %24 [
i8 69, label %26
i8 68, label %27
]
24: ; preds = %18, %21
%25 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str, i64 0, i64 0))
br label %6
26: ; preds = %21
br label %27
27: ; preds = %21, %26
%28 = phi i32 [ 1, %26 ], [ 0, %21 ]
ret i32 %28
}