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

/* Variables and functions */
struct stack *create_stack();
int /*<<< orphan*/ destroy_stack(struct stack *);
int pop_off_stack(struct stack *);
int /*<<< orphan*/ print_stack(struct stack *);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ push_on_stack(struct stack *, int);
int main(void) {
  struct stack *s;
  int i;
  s = create_stack();
  print_stack(s);
  for (i = 0; i < 5; i++)
    push_on_stack(s, i);
  print_stack(s);
  i = pop_off_stack(s);
  printf("\nPopped %d\n", i);
  print_stack(s);
  i = pop_off_stack(s);
  printf("\nPopped %d\n", i);
  print_stack(s);
  for (i = 10; i < 15; i++)
    push_on_stack(s, i);
  print_stack(s);
  destroy_stack(s);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   1050 <create_stack@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1070 <print_stack@plt>
movl   $0x0,-0x14(%rbp)
cmpl   $0x5,-0x14(%rbp)
jge    11ae <main+0x4e>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1060 <push_on_stack@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    118a <main+0x2a>
mov    -0x10(%rbp),%rdi
call   1070 <print_stack@plt>
mov    -0x10(%rbp),%rdi
call   1080 <pop_off_stack@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%esi
lea    0xe33(%rip),%rdi
call   1040 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1070 <print_stack@plt>
mov    -0x10(%rbp),%rdi
call   1080 <pop_off_stack@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%esi
lea    0xe0f(%rip),%rdi
call   1040 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1070 <print_stack@plt>
movl   $0xa,-0x14(%rbp)
cmpl   $0xf,-0x14(%rbp)
jge    122a <main+0xca>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1060 <push_on_stack@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1206 <main+0xa6>
mov    -0x10(%rbp),%rdi
call   1070 <print_stack@plt>
mov    -0x10(%rbp),%rdi
call   1030 <destroy_stack@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
xor    %eax,%eax
call   1050 <create_stack@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1070 <print_stack@plt>
mov    %rbx,%rdi
xor    %esi,%esi
call   1060 <push_on_stack@plt>
mov    %rbx,%rdi
mov    $0x1,%esi
call   1060 <push_on_stack@plt>
mov    %rbx,%rdi
mov    $0x2,%esi
call   1060 <push_on_stack@plt>
mov    %rbx,%rdi
mov    $0x3,%esi
call   1060 <push_on_stack@plt>
mov    %rbx,%rdi
mov    $0x4,%esi
call   1060 <push_on_stack@plt>
mov    %rbx,%rdi
call   1070 <print_stack@plt>
mov    %rbx,%rdi
call   1080 <pop_off_stack@plt>
lea    0xe35(%rip),%r14
mov    %r14,%rdi
mov    %eax,%esi
call   1040 <printf@plt>
mov    %rbx,%rdi
call   1070 <print_stack@plt>
mov    %rbx,%rdi
call   1080 <pop_off_stack@plt>
mov    %r14,%rdi
mov    %eax,%esi
call   1040 <printf@plt>
mov    %rbx,%rdi
call   1070 <print_stack@plt>
mov    %rbx,%rdi
mov    $0xa,%esi
call   1060 <push_on_stack@plt>
mov    %rbx,%rdi
mov    $0xb,%esi
call   1060 <push_on_stack@plt>
mov    %rbx,%rdi
mov    $0xc,%esi
call   1060 <push_on_stack@plt>
mov    %rbx,%rdi
mov    $0xd,%esi
call   1060 <push_on_stack@plt>
mov    %rbx,%rdi
mov    $0xe,%esi
call   1060 <push_on_stack@plt>
mov    %rbx,%rdi
call   1070 <print_stack@plt>
mov    %rbx,%rdi
call   1030 <destroy_stack@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.stack = type { i32 }
@.str = [12 x i8] c"\0APopped %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca %struct.stack*
%3 = alloca i32
store i32 0, i32* %1
%4 = call %struct.stack* (...) @create_stack()
store %struct.stack* %4, %struct.stack** %2
%5 = load %struct.stack*, %struct.stack** %2
%6 = call i32 @print_stack(%struct.stack* %5)
store i32 0, i32* %3
br label %7
7: ; preds = %14, %0
%8 = load i32, i32* %3
%9 = icmp slt i32 %8, 5
br i1 %9, label %10, label %17
10: ; preds = %7
%11 = load %struct.stack*, %struct.stack** %2
%12 = load i32, i32* %3
%13 = call i32 @push_on_stack(%struct.stack* %11, i32 %12)
br label %14
14: ; preds = %10
%15 = load i32, i32* %3
%16 = add nsw i32 %15, 1
store i32 %16, i32* %3
br label %7
17: ; preds = %7
%18 = load %struct.stack*, %struct.stack** %2
%19 = call i32 @print_stack(%struct.stack* %18)
%20 = load %struct.stack*, %struct.stack** %2
%21 = call i32 @pop_off_stack(%struct.stack* %20)
store i32 %21, i32* %3
%22 = load i32, i32* %3
%23 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %22)
%24 = load %struct.stack*, %struct.stack** %2
%25 = call i32 @print_stack(%struct.stack* %24)
%26 = load %struct.stack*, %struct.stack** %2
%27 = call i32 @pop_off_stack(%struct.stack* %26)
store i32 %27, i32* %3
%28 = load i32, i32* %3
%29 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %28)
%30 = load %struct.stack*, %struct.stack** %2
%31 = call i32 @print_stack(%struct.stack* %30)
store i32 10, i32* %3
br label %32
32: ; preds = %39, %17
%33 = load i32, i32* %3
%34 = icmp slt i32 %33, 15
br i1 %34, label %35, label %42
35: ; preds = %32
%36 = load %struct.stack*, %struct.stack** %2
%37 = load i32, i32* %3
%38 = call i32 @push_on_stack(%struct.stack* %36, i32 %37)
br label %39
39: ; preds = %35
%40 = load i32, i32* %3
%41 = add nsw i32 %40, 1
store i32 %41, i32* %3
br label %32
42: ; preds = %32
%43 = load %struct.stack*, %struct.stack** %2
%44 = call i32 @print_stack(%struct.stack* %43)
%45 = load %struct.stack*, %struct.stack** %2
%46 = call i32 @destroy_stack(%struct.stack* %45)
ret i32 0
}

