#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 *calloc(int, int);
int /*<<< orphan*/ exit(int);
int menu();
int /*<<< orphan*/ pause_t();
int pop(int *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ push(int *, int);
int /*<<< orphan*/ refresh();
int /*<<< orphan*/ scanf(char *, int *);
int /*<<< orphan*/ view(int *);
int main() {
  int *ARR = calloc(10, sizeof(int));
  refresh();
  while (1) {
    int data, val, num;
    data = menu();
    switch (data) {
    case 1:
      printf("ENter an element to be pushed into the stack:-\n");
      scanf("%d", &val);
      push(ARR, val);
      break;
    case 2:
      num = pop(ARR);
      printf("\n Popped element is = %d\n", num);
      pause_t();
      break;
    case 3:
      view(ARR);
      pause_t();
      break;
    default:
      exit(1);
    }
    refresh();
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0xa,%edi
mov    $0x4,%esi
call   1070 <calloc@plt>
mov    %rax,-0x10(%rbp)
mov    $0x0,%al
call   1080 <refresh@plt>
xor    %eax,%eax
call   1030 <menu@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x20(%rbp)
sub    $0x1,%eax
je     1209 <main+0x69>
jmp    11e7 <main+0x47>
mov    -0x20(%rbp),%eax
sub    $0x2,%eax
je     1238 <main+0x98>
jmp    11f8 <main+0x58>
mov    -0x20(%rbp),%eax
sub    $0x3,%eax
je     1261 <main+0xc1>
jmp    1276 <main+0xd6>
lea    0xdf0(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xe12(%rip),%rdi
lea    -0x18(%rbp),%rsi
call   1090 <scanf@plt>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%esi
call   10a0 <push@plt>
jmp    1280 <main+0xe0>
mov    -0x10(%rbp),%rdi
call   1060 <pop@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%esi
lea    0xde5(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x0,%al
call   1040 <pause_t@plt>
jmp    1280 <main+0xe0>
mov    -0x10(%rbp),%rdi
call   10b0 <view@plt>
mov    $0x0,%al
call   1040 <pause_t@plt>
jmp    1280 <main+0xe0>
mov    $0x1,%edi
call   10c0 <exit@plt>
mov    $0x0,%al
call   1080 <refresh@plt>
jmp    11c9 <main+0x29>

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    $0xa,%edi
mov    $0x4,%esi
call   1080 <calloc@plt>
mov    %rax,%rbx
xor    %eax,%eax
call   1090 <refresh@plt>
lea    0xe26(%rip),%r14
lea    0xe39(%rip),%r15
lea    0xe15(%rip),%r12
lea    0xc(%rsp),%r13
jmp    1222 <main+0x72>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %rbx,%rdi
call   1070 <pop@plt>
mov    %r14,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1060 <printf@plt>
xor    %eax,%eax
call   1050 <pause_t@plt>
xor    %eax,%eax
call   1090 <refresh@plt>
xor    %eax,%eax
call   1040 <menu@plt>
cmp    $0x3,%eax
je     1260 <main+0xb0>
cmp    $0x2,%eax
je     1200 <main+0x50>
cmp    $0x1,%eax
jne    126a <main+0xba>
mov    %r15,%rdi
call   1030 <puts@plt>
mov    %r12,%rdi
mov    %r13,%rsi
call   10a0 <scanf@plt>
mov    0xc(%rsp),%esi
mov    %rbx,%rdi
call   10b0 <push@plt>
jmp    121b <main+0x6b>
nopl   0x0(%rax)
mov    %rbx,%rdi
call   10c0 <view@plt>
jmp    1214 <main+0x64>
mov    $0x1,%edi
call   10d0 <exit@plt>

LLVM IR (-O0):
@.str = [48 x i8] c"ENter an element to be pushed into the stack:-\0A\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [26 x i8] c"\0A Popped element is = %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 0, i32* %1
%6 = call i32* @calloc(i32 10, i32 4)
store i32* %6, i32** %2
%7 = call i32 (...) @refresh()
br label %8
8: ; preds = %0, %29
%9 = call i32 (...) @menu()
store i32 %9, i32* %3
%10 = load i32, i32* %3
switch i32 %10, label %27 [
i32 1, label %11
i32 2, label %17
i32 3, label %23
]
11: ; preds = %8
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str, i64 0, i64 0))
%13 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %4)
%14 = load i32*, i32** %2
%15 = load i32, i32* %4
%16 = call i32 @push(i32* %14, i32 %15)
br label %29
17: ; preds = %8
%18 = load i32*, i32** %2
%19 = call i32 @pop(i32* %18)
store i32 %19, i32* %5
%20 = load i32, i32* %5
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0), i32 %20)
%22 = call i32 (...) @pause_t()
br label %29
23: ; preds = %8
%24 = load i32*, i32** %2
%25 = call i32 @view(i32* %24)
%26 = call i32 (...) @pause_t()
br label %29
27: ; preds = %8
%28 = call i32 @exit(i32 1)
unreachable
29: ; preds = %23, %17, %11
%30 = call i32 (...) @refresh()
br label %8
}

LLVM IR (-O2):
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [26 x i8] c"\0A Popped element is = %d\0A\00"
@str = [47 x i8] c"ENter an element to be pushed into the stack:-\00"
define i32 @main() {
%1 = alloca i32
%2 = tail call i32* @calloc(i32 10, i32 4)
%3 = tail call i32 (...) @refresh()
%4 = bitcast i32* %1 to i8*
br label %5
5: ; preds = %21, %0
%6 = call i32 (...) @menu()
switch i32 %6, label %19 [
i32 1, label %7
i32 2, label %12
i32 3, label %16
]
7: ; preds = %5
%8 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([47 x i8], [47 x i8]* @str, i64 0, i64 0))
%9 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%10 = load i32, i32* %1
%11 = call i32 @push(i32* %2, i32 %10)
br label %21
12: ; preds = %5
%13 = call i32 @pop(i32* %2)
%14 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0), i32 %13)
%15 = call i32 (...) @pause_t()
br label %21
16: ; preds = %5
%17 = call i32 @view(i32* %2)
%18 = call i32 (...) @pause_t()
br label %21
19: ; preds = %5
%20 = call i32 @exit(i32 1)
unreachable
21: ; preds = %16, %12, %7
%22 = call i32 (...) @refresh()
br label %5
}