#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*/ init();
int pop(unsigned int);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ push(unsigned int, int);
int /*<<< orphan*/ putchar(char);
int /*<<< orphan*/ puts(char *);
int /*<<< orphan*/ scanf(char *, ...);
int main() {
  unsigned ch, sno;
  int data;
  init();
  do {
    puts("What would you like to do?");
    puts(" ( 0) Exit");
    puts(" ( 1) Push");
    puts(" ( 2) Pop");
    scanf(" %u%*c", &ch);
    switch (ch) {
    case 0:
      puts("Bye!");
      break;
    case 1:
      puts("Stack Number (0-4)?");
      scanf(" %u%*c", &sno);
      puts("Data?");
      scanf(" %d%*c", &data);
      push(sno, data);
      break;
    case 2:
      puts("Stack Number (0-4)?");
      scanf(" %u%*c", &sno);
      if ((data = pop(sno)))
        printf("%d\n", data);
      break;
    default:
      puts("Incorrect Choice!");
      break;
    }
  } while (ch);
  putchar('\n');
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   1070 <init@plt>
lea    0xe73(%rip),%rdi
call   1040 <puts@plt>
lea    0xe82(%rip),%rdi
call   1040 <puts@plt>
lea    0xe81(%rip),%rdi
call   1040 <puts@plt>
lea    0xe80(%rip),%rdi
call   1040 <puts@plt>
lea    0xe7e(%rip),%rdi
xor    %eax,%eax
lea    -0x8(%rbp),%rsi
call   1080 <scanf@plt>
mov    -0x8(%rbp),%eax
mov    %eax,-0x14(%rbp)
test   %eax,%eax
je     11fd <main+0x8d>
jmp    11db <main+0x6b>
mov    -0x14(%rbp),%eax
sub    $0x1,%eax
je     120e <main+0x9e>
jmp    11ec <main+0x7c>
mov    -0x14(%rbp),%eax
sub    $0x2,%eax
je     125a <main+0xea>
jmp    12a0 <main+0x130>
lea    0xe3e(%rip),%rdi
call   1040 <puts@plt>
jmp    12ac <main+0x13c>
lea    0xe32(%rip),%rdi
call   1040 <puts@plt>
lea    0xe1a(%rip),%rdi
lea    -0xc(%rbp),%rsi
mov    $0x0,%al
call   1080 <scanf@plt>
lea    0xe28(%rip),%rdi
call   1040 <puts@plt>
lea    0xe22(%rip),%rdi
lea    -0x10(%rbp),%rsi
mov    $0x0,%al
call   1080 <scanf@plt>
mov    -0xc(%rbp),%edi
mov    -0x10(%rbp),%esi
call   1090 <push@plt>
jmp    12ac <main+0x13c>
lea    0xde6(%rip),%rdi
call   1040 <puts@plt>
lea    0xdce(%rip),%rdi
lea    -0xc(%rbp),%rsi
mov    $0x0,%al
call   1080 <scanf@plt>
mov    -0xc(%rbp),%edi
call   1060 <pop@plt>
mov    %eax,-0x10(%rbp)
cmp    $0x0,%eax
je     129b <main+0x12b>
mov    -0x10(%rbp),%esi
lea    0xdd2(%rip),%rdi
call   1050 <printf@plt>
jmp    12ac <main+0x13c>
lea    0xdc5(%rip),%rdi
call   1040 <puts@plt>
jmp    12b1 <main+0x141>
cmpl   $0x0,-0x8(%rbp)
jne    1186 <main+0x16>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
xor    %eax,%eax
call   1070 <init@plt>
lea    0xe74(%rip),%r14
lea    0xe88(%rip),%r15
lea    0xe8c(%rip),%r12
lea    0xe90(%rip),%r13
lea    0xe93(%rip),%rbx
lea    0x14(%rsp),%rbp
jmp    11c7 <main+0x57>
nop
lea    0xeb5(%rip),%rdi
call   1040 <puts@plt>
cmpl   $0x0,0x14(%rsp)
je     12a3 <main+0x133>
mov    %r14,%rdi
call   1040 <puts@plt>
mov    %r15,%rdi
call   1040 <puts@plt>
mov    %r12,%rdi
call   1040 <puts@plt>
mov    %r13,%rdi
call   1040 <puts@plt>
mov    %rbx,%rdi
mov    %rbp,%rsi
xor    %eax,%eax
call   1080 <scanf@plt>
mov    0x14(%rsp),%eax
cmp    $0x2,%eax
je     1260 <main+0xf0>
cmp    $0x1,%eax
je     1210 <main+0xa0>
test   %eax,%eax
jne    11b0 <main+0x40>
lea    0xe35(%rip),%rdi
jmp    11b7 <main+0x47>
nop
lea    0xe30(%rip),%rdi
call   1040 <puts@plt>
mov    %rbx,%rdi
lea    0xc(%rsp),%rsi
xor    %eax,%eax
call   1080 <scanf@plt>
lea    0xe29(%rip),%rdi
call   1040 <puts@plt>
lea    0xe23(%rip),%rdi
lea    0x10(%rsp),%rsi
xor    %eax,%eax
call   1080 <scanf@plt>
mov    0xc(%rsp),%edi
mov    0x10(%rsp),%esi
call   1090 <push@plt>
jmp    11bc <main+0x4c>
nopl   0x0(%rax)
lea    0xde0(%rip),%rdi
call   1040 <puts@plt>
mov    %rbx,%rdi
lea    0xc(%rsp),%rsi
xor    %eax,%eax
call   1080 <scanf@plt>
mov    0xc(%rsp),%edi
call   1060 <pop@plt>
mov    %eax,0x10(%rsp)
test   %eax,%eax
je     11bc <main+0x4c>
lea    0xdd1(%rip),%rdi
mov    %eax,%esi
call   1050 <printf@plt>
jmp    11bc <main+0x4c>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [27 x i8] c"What would you like to do?\00"
@.str.1 = [11 x i8] c" ( 0) Exit\00"
@.str.2 = [11 x i8] c" ( 1) Push\00"
@.str.3 = [10 x i8] c" ( 2) Pop\00"
@.str.4 = [7 x i8] c" %u%*c\00"
@.str.5 = [5 x i8] c"Bye!\00"
@.str.6 = [20 x i8] c"Stack Number (0-4)?\00"
@.str.7 = [6 x i8] c"Data?\00"
@.str.8 = [7 x i8] c" %d%*c\00"
@.str.9 = [4 x i8] c"%d\0A\00"
@.str.10 = [18 x i8] c"Incorrect Choice!\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 0, i32* %1
%5 = call i32 (...) @init()
br label %6
6: ; preds = %36, %0
%7 = call i32 @puts(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
%8 = call i32 @puts(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
%9 = call i32 @puts(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
%10 = call i32 @puts(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0))
%11 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), i32* %2)
%12 = load i32, i32* %2
switch i32 %12, label %33 [
i32 0, label %13
i32 1, label %15
i32 2, label %23
]
13: ; preds = %6
%14 = call i32 @puts(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
br label %35
15: ; preds = %6
%16 = call i32 @puts(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.6, i64 0, i64 0))
%17 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), i32* %3)
%18 = call i32 @puts(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.7, i64 0, i64 0))
%19 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.8, i64 0, i64 0), i32* %4)
%20 = load i32, i32* %3
%21 = load i32, i32* %4
%22 = call i32 @push(i32 %20, i32 %21)
br label %35
23: ; preds = %6
%24 = call i32 @puts(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.6, i64 0, i64 0))
%25 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), i32* %3)
%26 = load i32, i32* %3
%27 = call i32 @pop(i32 %26)
store i32 %27, i32* %4
%28 = icmp ne i32 %27, 0
br i1 %28, label %29, label %32
29: ; preds = %23
%30 = load i32, i32* %4
%31 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.9, i64 0, i64 0), i32 %30)
br label %32
32: ; preds = %29, %23
br label %35
33: ; preds = %6
%34 = call i32 @puts(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.10, i64 0, i64 0))
br label %35
35: ; preds = %33, %32, %15, %13
br label %36
36: ; preds = %35
%37 = load i32, i32* %2
%38 = icmp ne i32 %37, 0
br i1 %38, label %6, label %39
39: ; preds = %36
%40 = call i32 @putchar(i8 signext 10)
ret i32 0
}

