#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 M_PI;
double Q_Bernoulli(double, double, double, double, double, double, double,
                   double, double);
double acos(int);
int /*<<< orphan*/ close_enough(double, double);
double dc_pipe(double, double, double);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int sin(int);
int /*<<< orphan*/ stderr;
double Q_outlet_pipe(double HW, double TW, double D, double S0, double L,
                     double n, double ke, double g) {
  double area = M_PI * D * D / 4.;
  double Rh = D / 4.;
  double Q = Q_Bernoulli(HW, TW, area, Rh, S0, L, n, ke, g);
  if (TW > D)
    return Q;
  int nmax = 50;
  double Q0;
  do {
    double dc = dc_pipe(D, Q, g);
    double h0 = (((dc + D) / 2.) > (TW) ? ((dc + D) / 2.) : (TW));
    if (h0 > D)
      h0 = D;
    Q0 = Q;
    double theta = acos(1. - 2. * h0 / D);
    double B = D * sin(theta);
    double area = D * D * (theta - sin(2. * theta) / 2.) / 4.;
    double perimeter = B + theta * D;
    Rh = area / perimeter;
    Q = Q_Bernoulli(HW, h0, area, Rh, S0, L, n, ke, g);
  } while (nmax-- && !close_enough(Q0, Q));
  if (nmax == 0)
    fprintf(
        stderr,
        "boyd87.c: Q_outlet_pipe(): warning: iterations did not converge\n");
  return Q;
}


