#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*/ get_top_val(struct stack *);
struct stack *pop(struct stack *);
int /*<<< orphan*/ print_stack(struct stack *);
struct stack *push(int, struct stack *);
int rand();
int main() {
  struct stack *top = NULL;
  top = push(rand() % 10, top);
  print_stack(top);
  top = pop(top);
  print_stack(top);
  top = pop(top);
  print_stack(top);
  top = push(rand() % 10, top);
  print_stack(top);
  top = push(rand() % 10, top);
  print_stack(top);
  top = push(rand() % 10, top);
  print_stack(top);
  top = push(rand() % 10, top);
  print_stack(top);
  top = push(rand() % 10, top);
  print_stack(top);
  top = push(rand() % 10, top);
  print_stack(top);
  top = push(rand() % 10, top);
  print_stack(top);
  get_top_val(top);
  top = pop(top);
  print_stack(top);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movq   $0x0,-0x8(%rbp)
mov    $0x0,%al
call   1070 <rand@plt>
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %edx,%edi
mov    -0x8(%rbp),%rsi
call   1060 <push@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <print_stack@plt>
mov    -0x8(%rbp),%rdi
call   1040 <pop@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <print_stack@plt>
mov    -0x8(%rbp),%rdi
call   1040 <pop@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <print_stack@plt>
mov    $0x0,%al
call   1070 <rand@plt>
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %edx,%edi
mov    -0x8(%rbp),%rsi
call   1060 <push@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <print_stack@plt>
mov    $0x0,%al
call   1070 <rand@plt>
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %edx,%edi
mov    -0x8(%rbp),%rsi
call   1060 <push@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <print_stack@plt>
mov    $0x0,%al
call   1070 <rand@plt>
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %edx,%edi
mov    -0x8(%rbp),%rsi
call   1060 <push@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <print_stack@plt>
mov    $0x0,%al
call   1070 <rand@plt>
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %edx,%edi
mov    -0x8(%rbp),%rsi
call   1060 <push@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <print_stack@plt>
mov    $0x0,%al
call   1070 <rand@plt>
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %edx,%edi
mov    -0x8(%rbp),%rsi
call   1060 <push@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <print_stack@plt>
mov    $0x0,%al
call   1070 <rand@plt>
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %edx,%edi
mov    -0x8(%rbp),%rsi
call   1060 <push@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <print_stack@plt>
mov    $0x0,%al
call   1070 <rand@plt>
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %edx,%edi
mov    -0x8(%rbp),%rsi
call   1060 <push@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <print_stack@plt>
mov    -0x8(%rbp),%rdi
call   1030 <get_top_val@plt>
mov    -0x8(%rbp),%rdi
call   1040 <pop@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <print_stack@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
xor    %eax,%eax
call   1070 <rand@plt>
movslq %eax,%rdi
imul   $0x66666667,%rdi,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x22,%rax
add    %ecx,%eax
add    %eax,%eax
lea    (%rax,%rax,4),%eax
sub    %eax,%edi
xor    %esi,%esi
call   1060 <push@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1050 <print_stack@plt>
mov    %rbx,%rdi
call   1040 <pop@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1050 <print_stack@plt>
mov    %rbx,%rdi
call   1040 <pop@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1050 <print_stack@plt>
xor    %eax,%eax
call   1070 <rand@plt>
movslq %eax,%rdi
imul   $0x66666667,%rdi,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x22,%rax
add    %ecx,%eax
add    %eax,%eax
lea    (%rax,%rax,4),%eax
sub    %eax,%edi
mov    %rbx,%rsi
call   1060 <push@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1050 <print_stack@plt>
xor    %eax,%eax
call   1070 <rand@plt>
movslq %eax,%rdi
imul   $0x66666667,%rdi,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x22,%rax
add    %ecx,%eax
add    %eax,%eax
lea    (%rax,%rax,4),%eax
sub    %eax,%edi
mov    %rbx,%rsi
call   1060 <push@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1050 <print_stack@plt>
xor    %eax,%eax
call   1070 <rand@plt>
movslq %eax,%rdi
imul   $0x66666667,%rdi,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x22,%rax
add    %ecx,%eax
add    %eax,%eax
lea    (%rax,%rax,4),%eax
sub    %eax,%edi
mov    %rbx,%rsi
call   1060 <push@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1050 <print_stack@plt>
xor    %eax,%eax
call   1070 <rand@plt>
movslq %eax,%rdi
imul   $0x66666667,%rdi,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x22,%rax
add    %ecx,%eax
add    %eax,%eax
lea    (%rax,%rax,4),%eax
sub    %eax,%edi
mov    %rbx,%rsi
call   1060 <push@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1050 <print_stack@plt>
xor    %eax,%eax
call   1070 <rand@plt>
movslq %eax,%rdi
imul   $0x66666667,%rdi,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x22,%rax
add    %ecx,%eax
add    %eax,%eax
lea    (%rax,%rax,4),%eax
sub    %eax,%edi
mov    %rbx,%rsi
call   1060 <push@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1050 <print_stack@plt>
xor    %eax,%eax
call   1070 <rand@plt>
movslq %eax,%rdi
imul   $0x66666667,%rdi,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x22,%rax
add    %ecx,%eax
add    %eax,%eax
lea    (%rax,%rax,4),%eax
sub    %eax,%edi
mov    %rbx,%rsi
call   1060 <push@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1050 <print_stack@plt>
xor    %eax,%eax
call   1070 <rand@plt>
movslq %eax,%rdi
imul   $0x66666667,%rdi,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x22,%rax
add    %ecx,%eax
add    %eax,%eax
lea    (%rax,%rax,4),%eax
sub    %eax,%edi
mov    %rbx,%rsi
call   1060 <push@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1050 <print_stack@plt>
mov    %rbx,%rdi
call   1030 <get_top_val@plt>
mov    %rbx,%rdi
call   1040 <pop@plt>
mov    %rax,%rdi
call   1050 <print_stack@plt>
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
%struct.stack = type { i32 }
define i32 @main() {
%1 = alloca %struct.stack*
store %struct.stack* null, %struct.stack** %1
%2 = call i32 (...) @rand()
%3 = srem i32 %2, 10
%4 = load %struct.stack*, %struct.stack** %1
%5 = call %struct.stack* @push(i32 %3, %struct.stack* %4)
store %struct.stack* %5, %struct.stack** %1
%6 = load %struct.stack*, %struct.stack** %1
%7 = call i32 @print_stack(%struct.stack* %6)
%8 = load %struct.stack*, %struct.stack** %1
%9 = call %struct.stack* @pop(%struct.stack* %8)
store %struct.stack* %9, %struct.stack** %1
%10 = load %struct.stack*, %struct.stack** %1
%11 = call i32 @print_stack(%struct.stack* %10)
%12 = load %struct.stack*, %struct.stack** %1
%13 = call %struct.stack* @pop(%struct.stack* %12)
store %struct.stack* %13, %struct.stack** %1
%14 = load %struct.stack*, %struct.stack** %1
%15 = call i32 @print_stack(%struct.stack* %14)
%16 = call i32 (...) @rand()
%17 = srem i32 %16, 10
%18 = load %struct.stack*, %struct.stack** %1
%19 = call %struct.stack* @push(i32 %17, %struct.stack* %18)
store %struct.stack* %19, %struct.stack** %1
%20 = load %struct.stack*, %struct.stack** %1
%21 = call i32 @print_stack(%struct.stack* %20)
%22 = call i32 (...) @rand()
%23 = srem i32 %22, 10
%24 = load %struct.stack*, %struct.stack** %1
%25 = call %struct.stack* @push(i32 %23, %struct.stack* %24)
store %struct.stack* %25, %struct.stack** %1
%26 = load %struct.stack*, %struct.stack** %1
%27 = call i32 @print_stack(%struct.stack* %26)
%28 = call i32 (...) @rand()
%29 = srem i32 %28, 10
%30 = load %struct.stack*, %struct.stack** %1
%31 = call %struct.stack* @push(i32 %29, %struct.stack* %30)
store %struct.stack* %31, %struct.stack** %1
%32 = load %struct.stack*, %struct.stack** %1
%33 = call i32 @print_stack(%struct.stack* %32)
%34 = call i32 (...) @rand()
%35 = srem i32 %34, 10
%36 = load %struct.stack*, %struct.stack** %1
%37 = call %struct.stack* @push(i32 %35, %struct.stack* %36)
store %struct.stack* %37, %struct.stack** %1
%38 = load %struct.stack*, %struct.stack** %1
%39 = call i32 @print_stack(%struct.stack* %38)
%40 = call i32 (...) @rand()
%41 = srem i32 %40, 10
%42 = load %struct.stack*, %struct.stack** %1
%43 = call %struct.stack* @push(i32 %41, %struct.stack* %42)
store %struct.stack* %43, %struct.stack** %1
%44 = load %struct.stack*, %struct.stack** %1
%45 = call i32 @print_stack(%struct.stack* %44)
%46 = call i32 (...) @rand()
%47 = srem i32 %46, 10
%48 = load %struct.stack*, %struct.stack** %1
%49 = call %struct.stack* @push(i32 %47, %struct.stack* %48)
store %struct.stack* %49, %struct.stack** %1
%50 = load %struct.stack*, %struct.stack** %1
%51 = call i32 @print_stack(%struct.stack* %50)
%52 = call i32 (...) @rand()
%53 = srem i32 %52, 10
%54 = load %struct.stack*, %struct.stack** %1
%55 = call %struct.stack* @push(i32 %53, %struct.stack* %54)
store %struct.stack* %55, %struct.stack** %1
%56 = load %struct.stack*, %struct.stack** %1
%57 = call i32 @print_stack(%struct.stack* %56)
%58 = load %struct.stack*, %struct.stack** %1
%59 = call i32 @get_top_val(%struct.stack* %58)
%60 = load %struct.stack*, %struct.stack** %1
%61 = call %struct.stack* @pop(%struct.stack* %60)
store %struct.stack* %61, %struct.stack** %1
%62 = load %struct.stack*, %struct.stack** %1
%63 = call i32 @print_stack(%struct.stack* %62)
ret i32 0
}

LLVM IR (-O2):
%struct.stack = type { i32 }
define i32 @main() {
%1 = tail call i32 (...) @rand()
%2 = srem i32 %1, 10
%3 = tail call %struct.stack* @push(i32 %2, %struct.stack* null)
%4 = tail call i32 @print_stack(%struct.stack* %3)
%5 = tail call %struct.stack* @pop(%struct.stack* %3)
%6 = tail call i32 @print_stack(%struct.stack* %5)
%7 = tail call %struct.stack* @pop(%struct.stack* %5)
%8 = tail call i32 @print_stack(%struct.stack* %7)
%9 = tail call i32 (...) @rand()
%10 = srem i32 %9, 10
%11 = tail call %struct.stack* @push(i32 %10, %struct.stack* %7)
%12 = tail call i32 @print_stack(%struct.stack* %11)
%13 = tail call i32 (...) @rand()
%14 = srem i32 %13, 10
%15 = tail call %struct.stack* @push(i32 %14, %struct.stack* %11)
%16 = tail call i32 @print_stack(%struct.stack* %15)
%17 = tail call i32 (...) @rand()
%18 = srem i32 %17, 10
%19 = tail call %struct.stack* @push(i32 %18, %struct.stack* %15)
%20 = tail call i32 @print_stack(%struct.stack* %19)
%21 = tail call i32 (...) @rand()
%22 = srem i32 %21, 10
%23 = tail call %struct.stack* @push(i32 %22, %struct.stack* %19)
%24 = tail call i32 @print_stack(%struct.stack* %23)
%25 = tail call i32 (...) @rand()
%26 = srem i32 %25, 10
%27 = tail call %struct.stack* @push(i32 %26, %struct.stack* %23)
%28 = tail call i32 @print_stack(%struct.stack* %27)
%29 = tail call i32 (...) @rand()
%30 = srem i32 %29, 10
%31 = tail call %struct.stack* @push(i32 %30, %struct.stack* %27)
%32 = tail call i32 @print_stack(%struct.stack* %31)
%33 = tail call i32 (...) @rand()
%34 = srem i32 %33, 10
%35 = tail call %struct.stack* @push(i32 %34, %struct.stack* %31)
%36 = tail call i32 @print_stack(%struct.stack* %35)
%37 = tail call i32 @get_top_val(%struct.stack* %35)
%38 = tail call %struct.stack* @pop(%struct.stack* %35)
%39 = tail call i32 @print_stack(%struct.stack* %38)
ret i32 0
}