#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 link {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ getchar();
struct link *pop(struct link *, int *);
int /*<<< orphan*/ printf(char *, ...);
struct link *push(struct link *, int);
int /*<<< orphan*/ puts(char *);
int /*<<< orphan*/ scanf(char *, int *);
int main() {
  struct link *top = NULL;
  int num = 0, menu = -1;
  while (menu != 0) {
    printf("\nPlease Choose an option:\n");
    printf("(1) Push to Stack\n(2) Pop from Stack\n\n(0) Exit Program (empty "
           "stack)\n");
    printf("\n---> ");
    scanf("%d", &menu);
    if (menu == 1) {
      printf("\nPush what value?: ");
      scanf("%d", &num);
      top = push(top, num);
    } else if (menu == 2) {
      top = pop(top, &num);
      if (top != NULL)
        printf("popped: %d\n", num);
    } else if (menu == 0) {
      puts("\n");
      while (top != NULL) {
        top = pop(top, &num);
        printf("%d\n", num);
      }
    } else {
      printf("\n-Invalid option-\n");
    }
  }
  printf("\n\[Press ENTER to close] ");
  getchar();
  getchar();
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movq   $0x0,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0xffffffff,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
je     12ac <main+0x14c>
lea    0xe6a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe77(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xeaf(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xea8(%rip),%rdi
lea    -0x18(%rbp),%rsi
call   1070 <scanf@plt>
cmpl   $0x1,-0x18(%rbp)
jne    1206 <main+0xa6>
lea    0xe91(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe80(%rip),%rdi
lea    -0x14(%rbp),%rsi
call   1070 <scanf@plt>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1080 <push@plt>
mov    %rax,-0x10(%rbp)
jmp    12a7 <main+0x147>
cmpl   $0x2,-0x18(%rbp)
jne    1242 <main+0xe2>
mov    -0x10(%rbp),%rdi
lea    -0x14(%rbp),%rsi
call   1050 <pop@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     123d <main+0xdd>
mov    -0x14(%rbp),%esi
lea    0xe49(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    12a2 <main+0x142>
cmpl   $0x0,-0x18(%rbp)
jne    128f <main+0x12f>
lea    0xe0c(%rip),%rdi
call   1030 <puts@plt>
cmpq   $0x0,-0x10(%rbp)
je     128a <main+0x12a>
mov    -0x10(%rbp),%rdi
lea    -0x14(%rbp),%rsi
call   1050 <pop@plt>
mov    %rax,-0x10(%rbp)
mov    -0x14(%rbp),%esi
lea    0xe09(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1258 <main+0xf8>
jmp    129d <main+0x13d>
lea    0xdf5(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    12a2 <main+0x142>
jmp    12a7 <main+0x147>
jmp    1185 <main+0x25>
lea    0xdeb(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x0,%al
call   1060 <getchar@plt>
mov    $0x0,%al
call   1060 <getchar@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
push   %rax
movl   $0x0,(%rsp)
movl   $0xffffffff,0x4(%rsp)
ff
lea    0xe7f(%rip),%r12
lea    0xe7f(%rip),%rbx
lea    0x4(%rsp),%r13
mov    %rsp,%rbp
lea    0xe8f(%rip),%r14
xor    %r15d,%r15d
jmp    11b7 <main+0x57>
nopl   0x0(%rax)
lea    0xefb(%rip),%rdi
call   1030 <puts@plt>
cmpl   $0x0,0x4(%rsp)
je     1298 <main+0x138>
lea    0xe85(%rip),%rdi
call   1030 <puts@plt>
lea    0xe93(%rip),%rdi
call   1030 <puts@plt>
mov    %r12,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbx,%rdi
mov    %r13,%rsi
call   1070 <scanf@plt>
mov    0x4(%rsp),%eax
test   %eax,%eax
je     1250 <main+0xf0>
cmp    $0x2,%eax
je     1220 <main+0xc0>
cmp    $0x1,%eax
jne    11a0 <main+0x40>
lea    0xe0d(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbx,%rdi
mov    %rbp,%rsi
call   1070 <scanf@plt>
mov    (%rsp),%esi
mov    %r15,%rdi
call   1080 <push@plt>
mov    %rax,%r15
jmp    11ac <main+0x4c>
nop
mov    %r15,%rdi
mov    %rbp,%rsi
call   1050 <pop@plt>
test   %rax,%rax
je     1290 <main+0x130>
mov    %rax,%r15
mov    (%rsp),%esi
lea    0xde1(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    11ac <main+0x4c>
nopl   0x0(%rax)
lea    0xdd1(%rip),%rdi
call   1030 <puts@plt>
test   %r15,%r15
je     1290 <main+0x130>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r15,%rdi
mov    %rbp,%rsi
call   1050 <pop@plt>
mov    %rax,%r15
mov    (%rsp),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
test   %r15,%r15
jne    1270 <main+0x110>
xor    %r15d,%r15d
jmp    11ac <main+0x4c>
lea    0xd8b(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
call   1060 <getchar@plt>
xor    %eax,%eax
call   1060 <getchar@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.link = type { i32 }
@.str = [27 x i8] c"\0APlease Choose an option:\0A\00"
@.str.1 = [70 x i8] c"(1) Push to Stack\0A(2) Pop from Stack\0A\0A(0) Exit Program (empty stack)\0A\00"
@.str.2 = [7 x i8] c"\0A---> \00"
@.str.3 = [3 x i8] c"%d\00"
@.str.4 = [20 x i8] c"\0APush what value?: \00"
@.str.5 = [12 x i8] c"popped: %d\0A\00"
@.str.6 = [2 x i8] c"\0A\00"
@.str.7 = [4 x i8] c"%d\0A\00"
@.str.8 = [19 x i8] c"\0A-Invalid option-\0A\00"
@.str.9 = [25 x i8] c"\0A[Press ENTER to close] \00"
define i32 @main() {
%1 = alloca i32
%2 = alloca %struct.link*
%3 = alloca i32
%4 = alloca i32
store i32 0, i32* %1
store %struct.link* null, %struct.link** %2
store i32 0, i32* %3
store i32 -1, i32* %4
br label %5
5: ; preds = %51, %0
%6 = load i32, i32* %4
%7 = icmp ne i32 %6, 0
br i1 %7, label %8, label %52
8: ; preds = %5
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([70 x i8], [70 x i8]* @.str.1, i64 0, i64 0))
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%12 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %4)
%13 = load i32, i32* %4
%14 = icmp eq i32 %13, 1
br i1 %14, label %15, label %21
15: ; preds = %8
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0))
%17 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %3)
%18 = load %struct.link*, %struct.link** %2
%19 = load i32, i32* %3
%20 = call %struct.link* @push(%struct.link* %18, i32 %19)
store %struct.link* %20, %struct.link** %2
br label %51
21: ; preds = %8
%22 = load i32, i32* %4
%23 = icmp eq i32 %22, 2
br i1 %23, label %24, label %33
24: ; preds = %21
%25 = load %struct.link*, %struct.link** %2
%26 = call %struct.link* @pop(%struct.link* %25, i32* %3)
store %struct.link* %26, %struct.link** %2
%27 = load %struct.link*, %struct.link** %2
%28 = icmp ne %struct.link* %27, null
br i1 %28, label %29, label %32
29: ; preds = %24
%30 = load i32, i32* %3
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.5, i64 0, i64 0), i32 %30)
br label %32
32: ; preds = %29, %24
br label %50
33: ; preds = %21
%34 = load i32, i32* %4
%35 = icmp eq i32 %34, 0
br i1 %35, label %36, label %47
36: ; preds = %33
%37 = call i32 @puts(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
br label %38
38: ; preds = %41, %36
%39 = load %struct.link*, %struct.link** %2
%40 = icmp ne %struct.link* %39, null
br i1 %40, label %41, label %46
41: ; preds = %38
%42 = load %struct.link*, %struct.link** %2
%43 = call %struct.link* @pop(%struct.link* %42, i32* %3)
store %struct.link* %43, %struct.link** %2
%44 = load i32, i32* %3
%45 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.7, i64 0, i64 0), i32 %44)
br label %38
46: ; preds = %38
br label %49
47: ; preds = %33
%48 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.8, i64 0, i64 0))
br label %49
49: ; preds = %47, %46
br label %50
50: ; preds = %49, %32
br label %51
51: ; preds = %50, %15
br label %5
52: ; preds = %5
%53 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.9, i64 0, i64 0))
%54 = call i32 (...) @getchar()
%55 = call i32 (...) @getchar()
ret i32 0
}

