#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*/ printf(char *, ...);
void *stack_create();
int /*<<< orphan*/ stack_destroy(void *);
int /*<<< orphan*/ stack_pop(void *);
int /*<<< orphan*/ stack_push(void *, int);
int *stack_top(void *);
int main(void) {
  int val;
  void *instance;
  int *top;
  instance = stack_create();
  if (instance == NULL) {
    printf("creating stack failed\n");
    return -1;
  }
  stack_pop(instance);
  val = 5;
  stack_push(instance, val);
  printf("push '%d' into stack\n", val);
  top = stack_top(instance);
  printf("top of the stack is %d\n", *top);
  val = 9;
  stack_push(instance, val);
  printf("push '%d' into stack\n", val);
  top = stack_top(instance);
  printf("top of the stack is %d\n", *top);
  stack_pop(instance);
  printf("pop the top item of the stack\n");
  top = stack_top(instance);
  printf("top of the stack is %d\n", *top);
  stack_destroy(instance);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   1050 <stack_create@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    119f <main+0x3f>
lea    0xe74(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    127a <main+0x11a>
mov    -0x10(%rbp),%rdi
call   1080 <stack_pop@plt>
movl   $0x5,-0x8(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%esi
call   1070 <stack_push@plt>
mov    -0x8(%rbp),%esi
lea    0xe52(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <stack_top@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%esi
lea    0xe47(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x9,-0x8(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%esi
call   1070 <stack_push@plt>
mov    -0x8(%rbp),%esi
lea    0xe0d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <stack_top@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%esi
lea    0xe02(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1080 <stack_pop@plt>
lea    0xe03(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <stack_top@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%esi
lea    0xdca(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1060 <stack_destroy@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
xor    %ebp,%ebp
xor    %eax,%eax
call   1060 <stack_create@plt>
test   %rax,%rax
je     1234 <main+0xc4>
mov    %rax,%rbx
mov    %rax,%rdi
call   1090 <stack_pop@plt>
mov    %rbx,%rdi
mov    $0x5,%esi
call   1080 <stack_push@plt>
lea    0xe58(%rip),%r15
mov    %r15,%rdi
mov    $0x5,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,%rdi
call   1030 <stack_top@plt>
mov    (%rax),%esi
lea    0xe4e(%rip),%r14
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,%rdi
mov    $0x9,%esi
call   1080 <stack_push@plt>
mov    %r15,%rdi
mov    $0x9,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,%rdi
call   1030 <stack_top@plt>
mov    (%rax),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,%rdi
call   1090 <stack_pop@plt>
lea    0xe1d(%rip),%rdi
call   1040 <puts@plt>
mov    %rbx,%rdi
call   1030 <stack_top@plt>
mov    (%rax),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,%rdi
call   1070 <stack_destroy@plt>
jmp    1245 <main+0xd5>
lea    0xe11(%rip),%rdi
call   1040 <puts@plt>
mov    $0xffffffff,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [23 x i8] c"creating stack failed\0A\00"
@.str.1 = [22 x i8] c"push '%d' into stack\0A\00"
@.str.2 = [24 x i8] c"top of the stack is %d\0A\00"
@.str.3 = [31 x i8] c"pop the top item of the stack\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32*
store i32 0, i32* %1
%5 = call i8* (...) @stack_create()
store i8* %5, i8** %3
%6 = load i8*, i8** %3
%7 = icmp eq i8* %6, null
br i1 %7, label %8, label %10
8: ; preds = %0
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %1
br label %43
10: ; preds = %0
%11 = load i8*, i8** %3
%12 = call i32 @stack_pop(i8* %11)
store i32 5, i32* %2
%13 = load i8*, i8** %3
%14 = load i32, i32* %2
%15 = call i32 @stack_push(i8* %13, i32 %14)
%16 = load i32, i32* %2
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i32 %16)
%18 = load i8*, i8** %3
%19 = call i32* @stack_top(i8* %18)
store i32* %19, i32** %4
%20 = load i32*, i32** %4
%21 = load i32, i32* %20
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i32 %21)
store i32 9, i32* %2
%23 = load i8*, i8** %3
%24 = load i32, i32* %2
%25 = call i32 @stack_push(i8* %23, i32 %24)
%26 = load i32, i32* %2
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i32 %26)
%28 = load i8*, i8** %3
%29 = call i32* @stack_top(i8* %28)
store i32* %29, i32** %4
%30 = load i32*, i32** %4
%31 = load i32, i32* %30
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i32 %31)
%33 = load i8*, i8** %3
%34 = call i32 @stack_pop(i8* %33)
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0))
%36 = load i8*, i8** %3
%37 = call i32* @stack_top(i8* %36)
store i32* %37, i32** %4
%38 = load i32*, i32** %4
%39 = load i32, i32* %38
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i32 %39)
%41 = load i8*, i8** %3
%42 = call i32 @stack_destroy(i8* %41)
store i32 0, i32* %1
br label %43
43: ; preds = %10, %8
%44 = load i32, i32* %1
ret i32 %44
}

LLVM IR (-O2):
@.str.1 = [22 x i8] c"push '%d' into stack\0A\00"
@.str.2 = [24 x i8] c"top of the stack is %d\0A\00"
@str = [30 x i8] c"pop the top item of the stack\00"
@str.4 = [22 x i8] c"creating stack failed\00"
define i32 @main() {
%1 = tail call i8* (...) @stack_create()
%2 = icmp eq i8* %1, null
br i1 %2, label %3, label %5
3: ; preds = %0
%4 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str.4, i64 0, i64 0))
br label %23
5: ; preds = %0
%6 = tail call i32 @stack_pop(i8* %1)
%7 = tail call i32 @stack_push(i8* %1, i32 5)
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i32 5)
%9 = tail call i32* @stack_top(i8* %1)
%10 = load i32, i32* %9
%11 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i32 %10)
%12 = tail call i32 @stack_push(i8* %1, i32 9)
%13 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i32 9)
%14 = tail call i32* @stack_top(i8* %1)
%15 = load i32, i32* %14
%16 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i32 %15)
%17 = tail call i32 @stack_pop(i8* %1)
%18 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @str, i64 0, i64 0))
%19 = tail call i32* @stack_top(i8* %1)
%20 = load i32, i32* %19
%21 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i32 %20)
%22 = tail call i32 @stack_destroy(i8* %1)
br label %23
23: ; preds = %5, %3
%24 = phi i32 [ -1, %3 ], [ 0, %5 ]
ret i32 %24
}