LLVM IR (-O2):
%struct.stack = type { i32 }
@.str = [12 x i8] c"\0APopped %d\0A\00"
define i32 @main() {
%1 = tail call %struct.stack* (...) @create_stack()
%2 = tail call i32 @print_stack(%struct.stack* %1)
%3 = tail call i32 @push_on_stack(%struct.stack* %1, i32 0)
%4 = tail call i32 @push_on_stack(%struct.stack* %1, i32 1)
%5 = tail call i32 @push_on_stack(%struct.stack* %1, i32 2)
%6 = tail call i32 @push_on_stack(%struct.stack* %1, i32 3)
%7 = tail call i32 @push_on_stack(%struct.stack* %1, i32 4)
%8 = tail call i32 @print_stack(%struct.stack* %1)
%9 = tail call i32 @pop_off_stack(%struct.stack* %1)
%10 = tail call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %9)
%11 = tail call i32 @print_stack(%struct.stack* %1)
%12 = tail call i32 @pop_off_stack(%struct.stack* %1)
%13 = tail call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %12)
%14 = tail call i32 @print_stack(%struct.stack* %1)
%15 = tail call i32 @push_on_stack(%struct.stack* %1, i32 10)
%16 = tail call i32 @push_on_stack(%struct.stack* %1, i32 11)
%17 = tail call i32 @push_on_stack(%struct.stack* %1, i32 12)
%18 = tail call i32 @push_on_stack(%struct.stack* %1, i32 13)
%19 = tail call i32 @push_on_stack(%struct.stack* %1, i32 14)
%20 = tail call i32 @print_stack(%struct.stack* %1)
%21 = tail call i32 @destroy_stack(%struct.stack* %1)
ret i32 0
}