#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 atoi(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, char *);
int /*<<< orphan*/ system(char *);
int menu(void) {
  char choice[80];
  int choice_value = 0;
  while (choice_value < 1 || choice_value > 4) {
    system("clear");
    printf("\t\tSPIDY MASTER CONTROLLER\n");
    printf("1.Calibrate\n2.Test\n3.Walk\n4.Quit\n\nMake your choice: ");
    scanf("%s%*[^\n]*", &choice[0]);
    if (choice[0] == 'q' || choice[0] == 'Q')
      choice_value = 4;
    else
      choice_value = atoi(choice);
    printf("You choose %i\n", choice_value);
  }
  return choice_value;
}


x86 assembly (clang, -O0):
<menu>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x54(%rbp)
mov    $0x1,%al
cmpl   $0x1,-0x54(%rbp)
mov    %al,-0x55(%rbp)
jl     1168 <menu+0x28>
cmpl   $0x4,-0x54(%rbp)
setg   %al
mov    %al,-0x55(%rbp)
mov    -0x55(%rbp),%al
test   $0x1,%al
jne    1178 <menu+0x38>
jmp    11f8 <menu+0xb8>
lea    0xe81(%rip),%rdi
call   1030 <system@plt>
lea    0xe7b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe88(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x50(%rbp),%rsi
lea    0xeab(%rip),%rdi
call   1050 <scanf@plt>
movsbl -0x50(%rbp),%eax
cmp    $0x71,%eax
je     11ca <menu+0x8a>
movsbl -0x50(%rbp),%eax
cmp    $0x51,%eax
jne    11d6 <menu+0x96>
movl   $0x4,-0x54(%rbp)
jmp    11e2 <menu+0xa2>
lea    -0x50(%rbp),%rdi
call   1060 <atoi@plt>
mov    %eax,-0x54(%rbp)
mov    -0x54(%rbp),%esi
lea    0xe74(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    114f <menu+0xf>
mov    -0x54(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<menu>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x58,%rsp
lea    0xeef(%rip),%r15
lea    0xe9a(%rip),%r12
lea    0xec8(%rip),%r13
mov    %rsp,%rbx
lea    0xec8(%rip),%rbp
nopl   (%rax)
lea    0xe79(%rip),%rdi
call   1040 <system@plt>
mov    %r15,%rdi
call   1030 <puts@plt>
mov    %r12,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r13,%rdi
mov    %rbx,%rsi
call   1060 <scanf@plt>
movzbl (%rsp),%eax
and    $0xdf,%al
cmp    $0x51,%al
je     11d5 <menu+0x85>
mov    %rbx,%rdi
call   1070 <atoi@plt>
mov    %eax,%r14d
mov    %rbp,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
lea    -0x5(%r14),%eax
cmp    $0xfffffffc,%eax
jb     1180 <menu+0x30>
jmp    11ee <menu+0x9e>
lea    0xe69(%rip),%rdi
mov    $0x4,%r14d
mov    $0x4,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r14d,%eax
add    $0x58,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [6 x i8] c"clear\00"
@.str.1 = [27 x i8] c"\09\09SPIDY MASTER CONTROLLER\0A\00"
@.str.2 = [53 x i8] c"1.Calibrate\0A2.Test\0A3.Walk\0A4.Quit\0A\0AMake your choice: \00"
@.str.3 = [10 x i8] c"%s%*[^\0A]*\00"
@.str.4 = [15 x i8] c"You choose %i\0A\00"
define i32 @menu() {
%1 = alloca [80 x i8]
%2 = alloca i32
store i32 0, i32* %2
br label %3
3: ; preds = %30, %0
%4 = load i32, i32* %2
%5 = icmp slt i32 %4, 1
br i1 %5, label %9, label %6
6: ; preds = %3
%7 = load i32, i32* %2
%8 = icmp sgt i32 %7, 4
br label %9
9: ; preds = %6, %3
%10 = phi i1 [ true, %3 ], [ %8, %6 ]
br i1 %10, label %11, label %33
11: ; preds = %9
%12 = call i32 @system(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0))
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.2, i64 0, i64 0))
%15 = getelementptr inbounds [80 x i8], [80 x i8]* %1, i64 0, i64 0
%16 = call i32 @scanf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i8* %15)
%17 = getelementptr inbounds [80 x i8], [80 x i8]* %1, i64 0, i64 0
%18 = load i8, i8* %17
%19 = sext i8 %18 to i32
%20 = icmp eq i32 %19, 113
br i1 %20, label %26, label %21
21: ; preds = %11
%22 = getelementptr inbounds [80 x i8], [80 x i8]* %1, i64 0, i64 0
%23 = load i8, i8* %22
%24 = sext i8 %23 to i32
%25 = icmp eq i32 %24, 81
br i1 %25, label %26, label %27
26: ; preds = %21, %11
store i32 4, i32* %2
br label %30
27: ; preds = %21
%28 = getelementptr inbounds [80 x i8], [80 x i8]* %1, i64 0, i64 0
%29 = call i32 @atoi(i8* %28)
store i32 %29, i32* %2
br label %30
30: ; preds = %27, %26
%31 = load i32, i32* %2
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0), i32 %31)
br label %3
33: ; preds = %9
%34 = load i32, i32* %2
ret i32 %34
}

LLVM IR (-O2):
@.str = [6 x i8] c"clear\00"
@.str.2 = [53 x i8] c"1.Calibrate\0A2.Test\0A3.Walk\0A4.Quit\0A\0AMake your choice: \00"
@.str.3 = [10 x i8] c"%s%*[^\0A]*\00"
@.str.4 = [15 x i8] c"You choose %i\0A\00"
@str = [26 x i8] c"\09\09SPIDY MASTER CONTROLLER\00"
define i32 @menu() {
%1 = alloca [80 x i8]
%2 = getelementptr inbounds [80 x i8], [80 x i8]* %1, i64 0, i64 0
br label %3
3: ; preds = %0, %13
%4 = call i32 @system(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%5 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str, i64 0, i64 0))
%6 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([53 x i8], [53 x i8]* @.str.2, i64 0, i64 0))
%7 = call i32 @scanf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i8* %2)
%8 = load i8, i8* %2
%9 = and i8 %8, -33
%10 = icmp eq i8 %9, 81
br i1 %10, label %11, label %13
11: ; preds = %3
%12 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0), i32 4)
br label %18
13: ; preds = %3
%14 = call i32 @atoi(i8* %2)
%15 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0), i32 %14)
%16 = add i32 %14, -5
%17 = icmp ult i32 %16, -4
br i1 %17, label %3, label %18
18: ; preds = %13, %11
%19 = phi i32 [ 4, %11 ], [ %14, %13 ]
ret i32 %19
}