#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*/ count();
int /*<<< orphan*/ create();
int /*<<< orphan*/ display();
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ pop();
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ push(int);
int /*<<< orphan*/ scanf(char *, int *);
int main() {
  int item, ch;
  while (1) {
    printf("\n1) Create stack");
    printf("\n2) Push");
    printf("\n3) Pop");
    printf("\n4) Display");
    printf("\n5) Count of elements in stack");
    printf("\n6) Exit");
    printf("\nEnter 1-6: ");
    scanf("%d", &ch);
    switch (ch) {
    case 1:
      create();
      break;
    case 2:
      printf("\nEnter element to be pushed: ");
      scanf("%d", &item);
      push(item);
      display();
      break;
    case 3:
      pop();
      display();
      break;
    case 4:
      display();
      break;
    case 5:
      count();
      break;
    case 6:
      exit(0);
      break;
    default:
      printf("\nWrong choice: ");
      break;
    }
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe82(%rip),%rdi
call   1050 <printf@plt>
lea    0xe87(%rip),%rdi
call   1050 <printf@plt>
lea    0xe84(%rip),%rdi
call   1050 <printf@plt>
lea    0xe80(%rip),%rdi
call   1050 <printf@plt>
lea    0xe80(%rip),%rdi
call   1050 <printf@plt>
lea    0xe93(%rip),%rdi
call   1050 <printf@plt>
lea    0xe90(%rip),%rdi
call   1050 <printf@plt>
lea    0xe91(%rip),%rdi
lea    -0xc(%rbp),%rsi
call   1080 <scanf@plt>
mov    -0xc(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,%ecx
mov    %rcx,-0x18(%rbp)
sub    $0x5,%eax
ja     128a <main+0x10a>
mov    -0x18(%rbp),%rax
lea    0xded(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    $0x0,%al
call   1070 <create@plt>
jmp    1296 <main+0x116>
lea    0xe4f(%rip),%rdi
call   1050 <printf@plt>
lea    0xe40(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1080 <scanf@plt>
mov    -0x8(%rbp),%edi
call   1090 <push@plt>
mov    $0x0,%al
call   1040 <display@plt>
jmp    1296 <main+0x116>
mov    $0x0,%al
call   1060 <pop@plt>
mov    $0x0,%al
call   1040 <display@plt>
jmp    1296 <main+0x116>
mov    $0x0,%al
call   1040 <display@plt>
jmp    1296 <main+0x116>
mov    $0x0,%al
call   1030 <count@plt>
jmp    1296 <main+0x116>
xor    %edi,%edi
call   10a0 <exit@plt>
lea    0xe0b(%rip),%rdi
call   1050 <printf@plt>
jmp    118f <main+0xf>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
lea    0xeb4(%rip),%rbx
lea    0xecc(%rip),%rbp
lea    0xece(%rip),%r14
lea    0xed4(%rip),%r15
mov    %rsp,%r12
lea    0xe4f(%rip),%r13
jmp    11c1 <main+0x41>
xor    %eax,%eax
call   1060 <pop@plt>
xor    %eax,%eax
call   1040 <display@plt>
lea    0xe50(%rip),%rdi
call   1050 <printf@plt>
lea    0xe55(%rip),%rdi
call   1050 <printf@plt>
lea    0xe52(%rip),%rdi
call   1050 <printf@plt>
lea    0xe4e(%rip),%rdi
call   1050 <printf@plt>
mov    %rbx,%rdi
call   1050 <printf@plt>
mov    %rbp,%rdi
call   1050 <printf@plt>
mov    %r14,%rdi
call   1050 <printf@plt>
mov    %r15,%rdi
mov    %r12,%rsi
call   1080 <scanf@plt>
mov    (%rsp),%eax
add    $0xffffffff,%eax
cmp    $0x5,%eax
ja     1232 <main+0xb2>
movslq 0x0(%r13,%rax,4),%rax
add    %r13,%rax
jmp    *%rax
xor    %eax,%eax
call   1070 <create@plt>
jmp    11c1 <main+0x41>
lea    0xe63(%rip),%rdi
call   1050 <printf@plt>
jmp    11c1 <main+0x41>
lea    0xe37(%rip),%rdi
call   1050 <printf@plt>
mov    %r15,%rdi
lea    0x4(%rsp),%rsi
call   1080 <scanf@plt>
mov    0x4(%rsp),%edi
call   1090 <push@plt>
jmp    11ba <main+0x3a>
xor    %eax,%eax
call   1030 <count@plt>
jmp    11c1 <main+0x41>
xor    %edi,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@.str = [17 x i8] c"\0A1) Create stack\00"
@.str.1 = [9 x i8] c"\0A2) Push\00"
@.str.2 = [8 x i8] c"\0A3) Pop\00"
@.str.3 = [12 x i8] c"\0A4) Display\00"
@.str.4 = [31 x i8] c"\0A5) Count of elements in stack\00"
@.str.5 = [9 x i8] c"\0A6) Exit\00"
@.str.6 = [13 x i8] c"\0AEnter 1-6: \00"
@.str.7 = [3 x i8] c"%d\00"
@.str.8 = [30 x i8] c"\0AEnter element to be pushed: \00"
@.str.9 = [16 x i8] c"\0AWrong choice: \00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
store i32 0, i32* %1
br label %4
4: ; preds = %0, %33
%5 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
%6 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
%7 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
%8 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0))
%9 = call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.4, i64 0, i64 0))
%10 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0))
%11 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.6, i64 0, i64 0))
%12 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0), i32* %3)
%13 = load i32, i32* %3
switch i32 %13, label %31 [
i32 1, label %14
i32 2, label %16
i32 3, label %22
i32 4, label %25
i32 5, label %27
i32 6, label %29
]
14: ; preds = %4
%15 = call i32 (...) @create()
br label %33
16: ; preds = %4
%17 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.8, i64 0, i64 0))
%18 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0), i32* %2)
%19 = load i32, i32* %2
%20 = call i32 @push(i32 %19)
%21 = call i32 (...) @display()
br label %33
22: ; preds = %4
%23 = call i32 (...) @pop()
%24 = call i32 (...) @display()
br label %33
25: ; preds = %4
%26 = call i32 (...) @display()
br label %33
27: ; preds = %4
%28 = call i32 (...) @count()
br label %33
29: ; preds = %4
%30 = call i32 @exit(i32 0)
unreachable
31: ; preds = %4
%32 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.9, i64 0, i64 0))
br label %33
33: ; preds = %31, %27, %25, %22, %16, %14
br label %4
}

