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

/* Variables and functions */
struct node *creat_stack();
int /*<<< orphan*/ pop_stack(struct node *);
int /*<<< orphan*/ push_stack(struct node **, int);
int main() {
  int temp = 0;
  int array[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
  struct node *p_top = NULL;
  p_top = creat_stack();
  for (temp = 0; temp < 10; temp++) {
    push_stack(&p_top, array[temp]);
  }
  for (temp = 0; temp < 10; temp++) {
    pop_stack(p_top);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
lea    -0x30(%rbp),%rdi
lea    0xe9f(%rip),%rsi
mov    $0x28,%edx
call   1040 <memcpy@plt>
movq   $0x0,-0x38(%rbp)
mov    $0x0,%al
call   1030 <creat_stack@plt>
mov    %rax,-0x38(%rbp)
movl   $0x0,-0x8(%rbp)
cmpl   $0xa,-0x8(%rbp)
jge    11ae <main+0x6e>
movslq -0x8(%rbp),%rax
mov    -0x30(%rbp,%rax,4),%esi
lea    -0x38(%rbp),%rdi
call   1050 <push_stack@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1185 <main+0x45>
movl   $0x0,-0x8(%rbp)
cmpl   $0xa,-0x8(%rbp)
jge    11d6 <main+0x96>
mov    -0x38(%rbp),%rdi
call   1060 <pop_stack@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    11b5 <main+0x75>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
xor    %eax,%eax
call   1030 <creat_stack@plt>
mov    %rax,0x8(%rsp)
lea    0x8(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x1,%esi
call   1040 <push_stack@plt>
mov    %rbx,%rdi
mov    $0x2,%esi
call   1040 <push_stack@plt>
mov    %rbx,%rdi
mov    $0x3,%esi
call   1040 <push_stack@plt>
mov    %rbx,%rdi
mov    $0x4,%esi
call   1040 <push_stack@plt>
mov    %rbx,%rdi
mov    $0x5,%esi
call   1040 <push_stack@plt>
mov    %rbx,%rdi
mov    $0x6,%esi
call   1040 <push_stack@plt>
mov    %rbx,%rdi
mov    $0x7,%esi
call   1040 <push_stack@plt>
mov    %rbx,%rdi
mov    $0x8,%esi
call   1040 <push_stack@plt>
mov    %rbx,%rdi
mov    $0x9,%esi
call   1040 <push_stack@plt>
mov    %rbx,%rdi
mov    $0xa,%esi
call   1040 <push_stack@plt>
mov    0x8(%rsp),%rdi
call   1050 <pop_stack@plt>
mov    0x8(%rsp),%rdi
call   1050 <pop_stack@plt>
mov    0x8(%rsp),%rdi
call   1050 <pop_stack@plt>
mov    0x8(%rsp),%rdi
call   1050 <pop_stack@plt>
mov    0x8(%rsp),%rdi
call   1050 <pop_stack@plt>
mov    0x8(%rsp),%rdi
call   1050 <pop_stack@plt>
mov    0x8(%rsp),%rdi
call   1050 <pop_stack@plt>
mov    0x8(%rsp),%rdi
call   1050 <pop_stack@plt>
mov    0x8(%rsp),%rdi
call   1050 <pop_stack@plt>
mov    0x8(%rsp),%rdi
call   1050 <pop_stack@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.node = type { i32 }
@__const.main.array = [10 x i32] [i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, i32 8, i32 9, i32 10]
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [10 x i32]
%4 = alloca %struct.node*
store i32 0, i32* %1
store i32 0, i32* %2
%5 = bitcast [10 x i32]* %3 to i8*
store %struct.node* null, %struct.node** %4
%6 = call %struct.node* (...) @creat_stack()
store %struct.node* %6, %struct.node** %4
store i32 0, i32* %2
br label %7
7: ; preds = %16, %0
%8 = load i32, i32* %2
%9 = icmp slt i32 %8, 10
br i1 %9, label %10, label %19
10: ; preds = %7
%11 = load i32, i32* %2
%12 = sext i32 %11 to i64
%13 = getelementptr inbounds [10 x i32], [10 x i32]* %3, i64 0, i64 %12
%14 = load i32, i32* %13
%15 = call i32 @push_stack(%struct.node** %4, i32 %14)
br label %16
16: ; preds = %10
%17 = load i32, i32* %2
%18 = add nsw i32 %17, 1
store i32 %18, i32* %2
br label %7
19: ; preds = %7
store i32 0, i32* %2
br label %20
20: ; preds = %26, %19
%21 = load i32, i32* %2
%22 = icmp slt i32 %21, 10
br i1 %22, label %23, label %29
23: ; preds = %20
%24 = load %struct.node*, %struct.node** %4
%25 = call i32 @pop_stack(%struct.node* %24)
br label %26
26: ; preds = %23
%27 = load i32, i32* %2
%28 = add nsw i32 %27, 1
store i32 %28, i32* %2
br label %20
29: ; preds = %20
ret i32 0
}

LLVM IR (-O2):
%struct.node = type { i32 }
define i32 @main() {
%1 = alloca %struct.node*
%2 = bitcast %struct.node** %1 to i8*
%3 = tail call %struct.node* (...) @creat_stack()
store %struct.node* %3, %struct.node** %1
%4 = call i32 @push_stack(%struct.node** %1, i32 1)
%5 = call i32 @push_stack(%struct.node** %1, i32 2)
%6 = call i32 @push_stack(%struct.node** %1, i32 3)
%7 = call i32 @push_stack(%struct.node** %1, i32 4)
%8 = call i32 @push_stack(%struct.node** %1, i32 5)
%9 = call i32 @push_stack(%struct.node** %1, i32 6)
%10 = call i32 @push_stack(%struct.node** %1, i32 7)
%11 = call i32 @push_stack(%struct.node** %1, i32 8)
%12 = call i32 @push_stack(%struct.node** %1, i32 9)
%13 = call i32 @push_stack(%struct.node** %1, i32 10)
%14 = load %struct.node*, %struct.node** %1
%15 = call i32 @pop_stack(%struct.node* %14)
%16 = load %struct.node*, %struct.node** %1
%17 = call i32 @pop_stack(%struct.node* %16)
%18 = load %struct.node*, %struct.node** %1
%19 = call i32 @pop_stack(%struct.node* %18)
%20 = load %struct.node*, %struct.node** %1
%21 = call i32 @pop_stack(%struct.node* %20)
%22 = load %struct.node*, %struct.node** %1
%23 = call i32 @pop_stack(%struct.node* %22)
%24 = load %struct.node*, %struct.node** %1
%25 = call i32 @pop_stack(%struct.node* %24)
%26 = load %struct.node*, %struct.node** %1
%27 = call i32 @pop_stack(%struct.node* %26)
%28 = load %struct.node*, %struct.node** %1
%29 = call i32 @pop_stack(%struct.node* %28)
%30 = load %struct.node*, %struct.node** %1
%31 = call i32 @pop_stack(%struct.node* %30)
%32 = load %struct.node*, %struct.node** %1
%33 = call i32 @pop_stack(%struct.node* %32)
ret i32 0
}