#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 */
char getchar();
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ scanf(char *, int *);
int menu() {
  printf("Card Catalog:\n");
  printf("\n");
  printf("1: Enter\n");
  printf("2: Search by Author\n");
  printf("3: Search by Title\n");
  printf("4: Quit\n");
  printf("\n");
  printf(":");
  int code;
  scanf("%d", &code);
  while (getchar() != '\n') {
  }
  if (!(1 <= code && code <= 4)) {
    return 0;
  }
  return code;
}


x86 assembly (clang, -O0):
<menu>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    0xec1(%rip),%rdi
call   1030 <printf@plt>
lea    0xec2(%rip),%rdi
call   1030 <printf@plt>
lea    0xeb8(%rip),%rdi
call   1030 <printf@plt>
lea    0xeb6(%rip),%rdi
call   1030 <printf@plt>
lea    0xebf(%rip),%rdi
call   1030 <printf@plt>
lea    0xec7(%rip),%rdi
call   1030 <printf@plt>
lea    0xe86(%rip),%rdi
call   1030 <printf@plt>
lea    0xeb8(%rip),%rdi
call   1030 <printf@plt>
lea    0xeae(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1050 <scanf@plt>
mov    $0x0,%al
call   1040 <getchar@plt>
movsbl %al,%eax
cmp    $0xa,%eax
je     11c0 <menu+0x90>
jmp    11a8 <menu+0x78>
mov    $0x1,%eax
cmp    -0x8(%rbp),%eax
jg     11d8 <menu+0xa8>
cmpl   $0x4,-0x8(%rbp)
jle    11e4 <menu+0xb4>
movl   $0x0,-0x4(%rbp)
jmp    11ea <menu+0xba>
mov    -0x8(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<menu>:
push   %rax
lea    0xebb(%rip),%rdi
call   1040 <puts@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
lea    0xeb3(%rip),%rdi
call   1040 <puts@plt>
lea    0xeb0(%rip),%rdi
call   1040 <puts@plt>
lea    0xeb8(%rip),%rdi
call   1040 <puts@plt>
lea    0xebf(%rip),%rdi
call   1040 <puts@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    $0x3a,%edi
call   1030 <putchar@plt>
lea    0xe5e(%rip),%rdi
lea    0x4(%rsp),%rsi
call   1060 <scanf@plt>
nopl   0x0(%rax)
xor    %eax,%eax
call   1050 <getchar@plt>
cmp    $0xa,%al
jne    11b0 <menu+0x70>
mov    0x4(%rsp),%ecx
lea    -0x1(%rcx),%edx
xor    %eax,%eax
cmp    $0x4,%edx
cmovb  %ecx,%eax
pop    %rcx
ret

LLVM IR (-O0):
@.str = [15 x i8] c"Card Catalog:\0A\00"
@.str.1 = [2 x i8] c"\0A\00"
@.str.2 = [10 x i8] c"1: Enter\0A\00"
@.str.3 = [21 x i8] c"2: Search by Author\0A\00"
@.str.4 = [20 x i8] c"3: Search by Title\0A\00"
@.str.5 = [9 x i8] c"4: Quit\0A\00"
@.str.6 = [2 x i8] c":\00"
@.str.7 = [3 x i8] c"%d\00"
define i32 @menu() {
%1 = alloca i32
%2 = alloca i32
%3 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
%4 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%5 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0))
%6 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0))
%7 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0))
%8 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0))
%9 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%10 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
%11 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0), i32* %2)
br label %12
12: ; preds = %16, %0
%13 = call signext i8 (...) @getchar()
%14 = sext i8 %13 to i32
%15 = icmp ne i32 %14, 10
br i1 %15, label %16, label %17
16: ; preds = %12
br label %12
17: ; preds = %12
%18 = load i32, i32* %2
%19 = icmp sle i32 1, %18
br i1 %19, label %20, label %23
20: ; preds = %17
%21 = load i32, i32* %2
%22 = icmp sle i32 %21, 4
br i1 %22, label %24, label %23
23: ; preds = %20, %17
store i32 0, i32* %1
br label %26
24: ; preds = %20
%25 = load i32, i32* %2
store i32 %25, i32* %1
br label %26
26: ; preds = %24, %23
%27 = load i32, i32* %1
ret i32 %27
}

LLVM IR (-O2):
@.str.7 = [3 x i8] c"%d\00"
@str = [14 x i8] c"Card Catalog:\00"
@str.8 = [9 x i8] c"1: Enter\00"
@str.9 = [20 x i8] c"2: Search by Author\00"
@str.10 = [19 x i8] c"3: Search by Title\00"
@str.11 = [8 x i8] c"4: Quit\00"
define i32 @menu() {
%1 = alloca i32
%2 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @str, i64 0, i64 0))
%3 = tail call i32 @putchar(i32 10)
%4 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @str.8, i64 0, i64 0))
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str.9, i64 0, i64 0))
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str.10, i64 0, i64 0))
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @str.11, i64 0, i64 0))
%8 = tail call i32 @putchar(i32 10)
%9 = tail call i32 @putchar(i32 58)
%10 = bitcast i32* %1 to i8*
%11 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0), i32* %1)
br label %12
12: ; preds = %12, %0
%13 = call signext i8 (...) @getchar()
%14 = icmp eq i8 %13, 10
br i1 %14, label %15, label %12
15: ; preds = %12
%16 = load i32, i32* %1
%17 = add i32 %16, -1
%18 = icmp ult i32 %17, 4
%19 = select i1 %18, i32 %16, i32 0
ret i32 %19
}