#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*/ pop(int *, int *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ push(int *, int *, int);
int /*<<< orphan*/ scanf(char *, int *);
main() {
  int stack[25], ch, top = -1, lim;
  printf("\nEnter the stack limit:");
  scanf("%d", &lim);
  do {
    printf("\n**MENU**\n1.PUSH an element:\n2.POP an element");
    printf("\n3.EXIT\nEnter your choice:");
    scanf("%d", &ch);
    switch (ch) {
    case 1:
      push(stack, &top, lim);
      break;
    case 2:
      pop(stack, &top);
      break;
    case 3:
      break;
    default:
      printf("\nInvalid choice. Try again!!");
      break;
    }
  } while (ch != 3);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0xffffffff,-0x78(%rbp)
lea    0xea0(%rip),%rdi
call   1030 <printf@plt>
lea    0xeac(%rip),%rdi
lea    -0x7c(%rbp),%rsi
call   1050 <scanf@plt>
lea    0xe9f(%rip),%rdi
call   1030 <printf@plt>
lea    0xec1(%rip),%rdi
call   1030 <printf@plt>
lea    0xe84(%rip),%rdi
lea    -0x74(%rbp),%rsi
call   1050 <scanf@plt>
mov    -0x74(%rbp),%eax
mov    %eax,-0x80(%rbp)
sub    $0x1,%eax
je     11d3 <main+0x93>
jmp    11b1 <main+0x71>
mov    -0x80(%rbp),%eax
sub    $0x2,%eax
je     11e8 <main+0xa8>
jmp    11c2 <main+0x82>
mov    -0x80(%rbp),%eax
sub    $0x3,%eax
je     11fa <main+0xba>
jmp    11ff <main+0xbf>
lea    -0x70(%rbp),%rdi
mov    -0x7c(%rbp),%edx
lea    -0x78(%rbp),%rsi
call   1060 <push@plt>
jmp    120b <main+0xcb>
lea    -0x70(%rbp),%rdi
lea    -0x78(%rbp),%rsi
call   1040 <pop@plt>
jmp    120b <main+0xcb>
jmp    120b <main+0xcb>
lea    0xe5e(%rip),%rdi
call   1030 <printf@plt>
jmp    1210 <main+0xd0>
cmpl   $0x3,-0x74(%rbp)
jne    1175 <main+0x35>
mov    -0x4(%rbp),%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x78,%rsp
movl   $0xffffffff,0xc(%rsp)
ff
lea    0xea3(%rip),%rdi
call   1030 <printf@plt>
lea    0xeaf(%rip),%r14
lea    0x8(%rsp),%rsi
mov    %r14,%rdi
call   1050 <scanf@plt>
lea    0xe9e(%rip),%r15
lea    0xec5(%rip),%r12
lea    0x4(%rsp),%rbx
lea    0x10(%rsp),%r13
lea    0xc(%rsp),%rbp
jmp    11b2 <main+0x72>
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r13,%rdi
mov    %rbp,%rsi
call   1040 <pop@plt>
cmpl   $0x3,0x4(%rsp)
je     1201 <main+0xc1>
mov    %r15,%rdi
call   1030 <printf@plt>
mov    %r12,%rdi
call   1030 <printf@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1050 <scanf@plt>
mov    0x4(%rsp),%eax
cmp    $0x1,%eax
je     11f0 <main+0xb0>
cmp    $0x2,%eax
je     11a0 <main+0x60>
cmp    $0x3,%eax
je     1201 <main+0xc1>
lea    0xe7d(%rip),%rdi
call   1030 <printf@plt>
jmp    11ab <main+0x6b>
xchg   %ax,%ax
mov    0x8(%rsp),%edx
mov    %r13,%rdi
mov    %rbp,%rsi
call   1060 <push@plt>
jmp    11ab <main+0x6b>
xor    %eax,%eax
add    $0x78,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [24 x i8] c"\0AEnter the stack limit:\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [46 x i8] c"\0A**MENU**\0A1.PUSH an element:\0A2.POP an element\00"
@.str.3 = [27 x i8] c"\0A3.EXIT\0AEnter your choice:\00"
@.str.4 = [29 x i8] c"\0AInvalid choice. Try again!!\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [25 x i32]
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 0, i32* %1
store i32 -1, i32* %4
%6 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
%7 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %5)
br label %8
8: ; preds = %24, %0
%9 = call i32 @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.2, i64 0, i64 0))
%10 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0))
%11 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %3)
%12 = load i32, i32* %3
switch i32 %12, label %21 [
i32 1, label %13
i32 2, label %17
i32 3, label %20
]
13: ; preds = %8
%14 = getelementptr inbounds [25 x i32], [25 x i32]* %2, i64 0, i64 0
%15 = load i32, i32* %5
%16 = call i32 @push(i32* %14, i32* %4, i32 %15)
br label %23
17: ; preds = %8
%18 = getelementptr inbounds [25 x i32], [25 x i32]* %2, i64 0, i64 0
%19 = call i32 @pop(i32* %18, i32* %4)
br label %23
20: ; preds = %8
br label %23
21: ; preds = %8
%22 = call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.4, i64 0, i64 0))
br label %23
23: ; preds = %21, %20, %17, %13
br label %24
24: ; preds = %23
%25 = load i32, i32* %3
%26 = icmp ne i32 %25, 3
br i1 %26, label %8, label %27
27: ; preds = %24
%28 = load i32, i32* %1
ret i32 %28
}

LLVM IR (-O2):
@.str = [24 x i8] c"\0AEnter the stack limit:\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [46 x i8] c"\0A**MENU**\0A1.PUSH an element:\0A2.POP an element\00"
@.str.3 = [27 x i8] c"\0A3.EXIT\0AEnter your choice:\00"
@.str.4 = [29 x i8] c"\0AInvalid choice. Try again!!\00"
define i32 @main() {
%1 = alloca [25 x i32]
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = bitcast [25 x i32]* %1 to i8*
%6 = bitcast i32* %2 to i8*
%7 = bitcast i32* %3 to i8*
store i32 -1, i32* %3
%8 = bitcast i32* %4 to i8*
%9 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
%10 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %4)
%11 = getelementptr inbounds [25 x i32], [25 x i32]* %1, i64 0, i64 0
br label %12
12: ; preds = %24, %0
%13 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([46 x i8], [46 x i8]* @.str.2, i64 0, i64 0))
%14 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0))
%15 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %2)
%16 = load i32, i32* %2
switch i32 %16, label %22 [
i32 1, label %17
i32 2, label %20
i32 3, label %27
]
17: ; preds = %12
%18 = load i32, i32* %4
%19 = call i32 @push(i32* %11, i32* %3, i32 %18)
br label %24
20: ; preds = %12
%21 = call i32 @pop(i32* %11, i32* %3)
br label %24
22: ; preds = %12
%23 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str.4, i64 0, i64 0))
br label %24
24: ; preds = %17, %20, %22
%25 = load i32, i32* %2
%26 = icmp eq i32 %25, 3
br i1 %26, label %27, label %12
27: ; preds = %12, %24
ret i32 0
}