#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*/ display(int *, unsigned int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int pop(unsigned int *, int *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ push(int, unsigned int *, int *);
int /*<<< orphan*/ scanf(char *, int *);
int /*<<< orphan*/ stempty(unsigned int);
int /*<<< orphan*/ stfull(unsigned int);
int main() {
  unsigned int top = 0;
  int stack[5] = {0};
  int value;
  int item;
  char ans;
  printf("\n Stack example");
  while (1) {
    printf("\nMain Menu");
    printf("\n1.Push \n2.Pop \n3.Display \n4.exit");
    printf("\nEnter Your Choice");
    scanf("%d", &value);
    switch (value) {
    case 1:
      printf("\nEnter The item to be pushed");
      if (!scanf("%d", &item)) {
        printf("Invalid input \n");
        exit(0);
      }
      if (stfull(top))
        printf("\nStack is Full!");
      else
        push(item, &top, stack);
      break;
    case 2:
      if (stempty(top))
        printf("\nEmpty stack!!!");
      else {
        item = pop(&top, stack);
        printf("\nThe popped element is %d", item);
      }
      break;
    case 3:
      display(stack, top);
      break;
    case 4:
      exit(0);
    default:
      printf("invalid input \n");
      exit(0);
    }
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
lea    -0x20(%rbp),%rdi
xor    %esi,%esi
mov    $0x14,%edx
call   1070 <memset@plt>
lea    0xe53(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe55(%rip),%rdi
xor    %eax,%eax
mov    %al,-0x39(%rbp)
call   1040 <printf@plt>
mov    -0x39(%rbp),%al
lea    0xe4c(%rip),%rdi
call   1040 <printf@plt>
mov    -0x39(%rbp),%al
lea    0xe5f(%rip),%rdi
call   1040 <printf@plt>
lea    0xeca(%rip),%rdi
lea    -0x24(%rbp),%rsi
call   1090 <scanf@plt>
mov    -0x24(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,%ecx
mov    %rcx,-0x38(%rbp)
sub    $0x3,%eax
ja     1303 <main+0x173>
mov    -0x38(%rbp),%rax
lea    0xddd(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
lea    0xe2d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe83(%rip),%rdi
lea    -0x28(%rbp),%rsi
call   1090 <scanf@plt>
cmp    $0x0,%eax
jne    1268 <main+0xd8>
lea    0xe23(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %edi,%edi
call   10b0 <exit@plt>
mov    -0x8(%rbp),%edi
call   1050 <stfull@plt>
cmp    $0x0,%eax
je     128c <main+0xfc>
lea    0xe0d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    129c <main+0x10c>
mov    -0x28(%rbp),%edi
lea    -0x20(%rbp),%rdx
lea    -0x8(%rbp),%rsi
call   10a0 <push@plt>
jmp    1318 <main+0x188>
mov    -0x8(%rbp),%edi
call   1060 <stempty@plt>
cmp    $0x0,%eax
je     12c5 <main+0x135>
lea    0xde4(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    12e6 <main+0x156>
lea    -0x20(%rbp),%rsi
lea    -0x8(%rbp),%rdi
call   1080 <pop@plt>
mov    %eax,-0x28(%rbp)
mov    -0x28(%rbp),%esi
lea    0xdce(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1318 <main+0x188>
lea    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%esi
call   1030 <display@plt>
jmp    1318 <main+0x188>
xor    %edi,%edi
call   10b0 <exit@plt>
lea    0xdbd(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %edi,%edi
call   10b0 <exit@plt>
jmp    11c4 <main+0x34>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
movl   $0x0,0x4(%rsp)
xorps  %xmm0,%xmm0
movaps %xmm0,0x10(%rsp)
movl   $0x0,0x20(%rsp)
lea    0xe53(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe55(%rip),%r14
lea    0xe59(%rip),%r15
lea    0xe74(%rip),%r12
lea    0xed4(%rip),%rbx
lea    0xc(%rsp),%r13
lea    0xe14(%rip),%rbp
jmp    11fe <main+0x6e>
xchg   %ax,%ax
mov    0x4(%rsp),%esi
lea    0x10(%rsp),%rdi
call   1040 <display@plt>
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r15,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r12,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,%rdi
mov    %r13,%rsi
call   1090 <scanf@plt>
mov    0xc(%rsp),%eax
add    $0xffffffff,%eax
cmp    $0x3,%eax
ja     12e0 <main+0x150>
movslq 0x0(%rbp,%rax,4),%rax
add    %rbp,%rax
jmp    *%rax
lea    0xe18(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,%rdi
lea    0x8(%rsp),%rsi
call   1090 <scanf@plt>
test   %eax,%eax
je     12f0 <main+0x160>
mov    0x4(%rsp),%edi
call   1060 <stfull@plt>
test   %eax,%eax
je     12c8 <main+0x138>
lea    0xe05(%rip),%rdi
jmp    1294 <main+0x104>
nopw   0x0(%rax,%rax,1)
mov    0x4(%rsp),%edi
call   1070 <stempty@plt>
test   %eax,%eax
je     12a0 <main+0x110>
lea    0xdf9(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    11fe <main+0x6e>
lea    0x4(%rsp),%rdi
lea    0x10(%rsp),%rsi
call   1080 <pop@plt>
mov    %eax,0x8(%rsp)
lea    0xde3(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    11fe <main+0x6e>
mov    0x8(%rsp),%edi
lea    0x4(%rsp),%rsi
lea    0x10(%rsp),%rdx
call   10a0 <push@plt>
jmp    11fe <main+0x6e>
lea    0xddf(%rip),%rdi
jmp    12f7 <main+0x167>
xor    %edi,%edi
call   10b0 <exit@plt>
lea    0xdc0(%rip),%rdi
call   1030 <puts@plt>
xor    %edi,%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
@.str = [16 x i8] c"\0A Stack example\00"
@.str.1 = [11 x i8] c"\0AMain Menu\00"
@.str.2 = [34 x i8] c"\0A1.Push \0A2.Pop \0A3.Display \0A4.exit\00"
@.str.3 = [19 x i8] c"\0AEnter Your Choice\00"
@.str.4 = [3 x i8] c"%d\00"
@.str.5 = [29 x i8] c"\0AEnter The item to be pushed\00"
@.str.6 = [16 x i8] c"Invalid input \0A\00"
@.str.7 = [16 x i8] c"\0AStack is Full!\00"
@.str.8 = [16 x i8] c"\0AEmpty stack!!!\00"
@.str.9 = [26 x i8] c"\0AThe popped element is %d\00"
@.str.10 = [16 x i8] c"invalid input \0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [5 x i32]
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8
store i32 0, i32* %1
store i32 0, i32* %2
%7 = bitcast [5 x i32]* %3 to i8*
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
br label %9
9: ; preds = %0, %54
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0))
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0))
%13 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32* %4)
%14 = load i32, i32* %4
switch i32 %14, label %51 [
i32 1, label %15
i32 2, label %33
i32 3, label %45
i32 4, label %49
]
15: ; preds = %9
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.5, i64 0, i64 0))
%17 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32* %5)
%18 = icmp ne i32 %17, 0
br i1 %18, label %22, label %19
19: ; preds = %15
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.6, i64 0, i64 0))
%21 = call i32 @exit(i32 0)
unreachable
22: ; preds = %15
%23 = load i32, i32* %2
%24 = call i32 @stfull(i32 %23)
%25 = icmp ne i32 %24, 0
br i1 %25, label %26, label %28
26: ; preds = %22
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.7, i64 0, i64 0))
br label %32
28: ; preds = %22
%29 = load i32, i32* %5
%30 = getelementptr inbounds [5 x i32], [5 x i32]* %3, i64 0, i64 0
%31 = call i32 @push(i32 %29, i32* %2, i32* %30)
br label %32
32: ; preds = %28, %26
br label %54
33: ; preds = %9
%34 = load i32, i32* %2
%35 = call i32 @stempty(i32 %34)
%36 = icmp ne i32 %35, 0
br i1 %36, label %37, label %39
37: ; preds = %33
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.8, i64 0, i64 0))
br label %44
39: ; preds = %33
%40 = getelementptr inbounds [5 x i32], [5 x i32]* %3, i64 0, i64 0
%41 = call i32 @pop(i32* %2, i32* %40)
store i32 %41, i32* %5
%42 = load i32, i32* %5
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.9, i64 0, i64 0), i32 %42)
br label %44
44: ; preds = %39, %37
br label %54
45: ; preds = %9
%46 = getelementptr inbounds [5 x i32], [5 x i32]* %3, i64 0, i64 0
%47 = load i32, i32* %2
%48 = call i32 @display(i32* %46, i32 %47)
br label %54
49: ; preds = %9
%50 = call i32 @exit(i32 0)
unreachable
51: ; preds = %9
%52 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.10, i64 0, i64 0))
%53 = call i32 @exit(i32 0)
unreachable
54: ; preds = %45, %44, %32
br label %9
}

