#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*/ printf(char *);
int scanf(char *, ...);
int menu(void) {
  int choice = -1;
  do {
    printf("***** STACK INTERFACE *****\n\n");
    printf("1) Push on stack.\n");
    printf("2) Pop from the stack.\n");
    printf("3) Lookup top of the stack.\n");
    printf("4) Print stack.\n");
    printf("5) Quit.\n");
    printf("***************************\n");
    if (scanf("%d", &choice) != 1)
      scanf("%*s");
  } while (choice < 1 || choice > 5);
  return choice;
}


x86 assembly (clang, -O0):
<menu>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0xffffffff,-0x4(%rbp)
lea    0xeca(%rip),%rdi
call   1030 <printf@plt>
lea    0xedc(%rip),%rdi
call   1030 <printf@plt>
lea    0xee3(%rip),%rdi
call   1030 <printf@plt>
lea    0xeef(%rip),%rdi
call   1030 <printf@plt>
lea    0xf00(%rip),%rdi
call   1030 <printf@plt>
lea    0xf05(%rip),%rdi
call   1030 <printf@plt>
lea    0xf03(%rip),%rdi
call   1030 <printf@plt>
lea    0xf14(%rip),%rdi
lea    -0x4(%rbp),%rsi
mov    $0x0,%al
call   1040 <scanf@plt>
cmp    $0x1,%eax
je     11ac <menu+0x8c>
lea    0xefc(%rip),%rdi
mov    $0x0,%al
call   1040 <scanf@plt>
jmp    11b1 <menu+0x91>
mov    $0x1,%al
cmpl   $0x1,-0x4(%rbp)
mov    %al,-0x5(%rbp)
jl     11ca <menu+0xaa>
cmpl   $0x5,-0x4(%rbp)
setg   %al
mov    %al,-0x5(%rbp)
mov    -0x5(%rbp),%al
test   $0x1,%al
jne    112f <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   $0xffffffff,0x4(%rsp)
ff
lea    0xf13(%rip),%r13
lea    0xf28(%rip),%rbx
lea    0xf31(%rip),%rbp
lea    0xf33(%rip),%r14
lea    0xeaa(%rip),%r15
lea    0x4(%rsp),%r12
jmp    116c <menu+0x4c>
nopl   (%rax)
mov    0x4(%rsp),%eax
lea    -0x6(%rax),%ecx
cmp    $0xfffffffb,%ecx
jae    11d2 <menu+0xb2>
lea    0xe94(%rip),%rdi
call   1030 <puts@plt>
lea    0xea5(%rip),%rdi
call   1030 <puts@plt>
lea    0xeab(%rip),%rdi
call   1030 <puts@plt>
mov    %r13,%rdi
call   1030 <puts@plt>
mov    %rbx,%rdi
call   1030 <puts@plt>
mov    %rbp,%rdi
call   1030 <puts@plt>
mov    %r14,%rdi
call   1030 <puts@plt>
mov    %r15,%rdi
mov    %r12,%rsi
xor    %eax,%eax
call   1040 <scanf@plt>
cmp    $0x1,%eax
je     1160 <menu+0x40>
lea    0xe3a(%rip),%rdi
xor    %eax,%eax
call   1040 <scanf@plt>
jmp    1160 <menu+0x40>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [30 x i8] c"***** STACK INTERFACE *****\0A\0A\00"
@.str.1 = [19 x i8] c"1) Push on stack.\0A\00"
@.str.2 = [24 x i8] c"2) Pop from the stack.\0A\00"
@.str.3 = [29 x i8] c"3) Lookup top of the stack.\0A\00"
@.str.4 = [17 x i8] c"4) Print stack.\0A\00"
@.str.5 = [10 x i8] c"5) Quit.\0A\00"
@.str.6 = [29 x i8] c"***************************\0A\00"
@.str.7 = [3 x i8] c"%d\00"
@.str.8 = [4 x i8] c"%*s\00"
define i32 @menu() {
%1 = alloca i32
store i32 -1, i32* %1
br label %2
2: ; preds = %21, %0
%3 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
%4 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
%5 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0))
%6 = call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0))
%7 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0))
%8 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.5, i64 0, i64 0))
%9 = call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.6, i64 0, i64 0))
%10 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0), i32* %1)
%11 = icmp ne i32 %10, 1
br i1 %11, label %12, label %14
12: ; preds = %2
%13 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.8, i64 0, i64 0))
br label %14
14: ; preds = %12, %2
br label %15
15: ; preds = %14
%16 = load i32, i32* %1
%17 = icmp slt i32 %16, 1
br i1 %17, label %21, label %18
18: ; preds = %15
%19 = load i32, i32* %1
%20 = icmp sgt i32 %19, 5
br label %21
21: ; preds = %18, %15
%22 = phi i1 [ true, %15 ], [ %20, %18 ]
br i1 %22, label %2, label %23
23: ; preds = %21
%24 = load i32, i32* %1
ret i32 %24
}

LLVM IR (-O2):
@.str.7 = [3 x i8] c"%d\00"
@.str.8 = [4 x i8] c"%*s\00"
@str = [29 x i8] c"***** STACK INTERFACE *****\0A\00"
@str.9 = [18 x i8] c"1) Push on stack.\00"
@str.10 = [23 x i8] c"2) Pop from the stack.\00"
@str.11 = [28 x i8] c"3) Lookup top of the stack.\00"
@str.12 = [16 x i8] c"4) Print stack.\00"
@str.13 = [9 x i8] c"5) Quit.\00"
@str.14 = [28 x i8] c"***************************\00"
define i32 @menu() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
store i32 -1, i32* %1
br label %3
3: ; preds = %15, %0
%4 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @str, i64 0, i64 0))
%5 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str.9, i64 0, i64 0))
%6 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str.10, i64 0, i64 0))
%7 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @str.11, i64 0, i64 0))
%8 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str.12, i64 0, i64 0))
%9 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @str.13, i64 0, i64 0))
%10 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @str.14, i64 0, i64 0))
%11 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0), i32* %1)
%12 = icmp eq i32 %11, 1
br i1 %12, label %15, label %13
13: ; preds = %3
%14 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.8, i64 0, i64 0))
br label %15
15: ; preds = %3, %13
%16 = load i32, i32* %1
%17 = add i32 %16, -6
%18 = icmp ult i32 %17, -5
br i1 %18, label %3, label %19
19: ; preds = %15
ret i32 %16
}