#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_precise(float *, float, float *, int, int);
float network_corr_precise(float *templates, float *sum_square_template,
                           int *moveouts, float *data, float *weights,
                           int n_samples_template, int n_samples_data,
                           int n_stations, int n_components, int normalize) {
  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_precise(templates + t, sum_square_template[component_offset],
                         data + d, n_samples_template, normalize);
      cc_sum += cc * weights[component_offset];
    }
  }
  return cc_sum;
}


x86 assembly (clang, -O0):
<network_corr_precise>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%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    %r9d,-0x2c(%rbp)
xorps  %xmm0,%xmm0
movss  %xmm0,-0x50(%rbp)
movl   $0x0,-0x30(%rbp)
mov    -0x30(%rbp),%eax
cmp    0x18(%rbp),%eax
jge    1262 <network_corr_precise+0x152>
mov    -0x30(%rbp),%eax
imul   0x20(%rbp),%eax
mov    %eax,-0x44(%rbp)
xorps  %xmm0,%xmm0
movss  %xmm0,-0x4c(%rbp)
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cmp    0x20(%rbp),%eax
jge    124f <network_corr_precise+0x13f>
mov    -0x44(%rbp),%eax
add    -0x34(%rbp),%eax
mov    %eax,-0x48(%rbp)
mov    -0x28(%rbp),%rax
movslq -0x48(%rbp),%rcx
movss  (%rax,%rcx,4),%xmm0
xorps  %xmm1,%xmm1
ucomiss %xmm1,%xmm0
jne    11a9 <network_corr_precise+0x99>
jp     11a9 <network_corr_precise+0x99>
jmp    1241 <network_corr_precise+0x131>
mov    -0x48(%rbp),%eax
imul   -0x2c(%rbp),%eax
mov    %eax,-0x40(%rbp)
mov    -0x48(%rbp),%eax
imul   0x10(%rbp),%eax
mov    -0x18(%rbp),%rcx
movslq -0x48(%rbp),%rdx
add    (%rcx,%rdx,4),%eax
mov    %eax,-0x38(%rbp)
mov    -0x48(%rbp),%eax
mov    0x10(%rbp),%ecx
add    $0x1,%ecx
imul   %ecx,%eax
mov    -0x18(%rbp),%rcx
movslq -0x48(%rbp),%rdx
add    (%rcx,%rdx,4),%eax
mov    %eax,-0x3c(%rbp)
mov    -0x8(%rbp),%rdi
movslq -0x40(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rdi
mov    -0x10(%rbp),%rax
movslq -0x48(%rbp),%rcx
movss  (%rax,%rcx,4),%xmm0
mov    -0x20(%rbp),%rsi
movslq -0x38(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rsi
mov    -0x2c(%rbp),%edx
mov    0x28(%rbp),%ecx
call   1030 <corrc_precise@plt>
movss  %xmm0,-0x4c(%rbp)
movss  -0x4c(%rbp),%xmm0
mov    -0x28(%rbp),%rax
movslq -0x48(%rbp),%rcx
movss  (%rax,%rcx,4),%xmm2
movss  -0x50(%rbp),%xmm1
mulss  %xmm2,%xmm0
addss  %xmm1,%xmm0
movss  %xmm0,-0x50(%rbp)
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    1170 <network_corr_precise+0x60>
jmp    1254 <network_corr_precise+0x144>
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    114b <network_corr_precise+0x3b>
movss  -0x50(%rbp),%xmm0
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<network_corr_precise>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x68,%rsp
mov    %rcx,0x60(%rsp)
mov    %rdx,0x10(%rsp)
mov    %rsi,0x8(%rsp)
mov    0xa8(%rsp),%eax
test   %eax,%eax
jle    1289 <network_corr_precise+0x179>
mov    %r9d,%r15d
mov    %r8,%r12
mov    %rdi,%r13
movslq 0xa0(%rsp),%rcx
movslq %r9d,%rdx
movslq 0xb0(%rsp),%rsi
mov    %eax,%eax
mov    %rax,0x28(%rsp)
mov    %esi,%eax
lea    0x0(,%rsi,4),%rbp
mov    %rbp,0x20(%rsp)
mov    %rsi,%rbp
imul   %rdx,%rbp
shl    $0x2,%rbp
mov    %rbp,0x18(%rsp)
shl    $0x2,%rdx
imul   %rcx,%rsi
mov    %rsi,0x30(%rsp)
xorps  %xmm1,%xmm1
xor    %ebp,%ebp
xor    %ebx,%ebx
xorps  %xmm2,%xmm2
mov    %rcx,0x58(%rsp)
mov    %rax,0x50(%rsp)
jmp    11ea <network_corr_precise+0xda>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    0x38(%rsp),%rbx
add    $0x1,%rbx
mov    0x20(%rsp),%rsi
add    %rsi,%r12
add    %rsi,0x10(%rsp)
add    %rsi,0x8(%rsp)
mov    0x48(%rsp),%r13
add    0x18(%rsp),%r13
mov    0x40(%rsp),%rbp
add    0x30(%rsp),%rbp
cmp    0x28(%rsp),%rbx
je     128c <network_corr_precise+0x17c>
cmpl   $0x0,0xb0(%rsp)
mov    %r13,0x48(%rsp)
mov    %rbp,0x40(%rsp)
mov    %rbx,0x38(%rsp)
jle    11b0 <network_corr_precise+0xa0>
xor    %r14d,%r14d
jmp    121f <network_corr_precise+0x10f>
nopl   0x0(%rax,%rax,1)
add    $0x1,%r14
add    %rdx,%r13
add    %rcx,%rbp
cmp    %r14,%rax
je     11b0 <network_corr_precise+0xa0>
movss  (%r12,%r14,4),%xmm0
ucomiss %xmm1,%xmm0
jne    122c <network_corr_precise+0x11c>
jnp    1210 <network_corr_precise+0x100>
mov    0x10(%rsp),%rax
movslq (%rax,%r14,4),%rax
add    %rbp,%rax
mov    0x8(%rsp),%rcx
movss  (%rcx,%r14,4),%xmm0
mov    0x60(%rsp),%rcx
lea    (%rcx,%rax,4),%rsi
mov    %r13,%rdi
mov    %rdx,%rbx
mov    %r15d,%edx
mov    0xb8(%rsp),%ecx
movss  %xmm2,0x4(%rsp)
call   1030 <corrc_precise@plt>
movss  0x4(%rsp),%xmm2
xorps  %xmm1,%xmm1
mov    0x50(%rsp),%rax
mov    %rbx,%rdx
mov    0x58(%rsp),%rcx
mulss  (%r12,%r14,4),%xmm0
addss  %xmm0,%xmm2
jmp    1210 <network_corr_precise+0x100>
xorps  %xmm2,%xmm2
movaps %xmm2,%xmm0
add    $0x68,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define float @network_corr_precise(float* %0, float* %1, i32* %2, float* %3, float* %4, i32 %5, i32 %6, i32 %7, i32 %8, i32 %9) {
%11 = alloca float*
%12 = alloca float*
%13 = alloca i32*
%14 = alloca float*
%15 = alloca float*
%16 = alloca i32
%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 float* %4, float** %15
store i32 %5, i32* %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 = %104, %10
%31 = load i32, i32* %21
%32 = load i32, i32* %18
%33 = icmp slt i32 %31, %32
br i1 %33, label %34, label %107
34: ; preds = %30
%35 = load i32, i32* %21
%36 = load i32, i32* %19
%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 = %100, %34
%39 = load i32, i32* %22
%40 = load i32, i32* %19
%41 = icmp slt i32 %39, %40
br i1 %41, label %42, label %103
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** %15
%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 %100
53: ; preds = %42
%54 = load i32, i32* %27
%55 = load i32, i32* %16
%56 = mul nsw i32 %54, %55
store i32 %56, i32* %25
%57 = load i32, i32* %27
%58 = load i32, i32* %17
%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* %17
%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 i32, i32* %16
%90 = load i32, i32* %20
%91 = call float @corrc_precise(float* %79, float %84, float* %88, i32 %89, i32 %90)
store float %91, float* %28
%92 = load float, float* %28
%93 = load float*, float** %15
%94 = load i32, i32* %27
%95 = sext i32 %94 to i64
%96 = getelementptr inbounds float, float* %93, i64 %95
%97 = load float, float* %96
%98 = load float, float* %29
%99 = call float @llvm.fmuladd.f32(float %92, float %97, float %98)
store float %99, float* %29
br label %100
100: ; preds = %53, %52
%101 = load i32, i32* %22
%102 = add nsw i32 %101, 1
store i32 %102, i32* %22
br label %38
103: ; preds = %38
br label %104
104: ; preds = %103
%105 = load i32, i32* %21
%106 = add nsw i32 %105, 1
store i32 %106, i32* %21
br label %30
107: ; preds = %30
%108 = load float, float* %29
ret float %108
}

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