#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*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, ...);
void main() {
  int top, i, ch;
  char a[10];
  printf("enter value of top");
  scanf("%d", &top);
  printf("top=%d\nenter character", top);
  for (i = 0; i <= top; i++)
    scanf("%c", &a[i]);
  while (1) {
    printf("press 1 to PUSH \n press 2 to POP\n3 to exit");
    scanf("%d", &ch);
    switch (ch) {
    case 1: {
      if (top == 10)
        printf("stack is full");
      else {
        top = top + 1;
        printf("enter character to push");
        scanf("%c", &a[top]);
        printf("\nstack is:");
        for (i = 0; i <= top; i++)
          printf("%c", a[i]);
      }
      break;
    }
    case 2: {
      if (top == 0)
        printf("stack is empty");
      else {
        top = top - 1;
        printf("stack is:");
        for (i = 0; i <= top; i++)
          printf("%c", a[i]);
      }
      break;
    }
    case 3:
      exit(0);
    }
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    0xec1(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xec6(%rip),%rdi
lea    -0x4(%rbp),%rsi
mov    $0x0,%al
call   1040 <scanf@plt>
mov    -0x4(%rbp),%esi
lea    0xeb4(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0x4(%rbp),%eax
jg     11a3 <main+0x73>
movslq -0x8(%rbp),%rax
lea    -0x16(%rbp),%rsi
add    %rax,%rsi
lea    0xe9f(%rip),%rdi
mov    $0x0,%al
call   1040 <scanf@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1170 <main+0x40>
jmp    11a8 <main+0x78>
lea    0xe81(%rip),%rdi
xor    %eax,%eax
mov    %al,-0x1d(%rbp)
call   1030 <printf@plt>
mov    -0x1d(%rbp),%al
lea    0xe50(%rip),%rdi
lea    -0xc(%rbp),%rsi
call   1040 <scanf@plt>
mov    -0xc(%rbp),%eax
mov    %eax,-0x1c(%rbp)
sub    $0x1,%eax
je     1202 <main+0xd2>
jmp    11e0 <main+0xb0>
mov    -0x1c(%rbp),%eax
sub    $0x2,%eax
je     129f <main+0x16f>
jmp    11f1 <main+0xc1>
mov    -0x1c(%rbp),%eax
sub    $0x3,%eax
je     1315 <main+0x1e5>
jmp    131c <main+0x1ec>
cmpl   $0xa,-0x4(%rbp)
jne    121f <main+0xef>
lea    0xe48(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    129a <main+0x16a>
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
lea    0xe3a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movslq -0x4(%rbp),%rax
lea    -0x16(%rbp),%rsi
add    %rax,%rsi
lea    0xde5(%rip),%rdi
mov    $0x0,%al
call   1040 <scanf@plt>
lea    0xe2b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0x4(%rbp),%eax
jg     1295 <main+0x165>
movslq -0x8(%rbp),%rax
movsbl -0x16(%rbp,%rax,1),%esi
lea    0xdad(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1264 <main+0x134>
jmp    129a <main+0x16a>
jmp    131c <main+0x1ec>
cmpl   $0x0,-0x4(%rbp)
jne    12bc <main+0x18c>
lea    0xddc(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1310 <main+0x1e0>
mov    -0x4(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x4(%rbp)
lea    0xdb6(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0x4(%rbp),%eax
jg     130b <main+0x1db>
movslq -0x8(%rbp),%rax
movsbl -0x16(%rbp,%rax,1),%esi
lea    0xd37(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    12da <main+0x1aa>
jmp    1310 <main+0x1e0>
jmp    131c <main+0x1ec>
xor    %edi,%edi
call   1050 <exit@plt>
jmp    11a8 <main+0x78>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
lea    0xeab(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xeb0(%rip),%rdi
lea    0x4(%rsp),%rsi
xor    %eax,%eax
call   1050 <scanf@plt>
mov    0x4(%rsp),%esi
lea    0xe9c(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
cmpl   $0x0,0x4(%rsp)
js     11c0 <main+0x80>
mov    $0xffffffffffffffff,%rbp
lea    0xe97(%rip),%rbx
cs nopw 0x0(%rax,%rax,1)
lea    (%rsp,%rbp,1),%rsi
add    $0xf,%rsi
mov    %rbx,%rdi
xor    %eax,%eax
call   1050 <scanf@plt>
movslq 0x4(%rsp),%rax
add    $0x1,%rbp
cmp    %rax,%rbp
jl     11a0 <main+0x60>
lea    0xe69(%rip),%r14
lea    0xe45(%rip),%r15
lea    0x8(%rsp),%rbx
lea    0xeb2(%rip),%r13
jmp    11e9 <main+0xa9>
nopl   0x0(%rax)
cmp    $0x3,%eax
je     12ee <main+0x1ae>
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <scanf@plt>
mov    0x8(%rsp),%eax
cmp    $0x1,%eax
je     1260 <main+0x120>
cmp    $0x2,%eax
jne    11e0 <main+0xa0>
mov    0x4(%rsp),%eax
mov    %r13,%rdi
test   %eax,%eax
je     1270 <main+0x130>
add    $0xffffffff,%eax
mov    %eax,0x4(%rsp)
lea    0xe5b(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
cmpl   $0x0,0x4(%rsp)
js     11e9 <main+0xa9>
mov    $0xffffffffffffffff,%rbp
nopl   0x0(%rax)
movsbl 0xf(%rsp,%rbp,1),%edi
call   1030 <putchar@plt>
movslq 0x4(%rsp),%rax
add    $0x1,%rbp
cmp    %rax,%rbp
jl     1240 <main+0x100>
jmp    11e9 <main+0xa9>
nopw   0x0(%rax,%rax,1)
mov    0x4(%rsp),%eax
lea    0xdf0(%rip),%rdi
cmp    $0xa,%eax
jne    127c <main+0x13c>
xor    %eax,%eax
call   1040 <printf@plt>
jmp    11e9 <main+0xa9>
add    $0x1,%eax
mov    %eax,0x4(%rsp)
lea    0xddf(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
movslq 0x4(%rsp),%rax
lea    (%rsp,%rax,1),%rsi
add    $0xe,%rsi
lea    0xd88(%rip),%rdi
xor    %eax,%eax
call   1050 <scanf@plt>
lea    0xdce(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
cmpl   $0x0,0x4(%rsp)
js     11e9 <main+0xa9>
mov    $0xffffffffffffffff,%r12
nopl   0x0(%rax)
movsbl 0xf(%rsp,%r12,1),%edi
call   1030 <putchar@plt>
movslq 0x4(%rsp),%rax
add    $0x1,%r12
cmp    %rax,%r12
jl     12d0 <main+0x190>
jmp    11e9 <main+0xa9>
xor    %edi,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@.str = [19 x i8] c"enter value of top\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [23 x i8] c"top=%d\0Aenter character\00"
@.str.3 = [3 x i8] c"%c\00"
@.str.4 = [43 x i8] c"press 1 to PUSH \0A press 2 to POP\0A3 to exit\00"
@.str.5 = [14 x i8] c"stack is full\00"
@.str.6 = [24 x i8] c"enter character to push\00"
@.str.7 = [11 x i8] c"\0Astack is:\00"
@.str.8 = [15 x i8] c"stack is empty\00"
@.str.9 = [10 x i8] c"stack is:\00"
define void @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca [10 x i8]
%5 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
%6 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%7 = load i32, i32* %1
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i32 %7)
store i32 0, i32* %2
br label %9
9: ; preds = %18, %0
%10 = load i32, i32* %2
%11 = load i32, i32* %1
%12 = icmp sle i32 %10, %11
br i1 %12, label %13, label %21
13: ; preds = %9
%14 = load i32, i32* %2
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds [10 x i8], [10 x i8]* %4, i64 0, i64 %15
%17 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %16)
br label %18
18: ; preds = %13
%19 = load i32, i32* %2
%20 = add nsw i32 %19, 1
store i32 %20, i32* %2
br label %9
21: ; preds = %9
br label %22
22: ; preds = %21, %83
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.4, i64 0, i64 0))
%24 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %3)
%25 = load i32, i32* %3
switch i32 %25, label %83 [
i32 1, label %26
i32 2, label %56
i32 3, label %81
]
26: ; preds = %22
%27 = load i32, i32* %1
%28 = icmp eq i32 %27, 10
br i1 %28, label %29, label %31
29: ; preds = %26
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.5, i64 0, i64 0))
br label %55
31: ; preds = %26
%32 = load i32, i32* %1
%33 = add nsw i32 %32, 1
store i32 %33, i32* %1
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.6, i64 0, i64 0))
%35 = load i32, i32* %1
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds [10 x i8], [10 x i8]* %4, i64 0, i64 %36
%38 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %37)
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.7, i64 0, i64 0))
store i32 0, i32* %2
br label %40
40: ; preds = %51, %31
%41 = load i32, i32* %2
%42 = load i32, i32* %1
%43 = icmp sle i32 %41, %42
br i1 %43, label %44, label %54
44: ; preds = %40
%45 = load i32, i32* %2
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds [10 x i8], [10 x i8]* %4, i64 0, i64 %46
%48 = load i8, i8* %47
%49 = sext i8 %48 to i32
%50 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32 %49)
br label %51
51: ; preds = %44
%52 = load i32, i32* %2
%53 = add nsw i32 %52, 1
store i32 %53, i32* %2
br label %40
54: ; preds = %40
br label %55
55: ; preds = %54, %29
br label %83
56: ; preds = %22
%57 = load i32, i32* %1
%58 = icmp eq i32 %57, 0
br i1 %58, label %59, label %61
59: ; preds = %56
%60 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.8, i64 0, i64 0))
br label %80
61: ; preds = %56
%62 = load i32, i32* %1
%63 = sub nsw i32 %62, 1
store i32 %63, i32* %1
%64 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.9, i64 0, i64 0))
store i32 0, i32* %2
br label %65
65: ; preds = %76, %61
%66 = load i32, i32* %2
%67 = load i32, i32* %1
%68 = icmp sle i32 %66, %67
br i1 %68, label %69, label %79
69: ; preds = %65
%70 = load i32, i32* %2
%71 = sext i32 %70 to i64
%72 = getelementptr inbounds [10 x i8], [10 x i8]* %4, i64 0, i64 %71
%73 = load i8, i8* %72
%74 = sext i8 %73 to i32
%75 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32 %74)
br label %76
76: ; preds = %69
%77 = load i32, i32* %2
%78 = add nsw i32 %77, 1
store i32 %78, i32* %2
br label %65
79: ; preds = %65
br label %80
80: ; preds = %79, %59
br label %83
81: ; preds = %22
%82 = call i32 @exit(i32 0)
unreachable
83: ; preds = %22, %80, %55
br label %22
}

