#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 */
double asum(double *, int);
double asum2(double *, int);
scalar_t__ calloc(int, int);
int /*<<< orphan*/ fatalx(char *, int);
int /*<<< orphan*/ free(double *);
double sqrt(double);
double vdot(double *, double *, int);
int /*<<< orphan*/ vsp(double *, double *, double, int);
double corrx(double *a, double *b, int n) {
  double v12, v11, v22, y1, y2, y;
  double *aa, *bb;
  if ((aa = (double *)calloc((n), sizeof(double))) == NULL)
    fatalx("Unable to allocate %d unit(s) for item \n", n);
  if ((bb = (double *)calloc((n), sizeof(double))) == NULL)
    fatalx("Unable to allocate %d unit(s) for item \n", n);
  y1 = asum(a, n) / (double)n;
  y2 = asum(b, n) / (double)n;
  vsp(aa, a, -y1, n);
  vsp(bb, b, -y2, n);
  v12 = vdot(aa, bb, n);
  v11 = asum2(aa, n);
  v22 = asum2(bb, n);
  free(aa);
  free(bb);
  y = v11 * v22;
  y += 1.0e-12;
  return (v12 / sqrt(y));
}


x86 assembly (clang, -O0):
<corrx>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x14(%rbp),%edi
mov    $0x8,%esi
call   1060 <calloc@plt>
mov    %rax,-0x50(%rbp)
cmp    $0x0,%rax
jne    11bd <corrx+0x3d>
mov    -0x14(%rbp),%esi
lea    0xe50(%rip),%rdi
call   1050 <fatalx@plt>
mov    -0x14(%rbp),%edi
mov    $0x8,%esi
call   1060 <calloc@plt>
mov    %rax,-0x58(%rbp)
cmp    $0x0,%rax
jne    11e7 <corrx+0x67>
mov    -0x14(%rbp),%esi
lea    0xe26(%rip),%rdi
call   1050 <fatalx@plt>
mov    -0x8(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1070 <asum@plt>
cvtsi2sdl -0x14(%rbp),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x38(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1070 <asum@plt>
cvtsi2sdl -0x14(%rbp),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x40(%rbp)
mov    -0x50(%rbp),%rdi
mov    -0x8(%rbp),%rsi
movsd  -0x38(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
mov    -0x14(%rbp),%edx
call   1040 <vsp@plt>
mov    -0x58(%rbp),%rdi
mov    -0x10(%rbp),%rsi
movsd  -0x40(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
mov    -0x14(%rbp),%edx
call   1040 <vsp@plt>
mov    -0x50(%rbp),%rdi
mov    -0x58(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1080 <vdot@plt>
movsd  %xmm0,-0x20(%rbp)
mov    -0x50(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   10a0 <asum2@plt>
movsd  %xmm0,-0x28(%rbp)
mov    -0x58(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   10a0 <asum2@plt>
movsd  %xmm0,-0x30(%rbp)
mov    -0x50(%rbp),%rdi
call   1030 <free@plt>
mov    -0x58(%rbp),%rdi
call   1030 <free@plt>
movsd  -0x28(%rbp),%xmm0
mulsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  0xd2d(%rip),%xmm0
addsd  -0x48(%rbp),%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x60(%rbp)
movsd  -0x48(%rbp),%xmm0
call   1090 <sqrt@plt>
movaps %xmm0,%xmm1
movsd  -0x60(%rbp),%xmm0
divsd  %xmm1,%xmm0
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<corrx>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x30,%rsp
mov    %edx,%ebx
mov    %rsi,%r12
mov    %rdi,%r13
mov    %edx,%edi
mov    $0x8,%esi
call   1060 <calloc@plt>
mov    %rax,%r14
test   %rax,%rax
jne    11b7 <corrx+0x37>
lea    0xe68(%rip),%rdi
mov    %ebx,%esi
call   1050 <fatalx@plt>
mov    %ebx,%edi
mov    $0x8,%esi
call   1060 <calloc@plt>
mov    %rax,%r15
test   %rax,%rax
jne    11d9 <corrx+0x59>
lea    0xe46(%rip),%rdi
mov    %ebx,%esi
call   1050 <fatalx@plt>
mov    %r13,%rdi
mov    %ebx,%esi
call   1070 <asum@plt>
movaps %xmm0,0x10(%rsp)
xorps  %xmm0,%xmm0
cvtsi2sd %ebx,%xmm0
movsd  %xmm0,0x8(%rsp)
mov    %r12,%rdi
mov    %ebx,%esi
call   1070 <asum@plt>
movapd %xmm0,0x20(%rsp)
movapd 0x10(%rsp),%xmm0
xorpd  0xded(%rip),%xmm0
divsd  0x8(%rsp),%xmm0
mov    %r14,%rdi
mov    %r13,%rsi
mov    %ebx,%edx
call   1040 <vsp@plt>
movapd 0x20(%rsp),%xmm0
xorpd  0xdcc(%rip),%xmm0
divsd  0x8(%rsp),%xmm0
mov    %r15,%rdi
mov    %r12,%rsi
mov    %ebx,%edx
call   1040 <vsp@plt>
mov    %r14,%rdi
mov    %r15,%rsi
mov    %ebx,%edx
call   1080 <vdot@plt>
movsd  %xmm0,0x10(%rsp)
mov    %r14,%rdi
mov    %ebx,%esi
call   10a0 <asum2@plt>
movsd  %xmm0,0x8(%rsp)
mov    %r15,%rdi
mov    %ebx,%esi
call   10a0 <asum2@plt>
movsd  %xmm0,0x20(%rsp)
mov    %r14,%rdi
call   1030 <free@plt>
mov    %r15,%rdi
call   1030 <free@plt>
movsd  0x20(%rsp),%xmm1
mulsd  0x8(%rsp),%xmm1
addsd  0xd72(%rip),%xmm1
xorpd  %xmm0,%xmm0
ucomisd %xmm0,%xmm1
movapd %xmm1,%xmm0
jb     12b2 <corrx+0x132>
sqrtsd %xmm0,%xmm0
jmp    12b7 <corrx+0x137>
call   1090 <sqrt@plt>
movsd  0x10(%rsp),%xmm1
divsd  %xmm0,%xmm1
movapd %xmm1,%xmm0
add    $0x30,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [41 x i8] c"Unable to allocate %d unit(s) for item \0A\00"
define double @corrx(double* %0, double* %1, i32 %2) {
%4 = alloca double*
%5 = alloca double*
%6 = alloca i32
%7 = alloca double
%8 = alloca double
%9 = alloca double
%10 = alloca double
%11 = alloca double
%12 = alloca double
%13 = alloca double*
%14 = alloca double*
store double* %0, double** %4
store double* %1, double** %5
store i32 %2, i32* %6
%15 = load i32, i32* %6
%16 = call i64 @calloc(i32 %15, i32 8)
%17 = inttoptr i64 %16 to double*
store double* %17, double** %13
%18 = icmp eq double* %17, null
br i1 %18, label %19, label %22
19: ; preds = %3
%20 = load i32, i32* %6
%21 = call i32 @fatalx(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0), i32 %20)
br label %22
22: ; preds = %19, %3
%23 = load i32, i32* %6
%24 = call i64 @calloc(i32 %23, i32 8)
%25 = inttoptr i64 %24 to double*
store double* %25, double** %14
%26 = icmp eq double* %25, null
br i1 %26, label %27, label %30
27: ; preds = %22
%28 = load i32, i32* %6
%29 = call i32 @fatalx(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0), i32 %28)
br label %30
30: ; preds = %27, %22
%31 = load double*, double** %4
%32 = load i32, i32* %6
%33 = call double @asum(double* %31, i32 %32)
%34 = load i32, i32* %6
%35 = sitofp i32 %34 to double
%36 = fdiv double %33, %35
store double %36, double* %10
%37 = load double*, double** %5
%38 = load i32, i32* %6
%39 = call double @asum(double* %37, i32 %38)
%40 = load i32, i32* %6
%41 = sitofp i32 %40 to double
%42 = fdiv double %39, %41
store double %42, double* %11
%43 = load double*, double** %13
%44 = load double*, double** %4
%45 = load double, double* %10
%46 = fneg double %45
%47 = load i32, i32* %6
%48 = call i32 @vsp(double* %43, double* %44, double %46, i32 %47)
%49 = load double*, double** %14
%50 = load double*, double** %5
%51 = load double, double* %11
%52 = fneg double %51
%53 = load i32, i32* %6
%54 = call i32 @vsp(double* %49, double* %50, double %52, i32 %53)
%55 = load double*, double** %13
%56 = load double*, double** %14
%57 = load i32, i32* %6
%58 = call double @vdot(double* %55, double* %56, i32 %57)
store double %58, double* %7
%59 = load double*, double** %13
%60 = load i32, i32* %6
%61 = call double @asum2(double* %59, i32 %60)
store double %61, double* %8
%62 = load double*, double** %14
%63 = load i32, i32* %6
%64 = call double @asum2(double* %62, i32 %63)
store double %64, double* %9
%65 = load double*, double** %13
%66 = call i32 @free(double* %65)
%67 = load double*, double** %14
%68 = call i32 @free(double* %67)
%69 = load double, double* %8
%70 = load double, double* %9
%71 = fmul double %69, %70
store double %71, double* %12
%72 = load double, double* %12
%73 = fadd double %72, 0x3D719799812DEA11
store double %73, double* %12
%74 = load double, double* %7
%75 = load double, double* %12
%76 = call double @sqrt(double %75)
%77 = fdiv double %74, %76
ret double %77
}

LLVM IR (-O2):
@.str = [41 x i8] c"Unable to allocate %d unit(s) for item \0A\00"
define double @corrx(double* %0, double* %1, i32 %2) {
%4 = tail call i64 @calloc(i32 %2, i32 8)
%5 = inttoptr i64 %4 to double*
%6 = icmp eq i64 %4, 0
br i1 %6, label %7, label %9
7: ; preds = %3
%8 = tail call i32 @fatalx(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0), i32 %2)
br label %9
9: ; preds = %7, %3
%10 = tail call i64 @calloc(i32 %2, i32 8)
%11 = inttoptr i64 %10 to double*
%12 = icmp eq i64 %10, 0
br i1 %12, label %13, label %15
13: ; preds = %9
%14 = tail call i32 @fatalx(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0), i32 %2)
br label %15
15: ; preds = %13, %9
%16 = tail call double @asum(double* %0, i32 %2)
%17 = sitofp i32 %2 to double
%18 = tail call double @asum(double* %1, i32 %2)
%19 = fneg double %16
%20 = fdiv double %19, %17
%21 = tail call i32 @vsp(double* %5, double* %0, double %20, i32 %2)
%22 = fneg double %18
%23 = fdiv double %22, %17
%24 = tail call i32 @vsp(double* %11, double* %1, double %23, i32 %2)
%25 = tail call double @vdot(double* %5, double* %11, i32 %2)
%26 = tail call double @asum2(double* %5, i32 %2)
%27 = tail call double @asum2(double* %11, i32 %2)
%28 = tail call i32 @free(double* %5)
%29 = tail call i32 @free(double* %11)
%30 = fmul double %26, %27
%31 = fadd double %30, 0x3D719799812DEA11
%32 = tail call double @sqrt(double %31)
%33 = fdiv double %25, %32
ret double %33
}