#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 EOF;
char getchar();
int /*<<< orphan*/ puts(char *);
int /*<<< orphan*/ *strchr(char *, int);
int tolower(int);
char menu(void) {
  int ch;
  puts("Nerfville Pet Club Membership Program");
  puts("Enter the letter corresponding to your choice: ");
  puts("a) add a pet    l) show list of pets");
  puts("n) number of pets    f) find pets");
  puts("d) delete a pet    q) quit");
  while ((ch = getchar()) != EOF) {
    while (getchar() != '\n')
      continue;
    ch = tolower(ch);
    if (strchr("alrfndq", ch) == NULL)
      puts("Please enter an a, l, f, n, d, or q:");
    else
      break;
  }
  if (ch == EOF)
    ch = 'q';
  return ch;
}


x86 assembly (clang, -O0):
<menu>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    0xeb1(%rip),%rdi
call   1030 <puts@plt>
lea    0xecb(%rip),%rdi
call   1030 <puts@plt>
lea    0xeef(%rip),%rdi
call   1030 <puts@plt>
lea    0xf08(%rip),%rdi
call   1030 <puts@plt>
lea    0xf1e(%rip),%rdi
call   1030 <puts@plt>
mov    $0x0,%al
call   1050 <getchar@plt>
movsbl %al,%eax
mov    %eax,-0x4(%rbp)
mov    0x2e50(%rip),%rcx
cmp    (%rcx),%eax
je     11fc <menu+0xbc>
jmp    11a5 <menu+0x65>
mov    $0x0,%al
call   1050 <getchar@plt>
movsbl %al,%eax
cmp    $0xa,%eax
je     11bd <menu+0x7d>
jmp    11a5 <menu+0x65>
mov    -0x4(%rbp),%edi
call   1060 <tolower@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%esi
lea    0xee6(%rip),%rdi
call   1040 <strchr@plt>
cmp    $0x0,%rax
jne    11f2 <menu+0xb2>
lea    0xed8(%rip),%rdi
call   1030 <puts@plt>
jmp    11f7 <menu+0xb7>
jmp    11fc <menu+0xbc>
jmp    1184 <menu+0x44>
mov    -0x4(%rbp),%eax
mov    0x2de2(%rip),%rcx
cmp    (%rcx),%eax
jne    1215 <menu+0xd5>
movl   $0x71,-0x4(%rbp)
mov    -0x4(%rbp),%eax
movsbl %al,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<menu>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
lea    0xeb1(%rip),%rdi
call   1030 <puts@plt>
lea    0xecb(%rip),%rdi
call   1030 <puts@plt>
lea    0xeef(%rip),%rdi
call   1030 <puts@plt>
lea    0xf08(%rip),%rdi
call   1030 <puts@plt>
lea    0xf1e(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
call   1050 <getchar@plt>
movsbl %al,%ebx
mov    0x2e53(%rip),%r12
cmp    %ebx,(%r12)
jne    119f <menu+0x5f>
mov    %ebx,%ebp
jmp    11f3 <menu+0xb3>
lea    0xf12(%rip),%r15
lea    0xf13(%rip),%r14
nopl   (%rax)
xor    %eax,%eax
call   1050 <getchar@plt>
cmp    $0xa,%al
jne    11b0 <menu+0x70>
mov    %ebx,%edi
call   1060 <tolower@plt>
mov    %eax,%ebp
mov    %r15,%rdi
mov    %eax,%esi
call   1040 <strchr@plt>
test   %rax,%rax
jne    11ef <menu+0xaf>
mov    %r14,%rdi
call   1030 <puts@plt>
xor    %eax,%eax
call   1050 <getchar@plt>
movsbl %al,%ebx
mov    %ebx,%ebp
cmp    %ebx,(%r12)
jne    11b0 <menu+0x70>
jmp    11f3 <menu+0xb3>
mov    (%r12),%ebx
cmp    %ebx,%ebp
mov    $0x71,%eax
cmovne %ebp,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [38 x i8] c"Nerfville Pet Club Membership Program\00"
@.str.1 = [48 x i8] c"Enter the letter corresponding to your choice: \00"
@.str.2 = [37 x i8] c"a) add a pet l) show list of pets\00"
@.str.3 = [34 x i8] c"n) number of pets f) find pets\00"
@.str.4 = [27 x i8] c"d) delete a pet q) quit\00"
@EOF = global i32 0
@.str.5 = [8 x i8] c"alrfndq\00"
@.str.6 = [37 x i8] c"Please enter an a, l, f, n, d, or q:\00"
define signext i8 @menu() {
%1 = alloca i32
%2 = call i32 @puts(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0))
%3 = call i32 @puts(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.1, i64 0, i64 0))
%4 = call i32 @puts(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.2, i64 0, i64 0))
%5 = call i32 @puts(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.3, i64 0, i64 0))
%6 = call i32 @puts(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.4, i64 0, i64 0))
br label %7
7: ; preds = %27, %0
%8 = call signext i8 (...) @getchar()
%9 = sext i8 %8 to i32
store i32 %9, i32* %1
%10 = load i32, i32* @EOF
%11 = icmp ne i32 %9, %10
br i1 %11, label %12, label %28
12: ; preds = %7
br label %13
13: ; preds = %17, %12
%14 = call signext i8 (...) @getchar()
%15 = sext i8 %14 to i32
%16 = icmp ne i32 %15, 10
br i1 %16, label %17, label %18
17: ; preds = %13
br label %13
18: ; preds = %13
%19 = load i32, i32* %1
%20 = call i32 @tolower(i32 %19)
store i32 %20, i32* %1
%21 = load i32, i32* %1
%22 = call i32* @strchr(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0), i32 %21)
%23 = icmp eq i32* %22, null
br i1 %23, label %24, label %26
24: ; preds = %18
%25 = call i32 @puts(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.6, i64 0, i64 0))
br label %27
26: ; preds = %18
br label %28
27: ; preds = %24
br label %7
28: ; preds = %26, %7
%29 = load i32, i32* %1
%30 = load i32, i32* @EOF
%31 = icmp eq i32 %29, %30
br i1 %31, label %32, label %33
32: ; preds = %28
store i32 113, i32* %1
br label %33
33: ; preds = %32, %28
%34 = load i32, i32* %1
%35 = trunc i32 %34 to i8
ret i8 %35
}

