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

/* Variables and functions */
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
struct sg_tree *sg_create_tree(double);
int /*<<< orphan*/ sg_insert(struct sg_tree *, unsigned int);
int /*<<< orphan*/ stdin;
int main(void) {
  struct sg_tree *sg_tree;
  unsigned int i;
  char d[2];
  printf("=== BENCHMARK SG MEM - START ===\n");
  printf("BENCHMARK SG MEM - Inserting %dM keys into scapegoat tree\n", 10);
  sg_tree = sg_create_tree(0.55);
  for (i = 0; i < 10 * 1000 * 1000; i++) {
    sg_insert(sg_tree, i);
  }
  printf("BENCHMARK SG MEM - Insertions done, measure memory usage then press "
         "any key to exit\n");
  fgets(d, 2, stdin);
  printf("=== BENCHMARK SG MEM - END ===\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeb2(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xec6(%rip),%rdi
mov    $0xa,%esi
mov    $0x0,%al
call   1040 <printf@plt>
movsd  0xe88(%rip),%xmm0
call   1060 <sg_create_tree@plt>
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
cmpl   $0x989680,-0x14(%rbp)
jae    11af <main+0x6f>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1030 <sg_insert@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1188 <main+0x48>
lea    0xeaf(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x16(%rbp),%rdi
mov    0x2e20(%rip),%rax
mov    (%rax),%edx
mov    $0x2,%esi
call   1050 <fgets@plt>
lea    0xedf(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
lea    0xee8(%rip),%rdi
call   1030 <puts@plt>
lea    0xea1(%rip),%rdi
xor    %ebx,%ebx
mov    $0xa,%esi
xor    %eax,%eax
call   1050 <printf@plt>
movsd  0xe83(%rip),%xmm0
call   1070 <sg_create_tree@plt>
mov    %rax,%r14
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r14,%rdi
mov    %ebx,%esi
call   1040 <sg_insert@plt>
add    $0x1,%ebx
cmp    $0x989680,%ebx
jne    1190 <main+0x40>
lea    0xeb8(%rip),%rdi
call   1030 <puts@plt>
mov    0x2e30(%rip),%rax
mov    (%rax),%edx
lea    0x6(%rsp),%rdi
mov    $0x2,%esi
call   1060 <fgets@plt>
lea    0xee8(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.sg_tree = type { i32 }
@.str = [34 x i8] c"=== BENCHMARK SG MEM - START ===\0A\00"
@.str.1 = [59 x i8] c"BENCHMARK SG MEM - Inserting %dM keys into scapegoat tree\0A\00"
@.str.2 = [85 x i8] c"BENCHMARK SG MEM - Insertions done, measure memory usage then press any key to exit\0A\00"
@stdin = global i32 0
@.str.3 = [32 x i8] c"=== BENCHMARK SG MEM - END ===\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca %struct.sg_tree*
%3 = alloca i32
%4 = alloca [2 x i8]
store i32 0, i32* %1
%5 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0))
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str.1, i64 0, i64 0), i32 10)
%7 = call %struct.sg_tree* @sg_create_tree(double 5.500000e-01)
store %struct.sg_tree* %7, %struct.sg_tree** %2
store i32 0, i32* %3
br label %8
8: ; preds = %15, %0
%9 = load i32, i32* %3
%10 = icmp ult i32 %9, 10000000
br i1 %10, label %11, label %18
11: ; preds = %8
%12 = load %struct.sg_tree*, %struct.sg_tree** %2
%13 = load i32, i32* %3
%14 = call i32 @sg_insert(%struct.sg_tree* %12, i32 %13)
br label %15
15: ; preds = %11
%16 = load i32, i32* %3
%17 = add i32 %16, 1
store i32 %17, i32* %3
br label %8
18: ; preds = %8
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([85 x i8], [85 x i8]* @.str.2, i64 0, i64 0))
%20 = getelementptr inbounds [2 x i8], [2 x i8]* %4, i64 0, i64 0
%21 = load i32, i32* @stdin
%22 = call i32 @fgets(i8* %20, i32 2, i32 %21)
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.3, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
%struct.sg_tree = type { i32 }
@.str.1 = [59 x i8] c"BENCHMARK SG MEM - Inserting %dM keys into scapegoat tree\0A\00"
@stdin = global i32 0
@str = [33 x i8] c"=== BENCHMARK SG MEM - START ===\00"
@str.4 = [84 x i8] c"BENCHMARK SG MEM - Insertions done, measure memory usage then press any key to exit\00"
@str.5 = [31 x i8] c"=== BENCHMARK SG MEM - END ===\00"
define i32 @main() {
%1 = alloca [2 x i8]
%2 = getelementptr inbounds [2 x i8], [2 x i8]* %1, i64 0, i64 0
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @str, i64 0, i64 0))
%4 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([59 x i8], [59 x i8]* @.str.1, i64 0, i64 0), i32 10)
%5 = tail call %struct.sg_tree* @sg_create_tree(double 5.500000e-01)
br label %6
6: ; preds = %0, %6
%7 = phi i32 [ 0, %0 ], [ %9, %6 ]
%8 = tail call i32 @sg_insert(%struct.sg_tree* %5, i32 %7)
%9 = add nuw nsw i32 %7, 1
%10 = icmp eq i32 %9, 10000000
br i1 %10, label %11, label %6
11: ; preds = %6
%12 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([84 x i8], [84 x i8]* @str.4, i64 0, i64 0))
%13 = load i32, i32* @stdin
%14 = call i32 @fgets(i8* %2, i32 2, i32 %13)
%15 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @str.5, i64 0, i64 0))
ret i32 0
}