int main(void) {
  push(3);
  push(5);
  push(9);
  push(1);
  push(12);
  push(15);
  printf("Elements at top of the stack: %d\n", peek());
  printf("Elements: \n");
  while (!isempty()) {
    int data = pop();
    printf("%d\n", data);
  }
  printf("Stack full: %s\n", isfull() ? "true" : "false");
  printf("Stack empty: %s\n", isempty() ? "true" : "false");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x3,%edi
mov    $0x0,%al
call   1070 <push@plt>
mov    $0x5,%edi
mov    $0x0,%al
call   1070 <push@plt>
mov    $0x9,%edi
mov    $0x0,%al
call   1070 <push@plt>
mov    $0x1,%edi
mov    $0x0,%al
call   1070 <push@plt>
mov    $0xc,%edi
mov    $0x0,%al
call   1070 <push@plt>
mov    $0xf,%edi
mov    $0x0,%al
call   1070 <push@plt>
mov    $0x0,%al
call   1030 <peek@plt>
mov    %eax,%esi
lea    0xe39(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xe4d(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x0,%al
call   1080 <isempty@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    11f8 <main+0x98>
jmp    1218 <main+0xb8>
mov    $0x0,%al
call   1060 <pop@plt>
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%esi
lea    0xe12(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    11dc <main+0x7c>
mov    $0x0,%al
call   1040 <isfull@plt>
mov    %eax,%ecx
lea    0xe1b(%rip),%rsi
lea    0xe0f(%rip),%rax
cmp    $0x0,%ecx
cmovne %rax,%rsi
lea    0xdf1(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x0,%al
call   1080 <isempty@plt>
mov    %eax,%ecx
lea    0xdef(%rip),%rsi
lea    0xde3(%rip),%rax
cmp    $0x0,%ecx
cmovne %rax,%rsi
lea    0xde0(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
mov    $0x3,%edi
xor    %eax,%eax
call   1080 <push@plt>
mov    $0x5,%edi
xor    %eax,%eax
call   1080 <push@plt>
mov    $0x9,%edi
xor    %eax,%eax
call   1080 <push@plt>
mov    $0x1,%edi
xor    %eax,%eax
call   1080 <push@plt>
mov    $0xc,%edi
xor    %eax,%eax
call   1080 <push@plt>
mov    $0xf,%edi
xor    %eax,%eax
call   1080 <push@plt>
xor    %eax,%eax
call   1030 <peek@plt>
lea    0xe36(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xe74(%rip),%rdi
call   1050 <puts@plt>
xor    %eax,%eax
call   1090 <isempty@plt>
test   %eax,%eax
jne    121e <main+0xae>
lea    0xe2d(%rip),%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1070 <pop@plt>
mov    %rbx,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1060 <printf@plt>
xor    %eax,%eax
call   1090 <isempty@plt>
test   %eax,%eax
je     1200 <main+0x90>
xor    %eax,%eax
call   1040 <isfull@plt>
test   %eax,%eax
lea    0xe09(%rip),%r14
lea    0xdfd(%rip),%rbx
mov    %rbx,%rsi
cmove  %r14,%rsi
lea    0xddf(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
xor    %eax,%eax
call   1090 <isempty@plt>
test   %eax,%eax
cmove  %r14,%rbx
lea    0xddf(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [34 x i8] c"Elements at top of the stack: %d\0A\00"
@.str.1 = [12 x i8] c"Elements: \0A\00"
@.str.2 = [4 x i8] c"%d\0A\00"
@.str.3 = [16 x i8] c"Stack full: %s\0A\00"
@.str.4 = [5 x i8] c"true\00"
@.str.5 = [6 x i8] c"false\00"
@.str.6 = [17 x i8] c"Stack empty: %s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
store i32 0, i32* %1
%3 = call i32 (i32, ...) bitcast (i32 (...)* @push to i32 (i32, ...)*)(i32 3)
%4 = call i32 (i32, ...) bitcast (i32 (...)* @push to i32 (i32, ...)*)(i32 5)
%5 = call i32 (i32, ...) bitcast (i32 (...)* @push to i32 (i32, ...)*)(i32 9)
%6 = call i32 (i32, ...) bitcast (i32 (...)* @push to i32 (i32, ...)*)(i32 1)
%7 = call i32 (i32, ...) bitcast (i32 (...)* @push to i32 (i32, ...)*)(i32 12)
%8 = call i32 (i32, ...) bitcast (i32 (...)* @push to i32 (i32, ...)*)(i32 15)
%9 = call i32 (...) @peek()
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i32 %9)
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
br label %12
12: ; preds = %16, %0
%13 = call i32 (...) @isempty()
%14 = icmp ne i32 %13, 0
%15 = xor i1 %14, true
br i1 %15, label %16, label %20
16: ; preds = %12
%17 = call i32 (...) @pop()
store i32 %17, i32* %2
%18 = load i32, i32* %2
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %18)
br label %12
20: ; preds = %12
%21 = call i32 (...) @isfull()
%22 = icmp ne i32 %21, 0
%23 = zext i1 %22 to i64
%24 = select i1 %22, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0)
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0), i8* %24)
%26 = call i32 (...) @isempty()
%27 = icmp ne i32 %26, 0
%28 = zext i1 %27 to i64
%29 = select i1 %27, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0)
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.6, i64 0, i64 0), i8* %29)
ret i32 0
}

LLVM IR (-O2):
@.str = [34 x i8] c"Elements at top of the stack: %d\0A\00"
@.str.2 = [4 x i8] c"%d\0A\00"
@.str.3 = [16 x i8] c"Stack full: %s\0A\00"
@.str.4 = [5 x i8] c"true\00"
@.str.5 = [6 x i8] c"false\00"
@.str.6 = [17 x i8] c"Stack empty: %s\0A\00"
@str = [11 x i8] c"Elements: \00"
define i32 @main() {
%1 = tail call i32 (i32, ...) bitcast (i32 (...)* @push to i32 (i32, ...)*)(i32 3)
%2 = tail call i32 (i32, ...) bitcast (i32 (...)* @push to i32 (i32, ...)*)(i32 5)
%3 = tail call i32 (i32, ...) bitcast (i32 (...)* @push to i32 (i32, ...)*)(i32 9)
%4 = tail call i32 (i32, ...) bitcast (i32 (...)* @push to i32 (i32, ...)*)(i32 1)
%5 = tail call i32 (i32, ...) bitcast (i32 (...)* @push to i32 (i32, ...)*)(i32 12)
%6 = tail call i32 (i32, ...) bitcast (i32 (...)* @push to i32 (i32, ...)*)(i32 15)
%7 = tail call i32 (...) @peek()
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i32 %7)
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @str, i64 0, i64 0))
%10 = tail call i32 (...) @isempty()
%11 = icmp eq i32 %10, 0
br i1 %11, label %12, label %17
12: ; preds = %0, %12
%13 = tail call i32 (...) @pop()
%14 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %13)
%15 = tail call i32 (...) @isempty()
%16 = icmp eq i32 %15, 0
br i1 %16, label %12, label %17
17: ; preds = %12, %0
%18 = tail call i32 (...) @isfull()
%19 = icmp eq i32 %18, 0
%20 = select i1 %19, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0)
%21 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0), i8* %20)
%22 = tail call i32 (...) @isempty()
%23 = icmp eq i32 %22, 0
%24 = select i1 %23, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0)
%25 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.6, i64 0, i64 0), i8* %24)
ret i32 0
}