#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 /*<<< orphan*/ free(double *);
double sqrt(double);
double vdot(double *, double *, int);
int /*<<< orphan*/ vsp(double *, double *, double, int);
double corr(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);
  y = v11 * v22;
  if (y == 0.0)
    fatalx("(corr) constant vector\n");
  free(aa);
  free(bb);
  return (v12 / sqrt(y));
}


x86 assembly (clang, -O0):
<corr>:
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    11bf <corr+0x3f>
mov    -0x14(%rbp),%esi
lea    0xe48(%rip),%rdi
mov    $0x0,%al
call   1050 <fatalx@plt>
mov    -0x14(%rbp),%edi
mov    $0x8,%esi
call   1060 <calloc@plt>
mov    %rax,-0x58(%rbp)
cmp    $0x0,%rax
jne    11eb <corr+0x6b>
mov    -0x14(%rbp),%esi
lea    0xe1c(%rip),%rdi
mov    $0x0,%al
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)
movsd  -0x28(%rbp),%xmm0
mulsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x48(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    12e3 <corr+0x163>
jp     12e3 <corr+0x163>
lea    0xd4d(%rip),%rdi
mov    $0x0,%al
call   1050 <fatalx@plt>
mov    -0x50(%rbp),%rdi
call   1030 <free@plt>
mov    -0x58(%rbp),%rdi
call   1030 <free@plt>
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):
<corr>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x30,%rsp
mov    %edx,%ebp
mov    %rsi,%r15
mov    %rdi,%r12
mov    %edx,%edi
mov    $0x8,%esi
call   1060 <calloc@plt>
mov    %rax,%r14
test   %rax,%rax
jne    11b8 <corr+0x38>
lea    0xe69(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1050 <fatalx@plt>
mov    %ebp,%edi
mov    $0x8,%esi
call   1060 <calloc@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    11dc <corr+0x5c>
lea    0xe45(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1050 <fatalx@plt>
mov    %r12,%rdi
mov    %ebp,%esi
call   1070 <asum@plt>
movaps %xmm0,0x20(%rsp)
xorps  %xmm0,%xmm0
cvtsi2sd %ebp,%xmm0
movsd  %xmm0,0x8(%rsp)
mov    %r15,%rdi
mov    %ebp,%esi
call   1070 <asum@plt>
movapd %xmm0,0x10(%rsp)
movapd 0x20(%rsp),%xmm0
xorpd  0xdea(%rip),%xmm0
divsd  0x8(%rsp),%xmm0
mov    %r14,%rdi
mov    %r12,%rsi
mov    %ebp,%edx
call   1040 <vsp@plt>
movapd 0x10(%rsp),%xmm0
xorpd  0xdc9(%rip),%xmm0
divsd  0x8(%rsp),%xmm0
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %ebp,%edx
call   1040 <vsp@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %ebp,%edx
call   1080 <vdot@plt>
movsd  %xmm0,0x10(%rsp)
mov    %r14,%rdi
mov    %ebp,%esi
call   10a0 <asum2@plt>
movsd  %xmm0,0x8(%rsp)
mov    %rbx,%rdi
mov    %ebp,%esi
call   10a0 <asum2@plt>
mulsd  0x8(%rsp),%xmm0
xorpd  %xmm1,%xmm1
movsd  %xmm0,0x8(%rsp)
ucomisd %xmm1,%xmm0
jne    129d <corr+0x11d>
jp     129d <corr+0x11d>
lea    0xdab(%rip),%rdi
xor    %eax,%eax
call   1050 <fatalx@plt>
mov    %r14,%rdi
call   1030 <free@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
movsd  0x8(%rsp),%xmm0
ucomisd 0xd55(%rip),%xmm0
jb     12c3 <corr+0x143>
sqrtsd %xmm0,%xmm0
jmp    12c8 <corr+0x148>
call   1090 <sqrt@plt>
movsd  0x10(%rsp),%xmm1
divsd  %xmm0,%xmm1
movapd %xmm1,%xmm0
add    $0x30,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [41 x i8] c"Unable to allocate %d unit(s) for item \0A\00"
@.str.1 = [24 x i8] c"(corr) constant vector\0A\00"
define double @corr(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 (i8*, ...) @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 (i8*, ...) @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* %8
%66 = load double, double* %9
%67 = fmul double %65, %66
store double %67, double* %12
%68 = load double, double* %12
%69 = fcmp oeq double %68, 0.000000e+00
br i1 %69, label %70, label %72
70: ; preds = %30
%71 = call i32 (i8*, ...) @fatalx(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0))
br label %72
72: ; preds = %70, %30
%73 = load double*, double** %13
%74 = call i32 @free(double* %73)
%75 = load double*, double** %14
%76 = call i32 @free(double* %75)
%77 = load double, double* %7
%78 = load double, double* %12
%79 = call double @sqrt(double %78)
%80 = fdiv double %77, %79
ret double %80
}

LLVM IR (-O2):
@.str = [41 x i8] c"Unable to allocate %d unit(s) for item \0A\00"
@.str.1 = [24 x i8] c"(corr) constant vector\0A\00"
define double @corr(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 (i8*, ...) @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 (i8*, ...) @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 = fmul double %26, %27
%29 = fcmp oeq double %28, 0.000000e+00
br i1 %29, label %30, label %32
30: ; preds = %15
%31 = tail call i32 (i8*, ...) @fatalx(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0))
br label %32
32: ; preds = %30, %15
%33 = tail call i32 @free(double* %5)
%34 = tail call i32 @free(double* %11)
%35 = tail call double @sqrt(double %28)
%36 = fdiv double %25, %35
ret double %36
}