LLVM IR (-O2):
@.str = [16 x i8] c"\0A Stack example\00"
@.str.1 = [11 x i8] c"\0AMain Menu\00"
@.str.2 = [34 x i8] c"\0A1.Push \0A2.Pop \0A3.Display \0A4.exit\00"
@.str.3 = [19 x i8] c"\0AEnter Your Choice\00"
@.str.4 = [3 x i8] c"%d\00"
@.str.5 = [29 x i8] c"\0AEnter The item to be pushed\00"
@.str.7 = [16 x i8] c"\0AStack is Full!\00"
@.str.8 = [16 x i8] c"\0AEmpty stack!!!\00"
@.str.9 = [26 x i8] c"\0AThe popped element is %d\00"
@str = [15 x i8] c"Invalid input \00"
@str.11 = [15 x i8] c"invalid input \00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [5 x i32]
%3 = alloca i32
%4 = alloca i32
%5 = bitcast i32* %1 to i8*
store i32 0, i32* %1
%6 = bitcast [5 x i32]* %2 to i8*
%7 = bitcast i32* %3 to i8*
%8 = bitcast i32* %4 to i8*
%9 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
%10 = getelementptr inbounds [5 x i32], [5 x i32]* %2, i64 0, i64 0
br label %11
11: ; preds = %39, %0
%12 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
%13 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0))
%14 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0))
%15 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32* %3)
%16 = load i32, i32* %3
switch i32 %16, label %48 [
i32 1, label %17
i32 2, label %33
i32 3, label %43
i32 4, label %46
]
17: ; preds = %11
%18 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str.5, i64 0, i64 0))
%19 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32* %4)
%20 = icmp eq i32 %19, 0
br i1 %20, label %21, label %24
21: ; preds = %17
%22 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str, i64 0, i64 0))
%23 = call i32 @exit(i32 0)
unreachable
24: ; preds = %17
%25 = load i32, i32* %1
%26 = call i32 @stfull(i32 %25)
%27 = icmp eq i32 %26, 0
br i1 %27, label %30, label %28
28: ; preds = %24
%29 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.7, i64 0, i64 0))
br label %39
30: ; preds = %24
%31 = load i32, i32* %4
%32 = call i32 @push(i32 %31, i32* %1, i32* %10)
br label %39
33: ; preds = %11
%34 = load i32, i32* %1
%35 = call i32 @stempty(i32 %34)
%36 = icmp eq i32 %35, 0
br i1 %36, label %40, label %37
37: ; preds = %33
%38 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.8, i64 0, i64 0))
br label %39
39: ; preds = %37, %40, %28, %30, %43
br label %11
40: ; preds = %33
%41 = call i32 @pop(i32* %1, i32* %10)
store i32 %41, i32* %4
%42 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.9, i64 0, i64 0), i32 %41)
br label %39
43: ; preds = %11
%44 = load i32, i32* %1
%45 = call i32 @display(i32* %10, i32 %44)
br label %39
46: ; preds = %11
%47 = call i32 @exit(i32 0)
unreachable
48: ; preds = %11
%49 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str.11, i64 0, i64 0))
%50 = call i32 @exit(i32 0)
unreachable
}