LLVM IR (-O2):
@.str = [19 x i8] c"enter value of top\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [23 x i8] c"top=%d\0Aenter character\00"
@.str.3 = [3 x i8] c"%c\00"
@.str.4 = [43 x i8] c"press 1 to PUSH \0A press 2 to POP\0A3 to exit\00"
@.str.5 = [14 x i8] c"stack is full\00"
@.str.6 = [24 x i8] c"enter character to push\00"
@.str.7 = [11 x i8] c"\0Astack is:\00"
@.str.8 = [15 x i8] c"stack is empty\00"
@.str.9 = [10 x i8] c"stack is:\00"
define void @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [10 x i8]
%4 = bitcast i32* %1 to i8*
%5 = bitcast i32* %2 to i8*
%6 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 0
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
%8 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%9 = load i32, i32* %1
%10 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i32 %9)
%11 = load i32, i32* %1
%12 = icmp slt i32 %11, 0
br i1 %12, label %21, label %13
13: ; preds = %0, %13
%14 = phi i64 [ %17, %13 ], [ 0, %0 ]
%15 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 %14
%16 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %15)
%17 = add nuw nsw i64 %14, 1
%18 = load i32, i32* %1
%19 = sext i32 %18 to i64
%20 = icmp slt i64 %14, %19
br i1 %20, label %13, label %21
21: ; preds = %13, %0
br label %22
22: ; preds = %72, %21
%23 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([43 x i8], [43 x i8]* @.str.4, i64 0, i64 0))
%24 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %2)
%25 = load i32, i32* %2
switch i32 %25, label %72 [
i32 1, label %26
i32 2, label %49
i32 3, label %67
]
26: ; preds = %22
%27 = load i32, i32* %1
%28 = icmp eq i32 %27, 10
br i1 %28, label %69, label %29
29: ; preds = %26
%30 = add nsw i32 %27, 1
store i32 %30, i32* %1
%31 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.6, i64 0, i64 0))
%32 = load i32, i32* %1
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 %33
%35 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %34)
%36 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.7, i64 0, i64 0))
%37 = load i32, i32* %1
%38 = icmp slt i32 %37, 0
br i1 %38, label %72, label %39
39: ; preds = %29, %39
%40 = phi i64 [ %45, %39 ], [ 0, %29 ]
%41 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 %40
%42 = load i8, i8* %41
%43 = sext i8 %42 to i32
%44 = call i32 @putchar(i32 %43)
%45 = add nuw nsw i64 %40, 1
%46 = load i32, i32* %1
%47 = sext i32 %46 to i64
%48 = icmp slt i64 %40, %47
br i1 %48, label %39, label %72
49: ; preds = %22
%50 = load i32, i32* %1
%51 = icmp eq i32 %50, 0
br i1 %51, label %69, label %52
52: ; preds = %49
%53 = add nsw i32 %50, -1
store i32 %53, i32* %1
%54 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.9, i64 0, i64 0))
%55 = load i32, i32* %1
%56 = icmp slt i32 %55, 0
br i1 %56, label %72, label %57
57: ; preds = %52, %57
%58 = phi i64 [ %63, %57 ], [ 0, %52 ]
%59 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 %58
%60 = load i8, i8* %59
%61 = sext i8 %60 to i32
%62 = call i32 @putchar(i32 %61)
%63 = add nuw nsw i64 %58, 1
%64 = load i32, i32* %1
%65 = sext i32 %64 to i64
%66 = icmp slt i64 %58, %65
br i1 %66, label %57, label %72
67: ; preds = %22
%68 = call i32 @exit(i32 0)
unreachable
69: ; preds = %49, %26
%70 = phi i8* [ getelementptr inbounds ([14 x i8], [14 x i8]* @.str.5, i64 0, i64 0), %26 ], [ getelementptr inbounds ([15 x i8], [15 x i8]* @.str.8, i64 0, i64 0), %49 ]
%71 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) %70)
br label %72
72: ; preds = %57, %39, %69, %52, %29, %22
br label %22
}