#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 gsw_alpha(double, double, double);
double gsw_beta(double, double, double);
void gsw_ipv_vs_fnsquared_ratio(double *sa, double *ct, double *p, int nz,
                                double *ipv_vs_fnsquared_ratio, double *p_mid) {
  int k;
  double dsa, sa_mid, dct, ct_mid, dp, p_ref;
  double alpha_mid, beta_mid;
  double alpha_pref, beta_pref, numerator, denominator;
  for (k = 0; k < nz - 1; k++) {
    dsa = (sa[k + 1] - sa[k]);
    sa_mid = 0.5 * (sa[k] + sa[k + 1]);
    dct = (ct[k + 1] - ct[k]);
    ct_mid = 0.5 * (ct[k] + ct[k + 1]);
    dp = (p[k + 1] - p[k]);
    p_mid[k] = 0.5 * (p[k] + p[k + 1]);
    alpha_mid = gsw_alpha(sa_mid, ct_mid, p_mid[k]);
    beta_mid = gsw_beta(sa_mid, ct_mid, p_mid[k]);
    alpha_pref = gsw_alpha(sa_mid, ct_mid, p_ref);
    beta_pref = gsw_beta(sa_mid, ct_mid, p_ref);
    numerator = dct * alpha_pref - dsa * beta_pref;
    denominator = dct * alpha_mid - dsa * beta_mid;
    if (denominator == 0)
      ipv_vs_fnsquared_ratio[k] = 9e15;
    else
      ipv_vs_fnsquared_ratio[k] = numerator / denominator;
  }
}


