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

/* Variables and functions */
int peek(struct StackNode *);
int pop(struct StackNode **);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ push(struct StackNode **, int);
int main() {
  struct StackNode *root = NULL;
  push(&root, 10);
  push(&root, 20);
  push(&root, 30);
  printf("%d popped from stack\n", pop(&root));
  printf("top element is %d\n", peek(root));
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
movq   $0x0,-0x10(%rbp)
lea    -0x10(%rbp),%rdi
mov    $0xa,%esi
call   1060 <push@plt>
lea    -0x10(%rbp),%rdi
mov    $0x14,%esi
call   1060 <push@plt>
lea    -0x10(%rbp),%rdi
mov    $0x1e,%esi
call   1060 <push@plt>
lea    -0x10(%rbp),%rdi
call   1050 <pop@plt>
mov    %eax,%esi
lea    0xe6d(%rip),%rdi
call   1040 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <peek@plt>
mov    %eax,%esi
lea    0xe6c(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
movq   $0x0,0x8(%rsp)
lea    0x8(%rsp),%rbx
mov    %rbx,%rdi
mov    $0xa,%esi
call   1060 <push@plt>
mov    %rbx,%rdi
mov    $0x14,%esi
call   1060 <push@plt>
mov    %rbx,%rdi
mov    $0x1e,%esi
call   1060 <push@plt>
mov    %rbx,%rdi
call   1050 <pop@plt>
lea    0xe77(%rip),%rdi
mov    %eax,%esi
call   1040 <printf@plt>
mov    0x8(%rsp),%rdi
call   1030 <peek@plt>
lea    0xe75(%rip),%rdi
mov    %eax,%esi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.StackNode = type { i32 }
@.str = [22 x i8] c"%d popped from stack\0A\00"
@.str.1 = [19 x i8] c"top element is %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca %struct.StackNode*
store i32 0, i32* %1
store %struct.StackNode* null, %struct.StackNode** %2
%3 = call i32 @push(%struct.StackNode** %2, i32 10)
%4 = call i32 @push(%struct.StackNode** %2, i32 20)
%5 = call i32 @push(%struct.StackNode** %2, i32 30)
%6 = call i32 @pop(%struct.StackNode** %2)
%7 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i32 %6)
%8 = load %struct.StackNode*, %struct.StackNode** %2
%9 = call i32 @peek(%struct.StackNode* %8)
%10 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i32 %9)
ret i32 0
}

LLVM IR (-O2):
%struct.StackNode = type { i32 }
@.str = [22 x i8] c"%d popped from stack\0A\00"
@.str.1 = [19 x i8] c"top element is %d\0A\00"
define i32 @main() {
%1 = alloca %struct.StackNode*
%2 = bitcast %struct.StackNode** %1 to i8*
store %struct.StackNode* null, %struct.StackNode** %1
%3 = call i32 @push(%struct.StackNode** %1, i32 10)
%4 = call i32 @push(%struct.StackNode** %1, i32 20)
%5 = call i32 @push(%struct.StackNode** %1, i32 30)
%6 = call i32 @pop(%struct.StackNode** %1)
%7 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i32 %6)
%8 = load %struct.StackNode*, %struct.StackNode** %1
%9 = call i32 @peek(%struct.StackNode* %8)
%10 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i32 %9)
ret i32 0
}