x86 assembly (clang, -O0):
<Q_outlet_pipe>:
push   %rbp
mov    %rsp,%rbp
sub    $0xd0,%rsp
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  %xmm7,-0x48(%rbp)
mov    0x2e4e(%rip),%rax
movsd  (%rax),%xmm0
mulsd  -0x20(%rbp),%xmm0
mulsd  -0x20(%rbp),%xmm0
movsd  0xe50(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x50(%rbp)
movsd  -0x20(%rbp),%xmm0
movsd  0xe3a(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x58(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  -0x18(%rbp),%xmm1
movsd  -0x50(%rbp),%xmm2
movsd  -0x58(%rbp),%xmm3
movsd  -0x28(%rbp),%xmm4
movsd  -0x30(%rbp),%xmm5
movsd  -0x38(%rbp),%xmm6
movsd  -0x40(%rbp),%xmm7
movsd  -0x48(%rbp),%xmm8
movsd  %xmm8,(%rsp)
call   1030 <Q_Bernoulli@plt>
movsd  %xmm0,-0x60(%rbp)
movsd  -0x18(%rbp),%xmm0
ucomisd -0x20(%rbp),%xmm0
jbe    122c <Q_outlet_pipe+0xcc>
movsd  -0x60(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1491 <Q_outlet_pipe+0x331>
movl   $0x32,-0x64(%rbp)
movsd  -0x20(%rbp),%xmm0
movsd  -0x60(%rbp),%xmm1
movsd  -0x48(%rbp),%xmm2
call   1080 <dc_pipe@plt>
movsd  %xmm0,-0x78(%rbp)
movsd  -0x78(%rbp),%xmm0
addsd  -0x20(%rbp),%xmm0
movsd  0xdaa(%rip),%xmm1
divsd  %xmm1,%xmm0
ucomisd -0x18(%rbp),%xmm0
jbe    1290 <Q_outlet_pipe+0x130>
movsd  -0x78(%rbp),%xmm0
addsd  -0x20(%rbp),%xmm0
movsd  0xd89(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0xa8(%rbp)
ff
jmp    129d <Q_outlet_pipe+0x13d>
movsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0xa8(%rbp)
ff
movsd  -0xa8(%rbp),%xmm0
ff
movsd  %xmm0,-0x80(%rbp)
movsd  -0x80(%rbp),%xmm0
ucomisd -0x20(%rbp),%xmm0
jbe    12c4 <Q_outlet_pipe+0x164>
movsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x80(%rbp)
movsd  -0x60(%rbp),%xmm0
movsd  %xmm0,-0x70(%rbp)
movsd  0xd32(%rip),%xmm1
mulsd  -0x80(%rbp),%xmm1
divsd  -0x20(%rbp),%xmm1
movsd  0xd28(%rip),%xmm0
subsd  %xmm1,%xmm0
cvttsd2si %xmm0,%edi
call   1040 <acos@plt>
movsd  %xmm0,-0x88(%rbp)
ff
movsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0xc0(%rbp)
ff
cvttsd2si -0x88(%rbp),%edi
ff
call   1070 <sin@plt>
movsd  -0xc0(%rbp),%xmm0
ff
cvtsi2sd %eax,%xmm1
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x90(%rbp)
ff
movsd  -0x20(%rbp),%xmm0
mulsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0xb0(%rbp)
ff
movsd  -0x88(%rbp),%xmm0
ff
movsd  %xmm0,-0xb8(%rbp)
ff
movsd  0xcaf(%rip),%xmm0
mulsd  -0x88(%rbp),%xmm0
ff
cvttsd2si %xmm0,%edi
call   1070 <sin@plt>
movsd  -0xb8(%rbp),%xmm1
ff
movsd  -0xb0(%rbp),%xmm0
ff
cvtsi2sd %eax,%xmm2
movsd  0xc82(%rip),%xmm3
divsd  %xmm3,%xmm2
subsd  %xmm2,%xmm1
mulsd  %xmm1,%xmm0
movsd  0xc66(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x98(%rbp)
ff
movsd  -0x90(%rbp),%xmm1
ff
movsd  -0x88(%rbp),%xmm0
ff
movsd  -0x20(%rbp),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0xa0(%rbp)
ff
movsd  -0x98(%rbp),%xmm0
ff
divsd  -0xa0(%rbp),%xmm0
ff
movsd  %xmm0,-0x58(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  -0x80(%rbp),%xmm1
movsd  -0x98(%rbp),%xmm2
ff
movsd  -0x58(%rbp),%xmm3
movsd  -0x28(%rbp),%xmm4
movsd  -0x30(%rbp),%xmm5
movsd  -0x38(%rbp),%xmm6
movsd  -0x40(%rbp),%xmm7
movsd  -0x48(%rbp),%xmm8
movsd  %xmm8,(%rsp)
call   1030 <Q_Bernoulli@plt>
movsd  %xmm0,-0x60(%rbp)
mov    -0x64(%rbp),%ecx
mov    %ecx,%eax
add    $0xffffffff,%eax
mov    %eax,-0x64(%rbp)
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0xc1(%rbp)
je     145a <Q_outlet_pipe+0x2fa>
movsd  -0x70(%rbp),%xmm0
movsd  -0x60(%rbp),%xmm1
call   1050 <close_enough@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
mov    %al,-0xc1(%rbp)
mov    -0xc1(%rbp),%al
test   $0x1,%al
jne    1233 <Q_outlet_pipe+0xd3>
cmpl   $0x0,-0x64(%rbp)
jne    1487 <Q_outlet_pipe+0x327>
mov    0x2b5f(%rip),%rax
mov    (%rax),%edi
lea    0xb96(%rip),%rsi
call   1060 <fprintf@plt>
movsd  -0x60(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0xd0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Q_outlet_pipe>:
push   %rbx
sub    $0x70,%rsp
movaps %xmm6,%xmm8
movaps %xmm5,%xmm9
movaps %xmm4,%xmm10
movaps %xmm3,%xmm4
movapd %xmm2,%xmm3
movsd  %xmm1,0x18(%rsp)
mov    0x2e63(%rip),%rax
movsd  (%rax),%xmm2
mulsd  %xmm3,%xmm2
mulsd  %xmm3,%xmm2
movsd  %xmm3,0x10(%rsp)
movsd  0xe61(%rip),%xmm6
mulsd  %xmm6,%xmm2
mulsd  %xmm6,%xmm3
movsd  %xmm7,0x20(%rsp)
movsd  %xmm7,(%rsp)
movsd  %xmm0,0x30(%rsp)
movsd  %xmm4,0x38(%rsp)
movsd  %xmm10,0x40(%rsp)
movaps %xmm10,%xmm5
movsd  %xmm9,0x48(%rsp)
movaps %xmm9,%xmm6
movsd  %xmm8,0x50(%rsp)
movaps %xmm8,%xmm7
call   1030 <Q_Bernoulli@plt>
movapd %xmm0,%xmm1
movsd  0x10(%rsp),%xmm0
movsd  0x18(%rsp),%xmm2
ucomisd %xmm0,%xmm2
jbe    1203 <Q_outlet_pipe+0xa3>
movapd %xmm1,%xmm2
jmp    1379 <Q_outlet_pipe+0x219>
movapd %xmm0,%xmm2
mulsd  %xmm0,%xmm2
movsd  %xmm2,0x28(%rsp)
mov    $0xffffffce,%ebx
cs nopw 0x0(%rax,%rax,1)
movsd  %xmm1,0x58(%rsp)
movsd  0x20(%rsp),%xmm2
call   1080 <dc_pipe@plt>
movsd  0x10(%rsp),%xmm2
addsd  %xmm2,%xmm0
movsd  0xdc5(%rip),%xmm1
mulsd  %xmm1,%xmm0
maxsd  0x18(%rsp),%xmm0
movapd %xmm2,%xmm1
minsd  %xmm0,%xmm1
movsd  %xmm1,0x68(%rsp)
movapd %xmm1,%xmm0
addsd  %xmm1,%xmm0
divsd  %xmm2,%xmm0
movsd  0xda1(%rip),%xmm1
subsd  %xmm0,%xmm1
cvttsd2si %xmm1,%edi
call   1040 <acos@plt>
movsd  %xmm0,0x8(%rsp)
cvttsd2si %xmm0,%edi
call   1070 <sin@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
mulsd  0x10(%rsp),%xmm0
movsd  %xmm0,0x60(%rsp)
movsd  0x8(%rsp),%xmm0
addsd  %xmm0,%xmm0
cvttsd2si %xmm0,%edi
call   1070 <sin@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
mulsd  0xd48(%rip),%xmm0
movsd  0x8(%rsp),%xmm1
movapd %xmm1,%xmm2
subsd  %xmm0,%xmm2
mulsd  0x28(%rsp),%xmm2
mulsd  0xd24(%rip),%xmm2
mulsd  0x10(%rsp),%xmm1
addsd  0x60(%rsp),%xmm1
movapd %xmm2,%xmm3
divsd  %xmm1,%xmm3
movsd  0x20(%rsp),%xmm0
movsd  %xmm0,(%rsp)
movsd  0x30(%rsp),%xmm0
movsd  0x68(%rsp),%xmm1
movsd  0x38(%rsp),%xmm4
movsd  0x40(%rsp),%xmm5
movsd  0x48(%rsp),%xmm6
movsd  0x50(%rsp),%xmm7
call   1030 <Q_Bernoulli@plt>
movaps %xmm0,%xmm2
test   %ebx,%ebx
je     1379 <Q_outlet_pipe+0x219>
movsd  0x58(%rsp),%xmm0
movaps %xmm2,%xmm1
movsd  %xmm2,0x8(%rsp)
call   1050 <close_enough@plt>
movsd  0x8(%rsp),%xmm2
add    $0x1,%ebx
movapd %xmm2,%xmm1
test   %eax,%eax
movsd  0x10(%rsp),%xmm0
je     1220 <Q_outlet_pipe+0xc0>
test   %ebx,%ebx
jne    1379 <Q_outlet_pipe+0x219>
mov    0x2c73(%rip),%rax
mov    (%rax),%edi
lea    0xcaa(%rip),%rsi
call   1060 <fprintf@plt>
movsd  0x8(%rsp),%xmm2
movapd %xmm2,%xmm0
add    $0x70,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@M_PI = global double 0.000000e+00
@stderr = global i32 0
@.str = [65 x i8] c"boyd87.c: Q_outlet_pipe(): warning: iterations did not converge\0A\00"
define double @Q_outlet_pipe(double %0, double %1, double %2, double %3, double %4, double %5, double %6, double %7) {
%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
%18 = alloca double
%19 = alloca double
%20 = alloca double
%21 = alloca i32
%22 = alloca double
%23 = alloca double
%24 = alloca double
%25 = alloca double
%26 = alloca double
%27 = alloca double
%28 = alloca double
store double %0, double* %10
store double %1, double* %11
store double %2, double* %12
store double %3, double* %13
store double %4, double* %14
store double %5, double* %15
store double %6, double* %16
store double %7, double* %17
%29 = load double, double* @M_PI
%30 = load double, double* %12
%31 = fmul double %29, %30
%32 = load double, double* %12
%33 = fmul double %31, %32
%34 = fdiv double %33, 4.000000e+00
store double %34, double* %18
%35 = load double, double* %12
%36 = fdiv double %35, 4.000000e+00
store double %36, double* %19
%37 = load double, double* %10
%38 = load double, double* %11
%39 = load double, double* %18
%40 = load double, double* %19
%41 = load double, double* %13
%42 = load double, double* %14
%43 = load double, double* %15
%44 = load double, double* %16
%45 = load double, double* %17
%46 = call double @Q_Bernoulli(double %37, double %38, double %39, double %40, double %41, double %42, double %43, double %44, double %45)
store double %46, double* %20
%47 = load double, double* %11
%48 = load double, double* %12
%49 = fcmp ogt double %47, %48
br i1 %49, label %50, label %52
50: ; preds = %8
%51 = load double, double* %20
store double %51, double* %9
br label %143
52: ; preds = %8
store i32 50, i32* %21
br label %53
53: ; preds = %133, %52
%54 = load double, double* %12
%55 = load double, double* %20
%56 = load double, double* %17
%57 = call double @dc_pipe(double %54, double %55, double %56)
store double %57, double* %23
%58 = load double, double* %23
%59 = load double, double* %12
%60 = fadd double %58, %59
%61 = fdiv double %60, 2.000000e+00
%62 = load double, double* %11
%63 = fcmp ogt double %61, %62
br i1 %63, label %64, label %69
64: ; preds = %53
%65 = load double, double* %23
%66 = load double, double* %12
%67 = fadd double %65, %66
%68 = fdiv double %67, 2.000000e+00
br label %71
69: ; preds = %53
%70 = load double, double* %11
br label %71
71: ; preds = %69, %64
%72 = phi double [ %68, %64 ], [ %70, %69 ]
store double %72, double* %24
%73 = load double, double* %24
%74 = load double, double* %12
%75 = fcmp ogt double %73, %74
br i1 %75, label %76, label %78
76: ; preds = %71
%77 = load double, double* %12
store double %77, double* %24
br label %78
78: ; preds = %76, %71
%79 = load double, double* %20
store double %79, double* %22
%80 = load double, double* %24
%81 = fmul double 2.000000e+00, %80
%82 = load double, double* %12
%83 = fdiv double %81, %82
%84 = fsub double 1.000000e+00, %83
%85 = fptosi double %84 to i32
%86 = call double @acos(i32 %85)
store double %86, double* %25
%87 = load double, double* %12
%88 = load double, double* %25
%89 = fptosi double %88 to i32
%90 = call i32 @sin(i32 %89)
%91 = sitofp i32 %90 to double
%92 = fmul double %87, %91
store double %92, double* %26
%93 = load double, double* %12
%94 = load double, double* %12
%95 = fmul double %93, %94
%96 = load double, double* %25
%97 = load double, double* %25
%98 = fmul double 2.000000e+00, %97
%99 = fptosi double %98 to i32
%100 = call i32 @sin(i32 %99)
%101 = sitofp i32 %100 to double
%102 = fdiv double %101, 2.000000e+00
%103 = fsub double %96, %102
%104 = fmul double %95, %103
%105 = fdiv double %104, 4.000000e+00
store double %105, double* %27
%106 = load double, double* %26
%107 = load double, double* %25
%108 = load double, double* %12
%109 = call double @llvm.fmuladd.f64(double %107, double %108, double %106)
store double %109, double* %28
%110 = load double, double* %27
%111 = load double, double* %28
%112 = fdiv double %110, %111
store double %112, double* %19
%113 = load double, double* %10
%114 = load double, double* %24
%115 = load double, double* %27
%116 = load double, double* %19
%117 = load double, double* %13
%118 = load double, double* %14
%119 = load double, double* %15
%120 = load double, double* %16
%121 = load double, double* %17
%122 = call double @Q_Bernoulli(double %113, double %114, double %115, double %116, double %117, double %118, double %119, double %120, double %121)
store double %122, double* %20
br label %123
123: ; preds = %78
%124 = load i32, i32* %21
%125 = add nsw i32 %124, -1
store i32 %125, i32* %21
%126 = icmp ne i32 %124, 0
br i1 %126, label %127, label %133
127: ; preds = %123
%128 = load double, double* %22
%129 = load double, double* %20
%130 = call i32 @close_enough(double %128, double %129)
%131 = icmp ne i32 %130, 0
%132 = xor i1 %131, true
br label %133
133: ; preds = %127, %123
%134 = phi i1 [ false, %123 ], [ %132, %127 ]
br i1 %134, label %53, label %135
135: ; preds = %133
%136 = load i32, i32* %21
%137 = icmp eq i32 %136, 0
br i1 %137, label %138, label %141
138: ; preds = %135
%139 = load i32, i32* @stderr
%140 = call i32 @fprintf(i32 %139, i8* getelementptr inbounds ([65 x i8], [65 x i8]* @.str, i64 0, i64 0))
br label %141
141: ; preds = %138, %135
%142 = load double, double* %20
store double %142, double* %9
br label %143
143: ; preds = %141, %50
%144 = load double, double* %9
ret double %144
}

LLVM IR (-O2):
@M_PI = global double 0.000000e+00
@stderr = global i32 0
@.str = [65 x i8] c"boyd87.c: Q_outlet_pipe(): warning: iterations did not converge\0A\00"
define double @Q_outlet_pipe(double %0, double %1, double %2, double %3, double %4, double %5, double %6, double %7) {
%9 = load double, double* @M_PI
%10 = fmul double %9, %2
%11 = fmul double %10, %2
%12 = fmul double %11, 2.500000e-01
%13 = fmul double %2, 2.500000e-01
%14 = tail call double @Q_Bernoulli(double %0, double %1, double %12, double %13, double %3, double %4, double %5, double %6, double %7)
%15 = fcmp ogt double %1, %2
br i1 %15, label %58, label %16
16: ; preds = %8
%17 = fmul double %2, %2
br label %18
18: ; preds = %16, %50
%19 = phi i32 [ %48, %50 ], [ 50, %16 ]
%20 = phi double [ %47, %50 ], [ %14, %16 ]
%21 = tail call double @dc_pipe(double %2, double %20, double %7)
%22 = fadd double %21, %2
%23 = fmul double %22, 5.000000e-01
%24 = fcmp ogt double %23, %1
%25 = select i1 %24, double %23, double %1
%26 = fcmp ogt double %25, %2
%27 = select i1 %26, double %2, double %25
%28 = fmul double %27, 2.000000e+00
%29 = fdiv double %28, %2
%30 = fsub double 1.000000e+00, %29
%31 = fptosi double %30 to i32
%32 = tail call double @acos(i32 %31)
%33 = fptosi double %32 to i32
%34 = tail call i32 @sin(i32 %33)
%35 = sitofp i32 %34 to double
%36 = fmul double %35, %2
%37 = fmul double %32, 2.000000e+00
%38 = fptosi double %37 to i32
%39 = tail call i32 @sin(i32 %38)
%40 = sitofp i32 %39 to double
%41 = fmul double %40, 5.000000e-01
%42 = fsub double %32, %41
%43 = fmul double %17, %42
%44 = fmul double %43, 2.500000e-01
%45 = tail call double @llvm.fmuladd.f64(double %32, double %2, double %36)
%46 = fdiv double %44, %45
%47 = tail call double @Q_Bernoulli(double %0, double %27, double %44, double %46, double %3, double %4, double %5, double %6, double %7)
%48 = add nsw i32 %19, -1
%49 = icmp eq i32 %19, 0
br i1 %49, label %58, label %50
50: ; preds = %18
%51 = tail call i32 @close_enough(double %20, double %47)
%52 = icmp eq i32 %51, 0
br i1 %52, label %18, label %53
53: ; preds = %50
%54 = icmp eq i32 %48, 0
br i1 %54, label %55, label %58
55: ; preds = %53
%56 = load i32, i32* @stderr
%57 = tail call i32 @fprintf(i32 %56, i8* getelementptr inbounds ([65 x i8], [65 x i8]* @.str, i64 0, i64 0))
br label %58
58: ; preds = %18, %53, %55, %8
%59 = phi double [ %14, %8 ], [ %47, %55 ], [ %47, %53 ], [ %47, %18 ]
ret double %59
}