LLVM IR (-O2):
%struct.link = type { i32 }
@.str.2 = [7 x i8] c"\0A---> \00"
@.str.3 = [3 x i8] c"%d\00"
@.str.4 = [20 x i8] c"\0APush what value?: \00"
@.str.5 = [12 x i8] c"popped: %d\0A\00"
@.str.6 = [2 x i8] c"\0A\00"
@.str.7 = [4 x i8] c"%d\0A\00"
@.str.9 = [25 x i8] c"\0A[Press ENTER to close] \00"
@str = [26 x i8] c"\0APlease Choose an option:\00"
@str.10 = [69 x i8] c"(1) Push to Stack\0A(2) Pop from Stack\0A\0A(0) Exit Program (empty stack)\00"
@str.11 = [18 x i8] c"\0A-Invalid option-\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = bitcast i32* %1 to i8*
store i32 0, i32* %1
%4 = bitcast i32* %2 to i8*
store i32 -1, i32* %2
br label %5
5: ; preds = %0, %34
%6 = phi %struct.link* [ null, %0 ], [ %35, %34 ]
%7 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str, i64 0, i64 0))
%8 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([69 x i8], [69 x i8]* @str.10, i64 0, i64 0))
%9 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%10 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %2)
%11 = load i32, i32* %2
switch i32 %11, label %32 [
i32 1, label %12
i32 2, label %17
i32 0, label %23
]
12: ; preds = %5
%13 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0))
%14 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %1)
%15 = load i32, i32* %1
%16 = call %struct.link* @push(%struct.link* %6, i32 %15)
br label %34
17: ; preds = %5
%18 = call %struct.link* @pop(%struct.link* %6, i32* %1)
%19 = icmp eq %struct.link* %18, null
br i1 %19, label %34, label %20
20: ; preds = %17
%21 = load i32, i32* %1
%22 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.5, i64 0, i64 0), i32 %21)
br label %34
23: ; preds = %5
%24 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
%25 = icmp eq %struct.link* %6, null
br i1 %25, label %34, label %26
26: ; preds = %23, %26
%27 = phi %struct.link* [ %28, %26 ], [ %6, %23 ]
%28 = call %struct.link* @pop(%struct.link* %27, i32* %1)
%29 = load i32, i32* %1
%30 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.7, i64 0, i64 0), i32 %29)
%31 = icmp eq %struct.link* %28, null
br i1 %31, label %34, label %26
32: ; preds = %5
%33 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str.11, i64 0, i64 0))
br label %34
34: ; preds = %26, %23, %20, %17, %32, %12
%35 = phi %struct.link* [ %16, %12 ], [ %18, %20 ], [ null, %17 ], [ %6, %32 ], [ null, %23 ], [ null, %26 ]
%36 = load i32, i32* %2
%37 = icmp eq i32 %36, 0
br i1 %37, label %38, label %5
38: ; preds = %34
%39 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.9, i64 0, i64 0))
%40 = call i32 (...) @getchar()
%41 = call i32 (...) @getchar()
ret i32 0
}