#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 dist1d_c(double, double);
double dist2d_c(double, double, double, double);
double *malloc(int);
double *cross_corr_2d_1d(double *norm_dcube, int n_x, int n_y, int n_vr,
                         double *c_x, double *c_y, double *c_vr, double c_xi,
                         double c_yi, double c_vri, double rmin, double rmax,
                         double vrmin, double vrmax) {
  double *vals;
  vals = malloc(sizeof(double) * 3);
  double sumx = 0.0, sumx2 = 0.0, ncell = 0.0, tmpval = 0.0;
  double tmp_x, tmp_y, tmp_vr, rdist, vrdist;
  int i_x, i_y, i_vr;
  for (i_x = 0; i_x < n_x; i_x++) {
    tmp_x = c_x[i_x];
    for (i_y = 0; i_y < n_y; i_y++) {
      tmp_y = c_y[i_y];
      rdist = dist2d_c(tmp_x, tmp_y, c_xi, c_yi);
      if ((rdist >= rmin) && (rdist < rmax)) {
        for (i_vr = 0; i_vr < n_vr; i_vr++) {
          tmp_vr = c_vr[i_vr];
          vrdist = dist1d_c(tmp_vr, c_vri);
          if ((vrdist >= vrmin) && (vrdist < vrmax)) {
            tmpval = norm_dcube[(n_y * n_vr * i_x) + (n_vr * i_y) + i_vr];
            sumx += tmpval;
            sumx2 += tmpval * tmpval;
            ncell += 1.0;
          }
        }
      }
    }
  }
  vals[0] = sumx;
  vals[1] = sumx2;
  vals[2] = ncell;
  return vals;
}


