#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 pop();
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ push(int);
int /*<<< orphan*/ scanf(char *, int *);
int main() {
  int select, element;
  printf("Select Stack Operations: (1) Push; (2): Pop; (0): Exit\n");
  scanf("%d", &select);
  do {
    switch (select) {
    case 1:
      printf("Enter element to be pushed into stack: ");
      scanf("%d", &element);
      push(element);
      printf("\n");
      break;
    case 2:
      element = pop();
      printf("Element %d is popped up\n", element);
      break;
    case 3:
      printf("Existing !!!\n");
      return 0;
    }
    printf("Select Stack Operations: (1) Push; (2): Pop; (0): Exit\n");
    scanf("%d", &select);
  } while (select);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeaa(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xed4(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1050 <scanf@plt>
mov    -0x8(%rbp),%eax
mov    %eax,-0x10(%rbp)
sub    $0x1,%eax
je     11a3 <main+0x63>
jmp    1181 <main+0x41>
mov    -0x10(%rbp),%eax
sub    $0x2,%eax
je     11dc <main+0x9c>
jmp    1192 <main+0x52>
mov    -0x10(%rbp),%eax
sub    $0x3,%eax
je     11fc <main+0xbc>
jmp    1216 <main+0xd6>
lea    0xe91(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe80(%rip),%rdi
lea    -0xc(%rbp),%rsi
call   1050 <scanf@plt>
mov    -0xc(%rbp),%edi
call   1060 <push@plt>
lea    0xeb8(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1216 <main+0xd6>
mov    $0x0,%al
call   1040 <pop@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%esi
lea    0xe73(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1216 <main+0xd6>
lea    0xe79(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1245 <main+0x105>
lea    0xde3(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe0d(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1050 <scanf@plt>
cmpl   $0x0,-0x8(%rbp)
jne    116d <main+0x2d>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
lea    0xedf(%rip),%r14
mov    %r14,%rdi
call   1040 <puts@plt>
lea    0xe7f(%rip),%rbx
lea    0x4(%rsp),%r15
mov    %rbx,%rdi
mov    %r15,%rsi
call   1070 <scanf@plt>
mov    0x4(%rsp),%eax
lea    0xe67(%rip),%r12
mov    %rsp,%r13
lea    0xe85(%rip),%rbp
jmp    11f2 <main+0x92>
nopl   0x0(%rax,%rax,1)
mov    %r12,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,%rdi
mov    %r13,%rsi
call   1070 <scanf@plt>
mov    (%rsp),%edi
call   1080 <push@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    %r14,%rdi
call   1040 <puts@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
call   1070 <scanf@plt>
mov    0x4(%rsp),%eax
test   %eax,%eax
je     1234 <main+0xd4>
cmp    $0x1,%eax
je     11b0 <main+0x50>
cmp    $0x2,%eax
je     1210 <main+0xb0>
cmp    $0x3,%eax
jne    11d7 <main+0x77>
jmp    1228 <main+0xc8>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
xor    %eax,%eax
call   1060 <pop@plt>
mov    %eax,(%rsp)
mov    %rbp,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    11d7 <main+0x77>
lea    0xe15(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [56 x i8] c"Select Stack Operations: (1) Push; (2): Pop; (0): Exit\0A\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [40 x i8] c"Enter element to be pushed into stack: \00"
@.str.3 = [2 x i8] c"\0A\00"
@.str.4 = [25 x i8] c"Element %d is popped up\0A\00"
@.str.5 = [14 x i8] c"Existing !!!\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
store i32 0, i32* %1
%4 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str, i64 0, i64 0))
%5 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %2)
br label %6
6: ; preds = %23, %0
%7 = load i32, i32* %2
switch i32 %7, label %20 [
i32 1, label %8
i32 2, label %14
i32 3, label %18
]
8: ; preds = %6
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 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* %3)
%11 = load i32, i32* %3
%12 = call i32 @push(i32 %11)
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
br label %20
14: ; preds = %6
%15 = call i32 (...) @pop()
store i32 %15, i32* %3
%16 = load i32, i32* %3
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.4, i64 0, i64 0), i32 %16)
br label %20
18: ; preds = %6
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.5, i64 0, i64 0))
store i32 0, i32* %1
br label %27
20: ; preds = %6, %14, %8
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str, i64 0, i64 0))
%22 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %2)
br label %23
23: ; preds = %20
%24 = load i32, i32* %2
%25 = icmp ne i32 %24, 0
br i1 %25, label %6, label %26
26: ; preds = %23
store i32 0, i32* %1
br label %27
27: ; preds = %26, %18
%28 = load i32, i32* %1
ret i32 %28
}

LLVM IR (-O2):
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [40 x i8] c"Enter element to be pushed into stack: \00"
@.str.4 = [25 x i8] c"Element %d is popped up\0A\00"
@str.6 = [13 x i8] c"Existing !!!\00"
@str.7 = [55 x i8] c"Select Stack Operations: (1) Push; (2): Pop; (0): Exit\00"
define i32 @main() {
%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 ([55 x i8], [55 x i8]* @str.7, 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
br label %8
8: ; preds = %21, %0
%9 = phi i32 [ %24, %21 ], [ %7, %0 ]
switch i32 %9, label %21 [
i32 1, label %10
i32 2, label %16
i32 3, label %19
]
10: ; preds = %8
%11 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @.str.2, i64 0, i64 0))
%12 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %2)
%13 = load i32, i32* %2
%14 = call i32 @push(i32 %13)
%15 = call i32 @putchar(i32 10)
br label %21
16: ; preds = %8
%17 = call i32 (...) @pop()
store i32 %17, i32* %2
%18 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.4, i64 0, i64 0), i32 %17)
br label %21
19: ; preds = %8
%20 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @str.6, i64 0, i64 0))
br label %26
21: ; preds = %8, %16, %10
%22 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([55 x i8], [55 x i8]* @str.7, i64 0, i64 0))
%23 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%24 = load i32, i32* %1
%25 = icmp eq i32 %24, 0
br i1 %25, label %26, label %8
26: ; preds = %21, %19
ret i32 0
}