#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 fabs(double);
double stub1(double, double, double, double, double, double);
double stub2(double, double, double, double, double, double);
double stub3(double, double, double, double, double, double);
double findpH(double (*fcnHndl)(double, double, double, double, double, double),
              double pH0, double Var1, double Var2, double K1, double K2,
              double Kw, double f) {
  double pHa, fnka, df, dpH;
  double tol = 1e-3;
  int iter = 0;
  int itermax = 50;
  double fnk = (*fcnHndl)(pH0, Var1, K1, K2, Kw, f) - Var2;
  double pH = pH0;
  pH0 = pH + 1;
  while ((fabs(pH - pH0) > tol) && (iter <= itermax)) {
    iter = iter + 1;
    pH0 = pH;
    if (pH != 0) {
      dpH = pH * tol;
    } else {
      dpH = tol;
    }
    pHa = pH - dpH;
    fnka = (*fcnHndl)(pHa, Var1, K1, K2, Kw, f) - Var2;
    df = (fnk - fnka) / (pH - pHa);
    if (df == 0) {
      pH = pH0 + 1.1 * tol;
    } else {
      pH = pH0 - fnk / df;
    }
    if (pH < 0) {
      pH = 0;
    }
    if (pH > 14) {
      pH = 14;
    }
    fnk = (*fcnHndl)(pH, Var1, K1, K2, Kw, f) - Var2;
  }
  return pH;
}


