#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 fmax(double, double);
double sqrt(double);
void calculateSubgridErrorShallowWater2D(int nElements_global,
                                         int nQuadraturePoints_element,
                                         double g, double *elementDiameter,
                                         double *h, double *hu, double *hv,
                                         double *cfl_1, double *cfl_2,
                                         double *cfl_3) {
  int eN, k;
  double u, v, speed, c;
  for (eN = 0; eN < nElements_global; eN++) {
    for (k = 0; k < nQuadraturePoints_element; k++) {
      u = hu[eN * nQuadraturePoints_element + k] /
          fmax(h[eN * nQuadraturePoints_element + k], 1.0e-8);
      v = hv[eN * nQuadraturePoints_element + k] /
          fmax(h[eN * nQuadraturePoints_element + k], 1.0e-8);
      speed = sqrt(u * u + v * v);
      c = sqrt(fabs(g * h[eN * nQuadraturePoints_element + k]));
      cfl_1[eN * nQuadraturePoints_element + k] =
          (speed - c) / elementDiameter[eN];
      cfl_2[eN * nQuadraturePoints_element + k] = speed / elementDiameter[eN];
      cfl_3[eN * nQuadraturePoints_element + k] =
          (speed + c) / elementDiameter[eN];
    }
  }
}


x86 assembly (clang, -O0):
<calculateSubgridErrorShallowWater2D>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    0x20(%rbp),%rax
mov    0x18(%rbp),%rax
mov    0x10(%rbp),%rax
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
movsd  %xmm0,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    %r9,-0x30(%rbp)
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    12e0 <calculateSubgridErrorShallowWater2D+0x1d0>
movl   $0x0,-0x38(%rbp)
mov    -0x38(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    12cd <calculateSubgridErrorShallowWater2D+0x1bd>
mov    -0x28(%rbp),%rax
mov    -0x34(%rbp),%ecx
imul   -0x8(%rbp),%ecx
add    -0x38(%rbp),%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x20(%rbp),%rax
mov    -0x34(%rbp),%ecx
imul   -0x8(%rbp),%ecx
add    -0x38(%rbp),%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm1
movsd  0xe77(%rip),%xmm2
maxsd  %xmm2,%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x40(%rbp)
mov    -0x30(%rbp),%rax
mov    -0x34(%rbp),%ecx
imul   -0x8(%rbp),%ecx
add    -0x38(%rbp),%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x20(%rbp),%rax
mov    -0x34(%rbp),%ecx
imul   -0x8(%rbp),%ecx
add    -0x38(%rbp),%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm1
movsd  0xe36(%rip),%xmm2
maxsd  %xmm2,%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x40(%rbp),%xmm0
movsd  -0x40(%rbp),%xmm2
movsd  -0x48(%rbp),%xmm1
mulsd  -0x48(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
call   1030 <sqrt@plt>
movsd  %xmm0,-0x50(%rbp)
movsd  -0x10(%rbp),%xmm0
mov    -0x20(%rbp),%rax
mov    -0x34(%rbp),%ecx
imul   -0x8(%rbp),%ecx
add    -0x38(%rbp),%ecx
movslq %ecx,%rcx
mulsd  (%rax,%rcx,8),%xmm0
movaps 0xdd1(%rip),%xmm1
pand   %xmm1,%xmm0
call   1030 <sqrt@plt>
movsd  %xmm0,-0x58(%rbp)
movsd  -0x50(%rbp),%xmm0
subsd  -0x58(%rbp),%xmm0
mov    -0x18(%rbp),%rax
movslq -0x34(%rbp),%rcx
divsd  (%rax,%rcx,8),%xmm0
mov    0x10(%rbp),%rax
mov    -0x34(%rbp),%ecx
imul   -0x8(%rbp),%ecx
add    -0x38(%rbp),%ecx
movslq %ecx,%rcx
movsd  %xmm0,(%rax,%rcx,8)
movsd  -0x50(%rbp),%xmm0
mov    -0x18(%rbp),%rax
movslq -0x34(%rbp),%rcx
divsd  (%rax,%rcx,8),%xmm0
mov    0x18(%rbp),%rax
mov    -0x34(%rbp),%ecx
imul   -0x8(%rbp),%ecx
add    -0x38(%rbp),%ecx
movslq %ecx,%rcx
movsd  %xmm0,(%rax,%rcx,8)
movsd  -0x50(%rbp),%xmm0
addsd  -0x58(%rbp),%xmm0
mov    -0x18(%rbp),%rax
movslq -0x34(%rbp),%rcx
divsd  (%rax,%rcx,8),%xmm0
mov    0x20(%rbp),%rax
mov    -0x34(%rbp),%ecx
imul   -0x8(%rbp),%ecx
add    -0x38(%rbp),%ecx
movslq %ecx,%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x38(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x38(%rbp)
jmp    1159 <calculateSubgridErrorShallowWater2D+0x49>
jmp    12d2 <calculateSubgridErrorShallowWater2D+0x1c2>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    1146 <calculateSubgridErrorShallowWater2D+0x36>
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<calculateSubgridErrorShallowWater2D>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x48,%rsp
mov    %r9,0x18(%rsp)
mov    %r8,0x10(%rsp)
movsd  %xmm0,0x40(%rsp)
mov    %esi,0x4(%rsp)
test   %edi,%edi
jle    12b4 <calculateSubgridErrorShallowWater2D+0x1a4>
mov    %rcx,%r12
mov    %rdx,%rbx
mov    0x90(%rsp),%rax
mov    %rax,0x8(%rsp)
mov    0x88(%rsp),%r13
mov    0x80(%rsp),%r14
movslq 0x4(%rsp),%rax
mov    %edi,%ecx
mov    %rcx,0x20(%rsp)
mov    %eax,%ecx
shl    $0x3,%rax
mov    %rax,0x28(%rsp)
shl    $0x3,%rcx
mov    %rcx,0x38(%rsp)
xor    %r15d,%r15d
xorpd  %xmm3,%xmm3
jmp    11bc <calculateSubgridErrorShallowWater2D+0xac>
cs nopw 0x0(%rax,%rax,1)
add    $0x1,%r15
mov    0x28(%rsp),%rax
add    %rax,0x10(%rsp)
add    %rax,%r12
add    %rax,0x18(%rsp)
add    %rax,%r14
add    %rax,%r13
add    %rax,0x8(%rsp)
cmp    0x20(%rsp),%r15
je     12b4 <calculateSubgridErrorShallowWater2D+0x1a4>
cmpl   $0x0,0x4(%rsp)
jle    1190 <calculateSubgridErrorShallowWater2D+0x80>
xor    %ebp,%ebp
jmp    122d <calculateSubgridErrorShallowWater2D+0x11d>
nopw   0x0(%rax,%rax,1)
movsd  %xmm2,0x30(%rsp)
call   1030 <sqrt@plt>
movsd  0x30(%rsp),%xmm2
xorpd  %xmm3,%xmm3
movapd %xmm2,%xmm1
subsd  %xmm0,%xmm1
divsd  (%rbx,%r15,8),%xmm1
movsd  %xmm1,(%r14,%rbp,1)
movapd %xmm2,%xmm1
divsd  (%rbx,%r15,8),%xmm1
movsd  %xmm1,0x0(%r13,%rbp,1)
addsd  %xmm0,%xmm2
divsd  (%rbx,%r15,8),%xmm2
mov    0x8(%rsp),%rax
movsd  %xmm2,(%rax,%rbp,1)
add    $0x8,%rbp
cmp    %rbp,0x38(%rsp)
je     1190 <calculateSubgridErrorShallowWater2D+0x80>
mov    0x10(%rsp),%rax
movsd  (%rax,%rbp,1),%xmm0
movsd  (%r12,%rbp,1),%xmm1
maxsd  0xdbb(%rip),%xmm1
divsd  %xmm1,%xmm0
mov    0x18(%rsp),%rax
movsd  (%rax,%rbp,1),%xmm2
divsd  %xmm1,%xmm2
mulsd  %xmm2,%xmm2
mulsd  %xmm0,%xmm0
addsd  %xmm2,%xmm0
ucomisd %xmm3,%xmm0
jb     1280 <calculateSubgridErrorShallowWater2D+0x170>
xorps  %xmm2,%xmm2
sqrtsd %xmm0,%xmm2
jmp    128d <calculateSubgridErrorShallowWater2D+0x17d>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
call   1030 <sqrt@plt>
xorpd  %xmm3,%xmm3
movapd %xmm0,%xmm2
movsd  (%r12,%rbp,1),%xmm0
mulsd  0x40(%rsp),%xmm0
andpd  0xd6f(%rip),%xmm0
ucomisd %xmm3,%xmm0
jb     11d0 <calculateSubgridErrorShallowWater2D+0xc0>
sqrtsd %xmm0,%xmm0
jmp    11e5 <calculateSubgridErrorShallowWater2D+0xd5>
add    $0x48,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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