#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 */
struct arrayStack {
  int dummy;
};

/* Variables and functions */
struct arrayStack *createStack(int);
int pop(struct arrayStack *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ push(struct arrayStack *, int);
int /*<<< orphan*/ scanf(char *, int *);
int main() {
  struct arrayStack *S = createStack(3);
  int o, q = 1;
  while (q) {
    printf("Enter 1 to Push Element\nEnter 2 to Pop an Element\nEnter 3 to "
           "EXIT ---> ");
    scanf("%d", &o);
    switch (o) {
    case 1: {
      int data;
      printf("Enter the data : ");
      scanf("%d", &data);
      push(S, data);
      break;
    }
    case 2: {
      int d = pop(S);
      if (d != 0) {
        printf("Popped Element is : %d\n", d);
      }
      break;
    }
    case 3: {
      q = 0;
    }
    }
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x3,%edi
call   1050 <createStack@plt>
mov    %rax,-0x10(%rbp)
movl   $0x1,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
je     1239 <main+0xe9>
lea    0xe7b(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xeb5(%rip),%rdi
lea    -0x14(%rbp),%rsi
call   1060 <scanf@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x24(%rbp)
sub    $0x1,%eax
je     11d2 <main+0x82>
jmp    11b0 <main+0x60>
mov    -0x24(%rbp),%eax
sub    $0x2,%eax
je     1201 <main+0xb1>
jmp    11c1 <main+0x71>
mov    -0x24(%rbp),%eax
sub    $0x3,%eax
je     122d <main+0xdd>
jmp    1234 <main+0xe4>
lea    0xe72(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe61(%rip),%rdi
lea    -0x1c(%rbp),%rsi
call   1060 <scanf@plt>
mov    -0x10(%rbp),%rdi
mov    -0x1c(%rbp),%esi
call   1070 <push@plt>
jmp    1234 <main+0xe4>
mov    -0x10(%rbp),%rdi
call   1040 <pop@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
je     1228 <main+0xd8>
mov    -0x20(%rbp),%esi
lea    0xe3c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1234 <main+0xe4>
movl   $0x0,-0x18(%rbp)
jmp    1174 <main+0x24>
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    $0x3,%edi
call   1050 <createStack@plt>
mov    %rax,%r15
lea    0xe91(%rip),%r14
lea    0xed2(%rip),%rbx
lea    0x4(%rsp),%r12
lea    0xec9(%rip),%r13
mov    %rsp,%rbp
jmp    1195 <main+0x45>
nopw   0x0(%rax,%rax,1)
cmp    $0x3,%eax
je     1202 <main+0xb2>
mov    %r14,%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    %rbx,%rdi
mov    %r12,%rsi
call   1060 <scanf@plt>
mov    0x4(%rsp),%eax
cmp    $0x1,%eax
je     11e0 <main+0x90>
cmp    $0x2,%eax
jne    1190 <main+0x40>
mov    %r15,%rdi
call   1040 <pop@plt>
test   %eax,%eax
je     1195 <main+0x45>
lea    0xe92(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1030 <printf@plt>
jmp    1195 <main+0x45>
cs nopw 0x0(%rax,%rax,1)
mov    %r13,%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    %rbx,%rdi
mov    %rbp,%rsi
call   1060 <scanf@plt>
mov    (%rsp),%esi
mov    %r15,%rdi
call   1070 <push@plt>
jmp    1195 <main+0x45>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.arrayStack = type { i32 }
@.str = [72 x i8] c"Enter 1 to Push Element\0AEnter 2 to Pop an Element\0AEnter 3 to EXIT ---> \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [18 x i8] c"Enter the data : \00"
@.str.3 = [24 x i8] c"Popped Element is : %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca %struct.arrayStack*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32 0, i32* %1
%7 = call %struct.arrayStack* @createStack(i32 3)
store %struct.arrayStack* %7, %struct.arrayStack** %2
store i32 1, i32* %4
br label %8
8: ; preds = %31, %0
%9 = load i32, i32* %4
%10 = icmp ne i32 %9, 0
br i1 %10, label %11, label %32
11: ; preds = %8
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([72 x i8], [72 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* %3)
%14 = load i32, i32* %3
switch i32 %14, label %31 [
i32 1, label %15
i32 2, label %21
i32 3, label %30
]
15: ; preds = %11
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0))
%17 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %5)
%18 = load %struct.arrayStack*, %struct.arrayStack** %2
%19 = load i32, i32* %5
%20 = call i32 @push(%struct.arrayStack* %18, i32 %19)
br label %31
21: ; preds = %11
%22 = load %struct.arrayStack*, %struct.arrayStack** %2
%23 = call i32 @pop(%struct.arrayStack* %22)
store i32 %23, i32* %6
%24 = load i32, i32* %6
%25 = icmp ne i32 %24, 0
br i1 %25, label %26, label %29
26: ; preds = %21
%27 = load i32, i32* %6
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0), i32 %27)
br label %29
29: ; preds = %26, %21
br label %31
30: ; preds = %11
store i32 0, i32* %4
br label %31
31: ; preds = %30, %11, %29, %15
br label %8
32: ; preds = %8
%33 = load i32, i32* %1
ret i32 %33
}

LLVM IR (-O2):
%struct.arrayStack = type { i32 }
@.str = [72 x i8] c"Enter 1 to Push Element\0AEnter 2 to Pop an Element\0AEnter 3 to EXIT ---> \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [18 x i8] c"Enter the data : \00"
@.str.3 = [24 x i8] c"Popped Element is : %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = tail call %struct.arrayStack* @createStack(i32 3)
%4 = bitcast i32* %1 to i8*
%5 = bitcast i32* %2 to i8*
br label %6
6: ; preds = %18, %0
%7 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([72 x i8], [72 x i8]* @.str, i64 0, i64 0))
%8 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%9 = load i32, i32* %1
switch i32 %9, label %18 [
i32 1, label %10
i32 2, label %15
i32 3, label %21
]
10: ; preds = %6
%11 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 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(%struct.arrayStack* %3, i32 %13)
br label %18
15: ; preds = %6
%16 = call i32 @pop(%struct.arrayStack* %3)
%17 = icmp eq i32 %16, 0
br i1 %17, label %18, label %19
18: ; preds = %15, %19, %6, %10
br label %6
19: ; preds = %15
%20 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0), i32 %16)
br label %18
21: ; preds = %6
ret i32 0
}