LLVM IR (-O2):
@.str = [27 x i8] c"What would you like to do?\00"
@.str.1 = [11 x i8] c" ( 0) Exit\00"
@.str.2 = [11 x i8] c" ( 1) Push\00"
@.str.3 = [10 x i8] c" ( 2) Pop\00"
@.str.4 = [7 x i8] c" %u%*c\00"
@.str.5 = [5 x i8] c"Bye!\00"
@.str.6 = [20 x i8] c"Stack Number (0-4)?\00"
@.str.7 = [6 x i8] c"Data?\00"
@.str.8 = [7 x i8] c" %d%*c\00"
@.str.9 = [4 x i8] c"%d\0A\00"
@.str.10 = [18 x i8] c"Incorrect Choice!\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = bitcast i32* %1 to i8*
%5 = bitcast i32* %2 to i8*
%6 = bitcast i32* %3 to i8*
%7 = tail call i32 (...) @init()
br label %8
8: ; preds = %35, %0
%9 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
%10 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
%11 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
%12 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0))
%13 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), i32* %1)
%14 = load i32, i32* %1
switch i32 %14, label %33 [
i32 0, label %15
i32 1, label %17
i32 2, label %25
]
15: ; preds = %8
%16 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
br label %35
17: ; preds = %8
%18 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.6, i64 0, i64 0))
%19 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), i32* %2)
%20 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.7, i64 0, i64 0))
%21 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.8, i64 0, i64 0), i32* %3)
%22 = load i32, i32* %2
%23 = load i32, i32* %3
%24 = call i32 @push(i32 %22, i32 %23)
br label %35
25: ; preds = %8
%26 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.6, i64 0, i64 0))
%27 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), i32* %2)
%28 = load i32, i32* %2
%29 = call i32 @pop(i32 %28)
store i32 %29, i32* %3
%30 = icmp eq i32 %29, 0
br i1 %30, label %35, label %31
31: ; preds = %25
%32 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.9, i64 0, i64 0), i32 %29)
br label %35
33: ; preds = %8
%34 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.10, i64 0, i64 0))
br label %35
35: ; preds = %15, %17, %33, %31, %25
%36 = load i32, i32* %1
%37 = icmp eq i32 %36, 0
br i1 %37, label %38, label %8
38: ; preds = %35
%39 = call i32 @putchar(i8 signext 10)
ret i32 0
}