#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;
int getchar();
scalar_t__ out_of_range(int, int, int);
int /*<<< orphan*/ printf(char *);
int scanf(char *, int *);
int menu(void) {
  int option = 0;
  while (out_of_range(option, 1, 4)) {
    printf("Please chose from the options below:\n");
    printf("[1] Start\n");
    printf("[2] About\n");
    printf("[3] Help\n");
    printf("[4] Exit\n\n");
    if (scanf(" %d", &option) != 1) {
      int ch;
      while ((ch = getchar()) != '\n' && ch != EOF)
        ;
    }
    if (out_of_range(option, 1, 4))
      printf("Invalid entry, please try again.\n");
  }
  return option;
}


x86 assembly (clang, -O0):
<menu>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%edi
mov    $0x1,%esi
mov    $0x4,%edx
call   1060 <out_of_range@plt>
cmp    $0x0,%rax
je     1238 <menu+0xf8>
lea    0xe8e(%rip),%rdi
call   1030 <printf@plt>
lea    0xea8(%rip),%rdi
call   1030 <printf@plt>
lea    0xea7(%rip),%rdi
call   1030 <printf@plt>
lea    0xea6(%rip),%rdi
call   1030 <printf@plt>
lea    0xea4(%rip),%rdi
call   1030 <printf@plt>
lea    0xea3(%rip),%rdi
lea    -0x4(%rbp),%rsi
call   1050 <scanf@plt>
cmp    $0x1,%eax
je     120b <menu+0xcb>
jmp    11c5 <menu+0x85>
mov    $0x0,%al
call   1040 <getchar@plt>
mov    %eax,%ecx
mov    %ecx,-0x8(%rbp)
xor    %eax,%eax
cmp    $0xa,%ecx
mov    %al,-0x9(%rbp)
je     11f1 <menu+0xb1>
mov    -0x8(%rbp),%eax
mov    0x2dff(%rip),%rcx
cmp    (%rcx),%eax
setne  %al
mov    %al,-0x9(%rbp)
mov    -0x9(%rbp),%al
test   $0x1,%al
jne    1201 <menu+0xc1>
jmp    1206 <menu+0xc6>
jmp    11c5 <menu+0x85>
jmp    120b <menu+0xcb>
mov    -0x4(%rbp),%edi
mov    $0x1,%esi
mov    $0x4,%edx
call   1060 <out_of_range@plt>
cmp    $0x0,%rax
je     1233 <menu+0xf3>
lea    0xe27(%rip),%rdi
call   1030 <printf@plt>
jmp    114f <menu+0xf>
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<menu>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
movl   $0x0,0x4(%rsp)
xor    %ebx,%ebx
xor    %edi,%edi
mov    $0x1,%esi
mov    $0x4,%edx
call   1060 <out_of_range@plt>
test   %rax,%rax
je     1242 <menu+0x102>
lea    0xebd(%rip),%r12
lea    0xec0(%rip),%r13
lea    0xec2(%rip),%rbx
lea    0xe75(%rip),%rbp
lea    0x4(%rsp),%r14
mov    0x2e51(%rip),%r15
jmp    11bc <menu+0x7c>
nopl   0x0(%rax)
mov    0x4(%rsp),%edi
mov    $0x1,%esi
mov    $0x4,%edx
call   1060 <out_of_range@plt>
test   %rax,%rax
je     123e <menu+0xfe>
lea    0xe41(%rip),%rdi
call   1030 <puts@plt>
lea    0xe5a(%rip),%rdi
call   1030 <puts@plt>
mov    %r12,%rdi
call   1030 <puts@plt>
mov    %r13,%rdi
call   1030 <puts@plt>
mov    %rbx,%rdi
call   1030 <puts@plt>
mov    %rbp,%rdi
mov    %r14,%rsi
call   1050 <scanf@plt>
cmp    $0x1,%eax
je     1211 <menu+0xd1>
nopl   0x0(%rax)
xor    %eax,%eax
call   1040 <getchar@plt>
cmp    $0xa,%eax
je     1211 <menu+0xd1>
cmp    (%r15),%eax
jne    1200 <menu+0xc0>
mov    0x4(%rsp),%edi
mov    $0x1,%esi
mov    $0x4,%edx
call   1060 <out_of_range@plt>
test   %rax,%rax
je     11a0 <menu+0x60>
lea    0xe1c(%rip),%rdi
call   1030 <puts@plt>
jmp    11a0 <menu+0x60>
mov    0x4(%rsp),%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [38 x i8] c"Please chose from the options below:\0A\00"
@.str.1 = [11 x i8] c"[1] Start\0A\00"
@.str.2 = [11 x i8] c"[2] About\0A\00"
@.str.3 = [10 x i8] c"[3] Help\0A\00"
@.str.4 = [11 x i8] c"[4] Exit\0A\0A\00"
@.str.5 = [4 x i8] c" %d\00"
@EOF = global i32 0
@.str.6 = [34 x i8] c"Invalid entry, please try again.\0A\00"
define i32 @menu() {
%1 = alloca i32
%2 = alloca i32
store i32 0, i32* %1
br label %3
3: ; preds = %33, %0
%4 = load i32, i32* %1
%5 = call i64 @out_of_range(i32 %4, i32 1, i32 4)
%6 = icmp ne i64 %5, 0
br i1 %6, label %7, label %34
7: ; preds = %3
%8 = call i32 @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0))
%9 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
%10 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
%11 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0))
%12 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0))
%13 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i32* %1)
%14 = icmp ne i32 %13, 1
br i1 %14, label %15, label %27
15: ; preds = %7
br label %16
16: ; preds = %25, %15
%17 = call i32 (...) @getchar()
store i32 %17, i32* %2
%18 = icmp ne i32 %17, 10
br i1 %18, label %19, label %23
19: ; preds = %16
%20 = load i32, i32* %2
%21 = load i32, i32* @EOF
%22 = icmp ne i32 %20, %21
br label %23
23: ; preds = %19, %16
%24 = phi i1 [ false, %16 ], [ %22, %19 ]
br i1 %24, label %25, label %26
25: ; preds = %23
br label %16
26: ; preds = %23
br label %27
27: ; preds = %26, %7
%28 = load i32, i32* %1
%29 = call i64 @out_of_range(i32 %28, i32 1, i32 4)
%30 = icmp ne i64 %29, 0
br i1 %30, label %31, label %33
31: ; preds = %27
%32 = call i32 @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.6, i64 0, i64 0))
br label %33
33: ; preds = %31, %27
br label %3
34: ; preds = %3
%35 = load i32, i32* %1
ret i32 %35
}

