#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*/ CloseVarPool();
int /*<<< orphan*/ DumpVarPool();
int /*<<< orphan*/ FindVar(int);
int /*<<< orphan*/ InitVarPool();
int /*<<< orphan*/ SortVarPool();
int /*<<< orphan*/ printf(char *, ...);
int rand();
void TestVarPool() {
  int n, v;
  InitVarPool();
  for (n = 0; n < 20; n++) {
    v = rand() & 7;
    FindVar(v);
    printf("inserted %d\n", v);
  }
  DumpVarPool();
  printf("\nSorted");
  SortVarPool();
  DumpVarPool();
  CloseVarPool();
}


x86 assembly (clang, -O0):
<TestVarPool>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    $0x0,%al
call   1080 <InitVarPool@plt>
movl   $0x0,-0x4(%rbp)
cmpl   $0x14,-0x4(%rbp)
jge    11c4 <TestVarPool+0x54>
mov    $0x0,%al
call   1090 <rand@plt>
and    $0x7,%eax
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%edi
call   1030 <FindVar@plt>
mov    -0x8(%rbp),%esi
lea    0xe51(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    1186 <TestVarPool+0x16>
mov    $0x0,%al
call   1050 <DumpVarPool@plt>
lea    0xe3b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x0,%al
call   1060 <SortVarPool@plt>
mov    $0x0,%al
call   1050 <DumpVarPool@plt>
mov    $0x0,%al
call   1070 <CloseVarPool@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<TestVarPool>:
push   %rbp
push   %rbx
push   %rax
xor    %eax,%eax
call   1080 <InitVarPool@plt>
xor    %eax,%eax
call   1090 <rand@plt>
mov    %eax,%ebp
and    $0x7,%ebp
mov    %ebp,%edi
call   1030 <FindVar@plt>
lea    0xe6c(%rip),%rbx
mov    %rbx,%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
call   1090 <rand@plt>
mov    %eax,%ebp
and    $0x7,%ebp
mov    %ebp,%edi
call   1030 <FindVar@plt>
mov    %rbx,%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
call   1090 <rand@plt>
mov    %eax,%ebp
and    $0x7,%ebp
mov    %ebp,%edi
call   1030 <FindVar@plt>
mov    %rbx,%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
call   1090 <rand@plt>
mov    %eax,%ebp
and    $0x7,%ebp
mov    %ebp,%edi
call   1030 <FindVar@plt>
mov    %rbx,%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
call   1090 <rand@plt>
mov    %eax,%ebp
and    $0x7,%ebp
mov    %ebp,%edi
call   1030 <FindVar@plt>
mov    %rbx,%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
call   1090 <rand@plt>
mov    %eax,%ebp
and    $0x7,%ebp
mov    %ebp,%edi
call   1030 <FindVar@plt>
mov    %rbx,%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
call   1090 <rand@plt>
mov    %eax,%ebp
and    $0x7,%ebp
mov    %ebp,%edi
call   1030 <FindVar@plt>
mov    %rbx,%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
call   1090 <rand@plt>
mov    %eax,%ebp
and    $0x7,%ebp
mov    %ebp,%edi
call   1030 <FindVar@plt>
mov    %rbx,%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
call   1090 <rand@plt>
mov    %eax,%ebp
and    $0x7,%ebp
mov    %ebp,%edi
call   1030 <FindVar@plt>
mov    %rbx,%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
call   1090 <rand@plt>
mov    %eax,%ebp
and    $0x7,%ebp
mov    %ebp,%edi
call   1030 <FindVar@plt>
mov    %rbx,%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
call   1090 <rand@plt>
mov    %eax,%ebp
and    $0x7,%ebp
mov    %ebp,%edi
call   1030 <FindVar@plt>
mov    %rbx,%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
call   1090 <rand@plt>
mov    %eax,%ebp
and    $0x7,%ebp
mov    %ebp,%edi
call   1030 <FindVar@plt>
mov    %rbx,%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
call   1090 <rand@plt>
mov    %eax,%ebp
and    $0x7,%ebp
mov    %ebp,%edi
call   1030 <FindVar@plt>
mov    %rbx,%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
call   1090 <rand@plt>
mov    %eax,%ebp
and    $0x7,%ebp
mov    %ebp,%edi
call   1030 <FindVar@plt>
mov    %rbx,%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
call   1090 <rand@plt>
mov    %eax,%ebp
and    $0x7,%ebp
mov    %ebp,%edi
call   1030 <FindVar@plt>
mov    %rbx,%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
call   1090 <rand@plt>
mov    %eax,%ebp
and    $0x7,%ebp
mov    %ebp,%edi
call   1030 <FindVar@plt>
mov    %rbx,%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
call   1090 <rand@plt>
mov    %eax,%ebp
and    $0x7,%ebp
mov    %ebp,%edi
call   1030 <FindVar@plt>
mov    %rbx,%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
call   1090 <rand@plt>
mov    %eax,%ebp
and    $0x7,%ebp
mov    %ebp,%edi
call   1030 <FindVar@plt>
mov    %rbx,%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
call   1090 <rand@plt>
mov    %eax,%ebp
and    $0x7,%ebp
mov    %ebp,%edi
call   1030 <FindVar@plt>
mov    %rbx,%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
call   1090 <rand@plt>
mov    %eax,%ebp
and    $0x7,%ebp
mov    %ebp,%edi
call   1030 <FindVar@plt>
mov    %rbx,%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
call   1050 <DumpVarPool@plt>
lea    0xc12(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
call   1060 <SortVarPool@plt>
xor    %eax,%eax
call   1050 <DumpVarPool@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1070 <CloseVarPool@plt>

LLVM IR (-O0):
@.str = [13 x i8] c"inserted %d\0A\00"
@.str.1 = [8 x i8] c"\0ASorted\00"
define void @TestVarPool() {
%1 = alloca i32
%2 = alloca i32
%3 = call i32 (...) @InitVarPool()
store i32 0, i32* %1
br label %4
4: ; preds = %14, %0
%5 = load i32, i32* %1
%6 = icmp slt i32 %5, 20
br i1 %6, label %7, label %17
7: ; preds = %4
%8 = call i32 (...) @rand()
%9 = and i32 %8, 7
store i32 %9, i32* %2
%10 = load i32, i32* %2
%11 = call i32 @FindVar(i32 %10)
%12 = load i32, i32* %2
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %12)
br label %14
14: ; preds = %7
%15 = load i32, i32* %1
%16 = add nsw i32 %15, 1
store i32 %16, i32* %1
br label %4
17: ; preds = %4
%18 = call i32 (...) @DumpVarPool()
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%20 = call i32 (...) @SortVarPool()
%21 = call i32 (...) @DumpVarPool()
%22 = call i32 (...) @CloseVarPool()
ret void
}

LLVM IR (-O2):
@.str = [13 x i8] c"inserted %d\0A\00"
@.str.1 = [8 x i8] c"\0ASorted\00"
define void @TestVarPool() {
%1 = tail call i32 (...) @InitVarPool()
%2 = tail call i32 (...) @rand()
%3 = and i32 %2, 7
%4 = tail call i32 @FindVar(i32 %3)
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %3)
%6 = tail call i32 (...) @rand()
%7 = and i32 %6, 7
%8 = tail call i32 @FindVar(i32 %7)
%9 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %7)
%10 = tail call i32 (...) @rand()
%11 = and i32 %10, 7
%12 = tail call i32 @FindVar(i32 %11)
%13 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %11)
%14 = tail call i32 (...) @rand()
%15 = and i32 %14, 7
%16 = tail call i32 @FindVar(i32 %15)
%17 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %15)
%18 = tail call i32 (...) @rand()
%19 = and i32 %18, 7
%20 = tail call i32 @FindVar(i32 %19)
%21 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %19)
%22 = tail call i32 (...) @rand()
%23 = and i32 %22, 7
%24 = tail call i32 @FindVar(i32 %23)
%25 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %23)
%26 = tail call i32 (...) @rand()
%27 = and i32 %26, 7
%28 = tail call i32 @FindVar(i32 %27)
%29 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %27)
%30 = tail call i32 (...) @rand()
%31 = and i32 %30, 7
%32 = tail call i32 @FindVar(i32 %31)
%33 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %31)
%34 = tail call i32 (...) @rand()
%35 = and i32 %34, 7
%36 = tail call i32 @FindVar(i32 %35)
%37 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %35)
%38 = tail call i32 (...) @rand()
%39 = and i32 %38, 7
%40 = tail call i32 @FindVar(i32 %39)
%41 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %39)
%42 = tail call i32 (...) @rand()
%43 = and i32 %42, 7
%44 = tail call i32 @FindVar(i32 %43)
%45 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %43)
%46 = tail call i32 (...) @rand()
%47 = and i32 %46, 7
%48 = tail call i32 @FindVar(i32 %47)
%49 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %47)
%50 = tail call i32 (...) @rand()
%51 = and i32 %50, 7
%52 = tail call i32 @FindVar(i32 %51)
%53 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %51)
%54 = tail call i32 (...) @rand()
%55 = and i32 %54, 7
%56 = tail call i32 @FindVar(i32 %55)
%57 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %55)
%58 = tail call i32 (...) @rand()
%59 = and i32 %58, 7
%60 = tail call i32 @FindVar(i32 %59)
%61 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %59)
%62 = tail call i32 (...) @rand()
%63 = and i32 %62, 7
%64 = tail call i32 @FindVar(i32 %63)
%65 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %63)
%66 = tail call i32 (...) @rand()
%67 = and i32 %66, 7
%68 = tail call i32 @FindVar(i32 %67)
%69 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %67)
%70 = tail call i32 (...) @rand()
%71 = and i32 %70, 7
%72 = tail call i32 @FindVar(i32 %71)
%73 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %71)
%74 = tail call i32 (...) @rand()
%75 = and i32 %74, 7
%76 = tail call i32 @FindVar(i32 %75)
%77 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %75)
%78 = tail call i32 (...) @rand()
%79 = and i32 %78, 7
%80 = tail call i32 @FindVar(i32 %79)
%81 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %79)
%82 = tail call i32 (...) @DumpVarPool()
%83 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%84 = tail call i32 (...) @SortVarPool()
%85 = tail call i32 (...) @DumpVarPool()
%86 = tail call i32 (...) @CloseVarPool()
ret void
}