#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 */
float corrc(float *, float, float *, double *, int);
float network_corr(float *templates, float *sum_square_template, int *moveouts,
                   float *data, double *csum_square_data, float *weights,
                   int n_samples_template, int n_samples_data, int n_stations,
                   int n_components) {
  int s, c, d, dd, t;
  int station_offset, component_offset;
  float cc, cc_sum = 0;
  for (s = 0; s < n_stations; s++) {
    station_offset = s * n_components;
    cc = 0;
    for (c = 0; c < n_components; c++) {
      component_offset = station_offset + c;
      if (weights[component_offset] == 0)
        continue;
      t = component_offset * n_samples_template;
      d = component_offset * n_samples_data + moveouts[component_offset];
      dd = component_offset * (n_samples_data + 1) + moveouts[component_offset];
      cc = corrc(templates + t, sum_square_template[component_offset], data + d,
                 csum_square_data + dd, n_samples_template);
      cc_sum += cc * weights[component_offset];
    }
  }
  return cc_sum;
}


x86 assembly (clang, -O0):
<network_corr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    0x28(%rbp),%eax
mov    0x20(%rbp),%eax
mov    0x18(%rbp),%eax
mov    0x10(%rbp),%eax
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    %r9,-0x30(%rbp)
xorps  %xmm0,%xmm0
movss  %xmm0,-0x54(%rbp)
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cmp    0x20(%rbp),%eax
jge    126e <network_corr+0x15e>
mov    -0x34(%rbp),%eax
imul   0x28(%rbp),%eax
mov    %eax,-0x48(%rbp)
xorps  %xmm0,%xmm0
movss  %xmm0,-0x50(%rbp)
movl   $0x0,-0x38(%rbp)
mov    -0x38(%rbp),%eax
cmp    0x28(%rbp),%eax
jge    125b <network_corr+0x14b>
mov    -0x48(%rbp),%eax
add    -0x38(%rbp),%eax
mov    %eax,-0x4c(%rbp)
mov    -0x30(%rbp),%rax
movslq -0x4c(%rbp),%rcx
movss  (%rax,%rcx,4),%xmm0
xorps  %xmm1,%xmm1
ucomiss %xmm1,%xmm0
jne    11a9 <network_corr+0x99>
jp     11a9 <network_corr+0x99>
jmp    124d <network_corr+0x13d>
mov    -0x4c(%rbp),%eax
imul   0x10(%rbp),%eax
mov    %eax,-0x44(%rbp)
mov    -0x4c(%rbp),%eax
imul   0x18(%rbp),%eax
mov    -0x18(%rbp),%rcx
movslq -0x4c(%rbp),%rdx
add    (%rcx,%rdx,4),%eax
mov    %eax,-0x3c(%rbp)
mov    -0x4c(%rbp),%eax
mov    0x18(%rbp),%ecx
add    $0x1,%ecx
imul   %ecx,%eax
mov    -0x18(%rbp),%rcx
movslq -0x4c(%rbp),%rdx
add    (%rcx,%rdx,4),%eax
mov    %eax,-0x40(%rbp)
mov    -0x8(%rbp),%rdi
movslq -0x44(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rdi
mov    -0x10(%rbp),%rax
movslq -0x4c(%rbp),%rcx
movss  (%rax,%rcx,4),%xmm0
mov    -0x20(%rbp),%rsi
movslq -0x3c(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rsi
mov    -0x28(%rbp),%rdx
movslq -0x40(%rbp),%rax
shl    $0x3,%rax
add    %rax,%rdx
mov    0x10(%rbp),%ecx
call   1030 <corrc@plt>
movss  %xmm0,-0x50(%rbp)
movss  -0x50(%rbp),%xmm0
mov    -0x30(%rbp),%rax
movslq -0x4c(%rbp),%rcx
movss  (%rax,%rcx,4),%xmm2
movss  -0x54(%rbp),%xmm1
mulss  %xmm2,%xmm0
addss  %xmm1,%xmm0
movss  %xmm0,-0x54(%rbp)
mov    -0x38(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x38(%rbp)
jmp    1170 <network_corr+0x60>
jmp    1260 <network_corr+0x150>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    114b <network_corr+0x3b>
movss  -0x54(%rbp),%xmm0
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<network_corr>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x88,%rsp
mov    %r8,0x80(%rsp)
mov    %rcx,0x78(%rsp)
mov    %rdx,0x10(%rsp)
mov    %rsi,0x8(%rsp)
mov    0xd0(%rsp),%eax
test   %eax,%eax
jle    12d5 <network_corr+0x1c5>
mov    0xc8(%rsp),%ecx
lea    0x1(%rcx),%edx
movslq %edx,%rdx
movslq %ecx,%rcx
movslq 0xc0(%rsp),%r13
movslq 0xd8(%rsp),%rbp
mov    %eax,%eax
mov    %rax,0x30(%rsp)
mov    %ebp,%eax
lea    0x0(,%rbp,4),%rbx
mov    %rbx,0x28(%rsp)
mov    %rbp,%rbx
imul   %r13,%rbx
shl    $0x2,%rbx
mov    %rbx,0x20(%rsp)
shl    $0x2,%r13
mov    %rbp,%rbx
imul   %rcx,%rbx
mov    %rbx,0x18(%rsp)
imul   %rdx,%rbp
mov    %rbp,0x38(%rsp)
xorps  %xmm1,%xmm1
xor    %r14d,%r14d
xor    %r15d,%r15d
xor    %ebp,%ebp
xorps  %xmm2,%xmm2
mov    %rcx,0x70(%rsp)
mov    %rdx,0x68(%rsp)
mov    %rax,0x60(%rsp)
jmp    1214 <network_corr+0x104>
cs nopw 0x0(%rax,%rax,1)
nop
mov    0x40(%rsp),%rbp
add    $0x1,%rbp
mov    0x28(%rsp),%rdi
add    %rdi,%r9
add    %rdi,0x10(%rsp)
add    %rdi,0x8(%rsp)
mov    0x58(%rsp),%rdi
add    0x20(%rsp),%rdi
mov    0x48(%rsp),%r15
add    0x18(%rsp),%r15
mov    0x50(%rsp),%r14
add    0x38(%rsp),%r14
cmp    0x30(%rsp),%rbp
je     12d8 <network_corr+0x1c8>
cmpl   $0x0,0xd8(%rsp)
mov    %rdi,0x58(%rsp)
mov    %r14,0x50(%rsp)
mov    %r15,0x48(%rsp)
mov    %rbp,0x40(%rsp)
jle    11d0 <network_corr+0xc0>
mov    %rdi,%rbp
xor    %r12d,%r12d
jmp    1256 <network_corr+0x146>
nopw   0x0(%rax,%rax,1)
add    $0x1,%r12
add    %r13,%rbp
add    %rcx,%r15
add    %rdx,%r14
cmp    %r12,%rax
je     11d0 <network_corr+0xc0>
movss  (%r9,%r12,4),%xmm0
ucomiss %xmm1,%xmm0
jne    1263 <network_corr+0x153>
jnp    1240 <network_corr+0x130>
mov    0x10(%rsp),%rax
movslq (%rax,%r12,4),%rax
lea    (%r15,%rax,1),%rcx
add    %r14,%rax
mov    0x8(%rsp),%rdx
movss  (%rdx,%r12,4),%xmm0
mov    0x78(%rsp),%rdx
lea    (%rdx,%rcx,4),%rsi
mov    0x80(%rsp),%rcx
lea    (%rcx,%rax,8),%rdx
mov    %rbp,%rdi
mov    0xc0(%rsp),%ecx
mov    %r9,%rbx
movss  %xmm2,0x4(%rsp)
call   1030 <corrc@plt>
movss  0x4(%rsp),%xmm2
xorps  %xmm1,%xmm1
mov    0x60(%rsp),%rax
mov    %rbx,%r9
mov    0x70(%rsp),%rcx
mov    0x68(%rsp),%rdx
mulss  (%rbx,%r12,4),%xmm0
addss  %xmm0,%xmm2
jmp    1240 <network_corr+0x130>
xorps  %xmm2,%xmm2
movaps %xmm2,%xmm0
add    $0x88,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define float @network_corr(float* %0, float* %1, i32* %2, float* %3, double* %4, float* %5, i32 %6, i32 %7, i32 %8, i32 %9) {
%11 = alloca float*
%12 = alloca float*
%13 = alloca i32*
%14 = alloca float*
%15 = alloca double*
%16 = alloca float*
%17 = alloca i32
%18 = alloca i32
%19 = alloca i32
%20 = alloca i32
%21 = alloca i32
%22 = alloca i32
%23 = alloca i32
%24 = alloca i32
%25 = alloca i32
%26 = alloca i32
%27 = alloca i32
%28 = alloca float
%29 = alloca float
store float* %0, float** %11
store float* %1, float** %12
store i32* %2, i32** %13
store float* %3, float** %14
store double* %4, double** %15
store float* %5, float** %16
store i32 %6, i32* %17
store i32 %7, i32* %18
store i32 %8, i32* %19
store i32 %9, i32* %20
store float 0.000000e+00, float* %29
store i32 0, i32* %21
br label %30
30: ; preds = %107, %10
%31 = load i32, i32* %21
%32 = load i32, i32* %19
%33 = icmp slt i32 %31, %32
br i1 %33, label %34, label %110
34: ; preds = %30
%35 = load i32, i32* %21
%36 = load i32, i32* %20
%37 = mul nsw i32 %35, %36
store i32 %37, i32* %26
store float 0.000000e+00, float* %28
store i32 0, i32* %22
br label %38
38: ; preds = %103, %34
%39 = load i32, i32* %22
%40 = load i32, i32* %20
%41 = icmp slt i32 %39, %40
br i1 %41, label %42, label %106
42: ; preds = %38
%43 = load i32, i32* %26
%44 = load i32, i32* %22
%45 = add nsw i32 %43, %44
store i32 %45, i32* %27
%46 = load float*, float** %16
%47 = load i32, i32* %27
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds float, float* %46, i64 %48
%50 = load float, float* %49
%51 = fcmp oeq float %50, 0.000000e+00
br i1 %51, label %52, label %53
52: ; preds = %42
br label %103
53: ; preds = %42
%54 = load i32, i32* %27
%55 = load i32, i32* %17
%56 = mul nsw i32 %54, %55
store i32 %56, i32* %25
%57 = load i32, i32* %27
%58 = load i32, i32* %18
%59 = mul nsw i32 %57, %58
%60 = load i32*, i32** %13
%61 = load i32, i32* %27
%62 = sext i32 %61 to i64
%63 = getelementptr inbounds i32, i32* %60, i64 %62
%64 = load i32, i32* %63
%65 = add nsw i32 %59, %64
store i32 %65, i32* %23
%66 = load i32, i32* %27
%67 = load i32, i32* %18
%68 = add nsw i32 %67, 1
%69 = mul nsw i32 %66, %68
%70 = load i32*, i32** %13
%71 = load i32, i32* %27
%72 = sext i32 %71 to i64
%73 = getelementptr inbounds i32, i32* %70, i64 %72
%74 = load i32, i32* %73
%75 = add nsw i32 %69, %74
store i32 %75, i32* %24
%76 = load float*, float** %11
%77 = load i32, i32* %25
%78 = sext i32 %77 to i64
%79 = getelementptr inbounds float, float* %76, i64 %78
%80 = load float*, float** %12
%81 = load i32, i32* %27
%82 = sext i32 %81 to i64
%83 = getelementptr inbounds float, float* %80, i64 %82
%84 = load float, float* %83
%85 = load float*, float** %14
%86 = load i32, i32* %23
%87 = sext i32 %86 to i64
%88 = getelementptr inbounds float, float* %85, i64 %87
%89 = load double*, double** %15
%90 = load i32, i32* %24
%91 = sext i32 %90 to i64
%92 = getelementptr inbounds double, double* %89, i64 %91
%93 = load i32, i32* %17
%94 = call float @corrc(float* %79, float %84, float* %88, double* %92, i32 %93)
store float %94, float* %28
%95 = load float, float* %28
%96 = load float*, float** %16
%97 = load i32, i32* %27
%98 = sext i32 %97 to i64
%99 = getelementptr inbounds float, float* %96, i64 %98
%100 = load float, float* %99
%101 = load float, float* %29
%102 = call float @llvm.fmuladd.f32(float %95, float %100, float %101)
store float %102, float* %29
br label %103
103: ; preds = %53, %52
%104 = load i32, i32* %22
%105 = add nsw i32 %104, 1
store i32 %105, i32* %22
br label %38
106: ; preds = %38
br label %107
107: ; preds = %106
%108 = load i32, i32* %21
%109 = add nsw i32 %108, 1
store i32 %109, i32* %21
br label %30
110: ; preds = %30
%111 = load float, float* %29
ret float %111
}

LLVM IR (-O2):
define float @network_corr(float* %0, float* nocapture %1, i32* nocapture %2, float* %3, double* %4, float* nocapture %5, i32 %6, i32 %7, i32 %8, i32 %9) {
%11 = icmp sgt i32 %8, 0
br i1 %11, label %12, label %57
12: ; preds = %10
%13 = icmp sgt i32 %9, 0
%14 = add nsw i32 %7, 1
%15 = sext i32 %14 to i64
%16 = sext i32 %7 to i64
%17 = sext i32 %6 to i64
%18 = sext i32 %9 to i64
%19 = zext i32 %8 to i64
%20 = zext i32 %9 to i64
br label %21
21: ; preds = %12, %53
%22 = phi i64 [ 0, %12 ], [ %55, %53 ]
%23 = phi float [ 0.000000e+00, %12 ], [ %54, %53 ]
%24 = mul nsw i64 %22, %18
br i1 %13, label %25, label %53
25: ; preds = %21, %49
%26 = phi i64 [ %51, %49 ], [ 0, %21 ]
%27 = phi float [ %50, %49 ], [ %23, %21 ]
%28 = add nsw i64 %26, %24
%29 = getelementptr inbounds float, float* %5, i64 %28
%30 = load float, float* %29
%31 = fcmp oeq float %30, 0.000000e+00
br i1 %31, label %49, label %32
32: ; preds = %25
%33 = mul nsw i64 %28, %17
%34 = mul nsw i64 %28, %16
%35 = getelementptr inbounds i32, i32* %2, i64 %28
%36 = load i32, i32* %35
%37 = sext i32 %36 to i64
%38 = add nsw i64 %34, %37
%39 = mul nsw i64 %28, %15
%40 = add nsw i64 %39, %37
%41 = getelementptr inbounds float, float* %0, i64 %33
%42 = getelementptr inbounds float, float* %1, i64 %28
%43 = load float, float* %42
%44 = getelementptr inbounds float, float* %3, i64 %38
%45 = getelementptr inbounds double, double* %4, i64 %40
%46 = tail call float @corrc(float* %41, float %43, float* %44, double* %45, i32 %6)
%47 = load float, float* %29
%48 = tail call float @llvm.fmuladd.f32(float %46, float %47, float %27)
br label %49
49: ; preds = %25, %32
%50 = phi float [ %27, %25 ], [ %48, %32 ]
%51 = add nuw nsw i64 %26, 1
%52 = icmp eq i64 %51, %20
br i1 %52, label %53, label %25
53: ; preds = %49, %21
%54 = phi float [ %23, %21 ], [ %50, %49 ]
%55 = add nuw nsw i64 %22, 1
%56 = icmp eq i64 %55, %19
br i1 %56, label %57, label %21
57: ; preds = %53, %10
%58 = phi float [ 0.000000e+00, %10 ], [ %54, %53 ]
ret float %58
}