x86 assembly (clang, -O0):
<cross_corr_2d_1d>:
push   %rbp
mov    %rsp,%rbp
sub    $0xc0,%rsp
mov    0x10(%rbp),%rax
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %ecx,-0x14(%rbp)
mov    %r8,-0x20(%rbp)
mov    %r9,-0x28(%rbp)
movsd  %xmm0,-0x30(%rbp)
movsd  %xmm1,-0x38(%rbp)
movsd  %xmm2,-0x40(%rbp)
movsd  %xmm3,-0x48(%rbp)
movsd  %xmm4,-0x50(%rbp)
movsd  %xmm5,-0x58(%rbp)
movsd  %xmm6,-0x60(%rbp)
mov    $0x18,%edi
call   1050 <malloc@plt>
mov    %rax,-0x68(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x70(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x78(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x80(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x88(%rbp)
ff
movl   $0x0,-0xb4(%rbp)
mov    -0xb4(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    139a <cross_corr_2d_1d+0x26a>
mov    -0x20(%rbp),%rax
movslq -0xb4(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x90(%rbp)
ff
movl   $0x0,-0xb8(%rbp)
mov    -0xb8(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    1381 <cross_corr_2d_1d+0x251>
mov    -0x28(%rbp),%rax
movslq -0xb8(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x98(%rbp)
ff
movsd  -0x90(%rbp),%xmm0
ff
movsd  -0x98(%rbp),%xmm1
ff
movsd  -0x30(%rbp),%xmm2
movsd  -0x38(%rbp),%xmm3
call   1040 <dist2d_c@plt>
movsd  %xmm0,-0xa8(%rbp)
ff
movsd  -0xa8(%rbp),%xmm0
ff
ucomisd -0x48(%rbp),%xmm0
jb     1368 <cross_corr_2d_1d+0x238>
movsd  -0xa8(%rbp),%xmm1
ff
movsd  -0x50(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jbe    1368 <cross_corr_2d_1d+0x238>
movl   $0x0,-0xbc(%rbp)
mov    -0xbc(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1363 <cross_corr_2d_1d+0x233>
mov    0x10(%rbp),%rax
movslq -0xbc(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0xa0(%rbp)
ff
movsd  -0xa0(%rbp),%xmm0
ff
movsd  -0x40(%rbp),%xmm1
call   1030 <dist1d_c@plt>
movsd  %xmm0,-0xb0(%rbp)
ff
movsd  -0xb0(%rbp),%xmm0
ff
ucomisd -0x58(%rbp),%xmm0
jb     134a <cross_corr_2d_1d+0x21a>
movsd  -0xb0(%rbp),%xmm1
ff
movsd  -0x60(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jbe    134a <cross_corr_2d_1d+0x21a>
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%ecx
imul   -0x14(%rbp),%ecx
imul   -0xb4(%rbp),%ecx
mov    -0x14(%rbp),%edx
imul   -0xb8(%rbp),%edx
add    %edx,%ecx
add    -0xbc(%rbp),%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x88(%rbp)
ff
movsd  -0x88(%rbp),%xmm0
ff
addsd  -0x70(%rbp),%xmm0
movsd  %xmm0,-0x70(%rbp)
movsd  -0x88(%rbp),%xmm0
ff
movsd  -0x88(%rbp),%xmm2
ff
movsd  -0x78(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x78(%rbp)
movsd  0xcc0(%rip),%xmm0
addsd  -0x80(%rbp),%xmm0
movsd  %xmm0,-0x80(%rbp)
jmp    134f <cross_corr_2d_1d+0x21f>
mov    -0xbc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xbc(%rbp)
jmp    1265 <cross_corr_2d_1d+0x135>
jmp    1368 <cross_corr_2d_1d+0x238>
jmp    136d <cross_corr_2d_1d+0x23d>
mov    -0xb8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xb8(%rbp)
jmp    11e3 <cross_corr_2d_1d+0xb3>
jmp    1386 <cross_corr_2d_1d+0x256>
mov    -0xb4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xb4(%rbp)
jmp    11b2 <cross_corr_2d_1d+0x82>
movsd  -0x70(%rbp),%xmm0
mov    -0x68(%rbp),%rax
movsd  %xmm0,(%rax)
movsd  -0x78(%rbp),%xmm0
mov    -0x68(%rbp),%rax
movsd  %xmm0,0x8(%rax)
movsd  -0x80(%rbp),%xmm0
mov    -0x68(%rbp),%rax
movsd  %xmm0,0x10(%rax)
mov    -0x68(%rbp),%rax
add    $0xc0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cross_corr_2d_1d>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xa8,%rsp
movsd  %xmm6,0x90(%rsp)
movsd  %xmm5,0xa0(%rsp)
movsd  %xmm4,0x58(%rsp)
movsd  %xmm3,0x80(%rsp)
movsd  %xmm2,0x98(%rsp)
movsd  %xmm1,0x78(%rsp)
movsd  %xmm0,0x70(%rsp)
mov    %r9,0x68(%rsp)
mov    %r8,0x38(%rsp)
mov    %ecx,%r12d
mov    %edx,%ebx
mov    %esi,%r14d
mov    %rdi,%rbp
mov    $0x18,%edi
call   1050 <malloc@plt>
mov    %rax,0x30(%rsp)
test   %r14d,%r14d
jle    132d <cross_corr_2d_1d+0x1fd>
mov    0xe0(%rsp),%r15
mov    %r14d,%eax
mov    %rax,0x48(%rsp)
mov    %ebx,%eax
mov    %rax,0x60(%rsp)
mov    %r12d,%eax
mov    %r12d,%r12d
mov    %eax,0x2c(%rsp)
imul   %ebx,%eax
mov    %rax,0x40(%rsp)
xorpd  %xmm0,%xmm0
movsd  %xmm0,0x18(%rsp)
xor    %r13d,%r13d
xor    %eax,%eax
mov    %rax,0x20(%rsp)
xorpd  %xmm0,%xmm0
movsd  %xmm0,0x8(%rsp)
xorpd  %xmm0,%xmm0
movsd  %xmm0,0x10(%rsp)
mov    %ebx,0x28(%rsp)
jmp    122a <cross_corr_2d_1d+0xfa>
nopl   0x0(%rax,%rax,1)
mov    0x20(%rsp),%rcx
add    $0x1,%rcx
mov    0x50(%rsp),%r13
add    0x40(%rsp),%r13
mov    %rcx,%rax
mov    %rcx,0x20(%rsp)
cmp    0x48(%rsp),%rcx
mov    0x28(%rsp),%ebx
je     134b <cross_corr_2d_1d+0x21b>
test   %ebx,%ebx
mov    %r13,0x50(%rsp)
jle    1200 <cross_corr_2d_1d+0xd0>
mov    0x38(%rsp),%rax
mov    0x20(%rsp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,0x88(%rsp)
xor    %ebx,%ebx
jmp    125e <cross_corr_2d_1d+0x12e>
nop
add    $0x1,%rbx
add    %r12,%r13
cmp    0x60(%rsp),%rbx
je     1200 <cross_corr_2d_1d+0xd0>
mov    0x68(%rsp),%rax
movsd  (%rax,%rbx,8),%xmm1
movsd  0x88(%rsp),%xmm0
movsd  0x70(%rsp),%xmm2
movsd  0x78(%rsp),%xmm3
call   1040 <dist2d_c@plt>
ucomisd 0x80(%rsp),%xmm0
jb     1250 <cross_corr_2d_1d+0x120>
movsd  0x58(%rsp),%xmm1
ucomisd %xmm0,%xmm1
jbe    1250 <cross_corr_2d_1d+0x120>
cmpl   $0x0,0x2c(%rsp)
jle    1250 <cross_corr_2d_1d+0x120>
xor    %r14d,%r14d
jmp    12b9 <cross_corr_2d_1d+0x189>
cs nopw 0x0(%rax,%rax,1)
nop
add    $0x1,%r14
cmp    %r14,%r12
je     1250 <cross_corr_2d_1d+0x120>
movsd  (%r15,%r14,8),%xmm0
movsd  0x98(%rsp),%xmm1
call   1030 <dist1d_c@plt>
ucomisd 0xa0(%rsp),%xmm0
jb     12b0 <cross_corr_2d_1d+0x180>
movsd  0x90(%rsp),%xmm1
ucomisd %xmm0,%xmm1
jbe    12b0 <cross_corr_2d_1d+0x180>
lea    (%r14,%r13,1),%eax
cltq
movsd  0x0(%rbp,%rax,8),%xmm0
movsd  0x18(%rsp),%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,0x18(%rsp)
mulsd  %xmm0,%xmm0
movsd  0x8(%rsp),%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,0x8(%rsp)
movsd  0x10(%rsp),%xmm0
addsd  0xcdb(%rip),%xmm0
movsd  %xmm0,0x10(%rsp)
jmp    12b0 <cross_corr_2d_1d+0x180>
xorpd  %xmm0,%xmm0
movsd  %xmm0,0x10(%rsp)
xorpd  %xmm0,%xmm0
movsd  %xmm0,0x8(%rsp)
xorpd  %xmm0,%xmm0
movsd  %xmm0,0x18(%rsp)
mov    0x30(%rsp),%rax
movsd  0x18(%rsp),%xmm0
movsd  %xmm0,(%rax)
movsd  0x8(%rsp),%xmm0
movsd  %xmm0,0x8(%rax)
movsd  0x10(%rsp),%xmm0
movsd  %xmm0,0x10(%rax)
add    $0xa8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define double* @cross_corr_2d_1d(double* %0, i32 %1, i32 %2, i32 %3, double* %4, double* %5, double* %6, double %7, double %8, double %9, double %10, double %11, double %12, double %13) {
%15 = alloca double*
%16 = alloca i32
%17 = alloca i32
%18 = alloca i32
%19 = alloca double*
%20 = alloca double*
%21 = alloca double*
%22 = alloca double
%23 = alloca double
%24 = alloca double
%25 = alloca double
%26 = alloca double
%27 = alloca double
%28 = alloca double
%29 = alloca double*
%30 = alloca double
%31 = alloca double
%32 = alloca double
%33 = alloca double
%34 = alloca double
%35 = alloca double
%36 = alloca double
%37 = alloca double
%38 = alloca double
%39 = alloca i32
%40 = alloca i32
%41 = alloca i32
store double* %0, double** %15
store i32 %1, i32* %16
store i32 %2, i32* %17
store i32 %3, i32* %18
store double* %4, double** %19
store double* %5, double** %20
store double* %6, double** %21
store double %7, double* %22
store double %8, double* %23
store double %9, double* %24
store double %10, double* %25
store double %11, double* %26
store double %12, double* %27
store double %13, double* %28
%42 = call double* @malloc(i32 24)
store double* %42, double** %29
store double 0.000000e+00, double* %30
store double 0.000000e+00, double* %31
store double 0.000000e+00, double* %32
store double 0.000000e+00, double* %33
store i32 0, i32* %39
br label %43
43: ; preds = %131, %14
%44 = load i32, i32* %39
%45 = load i32, i32* %16
%46 = icmp slt i32 %44, %45
br i1 %46, label %47, label %134
47: ; preds = %43
%48 = load double*, double** %19
%49 = load i32, i32* %39
%50 = sext i32 %49 to i64
%51 = getelementptr inbounds double, double* %48, i64 %50
%52 = load double, double* %51
store double %52, double* %34
store i32 0, i32* %40
br label %53
53: ; preds = %127, %47
%54 = load i32, i32* %40
%55 = load i32, i32* %17
%56 = icmp slt i32 %54, %55
br i1 %56, label %57, label %130
57: ; preds = %53
%58 = load double*, double** %20
%59 = load i32, i32* %40
%60 = sext i32 %59 to i64
%61 = getelementptr inbounds double, double* %58, i64 %60
%62 = load double, double* %61
store double %62, double* %35
%63 = load double, double* %34
%64 = load double, double* %35
%65 = load double, double* %22
%66 = load double, double* %23
%67 = call double @dist2d_c(double %63, double %64, double %65, double %66)
store double %67, double* %37
%68 = load double, double* %37
%69 = load double, double* %25
%70 = fcmp oge double %68, %69
br i1 %70, label %71, label %126
71: ; preds = %57
%72 = load double, double* %37
%73 = load double, double* %26
%74 = fcmp olt double %72, %73
br i1 %74, label %75, label %126
75: ; preds = %71
store i32 0, i32* %41
br label %76
76: ; preds = %122, %75
%77 = load i32, i32* %41
%78 = load i32, i32* %18
%79 = icmp slt i32 %77, %78
br i1 %79, label %80, label %125
80: ; preds = %76
%81 = load double*, double** %21
%82 = load i32, i32* %41
%83 = sext i32 %82 to i64
%84 = getelementptr inbounds double, double* %81, i64 %83
%85 = load double, double* %84
store double %85, double* %36
%86 = load double, double* %36
%87 = load double, double* %24
%88 = call double @dist1d_c(double %86, double %87)
store double %88, double* %38
%89 = load double, double* %38
%90 = load double, double* %27
%91 = fcmp oge double %89, %90
br i1 %91, label %92, label %121
92: ; preds = %80
%93 = load double, double* %38
%94 = load double, double* %28
%95 = fcmp olt double %93, %94
br i1 %95, label %96, label %121
96: ; preds = %92
%97 = load double*, double** %15
%98 = load i32, i32* %17
%99 = load i32, i32* %18
%100 = mul nsw i32 %98, %99
%101 = load i32, i32* %39
%102 = mul nsw i32 %100, %101
%103 = load i32, i32* %18
%104 = load i32, i32* %40
%105 = mul nsw i32 %103, %104
%106 = add nsw i32 %102, %105
%107 = load i32, i32* %41
%108 = add nsw i32 %106, %107
%109 = sext i32 %108 to i64
%110 = getelementptr inbounds double, double* %97, i64 %109
%111 = load double, double* %110
store double %111, double* %33
%112 = load double, double* %33
%113 = load double, double* %30
%114 = fadd double %113, %112
store double %114, double* %30
%115 = load double, double* %33
%116 = load double, double* %33
%117 = load double, double* %31
%118 = call double @llvm.fmuladd.f64(double %115, double %116, double %117)
store double %118, double* %31
%119 = load double, double* %32
%120 = fadd double %119, 1.000000e+00
store double %120, double* %32
br label %121
121: ; preds = %96, %92, %80
br label %122
122: ; preds = %121
%123 = load i32, i32* %41
%124 = add nsw i32 %123, 1
store i32 %124, i32* %41
br label %76
125: ; preds = %76
br label %126
126: ; preds = %125, %71, %57
br label %127
127: ; preds = %126
%128 = load i32, i32* %40
%129 = add nsw i32 %128, 1
store i32 %129, i32* %40
br label %53
130: ; preds = %53
br label %131
131: ; preds = %130
%132 = load i32, i32* %39
%133 = add nsw i32 %132, 1
store i32 %133, i32* %39
br label %43
134: ; preds = %43
%135 = load double, double* %30
%136 = load double*, double** %29
%137 = getelementptr inbounds double, double* %136, i64 0
store double %135, double* %137
%138 = load double, double* %31
%139 = load double*, double** %29
%140 = getelementptr inbounds double, double* %139, i64 1
store double %138, double* %140
%141 = load double, double* %32
%142 = load double*, double** %29
%143 = getelementptr inbounds double, double* %142, i64 2
store double %141, double* %143
%144 = load double*, double** %29
ret double* %144
}

LLVM IR (-O2):
define noalias double* @cross_corr_2d_1d(double* nocapture %0, i32 %1, i32 %2, i32 %3, double* nocapture %4, double* nocapture %5, double* nocapture %6, double %7, double %8, double %9, double %10, double %11, double %12, double %13) {
%15 = tail call double* @malloc(i32 24)
%16 = icmp sgt i32 %1, 0
br i1 %16, label %17, label %87
17: ; preds = %14
%18 = icmp sgt i32 %2, 0
%19 = icmp slt i32 %3, 1
%20 = zext i32 %1 to i64
%21 = zext i32 %2 to i64
%22 = zext i32 %3 to i64
br label %23
23: ; preds = %17, %81
%24 = phi i64 [ 0, %17 ], [ %85, %81 ]
%25 = phi double [ 0.000000e+00, %17 ], [ %84, %81 ]
%26 = phi double [ 0.000000e+00, %17 ], [ %83, %81 ]
%27 = phi double [ 0.000000e+00, %17 ], [ %82, %81 ]
%28 = getelementptr inbounds double, double* %4, i64 %24
%29 = load double, double* %28
br i1 %18, label %30, label %81
30: ; preds = %23
%31 = trunc i64 %24 to i32
%32 = mul i32 %31, %2
br label %33
33: ; preds = %30, %75
%34 = phi i64 [ 0, %30 ], [ %79, %75 ]
%35 = phi double [ %25, %30 ], [ %78, %75 ]
%36 = phi double [ %26, %30 ], [ %77, %75 ]
%37 = phi double [ %27, %30 ], [ %76, %75 ]
%38 = getelementptr inbounds double, double* %5, i64 %34
%39 = load double, double* %38
%40 = tail call double @dist2d_c(double %29, double %39, double %7, double %8)
%41 = fcmp ult double %40, %10
%42 = fcmp uge double %40, %11
%43 = or i1 %41, %42
%44 = or i1 %43, %19
br i1 %44, label %75, label %45
45: ; preds = %33
%46 = trunc i64 %34 to i32
%47 = add i32 %32, %46
%48 = mul i32 %47, %3
br label %49
49: ; preds = %45, %69
%50 = phi i64 [ 0, %45 ], [ %73, %69 ]
%51 = phi double [ %35, %45 ], [ %72, %69 ]
%52 = phi double [ %36, %45 ], [ %71, %69 ]
%53 = phi double [ %37, %45 ], [ %70, %69 ]
%54 = getelementptr inbounds double, double* %6, i64 %50
%55 = load double, double* %54
%56 = tail call double @dist1d_c(double %55, double %9)
%57 = fcmp oge double %56, %12
%58 = fcmp olt double %56, %13
%59 = and i1 %57, %58
br i1 %59, label %60, label %69
60: ; preds = %49
%61 = trunc i64 %50 to i32
%62 = add i32 %48, %61
%63 = sext i32 %62 to i64
%64 = getelementptr inbounds double, double* %0, i64 %63
%65 = load double, double* %64
%66 = fadd double %51, %65
%67 = tail call double @llvm.fmuladd.f64(double %65, double %65, double %52)
%68 = fadd double %53, 1.000000e+00
br label %69
69: ; preds = %49, %60
%70 = phi double [ %68, %60 ], [ %53, %49 ]
%71 = phi double [ %67, %60 ], [ %52, %49 ]
%72 = phi double [ %66, %60 ], [ %51, %49 ]
%73 = add nuw nsw i64 %50, 1
%74 = icmp eq i64 %73, %22
br i1 %74, label %75, label %49
75: ; preds = %69, %33
%76 = phi double [ %37, %33 ], [ %70, %69 ]
%77 = phi double [ %36, %33 ], [ %71, %69 ]
%78 = phi double [ %35, %33 ], [ %72, %69 ]
%79 = add nuw nsw i64 %34, 1
%80 = icmp eq i64 %79, %21
br i1 %80, label %81, label %33
81: ; preds = %75, %23
%82 = phi double [ %27, %23 ], [ %76, %75 ]
%83 = phi double [ %26, %23 ], [ %77, %75 ]
%84 = phi double [ %25, %23 ], [ %78, %75 ]
%85 = add nuw nsw i64 %24, 1
%86 = icmp eq i64 %85, %20
br i1 %86, label %87, label %23
87: ; preds = %81, %14
%88 = phi double [ 0.000000e+00, %14 ], [ %82, %81 ]
%89 = phi double [ 0.000000e+00, %14 ], [ %83, %81 ]
%90 = phi double [ 0.000000e+00, %14 ], [ %84, %81 ]
store double %90, double* %15
%91 = getelementptr inbounds double, double* %15, i64 1
store double %89, double* %91
%92 = getelementptr inbounds double, double* %15, i64 2
store double %88, double* %92
ret double* %15
}