#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 */
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ stack_delete(struct stack *);
struct stack *stack_new();
scalar_t__ stack_pick(struct stack *);
struct stack *stack_pop(struct stack *);
int /*<<< orphan*/ stack_push(struct stack *, int *);
int main(int argc, char *argv[]) {
  int i = 0;
  struct stack *s;
  s = stack_new();
  for (i = 0; i < 10; i++)
    stack_push(s, &i);
  for (i = 0; i < 10; i++) {
    printf("%d\n", *(int *)stack_pick(s));
    s = stack_pop(s);
  }
  stack_delete(s);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    $0x0,%al
call   1060 <stack_new@plt>
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x14(%rbp)
cmpl   $0xa,-0x14(%rbp)
jge    11b4 <main+0x54>
mov    -0x20(%rbp),%rdi
lea    -0x14(%rbp),%rsi
call   1070 <stack_push@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    118f <main+0x2f>
movl   $0x0,-0x14(%rbp)
cmpl   $0xa,-0x14(%rbp)
jge    11f7 <main+0x97>
mov    -0x20(%rbp),%rdi
call   1050 <stack_pick@plt>
mov    (%rax),%esi
lea    0xe29(%rip),%rdi
call   1040 <printf@plt>
mov    -0x20(%rbp),%rdi
call   1080 <stack_pop@plt>
mov    %rax,-0x20(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11bb <main+0x5b>
mov    -0x20(%rbp),%rdi
call   1030 <stack_delete@plt>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
xor    %eax,%eax
call   1060 <stack_new@plt>
mov    %rax,%rbx
movl   $0x0,0x4(%rsp)
lea    0x4(%rsp),%r14
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    %r14,%rsi
call   1070 <stack_push@plt>
mov    0x4(%rsp),%eax
lea    0x1(%rax),%ecx
mov    %ecx,0x4(%rsp)
cmp    $0x9,%eax
jl     1180 <main+0x20>
movl   $0x0,0x4(%rsp)
lea    0xe56(%rip),%r14
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1050 <stack_pick@plt>
mov    (%rax),%esi
mov    %r14,%rdi
call   1040 <printf@plt>
mov    %rbx,%rdi
call   1080 <stack_pop@plt>
mov    %rax,%rbx
mov    0x4(%rsp),%eax
lea    0x1(%rax),%ecx
mov    %ecx,0x4(%rsp)
cmp    $0x9,%eax
jl     11b0 <main+0x50>
mov    %rbx,%rdi
call   1030 <stack_delete@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.stack = type { i32 }
@.str = [4 x i8] c"%d\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca %struct.stack*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %6
%8 = call %struct.stack* (...) @stack_new()
store %struct.stack* %8, %struct.stack** %7
store i32 0, i32* %6
br label %9
9: ; preds = %15, %2
%10 = load i32, i32* %6
%11 = icmp slt i32 %10, 10
br i1 %11, label %12, label %18
12: ; preds = %9
%13 = load %struct.stack*, %struct.stack** %7
%14 = call i32 @stack_push(%struct.stack* %13, i32* %6)
br label %15
15: ; preds = %12
%16 = load i32, i32* %6
%17 = add nsw i32 %16, 1
store i32 %17, i32* %6
br label %9
18: ; preds = %9
store i32 0, i32* %6
br label %19
19: ; preds = %30, %18
%20 = load i32, i32* %6
%21 = icmp slt i32 %20, 10
br i1 %21, label %22, label %33
22: ; preds = %19
%23 = load %struct.stack*, %struct.stack** %7
%24 = call i64 @stack_pick(%struct.stack* %23)
%25 = inttoptr i64 %24 to i32*
%26 = load i32, i32* %25
%27 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %26)
%28 = load %struct.stack*, %struct.stack** %7
%29 = call %struct.stack* @stack_pop(%struct.stack* %28)
store %struct.stack* %29, %struct.stack** %7
br label %30
30: ; preds = %22
%31 = load i32, i32* %6
%32 = add nsw i32 %31, 1
store i32 %32, i32* %6
br label %19
33: ; preds = %19
%34 = load %struct.stack*, %struct.stack** %7
%35 = call i32 @stack_delete(%struct.stack* %34)
%36 = load i32, i32* %3
ret i32 %36
}

LLVM IR (-O2):
%struct.stack = type { i32 }
@.str = [4 x i8] c"%d\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
%5 = tail call %struct.stack* (...) @stack_new()
store i32 0, i32* %3
br label %7
6: ; preds = %7
store i32 0, i32* %3
br label %12
7: ; preds = %2, %7
%8 = call i32 @stack_push(%struct.stack* %5, i32* %3)
%9 = load i32, i32* %3
%10 = add nsw i32 %9, 1
store i32 %10, i32* %3
%11 = icmp slt i32 %9, 9
br i1 %11, label %7, label %6
12: ; preds = %6, %12
%13 = phi %struct.stack* [ %5, %6 ], [ %18, %12 ]
%14 = call i64 @stack_pick(%struct.stack* %13)
%15 = inttoptr i64 %14 to i32*
%16 = load i32, i32* %15
%17 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %16)
%18 = call %struct.stack* @stack_pop(%struct.stack* %13)
%19 = load i32, i32* %3
%20 = add nsw i32 %19, 1
store i32 %20, i32* %3
%21 = icmp slt i32 %19, 9
br i1 %21, label %12, label %22
22: ; preds = %12
%23 = call i32 @stack_delete(%struct.stack* %18)
ret i32 0
}