LLVM IR (-O2):
@.str = [38 x i8] c"Nerfville Pet Club Membership Program\00"
@.str.1 = [48 x i8] c"Enter the letter corresponding to your choice: \00"
@.str.2 = [37 x i8] c"a) add a pet l) show list of pets\00"
@.str.3 = [34 x i8] c"n) number of pets f) find pets\00"
@.str.4 = [27 x i8] c"d) delete a pet q) quit\00"
@EOF = global i32 0
@.str.5 = [8 x i8] c"alrfndq\00"
@.str.6 = [37 x i8] c"Please enter an a, l, f, n, d, or q:\00"
define signext i8 @menu() {
%1 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0))
%2 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([48 x i8], [48 x i8]* @.str.1, i64 0, i64 0))
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @.str.2, i64 0, i64 0))
%4 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @.str.3, i64 0, i64 0))
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.4, i64 0, i64 0))
%6 = tail call signext i8 (...) @getchar()
%7 = sext i8 %6 to i32
%8 = load i32, i32* @EOF
%9 = icmp eq i32 %8, %7
br i1 %9, label %27, label %10
10: ; preds = %0, %21
%11 = phi i32 [ %24, %21 ], [ %7, %0 ]
br label %12
12: ; preds = %10, %12
%13 = tail call signext i8 (...) @getchar()
%14 = icmp eq i8 %13, 10
br i1 %14, label %15, label %12
15: ; preds = %12
%16 = tail call i32 @tolower(i32 %11)
%17 = tail call i32* @strchr(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0), i32 %16)
%18 = icmp eq i32* %17, null
br i1 %18, label %21, label %19
19: ; preds = %15
%20 = load i32, i32* @EOF
br label %27
21: ; preds = %15
%22 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @.str.6, i64 0, i64 0))
%23 = tail call signext i8 (...) @getchar()
%24 = sext i8 %23 to i32
%25 = load i32, i32* @EOF
%26 = icmp eq i32 %25, %24
br i1 %26, label %27, label %10
27: ; preds = %21, %19, %0
%28 = phi i32 [ %7, %0 ], [ %20, %19 ], [ %24, %21 ]
%29 = phi i32 [ %7, %0 ], [ %16, %19 ], [ %24, %21 ]
%30 = icmp eq i32 %29, %28
%31 = trunc i32 %29 to i8
%32 = select i1 %30, i8 113, i8 %31
ret i8 %32
}