#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 Q_Bernoulli(double, double, double, double, double, double, double,
                   double, double);
int /*<<< orphan*/ close_enough(double, double);
double dc_box(double, double);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ stderr;
double Q_outlet_box(double HW, double TW, double B, double D, double S0,
                    double L, double n, double ke, double g) {
  double area = B * D;
  double Rh = B * D / (2. * (B + D));
  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_box(B, Q);
    double h0 = (((dc + D) / 2.) > (TW) ? ((dc + D) / 2.) : (TW));
    if (h0 > D)
      h0 = D;
    Q0 = Q;
    area = B * h0;
    Rh = B * h0 / (B + 2. * h0);
    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_box(): warning: iterations did not converge\n");
  return Q;
}


x86 assembly (clang, -O0):
<Q_outlet_box>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
movsd  0x10(%rbp),%xmm8
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)
movsd  -0x20(%rbp),%xmm0
mulsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x50(%rbp)
movsd  -0x20(%rbp),%xmm0
mulsd  -0x28(%rbp),%xmm0
movsd  -0x20(%rbp),%xmm2
addsd  -0x28(%rbp),%xmm2
movsd  0xe5c(%rip),%xmm1
mulsd  %xmm2,%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  -0x30(%rbp),%xmm4
movsd  -0x38(%rbp),%xmm5
movsd  -0x40(%rbp),%xmm6
movsd  -0x48(%rbp),%xmm7
movsd  0x10(%rbp),%xmm8
movsd  %xmm8,(%rsp)
call   1030 <Q_Bernoulli@plt>
movsd  %xmm0,-0x60(%rbp)
movsd  -0x18(%rbp),%xmm0
ucomisd -0x28(%rbp),%xmm0
jbe    120e <Q_outlet_box+0xce>
movsd  -0x60(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    138d <Q_outlet_box+0x24d>
movl   $0x32,-0x64(%rbp)
movsd  -0x20(%rbp),%xmm0
movsd  -0x60(%rbp),%xmm1
call   1060 <dc_box@plt>
movsd  %xmm0,-0x78(%rbp)
movsd  -0x78(%rbp),%xmm0
addsd  -0x28(%rbp),%xmm0
movsd  0xdc5(%rip),%xmm1
divsd  %xmm1,%xmm0
ucomisd -0x18(%rbp),%xmm0
jbe    126d <Q_outlet_box+0x12d>
movsd  -0x78(%rbp),%xmm0
addsd  -0x28(%rbp),%xmm0
movsd  0xda4(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x88(%rbp)
ff
jmp    127a <Q_outlet_box+0x13a>
movsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x88(%rbp)
ff
movsd  -0x88(%rbp),%xmm0
ff
movsd  %xmm0,-0x80(%rbp)
movsd  -0x80(%rbp),%xmm0
ucomisd -0x28(%rbp),%xmm0
jbe    12a1 <Q_outlet_box+0x161>
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x80(%rbp)
movsd  -0x60(%rbp),%xmm0
movsd  %xmm0,-0x70(%rbp)
movsd  -0x20(%rbp),%xmm0
mulsd  -0x80(%rbp),%xmm0
movsd  %xmm0,-0x50(%rbp)
movsd  -0x20(%rbp),%xmm0
mulsd  -0x80(%rbp),%xmm0
movsd  -0x20(%rbp),%xmm2
movsd  -0x80(%rbp),%xmm1
addsd  %xmm1,%xmm1
addsd  %xmm2,%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x58(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  -0x80(%rbp),%xmm1
movsd  -0x50(%rbp),%xmm2
movsd  -0x58(%rbp),%xmm3
movsd  -0x30(%rbp),%xmm4
movsd  -0x38(%rbp),%xmm5
movsd  -0x40(%rbp),%xmm6
movsd  -0x48(%rbp),%xmm7
movsd  0x10(%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,-0x89(%rbp)
je     1356 <Q_outlet_box+0x216>
movsd  -0x70(%rbp),%xmm0
movsd  -0x60(%rbp),%xmm1
call   1040 <close_enough@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
mov    %al,-0x89(%rbp)
mov    -0x89(%rbp),%al
test   $0x1,%al
jne    1215 <Q_outlet_box+0xd5>
cmpl   $0x0,-0x64(%rbp)
jne    1383 <Q_outlet_box+0x243>
mov    0x2c6b(%rip),%rax
mov    (%rax),%edi
lea    0xc8a(%rip),%rsi
call   1050 <fprintf@plt>
movsd  -0x60(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Q_outlet_box>:
push   %rbx
sub    $0x50,%rsp
movsd  %xmm3,0x18(%rsp)
movapd %xmm2,%xmm9
movsd  %xmm1,0x10(%rsp)
movsd  0x60(%rsp),%xmm8
mulsd  %xmm3,%xmm2
movsd  %xmm9,0x20(%rsp)
addsd  %xmm3,%xmm9
addsd  %xmm9,%xmm9
movapd %xmm2,%xmm3
divsd  %xmm9,%xmm3
movsd  %xmm8,(%rsp)
movsd  %xmm0,0x28(%rsp)
movsd  %xmm4,0x30(%rsp)
movsd  %xmm5,0x38(%rsp)
movsd  %xmm6,0x40(%rsp)
movsd  %xmm7,0x48(%rsp)
call   1030 <Q_Bernoulli@plt>
movapd %xmm0,%xmm1
movsd  0x10(%rsp),%xmm0
ucomisd 0x18(%rsp),%xmm0
jbe    11bf <Q_outlet_box+0x7f>
movapd %xmm1,%xmm2
jmp    129c <Q_outlet_box+0x15c>
mov    $0xffffffce,%ebx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movsd  0x20(%rsp),%xmm0
movsd  %xmm1,0x8(%rsp)
call   1060 <dc_box@plt>
movsd  0x18(%rsp),%xmm1
addsd  %xmm1,%xmm0
mulsd  0xe0d(%rip),%xmm0
maxsd  0x10(%rsp),%xmm0
minsd  %xmm0,%xmm1
movapd %xmm1,%xmm2
movsd  0x20(%rsp),%xmm3
mulsd  %xmm3,%xmm2
movapd %xmm1,%xmm0
addsd  %xmm1,%xmm0
addsd  %xmm3,%xmm0
movapd %xmm2,%xmm3
divsd  %xmm0,%xmm3
movsd  0x60(%rsp),%xmm0
movsd  %xmm0,(%rsp)
movsd  0x28(%rsp),%xmm0
movsd  0x30(%rsp),%xmm4
movsd  0x38(%rsp),%xmm5
movsd  0x40(%rsp),%xmm6
movsd  0x48(%rsp),%xmm7
call   1030 <Q_Bernoulli@plt>
movaps %xmm0,%xmm2
test   %ebx,%ebx
je     129c <Q_outlet_box+0x15c>
movsd  0x8(%rsp),%xmm0
movaps %xmm2,%xmm1
movsd  %xmm2,0x8(%rsp)
call   1040 <close_enough@plt>
movsd  0x8(%rsp),%xmm2
add    $0x1,%ebx
movapd %xmm2,%xmm1
test   %eax,%eax
je     11d0 <Q_outlet_box+0x90>
test   %ebx,%ebx
jne    129c <Q_outlet_box+0x15c>
mov    0x2d58(%rip),%rax
mov    (%rax),%edi
lea    0xd77(%rip),%rsi
call   1050 <fprintf@plt>
movsd  0x8(%rsp),%xmm2
movapd %xmm2,%xmm0
add    $0x50,%rsp
pop    %rbx
ret

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

LLVM IR (-O2):
@stderr = global i32 0
@.str = [64 x i8] c"boyd87.c: Q_outlet_box(): warning: iterations did not converge\0A\00"
define double @Q_outlet_box(double %0, double %1, double %2, double %3, double %4, double %5, double %6, double %7, double %8) {
%10 = fmul double %2, %3
%11 = fadd double %2, %3
%12 = fmul double %11, 2.000000e+00
%13 = fdiv double %10, %12
%14 = tail call double @Q_Bernoulli(double %0, double %1, double %10, double %13, double %4, double %5, double %6, double %7, double %8)
%15 = fcmp ogt double %1, %3
br i1 %15, label %40, label %16
16: ; preds = %9, %32
%17 = phi double [ %29, %32 ], [ %14, %9 ]
%18 = phi i32 [ %30, %32 ], [ 50, %9 ]
%19 = tail call double @dc_box(double %2, double %17)
%20 = fadd double %19, %3
%21 = fmul double %20, 5.000000e-01
%22 = fcmp ogt double %21, %1
%23 = select i1 %22, double %21, double %1
%24 = fcmp ogt double %23, %3
%25 = select i1 %24, double %3, double %23
%26 = fmul double %25, %2
%27 = tail call double @llvm.fmuladd.f64(double %25, double 2.000000e+00, double %2)
%28 = fdiv double %26, %27
%29 = tail call double @Q_Bernoulli(double %0, double %25, double %26, double %28, double %4, double %5, double %6, double %7, double %8)
%30 = add nsw i32 %18, -1
%31 = icmp eq i32 %18, 0
br i1 %31, label %40, label %32
32: ; preds = %16
%33 = tail call i32 @close_enough(double %17, double %29)
%34 = icmp eq i32 %33, 0
br i1 %34, label %16, label %35
35: ; preds = %32
%36 = icmp eq i32 %30, 0
br i1 %36, label %37, label %40
37: ; preds = %35
%38 = load i32, i32* @stderr
%39 = tail call i32 @fprintf(i32 %38, i8* getelementptr inbounds ([64 x i8], [64 x i8]* @.str, i64 0, i64 0))
br label %40
40: ; preds = %16, %35, %37, %9
%41 = phi double [ %14, %9 ], [ %29, %37 ], [ %29, %35 ], [ %29, %16 ]
ret double %41
}