#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 */
int atan2(double, double);
double gsw_alpha(double, double, double);
double gsw_beta(double, double, double);
void gsw_turner_rsubrho(double *sa, double *ct, double *p, int nz, double *tu,
                        double *rsubrho, double *p_mid) {
  int k;
  double pi = 3.141592653589793e0;
  double dsa, sa_mid, dct, ct_mid, dp;
  double alpha_mid, beta_mid;
  for (k = 0; k < nz - 1; k++) {
    dsa = (sa[k] - sa[k + 1]);
    sa_mid = 0.5e0 * (sa[k] + sa[k + 1]);
    dct = (ct[k] - ct[k + 1]);
    ct_mid = 0.5e0 * (ct[k] + ct[k + 1]);
    dp = (p[k] - p[k + 1]);
    p_mid[k] = 0.5e0 * (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]);
    tu[k] = (180e0 / pi) * atan2((alpha_mid * dct + beta_mid * dsa),
                                 (alpha_mid * dct - beta_mid * dsa));
    if (dsa == 0e0)
      rsubrho[k] = 9e15;
    else
      rsubrho[k] = (alpha_mid * dct) / (beta_mid * dsa);
  }
}


x86 assembly (clang, -O0):
<gsw_turner_rsubrho>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    0x10(%rbp),%rax
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    %r8,-0x28(%rbp)
mov    %r9,-0x30(%rbp)
movsd  0xea2(%rip),%xmm0
movsd  %xmm0,-0x40(%rbp)
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%eax
mov    -0x1c(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    13ab <gsw_turner_rsubrho+0x27b>
mov    -0x8(%rbp),%rax
movslq -0x34(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x8(%rbp),%rax
mov    -0x34(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
subsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x48(%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  0xe4a(%rip),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x50(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x34(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x10(%rbp),%rax
mov    -0x34(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
subsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x58(%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  0xdf6(%rip),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x60(%rbp)
mov    -0x18(%rbp),%rax
movslq -0x34(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x18(%rbp),%rax
mov    -0x34(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
subsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x68(%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  0xda2(%rip),%xmm0
mulsd  %xmm1,%xmm0
mov    0x10(%rbp),%rax
movslq -0x34(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
movsd  -0x50(%rbp),%xmm0
movsd  -0x60(%rbp),%xmm1
mov    0x10(%rbp),%rax
movslq -0x34(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm2
call   1050 <gsw_alpha@plt>
movsd  %xmm0,-0x70(%rbp)
movsd  -0x50(%rbp),%xmm0
movsd  -0x60(%rbp),%xmm1
mov    0x10(%rbp),%rax
movslq -0x34(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm2
call   1040 <gsw_beta@plt>
movsd  %xmm0,-0x78(%rbp)
movsd  0xd3f(%rip),%xmm0
divsd  -0x40(%rbp),%xmm0
movsd  %xmm0,-0x80(%rbp)
movsd  -0x70(%rbp),%xmm0
movsd  -0x58(%rbp),%xmm2
movsd  -0x78(%rbp),%xmm1
mulsd  -0x48(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  -0x70(%rbp),%xmm1
movsd  -0x58(%rbp),%xmm3
movsd  -0x78(%rbp),%xmm2
mulsd  -0x48(%rbp),%xmm2
movq   %xmm2,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm2
mulsd  %xmm3,%xmm1
addsd  %xmm2,%xmm1
call   1030 <atan2@plt>
movsd  -0x80(%rbp),%xmm0
cvtsi2sd %eax,%xmm1
mulsd  %xmm1,%xmm0
mov    -0x28(%rbp),%rax
movslq -0x34(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
movsd  -0x48(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    1373 <gsw_turner_rsubrho+0x243>
jp     1373 <gsw_turner_rsubrho+0x243>
mov    -0x30(%rbp),%rax
movslq -0x34(%rbp),%rcx
movsd  0xcaf(%rip),%xmm0
movsd  %xmm0,(%rax,%rcx,8)
jmp    1398 <gsw_turner_rsubrho+0x268>
movsd  -0x70(%rbp),%xmm0
mulsd  -0x58(%rbp),%xmm0
movsd  -0x78(%rbp),%xmm1
mulsd  -0x48(%rbp),%xmm1
divsd  %xmm1,%xmm0
mov    -0x30(%rbp),%rax
movslq -0x34(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
jmp    139d <gsw_turner_rsubrho+0x26d>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    116a <gsw_turner_rsubrho+0x3a>
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gsw_turner_rsubrho>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x48,%rsp
mov    %r9,0x30(%rsp)
mov    %r8,0x28(%rsp)
mov    %rcx,0x8(%rsp)
cmp    $0x2,%ecx
jl     12be <gsw_turner_rsubrho+0x18e>
mov    %rdx,%r13
mov    %rsi,%rbx
mov    %rdi,%rbp
mov    0x8(%rsp),%rax
add    $0xffffffff,%eax
mov    %rax,0x8(%rsp)
xor    %r15d,%r15d
jmp    1199 <gsw_turner_rsubrho+0x69>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    0x30(%rsp),%rax
movsd  %xmm0,(%rax,%r15,8)
mov    %r14,%r15
cmp    %r14,0x8(%rsp)
je     12be <gsw_turner_rsubrho+0x18e>
lea    0x1(%r15),%r14
movsd  0x0(%rbp,%r15,8),%xmm2
movsd  0x8(%rbp,%r15,8),%xmm0
movapd %xmm2,%xmm1
subsd  %xmm0,%xmm1
movsd  %xmm1,0x20(%rsp)
addsd  %xmm0,%xmm2
movsd  0xe3b(%rip),%xmm1
mulsd  %xmm1,%xmm2
movapd %xmm2,%xmm0
movsd  %xmm2,0x40(%rsp)
movsd  (%rbx,%r15,8),%xmm3
movsd  0x8(%rbx,%r15,8),%xmm4
movapd %xmm3,%xmm2
subsd  %xmm4,%xmm2
movsd  %xmm2,0x10(%rsp)
addsd  %xmm4,%xmm3
mulsd  %xmm1,%xmm3
movsd  %xmm3,0x38(%rsp)
movsd  0x0(%r13,%r15,8),%xmm2
addsd  0x8(%r13,%r15,8),%xmm2
mulsd  %xmm1,%xmm2
mov    0x80(%rsp),%r12
movsd  %xmm2,(%r12,%r15,8)
movapd %xmm3,%xmm1
call   1050 <gsw_alpha@plt>
movsd  %xmm0,0x18(%rsp)
movsd  (%r12,%r15,8),%xmm2
movsd  0x40(%rsp),%xmm0
movsd  0x38(%rsp),%xmm1
call   1040 <gsw_beta@plt>
movapd %xmm0,%xmm2
mulsd  0x20(%rsp),%xmm2
movsd  0x18(%rsp),%xmm1
mulsd  0x10(%rsp),%xmm1
movapd %xmm1,%xmm0
addsd  %xmm2,%xmm0
movsd  %xmm1,0x18(%rsp)
movsd  %xmm2,0x10(%rsp)
subsd  %xmm2,%xmm1
call   1030 <atan2@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
mulsd  0xd84(%rip),%xmm0
mov    0x28(%rsp),%rax
movsd  %xmm0,(%rax,%r15,8)
movsd  0x20(%rsp),%xmm0
ucomisd 0xd7b(%rip),%xmm0
movsd  0xd6b(%rip),%xmm0
jne    12ad <gsw_turner_rsubrho+0x17d>
jnp    1180 <gsw_turner_rsubrho+0x50>
movsd  0x18(%rsp),%xmm0
divsd  0x10(%rsp),%xmm0
jmp    1180 <gsw_turner_rsubrho+0x50>
add    $0x48,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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