#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 */
int /*<<< orphan*/ fabs(double);
double fmax(double, double);
double sqrt(int /*<<< orphan*/);
void calculateSubgridErrorShallowWater1D(int nElements_global,
                                         int nQuadraturePoints_element,
                                         double g, double *elementDiameter,
                                         double *h, double *hu, double *cfl_1,
                                         double *cfl_2) {
  int eN, k;
  double u, 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);
      c = sqrt(fabs(g * h[eN * nQuadraturePoints_element + k]));
      cfl_1[eN * nQuadraturePoints_element + k] = (u - c) / elementDiameter[eN];
      cfl_2[eN * nQuadraturePoints_element + k] = (u + c) / elementDiameter[eN];
    }
  }
}


x86 assembly (clang, -O0):
<calculateSubgridErrorShallowWater1D>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
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    1255 <calculateSubgridErrorShallowWater1D+0x135>
movl   $0x0,-0x38(%rbp)
mov    -0x38(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    1242 <calculateSubgridErrorShallowWater1D+0x122>
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  0xe5f(%rip),%xmm2
maxsd  %xmm2,%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x40(%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
call   1030 <fabs@plt>
mov    %eax,%edi
call   1040 <sqrt@plt>
movsd  %xmm0,-0x48(%rbp)
movsd  -0x40(%rbp),%xmm0
subsd  -0x48(%rbp),%xmm0
mov    -0x18(%rbp),%rax
movslq -0x34(%rbp),%rcx
divsd  (%rax,%rcx,8),%xmm0
mov    -0x30(%rbp),%rax
mov    -0x34(%rbp),%ecx
imul   -0x8(%rbp),%ecx
add    -0x38(%rbp),%ecx
movslq %ecx,%rcx
movsd  %xmm0,(%rax,%rcx,8)
movsd  -0x40(%rbp),%xmm0
addsd  -0x48(%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)
mov    -0x38(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x38(%rbp)
jmp    1161 <calculateSubgridErrorShallowWater1D+0x41>
jmp    1247 <calculateSubgridErrorShallowWater1D+0x127>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    114e <calculateSubgridErrorShallowWater1D+0x2e>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<calculateSubgridErrorShallowWater1D>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %esi,0x4(%rsp)
test   %edi,%edi
jle    124a <calculateSubgridErrorShallowWater1D+0x12a>
mov    %rdx,%r13
movapd %xmm0,%xmm2
mov    0x70(%rsp),%rbx
movslq 0x4(%rsp),%rsi
mov    %edi,%edi
mov    %rdi,0x8(%rsp)
mov    %esi,%r15d
shl    $0x3,%rsi
mov    %rsi,0x10(%rsp)
xor    %r12d,%r12d
movsd  0xe97(%rip),%xmm3
movsd  %xmm0,0x18(%rsp)
jmp    11a0 <calculateSubgridErrorShallowWater1D+0x80>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
add    $0x1,%r12
mov    0x10(%rsp),%rbp
add    %rbp,%r8
add    %rbp,%rcx
add    %rbp,%r9
add    %rbp,%rbx
cmp    0x8(%rsp),%r12
je     124a <calculateSubgridErrorShallowWater1D+0x12a>
cmpl   $0x0,0x4(%rsp)
jle    1180 <calculateSubgridErrorShallowWater1D+0x60>
xor    %r14d,%r14d
mov    %r9,0x28(%rsp)
mov    %r8,0x20(%rsp)
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movsd  (%r8,%r14,8),%xmm4
movsd  (%rcx,%r14,8),%xmm0
movapd %xmm0,%xmm1
maxsd  %xmm3,%xmm1
divsd  %xmm1,%xmm4
movsd  %xmm4,0x30(%rsp)
mulsd  %xmm2,%xmm0
mov    %rcx,%rbp
call   1030 <fabs@plt>
mov    %eax,%edi
call   1040 <sqrt@plt>
movsd  0xe07(%rip),%xmm3
movsd  0x18(%rsp),%xmm2
mov    %rbp,%rcx
mov    0x20(%rsp),%r8
mov    0x28(%rsp),%r9
movsd  0x30(%rsp),%xmm4
movapd %xmm4,%xmm1
subsd  %xmm0,%xmm1
divsd  0x0(%r13,%r12,8),%xmm1
movsd  %xmm1,(%r9,%r14,8)
addsd  %xmm0,%xmm4
divsd  0x0(%r13,%r12,8),%xmm4
movsd  %xmm4,(%rbx,%r14,8)
add    $0x1,%r14
cmp    %r14,%r15
jne    11c0 <calculateSubgridErrorShallowWater1D+0xa0>
jmp    1180 <calculateSubgridErrorShallowWater1D+0x60>
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @calculateSubgridErrorShallowWater1D(i32 %0, i32 %1, double %2, double* %3, double* %4, double* %5, double* %6, double* %7) {
%9 = alloca i32
%10 = alloca i32
%11 = alloca double
%12 = alloca double*
%13 = alloca double*
%14 = alloca double*
%15 = alloca double*
%16 = alloca double*
%17 = alloca i32
%18 = alloca i32
%19 = alloca double
%20 = alloca double
store i32 %0, i32* %9
store i32 %1, i32* %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 i32 0, i32* %17
br label %21
21: ; preds = %102, %8
%22 = load i32, i32* %17
%23 = load i32, i32* %9
%24 = icmp slt i32 %22, %23
br i1 %24, label %25, label %105
25: ; preds = %21
store i32 0, i32* %18
br label %26
26: ; preds = %98, %25
%27 = load i32, i32* %18
%28 = load i32, i32* %10
%29 = icmp slt i32 %27, %28
br i1 %29, label %30, label %101
30: ; preds = %26
%31 = load double*, double** %14
%32 = load i32, i32* %17
%33 = load i32, i32* %10
%34 = mul nsw i32 %32, %33
%35 = load i32, i32* %18
%36 = add nsw i32 %34, %35
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds double, double* %31, i64 %37
%39 = load double, double* %38
%40 = load double*, double** %13
%41 = load i32, i32* %17
%42 = load i32, i32* %10
%43 = mul nsw i32 %41, %42
%44 = load i32, i32* %18
%45 = add nsw i32 %43, %44
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds double, double* %40, i64 %46
%48 = load double, double* %47
%49 = call double @llvm.maxnum.f64(double %48, double 1.000000e-08)
%50 = fdiv double %39, %49
store double %50, double* %19
%51 = load double, double* %11
%52 = load double*, double** %13
%53 = load i32, i32* %17
%54 = load i32, i32* %10
%55 = mul nsw i32 %53, %54
%56 = load i32, i32* %18
%57 = add nsw i32 %55, %56
%58 = sext i32 %57 to i64
%59 = getelementptr inbounds double, double* %52, i64 %58
%60 = load double, double* %59
%61 = fmul double %51, %60
%62 = call i32 @fabs(double %61)
%63 = call double @sqrt(i32 %62)
store double %63, double* %20
%64 = load double, double* %19
%65 = load double, double* %20
%66 = fsub double %64, %65
%67 = load double*, double** %12
%68 = load i32, i32* %17
%69 = sext i32 %68 to i64
%70 = getelementptr inbounds double, double* %67, i64 %69
%71 = load double, double* %70
%72 = fdiv double %66, %71
%73 = load double*, double** %15
%74 = load i32, i32* %17
%75 = load i32, i32* %10
%76 = mul nsw i32 %74, %75
%77 = load i32, i32* %18
%78 = add nsw i32 %76, %77
%79 = sext i32 %78 to i64
%80 = getelementptr inbounds double, double* %73, i64 %79
store double %72, double* %80
%81 = load double, double* %19
%82 = load double, double* %20
%83 = fadd double %81, %82
%84 = load double*, double** %12
%85 = load i32, i32* %17
%86 = sext i32 %85 to i64
%87 = getelementptr inbounds double, double* %84, i64 %86
%88 = load double, double* %87
%89 = fdiv double %83, %88
%90 = load double*, double** %16
%91 = load i32, i32* %17
%92 = load i32, i32* %10
%93 = mul nsw i32 %91, %92
%94 = load i32, i32* %18
%95 = add nsw i32 %93, %94
%96 = sext i32 %95 to i64
%97 = getelementptr inbounds double, double* %90, i64 %96
store double %89, double* %97
br label %98
98: ; preds = %30
%99 = load i32, i32* %18
%100 = add nsw i32 %99, 1
store i32 %100, i32* %18
br label %26
101: ; preds = %26
br label %102
102: ; preds = %101
%103 = load i32, i32* %17
%104 = add nsw i32 %103, 1
store i32 %104, i32* %17
br label %21
105: ; preds = %21
ret void
}

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