LLVM IR (-O2):
@.str = [17 x i8] c"\0A1) Create stack\00"
@.str.1 = [9 x i8] c"\0A2) Push\00"
@.str.2 = [8 x i8] c"\0A3) Pop\00"
@.str.3 = [12 x i8] c"\0A4) Display\00"
@.str.4 = [31 x i8] c"\0A5) Count of elements in stack\00"
@.str.5 = [9 x i8] c"\0A6) Exit\00"
@.str.6 = [13 x i8] c"\0AEnter 1-6: \00"
@.str.7 = [3 x i8] c"%d\00"
@.str.8 = [30 x i8] c"\0AEnter element to be pushed: \00"
@.str.9 = [16 x i8] c"\0AWrong choice: \00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = bitcast i32* %1 to i8*
%4 = bitcast i32* %2 to i8*
br label %5
5: ; preds = %34, %0
%6 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
%7 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
%8 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
%9 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0))
%10 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str.4, i64 0, i64 0))
%11 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0))
%12 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.6, i64 0, i64 0))
%13 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0), i32* %2)
%14 = load i32, i32* %2
switch i32 %14, label %32 [
i32 1, label %15
i32 2, label %17
i32 3, label %23
i32 4, label %26
i32 5, label %28
i32 6, label %30
]
15: ; preds = %5
%16 = call i32 (...) @create()
br label %34
17: ; preds = %5
%18 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str.8, i64 0, i64 0))
%19 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0), i32* %1)
%20 = load i32, i32* %1
%21 = call i32 @push(i32 %20)
%22 = call i32 (...) @display()
br label %34
23: ; preds = %5
%24 = call i32 (...) @pop()
%25 = call i32 (...) @display()
br label %34
26: ; preds = %5
%27 = call i32 (...) @display()
br label %34
28: ; preds = %5
%29 = call i32 (...) @count()
br label %34
30: ; preds = %5
%31 = call i32 @exit(i32 0)
unreachable
32: ; preds = %5
%33 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.9, i64 0, i64 0))
br label %34
34: ; preds = %32, %28, %26, %23, %17, %15
br label %5
}