#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 calc_density(double);
void colavg(double *finaltemp, double *T, double *Ti, float lakeprv,
            double *density, int numnod, double dz, double surfdz) {
  int j;
  double water_densityw, water_densityi;
  double temp;
  float z;
  for (j = 0; j < numnod; j++) {
    water_densityw = calc_density(T[j]);
    water_densityi = calc_density(Ti[j]);
    water_densityw = water_densityw + 1000.;
    water_densityi = water_densityi + 1000.;
    z = dz;
    if (j == 0)
      z = surfdz;
    temp = ((1. - lakeprv) * T[j] * z * water_densityw +
            lakeprv * Ti[j] * z * water_densityi) /
           ((1. - lakeprv) * z * water_densityw + lakeprv * z * water_densityi);
    finaltemp[j] = temp;
    density[j] = calc_density(finaltemp[j]);
  }
}


x86 assembly (clang, -O0):
<colavg>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movss  %xmm0,-0x1c(%rbp)
mov    %rcx,-0x28(%rbp)
mov    %r8d,-0x2c(%rbp)
movsd  %xmm1,-0x38(%rbp)
movsd  %xmm2,-0x40(%rbp)
movl   $0x0,-0x44(%rbp)
mov    -0x44(%rbp),%eax
cmp    -0x2c(%rbp),%eax
jge    12b4 <colavg+0x1a4>
mov    -0x10(%rbp),%rax
movslq -0x44(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
call   1030 <calc_density@plt>
movsd  %xmm0,-0x50(%rbp)
mov    -0x18(%rbp),%rax
movslq -0x44(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
call   1030 <calc_density@plt>
movsd  %xmm0,-0x58(%rbp)
movsd  0xe7c(%rip),%xmm0
addsd  -0x50(%rbp),%xmm0
movsd  %xmm0,-0x50(%rbp)
movsd  0xe6a(%rip),%xmm0
addsd  -0x58(%rbp),%xmm0
movsd  %xmm0,-0x58(%rbp)
movsd  -0x38(%rbp),%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x64(%rbp)
cmpl   $0x0,-0x44(%rbp)
jne    11c6 <colavg+0xb6>
movsd  -0x40(%rbp),%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x64(%rbp)
movss  -0x1c(%rbp),%xmm0
cvtss2sd %xmm0,%xmm1
movsd  0xe31(%rip),%xmm0
subsd  %xmm1,%xmm0
mov    -0x10(%rbp),%rax
movslq -0x44(%rbp),%rcx
mulsd  (%rax,%rcx,8),%xmm0
movss  -0x64(%rbp),%xmm1
cvtss2sd %xmm1,%xmm1
mulsd  %xmm1,%xmm0
movsd  -0x50(%rbp),%xmm2
movss  -0x1c(%rbp),%xmm1
cvtss2sd %xmm1,%xmm1
mov    -0x18(%rbp),%rax
movslq -0x44(%rbp),%rcx
mulsd  (%rax,%rcx,8),%xmm1
movss  -0x64(%rbp),%xmm3
cvtss2sd %xmm3,%xmm3
mulsd  %xmm3,%xmm1
mulsd  -0x58(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movss  -0x1c(%rbp),%xmm1
cvtss2sd %xmm1,%xmm2
movsd  0xdcd(%rip),%xmm1
subsd  %xmm2,%xmm1
movss  -0x64(%rbp),%xmm2
cvtss2sd %xmm2,%xmm2
mulsd  %xmm2,%xmm1
movsd  -0x50(%rbp),%xmm3
movss  -0x1c(%rbp),%xmm2
mulss  -0x64(%rbp),%xmm2
cvtss2sd %xmm2,%xmm2
mulsd  -0x58(%rbp),%xmm2
mulsd  %xmm3,%xmm1
addsd  %xmm2,%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x60(%rbp)
movsd  -0x60(%rbp),%xmm0
mov    -0x8(%rbp),%rax
movslq -0x44(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x8(%rbp),%rax
movslq -0x44(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
call   1030 <calc_density@plt>
mov    -0x28(%rbp),%rax
movslq -0x44(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x44(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x44(%rbp)
jmp    1142 <colavg+0x32>
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<colavg>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
movsd  %xmm2,0x28(%rsp)
movsd  %xmm1,0x10(%rsp)
movss  %xmm0,0xc(%rsp)
test   %r8d,%r8d
jle    1244 <colavg+0x134>
mov    %rcx,%r14
mov    %rdx,%r15
mov    %rsi,%rbx
mov    %rdi,%r12
movss  0xc(%rsp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xea9(%rip),%xmm1
movsd  %xmm0,0x20(%rsp)
subsd  %xmm0,%xmm1
movsd  %xmm1,0x18(%rsp)
mov    %r8d,%r13d
xor    %ebp,%ebp
jmp    120f <colavg+0xff>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movsd  0xe80(%rip),%xmm2
movsd  0x30(%rsp),%xmm6
addsd  %xmm2,%xmm6
addsd  %xmm2,%xmm0
xorps  %xmm2,%xmm2
cvtsd2ss %xmm1,%xmm2
movsd  (%rbx,%rbp,8),%xmm1
movsd  0x18(%rsp),%xmm5
mulsd  %xmm5,%xmm1
xorps  %xmm3,%xmm3
cvtss2sd %xmm2,%xmm3
mulsd  %xmm3,%xmm1
movsd  (%r15,%rbp,8),%xmm4
mulsd  0x20(%rsp),%xmm4
mulsd  %xmm3,%xmm4
mulsd  %xmm0,%xmm4
mulsd  %xmm6,%xmm1
addsd  %xmm4,%xmm1
mulsd  %xmm5,%xmm3
mulss  0xc(%rsp),%xmm2
cvtss2sd %xmm2,%xmm2
mulsd  %xmm0,%xmm2
mulsd  %xmm6,%xmm3
addsd  %xmm2,%xmm3
divsd  %xmm3,%xmm1
movsd  %xmm1,(%r12,%rbp,8)
movapd %xmm1,%xmm0
call   1030 <calc_density@plt>
movsd  %xmm0,(%r14,%rbp,8)
add    $0x1,%rbp
cmp    %rbp,%r13
je     1244 <colavg+0x134>
movsd  (%rbx,%rbp,8),%xmm0
call   1030 <calc_density@plt>
movsd  %xmm0,0x30(%rsp)
movsd  (%r15,%rbp,8),%xmm0
call   1030 <calc_density@plt>
movsd  0x28(%rsp),%xmm1
test   %rbp,%rbp
je     1180 <colavg+0x70>
movsd  0x10(%rsp),%xmm1
jmp    1180 <colavg+0x70>
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define void @colavg(double* nocapture writeonly %0, double* nocapture %1, double* nocapture %2, float %3, double* nocapture writeonly %4, i32 %5, double %6, double %7) {
%9 = icmp sgt i32 %5, 0
br i1 %9, label %10, label %47
10: ; preds = %8
%11 = fpext float %3 to double
%12 = fsub double 1.000000e+00, %11
%13 = zext i32 %5 to i64
br label %14
14: ; preds = %10, %14
%15 = phi i64 [ 0, %10 ], [ %45, %14 ]
%16 = getelementptr inbounds double, double* %1, i64 %15
%17 = load double, double* %16
%18 = tail call double @calc_density(double %17)
%19 = getelementptr inbounds double, double* %2, i64 %15
%20 = load double, double* %19
%21 = tail call double @calc_density(double %20)
%22 = fadd double %18, 1.000000e+03
%23 = fadd double %21, 1.000000e+03
%24 = icmp eq i64 %15, 0
%25 = select i1 %24, double %7, double %6
%26 = fptrunc double %25 to float
%27 = load double, double* %16
%28 = fmul double %12, %27
%29 = fpext float %26 to double
%30 = fmul double %28, %29
%31 = load double, double* %19
%32 = fmul double %31, %11
%33 = fmul double %32, %29
%34 = fmul double %23, %33
%35 = tail call double @llvm.fmuladd.f64(double %30, double %22, double %34)
%36 = fmul double %12, %29
%37 = fmul float %26, %3
%38 = fpext float %37 to double
%39 = fmul double %23, %38
%40 = tail call double @llvm.fmuladd.f64(double %36, double %22, double %39)
%41 = fdiv double %35, %40
%42 = getelementptr inbounds double, double* %0, i64 %15
store double %41, double* %42
%43 = tail call double @calc_density(double %41)
%44 = getelementptr inbounds double, double* %4, i64 %15
store double %43, double* %44
%45 = add nuw nsw i64 %15, 1
%46 = icmp eq i64 %45, %13
br i1 %46, label %47, label %14
47: ; preds = %14, %8
ret void
}