#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);
double gsw_specvol(double, double, double);
double gsw_sa_from_rho(double rho, double ct, double p) {
  int no_iter;
  double sa, v_lab, v_0, v_50, v_sa, sa_old, delta_v, sa_mean, alpha, beta;
  v_lab = 1e0 / rho;
  v_0 = gsw_specvol(0e0, ct, p);
  v_50 = gsw_specvol(50e0, ct, p);
  sa = 50e0 * (v_lab - v_0) / (v_50 - v_0);
  if (sa < 0e0 || sa > 50e0)
    sa = 9e15;
  v_sa = (v_50 - v_0) / 50e0;
  for (no_iter = 1; no_iter <= 2; no_iter++) {
    sa_old = sa;
    delta_v = gsw_specvol(sa_old, ct, p) - v_lab;
    sa = sa_old - delta_v / v_sa;
    sa_mean = 0.5e0 * (sa + sa_old);
    alpha = gsw_alpha(sa_mean, ct, p);
    beta = gsw_beta(sa_mean, ct, p);
    v_sa = -beta / rho;
    sa = sa_old - delta_v / v_sa;
    if (sa < 0e0 || sa > 50e0)
      sa = 9e15;
  }
  return (sa);
}


x86 assembly (clang, -O0):
<gsw_sa_from_rho>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movsd  %xmm0,-0x8(%rbp)
movsd  %xmm1,-0x10(%rbp)
movsd  %xmm2,-0x18(%rbp)
movsd  0xeb9(%rip),%xmm0
divsd  -0x8(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x10(%rbp),%xmm1
movsd  -0x18(%rbp),%xmm2
xorps  %xmm0,%xmm0
call   1050 <gsw_specvol@plt>
movsd  %xmm0,-0x38(%rbp)
movsd  -0x10(%rbp),%xmm1
movsd  -0x18(%rbp),%xmm2
movsd  0xe7e(%rip),%xmm0
call   1050 <gsw_specvol@plt>
movsd  %xmm0,-0x40(%rbp)
movsd  -0x30(%rbp),%xmm1
subsd  -0x38(%rbp),%xmm1
movsd  0xe62(%rip),%xmm0
mulsd  %xmm1,%xmm0
movsd  -0x40(%rbp),%xmm1
subsd  -0x38(%rbp),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x28(%rbp),%xmm0
ja     11da <gsw_sa_from_rho+0xaa>
movsd  -0x28(%rbp),%xmm0
movsd  0xe30(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    11e7 <gsw_sa_from_rho+0xb7>
movsd  0xe2e(%rip),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x40(%rbp),%xmm0
subsd  -0x38(%rbp),%xmm0
movsd  0xe07(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x48(%rbp)
movl   $0x1,-0x1c(%rbp)
cmpl   $0x2,-0x1c(%rbp)
jg     1323 <gsw_sa_from_rho+0x1f3>
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x50(%rbp)
movsd  -0x50(%rbp),%xmm0
movsd  -0x10(%rbp),%xmm1
movsd  -0x18(%rbp),%xmm2
call   1050 <gsw_specvol@plt>
subsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x58(%rbp)
movsd  -0x50(%rbp),%xmm0
movsd  -0x58(%rbp),%xmm1
divsd  -0x48(%rbp),%xmm1
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm1
addsd  -0x50(%rbp),%xmm1
movsd  0xdb3(%rip),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x60(%rbp)
movsd  -0x60(%rbp),%xmm0
movsd  -0x10(%rbp),%xmm1
movsd  -0x18(%rbp),%xmm2
call   1040 <gsw_alpha@plt>
movsd  %xmm0,-0x68(%rbp)
movsd  -0x60(%rbp),%xmm0
movsd  -0x10(%rbp),%xmm1
movsd  -0x18(%rbp),%xmm2
call   1030 <gsw_beta@plt>
movsd  %xmm0,-0x70(%rbp)
movsd  -0x70(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
divsd  -0x8(%rbp),%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x50(%rbp),%xmm0
movsd  -0x58(%rbp),%xmm1
divsd  -0x48(%rbp),%xmm1
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x28(%rbp),%xmm0
ja     1303 <gsw_sa_from_rho+0x1d3>
movsd  -0x28(%rbp),%xmm0
movsd  0xd07(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    1310 <gsw_sa_from_rho+0x1e0>
movsd  0xd05(%rip),%xmm0
movsd  %xmm0,-0x28(%rbp)
jmp    1315 <gsw_sa_from_rho+0x1e5>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1209 <gsw_sa_from_rho+0xd9>
movsd  -0x28(%rbp),%xmm0
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gsw_sa_from_rho>:
sub    $0x58,%rsp
movsd  %xmm2,0x8(%rsp)
movsd  %xmm1,(%rsp)
movsd  %xmm0,0x48(%rsp)
movsd  0xeb3(%rip),%xmm3
divsd  %xmm0,%xmm3
movsd  %xmm3,0x30(%rsp)
xorpd  %xmm0,%xmm0
call   1050 <gsw_specvol@plt>
movsd  %xmm0,0x20(%rsp)
movsd  0xe9a(%rip),%xmm0
movsd  (%rsp),%xmm1
movsd  0x8(%rsp),%xmm2
call   1050 <gsw_specvol@plt>
movapd %xmm0,%xmm2
movsd  0x30(%rsp),%xmm0
movsd  0x20(%rsp),%xmm3
subsd  %xmm3,%xmm0
movsd  0xe6e(%rip),%xmm1
mulsd  %xmm1,%xmm0
subsd  %xmm3,%xmm2
divsd  %xmm2,%xmm0
movapd %xmm2,%xmm5
movapd %xmm1,%xmm3
movapd %xmm1,%xmm2
cmpltsd %xmm0,%xmm3
movapd %xmm3,%xmm1
andnpd %xmm0,%xmm1
movsd  0xe49(%rip),%xmm4
andpd  %xmm4,%xmm3
orpd   %xmm1,%xmm3
cmpltsd 0xe48(%rip),%xmm0
movapd %xmm0,%xmm1
andnpd %xmm3,%xmm1
andpd  %xmm4,%xmm0
orpd   %xmm1,%xmm0
movapd %xmm0,0x20(%rsp)
divsd  %xmm2,%xmm5
movsd  %xmm5,0x10(%rsp)
movsd  (%rsp),%xmm1
movsd  0x8(%rsp),%xmm2
call   1050 <gsw_specvol@plt>
subsd  0x30(%rsp),%xmm0
movsd  %xmm0,0x50(%rsp)
movapd %xmm0,%xmm2
divsd  0x10(%rsp),%xmm2
movapd 0x20(%rsp),%xmm1
movapd %xmm1,%xmm0
subsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
mulsd  0xde0(%rip),%xmm0
movapd %xmm0,0x10(%rsp)
movsd  (%rsp),%xmm1
movsd  0x8(%rsp),%xmm2
call   1040 <gsw_alpha@plt>
movapd 0x10(%rsp),%xmm0
movsd  (%rsp),%xmm1
movsd  0x8(%rsp),%xmm2
call   1030 <gsw_beta@plt>
xorpd  0xdc4(%rip),%xmm0
divsd  0x48(%rsp),%xmm0
movapd %xmm0,0x10(%rsp)
movsd  0x50(%rsp),%xmm1
divsd  %xmm0,%xmm1
movapd 0x20(%rsp),%xmm0
subsd  %xmm1,%xmm0
movsd  0xd74(%rip),%xmm3
cmpltsd %xmm0,%xmm3
movapd %xmm3,%xmm1
andnpd %xmm0,%xmm1
movsd  0xd67(%rip),%xmm2
andpd  %xmm2,%xmm3
orpd   %xmm1,%xmm3
cmpltsd 0xd66(%rip),%xmm0
movapd %xmm0,%xmm1
andnpd %xmm3,%xmm1
andpd  %xmm2,%xmm0
orpd   %xmm1,%xmm0
movapd %xmm0,0x20(%rsp)
movsd  (%rsp),%xmm1
movsd  0x8(%rsp),%xmm2
call   1050 <gsw_specvol@plt>
subsd  0x30(%rsp),%xmm0
movapd %xmm0,0x30(%rsp)
movapd %xmm0,%xmm2
divsd  0x10(%rsp),%xmm2
movapd 0x20(%rsp),%xmm1
movapd %xmm1,%xmm0
subsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
mulsd  0xd08(%rip),%xmm0
movapd %xmm0,0x10(%rsp)
movsd  (%rsp),%xmm1
movsd  0x8(%rsp),%xmm2
call   1040 <gsw_alpha@plt>
movapd 0x10(%rsp),%xmm0
movsd  (%rsp),%xmm1
movsd  0x8(%rsp),%xmm2
call   1030 <gsw_beta@plt>
divsd  0x48(%rsp),%xmm0
movapd 0x30(%rsp),%xmm3
divsd  %xmm0,%xmm3
addsd  0x20(%rsp),%xmm3
movsd  0xcae(%rip),%xmm1
cmpltsd %xmm3,%xmm1
movapd %xmm1,%xmm0
andnpd %xmm3,%xmm0
movsd  0xca1(%rip),%xmm2
andpd  %xmm2,%xmm1
orpd   %xmm0,%xmm1
cmpltsd 0xca0(%rip),%xmm3
movapd %xmm3,%xmm0
andnpd %xmm1,%xmm0
andpd  %xmm2,%xmm3
orpd   %xmm0,%xmm3
movapd %xmm3,%xmm0
add    $0x58,%rsp
ret

LLVM IR (-O0):
define double @gsw_sa_from_rho(double %0, double %1, double %2) {
%4 = alloca double
%5 = alloca double
%6 = alloca double
%7 = alloca i32
%8 = alloca double
%9 = alloca double
%10 = alloca double
%11 = alloca double
%12 = alloca double
%13 = alloca double
%14 = alloca double
%15 = alloca double
%16 = alloca double
%17 = alloca double
store double %0, double* %4
store double %1, double* %5
store double %2, double* %6
%18 = load double, double* %4
%19 = fdiv double 1.000000e+00, %18
store double %19, double* %9
%20 = load double, double* %5
%21 = load double, double* %6
%22 = call double @gsw_specvol(double 0.000000e+00, double %20, double %21)
store double %22, double* %10
%23 = load double, double* %5
%24 = load double, double* %6
%25 = call double @gsw_specvol(double 5.000000e+01, double %23, double %24)
store double %25, double* %11
%26 = load double, double* %9
%27 = load double, double* %10
%28 = fsub double %26, %27
%29 = fmul double 5.000000e+01, %28
%30 = load double, double* %11
%31 = load double, double* %10
%32 = fsub double %30, %31
%33 = fdiv double %29, %32
store double %33, double* %8
%34 = load double, double* %8
%35 = fcmp olt double %34, 0.000000e+00
br i1 %35, label %39, label %36
36: ; preds = %3
%37 = load double, double* %8
%38 = fcmp ogt double %37, 5.000000e+01
br i1 %38, label %39, label %40
39: ; preds = %36, %3
store double 9.000000e+15, double* %8
br label %40
40: ; preds = %39, %36
%41 = load double, double* %11
%42 = load double, double* %10
%43 = fsub double %41, %42
%44 = fdiv double %43, 5.000000e+01
store double %44, double* %12
store i32 1, i32* %7
br label %45
45: ; preds = %89, %40
%46 = load i32, i32* %7
%47 = icmp sle i32 %46, 2
br i1 %47, label %48, label %92
48: ; preds = %45
%49 = load double, double* %8
store double %49, double* %13
%50 = load double, double* %13
%51 = load double, double* %5
%52 = load double, double* %6
%53 = call double @gsw_specvol(double %50, double %51, double %52)
%54 = load double, double* %9
%55 = fsub double %53, %54
store double %55, double* %14
%56 = load double, double* %13
%57 = load double, double* %14
%58 = load double, double* %12
%59 = fdiv double %57, %58
%60 = fsub double %56, %59
store double %60, double* %8
%61 = load double, double* %8
%62 = load double, double* %13
%63 = fadd double %61, %62
%64 = fmul double 5.000000e-01, %63
store double %64, double* %15
%65 = load double, double* %15
%66 = load double, double* %5
%67 = load double, double* %6
%68 = call double @gsw_alpha(double %65, double %66, double %67)
store double %68, double* %16
%69 = load double, double* %15
%70 = load double, double* %5
%71 = load double, double* %6
%72 = call double @gsw_beta(double %69, double %70, double %71)
store double %72, double* %17
%73 = load double, double* %17
%74 = fneg double %73
%75 = load double, double* %4
%76 = fdiv double %74, %75
store double %76, double* %12
%77 = load double, double* %13
%78 = load double, double* %14
%79 = load double, double* %12
%80 = fdiv double %78, %79
%81 = fsub double %77, %80
store double %81, double* %8
%82 = load double, double* %8
%83 = fcmp olt double %82, 0.000000e+00
br i1 %83, label %87, label %84
84: ; preds = %48
%85 = load double, double* %8
%86 = fcmp ogt double %85, 5.000000e+01
br i1 %86, label %87, label %88
87: ; preds = %84, %48
store double 9.000000e+15, double* %8
br label %88
88: ; preds = %87, %84
br label %89
89: ; preds = %88
%90 = load i32, i32* %7
%91 = add nsw i32 %90, 1
store i32 %91, i32* %7
br label %45
92: ; preds = %45
%93 = load double, double* %8
ret double %93
}

LLVM IR (-O2):
define double @gsw_sa_from_rho(double %0, double %1, double %2) {
%4 = fdiv double 1.000000e+00, %0
%5 = tail call double @gsw_specvol(double 0.000000e+00, double %1, double %2)
%6 = tail call double @gsw_specvol(double 5.000000e+01, double %1, double %2)
%7 = fsub double %4, %5
%8 = fmul double %7, 5.000000e+01
%9 = fsub double %6, %5
%10 = fdiv double %8, %9
%11 = fcmp olt double %10, 0.000000e+00
%12 = fcmp ogt double %10, 5.000000e+01
%13 = or i1 %11, %12
%14 = select i1 %13, double 9.000000e+15, double %10
%15 = fdiv double %9, 5.000000e+01
%16 = tail call double @gsw_specvol(double %14, double %1, double %2)
%17 = fsub double %16, %4
%18 = fdiv double %17, %15
%19 = fsub double %14, %18
%20 = fadd double %14, %19
%21 = fmul double %20, 5.000000e-01
%22 = tail call double @gsw_alpha(double %21, double %1, double %2)
%23 = tail call double @gsw_beta(double %21, double %1, double %2)
%24 = fneg double %23
%25 = fdiv double %24, %0
%26 = fdiv double %17, %25
%27 = fsub double %14, %26
%28 = fcmp olt double %27, 0.000000e+00
%29 = fcmp ogt double %27, 5.000000e+01
%30 = or i1 %28, %29
%31 = select i1 %30, double 9.000000e+15, double %27
%32 = tail call double @gsw_specvol(double %31, double %1, double %2)
%33 = fsub double %32, %4
%34 = fdiv double %33, %25
%35 = fsub double %31, %34
%36 = fadd double %31, %35
%37 = fmul double %36, 5.000000e-01
%38 = tail call double @gsw_alpha(double %37, double %1, double %2)
%39 = tail call double @gsw_beta(double %37, double %1, double %2)
%40 = fneg double %39
%41 = fdiv double %40, %0
%42 = fdiv double %33, %41
%43 = fsub double %31, %42
%44 = fcmp olt double %43, 0.000000e+00
%45 = fcmp ogt double %43, 5.000000e+01
%46 = or i1 %44, %45
%47 = select i1 %46, double 9.000000e+15, double %43
ret double %47
}