#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 bubble_duplicates(int *, int);
int hist_duplicates(int *, int);
int /*<<< orphan*/ printf(char *, ...);
int rand();
int /*<<< orphan*/ system(char *);
int main(int argc, char **argv) {
  static int values[500000];
  for (int i = 0; i < 500000; ++i)
    values[i] = rand();
  printf("Histogram Duplicates: ");
  int duplicates1 = hist_duplicates(values, 500000);
  printf("%d / %d (%.2g%%)\n", duplicates1, 500000,
         100.f * duplicates1 / 500000);
  printf("Bubble Duplicates:    ");
  int duplicates2 = bubble_duplicates(values, 500000);
  printf("%d / %d (%.2g%%)\n", duplicates2, 500000,
         100.f * duplicates2 / 500000);
  system("pause");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
cmpl   $0x7a120,-0x14(%rbp)
jge    119f <main+0x4f>
mov    $0x0,%al
call   1070 <rand@plt>
mov    %eax,%edx
movslq -0x14(%rbp),%rcx
lea    0x2ed2(%rip),%rax
mov    %edx,(%rax,%rcx,4)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    116d <main+0x1d>
lea    0xe62(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0x2eac(%rip),%rdi
mov    $0x7a120,%esi
call   1060 <hist_duplicates@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%esi
cvtsi2ssl -0x18(%rbp),%xmm1
movss  0xe33(%rip),%xmm0
mulss  %xmm1,%xmm0
movss  0xe23(%rip),%xmm1
divss  %xmm1,%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xe33(%rip),%rdi
mov    $0x7a120,%edx
mov    $0x1,%al
call   1040 <printf@plt>
lea    0xe32(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0x2e53(%rip),%rdi
mov    $0x7a120,%esi
call   1050 <bubble_duplicates@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%esi
cvtsi2ssl -0x1c(%rbp),%xmm1
movss  0xdda(%rip),%xmm0
mulss  %xmm1,%xmm0
movss  0xdca(%rip),%xmm1
divss  %xmm1,%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xdda(%rip),%rdi
mov    $0x7a120,%edx
mov    $0x1,%al
call   1040 <printf@plt>
lea    0xdf0(%rip),%rdi
call   1030 <system@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
lea    0x2f05(%rip),%r14
xor    %ebx,%ebx
nopl   (%rax)
xor    %eax,%eax
call   1070 <rand@plt>
mov    %eax,(%rbx,%r14,1)
add    $0x4,%rbx
cmp    $0x1e8480,%rbx
jne    1160 <main+0x10>
lea    0xe89(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0x2ed3(%rip),%r14
mov    %r14,%rdi
mov    $0x7a120,%esi
call   1060 <hist_duplicates@plt>
cvtsi2ss %eax,%xmm0
mulss  0xe5a(%rip),%xmm0
divss  0xe56(%rip),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xe66(%rip),%rbx
mov    %rbx,%rdi
mov    %eax,%esi
mov    $0x7a120,%edx
mov    $0x1,%al
call   1040 <printf@plt>
lea    0xe60(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r14,%rdi
mov    $0x7a120,%esi
call   1050 <bubble_duplicates@plt>
xorps  %xmm0,%xmm0
cvtsi2ss %eax,%xmm0
mulss  0xe0c(%rip),%xmm0
divss  0xe08(%rip),%xmm0
cvtss2sd %xmm0,%xmm0
mov    %rbx,%rdi
mov    %eax,%esi
mov    $0x7a120,%edx
mov    $0x1,%al
call   1040 <printf@plt>
lea    0xe30(%rip),%rdi
call   1030 <system@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@main.values = internal global [500000 x i32] zeroinitializer
@.str = [23 x i8] c"Histogram Duplicates: \00"
@.str.1 = [18 x i8] c"%d / %d (%.2g%%)\0A\00"
@.str.2 = [23 x i8] c"Bubble Duplicates: \00"
@.str.3 = [6 x i8] c"pause\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %6
br label %9
9: ; preds = %17, %2
%10 = load i32, i32* %6
%11 = icmp slt i32 %10, 500000
br i1 %11, label %12, label %20
12: ; preds = %9
%13 = call i32 (...) @rand()
%14 = load i32, i32* %6
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds [500000 x i32], [500000 x i32]* @main.values, i64 0, i64 %15
store i32 %13, i32* %16
br label %17
17: ; preds = %12
%18 = load i32, i32* %6
%19 = add nsw i32 %18, 1
store i32 %19, i32* %6
br label %9
20: ; preds = %9
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
%22 = call i32 @hist_duplicates(i32* getelementptr inbounds ([500000 x i32], [500000 x i32]* @main.values, i64 0, i64 0), i32 500000)
store i32 %22, i32* %7
%23 = load i32, i32* %7
%24 = load i32, i32* %7
%25 = sitofp i32 %24 to float
%26 = fmul float 1.000000e+02, %25
%27 = fdiv float %26, 5.000000e+05
%28 = fpext float %27 to double
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i32 %23, i32 500000, double %28)
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0))
%31 = call i32 @bubble_duplicates(i32* getelementptr inbounds ([500000 x i32], [500000 x i32]* @main.values, i64 0, i64 0), i32 500000)
store i32 %31, i32* %8
%32 = load i32, i32* %8
%33 = load i32, i32* %8
%34 = sitofp i32 %33 to float
%35 = fmul float 1.000000e+02, %34
%36 = fdiv float %35, 5.000000e+05
%37 = fpext float %36 to double
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i32 %32, i32 500000, double %37)
%39 = call i32 @system(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@main.values = internal global [500000 x i32] zeroinitializer
@.str = [23 x i8] c"Histogram Duplicates: \00"
@.str.1 = [18 x i8] c"%d / %d (%.2g%%)\0A\00"
@.str.2 = [23 x i8] c"Bubble Duplicates: \00"
@.str.3 = [6 x i8] c"pause\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
br label %19
3: ; preds = %19
%4 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
%5 = tail call i32 @hist_duplicates(i32* getelementptr inbounds ([500000 x i32], [500000 x i32]* @main.values, i64 0, i64 0), i32 500000)
%6 = sitofp i32 %5 to float
%7 = fmul float %6, 1.000000e+02
%8 = fdiv float %7, 5.000000e+05
%9 = fpext float %8 to double
%10 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i32 %5, i32 500000, double %9)
%11 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0))
%12 = tail call i32 @bubble_duplicates(i32* getelementptr inbounds ([500000 x i32], [500000 x i32]* @main.values, i64 0, i64 0), i32 500000)
%13 = sitofp i32 %12 to float
%14 = fmul float %13, 1.000000e+02
%15 = fdiv float %14, 5.000000e+05
%16 = fpext float %15 to double
%17 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i32 %12, i32 500000, double %16)
%18 = tail call i32 @system(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
ret i32 0
19: ; preds = %2, %19
%20 = phi i64 [ 0, %2 ], [ %23, %19 ]
%21 = tail call i32 (...) @rand()
%22 = getelementptr inbounds [500000 x i32], [500000 x i32]* @main.values, i64 0, i64 %20
store i32 %21, i32* %22
%23 = add nuw nsw i64 %20, 1
%24 = icmp eq i64 %23, 500000
br i1 %24, label %3, label %19
}