#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 gkc_summary {
  int dummy;
};
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, long);
struct gkc_summary *gkc_combine(struct gkc_summary *, struct gkc_summary *);
int /*<<< orphan*/ gkc_insert_value(struct gkc_summary *, long);
int /*<<< orphan*/ gkc_print_summary(struct gkc_summary *);
int /*<<< orphan*/ gkc_sanity_check(struct gkc_summary *);
struct gkc_summary *gkc_summary_alloc(double);
int /*<<< orphan*/ gkc_summary_free(struct gkc_summary *);
int /*<<< orphan*/ print_query(struct gkc_summary *, double);
int random();
int /*<<< orphan*/ srandom(int /*<<< orphan*/);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
int main(void) {
  unsigned int i;
  double input[] = {12, 6, 10, 1};
  FILE *out;
  struct gkc_summary *summary;
  struct gkc_summary *s1, *s2, *snew;
  summary = gkc_summary_alloc(0.01);
  print_query(summary, 0.1);
  goto test_combine;
  summary = gkc_summary_alloc(0.01);
  (void)input;
  if (0) {
    out = fopen("data", "w+");
  }
  srandom(time(NULL));
  for (i = 0; i < 10 * 1000 * 1000; i++) {
    long r = random() % 10000;
    gkc_insert_value(summary, r);
    if (0) {
      fprintf(out, "%ld\n", r);
    }
  }
  if (0) {
    fclose(out);
  }
  gkc_print_summary(summary);
  print_query(summary, .02);
  print_query(summary, .1);
  print_query(summary, .25);
  print_query(summary, .5);
  print_query(summary, .75);
  print_query(summary, .82);
  print_query(summary, .88);
  print_query(summary, .86);
  print_query(summary, .99);
  gkc_sanity_check(summary);
  gkc_summary_free(summary);
test_combine:
  s1 = gkc_summary_alloc(0.01);
  s2 = gkc_summary_alloc(0.01);
  for (i = 0; i < 1 * 10 * 1000; i++) {
    long r = random() % 10000;
    gkc_insert_value(s1, r);
  }
  snew = gkc_combine(s1, s2);
  gkc_summary_free(s1);
  gkc_summary_free(s2);
  gkc_print_summary(snew);
  print_query(snew, .02);
  print_query(snew, .1);
  print_query(snew, .25);
  print_query(snew, .5);
  print_query(snew, .75);
  print_query(snew, .82);
  print_query(snew, .88);
  print_query(snew, .86);
  print_query(snew, .99);
  gkc_sanity_check(snew);
  gkc_summary_free(snew);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
mov    0xeba(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    0xeb7(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    0xeb4(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    0xeb1(%rip),%rax
mov    %rax,-0x18(%rbp)
movsd  0xe45(%rip),%xmm0
call   10a0 <gkc_summary_alloc@plt>
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rdi
movsd  0xe28(%rip),%xmm0
call   1060 <print_query@plt>
movsd  0xe23(%rip),%xmm0
call   10a0 <gkc_summary_alloc@plt>
mov    %rax,-0x48(%rbp)
movsd  0xe12(%rip),%xmm0
call   10a0 <gkc_summary_alloc@plt>
mov    %rax,-0x50(%rbp)
movl   $0x0,-0x8(%rbp)
cmpl   $0x2710,-0x8(%rbp)
jae    1244 <main+0xc4>
mov    $0x0,%al
call   1070 <random@plt>
mov    $0x2710,%ecx
cltd
idiv   %ecx
movslq %edx,%rax
mov    %rax,-0x60(%rbp)
mov    -0x48(%rbp),%rdi
mov    -0x60(%rbp),%rsi
call   1050 <gkc_insert_value@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1206 <main+0x86>
mov    -0x48(%rbp),%rdi
mov    -0x50(%rbp),%rsi
call   1090 <gkc_combine@plt>
mov    %rax,-0x58(%rbp)
mov    -0x48(%rbp),%rdi
call   1040 <gkc_summary_free@plt>
mov    -0x50(%rbp),%rdi
call   1040 <gkc_summary_free@plt>
mov    -0x58(%rbp),%rdi
call   1080 <gkc_print_summary@plt>
mov    -0x58(%rbp),%rdi
movsd  0xdcc(%rip),%xmm0
call   1060 <print_query@plt>
mov    -0x58(%rbp),%rdi
movsd  0xd73(%rip),%xmm0
call   1060 <print_query@plt>
mov    -0x58(%rbp),%rdi
movsd  0xda2(%rip),%xmm0
call   1060 <print_query@plt>
mov    -0x58(%rbp),%rdi
movsd  0xd89(%rip),%xmm0
call   1060 <print_query@plt>
mov    -0x58(%rbp),%rdi
movsd  0xd70(%rip),%xmm0
call   1060 <print_query@plt>
mov    -0x58(%rbp),%rdi
movsd  0xd57(%rip),%xmm0
call   1060 <print_query@plt>
mov    -0x58(%rbp),%rdi
movsd  0xd3e(%rip),%xmm0
call   1060 <print_query@plt>
mov    -0x58(%rbp),%rdi
movsd  0xd25(%rip),%xmm0
call   1060 <print_query@plt>
mov    -0x58(%rbp),%rdi
movsd  0xd0c(%rip),%xmm0
call   1060 <print_query@plt>
mov    -0x58(%rbp),%rdi
call   1030 <gkc_sanity_check@plt>
mov    -0x58(%rbp),%rdi
call   1040 <gkc_summary_free@plt>
xor    %eax,%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
movsd  0xe71(%rip),%xmm0
call   10a0 <gkc_summary_alloc@plt>
movsd  0xe6c(%rip),%xmm0
mov    %rax,%rdi
call   1060 <print_query@plt>
movsd  0xe54(%rip),%xmm0
call   10a0 <gkc_summary_alloc@plt>
mov    %rax,%rbx
movsd  0xe44(%rip),%xmm0
call   10a0 <gkc_summary_alloc@plt>
mov    %rax,%r15
mov    $0x2710,%ebp
nopl   0x0(%rax)
xor    %eax,%eax
call   1070 <random@plt>
cltq
imul   $0x68db8bad,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x2c,%rcx
add    %edx,%ecx
imul   $0x2710,%ecx,%ecx
sub    %ecx,%eax
movslq %eax,%rsi
mov    %rbx,%rdi
call   1050 <gkc_insert_value@plt>
add    $0xffffffff,%ebp
jne    11d0 <main+0x50>
mov    %rbx,%rdi
mov    %r15,%rsi
call   1090 <gkc_combine@plt>
mov    %rax,%r14
mov    %rbx,%rdi
call   1040 <gkc_summary_free@plt>
mov    %r15,%rdi
call   1040 <gkc_summary_free@plt>
mov    %r14,%rdi
call   1080 <gkc_print_summary@plt>
movsd  0xddd(%rip),%xmm0
mov    %r14,%rdi
call   1060 <print_query@plt>
movsd  0xdc5(%rip),%xmm0
mov    %r14,%rdi
call   1060 <print_query@plt>
movsd  0xdc5(%rip),%xmm0
mov    %r14,%rdi
call   1060 <print_query@plt>
movsd  0xdbd(%rip),%xmm0
mov    %r14,%rdi
call   1060 <print_query@plt>
movsd  0xdb5(%rip),%xmm0
mov    %r14,%rdi
call   1060 <print_query@plt>
movsd  0xdad(%rip),%xmm0
mov    %r14,%rdi
call   1060 <print_query@plt>
movsd  0xda5(%rip),%xmm0
mov    %r14,%rdi
call   1060 <print_query@plt>
movsd  0xd9d(%rip),%xmm0
mov    %r14,%rdi
call   1060 <print_query@plt>
movsd  0xd95(%rip),%xmm0
mov    %r14,%rdi
call   1060 <print_query@plt>
mov    %r14,%rdi
call   1030 <gkc_sanity_check@plt>
mov    %r14,%rdi
call   1040 <gkc_summary_free@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.gkc_summary = type { i32 }
@__const.main.input = [4 x double] [double 1.200000e+01, double 6.000000e+00, double 1.000000e+01, double 1.000000e+00]
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [4 x double]
%4 = alloca i32*
%5 = alloca %struct.gkc_summary*
%6 = alloca %struct.gkc_summary*
%7 = alloca %struct.gkc_summary*
%8 = alloca %struct.gkc_summary*
%9 = alloca i64
store i32 0, i32* %1
%10 = bitcast [4 x double]* %3 to i8*
%11 = call %struct.gkc_summary* @gkc_summary_alloc(double 1.000000e-02)
store %struct.gkc_summary* %11, %struct.gkc_summary** %5
%12 = load %struct.gkc_summary*, %struct.gkc_summary** %5
%13 = call i32 @print_query(%struct.gkc_summary* %12, double 1.000000e-01)
br label %14
14: ; preds = %0
%15 = call %struct.gkc_summary* @gkc_summary_alloc(double 1.000000e-02)
store %struct.gkc_summary* %15, %struct.gkc_summary** %6
%16 = call %struct.gkc_summary* @gkc_summary_alloc(double 1.000000e-02)
store %struct.gkc_summary* %16, %struct.gkc_summary** %7
store i32 0, i32* %2
br label %17
17: ; preds = %27, %14
%18 = load i32, i32* %2
%19 = icmp ult i32 %18, 10000
br i1 %19, label %20, label %30
20: ; preds = %17
%21 = call i32 (...) @random()
%22 = srem i32 %21, 10000
%23 = sext i32 %22 to i64
store i64 %23, i64* %9
%24 = load %struct.gkc_summary*, %struct.gkc_summary** %6
%25 = load i64, i64* %9
%26 = call i32 @gkc_insert_value(%struct.gkc_summary* %24, i64 %25)
br label %27
27: ; preds = %20
%28 = load i32, i32* %2
%29 = add i32 %28, 1
store i32 %29, i32* %2
br label %17
30: ; preds = %17
%31 = load %struct.gkc_summary*, %struct.gkc_summary** %6
%32 = load %struct.gkc_summary*, %struct.gkc_summary** %7
%33 = call %struct.gkc_summary* @gkc_combine(%struct.gkc_summary* %31, %struct.gkc_summary* %32)
store %struct.gkc_summary* %33, %struct.gkc_summary** %8
%34 = load %struct.gkc_summary*, %struct.gkc_summary** %6
%35 = call i32 @gkc_summary_free(%struct.gkc_summary* %34)
%36 = load %struct.gkc_summary*, %struct.gkc_summary** %7
%37 = call i32 @gkc_summary_free(%struct.gkc_summary* %36)
%38 = load %struct.gkc_summary*, %struct.gkc_summary** %8
%39 = call i32 @gkc_print_summary(%struct.gkc_summary* %38)
%40 = load %struct.gkc_summary*, %struct.gkc_summary** %8
%41 = call i32 @print_query(%struct.gkc_summary* %40, double 2.000000e-02)
%42 = load %struct.gkc_summary*, %struct.gkc_summary** %8
%43 = call i32 @print_query(%struct.gkc_summary* %42, double 1.000000e-01)
%44 = load %struct.gkc_summary*, %struct.gkc_summary** %8
%45 = call i32 @print_query(%struct.gkc_summary* %44, double 2.500000e-01)
%46 = load %struct.gkc_summary*, %struct.gkc_summary** %8
%47 = call i32 @print_query(%struct.gkc_summary* %46, double 5.000000e-01)
%48 = load %struct.gkc_summary*, %struct.gkc_summary** %8
%49 = call i32 @print_query(%struct.gkc_summary* %48, double 7.500000e-01)
%50 = load %struct.gkc_summary*, %struct.gkc_summary** %8
%51 = call i32 @print_query(%struct.gkc_summary* %50, double 8.200000e-01)
%52 = load %struct.gkc_summary*, %struct.gkc_summary** %8
%53 = call i32 @print_query(%struct.gkc_summary* %52, double 8.800000e-01)
%54 = load %struct.gkc_summary*, %struct.gkc_summary** %8
%55 = call i32 @print_query(%struct.gkc_summary* %54, double 8.600000e-01)
%56 = load %struct.gkc_summary*, %struct.gkc_summary** %8
%57 = call i32 @print_query(%struct.gkc_summary* %56, double 0x3FEFAE147AE147AE)
%58 = load %struct.gkc_summary*, %struct.gkc_summary** %8
%59 = call i32 @gkc_sanity_check(%struct.gkc_summary* %58)
%60 = load %struct.gkc_summary*, %struct.gkc_summary** %8
%61 = call i32 @gkc_summary_free(%struct.gkc_summary* %60)
ret i32 0
}

LLVM IR (-O2):
%struct.gkc_summary = type { i32 }
define i32 @main() {
%1 = tail call %struct.gkc_summary* @gkc_summary_alloc(double 1.000000e-02)
%2 = tail call i32 @print_query(%struct.gkc_summary* %1, double 1.000000e-01)
%3 = tail call %struct.gkc_summary* @gkc_summary_alloc(double 1.000000e-02)
%4 = tail call %struct.gkc_summary* @gkc_summary_alloc(double 1.000000e-02)
br label %5
5: ; preds = %0, %5
%6 = phi i32 [ 0, %0 ], [ %11, %5 ]
%7 = tail call i32 (...) @random()
%8 = srem i32 %7, 10000
%9 = sext i32 %8 to i64
%10 = tail call i32 @gkc_insert_value(%struct.gkc_summary* %3, i64 %9)
%11 = add nuw nsw i32 %6, 1
%12 = icmp eq i32 %11, 10000
br i1 %12, label %13, label %5
13: ; preds = %5
%14 = tail call %struct.gkc_summary* @gkc_combine(%struct.gkc_summary* %3, %struct.gkc_summary* %4)
%15 = tail call i32 @gkc_summary_free(%struct.gkc_summary* %3)
%16 = tail call i32 @gkc_summary_free(%struct.gkc_summary* %4)
%17 = tail call i32 @gkc_print_summary(%struct.gkc_summary* %14)
%18 = tail call i32 @print_query(%struct.gkc_summary* %14, double 2.000000e-02)
%19 = tail call i32 @print_query(%struct.gkc_summary* %14, double 1.000000e-01)
%20 = tail call i32 @print_query(%struct.gkc_summary* %14, double 2.500000e-01)
%21 = tail call i32 @print_query(%struct.gkc_summary* %14, double 5.000000e-01)
%22 = tail call i32 @print_query(%struct.gkc_summary* %14, double 7.500000e-01)
%23 = tail call i32 @print_query(%struct.gkc_summary* %14, double 8.200000e-01)
%24 = tail call i32 @print_query(%struct.gkc_summary* %14, double 8.800000e-01)
%25 = tail call i32 @print_query(%struct.gkc_summary* %14, double 8.600000e-01)
%26 = tail call i32 @print_query(%struct.gkc_summary* %14, double 0x3FEFAE147AE147AE)
%27 = tail call i32 @gkc_sanity_check(%struct.gkc_summary* %14)
%28 = tail call i32 @gkc_summary_free(%struct.gkc_summary* %14)
ret i32 0
}