LLVM IR (-O2):
@.str.5 = [4 x i8] c" %d\00"
@EOF = global i32 0
@str = [37 x i8] c"Please chose from the options below:\00"
@str.7 = [10 x i8] c"[1] Start\00"
@str.8 = [10 x i8] c"[2] About\00"
@str.9 = [9 x i8] c"[3] Help\00"
@str.10 = [10 x i8] c"[4] Exit\0A\00"
@str.11 = [33 x i8] c"Invalid entry, please try again.\00"
define i32 @menu() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
store i32 0, i32* %1
%3 = call i64 @out_of_range(i32 0, i32 1, i32 4)
%4 = icmp eq i64 %3, 0
br i1 %4, label %31, label %5
5: ; preds = %0, %25
%6 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @str, i64 0, i64 0))
%7 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @str.7, i64 0, i64 0))
%8 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @str.8, i64 0, i64 0))
%9 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @str.9, i64 0, i64 0))
%10 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @str.10, i64 0, i64 0))
%11 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i32* %1)
%12 = icmp eq i32 %11, 1
br i1 %12, label %19, label %13
13: ; preds = %5, %13
%14 = call i32 (...) @getchar()
%15 = icmp ne i32 %14, 10
%16 = load i32, i32* @EOF
%17 = icmp ne i32 %14, %16
%18 = select i1 %15, i1 %17, i1 false
br i1 %18, label %13, label %19
19: ; preds = %13, %5
%20 = load i32, i32* %1
%21 = call i64 @out_of_range(i32 %20, i32 1, i32 4)
%22 = icmp eq i64 %21, 0
br i1 %22, label %25, label %23
23: ; preds = %19
%24 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @str.11, i64 0, i64 0))
br label %25
25: ; preds = %23, %19
%26 = load i32, i32* %1
%27 = call i64 @out_of_range(i32 %26, i32 1, i32 4)
%28 = icmp eq i64 %27, 0
br i1 %28, label %29, label %5
29: ; preds = %25
%30 = load i32, i32* %1
br label %31
31: ; preds = %29, %0
%32 = phi i32 [ %30, %29 ], [ 0, %0 ]
ret i32 %32
}