x86 assembly (clang, -O0):
<gsw_ipv_vs_fnsquared_ratio>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    %r8,-0x28(%rbp)
mov    %r9,-0x30(%rbp)
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%eax
mov    -0x1c(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    13b3 <gsw_ipv_vs_fnsquared_ratio+0x293>
mov    -0x8(%rbp),%rax
mov    -0x34(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x8(%rbp),%rax
movslq -0x34(%rbp),%rcx
subsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x40(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x34(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm1
mov    -0x8(%rbp),%rax
mov    -0x34(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
addsd  (%rax,%rcx,8),%xmm1
movsd  0xe5b(%rip),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x48(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x34(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x10(%rbp),%rax
movslq -0x34(%rbp),%rcx
subsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x50(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x34(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm1
mov    -0x10(%rbp),%rax
mov    -0x34(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
addsd  (%rax,%rcx,8),%xmm1
movsd  0xe07(%rip),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x58(%rbp)
mov    -0x18(%rbp),%rax
mov    -0x34(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x18(%rbp),%rax
movslq -0x34(%rbp),%rcx
subsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x60(%rbp)
mov    -0x18(%rbp),%rax
movslq -0x34(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm1
mov    -0x18(%rbp),%rax
mov    -0x34(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
addsd  (%rax,%rcx,8),%xmm1
movsd  0xdb3(%rip),%xmm0
mulsd  %xmm1,%xmm0
mov    -0x30(%rbp),%rax
movslq -0x34(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
movsd  -0x48(%rbp),%xmm0
movsd  -0x58(%rbp),%xmm1
mov    -0x30(%rbp),%rax
movslq -0x34(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm2
call   1040 <gsw_alpha@plt>
movsd  %xmm0,-0x70(%rbp)
movsd  -0x48(%rbp),%xmm0
movsd  -0x58(%rbp),%xmm1
mov    -0x30(%rbp),%rax
movslq -0x34(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm2
call   1030 <gsw_beta@plt>
movsd  %xmm0,-0x78(%rbp)
movsd  -0x48(%rbp),%xmm0
movsd  -0x58(%rbp),%xmm1
movsd  -0x68(%rbp),%xmm2
call   1040 <gsw_alpha@plt>
movsd  %xmm0,-0x80(%rbp)
movsd  -0x48(%rbp),%xmm0
movsd  -0x58(%rbp),%xmm1
movsd  -0x68(%rbp),%xmm2
call   1030 <gsw_beta@plt>
movsd  %xmm0,-0x88(%rbp)
ff
movsd  -0x50(%rbp),%xmm0
movsd  -0x80(%rbp),%xmm2
movsd  -0x40(%rbp),%xmm1
mulsd  -0x88(%rbp),%xmm1
ff
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x90(%rbp)
ff
movsd  -0x50(%rbp),%xmm0
movsd  -0x70(%rbp),%xmm2
movsd  -0x40(%rbp),%xmm1
mulsd  -0x78(%rbp),%xmm1
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x98(%rbp)
ff
movsd  -0x98(%rbp),%xmm0
ff
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    1383 <gsw_ipv_vs_fnsquared_ratio+0x263>
jp     1383 <gsw_ipv_vs_fnsquared_ratio+0x263>
mov    -0x28(%rbp),%rax
movslq -0x34(%rbp),%rcx
movsd  0xc8f(%rip),%xmm0
movsd  %xmm0,(%rax,%rcx,8)
jmp    13a0 <gsw_ipv_vs_fnsquared_ratio+0x280>
movsd  -0x90(%rbp),%xmm0
ff
divsd  -0x98(%rbp),%xmm0
ff
mov    -0x28(%rbp),%rax
movslq -0x34(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
jmp    13a5 <gsw_ipv_vs_fnsquared_ratio+0x285>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    1149 <gsw_ipv_vs_fnsquared_ratio+0x29>
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gsw_ipv_vs_fnsquared_ratio>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x58,%rsp
mov    %r8,0x18(%rsp)
mov    %rcx,(%rsp)
cmp    $0x2,%ecx
jl     12a6 <gsw_ipv_vs_fnsquared_ratio+0x186>
mov    %r9,%r12
mov    %rdx,%r13
mov    %rsi,%rbx
mov    %rdi,%rbp
mov    (%rsp),%rax
add    $0xffffffff,%eax
mov    %rax,(%rsp)
xor    %r14d,%r14d
jmp    1178 <gsw_ipv_vs_fnsquared_ratio+0x58>
nopl   0x0(%rax)
mov    0x18(%rsp),%rax
movsd  %xmm1,(%rax,%r14,8)
mov    %r15,%r14
cmp    %r15,(%rsp)
je     12a6 <gsw_ipv_vs_fnsquared_ratio+0x186>
lea    0x1(%r14),%r15
movsd  0x0(%rbp,%r14,8),%xmm0
movsd  0x8(%rbp,%r14,8),%xmm2
movapd %xmm2,%xmm1
subsd  %xmm0,%xmm1
movapd %xmm1,0x40(%rsp)
addsd  %xmm0,%xmm2
movsd  0xe5c(%rip),%xmm1
mulsd  %xmm1,%xmm2
movapd %xmm2,%xmm0
movsd  %xmm2,0x10(%rsp)
movsd  (%rbx,%r14,8),%xmm2
movsd  0x8(%rbx,%r14,8),%xmm4
movapd %xmm4,%xmm3
subsd  %xmm2,%xmm3
movsd  %xmm3,0x38(%rsp)
addsd  %xmm2,%xmm4
mulsd  %xmm1,%xmm4
movsd  %xmm4,0x8(%rsp)
movsd  0x8(%r13,%r14,8),%xmm2
addsd  0x0(%r13,%r14,8),%xmm2
mulsd  %xmm1,%xmm2
movsd  %xmm2,(%r12,%r14,8)
movapd %xmm4,%xmm1
call   1040 <gsw_alpha@plt>
movsd  %xmm0,0x30(%rsp)
movsd  (%r12,%r14,8),%xmm2
movsd  0x10(%rsp),%xmm0
movsd  0x8(%rsp),%xmm1
call   1030 <gsw_beta@plt>
movsd  %xmm0,0x28(%rsp)
movsd  0x10(%rsp),%xmm0
movsd  0x8(%rsp),%xmm1
call   1040 <gsw_alpha@plt>
movsd  %xmm0,0x20(%rsp)
movsd  0x10(%rsp),%xmm0
movsd  0x8(%rsp),%xmm1
call   1030 <gsw_beta@plt>
movsd  0x30(%rsp),%xmm4
movsd  0x38(%rsp),%xmm3
movapd 0x40(%rsp),%xmm2
movsd  0x28(%rsp),%xmm1
mulsd  %xmm2,%xmm1
mulsd  %xmm3,%xmm4
subsd  %xmm1,%xmm4
ucomisd 0xd9d(%rip),%xmm4
movsd  0xd8d(%rip),%xmm1
jne    1283 <gsw_ipv_vs_fnsquared_ratio+0x163>
jnp    1160 <gsw_ipv_vs_fnsquared_ratio+0x40>
xorpd  0xd95(%rip),%xmm2
mulsd  %xmm2,%xmm0
mulsd  0x20(%rsp),%xmm3
addsd  %xmm0,%xmm3
divsd  %xmm4,%xmm3
movapd %xmm3,%xmm1
jmp    1160 <gsw_ipv_vs_fnsquared_ratio+0x40>
add    $0x58,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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