x86 assembly (clang, -O0):
<findpH>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
mov    %rdi,-0x8(%rbp)
movsd  %xmm0,-0x10(%rbp)
movsd  %xmm1,-0x18(%rbp)
movsd  %xmm2,-0x20(%rbp)
movsd  %xmm3,-0x28(%rbp)
movsd  %xmm4,-0x30(%rbp)
movsd  %xmm5,-0x38(%rbp)
movsd  %xmm6,-0x40(%rbp)
movsd  0xece(%rip),%xmm0
movsd  %xmm0,-0x68(%rbp)
movl   $0x0,-0x6c(%rbp)
movl   $0x32,-0x70(%rbp)
mov    -0x8(%rbp),%rax
movsd  -0x10(%rbp),%xmm0
movsd  -0x18(%rbp),%xmm1
movsd  -0x28(%rbp),%xmm2
movsd  -0x30(%rbp),%xmm3
movsd  -0x38(%rbp),%xmm4
movsd  -0x40(%rbp),%xmm5
call   *%rax
subsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x78(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x80(%rbp)
movsd  0xe73(%rip),%xmm0
addsd  -0x80(%rbp),%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  -0x80(%rbp),%xmm0
subsd  -0x10(%rbp),%xmm0
movaps 0xe78(%rip),%xmm1
pand   %xmm1,%xmm0
xor    %eax,%eax
ucomisd -0x68(%rbp),%xmm0
mov    %al,-0x81(%rbp)
jbe    11ce <findpH+0xce>
mov    -0x6c(%rbp),%eax
cmp    -0x70(%rbp),%eax
setle  %al
mov    %al,-0x81(%rbp)
mov    -0x81(%rbp),%al
test   $0x1,%al
jne    11e1 <findpH+0xe1>
jmp    134a <findpH+0x24a>
mov    -0x6c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x6c(%rbp)
movsd  -0x80(%rbp),%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  -0x80(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    1211 <findpH+0x111>
jp     1211 <findpH+0x111>
jmp    1225 <findpH+0x125>
movsd  -0x80(%rbp),%xmm0
mulsd  -0x68(%rbp),%xmm0
movsd  %xmm0,-0x60(%rbp)
jmp    122f <findpH+0x12f>
movsd  -0x68(%rbp),%xmm0
movsd  %xmm0,-0x60(%rbp)
movsd  -0x80(%rbp),%xmm0
subsd  -0x60(%rbp),%xmm0
movsd  %xmm0,-0x48(%rbp)
mov    -0x8(%rbp),%rax
movsd  -0x48(%rbp),%xmm0
movsd  -0x18(%rbp),%xmm1
movsd  -0x28(%rbp),%xmm2
movsd  -0x30(%rbp),%xmm3
movsd  -0x38(%rbp),%xmm4
movsd  -0x40(%rbp),%xmm5
call   *%rax
subsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x50(%rbp)
movsd  -0x78(%rbp),%xmm0
subsd  -0x50(%rbp),%xmm0
movsd  -0x80(%rbp),%xmm1
subsd  -0x48(%rbp),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x58(%rbp)
movsd  -0x58(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    12c5 <findpH+0x1c5>
jp     12c5 <findpH+0x1c5>
movsd  -0x10(%rbp),%xmm1
movsd  -0x68(%rbp),%xmm0
movsd  0xd5d(%rip),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x80(%rbp)
jmp    12dd <findpH+0x1dd>
movsd  -0x10(%rbp),%xmm0
movsd  -0x78(%rbp),%xmm1
divsd  -0x58(%rbp),%xmm1
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x80(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x80(%rbp),%xmm0
jbe    12f3 <findpH+0x1f3>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x80(%rbp)
movsd  -0x80(%rbp),%xmm0
movsd  0xd18(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    1317 <findpH+0x217>
movsd  0xd06(%rip),%xmm0
movsd  %xmm0,-0x80(%rbp)
mov    -0x8(%rbp),%rax
movsd  -0x80(%rbp),%xmm0
movsd  -0x18(%rbp),%xmm1
movsd  -0x28(%rbp),%xmm2
movsd  -0x30(%rbp),%xmm3
movsd  -0x38(%rbp),%xmm4
movsd  -0x40(%rbp),%xmm5
call   *%rax
subsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x78(%rbp)
jmp    1197 <findpH+0x97>
movsd  -0x80(%rbp),%xmm0
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<findpH>:
push   %r14
push   %rbx
sub    $0x48,%rsp
movsd  %xmm2,0x38(%rsp)
movsd  %xmm0,(%rsp)
mov    %rdi,%r14
movsd  %xmm1,0x10(%rsp)
movsd  %xmm3,0x18(%rsp)
movaps %xmm3,%xmm2
movsd  %xmm4,0x20(%rsp)
movaps %xmm4,%xmm3
movsd  %xmm5,0x28(%rsp)
movapd %xmm5,%xmm4
movsd  %xmm6,0x30(%rsp)
movapd %xmm6,%xmm5
call   *%rdi
movsd  (%rsp),%xmm3
movsd  0xeb0(%rip),%xmm1
addsd  %xmm3,%xmm1
movapd %xmm3,%xmm2
subsd  %xmm1,%xmm2
andpd  0xecc(%rip),%xmm2
ucomisd 0xe9c(%rip),%xmm2
jbe    12b0 <findpH+0x1b0>
xor    %ebx,%ebx
movsd  0xe8c(%rip),%xmm2
nopl   0x0(%rax)
movsd  %xmm3,(%rsp)
subsd  0x38(%rsp),%xmm0
movsd  %xmm0,0x8(%rsp)
movapd %xmm3,%xmm0
mulsd  %xmm2,%xmm0
movapd %xmm3,%xmm1
xorpd  %xmm4,%xmm4
cmpneqsd %xmm4,%xmm1
andpd  %xmm1,%xmm0
andnpd %xmm2,%xmm1
orpd   %xmm0,%xmm1
movapd %xmm3,%xmm0
subsd  %xmm1,%xmm0
movsd  %xmm0,0x40(%rsp)
movsd  0x10(%rsp),%xmm1
movsd  0x18(%rsp),%xmm2
movsd  0x20(%rsp),%xmm3
movsd  0x28(%rsp),%xmm4
movsd  0x30(%rsp),%xmm5
call   *%r14
movsd  0x8(%rsp),%xmm3
movsd  (%rsp),%xmm2
subsd  0x38(%rsp),%xmm0
movapd %xmm3,%xmm1
subsd  %xmm0,%xmm1
movapd %xmm2,%xmm0
subsd  0x40(%rsp),%xmm0
divsd  %xmm0,%xmm1
ucomisd 0xe10(%rip),%xmm1
jne    1230 <findpH+0x130>
jp     1230 <findpH+0x130>
movapd %xmm2,%xmm0
addsd  0xdf0(%rip),%xmm0
jmp    123c <findpH+0x13c>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
divsd  %xmm1,%xmm3
movapd %xmm2,%xmm0
subsd  %xmm3,%xmm0
movsd  0x30(%rsp),%xmm5
movsd  0x28(%rsp),%xmm4
movsd  0x20(%rsp),%xmm3
movsd  0x18(%rsp),%xmm2
movsd  0x10(%rsp),%xmm1
xorpd  %xmm6,%xmm6
maxsd  %xmm0,%xmm6
movsd  0xdae(%rip),%xmm0
minsd  %xmm6,%xmm0
movsd  %xmm0,0x8(%rsp)
call   *%r14
movsd  0x8(%rsp),%xmm4
movapd %xmm4,%xmm1
subsd  (%rsp),%xmm1
andpd  0xda2(%rip),%xmm1
movsd  0xd72(%rip),%xmm2
ucomisd %xmm2,%xmm1
jbe    12b4 <findpH+0x1b4>
lea    0x1(%rbx),%eax
movapd %xmm4,%xmm3
cmp    $0x32,%ebx
mov    %eax,%ebx
jb     1180 <findpH+0x80>
jmp    12b4 <findpH+0x1b4>
movapd %xmm3,%xmm4
movapd %xmm4,%xmm0
add    $0x48,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define double @findpH(double (double, double, double, double, double, double)* %0, double %1, double %2, double %3, double %4, double %5, double %6, double %7) {
%9 = alloca double (double, double, double, double, double, 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
%18 = alloca double
%19 = alloca double
%20 = alloca double
%21 = alloca double
%22 = alloca i32
%23 = alloca i32
%24 = alloca double
%25 = alloca double
store double (double, double, double, double, double, double)* %0, double (double, double, double, double, double, double)** %9
store double %1, double* %10
store double %2, double* %11
store double %3, double* %12
store double %4, double* %13
store double %5, double* %14
store double %6, double* %15
store double %7, double* %16
store double 1.000000e-03, double* %21
store i32 0, i32* %22
store i32 50, i32* %23
%26 = load double (double, double, double, double, double, double)*, double (double, double, double, double, double, double)** %9
%27 = load double, double* %10
%28 = load double, double* %11
%29 = load double, double* %13
%30 = load double, double* %14
%31 = load double, double* %15
%32 = load double, double* %16
%33 = call double %26(double %27, double %28, double %29, double %30, double %31, double %32)
%34 = load double, double* %12
%35 = fsub double %33, %34
store double %35, double* %24
%36 = load double, double* %10
store double %36, double* %25
%37 = load double, double* %25
%38 = fadd double %37, 1.000000e+00
store double %38, double* %10
br label %39
39: ; preds = %105, %8
%40 = load double, double* %25
%41 = load double, double* %10
%42 = fsub double %40, %41
%43 = call double @llvm.fabs.f64(double %42)
%44 = load double, double* %21
%45 = fcmp ogt double %43, %44
br i1 %45, label %46, label %50
46: ; preds = %39
%47 = load i32, i32* %22
%48 = load i32, i32* %23
%49 = icmp sle i32 %47, %48
br label %50
50: ; preds = %46, %39
%51 = phi i1 [ false, %39 ], [ %49, %46 ]
br i1 %51, label %52, label %116
52: ; preds = %50
%53 = load i32, i32* %22
%54 = add nsw i32 %53, 1
store i32 %54, i32* %22
%55 = load double, double* %25
store double %55, double* %10
%56 = load double, double* %25
%57 = fcmp une double %56, 0.000000e+00
br i1 %57, label %58, label %62
58: ; preds = %52
%59 = load double, double* %25
%60 = load double, double* %21
%61 = fmul double %59, %60
store double %61, double* %20
br label %64
62: ; preds = %52
%63 = load double, double* %21
store double %63, double* %20
br label %64
64: ; preds = %62, %58
%65 = load double, double* %25
%66 = load double, double* %20
%67 = fsub double %65, %66
store double %67, double* %17
%68 = load double (double, double, double, double, double, double)*, double (double, double, double, double, double, double)** %9
%69 = load double, double* %17
%70 = load double, double* %11
%71 = load double, double* %13
%72 = load double, double* %14
%73 = load double, double* %15
%74 = load double, double* %16
%75 = call double %68(double %69, double %70, double %71, double %72, double %73, double %74)
%76 = load double, double* %12
%77 = fsub double %75, %76
store double %77, double* %18
%78 = load double, double* %24
%79 = load double, double* %18
%80 = fsub double %78, %79
%81 = load double, double* %25
%82 = load double, double* %17
%83 = fsub double %81, %82
%84 = fdiv double %80, %83
store double %84, double* %19
%85 = load double, double* %19
%86 = fcmp oeq double %85, 0.000000e+00
br i1 %86, label %87, label %91
87: ; preds = %64
%88 = load double, double* %10
%89 = load double, double* %21
%90 = call double @llvm.fmuladd.f64(double 1.100000e+00, double %89, double %88)
store double %90, double* %25
br label %97
91: ; preds = %64
%92 = load double, double* %10
%93 = load double, double* %24
%94 = load double, double* %19
%95 = fdiv double %93, %94
%96 = fsub double %92, %95
store double %96, double* %25
br label %97
97: ; preds = %91, %87
%98 = load double, double* %25
%99 = fcmp olt double %98, 0.000000e+00
br i1 %99, label %100, label %101
100: ; preds = %97
store double 0.000000e+00, double* %25
br label %101
101: ; preds = %100, %97
%102 = load double, double* %25
%103 = fcmp ogt double %102, 1.400000e+01
br i1 %103, label %104, label %105
104: ; preds = %101
store double 1.400000e+01, double* %25
br label %105
105: ; preds = %104, %101
%106 = load double (double, double, double, double, double, double)*, double (double, double, double, double, double, double)** %9
%107 = load double, double* %25
%108 = load double, double* %11
%109 = load double, double* %13
%110 = load double, double* %14
%111 = load double, double* %15
%112 = load double, double* %16
%113 = call double %106(double %107, double %108, double %109, double %110, double %111, double %112)
%114 = load double, double* %12
%115 = fsub double %113, %114
store double %115, double* %24
br label %39
116: ; preds = %50
%117 = load double, double* %25
ret double %117
}

LLVM IR (-O2):
define double @findpH(double (double, double, double, double, double, double)* nocapture %0, double %1, double %2, double %3, double %4, double %5, double %6, double %7) {
%9 = tail call double %0(double %1, double %2, double %4, double %5, double %6, double %7)
%10 = fadd double %1, 1.000000e+00
%11 = fsub double %1, %10
%12 = tail call double @llvm.fabs.f64(double %11)
%13 = fcmp ogt double %12, 1.000000e-03
br i1 %13, label %14, label %47
14: ; preds = %8, %35
%15 = phi double [ %41, %35 ], [ %9, %8 ]
%16 = phi double [ %40, %35 ], [ %1, %8 ]
%17 = phi i32 [ %19, %35 ], [ 0, %8 ]
%18 = fsub double %15, %3
%19 = add nuw nsw i32 %17, 1
%20 = fcmp une double %16, 0.000000e+00
%21 = fmul double %16, 1.000000e-03
%22 = select i1 %20, double %21, double 1.000000e-03
%23 = fsub double %16, %22
%24 = tail call double %0(double %23, double %2, double %4, double %5, double %6, double %7)
%25 = fsub double %24, %3
%26 = fsub double %18, %25
%27 = fsub double %16, %23
%28 = fdiv double %26, %27
%29 = fcmp oeq double %28, 0.000000e+00
br i1 %29, label %30, label %32
30: ; preds = %14
%31 = fadd double %16, 1.100000e-03
br label %35
32: ; preds = %14
%33 = fdiv double %18, %28
%34 = fsub double %16, %33
br label %35
35: ; preds = %32, %30
%36 = phi double [ %31, %30 ], [ %34, %32 ]
%37 = fcmp olt double %36, 0.000000e+00
%38 = select i1 %37, double 0.000000e+00, double %36
%39 = fcmp ogt double %38, 1.400000e+01
%40 = select i1 %39, double 1.400000e+01, double %38
%41 = tail call double %0(double %40, double %2, double %4, double %5, double %6, double %7)
%42 = fsub double %40, %16
%43 = tail call double @llvm.fabs.f64(double %42)
%44 = fcmp ogt double %43, 1.000000e-03
%45 = icmp ult i32 %17, 50
%46 = select i1 %44, i1 %45, i1 false
br i1 %46, label %14, label %47
47: ; preds = %35, %8
%48 = phi double [ %1, %8 ], [ %40, %35 ]
ret double %48
}