#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 *, ...);
int rand();
int /*<<< orphan*/ stackDisplay();
int /*<<< orphan*/ stackEmpty();
int /*<<< orphan*/ stackInit(int);
int stackPop();
int /*<<< orphan*/ stackPush(int);
int main(void) {
  int i, item;
  stackInit(100);
  for (i = 0; i < 10; i++) {
    stackPush(rand() % 100);
    printf("\n");
  }
  printf("\n");
  printf("Initial Contents: ");
  stackDisplay();
  for (i = 0; i < 5; i++) {
    if (!stackEmpty()) {
      item = stackPop();
      printf("%d popped from stack. ", item);
      printf("\n");
    }
  }
  printf("\n");
  printf("Contents after popping off 5 items: ");
  stackDisplay();
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x64,%edi
call   1060 <stackInit@plt>
movl   $0x0,-0x8(%rbp)
cmpl   $0xa,-0x8(%rbp)
jge    11cc <main+0x5c>
mov    $0x0,%al
call   1080 <rand@plt>
mov    $0x64,%ecx
cltd
idiv   %ecx
mov    %edx,%edi
call   1090 <stackPush@plt>
lea    0xe49(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1190 <main+0x20>
lea    0xe2d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe21(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x0,%al
call   1050 <stackDisplay@plt>
movl   $0x0,-0x8(%rbp)
cmpl   $0x5,-0x8(%rbp)
jge    124c <main+0xdc>
mov    $0x0,%al
call   1040 <stackEmpty@plt>
cmp    $0x0,%eax
jne    1239 <main+0xc9>
mov    $0x0,%al
call   1070 <stackPop@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%esi
lea    0xdf1(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xdce(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    123e <main+0xce>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    11f6 <main+0x86>
lea    0xdad(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xdcb(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x0,%al
call   1050 <stackDisplay@plt>
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
mov    $0x64,%edi
call   1070 <stackInit@plt>
xor    %eax,%eax
call   1090 <rand@plt>
movslq %eax,%rdi
imul   $0x51eb851f,%rdi,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x25,%rax
add    %ecx,%eax
imul   $0x64,%eax,%eax
sub    %eax,%edi
call   10a0 <stackPush@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
call   1090 <rand@plt>
movslq %eax,%rdi
imul   $0x51eb851f,%rdi,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x25,%rax
add    %ecx,%eax
imul   $0x64,%eax,%eax
sub    %eax,%edi
call   10a0 <stackPush@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
call   1090 <rand@plt>
movslq %eax,%rdi
imul   $0x51eb851f,%rdi,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x25,%rax
add    %ecx,%eax
imul   $0x64,%eax,%eax
sub    %eax,%edi
call   10a0 <stackPush@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
call   1090 <rand@plt>
movslq %eax,%rdi
imul   $0x51eb851f,%rdi,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x25,%rax
add    %ecx,%eax
imul   $0x64,%eax,%eax
sub    %eax,%edi
call   10a0 <stackPush@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
call   1090 <rand@plt>
movslq %eax,%rdi
imul   $0x51eb851f,%rdi,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x25,%rax
add    %ecx,%eax
imul   $0x64,%eax,%eax
sub    %eax,%edi
call   10a0 <stackPush@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
call   1090 <rand@plt>
movslq %eax,%rdi
imul   $0x51eb851f,%rdi,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x25,%rax
add    %ecx,%eax
imul   $0x64,%eax,%eax
sub    %eax,%edi
call   10a0 <stackPush@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
call   1090 <rand@plt>
movslq %eax,%rdi
imul   $0x51eb851f,%rdi,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x25,%rax
add    %ecx,%eax
imul   $0x64,%eax,%eax
sub    %eax,%edi
call   10a0 <stackPush@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
call   1090 <rand@plt>
movslq %eax,%rdi
imul   $0x51eb851f,%rdi,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x25,%rax
add    %ecx,%eax
imul   $0x64,%eax,%eax
sub    %eax,%edi
call   10a0 <stackPush@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
call   1090 <rand@plt>
movslq %eax,%rdi
imul   $0x51eb851f,%rdi,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x25,%rax
add    %ecx,%eax
imul   $0x64,%eax,%eax
sub    %eax,%edi
call   10a0 <stackPush@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
call   1090 <rand@plt>
movslq %eax,%rdi
imul   $0x51eb851f,%rdi,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x25,%rax
add    %ecx,%eax
imul   $0x64,%eax,%eax
sub    %eax,%edi
call   10a0 <stackPush@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
lea    0xc70(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
call   1060 <stackDisplay@plt>
xor    %eax,%eax
call   1050 <stackEmpty@plt>
test   %eax,%eax
jne    13ca <main+0x24a>
xor    %eax,%eax
call   1080 <stackPop@plt>
lea    0xc5c(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
call   1050 <stackEmpty@plt>
test   %eax,%eax
jne    13f6 <main+0x276>
xor    %eax,%eax
call   1080 <stackPop@plt>
lea    0xc30(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
call   1050 <stackEmpty@plt>
test   %eax,%eax
jne    1422 <main+0x2a2>
xor    %eax,%eax
call   1080 <stackPop@plt>
lea    0xc04(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
call   1050 <stackEmpty@plt>
test   %eax,%eax
jne    144e <main+0x2ce>
xor    %eax,%eax
call   1080 <stackPop@plt>
lea    0xbd8(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
call   1050 <stackEmpty@plt>
test   %eax,%eax
jne    147a <main+0x2fa>
xor    %eax,%eax
call   1080 <stackPop@plt>
lea    0xbac(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
lea    0xb9f(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
call   1060 <stackDisplay@plt>
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
@.str = [2 x i8] c"\0A\00"
@.str.1 = [19 x i8] c"Initial Contents: \00"
@.str.2 = [23 x i8] c"%d popped from stack. \00"
@.str.3 = [37 x i8] c"Contents after popping off 5 items: \00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
store i32 0, i32* %1
%4 = call i32 @stackInit(i32 100)
store i32 0, i32* %2
br label %5
5: ; preds = %13, %0
%6 = load i32, i32* %2
%7 = icmp slt i32 %6, 10
br i1 %7, label %8, label %16
8: ; preds = %5
%9 = call i32 (...) @rand()
%10 = srem i32 %9, 100
%11 = call i32 @stackPush(i32 %10)
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
br label %13
13: ; preds = %8
%14 = load i32, i32* %2
%15 = add nsw i32 %14, 1
store i32 %15, i32* %2
br label %5
16: ; preds = %5
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
%19 = call i32 (...) @stackDisplay()
store i32 0, i32* %2
br label %20
20: ; preds = %32, %16
%21 = load i32, i32* %2
%22 = icmp slt i32 %21, 5
br i1 %22, label %23, label %35
23: ; preds = %20
%24 = call i32 (...) @stackEmpty()
%25 = icmp ne i32 %24, 0
br i1 %25, label %31, label %26
26: ; preds = %23
%27 = call i32 (...) @stackPop()
store i32 %27, i32* %3
%28 = load i32, i32* %3
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i32 %28)
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
br label %31
31: ; preds = %26, %23
br label %32
32: ; preds = %31
%33 = load i32, i32* %2
%34 = add nsw i32 %33, 1
store i32 %34, i32* %2
br label %20
35: ; preds = %20
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.3, i64 0, i64 0))
%38 = call i32 (...) @stackDisplay()
%39 = load i32, i32* %1
ret i32 %39
}

LLVM IR (-O2):
@.str.1 = [19 x i8] c"Initial Contents: \00"
@.str.2 = [23 x i8] c"%d popped from stack. \00"
@.str.3 = [37 x i8] c"Contents after popping off 5 items: \00"
define i32 @main() {
%1 = tail call i32 @stackInit(i32 100)
%2 = tail call i32 (...) @rand()
%3 = srem i32 %2, 100
%4 = tail call i32 @stackPush(i32 %3)
%5 = tail call i32 @putchar(i32 10)
%6 = tail call i32 (...) @rand()
%7 = srem i32 %6, 100
%8 = tail call i32 @stackPush(i32 %7)
%9 = tail call i32 @putchar(i32 10)
%10 = tail call i32 (...) @rand()
%11 = srem i32 %10, 100
%12 = tail call i32 @stackPush(i32 %11)
%13 = tail call i32 @putchar(i32 10)
%14 = tail call i32 (...) @rand()
%15 = srem i32 %14, 100
%16 = tail call i32 @stackPush(i32 %15)
%17 = tail call i32 @putchar(i32 10)
%18 = tail call i32 (...) @rand()
%19 = srem i32 %18, 100
%20 = tail call i32 @stackPush(i32 %19)
%21 = tail call i32 @putchar(i32 10)
%22 = tail call i32 (...) @rand()
%23 = srem i32 %22, 100
%24 = tail call i32 @stackPush(i32 %23)
%25 = tail call i32 @putchar(i32 10)
%26 = tail call i32 (...) @rand()
%27 = srem i32 %26, 100
%28 = tail call i32 @stackPush(i32 %27)
%29 = tail call i32 @putchar(i32 10)
%30 = tail call i32 (...) @rand()
%31 = srem i32 %30, 100
%32 = tail call i32 @stackPush(i32 %31)
%33 = tail call i32 @putchar(i32 10)
%34 = tail call i32 (...) @rand()
%35 = srem i32 %34, 100
%36 = tail call i32 @stackPush(i32 %35)
%37 = tail call i32 @putchar(i32 10)
%38 = tail call i32 (...) @rand()
%39 = srem i32 %38, 100
%40 = tail call i32 @stackPush(i32 %39)
%41 = tail call i32 @putchar(i32 10)
%42 = tail call i32 @putchar(i32 10)
%43 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
%44 = tail call i32 (...) @stackDisplay()
%45 = tail call i32 (...) @stackEmpty()
%46 = icmp eq i32 %45, 0
br i1 %46, label %47, label %51
47: ; preds = %0
%48 = tail call i32 (...) @stackPop()
%49 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i32 %48)
%50 = tail call i32 @putchar(i32 10)
br label %51
51: ; preds = %0, %47
%52 = tail call i32 (...) @stackEmpty()
%53 = icmp eq i32 %52, 0
br i1 %53, label %54, label %58
54: ; preds = %51
%55 = tail call i32 (...) @stackPop()
%56 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i32 %55)
%57 = tail call i32 @putchar(i32 10)
br label %58
58: ; preds = %54, %51
%59 = tail call i32 (...) @stackEmpty()
%60 = icmp eq i32 %59, 0
br i1 %60, label %61, label %65
61: ; preds = %58
%62 = tail call i32 (...) @stackPop()
%63 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i32 %62)
%64 = tail call i32 @putchar(i32 10)
br label %65
65: ; preds = %61, %58
%66 = tail call i32 (...) @stackEmpty()
%67 = icmp eq i32 %66, 0
br i1 %67, label %68, label %72
68: ; preds = %65
%69 = tail call i32 (...) @stackPop()
%70 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i32 %69)
%71 = tail call i32 @putchar(i32 10)
br label %72
72: ; preds = %68, %65
%73 = tail call i32 (...) @stackEmpty()
%74 = icmp eq i32 %73, 0
br i1 %74, label %75, label %79
75: ; preds = %72
%76 = tail call i32 (...) @stackPop()
%77 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i32 %76)
%78 = tail call i32 @putchar(i32 10)
br label %79
79: ; preds = %75, %72
%80 = tail call i32 @putchar(i32 10)
%81 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @.str.3, i64 0, i64 0))
%82 = tail call i32 (...) @stackDisplay()
ret i32 0
}