#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 */
typedef scalar_t__ uint;

/* Variables and functions */
int /*<<< orphan*/ calcMeanAndSD(double *, scalar_t__, double *, double *);
int /*<<< orphan*/ free(double *);
scalar_t__ malloc(int);
int /*<<< orphan*/ osso_targ(scalar_t__, scalar_t__, double *);
int /*<<< orphan*/ printf(char *, double, double);
int main() {
  double *probs;
  double mean, sd;
  uint k = 1 << 21;
  uint n = 1 << 20;
  uint len = (((k) < (n)) ? (k) : (n));
  probs = (double *)malloc(sizeof(double) * len);
  osso_targ(k, n, probs);
  calcMeanAndSD(probs, len, &mean, &sd);
  printf("Mean = %.15f, sd=%.15f\n", mean, sd);
  free(probs);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
movq   $0x200000,-0x28(%rbp)
movq   $0x100000,-0x30(%rbp)
mov    -0x28(%rbp),%rax
cmp    -0x30(%rbp),%rax
jge    118a <main+0x3a>
mov    -0x28(%rbp),%rax
mov    %rax,-0x40(%rbp)
jmp    1192 <main+0x42>
mov    -0x30(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    -0x10(%rbp),%rdx
call   1060 <osso_targ@plt>
mov    -0x10(%rbp),%rdi
mov    -0x38(%rbp),%rsi
lea    -0x18(%rbp),%rdx
lea    -0x20(%rbp),%rcx
call   1070 <calcMeanAndSD@plt>
movsd  -0x18(%rbp),%xmm0
movsd  -0x20(%rbp),%xmm1
lea    0xe1c(%rip),%rdi
call   1040 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
mov    $0x800000,%edi
call   1050 <malloc@plt>
mov    %rax,%rbx
mov    $0x200000,%edi
mov    $0x100000,%esi
mov    %rax,%rdx
call   1060 <osso_targ@plt>
lea    0x8(%rsp),%rdx
mov    %rsp,%rcx
mov    $0x100000,%esi
mov    %rbx,%rdi
call   1070 <calcMeanAndSD@plt>
movsd  0x8(%rsp),%xmm0
movsd  (%rsp),%xmm1
lea    0xe65(%rip),%rdi
call   1040 <printf@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [24 x i8] c"Mean = %.15f, sd=%.15f\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca double*
%3 = alloca double
%4 = alloca double
%5 = alloca i64
%6 = alloca i64
%7 = alloca i64
store i32 0, i32* %1
store i64 2097152, i64* %5
store i64 1048576, i64* %6
%8 = load i64, i64* %5
%9 = load i64, i64* %6
%10 = icmp slt i64 %8, %9
br i1 %10, label %11, label %13
11: ; preds = %0
%12 = load i64, i64* %5
br label %15
13: ; preds = %0
%14 = load i64, i64* %6
br label %15
15: ; preds = %13, %11
%16 = phi i64 [ %12, %11 ], [ %14, %13 ]
store i64 %16, i64* %7
%17 = load i64, i64* %7
%18 = mul i64 8, %17
%19 = trunc i64 %18 to i32
%20 = call i64 @malloc(i32 %19)
%21 = inttoptr i64 %20 to double*
store double* %21, double** %2
%22 = load i64, i64* %5
%23 = load i64, i64* %6
%24 = load double*, double** %2
%25 = call i32 @osso_targ(i64 %22, i64 %23, double* %24)
%26 = load double*, double** %2
%27 = load i64, i64* %7
%28 = call i32 @calcMeanAndSD(double* %26, i64 %27, double* %3, double* %4)
%29 = load double, double* %3
%30 = load double, double* %4
%31 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), double %29, double %30)
%32 = load double*, double** %2
%33 = call i32 @free(double* %32)
ret i32 0
}

LLVM IR (-O2):
@.str = [24 x i8] c"Mean = %.15f, sd=%.15f\0A\00"
define i32 @main() {
%1 = alloca double
%2 = alloca double
%3 = bitcast double* %1 to i8*
%4 = bitcast double* %2 to i8*
%5 = tail call i64 @malloc(i32 8388608)
%6 = inttoptr i64 %5 to double*
%7 = tail call i32 @osso_targ(i64 2097152, i64 1048576, double* %6)
%8 = call i32 @calcMeanAndSD(double* %6, i64 1048576, double* %1, double* %2)
%9 = load double, double* %1
%10 = load double, double* %2
%11 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), double %9, double %10)
%12 = call i32 @free(double* %6)
ret i32 0
}