#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*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ pop();
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ push(int);
int /*<<< orphan*/ scanf(char *, int *);
int /*<<< orphan*/ showStack();
void menu() {
  int option, input;
  printf("\n1. Push\n2. Pop\n3. Show Stack\n4. Exit\n\n");
  scanf("%d", &option);
  switch (option) {
  case 1:
    printf("\n\nInput: ");
    scanf("%d", &input);
    push(input);
    break;
  case 2:
    pop();
    break;
  case 3:
    showStack();
    break;
  case 4:
    exit(0);
  default:
    printf("\nError: Please enter a valid option.\n");
  }
}


x86 assembly (clang, -O0):
<menu>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    0xea1(%rip),%rdi
call   1030 <printf@plt>
lea    0xebd(%rip),%rdi
lea    -0x4(%rbp),%rsi
call   1050 <scanf@plt>
mov    -0x4(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,%ecx
mov    %rcx,-0x10(%rbp)
sub    $0x3,%eax
ja     11f5 <menu+0x95>
mov    -0x10(%rbp),%rax
lea    0xe5c(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
lea    0xe87(%rip),%rdi
call   1030 <printf@plt>
lea    0xe78(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1050 <scanf@plt>
mov    -0x8(%rbp),%edi
call   1060 <push@plt>
jmp    1201 <menu+0xa1>
mov    $0x0,%al
call   1040 <pop@plt>
jmp    1201 <menu+0xa1>
mov    $0x0,%al
call   1070 <showStack@plt>
jmp    1201 <menu+0xa1>
xor    %edi,%edi
call   1080 <exit@plt>
lea    0xe49(%rip),%rdi
call   1030 <printf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<menu>:
push   %rax
lea    0xea5(%rip),%rdi
call   1030 <puts@plt>
lea    0xe8c(%rip),%rdi
lea    0x4(%rsp),%rsi
call   1060 <scanf@plt>
mov    0x4(%rsp),%eax
add    $0xffffffff,%eax
cmp    $0x3,%eax
ja     11cf <menu+0x5f>
lea    0xe5f(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
lea    0xe62(%rip),%rdi
call   1040 <printf@plt>
lea    0xe53(%rip),%rdi
mov    %rsp,%rsi
call   1060 <scanf@plt>
mov    (%rsp),%edi
call   1070 <push@plt>
pop    %rax
ret
lea    0xe6e(%rip),%rdi
call   1030 <puts@plt>
pop    %rax
ret
xor    %eax,%eax
call   1050 <pop@plt>
pop    %rax
ret
xor    %eax,%eax
call   1080 <showStack@plt>
pop    %rax
ret
xor    %edi,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@.str = [40 x i8] c"\0A1. Push\0A2. Pop\0A3. Show Stack\0A4. Exit\0A\0A\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [10 x i8] c"\0A\0AInput: \00"
@.str.3 = [38 x i8] c"\0AError: Please enter a valid option.\0A\00"
define void @menu() {
%1 = alloca i32
%2 = alloca i32
%3 = call i32 @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0))
%4 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%5 = load i32, i32* %1
switch i32 %5, label %17 [
i32 1, label %6
i32 2, label %11
i32 3, label %13
i32 4, label %15
]
6: ; preds = %0
%7 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0))
%8 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %2)
%9 = load i32, i32* %2
%10 = call i32 @push(i32 %9)
br label %19
11: ; preds = %0
%12 = call i32 (...) @pop()
br label %19
13: ; preds = %0
%14 = call i32 (...) @showStack()
br label %19
15: ; preds = %0
%16 = call i32 @exit(i32 0)
unreachable
17: ; preds = %0
%18 = call i32 @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.3, i64 0, i64 0))
br label %19
19: ; preds = %17, %13, %11, %6
ret void
}

LLVM IR (-O2):
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [10 x i8] c"\0A\0AInput: \00"
@str = [39 x i8] c"\0A1. Push\0A2. Pop\0A3. Show Stack\0A4. Exit\0A\00"
@str.4 = [37 x i8] c"\0AError: Please enter a valid option.\00"
define void @menu() {
%1 = alloca i32
%2 = alloca i32
%3 = bitcast i32* %1 to i8*
%4 = bitcast i32* %2 to i8*
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @str, i64 0, i64 0))
%6 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%7 = load i32, i32* %1
switch i32 %7, label %19 [
i32 1, label %8
i32 2, label %13
i32 3, label %15
i32 4, label %17
]
8: ; preds = %0
%9 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0))
%10 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %2)
%11 = load i32, i32* %2
%12 = call i32 @push(i32 %11)
br label %21
13: ; preds = %0
%14 = call i32 (...) @pop()
br label %21
15: ; preds = %0
%16 = call i32 (...) @showStack()
br label %21
17: ; preds = %0
%18 = call i32 @exit(i32 0)
unreachable
19: ; preds = %0
%20 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @str.4, i64 0, i64 0))
br label %21
21: ; preds = %19, %15, %13, %8
ret void
}